POC, WIP: OR-clause support for indexes

Started by Teodor Sigaevabout 10 years ago329 messages
#1Teodor Sigaev
teodor@sigaev.ru
1 attachment(s)

I'd like to present OR-clause support for indexes. Although OR-clauses could be
supported by bitmapOR index scan it isn't very effective and such scan lost any
order existing in index. We (with Alexander Korotkov) presented results on
Vienna's conference this year. In short, it provides performance improvement:

EXPLAIN ANALYZE
SELECT count(*) FROM tst WHERE id = 5 OR id = 500 OR id = 5000;
me=0.080..0.267 rows=173 loops=1)
Recheck Cond: ((id = 5) OR (id = 500) OR (id = 5000))
Heap Blocks: exact=172
-> Bitmap Index Scan on idx_gin (cost=0.00..57.50 rows=15000
width=0) (actual time=0.059..0.059 rows=147 loops=1)
Index Cond: ((id = 5) OR (id = 500) OR (id = 5000))
Planning time: 0.077 ms
Execution time: 0.308 ms <-------
QUERY PLAN

-----------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=51180.53..51180.54 rows=1 width=0) (actual
time=796.766..796.766 rows=1 loops=1)
-> Index Only Scan using idx_btree on tst (cost=0.42..51180.40 rows=55
width=0) (actual time=0.444..796.736 rows=173 loops=1)
Filter: ((id = 5) OR (id = 500) OR (id = 5000))
Rows Removed by Filter: 999829
Heap Fetches: 1000002
Planning time: 0.087 ms
Execution time: 796.798 ms <------
QUERY PLAN

-------------------------------------------------------------------------------------------------------------
Aggregate (cost=21925.63..21925.64 rows=1 width=0) (actual
time=160.412..160.412 rows=1 loops=1)
-> Seq Scan on tst (cost=0.00..21925.03 rows=237 width=0) (actual
time=0.535..160.362 rows=175 loops=1)
Filter: ((id = 5) OR (id = 500) OR (id = 5000))
Rows Removed by Filter: 999827
Planning time: 0.459 ms
Execution time: 160.451 ms

It also could work together with KNN feature of GiST and in this case
performance improvement could be up to several orders of magnitude, in
artificial example it was 37000 times faster.

Not all indexes can support oR-clause, patch adds support to GIN, GiST and BRIN
indexes. pg_am table is extended for adding amcanorclause column which indicates
possibility of executing of OR-clause by index.

indexqual and indexqualorig doesn't contain implicitly-ANDed list of index
qual expressions, now that lists could contain OR RestrictionInfo. Actually, the
patch just tries to convert BitmapOr node to IndexScan or IndexOnlyScan. Thats
significantly simplifies logic to find possible clause's list for index.
Index always gets a array of ScanKey but for indexes which support OR-clauses
array of ScanKey is actually exection tree in reversed polish notation form.
Transformation is done in ExecInitIndexScan().

The problems on the way which I see for now:
1 Calculating cost. Right now it's just a simple transformation of costs
computed for BitmapOr path. I'd like to hope that's possible and so index's
estimation function could be non-touched. So, they could believe that all
clauses are implicitly-ANDed
2 I'd like to add such support to btree but it seems that it should be a
separated patch. Btree search algorithm doesn't use any kind of stack of pages
and algorithm to walk over btree doesn't clear for me for now.
3 I could miss some places which still assumes implicitly-ANDed list of clauses
although regression tests passes fine.

Hope, hackers will not have an strong objections to do that. But obviously patch
requires further work and I'd like to see comments, suggestions and
recommendations. Thank you.

--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/

Attachments:

index_or-1.patch.gzapplication/x-gzip; name=index_or-1.patch.gzDownload
#2Feng Tian
ftian@vitessedata.com
In reply to: Teodor Sigaev (#1)
Re: POC, WIP: OR-clause support for indexes

Hi, Teodor,

This is great. I got a question, is it possible make btree index to
support OR as well? Is btree supports more invasive, in the sense that we
need to do enhance ScanKey to supports an array of values?

Thanks,
Feng

On Sat, Dec 26, 2015 at 10:04 AM, Teodor Sigaev <teodor@sigaev.ru> wrote:

Show quoted text

I'd like to present OR-clause support for indexes. Although OR-clauses
could be supported by bitmapOR index scan it isn't very effective and such
scan lost any order existing in index. We (with Alexander Korotkov)
presented results on Vienna's conference this year. In short, it provides
performance improvement:

EXPLAIN ANALYZE
SELECT count(*) FROM tst WHERE id = 5 OR id = 500 OR id = 5000;
me=0.080..0.267 rows=173 loops=1)
Recheck Cond: ((id = 5) OR (id = 500) OR (id = 5000))
Heap Blocks: exact=172
-> Bitmap Index Scan on idx_gin (cost=0.00..57.50 rows=15000
width=0) (actual time=0.059..0.059 rows=147 loops=1)
Index Cond: ((id = 5) OR (id = 500) OR (id = 5000))
Planning time: 0.077 ms
Execution time: 0.308 ms <-------
QUERY PLAN

-----------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=51180.53..51180.54 rows=1 width=0) (actual
time=796.766..796.766 rows=1 loops=1)
-> Index Only Scan using idx_btree on tst (cost=0.42..51180.40
rows=55 width=0) (actual time=0.444..796.736 rows=173 loops=1)
Filter: ((id = 5) OR (id = 500) OR (id = 5000))
Rows Removed by Filter: 999829
Heap Fetches: 1000002
Planning time: 0.087 ms
Execution time: 796.798 ms <------
QUERY PLAN

-------------------------------------------------------------------------------------------------------------
Aggregate (cost=21925.63..21925.64 rows=1 width=0) (actual
time=160.412..160.412 rows=1 loops=1)
-> Seq Scan on tst (cost=0.00..21925.03 rows=237 width=0) (actual
time=0.535..160.362 rows=175 loops=1)
Filter: ((id = 5) OR (id = 500) OR (id = 5000))
Rows Removed by Filter: 999827
Planning time: 0.459 ms
Execution time: 160.451 ms

It also could work together with KNN feature of GiST and in this case
performance improvement could be up to several orders of magnitude, in
artificial example it was 37000 times faster.

Not all indexes can support oR-clause, patch adds support to GIN, GiST
and BRIN indexes. pg_am table is extended for adding amcanorclause column
which indicates possibility of executing of OR-clause by index.

indexqual and indexqualorig doesn't contain implicitly-ANDed list of
index qual expressions, now that lists could contain OR RestrictionInfo.
Actually, the patch just tries to convert BitmapOr node to IndexScan or
IndexOnlyScan. Thats significantly simplifies logic to find possible
clause's list for index.
Index always gets a array of ScanKey but for indexes which support
OR-clauses
array of ScanKey is actually exection tree in reversed polish notation
form. Transformation is done in ExecInitIndexScan().

The problems on the way which I see for now:
1 Calculating cost. Right now it's just a simple transformation of costs
computed for BitmapOr path. I'd like to hope that's possible and so index's
estimation function could be non-touched. So, they could believe that all
clauses are implicitly-ANDed
2 I'd like to add such support to btree but it seems that it should be a
separated patch. Btree search algorithm doesn't use any kind of stack of
pages and algorithm to walk over btree doesn't clear for me for now.
3 I could miss some places which still assumes implicitly-ANDed list of
clauses although regression tests passes fine.

Hope, hackers will not have an strong objections to do that. But obviously
patch
requires further work and I'd like to see comments, suggestions and
recommendations. Thank you.

--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW:
http://www.sigaev.ru/

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Teodor Sigaev
teodor@sigaev.ru
In reply to: Feng Tian (#2)
Re: POC, WIP: OR-clause support for indexes

This is great. I got a question, is it possible make btree index to support OR
as well? Is btree supports more invasive, in the sense that we need to do
enhance ScanKey to supports an array of values?

Btree now works by follow: find the max/min tuple which satisfies condtions and
then executes forward/backward scan over leaf pages. For complicated clauses
it's not obvious how to find min/max tuple. Scanning whole index isn't an option
from preformance point of view.

--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4David Rowley
david.rowley@2ndquadrant.com
In reply to: Teodor Sigaev (#1)
Re: POC, WIP: OR-clause support for indexes

On 27 December 2015 at 07:04, Teodor Sigaev <teodor@sigaev.ru> wrote:

I'd like to present OR-clause support for indexes. Although OR-clauses
could be supported by bitmapOR index scan it isn't very effective and such
scan lost any order existing in index. We (with Alexander Korotkov)
presented results on Vienna's conference this year. In short, it provides
performance improvement:

EXPLAIN ANALYZE
SELECT count(*) FROM tst WHERE id = 5 OR id = 500 OR id = 5000;
me=0.080..0.267 rows=173 loops=1)
Recheck Cond: ((id = 5) OR (id = 500) OR (id = 5000))
Heap Blocks: exact=172
-> Bitmap Index Scan on idx_gin (cost=0.00..57.50 rows=15000
width=0) (actual time=0.059..0.059 rows=147 loops=1)
Index Cond: ((id = 5) OR (id = 500) OR (id = 5000))
Planning time: 0.077 ms
Execution time: 0.308 ms <-------
QUERY PLAN

-----------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=51180.53..51180.54 rows=1 width=0) (actual
time=796.766..796.766 rows=1 loops=1)
-> Index Only Scan using idx_btree on tst (cost=0.42..51180.40
rows=55 width=0) (actual time=0.444..796.736 rows=173 loops=1)
Filter: ((id = 5) OR (id = 500) OR (id = 5000))
Rows Removed by Filter: 999829
Heap Fetches: 1000002
Planning time: 0.087 ms
Execution time: 796.798 ms <------
QUERY PLAN

-------------------------------------------------------------------------------------------------------------
Aggregate (cost=21925.63..21925.64 rows=1 width=0) (actual
time=160.412..160.412 rows=1 loops=1)
-> Seq Scan on tst (cost=0.00..21925.03 rows=237 width=0) (actual
time=0.535..160.362 rows=175 loops=1)
Filter: ((id = 5) OR (id = 500) OR (id = 5000))
Rows Removed by Filter: 999827
Planning time: 0.459 ms
Execution time: 160.451 ms

It also could work together with KNN feature of GiST and in this case
performance improvement could be up to several orders of magnitude, in
artificial example it was 37000 times faster.

Not all indexes can support oR-clause, patch adds support to GIN, GiST
and BRIN indexes. pg_am table is extended for adding amcanorclause column
which indicates possibility of executing of OR-clause by index.

indexqual and indexqualorig doesn't contain implicitly-ANDed list of
index qual expressions, now that lists could contain OR RestrictionInfo.
Actually, the patch just tries to convert BitmapOr node to IndexScan or
IndexOnlyScan. Thats significantly simplifies logic to find possible
clause's list for index.
Index always gets a array of ScanKey but for indexes which support
OR-clauses
array of ScanKey is actually exection tree in reversed polish notation
form. Transformation is done in ExecInitIndexScan().

The problems on the way which I see for now:
1 Calculating cost. Right now it's just a simple transformation of costs
computed for BitmapOr path. I'd like to hope that's possible and so index's
estimation function could be non-touched. So, they could believe that all
clauses are implicitly-ANDed
2 I'd like to add such support to btree but it seems that it should be a
separated patch. Btree search algorithm doesn't use any kind of stack of
pages and algorithm to walk over btree doesn't clear for me for now.
3 I could miss some places which still assumes implicitly-ANDed list of
clauses although regression tests passes fine.

Hope, hackers will not have an strong objections to do that. But obviously
patch
requires further work and I'd like to see comments, suggestions and
recommendations. Thank you.

Hi,

I'd like to see comments too! but more so in the code. :) I've had a look
over this, and it seems like a great area in which we could improve on, and
your reported performance improvements are certainly very interesting too.
However I'm finding the code rather hard to follow, which might be a
combination of my lack of familiarity with the index code, but more likely
it's the lack of comments to explain what's going on. Let's just take 1
function as an example:

Here there's not a single comment, so I'm just going to try to work out
what's going on based on the code.

+static void
+compileScanKeys(IndexScanDesc scan)
+{
+ GISTScanOpaque so = (GISTScanOpaque) scan->opaque;
+ int *stack,
+ stackPos = -1,
+ i;
+
+ if (scan->numberOfKeys <= 1 || so->useExec == false)
+ return;
+
+ Assert(scan->numberOfKeys >=3);

Why can numberOfKeys never be 2? I looked at what calls this and I can't
really work it out. I'm really also not sure what useExec means as there's
no comment in that struct member, and what if numberOfKeys == 1 and useExec
== false, won't this Assert() fail? If that's not a possible situation then
why not?

+
+ if (so->leftArgs != NULL)
+ return;
+
+ so->leftArgs = MemoryContextAlloc(so->giststate->scanCxt,
+  sizeof(*so->leftArgs) * scan->numberOfKeys);
+ so->rightArgs = MemoryContextAlloc(so->giststate->scanCxt,
+   sizeof(*so->rightArgs) * scan->numberOfKeys);
+
+ stack = palloc(sizeof(*stack) * scan->numberOfKeys);
+
+ for(i=0; i<scan->numberOfKeys; i++)
+ {
+ ScanKey     key = scan->keyData + i;

Is there a reason not to use keyData[i]; ?

+
+ if (stackPos >= 0 && (key->sk_flags & (SK_OR | SK_AND)))
+ {
+ Assert(stackPos >= 1 && stackPos < scan->numberOfKeys);
stackPos >= 1? This seems unnecessary and confusing as the if test surely
makes that impossible.
+
+ so->leftArgs[i] = stack[stackPos - 1];

Something is broken here as stackPos can be 0 (going by the if() not the
Assert()), therefore that's stack[-1].

+ so->rightArgs[i] = stack[stackPos];
+ stackPos--;
+ }
+ else
+ {
+ stackPos++;
+ }
+

stackPos is initialised to -1, so this appears to always skip the first
element of the keyData array. If that's really the intention, then wouldn't
it be better to just make the initial condition of the for() look i = 1 ?

+ stack[stackPos] = i;
+ }
+
+ Assert(stackPos == 0);
+ pfree(stack);
+}

I'd like to review more, but it feels like a job that's more difficult than
it needs to be due to lack of comments.

Would it be possible to update the patch to try and explain things a little
better?

Many thanks

David

--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

#5Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: David Rowley (#4)
Re: POC, WIP: OR-clause support for indexes

I think this is very exciting stuff, but since you didn't submit an
updated patch after David's review, I'm closing it for now as
returned-with-feedback. Please submit a new version once you have it.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6Teodor Sigaev
teodor@sigaev.ru
In reply to: David Rowley (#4)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Thank you for review!

I'd like to see comments too! but more so in the code. :) I've had a look over
this, and it seems like a great area in which we could improve on, and your
reported performance improvements are certainly very interesting too. However
I'm finding the code rather hard to follow, which might be a combination of my
lack of familiarity with the index code, but more likely it's the lack of

I've added comments, fixed a found bugs.

comments to explain what's going on. Let's just take 1 function as an example:

Here there's not a single comment, so I'm just going to try to work out what's
going on based on the code.

+static void
+compileScanKeys(IndexScanDesc scan)
+{
+GISTScanOpaqueso = (GISTScanOpaque) scan->opaque;
+int*stack,
+stackPos = -1,
+i;
+
+if (scan->numberOfKeys <= 1 || so->useExec == false)
+return;
+
+Assert(scan->numberOfKeys >=3);

Why can numberOfKeys never be 2? I looked at what calls this and I can't really

Because here they are actually an expression, expression could contain 1 or tree
or more nodes but could not two (operation AND/OR plus two arguments)

work it out. I'm really also not sure what useExec means as there's no comment

fixed. If useExec == false then SkanKeys are implicitly ANDed and stored in just
array.

in that struct member, and what if numberOfKeys == 1 and useExec == false, won't
this Assert() fail? If that's not a possible situation then why not?

fixed

+ScanKey key = scan->keyData + i;
Is there a reason not to use keyData[i]; ?

That's the same ScanKey key = &scan->keyData[i];
I prefer first form as more clear but I could be wrong - but there are other
places in code where pointer arithmetic is used.

+if (stackPos >= 0 && (key->sk_flags & (SK_OR | SK_AND)))
+{
+Assert(stackPos >= 1 && stackPos < scan->numberOfKeys);
stackPos >= 1? This seems unnecessary and confusing as the if test surely makes
that impossible.
+
+so->leftArgs[i] = stack[stackPos - 1];
Something is broken here as stackPos can be 0 (going by the if() not the
Assert()), therefore that's stack[-1].

fixed

stackPos is initialised to -1, so this appears to always skip the first element
of the keyData array. If that's really the intention, then wouldn't it be better
to just make the initial condition of the for() look i = 1 ?

done

I'd like to review more, but it feels like a job that's more difficult than it
needs to be due to lack of comments.

Would it be possible to update the patch to try and explain things a little better?

Hope, I made cleaner..

--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/

Attachments:

index_or-2.patch.gzapplication/x-gzip; name=index_or-2.patch.gzDownload
#7Tomas Vondra
tomas.vondra@2ndquadrant.com
In reply to: Teodor Sigaev (#6)
Re: POC, WIP: OR-clause support for indexes

Hi Teodor,

I've looked into v2 of the patch you sent a few days ago. Firstly, I
definitely agree that being able to use OR conditions with an index is
definitely a cool idea.

I do however agree with David that the patch would definitely benefit
from comments documenting various bits that are less obvious to mere
mortals like me, with limited knowledge of the index internals.

I also wonder whether the patch should add explanation of OR-clauses
handling into the READMEs in src/backend/access/*

The patch would probably benefit from transforming it into a patch
series - one patch for the infrastructure shared by all the indexes,
then one patch per index type. That should make it easier to review, and
I seriously doubt we'd want to commit this in one huge chunk anyway.

Now, some review comments from eyeballing the patch. Some of those are
nitpicking, but well ...

1) fields in BrinOpaque are not following the naming convention (all the
existing fields start with bo_)

2) there's plenty of places violating the usual code style (e.g. for
single-command if branches) - not a big deal for WIP patch, but needs to
get fixed eventually

3) I wonder whether we really need both SK_OR and SK_AND, considering
they are mutually exclusive. Why not to assume SK_AND by default, and
only use SK_OR? If we really need them, perhaps an assert making sure
they are not set at the same time would be appropriate.

4) scanGetItem is a prime example of the "badly needs comments" issue,
particularly because the previous version of the function actually had
quite a lot of them while the new function has none.

5) scanGetItem() may end up using uninitialized 'cmp' - it only gets
initialized when (!leftFinished && !rightFinished), but then gets used
when either part of the condition evaluates to true. Probably should be

if (!leftFinished || !rightFinished)
cmp = ...

6) the code in nodeIndexscan.c should not include call to abort()

{
abort();
elog(ERROR, "unsupported indexqual type: %d",
(int) nodeTag(clause));
}

7) I find it rather ugly that the paths are built by converting BitmapOr
paths. Firstly, it means indexes without amgetbitmap can't benefit from
this change. Maybe that's reasonable limitation, though?

But more importantly, this design already has a bunch of unintended
consequences. For example, the current code completely ignores
enable_indexscan setting, because it merely copies the costs from the
bitmap path.

SET enable_indexscan = off;
EXPLAIN SELECT * FROM t WHERE (c && ARRAY[1] OR c && ARRAY[2]);

QUERY PLAN
-------------------------------------------------------------------
Index Scan using t_c_idx on t (cost=0.00..4.29 rows=0 width=33)
Index Cond: ((c && '{1}'::integer[]) OR (c && '{2}'::integer[]))
(2 rows)

That's pretty dubious, I guess. So this code probably needs to be made
aware of enable_indexscan - right now it entirely ignores startup_cost
in convert_bitmap_path_to_index_clause(). But of course if there are
multiple IndexPaths, the enable_indexscan=off will be included multiple
times.

9) This already breaks estimation for some reason. Consider this
example, using a table with int[] column, with gist index built using
intarray:

EXPLAIN SELECT * FROM t WHERE (c && ARRAY[1,2,3,4,5,6,7]);

QUERY PLAN
--------------------------------------------------------------------
Index Scan using t_c_idx on t (cost=0.28..52.48 rows=12 width=33)
Index Cond: (c && '{1,2,3,4,5,6,7}'::integer[])
(2 rows)

EXPLAIN SELECT * FROM t WHERE (c && ARRAY[8,9,10,11,12,13,14]);

QUERY PLAN
--------------------------------------------------------------------
Index Scan using t_c_idx on t (cost=0.28..44.45 rows=10 width=33)
Index Cond: (c && '{8,9,10,11,12,13,14}'::integer[])
(2 rows)

EXPLAIN SELECT * FROM t WHERE (c && ARRAY[1,2,3,4,5,6,7])
OR (c && ARRAY[8,9,10,11,12,13,14]);

QUERY PLAN
--------------------------------------------------------------------
Index Scan using t_c_idx on t (cost=0.00..4.37 rows=0 width=33)
Index Cond: ((c && '{1,2,3,4,5,6,7}'::integer[])
OR (c && '{8,9,10,11,12,13,14}'::integer[]))
(2 rows)

So the OR-clause is estimated to match 0 rows, less than each of the
clauses independently. Needless to say that without the patch this works
just fine.

10) Also, this already breaks some regression tests, apparently because
it changes how 'width' is computed.

So I think this way of building the index path from a BitmapOr path is
pretty much a dead-end.

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#8Teodor Sigaev
teodor@sigaev.ru
In reply to: Tomas Vondra (#7)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

I also wonder whether the patch should add explanation of OR-clauses
handling into the READMEs in src/backend/access/*

Oops, will add shortly.

The patch would probably benefit from transforming it into a patch
series - one patch for the infrastructure shared by all the indexes,
then one patch per index type. That should make it easier to review, and
I seriously doubt we'd want to commit this in one huge chunk anyway.

Ok, will do it.

1) fields in BrinOpaque are not following the naming convention (all the
existing fields start with bo_)

fixed

2) there's plenty of places violating the usual code style (e.g. for
single-command if branches) - not a big deal for WIP patch, but needs to
get fixed eventually

hope, fixed

3) I wonder whether we really need both SK_OR and SK_AND, considering
they are mutually exclusive. Why not to assume SK_AND by default, and
only use SK_OR? If we really need them, perhaps an assert making sure
they are not set at the same time would be appropriate.

In short: possible ambiguity and increasing stack machine complexity.
Let we have follow expression in reversed polish notation (letters represent a
condtion, | - OR, & - AND logical operation, ANDs are omitted):
a b c |

Is it ((a & b)| c) or (a & (b | c)) ?

Also, using both SK_ makes code more readable.

4) scanGetItem is a prime example of the "badly needs comments" issue,
particularly because the previous version of the function actually had
quite a lot of them while the new function has none.

Will add soon

5) scanGetItem() may end up using uninitialized 'cmp' - it only gets
initialized when (!leftFinished && !rightFinished), but then gets used
when either part of the condition evaluates to true. Probably should be

if (!leftFinished || !rightFinished)
cmp = ...

fixed

6) the code in nodeIndexscan.c should not include call to abort()

{
abort();
elog(ERROR, "unsupported indexqual type: %d",
(int) nodeTag(clause));
}

fixed, just forgot to remove

7) I find it rather ugly that the paths are built by converting BitmapOr
paths. Firstly, it means indexes without amgetbitmap can't benefit from
this change. Maybe that's reasonable limitation, though?

I based on following thoughts:
1 code which tries to find OR-index path will be very similar to existing
generate_or_bitmap code. Obviously, it should not be duplicated.
2 all existsing indexes have amgetbitmap method, only a few don't. amgetbitmap
interface is simpler. Anyway, I can add an option for generate_or_bitmap
to use any index, but, in current state it will just repeat all work.

But more importantly, this design already has a bunch of unintended
consequences. For example, the current code completely ignores
enable_indexscan setting, because it merely copies the costs from the
bitmap path.

I'd like to add separate enable_indexorscan

That's pretty dubious, I guess. So this code probably needs to be made
aware of enable_indexscan - right now it entirely ignores startup_cost
in convert_bitmap_path_to_index_clause(). But of course if there are
multiple IndexPaths, the enable_indexscan=off will be included multiple
times.

9) This already breaks estimation for some reason. Consider this

...

So the OR-clause is estimated to match 0 rows, less than each of the
clauses independently. Needless to say that without the patch this works
just fine.

fixed

10) Also, this already breaks some regression tests, apparently because
it changes how 'width' is computed.

fixed too

So I think this way of building the index path from a BitmapOr path is
pretty much a dead-end.

I don't think so because separate code path to support OR-clause in index will
significanlty duplicate BitmapOr generator.

Will send next version as soon as possible. Thank you for your attention!

--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/

Attachments:

index_or-3.patch.gzapplication/x-gzip; name=index_or-3.patch.gzDownload
#9Teodor Sigaev
teodor@sigaev.ru
In reply to: Tomas Vondra (#7)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

I also wonder whether the patch should add explanation of OR-clauses
handling into the READMEs in src/backend/access/*

Not yet, but will

The patch would probably benefit from transforming it into a patch
series - one patch for the infrastructure shared by all the indexes,
then one patch per index type. That should make it easier to review, and
I seriously doubt we'd want to commit this in one huge chunk anyway.

I splitted to two:
1 0001-idx_or_core - only planner and executor changes
2 0002-idx_or_indexes - BRIN/GIN/GiST changes with tests

I don't think that splitting of second patch adds readability but increase
management diffculties, but if your insist I will split.

4) scanGetItem is a prime example of the "badly needs comments" issue,
particularly because the previous version of the function actually had
quite a lot of them while the new function has none.

added

--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/

Attachments:

0001-idx_or_core-v4.patch.gzapplication/x-gzip; name=0001-idx_or_core-v4.patch.gzDownload
0002-idx_or_indexes-v4.patch.gzapplication/x-gzip; name=0002-idx_or_indexes-v4.patch.gzDownload
��,�V�}kw�6��g�W ��H6��z+n2��N�����������EI��ZU���I3���$�r���'��#�xnl�76F�x,��� ��8>x�k6z�
�~?D�����b���N0�����iuF�Z�9t��H��z����V�k�����[��?�)����{���������?q-��x	O��G�^N����b:�#1/������Sov���{(|���zs����u�^}��C!��`��w�J�0����E<�f?����,H���j���}*��RI�1���Atg�G���|!>��;0-/	����"�����/v�5�&�����aY�|�O�J8��=|wh���{�.���X����&~T~���������N�/N�?����i.�`�W_x��d'~�
&�x.��$&�Ye��?BX�KK\���R��h�>:	h�LW�,���6���,:��.D���8Q��=�����,F�	b�`�+�}���
j�2����`��)f0�X~
��
nc�eHk	�����1�&�rK��w����U}a`�'���^�2���(n!y�-Bc���>)GPp m���\����%o�����?��y��>}
��n�/4��t'�"?YD3�%p���=�;p�������8)!E:������C��gz��*��������BF[���2:��C�;gq�?K^�*;{�}�J�]=Ds�8�3\������;/��w���$b��%�$��P�V_���{_��/o�����v�y�C&�p����_uU��������T�F#^��8���\V��'��(��xqr*�����w��x�\�JOw����W��~$��c����UL�8������.�u?Fbz�<�G,��E"���V�A���� ���p��3�������~TjB�@��&������d4{�����K��\AS�e�V�gOW��tF�?�DL�������$���������JD�%������mOw�� �%���3x�!&ax-s�"�/fCM�V61���6�]��3%���%����q�?�t��)�7�-������p@�2#0=W4��7�5�yyzt|��������/^�����.����6����/�#` �Y��EA1��at�*�%�����(a�����^��+��FQ��M�0�"����J��6�>"d:��{��r�Bb.
��I<�90�9`� H�83���_�|�A-�o��$�5:`c/�,�45��Ks�a�7
<1#�	Dn��|��85..���(�F#5�t�1���
'���{�8^����X(���D�����-$p�Q���6�%r���|��r�5��vX��M������e����,/�dr�k�T�@9=A/��K`$e��&��3�=;q &�������$��I�B�hv<�Ac���0��T�L1A-m���
���p�Q�Ly������?�t�u���D�>��R	_���H|�'c5|G�o��szb��k��%�^�L�
���������`�Bo	�3��a�� ��������*�A
N�"�s���82�����J

*Q�EM�j����Q�H.
'����\�E�\�������]������F���'2�
�#��IYL���<� �`"$0y(��\B����'���
���COe-<��3*�o%]���y2F�^������{'/������R����(,G��h�ES�Vl,�rMS���g�K���r��W�U7pW�U7��a���
���\v�<+[wdS��U���wh��B��`��T��6C�����r�V�Z�M�_.�r���X}G9W������d���^���(���w�}��s'�W��H���;��&�������+��eX^UD
�z��H��^}�
�]X"��K)F�<�/�}au)���P�#m��T!:��A-N�lR��'�Fr3�3s8����D9�����J���2�Q� ����,���?����a�\��������i��#��m&�����+q
@��"YJJ�:��T�+v�a�mh
D��q�KM�<
��E6�_�$��t����9zt<���w�����`5�wq+kh�����ri�c_vAI^���oB�����@!YK��={[�����<��J0Z`�����/r���7��g��(F����-��`:�� 	�J����r�t��	X�% i�g�tL|�M�"�<���9��l�9������I��Bc4%�VA�M[6����E���N���o���	��r����m������D�#��4NZr4��S�n+\{��V=("=�-���-O\7����%/��+��ja������K)�jlo/-�_2����ET		����^���t��4�|���Od���4j2�E�Z?b��n�N�%��H���h	%��M�M�~4
f�^,�L�'���e�R�\�/�PE
��s-z[P3�G�U��82�uEz�Fk�����Ua���,!���f�_�Z�Zc\5F���o���p��&���m��>�q���&L
H����8�����O���&���(��RR$��5E����a]y���@���:�39�����nw��K6��(9[�y�,��Z������P��O�$'�s���*mN�	YF�-��Rz�4���}P���^y�������L�������I��3?�9�������|��H����?�*����n�~�Ww
�?p��{l��}0�A������qi�u>�^�`6���T�����8�5&���'��@�������Zy�h�C+�X�rPI%�4��4�\�������LZ
ZV�������T 4Se��*2��?T����0�g���^,Y4��@� k�=���[�����
mR�MC�i�j���H|oK�)Z!�����+/AA�
%dY�����7�o�.8���*���s�o�����&n��M�2���B7��L����Q���6�|&�3���o�~�]_ys @J����J����F���%�].b�P�<��
�yBn5���	�X���s^�ZE�*!���zL��l����T�FbW�o��m�]!���v���@�r]�^������T~���a�+��3�I ��7�}ny�S�d���4��$Z��-�#`�8\�F\�d&��?G�2R��F���_�$~�e��B���Pina�^4��{S��\����e�����yB��6��l������_h�a��n�a>5N��H3Vd��G��^flJ�v5S����AKo�Q�z�OdE�� $2Z��}*�N@Do��'�1��A���L6��U\!5�"�<+���l@��p��������0���4����-�����c����gYM�ZZ@{���R�)�k�
�Ow��?���-� ^!���sG,�<O�� �y���#s[�+jD���
��l�?��Y�yGL}o����x1@��VLn	}��L��<���J7L �$�����o.�}�M�
�{��5z�/�q�1���u�!�����P�340 ^��p!��c%����H�" �����E�>���d��6W{���Ip��cDq��w���|Q����a�
�i5�vJ�OW>i������~�5M�p~�a�a���b���c��?�b�N]b����p+��"����?L�,V�4\pC�S���R�����q0
�	9������g[�`�B�3�Lo.�$ 7�`GL^�
X���]e�-���hM�=�eyv��A�=6�]l�����4�e{���6������=aM�x��0p(�8��s�vts������� �x���[������'�/����#����`�#���^�_cNU�i��RC���"��(��a*��!:���v�r��DI�8w%�0�mM�=^G����T_h����I���,�L���]'N�	;���l���(�m�Q�����%)��^)��h�YQ�����\��+��_�2cJ/�!M*��%��@��x��2FBJ$t

���T"dC���1�^j��a,L\5�9�o�+�/���M���/���*����uf`��O����ehR�/��	���{�����<L�k�5� 3�����+%���aQ�")��r1H0G����hL��(����f?P�JE@#�>��qJ
#I��%1M1�
�(e��4�3�0	�;���� B�frN��=Ar�.���0��E`�5hl�������Y�W�Ev��B	���7����vc�����Q6�������~f81�`X�o�2�Bl�pm�*��$�����%0�b��"b.��3��/�a����`X�K��\9�6����J��q�S��F�BD�j��C�K�J�3H���,I������K��61(C�Y}���jg��g�v���@������;@e`WMD�(��exm��^d�
��4Y�l�[��_]%�����E��������bt!o�����zq���e�H"������X?������q�����[�S3�[����xZ#byIfq#�6qTdo�w�#�Z�,
T��Z���a�lNx�/�yc���N��3&��(�P����*����?�8'��8���g���A,��8Tx;�;�1����}�I��'Jj���D�	�uiE%�]�%"�T�3(;���q�2�C��U�j�(Z���W�i�����=%}k[�b�=c�<����#�wf�%c�A��cy.�\�6�m{��D�#7�Q�
�r$�B#0$	�b�AZy�����
��9��!0������o�r����nTE`�K�P}M���:�QE��O��#��X�����
�,���r�/6�@�A!�j����O(��dI�.%]��J�!�
U�+��,E?KI�ej'�-O�:d�>���!Z�o���
R@9���kXK�+[n5��\)���S���b�M*3ks��hq��Z�~�3�V����-�p�,'�����j��=��`2���a��D�p����e$�D,����V5��{����$iEr�����&�!k�K��[T;l_!�{^�G�B�d�|V�K��u2�v�I�`�w�2�c#&=���x��9
^K��R��*�5�tM?��B
�V�x���P�0hneq����V������;�7�����P�.8&#���aYn�V�y�l��k�1�m�~���j���F�G4ny�F�������RQ�Hv��7�{'�k&�2Z���Tx�b���b�`�8�a�"5�������a�����O^Pe������v�M
�_9���&���"�c�pM��v�����.l���E���j���)RYn�Al��n���0(MT���p�]������l���P<�)q��/q���W9���@����E9
�����#!�r�{�t<(��d���k{��:��K��/�9|���mu�Pri��^ Z��O��)�R`�&�7������{�i�a��fX�g�'�9X�>��UuD�:6���6S^Y*&A�p�
�;�0��-��v���h���a"g�:�~���ixS[�	X��0�l�wXUe)c%�<��~�LoD�
������8dU�&�f�	��d�D�a����y���u�����E����`ZBdY�������#d-=�����,����`��bh�>(����+� ��\��03^��K���v�����m�Y�����0�	.��������h��3z��a�<bQ�U�5�t�1k�����|Vn�E1�n�b3�q���#<0x�>�@`�G��0������7��V�H�M�|X�e
�J��v[H
`�8����G�$��%��7H3�!A�|�qJf��f$�#s��k#����S�2M{+J"�M����J��Z���Nn�,v�S��O�=�-0��"��.��|o��_>g�x�k�O�e����*�|��]fY��i�vD�6"�:����2Y�uMlMf�O��[r���1dA0���"�������J��
���W��M^��Ae/SI����[8��'���Zc����9����x����R$�O��|�Y8"VF�Ji+�������T�P���<Vl��e��$��4<����]�����(����u�
2�B�m������H�o���CO~��X5>�'/^1/!Z/s��(��Y�0EU��
e�Cl�����{�6��B�!��hF��if�dt�%v����=����d"9�#���nydYE7KY@��2l�%B]�A�G�1������F��8=
�?��9�����O?��0`�c��0R4������Zm�m�L�6���]�	��t��TX �$X^n:u���'��,�k�At����!�Q���<<���b�a��3� tB�/�N�la����dOM#:���%�:	�(\�z~��`wMH��+�{��!Q��6A���$�k
����5�Jy������#8L������}�
�����Q6ye@��q��LY!���kC���:�f�D����*m<��%�����)�CL(C����J���8�@����^�^	]�T�?�0�e_����-���J�����������|������D)�h��T���O���(=�"9���fo�3 ��}�]��*����4�RgNt[ch�\��i��q���C���X/�es�1Iu��I�'#w��F����}my����/^��^����}s~V���Gy�2��-�Q(N�a�:D'��x�H@���.�7��y�h���Z�hD9����+<9\ObY���Y����L��H�7G�`.���� u3"sqY�u�DO2�=�J���g�9�����\D���Z��;���^�9�.6<�/YwL_�������Y�A�W��$��q|L�����f �-If�$����+Y�P�R�����V��^��e��);g�*	9��R%��C�cf
��I+�qJ��A�������q�vK��zV��@�����f��@JJ�WW�d�3u�_�0�V�_�s1	���P��;>�s�&&�$}UW�
�2ZYw��Yw�L��3�c�[%�15��w��e��a�T
����/dfbMqmnC�����6Z�r���>����-
�$�1oT���yS���lc�K��d7��:����&���R����	Jo���5l��d��I�l���H*�EG�Mm��;*C���o�M�@��I����(daz�L)�u$�M����uMm�e,��A}����D�VW|�n=0���	�������2�i"����c������^j�����D2�Y�Fk�������i[��\D/���p�j*�GB%UZ���J�=�
k���N~�02&����gR�#IU�����]���N(����v��iMWe���W=3#�f��@y�����< ��R_���_d)�T*��.Ak�RQ'B���/��p4-����2I�j������Le+�o����'�l��C�1����S�P*�
��$[+iG��b���$�0�������g�2M���+�TE@�4k� ;��7x3����(���q��0k�m�]"_��,��4��R��������z�Fr�"�~���������{�����,Y'9�b�{h!����O�Vt��eE��]E��:N���������M�^��;�����`��&V�rZ�����_Z�8��"K��]�8N6ZdYl�U^���,#���6{��Z���w����k�6k�U��BQ��uM�����Q�b����
t���d\H��[#��S�a�0��43����/�b_��o�����7�
��'������5_�w�z�T��?:;������\����P`:'P)���7T��i^g1,#��SXB*�$3��W�������|J���o<����/s?���G��~'{�d����|���}�dN���[�
�����H����v����������u���y������t.�������/�p����)6J�e���y*�������$���`D���'��L8(�B�V��3�'
N?��R;?9���k�0\�izR��k�� ���qj�0������4RA�b#�����e�q��I��x<��;�����6wv#�f�i�������� U>��'�\�I��N!k{���:2���m�7\����V�Nl�EALW6Qn���N�s��'xk
��]����.�F�B
Y�l�����4��ttDI�$����7���9�Z��I@:�������r'2�C�<�L��'7�-n=�?�G��hA���@�F����h�q��LR��=[�X���O����)�U
�l�;����;^6E�P�D��U�	�U�����R�B�����������m.�V���])����|w������TR!�����w����yU++���.����T�b� Rn�Ns�g��:0����1Ct����4��>�Zr�I���H0���.'E����^"K�+4j��Di3AB�#�.6	R!h+��6��MgE~^rn(�	��������L,���b�c�*\�sM�`��B�F�I���D������zC�E�k�x����������?��2!�z2+0��93(�U��p.#�2QR��;����N�P��6�JS��[��E�J	��4{mO�s@
����"�dV�n��'y�Fp���H&��g��E%�D_-eDz�OY)����Y�>}Q$��o
���*���������|Q�2��m���6����I�}�]��
|�6���]��-�>��9�F�0��6�)x�m���*� ��l7�=��:�?�PU�������I$mj���R�n�(�1K���U�NC!e�R�d�k5UM���5i��^�M�uW�FV�T�F6�I��J��rc�^��FM����+8��>Q����A�1�I�� m��(6Q��o������c�U���Ru���:��e*;�����,������f�G[�eMYM�1�Tv�VV�G��6:���T��/�W��G�<�8��1.@�3f_��x^7���vs��$ml_f�6�f���[�Z�Q��ns�1���Fq#J�Gq���$��/����D�4�nBc'}����� hst���D�^�O�GA�j�4<�G���O��N6�\����l� �����4�s��o�EL����e�Y=������pQh5]�l�(\1��|���J:Gorj:D���m�J$�|,O����Q�z����z�uV{mx��
�*:���!9L�n����/�����B�Xw'
2�.��s������)``��M=�J���������LOvTt���&ul��+�C��E�7��C��#c��5Q���M4�i,����R��C�(��9����a�}��]nv=���/���s\��thw���t�
}�.�����N=<��^�k\�(�V�Jx�� ��������Hh.��n�)S���=b�j+��{�P���C�j}��1���X*elLb��{YQ����R0P�2�"���i{2��V��i+���w�y��EB�Ut>G���)N����w�qy���b��x)dip�E��hD�vN�����oF�����UO��@;iXu�*�\��s{��:�ww(smz��n�4��f��*��
��G+Q�#r���w���i��9^�b��jb|�jkB�TP��l��<��QJsJWL�^k�%#���|�p�F#��Y)�.x;���U�x�1h?����|r'��%�W�kp)'�l73b�.�Q�#2������
=k�^�����������"��FR�|e1�9���h��h�Hb;�N����L�a�������:����d����
��{3����M���fV���_P6?}sL�����Q�|Q��}lGr�
�S�3�XH�<V��d�g���������������
�h!	����hB���}��WL��>�B�J�IG���-�����+8[�������������&D����*�u�z�lbq��%�����t�e�� �;W�K8�&�O�&fD�s�M�
!e�1�U��(�l!��g�%��=�\| ��������[�k=*��mi�{kI�YF��q��l�Z��j4Guc����X��hX���)N�]hK[�+��r�V=y�`����G���Ys�+Z�z��.�6����e�ZJ�����Fz+�3��m{]�an�r�U#,�?Q=�����R}ON��M�-�U.�Eq�J8�7j1T� �d��x{	����*�`�����7Nd�wI�!g9�w�ZD8��&�|���R�EC���}������	JadV�a5.����D��(��)���-�5��`�B�[�v����j�A���%^�L��k
�����{�O�0�����W�t��E��N��d�v�����`��Ie}��������7�Dv��������(��z/���NN�H�e���w��8`��pBRSK}������g*K;��O�V!�[�MY���Oz�H��)�m�����w������w�}�� ����A��'(?E���m{�������j4��f��j�]Yg�e�[���n��6Z�zog����&��g���=��_����������W�s�^��r��^������Ey�	n�q���T�}������L�x��;��}�����~?�e�K�@��/���0��v����1�t*�E ����r�Z�
�D�^-�,]�\1X1��t'�xHk�$&�n\�!�T��;����i�s�T�^f�2��_�R��T|NbQ���"�9q������{�}P����e���X=��YvY+^gK1{�m��������mt7�s���sd��i��o����hy���y����
.��D"M"����B<�����8=��z���Z���HE�}\v����7���T�����J����6-����N@���)���B�& cW���H�������xR���?���$����@���W��oI��H�?���\^�i*n�J����`H7��Rxp��f
a&��'e���P�<y� k�g;l��f3G6~���t
�T[0����F����0)7���z�v��!�]0�����
�=$�A��"^��SVP.����-h�W�9<��������[w\�VmB/�����k7��?r^^
���s1�a�����6�xt|Xl4��`��90|�4�5�Q�Y����&%W�{MJ��E�#�w:�RkfZ�sK]�R=+���h!�X�����i�u�V��m��l�n@@�O�Us[6���c�X�;cW�H��qo�7&�w��B��6,�^,(��%%�d_�����&�e�����8T��_��+�7�Y��w�N�n�z���i�"�_�A@��N�#RI,`����&WGy��G�c�T�Z�A��>?�>�
�A�t�����O�}�+��'��R<XOT>���#�V���w���>^����2,���8�?�v��v2�N��Q��������N�u�
����N��4����Mn�6�^���^4��nGu��]�0lPi�N��1�,�E���F:-���n����>��q��!]���!:P��w�0���"Ht��^������^nn������z�U8M�Qhvz�fO����u����=��n���w4�!��vLV�������r�������~�����#^���u[4��������m�mh4���1(���5�p�t�����m���z��V����0�H0��&���&|t������+D9h�������-���U3�uK�j���z����lZ�-]���w�p{����k�i��^�cH[�N��M�u��;��Z�~;��a��{�]�����=��0e�_���p;
��^�pT�v���t��`4�^���t��z���&�V�����������!; GY�7:�t_��
C�u�I�K9 Y�
�`��2%$_T%�|������s�t���������x�D=��F������j���h�`W7�vu���[��t:y*��Z92o�.��v���t���i��z��)i|���3�#g*������
1H��i�"%�!�AF��e�sJ�%����lK9�w�����-Wt�t]V-6eV�|;.��L��y�����7W�>�N�hJ��Gn�!��H�:�Zm����So��=����`�n���i;�z��S1Td�Z����vG��&I����s�&h��V�{����[oYpQ��%��y[h����M���~�����ef{�>-��{0=2,�0�B�P&��P����A>���R-�[=�`@n��wWc@����QG�E��t `��]<
���*��m���M�u���m��x?/�p
h0T��<���	K+p$x@g
^��Dku�M��:�N�X���7�nj�)r��r�x��V^��[i�;�������]��i)C�:=��G���/�a����������=;:�s��2����'x���\*���S��){;�y�{�T>��h�Md&��]f.��,�[[�We���x��v���
�C�V�>�hU�d
�g�0����~�M��@4�m��j����
����6������������F�����$w���N�cX����g����)�4��W��t��RR�s�i�M�����*�|uy}��W������2p�?!=�.��������O8���|��o|>���T���h��IKE�fVF�g)�������>��!c��F7c���S5xb��$�0�,�3
���������fx��&������j{}�U�5�Y��n�7�f��#�?���5|���Of���Wc%���<l���=�s�@��f!�����;)�<�U3�|SY~,� jk���\�;Z�t�k��_��5V��k���X���B�X�{K��:iI���3����<!�{����@;~������pMj��%�H�2����R�?��A�Go�|����O��E��S�<y����#<z{r�n��,i �+��QF�)���������]��Y���w�/OS��2����>P"��o*���������\O���M+hw���N<�u@����v��h�K/U��
Z�+�4����R�����7'�tn�/��s����@����<l"�h�����m�`��6q�w���mj�~����I}
u�����)
�2�?H���������=P��1�VMr*u:]�"m~B���[�$��&^�����&��0�C��W���]��bT�`�b;7��]�����
���>;&�N����}�+�������x����
(oJc�
#10Andreas Karlsson
andreas@proxel.se
In reply to: Teodor Sigaev (#9)
Re: POC, WIP: OR-clause support for indexes

I gave this patch a quick spin and noticed a strange query plan.

CREATE TABLE test (a int, b int, c int);
CREATE INDEX ON test USING gin (a, b, c);
INSERT INTO test SELECT i % 7, i % 9, i % 11 FROM generate_series(1,
1000000) i;
EXPLAIN ANALYZE SELECT * FROM test WHERE (a = 3 OR b = 5) AND c = 2;

QUERY PLAN

----------------------------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on test (cost=829.45..4892.10 rows=21819 width=12)
(actual time=66.494..76.234 rows=21645 loops=1)
Recheck Cond: ((((a = 3) AND (c = 2)) OR ((b = 5) AND (c = 2))) AND
(c = 2))
Heap Blocks: exact=5406
-> Bitmap Index Scan on test_a_b_c_idx (cost=0.00..824.00
rows=2100 width=0) (actual time=65.272..65.272 rows=21645 loops=1)
Index Cond: ((((a = 3) AND (c = 2)) OR ((b = 5) AND (c = 2)))
AND (c = 2))
Planning time: 0.200 ms
Execution time: 77.206 ms
(7 rows)

Shouldn't the index condition just be "((a = 3) AND (c = 2)) OR ((b = 5)
AND (c = 2))"?

Also when applying and reading the patch I noticed some minor
issues/nitpick.

- I get whitespace warnings from git apply when I apply the patches.
- You have any insconstent style for casts: I think "(Node*)clause"
should be "(Node *) clause".
- Same with pointers. "List* quals" should be "List *quals"
- I am personally not a fan of seeing the "isorderby == false &&
index->rd_amroutine->amcanorclause" clause twice. Feels like a risk for
diverging code paths. But it could be that there is no clean alternative.

Andreas

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#11Tomas Vondra
tomas.vondra@2ndquadrant.com
In reply to: Teodor Sigaev (#8)
Re: POC, WIP: OR-clause support for indexes

Hi Teodor,

Sadly the v4 does not work for me - I do get assertion failures. For
example with the example Andreas Karlsson posted in this thread:

CREATE EXTENSION btree_gin;
CREATE TABLE test (a int, b int, c int);
CREATE INDEX ON test USING gin (a, b, c);
INSERT INTO test SELECT i % 7, i % 9, i % 11 FROM generate_series(1,
1000000) i;
EXPLAIN ANALYZE SELECT * FROM test WHERE (a = 3 OR b = 5) AND c = 2;

It seems working, but only until I run ANALYZE on the table. Once I do
that, I start getting crashes at this line

*qualcols = list_concat(*qualcols,
list_copy(idx_path->indexqualcols));

in convert_bitmap_path_to_index_clause. Apparently one of the lists is
T_List while the other one is T_IntList, so list_concat() errors out.

My guess is that the T_BitmapOrPath branch should do

oredqualcols = list_concat(oredqualcols, li_qualcols);
...
*qualcols = list_concat(qualcols, oredqualcols);

instead of

oredqualcols = lappend(oredqualcols, li_qualcols);
...
*qualcols = lappend(*qualcols, oredqualcols);

but once I fixed that I got some other assert failures further down,
that I haven't tried to fix.

So the patch seems to be broken, and I suspect this might be related to
the broken index condition reported by Andreas (although I don't see
that - I either see correct condition or assertion failures).

On 03/17/2016 06:19 PM, Teodor Sigaev wrote:
...

7) I find it rather ugly that the paths are built by converting BitmapOr
paths. Firstly, it means indexes without amgetbitmap can't benefit from
this change. Maybe that's reasonable limitation, though?

I based on following thoughts:
1 code which tries to find OR-index path will be very similar to existing
generate_or_bitmap code. Obviously, it should not be duplicated.
2 all existsing indexes have amgetbitmap method, only a few don't.
amgetbitmap
interface is simpler. Anyway, I can add an option for generate_or_bitmap
to use any index, but, in current state it will just repeat all work.

I agree that the code should not be duplicated, but is this really a
good solution. Perhaps a refactoring that'd allow sharing most of the
code would be more appropriate.

But more importantly, this design already has a bunch of unintended
consequences. For example, the current code completely ignores
enable_indexscan setting, because it merely copies the costs from the
bitmap path.

I'd like to add separate enable_indexorscan

That may be useful, but why shouldn't enable_indexscan=off also disable
indexorscan? I would find it rather surprising if after setting
enable_indexscan=off I'd still get index scans for OR-clauses.

That's pretty dubious, I guess. So this code probably needs to be made
aware of enable_indexscan - right now it entirely ignores startup_cost
in convert_bitmap_path_to_index_clause(). But of course if there are
multiple IndexPaths, the enable_indexscan=off will be included multiple
times.

... and it does not address this at all.

I really doubt a costing derived from the bitmap index scan nodes will
make much sense - you essentially need to revert unknown parts of the
costing to only include building the bitmap once, etc.

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#12David Steele
david@pgmasters.net
In reply to: Tomas Vondra (#11)
Re: POC, WIP: OR-clause support for indexes

Hi Teador,

On 3/19/16 8:44 PM, Tomas Vondra wrote:

Sadly the v4 does not work for me - I do get assertion failures.

Time is growing short and there seem to be some serious concerns with
this patch. Can you provide a new patch soon? If not, I think it might
be be time to mark this "returned with feedback".

Thanks,
--
-David
david@pgmasters.net

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#13David Steele
david@pgmasters.net
In reply to: David Steele (#12)
Re: POC, WIP: OR-clause support for indexes

On 3/25/16 11:13 AM, David Steele wrote:

Time is growing short and there seem to be some serious concerns with
this patch. Can you provide a new patch soon? If not, I think it might
be be time to mark this "returned with feedback".

I have marked this patch "returned with feedback". Please feel free to
resubmit for 9.7!

Thanks,
--
-David
david@pgmasters.net

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#14Andrey Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Teodor Sigaev (#1)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 12/26/15 23:04, Teodor Sigaev wrote:

I'd like to present OR-clause support for indexes. Although OR-clauses
could be supported by bitmapOR index scan it isn't very effective and
such scan lost any order existing in index. We (with Alexander Korotkov)
presented results on Vienna's conference this year. In short, it
provides performance improvement:

EXPLAIN ANALYZE
SELECT count(*) FROM tst WHERE id = 5 OR id = 500 OR id = 5000;
...
The problems on the way which I see for now:
1 Calculating cost. Right now it's just a simple transformation of costs
computed for BitmapOr path. I'd like to hope that's possible and so
index's estimation function could be non-touched. So, they could believe
that all clauses are implicitly-ANDed
2 I'd like to add such support to btree but it seems that it should be a
separated patch. Btree search algorithm doesn't use any kind of stack of
pages and algorithm to walk over btree doesn't clear for me for now.
3 I could miss some places which still assumes  implicitly-ANDed list of
clauses although regression tests passes fine.

I support such a cunning approach. But this specific case, you
demonstrated above, could be optimized independently at an earlier
stage. If to convert:

(F(A) = ConstStableExpr_1) OR (F(A) = ConstStableExpr_2)
to
F(A) IN (ConstStableExpr_1, ConstStableExpr_2)

it can be seen significant execution speedup. For example, using the
demo.sql to estimate maximum positive effect we see about 40% of
execution and 100% of planning speedup.

To avoid unnecessary overhead, induced by the optimization, such
transformation may be made at the stage of planning (we have cardinality
estimations and have pruned partitions) but before creation of a
relation scan paths. So, we can avoid planning overhead and non-optimal
BitmapOr in the case of many OR's possibly aggravated by many indexes on
the relation.
For example, such operation can be executed in create_index_paths()
before passing rel->indexlist.

--
Regards
Andrey Lepikhov
Postgres Professional

Attachments:

demo.sqlapplication/sql; name=demo.sqlDownload
#15Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Andrey Lepikhov (#14)
Re: POC, WIP: OR-clause support for indexes

I agree with your idea and try to implement it and will soon attach a
patch with a solution.

I also have a really practical example confirming that such optimization
can be useful.

A query was written that consisted of 50000 conditions due to the fact
that the ORM framework couldn't work with a query having an ANY
operator. In summary, we got a better plan that contained 50000 Bitmap
Index Scan nodes with 50000 different conditions. Since approximately
27336 Bite of memory were required to initialize one BitmapOr Index Scan
node, therefore, about 1.27 GB of memory was spent at the initialization
step of the plan execution and query execution time was about 55756,053
ms (00:55,756).

|psql -U postgres -c "CREATE DATABASE test_db" pgbench -U postgres -d
test_db -i -s 10 ||SELECT FORMAT('prepare x %s AS SELECT * FROM pgbench_accounts a WHERE
%s', '(' || string_agg('int', ',') || ')', string_agg(FORMAT('aid =
$%s', g.id), ' or ') ) AS cmd FROM generate_series(1, 50000) AS g(id)
\gexec ||SELECT FORMAT('execute x %s;', '(' || string_agg(g.id::text, ',') ||
')') AS cmd FROM generate_series(1, 50000) AS g(id) \gexec |||||

||

I got the plan of this query:

|QUERY PLAN

---------------------------------------------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on pgbench_accounts a  (cost=44.35..83.96 rows=10
width=97)
   Recheck Cond: ((aid = 1) OR (aid = 2) OR (aid = 3) OR (aid = 4) OR
(aid = 5) OR (aid = 6) OR (aid = 7) OR (aid = 8) OR (aid = 9) OR (aid = 10))
   ->  BitmapOr  (cost=44.35..44.35 rows=10 width=0)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0)
               Index Cond: (aid = 1)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0)
               Index Cond: (aid = 2)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0)
               Index Cond: (aid = 3)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0)
               Index Cond: (aid = 4)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0)
               Index Cond: (aid = 5)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0)
               Index Cond: (aid = 6)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0)
               Index Cond: (aid = 7)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0)
               Index Cond: (aid = 8)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0)
               Index Cond: (aid = 9)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0)
               Index Cond: (aid = 10)|

If I rewrite this query using ANY operator,

SELECT FORMAT('prepare x %s AS SELECT * FROM pgbench_accounts a WHERE aid = ANY(SELECT
g.id FROM generate_series(1, 50000) AS g(id))',
'(' || string_agg('int',',') ||')'
) AS cmd FROM generate_series(1, 50000) AS g(id)
\gexec

I will get a plan where the array comparison operator is used through
ANY operator at the index scan stage. It's execution time is
significantly lower as  339,764 ms.

QUERY PLAN
---------------------------------------------------------------------------------------------------
Index Scan using pgbench_accounts_pkey on pgbench_accounts a (cost=0.42..48.43 rows=10 width=97)
Index Cond: (aid = ANY ('{1,2,3,4,5,6,7,8,9,10}'::integer[]))
(2 rows)

IN operator is also converted to ANY operator, and if I rewrite this
query as:

SELECT FORMAT('prepare x %s AS SELECT * FROM pgbench_accounts a WHERE aid IN(%s)',
'(' || string_agg('int',',') ||')',
string_agg(FORMAT('%s', g.id),', ')
) AS cmd
FROM generate_series(1, 50000) AS g(id)
\gexec

I will get the same plan as the previous one using ANY operator and his
execution time will be about the same.

QUERY PLAN
---------------------------------------------------------------------------------------------------
Index Scan using pgbench_accounts_pkey on pgbench_accounts a (cost=0.42..48.43 rows=10 width=97)
Index Cond: (aid = ANY ('{1,2,3,4,5,6,7,8,9,10}'::integer[]))
(2 rows)

On 28.12.2022 07:19, Andrey Lepikhov wrote:

On 12/26/15 23:04, Teodor Sigaev wrote:

I'd like to present OR-clause support for indexes. Although
OR-clauses could be supported by bitmapOR index scan it isn't very
effective and such scan lost any order existing in index. We (with
Alexander Korotkov) presented results on Vienna's conference this
year. In short, it provides performance improvement:

EXPLAIN ANALYZE
SELECT count(*) FROM tst WHERE id = 5 OR id = 500 OR id = 5000;
...
The problems on the way which I see for now:
1 Calculating cost. Right now it's just a simple transformation of
costs computed for BitmapOr path. I'd like to hope that's possible
and so index's estimation function could be non-touched. So, they
could believe that all clauses are implicitly-ANDed
2 I'd like to add such support to btree but it seems that it should
be a separated patch. Btree search algorithm doesn't use any kind of
stack of pages and algorithm to walk over btree doesn't clear for me
for now.
3 I could miss some places which still assumes  implicitly-ANDed list
of clauses although regression tests passes fine.

I support such a cunning approach. But this specific case, you
demonstrated above, could be optimized independently at an earlier
stage. If to convert:

(F(A) = ConstStableExpr_1) OR (F(A) = ConstStableExpr_2)
to
F(A) IN (ConstStableExpr_1, ConstStableExpr_2)

it can be seen significant execution speedup. For example, using the
demo.sql to estimate maximum positive effect we see about 40% of
execution and 100% of planning speedup.

To avoid unnecessary overhead, induced by the optimization, such
transformation may be made at the stage of planning (we have
cardinality estimations and have pruned partitions) but before
creation of a relation scan paths. So, we can avoid planning overhead
and non-optimal BitmapOr in the case of many OR's possibly aggravated
by many indexes on the relation.
For example, such operation can be executed in create_index_paths()
before passing rel->indexlist.

--
Alena Rybakina
Postgres Professional

#16Marcos Pegoraro
marcos@f10.com.br
In reply to: Alena Rybakina (#15)
Re: POC, WIP: OR-clause support for indexes

I agree with your idea and try to implement it and will soon attach a
patch with a solution.

Additionally, if those OR constants repeat you'll see ...
If all constants are the same value, fine
explain select * from x where ((ID = 1) OR (ID = 1) OR (ID = 1));
Index Only Scan using x_id on x (cost=0.42..4.44 rows=1 width=4)
Index Cond: (id = 1)

if all values are almost the same, ops
explain select * from x where ((ID = 1) OR (ID = 1) OR (ID = 1) OR (ID =
2));
Bitmap Heap Scan on x (cost=17.73..33.45 rows=4 width=4)
Recheck Cond: ((id = 1) OR (id = 1) OR (id = 1) OR (id = 2))
-> BitmapOr (cost=17.73..17.73 rows=4 width=0)
-> Bitmap Index Scan on x_id (cost=0.00..4.43 rows=1 width=0)
Index Cond: (id = 1)
-> Bitmap Index Scan on x_id (cost=0.00..4.43 rows=1 width=0)
Index Cond: (id = 1)
-> Bitmap Index Scan on x_id (cost=0.00..4.43 rows=1 width=0)
Index Cond: (id = 1)
-> Bitmap Index Scan on x_id (cost=0.00..4.43 rows=1 width=0)
Index Cond: (id = 2)

thanks
Marcos

#17Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Marcos Pegoraro (#16)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi, all! Sorry I haven't written for a long time.

I finished writing the code patch for transformation "Or" expressions to
"Any" expressions. I didn't see any problems in regression tests, even
when I changed the constant at which the minimum or expression is
replaced by any at 0. I ran my patch on sqlancer and so far the code has
never fallen.

On 14.01.2023 18:45, Marcos Pegoraro wrote:

I agree with your idea and try to implement it and will soon
attach a patch with a solution.

Additionally, if those OR constants repeat you'll see ...
If all constants are the same value, fine
explain select * from x where ((ID = 1) OR (ID = 1) OR (ID = 1));
Index Only Scan using x_id on x  (cost=0.42..4.44 rows=1 width=4)
  Index Cond: (id = 1)

if all values are almost the same, ops
explain select * from x where ((ID = 1) OR (ID = 1) OR (ID = 1) OR (ID
= 2));
Bitmap Heap Scan on x  (cost=17.73..33.45 rows=4 width=4)
  Recheck Cond: ((id = 1) OR (id = 1) OR (id = 1) OR (id = 2))
  ->  BitmapOr  (cost=17.73..17.73 rows=4 width=0)
        ->  Bitmap Index Scan on x_id  (cost=0.00..4.43 rows=1 width=0)
              Index Cond: (id = 1)
        ->  Bitmap Index Scan on x_id  (cost=0.00..4.43 rows=1 width=0)
              Index Cond: (id = 1)
        ->  Bitmap Index Scan on x_id  (cost=0.00..4.43 rows=1 width=0)
              Index Cond: (id = 1)
        ->  Bitmap Index Scan on x_id  (cost=0.00..4.43 rows=1 width=0)
              Index Cond: (id = 2)

thanks
Marcos

--

Regards,

Alena Rybakina

Attachments:

0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patchtext/x-patch; charset=UTF-8; name=0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patchDownload
From 56fba3befe4f6b041d097d8884815fe943fb21f9 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Mon, 26 Jun 2023 04:18:15 +0300
Subject: [PATCH] Replace clause (X=N1) OR (X=N2) ... with X = ANY(N1, N2) on 
 the stage of the optimiser when we are still working with a tree expression.

Firstly, we do not try to make a transformation for "non-or"
expressions or inequalities and the creation of a relation
with "or" expressions occurs according to the same scenario;
secondly, we do not make transformations if there are less
than 15 or expressions (here you can put another number, but
during testing, already starting with 3 expressions, the execution
time and planning time with transformed or were faster);
thirdly, it is worth considering that we consider "or" expressions
only at the current level.
The transformation takes place according to the following scheme:
first we define the groups on the left side, collect the constants
in a list for each group, then considering each group we make the
collected constants to one type, find a common type for array and
using the make_scalar_array_op function we form ScalarArrayOpExpr,
if possible. If it is not possible, then these constants both remain
in the same expr as before the function call. All successful attempts
(received ScalarArrayOpExpr together with unformulated Expr are combined
via OR operation).
---
 src/backend/parser/parse_expr.c  | 289 ++++++++++++++++++++++++++++++-
 src/tools/pgindent/typedefs.list |   1 +
 2 files changed, 289 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6d..c5f58aee9ec 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -95,6 +95,293 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+int const_transform_or_limit = 15;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, Expr *expr_orig)
+{
+	List		   *or_list = NIL;
+	ListCell	   *lc_eargs,
+				   *lc_args;
+	List		   *groups_list = NIL;
+	bool			change_apply = false;
+	const char 	   *opname;
+	Node 		   *result;
+	bool			or_statement=false;
+	BoolExpr 	   *expr = (BoolExpr *)copyObject(expr_orig);
+
+	Assert(IsA(expr, BoolExpr));
+
+	/* If this is not expression "Or", then will do it the old way. */
+	switch (expr->boolop)
+	{
+		case AND_EXPR:
+			opname = "AND";
+			break;
+		case OR_EXPR:
+			opname = "OR";
+			or_statement = true;
+			break;
+		case NOT_EXPR:
+			opname = "NOT";
+			break;
+		default:
+			elog(ERROR, "unrecognized boolop: %d", (int) expr->boolop);
+			opname = NULL;		/* keep compiler quiet */
+			break;
+	}
+
+	if (!or_statement || list_length(expr->args) < const_transform_or_limit)
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+
+	/*
+		* NOTE:
+		* It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		* a list of sub-restrictinfo args, and rinfo->clause - which is the
+		* same expression, made from bare clauses. To not break selectivity
+		* caches and other optimizations, use both:
+		* - use rinfos from orclause if no transformation needed
+		* - use  bare quals from rinfo->clause in the case of transformation,
+		* to create new RestrictInfo: in this case we have no options to avoid
+		* selectivity estimation procedure.
+		*/
+	foreach(lc_eargs, expr->args)
+	{
+		A_Expr			   *arg = (A_Expr *) lfirst(lc_eargs);
+		Node			   *bare_orarg;
+		Node			   *const_expr;
+		Node			   *non_const_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+		bool 				allow_transformation;
+
+		/*
+		 * The first step: checking that the expression consists only of equality.
+		 * We can only do this here, while arg is still row data type, namely A_Expr.
+		 * After applying transformExprRecurce, we already know that it will be OpExr type,
+		 * but checking the expression for equality is already becoming impossible for us.
+		 * Sometimes we have the chance to devide expression into the groups on
+		 * equality and inequality. This is possible if all list items are not at the
+		 * same level of a single BoolExpr expression, otherwise all of them cannot be converted.
+		 */
+
+		if (!arg)
+			break;
+
+		allow_transformation = (
+			                    or_statement &&
+		                        arg->type == T_A_Expr && (arg)->kind == AEXPR_OP &&
+							    list_length((arg)->name) >=1 && strcmp(strVal(linitial((arg)->name)), "=") == 0
+							   );
+
+
+		bare_orarg = transformExprRecurse(pstate, (Node *)arg);
+		bare_orarg = coerce_to_boolean(pstate, bare_orarg, opname);
+
+		/*
+		 * The next step: transform all the inputs, and detect whether any contain
+	 	 * Vars.
+		 */
+		if (!allow_transformation || !bare_orarg || !IsA(bare_orarg, OpExpr) || !contain_vars_of_level(bare_orarg, 0))
+		{
+			/* Again, it's not the expr we can transform */
+			or_list = lappend(or_list, bare_orarg);
+			continue;
+		}
+
+		/*
+		 * Get pointers to constant and expression sides of the clause
+		 */
+		non_const_expr = get_leftop(bare_orarg);
+		const_expr = get_rightop(bare_orarg);
+
+		/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table (htab key ???).
+			*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, non_const_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				non_const_expr = NULL;
+				break;
+			}
+		}
+
+		if (non_const_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = non_const_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->opno = ((OpExpr *)bare_orarg)->opno;
+		gentry->expr = (Expr *)bare_orarg;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this rinfo, just add itself
+		* to the list and go further.
+		*/
+		or_statement = false;
+	}
+	else
+	{
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type,
+								array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation. It's been a long way ;)
+			 *
+			 * First of all, try to select a common type for the array elements.  Note that
+			 * since the LHS' type is first in the list, it will be preferred when
+			 * there is doubt (eg, when all the RHS items are unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+			if (OidIsValid(scalar_type) &&
+				!verify_common_type(scalar_type, allexprs))
+				scalar_type = InvalidOid;
+
+			if (OidIsValid(scalar_type) && scalar_type != RECORDOID)
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+			if (array_type != InvalidOid)
+			{
+				/*
+			 	 * OK: coerce all the right-hand non-Var inputs to the common type
+			 	 * and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1; /* Position of the new clause is undefined */
+
+				saopexpr = (ScalarArrayOpExpr *)make_scalar_array_op(pstate,
+												   list_make1(makeString((char *) "=")),
+												   true,
+												   gentry->node,
+												   (Node *) newa,
+												   -1); /* Position of the new clause is undefined */
+
+				/*
+				* TODO: here we can try to coerce the array to a Const and find
+				* hash func instead of linear search (see 50e17ad281b).
+				* convert_saop_to_hashed_saop((Node *) saopexpr);
+				* We don't have to do this anymore, do we?
+				*/
+
+				or_list = lappend(or_list, (void *) saopexpr);
+				change_apply = true;
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		if (!change_apply)
+		{
+			or_statement = false;
+		}
+	}
+
+	if (or_statement)
+	{
+		/* One more trick: assemble correct clause */
+		expr = list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, list_copy(or_list), -1) : linitial(or_list);
+		result = (Node *)expr;
+	}
+	/*
+	 * There was no reasons to create a new expresion, so
+	 * run the original BoolExpr conversion with using
+	 * transformBoolExpr function
+	 */
+	else
+	{
+		result = transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	list_free(or_list);
+	list_free_deep(groups_list);
+
+	return result;
+}
 
 /*
  * transformExpr -
@@ -208,7 +495,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (Expr *)expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 260854747b4..01918e6aeac 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1630,6 +1630,7 @@ NumericSumAccum
 NumericVar
 OM_uint32
 OP
+OrClauseGroupEntry
 OSAPerGroupState
 OSAPerQueryState
 OSInfo
-- 
2.34.1

#18Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Alena Rybakina (#17)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Sorry,  I wrote the last sentence in a confusing way, I meant that I
formed transformations for any number of "or" expressions
(const_transform_or_limit=1). in regression tests, I noticed only diff
changes of transformations of "or" expressions to "any". I attach a file
with diff.

Show quoted text

On 26.06.2023 04:47, Alena Rybakina wrote:

Hi, all! Sorry I haven't written for a long time.

I finished writing the code patch for transformation "Or" expressions
to "Any" expressions. I didn't see any problems in regression tests,
even when I changed the constant at which the minimum or expression is
replaced by any at 0. I ran my patch on sqlancer and so far the code
has never fallen.

On 14.01.2023 18:45, Marcos Pegoraro wrote:

I agree with your idea and try to implement it and will soon
attach a patch with a solution.

Additionally, if those OR constants repeat you'll see ...
If all constants are the same value, fine
explain select * from x where ((ID = 1) OR (ID = 1) OR (ID = 1));
Index Only Scan using x_id on x  (cost=0.42..4.44 rows=1 width=4)
  Index Cond: (id = 1)

if all values are almost the same, ops
explain select * from x where ((ID = 1) OR (ID = 1) OR (ID = 1) OR
(ID = 2));
Bitmap Heap Scan on x  (cost=17.73..33.45 rows=4 width=4)
  Recheck Cond: ((id = 1) OR (id = 1) OR (id = 1) OR (id = 2))
  ->  BitmapOr  (cost=17.73..17.73 rows=4 width=0)
        ->  Bitmap Index Scan on x_id  (cost=0.00..4.43 rows=1 width=0)
              Index Cond: (id = 1)
        ->  Bitmap Index Scan on x_id  (cost=0.00..4.43 rows=1 width=0)
              Index Cond: (id = 1)
        ->  Bitmap Index Scan on x_id  (cost=0.00..4.43 rows=1 width=0)
              Index Cond: (id = 1)
        ->  Bitmap Index Scan on x_id  (cost=0.00..4.43 rows=1 width=0)
              Index Cond: (id = 2)

thanks
Marcos

--

Regards,

Alena Rybakina

Attachments:

regression.diffstext/plain; charset=UTF-8; name=regression.diffsDownload
diff -U3 /home/alena/postgrespro9/src/test/regress/expected/create_index.out /home/alena/postgrespro9/src/test/regress/results/create_index.out
--- /home/alena/postgrespro9/src/test/regress/expected/create_index.out	2023-06-26 04:08:22.903294342 +0300
+++ /home/alena/postgrespro9/src/test/regress/results/create_index.out	2023-06-26 05:36:31.904205986 +0300
@@ -1838,18 +1838,11 @@
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,20 +1854,17 @@
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff -U3 /home/alena/postgrespro9/src/test/regress/expected/join.out /home/alena/postgrespro9/src/test/regress/results/join.out
--- /home/alena/postgrespro9/src/test/regress/expected/join.out	2023-06-26 04:08:22.903294342 +0300
+++ /home/alena/postgrespro9/src/test/regress/results/join.out	2023-06-26 05:36:36.748191699 +0300
@@ -4184,10 +4184,10 @@
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4197,15 +4197,13 @@
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff -U3 /home/alena/postgrespro9/src/test/regress/expected/stats_ext.out /home/alena/postgrespro9/src/test/regress/results/stats_ext.out
--- /home/alena/postgrespro9/src/test/regress/expected/stats_ext.out	2023-06-26 04:04:26.560435094 +0300
+++ /home/alena/postgrespro9/src/test/regress/results/stats_ext.out	2023-06-26 05:36:48.300155667 +0300
@@ -1322,19 +1322,19 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff -U3 /home/alena/postgrespro9/src/test/regress/expected/partition_prune.out /home/alena/postgrespro9/src/test/regress/results/partition_prune.out
--- /home/alena/postgrespro9/src/test/regress/expected/partition_prune.out	2023-06-26 04:05:30.305209590 +0300
+++ /home/alena/postgrespro9/src/test/regress/results/partition_prune.out	2023-06-26 05:36:58.912120163 +0300
@@ -82,23 +82,23 @@
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
 explain (costs off) select * from lp where a <> 'g';
@@ -515,10 +515,10 @@
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +596,13 @@
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -1933,10 +1933,10 @@
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
@@ -2265,11 +2265,11 @@
          Workers Launched: N
          ->  Parallel Append (actual rows=N loops=N)
                ->  Parallel Seq Scan on ab_a1_b2 ab_1 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a2_b2 ab_2 (never executed)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a3_b2 ab_3 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
 (16 rows)
 
 -- Test pruning during parallel nested loop query
In reply to: Alena Rybakina (#17)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Sun, Jun 25, 2023 at 6:48 PM Alena Rybakina <lena.ribackina@yandex.ru> wrote:

I finished writing the code patch for transformation "Or" expressions to "Any" expressions.

This seems interesting to me. I'm currently working on improving
nbtree's "native execution of ScalarArrayOpExpr quals" (see commit
9e8da0f7 for background information). That is relevant to what you're
trying to do here.

Right now nbtree's handling of ScalarArrayOpExpr is rather
inefficient. The executor does pass the index scan an array of
constants, so the whole structure already allows the nbtree code to
execute the ScalarArrayOpExpr in whatever way would be most efficient.
There is only one problem: it doesn't really try to do so. It more or
less just breaks down the large ScalarArrayOpExpr into "mini" queries
-- one per constant. Internally, query execution isn't significantly
different to executing many of these "mini" queries independently. We
just sort and deduplicate the arrays. We don't intelligently decide
which pages dynamically. This is related to skip scan.

Attached is an example query that shows the problem. Right now the
query needs to access a buffer containing an index page a total of 24
times. It's actually accessing the same 2 pages 12 times. My draft
patch only requires 2 buffer accesses -- because it "coalesces the
array constants together" dynamically at run time. That is a little
extreme, but it's certainly possible.

BTW, this project is related to skip scan. It's part of the same
family of techniques -- MDAM techniques. (I suppose that that's
already true for ScalarArrayOpExpr execution by nbtree, but without
dynamic behavior it's not nearly as valuable as it could be.)

If executing ScalarArrayOpExprs was less inefficient in these cases
then the planner could be a lot more aggressive about using them.
Seems like these executor improvements might go well together with
what you're doing in the planner. Note that I have to "set
random_page_cost=0.1" to get the planner to use all of the quals from
the query as index quals. It thinks (correctly) that the query plan is
very inefficient. That happens to match reality right now, but the
underlying reality could change significantly. Something to think
about.

--
Peter Geoghegan

Attachments:

saop_patch_test.sqlapplication/octet-stream; name=saop_patch_test.sqlDownload
#20Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Peter Geoghegan (#19)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 26.06.2023 06:18, Peter Geoghegan wrote:

On Sun, Jun 25, 2023 at 6:48 PM Alena Rybakina<lena.ribackina@yandex.ru> wrote:

I finished writing the code patch for transformation "Or" expressions to "Any" expressions.

This seems interesting to me. I'm currently working on improving
nbtree's "native execution of ScalarArrayOpExpr quals" (see commit
9e8da0f7 for background information). That is relevant to what you're
trying to do here.

Right now nbtree's handling of ScalarArrayOpExpr is rather
inefficient. The executor does pass the index scan an array of
constants, so the whole structure already allows the nbtree code to
execute the ScalarArrayOpExpr in whatever way would be most efficient.
There is only one problem: it doesn't really try to do so. It more or
less just breaks down the large ScalarArrayOpExpr into "mini" queries
-- one per constant. Internally, query execution isn't significantly
different to executing many of these "mini" queries independently. We
just sort and deduplicate the arrays. We don't intelligently decide
which pages dynamically. This is related to skip scan.

Attached is an example query that shows the problem. Right now the
query needs to access a buffer containing an index page a total of 24
times. It's actually accessing the same 2 pages 12 times. My draft
patch only requires 2 buffer accesses -- because it "coalesces the
array constants together" dynamically at run time. That is a little
extreme, but it's certainly possible.

BTW, this project is related to skip scan. It's part of the same
family of techniques -- MDAM techniques. (I suppose that that's
already true for ScalarArrayOpExpr execution by nbtree, but without
dynamic behavior it's not nearly as valuable as it could be.)

If executing ScalarArrayOpExprs was less inefficient in these cases
then the planner could be a lot more aggressive about using them.
Seems like these executor improvements might go well together with
what you're doing in the planner. Note that I have to "set
random_page_cost=0.1" to get the planner to use all of the quals from
the query as index quals. It thinks (correctly) that the query plan is
very inefficient. That happens to match reality right now, but the
underlying reality could change significantly. Something to think
about.

--
Peter Geoghegan

Thank you for your feedback, your work is also very interesting and
important, and I will be happy to review it. I learned something new
from your letter, thank you very much for that!

I analyzed the buffer consumption when I ran control regression tests
using my patch. diff shows me that there is no difference between the
number of buffer block scans without and using my patch, as far as I
have seen. (regression.diffs)

In addition, I analyzed the scheduling and duration of the execution
time of the source code and with my applied patch. I generated 20
billion data from pgbench and plotted the scheduling and execution time
depending on the number of "or" expressions.
By runtime, I noticed a clear acceleration for queries when using the
index, but I can't say the same when the index is disabled.
At first I turned it off in this way:
1)enable_seqscan='off'
2)enable_indexonlyscan='off'
enable_indexscan='off'

Unfortunately, it is not yet clear which constant needs to be set when
the transformation needs to be done, I will still study in detail. (the
graph for all this is presented in graph1.svg)
\\

--
Regards,
Alena Rybakina

Attachments:

regression.diffstext/plain; charset=UTF-8; name=regression.diffsDownload
diff -U3 /home/alena/postgrespro7/src/test/regress/expected/create_index.out /home/alena/postgrespro7/src/test/regress/results/create_index.out
--- /home/alena/postgrespro7/src/test/regress/expected/create_index.out	2023-06-27 10:20:52.287769054 +0300
+++ /home/alena/postgrespro7/src/test/regress/results/create_index.out	2023-06-27 10:32:20.701220051 +0300
@@ -1838,26 +1838,14 @@
 EXPLAIN (ANALYZE, COSTS OFF, BUFFERS, TIMING OFF, SUMMARY OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1 (actual rows=1 loops=1)
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   Heap Blocks: exact=1
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1 (actual rows=1 loops=1)
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
    Buffers: shared hit=5 read=2
-   ->  BitmapOr (actual rows=0 loops=1)
-         Buffers: shared hit=4 read=2
-         ->  Bitmap Index Scan on tenk1_thous_tenthous (actual rows=0 loops=1)
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-               Buffers: shared read=2
-         ->  Bitmap Index Scan on tenk1_thous_tenthous (actual rows=0 loops=1)
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-               Buffers: shared hit=2
-         ->  Bitmap Index Scan on tenk1_thous_tenthous (actual rows=1 loops=1)
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-               Buffers: shared hit=2
  Planning:
    Buffers: shared hit=51
-(17 rows)
+(5 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1869,12 +1857,12 @@
 EXPLAIN (ANALYZE, COSTS OFF, BUFFERS, TIMING OFF, SUMMARY OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                         QUERY PLAN                                         
---------------------------------------------------------------------------------------------
+                                      QUERY PLAN                                      
+--------------------------------------------------------------------------------------
  Aggregate (actual rows=1 loops=1)
    Buffers: shared hit=5 read=3
    ->  Bitmap Heap Scan on tenk1 (actual rows=10 loops=1)
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
          Heap Blocks: exact=10
          Buffers: shared hit=5 read=3
          ->  BitmapAnd (actual rows=0 loops=1)
@@ -1882,15 +1870,10 @@
                ->  Bitmap Index Scan on tenk1_hundred (actual rows=100 loops=1)
                      Index Cond: (hundred = 42)
                      Buffers: shared read=2
-               ->  BitmapOr (actual rows=0 loops=1)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous (actual rows=20 loops=1)
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                      Buffers: shared hit=3 read=1
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous (actual rows=10 loops=1)
-                           Index Cond: (thousand = 42)
-                           Buffers: shared hit=2
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous (actual rows=10 loops=1)
-                           Index Cond: (thousand = 99)
-                           Buffers: shared hit=1 read=1
-(19 rows)
+(14 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff -U3 /home/alena/postgrespro7/src/test/regress/expected/join.out /home/alena/postgrespro7/src/test/regress/results/join.out
--- /home/alena/postgrespro7/src/test/regress/expected/join.out	2023-06-27 10:21:22.096306419 +0300
+++ /home/alena/postgrespro7/src/test/regress/results/join.out	2023-06-27 10:32:26.049288441 +0300
@@ -4207,10 +4207,10 @@
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop (actual rows=201 loops=1)
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    Rows Removed by Join Filter: 102
    Buffers: shared hit=98
    ->  Bitmap Heap Scan on tenk1 b (actual rows=101 loops=1)
@@ -4228,7 +4228,7 @@
    ->  Materialize (actual rows=3 loops=101)
          Buffers: shared hit=8
          ->  Bitmap Heap Scan on tenk1 a (actual rows=3 loops=1)
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                Heap Blocks: exact=2
                Buffers: shared hit=8
                ->  BitmapOr (actual rows=0 loops=1)
@@ -4236,13 +4236,10 @@
                      ->  Bitmap Index Scan on tenk1_unique1 (actual rows=1 loops=1)
                            Index Cond: (unique1 = 1)
                            Buffers: shared hit=2
-                     ->  Bitmap Index Scan on tenk1_unique2 (actual rows=1 loops=1)
-                           Index Cond: (unique2 = 3)
-                           Buffers: shared hit=2
-                     ->  Bitmap Index Scan on tenk1_unique2 (actual rows=1 loops=1)
-                           Index Cond: (unique2 = 7)
-                           Buffers: shared hit=2
-(33 rows)
+                     ->  Bitmap Index Scan on tenk1_unique2 (actual rows=2 loops=1)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                           Buffers: shared hit=4
+(30 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff -U3 /home/alena/postgrespro7/src/test/regress/expected/stats_ext.out /home/alena/postgrespro7/src/test/regress/results/stats_ext.out
--- /home/alena/postgrespro7/src/test/regress/expected/stats_ext.out	2023-06-27 00:35:33.761010034 +0300
+++ /home/alena/postgrespro7/src/test/regress/results/stats_ext.out	2023-06-27 10:32:37.537436241 +0300
@@ -1322,19 +1322,19 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff -U3 /home/alena/postgrespro7/src/test/regress/expected/partition_prune.out /home/alena/postgrespro7/src/test/regress/results/partition_prune.out
--- /home/alena/postgrespro7/src/test/regress/expected/partition_prune.out	2023-06-27 10:31:39.596703531 +0300
+++ /home/alena/postgrespro7/src/test/regress/results/partition_prune.out	2023-06-27 10:32:48.285575599 +0300
@@ -82,23 +82,25 @@
 (2 rows)
 
 EXPLAIN (ANALYZE, COSTS OFF, BUFFERS, TIMING OFF, SUMMARY OFF) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                      QUERY PLAN                      
+------------------------------------------------------
  Append (actual rows=0 loops=1)
    ->  Seq Scan on lp_ad lp_1 (actual rows=0 loops=1)
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2 (actual rows=0 loops=1)
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
-(5 rows)
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+ Planning:
+   Buffers: shared hit=16
+(7 rows)
 
 EXPLAIN (ANALYZE, COSTS OFF, BUFFERS, TIMING OFF, SUMMARY OFF) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append (actual rows=0 loops=1)
    ->  Seq Scan on lp_ad lp_1 (actual rows=0 loops=1)
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2 (actual rows=0 loops=1)
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
 explain (costs off) select * from lp where a <> 'g';
@@ -518,8 +520,10 @@
                   QUERY PLAN                  
 ----------------------------------------------
  Seq Scan on rlp2 rlp (actual rows=0 loops=1)
-   Filter: ((a = 1) OR (a = 7))
-(2 rows)
+   Filter: (a = ANY ('{1,7}'::integer[]))
+ Planning:
+   Buffers: shared hit=16
+(4 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
                       QUERY PLAN                       
@@ -600,9 +604,9 @@
 --------------------------------------------------------------
  Append (actual rows=0 loops=1)
    ->  Seq Scan on rlp4_1 rlp_1 (actual rows=0 loops=1)
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2 (actual rows=0 loops=1)
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -1933,10 +1937,10 @@
 
 EXPLAIN (ANALYZE, COSTS OFF, BUFFERS, TIMING OFF, SUMMARY OFF) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp (actual rows=0 loops=1)
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
    Rows Removed by Filter: 2
    Buffers: shared hit=1
 (4 rows)
@@ -2269,11 +2273,11 @@
          Workers Launched: N
          ->  Parallel Append (actual rows=N loops=N)
                ->  Parallel Seq Scan on ab_a1_b2 ab_1 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a2_b2 ab_2 (never executed)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a3_b2 ab_3 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
 (16 rows)
 
 -- Test pruning during parallel nested loop query
graph1.pngimage/png; name=graph1.pngDownload
�PNG


IHDR�Xr�sRGB��� IDATx^��x���$� ��. D�w�H�V��bAPD, z����.M��I��H(!�$��O�e7�fgvw�M�;�s�+��3g�sfv����' !!!,$@$@$@$@$@$@$@$@$��(�|�g�,        E���H�H�H�H�H�H�H�H��	P`�t��q$@$@$@$@$@$@$@$@X$@$@$@$@$@$@$@$@>M������#       ���        �iX>�=l	�	�	�	�	�	�	�	��	�	�	�	�	�	�	�	��O�����a�H�H�H�H�H�H�H�H�(�8H�H�H�H�H�H�H�H�|��OwG$@$@$@$@$@$@$@$@��1@$@$@$@$@$@$@$@$��(�|�{�8        
,�        �&@�������	�	�	�	�	�	�	�	P`q�	�	�	�	�	�	�	�	�4
,��6�H�H�H�H�H�H�H�H��c�H�H�H�H�H�H�H�H��	P`�t��q$@$@$@$@$@$@$@$@X$@$@$@$@$@$@$@$@>M������#       ���        �iX>�=l	�	�	�	�	�	�	�	��	�	�	�	�	�	�	�	��O�����a�H�H�H�H�H�H�H�H�(�8H�H�H�H�H�H�H�H�|��OwG$@$@$@$@$@$@$@$@��1@$@$@$@$@$@$@$@$��(�|�{�8        
,�        �&@�������	�	�	�	�	�	�	�	P`q�	�	�	�	�	�	�	�	�4
,��6�H�H�H�H�H�H�H�H��c�H�H�H�H�H�H�H�H��	P`�t��F��
\���k�4C�|�Q>���o��90dZ;(��k����L�d�����O����7:��w���va��p��M5dBB��B��xnh=O
!��	p<s<?�����O�K��6�H�H�'	P`�d��V�~�{��@���d����8k��X��]�?��)��<��;�{]�y�+�m�����d��-OF�����"!!YseD���<5�X�C$������_�;�?]/)�s�`  �$��k���9rc��d���4��Ov����y�4��7�o�OPD��1�����n��Q�����)V`��/����W����Z�����(y���8�9�}wt�e$@$@$@�J��V����p�v��x�<�P�P���������(���X
,���~�����#"o5���5���5�J�&$�q�
D@�W�j���{��������o�kt<p{  H
�Z`��_��Wp��s����S��-�[<j���?��_�lC�W*��m>���V�>���^U�dr���o���|���09s�H$Z!G�p�l]u��F��@K��E��g��^�����c���6����(���L���t�*h��c6�O�������X����C�����*�5[�@��ex�|������_��oUG�b��x�������(Y9��{�����Kr��qK��=kO����I�����U�'�H�\6������������>y�fE�^�p`�iH��;������]	��g���;q��u�+�|�B��Fud�����D`����F��+�G�����]��[wQ�Dv�{�*N�}�Go��=��U��4�������O�	��g���r�In5@�'���_"K���9��?j�s���G�#���y���H���G��a���8u+��4��?F!M|wv�<��n���z�'R���6��i����N
�����w�IH�K<�ir�c��������DS����W�xsu<�g�vz�����+�w�\�z�_�i�~ht{#�wF��+��F�ot,s{  �$
,K^�D����3�#k���DL��>E+�V/���f���J<���_%(a��i%<�h\T�pZIl�h��-���+��i���F�,���7�DX����#���l:����4���Kf�i���p��5�7i��
��}!�^���G��`��qp�Y�~���W�R�������\�������3a���X����~_7uk���B�{5[�@�R9�����#��m%���V\i�W//Q}#}%��zW����3����n	,�=�/�"c��od��=�NB��0~k|K�|�,3�����xs��o�/S�_�j�U����D�S�+&�B���]sf__�T�A�$���)��?��RU�!,K(�&^������~��m�'E�*y��.)�-���:.�����rOF����X0v�m�Z�����c�m=0r?��6/9����Q��c�^%�+5*�t������+��#<�}���/��7W���qg�=)}���}g�z7r�
O��C�������|?m�����I�H�H��(�t,.����sQ�LN�CJ��|������3�#s���~�t*���*���������$���������}�~�a��}J����wo-���'����U�Q����=��B��5G���9rw�.&��D�I��}�����xoj[�$��/R��Y��pf�����Gv_���p9
���[�����W,�M�.��gE������Z�cm��1@IE�D�
�<WE�����G�<
��	�
����|�VE
����m�8Xf�1�3�98oF�������-,�Yd�7�-S���V��N1���[�5�����H�7�������5_��r����j�������S��9G��s"�����>�g7j�/���NUB����j�~"iQYre@�<aJ��M��H�n�
O~_�p�����5z��t�����;�����<�]��3r��\�F��F�������OW�w�ot|s{  p��_,�Z(\��X2]����`���'��%��<x��������)|2���g
x)>����BM���{R$RK^~e�J
�9n����|&JIM������1a��'O�J�b6������q��x�������3��
c5"���r3V���wy�n��2����b��Z�Ij%E��Z1����������.xD`���E�����m�VF��m��j�9XIz��Q�I�����h�2�d\=�nm�iW��pC;�QS^}]`��7��R>l?[E~�{7�o��H��w[^R�6z��}D,�P~z�d���r�i��}�7z?���i�"}����*���c�����(�@7�_����~7�����I��_�_#�wF�����������c����������N���onO$@$@��k���D9����2���������#�<���iw7��i�����U�1tNG�)r?����&�D��X�h*��y�~��C������i�Z��FB�g�rx�2�%���I��L�h]$rI���g�'��a�?*Z�H��6ukv�����Tq<?�6�O�"#B�^�#����n�:{�7Z�&E����ig"|]`��^@�r)�(2v�������g��c���������d�e?�V��$��Y�/��:�����z����D�q�����'�?���M����Z��xP`�_�����7��~����I��_�_#�wF�����������c����������N���onO$@$@��k��7��5d�o$Sv��6�wm��LS�� ��L���N���R�'��%]-����X_XZ�G,��@���f��t;W��w��4���_U���/<�$�$@��OP�>	,�I��b������e����n�A�D`�|���dQ{���2��������h�S����_��v9�[�b��X�j�L������;��O*����1$z���8���dR$JR"N������n������D����:���J�]�)������h���������-�\iOJ��	G�wF�����������8r�}gt<�z���~���'  w	P`���%�cc�0��|���A��8d��A�Z?�B��VCV���q���hX��X���{@�^����2+G��~{+}im���(^n��W9���sMXH������;�b���On,-������r�X?��
���'"��I*����������2����z���?s�F��]����Q�"	�%���G`XF�?I�I�.y���F��IT����>����z�Q�����Z`%'v����6������)�F����n�����l��J{4������F����������F��F�w&���w���7z�q{  p���5���X3��Zq������&�V@�W����Dt�Hj���Za�������� �,���'���C�����g�YE������u��Zm\l�;`���M����g?���J����~(	���R�^H������A��KY�����-���eI��K�E��K�<iRm-�Nr�����|��_g�F����
�����B�S�&�e������r�^�V���Q�~ag�^���XF�'f,Wy�����2��F�w���h{�X�����1���������;#��j��q2z?�����;��������O��H�H��%@��S`I��1���]�����w�����u��j��3�*zCgw�I�,/��!bBK4,�jh��JR�x�^=K�����d%2Y5M^��r����j:b���XL��9_m��G�f�#��
"gX�[�aK��w~jcY�,>.#_ZI\���N�Y0q5=O>`�k�3g�R��L�����Q�DvH��V��G���g�����TU����=!�$!�����)������8��Oi�B�������7c�t�����c�g��p6���/�`����kD���Zg�_�Xf]_�
��,���c�0q�*4�Va]�s2�r����W`���-���������*�F�������,��F����w<{�=F�����=���5�}g�|��_��������~��F�w�ot<q{  p��_,@Z�� ��
B��#��"��Q�9��%�Mi��� �wY	���sUB�f�W�J+Z��H��� 8m�n8���N��e�A�����X��n%���eH���O*)b��]�G[�N��JU����oa��]��/{���+�D$I(i�L�Q&	��]��~_���K�Vl>�^�d�Z�"Y���z�X����V,�e�J�\�yq�oj��#y�4����A.����\	���VALt,���r�
b��#jU���7B�29�%�a�&"���(1'���,��������?�G%�oj[�c���h|$W�������2�������'Q�z~��ms��h�l�([���N"���8���_�F������Ft��S�\Q��d�|�8C�{z��<*��'�Y��Q�%�m�����D�p�����I�?�n����$�HN9w��~#�i��ZW��O~_���F���cd<sF�����+�wF����k�~ht{��wF����G/���^��H�H��k���������t?�z�g�9�#�\Y��;�ct��J�XGw�6;V���q�p��0W������zI��v�����������9w�L����E���u�~�6����C;�)����,h��	DE�����(��$�c�^��'�N�����C�X����Zl\x(��F���z�m(+�It�����^|E�Umn�e��������!��v��J���K9��}2�R����C�O���\i�����H'{RW�����5����ZI�^~,�����^�2([�����G�)	�X����Fu���Q))����t�p-E
���e3��it��_NZ���_n��X���e�_"e&�e�H�\z���vf\_�,����'�v�Yw��oAnX��dD��� ���ev���~��i��ZWNF�������������x����g�c�H{R��w������s�j}d�~hd{��w�x�2�~�����	�	���	����4D�G�$`y��P]��d��+	�eB���*�8���H�H�;�}��<
	�	�	�X��'y���=��2����K*���v�n�k3���f/*��-a�$@$@~�q,�	�	�	!@�e��%/���!����*\��Y��\)������)�
�)����F  �d	����H�H�H�
,#��-	x����,I�%���S�j��<E2��r��$
-  ����wy�h$@$@$��	P`��d�I�H�H�H�H�H�H�H ���J���#       ��N�+�� �O$@$@$@$@$@$@$@��V*�`�	�	�	�	�	�	�	�	�tX)��~       H�(�Ry��H�H�H�H�H�H�H�H ���J�=���	�	�	�	�	�	�	�@*'@���;��G$@$@$@$@$@$@$@)�VJ�A��H�H�H�H�H�H�H�R9
�T��<=       H�(�Rz��$@$@$@$@$@$@$@$��	P`�����	�	�	�	�	�	�	�@J'@���{��'       �TN�+�w0O�H�H�H�H�H�H�H�R:
����l?	�	�	�	�	�	�	�	�rX���yz$@$@$@$@$@$@$@$��	P`��d�I�H�H�H�H�H�H�H ���J���#       ��N�+�� �O$@$@$@$@$@$@$@��V*�`�	�	�	�	�	�	�	�	�tX)��~       H�(�Ry��H�H�H�H�H�H�H�H ���J�=���	�	�	�	�	�	�	�@*'@���;��G$@$@$@$@$@$@$@)�VJ�A��H�H�H�H�H�H�H�R9
�T��<=       H�(�Rz��$@$@$@$@$@$@$@$��	P`���������|iz}��>�����+*"�����;����;	
F��e����n���O���n�Q�D6�x��G���2u��F�A5=V���0�����g�X���\{����7~�g�=�,�28<����a����[�����+y�q?C�W���7���r�o�k�O�Mq<�}a�I����uz����`^���D|F�H ��E�������%�g�9�5��_��Wp�v�����3���(T:G��|&
L��ZmJ*!�+���k���cx�_%�-��e��&��v��sg�����Y�6��c�=*S) R�P��pz/6O^W'�e�����,V�������aYCQ�D6��S�������k�n!��
�}s9|M`9��k�����at��������>#��?�����3G	�Xn��<�F]�F�7k<PK�B��5wF7j�����V��<�i��;-2~����x��x����wv�GBB���a�	�	���85=����S7��pW
,3��_�^�e�����>F`��?�z�����Q��/����p��+�ck�%�k��$����}�����zH���3���92����y��B���������q�A�Q9���}m)^��9JW�o�����V���
����_:�9_m��D��x�|.t|���D2�����!�|�/��?YDM�Il�l|��&�~`�z��L����F��s����)�����6�T���v#8$�|�SG���c����j*j�) IDATK+���S�W/�D����g�_|��$z��/�c�����.j�,�>��y�����V��w�=_=S��������(�'�s�>]�#�/ �v,���~�2���9��;��Z��������9f�����^E��x|0��M���������o!Cx*>Y�^������j���j�I�6�6j�J�b]n=�������uC�������y8-T*��������x��<�>���#E"�&���e��cU>�h�7��E�������5'�5&�^;
�a��d��~�����#&���U���C�|`
��1���mX7� ���`9'�C;������)wn�b��[�g�	5-6k�0��XOv.kS��+~�]��X(^1������-�I�/��~�W	��y���G�q�{�	�{{�����o��}�%M�{u��6�t��\7r��������l��	<V���.��;}�
�xL����Q�U0���"������������h�v�I��e�Jv��������~#��0@��*�{F�k�����b�"��)��L`����J��4�A(�xtP�s��6�Q���:���5���m�
���um��X�=^���l�����>#���z����H@#@���X�#��zyQ��gu@h�������!��A"��������-�&�2C����^�EpH�!/�m�VF�'����_l�#�r�v#���h%�&^��# �#Y��r,k�y��z��6:��%2)[�0%�F�\����uS��,�>|aU��){0��mJ�T�S�\���������K�i���Z^nE��Y
�����%WF�K��-9�d�P��� G�p��c�����P����}�_����)))�E����8d��Q�g��=��mg�c��x
�����������"EJ~�>~��g����1u�:�����Z���A�Y��I�Z&-�gP"��5��������#�wn�E����[yU�/���\�Bx������]'">�|?`�T/�@,�"��Z�\�R�|���+����+���/<��e,.�S�a�Xz�����_X���v�;s$�'�U/�F���_RQ�r-������J���"/�_��P�Z����8uo�~������!R���d��.�	����x/Z!��F@2�D8�����K�����|`�Z�'������������~n��_o����p��jK���[�����"0(1
�H��?�
���W��s�~l��Oi�B��?�?9����z���~������g�=~U?D������X���^�(Y%$w��kw�����S$�M=r�Q]�Y1��"���^�ME)K�#E�=^���l�����W|F�3�����-	��c@NEp��}�Zd�Y���_X����<�J�����PQ��X���@"f�����l�%"�5��=WQA�q	�x2*7.f�����������5WoD����_Vm�3�P��%�r>"&}�Z�B,�N";�Z����T��h2��*���V$:D�`F��a��k�m1��E�W�>��v~��.�hE�������l�!9���@��9��>����y#<����S�9r#�N����H�&F���D���x2��J
Q�L$������c%������#�R�':[�W~����$>]�Uo7?��L)Q)�C�%���{���J;D�hcO$��x�7���n�nX1y�E`�R�c���H|�u��6"e��<q%�DQ�ub-����rX�D�-�y�T������A��$��`�Di#cZ�]�����y���h�l�",EX/~�$�4-��&�"5a�������a��<���o�"b[�,�Z��j���*��E]�-o����=@�KJlL��_�8��m��H`�m������I��	,���O��O>bs
�	,�r-�}�������v��
/X��r��������,Q���k�q���z��Z�A�X�3�-'>#���g>#���p+H�(���WGI�%��m��F+25LDQ�|a�U(3^���s�>m%/��eT����Z�^{��h�'��1n��.����U�'������OG�h��N����a��U��!mf������[���zF{ad�$'�d����/~�fU�d�N,��c7�dy��(�y�����wB����q�#���`�}�-��p
�6mN�
�p*U5�%"�H�$:g���J�I����Q�na�#��K�Y��=%�D��8��L5���o��`�l�u&�D^YKb����	�P9�:�h��,��22f%�r��� 8$�)�Q�FNT���U�m)��YPEO$��"`*�/�R����f�Hmj�&������@��UT����q�!L�x�+J$��3�����Q~"�$�P�M��w	2��Q����������6y�$*N"1_�_���H`�m������K�4���������K�;?�y ���)�I)m^r��\�)-�Xd�D ����M��������=�g��,c�����|F�Y�gc��[�@J%@��F����D���4�"XE��|�f��6���c�R��|��r�Y{i��aiE�%����A�ZC{��i����8�
,�~�|V"�d5%i�&��l|Q	�O���$�uRt�r��t���X��)�[���f+9�d����,y��n�Kn%Q7rL�K��&W$2E���yN�*]���ib$�����C�7��W�B5[���_�R0���a��h���i��O	,Y��Z���DH������J*J�
,������6�9o9���j���CcV�-6���D�h�@�����[5c��z������:�Q�"\E.5�VAM'N����'K�WZ�|ZI�g�=�,�����c�~���U%_��sKz/��OPQ��mI��"�$?����,�E%��_�*K�;�|���o6`B�@�.�����?F����.�~��i��&@~�HZ�Xr��=s��GT.D��h%����������=�g��o/�;�������S|FH]��<�C�K%����%������J���_���iK��+����w��y�$�C�c�������8�
������	yi�'�$oUH����������������4K�A�N�kZ}X�ww�����1E`I�������.�,"�DH���"9�>{n���6��"�^�������F�����L��
H��Y`
n9]]��Xd��]D��1;���jj�\����0c9����H�]��)+��4�$F�5��EGE���I�l�(	�%B�Q�'��������x��6v�D����#���_�%�V$GX�����#����z���k���N�� �P%��!���[��X�B/"Z�z��#���QVJX|Fx�����G.=�x>#��K�w,�R��"��<A��
�zVTD��	#�pd%�a���l�6	���;���7�i7Z�vi��L(�J$���V#��U�f�+���=��<��B��Dw��_�_I�'W���p�����l���c��Fr}��1M�W`i�l�J?I�*���l�xJ`9����#�����Z�i�����W��2�h���O8K��:�JA����S>Y����������5wF�*�	,=��W]�H+Ivl�Mx��=-K���YY�����b��V��R���q}K�u��DV�T�O��@�����H�)ErE�T]I�����J�\���EOXG7J�/�����X�h)+y��r��-�����\^��������V<����I�~Y4"iy���i[-{'������?z����Nz���=�������w��r��w��(�3����s����g}�������`,%�X���A�=�[�@j#@��F���idD4:�I�><�2�P���<x{b+�px�y�����n���_�$a�H.I\,/["�$�Cr2I�L�:��v�+�$=o��*JUI�����z�j�lg���D"��|;�������A�ny��r��]���:�J���$�����&S�$Qv�7����n�&�$yo����L.K��d�'����>���n_��b(y�$�E+�XF��G`�Jy��[����.��#<���Inl:UMA�1V�U	�d_V4��ej��}.�:?���N��2��2����
v���2%&8�V!t6�p��C����j��uA�<�r1���{z���&��LI���t�?���3;�L�sv��yJd�����I�
JbI���Q9��HLR.��y��.��W��(�B�����&��D`�~�.�'���c���@8��n��A�X������{{N��.�j!_�,8u(3���r��4H)z������]��}H��J�k�����D���Lr��_M�w���Z~��~���Y���K����v���^[��d�s)����^�K��,�"?��
������C~��{��cO�o�^qv���}�g�q������#����g��8|FH�_�<3�$@��F�;J�.U����L�$�	����6+��T#�e!/���BU+�����_o��mgU�U�G���J
�i����f��*���.Y]����
�@�U*m\��_**Go�TF-����_%J8��R�O��H�%bL�4���:��H�8X����,��Kk�*>���K�1�<�ju��xJ�\I#��EHe�������q'�T�N��Hl)z�\������B��
�p��>�K����������Z�SY#�^����1+QO�#V��$��D<]�`���S����?vM��c�.����8�M�}���N�x�%���������YV)Vr~K&�R�JdW+lJT�����Q%����ie)x+2&��-K��E��Xz�/+���R�se�5YA���VUL:n���[�Q�/)���R���?F�g�6�0*���E�o���z��EG���T"��eF�V%�B_�^��=/�j���{Z`i��|F���g>#��'S�)z�c����g���}�3!#(�����$@$@$@$@$@$@$@$@^'@��u�< 	�����	�5�Yi�|ET��8]��H�H�H ��3B��c�!	���P`y�%k"       0��	PY%	�	�	�	�	�	�	�	���P`y�%k"  p���eG�x�N��f�B��������"+�~��<�������I��s.���������	�	�	�	x��a�P$@$@$@�	�	#_Z����B����s�Q,���vB�<u���=�Nb��������:X��V+r�ID���.7"   ��G������I�H�H��L�d�Zb��O���U�V�����g%]�^��
�����V������u�F`�������b��=X��r#   xx�V`���~x����92���1��K��3��i9����U�g3��	B�� \�y����}�Y2����8D���=�3s:�	
�+"�j�,�';������y�T$��n�����x�	T�����k�����?���a�-�^\.]���X��uy�&~w�	�u���L�&��q%2�����
a��������F-����Bp�V,b��;��/>��-�/��'II	P`qL�F��4���)��g,G���g
,[��(��yj��Wb5&}�o�k�V�g�	������H`I�������k���5�j�����=<Q1XF��>8(B����\�4C�4J`���/�����<#�$�G�%�D����?����^��9S`���|�X�a,G�����|��Z��B�`�6=�o�)�|�&�6<�	���|����4��=�;�8f#������ ��
��&����< 
�D��G P�����y��"������{(	�#
,�u/�3���)��gL���Xr�������Z��h����L��~�^���`�'�V��Y����:����S
cviN!t	���8��.�7�B����Smqq
�����S
�T���v*X�����)�����KL��\��g
-@>�<U�C����t�T$�U+G����}��������3+�v,2d
�[�["W�,�������|�X�3�#P`y�3�wF���(�|��Rp�(���<
,�S`y�1�8��|��tT�����%��r�^|4�2eOoiH����3Lhi��I����w[NG���P�vA%��C�p�j4DZie��SX��v����B�@������|�X�3���c9
��F���(�|�wRx�(���@
,�S`y�1�F`���X0v;�^��<�dA��5U���������[vV]+]-?��i�@=�B��k��HX�s��2�1�wS`=��S�7�x$�"@��[���ZC�e~wR`����;�)�(��7��?s`y�'(���L�e>c
,�0������H��|����P
n���G�e>c
,�0��J�t�$��R���I��7���;�@������@|�^0
��W��z>�Gq:��9����Sm93�;��G�=X��'��EX�w%���)����;:N|�[���F�!X�z6G���x
�D��/
��=���>{%���)�<���;8���!A�GP`�HG��fP`���X�3���cX��ME�}����"��H
,�
=
����+��������������<�XC�lE���g
,
,��4�e��#X2q"��P���]	��W�L�&�y�66���� [^��;�ph�UR`F�����K���(�\ggd��!AH��7����$�%cZ���CtL��=S�����2����|=���:!N!|8��,�p��J��z�`���F����wQ����X��X��L�����va��vZ��������:�r��j6��U@���*��64aY������Q`y���#���l�����X�w2����X���/+06N�E��� ��r��JJ��;�.�Q(����+�s�V!��)�����A���9�wF���B��9���D����vTn�������@V+�?�)D�P�<����Z�3F���{_��c7��������y�3�xK`y�O�e� `������|�X�a,G��~�md<5V��Qt��we�P`yo�Y��;�)�9GE�D�e��#<���J�����X���g
,�X�g�b�lX�>������x�Z�G�?�=6/9�M�A"����ZmJ�mO��Y�6�����F�&����j1$Q^OE"W�L���1���A����kU-�������f�;z
!�iP�iq��_U���7����?�� z}��>�>����~�W��@���h��*>Y��������h�|EL�gG�����u��[�x��d4�Qk����/T������Z�\u��R��s�Go���"S������h�BE�P���2l
n;�L�B��K�����
M!�q53Gn�?��"0(���G�5�><D�AO�$������;�\�<
���N�e>c9#���95,�����@�g��S������R`yg�%=
�w�S`����|�r
,�p������f(��.}X�C����z�9X����gC��A�^��`
	
F�L�BeH��(_���RW/�������Q����s���|�%���/����]�a���(R6��F�D��[U�W�l��+P�]i%��������s�~�r|��y�4��J�������/�j�O����'1��?0`BK{,��~���X��v�fL�&�V@��y}9�������_��<E�`��x��z����?���3�#��]n5C�g��%U�1o��z�K�A�r��?����/��o����:���!�%�2fN���E|\<&^�D��c�����3�������J��Ur��������-)������(�DVe�w8�����5� .]!�@(�t����X���2
,�9S`��X�@���X���f5|�0���>t5��z��MN`�P�v�>�����=N"��C�Tu�X��W�5��E`It�uN����B�gC��%w/���	��j�RU�9�p�Y%�d
a�2��?T�^��I�G��,A������Z�o"��zy�Cr\��	��S�"4C0�}#�wW�c"������?�5s���-�J���y[��v�)x�o�h�X���������� IDATX��]���s�����X�rd�y���X�'����\�����!����WN�e~�S`��X�@����Q`e��!��+���M����t�������R`y���(���L�e>c9�w8S`�r6[`I���2���m<T�����H��������v�.��~��/}%E�V����mp��9"�n=�[Y����\�jS
�;��l�x�N*�e�P�X�
%F�k%9�5��|T�_�_�h�~���q��
��\�M����%N�EX�v��I����/�i����_�y������<�@"��sG�T�o�k�������k=C������f"��@���h����G��R�:�a��g���rve�s�	P`��N��X�Q��!�[�t��Z��t�������OUjd���A���=t<�!�Gq:�,�����D��;���P`y��)���������;�j�(���������b4������PZM��h(��d#���U����T`��E����������E#��U���Q�5u�zH>��G5Vu���H�q�z>p����������u�6�s�F�YWdO`]<��H����9����Nb���6KK���v��h6U�,G}�������r�=��UX�����~V�lI��=���t�%�*���iu��A�'�`K
,��T�K���n�d�6p�$.������s������������g
,[�X�I���I����5�v�
���7��l������$��2[:Cd��#x�����$'�&���'�z
�����s��VR�X����m��w����r���M'9�����p2��W�����5'��J�K��K�1�)�����W~�W>��w9��\��w
,��s��(X�w;����X����V�u%}J����1YC�]-X��so?
,��9�;d�zdk������������v��.��r��h����g��J�Bu��
,[0X�������1tNG��������\�2�*)j
a2X�������[�`�����I�F�G���T�����m�ex��&*2����UCgw@����wV��X�%�#ee�[�wT��$��$���������;��Z-p��������������!<=�K"?��?T�����[krXzy&�%P`�k�4X���TL�e>c9�w8�t�����\\���'J���.�w�]��P`��=|���8a,Z�����q�kwF`����$�V�f?��l@���p}����?����K]G�����N!�}g|������,���K9�����V��S�����N��!�M�R�L{I���F�����&�$'�dI�.��d��$@o��
�W����K*�g�	�E�h����*��&mb{��%+�yYre@�5U-I���4gwa ���������p���dgS���������hg}���$@��&@�S`����M(�<QG)I`�9���C�
^�8K�����83O�A��	�������S<��/W���2�=�R{Td6o
Ddd:v���fQ`yc���z��N�T�0��\�X�|�5��Q��SF`��^J�m��2��(��g,G�����"�DZ�\W��"�&�kn�H�UR�X�wI�B�����
���Ah�:-^�u������V1�3%���;�
,�`tXI����Q��3! *15j#b�rs���S`Q`�����[���p0��ih-S`����;��()E`I[3���Vd����+9������(���]X�^��tK����*����������=|=&VA��=T���+��%@�e�X��D�e��.m�j�Ad�|���k������K���
,�P`����|�6G`�w��������DlX9�(6�;0(���9��(��C/��,��5j#W���p5Y�w��J�o����<
F���o���A�S�
��1w�]T��vGP`��PW\�P&�7����r{��TA�+Ut�o�����,��(����V����������-����">�;�L1�;���{�s��Z��� rV(�V�������4k��Sf{�1�H�Z�`��@�8�.�6O�U���N3)����_�U�N���������������V����bX�����)���X���K��ccU���GT�Q^�Wr\
,��=�#1��!�#[�&�-S��n�6�0 2�����^���51(S6^A���NoP`�C/�}�b3�"j�H�m�$��[���
����f�y���)�(��x����P`q8�F��4���)��gL����"�d�`���q�p_���R��$m�V��5m
,��=
,�Y��J?}
2g����,�_W!����^^,wz��z��+��%�������-����i�N����|n�Q�����[c���m�V`
j6�_���M����s�I�����p[G�e>
,�S`y��/�����m{u�����f��z8�����V!�\X2�0�m����u����	�����E1nc��r��
d�L����c�M!L��#������Fhz
,
,��L���:��f���3�#�><U�C����&P!�y����7�B`P oP�������Xo]v�����7��P&tx�:JW�o�����F
,����|�X�a�K"�r�+�"��=]�e
,��=�#Q`y�{R���nU���_�4��\�����*���p��}��*
,W�9�O$�D`���mX7�����C������ZS�,�S����ZmJ�^�2�|:?��

�)���=��}�b����������>\�b���3��V����"t}�JU���+�b��6��������z�C���>��2�1�w?�%	���������:��5]�e
,��=�#Q`y�{����~�T���O��KI*�������f���1��������/����F�����~�(P ��2�;���r���}�
�~V�lI�E��������������l�?�)$��h�'���o����[x��i�����Y \}���s��2|��s	��O����{x��'-=!B�T�|h��������mG�Z��%�����'N!4S`����|�r�B���L������3P����-p����~F���q��(X����{G����c&�v�n�I�D��v���AC<�?�����.�WQ�W �G)�Kr��l����������F
,��7[����O��[����h^'�+�����h6�[p�";;��u3GnT�)�����������.�������������'�����j�s�Mcn���:?���m�����y�����\���������H����DXO4.�����w�wtS%Z3
,��.���)��g,G���go
,�����n�����<�$���R`9#d��X��*���������{9�<d������/��������X�T����-���o��H���Kfe�:f��v��bQ�B.tT�g6|A�l��s7 ����{�	d���+�v�
����%�Yh�f�S����CX;V�/�UrJ���������dAgi3�sf��	-�����US��J"���WH&}�o�k���Y{�~J4���:��m8�[!$�~�����-�����*���[w!/,���-S:\���l��ZC�!88Q�l�z�yL�;S�`������8��~������D��h�U�4]��	�=4�?�x+tH����C���Z��������H��y���	��66j�j�M����e�oX�����s��{u�-O~��NG�(*�<����{�f}yn4z��S�`���^X�+%�z�k������2��z��H������_J`IdVX�PtR/W������|��Z��B�`�6�x�.�m<���`����U�LNe-�o���e3���)U����� ���DA��x60o�@��Mh�����������v�����(�	�B|��)��\�,�%@�����L5L�t�>��L����Tz
,�w�&�.=o��K��e7������-=�?������x���4{�14{��q�j4�n:�~P�[<
���Z?�����y�alZ|H-'3�$���Y�6������"pI�������c����h�>O`��#jA�]���>�2g�\U�]�m������k���Wp��%�.���j�������(!m�}#y�fUy�e�`��������r��@X�PT{�8����e6��h���6���1��Q9���8i^���[��3��W��|����&�VM��%w����P�J>���N�������B(��������vj���n�Q�yq4��8����b#�_���G5V������*�+�F��V/�Bh���B�s
�����B����B���$������9������z�F���U�U��.h�0�zg�%=
�w�;X�Z5A���6������w
,��)��{�3�-g�#�.����������w;�����Bh���Q�t��D���nR>l?YsgTA.-zUR��BB��!S��\����<�[2=/���������\�y�f��/7���'��������CD�H�_>Z�t�> ��zy	���W���Je�������V�@��@l��f}�	l��[<a'v�:���<p��
��Q1�j�N�r���(|��R��X�"�"��v�)(S=?�W��*��+>Yse@��A�x2�����[!��8��U|��7������;W��Gy(k��X2a'^���b]"�����S1tNG�)�8�u������5���gU�O��1�>kh����sQ�i1�J����5`h�9h��,w�`����!G�e>c
,�+���A�~��w��GqW`�\]�,�;"�^$b���r�-��L����9(���@��9���:W�R*���1m*v$��Cw����)�������_����X��L�e��t�5�*���|��ng8�����o)>]�U	*�|�������Y�M��>��	AiL�,9�T`I���q� A4�%:�Q�"��J�'B��X���a�������e9����%�WX�t��3�#�q�y*�w���6mvU`�k�m�.y�2%P��/?�"��3q\���V�yq��Qb[���]P���������u�%�Nli�/�X�<2E'4cb�}?`�
�{������������]����S�\�d��2�&JW��B�VN��g��^mc�
���o.W�6_�DaF�e�0��2�1����X��lT`��J{m����"�*��y����w��B);��w�]��P`y�{r2����d�?��^�g����Z�?5Q`y��3N��f-�I����eK[�<�{�(�la�.���w��
���o��ng�8XU$3��+H������(G�\q$�F�Y�"������H$S�g�XE+�F�>O��o���7���f�W"��]�uh�9��sOE=�����n���U�%���>�7�{�r�w\�w[^���O���9��ez�53�4��
�v%*�A��Q�YqK4�/m�Uy]`-����������������L�l��?�"�$�����mL���G�`�v\�py����{��*�K����z�{�Nn����2<V�@�e��(�#si
,�����������O�c\�{q��4����F�P`���m)�<�RKh}}���r&q�gG5Q`y�������b�����[m*N*�2������<�\���&
,�>7]`����S�{��_�F�2����B�E����z�R^<�����������bU_�W*[����,��X���*�X��]I��T`I�)Y|N�f����]S��<)��|�Y���X}%>�:M�,Y,���$'�7eA�����#�R�=_�C^X�l�N�e~OP`����|�r
,�pv$��o�E����U��ETe�����-q���7=PQX[����;�T�dUB�e����k*g�����������7�����!�������~(��2J:��%%!<�	��,��Jm���D����B��1�/
D���h���UY)�<7�3����3�����I�����^5�,���z�~^��
,�R�|������I�e�������8x������������x��_O!LN`
�05Z���6�����������[K'��g���B(�U�6���)m-)9�%���F��i�R��_��@��k��~Z��q[��z����X�w4���)���X�bO`�|O�U��*��eZ`j��rD���%�a!	YKU���+�b��6��Jv��H��=�NB"��"n����K~A|��,��N�ep�t$~xo>S^�����C��m�	,��J?k*".Gl����Gj(U4�"p���g��N��������x��X�5���-��r�;JV�S9b��)����{�*�f��=��s����������C��>����_9{CgwPI��	,I�.���H�?���3����W�A���y���"���	�����m���$�Zx�G��K���o'FI$%�D�%'�$z�������t*3Gn���g,S�{y��*M��i��X����j����-����U����a�����2�gZIN`I�M����M�9Gz\>�b))�$���,X�~*?6��L�e>c9#���9k�y$�Y���v�n����`�����%�����,��=�������z�	��'OZ���*U5Z�L�wV^����a�����~�r�x��M��)&�������p�:^���3�:?�(���FP9XZ���^}5b�����f��'&�={%�ac_�{�E�fq�4���C(��3���;�)�l9��B9sI:���mJ�����s��;�mV�Kn
���g�*z���*j����G%��a���h���Z��v�R���m��I���!��@�lN�������Krb=�A]�X�D���
�'.b'E[=P���g?��-�����#���s���"���/��/>ny��}�X�Bru	��7bT~.�J���r����9
�C����
,����|�r
,�9���YwwRJ��`J[=�S��Q`��?y8�_�"�H/��D��Mt��_X%���7�����W����-=��C������d
�H��k����r&��iX�i5B���uZT��y�bB�����+�8��Y/P`9#���)�<��Y-X���M`9f}.y�;�����u�k��A`�\?
,��\���Ur����2����eJ`��%��n���"������z��ix�_ j��7��P�N��=�A?�1<$�,Y��������m�/�qq	��d,.8yi�2eB���v�	N��{���
��	n�
�!��q����bZ�L��������I���Myq�a��,�������C�����$P�$B$���������	��8���sO�4A��OP�xX���x���K�T�����G����u�5�o�������cm.��rwtF��!�?��r���(��P2�M���v�\������!��0D�����X+|{kX��OC�W� }X������m<��C���p�9X/�e����]^���t}���F���N�Dx�*�u��9v�0{x"�b�U�M��� ��<
����&�+V0QQ���wQ��k����!4
�s<�<�����,�� �@A\�w�n=��Q�o%����`)WN^DB�L.��;&�<�7���^\���_xID��	���~���+���@&���a�|��Y��)�Rv��t�)���
,��(�<�9���Hn���F���Ql����Nl���Q`
�6��W�(�2����_E_���@LN`I2�%w����P�J>K���0uf��?�bgS��,������y��R�/tO�������Xt��|r�v�B�eS �.���5]��B�~��b'�Er��M!���	B6�W����~c��N!��B����>�w���N�e6a��|�X�al�j`�������WZ�v9��U=s��Y�?
��#�CV��YCK�}�y�Z"[V�.�zO`P�Z��Qq$�du�%v���Z ��6���N@��w�E IDAT��&�N�#��Z�W`i���	��9qq��Z�H���c��46</�vm%B
,�GJ`d$�-[��,J`�8X!�# �:b��w���-��(�(��g��L�#@���a
,��Z*��2���X�s�s���F�;'q��$������?
,Y��������(]5?6/9����h^'��u�f&2���l���D�S�y���r:�����*��V��H�>_4B��y,UJ����i}'�C��|q��I�{�>���S�V�/�zV��c��@��d�zV �F��������x��X�5����&q�N�P`Q`yg��(�N���{(�������2�1�{�s�+���S�O�k� &��iXXB`���X0v;�^��<�dA��5Q���DGK��nE>�r[�j��Ls,����������b�������tnE��w�����L��3�+�$&G�����n���b�DE���i	�\�|e��!�����F`�B��>X�����+����>X��O}��(���

,�S`c,S��[��?7i#�"���d���(XX�F�9[��M@H��k�&s7J9G�j��W'�����W�+�����'@���h��,���Y�F&'�$�0t�TD
�<X�u(�(��B�=���J%���A�e~�P`���K?���#�����
���*�����-)�(�v�$�i���o[v�1���Jya�m1"-O�D)��X�3����*�B|x8.��lE�g�<��*�>�O�TR�E�
(�+-+M�+HQ`������
���"��4��J���!���,(	��@��|�y�fB2s��}�����y|�������o�9�3��D$fL�����+��HX���&���`����3��`�7,�3�R�1��������[�#.�-uqUrfX��y��^�E��E��� :���7}�
�� v���H�6�b�4,�B��-l�jT:@�~��8�m��d!b����n����HX���$���`���4��`�7,�3�*[c�M�����~���J����rf1X��yF;_�V�NEH����%D+��3K������>S���gjX�����d����"�(�+85�f-P�����hX�|�)�g�oX3�\<����@�u'�ii�#�_���n1}� T�U���f8,3X�O��K�a`���������4�^������`�.�`��KG�pX����
pn�'�S�J^�N2�jZE`U��u��������0�2�
���1:3�*��.^�XJk�jT���<j��\�JZ&t_��D�^�	�nAT�0�3�����k^���l�cx�6`i������QM���� �X��v�:�wj!b�7^�7��v�R5�Zl���S�����_Y��g�h�������D����uA��8�����hX4!������eD����IX��|���
��S5,U2y������*�{���L����+�n�����������	U�Y���]�`�[�?���a+1k�p�?=ZQa����f���&�%�	xZ��|/`�%_cZ����skvn����	N+�j/�u��Y�#��a�e����*���q�v��G�1Q3��N�s`i�Sy���=�4�?���AZ�d
�rW��i�L���\��r�X9����,��o\�v|y��� H��c;�����a��_�k�/�H�!�;��C�D�������8��E�FX��k<2��
Q����tT�����W3r���m���6��~�������^Fhx0Zwk��O��*+3�����g��������*���u���K�3Q�v4z��q��bG�8s,
��/�m��_/���7�
F�U+�{`>�m�����q8��E���>O��N}�����,���'���*h��m��D�
��^���$�=����xp�������R3/ec��]8��$���Mm|�="�C������e��1�*�d��l�X�5.����6�\9(���9r���&:,Gi`Is5�3�rOw���v5r�;�z?��'�jq=!W
s
�k�n�A�U�~M�����U��+�e�N��WwLb��Q���e���y��RPJaDT(z��S��p"c�������E�zx��w���+�9|�ml(�T�
���s�&����
L��niVM��:Q��m�7�lv�Ft��D�.j�����)|������l[�
Pvd�)$>�O�����nO��/|����B�;j���m<�/���B��o-�0�&r��Q�N��L�<�{�-j�R��o����
kn>�^|S��C��<L���8g|�F�W�����_��hs����w������u�&xuh�	M�����/vFaA!�N�F��gfG����+=K{�`���K)v�,���K���By��
��Q-��f�0;E[Q�`V�!�F\��,GE`��.�
,ctw`EOL@�9�pi����!������A(�Mu�P���[-�

Azz�����%���,��LL����������qk
fd��b�w��#`9�X6�R�v���9�>��Q�p��\>w�}1���=N�,�Ab���(���������.��Z/>�9���������G�O0��nh���2������T�BX��y�k��aS��=���kP��X<�B�;�\�<�F�!Z��)k���i�o��!"r�`�[_��/��e�!��Y?�P�������w	]���[�}���i����J5�:��e��^��@�����i�9r��O��Wg6Q�gI
`�����N�K����kL+��E�*2u"����j=�����p���d���QaX�=���`�����`EO���=qi�Rc6��*S&Z0oN0^�f��Q�j�=�9�b��\4mV�i'�4��vg5�����Zno��2�r40,�BR��O��+b���R�
�f���E�5Zmz4�����	`%�9������m�rtx�1����g���Q�q4mWGDbU��x��3�5m�����g[c������L<��C�������'���i+�� EZ%�&����ny+������A����	���GxvvOF�����3����T��)�2�b6�Q���-��y]��4w�g��0���{o��|�`���V(�n����4�bG\l��q�Va��(9,�]P,�K���cF ��qdL��*}�Vp`�����q~��������C��+�W��]|��x2��&����`�=9�)���d,����,�%��You��	�L���H���&"�����^���{R��)�$���#v`{���zr�h���m�V��p�vP=����"� �E�L�����
���j�x�4�����8��g?Qi�lJ�����\+���lK�����R���}Q���bg6Qq�g��0�ri�����UN�8X�����?���D�>��0{trr��Fn��o��n�g�e���K��T3�j����:��]�E���Xm[��xj���hN!|��`�=��g�xn���-X�|9t�v���.����qSf����������{3�r�/��#��XT�������O!)����K� ��&�EE��"-6c,:��E��wq-)j������O!$Xus����5O��U�`���0c�P�-j��sF5������>�:������[���J����S�1�B�������;��M����
`����+,�~����`����|�iX�G ��"!^Z�9�����%#�f���2,#���5`i��V��N]��D�`O��EL���*�������yG}��&Y0ld>^�n�4��&�@��K�H�+����`)�Wmqx�('`9��6�E����//�/n\��>AU�^����&R�D`Q��7�X�q�D�FU������lF�[+:�T�`�y��u��[]E�����s���T�[���)������,J���	����h3*�@���m��C�1�������o����'U,��[�V#2:C������E����r��Y�,�z2��������D������nR�9,��
��(�� ���BJ"*�>Ue�z����Q��U`9j��;�K��E�}Z"K<X�f��5����:�K��<A���	A�����U{!ve|���X�J�xX���N$!��`U�����������,R��B��;�w������5G����p�&�}�6�`��D7R�[h�wt���k'����`Q*�N��(��
�?4�5���f�xOMD7.}kR�(����R_@�����T��n�����X=��5����\=�I������IG%������R�g�}p�+���n+��m�Td��Z*�:�2��8�QG�"?�.�^/t(y��G��8�����tt.
S��C?b�gA��.����a�r��S��n���b�_�I�E{=~<m��S���9���K�\DCvn���O��0Y�@
+����X�P��5��������
P^#������	`�e#��`��,,��
�
�(�����B����8�I}z�1�:����7����%V��C��ot7G�C?�������)�
[���@A�z8�C��%����V���MAd�e���F`��]�,��n>�`iQ��jR��&�����-�4���f��}&
-�(�~�����MS�����`i~rJP2�P��BQ0��+@�$�cF������>S�4�,Z�R�r���^��M����1,[�w��?P[ve�:���!��2����*�`��B$�0�b����~�,?0�Y��K�e`���V��E�*��t!Hf���l�-�%�������$���;I���3�E�<I��`�>��/]�];0����N�TV��u�h����MP4��Q����Z����S�����)gl/X���8^��
0�2�e�`_����|�����G�Z���#�U�1d6�l���Z,������$��2��ys��l���`������������?���%�O���k��}��n=
0|�{�jjt)�'zb*���V$!��`)ke&L�\k�����X�����,�+��}�x�`�wX�56����"�X"
�cp�}�MzLI4F}Wa��K_�ro���"h����k�|� ��I�x���F
,ER��E��T;�G/?VZ��|
`y��V�sX��-I�n�T,�`)i�9�{������Z�G0�b�U����n�,vi
0��&�u`T��3���/V�W0S
!A�j�nG`~�(�~����V�n���^fJ,On�3�y���"�*|���I��5�1�%�5�q��/_XJ��W�Y
��"�u�jXA�SPip������D&Z�,�#o��
0������4,��,��
�X���LIDf�I���
)�����j�m���1�h���X����a��@���u��p&{�X���4�*{�`��XD�����[�`2�1������O��E7~�[/��kX����������2��3`y��v�,���K���X��	��:K�j[�5���X��yFkXJ!�y��D}���(m�F��B�S���C/�%^��,Dn|G�a�[��A��2���~�P���������Y����#�Tf��K��pG�V��_����c�%_X�56`Qz`@A�-�*��vT�������C|�0�1�b���_d�--����/E���GF�cF��:>z,�g���	��>��O�Bz����~m�

A���X����R}��t��Z�D�Y�6���{��H+�"�k;��D�6n�`��K��p/W���[���c�%_|X�56`��L���c�������m����Z,������4�%k-_�7t�vD�~y:���1nC�"0@����n�����S���@����onw��uDg�}���~}B�V���C�x}� ����`\�zw[����?\�{o����,X����o}`����<�����,��h�����s+vDZ�9~mU��`1�2��|��=8�zc*Bv���'�������X�m�����6�m��/�Pn��4�������P�OWdL�i����UY���7���L�c���#�|&��DQ�����3Z���k
fd���dN}U��c��K�������{���cxu��}�����_��m�1xbG��(k���a�����[�U��>���<a�������Z��j�o�O#0(��Y�!A�|f��S����y��<,7��0���<��wwJ
���4\i0	�������[���X��=���e��h�j�a������fY������)��`QjR��Y_�WG����q�t<U�;-q�ia���`Q�Q��D=��[��8��5(�t��`��S���=�E!=1��v����<������]����@t�Y��|���n�.�����rK!�+�X����X�P��O�-��jm��Q�Z���3�����{������jE���1hB��9V��|Oe�/]�k����*���a\
��(k`aA���|vP�6X�J9,j�[��y9#_�_�<"3��B��"��$	����K��`����|�i=Vy+���B���	�����MIG�aqb���||4�k��*��j��m<�#�����/��������DQ4V���j5.��`��n��~���Fg�HGv��E��
�HL�j)�SWm���J�[Y5��>Y��G~=9Sg:����;�-z��BO��k����tFg��T��o�>�v���Q����V_�G����2,GU��Z��l]v�'uB��QX��>�;�.��B�J�����0��@�������7�H/_��`���{|����2�%�F����6 ��y�,Y�X��.t����.�����`�W��|�`���S�E5�,�l�UA9)���+�j
��zcQh�1�>�
,c����c��o��}����b�����m+��������+�c���N}�����E�+l�D|�A�)��&=/�+\��'E�]����d��7��C5|.�����+�Lu�>�0/M�����x7�����uK�����~e�hdL�i[��-�f��]AH��q���@�A�x�}��%�G�MW�O5�d�U��R?7�.�\�F:M}`�_��o-��������(��-�R6�-���tF�������0/.���k~�����JZ�L��5����v������bnH!$���?��s���}������V����5�^�'~�$~��p�R��
-:�CJ��y�(���3mq����14�����=���Z�+a��x�*X�y�h��o����."�b8�>�=�h��k��G����~�W�����������2���
D�:�b+;�<���������b�Ht{������:wvX/>�9Zwm�^���P���{?��i��D�z�Al�_�8�/7X���K����kL+����HD�\�����t�a�s1�rHV����C�ZQ����7m}Mo�
]���X�n�(������'��V����_���3GOk��!A�D���� L$����yO]��ww�2��^*�����5�������lz6���&x�BH�+iv�Gsl�sJ���W2��$���#y�����i��~�X��I�jN���cw��%m�.������[o������'v����>&����d��hQ�Xw�}=g������})�{������
L��W�kR��c��/�y���w/�[�J5* "*=G�)�!��[*��;��Gp���J���/�N���D��Ef��[�������M��J���-��`����<zc���W����E�����"����~��o���y}P�f���=~��L[9�����(�hb��p�w`3�;������=���`��l$t]���j�a\M���P�S�z�(EQ���|����Q�a%��������H IDAT���
p������������D�����?�<����w��,��u�~��4�Y���?��=��.,]dt:	,�3���1��.������S�S�'��,����X���Z��3w�'g<�F�o�q�,�xb%��z��<����h�7x���i1�_�-`��B�� rv".�\oK��B�E���8�#XB�X�u�����T����1����H�;���a�V#0=��H1�K�:��j��;I�u�5��9��WiE��XJ�����b[�$S&���n=��J���}z�;�e���r��\{������,*L�x��TA��t��%`���)�x���/�)�=�������<*���z,!Axrf�+*{D�B�}1�i	�,"8T`}<e3��
l��(�k|��xd\;�R��H��K�+�Z$���{DW*�DsL�r ����S
������N�z�=��l~Q���*�]��e�!9��5����f������-�@�Sm��M��x�������<�Y����*������7��+n������o�Fj�y<?���<�{N��	������|�3|.X�%g�%_cX�5��������>2LBN�^bcT�=?�.�+�fb��(�,�5�����qk��/������6��%�l��������H�9L����Fo(��?�L��Ph����2k`8��=u�^�����X����R;7y&��-����D�����z�:I����e,4��*���n%l�*�S�qK�.7���T�|��+���i���e���,�(�2�g���N�N!w�z���>rz��(
V�]������0�&�BSO7��������F\Z��s���u��-[�/HQWJ���R��,�EQE!���5�~�qsE�����Xo?�FDx��Gq)%j���c-4��-k�����2�0��O�{��TB��<���w����/��r�X?1v�i�������zQ��S�w������~�d��1�z���hi6;a#�����5���6����<}��d����
��<L
={��2vF�gJ[��=8�t����'��XX��g�%_cX�5�\�
)��>2^l���.�-5fc~�
,G��XS�~.jYR=
��o����-j4(����y�!����}�Ju��
������hpG
Q�KM�1g�����~�)���+��M_��!��>�������?��ib�(}����3}��������)J�������L��������cm�q��tQ�1�Qmjn��j���z����;�#
��qn�/N���,Z�@�l���������s�f��j�#�/|���l�����z��'��y,����ST�����S)��`��F��;k���ZY��Q��|����=�=��iX
��i+�T`Q�)��R+V���?.��'�Z��nQ��`Q���mwB"����^�=TY��7�H����!j�QJa���t����m���V���"2.f�7�J�Q�M���F��Z��4GoX���K����kL+�XT�����;5�0{f�����3�Z���=e,��g�����gS�@�<_\�W|3H�R
����6�������.���\�Pd��O�
���q[�g�&pE�/���]6���7G�e-@pH��Fu������(mi��v/����F���}e���2G�
��Q�Y���ctY��e~���ni��(�I�miT������]�{���f�o�g���]P3<
�>w	=\,���}��������W�]��~s��~E+�����Q�:%,G����/����������q�����q<Xs'~#R�8�,7����Ws
�3���#K�������?����
�������������e}w�`���m��`Q�h^�U�IR��x�K��s������`�F�H���te�'�l��(_��>A��:����/7X���K����kL+(+��yD�� 
��@��9=PG0�rS���u�p��?a	
��cZ��t�Qh;��o�>�������t4��S��5���Y��P����'�>���������S��l��v|�|CVQ��"�(��!�Cu�!�����M_�@��b&%������t��7���{�~F,Z_�jHO�E���Z#
O��v�B�>!h��+V�z<���E������/�{K\?7�,�T��%i_���Vd�����G5��h�`)7��DN�0��JC�z_�F�1�r��������E���Y�G�_8����>"��Ss�(0���S�"�_/>�)���������w����T3
�����~�qW���T��
�S	j�*F{p��z��0qI���t,���v����[���lZt��`M����-����k1��_���;��e$>�^!<S�3�Eu�v����x/x�D(�����y����m�B�k������6,��,s"X�5f�%_cZ!20���H����{�"�2E_=��Fo���:��������
��������7l��=:����(R|�'�Ej�����
�R���va�;�D*��V���]vz`��,� �c'������-�Q��
-Z�(��=Y��a��n��QX��������A~�������zmT5cK�[���+V�;�N������MZ�~��������=@���=�?0��ho�5+qe�&������� df�Nw%
Y�E�1�8��������_z:����-����������C���\	�����������\��{���Y�s���	�,B?HD��C����2�R��^�2w���_�+�F7��IS�:{rF�����������f�P%'���q5��n�s���7���Z�g���G���T�n#�����;E�6}�w�#M���a���K�� S��+�X�G.��o�����)���+[D1w�;n�Z��	Q��K�E���F�L�,t{ 3*�cX+���iA��H���\Q��R)��������������`���|�`����y�)�;���^D����E��EA��$H��QT�K�	�OIp�n�!�E����8�m,���������������AN,YV�^���A�>��W�^$��y����	��
�<�W�^xH0��\�5{��O��U~����
ys�!�PO��u���gaI|_���l�f�`	D�U�-}�^������1�!b��@��U����.��C���-���{�le	*�J�h?C���1�z!w��������:���sx��N�� w�7�}l��@,Zb���x�u�H}�Z+"�8���\&t_���; ����.���V�`���b��K_n��[��|�`��8��B�)��=�m>��<`9j+`�����R�-:�7!SQQ��Au�j�VY����u.��������3-x6���&�����Pj��)��gJ�1k�no�:s�����{A������ZY���RFc������������!��;���lI0^�f��RJ�64����p$iJ�vz>/<I!TR�(������\�������4������6.�v�w��?����4HyK!4B��sW������^�-;�������i�ET��>h�^x��pX��2G����/�P�E�RS����;��+`�R���`y�!�qr���BPv
��O�Z�Q����z�����K,}�.sX�,_�[OWM���//���������O~���s���v>W�sl��Ks<w���A���^��d=���UT�=}�Q�����`rw|i�����h_�G�mz�Bk�3O��`��	�=Wnp�f�+]��
���l��{hr5���S&Z0oN0�V����������	��A�,@�[����O�SS=�j�:�����������;��5��^J:�C)�_���~�Z�<<���k>�9�����('��K��<T��*���id{�����q��%����k��s�	T����m�3���!=��-����3��,c���������*g*$��m�$�fW���8H�*�{��+��T�u��i�m�"����	���/�
�gXJ4}(N>j|!w����� |��0w��5E����I��63�"��z��B���3��IS�:��-������{I���F%�����D��+���;�m�Gk�D,Y$�}~K��p%#=��G4�����Y�'�>���o���1���H��,*��A�-��,]o�dH���eT���KT��\������B����Hu)�I��e`yMz^��
�Z�����|�6�*xV�a%��=niV����oyX�iY�L��k�K��T�*��DK����m7F'' ?�%r��*��,m:�����r�R�U|�o���\,~}lOW��7`��y�[Y���(%��6���P�IU���=�9�1���9w�/j����N	����������:uqv�����gv�U���6z���{Y����]��T9�{:�d����t}�F����.5t���Es����^J���HF��N�EG�@��~��;���:.wfl�f�#���X�_�5�EE�tr��+[���jotv�
&"z�x��T��{d`>-D�U+���k����j��K�R���(��;U����7�������M�w������|S2���1,mW��a���A�f�J=u�p3������`9*'`�j����_�/(r	����c���j�P���F,v�H\9����Y|`�w%A)�����-K��tQ���;����vn��O��-J�S������CJ-9�Mj�f-����[�RS@@���
��%AUi�W|�ja��y
�\�/�
��;�����y���4��*v�(O����.ox/@@z�G�	H)m2s��2��{g�|#���C�f!���b�e����&Q�`����Z��<�z��q��P#�}�6�+\�K�2���1��5���� �R'd�,:Ra���[�S�7r����K�/�
�u�����zw<����?�/�Q"k����+MN��/,��$"�vl-3�[�R��'&���Y���f��.X���X
P��/2i���SM/��{��L[�}�N�S�U����V��iY{Y�$��X���W��]���g�,�[�[k 0#g�'�������8�jL(,;�0�2�����P�`=s����M��F�{oA�&��e.��[fnt�e�g�����K�&,��c�%_cX�kl��5���0��a���r��1�r�K������<L]oX������N�x(�����J9E��nE��S��i�r=��#�����=���)������>zTc�������-���XW�����T�� V�f�����*
���uk\��r�S���Rg{#��v�x�)�1�rT��lo�����
���h���j��������^����sN�Y����;S�V����	��������
�?���\A�z1xd\;������;���z�6[yXT��RC.oEPV*.�^/d��W����:�[��ydX��z0,G�d,��Pm��o������<,�GS���"����F�dZ��6�W�E�q'O��iV�d���C��+�eD����A)_�f�U�B��}�!t�6q�S�l��!~���#���[dd�&ZeHt��t�������E��	�4D�k�s�Z5��i���;�j����.^�E$2�rT��+����U�u��K��yS�J���w�/����G?�p�	T�Y����������A��ED�'/mF�;j������9��
����������b�������|�`�e]1��U�R'+o����^�������xC�bjg;'{�J��|_�`9�,`������JyX�$}��X��!��z�����47X7U	�I7TR���V�~TYk�
�h��*�QE��|�T)�pT����=�3��Peh���z,w�5z�R��>�S�=%*����������QmXzy��k
�Y�]�A\}��A��u;�*�c������W��������Z�h��#�N!��ux���a	
����@5<����h5nsz��S��`Q�7G�F�FU0xb1�BY�>/,��'�UugX���o�J
���TYbE���;��g��������QY�k��*�`���}aruy�`e��q�0!�����JJ����xuz�L2�����������[�
���*M`��	�$S�����#��]Is����c^e�Xy���<{Y�������<���`�R��5���|k����]e���d����|��f���q�v�YV���'���a��>�B�{6��Y�n���c���W+�/]����� '+�������8,���K��������GE����An�b�L7�\�&��g6�,
V�f5X�}�V`���3,c���*��+Bui���R�]O��#�����	A���X�*WO��R��l�%3�T�x&�`�B,��Qp�d�������ZP��6��|��2�L�KyT�p�e�Qik��_�������@L~h	b�E��9�0��G�N7Q��"��:�5P|<e3���S����&|���:��e������Fh��ZY�����O���
�d����HN�n����V�� �G�9(�'_����Q�RX"��a9�@���h2rM?X�D��7�%8����������f���`����o�]_0"4���t��3���`c5X��w���Z��
�w�;u�!���2
&`�)�_E/����e&LD����?����8t��p~K�m���"[��"3#I�s�],I���^��_��Ok������!�;��6s�����5��"<<�5"�B�����bg���C�O`��}l�������c�w����`�+��AT�w��!�Z�B�,*M���>�^��=I~!G^�����o���.lEP�O�������4UNl	
���y��*%s�[XH ����� X^p-�
i����#���;���,��KI�{6���&������r����W�^�"+���+#G#c�Lc6�b���0�"�^�?�b��.�^���O]���F��Td
l+_Z
!�_�$�����0��"��T�t���U����)�t+�s��������m�1m�h��!�{��M��f�D���x��.6�nA��c�����>������8�P�?r
�|�}9���c�$ �bG�T���j����
�B��p�q
��`�B���t��`��
N����4����
��0o~��(�j�:����@l�����J�r��T�&�`�L�3f��W7�j$.y�U�J���)w��}����L�l�X�4�E������/���[��H`�e�g��
�`�_���n�����yKq���o����l�[_�M��Z8};�2r1���m��:p9Zwk�n��aX��i�f�u�r�e�oP3tR��D��|wc�%_c_X�"��i��������,=Tt=,X��D~-K�mp�w�{+�#���>J�[�2���,5���1���1�������wB�WmZ����<\��R�+��W�Y1|���Gm����K��<�y0`�"?�����/��{�������`%���AQW���#r���7�[��s�>�F�K=r�?�%M�G�6�����+ �J����k}N:�Y�n����M
*1�2�`��W����#� W��FFc�����,5*y��,�������k�0lh�v/���<_����KMZ�^&�hJ_�h�,�C;���&PB�rm�<���7��B�taA�zz����D���>�:tFn|��:2�}�Ui �
��M�r�&7��T^�]����oo��������T�p�E�����Y��������jz.�������������\|{!��6�������+�ykE�w��=��BH���m�����sr�|�c�%_c_X������HLk>W�0:��KgA�����0�Bh���\E��O_I>Zv1m������#���+#����Z�l�@��%Axd`��KW�Y;IO�E��������,uu��/�x IDATx���+��)��������� /2��s�����x'�Z&�������,��Q���K��d�c�%[a��|�}`�A9)(�����X��;�i���v����E�7�5���������<�C�X�,�!�K��Iz���)��XD`�9zZ�[���"�2��s}E���
,�"g�`\z�
gPnm_��+sU���;1��u���U�����8�
0�r)����(m0��6�5�����7xX����1��|�K��bD�n3���`��d���
`�m���N��W��
z�N�`)���n=�%� �M�}�1m�����}���R�����K�smX��4K�g��`q�g�:��&cX2<���`���|t��������UZ�9��5X�W`�%Q\��`1�2���XJ�����xu��G��=0��o&3,����C���-��*V��v��K���v1����>�K�,��K�}eP�[	^U��-��Z� ��Y���qrXf�
��`�r9]��|��`���S��U�1��yU�r���2����1��/���3�����f���e��[�LK�Ej@�|e����N�$��V��������6H5��w�.k��,�;f32�����}J���`�)�y`��	�{X�mcV�E'�(,_��R,�K�/3��Qc.�n���\Ek
!E������\~�����*,�v1��2��ys��l�U�y���Q;I�
��!;�#3a�Y���>�m���GJ+�V���(��(:�v&wa�� 0-M�r<'+`z`��D��AX�mg&�E���B��o��1�,G�`�w�,����We�%��fX]����|e��@/��q��"��[r��Y�f��X5n�!����O6����C{a@I�U���j���4dL{Y��.=[����*|��
3�	Pg_�L�O���Q��3Ey�?*���j�31��o�,��Uap�u:�B�w���R��,e�e���Os���,3����K����n�.l��W��+�a�$Z����0����"�&-q�WG��J�<�WG�6]�+�E�J��G���
��qn�/�;Ci���%9;=Fw�&�n��'�g�2a�����8�P�k(�`N`��.~�+X��h�hMG�m�#0?�P���7�A�!�J�|���`1�2��3�2�
�<����
@ZZ��(�aB�,�N\�����5����<���bFwo���j�����AC��Q��>�;f$
�����GYS�"��2��
�H��?[}�]�=t�vQ|<��z"c�L�eEw������Ij�����2#�`i���O
0��'k��,����Ni�< ����W%-�X�}�V`���Os�
,c��O�n��hN0^���V���+7�E�!�h�im� ���=w�1j��e���������^2:�K�Y����U:��
F��I�S2	�E��%"����qi�R�%X��t?��'PE}��JXj=��������&:,���&�
������VP���W`�e�`1�2��`�AgXJ
�+��>J{
�'�p��g�,O��c�`��
dd���jX��#=��2�fNK]\�A3(*k�����Y��I��)�S�(�ZA�z8�C�������k��@4XZ���������&;,���Rj^e�4i���?��W`�e�`1�2��`�AgX}{�"i�w
�;[��1�.`Q�N������{=�5�^E�����qab���9��D��&Q�15�����B`F��/~�K�V���6|�B��g�_em�R�L����������`��-��������"�*�+����W%-�K�/�
�`�i����?����Dz}Pv����6ybH6�Bi�`����q����9���q~�mS���5�)l*�w�6oN0PJ{���,���1P��	V<7�12R��"����@N�^b;�B�s;�R��@��V��RA�SP�f�����K�qQ���X���`�%�(�Xt���#�W�����b�%�wK[�,�x���\�+����
{T����R?�3�2��e,�=���/^��-m�C��G5�rz�VA�J���#(5��n9������%�7�w��kX�����#�b&% �x�C����@`F�8�����T���	(��A^��R�����K�Z���`��O�4�Y`�7���n,���?�	W�,c����1��|wE�<14���-��i�����_��o�S�@���x��M����z���T�_��Q��6WF�q��F�<��U���-��Z��@�P>X��%k~��F�0�{/i�j���,W
����,��	��K��XT�*:9[o�5�����lX��,c<M��Y����q#�;)2f8?�����kg�xv|���q����
���!(
 aO��m_���),#,
��&S��"2�����QB+����:�T��8QE�,�����u��g��7f���;KY�N�"$����j���>���:�i`��
~�X�
k�R
��i�K����c�%��iX���4yK)�=o~��(0�qT��������"�nC��	�6R���`9K�S-��^T�����31�rOX��/M
P�d���f4`���Z5���=d����
���4��v���qm��p�x���C�x�z]vfX��(��;
0��[��N`�7���y��vAF�7�M�+X�}��`1����9��n
!��m���~��]Q�Eh���+D�EX�U�(N��iV��������'��2��i��a���5��k�����j'�`����S��UJM��U�V	lEON��r��t�>=&��<������`)���������K��<��`�ev���`�7�L���������\����X�}�V`���s��0�
c�5��*�,%���t.�%hp��@PD�����I�����:}\�*O��HX�])�li��X�-pz�O��G�j'���Xe������	`]Z�Tt��GOJ����<����zD_y��(Eo�.��IkXZ����,��	��K�Q�X�"Sg!����F�������V`�e��`1�"���
�?���\A�z1xd\;4i[[����b��_�}��-�c��N�Z;�6�O[S�j�>�9����0��K}<<�
�-��`)QL��z��;����fP�{g1�*��L/������
`�.�z`)��.5��>_jJ�����fXT�*b���>9�����������7���x3fO��<U�����|�r>�oX���7�����[��[+4���=��+0�2�H�`���9��
����������b������P�fU��q�O�z�A�z/*V��O�v	/-�����KM�K�,����E������L���:���z?��mP��b��v�f-B���Q�d��R��6//6#<`����=��M���6�G�2p���IfXe�U���LO���G�*����x��`�:=�z�~�	��zH/M��K���^W���M��`�%���,���8���q�]
-1b�RE�Un����#+0�2�P�`-��
y9�>)��V�67���;U9�������w��C�D���|<{��Lb4lU�7�_��w�<n���;E�����z��Q�`����h_h�4����K�;{�������gW��U�$_X�E7�����W�,G�f���3�����|�r>�oX���	����+B/o��h4W����a]��1�c��k�c+�����w`3���M���t�\��+yx��O��g�P�a%[�i��@��
q�c�q%-/>�9�?���5����k��������,�`�/��q�����C�Gs�1|d�*�������&��2��ys��l�U�M~�Ndl/�(���9e��E�e�������>������|��&�?,��Q�(�*��Z��S���X���;�
Y7
��N��}sX����\���i
O��gg�����&|��KG<"�����D��������F��c��n�*�s8�t�6��,j�5dr'��'5�h<}��f���.����,(e���Vt����zX
�b�7V��CE]��+��.��/�8���(�������������1�a���O�U��,�[����K�����s�{p$��a�j�����o��V`�e�A`1���c�Q��r�^}�3�L���'0��>.�`�Xy���SDc������:}���5}��D��V����21��_���oA�Qw����|��K�Kt��G`�8`�����>���-}&���H�*�_�y�7t�v�@�o�n�A^���_.������ez�:k��,^3��>~����t���9`���|g�����,�E�V9�z�
P�U�m���V��� ��`���`cPX�(��m������61�>U���x��..1��Ow���E��+���2`����oPs��`~��4>�m{|������$��q���:���r-�P�sgm�����nb��X5*����l�,*��(���.f�J\���w�B��!h��_o5vmCzm�
�A���xV��{��5�D�"=�
k��SQ�D�(Vn�@yT�Vy��Agf�%_��+��tD{_D[������z6��i��+�[��16e��k�����������������Vf�oI�*7E9�~J��������}��$t���?�[�W����!y�	��DJ5$�5c�`�S�y��{����!H�U��.��$�9���BJ�3�
��v�
D�����Mo��^��B��>�����z�w
!�N�����\\����U��,���ov�K�)�����+�b�J���ZW�
����M�IP'0��IH�0�b��z�^�K��&mjc��_�i���bb�D8D��b�E��9�u����g���1b�}����%!�B^�������5c�J{�^��{�����sP�e
�V�i
,Y���u"5���	-]�)���J��u�E�h���"���{���E���d=�:/,c,�'����j�`��>[���1~���OX�������<S�^���Svv5=��7M�Y2����J��E�w:�����0�b�E
|��(���O�X���4>
��q�����������d�dY����0xbG��F��������#":T��zhtk���`Qa�~}BDQ�y��\H7��n�;�>?��vB_XeD6i��+Vy?M���0�R����b��}{F0��~�t�X}{��Q_�-����\��
0��U����`�g$SA�)���0{���E�:�t�:���nP��1N���1��|3F`�k����Q�N6m���{�}`}�a0^�d�!��[>Lp�n�����[��,c�Q���K����d�<�'�Z�6����nM��d{,�
��fU��Y-��b���	\U����)�*���V�������l���T��1����1��[�������T���LSs�S[�X�EE�}�M�h��9��O����o�R\���������HyX��W������|<7!_Z])=yF��0�8�w��?��Zm�i.�����Z��y~�*�S���l�7;b������~�%�'\���6�����Ev�^�h<�a��n!��2�v�,W
��8,X�x�g���Ej������S��=>dy����K�g�X�a]�H�l_���L
��$Y�&���| O��#|��;*jS��+�=� �"�>bT>F<)���7�R��K&��T�L������ �o���N�k�c�����n�}`�����#�CX�aGS���s�P����5�����1�|�$X�Z��K�����1����`1�2������RRT���D���=���"E6��h5�<���$�R����G.�?X jM���m&lC�zf���$Tc�%�c�Pk_Pq",@Q2�=����[}gU./�t�O���@��J9���^c[���K&�<���JS��������e)�DJ*���:�K_���|GX�c+��)��Mqj!"�%�����*:9A����V����`�RH��`����Y`1�r�#F<��R>�QV�Q�E��>A�&M�i���#4�c��j`�f�a��@�U�)�Ez���%��<�O��%�`����J�|��I�	`���D��F7��_y����@�{G0�N�B4k^�����BM���^�H[���Uc��J!~�_`����5��`���P�[��-�*��D�Z$,��|�j
v�Z���N�@X��r�3,Xn;���X��F���o����C2���r7QGYt�JMw�a�W�):��_;�}��H���f��J�����xu��Se��v�r#hyX�du9��eQ��������U��0�r�2��O`����5����"XUcUQ�OE������'"��d��r�`^�N)�����;�i�K�f��`�����{����!!"�H���e�%�������j��9�y�>��TvJ,����b�y����K����B�#��h���B�f������`�kE��~��kC��B��tn3�i�kXzT}i��]O�q��,_������+('a����{p��9��cHk>W�vn�H�ZVZ����������}���d��K�����'�*#k��8�V����J�1�N��}�VC5����h�e��`Z5S��d�����|�����Z���K�>��^�3rJgT ����Z��`�e+���
`�^���#	"�*�ZO\�[*,G����+��#�z/[��fe�e��,ctf���Os���KIt������Y��Iq�=�+�Xf�&�����F,�:����[���a�TO���N��1|`-[��f�p��s�Y���u��/G��Q��(o
0�*o7���
�(�*��i�d)�[o��������jZ)�7P��b�e������,c<�8��|��O^�6��L��G����%S�!����[7M��*7��N���O�#&Z�-����Yr�l]��W�<��QP���`9��)��x��`��Mz_XRg!8�'Z�q)�s�$�\���6UOu���L�V��:�FqX����1:3�b�e���h�6qa""H�5�f8�Q{�������?V�!����
�F��7�Qj��0�' 3[}��Q�����.#e,Wm���}{SoX�����y`�e[��N����	V�5�c������g�=m+�^!�jW�4�*�A`��a�e���`�i�,J��h�O���j����K9A,J���N��g>��e#��H0FM�^���<J�p��EX�>�L���+Ph���O-�U���2����|"ySsX�����y`�e[��N��(���qY7=f���75��!�}�s��;�*j��`y�)���`1�2���X�V�t7j������U �f��?�\im$���J�����*K���e��R.r(�:@�OT���Sn�4������������f�������d�"XE�Zb��Uw����A����6�"�����������5������X�X��1:3�b�e���`
�];��V�[�q�Y� By�F��~YAT��L�E����F���h���U1�*�����wX�<�!�
0��;��2)�_E�jW�T�%~�=8B_�F������������)Xz)�|X�����1�f�E����y�ik.��)2��
�����C�l!��e4ld>^�n5�
���`�_�����V��v>�3`�HS@/�EQV�'"�z/��*X�u��`2�j
�v3O���0�2FgX���4�,%b�v2o~��(0��
���,����-B��E���7�"j-�����H.��J�-�7�� IDATt�����������X�,c<�W1���n!���>�*��cHk>W(�����X�It����UN�8X��r�7,X�������p.-G�)���WmZ���_^#VH_X�mpf.V�@�P>�/�X��k�!K��&f�e��`1�2��x�+������iXa�� ��*� ��Lqr�����?���Bv�!~������*�^X���u,XZ}FF��_�PqY���X�J~d�����W�R�<�h�i#��6Q>�d����:���d��M���1����]Xf���O�����[�����}�}���m��1Z3�2FgX���4���XS&Z0oN��{U�n�+������E�����5��~����?�E�y�<PjR%L�����<���xX���qX���$���`���4���X'!��V��]�s����)�*�R'dW�%n��ZX�5��,=Tt=,X��D~Y�����-����A�,�W����Ei�� �����tI0���`�����X�_6`I����`�i���`�ev����U��&NQh�����
,W��/���V�������3�2FzX�����1��|Y�V����X`��|3��{0KEU��"jF��[$��7mVX�6
zd`>�M4�m{
hk_��[�K��3��,0�R�U9��yV�d
0�2�A�i;��� ���=�i���n
�8���4������tQ��T��CX�tp#���	�<��M`�E��C,���H�� ����l��M0/�TRcb�s
`I~�0��,0,X����#
0��C�i�T�����G@*��B���n
�l0Y<^���:���9��D���t_�,c,���`1�2������+�	`)��1lX$�K�XJqt��������\E)6�|!���en��i,Mr���S��,�]����|��2�hM���X�QcK������#���W����H+��H���j=q)n���Z�d�|��Uz��e��<����3�2FgX���4Xf��lK�� ��%�b�2-�^���rw(�f��v��X
l��u��!��<iQV��|��=0�2FiX���4^��
0�2��$��@Ud�,����m��
;���+�V����7��C/mG�}]Q��ZClK��RY�Z�v��B�����`c^X�����1���:�`�6
����a�������Dp)�J �w
��B��U�� i�(�_^,c,���1����]Xf����#���$J��=0��LE7��@U���������jWi�
,��i��K�f��`���j��0�b���k��)��kZ��fX�_�U����X�+K�":�"`�6m��]�#���ru>�<��K0�b�e���*fW�oV��X����*T�}������6{���mv�8����tX��S���K������}i�S������I�?�����9�{;DO�!,=Tt>,��
����,c<��*������1*�]E&�Z�6����m�B��H��4,��^��,c<�W1�~	�r�����3����������&���;�/]���`)P��5%��~��lK��~Uw�}
���l�d[���?�,�7����Y������K������Va���8o+{%X�X��|�e�)-�7'f��Q��,#T`1�2��x�+��k�����������Pl�U����?����{�B/o��^R����G"(+U<v��z[�Z"l?��������5B~X=5��x��?A/�Ee��K�`���$�������<��"� ��s^~.rs��f��M�>y���������V1�v��m`M����s ����+y����>=O��0]�#����A/`����y`��Y&�������f�%[���`9����w����K������x*O�������w�UT[����W�H���Wi���>E�	�����
HQz�*�;H�Ho!@����ssoHrg�;7��g���%gN�����������i�|��e���{'Y~w+ml��bWc����� k���:v4����s�-���2�����c��`l�[�c�}Z����+~9��
S3v�����f���O�M���$dJ����]�P�������DG��)] Fl��D�z�����	���a�zd�Y��GX�v��y�Z�.�U��,m��m��#s�@���v�c�����v1��+�>������|�~�ZOk'(���H5��Bx#
Jr�=}j<��B�O�@����Z��+P�r<��Z��e>gk�^��:�� �>��*��#�J���{��p�*P�rE�mP��eD�����g�Hk����C�>�0��9������	//���������9���E�����bU	����M�b������33��O��2gK%�����G`�����*��OB��}�	H� � �!�*���g���cC�
v�u��h���Q�F%�G>0|P�����R�ew�^������ ,�9[X;���]��D;�����=���e��@�9k@��s,���:��FlD@�Z�Q_��
��-�<�2c��+�����������-k�?26���~�b~����O[��������=6����z��hE�`m7�/�n������i��\�q�Fn����n�:�����J(�B���������H�Z���g���u���D`�S;"{�����C����K+���De��-�y�|��Q���N-�����[��d���������cG}!y�+�JGa���D�X��������H�'��=P�r�Q����,��{q=)`-�|'n\��7>kl!�������f|�����+&qw=�H���+y��\�Xz(%�O!L>C=-0��-%o��%y,W|����G������(Y�*���1EGEc��=���$BD�H���6�yd���r���HH��}�b>T��]]����T�J��~7L���N2P�J<����K���,�,3,
X��4���<R����4D����+|�
��O����`�����������)`��Xz�����(`�=z��^�.Cj�D�|���4���vD���t������/G�kl=d��V]��m|0���'�5v�_F��j �q4����A�^(`����J����^��r��)`9���V(`Q��g#��w�HK��o=�>���������9����(S�,'�6,�AS�2�1,�0�^(`Q�aI��">iE�U��|�z�<���,���������P�g�=��V�����*?�G�:#S��O4�,=��_�V��k��=B��=,�p��
,
X�l���)`�����9��(�*C�4h�r<���eU���|��e>c
X�3���������[�v]��ZC�N�-@~��.�����	Ye��Gx�������b��Q�����(t-����o��F�bX7�0d���
����T�L
X�����e>g
X�3�(`9�3,
X��4���<V����=B��=��3��,{��{n!tG{�0���7
X�b�*@4 '
��9d[����0xzk{&��_J�����������^���V�@�l��
���){�h������o�yw-�4)�~/V���v�b��H���"e�YL"�����_����MB���rb��HZ���S�!<"
QQ�,����77�&�%@�e���F��5��e>c���s8S���5���y�
����){�}Dm�~�v^��i������m�	m%�X�^[�Ber�u��X7����PI�.e��c���VtQ��p��fv2+dH�{?�.�]x��~��H��a�g3�!(�O5A��L��R�#�QG��b�,�P�F��q��4g
X����e>c
X�a,�P���%[��5+��]�X`���v����Old��D���>�-��j�?����~�2�t��_���
=,�?���Y���{q�]����-����X+�Bh>c��[���[m9����9��	���EP�7�}|TD5����d��5/�����eM��||s����������p�:��e�c:-T��$1�u�~!�~���7���G�������J����	�{�fb���(T&���6��wD�U���c������;���`����e:b�9;�3{1�m������B^H�k,/\kN�H�H�\���2��Rt\%�����c�����#2fKc3v�u%��������j����3�>2eO�E_�B���2�E�2/E�F=�B��up��CL�;w/g����88   �B��p�9e  pU���V9�n_����2���(R>��MH������������0�+�E�������������V�[+m� �hY/��_?o�ysU+��H�H�H�H�I�h$@$@$@$@$@$@$@$@.M��K/�gN���iO�%��<���F����r���u��-_�x#^��O�t{b{���q��y�p(N6F.M��� (M���c1�}��j-�G0���@�9��	�
����
�/�����*�k��O��{5,�h�����8GF���W�B��G�_,�����jEr���'o"]�����4�T��{>h����o�b�OTr�\Oe�\,k����j�M������(Y-���tN�s~���vb����r�����Z�{BtT4�L��N-}�"�r�����=_U���}���k�������C$	�v+�Z/��\l���{�}���|��0�=x~z|{�.
X��$>���Kz��`��=��=�>�}���)?���s�D�bY�{���q�W���$�M�J����jus�|�dM�`��A�+�>�������[O%�]��A���>^�E}1
�a�~E��EP�Si\9s?���?�g�D�eTk�u�|0>�����Z�:{�:>��]��D�����i,�~F/����������<k�\��������6�TnT�zUP��y��rD�{�i�K�n�������C�>bl_v��������<�3���W0���x��f(^9�j������Y%���a�;����z�]��JB>��g}}�������s�6r#n]A�� m� �!������"M�@�W�G�$�u�F��s���0.���c�'N���^�>��'���n��2ay�?S17�6+�.�/'o���!3Z���9Td���{������������U��y�����@�N�S+�~:6�()���k>�7T����h��d���+ZA�D��h��������
(���2�&���>Z��&���
I��&=��f����"���3���E+�~B��~!�_^��*M�x�9&i>�&�PQ��Old�~t�*iv��e���W��=#IK��!��	�>{>��gW\��	�q��5��%�R����H�G���D���#<i4�|=���}�'9���5ZC��e�/%���31lv������nh�*	�$�5����1c�F|����D���t�MR'3V�" a��^Z���9��0`��b��zx��4|�������e��_7 ��5�3�r���=k���U������an-`�����(�������]�v!}'5V?��S�|�q��=|�����������,�~�W9N�f�l�x�aa�{���5qv�����h���-F��E��b���c|�%j]D�b�!p|���q���eS�/��\���b���`����{��lz���1xb�q}=�.kk��cX��!��,c�4��(�sJ�G�����`�=A�=�>�}�����]���	
�>s*��}�	|0��|�^a!k����K����~c�v����}�����7���uV��	�/v}�#o����Am�����( �n���z.?&��Sv�V#�et����q�%j�;�UlAPq����9R�
xB��/��D�0��6��!9Oom#`]9{G�]���8v.a���MD��V��C���k�-
����{��U]��A��|��U|�o��*(u4�TB�E ��/#�
��������(�P����b$B�=�f�3�x��e�	��C����"������	X},�8�r�L�V��<��,����=A�=�>��?[I�0e��~QU��5���%~�+��c
�F^#`�����5��5H�%5^^�W�o}���A��Hm���C�/�X�^O�QE��~�2����o[y
eV�����[���Z����H�)��_��������~�]}mn�rK8�u��fs���*H�>K��A��qd��y	����XO��������*��������)��zZ�w��c���q+��X����|��h�I��D�29��oe��U��S8���:�00��X/�$���L���Cd;�������
��W=�f�36�&��;LR�^zQB>��g��Vr��Do5�QN=Yl	$�#XX	=�4�>B��e�G�s��,�	s����Q�
��@{��Z�AEd���w? ���F�:����T��U�h��G�����J��I����J���?���g�?l��;���l	����b���-���$y0j�+�+N�mm�"�C@���6���"�ivj-`�6�j���~���R~�d;�^`��)[S��CC����-T�q�r���/wa��$��u�������D���>�������$9�$_�����Y@���l����DlE@r�{6Z�����r?�>���{3�4)�	��C���)�'�#�yv��uh�y
+F�m���V�a�G������#$�g�G�s����8��G����4u��v��\!��rZ��'���S��	8���X�5oP��E_K.��������=��6��c�+KQ�r^t\���]�r����a#��4�D��I9Z��u>�������k�Na$�����"y�������:] ��Y��-�����^���La����_�r`����:,@������rD����
a�����Q ���������RF����*q����	�{�fb���(T&�M,IT.[j���R��%��Xr�����_��	�sL!�so�=��d6=vh�<�}{>��g�u,���g�Dz����#�{vI;��({>��{�u,�O������5R[KV�g� [�_�]�^,�W��G$���X2�o�S�,]������[�B����UZ�N?���|T�p��h[D����D����R8m�*9�D�H�~��X�^�%W:��t�#�In�����!�Jh���%�!(M��:��Rt\%�����c�������K��	C� s���:�E�-���#��l�z��#������:�w4�^��&90VO?�>��#S��X��.%�Hr1��'������V[
��0f!D�����+�U�&�������:�����c���{��f�$�g�In��.��#�yvYXr���W��e�%��g{>��g���U�qa�D�>���e�G�w���`�/v��k�0�?���p�q,�j7F�o��y����>B� �#�U�|������WbK��E�a@u�M��>I�(9��+]���D�\:us�mQ"K��1y�$jH+�/��3�z%M���!'����o��������$_�$�m�A5T��V�,��������kxfF�I��.�;,m� �hY\}����g������b��������nCk!S����q�S��(�r.�S	�,P�V"n_~�n���J���:�KY���7��AKr{v��1�sz}{�.kK=���Vi��@�|��)c��G������G���|{������`ut���F���"XK�����>G� o"�U�7-,�J$@$@$@$@$@$@$@�B����$�A$@$@$@$@$@$@$@J���.,�E$@$@$@$@$@$@$@�B����$�A$@$@$@$@$@$@$@J���.,�E$@$@$@$@$@$@$@�B����$�A$@$@$@$@$@$@$@J���.,�E$_\�� IDAT@$@$@$@$@$@$@�B����$�A$@$@$@$@$@$@$@J���.,�E$@$@$@$@$@$@$@�B����$�A$@$@$@$@$@$@$@J���.,�E$@$@$@$@$@$@$@�B����$�A$@$@$@$@$@$@$@J���.,�E$@$@$@$@$@$@$@�B����$�A$@$@$@$@$@$@$@J���.,�E$@$@$@$@$@$@$@�B����$�A$@$@$@$@$@$@$@J���.,�E$@$@$@$@$@$@$@�B����$�A$@$@$@$@$@$@$@J���.,�E$@$@$@$@$@$@$@�B����$�/�3G�c��K��WMQ���Ci���X7�0n\Ft4�:] �
{�>�1s�Db|�o���/6�$  X3� �L����{! ���-�\S�Q�X��.����o>���/����Ym�){��{6�@��?*������>% W#@��V��q(O�������H�\�����������L��+�C����'�e�q����UI��p$@$�A<Q��g�����f��(_�)��!�q�V���T��z��X��.���z��	��7���
���st���8>>������w��3Fm�����5OzS������lo���'��<�	�	x:g
X�#������3��'�]��+������=���Is��x�D$@.J���.��
k�k+�&C�4.��?�������=-^�]��?c��l�
��Cf���,�a�z~:����F/�����f�����_�FPj:-�>u�**5(������5���
px�y�|�D��Y]�����,��s�z��@t��}��
u�F�7�"U�K=��~_4Q�O����n�QX$:�Wu;�2�|�����o����kj|�5��KeQ�iQK[3?����N&���K:!G��������:��g��/����@�7���R�M�s��0�fG�]��{���;j�+�]�X���s��^�voWC�N�-?�u�����3�>�mTX�\l����_x+������9GZ�x��6��hd�.���%�w�u���B��Y����(U=�
����X�����"��
C��i��Z�^��66���?�k�)5��iP�J^�}�2�Lk�w���}�����%��P�����������}�����]G��������[�iE�\/  ��V����D`���>��pf�L}�t�|M��K[����iP�Uq�~���)=�,��%�
������V�������#��C�"Y�������sq���x����Vw3���#���g�]yf�D���_�1[�vD#�U������}��G��
K��,�?����O`�������S���"�av����;�����k�`�lI�w��Q��\�[o��CX��n����.��B=>}�V�z$@�@��+���A�)y�I�H�,q0�-;��: g�������m��z�����*����0�<�B�����7`��J�,v�kYej���7���m(Q5�������R"���UW������ �����7/XVIrN�Uk�4)�C��)QMB�Eh�������H�O�����Q��<JAN������ZD,�e!��8#�~:��~�FX�~%���"��cMz�WBbxh�r��q�s�YG�Y��q/-V/)���B��Ypt�e��TB�^,�UD$��!��p�i�*��i�bs��M*�/
{^�QP�AT{	�;���al����LV���r���{[��o���J�m�{��}N9�r��1�P����L+"��x^]W����%���I^l��Xm�"��`����v�%m�w��(�q`
%��Y����!�F�b��b��X�H�# y|�gI��C���Gxh�X��wB1vig���hA�D�h��,r��D���������%����g�|x�s)�w.��������"G��x���r�g����>/��N��B>��>����
��&r���q����<����G}|�H�"���������yy����+g�b����:��_|��7���>�m��K��~T&k�-����*g����z>-���5�����Ao=���;�j��\�|��r`����#��L�#p�\a�`�P���+���+�eJ�f,��|1�h)-
��s�q�s**G��v]��u/�����t�%i�&`I�I���[H/�|'6�r�wW����4���U+�"��b�uO��k�+n��^c�)!+9ED�?�8�OVw���v]������i~��c���v|��'��7�����A���Ud�V�+�0����rZ����u����
�;��y�"��t������������8t���n�z�5S��������������h&��N���}����h�q�� C���vt����3�Onf��5��hB�"������j����!	v��:�Z�������Sy�q�'`���%M�%�P+C^�����Z"��z�����$@$`M@��E��{�V���q+��])���{�|H�g�V>��X=�F�Y"��U�O������U�{����g��2����"I�W|�u$�����,Mh���b��M��<�<R��hf�Z���6�|��X��������1k>bR�bd�z��z�Y��������	Xz}<�I��5$@)E�VJ���~���e�m
��'�f�9�����T"�����5qd��;CEf�c�9'q�L4aj�-Q�B.�x���N�%��n�s@��U������8��+�$��,d;�lu�]s��B"~����M�UG	X����F���U�K\�H�o����#�,s�8O�f{������F�A�mo�r0lv�'�&��];��c]�ED�x[��3��
J��2�"c�����bY{���E%Q-�\�����y�������vE<����n	�	XzmGsN'm�a�mV�H��[Z�;/��q�$@&qA$����[/`�;kT���������G���c�v�y����
���>�>o����!�@���[����~%`I��O����'i�k��H|#3|#�_�_K7 ���m���6�����X��El>�h~h\?(�|��<���x���W��I��I��3i{q_z�N�������������E���A"jh�����@��F�H������c�I�<z���W������:2K��������I]���f����!c�.�+l�������lDG	XW�����������6o����G�bZ;����|Q��"��P��lC���q�K~'[:�~�WESi9��y�zJ4���u�Z��u^5=�'_.�\�������h�����/["�$��l��H�K�R�HN
���'C��%��?��m)�'�DDH��$&`�����'`�KRm���	��5$Z��Z�X3_��7r����������){�����c>�yfi~���j�J�v�������������R�F�o��VZ�'%����0�G0�����m��}�:�?����P�����h����G9�K)!)���,#>}���u�: �� @+%�{a�z�N������e-6����
gZ��'E�zeL]�D��?��C~�{?�D���T�!��&[�M��-U��A6"Rb!�F�wd�y*�}|X�E)9J�J����������&�w���O��M������"���u�|�o!9�d������/c�K��"�.�����E�7�<fz�"[8�������ib��\���h�v^T/@�e����
�su��HR���n��h7nIL��k;F�S��������>	�	��X���{���b����D��H�ov�V�4���,�Z�Ym��y�G	X{�����6<��_d�l��_���<W�r0���C��nA�Z�a>��3S���Q�_I�4)���C���W�so����1��>��������2Y�H�P�r�U��1��$\]B�%�_+�v\�Wo�N��%Fi�9�e�����{w�P^r*
j������_L%rG�@hI����87z�U"���~Z�d��U�P����Q��)��e��yZaK�~J~1��i��%)�8�qs���&��O7�/��X�"��}��?����uPU�=���],9�$���
f�����6��~�gL��X�b��+��.c��^(E`�W�Z'�����JJ/_�E���-������QYW����0pj��0nIL��k;z�S�s�k��G$@z���r������mm�r
�D�h�F�Y�������;J��g�����i��
g����j��uNE=�U=� u�>��DI4�#��r�O@����i��IlLrE�Y����K���������w�z��z��e�w�>}���z$@�@��+���A��%9���]�Q�Q����`!	��K���g(��5Lxe�rZ^�U�+����71c�&���z����H�}�	��L��yHE��^��&:����c�-Vck�F��u��c�*��t���������BX�e1��KN!�mpe-�8r�"R�)MC�U��<�2��)�%"��3Z[��W�#�.�����
��C^.D��vP���B95P���)Ir
���g�Q���e5$���}�e���%_g�gN�"����Z��{"�I�[�Y�v%!�z7/�(���V-��b+y�d|m%/:�����0vI'%��K����lc��`�����/����952/�mq�$@N"�W�r�� �W���Sj�>/'��]�����r+�t)F�Y�����-`I{�?�����:�|�$y�DI����@�HA��W"���<k�O~AEt_�y���X�&BLlL>X������N?���N�pI'�\�z��w�z��z�I��;�X�2�B�':�9��?��rp�^�>��nt��H�!(`9#�G@��%���Ow������cI�*��}��q��Jh1"`���
&��B	A�V���U��r��R�u��"X��I.������"n�=��=&������S���]�c)�3Y��WE�8R���w�v
�fRb���'U��,�@/���6�S��K���H(/��������T�19aH+����buL���A�1�[1u���d��m{����w����6�L���+�W%/7"�5�R���@�g%}��&���Er`�����a���6���]8�����%�+R.'Z�VYEfI�^~��O�t�D��������w.F��uI�H 1z,G��kr����cK�#�����P�]I���d�z�Y��pGm!�6���5���������r�~u:�����m�b��O�������/A��w�G[��8rn{�4Z^S��$C�����TF�n�{YO�1%��|��.z��g�F��z��7���V	�1`e�������*Y�H�P�r�U�H��M >�4���   �'�H����H�H�	P���E��I�	P���U��H�H�H �(`%�![  W @�V�c H6
X�F�H�H�H�#	P���e��H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\tN�H�H�H�H�H�H�H���,wZ-��H�H�H�H�H�H�H���,/\t�S���U|�{9^���{�����
���v����q�n�R�N�Rh�Fe������u[����������Z�P�mIt\�a���w�^[��; �S��.&����A���?����W"�V(F�oo**���y�_�e�6�X|���������~?6/�����6��{0���E��
3�J���1m:b���������Qb)[��A,�)k���=	P�2�n��ub��x�h��*�T�@k)Wu��s����(X2{���q�~�s5[W�����6a��g�b�*Jt���A�����HW���C������yw�H�\S)`�g��9��C��Gh�J�@�->��;����L��L]�l<��>Kj(�-_���J�>k������w�����H�X�r=���P�w��5�g?z���F[���Qb)[�����@���(`XAqP��E��=qU���%W:��LU�Xz��L���]+eFh��Q�h�\��~-��
������������
_'v�������d;�K)`�A5���T�z�m��-^=w��O�Y�A�h�A��b"D�^���������S+K~o��%���{r�w����A9�>����{r���`}��l�e���e�%@��������rF*�v^��o��[_7C�j�,����
��0xzk�����_�x>���"b*�T"�H��1�(���|��X�i�].(M���K�����<qM���l�e�:a;6-8f��������U�z�����c����r���]MEmie�/G�#��}d��F��Y���E������x�����x�E1���������8��,�<B�����kY�jS���	//U"�D���x+N�������Kb���Ga�x������H�)�O�������Q9������}[���� m� T��4��U���u�K�|��4tZ����b]���_��
VwC��i�g����8�KdG����v�!��T����?���H�H��C~�\�V���N���
�x7�Sc������,oR�����yG�g*�F��E���?��Bh�f�L��U�� IDAT-���-p���6Gu��gV�)a"����8�����%wz��P
�:��iF�����^���V�����!G��z������=k�Q�{�<���{9;8���{oF-��_'l��#��>sj4�Y���42tUW^�g~�����Y���+�g�?��%v��r�5��P������G�����'o�?�E+�F���!S�����-(�
9d�����{�(Q%/z�����q�=Q��]��K�n+���/���i2Y��{�����P�YQu������,�� >�@����0�>
yFY{�����tZ��u�R��M���{m�r��}[��������YA���8���m����?�����:$�
X�C��%�I(��H0�=R�T/.���s�B"���C3��|��'�I��J`:s��z��C�����r���Q������=���v*�C��)!�C�X���
�3�>�R��e-,�|�^�e�	��1)k��J���g�����&��Y�������u�a��{��"/{g�]��q[��Gy��������dy91�t���������9�!M�@��%����w�m����/���){�sTTo�����m���w�()����#k�t�:#Eo�#��S}�~M_��4`D�[�"%�+�C��Yp��C��h��>�eHM���v�zq���q�l���/6�T����z�GT���X64�VV����M(S� ^SW����>�|;pJU��D,D�5k�ze��]P�����(O.��;�l_x�Z�-��/��s`��Y��	�,S���w(B��S�0tf�Bi��-�����*��E���Q�~"�I��Oz-SB��/2���7�����wP�)2'���O���m�	�X����r�:��^��w�(��Y����q�~�S�ZF��I����U���8�a���*_J��y-9��G��7)"|�_,=�/3�Z���U��y�J���6"����r3z�E�
�[,��0sl��R�IO�?���/������>���9���-��.s��Au����46/<��0���
����0�����.ef������j�"�y"�����ME(K�#E��]�����-y�����?�@�����uI >���8�"p�6�eE.��f��]+��C�V�{���gUT��$�z16H�y���%�,b��@���A�>UT���
l4��yi?��Y�[F}�����M"$dlz�j�E`��*�1`���*
B;���~�z|����r`��(S����"�!3q}w���K�~�_P�qa�y���h��]�hE���%w�/mm�!9�����'7���}���	
Q����Ny���U$�D�iEDM�k"�H$���������*�/�D3A/��C�Jl���z�GTig��N����������+��]�'����b��$(`�=v��T�!��f{"h�����m,mK����,��1zm���`|�e��D|�:�M�r�I$���X��W��U�r��1b�����6���A"�$�Q"���M��K4������@����#E�z���*M���I��DNXG3�Y���ob�K����&([���D^��k2�k?ow����/�+`�������y�y�
��I����Rq��������D��t�K�{��[��>|�G�h��31Q��A��}��������Wr"�sA��J$��ug�{�����q�%�u�>,=��u��"�cp���X����I���������^���,Q�n8��{�����<��*�[N���j�kC���wX�<�,+�Pw�_����F+�5L���y�#g�Lx}b#����#�V��o]d_�|�����+�R�6�c����tP[��Y%��v������ql�E|��jL��K%E�z�������e,Z^���SFFKb�l}���O�t��*[9u?V��Sv����J���/w�����@Ld\R��>ED������%��R�6'�Ep*Q5�%"���$:����J��h�����\��TT�|��H��':J��M�3�H��_m}��l���D���%RO����"v*�U����Z���h,#6+������� %YG������mJ�t�*�"�8=��,T��T�r�
m������6jV\��[�G��[EE�-�~;���&��j�mI�+o�,�������C8���%S^����7�lj��l�x��
�%��`�-��oF��+b�l��Y�O�|XWmO�����o8CK�Q�a=M�z��j�br��!�[?�s�����o��!Z+Z$eR�����?�@����>�9d/#@�����*Q<�5��H���s<���G�]��S^P"�u����8��<�b�aiE^��.�����lY�<M���:���!?Q���D@I>+���.�&`M��K	pc�.R"�uRt�r�y&u^�	Xk�-���Pe�Vr��6N��[��������D�H�b��z�Q|�yx�y�7����������YFrH��#_myYE
�hYk>��^��x�.e��k�6L��,9���E_^�$bF�c�Z�	Xq����DVU{���M����'o�Y���t6$�BDSm��9J���_�b��S��V5ZC�w�[W�d�l'N�����'K�WZ�%��5�����36g�������NT�}��U��:/�����JoX������N{�����'������b{yt���s�n@"��;i01QA���F����+����(�}K�E��dk�u4�������')`��p���}��-��"@>F�-����v����A��M�������m�n�@�P=�,K�7�4)���!�Q�j>�cG�-YGTH��������"���,�n�30����z������8�[�Z_Rr��$&`�^uJmi��%y�VM�"�iI��A��'GT�q�S,)ZT����K�(yAN�����4��R�{��>�1iC���'
��%Y���
x��5��/���:KrY'q!�����l��)��"i-��]���Dt�s�%�J�+Mt�,I�,[*��^�I�lQ�K�hBX������X���@�lI���%d�"��H's�X����$�"��ZG�j���:1U�;�4�Y�
O�O�1f��l;��%9�n>G+�np���@	�>>H�6��f�l75"`�ow��<���?H�\���������M��
�����e`��
X�n�bt�j��$6��B�~.�M�-��c������]�"'�x%"�|�}����*ls����U����_@����_���$��m5�_I�'V�����%y�7��r�X���\_�bj$�H��%�C�}\�O��J�Cf���r��e�O=��?����Z������Ud�u4[b�'�%j���% 	z_��f��l]r\�H��{�b/K���wL�+D`ID�$<���&<d���%��zmV����Z��S[*E��p�%]���(u$zH�z{6�M�D5]��"8�L�Vm��$�Zq\Ni��E���"(��%���/r��XZ���D"�I�s��o>�6,`���;�Nu�XHn�-7+�N(>^���w#��%S�(A7n�\b� �%��V�^��-����%��le��nuK=9PANDew��WO���,1[3b���������?�g��l9�?0�������?�w�a-�t���8���B��*9�v���m#���ju*�{?�T����I����b�K�dZ$���'"�DrHN&��)�|A����K������D��h.9�JN��zF�8��!����������Xr����W��p�6 �*-jJ�����$6��'����SM� 'mK4��I�"�W���gbXRO�]����:L��]��bh��-�%`�S��%/���[����.D%GxZ��������V[���kYL%��
��E��%E��K]{�#u�������"��=U*���J-�E;�����O��1���"��)y"�����'���YIR.��%QK�.[�~�s#�����go�d��L�<h���Ud+��1�TN�F���&d��#�������l[��\;"j��&_�%�������]>s9�g@�IMTD����_XE��f���E_?_��~n^���rX,��U��:w���j'E�:����+�sE%B�������s+"����[��\�������	����a�I��9��5�M��x��%����*{��^��r�e�v%�3��8fq'u"��&mtZ�
fR[���W��Q�������7*`%fkF��������g�[;����?��E���AB����'��}�r��M����O(��4!���1���[D��s���'[��EG^n%������`�;��������[�A!�Qm��6-�K���KN�k�ze�'j��WO?��r4�M;R~����y���h�]�:����'�}d�1&����eyf`T4IB�j���/v���s��Q�#��R��D����=}�qP���n��r���$I�-��Qf���)lbw"����K�$���w�����q���m�K�6$�Q"��
X-�t�%Z��#�Z�v,�N���W9��z����D=I���Z�5q�'������o^0�W���;J�=s����D�����Gy�vd;��CN�B@����j����$>��o�������6%�Br�����d����y��[���H�L9����!��ED��?)�w+b[|ENP�N��c�"��6l�R�
@���U����B������rz�0�l���}��ae�WB��"r���ouO�b�*P�
i������*��I+"n����+[K%O`�,i��O��Y<��QK($dkz��Q�Z��C�������E����g>�9��&@+�W���	�	�	�	�	�	�	�	$J�
�H�L@"�$"�^�������.�B$@$@$���x��rv$@���e>c�@$@$@$@$@$@$@$@$������	�	�	�	�	�	�	�	�O�����	�	�	�	�	�	�	�	�@2P�J<^J$@$@$@$@$@$@$@$`>��ED�O��{���cN�g1�9���i4gsY��-��_������C���t��rvg�b>��-��_���pA^+`]�����YC��)���#�1_��ZY_ G���z��lci7M��p��#3����3�DX�c��?�z G�T�����lc�|��w�������;K����yK���ip38��N�2��	P_lCB#I�D�3���DD2A0����D�l�\�,�]�,������)`9���B��5,���uO�������)`��Xz�����l9S�r����#@����cFD�����e>c
X�aL�I���g{�������)`����sK/�(`9����+�������c��e�R�2�1,�0��EK#�{�)��~?n_���3��;�Q�Z>��x�������o��u����QX$�O��}�N����]]����T�`�a�I��V�����!\I���$�3t!,
X���=�,�]���,������)`9�1,
XB�������rtR%���������}��#��N�����-����}�w�!�|���5k�\��N��@��hL�*7*�f�*P��E9��(`%���(`�#���S�rG{�P���e�F�{� @�;�9EfI�|���gL�9�)`Q�",ItT���,@D�*Q5/��������#
���6oV�������6X!�C1��9�hYgd����6��s�+Q�J6B�
P����!(`9��F(`Q��k$��(`y�2��$)`������)`9�1,
XB@��=���u*m���]�v!}'5�e��Q���x��~B�:��Y,�f/j�*�u�#:*�6,�voWC@�#�tQN~%
X�gh�
X�9�����^+�(`����;P���uN�YR�2;,�S�rc
X���DF���

L��k���|���6l��	X~=��S�*�����q��|��ZTiRD�-X���#�%}n�����
���E�T��gC��WN��i��?6~1��M c�@�����Q�����Y3y��87H�,�i(`����0,�S�rco�B#�������"�to<�pp�9h�f�I��S����#�/���K<��ac�O�Z7������S%m��i�1���������m�/^`�@P�/ED�V�b���|I�&!V����(���
3)��>��������@T0b�����B�H��7����L�|���gL�9��Y��*��j
t�F\��k���-F�fEQ�K�����v����Old���v,?��_���
=,��zS���������0��]�-�I�f�*n!4B+�u��0���\�n[wn�C�V�(U:
�69>�4O��F��.	x
X���7
X��	,�S�rco��H��;[p��]�Y�4FD�������o���=n+��W�7���i�����gyc�~!�~���7}�F����?�!m~��#r���]?�0�-=��;P�r��<,�AS�2���@�9��M�*y���L��u8$
XG���,7Y(w&,�W����)`9���X9��_��v�y��"A��(`]8q�{.E��5P�j>�\�7��9�1�:"c�46�����N8��axh$�]�������([���$I��I��D��(tY�n=��!��q�r*���:�o����)`����sK/�(`5������,��rd���H�l��P�r��r��R�2�(`����s{���v���D�K�Rd�E�Jw~2��BX����W��,�����U���W�#w���<������!&$`I����'�k����'7S���������Zi3�F��x�wE����X�~7�y���=Q�2�)`����s�����K�X���O�@�N��E��8�����F��nC��e��Q�2�1,�0�4K��')xa9��v���Az��e��/���`�	4G�|���gL�9��U��l�?&}�^�Fb�������P�l��P�r��r��R�2�(`����s�����4Wf�H���X�*��Jj��H��S�r��Y�D�9�)`������)`9���
XZ"�j�Ea�r�&r���<�cO�E��k��G�����I�|�����],�rn.� E�g���W���Pj��!\I�L+��t_HK7�dUd�d��}�;���x��*�B���8~��[�)`�6V�0�<lA]i:��_
X�3�����$`����&U���!2c9<�����(`9���(`�F������O���taJv%
X�F��W����Q� �y-Rm�J�B�r���!��FQ(`9�"�pG��q��d���_(
X�3����� `I�U���C��-)<!E��
���xl��s�S�2�3,�K�����,-�U���1m�#�5���1#�)����B�Q$������n+�F���e�bQ�2�1,�0vKK�.[���������)`9���{�������L�|����Xzqu�Z�T�x��=B��MC�t���E	P�r����aQ�2)`����s���r��Z �v��E�#* ��`(`��8�(`9�;,�9S�2�1,�0vuk�\��/��Gc����J�0,��{r-�\k=<j4��_N
X�3�����&`������
�wu��Z�g��<��D���U��������)`����s�����Uvn����#��Sl�+3�P�2�.�ve�\yu�|l��_@
X�3�����&`e:�i.�Q'J���������Y[wH�9�)`������)`9��+X����Q� ���=���*1���g{���P�r�����P�29)`����s���%QW��@�w�Rt8�*�<V=1+E�3�I�)`�����)`9��+Xo��������1�"����P�##@�����C�����e>c
X�a����U���i.����RL��K���l��'F`9�;,�9S�2�1,�0vU�^�JN� �:���w��=����'s� IDAT��=�,O]Y�,�����)`9�qJ
XY�4F���j��+�CX���t"=Q�J�e�������L�|����������!B��Y��,��fg.D��-��
���+J�|����8%���[�����[v��D_	
X��=��(`9�;,�9S�2�1,�0vU�y��'
X)I�}�$
X)I�����e�S�2�1,�0v��%��^��4������;orI��V�9�
X���	
X: %�
�d�yy�4@t4BB�s���ay\���p�A""��rn�I���u��)`9#qC��p��e���_)
X�3�������o����G��\i�`|�)`9���{�������L�|��,�pvw�j�T�t��6��T���p��cw���x��5��l�{�:*7./����~������(`����gL�9��%`�;?�/�������&���(`%�.����:����R2�P�J&@��S��	*���]�z��@�]���'G�C��G�Q�J�A�r�%�"����1�N\���dB��E��oe���*��������pt�����b�����L�o�{�)��~?n_���3��;�Q�Z>��)`��MR�2
(`����s�%`��0���n������z��� ����eX�S�J"8�Q�2+U)`%��K�]��l�?&}��E����,=���
�X"N�h35[G���p�b0~�
��E������������<�GFa�Q�|.t}?�k�`��^�.Cj�D�|���4���vD���T
X)o���_
X�3����fXY�4A��-j�*�u�����)`9���{�������L�|��,�pvwk�v?�k�j�Ea���dCcV��7%�t���kJl�?����P�h�������������|��r���~b�eL~{5>��'��0k�<
�D���,�E�*Q5/������%u'���gC��1"��o���gL�|�����+������,�-��r�p�D�,�4�,���X�V����X��J+�\�����>�V!2d����afU
X�F�������8Myg
2dM���?�C��c����|cOK���x���6����v]��ZC�N�-u~��.����6���
������Nj_�����K�|���gL�9�!`����a�nj�r���������{���@����eV2��%`e����ek�1:����s���s8���%y�7}��I/�
!�|��@���NR�E�����1����;���lV�T��2a���X=��.�����"S��8��V�}?o��\I���������1���j[����0xzk���;8����A�csh������C����<N�A�1��D1fH�`����|�����aIsXL�5�6�=�BD�q�.���Hur��3!��^D�.��d�����]�~2n4
X�Y,�����*���yk�~����O��4n��s8���5�?����i��x��A����=B���))`��<�@�
X{�����V��u�RH�-=�53*K"��gI������UP[E��l��Yi�a��=�>�6�l��c;/a��V��R9pp�9��Bes�,����'��0m���("
Q��_FM��5,�������l���������"��l�9FOh;��QQ���2�z���|�#����,9���������e����f	X������a���;��L�E{���������� `5��cG}�|�����'R�r����#�b��_�`����	
Q�J^��[����/6�n!����6����E�g���n�Q�YQ��R�r���l������F+0u���

	����������p����-��3�B�Ki�������ms�=���������B����.����������,1y=�pa��",�p7C�
��U
���y�5m�����}�Q+@�Q$o��s8����%aO�!'�$-���`����#(�
w$�"����r�~��Ms�+���[����d6F-���O�|A?��Y��	������=n+����X��i!�4)b9�P;��t���a�w.�F/�����e��R�2�1,�S�rc�E��t{+2}U
�F�]n���Y
X���{
X�p���V�liT7WO_�z�J8P�r�-S�r������s�1���;8�w>P�r����#�t��n���>i�"r[�H.������v�:H�U��k!<4?
��>������_8q�{.E��5P�j>�\�7��9�1�:"���&`Un\���)�b����H�`F�|c��e>c
X�3����F�\r�7�"����J�-QX��sz����q{������$�*k���(U76�V��
�j!��sl��s8����� (3uDvG����l�	8]�Z��>����O��\W���~� 8�����[����*M���������\�o�i,�����G�B��yP
)���{kK~8���8s����F�I�|s��e>c
X�3����F�T�W�?�<������@O�*`�^}
+�����9fD�w����F���w�����������}����`�B�(���7C�J����(]!��#{�jj+�Dcyk���������))`i���w���]� 0
X��;��z�.`�

X��,�S�2�1,�0NH���V�v���9o0.��7
Xr���������(Q5��?��������5w:]�")m9�`v��C��8aK"��M��@?
X��:�����#�i��B�8kM�%
X�!��V��� ��qz��hQ�rI��n(`�����x)`��X��gL�9���D����8|#���7j������Q�FKN&~�N'��Z%��E�>�t��~D��������v�ZuRq|X"tI�V����v�!
X��:����v���>���yv�fB��,��kb-Q�r������C���(Y*
�7�;g��g�<����>���TR����HQ,�H�,M�Z a�qw����V��kX�"����Ui�H,(	���F�$��9w�I&�����{��3s��>;���?g&�_�9W�*���]BRX!iVc��|;0���1,}4�`�s	&�R������
^���`P�=�\����x���'��0�������V)JP{��7=�e���I�4n���Y��S�p'-�
�lX���}D
!5�E-�o"d���*���"��T_�6��ID`�J�}Kr�U8,�Bq��S�V���8b�%���k�K��?�6[E���R�j8�GoZ�?N����������|S_�D6�>��I�^�����6������
S�d���?g#S��f�D�?g���Q2�����	,�DG�QX��,���1��2��
������c,(*�@E���u
����Pn�@8*�+����`���|�`����$M�������'�����J�#��:d9n����QX=�K=�73�w���#T;c]������}�~��������R`�����j�U�����T�=���nA���P>l��NLYY0��]�y��
����DZMV$[�J�L���1X��4��2[%*����m�@��v$&�'[\����<�r`���}X���K������Vi�� ��a�^:%M����AW
G�5{��s�����..�Pz_��s���T[�.������
�f����N���^��S@������m3�g?��2H����u���m��B��'���)��*�n\}������w�Eb�3^[R�AC���	����{���B���8,�f`�%_cX�4n�=��m]�*��;J�E���
���`-��T\=��]����.���Aw\�f���y0�M����V����_QS�LQ�fVi�
q�Qxx�04��!`��h	���6�o#d�%��iX��J��g,x~�M�����E�2����x�)��x6	�1��oJX�5f�����.���A0g�"�N���Jk"6�D������5R�����������w����)��Gk�X�#>Y�3�����n�1r%�����E��z�T��|������1S�E�>m��F�Q�S,���������|��oAB��#"`���z��gf��o��yJS��p2�,�K[0��G�PX��
{���{k�����>~��OX��I����|S2���1,�56���t�%�[�����&;�T2�r�:)��'��z�W�9^�5��))�VU��	`Q�����_.���RkN!��=�dF�V����7l�s������4g�����+p
��J�������D;�/e����>���P��A��K�!`���V�������Vc]���{`�w\w�l�`�m��P^a���e�9�V����<�qE����Q�����(<9KWi�}X���q2X��J����h�G�E Kmc��V1�*
0�
K�����|�`�qT�V$�K���
��L��<N��V`���hX���k-VT�V41�N]pj���b�1�#��YL��kk���h� DenAn�"���tmX���K9=�����i�ss-xxJ9z��+ip��(��n��k��Z�V=;$/_o
0��7�CaX�m�K�����"��l����}P�a�+]��Y`1�
����K}���2��!2s�X�d���K�V��=
ya��{A ���/4� c����y�#�����,z�&Z��JK@�}��^|��-�XJT�>���P��A��K�!`����:�)]����Q�a�(�N����u������:o����]k���R��f�.��H6r���v��S��!��
m�jZh��V�>,}t�`9kS��v�*A�6�S����j�N�b��
,^Z�t��,����Q�V����`�%�*��k�K��
�2�2�����4tP�����ro����<m���7���p�X�,����N�*�L�,��g�nt:�xX�I�u"X����z���g�m��x1�&�`���D���*p�}���b��Z2"
0�
C���[��|�`)�8��2$�M���]�
�+��,��"�,��V�(���@*~^<f
�����5\���X��A����'$�y�b�c��4[��fR2��GJ����:��F~^��u������j�ZFR����b{a�%����k������,��:���:�u��R+1�b���Wd�c�%S]����SP�>�s���4�����]���,�Y�Q�
R-��6�4-2�K�[���#���N�@����wY�J|��T����3��P��4���`��,��e�%_cXukh��%^���6J�z.���J�`)���`�TW;���6
����iEi��3��x�P��KKUbW.�cT�����ZN�6,i��M�K�e���@i}/d�0*U}J�>*T��Ko�y=�(��(��}0��oTX�5f�U��	&�A�|���K�ul�"�`�?Z�e������	4��f��Q�m���%%�yaE�v8��%C����S��+Y��,e��e����2��L3n��;�R���\�V����U�V����g�%�F��k�������JWavz�Rm�]53,X�9S1�
@<C�X*�su��#�rqj����?��Ci�q��#"7�������S�?�@�S>��r��)`=���S*��T�G_����&�
0�
f�|�����|��`�j��S�,H�D����+�,XJ}Ef?X2�����Ea�:k���E�W���Z6��?��&5�`����`����Q2����?,#X��P
0����dMX�
�K����(�����������3P�,/��,}���Wa���XT���/r_Z$5Ok%(��n��S����
���[]��]�V�
*�K�N��b��� �@=������rA�oX���K�������q�_B~�y(j9N\h�R�,Y��f^Xj���o � �����H�Xt���Y���jd�3�?oJE��U���"���<���,-��{X�5��,XZ���
0�
~������|��	`���t� 5*����}>�
,X�:���`�c��H���{b��7�9ARa�]o#l�0
����K��%r��>��K�C`9�wVZpY�JR�XL��R,w1`��A�tX���K������U��u(l7QI�V	��&iZ�]��`1�R�+2�1���n���,����R2�m�2�f�%S���`��s���>4���������-U,&,�Rq�S�V��H�a�%���k�+i_:b[&�Y�]��`1�R�/��2��������@wIQ\�.]�?�YM
���x����p=r3�
��s1���*��a�����
�(�g�h�ik��oK��K�T�1�`�b5�q`��,��,��{/b�-����v��1�b���_d�e�%KYmV}�"��:����(NM��:�,����m���r�1��O�`X��
�c�,�U����C%HH�+���"��S*�+�j�#1��o	X�5���
~����kQ�a��Z�G�4X�N����7����t���D`9S�l�����/����$M��+�CI�--�s1���x
�`��@$
��2��exvn7��5e����,
���J`���c������|��`E�\��]��P1mq��A}D�cX��p��0��\�:'�`Qz]��)(J����/�  �b�����sW)����DjJnM��^��{Dz��5��a�%���&e����Z�&Z��>^���S�J}�a���Y��"�l��S����"��S*�+�j�#1��o	X�56�E���O�GQ��.q�d�@I�a8�n���2jc�����K+���d�`���x�	�&�����"�Y��T���Px����,}�f����Z���������J�����=Y']���'Zq[j9^��)Z��"��S*�+�j�#1��o	X�5&��p`2b�-��<g�����>���*�`i�JM�+ ��`)�\a�P����BG��T8\K��#��[GD��N��d����nUu7�~(��M���K��< D`�"�4�1`��
,�`Q�5gTU�����
����X����U�&E�b��6?O\����#,:)Ea�]�7���u�F�W��$����\�4���@��`������YK��L��;�3�(�x�}Jg!��N+Z��"��S*�+�j�#1��o	X�56"�2�d!����>�%M�"���=OP�/���l�9�]aX�=�V�(�XU-����
D���'����A����3k6����U�/X�x8,}t�`
�����M�}�WZ����S*�D�K�Ex~�*����	�}1��oDX�56"��[}5P����t����Wa��K��)��#��p'�+9m�7�Gn�"M�_|8�+pr�����51P@�S�v��UX~K�j ,Ur��Y+�u�Hzv�F|�)�{?�=�V}[���/`���a�.,�Ff�%_��X��=���A�}�L���[�m�U]�c��K�w��U`�c��n����������p>r���*R��:��&������?g��-����m�K��~
`���l�i�(����V\��K�T��(`���`����a�,��f�%_��X��\
sq�8hN��Q�t�>���U`1�"����-�9���]"n{�.��Z�G;t������o��/p����X����b��}`��p
�`����j������Hr���k=o����P������>�3��Gg��]i�����2l�Z���%��K��<eP(�+(���d�%�4G�A IDATn��k�'��h����P�l��{��X�w���B*��.�1�b�E`i�=kq����c�����CX��k<��h4j�@��(���da��������`��������#/E��:���<�:�S�8�+�q,E*�I
�
|5�3D���G���Nm�B�r���K�`�������E���9��U`���G���������
��u��������
�9=o�?��0)�O�������xX��g�%_c�����S���Z�uf����X����~�G����Vr���v����K�jK�Yw�X:k�J�q���]k������{�������hwY�<�^~d#�?��-��='�[�M�8|��:~8��{0,E*��H�NC�d�6�I��Q2d8J�[(��Eu��z��;�������K�\~w�
`���"�^�`��J<0�pXy�����"�a4|��C����_�>�v�"�-������X��{.,�3����,�E�V�_Q�q�t�`��"E0����,}VEy%V=�g�Ez�SG�E��@��I���p4H���Mv~J��=�\������/����<Lx�qq��Vn���j����Z�����	�b�6�/,_k����0}
����h�>��]�I�Q��-N�:�����#Yh���(�~���~���/�Tb��Z2�h	�����1�2�Ax;�)���|j3vo9�����n�HlbN��_a����������6��O]��&e,�K���s2���1,��
�QfDZ��-������&;z�\��JK"N�=�Jk�8��|�����
,w{4M���\!�������~��/QJ����Fd}
������|v;��zF����U4��7-�'v����?�C����wo>����T4G�NJ����37c�����X��
�k�u
�FYPT����i�n�����mQ��!u�������z�#Ch�4G���`K��<�gO��b|��?���>��d�A��2����c������J�����1�f��W����Z�q���K���!�1,�*Q�Z��"L�L�����s;?�	�}��k��`�����|�`��X|�`��>�E���6K�V��<7��3�ZU� ,w����-v�#%�R��
�3�����|/��O�;J�7��U����'uGl|V��RDO�����G1u��{�����gP�"�,:��:W����pS 1���s6b�^[���=�a��MC���������0�����_��O�e���u��(��x�{��*���{���f�?�-����1����`)���.
b,(.�@E��O
�������G��� Xua��B���������������w���_?���w�^�����|�`���V�`��<qY�a*�Cn�En����)�������]sYkb�kx�?C���fb�}�GD��7�	k���������6��[���f��/z�7���������=yyv���xX����_��=�\���kn��P��~
P�BH�t�o-�������������"v�r�O@��y~��H�8�Pkp
�>:�C
!���k|$����7�z�S��;^�x
��G,�O�G��6b��_r�}������YX:k3��$�������|0���1,��XT���N9��tA~�g]7����[��>���o����wU� 0�>p
��2����p�'xq��:��9[E
��6->3�]t�A�X���������GOk�;��~�7x�?C���d����1�R���n�P!w�X������3T-m��CD~.*�h��	�x���K�	����o�T
�E��j#t�uK",U���CH7���I���{������;ur
RF\�:����0��,��������|�`����|�i_XQ9[�pp�(�^�t(r�������\��g���
,w�����3�}i=fJ��EO�zGM������~�<��V]*��i<}�j�����z����?���{0���Hl���#W"�i\��GJ)]�n���aoa��k��O[�(����s@�^��t���x��F���\�]'�`r��gf!~��f,BQ��r-Z��~��j�d��F-��2��_;5#�`�2<
;�����2�J�\�����������i�q�8���/���}CL_v�������S>��;��������>�u`�%�|��k�K���B]�`�-���E^5����q�`n�W��X�������V����������?S{�]����
~�,��5/-
���z������V��
9��	�9�pV_�����sy�S/.��������~[�(t�g?Nc����(X�a�S�P��G����L��-@QXg�l�t�M���u�^�������9J,�J��V`�).��iV�����&���T���`)��j
�,:�er��lDF[�k����FR�_p�
_�o��V�"Xa�%�r��k�K��5V��)�9�N�"x���]��O�CY��\�=�0��`�*�V�7��E��rW7����X���u��E)���� ��n�S������I�?{.
�����X��A������F)~I�a�����_(��i��y�����K��ud��|���{�����m�+��h�"��.����V��Z�3l�a���u�c�)P`y;_e�&	Wz�������K����kL�U�����6Bna�Ak�^T�����9=PC0��`y3����h~A���
��`�c/%���a���+�(�S4��9L��8�����S�U������e����'c���������A�w�*A�6�X;2��uD$:u��Z���>~��O7�u�X��6j��h��I��#,��3���1,y�[�����UQ�W�����]UZ]���v~33��`���z�E��QM�%KDBen�5��NR_�_�U�>�����=,}t�`��g���Qh���/v����Wqr��t���`(2Z��}W/R|��_�+�k����[��|�`i�1EZQ�ug]+�
��B�%3P��I���S��>+�~������QM�%K��������KP<f��zVT�����(<TZ�EvY����SWUk0���|����B���/�r���;�3�xN��f�����~Q�~�ID`Q$V]��6Z�,����z��%(+)�%W����_��6�x���4
��V�1,��c�%_cX�kLVI{�k� H@��O�
�ya���HX��p�Y��;��?��cd���4T��Y�����tC�kP�F���\j�3�R���}`������,���(����a���������w�Eb�3^��aTj���`���oT��>�{�ad��A�6���FHq)���*�n����,�����K�fjG0�R����@'���Jn��B�+�_
0��`���z_>W����QM�_�I���h��/-Ru�~'������ysP�:��n�M�6
�G��i(�:C��`)�*����O�`��#��-�	v�%8�I�wb��g���u�c�)���{��"|��!���'���Y�=�t����9>,��d�%_cX�4n������V�A�kU����vX�t��7,}V�UB�g�?����������M�		8��q��k0�����
��,�,y���O��u��{i���!�n'��u�[�����P�:N�t�KPGX��x�?k�J�h���X�4��@0�R�:�1��`������������w���}2�>z-.��,d��K�)`����g�	T�]���E�ujt� E\QZ`��3� �K�/�
��X�����e���j��xX�+�!ib��+��t���5��m�-�4��P���p'��T��7VO0��'�y�zW�
`�����9��?>���k���#;�]����Q�7�KkEk��K�����8y�(D�\/^���E-�&xU�N�a`������X����Gd���j���J!�(,j�T_��m������M`)Q)�>��P�����������J���]�2A��V���7���n!�������q�5�`2Gx\����i�m��:xn}���pu5X��]�l��k���q�o�QiM�U���?��>w�$����Z�������]��I��x�9�N���ta����Wo�`�P�����>����u����P2��������F#�!F�,*s*��U���K/b�����,�WT��WJpoW�$,5jq�PR�
`=t�������R��S��f|�c�r���[��������a_f������:9E���l���n�7�9^�f�q���xs6X�'�	`,��	�`Q����F�T����}q��GB3�-��6�SD`)I�.��E����Y��k�:,}�����Te�#��������z �q�/L���9�M�K�Lwb����&�`)�8H;1�
R���V�c��g�0AEy%����~+n:l��A-����6���c���������pEs����@���Nb�=kq����c�������_��wG���1��eA��2�R���=�`UO$P����5��sNr�
����q��V���`��"`�c��]��>��������=v\�9��]tK#tF}����3k7*:2,E2��V�*����L��
w
AtX�>]���]���1����������M����S��M����W��������F��t������Y��LB@�c�Vz�U��}6}�^���9 ���fX�5'�Ei�qY/�[O�;��e�o]+5�a��F-��2�b����h7��vZz����VwJ����Bi���G�2!�6�t��w���0m�R��`�ER0�R$S��`,��	`1�R�(�)��`��*a��������VpX�7g��'?�����nJ�������f�f�}O��S;�����N�������������>EIQ&<?�U���|�f�%_�pX�����[QiI��n��4Y���5-�K�/�
�`��i�Wa���<���Q���^�"[���l��*�z!,}���>:�+��^T�>!��=G`��w����`U��.����lx}f�N���+��4�,�	�^���:W�����;��������"�p������H7����g�w[6ye8�b�jh���^1?��W��[y%��u���dF���R[h����f�/�=�r�_|�����(�BE�����l���!���<�**����
R�b6I)�.���13,}�������M�NLQa����+�]�s�_������e�y��6:��%�-���s�	��)�U���/���CU��m���7�k��!>9i3��/=^���,��!�q���������_b�c��73�w���#\��NM��������6s�aNAY���0�J����b����4�PVb�H�
!�:�q��#4��i���������&X,&�+.W:����@�����6�$_B���~�X�*�l|0�B�<	�X�����	J)��X���q��a/{�o/��J�g����^�b�������h�;+-xj�
����;(,}��W1��X{�d���7U��������uZ�_#��_�r1n���K�s3�{����������I(.(���!����o�B(�9�P����BH5�bN�Ga�	B0*����(i6E��\�����yN!�G}N!t������w5Wa����u,*T^���n�����YD�2!�9�f�f}	�D�h�'�=�s^X>%��,Md�9I8�WZ��t+nK-��67�`�t��
`��.��A���;����$!���~�Om�s������l�V��"��]f���.���Aw\�X�>��S���Q���1�1 �rX::2,�b;�J�5�'�	�N��	[�1����,��L+0�b����y_%\V~^D�+���T��_����]���,C���~>�!����'u�5�e�X�����}�12����6�3��FG_�(X}hF��vt����;2��uD�8���J`�r~=,�`U�W��|��-�=��t��EF[D����|����>(-������u����F�>xO��c�������,�����F���S/�k���;�b�C1m���C���#���7,�;�J�{/b�-GQ��(�x�!����,�����������\%�}Azn���E��oK��X�_��xw���(�T`Q�^�nQ�N��E�q
f��hi����Z��1�R���}4��	���q�������q5^��
���p��y�u�B�/����J�����gk����>�b�z���������V��
9�����3%�h�z�:��'��s+~�s_r����|�d�%_�`X��������v���I��&�+�` �����.,��a�pXG�D����Z���&>�����j
����`�nQ(����1�x�%�T��`%MH�=19KW�3%���G`�����Y	�"�>�Z����]%�lL�*=�E����@�S%��V��Q�`�%���kL��U��t!��k6�4��|�4Z��FB���,}<��*��FQ��Vq��&�p��+|��2<R@��

��]0qW{6��g���%`������3<?���Q��R�U�J���
f��a����B�����g`���r����-�V�������]^�/��+0��PL/S1�b�����'�"p��"^Y`U��0��S����]��T[�����o�/S�&����Z��������m[pf�G^'9q���2+Z]�(�+&w$,��:gW�(����^[R�AC*����U�P���@����K��<�a`�eX���`��a0,�]0.�%t�!_�W`�����c��KOO�E)�=�E����]���)W�[���'Z�S�������U���(������������nB|t������0������nl��:�;2��n��^���M����ZsV_��<���V�^�>;��
�)||�E9Xr4�Y�KX�e���-,��2:������^����`�RH��`1�����%�S	nP!�^)�E&<0��wVZD���k��7����41%��e�+g�e�<*-n@�b��M�Jm ����i��a=r3����A}��|��Z�.��8��>V���p}��
,^Z����q���G�y�zU�V����3��o_#,�W�����v��U0C,X�}�V`��KO��J(,-�u�e����t��+a�d4X4���`�q�t)�c{��k*�+=>�*�,�u5*��ei|4�C�$8�mrES��^��sl������\��t��E{��)���O#q�����p$��M;`i����|,�g�5��9Q`�0�
L?�
0�
^�~���������n������yU�r���2���-�u�]an���x_f6Lf���B�NNAdtUQr�����p�P[q�k,e�(Y���{�����l��W����
xe�B�@�*���������:@R��zc��-�*O��LOlTj�XJ�����L��������P�V8�c����},J�����J�J������K;-y��R�Vp�+�v�K���
���t�`���AW��.�1�����`)��������3%��x��������we7�����s�������G��E��X��)� X����x�uD��2|Y�J��V~��/Z��KHz�T�M;G� EN�5U�B:���-�9��������c�2�"���
`9�%	W���1�
e����)���C���I���h�"��9U���`��eX��x�����M����S��M�r��c�x`^��X��>�!p�����=��7����T`=:����}*���$��-���S<
;`���G�3�b�g�CiJ���:��g
�LY�Y�,��������,�f
�Q���v���`��~<���b IDAT���������U~�y(j9N��u\��>bs
,w�9��������7��/|~����"���:�/�m/m��Y�m��X7�}��~l[}�
`��������Q������&u�	��f "?E�ck�s�iL�;T�WFO�K�x/bW.G���(�ob�J0���A<L'`�/��Z�Ru�)�R����Ue�%��x�`P�V0X)H��K������*Tj^��,��L+0�b����2���
�������1r%�����E�0������ \����)�^�`���q�U��=��r;>��II������%��nG��qiv��8�
s\)+����+�{7���*���E��	6=����?�����X�z��EDfS��7y
���**�������;}���u�c���v<��1?���[5����J;��������A���X�pT�V8Z]�33��/�Q�6�rl	]C��,��[�
�`���m���7�k��!>9i3��/=^����
���#�7F�D�#���/�����������WG�z�[����3����p��I$�k&�v:W�-}2r$;Wv�S�S����+L/co��4gg�����.����Xg7����hr���Z��KH��(*��}�����C�h���M�l �����|�������=�D�������,�Ogo�X�W����Y�`����a�,��6
����j�+:G`��eZ�,_��gK?�9^�T�BH�>|�<��-h��|M��z�Xv��-5�������D��w����2��Z����\��yV�u�(������aLy���T4����y$!UZm
!�\tS�!�<S�>TV
!�Y��R
�`�����T�VF��#G"��3.�dG��
p
�/�9�AX�`� �#,���O�Ei�	��l��C�p{u�1�����jk�5�jk�w�S-����B�y}�>�o<�	���O��V�|��"��+A�����AF�X����P�o���L��������M�u�o�"��|�����E��=>R���Kl�27e
�X�V�^��^]h���p��c�^����R�{�4`I��5q},sI�d�D����i9X�}�,�^��#������J�mxm�g�v����o=��X�����Y�Nw{����e�/�[�{;�����G�GF[@��(�zsJ��bW�����(�R�
1.` ������S�^��2/,���_��e��;E���`��Z�,����-<R3rt_��i;,m��4[���f�:"={W���������*T���*[b�%�����O�C����5��3�?�,���8�����U����+�[Oo���Y"�����1��^0�(h�	`Q���y�uN>���h{Y�Z�:?>����Wpz��O#m��I����Z�y-L�(���)}�Mz��+��:$����}pf����s0��k��o�SfX�t
�W]��R��	�����;]�+P���A���5��7�K���`��b�5������X�}�V`��KO��
��V3��
�=8��h�5#zZn�����K0�W�=��d�Y���LL��C�k�h���D���"���U.R���,}<�.����h��;kJ�d����TkS�H'��
������:���|��XT�=���4&�`[��>a��KOc�����a}�r�n1������P0yZ��oZ��R�������[��u��&�����tg�UD�����P�N+3
���G�F
U;�Xt����m������/�����Hl�`����X�pT�V8Z]�33��/�^��U���
��t{;� ,��L+0�b����1��[gg
���9R
a���Q��+*����%�WT;�Z8��@i�������[k�[8�:���`9}�le�S�������fQs��3�|tS(��Ji���e�eD���+�K��a�,���`%������M����c�%��`���k`��w5W��B����J�����R��q�M�M�"��/���e�*�xYYH�Q:aM(�"/ ��g�}i����nF��7�R��5oL���|��:��k,�����kK�B����q�eS!�����X�pS�V�Y\��2��/�^�"�>��K�
��W���n]+p��*����X�r�+%����X�H�P�X�S�(��q�Kp�2
2++��w�w�3�WEj�U�e��=��%����wap��/�r�'��ds�&�vF;�d�v�du�E�'�;�_8Tr�kO�@v=�E����:�������p����e�%_l����Jk���|����@�`��i�W�`9�E<�[��9}1�-�3g�f������0}2L
���gP<DN]��z�*�rzr�������En��K�Oo'��^N�;S�h.*�O�X���,gm���+�xiY(O�|v�j�X������P�����K�1d��Cs��RTZq���a�`��eZ�,}<M��ex�������-"]�����������[��y��?���/�E`����M[���D�[*%��(i���y}i�E^U��I�0��!g�*�����xK�}�,z��.JDR-������3�g���,�3�WJ%/	��@u���4{j�
����~�D��-�H���d��,��(hw�K��XQg�"2g+�����y�T5��k����yU�r���2��s
�>~Ws"�h�&�@�����2�r�LX��6#��e8�S��n�����u���R5)�������������������z,�	JF��E��[S�(��j\}o�6��ui^�3I(��������$$k�)�����O(*�+�j�31��o�����{�*j5���}9��Q�Uir�8��2}U��o�G_	=������[^a��=�}��r�����X�_�Ec�>�]�"��~���u�]uxuwz9f�	��+��d�����uq�/����,G����oj�y��X�b���T�l$��w�^�	h_m���"����
gJU��O
�r��O���W�5��$��.�:���;�n��l�T(�s[�V`����U�V����;g�%�D�A)[��.���k�O����E-���
�2`*�BY���%tu�-�;�`�c/X���4����%BDbl�/�tCV]�����	�b��N��������E���=�d�BH6�b�J�Q���b����"H��C3^Y`��#U��)um�y��d���G)�"��qe�����7�\�B�	�q�B��|�
0�R��W�,�R��Q��R/�s��<T��ZA�i(�0��<E_������pW�����@X����������\%P�E������oK�*�z��Z;F��f
��gf!~��g���~<�~Wur?~�wW:�^���	����$R�(����[�(
��3�RMK�35�~����R������:h4}��,w%`i�Y<O�)�+�,D�e�%�XQ9[������F����VS�bQ�pp��]U�:
��&��D��Kc3�b����y_E���Xw�E�wJ��"�F���J4L���3P�RD�dF`��W(��h�@P��5]Z��rjK��
f����o��Zh;*s+������?g^%MLi�9K�FEG��6���O)�(;u��Z�/X��:
0�
[�$��1�������R�'�!y�h������y�xL��*���j������>�g���3G`��w5W�
`�������4�v�K[[Q�[���p�/�\���	������5��St���3k7�n�L7
��{Q�:��(��^��X��A�R-�W8@�����k�`���{�_X�k6+2�RojP��,��G�"�}5P<��N���U�g��"�+��T���M���i[}fX���4��0���
��p���H��n�s�������EgIN�����G&��	�R��G�?�Y��;��+-7�]nE5��~���~�R���,XZ���
0�
N���`)7A��oG�Z�1�p����&�=P��WZ/i:�mR��*�	��KX��,X�x,Y:S$
E�T�i����j�<X}]X��P5�Q�E�u���!��i(��n2�6h�V�WJ��@��a=
�'�N�
��H���T���v�@Q�-�R��J2�b������CTX!jX#�V�V��m9"�n�U�AU�O��T����}p��FE&d��H��;1�
XBE0�b���Q$w�,���Eq/��3k?�5���=�$�c����]D�(�,g�AN��;��A��t����nQ@�����Y����p�h�8���H{��1�V��S����L��[%w�*���BX�x���R�V�hGa�QE5��Z�s��j��R�����(%��.H}������R���+0���f��K�����K��M�)��K��JzS*^���������!�Bu�j��H�W���B�����^x�&"��&L{�����/��9%��'�Vu
����L��"��h��X���z
0�
=��D��}9P�+jg����d�
LtS 5JT�j��>��K�`1�������K�(��j^����*�t4,�J)�G��)=����6?#,��"�I7
Rs�����GYw�����Mb�=�����61��+J�\z�2�R*��w�6�g�Jiu�n�%-ZU���\�yJ�J���N��-�����,��b`)��;�U \V��e�9�Qg� ��"�t�b�p`2bN�)������Z��g������b�����`��i������u����8XZX�}�;	�&���4y�`���I���:��q	����3<?���;��UZZ$L���1���ZS���}k,p������l��W84�����V�G}h�
O-���isO������E��41�J���pp->#+PKX��5�E7Z� 2g+*b��@U���h�����4t�!M��3��GjX�����>��K�E=��`��U���m��*��},����.�)?������U>���uBJa;�QQ������E��U`�:"J��
\��K��.G��(���gQ�g]M�5zL�)<4��aM�O�poz
o�\X�k�3xP ����\TD�'�����S����C��m�xL7Z����a_W�+����>J3��GgX���4X��L`�
oS��X����*��},�{�BG����&����I�E���~E*�^q�����<1�s���I�c-�@>_��r���B~�������:�;XSO��.
�W���Mi�e�}P��OJJ�Z�0�R���`����Q�`�����gU)}%~�l��|�_�4�gf�%�{!�M�lX[�������8+N���Y���T+��YQK�Fi�e)}��@��X��X���@��^[R6���h�f,,w�`���J
0�
%k�,FXa}r="�n=����P�"��m�(WX�Wl��>Va�����`��i�Wa�U�>MC5���,y%C�d.X��q��FN���(\��n���Q
.jT��Y�]�)��U��>g���+�r�^=��T����1s�M����Z���������5�S������u(���B�FXAE�����?�<4�������������V�����B���K}����/��uY�R�"37��}���}��9��hUo�V��q&U�m��{~�
`%������
iz6J���������u�^��"?����3+O�1�u;>�T����z��Z��D�+/����E���V�z:����|)������V�O[�T�'�r��W]+J	��m������;�x��Kk1��GgX�H�/6��u�A��B4k������z�V���J;���%�����l�py3���MZ'����9k|���s�������z�b5A�rF��*����]��H)=�n���1��B��� �Tvm_�M�_��/���[\�x�oj��h�N�>3E<Q����<�g��^�Q�Y��n����H�i{xwMz�����z���N�,�tQ}��?�|o1���y=�(��(��}���B�Q'�#�������}9��,�Xp��
v�`�cAX�������Nb�=kq����c�����CX��k<��h4j�@�#~�d7���^�=�z4l'��)O����������������g����m�5;`����`���� ���`��~G�{���������g'��Y��N]��4b�%�����S�^�����.���W������yV1�g�d��
Z�����T���i�|�	��r��j�T7�E���'$�	�`�p�R
0�
)s�02��E��*
��������]�D]+j�]���8c���n`i,���`��3,XKgmAYI��O�F@�c�Vz�U�q���t��v���iq9��M<�1_��>?�7���7���o��L�5���,���8}
N�Y��k:��n�{�U�D��%t"�F{�V�����~�<������RK�U���&�z�T���}�;Q�,:6Eb����G"�
T��jQ%MJGE�P0y�4�)�0�0`�*GB�]�:�>q�,�A��2�
�wD���V��^��e����"��rq����P�a�xL��"�sQ��������������>:3�b�5k�{�=�\���%��/����<�|���2<��
<��V��8��}�������q��.(�-�c7��Q�B�A����1��n�=���V���h�h�?�Sg���=5q��3���+���^'0��2D}@��#������~(<LsxE�0�Rb���M���vXf���B�q3���=E��?
R=4Jg����R���g����E1d����wW��Ec�!�<E�L�|�?�3�����{�+�z����{Aq���r??�E�5v�2�%9KWyU��N�CBBX!aFcB�EVq����M�"���j��c�st)���������_���`i���9`��H���Ul�
��M.�������v`�����CAi��7���G�����|P�3����k~�����������s�~�Q,������F�Zi3���jk`�U(a�#(�:Cqd
g�k�����s�$Re�g5�v)�G����*���P��H�w��f�:�����3~��7O�/R��`h;2��3������tV��i����H��g�jG�IDsUo�n�U=���FQ>e���^p�_����D����j�������L��:!������������Jj�1��R}�+�`�L�
�����%Y�v@gJ`��uH�5Z���W���1�T��]Xr�u��K�`���k����yRw��Ga��/1��~�����;�b��>�:���� v}����z���qQ�f9�Qk���E��+��������W�����
�v�"����%o<�����������O>���O9������|Q���a�=�����a�zQ�������*�R��~v$���m��z��E\x������W��y�o�	�=�^����<������m����m��;���;������ph��9��l���_\w�x� )�����BO_��������������x��������.�p�w>����������w��\$�F�V��R�������^�����7����o#G����H�?�T,�]Y��P�Vp�)(w�`Q�U��tQ��"�N�=�:3f�[e��l��3��GgX�:�#��T��C.�
�wq�A��rO��_���K����~�c��[���F��O�~GDY�0����~��wL~u���/>�	����~�&"�N���\�:46����H����,��R�b_~	%��wEHP�5g���
V�Di`
�����������_m��
cp�l������1��SEpZo�gL1^�b��B�n]}N����T�`���[���DYJ_�����pn��)����)��U�"C���g�� IDAT:�P\���R�Y[����Q�K�����z��zN�z���R��3�RAOo���|������>�#�=r���7�#%������H	�F}��	j�m/��y�#n�|1���&H�����5���jOi��X�pT�V8Z]�3{X���'�"��"�n��\<.K������E
�@M�+P��g��L�@{1�rW0��9[Q�_���ot�13�]Q��
�WoIe2���U�������U�n�L<_p��,���#qQ��X��k���[J"�����8�)�5!���W9o�=�m|�+;�/k�)}����gj!�������PZ���������k`���������]��/-r�*�oOLD��i>}K����@�	��Fi�T�����#�e�61Q�[��U��57����.]�����f�r���6}N8��])l��(�2�k�>y�g�5��Kg�5�5�(e��3�pv�;~��@�.�y����������U�����B��<�'�E��T�/v|��NW� E_9S
xCn��>fa������uG��}�4��c5�LM�e=Zc�����=���h$6��< ���UR�8<�h��p����
��{����&qx��;�w����GP����{��������Et�����7i�u�����7?Z|��O|[%���C�^��(�M������Z������qFX2Tu��.���6
�����[o�B��=�@������H �
� �6��'�"��
QD�0�a��o��'$I������G��q.[������@��X5� �hr]O&�E�i�������� ,-��s����ZA�����Q��yD�X'"�J����
���l�6��f�P�.�Nf��2������������H��?9��������!�LIA�+���'�Eu��.�
[�{%E6\zM+���G�.g��X��-Nd�!6!J��9�;�b,V�n������(
�k�eF����PQ
�3�PD�LJG���;���&�z���_��g?[/{�uX�
����ME��{�{�_]���9����)JM3�o~ru38AE�����:-P�E�����Q���V�hO���s�>ch]gdAOJ��'
orTb�eTL�Za���=������k*b�A%�R��t&m	���q\R��1�R��
%`��5��,tC A*��*n=E-y���>
����Lm'�n��m�����1+,}tf���s�,}���*�u:���w��`}���/��vKi_
9��T����	���K+%=���OX��~K�X��V���
�n�y���@A�u�����^��D�vG
���|�s�Y)
��*����Mp�
z:����A��I����u���]j�@"�`�>�V`��t�7�H�!{lb�.��`7���������<��A)h?��|���Qz�k7����a�a�,}��K�`���K���J���&�D��:����r�����Q��Z��4�U������'X���<)��e#����
���^�@E���(���Q �vB����#���Tx[����p�+��>��o!����z^
����#	xH
v}��4��d�#Y��5W����Y�L��DXF{��~�R��^Jt�������5@�?��/���t��)XtS ���C���q�����KQ��O^w��Rs�A�1��`�c"X�����>��}���JX�fQ$�p������z���|�=q��rh�@����|�?R��v����P0e�*�S_JWO��u��S�n2�=����Y�K�VE=��3��d5����)E;[�GMD�m4b�H��4r3^	�|�������xJ�N��E�\/@�����v����������]���tw��B)����JK�Z��R�hg�uU�,_
�:��5T2,%*�������O�3�����a#!�9��0��oX�k\=����)��SS
�������?S�R�R����9�����s��F���9�f�����A_:`9�H���=�]������^n8�O�������x�5b���c��PU d�d����p���h�07���i���x�Lq���U����C�..��Rt���*��#��&��u��v�V�0��JI��0���1��K�`1������R�-�F�W����|�2�
Lc�.Tg�,����z]3zX���D��8��I!��I��H7�%FF�'��c��V��8�SJ��B��V��7`xE�3����x�`T $Vi�
�G��5;��������xu�g?�/��^�)���UZ�R�(
*��Q����jFN����S�;	l��41�`K�%M������d)[5/,�3��GcZ�,����J���,�:3��F���@L&L����.���Y0v�2Uif����f!����F[�u#,Oj��a}�����s^�~I������~��������p�v������xh��zX��GP�Y+J���m9���E
�����	T5����������c����1���7T�5SA�������`�W��|�i���GgX���4��0���
����K[����iV49K�)cu��7�U�!T���lFXNP��R�h��I� �)�`����i�I����8s�yv���{�f����_���`����O�s.���/��������:x�X��_�����5���?j�H+zLi������/�g�%_y'�z��^#����������/������l;�	e������U����2��������W�[2=�D��k���u'�z��'��98��8������������U�	�H'�g��|��[����)"�Fn�>�`������������������M����h����gO}d��5�|������ZkRX�uf����Q�[�4�^P��3k�c	`E��E����"�(�.n�K��YP{u��ht�U��T'+ib:*D�+���`��7���
�$�Z����F�1�����M���w������w����O��wY���~����]�z���]��WG��,����Mw=?��L����DT&^��>�s�y���q�-��U�T��|���OO���/""�G{�����F[p����=5��I�W�����'W��S�P���R\����C
�xH8���#P�[-&�M��m��d��K�M��H3�+�����ue������S,��JX����3,��S<��b�Tw��V���
�������������
���`XN�I����WdnXa��|�:M�����F�1�����	��-���E
�l�:�g�=0[L�[U_
"~���~q5�n�F^��G��7�V5O��Uc�l�x�])���^��!O���b����>g}(��L&|:�S��F���%7"��(s���hK��1=�'�=��\On�9���c�?���T��Ad�kW�=	���&�h�y�fo��O�5����g)���,}4g�%_gX�5&��������Ei�>����o0�${�,I2��e�%[a���
�$�z��8u4}n�K�o?�K��/n�C<����/u�����w�-K<6��Q�_�i�9�U�Vuu&p�h�>��vd��>������������O~�vo�M��|
��X���0U@�c;#�J�*�Y0LWqF`��W�������qX���K����kL+$�w����[n�g�0]����`������X_m<�X�|8T$��y�8����e��[��O��|�qw��
\�]������\K���
,}tg�%_gX�5��*������
,X���|ZO
�$�*+)���+�����q]�}�4?��{��rm[X:�`���|�`��1����~��y%X�X��|�`����>�*�`��m���I�E��)��l�*�Q,��
}o���G`�wKX�5f�%_cX�h��������U_��>�3���3,�3��GcX�u�B�|�W2�!�|����B���+p
}����B���)����k��rW��/���:,9�����|�`����>3�b�����JFW���-��c�%�x��kL+0��GgX���4��0���
����K������,�<�W2���n� �,��c�%_cX�hL�0�b����y^��>V`�%_gX�5f�����`��i���`�et��`�7��o�,��:�0~���Kq�A����B�mq)P���(��b���\�[)P��������M�6oC��&Hw�9��m�d�7������N�3���aS�z�3C?��3�����N+�9S��x��>c
X�>�H��";��"{��~$@$@$@$@$@$@$@$@�(`q$�	�	�	�	�	�	�	�	Dj�"u��r$@$@$@$@$@$@$@$@�8H�H�H�H�H�H�H�H�"5
X��{��r�����9�e������H���U�J�����r�HR#������d@������� Il�k`$i��H��	|��o��n��o��6�}m���{��o���a8�-$Y������s�?z�����D�U
�� M�).1bF�,��������|P��?'�������H�.E%c�d��_9sOq�z���MK�{��J-�Y~����n^��AY7��Y�HR�Oh�}����r��I�.�4�VLrMc�=�S��_<%����C������N'��-i���y++&�������/%s����_)I�&�����m�o��l�yTv.?-��K����b��R�n����f��9����5������`k���e�8	�F��v�
�ls�e#��3h#�f���e��qI���O�y�����S���6>^A.I������W��W��#k��mj��+��U��}k�������I�������2juS�c��R��^ ��3K�&���?�����_J
U
����k\u��C���*y|����u��;�}�U��O	�Q$��|^V�zH�,m,)���8��y���r��C%d�y�Vf�*��2K��?U7o�}\��?��{�dq�k�����
$J�(�l#�=+�����K���%U�D����2��z�4��d�L��`kn���������q���l�:k,����`k��������`k���e�����������
'���,8)�f��k�I�x1�]a!� �#�2�������<���$K�=q��
�!��������:?,
�b��@J)R-��;']���>��H����g��Id��f%J�`��}��t���������\��#wI���%e� ����������R�\��f��B?`g��Q h�(�Zj�/�~d�p��/V�'��0,�_`1'�X�%	��	q����P���/%�dW�������uR5�R �;��+eto%������c���h�^�%���J���4^"�ke�
������9#L�y�t���s�Km�:kWpk��=r��m��[-q�E�y��
�F��v�F��'j�F��3�X���>��R)^;�����~	��fK�������
�c�W���p����2k�6�q[kK�[�s���I��:��E�����`�(y�������]Wdz����z��c���w��?T��S:�JN����u�����j17X��-��jfS^nFY:�Wn_y(�UV?2,x�M��#��_H�qU$j��E�!���zQ��T���9'!�*f�]�*A�g,h i�$��dD��R�j%���S7��2��
�/�X	��]����N�J�lr��-���F�3���u�f�MM@gFt����m���,`m_rJ6�~\m�1���	�F�Y�h#��k�e#���ls�&�����c*J�D1�����gd��F�-*�+l#�$�r\F�B���Ge�w��<.zN�)�M�?V���r� �
V^=�WI���jPi�������������,��i�-���S���1���2��
�No�N�
C���3��;���XX�m sx�!49z��c%`���''w_��u�q7u�s�h��G1�w��L��Q�E��{���+��k�B1��z���q���5�q
Ww�I�$����|JY?��Q�E��A�C���9g�q��m�t����x�"����v������RfLD�&��t�.��E!��e�F��3h#���E����7�{����{�R^���]a�� W$�2>�6�:����6H����E���U�����������_����n����*���3lS�+u�����J��9%U�D*|m�o;����X;���MS��eR5;����/�~��m���S�;���w�yR�Sa��]�'��J��=W���k�{Fm���>W29����Y�����-�I���oom���R'd�\��J�����`7�X��\#�$�:<-V�2�����4B
a�	H��Lxe�����k�|1��
y���9g�1�yi����0=�Eo
�F�Y� Z��xoUn�O��,��g#����.C������e#����E!t�H�q����6�7���^�Hyd����	�@p.#`��yYy��c�(F�����%MV�M��+q
�?m�������}��!�F9�sQf�aa��	y0J7�){W�Uam��e	$�}���*���1N����V�"���@Y��yp��%|!�1b����=���T��Y	�d��|e�O+��N��Y&��\�?})]J�������7� rb!_�a��)���8���W�Dl"��l�
��Z_���A��+i?������38�"���8��:8���g#��]������a�q0pa���-Ag���h#��/����3g�Fx?�W/^K�3�!/��.���8��	��p���� �p�y���(�F�pF��l���R�m,�	<} c�zKv������%Q�q�����b��+C,�N!N�1<���l6�=���-j�NaA.+��0<y��� ����z��H��9T�{����,���������xZ�h����-�Z�#�	\��������%�'	�O11>!���H	U0�P�=�o*��^3�H�<��r`!Q9Bj{L��~�HN{U!��l& �!���9gp4E4�q�up����t�.s,x�c
��7K ������Fx���e#���X�������Tb�
�Y4���WoW@J��!����G$���Xh��=7)o�f����g/Un�O�f��]�pdh������Q���cE��9/�s��=�N���[UrFx���?F�����)�Z���Y���-��j��Jh�U�I�=���:���x�..9���}k����N��e�-;��S� sr���wv]I�9(!�S��Q|����XF��/S�l��-�Y<��c��c�~dyI�4�,���$ ��~�Bo9�B
J��5Mu���N����2R�BFu����s��������q�����l���,`a���+p|����l�F��v�,���Tm���.[6��9�6����I]7�s���nD����e���2xqC�H����
p9.%`ag��'v]VbK��Y�Q�b*L��6$ZD���J�>%,^*����y#w*�%�G`'x
��1��!�
M���'��X)�W�|^�p���z�*�<]�b���y�v��������q�/$�
.�'����]��'5b��/e�������a��%�!(��S�&�T�L��+��E��D�=�������Jqzf���,xl���38�>[��C����]���e��Z���JC����i���EH�C�l�]�m��a�F�5g�F�����{�H��W*o.k�0
�+ls�$�J\J�r��e[I�H�H�H�H�H�H�H�YP�r��d;H�H�H�H�H�H�H�H�I	P�r��e�H�H�H�H�H�H�H�H�YP�r��d;H�H�H�H�H�H�H�H�I	P�r��e�H�H�H�H�H�H�H�H�YP�r��d;H�H�H�H�H�H�H�H�I	P�r��e�H�H�H�H�H�H�H�H�YP�r��d;kD��JIDATH�H�H�H�H�H�H�H�I	P�r��e�H�H�H�H�H�H�H�H�YP�r��d;H�H�H�H�H�H�H�H�I	P�r��e�H�H�H�H�H�H�H�H�YP�r��d;H�H�H�H�H�H�H�H�I	P�r��e�H�H�H�H�H�H�H�H�YP�r��d;H�H�H�H�H�H�H�H�I	P�r��e�	\8yG������J���:
�������'�������H��1�y�R�i��N�F6$�������wd���DB$@$�@f����=���{4>��=�����t���rA���h��J�x��wN=I�4����!:������!��CI�H ����z��q(g�n^��!��H��)�\�<J�z����H�P���P~|��'�s�i���c������k@$@ND�,��F��u�K�2�%�[4y���d)�Rb���D����������C��	��+���
���m�����o%J�(Q�D(�}k��Y����U^��*^�����?T�m���w��8��A$@�N�C
X�_�����*;!"����n��5M#�5Z�v�u�����y��H�")
X��c��Z��\#���K���e�o������0i��������\�K={�B���c�Y��K�\j���RD*��'w�<��I��e�O��=Vt�:��>w����QZ.��7�/FW��.���Fd��H�oKJ�����8Y?��@ ������e3H�NE$f7�u��;�������u������+i�Mq)�8���w��]Y��A9���v�*��+E�f�<k���g��P�=lEI�6�������l�sBn]��hn�$c�dR����>W�m�c����N��"���#e\)� �Th���^��}�n�4�ZT�5�m�9�qJ���~dy)T)��9�X�hQ�X���z�a���T%�#5�((E�q������GVL������7�&Kb�����*�������d�O�O�����s��[���W��-��[7����;��+��d/�Z�w.*����\w���2��
��c��B�3v�N;">NJ�_k���{���;3N���I������o  �P|Y�7i���<�Rv{�Q�h�L����!w��k������c�I�������VR:k*�k<�v��[[������z��#��1paI�9���@g��_g����(�g#tp���v����Y�f��!���UvQ�$A��������Y��;����3jK��A6�����Ug������K��R�����K�]���;�fK"^�KH�I�d����]Wu��4��,���R�|���B�c��F����H 2��z��a
"�G�``�^yF�,i$��%Pt�n<���������r\=}�\�-'���o�������dXv>��M��H'W�����wK�"����#w	rKA,�[2����'sG��I�)�-���S�K���U2������|m��J��>��y?�r�d+�J�#�`�o�{B�+k������u���������^����@�0V�u~%$<{���'n�d�����1hd���#�y���*Sb�c�5&j�/(�>��������?8m�T	�M������r��d��\Z�+��@��D�� �����H�7]*i�zH�n����u��s�i��s
�Z0����?}!�z|��z�;{�v�[*��3
R��������G��	6Fy�Z�
��v!	X�ci�~9�D��=�+!�����'�������{��% ��@�x�c�u�r�����L��Q��=���^���6�!`A���,����H�N�g�F��I���*��Y�x��[�{��c;.I��
I��	�����/�ZK�)��<�+N���&�Wc+Y^��^�7��M�n�(^��K�����#�"�"�����A���������Y7/>����+�����2��Zi?�������u�ijc�t��R�y^e�L��Yn]~(#Vz�{��w��#�����{��c�g��?���l��r`��x�tG&�#�(`E�^p�:`Q���M����MS��v�-exa�c�6����������5���<��/����$m7,x��Q�Bz����g�I������Sm�2V!V�,1��A1J���������rJ�
O��pd�E�n}s+Ajx�e�������-:%��#?nk-���g���5�K����g�Q���%��PFkD������[_�0��y�a��[J�A	ua��X�;����k���D�����9����Z����~�������mAx��\�T�{���C-�D��J�I�,��Tb��&�h��(Q�(�F���zA���?��/u�D!���c�I��;�G��}h�>��Iv���E�\�-����H�� `�����x��#W7U�(����)X��2��r����Y���b}��y
K�������F����6E��^�8�u��\����G��@,P>C�������_��&��9B?-��j�G%1���'��7������{�����^g��a^K��iH���G!,!��H�c�������{at�21B����0{�S�."A)<�.����52���R�Y0��$���!L����d�4��vI~�f�%r
��9����H���,�����%��7��!����V��<~~���*���,�G�*s������� ��
//�8��h��Eh���OF?���F�@E�>�����n2����;���x����^^����Pf.�;<�&�jk�{S������,m��r7�>.�&�W�c��q,�)�}���1��q>���f�c�������\ �$q��c���+2���}k�x�#`����8��������N�m��y{�,�A
xQ������{%`�Kwz��b�I�����&�m6�=�/�o���=��{��c��k0�<+g���1���v�������&`�c��F�_)�'��(`}H�.�.�xt�3B;O�������A5�
9� VpOxl�]�3��>+���B��R@^&�g�;t�Z���Yi�d-�RPgsA������7��9%`���@5X,^��K���y��O
�B1������ex��C�=C��w������=����2r��y�?���q`.���g�����v.�n?y',����*���m,s���Ox�]��urR`�?�F�����Ra)��C>�!��	X�c'�D�!	X��%�c���	����x@c.4�E��]�����6�17��s��{�A�=iO�&�=k�a� �V��A��a�q�y�x���K�T�/n�B+��� 8"%DD������6��A�W�1V�Q.+[���V�U>����l�����	X��x������H�>
X���S������)�,6 ��g���$�a��-k�����2���fZ-��?��1�05�~�=(���U���[�H�s���{�_����������������X�����d��l��q�d��S�k.$6�0'�G~��B����iB�xi.���Cu:���-��y�t��N��������41'?7~������_��V�g ����7I�/���rp �n��>Kw��c�����{�<�' �������h��G�
=G� ���v�o;UM{�,C�2��
Oo����;%`�x^���y��_�t����X��4�uU����/6���)yK~��A����F�{!���EZ
*m���e�W��7u�bo��t���x`��h#��L^G$P����u����Wp������2���p	X�0���Qpz��y'd���*�<r*��NW�M��)<w��H2o��c��v+<�o9�N2'w��%�O���,<���!�(�����b���6#),�����`����t#�H�j�By2u_U��W% n��X����M-9����G�����Q���f:��<cxr`���n>��	�Ux!
`�!��$����RI����^[��C�v�W��~2���9��
=^�'`��]�T�-�c���	��],G���hxmu�)���1<z�Y�-`���F�%`a��[s�J1��(G|.���7��ssNE�uUg,��������8��8���=���i�d�C�����r`��wMm�����;�u�]Wu���}�um<��#���	D�"C/�@t,�|�;�Q��f&,�;}8��.��eL���h��y���J.��'��lW���a{Fn#�}��BgW�4C�6���q��cx���nu�.���XzJ T�J�H�.�>4�������^8�ap��2-�l3D*����8@�<I�1���B~(�@���cIh�]�������KS^�x-����g6P1�p
!N
D
NI�)���]TGi���a��q6��2������RS8����,�?$���J7�)���w����oo1�`�y�P?x[�Cy���M��h��2|4��Q���`���������5N�i�L[l"	��"�+`9�F��
oY�R�y'�����N����b���hKw�w������M X�R���'H^/�^�k[	D��t�_x2c�km�I��G��+km����<�0��a��	������lW�[��*��N[t�����^��]~w�Z�2q
!�	����2Gw�f98@������&:��H�!(`9#b����qb��{������c$n��<��*��*�Z����)c�X�� �u����WU��|��+��������(�Cx!�X���c��bb�=���'P9��c)mV��y��8R���}���Ms�+��>`�B`��6����������������0NWD���>*�N2
�-��c��c��sl���j�@�C��t�6������/+&P��U��B_��y�ND>+��K�9�j���2�����M����n�|]�]�|������3���y���nCs������5N�N���3�y-	�	������h�&��<&���R^?��c�s�2
rZ������Y�9�Q!�x��<o�u���uo����t�w��S��m\�c�wNA�]Wu�t���#v){q���Vi����@�f(
�X�&y�����?ac"�6��E�-:u�g]�Y�m�$�B+�0{���x�tG%�#�(`E�^`H��M $�4��H�H�H���BI���bH�H�	P�r�Ng�I�	P�r�^e�H�H�H �(`��!�@$@������	�@�	P�
7B>�H�H���,��V6�H�	P�r�Ng�I�H�H�H�H�H�H�H��D����XW       pA���oRv���IEND�B`�
#21Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Alena Rybakina (#20)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 27.06.2023 16:19, Alena Rybakina wrote:

Thank you for your feedback, your work is also very interesting and
important, and I will be happy to review it. I learned something new
from your letter, thank you very much for that!

I analyzed the buffer consumption when I ran control regression tests
using my patch. diff shows me that there is no difference between the
number of buffer block scans without and using my patch, as far as I
have seen. (regression.diffs)

In addition, I analyzed the scheduling and duration of the execution
time of the source code and with my applied patch. I generated 20
billion data from pgbench and plotted the scheduling and execution
time depending on the number of "or" expressions.
By runtime, I noticed a clear acceleration for queries when using the
index, but I can't say the same when the index is disabled.
At first I turned it off in this way:
1)enable_seqscan='off'
2)enable_indexonlyscan='off'
enable_indexscan='off'

Unfortunately, it is not yet clear which constant needs to be set when
the transformation needs to be done, I will still study in detail.
(the graph for all this is presented in graph1.svg)
\\
--
Regards,
Alena Rybakina

Sorry, just now I noticed that there were incorrect names in the
headings of the pictures, I corrected it. I also attach its html copy,
because it may be more convenient for viewing it.

--
Regards,
Alena Rybakina

Attachments:

graphs.htmltext/html; charset=UTF-8; name=graphs.htmlDownload

<!-- saved from url=(0062)file:///home/alena/Downloads/Telegram%20Desktop/temp-plot.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><style id="plotly.js-style-global"></style><style id="plotly.js-style-modebar-1bd8a8"></style></head>
<body>
    <div>                        <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>
        <script type="text/javascript">/**
* plotly.js v2.12.1
* Copyright 2012-2022, Plotly, Inc.
* All rights reserved.
* Licensed under the MIT license
*/
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Plotly=t()}}((function(){return function t(e,r,n){function i(o,s){if(!r[o]){if(!e[o]){var l="function"==typeof require&&require;if(!s&&l)return l(o,!0);if(a)return a(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var u=r[o]={exports:{}};e[o][0].call(u.exports,(function(t){return i(e[o][1][t]||t)}),u,u.exports,t,e,r,n)}return r[o].exports}for(var a="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);return i}({1:[function(t,e,r){"use strict";var n=t("../src/lib"),i={"X,X div":'direction:ltr;font-family:"Open Sans",verdana,arial,sans-serif;margin:0;padding:0;',"X input,X button":'font-family:"Open Sans",verdana,arial,sans-serif;',"X input:focus,X button:focus":"outline:none;","X a":"text-decoration:none;","X a:hover":"text-decoration:none;","X .crisp":"shape-rendering:crispEdges;","X .user-select-none":"-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;","X svg":"overflow:hidden;","X svg a":"fill:#447adb;","X svg a:hover":"fill:#3c6dc5;","X .main-svg":"position:absolute;top:0;left:0;pointer-events:none;","X .main-svg .draglayer":"pointer-events:all;","X .cursor-default":"cursor:default;","X .cursor-pointer":"cursor:pointer;","X .cursor-crosshair":"cursor:crosshair;","X .cursor-move":"cursor:move;","X .cursor-col-resize":"cursor:col-resize;","X .cursor-row-resize":"cursor:row-resize;","X .cursor-ns-resize":"cursor:ns-resize;","X .cursor-ew-resize":"cursor:ew-resize;","X .cursor-sw-resize":"cursor:sw-resize;","X .cursor-s-resize":"cursor:s-resize;","X .cursor-se-resize":"cursor:se-resize;","X .cursor-w-resize":"cursor:w-resize;","X .cursor-e-resize":"cursor:e-resize;","X .cursor-nw-resize":"cursor:nw-resize;","X .cursor-n-resize":"cursor:n-resize;","X .cursor-ne-resize":"cursor:ne-resize;","X .cursor-grab":"cursor:-webkit-grab;cursor:grab;","X .modebar":"position:absolute;top:2px;right:2px;","X .ease-bg":"-webkit-transition:background-color .3s ease 0s;-moz-transition:background-color .3s ease 0s;-ms-transition:background-color .3s ease 0s;-o-transition:background-color .3s ease 0s;transition:background-color .3s ease 0s;","X .modebar--hover>:not(.watermark)":"opacity:0;-webkit-transition:opacity .3s ease 0s;-moz-transition:opacity .3s ease 0s;-ms-transition:opacity .3s ease 0s;-o-transition:opacity .3s ease 0s;transition:opacity .3s ease 0s;","X:hover .modebar--hover .modebar-group":"opacity:1;","X .modebar-group":"float:left;display:inline-block;box-sizing:border-box;padding-left:8px;position:relative;vertical-align:middle;white-space:nowrap;","X .modebar-btn":"position:relative;font-size:16px;padding:3px 4px;height:22px;cursor:pointer;line-height:normal;box-sizing:border-box;","X .modebar-btn svg":"position:relative;top:2px;","X .modebar.vertical":"display:flex;flex-direction:column;flex-wrap:wrap;align-content:flex-end;max-height:100%;","X .modebar.vertical svg":"top:-1px;","X .modebar.vertical .modebar-group":"display:block;float:none;padding-left:0px;padding-bottom:8px;","X .modebar.vertical .modebar-group .modebar-btn":"display:block;text-align:center;","X [data-title]:before,X [data-title]:after":"position:absolute;-webkit-transform:translate3d(0, 0, 0);-moz-transform:translate3d(0, 0, 0);-ms-transform:translate3d(0, 0, 0);-o-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0);display:none;opacity:0;z-index:1001;pointer-events:none;top:110%;right:50%;","X [data-title]:hover:before,X [data-title]:hover:after":"display:block;opacity:1;","X [data-title]:before":'content:"";position:absolute;background:rgba(0,0,0,0);border:6px solid rgba(0,0,0,0);z-index:1002;margin-top:-12px;border-bottom-color:#69738a;margin-right:-6px;',"X [data-title]:after":"content:attr(data-title);background:#69738a;color:#fff;padding:8px 10px;font-size:12px;line-height:12px;white-space:nowrap;margin-right:-18px;border-radius:2px;","X .vertical [data-title]:before,X .vertical [data-title]:after":"top:0%;right:200%;","X .vertical [data-title]:before":"border:6px solid rgba(0,0,0,0);border-left-color:#69738a;margin-top:8px;margin-right:-30px;","X .select-outline":"fill:none;stroke-width:1;shape-rendering:crispEdges;","X .select-outline-1":"stroke:#fff;","X .select-outline-2":"stroke:#000;stroke-dasharray:2px 2px;",Y:'font-family:"Open Sans",verdana,arial,sans-serif;position:fixed;top:50px;right:20px;z-index:10000;font-size:10pt;max-width:180px;',"Y p":"margin:0;","Y .notifier-note":"min-width:180px;max-width:250px;border:1px solid #fff;z-index:3000;margin:0;background-color:#8c97af;background-color:rgba(140,151,175,.9);color:#fff;padding:10px;overflow-wrap:break-word;word-wrap:break-word;-ms-hyphens:auto;-webkit-hyphens:auto;hyphens:auto;","Y .notifier-close":"color:#fff;opacity:.8;float:right;padding:0 5px;background:none;border:none;font-size:20px;font-weight:bold;line-height:20px;","Y .notifier-close:hover":"color:#444;text-decoration:none;cursor:pointer;"};for(var a in i){var o=a.replace(/^,/," ,").replace(/X/g,".js-plotly-plot .plotly").replace(/Y/g,".plotly-notifier");n.addStyleRule(o,i[a])}},{"../src/lib":503}],2:[function(t,e,r){"use strict";e.exports=t("../src/transforms/aggregate")},{"../src/transforms/aggregate":1118}],3:[function(t,e,r){"use strict";e.exports=t("../src/traces/bar")},{"../src/traces/bar":656}],4:[function(t,e,r){"use strict";e.exports=t("../src/traces/barpolar")},{"../src/traces/barpolar":669}],5:[function(t,e,r){"use strict";e.exports=t("../src/traces/box")},{"../src/traces/box":679}],6:[function(t,e,r){"use strict";e.exports=t("../src/components/calendars")},{"../src/components/calendars":364}],7:[function(t,e,r){"use strict";e.exports=t("../src/traces/candlestick")},{"../src/traces/candlestick":688}],8:[function(t,e,r){"use strict";e.exports=t("../src/traces/carpet")},{"../src/traces/carpet":707}],9:[function(t,e,r){"use strict";e.exports=t("../src/traces/choropleth")},{"../src/traces/choropleth":721}],10:[function(t,e,r){"use strict";e.exports=t("../src/traces/choroplethmapbox")},{"../src/traces/choroplethmapbox":728}],11:[function(t,e,r){"use strict";e.exports=t("../src/traces/cone")},{"../src/traces/cone":734}],12:[function(t,e,r){"use strict";e.exports=t("../src/traces/contour")},{"../src/traces/contour":749}],13:[function(t,e,r){"use strict";e.exports=t("../src/traces/contourcarpet")},{"../src/traces/contourcarpet":760}],14:[function(t,e,r){"use strict";e.exports=t("../src/core")},{"../src/core":481}],15:[function(t,e,r){"use strict";e.exports=t("../src/traces/densitymapbox")},{"../src/traces/densitymapbox":768}],16:[function(t,e,r){"use strict";e.exports=t("../src/transforms/filter")},{"../src/transforms/filter":1119}],17:[function(t,e,r){"use strict";e.exports=t("../src/traces/funnel")},{"../src/traces/funnel":778}],18:[function(t,e,r){"use strict";e.exports=t("../src/traces/funnelarea")},{"../src/traces/funnelarea":787}],19:[function(t,e,r){"use strict";e.exports=t("../src/transforms/groupby")},{"../src/transforms/groupby":1120}],20:[function(t,e,r){"use strict";e.exports=t("../src/traces/heatmap")},{"../src/traces/heatmap":800}],21:[function(t,e,r){"use strict";e.exports=t("../src/traces/heatmapgl")},{"../src/traces/heatmapgl":811}],22:[function(t,e,r){"use strict";e.exports=t("../src/traces/histogram")},{"../src/traces/histogram":823}],23:[function(t,e,r){"use strict";e.exports=t("../src/traces/histogram2d")},{"../src/traces/histogram2d":829}],24:[function(t,e,r){"use strict";e.exports=t("../src/traces/histogram2dcontour")},{"../src/traces/histogram2dcontour":833}],25:[function(t,e,r){"use strict";e.exports=t("../src/traces/icicle")},{"../src/traces/icicle":839}],26:[function(t,e,r){"use strict";e.exports=t("../src/traces/image")},{"../src/traces/image":852}],27:[function(t,e,r){"use strict";var n=t("./core");n.register([t("./bar"),t("./box"),t("./heatmap"),t("./histogram"),t("./histogram2d"),t("./histogram2dcontour"),t("./contour"),t("./scatterternary"),t("./violin"),t("./funnel"),t("./waterfall"),t("./image"),t("./pie"),t("./sunburst"),t("./treemap"),t("./icicle"),t("./funnelarea"),t("./scatter3d"),t("./surface"),t("./isosurface"),t("./volume"),t("./mesh3d"),t("./cone"),t("./streamtube"),t("./scattergeo"),t("./choropleth"),t("./scattergl"),t("./splom"),t("./pointcloud"),t("./heatmapgl"),t("./parcoords"),t("./parcats"),t("./scattermapbox"),t("./choroplethmapbox"),t("./densitymapbox"),t("./sankey"),t("./indicator"),t("./table"),t("./carpet"),t("./scattercarpet"),t("./contourcarpet"),t("./ohlc"),t("./candlestick"),t("./scatterpolar"),t("./scatterpolargl"),t("./barpolar"),t("./scattersmith"),t("./aggregate"),t("./filter"),t("./groupby"),t("./sort"),t("./calendars")]),e.exports=n},{"./aggregate":2,"./bar":3,"./barpolar":4,"./box":5,"./calendars":6,"./candlestick":7,"./carpet":8,"./choropleth":9,"./choroplethmapbox":10,"./cone":11,"./contour":12,"./contourcarpet":13,"./core":14,"./densitymapbox":15,"./filter":16,"./funnel":17,"./funnelarea":18,"./groupby":19,"./heatmap":20,"./heatmapgl":21,"./histogram":22,"./histogram2d":23,"./histogram2dcontour":24,"./icicle":25,"./image":26,"./indicator":28,"./isosurface":29,"./mesh3d":30,"./ohlc":31,"./parcats":32,"./parcoords":33,"./pie":34,"./pointcloud":35,"./sankey":36,"./scatter3d":37,"./scattercarpet":38,"./scattergeo":39,"./scattergl":40,"./scattermapbox":41,"./scatterpolar":42,"./scatterpolargl":43,"./scattersmith":44,"./scatterternary":45,"./sort":46,"./splom":47,"./streamtube":48,"./sunburst":49,"./surface":50,"./table":51,"./treemap":52,"./violin":53,"./volume":54,"./waterfall":55}],28:[function(t,e,r){"use strict";e.exports=t("../src/traces/indicator")},{"../src/traces/indicator":860}],29:[function(t,e,r){"use strict";e.exports=t("../src/traces/isosurface")},{"../src/traces/isosurface":866}],30:[function(t,e,r){"use strict";e.exports=t("../src/traces/mesh3d")},{"../src/traces/mesh3d":871}],31:[function(t,e,r){"use strict";e.exports=t("../src/traces/ohlc")},{"../src/traces/ohlc":876}],32:[function(t,e,r){"use strict";e.exports=t("../src/traces/parcats")},{"../src/traces/parcats":885}],33:[function(t,e,r){"use strict";e.exports=t("../src/traces/parcoords")},{"../src/traces/parcoords":896}],34:[function(t,e,r){"use strict";e.exports=t("../src/traces/pie")},{"../src/traces/pie":907}],35:[function(t,e,r){"use strict";e.exports=t("../src/traces/pointcloud")},{"../src/traces/pointcloud":916}],36:[function(t,e,r){"use strict";e.exports=t("../src/traces/sankey")},{"../src/traces/sankey":922}],37:[function(t,e,r){"use strict";e.exports=t("../src/traces/scatter3d")},{"../src/traces/scatter3d":960}],38:[function(t,e,r){"use strict";e.exports=t("../src/traces/scattercarpet")},{"../src/traces/scattercarpet":967}],39:[function(t,e,r){"use strict";e.exports=t("../src/traces/scattergeo")},{"../src/traces/scattergeo":975}],40:[function(t,e,r){"use strict";e.exports=t("../src/traces/scattergl")},{"../src/traces/scattergl":989}],41:[function(t,e,r){"use strict";e.exports=t("../src/traces/scattermapbox")},{"../src/traces/scattermapbox":999}],42:[function(t,e,r){"use strict";e.exports=t("../src/traces/scatterpolar")},{"../src/traces/scatterpolar":1007}],43:[function(t,e,r){"use strict";e.exports=t("../src/traces/scatterpolargl")},{"../src/traces/scatterpolargl":1015}],44:[function(t,e,r){"use strict";e.exports=t("../src/traces/scattersmith")},{"../src/traces/scattersmith":1022}],45:[function(t,e,r){"use strict";e.exports=t("../src/traces/scatterternary")},{"../src/traces/scatterternary":1030}],46:[function(t,e,r){"use strict";e.exports=t("../src/transforms/sort")},{"../src/transforms/sort":1122}],47:[function(t,e,r){"use strict";e.exports=t("../src/traces/splom")},{"../src/traces/splom":1040}],48:[function(t,e,r){"use strict";e.exports=t("../src/traces/streamtube")},{"../src/traces/streamtube":1048}],49:[function(t,e,r){"use strict";e.exports=t("../src/traces/sunburst")},{"../src/traces/sunburst":1056}],50:[function(t,e,r){"use strict";e.exports=t("../src/traces/surface")},{"../src/traces/surface":1065}],51:[function(t,e,r){"use strict";e.exports=t("../src/traces/table")},{"../src/traces/table":1073}],52:[function(t,e,r){"use strict";e.exports=t("../src/traces/treemap")},{"../src/traces/treemap":1084}],53:[function(t,e,r){"use strict";e.exports=t("../src/traces/violin")},{"../src/traces/violin":1097}],54:[function(t,e,r){"use strict";e.exports=t("../src/traces/volume")},{"../src/traces/volume":1105}],55:[function(t,e,r){"use strict";e.exports=t("../src/traces/waterfall")},{"../src/traces/waterfall":1113}],56:[function(t,e,r){!function(n,i){"object"==typeof r&&void 0!==e?i(r,t("d3-array"),t("d3-collection"),t("d3-shape"),t("elementary-circuits-directed-graph")):i(n.d3=n.d3||{},n.d3,n.d3,n.d3,null)}(this,(function(t,e,r,n,i){"use strict";function a(t){return t.target.depth}function o(t,e){return t.sourceLinks.length?t.depth:e-1}function s(t){return function(){return t}}i=i&&i.hasOwnProperty("default")?i.default:i;var l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};function c(t,e){return f(t.source,e.source)||t.index-e.index}function u(t,e){return f(t.target,e.target)||t.index-e.index}function f(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function h(t){return t.value}function p(t){return(t.y0+t.y1)/2}function d(t){return p(t.source)}function m(t){return p(t.target)}function g(t){return t.index}function v(t){return t.nodes}function y(t){return t.links}function x(t,e){var r=t.get(e);if(!r)throw new Error("missing: "+e);return r}function b(t,e){return e(t)}function _(t,e,r){var n=0;if(null===r){for(var a=[],o=0;o<t.links.length;o++){var s=t.links[o],l=s.source.index,c=s.target.index;a[l]||(a[l]=[]),a[c]||(a[c]=[]),-1===a[l].indexOf(c)&&a[l].push(c)}var u=i(a);u.sort((function(t,e){return t.length-e.length}));var f={};for(o=0;o<u.length;o++){var h=u[o].slice(-2);f[h[0]]||(f[h[0]]={}),f[h[0]][h[1]]=!0}t.links.forEach((function(t){var e=t.target.index,r=t.source.index;e===r||f[r]&&f[r][e]?(t.circular=!0,t.circularLinkID=n,n+=1):t.circular=!1}))}else t.links.forEach((function(t){t.source[r]<t.target[r]?t.circular=!1:(t.circular=!0,t.circularLinkID=n,n+=1)}))}function w(t,e){var r=0,n=0;t.links.forEach((function(i){i.circular&&(i.source.circularLinkType||i.target.circularLinkType?i.circularLinkType=i.source.circularLinkType?i.source.circularLinkType:i.target.circularLinkType:i.circularLinkType=r<n?"top":"bottom","top"==i.circularLinkType?r+=1:n+=1,t.nodes.forEach((function(t){b(t,e)!=b(i.source,e)&&b(t,e)!=b(i.target,e)||(t.circularLinkType=i.circularLinkType)})))})),t.links.forEach((function(t){t.circular&&(t.source.circularLinkType==t.target.circularLinkType&&(t.circularLinkType=t.source.circularLinkType),q(t,e)&&(t.circularLinkType=t.source.circularLinkType))}))}function T(t){var e=Math.abs(t.y1-t.y0),r=Math.abs(t.target.x0-t.source.x1);return Math.atan(r/e)}function k(t,e){var r=0;t.sourceLinks.forEach((function(t){r=t.circular&&!q(t,e)?r+1:r}));var n=0;return t.targetLinks.forEach((function(t){n=t.circular&&!q(t,e)?n+1:n})),r+n}function A(t){var e=t.source.sourceLinks,r=0;e.forEach((function(t){r=t.circular?r+1:r}));var n=t.target.targetLinks,i=0;return n.forEach((function(t){i=t.circular?i+1:i})),!(r>1||i>1)}function M(t,e,r){return t.sort(E),t.forEach((function(n,i){var a,o,s=0;if(q(n,r)&&A(n))n.circularPathData.verticalBuffer=s+n.width/2;else{for(var l=0;l<i;l++)if(a=t[i],o=t[l],!(a.source.column<o.target.column||a.target.column>o.source.column)){var c=t[l].circularPathData.verticalBuffer+t[l].width/2+e;s=c>s?c:s}n.circularPathData.verticalBuffer=s+n.width/2}})),t}function S(t,r,i,a){var o=e.min(t.links,(function(t){return t.source.y0}));t.links.forEach((function(t){t.circular&&(t.circularPathData={})})),M(t.links.filter((function(t){return"top"==t.circularLinkType})),r,a),M(t.links.filter((function(t){return"bottom"==t.circularLinkType})),r,a),t.links.forEach((function(e){if(e.circular){if(e.circularPathData.arcRadius=e.width+10,e.circularPathData.leftNodeBuffer=5,e.circularPathData.rightNodeBuffer=5,e.circularPathData.sourceWidth=e.source.x1-e.source.x0,e.circularPathData.sourceX=e.source.x0+e.circularPathData.sourceWidth,e.circularPathData.targetX=e.target.x0,e.circularPathData.sourceY=e.y0,e.circularPathData.targetY=e.y1,q(e,a)&&A(e))e.circularPathData.leftSmallArcRadius=10+e.width/2,e.circularPathData.leftLargeArcRadius=10+e.width/2,e.circularPathData.rightSmallArcRadius=10+e.width/2,e.circularPathData.rightLargeArcRadius=10+e.width/2,"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=e.source.y1+25+e.circularPathData.verticalBuffer,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius):(e.circularPathData.verticalFullExtent=e.source.y0-25-e.circularPathData.verticalBuffer,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius);else{var s=e.source.column,l=e.circularLinkType,c=t.links.filter((function(t){return t.source.column==s&&t.circularLinkType==l}));"bottom"==e.circularLinkType?c.sort(C):c.sort(L);var u=0;c.forEach((function(t,n){t.circularLinkID==e.circularLinkID&&(e.circularPathData.leftSmallArcRadius=10+e.width/2+u,e.circularPathData.leftLargeArcRadius=10+e.width/2+n*r+u),u+=t.width})),s=e.target.column,c=t.links.filter((function(t){return t.target.column==s&&t.circularLinkType==l})),"bottom"==e.circularLinkType?c.sort(I):c.sort(P),u=0,c.forEach((function(t,n){t.circularLinkID==e.circularLinkID&&(e.circularPathData.rightSmallArcRadius=10+e.width/2+u,e.circularPathData.rightLargeArcRadius=10+e.width/2+n*r+u),u+=t.width})),"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=Math.max(i,e.source.y1,e.target.y1)+25+e.circularPathData.verticalBuffer,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius):(e.circularPathData.verticalFullExtent=o-25-e.circularPathData.verticalBuffer,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius)}e.circularPathData.leftInnerExtent=e.circularPathData.sourceX+e.circularPathData.leftNodeBuffer,e.circularPathData.rightInnerExtent=e.circularPathData.targetX-e.circularPathData.rightNodeBuffer,e.circularPathData.leftFullExtent=e.circularPathData.sourceX+e.circularPathData.leftLargeArcRadius+e.circularPathData.leftNodeBuffer,e.circularPathData.rightFullExtent=e.circularPathData.targetX-e.circularPathData.rightLargeArcRadius-e.circularPathData.rightNodeBuffer}if(e.circular)e.path=function(t){var e="";e="top"==t.circularLinkType?"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 0 "+t.circularPathData.leftFullExtent+" "+(t.circularPathData.sourceY-t.circularPathData.leftSmallArcRadius)+" L"+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 0 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 0 "+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" L"+t.circularPathData.rightFullExtent+" "+(t.circularPathData.targetY-t.circularPathData.rightSmallArcRadius)+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 0 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY:"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 1 "+t.circularPathData.leftFullExtent+" "+(t.circularPathData.sourceY+t.circularPathData.leftSmallArcRadius)+" L"+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 1 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 1 "+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" L"+t.circularPathData.rightFullExtent+" "+(t.circularPathData.targetY+t.circularPathData.rightSmallArcRadius)+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 1 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY;return e}(e);else{var f=n.linkHorizontal().source((function(t){return[t.source.x0+(t.source.x1-t.source.x0),t.y0]})).target((function(t){return[t.target.x0,t.y1]}));e.path=f(e)}}))}function E(t,e){return O(t)==O(e)?"bottom"==t.circularLinkType?C(t,e):L(t,e):O(e)-O(t)}function L(t,e){return t.y0-e.y0}function C(t,e){return e.y0-t.y0}function P(t,e){return t.y1-e.y1}function I(t,e){return e.y1-t.y1}function O(t){return t.target.column-t.source.column}function z(t){return t.target.x0-t.source.x1}function D(t,e){var r=T(t),n=z(e)/Math.tan(r);return"up"==H(t)?t.y1+n:t.y1-n}function R(t,e){var r=T(t),n=z(e)/Math.tan(r);return"up"==H(t)?t.y1-n:t.y1+n}function F(t,e,r,n){t.links.forEach((function(i){if(!i.circular&&i.target.column-i.source.column>1){var a=i.source.column+1,o=i.target.column-1,s=1,l=o-a+1;for(s=1;a<=o;a++,s++)t.nodes.forEach((function(o){if(o.column==a){var c,u=s/(l+1),f=Math.pow(1-u,3),h=3*u*Math.pow(1-u,2),p=3*Math.pow(u,2)*(1-u),d=Math.pow(u,3),m=f*i.y0+h*i.y0+p*i.y1+d*i.y1,g=m-i.width/2,v=m+i.width/2;g>o.y0&&g<o.y1?(c=o.y1-g+10,c="bottom"==o.circularLinkType?c:-c,o=N(o,c,e,r),t.nodes.forEach((function(t){b(t,n)!=b(o,n)&&t.column==o.column&&B(o,t)&&N(t,c,e,r)}))):(v>o.y0&&v<o.y1||g<o.y0&&v>o.y1)&&(c=v-o.y0+10,o=N(o,c,e,r),t.nodes.forEach((function(t){b(t,n)!=b(o,n)&&t.column==o.column&&t.y0<o.y1&&t.y1>o.y1&&N(t,c,e,r)})))}}))}}))}function B(t,e){return t.y0>e.y0&&t.y0<e.y1||(t.y1>e.y0&&t.y1<e.y1||t.y0<e.y0&&t.y1>e.y1)}function N(t,e,r,n){return t.y0+e>=r&&t.y1+e<=n&&(t.y0=t.y0+e,t.y1=t.y1+e,t.targetLinks.forEach((function(t){t.y1=t.y1+e})),t.sourceLinks.forEach((function(t){t.y0=t.y0+e}))),t}function j(t,e,r,n){t.nodes.forEach((function(i){n&&i.y+(i.y1-i.y0)>e&&(i.y=i.y-(i.y+(i.y1-i.y0)-e));var a=t.links.filter((function(t){return b(t.source,r)==b(i,r)})),o=a.length;o>1&&a.sort((function(t,e){if(!t.circular&&!e.circular){if(t.target.column==e.target.column)return t.y1-e.y1;if(!V(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var r=R(e,t);return t.y1-r}if(e.target.column>t.target.column)return R(t,e)-e.y1}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.target.column===e.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.target.column===e.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:"top"==t.circularLinkType?-1:1:void 0}));var s=i.y0;a.forEach((function(t){t.y0=s+t.width/2,s+=t.width})),a.forEach((function(t,e){if("bottom"==t.circularLinkType){for(var r=e+1,n=0;r<o;r++)n+=a[r].width;t.y0=i.y1-n-t.width/2}}))}))}function U(t,e,r){t.nodes.forEach((function(e){var n=t.links.filter((function(t){return b(t.target,r)==b(e,r)})),i=n.length;i>1&&n.sort((function(t,e){if(!t.circular&&!e.circular){if(t.source.column==e.source.column)return t.y0-e.y0;if(!V(t,e))return t.y0-e.y0;if(e.source.column<t.source.column){var r=D(e,t);return t.y0-r}if(t.source.column<e.source.column)return D(t,e)-e.y0}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:t.source.column-e.source.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:e.source.column-t.source.column:"top"==t.circularLinkType?-1:1:void 0}));var a=e.y0;n.forEach((function(t){t.y1=a+t.width/2,a+=t.width})),n.forEach((function(t,r){if("bottom"==t.circularLinkType){for(var a=r+1,o=0;a<i;a++)o+=n[a].width;t.y1=e.y1-o-t.width/2}}))}))}function V(t,e){return H(t)==H(e)}function H(t){return t.y0-t.y1>0?"up":"down"}function q(t,e){return b(t.source,e)==b(t.target,e)}function G(t,r,n){var i=t.nodes,a=t.links,o=!1,s=!1;if(a.forEach((function(t){"top"==t.circularLinkType?o=!0:"bottom"==t.circularLinkType&&(s=!0)})),0==o||0==s){var l=e.min(i,(function(t){return t.y0})),c=(n-r)/(e.max(i,(function(t){return t.y1}))-l);i.forEach((function(t){var e=(t.y1-t.y0)*c;t.y0=(t.y0-l)*c,t.y1=t.y0+e})),a.forEach((function(t){t.y0=(t.y0-l)*c,t.y1=(t.y1-l)*c,t.width=t.width*c}))}}t.sankeyCircular=function(){var t,n,i=0,a=0,b=1,T=1,A=24,M=g,E=o,L=v,C=y,P=32,I=2,O=null;function z(){var t={nodes:L.apply(null,arguments),links:C.apply(null,arguments)};D(t),_(t,M,O),R(t),B(t),w(t,M),N(t,P,M),V(t);for(var e=4,r=0;r<e;r++)j(t,T,M),U(t,T,M),F(t,a,T,M),j(t,T,M),U(t,T,M);return G(t,a,T),S(t,I,T,M),t}function D(t){t.nodes.forEach((function(t,e){t.index=e,t.sourceLinks=[],t.targetLinks=[]}));var e=r.map(t.nodes,M);return t.links.forEach((function(t,r){t.index=r;var n=t.source,i=t.target;"object"!==(void 0===n?"undefined":l(n))&&(n=t.source=x(e,n)),"object"!==(void 0===i?"undefined":l(i))&&(i=t.target=x(e,i)),n.sourceLinks.push(t),i.targetLinks.push(t)})),t}function R(t){t.nodes.forEach((function(t){t.partOfCycle=!1,t.value=Math.max(e.sum(t.sourceLinks,h),e.sum(t.targetLinks,h)),t.sourceLinks.forEach((function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)})),t.targetLinks.forEach((function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)}))}))}function B(t){var e,r,n;for(e=t.nodes,r=[],n=0;e.length;++n,e=r,r=[])e.forEach((function(t){t.depth=n,t.sourceLinks.forEach((function(t){r.indexOf(t.target)<0&&!t.circular&&r.push(t.target)}))}));for(e=t.nodes,r=[],n=0;e.length;++n,e=r,r=[])e.forEach((function(t){t.height=n,t.targetLinks.forEach((function(t){r.indexOf(t.source)<0&&!t.circular&&r.push(t.source)}))}));t.nodes.forEach((function(t){t.column=Math.floor(E.call(null,t,n))}))}function N(o,s,l){var c=r.nest().key((function(t){return t.column})).sortKeys(e.ascending).entries(o.nodes).map((function(t){return t.values}));!function(r){if(n){var s=1/0;c.forEach((function(t){var e=T*n/(t.length+1);s=e<s?e:s})),t=s}var l=e.min(c,(function(r){return(T-a-(r.length-1)*t)/e.sum(r,h)}));l*=.3,o.links.forEach((function(t){t.width=t.value*l}));var u=function(t){var r=0,n=0,i=0,a=0,o=e.max(t.nodes,(function(t){return t.column}));return t.links.forEach((function(t){t.circular&&("top"==t.circularLinkType?r+=t.width:n+=t.width,0==t.target.column&&(a+=t.width),t.source.column==o&&(i+=t.width))})),{top:r=r>0?r+25+10:r,bottom:n=n>0?n+25+10:n,left:a=a>0?a+25+10:a,right:i=i>0?i+25+10:i}}(o),f=function(t,r){var n=e.max(t.nodes,(function(t){return t.column})),o=b-i,s=T-a,l=o/(o+r.right+r.left),c=s/(s+r.top+r.bottom);return i=i*l+r.left,b=0==r.right?b:b*l,a=a*c+r.top,T*=c,t.nodes.forEach((function(t){t.x0=i+t.column*((b-i-A)/n),t.x1=t.x0+A})),c}(o,u);l*=f,o.links.forEach((function(t){t.width=t.value*l})),c.forEach((function(t){var e=t.length;t.forEach((function(t,n){t.depth==c.length-1&&1==e||0==t.depth&&1==e?(t.y0=T/2-t.value*l,t.y1=t.y0+t.value*l):t.partOfCycle?0==k(t,r)?(t.y0=T/2+n,t.y1=t.y0+t.value*l):"top"==t.circularLinkType?(t.y0=a+n,t.y1=t.y0+t.value*l):(t.y0=T-t.value*l-n,t.y1=t.y0+t.value*l):0==u.top||0==u.bottom?(t.y0=(T-a)/e*n,t.y1=t.y0+t.value*l):(t.y0=(T-a)/2-e/2+n,t.y1=t.y0+t.value*l)}))}))}(l),y();for(var u=1,g=s;g>0;--g)v(u*=.99,l),y();function v(t,r){var n=c.length;c.forEach((function(i){var a=i.length,o=i[0].depth;i.forEach((function(i){var s;if(i.sourceLinks.length||i.targetLinks.length)if(i.partOfCycle&&k(i,r)>0);else if(0==o&&1==a)s=i.y1-i.y0,i.y0=T/2-s/2,i.y1=T/2+s/2;else if(o==n-1&&1==a)s=i.y1-i.y0,i.y0=T/2-s/2,i.y1=T/2+s/2;else{var l=e.mean(i.sourceLinks,m),c=e.mean(i.targetLinks,d),u=((l&&c?(l+c)/2:l||c)-p(i))*t;i.y0+=u,i.y1+=u}}))}))}function y(){c.forEach((function(e){var r,n,i,o=a,s=e.length;for(e.sort(f),i=0;i<s;++i)(n=o-(r=e[i]).y0)>0&&(r.y0+=n,r.y1+=n),o=r.y1+t;if((n=o-t-T)>0)for(o=r.y0-=n,r.y1-=n,i=s-2;i>=0;--i)(n=(r=e[i]).y1+t-o)>0&&(r.y0-=n,r.y1-=n),o=r.y0}))}}function V(t){t.nodes.forEach((function(t){t.sourceLinks.sort(u),t.targetLinks.sort(c)})),t.nodes.forEach((function(t){var e=t.y0,r=e,n=t.y1,i=n;t.sourceLinks.forEach((function(t){t.circular?(t.y0=n-t.width/2,n-=t.width):(t.y0=e+t.width/2,e+=t.width)})),t.targetLinks.forEach((function(t){t.circular?(t.y1=i-t.width/2,i-=t.width):(t.y1=r+t.width/2,r+=t.width)}))}))}return z.nodeId=function(t){return arguments.length?(M="function"==typeof t?t:s(t),z):M},z.nodeAlign=function(t){return arguments.length?(E="function"==typeof t?t:s(t),z):E},z.nodeWidth=function(t){return arguments.length?(A=+t,z):A},z.nodePadding=function(e){return arguments.length?(t=+e,z):t},z.nodes=function(t){return arguments.length?(L="function"==typeof t?t:s(t),z):L},z.links=function(t){return arguments.length?(C="function"==typeof t?t:s(t),z):C},z.size=function(t){return arguments.length?(i=a=0,b=+t[0],T=+t[1],z):[b-i,T-a]},z.extent=function(t){return arguments.length?(i=+t[0][0],b=+t[1][0],a=+t[0][1],T=+t[1][1],z):[[i,a],[b,T]]},z.iterations=function(t){return arguments.length?(P=+t,z):P},z.circularLinkGap=function(t){return arguments.length?(I=+t,z):I},z.nodePaddingRatio=function(t){return arguments.length?(n=+t,z):n},z.sortNodes=function(t){return arguments.length?(O=t,z):O},z.update=function(t){return w(t,M),V(t),t.links.forEach((function(t){t.circular&&(t.circularLinkType=t.y0+t.y1<T?"top":"bottom",t.source.circularLinkType=t.circularLinkType,t.target.circularLinkType=t.circularLinkType)})),j(t,T,M,!1),U(t,T,M),S(t,I,T,M),t},z},t.sankeyCenter=function(t){return t.targetLinks.length?t.depth:t.sourceLinks.length?e.min(t.sourceLinks,a)-1:0},t.sankeyLeft=function(t){return t.depth},t.sankeyRight=function(t,e){return e-1-t.height},t.sankeyJustify=o,Object.defineProperty(t,"__esModule",{value:!0})}))},{"d3-array":107,"d3-collection":108,"d3-shape":119,"elementary-circuits-directed-graph":130}],57:[function(t,e,r){!function(n,i){"object"==typeof r&&void 0!==e?i(r,t("d3-array"),t("d3-collection"),t("d3-shape")):i(n.d3=n.d3||{},n.d3,n.d3,n.d3)}(this,(function(t,e,r,n){"use strict";function i(t){return t.target.depth}function a(t,e){return t.sourceLinks.length?t.depth:e-1}function o(t){return function(){return t}}function s(t,e){return c(t.source,e.source)||t.index-e.index}function l(t,e){return c(t.target,e.target)||t.index-e.index}function c(t,e){return t.y0-e.y0}function u(t){return t.value}function f(t){return(t.y0+t.y1)/2}function h(t){return f(t.source)*t.value}function p(t){return f(t.target)*t.value}function d(t){return t.index}function m(t){return t.nodes}function g(t){return t.links}function v(t,e){var r=t.get(e);if(!r)throw new Error("missing: "+e);return r}function y(t){return[t.source.x1,t.y0]}function x(t){return[t.target.x0,t.y1]}t.sankey=function(){var t=0,n=0,i=1,y=1,x=24,b=8,_=d,w=a,T=m,k=g,A=32;function M(){var t={nodes:T.apply(null,arguments),links:k.apply(null,arguments)};return S(t),E(t),L(t),C(t),P(t),t}function S(t){t.nodes.forEach((function(t,e){t.index=e,t.sourceLinks=[],t.targetLinks=[]}));var e=r.map(t.nodes,_);t.links.forEach((function(t,r){t.index=r;var n=t.source,i=t.target;"object"!=typeof n&&(n=t.source=v(e,n)),"object"!=typeof i&&(i=t.target=v(e,i)),n.sourceLinks.push(t),i.targetLinks.push(t)}))}function E(t){t.nodes.forEach((function(t){t.value=Math.max(e.sum(t.sourceLinks,u),e.sum(t.targetLinks,u))}))}function L(e){var r,n,a;for(r=e.nodes,n=[],a=0;r.length;++a,r=n,n=[])r.forEach((function(t){t.depth=a,t.sourceLinks.forEach((function(t){n.indexOf(t.target)<0&&n.push(t.target)}))}));for(r=e.nodes,n=[],a=0;r.length;++a,r=n,n=[])r.forEach((function(t){t.height=a,t.targetLinks.forEach((function(t){n.indexOf(t.source)<0&&n.push(t.source)}))}));var o=(i-t-x)/(a-1);e.nodes.forEach((function(e){e.x1=(e.x0=t+Math.max(0,Math.min(a-1,Math.floor(w.call(null,e,a))))*o)+x}))}function C(t){var i=r.nest().key((function(t){return t.x0})).sortKeys(e.ascending).entries(t.nodes).map((function(t){return t.values}));!function(){var r=e.max(i,(function(t){return t.length})),a=2/3*(y-n)/(r-1);b>a&&(b=a);var o=e.min(i,(function(t){return(y-n-(t.length-1)*b)/e.sum(t,u)}));i.forEach((function(t){t.forEach((function(t,e){t.y1=(t.y0=e)+t.value*o}))})),t.links.forEach((function(t){t.width=t.value*o}))}(),d();for(var a=1,o=A;o>0;--o)l(a*=.99),d(),s(a),d();function s(t){i.forEach((function(r){r.forEach((function(r){if(r.targetLinks.length){var n=(e.sum(r.targetLinks,h)/e.sum(r.targetLinks,u)-f(r))*t;r.y0+=n,r.y1+=n}}))}))}function l(t){i.slice().reverse().forEach((function(r){r.forEach((function(r){if(r.sourceLinks.length){var n=(e.sum(r.sourceLinks,p)/e.sum(r.sourceLinks,u)-f(r))*t;r.y0+=n,r.y1+=n}}))}))}function d(){i.forEach((function(t){var e,r,i,a=n,o=t.length;for(t.sort(c),i=0;i<o;++i)(r=a-(e=t[i]).y0)>0&&(e.y0+=r,e.y1+=r),a=e.y1+b;if((r=a-b-y)>0)for(a=e.y0-=r,e.y1-=r,i=o-2;i>=0;--i)(r=(e=t[i]).y1+b-a)>0&&(e.y0-=r,e.y1-=r),a=e.y0}))}}function P(t){t.nodes.forEach((function(t){t.sourceLinks.sort(l),t.targetLinks.sort(s)})),t.nodes.forEach((function(t){var e=t.y0,r=e;t.sourceLinks.forEach((function(t){t.y0=e+t.width/2,e+=t.width})),t.targetLinks.forEach((function(t){t.y1=r+t.width/2,r+=t.width}))}))}return M.update=function(t){return P(t),t},M.nodeId=function(t){return arguments.length?(_="function"==typeof t?t:o(t),M):_},M.nodeAlign=function(t){return arguments.length?(w="function"==typeof t?t:o(t),M):w},M.nodeWidth=function(t){return arguments.length?(x=+t,M):x},M.nodePadding=function(t){return arguments.length?(b=+t,M):b},M.nodes=function(t){return arguments.length?(T="function"==typeof t?t:o(t),M):T},M.links=function(t){return arguments.length?(k="function"==typeof t?t:o(t),M):k},M.size=function(e){return arguments.length?(t=n=0,i=+e[0],y=+e[1],M):[i-t,y-n]},M.extent=function(e){return arguments.length?(t=+e[0][0],i=+e[1][0],n=+e[0][1],y=+e[1][1],M):[[t,n],[i,y]]},M.iterations=function(t){return arguments.length?(A=+t,M):A},M},t.sankeyCenter=function(t){return t.targetLinks.length?t.depth:t.sourceLinks.length?e.min(t.sourceLinks,i)-1:0},t.sankeyLeft=function(t){return t.depth},t.sankeyRight=function(t,e){return e-1-t.height},t.sankeyJustify=a,t.sankeyLinkHorizontal=function(){return n.linkHorizontal().source(y).target(x)},Object.defineProperty(t,"__esModule",{value:!0})}))},{"d3-array":107,"d3-collection":108,"d3-shape":119}],58:[function(t,e,r){(function(){var t={version:"3.8.0"},r=[].slice,n=function(t){return r.call(t)},i=self.document;function a(t){return t&&(t.ownerDocument||t.document||t).documentElement}function o(t){return t&&(t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView)}if(i)try{n(i.documentElement.childNodes)[0].nodeType}catch(t){n=function(t){for(var e=t.length,r=new Array(e);e--;)r[e]=t[e];return r}}if(Date.now||(Date.now=function(){return+new Date}),i)try{i.createElement("DIV").style.setProperty("opacity",0,"")}catch(t){var s=this.Element.prototype,l=s.setAttribute,c=s.setAttributeNS,u=this.CSSStyleDeclaration.prototype,f=u.setProperty;s.setAttribute=function(t,e){l.call(this,t,e+"")},s.setAttributeNS=function(t,e,r){c.call(this,t,e,r+"")},u.setProperty=function(t,e,r){f.call(this,t,e+"",r)}}function h(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function p(t){return null===t?NaN:+t}function d(t){return!isNaN(t)}function m(t){return{left:function(e,r,n,i){for(arguments.length<3&&(n=0),arguments.length<4&&(i=e.length);n<i;){var a=n+i>>>1;t(e[a],r)<0?n=a+1:i=a}return n},right:function(e,r,n,i){for(arguments.length<3&&(n=0),arguments.length<4&&(i=e.length);n<i;){var a=n+i>>>1;t(e[a],r)>0?i=a:n=a+1}return n}}}t.ascending=h,t.descending=function(t,e){return e<t?-1:e>t?1:e>=t?0:NaN},t.min=function(t,e){var r,n,i=-1,a=t.length;if(1===arguments.length){for(;++i<a;)if(null!=(n=t[i])&&n>=n){r=n;break}for(;++i<a;)null!=(n=t[i])&&r>n&&(r=n)}else{for(;++i<a;)if(null!=(n=e.call(t,t[i],i))&&n>=n){r=n;break}for(;++i<a;)null!=(n=e.call(t,t[i],i))&&r>n&&(r=n)}return r},t.max=function(t,e){var r,n,i=-1,a=t.length;if(1===arguments.length){for(;++i<a;)if(null!=(n=t[i])&&n>=n){r=n;break}for(;++i<a;)null!=(n=t[i])&&n>r&&(r=n)}else{for(;++i<a;)if(null!=(n=e.call(t,t[i],i))&&n>=n){r=n;break}for(;++i<a;)null!=(n=e.call(t,t[i],i))&&n>r&&(r=n)}return r},t.extent=function(t,e){var r,n,i,a=-1,o=t.length;if(1===arguments.length){for(;++a<o;)if(null!=(n=t[a])&&n>=n){r=i=n;break}for(;++a<o;)null!=(n=t[a])&&(r>n&&(r=n),i<n&&(i=n))}else{for(;++a<o;)if(null!=(n=e.call(t,t[a],a))&&n>=n){r=i=n;break}for(;++a<o;)null!=(n=e.call(t,t[a],a))&&(r>n&&(r=n),i<n&&(i=n))}return[r,i]},t.sum=function(t,e){var r,n=0,i=t.length,a=-1;if(1===arguments.length)for(;++a<i;)d(r=+t[a])&&(n+=r);else for(;++a<i;)d(r=+e.call(t,t[a],a))&&(n+=r);return n},t.mean=function(t,e){var r,n=0,i=t.length,a=-1,o=i;if(1===arguments.length)for(;++a<i;)d(r=p(t[a]))?n+=r:--o;else for(;++a<i;)d(r=p(e.call(t,t[a],a)))?n+=r:--o;if(o)return n/o},t.quantile=function(t,e){var r=(t.length-1)*e+1,n=Math.floor(r),i=+t[n-1],a=r-n;return a?i+a*(t[n]-i):i},t.median=function(e,r){var n,i=[],a=e.length,o=-1;if(1===arguments.length)for(;++o<a;)d(n=p(e[o]))&&i.push(n);else for(;++o<a;)d(n=p(r.call(e,e[o],o)))&&i.push(n);if(i.length)return t.quantile(i.sort(h),.5)},t.variance=function(t,e){var r,n,i=t.length,a=0,o=0,s=-1,l=0;if(1===arguments.length)for(;++s<i;)d(r=p(t[s]))&&(o+=(n=r-a)*(r-(a+=n/++l)));else for(;++s<i;)d(r=p(e.call(t,t[s],s)))&&(o+=(n=r-a)*(r-(a+=n/++l)));if(l>1)return o/(l-1)},t.deviation=function(){var e=t.variance.apply(this,arguments);return e?Math.sqrt(e):e};var g=m(h);function v(t){return t.length}t.bisectLeft=g.left,t.bisect=t.bisectRight=g.right,t.bisector=function(t){return m(1===t.length?function(e,r){return h(t(e),r)}:t)},t.shuffle=function(t,e,r){(a=arguments.length)<3&&(r=t.length,a<2&&(e=0));for(var n,i,a=r-e;a;)i=Math.random()*a--|0,n=t[a+e],t[a+e]=t[i+e],t[i+e]=n;return t},t.permute=function(t,e){for(var r=e.length,n=new Array(r);r--;)n[r]=t[e[r]];return n},t.pairs=function(t){for(var e=0,r=t.length-1,n=t[0],i=new Array(r<0?0:r);e<r;)i[e]=[n,n=t[++e]];return i},t.transpose=function(e){if(!(a=e.length))return[];for(var r=-1,n=t.min(e,v),i=new Array(n);++r<n;)for(var a,o=-1,s=i[r]=new Array(a);++o<a;)s[o]=e[o][r];return i},t.zip=function(){return t.transpose(arguments)},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e},t.values=function(t){var e=[];for(var r in t)e.push(t[r]);return e},t.entries=function(t){var e=[];for(var r in t)e.push({key:r,value:t[r]});return e},t.merge=function(t){for(var e,r,n,i=t.length,a=-1,o=0;++a<i;)o+=t[a].length;for(r=new Array(o);--i>=0;)for(e=(n=t[i]).length;--e>=0;)r[--o]=n[e];return r};var y=Math.abs;function x(t){for(var e=1;t*e%1;)e*=10;return e}function b(t,e){for(var r in e)Object.defineProperty(t.prototype,r,{value:e[r],enumerable:!1})}function _(){this._=Object.create(null)}t.range=function(t,e,r){if(arguments.length<3&&(r=1,arguments.length<2&&(e=t,t=0)),(e-t)/r==1/0)throw new Error("infinite range");var n,i=[],a=x(y(r)),o=-1;if(t*=a,e*=a,(r*=a)<0)for(;(n=t+r*++o)>e;)i.push(n/a);else for(;(n=t+r*++o)<e;)i.push(n/a);return i},t.map=function(t,e){var r=new _;if(t instanceof _)t.forEach((function(t,e){r.set(t,e)}));else if(Array.isArray(t)){var n,i=-1,a=t.length;if(1===arguments.length)for(;++i<a;)r.set(i,t[i]);else for(;++i<a;)r.set(e.call(t,n=t[i],i),n)}else for(var o in t)r.set(o,t[o]);return r};function w(t){return"__proto__"==(t+="")||"\0"===t[0]?"\0"+t:t}function T(t){return"\0"===(t+="")[0]?t.slice(1):t}function k(t){return w(t)in this._}function A(t){return(t=w(t))in this._&&delete this._[t]}function M(){var t=[];for(var e in this._)t.push(T(e));return t}function S(){var t=0;for(var e in this._)++t;return t}function E(){for(var t in this._)return!1;return!0}function L(){this._=Object.create(null)}function C(t){return t}function P(t,e,r){return function(){var n=r.apply(e,arguments);return n===e?t:n}}function I(t,e){if(e in t)return e;e=e.charAt(0).toUpperCase()+e.slice(1);for(var r=0,n=O.length;r<n;++r){var i=O[r]+e;if(i in t)return i}}b(_,{has:k,get:function(t){return this._[w(t)]},set:function(t,e){return this._[w(t)]=e},remove:A,keys:M,values:function(){var t=[];for(var e in this._)t.push(this._[e]);return t},entries:function(){var t=[];for(var e in this._)t.push({key:T(e),value:this._[e]});return t},size:S,empty:E,forEach:function(t){for(var e in this._)t.call(this,T(e),this._[e])}}),t.nest=function(){var e,r,n={},i=[],a=[];function o(t,a,s){if(s>=i.length)return r?r.call(n,a):e?a.sort(e):a;for(var l,c,u,f,h=-1,p=a.length,d=i[s++],m=new _;++h<p;)(f=m.get(l=d(c=a[h])))?f.push(c):m.set(l,[c]);return t?(c=t(),u=function(e,r){c.set(e,o(t,r,s))}):(c={},u=function(e,r){c[e]=o(t,r,s)}),m.forEach(u),c}return n.map=function(t,e){return o(e,t,0)},n.entries=function(e){return function t(e,r){if(r>=i.length)return e;var n=[],o=a[r++];return e.forEach((function(e,i){n.push({key:e,values:t(i,r)})})),o?n.sort((function(t,e){return o(t.key,e.key)})):n}(o(t.map,e,0),0)},n.key=function(t){return i.push(t),n},n.sortKeys=function(t){return a[i.length-1]=t,n},n.sortValues=function(t){return e=t,n},n.rollup=function(t){return r=t,n},n},t.set=function(t){var e=new L;if(t)for(var r=0,n=t.length;r<n;++r)e.add(t[r]);return e},b(L,{has:k,add:function(t){return this._[w(t+="")]=!0,t},remove:A,values:M,size:S,empty:E,forEach:function(t){for(var e in this._)t.call(this,T(e))}}),t.behavior={},t.rebind=function(t,e){for(var r,n=1,i=arguments.length;++n<i;)t[r=arguments[n]]=P(t,e,e[r]);return t};var O=["webkit","ms","moz","Moz","o","O"];function z(){}function D(){}function R(t){var e=[],r=new _;function n(){for(var r,n=e,i=-1,a=n.length;++i<a;)(r=n[i].on)&&r.apply(this,arguments);return t}return n.on=function(n,i){var a,o=r.get(n);return arguments.length<2?o&&o.on:(o&&(o.on=null,e=e.slice(0,a=e.indexOf(o)).concat(e.slice(a+1)),r.remove(n)),i&&e.push(r.set(n,{on:i})),t)},n}function F(){t.event.preventDefault()}function B(){for(var e,r=t.event;e=r.sourceEvent;)r=e;return r}function N(e){for(var r=new D,n=0,i=arguments.length;++n<i;)r[arguments[n]]=R(r);return r.of=function(n,i){return function(a){try{var o=a.sourceEvent=t.event;a.target=e,t.event=a,r[a.type].apply(n,i)}finally{t.event=o}}},r}t.dispatch=function(){for(var t=new D,e=-1,r=arguments.length;++e<r;)t[arguments[e]]=R(t);return t},D.prototype.on=function(t,e){var r=t.indexOf("."),n="";if(r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),t)return arguments.length<2?this[t].on(n):this[t].on(n,e);if(2===arguments.length){if(null==e)for(t in this)this.hasOwnProperty(t)&&this[t].on(n,null);return this}},t.event=null,t.requote=function(t){return t.replace(j,"\\$&")};var j=/[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g,U={}.__proto__?function(t,e){t.__proto__=e}:function(t,e){for(var r in e)t[r]=e[r]};function V(t){return U(t,Y),t}var H=function(t,e){return e.querySelector(t)},q=function(t,e){return e.querySelectorAll(t)},G=function(t,e){var r=t.matches||t[I(t,"matchesSelector")];return(G=function(t,e){return r.call(t,e)})(t,e)};"function"==typeof Sizzle&&(H=function(t,e){return Sizzle(t,e)[0]||null},q=Sizzle,G=Sizzle.matchesSelector),t.selection=function(){return t.select(i.documentElement)};var Y=t.selection.prototype=[];function W(t){return"function"==typeof t?t:function(){return H(t,this)}}function X(t){return"function"==typeof t?t:function(){return q(t,this)}}Y.select=function(t){var e,r,n,i,a=[];t=W(t);for(var o=-1,s=this.length;++o<s;){a.push(e=[]),e.parentNode=(n=this[o]).parentNode;for(var l=-1,c=n.length;++l<c;)(i=n[l])?(e.push(r=t.call(i,i.__data__,l,o)),r&&"__data__"in i&&(r.__data__=i.__data__)):e.push(null)}return V(a)},Y.selectAll=function(t){var e,r,i=[];t=X(t);for(var a=-1,o=this.length;++a<o;)for(var s=this[a],l=-1,c=s.length;++l<c;)(r=s[l])&&(i.push(e=n(t.call(r,r.__data__,l,a))),e.parentNode=r);return V(i)};var Z="http://www.w3.org/1999/xhtml",J={svg:"http://www.w3.org/2000/svg",xhtml:Z,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function K(e,r){return e=t.ns.qualify(e),null==r?e.local?function(){this.removeAttributeNS(e.space,e.local)}:function(){this.removeAttribute(e)}:"function"==typeof r?e.local?function(){var t=r.apply(this,arguments);null==t?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,t)}:function(){var t=r.apply(this,arguments);null==t?this.removeAttribute(e):this.setAttribute(e,t)}:e.local?function(){this.setAttributeNS(e.space,e.local,r)}:function(){this.setAttribute(e,r)}}function Q(t){return t.trim().replace(/\s+/g," ")}function $(e){return new RegExp("(?:^|\\s+)"+t.requote(e)+"(?:\\s+|$)","g")}function tt(t){return(t+"").trim().split(/^|\s+/)}function et(t,e){var r=(t=tt(t).map(rt)).length;return"function"==typeof e?function(){for(var n=-1,i=e.apply(this,arguments);++n<r;)t[n](this,i)}:function(){for(var n=-1;++n<r;)t[n](this,e)}}function rt(t){var e=$(t);return function(r,n){if(i=r.classList)return n?i.add(t):i.remove(t);var i=r.getAttribute("class")||"";n?(e.lastIndex=0,e.test(i)||r.setAttribute("class",Q(i+" "+t))):r.setAttribute("class",Q(i.replace(e," ")))}}function nt(t,e,r){return null==e?function(){this.style.removeProperty(t)}:"function"==typeof e?function(){var n=e.apply(this,arguments);null==n?this.style.removeProperty(t):this.style.setProperty(t,n,r)}:function(){this.style.setProperty(t,e,r)}}function it(t,e){return null==e?function(){delete this[t]}:"function"==typeof e?function(){var r=e.apply(this,arguments);null==r?delete this[t]:this[t]=r}:function(){this[t]=e}}function at(e){return"function"==typeof e?e:(e=t.ns.qualify(e)).local?function(){return this.ownerDocument.createElementNS(e.space,e.local)}:function(){var t=this.ownerDocument,r=this.namespaceURI;return r===Z&&t.documentElement.namespaceURI===Z?t.createElement(e):t.createElementNS(r,e)}}function ot(){var t=this.parentNode;t&&t.removeChild(this)}function st(t){return{__data__:t}}function lt(t){return function(){return G(this,t)}}function ct(t){return arguments.length||(t=h),function(e,r){return e&&r?t(e.__data__,r.__data__):!e-!r}}function ut(t,e){for(var r=0,n=t.length;r<n;r++)for(var i,a=t[r],o=0,s=a.length;o<s;o++)(i=a[o])&&e(i,o,r);return t}function ft(t){return U(t,ht),t}t.ns={prefix:J,qualify:function(t){var e=t.indexOf(":"),r=t;return e>=0&&"xmlns"!==(r=t.slice(0,e))&&(t=t.slice(e+1)),J.hasOwnProperty(r)?{space:J[r],local:t}:t}},Y.attr=function(e,r){if(arguments.length<2){if("string"==typeof e){var n=this.node();return(e=t.ns.qualify(e)).local?n.getAttributeNS(e.space,e.local):n.getAttribute(e)}for(r in e)this.each(K(r,e[r]));return this}return this.each(K(e,r))},Y.classed=function(t,e){if(arguments.length<2){if("string"==typeof t){var r=this.node(),n=(t=tt(t)).length,i=-1;if(e=r.classList){for(;++i<n;)if(!e.contains(t[i]))return!1}else for(e=r.getAttribute("class");++i<n;)if(!$(t[i]).test(e))return!1;return!0}for(e in t)this.each(et(e,t[e]));return this}return this.each(et(t,e))},Y.style=function(t,e,r){var n=arguments.length;if(n<3){if("string"!=typeof t){for(r in n<2&&(e=""),t)this.each(nt(r,t[r],e));return this}if(n<2){var i=this.node();return o(i).getComputedStyle(i,null).getPropertyValue(t)}r=""}return this.each(nt(t,e,r))},Y.property=function(t,e){if(arguments.length<2){if("string"==typeof t)return this.node()[t];for(e in t)this.each(it(e,t[e]));return this}return this.each(it(t,e))},Y.text=function(t){return arguments.length?this.each("function"==typeof t?function(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}:null==t?function(){this.textContent=""}:function(){this.textContent=t}):this.node().textContent},Y.html=function(t){return arguments.length?this.each("function"==typeof t?function(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}:null==t?function(){this.innerHTML=""}:function(){this.innerHTML=t}):this.node().innerHTML},Y.append=function(t){return t=at(t),this.select((function(){return this.appendChild(t.apply(this,arguments))}))},Y.insert=function(t,e){return t=at(t),e=W(e),this.select((function(){return this.insertBefore(t.apply(this,arguments),e.apply(this,arguments)||null)}))},Y.remove=function(){return this.each(ot)},Y.data=function(t,e){var r,n,i=-1,a=this.length;if(!arguments.length){for(t=new Array(a=(r=this[0]).length);++i<a;)(n=r[i])&&(t[i]=n.__data__);return t}function o(t,r){var n,i,a,o=t.length,u=r.length,f=Math.min(o,u),h=new Array(u),p=new Array(u),d=new Array(o);if(e){var m,g=new _,v=new Array(o);for(n=-1;++n<o;)(i=t[n])&&(g.has(m=e.call(i,i.__data__,n))?d[n]=i:g.set(m,i),v[n]=m);for(n=-1;++n<u;)(i=g.get(m=e.call(r,a=r[n],n)))?!0!==i&&(h[n]=i,i.__data__=a):p[n]=st(a),g.set(m,!0);for(n=-1;++n<o;)n in v&&!0!==g.get(v[n])&&(d[n]=t[n])}else{for(n=-1;++n<f;)i=t[n],a=r[n],i?(i.__data__=a,h[n]=i):p[n]=st(a);for(;n<u;++n)p[n]=st(r[n]);for(;n<o;++n)d[n]=t[n]}p.update=h,p.parentNode=h.parentNode=d.parentNode=t.parentNode,s.push(p),l.push(h),c.push(d)}var s=ft([]),l=V([]),c=V([]);if("function"==typeof t)for(;++i<a;)o(r=this[i],t.call(r,r.parentNode.__data__,i));else for(;++i<a;)o(r=this[i],t);return l.enter=function(){return s},l.exit=function(){return c},l},Y.datum=function(t){return arguments.length?this.property("__data__",t):this.property("__data__")},Y.filter=function(t){var e,r,n,i=[];"function"!=typeof t&&(t=lt(t));for(var a=0,o=this.length;a<o;a++){i.push(e=[]),e.parentNode=(r=this[a]).parentNode;for(var s=0,l=r.length;s<l;s++)(n=r[s])&&t.call(n,n.__data__,s,a)&&e.push(n)}return V(i)},Y.order=function(){for(var t=-1,e=this.length;++t<e;)for(var r,n=this[t],i=n.length-1,a=n[i];--i>=0;)(r=n[i])&&(a&&a!==r.nextSibling&&a.parentNode.insertBefore(r,a),a=r);return this},Y.sort=function(t){t=ct.apply(this,arguments);for(var e=-1,r=this.length;++e<r;)this[e].sort(t);return this.order()},Y.each=function(t){return ut(this,(function(e,r,n){t.call(e,e.__data__,r,n)}))},Y.call=function(t){var e=n(arguments);return t.apply(e[0]=this,e),this},Y.empty=function(){return!this.node()},Y.node=function(){for(var t=0,e=this.length;t<e;t++)for(var r=this[t],n=0,i=r.length;n<i;n++){var a=r[n];if(a)return a}return null},Y.size=function(){var t=0;return ut(this,(function(){++t})),t};var ht=[];function pt(t){var e,r;return function(n,i,a){var o,s=t[a].update,l=s.length;for(a!=r&&(r=a,e=0),i>=e&&(e=i+1);!(o=s[e])&&++e<l;);return o}}function dt(e,r,i){var a="__on"+e,o=e.indexOf("."),s=gt;o>0&&(e=e.slice(0,o));var l=mt.get(e);function c(){var t=this[a];t&&(this.removeEventListener(e,t,t.$),delete this[a])}return l&&(e=l,s=vt),o?r?function(){var t=s(r,n(arguments));c.call(this),this.addEventListener(e,this[a]=t,t.$=i),t._=r}:c:r?z:function(){var r,n=new RegExp("^__on([^.]+)"+t.requote(e)+"$");for(var i in this)if(r=i.match(n)){var a=this[i];this.removeEventListener(r[1],a,a.$),delete this[i]}}}t.selection.enter=ft,t.selection.enter.prototype=ht,ht.append=Y.append,ht.empty=Y.empty,ht.node=Y.node,ht.call=Y.call,ht.size=Y.size,ht.select=function(t){for(var e,r,n,i,a,o=[],s=-1,l=this.length;++s<l;){n=(i=this[s]).update,o.push(e=[]),e.parentNode=i.parentNode;for(var c=-1,u=i.length;++c<u;)(a=i[c])?(e.push(n[c]=r=t.call(i.parentNode,a.__data__,c,s)),r.__data__=a.__data__):e.push(null)}return V(o)},ht.insert=function(t,e){return arguments.length<2&&(e=pt(this)),Y.insert.call(this,t,e)},t.select=function(t){var e;return"string"==typeof t?(e=[H(t,i)]).parentNode=i.documentElement:(e=[t]).parentNode=a(t),V([e])},t.selectAll=function(t){var e;return"string"==typeof t?(e=n(q(t,i))).parentNode=i.documentElement:(e=n(t)).parentNode=null,V([e])},Y.on=function(t,e,r){var n=arguments.length;if(n<3){if("string"!=typeof t){for(r in n<2&&(e=!1),t)this.each(dt(r,t[r],e));return this}if(n<2)return(n=this.node()["__on"+t])&&n._;r=!1}return this.each(dt(t,e,r))};var mt=t.map({mouseenter:"mouseover",mouseleave:"mouseout"});function gt(e,r){return function(n){var i=t.event;t.event=n,r[0]=this.__data__;try{e.apply(this,r)}finally{t.event=i}}}function vt(t,e){var r=gt(t,e);return function(t){var e=t.relatedTarget;e&&(e===this||8&e.compareDocumentPosition(this))||r.call(this,t)}}i&&mt.forEach((function(t){"on"+t in i&&mt.remove(t)}));var yt,xt=0;function bt(e){var r=".dragsuppress-"+ ++xt,n="click"+r,i=t.select(o(e)).on("touchmove"+r,F).on("dragstart"+r,F).on("selectstart"+r,F);if(null==yt&&(yt=!("onselectstart"in e)&&I(e.style,"userSelect")),yt){var s=a(e).style,l=s[yt];s[yt]="none"}return function(t){if(i.on(r,null),yt&&(s[yt]=l),t){var e=function(){i.on(n,null)};i.on(n,(function(){F(),e()}),!0),setTimeout(e,0)}}}t.mouse=function(t){return wt(t,B())};var _t=this.navigator&&/WebKit/.test(this.navigator.userAgent)?-1:0;function wt(e,r){r.changedTouches&&(r=r.changedTouches[0]);var n=e.ownerSVGElement||e;if(n.createSVGPoint){var i=n.createSVGPoint();if(_t<0){var a=o(e);if(a.scrollX||a.scrollY){var s=(n=t.select("body").append("svg").style({position:"absolute",top:0,left:0,margin:0,padding:0,border:"none"},"important"))[0][0].getScreenCTM();_t=!(s.f||s.e),n.remove()}}return _t?(i.x=r.pageX,i.y=r.pageY):(i.x=r.clientX,i.y=r.clientY),[(i=i.matrixTransform(e.getScreenCTM().inverse())).x,i.y]}var l=e.getBoundingClientRect();return[r.clientX-l.left-e.clientLeft,r.clientY-l.top-e.clientTop]}function Tt(){return t.event.changedTouches[0].identifier}t.touch=function(t,e,r){if(arguments.length<3&&(r=e,e=B().changedTouches),e)for(var n,i=0,a=e.length;i<a;++i)if((n=e[i]).identifier===r)return wt(t,n)},t.behavior.drag=function(){var e=N(a,"drag","dragstart","dragend"),r=null,n=s(z,t.mouse,o,"mousemove","mouseup"),i=s(Tt,t.touch,C,"touchmove","touchend");function a(){this.on("mousedown.drag",n).on("touchstart.drag",i)}function s(n,i,a,o,s){return function(){var l,c=this,u=t.event.target.correspondingElement||t.event.target,f=c.parentNode,h=e.of(c,arguments),p=0,d=n(),m=".drag"+(null==d?"":"-"+d),g=t.select(a(u)).on(o+m,x).on(s+m,b),v=bt(u),y=i(f,d);function x(){var t,e,r=i(f,d);r&&(t=r[0]-y[0],e=r[1]-y[1],p|=t|e,y=r,h({type:"drag",x:r[0]+l[0],y:r[1]+l[1],dx:t,dy:e}))}function b(){i(f,d)&&(g.on(o+m,null).on(s+m,null),v(p),h({type:"dragend"}))}l=r?[(l=r.apply(c,arguments)).x-y[0],l.y-y[1]]:[0,0],h({type:"dragstart"})}}return a.origin=function(t){return arguments.length?(r=t,a):r},t.rebind(a,e,"on")},t.touches=function(t,e){return arguments.length<2&&(e=B().touches),e?n(e).map((function(e){var r=wt(t,e);return r.identifier=e.identifier,r})):[]};var kt=1e-6,At=Math.PI,Mt=2*At,St=Mt-kt,Et=At/2,Lt=At/180,Ct=180/At;function Pt(t){return t>1?Et:t<-1?-Et:Math.asin(t)}function It(t){return((t=Math.exp(t))+1/t)/2}var Ot=Math.SQRT2;t.interpolateZoom=function(t,e){var r,n,i=t[0],a=t[1],o=t[2],s=e[0],l=e[1],c=e[2],u=s-i,f=l-a,h=u*u+f*f;if(h<1e-12)n=Math.log(c/o)/Ot,r=function(t){return[i+t*u,a+t*f,o*Math.exp(Ot*t*n)]};else{var p=Math.sqrt(h),d=(c*c-o*o+4*h)/(2*o*2*p),m=(c*c-o*o-4*h)/(2*c*2*p),g=Math.log(Math.sqrt(d*d+1)-d),v=Math.log(Math.sqrt(m*m+1)-m);n=(v-g)/Ot,r=function(t){var e,r=t*n,s=It(g),l=o/(2*p)*(s*(e=Ot*r+g,((e=Math.exp(2*e))-1)/(e+1))-function(t){return((t=Math.exp(t))-1/t)/2}(g));return[i+l*u,a+l*f,o*s/It(Ot*r+g)]}}return r.duration=1e3*n,r},t.behavior.zoom=function(){var e,r,n,a,s,l,c,u,f,h={x:0,y:0,k:1},p=[960,500],d=Rt,m=250,g=0,v="mousedown.zoom",y="mousemove.zoom",x="mouseup.zoom",b="touchstart.zoom",_=N(w,"zoomstart","zoom","zoomend");function w(t){t.on(v,P).on(Dt+".zoom",O).on("dblclick.zoom",z).on(b,I)}function T(t){return[(t[0]-h.x)/h.k,(t[1]-h.y)/h.k]}function k(t){h.k=Math.max(d[0],Math.min(d[1],t))}function A(t,e){e=function(t){return[t[0]*h.k+h.x,t[1]*h.k+h.y]}(e),h.x+=t[0]-e[0],h.y+=t[1]-e[1]}function M(e,n,i,a){e.__chart__={x:h.x,y:h.y,k:h.k},k(Math.pow(2,a)),A(r=n,i),e=t.select(e),m>0&&(e=e.transition().duration(m)),e.call(w.event)}function S(){c&&c.domain(l.range().map((function(t){return(t-h.x)/h.k})).map(l.invert)),f&&f.domain(u.range().map((function(t){return(t-h.y)/h.k})).map(u.invert))}function E(t){g++||t({type:"zoomstart"})}function L(t){S(),t({type:"zoom",scale:h.k,translate:[h.x,h.y]})}function C(t){--g||(t({type:"zoomend"}),r=null)}function P(){var e=this,r=_.of(e,arguments),n=0,i=t.select(o(e)).on(y,l).on(x,c),a=T(t.mouse(e)),s=bt(e);function l(){n=1,A(t.mouse(e),a),L(r)}function c(){i.on(y,null).on(x,null),s(n),C(r)}Di.call(e),E(r)}function I(){var e,r=this,n=_.of(r,arguments),i={},a=0,o=".zoom-"+t.event.changedTouches[0].identifier,l="touchmove"+o,c="touchend"+o,u=[],f=t.select(r),p=bt(r);function d(){var n=t.touches(r);return e=h.k,n.forEach((function(t){t.identifier in i&&(i[t.identifier]=T(t))})),n}function m(){var e=t.event.target;t.select(e).on(l,g).on(c,y),u.push(e);for(var n=t.event.changedTouches,o=0,f=n.length;o<f;++o)i[n[o].identifier]=null;var p=d(),m=Date.now();if(1===p.length){if(m-s<500){var v=p[0];M(r,v,i[v.identifier],Math.floor(Math.log(h.k)/Math.LN2)+1),F()}s=m}else if(p.length>1){v=p[0];var x=p[1],b=v[0]-x[0],_=v[1]-x[1];a=b*b+_*_}}function g(){var o,l,c,u,f=t.touches(r);Di.call(r);for(var h=0,p=f.length;h<p;++h,u=null)if(c=f[h],u=i[c.identifier]){if(l)break;o=c,l=u}if(u){var d=(d=c[0]-o[0])*d+(d=c[1]-o[1])*d,m=a&&Math.sqrt(d/a);o=[(o[0]+c[0])/2,(o[1]+c[1])/2],l=[(l[0]+u[0])/2,(l[1]+u[1])/2],k(m*e)}s=null,A(o,l),L(n)}function y(){if(t.event.touches.length){for(var e=t.event.changedTouches,r=0,a=e.length;r<a;++r)delete i[e[r].identifier];for(var s in i)return void d()}t.selectAll(u).on(o,null),f.on(v,P).on(b,I),p(),C(n)}m(),E(n),f.on(v,null).on(b,m)}function O(){var i=_.of(this,arguments);a?clearTimeout(a):(Di.call(this),e=T(r=n||t.mouse(this)),E(i)),a=setTimeout((function(){a=null,C(i)}),50),F(),k(Math.pow(2,.002*zt())*h.k),A(r,e),L(i)}function z(){var e=t.mouse(this),r=Math.log(h.k)/Math.LN2;M(this,e,T(e),t.event.shiftKey?Math.ceil(r)-1:Math.floor(r)+1)}return Dt||(Dt="onwheel"in i?(zt=function(){return-t.event.deltaY*(t.event.deltaMode?120:1)},"wheel"):"onmousewheel"in i?(zt=function(){return t.event.wheelDelta},"mousewheel"):(zt=function(){return-t.event.detail},"MozMousePixelScroll")),w.event=function(e){e.each((function(){var e=_.of(this,arguments),n=h;Bi?t.select(this).transition().each("start.zoom",(function(){h=this.__chart__||{x:0,y:0,k:1},E(e)})).tween("zoom:zoom",(function(){var i=p[0],a=p[1],o=r?r[0]:i/2,s=r?r[1]:a/2,l=t.interpolateZoom([(o-h.x)/h.k,(s-h.y)/h.k,i/h.k],[(o-n.x)/n.k,(s-n.y)/n.k,i/n.k]);return function(t){var r=l(t),n=i/r[2];this.__chart__=h={x:o-r[0]*n,y:s-r[1]*n,k:n},L(e)}})).each("interrupt.zoom",(function(){C(e)})).each("end.zoom",(function(){C(e)})):(this.__chart__=h,E(e),L(e),C(e))}))},w.translate=function(t){return arguments.length?(h={x:+t[0],y:+t[1],k:h.k},S(),w):[h.x,h.y]},w.scale=function(t){return arguments.length?(h={x:h.x,y:h.y,k:null},k(+t),S(),w):h.k},w.scaleExtent=function(t){return arguments.length?(d=null==t?Rt:[+t[0],+t[1]],w):d},w.center=function(t){return arguments.length?(n=t&&[+t[0],+t[1]],w):n},w.size=function(t){return arguments.length?(p=t&&[+t[0],+t[1]],w):p},w.duration=function(t){return arguments.length?(m=+t,w):m},w.x=function(t){return arguments.length?(c=t,l=t.copy(),h={x:0,y:0,k:1},w):c},w.y=function(t){return arguments.length?(f=t,u=t.copy(),h={x:0,y:0,k:1},w):f},t.rebind(w,_,"on")};var zt,Dt,Rt=[0,1/0];function Ft(){}function Bt(t,e,r){return this instanceof Bt?(this.h=+t,this.s=+e,void(this.l=+r)):arguments.length<2?t instanceof Bt?new Bt(t.h,t.s,t.l):ne(""+t,ie,Bt):new Bt(t,e,r)}t.color=Ft,Ft.prototype.toString=function(){return this.rgb()+""},t.hsl=Bt;var Nt=Bt.prototype=new Ft;function jt(t,e,r){var n,i;function a(t){return Math.round(255*function(t){return t>360?t-=360:t<0&&(t+=360),t<60?n+(i-n)*t/60:t<180?i:t<240?n+(i-n)*(240-t)/60:n}(t))}return t=isNaN(t)?0:(t%=360)<0?t+360:t,e=isNaN(e)||e<0?0:e>1?1:e,n=2*(r=r<0?0:r>1?1:r)-(i=r<=.5?r*(1+e):r+e-r*e),new Qt(a(t+120),a(t),a(t-120))}function Ut(e,r,n){return this instanceof Ut?(this.h=+e,this.c=+r,void(this.l=+n)):arguments.length<2?e instanceof Ut?new Ut(e.h,e.c,e.l):Xt(e instanceof qt?e.l:(e=ae((e=t.rgb(e)).r,e.g,e.b)).l,e.a,e.b):new Ut(e,r,n)}Nt.brighter=function(t){return t=Math.pow(.7,arguments.length?t:1),new Bt(this.h,this.s,this.l/t)},Nt.darker=function(t){return t=Math.pow(.7,arguments.length?t:1),new Bt(this.h,this.s,t*this.l)},Nt.rgb=function(){return jt(this.h,this.s,this.l)},t.hcl=Ut;var Vt=Ut.prototype=new Ft;function Ht(t,e,r){return isNaN(t)&&(t=0),isNaN(e)&&(e=0),new qt(r,Math.cos(t*=Lt)*e,Math.sin(t)*e)}function qt(t,e,r){return this instanceof qt?(this.l=+t,this.a=+e,void(this.b=+r)):arguments.length<2?t instanceof qt?new qt(t.l,t.a,t.b):t instanceof Ut?Ht(t.h,t.c,t.l):ae((t=Qt(t)).r,t.g,t.b):new qt(t,e,r)}Vt.brighter=function(t){return new Ut(this.h,this.c,Math.min(100,this.l+Gt*(arguments.length?t:1)))},Vt.darker=function(t){return new Ut(this.h,this.c,Math.max(0,this.l-Gt*(arguments.length?t:1)))},Vt.rgb=function(){return Ht(this.h,this.c,this.l).rgb()},t.lab=qt;var Gt=18,Yt=qt.prototype=new Ft;function Wt(t,e,r){var n=(t+16)/116,i=n+e/500,a=n-r/200;return new Qt(Kt(3.2404542*(i=.95047*Zt(i))-1.5371385*(n=1*Zt(n))-.4985314*(a=1.08883*Zt(a))),Kt(-.969266*i+1.8760108*n+.041556*a),Kt(.0556434*i-.2040259*n+1.0572252*a))}function Xt(t,e,r){return t>0?new Ut(Math.atan2(r,e)*Ct,Math.sqrt(e*e+r*r),t):new Ut(NaN,NaN,t)}function Zt(t){return t>.206893034?t*t*t:(t-4/29)/7.787037}function Jt(t){return t>.008856?Math.pow(t,1/3):7.787037*t+4/29}function Kt(t){return Math.round(255*(t<=.00304?12.92*t:1.055*Math.pow(t,1/2.4)-.055))}function Qt(t,e,r){return this instanceof Qt?(this.r=~~t,this.g=~~e,void(this.b=~~r)):arguments.length<2?t instanceof Qt?new Qt(t.r,t.g,t.b):ne(""+t,Qt,jt):new Qt(t,e,r)}function $t(t){return new Qt(t>>16,t>>8&255,255&t)}function te(t){return $t(t)+""}Yt.brighter=function(t){return new qt(Math.min(100,this.l+Gt*(arguments.length?t:1)),this.a,this.b)},Yt.darker=function(t){return new qt(Math.max(0,this.l-Gt*(arguments.length?t:1)),this.a,this.b)},Yt.rgb=function(){return Wt(this.l,this.a,this.b)},t.rgb=Qt;var ee=Qt.prototype=new Ft;function re(t){return t<16?"0"+Math.max(0,t).toString(16):Math.min(255,t).toString(16)}function ne(t,e,r){var n,i,a,o=0,s=0,l=0;if(n=/([a-z]+)\((.*)\)/.exec(t=t.toLowerCase()))switch(i=n[2].split(","),n[1]){case"hsl":return r(parseFloat(i[0]),parseFloat(i[1])/100,parseFloat(i[2])/100);case"rgb":return e(se(i[0]),se(i[1]),se(i[2]))}return(a=le.get(t))?e(a.r,a.g,a.b):(null==t||"#"!==t.charAt(0)||isNaN(a=parseInt(t.slice(1),16))||(4===t.length?(o=(3840&a)>>4,o|=o>>4,s=240&a,s|=s>>4,l=15&a,l|=l<<4):7===t.length&&(o=(16711680&a)>>16,s=(65280&a)>>8,l=255&a)),e(o,s,l))}function ie(t,e,r){var n,i,a=Math.min(t/=255,e/=255,r/=255),o=Math.max(t,e,r),s=o-a,l=(o+a)/2;return s?(i=l<.5?s/(o+a):s/(2-o-a),n=t==o?(e-r)/s+(e<r?6:0):e==o?(r-t)/s+2:(t-e)/s+4,n*=60):(n=NaN,i=l>0&&l<1?0:n),new Bt(n,i,l)}function ae(t,e,r){var n=Jt((.4124564*(t=oe(t))+.3575761*(e=oe(e))+.1804375*(r=oe(r)))/.95047),i=Jt((.2126729*t+.7151522*e+.072175*r)/1);return qt(116*i-16,500*(n-i),200*(i-Jt((.0193339*t+.119192*e+.9503041*r)/1.08883)))}function oe(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function se(t){var e=parseFloat(t);return"%"===t.charAt(t.length-1)?Math.round(2.55*e):e}ee.brighter=function(t){t=Math.pow(.7,arguments.length?t:1);var e=this.r,r=this.g,n=this.b,i=30;return e||r||n?(e&&e<i&&(e=i),r&&r<i&&(r=i),n&&n<i&&(n=i),new Qt(Math.min(255,e/t),Math.min(255,r/t),Math.min(255,n/t))):new Qt(i,i,i)},ee.darker=function(t){return new Qt((t=Math.pow(.7,arguments.length?t:1))*this.r,t*this.g,t*this.b)},ee.hsl=function(){return ie(this.r,this.g,this.b)},ee.toString=function(){return"#"+re(this.r)+re(this.g)+re(this.b)};var le=t.map({aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074});function ce(t){return"function"==typeof t?t:function(){return t}}function ue(t){return function(e,r,n){return 2===arguments.length&&"function"==typeof r&&(n=r,r=null),fe(e,r,t,n)}}function fe(e,r,i,a){var o={},s=t.dispatch("beforesend","progress","load","error"),l={},c=new XMLHttpRequest,u=null;function f(){var t,e=c.status;if(!e&&function(t){var e=t.responseType;return e&&"text"!==e?t.response:t.responseText}(c)||e>=200&&e<300||304===e){try{t=i.call(o,c)}catch(t){return void s.error.call(o,t)}s.load.call(o,t)}else s.error.call(o,c)}return self.XDomainRequest&&!("withCredentials"in c)&&/^(http(s)?:)?\/\//.test(e)&&(c=new XDomainRequest),"onload"in c?c.onload=c.onerror=f:c.onreadystatechange=function(){c.readyState>3&&f()},c.onprogress=function(e){var r=t.event;t.event=e;try{s.progress.call(o,c)}finally{t.event=r}},o.header=function(t,e){return t=(t+"").toLowerCase(),arguments.length<2?l[t]:(null==e?delete l[t]:l[t]=e+"",o)},o.mimeType=function(t){return arguments.length?(r=null==t?null:t+"",o):r},o.responseType=function(t){return arguments.length?(u=t,o):u},o.response=function(t){return i=t,o},["get","post"].forEach((function(t){o[t]=function(){return o.send.apply(o,[t].concat(n(arguments)))}})),o.send=function(t,n,i){if(2===arguments.length&&"function"==typeof n&&(i=n,n=null),c.open(t,e,!0),null==r||"accept"in l||(l.accept=r+",*/*"),c.setRequestHeader)for(var a in l)c.setRequestHeader(a,l[a]);return null!=r&&c.overrideMimeType&&c.overrideMimeType(r),null!=u&&(c.responseType=u),null!=i&&o.on("error",i).on("load",(function(t){i(null,t)})),s.beforesend.call(o,c),c.send(null==n?null:n),o},o.abort=function(){return c.abort(),o},t.rebind(o,s,"on"),null==a?o:o.get(function(t){return 1===t.length?function(e,r){t(null==e?r:null)}:t}(a))}le.forEach((function(t,e){le.set(t,$t(e))})),t.functor=ce,t.xhr=ue(C),t.dsv=function(t,e){var r=new RegExp('["'+t+"\n]"),n=t.charCodeAt(0);function i(t,r,n){arguments.length<3&&(n=r,r=null);var i=fe(t,e,null==r?a:o(r),n);return i.row=function(t){return arguments.length?i.response(null==(r=t)?a:o(t)):r},i}function a(t){return i.parse(t.responseText)}function o(t){return function(e){return i.parse(e.responseText,t)}}function s(e){return e.map(l).join(t)}function l(t){return r.test(t)?'"'+t.replace(/\"/g,'""')+'"':t}return i.parse=function(t,e){var r;return i.parseRows(t,(function(t,n){if(r)return r(t,n-1);var i=function(e){for(var r={},n=t.length,i=0;i<n;++i)r[t[i]]=e[i];return r};r=e?function(t,r){return e(i(t),r)}:i}))},i.parseRows=function(t,e){var r,i,a={},o={},s=[],l=t.length,c=0,u=0;function f(){if(c>=l)return o;if(i)return i=!1,a;var e=c;if(34===t.charCodeAt(e)){for(var r=e;r++<l;)if(34===t.charCodeAt(r)){if(34!==t.charCodeAt(r+1))break;++r}return c=r+2,13===(s=t.charCodeAt(r+1))?(i=!0,10===t.charCodeAt(r+2)&&++c):10===s&&(i=!0),t.slice(e+1,r).replace(/""/g,'"')}for(;c<l;){var s,u=1;if(10===(s=t.charCodeAt(c++)))i=!0;else if(13===s)i=!0,10===t.charCodeAt(c)&&(++c,++u);else if(s!==n)continue;return t.slice(e,c-u)}return t.slice(e)}for(;(r=f())!==o;){for(var h=[];r!==a&&r!==o;)h.push(r),r=f();e&&null==(h=e(h,u++))||s.push(h)}return s},i.format=function(e){if(Array.isArray(e[0]))return i.formatRows(e);var r=new L,n=[];return e.forEach((function(t){for(var e in t)r.has(e)||n.push(r.add(e))})),[n.map(l).join(t)].concat(e.map((function(e){return n.map((function(t){return l(e[t])})).join(t)}))).join("\n")},i.formatRows=function(t){return t.map(s).join("\n")},i},t.csv=t.dsv(",","text/csv"),t.tsv=t.dsv("\t","text/tab-separated-values");var he,pe,de,me,ge=this[I(this,"requestAnimationFrame")]||function(t){setTimeout(t,17)};function ve(t,e,r){var n=arguments.length;n<2&&(e=0),n<3&&(r=Date.now());var i=r+e,a={c:t,t:i,n:null};return pe?pe.n=a:he=a,pe=a,de||(me=clearTimeout(me),de=1,ge(ye)),a}function ye(){var t=xe(),e=be()-t;e>24?(isFinite(e)&&(clearTimeout(me),me=setTimeout(ye,e)),de=0):(de=1,ge(ye))}function xe(){for(var t=Date.now(),e=he;e;)t>=e.t&&e.c(t-e.t)&&(e.c=null),e=e.n;return t}function be(){for(var t,e=he,r=1/0;e;)e.c?(e.t<r&&(r=e.t),e=(t=e).n):e=t?t.n=e.n:he=e.n;return pe=t,r}function _e(t){return t[0]}function we(t){return t[1]}function Te(t){for(var e,r,n,i=t.length,a=[0,1],o=2,s=2;s<i;s++){for(;o>1&&(e=t[a[o-2]],r=t[a[o-1]],n=t[s],(r[0]-e[0])*(n[1]-e[1])-(r[1]-e[1])*(n[0]-e[0])<=0);)--o;a[o++]=s}return a.slice(0,o)}function ke(t,e){return t[0]-e[0]||t[1]-e[1]}t.timer=function(){ve.apply(this,arguments)},t.timer.flush=function(){xe(),be()},t.round=function(t,e){return e?Math.round(t*(e=Math.pow(10,e)))/e:Math.round(t)},t.geom={},t.geom.hull=function(t){var e=_e,r=we;if(arguments.length)return n(t);function n(t){if(t.length<3)return[];var n,i=ce(e),a=ce(r),o=t.length,s=[],l=[];for(n=0;n<o;n++)s.push([+i.call(this,t[n],n),+a.call(this,t[n],n),n]);for(s.sort(ke),n=0;n<o;n++)l.push([s[n][0],-s[n][1]]);var c=Te(s),u=Te(l),f=u[0]===c[0],h=u[u.length-1]===c[c.length-1],p=[];for(n=c.length-1;n>=0;--n)p.push(t[s[c[n]][2]]);for(n=+f;n<u.length-h;++n)p.push(t[s[u[n]][2]]);return p}return n.x=function(t){return arguments.length?(e=t,n):e},n.y=function(t){return arguments.length?(r=t,n):r},n},t.geom.polygon=function(t){return U(t,Ae),t};var Ae=t.geom.polygon.prototype=[];function Me(t,e,r){return(r[0]-e[0])*(t[1]-e[1])<(r[1]-e[1])*(t[0]-e[0])}function Se(t,e,r,n){var i=t[0],a=r[0],o=e[0]-i,s=n[0]-a,l=t[1],c=r[1],u=e[1]-l,f=n[1]-c,h=(s*(l-c)-f*(i-a))/(f*o-s*u);return[i+h*o,l+h*u]}function Ee(t){var e=t[0],r=t[t.length-1];return!(e[0]-r[0]||e[1]-r[1])}Ae.area=function(){for(var t,e=-1,r=this.length,n=this[r-1],i=0;++e<r;)t=n,n=this[e],i+=t[1]*n[0]-t[0]*n[1];return.5*i},Ae.centroid=function(t){var e,r,n=-1,i=this.length,a=0,o=0,s=this[i-1];for(arguments.length||(t=-1/(6*this.area()));++n<i;)e=s,s=this[n],r=e[0]*s[1]-s[0]*e[1],a+=(e[0]+s[0])*r,o+=(e[1]+s[1])*r;return[a*t,o*t]},Ae.clip=function(t){for(var e,r,n,i,a,o,s=Ee(t),l=-1,c=this.length-Ee(this),u=this[c-1];++l<c;){for(e=t.slice(),t.length=0,i=this[l],a=e[(n=e.length-s)-1],r=-1;++r<n;)Me(o=e[r],u,i)?(Me(a,u,i)||t.push(Se(a,o,u,i)),t.push(o)):Me(a,u,i)&&t.push(Se(a,o,u,i)),a=o;s&&t.push(t[0]),u=i}return t};var Le,Ce,Pe,Ie,Oe,ze=[],De=[];function Re(){er(this),this.edge=this.site=this.circle=null}function Fe(t){var e=ze.pop()||new Re;return e.site=t,e}function Be(t){We(t),Pe.remove(t),ze.push(t),er(t)}function Ne(t){var e=t.circle,r=e.x,n=e.cy,i={x:r,y:n},a=t.P,o=t.N,s=[t];Be(t);for(var l=a;l.circle&&y(r-l.circle.x)<kt&&y(n-l.circle.cy)<kt;)a=l.P,s.unshift(l),Be(l),l=a;s.unshift(l),We(l);for(var c=o;c.circle&&y(r-c.circle.x)<kt&&y(n-c.circle.cy)<kt;)o=c.N,s.push(c),Be(c),c=o;s.push(c),We(c);var u,f=s.length;for(u=1;u<f;++u)c=s[u],l=s[u-1],Qe(c.edge,l.site,c.site,i);l=s[0],(c=s[f-1]).edge=Je(l.site,c.site,null,i),Ye(l),Ye(c)}function je(t){for(var e,r,n,i,a=t.x,o=t.y,s=Pe._;s;)if((n=Ue(s,o)-a)>kt)s=s.L;else{if(!((i=a-Ve(s,o))>kt)){n>-kt?(e=s.P,r=s):i>-kt?(e=s,r=s.N):e=r=s;break}if(!s.R){e=s;break}s=s.R}var l=Fe(t);if(Pe.insert(e,l),e||r){if(e===r)return We(e),r=Fe(e.site),Pe.insert(l,r),l.edge=r.edge=Je(e.site,l.site),Ye(e),void Ye(r);if(r){We(e),We(r);var c=e.site,u=c.x,f=c.y,h=t.x-u,p=t.y-f,d=r.site,m=d.x-u,g=d.y-f,v=2*(h*g-p*m),y=h*h+p*p,x=m*m+g*g,b={x:(g*y-p*x)/v+u,y:(h*x-m*y)/v+f};Qe(r.edge,c,d,b),l.edge=Je(c,t,null,b),r.edge=Je(t,d,null,b),Ye(e),Ye(r)}else l.edge=Je(e.site,l.site)}}function Ue(t,e){var r=t.site,n=r.x,i=r.y,a=i-e;if(!a)return n;var o=t.P;if(!o)return-1/0;var s=(r=o.site).x,l=r.y,c=l-e;if(!c)return s;var u=s-n,f=1/a-1/c,h=u/c;return f?(-h+Math.sqrt(h*h-2*f*(u*u/(-2*c)-l+c/2+i-a/2)))/f+n:(n+s)/2}function Ve(t,e){var r=t.N;if(r)return Ue(r,e);var n=t.site;return n.y===e?n.x:1/0}function He(t){this.site=t,this.edges=[]}function qe(t,e){return e.angle-t.angle}function Ge(){er(this),this.x=this.y=this.arc=this.site=this.cy=null}function Ye(t){var e=t.P,r=t.N;if(e&&r){var n=e.site,i=t.site,a=r.site;if(n!==a){var o=i.x,s=i.y,l=n.x-o,c=n.y-s,u=a.x-o,f=2*(l*(g=a.y-s)-c*u);if(!(f>=-1e-12)){var h=l*l+c*c,p=u*u+g*g,d=(g*h-c*p)/f,m=(l*p-u*h)/f,g=m+s,v=De.pop()||new Ge;v.arc=t,v.site=i,v.x=d+o,v.y=g+Math.sqrt(d*d+m*m),v.cy=g,t.circle=v;for(var y=null,x=Oe._;x;)if(v.y<x.y||v.y===x.y&&v.x<=x.x){if(!x.L){y=x.P;break}x=x.L}else{if(!x.R){y=x;break}x=x.R}Oe.insert(y,v),y||(Ie=v)}}}}function We(t){var e=t.circle;e&&(e.P||(Ie=e.N),Oe.remove(e),De.push(e),er(e),t.circle=null)}function Xe(t,e){var r=t.b;if(r)return!0;var n,i,a=t.a,o=e[0][0],s=e[1][0],l=e[0][1],c=e[1][1],u=t.l,f=t.r,h=u.x,p=u.y,d=f.x,m=f.y,g=(h+d)/2,v=(p+m)/2;if(m===p){if(g<o||g>=s)return;if(h>d){if(a){if(a.y>=c)return}else a={x:g,y:l};r={x:g,y:c}}else{if(a){if(a.y<l)return}else a={x:g,y:c};r={x:g,y:l}}}else if(i=v-(n=(h-d)/(m-p))*g,n<-1||n>1)if(h>d){if(a){if(a.y>=c)return}else a={x:(l-i)/n,y:l};r={x:(c-i)/n,y:c}}else{if(a){if(a.y<l)return}else a={x:(c-i)/n,y:c};r={x:(l-i)/n,y:l}}else if(p<m){if(a){if(a.x>=s)return}else a={x:o,y:n*o+i};r={x:s,y:n*s+i}}else{if(a){if(a.x<o)return}else a={x:s,y:n*s+i};r={x:o,y:n*o+i}}return t.a=a,t.b=r,!0}function Ze(t,e){this.l=t,this.r=e,this.a=this.b=null}function Je(t,e,r,n){var i=new Ze(t,e);return Le.push(i),r&&Qe(i,t,e,r),n&&Qe(i,e,t,n),Ce[t.i].edges.push(new $e(i,t,e)),Ce[e.i].edges.push(new $e(i,e,t)),i}function Ke(t,e,r){var n=new Ze(t,null);return n.a=e,n.b=r,Le.push(n),n}function Qe(t,e,r,n){t.a||t.b?t.l===r?t.b=n:t.a=n:(t.a=n,t.l=e,t.r=r)}function $e(t,e,r){var n=t.a,i=t.b;this.edge=t,this.site=e,this.angle=r?Math.atan2(r.y-e.y,r.x-e.x):t.l===e?Math.atan2(i.x-n.x,n.y-i.y):Math.atan2(n.x-i.x,i.y-n.y)}function tr(){this._=null}function er(t){t.U=t.C=t.L=t.R=t.P=t.N=null}function rr(t,e){var r=e,n=e.R,i=r.U;i?i.L===r?i.L=n:i.R=n:t._=n,n.U=i,r.U=n,r.R=n.L,r.R&&(r.R.U=r),n.L=r}function nr(t,e){var r=e,n=e.L,i=r.U;i?i.L===r?i.L=n:i.R=n:t._=n,n.U=i,r.U=n,r.L=n.R,r.L&&(r.L.U=r),n.R=r}function ir(t){for(;t.L;)t=t.L;return t}function ar(t,e){var r,n,i,a=t.sort(or).pop();for(Le=[],Ce=new Array(t.length),Pe=new tr,Oe=new tr;;)if(i=Ie,a&&(!i||a.y<i.y||a.y===i.y&&a.x<i.x))a.x===r&&a.y===n||(Ce[a.i]=new He(a),je(a),r=a.x,n=a.y),a=t.pop();else{if(!i)break;Ne(i.arc)}e&&(function(t){for(var e,r,n,i,a,o=Le,s=(r=t[0][0],n=t[0][1],i=t[1][0],a=t[1][1],function(t){var e,o=t.a,s=t.b,l=o.x,c=o.y,u=0,f=1,h=s.x-l,p=s.y-c;if(e=r-l,h||!(e>0)){if(e/=h,h<0){if(e<u)return;e<f&&(f=e)}else if(h>0){if(e>f)return;e>u&&(u=e)}if(e=i-l,h||!(e<0)){if(e/=h,h<0){if(e>f)return;e>u&&(u=e)}else if(h>0){if(e<u)return;e<f&&(f=e)}if(e=n-c,p||!(e>0)){if(e/=p,p<0){if(e<u)return;e<f&&(f=e)}else if(p>0){if(e>f)return;e>u&&(u=e)}if(e=a-c,p||!(e<0)){if(e/=p,p<0){if(e>f)return;e>u&&(u=e)}else if(p>0){if(e<u)return;e<f&&(f=e)}return u>0&&(t.a={x:l+u*h,y:c+u*p}),f<1&&(t.b={x:l+f*h,y:c+f*p}),t}}}}}),l=o.length;l--;)(!Xe(e=o[l],t)||!s(e)||y(e.a.x-e.b.x)<kt&&y(e.a.y-e.b.y)<kt)&&(e.a=e.b=null,o.splice(l,1))}(e),function(t){for(var e,r,n,i,a,o,s,l,c,u,f=t[0][0],h=t[1][0],p=t[0][1],d=t[1][1],m=Ce,g=m.length;g--;)if((a=m[g])&&a.prepare())for(l=(s=a.edges).length,o=0;o<l;)n=(u=s[o].end()).x,i=u.y,e=(c=s[++o%l].start()).x,r=c.y,(y(n-e)>kt||y(i-r)>kt)&&(s.splice(o,0,new $e(Ke(a.site,u,y(n-f)<kt&&d-i>kt?{x:f,y:y(e-f)<kt?r:d}:y(i-d)<kt&&h-n>kt?{x:y(r-d)<kt?e:h,y:d}:y(n-h)<kt&&i-p>kt?{x:h,y:y(e-h)<kt?r:p}:y(i-p)<kt&&n-f>kt?{x:y(r-p)<kt?e:f,y:p}:null),a.site,null)),++l)}(e));var o={cells:Ce,edges:Le};return Pe=Oe=Le=Ce=null,o}function or(t,e){return e.y-t.y||e.x-t.x}He.prototype.prepare=function(){for(var t,e=this.edges,r=e.length;r--;)(t=e[r].edge).b&&t.a||e.splice(r,1);return e.sort(qe),e.length},$e.prototype={start:function(){return this.edge.l===this.site?this.edge.a:this.edge.b},end:function(){return this.edge.l===this.site?this.edge.b:this.edge.a}},tr.prototype={insert:function(t,e){var r,n,i;if(t){if(e.P=t,e.N=t.N,t.N&&(t.N.P=e),t.N=e,t.R){for(t=t.R;t.L;)t=t.L;t.L=e}else t.R=e;r=t}else this._?(t=ir(this._),e.P=null,e.N=t,t.P=t.L=e,r=t):(e.P=e.N=null,this._=e,r=null);for(e.L=e.R=null,e.U=r,e.C=!0,t=e;r&&r.C;)r===(n=r.U).L?(i=n.R)&&i.C?(r.C=i.C=!1,n.C=!0,t=n):(t===r.R&&(rr(this,r),r=(t=r).U),r.C=!1,n.C=!0,nr(this,n)):(i=n.L)&&i.C?(r.C=i.C=!1,n.C=!0,t=n):(t===r.L&&(nr(this,r),r=(t=r).U),r.C=!1,n.C=!0,rr(this,n)),r=t.U;this._.C=!1},remove:function(t){t.N&&(t.N.P=t.P),t.P&&(t.P.N=t.N),t.N=t.P=null;var e,r,n,i=t.U,a=t.L,o=t.R;if(r=a?o?ir(o):a:o,i?i.L===t?i.L=r:i.R=r:this._=r,a&&o?(n=r.C,r.C=t.C,r.L=a,a.U=r,r!==o?(i=r.U,r.U=t.U,t=r.R,i.L=t,r.R=o,o.U=r):(r.U=i,i=r,t=r.R)):(n=t.C,t=r),t&&(t.U=i),!n)if(t&&t.C)t.C=!1;else{do{if(t===this._)break;if(t===i.L){if((e=i.R).C&&(e.C=!1,i.C=!0,rr(this,i),e=i.R),e.L&&e.L.C||e.R&&e.R.C){e.R&&e.R.C||(e.L.C=!1,e.C=!0,nr(this,e),e=i.R),e.C=i.C,i.C=e.R.C=!1,rr(this,i),t=this._;break}}else if((e=i.L).C&&(e.C=!1,i.C=!0,nr(this,i),e=i.L),e.L&&e.L.C||e.R&&e.R.C){e.L&&e.L.C||(e.R.C=!1,e.C=!0,rr(this,e),e=i.L),e.C=i.C,i.C=e.L.C=!1,nr(this,i),t=this._;break}e.C=!0,t=i,i=i.U}while(!t.C);t&&(t.C=!1)}}},t.geom.voronoi=function(t){var e=_e,r=we,n=e,i=r,a=sr;if(t)return o(t);function o(t){var e=new Array(t.length),r=a[0][0],n=a[0][1],i=a[1][0],o=a[1][1];return ar(s(t),a).cells.forEach((function(a,s){var l=a.edges,c=a.site;(e[s]=l.length?l.map((function(t){var e=t.start();return[e.x,e.y]})):c.x>=r&&c.x<=i&&c.y>=n&&c.y<=o?[[r,o],[i,o],[i,n],[r,n]]:[]).point=t[s]})),e}function s(t){return t.map((function(t,e){return{x:Math.round(n(t,e)/kt)*kt,y:Math.round(i(t,e)/kt)*kt,i:e}}))}return o.links=function(t){return ar(s(t)).edges.filter((function(t){return t.l&&t.r})).map((function(e){return{source:t[e.l.i],target:t[e.r.i]}}))},o.triangles=function(t){var e=[];return ar(s(t)).cells.forEach((function(r,n){for(var i,a,o,s,l=r.site,c=r.edges.sort(qe),u=-1,f=c.length,h=c[f-1].edge,p=h.l===l?h.r:h.l;++u<f;)h,i=p,p=(h=c[u].edge).l===l?h.r:h.l,n<i.i&&n<p.i&&(o=i,s=p,((a=l).x-s.x)*(o.y-a.y)-(a.x-o.x)*(s.y-a.y)<0)&&e.push([t[n],t[i.i],t[p.i]])})),e},o.x=function(t){return arguments.length?(n=ce(e=t),o):e},o.y=function(t){return arguments.length?(i=ce(r=t),o):r},o.clipExtent=function(t){return arguments.length?(a=null==t?sr:t,o):a===sr?null:a},o.size=function(t){return arguments.length?o.clipExtent(t&&[[0,0],t]):a===sr?null:a&&a[1]},o};var sr=[[-1e6,-1e6],[1e6,1e6]];function lr(t){return t.x}function cr(t){return t.y}function ur(t,e,r,n,i,a){if(!t(e,r,n,i,a)){var o=.5*(r+i),s=.5*(n+a),l=e.nodes;l[0]&&ur(t,l[0],r,n,o,s),l[1]&&ur(t,l[1],o,n,i,s),l[2]&&ur(t,l[2],r,s,o,a),l[3]&&ur(t,l[3],o,s,i,a)}}function fr(t,e,r,n,i,a,o){var s,l=1/0;return function t(c,u,f,h,p){if(!(u>a||f>o||h<n||p<i)){if(d=c.point){var d,m=e-c.x,g=r-c.y,v=m*m+g*g;if(v<l){var y=Math.sqrt(l=v);n=e-y,i=r-y,a=e+y,o=r+y,s=d}}for(var x=c.nodes,b=.5*(u+h),_=.5*(f+p),w=(r>=_)<<1|e>=b,T=w+4;w<T;++w)if(c=x[3&w])switch(3&w){case 0:t(c,u,f,b,_);break;case 1:t(c,b,f,h,_);break;case 2:t(c,u,_,b,p);break;case 3:t(c,b,_,h,p)}}}(t,n,i,a,o),s}function hr(e,r){e=t.rgb(e),r=t.rgb(r);var n=e.r,i=e.g,a=e.b,o=r.r-n,s=r.g-i,l=r.b-a;return function(t){return"#"+re(Math.round(n+o*t))+re(Math.round(i+s*t))+re(Math.round(a+l*t))}}function pr(t,e){var r,n={},i={};for(r in t)r in e?n[r]=yr(t[r],e[r]):i[r]=t[r];for(r in e)r in t||(i[r]=e[r]);return function(t){for(r in n)i[r]=n[r](t);return i}}function dr(t,e){return t=+t,e=+e,function(r){return t*(1-r)+e*r}}function mr(t,e){var r,n,i,a=gr.lastIndex=vr.lastIndex=0,o=-1,s=[],l=[];for(t+="",e+="";(r=gr.exec(t))&&(n=vr.exec(e));)(i=n.index)>a&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(r=r[0])===(n=n[0])?s[o]?s[o]+=n:s[++o]=n:(s[++o]=null,l.push({i:o,x:dr(r,n)})),a=vr.lastIndex;return a<e.length&&(i=e.slice(a),s[o]?s[o]+=i:s[++o]=i),s.length<2?l[0]?(e=l[0].x,function(t){return e(t)+""}):function(){return e}:(e=l.length,function(t){for(var r,n=0;n<e;++n)s[(r=l[n]).i]=r.x(t);return s.join("")})}t.geom.delaunay=function(e){return t.geom.voronoi().triangles(e)},t.geom.quadtree=function(t,e,r,n,i){var a,o=_e,s=we;if(a=arguments.length)return o=lr,s=cr,3===a&&(i=r,n=e,r=e=0),l(t);function l(t){var l,c,u,f,h,p,d,m,g,v=ce(o),x=ce(s);if(null!=e)p=e,d=r,m=n,g=i;else if(m=g=-(p=d=1/0),c=[],u=[],h=t.length,a)for(f=0;f<h;++f)(l=t[f]).x<p&&(p=l.x),l.y<d&&(d=l.y),l.x>m&&(m=l.x),l.y>g&&(g=l.y),c.push(l.x),u.push(l.y);else for(f=0;f<h;++f){var b=+v(l=t[f],f),_=+x(l,f);b<p&&(p=b),_<d&&(d=_),b>m&&(m=b),_>g&&(g=_),c.push(b),u.push(_)}var w=m-p,T=g-d;function k(t,e,r,n,i,a,o,s){if(!isNaN(r)&&!isNaN(n))if(t.leaf){var l=t.x,c=t.y;if(null!=l)if(y(l-r)+y(c-n)<.01)A(t,e,r,n,i,a,o,s);else{var u=t.point;t.x=t.y=t.point=null,A(t,u,l,c,i,a,o,s),A(t,e,r,n,i,a,o,s)}else t.x=r,t.y=n,t.point=e}else A(t,e,r,n,i,a,o,s)}function A(t,e,r,n,i,a,o,s){var l=.5*(i+o),c=.5*(a+s),u=r>=l,f=n>=c,h=f<<1|u;t.leaf=!1,u?i=l:o=l,f?a=c:s=c,k(t=t.nodes[h]||(t.nodes[h]={leaf:!0,nodes:[],point:null,x:null,y:null}),e,r,n,i,a,o,s)}w>T?g=d+w:m=p+T;var M={leaf:!0,nodes:[],point:null,x:null,y:null,add:function(t){k(M,t,+v(t,++f),+x(t,f),p,d,m,g)},visit:function(t){ur(t,M,p,d,m,g)},find:function(t){return fr(M,t[0],t[1],p,d,m,g)}};if(f=-1,null==e){for(;++f<h;)k(M,t[f],c[f],u[f],p,d,m,g);--f}else t.forEach(M.add);return c=u=t=l=null,M}return l.x=function(t){return arguments.length?(o=t,l):o},l.y=function(t){return arguments.length?(s=t,l):s},l.extent=function(t){return arguments.length?(null==t?e=r=n=i=null:(e=+t[0][0],r=+t[0][1],n=+t[1][0],i=+t[1][1]),l):null==e?null:[[e,r],[n,i]]},l.size=function(t){return arguments.length?(null==t?e=r=n=i=null:(e=r=0,n=+t[0],i=+t[1]),l):null==e?null:[n-e,i-r]},l},t.interpolateRgb=hr,t.interpolateObject=pr,t.interpolateNumber=dr,t.interpolateString=mr;var gr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,vr=new RegExp(gr.source,"g");function yr(e,r){for(var n,i=t.interpolators.length;--i>=0&&!(n=t.interpolators[i](e,r)););return n}function xr(t,e){var r,n=[],i=[],a=t.length,o=e.length,s=Math.min(t.length,e.length);for(r=0;r<s;++r)n.push(yr(t[r],e[r]));for(;r<a;++r)i[r]=t[r];for(;r<o;++r)i[r]=e[r];return function(t){for(r=0;r<s;++r)i[r]=n[r](t);return i}}t.interpolate=yr,t.interpolators=[function(t,e){var r=typeof e;return("string"===r?le.has(e.toLowerCase())||/^(#|rgb\(|hsl\()/i.test(e)?hr:mr:e instanceof Ft?hr:Array.isArray(e)?xr:"object"===r&&isNaN(e)?pr:dr)(t,e)}],t.interpolateArray=xr;var br=function(){return C},_r=t.map({linear:br,poly:function(t){return function(e){return Math.pow(e,t)}},quad:function(){return Mr},cubic:function(){return Sr},sin:function(){return Lr},exp:function(){return Cr},circle:function(){return Pr},elastic:function(t,e){var r;arguments.length<2&&(e=.45);arguments.length?r=e/Mt*Math.asin(1/t):(t=1,r=e/4);return function(n){return 1+t*Math.pow(2,-10*n)*Math.sin((n-r)*Mt/e)}},back:function(t){t||(t=1.70158);return function(e){return e*e*((t+1)*e-t)}},bounce:function(){return Ir}}),wr=t.map({in:C,out:kr,"in-out":Ar,"out-in":function(t){return Ar(kr(t))}});function Tr(t){return function(e){return e<=0?0:e>=1?1:t(e)}}function kr(t){return function(e){return 1-t(1-e)}}function Ar(t){return function(e){return.5*(e<.5?t(2*e):2-t(2-2*e))}}function Mr(t){return t*t}function Sr(t){return t*t*t}function Er(t){if(t<=0)return 0;if(t>=1)return 1;var e=t*t,r=e*t;return 4*(t<.5?r:3*(t-e)+r-.75)}function Lr(t){return 1-Math.cos(t*Et)}function Cr(t){return Math.pow(2,10*(t-1))}function Pr(t){return 1-Math.sqrt(1-t*t)}function Ir(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375}function Or(t,e){return e-=t,function(r){return Math.round(t+e*r)}}function zr(t){var e,r,n,i=[t.a,t.b],a=[t.c,t.d],o=Rr(i),s=Dr(i,a),l=Rr(((e=a)[0]+=(n=-s)*(r=i)[0],e[1]+=n*r[1],e))||0;i[0]*a[1]<a[0]*i[1]&&(i[0]*=-1,i[1]*=-1,o*=-1,s*=-1),this.rotate=(o?Math.atan2(i[1],i[0]):Math.atan2(-a[0],a[1]))*Ct,this.translate=[t.e,t.f],this.scale=[o,l],this.skew=l?Math.atan2(s,l)*Ct:0}function Dr(t,e){return t[0]*e[0]+t[1]*e[1]}function Rr(t){var e=Math.sqrt(Dr(t,t));return e&&(t[0]/=e,t[1]/=e),e}t.ease=function(t){var e=t.indexOf("-"),n=e>=0?t.slice(0,e):t,i=e>=0?t.slice(e+1):"in";return n=_r.get(n)||br,Tr((i=wr.get(i)||C)(n.apply(null,r.call(arguments,1))))},t.interpolateHcl=function(e,r){e=t.hcl(e),r=t.hcl(r);var n=e.h,i=e.c,a=e.l,o=r.h-n,s=r.c-i,l=r.l-a;isNaN(s)&&(s=0,i=isNaN(i)?r.c:i);isNaN(o)?(o=0,n=isNaN(n)?r.h:n):o>180?o-=360:o<-180&&(o+=360);return function(t){return Ht(n+o*t,i+s*t,a+l*t)+""}},t.interpolateHsl=function(e,r){e=t.hsl(e),r=t.hsl(r);var n=e.h,i=e.s,a=e.l,o=r.h-n,s=r.s-i,l=r.l-a;isNaN(s)&&(s=0,i=isNaN(i)?r.s:i);isNaN(o)?(o=0,n=isNaN(n)?r.h:n):o>180?o-=360:o<-180&&(o+=360);return function(t){return jt(n+o*t,i+s*t,a+l*t)+""}},t.interpolateLab=function(e,r){e=t.lab(e),r=t.lab(r);var n=e.l,i=e.a,a=e.b,o=r.l-n,s=r.a-i,l=r.b-a;return function(t){return Wt(n+o*t,i+s*t,a+l*t)+""}},t.interpolateRound=Or,t.transform=function(e){var r=i.createElementNS(t.ns.prefix.svg,"g");return(t.transform=function(t){if(null!=t){r.setAttribute("transform",t);var e=r.transform.baseVal.consolidate()}return new zr(e?e.matrix:Fr)})(e)},zr.prototype.toString=function(){return"translate("+this.translate+")rotate("+this.rotate+")skewX("+this.skew+")scale("+this.scale+")"};var Fr={a:1,b:0,c:0,d:1,e:0,f:0};function Br(t){return t.length?t.pop()+",":""}function Nr(e,r){var n=[],i=[];return e=t.transform(e),r=t.transform(r),function(t,e,r,n){if(t[0]!==e[0]||t[1]!==e[1]){var i=r.push("translate(",null,",",null,")");n.push({i:i-4,x:dr(t[0],e[0])},{i:i-2,x:dr(t[1],e[1])})}else(e[0]||e[1])&&r.push("translate("+e+")")}(e.translate,r.translate,n,i),function(t,e,r,n){t!==e?(t-e>180?e+=360:e-t>180&&(t+=360),n.push({i:r.push(Br(r)+"rotate(",null,")")-2,x:dr(t,e)})):e&&r.push(Br(r)+"rotate("+e+")")}(e.rotate,r.rotate,n,i),function(t,e,r,n){t!==e?n.push({i:r.push(Br(r)+"skewX(",null,")")-2,x:dr(t,e)}):e&&r.push(Br(r)+"skewX("+e+")")}(e.skew,r.skew,n,i),function(t,e,r,n){if(t[0]!==e[0]||t[1]!==e[1]){var i=r.push(Br(r)+"scale(",null,",",null,")");n.push({i:i-4,x:dr(t[0],e[0])},{i:i-2,x:dr(t[1],e[1])})}else 1===e[0]&&1===e[1]||r.push(Br(r)+"scale("+e+")")}(e.scale,r.scale,n,i),e=r=null,function(t){for(var e,r=-1,a=i.length;++r<a;)n[(e=i[r]).i]=e.x(t);return n.join("")}}function jr(t,e){return e=(e-=t=+t)||1/e,function(r){return(r-t)/e}}function Ur(t,e){return e=(e-=t=+t)||1/e,function(r){return Math.max(0,Math.min(1,(r-t)/e))}}function Vr(t){for(var e=t.source,r=t.target,n=function(t,e){if(t===e)return t;var r=Hr(t),n=Hr(e),i=r.pop(),a=n.pop(),o=null;for(;i===a;)o=i,i=r.pop(),a=n.pop();return o}(e,r),i=[e];e!==n;)e=e.parent,i.push(e);for(var a=i.length;r!==n;)i.splice(a,0,r),r=r.parent;return i}function Hr(t){for(var e=[],r=t.parent;null!=r;)e.push(t),t=r,r=r.parent;return e.push(t),e}function qr(t){t.fixed|=2}function Gr(t){t.fixed&=-7}function Yr(t){t.fixed|=4,t.px=t.x,t.py=t.y}function Wr(t){t.fixed&=-5}t.interpolateTransform=Nr,t.layout={},t.layout.bundle=function(){return function(t){for(var e=[],r=-1,n=t.length;++r<n;)e.push(Vr(t[r]));return e}},t.layout.chord=function(){var e,r,n,i,a,o,s,l={},c=0;function u(){var l,u,h,p,d,m={},g=[],v=t.range(i),y=[];for(e=[],r=[],l=0,p=-1;++p<i;){for(u=0,d=-1;++d<i;)u+=n[p][d];g.push(u),y.push(t.range(i)),l+=u}for(a&&v.sort((function(t,e){return a(g[t],g[e])})),o&&y.forEach((function(t,e){t.sort((function(t,r){return o(n[e][t],n[e][r])}))})),l=(Mt-c*i)/l,u=0,p=-1;++p<i;){for(h=u,d=-1;++d<i;){var x=v[p],b=y[x][d],_=n[x][b],w=u,T=u+=_*l;m[x+"-"+b]={index:x,subindex:b,startAngle:w,endAngle:T,value:_}}r[x]={index:x,startAngle:h,endAngle:u,value:g[x]},u+=c}for(p=-1;++p<i;)for(d=p-1;++d<i;){var k=m[p+"-"+d],A=m[d+"-"+p];(k.value||A.value)&&e.push(k.value<A.value?{source:A,target:k}:{source:k,target:A})}s&&f()}function f(){e.sort((function(t,e){return s((t.source.value+t.target.value)/2,(e.source.value+e.target.value)/2)}))}return l.matrix=function(t){return arguments.length?(i=(n=t)&&n.length,e=r=null,l):n},l.padding=function(t){return arguments.length?(c=t,e=r=null,l):c},l.sortGroups=function(t){return arguments.length?(a=t,e=r=null,l):a},l.sortSubgroups=function(t){return arguments.length?(o=t,e=null,l):o},l.sortChords=function(t){return arguments.length?(s=t,e&&f(),l):s},l.chords=function(){return e||u(),e},l.groups=function(){return r||u(),r},l},t.layout.force=function(){var e,r,n,i,a,o,s={},l=t.dispatch("start","tick","end"),c=[1,1],u=.9,f=Xr,h=Zr,p=-30,d=Jr,m=.1,g=.64,v=[],y=[];function x(t){return function(e,r,n,i){if(e.point!==t){var a=e.cx-t.x,o=e.cy-t.y,s=i-r,l=a*a+o*o;if(s*s/g<l){if(l<d){var c=e.charge/l;t.px-=a*c,t.py-=o*c}return!0}if(e.point&&l&&l<d){c=e.pointCharge/l;t.px-=a*c,t.py-=o*c}}return!e.charge}}function b(e){e.px=t.event.x,e.py=t.event.y,s.resume()}return s.tick=function(){if((n*=.99)<.005)return e=null,l.end({type:"end",alpha:n=0}),!0;var r,s,f,h,d,g,b,_,w,T=v.length,k=y.length;for(s=0;s<k;++s)h=(f=y[s]).source,(g=(_=(d=f.target).x-h.x)*_+(w=d.y-h.y)*w)&&(_*=g=n*a[s]*((g=Math.sqrt(g))-i[s])/g,w*=g,d.x-=_*(b=h.weight+d.weight?h.weight/(h.weight+d.weight):.5),d.y-=w*b,h.x+=_*(b=1-b),h.y+=w*b);if((b=n*m)&&(_=c[0]/2,w=c[1]/2,s=-1,b))for(;++s<T;)(f=v[s]).x+=(_-f.x)*b,f.y+=(w-f.y)*b;if(p)for(!function t(e,r,n){var i=0,a=0;if(e.charge=0,!e.leaf)for(var o,s=e.nodes,l=s.length,c=-1;++c<l;)null!=(o=s[c])&&(t(o,r,n),e.charge+=o.charge,i+=o.charge*o.cx,a+=o.charge*o.cy);if(e.point){e.leaf||(e.point.x+=Math.random()-.5,e.point.y+=Math.random()-.5);var u=r*n[e.point.index];e.charge+=e.pointCharge=u,i+=u*e.point.x,a+=u*e.point.y}e.cx=i/e.charge,e.cy=a/e.charge}(r=t.geom.quadtree(v),n,o),s=-1;++s<T;)(f=v[s]).fixed||r.visit(x(f));for(s=-1;++s<T;)(f=v[s]).fixed?(f.x=f.px,f.y=f.py):(f.x-=(f.px-(f.px=f.x))*u,f.y-=(f.py-(f.py=f.y))*u);l.tick({type:"tick",alpha:n})},s.nodes=function(t){return arguments.length?(v=t,s):v},s.links=function(t){return arguments.length?(y=t,s):y},s.size=function(t){return arguments.length?(c=t,s):c},s.linkDistance=function(t){return arguments.length?(f="function"==typeof t?t:+t,s):f},s.distance=s.linkDistance,s.linkStrength=function(t){return arguments.length?(h="function"==typeof t?t:+t,s):h},s.friction=function(t){return arguments.length?(u=+t,s):u},s.charge=function(t){return arguments.length?(p="function"==typeof t?t:+t,s):p},s.chargeDistance=function(t){return arguments.length?(d=t*t,s):Math.sqrt(d)},s.gravity=function(t){return arguments.length?(m=+t,s):m},s.theta=function(t){return arguments.length?(g=t*t,s):Math.sqrt(g)},s.alpha=function(t){return arguments.length?(t=+t,n?t>0?n=t:(e.c=null,e.t=NaN,e=null,l.end({type:"end",alpha:n=0})):t>0&&(l.start({type:"start",alpha:n=t}),e=ve(s.tick)),s):n},s.start=function(){var t,e,r,n=v.length,l=y.length,u=c[0],d=c[1];for(t=0;t<n;++t)(r=v[t]).index=t,r.weight=0;for(t=0;t<l;++t)"number"==typeof(r=y[t]).source&&(r.source=v[r.source]),"number"==typeof r.target&&(r.target=v[r.target]),++r.source.weight,++r.target.weight;for(t=0;t<n;++t)r=v[t],isNaN(r.x)&&(r.x=m("x",u)),isNaN(r.y)&&(r.y=m("y",d)),isNaN(r.px)&&(r.px=r.x),isNaN(r.py)&&(r.py=r.y);if(i=[],"function"==typeof f)for(t=0;t<l;++t)i[t]=+f.call(this,y[t],t);else for(t=0;t<l;++t)i[t]=f;if(a=[],"function"==typeof h)for(t=0;t<l;++t)a[t]=+h.call(this,y[t],t);else for(t=0;t<l;++t)a[t]=h;if(o=[],"function"==typeof p)for(t=0;t<n;++t)o[t]=+p.call(this,v[t],t);else for(t=0;t<n;++t)o[t]=p;function m(r,i){if(!e){for(e=new Array(n),c=0;c<n;++c)e[c]=[];for(c=0;c<l;++c){var a=y[c];e[a.source.index].push(a.target),e[a.target.index].push(a.source)}}for(var o,s=e[t],c=-1,u=s.length;++c<u;)if(!isNaN(o=s[c][r]))return o;return Math.random()*i}return s.resume()},s.resume=function(){return s.alpha(.1)},s.stop=function(){return s.alpha(0)},s.drag=function(){if(r||(r=t.behavior.drag().origin(C).on("dragstart.force",qr).on("drag.force",b).on("dragend.force",Gr)),!arguments.length)return r;this.on("mouseover.force",Yr).on("mouseout.force",Wr).call(r)},t.rebind(s,l,"on")};var Xr=20,Zr=1,Jr=1/0;function Kr(e,r){return t.rebind(e,r,"sort","children","value"),e.nodes=e,e.links=nn,e}function Qr(t,e){for(var r=[t];null!=(t=r.pop());)if(e(t),(i=t.children)&&(n=i.length))for(var n,i;--n>=0;)r.push(i[n])}function $r(t,e){for(var r=[t],n=[];null!=(t=r.pop());)if(n.push(t),(a=t.children)&&(i=a.length))for(var i,a,o=-1;++o<i;)r.push(a[o]);for(;null!=(t=n.pop());)e(t)}function tn(t){return t.children}function en(t){return t.value}function rn(t,e){return e.value-t.value}function nn(e){return t.merge(e.map((function(t){return(t.children||[]).map((function(e){return{source:t,target:e}}))})))}t.layout.hierarchy=function(){var t=rn,e=tn,r=en;function n(i){var a,o=[i],s=[];for(i.depth=0;null!=(a=o.pop());)if(s.push(a),(c=e.call(n,a,a.depth))&&(l=c.length)){for(var l,c,u;--l>=0;)o.push(u=c[l]),u.parent=a,u.depth=a.depth+1;r&&(a.value=0),a.children=c}else r&&(a.value=+r.call(n,a,a.depth)||0),delete a.children;return $r(i,(function(e){var n,i;t&&(n=e.children)&&n.sort(t),r&&(i=e.parent)&&(i.value+=e.value)})),s}return n.sort=function(e){return arguments.length?(t=e,n):t},n.children=function(t){return arguments.length?(e=t,n):e},n.value=function(t){return arguments.length?(r=t,n):r},n.revalue=function(t){return r&&(Qr(t,(function(t){t.children&&(t.value=0)})),$r(t,(function(t){var e;t.children||(t.value=+r.call(n,t,t.depth)||0),(e=t.parent)&&(e.value+=t.value)}))),t},n},t.layout.partition=function(){var e=t.layout.hierarchy(),r=[1,1];function n(t,n){var i=e.call(this,t,n);return function t(e,r,n,i){var a=e.children;if(e.x=r,e.y=e.depth*i,e.dx=n,e.dy=i,a&&(o=a.length)){var o,s,l,c=-1;for(n=e.value?n/e.value:0;++c<o;)t(s=a[c],r,l=s.value*n,i),r+=l}}(i[0],0,r[0],r[1]/function t(e){var r=e.children,n=0;if(r&&(i=r.length))for(var i,a=-1;++a<i;)n=Math.max(n,t(r[a]));return 1+n}(i[0])),i}return n.size=function(t){return arguments.length?(r=t,n):r},Kr(n,e)},t.layout.pie=function(){var e=Number,r=an,n=0,i=Mt,a=0;function o(s){var l,c=s.length,u=s.map((function(t,r){return+e.call(o,t,r)})),f=+("function"==typeof n?n.apply(this,arguments):n),h=("function"==typeof i?i.apply(this,arguments):i)-f,p=Math.min(Math.abs(h)/c,+("function"==typeof a?a.apply(this,arguments):a)),d=p*(h<0?-1:1),m=t.sum(u),g=m?(h-c*d)/m:0,v=t.range(c),y=[];return null!=r&&v.sort(r===an?function(t,e){return u[e]-u[t]}:function(t,e){return r(s[t],s[e])}),v.forEach((function(t){y[t]={data:s[t],value:l=u[t],startAngle:f,endAngle:f+=l*g+d,padAngle:p}})),y}return o.value=function(t){return arguments.length?(e=t,o):e},o.sort=function(t){return arguments.length?(r=t,o):r},o.startAngle=function(t){return arguments.length?(n=t,o):n},o.endAngle=function(t){return arguments.length?(i=t,o):i},o.padAngle=function(t){return arguments.length?(a=t,o):a},o};var an={};function on(t){return t.x}function sn(t){return t.y}function ln(t,e,r){t.y0=e,t.y=r}t.layout.stack=function(){var e=C,r=fn,n=hn,i=ln,a=on,o=sn;function s(l,c){if(!(p=l.length))return l;var u=l.map((function(t,r){return e.call(s,t,r)})),f=u.map((function(t){return t.map((function(t,e){return[a.call(s,t,e),o.call(s,t,e)]}))})),h=r.call(s,f,c);u=t.permute(u,h),f=t.permute(f,h);var p,d,m,g,v=n.call(s,f,c),y=u[0].length;for(m=0;m<y;++m)for(i.call(s,u[0][m],g=v[m],f[0][m][1]),d=1;d<p;++d)i.call(s,u[d][m],g+=f[d-1][m][1],f[d][m][1]);return l}return s.values=function(t){return arguments.length?(e=t,s):e},s.order=function(t){return arguments.length?(r="function"==typeof t?t:cn.get(t)||fn,s):r},s.offset=function(t){return arguments.length?(n="function"==typeof t?t:un.get(t)||hn,s):n},s.x=function(t){return arguments.length?(a=t,s):a},s.y=function(t){return arguments.length?(o=t,s):o},s.out=function(t){return arguments.length?(i=t,s):i},s};var cn=t.map({"inside-out":function(e){var r,n,i=e.length,a=e.map(pn),o=e.map(dn),s=t.range(i).sort((function(t,e){return a[t]-a[e]})),l=0,c=0,u=[],f=[];for(r=0;r<i;++r)n=s[r],l<c?(l+=o[n],u.push(n)):(c+=o[n],f.push(n));return f.reverse().concat(u)},reverse:function(e){return t.range(e.length).reverse()},default:fn}),un=t.map({silhouette:function(t){var e,r,n,i=t.length,a=t[0].length,o=[],s=0,l=[];for(r=0;r<a;++r){for(e=0,n=0;e<i;e++)n+=t[e][r][1];n>s&&(s=n),o.push(n)}for(r=0;r<a;++r)l[r]=(s-o[r])/2;return l},wiggle:function(t){var e,r,n,i,a,o,s,l,c,u=t.length,f=t[0],h=f.length,p=[];for(p[0]=l=c=0,r=1;r<h;++r){for(e=0,i=0;e<u;++e)i+=t[e][r][1];for(e=0,a=0,s=f[r][0]-f[r-1][0];e<u;++e){for(n=0,o=(t[e][r][1]-t[e][r-1][1])/(2*s);n<e;++n)o+=(t[n][r][1]-t[n][r-1][1])/s;a+=o*t[e][r][1]}p[r]=l-=i?a/i*s:0,l<c&&(c=l)}for(r=0;r<h;++r)p[r]-=c;return p},expand:function(t){var e,r,n,i=t.length,a=t[0].length,o=1/i,s=[];for(r=0;r<a;++r){for(e=0,n=0;e<i;e++)n+=t[e][r][1];if(n)for(e=0;e<i;e++)t[e][r][1]/=n;else for(e=0;e<i;e++)t[e][r][1]=o}for(r=0;r<a;++r)s[r]=0;return s},zero:hn});function fn(e){return t.range(e.length)}function hn(t){for(var e=-1,r=t[0].length,n=[];++e<r;)n[e]=0;return n}function pn(t){for(var e,r=1,n=0,i=t[0][1],a=t.length;r<a;++r)(e=t[r][1])>i&&(n=r,i=e);return n}function dn(t){return t.reduce(mn,0)}function mn(t,e){return t+e[1]}function gn(t,e){return vn(t,Math.ceil(Math.log(e.length)/Math.LN2+1))}function vn(t,e){for(var r=-1,n=+t[0],i=(t[1]-n)/e,a=[];++r<=e;)a[r]=i*r+n;return a}function yn(e){return[t.min(e),t.max(e)]}function xn(t,e){return t.value-e.value}function bn(t,e){var r=t._pack_next;t._pack_next=e,e._pack_prev=t,e._pack_next=r,r._pack_prev=e}function _n(t,e){t._pack_next=e,e._pack_prev=t}function wn(t,e){var r=e.x-t.x,n=e.y-t.y,i=t.r+e.r;return.999*i*i>r*r+n*n}function Tn(t){if((e=t.children)&&(l=e.length)){var e,r,n,i,a,o,s,l,c=1/0,u=-1/0,f=1/0,h=-1/0;if(e.forEach(kn),(r=e[0]).x=-r.r,r.y=0,x(r),l>1&&((n=e[1]).x=n.r,n.y=0,x(n),l>2))for(Mn(r,n,i=e[2]),x(i),bn(r,i),r._pack_prev=i,bn(i,n),n=r._pack_next,a=3;a<l;a++){Mn(r,n,i=e[a]);var p=0,d=1,m=1;for(o=n._pack_next;o!==n;o=o._pack_next,d++)if(wn(o,i)){p=1;break}if(1==p)for(s=r._pack_prev;s!==o._pack_prev&&!wn(s,i);s=s._pack_prev,m++);p?(d<m||d==m&&n.r<r.r?_n(r,n=o):_n(r=s,n),a--):(bn(r,i),n=i,x(i))}var g=(c+u)/2,v=(f+h)/2,y=0;for(a=0;a<l;a++)(i=e[a]).x-=g,i.y-=v,y=Math.max(y,i.r+Math.sqrt(i.x*i.x+i.y*i.y));t.r=y,e.forEach(An)}function x(t){c=Math.min(t.x-t.r,c),u=Math.max(t.x+t.r,u),f=Math.min(t.y-t.r,f),h=Math.max(t.y+t.r,h)}}function kn(t){t._pack_next=t._pack_prev=t}function An(t){delete t._pack_next,delete t._pack_prev}function Mn(t,e,r){var n=t.r+r.r,i=e.x-t.x,a=e.y-t.y;if(n&&(i||a)){var o=e.r+r.r,s=i*i+a*a,l=.5+((n*=n)-(o*=o))/(2*s),c=Math.sqrt(Math.max(0,2*o*(n+s)-(n-=s)*n-o*o))/(2*s);r.x=t.x+l*i+c*a,r.y=t.y+l*a-c*i}else r.x=t.x+n,r.y=t.y}function Sn(t,e){return t.parent==e.parent?1:2}function En(t){var e=t.children;return e.length?e[0]:t.t}function Ln(t){var e,r=t.children;return(e=r.length)?r[e-1]:t.t}function Cn(t,e,r){var n=r/(e.i-t.i);e.c-=n,e.s+=r,t.c+=n,e.z+=r,e.m+=r}function Pn(t,e,r){return t.a.parent===e.parent?t.a:r}function In(t){return{x:t.x,y:t.y,dx:t.dx,dy:t.dy}}function On(t,e){var r=t.x+e[3],n=t.y+e[0],i=t.dx-e[1]-e[3],a=t.dy-e[0]-e[2];return i<0&&(r+=i/2,i=0),a<0&&(n+=a/2,a=0),{x:r,y:n,dx:i,dy:a}}function zn(t){var e=t[0],r=t[t.length-1];return e<r?[e,r]:[r,e]}function Dn(t){return t.rangeExtent?t.rangeExtent():zn(t.range())}function Rn(t,e,r,n){var i=r(t[0],t[1]),a=n(e[0],e[1]);return function(t){return a(i(t))}}function Fn(t,e){var r,n=0,i=t.length-1,a=t[n],o=t[i];return o<a&&(r=n,n=i,i=r,r=a,a=o,o=r),t[n]=e.floor(a),t[i]=e.ceil(o),t}function Bn(t){return t?{floor:function(e){return Math.floor(e/t)*t},ceil:function(e){return Math.ceil(e/t)*t}}:Nn}t.layout.histogram=function(){var e=!0,r=Number,n=yn,i=gn;function a(a,o){for(var s,l,c=[],u=a.map(r,this),f=n.call(this,u,o),h=i.call(this,f,u,o),p=(o=-1,u.length),d=h.length-1,m=e?1:1/p;++o<d;)(s=c[o]=[]).dx=h[o+1]-(s.x=h[o]),s.y=0;if(d>0)for(o=-1;++o<p;)(l=u[o])>=f[0]&&l<=f[1]&&((s=c[t.bisect(h,l,1,d)-1]).y+=m,s.push(a[o]));return c}return a.value=function(t){return arguments.length?(r=t,a):r},a.range=function(t){return arguments.length?(n=ce(t),a):n},a.bins=function(t){return arguments.length?(i="number"==typeof t?function(e){return vn(e,t)}:ce(t),a):i},a.frequency=function(t){return arguments.length?(e=!!t,a):e},a},t.layout.pack=function(){var e,r=t.layout.hierarchy().sort(xn),n=0,i=[1,1];function a(t,a){var o=r.call(this,t,a),s=o[0],l=i[0],c=i[1],u=null==e?Math.sqrt:"function"==typeof e?e:function(){return e};if(s.x=s.y=0,$r(s,(function(t){t.r=+u(t.value)})),$r(s,Tn),n){var f=n*(e?1:Math.max(2*s.r/l,2*s.r/c))/2;$r(s,(function(t){t.r+=f})),$r(s,Tn),$r(s,(function(t){t.r-=f}))}return function t(e,r,n,i){var a=e.children;if(e.x=r+=i*e.x,e.y=n+=i*e.y,e.r*=i,a)for(var o=-1,s=a.length;++o<s;)t(a[o],r,n,i)}(s,l/2,c/2,e?1:1/Math.max(2*s.r/l,2*s.r/c)),o}return a.size=function(t){return arguments.length?(i=t,a):i},a.radius=function(t){return arguments.length?(e=null==t||"function"==typeof t?t:+t,a):e},a.padding=function(t){return arguments.length?(n=+t,a):n},Kr(a,r)},t.layout.tree=function(){var e=t.layout.hierarchy().sort(null).value(null),r=Sn,n=[1,1],i=null;function a(t,a){var c=e.call(this,t,a),u=c[0],f=function(t){var e,r={A:null,children:[t]},n=[r];for(;null!=(e=n.pop());)for(var i,a=e.children,o=0,s=a.length;o<s;++o)n.push((a[o]=i={_:a[o],parent:e,children:(i=a[o].children)&&i.slice()||[],A:null,a:null,z:0,m:0,c:0,s:0,t:null,i:o}).a=i);return r.children[0]}(u);if($r(f,o),f.parent.m=-f.z,Qr(f,s),i)Qr(u,l);else{var h=u,p=u,d=u;Qr(u,(function(t){t.x<h.x&&(h=t),t.x>p.x&&(p=t),t.depth>d.depth&&(d=t)}));var m=r(h,p)/2-h.x,g=n[0]/(p.x+r(p,h)/2+m),v=n[1]/(d.depth||1);Qr(u,(function(t){t.x=(t.x+m)*g,t.y=t.depth*v}))}return c}function o(t){var e=t.children,n=t.parent.children,i=t.i?n[t.i-1]:null;if(e.length){!function(t){var e,r=0,n=0,i=t.children,a=i.length;for(;--a>=0;)(e=i[a]).z+=r,e.m+=r,r+=e.s+(n+=e.c)}(t);var a=(e[0].z+e[e.length-1].z)/2;i?(t.z=i.z+r(t._,i._),t.m=t.z-a):t.z=a}else i&&(t.z=i.z+r(t._,i._));t.parent.A=function(t,e,n){if(e){for(var i,a=t,o=t,s=e,l=a.parent.children[0],c=a.m,u=o.m,f=s.m,h=l.m;s=Ln(s),a=En(a),s&&a;)l=En(l),(o=Ln(o)).a=t,(i=s.z+f-a.z-c+r(s._,a._))>0&&(Cn(Pn(s,t,n),t,i),c+=i,u+=i),f+=s.m,c+=a.m,h+=l.m,u+=o.m;s&&!Ln(o)&&(o.t=s,o.m+=f-u),a&&!En(l)&&(l.t=a,l.m+=c-h,n=t)}return n}(t,i,t.parent.A||n[0])}function s(t){t._.x=t.z+t.parent.m,t.m+=t.parent.m}function l(t){t.x*=n[0],t.y=t.depth*n[1]}return a.separation=function(t){return arguments.length?(r=t,a):r},a.size=function(t){return arguments.length?(i=null==(n=t)?l:null,a):i?null:n},a.nodeSize=function(t){return arguments.length?(i=null==(n=t)?null:l,a):i?n:null},Kr(a,e)},t.layout.cluster=function(){var e=t.layout.hierarchy().sort(null).value(null),r=Sn,n=[1,1],i=!1;function a(a,o){var s,l=e.call(this,a,o),c=l[0],u=0;$r(c,(function(e){var n=e.children;n&&n.length?(e.x=function(t){return t.reduce((function(t,e){return t+e.x}),0)/t.length}(n),e.y=function(e){return 1+t.max(e,(function(t){return t.y}))}(n)):(e.x=s?u+=r(e,s):0,e.y=0,s=e)}));var f=function t(e){var r=e.children;return r&&r.length?t(r[0]):e}(c),h=function t(e){var r,n=e.children;return n&&(r=n.length)?t(n[r-1]):e}(c),p=f.x-r(f,h)/2,d=h.x+r(h,f)/2;return $r(c,i?function(t){t.x=(t.x-c.x)*n[0],t.y=(c.y-t.y)*n[1]}:function(t){t.x=(t.x-p)/(d-p)*n[0],t.y=(1-(c.y?t.y/c.y:1))*n[1]}),l}return a.separation=function(t){return arguments.length?(r=t,a):r},a.size=function(t){return arguments.length?(i=null==(n=t),a):i?null:n},a.nodeSize=function(t){return arguments.length?(i=null!=(n=t),a):i?n:null},Kr(a,e)},t.layout.treemap=function(){var e,r=t.layout.hierarchy(),n=Math.round,i=[1,1],a=null,o=In,s=!1,l="squarify",c=.5*(1+Math.sqrt(5));function u(t,e){for(var r,n,i=-1,a=t.length;++i<a;)n=(r=t[i]).value*(e<0?0:e),r.area=isNaN(n)||n<=0?0:n}function f(t){var e=t.children;if(e&&e.length){var r,n,i,a=o(t),s=[],c=e.slice(),h=1/0,m="slice"===l?a.dx:"dice"===l?a.dy:"slice-dice"===l?1&t.depth?a.dy:a.dx:Math.min(a.dx,a.dy);for(u(c,a.dx*a.dy/t.value),s.area=0;(i=c.length)>0;)s.push(r=c[i-1]),s.area+=r.area,"squarify"!==l||(n=p(s,m))<=h?(c.pop(),h=n):(s.area-=s.pop().area,d(s,m,a,!1),m=Math.min(a.dx,a.dy),s.length=s.area=0,h=1/0);s.length&&(d(s,m,a,!0),s.length=s.area=0),e.forEach(f)}}function h(t){var e=t.children;if(e&&e.length){var r,n=o(t),i=e.slice(),a=[];for(u(i,n.dx*n.dy/t.value),a.area=0;r=i.pop();)a.push(r),a.area+=r.area,null!=r.z&&(d(a,r.z?n.dx:n.dy,n,!i.length),a.length=a.area=0);e.forEach(h)}}function p(t,e){for(var r,n=t.area,i=0,a=1/0,o=-1,s=t.length;++o<s;)(r=t[o].area)&&(r<a&&(a=r),r>i&&(i=r));return e*=e,(n*=n)?Math.max(e*i*c/n,n/(e*a*c)):1/0}function d(t,e,r,i){var a,o=-1,s=t.length,l=r.x,c=r.y,u=e?n(t.area/e):0;if(e==r.dx){for((i||u>r.dy)&&(u=r.dy);++o<s;)(a=t[o]).x=l,a.y=c,a.dy=u,l+=a.dx=Math.min(r.x+r.dx-l,u?n(a.area/u):0);a.z=!0,a.dx+=r.x+r.dx-l,r.y+=u,r.dy-=u}else{for((i||u>r.dx)&&(u=r.dx);++o<s;)(a=t[o]).x=l,a.y=c,a.dx=u,c+=a.dy=Math.min(r.y+r.dy-c,u?n(a.area/u):0);a.z=!1,a.dy+=r.y+r.dy-c,r.x+=u,r.dx-=u}}function m(t){var n=e||r(t),a=n[0];return a.x=a.y=0,a.value?(a.dx=i[0],a.dy=i[1]):a.dx=a.dy=0,e&&r.revalue(a),u([a],a.dx*a.dy/a.value),(e?h:f)(a),s&&(e=n),n}return m.size=function(t){return arguments.length?(i=t,m):i},m.padding=function(t){if(!arguments.length)return a;function e(e){var r=t.call(m,e,e.depth);return null==r?In(e):On(e,"number"==typeof r?[r,r,r,r]:r)}function r(e){return On(e,t)}var n;return o=null==(a=t)?In:"function"==(n=typeof t)?e:"number"===n?(t=[t,t,t,t],r):r,m},m.round=function(t){return arguments.length?(n=t?Math.round:Number,m):n!=Number},m.sticky=function(t){return arguments.length?(s=t,e=null,m):s},m.ratio=function(t){return arguments.length?(c=t,m):c},m.mode=function(t){return arguments.length?(l=t+"",m):l},Kr(m,r)},t.random={normal:function(t,e){var r=arguments.length;return r<2&&(e=1),r<1&&(t=0),function(){var r,n,i;do{i=(r=2*Math.random()-1)*r+(n=2*Math.random()-1)*n}while(!i||i>1);return t+e*r*Math.sqrt(-2*Math.log(i)/i)}},logNormal:function(){var e=t.random.normal.apply(t,arguments);return function(){return Math.exp(e())}},bates:function(e){var r=t.random.irwinHall(e);return function(){return r()/e}},irwinHall:function(t){return function(){for(var e=0,r=0;r<t;r++)e+=Math.random();return e}}},t.scale={};var Nn={floor:C,ceil:C};function jn(e,r,n,i){var a=[],o=[],s=0,l=Math.min(e.length,r.length)-1;for(e[l]<e[0]&&(e=e.slice().reverse(),r=r.slice().reverse());++s<=l;)a.push(n(e[s-1],e[s])),o.push(i(r[s-1],r[s]));return function(r){var n=t.bisect(e,r,1,l)-1;return o[n](a[n](r))}}function Un(e,r){return t.rebind(e,r,"range","rangeRound","interpolate","clamp")}function Vn(t,e){return Fn(t,Bn(Hn(t,e)[2])),Fn(t,Bn(Hn(t,e)[2])),t}function Hn(t,e){null==e&&(e=10);var r=zn(t),n=r[1]-r[0],i=Math.pow(10,Math.floor(Math.log(n/e)/Math.LN10)),a=e/n*i;return a<=.15?i*=10:a<=.35?i*=5:a<=.75&&(i*=2),r[0]=Math.ceil(r[0]/i)*i,r[1]=Math.floor(r[1]/i)*i+.5*i,r[2]=i,r}function qn(e,r){return t.range.apply(t,Hn(e,r))}t.scale.linear=function(){return function t(e,r,n,i){var a,o;function s(){var t=Math.min(e.length,r.length)>2?jn:Rn,s=i?Ur:jr;return a=t(e,r,s,n),o=t(r,e,s,yr),l}function l(t){return a(t)}return l.invert=function(t){return o(t)},l.domain=function(t){return arguments.length?(e=t.map(Number),s()):e},l.range=function(t){return arguments.length?(r=t,s()):r},l.rangeRound=function(t){return l.range(t).interpolate(Or)},l.clamp=function(t){return arguments.length?(i=t,s()):i},l.interpolate=function(t){return arguments.length?(n=t,s()):n},l.ticks=function(t){return qn(e,t)},l.tickFormat=function(t,r){return d3_scale_linearTickFormat(e,t,r)},l.nice=function(t){return Vn(e,t),s()},l.copy=function(){return t(e,r,n,i)},s()}([0,1],[0,1],yr,!1)};t.scale.log=function(){return function t(e,r,n,i){function a(t){return(n?Math.log(t<0?0:t):-Math.log(t>0?0:-t))/Math.log(r)}function o(t){return n?Math.pow(r,t):-Math.pow(r,-t)}function s(t){return e(a(t))}return s.invert=function(t){return o(e.invert(t))},s.domain=function(t){return arguments.length?(n=t[0]>=0,e.domain((i=t.map(Number)).map(a)),s):i},s.base=function(t){return arguments.length?(r=+t,e.domain(i.map(a)),s):r},s.nice=function(){var t=Fn(i.map(a),n?Math:Gn);return e.domain(t),i=t.map(o),s},s.ticks=function(){var t=zn(i),e=[],s=t[0],l=t[1],c=Math.floor(a(s)),u=Math.ceil(a(l)),f=r%1?2:r;if(isFinite(u-c)){if(n){for(;c<u;c++)for(var h=1;h<f;h++)e.push(o(c)*h);e.push(o(c))}else for(e.push(o(c));c++<u;)for(h=f-1;h>0;h--)e.push(o(c)*h);for(c=0;e[c]<s;c++);for(u=e.length;e[u-1]>l;u--);e=e.slice(c,u)}return e},s.copy=function(){return t(e.copy(),r,n,i)},Un(s,e)}(t.scale.linear().domain([0,1]),10,!0,[1,10])};var Gn={floor:function(t){return-Math.ceil(-t)},ceil:function(t){return-Math.floor(-t)}};function Yn(t){return function(e){return e<0?-Math.pow(-e,t):Math.pow(e,t)}}t.scale.pow=function(){return function t(e,r,n){var i=Yn(r),a=Yn(1/r);function o(t){return e(i(t))}return o.invert=function(t){return a(e.invert(t))},o.domain=function(t){return arguments.length?(e.domain((n=t.map(Number)).map(i)),o):n},o.ticks=function(t){return qn(n,t)},o.tickFormat=function(t,e){return d3_scale_linearTickFormat(n,t,e)},o.nice=function(t){return o.domain(Vn(n,t))},o.exponent=function(t){return arguments.length?(i=Yn(r=t),a=Yn(1/r),e.domain(n.map(i)),o):r},o.copy=function(){return t(e.copy(),r,n)},Un(o,e)}(t.scale.linear(),1,[0,1])},t.scale.sqrt=function(){return t.scale.pow().exponent(.5)},t.scale.ordinal=function(){return function e(r,n){var i,a,o;function s(t){return a[((i.get(t)||("range"===n.t?i.set(t,r.push(t)):NaN))-1)%a.length]}function l(e,n){return t.range(r.length).map((function(t){return e+n*t}))}return s.domain=function(t){if(!arguments.length)return r;r=[],i=new _;for(var e,a=-1,o=t.length;++a<o;)i.has(e=t[a])||i.set(e,r.push(e));return s[n.t].apply(s,n.a)},s.range=function(t){return arguments.length?(a=t,o=0,n={t:"range",a:arguments},s):a},s.rangePoints=function(t,e){arguments.length<2&&(e=0);var i=t[0],c=t[1],u=r.length<2?(i=(i+c)/2,0):(c-i)/(r.length-1+e);return a=l(i+u*e/2,u),o=0,n={t:"rangePoints",a:arguments},s},s.rangeRoundPoints=function(t,e){arguments.length<2&&(e=0);var i=t[0],c=t[1],u=r.length<2?(i=c=Math.round((i+c)/2),0):(c-i)/(r.length-1+e)|0;return a=l(i+Math.round(u*e/2+(c-i-(r.length-1+e)*u)/2),u),o=0,n={t:"rangeRoundPoints",a:arguments},s},s.rangeBands=function(t,e,i){arguments.length<2&&(e=0),arguments.length<3&&(i=e);var c=t[1]<t[0],u=t[c-0],f=t[1-c],h=(f-u)/(r.length-e+2*i);return a=l(u+h*i,h),c&&a.reverse(),o=h*(1-e),n={t:"rangeBands",a:arguments},s},s.rangeRoundBands=function(t,e,i){arguments.length<2&&(e=0),arguments.length<3&&(i=e);var c=t[1]<t[0],u=t[c-0],f=t[1-c],h=Math.floor((f-u)/(r.length-e+2*i));return a=l(u+Math.round((f-u-(r.length-e)*h)/2),h),c&&a.reverse(),o=Math.round(h*(1-e)),n={t:"rangeRoundBands",a:arguments},s},s.rangeBand=function(){return o},s.rangeExtent=function(){return zn(n.a[0])},s.copy=function(){return e(r,n)},s.domain(r)}([],{t:"range",a:[[]]})},t.scale.category10=function(){return t.scale.ordinal().range(Wn)},t.scale.category20=function(){return t.scale.ordinal().range(Xn)},t.scale.category20b=function(){return t.scale.ordinal().range(Zn)},t.scale.category20c=function(){return t.scale.ordinal().range(Jn)};var Wn=[2062260,16744206,2924588,14034728,9725885,9197131,14907330,8355711,12369186,1556175].map(te),Xn=[2062260,11454440,16744206,16759672,2924588,10018698,14034728,16750742,9725885,12955861,9197131,12885140,14907330,16234194,8355711,13092807,12369186,14408589,1556175,10410725].map(te),Zn=[3750777,5395619,7040719,10264286,6519097,9216594,11915115,13556636,9202993,12426809,15186514,15190932,8666169,11356490,14049643,15177372,8077683,10834324,13528509,14589654].map(te),Jn=[3244733,7057110,10406625,13032431,15095053,16616764,16625259,16634018,3253076,7652470,10607003,13101504,7695281,10394312,12369372,14342891,6513507,9868950,12434877,14277081].map(te);function Kn(){return 0}t.scale.quantile=function(){return function e(r,n){var i;function a(){var e=0,a=n.length;for(i=[];++e<a;)i[e-1]=t.quantile(r,e/a);return o}function o(e){if(!isNaN(e=+e))return n[t.bisect(i,e)]}return o.domain=function(t){return arguments.length?(r=t.map(p).filter(d).sort(h),a()):r},o.range=function(t){return arguments.length?(n=t,a()):n},o.quantiles=function(){return i},o.invertExtent=function(t){return(t=n.indexOf(t))<0?[NaN,NaN]:[t>0?i[t-1]:r[0],t<i.length?i[t]:r[r.length-1]]},o.copy=function(){return e(r,n)},a()}([],[])},t.scale.quantize=function(){return function t(e,r,n){var i,a;function o(t){return n[Math.max(0,Math.min(a,Math.floor(i*(t-e))))]}function s(){return i=n.length/(r-e),a=n.length-1,o}return o.domain=function(t){return arguments.length?(e=+t[0],r=+t[t.length-1],s()):[e,r]},o.range=function(t){return arguments.length?(n=t,s()):n},o.invertExtent=function(t){return[t=(t=n.indexOf(t))<0?NaN:t/i+e,t+1/i]},o.copy=function(){return t(e,r,n)},s()}(0,1,[0,1])},t.scale.threshold=function(){return function e(r,n){function i(e){if(e<=e)return n[t.bisect(r,e)]}return i.domain=function(t){return arguments.length?(r=t,i):r},i.range=function(t){return arguments.length?(n=t,i):n},i.invertExtent=function(t){return t=n.indexOf(t),[r[t-1],r[t]]},i.copy=function(){return e(r,n)},i}([.5],[0,1])},t.scale.identity=function(){return function t(e){function r(t){return+t}return r.invert=r,r.domain=r.range=function(t){return arguments.length?(e=t.map(r),r):e},r.ticks=function(t){return qn(e,t)},r.tickFormat=function(t,r){return d3_scale_linearTickFormat(e,t,r)},r.copy=function(){return t(e)},r}([0,1])},t.svg={},t.svg.arc=function(){var t=$n,e=ti,r=Kn,n=Qn,i=ei,a=ri,o=ni;function s(){var s=Math.max(0,+t.apply(this,arguments)),c=Math.max(0,+e.apply(this,arguments)),u=i.apply(this,arguments)-Et,f=a.apply(this,arguments)-Et,h=Math.abs(f-u),p=u>f?0:1;if(c<s&&(d=c,c=s,s=d),h>=St)return l(c,p)+(s?l(s,1-p):"")+"Z";var d,m,g,v,y,x,b,_,w,T,k,A,M=0,S=0,E=[];if((v=(+o.apply(this,arguments)||0)/2)&&(g=n===Qn?Math.sqrt(s*s+c*c):+n.apply(this,arguments),p||(S*=-1),c&&(S=Pt(g/c*Math.sin(v))),s&&(M=Pt(g/s*Math.sin(v)))),c){y=c*Math.cos(u+S),x=c*Math.sin(u+S),b=c*Math.cos(f-S),_=c*Math.sin(f-S);var L=Math.abs(f-u-2*S)<=At?0:1;if(S&&ii(y,x,b,_)===p^L){var C=(u+f)/2;y=c*Math.cos(C),x=c*Math.sin(C),b=_=null}}else y=x=0;if(s){w=s*Math.cos(f-M),T=s*Math.sin(f-M),k=s*Math.cos(u+M),A=s*Math.sin(u+M);var P=Math.abs(u-f+2*M)<=At?0:1;if(M&&ii(w,T,k,A)===1-p^P){var I=(u+f)/2;w=s*Math.cos(I),T=s*Math.sin(I),k=A=null}}else w=T=0;if(h>kt&&(d=Math.min(Math.abs(c-s)/2,+r.apply(this,arguments)))>.001){m=s<c^p?0:1;var O=d,z=d;if(h<At){var D=null==k?[w,T]:null==b?[y,x]:Se([y,x],[k,A],[b,_],[w,T]),R=y-D[0],F=x-D[1],B=b-D[0],N=_-D[1],j=1/Math.sin(Math.acos((R*B+F*N)/(Math.sqrt(R*R+F*F)*Math.sqrt(B*B+N*N)))/2),U=Math.sqrt(D[0]*D[0]+D[1]*D[1]);z=Math.min(d,(s-U)/(j-1)),O=Math.min(d,(c-U)/(j+1))}if(null!=b){var V=ai(null==k?[w,T]:[k,A],[y,x],c,O,p),H=ai([b,_],[w,T],c,O,p);d===O?E.push("M",V[0],"A",O,",",O," 0 0,",m," ",V[1],"A",c,",",c," 0 ",1-p^ii(V[1][0],V[1][1],H[1][0],H[1][1]),",",p," ",H[1],"A",O,",",O," 0 0,",m," ",H[0]):E.push("M",V[0],"A",O,",",O," 0 1,",m," ",H[0])}else E.push("M",y,",",x);if(null!=k){var q=ai([y,x],[k,A],s,-z,p),G=ai([w,T],null==b?[y,x]:[b,_],s,-z,p);d===z?E.push("L",G[0],"A",z,",",z," 0 0,",m," ",G[1],"A",s,",",s," 0 ",p^ii(G[1][0],G[1][1],q[1][0],q[1][1]),",",1-p," ",q[1],"A",z,",",z," 0 0,",m," ",q[0]):E.push("L",G[0],"A",z,",",z," 0 0,",m," ",q[0])}else E.push("L",w,",",T)}else E.push("M",y,",",x),null!=b&&E.push("A",c,",",c," 0 ",L,",",p," ",b,",",_),E.push("L",w,",",T),null!=k&&E.push("A",s,",",s," 0 ",P,",",1-p," ",k,",",A);return E.push("Z"),E.join("")}function l(t,e){return"M0,"+t+"A"+t+","+t+" 0 1,"+e+" 0,"+-t+"A"+t+","+t+" 0 1,"+e+" 0,"+t}return s.innerRadius=function(e){return arguments.length?(t=ce(e),s):t},s.outerRadius=function(t){return arguments.length?(e=ce(t),s):e},s.cornerRadius=function(t){return arguments.length?(r=ce(t),s):r},s.padRadius=function(t){return arguments.length?(n=t==Qn?Qn:ce(t),s):n},s.startAngle=function(t){return arguments.length?(i=ce(t),s):i},s.endAngle=function(t){return arguments.length?(a=ce(t),s):a},s.padAngle=function(t){return arguments.length?(o=ce(t),s):o},s.centroid=function(){var r=(+t.apply(this,arguments)+ +e.apply(this,arguments))/2,n=(+i.apply(this,arguments)+ +a.apply(this,arguments))/2-Et;return[Math.cos(n)*r,Math.sin(n)*r]},s};var Qn="auto";function $n(t){return t.innerRadius}function ti(t){return t.outerRadius}function ei(t){return t.startAngle}function ri(t){return t.endAngle}function ni(t){return t&&t.padAngle}function ii(t,e,r,n){return(t-r)*e-(e-n)*t>0?0:1}function ai(t,e,r,n,i){var a=t[0]-e[0],o=t[1]-e[1],s=(i?n:-n)/Math.sqrt(a*a+o*o),l=s*o,c=-s*a,u=t[0]+l,f=t[1]+c,h=e[0]+l,p=e[1]+c,d=(u+h)/2,m=(f+p)/2,g=h-u,v=p-f,y=g*g+v*v,x=r-n,b=u*p-h*f,_=(v<0?-1:1)*Math.sqrt(Math.max(0,x*x*y-b*b)),w=(b*v-g*_)/y,T=(-b*g-v*_)/y,k=(b*v+g*_)/y,A=(-b*g+v*_)/y,M=w-d,S=T-m,E=k-d,L=A-m;return M*M+S*S>E*E+L*L&&(w=k,T=A),[[w-l,T-c],[w*r/x,T*r/x]]}function oi(){return!0}function si(t){var e=_e,r=we,n=oi,i=ci,a=i.key,o=.7;function s(a){var s,l=[],c=[],u=-1,f=a.length,h=ce(e),p=ce(r);function d(){l.push("M",i(t(c),o))}for(;++u<f;)n.call(this,s=a[u],u)?c.push([+h.call(this,s,u),+p.call(this,s,u)]):c.length&&(d(),c=[]);return c.length&&d(),l.length?l.join(""):null}return s.x=function(t){return arguments.length?(e=t,s):e},s.y=function(t){return arguments.length?(r=t,s):r},s.defined=function(t){return arguments.length?(n=t,s):n},s.interpolate=function(t){return arguments.length?(a="function"==typeof t?i=t:(i=li.get(t)||ci).key,s):a},s.tension=function(t){return arguments.length?(o=t,s):o},s}t.svg.line=function(){return si(C)};var li=t.map({linear:ci,"linear-closed":ui,step:function(t){var e=0,r=t.length,n=t[0],i=[n[0],",",n[1]];for(;++e<r;)i.push("H",(n[0]+(n=t[e])[0])/2,"V",n[1]);r>1&&i.push("H",n[0]);return i.join("")},"step-before":fi,"step-after":hi,basis:mi,"basis-open":function(t){if(t.length<4)return ci(t);var e,r=[],n=-1,i=t.length,a=[0],o=[0];for(;++n<3;)e=t[n],a.push(e[0]),o.push(e[1]);r.push(gi(xi,a)+","+gi(xi,o)),--n;for(;++n<i;)e=t[n],a.shift(),a.push(e[0]),o.shift(),o.push(e[1]),bi(r,a,o);return r.join("")},"basis-closed":function(t){var e,r,n=-1,i=t.length,a=i+4,o=[],s=[];for(;++n<4;)r=t[n%i],o.push(r[0]),s.push(r[1]);e=[gi(xi,o),",",gi(xi,s)],--n;for(;++n<a;)r=t[n%i],o.shift(),o.push(r[0]),s.shift(),s.push(r[1]),bi(e,o,s);return e.join("")},bundle:function(t,e){var r=t.length-1;if(r)for(var n,i,a=t[0][0],o=t[0][1],s=t[r][0]-a,l=t[r][1]-o,c=-1;++c<=r;)n=t[c],i=c/r,n[0]=e*n[0]+(1-e)*(a+i*s),n[1]=e*n[1]+(1-e)*(o+i*l);return mi(t)},cardinal:function(t,e){return t.length<3?ci(t):t[0]+pi(t,di(t,e))},"cardinal-open":function(t,e){return t.length<4?ci(t):t[1]+pi(t.slice(1,-1),di(t,e))},"cardinal-closed":function(t,e){return t.length<3?ui(t):t[0]+pi((t.push(t[0]),t),di([t[t.length-2]].concat(t,[t[1]]),e))},monotone:function(t){return t.length<3?ci(t):t[0]+pi(t,function(t){var e,r,n,i,a=[],o=function(t){var e=0,r=t.length-1,n=[],i=t[0],a=t[1],o=n[0]=_i(i,a);for(;++e<r;)n[e]=(o+(o=_i(i=a,a=t[e+1])))/2;return n[e]=o,n}(t),s=-1,l=t.length-1;for(;++s<l;)e=_i(t[s],t[s+1]),y(e)<kt?o[s]=o[s+1]=0:(r=o[s]/e,n=o[s+1]/e,(i=r*r+n*n)>9&&(i=3*e/Math.sqrt(i),o[s]=i*r,o[s+1]=i*n));s=-1;for(;++s<=l;)i=(t[Math.min(l,s+1)][0]-t[Math.max(0,s-1)][0])/(6*(1+o[s]*o[s])),a.push([i||0,o[s]*i||0]);return a}(t))}});function ci(t){return t.length>1?t.join("L"):t+"Z"}function ui(t){return t.join("L")+"Z"}function fi(t){for(var e=0,r=t.length,n=t[0],i=[n[0],",",n[1]];++e<r;)i.push("V",(n=t[e])[1],"H",n[0]);return i.join("")}function hi(t){for(var e=0,r=t.length,n=t[0],i=[n[0],",",n[1]];++e<r;)i.push("H",(n=t[e])[0],"V",n[1]);return i.join("")}function pi(t,e){if(e.length<1||t.length!=e.length&&t.length!=e.length+2)return ci(t);var r=t.length!=e.length,n="",i=t[0],a=t[1],o=e[0],s=o,l=1;if(r&&(n+="Q"+(a[0]-2*o[0]/3)+","+(a[1]-2*o[1]/3)+","+a[0]+","+a[1],i=t[1],l=2),e.length>1){s=e[1],a=t[l],l++,n+="C"+(i[0]+o[0])+","+(i[1]+o[1])+","+(a[0]-s[0])+","+(a[1]-s[1])+","+a[0]+","+a[1];for(var c=2;c<e.length;c++,l++)a=t[l],s=e[c],n+="S"+(a[0]-s[0])+","+(a[1]-s[1])+","+a[0]+","+a[1]}if(r){var u=t[l];n+="Q"+(a[0]+2*s[0]/3)+","+(a[1]+2*s[1]/3)+","+u[0]+","+u[1]}return n}function di(t,e){for(var r,n=[],i=(1-e)/2,a=t[0],o=t[1],s=1,l=t.length;++s<l;)r=a,a=o,o=t[s],n.push([i*(o[0]-r[0]),i*(o[1]-r[1])]);return n}function mi(t){if(t.length<3)return ci(t);var e=1,r=t.length,n=t[0],i=n[0],a=n[1],o=[i,i,i,(n=t[1])[0]],s=[a,a,a,n[1]],l=[i,",",a,"L",gi(xi,o),",",gi(xi,s)];for(t.push(t[r-1]);++e<=r;)n=t[e],o.shift(),o.push(n[0]),s.shift(),s.push(n[1]),bi(l,o,s);return t.pop(),l.push("L",n),l.join("")}function gi(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}li.forEach((function(t,e){e.key=t,e.closed=/-closed$/.test(t)}));var vi=[0,2/3,1/3,0],yi=[0,1/3,2/3,0],xi=[0,1/6,2/3,1/6];function bi(t,e,r){t.push("C",gi(vi,e),",",gi(vi,r),",",gi(yi,e),",",gi(yi,r),",",gi(xi,e),",",gi(xi,r))}function _i(t,e){return(e[1]-t[1])/(e[0]-t[0])}function wi(t){for(var e,r,n,i=-1,a=t.length;++i<a;)r=(e=t[i])[0],n=e[1]-Et,e[0]=r*Math.cos(n),e[1]=r*Math.sin(n);return t}function Ti(t){var e=_e,r=_e,n=0,i=we,a=oi,o=ci,s=o.key,l=o,c="L",u=.7;function f(s){var f,h,p,d=[],m=[],g=[],v=-1,y=s.length,x=ce(e),b=ce(n),_=e===r?function(){return h}:ce(r),w=n===i?function(){return p}:ce(i);function T(){d.push("M",o(t(g),u),c,l(t(m.reverse()),u),"Z")}for(;++v<y;)a.call(this,f=s[v],v)?(m.push([h=+x.call(this,f,v),p=+b.call(this,f,v)]),g.push([+_.call(this,f,v),+w.call(this,f,v)])):m.length&&(T(),m=[],g=[]);return m.length&&T(),d.length?d.join(""):null}return f.x=function(t){return arguments.length?(e=r=t,f):r},f.x0=function(t){return arguments.length?(e=t,f):e},f.x1=function(t){return arguments.length?(r=t,f):r},f.y=function(t){return arguments.length?(n=i=t,f):i},f.y0=function(t){return arguments.length?(n=t,f):n},f.y1=function(t){return arguments.length?(i=t,f):i},f.defined=function(t){return arguments.length?(a=t,f):a},f.interpolate=function(t){return arguments.length?(s="function"==typeof t?o=t:(o=li.get(t)||ci).key,l=o.reverse||o,c=o.closed?"M":"L",f):s},f.tension=function(t){return arguments.length?(u=t,f):u},f}function ki(t){return t.source}function Ai(t){return t.target}function Mi(t){return t.radius}function Si(t){return[t.x,t.y]}function Ei(t){return function(){var e=t.apply(this,arguments),r=e[0],n=e[1]-Et;return[r*Math.cos(n),r*Math.sin(n)]}}function Li(){return 64}function Ci(){return"circle"}function Pi(t){var e=Math.sqrt(t/At);return"M0,"+e+"A"+e+","+e+" 0 1,1 0,"+-e+"A"+e+","+e+" 0 1,1 0,"+e+"Z"}t.svg.line.radial=function(){var t=si(wi);return t.radius=t.x,delete t.x,t.angle=t.y,delete t.y,t},fi.reverse=hi,hi.reverse=fi,t.svg.area=function(){return Ti(C)},t.svg.area.radial=function(){var t=Ti(wi);return t.radius=t.x,delete t.x,t.innerRadius=t.x0,delete t.x0,t.outerRadius=t.x1,delete t.x1,t.angle=t.y,delete t.y,t.startAngle=t.y0,delete t.y0,t.endAngle=t.y1,delete t.y1,t},t.svg.chord=function(){var t=ki,e=Ai,r=Mi,n=ei,i=ri;function a(r,n){var i,a,c=o(this,t,r,n),u=o(this,e,r,n);return"M"+c.p0+s(c.r,c.p1,c.a1-c.a0)+(a=u,((i=c).a0==a.a0&&i.a1==a.a1?l(c.r,c.p1,c.r,c.p0):l(c.r,c.p1,u.r,u.p0)+s(u.r,u.p1,u.a1-u.a0)+l(u.r,u.p1,c.r,c.p0))+"Z")}function o(t,e,a,o){var s=e.call(t,a,o),l=r.call(t,s,o),c=n.call(t,s,o)-Et,u=i.call(t,s,o)-Et;return{r:l,a0:c,a1:u,p0:[l*Math.cos(c),l*Math.sin(c)],p1:[l*Math.cos(u),l*Math.sin(u)]}}function s(t,e,r){return"A"+t+","+t+" 0 "+ +(r>At)+",1 "+e}function l(t,e,r,n){return"Q 0,0 "+n}return a.radius=function(t){return arguments.length?(r=ce(t),a):r},a.source=function(e){return arguments.length?(t=ce(e),a):t},a.target=function(t){return arguments.length?(e=ce(t),a):e},a.startAngle=function(t){return arguments.length?(n=ce(t),a):n},a.endAngle=function(t){return arguments.length?(i=ce(t),a):i},a},t.svg.diagonal=function(){var t=ki,e=Ai,r=Si;function n(n,i){var a=t.call(this,n,i),o=e.call(this,n,i),s=(a.y+o.y)/2,l=[a,{x:a.x,y:s},{x:o.x,y:s},o];return"M"+(l=l.map(r))[0]+"C"+l[1]+" "+l[2]+" "+l[3]}return n.source=function(e){return arguments.length?(t=ce(e),n):t},n.target=function(t){return arguments.length?(e=ce(t),n):e},n.projection=function(t){return arguments.length?(r=t,n):r},n},t.svg.diagonal.radial=function(){var e=t.svg.diagonal(),r=Si,n=e.projection;return e.projection=function(t){return arguments.length?n(Ei(r=t)):r},e},t.svg.symbol=function(){var t=Ci,e=Li;function r(r,n){return(Ii.get(t.call(this,r,n))||Pi)(e.call(this,r,n))}return r.type=function(e){return arguments.length?(t=ce(e),r):t},r.size=function(t){return arguments.length?(e=ce(t),r):e},r};var Ii=t.map({circle:Pi,cross:function(t){var e=Math.sqrt(t/5)/2;return"M"+-3*e+","+-e+"H"+-e+"V"+-3*e+"H"+e+"V"+-e+"H"+3*e+"V"+e+"H"+e+"V"+3*e+"H"+-e+"V"+e+"H"+-3*e+"Z"},diamond:function(t){var e=Math.sqrt(t/(2*zi)),r=e*zi;return"M0,"+-e+"L"+r+",0 0,"+e+" "+-r+",0Z"},square:function(t){var e=Math.sqrt(t)/2;return"M"+-e+","+-e+"L"+e+","+-e+" "+e+","+e+" "+-e+","+e+"Z"},"triangle-down":function(t){var e=Math.sqrt(t/Oi),r=e*Oi/2;return"M0,"+r+"L"+e+","+-r+" "+-e+","+-r+"Z"},"triangle-up":function(t){var e=Math.sqrt(t/Oi),r=e*Oi/2;return"M0,"+-r+"L"+e+","+r+" "+-e+","+r+"Z"}});t.svg.symbolTypes=Ii.keys();var Oi=Math.sqrt(3),zi=Math.tan(30*Lt);Y.transition=function(t){for(var e,r,n=Bi||++Ui,i=qi(t),a=[],o=Ni||{time:Date.now(),ease:Er,delay:0,duration:250},s=-1,l=this.length;++s<l;){a.push(e=[]);for(var c=this[s],u=-1,f=c.length;++u<f;)(r=c[u])&&Gi(r,u,i,n,o),e.push(r)}return Fi(a,i,n)},Y.interrupt=function(t){return this.each(null==t?Di:Ri(qi(t)))};var Di=Ri(qi());function Ri(t){return function(){var e,r,n;(e=this[t])&&(n=e[r=e.active])&&(n.timer.c=null,n.timer.t=NaN,--e.count?delete e[r]:delete this[t],e.active+=.5,n.event&&n.event.interrupt.call(this,this.__data__,n.index))}}function Fi(t,e,r){return U(t,ji),t.namespace=e,t.id=r,t}var Bi,Ni,ji=[],Ui=0;function Vi(t,e,r,n){var i=t.id,a=t.namespace;return ut(t,"function"==typeof r?function(t,o,s){t[a][i].tween.set(e,n(r.call(t,t.__data__,o,s)))}:(r=n(r),function(t){t[a][i].tween.set(e,r)}))}function Hi(t){return null==t&&(t=""),function(){this.textContent=t}}function qi(t){return null==t?"__transition__":"__transition_"+t+"__"}function Gi(t,e,r,n,i){var a,o,s,l,c,u=t[r]||(t[r]={active:0,count:0}),f=u[n];function h(r){var i=u.active,h=u[i];for(var d in h&&(h.timer.c=null,h.timer.t=NaN,--u.count,delete u[i],h.event&&h.event.interrupt.call(t,t.__data__,h.index)),u)if(+d<n){var m=u[d];m.timer.c=null,m.timer.t=NaN,--u.count,delete u[d]}o.c=p,ve((function(){return o.c&&p(r||1)&&(o.c=null,o.t=NaN),1}),0,a),u.active=n,f.event&&f.event.start.call(t,t.__data__,e),c=[],f.tween.forEach((function(r,n){(n=n.call(t,t.__data__,e))&&c.push(n)})),l=f.ease,s=f.duration}function p(i){for(var a=i/s,o=l(a),h=c.length;h>0;)c[--h].call(t,o);if(a>=1)return f.event&&f.event.end.call(t,t.__data__,e),--u.count?delete u[n]:delete t[r],1}f||(a=i.time,o=ve((function(t){var e=f.delay;if(o.t=e+a,e<=t)return h(t-e);o.c=h}),0,a),f=u[n]={tween:new _,time:a,timer:o,delay:i.delay,duration:i.duration,ease:i.ease,index:e},i=null,++u.count)}ji.call=Y.call,ji.empty=Y.empty,ji.node=Y.node,ji.size=Y.size,t.transition=function(e,r){return e&&e.transition?Bi?e.transition(r):e:t.selection().transition(e)},t.transition.prototype=ji,ji.select=function(t){var e,r,n,i=this.id,a=this.namespace,o=[];t=W(t);for(var s=-1,l=this.length;++s<l;){o.push(e=[]);for(var c=this[s],u=-1,f=c.length;++u<f;)(n=c[u])&&(r=t.call(n,n.__data__,u,s))?("__data__"in n&&(r.__data__=n.__data__),Gi(r,u,a,i,n[a][i]),e.push(r)):e.push(null)}return Fi(o,a,i)},ji.selectAll=function(t){var e,r,n,i,a,o=this.id,s=this.namespace,l=[];t=X(t);for(var c=-1,u=this.length;++c<u;)for(var f=this[c],h=-1,p=f.length;++h<p;)if(n=f[h]){a=n[s][o],r=t.call(n,n.__data__,h,c),l.push(e=[]);for(var d=-1,m=r.length;++d<m;)(i=r[d])&&Gi(i,d,s,o,a),e.push(i)}return Fi(l,s,o)},ji.filter=function(t){var e,r,n=[];"function"!=typeof t&&(t=lt(t));for(var i=0,a=this.length;i<a;i++){n.push(e=[]);for(var o,s=0,l=(o=this[i]).length;s<l;s++)(r=o[s])&&t.call(r,r.__data__,s,i)&&e.push(r)}return Fi(n,this.namespace,this.id)},ji.tween=function(t,e){var r=this.id,n=this.namespace;return arguments.length<2?this.node()[n][r].tween.get(t):ut(this,null==e?function(e){e[n][r].tween.remove(t)}:function(i){i[n][r].tween.set(t,e)})},ji.attr=function(e,r){if(arguments.length<2){for(r in e)this.attr(r,e[r]);return this}var n="transform"==e?Nr:yr,i=t.ns.qualify(e);function a(){this.removeAttribute(i)}function o(){this.removeAttributeNS(i.space,i.local)}function s(t){return null==t?a:(t+="",function(){var e,r=this.getAttribute(i);return r!==t&&(e=n(r,t),function(t){this.setAttribute(i,e(t))})})}function l(t){return null==t?o:(t+="",function(){var e,r=this.getAttributeNS(i.space,i.local);return r!==t&&(e=n(r,t),function(t){this.setAttributeNS(i.space,i.local,e(t))})})}return Vi(this,"attr."+e,r,i.local?l:s)},ji.attrTween=function(e,r){var n=t.ns.qualify(e);return this.tween("attr."+e,n.local?function(t,e){var i=r.call(this,t,e,this.getAttributeNS(n.space,n.local));return i&&function(t){this.setAttributeNS(n.space,n.local,i(t))}}:function(t,e){var i=r.call(this,t,e,this.getAttribute(n));return i&&function(t){this.setAttribute(n,i(t))}})},ji.style=function(t,e,r){var n=arguments.length;if(n<3){if("string"!=typeof t){for(r in n<2&&(e=""),t)this.style(r,t[r],e);return this}r=""}function i(){this.style.removeProperty(t)}function a(e){return null==e?i:(e+="",function(){var n,i=o(this).getComputedStyle(this,null).getPropertyValue(t);return i!==e&&(n=yr(i,e),function(e){this.style.setProperty(t,n(e),r)})})}return Vi(this,"style."+t,e,a)},ji.styleTween=function(t,e,r){function n(n,i){var a=e.call(this,n,i,o(this).getComputedStyle(this,null).getPropertyValue(t));return a&&function(e){this.style.setProperty(t,a(e),r)}}return arguments.length<3&&(r=""),this.tween("style."+t,n)},ji.text=function(t){return Vi(this,"text",t,Hi)},ji.remove=function(){var t=this.namespace;return this.each("end.transition",(function(){var e;this[t].count<2&&(e=this.parentNode)&&e.removeChild(this)}))},ji.ease=function(e){var r=this.id,n=this.namespace;return arguments.length<1?this.node()[n][r].ease:("function"!=typeof e&&(e=t.ease.apply(t,arguments)),ut(this,(function(t){t[n][r].ease=e})))},ji.delay=function(t){var e=this.id,r=this.namespace;return arguments.length<1?this.node()[r][e].delay:ut(this,"function"==typeof t?function(n,i,a){n[r][e].delay=+t.call(n,n.__data__,i,a)}:(t=+t,function(n){n[r][e].delay=t}))},ji.duration=function(t){var e=this.id,r=this.namespace;return arguments.length<1?this.node()[r][e].duration:ut(this,"function"==typeof t?function(n,i,a){n[r][e].duration=Math.max(1,t.call(n,n.__data__,i,a))}:(t=Math.max(1,t),function(n){n[r][e].duration=t}))},ji.each=function(e,r){var n=this.id,i=this.namespace;if(arguments.length<2){var a=Ni,o=Bi;try{Bi=n,ut(this,(function(t,r,a){Ni=t[i][n],e.call(t,t.__data__,r,a)}))}finally{Ni=a,Bi=o}}else ut(this,(function(a){var o=a[i][n];(o.event||(o.event=t.dispatch("start","end","interrupt"))).on(e,r)}));return this},ji.transition=function(){for(var t,e,r,n=this.id,i=++Ui,a=this.namespace,o=[],s=0,l=this.length;s<l;s++){o.push(t=[]);for(var c,u=0,f=(c=this[s]).length;u<f;u++)(e=c[u])&&Gi(e,u,a,i,{time:(r=e[a][n]).time,ease:r.ease,delay:r.delay+r.duration,duration:r.duration}),t.push(e)}return Fi(o,a,i)},t.svg.axis=function(){var e,r=t.scale.linear(),i=Yi,a=6,o=6,s=3,l=[10],c=null;function u(n){n.each((function(){var n,u=t.select(this),f=this.__chart__||r,h=this.__chart__=r.copy(),p=null==c?h.ticks?h.ticks.apply(h,l):h.domain():c,d=null==e?h.tickFormat?h.tickFormat.apply(h,l):C:e,m=u.selectAll(".tick").data(p,h),g=m.enter().insert("g",".domain").attr("class","tick").style("opacity",kt),v=t.transition(m.exit()).style("opacity",kt).remove(),y=t.transition(m.order()).style("opacity",1),x=Math.max(a,0)+s,b=Dn(h),_=u.selectAll(".domain").data([0]),w=(_.enter().append("path").attr("class","domain"),t.transition(_));g.append("line"),g.append("text");var T,k,A,M,S=g.select("line"),E=y.select("line"),L=m.select("text").text(d),P=g.select("text"),I=y.select("text"),O="top"===i||"left"===i?-1:1;if("bottom"===i||"top"===i?(n=Xi,T="x",A="y",k="x2",M="y2",L.attr("dy",O<0?"0em":".71em").style("text-anchor","middle"),w.attr("d","M"+b[0]+","+O*o+"V0H"+b[1]+"V"+O*o)):(n=Zi,T="y",A="x",k="y2",M="x2",L.attr("dy",".32em").style("text-anchor",O<0?"end":"start"),w.attr("d","M"+O*o+","+b[0]+"H0V"+b[1]+"H"+O*o)),S.attr(M,O*a),P.attr(A,O*x),E.attr(k,0).attr(M,O*a),I.attr(T,0).attr(A,O*x),h.rangeBand){var z=h,D=z.rangeBand()/2;f=h=function(t){return z(t)+D}}else f.rangeBand?f=h:v.call(n,h,f);g.call(n,f,h),y.call(n,h,h)}))}return u.scale=function(t){return arguments.length?(r=t,u):r},u.orient=function(t){return arguments.length?(i=t in Wi?t+"":Yi,u):i},u.ticks=function(){return arguments.length?(l=n(arguments),u):l},u.tickValues=function(t){return arguments.length?(c=t,u):c},u.tickFormat=function(t){return arguments.length?(e=t,u):e},u.tickSize=function(t){var e=arguments.length;return e?(a=+t,o=+arguments[e-1],u):a},u.innerTickSize=function(t){return arguments.length?(a=+t,u):a},u.outerTickSize=function(t){return arguments.length?(o=+t,u):o},u.tickPadding=function(t){return arguments.length?(s=+t,u):s},u.tickSubdivide=function(){return arguments.length&&u},u};var Yi="bottom",Wi={top:1,right:1,bottom:1,left:1};function Xi(t,e,r){t.attr("transform",(function(t){var n=e(t);return"translate("+(isFinite(n)?n:r(t))+",0)"}))}function Zi(t,e,r){t.attr("transform",(function(t){var n=e(t);return"translate(0,"+(isFinite(n)?n:r(t))+")"}))}t.svg.brush=function(){var e,r,n=N(h,"brushstart","brush","brushend"),i=null,a=null,s=[0,0],l=[0,0],c=!0,u=!0,f=Ki[0];function h(e){e.each((function(){var e=t.select(this).style("pointer-events","all").style("-webkit-tap-highlight-color","rgba(0,0,0,0)").on("mousedown.brush",g).on("touchstart.brush",g),r=e.selectAll(".background").data([0]);r.enter().append("rect").attr("class","background").style("visibility","hidden").style("cursor","crosshair"),e.selectAll(".extent").data([0]).enter().append("rect").attr("class","extent").style("cursor","move");var n=e.selectAll(".resize").data(f,C);n.exit().remove(),n.enter().append("g").attr("class",(function(t){return"resize "+t})).style("cursor",(function(t){return Ji[t]})).append("rect").attr("x",(function(t){return/[ew]$/.test(t)?-3:null})).attr("y",(function(t){return/^[ns]/.test(t)?-3:null})).attr("width",6).attr("height",6).style("visibility","hidden"),n.style("display",h.empty()?"none":null);var o,s=t.transition(e),l=t.transition(r);i&&(o=Dn(i),l.attr("x",o[0]).attr("width",o[1]-o[0]),d(s)),a&&(o=Dn(a),l.attr("y",o[0]).attr("height",o[1]-o[0]),m(s)),p(s)}))}function p(t){t.selectAll(".resize").attr("transform",(function(t){return"translate("+s[+/e$/.test(t)]+","+l[+/^s/.test(t)]+")"}))}function d(t){t.select(".extent").attr("x",s[0]),t.selectAll(".extent,.n>rect,.s>rect").attr("width",s[1]-s[0])}function m(t){t.select(".extent").attr("y",l[0]),t.selectAll(".extent,.e>rect,.w>rect").attr("height",l[1]-l[0])}function g(){var f,g,v=this,y=t.select(t.event.target),x=n.of(v,arguments),b=t.select(v),_=y.datum(),w=!/^(n|s)$/.test(_)&&i,T=!/^(e|w)$/.test(_)&&a,k=y.classed("extent"),A=bt(v),M=t.mouse(v),S=t.select(o(v)).on("keydown.brush",C).on("keyup.brush",P);if(t.event.changedTouches?S.on("touchmove.brush",I).on("touchend.brush",z):S.on("mousemove.brush",I).on("mouseup.brush",z),b.interrupt().selectAll("*").interrupt(),k)M[0]=s[0]-M[0],M[1]=l[0]-M[1];else if(_){var E=+/w$/.test(_),L=+/^n/.test(_);g=[s[1-E]-M[0],l[1-L]-M[1]],M[0]=s[E],M[1]=l[L]}else t.event.altKey&&(f=M.slice());function C(){32==t.event.keyCode&&(k||(f=null,M[0]-=s[1],M[1]-=l[1],k=2),F())}function P(){32==t.event.keyCode&&2==k&&(M[0]+=s[1],M[1]+=l[1],k=0,F())}function I(){var e=t.mouse(v),r=!1;g&&(e[0]+=g[0],e[1]+=g[1]),k||(t.event.altKey?(f||(f=[(s[0]+s[1])/2,(l[0]+l[1])/2]),M[0]=s[+(e[0]<f[0])],M[1]=l[+(e[1]<f[1])]):f=null),w&&O(e,i,0)&&(d(b),r=!0),T&&O(e,a,1)&&(m(b),r=!0),r&&(p(b),x({type:"brush",mode:k?"move":"resize"}))}function O(t,n,i){var a,o,h=Dn(n),p=h[0],d=h[1],m=M[i],g=i?l:s,v=g[1]-g[0];if(k&&(p-=m,d-=v+m),a=(i?u:c)?Math.max(p,Math.min(d,t[i])):t[i],k?o=(a+=m)+v:(f&&(m=Math.max(p,Math.min(d,2*f[i]-a))),m<a?(o=a,a=m):o=m),g[0]!=a||g[1]!=o)return i?r=null:e=null,g[0]=a,g[1]=o,!0}function z(){I(),b.style("pointer-events","all").selectAll(".resize").style("display",h.empty()?"none":null),t.select("body").style("cursor",null),S.on("mousemove.brush",null).on("mouseup.brush",null).on("touchmove.brush",null).on("touchend.brush",null).on("keydown.brush",null).on("keyup.brush",null),A(),x({type:"brushend"})}b.style("pointer-events","none").selectAll(".resize").style("display",null),t.select("body").style("cursor",y.style("cursor")),x({type:"brushstart"}),I()}return h.event=function(i){i.each((function(){var i=n.of(this,arguments),a={x:s,y:l,i:e,j:r},o=this.__chart__||a;this.__chart__=a,Bi?t.select(this).transition().each("start.brush",(function(){e=o.i,r=o.j,s=o.x,l=o.y,i({type:"brushstart"})})).tween("brush:brush",(function(){var t=xr(s,a.x),n=xr(l,a.y);return e=r=null,function(e){s=a.x=t(e),l=a.y=n(e),i({type:"brush",mode:"resize"})}})).each("end.brush",(function(){e=a.i,r=a.j,i({type:"brush",mode:"resize"}),i({type:"brushend"})})):(i({type:"brushstart"}),i({type:"brush",mode:"resize"}),i({type:"brushend"}))}))},h.x=function(t){return arguments.length?(f=Ki[!(i=t)<<1|!a],h):i},h.y=function(t){return arguments.length?(f=Ki[!i<<1|!(a=t)],h):a},h.clamp=function(t){return arguments.length?(i&&a?(c=!!t[0],u=!!t[1]):i?c=!!t:a&&(u=!!t),h):i&&a?[c,u]:i?c:a?u:null},h.extent=function(t){var n,o,c,u,f;return arguments.length?(i&&(n=t[0],o=t[1],a&&(n=n[0],o=o[0]),e=[n,o],i.invert&&(n=i(n),o=i(o)),o<n&&(f=n,n=o,o=f),n==s[0]&&o==s[1]||(s=[n,o])),a&&(c=t[0],u=t[1],i&&(c=c[1],u=u[1]),r=[c,u],a.invert&&(c=a(c),u=a(u)),u<c&&(f=c,c=u,u=f),c==l[0]&&u==l[1]||(l=[c,u])),h):(i&&(e?(n=e[0],o=e[1]):(n=s[0],o=s[1],i.invert&&(n=i.invert(n),o=i.invert(o)),o<n&&(f=n,n=o,o=f))),a&&(r?(c=r[0],u=r[1]):(c=l[0],u=l[1],a.invert&&(c=a.invert(c),u=a.invert(u)),u<c&&(f=c,c=u,u=f))),i&&a?[[n,c],[o,u]]:i?[n,o]:a&&[c,u])},h.clear=function(){return h.empty()||(s=[0,0],l=[0,0],e=r=null),h},h.empty=function(){return!!i&&s[0]==s[1]||!!a&&l[0]==l[1]},t.rebind(h,n,"on")};var Ji={n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},Ki=[["n","e","s","w","nw","ne","se","sw"],["e","w"],["n","s"],[]];function Qi(t){return JSON.parse(t.responseText)}function $i(t){var e=i.createRange();return e.selectNode(i.body),e.createContextualFragment(t.responseText)}t.text=ue((function(t){return t.responseText})),t.json=function(t,e){return fe(t,"application/json",Qi,e)},t.html=function(t,e){return fe(t,"text/html",$i,e)},t.xml=ue((function(t){return t.responseXML})),"object"==typeof e&&e.exports?e.exports=t:this.d3=t}).apply(self)},{}],59:[function(t,e,r){"use strict";e.exports=t("./quad")},{"./quad":60}],60:[function(t,e,r){"use strict";var n=t("binary-search-bounds"),i=t("clamp"),a=t("parse-rect"),o=t("array-bounds"),s=t("pick-by-alias"),l=t("defined"),c=t("flatten-vertex-data"),u=t("is-obj"),f=t("dtype"),h=t("math-log2");function p(t,e){for(var r=e[0],n=e[1],a=1/(e[2]-r),o=1/(e[3]-n),s=new Array(t.length),l=0,c=t.length/2;l<c;l++)s[2*l]=i((t[2*l]-r)*a,0,1),s[2*l+1]=i((t[2*l+1]-n)*o,0,1);return s}e.exports=function(t,e){e||(e={}),t=c(t,"float64"),e=s(e,{bounds:"range bounds dataBox databox",maxDepth:"depth maxDepth maxdepth level maxLevel maxlevel levels",dtype:"type dtype format out dst output destination"});var r=l(e.maxDepth,255),i=l(e.bounds,o(t,2));i[0]===i[2]&&i[2]++,i[1]===i[3]&&i[3]++;var d,m=p(t,i),g=t.length>>>1;e.dtype||(e.dtype="array"),"string"==typeof e.dtype?d=new(f(e.dtype))(g):e.dtype&&(d=e.dtype,Array.isArray(d)&&(d.length=g));for(var v=0;v<g;++v)d[v]=v;var y=[],x=[],b=[],_=[];!function t(e,n,i,a,o,s){if(!a.length)return null;var l=y[o]||(y[o]=[]),c=b[o]||(b[o]=[]),u=x[o]||(x[o]=[]),f=l.length;if(++o>r||s>1073741824){for(var h=0;h<a.length;h++)l.push(a[h]),c.push(s),u.push(null,null,null,null);return f}if(l.push(a[0]),c.push(s),a.length<=1)return u.push(null,null,null,null),f;for(var p=.5*i,d=e+p,g=n+p,v=[],_=[],w=[],T=[],k=1,A=a.length;k<A;k++){var M=a[k],S=m[2*M],E=m[2*M+1];S<d?E<g?v.push(M):_.push(M):E<g?w.push(M):T.push(M)}return s<<=2,u.push(t(e,n,p,v,o,s),t(e,g,p,_,o,s+1),t(d,n,p,w,o,s+2),t(d,g,p,T,o,s+3)),f}(0,0,1,d,0,1);for(var w=0,T=0;T<y.length;T++){var k=y[T];if(d.set)d.set(k,w);else for(var A=0,M=k.length;A<M;A++)d[A+w]=k[A];var S=w+y[T].length;_[T]=[w,S],w=S}return d.range=function(){var e,r=[],n=arguments.length;for(;n--;)r[n]=arguments[n];if(u(r[r.length-1])){var o=r.pop();r.length||null==o.x&&null==o.l&&null==o.left||(r=[o],e={}),e=s(o,{level:"level maxLevel",d:"d diam diameter r radius px pxSize pixel pixelSize maxD size minSize",lod:"lod details ranges offsets"})}else e={};r.length||(r=i);var c=a.apply(void 0,r),f=[Math.min(c.x,c.x+c.width),Math.min(c.y,c.y+c.height),Math.max(c.x,c.x+c.width),Math.max(c.y,c.y+c.height)],d=f[0],m=f[1],g=f[2],v=f[3],b=p([d,m,g,v],i),_=b[0],w=b[1],T=b[2],k=b[3],A=l(e.level,y.length);if(null!=e.d){var M;"number"==typeof e.d?M=[e.d,e.d]:e.d.length&&(M=e.d),A=Math.min(Math.max(Math.ceil(-h(Math.abs(M[0])/(i[2]-i[0]))),Math.ceil(-h(Math.abs(M[1])/(i[3]-i[1])))),A)}if(A=Math.min(A,y.length),e.lod)return E(_,w,T,k,A);var S=[];function L(e,r,n,i,a,o){if(null!==a&&null!==o&&!(_>e+n||w>r+n||T<e||k<r||i>=A||a===o)){var s=y[i];void 0===o&&(o=s.length);for(var l=a;l<o;l++){var c=s[l],u=t[2*c],f=t[2*c+1];u>=d&&u<=g&&f>=m&&f<=v&&S.push(c)}var h=x[i],p=h[4*a+0],b=h[4*a+1],M=h[4*a+2],E=h[4*a+3],P=C(h,a+1),I=.5*n,O=i+1;L(e,r,I,O,p,b||M||E||P),L(e,r+I,I,O,b,M||E||P),L(e+I,r,I,O,M,E||P),L(e+I,r+I,I,O,E,P)}}function C(t,e){for(var r=null,n=0;null===r;)if(r=t[4*e+n],++n>t.length)return null;return r}return L(0,0,1,0,0,1),S},d;function E(t,e,r,i,a){for(var o=[],s=0;s<a;s++){var l=b[s],c=_[s][0],u=L(t,e,s),f=L(r,i,s),h=n.ge(l,u),p=n.gt(l,f,h,l.length-1);o[s]=[h+c,p+c]}return o}function L(t,e,r){for(var n=1,i=.5,a=.5,o=.5,s=0;s<r;s++)n<<=2,n+=t<i?e<a?0:1:e<a?2:3,o*=.5,i+=t<i?-o:o,a+=e<a?-o:o;return n}}},{"array-bounds":71,"binary-search-bounds":80,clamp:86,defined:124,dtype:127,"flatten-vertex-data":191,"is-obj":235,"math-log2":240,"parse-rect":249,"pick-by-alias":253}],61:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("@turf/meta");function i(t){var e=0;if(t&&t.length>0){e+=Math.abs(a(t[0]));for(var r=1;r<t.length;r++)e-=Math.abs(a(t[r]))}return e}function a(t){var e,r,n,i,a,s,l=0,c=t.length;if(c>2){for(s=0;s<c;s++)s===c-2?(n=c-2,i=c-1,a=0):s===c-1?(n=c-1,i=0,a=1):(n=s,i=s+1,a=s+2),e=t[n],r=t[i],l+=(o(t[a][0])-o(e[0]))*Math.sin(o(r[1]));l=6378137*l*6378137/2}return l}function o(t){return t*Math.PI/180}r.default=function(t){return n.geomReduce(t,(function(t,e){return t+function(t){var e,r=0;switch(t.type){case"Polygon":return i(t.coordinates);case"MultiPolygon":for(e=0;e<t.coordinates.length;e++)r+=i(t.coordinates[e]);return r;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}(e)}),0)}},{"@turf/meta":63}],62:[function(t,e,r){"use strict";function n(t,e,r){void 0===r&&(r={});var n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=e||{},n.geometry=t,n}function i(t,e,r){if(void 0===r&&(r={}),!t)throw new Error("coordinates is required");if(!Array.isArray(t))throw new Error("coordinates must be an Array");if(t.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!d(t[0])||!d(t[1]))throw new Error("coordinates must contain numbers");return n({type:"Point",coordinates:t},e,r)}function a(t,e,r){void 0===r&&(r={});for(var i=0,a=t;i<a.length;i++){var o=a[i];if(o.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");for(var s=0;s<o[o.length-1].length;s++)if(o[o.length-1][s]!==o[0][s])throw new Error("First and last Position are not equivalent.")}return n({type:"Polygon",coordinates:t},e,r)}function o(t,e,r){if(void 0===r&&(r={}),t.length<2)throw new Error("coordinates must be an array of two or more positions");return n({type:"LineString",coordinates:t},e,r)}function s(t,e){void 0===e&&(e={});var r={type:"FeatureCollection"};return e.id&&(r.id=e.id),e.bbox&&(r.bbox=e.bbox),r.features=t,r}function l(t,e,r){return void 0===r&&(r={}),n({type:"MultiLineString",coordinates:t},e,r)}function c(t,e,r){return void 0===r&&(r={}),n({type:"MultiPoint",coordinates:t},e,r)}function u(t,e,r){return void 0===r&&(r={}),n({type:"MultiPolygon",coordinates:t},e,r)}function f(t,e){void 0===e&&(e="kilometers");var n=r.factors[e];if(!n)throw new Error(e+" units is invalid");return t*n}function h(t,e){void 0===e&&(e="kilometers");var n=r.factors[e];if(!n)throw new Error(e+" units is invalid");return t/n}function p(t){return 180*(t%(2*Math.PI))/Math.PI}function d(t){return!isNaN(t)&&null!==t&&!Array.isArray(t)}Object.defineProperty(r,"__esModule",{value:!0}),r.earthRadius=6371008.8,r.factors={centimeters:100*r.earthRadius,centimetres:100*r.earthRadius,degrees:r.earthRadius/111325,feet:3.28084*r.earthRadius,inches:39.37*r.earthRadius,kilometers:r.earthRadius/1e3,kilometres:r.earthRadius/1e3,meters:r.earthRadius,metres:r.earthRadius,miles:r.earthRadius/1609.344,millimeters:1e3*r.earthRadius,millimetres:1e3*r.earthRadius,nauticalmiles:r.earthRadius/1852,radians:1,yards:1.0936*r.earthRadius},r.unitsFactors={centimeters:100,centimetres:100,degrees:1/111325,feet:3.28084,inches:39.37,kilometers:.001,kilometres:.001,meters:1,metres:1,miles:1/1609.344,millimeters:1e3,millimetres:1e3,nauticalmiles:1/1852,radians:1/r.earthRadius,yards:1.0936133},r.areaFactors={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,hectares:1e-4,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,millimeters:1e6,millimetres:1e6,yards:1.195990046},r.feature=n,r.geometry=function(t,e,r){switch(void 0===r&&(r={}),t){case"Point":return i(e).geometry;case"LineString":return o(e).geometry;case"Polygon":return a(e).geometry;case"MultiPoint":return c(e).geometry;case"MultiLineString":return l(e).geometry;case"MultiPolygon":return u(e).geometry;default:throw new Error(t+" is invalid")}},r.point=i,r.points=function(t,e,r){return void 0===r&&(r={}),s(t.map((function(t){return i(t,e)})),r)},r.polygon=a,r.polygons=function(t,e,r){return void 0===r&&(r={}),s(t.map((function(t){return a(t,e)})),r)},r.lineString=o,r.lineStrings=function(t,e,r){return void 0===r&&(r={}),s(t.map((function(t){return o(t,e)})),r)},r.featureCollection=s,r.multiLineString=l,r.multiPoint=c,r.multiPolygon=u,r.geometryCollection=function(t,e,r){return void 0===r&&(r={}),n({type:"GeometryCollection",geometries:t},e,r)},r.round=function(t,e){if(void 0===e&&(e=0),e&&!(e>=0))throw new Error("precision must be a positive number");var r=Math.pow(10,e||0);return Math.round(t*r)/r},r.radiansToLength=f,r.lengthToRadians=h,r.lengthToDegrees=function(t,e){return p(h(t,e))},r.bearingToAzimuth=function(t){var e=t%360;return e<0&&(e+=360),e},r.radiansToDegrees=p,r.degreesToRadians=function(t){return t%360*Math.PI/180},r.convertLength=function(t,e,r){if(void 0===e&&(e="kilometers"),void 0===r&&(r="kilometers"),!(t>=0))throw new Error("length must be a positive number");return f(h(t,e),r)},r.convertArea=function(t,e,n){if(void 0===e&&(e="meters"),void 0===n&&(n="kilometers"),!(t>=0))throw new Error("area must be a positive number");var i=r.areaFactors[e];if(!i)throw new Error("invalid original units");var a=r.areaFactors[n];if(!a)throw new Error("invalid final units");return t/i*a},r.isNumber=d,r.isObject=function(t){return!!t&&t.constructor===Object},r.validateBBox=function(t){if(!t)throw new Error("bbox is required");if(!Array.isArray(t))throw new Error("bbox must be an Array");if(4!==t.length&&6!==t.length)throw new Error("bbox must be an Array of 4 or 6 numbers");t.forEach((function(t){if(!d(t))throw new Error("bbox must only contain numbers")}))},r.validateId=function(t){if(!t)throw new Error("id is required");if(-1===["string","number"].indexOf(typeof t))throw new Error("id must be a number or a string")}},{}],63:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("@turf/helpers");function i(t,e,r){if(null!==t)for(var n,a,o,s,l,c,u,f,h=0,p=0,d=t.type,m="FeatureCollection"===d,g="Feature"===d,v=m?t.features.length:1,y=0;y<v;y++){l=(f=!!(u=m?t.features[y].geometry:g?t.geometry:t)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var x=0;x<l;x++){var b=0,_=0;if(null!==(s=f?u.geometries[x]:u)){c=s.coordinates;var w=s.type;switch(h=!r||"Polygon"!==w&&"MultiPolygon"!==w?0:1,w){case null:break;case"Point":if(!1===e(c,p,y,b,_))return!1;p++,b++;break;case"LineString":case"MultiPoint":for(n=0;n<c.length;n++){if(!1===e(c[n],p,y,b,_))return!1;p++,"MultiPoint"===w&&b++}"LineString"===w&&b++;break;case"Polygon":case"MultiLineString":for(n=0;n<c.length;n++){for(a=0;a<c[n].length-h;a++){if(!1===e(c[n][a],p,y,b,_))return!1;p++}"MultiLineString"===w&&b++,"Polygon"===w&&_++}"Polygon"===w&&b++;break;case"MultiPolygon":for(n=0;n<c.length;n++){for(_=0,a=0;a<c[n].length;a++){for(o=0;o<c[n][a].length-h;o++){if(!1===e(c[n][a][o],p,y,b,_))return!1;p++}_++}b++}break;case"GeometryCollection":for(n=0;n<s.geometries.length;n++)if(!1===i(s.geometries[n],e,r))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function a(t,e){var r;switch(t.type){case"FeatureCollection":for(r=0;r<t.features.length&&!1!==e(t.features[r].properties,r);r++);break;case"Feature":e(t.properties,0)}}function o(t,e){if("Feature"===t.type)e(t,0);else if("FeatureCollection"===t.type)for(var r=0;r<t.features.length&&!1!==e(t.features[r],r);r++);}function s(t,e){var r,n,i,a,o,s,l,c,u,f,h=0,p="FeatureCollection"===t.type,d="Feature"===t.type,m=p?t.features.length:1;for(r=0;r<m;r++){for(s=p?t.features[r].geometry:d?t.geometry:t,c=p?t.features[r].properties:d?t.properties:{},u=p?t.features[r].bbox:d?t.bbox:void 0,f=p?t.features[r].id:d?t.id:void 0,o=(l=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,i=0;i<o;i++)if(null!==(a=l?s.geometries[i]:s))switch(a.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===e(a,h,c,u,f))return!1;break;case"GeometryCollection":for(n=0;n<a.geometries.length;n++)if(!1===e(a.geometries[n],h,c,u,f))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===e(null,h,c,u,f))return!1;h++}}function l(t,e){s(t,(function(t,r,i,a,o){var s,l=null===t?null:t.type;switch(l){case null:case"Point":case"LineString":case"Polygon":return!1!==e(n.feature(t,i,{bbox:a,id:o}),r,0)&&void 0}switch(l){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var c=0;c<t.coordinates.length;c++){var u={type:s,coordinates:t.coordinates[c]};if(!1===e(n.feature(u,i),r,c))return!1}}))}function c(t,e){l(t,(function(t,r,a){var o=0;if(t.geometry){var s=t.geometry.type;if("Point"!==s&&"MultiPoint"!==s){var l,c=0,u=0,f=0;return!1!==i(t,(function(i,s,h,p,d){if(void 0===l||r>c||p>u||d>f)return l=i,c=r,u=p,f=d,void(o=0);var m=n.lineString([l,i],t.properties);if(!1===e(m,r,a,d,o))return!1;o++,l=i}))&&void 0}}}))}function u(t,e){if(!t)throw new Error("geojson is required");l(t,(function(t,r,i){if(null!==t.geometry){var a=t.geometry.type,o=t.geometry.coordinates;switch(a){case"LineString":if(!1===e(t,r,i,0,0))return!1;break;case"Polygon":for(var s=0;s<o.length;s++)if(!1===e(n.lineString(o[s],t.properties),r,i,s))return!1}}}))}r.coordEach=i,r.coordReduce=function(t,e,r,n){var a=r;return i(t,(function(t,n,i,o,s){a=0===n&&void 0===r?t:e(a,t,n,i,o,s)}),n),a},r.propEach=a,r.propReduce=function(t,e,r){var n=r;return a(t,(function(t,i){n=0===i&&void 0===r?t:e(n,t,i)})),n},r.featureEach=o,r.featureReduce=function(t,e,r){var n=r;return o(t,(function(t,i){n=0===i&&void 0===r?t:e(n,t,i)})),n},r.coordAll=function(t){var e=[];return i(t,(function(t){e.push(t)})),e},r.geomEach=s,r.geomReduce=function(t,e,r){var n=r;return s(t,(function(t,i,a,o,s){n=0===i&&void 0===r?t:e(n,t,i,a,o,s)})),n},r.flattenEach=l,r.flattenReduce=function(t,e,r){var n=r;return l(t,(function(t,i,a){n=0===i&&0===a&&void 0===r?t:e(n,t,i,a)})),n},r.segmentEach=c,r.segmentReduce=function(t,e,r){var n=r,i=!1;return c(t,(function(t,a,o,s,l){n=!1===i&&void 0===r?t:e(n,t,a,o,s,l),i=!0})),n},r.lineEach=u,r.lineReduce=function(t,e,r){var n=r;return u(t,(function(t,i,a,o){n=0===i&&void 0===r?t:e(n,t,i,a,o)})),n},r.findSegment=function(t,e){if(e=e||{},!n.isObject(e))throw new Error("options is invalid");var r,i=e.featureIndex||0,a=e.multiFeatureIndex||0,o=e.geometryIndex||0,s=e.segmentIndex||0,l=e.properties;switch(t.type){case"FeatureCollection":i<0&&(i=t.features.length+i),l=l||t.features[i].properties,r=t.features[i].geometry;break;case"Feature":l=l||t.properties,r=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":r=t;break;default:throw new Error("geojson is invalid")}if(null===r)return null;var c=r.coordinates;switch(r.type){case"Point":case"MultiPoint":return null;case"LineString":return s<0&&(s=c.length+s-1),n.lineString([c[s],c[s+1]],l,e);case"Polygon":return o<0&&(o=c.length+o),s<0&&(s=c[o].length+s-1),n.lineString([c[o][s],c[o][s+1]],l,e);case"MultiLineString":return a<0&&(a=c.length+a),s<0&&(s=c[a].length+s-1),n.lineString([c[a][s],c[a][s+1]],l,e);case"MultiPolygon":return a<0&&(a=c.length+a),o<0&&(o=c[a].length+o),s<0&&(s=c[a][o].length-s-1),n.lineString([c[a][o][s],c[a][o][s+1]],l,e)}throw new Error("geojson is invalid")},r.findPoint=function(t,e){if(e=e||{},!n.isObject(e))throw new Error("options is invalid");var r,i=e.featureIndex||0,a=e.multiFeatureIndex||0,o=e.geometryIndex||0,s=e.coordIndex||0,l=e.properties;switch(t.type){case"FeatureCollection":i<0&&(i=t.features.length+i),l=l||t.features[i].properties,r=t.features[i].geometry;break;case"Feature":l=l||t.properties,r=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":r=t;break;default:throw new Error("geojson is invalid")}if(null===r)return null;var c=r.coordinates;switch(r.type){case"Point":return n.point(c,l,e);case"MultiPoint":return a<0&&(a=c.length+a),n.point(c[a],l,e);case"LineString":return s<0&&(s=c.length+s),n.point(c[s],l,e);case"Polygon":return o<0&&(o=c.length+o),s<0&&(s=c[o].length+s),n.point(c[o][s],l,e);case"MultiLineString":return a<0&&(a=c.length+a),s<0&&(s=c[a].length+s),n.point(c[a][s],l,e);case"MultiPolygon":return a<0&&(a=c.length+a),o<0&&(o=c[a].length+o),s<0&&(s=c[a][o].length-s),n.point(c[a][o][s],l,e)}throw new Error("geojson is invalid")}},{"@turf/helpers":62}],64:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("@turf/meta");function i(t){var e=[1/0,1/0,-1/0,-1/0];return n.coordEach(t,(function(t){e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]<t[0]&&(e[2]=t[0]),e[3]<t[1]&&(e[3]=t[1])})),e}i.default=i,r.default=i},{"@turf/meta":66}],65:[function(t,e,r){arguments[4][62][0].apply(r,arguments)},{dup:62}],66:[function(t,e,r){arguments[4][63][0].apply(r,arguments)},{"@turf/helpers":65,dup:63}],67:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("@turf/meta"),i=t("@turf/helpers");r.default=function(t,e){void 0===e&&(e={});var r=0,a=0,o=0;return n.coordEach(t,(function(t){r+=t[0],a+=t[1],o++})),i.point([r/o,a/o],e.properties)}},{"@turf/helpers":68,"@turf/meta":69}],68:[function(t,e,r){"use strict";function n(t,e,r){void 0===r&&(r={});var n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=e||{},n.geometry=t,n}function i(t,e,r){return void 0===r&&(r={}),n({type:"Point",coordinates:t},e,r)}function a(t,e,r){void 0===r&&(r={});for(var i=0,a=t;i<a.length;i++){var o=a[i];if(o.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");for(var s=0;s<o[o.length-1].length;s++)if(o[o.length-1][s]!==o[0][s])throw new Error("First and last Position are not equivalent.")}return n({type:"Polygon",coordinates:t},e,r)}function o(t,e,r){if(void 0===r&&(r={}),t.length<2)throw new Error("coordinates must be an array of two or more positions");return n({type:"LineString",coordinates:t},e,r)}function s(t,e){void 0===e&&(e={});var r={type:"FeatureCollection"};return e.id&&(r.id=e.id),e.bbox&&(r.bbox=e.bbox),r.features=t,r}function l(t,e,r){return void 0===r&&(r={}),n({type:"MultiLineString",coordinates:t},e,r)}function c(t,e,r){return void 0===r&&(r={}),n({type:"MultiPoint",coordinates:t},e,r)}function u(t,e,r){return void 0===r&&(r={}),n({type:"MultiPolygon",coordinates:t},e,r)}function f(t,e){void 0===e&&(e="kilometers");var n=r.factors[e];if(!n)throw new Error(e+" units is invalid");return t*n}function h(t,e){void 0===e&&(e="kilometers");var n=r.factors[e];if(!n)throw new Error(e+" units is invalid");return t/n}function p(t){return 180*(t%(2*Math.PI))/Math.PI}function d(t){return!isNaN(t)&&null!==t&&!Array.isArray(t)&&!/^\s*$/.test(t)}Object.defineProperty(r,"__esModule",{value:!0}),r.earthRadius=6371008.8,r.factors={centimeters:100*r.earthRadius,centimetres:100*r.earthRadius,degrees:r.earthRadius/111325,feet:3.28084*r.earthRadius,inches:39.37*r.earthRadius,kilometers:r.earthRadius/1e3,kilometres:r.earthRadius/1e3,meters:r.earthRadius,metres:r.earthRadius,miles:r.earthRadius/1609.344,millimeters:1e3*r.earthRadius,millimetres:1e3*r.earthRadius,nauticalmiles:r.earthRadius/1852,radians:1,yards:r.earthRadius/1.0936},r.unitsFactors={centimeters:100,centimetres:100,degrees:1/111325,feet:3.28084,inches:39.37,kilometers:.001,kilometres:.001,meters:1,metres:1,miles:1/1609.344,millimeters:1e3,millimetres:1e3,nauticalmiles:1/1852,radians:1/r.earthRadius,yards:1/1.0936},r.areaFactors={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,millimeters:1e6,millimetres:1e6,yards:1.195990046},r.feature=n,r.geometry=function(t,e,r){switch(void 0===r&&(r={}),t){case"Point":return i(e).geometry;case"LineString":return o(e).geometry;case"Polygon":return a(e).geometry;case"MultiPoint":return c(e).geometry;case"MultiLineString":return l(e).geometry;case"MultiPolygon":return u(e).geometry;default:throw new Error(t+" is invalid")}},r.point=i,r.points=function(t,e,r){return void 0===r&&(r={}),s(t.map((function(t){return i(t,e)})),r)},r.polygon=a,r.polygons=function(t,e,r){return void 0===r&&(r={}),s(t.map((function(t){return a(t,e)})),r)},r.lineString=o,r.lineStrings=function(t,e,r){return void 0===r&&(r={}),s(t.map((function(t){return o(t,e)})),r)},r.featureCollection=s,r.multiLineString=l,r.multiPoint=c,r.multiPolygon=u,r.geometryCollection=function(t,e,r){return void 0===r&&(r={}),n({type:"GeometryCollection",geometries:t},e,r)},r.round=function(t,e){if(void 0===e&&(e=0),e&&!(e>=0))throw new Error("precision must be a positive number");var r=Math.pow(10,e||0);return Math.round(t*r)/r},r.radiansToLength=f,r.lengthToRadians=h,r.lengthToDegrees=function(t,e){return p(h(t,e))},r.bearingToAzimuth=function(t){var e=t%360;return e<0&&(e+=360),e},r.radiansToDegrees=p,r.degreesToRadians=function(t){return t%360*Math.PI/180},r.convertLength=function(t,e,r){if(void 0===e&&(e="kilometers"),void 0===r&&(r="kilometers"),!(t>=0))throw new Error("length must be a positive number");return f(h(t,e),r)},r.convertArea=function(t,e,n){if(void 0===e&&(e="meters"),void 0===n&&(n="kilometers"),!(t>=0))throw new Error("area must be a positive number");var i=r.areaFactors[e];if(!i)throw new Error("invalid original units");var a=r.areaFactors[n];if(!a)throw new Error("invalid final units");return t/i*a},r.isNumber=d,r.isObject=function(t){return!!t&&t.constructor===Object},r.validateBBox=function(t){if(!t)throw new Error("bbox is required");if(!Array.isArray(t))throw new Error("bbox must be an Array");if(4!==t.length&&6!==t.length)throw new Error("bbox must be an Array of 4 or 6 numbers");t.forEach((function(t){if(!d(t))throw new Error("bbox must only contain numbers")}))},r.validateId=function(t){if(!t)throw new Error("id is required");if(-1===["string","number"].indexOf(typeof t))throw new Error("id must be a number or a string")},r.radians2degrees=function(){throw new Error("method has been renamed to `radiansToDegrees`")},r.degrees2radians=function(){throw new Error("method has been renamed to `degreesToRadians`")},r.distanceToDegrees=function(){throw new Error("method has been renamed to `lengthToDegrees`")},r.distanceToRadians=function(){throw new Error("method has been renamed to `lengthToRadians`")},r.radiansToDistance=function(){throw new Error("method has been renamed to `radiansToLength`")},r.bearingToAngle=function(){throw new Error("method has been renamed to `bearingToAzimuth`")},r.convertDistance=function(){throw new Error("method has been renamed to `convertLength`")}},{}],69:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("@turf/helpers");function i(t,e,r){if(null!==t)for(var n,a,o,s,l,c,u,f,h=0,p=0,d=t.type,m="FeatureCollection"===d,g="Feature"===d,v=m?t.features.length:1,y=0;y<v;y++){l=(f=!!(u=m?t.features[y].geometry:g?t.geometry:t)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var x=0;x<l;x++){var b=0,_=0;if(null!==(s=f?u.geometries[x]:u)){c=s.coordinates;var w=s.type;switch(h=!r||"Polygon"!==w&&"MultiPolygon"!==w?0:1,w){case null:break;case"Point":if(!1===e(c,p,y,b,_))return!1;p++,b++;break;case"LineString":case"MultiPoint":for(n=0;n<c.length;n++){if(!1===e(c[n],p,y,b,_))return!1;p++,"MultiPoint"===w&&b++}"LineString"===w&&b++;break;case"Polygon":case"MultiLineString":for(n=0;n<c.length;n++){for(a=0;a<c[n].length-h;a++){if(!1===e(c[n][a],p,y,b,_))return!1;p++}"MultiLineString"===w&&b++,"Polygon"===w&&_++}"Polygon"===w&&b++;break;case"MultiPolygon":for(n=0;n<c.length;n++){for(_=0,a=0;a<c[n].length;a++){for(o=0;o<c[n][a].length-h;o++){if(!1===e(c[n][a][o],p,y,b,_))return!1;p++}_++}b++}break;case"GeometryCollection":for(n=0;n<s.geometries.length;n++)if(!1===i(s.geometries[n],e,r))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function a(t,e){var r;switch(t.type){case"FeatureCollection":for(r=0;r<t.features.length&&!1!==e(t.features[r].properties,r);r++);break;case"Feature":e(t.properties,0)}}function o(t,e){if("Feature"===t.type)e(t,0);else if("FeatureCollection"===t.type)for(var r=0;r<t.features.length&&!1!==e(t.features[r],r);r++);}function s(t,e){var r,n,i,a,o,s,l,c,u,f,h=0,p="FeatureCollection"===t.type,d="Feature"===t.type,m=p?t.features.length:1;for(r=0;r<m;r++){for(s=p?t.features[r].geometry:d?t.geometry:t,c=p?t.features[r].properties:d?t.properties:{},u=p?t.features[r].bbox:d?t.bbox:void 0,f=p?t.features[r].id:d?t.id:void 0,o=(l=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,i=0;i<o;i++)if(null!==(a=l?s.geometries[i]:s))switch(a.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===e(a,h,c,u,f))return!1;break;case"GeometryCollection":for(n=0;n<a.geometries.length;n++)if(!1===e(a.geometries[n],h,c,u,f))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===e(null,h,c,u,f))return!1;h++}}function l(t,e){s(t,(function(t,r,i,a,o){var s,l=null===t?null:t.type;switch(l){case null:case"Point":case"LineString":case"Polygon":return!1!==e(n.feature(t,i,{bbox:a,id:o}),r,0)&&void 0}switch(l){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var c=0;c<t.coordinates.length;c++){var u={type:s,coordinates:t.coordinates[c]};if(!1===e(n.feature(u,i),r,c))return!1}}))}function c(t,e){l(t,(function(t,r,a){var o=0;if(t.geometry){var s=t.geometry.type;if("Point"!==s&&"MultiPoint"!==s){var l,c=0,u=0,f=0;return!1!==i(t,(function(i,s,h,p,d){if(void 0===l||r>c||p>u||d>f)return l=i,c=r,u=p,f=d,void(o=0);var m=n.lineString([l,i],t.properties);if(!1===e(m,r,a,d,o))return!1;o++,l=i}))&&void 0}}}))}function u(t,e){if(!t)throw new Error("geojson is required");l(t,(function(t,r,i){if(null!==t.geometry){var a=t.geometry.type,o=t.geometry.coordinates;switch(a){case"LineString":if(!1===e(t,r,i,0,0))return!1;break;case"Polygon":for(var s=0;s<o.length;s++)if(!1===e(n.lineString(o[s],t.properties),r,i,s))return!1}}}))}r.coordEach=i,r.coordReduce=function(t,e,r,n){var a=r;return i(t,(function(t,n,i,o,s){a=0===n&&void 0===r?t:e(a,t,n,i,o,s)}),n),a},r.propEach=a,r.propReduce=function(t,e,r){var n=r;return a(t,(function(t,i){n=0===i&&void 0===r?t:e(n,t,i)})),n},r.featureEach=o,r.featureReduce=function(t,e,r){var n=r;return o(t,(function(t,i){n=0===i&&void 0===r?t:e(n,t,i)})),n},r.coordAll=function(t){var e=[];return i(t,(function(t){e.push(t)})),e},r.geomEach=s,r.geomReduce=function(t,e,r){var n=r;return s(t,(function(t,i,a,o,s){n=0===i&&void 0===r?t:e(n,t,i,a,o,s)})),n},r.flattenEach=l,r.flattenReduce=function(t,e,r){var n=r;return l(t,(function(t,i,a){n=0===i&&0===a&&void 0===r?t:e(n,t,i,a)})),n},r.segmentEach=c,r.segmentReduce=function(t,e,r){var n=r,i=!1;return c(t,(function(t,a,o,s,l){n=!1===i&&void 0===r?t:e(n,t,a,o,s,l),i=!0})),n},r.lineEach=u,r.lineReduce=function(t,e,r){var n=r;return u(t,(function(t,i,a,o){n=0===i&&void 0===r?t:e(n,t,i,a,o)})),n},r.findSegment=function(t,e){if(e=e||{},!n.isObject(e))throw new Error("options is invalid");var r,i=e.featureIndex||0,a=e.multiFeatureIndex||0,o=e.geometryIndex||0,s=e.segmentIndex||0,l=e.properties;switch(t.type){case"FeatureCollection":i<0&&(i=t.features.length+i),l=l||t.features[i].properties,r=t.features[i].geometry;break;case"Feature":l=l||t.properties,r=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":r=t;break;default:throw new Error("geojson is invalid")}if(null===r)return null;var c=r.coordinates;switch(r.type){case"Point":case"MultiPoint":return null;case"LineString":return s<0&&(s=c.length+s-1),n.lineString([c[s],c[s+1]],l,e);case"Polygon":return o<0&&(o=c.length+o),s<0&&(s=c[o].length+s-1),n.lineString([c[o][s],c[o][s+1]],l,e);case"MultiLineString":return a<0&&(a=c.length+a),s<0&&(s=c[a].length+s-1),n.lineString([c[a][s],c[a][s+1]],l,e);case"MultiPolygon":return a<0&&(a=c.length+a),o<0&&(o=c[a].length+o),s<0&&(s=c[a][o].length-s-1),n.lineString([c[a][o][s],c[a][o][s+1]],l,e)}throw new Error("geojson is invalid")},r.findPoint=function(t,e){if(e=e||{},!n.isObject(e))throw new Error("options is invalid");var r,i=e.featureIndex||0,a=e.multiFeatureIndex||0,o=e.geometryIndex||0,s=e.coordIndex||0,l=e.properties;switch(t.type){case"FeatureCollection":i<0&&(i=t.features.length+i),l=l||t.features[i].properties,r=t.features[i].geometry;break;case"Feature":l=l||t.properties,r=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":r=t;break;default:throw new Error("geojson is invalid")}if(null===r)return null;var c=r.coordinates;switch(r.type){case"Point":return n.point(c,l,e);case"MultiPoint":return a<0&&(a=c.length+a),n.point(c[a],l,e);case"LineString":return s<0&&(s=c.length+s),n.point(c[s],l,e);case"Polygon":return o<0&&(o=c.length+o),s<0&&(s=c[o].length+s),n.point(c[o][s],l,e);case"MultiLineString":return a<0&&(a=c.length+a),s<0&&(s=c[a].length+s),n.point(c[a][s],l,e);case"MultiPolygon":return a<0&&(a=c.length+a),o<0&&(o=c[a].length+o),s<0&&(s=c[a][o].length-s),n.point(c[a][o][s],l,e)}throw new Error("geojson is invalid")}},{"@turf/helpers":68}],70:[function(t,e,r){e.exports=function(t){var e=0,r=0,n=0,i=0;return t.map((function(t){var a=(t=t.slice())[0],o=a.toUpperCase();if(a!=o)switch(t[0]=o,a){case"a":t[6]+=n,t[7]+=i;break;case"v":t[1]+=i;break;case"h":t[1]+=n;break;default:for(var s=1;s<t.length;)t[s++]+=n,t[s++]+=i}switch(o){case"Z":n=e,i=r;break;case"H":n=t[1];break;case"V":i=t[1];break;case"M":n=e=t[1],i=r=t[2];break;default:n=t[t.length-2],i=t[t.length-1]}return t}))}},{}],71:[function(t,e,r){"use strict";e.exports=function(t,e){if(!t||null==t.length)throw Error("Argument should be an array");e=null==e?1:Math.floor(e);for(var r=Array(2*e),n=0;n<e;n++){for(var i=-1/0,a=1/0,o=n,s=t.length;o<s;o+=e)t[o]>i&&(i=t[o]),t[o]<a&&(a=t[o]);r[n]=a,r[e+n]=i}return r}},{}],72:[function(t,e,r){"use strict";e.exports=function(t,e,r){if("function"==typeof Array.prototype.findIndex)return t.findIndex(e,r);if("function"!=typeof e)throw new TypeError("predicate must be a function");var n=Object(t),i=n.length;if(0===i)return-1;for(var a=0;a<i;a++)if(e.call(r,n[a],a,n))return a;return-1}},{}],73:[function(t,e,r){"use strict";var n=t("array-bounds");e.exports=function(t,e,r){if(!t||null==t.length)throw Error("Argument should be an array");null==e&&(e=1);null==r&&(r=n(t,e));for(var i=0;i<e;i++){var a=r[e+i],o=r[i],s=i,l=t.length;if(a===1/0&&o===-1/0)for(s=i;s<l;s+=e)t[s]=t[s]===a?1:t[s]===o?0:.5;else if(a===1/0)for(s=i;s<l;s+=e)t[s]=t[s]===a?1:0;else if(o===-1/0)for(s=i;s<l;s+=e)t[s]=t[s]===o?0:1;else{var c=a-o;for(s=i;s<l;s+=e)isNaN(t[s])||(t[s]=0===c?.5:(t[s]-o)/c)}}return t}},{"array-bounds":71}],74:[function(t,e,r){e.exports=function(t,e){var r="number"==typeof t,n="number"==typeof e;r&&!n?(e=t,t=0):r||n||(t=0,e=0);var i=(e|=0)-(t|=0);if(i<0)throw new Error("array length must be positive");for(var a=new Array(i),o=0,s=t;o<i;o++,s++)a[o]=s;return a}},{}],75:[function(t,e,r){(function(r){(function(){"use strict";var n=t("object-assign");
/*!
 * The buffer module from node.js, for the browser.
 *
 * @author   Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
 * @license  MIT
 */function i(t,e){if(t===e)return 0;for(var r=t.length,n=e.length,i=0,a=Math.min(r,n);i<a;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0}function a(t){return r.Buffer&&"function"==typeof r.Buffer.isBuffer?r.Buffer.isBuffer(t):!(null==t||!t._isBuffer)}var o=t("util/"),s=Object.prototype.hasOwnProperty,l=Array.prototype.slice,c="foo"===function(){}.name;function u(t){return Object.prototype.toString.call(t)}function f(t){return!a(t)&&("function"==typeof r.ArrayBuffer&&("function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):!!t&&(t instanceof DataView||!!(t.buffer&&t.buffer instanceof ArrayBuffer))))}var h=e.exports=y,p=/\s*function\s+([^\(\s]*)\s*/;function d(t){if(o.isFunction(t)){if(c)return t.name;var e=t.toString().match(p);return e&&e[1]}}function m(t,e){return"string"==typeof t?t.length<e?t:t.slice(0,e):t}function g(t){if(c||!o.isFunction(t))return o.inspect(t);var e=d(t);return"[Function"+(e?": "+e:"")+"]"}function v(t,e,r,n,i){throw new h.AssertionError({message:r,actual:t,expected:e,operator:n,stackStartFunction:i})}function y(t,e){t||v(t,!0,e,"==",h.ok)}function x(t,e,r,n){if(t===e)return!0;if(a(t)&&a(e))return 0===i(t,e);if(o.isDate(t)&&o.isDate(e))return t.getTime()===e.getTime();if(o.isRegExp(t)&&o.isRegExp(e))return t.source===e.source&&t.global===e.global&&t.multiline===e.multiline&&t.lastIndex===e.lastIndex&&t.ignoreCase===e.ignoreCase;if(null!==t&&"object"==typeof t||null!==e&&"object"==typeof e){if(f(t)&&f(e)&&u(t)===u(e)&&!(t instanceof Float32Array||t instanceof Float64Array))return 0===i(new Uint8Array(t.buffer),new Uint8Array(e.buffer));if(a(t)!==a(e))return!1;var s=(n=n||{actual:[],expected:[]}).actual.indexOf(t);return-1!==s&&s===n.expected.indexOf(e)||(n.actual.push(t),n.expected.push(e),function(t,e,r,n){if(null==t||null==e)return!1;if(o.isPrimitive(t)||o.isPrimitive(e))return t===e;if(r&&Object.getPrototypeOf(t)!==Object.getPrototypeOf(e))return!1;var i=b(t),a=b(e);if(i&&!a||!i&&a)return!1;if(i)return t=l.call(t),e=l.call(e),x(t,e,r);var s,c,u=T(t),f=T(e);if(u.length!==f.length)return!1;for(u.sort(),f.sort(),c=u.length-1;c>=0;c--)if(u[c]!==f[c])return!1;for(c=u.length-1;c>=0;c--)if(s=u[c],!x(t[s],e[s],r,n))return!1;return!0}(t,e,r,n))}return r?t===e:t==e}function b(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function _(t,e){if(!t||!e)return!1;if("[object RegExp]"==Object.prototype.toString.call(e))return e.test(t);try{if(t instanceof e)return!0}catch(t){}return!Error.isPrototypeOf(e)&&!0===e.call({},t)}function w(t,e,r,n){var i;if("function"!=typeof e)throw new TypeError('"block" argument must be a function');"string"==typeof r&&(n=r,r=null),i=function(t){var e;try{t()}catch(t){e=t}return e}(e),n=(r&&r.name?" ("+r.name+").":".")+(n?" "+n:"."),t&&!i&&v(i,r,"Missing expected exception"+n);var a="string"==typeof n,s=!t&&i&&!r;if((!t&&o.isError(i)&&a&&_(i,r)||s)&&v(i,r,"Got unwanted exception"+n),t&&i&&r&&!_(i,r)||!t&&i)throw i}h.AssertionError=function(t){this.name="AssertionError",this.actual=t.actual,this.expected=t.expected,this.operator=t.operator,t.message?(this.message=t.message,this.generatedMessage=!1):(this.message=function(t){return m(g(t.actual),128)+" "+t.operator+" "+m(g(t.expected),128)}(this),this.generatedMessage=!0);var e=t.stackStartFunction||v;if(Error.captureStackTrace)Error.captureStackTrace(this,e);else{var r=new Error;if(r.stack){var n=r.stack,i=d(e),a=n.indexOf("\n"+i);if(a>=0){var o=n.indexOf("\n",a+1);n=n.substring(o+1)}this.stack=n}}},o.inherits(h.AssertionError,Error),h.fail=v,h.ok=y,h.equal=function(t,e,r){t!=e&&v(t,e,r,"==",h.equal)},h.notEqual=function(t,e,r){t==e&&v(t,e,r,"!=",h.notEqual)},h.deepEqual=function(t,e,r){x(t,e,!1)||v(t,e,r,"deepEqual",h.deepEqual)},h.deepStrictEqual=function(t,e,r){x(t,e,!0)||v(t,e,r,"deepStrictEqual",h.deepStrictEqual)},h.notDeepEqual=function(t,e,r){x(t,e,!1)&&v(t,e,r,"notDeepEqual",h.notDeepEqual)},h.notDeepStrictEqual=function t(e,r,n){x(e,r,!0)&&v(e,r,n,"notDeepStrictEqual",t)},h.strictEqual=function(t,e,r){t!==e&&v(t,e,r,"===",h.strictEqual)},h.notStrictEqual=function(t,e,r){t===e&&v(t,e,r,"!==",h.notStrictEqual)},h.throws=function(t,e,r){w(!0,t,e,r)},h.doesNotThrow=function(t,e,r){w(!1,t,e,r)},h.ifError=function(t){if(t)throw t},h.strict=n((function t(e,r){e||v(e,!0,r,"==",t)}),h,{equal:h.strictEqual,deepEqual:h.deepStrictEqual,notEqual:h.notStrictEqual,notDeepEqual:h.notDeepStrictEqual}),h.strict.strict=h.strict;var T=Object.keys||function(t){var e=[];for(var r in t)s.call(t,r)&&e.push(r);return e}}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"object-assign":247,"util/":78}],76:[function(t,e,r){"function"==typeof Object.create?e.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}},{}],77:[function(t,e,r){e.exports=function(t){return t&&"object"==typeof t&&"function"==typeof t.copy&&"function"==typeof t.fill&&"function"==typeof t.readUInt8}},{}],78:[function(t,e,r){(function(e,n){(function(){var i=/%[sdj%]/g;r.format=function(t){if(!v(t)){for(var e=[],r=0;r<arguments.length;r++)e.push(s(arguments[r]));return e.join(" ")}r=1;for(var n=arguments,a=n.length,o=String(t).replace(i,(function(t){if("%%"===t)return"%";if(r>=a)return t;switch(t){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(t){return"[Circular]"}default:return t}})),l=n[r];r<a;l=n[++r])m(l)||!b(l)?o+=" "+l:o+=" "+s(l);return o},r.deprecate=function(t,i){if(y(n.process))return function(){return r.deprecate(t,i).apply(this,arguments)};if(!0===e.noDeprecation)return t;var a=!1;return function(){if(!a){if(e.throwDeprecation)throw new Error(i);e.traceDeprecation?console.trace(i):console.error(i),a=!0}return t.apply(this,arguments)}};var a,o={};function s(t,e){var n={seen:[],stylize:c};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),d(e)?n.showHidden=e:e&&r._extend(n,e),y(n.showHidden)&&(n.showHidden=!1),y(n.depth)&&(n.depth=2),y(n.colors)&&(n.colors=!1),y(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=l),u(n,t,n.depth)}function l(t,e){var r=s.styles[e];return r?"\x1b["+s.colors[r][0]+"m"+t+"\x1b["+s.colors[r][1]+"m":t}function c(t,e){return t}function u(t,e,n){if(t.customInspect&&e&&T(e.inspect)&&e.inspect!==r.inspect&&(!e.constructor||e.constructor.prototype!==e)){var i=e.inspect(n,t);return v(i)||(i=u(t,i,n)),i}var a=function(t,e){if(y(e))return t.stylize("undefined","undefined");if(v(e)){var r="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(r,"string")}if(g(e))return t.stylize(""+e,"number");if(d(e))return t.stylize(""+e,"boolean");if(m(e))return t.stylize("null","null")}(t,e);if(a)return a;var o=Object.keys(e),s=function(t){var e={};return t.forEach((function(t,r){e[t]=!0})),e}(o);if(t.showHidden&&(o=Object.getOwnPropertyNames(e)),w(e)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return f(e);if(0===o.length){if(T(e)){var l=e.name?": "+e.name:"";return t.stylize("[Function"+l+"]","special")}if(x(e))return t.stylize(RegExp.prototype.toString.call(e),"regexp");if(_(e))return t.stylize(Date.prototype.toString.call(e),"date");if(w(e))return f(e)}var c,b="",k=!1,A=["{","}"];(p(e)&&(k=!0,A=["[","]"]),T(e))&&(b=" [Function"+(e.name?": "+e.name:"")+"]");return x(e)&&(b=" "+RegExp.prototype.toString.call(e)),_(e)&&(b=" "+Date.prototype.toUTCString.call(e)),w(e)&&(b=" "+f(e)),0!==o.length||k&&0!=e.length?n<0?x(e)?t.stylize(RegExp.prototype.toString.call(e),"regexp"):t.stylize("[Object]","special"):(t.seen.push(e),c=k?function(t,e,r,n,i){for(var a=[],o=0,s=e.length;o<s;++o)E(e,String(o))?a.push(h(t,e,r,n,String(o),!0)):a.push("");return i.forEach((function(i){i.match(/^\d+$/)||a.push(h(t,e,r,n,i,!0))})),a}(t,e,n,s,o):o.map((function(r){return h(t,e,n,s,r,k)})),t.seen.pop(),function(t,e,r){if(t.reduce((function(t,e){return e.indexOf("\n")>=0&&0,t+e.replace(/\u001b\[\d\d?m/g,"").length+1}),0)>60)return r[0]+(""===e?"":e+"\n ")+" "+t.join(",\n  ")+" "+r[1];return r[0]+e+" "+t.join(", ")+" "+r[1]}(c,b,A)):A[0]+b+A[1]}function f(t){return"["+Error.prototype.toString.call(t)+"]"}function h(t,e,r,n,i,a){var o,s,l;if((l=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]}).get?s=l.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):l.set&&(s=t.stylize("[Setter]","special")),E(n,i)||(o="["+i+"]"),s||(t.seen.indexOf(l.value)<0?(s=m(r)?u(t,l.value,null):u(t,l.value,r-1)).indexOf("\n")>-1&&(s=a?s.split("\n").map((function(t){return"  "+t})).join("\n").substr(2):"\n"+s.split("\n").map((function(t){return"   "+t})).join("\n")):s=t.stylize("[Circular]","special")),y(o)){if(a&&i.match(/^\d+$/))return s;(o=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(o=o.substr(1,o.length-2),o=t.stylize(o,"name")):(o=o.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),o=t.stylize(o,"string"))}return o+": "+s}function p(t){return Array.isArray(t)}function d(t){return"boolean"==typeof t}function m(t){return null===t}function g(t){return"number"==typeof t}function v(t){return"string"==typeof t}function y(t){return void 0===t}function x(t){return b(t)&&"[object RegExp]"===k(t)}function b(t){return"object"==typeof t&&null!==t}function _(t){return b(t)&&"[object Date]"===k(t)}function w(t){return b(t)&&("[object Error]"===k(t)||t instanceof Error)}function T(t){return"function"==typeof t}function k(t){return Object.prototype.toString.call(t)}function A(t){return t<10?"0"+t.toString(10):t.toString(10)}r.debuglog=function(t){if(y(a)&&(a=e.env.NODE_DEBUG||""),t=t.toUpperCase(),!o[t])if(new RegExp("\\b"+t+"\\b","i").test(a)){var n=e.pid;o[t]=function(){var e=r.format.apply(r,arguments);console.error("%s %d: %s",t,n,e)}}else o[t]=function(){};return o[t]},r.inspect=s,s.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},s.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=p,r.isBoolean=d,r.isNull=m,r.isNullOrUndefined=function(t){return null==t},r.isNumber=g,r.isString=v,r.isSymbol=function(t){return"symbol"==typeof t},r.isUndefined=y,r.isRegExp=x,r.isObject=b,r.isDate=_,r.isError=w,r.isFunction=T,r.isPrimitive=function(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t},r.isBuffer=t("./support/isBuffer");var M=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function S(){var t=new Date,e=[A(t.getHours()),A(t.getMinutes()),A(t.getSeconds())].join(":");return[t.getDate(),M[t.getMonth()],e].join(" ")}function E(t,e){return Object.prototype.hasOwnProperty.call(t,e)}r.log=function(){console.log("%s - %s",S(),r.format.apply(r,arguments))},r.inherits=t("inherits"),r._extend=function(t,e){if(!e||!b(e))return t;for(var r=Object.keys(e),n=r.length;n--;)t[r[n]]=e[r[n]];return t}}).call(this)}).call(this,t("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":77,_process:277,inherits:76}],79:[function(t,e,r){"use strict";r.byteLength=function(t){var e=c(t),r=e[0],n=e[1];return 3*(r+n)/4-n},r.toByteArray=function(t){var e,r,n=c(t),o=n[0],s=n[1],l=new a(function(t,e,r){return 3*(e+r)/4-r}(0,o,s)),u=0,f=s>0?o-4:o;for(r=0;r<f;r+=4)e=i[t.charCodeAt(r)]<<18|i[t.charCodeAt(r+1)]<<12|i[t.charCodeAt(r+2)]<<6|i[t.charCodeAt(r+3)],l[u++]=e>>16&255,l[u++]=e>>8&255,l[u++]=255&e;2===s&&(e=i[t.charCodeAt(r)]<<2|i[t.charCodeAt(r+1)]>>4,l[u++]=255&e);1===s&&(e=i[t.charCodeAt(r)]<<10|i[t.charCodeAt(r+1)]<<4|i[t.charCodeAt(r+2)]>>2,l[u++]=e>>8&255,l[u++]=255&e);return l},r.fromByteArray=function(t){for(var e,r=t.length,i=r%3,a=[],o=0,s=r-i;o<s;o+=16383)a.push(u(t,o,o+16383>s?s:o+16383));1===i?(e=t[r-1],a.push(n[e>>2]+n[e<<4&63]+"==")):2===i&&(e=(t[r-2]<<8)+t[r-1],a.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return a.join("")};for(var n=[],i=[],a="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0,l=o.length;s<l;++s)n[s]=o[s],i[o.charCodeAt(s)]=s;function c(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function u(t,e,r){for(var i,a,o=[],s=e;s<r;s+=3)i=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(255&t[s+2]),o.push(n[(a=i)>>18&63]+n[a>>12&63]+n[a>>6&63]+n[63&a]);return o.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},{}],80:[function(t,e,r){"use strict";function n(t,e,r,n,i){for(var a=i+1;n<=i;){var o=n+i>>>1,s=t[o];(void 0!==r?r(s,e):s-e)>=0?(a=o,i=o-1):n=o+1}return a}function i(t,e,r,n,i){for(var a=i+1;n<=i;){var o=n+i>>>1,s=t[o];(void 0!==r?r(s,e):s-e)>0?(a=o,i=o-1):n=o+1}return a}function a(t,e,r,n,i){for(var a=n-1;n<=i;){var o=n+i>>>1,s=t[o];(void 0!==r?r(s,e):s-e)<0?(a=o,n=o+1):i=o-1}return a}function o(t,e,r,n,i){for(var a=n-1;n<=i;){var o=n+i>>>1,s=t[o];(void 0!==r?r(s,e):s-e)<=0?(a=o,n=o+1):i=o-1}return a}function s(t,e,r,n,i){for(;n<=i;){var a=n+i>>>1,o=t[a],s=void 0!==r?r(o,e):o-e;if(0===s)return a;s<=0?n=a+1:i=a-1}return-1}function l(t,e,r,n,i,a){return"function"==typeof r?a(t,e,r,void 0===n?0:0|n,void 0===i?t.length-1:0|i):a(t,e,void 0,void 0===r?0:0|r,void 0===n?t.length-1:0|n)}e.exports={ge:function(t,e,r,i,a){return l(t,e,r,i,a,n)},gt:function(t,e,r,n,a){return l(t,e,r,n,a,i)},lt:function(t,e,r,n,i){return l(t,e,r,n,i,a)},le:function(t,e,r,n,i){return l(t,e,r,n,i,o)},eq:function(t,e,r,n,i){return l(t,e,r,n,i,s)}}},{}],81:[function(t,e,r){"use strict";function n(t){var e=32;return(t&=-t)&&e--,65535&t&&(e-=16),16711935&t&&(e-=8),252645135&t&&(e-=4),858993459&t&&(e-=2),1431655765&t&&(e-=1),e}r.INT_BITS=32,r.INT_MAX=2147483647,r.INT_MIN=-1<<31,r.sign=function(t){return(t>0)-(t<0)},r.abs=function(t){var e=t>>31;return(t^e)-e},r.min=function(t,e){return e^(t^e)&-(t<e)},r.max=function(t,e){return t^(t^e)&-(t<e)},r.isPow2=function(t){return!(t&t-1||!t)},r.log2=function(t){var e,r;return e=(t>65535)<<4,e|=r=((t>>>=e)>255)<<3,e|=r=((t>>>=r)>15)<<2,(e|=r=((t>>>=r)>3)<<1)|(t>>>=r)>>1},r.log10=function(t){return t>=1e9?9:t>=1e8?8:t>=1e7?7:t>=1e6?6:t>=1e5?5:t>=1e4?4:t>=1e3?3:t>=100?2:t>=10?1:0},r.popCount=function(t){return 16843009*((t=(858993459&(t-=t>>>1&1431655765))+(t>>>2&858993459))+(t>>>4)&252645135)>>>24},r.countTrailingZeros=n,r.nextPow2=function(t){return t+=0===t,--t,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,(t|=t>>>16)+1},r.prevPow2=function(t){return t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,(t|=t>>>16)-(t>>>1)},r.parity=function(t){return t^=t>>>16,t^=t>>>8,t^=t>>>4,27030>>>(t&=15)&1};var i=new Array(256);!function(t){for(var e=0;e<256;++e){var r=e,n=e,i=7;for(r>>>=1;r;r>>>=1)n<<=1,n|=1&r,--i;t[e]=n<<i&255}}(i),r.reverse=function(t){return i[255&t]<<24|i[t>>>8&255]<<16|i[t>>>16&255]<<8|i[t>>>24&255]},r.interleave2=function(t,e){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t&=65535)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e&=65535)|e<<8))|e<<4))|e<<2))|e<<1))<<1},r.deinterleave2=function(t,e){return(t=65535&((t=16711935&((t=252645135&((t=858993459&((t=t>>>e&1431655765)|t>>>1))|t>>>2))|t>>>4))|t>>>16))<<16>>16},r.interleave3=function(t,e,r){return t=1227133513&((t=3272356035&((t=251719695&((t=4278190335&((t&=1023)|t<<16))|t<<8))|t<<4))|t<<2),(t|=(e=1227133513&((e=3272356035&((e=251719695&((e=4278190335&((e&=1023)|e<<16))|e<<8))|e<<4))|e<<2))<<1)|(r=1227133513&((r=3272356035&((r=251719695&((r=4278190335&((r&=1023)|r<<16))|r<<8))|r<<4))|r<<2))<<2},r.deinterleave3=function(t,e){return(t=1023&((t=4278190335&((t=251719695&((t=3272356035&((t=t>>>e&1227133513)|t>>>2))|t>>>4))|t>>>8))|t>>>16))<<22>>22},r.nextCombination=function(t){var e=t|t-1;return e+1|(~e&-~e)-1>>>n(t)+1}},{}],82:[function(t,e,r){"use strict";var n=t("clamp");e.exports=function(t,e){e||(e={});var r,o,s,l,c,u,f,h,p,d,m,g=null==e.cutoff?.25:e.cutoff,v=null==e.radius?8:e.radius,y=e.channel||0;if(ArrayBuffer.isView(t)||Array.isArray(t)){if(!e.width||!e.height)throw Error("For raw data width and height should be provided by options");r=e.width,o=e.height,l=t,u=e.stride?e.stride:Math.floor(t.length/r/o)}else window.HTMLCanvasElement&&t instanceof window.HTMLCanvasElement?(f=(h=t).getContext("2d"),r=h.width,o=h.height,p=f.getImageData(0,0,r,o),l=p.data,u=4):window.CanvasRenderingContext2D&&t instanceof window.CanvasRenderingContext2D?(h=t.canvas,f=t,r=h.width,o=h.height,p=f.getImageData(0,0,r,o),l=p.data,u=4):window.ImageData&&t instanceof window.ImageData&&(p=t,r=t.width,o=t.height,l=p.data,u=4);if(s=Math.max(r,o),window.Uint8ClampedArray&&l instanceof window.Uint8ClampedArray||window.Uint8Array&&l instanceof window.Uint8Array)for(c=l,l=Array(r*o),d=0,m=c.length;d<m;d++)l[d]=c[d*u+y]/255;else if(1!==u)throw Error("Raw data can have only 1 value per pixel");var x=Array(r*o),b=Array(r*o),_=Array(s),w=Array(s),T=Array(s+1),k=Array(s);for(d=0,m=r*o;d<m;d++){var A=l[d];x[d]=1===A?0:0===A?i:Math.pow(Math.max(0,.5-A),2),b[d]=1===A?i:0===A?0:Math.pow(Math.max(0,A-.5),2)}a(x,r,o,_,w,k,T),a(b,r,o,_,w,k,T);var M=window.Float32Array?new Float32Array(r*o):new Array(r*o);for(d=0,m=r*o;d<m;d++)M[d]=n(1-((x[d]-b[d])/v+g),0,1);return M};var i=1e20;function a(t,e,r,n,i,a,s){for(var l=0;l<e;l++){for(var c=0;c<r;c++)n[c]=t[c*e+l];for(o(n,i,a,s,r),c=0;c<r;c++)t[c*e+l]=i[c]}for(c=0;c<r;c++){for(l=0;l<e;l++)n[l]=t[c*e+l];for(o(n,i,a,s,e),l=0;l<e;l++)t[c*e+l]=Math.sqrt(i[l])}}function o(t,e,r,n,a){r[0]=0,n[0]=-i,n[1]=+i;for(var o=1,s=0;o<a;o++){for(var l=(t[o]+o*o-(t[r[s]]+r[s]*r[s]))/(2*o-2*r[s]);l<=n[s];)s--,l=(t[o]+o*o-(t[r[s]]+r[s]*r[s]))/(2*o-2*r[s]);r[++s]=o,n[s]=l,n[s+1]=+i}for(o=0,s=0;o<a;o++){for(;n[s+1]<o;)s++;e[o]=(o-r[s])*(o-r[s])+t[r[s]]}}},{clamp:86}],83:[function(t,e,r){},{}],84:[function(t,e,r){"use strict";var n,i="object"==typeof Reflect?Reflect:null,a=i&&"function"==typeof i.apply?i.apply:function(t,e,r){return Function.prototype.apply.call(t,e,r)};n=i&&"function"==typeof i.ownKeys?i.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var o=Number.isNaN||function(t){return t!=t};function s(){s.init.call(this)}e.exports=s,e.exports.once=function(t,e){return new Promise((function(r,n){function i(){void 0!==a&&t.removeListener("error",a),r([].slice.call(arguments))}var a;"error"!==e&&(a=function(r){t.removeListener(e,i),n(r)},t.once("error",a)),t.once(e,i)}))},s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var l=10;function c(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function u(t){return void 0===t._maxListeners?s.defaultMaxListeners:t._maxListeners}function f(t,e,r,n){var i,a,o,s;if(c(r),void 0===(a=t._events)?(a=t._events=Object.create(null),t._eventsCount=0):(void 0!==a.newListener&&(t.emit("newListener",e,r.listener?r.listener:r),a=t._events),o=a[e]),void 0===o)o=a[e]=r,++t._eventsCount;else if("function"==typeof o?o=a[e]=n?[r,o]:[o,r]:n?o.unshift(r):o.push(r),(i=u(t))>0&&o.length>i&&!o.warned){o.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=t,l.type=e,l.count=o.length,s=l,console&&console.warn&&console.warn(s)}return t}function h(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=h.bind(n);return i.listener=r,n.wrapFn=i,i}function d(t,e,r){var n=t._events;if(void 0===n)return[];var i=n[e];return void 0===i?[]:"function"==typeof i?r?[i.listener||i]:[i]:r?function(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}(i):g(i,i.length)}function m(t){var e=this._events;if(void 0!==e){var r=e[t];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function g(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return l},set:function(t){if("number"!=typeof t||t<0||o(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");l=t}}),s.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||o(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(t){for(var e=[],r=1;r<arguments.length;r++)e.push(arguments[r]);var n="error"===t,i=this._events;if(void 0!==i)n=n&&void 0===i.error;else if(!n)return!1;if(n){var o;if(e.length>0&&(o=e[0]),o instanceof Error)throw o;var s=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw s.context=o,s}var l=i[t];if(void 0===l)return!1;if("function"==typeof l)a(l,this,e);else{var c=l.length,u=g(l,c);for(r=0;r<c;++r)a(u[r],this,e)}return!0},s.prototype.addListener=function(t,e){return f(this,t,e,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(t,e){return f(this,t,e,!0)},s.prototype.once=function(t,e){return c(e),this.on(t,p(this,t,e)),this},s.prototype.prependOnceListener=function(t,e){return c(e),this.prependListener(t,p(this,t,e)),this},s.prototype.removeListener=function(t,e){var r,n,i,a,o;if(c(e),void 0===(n=this._events))return this;if(void 0===(r=n[t]))return this;if(r===e||r.listener===e)0==--this._eventsCount?this._events=Object.create(null):(delete n[t],n.removeListener&&this.emit("removeListener",t,r.listener||e));else if("function"!=typeof r){for(i=-1,a=r.length-1;a>=0;a--)if(r[a]===e||r[a].listener===e){o=r[a].listener,i=a;break}if(i<0)return this;0===i?r.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(r,i),1===r.length&&(n[t]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",t,o||e)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(t){var e,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[t]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[t]),this;if(0===arguments.length){var i,a=Object.keys(r);for(n=0;n<a.length;++n)"removeListener"!==(i=a[n])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(e=r[t]))this.removeListener(t,e);else if(void 0!==e)for(n=e.length-1;n>=0;n--)this.removeListener(t,e[n]);return this},s.prototype.listeners=function(t){return d(this,t,!0)},s.prototype.rawListeners=function(t){return d(this,t,!1)},s.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):m.call(t,e)},s.prototype.listenerCount=m,s.prototype.eventNames=function(){return this._eventsCount>0?n(this._events):[]}},{}],85:[function(t,e,r){(function(e){(function(){
/*!
 * The buffer module from node.js, for the browser.
 *
 * @author   Feross Aboukhadijeh <https://feross.org>
 * @license  MIT
 */
"use strict";var e=t("base64-js"),n=t("ieee754");r.Buffer=a,r.SlowBuffer=function(t){+t!=t&&(t=0);return a.alloc(+t)},r.INSPECT_MAX_BYTES=50;function i(t){if(t>2147483647)throw new RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return e.__proto__=a.prototype,e}function a(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return l(t)}return o(t,e,r)}function o(t,e,r){if("string"==typeof t)return function(t,e){"string"==typeof e&&""!==e||(e="utf8");if(!a.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var r=0|f(t,e),n=i(r),o=n.write(t,e);o!==r&&(n=n.slice(0,o));return n}(t,e);if(ArrayBuffer.isView(t))return c(t);if(null==t)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(B(t,ArrayBuffer)||t&&B(t.buffer,ArrayBuffer))return function(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r);return n.__proto__=a.prototype,n}(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return a.from(n,e,r);var o=function(t){if(a.isBuffer(t)){var e=0|u(t.length),r=i(e);return 0===r.length||t.copy(r,0,0,e),r}if(void 0!==t.length)return"number"!=typeof t.length||N(t.length)?i(0):c(t);if("Buffer"===t.type&&Array.isArray(t.data))return c(t.data)}(t);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return a.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function s(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function l(t){return s(t),i(t<0?0:0|u(t))}function c(t){for(var e=t.length<0?0:0|u(t.length),r=i(e),n=0;n<e;n+=1)r[n]=255&t[n];return r}function u(t){if(t>=2147483647)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+2147483647..toString(16)+" bytes");return 0|t}function f(t,e){if(a.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||B(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var i=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return D(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return R(t).length;default:if(i)return n?-1:D(t).length;e=(""+e).toLowerCase(),i=!0}}function h(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return M(this,e,r);case"utf8":case"utf-8":return T(this,e,r);case"ascii":return k(this,e,r);case"latin1":case"binary":return A(this,e,r);case"base64":return w(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function p(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function d(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),N(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=a.from(e,n)),a.isBuffer(e))return 0===e.length?-1:m(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):m(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,r,n,i){var a,o=1,s=t.length,l=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;o=2,s/=2,l/=2,r/=2}function c(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(i){var u=-1;for(a=r;a<s;a++)if(c(t,a)===c(e,-1===u?0:a-u)){if(-1===u&&(u=a),a-u+1===l)return u*o}else-1!==u&&(a-=a-u),u=-1}else for(r+l>s&&(r=s-l),a=r;a>=0;a--){for(var f=!0,h=0;h<l;h++)if(c(t,a+h)!==c(e,h)){f=!1;break}if(f)return a}return-1}function g(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;var a=e.length;n>a/2&&(n=a/2);for(var o=0;o<n;++o){var s=parseInt(e.substr(2*o,2),16);if(N(s))return o;t[r+o]=s}return o}function v(t,e,r,n){return F(D(e,t.length-r),t,r,n)}function y(t,e,r,n){return F(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function x(t,e,r,n){return y(t,e,r,n)}function b(t,e,r,n){return F(R(e),t,r,n)}function _(t,e,r,n){return F(function(t,e){for(var r,n,i,a=[],o=0;o<t.length&&!((e-=2)<0);++o)r=t.charCodeAt(o),n=r>>8,i=r%256,a.push(i),a.push(n);return a}(e,t.length-r),t,r,n)}function w(t,r,n){return 0===r&&n===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(r,n))}function T(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var a,o,s,l,c=t[i],u=null,f=c>239?4:c>223?3:c>191?2:1;if(i+f<=r)switch(f){case 1:c<128&&(u=c);break;case 2:128==(192&(a=t[i+1]))&&(l=(31&c)<<6|63&a)>127&&(u=l);break;case 3:a=t[i+1],o=t[i+2],128==(192&a)&&128==(192&o)&&(l=(15&c)<<12|(63&a)<<6|63&o)>2047&&(l<55296||l>57343)&&(u=l);break;case 4:a=t[i+1],o=t[i+2],s=t[i+3],128==(192&a)&&128==(192&o)&&128==(192&s)&&(l=(15&c)<<18|(63&a)<<12|(63&o)<<6|63&s)>65535&&l<1114112&&(u=l)}null===u?(u=65533,f=1):u>65535&&(u-=65536,n.push(u>>>10&1023|55296),u=56320|1023&u),n.push(u),i+=f}return function(t){var e=t.length;if(e<=4096)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=4096));return r}(n)}r.kMaxLength=2147483647,a.TYPED_ARRAY_SUPPORT=function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()}catch(t){return!1}}(),a.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&a[Symbol.species]===a&&Object.defineProperty(a,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),a.poolSize=8192,a.from=function(t,e,r){return o(t,e,r)},a.prototype.__proto__=Uint8Array.prototype,a.__proto__=Uint8Array,a.alloc=function(t,e,r){return function(t,e,r){return s(t),t<=0?i(t):void 0!==e?"string"==typeof r?i(t).fill(e,r):i(t).fill(e):i(t)}(t,e,r)},a.allocUnsafe=function(t){return l(t)},a.allocUnsafeSlow=function(t){return l(t)},a.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==a.prototype},a.compare=function(t,e){if(B(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),B(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(t)||!a.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},a.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return a.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=a.allocUnsafe(e),i=0;for(r=0;r<t.length;++r){var o=t[r];if(B(o,Uint8Array)&&(o=a.from(o)),!a.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},a.byteLength=f,a.prototype._isBuffer=!0,a.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)p(this,e,e+1);return this},a.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)p(this,e,e+3),p(this,e+1,e+2);return this},a.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)p(this,e,e+7),p(this,e+1,e+6),p(this,e+2,e+5),p(this,e+3,e+4);return this},a.prototype.toString=function(){var t=this.length;return 0===t?"":0===arguments.length?T(this,0,t):h.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(t){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===a.compare(this,t)},a.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"},a.prototype.compare=function(t,e,r,n,i){if(B(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0),l=Math.min(o,s),c=this.slice(n,i),u=t.slice(e,r),f=0;f<l;++f)if(c[f]!==u[f]){o=c[f],s=u[f];break}return o<s?-1:s<o?1:0},a.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},a.prototype.indexOf=function(t,e,r){return d(this,t,e,r,!0)},a.prototype.lastIndexOf=function(t,e,r){return d(this,t,e,r,!1)},a.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var a=!1;;)switch(n){case"hex":return g(this,t,e,r);case"utf8":case"utf-8":return v(this,t,e,r);case"ascii":return y(this,t,e,r);case"latin1":case"binary":return x(this,t,e,r);case"base64":return b(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _(this,t,e,r);default:if(a)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),a=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function k(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function A(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function M(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var i="",a=e;a<r;++a)i+=z(t[a]);return i}function S(t,e,r){for(var n=t.slice(e,r),i="",a=0;a<n.length;a+=2)i+=String.fromCharCode(n[a]+256*n[a+1]);return i}function E(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function L(t,e,r,n,i,o){if(!a.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function C(t,e,r,n,i,a){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function P(t,e,r,i,a){return e=+e,r>>>=0,a||C(t,0,r,4),n.write(t,e,r,i,23,4),r+4}function I(t,e,r,i,a){return e=+e,r>>>=0,a||C(t,0,r,8),n.write(t,e,r,i,52,8),r+8}a.prototype.slice=function(t,e){var r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);var n=this.subarray(t,e);return n.__proto__=a.prototype,n},a.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||E(t,e,this.length);for(var n=this[t],i=1,a=0;++a<e&&(i*=256);)n+=this[t+a]*i;return n},a.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||E(t,e,this.length);for(var n=this[t+--e],i=1;e>0&&(i*=256);)n+=this[t+--e]*i;return n},a.prototype.readUInt8=function(t,e){return t>>>=0,e||E(t,1,this.length),this[t]},a.prototype.readUInt16LE=function(t,e){return t>>>=0,e||E(t,2,this.length),this[t]|this[t+1]<<8},a.prototype.readUInt16BE=function(t,e){return t>>>=0,e||E(t,2,this.length),this[t]<<8|this[t+1]},a.prototype.readUInt32LE=function(t,e){return t>>>=0,e||E(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},a.prototype.readUInt32BE=function(t,e){return t>>>=0,e||E(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},a.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||E(t,e,this.length);for(var n=this[t],i=1,a=0;++a<e&&(i*=256);)n+=this[t+a]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*e)),n},a.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||E(t,e,this.length);for(var n=e,i=1,a=this[t+--n];n>0&&(i*=256);)a+=this[t+--n]*i;return a>=(i*=128)&&(a-=Math.pow(2,8*e)),a},a.prototype.readInt8=function(t,e){return t>>>=0,e||E(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},a.prototype.readInt16LE=function(t,e){t>>>=0,e||E(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt16BE=function(t,e){t>>>=0,e||E(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt32LE=function(t,e){return t>>>=0,e||E(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},a.prototype.readInt32BE=function(t,e){return t>>>=0,e||E(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},a.prototype.readFloatLE=function(t,e){return t>>>=0,e||E(t,4,this.length),n.read(this,t,!0,23,4)},a.prototype.readFloatBE=function(t,e){return t>>>=0,e||E(t,4,this.length),n.read(this,t,!1,23,4)},a.prototype.readDoubleLE=function(t,e){return t>>>=0,e||E(t,8,this.length),n.read(this,t,!0,52,8)},a.prototype.readDoubleBE=function(t,e){return t>>>=0,e||E(t,8,this.length),n.read(this,t,!1,52,8)},a.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e>>>=0,r>>>=0,n)||L(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,a=0;for(this[e]=255&t;++a<r&&(i*=256);)this[e+a]=t/i&255;return e+r},a.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e>>>=0,r>>>=0,n)||L(this,t,e,r,Math.pow(2,8*r)-1,0);var i=r-1,a=1;for(this[e+i]=255&t;--i>=0&&(a*=256);)this[e+i]=t/a&255;return e+r},a.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,1,255,0),this[e]=255&t,e+1},a.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},a.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},a.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},a.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},a.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var i=Math.pow(2,8*r-1);L(this,t,e,r,i-1,-i)}var a=0,o=1,s=0;for(this[e]=255&t;++a<r&&(o*=256);)t<0&&0===s&&0!==this[e+a-1]&&(s=1),this[e+a]=(t/o>>0)-s&255;return e+r},a.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var i=Math.pow(2,8*r-1);L(this,t,e,r,i-1,-i)}var a=r-1,o=1,s=0;for(this[e+a]=255&t;--a>=0&&(o*=256);)t<0&&0===s&&0!==this[e+a+1]&&(s=1),this[e+a]=(t/o>>0)-s&255;return e+r},a.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},a.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},a.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},a.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},a.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},a.prototype.writeFloatLE=function(t,e,r){return P(this,t,e,!0,r)},a.prototype.writeFloatBE=function(t,e,r){return P(this,t,e,!1,r)},a.prototype.writeDoubleLE=function(t,e,r){return I(this,t,e,!0,r)},a.prototype.writeDoubleBE=function(t,e,r){return I(this,t,e,!1,r)},a.prototype.copy=function(t,e,r,n){if(!a.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var i=n-r;if(this===t&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(e,r,n);else if(this===t&&r<e&&e<n)for(var o=i-1;o>=0;--o)t[o+e]=this[o+r];else Uint8Array.prototype.set.call(t,this.subarray(r,n),e);return i},a.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!a.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){var i=t.charCodeAt(0);("utf8"===n&&i<128||"latin1"===n)&&(t=i)}}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{var s=a.isBuffer(t)?t:a.from(t,n),l=s.length;if(0===l)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<r-e;++o)this[o+e]=s[o%l]}return this};var O=/[^+/0-9A-Za-z-_]/g;function z(t){return t<16?"0"+t.toString(16):t.toString(16)}function D(t,e){var r;e=e||1/0;for(var n=t.length,i=null,a=[],o=0;o<n;++o){if((r=t.charCodeAt(o))>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&a.push(239,191,189);continue}if(o+1===n){(e-=3)>-1&&a.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&a.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&a.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;a.push(r)}else if(r<2048){if((e-=2)<0)break;a.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;a.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;a.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return a}function R(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(O,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function F(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function B(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function N(t){return t!=t}}).call(this)}).call(this,t("buffer").Buffer)},{"base64-js":79,buffer:85,ieee754:230}],86:[function(t,e,r){e.exports=function(t,e,r){return e<r?t<e?e:t>r?r:t:t<r?r:t>e?e:t}},{}],87:[function(t,e,r){"use strict";var n=t("clamp");function i(t,e){null==e&&(e=!0);var r=t[0],i=t[1],a=t[2],o=t[3];return null==o&&(o=e?1:255),e&&(r*=255,i*=255,a*=255,o*=255),16777216*(r=255&n(r,0,255))+((i=255&n(i,0,255))<<16)+((a=255&n(a,0,255))<<8)+(o=255&n(o,0,255))}e.exports=i,e.exports.to=i,e.exports.from=function(t,e){var r=(t=+t)>>>24,n=(16711680&t)>>>16,i=(65280&t)>>>8,a=255&t;return!1===e?[r,n,i,a]:[r/255,n/255,i/255,a/255]}},{clamp:86}],88:[function(t,e,r){"use strict";e.exports={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}},{}],89:[function(t,e,r){"use strict";var n=t("color-rgba"),i=t("clamp"),a=t("dtype");e.exports=function(t,e){"float"!==e&&e||(e="array"),"uint"===e&&(e="uint8"),"uint_clamped"===e&&(e="uint8_clamped");var r=new(a(e))(4),o="uint8"!==e&&"uint8_clamped"!==e;return t.length&&"string"!=typeof t||((t=n(t))[0]/=255,t[1]/=255,t[2]/=255),function(t){return t instanceof Uint8Array||t instanceof Uint8ClampedArray||!!(Array.isArray(t)&&(t[0]>1||0===t[0])&&(t[1]>1||0===t[1])&&(t[2]>1||0===t[2])&&(!t[3]||t[3]>1))}(t)?(r[0]=t[0],r[1]=t[1],r[2]=t[2],r[3]=null!=t[3]?t[3]:255,o&&(r[0]/=255,r[1]/=255,r[2]/=255,r[3]/=255),r):(o?(r[0]=t[0],r[1]=t[1],r[2]=t[2],r[3]=null!=t[3]?t[3]:1):(r[0]=i(Math.floor(255*t[0]),0,255),r[1]=i(Math.floor(255*t[1]),0,255),r[2]=i(Math.floor(255*t[2]),0,255),r[3]=null==t[3]?255:i(Math.floor(255*t[3]),0,255)),r)}},{clamp:86,"color-rgba":91,dtype:127}],90:[function(t,e,r){(function(r){(function(){"use strict";var n=t("color-name"),i=t("is-plain-obj"),a=t("defined");e.exports=function(t){var e,s,l=[],c=1;if("string"==typeof t)if(n[t])l=n[t].slice(),s="rgb";else if("transparent"===t)c=0,s="rgb",l=[0,0,0];else if(/^#[A-Fa-f0-9]+$/.test(t)){var u=(p=t.slice(1)).length;c=1,u<=4?(l=[parseInt(p[0]+p[0],16),parseInt(p[1]+p[1],16),parseInt(p[2]+p[2],16)],4===u&&(c=parseInt(p[3]+p[3],16)/255)):(l=[parseInt(p[0]+p[1],16),parseInt(p[2]+p[3],16),parseInt(p[4]+p[5],16)],8===u&&(c=parseInt(p[6]+p[7],16)/255)),l[0]||(l[0]=0),l[1]||(l[1]=0),l[2]||(l[2]=0),s="rgb"}else if(e=/^((?:rgb|hs[lvb]|hwb|cmyk?|xy[zy]|gray|lab|lchu?v?|[ly]uv|lms)a?)\s*\(([^\)]*)\)/.exec(t)){var f=e[1],h="rgb"===f,p=f.replace(/a$/,"");s=p;u="cmyk"===p?4:"gray"===p?1:3;l=e[2].trim().split(/\s*,\s*/).map((function(t,e){if(/%$/.test(t))return e===u?parseFloat(t)/100:"rgb"===p?255*parseFloat(t)/100:parseFloat(t);if("h"===p[e]){if(/deg$/.test(t))return parseFloat(t);if(void 0!==o[t])return o[t]}return parseFloat(t)})),f===p&&l.push(1),c=h||void 0===l[u]?1:l[u],l=l.slice(0,u)}else t.length>10&&/[0-9](?:\s|\/)/.test(t)&&(l=t.match(/([0-9]+)/g).map((function(t){return parseFloat(t)})),s=t.match(/([a-z])/gi).join("").toLowerCase());else if(isNaN(t))if(i(t)){var d=a(t.r,t.red,t.R,null);null!==d?(s="rgb",l=[d,a(t.g,t.green,t.G),a(t.b,t.blue,t.B)]):(s="hsl",l=[a(t.h,t.hue,t.H),a(t.s,t.saturation,t.S),a(t.l,t.lightness,t.L,t.b,t.brightness)]),c=a(t.a,t.alpha,t.opacity,1),null!=t.opacity&&(c/=100)}else(Array.isArray(t)||r.ArrayBuffer&&ArrayBuffer.isView&&ArrayBuffer.isView(t))&&(l=[t[0],t[1],t[2]],s="rgb",c=4===t.length?t[3]:1);else s="rgb",l=[t>>>16,(65280&t)>>>8,255&t];return{space:s,values:l,alpha:c}};var o={red:0,orange:60,yellow:120,green:180,blue:240,purple:300}}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"color-name":88,defined:124,"is-plain-obj":236}],91:[function(t,e,r){"use strict";var n=t("color-parse"),i=t("color-space/hsl"),a=t("clamp");e.exports=function(t){var e,r=n(t);return r.space?((e=Array(3))[0]=a(r.values[0],0,255),e[1]=a(r.values[1],0,255),e[2]=a(r.values[2],0,255),"h"===r.space[0]&&(e=i.rgb(e)),e.push(a(r.alpha,0,1)),e):[]}},{clamp:86,"color-parse":90,"color-space/hsl":92}],92:[function(t,e,r){"use strict";var n=t("./rgb");e.exports={name:"hsl",min:[0,0,0],max:[360,100,100],channel:["hue","saturation","lightness"],alias:["HSL"],rgb:function(t){var e,r,n,i,a,o=t[0]/360,s=t[1]/100,l=t[2]/100;if(0===s)return[a=255*l,a,a];e=2*l-(r=l<.5?l*(1+s):l+s-l*s),i=[0,0,0];for(var c=0;c<3;c++)(n=o+1/3*-(c-1))<0?n++:n>1&&n--,a=6*n<1?e+6*(r-e)*n:2*n<1?r:3*n<2?e+(r-e)*(2/3-n)*6:e,i[c]=255*a;return i}},n.hsl=function(t){var e,r,n=t[0]/255,i=t[1]/255,a=t[2]/255,o=Math.min(n,i,a),s=Math.max(n,i,a),l=s-o;return s===o?e=0:n===s?e=(i-a)/l:i===s?e=2+(a-n)/l:a===s&&(e=4+(n-i)/l),(e=Math.min(60*e,360))<0&&(e+=360),r=(o+s)/2,[e,100*(s===o?0:r<=.5?l/(s+o):l/(2-s-o)),100*r]}},{"./rgb":93}],93:[function(t,e,r){"use strict";e.exports={name:"rgb",min:[0,0,0],max:[255,255,255],channel:["red","green","blue"],alias:["RGB"]}},{}],94:[function(t,e,r){e.exports={AFG:"afghan",ALA:"\\b\\wland",ALB:"albania",DZA:"algeria",ASM:"^(?=.*americ).*samoa",AND:"andorra",AGO:"angola",AIA:"anguill?a",ATA:"antarctica",ATG:"antigua",ARG:"argentin",ARM:"armenia",ABW:"^(?!.*bonaire).*\\baruba",AUS:"australia",AUT:"^(?!.*hungary).*austria|\\baustri.*\\bemp",AZE:"azerbaijan",BHS:"bahamas",BHR:"bahrain",BGD:"bangladesh|^(?=.*east).*paki?stan",BRB:"barbados",BLR:"belarus|byelo",BEL:"^(?!.*luxem).*belgium",BLZ:"belize|^(?=.*british).*honduras",BEN:"benin|dahome",BMU:"bermuda",BTN:"bhutan",BOL:"bolivia",BES:"^(?=.*bonaire).*eustatius|^(?=.*carib).*netherlands|\\bbes.?islands",BIH:"herzegovina|bosnia",BWA:"botswana|bechuana",BVT:"bouvet",BRA:"brazil",IOT:"british.?indian.?ocean",BRN:"brunei",BGR:"bulgaria",BFA:"burkina|\\bfaso|upper.?volta",BDI:"burundi",CPV:"verde",KHM:"cambodia|kampuchea|khmer",CMR:"cameroon",CAN:"canada",CYM:"cayman",CAF:"\\bcentral.african.republic",TCD:"\\bchad",CHL:"\\bchile",CHN:"^(?!.*\\bmac)(?!.*\\bhong)(?!.*\\btai)(?!.*\\brep).*china|^(?=.*peo)(?=.*rep).*china",CXR:"christmas",CCK:"\\bcocos|keeling",COL:"colombia",COM:"comoro",COG:"^(?!.*\\bdem)(?!.*\\bd[\\.]?r)(?!.*kinshasa)(?!.*zaire)(?!.*belg)(?!.*l.opoldville)(?!.*free).*\\bcongo",COK:"\\bcook",CRI:"costa.?rica",CIV:"ivoire|ivory",HRV:"croatia",CUB:"\\bcuba",CUW:"^(?!.*bonaire).*\\bcura(c|\xe7)ao",CYP:"cyprus",CSK:"czechoslovakia",CZE:"^(?=.*rep).*czech|czechia|bohemia",COD:"\\bdem.*congo|congo.*\\bdem|congo.*\\bd[\\.]?r|\\bd[\\.]?r.*congo|belgian.?congo|congo.?free.?state|kinshasa|zaire|l.opoldville|drc|droc|rdc",DNK:"denmark",DJI:"djibouti",DMA:"dominica(?!n)",DOM:"dominican.rep",ECU:"ecuador",EGY:"egypt",SLV:"el.?salvador",GNQ:"guine.*eq|eq.*guine|^(?=.*span).*guinea",ERI:"eritrea",EST:"estonia",ETH:"ethiopia|abyssinia",FLK:"falkland|malvinas",FRO:"faroe|faeroe",FJI:"fiji",FIN:"finland",FRA:"^(?!.*\\bdep)(?!.*martinique).*france|french.?republic|\\bgaul",GUF:"^(?=.*french).*guiana",PYF:"french.?polynesia|tahiti",ATF:"french.?southern",GAB:"gabon",GMB:"gambia",GEO:"^(?!.*south).*georgia",DDR:"german.?democratic.?republic|democratic.?republic.*germany|east.germany",DEU:"^(?!.*east).*germany|^(?=.*\\bfed.*\\brep).*german",GHA:"ghana|gold.?coast",GIB:"gibraltar",GRC:"greece|hellenic|hellas",GRL:"greenland",GRD:"grenada",GLP:"guadeloupe",GUM:"\\bguam",GTM:"guatemala",GGY:"guernsey",GIN:"^(?!.*eq)(?!.*span)(?!.*bissau)(?!.*portu)(?!.*new).*guinea",GNB:"bissau|^(?=.*portu).*guinea",GUY:"guyana|british.?guiana",HTI:"haiti",HMD:"heard.*mcdonald",VAT:"holy.?see|vatican|papal.?st",HND:"^(?!.*brit).*honduras",HKG:"hong.?kong",HUN:"^(?!.*austr).*hungary",ISL:"iceland",IND:"india(?!.*ocea)",IDN:"indonesia",IRN:"\\biran|persia",IRQ:"\\biraq|mesopotamia",IRL:"(^ireland)|(^republic.*ireland)",IMN:"^(?=.*isle).*\\bman",ISR:"israel",ITA:"italy",JAM:"jamaica",JPN:"japan",JEY:"jersey",JOR:"jordan",KAZ:"kazak",KEN:"kenya|british.?east.?africa|east.?africa.?prot",KIR:"kiribati",PRK:"^(?=.*democrat|people|north|d.*p.*.r).*\\bkorea|dprk|korea.*(d.*p.*r)",KWT:"kuwait",KGZ:"kyrgyz|kirghiz",LAO:"\\blaos?\\b",LVA:"latvia",LBN:"lebanon",LSO:"lesotho|basuto",LBR:"liberia",LBY:"libya",LIE:"liechtenstein",LTU:"lithuania",LUX:"^(?!.*belg).*luxem",MAC:"maca(o|u)",MDG:"madagascar|malagasy",MWI:"malawi|nyasa",MYS:"malaysia",MDV:"maldive",MLI:"\\bmali\\b",MLT:"\\bmalta",MHL:"marshall",MTQ:"martinique",MRT:"mauritania",MUS:"mauritius",MYT:"\\bmayotte",MEX:"\\bmexic",FSM:"fed.*micronesia|micronesia.*fed",MCO:"monaco",MNG:"mongolia",MNE:"^(?!.*serbia).*montenegro",MSR:"montserrat",MAR:"morocco|\\bmaroc",MOZ:"mozambique",MMR:"myanmar|burma",NAM:"namibia",NRU:"nauru",NPL:"nepal",NLD:"^(?!.*\\bant)(?!.*\\bcarib).*netherlands",ANT:"^(?=.*\\bant).*(nether|dutch)",NCL:"new.?caledonia",NZL:"new.?zealand",NIC:"nicaragua",NER:"\\bniger(?!ia)",NGA:"nigeria",NIU:"niue",NFK:"norfolk",MNP:"mariana",NOR:"norway",OMN:"\\boman|trucial",PAK:"^(?!.*east).*paki?stan",PLW:"palau",PSE:"palestin|\\bgaza|west.?bank",PAN:"panama",PNG:"papua|new.?guinea",PRY:"paraguay",PER:"peru",PHL:"philippines",PCN:"pitcairn",POL:"poland",PRT:"portugal",PRI:"puerto.?rico",QAT:"qatar",KOR:"^(?!.*d.*p.*r)(?!.*democrat)(?!.*people)(?!.*north).*\\bkorea(?!.*d.*p.*r)",MDA:"moldov|b(a|e)ssarabia",REU:"r(e|\xe9)union",ROU:"r(o|u|ou)mania",RUS:"\\brussia|soviet.?union|u\\.?s\\.?s\\.?r|socialist.?republics",RWA:"rwanda",BLM:"barth(e|\xe9)lemy",SHN:"helena",KNA:"kitts|\\bnevis",LCA:"\\blucia",MAF:"^(?=.*collectivity).*martin|^(?=.*france).*martin(?!ique)|^(?=.*french).*martin(?!ique)",SPM:"miquelon",VCT:"vincent",WSM:"^(?!.*amer).*samoa",SMR:"san.?marino",STP:"\\bs(a|\xe3)o.?tom(e|\xe9)",SAU:"\\bsa\\w*.?arabia",SEN:"senegal",SRB:"^(?!.*monte).*serbia",SYC:"seychell",SLE:"sierra",SGP:"singapore",SXM:"^(?!.*martin)(?!.*saba).*maarten",SVK:"^(?!.*cze).*slovak",SVN:"slovenia",SLB:"solomon",SOM:"somali",ZAF:"south.africa|s\\\\..?africa",SGS:"south.?georgia|sandwich",SSD:"\\bs\\w*.?sudan",ESP:"spain",LKA:"sri.?lanka|ceylon",SDN:"^(?!.*\\bs(?!u)).*sudan",SUR:"surinam|dutch.?guiana",SJM:"svalbard",SWZ:"swaziland",SWE:"sweden",CHE:"switz|swiss",SYR:"syria",TWN:"taiwan|taipei|formosa|^(?!.*peo)(?=.*rep).*china",TJK:"tajik",THA:"thailand|\\bsiam",MKD:"macedonia|fyrom",TLS:"^(?=.*leste).*timor|^(?=.*east).*timor",TGO:"togo",TKL:"tokelau",TON:"tonga",TTO:"trinidad|tobago",TUN:"tunisia",TUR:"turkey",TKM:"turkmen",TCA:"turks",TUV:"tuvalu",UGA:"uganda",UKR:"ukrain",ARE:"emirates|^u\\.?a\\.?e\\.?$|united.?arab.?em",GBR:"united.?kingdom|britain|^u\\.?k\\.?$",TZA:"tanzania",USA:"united.?states\\b(?!.*islands)|\\bu\\.?s\\.?a\\.?\\b|^\\s*u\\.?s\\.?\\b(?!.*islands)",UMI:"minor.?outlying.?is",URY:"uruguay",UZB:"uzbek",VUT:"vanuatu|new.?hebrides",VEN:"venezuela",VNM:"^(?!.*republic).*viet.?nam|^(?=.*socialist).*viet.?nam",VGB:"^(?=.*\\bu\\.?\\s?k).*virgin|^(?=.*brit).*virgin|^(?=.*kingdom).*virgin",VIR:"^(?=.*\\bu\\.?\\s?s).*virgin|^(?=.*states).*virgin",WLF:"futuna|wallis",ESH:"western.sahara",YEM:"^(?!.*arab)(?!.*north)(?!.*sana)(?!.*peo)(?!.*dem)(?!.*south)(?!.*aden)(?!.*\\bp\\.?d\\.?r).*yemen",YMD:"^(?=.*peo).*yemen|^(?!.*rep)(?=.*dem).*yemen|^(?=.*south).*yemen|^(?=.*aden).*yemen|^(?=.*\\bp\\.?d\\.?r).*yemen",YUG:"yugoslavia",ZMB:"zambia|northern.?rhodesia",EAZ:"zanzibar",ZWE:"zimbabwe|^(?!.*northern).*rhodesia"}},{}],95:[function(t,e,r){e.exports=["xx-small","x-small","small","medium","large","x-large","xx-large","larger","smaller"]},{}],96:[function(t,e,r){e.exports=["normal","condensed","semi-condensed","extra-condensed","ultra-condensed","expanded","semi-expanded","extra-expanded","ultra-expanded"]},{}],97:[function(t,e,r){e.exports=["normal","italic","oblique"]},{}],98:[function(t,e,r){e.exports=["normal","bold","bolder","lighter","100","200","300","400","500","600","700","800","900"]},{}],99:[function(t,e,r){"use strict";e.exports={parse:t("./parse"),stringify:t("./stringify")}},{"./parse":101,"./stringify":102}],100:[function(t,e,r){"use strict";var n=t("css-font-size-keywords");e.exports={isSize:function(t){return/^[\d\.]/.test(t)||-1!==t.indexOf("/")||-1!==n.indexOf(t)}}},{"css-font-size-keywords":95}],101:[function(t,e,r){"use strict";var n=t("unquote"),i=t("css-global-keywords"),a=t("css-system-font-keywords"),o=t("css-font-weight-keywords"),s=t("css-font-style-keywords"),l=t("css-font-stretch-keywords"),c=t("string-split-by"),u=t("./lib/util").isSize;e.exports=h;var f=h.cache={};function h(t){if("string"!=typeof t)throw new Error("Font argument must be a string.");if(f[t])return f[t];if(""===t)throw new Error("Cannot parse an empty string.");if(-1!==a.indexOf(t))return f[t]={system:t};for(var e,r={style:"normal",variant:"normal",weight:"normal",stretch:"normal",lineHeight:"normal",size:"1rem",family:["serif"]},h=c(t,/\s+/);e=h.shift();){if(-1!==i.indexOf(e))return["style","variant","weight","stretch"].forEach((function(t){r[t]=e})),f[t]=r;if(-1===s.indexOf(e))if("normal"!==e&&"small-caps"!==e)if(-1===l.indexOf(e)){if(-1===o.indexOf(e)){if(u(e)){var d=c(e,"/");if(r.size=d[0],null!=d[1]?r.lineHeight=p(d[1]):"/"===h[0]&&(h.shift(),r.lineHeight=p(h.shift())),!h.length)throw new Error("Missing required font-family.");return r.family=c(h.join(" "),/\s*,\s*/).map(n),f[t]=r}throw new Error("Unknown or unsupported font token: "+e)}r.weight=e}else r.stretch=e;else r.variant=e;else r.style=e}throw new Error("Missing required font-size.")}function p(t){var e=parseFloat(t);return e.toString()===t?e:t}},{"./lib/util":100,"css-font-stretch-keywords":96,"css-font-style-keywords":97,"css-font-weight-keywords":98,"css-global-keywords":103,"css-system-font-keywords":104,"string-split-by":305,unquote:328}],102:[function(t,e,r){"use strict";var n=t("pick-by-alias"),i=t("./lib/util").isSize,a=m(t("css-global-keywords")),o=m(t("css-system-font-keywords")),s=m(t("css-font-weight-keywords")),l=m(t("css-font-style-keywords")),c=m(t("css-font-stretch-keywords")),u={normal:1,"small-caps":1},f={serif:1,"sans-serif":1,monospace:1,cursive:1,fantasy:1,"system-ui":1},h="1rem",p="serif";function d(t,e){if(t&&!e[t]&&!a[t])throw Error("Unknown keyword `"+t+"`");return t}function m(t){for(var e={},r=0;r<t.length;r++)e[t[r]]=1;return e}e.exports=function(t){if((t=n(t,{style:"style fontstyle fontStyle font-style slope distinction",variant:"variant font-variant fontVariant fontvariant var capitalization",weight:"weight w font-weight fontWeight fontweight",stretch:"stretch font-stretch fontStretch fontstretch width",size:"size s font-size fontSize fontsize height em emSize",lineHeight:"lh line-height lineHeight lineheight leading",family:"font family fontFamily font-family fontfamily type typeface face",system:"system reserved default global"})).system)return t.system&&d(t.system,o),t.system;if(d(t.style,l),d(t.variant,u),d(t.weight,s),d(t.stretch,c),null==t.size&&(t.size=h),"number"==typeof t.size&&(t.size+="px"),!i)throw Error("Bad size value `"+t.size+"`");t.family||(t.family=p),Array.isArray(t.family)&&(t.family.length||(t.family=[p]),t.family=t.family.map((function(t){return f[t]?t:'"'+t+'"'})).join(", "));var e=[];return e.push(t.style),t.variant!==t.style&&e.push(t.variant),t.weight!==t.variant&&t.weight!==t.style&&e.push(t.weight),t.stretch!==t.weight&&t.stretch!==t.variant&&t.stretch!==t.style&&e.push(t.stretch),e.push(t.size+(null==t.lineHeight||"normal"===t.lineHeight||t.lineHeight+""=="1"?"":"/"+t.lineHeight)),e.push(t.family),e.filter(Boolean).join(" ")}},{"./lib/util":100,"css-font-stretch-keywords":96,"css-font-style-keywords":97,"css-font-weight-keywords":98,"css-global-keywords":103,"css-system-font-keywords":104,"pick-by-alias":253}],103:[function(t,e,r){e.exports=["inherit","initial","unset"]},{}],104:[function(t,e,r){e.exports=["caption","icon","menu","message-box","small-caption","status-bar"]},{}],105:[function(t,e,r){"use strict";var n,i=t("type/value/is"),a=t("type/value/ensure"),o=t("type/plain-function/ensure"),s=t("es5-ext/object/copy"),l=t("es5-ext/object/normalize-options"),c=t("es5-ext/object/map"),u=Function.prototype.bind,f=Object.defineProperty,h=Object.prototype.hasOwnProperty;n=function(t,e,r){var n,i=a(e)&&o(e.value);return delete(n=s(e)).writable,delete n.value,n.get=function(){return!r.overwriteDefinition&&h.call(this,t)?i:(e.value=u.call(i,r.resolveContext?r.resolveContext(this):this),f(this,t,e),this[t])},n},e.exports=function(t){var e=l(arguments[1]);return i(e.resolveContext)&&o(e.resolveContext),c(t,(function(t,r){return n(r,t,e)}))}},{"es5-ext/object/copy":147,"es5-ext/object/map":155,"es5-ext/object/normalize-options":156,"type/plain-function/ensure":321,"type/value/ensure":325,"type/value/is":326}],106:[function(t,e,r){"use strict";var n=t("type/value/is"),i=t("type/plain-function/is"),a=t("es5-ext/object/assign"),o=t("es5-ext/object/normalize-options"),s=t("es5-ext/string/#/contains");(e.exports=function(t,e){var r,i,l,c,u;return arguments.length<2||"string"!=typeof t?(c=e,e=t,t=null):c=arguments[2],n(t)?(r=s.call(t,"c"),i=s.call(t,"e"),l=s.call(t,"w")):(r=l=!0,i=!1),u={value:e,configurable:r,enumerable:i,writable:l},c?a(o(c),u):u}).gs=function(t,e,r){var l,c,u,f;return"string"!=typeof t?(u=r,r=e,e=t,t=null):u=arguments[3],n(e)?i(e)?n(r)?i(r)||(u=r,r=void 0):r=void 0:(u=e,e=r=void 0):e=void 0,n(t)?(l=s.call(t,"c"),c=s.call(t,"e")):(l=!0,c=!1),f={get:e,set:r,configurable:l,enumerable:c},u?a(o(u),f):f}},{"es5-ext/object/assign":144,"es5-ext/object/normalize-options":156,"es5-ext/string/#/contains":163,"type/plain-function/is":322,"type/value/is":326}],107:[function(t,e,r){!function(t,n){n("object"==typeof r&&void 0!==e?r:t.d3=t.d3||{})}(this,(function(t){"use strict";function e(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function r(t){var r;return 1===t.length&&(r=t,t=function(t,n){return e(r(t),n)}),{left:function(e,r,n,i){for(null==n&&(n=0),null==i&&(i=e.length);n<i;){var a=n+i>>>1;t(e[a],r)<0?n=a+1:i=a}return n},right:function(e,r,n,i){for(null==n&&(n=0),null==i&&(i=e.length);n<i;){var a=n+i>>>1;t(e[a],r)>0?i=a:n=a+1}return n}}}var n=r(e),i=n.right,a=n.left;function o(t,e){return[t,e]}function s(t){return null===t?NaN:+t}function l(t,e){var r,n,i=t.length,a=0,o=-1,l=0,c=0;if(null==e)for(;++o<i;)isNaN(r=s(t[o]))||(c+=(n=r-l)*(r-(l+=n/++a)));else for(;++o<i;)isNaN(r=s(e(t[o],o,t)))||(c+=(n=r-l)*(r-(l+=n/++a)));if(a>1)return c/(a-1)}function c(t,e){var r=l(t,e);return r?Math.sqrt(r):r}function u(t,e){var r,n,i,a=t.length,o=-1;if(null==e){for(;++o<a;)if(null!=(r=t[o])&&r>=r)for(n=i=r;++o<a;)null!=(r=t[o])&&(n>r&&(n=r),i<r&&(i=r))}else for(;++o<a;)if(null!=(r=e(t[o],o,t))&&r>=r)for(n=i=r;++o<a;)null!=(r=e(t[o],o,t))&&(n>r&&(n=r),i<r&&(i=r));return[n,i]}var f=Array.prototype,h=f.slice,p=f.map;function d(t){return function(){return t}}function m(t){return t}function g(t,e,r){t=+t,e=+e,r=(i=arguments.length)<2?(e=t,t=0,1):i<3?1:+r;for(var n=-1,i=0|Math.max(0,Math.ceil((e-t)/r)),a=new Array(i);++n<i;)a[n]=t+n*r;return a}var v=Math.sqrt(50),y=Math.sqrt(10),x=Math.sqrt(2);function b(t,e,r){var n=(e-t)/Math.max(0,r),i=Math.floor(Math.log(n)/Math.LN10),a=n/Math.pow(10,i);return i>=0?(a>=v?10:a>=y?5:a>=x?2:1)*Math.pow(10,i):-Math.pow(10,-i)/(a>=v?10:a>=y?5:a>=x?2:1)}function _(t,e,r){var n=Math.abs(e-t)/Math.max(0,r),i=Math.pow(10,Math.floor(Math.log(n)/Math.LN10)),a=n/i;return a>=v?i*=10:a>=y?i*=5:a>=x&&(i*=2),e<t?-i:i}function w(t){return Math.ceil(Math.log(t.length)/Math.LN2)+1}function T(t,e,r){if(null==r&&(r=s),n=t.length){if((e=+e)<=0||n<2)return+r(t[0],0,t);if(e>=1)return+r(t[n-1],n-1,t);var n,i=(n-1)*e,a=Math.floor(i),o=+r(t[a],a,t);return o+(+r(t[a+1],a+1,t)-o)*(i-a)}}function k(t,e){var r,n,i=t.length,a=-1;if(null==e){for(;++a<i;)if(null!=(r=t[a])&&r>=r)for(n=r;++a<i;)null!=(r=t[a])&&n>r&&(n=r)}else for(;++a<i;)if(null!=(r=e(t[a],a,t))&&r>=r)for(n=r;++a<i;)null!=(r=e(t[a],a,t))&&n>r&&(n=r);return n}function A(t){if(!(i=t.length))return[];for(var e=-1,r=k(t,M),n=new Array(r);++e<r;)for(var i,a=-1,o=n[e]=new Array(i);++a<i;)o[a]=t[a][e];return n}function M(t){return t.length}t.bisect=i,t.bisectRight=i,t.bisectLeft=a,t.ascending=e,t.bisector=r,t.cross=function(t,e,r){var n,i,a,s,l=t.length,c=e.length,u=new Array(l*c);for(null==r&&(r=o),n=a=0;n<l;++n)for(s=t[n],i=0;i<c;++i,++a)u[a]=r(s,e[i]);return u},t.descending=function(t,e){return e<t?-1:e>t?1:e>=t?0:NaN},t.deviation=c,t.extent=u,t.histogram=function(){var t=m,e=u,r=w;function n(n){var a,o,s=n.length,l=new Array(s);for(a=0;a<s;++a)l[a]=t(n[a],a,n);var c=e(l),u=c[0],f=c[1],h=r(l,u,f);Array.isArray(h)||(h=_(u,f,h),h=g(Math.ceil(u/h)*h,f,h));for(var p=h.length;h[0]<=u;)h.shift(),--p;for(;h[p-1]>f;)h.pop(),--p;var d,m=new Array(p+1);for(a=0;a<=p;++a)(d=m[a]=[]).x0=a>0?h[a-1]:u,d.x1=a<p?h[a]:f;for(a=0;a<s;++a)u<=(o=l[a])&&o<=f&&m[i(h,o,0,p)].push(n[a]);return m}return n.value=function(e){return arguments.length?(t="function"==typeof e?e:d(e),n):t},n.domain=function(t){return arguments.length?(e="function"==typeof t?t:d([t[0],t[1]]),n):e},n.thresholds=function(t){return arguments.length?(r="function"==typeof t?t:Array.isArray(t)?d(h.call(t)):d(t),n):r},n},t.thresholdFreedmanDiaconis=function(t,r,n){return t=p.call(t,s).sort(e),Math.ceil((n-r)/(2*(T(t,.75)-T(t,.25))*Math.pow(t.length,-1/3)))},t.thresholdScott=function(t,e,r){return Math.ceil((r-e)/(3.5*c(t)*Math.pow(t.length,-1/3)))},t.thresholdSturges=w,t.max=function(t,e){var r,n,i=t.length,a=-1;if(null==e){for(;++a<i;)if(null!=(r=t[a])&&r>=r)for(n=r;++a<i;)null!=(r=t[a])&&r>n&&(n=r)}else for(;++a<i;)if(null!=(r=e(t[a],a,t))&&r>=r)for(n=r;++a<i;)null!=(r=e(t[a],a,t))&&r>n&&(n=r);return n},t.mean=function(t,e){var r,n=t.length,i=n,a=-1,o=0;if(null==e)for(;++a<n;)isNaN(r=s(t[a]))?--i:o+=r;else for(;++a<n;)isNaN(r=s(e(t[a],a,t)))?--i:o+=r;if(i)return o/i},t.median=function(t,r){var n,i=t.length,a=-1,o=[];if(null==r)for(;++a<i;)isNaN(n=s(t[a]))||o.push(n);else for(;++a<i;)isNaN(n=s(r(t[a],a,t)))||o.push(n);return T(o.sort(e),.5)},t.merge=function(t){for(var e,r,n,i=t.length,a=-1,o=0;++a<i;)o+=t[a].length;for(r=new Array(o);--i>=0;)for(e=(n=t[i]).length;--e>=0;)r[--o]=n[e];return r},t.min=k,t.pairs=function(t,e){null==e&&(e=o);for(var r=0,n=t.length-1,i=t[0],a=new Array(n<0?0:n);r<n;)a[r]=e(i,i=t[++r]);return a},t.permute=function(t,e){for(var r=e.length,n=new Array(r);r--;)n[r]=t[e[r]];return n},t.quantile=T,t.range=g,t.scan=function(t,r){if(n=t.length){var n,i,a=0,o=0,s=t[o];for(null==r&&(r=e);++a<n;)(r(i=t[a],s)<0||0!==r(s,s))&&(s=i,o=a);return 0===r(s,s)?o:void 0}},t.shuffle=function(t,e,r){for(var n,i,a=(null==r?t.length:r)-(e=null==e?0:+e);a;)i=Math.random()*a--|0,n=t[a+e],t[a+e]=t[i+e],t[i+e]=n;return t},t.sum=function(t,e){var r,n=t.length,i=-1,a=0;if(null==e)for(;++i<n;)(r=+t[i])&&(a+=r);else for(;++i<n;)(r=+e(t[i],i,t))&&(a+=r);return a},t.ticks=function(t,e,r){var n,i,a,o,s=-1;if(r=+r,(t=+t)===(e=+e)&&r>0)return[t];if((n=e<t)&&(i=t,t=e,e=i),0===(o=b(t,e,r))||!isFinite(o))return[];if(o>0)for(t=Math.ceil(t/o),e=Math.floor(e/o),a=new Array(i=Math.ceil(e-t+1));++s<i;)a[s]=(t+s)*o;else for(t=Math.floor(t*o),e=Math.ceil(e*o),a=new Array(i=Math.ceil(t-e+1));++s<i;)a[s]=(t-s)/o;return n&&a.reverse(),a},t.tickIncrement=b,t.tickStep=_,t.transpose=A,t.variance=l,t.zip=function(){return A(arguments)},Object.defineProperty(t,"__esModule",{value:!0})}))},{}],108:[function(t,e,r){!function(t,n){n("object"==typeof r&&void 0!==e?r:t.d3=t.d3||{})}(this,(function(t){"use strict";function e(){}function r(t,r){var n=new e;if(t instanceof e)t.each((function(t,e){n.set(e,t)}));else if(Array.isArray(t)){var i,a=-1,o=t.length;if(null==r)for(;++a<o;)n.set(a,t[a]);else for(;++a<o;)n.set(r(i=t[a],a,t),i)}else if(t)for(var s in t)n.set(s,t[s]);return n}function n(){return{}}function i(t,e,r){t[e]=r}function a(){return r()}function o(t,e,r){t.set(e,r)}function s(){}e.prototype=r.prototype={constructor:e,has:function(t){return"$"+t in this},get:function(t){return this["$"+t]},set:function(t,e){return this["$"+t]=e,this},remove:function(t){var e="$"+t;return e in this&&delete this[e]},clear:function(){for(var t in this)"$"===t[0]&&delete this[t]},keys:function(){var t=[];for(var e in this)"$"===e[0]&&t.push(e.slice(1));return t},values:function(){var t=[];for(var e in this)"$"===e[0]&&t.push(this[e]);return t},entries:function(){var t=[];for(var e in this)"$"===e[0]&&t.push({key:e.slice(1),value:this[e]});return t},size:function(){var t=0;for(var e in this)"$"===e[0]&&++t;return t},empty:function(){for(var t in this)if("$"===t[0])return!1;return!0},each:function(t){for(var e in this)"$"===e[0]&&t(this[e],e.slice(1),this)}};var l=r.prototype;function c(t,e){var r=new s;if(t instanceof s)t.each((function(t){r.add(t)}));else if(t){var n=-1,i=t.length;if(null==e)for(;++n<i;)r.add(t[n]);else for(;++n<i;)r.add(e(t[n],n,t))}return r}s.prototype=c.prototype={constructor:s,has:l.has,add:function(t){return this["$"+(t+="")]=t,this},remove:l.remove,clear:l.clear,values:l.keys,size:l.size,empty:l.empty,each:l.each},t.nest=function(){var t,e,s,l=[],c=[];function u(n,i,a,o){if(i>=l.length)return null!=t&&n.sort(t),null!=e?e(n):n;for(var s,c,f,h=-1,p=n.length,d=l[i++],m=r(),g=a();++h<p;)(f=m.get(s=d(c=n[h])+""))?f.push(c):m.set(s,[c]);return m.each((function(t,e){o(g,e,u(t,i,a,o))})),g}return s={object:function(t){return u(t,0,n,i)},map:function(t){return u(t,0,a,o)},entries:function(t){return function t(r,n){if(++n>l.length)return r;var i,a=c[n-1];return null!=e&&n>=l.length?i=r.entries():(i=[],r.each((function(e,r){i.push({key:r,values:t(e,n)})}))),null!=a?i.sort((function(t,e){return a(t.key,e.key)})):i}(u(t,0,a,o),0)},key:function(t){return l.push(t),s},sortKeys:function(t){return c[l.length-1]=t,s},sortValues:function(e){return t=e,s},rollup:function(t){return e=t,s}}},t.set=c,t.map=r,t.keys=function(t){var e=[];for(var r in t)e.push(r);return e},t.values=function(t){var e=[];for(var r in t)e.push(t[r]);return e},t.entries=function(t){var e=[];for(var r in t)e.push({key:r,value:t[r]});return e},Object.defineProperty(t,"__esModule",{value:!0})}))},{}],109:[function(t,e,r){!function(t,n){"object"==typeof r&&void 0!==e?n(r):n((t=t||self).d3=t.d3||{})}(this,(function(t){"use strict";function e(t,e,r){t.prototype=e.prototype=r,r.constructor=t}function r(t,e){var r=Object.create(t.prototype);for(var n in e)r[n]=e[n];return r}function n(){}var i="\\s*([+-]?\\d+)\\s*",a="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",o="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",s=/^#([0-9a-f]{3,8})$/,l=new RegExp("^rgb\\("+[i,i,i]+"\\)$"),c=new RegExp("^rgb\\("+[o,o,o]+"\\)$"),u=new RegExp("^rgba\\("+[i,i,i,a]+"\\)$"),f=new RegExp("^rgba\\("+[o,o,o,a]+"\\)$"),h=new RegExp("^hsl\\("+[a,o,o]+"\\)$"),p=new RegExp("^hsla\\("+[a,o,o,a]+"\\)$"),d={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function m(){return this.rgb().formatHex()}function g(){return this.rgb().formatRgb()}function v(t){var e,r;return t=(t+"").trim().toLowerCase(),(e=s.exec(t))?(r=e[1].length,e=parseInt(e[1],16),6===r?y(e):3===r?new w(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===r?x(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===r?x(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=l.exec(t))?new w(e[1],e[2],e[3],1):(e=c.exec(t))?new w(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=u.exec(t))?x(e[1],e[2],e[3],e[4]):(e=f.exec(t))?x(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=h.exec(t))?M(e[1],e[2]/100,e[3]/100,1):(e=p.exec(t))?M(e[1],e[2]/100,e[3]/100,e[4]):d.hasOwnProperty(t)?y(d[t]):"transparent"===t?new w(NaN,NaN,NaN,0):null}function y(t){return new w(t>>16&255,t>>8&255,255&t,1)}function x(t,e,r,n){return n<=0&&(t=e=r=NaN),new w(t,e,r,n)}function b(t){return t instanceof n||(t=v(t)),t?new w((t=t.rgb()).r,t.g,t.b,t.opacity):new w}function _(t,e,r,n){return 1===arguments.length?b(t):new w(t,e,r,null==n?1:n)}function w(t,e,r,n){this.r=+t,this.g=+e,this.b=+r,this.opacity=+n}function T(){return"#"+A(this.r)+A(this.g)+A(this.b)}function k(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}function A(t){return((t=Math.max(0,Math.min(255,Math.round(t)||0)))<16?"0":"")+t.toString(16)}function M(t,e,r,n){return n<=0?t=e=r=NaN:r<=0||r>=1?t=e=NaN:e<=0&&(t=NaN),new L(t,e,r,n)}function S(t){if(t instanceof L)return new L(t.h,t.s,t.l,t.opacity);if(t instanceof n||(t=v(t)),!t)return new L;if(t instanceof L)return t;var e=(t=t.rgb()).r/255,r=t.g/255,i=t.b/255,a=Math.min(e,r,i),o=Math.max(e,r,i),s=NaN,l=o-a,c=(o+a)/2;return l?(s=e===o?(r-i)/l+6*(r<i):r===o?(i-e)/l+2:(e-r)/l+4,l/=c<.5?o+a:2-o-a,s*=60):l=c>0&&c<1?0:s,new L(s,l,c,t.opacity)}function E(t,e,r,n){return 1===arguments.length?S(t):new L(t,e,r,null==n?1:n)}function L(t,e,r,n){this.h=+t,this.s=+e,this.l=+r,this.opacity=+n}function C(t,e,r){return 255*(t<60?e+(r-e)*t/60:t<180?r:t<240?e+(r-e)*(240-t)/60:e)}e(n,v,{copy:function(t){return Object.assign(new this.constructor,this,t)},displayable:function(){return this.rgb().displayable()},hex:m,formatHex:m,formatHsl:function(){return S(this).formatHsl()},formatRgb:g,toString:g}),e(w,_,r(n,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new w(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new w(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:T,formatHex:T,formatRgb:k,toString:k})),e(L,E,r(n,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new L(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new L(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,r=this.l,n=r+(r<.5?r:1-r)*e,i=2*r-n;return new w(C(t>=240?t-240:t+120,i,n),C(t,i,n),C(t<120?t+240:t-120,i,n),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"hsl(":"hsla(")+(this.h||0)+", "+100*(this.s||0)+"%, "+100*(this.l||0)+"%"+(1===t?")":", "+t+")")}}));var P=Math.PI/180,I=180/Math.PI,O=6/29,z=3*O*O;function D(t){if(t instanceof F)return new F(t.l,t.a,t.b,t.opacity);if(t instanceof q)return G(t);t instanceof w||(t=b(t));var e,r,n=U(t.r),i=U(t.g),a=U(t.b),o=B((.2225045*n+.7168786*i+.0606169*a)/1);return n===i&&i===a?e=r=o:(e=B((.4360747*n+.3850649*i+.1430804*a)/.96422),r=B((.0139322*n+.0971045*i+.7141733*a)/.82521)),new F(116*o-16,500*(e-o),200*(o-r),t.opacity)}function R(t,e,r,n){return 1===arguments.length?D(t):new F(t,e,r,null==n?1:n)}function F(t,e,r,n){this.l=+t,this.a=+e,this.b=+r,this.opacity=+n}function B(t){return t>.008856451679035631?Math.pow(t,1/3):t/z+4/29}function N(t){return t>O?t*t*t:z*(t-4/29)}function j(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function U(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function V(t){if(t instanceof q)return new q(t.h,t.c,t.l,t.opacity);if(t instanceof F||(t=D(t)),0===t.a&&0===t.b)return new q(NaN,0<t.l&&t.l<100?0:NaN,t.l,t.opacity);var e=Math.atan2(t.b,t.a)*I;return new q(e<0?e+360:e,Math.sqrt(t.a*t.a+t.b*t.b),t.l,t.opacity)}function H(t,e,r,n){return 1===arguments.length?V(t):new q(t,e,r,null==n?1:n)}function q(t,e,r,n){this.h=+t,this.c=+e,this.l=+r,this.opacity=+n}function G(t){if(isNaN(t.h))return new F(t.l,0,0,t.opacity);var e=t.h*P;return new F(t.l,Math.cos(e)*t.c,Math.sin(e)*t.c,t.opacity)}e(F,R,r(n,{brighter:function(t){return new F(this.l+18*(null==t?1:t),this.a,this.b,this.opacity)},darker:function(t){return new F(this.l-18*(null==t?1:t),this.a,this.b,this.opacity)},rgb:function(){var t=(this.l+16)/116,e=isNaN(this.a)?t:t+this.a/500,r=isNaN(this.b)?t:t-this.b/200;return new w(j(3.1338561*(e=.96422*N(e))-1.6168667*(t=1*N(t))-.4906146*(r=.82521*N(r))),j(-.9787684*e+1.9161415*t+.033454*r),j(.0719453*e-.2289914*t+1.4052427*r),this.opacity)}})),e(q,H,r(n,{brighter:function(t){return new q(this.h,this.c,this.l+18*(null==t?1:t),this.opacity)},darker:function(t){return new q(this.h,this.c,this.l-18*(null==t?1:t),this.opacity)},rgb:function(){return G(this).rgb()}}));var Y=-.14861,W=1.78277,X=-.29227,Z=-.90649,J=1.97294,K=J*Z,Q=J*W,$=W*X-Z*Y;function tt(t){if(t instanceof rt)return new rt(t.h,t.s,t.l,t.opacity);t instanceof w||(t=b(t));var e=t.r/255,r=t.g/255,n=t.b/255,i=($*n+K*e-Q*r)/($+K-Q),a=n-i,o=(J*(r-i)-X*a)/Z,s=Math.sqrt(o*o+a*a)/(J*i*(1-i)),l=s?Math.atan2(o,a)*I-120:NaN;return new rt(l<0?l+360:l,s,i,t.opacity)}function et(t,e,r,n){return 1===arguments.length?tt(t):new rt(t,e,r,null==n?1:n)}function rt(t,e,r,n){this.h=+t,this.s=+e,this.l=+r,this.opacity=+n}e(rt,et,r(n,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new rt(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new rt(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=isNaN(this.h)?0:(this.h+120)*P,e=+this.l,r=isNaN(this.s)?0:this.s*e*(1-e),n=Math.cos(t),i=Math.sin(t);return new w(255*(e+r*(Y*n+W*i)),255*(e+r*(X*n+Z*i)),255*(e+r*(J*n)),this.opacity)}})),t.color=v,t.cubehelix=et,t.gray=function(t,e){return new F(t,0,0,null==e?1:e)},t.hcl=H,t.hsl=E,t.lab=R,t.lch=function(t,e,r,n){return 1===arguments.length?V(t):new q(r,e,t,null==n?1:n)},t.rgb=_,Object.defineProperty(t,"__esModule",{value:!0})}))},{}],110:[function(t,e,r){!function(t,n){"object"==typeof r&&void 0!==e?n(r):n((t=t||self).d3=t.d3||{})}(this,(function(t){"use strict";var e={value:function(){}};function r(){for(var t,e=0,r=arguments.length,i={};e<r;++e){if(!(t=arguments[e]+"")||t in i||/[\s.]/.test(t))throw new Error("illegal type: "+t);i[t]=[]}return new n(i)}function n(t){this._=t}function i(t,e){return t.trim().split(/^|\s+/).map((function(t){var r="",n=t.indexOf(".");if(n>=0&&(r=t.slice(n+1),t=t.slice(0,n)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:r}}))}function a(t,e){for(var r,n=0,i=t.length;n<i;++n)if((r=t[n]).name===e)return r.value}function o(t,r,n){for(var i=0,a=t.length;i<a;++i)if(t[i].name===r){t[i]=e,t=t.slice(0,i).concat(t.slice(i+1));break}return null!=n&&t.push({name:r,value:n}),t}n.prototype=r.prototype={constructor:n,on:function(t,e){var r,n=this._,s=i(t+"",n),l=-1,c=s.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++l<c;)if(r=(t=s[l]).type)n[r]=o(n[r],t.name,e);else if(null==e)for(r in n)n[r]=o(n[r],t.name,null);return this}for(;++l<c;)if((r=(t=s[l]).type)&&(r=a(n[r],t.name)))return r},copy:function(){var t={},e=this._;for(var r in e)t[r]=e[r].slice();return new n(t)},call:function(t,e){if((r=arguments.length-2)>0)for(var r,n,i=new Array(r),a=0;a<r;++a)i[a]=arguments[a+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(a=0,r=(n=this._[t]).length;a<r;++a)n[a].value.apply(e,i)},apply:function(t,e,r){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var n=this._[t],i=0,a=n.length;i<a;++i)n[i].value.apply(e,r)}},t.dispatch=r,Object.defineProperty(t,"__esModule",{value:!0})}))},{}],111:[function(t,e,r){!function(n,i){"object"==typeof r&&void 0!==e?i(r,t("d3-quadtree"),t("d3-collection"),t("d3-dispatch"),t("d3-timer")):i(n.d3=n.d3||{},n.d3,n.d3,n.d3,n.d3)}(this,(function(t,e,r,n,i){"use strict";function a(t){return function(){return t}}function o(){return 1e-6*(Math.random()-.5)}function s(t){return t.x+t.vx}function l(t){return t.y+t.vy}function c(t){return t.index}function u(t,e){var r=t.get(e);if(!r)throw new Error("missing: "+e);return r}function f(t){return t.x}function h(t){return t.y}var p=Math.PI*(3-Math.sqrt(5));t.forceCenter=function(t,e){var r;function n(){var n,i,a=r.length,o=0,s=0;for(n=0;n<a;++n)o+=(i=r[n]).x,s+=i.y;for(o=o/a-t,s=s/a-e,n=0;n<a;++n)(i=r[n]).x-=o,i.y-=s}return null==t&&(t=0),null==e&&(e=0),n.initialize=function(t){r=t},n.x=function(e){return arguments.length?(t=+e,n):t},n.y=function(t){return arguments.length?(e=+t,n):e},n},t.forceCollide=function(t){var r,n,i=1,c=1;function u(){for(var t,a,u,h,p,d,m,g=r.length,v=0;v<c;++v)for(a=e.quadtree(r,s,l).visitAfter(f),t=0;t<g;++t)u=r[t],d=n[u.index],m=d*d,h=u.x+u.vx,p=u.y+u.vy,a.visit(y);function y(t,e,r,n,a){var s=t.data,l=t.r,c=d+l;if(!s)return e>h+c||n<h-c||r>p+c||a<p-c;if(s.index>u.index){var f=h-s.x-s.vx,g=p-s.y-s.vy,v=f*f+g*g;v<c*c&&(0===f&&(v+=(f=o())*f),0===g&&(v+=(g=o())*g),v=(c-(v=Math.sqrt(v)))/v*i,u.vx+=(f*=v)*(c=(l*=l)/(m+l)),u.vy+=(g*=v)*c,s.vx-=f*(c=1-c),s.vy-=g*c)}}}function f(t){if(t.data)return t.r=n[t.data.index];for(var e=t.r=0;e<4;++e)t[e]&&t[e].r>t.r&&(t.r=t[e].r)}function h(){if(r){var e,i,a=r.length;for(n=new Array(a),e=0;e<a;++e)i=r[e],n[i.index]=+t(i,e,r)}}return"function"!=typeof t&&(t=a(null==t?1:+t)),u.initialize=function(t){r=t,h()},u.iterations=function(t){return arguments.length?(c=+t,u):c},u.strength=function(t){return arguments.length?(i=+t,u):i},u.radius=function(e){return arguments.length?(t="function"==typeof e?e:a(+e),h(),u):t},u},t.forceLink=function(t){var e,n,i,s,l,f=c,h=function(t){return 1/Math.min(s[t.source.index],s[t.target.index])},p=a(30),d=1;function m(r){for(var i=0,a=t.length;i<d;++i)for(var s,c,u,f,h,p,m,g=0;g<a;++g)c=(s=t[g]).source,f=(u=s.target).x+u.vx-c.x-c.vx||o(),h=u.y+u.vy-c.y-c.vy||o(),f*=p=((p=Math.sqrt(f*f+h*h))-n[g])/p*r*e[g],h*=p,u.vx-=f*(m=l[g]),u.vy-=h*m,c.vx+=f*(m=1-m),c.vy+=h*m}function g(){if(i){var a,o,c=i.length,h=t.length,p=r.map(i,f);for(a=0,s=new Array(c);a<h;++a)(o=t[a]).index=a,"object"!=typeof o.source&&(o.source=u(p,o.source)),"object"!=typeof o.target&&(o.target=u(p,o.target)),s[o.source.index]=(s[o.source.index]||0)+1,s[o.target.index]=(s[o.target.index]||0)+1;for(a=0,l=new Array(h);a<h;++a)o=t[a],l[a]=s[o.source.index]/(s[o.source.index]+s[o.target.index]);e=new Array(h),v(),n=new Array(h),y()}}function v(){if(i)for(var r=0,n=t.length;r<n;++r)e[r]=+h(t[r],r,t)}function y(){if(i)for(var e=0,r=t.length;e<r;++e)n[e]=+p(t[e],e,t)}return null==t&&(t=[]),m.initialize=function(t){i=t,g()},m.links=function(e){return arguments.length?(t=e,g(),m):t},m.id=function(t){return arguments.length?(f=t,m):f},m.iterations=function(t){return arguments.length?(d=+t,m):d},m.strength=function(t){return arguments.length?(h="function"==typeof t?t:a(+t),v(),m):h},m.distance=function(t){return arguments.length?(p="function"==typeof t?t:a(+t),y(),m):p},m},t.forceManyBody=function(){var t,r,n,i,s=a(-30),l=1,c=1/0,u=.81;function p(i){var a,o=t.length,s=e.quadtree(t,f,h).visitAfter(m);for(n=i,a=0;a<o;++a)r=t[a],s.visit(g)}function d(){if(t){var e,r,n=t.length;for(i=new Array(n),e=0;e<n;++e)r=t[e],i[r.index]=+s(r,e,t)}}function m(t){var e,r,n,a,o,s=0,l=0;if(t.length){for(n=a=o=0;o<4;++o)(e=t[o])&&(r=Math.abs(e.value))&&(s+=e.value,l+=r,n+=r*e.x,a+=r*e.y);t.x=n/l,t.y=a/l}else{(e=t).x=e.data.x,e.y=e.data.y;do{s+=i[e.data.index]}while(e=e.next)}t.value=s}function g(t,e,a,s){if(!t.value)return!0;var f=t.x-r.x,h=t.y-r.y,p=s-e,d=f*f+h*h;if(p*p/u<d)return d<c&&(0===f&&(d+=(f=o())*f),0===h&&(d+=(h=o())*h),d<l&&(d=Math.sqrt(l*d)),r.vx+=f*t.value*n/d,r.vy+=h*t.value*n/d),!0;if(!(t.length||d>=c)){(t.data!==r||t.next)&&(0===f&&(d+=(f=o())*f),0===h&&(d+=(h=o())*h),d<l&&(d=Math.sqrt(l*d)));do{t.data!==r&&(p=i[t.data.index]*n/d,r.vx+=f*p,r.vy+=h*p)}while(t=t.next)}}return p.initialize=function(e){t=e,d()},p.strength=function(t){return arguments.length?(s="function"==typeof t?t:a(+t),d(),p):s},p.distanceMin=function(t){return arguments.length?(l=t*t,p):Math.sqrt(l)},p.distanceMax=function(t){return arguments.length?(c=t*t,p):Math.sqrt(c)},p.theta=function(t){return arguments.length?(u=t*t,p):Math.sqrt(u)},p},t.forceRadial=function(t,e,r){var n,i,o,s=a(.1);function l(t){for(var a=0,s=n.length;a<s;++a){var l=n[a],c=l.x-e||1e-6,u=l.y-r||1e-6,f=Math.sqrt(c*c+u*u),h=(o[a]-f)*i[a]*t/f;l.vx+=c*h,l.vy+=u*h}}function c(){if(n){var e,r=n.length;for(i=new Array(r),o=new Array(r),e=0;e<r;++e)o[e]=+t(n[e],e,n),i[e]=isNaN(o[e])?0:+s(n[e],e,n)}}return"function"!=typeof t&&(t=a(+t)),null==e&&(e=0),null==r&&(r=0),l.initialize=function(t){n=t,c()},l.strength=function(t){return arguments.length?(s="function"==typeof t?t:a(+t),c(),l):s},l.radius=function(e){return arguments.length?(t="function"==typeof e?e:a(+e),c(),l):t},l.x=function(t){return arguments.length?(e=+t,l):e},l.y=function(t){return arguments.length?(r=+t,l):r},l},t.forceSimulation=function(t){var e,a=1,o=.001,s=1-Math.pow(o,1/300),l=0,c=.6,u=r.map(),f=i.timer(d),h=n.dispatch("tick","end");function d(){m(),h.call("tick",e),a<o&&(f.stop(),h.call("end",e))}function m(r){var n,i,o=t.length;void 0===r&&(r=1);for(var f=0;f<r;++f)for(a+=(l-a)*s,u.each((function(t){t(a)})),n=0;n<o;++n)null==(i=t[n]).fx?i.x+=i.vx*=c:(i.x=i.fx,i.vx=0),null==i.fy?i.y+=i.vy*=c:(i.y=i.fy,i.vy=0);return e}function g(){for(var e,r=0,n=t.length;r<n;++r){if((e=t[r]).index=r,null!=e.fx&&(e.x=e.fx),null!=e.fy&&(e.y=e.fy),isNaN(e.x)||isNaN(e.y)){var i=10*Math.sqrt(r),a=r*p;e.x=i*Math.cos(a),e.y=i*Math.sin(a)}(isNaN(e.vx)||isNaN(e.vy))&&(e.vx=e.vy=0)}}function v(e){return e.initialize&&e.initialize(t),e}return null==t&&(t=[]),g(),e={tick:m,restart:function(){return f.restart(d),e},stop:function(){return f.stop(),e},nodes:function(r){return arguments.length?(t=r,g(),u.each(v),e):t},alpha:function(t){return arguments.length?(a=+t,e):a},alphaMin:function(t){return arguments.length?(o=+t,e):o},alphaDecay:function(t){return arguments.length?(s=+t,e):+s},alphaTarget:function(t){return arguments.length?(l=+t,e):l},velocityDecay:function(t){return arguments.length?(c=1-t,e):1-c},force:function(t,r){return arguments.length>1?(null==r?u.remove(t):u.set(t,v(r)),e):u.get(t)},find:function(e,r,n){var i,a,o,s,l,c=0,u=t.length;for(null==n?n=1/0:n*=n,c=0;c<u;++c)(o=(i=e-(s=t[c]).x)*i+(a=r-s.y)*a)<n&&(l=s,n=o);return l},on:function(t,r){return arguments.length>1?(h.on(t,r),e):h.on(t)}}},t.forceX=function(t){var e,r,n,i=a(.1);function o(t){for(var i,a=0,o=e.length;a<o;++a)(i=e[a]).vx+=(n[a]-i.x)*r[a]*t}function s(){if(e){var a,o=e.length;for(r=new Array(o),n=new Array(o),a=0;a<o;++a)r[a]=isNaN(n[a]=+t(e[a],a,e))?0:+i(e[a],a,e)}}return"function"!=typeof t&&(t=a(null==t?0:+t)),o.initialize=function(t){e=t,s()},o.strength=function(t){return arguments.length?(i="function"==typeof t?t:a(+t),s(),o):i},o.x=function(e){return arguments.length?(t="function"==typeof e?e:a(+e),s(),o):t},o},t.forceY=function(t){var e,r,n,i=a(.1);function o(t){for(var i,a=0,o=e.length;a<o;++a)(i=e[a]).vy+=(n[a]-i.y)*r[a]*t}function s(){if(e){var a,o=e.length;for(r=new Array(o),n=new Array(o),a=0;a<o;++a)r[a]=isNaN(n[a]=+t(e[a],a,e))?0:+i(e[a],a,e)}}return"function"!=typeof t&&(t=a(null==t?0:+t)),o.initialize=function(t){e=t,s()},o.strength=function(t){return arguments.length?(i="function"==typeof t?t:a(+t),s(),o):i},o.y=function(e){return arguments.length?(t="function"==typeof e?e:a(+e),s(),o):t},o},Object.defineProperty(t,"__esModule",{value:!0})}))},{"d3-collection":108,"d3-dispatch":110,"d3-quadtree":118,"d3-timer":123}],112:[function(t,e,r){!function(t,n){"object"==typeof r&&void 0!==e?n(r):n((t="undefined"!=typeof globalThis?globalThis:t||self).d3=t.d3||{})}(this,(function(t){"use strict";function e(t,e){if((r=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var r,n=t.slice(0,r);return[n.length>1?n[0]+n.slice(2):n,+t.slice(r+1)]}function r(t){return(t=e(Math.abs(t)))?t[1]:NaN}var n,i=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function a(t){if(!(e=i.exec(t)))throw new Error("invalid format: "+t);var e;return new o({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function o(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function s(t,r){var n=e(t,r);if(!n)return t+"";var i=n[0],a=n[1];return a<0?"0."+new Array(-a).join("0")+i:i.length>a+1?i.slice(0,a+1)+"."+i.slice(a+1):i+new Array(a-i.length+2).join("0")}a.prototype=o.prototype,o.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var l={"%":function(t,e){return(100*t).toFixed(e)},b:function(t){return Math.round(t).toString(2)},c:function(t){return t+""},d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:function(t,e){return t.toExponential(e)},f:function(t,e){return t.toFixed(e)},g:function(t,e){return t.toPrecision(e)},o:function(t){return Math.round(t).toString(8)},p:function(t,e){return s(100*t,e)},r:s,s:function(t,r){var i=e(t,r);if(!i)return t+"";var a=i[0],o=i[1],s=o-(n=3*Math.max(-8,Math.min(8,Math.floor(o/3))))+1,l=a.length;return s===l?a:s>l?a+new Array(s-l+1).join("0"):s>0?a.slice(0,s)+"."+a.slice(s):"0."+new Array(1-s).join("0")+e(t,Math.max(0,r+s-1))[0]},X:function(t){return Math.round(t).toString(16).toUpperCase()},x:function(t){return Math.round(t).toString(16)}};function c(t){return t}var u,f=Array.prototype.map,h=["y","z","a","f","p","n","\xb5","m","","k","M","G","T","P","E","Z","Y"];function p(t){var e,i,o=void 0===t.grouping||void 0===t.thousands?c:(e=f.call(t.grouping,Number),i=t.thousands+"",function(t,r){for(var n=t.length,a=[],o=0,s=e[0],l=0;n>0&&s>0&&(l+s+1>r&&(s=Math.max(1,r-l)),a.push(t.substring(n-=s,n+s)),!((l+=s+1)>r));)s=e[o=(o+1)%e.length];return a.reverse().join(i)}),s=void 0===t.currency?"":t.currency[0]+"",u=void 0===t.currency?"":t.currency[1]+"",p=void 0===t.decimal?".":t.decimal+"",d=void 0===t.numerals?c:function(t){return function(e){return e.replace(/[0-9]/g,(function(e){return t[+e]}))}}(f.call(t.numerals,String)),m=void 0===t.percent?"%":t.percent+"",g=void 0===t.minus?"-":t.minus+"",v=void 0===t.nan?"NaN":t.nan+"";function y(t){var e=(t=a(t)).fill,r=t.align,i=t.sign,c=t.symbol,f=t.zero,y=t.width,x=t.comma,b=t.precision,_=t.trim,w=t.type;"n"===w?(x=!0,w="g"):l[w]||(void 0===b&&(b=12),_=!0,w="g"),(f||"0"===e&&"="===r)&&(f=!0,e="0",r="=");var T="$"===c?s:"#"===c&&/[boxX]/.test(w)?"0"+w.toLowerCase():"",k="$"===c?u:/[%p]/.test(w)?m:"",A=l[w],M=/[defgprs%]/.test(w);function S(t){var a,s,l,c=T,u=k;if("c"===w)u=A(t)+u,t="";else{var m=(t=+t)<0||1/t<0;if(t=isNaN(t)?v:A(Math.abs(t),b),_&&(t=function(t){t:for(var e,r=t.length,n=1,i=-1;n<r;++n)switch(t[n]){case".":i=e=n;break;case"0":0===i&&(i=n),e=n;break;default:if(!+t[n])break t;i>0&&(i=0)}return i>0?t.slice(0,i)+t.slice(e+1):t}(t)),m&&0==+t&&"+"!==i&&(m=!1),c=(m?"("===i?i:g:"-"===i||"("===i?"":i)+c,u=("s"===w?h[8+n/3]:"")+u+(m&&"("===i?")":""),M)for(a=-1,s=t.length;++a<s;)if(48>(l=t.charCodeAt(a))||l>57){u=(46===l?p+t.slice(a+1):t.slice(a))+u,t=t.slice(0,a);break}}x&&!f&&(t=o(t,1/0));var S=c.length+t.length+u.length,E=S<y?new Array(y-S+1).join(e):"";switch(x&&f&&(t=o(E+t,E.length?y-u.length:1/0),E=""),r){case"<":t=c+t+u+E;break;case"=":t=c+E+t+u;break;case"^":t=E.slice(0,S=E.length>>1)+c+t+u+E.slice(S);break;default:t=E+c+t+u}return d(t)}return b=void 0===b?6:/[gprs]/.test(w)?Math.max(1,Math.min(21,b)):Math.max(0,Math.min(20,b)),S.toString=function(){return t+""},S}return{format:y,formatPrefix:function(t,e){var n=y(((t=a(t)).type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor(r(e)/3))),o=Math.pow(10,-i),s=h[8+i/3];return function(t){return n(o*t)+s}}}}function d(e){return u=p(e),t.format=u.format,t.formatPrefix=u.formatPrefix,u}d({decimal:".",thousands:",",grouping:[3],currency:["$",""],minus:"-"}),t.FormatSpecifier=o,t.formatDefaultLocale=d,t.formatLocale=p,t.formatSpecifier=a,t.precisionFixed=function(t){return Math.max(0,-r(Math.abs(t)))},t.precisionPrefix=function(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(r(e)/3)))-r(Math.abs(t)))},t.precisionRound=function(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,r(e)-r(t))+1},Object.defineProperty(t,"__esModule",{value:!0})}))},{}],113:[function(t,e,r){!function(n,i){"object"==typeof r&&void 0!==e?i(r,t("d3-geo"),t("d3-array")):i(n.d3=n.d3||{},n.d3,n.d3)}(this,(function(t,e,r){"use strict";var n=Math.abs,i=Math.atan,a=Math.atan2,o=Math.cos,s=Math.exp,l=Math.floor,c=Math.log,u=Math.max,f=Math.min,h=Math.pow,p=Math.round,d=Math.sign||function(t){return t>0?1:t<0?-1:0},m=Math.sin,g=Math.tan,v=1e-6,y=Math.PI,x=y/2,b=y/4,_=Math.SQRT1_2,w=L(2),T=L(y),k=2*y,A=180/y,M=y/180;function S(t){return t>1?x:t<-1?-x:Math.asin(t)}function E(t){return t>1?0:t<-1?y:Math.acos(t)}function L(t){return t>0?Math.sqrt(t):0}function C(t){return(s(t)-s(-t))/2}function P(t){return(s(t)+s(-t))/2}function I(t){var e=g(t/2),r=2*c(o(t/2))/(e*e);function i(t,e){var n=o(t),i=o(e),a=m(e),s=i*n,l=-((1-s?c((1+s)/2)/(1-s):-.5)+r/(1+s));return[l*i*m(t),l*a]}return i.invert=function(e,i){var s,l=L(e*e+i*i),u=-t/2,f=50;if(!l)return[0,0];do{var h=u/2,p=o(h),d=m(h),g=d/p,y=-c(n(p));u-=s=(2/g*y-r*g-l)/(-y/(d*d)+1-r/(2*p*p))*(p<0?.7:1)}while(n(s)>v&&--f>0);var x=m(u);return[a(e*x,l*o(u)),S(i*x/l)]},i}function O(t,e){var r=o(e),n=function(t){return t?t/Math.sin(t):1}(E(r*o(t/=2)));return[2*r*m(t)*n,m(e)*n]}function z(t){var e=m(t),r=o(t),i=t>=0?1:-1,s=g(i*t),l=(1+e-r)/2;function c(t,n){var c=o(n),u=o(t/=2);return[(1+c)*m(t),(i*n>-a(u,s)-.001?0:10*-i)+l+m(n)*r-(1+c)*e*u]}return c.invert=function(t,c){var u=0,f=0,h=50;do{var p=o(u),d=m(u),g=o(f),y=m(f),x=1+g,b=x*d-t,_=l+y*r-x*e*p-c,w=x*p/2,T=-d*y,k=e*x*d/2,A=r*g+e*p*y,M=T*k-A*w,S=(_*T-b*A)/M/2,E=(b*k-_*w)/M;n(E)>2&&(E/=2),u-=S,f-=E}while((n(S)>v||n(E)>v)&&--h>0);return i*f>-a(o(u),s)-.001?[2*u,f]:null},c}function D(t,e){var r=g(e/2),n=L(1-r*r),i=1+n*o(t/=2),a=m(t)*n/i,s=r/i,l=a*a,c=s*s;return[4/3*a*(3+l-3*c),4/3*s*(3+3*l-c)]}O.invert=function(t,e){if(!(t*t+4*e*e>y*y+v)){var r=t,i=e,a=25;do{var s,l=m(r),c=m(r/2),u=o(r/2),f=m(i),h=o(i),p=m(2*i),d=f*f,g=h*h,x=c*c,b=1-g*u*u,_=b?E(h*u)*L(s=1/b):s=0,w=2*_*h*c-t,T=_*f-e,k=s*(g*x+_*h*u*d),A=s*(.5*l*p-2*_*f*c),M=.25*s*(p*c-_*f*g*l),S=s*(d*u+_*x*h),C=A*M-S*k;if(!C)break;var P=(T*A-w*S)/C,I=(w*M-T*k)/C;r-=P,i-=I}while((n(P)>v||n(I)>v)&&--a>0);return[r,i]}},D.invert=function(t,e){if(e*=3/8,!(t*=3/8)&&n(e)>1)return null;var r=1+t*t+e*e,i=L((r-L(r*r-4*e*e))/2),s=S(i)/3,l=i?function(t){return c(t+L(t*t-1))}(n(e/i))/3:function(t){return c(t+L(t*t+1))}(n(t))/3,u=o(s),f=P(l),h=f*f-u*u;return[2*d(t)*a(C(l)*u,.25-h),2*d(e)*a(f*m(s),.25+h)]};var R=L(8),F=c(1+w);function B(t,e){var r=n(e);return r<b?[t,c(g(b+e/2))]:[t*o(r)*(2*w-1/m(r)),d(e)*(2*w*(r-b)-c(g(r/2)))]}function N(t){var r=2*y/t;function s(t,i){var s=e.geoAzimuthalEquidistantRaw(t,i);if(n(t)>x){var l=a(s[1],s[0]),c=L(s[0]*s[0]+s[1]*s[1]),u=r*p((l-x)/r)+x,f=a(m(l-=u),2-o(l));l=u+S(y/c*m(f))-f,s[0]=c*o(l),s[1]=c*m(l)}return s}return s.invert=function(t,n){var s=L(t*t+n*n);if(s>x){var l=a(n,t),c=r*p((l-x)/r)+x,u=l>c?-1:1,f=s*o(c-l),h=1/g(u*E((f-y)/L(y*(y-2*f)+s*s)));l=c+2*i((h+u*L(h*h-3))/3),t=s*o(l),n=s*m(l)}return e.geoAzimuthalEquidistantRaw.invert(t,n)},s}function j(t,r){if(arguments.length<2&&(r=t),1===r)return e.geoAzimuthalEqualAreaRaw;if(r===1/0)return U;function n(n,i){var a=e.geoAzimuthalEqualAreaRaw(n/r,i);return a[0]*=t,a}return n.invert=function(n,i){var a=e.geoAzimuthalEqualAreaRaw.invert(n/t,i);return a[0]*=r,a},n}function U(t,e){return[t*o(e)/o(e/=2),2*m(e)]}function V(t,e,r){var i,a,o,s=100;r=void 0===r?0:+r,e=+e;do{(a=t(r))===(o=t(r+v))&&(o=a+v),r-=i=-1*v*(a-e)/(a-o)}while(s-- >0&&n(i)>v);return s<0?NaN:r}function H(t,e,r){return void 0===e&&(e=40),void 0===r&&(r=1e-12),function(i,a,o,s){var l,c,u;o=void 0===o?0:+o,s=void 0===s?0:+s;for(var f=0;f<e;f++){var h=t(o,s),p=h[0]-i,d=h[1]-a;if(n(p)<r&&n(d)<r)break;var m=p*p+d*d;if(m>l)o-=c/=2,s-=u/=2;else{l=m;var g=(o>0?-1:1)*r,v=(s>0?-1:1)*r,y=t(o+g,s),x=t(o,s+v),b=(y[0]-h[0])/g,_=(y[1]-h[1])/g,w=(x[0]-h[0])/v,T=(x[1]-h[1])/v,k=T*b-_*w,A=(n(k)<.5?.5:1)/k;if(o+=c=(d*w-p*T)*A,s+=u=(p*_-d*b)*A,n(c)<r&&n(u)<r)break}}return[o,s]}}function q(){var t=j(1.68,2);function e(e,r){if(e+r<-1.4){var n=(e-r+1.6)*(e+r+1.4)/8;e+=n,r-=.8*n*m(r+y/2)}var i=t(e,r),a=(1-o(e*r))/12;return i[1]<0&&(i[0]*=1+a),i[1]>0&&(i[1]*=1+a/1.5*i[0]*i[0]),i}return e.invert=H(e),e}function G(t,e){var r,i=t*m(e),a=30;do{e-=r=(e+m(e)-i)/(1+o(e))}while(n(r)>v&&--a>0);return e/2}function Y(t,e,r){function n(n,i){return[t*n*o(i=G(r,i)),e*m(i)]}return n.invert=function(n,i){return i=S(i/e),[n/(t*o(i)),S((2*i+m(2*i))/r)]},n}B.invert=function(t,e){if((a=n(e))<F)return[t,2*i(s(e))-x];var r,a,l=b,u=25;do{var f=o(l/2),h=g(l/2);l-=r=(R*(l-b)-c(h)-a)/(R-f*f/(2*h))}while(n(r)>1e-12&&--u>0);return[t/(o(l)*(R-1/m(l))),d(e)*l]},U.invert=function(t,e){var r=2*S(e/2);return[t*o(r/2)/o(r),r]};var W=Y(w/x,w,y);var X=2.00276,Z=1.11072;function J(t,e){var r=G(y,e);return[X*t/(1/o(e)+Z/o(r)),(e+w*m(r))/X]}function K(t){var r=0,n=e.geoProjectionMutator(t),i=n(r);return i.parallel=function(t){return arguments.length?n(r=t*M):r*A},i}function Q(t,e){return[t*o(e),e]}function $(t){if(!t)return Q;var e=1/g(t);function r(r,n){var i=e+t-n,a=i?r*o(n)/i:i;return[i*m(a),e-i*o(a)]}return r.invert=function(r,n){var i=L(r*r+(n=e-n)*n),s=e+t-i;return[i/o(s)*a(r,n),s]},r}function tt(t){function e(e,r){var n=x-r,i=n?e*t*m(n)/n:n;return[n*m(i)/t,x-n*o(i)]}return e.invert=function(e,r){var n=e*t,i=x-r,o=L(n*n+i*i),s=a(n,i);return[(o?o/m(o):1)*s/t,x-o]},e}J.invert=function(t,e){var r,i,a=X*e,s=e<0?-b:b,l=25;do{i=a-w*m(s),s-=r=(m(2*s)+2*s-y*m(i))/(2*o(2*s)+2+y*o(i)*w*o(s))}while(n(r)>v&&--l>0);return i=a-w*m(s),[t*(1/o(i)+Z/o(s))/X,i]},Q.invert=function(t,e){return[t/o(e),e]};var et=Y(1,4/y,y);function rt(t,e,r,i,s,l){var c,u=o(l);if(n(t)>1||n(l)>1)c=E(r*s+e*i*u);else{var f=m(t/2),h=m(l/2);c=2*S(L(f*f+e*i*h*h))}return n(c)>v?[c,a(i*m(l),e*s-r*i*u)]:[0,0]}function nt(t,e,r){return E((t*t+e*e-r*r)/(2*t*e))}function it(t){return t-2*y*l((t+y)/(2*y))}function at(t,e,r){for(var n,i=[[t[0],t[1],m(t[1]),o(t[1])],[e[0],e[1],m(e[1]),o(e[1])],[r[0],r[1],m(r[1]),o(r[1])]],a=i[2],s=0;s<3;++s,a=n)n=i[s],a.v=rt(n[1]-a[1],a[3],a[2],n[3],n[2],n[0]-a[0]),a.point=[0,0];var l=nt(i[0].v[0],i[2].v[0],i[1].v[0]),c=nt(i[0].v[0],i[1].v[0],i[2].v[0]),u=y-l;i[2].point[1]=0,i[0].point[0]=-(i[1].point[0]=i[0].v[0]/2);var f=[i[2].point[0]=i[0].point[0]+i[2].v[0]*o(l),2*(i[0].point[1]=i[1].point[1]=i[2].v[0]*m(l))];return function(t,e){var r,n=m(e),a=o(e),s=new Array(3);for(r=0;r<3;++r){var l=i[r];if(s[r]=rt(e-l[1],l[3],l[2],a,n,t-l[0]),!s[r][0])return l.point;s[r][1]=it(s[r][1]-l.v[1])}var h=f.slice();for(r=0;r<3;++r){var p=2==r?0:r+1,d=nt(i[r].v[0],s[r][0],s[p][0]);s[r][1]<0&&(d=-d),r?1==r?(d=c-d,h[0]-=s[r][0]*o(d),h[1]-=s[r][0]*m(d)):(d=u-d,h[0]+=s[r][0]*o(d),h[1]+=s[r][0]*m(d)):(h[0]+=s[r][0]*o(d),h[1]-=s[r][0]*m(d))}return h[0]/=3,h[1]/=3,h}}function ot(t){return t[0]*=M,t[1]*=M,t}function st(t,r,n){var i=e.geoCentroid({type:"MultiPoint",coordinates:[t,r,n]}),a=[-i[0],-i[1]],o=e.geoRotation(a),s=at(ot(o(t)),ot(o(r)),ot(o(n)));s.invert=H(s);var l=e.geoProjection(s).rotate(a),c=l.center;return delete l.rotate,l.center=function(t){return arguments.length?c(o(t)):o.invert(c())},l.clipAngle(90)}function lt(t,e){var r=L(1-m(e));return[2/T*t*r,T*(1-r)]}function ct(t){var e=g(t);function r(t,r){return[t,(t?t/m(t):1)*(m(r)*o(t)-e*o(r))]}return r.invert=e?function(t,r){t&&(r*=m(t)/t);var n=o(t);return[t,2*a(L(n*n+e*e-r*r)-n,e-r)]}:function(t,e){return[t,S(t?e*g(t)/t:e)]},r}lt.invert=function(t,e){var r=(r=e/T-1)*r;return[r>0?t*L(y/r)/2:0,S(1-r)]};var ut=L(3);function ft(t,e){return[ut*t*(2*o(2*e/3)-1)/T,ut*T*m(e/3)]}function ht(t){var e=o(t);function r(t,r){return[t*e,m(r)/e]}return r.invert=function(t,r){return[t/e,S(r*e)]},r}function pt(t){var e=o(t);function r(t,r){return[t*e,(1+e)*g(r/2)]}return r.invert=function(t,r){return[t/e,2*i(r/(1+e))]},r}function dt(t,e){var r=L(8/(3*y));return[r*t*(1-n(e)/y),r*e]}function mt(t,e){var r=L(4-3*m(n(e)));return[2/L(6*y)*t*r,d(e)*L(2*y/3)*(2-r)]}function gt(t,e){var r=L(y*(4+y));return[2/r*t*(1+L(1-4*e*e/(y*y))),4/r*e]}function vt(t,e){var r=(2+x)*m(e);e/=2;for(var i=0,a=1/0;i<10&&n(a)>v;i++){var s=o(e);e-=a=(e+m(e)*(s+2)-r)/(2*s*(1+s))}return[2/L(y*(4+y))*t*(1+o(e)),2*L(y/(4+y))*m(e)]}function yt(t,e){return[t*(1+o(e))/L(2+y),2*e/L(2+y)]}function xt(t,e){for(var r=(1+x)*m(e),i=0,a=1/0;i<10&&n(a)>v;i++)e-=a=(e+m(e)-r)/(1+o(e));return r=L(2+y),[t*(1+o(e))/r,2*e/r]}ft.invert=function(t,e){var r=3*S(e/(ut*T));return[T*t/(ut*(2*o(2*r/3)-1)),r]},dt.invert=function(t,e){var r=L(8/(3*y)),i=e/r;return[t/(r*(1-n(i)/y)),i]},mt.invert=function(t,e){var r=2-n(e)/L(2*y/3);return[t*L(6*y)/(2*r),d(e)*S((4-r*r)/3)]},gt.invert=function(t,e){var r=L(y*(4+y))/2;return[t*r/(1+L(1-e*e*(4+y)/(4*y))),e*r/2]},vt.invert=function(t,e){var r=e*L((4+y)/y)/2,n=S(r),i=o(n);return[t/(2/L(y*(4+y))*(1+i)),S((n+r*(i+2))/(2+x))]},yt.invert=function(t,e){var r=L(2+y),n=e*r/2;return[r*t/(1+o(n)),n]},xt.invert=function(t,e){var r=1+x,n=L(r/2);return[2*t*n/(1+o(e*=n)),S((e+m(e))/r)]};var bt=3+2*w;function _t(t,e){var r=m(t/=2),n=o(t),a=L(o(e)),s=o(e/=2),l=m(e)/(s+w*n*a),u=L(2/(1+l*l)),f=L((w*s+(n+r)*a)/(w*s+(n-r)*a));return[bt*(u*(f-1/f)-2*c(f)),bt*(u*l*(f+1/f)-2*i(l))]}_t.invert=function(t,e){if(!(r=D.invert(t/1.2,1.065*e)))return null;var r,a=r[0],s=r[1],l=20;t/=bt,e/=bt;do{var h=a/2,p=s/2,d=m(h),g=o(h),y=m(p),b=o(p),T=o(s),k=L(T),A=y/(b+w*g*k),M=A*A,S=L(2/(1+M)),E=(w*b+(g+d)*k)/(w*b+(g-d)*k),C=L(E),P=C-1/C,I=C+1/C,O=S*P-2*c(C)-t,z=S*A*I-2*i(A)-e,R=y&&_*k*d*M/y,F=(w*g*b+k)/(2*(b+w*g*k)*(b+w*g*k)*k),B=-.5*A*S*S*S,N=B*R,j=B*F,U=(U=2*b+w*k*(g-d))*U*C,V=(w*g*b*k+T)/U,H=-w*d*y/(k*U),q=P*N-2*V/C+S*(V+V/E),G=P*j-2*H/C+S*(H+H/E),Y=A*I*N-2*R/(1+M)+S*I*R+S*A*(V-V/E),W=A*I*j-2*F/(1+M)+S*I*F+S*A*(H-H/E),X=G*Y-W*q;if(!X)break;var Z=(z*G-O*W)/X,J=(O*Y-z*q)/X;a-=Z,s=u(-x,f(x,s-J))}while((n(Z)>v||n(J)>v)&&--l>0);return n(n(s)-x)<v?[0,s]:l&&[a,s]};var wt=o(35*M);function Tt(t,e){var r=g(e/2);return[t*wt*L(1-r*r),(1+wt)*r]}function kt(t,e){var r=e/2,n=o(r);return[2*t/T*o(e)*n*n,T*g(r)]}function At(t){var e=1-t,r=i(y,0)[0]-i(-y,0)[0],n=L(2*(i(0,x)[1]-i(0,-x)[1])/r);function i(r,n){var i=o(n),a=m(n);return[i/(e+t*i)*r,e*n+t*a]}function a(t,e){var r=i(t,e);return[r[0]*n,r[1]/n]}function s(t){return a(0,t)[1]}return a.invert=function(r,i){var a=V(s,i);return[r/n*(t+e/o(a)),a]},a}function Mt(t){return[t[0]/2,S(g(t[1]/2*M))*A]}function St(t){return[2*t[0],2*i(m(t[1]*M))*A]}function Et(t,r){var i=2*y/r,s=t*t;function l(r,l){var c=e.geoAzimuthalEquidistantRaw(r,l),u=c[0],f=c[1],h=u*u+f*f;if(h>s){var d=L(h),g=a(f,u),b=i*p(g/i),_=g-b,w=t*o(_),T=(t*m(_)-_*m(w))/(x-w),k=Lt(_,T),A=(y-t)/Ct(k,w,y);u=d;var M,S=50;do{u-=M=(t+Ct(k,w,u)*A-d)/(k(u)*A)}while(n(M)>v&&--S>0);f=_*m(u),u<x&&(f-=T*(u-x));var E=m(b),C=o(b);c[0]=u*C-f*E,c[1]=u*E+f*C}return c}return l.invert=function(r,l){var c=r*r+l*l;if(c>s){var u=L(c),f=a(l,r),h=i*p(f/i),d=f-h;r=u*o(d),l=u*m(d);for(var g=r-x,v=m(r),b=l/v,_=r<x?1/0:0,w=10;;){var T=t*m(b),k=t*o(b),A=m(k),M=x-k,S=(T-b*A)/M,E=Lt(b,S);if(n(_)<1e-12||!--w)break;b-=_=(b*v-S*g-l)/(v-2*g*(M*(k+b*T*o(k)-A)-T*(T-b*A))/(M*M))}r=(u=t+Ct(E,k,r)*(y-t)/Ct(E,k,y))*o(f=h+b),l=u*m(f)}return e.geoAzimuthalEquidistantRaw.invert(r,l)},l}function Lt(t,e){return function(r){var n=t*o(r);return r<x&&(n-=e),L(1+n*n)}}function Ct(t,e,r){for(var n=(r-e)/50,i=t(e)+t(r),a=1,o=e;a<50;++a)i+=2*t(o+=n);return.5*i*n}function Pt(t,e,r,i,a,s,l,c){function u(n,u){if(!u)return[t*n/y,0];var f=u*u,h=t+f*(e+f*(r+f*i)),p=u*(a-1+f*(s-c+f*l)),d=(h*h+p*p)/(2*p),g=n*S(h/d)/y;return[d*m(g),u*(1+f*c)+d*(1-o(g))]}return arguments.length<8&&(c=0),u.invert=function(u,f){var h,p,d=y*u/t,g=f,x=50;do{var b=g*g,_=t+b*(e+b*(r+b*i)),w=g*(a-1+b*(s-c+b*l)),T=_*_+w*w,k=2*w,A=T/k,M=A*A,E=S(_/A)/y,C=d*E,P=_*_,I=(2*e+b*(4*r+6*b*i))*g,O=a+b*(3*s+5*b*l),z=(2*(_*I+w*(O-1))*k-T*(2*(O-1)))/(k*k),D=o(C),R=m(C),F=A*D,B=A*R,N=d/y*(1/L(1-P/M))*(I*A-_*z)/M,j=B-u,U=g*(1+b*c)+A-F-f,V=z*R+F*N,H=F*E,q=1+z-(z*D-B*N),G=B*E,Y=V*G-q*H;if(!Y)break;d-=h=(U*V-j*q)/Y,g-=p=(j*G-U*H)/Y}while((n(h)>v||n(p)>v)&&--x>0);return[d,g]},u}Tt.invert=function(t,e){var r=e/(1+wt);return[t&&t/(wt*L(1-r*r)),2*i(r)]},kt.invert=function(t,e){var r=i(e/T),n=o(r),a=2*r;return[t*T/2/(o(a)*n*n),a]};var It=Pt(2.8284,-1.6988,.75432,-.18071,1.76003,-.38914,.042555);var Ot=Pt(2.583819,-.835827,.170354,-.038094,1.543313,-.411435,.082742);var zt=Pt(5/6*y,-.62636,-.0344,0,1.3493,-.05524,0,.045);function Dt(t,e){var r=t*t,n=e*e;return[t*(1-.162388*n)*(.87-952426e-9*r*r),e*(1+n/12)]}Dt.invert=function(t,e){var r,i=t,a=e,o=50;do{var s=a*a;a-=r=(a*(1+s/12)-e)/(1+s/4)}while(n(r)>v&&--o>0);o=50,t/=1-.162388*s;do{var l=(l=i*i)*l;i-=r=(i*(.87-952426e-9*l)-t)/(.87-.00476213*l)}while(n(r)>v&&--o>0);return[i,a]};var Rt=Pt(2.6516,-.76534,.19123,-.047094,1.36289,-.13965,.031762);function Ft(t){var e=t(x,0)[0]-t(-x,0)[0];function r(r,n){var i=r>0?-.5:.5,a=t(r+i*y,n);return a[0]-=i*e,a}return t.invert&&(r.invert=function(r,n){var i=r>0?-.5:.5,a=t.invert(r+i*e,n),o=a[0]-i*y;return o<-y?o+=2*y:o>y&&(o-=2*y),a[0]=o,a}),r}function Bt(t,e){var r=d(t),i=d(e),s=o(e),l=o(t)*s,c=m(t)*s,u=m(i*e);t=n(a(c,u)),e=S(l),n(t-x)>v&&(t%=x);var f=function(t,e){if(e===x)return[0,0];var r,i,a=m(e),s=a*a,l=s*s,c=1+l,u=1+3*l,f=1-l,h=S(1/L(c)),p=f+s*c*h,d=(1-a)/p,g=L(d),b=d*c,_=L(b),w=g*f;if(0===t)return[0,-(w+s*_)];var T,k=o(e),A=1/k,M=2*a*k,E=(-p*k-(-3*s+h*u)*M*(1-a))/(p*p),C=-A*M,P=-A*(s*c*E+d*u*M),I=-2*A*(f*(.5*E/g)-2*s*g*M),O=4*t/y;if(t>.222*y||e<y/4&&t>.175*y){if(r=(w+s*L(b*(1+l)-w*w))/(1+l),t>y/4)return[r,r];var z=r,D=.5*r;r=.5*(D+z),i=50;do{var R=L(b-r*r),F=r*(I+C*R)+P*S(r/_)-O;if(!F)break;F<0?D=r:z=r,r=.5*(D+z)}while(n(z-D)>v&&--i>0)}else{r=v,i=25;do{var B=r*r,N=L(b-B),j=I+C*N,U=r*j+P*S(r/_)-O,V=j+(P-C*B)/N;r-=T=N?U/V:0}while(n(T)>v&&--i>0)}return[r,-w-s*L(b-r*r)]}(t>y/4?x-t:t,e);return t>y/4&&(u=f[0],f[0]=-f[1],f[1]=-u),f[0]*=r,f[1]*=-i,f}function Nt(t,e){var r,a,l,c,u,f;if(e<v)return[(c=m(t))-(r=e*(t-c*(a=o(t)))/4)*a,a+r*c,1-e*c*c/2,t-r];if(e>=1-v)return r=(1-e)/4,l=1/(a=P(t)),[(c=((f=s(2*(f=t)))-1)/(f+1))+r*((u=a*C(t))-t)/(a*a),l-r*c*l*(u-t),l+r*c*l*(u+t),2*i(s(t))-x+r*(u-t)/a];var h=[1,0,0,0,0,0,0,0,0],p=[L(e),0,0,0,0,0,0,0,0],d=0;for(a=L(1-e),u=1;n(p[d]/h[d])>v&&d<8;)r=h[d++],p[d]=(r-a)/2,h[d]=(r+a)/2,a=L(r*a),u*=2;l=u*h[d]*t;do{l=(S(c=p[d]*m(a=l)/h[d])+l)/2}while(--d);return[m(l),c=o(l),c/o(l-a),l]}function jt(t,e){if(!e)return t;if(1===e)return c(g(t/2+b));for(var r=1,a=L(1-e),o=L(e),s=0;n(o)>v;s++){if(t%y){var l=i(a*g(t)/r);l<0&&(l+=y),t+=l+~~(t/y)*y}else t+=t;o=(r+a)/2,a=L(r*a),o=((r=o)-a)/2}return t/(h(2,s)*r)}function Ut(t,e){var r=(w-1)/(w+1),l=L(1-r*r),u=jt(x,l*l),f=c(g(y/4+n(e)/2)),h=s(-1*f)/L(r),p=function(t,e){var r=t*t,n=e+1,i=1-r-e*e;return[.5*((t>=0?x:-x)-a(i,2*t)),-.25*c(i*i+4*r)+.5*c(n*n+r)]}(h*o(-1*t),h*m(-1*t)),v=function(t,e,r){var a=n(t),o=C(n(e));if(a){var s=1/m(a),l=1/(g(a)*g(a)),c=-(l+r*(o*o*s*s)-1+r),u=(-c+L(c*c-4*((r-1)*l)))/2;return[jt(i(1/L(u)),r)*d(t),jt(i(L((u/l-1)/r)),1-r)*d(e)]}return[0,jt(i(o),1-r)*d(e)]}(p[0],p[1],l*l);return[-v[1],(e>=0?1:-1)*(.5*u-v[0])]}function Vt(t){var e=m(t),r=o(t),i=Ht(t);function s(t,a){var s=i(t,a);t=s[0],a=s[1];var l=m(a),c=o(a),u=o(t),f=E(e*l+r*c*u),h=m(f),p=n(h)>v?f/h:1;return[p*r*m(t),(n(t)>x?p:-p)*(e*c-r*l*u)]}return i.invert=Ht(-t),s.invert=function(t,r){var n=L(t*t+r*r),s=-m(n),l=o(n),c=n*l,u=-r*s,f=n*e,h=L(c*c+u*u-f*f),p=a(c*f+u*h,u*f-c*h),d=(n>x?-1:1)*a(t*s,n*o(p)*l+r*m(p)*s);return i.invert(d,p)},s}function Ht(t){var e=m(t),r=o(t);return function(t,n){var i=o(n),s=o(t)*i,l=m(t)*i,c=m(n);return[a(l,s*r-c*e),S(c*r+s*e)]}}Bt.invert=function(t,e){n(t)>1&&(t=2*d(t)-t),n(e)>1&&(e=2*d(e)-e);var r=d(t),i=d(e),s=-r*t,l=-i*e,c=l/s<1,u=function(t,e){var r=0,i=1,a=.5,s=50;for(;;){var l=a*a,c=L(a),u=S(1/L(1+l)),f=1-l+a*(1+l)*u,h=(1-c)/f,p=L(h),d=h*(1+l),m=p*(1-l),g=L(d-t*t),v=e+m+a*g;if(n(i-r)<1e-12||0==--s||0===v)break;v>0?r=a:i=a,a=.5*(r+i)}if(!s)return null;var x=S(c),b=o(x),_=1/b,w=2*c*b,T=(-f*b-(-3*a+u*(1+3*l))*w*(1-c))/(f*f);return[y/4*(t*(-2*_*(.5*T/p*(1-l)-2*a*p*w)+-_*w*g)+-_*(a*(1+l)*T+h*(1+3*l)*w)*S(t/L(d))),x]}(c?l:s,c?s:l),f=u[0],h=u[1],p=o(h);return c&&(f=-x-f),[r*(a(m(f)*p,-m(h))+y),i*S(o(f)*p)]},Ut.invert=function(t,e){var r,n,o,l,u,f,h=(w-1)/(w+1),p=L(1-h*h),d=jt(x,p*p),m=(n=-t,o=p*p,(r=.5*d-e)?(l=Nt(r,o),n?(f=(u=Nt(n,1-o))[1]*u[1]+o*l[0]*l[0]*u[0]*u[0],[[l[0]*u[2]/f,l[1]*l[2]*u[0]*u[1]/f],[l[1]*u[1]/f,-l[0]*l[2]*u[0]*u[2]/f],[l[2]*u[1]*u[2]/f,-o*l[0]*l[1]*u[0]/f]]):[[l[0],0],[l[1],0],[l[2],0]]):[[0,(u=Nt(n,1-o))[0]/u[1]],[1/u[1],0],[u[2]/u[1],0]]),g=function(t,e){var r=e[0]*e[0]+e[1]*e[1];return[(t[0]*e[0]+t[1]*e[1])/r,(t[1]*e[0]-t[0]*e[1])/r]}(m[0],m[1]);return[a(g[1],g[0])/-1,2*i(s(-.5*c(h*g[0]*g[0]+h*g[1]*g[1])))-x]};var qt=S(1-1/3)*A,Gt=ht(0);function Yt(t){var e=qt*M,r=lt(y,e)[0]-lt(-y,e)[0],i=Gt(0,e)[1],a=lt(0,e)[1],o=T-a,s=k/t,c=4/k,h=i+o*o*4/k;function p(p,d){var m,g=n(d);if(g>e){var v=f(t-1,u(0,l((p+y)/s)));(m=lt(p+=y*(t-1)/t-v*s,g))[0]=m[0]*k/r-k*(t-1)/(2*t)+v*k/t,m[1]=i+4*(m[1]-a)*o/k,d<0&&(m[1]=-m[1])}else m=Gt(p,d);return m[0]*=c,m[1]/=h,m}return p.invert=function(e,p){e/=c;var d=n(p*=h);if(d>i){var m=f(t-1,u(0,l((e+y)/s)));e=(e+y*(t-1)/t-m*s)*r/k;var g=lt.invert(e,.25*(d-i)*k/o+a);return g[0]-=y*(t-1)/t-m*s,p<0&&(g[1]=-g[1]),g}return Gt.invert(e,p)},p}function Wt(t,e){return[t,1&e?90-v:qt]}function Xt(t,e){return[t,1&e?-90+v:-qt]}function Zt(t){return[t[0]*(1-v),t[1]]}function Jt(t){var e,r=1+t,i=S(m(1/r)),s=2*L(y/(e=y+4*i*r)),l=.5*s*(r+L(t*(2+t))),c=t*t,u=r*r;function f(f,h){var p,d,g=1-m(h);if(g&&g<2){var v,b=x-h,_=25;do{var w=m(b),T=o(b),k=i+a(w,r-T),A=1+u-2*r*T;b-=v=(b-c*i-r*w+A*k-.5*g*e)/(2*r*w*k)}while(n(v)>1e-12&&--_>0);p=s*L(A),d=f*k/y}else p=s*(t+g),d=f*i/y;return[p*m(d),l-p*o(d)]}return f.invert=function(t,n){var o=t*t+(n-=l)*n,f=(1+u-o/(s*s))/(2*r),h=E(f),p=m(h),d=i+a(p,r-f);return[S(t/L(o))*y/d,S(1-2*(h-c*i-r*p+(1+u-2*r*f)*d)/e)]},f}function Kt(t,e){return e>-.7109889596207567?((t=W(t,e))[1]+=.0528035274542,t):Q(t,e)}function Qt(t,e){return n(e)>.7109889596207567?((t=W(t,e))[1]-=e>0?.0528035274542:-.0528035274542,t):Q(t,e)}function $t(t,e,r,n){var i=L(4*y/(2*r+(1+t-e/2)*m(2*r)+(t+e)/2*m(4*r)+e/2*m(6*r))),a=L(n*m(r)*L((1+t*o(2*r)+e*o(4*r))/(1+t+e))),s=r*c(1);function l(r){return L(1+t*o(2*r)+e*o(4*r))}function c(n){var i=n*r;return(2*i+(1+t-e/2)*m(2*i)+(t+e)/2*m(4*i)+e/2*m(6*i))/r}function u(t){return l(t)*m(t)}var f=function(t,e){var n=r*V(c,s*m(e)/r,e/y);isNaN(n)&&(n=r*d(e));var u=i*l(n);return[u*a*t/y*o(n),u/a*m(n)]};return f.invert=function(t,e){var n=V(u,e*a/i);return[t*y/(o(n)*i*a*l(n)),S(r*c(n/r)/s)]},0===r&&(i=L(n/y),(f=function(t,e){return[t*i,m(e)/i]}).invert=function(t,e){return[t/i,S(e*i)]}),f}function te(t,e,r,n,i){void 0===n&&(n=1e-8),void 0===i&&(i=20);var a=t(e),o=t(.5*(e+r)),s=t(r);return function t(e,r,n,i,a,o,s,l,c,u,f){if(f.nanEncountered)return NaN;var h,p,d,m,g,v,y,x,b,_;if(p=e(r+.25*(h=n-r)),d=e(n-.25*h),isNaN(p))f.nanEncountered=!0;else{if(!isNaN(d))return _=((v=(m=h*(i+4*p+a)/12)+(g=h*(a+4*d+o)/12))-s)/15,u>c?(f.maxDepthCount++,v+_):Math.abs(_)<l?v+_:(x=t(e,r,y=r+.5*h,i,p,a,m,.5*l,c,u+1,f),isNaN(x)?(f.nanEncountered=!0,NaN):(b=t(e,y,n,a,d,o,g,.5*l,c,u+1,f),isNaN(b)?(f.nanEncountered=!0,NaN):x+b));f.nanEncountered=!0}}(t,e,r,a,o,s,(a+4*o+s)*(r-e)/6,n,i,1,{maxDepthCount:0,nanEncountered:!1})}function ee(t,e,r){function i(r){return t+(1-t)*h(1-h(r,e),1/e)}function a(t){return te(i,0,t,1e-4)}for(var o=1/a(1),s=1e3,l=(1+1e-8)*o,c=[],u=0;u<=s;u++)c.push(a(u/s)*l);function f(t){var e=0,r=s,n=500;do{c[n]>t?r=n:e=n,n=e+r>>1}while(n>e);var i=c[n+1]-c[n];return i&&(i=(t-c[n+1])/i),(n+1+i)/s}var p=2*f(1)/y*o/r,g=function(t,e){var r=f(n(m(e))),a=i(r)*t;return r/=p,[a,e>=0?r:-r]};return g.invert=function(t,e){var r;return n(e*=p)<1&&(r=d(e)*S(a(n(e))*o)),[t/i(n(e)),r]},g}function re(t,e){return n(t[0]-e[0])<v&&n(t[1]-e[1])<v}function ne(t,e){for(var r,n,i,a=-1,o=t.length,s=t[0],l=[];++a<o;){n=((r=t[a])[0]-s[0])/e,i=(r[1]-s[1])/e;for(var c=0;c<e;++c)l.push([s[0]+c*n,s[1]+c*i]);s=r}return l.push(r),l}function ie(t){var e,n,i,a,o,s,l,c=[],u=t[0].length;for(l=0;l<u;++l)n=(e=t[0][l])[0][0],i=e[0][1],a=e[1][1],o=e[2][0],s=e[2][1],c.push(ne([[n+v,i+v],[n+v,a-v],[o-v,a-v],[o-v,s+v]],30));for(l=t[1].length-1;l>=0;--l)n=(e=t[1][l])[0][0],i=e[0][1],a=e[1][1],o=e[2][0],s=e[2][1],c.push(ne([[o-v,s-v],[o-v,a+v],[n+v,a+v],[n+v,i-v]],30));return{type:"Polygon",coordinates:[r.merge(c)]}}function ae(t,r,n){var i,a;function o(e,n){for(var i=n<0?-1:1,a=r[+(n<0)],o=0,s=a.length-1;o<s&&e>a[o][2][0];++o);var l=t(e-a[o][1][0],n);return l[0]+=t(a[o][1][0],i*n>i*a[o][0][1]?a[o][0][1]:n)[0],l}n?o.invert=n(o):t.invert&&(o.invert=function(e,n){for(var i=a[+(n<0)],s=r[+(n<0)],l=0,c=i.length;l<c;++l){var u=i[l];if(u[0][0]<=e&&e<u[1][0]&&u[0][1]<=n&&n<u[1][1]){var f=t.invert(e-t(s[l][1][0],0)[0],n);return f[0]+=s[l][1][0],re(o(f[0],f[1]),[e,n])?f:null}}});var s=e.geoProjection(o),l=s.stream;return s.stream=function(t){var r=s.rotate(),n=l(t),a=(s.rotate([0,0]),l(t));return s.rotate(r),n.sphere=function(){e.geoStream(i,a)},n},s.lobes=function(e){return arguments.length?(i=ie(e),r=e.map((function(t){return t.map((function(t){return[[t[0][0]*M,t[0][1]*M],[t[1][0]*M,t[1][1]*M],[t[2][0]*M,t[2][1]*M]]}))})),a=r.map((function(e){return e.map((function(e){var r,n=t(e[0][0],e[0][1])[0],i=t(e[2][0],e[2][1])[0],a=t(e[1][0],e[0][1])[1],o=t(e[1][0],e[1][1])[1];return a>o&&(r=a,a=o,o=r),[[n,a],[i,o]]}))})),s):r.map((function(t){return t.map((function(t){return[[t[0][0]*A,t[0][1]*A],[t[1][0]*A,t[1][1]*A],[t[2][0]*A,t[2][1]*A]]}))}))},null!=r&&s.lobes(r),s}Kt.invert=function(t,e){return e>-.7109889596207567?W.invert(t,e-.0528035274542):Q.invert(t,e)},Qt.invert=function(t,e){return n(e)>.7109889596207567?W.invert(t,e+(e>0?.0528035274542:-.0528035274542)):Q.invert(t,e)};var oe=[[[[-180,0],[-100,90],[-40,0]],[[-40,0],[30,90],[180,0]]],[[[-180,0],[-160,-90],[-100,0]],[[-100,0],[-60,-90],[-20,0]],[[-20,0],[20,-90],[80,0]],[[80,0],[140,-90],[180,0]]]];var se=[[[[-180,0],[-100,90],[-40,0]],[[-40,0],[30,90],[180,0]]],[[[-180,0],[-160,-90],[-100,0]],[[-100,0],[-60,-90],[-20,0]],[[-20,0],[20,-90],[80,0]],[[80,0],[140,-90],[180,0]]]];var le=[[[[-180,0],[-100,90],[-40,0]],[[-40,0],[30,90],[180,0]]],[[[-180,0],[-160,-90],[-100,0]],[[-100,0],[-60,-90],[-20,0]],[[-20,0],[20,-90],[80,0]],[[80,0],[140,-90],[180,0]]]];var ce=[[[[-180,0],[-90,90],[0,0]],[[0,0],[90,90],[180,0]]],[[[-180,0],[-90,-90],[0,0]],[[0,0],[90,-90],[180,0]]]];var ue=[[[[-180,35],[-30,90],[0,35]],[[0,35],[30,90],[180,35]]],[[[-180,-10],[-102,-90],[-65,-10]],[[-65,-10],[5,-90],[77,-10]],[[77,-10],[103,-90],[180,-10]]]];var fe=[[[[-180,0],[-110,90],[-40,0]],[[-40,0],[0,90],[40,0]],[[40,0],[110,90],[180,0]]],[[[-180,0],[-110,-90],[-40,0]],[[-40,0],[0,-90],[40,0]],[[40,0],[110,-90],[180,0]]]];function he(t,e){return[3/k*t*L(y*y/3-e*e),e]}function pe(t){function e(e,r){if(n(n(r)-x)<v)return[0,r<0?-2:2];var i=m(r),a=h((1+i)/(1-i),t/2),s=.5*(a+1/a)+o(e*=t);return[2*m(e)/s,(a-1/a)/s]}return e.invert=function(e,r){var i=n(r);if(n(i-2)<v)return e?null:[0,d(r)*x];if(i>2)return null;var o=(e/=2)*e,s=(r/=2)*r,l=2*r/(1+o+s);return l=h((1+l)/(1-l),1/t),[a(2*e,1-o-s)/t,S((l-1)/(l+1))]},e}he.invert=function(t,e){return[k/3*t/L(y*y/3-e*e),e]};var de=y/w;function me(t,e){return[t*(1+L(o(e)))/2,e/(o(e/2)*o(t/6))]}function ge(t,e){var r=t*t,n=e*e;return[t*(.975534+n*(-.0143059*r-.119161+-.0547009*n)),e*(1.00384+r*(.0802894+-.02855*n+199025e-9*r)+n*(.0998909+-.0491032*n))]}function ve(t,e){return[m(t)/o(e),g(e)*o(t)]}function ye(t){var e=o(t),r=g(b+t/2);function i(i,a){var o=a-t,s=n(o)<v?i*e:n(s=b+a/2)<v||n(n(s)-x)<v?0:i*o/c(g(s)/r);return[s,o]}return i.invert=function(i,a){var o,s=a+t;return[n(a)<v?i/e:n(o=b+s/2)<v||n(n(o)-x)<v?0:i*c(g(o)/r)/a,s]},i}function xe(t,e){return[t,1.25*c(g(b+.4*e))]}function be(t){var e=t.length-1;function r(r,n){for(var i,a=o(n),s=2/(1+a*o(r)),l=s*a*m(r),c=s*m(n),u=e,f=t[u],h=f[0],p=f[1];--u>=0;)h=(f=t[u])[0]+l*(i=h)-c*p,p=f[1]+l*p+c*i;return[h=l*(i=h)-c*p,p=l*p+c*i]}return r.invert=function(r,s){var l=20,c=r,u=s;do{for(var f,h=e,p=t[h],d=p[0],g=p[1],v=0,y=0;--h>=0;)v=d+c*(f=v)-u*y,y=g+c*y+u*f,d=(p=t[h])[0]+c*(f=d)-u*g,g=p[1]+c*g+u*f;var x,b,_=(v=d+c*(f=v)-u*y)*v+(y=g+c*y+u*f)*y;c-=x=((d=c*(f=d)-u*g-r)*v+(g=c*g+u*f-s)*y)/_,u-=b=(g*v-d*y)/_}while(n(x)+n(b)>1e-12&&--l>0);if(l){var w=L(c*c+u*u),T=2*i(.5*w),k=m(T);return[a(c*k,w*o(T)),w?S(u*k/w):0]}},r}me.invert=function(t,e){var r=n(t),i=n(e),a=v,s=x;i<de?s*=i/de:a+=6*E(de/i);for(var l=0;l<25;l++){var c=m(s),u=L(o(s)),f=m(s/2),h=o(s/2),p=m(a/6),d=o(a/6),g=.5*a*(1+u)-r,y=s/(h*d)-i,b=u?-.25*a*c/u:0,_=.5*(1+u),w=(1+.5*s*f/h)/(h*d),T=s/h*(p/6)/(d*d),k=b*T-w*_,A=(g*T-y*_)/k,M=(y*b-g*w)/k;if(s-=A,a-=M,n(A)<v&&n(M)<v)break}return[t<0?-a:a,e<0?-s:s]},ge.invert=function(t,e){var r=d(t)*y,i=e/2,a=50;do{var o=r*r,s=i*i,l=r*i,c=r*(.975534+s*(-.0143059*o-.119161+-.0547009*s))-t,u=i*(1.00384+o*(.0802894+-.02855*s+199025e-9*o)+s*(.0998909+-.0491032*s))-e,f=.975534-s*(.119161+3*o*.0143059+.0547009*s),h=-l*(.238322+.2188036*s+.0286118*o),p=l*(.1605788+7961e-7*o+-.0571*s),m=1.00384+o*(.0802894+199025e-9*o)+s*(3*(.0998909-.02855*o)-.245516*s),g=h*p-m*f,x=(u*h-c*m)/g,b=(c*p-u*f)/g;r-=x,i-=b}while((n(x)>v||n(b)>v)&&--a>0);return a&&[r,i]},ve.invert=function(t,e){var r=t*t,n=e*e+1,i=r+n,a=t?_*L((i-L(i*i-4*r))/r):1/L(n);return[S(t*a),d(e)*E(a)]},xe.invert=function(t,e){return[t,2.5*i(s(.8*e))-.625*y]};var _e=[[.9972523,0],[.0052513,-.0041175],[.0074606,.0048125],[-.0153783,-.1968253],[.0636871,-.1408027],[.3660976,-.2937382]],we=[[.98879,0],[0,0],[-.050909,0],[0,0],[.075528,0]],Te=[[.984299,0],[.0211642,.0037608],[-.1036018,-.0575102],[-.0329095,-.0320119],[.0499471,.1223335],[.026046,.0899805],[7388e-7,-.1435792],[.0075848,-.1334108],[-.0216473,.0776645],[-.0225161,.0853673]],ke=[[.9245,0],[0,0],[.01943,0]],Ae=[[.721316,0],[0,0],[-.00881625,-.00617325]];function Me(t,r){var n=e.geoProjection(be(t)).rotate(r).clipAngle(90),i=e.geoRotation(r),a=n.center;return delete n.rotate,n.center=function(t){return arguments.length?a(i(t)):i.invert(a())},n}var Se=L(6),Ee=L(7);function Le(t,e){var r=S(7*m(e)/(3*Se));return[Se*t*(2*o(2*r/3)-1)/Ee,9*m(r/3)/Ee]}function Ce(t,e){for(var r,i=(1+_)*m(e),a=e,s=0;s<25&&(a-=r=(m(a/2)+m(a)-i)/(.5*o(a/2)+o(a)),!(n(r)<v));s++);return[t*(1+2*o(a)/o(a/2))/(3*w),2*L(3)*m(a/2)/L(2+w)]}function Pe(t,e){for(var r,i=L(6/(4+y)),a=(1+y/4)*m(e),s=e/2,l=0;l<25&&(s-=r=(s/2+m(s)-a)/(.5+o(s)),!(n(r)<v));l++);return[i*(.5+o(s))*t/1.5,i*s]}function Ie(t,e){var r=e*e,n=r*r,i=r*n;return[t*(.84719-.13063*r+i*i*(.05494*r-.04515-.02326*n+.00331*i)),e*(1.01183+n*n*(.01926*r-.02625-.00396*n))]}function Oe(t,e){return[t*(1+o(e))/2,2*(e-g(e/2))]}Le.invert=function(t,e){var r=3*S(e*Ee/9);return[t*Ee/(Se*(2*o(2*r/3)-1)),S(3*m(r)*Se/7)]},Ce.invert=function(t,e){var r=e*L(2+w)/(2*L(3)),n=2*S(r);return[3*w*t/(1+2*o(n)/o(n/2)),S((r+m(n))/(1+_))]},Pe.invert=function(t,e){var r=L(6/(4+y)),i=e/r;return n(n(i)-x)<v&&(i=i<0?-x:x),[1.5*t/(r*(.5+o(i))),S((i/2+m(i))/(1+y/4))]},Ie.invert=function(t,e){var r,i,a,o,s=e,l=25;do{s-=r=(s*(1.01183+(a=(i=s*s)*i)*a*(.01926*i-.02625-.00396*a))-e)/(1.01183+a*a*(.21186*i-.23625+-.05148*a))}while(n(r)>1e-12&&--l>0);return[t/(.84719-.13063*(i=s*s)+(o=i*(a=i*i))*o*(.05494*i-.04515-.02326*a+.00331*o)),s]},Oe.invert=function(t,e){for(var r=e/2,i=0,a=1/0;i<10&&n(a)>v;++i){var s=o(e/2);e-=a=(e-g(e/2)-r)/(1-.5/(s*s))}return[2*t/(1+o(e)),e]};var ze=[[[[-180,0],[-90,90],[0,0]],[[0,0],[90,90],[180,0]]],[[[-180,0],[-90,-90],[0,0]],[[0,0],[90,-90],[180,0]]]];function De(t,e){var r=m(e),i=o(e),a=d(t);if(0===t||n(e)===x)return[0,e];if(0===e)return[t,0];if(n(t)===x)return[t*i,x*r];var s=y/(2*t)-2*t/y,l=2*e/y,c=(1-l*l)/(r-l),u=s*s,f=c*c,h=1+u/f,p=1+f/u,g=(s*r/c-s/2)/h,v=(f*r/u+c/2)/p,b=v*v-(f*r*r/u+c*r-1)/p;return[x*(g+L(g*g+i*i/h)*a),x*(v+L(b<0?0:b)*d(-e*s)*a)]}De.invert=function(t,e){var r=(t/=x)*t,n=r+(e/=x)*e,i=y*y;return[t?(n-1+L((1-n)*(1-n)+4*r))/(2*t)*x:0,V((function(t){return n*(y*m(t)-2*t)*y+4*t*t*(e-m(t))+2*y*t-i*e}),0)]};function Re(t,e){var r=e*e;return[t,e*(1.0148+r*r*(.23185+r*(.02406*r-.14499)))]}function Fe(t,e){if(n(e)<v)return[t,0];var r=g(e),i=t*m(e);return[m(i)/r,e+(1-o(i))/r]}function Be(t,e){var r=je(t[1],t[0]),n=je(e[1],e[0]),i=function(t,e){return a(t[0]*e[1]-t[1]*e[0],t[0]*e[0]+t[1]*e[1])}(r,n),s=Ue(r)/Ue(n);return Ne([1,0,t[0][0],0,1,t[0][1]],Ne([s,0,0,0,s,0],Ne([o(i),m(i),0,-m(i),o(i),0],[1,0,-e[0][0],0,1,-e[0][1]])))}function Ne(t,e){return[t[0]*e[0]+t[1]*e[3],t[0]*e[1]+t[1]*e[4],t[0]*e[2]+t[1]*e[5]+t[2],t[3]*e[0]+t[4]*e[3],t[3]*e[1]+t[4]*e[4],t[3]*e[2]+t[4]*e[5]+t[5]]}function je(t,e){return[t[0]-e[0],t[1]-e[1]]}function Ue(t){return L(t[0]*t[0]+t[1]*t[1])}function Ve(t,r,i){function a(t,e){var n,i=r(t,e),a=i.project([t*A,e*A]);return(n=i.transform)?[n[0]*a[0]+n[1]*a[1]+n[2],-(n[3]*a[0]+n[4]*a[1]+n[5])]:(a[1]=-a[1],a)}!function t(e,r){if(e.edges=function(t){for(var e=t.length,r=[],n=t[e-1],i=0;i<e;++i)r.push([n,n=t[i]]);return r}(e.face),r.face){var n=e.shared=function(t,e){for(var r,n,i=t.length,a=null,o=0;o<i;++o){r=t[o];for(var s=e.length;--s>=0;)if(n=e[s],r[0]===n[0]&&r[1]===n[1]){if(a)return[a,r];a=r}}}(e.face,r.face),i=Be(n.map(r.project),n.map(e.project));e.transform=r.transform?Ne(r.transform,i):i;for(var a=r.edges,o=0,s=a.length;o<s;++o)He(n[0],a[o][1])&&He(n[1],a[o][0])&&(a[o]=e),He(n[0],a[o][0])&&He(n[1],a[o][1])&&(a[o]=e);for(a=e.edges,o=0,s=a.length;o<s;++o)He(n[0],a[o][0])&&He(n[1],a[o][1])&&(a[o]=r),He(n[0],a[o][1])&&He(n[1],a[o][0])&&(a[o]=r)}else e.transform=r.transform;e.children&&e.children.forEach((function(r){t(r,e)}));return e}(t,{transform:null}),qe(t)&&(a.invert=function(e,n){var i=function t(e,n){var i=e.project.invert,a=e.transform,o=n;a&&(a=function(t){var e=1/(t[0]*t[4]-t[1]*t[3]);return[e*t[4],-e*t[1],e*(t[1]*t[5]-t[2]*t[4]),-e*t[3],e*t[0],e*(t[2]*t[3]-t[0]*t[5])]}(a),o=[a[0]*o[0]+a[1]*o[1]+a[2],a[3]*o[0]+a[4]*o[1]+a[5]]);if(i&&e===function(t){return r(t[0]*M,t[1]*M)}(s=i(o)))return s;for(var s,l=e.children,c=0,u=l&&l.length;c<u;++c)if(s=t(l[c],n))return s}(t,[e,-n]);return i&&(i[0]*=M,i[1]*=M,i)});var o=e.geoProjection(a),s=o.stream;return o.stream=function(r){var i=o.rotate(),a=s(r),l=(o.rotate([0,0]),s(r));return o.rotate(i),a.sphere=function(){l.polygonStart(),l.lineStart(),function t(r,i,a){var o,s,l=i.edges,c=l.length,u={type:"MultiPoint",coordinates:i.face},f=i.face.filter((function(t){return 90!==n(t[1])})),h=e.geoBounds({type:"MultiPoint",coordinates:f}),p=!1,d=-1,m=h[1][0]-h[0][0],g=180===m||360===m?[(h[0][0]+h[1][0])/2,(h[0][1]+h[1][1])/2]:e.geoCentroid(u);if(a)for(;++d<c&&l[d]!==a;);++d;for(var y=0;y<c;++y)s=l[(y+d)%c],Array.isArray(s)?(p||(r.point((o=e.geoInterpolate(s[0],g)(v))[0],o[1]),p=!0),r.point((o=e.geoInterpolate(s[1],g)(v))[0],o[1])):(p=!1,s!==a&&t(r,s,i))}(l,t),l.lineEnd(),l.polygonEnd()},a},o.angle(null==i?-30:i*A)}function He(t,e){return t&&e&&t[0]===e[0]&&t[1]===e[1]}function qe(t){return t.project.invert||t.children&&t.children.some(qe)}Re.invert=function(t,e){e>1.790857183?e=1.790857183:e<-1.790857183&&(e=-1.790857183);var r,i=e;do{var a=i*i;i-=r=(i*(1.0148+a*a*(.23185+a*(.02406*a-.14499)))-e)/(1.0148+a*a*(5*.23185+a*(.21654*a-1.01493)))}while(n(r)>v);return[t,i]},Fe.invert=function(t,e){if(n(e)<v)return[t,0];var r,i=t*t+e*e,a=.5*e,s=10;do{var l=g(a),c=1/o(a),u=i-2*e*a+a*a;a-=r=(l*u+2*(a-e))/(2+u*c*c+2*(a-e)*l)}while(n(r)>v&&--s>0);return l=g(a),[(n(e)<n(a+1/l)?S(t*l):d(e)*d(t)*(E(n(t*l))+x))/m(a),a]};var Ge=[[0,90],[-90,0],[0,0],[90,0],[180,0],[0,-90]],Ye=[[0,2,1],[0,3,2],[5,1,2],[5,2,3],[0,1,4],[0,4,3],[5,4,1],[5,3,4]].map((function(t){return t.map((function(t){return Ge[t]}))}));var We=2/L(3);function Xe(t,e){var r=lt(t,e);return[r[0]*We,r[1]]}function Ze(t,e){for(var r=0,n=t.length,i=0;r<n;++r)i+=t[r]*e[r];return i}function Je(t){return[a(t[1],t[0])*A,S(u(-1,f(1,t[2])))*A]}function Ke(t){var e=t[0]*M,r=t[1]*M,n=o(r);return[n*o(e),n*m(e),m(r)]}function Qe(){}function $e(t,e){return{type:"FeatureCollection",features:t.features.map((function(t){return tr(t,e)}))}}function tr(t,e){return{type:"Feature",id:t.id,properties:t.properties,geometry:er(t.geometry,e)}}function er(t,r){if(!t)return null;if("GeometryCollection"===t.type)return function(t,e){return{type:"GeometryCollection",geometries:t.geometries.map((function(t){return er(t,e)}))}}(t,r);var n;switch(t.type){case"Point":case"MultiPoint":n=ir;break;case"LineString":case"MultiLineString":n=ar;break;case"Polygon":case"MultiPolygon":case"Sphere":n=or;break;default:return null}return e.geoStream(t,r(n)),n.result()}Xe.invert=function(t,e){return lt.invert(t/We,e)};var rr=[],nr=[],ir={point:function(t,e){rr.push([t,e])},result:function(){var t=rr.length?rr.length<2?{type:"Point",coordinates:rr[0]}:{type:"MultiPoint",coordinates:rr}:null;return rr=[],t}},ar={lineStart:Qe,point:function(t,e){rr.push([t,e])},lineEnd:function(){rr.length&&(nr.push(rr),rr=[])},result:function(){var t=nr.length?nr.length<2?{type:"LineString",coordinates:nr[0]}:{type:"MultiLineString",coordinates:nr}:null;return nr=[],t}},or={polygonStart:Qe,lineStart:Qe,point:function(t,e){rr.push([t,e])},lineEnd:function(){var t=rr.length;if(t){do{rr.push(rr[0].slice())}while(++t<4);nr.push(rr),rr=[]}},polygonEnd:Qe,result:function(){if(!nr.length)return null;var t=[],e=[];return nr.forEach((function(r){!function(t){if((e=t.length)<4)return!1;for(var e,r=0,n=t[e-1][1]*t[0][0]-t[e-1][0]*t[0][1];++r<e;)n+=t[r-1][1]*t[r][0]-t[r-1][0]*t[r][1];return n<=0}(r)?e.push(r):t.push([r])})),e.forEach((function(e){var r=e[0];t.some((function(t){if(function(t,e){for(var r=e[0],n=e[1],i=!1,a=0,o=t.length,s=o-1;a<o;s=a++){var l=t[a],c=l[0],u=l[1],f=t[s],h=f[0],p=f[1];u>n^p>n&&r<(h-c)*(n-u)/(p-u)+c&&(i=!i)}return i}(t[0],r))return t.push(e),!0}))||t.push([e])})),nr=[],t.length?t.length>1?{type:"MultiPolygon",coordinates:t}:{type:"Polygon",coordinates:t[0]}:null}};function sr(t){var r=t(x,0)[0]-t(-x,0)[0];function i(e,i){var a=n(e)<x,o=t(a?e:e>0?e-y:e+y,i),s=(o[0]-o[1])*_,l=(o[0]+o[1])*_;if(a)return[s,l];var c=r*_,u=s>0^l>0?-1:1;return[u*s-d(l)*c,u*l-d(s)*c]}return t.invert&&(i.invert=function(e,i){var a=(e+i)*_,o=(i-e)*_,s=n(a)<.5*r&&n(o)<.5*r;if(!s){var l=r*_,c=a>0^o>0?-1:1,u=-c*e+(o>0?1:-1)*l,f=-c*i+(a>0?1:-1)*l;a=(-u-f)*_,o=(u-f)*_}var h=t.invert(a,o);return s||(h[0]+=a>0?y:-y),h}),e.geoProjection(i).rotate([-90,-90,45]).clipAngle(179.999)}function lr(){return sr(Ut).scale(111.48)}function cr(t){var e=m(t);function r(r,n){var a=e?g(r*e/2)/e:r/2;if(!n)return[2*a,-t];var s=2*i(a*m(n)),l=1/g(n);return[m(s)*l,n+(1-o(s))*l-t]}return r.invert=function(r,a){if(n(a+=t)<v)return[e?2*i(e*r/2)/e:r,0];var s,l=r*r+a*a,c=0,u=10;do{var f=g(c),h=1/o(c),p=l-2*a*c+c*c;c-=s=(f*p+2*(c-a))/(2+p*h*h+2*(c-a)*f)}while(n(s)>v&&--u>0);var d=r*(f=g(c)),x=g(n(a)<n(c+1/f)?.5*S(d):.5*E(d)+y/4)/m(c);return[e?2*i(e*x)/e:2*x,c]},r}var ur=[[.9986,-.062],[1,0],[.9986,.062],[.9954,.124],[.99,.186],[.9822,.248],[.973,.31],[.96,.372],[.9427,.434],[.9216,.4958],[.8962,.5571],[.8679,.6176],[.835,.6769],[.7986,.7346],[.7597,.7903],[.7186,.8435],[.6732,.8936],[.6213,.9394],[.5722,.9761],[.5322,1]];function fr(t,e){var r,i=f(18,36*n(e)/y),a=l(i),o=i-a,s=(r=ur[a])[0],c=r[1],u=(r=ur[++a])[0],h=r[1],p=(r=ur[f(19,++a)])[0],d=r[1];return[t*(u+o*(p-s)/2+o*o*(p-2*u+s)/2),(e>0?x:-x)*(h+o*(d-c)/2+o*o*(d-2*h+c)/2)]}function hr(t,e){var r=function(t){function e(e,r){var n=o(r),i=(t-1)/(t-n*o(e));return[i*n*m(e),i*m(r)]}return e.invert=function(e,r){var n=e*e+r*r,i=L(n),o=(t-L(1-n*(t+1)/(t-1)))/((t-1)/i+i/(t-1));return[a(e*o,i*L(1-o*o)),i?S(r*o/i):0]},e}(t);if(!e)return r;var n=o(e),i=m(e);function s(e,a){var o=r(e,a),s=o[1],l=s*i/(t-1)+n;return[o[0]*n/l,s/l]}return s.invert=function(e,a){var o=(t-1)/(t-1-a*i);return r.invert(o*e,o*a*n)},s}ur.forEach((function(t){t[1]*=1.0144})),fr.invert=function(t,e){var r=e/x,i=90*r,a=f(18,n(i/5)),o=u(0,l(a));do{var s=ur[o][1],c=ur[o+1][1],h=ur[f(19,o+2)][1],p=h-s,d=h-2*c+s,m=2*(n(r)-c)/p,g=d/p,v=m*(1-g*m*(1-2*g*m));if(v>=0||1===o){i=(e>=0?5:-5)*(v+a);var y,b=50;do{v=(a=f(18,n(i)/5))-(o=l(a)),s=ur[o][1],c=ur[o+1][1],h=ur[f(19,o+2)][1],i-=(y=(e>=0?x:-x)*(c+v*(h-s)/2+v*v*(h-2*c+s)/2)-e)*A}while(n(y)>1e-12&&--b>0);break}}while(--o>=0);var _=ur[o][0],w=ur[o+1][0],T=ur[f(19,o+2)][0];return[t/(w+v*(T-_)/2+v*v*(T-2*w+_)/2),i*M]};var pr=-179.9999,dr=179.9999,mr=-89.9999;function gr(t){return t.length>0}function vr(t){return-90===t||90===t?[0,t]:[-180,(e=t,Math.floor(1e4*e)/1e4)];var e}function yr(t){var e=t[0],r=t[1],n=!1;return e<=pr?(e=-180,n=!0):e>=dr&&(e=180,n=!0),r<=mr?(r=-90,n=!0):r>=89.9999&&(r=90,n=!0),n?[e,r]:t}function xr(t){return t.map(yr)}function br(t,e,r){for(var n=0,i=t.length;n<i;++n){var a=t[n].slice();r.push({index:-1,polygon:e,ring:a});for(var o=0,s=a.length;o<s;++o){var l=a[o],c=l[0],u=l[1];if(c<=pr||c>=dr||u<=mr||u>=89.9999){a[o]=yr(l);for(var f=o+1;f<s;++f){var h=a[f],p=h[0],d=h[1];if(p>pr&&p<dr&&d>mr&&d<89.9999)break}if(f===o+1)continue;if(o){var m={index:-1,polygon:e,ring:a.slice(0,o+1)};m.ring[m.ring.length-1]=vr(u),r[r.length-1]=m}else r.pop();if(f>=s)break;r.push({index:-1,polygon:e,ring:a=a.slice(f-1)}),a[0]=vr(a[0][1]),o=-1,s=a.length}}}}function _r(t){var e,r,n,i,a,o,s=t.length,l={},c={};for(e=0;e<s;++e)n=(r=t[e]).ring[0],a=r.ring[r.ring.length-1],n[0]!==a[0]||n[1]!==a[1]?(r.index=e,l[n]=c[a]=r):(r.polygon.push(r.ring),t[e]=null);for(e=0;e<s;++e)if(r=t[e]){if(n=r.ring[0],a=r.ring[r.ring.length-1],i=c[n],o=l[a],delete l[n],delete c[a],n[0]===a[0]&&n[1]===a[1]){r.polygon.push(r.ring);continue}i?(delete c[n],delete l[i.ring[0]],i.ring.pop(),t[i.index]=null,r={index:-1,polygon:i.polygon,ring:i.ring.concat(r.ring)},i===o?r.polygon.push(r.ring):(r.index=s++,t.push(l[r.ring[0]]=c[r.ring[r.ring.length-1]]=r))):o?(delete l[a],delete c[o.ring[o.ring.length-1]],r.ring.pop(),r={index:s++,polygon:o.polygon,ring:r.ring.concat(o.ring)},t[o.index]=null,t.push(l[r.ring[0]]=c[r.ring[r.ring.length-1]]=r)):(r.ring.push(r.ring[0]),r.polygon.push(r.ring))}}function wr(t){var e={type:"Feature",geometry:Tr(t.geometry)};return null!=t.id&&(e.id=t.id),null!=t.bbox&&(e.bbox=t.bbox),null!=t.properties&&(e.properties=t.properties),e}function Tr(t){if(null==t)return t;var e,r,n,i;switch(t.type){case"GeometryCollection":e={type:"GeometryCollection",geometries:t.geometries.map(Tr)};break;case"Point":e={type:"Point",coordinates:yr(t.coordinates)};break;case"MultiPoint":case"LineString":e={type:t.type,coordinates:xr(t.coordinates)};break;case"MultiLineString":e={type:"MultiLineString",coordinates:t.coordinates.map(xr)};break;case"Polygon":var a=[];br(t.coordinates,a,r=[]),_r(r),e={type:"Polygon",coordinates:a};break;case"MultiPolygon":r=[],n=-1,i=t.coordinates.length;for(var o=new Array(i);++n<i;)br(t.coordinates[n],o[n]=[],r);_r(r),e={type:"MultiPolygon",coordinates:o.filter(gr)};break;default:return t}return null!=t.bbox&&(e.bbox=t.bbox),e}function kr(t,e){var r=g(e/2),n=m(b*r);return[t*(.74482-.34588*n*n),1.70711*r]}function Ar(t,r,n){var i=e.geoInterpolate(r,n),a=i(.5),o=e.geoRotation([-a[0],-a[1]])(r),s=i.distance/2,l=-S(m(o[1]*M)/m(s)),c=[-a[0],-a[1],-(o[0]>0?y-l:l)*A],u=e.geoProjection(t(s)).rotate(c),f=e.geoRotation(c),h=u.center;return delete u.rotate,u.center=function(t){return arguments.length?h(f(t)):f.invert(h())},u.clipAngle(90)}function Mr(t){var r=o(t);function n(t,n){var i=e.geoGnomonicRaw(t,n);return i[0]*=r,i}return n.invert=function(t,n){return e.geoGnomonicRaw.invert(t/r,n)},n}function Sr(t,e){return Ar(Mr,t,e)}function Er(t){if(!(t*=2))return e.geoAzimuthalEquidistantRaw;var r=-t/2,n=-r,i=t*t,s=g(n),l=.5/m(n);function c(e,a){var s=E(o(a)*o(e-r)),l=E(o(a)*o(e-n));return[((s*=s)-(l*=l))/(2*t),(a<0?-1:1)*L(4*i*l-(i-s+l)*(i-s+l))/(2*t)]}return c.invert=function(t,e){var i,c,u=e*e,f=o(L(u+(i=t+r)*i)),h=o(L(u+(i=t+n)*i));return[a(c=f-h,i=(f+h)*s),(e<0?-1:1)*E(L(i*i+c*c)*l)]},c}function Lr(t,e){return Ar(Er,t,e)}function Cr(t,e){if(n(e)<v)return[t,0];var r=n(e/x),i=S(r);if(n(t)<v||n(n(e)-x)<v)return[0,d(e)*y*g(i/2)];var a=o(i),s=n(y/t-t/y)/2,l=s*s,c=a/(r+a-1),u=c*(2/r-1),f=u*u,h=f+l,p=c-f,m=l+c;return[d(t)*y*(s*p+L(l*p*p-h*(c*c-f)))/h,d(e)*y*(u*m-s*L((l+1)*h-m*m))/h]}function Pr(t,e){if(n(e)<v)return[t,0];var r=n(e/x),i=S(r);if(n(t)<v||n(n(e)-x)<v)return[0,d(e)*y*g(i/2)];var a=o(i),s=n(y/t-t/y)/2,l=s*s,c=a*(L(1+l)-s*a)/(1+l*r*r);return[d(t)*y*c,d(e)*y*L(1-c*(2*s+c))]}function Ir(t,e){if(n(e)<v)return[t,0];var r=e/x,i=S(r);if(n(t)<v||n(n(e)-x)<v)return[0,y*g(i/2)];var a=(y/t-t/y)/2,s=r/(1+o(i));return[y*(d(t)*L(a*a+1-s*s)-a),y*s]}function Or(t,e){if(!e)return[t,0];var r=n(e);if(!t||r===x)return[0,e];var i=r/x,a=i*i,o=(8*i-a*(a+2)-5)/(2*a*(i-1)),s=o*o,l=i*o,c=a+s+2*l,u=i+3*o,f=t/x,h=f+1/f,p=d(n(t)-x)*L(h*h-4),m=p*p,g=(p*(c+s-1)+2*L(c*(a+s*m-1)+(1-a)*(a*(u*u+4*s)+12*l*s+4*s*s)))/(4*c+m);return[d(t)*x*g,d(e)*x*L(1+p*n(g)-g*g)]}function zr(t,e,r,n){var i=y/3;t=u(t,v),e=u(e,v),t=f(t,x),e=f(e,y-v),r=u(r,0),r=f(r,100-v);var s=(n=u(n,v))/100,l=E((r/100+1)*o(i))/i,c=m(t)/m(l*x),h=e/y,p=L(s*m(t/2)/m(e/2));return function(t,e,r,n,i){function s(a,s){var l=r*m(n*s),c=L(1-l*l),u=L(2/(1+c*o(a*=i)));return[t*c*u*m(a),e*l*u]}return s.invert=function(o,s){var l=o/t,c=s/e,u=L(l*l+c*c),f=2*S(u/2);return[a(o*g(f),t*u)/i,u&&S(s*m(f)/(e*r*u))/n]},s}(p/L(h*c*l),1/(p*L(h*c*l)),c,l,h)}function Dr(){var t=65*M,r=60*M,n=20,i=200,a=e.geoProjectionMutator(zr),o=a(t,r,n,i);return o.poleline=function(e){return arguments.length?a(t=+e*M,r,n,i):t*A},o.parallels=function(e){return arguments.length?a(t,r=+e*M,n,i):r*A},o.inflation=function(e){return arguments.length?a(t,r,n=+e,i):n},o.ratio=function(e){return arguments.length?a(t,r,n,i=+e):i},o.scale(163.775)}kr.invert=function(t,e){var r=e/1.70711,n=m(b*r);return[t/(.74482-.34588*n*n),2*i(r)]},Cr.invert=function(t,e){if(n(e)<v)return[t,0];if(n(t)<v)return[0,x*m(2*i(e/y))];var r=(t/=y)*t,a=(e/=y)*e,s=r+a,l=s*s,c=-n(e)*(1+s),u=c-2*a+r,f=-2*c+1+2*a+l,h=a/f+(2*u*u*u/(f*f*f)-9*c*u/(f*f))/27,p=(c-u*u/(3*f))/f,g=2*L(-p/3),b=E(3*h/(p*g))/3;return[y*(s-1+L(1+2*(r-a)+l))/(2*t),d(e)*y*(-g*o(b+y/3)-u/(3*f))]},Pr.invert=function(t,e){if(!t)return[0,x*m(2*i(e/y))];var r=n(t/y),o=(1-r*r-(e/=y)*e)/(2*r),s=L(o*o+1);return[d(t)*y*(s-o),d(e)*x*m(2*a(L((1-2*o*r)*(o+s)-r),L(s+o+r)))]},Ir.invert=function(t,e){if(!e)return[t,0];var r=e/y,n=(y*y*(1-r*r)-t*t)/(2*y*t);return[t?y*(d(t)*L(n*n+1)-n):0,x*m(2*i(r))]},Or.invert=function(t,e){var r;if(!t||!e)return[t,e];e/=y;var i=d(t)*t/x,a=(i*i-1+4*e*e)/n(i),o=a*a,s=2*e,l=50;do{var c=s*s,u=(8*s-c*(c+2)-5)/(2*c*(s-1)),f=(3*s-c*s-10)/(2*c*s),h=u*u,p=s*u,m=s+u,g=m*m,b=s+3*u,_=-2*m*(4*p*h+(1-4*c+3*c*c)*(1+f)+h*(14*c-6-o+(8*c-8-2*o)*f)+p*(12*c-8+(10*c-10-o)*f)),w=L(g*(c+h*o-1)+(1-c)*(c*(b*b+4*h)+h*(12*p+4*h)));s-=r=(a*(g+h-1)+2*w-i*(4*g+o))/(a*(2*u*f+2*m*(1+f))+_/w-8*m*(a*(-1+h+g)+2*w)*(1+f)/(o+4*g))}while(r>v&&--l>0);return[d(t)*(L(a*a+4)+a)*y/4,x*s]};var Rr=4*y+3*L(3),Fr=2*L(2*y*L(3)/Rr),Br=Y(Fr*L(3)/y,Fr,Rr/6);function Nr(t,e){return[t*L(1-3*e*e/(y*y)),e]}function jr(t,e){var r=o(e),n=o(t)*r,i=1-n,s=o(t=a(m(t)*r,-m(e))),l=m(t);return[l*(r=L(1-n*n))-s*i,-s*r-l*i]}function Ur(t,e){var r=O(t,e);return[(r[0]+t/x)/2,(r[1]+e)/2]}Nr.invert=function(t,e){return[t/L(1-3*e*e/(y*y)),e]},jr.invert=function(t,e){var r=(t*t+e*e)/-2,n=L(-r*(2+r)),i=e*r+t*n,o=t*r-e*n,s=L(o*o+i*i);return[a(n*i,s*(1+r)),s?-S(n*o/s):0]},Ur.invert=function(t,e){var r=t,i=e,a=25;do{var s,l=o(i),c=m(i),u=m(2*i),f=c*c,h=l*l,p=m(r),d=o(r/2),g=m(r/2),y=g*g,b=1-h*d*d,_=b?E(l*d)*L(s=1/b):s=0,w=.5*(2*_*l*g+r/x)-t,T=.5*(_*c+i)-e,k=.5*s*(h*y+_*l*d*f)+.5/x,A=s*(p*u/4-_*c*g),M=.125*s*(u*g-_*c*h*p),S=.5*s*(f*d+_*y*l)+.5,C=A*M-S*k,P=(T*A-w*S)/C,I=(w*M-T*k)/C;r-=P,i-=I}while((n(P)>v||n(I)>v)&&--a>0);return[r,i]},t.geoNaturalEarth=e.geoNaturalEarth1,t.geoNaturalEarthRaw=e.geoNaturalEarth1Raw,t.geoAiry=function(){var t=x,r=e.geoProjectionMutator(I),n=r(t);return n.radius=function(e){return arguments.length?r(t=e*M):t*A},n.scale(179.976).clipAngle(147)},t.geoAiryRaw=I,t.geoAitoff=function(){return e.geoProjection(O).scale(152.63)},t.geoAitoffRaw=O,t.geoArmadillo=function(){var t=20*M,r=t>=0?1:-1,n=g(r*t),i=e.geoProjectionMutator(z),s=i(t),l=s.stream;return s.parallel=function(e){return arguments.length?(n=g((r=(t=e*M)>=0?1:-1)*t),i(t)):t*A},s.stream=function(e){var i=s.rotate(),c=l(e),u=(s.rotate([0,0]),l(e)),f=s.precision();return s.rotate(i),c.sphere=function(){u.polygonStart(),u.lineStart();for(var e=-180*r;r*e<180;e+=90*r)u.point(e,90*r);if(t)for(;r*(e-=3*r*f)>=-180;)u.point(e,r*-a(o(e*M/2),n)*A);u.lineEnd(),u.polygonEnd()},c},s.scale(218.695).center([0,28.0974])},t.geoArmadilloRaw=z,t.geoAugust=function(){return e.geoProjection(D).scale(66.1603)},t.geoAugustRaw=D,t.geoBaker=function(){return e.geoProjection(B).scale(112.314)},t.geoBakerRaw=B,t.geoBerghaus=function(){var t=5,r=e.geoProjectionMutator(N),n=r(t),i=n.stream,s=-o(.01*M),l=m(.01*M);return n.lobes=function(e){return arguments.length?r(t=+e):t},n.stream=function(e){var r=n.rotate(),c=i(e),u=(n.rotate([0,0]),i(e));return n.rotate(r),c.sphere=function(){u.polygonStart(),u.lineStart();for(var e=0,r=360/t,n=2*y/t,i=90-180/t,c=x;e<t;++e,i-=r,c-=n)u.point(a(l*o(c),s)*A,S(l*m(c))*A),i<-90?(u.point(-90,-180-i-.01),u.point(-90,-180-i+.01)):(u.point(90,i+.01),u.point(90,i-.01));u.lineEnd(),u.polygonEnd()},c},n.scale(87.8076).center([0,17.1875]).clipAngle(179.999)},t.geoBerghausRaw=N,t.geoBertin1953=function(){return e.geoProjection(q()).rotate([-16.5,-42]).scale(176.57).center([7.93,.09])},t.geoBertin1953Raw=q,t.geoBoggs=function(){return e.geoProjection(J).scale(160.857)},t.geoBoggsRaw=J,t.geoBonne=function(){return K($).scale(123.082).center([0,26.1441]).parallel(45)},t.geoBonneRaw=$,t.geoBottomley=function(){var t=.5,r=e.geoProjectionMutator(tt),n=r(t);return n.fraction=function(e){return arguments.length?r(t=+e):t},n.scale(158.837)},t.geoBottomleyRaw=tt,t.geoBromley=function(){return e.geoProjection(et).scale(152.63)},t.geoBromleyRaw=et,t.geoChamberlin=st,t.geoChamberlinRaw=at,t.geoChamberlinAfrica=function(){return st([0,22],[45,22],[22.5,-22]).scale(380).center([22.5,2])},t.geoCollignon=function(){return e.geoProjection(lt).scale(95.6464).center([0,30])},t.geoCollignonRaw=lt,t.geoCraig=function(){return K(ct).scale(249.828).clipAngle(90)},t.geoCraigRaw=ct,t.geoCraster=function(){return e.geoProjection(ft).scale(156.19)},t.geoCrasterRaw=ft,t.geoCylindricalEqualArea=function(){return K(ht).parallel(38.58).scale(195.044)},t.geoCylindricalEqualAreaRaw=ht,t.geoCylindricalStereographic=function(){return K(pt).scale(124.75)},t.geoCylindricalStereographicRaw=pt,t.geoEckert1=function(){return e.geoProjection(dt).scale(165.664)},t.geoEckert1Raw=dt,t.geoEckert2=function(){return e.geoProjection(mt).scale(165.664)},t.geoEckert2Raw=mt,t.geoEckert3=function(){return e.geoProjection(gt).scale(180.739)},t.geoEckert3Raw=gt,t.geoEckert4=function(){return e.geoProjection(vt).scale(180.739)},t.geoEckert4Raw=vt,t.geoEckert5=function(){return e.geoProjection(yt).scale(173.044)},t.geoEckert5Raw=yt,t.geoEckert6=function(){return e.geoProjection(xt).scale(173.044)},t.geoEckert6Raw=xt,t.geoEisenlohr=function(){return e.geoProjection(_t).scale(62.5271)},t.geoEisenlohrRaw=_t,t.geoFahey=function(){return e.geoProjection(Tt).scale(137.152)},t.geoFaheyRaw=Tt,t.geoFoucaut=function(){return e.geoProjection(kt).scale(135.264)},t.geoFoucautRaw=kt,t.geoFoucautSinusoidal=function(){var t=.5,r=e.geoProjectionMutator(At),n=r(t);return n.alpha=function(e){return arguments.length?r(t=+e):t},n.scale(168.725)},t.geoFoucautSinusoidalRaw=At,t.geoGilbert=function(t){null==t&&(t=e.geoOrthographic);var r=t(),n=e.geoEquirectangular().scale(A).precision(0).clipAngle(null).translate([0,0]);function i(t){return r(Mt(t))}function a(t){i[t]=function(){return arguments.length?(r[t].apply(r,arguments),i):r[t]()}}return r.invert&&(i.invert=function(t){return St(r.invert(t))}),i.stream=function(t){var e=r.stream(t),i=n.stream({point:function(t,r){e.point(t/2,S(g(-r/2*M))*A)},lineStart:function(){e.lineStart()},lineEnd:function(){e.lineEnd()},polygonStart:function(){e.polygonStart()},polygonEnd:function(){e.polygonEnd()}});return i.sphere=e.sphere,i},i.rotate=function(t){return arguments.length?(n.rotate(t),i):n.rotate()},i.center=function(t){return arguments.length?(r.center(Mt(t)),i):St(r.center())},a("angle"),a("clipAngle"),a("clipExtent"),a("fitExtent"),a("fitHeight"),a("fitSize"),a("fitWidth"),a("scale"),a("translate"),a("precision"),i.scale(249.5)},t.geoGingery=function(){var t=6,r=30*M,n=o(r),i=m(r),s=e.geoProjectionMutator(Et),l=s(r,t),c=l.stream,u=-o(.01*M),f=m(.01*M);return l.radius=function(e){return arguments.length?(n=o(r=e*M),i=m(r),s(r,t)):r*A},l.lobes=function(e){return arguments.length?s(r,t=+e):t},l.stream=function(e){var r=l.rotate(),s=c(e),h=(l.rotate([0,0]),c(e));return l.rotate(r),s.sphere=function(){h.polygonStart(),h.lineStart();for(var e=0,r=2*y/t,s=0;e<t;++e,s-=r)h.point(a(f*o(s),u)*A,S(f*m(s))*A),h.point(a(i*o(s-r/2),n)*A,S(i*m(s-r/2))*A);h.lineEnd(),h.polygonEnd()},s},l.rotate([90,-40]).scale(91.7095).clipAngle(179.999)},t.geoGingeryRaw=Et,t.geoGinzburg4=function(){return e.geoProjection(It).scale(149.995)},t.geoGinzburg4Raw=It,t.geoGinzburg5=function(){return e.geoProjection(Ot).scale(153.93)},t.geoGinzburg5Raw=Ot,t.geoGinzburg6=function(){return e.geoProjection(zt).scale(130.945)},t.geoGinzburg6Raw=zt,t.geoGinzburg8=function(){return e.geoProjection(Dt).scale(131.747)},t.geoGinzburg8Raw=Dt,t.geoGinzburg9=function(){return e.geoProjection(Rt).scale(131.087)},t.geoGinzburg9Raw=Rt,t.geoGringorten=function(){return e.geoProjection(Ft(Bt)).scale(239.75)},t.geoGringortenRaw=Bt,t.geoGuyou=function(){return e.geoProjection(Ft(Ut)).scale(151.496)},t.geoGuyouRaw=Ut,t.geoHammer=function(){var t=2,r=e.geoProjectionMutator(j),n=r(t);return n.coefficient=function(e){return arguments.length?r(t=+e):t},n.scale(169.529)},t.geoHammerRaw=j,t.geoHammerRetroazimuthal=function(){var t=0,r=e.geoProjectionMutator(Vt),n=r(t),i=n.rotate,a=n.stream,o=e.geoCircle();return n.parallel=function(e){if(!arguments.length)return t*A;var i=n.rotate();return r(t=e*M).rotate(i)},n.rotate=function(e){return arguments.length?(i.call(n,[e[0],e[1]-t*A]),o.center([-e[0],-e[1]]),n):((e=i.call(n))[1]+=t*A,e)},n.stream=function(t){return(t=a(t)).sphere=function(){t.polygonStart();var e,r=o.radius(89.99)().coordinates[0],n=r.length-1,i=-1;for(t.lineStart();++i<n;)t.point((e=r[i])[0],e[1]);for(t.lineEnd(),n=(r=o.radius(90.01)().coordinates[0]).length-1,t.lineStart();--i>=0;)t.point((e=r[i])[0],e[1]);t.lineEnd(),t.polygonEnd()},t},n.scale(79.4187).parallel(45).clipAngle(179.999)},t.geoHammerRetroazimuthalRaw=Vt,t.geoHealpix=function(){var t=4,n=e.geoProjectionMutator(Yt),i=n(t),a=i.stream;return i.lobes=function(e){return arguments.length?n(t=+e):t},i.stream=function(n){var o=i.rotate(),s=a(n),l=(i.rotate([0,0]),a(n));return i.rotate(o),s.sphere=function(){var n,i;e.geoStream((n=180/t,i=[].concat(r.range(-180,180+n/2,n).map(Wt),r.range(180,-180-n/2,-n).map(Xt)),{type:"Polygon",coordinates:[180===n?i.map(Zt):i]}),l)},s},i.scale(239.75)},t.geoHealpixRaw=Yt,t.geoHill=function(){var t=1,r=e.geoProjectionMutator(Jt),n=r(t);return n.ratio=function(e){return arguments.length?r(t=+e):t},n.scale(167.774).center([0,18.67])},t.geoHillRaw=Jt,t.geoHomolosine=function(){return e.geoProjection(Qt).scale(152.63)},t.geoHomolosineRaw=Qt,t.geoHufnagel=function(){var t=1,r=0,n=45*M,i=2,a=e.geoProjectionMutator($t),o=a(t,r,n,i);return o.a=function(e){return arguments.length?a(t=+e,r,n,i):t},o.b=function(e){return arguments.length?a(t,r=+e,n,i):r},o.psiMax=function(e){return arguments.length?a(t,r,n=+e*M,i):n*A},o.ratio=function(e){return arguments.length?a(t,r,n,i=+e):i},o.scale(180.739)},t.geoHufnagelRaw=$t,t.geoHyperelliptical=function(){var t=0,r=2.5,n=1.183136,i=e.geoProjectionMutator(ee),a=i(t,r,n);return a.alpha=function(e){return arguments.length?i(t=+e,r,n):t},a.k=function(e){return arguments.length?i(t,r=+e,n):r},a.gamma=function(e){return arguments.length?i(t,r,n=+e):n},a.scale(152.63)},t.geoHyperellipticalRaw=ee,t.geoInterrupt=ae,t.geoInterruptedBoggs=function(){return ae(J,oe).scale(160.857)},t.geoInterruptedHomolosine=function(){return ae(Qt,se).scale(152.63)},t.geoInterruptedMollweide=function(){return ae(W,le).scale(169.529)},t.geoInterruptedMollweideHemispheres=function(){return ae(W,ce).scale(169.529).rotate([20,0])},t.geoInterruptedSinuMollweide=function(){return ae(Kt,ue,H).rotate([-20,-55]).scale(164.263).center([0,-5.4036])},t.geoInterruptedSinusoidal=function(){return ae(Q,fe).scale(152.63).rotate([-20,0])},t.geoKavrayskiy7=function(){return e.geoProjection(he).scale(158.837)},t.geoKavrayskiy7Raw=he,t.geoLagrange=function(){var t=.5,r=e.geoProjectionMutator(pe),n=r(t);return n.spacing=function(e){return arguments.length?r(t=+e):t},n.scale(124.75)},t.geoLagrangeRaw=pe,t.geoLarrivee=function(){return e.geoProjection(me).scale(97.2672)},t.geoLarriveeRaw=me,t.geoLaskowski=function(){return e.geoProjection(ge).scale(139.98)},t.geoLaskowskiRaw=ge,t.geoLittrow=function(){return e.geoProjection(ve).scale(144.049).clipAngle(89.999)},t.geoLittrowRaw=ve,t.geoLoximuthal=function(){return K(ye).parallel(40).scale(158.837)},t.geoLoximuthalRaw=ye,t.geoMiller=function(){return e.geoProjection(xe).scale(108.318)},t.geoMillerRaw=xe,t.geoModifiedStereographic=Me,t.geoModifiedStereographicRaw=be,t.geoModifiedStereographicAlaska=function(){return Me(_e,[152,-64]).scale(1400).center([-160.908,62.4864]).clipAngle(30).angle(7.8)},t.geoModifiedStereographicGs48=function(){return Me(we,[95,-38]).scale(1e3).clipAngle(55).center([-96.5563,38.8675])},t.geoModifiedStereographicGs50=function(){return Me(Te,[120,-45]).scale(359.513).clipAngle(55).center([-117.474,53.0628])},t.geoModifiedStereographicMiller=function(){return Me(ke,[-20,-18]).scale(209.091).center([20,16.7214]).clipAngle(82)},t.geoModifiedStereographicLee=function(){return Me(Ae,[165,10]).scale(250).clipAngle(130).center([-165,-10])},t.geoMollweide=function(){return e.geoProjection(W).scale(169.529)},t.geoMollweideRaw=W,t.geoMtFlatPolarParabolic=function(){return e.geoProjection(Le).scale(164.859)},t.geoMtFlatPolarParabolicRaw=Le,t.geoMtFlatPolarQuartic=function(){return e.geoProjection(Ce).scale(188.209)},t.geoMtFlatPolarQuarticRaw=Ce,t.geoMtFlatPolarSinusoidal=function(){return e.geoProjection(Pe).scale(166.518)},t.geoMtFlatPolarSinusoidalRaw=Pe,t.geoNaturalEarth2=function(){return e.geoProjection(Ie).scale(175.295)},t.geoNaturalEarth2Raw=Ie,t.geoNellHammer=function(){return e.geoProjection(Oe).scale(152.63)},t.geoNellHammerRaw=Oe,t.geoInterruptedQuarticAuthalic=function(){return ae(j(1/0),ze).rotate([20,0]).scale(152.63)},t.geoNicolosi=function(){return e.geoProjection(De).scale(127.267)},t.geoNicolosiRaw=De,t.geoPatterson=function(){return e.geoProjection(Re).scale(139.319)},t.geoPattersonRaw=Re,t.geoPolyconic=function(){return e.geoProjection(Fe).scale(103.74)},t.geoPolyconicRaw=Fe,t.geoPolyhedral=Ve,t.geoPolyhedralButterfly=function(t){t=t||function(t){var r=e.geoCentroid({type:"MultiPoint",coordinates:t});return e.geoGnomonic().scale(1).translate([0,0]).rotate([-r[0],-r[1]])};var r=Ye.map((function(e){return{face:e,project:t(e)}}));return[-1,0,0,1,0,1,4,5].forEach((function(t,e){var n=r[t];n&&(n.children||(n.children=[])).push(r[e])})),Ve(r[0],(function(t,e){return r[t<-y/2?e<0?6:4:t<0?e<0?2:0:t<y/2?e<0?3:1:e<0?7:5]})).angle(-30).scale(101.858).center([0,45])},t.geoPolyhedralCollignon=function(t){t=t||function(t){var r=e.geoCentroid({type:"MultiPoint",coordinates:t});return e.geoProjection(Xe).translate([0,0]).scale(1).rotate(r[1]>0?[-r[0],0]:[180-r[0],180])};var r=Ye.map((function(e){return{face:e,project:t(e)}}));return[-1,0,0,1,0,1,4,5].forEach((function(t,e){var n=r[t];n&&(n.children||(n.children=[])).push(r[e])})),Ve(r[0],(function(t,e){return r[t<-y/2?e<0?6:4:t<0?e<0?2:0:t<y/2?e<0?3:1:e<0?7:5]})).angle(-30).scale(121.906).center([0,48.5904])},t.geoPolyhedralWaterman=function(t){t=t||function(t){var r=6===t.length?e.geoCentroid({type:"MultiPoint",coordinates:t}):t[0];return e.geoGnomonic().scale(1).translate([0,0]).rotate([-r[0],-r[1]])};var r=Ye.map((function(t){for(var e,r=t.map(Ke),n=r.length,i=r[n-1],a=[],o=0;o<n;++o)e=r[o],a.push(Je([.9486832980505138*i[0]+.31622776601683794*e[0],.9486832980505138*i[1]+.31622776601683794*e[1],.9486832980505138*i[2]+.31622776601683794*e[2]]),Je([.9486832980505138*e[0]+.31622776601683794*i[0],.9486832980505138*e[1]+.31622776601683794*i[1],.9486832980505138*e[2]+.31622776601683794*i[2]])),i=e;return a})),n=[],i=[-1,0,0,1,0,1,4,5];r.forEach((function(t,e){for(var a,o,s=Ye[e],l=s.length,c=n[e]=[],u=0;u<l;++u)r.push([s[u],t[(2*u+2)%(2*l)],t[(2*u+1)%(2*l)]]),i.push(e),c.push((a=Ke(t[(2*u+2)%(2*l)]),o=Ke(t[(2*u+1)%(2*l)]),[a[1]*o[2]-a[2]*o[1],a[2]*o[0]-a[0]*o[2],a[0]*o[1]-a[1]*o[0]]))}));var a=r.map((function(e){return{project:t(e),face:e}}));return i.forEach((function(t,e){var r=a[t];r&&(r.children||(r.children=[])).push(a[e])})),Ve(a[0],(function(t,e){var r=o(e),i=[r*o(t),r*m(t),m(e)],s=t<-y/2?e<0?6:4:t<0?e<0?2:0:t<y/2?e<0?3:1:e<0?7:5,l=n[s];return a[Ze(l[0],i)<0?8+3*s:Ze(l[1],i)<0?8+3*s+1:Ze(l[2],i)<0?8+3*s+2:s]})).angle(-30).scale(110.625).center([0,45])},t.geoProject=function(t,e){var r,n=e.stream;if(!n)throw new Error("invalid projection");switch(t&&t.type){case"Feature":r=tr;break;case"FeatureCollection":r=$e;break;default:r=er}return r(t,n)},t.geoGringortenQuincuncial=function(){return sr(Bt).scale(176.423)},t.geoPeirceQuincuncial=lr,t.geoPierceQuincuncial=lr,t.geoQuantize=function(t,e){if(!(0<=(e=+e)&&e<=20))throw new Error("invalid digits");function r(t){var r=t.length,n=2,i=new Array(r);for(i[0]=+t[0].toFixed(e),i[1]=+t[1].toFixed(e);n<r;)i[n]=t[n],++n;return i}function n(t){return t.map(r)}function i(t){for(var e=r(t[0]),n=[e],i=1;i<t.length;i++){var a=r(t[i]);(a.length>2||a[0]!=e[0]||a[1]!=e[1])&&(n.push(a),e=a)}return 1===n.length&&t.length>1&&n.push(r(t[t.length-1])),n}function a(t){return t.map(i)}function o(t){if(null==t)return t;var e;switch(t.type){case"GeometryCollection":e={type:"GeometryCollection",geometries:t.geometries.map(o)};break;case"Point":e={type:"Point",coordinates:r(t.coordinates)};break;case"MultiPoint":e={type:t.type,coordinates:n(t.coordinates)};break;case"LineString":e={type:t.type,coordinates:i(t.coordinates)};break;case"MultiLineString":case"Polygon":e={type:t.type,coordinates:a(t.coordinates)};break;case"MultiPolygon":e={type:"MultiPolygon",coordinates:t.coordinates.map(a)};break;default:return t}return null!=t.bbox&&(e.bbox=t.bbox),e}function s(t){var e={type:"Feature",properties:t.properties,geometry:o(t.geometry)};return null!=t.id&&(e.id=t.id),null!=t.bbox&&(e.bbox=t.bbox),e}if(null!=t)switch(t.type){case"Feature":return s(t);case"FeatureCollection":var l={type:"FeatureCollection",features:t.features.map(s)};return null!=t.bbox&&(l.bbox=t.bbox),l;default:return o(t)}return t},t.geoQuincuncial=sr,t.geoRectangularPolyconic=function(){return K(cr).scale(131.215)},t.geoRectangularPolyconicRaw=cr,t.geoRobinson=function(){return e.geoProjection(fr).scale(152.63)},t.geoRobinsonRaw=fr,t.geoSatellite=function(){var t=2,r=0,n=e.geoProjectionMutator(hr),i=n(t,r);return i.distance=function(e){return arguments.length?n(t=+e,r):t},i.tilt=function(e){return arguments.length?n(t,r=e*M):r*A},i.scale(432.147).clipAngle(E(1/t)*A-1e-6)},t.geoSatelliteRaw=hr,t.geoSinuMollweide=function(){return e.geoProjection(Kt).rotate([-20,-55]).scale(164.263).center([0,-5.4036])},t.geoSinuMollweideRaw=Kt,t.geoSinusoidal=function(){return e.geoProjection(Q).scale(152.63)},t.geoSinusoidalRaw=Q,t.geoStitch=function(t){if(null==t)return t;switch(t.type){case"Feature":return wr(t);case"FeatureCollection":var e={type:"FeatureCollection",features:t.features.map(wr)};return null!=t.bbox&&(e.bbox=t.bbox),e;default:return Tr(t)}},t.geoTimes=function(){return e.geoProjection(kr).scale(146.153)},t.geoTimesRaw=kr,t.geoTwoPointAzimuthal=Sr,t.geoTwoPointAzimuthalRaw=Mr,t.geoTwoPointAzimuthalUsa=function(){return Sr([-158,21.5],[-77,39]).clipAngle(60).scale(400)},t.geoTwoPointEquidistant=Lr,t.geoTwoPointEquidistantRaw=Er,t.geoTwoPointEquidistantUsa=function(){return Lr([-158,21.5],[-77,39]).clipAngle(130).scale(122.571)},t.geoVanDerGrinten=function(){return e.geoProjection(Cr).scale(79.4183)},t.geoVanDerGrintenRaw=Cr,t.geoVanDerGrinten2=function(){return e.geoProjection(Pr).scale(79.4183)},t.geoVanDerGrinten2Raw=Pr,t.geoVanDerGrinten3=function(){return e.geoProjection(Ir).scale(79.4183)},t.geoVanDerGrinten3Raw=Ir,t.geoVanDerGrinten4=function(){return e.geoProjection(Or).scale(127.16)},t.geoVanDerGrinten4Raw=Or,t.geoWagner=Dr,t.geoWagner7=function(){return Dr().poleline(65).parallels(60).inflation(0).ratio(200).scale(172.633)},t.geoWagnerRaw=zr,t.geoWagner4=function(){return e.geoProjection(Br).scale(176.84)},t.geoWagner4Raw=Br,t.geoWagner6=function(){return e.geoProjection(Nr).scale(152.63)},t.geoWagner6Raw=Nr,t.geoWiechel=function(){return e.geoProjection(jr).rotate([0,-90,45]).scale(124.75).clipAngle(179.999)},t.geoWiechelRaw=jr,t.geoWinkel3=function(){return e.geoProjection(Ur).scale(158.837)},t.geoWinkel3Raw=Ur,Object.defineProperty(t,"__esModule",{value:!0})}))},{"d3-array":107,"d3-geo":114}],114:[function(t,e,r){!function(n,i){"object"==typeof r&&void 0!==e?i(r,t("d3-array")):i((n=n||self).d3=n.d3||{},n.d3)}(this,(function(t,e){"use strict";function r(){return new n}function n(){this.reset()}n.prototype={constructor:n,reset:function(){this.s=this.t=0},add:function(t){a(i,t,this.t),a(this,i.s,this.s),this.s?this.t+=i.t:this.s=i.t},valueOf:function(){return this.s}};var i=new n;function a(t,e,r){var n=t.s=e+r,i=n-e,a=n-i;t.t=e-a+(r-i)}var o=1e-6,s=Math.PI,l=s/2,c=s/4,u=2*s,f=180/s,h=s/180,p=Math.abs,d=Math.atan,m=Math.atan2,g=Math.cos,v=Math.ceil,y=Math.exp,x=Math.log,b=Math.pow,_=Math.sin,w=Math.sign||function(t){return t>0?1:t<0?-1:0},T=Math.sqrt,k=Math.tan;function A(t){return t>1?0:t<-1?s:Math.acos(t)}function M(t){return t>1?l:t<-1?-l:Math.asin(t)}function S(t){return(t=_(t/2))*t}function E(){}function L(t,e){t&&P.hasOwnProperty(t.type)&&P[t.type](t,e)}var C={Feature:function(t,e){L(t.geometry,e)},FeatureCollection:function(t,e){for(var r=t.features,n=-1,i=r.length;++n<i;)L(r[n].geometry,e)}},P={Sphere:function(t,e){e.sphere()},Point:function(t,e){t=t.coordinates,e.point(t[0],t[1],t[2])},MultiPoint:function(t,e){for(var r=t.coordinates,n=-1,i=r.length;++n<i;)t=r[n],e.point(t[0],t[1],t[2])},LineString:function(t,e){I(t.coordinates,e,0)},MultiLineString:function(t,e){for(var r=t.coordinates,n=-1,i=r.length;++n<i;)I(r[n],e,0)},Polygon:function(t,e){O(t.coordinates,e)},MultiPolygon:function(t,e){for(var r=t.coordinates,n=-1,i=r.length;++n<i;)O(r[n],e)},GeometryCollection:function(t,e){for(var r=t.geometries,n=-1,i=r.length;++n<i;)L(r[n],e)}};function I(t,e,r){var n,i=-1,a=t.length-r;for(e.lineStart();++i<a;)n=t[i],e.point(n[0],n[1],n[2]);e.lineEnd()}function O(t,e){var r=-1,n=t.length;for(e.polygonStart();++r<n;)I(t[r],e,1);e.polygonEnd()}function z(t,e){t&&C.hasOwnProperty(t.type)?C[t.type](t,e):L(t,e)}var D,R,F,B,N,j=r(),U=r(),V={point:E,lineStart:E,lineEnd:E,polygonStart:function(){j.reset(),V.lineStart=H,V.lineEnd=q},polygonEnd:function(){var t=+j;U.add(t<0?u+t:t),this.lineStart=this.lineEnd=this.point=E},sphere:function(){U.add(u)}};function H(){V.point=G}function q(){Y(D,R)}function G(t,e){V.point=Y,D=t,R=e,F=t*=h,B=g(e=(e*=h)/2+c),N=_(e)}function Y(t,e){var r=(t*=h)-F,n=r>=0?1:-1,i=n*r,a=g(e=(e*=h)/2+c),o=_(e),s=N*o,l=B*a+s*g(i),u=s*n*_(i);j.add(m(u,l)),F=t,B=a,N=o}function W(t){return[m(t[1],t[0]),M(t[2])]}function X(t){var e=t[0],r=t[1],n=g(r);return[n*g(e),n*_(e),_(r)]}function Z(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function J(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function K(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function Q(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function $(t){var e=T(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}var tt,et,rt,nt,it,at,ot,st,lt,ct,ut,ft,ht,pt,dt,mt,gt,vt,yt,xt,bt,_t,wt,Tt,kt,At,Mt=r(),St={point:Et,lineStart:Ct,lineEnd:Pt,polygonStart:function(){St.point=It,St.lineStart=Ot,St.lineEnd=zt,Mt.reset(),V.polygonStart()},polygonEnd:function(){V.polygonEnd(),St.point=Et,St.lineStart=Ct,St.lineEnd=Pt,j<0?(tt=-(rt=180),et=-(nt=90)):Mt>o?nt=90:Mt<-o&&(et=-90),ct[0]=tt,ct[1]=rt},sphere:function(){tt=-(rt=180),et=-(nt=90)}};function Et(t,e){lt.push(ct=[tt=t,rt=t]),e<et&&(et=e),e>nt&&(nt=e)}function Lt(t,e){var r=X([t*h,e*h]);if(st){var n=J(st,r),i=J([n[1],-n[0],0],n);$(i),i=W(i);var a,o=t-it,s=o>0?1:-1,l=i[0]*f*s,c=p(o)>180;c^(s*it<l&&l<s*t)?(a=i[1]*f)>nt&&(nt=a):c^(s*it<(l=(l+360)%360-180)&&l<s*t)?(a=-i[1]*f)<et&&(et=a):(e<et&&(et=e),e>nt&&(nt=e)),c?t<it?Dt(tt,t)>Dt(tt,rt)&&(rt=t):Dt(t,rt)>Dt(tt,rt)&&(tt=t):rt>=tt?(t<tt&&(tt=t),t>rt&&(rt=t)):t>it?Dt(tt,t)>Dt(tt,rt)&&(rt=t):Dt(t,rt)>Dt(tt,rt)&&(tt=t)}else lt.push(ct=[tt=t,rt=t]);e<et&&(et=e),e>nt&&(nt=e),st=r,it=t}function Ct(){St.point=Lt}function Pt(){ct[0]=tt,ct[1]=rt,St.point=Et,st=null}function It(t,e){if(st){var r=t-it;Mt.add(p(r)>180?r+(r>0?360:-360):r)}else at=t,ot=e;V.point(t,e),Lt(t,e)}function Ot(){V.lineStart()}function zt(){It(at,ot),V.lineEnd(),p(Mt)>o&&(tt=-(rt=180)),ct[0]=tt,ct[1]=rt,st=null}function Dt(t,e){return(e-=t)<0?e+360:e}function Rt(t,e){return t[0]-e[0]}function Ft(t,e){return t[0]<=t[1]?t[0]<=e&&e<=t[1]:e<t[0]||t[1]<e}var Bt={sphere:E,point:Nt,lineStart:Ut,lineEnd:qt,polygonStart:function(){Bt.lineStart=Gt,Bt.lineEnd=Yt},polygonEnd:function(){Bt.lineStart=Ut,Bt.lineEnd=qt}};function Nt(t,e){t*=h;var r=g(e*=h);jt(r*g(t),r*_(t),_(e))}function jt(t,e,r){++ut,ht+=(t-ht)/ut,pt+=(e-pt)/ut,dt+=(r-dt)/ut}function Ut(){Bt.point=Vt}function Vt(t,e){t*=h;var r=g(e*=h);Tt=r*g(t),kt=r*_(t),At=_(e),Bt.point=Ht,jt(Tt,kt,At)}function Ht(t,e){t*=h;var r=g(e*=h),n=r*g(t),i=r*_(t),a=_(e),o=m(T((o=kt*a-At*i)*o+(o=At*n-Tt*a)*o+(o=Tt*i-kt*n)*o),Tt*n+kt*i+At*a);ft+=o,mt+=o*(Tt+(Tt=n)),gt+=o*(kt+(kt=i)),vt+=o*(At+(At=a)),jt(Tt,kt,At)}function qt(){Bt.point=Nt}function Gt(){Bt.point=Wt}function Yt(){Xt(_t,wt),Bt.point=Nt}function Wt(t,e){_t=t,wt=e,t*=h,e*=h,Bt.point=Xt;var r=g(e);Tt=r*g(t),kt=r*_(t),At=_(e),jt(Tt,kt,At)}function Xt(t,e){t*=h;var r=g(e*=h),n=r*g(t),i=r*_(t),a=_(e),o=kt*a-At*i,s=At*n-Tt*a,l=Tt*i-kt*n,c=T(o*o+s*s+l*l),u=M(c),f=c&&-u/c;yt+=f*o,xt+=f*s,bt+=f*l,ft+=u,mt+=u*(Tt+(Tt=n)),gt+=u*(kt+(kt=i)),vt+=u*(At+(At=a)),jt(Tt,kt,At)}function Zt(t){return function(){return t}}function Jt(t,e){function r(r,n){return r=t(r,n),e(r[0],r[1])}return t.invert&&e.invert&&(r.invert=function(r,n){return(r=e.invert(r,n))&&t.invert(r[0],r[1])}),r}function Kt(t,e){return[p(t)>s?t+Math.round(-t/u)*u:t,e]}function Qt(t,e,r){return(t%=u)?e||r?Jt(te(t),ee(e,r)):te(t):e||r?ee(e,r):Kt}function $t(t){return function(e,r){return[(e+=t)>s?e-u:e<-s?e+u:e,r]}}function te(t){var e=$t(t);return e.invert=$t(-t),e}function ee(t,e){var r=g(t),n=_(t),i=g(e),a=_(e);function o(t,e){var o=g(e),s=g(t)*o,l=_(t)*o,c=_(e),u=c*r+s*n;return[m(l*i-u*a,s*r-c*n),M(u*i+l*a)]}return o.invert=function(t,e){var o=g(e),s=g(t)*o,l=_(t)*o,c=_(e),u=c*i-l*a;return[m(l*i+c*a,s*r+u*n),M(u*r-s*n)]},o}function re(t){function e(e){return(e=t(e[0]*h,e[1]*h))[0]*=f,e[1]*=f,e}return t=Qt(t[0]*h,t[1]*h,t.length>2?t[2]*h:0),e.invert=function(e){return(e=t.invert(e[0]*h,e[1]*h))[0]*=f,e[1]*=f,e},e}function ne(t,e,r,n,i,a){if(r){var o=g(e),s=_(e),l=n*r;null==i?(i=e+n*u,a=e-l/2):(i=ie(o,i),a=ie(o,a),(n>0?i<a:i>a)&&(i+=n*u));for(var c,f=i;n>0?f>a:f<a;f-=l)c=W([o,-s*g(f),-s*_(f)]),t.point(c[0],c[1])}}function ie(t,e){(e=X(e))[0]-=t,$(e);var r=A(-e[1]);return((-e[2]<0?-r:r)+u-o)%u}function ae(){var t,e=[];return{point:function(e,r,n){t.push([e,r,n])},lineStart:function(){e.push(t=[])},lineEnd:E,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var r=e;return e=[],t=null,r}}}function oe(t,e){return p(t[0]-e[0])<o&&p(t[1]-e[1])<o}function se(t,e,r,n){this.x=t,this.z=e,this.o=r,this.e=n,this.v=!1,this.n=this.p=null}function le(t,e,r,n,i){var a,s,l=[],c=[];if(t.forEach((function(t){if(!((e=t.length-1)<=0)){var e,r,n=t[0],s=t[e];if(oe(n,s)){if(!n[2]&&!s[2]){for(i.lineStart(),a=0;a<e;++a)i.point((n=t[a])[0],n[1]);return void i.lineEnd()}s[0]+=2*o}l.push(r=new se(n,t,null,!0)),c.push(r.o=new se(n,null,r,!1)),l.push(r=new se(s,t,null,!1)),c.push(r.o=new se(s,null,r,!0))}})),l.length){for(c.sort(e),ce(l),ce(c),a=0,s=c.length;a<s;++a)c[a].e=r=!r;for(var u,f,h=l[0];;){for(var p=h,d=!0;p.v;)if((p=p.n)===h)return;u=p.z,i.lineStart();do{if(p.v=p.o.v=!0,p.e){if(d)for(a=0,s=u.length;a<s;++a)i.point((f=u[a])[0],f[1]);else n(p.x,p.n.x,1,i);p=p.n}else{if(d)for(u=p.p.z,a=u.length-1;a>=0;--a)i.point((f=u[a])[0],f[1]);else n(p.x,p.p.x,-1,i);p=p.p}u=(p=p.o).z,d=!d}while(!p.v);i.lineEnd()}}}function ce(t){if(e=t.length){for(var e,r,n=0,i=t[0];++n<e;)i.n=r=t[n],r.p=i,i=r;i.n=r=t[0],r.p=i}}Kt.invert=Kt;var ue=r();function fe(t){return p(t[0])<=s?t[0]:w(t[0])*((p(t[0])+s)%u-s)}function he(t,e){var r=fe(e),n=e[1],i=_(n),a=[_(r),-g(r),0],f=0,h=0;ue.reset(),1===i?n=l+o:-1===i&&(n=-l-o);for(var p=0,d=t.length;p<d;++p)if(y=(v=t[p]).length)for(var v,y,x=v[y-1],b=fe(x),w=x[1]/2+c,T=_(w),k=g(w),A=0;A<y;++A,b=E,T=C,k=P,x=S){var S=v[A],E=fe(S),L=S[1]/2+c,C=_(L),P=g(L),I=E-b,O=I>=0?1:-1,z=O*I,D=z>s,R=T*C;if(ue.add(m(R*O*_(z),k*P+R*g(z))),f+=D?I+O*u:I,D^b>=r^E>=r){var F=J(X(x),X(S));$(F);var B=J(a,F);$(B);var N=(D^I>=0?-1:1)*M(B[2]);(n>N||n===N&&(F[0]||F[1]))&&(h+=D^I>=0?1:-1)}}return(f<-o||f<o&&ue<-o)^1&h}function pe(t,r,n,i){return function(a){var o,s,l,c=r(a),u=ae(),f=r(u),h=!1,p={point:d,lineStart:g,lineEnd:v,polygonStart:function(){p.point=y,p.lineStart=x,p.lineEnd=b,s=[],o=[]},polygonEnd:function(){p.point=d,p.lineStart=g,p.lineEnd=v,s=e.merge(s);var t=he(o,i);s.length?(h||(a.polygonStart(),h=!0),le(s,me,t,n,a)):t&&(h||(a.polygonStart(),h=!0),a.lineStart(),n(null,null,1,a),a.lineEnd()),h&&(a.polygonEnd(),h=!1),s=o=null},sphere:function(){a.polygonStart(),a.lineStart(),n(null,null,1,a),a.lineEnd(),a.polygonEnd()}};function d(e,r){t(e,r)&&a.point(e,r)}function m(t,e){c.point(t,e)}function g(){p.point=m,c.lineStart()}function v(){p.point=d,c.lineEnd()}function y(t,e){l.push([t,e]),f.point(t,e)}function x(){f.lineStart(),l=[]}function b(){y(l[0][0],l[0][1]),f.lineEnd();var t,e,r,n,i=f.clean(),c=u.result(),p=c.length;if(l.pop(),o.push(l),l=null,p)if(1&i){if((e=(r=c[0]).length-1)>0){for(h||(a.polygonStart(),h=!0),a.lineStart(),t=0;t<e;++t)a.point((n=r[t])[0],n[1]);a.lineEnd()}}else p>1&&2&i&&c.push(c.pop().concat(c.shift())),s.push(c.filter(de))}return p}}function de(t){return t.length>1}function me(t,e){return((t=t.x)[0]<0?t[1]-l-o:l-t[1])-((e=e.x)[0]<0?e[1]-l-o:l-e[1])}var ge=pe((function(){return!0}),(function(t){var e,r=NaN,n=NaN,i=NaN;return{lineStart:function(){t.lineStart(),e=1},point:function(a,c){var u=a>0?s:-s,f=p(a-r);p(f-s)<o?(t.point(r,n=(n+c)/2>0?l:-l),t.point(i,n),t.lineEnd(),t.lineStart(),t.point(u,n),t.point(a,n),e=0):i!==u&&f>=s&&(p(r-i)<o&&(r-=i*o),p(a-u)<o&&(a-=u*o),n=function(t,e,r,n){var i,a,s=_(t-r);return p(s)>o?d((_(e)*(a=g(n))*_(r)-_(n)*(i=g(e))*_(t))/(i*a*s)):(e+n)/2}(r,n,a,c),t.point(i,n),t.lineEnd(),t.lineStart(),t.point(u,n),e=0),t.point(r=a,n=c),i=u},lineEnd:function(){t.lineEnd(),r=n=NaN},clean:function(){return 2-e}}}),(function(t,e,r,n){var i;if(null==t)i=r*l,n.point(-s,i),n.point(0,i),n.point(s,i),n.point(s,0),n.point(s,-i),n.point(0,-i),n.point(-s,-i),n.point(-s,0),n.point(-s,i);else if(p(t[0]-e[0])>o){var a=t[0]<e[0]?s:-s;i=r*a/2,n.point(-a,i),n.point(0,i),n.point(a,i)}else n.point(e[0],e[1])}),[-s,-l]);function ve(t){var e=g(t),r=6*h,n=e>0,i=p(e)>o;function a(t,r){return g(t)*g(r)>e}function l(t,r,n){var i=[1,0,0],a=J(X(t),X(r)),l=Z(a,a),c=a[0],u=l-c*c;if(!u)return!n&&t;var f=e*l/u,h=-e*c/u,d=J(i,a),m=Q(i,f);K(m,Q(a,h));var g=d,v=Z(m,g),y=Z(g,g),x=v*v-y*(Z(m,m)-1);if(!(x<0)){var b=T(x),_=Q(g,(-v-b)/y);if(K(_,m),_=W(_),!n)return _;var w,k=t[0],A=r[0],M=t[1],S=r[1];A<k&&(w=k,k=A,A=w);var E=A-k,L=p(E-s)<o;if(!L&&S<M&&(w=M,M=S,S=w),L||E<o?L?M+S>0^_[1]<(p(_[0]-k)<o?M:S):M<=_[1]&&_[1]<=S:E>s^(k<=_[0]&&_[0]<=A)){var C=Q(g,(-v+b)/y);return K(C,m),[_,W(C)]}}}function c(e,r){var i=n?t:s-t,a=0;return e<-i?a|=1:e>i&&(a|=2),r<-i?a|=4:r>i&&(a|=8),a}return pe(a,(function(t){var e,r,o,u,f;return{lineStart:function(){u=o=!1,f=1},point:function(h,p){var d,m=[h,p],g=a(h,p),v=n?g?0:c(h,p):g?c(h+(h<0?s:-s),p):0;if(!e&&(u=o=g)&&t.lineStart(),g!==o&&(!(d=l(e,m))||oe(e,d)||oe(m,d))&&(m[2]=1),g!==o)f=0,g?(t.lineStart(),d=l(m,e),t.point(d[0],d[1])):(d=l(e,m),t.point(d[0],d[1],2),t.lineEnd()),e=d;else if(i&&e&&n^g){var y;v&r||!(y=l(m,e,!0))||(f=0,n?(t.lineStart(),t.point(y[0][0],y[0][1]),t.point(y[1][0],y[1][1]),t.lineEnd()):(t.point(y[1][0],y[1][1]),t.lineEnd(),t.lineStart(),t.point(y[0][0],y[0][1],3)))}!g||e&&oe(e,m)||t.point(m[0],m[1]),e=m,o=g,r=v},lineEnd:function(){o&&t.lineEnd(),e=null},clean:function(){return f|(u&&o)<<1}}}),(function(e,n,i,a){ne(a,t,r,i,e,n)}),n?[0,-t]:[-s,t-s])}function ye(t,r,n,i){function a(e,a){return t<=e&&e<=n&&r<=a&&a<=i}function s(e,a,o,s){var c=0,f=0;if(null==e||(c=l(e,o))!==(f=l(a,o))||u(e,a)<0^o>0)do{s.point(0===c||3===c?t:n,c>1?i:r)}while((c=(c+o+4)%4)!==f);else s.point(a[0],a[1])}function l(e,i){return p(e[0]-t)<o?i>0?0:3:p(e[0]-n)<o?i>0?2:1:p(e[1]-r)<o?i>0?1:0:i>0?3:2}function c(t,e){return u(t.x,e.x)}function u(t,e){var r=l(t,1),n=l(e,1);return r!==n?r-n:0===r?e[1]-t[1]:1===r?t[0]-e[0]:2===r?t[1]-e[1]:e[0]-t[0]}return function(o){var l,u,f,h,p,d,m,g,v,y,x,b=o,_=ae(),w={point:T,lineStart:function(){w.point=k,u&&u.push(f=[]);y=!0,v=!1,m=g=NaN},lineEnd:function(){l&&(k(h,p),d&&v&&_.rejoin(),l.push(_.result()));w.point=T,v&&b.lineEnd()},polygonStart:function(){b=_,l=[],u=[],x=!0},polygonEnd:function(){var r=function(){for(var e=0,r=0,n=u.length;r<n;++r)for(var a,o,s=u[r],l=1,c=s.length,f=s[0],h=f[0],p=f[1];l<c;++l)a=h,o=p,f=s[l],h=f[0],p=f[1],o<=i?p>i&&(h-a)*(i-o)>(p-o)*(t-a)&&++e:p<=i&&(h-a)*(i-o)<(p-o)*(t-a)&&--e;return e}(),n=x&&r,a=(l=e.merge(l)).length;(n||a)&&(o.polygonStart(),n&&(o.lineStart(),s(null,null,1,o),o.lineEnd()),a&&le(l,c,r,s,o),o.polygonEnd());b=o,l=u=f=null}};function T(t,e){a(t,e)&&b.point(t,e)}function k(e,o){var s=a(e,o);if(u&&f.push([e,o]),y)h=e,p=o,d=s,y=!1,s&&(b.lineStart(),b.point(e,o));else if(s&&v)b.point(e,o);else{var l=[m=Math.max(-1e9,Math.min(1e9,m)),g=Math.max(-1e9,Math.min(1e9,g))],c=[e=Math.max(-1e9,Math.min(1e9,e)),o=Math.max(-1e9,Math.min(1e9,o))];!function(t,e,r,n,i,a){var o,s=t[0],l=t[1],c=0,u=1,f=e[0]-s,h=e[1]-l;if(o=r-s,f||!(o>0)){if(o/=f,f<0){if(o<c)return;o<u&&(u=o)}else if(f>0){if(o>u)return;o>c&&(c=o)}if(o=i-s,f||!(o<0)){if(o/=f,f<0){if(o>u)return;o>c&&(c=o)}else if(f>0){if(o<c)return;o<u&&(u=o)}if(o=n-l,h||!(o>0)){if(o/=h,h<0){if(o<c)return;o<u&&(u=o)}else if(h>0){if(o>u)return;o>c&&(c=o)}if(o=a-l,h||!(o<0)){if(o/=h,h<0){if(o>u)return;o>c&&(c=o)}else if(h>0){if(o<c)return;o<u&&(u=o)}return c>0&&(t[0]=s+c*f,t[1]=l+c*h),u<1&&(e[0]=s+u*f,e[1]=l+u*h),!0}}}}}(l,c,t,r,n,i)?s&&(b.lineStart(),b.point(e,o),x=!1):(v||(b.lineStart(),b.point(l[0],l[1])),b.point(c[0],c[1]),s||b.lineEnd(),x=!1)}m=e,g=o,v=s}return w}}var xe,be,_e,we=r(),Te={sphere:E,point:E,lineStart:function(){Te.point=Ae,Te.lineEnd=ke},lineEnd:E,polygonStart:E,polygonEnd:E};function ke(){Te.point=Te.lineEnd=E}function Ae(t,e){xe=t*=h,be=_(e*=h),_e=g(e),Te.point=Me}function Me(t,e){t*=h;var r=_(e*=h),n=g(e),i=p(t-xe),a=g(i),o=n*_(i),s=_e*r-be*n*a,l=be*r+_e*n*a;we.add(m(T(o*o+s*s),l)),xe=t,be=r,_e=n}function Se(t){return we.reset(),z(t,Te),+we}var Ee=[null,null],Le={type:"LineString",coordinates:Ee};function Ce(t,e){return Ee[0]=t,Ee[1]=e,Se(Le)}var Pe={Feature:function(t,e){return Oe(t.geometry,e)},FeatureCollection:function(t,e){for(var r=t.features,n=-1,i=r.length;++n<i;)if(Oe(r[n].geometry,e))return!0;return!1}},Ie={Sphere:function(){return!0},Point:function(t,e){return ze(t.coordinates,e)},MultiPoint:function(t,e){for(var r=t.coordinates,n=-1,i=r.length;++n<i;)if(ze(r[n],e))return!0;return!1},LineString:function(t,e){return De(t.coordinates,e)},MultiLineString:function(t,e){for(var r=t.coordinates,n=-1,i=r.length;++n<i;)if(De(r[n],e))return!0;return!1},Polygon:function(t,e){return Re(t.coordinates,e)},MultiPolygon:function(t,e){for(var r=t.coordinates,n=-1,i=r.length;++n<i;)if(Re(r[n],e))return!0;return!1},GeometryCollection:function(t,e){for(var r=t.geometries,n=-1,i=r.length;++n<i;)if(Oe(r[n],e))return!0;return!1}};function Oe(t,e){return!(!t||!Ie.hasOwnProperty(t.type))&&Ie[t.type](t,e)}function ze(t,e){return 0===Ce(t,e)}function De(t,e){for(var r,n,i,a=0,o=t.length;a<o;a++){if(0===(n=Ce(t[a],e)))return!0;if(a>0&&(i=Ce(t[a],t[a-1]))>0&&r<=i&&n<=i&&(r+n-i)*(1-Math.pow((r-n)/i,2))<1e-12*i)return!0;r=n}return!1}function Re(t,e){return!!he(t.map(Fe),Be(e))}function Fe(t){return(t=t.map(Be)).pop(),t}function Be(t){return[t[0]*h,t[1]*h]}function Ne(t,r,n){var i=e.range(t,r-o,n).concat(r);return function(t){return i.map((function(e){return[t,e]}))}}function je(t,r,n){var i=e.range(t,r-o,n).concat(r);return function(t){return i.map((function(e){return[e,t]}))}}function Ue(){var t,r,n,i,a,s,l,c,u,f,h,d,m=10,g=m,y=90,x=360,b=2.5;function _(){return{type:"MultiLineString",coordinates:w()}}function w(){return e.range(v(i/y)*y,n,y).map(h).concat(e.range(v(c/x)*x,l,x).map(d)).concat(e.range(v(r/m)*m,t,m).filter((function(t){return p(t%y)>o})).map(u)).concat(e.range(v(s/g)*g,a,g).filter((function(t){return p(t%x)>o})).map(f))}return _.lines=function(){return w().map((function(t){return{type:"LineString",coordinates:t}}))},_.outline=function(){return{type:"Polygon",coordinates:[h(i).concat(d(l).slice(1),h(n).reverse().slice(1),d(c).reverse().slice(1))]}},_.extent=function(t){return arguments.length?_.extentMajor(t).extentMinor(t):_.extentMinor()},_.extentMajor=function(t){return arguments.length?(i=+t[0][0],n=+t[1][0],c=+t[0][1],l=+t[1][1],i>n&&(t=i,i=n,n=t),c>l&&(t=c,c=l,l=t),_.precision(b)):[[i,c],[n,l]]},_.extentMinor=function(e){return arguments.length?(r=+e[0][0],t=+e[1][0],s=+e[0][1],a=+e[1][1],r>t&&(e=r,r=t,t=e),s>a&&(e=s,s=a,a=e),_.precision(b)):[[r,s],[t,a]]},_.step=function(t){return arguments.length?_.stepMajor(t).stepMinor(t):_.stepMinor()},_.stepMajor=function(t){return arguments.length?(y=+t[0],x=+t[1],_):[y,x]},_.stepMinor=function(t){return arguments.length?(m=+t[0],g=+t[1],_):[m,g]},_.precision=function(e){return arguments.length?(b=+e,u=Ne(s,a,90),f=je(r,t,b),h=Ne(c,l,90),d=je(i,n,b),_):b},_.extentMajor([[-180,-90+o],[180,90-o]]).extentMinor([[-180,-80-o],[180,80+o]])}function Ve(t){return t}var He,qe,Ge,Ye,We=r(),Xe=r(),Ze={point:E,lineStart:E,lineEnd:E,polygonStart:function(){Ze.lineStart=Je,Ze.lineEnd=$e},polygonEnd:function(){Ze.lineStart=Ze.lineEnd=Ze.point=E,We.add(p(Xe)),Xe.reset()},result:function(){var t=We/2;return We.reset(),t}};function Je(){Ze.point=Ke}function Ke(t,e){Ze.point=Qe,He=Ge=t,qe=Ye=e}function Qe(t,e){Xe.add(Ye*t-Ge*e),Ge=t,Ye=e}function $e(){Qe(He,qe)}var tr=1/0,er=tr,rr=-tr,nr=rr,ir={point:function(t,e){t<tr&&(tr=t);t>rr&&(rr=t);e<er&&(er=e);e>nr&&(nr=e)},lineStart:E,lineEnd:E,polygonStart:E,polygonEnd:E,result:function(){var t=[[tr,er],[rr,nr]];return rr=nr=-(er=tr=1/0),t}};var ar,or,sr,lr,cr=0,ur=0,fr=0,hr=0,pr=0,dr=0,mr=0,gr=0,vr=0,yr={point:xr,lineStart:br,lineEnd:Tr,polygonStart:function(){yr.lineStart=kr,yr.lineEnd=Ar},polygonEnd:function(){yr.point=xr,yr.lineStart=br,yr.lineEnd=Tr},result:function(){var t=vr?[mr/vr,gr/vr]:dr?[hr/dr,pr/dr]:fr?[cr/fr,ur/fr]:[NaN,NaN];return cr=ur=fr=hr=pr=dr=mr=gr=vr=0,t}};function xr(t,e){cr+=t,ur+=e,++fr}function br(){yr.point=_r}function _r(t,e){yr.point=wr,xr(sr=t,lr=e)}function wr(t,e){var r=t-sr,n=e-lr,i=T(r*r+n*n);hr+=i*(sr+t)/2,pr+=i*(lr+e)/2,dr+=i,xr(sr=t,lr=e)}function Tr(){yr.point=xr}function kr(){yr.point=Mr}function Ar(){Sr(ar,or)}function Mr(t,e){yr.point=Sr,xr(ar=sr=t,or=lr=e)}function Sr(t,e){var r=t-sr,n=e-lr,i=T(r*r+n*n);hr+=i*(sr+t)/2,pr+=i*(lr+e)/2,dr+=i,mr+=(i=lr*t-sr*e)*(sr+t),gr+=i*(lr+e),vr+=3*i,xr(sr=t,lr=e)}function Er(t){this._context=t}Er.prototype={_radius:4.5,pointRadius:function(t){return this._radius=t,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._context.closePath(),this._point=NaN},point:function(t,e){switch(this._point){case 0:this._context.moveTo(t,e),this._point=1;break;case 1:this._context.lineTo(t,e);break;default:this._context.moveTo(t+this._radius,e),this._context.arc(t,e,this._radius,0,u)}},result:E};var Lr,Cr,Pr,Ir,Or,zr=r(),Dr={point:E,lineStart:function(){Dr.point=Rr},lineEnd:function(){Lr&&Fr(Cr,Pr),Dr.point=E},polygonStart:function(){Lr=!0},polygonEnd:function(){Lr=null},result:function(){var t=+zr;return zr.reset(),t}};function Rr(t,e){Dr.point=Fr,Cr=Ir=t,Pr=Or=e}function Fr(t,e){Ir-=t,Or-=e,zr.add(T(Ir*Ir+Or*Or)),Ir=t,Or=e}function Br(){this._string=[]}function Nr(t){return"m0,"+t+"a"+t+","+t+" 0 1,1 0,"+-2*t+"a"+t+","+t+" 0 1,1 0,"+2*t+"z"}function jr(t){return function(e){var r=new Ur;for(var n in t)r[n]=t[n];return r.stream=e,r}}function Ur(){}function Vr(t,e,r){var n=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),null!=n&&t.clipExtent(null),z(r,t.stream(ir)),e(ir.result()),null!=n&&t.clipExtent(n),t}function Hr(t,e,r){return Vr(t,(function(r){var n=e[1][0]-e[0][0],i=e[1][1]-e[0][1],a=Math.min(n/(r[1][0]-r[0][0]),i/(r[1][1]-r[0][1])),o=+e[0][0]+(n-a*(r[1][0]+r[0][0]))/2,s=+e[0][1]+(i-a*(r[1][1]+r[0][1]))/2;t.scale(150*a).translate([o,s])}),r)}function qr(t,e,r){return Hr(t,[[0,0],e],r)}function Gr(t,e,r){return Vr(t,(function(r){var n=+e,i=n/(r[1][0]-r[0][0]),a=(n-i*(r[1][0]+r[0][0]))/2,o=-i*r[0][1];t.scale(150*i).translate([a,o])}),r)}function Yr(t,e,r){return Vr(t,(function(r){var n=+e,i=n/(r[1][1]-r[0][1]),a=-i*r[0][0],o=(n-i*(r[1][1]+r[0][1]))/2;t.scale(150*i).translate([a,o])}),r)}Br.prototype={_radius:4.5,_circle:Nr(4.5),pointRadius:function(t){return(t=+t)!==this._radius&&(this._radius=t,this._circle=null),this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._string.push("Z"),this._point=NaN},point:function(t,e){switch(this._point){case 0:this._string.push("M",t,",",e),this._point=1;break;case 1:this._string.push("L",t,",",e);break;default:null==this._circle&&(this._circle=Nr(this._radius)),this._string.push("M",t,",",e,this._circle)}},result:function(){if(this._string.length){var t=this._string.join("");return this._string=[],t}return null}},Ur.prototype={constructor:Ur,point:function(t,e){this.stream.point(t,e)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};var Wr=g(30*h);function Xr(t,e){return+e?function(t,e){function r(n,i,a,s,l,c,u,f,h,d,g,v,y,x){var b=u-n,_=f-i,w=b*b+_*_;if(w>4*e&&y--){var k=s+d,A=l+g,S=c+v,E=T(k*k+A*A+S*S),L=M(S/=E),C=p(p(S)-1)<o||p(a-h)<o?(a+h)/2:m(A,k),P=t(C,L),I=P[0],O=P[1],z=I-n,D=O-i,R=_*z-b*D;(R*R/w>e||p((b*z+_*D)/w-.5)>.3||s*d+l*g+c*v<Wr)&&(r(n,i,a,s,l,c,I,O,C,k/=E,A/=E,S,y,x),x.point(I,O),r(I,O,C,k,A,S,u,f,h,d,g,v,y,x))}}return function(e){var n,i,a,o,s,l,c,u,f,h,p,d,m={point:g,lineStart:v,lineEnd:x,polygonStart:function(){e.polygonStart(),m.lineStart=b},polygonEnd:function(){e.polygonEnd(),m.lineStart=v}};function g(r,n){r=t(r,n),e.point(r[0],r[1])}function v(){u=NaN,m.point=y,e.lineStart()}function y(n,i){var a=X([n,i]),o=t(n,i);r(u,f,c,h,p,d,u=o[0],f=o[1],c=n,h=a[0],p=a[1],d=a[2],16,e),e.point(u,f)}function x(){m.point=g,e.lineEnd()}function b(){v(),m.point=_,m.lineEnd=w}function _(t,e){y(n=t,e),i=u,a=f,o=h,s=p,l=d,m.point=y}function w(){r(u,f,c,h,p,d,i,a,n,o,s,l,16,e),m.lineEnd=x,x()}return m}}(t,e):function(t){return jr({point:function(e,r){e=t(e,r),this.stream.point(e[0],e[1])}})}(t)}var Zr=jr({point:function(t,e){this.stream.point(t*h,e*h)}});function Jr(t,e,r,n,i){function a(a,o){return[e+t*(a*=n),r-t*(o*=i)]}return a.invert=function(a,o){return[(a-e)/t*n,(r-o)/t*i]},a}function Kr(t,e,r,n,i,a){var o=g(a),s=_(a),l=o*t,c=s*t,u=o/t,f=s/t,h=(s*r-o*e)/t,p=(s*e+o*r)/t;function d(t,a){return[l*(t*=n)-c*(a*=i)+e,r-c*t-l*a]}return d.invert=function(t,e){return[n*(u*t-f*e+h),i*(p-f*t-u*e)]},d}function Qr(t){return $r((function(){return t}))()}function $r(t){var e,r,n,i,a,o,s,l,c,u,p=150,d=480,m=250,g=0,v=0,y=0,x=0,b=0,_=0,w=1,k=1,A=null,M=ge,S=null,E=Ve,L=.5;function C(t){return l(t[0]*h,t[1]*h)}function P(t){return(t=l.invert(t[0],t[1]))&&[t[0]*f,t[1]*f]}function I(){var t=Kr(p,0,0,w,k,_).apply(null,e(g,v)),n=(_?Kr:Jr)(p,d-t[0],m-t[1],w,k,_);return r=Qt(y,x,b),s=Jt(e,n),l=Jt(r,s),o=Xr(s,L),O()}function O(){return c=u=null,C}return C.stream=function(t){return c&&u===t?c:c=Zr(function(t){return jr({point:function(e,r){var n=t(e,r);return this.stream.point(n[0],n[1])}})}(r)(M(o(E(u=t)))))},C.preclip=function(t){return arguments.length?(M=t,A=void 0,O()):M},C.postclip=function(t){return arguments.length?(E=t,S=n=i=a=null,O()):E},C.clipAngle=function(t){return arguments.length?(M=+t?ve(A=t*h):(A=null,ge),O()):A*f},C.clipExtent=function(t){return arguments.length?(E=null==t?(S=n=i=a=null,Ve):ye(S=+t[0][0],n=+t[0][1],i=+t[1][0],a=+t[1][1]),O()):null==S?null:[[S,n],[i,a]]},C.scale=function(t){return arguments.length?(p=+t,I()):p},C.translate=function(t){return arguments.length?(d=+t[0],m=+t[1],I()):[d,m]},C.center=function(t){return arguments.length?(g=t[0]%360*h,v=t[1]%360*h,I()):[g*f,v*f]},C.rotate=function(t){return arguments.length?(y=t[0]%360*h,x=t[1]%360*h,b=t.length>2?t[2]%360*h:0,I()):[y*f,x*f,b*f]},C.angle=function(t){return arguments.length?(_=t%360*h,I()):_*f},C.reflectX=function(t){return arguments.length?(w=t?-1:1,I()):w<0},C.reflectY=function(t){return arguments.length?(k=t?-1:1,I()):k<0},C.precision=function(t){return arguments.length?(o=Xr(s,L=t*t),O()):T(L)},C.fitExtent=function(t,e){return Hr(C,t,e)},C.fitSize=function(t,e){return qr(C,t,e)},C.fitWidth=function(t,e){return Gr(C,t,e)},C.fitHeight=function(t,e){return Yr(C,t,e)},function(){return e=t.apply(this,arguments),C.invert=e.invert&&P,I()}}function tn(t){var e=0,r=s/3,n=$r(t),i=n(e,r);return i.parallels=function(t){return arguments.length?n(e=t[0]*h,r=t[1]*h):[e*f,r*f]},i}function en(t,e){var r=_(t),n=(r+_(e))/2;if(p(n)<o)return function(t){var e=g(t);function r(t,r){return[t*e,_(r)/e]}return r.invert=function(t,r){return[t/e,M(r*e)]},r}(t);var i=1+r*(2*n-r),a=T(i)/n;function l(t,e){var r=T(i-2*n*_(e))/n;return[r*_(t*=n),a-r*g(t)]}return l.invert=function(t,e){var r=a-e,o=m(t,p(r))*w(r);return r*n<0&&(o-=s*w(t)*w(r)),[o/n,M((i-(t*t+r*r)*n*n)/(2*n))]},l}function rn(){return tn(en).scale(155.424).center([0,33.6442])}function nn(){return rn().parallels([29.5,45.5]).scale(1070).translate([480,250]).rotate([96,0]).center([-.6,38.7])}function an(t){return function(e,r){var n=g(e),i=g(r),a=t(n*i);return[a*i*_(e),a*_(r)]}}function on(t){return function(e,r){var n=T(e*e+r*r),i=t(n),a=_(i),o=g(i);return[m(e*a,n*o),M(n&&r*a/n)]}}var sn=an((function(t){return T(2/(1+t))}));sn.invert=on((function(t){return 2*M(t/2)}));var ln=an((function(t){return(t=A(t))&&t/_(t)}));function cn(t,e){return[t,x(k((l+e)/2))]}function un(t){var e,r,n,i=Qr(t),a=i.center,o=i.scale,l=i.translate,c=i.clipExtent,u=null;function f(){var a=s*o(),l=i(re(i.rotate()).invert([0,0]));return c(null==u?[[l[0]-a,l[1]-a],[l[0]+a,l[1]+a]]:t===cn?[[Math.max(l[0]-a,u),e],[Math.min(l[0]+a,r),n]]:[[u,Math.max(l[1]-a,e)],[r,Math.min(l[1]+a,n)]])}return i.scale=function(t){return arguments.length?(o(t),f()):o()},i.translate=function(t){return arguments.length?(l(t),f()):l()},i.center=function(t){return arguments.length?(a(t),f()):a()},i.clipExtent=function(t){return arguments.length?(null==t?u=e=r=n=null:(u=+t[0][0],e=+t[0][1],r=+t[1][0],n=+t[1][1]),f()):null==u?null:[[u,e],[r,n]]},f()}function fn(t){return k((l+t)/2)}function hn(t,e){var r=g(t),n=t===e?_(t):x(r/g(e))/x(fn(e)/fn(t)),i=r*b(fn(t),n)/n;if(!n)return cn;function a(t,e){i>0?e<-l+o&&(e=-l+o):e>l-o&&(e=l-o);var r=i/b(fn(e),n);return[r*_(n*t),i-r*g(n*t)]}return a.invert=function(t,e){var r=i-e,a=w(n)*T(t*t+r*r),o=m(t,p(r))*w(r);return r*n<0&&(o-=s*w(t)*w(r)),[o/n,2*d(b(i/a,1/n))-l]},a}function pn(t,e){return[t,e]}function dn(t,e){var r=g(t),n=t===e?_(t):(r-g(e))/(e-t),i=r/n+t;if(p(n)<o)return pn;function a(t,e){var r=i-e,a=n*t;return[r*_(a),i-r*g(a)]}return a.invert=function(t,e){var r=i-e,a=m(t,p(r))*w(r);return r*n<0&&(a-=s*w(t)*w(r)),[a/n,i-w(n)*T(t*t+r*r)]},a}ln.invert=on((function(t){return t})),cn.invert=function(t,e){return[t,2*d(y(e))-l]},pn.invert=pn;var mn=1.340264,gn=-.081106,vn=893e-6,yn=.003796,xn=T(3)/2;function bn(t,e){var r=M(xn*_(e)),n=r*r,i=n*n*n;return[t*g(r)/(xn*(mn+3*gn*n+i*(7*vn+9*yn*n))),r*(mn+gn*n+i*(vn+yn*n))]}function _n(t,e){var r=g(e),n=g(t)*r;return[r*_(t)/n,_(e)/n]}function wn(t,e){var r=e*e,n=r*r;return[t*(.8707-.131979*r+n*(n*(.003971*r-.001529*n)-.013791)),e*(1.007226+r*(.015085+n*(.028874*r-.044475-.005916*n)))]}function Tn(t,e){return[g(e)*_(t),_(e)]}function kn(t,e){var r=g(e),n=1+g(t)*r;return[r*_(t)/n,_(e)/n]}function An(t,e){return[x(k((l+e)/2)),-t]}bn.invert=function(t,e){for(var r,n=e,i=n*n,a=i*i*i,o=0;o<12&&(a=(i=(n-=r=(n*(mn+gn*i+a*(vn+yn*i))-e)/(mn+3*gn*i+a*(7*vn+9*yn*i)))*n)*i*i,!(p(r)<1e-12));++o);return[xn*t*(mn+3*gn*i+a*(7*vn+9*yn*i))/g(n),M(_(n)/xn)]},_n.invert=on(d),wn.invert=function(t,e){var r,n=e,i=25;do{var a=n*n,s=a*a;n-=r=(n*(1.007226+a*(.015085+s*(.028874*a-.044475-.005916*s)))-e)/(1.007226+a*(.045255+s*(.259866*a-.311325-.005916*11*s)))}while(p(r)>o&&--i>0);return[t/(.8707+(a=n*n)*(a*(a*a*a*(.003971-.001529*a)-.013791)-.131979)),n]},Tn.invert=on(M),kn.invert=on((function(t){return 2*d(t)})),An.invert=function(t,e){return[-e,2*d(y(t))-l]},t.geoAlbers=nn,t.geoAlbersUsa=function(){var t,e,r,n,i,a,s=nn(),l=rn().rotate([154,0]).center([-2,58.5]).parallels([55,65]),c=rn().rotate([157,0]).center([-3,19.9]).parallels([8,18]),u={point:function(t,e){a=[t,e]}};function f(t){var e=t[0],o=t[1];return a=null,r.point(e,o),a||(n.point(e,o),a)||(i.point(e,o),a)}function h(){return t=e=null,f}return f.invert=function(t){var e=s.scale(),r=s.translate(),n=(t[0]-r[0])/e,i=(t[1]-r[1])/e;return(i>=.12&&i<.234&&n>=-.425&&n<-.214?l:i>=.166&&i<.234&&n>=-.214&&n<-.115?c:s).invert(t)},f.stream=function(r){return t&&e===r?t:(n=[s.stream(e=r),l.stream(r),c.stream(r)],i=n.length,t={point:function(t,e){for(var r=-1;++r<i;)n[r].point(t,e)},sphere:function(){for(var t=-1;++t<i;)n[t].sphere()},lineStart:function(){for(var t=-1;++t<i;)n[t].lineStart()},lineEnd:function(){for(var t=-1;++t<i;)n[t].lineEnd()},polygonStart:function(){for(var t=-1;++t<i;)n[t].polygonStart()},polygonEnd:function(){for(var t=-1;++t<i;)n[t].polygonEnd()}});var n,i},f.precision=function(t){return arguments.length?(s.precision(t),l.precision(t),c.precision(t),h()):s.precision()},f.scale=function(t){return arguments.length?(s.scale(t),l.scale(.35*t),c.scale(t),f.translate(s.translate())):s.scale()},f.translate=function(t){if(!arguments.length)return s.translate();var e=s.scale(),a=+t[0],f=+t[1];return r=s.translate(t).clipExtent([[a-.455*e,f-.238*e],[a+.455*e,f+.238*e]]).stream(u),n=l.translate([a-.307*e,f+.201*e]).clipExtent([[a-.425*e+o,f+.12*e+o],[a-.214*e-o,f+.234*e-o]]).stream(u),i=c.translate([a-.205*e,f+.212*e]).clipExtent([[a-.214*e+o,f+.166*e+o],[a-.115*e-o,f+.234*e-o]]).stream(u),h()},f.fitExtent=function(t,e){return Hr(f,t,e)},f.fitSize=function(t,e){return qr(f,t,e)},f.fitWidth=function(t,e){return Gr(f,t,e)},f.fitHeight=function(t,e){return Yr(f,t,e)},f.scale(1070)},t.geoArea=function(t){return U.reset(),z(t,V),2*U},t.geoAzimuthalEqualArea=function(){return Qr(sn).scale(124.75).clipAngle(179.999)},t.geoAzimuthalEqualAreaRaw=sn,t.geoAzimuthalEquidistant=function(){return Qr(ln).scale(79.4188).clipAngle(179.999)},t.geoAzimuthalEquidistantRaw=ln,t.geoBounds=function(t){var e,r,n,i,a,o,s;if(nt=rt=-(tt=et=1/0),lt=[],z(t,St),r=lt.length){for(lt.sort(Rt),e=1,a=[n=lt[0]];e<r;++e)Ft(n,(i=lt[e])[0])||Ft(n,i[1])?(Dt(n[0],i[1])>Dt(n[0],n[1])&&(n[1]=i[1]),Dt(i[0],n[1])>Dt(n[0],n[1])&&(n[0]=i[0])):a.push(n=i);for(o=-1/0,e=0,n=a[r=a.length-1];e<=r;n=i,++e)i=a[e],(s=Dt(n[1],i[0]))>o&&(o=s,tt=i[0],rt=n[1])}return lt=ct=null,tt===1/0||et===1/0?[[NaN,NaN],[NaN,NaN]]:[[tt,et],[rt,nt]]},t.geoCentroid=function(t){ut=ft=ht=pt=dt=mt=gt=vt=yt=xt=bt=0,z(t,Bt);var e=yt,r=xt,n=bt,i=e*e+r*r+n*n;return i<1e-12&&(e=mt,r=gt,n=vt,ft<o&&(e=ht,r=pt,n=dt),(i=e*e+r*r+n*n)<1e-12)?[NaN,NaN]:[m(r,e)*f,M(n/T(i))*f]},t.geoCircle=function(){var t,e,r=Zt([0,0]),n=Zt(90),i=Zt(6),a={point:function(r,n){t.push(r=e(r,n)),r[0]*=f,r[1]*=f}};function o(){var o=r.apply(this,arguments),s=n.apply(this,arguments)*h,l=i.apply(this,arguments)*h;return t=[],e=Qt(-o[0]*h,-o[1]*h,0).invert,ne(a,s,l,1),o={type:"Polygon",coordinates:[t]},t=e=null,o}return o.center=function(t){return arguments.length?(r="function"==typeof t?t:Zt([+t[0],+t[1]]),o):r},o.radius=function(t){return arguments.length?(n="function"==typeof t?t:Zt(+t),o):n},o.precision=function(t){return arguments.length?(i="function"==typeof t?t:Zt(+t),o):i},o},t.geoClipAntimeridian=ge,t.geoClipCircle=ve,t.geoClipExtent=function(){var t,e,r,n=0,i=0,a=960,o=500;return r={stream:function(r){return t&&e===r?t:t=ye(n,i,a,o)(e=r)},extent:function(s){return arguments.length?(n=+s[0][0],i=+s[0][1],a=+s[1][0],o=+s[1][1],t=e=null,r):[[n,i],[a,o]]}}},t.geoClipRectangle=ye,t.geoConicConformal=function(){return tn(hn).scale(109.5).parallels([30,30])},t.geoConicConformalRaw=hn,t.geoConicEqualArea=rn,t.geoConicEqualAreaRaw=en,t.geoConicEquidistant=function(){return tn(dn).scale(131.154).center([0,13.9389])},t.geoConicEquidistantRaw=dn,t.geoContains=function(t,e){return(t&&Pe.hasOwnProperty(t.type)?Pe[t.type]:Oe)(t,e)},t.geoDistance=Ce,t.geoEqualEarth=function(){return Qr(bn).scale(177.158)},t.geoEqualEarthRaw=bn,t.geoEquirectangular=function(){return Qr(pn).scale(152.63)},t.geoEquirectangularRaw=pn,t.geoGnomonic=function(){return Qr(_n).scale(144.049).clipAngle(60)},t.geoGnomonicRaw=_n,t.geoGraticule=Ue,t.geoGraticule10=function(){return Ue()()},t.geoIdentity=function(){var t,e,r,n,i,a,o,s=1,l=0,c=0,u=1,p=1,d=0,m=null,v=1,y=1,x=jr({point:function(t,e){var r=T([t,e]);this.stream.point(r[0],r[1])}}),b=Ve;function w(){return v=s*u,y=s*p,a=o=null,T}function T(r){var n=r[0]*v,i=r[1]*y;if(d){var a=i*t-n*e;n=n*t+i*e,i=a}return[n+l,i+c]}return T.invert=function(r){var n=r[0]-l,i=r[1]-c;if(d){var a=i*t+n*e;n=n*t-i*e,i=a}return[n/v,i/y]},T.stream=function(t){return a&&o===t?a:a=x(b(o=t))},T.postclip=function(t){return arguments.length?(b=t,m=r=n=i=null,w()):b},T.clipExtent=function(t){return arguments.length?(b=null==t?(m=r=n=i=null,Ve):ye(m=+t[0][0],r=+t[0][1],n=+t[1][0],i=+t[1][1]),w()):null==m?null:[[m,r],[n,i]]},T.scale=function(t){return arguments.length?(s=+t,w()):s},T.translate=function(t){return arguments.length?(l=+t[0],c=+t[1],w()):[l,c]},T.angle=function(r){return arguments.length?(e=_(d=r%360*h),t=g(d),w()):d*f},T.reflectX=function(t){return arguments.length?(u=t?-1:1,w()):u<0},T.reflectY=function(t){return arguments.length?(p=t?-1:1,w()):p<0},T.fitExtent=function(t,e){return Hr(T,t,e)},T.fitSize=function(t,e){return qr(T,t,e)},T.fitWidth=function(t,e){return Gr(T,t,e)},T.fitHeight=function(t,e){return Yr(T,t,e)},T},t.geoInterpolate=function(t,e){var r=t[0]*h,n=t[1]*h,i=e[0]*h,a=e[1]*h,o=g(n),s=_(n),l=g(a),c=_(a),u=o*g(r),p=o*_(r),d=l*g(i),v=l*_(i),y=2*M(T(S(a-n)+o*l*S(i-r))),x=_(y),b=y?function(t){var e=_(t*=y)/x,r=_(y-t)/x,n=r*u+e*d,i=r*p+e*v,a=r*s+e*c;return[m(i,n)*f,m(a,T(n*n+i*i))*f]}:function(){return[r*f,n*f]};return b.distance=y,b},t.geoLength=Se,t.geoMercator=function(){return un(cn).scale(961/u)},t.geoMercatorRaw=cn,t.geoNaturalEarth1=function(){return Qr(wn).scale(175.295)},t.geoNaturalEarth1Raw=wn,t.geoOrthographic=function(){return Qr(Tn).scale(249.5).clipAngle(90+o)},t.geoOrthographicRaw=Tn,t.geoPath=function(t,e){var r,n,i=4.5;function a(t){return t&&("function"==typeof i&&n.pointRadius(+i.apply(this,arguments)),z(t,r(n))),n.result()}return a.area=function(t){return z(t,r(Ze)),Ze.result()},a.measure=function(t){return z(t,r(Dr)),Dr.result()},a.bounds=function(t){return z(t,r(ir)),ir.result()},a.centroid=function(t){return z(t,r(yr)),yr.result()},a.projection=function(e){return arguments.length?(r=null==e?(t=null,Ve):(t=e).stream,a):t},a.context=function(t){return arguments.length?(n=null==t?(e=null,new Br):new Er(e=t),"function"!=typeof i&&n.pointRadius(i),a):e},a.pointRadius=function(t){return arguments.length?(i="function"==typeof t?t:(n.pointRadius(+t),+t),a):i},a.projection(t).context(e)},t.geoProjection=Qr,t.geoProjectionMutator=$r,t.geoRotation=re,t.geoStereographic=function(){return Qr(kn).scale(250).clipAngle(142)},t.geoStereographicRaw=kn,t.geoStream=z,t.geoTransform=function(t){return{stream:jr(t)}},t.geoTransverseMercator=function(){var t=un(An),e=t.center,r=t.rotate;return t.center=function(t){return arguments.length?e([-t[1],t[0]]):[(t=e())[1],-t[0]]},t.rotate=function(t){return arguments.length?r([t[0],t[1],t.length>2?t[2]+90:90]):[(t=r())[0],t[1],t[2]-90]},r([0,0,90]).scale(159.155)},t.geoTransverseMercatorRaw=An,Object.defineProperty(t,"__esModule",{value:!0})}))},{"d3-array":107}],115:[function(t,e,r){!function(t,n){"object"==typeof r&&void 0!==e?n(r):n((t=t||self).d3=t.d3||{})}(this,(function(t){"use strict";function e(t,e){return t.parent===e.parent?1:2}function r(t,e){return t+e.x}function n(t,e){return Math.max(t,e.y)}function i(t){var e=0,r=t.children,n=r&&r.length;if(n)for(;--n>=0;)e+=r[n].value;else e=1;t.value=e}function a(t,e){var r,n,i,a,s,u=new c(t),f=+t.value&&(u.value=t.value),h=[u];for(null==e&&(e=o);r=h.pop();)if(f&&(r.value=+r.data.value),(i=e(r.data))&&(s=i.length))for(r.children=new Array(s),a=s-1;a>=0;--a)h.push(n=r.children[a]=new c(i[a])),n.parent=r,n.depth=r.depth+1;return u.eachBefore(l)}function o(t){return t.children}function s(t){t.data=t.data.data}function l(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function c(t){this.data=t,this.depth=this.height=0,this.parent=null}c.prototype=a.prototype={constructor:c,count:function(){return this.eachAfter(i)},each:function(t){var e,r,n,i,a=this,o=[a];do{for(e=o.reverse(),o=[];a=e.pop();)if(t(a),r=a.children)for(n=0,i=r.length;n<i;++n)o.push(r[n])}while(o.length);return this},eachAfter:function(t){for(var e,r,n,i=this,a=[i],o=[];i=a.pop();)if(o.push(i),e=i.children)for(r=0,n=e.length;r<n;++r)a.push(e[r]);for(;i=o.pop();)t(i);return this},eachBefore:function(t){for(var e,r,n=this,i=[n];n=i.pop();)if(t(n),e=n.children)for(r=e.length-1;r>=0;--r)i.push(e[r]);return this},sum:function(t){return this.eachAfter((function(e){for(var r=+t(e.data)||0,n=e.children,i=n&&n.length;--i>=0;)r+=n[i].value;e.value=r}))},sort:function(t){return this.eachBefore((function(e){e.children&&e.children.sort(t)}))},path:function(t){for(var e=this,r=function(t,e){if(t===e)return t;var r=t.ancestors(),n=e.ancestors(),i=null;t=r.pop(),e=n.pop();for(;t===e;)i=t,t=r.pop(),e=n.pop();return i}(e,t),n=[e];e!==r;)e=e.parent,n.push(e);for(var i=n.length;t!==r;)n.splice(i,0,t),t=t.parent;return n},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){var t=[];return this.each((function(e){t.push(e)})),t},leaves:function(){var t=[];return this.eachBefore((function(e){e.children||t.push(e)})),t},links:function(){var t=this,e=[];return t.each((function(r){r!==t&&e.push({source:r.parent,target:r})})),e},copy:function(){return a(this).eachBefore(s)}};var u=Array.prototype.slice;function f(t){for(var e,r,n=0,i=(t=function(t){for(var e,r,n=t.length;n;)r=Math.random()*n--|0,e=t[n],t[n]=t[r],t[r]=e;return t}(u.call(t))).length,a=[];n<i;)e=t[n],r&&d(r,e)?++n:(r=g(a=h(a,e)),n=0);return r}function h(t,e){var r,n;if(m(e,t))return[e];for(r=0;r<t.length;++r)if(p(e,t[r])&&m(v(t[r],e),t))return[t[r],e];for(r=0;r<t.length-1;++r)for(n=r+1;n<t.length;++n)if(p(v(t[r],t[n]),e)&&p(v(t[r],e),t[n])&&p(v(t[n],e),t[r])&&m(y(t[r],t[n],e),t))return[t[r],t[n],e];throw new Error}function p(t,e){var r=t.r-e.r,n=e.x-t.x,i=e.y-t.y;return r<0||r*r<n*n+i*i}function d(t,e){var r=t.r-e.r+1e-6,n=e.x-t.x,i=e.y-t.y;return r>0&&r*r>n*n+i*i}function m(t,e){for(var r=0;r<e.length;++r)if(!d(t,e[r]))return!1;return!0}function g(t){switch(t.length){case 1:return{x:(e=t[0]).x,y:e.y,r:e.r};case 2:return v(t[0],t[1]);case 3:return y(t[0],t[1],t[2])}var e}function v(t,e){var r=t.x,n=t.y,i=t.r,a=e.x,o=e.y,s=e.r,l=a-r,c=o-n,u=s-i,f=Math.sqrt(l*l+c*c);return{x:(r+a+l/f*u)/2,y:(n+o+c/f*u)/2,r:(f+i+s)/2}}function y(t,e,r){var n=t.x,i=t.y,a=t.r,o=e.x,s=e.y,l=e.r,c=r.x,u=r.y,f=r.r,h=n-o,p=n-c,d=i-s,m=i-u,g=l-a,v=f-a,y=n*n+i*i-a*a,x=y-o*o-s*s+l*l,b=y-c*c-u*u+f*f,_=p*d-h*m,w=(d*b-m*x)/(2*_)-n,T=(m*g-d*v)/_,k=(p*x-h*b)/(2*_)-i,A=(h*v-p*g)/_,M=T*T+A*A-1,S=2*(a+w*T+k*A),E=w*w+k*k-a*a,L=-(M?(S+Math.sqrt(S*S-4*M*E))/(2*M):E/S);return{x:n+w+T*L,y:i+k+A*L,r:L}}function x(t,e,r){var n,i,a,o,s=t.x-e.x,l=t.y-e.y,c=s*s+l*l;c?(i=e.r+r.r,i*=i,o=t.r+r.r,i>(o*=o)?(n=(c+o-i)/(2*c),a=Math.sqrt(Math.max(0,o/c-n*n)),r.x=t.x-n*s-a*l,r.y=t.y-n*l+a*s):(n=(c+i-o)/(2*c),a=Math.sqrt(Math.max(0,i/c-n*n)),r.x=e.x+n*s-a*l,r.y=e.y+n*l+a*s)):(r.x=e.x+r.r,r.y=e.y)}function b(t,e){var r=t.r+e.r-1e-6,n=e.x-t.x,i=e.y-t.y;return r>0&&r*r>n*n+i*i}function _(t){var e=t._,r=t.next._,n=e.r+r.r,i=(e.x*r.r+r.x*e.r)/n,a=(e.y*r.r+r.y*e.r)/n;return i*i+a*a}function w(t){this._=t,this.next=null,this.previous=null}function T(t){if(!(i=t.length))return 0;var e,r,n,i,a,o,s,l,c,u,h;if((e=t[0]).x=0,e.y=0,!(i>1))return e.r;if(r=t[1],e.x=-r.r,r.x=e.r,r.y=0,!(i>2))return e.r+r.r;x(r,e,n=t[2]),e=new w(e),r=new w(r),n=new w(n),e.next=n.previous=r,r.next=e.previous=n,n.next=r.previous=e;t:for(s=3;s<i;++s){x(e._,r._,n=t[s]),n=new w(n),l=r.next,c=e.previous,u=r._.r,h=e._.r;do{if(u<=h){if(b(l._,n._)){r=l,e.next=r,r.previous=e,--s;continue t}u+=l._.r,l=l.next}else{if(b(c._,n._)){(e=c).next=r,r.previous=e,--s;continue t}h+=c._.r,c=c.previous}}while(l!==c.next);for(n.previous=e,n.next=r,e.next=r.previous=r=n,a=_(e);(n=n.next)!==r;)(o=_(n))<a&&(e=n,a=o);r=e.next}for(e=[r._],n=r;(n=n.next)!==r;)e.push(n._);for(n=f(e),s=0;s<i;++s)(e=t[s]).x-=n.x,e.y-=n.y;return n.r}function k(t){return null==t?null:A(t)}function A(t){if("function"!=typeof t)throw new Error;return t}function M(){return 0}function S(t){return function(){return t}}function E(t){return Math.sqrt(t.value)}function L(t){return function(e){e.children||(e.r=Math.max(0,+t(e)||0))}}function C(t,e){return function(r){if(n=r.children){var n,i,a,o=n.length,s=t(r)*e||0;if(s)for(i=0;i<o;++i)n[i].r+=s;if(a=T(n),s)for(i=0;i<o;++i)n[i].r-=s;r.r=a+s}}}function P(t){return function(e){var r=e.parent;e.r*=t,r&&(e.x=r.x+t*e.x,e.y=r.y+t*e.y)}}function I(t){t.x0=Math.round(t.x0),t.y0=Math.round(t.y0),t.x1=Math.round(t.x1),t.y1=Math.round(t.y1)}function O(t,e,r,n,i){for(var a,o=t.children,s=-1,l=o.length,c=t.value&&(n-e)/t.value;++s<l;)(a=o[s]).y0=r,a.y1=i,a.x0=e,a.x1=e+=a.value*c}var z={depth:-1},D={};function R(t){return t.id}function F(t){return t.parentId}function B(t,e){return t.parent===e.parent?1:2}function N(t){var e=t.children;return e?e[0]:t.t}function j(t){var e=t.children;return e?e[e.length-1]:t.t}function U(t,e,r){var n=r/(e.i-t.i);e.c-=n,e.s+=r,t.c+=n,e.z+=r,e.m+=r}function V(t,e,r){return t.a.parent===e.parent?t.a:r}function H(t,e){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=e}function q(t,e,r,n,i){for(var a,o=t.children,s=-1,l=o.length,c=t.value&&(i-r)/t.value;++s<l;)(a=o[s]).x0=e,a.x1=n,a.y0=r,a.y1=r+=a.value*c}H.prototype=Object.create(c.prototype);var G=(1+Math.sqrt(5))/2;function Y(t,e,r,n,i,a){for(var o,s,l,c,u,f,h,p,d,m,g,v=[],y=e.children,x=0,b=0,_=y.length,w=e.value;x<_;){l=i-r,c=a-n;do{u=y[b++].value}while(!u&&b<_);for(f=h=u,g=u*u*(m=Math.max(c/l,l/c)/(w*t)),d=Math.max(h/g,g/f);b<_;++b){if(u+=s=y[b].value,s<f&&(f=s),s>h&&(h=s),g=u*u*m,(p=Math.max(h/g,g/f))>d){u-=s;break}d=p}v.push(o={value:u,dice:l<c,children:y.slice(x,b)}),o.dice?O(o,r,n,i,w?n+=c*u/w:a):q(o,r,n,w?r+=l*u/w:i,a),w-=u,x=b}return v}var W=function t(e){function r(t,r,n,i,a){Y(e,t,r,n,i,a)}return r.ratio=function(e){return t((e=+e)>1?e:1)},r}(G);var X=function t(e){function r(t,r,n,i,a){if((o=t._squarify)&&o.ratio===e)for(var o,s,l,c,u,f=-1,h=o.length,p=t.value;++f<h;){for(l=(s=o[f]).children,c=s.value=0,u=l.length;c<u;++c)s.value+=l[c].value;s.dice?O(s,r,n,i,n+=(a-n)*s.value/p):q(s,r,n,r+=(i-r)*s.value/p,a),p-=s.value}else t._squarify=o=Y(e,t,r,n,i,a),o.ratio=e}return r.ratio=function(e){return t((e=+e)>1?e:1)},r}(G);t.cluster=function(){var t=e,i=1,a=1,o=!1;function s(e){var s,l=0;e.eachAfter((function(e){var i=e.children;i?(e.x=function(t){return t.reduce(r,0)/t.length}(i),e.y=function(t){return 1+t.reduce(n,0)}(i)):(e.x=s?l+=t(e,s):0,e.y=0,s=e)}));var c=function(t){for(var e;e=t.children;)t=e[0];return t}(e),u=function(t){for(var e;e=t.children;)t=e[e.length-1];return t}(e),f=c.x-t(c,u)/2,h=u.x+t(u,c)/2;return e.eachAfter(o?function(t){t.x=(t.x-e.x)*i,t.y=(e.y-t.y)*a}:function(t){t.x=(t.x-f)/(h-f)*i,t.y=(1-(e.y?t.y/e.y:1))*a})}return s.separation=function(e){return arguments.length?(t=e,s):t},s.size=function(t){return arguments.length?(o=!1,i=+t[0],a=+t[1],s):o?null:[i,a]},s.nodeSize=function(t){return arguments.length?(o=!0,i=+t[0],a=+t[1],s):o?[i,a]:null},s},t.hierarchy=a,t.pack=function(){var t=null,e=1,r=1,n=M;function i(i){return i.x=e/2,i.y=r/2,t?i.eachBefore(L(t)).eachAfter(C(n,.5)).eachBefore(P(1)):i.eachBefore(L(E)).eachAfter(C(M,1)).eachAfter(C(n,i.r/Math.min(e,r))).eachBefore(P(Math.min(e,r)/(2*i.r))),i}return i.radius=function(e){return arguments.length?(t=k(e),i):t},i.size=function(t){return arguments.length?(e=+t[0],r=+t[1],i):[e,r]},i.padding=function(t){return arguments.length?(n="function"==typeof t?t:S(+t),i):n},i},t.packEnclose=f,t.packSiblings=function(t){return T(t),t},t.partition=function(){var t=1,e=1,r=0,n=!1;function i(i){var a=i.height+1;return i.x0=i.y0=r,i.x1=t,i.y1=e/a,i.eachBefore(function(t,e){return function(n){n.children&&O(n,n.x0,t*(n.depth+1)/e,n.x1,t*(n.depth+2)/e);var i=n.x0,a=n.y0,o=n.x1-r,s=n.y1-r;o<i&&(i=o=(i+o)/2),s<a&&(a=s=(a+s)/2),n.x0=i,n.y0=a,n.x1=o,n.y1=s}}(e,a)),n&&i.eachBefore(I),i}return i.round=function(t){return arguments.length?(n=!!t,i):n},i.size=function(r){return arguments.length?(t=+r[0],e=+r[1],i):[t,e]},i.padding=function(t){return arguments.length?(r=+t,i):r},i},t.stratify=function(){var t=R,e=F;function r(r){var n,i,a,o,s,u,f,h=r.length,p=new Array(h),d={};for(i=0;i<h;++i)n=r[i],s=p[i]=new c(n),null!=(u=t(n,i,r))&&(u+="")&&(d[f="$"+(s.id=u)]=f in d?D:s);for(i=0;i<h;++i)if(s=p[i],null!=(u=e(r[i],i,r))&&(u+="")){if(!(o=d["$"+u]))throw new Error("missing: "+u);if(o===D)throw new Error("ambiguous: "+u);o.children?o.children.push(s):o.children=[s],s.parent=o}else{if(a)throw new Error("multiple roots");a=s}if(!a)throw new Error("no root");if(a.parent=z,a.eachBefore((function(t){t.depth=t.parent.depth+1,--h})).eachBefore(l),a.parent=null,h>0)throw new Error("cycle");return a}return r.id=function(e){return arguments.length?(t=A(e),r):t},r.parentId=function(t){return arguments.length?(e=A(t),r):e},r},t.tree=function(){var t=B,e=1,r=1,n=null;function i(i){var l=function(t){for(var e,r,n,i,a,o=new H(t,0),s=[o];e=s.pop();)if(n=e._.children)for(e.children=new Array(a=n.length),i=a-1;i>=0;--i)s.push(r=e.children[i]=new H(n[i],i)),r.parent=e;return(o.parent=new H(null,0)).children=[o],o}(i);if(l.eachAfter(a),l.parent.m=-l.z,l.eachBefore(o),n)i.eachBefore(s);else{var c=i,u=i,f=i;i.eachBefore((function(t){t.x<c.x&&(c=t),t.x>u.x&&(u=t),t.depth>f.depth&&(f=t)}));var h=c===u?1:t(c,u)/2,p=h-c.x,d=e/(u.x+h+p),m=r/(f.depth||1);i.eachBefore((function(t){t.x=(t.x+p)*d,t.y=t.depth*m}))}return i}function a(e){var r=e.children,n=e.parent.children,i=e.i?n[e.i-1]:null;if(r){!function(t){for(var e,r=0,n=0,i=t.children,a=i.length;--a>=0;)(e=i[a]).z+=r,e.m+=r,r+=e.s+(n+=e.c)}(e);var a=(r[0].z+r[r.length-1].z)/2;i?(e.z=i.z+t(e._,i._),e.m=e.z-a):e.z=a}else i&&(e.z=i.z+t(e._,i._));e.parent.A=function(e,r,n){if(r){for(var i,a=e,o=e,s=r,l=a.parent.children[0],c=a.m,u=o.m,f=s.m,h=l.m;s=j(s),a=N(a),s&&a;)l=N(l),(o=j(o)).a=e,(i=s.z+f-a.z-c+t(s._,a._))>0&&(U(V(s,e,n),e,i),c+=i,u+=i),f+=s.m,c+=a.m,h+=l.m,u+=o.m;s&&!j(o)&&(o.t=s,o.m+=f-u),a&&!N(l)&&(l.t=a,l.m+=c-h,n=e)}return n}(e,i,e.parent.A||n[0])}function o(t){t._.x=t.z+t.parent.m,t.m+=t.parent.m}function s(t){t.x*=e,t.y=t.depth*r}return i.separation=function(e){return arguments.length?(t=e,i):t},i.size=function(t){return arguments.length?(n=!1,e=+t[0],r=+t[1],i):n?null:[e,r]},i.nodeSize=function(t){return arguments.length?(n=!0,e=+t[0],r=+t[1],i):n?[e,r]:null},i},t.treemap=function(){var t=W,e=!1,r=1,n=1,i=[0],a=M,o=M,s=M,l=M,c=M;function u(t){return t.x0=t.y0=0,t.x1=r,t.y1=n,t.eachBefore(f),i=[0],e&&t.eachBefore(I),t}function f(e){var r=i[e.depth],n=e.x0+r,u=e.y0+r,f=e.x1-r,h=e.y1-r;f<n&&(n=f=(n+f)/2),h<u&&(u=h=(u+h)/2),e.x0=n,e.y0=u,e.x1=f,e.y1=h,e.children&&(r=i[e.depth+1]=a(e)/2,n+=c(e)-r,u+=o(e)-r,(f-=s(e)-r)<n&&(n=f=(n+f)/2),(h-=l(e)-r)<u&&(u=h=(u+h)/2),t(e,n,u,f,h))}return u.round=function(t){return arguments.length?(e=!!t,u):e},u.size=function(t){return arguments.length?(r=+t[0],n=+t[1],u):[r,n]},u.tile=function(e){return arguments.length?(t=A(e),u):t},u.padding=function(t){return arguments.length?u.paddingInner(t).paddingOuter(t):u.paddingInner()},u.paddingInner=function(t){return arguments.length?(a="function"==typeof t?t:S(+t),u):a},u.paddingOuter=function(t){return arguments.length?u.paddingTop(t).paddingRight(t).paddingBottom(t).paddingLeft(t):u.paddingTop()},u.paddingTop=function(t){return arguments.length?(o="function"==typeof t?t:S(+t),u):o},u.paddingRight=function(t){return arguments.length?(s="function"==typeof t?t:S(+t),u):s},u.paddingBottom=function(t){return arguments.length?(l="function"==typeof t?t:S(+t),u):l},u.paddingLeft=function(t){return arguments.length?(c="function"==typeof t?t:S(+t),u):c},u},t.treemapBinary=function(t,e,r,n,i){var a,o,s=t.children,l=s.length,c=new Array(l+1);for(c[0]=o=a=0;a<l;++a)c[a+1]=o+=s[a].value;!function t(e,r,n,i,a,o,l){if(e>=r-1){var u=s[e];return u.x0=i,u.y0=a,u.x1=o,void(u.y1=l)}var f=c[e],h=n/2+f,p=e+1,d=r-1;for(;p<d;){var m=p+d>>>1;c[m]<h?p=m+1:d=m}h-c[p-1]<c[p]-h&&e+1<p&&--p;var g=c[p]-f,v=n-g;if(o-i>l-a){var y=(i*v+o*g)/n;t(e,p,g,i,a,y,l),t(p,r,v,y,a,o,l)}else{var x=(a*v+l*g)/n;t(e,p,g,i,a,o,x),t(p,r,v,i,x,o,l)}}(0,l,t.value,e,r,n,i)},t.treemapDice=O,t.treemapResquarify=X,t.treemapSlice=q,t.treemapSliceDice=function(t,e,r,n,i){(1&t.depth?q:O)(t,e,r,n,i)},t.treemapSquarify=W,Object.defineProperty(t,"__esModule",{value:!0})}))},{}],116:[function(t,e,r){!function(n,i){"object"==typeof r&&void 0!==e?i(r,t("d3-color")):i((n=n||self).d3=n.d3||{},n.d3)}(this,(function(t,e){"use strict";function r(t,e,r,n,i){var a=t*t,o=a*t;return((1-3*t+3*a-o)*e+(4-6*a+3*o)*r+(1+3*t+3*a-3*o)*n+o*i)/6}function n(t){var e=t.length-1;return function(n){var i=n<=0?n=0:n>=1?(n=1,e-1):Math.floor(n*e),a=t[i],o=t[i+1],s=i>0?t[i-1]:2*a-o,l=i<e-1?t[i+2]:2*o-a;return r((n-i/e)*e,s,a,o,l)}}function i(t){var e=t.length;return function(n){var i=Math.floor(((n%=1)<0?++n:n)*e),a=t[(i+e-1)%e],o=t[i%e],s=t[(i+1)%e],l=t[(i+2)%e];return r((n-i/e)*e,a,o,s,l)}}function a(t){return function(){return t}}function o(t,e){return function(r){return t+r*e}}function s(t,e){var r=e-t;return r?o(t,r>180||r<-180?r-360*Math.round(r/360):r):a(isNaN(t)?e:t)}function l(t){return 1==(t=+t)?c:function(e,r){return r-e?function(t,e,r){return t=Math.pow(t,r),e=Math.pow(e,r)-t,r=1/r,function(n){return Math.pow(t+n*e,r)}}(e,r,t):a(isNaN(e)?r:e)}}function c(t,e){var r=e-t;return r?o(t,r):a(isNaN(t)?e:t)}var u=function t(r){var n=l(r);function i(t,r){var i=n((t=e.rgb(t)).r,(r=e.rgb(r)).r),a=n(t.g,r.g),o=n(t.b,r.b),s=c(t.opacity,r.opacity);return function(e){return t.r=i(e),t.g=a(e),t.b=o(e),t.opacity=s(e),t+""}}return i.gamma=t,i}(1);function f(t){return function(r){var n,i,a=r.length,o=new Array(a),s=new Array(a),l=new Array(a);for(n=0;n<a;++n)i=e.rgb(r[n]),o[n]=i.r||0,s[n]=i.g||0,l[n]=i.b||0;return o=t(o),s=t(s),l=t(l),i.opacity=1,function(t){return i.r=o(t),i.g=s(t),i.b=l(t),i+""}}}var h=f(n),p=f(i);function d(t,e){e||(e=[]);var r,n=t?Math.min(e.length,t.length):0,i=e.slice();return function(a){for(r=0;r<n;++r)i[r]=t[r]*(1-a)+e[r]*a;return i}}function m(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function g(t,e){var r,n=e?e.length:0,i=t?Math.min(n,t.length):0,a=new Array(i),o=new Array(n);for(r=0;r<i;++r)a[r]=T(t[r],e[r]);for(;r<n;++r)o[r]=e[r];return function(t){for(r=0;r<i;++r)o[r]=a[r](t);return o}}function v(t,e){var r=new Date;return t=+t,e=+e,function(n){return r.setTime(t*(1-n)+e*n),r}}function y(t,e){return t=+t,e=+e,function(r){return t*(1-r)+e*r}}function x(t,e){var r,n={},i={};for(r in null!==t&&"object"==typeof t||(t={}),null!==e&&"object"==typeof e||(e={}),e)r in t?n[r]=T(t[r],e[r]):i[r]=e[r];return function(t){for(r in n)i[r]=n[r](t);return i}}var b=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,_=new RegExp(b.source,"g");function w(t,e){var r,n,i,a=b.lastIndex=_.lastIndex=0,o=-1,s=[],l=[];for(t+="",e+="";(r=b.exec(t))&&(n=_.exec(e));)(i=n.index)>a&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(r=r[0])===(n=n[0])?s[o]?s[o]+=n:s[++o]=n:(s[++o]=null,l.push({i:o,x:y(r,n)})),a=_.lastIndex;return a<e.length&&(i=e.slice(a),s[o]?s[o]+=i:s[++o]=i),s.length<2?l[0]?function(t){return function(e){return t(e)+""}}(l[0].x):function(t){return function(){return t}}(e):(e=l.length,function(t){for(var r,n=0;n<e;++n)s[(r=l[n]).i]=r.x(t);return s.join("")})}function T(t,r){var n,i=typeof r;return null==r||"boolean"===i?a(r):("number"===i?y:"string"===i?(n=e.color(r))?(r=n,u):w:r instanceof e.color?u:r instanceof Date?v:m(r)?d:Array.isArray(r)?g:"function"!=typeof r.valueOf&&"function"!=typeof r.toString||isNaN(r)?x:y)(t,r)}var k,A,M,S,E=180/Math.PI,L={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function C(t,e,r,n,i,a){var o,s,l;return(o=Math.sqrt(t*t+e*e))&&(t/=o,e/=o),(l=t*r+e*n)&&(r-=t*l,n-=e*l),(s=Math.sqrt(r*r+n*n))&&(r/=s,n/=s,l/=s),t*n<e*r&&(t=-t,e=-e,l=-l,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(e,t)*E,skewX:Math.atan(l)*E,scaleX:o,scaleY:s}}function P(t,e,r,n){function i(t){return t.length?t.pop()+" ":""}return function(a,o){var s=[],l=[];return a=t(a),o=t(o),function(t,n,i,a,o,s){if(t!==i||n!==a){var l=o.push("translate(",null,e,null,r);s.push({i:l-4,x:y(t,i)},{i:l-2,x:y(n,a)})}else(i||a)&&o.push("translate("+i+e+a+r)}(a.translateX,a.translateY,o.translateX,o.translateY,s,l),function(t,e,r,a){t!==e?(t-e>180?e+=360:e-t>180&&(t+=360),a.push({i:r.push(i(r)+"rotate(",null,n)-2,x:y(t,e)})):e&&r.push(i(r)+"rotate("+e+n)}(a.rotate,o.rotate,s,l),function(t,e,r,a){t!==e?a.push({i:r.push(i(r)+"skewX(",null,n)-2,x:y(t,e)}):e&&r.push(i(r)+"skewX("+e+n)}(a.skewX,o.skewX,s,l),function(t,e,r,n,a,o){if(t!==r||e!==n){var s=a.push(i(a)+"scale(",null,",",null,")");o.push({i:s-4,x:y(t,r)},{i:s-2,x:y(e,n)})}else 1===r&&1===n||a.push(i(a)+"scale("+r+","+n+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,l),a=o=null,function(t){for(var e,r=-1,n=l.length;++r<n;)s[(e=l[r]).i]=e.x(t);return s.join("")}}}var I=P((function(t){return"none"===t?L:(k||(k=document.createElement("DIV"),A=document.documentElement,M=document.defaultView),k.style.transform=t,t=M.getComputedStyle(A.appendChild(k),null).getPropertyValue("transform"),A.removeChild(k),C(+(t=t.slice(7,-1).split(","))[0],+t[1],+t[2],+t[3],+t[4],+t[5]))}),"px, ","px)","deg)"),O=P((function(t){return null==t?L:(S||(S=document.createElementNS("http://www.w3.org/2000/svg","g")),S.setAttribute("transform",t),(t=S.transform.baseVal.consolidate())?C((t=t.matrix).a,t.b,t.c,t.d,t.e,t.f):L)}),", ",")",")"),z=Math.SQRT2;function D(t){return((t=Math.exp(t))+1/t)/2}function R(t){return function(r,n){var i=t((r=e.hsl(r)).h,(n=e.hsl(n)).h),a=c(r.s,n.s),o=c(r.l,n.l),s=c(r.opacity,n.opacity);return function(t){return r.h=i(t),r.s=a(t),r.l=o(t),r.opacity=s(t),r+""}}}var F=R(s),B=R(c);function N(t){return function(r,n){var i=t((r=e.hcl(r)).h,(n=e.hcl(n)).h),a=c(r.c,n.c),o=c(r.l,n.l),s=c(r.opacity,n.opacity);return function(t){return r.h=i(t),r.c=a(t),r.l=o(t),r.opacity=s(t),r+""}}}var j=N(s),U=N(c);function V(t){return function r(n){function i(r,i){var a=t((r=e.cubehelix(r)).h,(i=e.cubehelix(i)).h),o=c(r.s,i.s),s=c(r.l,i.l),l=c(r.opacity,i.opacity);return function(t){return r.h=a(t),r.s=o(t),r.l=s(Math.pow(t,n)),r.opacity=l(t),r+""}}return n=+n,i.gamma=r,i}(1)}var H=V(s),q=V(c);t.interpolate=T,t.interpolateArray=function(t,e){return(m(e)?d:g)(t,e)},t.interpolateBasis=n,t.interpolateBasisClosed=i,t.interpolateCubehelix=H,t.interpolateCubehelixLong=q,t.interpolateDate=v,t.interpolateDiscrete=function(t){var e=t.length;return function(r){return t[Math.max(0,Math.min(e-1,Math.floor(r*e)))]}},t.interpolateHcl=j,t.interpolateHclLong=U,t.interpolateHsl=F,t.interpolateHslLong=B,t.interpolateHue=function(t,e){var r=s(+t,+e);return function(t){var e=r(t);return e-360*Math.floor(e/360)}},t.interpolateLab=function(t,r){var n=c((t=e.lab(t)).l,(r=e.lab(r)).l),i=c(t.a,r.a),a=c(t.b,r.b),o=c(t.opacity,r.opacity);return function(e){return t.l=n(e),t.a=i(e),t.b=a(e),t.opacity=o(e),t+""}},t.interpolateNumber=y,t.interpolateNumberArray=d,t.interpolateObject=x,t.interpolateRgb=u,t.interpolateRgbBasis=h,t.interpolateRgbBasisClosed=p,t.interpolateRound=function(t,e){return t=+t,e=+e,function(r){return Math.round(t*(1-r)+e*r)}},t.interpolateString=w,t.interpolateTransformCss=I,t.interpolateTransformSvg=O,t.interpolateZoom=function(t,e){var r,n,i=t[0],a=t[1],o=t[2],s=e[0],l=e[1],c=e[2],u=s-i,f=l-a,h=u*u+f*f;if(h<1e-12)n=Math.log(c/o)/z,r=function(t){return[i+t*u,a+t*f,o*Math.exp(z*t*n)]};else{var p=Math.sqrt(h),d=(c*c-o*o+4*h)/(2*o*2*p),m=(c*c-o*o-4*h)/(2*c*2*p),g=Math.log(Math.sqrt(d*d+1)-d),v=Math.log(Math.sqrt(m*m+1)-m);n=(v-g)/z,r=function(t){var e,r=t*n,s=D(g),l=o/(2*p)*(s*(e=z*r+g,((e=Math.exp(2*e))-1)/(e+1))-function(t){return((t=Math.exp(t))-1/t)/2}(g));return[i+l*u,a+l*f,o*s/D(z*r+g)]}}return r.duration=1e3*n,r},t.piecewise=function(t,e){for(var r=0,n=e.length-1,i=e[0],a=new Array(n<0?0:n);r<n;)a[r]=t(i,i=e[++r]);return function(t){var e=Math.max(0,Math.min(n-1,Math.floor(t*=n)));return a[e](t-e)}},t.quantize=function(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t(n/(e-1));return r},Object.defineProperty(t,"__esModule",{value:!0})}))},{"d3-color":109}],117:[function(t,e,r){!function(t,n){"object"==typeof r&&void 0!==e?n(r):n((t=t||self).d3=t.d3||{})}(this,(function(t){"use strict";var e=Math.PI,r=2*e,n=r-1e-6;function i(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function a(){return new i}i.prototype=a.prototype={constructor:i,moveTo:function(t,e){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)},closePath:function(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")},lineTo:function(t,e){this._+="L"+(this._x1=+t)+","+(this._y1=+e)},quadraticCurveTo:function(t,e,r,n){this._+="Q"+ +t+","+ +e+","+(this._x1=+r)+","+(this._y1=+n)},bezierCurveTo:function(t,e,r,n,i,a){this._+="C"+ +t+","+ +e+","+ +r+","+ +n+","+(this._x1=+i)+","+(this._y1=+a)},arcTo:function(t,r,n,i,a){t=+t,r=+r,n=+n,i=+i,a=+a;var o=this._x1,s=this._y1,l=n-t,c=i-r,u=o-t,f=s-r,h=u*u+f*f;if(a<0)throw new Error("negative radius: "+a);if(null===this._x1)this._+="M"+(this._x1=t)+","+(this._y1=r);else if(h>1e-6)if(Math.abs(f*l-c*u)>1e-6&&a){var p=n-o,d=i-s,m=l*l+c*c,g=p*p+d*d,v=Math.sqrt(m),y=Math.sqrt(h),x=a*Math.tan((e-Math.acos((m+h-g)/(2*v*y)))/2),b=x/y,_=x/v;Math.abs(b-1)>1e-6&&(this._+="L"+(t+b*u)+","+(r+b*f)),this._+="A"+a+","+a+",0,0,"+ +(f*p>u*d)+","+(this._x1=t+_*l)+","+(this._y1=r+_*c)}else this._+="L"+(this._x1=t)+","+(this._y1=r);else;},arc:function(t,i,a,o,s,l){t=+t,i=+i,l=!!l;var c=(a=+a)*Math.cos(o),u=a*Math.sin(o),f=t+c,h=i+u,p=1^l,d=l?o-s:s-o;if(a<0)throw new Error("negative radius: "+a);null===this._x1?this._+="M"+f+","+h:(Math.abs(this._x1-f)>1e-6||Math.abs(this._y1-h)>1e-6)&&(this._+="L"+f+","+h),a&&(d<0&&(d=d%r+r),d>n?this._+="A"+a+","+a+",0,1,"+p+","+(t-c)+","+(i-u)+"A"+a+","+a+",0,1,"+p+","+(this._x1=f)+","+(this._y1=h):d>1e-6&&(this._+="A"+a+","+a+",0,"+ +(d>=e)+","+p+","+(this._x1=t+a*Math.cos(s))+","+(this._y1=i+a*Math.sin(s))))},rect:function(t,e,r,n){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)+"h"+ +r+"v"+ +n+"h"+-r+"Z"},toString:function(){return this._}},t.path=a,Object.defineProperty(t,"__esModule",{value:!0})}))},{}],118:[function(t,e,r){!function(t,n){"object"==typeof r&&void 0!==e?n(r):n((t=t||self).d3=t.d3||{})}(this,(function(t){"use strict";function e(t,e,r,n){if(isNaN(e)||isNaN(r))return t;var i,a,o,s,l,c,u,f,h,p=t._root,d={data:n},m=t._x0,g=t._y0,v=t._x1,y=t._y1;if(!p)return t._root=d,t;for(;p.length;)if((c=e>=(a=(m+v)/2))?m=a:v=a,(u=r>=(o=(g+y)/2))?g=o:y=o,i=p,!(p=p[f=u<<1|c]))return i[f]=d,t;if(s=+t._x.call(null,p.data),l=+t._y.call(null,p.data),e===s&&r===l)return d.next=p,i?i[f]=d:t._root=d,t;do{i=i?i[f]=new Array(4):t._root=new Array(4),(c=e>=(a=(m+v)/2))?m=a:v=a,(u=r>=(o=(g+y)/2))?g=o:y=o}while((f=u<<1|c)==(h=(l>=o)<<1|s>=a));return i[h]=p,i[f]=d,t}function r(t,e,r,n,i){this.node=t,this.x0=e,this.y0=r,this.x1=n,this.y1=i}function n(t){return t[0]}function i(t){return t[1]}function a(t,e,r){var a=new o(null==e?n:e,null==r?i:r,NaN,NaN,NaN,NaN);return null==t?a:a.addAll(t)}function o(t,e,r,n,i,a){this._x=t,this._y=e,this._x0=r,this._y0=n,this._x1=i,this._y1=a,this._root=void 0}function s(t){for(var e={data:t.data},r=e;t=t.next;)r=r.next={data:t.data};return e}var l=a.prototype=o.prototype;l.copy=function(){var t,e,r=new o(this._x,this._y,this._x0,this._y0,this._x1,this._y1),n=this._root;if(!n)return r;if(!n.length)return r._root=s(n),r;for(t=[{source:n,target:r._root=new Array(4)}];n=t.pop();)for(var i=0;i<4;++i)(e=n.source[i])&&(e.length?t.push({source:e,target:n.target[i]=new Array(4)}):n.target[i]=s(e));return r},l.add=function(t){var r=+this._x.call(null,t),n=+this._y.call(null,t);return e(this.cover(r,n),r,n,t)},l.addAll=function(t){var r,n,i,a,o=t.length,s=new Array(o),l=new Array(o),c=1/0,u=1/0,f=-1/0,h=-1/0;for(n=0;n<o;++n)isNaN(i=+this._x.call(null,r=t[n]))||isNaN(a=+this._y.call(null,r))||(s[n]=i,l[n]=a,i<c&&(c=i),i>f&&(f=i),a<u&&(u=a),a>h&&(h=a));if(c>f||u>h)return this;for(this.cover(c,u).cover(f,h),n=0;n<o;++n)e(this,s[n],l[n],t[n]);return this},l.cover=function(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var r=this._x0,n=this._y0,i=this._x1,a=this._y1;if(isNaN(r))i=(r=Math.floor(t))+1,a=(n=Math.floor(e))+1;else{for(var o,s,l=i-r,c=this._root;r>t||t>=i||n>e||e>=a;)switch(s=(e<n)<<1|t<r,(o=new Array(4))[s]=c,c=o,l*=2,s){case 0:i=r+l,a=n+l;break;case 1:r=i-l,a=n+l;break;case 2:i=r+l,n=a-l;break;case 3:r=i-l,n=a-l}this._root&&this._root.length&&(this._root=c)}return this._x0=r,this._y0=n,this._x1=i,this._y1=a,this},l.data=function(){var t=[];return this.visit((function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)})),t},l.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},l.find=function(t,e,n){var i,a,o,s,l,c,u,f=this._x0,h=this._y0,p=this._x1,d=this._y1,m=[],g=this._root;for(g&&m.push(new r(g,f,h,p,d)),null==n?n=1/0:(f=t-n,h=e-n,p=t+n,d=e+n,n*=n);c=m.pop();)if(!(!(g=c.node)||(a=c.x0)>p||(o=c.y0)>d||(s=c.x1)<f||(l=c.y1)<h))if(g.length){var v=(a+s)/2,y=(o+l)/2;m.push(new r(g[3],v,y,s,l),new r(g[2],a,y,v,l),new r(g[1],v,o,s,y),new r(g[0],a,o,v,y)),(u=(e>=y)<<1|t>=v)&&(c=m[m.length-1],m[m.length-1]=m[m.length-1-u],m[m.length-1-u]=c)}else{var x=t-+this._x.call(null,g.data),b=e-+this._y.call(null,g.data),_=x*x+b*b;if(_<n){var w=Math.sqrt(n=_);f=t-w,h=e-w,p=t+w,d=e+w,i=g.data}}return i},l.remove=function(t){if(isNaN(a=+this._x.call(null,t))||isNaN(o=+this._y.call(null,t)))return this;var e,r,n,i,a,o,s,l,c,u,f,h,p=this._root,d=this._x0,m=this._y0,g=this._x1,v=this._y1;if(!p)return this;if(p.length)for(;;){if((c=a>=(s=(d+g)/2))?d=s:g=s,(u=o>=(l=(m+v)/2))?m=l:v=l,e=p,!(p=p[f=u<<1|c]))return this;if(!p.length)break;(e[f+1&3]||e[f+2&3]||e[f+3&3])&&(r=e,h=f)}for(;p.data!==t;)if(n=p,!(p=p.next))return this;return(i=p.next)&&delete p.next,n?(i?n.next=i:delete n.next,this):e?(i?e[f]=i:delete e[f],(p=e[0]||e[1]||e[2]||e[3])&&p===(e[3]||e[2]||e[1]||e[0])&&!p.length&&(r?r[h]=p:this._root=p),this):(this._root=i,this)},l.removeAll=function(t){for(var e=0,r=t.length;e<r;++e)this.remove(t[e]);return this},l.root=function(){return this._root},l.size=function(){var t=0;return this.visit((function(e){if(!e.length)do{++t}while(e=e.next)})),t},l.visit=function(t){var e,n,i,a,o,s,l=[],c=this._root;for(c&&l.push(new r(c,this._x0,this._y0,this._x1,this._y1));e=l.pop();)if(!t(c=e.node,i=e.x0,a=e.y0,o=e.x1,s=e.y1)&&c.length){var u=(i+o)/2,f=(a+s)/2;(n=c[3])&&l.push(new r(n,u,f,o,s)),(n=c[2])&&l.push(new r(n,i,f,u,s)),(n=c[1])&&l.push(new r(n,u,a,o,f)),(n=c[0])&&l.push(new r(n,i,a,u,f))}return this},l.visitAfter=function(t){var e,n=[],i=[];for(this._root&&n.push(new r(this._root,this._x0,this._y0,this._x1,this._y1));e=n.pop();){var a=e.node;if(a.length){var o,s=e.x0,l=e.y0,c=e.x1,u=e.y1,f=(s+c)/2,h=(l+u)/2;(o=a[0])&&n.push(new r(o,s,l,f,h)),(o=a[1])&&n.push(new r(o,f,l,c,h)),(o=a[2])&&n.push(new r(o,s,h,f,u)),(o=a[3])&&n.push(new r(o,f,h,c,u))}i.push(e)}for(;e=i.pop();)t(e.node,e.x0,e.y0,e.x1,e.y1);return this},l.x=function(t){return arguments.length?(this._x=t,this):this._x},l.y=function(t){return arguments.length?(this._y=t,this):this._y},t.quadtree=a,Object.defineProperty(t,"__esModule",{value:!0})}))},{}],119:[function(t,e,r){!function(n,i){"object"==typeof r&&void 0!==e?i(r,t("d3-path")):i((n=n||self).d3=n.d3||{},n.d3)}(this,(function(t,e){"use strict";function r(t){return function(){return t}}var n=Math.abs,i=Math.atan2,a=Math.cos,o=Math.max,s=Math.min,l=Math.sin,c=Math.sqrt,u=Math.PI,f=u/2,h=2*u;function p(t){return t>1?0:t<-1?u:Math.acos(t)}function d(t){return t>=1?f:t<=-1?-f:Math.asin(t)}function m(t){return t.innerRadius}function g(t){return t.outerRadius}function v(t){return t.startAngle}function y(t){return t.endAngle}function x(t){return t&&t.padAngle}function b(t,e,r,n,i,a,o,s){var l=r-t,c=n-e,u=o-i,f=s-a,h=f*l-u*c;if(!(h*h<1e-12))return[t+(h=(u*(e-a)-f*(t-i))/h)*l,e+h*c]}function _(t,e,r,n,i,a,s){var l=t-r,u=e-n,f=(s?a:-a)/c(l*l+u*u),h=f*u,p=-f*l,d=t+h,m=e+p,g=r+h,v=n+p,y=(d+g)/2,x=(m+v)/2,b=g-d,_=v-m,w=b*b+_*_,T=i-a,k=d*v-g*m,A=(_<0?-1:1)*c(o(0,T*T*w-k*k)),M=(k*_-b*A)/w,S=(-k*b-_*A)/w,E=(k*_+b*A)/w,L=(-k*b+_*A)/w,C=M-y,P=S-x,I=E-y,O=L-x;return C*C+P*P>I*I+O*O&&(M=E,S=L),{cx:M,cy:S,x01:-h,y01:-p,x11:M*(i/T-1),y11:S*(i/T-1)}}function w(t){this._context=t}function T(t){return new w(t)}function k(t){return t[0]}function A(t){return t[1]}function M(){var t=k,n=A,i=r(!0),a=null,o=T,s=null;function l(r){var l,c,u,f=r.length,h=!1;for(null==a&&(s=o(u=e.path())),l=0;l<=f;++l)!(l<f&&i(c=r[l],l,r))===h&&((h=!h)?s.lineStart():s.lineEnd()),h&&s.point(+t(c,l,r),+n(c,l,r));if(u)return s=null,u+""||null}return l.x=function(e){return arguments.length?(t="function"==typeof e?e:r(+e),l):t},l.y=function(t){return arguments.length?(n="function"==typeof t?t:r(+t),l):n},l.defined=function(t){return arguments.length?(i="function"==typeof t?t:r(!!t),l):i},l.curve=function(t){return arguments.length?(o=t,null!=a&&(s=o(a)),l):o},l.context=function(t){return arguments.length?(null==t?a=s=null:s=o(a=t),l):a},l}function S(){var t=k,n=null,i=r(0),a=A,o=r(!0),s=null,l=T,c=null;function u(r){var u,f,h,p,d,m=r.length,g=!1,v=new Array(m),y=new Array(m);for(null==s&&(c=l(d=e.path())),u=0;u<=m;++u){if(!(u<m&&o(p=r[u],u,r))===g)if(g=!g)f=u,c.areaStart(),c.lineStart();else{for(c.lineEnd(),c.lineStart(),h=u-1;h>=f;--h)c.point(v[h],y[h]);c.lineEnd(),c.areaEnd()}g&&(v[u]=+t(p,u,r),y[u]=+i(p,u,r),c.point(n?+n(p,u,r):v[u],a?+a(p,u,r):y[u]))}if(d)return c=null,d+""||null}function f(){return M().defined(o).curve(l).context(s)}return u.x=function(e){return arguments.length?(t="function"==typeof e?e:r(+e),n=null,u):t},u.x0=function(e){return arguments.length?(t="function"==typeof e?e:r(+e),u):t},u.x1=function(t){return arguments.length?(n=null==t?null:"function"==typeof t?t:r(+t),u):n},u.y=function(t){return arguments.length?(i="function"==typeof t?t:r(+t),a=null,u):i},u.y0=function(t){return arguments.length?(i="function"==typeof t?t:r(+t),u):i},u.y1=function(t){return arguments.length?(a=null==t?null:"function"==typeof t?t:r(+t),u):a},u.lineX0=u.lineY0=function(){return f().x(t).y(i)},u.lineY1=function(){return f().x(t).y(a)},u.lineX1=function(){return f().x(n).y(i)},u.defined=function(t){return arguments.length?(o="function"==typeof t?t:r(!!t),u):o},u.curve=function(t){return arguments.length?(l=t,null!=s&&(c=l(s)),u):l},u.context=function(t){return arguments.length?(null==t?s=c=null:c=l(s=t),u):s},u}function E(t,e){return e<t?-1:e>t?1:e>=t?0:NaN}function L(t){return t}w.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e)}}};var C=I(T);function P(t){this._curve=t}function I(t){function e(e){return new P(t(e))}return e._curve=t,e}function O(t){var e=t.curve;return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t.curve=function(t){return arguments.length?e(I(t)):e()._curve},t}function z(){return O(M().curve(C))}function D(){var t=S().curve(C),e=t.curve,r=t.lineX0,n=t.lineX1,i=t.lineY0,a=t.lineY1;return t.angle=t.x,delete t.x,t.startAngle=t.x0,delete t.x0,t.endAngle=t.x1,delete t.x1,t.radius=t.y,delete t.y,t.innerRadius=t.y0,delete t.y0,t.outerRadius=t.y1,delete t.y1,t.lineStartAngle=function(){return O(r())},delete t.lineX0,t.lineEndAngle=function(){return O(n())},delete t.lineX1,t.lineInnerRadius=function(){return O(i())},delete t.lineY0,t.lineOuterRadius=function(){return O(a())},delete t.lineY1,t.curve=function(t){return arguments.length?e(I(t)):e()._curve},t}function R(t,e){return[(e=+e)*Math.cos(t-=Math.PI/2),e*Math.sin(t)]}P.prototype={areaStart:function(){this._curve.areaStart()},areaEnd:function(){this._curve.areaEnd()},lineStart:function(){this._curve.lineStart()},lineEnd:function(){this._curve.lineEnd()},point:function(t,e){this._curve.point(e*Math.sin(t),e*-Math.cos(t))}};var F=Array.prototype.slice;function B(t){return t.source}function N(t){return t.target}function j(t){var n=B,i=N,a=k,o=A,s=null;function l(){var r,l=F.call(arguments),c=n.apply(this,l),u=i.apply(this,l);if(s||(s=r=e.path()),t(s,+a.apply(this,(l[0]=c,l)),+o.apply(this,l),+a.apply(this,(l[0]=u,l)),+o.apply(this,l)),r)return s=null,r+""||null}return l.source=function(t){return arguments.length?(n=t,l):n},l.target=function(t){return arguments.length?(i=t,l):i},l.x=function(t){return arguments.length?(a="function"==typeof t?t:r(+t),l):a},l.y=function(t){return arguments.length?(o="function"==typeof t?t:r(+t),l):o},l.context=function(t){return arguments.length?(s=null==t?null:t,l):s},l}function U(t,e,r,n,i){t.moveTo(e,r),t.bezierCurveTo(e=(e+n)/2,r,e,i,n,i)}function V(t,e,r,n,i){t.moveTo(e,r),t.bezierCurveTo(e,r=(r+i)/2,n,r,n,i)}function H(t,e,r,n,i){var a=R(e,r),o=R(e,r=(r+i)/2),s=R(n,r),l=R(n,i);t.moveTo(a[0],a[1]),t.bezierCurveTo(o[0],o[1],s[0],s[1],l[0],l[1])}var q={draw:function(t,e){var r=Math.sqrt(e/u);t.moveTo(r,0),t.arc(0,0,r,0,h)}},G={draw:function(t,e){var r=Math.sqrt(e/5)/2;t.moveTo(-3*r,-r),t.lineTo(-r,-r),t.lineTo(-r,-3*r),t.lineTo(r,-3*r),t.lineTo(r,-r),t.lineTo(3*r,-r),t.lineTo(3*r,r),t.lineTo(r,r),t.lineTo(r,3*r),t.lineTo(-r,3*r),t.lineTo(-r,r),t.lineTo(-3*r,r),t.closePath()}},Y=Math.sqrt(1/3),W=2*Y,X={draw:function(t,e){var r=Math.sqrt(e/W),n=r*Y;t.moveTo(0,-r),t.lineTo(n,0),t.lineTo(0,r),t.lineTo(-n,0),t.closePath()}},Z=Math.sin(u/10)/Math.sin(7*u/10),J=Math.sin(h/10)*Z,K=-Math.cos(h/10)*Z,Q={draw:function(t,e){var r=Math.sqrt(.8908130915292852*e),n=J*r,i=K*r;t.moveTo(0,-r),t.lineTo(n,i);for(var a=1;a<5;++a){var o=h*a/5,s=Math.cos(o),l=Math.sin(o);t.lineTo(l*r,-s*r),t.lineTo(s*n-l*i,l*n+s*i)}t.closePath()}},$={draw:function(t,e){var r=Math.sqrt(e),n=-r/2;t.rect(n,n,r,r)}},tt=Math.sqrt(3),et={draw:function(t,e){var r=-Math.sqrt(e/(3*tt));t.moveTo(0,2*r),t.lineTo(-tt*r,-r),t.lineTo(tt*r,-r),t.closePath()}},rt=-.5,nt=Math.sqrt(3)/2,it=1/Math.sqrt(12),at=3*(it/2+1),ot={draw:function(t,e){var r=Math.sqrt(e/at),n=r/2,i=r*it,a=n,o=r*it+r,s=-a,l=o;t.moveTo(n,i),t.lineTo(a,o),t.lineTo(s,l),t.lineTo(rt*n-nt*i,nt*n+rt*i),t.lineTo(rt*a-nt*o,nt*a+rt*o),t.lineTo(rt*s-nt*l,nt*s+rt*l),t.lineTo(rt*n+nt*i,rt*i-nt*n),t.lineTo(rt*a+nt*o,rt*o-nt*a),t.lineTo(rt*s+nt*l,rt*l-nt*s),t.closePath()}},st=[q,G,X,$,Q,et,ot];function lt(){}function ct(t,e,r){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+r)/6)}function ut(t){this._context=t}function ft(t){this._context=t}function ht(t){this._context=t}function pt(t,e){this._basis=new ut(t),this._beta=e}ut.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:ct(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:ct(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},ft.prototype={areaStart:lt,areaEnd:lt,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4)}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x2=t,this._y2=e;break;case 1:this._point=2,this._x3=t,this._y3=e;break;case 2:this._point=3,this._x4=t,this._y4=e,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+e)/6);break;default:ct(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},ht.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var r=(this._x0+4*this._x1+t)/6,n=(this._y0+4*this._y1+e)/6;this._line?this._context.lineTo(r,n):this._context.moveTo(r,n);break;case 3:this._point=4;default:ct(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},pt.prototype={lineStart:function(){this._x=[],this._y=[],this._basis.lineStart()},lineEnd:function(){var t=this._x,e=this._y,r=t.length-1;if(r>0)for(var n,i=t[0],a=e[0],o=t[r]-i,s=e[r]-a,l=-1;++l<=r;)n=l/r,this._basis.point(this._beta*t[l]+(1-this._beta)*(i+n*o),this._beta*e[l]+(1-this._beta)*(a+n*s));this._x=this._y=null,this._basis.lineEnd()},point:function(t,e){this._x.push(+t),this._y.push(+e)}};var dt=function t(e){function r(t){return 1===e?new ut(t):new pt(t,e)}return r.beta=function(e){return t(+e)},r}(.85);function mt(t,e,r){t._context.bezierCurveTo(t._x1+t._k*(t._x2-t._x0),t._y1+t._k*(t._y2-t._y0),t._x2+t._k*(t._x1-e),t._y2+t._k*(t._y1-r),t._x2,t._y2)}function gt(t,e){this._context=t,this._k=(1-e)/6}gt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:mt(this,this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2,this._x1=t,this._y1=e;break;case 2:this._point=3;default:mt(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};var vt=function t(e){function r(t){return new gt(t,e)}return r.tension=function(e){return t(+e)},r}(0);function yt(t,e){this._context=t,this._k=(1-e)/6}yt.prototype={areaStart:lt,areaEnd:lt,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x3=t,this._y3=e;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=e);break;case 2:this._point=3,this._x5=t,this._y5=e;break;default:mt(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};var xt=function t(e){function r(t){return new yt(t,e)}return r.tension=function(e){return t(+e)},r}(0);function bt(t,e){this._context=t,this._k=(1-e)/6}bt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:mt(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};var _t=function t(e){function r(t){return new bt(t,e)}return r.tension=function(e){return t(+e)},r}(0);function wt(t,e,r){var n=t._x1,i=t._y1,a=t._x2,o=t._y2;if(t._l01_a>1e-12){var s=2*t._l01_2a+3*t._l01_a*t._l12_a+t._l12_2a,l=3*t._l01_a*(t._l01_a+t._l12_a);n=(n*s-t._x0*t._l12_2a+t._x2*t._l01_2a)/l,i=(i*s-t._y0*t._l12_2a+t._y2*t._l01_2a)/l}if(t._l23_a>1e-12){var c=2*t._l23_2a+3*t._l23_a*t._l12_a+t._l12_2a,u=3*t._l23_a*(t._l23_a+t._l12_a);a=(a*c+t._x1*t._l23_2a-e*t._l12_2a)/u,o=(o*c+t._y1*t._l23_2a-r*t._l12_2a)/u}t._context.bezierCurveTo(n,i,a,o,t._x2,t._y2)}function Tt(t,e){this._context=t,this._alpha=e}Tt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this.point(this._x2,this._y2)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){if(t=+t,e=+e,this._point){var r=this._x2-t,n=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(r*r+n*n,this._alpha))}switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3;default:wt(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};var kt=function t(e){function r(t){return e?new Tt(t,e):new gt(t,0)}return r.alpha=function(e){return t(+e)},r}(.5);function At(t,e){this._context=t,this._alpha=e}At.prototype={areaStart:lt,areaEnd:lt,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,e){if(t=+t,e=+e,this._point){var r=this._x2-t,n=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(r*r+n*n,this._alpha))}switch(this._point){case 0:this._point=1,this._x3=t,this._y3=e;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=e);break;case 2:this._point=3,this._x5=t,this._y5=e;break;default:wt(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};var Mt=function t(e){function r(t){return e?new At(t,e):new yt(t,0)}return r.alpha=function(e){return t(+e)},r}(.5);function St(t,e){this._context=t,this._alpha=e}St.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){if(t=+t,e=+e,this._point){var r=this._x2-t,n=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(r*r+n*n,this._alpha))}switch(this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:wt(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};var Et=function t(e){function r(t){return e?new St(t,e):new bt(t,0)}return r.alpha=function(e){return t(+e)},r}(.5);function Lt(t){this._context=t}function Ct(t){return t<0?-1:1}function Pt(t,e,r){var n=t._x1-t._x0,i=e-t._x1,a=(t._y1-t._y0)/(n||i<0&&-0),o=(r-t._y1)/(i||n<0&&-0),s=(a*i+o*n)/(n+i);return(Ct(a)+Ct(o))*Math.min(Math.abs(a),Math.abs(o),.5*Math.abs(s))||0}function It(t,e){var r=t._x1-t._x0;return r?(3*(t._y1-t._y0)/r-e)/2:e}function Ot(t,e,r){var n=t._x0,i=t._y0,a=t._x1,o=t._y1,s=(a-n)/3;t._context.bezierCurveTo(n+s,i+s*e,a-s,o-s*r,a,o)}function zt(t){this._context=t}function Dt(t){this._context=new Rt(t)}function Rt(t){this._context=t}function Ft(t){this._context=t}function Bt(t){var e,r,n=t.length-1,i=new Array(n),a=new Array(n),o=new Array(n);for(i[0]=0,a[0]=2,o[0]=t[0]+2*t[1],e=1;e<n-1;++e)i[e]=1,a[e]=4,o[e]=4*t[e]+2*t[e+1];for(i[n-1]=2,a[n-1]=7,o[n-1]=8*t[n-1]+t[n],e=1;e<n;++e)r=i[e]/a[e-1],a[e]-=r,o[e]-=r*o[e-1];for(i[n-1]=o[n-1]/a[n-1],e=n-2;e>=0;--e)i[e]=(o[e]-i[e+1])/a[e];for(a[n-1]=(t[n]+i[n-1])/2,e=0;e<n-1;++e)a[e]=2*t[e+1]-i[e+1];return[i,a]}function Nt(t,e){this._context=t,this._t=e}function jt(t,e){if((i=t.length)>1)for(var r,n,i,a=1,o=t[e[0]],s=o.length;a<i;++a)for(n=o,o=t[e[a]],r=0;r<s;++r)o[r][1]+=o[r][0]=isNaN(n[r][1])?n[r][0]:n[r][1]}function Ut(t){for(var e=t.length,r=new Array(e);--e>=0;)r[e]=e;return r}function Vt(t,e){return t[e]}function Ht(t){var e=t.map(qt);return Ut(t).sort((function(t,r){return e[t]-e[r]}))}function qt(t){for(var e,r=-1,n=0,i=t.length,a=-1/0;++r<i;)(e=+t[r][1])>a&&(a=e,n=r);return n}function Gt(t){var e=t.map(Yt);return Ut(t).sort((function(t,r){return e[t]-e[r]}))}function Yt(t){for(var e,r=0,n=-1,i=t.length;++n<i;)(e=+t[n][1])&&(r+=e);return r}Lt.prototype={areaStart:lt,areaEnd:lt,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(t,e){t=+t,e=+e,this._point?this._context.lineTo(t,e):(this._point=1,this._context.moveTo(t,e))}},zt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:Ot(this,this._t0,It(this,this._t0))}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){var r=NaN;if(e=+e,(t=+t)!==this._x1||e!==this._y1){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,Ot(this,It(this,r=Pt(this,t,e)),r);break;default:Ot(this,this._t0,r=Pt(this,t,e))}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e,this._t0=r}}},(Dt.prototype=Object.create(zt.prototype)).point=function(t,e){zt.prototype.point.call(this,e,t)},Rt.prototype={moveTo:function(t,e){this._context.moveTo(e,t)},closePath:function(){this._context.closePath()},lineTo:function(t,e){this._context.lineTo(e,t)},bezierCurveTo:function(t,e,r,n,i,a){this._context.bezierCurveTo(e,t,n,r,a,i)}},Ft.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var t=this._x,e=this._y,r=t.length;if(r)if(this._line?this._context.lineTo(t[0],e[0]):this._context.moveTo(t[0],e[0]),2===r)this._context.lineTo(t[1],e[1]);else for(var n=Bt(t),i=Bt(e),a=0,o=1;o<r;++a,++o)this._context.bezierCurveTo(n[0][a],i[0][a],n[1][a],i[1][a],t[o],e[o]);(this._line||0!==this._line&&1===r)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(t,e){this._x.push(+t),this._y.push(+e)}},Nt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&2===this._point&&this._context.lineTo(this._x,this._y),(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var r=this._x*(1-this._t)+t*this._t;this._context.lineTo(r,this._y),this._context.lineTo(r,e)}}this._x=t,this._y=e}},t.arc=function(){var t=m,o=g,w=r(0),T=null,k=v,A=y,M=x,S=null;function E(){var r,m,g=+t.apply(this,arguments),v=+o.apply(this,arguments),y=k.apply(this,arguments)-f,x=A.apply(this,arguments)-f,E=n(x-y),L=x>y;if(S||(S=r=e.path()),v<g&&(m=v,v=g,g=m),v>1e-12)if(E>h-1e-12)S.moveTo(v*a(y),v*l(y)),S.arc(0,0,v,y,x,!L),g>1e-12&&(S.moveTo(g*a(x),g*l(x)),S.arc(0,0,g,x,y,L));else{var C,P,I=y,O=x,z=y,D=x,R=E,F=E,B=M.apply(this,arguments)/2,N=B>1e-12&&(T?+T.apply(this,arguments):c(g*g+v*v)),j=s(n(v-g)/2,+w.apply(this,arguments)),U=j,V=j;if(N>1e-12){var H=d(N/g*l(B)),q=d(N/v*l(B));(R-=2*H)>1e-12?(z+=H*=L?1:-1,D-=H):(R=0,z=D=(y+x)/2),(F-=2*q)>1e-12?(I+=q*=L?1:-1,O-=q):(F=0,I=O=(y+x)/2)}var G=v*a(I),Y=v*l(I),W=g*a(D),X=g*l(D);if(j>1e-12){var Z,J=v*a(O),K=v*l(O),Q=g*a(z),$=g*l(z);if(E<u&&(Z=b(G,Y,Q,$,J,K,W,X))){var tt=G-Z[0],et=Y-Z[1],rt=J-Z[0],nt=K-Z[1],it=1/l(p((tt*rt+et*nt)/(c(tt*tt+et*et)*c(rt*rt+nt*nt)))/2),at=c(Z[0]*Z[0]+Z[1]*Z[1]);U=s(j,(g-at)/(it-1)),V=s(j,(v-at)/(it+1))}}F>1e-12?V>1e-12?(C=_(Q,$,G,Y,v,V,L),P=_(J,K,W,X,v,V,L),S.moveTo(C.cx+C.x01,C.cy+C.y01),V<j?S.arc(C.cx,C.cy,V,i(C.y01,C.x01),i(P.y01,P.x01),!L):(S.arc(C.cx,C.cy,V,i(C.y01,C.x01),i(C.y11,C.x11),!L),S.arc(0,0,v,i(C.cy+C.y11,C.cx+C.x11),i(P.cy+P.y11,P.cx+P.x11),!L),S.arc(P.cx,P.cy,V,i(P.y11,P.x11),i(P.y01,P.x01),!L))):(S.moveTo(G,Y),S.arc(0,0,v,I,O,!L)):S.moveTo(G,Y),g>1e-12&&R>1e-12?U>1e-12?(C=_(W,X,J,K,g,-U,L),P=_(G,Y,Q,$,g,-U,L),S.lineTo(C.cx+C.x01,C.cy+C.y01),U<j?S.arc(C.cx,C.cy,U,i(C.y01,C.x01),i(P.y01,P.x01),!L):(S.arc(C.cx,C.cy,U,i(C.y01,C.x01),i(C.y11,C.x11),!L),S.arc(0,0,g,i(C.cy+C.y11,C.cx+C.x11),i(P.cy+P.y11,P.cx+P.x11),L),S.arc(P.cx,P.cy,U,i(P.y11,P.x11),i(P.y01,P.x01),!L))):S.arc(0,0,g,D,z,L):S.lineTo(W,X)}else S.moveTo(0,0);if(S.closePath(),r)return S=null,r+""||null}return E.centroid=function(){var e=(+t.apply(this,arguments)+ +o.apply(this,arguments))/2,r=(+k.apply(this,arguments)+ +A.apply(this,arguments))/2-u/2;return[a(r)*e,l(r)*e]},E.innerRadius=function(e){return arguments.length?(t="function"==typeof e?e:r(+e),E):t},E.outerRadius=function(t){return arguments.length?(o="function"==typeof t?t:r(+t),E):o},E.cornerRadius=function(t){return arguments.length?(w="function"==typeof t?t:r(+t),E):w},E.padRadius=function(t){return arguments.length?(T=null==t?null:"function"==typeof t?t:r(+t),E):T},E.startAngle=function(t){return arguments.length?(k="function"==typeof t?t:r(+t),E):k},E.endAngle=function(t){return arguments.length?(A="function"==typeof t?t:r(+t),E):A},E.padAngle=function(t){return arguments.length?(M="function"==typeof t?t:r(+t),E):M},E.context=function(t){return arguments.length?(S=null==t?null:t,E):S},E},t.area=S,t.areaRadial=D,t.curveBasis=function(t){return new ut(t)},t.curveBasisClosed=function(t){return new ft(t)},t.curveBasisOpen=function(t){return new ht(t)},t.curveBundle=dt,t.curveCardinal=vt,t.curveCardinalClosed=xt,t.curveCardinalOpen=_t,t.curveCatmullRom=kt,t.curveCatmullRomClosed=Mt,t.curveCatmullRomOpen=Et,t.curveLinear=T,t.curveLinearClosed=function(t){return new Lt(t)},t.curveMonotoneX=function(t){return new zt(t)},t.curveMonotoneY=function(t){return new Dt(t)},t.curveNatural=function(t){return new Ft(t)},t.curveStep=function(t){return new Nt(t,.5)},t.curveStepAfter=function(t){return new Nt(t,1)},t.curveStepBefore=function(t){return new Nt(t,0)},t.line=M,t.lineRadial=z,t.linkHorizontal=function(){return j(U)},t.linkRadial=function(){var t=j(H);return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t},t.linkVertical=function(){return j(V)},t.pie=function(){var t=L,e=E,n=null,i=r(0),a=r(h),o=r(0);function s(r){var s,l,c,u,f,p=r.length,d=0,m=new Array(p),g=new Array(p),v=+i.apply(this,arguments),y=Math.min(h,Math.max(-h,a.apply(this,arguments)-v)),x=Math.min(Math.abs(y)/p,o.apply(this,arguments)),b=x*(y<0?-1:1);for(s=0;s<p;++s)(f=g[m[s]=s]=+t(r[s],s,r))>0&&(d+=f);for(null!=e?m.sort((function(t,r){return e(g[t],g[r])})):null!=n&&m.sort((function(t,e){return n(r[t],r[e])})),s=0,c=d?(y-p*b)/d:0;s<p;++s,v=u)l=m[s],u=v+((f=g[l])>0?f*c:0)+b,g[l]={data:r[l],index:s,value:f,startAngle:v,endAngle:u,padAngle:x};return g}return s.value=function(e){return arguments.length?(t="function"==typeof e?e:r(+e),s):t},s.sortValues=function(t){return arguments.length?(e=t,n=null,s):e},s.sort=function(t){return arguments.length?(n=t,e=null,s):n},s.startAngle=function(t){return arguments.length?(i="function"==typeof t?t:r(+t),s):i},s.endAngle=function(t){return arguments.length?(a="function"==typeof t?t:r(+t),s):a},s.padAngle=function(t){return arguments.length?(o="function"==typeof t?t:r(+t),s):o},s},t.pointRadial=R,t.radialArea=D,t.radialLine=z,t.stack=function(){var t=r([]),e=Ut,n=jt,i=Vt;function a(r){var a,o,s=t.apply(this,arguments),l=r.length,c=s.length,u=new Array(c);for(a=0;a<c;++a){for(var f,h=s[a],p=u[a]=new Array(l),d=0;d<l;++d)p[d]=f=[0,+i(r[d],h,d,r)],f.data=r[d];p.key=h}for(a=0,o=e(u);a<c;++a)u[o[a]].index=a;return n(u,o),u}return a.keys=function(e){return arguments.length?(t="function"==typeof e?e:r(F.call(e)),a):t},a.value=function(t){return arguments.length?(i="function"==typeof t?t:r(+t),a):i},a.order=function(t){return arguments.length?(e=null==t?Ut:"function"==typeof t?t:r(F.call(t)),a):e},a.offset=function(t){return arguments.length?(n=null==t?jt:t,a):n},a},t.stackOffsetDiverging=function(t,e){if((s=t.length)>0)for(var r,n,i,a,o,s,l=0,c=t[e[0]].length;l<c;++l)for(a=o=0,r=0;r<s;++r)(i=(n=t[e[r]][l])[1]-n[0])>0?(n[0]=a,n[1]=a+=i):i<0?(n[1]=o,n[0]=o+=i):(n[0]=0,n[1]=i)},t.stackOffsetExpand=function(t,e){if((n=t.length)>0){for(var r,n,i,a=0,o=t[0].length;a<o;++a){for(i=r=0;r<n;++r)i+=t[r][a][1]||0;if(i)for(r=0;r<n;++r)t[r][a][1]/=i}jt(t,e)}},t.stackOffsetNone=jt,t.stackOffsetSilhouette=function(t,e){if((r=t.length)>0){for(var r,n=0,i=t[e[0]],a=i.length;n<a;++n){for(var o=0,s=0;o<r;++o)s+=t[o][n][1]||0;i[n][1]+=i[n][0]=-s/2}jt(t,e)}},t.stackOffsetWiggle=function(t,e){if((i=t.length)>0&&(n=(r=t[e[0]]).length)>0){for(var r,n,i,a=0,o=1;o<n;++o){for(var s=0,l=0,c=0;s<i;++s){for(var u=t[e[s]],f=u[o][1]||0,h=(f-(u[o-1][1]||0))/2,p=0;p<s;++p){var d=t[e[p]];h+=(d[o][1]||0)-(d[o-1][1]||0)}l+=f,c+=h*f}r[o-1][1]+=r[o-1][0]=a,l&&(a-=c/l)}r[o-1][1]+=r[o-1][0]=a,jt(t,e)}},t.stackOrderAppearance=Ht,t.stackOrderAscending=Gt,t.stackOrderDescending=function(t){return Gt(t).reverse()},t.stackOrderInsideOut=function(t){var e,r,n=t.length,i=t.map(Yt),a=Ht(t),o=0,s=0,l=[],c=[];for(e=0;e<n;++e)r=a[e],o<s?(o+=i[r],l.push(r)):(s+=i[r],c.push(r));return c.reverse().concat(l)},t.stackOrderNone=Ut,t.stackOrderReverse=function(t){return Ut(t).reverse()},t.symbol=function(){var t=r(q),n=r(64),i=null;function a(){var r;if(i||(i=r=e.path()),t.apply(this,arguments).draw(i,+n.apply(this,arguments)),r)return i=null,r+""||null}return a.type=function(e){return arguments.length?(t="function"==typeof e?e:r(e),a):t},a.size=function(t){return arguments.length?(n="function"==typeof t?t:r(+t),a):n},a.context=function(t){return arguments.length?(i=null==t?null:t,a):i},a},t.symbolCircle=q,t.symbolCross=G,t.symbolDiamond=X,t.symbolSquare=$,t.symbolStar=Q,t.symbolTriangle=et,t.symbolWye=ot,t.symbols=st,Object.defineProperty(t,"__esModule",{value:!0})}))},{"d3-path":117}],120:[function(t,e,r){!function(n,i){"object"==typeof r&&void 0!==e?i(r,t("d3-time")):i((n=n||self).d3=n.d3||{},n.d3)}(this,(function(t,e){"use strict";function r(t){if(0<=t.y&&t.y<100){var e=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return e.setFullYear(t.y),e}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function n(t){if(0<=t.y&&t.y<100){var e=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return e.setUTCFullYear(t.y),e}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function i(t,e,r){return{y:t,m:e,d:r,H:0,M:0,S:0,L:0}}function a(t){var a=t.dateTime,o=t.date,l=t.time,c=t.periods,u=t.days,f=t.shortDays,h=t.months,yt=t.shortMonths,xt=p(c),bt=d(c),_t=p(u),wt=d(u),Tt=p(f),kt=d(f),At=p(h),Mt=d(h),St=p(yt),Et=d(yt),Lt={a:function(t){return f[t.getDay()]},A:function(t){return u[t.getDay()]},b:function(t){return yt[t.getMonth()]},B:function(t){return h[t.getMonth()]},c:null,d:D,e:D,f:j,H:R,I:F,j:B,L:N,m:U,M:V,p:function(t){return c[+(t.getHours()>=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:gt,s:vt,S:H,u:q,U:G,V:Y,w:W,W:X,x:null,X:null,y:Z,Y:J,Z:K,"%":mt},Ct={a:function(t){return f[t.getUTCDay()]},A:function(t){return u[t.getUTCDay()]},b:function(t){return yt[t.getUTCMonth()]},B:function(t){return h[t.getUTCMonth()]},c:null,d:Q,e:Q,f:nt,H:$,I:tt,j:et,L:rt,m:it,M:at,p:function(t){return c[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:gt,s:vt,S:ot,u:st,U:lt,V:ct,w:ut,W:ft,x:null,X:null,y:ht,Y:pt,Z:dt,"%":mt},Pt={a:function(t,e,r){var n=Tt.exec(e.slice(r));return n?(t.w=kt[n[0].toLowerCase()],r+n[0].length):-1},A:function(t,e,r){var n=_t.exec(e.slice(r));return n?(t.w=wt[n[0].toLowerCase()],r+n[0].length):-1},b:function(t,e,r){var n=St.exec(e.slice(r));return n?(t.m=Et[n[0].toLowerCase()],r+n[0].length):-1},B:function(t,e,r){var n=At.exec(e.slice(r));return n?(t.m=Mt[n[0].toLowerCase()],r+n[0].length):-1},c:function(t,e,r){return zt(t,a,e,r)},d:A,e:A,f:P,H:S,I:S,j:M,L:C,m:k,M:E,p:function(t,e,r){var n=xt.exec(e.slice(r));return n?(t.p=bt[n[0].toLowerCase()],r+n[0].length):-1},q:T,Q:O,s:z,S:L,u:g,U:v,V:y,w:m,W:x,x:function(t,e,r){return zt(t,o,e,r)},X:function(t,e,r){return zt(t,l,e,r)},y:_,Y:b,Z:w,"%":I};function It(t,e){return function(r){var n,i,a,o=[],l=-1,c=0,u=t.length;for(r instanceof Date||(r=new Date(+r));++l<u;)37===t.charCodeAt(l)&&(o.push(t.slice(c,l)),null!=(i=s[n=t.charAt(++l)])?n=t.charAt(++l):i="e"===n?" ":"0",(a=e[n])&&(n=a(r,i)),o.push(n),c=l+1);return o.push(t.slice(c,l)),o.join("")}}function Ot(t,a){return function(o){var s,l,c=i(1900,void 0,1);if(zt(c,t,o+="",0)!=o.length)return null;if("Q"in c)return new Date(c.Q);if("s"in c)return new Date(1e3*c.s+("L"in c?c.L:0));if(a&&!("Z"in c)&&(c.Z=0),"p"in c&&(c.H=c.H%12+12*c.p),void 0===c.m&&(c.m="q"in c?c.q:0),"V"in c){if(c.V<1||c.V>53)return null;"w"in c||(c.w=1),"Z"in c?(l=(s=n(i(c.y,0,1))).getUTCDay(),s=l>4||0===l?e.utcMonday.ceil(s):e.utcMonday(s),s=e.utcDay.offset(s,7*(c.V-1)),c.y=s.getUTCFullYear(),c.m=s.getUTCMonth(),c.d=s.getUTCDate()+(c.w+6)%7):(l=(s=r(i(c.y,0,1))).getDay(),s=l>4||0===l?e.timeMonday.ceil(s):e.timeMonday(s),s=e.timeDay.offset(s,7*(c.V-1)),c.y=s.getFullYear(),c.m=s.getMonth(),c.d=s.getDate()+(c.w+6)%7)}else("W"in c||"U"in c)&&("w"in c||(c.w="u"in c?c.u%7:"W"in c?1:0),l="Z"in c?n(i(c.y,0,1)).getUTCDay():r(i(c.y,0,1)).getDay(),c.m=0,c.d="W"in c?(c.w+6)%7+7*c.W-(l+5)%7:c.w+7*c.U-(l+6)%7);return"Z"in c?(c.H+=c.Z/100|0,c.M+=c.Z%100,n(c)):r(c)}}function zt(t,e,r,n){for(var i,a,o=0,l=e.length,c=r.length;o<l;){if(n>=c)return-1;if(37===(i=e.charCodeAt(o++))){if(i=e.charAt(o++),!(a=Pt[i in s?e.charAt(o++):i])||(n=a(t,r,n))<0)return-1}else if(i!=r.charCodeAt(n++))return-1}return n}return Lt.x=It(o,Lt),Lt.X=It(l,Lt),Lt.c=It(a,Lt),Ct.x=It(o,Ct),Ct.X=It(l,Ct),Ct.c=It(a,Ct),{format:function(t){var e=It(t+="",Lt);return e.toString=function(){return t},e},parse:function(t){var e=Ot(t+="",!1);return e.toString=function(){return t},e},utcFormat:function(t){var e=It(t+="",Ct);return e.toString=function(){return t},e},utcParse:function(t){var e=Ot(t+="",!0);return e.toString=function(){return t},e}}}var o,s={"-":"",_:" ",0:"0"},l=/^\s*\d+/,c=/^%/,u=/[\\^$*+?|[\]().{}]/g;function f(t,e,r){var n=t<0?"-":"",i=(n?-t:t)+"",a=i.length;return n+(a<r?new Array(r-a+1).join(e)+i:i)}function h(t){return t.replace(u,"\\$&")}function p(t){return new RegExp("^(?:"+t.map(h).join("|")+")","i")}function d(t){for(var e={},r=-1,n=t.length;++r<n;)e[t[r].toLowerCase()]=r;return e}function m(t,e,r){var n=l.exec(e.slice(r,r+1));return n?(t.w=+n[0],r+n[0].length):-1}function g(t,e,r){var n=l.exec(e.slice(r,r+1));return n?(t.u=+n[0],r+n[0].length):-1}function v(t,e,r){var n=l.exec(e.slice(r,r+2));return n?(t.U=+n[0],r+n[0].length):-1}function y(t,e,r){var n=l.exec(e.slice(r,r+2));return n?(t.V=+n[0],r+n[0].length):-1}function x(t,e,r){var n=l.exec(e.slice(r,r+2));return n?(t.W=+n[0],r+n[0].length):-1}function b(t,e,r){var n=l.exec(e.slice(r,r+4));return n?(t.y=+n[0],r+n[0].length):-1}function _(t,e,r){var n=l.exec(e.slice(r,r+2));return n?(t.y=+n[0]+(+n[0]>68?1900:2e3),r+n[0].length):-1}function w(t,e,r){var n=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(r,r+6));return n?(t.Z=n[1]?0:-(n[2]+(n[3]||"00")),r+n[0].length):-1}function T(t,e,r){var n=l.exec(e.slice(r,r+1));return n?(t.q=3*n[0]-3,r+n[0].length):-1}function k(t,e,r){var n=l.exec(e.slice(r,r+2));return n?(t.m=n[0]-1,r+n[0].length):-1}function A(t,e,r){var n=l.exec(e.slice(r,r+2));return n?(t.d=+n[0],r+n[0].length):-1}function M(t,e,r){var n=l.exec(e.slice(r,r+3));return n?(t.m=0,t.d=+n[0],r+n[0].length):-1}function S(t,e,r){var n=l.exec(e.slice(r,r+2));return n?(t.H=+n[0],r+n[0].length):-1}function E(t,e,r){var n=l.exec(e.slice(r,r+2));return n?(t.M=+n[0],r+n[0].length):-1}function L(t,e,r){var n=l.exec(e.slice(r,r+2));return n?(t.S=+n[0],r+n[0].length):-1}function C(t,e,r){var n=l.exec(e.slice(r,r+3));return n?(t.L=+n[0],r+n[0].length):-1}function P(t,e,r){var n=l.exec(e.slice(r,r+6));return n?(t.L=Math.floor(n[0]/1e3),r+n[0].length):-1}function I(t,e,r){var n=c.exec(e.slice(r,r+1));return n?r+n[0].length:-1}function O(t,e,r){var n=l.exec(e.slice(r));return n?(t.Q=+n[0],r+n[0].length):-1}function z(t,e,r){var n=l.exec(e.slice(r));return n?(t.s=+n[0],r+n[0].length):-1}function D(t,e){return f(t.getDate(),e,2)}function R(t,e){return f(t.getHours(),e,2)}function F(t,e){return f(t.getHours()%12||12,e,2)}function B(t,r){return f(1+e.timeDay.count(e.timeYear(t),t),r,3)}function N(t,e){return f(t.getMilliseconds(),e,3)}function j(t,e){return N(t,e)+"000"}function U(t,e){return f(t.getMonth()+1,e,2)}function V(t,e){return f(t.getMinutes(),e,2)}function H(t,e){return f(t.getSeconds(),e,2)}function q(t){var e=t.getDay();return 0===e?7:e}function G(t,r){return f(e.timeSunday.count(e.timeYear(t)-1,t),r,2)}function Y(t,r){var n=t.getDay();return t=n>=4||0===n?e.timeThursday(t):e.timeThursday.ceil(t),f(e.timeThursday.count(e.timeYear(t),t)+(4===e.timeYear(t).getDay()),r,2)}function W(t){return t.getDay()}function X(t,r){return f(e.timeMonday.count(e.timeYear(t)-1,t),r,2)}function Z(t,e){return f(t.getFullYear()%100,e,2)}function J(t,e){return f(t.getFullYear()%1e4,e,4)}function K(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+f(e/60|0,"0",2)+f(e%60,"0",2)}function Q(t,e){return f(t.getUTCDate(),e,2)}function $(t,e){return f(t.getUTCHours(),e,2)}function tt(t,e){return f(t.getUTCHours()%12||12,e,2)}function et(t,r){return f(1+e.utcDay.count(e.utcYear(t),t),r,3)}function rt(t,e){return f(t.getUTCMilliseconds(),e,3)}function nt(t,e){return rt(t,e)+"000"}function it(t,e){return f(t.getUTCMonth()+1,e,2)}function at(t,e){return f(t.getUTCMinutes(),e,2)}function ot(t,e){return f(t.getUTCSeconds(),e,2)}function st(t){var e=t.getUTCDay();return 0===e?7:e}function lt(t,r){return f(e.utcSunday.count(e.utcYear(t)-1,t),r,2)}function ct(t,r){var n=t.getUTCDay();return t=n>=4||0===n?e.utcThursday(t):e.utcThursday.ceil(t),f(e.utcThursday.count(e.utcYear(t),t)+(4===e.utcYear(t).getUTCDay()),r,2)}function ut(t){return t.getUTCDay()}function ft(t,r){return f(e.utcMonday.count(e.utcYear(t)-1,t),r,2)}function ht(t,e){return f(t.getUTCFullYear()%100,e,2)}function pt(t,e){return f(t.getUTCFullYear()%1e4,e,4)}function dt(){return"+0000"}function mt(){return"%"}function gt(t){return+t}function vt(t){return Math.floor(+t/1e3)}function yt(e){return o=a(e),t.timeFormat=o.format,t.timeParse=o.parse,t.utcFormat=o.utcFormat,t.utcParse=o.utcParse,o}yt({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});var xt=Date.prototype.toISOString?function(t){return t.toISOString()}:t.utcFormat("%Y-%m-%dT%H:%M:%S.%LZ");var bt=+new Date("2000-01-01T00:00:00.000Z")?function(t){var e=new Date(t);return isNaN(e)?null:e}:t.utcParse("%Y-%m-%dT%H:%M:%S.%LZ");t.isoFormat=xt,t.isoParse=bt,t.timeFormatDefaultLocale=yt,t.timeFormatLocale=a,Object.defineProperty(t,"__esModule",{value:!0})}))},{"d3-time":121}],121:[function(t,e,r){!function(t,n){"object"==typeof r&&void 0!==e?n(r):n((t=t||self).d3=t.d3||{})}(this,(function(t){"use strict";var e=new Date,r=new Date;function n(t,i,a,o){function s(e){return t(e=0===arguments.length?new Date:new Date(+e)),e}return s.floor=function(e){return t(e=new Date(+e)),e},s.ceil=function(e){return t(e=new Date(e-1)),i(e,1),t(e),e},s.round=function(t){var e=s(t),r=s.ceil(t);return t-e<r-t?e:r},s.offset=function(t,e){return i(t=new Date(+t),null==e?1:Math.floor(e)),t},s.range=function(e,r,n){var a,o=[];if(e=s.ceil(e),n=null==n?1:Math.floor(n),!(e<r&&n>0))return o;do{o.push(a=new Date(+e)),i(e,n),t(e)}while(a<e&&e<r);return o},s.filter=function(e){return n((function(r){if(r>=r)for(;t(r),!e(r);)r.setTime(r-1)}),(function(t,r){if(t>=t)if(r<0)for(;++r<=0;)for(;i(t,-1),!e(t););else for(;--r>=0;)for(;i(t,1),!e(t););}))},a&&(s.count=function(n,i){return e.setTime(+n),r.setTime(+i),t(e),t(r),Math.floor(a(e,r))},s.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?s.filter(o?function(e){return o(e)%t==0}:function(e){return s.count(0,e)%t==0}):s:null}),s}var i=n((function(){}),(function(t,e){t.setTime(+t+e)}),(function(t,e){return e-t}));i.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?n((function(e){e.setTime(Math.floor(e/t)*t)}),(function(e,r){e.setTime(+e+r*t)}),(function(e,r){return(r-e)/t})):i:null};var a=i.range,o=n((function(t){t.setTime(t-t.getMilliseconds())}),(function(t,e){t.setTime(+t+1e3*e)}),(function(t,e){return(e-t)/1e3}),(function(t){return t.getUTCSeconds()})),s=o.range,l=n((function(t){t.setTime(t-t.getMilliseconds()-1e3*t.getSeconds())}),(function(t,e){t.setTime(+t+6e4*e)}),(function(t,e){return(e-t)/6e4}),(function(t){return t.getMinutes()})),c=l.range,u=n((function(t){t.setTime(t-t.getMilliseconds()-1e3*t.getSeconds()-6e4*t.getMinutes())}),(function(t,e){t.setTime(+t+36e5*e)}),(function(t,e){return(e-t)/36e5}),(function(t){return t.getHours()})),f=u.range,h=n((function(t){t.setHours(0,0,0,0)}),(function(t,e){t.setDate(t.getDate()+e)}),(function(t,e){return(e-t-6e4*(e.getTimezoneOffset()-t.getTimezoneOffset()))/864e5}),(function(t){return t.getDate()-1})),p=h.range;function d(t){return n((function(e){e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)}),(function(t,e){t.setDate(t.getDate()+7*e)}),(function(t,e){return(e-t-6e4*(e.getTimezoneOffset()-t.getTimezoneOffset()))/6048e5}))}var m=d(0),g=d(1),v=d(2),y=d(3),x=d(4),b=d(5),_=d(6),w=m.range,T=g.range,k=v.range,A=y.range,M=x.range,S=b.range,E=_.range,L=n((function(t){t.setDate(1),t.setHours(0,0,0,0)}),(function(t,e){t.setMonth(t.getMonth()+e)}),(function(t,e){return e.getMonth()-t.getMonth()+12*(e.getFullYear()-t.getFullYear())}),(function(t){return t.getMonth()})),C=L.range,P=n((function(t){t.setMonth(0,1),t.setHours(0,0,0,0)}),(function(t,e){t.setFullYear(t.getFullYear()+e)}),(function(t,e){return e.getFullYear()-t.getFullYear()}),(function(t){return t.getFullYear()}));P.every=function(t){return isFinite(t=Math.floor(t))&&t>0?n((function(e){e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)}),(function(e,r){e.setFullYear(e.getFullYear()+r*t)})):null};var I=P.range,O=n((function(t){t.setUTCSeconds(0,0)}),(function(t,e){t.setTime(+t+6e4*e)}),(function(t,e){return(e-t)/6e4}),(function(t){return t.getUTCMinutes()})),z=O.range,D=n((function(t){t.setUTCMinutes(0,0,0)}),(function(t,e){t.setTime(+t+36e5*e)}),(function(t,e){return(e-t)/36e5}),(function(t){return t.getUTCHours()})),R=D.range,F=n((function(t){t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+e)}),(function(t,e){return(e-t)/864e5}),(function(t){return t.getUTCDate()-1})),B=F.range;function N(t){return n((function(e){e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+7*e)}),(function(t,e){return(e-t)/6048e5}))}var j=N(0),U=N(1),V=N(2),H=N(3),q=N(4),G=N(5),Y=N(6),W=j.range,X=U.range,Z=V.range,J=H.range,K=q.range,Q=G.range,$=Y.range,tt=n((function(t){t.setUTCDate(1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCMonth(t.getUTCMonth()+e)}),(function(t,e){return e.getUTCMonth()-t.getUTCMonth()+12*(e.getUTCFullYear()-t.getUTCFullYear())}),(function(t){return t.getUTCMonth()})),et=tt.range,rt=n((function(t){t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCFullYear(t.getUTCFullYear()+e)}),(function(t,e){return e.getUTCFullYear()-t.getUTCFullYear()}),(function(t){return t.getUTCFullYear()}));rt.every=function(t){return isFinite(t=Math.floor(t))&&t>0?n((function(e){e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)}),(function(e,r){e.setUTCFullYear(e.getUTCFullYear()+r*t)})):null};var nt=rt.range;t.timeDay=h,t.timeDays=p,t.timeFriday=b,t.timeFridays=S,t.timeHour=u,t.timeHours=f,t.timeInterval=n,t.timeMillisecond=i,t.timeMilliseconds=a,t.timeMinute=l,t.timeMinutes=c,t.timeMonday=g,t.timeMondays=T,t.timeMonth=L,t.timeMonths=C,t.timeSaturday=_,t.timeSaturdays=E,t.timeSecond=o,t.timeSeconds=s,t.timeSunday=m,t.timeSundays=w,t.timeThursday=x,t.timeThursdays=M,t.timeTuesday=v,t.timeTuesdays=k,t.timeWednesday=y,t.timeWednesdays=A,t.timeWeek=m,t.timeWeeks=w,t.timeYear=P,t.timeYears=I,t.utcDay=F,t.utcDays=B,t.utcFriday=G,t.utcFridays=Q,t.utcHour=D,t.utcHours=R,t.utcMillisecond=i,t.utcMilliseconds=a,t.utcMinute=O,t.utcMinutes=z,t.utcMonday=U,t.utcMondays=X,t.utcMonth=tt,t.utcMonths=et,t.utcSaturday=Y,t.utcSaturdays=$,t.utcSecond=o,t.utcSeconds=s,t.utcSunday=j,t.utcSundays=W,t.utcThursday=q,t.utcThursdays=K,t.utcTuesday=V,t.utcTuesdays=Z,t.utcWednesday=H,t.utcWednesdays=J,t.utcWeek=j,t.utcWeeks=W,t.utcYear=rt,t.utcYears=nt,Object.defineProperty(t,"__esModule",{value:!0})}))},{}],122:[function(t,e,r){arguments[4][121][0].apply(r,arguments)},{dup:121}],123:[function(t,e,r){!function(t,n){"object"==typeof r&&void 0!==e?n(r):n((t=t||self).d3=t.d3||{})}(this,(function(t){"use strict";var e,r,n=0,i=0,a=0,o=0,s=0,l=0,c="object"==typeof performance&&performance.now?performance:Date,u="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function f(){return s||(u(h),s=c.now()+l)}function h(){s=0}function p(){this._call=this._time=this._next=null}function d(t,e,r){var n=new p;return n.restart(t,e,r),n}function m(){f(),++n;for(var t,r=e;r;)(t=s-r._time)>=0&&r._call.call(null,t),r=r._next;--n}function g(){s=(o=c.now())+l,n=i=0;try{m()}finally{n=0,function(){var t,n,i=e,a=1/0;for(;i;)i._call?(a>i._time&&(a=i._time),t=i,i=i._next):(n=i._next,i._next=null,i=t?t._next=n:e=n);r=t,y(a)}(),s=0}}function v(){var t=c.now(),e=t-o;e>1e3&&(l-=e,o=t)}function y(t){n||(i&&(i=clearTimeout(i)),t-s>24?(t<1/0&&(i=setTimeout(g,t-c.now()-l)),a&&(a=clearInterval(a))):(a||(o=c.now(),a=setInterval(v,1e3)),n=1,u(g)))}p.prototype=d.prototype={constructor:p,restart:function(t,n,i){if("function"!=typeof t)throw new TypeError("callback is not a function");i=(null==i?f():+i)+(null==n?0:+n),this._next||r===this||(r?r._next=this:e=this,r=this),this._call=t,this._time=i,y()},stop:function(){this._call&&(this._call=null,this._time=1/0,y())}},t.interval=function(t,e,r){var n=new p,i=e;return null==e?(n.restart(t,e,r),n):(e=+e,r=null==r?f():+r,n.restart((function a(o){o+=i,n.restart(a,i+=e,r),t(o)}),e,r),n)},t.now=f,t.timeout=function(t,e,r){var n=new p;return e=null==e?0:+e,n.restart((function(r){n.stop(),t(r+e)}),e,r),n},t.timer=d,t.timerFlush=m,Object.defineProperty(t,"__esModule",{value:!0})}))},{}],124:[function(t,e,r){e.exports=function(){for(var t=0;t<arguments.length;t++)if(void 0!==arguments[t])return arguments[t]}},{}],125:[function(t,e,r){"use strict";e.exports=a;var n=(a.canvas=document.createElement("canvas")).getContext("2d"),i=o([32,126]);function a(t,e){Array.isArray(t)&&(t=t.join(", "));var r,a={},s=16,l=.05;e&&(2===e.length&&"number"==typeof e[0]?r=o(e):Array.isArray(e)?r=e:(e.o?r=o(e.o):e.pairs&&(r=e.pairs),e.fontSize&&(s=e.fontSize),null!=e.threshold&&(l=e.threshold))),r||(r=i),n.font=s+"px "+t;for(var c=0;c<r.length;c++){var u=r[c],f=n.measureText(u[0]).width+n.measureText(u[1]).width,h=n.measureText(u).width;if(Math.abs(f-h)>s*l){var p=(h-f)/s;a[u]=1e3*p}}return a}function o(t){for(var e=[],r=t[0];r<=t[1];r++)for(var n=String.fromCharCode(r),i=t[0];i<t[1];i++){var a=n+String.fromCharCode(i);e.push(a)}return e}a.createPairs=o,a.ascii=i},{}],126:[function(t,e,r){var n=t("abs-svg-path"),i=t("normalize-svg-path"),a={M:"moveTo",C:"bezierCurveTo"};e.exports=function(t,e){t.beginPath(),i(n(e)).forEach((function(e){var r=e[0],n=e.slice(1);t[a[r]].apply(t,n)})),t.closePath()}},{"abs-svg-path":70,"normalize-svg-path":246}],127:[function(t,e,r){e.exports=function(t){switch(t){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array;case"uint8_clamped":return Uint8ClampedArray}}},{}],128:[function(t,e,r){"use strict";e.exports=function(t,e){switch(void 0===e&&(e=0),typeof t){case"number":if(t>0)return function(t,e){var r,n;for(r=new Array(t),n=0;n<t;++n)r[n]=e;return r}(0|t,e);break;case"object":if("number"==typeof t.length)return function t(e,r,n){var i=0|e[n];if(i<=0)return[];var a,o=new Array(i);if(n===e.length-1)for(a=0;a<i;++a)o[a]=r;else for(a=0;a<i;++a)o[a]=t(e,r,n+1);return o}(t,e,0)}return[]}},{}],129:[function(t,e,r){"use strict";function n(t,e,r){r=r||2;var n,s,l,c,u,p,d,g=e&&e.length,v=g?e[0]*r:t.length,y=i(t,0,v,r,!0),x=[];if(!y||y.next===y.prev)return x;if(g&&(y=function(t,e,r,n){var o,s,l,c,u,p=[];for(o=0,s=e.length;o<s;o++)l=e[o]*n,c=o<s-1?e[o+1]*n:t.length,(u=i(t,l,c,n,!1))===u.next&&(u.steiner=!0),p.push(m(u));for(p.sort(f),o=0;o<p.length;o++)h(p[o],r),r=a(r,r.next);return r}(t,e,y,r)),t.length>80*r){n=l=t[0],s=c=t[1];for(var b=r;b<v;b+=r)(u=t[b])<n&&(n=u),(p=t[b+1])<s&&(s=p),u>l&&(l=u),p>c&&(c=p);d=0!==(d=Math.max(l-n,c-s))?1/d:0}return o(y,x,r,n,s,d),x}function i(t,e,r,n,i){var a,o;if(i===E(t,e,r,n)>0)for(a=e;a<r;a+=n)o=A(a,t[a],t[a+1],o);else for(a=r-n;a>=e;a-=n)o=A(a,t[a],t[a+1],o);return o&&x(o,o.next)&&(M(o),o=o.next),o}function a(t,e){if(!t)return t;e||(e=t);var r,n=t;do{if(r=!1,n.steiner||!x(n,n.next)&&0!==y(n.prev,n,n.next))n=n.next;else{if(M(n),(n=e=n.prev)===n.next)break;r=!0}}while(r||n!==e);return e}function o(t,e,r,n,i,f,h){if(t){!h&&f&&function(t,e,r,n){var i=t;do{null===i.z&&(i.z=d(i.x,i.y,e,r,n)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next}while(i!==t);i.prevZ.nextZ=null,i.prevZ=null,function(t){var e,r,n,i,a,o,s,l,c=1;do{for(r=t,t=null,a=null,o=0;r;){for(o++,n=r,s=0,e=0;e<c&&(s++,n=n.nextZ);e++);for(l=c;s>0||l>0&&n;)0!==s&&(0===l||!n||r.z<=n.z)?(i=r,r=r.nextZ,s--):(i=n,n=n.nextZ,l--),a?a.nextZ=i:t=i,i.prevZ=a,a=i;r=n}a.nextZ=null,c*=2}while(o>1)}(i)}(t,n,i,f);for(var p,m,g=t;t.prev!==t.next;)if(p=t.prev,m=t.next,f?l(t,n,i,f):s(t))e.push(p.i/r),e.push(t.i/r),e.push(m.i/r),M(t),t=m.next,g=m.next;else if((t=m)===g){h?1===h?o(t=c(a(t),e,r),e,r,n,i,f,2):2===h&&u(t,e,r,n,i,f):o(a(t),e,r,n,i,f,1);break}}}function s(t){var e=t.prev,r=t,n=t.next;if(y(e,r,n)>=0)return!1;for(var i=t.next.next;i!==t.prev;){if(g(e.x,e.y,r.x,r.y,n.x,n.y,i.x,i.y)&&y(i.prev,i,i.next)>=0)return!1;i=i.next}return!0}function l(t,e,r,n){var i=t.prev,a=t,o=t.next;if(y(i,a,o)>=0)return!1;for(var s=i.x<a.x?i.x<o.x?i.x:o.x:a.x<o.x?a.x:o.x,l=i.y<a.y?i.y<o.y?i.y:o.y:a.y<o.y?a.y:o.y,c=i.x>a.x?i.x>o.x?i.x:o.x:a.x>o.x?a.x:o.x,u=i.y>a.y?i.y>o.y?i.y:o.y:a.y>o.y?a.y:o.y,f=d(s,l,e,r,n),h=d(c,u,e,r,n),p=t.prevZ,m=t.nextZ;p&&p.z>=f&&m&&m.z<=h;){if(p!==t.prev&&p!==t.next&&g(i.x,i.y,a.x,a.y,o.x,o.y,p.x,p.y)&&y(p.prev,p,p.next)>=0)return!1;if(p=p.prevZ,m!==t.prev&&m!==t.next&&g(i.x,i.y,a.x,a.y,o.x,o.y,m.x,m.y)&&y(m.prev,m,m.next)>=0)return!1;m=m.nextZ}for(;p&&p.z>=f;){if(p!==t.prev&&p!==t.next&&g(i.x,i.y,a.x,a.y,o.x,o.y,p.x,p.y)&&y(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;m&&m.z<=h;){if(m!==t.prev&&m!==t.next&&g(i.x,i.y,a.x,a.y,o.x,o.y,m.x,m.y)&&y(m.prev,m,m.next)>=0)return!1;m=m.nextZ}return!0}function c(t,e,r){var n=t;do{var i=n.prev,o=n.next.next;!x(i,o)&&b(i,n,n.next,o)&&T(i,o)&&T(o,i)&&(e.push(i.i/r),e.push(n.i/r),e.push(o.i/r),M(n),M(n.next),n=t=o),n=n.next}while(n!==t);return a(n)}function u(t,e,r,n,i,s){var l=t;do{for(var c=l.next.next;c!==l.prev;){if(l.i!==c.i&&v(l,c)){var u=k(l,c);return l=a(l,l.next),u=a(u,u.next),o(l,e,r,n,i,s),void o(u,e,r,n,i,s)}c=c.next}l=l.next}while(l!==t)}function f(t,e){return t.x-e.x}function h(t,e){if(e=function(t,e){var r,n=e,i=t.x,a=t.y,o=-1/0;do{if(a<=n.y&&a>=n.next.y&&n.next.y!==n.y){var s=n.x+(a-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(s<=i&&s>o){if(o=s,s===i){if(a===n.y)return n;if(a===n.next.y)return n.next}r=n.x<n.next.x?n:n.next}}n=n.next}while(n!==e);if(!r)return null;if(i===o)return r;var l,c=r,u=r.x,f=r.y,h=1/0;n=r;do{i>=n.x&&n.x>=u&&i!==n.x&&g(a<f?i:o,a,u,f,a<f?o:i,a,n.x,n.y)&&(l=Math.abs(a-n.y)/(i-n.x),T(n,t)&&(l<h||l===h&&(n.x>r.x||n.x===r.x&&p(r,n)))&&(r=n,h=l)),n=n.next}while(n!==c);return r}(t,e)){var r=k(e,t);a(e,e.next),a(r,r.next)}}function p(t,e){return y(t.prev,t,e.prev)<0&&y(e.next,t,t.next)<0}function d(t,e,r,n,i){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-r)*i)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-n)*i)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function m(t){var e=t,r=t;do{(e.x<r.x||e.x===r.x&&e.y<r.y)&&(r=e),e=e.next}while(e!==t);return r}function g(t,e,r,n,i,a,o,s){return(i-o)*(e-s)-(t-o)*(a-s)>=0&&(t-o)*(n-s)-(r-o)*(e-s)>=0&&(r-o)*(a-s)-(i-o)*(n-s)>=0}function v(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var r=t;do{if(r.i!==t.i&&r.next.i!==t.i&&r.i!==e.i&&r.next.i!==e.i&&b(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(T(t,e)&&T(e,t)&&function(t,e){var r=t,n=!1,i=(t.x+e.x)/2,a=(t.y+e.y)/2;do{r.y>a!=r.next.y>a&&r.next.y!==r.y&&i<(r.next.x-r.x)*(a-r.y)/(r.next.y-r.y)+r.x&&(n=!n),r=r.next}while(r!==t);return n}(t,e)&&(y(t.prev,t,e.prev)||y(t,e.prev,e))||x(t,e)&&y(t.prev,t,t.next)>0&&y(e.prev,e,e.next)>0)}function y(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function x(t,e){return t.x===e.x&&t.y===e.y}function b(t,e,r,n){var i=w(y(t,e,r)),a=w(y(t,e,n)),o=w(y(r,n,t)),s=w(y(r,n,e));return i!==a&&o!==s||(!(0!==i||!_(t,r,e))||(!(0!==a||!_(t,n,e))||(!(0!==o||!_(r,t,n))||!(0!==s||!_(r,e,n)))))}function _(t,e,r){return e.x<=Math.max(t.x,r.x)&&e.x>=Math.min(t.x,r.x)&&e.y<=Math.max(t.y,r.y)&&e.y>=Math.min(t.y,r.y)}function w(t){return t>0?1:t<0?-1:0}function T(t,e){return y(t.prev,t,t.next)<0?y(t,e,t.next)>=0&&y(t,t.prev,e)>=0:y(t,e,t.prev)<0||y(t,t.next,e)<0}function k(t,e){var r=new S(t.i,t.x,t.y),n=new S(e.i,e.x,e.y),i=t.next,a=e.prev;return t.next=e,e.prev=t,r.next=i,i.prev=r,n.next=r,r.prev=n,a.next=n,n.prev=a,n}function A(t,e,r,n){var i=new S(t,e,r);return n?(i.next=n.next,i.prev=n,n.next.prev=i,n.next=i):(i.prev=i,i.next=i),i}function M(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function S(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function E(t,e,r,n){for(var i=0,a=e,o=r-n;a<r;a+=n)i+=(t[o]-t[a])*(t[a+1]+t[o+1]),o=a;return i}e.exports=n,e.exports.default=n,n.deviation=function(t,e,r,n){var i=e&&e.length,a=i?e[0]*r:t.length,o=Math.abs(E(t,0,a,r));if(i)for(var s=0,l=e.length;s<l;s++){var c=e[s]*r,u=s<l-1?e[s+1]*r:t.length;o-=Math.abs(E(t,c,u,r))}var f=0;for(s=0;s<n.length;s+=3){var h=n[s]*r,p=n[s+1]*r,d=n[s+2]*r;f+=Math.abs((t[h]-t[d])*(t[p+1]-t[h+1])-(t[h]-t[p])*(t[d+1]-t[h+1]))}return 0===o&&0===f?0:Math.abs((f-o)/o)},n.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},n=0,i=0;i<t.length;i++){for(var a=0;a<t[i].length;a++)for(var o=0;o<e;o++)r.vertices.push(t[i][a][o]);i>0&&(n+=t[i-1].length,r.holes.push(n))}return r}},{}],130:[function(t,e,r){var n=t("strongly-connected-components");e.exports=function(t,e){var r,i=[],a=[],o=[],s={},l=[];function c(t){var e,n,i=!1;for(a.push(t),o[t]=!0,e=0;e<l[t].length;e++)(n=l[t][e])===r?(u(r,a),i=!0):o[n]||(i=c(n));if(i)!function t(e){o[e]=!1,s.hasOwnProperty(e)&&Object.keys(s[e]).forEach((function(r){delete s[e][r],o[r]&&t(r)}))}(t);else for(e=0;e<l[t].length;e++){n=l[t][e];var f=s[n];f||(f={},s[n]=f),f[n]=!0}return a.pop(),i}function u(t,r){var n=[].concat(r).concat(t);e?e(c):i.push(n)}function f(e){!function(e){for(var r=0;r<t.length;r++)r<e&&(t[r]=[]),t[r]=t[r].filter((function(t){return t>=e}))}(e);for(var r,i=n(t).components.filter((function(t){return t.length>1})),a=1/0,o=0;o<i.length;o++)for(var s=0;s<i[o].length;s++)i[o][s]<a&&(a=i[o][s],r=o);var l=i[r];return!!l&&{leastVertex:a,adjList:t.map((function(t,e){return-1===l.indexOf(e)?[]:t.filter((function(t){return-1!==l.indexOf(t)}))}))}}r=0;for(var h=t.length;r<h;){var p=f(r);if(r=p.leastVertex,l=p.adjList){for(var d=0;d<l.length;d++)for(var m=0;m<l[d].length;m++){var g=l[d][m];o[+g]=!1,s[g]={}}c(r),r+=1}else r=h}return e?void 0:i}},{"strongly-connected-components":306}],131:[function(t,e,r){"use strict";var n=t("../../object/valid-value");e.exports=function(){return n(this).length=0,this}},{"../../object/valid-value":162}],132:[function(t,e,r){"use strict";e.exports=t("./is-implemented")()?Array.from:t("./shim")},{"./is-implemented":133,"./shim":134}],133:[function(t,e,r){"use strict";e.exports=function(){var t,e,r=Array.from;return"function"==typeof r&&(e=r(t=["raz","dwa"]),Boolean(e&&e!==t&&"dwa"===e[1]))}},{}],134:[function(t,e,r){"use strict";var n=t("es6-symbol").iterator,i=t("../../function/is-arguments"),a=t("../../function/is-function"),o=t("../../number/to-pos-integer"),s=t("../../object/valid-callable"),l=t("../../object/valid-value"),c=t("../../object/is-value"),u=t("../../string/is-string"),f=Array.isArray,h=Function.prototype.call,p={configurable:!0,enumerable:!0,writable:!0,value:null},d=Object.defineProperty;e.exports=function(t){var e,r,m,g,v,y,x,b,_,w,T=arguments[1],k=arguments[2];if(t=Object(l(t)),c(T)&&s(T),this&&this!==Array&&a(this))e=this;else{if(!T){if(i(t))return 1!==(v=t.length)?Array.apply(null,t):((g=new Array(1))[0]=t[0],g);if(f(t)){for(g=new Array(v=t.length),r=0;r<v;++r)g[r]=t[r];return g}}g=[]}if(!f(t))if(void 0!==(_=t[n])){for(x=s(_).call(t),e&&(g=new e),b=x.next(),r=0;!b.done;)w=T?h.call(T,k,b.value,r):b.value,e?(p.value=w,d(g,r,p)):g[r]=w,b=x.next(),++r;v=r}else if(u(t)){for(v=t.length,e&&(g=new e),r=0,m=0;r<v;++r)w=t[r],r+1<v&&(y=w.charCodeAt(0))>=55296&&y<=56319&&(w+=t[++r]),w=T?h.call(T,k,w,m):w,e?(p.value=w,d(g,m,p)):g[m]=w,++m;v=m}if(void 0===v)for(v=o(t.length),e&&(g=new e(v)),r=0;r<v;++r)w=T?h.call(T,k,t[r],r):t[r],e?(p.value=w,d(g,r,p)):g[r]=w;return e&&(p.value=null,g.length=v),g}},{"../../function/is-arguments":135,"../../function/is-function":136,"../../number/to-pos-integer":142,"../../object/is-value":151,"../../object/valid-callable":160,"../../object/valid-value":162,"../../string/is-string":166,"es6-symbol":175}],135:[function(t,e,r){"use strict";var n=Object.prototype.toString,i=n.call(function(){return arguments}());e.exports=function(t){return n.call(t)===i}},{}],136:[function(t,e,r){"use strict";var n=Object.prototype.toString,i=RegExp.prototype.test.bind(/^[object [A-Za-z0-9]*Function]$/);e.exports=function(t){return"function"==typeof t&&i(n.call(t))}},{}],137:[function(t,e,r){"use strict";e.exports=function(){}},{}],138:[function(t,e,r){"use strict";e.exports=t("./is-implemented")()?Math.sign:t("./shim")},{"./is-implemented":139,"./shim":140}],139:[function(t,e,r){"use strict";e.exports=function(){var t=Math.sign;return"function"==typeof t&&(1===t(10)&&-1===t(-20))}},{}],140:[function(t,e,r){"use strict";e.exports=function(t){return t=Number(t),isNaN(t)||0===t?t:t>0?1:-1}},{}],141:[function(t,e,r){"use strict";var n=t("../math/sign"),i=Math.abs,a=Math.floor;e.exports=function(t){return isNaN(t)?0:0!==(t=Number(t))&&isFinite(t)?n(t)*a(i(t)):t}},{"../math/sign":138}],142:[function(t,e,r){"use strict";var n=t("./to-integer"),i=Math.max;e.exports=function(t){return i(0,n(t))}},{"./to-integer":141}],143:[function(t,e,r){"use strict";var n=t("./valid-callable"),i=t("./valid-value"),a=Function.prototype.bind,o=Function.prototype.call,s=Object.keys,l=Object.prototype.propertyIsEnumerable;e.exports=function(t,e){return function(r,c){var u,f=arguments[2],h=arguments[3];return r=Object(i(r)),n(c),u=s(r),h&&u.sort("function"==typeof h?a.call(h,r):void 0),"function"!=typeof t&&(t=u[t]),o.call(t,u,(function(t,n){return l.call(r,t)?o.call(c,f,r[t],t,r,n):e}))}}},{"./valid-callable":160,"./valid-value":162}],144:[function(t,e,r){"use strict";e.exports=t("./is-implemented")()?Object.assign:t("./shim")},{"./is-implemented":145,"./shim":146}],145:[function(t,e,r){"use strict";e.exports=function(){var t,e=Object.assign;return"function"==typeof e&&(e(t={foo:"raz"},{bar:"dwa"},{trzy:"trzy"}),t.foo+t.bar+t.trzy==="razdwatrzy")}},{}],146:[function(t,e,r){"use strict";var n=t("../keys"),i=t("../valid-value"),a=Math.max;e.exports=function(t,e){var r,o,s,l=a(arguments.length,2);for(t=Object(i(t)),s=function(n){try{t[n]=e[n]}catch(t){r||(r=t)}},o=1;o<l;++o)n(e=arguments[o]).forEach(s);if(void 0!==r)throw r;return t}},{"../keys":152,"../valid-value":162}],147:[function(t,e,r){"use strict";var n=t("../array/from"),i=t("./assign"),a=t("./valid-value");e.exports=function(t){var e=Object(a(t)),r=arguments[1],o=Object(arguments[2]);if(e!==t&&!r)return e;var s={};return r?n(r,(function(e){(o.ensure||e in t)&&(s[e]=t[e])})):i(s,t),s}},{"../array/from":132,"./assign":144,"./valid-value":162}],148:[function(t,e,r){"use strict";var n,i,a,o,s=Object.create;t("./set-prototype-of/is-implemented")()||(n=t("./set-prototype-of/shim")),e.exports=n?1!==n.level?s:(i={},a={},o={configurable:!1,enumerable:!1,writable:!0,value:void 0},Object.getOwnPropertyNames(Object.prototype).forEach((function(t){a[t]="__proto__"!==t?o:{configurable:!0,enumerable:!1,writable:!0,value:void 0}})),Object.defineProperties(i,a),Object.defineProperty(n,"nullPolyfill",{configurable:!1,enumerable:!1,writable:!1,value:i}),function(t,e){return s(null===t?i:t,e)}):s},{"./set-prototype-of/is-implemented":158,"./set-prototype-of/shim":159}],149:[function(t,e,r){"use strict";e.exports=t("./_iterate")("forEach")},{"./_iterate":143}],150:[function(t,e,r){"use strict";var n=t("./is-value"),i={function:!0,object:!0};e.exports=function(t){return n(t)&&i[typeof t]||!1}},{"./is-value":151}],151:[function(t,e,r){"use strict";var n=t("../function/noop")();e.exports=function(t){return t!==n&&null!==t}},{"../function/noop":137}],152:[function(t,e,r){"use strict";e.exports=t("./is-implemented")()?Object.keys:t("./shim")},{"./is-implemented":153,"./shim":154}],153:[function(t,e,r){"use strict";e.exports=function(){try{return Object.keys("primitive"),!0}catch(t){return!1}}},{}],154:[function(t,e,r){"use strict";var n=t("../is-value"),i=Object.keys;e.exports=function(t){return i(n(t)?Object(t):t)}},{"../is-value":151}],155:[function(t,e,r){"use strict";var n=t("./valid-callable"),i=t("./for-each"),a=Function.prototype.call;e.exports=function(t,e){var r={},o=arguments[2];return n(e),i(t,(function(t,n,i,s){r[n]=a.call(e,o,t,n,i,s)})),r}},{"./for-each":149,"./valid-callable":160}],156:[function(t,e,r){"use strict";var n=t("./is-value"),i=Array.prototype.forEach,a=Object.create,o=function(t,e){var r;for(r in t)e[r]=t[r]};e.exports=function(t){var e=a(null);return i.call(arguments,(function(t){n(t)&&o(Object(t),e)})),e}},{"./is-value":151}],157:[function(t,e,r){"use strict";e.exports=t("./is-implemented")()?Object.setPrototypeOf:t("./shim")},{"./is-implemented":158,"./shim":159}],158:[function(t,e,r){"use strict";var n=Object.create,i=Object.getPrototypeOf,a={};e.exports=function(){var t=Object.setPrototypeOf,e=arguments[0]||n;return"function"==typeof t&&i(t(e(null),a))===a}},{}],159:[function(t,e,r){"use strict";var n,i=t("../is-object"),a=t("../valid-value"),o=Object.prototype.isPrototypeOf,s=Object.defineProperty,l={configurable:!0,enumerable:!1,writable:!0,value:void 0};n=function(t,e){if(a(t),null===e||i(e))return t;throw new TypeError("Prototype must be null or an object")},e.exports=function(t){var e,r;return t?(2===t.level?t.set?(r=t.set,e=function(t,e){return r.call(n(t,e),e),t}):e=function(t,e){return n(t,e).__proto__=e,t}:e=function t(e,r){var i;return n(e,r),(i=o.call(t.nullPolyfill,e))&&delete t.nullPolyfill.__proto__,null===r&&(r=t.nullPolyfill),e.__proto__=r,i&&s(t.nullPolyfill,"__proto__",l),e},Object.defineProperty(e,"level",{configurable:!1,enumerable:!1,writable:!1,value:t.level})):null}(function(){var t,e=Object.create(null),r={},n=Object.getOwnPropertyDescriptor(Object.prototype,"__proto__");if(n){try{(t=n.set).call(e,r)}catch(t){}if(Object.getPrototypeOf(e)===r)return{set:t,level:2}}return e.__proto__=r,Object.getPrototypeOf(e)===r?{level:2}:((e={}).__proto__=r,Object.getPrototypeOf(e)===r&&{level:1})}()),t("../create")},{"../create":148,"../is-object":150,"../valid-value":162}],160:[function(t,e,r){"use strict";e.exports=function(t){if("function"!=typeof t)throw new TypeError(t+" is not a function");return t}},{}],161:[function(t,e,r){"use strict";var n=t("./is-object");e.exports=function(t){if(!n(t))throw new TypeError(t+" is not an Object");return t}},{"./is-object":150}],162:[function(t,e,r){"use strict";var n=t("./is-value");e.exports=function(t){if(!n(t))throw new TypeError("Cannot use null or undefined");return t}},{"./is-value":151}],163:[function(t,e,r){"use strict";e.exports=t("./is-implemented")()?String.prototype.contains:t("./shim")},{"./is-implemented":164,"./shim":165}],164:[function(t,e,r){"use strict";var n="razdwatrzy";e.exports=function(){return"function"==typeof n.contains&&(!0===n.contains("dwa")&&!1===n.contains("foo"))}},{}],165:[function(t,e,r){"use strict";var n=String.prototype.indexOf;e.exports=function(t){return n.call(this,t,arguments[1])>-1}},{}],166:[function(t,e,r){"use strict";var n=Object.prototype.toString,i=n.call("");e.exports=function(t){return"string"==typeof t||t&&"object"==typeof t&&(t instanceof String||n.call(t)===i)||!1}},{}],167:[function(t,e,r){"use strict";var n=Object.create(null),i=Math.random;e.exports=function(){var t;do{t=i().toString(36).slice(2)}while(n[t]);return t}},{}],168:[function(t,e,r){"use strict";var n,i=t("es5-ext/object/set-prototype-of"),a=t("es5-ext/string/#/contains"),o=t("d"),s=t("es6-symbol"),l=t("./"),c=Object.defineProperty;n=e.exports=function(t,e){if(!(this instanceof n))throw new TypeError("Constructor requires 'new'");l.call(this,t),e=e?a.call(e,"key+value")?"key+value":a.call(e,"key")?"key":"value":"value",c(this,"__kind__",o("",e))},i&&i(n,l),delete n.prototype.constructor,n.prototype=Object.create(l.prototype,{_resolve:o((function(t){return"value"===this.__kind__?this.__list__[t]:"key+value"===this.__kind__?[t,this.__list__[t]]:t}))}),c(n.prototype,s.toStringTag,o("c","Array Iterator"))},{"./":171,d:106,"es5-ext/object/set-prototype-of":157,"es5-ext/string/#/contains":163,"es6-symbol":175}],169:[function(t,e,r){"use strict";var n=t("es5-ext/function/is-arguments"),i=t("es5-ext/object/valid-callable"),a=t("es5-ext/string/is-string"),o=t("./get"),s=Array.isArray,l=Function.prototype.call,c=Array.prototype.some;e.exports=function(t,e){var r,u,f,h,p,d,m,g,v=arguments[2];if(s(t)||n(t)?r="array":a(t)?r="string":t=o(t),i(e),f=function(){h=!0},"array"!==r)if("string"!==r)for(u=t.next();!u.done;){if(l.call(e,v,u.value,f),h)return;u=t.next()}else for(d=t.length,p=0;p<d&&(m=t[p],p+1<d&&(g=m.charCodeAt(0))>=55296&&g<=56319&&(m+=t[++p]),l.call(e,v,m,f),!h);++p);else c.call(t,(function(t){return l.call(e,v,t,f),h}))}},{"./get":170,"es5-ext/function/is-arguments":135,"es5-ext/object/valid-callable":160,"es5-ext/string/is-string":166}],170:[function(t,e,r){"use strict";var n=t("es5-ext/function/is-arguments"),i=t("es5-ext/string/is-string"),a=t("./array"),o=t("./string"),s=t("./valid-iterable"),l=t("es6-symbol").iterator;e.exports=function(t){return"function"==typeof s(t)[l]?t[l]():n(t)?new a(t):i(t)?new o(t):new a(t)}},{"./array":168,"./string":173,"./valid-iterable":174,"es5-ext/function/is-arguments":135,"es5-ext/string/is-string":166,"es6-symbol":175}],171:[function(t,e,r){"use strict";var n,i=t("es5-ext/array/#/clear"),a=t("es5-ext/object/assign"),o=t("es5-ext/object/valid-callable"),s=t("es5-ext/object/valid-value"),l=t("d"),c=t("d/auto-bind"),u=t("es6-symbol"),f=Object.defineProperty,h=Object.defineProperties;e.exports=n=function(t,e){if(!(this instanceof n))throw new TypeError("Constructor requires 'new'");h(this,{__list__:l("w",s(t)),__context__:l("w",e),__nextIndex__:l("w",0)}),e&&(o(e.on),e.on("_add",this._onAdd),e.on("_delete",this._onDelete),e.on("_clear",this._onClear))},delete n.prototype.constructor,h(n.prototype,a({_next:l((function(){var t;if(this.__list__)return this.__redo__&&void 0!==(t=this.__redo__.shift())?t:this.__nextIndex__<this.__list__.length?this.__nextIndex__++:void this._unBind()})),next:l((function(){return this._createResult(this._next())})),_createResult:l((function(t){return void 0===t?{done:!0,value:void 0}:{done:!1,value:this._resolve(t)}})),_resolve:l((function(t){return this.__list__[t]})),_unBind:l((function(){this.__list__=null,delete this.__redo__,this.__context__&&(this.__context__.off("_add",this._onAdd),this.__context__.off("_delete",this._onDelete),this.__context__.off("_clear",this._onClear),this.__context__=null)})),toString:l((function(){return"[object "+(this[u.toStringTag]||"Object")+"]"}))},c({_onAdd:l((function(t){t>=this.__nextIndex__||(++this.__nextIndex__,this.__redo__?(this.__redo__.forEach((function(e,r){e>=t&&(this.__redo__[r]=++e)}),this),this.__redo__.push(t)):f(this,"__redo__",l("c",[t])))})),_onDelete:l((function(t){var e;t>=this.__nextIndex__||(--this.__nextIndex__,this.__redo__&&(-1!==(e=this.__redo__.indexOf(t))&&this.__redo__.splice(e,1),this.__redo__.forEach((function(e,r){e>t&&(this.__redo__[r]=--e)}),this)))})),_onClear:l((function(){this.__redo__&&i.call(this.__redo__),this.__nextIndex__=0}))}))),f(n.prototype,u.iterator,l((function(){return this})))},{d:106,"d/auto-bind":105,"es5-ext/array/#/clear":131,"es5-ext/object/assign":144,"es5-ext/object/valid-callable":160,"es5-ext/object/valid-value":162,"es6-symbol":175}],172:[function(t,e,r){"use strict";var n=t("es5-ext/function/is-arguments"),i=t("es5-ext/object/is-value"),a=t("es5-ext/string/is-string"),o=t("es6-symbol").iterator,s=Array.isArray;e.exports=function(t){return!!i(t)&&(!!s(t)||(!!a(t)||(!!n(t)||"function"==typeof t[o])))}},{"es5-ext/function/is-arguments":135,"es5-ext/object/is-value":151,"es5-ext/string/is-string":166,"es6-symbol":175}],173:[function(t,e,r){"use strict";var n,i=t("es5-ext/object/set-prototype-of"),a=t("d"),o=t("es6-symbol"),s=t("./"),l=Object.defineProperty;n=e.exports=function(t){if(!(this instanceof n))throw new TypeError("Constructor requires 'new'");t=String(t),s.call(this,t),l(this,"__length__",a("",t.length))},i&&i(n,s),delete n.prototype.constructor,n.prototype=Object.create(s.prototype,{_next:a((function(){if(this.__list__)return this.__nextIndex__<this.__length__?this.__nextIndex__++:void this._unBind()})),_resolve:a((function(t){var e,r=this.__list__[t];return this.__nextIndex__===this.__length__?r:(e=r.charCodeAt(0))>=55296&&e<=56319?r+this.__list__[this.__nextIndex__++]:r}))}),l(n.prototype,o.toStringTag,a("c","String Iterator"))},{"./":171,d:106,"es5-ext/object/set-prototype-of":157,"es6-symbol":175}],174:[function(t,e,r){"use strict";var n=t("./is-iterable");e.exports=function(t){if(!n(t))throw new TypeError(t+" is not iterable");return t}},{"./is-iterable":172}],175:[function(t,e,r){"use strict";e.exports=t("./is-implemented")()?t("ext/global-this").Symbol:t("./polyfill")},{"./is-implemented":176,"./polyfill":181,"ext/global-this":188}],176:[function(t,e,r){"use strict";var n=t("ext/global-this"),i={object:!0,symbol:!0};e.exports=function(){var t,e=n.Symbol;if("function"!=typeof e)return!1;t=e("test symbol");try{String(t)}catch(t){return!1}return!!i[typeof e.iterator]&&(!!i[typeof e.toPrimitive]&&!!i[typeof e.toStringTag])}},{"ext/global-this":188}],177:[function(t,e,r){"use strict";e.exports=function(t){return!!t&&("symbol"==typeof t||!!t.constructor&&("Symbol"===t.constructor.name&&"Symbol"===t[t.constructor.toStringTag]))}},{}],178:[function(t,e,r){"use strict";var n=t("d"),i=Object.create,a=Object.defineProperty,o=Object.prototype,s=i(null);e.exports=function(t){for(var e,r,i=0;s[t+(i||"")];)++i;return s[t+=i||""]=!0,a(o,e="@@"+t,n.gs(null,(function(t){r||(r=!0,a(this,e,n(t)),r=!1)}))),e}},{d:106}],179:[function(t,e,r){"use strict";var n=t("d"),i=t("ext/global-this").Symbol;e.exports=function(t){return Object.defineProperties(t,{hasInstance:n("",i&&i.hasInstance||t("hasInstance")),isConcatSpreadable:n("",i&&i.isConcatSpreadable||t("isConcatSpreadable")),iterator:n("",i&&i.iterator||t("iterator")),match:n("",i&&i.match||t("match")),replace:n("",i&&i.replace||t("replace")),search:n("",i&&i.search||t("search")),species:n("",i&&i.species||t("species")),split:n("",i&&i.split||t("split")),toPrimitive:n("",i&&i.toPrimitive||t("toPrimitive")),toStringTag:n("",i&&i.toStringTag||t("toStringTag")),unscopables:n("",i&&i.unscopables||t("unscopables"))})}},{d:106,"ext/global-this":188}],180:[function(t,e,r){"use strict";var n=t("d"),i=t("../../../validate-symbol"),a=Object.create(null);e.exports=function(t){return Object.defineProperties(t,{for:n((function(e){return a[e]?a[e]:a[e]=t(String(e))})),keyFor:n((function(t){var e;for(e in i(t),a)if(a[e]===t)return e}))})}},{"../../../validate-symbol":182,d:106}],181:[function(t,e,r){"use strict";var n,i,a,o=t("d"),s=t("./validate-symbol"),l=t("ext/global-this").Symbol,c=t("./lib/private/generate-name"),u=t("./lib/private/setup/standard-symbols"),f=t("./lib/private/setup/symbol-registry"),h=Object.create,p=Object.defineProperties,d=Object.defineProperty;if("function"==typeof l)try{String(l()),a=!0}catch(t){}else l=null;i=function(t){if(this instanceof i)throw new TypeError("Symbol is not a constructor");return n(t)},e.exports=n=function t(e){var r;if(this instanceof t)throw new TypeError("Symbol is not a constructor");return a?l(e):(r=h(i.prototype),e=void 0===e?"":String(e),p(r,{__description__:o("",e),__name__:o("",c(e))}))},u(n),f(n),p(i.prototype,{constructor:o(n),toString:o("",(function(){return this.__name__}))}),p(n.prototype,{toString:o((function(){return"Symbol ("+s(this).__description__+")"})),valueOf:o((function(){return s(this)}))}),d(n.prototype,n.toPrimitive,o("",(function(){var t=s(this);return"symbol"==typeof t?t:t.toString()}))),d(n.prototype,n.toStringTag,o("c","Symbol")),d(i.prototype,n.toStringTag,o("c",n.prototype[n.toStringTag])),d(i.prototype,n.toPrimitive,o("c",n.prototype[n.toPrimitive]))},{"./lib/private/generate-name":178,"./lib/private/setup/standard-symbols":179,"./lib/private/setup/symbol-registry":180,"./validate-symbol":182,d:106,"ext/global-this":188}],182:[function(t,e,r){"use strict";var n=t("./is-symbol");e.exports=function(t){if(!n(t))throw new TypeError(t+" is not a symbol");return t}},{"./is-symbol":177}],183:[function(t,e,r){"use strict";e.exports=t("./is-implemented")()?WeakMap:t("./polyfill")},{"./is-implemented":184,"./polyfill":186}],184:[function(t,e,r){"use strict";e.exports=function(){var t,e;if("function"!=typeof WeakMap)return!1;try{t=new WeakMap([[e={},"one"],[{},"two"],[{},"three"]])}catch(t){return!1}return"[object WeakMap]"===String(t)&&("function"==typeof t.set&&(t.set({},1)===t&&("function"==typeof t.delete&&("function"==typeof t.has&&"one"===t.get(e)))))}},{}],185:[function(t,e,r){"use strict";e.exports="function"==typeof WeakMap&&"[object WeakMap]"===Object.prototype.toString.call(new WeakMap)},{}],186:[function(t,e,r){"use strict";var n,i=t("es5-ext/object/is-value"),a=t("es5-ext/object/set-prototype-of"),o=t("es5-ext/object/valid-object"),s=t("es5-ext/object/valid-value"),l=t("es5-ext/string/random-uniq"),c=t("d"),u=t("es6-iterator/get"),f=t("es6-iterator/for-of"),h=t("es6-symbol").toStringTag,p=t("./is-native-implemented"),d=Array.isArray,m=Object.defineProperty,g=Object.prototype.hasOwnProperty,v=Object.getPrototypeOf;e.exports=n=function(){var t,e=arguments[0];if(!(this instanceof n))throw new TypeError("Constructor requires 'new'");return t=p&&a&&WeakMap!==n?a(new WeakMap,v(this)):this,i(e)&&(d(e)||(e=u(e))),m(t,"__weakMapData__",c("c","$weakMap$"+l())),e?(f(e,(function(e){s(e),t.set(e[0],e[1])})),t):t},p&&(a&&a(n,WeakMap),n.prototype=Object.create(WeakMap.prototype,{constructor:c(n)})),Object.defineProperties(n.prototype,{delete:c((function(t){return!!g.call(o(t),this.__weakMapData__)&&(delete t[this.__weakMapData__],!0)})),get:c((function(t){if(g.call(o(t),this.__weakMapData__))return t[this.__weakMapData__]})),has:c((function(t){return g.call(o(t),this.__weakMapData__)})),set:c((function(t,e){return m(o(t),this.__weakMapData__,c("c",e)),this})),toString:c((function(){return"[object WeakMap]"}))}),m(n.prototype,h,c("c","WeakMap"))},{"./is-native-implemented":185,d:106,"es5-ext/object/is-value":151,"es5-ext/object/set-prototype-of":157,"es5-ext/object/valid-object":161,"es5-ext/object/valid-value":162,"es5-ext/string/random-uniq":167,"es6-iterator/for-of":169,"es6-iterator/get":170,"es6-symbol":175}],187:[function(t,e,r){var n=function(){if("object"==typeof self&&self)return self;if("object"==typeof window&&window)return window;throw new Error("Unable to resolve global `this`")};e.exports=function(){if(this)return this;try{Object.defineProperty(Object.prototype,"__global__",{get:function(){return this},configurable:!0})}catch(t){return n()}try{return __global__||n()}finally{delete Object.prototype.__global__}}()},{}],188:[function(t,e,r){"use strict";e.exports=t("./is-implemented")()?globalThis:t("./implementation")},{"./implementation":187,"./is-implemented":189}],189:[function(t,e,r){"use strict";e.exports=function(){return"object"==typeof globalThis&&(!!globalThis&&globalThis.Array===Array)}},{}],190:[function(t,e,r){"use strict";var n=t("is-string-blank");e.exports=function(t){var e=typeof t;if("string"===e){var r=t;if(0===(t=+t)&&n(r))return!1}else if("number"!==e)return!1;return t-t<1}},{"is-string-blank":237}],191:[function(t,e,r){var n=t("dtype");e.exports=function(t,e,r){if(!t)throw new TypeError("must specify data as first parameter");if(r=0|+(r||0),Array.isArray(t)&&t[0]&&"number"==typeof t[0][0]){var i,a,o,s,l=t[0].length,c=t.length*l;e&&"string"!=typeof e||(e=new(n(e||"float32"))(c+r));var u=e.length-r;if(c!==u)throw new Error("source length "+c+" ("+l+"x"+t.length+") does not match destination length "+u);for(i=0,o=r;i<t.length;i++)for(a=0;a<l;a++)e[o++]=null===t[i][a]?NaN:t[i][a]}else if(e&&"string"!=typeof e)e.set(t,r);else{var f=n(e||"float32");if(Array.isArray(t)||"array"===e)for(e=new f(t.length+r),i=0,o=r,s=e.length;o<s;o++,i++)e[o]=null===t[i]?NaN:t[i];else 0===r?e=new f(t):(e=new f(t.length+r)).set(t,r)}return e}},{dtype:127}],192:[function(t,e,r){"use strict";var n=t("css-font/stringify"),i=[32,126];e.exports=function(t){var e=(t=t||{}).shape?t.shape:t.canvas?[t.canvas.width,t.canvas.height]:[512,512],r=t.canvas||document.createElement("canvas"),a=t.font,o="number"==typeof t.step?[t.step,t.step]:t.step||[32,32],s=t.chars||i;a&&"string"!=typeof a&&(a=n(a));if(Array.isArray(s)){if(2===s.length&&"number"==typeof s[0]&&"number"==typeof s[1]){for(var l=[],c=s[0],u=0;c<=s[1];c++)l[u++]=String.fromCharCode(c);s=l}}else s=String(s).split("");e=e.slice(),r.width=e[0],r.height=e[1];var f=r.getContext("2d");f.fillStyle="#000",f.fillRect(0,0,r.width,r.height),f.font=a,f.textAlign="center",f.textBaseline="middle",f.fillStyle="#fff";var h=o[0]/2,p=o[1]/2;for(c=0;c<s.length;c++)f.fillText(s[c],h,p),(h+=o[0])>e[0]-o[0]/2&&(h=o[0]/2,p+=o[1]);return r}},{"css-font/stringify":102}],193:[function(t,e,r){"use strict";function n(t,e){e||(e={}),("string"==typeof t||Array.isArray(t))&&(e.family=t);var r=Array.isArray(e.family)?e.family.join(", "):e.family;if(!r)throw Error("`family` must be defined");var s=e.size||e.fontSize||e.em||48,l=e.weight||e.fontWeight||"",c=(t=[e.style||e.fontStyle||"",l,s].join(" ")+"px "+r,e.origin||"top");if(n.cache[r]&&s<=n.cache[r].em)return i(n.cache[r],c);var u=e.canvas||n.canvas,f=u.getContext("2d"),h={upper:void 0!==e.upper?e.upper:"H",lower:void 0!==e.lower?e.lower:"x",descent:void 0!==e.descent?e.descent:"p",ascent:void 0!==e.ascent?e.ascent:"h",tittle:void 0!==e.tittle?e.tittle:"i",overshoot:void 0!==e.overshoot?e.overshoot:"O"},p=Math.ceil(1.5*s);u.height=p,u.width=.5*p,f.font=t;var d={top:0};f.clearRect(0,0,p,p),f.textBaseline="top",f.fillStyle="black",f.fillText("H",0,0);var m=a(f.getImageData(0,0,p,p));f.clearRect(0,0,p,p),f.textBaseline="bottom",f.fillText("H",0,p);var g=a(f.getImageData(0,0,p,p));d.lineHeight=d.bottom=p-g+m,f.clearRect(0,0,p,p),f.textBaseline="alphabetic",f.fillText("H",0,p);var v=p-a(f.getImageData(0,0,p,p))-1+m;d.baseline=d.alphabetic=v,f.clearRect(0,0,p,p),f.textBaseline="middle",f.fillText("H",0,.5*p);var y=a(f.getImageData(0,0,p,p));d.median=d.middle=p-y-1+m-.5*p,f.clearRect(0,0,p,p),f.textBaseline="hanging",f.fillText("H",0,.5*p);var x=a(f.getImageData(0,0,p,p));d.hanging=p-x-1+m-.5*p,f.clearRect(0,0,p,p),f.textBaseline="ideographic",f.fillText("H",0,p);var b=a(f.getImageData(0,0,p,p));if(d.ideographic=p-b-1+m,h.upper&&(f.clearRect(0,0,p,p),f.textBaseline="top",f.fillText(h.upper,0,0),d.upper=a(f.getImageData(0,0,p,p)),d.capHeight=d.baseline-d.upper),h.lower&&(f.clearRect(0,0,p,p),f.textBaseline="top",f.fillText(h.lower,0,0),d.lower=a(f.getImageData(0,0,p,p)),d.xHeight=d.baseline-d.lower),h.tittle&&(f.clearRect(0,0,p,p),f.textBaseline="top",f.fillText(h.tittle,0,0),d.tittle=a(f.getImageData(0,0,p,p))),h.ascent&&(f.clearRect(0,0,p,p),f.textBaseline="top",f.fillText(h.ascent,0,0),d.ascent=a(f.getImageData(0,0,p,p))),h.descent&&(f.clearRect(0,0,p,p),f.textBaseline="top",f.fillText(h.descent,0,0),d.descent=o(f.getImageData(0,0,p,p))),h.overshoot){f.clearRect(0,0,p,p),f.textBaseline="top",f.fillText(h.overshoot,0,0);var _=o(f.getImageData(0,0,p,p));d.overshoot=_-v}for(var w in d)d[w]/=s;return d.em=s,n.cache[r]=d,i(d,c)}function i(t,e){var r={};for(var n in"string"==typeof e&&(e=t[e]),t)"em"!==n&&(r[n]=t[n]-e);return r}function a(t){for(var e=t.height,r=t.data,n=3;n<r.length;n+=4)if(0!==r[n])return Math.floor(.25*(n-3)/e)}function o(t){for(var e=t.height,r=t.data,n=r.length-1;n>0;n-=4)if(0!==r[n])return Math.floor(.25*(n-3)/e)}e.exports=n,n.canvas=document.createElement("canvas"),n.cache={}},{}],194:[function(t,e,r){e.exports=function(t,e){if("string"!=typeof t)throw new TypeError("must specify type string");if(e=e||{},"undefined"==typeof document&&!e.canvas)return null;var r=e.canvas||document.createElement("canvas");"number"==typeof e.width&&(r.width=e.width);"number"==typeof e.height&&(r.height=e.height);var n,i=e;try{var a=[t];0===t.indexOf("webgl")&&a.push("experimental-"+t);for(var o=0;o<a.length;o++)if(n=r.getContext(a[o],i))return n}catch(t){n=null}return n||null}},{}],195:[function(t,e,r){e.exports=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],l=e[6],c=e[7],u=e[8],f=e[9],h=e[10],p=e[11],d=e[12],m=e[13],g=e[14],v=e[15];return t[0]=s*(h*v-p*g)-f*(l*v-c*g)+m*(l*p-c*h),t[1]=-(n*(h*v-p*g)-f*(i*v-a*g)+m*(i*p-a*h)),t[2]=n*(l*v-c*g)-s*(i*v-a*g)+m*(i*c-a*l),t[3]=-(n*(l*p-c*h)-s*(i*p-a*h)+f*(i*c-a*l)),t[4]=-(o*(h*v-p*g)-u*(l*v-c*g)+d*(l*p-c*h)),t[5]=r*(h*v-p*g)-u*(i*v-a*g)+d*(i*p-a*h),t[6]=-(r*(l*v-c*g)-o*(i*v-a*g)+d*(i*c-a*l)),t[7]=r*(l*p-c*h)-o*(i*p-a*h)+u*(i*c-a*l),t[8]=o*(f*v-p*m)-u*(s*v-c*m)+d*(s*p-c*f),t[9]=-(r*(f*v-p*m)-u*(n*v-a*m)+d*(n*p-a*f)),t[10]=r*(s*v-c*m)-o*(n*v-a*m)+d*(n*c-a*s),t[11]=-(r*(s*p-c*f)-o*(n*p-a*f)+u*(n*c-a*s)),t[12]=-(o*(f*g-h*m)-u*(s*g-l*m)+d*(s*h-l*f)),t[13]=r*(f*g-h*m)-u*(n*g-i*m)+d*(n*h-i*f),t[14]=-(r*(s*g-l*m)-o*(n*g-i*m)+d*(n*l-i*s)),t[15]=r*(s*h-l*f)-o*(n*h-i*f)+u*(n*l-i*s),t}},{}],196:[function(t,e,r){e.exports=function(t){var e=new Float32Array(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}},{}],197:[function(t,e,r){e.exports=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}},{}],198:[function(t,e,r){e.exports=function(){var t=new Float32Array(16);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}},{}],199:[function(t,e,r){e.exports=function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],l=t[7],c=t[8],u=t[9],f=t[10],h=t[11],p=t[12],d=t[13],m=t[14],g=t[15];return(e*o-r*a)*(f*g-h*m)-(e*s-n*a)*(u*g-h*d)+(e*l-i*a)*(u*m-f*d)+(r*s-n*o)*(c*g-h*p)-(r*l-i*o)*(c*m-f*p)+(n*l-i*s)*(c*d-u*p)}},{}],200:[function(t,e,r){e.exports=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r+r,s=n+n,l=i+i,c=r*o,u=n*o,f=n*s,h=i*o,p=i*s,d=i*l,m=a*o,g=a*s,v=a*l;return t[0]=1-f-d,t[1]=u+v,t[2]=h-g,t[3]=0,t[4]=u-v,t[5]=1-c-d,t[6]=p+m,t[7]=0,t[8]=h+g,t[9]=p-m,t[10]=1-c-f,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}},{}],201:[function(t,e,r){e.exports=function(t,e,r){var n,i,a,o=r[0],s=r[1],l=r[2],c=Math.sqrt(o*o+s*s+l*l);if(Math.abs(c)<1e-6)return null;return o*=c=1/c,s*=c,l*=c,n=Math.sin(e),i=Math.cos(e),a=1-i,t[0]=o*o*a+i,t[1]=s*o*a+l*n,t[2]=l*o*a-s*n,t[3]=0,t[4]=o*s*a-l*n,t[5]=s*s*a+i,t[6]=l*s*a+o*n,t[7]=0,t[8]=o*l*a+s*n,t[9]=s*l*a-o*n,t[10]=l*l*a+i,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}},{}],202:[function(t,e,r){e.exports=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=n+n,l=i+i,c=a+a,u=n*s,f=n*l,h=n*c,p=i*l,d=i*c,m=a*c,g=o*s,v=o*l,y=o*c;return t[0]=1-(p+m),t[1]=f+y,t[2]=h-v,t[3]=0,t[4]=f-y,t[5]=1-(u+m),t[6]=d+g,t[7]=0,t[8]=h+v,t[9]=d-g,t[10]=1-(u+p),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}},{}],203:[function(t,e,r){e.exports=function(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}},{}],204:[function(t,e,r){e.exports=function(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}},{}],205:[function(t,e,r){e.exports=function(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n,t[6]=r,t[7]=0,t[8]=0,t[9]=-r,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}},{}],206:[function(t,e,r){e.exports=function(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=0,t[2]=-r,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=r,t[9]=0,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}},{}],207:[function(t,e,r){e.exports=function(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=0,t[4]=-r,t[5]=n,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}},{}],208:[function(t,e,r){e.exports=function(t,e,r,n,i,a,o){var s=1/(r-e),l=1/(i-n),c=1/(a-o);return t[0]=2*a*s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2*a*l,t[6]=0,t[7]=0,t[8]=(r+e)*s,t[9]=(i+n)*l,t[10]=(o+a)*c,t[11]=-1,t[12]=0,t[13]=0,t[14]=o*a*2*c,t[15]=0,t}},{}],209:[function(t,e,r){e.exports=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}},{}],210:[function(t,e,r){e.exports={create:t("./create"),clone:t("./clone"),copy:t("./copy"),identity:t("./identity"),transpose:t("./transpose"),invert:t("./invert"),adjoint:t("./adjoint"),determinant:t("./determinant"),multiply:t("./multiply"),translate:t("./translate"),scale:t("./scale"),rotate:t("./rotate"),rotateX:t("./rotateX"),rotateY:t("./rotateY"),rotateZ:t("./rotateZ"),fromRotation:t("./fromRotation"),fromRotationTranslation:t("./fromRotationTranslation"),fromScaling:t("./fromScaling"),fromTranslation:t("./fromTranslation"),fromXRotation:t("./fromXRotation"),fromYRotation:t("./fromYRotation"),fromZRotation:t("./fromZRotation"),fromQuat:t("./fromQuat"),frustum:t("./frustum"),perspective:t("./perspective"),perspectiveFromFieldOfView:t("./perspectiveFromFieldOfView"),ortho:t("./ortho"),lookAt:t("./lookAt"),str:t("./str")}},{"./adjoint":195,"./clone":196,"./copy":197,"./create":198,"./determinant":199,"./fromQuat":200,"./fromRotation":201,"./fromRotationTranslation":202,"./fromScaling":203,"./fromTranslation":204,"./fromXRotation":205,"./fromYRotation":206,"./fromZRotation":207,"./frustum":208,"./identity":209,"./invert":211,"./lookAt":212,"./multiply":213,"./ortho":214,"./perspective":215,"./perspectiveFromFieldOfView":216,"./rotate":217,"./rotateX":218,"./rotateY":219,"./rotateZ":220,"./scale":221,"./str":222,"./translate":223,"./transpose":224}],211:[function(t,e,r){e.exports=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],l=e[6],c=e[7],u=e[8],f=e[9],h=e[10],p=e[11],d=e[12],m=e[13],g=e[14],v=e[15],y=r*s-n*o,x=r*l-i*o,b=r*c-a*o,_=n*l-i*s,w=n*c-a*s,T=i*c-a*l,k=u*m-f*d,A=u*g-h*d,M=u*v-p*d,S=f*g-h*m,E=f*v-p*m,L=h*v-p*g,C=y*L-x*E+b*S+_*M-w*A+T*k;if(!C)return null;return C=1/C,t[0]=(s*L-l*E+c*S)*C,t[1]=(i*E-n*L-a*S)*C,t[2]=(m*T-g*w+v*_)*C,t[3]=(h*w-f*T-p*_)*C,t[4]=(l*M-o*L-c*A)*C,t[5]=(r*L-i*M+a*A)*C,t[6]=(g*b-d*T-v*x)*C,t[7]=(u*T-h*b+p*x)*C,t[8]=(o*E-s*M+c*k)*C,t[9]=(n*M-r*E-a*k)*C,t[10]=(d*w-m*b+v*y)*C,t[11]=(f*b-u*w-p*y)*C,t[12]=(s*A-o*S-l*k)*C,t[13]=(r*S-n*A+i*k)*C,t[14]=(m*x-d*_-g*y)*C,t[15]=(u*_-f*x+h*y)*C,t}},{}],212:[function(t,e,r){var n=t("./identity");e.exports=function(t,e,r,i){var a,o,s,l,c,u,f,h,p,d,m=e[0],g=e[1],v=e[2],y=i[0],x=i[1],b=i[2],_=r[0],w=r[1],T=r[2];if(Math.abs(m-_)<1e-6&&Math.abs(g-w)<1e-6&&Math.abs(v-T)<1e-6)return n(t);f=m-_,h=g-w,p=v-T,d=1/Math.sqrt(f*f+h*h+p*p),a=x*(p*=d)-b*(h*=d),o=b*(f*=d)-y*p,s=y*h-x*f,(d=Math.sqrt(a*a+o*o+s*s))?(a*=d=1/d,o*=d,s*=d):(a=0,o=0,s=0);l=h*s-p*o,c=p*a-f*s,u=f*o-h*a,(d=Math.sqrt(l*l+c*c+u*u))?(l*=d=1/d,c*=d,u*=d):(l=0,c=0,u=0);return t[0]=a,t[1]=l,t[2]=f,t[3]=0,t[4]=o,t[5]=c,t[6]=h,t[7]=0,t[8]=s,t[9]=u,t[10]=p,t[11]=0,t[12]=-(a*m+o*g+s*v),t[13]=-(l*m+c*g+u*v),t[14]=-(f*m+h*g+p*v),t[15]=1,t}},{"./identity":209}],213:[function(t,e,r){e.exports=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],l=e[5],c=e[6],u=e[7],f=e[8],h=e[9],p=e[10],d=e[11],m=e[12],g=e[13],v=e[14],y=e[15],x=r[0],b=r[1],_=r[2],w=r[3];return t[0]=x*n+b*s+_*f+w*m,t[1]=x*i+b*l+_*h+w*g,t[2]=x*a+b*c+_*p+w*v,t[3]=x*o+b*u+_*d+w*y,x=r[4],b=r[5],_=r[6],w=r[7],t[4]=x*n+b*s+_*f+w*m,t[5]=x*i+b*l+_*h+w*g,t[6]=x*a+b*c+_*p+w*v,t[7]=x*o+b*u+_*d+w*y,x=r[8],b=r[9],_=r[10],w=r[11],t[8]=x*n+b*s+_*f+w*m,t[9]=x*i+b*l+_*h+w*g,t[10]=x*a+b*c+_*p+w*v,t[11]=x*o+b*u+_*d+w*y,x=r[12],b=r[13],_=r[14],w=r[15],t[12]=x*n+b*s+_*f+w*m,t[13]=x*i+b*l+_*h+w*g,t[14]=x*a+b*c+_*p+w*v,t[15]=x*o+b*u+_*d+w*y,t}},{}],214:[function(t,e,r){e.exports=function(t,e,r,n,i,a,o){var s=1/(e-r),l=1/(n-i),c=1/(a-o);return t[0]=-2*s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*l,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*c,t[11]=0,t[12]=(e+r)*s,t[13]=(i+n)*l,t[14]=(o+a)*c,t[15]=1,t}},{}],215:[function(t,e,r){e.exports=function(t,e,r,n,i){var a=1/Math.tan(e/2),o=1/(n-i);return t[0]=a/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=(i+n)*o,t[11]=-1,t[12]=0,t[13]=0,t[14]=2*i*n*o,t[15]=0,t}},{}],216:[function(t,e,r){e.exports=function(t,e,r,n){var i=Math.tan(e.upDegrees*Math.PI/180),a=Math.tan(e.downDegrees*Math.PI/180),o=Math.tan(e.leftDegrees*Math.PI/180),s=Math.tan(e.rightDegrees*Math.PI/180),l=2/(o+s),c=2/(i+a);return t[0]=l,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=c,t[6]=0,t[7]=0,t[8]=-(o-s)*l*.5,t[9]=(i-a)*c*.5,t[10]=n/(r-n),t[11]=-1,t[12]=0,t[13]=0,t[14]=n*r/(r-n),t[15]=0,t}},{}],217:[function(t,e,r){e.exports=function(t,e,r,n){var i,a,o,s,l,c,u,f,h,p,d,m,g,v,y,x,b,_,w,T,k,A,M,S,E=n[0],L=n[1],C=n[2],P=Math.sqrt(E*E+L*L+C*C);if(Math.abs(P)<1e-6)return null;E*=P=1/P,L*=P,C*=P,i=Math.sin(r),a=Math.cos(r),o=1-a,s=e[0],l=e[1],c=e[2],u=e[3],f=e[4],h=e[5],p=e[6],d=e[7],m=e[8],g=e[9],v=e[10],y=e[11],x=E*E*o+a,b=L*E*o+C*i,_=C*E*o-L*i,w=E*L*o-C*i,T=L*L*o+a,k=C*L*o+E*i,A=E*C*o+L*i,M=L*C*o-E*i,S=C*C*o+a,t[0]=s*x+f*b+m*_,t[1]=l*x+h*b+g*_,t[2]=c*x+p*b+v*_,t[3]=u*x+d*b+y*_,t[4]=s*w+f*T+m*k,t[5]=l*w+h*T+g*k,t[6]=c*w+p*T+v*k,t[7]=u*w+d*T+y*k,t[8]=s*A+f*M+m*S,t[9]=l*A+h*M+g*S,t[10]=c*A+p*M+v*S,t[11]=u*A+d*M+y*S,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]);return t}},{}],218:[function(t,e,r){e.exports=function(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[4],o=e[5],s=e[6],l=e[7],c=e[8],u=e[9],f=e[10],h=e[11];e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]);return t[4]=a*i+c*n,t[5]=o*i+u*n,t[6]=s*i+f*n,t[7]=l*i+h*n,t[8]=c*i-a*n,t[9]=u*i-o*n,t[10]=f*i-s*n,t[11]=h*i-l*n,t}},{}],219:[function(t,e,r){e.exports=function(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[0],o=e[1],s=e[2],l=e[3],c=e[8],u=e[9],f=e[10],h=e[11];e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]);return t[0]=a*i-c*n,t[1]=o*i-u*n,t[2]=s*i-f*n,t[3]=l*i-h*n,t[8]=a*n+c*i,t[9]=o*n+u*i,t[10]=s*n+f*i,t[11]=l*n+h*i,t}},{}],220:[function(t,e,r){e.exports=function(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[0],o=e[1],s=e[2],l=e[3],c=e[4],u=e[5],f=e[6],h=e[7];e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]);return t[0]=a*i+c*n,t[1]=o*i+u*n,t[2]=s*i+f*n,t[3]=l*i+h*n,t[4]=c*i-a*n,t[5]=u*i-o*n,t[6]=f*i-s*n,t[7]=h*i-l*n,t}},{}],221:[function(t,e,r){e.exports=function(t,e,r){var n=r[0],i=r[1],a=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*a,t[9]=e[9]*a,t[10]=e[10]*a,t[11]=e[11]*a,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}},{}],222:[function(t,e,r){e.exports=function(t){return"mat4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+", "+t[9]+", "+t[10]+", "+t[11]+", "+t[12]+", "+t[13]+", "+t[14]+", "+t[15]+")"}},{}],223:[function(t,e,r){e.exports=function(t,e,r){var n,i,a,o,s,l,c,u,f,h,p,d,m=r[0],g=r[1],v=r[2];e===t?(t[12]=e[0]*m+e[4]*g+e[8]*v+e[12],t[13]=e[1]*m+e[5]*g+e[9]*v+e[13],t[14]=e[2]*m+e[6]*g+e[10]*v+e[14],t[15]=e[3]*m+e[7]*g+e[11]*v+e[15]):(n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],l=e[5],c=e[6],u=e[7],f=e[8],h=e[9],p=e[10],d=e[11],t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=l,t[6]=c,t[7]=u,t[8]=f,t[9]=h,t[10]=p,t[11]=d,t[12]=n*m+s*g+f*v+e[12],t[13]=i*m+l*g+h*v+e[13],t[14]=a*m+c*g+p*v+e[14],t[15]=o*m+u*g+d*v+e[15]);return t}},{}],224:[function(t,e,r){e.exports=function(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],a=e[6],o=e[7],s=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=a,t[11]=e[14],t[12]=i,t[13]=o,t[14]=s}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}},{}],225:[function(t,e,r){"use strict";var n=t("css-font"),i=t("pick-by-alias"),a=t("regl"),o=t("gl-util/context"),s=t("es6-weak-map"),l=t("color-normalize"),c=t("font-atlas"),u=t("typedarray-pool"),f=t("parse-rect"),h=t("is-plain-obj"),p=t("parse-unit"),d=t("to-px"),m=t("detect-kerning"),g=t("object-assign"),v=t("font-measure"),y=t("flatten-vertex-data"),x=t("bit-twiddle").nextPow2,b=new s,_=!1;if(document.body){var w=document.body.appendChild(document.createElement("div"));w.style.font="italic small-caps bold condensed 16px/2 cursive",getComputedStyle(w).fontStretch&&(_=!0),document.body.removeChild(w)}var T=function(t){!function(t){return"function"==typeof t&&t._gl&&t.prop&&t.texture&&t.buffer}(t)?this.gl=o(t):(t={regl:t},this.gl=t.regl._gl),this.shader=b.get(this.gl),this.shader?this.regl=this.shader.regl:this.regl=t.regl||a({gl:this.gl}),this.charBuffer=this.regl.buffer({type:"uint8",usage:"stream"}),this.sizeBuffer=this.regl.buffer({type:"float",usage:"stream"}),this.shader||(this.shader=this.createShader(),b.set(this.gl,this.shader)),this.batch=[],this.fontSize=[],this.font=[],this.fontAtlas=[],this.draw=this.shader.draw.bind(this),this.render=function(){this.regl._refresh(),this.draw(this.batch)},this.canvas=this.gl.canvas,this.update(h(t)?t:{})};T.prototype.createShader=function(){var t=this.regl,e=t({blend:{enable:!0,color:[0,0,0,1],func:{srcRGB:"src alpha",dstRGB:"one minus src alpha",srcAlpha:"one minus dst alpha",dstAlpha:"one"}},stencil:{enable:!1},depth:{enable:!1},count:t.prop("count"),offset:t.prop("offset"),attributes:{charOffset:{offset:4,stride:8,buffer:t.this("sizeBuffer")},width:{offset:0,stride:8,buffer:t.this("sizeBuffer")},char:t.this("charBuffer"),position:t.this("position")},uniforms:{atlasSize:function(t,e){return[e.atlas.width,e.atlas.height]},atlasDim:function(t,e){return[e.atlas.cols,e.atlas.rows]},atlas:function(t,e){return e.atlas.texture},charStep:function(t,e){return e.atlas.step},em:function(t,e){return e.atlas.em},color:t.prop("color"),opacity:t.prop("opacity"),viewport:t.this("viewportArray"),scale:t.this("scale"),align:t.prop("align"),baseline:t.prop("baseline"),translate:t.this("translate"),positionOffset:t.prop("positionOffset")},primitive:"points",viewport:t.this("viewport"),vert:"\n\t\t\tprecision highp float;\n\t\t\tattribute float width, charOffset, char;\n\t\t\tattribute vec2 position;\n\t\t\tuniform float fontSize, charStep, em, align, baseline;\n\t\t\tuniform vec4 viewport;\n\t\t\tuniform vec4 color;\n\t\t\tuniform vec2 atlasSize, atlasDim, scale, translate, positionOffset;\n\t\t\tvarying vec2 charCoord, charId;\n\t\t\tvarying float charWidth;\n\t\t\tvarying vec4 fontColor;\n\t\t\tvoid main () {\n\t\t\t\tvec2 offset = floor(em * (vec2(align + charOffset, baseline)\n\t\t\t\t\t+ vec2(positionOffset.x, -positionOffset.y)))\n\t\t\t\t\t/ (viewport.zw * scale.xy);\n\n\t\t\t\tvec2 position = (position + translate) * scale;\n\t\t\t\tposition += offset * scale;\n\n\t\t\t\tcharCoord = position * viewport.zw + viewport.xy;\n\n\t\t\t\tgl_Position = vec4(position * 2. - 1., 0, 1);\n\n\t\t\t\tgl_PointSize = charStep;\n\n\t\t\t\tcharId.x = mod(char, atlasDim.x);\n\t\t\t\tcharId.y = floor(char / atlasDim.x);\n\n\t\t\t\tcharWidth = width * em;\n\n\t\t\t\tfontColor = color / 255.;\n\t\t\t}",frag:"\n\t\t\tprecision highp float;\n\t\t\tuniform float fontSize, charStep, opacity;\n\t\t\tuniform vec2 atlasSize;\n\t\t\tuniform vec4 viewport;\n\t\t\tuniform sampler2D atlas;\n\t\t\tvarying vec4 fontColor;\n\t\t\tvarying vec2 charCoord, charId;\n\t\t\tvarying float charWidth;\n\n\t\t\tfloat lightness(vec4 color) {\n\t\t\t\treturn color.r * 0.299 + color.g * 0.587 + color.b * 0.114;\n\t\t\t}\n\n\t\t\tvoid main () {\n\t\t\t\tvec2 uv = gl_FragCoord.xy - charCoord + charStep * .5;\n\t\t\t\tfloat halfCharStep = floor(charStep * .5 + .5);\n\n\t\t\t\t// invert y and shift by 1px (FF expecially needs that)\n\t\t\t\tuv.y = charStep - uv.y;\n\n\t\t\t\t// ignore points outside of character bounding box\n\t\t\t\tfloat halfCharWidth = ceil(charWidth * .5);\n\t\t\t\tif (floor(uv.x) > halfCharStep + halfCharWidth ||\n\t\t\t\t\tfloor(uv.x) < halfCharStep - halfCharWidth) return;\n\n\t\t\t\tuv += charId * charStep;\n\t\t\t\tuv = uv / atlasSize;\n\n\t\t\t\tvec4 color = fontColor;\n\t\t\t\tvec4 mask = texture2D(atlas, uv);\n\n\t\t\t\tfloat maskY = lightness(mask);\n\t\t\t\t// float colorY = lightness(color);\n\t\t\t\tcolor.a *= maskY;\n\t\t\t\tcolor.a *= opacity;\n\n\t\t\t\t// color.a += .1;\n\n\t\t\t\t// antialiasing, see yiq color space y-channel formula\n\t\t\t\t// color.rgb += (1. - color.rgb) * (1. - mask.rgb);\n\n\t\t\t\tgl_FragColor = color;\n\t\t\t}"});return{regl:t,draw:e,atlas:{}}},T.prototype.update=function(t){var e=this;if("string"==typeof t)t={text:t};else if(!t)return;null!=(t=i(t,{position:"position positions coord coords coordinates",font:"font fontFace fontface typeface cssFont css-font family fontFamily",fontSize:"fontSize fontsize size font-size",text:"text texts chars characters value values symbols",align:"align alignment textAlign textbaseline",baseline:"baseline textBaseline textbaseline",direction:"dir direction textDirection",color:"color colour fill fill-color fillColor textColor textcolor",kerning:"kerning kern",range:"range dataBox",viewport:"vp viewport viewBox viewbox viewPort",opacity:"opacity alpha transparency visible visibility opaque",offset:"offset positionOffset padding shift indent indentation"},!0)).opacity&&(Array.isArray(t.opacity)?this.opacity=t.opacity.map((function(t){return parseFloat(t)})):this.opacity=parseFloat(t.opacity)),null!=t.viewport&&(this.viewport=f(t.viewport),this.viewportArray=[this.viewport.x,this.viewport.y,this.viewport.width,this.viewport.height]),null==this.viewport&&(this.viewport={x:0,y:0,width:this.gl.drawingBufferWidth,height:this.gl.drawingBufferHeight},this.viewportArray=[this.viewport.x,this.viewport.y,this.viewport.width,this.viewport.height]),null!=t.kerning&&(this.kerning=t.kerning),null!=t.offset&&("number"==typeof t.offset&&(t.offset=[t.offset,0]),this.positionOffset=y(t.offset)),t.direction&&(this.direction=t.direction),t.range&&(this.range=t.range,this.scale=[1/(t.range[2]-t.range[0]),1/(t.range[3]-t.range[1])],this.translate=[-t.range[0],-t.range[1]]),t.scale&&(this.scale=t.scale),t.translate&&(this.translate=t.translate),this.scale||(this.scale=[1/this.viewport.width,1/this.viewport.height]),this.translate||(this.translate=[0,0]),this.font.length||t.font||(t.font=T.baseFontSize+"px sans-serif");var r,a=!1,o=!1;if(t.font&&(Array.isArray(t.font)?t.font:[t.font]).forEach((function(t,r){if("string"==typeof t)try{t=n.parse(t)}catch(e){t=n.parse(T.baseFontSize+"px "+t)}else t=n.parse(n.stringify(t));var i=n.stringify({size:T.baseFontSize,family:t.family,stretch:_?t.stretch:void 0,variant:t.variant,weight:t.weight,style:t.style}),s=p(t.size),l=Math.round(s[0]*d(s[1]));if(l!==e.fontSize[r]&&(o=!0,e.fontSize[r]=l),!(e.font[r]&&i==e.font[r].baseString||(a=!0,e.font[r]=T.fonts[i],e.font[r]))){var c=t.family.join(", "),u=[t.style];t.style!=t.variant&&u.push(t.variant),t.variant!=t.weight&&u.push(t.weight),_&&t.weight!=t.stretch&&u.push(t.stretch),e.font[r]={baseString:i,family:c,weight:t.weight,stretch:t.stretch,style:t.style,variant:t.variant,width:{},kerning:{},metrics:v(c,{origin:"top",fontSize:T.baseFontSize,fontStyle:u.join(" ")})},T.fonts[i]=e.font[r]}})),(a||o)&&this.font.forEach((function(r,i){var a=n.stringify({size:e.fontSize[i],family:r.family,stretch:_?r.stretch:void 0,variant:r.variant,weight:r.weight,style:r.style});if(e.fontAtlas[i]=e.shader.atlas[a],!e.fontAtlas[i]){var o=r.metrics;e.shader.atlas[a]=e.fontAtlas[i]={fontString:a,step:2*Math.ceil(e.fontSize[i]*o.bottom*.5),em:e.fontSize[i],cols:0,rows:0,height:0,width:0,chars:[],ids:{},texture:e.regl.texture()}}null==t.text&&(t.text=e.text)})),"string"==typeof t.text&&t.position&&t.position.length>2){for(var s=Array(.5*t.position.length),h=0;h<s.length;h++)s[h]=t.text;t.text=s}if(null!=t.text||a){if(this.textOffsets=[0],Array.isArray(t.text)){this.count=t.text[0].length,this.counts=[this.count];for(var b=1;b<t.text.length;b++)this.textOffsets[b]=this.textOffsets[b-1]+t.text[b-1].length,this.count+=t.text[b].length,this.counts.push(t.text[b].length);this.text=t.text.join("")}else this.text=t.text,this.count=this.text.length,this.counts=[this.count];r=[],this.font.forEach((function(t,n){T.atlasContext.font=t.baseString;for(var i=e.fontAtlas[n],a=0;a<e.text.length;a++){var o=e.text.charAt(a);if(null==i.ids[o]&&(i.ids[o]=i.chars.length,i.chars.push(o),r.push(o)),null==t.width[o]&&(t.width[o]=T.atlasContext.measureText(o).width/T.baseFontSize,e.kerning)){var s=[];for(var l in t.width)s.push(l+o,o+l);g(t.kerning,m(t.family,{pairs:s}))}}}))}if(t.position)if(t.position.length>2){for(var w=!t.position[0].length,k=u.mallocFloat(2*this.count),A=0,M=0;A<this.counts.length;A++){var S=this.counts[A];if(w)for(var E=0;E<S;E++)k[M++]=t.position[2*A],k[M++]=t.position[2*A+1];else for(var L=0;L<S;L++)k[M++]=t.position[A][0],k[M++]=t.position[A][1]}this.position.call?this.position({type:"float",data:k}):this.position=this.regl.buffer({type:"float",data:k}),u.freeFloat(k)}else this.position.destroy&&this.position.destroy(),this.position={constant:t.position};if(t.text||a){var C=u.mallocUint8(this.count),P=u.mallocFloat(2*this.count);this.textWidth=[];for(var I=0,O=0;I<this.counts.length;I++){for(var z=this.counts[I],D=this.font[I]||this.font[0],R=this.fontAtlas[I]||this.fontAtlas[0],F=0;F<z;F++){var B=this.text.charAt(O),N=this.text.charAt(O-1);if(C[O]=R.ids[B],P[2*O]=D.width[B],F){var j=P[2*O-2],U=P[2*O],V=P[2*O-1]+.5*j+.5*U;if(this.kerning){var H=D.kerning[N+B];H&&(V+=.001*H)}P[2*O+1]=V}else P[2*O+1]=.5*P[2*O];O++}this.textWidth.push(P.length?.5*P[2*O-2]+P[2*O-1]:0)}t.align||(t.align=this.align),this.charBuffer({data:C,type:"uint8",usage:"stream"}),this.sizeBuffer({data:P,type:"float",usage:"stream"}),u.freeUint8(C),u.freeFloat(P),r.length&&this.font.forEach((function(t,r){var n=e.fontAtlas[r],i=n.step,a=Math.floor(T.maxAtlasSize/i),o=Math.min(a,n.chars.length),s=Math.ceil(n.chars.length/o),l=x(o*i),u=x(s*i);n.width=l,n.height=u,n.rows=s,n.cols=o,n.em&&n.texture({data:c({canvas:T.atlasCanvas,font:n.fontString,chars:n.chars,shape:[l,u],step:[i,i]})})}))}if(t.align&&(this.align=t.align,this.alignOffset=this.textWidth.map((function(t,r){var n=Array.isArray(e.align)?e.align.length>1?e.align[r]:e.align[0]:e.align;if("number"==typeof n)return n;switch(n){case"right":case"end":return-t;case"center":case"centre":case"middle":return.5*-t}return 0}))),null==this.baseline&&null==t.baseline&&(t.baseline=0),null!=t.baseline&&(this.baseline=t.baseline,Array.isArray(this.baseline)||(this.baseline=[this.baseline]),this.baselineOffset=this.baseline.map((function(t,r){var n=(e.font[r]||e.font[0]).metrics,i=0;return i+=.5*n.bottom,i+="number"==typeof t?t-n.baseline:-n[t],i*=-1}))),null!=t.color)if(t.color||(t.color="transparent"),"string"!=typeof t.color&&isNaN(t.color)){var q;if("number"==typeof t.color[0]&&t.color.length>this.counts.length){var G=t.color.length;q=u.mallocUint8(G);for(var Y=(t.color.subarray||t.color.slice).bind(t.color),W=0;W<G;W+=4)q.set(l(Y(W,W+4),"uint8"),W)}else{var X=t.color.length;q=u.mallocUint8(4*X);for(var Z=0;Z<X;Z++)q.set(l(t.color[Z]||0,"uint8"),4*Z)}this.color=q}else this.color=l(t.color,"uint8");if(t.position||t.text||t.color||t.baseline||t.align||t.font||t.offset||t.opacity)if(this.color.length>4||this.baselineOffset.length>1||this.align&&this.align.length>1||this.fontAtlas.length>1||this.positionOffset.length>2){var J=Math.max(.5*this.position.length||0,.25*this.color.length||0,this.baselineOffset.length||0,this.alignOffset.length||0,this.font.length||0,this.opacity.length||0,.5*this.positionOffset.length||0);this.batch=Array(J);for(var K=0;K<this.batch.length;K++)this.batch[K]={count:this.counts.length>1?this.counts[K]:this.counts[0],offset:this.textOffsets.length>1?this.textOffsets[K]:this.textOffsets[0],color:this.color?this.color.length<=4?this.color:this.color.subarray(4*K,4*K+4):[0,0,0,255],opacity:Array.isArray(this.opacity)?this.opacity[K]:this.opacity,baseline:null!=this.baselineOffset[K]?this.baselineOffset[K]:this.baselineOffset[0],align:this.align?null!=this.alignOffset[K]?this.alignOffset[K]:this.alignOffset[0]:0,atlas:this.fontAtlas[K]||this.fontAtlas[0],positionOffset:this.positionOffset.length>2?this.positionOffset.subarray(2*K,2*K+2):this.positionOffset}}else this.count?this.batch=[{count:this.count,offset:0,color:this.color||[0,0,0,255],opacity:Array.isArray(this.opacity)?this.opacity[0]:this.opacity,baseline:this.baselineOffset[0],align:this.alignOffset?this.alignOffset[0]:0,atlas:this.fontAtlas[0],positionOffset:this.positionOffset}]:this.batch=[]},T.prototype.destroy=function(){},T.prototype.kerning=!0,T.prototype.position={constant:new Float32Array(2)},T.prototype.translate=null,T.prototype.scale=null,T.prototype.font=null,T.prototype.text="",T.prototype.positionOffset=[0,0],T.prototype.opacity=1,T.prototype.color=new Uint8Array([0,0,0,255]),T.prototype.alignOffset=[0,0],T.maxAtlasSize=1024,T.atlasCanvas=document.createElement("canvas"),T.atlasContext=T.atlasCanvas.getContext("2d",{alpha:!1}),T.baseFontSize=64,T.fonts={},e.exports=T},{"bit-twiddle":81,"color-normalize":89,"css-font":99,"detect-kerning":125,"es6-weak-map":183,"flatten-vertex-data":191,"font-atlas":192,"font-measure":193,"gl-util/context":226,"is-plain-obj":236,"object-assign":247,"parse-rect":249,"parse-unit":251,"pick-by-alias":253,regl:283,"to-px":314,"typedarray-pool":327}],226:[function(t,e,r){(function(r){(function(){"use strict";var n=t("pick-by-alias");function i(t){if(t.container)if(t.container==document.body)document.body.style.width||(t.canvas.width=t.width||t.pixelRatio*r.innerWidth),document.body.style.height||(t.canvas.height=t.height||t.pixelRatio*r.innerHeight);else{var e=t.container.getBoundingClientRect();t.canvas.width=t.width||e.right-e.left,t.canvas.height=t.height||e.bottom-e.top}}function a(t){return"function"==typeof t.getContext&&"width"in t&&"height"in t}function o(){var t=document.createElement("canvas");return t.style.position="absolute",t.style.top=0,t.style.left=0,t}e.exports=function(t){var e;if(t?"string"==typeof t&&(t={container:t}):t={},a(t)?t={container:t}:t="string"==typeof(e=t).nodeName&&"function"==typeof e.appendChild&&"function"==typeof e.getBoundingClientRect?{container:t}:function(t){return"function"==typeof t.drawArrays||"function"==typeof t.drawElements}(t)?{gl:t}:n(t,{container:"container target element el canvas holder parent parentNode wrapper use ref root node",gl:"gl context webgl glContext",attrs:"attributes attrs contextAttributes",pixelRatio:"pixelRatio pxRatio px ratio pxratio pixelratio",width:"w width",height:"h height"},!0),t.pixelRatio||(t.pixelRatio=r.pixelRatio||1),t.gl)return t.gl;if(t.canvas&&(t.container=t.canvas.parentNode),t.container){if("string"==typeof t.container){var s=document.querySelector(t.container);if(!s)throw Error("Element "+t.container+" is not found");t.container=s}a(t.container)?(t.canvas=t.container,t.container=t.canvas.parentNode):t.canvas||(t.canvas=o(),t.container.appendChild(t.canvas),i(t))}else if(!t.canvas){if("undefined"==typeof document)throw Error("Not DOM environment. Use headless-gl.");t.container=document.body||document.documentElement,t.canvas=o(),t.container.appendChild(t.canvas),i(t)}return t.gl||["webgl","experimental-webgl","webgl-experimental"].some((function(e){try{t.gl=t.canvas.getContext(e,t.attrs)}catch(t){}return t.gl})),t.gl}}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"pick-by-alias":253}],227:[function(t,e,r){e.exports=function(t){"string"==typeof t&&(t=[t]);for(var e=[].slice.call(arguments,1),r=[],n=0;n<t.length-1;n++)r.push(t[n],e[n]||"");return r.push(t[n]),r.join("")}},{}],228:[function(t,e,r){(function(r){(function(){"use strict";var n,i=t("is-browser");n="function"==typeof r.matchMedia?!r.matchMedia("(hover: none)").matches:i,e.exports=n}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"is-browser":232}],229:[function(t,e,r){"use strict";var n=t("is-browser");e.exports=n&&function(){var t=!1;try{var e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("test",null,e),window.removeEventListener("test",null,e)}catch(e){t=!1}return t}()},{"is-browser":232}],230:[function(t,e,r){r.read=function(t,e,r,n,i){var a,o,s=8*i-n-1,l=(1<<s)-1,c=l>>1,u=-7,f=r?i-1:0,h=r?-1:1,p=t[e+f];for(f+=h,a=p&(1<<-u)-1,p>>=-u,u+=s;u>0;a=256*a+t[e+f],f+=h,u-=8);for(o=a&(1<<-u)-1,a>>=-u,u+=n;u>0;o=256*o+t[e+f],f+=h,u-=8);if(0===a)a=1-c;else{if(a===l)return o?NaN:1/0*(p?-1:1);o+=Math.pow(2,n),a-=c}return(p?-1:1)*o*Math.pow(2,a-n)},r.write=function(t,e,r,n,i,a){var o,s,l,c=8*a-i-1,u=(1<<c)-1,f=u>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:a-1,d=n?1:-1,m=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,o=u):(o=Math.floor(Math.log(e)/Math.LN2),e*(l=Math.pow(2,-o))<1&&(o--,l*=2),(e+=o+f>=1?h/l:h*Math.pow(2,1-f))*l>=2&&(o++,l/=2),o+f>=u?(s=0,o=u):o+f>=1?(s=(e*l-1)*Math.pow(2,i),o+=f):(s=e*Math.pow(2,f-1)*Math.pow(2,i),o=0));i>=8;t[r+p]=255&s,p+=d,s/=256,i-=8);for(o=o<<i|s,c+=i;c>0;t[r+p]=255&o,p+=d,o/=256,c-=8);t[r+p-d]|=128*m}},{}],231:[function(t,e,r){"function"==typeof Object.create?e.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:e.exports=function(t,e){if(e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}}},{}],232:[function(t,e,r){e.exports=!0},{}],233:[function(t,e,r){"use strict";e.exports="undefined"!=typeof navigator&&(/MSIE/.test(navigator.userAgent)||/Trident\//.test(navigator.appVersion))},{}],234:[function(t,e,r){"use strict";e.exports=a,e.exports.isMobile=a,e.exports.default=a;var n=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series[46]0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i,i=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series[46]0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|android|ipad|playbook|silk/i;function a(t){t||(t={});var e=t.ua;if(e||"undefined"==typeof navigator||(e=navigator.userAgent),e&&e.headers&&"string"==typeof e.headers["user-agent"]&&(e=e.headers["user-agent"]),"string"!=typeof e)return!1;var r=t.tablet?i.test(e):n.test(e);return!r&&t.tablet&&t.featureDetect&&navigator&&navigator.maxTouchPoints>1&&-1!==e.indexOf("Macintosh")&&-1!==e.indexOf("Safari")&&(r=!0),r}},{}],235:[function(t,e,r){"use strict";e.exports=function(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}},{}],236:[function(t,e,r){"use strict";var n=Object.prototype.toString;e.exports=function(t){var e;return"[object Object]"===n.call(t)&&(null===(e=Object.getPrototypeOf(t))||e===Object.getPrototypeOf({}))}},{}],237:[function(t,e,r){"use strict";e.exports=function(t){for(var e,r=t.length,n=0;n<r;n++)if(((e=t.charCodeAt(n))<9||e>13)&&32!==e&&133!==e&&160!==e&&5760!==e&&6158!==e&&(e<8192||e>8205)&&8232!==e&&8233!==e&&8239!==e&&8287!==e&&8288!==e&&12288!==e&&65279!==e)return!1;return!0}},{}],238:[function(t,e,r){"use strict";e.exports=function(t){return"string"==typeof t&&(t=t.trim(),!!(/^[mzlhvcsqta]\s*[-+.0-9][^mlhvzcsqta]+/i.test(t)&&/[\dz]$/i.test(t)&&t.length>4))}},{}],239:[function(t,e,r){!function(t,n){"object"==typeof r&&void 0!==e?e.exports=n():(t=t||self).mapboxgl=n()}(this,(function(){"use strict";var t,e,r;function n(n,i){if(t)if(e){var a="var sharedChunk = {}; ("+t+")(sharedChunk); ("+e+")(sharedChunk);",o={};t(o),(r=i(o)).workerUrl=window.URL.createObjectURL(new Blob([a],{type:"text/javascript"}))}else e=i;else t=i}return n(0,(function(t){function e(t,e){return t(e={exports:{}},e.exports),e.exports}var r=n;function n(t,e,r,n){this.cx=3*t,this.bx=3*(r-t)-this.cx,this.ax=1-this.cx-this.bx,this.cy=3*e,this.by=3*(n-e)-this.cy,this.ay=1-this.cy-this.by,this.p1x=t,this.p1y=n,this.p2x=r,this.p2y=n}n.prototype.sampleCurveX=function(t){return((this.ax*t+this.bx)*t+this.cx)*t},n.prototype.sampleCurveY=function(t){return((this.ay*t+this.by)*t+this.cy)*t},n.prototype.sampleCurveDerivativeX=function(t){return(3*this.ax*t+2*this.bx)*t+this.cx},n.prototype.solveCurveX=function(t,e){var r,n,i,a,o;for(void 0===e&&(e=1e-6),i=t,o=0;o<8;o++){if(a=this.sampleCurveX(i)-t,Math.abs(a)<e)return i;var s=this.sampleCurveDerivativeX(i);if(Math.abs(s)<1e-6)break;i-=a/s}if((i=t)<(r=0))return r;if(i>(n=1))return n;for(;r<n;){if(a=this.sampleCurveX(i),Math.abs(a-t)<e)return i;t>a?r=i:n=i,i=.5*(n-r)+r}return i},n.prototype.solve=function(t,e){return this.sampleCurveY(this.solveCurveX(t,e))};var i=a;function a(t,e){this.x=t,this.y=e}function o(t,e,n,i){var a=new r(t,e,n,i);return function(t){return a.solve(t)}}a.prototype={clone:function(){return new a(this.x,this.y)},add:function(t){return this.clone()._add(t)},sub:function(t){return this.clone()._sub(t)},multByPoint:function(t){return this.clone()._multByPoint(t)},divByPoint:function(t){return this.clone()._divByPoint(t)},mult:function(t){return this.clone()._mult(t)},div:function(t){return this.clone()._div(t)},rotate:function(t){return this.clone()._rotate(t)},rotateAround:function(t,e){return this.clone()._rotateAround(t,e)},matMult:function(t){return this.clone()._matMult(t)},unit:function(){return this.clone()._unit()},perp:function(){return this.clone()._perp()},round:function(){return this.clone()._round()},mag:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals:function(t){return this.x===t.x&&this.y===t.y},dist:function(t){return Math.sqrt(this.distSqr(t))},distSqr:function(t){var e=t.x-this.x,r=t.y-this.y;return e*e+r*r},angle:function(){return Math.atan2(this.y,this.x)},angleTo:function(t){return Math.atan2(this.y-t.y,this.x-t.x)},angleWith:function(t){return this.angleWithSep(t.x,t.y)},angleWithSep:function(t,e){return Math.atan2(this.x*e-this.y*t,this.x*t+this.y*e)},_matMult:function(t){var e=t[0]*this.x+t[1]*this.y,r=t[2]*this.x+t[3]*this.y;return this.x=e,this.y=r,this},_add:function(t){return this.x+=t.x,this.y+=t.y,this},_sub:function(t){return this.x-=t.x,this.y-=t.y,this},_mult:function(t){return this.x*=t,this.y*=t,this},_div:function(t){return this.x/=t,this.y/=t,this},_multByPoint:function(t){return this.x*=t.x,this.y*=t.y,this},_divByPoint:function(t){return this.x/=t.x,this.y/=t.y,this},_unit:function(){return this._div(this.mag()),this},_perp:function(){var t=this.y;return this.y=this.x,this.x=-t,this},_rotate:function(t){var e=Math.cos(t),r=Math.sin(t),n=e*this.x-r*this.y,i=r*this.x+e*this.y;return this.x=n,this.y=i,this},_rotateAround:function(t,e){var r=Math.cos(t),n=Math.sin(t),i=e.x+r*(this.x-e.x)-n*(this.y-e.y),a=e.y+n*(this.x-e.x)+r*(this.y-e.y);return this.x=i,this.y=a,this},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}},a.convert=function(t){return t instanceof a?t:Array.isArray(t)?new a(t[0],t[1]):t};var s=o(.25,.1,.25,1);function l(t,e,r){return Math.min(r,Math.max(e,t))}function c(t,e,r){var n=r-e,i=((t-e)%n+n)%n+e;return i===e?r:i}function u(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];for(var n=0,i=e;n<i.length;n+=1){var a=i[n];for(var o in a)t[o]=a[o]}return t}var f=1;function h(){return f++}function p(){return function t(e){return e?(e^16*Math.random()>>e/4).toString(16):([1e7]+-[1e3]+-4e3+-8e3+-1e11).replace(/[018]/g,t)}()}function d(t){return!!t&&/^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(t)}function m(t,e){t.forEach((function(t){e[t]&&(e[t]=e[t].bind(e))}))}function g(t,e){return-1!==t.indexOf(e,t.length-e.length)}function v(t,e,r){var n={};for(var i in t)n[i]=e.call(r||this,t[i],i,t);return n}function y(t,e,r){var n={};for(var i in t)e.call(r||this,t[i],i,t)&&(n[i]=t[i]);return n}function x(t){return Array.isArray(t)?t.map(x):"object"==typeof t&&t?v(t,x):t}var b={};function _(t){b[t]||("undefined"!=typeof console&&console.warn(t),b[t]=!0)}function w(t,e,r){return(r.y-t.y)*(e.x-t.x)>(e.y-t.y)*(r.x-t.x)}function T(t){for(var e=0,r=0,n=t.length,i=n-1,a=void 0,o=void 0;r<n;i=r++)a=t[r],e+=((o=t[i]).x-a.x)*(a.y+o.y);return e}function k(){return"undefined"!=typeof WorkerGlobalScope&&"undefined"!=typeof self&&self instanceof WorkerGlobalScope}function A(t){var e={};if(t.replace(/(?:^|(?:\s*\,\s*))([^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)(?:\=(?:([^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)|(?:\"((?:[^"\\]|\\.)*)\")))?/g,(function(t,r,n,i){var a=n||i;return e[r]=!a||a.toLowerCase(),""})),e["max-age"]){var r=parseInt(e["max-age"],10);isNaN(r)?delete e["max-age"]:e["max-age"]=r}return e}var M=null;function S(t){if(null==M){var e=t.navigator?t.navigator.userAgent:null;M=!!t.safari||!(!e||!(/\b(iPad|iPhone|iPod)\b/.test(e)||e.match("Safari")&&!e.match("Chrome")))}return M}function E(t){try{var e=self[t];return e.setItem("_mapbox_test_",1),e.removeItem("_mapbox_test_"),!0}catch(t){return!1}}var L,C,P,I,O=self.performance&&self.performance.now?self.performance.now.bind(self.performance):Date.now.bind(Date),z=self.requestAnimationFrame||self.mozRequestAnimationFrame||self.webkitRequestAnimationFrame||self.msRequestAnimationFrame,D=self.cancelAnimationFrame||self.mozCancelAnimationFrame||self.webkitCancelAnimationFrame||self.msCancelAnimationFrame,R={now:O,frame:function(t){var e=z(t);return{cancel:function(){return D(e)}}},getImageData:function(t,e){void 0===e&&(e=0);var r=self.document.createElement("canvas"),n=r.getContext("2d");if(!n)throw new Error("failed to create canvas 2d context");return r.width=t.width,r.height=t.height,n.drawImage(t,0,0,t.width,t.height),n.getImageData(-e,-e,t.width+2*e,t.height+2*e)},resolveURL:function(t){return L||(L=self.document.createElement("a")),L.href=t,L.href},hardwareConcurrency:self.navigator.hardwareConcurrency||4,get devicePixelRatio(){return self.devicePixelRatio},get prefersReducedMotion(){return!!self.matchMedia&&(null==C&&(C=self.matchMedia("(prefers-reduced-motion: reduce)")),C.matches)}},F={API_URL:"https://api.mapbox.com",get EVENTS_URL(){return this.API_URL?0===this.API_URL.indexOf("https://api.mapbox.cn")?"https://events.mapbox.cn/events/v2":0===this.API_URL.indexOf("https://api.mapbox.com")?"https://events.mapbox.com/events/v2":null:null},FEEDBACK_URL:"https://apps.mapbox.com/feedback",REQUIRE_ACCESS_TOKEN:!0,ACCESS_TOKEN:null,MAX_PARALLEL_IMAGE_REQUESTS:16},B={supported:!1,testSupport:function(t){if(N||!I)return;j?U(t):P=t}},N=!1,j=!1;function U(t){var e=t.createTexture();t.bindTexture(t.TEXTURE_2D,e);try{if(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,I),t.isContextLost())return;B.supported=!0}catch(t){}t.deleteTexture(e),N=!0}self.document&&((I=self.document.createElement("img")).onload=function(){P&&U(P),P=null,j=!0},I.onerror=function(){N=!0,P=null},I.src="data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAQAAAAfQ//73v/+BiOh/AAA=");var V="01";var H=function(t,e){this._transformRequestFn=t,this._customAccessToken=e,this._createSkuToken()};function q(t){return 0===t.indexOf("mapbox:")}H.prototype._createSkuToken=function(){var t=function(){for(var t="",e=0;e<10;e++)t+="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(62*Math.random())];return{token:["1",V,t].join(""),tokenExpiresAt:Date.now()+432e5}}();this._skuToken=t.token,this._skuTokenExpiresAt=t.tokenExpiresAt},H.prototype._isSkuTokenExpired=function(){return Date.now()>this._skuTokenExpiresAt},H.prototype.transformRequest=function(t,e){return this._transformRequestFn&&this._transformRequestFn(t,e)||{url:t}},H.prototype.normalizeStyleURL=function(t,e){if(!q(t))return t;var r=X(t);return r.path="/styles/v1"+r.path,this._makeAPIURL(r,this._customAccessToken||e)},H.prototype.normalizeGlyphsURL=function(t,e){if(!q(t))return t;var r=X(t);return r.path="/fonts/v1"+r.path,this._makeAPIURL(r,this._customAccessToken||e)},H.prototype.normalizeSourceURL=function(t,e){if(!q(t))return t;var r=X(t);return r.path="/v4/"+r.authority+".json",r.params.push("secure"),this._makeAPIURL(r,this._customAccessToken||e)},H.prototype.normalizeSpriteURL=function(t,e,r,n){var i=X(t);return q(t)?(i.path="/styles/v1"+i.path+"/sprite"+e+r,this._makeAPIURL(i,this._customAccessToken||n)):(i.path+=""+e+r,Z(i))},H.prototype.normalizeTileURL=function(t,e){if(this._isSkuTokenExpired()&&this._createSkuToken(),t&&!q(t))return t;var r=X(t),n=R.devicePixelRatio>=2||512===e?"@2x":"",i=B.supported?".webp":"$1";r.path=r.path.replace(/(\.(png|jpg)\d*)(?=$)/,""+n+i),r.path=r.path.replace(/^.+\/v4\//,"/"),r.path="/v4"+r.path;var a=this._customAccessToken||function(t){for(var e=0,r=t;e<r.length;e+=1){var n=r[e].match(/^access_token=(.*)$/);if(n)return n[1]}return null}(r.params)||F.ACCESS_TOKEN;return F.REQUIRE_ACCESS_TOKEN&&a&&this._skuToken&&r.params.push("sku="+this._skuToken),this._makeAPIURL(r,a)},H.prototype.canonicalizeTileURL=function(t,e){var r=X(t);if(!r.path.match(/(^\/v4\/)/)||!r.path.match(/\.[\w]+$/))return t;var n="mapbox://tiles/";n+=r.path.replace("/v4/","");var i=r.params;return e&&(i=i.filter((function(t){return!t.match(/^access_token=/)}))),i.length&&(n+="?"+i.join("&")),n},H.prototype.canonicalizeTileset=function(t,e){for(var r=!!e&&q(e),n=[],i=0,a=t.tiles||[];i<a.length;i+=1){var o=a[i];Y(o)?n.push(this.canonicalizeTileURL(o,r)):n.push(o)}return n},H.prototype._makeAPIURL=function(t,e){var r="See https://www.mapbox.com/api-documentation/#access-tokens-and-token-scopes",n=X(F.API_URL);if(t.protocol=n.protocol,t.authority=n.authority,"/"!==n.path&&(t.path=""+n.path+t.path),!F.REQUIRE_ACCESS_TOKEN)return Z(t);if(!(e=e||F.ACCESS_TOKEN))throw new Error("An API access token is required to use Mapbox GL. "+r);if("s"===e[0])throw new Error("Use a public access token (pk.*) with Mapbox GL, not a secret access token (sk.*). "+r);return t.params=t.params.filter((function(t){return-1===t.indexOf("access_token")})),t.params.push("access_token="+e),Z(t)};var G=/^((https?:)?\/\/)?([^\/]+\.)?mapbox\.c(n|om)(\/|\?|$)/i;function Y(t){return G.test(t)}var W=/^(\w+):\/\/([^/?]*)(\/[^?]+)?\??(.+)?/;function X(t){var e=t.match(W);if(!e)throw new Error("Unable to parse URL object");return{protocol:e[1],authority:e[2],path:e[3]||"/",params:e[4]?e[4].split("&"):[]}}function Z(t){var e=t.params.length?"?"+t.params.join("&"):"";return t.protocol+"://"+t.authority+t.path+e}function J(t){if(!t)return null;var e,r=t.split(".");if(!r||3!==r.length)return null;try{return JSON.parse((e=r[1],decodeURIComponent(self.atob(e).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join(""))))}catch(t){return null}}var K=function(t){this.type=t,this.anonId=null,this.eventData={},this.queue=[],this.pendingRequest=null};K.prototype.getStorageKey=function(t){var e,r=J(F.ACCESS_TOKEN),n="";return r&&r.u?(e=r.u,n=self.btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(t,e){return String.fromCharCode(Number("0x"+e))})))):n=F.ACCESS_TOKEN||"",t?"mapbox.eventData."+t+":"+n:"mapbox.eventData:"+n},K.prototype.fetchEventData=function(){var t=E("localStorage"),e=this.getStorageKey(),r=this.getStorageKey("uuid");if(t)try{var n=self.localStorage.getItem(e);n&&(this.eventData=JSON.parse(n));var i=self.localStorage.getItem(r);i&&(this.anonId=i)}catch(t){_("Unable to read from LocalStorage")}},K.prototype.saveEventData=function(){var t=E("localStorage"),e=this.getStorageKey(),r=this.getStorageKey("uuid");if(t)try{self.localStorage.setItem(r,this.anonId),Object.keys(this.eventData).length>=1&&self.localStorage.setItem(e,JSON.stringify(this.eventData))}catch(t){_("Unable to write to LocalStorage")}},K.prototype.processRequests=function(t){},K.prototype.postEvent=function(t,e,r,n){var i=this;if(F.EVENTS_URL){var a=X(F.EVENTS_URL);a.params.push("access_token="+(n||F.ACCESS_TOKEN||""));var o={event:this.type,created:new Date(t).toISOString(),sdkIdentifier:"mapbox-gl-js",sdkVersion:"1.10.1",skuId:V,userId:this.anonId},s=e?u(o,e):o,l={url:Z(a),headers:{"Content-Type":"text/plain"},body:JSON.stringify([s])};this.pendingRequest=bt(l,(function(t){i.pendingRequest=null,r(t),i.saveEventData(),i.processRequests(n)}))}},K.prototype.queueRequest=function(t,e){this.queue.push(t),this.processRequests(e)};var Q,$,tt=function(t){function e(){t.call(this,"map.load"),this.success={},this.skuToken=""}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.postMapLoadEvent=function(t,e,r,n){this.skuToken=r,(F.EVENTS_URL&&n||F.ACCESS_TOKEN&&Array.isArray(t)&&t.some((function(t){return q(t)||Y(t)})))&&this.queueRequest({id:e,timestamp:Date.now()},n)},e.prototype.processRequests=function(t){var e=this;if(!this.pendingRequest&&0!==this.queue.length){var r=this.queue.shift(),n=r.id,i=r.timestamp;n&&this.success[n]||(this.anonId||this.fetchEventData(),d(this.anonId)||(this.anonId=p()),this.postEvent(i,{skuToken:this.skuToken},(function(t){t||n&&(e.success[n]=!0)}),t))}},e}(K),et=new(function(t){function e(e){t.call(this,"appUserTurnstile"),this._customAccessToken=e}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.postTurnstileEvent=function(t,e){F.EVENTS_URL&&F.ACCESS_TOKEN&&Array.isArray(t)&&t.some((function(t){return q(t)||Y(t)}))&&this.queueRequest(Date.now(),e)},e.prototype.processRequests=function(t){var e=this;if(!this.pendingRequest&&0!==this.queue.length){this.anonId&&this.eventData.lastSuccess&&this.eventData.tokenU||this.fetchEventData();var r=J(F.ACCESS_TOKEN),n=r?r.u:F.ACCESS_TOKEN,i=n!==this.eventData.tokenU;d(this.anonId)||(this.anonId=p(),i=!0);var a=this.queue.shift();if(this.eventData.lastSuccess){var o=new Date(this.eventData.lastSuccess),s=new Date(a),l=(a-this.eventData.lastSuccess)/864e5;i=i||l>=1||l<-1||o.getDate()!==s.getDate()}else i=!0;if(!i)return this.processRequests();this.postEvent(a,{"enabled.telemetry":!1},(function(t){t||(e.eventData.lastSuccess=a,e.eventData.tokenU=n)}),t)}},e}(K)),rt=et.postTurnstileEvent.bind(et),nt=new tt,it=nt.postMapLoadEvent.bind(nt),at=500,ot=50;function st(){self.caches&&!Q&&(Q=self.caches.open("mapbox-tiles"))}function lt(t,e,r){if(st(),Q){var n={status:e.status,statusText:e.statusText,headers:new self.Headers};e.headers.forEach((function(t,e){return n.headers.set(e,t)}));var i=A(e.headers.get("Cache-Control")||"");if(!i["no-store"])i["max-age"]&&n.headers.set("Expires",new Date(r+1e3*i["max-age"]).toUTCString()),new Date(n.headers.get("Expires")).getTime()-r<42e4||function(t,e){if(void 0===$)try{new Response(new ReadableStream),$=!0}catch(t){$=!1}$?e(t.body):t.blob().then(e)}(e,(function(e){var r=new self.Response(e,n);st(),Q&&Q.then((function(e){return e.put(ct(t.url),r)})).catch((function(t){return _(t.message)}))}))}}function ct(t){var e=t.indexOf("?");return e<0?t:t.slice(0,e)}function ut(t,e){if(st(),!Q)return e(null);var r=ct(t.url);Q.then((function(t){t.match(r).then((function(n){var i=function(t){if(!t)return!1;var e=new Date(t.headers.get("Expires")||0),r=A(t.headers.get("Cache-Control")||"");return e>Date.now()&&!r["no-cache"]}(n);t.delete(r),i&&t.put(r,n.clone()),e(null,n,i)})).catch(e)})).catch(e)}var ft,ht=1/0;function pt(){return null==ft&&(ft=self.OffscreenCanvas&&new self.OffscreenCanvas(1,1).getContext("2d")&&"function"==typeof self.createImageBitmap),ft}var dt={Unknown:"Unknown",Style:"Style",Source:"Source",Tile:"Tile",Glyphs:"Glyphs",SpriteImage:"SpriteImage",SpriteJSON:"SpriteJSON",Image:"Image"};"function"==typeof Object.freeze&&Object.freeze(dt);var mt=function(t){function e(e,r,n){401===r&&Y(n)&&(e+=": you may have provided an invalid Mapbox access token. See https://www.mapbox.com/api-documentation/#access-tokens-and-token-scopes"),t.call(this,e),this.status=r,this.url=n,this.name=this.constructor.name,this.message=e}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.toString=function(){return this.name+": "+this.message+" ("+this.status+"): "+this.url},e}(Error),gt=k()?function(){return self.worker&&self.worker.referrer}:function(){return("blob:"===self.location.protocol?self.parent:self).location.href};function vt(t,e){var r,n=new self.AbortController,i=new self.Request(t.url,{method:t.method||"GET",body:t.body,credentials:t.credentials,headers:t.headers,referrer:gt(),signal:n.signal}),a=!1,o=!1,s=(r=i.url).indexOf("sku=")>0&&Y(r);"json"===t.type&&i.headers.set("Accept","application/json");var l=function(r,n,a){if(!o){if(r&&"SecurityError"!==r.message&&_(r),n&&a)return c(n);var l=Date.now();self.fetch(i).then((function(r){if(r.ok){var n=s?r.clone():null;return c(r,n,l)}return e(new mt(r.statusText,r.status,t.url))})).catch((function(t){20!==t.code&&e(new Error(t.message))}))}},c=function(r,n,s){("arrayBuffer"===t.type?r.arrayBuffer():"json"===t.type?r.json():r.text()).then((function(t){o||(n&&s&&lt(i,n,s),a=!0,e(null,t,r.headers.get("Cache-Control"),r.headers.get("Expires")))})).catch((function(t){o||e(new Error(t.message))}))};return s?ut(i,l):l(null,null),{cancel:function(){o=!0,a||n.abort()}}}var yt=function(t,e){if(r=t.url,!(/^file:/.test(r)||/^file:/.test(gt())&&!/^\w+:/.test(r))){if(self.fetch&&self.Request&&self.AbortController&&self.Request.prototype.hasOwnProperty("signal"))return vt(t,e);if(k()&&self.worker&&self.worker.actor){return self.worker.actor.send("getResource",t,e,void 0,!0)}}var r;return function(t,e){var r=new self.XMLHttpRequest;for(var n in r.open(t.method||"GET",t.url,!0),"arrayBuffer"===t.type&&(r.responseType="arraybuffer"),t.headers)r.setRequestHeader(n,t.headers[n]);return"json"===t.type&&(r.responseType="text",r.setRequestHeader("Accept","application/json")),r.withCredentials="include"===t.credentials,r.onerror=function(){e(new Error(r.statusText))},r.onload=function(){if((r.status>=200&&r.status<300||0===r.status)&&null!==r.response){var n=r.response;if("json"===t.type)try{n=JSON.parse(r.response)}catch(t){return e(t)}e(null,n,r.getResponseHeader("Cache-Control"),r.getResponseHeader("Expires"))}else e(new mt(r.statusText,r.status,t.url))},r.send(t.body),{cancel:function(){return r.abort()}}}(t,e)},xt=function(t,e){return yt(u(t,{type:"arrayBuffer"}),e)},bt=function(t,e){return yt(u(t,{method:"POST"}),e)};var _t,wt;_t=[],wt=0;var Tt=function(t,e){if(B.supported&&(t.headers||(t.headers={}),t.headers.accept="image/webp,*/*"),wt>=F.MAX_PARALLEL_IMAGE_REQUESTS){var r={requestParameters:t,callback:e,cancelled:!1,cancel:function(){this.cancelled=!0}};return _t.push(r),r}wt++;var n=!1,i=function(){if(!n)for(n=!0,wt--;_t.length&&wt<F.MAX_PARALLEL_IMAGE_REQUESTS;){var t=_t.shift(),e=t.requestParameters,r=t.callback;t.cancelled||(t.cancel=Tt(e,r).cancel)}},a=xt(t,(function(t,r,n,a){i(),t?e(t):r&&(pt()?function(t,e){var r=new self.Blob([new Uint8Array(t)],{type:"image/png"});self.createImageBitmap(r).then((function(t){e(null,t)})).catch((function(t){e(new Error("Could not load image because of "+t.message+". Please make sure to use a supported image type such as PNG or JPEG. Note that SVGs are not supported."))}))}(r,e):function(t,e,r,n){var i=new self.Image,a=self.URL;i.onload=function(){e(null,i),a.revokeObjectURL(i.src)},i.onerror=function(){return e(new Error("Could not load image. Please make sure to use a supported image type such as PNG or JPEG. Note that SVGs are not supported."))};var o=new self.Blob([new Uint8Array(t)],{type:"image/png"});i.cacheControl=r,i.expires=n,i.src=t.byteLength?a.createObjectURL(o):"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAUAAarVyFEAAAAASUVORK5CYII="}(r,e,n,a))}));return{cancel:function(){a.cancel(),i()}}};function kt(t,e,r){r[t]&&-1!==r[t].indexOf(e)||(r[t]=r[t]||[],r[t].push(e))}function At(t,e,r){if(r&&r[t]){var n=r[t].indexOf(e);-1!==n&&r[t].splice(n,1)}}var Mt=function(t,e){void 0===e&&(e={}),u(this,e),this.type=t},St=function(t){function e(e,r){void 0===r&&(r={}),t.call(this,"error",u({error:e},r))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Mt),Et=function(){};Et.prototype.on=function(t,e){return this._listeners=this._listeners||{},kt(t,e,this._listeners),this},Et.prototype.off=function(t,e){return At(t,e,this._listeners),At(t,e,this._oneTimeListeners),this},Et.prototype.once=function(t,e){return this._oneTimeListeners=this._oneTimeListeners||{},kt(t,e,this._oneTimeListeners),this},Et.prototype.fire=function(t,e){"string"==typeof t&&(t=new Mt(t,e||{}));var r=t.type;if(this.listens(r)){t.target=this;for(var n=0,i=this._listeners&&this._listeners[r]?this._listeners[r].slice():[];n<i.length;n+=1){i[n].call(this,t)}for(var a=0,o=this._oneTimeListeners&&this._oneTimeListeners[r]?this._oneTimeListeners[r].slice():[];a<o.length;a+=1){var s=o[a];At(r,s,this._oneTimeListeners),s.call(this,t)}var l=this._eventedParent;l&&(u(t,"function"==typeof this._eventedParentData?this._eventedParentData():this._eventedParentData),l.fire(t))}else t instanceof St&&console.error(t.error);return this},Et.prototype.listens=function(t){return this._listeners&&this._listeners[t]&&this._listeners[t].length>0||this._oneTimeListeners&&this._oneTimeListeners[t]&&this._oneTimeListeners[t].length>0||this._eventedParent&&this._eventedParent.listens(t)},Et.prototype.setEventedParent=function(t,e){return this._eventedParent=t,this._eventedParentData=e,this};var Lt={$version:8,$root:{version:{required:!0,type:"enum",values:[8]},name:{type:"string"},metadata:{type:"*"},center:{type:"array",value:"number"},zoom:{type:"number"},bearing:{type:"number",default:0,period:360,units:"degrees"},pitch:{type:"number",default:0,units:"degrees"},light:{type:"light"},sources:{required:!0,type:"sources"},sprite:{type:"string"},glyphs:{type:"string"},transition:{type:"transition"},layers:{required:!0,type:"array",value:"layer"}},sources:{"*":{type:"source"}},source:["source_vector","source_raster","source_raster_dem","source_geojson","source_video","source_image"],source_vector:{type:{required:!0,type:"enum",values:{vector:{}}},url:{type:"string"},tiles:{type:"array",value:"string"},bounds:{type:"array",value:"number",length:4,default:[-180,-85.051129,180,85.051129]},scheme:{type:"enum",values:{xyz:{},tms:{}},default:"xyz"},minzoom:{type:"number",default:0},maxzoom:{type:"number",default:22},attribution:{type:"string"},promoteId:{type:"promoteId"},"*":{type:"*"}},source_raster:{type:{required:!0,type:"enum",values:{raster:{}}},url:{type:"string"},tiles:{type:"array",value:"string"},bounds:{type:"array",value:"number",length:4,default:[-180,-85.051129,180,85.051129]},minzoom:{type:"number",default:0},maxzoom:{type:"number",default:22},tileSize:{type:"number",default:512,units:"pixels"},scheme:{type:"enum",values:{xyz:{},tms:{}},default:"xyz"},attribution:{type:"string"},"*":{type:"*"}},source_raster_dem:{type:{required:!0,type:"enum",values:{"raster-dem":{}}},url:{type:"string"},tiles:{type:"array",value:"string"},bounds:{type:"array",value:"number",length:4,default:[-180,-85.051129,180,85.051129]},minzoom:{type:"number",default:0},maxzoom:{type:"number",default:22},tileSize:{type:"number",default:512,units:"pixels"},attribution:{type:"string"},encoding:{type:"enum",values:{terrarium:{},mapbox:{}},default:"mapbox"},"*":{type:"*"}},source_geojson:{type:{required:!0,type:"enum",values:{geojson:{}}},data:{type:"*"},maxzoom:{type:"number",default:18},attribution:{type:"string"},buffer:{type:"number",default:128,maximum:512,minimum:0},tolerance:{type:"number",default:.375},cluster:{type:"boolean",default:!1},clusterRadius:{type:"number",default:50,minimum:0},clusterMaxZoom:{type:"number"},clusterProperties:{type:"*"},lineMetrics:{type:"boolean",default:!1},generateId:{type:"boolean",default:!1},promoteId:{type:"promoteId"}},source_video:{type:{required:!0,type:"enum",values:{video:{}}},urls:{required:!0,type:"array",value:"string"},coordinates:{required:!0,type:"array",length:4,value:{type:"array",length:2,value:"number"}}},source_image:{type:{required:!0,type:"enum",values:{image:{}}},url:{required:!0,type:"string"},coordinates:{required:!0,type:"array",length:4,value:{type:"array",length:2,value:"number"}}},layer:{id:{type:"string",required:!0},type:{type:"enum",values:{fill:{},line:{},symbol:{},circle:{},heatmap:{},"fill-extrusion":{},raster:{},hillshade:{},background:{}},required:!0},metadata:{type:"*"},source:{type:"string"},"source-layer":{type:"string"},minzoom:{type:"number",minimum:0,maximum:24},maxzoom:{type:"number",minimum:0,maximum:24},filter:{type:"filter"},layout:{type:"layout"},paint:{type:"paint"}},layout:["layout_fill","layout_line","layout_circle","layout_heatmap","layout_fill-extrusion","layout_symbol","layout_raster","layout_hillshade","layout_background"],layout_background:{visibility:{type:"enum",values:{visible:{},none:{}},default:"visible","property-type":"constant"}},layout_fill:{"fill-sort-key":{type:"number",expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"data-driven"},visibility:{type:"enum",values:{visible:{},none:{}},default:"visible","property-type":"constant"}},layout_circle:{"circle-sort-key":{type:"number",expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"data-driven"},visibility:{type:"enum",values:{visible:{},none:{}},default:"visible","property-type":"constant"}},layout_heatmap:{visibility:{type:"enum",values:{visible:{},none:{}},default:"visible","property-type":"constant"}},"layout_fill-extrusion":{visibility:{type:"enum",values:{visible:{},none:{}},default:"visible","property-type":"constant"}},layout_line:{"line-cap":{type:"enum",values:{butt:{},round:{},square:{}},default:"butt",expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"line-join":{type:"enum",values:{bevel:{},round:{},miter:{}},default:"miter",expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"data-driven"},"line-miter-limit":{type:"number",default:2,requires:[{"line-join":"miter"}],expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"line-round-limit":{type:"number",default:1.05,requires:[{"line-join":"round"}],expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"line-sort-key":{type:"number",expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"data-driven"},visibility:{type:"enum",values:{visible:{},none:{}},default:"visible","property-type":"constant"}},layout_symbol:{"symbol-placement":{type:"enum",values:{point:{},line:{},"line-center":{}},default:"point",expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"symbol-spacing":{type:"number",default:250,minimum:1,units:"pixels",requires:[{"symbol-placement":"line"}],expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"symbol-avoid-edges":{type:"boolean",default:!1,expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"symbol-sort-key":{type:"number",expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"data-driven"},"symbol-z-order":{type:"enum",values:{auto:{},"viewport-y":{},source:{}},default:"auto",expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"icon-allow-overlap":{type:"boolean",default:!1,requires:["icon-image"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"icon-ignore-placement":{type:"boolean",default:!1,requires:["icon-image"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"icon-optional":{type:"boolean",default:!1,requires:["icon-image","text-field"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"icon-rotation-alignment":{type:"enum",values:{map:{},viewport:{},auto:{}},default:"auto",requires:["icon-image"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"icon-size":{type:"number",default:1,minimum:0,units:"factor of the original icon size",requires:["icon-image"],expression:{interpolated:!0,parameters:["zoom","feature"]},"property-type":"data-driven"},"icon-text-fit":{type:"enum",values:{none:{},width:{},height:{},both:{}},default:"none",requires:["icon-image","text-field"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"icon-text-fit-padding":{type:"array",value:"number",length:4,default:[0,0,0,0],units:"pixels",requires:["icon-image","text-field",{"icon-text-fit":["both","width","height"]}],expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"icon-image":{type:"resolvedImage",tokens:!0,expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"data-driven"},"icon-rotate":{type:"number",default:0,period:360,units:"degrees",requires:["icon-image"],expression:{interpolated:!0,parameters:["zoom","feature"]},"property-type":"data-driven"},"icon-padding":{type:"number",default:2,minimum:0,units:"pixels",requires:["icon-image"],expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"icon-keep-upright":{type:"boolean",default:!1,requires:["icon-image",{"icon-rotation-alignment":"map"},{"symbol-placement":["line","line-center"]}],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"icon-offset":{type:"array",value:"number",length:2,default:[0,0],requires:["icon-image"],expression:{interpolated:!0,parameters:["zoom","feature"]},"property-type":"data-driven"},"icon-anchor":{type:"enum",values:{center:{},left:{},right:{},top:{},bottom:{},"top-left":{},"top-right":{},"bottom-left":{},"bottom-right":{}},default:"center",requires:["icon-image"],expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"data-driven"},"icon-pitch-alignment":{type:"enum",values:{map:{},viewport:{},auto:{}},default:"auto",requires:["icon-image"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"text-pitch-alignment":{type:"enum",values:{map:{},viewport:{},auto:{}},default:"auto",requires:["text-field"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"text-rotation-alignment":{type:"enum",values:{map:{},viewport:{},auto:{}},default:"auto",requires:["text-field"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"text-field":{type:"formatted",default:"",tokens:!0,expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"data-driven"},"text-font":{type:"array",value:"string",default:["Open Sans Regular","Arial Unicode MS Regular"],requires:["text-field"],expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"data-driven"},"text-size":{type:"number",default:16,minimum:0,units:"pixels",requires:["text-field"],expression:{interpolated:!0,parameters:["zoom","feature"]},"property-type":"data-driven"},"text-max-width":{type:"number",default:10,minimum:0,units:"ems",requires:["text-field"],expression:{interpolated:!0,parameters:["zoom","feature"]},"property-type":"data-driven"},"text-line-height":{type:"number",default:1.2,units:"ems",requires:["text-field"],expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"text-letter-spacing":{type:"number",default:0,units:"ems",requires:["text-field"],expression:{interpolated:!0,parameters:["zoom","feature"]},"property-type":"data-driven"},"text-justify":{type:"enum",values:{auto:{},left:{},center:{},right:{}},default:"center",requires:["text-field"],expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"data-driven"},"text-radial-offset":{type:"number",units:"ems",default:0,requires:["text-field"],"property-type":"data-driven",expression:{interpolated:!0,parameters:["zoom","feature"]}},"text-variable-anchor":{type:"array",value:"enum",values:{center:{},left:{},right:{},top:{},bottom:{},"top-left":{},"top-right":{},"bottom-left":{},"bottom-right":{}},requires:["text-field",{"symbol-placement":["point"]}],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"text-anchor":{type:"enum",values:{center:{},left:{},right:{},top:{},bottom:{},"top-left":{},"top-right":{},"bottom-left":{},"bottom-right":{}},default:"center",requires:["text-field",{"!":"text-variable-anchor"}],expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"data-driven"},"text-max-angle":{type:"number",default:45,units:"degrees",requires:["text-field",{"symbol-placement":["line","line-center"]}],expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"text-writing-mode":{type:"array",value:"enum",values:{horizontal:{},vertical:{}},requires:["text-field",{"symbol-placement":["point"]}],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"text-rotate":{type:"number",default:0,period:360,units:"degrees",requires:["text-field"],expression:{interpolated:!0,parameters:["zoom","feature"]},"property-type":"data-driven"},"text-padding":{type:"number",default:2,minimum:0,units:"pixels",requires:["text-field"],expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"text-keep-upright":{type:"boolean",default:!0,requires:["text-field",{"text-rotation-alignment":"map"},{"symbol-placement":["line","line-center"]}],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"text-transform":{type:"enum",values:{none:{},uppercase:{},lowercase:{}},default:"none",requires:["text-field"],expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"data-driven"},"text-offset":{type:"array",value:"number",units:"ems",length:2,default:[0,0],requires:["text-field",{"!":"text-radial-offset"}],expression:{interpolated:!0,parameters:["zoom","feature"]},"property-type":"data-driven"},"text-allow-overlap":{type:"boolean",default:!1,requires:["text-field"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"text-ignore-placement":{type:"boolean",default:!1,requires:["text-field"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"text-optional":{type:"boolean",default:!1,requires:["text-field","icon-image"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},visibility:{type:"enum",values:{visible:{},none:{}},default:"visible","property-type":"constant"}},layout_raster:{visibility:{type:"enum",values:{visible:{},none:{}},default:"visible","property-type":"constant"}},layout_hillshade:{visibility:{type:"enum",values:{visible:{},none:{}},default:"visible","property-type":"constant"}},filter:{type:"array",value:"*"},filter_operator:{type:"enum",values:{"==":{},"!=":{},">":{},">=":{},"<":{},"<=":{},in:{},"!in":{},all:{},any:{},none:{},has:{},"!has":{},within:{}}},geometry_type:{type:"enum",values:{Point:{},LineString:{},Polygon:{}}},function:{expression:{type:"expression"},stops:{type:"array",value:"function_stop"},base:{type:"number",default:1,minimum:0},property:{type:"string",default:"$zoom"},type:{type:"enum",values:{identity:{},exponential:{},interval:{},categorical:{}},default:"exponential"},colorSpace:{type:"enum",values:{rgb:{},lab:{},hcl:{}},default:"rgb"},default:{type:"*",required:!1}},function_stop:{type:"array",minimum:0,maximum:24,value:["number","color"],length:2},expression:{type:"array",value:"*",minimum:1},expression_name:{type:"enum",values:{let:{group:"Variable binding"},var:{group:"Variable binding"},literal:{group:"Types"},array:{group:"Types"},at:{group:"Lookup"},in:{group:"Lookup"},"index-of":{group:"Lookup"},slice:{group:"Lookup"},case:{group:"Decision"},match:{group:"Decision"},coalesce:{group:"Decision"},step:{group:"Ramps, scales, curves"},interpolate:{group:"Ramps, scales, curves"},"interpolate-hcl":{group:"Ramps, scales, curves"},"interpolate-lab":{group:"Ramps, scales, curves"},ln2:{group:"Math"},pi:{group:"Math"},e:{group:"Math"},typeof:{group:"Types"},string:{group:"Types"},number:{group:"Types"},boolean:{group:"Types"},object:{group:"Types"},collator:{group:"Types"},format:{group:"Types"},image:{group:"Types"},"number-format":{group:"Types"},"to-string":{group:"Types"},"to-number":{group:"Types"},"to-boolean":{group:"Types"},"to-rgba":{group:"Color"},"to-color":{group:"Types"},rgb:{group:"Color"},rgba:{group:"Color"},get:{group:"Lookup"},has:{group:"Lookup"},length:{group:"Lookup"},properties:{group:"Feature data"},"feature-state":{group:"Feature data"},"geometry-type":{group:"Feature data"},id:{group:"Feature data"},zoom:{group:"Zoom"},"heatmap-density":{group:"Heatmap"},"line-progress":{group:"Feature data"},accumulated:{group:"Feature data"},"+":{group:"Math"},"*":{group:"Math"},"-":{group:"Math"},"/":{group:"Math"},"%":{group:"Math"},"^":{group:"Math"},sqrt:{group:"Math"},log10:{group:"Math"},ln:{group:"Math"},log2:{group:"Math"},sin:{group:"Math"},cos:{group:"Math"},tan:{group:"Math"},asin:{group:"Math"},acos:{group:"Math"},atan:{group:"Math"},min:{group:"Math"},max:{group:"Math"},round:{group:"Math"},abs:{group:"Math"},ceil:{group:"Math"},floor:{group:"Math"},distance:{group:"Math"},"==":{group:"Decision"},"!=":{group:"Decision"},">":{group:"Decision"},"<":{group:"Decision"},">=":{group:"Decision"},"<=":{group:"Decision"},all:{group:"Decision"},any:{group:"Decision"},"!":{group:"Decision"},within:{group:"Decision"},"is-supported-script":{group:"String"},upcase:{group:"String"},downcase:{group:"String"},concat:{group:"String"},"resolved-locale":{group:"String"}}},light:{anchor:{type:"enum",default:"viewport",values:{map:{},viewport:{}},"property-type":"data-constant",transition:!1,expression:{interpolated:!1,parameters:["zoom"]}},position:{type:"array",default:[1.15,210,30],length:3,value:"number","property-type":"data-constant",transition:!0,expression:{interpolated:!0,parameters:["zoom"]}},color:{type:"color","property-type":"data-constant",default:"#ffffff",expression:{interpolated:!0,parameters:["zoom"]},transition:!0},intensity:{type:"number","property-type":"data-constant",default:.5,minimum:0,maximum:1,expression:{interpolated:!0,parameters:["zoom"]},transition:!0}},paint:["paint_fill","paint_line","paint_circle","paint_heatmap","paint_fill-extrusion","paint_symbol","paint_raster","paint_hillshade","paint_background"],paint_fill:{"fill-antialias":{type:"boolean",default:!0,expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"fill-opacity":{type:"number",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"fill-color":{type:"color",default:"#000000",transition:!0,requires:[{"!":"fill-pattern"}],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"fill-outline-color":{type:"color",transition:!0,requires:[{"!":"fill-pattern"},{"fill-antialias":!0}],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"fill-translate":{type:"array",value:"number",length:2,default:[0,0],transition:!0,units:"pixels",expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"fill-translate-anchor":{type:"enum",values:{map:{},viewport:{}},default:"map",requires:["fill-translate"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"fill-pattern":{type:"resolvedImage",transition:!0,expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"cross-faded-data-driven"}},"paint_fill-extrusion":{"fill-extrusion-opacity":{type:"number",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"fill-extrusion-color":{type:"color",default:"#000000",transition:!0,requires:[{"!":"fill-extrusion-pattern"}],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"fill-extrusion-translate":{type:"array",value:"number",length:2,default:[0,0],transition:!0,units:"pixels",expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"fill-extrusion-translate-anchor":{type:"enum",values:{map:{},viewport:{}},default:"map",requires:["fill-extrusion-translate"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"fill-extrusion-pattern":{type:"resolvedImage",transition:!0,expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"cross-faded-data-driven"},"fill-extrusion-height":{type:"number",default:0,minimum:0,units:"meters",transition:!0,expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"fill-extrusion-base":{type:"number",default:0,minimum:0,units:"meters",transition:!0,requires:["fill-extrusion-height"],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"fill-extrusion-vertical-gradient":{type:"boolean",default:!0,transition:!1,expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"}},paint_line:{"line-opacity":{type:"number",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"line-color":{type:"color",default:"#000000",transition:!0,requires:[{"!":"line-pattern"}],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"line-translate":{type:"array",value:"number",length:2,default:[0,0],transition:!0,units:"pixels",expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"line-translate-anchor":{type:"enum",values:{map:{},viewport:{}},default:"map",requires:["line-translate"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"line-width":{type:"number",default:1,minimum:0,transition:!0,units:"pixels",expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"line-gap-width":{type:"number",default:0,minimum:0,transition:!0,units:"pixels",expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"line-offset":{type:"number",default:0,transition:!0,units:"pixels",expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"line-blur":{type:"number",default:0,minimum:0,transition:!0,units:"pixels",expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"line-dasharray":{type:"array",value:"number",minimum:0,transition:!0,units:"line widths",requires:[{"!":"line-pattern"}],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"cross-faded"},"line-pattern":{type:"resolvedImage",transition:!0,expression:{interpolated:!1,parameters:["zoom","feature"]},"property-type":"cross-faded-data-driven"},"line-gradient":{type:"color",transition:!1,requires:[{"!":"line-dasharray"},{"!":"line-pattern"},{source:"geojson",has:{lineMetrics:!0}}],expression:{interpolated:!0,parameters:["line-progress"]},"property-type":"color-ramp"}},paint_circle:{"circle-radius":{type:"number",default:5,minimum:0,transition:!0,units:"pixels",expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"circle-color":{type:"color",default:"#000000",transition:!0,expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"circle-blur":{type:"number",default:0,transition:!0,expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"circle-opacity":{type:"number",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"circle-translate":{type:"array",value:"number",length:2,default:[0,0],transition:!0,units:"pixels",expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"circle-translate-anchor":{type:"enum",values:{map:{},viewport:{}},default:"map",requires:["circle-translate"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"circle-pitch-scale":{type:"enum",values:{map:{},viewport:{}},default:"map",expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"circle-pitch-alignment":{type:"enum",values:{map:{},viewport:{}},default:"viewport",expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"circle-stroke-width":{type:"number",default:0,minimum:0,transition:!0,units:"pixels",expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"circle-stroke-color":{type:"color",default:"#000000",transition:!0,expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"circle-stroke-opacity":{type:"number",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"}},paint_heatmap:{"heatmap-radius":{type:"number",default:30,minimum:1,transition:!0,units:"pixels",expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"heatmap-weight":{type:"number",default:1,minimum:0,transition:!1,expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"heatmap-intensity":{type:"number",default:1,minimum:0,transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"heatmap-color":{type:"color",default:["interpolate",["linear"],["heatmap-density"],0,"rgba(0, 0, 255, 0)",.1,"royalblue",.3,"cyan",.5,"lime",.7,"yellow",1,"red"],transition:!1,expression:{interpolated:!0,parameters:["heatmap-density"]},"property-type":"color-ramp"},"heatmap-opacity":{type:"number",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"}},paint_symbol:{"icon-opacity":{type:"number",default:1,minimum:0,maximum:1,transition:!0,requires:["icon-image"],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"icon-color":{type:"color",default:"#000000",transition:!0,requires:["icon-image"],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"icon-halo-color":{type:"color",default:"rgba(0, 0, 0, 0)",transition:!0,requires:["icon-image"],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"icon-halo-width":{type:"number",default:0,minimum:0,transition:!0,units:"pixels",requires:["icon-image"],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"icon-halo-blur":{type:"number",default:0,minimum:0,transition:!0,units:"pixels",requires:["icon-image"],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"icon-translate":{type:"array",value:"number",length:2,default:[0,0],transition:!0,units:"pixels",requires:["icon-image"],expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"icon-translate-anchor":{type:"enum",values:{map:{},viewport:{}},default:"map",requires:["icon-image","icon-translate"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"text-opacity":{type:"number",default:1,minimum:0,maximum:1,transition:!0,requires:["text-field"],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"text-color":{type:"color",default:"#000000",transition:!0,overridable:!0,requires:["text-field"],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"text-halo-color":{type:"color",default:"rgba(0, 0, 0, 0)",transition:!0,requires:["text-field"],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"text-halo-width":{type:"number",default:0,minimum:0,transition:!0,units:"pixels",requires:["text-field"],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"text-halo-blur":{type:"number",default:0,minimum:0,transition:!0,units:"pixels",requires:["text-field"],expression:{interpolated:!0,parameters:["zoom","feature","feature-state"]},"property-type":"data-driven"},"text-translate":{type:"array",value:"number",length:2,default:[0,0],transition:!0,units:"pixels",requires:["text-field"],expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"text-translate-anchor":{type:"enum",values:{map:{},viewport:{}},default:"map",requires:["text-field","text-translate"],expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"}},paint_raster:{"raster-opacity":{type:"number",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"raster-hue-rotate":{type:"number",default:0,period:360,transition:!0,units:"degrees",expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"raster-brightness-min":{type:"number",default:0,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"raster-brightness-max":{type:"number",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"raster-saturation":{type:"number",default:0,minimum:-1,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"raster-contrast":{type:"number",default:0,minimum:-1,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"raster-resampling":{type:"enum",values:{linear:{},nearest:{}},default:"linear",expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"raster-fade-duration":{type:"number",default:300,minimum:0,transition:!1,units:"milliseconds",expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"}},paint_hillshade:{"hillshade-illumination-direction":{type:"number",default:335,minimum:0,maximum:359,transition:!1,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"hillshade-illumination-anchor":{type:"enum",values:{map:{},viewport:{}},default:"viewport",expression:{interpolated:!1,parameters:["zoom"]},"property-type":"data-constant"},"hillshade-exaggeration":{type:"number",default:.5,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"hillshade-shadow-color":{type:"color",default:"#000000",transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"hillshade-highlight-color":{type:"color",default:"#FFFFFF",transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"hillshade-accent-color":{type:"color",default:"#000000",transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"}},paint_background:{"background-color":{type:"color",default:"#000000",transition:!0,requires:[{"!":"background-pattern"}],expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"},"background-pattern":{type:"resolvedImage",transition:!0,expression:{interpolated:!1,parameters:["zoom"]},"property-type":"cross-faded"},"background-opacity":{type:"number",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:["zoom"]},"property-type":"data-constant"}},transition:{duration:{type:"number",default:300,minimum:0,units:"milliseconds"},delay:{type:"number",default:0,minimum:0,units:"milliseconds"}},"property-type":{"data-driven":{type:"property-type"},"cross-faded":{type:"property-type"},"cross-faded-data-driven":{type:"property-type"},"color-ramp":{type:"property-type"},"data-constant":{type:"property-type"},constant:{type:"property-type"}},promoteId:{"*":{type:"string"}}},Ct=function(t,e,r,n){this.message=(t?t+": ":"")+r,n&&(this.identifier=n),null!=e&&e.__line__&&(this.line=e.__line__)};function Pt(t){var e=t.key,r=t.value;return r?[new Ct(e,r,"constants have been deprecated as of v8")]:[]}function It(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];for(var n=0,i=e;n<i.length;n+=1){var a=i[n];for(var o in a)t[o]=a[o]}return t}function Ot(t){return t instanceof Number||t instanceof String||t instanceof Boolean?t.valueOf():t}function zt(t){if(Array.isArray(t))return t.map(zt);if(t instanceof Object&&!(t instanceof Number||t instanceof String||t instanceof Boolean)){var e={};for(var r in t)e[r]=zt(t[r]);return e}return Ot(t)}var Dt=function(t){function e(e,r){t.call(this,r),this.message=r,this.key=e}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Error),Rt=function(t,e){void 0===e&&(e=[]),this.parent=t,this.bindings={};for(var r=0,n=e;r<n.length;r+=1){var i=n[r],a=i[0],o=i[1];this.bindings[a]=o}};Rt.prototype.concat=function(t){return new Rt(this,t)},Rt.prototype.get=function(t){if(this.bindings[t])return this.bindings[t];if(this.parent)return this.parent.get(t);throw new Error(t+" not found in scope.")},Rt.prototype.has=function(t){return!!this.bindings[t]||!!this.parent&&this.parent.has(t)};var Ft={kind:"null"},Bt={kind:"number"},Nt={kind:"string"},jt={kind:"boolean"},Ut={kind:"color"},Vt={kind:"object"},Ht={kind:"value"},qt={kind:"collator"},Gt={kind:"formatted"},Yt={kind:"resolvedImage"};function Wt(t,e){return{kind:"array",itemType:t,N:e}}function Xt(t){if("array"===t.kind){var e=Xt(t.itemType);return"number"==typeof t.N?"array<"+e+", "+t.N+">":"value"===t.itemType.kind?"array":"array<"+e+">"}return t.kind}var Zt=[Ft,Bt,Nt,jt,Ut,Gt,Vt,Wt(Ht),Yt];function Jt(t,e){if("error"===e.kind)return null;if("array"===t.kind){if("array"===e.kind&&(0===e.N&&"value"===e.itemType.kind||!Jt(t.itemType,e.itemType))&&("number"!=typeof t.N||t.N===e.N))return null}else{if(t.kind===e.kind)return null;if("value"===t.kind)for(var r=0,n=Zt;r<n.length;r+=1){if(!Jt(n[r],e))return null}}return"Expected "+Xt(t)+" but found "+Xt(e)+" instead."}function Kt(t,e){return e.some((function(e){return e.kind===t.kind}))}function Qt(t,e){return e.some((function(e){return"null"===e?null===t:"array"===e?Array.isArray(t):"object"===e?t&&!Array.isArray(t)&&"object"==typeof t:e===typeof t}))}var $t=e((function(t,e){var r={transparent:[0,0,0,0],aliceblue:[240,248,255,1],antiquewhite:[250,235,215,1],aqua:[0,255,255,1],aquamarine:[127,255,212,1],azure:[240,255,255,1],beige:[245,245,220,1],bisque:[255,228,196,1],black:[0,0,0,1],blanchedalmond:[255,235,205,1],blue:[0,0,255,1],blueviolet:[138,43,226,1],brown:[165,42,42,1],burlywood:[222,184,135,1],cadetblue:[95,158,160,1],chartreuse:[127,255,0,1],chocolate:[210,105,30,1],coral:[255,127,80,1],cornflowerblue:[100,149,237,1],cornsilk:[255,248,220,1],crimson:[220,20,60,1],cyan:[0,255,255,1],darkblue:[0,0,139,1],darkcyan:[0,139,139,1],darkgoldenrod:[184,134,11,1],darkgray:[169,169,169,1],darkgreen:[0,100,0,1],darkgrey:[169,169,169,1],darkkhaki:[189,183,107,1],darkmagenta:[139,0,139,1],darkolivegreen:[85,107,47,1],darkorange:[255,140,0,1],darkorchid:[153,50,204,1],darkred:[139,0,0,1],darksalmon:[233,150,122,1],darkseagreen:[143,188,143,1],darkslateblue:[72,61,139,1],darkslategray:[47,79,79,1],darkslategrey:[47,79,79,1],darkturquoise:[0,206,209,1],darkviolet:[148,0,211,1],deeppink:[255,20,147,1],deepskyblue:[0,191,255,1],dimgray:[105,105,105,1],dimgrey:[105,105,105,1],dodgerblue:[30,144,255,1],firebrick:[178,34,34,1],floralwhite:[255,250,240,1],forestgreen:[34,139,34,1],fuchsia:[255,0,255,1],gainsboro:[220,220,220,1],ghostwhite:[248,248,255,1],gold:[255,215,0,1],goldenrod:[218,165,32,1],gray:[128,128,128,1],green:[0,128,0,1],greenyellow:[173,255,47,1],grey:[128,128,128,1],honeydew:[240,255,240,1],hotpink:[255,105,180,1],indianred:[205,92,92,1],indigo:[75,0,130,1],ivory:[255,255,240,1],khaki:[240,230,140,1],lavender:[230,230,250,1],lavenderblush:[255,240,245,1],lawngreen:[124,252,0,1],lemonchiffon:[255,250,205,1],lightblue:[173,216,230,1],lightcoral:[240,128,128,1],lightcyan:[224,255,255,1],lightgoldenrodyellow:[250,250,210,1],lightgray:[211,211,211,1],lightgreen:[144,238,144,1],lightgrey:[211,211,211,1],lightpink:[255,182,193,1],lightsalmon:[255,160,122,1],lightseagreen:[32,178,170,1],lightskyblue:[135,206,250,1],lightslategray:[119,136,153,1],lightslategrey:[119,136,153,1],lightsteelblue:[176,196,222,1],lightyellow:[255,255,224,1],lime:[0,255,0,1],limegreen:[50,205,50,1],linen:[250,240,230,1],magenta:[255,0,255,1],maroon:[128,0,0,1],mediumaquamarine:[102,205,170,1],mediumblue:[0,0,205,1],mediumorchid:[186,85,211,1],mediumpurple:[147,112,219,1],mediumseagreen:[60,179,113,1],mediumslateblue:[123,104,238,1],mediumspringgreen:[0,250,154,1],mediumturquoise:[72,209,204,1],mediumvioletred:[199,21,133,1],midnightblue:[25,25,112,1],mintcream:[245,255,250,1],mistyrose:[255,228,225,1],moccasin:[255,228,181,1],navajowhite:[255,222,173,1],navy:[0,0,128,1],oldlace:[253,245,230,1],olive:[128,128,0,1],olivedrab:[107,142,35,1],orange:[255,165,0,1],orangered:[255,69,0,1],orchid:[218,112,214,1],palegoldenrod:[238,232,170,1],palegreen:[152,251,152,1],paleturquoise:[175,238,238,1],palevioletred:[219,112,147,1],papayawhip:[255,239,213,1],peachpuff:[255,218,185,1],peru:[205,133,63,1],pink:[255,192,203,1],plum:[221,160,221,1],powderblue:[176,224,230,1],purple:[128,0,128,1],rebeccapurple:[102,51,153,1],red:[255,0,0,1],rosybrown:[188,143,143,1],royalblue:[65,105,225,1],saddlebrown:[139,69,19,1],salmon:[250,128,114,1],sandybrown:[244,164,96,1],seagreen:[46,139,87,1],seashell:[255,245,238,1],sienna:[160,82,45,1],silver:[192,192,192,1],skyblue:[135,206,235,1],slateblue:[106,90,205,1],slategray:[112,128,144,1],slategrey:[112,128,144,1],snow:[255,250,250,1],springgreen:[0,255,127,1],steelblue:[70,130,180,1],tan:[210,180,140,1],teal:[0,128,128,1],thistle:[216,191,216,1],tomato:[255,99,71,1],turquoise:[64,224,208,1],violet:[238,130,238,1],wheat:[245,222,179,1],white:[255,255,255,1],whitesmoke:[245,245,245,1],yellow:[255,255,0,1],yellowgreen:[154,205,50,1]};function n(t){return(t=Math.round(t))<0?0:t>255?255:t}function i(t){return t<0?0:t>1?1:t}function a(t){return"%"===t[t.length-1]?n(parseFloat(t)/100*255):n(parseInt(t))}function o(t){return"%"===t[t.length-1]?i(parseFloat(t)/100):i(parseFloat(t))}function s(t,e,r){return r<0?r+=1:r>1&&(r-=1),6*r<1?t+(e-t)*r*6:2*r<1?e:3*r<2?t+(e-t)*(2/3-r)*6:t}try{e.parseCSSColor=function(t){var e,i=t.replace(/ /g,"").toLowerCase();if(i in r)return r[i].slice();if("#"===i[0])return 4===i.length?(e=parseInt(i.substr(1),16))>=0&&e<=4095?[(3840&e)>>4|(3840&e)>>8,240&e|(240&e)>>4,15&e|(15&e)<<4,1]:null:7===i.length&&(e=parseInt(i.substr(1),16))>=0&&e<=16777215?[(16711680&e)>>16,(65280&e)>>8,255&e,1]:null;var l=i.indexOf("("),c=i.indexOf(")");if(-1!==l&&c+1===i.length){var u=i.substr(0,l),f=i.substr(l+1,c-(l+1)).split(","),h=1;switch(u){case"rgba":if(4!==f.length)return null;h=o(f.pop());case"rgb":return 3!==f.length?null:[a(f[0]),a(f[1]),a(f[2]),h];case"hsla":if(4!==f.length)return null;h=o(f.pop());case"hsl":if(3!==f.length)return null;var p=(parseFloat(f[0])%360+360)%360/360,d=o(f[1]),m=o(f[2]),g=m<=.5?m*(d+1):m+d-m*d,v=2*m-g;return[n(255*s(v,g,p+1/3)),n(255*s(v,g,p)),n(255*s(v,g,p-1/3)),h];default:return null}}return null}}catch(t){}})).parseCSSColor,te=function(t,e,r,n){void 0===n&&(n=1),this.r=t,this.g=e,this.b=r,this.a=n};te.parse=function(t){if(t){if(t instanceof te)return t;if("string"==typeof t){var e=$t(t);if(e)return new te(e[0]/255*e[3],e[1]/255*e[3],e[2]/255*e[3],e[3])}}},te.prototype.toString=function(){var t=this.toArray(),e=t[0],r=t[1],n=t[2],i=t[3];return"rgba("+Math.round(e)+","+Math.round(r)+","+Math.round(n)+","+i+")"},te.prototype.toArray=function(){var t=this.r,e=this.g,r=this.b,n=this.a;return 0===n?[0,0,0,0]:[255*t/n,255*e/n,255*r/n,n]},te.black=new te(0,0,0,1),te.white=new te(1,1,1,1),te.transparent=new te(0,0,0,0),te.red=new te(1,0,0,1);var ee=function(t,e,r){this.sensitivity=t?e?"variant":"case":e?"accent":"base",this.locale=r,this.collator=new Intl.Collator(this.locale?this.locale:[],{sensitivity:this.sensitivity,usage:"search"})};ee.prototype.compare=function(t,e){return this.collator.compare(t,e)},ee.prototype.resolvedLocale=function(){return new Intl.Collator(this.locale?this.locale:[]).resolvedOptions().locale};var re=function(t,e,r,n,i){this.text=t,this.image=e,this.scale=r,this.fontStack=n,this.textColor=i},ne=function(t){this.sections=t};ne.fromString=function(t){return new ne([new re(t,null,null,null,null)])},ne.prototype.isEmpty=function(){return 0===this.sections.length||!this.sections.some((function(t){return 0!==t.text.length||t.image&&0!==t.image.name.length}))},ne.factory=function(t){return t instanceof ne?t:ne.fromString(t)},ne.prototype.toString=function(){return 0===this.sections.length?"":this.sections.map((function(t){return t.text})).join("")},ne.prototype.serialize=function(){for(var t=["format"],e=0,r=this.sections;e<r.length;e+=1){var n=r[e];if(n.image)t.push(["image",n.image.name]);else{t.push(n.text);var i={};n.fontStack&&(i["text-font"]=["literal",n.fontStack.split(",")]),n.scale&&(i["font-scale"]=n.scale),n.textColor&&(i["text-color"]=["rgba"].concat(n.textColor.toArray())),t.push(i)}}return t};var ie=function(t){this.name=t.name,this.available=t.available};function ae(t,e,r,n){return"number"==typeof t&&t>=0&&t<=255&&"number"==typeof e&&e>=0&&e<=255&&"number"==typeof r&&r>=0&&r<=255?void 0===n||"number"==typeof n&&n>=0&&n<=1?null:"Invalid rgba value ["+[t,e,r,n].join(", ")+"]: 'a' must be between 0 and 1.":"Invalid rgba value ["+("number"==typeof n?[t,e,r,n]:[t,e,r]).join(", ")+"]: 'r', 'g', and 'b' must be between 0 and 255."}function oe(t){if(null===t)return!0;if("string"==typeof t)return!0;if("boolean"==typeof t)return!0;if("number"==typeof t)return!0;if(t instanceof te)return!0;if(t instanceof ee)return!0;if(t instanceof ne)return!0;if(t instanceof ie)return!0;if(Array.isArray(t)){for(var e=0,r=t;e<r.length;e+=1){if(!oe(r[e]))return!1}return!0}if("object"==typeof t){for(var n in t)if(!oe(t[n]))return!1;return!0}return!1}function se(t){if(null===t)return Ft;if("string"==typeof t)return Nt;if("boolean"==typeof t)return jt;if("number"==typeof t)return Bt;if(t instanceof te)return Ut;if(t instanceof ee)return qt;if(t instanceof ne)return Gt;if(t instanceof ie)return Yt;if(Array.isArray(t)){for(var e,r=t.length,n=0,i=t;n<i.length;n+=1){var a=se(i[n]);if(e){if(e===a)continue;e=Ht;break}e=a}return Wt(e||Ht,r)}return Vt}function le(t){var e=typeof t;return null===t?"":"string"===e||"number"===e||"boolean"===e?String(t):t instanceof te||t instanceof ne||t instanceof ie?t.toString():JSON.stringify(t)}ie.prototype.toString=function(){return this.name},ie.fromString=function(t){return t?new ie({name:t,available:!1}):null},ie.prototype.serialize=function(){return["image",this.name]};var ce=function(t,e){this.type=t,this.value=e};ce.parse=function(t,e){if(2!==t.length)return e.error("'literal' expression requires exactly one argument, but found "+(t.length-1)+" instead.");if(!oe(t[1]))return e.error("invalid value");var r=t[1],n=se(r),i=e.expectedType;return"array"!==n.kind||0!==n.N||!i||"array"!==i.kind||"number"==typeof i.N&&0!==i.N||(n=i),new ce(n,r)},ce.prototype.evaluate=function(){return this.value},ce.prototype.eachChild=function(){},ce.prototype.outputDefined=function(){return!0},ce.prototype.serialize=function(){return"array"===this.type.kind||"object"===this.type.kind?["literal",this.value]:this.value instanceof te?["rgba"].concat(this.value.toArray()):this.value instanceof ne?this.value.serialize():this.value};var ue=function(t){this.name="ExpressionEvaluationError",this.message=t};ue.prototype.toJSON=function(){return this.message};var fe={string:Nt,number:Bt,boolean:jt,object:Vt},he=function(t,e){this.type=t,this.args=e};he.parse=function(t,e){if(t.length<2)return e.error("Expected at least one argument.");var r,n=1,i=t[0];if("array"===i){var a,o;if(t.length>2){var s=t[1];if("string"!=typeof s||!(s in fe)||"object"===s)return e.error('The item type argument of "array" must be one of string, number, boolean',1);a=fe[s],n++}else a=Ht;if(t.length>3){if(null!==t[2]&&("number"!=typeof t[2]||t[2]<0||t[2]!==Math.floor(t[2])))return e.error('The length argument to "array" must be a positive integer literal',2);o=t[2],n++}r=Wt(a,o)}else r=fe[i];for(var l=[];n<t.length;n++){var c=e.parse(t[n],n,Ht);if(!c)return null;l.push(c)}return new he(r,l)},he.prototype.evaluate=function(t){for(var e=0;e<this.args.length;e++){var r=this.args[e].evaluate(t);if(!Jt(this.type,se(r)))return r;if(e===this.args.length-1)throw new ue("Expected value to be of type "+Xt(this.type)+", but found "+Xt(se(r))+" instead.")}return null},he.prototype.eachChild=function(t){this.args.forEach(t)},he.prototype.outputDefined=function(){return this.args.every((function(t){return t.outputDefined()}))},he.prototype.serialize=function(){var t=this.type,e=[t.kind];if("array"===t.kind){var r=t.itemType;if("string"===r.kind||"number"===r.kind||"boolean"===r.kind){e.push(r.kind);var n=t.N;("number"==typeof n||this.args.length>1)&&e.push(n)}}return e.concat(this.args.map((function(t){return t.serialize()})))};var pe=function(t){this.type=Gt,this.sections=t};pe.parse=function(t,e){if(t.length<2)return e.error("Expected at least one argument.");var r=t[1];if(!Array.isArray(r)&&"object"==typeof r)return e.error("First argument must be an image or text section.");for(var n=[],i=!1,a=1;a<=t.length-1;++a){var o=t[a];if(i&&"object"==typeof o&&!Array.isArray(o)){i=!1;var s=null;if(o["font-scale"]&&!(s=e.parse(o["font-scale"],1,Bt)))return null;var l=null;if(o["text-font"]&&!(l=e.parse(o["text-font"],1,Wt(Nt))))return null;var c=null;if(o["text-color"]&&!(c=e.parse(o["text-color"],1,Ut)))return null;var u=n[n.length-1];u.scale=s,u.font=l,u.textColor=c}else{var f=e.parse(t[a],1,Ht);if(!f)return null;var h=f.type.kind;if("string"!==h&&"value"!==h&&"null"!==h&&"resolvedImage"!==h)return e.error("Formatted text type must be 'string', 'value', 'image' or 'null'.");i=!0,n.push({content:f,scale:null,font:null,textColor:null})}}return new pe(n)},pe.prototype.evaluate=function(t){return new ne(this.sections.map((function(e){var r=e.content.evaluate(t);return se(r)===Yt?new re("",r,null,null,null):new re(le(r),null,e.scale?e.scale.evaluate(t):null,e.font?e.font.evaluate(t).join(","):null,e.textColor?e.textColor.evaluate(t):null)})))},pe.prototype.eachChild=function(t){for(var e=0,r=this.sections;e<r.length;e+=1){var n=r[e];t(n.content),n.scale&&t(n.scale),n.font&&t(n.font),n.textColor&&t(n.textColor)}},pe.prototype.outputDefined=function(){return!1},pe.prototype.serialize=function(){for(var t=["format"],e=0,r=this.sections;e<r.length;e+=1){var n=r[e];t.push(n.content.serialize());var i={};n.scale&&(i["font-scale"]=n.scale.serialize()),n.font&&(i["text-font"]=n.font.serialize()),n.textColor&&(i["text-color"]=n.textColor.serialize()),t.push(i)}return t};var de=function(t){this.type=Yt,this.input=t};de.parse=function(t,e){if(2!==t.length)return e.error("Expected two arguments.");var r=e.parse(t[1],1,Nt);return r?new de(r):e.error("No image name provided.")},de.prototype.evaluate=function(t){var e=this.input.evaluate(t),r=ie.fromString(e);return r&&t.availableImages&&(r.available=t.availableImages.indexOf(e)>-1),r},de.prototype.eachChild=function(t){t(this.input)},de.prototype.outputDefined=function(){return!1},de.prototype.serialize=function(){return["image",this.input.serialize()]};var me={"to-boolean":jt,"to-color":Ut,"to-number":Bt,"to-string":Nt},ge=function(t,e){this.type=t,this.args=e};ge.parse=function(t,e){if(t.length<2)return e.error("Expected at least one argument.");var r=t[0];if(("to-boolean"===r||"to-string"===r)&&2!==t.length)return e.error("Expected one argument.");for(var n=me[r],i=[],a=1;a<t.length;a++){var o=e.parse(t[a],a,Ht);if(!o)return null;i.push(o)}return new ge(n,i)},ge.prototype.evaluate=function(t){if("boolean"===this.type.kind)return Boolean(this.args[0].evaluate(t));if("color"===this.type.kind){for(var e,r,n=0,i=this.args;n<i.length;n+=1){if(r=null,(e=i[n].evaluate(t))instanceof te)return e;if("string"==typeof e){var a=t.parseColor(e);if(a)return a}else if(Array.isArray(e)&&!(r=e.length<3||e.length>4?"Invalid rbga value "+JSON.stringify(e)+": expected an array containing either three or four numeric values.":ae(e[0],e[1],e[2],e[3])))return new te(e[0]/255,e[1]/255,e[2]/255,e[3])}throw new ue(r||"Could not parse color from value '"+("string"==typeof e?e:String(JSON.stringify(e)))+"'")}if("number"===this.type.kind){for(var o=null,s=0,l=this.args;s<l.length;s+=1){if(null===(o=l[s].evaluate(t)))return 0;var c=Number(o);if(!isNaN(c))return c}throw new ue("Could not convert "+JSON.stringify(o)+" to number.")}return"formatted"===this.type.kind?ne.fromString(le(this.args[0].evaluate(t))):"resolvedImage"===this.type.kind?ie.fromString(le(this.args[0].evaluate(t))):le(this.args[0].evaluate(t))},ge.prototype.eachChild=function(t){this.args.forEach(t)},ge.prototype.outputDefined=function(){return this.args.every((function(t){return t.outputDefined()}))},ge.prototype.serialize=function(){if("formatted"===this.type.kind)return new pe([{content:this.args[0],scale:null,font:null,textColor:null}]).serialize();if("resolvedImage"===this.type.kind)return new de(this.args[0]).serialize();var t=["to-"+this.type.kind];return this.eachChild((function(e){t.push(e.serialize())})),t};var ve=["Unknown","Point","LineString","Polygon"],ye=function(){this.globals=null,this.feature=null,this.featureState=null,this.formattedSection=null,this._parseColorCache={},this.availableImages=null,this.canonical=null};ye.prototype.id=function(){return this.feature&&"id"in this.feature?this.feature.id:null},ye.prototype.geometryType=function(){return this.feature?"number"==typeof this.feature.type?ve[this.feature.type]:this.feature.type:null},ye.prototype.geometry=function(){return this.feature&&"geometry"in this.feature?this.feature.geometry:null},ye.prototype.canonicalID=function(){return this.canonical},ye.prototype.properties=function(){return this.feature&&this.feature.properties||{}},ye.prototype.parseColor=function(t){var e=this._parseColorCache[t];return e||(e=this._parseColorCache[t]=te.parse(t)),e};var xe=function(t,e,r,n){this.name=t,this.type=e,this._evaluate=r,this.args=n};xe.prototype.evaluate=function(t){return this._evaluate(t,this.args)},xe.prototype.eachChild=function(t){this.args.forEach(t)},xe.prototype.outputDefined=function(){return!1},xe.prototype.serialize=function(){return[this.name].concat(this.args.map((function(t){return t.serialize()})))},xe.parse=function(t,e){var r,n=t[0],i=xe.definitions[n];if(!i)return e.error('Unknown expression "'+n+'". If you wanted a literal array, use ["literal", [...]].',0);for(var a=Array.isArray(i)?i[0]:i.type,o=Array.isArray(i)?[[i[1],i[2]]]:i.overloads,s=o.filter((function(e){var r=e[0];return!Array.isArray(r)||r.length===t.length-1})),l=null,c=0,u=s;c<u.length;c+=1){var f=u[c],h=f[0],p=f[1];l=new Ue(e.registry,e.path,null,e.scope);for(var d=[],m=!1,g=1;g<t.length;g++){var v=t[g],y=Array.isArray(h)?h[g-1]:h.type,x=l.parse(v,1+d.length,y);if(!x){m=!0;break}d.push(x)}if(!m)if(Array.isArray(h)&&h.length!==d.length)l.error("Expected "+h.length+" arguments, but found "+d.length+" instead.");else{for(var b=0;b<d.length;b++){var _=Array.isArray(h)?h[b]:h.type,w=d[b];l.concat(b+1).checkSubtype(_,w.type)}if(0===l.errors.length)return new xe(n,a,p,d)}}if(1===s.length)(r=e.errors).push.apply(r,l.errors);else{for(var T=(s.length?s:o).map((function(t){var e,r=t[0];return e=r,Array.isArray(e)?"("+e.map(Xt).join(", ")+")":"("+Xt(e.type)+"...)"})).join(" | "),k=[],A=1;A<t.length;A++){var M=e.parse(t[A],1+k.length);if(!M)return null;k.push(Xt(M.type))}e.error("Expected arguments of type "+T+", but found ("+k.join(", ")+") instead.")}return null},xe.register=function(t,e){for(var r in xe.definitions=e,e)t[r]=xe};var be=function(t,e,r){this.type=qt,this.locale=r,this.caseSensitive=t,this.diacriticSensitive=e};be.parse=function(t,e){if(2!==t.length)return e.error("Expected one argument.");var r=t[1];if("object"!=typeof r||Array.isArray(r))return e.error("Collator options argument must be an object.");var n=e.parse(void 0!==r["case-sensitive"]&&r["case-sensitive"],1,jt);if(!n)return null;var i=e.parse(void 0!==r["diacritic-sensitive"]&&r["diacritic-sensitive"],1,jt);if(!i)return null;var a=null;return r.locale&&!(a=e.parse(r.locale,1,Nt))?null:new be(n,i,a)},be.prototype.evaluate=function(t){return new ee(this.caseSensitive.evaluate(t),this.diacriticSensitive.evaluate(t),this.locale?this.locale.evaluate(t):null)},be.prototype.eachChild=function(t){t(this.caseSensitive),t(this.diacriticSensitive),this.locale&&t(this.locale)},be.prototype.outputDefined=function(){return!1},be.prototype.serialize=function(){var t={};return t["case-sensitive"]=this.caseSensitive.serialize(),t["diacritic-sensitive"]=this.diacriticSensitive.serialize(),this.locale&&(t.locale=this.locale.serialize()),["collator",t]};function _e(t,e){t[0]=Math.min(t[0],e[0]),t[1]=Math.min(t[1],e[1]),t[2]=Math.max(t[2],e[0]),t[3]=Math.max(t[3],e[1])}function we(t,e){return!(t[0]<=e[0])&&(!(t[2]>=e[2])&&(!(t[1]<=e[1])&&!(t[3]>=e[3])))}function Te(t,e){var r,n=(180+t[0])/360,i=(r=t[1],(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+r*Math.PI/360)))/360),a=Math.pow(2,e.z);return[Math.round(n*a*8192),Math.round(i*a*8192)]}function ke(t,e,r){return e[1]>t[1]!=r[1]>t[1]&&t[0]<(r[0]-e[0])*(t[1]-e[1])/(r[1]-e[1])+e[0]}function Ae(t,e){for(var r,n,i,a,o,s,l,c=!1,u=0,f=e.length;u<f;u++)for(var h=e[u],p=0,d=h.length;p<d-1;p++){if(r=t,n=h[p],i=h[p+1],a=void 0,o=void 0,s=void 0,l=void 0,a=r[0]-n[0],o=r[1]-n[1],s=r[0]-i[0],l=r[1]-i[1],a*l-s*o==0&&a*s<=0&&o*l<=0)return!1;ke(t,h[p],h[p+1])&&(c=!c)}return c}function Me(t,e){for(var r=0;r<e.length;r++)if(Ae(t,e[r]))return!0;return!1}function Se(t,e,r,n){var i=t[0]-r[0],a=t[1]-r[1],o=e[0]-r[0],s=e[1]-r[1],l=n[0]-r[0],c=n[1]-r[1],u=i*c-l*a,f=o*c-l*s;return u>0&&f<0||u<0&&f>0}function Ee(t,e,r){for(var n=0,i=r;n<i.length;n+=1)for(var a=i[n],o=0;o<a.length-1;++o)if(s=t,l=e,c=a[o],u=a[o+1],f=void 0,h=void 0,p=void 0,d=void 0,p=[l[0]-s[0],l[1]-s[1]],d=[u[0]-c[0],u[1]-c[1]],0!=(f=d)[0]*(h=p)[1]-f[1]*h[0]&&Se(s,l,c,u)&&Se(c,u,s,l))return!0;var s,l,c,u,f,h,p,d;return!1}function Le(t,e){for(var r=0;r<t.length;++r)if(!Ae(t[r],e))return!1;for(var n=0;n<t.length-1;++n)if(Ee(t[n],t[n+1],e))return!1;return!0}function Ce(t,e){for(var r=0;r<e.length;r++)if(Le(t,e[r]))return!0;return!1}function Pe(t,e,r){for(var n=[],i=0;i<t.length;i++){for(var a=[],o=0;o<t[i].length;o++){var s=Te(t[i][o],r);_e(e,s),a.push(s)}n.push(a)}return n}function Ie(t,e,r){for(var n=[],i=0;i<t.length;i++){var a=Pe(t[i],e,r);n.push(a)}return n}function Oe(t,e,r,n){if(t[0]<r[0]||t[0]>r[2]){var i=.5*n,a=t[0]-r[0]>i?-n:r[0]-t[0]>i?n:0;0===a&&(a=t[0]-r[2]>i?-n:r[2]-t[0]>i?n:0),t[0]+=a}_e(e,t)}function ze(t,e,r,n){for(var i=8192*Math.pow(2,n.z),a=[8192*n.x,8192*n.y],o=[],s=0,l=t;s<l.length;s+=1)for(var c=0,u=l[s];c<u.length;c+=1){var f=u[c],h=[f.x+a[0],f.y+a[1]];Oe(h,e,r,i),o.push(h)}return o}function De(t,e,r,n){for(var i,a=8192*Math.pow(2,n.z),o=[8192*n.x,8192*n.y],s=[],l=0,c=t;l<c.length;l+=1){for(var u=[],f=0,h=c[l];f<h.length;f+=1){var p=h[f],d=[p.x+o[0],p.y+o[1]];_e(e,d),u.push(d)}s.push(u)}if(e[2]-e[0]<=a/2){(i=e)[0]=i[1]=1/0,i[2]=i[3]=-1/0;for(var m=0,g=s;m<g.length;m+=1)for(var v=0,y=g[m];v<y.length;v+=1){Oe(y[v],e,r,a)}}return s}var Re=function(t,e){this.type=jt,this.geojson=t,this.geometries=e};function Fe(t){if(t instanceof xe){if("get"===t.name&&1===t.args.length)return!1;if("feature-state"===t.name)return!1;if("has"===t.name&&1===t.args.length)return!1;if("properties"===t.name||"geometry-type"===t.name||"id"===t.name)return!1;if(/^filter-/.test(t.name))return!1}if(t instanceof Re)return!1;var e=!0;return t.eachChild((function(t){e&&!Fe(t)&&(e=!1)})),e}function Be(t){if(t instanceof xe&&"feature-state"===t.name)return!1;var e=!0;return t.eachChild((function(t){e&&!Be(t)&&(e=!1)})),e}function Ne(t,e){if(t instanceof xe&&e.indexOf(t.name)>=0)return!1;var r=!0;return t.eachChild((function(t){r&&!Ne(t,e)&&(r=!1)})),r}Re.parse=function(t,e){if(2!==t.length)return e.error("'within' expression requires exactly one argument, but found "+(t.length-1)+" instead.");if(oe(t[1])){var r=t[1];if("FeatureCollection"===r.type)for(var n=0;n<r.features.length;++n){var i=r.features[n].geometry.type;if("Polygon"===i||"MultiPolygon"===i)return new Re(r,r.features[n].geometry)}else if("Feature"===r.type){var a=r.geometry.type;if("Polygon"===a||"MultiPolygon"===a)return new Re(r,r.geometry)}else if("Polygon"===r.type||"MultiPolygon"===r.type)return new Re(r,r)}return e.error("'within' expression requires valid geojson object that contains polygon geometry type.")},Re.prototype.evaluate=function(t){if(null!=t.geometry()&&null!=t.canonicalID()){if("Point"===t.geometryType())return function(t,e){var r=[1/0,1/0,-1/0,-1/0],n=[1/0,1/0,-1/0,-1/0],i=t.canonicalID();if("Polygon"===e.type){var a=Pe(e.coordinates,n,i),o=ze(t.geometry(),r,n,i);if(!we(r,n))return!1;for(var s=0,l=o;s<l.length;s+=1){if(!Ae(l[s],a))return!1}}if("MultiPolygon"===e.type){var c=Ie(e.coordinates,n,i),u=ze(t.geometry(),r,n,i);if(!we(r,n))return!1;for(var f=0,h=u;f<h.length;f+=1){if(!Me(h[f],c))return!1}}return!0}(t,this.geometries);if("LineString"===t.geometryType())return function(t,e){var r=[1/0,1/0,-1/0,-1/0],n=[1/0,1/0,-1/0,-1/0],i=t.canonicalID();if("Polygon"===e.type){var a=Pe(e.coordinates,n,i),o=De(t.geometry(),r,n,i);if(!we(r,n))return!1;for(var s=0,l=o;s<l.length;s+=1){if(!Le(l[s],a))return!1}}if("MultiPolygon"===e.type){var c=Ie(e.coordinates,n,i),u=De(t.geometry(),r,n,i);if(!we(r,n))return!1;for(var f=0,h=u;f<h.length;f+=1){if(!Ce(h[f],c))return!1}}return!0}(t,this.geometries)}return!1},Re.prototype.eachChild=function(){},Re.prototype.outputDefined=function(){return!0},Re.prototype.serialize=function(){return["within",this.geojson]};var je=function(t,e){this.type=e.type,this.name=t,this.boundExpression=e};je.parse=function(t,e){if(2!==t.length||"string"!=typeof t[1])return e.error("'var' expression requires exactly one string literal argument.");var r=t[1];return e.scope.has(r)?new je(r,e.scope.get(r)):e.error('Unknown variable "'+r+'". Make sure "'+r+'" has been bound in an enclosing "let" expression before using it.',1)},je.prototype.evaluate=function(t){return this.boundExpression.evaluate(t)},je.prototype.eachChild=function(){},je.prototype.outputDefined=function(){return!1},je.prototype.serialize=function(){return["var",this.name]};var Ue=function(t,e,r,n,i){void 0===e&&(e=[]),void 0===n&&(n=new Rt),void 0===i&&(i=[]),this.registry=t,this.path=e,this.key=e.map((function(t){return"["+t+"]"})).join(""),this.scope=n,this.errors=i,this.expectedType=r};function Ve(t,e){for(var r,n,i=t.length-1,a=0,o=i,s=0;a<=o;)if(r=t[s=Math.floor((a+o)/2)],n=t[s+1],r<=e){if(s===i||e<n)return s;a=s+1}else{if(!(r>e))throw new ue("Input is not a number.");o=s-1}return 0}Ue.prototype.parse=function(t,e,r,n,i){return void 0===i&&(i={}),e?this.concat(e,r,n)._parse(t,i):this._parse(t,i)},Ue.prototype._parse=function(t,e){function r(t,e,r){return"assert"===r?new he(e,[t]):"coerce"===r?new ge(e,[t]):t}if(null!==t&&"string"!=typeof t&&"boolean"!=typeof t&&"number"!=typeof t||(t=["literal",t]),Array.isArray(t)){if(0===t.length)return this.error('Expected an array with at least one element. If you wanted a literal array, use ["literal", []].');var n=t[0];if("string"!=typeof n)return this.error("Expression name must be a string, but found "+typeof n+' instead. If you wanted a literal array, use ["literal", [...]].',0),null;var i=this.registry[n];if(i){var a=i.parse(t,this);if(!a)return null;if(this.expectedType){var o=this.expectedType,s=a.type;if("string"!==o.kind&&"number"!==o.kind&&"boolean"!==o.kind&&"object"!==o.kind&&"array"!==o.kind||"value"!==s.kind)if("color"!==o.kind&&"formatted"!==o.kind&&"resolvedImage"!==o.kind||"value"!==s.kind&&"string"!==s.kind){if(this.checkSubtype(o,s))return null}else a=r(a,o,e.typeAnnotation||"coerce");else a=r(a,o,e.typeAnnotation||"assert")}if(!(a instanceof ce)&&"resolvedImage"!==a.type.kind&&function t(e){if(e instanceof je)return t(e.boundExpression);if(e instanceof xe&&"error"===e.name)return!1;if(e instanceof be)return!1;if(e instanceof Re)return!1;var r=e instanceof ge||e instanceof he,n=!0;if(e.eachChild((function(e){n=r?n&&t(e):n&&e instanceof ce})),!n)return!1;return Fe(e)&&Ne(e,["zoom","heatmap-density","line-progress","accumulated","is-supported-script"])}(a)){var l=new ye;try{a=new ce(a.type,a.evaluate(l))}catch(t){return this.error(t.message),null}}return a}return this.error('Unknown expression "'+n+'". If you wanted a literal array, use ["literal", [...]].',0)}return void 0===t?this.error("'undefined' value invalid. Use null instead."):"object"==typeof t?this.error('Bare objects invalid. Use ["literal", {...}] instead.'):this.error("Expected an array, but found "+typeof t+" instead.")},Ue.prototype.concat=function(t,e,r){var n="number"==typeof t?this.path.concat(t):this.path,i=r?this.scope.concat(r):this.scope;return new Ue(this.registry,n,e||null,i,this.errors)},Ue.prototype.error=function(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];var n=""+this.key+e.map((function(t){return"["+t+"]"})).join("");this.errors.push(new Dt(n,t))},Ue.prototype.checkSubtype=function(t,e){var r=Jt(t,e);return r&&this.error(r),r};var He=function(t,e,r){this.type=t,this.input=e,this.labels=[],this.outputs=[];for(var n=0,i=r;n<i.length;n+=1){var a=i[n],o=a[0],s=a[1];this.labels.push(o),this.outputs.push(s)}};function qe(t,e,r){return t*(1-r)+e*r}He.parse=function(t,e){if(t.length-1<4)return e.error("Expected at least 4 arguments, but found only "+(t.length-1)+".");if((t.length-1)%2!=0)return e.error("Expected an even number of arguments.");var r=e.parse(t[1],1,Bt);if(!r)return null;var n=[],i=null;e.expectedType&&"value"!==e.expectedType.kind&&(i=e.expectedType);for(var a=1;a<t.length;a+=2){var o=1===a?-1/0:t[a],s=t[a+1],l=a,c=a+1;if("number"!=typeof o)return e.error('Input/output pairs for "step" expressions must be defined using literal numeric values (not computed expressions) for the input values.',l);if(n.length&&n[n.length-1][0]>=o)return e.error('Input/output pairs for "step" expressions must be arranged with input values in strictly ascending order.',l);var u=e.parse(s,c,i);if(!u)return null;i=i||u.type,n.push([o,u])}return new He(i,r,n)},He.prototype.evaluate=function(t){var e=this.labels,r=this.outputs;if(1===e.length)return r[0].evaluate(t);var n=this.input.evaluate(t);if(n<=e[0])return r[0].evaluate(t);var i=e.length;return n>=e[i-1]?r[i-1].evaluate(t):r[Ve(e,n)].evaluate(t)},He.prototype.eachChild=function(t){t(this.input);for(var e=0,r=this.outputs;e<r.length;e+=1){t(r[e])}},He.prototype.outputDefined=function(){return this.outputs.every((function(t){return t.outputDefined()}))},He.prototype.serialize=function(){for(var t=["step",this.input.serialize()],e=0;e<this.labels.length;e++)e>0&&t.push(this.labels[e]),t.push(this.outputs[e].serialize());return t};var Ge=Object.freeze({__proto__:null,number:qe,color:function(t,e,r){return new te(qe(t.r,e.r,r),qe(t.g,e.g,r),qe(t.b,e.b,r),qe(t.a,e.a,r))},array:function(t,e,r){return t.map((function(t,n){return qe(t,e[n],r)}))}}),Ye=6/29,We=3*Ye*Ye,Xe=Math.PI/180,Ze=180/Math.PI;function Je(t){return t>.008856451679035631?Math.pow(t,1/3):t/We+4/29}function Ke(t){return t>Ye?t*t*t:We*(t-4/29)}function Qe(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function $e(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function tr(t){var e=$e(t.r),r=$e(t.g),n=$e(t.b),i=Je((.4124564*e+.3575761*r+.1804375*n)/.95047),a=Je((.2126729*e+.7151522*r+.072175*n)/1);return{l:116*a-16,a:500*(i-a),b:200*(a-Je((.0193339*e+.119192*r+.9503041*n)/1.08883)),alpha:t.a}}function er(t){var e=(t.l+16)/116,r=isNaN(t.a)?e:e+t.a/500,n=isNaN(t.b)?e:e-t.b/200;return e=1*Ke(e),r=.95047*Ke(r),n=1.08883*Ke(n),new te(Qe(3.2404542*r-1.5371385*e-.4985314*n),Qe(-.969266*r+1.8760108*e+.041556*n),Qe(.0556434*r-.2040259*e+1.0572252*n),t.alpha)}function rr(t,e,r){var n=e-t;return t+r*(n>180||n<-180?n-360*Math.round(n/360):n)}var nr={forward:tr,reverse:er,interpolate:function(t,e,r){return{l:qe(t.l,e.l,r),a:qe(t.a,e.a,r),b:qe(t.b,e.b,r),alpha:qe(t.alpha,e.alpha,r)}}},ir={forward:function(t){var e=tr(t),r=e.l,n=e.a,i=e.b,a=Math.atan2(i,n)*Ze;return{h:a<0?a+360:a,c:Math.sqrt(n*n+i*i),l:r,alpha:t.a}},reverse:function(t){var e=t.h*Xe,r=t.c;return er({l:t.l,a:Math.cos(e)*r,b:Math.sin(e)*r,alpha:t.alpha})},interpolate:function(t,e,r){return{h:rr(t.h,e.h,r),c:qe(t.c,e.c,r),l:qe(t.l,e.l,r),alpha:qe(t.alpha,e.alpha,r)}}},ar=Object.freeze({__proto__:null,lab:nr,hcl:ir}),or=function(t,e,r,n,i){this.type=t,this.operator=e,this.interpolation=r,this.input=n,this.labels=[],this.outputs=[];for(var a=0,o=i;a<o.length;a+=1){var s=o[a],l=s[0],c=s[1];this.labels.push(l),this.outputs.push(c)}};function sr(t,e,r,n){var i=n-r,a=t-r;return 0===i?0:1===e?a/i:(Math.pow(e,a)-1)/(Math.pow(e,i)-1)}or.interpolationFactor=function(t,e,n,i){var a=0;if("exponential"===t.name)a=sr(e,t.base,n,i);else if("linear"===t.name)a=sr(e,1,n,i);else if("cubic-bezier"===t.name){var o=t.controlPoints;a=new r(o[0],o[1],o[2],o[3]).solve(sr(e,1,n,i))}return a},or.parse=function(t,e){var r=t[0],n=t[1],i=t[2],a=t.slice(3);if(!Array.isArray(n)||0===n.length)return e.error("Expected an interpolation type expression.",1);if("linear"===n[0])n={name:"linear"};else if("exponential"===n[0]){var o=n[1];if("number"!=typeof o)return e.error("Exponential interpolation requires a numeric base.",1,1);n={name:"exponential",base:o}}else{if("cubic-bezier"!==n[0])return e.error("Unknown interpolation type "+String(n[0]),1,0);var s=n.slice(1);if(4!==s.length||s.some((function(t){return"number"!=typeof t||t<0||t>1})))return e.error("Cubic bezier interpolation requires four numeric arguments with values between 0 and 1.",1);n={name:"cubic-bezier",controlPoints:s}}if(t.length-1<4)return e.error("Expected at least 4 arguments, but found only "+(t.length-1)+".");if((t.length-1)%2!=0)return e.error("Expected an even number of arguments.");if(!(i=e.parse(i,2,Bt)))return null;var l=[],c=null;"interpolate-hcl"===r||"interpolate-lab"===r?c=Ut:e.expectedType&&"value"!==e.expectedType.kind&&(c=e.expectedType);for(var u=0;u<a.length;u+=2){var f=a[u],h=a[u+1],p=u+3,d=u+4;if("number"!=typeof f)return e.error('Input/output pairs for "interpolate" expressions must be defined using literal numeric values (not computed expressions) for the input values.',p);if(l.length&&l[l.length-1][0]>=f)return e.error('Input/output pairs for "interpolate" expressions must be arranged with input values in strictly ascending order.',p);var m=e.parse(h,d,c);if(!m)return null;c=c||m.type,l.push([f,m])}return"number"===c.kind||"color"===c.kind||"array"===c.kind&&"number"===c.itemType.kind&&"number"==typeof c.N?new or(c,r,n,i,l):e.error("Type "+Xt(c)+" is not interpolatable.")},or.prototype.evaluate=function(t){var e=this.labels,r=this.outputs;if(1===e.length)return r[0].evaluate(t);var n=this.input.evaluate(t);if(n<=e[0])return r[0].evaluate(t);var i=e.length;if(n>=e[i-1])return r[i-1].evaluate(t);var a=Ve(e,n),o=e[a],s=e[a+1],l=or.interpolationFactor(this.interpolation,n,o,s),c=r[a].evaluate(t),u=r[a+1].evaluate(t);return"interpolate"===this.operator?Ge[this.type.kind.toLowerCase()](c,u,l):"interpolate-hcl"===this.operator?ir.reverse(ir.interpolate(ir.forward(c),ir.forward(u),l)):nr.reverse(nr.interpolate(nr.forward(c),nr.forward(u),l))},or.prototype.eachChild=function(t){t(this.input);for(var e=0,r=this.outputs;e<r.length;e+=1){t(r[e])}},or.prototype.outputDefined=function(){return this.outputs.every((function(t){return t.outputDefined()}))},or.prototype.serialize=function(){var t;t="linear"===this.interpolation.name?["linear"]:"exponential"===this.interpolation.name?1===this.interpolation.base?["linear"]:["exponential",this.interpolation.base]:["cubic-bezier"].concat(this.interpolation.controlPoints);for(var e=[this.operator,t,this.input.serialize()],r=0;r<this.labels.length;r++)e.push(this.labels[r],this.outputs[r].serialize());return e};var lr=function(t,e){this.type=t,this.args=e};lr.parse=function(t,e){if(t.length<2)return e.error("Expectected at least one argument.");var r=null,n=e.expectedType;n&&"value"!==n.kind&&(r=n);for(var i=[],a=0,o=t.slice(1);a<o.length;a+=1){var s=o[a],l=e.parse(s,1+i.length,r,void 0,{typeAnnotation:"omit"});if(!l)return null;r=r||l.type,i.push(l)}var c=n&&i.some((function(t){return Jt(n,t.type)}));return new lr(c?Ht:r,i)},lr.prototype.evaluate=function(t){for(var e,r=null,n=0,i=0,a=this.args;i<a.length;i+=1){if(n++,(r=a[i].evaluate(t))&&r instanceof ie&&!r.available&&(e||(e=r.name),r=null,n===this.args.length&&(r=e)),null!==r)break}return r},lr.prototype.eachChild=function(t){this.args.forEach(t)},lr.prototype.outputDefined=function(){return this.args.every((function(t){return t.outputDefined()}))},lr.prototype.serialize=function(){var t=["coalesce"];return this.eachChild((function(e){t.push(e.serialize())})),t};var cr=function(t,e){this.type=e.type,this.bindings=[].concat(t),this.result=e};cr.prototype.evaluate=function(t){return this.result.evaluate(t)},cr.prototype.eachChild=function(t){for(var e=0,r=this.bindings;e<r.length;e+=1){t(r[e][1])}t(this.result)},cr.parse=function(t,e){if(t.length<4)return e.error("Expected at least 3 arguments, but found "+(t.length-1)+" instead.");for(var r=[],n=1;n<t.length-1;n+=2){var i=t[n];if("string"!=typeof i)return e.error("Expected string, but found "+typeof i+" instead.",n);if(/[^a-zA-Z0-9_]/.test(i))return e.error("Variable names must contain only alphanumeric characters or '_'.",n);var a=e.parse(t[n+1],n+1);if(!a)return null;r.push([i,a])}var o=e.parse(t[t.length-1],t.length-1,e.expectedType,r);return o?new cr(r,o):null},cr.prototype.outputDefined=function(){return this.result.outputDefined()},cr.prototype.serialize=function(){for(var t=["let"],e=0,r=this.bindings;e<r.length;e+=1){var n=r[e],i=n[0],a=n[1];t.push(i,a.serialize())}return t.push(this.result.serialize()),t};var ur=function(t,e,r){this.type=t,this.index=e,this.input=r};ur.parse=function(t,e){if(3!==t.length)return e.error("Expected 2 arguments, but found "+(t.length-1)+" instead.");var r=e.parse(t[1],1,Bt),n=e.parse(t[2],2,Wt(e.expectedType||Ht));if(!r||!n)return null;var i=n.type;return new ur(i.itemType,r,n)},ur.prototype.evaluate=function(t){var e=this.index.evaluate(t),r=this.input.evaluate(t);if(e<0)throw new ue("Array index out of bounds: "+e+" < 0.");if(e>=r.length)throw new ue("Array index out of bounds: "+e+" > "+(r.length-1)+".");if(e!==Math.floor(e))throw new ue("Array index must be an integer, but found "+e+" instead.");return r[e]},ur.prototype.eachChild=function(t){t(this.index),t(this.input)},ur.prototype.outputDefined=function(){return!1},ur.prototype.serialize=function(){return["at",this.index.serialize(),this.input.serialize()]};var fr=function(t,e){this.type=jt,this.needle=t,this.haystack=e};fr.parse=function(t,e){if(3!==t.length)return e.error("Expected 2 arguments, but found "+(t.length-1)+" instead.");var r=e.parse(t[1],1,Ht),n=e.parse(t[2],2,Ht);return r&&n?Kt(r.type,[jt,Nt,Bt,Ft,Ht])?new fr(r,n):e.error("Expected first argument to be of type boolean, string, number or null, but found "+Xt(r.type)+" instead"):null},fr.prototype.evaluate=function(t){var e=this.needle.evaluate(t),r=this.haystack.evaluate(t);if(!r)return!1;if(!Qt(e,["boolean","string","number","null"]))throw new ue("Expected first argument to be of type boolean, string, number or null, but found "+Xt(se(e))+" instead.");if(!Qt(r,["string","array"]))throw new ue("Expected second argument to be of type array or string, but found "+Xt(se(r))+" instead.");return r.indexOf(e)>=0},fr.prototype.eachChild=function(t){t(this.needle),t(this.haystack)},fr.prototype.outputDefined=function(){return!0},fr.prototype.serialize=function(){return["in",this.needle.serialize(),this.haystack.serialize()]};var hr=function(t,e,r){this.type=Bt,this.needle=t,this.haystack=e,this.fromIndex=r};hr.parse=function(t,e){if(t.length<=2||t.length>=5)return e.error("Expected 3 or 4 arguments, but found "+(t.length-1)+" instead.");var r=e.parse(t[1],1,Ht),n=e.parse(t[2],2,Ht);if(!r||!n)return null;if(!Kt(r.type,[jt,Nt,Bt,Ft,Ht]))return e.error("Expected first argument to be of type boolean, string, number or null, but found "+Xt(r.type)+" instead");if(4===t.length){var i=e.parse(t[3],3,Bt);return i?new hr(r,n,i):null}return new hr(r,n)},hr.prototype.evaluate=function(t){var e=this.needle.evaluate(t),r=this.haystack.evaluate(t);if(!Qt(e,["boolean","string","number","null"]))throw new ue("Expected first argument to be of type boolean, string, number or null, but found "+Xt(se(e))+" instead.");if(!Qt(r,["string","array"]))throw new ue("Expected second argument to be of type array or string, but found "+Xt(se(r))+" instead.");if(this.fromIndex){var n=this.fromIndex.evaluate(t);return r.indexOf(e,n)}return r.indexOf(e)},hr.prototype.eachChild=function(t){t(this.needle),t(this.haystack),this.fromIndex&&t(this.fromIndex)},hr.prototype.outputDefined=function(){return!1},hr.prototype.serialize=function(){if(null!=this.fromIndex&&void 0!==this.fromIndex){var t=this.fromIndex.serialize();return["index-of",this.needle.serialize(),this.haystack.serialize(),t]}return["index-of",this.needle.serialize(),this.haystack.serialize()]};var pr=function(t,e,r,n,i,a){this.inputType=t,this.type=e,this.input=r,this.cases=n,this.outputs=i,this.otherwise=a};pr.parse=function(t,e){if(t.length<5)return e.error("Expected at least 4 arguments, but found only "+(t.length-1)+".");if(t.length%2!=1)return e.error("Expected an even number of arguments.");var r,n;e.expectedType&&"value"!==e.expectedType.kind&&(n=e.expectedType);for(var i={},a=[],o=2;o<t.length-1;o+=2){var s=t[o],l=t[o+1];Array.isArray(s)||(s=[s]);var c=e.concat(o);if(0===s.length)return c.error("Expected at least one branch label.");for(var u=0,f=s;u<f.length;u+=1){var h=f[u];if("number"!=typeof h&&"string"!=typeof h)return c.error("Branch labels must be numbers or strings.");if("number"==typeof h&&Math.abs(h)>Number.MAX_SAFE_INTEGER)return c.error("Branch labels must be integers no larger than "+Number.MAX_SAFE_INTEGER+".");if("number"==typeof h&&Math.floor(h)!==h)return c.error("Numeric branch labels must be integer values.");if(r){if(c.checkSubtype(r,se(h)))return null}else r=se(h);if(void 0!==i[String(h)])return c.error("Branch labels must be unique.");i[String(h)]=a.length}var p=e.parse(l,o,n);if(!p)return null;n=n||p.type,a.push(p)}var d=e.parse(t[1],1,Ht);if(!d)return null;var m=e.parse(t[t.length-1],t.length-1,n);return m?"value"!==d.type.kind&&e.concat(1).checkSubtype(r,d.type)?null:new pr(r,n,d,i,a,m):null},pr.prototype.evaluate=function(t){var e=this.input.evaluate(t);return(se(e)===this.inputType&&this.outputs[this.cases[e]]||this.otherwise).evaluate(t)},pr.prototype.eachChild=function(t){t(this.input),this.outputs.forEach(t),t(this.otherwise)},pr.prototype.outputDefined=function(){return this.outputs.every((function(t){return t.outputDefined()}))&&this.otherwise.outputDefined()},pr.prototype.serialize=function(){for(var t=this,e=["match",this.input.serialize()],r=[],n={},i=0,a=Object.keys(this.cases).sort();i<a.length;i+=1){var o=a[i];void 0===(f=n[this.cases[o]])?(n[this.cases[o]]=r.length,r.push([this.cases[o],[o]])):r[f][1].push(o)}for(var s=function(e){return"number"===t.inputType.kind?Number(e):e},l=0,c=r;l<c.length;l+=1){var u=c[l],f=u[0],h=u[1];1===h.length?e.push(s(h[0])):e.push(h.map(s)),e.push(this.outputs[outputIndex$1].serialize())}return e.push(this.otherwise.serialize()),e};var dr=function(t,e,r){this.type=t,this.branches=e,this.otherwise=r};dr.parse=function(t,e){if(t.length<4)return e.error("Expected at least 3 arguments, but found only "+(t.length-1)+".");if(t.length%2!=0)return e.error("Expected an odd number of arguments.");var r;e.expectedType&&"value"!==e.expectedType.kind&&(r=e.expectedType);for(var n=[],i=1;i<t.length-1;i+=2){var a=e.parse(t[i],i,jt);if(!a)return null;var o=e.parse(t[i+1],i+1,r);if(!o)return null;n.push([a,o]),r=r||o.type}var s=e.parse(t[t.length-1],t.length-1,r);return s?new dr(r,n,s):null},dr.prototype.evaluate=function(t){for(var e=0,r=this.branches;e<r.length;e+=1){var n=r[e],i=n[0],a=n[1];if(i.evaluate(t))return a.evaluate(t)}return this.otherwise.evaluate(t)},dr.prototype.eachChild=function(t){for(var e=0,r=this.branches;e<r.length;e+=1){var n=r[e],i=n[0],a=n[1];t(i),t(a)}t(this.otherwise)},dr.prototype.outputDefined=function(){return this.branches.every((function(t){t[0];return t[1].outputDefined()}))&&this.otherwise.outputDefined()},dr.prototype.serialize=function(){var t=["case"];return this.eachChild((function(e){t.push(e.serialize())})),t};var mr=function(t,e,r,n){this.type=t,this.input=e,this.beginIndex=r,this.endIndex=n};function gr(t,e){return"=="===t||"!="===t?"boolean"===e.kind||"string"===e.kind||"number"===e.kind||"null"===e.kind||"value"===e.kind:"string"===e.kind||"number"===e.kind||"value"===e.kind}function vr(t,e,r,n){return 0===n.compare(e,r)}function yr(t,e,r){var n="=="!==t&&"!="!==t;return function(){function i(t,e,r){this.type=jt,this.lhs=t,this.rhs=e,this.collator=r,this.hasUntypedArgument="value"===t.type.kind||"value"===e.type.kind}return i.parse=function(t,e){if(3!==t.length&&4!==t.length)return e.error("Expected two or three arguments.");var r=t[0],a=e.parse(t[1],1,Ht);if(!a)return null;if(!gr(r,a.type))return e.concat(1).error('"'+r+"\" comparisons are not supported for type '"+Xt(a.type)+"'.");var o=e.parse(t[2],2,Ht);if(!o)return null;if(!gr(r,o.type))return e.concat(2).error('"'+r+"\" comparisons are not supported for type '"+Xt(o.type)+"'.");if(a.type.kind!==o.type.kind&&"value"!==a.type.kind&&"value"!==o.type.kind)return e.error("Cannot compare types '"+Xt(a.type)+"' and '"+Xt(o.type)+"'.");n&&("value"===a.type.kind&&"value"!==o.type.kind?a=new he(o.type,[a]):"value"!==a.type.kind&&"value"===o.type.kind&&(o=new he(a.type,[o])));var s=null;if(4===t.length){if("string"!==a.type.kind&&"string"!==o.type.kind&&"value"!==a.type.kind&&"value"!==o.type.kind)return e.error("Cannot use collator to compare non-string types.");if(!(s=e.parse(t[3],3,qt)))return null}return new i(a,o,s)},i.prototype.evaluate=function(i){var a=this.lhs.evaluate(i),o=this.rhs.evaluate(i);if(n&&this.hasUntypedArgument){var s=se(a),l=se(o);if(s.kind!==l.kind||"string"!==s.kind&&"number"!==s.kind)throw new ue('Expected arguments for "'+t+'" to be (string, string) or (number, number), but found ('+s.kind+", "+l.kind+") instead.")}if(this.collator&&!n&&this.hasUntypedArgument){var c=se(a),u=se(o);if("string"!==c.kind||"string"!==u.kind)return e(i,a,o)}return this.collator?r(i,a,o,this.collator.evaluate(i)):e(i,a,o)},i.prototype.eachChild=function(t){t(this.lhs),t(this.rhs),this.collator&&t(this.collator)},i.prototype.outputDefined=function(){return!0},i.prototype.serialize=function(){var e=[t];return this.eachChild((function(t){e.push(t.serialize())})),e},i}()}mr.parse=function(t,e){if(t.length<=2||t.length>=5)return e.error("Expected 3 or 4 arguments, but found "+(t.length-1)+" instead.");var r=e.parse(t[1],1,Ht),n=e.parse(t[2],2,Bt);if(!r||!n)return null;if(!Kt(r.type,[Wt(Ht),Nt,Ht]))return e.error("Expected first argument to be of type array or string, but found "+Xt(r.type)+" instead");if(4===t.length){var i=e.parse(t[3],3,Bt);return i?new mr(r.type,r,n,i):null}return new mr(r.type,r,n)},mr.prototype.evaluate=function(t){var e=this.input.evaluate(t),r=this.beginIndex.evaluate(t);if(!Qt(e,["string","array"]))throw new ue("Expected first argument to be of type array or string, but found "+Xt(se(e))+" instead.");if(this.endIndex){var n=this.endIndex.evaluate(t);return e.slice(r,n)}return e.slice(r)},mr.prototype.eachChild=function(t){t(this.input),t(this.beginIndex),this.endIndex&&t(this.endIndex)},mr.prototype.outputDefined=function(){return!1},mr.prototype.serialize=function(){if(null!=this.endIndex&&void 0!==this.endIndex){var t=this.endIndex.serialize();return["slice",this.input.serialize(),this.beginIndex.serialize(),t]}return["slice",this.input.serialize(),this.beginIndex.serialize()]};var xr=yr("==",(function(t,e,r){return e===r}),vr),br=yr("!=",(function(t,e,r){return e!==r}),(function(t,e,r,n){return!vr(0,e,r,n)})),_r=yr("<",(function(t,e,r){return e<r}),(function(t,e,r,n){return n.compare(e,r)<0})),wr=yr(">",(function(t,e,r){return e>r}),(function(t,e,r,n){return n.compare(e,r)>0})),Tr=yr("<=",(function(t,e,r){return e<=r}),(function(t,e,r,n){return n.compare(e,r)<=0})),kr=yr(">=",(function(t,e,r){return e>=r}),(function(t,e,r,n){return n.compare(e,r)>=0})),Ar=function(t,e,r,n,i){this.type=Nt,this.number=t,this.locale=e,this.currency=r,this.minFractionDigits=n,this.maxFractionDigits=i};Ar.parse=function(t,e){if(3!==t.length)return e.error("Expected two arguments.");var r=e.parse(t[1],1,Bt);if(!r)return null;var n=t[2];if("object"!=typeof n||Array.isArray(n))return e.error("NumberFormat options argument must be an object.");var i=null;if(n.locale&&!(i=e.parse(n.locale,1,Nt)))return null;var a=null;if(n.currency&&!(a=e.parse(n.currency,1,Nt)))return null;var o=null;if(n["min-fraction-digits"]&&!(o=e.parse(n["min-fraction-digits"],1,Bt)))return null;var s=null;return n["max-fraction-digits"]&&!(s=e.parse(n["max-fraction-digits"],1,Bt))?null:new Ar(r,i,a,o,s)},Ar.prototype.evaluate=function(t){return new Intl.NumberFormat(this.locale?this.locale.evaluate(t):[],{style:this.currency?"currency":"decimal",currency:this.currency?this.currency.evaluate(t):void 0,minimumFractionDigits:this.minFractionDigits?this.minFractionDigits.evaluate(t):void 0,maximumFractionDigits:this.maxFractionDigits?this.maxFractionDigits.evaluate(t):void 0}).format(this.number.evaluate(t))},Ar.prototype.eachChild=function(t){t(this.number),this.locale&&t(this.locale),this.currency&&t(this.currency),this.minFractionDigits&&t(this.minFractionDigits),this.maxFractionDigits&&t(this.maxFractionDigits)},Ar.prototype.outputDefined=function(){return!1},Ar.prototype.serialize=function(){var t={};return this.locale&&(t.locale=this.locale.serialize()),this.currency&&(t.currency=this.currency.serialize()),this.minFractionDigits&&(t["min-fraction-digits"]=this.minFractionDigits.serialize()),this.maxFractionDigits&&(t["max-fraction-digits"]=this.maxFractionDigits.serialize()),["number-format",this.number.serialize(),t]};var Mr=function(t){this.type=Bt,this.input=t};Mr.parse=function(t,e){if(2!==t.length)return e.error("Expected 1 argument, but found "+(t.length-1)+" instead.");var r=e.parse(t[1],1);return r?"array"!==r.type.kind&&"string"!==r.type.kind&&"value"!==r.type.kind?e.error("Expected argument of type string or array, but found "+Xt(r.type)+" instead."):new Mr(r):null},Mr.prototype.evaluate=function(t){var e=this.input.evaluate(t);if("string"==typeof e)return e.length;if(Array.isArray(e))return e.length;throw new ue("Expected value to be of type string or array, but found "+Xt(se(e))+" instead.")},Mr.prototype.eachChild=function(t){t(this.input)},Mr.prototype.outputDefined=function(){return!1},Mr.prototype.serialize=function(){var t=["length"];return this.eachChild((function(e){t.push(e.serialize())})),t};var Sr={"==":xr,"!=":br,">":wr,"<":_r,">=":kr,"<=":Tr,array:he,at:ur,boolean:he,case:dr,coalesce:lr,collator:be,format:pe,image:de,in:fr,"index-of":hr,interpolate:or,"interpolate-hcl":or,"interpolate-lab":or,length:Mr,let:cr,literal:ce,match:pr,number:he,"number-format":Ar,object:he,slice:mr,step:He,string:he,"to-boolean":ge,"to-color":ge,"to-number":ge,"to-string":ge,var:je,within:Re};function Er(t,e){var r=e[0],n=e[1],i=e[2],a=e[3];r=r.evaluate(t),n=n.evaluate(t),i=i.evaluate(t);var o=a?a.evaluate(t):1,s=ae(r,n,i,o);if(s)throw new ue(s);return new te(r/255*o,n/255*o,i/255*o,o)}function Lr(t,e){return t in e}function Cr(t,e){var r=e[t];return void 0===r?null:r}function Pr(t){return{type:t}}function Ir(t){return{result:"success",value:t}}function Or(t){return{result:"error",value:t}}function zr(t){return"data-driven"===t["property-type"]||"cross-faded-data-driven"===t["property-type"]}function Dr(t){return!!t.expression&&t.expression.parameters.indexOf("zoom")>-1}function Rr(t){return!!t.expression&&t.expression.interpolated}function Fr(t){return t instanceof Number?"number":t instanceof String?"string":t instanceof Boolean?"boolean":Array.isArray(t)?"array":null===t?"null":typeof t}function Br(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}function Nr(t){return t}function jr(t,e,r){return void 0!==t?t:void 0!==e?e:void 0!==r?r:void 0}function Ur(t,e,r,n,i){return jr(typeof r===i?n[r]:void 0,t.default,e.default)}function Vr(t,e,r){if("number"!==Fr(r))return jr(t.default,e.default);var n=t.stops.length;if(1===n)return t.stops[0][1];if(r<=t.stops[0][0])return t.stops[0][1];if(r>=t.stops[n-1][0])return t.stops[n-1][1];var i=Ve(t.stops.map((function(t){return t[0]})),r);return t.stops[i][1]}function Hr(t,e,r){var n=void 0!==t.base?t.base:1;if("number"!==Fr(r))return jr(t.default,e.default);var i=t.stops.length;if(1===i)return t.stops[0][1];if(r<=t.stops[0][0])return t.stops[0][1];if(r>=t.stops[i-1][0])return t.stops[i-1][1];var a=Ve(t.stops.map((function(t){return t[0]})),r),o=function(t,e,r,n){var i=n-r,a=t-r;return 0===i?0:1===e?a/i:(Math.pow(e,a)-1)/(Math.pow(e,i)-1)}(r,n,t.stops[a][0],t.stops[a+1][0]),s=t.stops[a][1],l=t.stops[a+1][1],c=Ge[e.type]||Nr;if(t.colorSpace&&"rgb"!==t.colorSpace){var u=ar[t.colorSpace];c=function(t,e){return u.reverse(u.interpolate(u.forward(t),u.forward(e),o))}}return"function"==typeof s.evaluate?{evaluate:function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];var r=s.evaluate.apply(void 0,t),n=l.evaluate.apply(void 0,t);if(void 0!==r&&void 0!==n)return c(r,n,o)}}:c(s,l,o)}function qr(t,e,r){return"color"===e.type?r=te.parse(r):"formatted"===e.type?r=ne.fromString(r.toString()):"resolvedImage"===e.type?r=ie.fromString(r.toString()):Fr(r)===e.type||"enum"===e.type&&e.values[r]||(r=void 0),jr(r,t.default,e.default)}xe.register(Sr,{error:[{kind:"error"},[Nt],function(t,e){var r=e[0];throw new ue(r.evaluate(t))}],typeof:[Nt,[Ht],function(t,e){return Xt(se(e[0].evaluate(t)))}],"to-rgba":[Wt(Bt,4),[Ut],function(t,e){return e[0].evaluate(t).toArray()}],rgb:[Ut,[Bt,Bt,Bt],Er],rgba:[Ut,[Bt,Bt,Bt,Bt],Er],has:{type:jt,overloads:[[[Nt],function(t,e){return Lr(e[0].evaluate(t),t.properties())}],[[Nt,Vt],function(t,e){var r=e[0],n=e[1];return Lr(r.evaluate(t),n.evaluate(t))}]]},get:{type:Ht,overloads:[[[Nt],function(t,e){return Cr(e[0].evaluate(t),t.properties())}],[[Nt,Vt],function(t,e){var r=e[0],n=e[1];return Cr(r.evaluate(t),n.evaluate(t))}]]},"feature-state":[Ht,[Nt],function(t,e){return Cr(e[0].evaluate(t),t.featureState||{})}],properties:[Vt,[],function(t){return t.properties()}],"geometry-type":[Nt,[],function(t){return t.geometryType()}],id:[Ht,[],function(t){return t.id()}],zoom:[Bt,[],function(t){return t.globals.zoom}],"heatmap-density":[Bt,[],function(t){return t.globals.heatmapDensity||0}],"line-progress":[Bt,[],function(t){return t.globals.lineProgress||0}],accumulated:[Ht,[],function(t){return void 0===t.globals.accumulated?null:t.globals.accumulated}],"+":[Bt,Pr(Bt),function(t,e){for(var r=0,n=0,i=e;n<i.length;n+=1){r+=i[n].evaluate(t)}return r}],"*":[Bt,Pr(Bt),function(t,e){for(var r=1,n=0,i=e;n<i.length;n+=1){r*=i[n].evaluate(t)}return r}],"-":{type:Bt,overloads:[[[Bt,Bt],function(t,e){var r=e[0],n=e[1];return r.evaluate(t)-n.evaluate(t)}],[[Bt],function(t,e){return-e[0].evaluate(t)}]]},"/":[Bt,[Bt,Bt],function(t,e){var r=e[0],n=e[1];return r.evaluate(t)/n.evaluate(t)}],"%":[Bt,[Bt,Bt],function(t,e){var r=e[0],n=e[1];return r.evaluate(t)%n.evaluate(t)}],ln2:[Bt,[],function(){return Math.LN2}],pi:[Bt,[],function(){return Math.PI}],e:[Bt,[],function(){return Math.E}],"^":[Bt,[Bt,Bt],function(t,e){var r=e[0],n=e[1];return Math.pow(r.evaluate(t),n.evaluate(t))}],sqrt:[Bt,[Bt],function(t,e){var r=e[0];return Math.sqrt(r.evaluate(t))}],log10:[Bt,[Bt],function(t,e){var r=e[0];return Math.log(r.evaluate(t))/Math.LN10}],ln:[Bt,[Bt],function(t,e){var r=e[0];return Math.log(r.evaluate(t))}],log2:[Bt,[Bt],function(t,e){var r=e[0];return Math.log(r.evaluate(t))/Math.LN2}],sin:[Bt,[Bt],function(t,e){var r=e[0];return Math.sin(r.evaluate(t))}],cos:[Bt,[Bt],function(t,e){var r=e[0];return Math.cos(r.evaluate(t))}],tan:[Bt,[Bt],function(t,e){var r=e[0];return Math.tan(r.evaluate(t))}],asin:[Bt,[Bt],function(t,e){var r=e[0];return Math.asin(r.evaluate(t))}],acos:[Bt,[Bt],function(t,e){var r=e[0];return Math.acos(r.evaluate(t))}],atan:[Bt,[Bt],function(t,e){var r=e[0];return Math.atan(r.evaluate(t))}],min:[Bt,Pr(Bt),function(t,e){return Math.min.apply(Math,e.map((function(e){return e.evaluate(t)})))}],max:[Bt,Pr(Bt),function(t,e){return Math.max.apply(Math,e.map((function(e){return e.evaluate(t)})))}],abs:[Bt,[Bt],function(t,e){var r=e[0];return Math.abs(r.evaluate(t))}],round:[Bt,[Bt],function(t,e){var r=e[0].evaluate(t);return r<0?-Math.round(-r):Math.round(r)}],floor:[Bt,[Bt],function(t,e){var r=e[0];return Math.floor(r.evaluate(t))}],ceil:[Bt,[Bt],function(t,e){var r=e[0];return Math.ceil(r.evaluate(t))}],"filter-==":[jt,[Nt,Ht],function(t,e){var r=e[0],n=e[1];return t.properties()[r.value]===n.value}],"filter-id-==":[jt,[Ht],function(t,e){var r=e[0];return t.id()===r.value}],"filter-type-==":[jt,[Nt],function(t,e){var r=e[0];return t.geometryType()===r.value}],"filter-<":[jt,[Nt,Ht],function(t,e){var r=e[0],n=e[1],i=t.properties()[r.value],a=n.value;return typeof i==typeof a&&i<a}],"filter-id-<":[jt,[Ht],function(t,e){var r=e[0],n=t.id(),i=r.value;return typeof n==typeof i&&n<i}],"filter->":[jt,[Nt,Ht],function(t,e){var r=e[0],n=e[1],i=t.properties()[r.value],a=n.value;return typeof i==typeof a&&i>a}],"filter-id->":[jt,[Ht],function(t,e){var r=e[0],n=t.id(),i=r.value;return typeof n==typeof i&&n>i}],"filter-<=":[jt,[Nt,Ht],function(t,e){var r=e[0],n=e[1],i=t.properties()[r.value],a=n.value;return typeof i==typeof a&&i<=a}],"filter-id-<=":[jt,[Ht],function(t,e){var r=e[0],n=t.id(),i=r.value;return typeof n==typeof i&&n<=i}],"filter->=":[jt,[Nt,Ht],function(t,e){var r=e[0],n=e[1],i=t.properties()[r.value],a=n.value;return typeof i==typeof a&&i>=a}],"filter-id->=":[jt,[Ht],function(t,e){var r=e[0],n=t.id(),i=r.value;return typeof n==typeof i&&n>=i}],"filter-has":[jt,[Ht],function(t,e){return e[0].value in t.properties()}],"filter-has-id":[jt,[],function(t){return null!==t.id()&&void 0!==t.id()}],"filter-type-in":[jt,[Wt(Nt)],function(t,e){return e[0].value.indexOf(t.geometryType())>=0}],"filter-id-in":[jt,[Wt(Ht)],function(t,e){return e[0].value.indexOf(t.id())>=0}],"filter-in-small":[jt,[Nt,Wt(Ht)],function(t,e){var r=e[0];return e[1].value.indexOf(t.properties()[r.value])>=0}],"filter-in-large":[jt,[Nt,Wt(Ht)],function(t,e){var r=e[0],n=e[1];return function(t,e,r,n){for(;r<=n;){var i=r+n>>1;if(e[i]===t)return!0;e[i]>t?n=i-1:r=i+1}return!1}(t.properties()[r.value],n.value,0,n.value.length-1)}],all:{type:jt,overloads:[[[jt,jt],function(t,e){var r=e[0],n=e[1];return r.evaluate(t)&&n.evaluate(t)}],[Pr(jt),function(t,e){for(var r=0,n=e;r<n.length;r+=1){if(!n[r].evaluate(t))return!1}return!0}]]},any:{type:jt,overloads:[[[jt,jt],function(t,e){var r=e[0],n=e[1];return r.evaluate(t)||n.evaluate(t)}],[Pr(jt),function(t,e){for(var r=0,n=e;r<n.length;r+=1){if(n[r].evaluate(t))return!0}return!1}]]},"!":[jt,[jt],function(t,e){return!e[0].evaluate(t)}],"is-supported-script":[jt,[Nt],function(t,e){var r=e[0],n=t.globals&&t.globals.isSupportedScript;return!n||n(r.evaluate(t))}],upcase:[Nt,[Nt],function(t,e){return e[0].evaluate(t).toUpperCase()}],downcase:[Nt,[Nt],function(t,e){return e[0].evaluate(t).toLowerCase()}],concat:[Nt,Pr(Ht),function(t,e){return e.map((function(e){return le(e.evaluate(t))})).join("")}],"resolved-locale":[Nt,[qt],function(t,e){return e[0].evaluate(t).resolvedLocale()}]});var Gr=function(t,e){this.expression=t,this._warningHistory={},this._evaluator=new ye,this._defaultValue=e?function(t){return"color"===t.type&&Br(t.default)?new te(0,0,0,0):"color"===t.type?te.parse(t.default)||null:void 0===t.default?null:t.default}(e):null,this._enumValues=e&&"enum"===e.type?e.values:null};function Yr(t){return Array.isArray(t)&&t.length>0&&"string"==typeof t[0]&&t[0]in Sr}function Wr(t,e){var r=new Ue(Sr,[],e?function(t){var e={color:Ut,string:Nt,number:Bt,enum:Nt,boolean:jt,formatted:Gt,resolvedImage:Yt};if("array"===t.type)return Wt(e[t.value]||Ht,t.length);return e[t.type]}(e):void 0),n=r.parse(t,void 0,void 0,void 0,e&&"string"===e.type?{typeAnnotation:"coerce"}:void 0);return n?Ir(new Gr(n,e)):Or(r.errors)}Gr.prototype.evaluateWithoutErrorHandling=function(t,e,r,n,i,a){return this._evaluator.globals=t,this._evaluator.feature=e,this._evaluator.featureState=r,this._evaluator.canonical=n,this._evaluator.availableImages=i||null,this._evaluator.formattedSection=a,this.expression.evaluate(this._evaluator)},Gr.prototype.evaluate=function(t,e,r,n,i,a){this._evaluator.globals=t,this._evaluator.feature=e||null,this._evaluator.featureState=r||null,this._evaluator.canonical=n,this._evaluator.availableImages=i||null,this._evaluator.formattedSection=a||null;try{var o=this.expression.evaluate(this._evaluator);if(null==o||"number"==typeof o&&o!=o)return this._defaultValue;if(this._enumValues&&!(o in this._enumValues))throw new ue("Expected value to be one of "+Object.keys(this._enumValues).map((function(t){return JSON.stringify(t)})).join(", ")+", but found "+JSON.stringify(o)+" instead.");return o}catch(t){return this._warningHistory[t.message]||(this._warningHistory[t.message]=!0,"undefined"!=typeof console&&console.warn(t.message)),this._defaultValue}};var Xr=function(t,e){this.kind=t,this._styleExpression=e,this.isStateDependent="constant"!==t&&!Be(e.expression)};Xr.prototype.evaluateWithoutErrorHandling=function(t,e,r,n,i,a){return this._styleExpression.evaluateWithoutErrorHandling(t,e,r,n,i,a)},Xr.prototype.evaluate=function(t,e,r,n,i,a){return this._styleExpression.evaluate(t,e,r,n,i,a)};var Zr=function(t,e,r,n){this.kind=t,this.zoomStops=r,this._styleExpression=e,this.isStateDependent="camera"!==t&&!Be(e.expression),this.interpolationType=n};function Jr(t,e){if("error"===(t=Wr(t,e)).result)return t;var r=t.value.expression,n=Fe(r);if(!n&&!zr(e))return Or([new Dt("","data expressions not supported")]);var i=Ne(r,["zoom"]);if(!i&&!Dr(e))return Or([new Dt("","zoom expressions not supported")]);var a=function t(e){var r=null;if(e instanceof cr)r=t(e.result);else if(e instanceof lr)for(var n=0,i=e.args;n<i.length;n+=1){var a=i[n];if(r=t(a))break}else(e instanceof He||e instanceof or)&&e.input instanceof xe&&"zoom"===e.input.name&&(r=e);if(r instanceof Dt)return r;return e.eachChild((function(e){var n=t(e);n instanceof Dt?r=n:!r&&n?r=new Dt("",'"zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.'):r&&n&&r!==n&&(r=new Dt("",'Only one zoom-based "step" or "interpolate" subexpression may be used in an expression.'))})),r}(r);if(!a&&!i)return Or([new Dt("",'"zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.')]);if(a instanceof Dt)return Or([a]);if(a instanceof or&&!Rr(e))return Or([new Dt("",'"interpolate" expressions cannot be used with this property')]);if(!a)return Ir(new Xr(n?"constant":"source",t.value));var o=a instanceof or?a.interpolation:void 0;return Ir(new Zr(n?"camera":"composite",t.value,a.labels,o))}Zr.prototype.evaluateWithoutErrorHandling=function(t,e,r,n,i,a){return this._styleExpression.evaluateWithoutErrorHandling(t,e,r,n,i,a)},Zr.prototype.evaluate=function(t,e,r,n,i,a){return this._styleExpression.evaluate(t,e,r,n,i,a)},Zr.prototype.interpolationFactor=function(t,e,r){return this.interpolationType?or.interpolationFactor(this.interpolationType,t,e,r):0};var Kr=function(t,e){this._parameters=t,this._specification=e,It(this,function t(e,r){var n,i,a,o="color"===r.type,s=e.stops&&"object"==typeof e.stops[0][0],l=s||void 0!==e.property,c=s||!l,u=e.type||(Rr(r)?"exponential":"interval");if(o&&((e=It({},e)).stops&&(e.stops=e.stops.map((function(t){return[t[0],te.parse(t[1])]}))),e.default?e.default=te.parse(e.default):e.default=te.parse(r.default)),e.colorSpace&&"rgb"!==e.colorSpace&&!ar[e.colorSpace])throw new Error("Unknown color space: "+e.colorSpace);if("exponential"===u)n=Hr;else if("interval"===u)n=Vr;else if("categorical"===u){n=Ur,i=Object.create(null);for(var f=0,h=e.stops;f<h.length;f+=1){var p=h[f];i[p[0]]=p[1]}a=typeof e.stops[0][0]}else{if("identity"!==u)throw new Error('Unknown function type "'+u+'"');n=qr}if(s){for(var d={},m=[],g=0;g<e.stops.length;g++){var v=e.stops[g],y=v[0].zoom;void 0===d[y]&&(d[y]={zoom:y,type:e.type,property:e.property,default:e.default,stops:[]},m.push(y)),d[y].stops.push([v[0].value,v[1]])}for(var x=[],b=0,_=m;b<_.length;b+=1){var w=_[b];x.push([d[w].zoom,t(d[w],r)])}var T={name:"linear"};return{kind:"composite",interpolationType:T,interpolationFactor:or.interpolationFactor.bind(void 0,T),zoomStops:x.map((function(t){return t[0]})),evaluate:function(t,n){var i=t.zoom;return Hr({stops:x,base:e.base},r,i).evaluate(i,n)}}}if(c){var k="exponential"===u?{name:"exponential",base:void 0!==e.base?e.base:1}:null;return{kind:"camera",interpolationType:k,interpolationFactor:or.interpolationFactor.bind(void 0,k),zoomStops:e.stops.map((function(t){return t[0]})),evaluate:function(t){var o=t.zoom;return n(e,r,o,i,a)}}}return{kind:"source",evaluate:function(t,o){var s=o&&o.properties?o.properties[e.property]:void 0;return void 0===s?jr(e.default,r.default):n(e,r,s,i,a)}}}(this._parameters,this._specification))};function Qr(t){var e=t.key,r=t.value,n=t.valueSpec||{},i=t.objectElementValidators||{},a=t.style,o=t.styleSpec,s=[],l=Fr(r);if("object"!==l)return[new Ct(e,r,"object expected, "+l+" found")];for(var c in r){var u=c.split(".")[0],f=n[u]||n["*"],h=void 0;if(i[u])h=i[u];else if(n[u])h=kn;else if(i["*"])h=i["*"];else{if(!n["*"]){s.push(new Ct(e,r[c],'unknown property "'+c+'"'));continue}h=kn}s=s.concat(h({key:(e?e+".":e)+c,value:r[c],valueSpec:f,style:a,styleSpec:o,object:r,objectKey:c},r))}for(var p in n)i[p]||n[p].required&&void 0===n[p].default&&void 0===r[p]&&s.push(new Ct(e,r,'missing required property "'+p+'"'));return s}function $r(t){var e=t.value,r=t.valueSpec,n=t.style,i=t.styleSpec,a=t.key,o=t.arrayElementValidator||kn;if("array"!==Fr(e))return[new Ct(a,e,"array expected, "+Fr(e)+" found")];if(r.length&&e.length!==r.length)return[new Ct(a,e,"array length "+r.length+" expected, length "+e.length+" found")];if(r["min-length"]&&e.length<r["min-length"])return[new Ct(a,e,"array length at least "+r["min-length"]+" expected, length "+e.length+" found")];var s={type:r.value,values:r.values};i.$version<7&&(s.function=r.function),"object"===Fr(r.value)&&(s=r.value);for(var l=[],c=0;c<e.length;c++)l=l.concat(o({array:e,arrayIndex:c,value:e[c],valueSpec:s,style:n,styleSpec:i,key:a+"["+c+"]"}));return l}function tn(t){var e=t.key,r=t.value,n=t.valueSpec,i=Fr(r);return"number"===i&&r!=r&&(i="NaN"),"number"!==i?[new Ct(e,r,"number expected, "+i+" found")]:"minimum"in n&&r<n.minimum?[new Ct(e,r,r+" is less than the minimum value "+n.minimum)]:"maximum"in n&&r>n.maximum?[new Ct(e,r,r+" is greater than the maximum value "+n.maximum)]:[]}function en(t){var e,r,n,i=t.valueSpec,a=Ot(t.value.type),o={},s="categorical"!==a&&void 0===t.value.property,l=!s,c="array"===Fr(t.value.stops)&&"array"===Fr(t.value.stops[0])&&"object"===Fr(t.value.stops[0][0]),u=Qr({key:t.key,value:t.value,valueSpec:t.styleSpec.function,style:t.style,styleSpec:t.styleSpec,objectElementValidators:{stops:function(t){if("identity"===a)return[new Ct(t.key,t.value,'identity function may not have a "stops" property')];var e=[],r=t.value;e=e.concat($r({key:t.key,value:r,valueSpec:t.valueSpec,style:t.style,styleSpec:t.styleSpec,arrayElementValidator:f})),"array"===Fr(r)&&0===r.length&&e.push(new Ct(t.key,r,"array must have at least one stop"));return e},default:function(t){return kn({key:t.key,value:t.value,valueSpec:i,style:t.style,styleSpec:t.styleSpec})}}});return"identity"===a&&s&&u.push(new Ct(t.key,t.value,'missing required property "property"')),"identity"===a||t.value.stops||u.push(new Ct(t.key,t.value,'missing required property "stops"')),"exponential"===a&&t.valueSpec.expression&&!Rr(t.valueSpec)&&u.push(new Ct(t.key,t.value,"exponential functions not supported")),t.styleSpec.$version>=8&&(l&&!zr(t.valueSpec)?u.push(new Ct(t.key,t.value,"property functions not supported")):s&&!Dr(t.valueSpec)&&u.push(new Ct(t.key,t.value,"zoom functions not supported"))),"categorical"!==a&&!c||void 0!==t.value.property||u.push(new Ct(t.key,t.value,'"property" property is required')),u;function f(t){var e=[],a=t.value,s=t.key;if("array"!==Fr(a))return[new Ct(s,a,"array expected, "+Fr(a)+" found")];if(2!==a.length)return[new Ct(s,a,"array length 2 expected, length "+a.length+" found")];if(c){if("object"!==Fr(a[0]))return[new Ct(s,a,"object expected, "+Fr(a[0])+" found")];if(void 0===a[0].zoom)return[new Ct(s,a,"object stop key must have zoom")];if(void 0===a[0].value)return[new Ct(s,a,"object stop key must have value")];if(n&&n>Ot(a[0].zoom))return[new Ct(s,a[0].zoom,"stop zoom values must appear in ascending order")];Ot(a[0].zoom)!==n&&(n=Ot(a[0].zoom),r=void 0,o={}),e=e.concat(Qr({key:s+"[0]",value:a[0],valueSpec:{zoom:{}},style:t.style,styleSpec:t.styleSpec,objectElementValidators:{zoom:tn,value:h}}))}else e=e.concat(h({key:s+"[0]",value:a[0],valueSpec:{},style:t.style,styleSpec:t.styleSpec},a));return Yr(zt(a[1]))?e.concat([new Ct(s+"[1]",a[1],"expressions are not allowed in function stops.")]):e.concat(kn({key:s+"[1]",value:a[1],valueSpec:i,style:t.style,styleSpec:t.styleSpec}))}function h(t,n){var s=Fr(t.value),l=Ot(t.value),c=null!==t.value?t.value:n;if(e){if(s!==e)return[new Ct(t.key,c,s+" stop domain type must match previous stop domain type "+e)]}else e=s;if("number"!==s&&"string"!==s&&"boolean"!==s)return[new Ct(t.key,c,"stop domain value must be a number, string, or boolean")];if("number"!==s&&"categorical"!==a){var u="number expected, "+s+" found";return zr(i)&&void 0===a&&(u+='\nIf you intended to use a categorical function, specify `"type": "categorical"`.'),[new Ct(t.key,c,u)]}return"categorical"!==a||"number"!==s||isFinite(l)&&Math.floor(l)===l?"categorical"!==a&&"number"===s&&void 0!==r&&l<r?[new Ct(t.key,c,"stop domain values must appear in ascending order")]:(r=l,"categorical"===a&&l in o?[new Ct(t.key,c,"stop domain values must be unique")]:(o[l]=!0,[])):[new Ct(t.key,c,"integer expected, found "+l)]}}function rn(t){var e=("property"===t.expressionContext?Jr:Wr)(zt(t.value),t.valueSpec);if("error"===e.result)return e.value.map((function(e){return new Ct(""+t.key+e.key,t.value,e.message)}));var r=e.value.expression||e.value._styleExpression.expression;if("property"===t.expressionContext&&"text-font"===t.propertyKey&&!r.outputDefined())return[new Ct(t.key,t.value,'Invalid data expression for "'+t.propertyKey+'". Output values must be contained as literals within the expression.')];if("property"===t.expressionContext&&"layout"===t.propertyType&&!Be(r))return[new Ct(t.key,t.value,'"feature-state" data expressions are not supported with layout properties.')];if("filter"===t.expressionContext&&!Be(r))return[new Ct(t.key,t.value,'"feature-state" data expressions are not supported with filters.')];if(t.expressionContext&&0===t.expressionContext.indexOf("cluster")){if(!Ne(r,["zoom","feature-state"]))return[new Ct(t.key,t.value,'"zoom" and "feature-state" expressions are not supported with cluster properties.')];if("cluster-initial"===t.expressionContext&&!Fe(r))return[new Ct(t.key,t.value,"Feature data expressions are not supported with initial expression part of cluster properties.")]}return[]}function nn(t){var e=t.key,r=t.value,n=t.valueSpec,i=[];return Array.isArray(n.values)?-1===n.values.indexOf(Ot(r))&&i.push(new Ct(e,r,"expected one of ["+n.values.join(", ")+"], "+JSON.stringify(r)+" found")):-1===Object.keys(n.values).indexOf(Ot(r))&&i.push(new Ct(e,r,"expected one of ["+Object.keys(n.values).join(", ")+"], "+JSON.stringify(r)+" found")),i}function an(t){if(!0===t||!1===t)return!0;if(!Array.isArray(t)||0===t.length)return!1;switch(t[0]){case"has":return t.length>=2&&"$id"!==t[1]&&"$type"!==t[1];case"in":return t.length>=3&&("string"!=typeof t[1]||Array.isArray(t[2]));case"!in":case"!has":case"none":return!1;case"==":case"!=":case">":case">=":case"<":case"<=":return 3!==t.length||Array.isArray(t[1])||Array.isArray(t[2]);case"any":case"all":for(var e=0,r=t.slice(1);e<r.length;e+=1){var n=r[e];if(!an(n)&&"boolean"!=typeof n)return!1}return!0;default:return!0}}Kr.deserialize=function(t){return new Kr(t._parameters,t._specification)},Kr.serialize=function(t){return{_parameters:t._parameters,_specification:t._specification}};var on={type:"boolean",default:!1,transition:!1,"property-type":"data-driven",expression:{interpolated:!1,parameters:["zoom","feature"]}};function sn(t){if(null==t)return{filter:function(){return!0},needGeometry:!1};an(t)||(t=cn(t));var e=Wr(t,on);if("error"===e.result)throw new Error(e.value.map((function(t){return t.key+": "+t.message})).join(", "));return{filter:function(t,r,n){return e.value.evaluate(t,r,{},n)},needGeometry:function t(e){if(!Array.isArray(e))return!1;if("within"===e[0])return!0;for(var r=1;r<e.length;r++)if(t(e[r]))return!0;return!1}(t)}}function ln(t,e){return t<e?-1:t>e?1:0}function cn(t){if(!t)return!0;var e,r=t[0];return t.length<=1?"any"!==r:"=="===r?un(t[1],t[2],"=="):"!="===r?pn(un(t[1],t[2],"==")):"<"===r||">"===r||"<="===r||">="===r?un(t[1],t[2],r):"any"===r?(e=t.slice(1),["any"].concat(e.map(cn))):"all"===r?["all"].concat(t.slice(1).map(cn)):"none"===r?["all"].concat(t.slice(1).map(cn).map(pn)):"in"===r?fn(t[1],t.slice(2)):"!in"===r?pn(fn(t[1],t.slice(2))):"has"===r?hn(t[1]):"!has"===r?pn(hn(t[1])):"within"!==r||t}function un(t,e,r){switch(t){case"$type":return["filter-type-"+r,e];case"$id":return["filter-id-"+r,e];default:return["filter-"+r,t,e]}}function fn(t,e){if(0===e.length)return!1;switch(t){case"$type":return["filter-type-in",["literal",e]];case"$id":return["filter-id-in",["literal",e]];default:return e.length>200&&!e.some((function(t){return typeof t!=typeof e[0]}))?["filter-in-large",t,["literal",e.sort(ln)]]:["filter-in-small",t,["literal",e]]}}function hn(t){switch(t){case"$type":return!0;case"$id":return["filter-has-id"];default:return["filter-has",t]}}function pn(t){return["!",t]}function dn(t){return an(zt(t.value))?rn(It({},t,{expressionContext:"filter",valueSpec:{value:"boolean"}})):function t(e){var r=e.value,n=e.key;if("array"!==Fr(r))return[new Ct(n,r,"array expected, "+Fr(r)+" found")];var i,a=e.styleSpec,o=[];if(r.length<1)return[new Ct(n,r,"filter array must have at least 1 element")];switch(o=o.concat(nn({key:n+"[0]",value:r[0],valueSpec:a.filter_operator,style:e.style,styleSpec:e.styleSpec})),Ot(r[0])){case"<":case"<=":case">":case">=":r.length>=2&&"$type"===Ot(r[1])&&o.push(new Ct(n,r,'"$type" cannot be use with operator "'+r[0]+'"'));case"==":case"!=":3!==r.length&&o.push(new Ct(n,r,'filter array for operator "'+r[0]+'" must have 3 elements'));case"in":case"!in":r.length>=2&&"string"!==(i=Fr(r[1]))&&o.push(new Ct(n+"[1]",r[1],"string expected, "+i+" found"));for(var s=2;s<r.length;s++)i=Fr(r[s]),"$type"===Ot(r[1])?o=o.concat(nn({key:n+"["+s+"]",value:r[s],valueSpec:a.geometry_type,style:e.style,styleSpec:e.styleSpec})):"string"!==i&&"number"!==i&&"boolean"!==i&&o.push(new Ct(n+"["+s+"]",r[s],"string, number, or boolean expected, "+i+" found"));break;case"any":case"all":case"none":for(var l=1;l<r.length;l++)o=o.concat(t({key:n+"["+l+"]",value:r[l],style:e.style,styleSpec:e.styleSpec}));break;case"has":case"!has":i=Fr(r[1]),2!==r.length?o.push(new Ct(n,r,'filter array for "'+r[0]+'" operator must have 2 elements')):"string"!==i&&o.push(new Ct(n+"[1]",r[1],"string expected, "+i+" found"));break;case"within":i=Fr(r[1]),2!==r.length?o.push(new Ct(n,r,'filter array for "'+r[0]+'" operator must have 2 elements')):"object"!==i&&o.push(new Ct(n+"[1]",r[1],"object expected, "+i+" found"))}return o}(t)}function mn(t,e){var r=t.key,n=t.style,i=t.styleSpec,a=t.value,o=t.objectKey,s=i[e+"_"+t.layerType];if(!s)return[];var l=o.match(/^(.*)-transition$/);if("paint"===e&&l&&s[l[1]]&&s[l[1]].transition)return kn({key:r,value:a,valueSpec:i.transition,style:n,styleSpec:i});var c,u=t.valueSpec||s[o];if(!u)return[new Ct(r,a,'unknown property "'+o+'"')];if("string"===Fr(a)&&zr(u)&&!u.tokens&&(c=/^{([^}]+)}$/.exec(a)))return[new Ct(r,a,'"'+o+'" does not support interpolation syntax\nUse an identity property function instead: `{ "type": "identity", "property": '+JSON.stringify(c[1])+" }`.")];var f=[];return"symbol"===t.layerType&&("text-field"===o&&n&&!n.glyphs&&f.push(new Ct(r,a,'use of "text-field" requires a style "glyphs" property')),"text-font"===o&&Br(zt(a))&&"identity"===Ot(a.type)&&f.push(new Ct(r,a,'"text-font" does not support identity functions'))),f.concat(kn({key:t.key,value:a,valueSpec:u,style:n,styleSpec:i,expressionContext:"property",propertyType:e,propertyKey:o}))}function gn(t){return mn(t,"paint")}function vn(t){return mn(t,"layout")}function yn(t){var e=[],r=t.value,n=t.key,i=t.style,a=t.styleSpec;r.type||r.ref||e.push(new Ct(n,r,'either "type" or "ref" is required'));var o,s=Ot(r.type),l=Ot(r.ref);if(r.id)for(var c=Ot(r.id),u=0;u<t.arrayIndex;u++){var f=i.layers[u];Ot(f.id)===c&&e.push(new Ct(n,r.id,'duplicate layer id "'+r.id+'", previously used at line '+f.id.__line__))}if("ref"in r)["type","source","source-layer","filter","layout"].forEach((function(t){t in r&&e.push(new Ct(n,r[t],'"'+t+'" is prohibited for ref layers'))})),i.layers.forEach((function(t){Ot(t.id)===l&&(o=t)})),o?o.ref?e.push(new Ct(n,r.ref,"ref cannot reference another ref layer")):s=Ot(o.type):e.push(new Ct(n,r.ref,'ref layer "'+l+'" not found'));else if("background"!==s)if(r.source){var h=i.sources&&i.sources[r.source],p=h&&Ot(h.type);h?"vector"===p&&"raster"===s?e.push(new Ct(n,r.source,'layer "'+r.id+'" requires a raster source')):"raster"===p&&"raster"!==s?e.push(new Ct(n,r.source,'layer "'+r.id+'" requires a vector source')):"vector"!==p||r["source-layer"]?"raster-dem"===p&&"hillshade"!==s?e.push(new Ct(n,r.source,"raster-dem source can only be used with layer type 'hillshade'.")):"line"!==s||!r.paint||!r.paint["line-gradient"]||"geojson"===p&&h.lineMetrics||e.push(new Ct(n,r,'layer "'+r.id+'" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.')):e.push(new Ct(n,r,'layer "'+r.id+'" must specify a "source-layer"')):e.push(new Ct(n,r.source,'source "'+r.source+'" not found'))}else e.push(new Ct(n,r,'missing required property "source"'));return e=e.concat(Qr({key:n,value:r,valueSpec:a.layer,style:t.style,styleSpec:t.styleSpec,objectElementValidators:{"*":function(){return[]},type:function(){return kn({key:n+".type",value:r.type,valueSpec:a.layer.type,style:t.style,styleSpec:t.styleSpec,object:r,objectKey:"type"})},filter:dn,layout:function(t){return Qr({layer:r,key:t.key,value:t.value,style:t.style,styleSpec:t.styleSpec,objectElementValidators:{"*":function(t){return vn(It({layerType:s},t))}}})},paint:function(t){return Qr({layer:r,key:t.key,value:t.value,style:t.style,styleSpec:t.styleSpec,objectElementValidators:{"*":function(t){return gn(It({layerType:s},t))}}})}}}))}function xn(t){var e=t.value,r=t.key,n=Fr(e);return"string"!==n?[new Ct(r,e,"string expected, "+n+" found")]:[]}var bn={promoteId:function(t){var e=t.key,r=t.value;if("string"===Fr(r))return xn({key:e,value:r});var n=[];for(var i in r)n.push.apply(n,xn({key:e+"."+i,value:r[i]}));return n}};function _n(t){var e=t.value,r=t.key,n=t.styleSpec,i=t.style;if(!e.type)return[new Ct(r,e,'"type" is required')];var a,o=Ot(e.type);switch(o){case"vector":case"raster":case"raster-dem":return a=Qr({key:r,value:e,valueSpec:n["source_"+o.replace("-","_")],style:t.style,styleSpec:n,objectElementValidators:bn});case"geojson":if(a=Qr({key:r,value:e,valueSpec:n.source_geojson,style:i,styleSpec:n,objectElementValidators:bn}),e.cluster)for(var s in e.clusterProperties){var l=e.clusterProperties[s],c=l[0],u=l[1],f="string"==typeof c?[c,["accumulated"],["get",s]]:c;a.push.apply(a,rn({key:r+"."+s+".map",value:u,expressionContext:"cluster-map"})),a.push.apply(a,rn({key:r+"."+s+".reduce",value:f,expressionContext:"cluster-reduce"}))}return a;case"video":return Qr({key:r,value:e,valueSpec:n.source_video,style:i,styleSpec:n});case"image":return Qr({key:r,value:e,valueSpec:n.source_image,style:i,styleSpec:n});case"canvas":return[new Ct(r,null,"Please use runtime APIs to add canvas sources, rather than including them in stylesheets.","source.canvas")];default:return nn({key:r+".type",value:e.type,valueSpec:{values:["vector","raster","raster-dem","geojson","video","image"]},style:i,styleSpec:n})}}function wn(t){var e=t.value,r=t.styleSpec,n=r.light,i=t.style,a=[],o=Fr(e);if(void 0===e)return a;if("object"!==o)return a=a.concat([new Ct("light",e,"object expected, "+o+" found")]);for(var s in e){var l=s.match(/^(.*)-transition$/);a=l&&n[l[1]]&&n[l[1]].transition?a.concat(kn({key:s,value:e[s],valueSpec:r.transition,style:i,styleSpec:r})):n[s]?a.concat(kn({key:s,value:e[s],valueSpec:n[s],style:i,styleSpec:r})):a.concat([new Ct(s,e[s],'unknown property "'+s+'"')])}return a}var Tn={"*":function(){return[]},array:$r,boolean:function(t){var e=t.value,r=t.key,n=Fr(e);return"boolean"!==n?[new Ct(r,e,"boolean expected, "+n+" found")]:[]},number:tn,color:function(t){var e=t.key,r=t.value,n=Fr(r);return"string"!==n?[new Ct(e,r,"color expected, "+n+" found")]:null===$t(r)?[new Ct(e,r,'color expected, "'+r+'" found')]:[]},constants:Pt,enum:nn,filter:dn,function:en,layer:yn,object:Qr,source:_n,light:wn,string:xn,formatted:function(t){return 0===xn(t).length?[]:rn(t)},resolvedImage:function(t){return 0===xn(t).length?[]:rn(t)}};function kn(t){var e=t.value,r=t.valueSpec,n=t.styleSpec;return r.expression&&Br(Ot(e))?en(t):r.expression&&Yr(zt(e))?rn(t):r.type&&Tn[r.type]?Tn[r.type](t):Qr(It({},t,{valueSpec:r.type?n[r.type]:r}))}function An(t){var e=t.value,r=t.key,n=xn(t);return n.length||(-1===e.indexOf("{fontstack}")&&n.push(new Ct(r,e,'"glyphs" url must include a "{fontstack}" token')),-1===e.indexOf("{range}")&&n.push(new Ct(r,e,'"glyphs" url must include a "{range}" token'))),n}function Mn(t,e){void 0===e&&(e=Lt);var r=[];return r=r.concat(kn({key:"",value:t,valueSpec:e.$root,styleSpec:e,style:t,objectElementValidators:{glyphs:An,"*":function(){return[]}}})),t.constants&&(r=r.concat(Pt({key:"constants",value:t.constants,style:t,styleSpec:e}))),Sn(r)}function Sn(t){return[].concat(t).sort((function(t,e){return t.line-e.line}))}function En(t){return function(){for(var e=[],r=arguments.length;r--;)e[r]=arguments[r];return Sn(t.apply(this,e))}}Mn.source=En(_n),Mn.light=En(wn),Mn.layer=En(yn),Mn.filter=En(dn),Mn.paintProperty=En(gn),Mn.layoutProperty=En(vn);var Ln=Mn,Cn=Ln.light,Pn=Ln.paintProperty,In=Ln.layoutProperty;function On(t,e){var r=!1;if(e&&e.length)for(var n=0,i=e;n<i.length;n+=1){var a=i[n];t.fire(new St(new Error(a.message))),r=!0}return r}var zn=Dn;function Dn(t,e,r){var n=this.cells=[];if(t instanceof ArrayBuffer){this.arrayBuffer=t;var i=new Int32Array(this.arrayBuffer);t=i[0],e=i[1],r=i[2],this.d=e+2*r;for(var a=0;a<this.d*this.d;a++){var o=i[3+a],s=i[3+a+1];n.push(o===s?null:i.subarray(o,s))}var l=i[3+n.length],c=i[3+n.length+1];this.keys=i.subarray(l,c),this.bboxes=i.subarray(c),this.insert=this._insertReadonly}else{this.d=e+2*r;for(var u=0;u<this.d*this.d;u++)n.push([]);this.keys=[],this.bboxes=[]}this.n=e,this.extent=t,this.padding=r,this.scale=e/t,this.uid=0;var f=r/e*t;this.min=-f,this.max=t+f}Dn.prototype.insert=function(t,e,r,n,i){this._forEachCell(e,r,n,i,this._insertCell,this.uid++),this.keys.push(t),this.bboxes.push(e),this.bboxes.push(r),this.bboxes.push(n),this.bboxes.push(i)},Dn.prototype._insertReadonly=function(){throw"Cannot insert into a GridIndex created from an ArrayBuffer."},Dn.prototype._insertCell=function(t,e,r,n,i,a){this.cells[i].push(a)},Dn.prototype.query=function(t,e,r,n,i){var a=this.min,o=this.max;if(t<=a&&e<=a&&o<=r&&o<=n&&!i)return Array.prototype.slice.call(this.keys);var s=[];return this._forEachCell(t,e,r,n,this._queryCell,s,{},i),s},Dn.prototype._queryCell=function(t,e,r,n,i,a,o,s){var l=this.cells[i];if(null!==l)for(var c=this.keys,u=this.bboxes,f=0;f<l.length;f++){var h=l[f];if(void 0===o[h]){var p=4*h;(s?s(u[p+0],u[p+1],u[p+2],u[p+3]):t<=u[p+2]&&e<=u[p+3]&&r>=u[p+0]&&n>=u[p+1])?(o[h]=!0,a.push(c[h])):o[h]=!1}}},Dn.prototype._forEachCell=function(t,e,r,n,i,a,o,s){for(var l=this._convertToCellCoord(t),c=this._convertToCellCoord(e),u=this._convertToCellCoord(r),f=this._convertToCellCoord(n),h=l;h<=u;h++)for(var p=c;p<=f;p++){var d=this.d*p+h;if((!s||s(this._convertFromCellCoord(h),this._convertFromCellCoord(p),this._convertFromCellCoord(h+1),this._convertFromCellCoord(p+1)))&&i.call(this,t,e,r,n,d,a,o,s))return}},Dn.prototype._convertFromCellCoord=function(t){return(t-this.padding)/this.scale},Dn.prototype._convertToCellCoord=function(t){return Math.max(0,Math.min(this.d-1,Math.floor(t*this.scale)+this.padding))},Dn.prototype.toArrayBuffer=function(){if(this.arrayBuffer)return this.arrayBuffer;for(var t=this.cells,e=3+this.cells.length+1+1,r=0,n=0;n<this.cells.length;n++)r+=this.cells[n].length;var i=new Int32Array(e+r+this.keys.length+this.bboxes.length);i[0]=this.extent,i[1]=this.n,i[2]=this.padding;for(var a=e,o=0;o<t.length;o++){var s=t[o];i[3+o]=a,i.set(s,a),a+=s.length}return i[3+t.length]=a,i.set(this.keys,a),a+=this.keys.length,i[3+t.length+1]=a,i.set(this.bboxes,a),a+=this.bboxes.length,i.buffer};var Rn=self.ImageData,Fn=self.ImageBitmap,Bn={};function Nn(t,e,r){void 0===r&&(r={}),Object.defineProperty(e,"_classRegistryKey",{value:t,writeable:!1}),Bn[t]={klass:e,omit:r.omit||[],shallow:r.shallow||[]}}for(var jn in Nn("Object",Object),zn.serialize=function(t,e){var r=t.toArrayBuffer();return e&&e.push(r),{buffer:r}},zn.deserialize=function(t){return new zn(t.buffer)},Nn("Grid",zn),Nn("Color",te),Nn("Error",Error),Nn("ResolvedImage",ie),Nn("StylePropertyFunction",Kr),Nn("StyleExpression",Gr,{omit:["_evaluator"]}),Nn("ZoomDependentExpression",Zr),Nn("ZoomConstantExpression",Xr),Nn("CompoundExpression",xe,{omit:["_evaluate"]}),Sr)Sr[jn]._classRegistryKey||Nn("Expression_"+jn,Sr[jn]);function Un(t){return t&&"undefined"!=typeof ArrayBuffer&&(t instanceof ArrayBuffer||t.constructor&&"ArrayBuffer"===t.constructor.name)}function Vn(t){return Fn&&t instanceof Fn}function Hn(t,e){if(null==t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||t instanceof Boolean||t instanceof Number||t instanceof String||t instanceof Date||t instanceof RegExp)return t;if(Un(t)||Vn(t))return e&&e.push(t),t;if(ArrayBuffer.isView(t)){var r=t;return e&&e.push(r.buffer),r}if(t instanceof Rn)return e&&e.push(t.data.buffer),t;if(Array.isArray(t)){for(var n=[],i=0,a=t;i<a.length;i+=1){var o=a[i];n.push(Hn(o,e))}return n}if("object"==typeof t){var s=t.constructor,l=s._classRegistryKey;if(!l)throw new Error("can't serialize object of unregistered class");var c=s.serialize?s.serialize(t,e):{};if(!s.serialize){for(var u in t)if(t.hasOwnProperty(u)&&!(Bn[l].omit.indexOf(u)>=0)){var f=t[u];c[u]=Bn[l].shallow.indexOf(u)>=0?f:Hn(f,e)}t instanceof Error&&(c.message=t.message)}if(c.$name)throw new Error("$name property is reserved for worker serialization logic.");return"Object"!==l&&(c.$name=l),c}throw new Error("can't serialize object of type "+typeof t)}function qn(t){if(null==t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||t instanceof Boolean||t instanceof Number||t instanceof String||t instanceof Date||t instanceof RegExp||Un(t)||Vn(t)||ArrayBuffer.isView(t)||t instanceof Rn)return t;if(Array.isArray(t))return t.map(qn);if("object"==typeof t){var e=t.$name||"Object",r=Bn[e].klass;if(!r)throw new Error("can't deserialize unregistered class "+e);if(r.deserialize)return r.deserialize(t);for(var n=Object.create(r.prototype),i=0,a=Object.keys(t);i<a.length;i+=1){var o=a[i];if("$name"!==o){var s=t[o];n[o]=Bn[e].shallow.indexOf(o)>=0?s:qn(s)}}return n}throw new Error("can't deserialize object of type "+typeof t)}var Gn=function(){this.first=!0};Gn.prototype.update=function(t,e){var r=Math.floor(t);return this.first?(this.first=!1,this.lastIntegerZoom=r,this.lastIntegerZoomTime=0,this.lastZoom=t,this.lastFloorZoom=r,!0):(this.lastFloorZoom>r?(this.lastIntegerZoom=r+1,this.lastIntegerZoomTime=e):this.lastFloorZoom<r&&(this.lastIntegerZoom=r,this.lastIntegerZoomTime=e),t!==this.lastZoom&&(this.lastZoom=t,this.lastFloorZoom=r,!0))};var Yn={"Latin-1 Supplement":function(t){return t>=128&&t<=255},Arabic:function(t){return t>=1536&&t<=1791},"Arabic Supplement":function(t){return t>=1872&&t<=1919},"Arabic Extended-A":function(t){return t>=2208&&t<=2303},"Hangul Jamo":function(t){return t>=4352&&t<=4607},"Unified Canadian Aboriginal Syllabics":function(t){return t>=5120&&t<=5759},Khmer:function(t){return t>=6016&&t<=6143},"Unified Canadian Aboriginal Syllabics Extended":function(t){return t>=6320&&t<=6399},"General Punctuation":function(t){return t>=8192&&t<=8303},"Letterlike Symbols":function(t){return t>=8448&&t<=8527},"Number Forms":function(t){return t>=8528&&t<=8591},"Miscellaneous Technical":function(t){return t>=8960&&t<=9215},"Control Pictures":function(t){return t>=9216&&t<=9279},"Optical Character Recognition":function(t){return t>=9280&&t<=9311},"Enclosed Alphanumerics":function(t){return t>=9312&&t<=9471},"Geometric Shapes":function(t){return t>=9632&&t<=9727},"Miscellaneous Symbols":function(t){return t>=9728&&t<=9983},"Miscellaneous Symbols and Arrows":function(t){return t>=11008&&t<=11263},"CJK Radicals Supplement":function(t){return t>=11904&&t<=12031},"Kangxi Radicals":function(t){return t>=12032&&t<=12255},"Ideographic Description Characters":function(t){return t>=12272&&t<=12287},"CJK Symbols and Punctuation":function(t){return t>=12288&&t<=12351},Hiragana:function(t){return t>=12352&&t<=12447},Katakana:function(t){return t>=12448&&t<=12543},Bopomofo:function(t){return t>=12544&&t<=12591},"Hangul Compatibility Jamo":function(t){return t>=12592&&t<=12687},Kanbun:function(t){return t>=12688&&t<=12703},"Bopomofo Extended":function(t){return t>=12704&&t<=12735},"CJK Strokes":function(t){return t>=12736&&t<=12783},"Katakana Phonetic Extensions":function(t){return t>=12784&&t<=12799},"Enclosed CJK Letters and Months":function(t){return t>=12800&&t<=13055},"CJK Compatibility":function(t){return t>=13056&&t<=13311},"CJK Unified Ideographs Extension A":function(t){return t>=13312&&t<=19903},"Yijing Hexagram Symbols":function(t){return t>=19904&&t<=19967},"CJK Unified Ideographs":function(t){return t>=19968&&t<=40959},"Yi Syllables":function(t){return t>=40960&&t<=42127},"Yi Radicals":function(t){return t>=42128&&t<=42191},"Hangul Jamo Extended-A":function(t){return t>=43360&&t<=43391},"Hangul Syllables":function(t){return t>=44032&&t<=55215},"Hangul Jamo Extended-B":function(t){return t>=55216&&t<=55295},"Private Use Area":function(t){return t>=57344&&t<=63743},"CJK Compatibility Ideographs":function(t){return t>=63744&&t<=64255},"Arabic Presentation Forms-A":function(t){return t>=64336&&t<=65023},"Vertical Forms":function(t){return t>=65040&&t<=65055},"CJK Compatibility Forms":function(t){return t>=65072&&t<=65103},"Small Form Variants":function(t){return t>=65104&&t<=65135},"Arabic Presentation Forms-B":function(t){return t>=65136&&t<=65279},"Halfwidth and Fullwidth Forms":function(t){return t>=65280&&t<=65519}};function Wn(t){for(var e=0,r=t;e<r.length;e+=1){if(Zn(r[e].charCodeAt(0)))return!0}return!1}function Xn(t){return!Yn.Arabic(t)&&(!Yn["Arabic Supplement"](t)&&(!Yn["Arabic Extended-A"](t)&&(!Yn["Arabic Presentation Forms-A"](t)&&!Yn["Arabic Presentation Forms-B"](t))))}function Zn(t){return 746===t||747===t||!(t<4352)&&(!!Yn["Bopomofo Extended"](t)||(!!Yn.Bopomofo(t)||(!(!Yn["CJK Compatibility Forms"](t)||t>=65097&&t<=65103)||(!!Yn["CJK Compatibility Ideographs"](t)||(!!Yn["CJK Compatibility"](t)||(!!Yn["CJK Radicals Supplement"](t)||(!!Yn["CJK Strokes"](t)||(!(!Yn["CJK Symbols and Punctuation"](t)||t>=12296&&t<=12305||t>=12308&&t<=12319||12336===t)||(!!Yn["CJK Unified Ideographs Extension A"](t)||(!!Yn["CJK Unified Ideographs"](t)||(!!Yn["Enclosed CJK Letters and Months"](t)||(!!Yn["Hangul Compatibility Jamo"](t)||(!!Yn["Hangul Jamo Extended-A"](t)||(!!Yn["Hangul Jamo Extended-B"](t)||(!!Yn["Hangul Jamo"](t)||(!!Yn["Hangul Syllables"](t)||(!!Yn.Hiragana(t)||(!!Yn["Ideographic Description Characters"](t)||(!!Yn.Kanbun(t)||(!!Yn["Kangxi Radicals"](t)||(!!Yn["Katakana Phonetic Extensions"](t)||(!(!Yn.Katakana(t)||12540===t)||(!(!Yn["Halfwidth and Fullwidth Forms"](t)||65288===t||65289===t||65293===t||t>=65306&&t<=65310||65339===t||65341===t||65343===t||t>=65371&&t<=65503||65507===t||t>=65512&&t<=65519)||(!(!Yn["Small Form Variants"](t)||t>=65112&&t<=65118||t>=65123&&t<=65126)||(!!Yn["Unified Canadian Aboriginal Syllabics"](t)||(!!Yn["Unified Canadian Aboriginal Syllabics Extended"](t)||(!!Yn["Vertical Forms"](t)||(!!Yn["Yijing Hexagram Symbols"](t)||(!!Yn["Yi Syllables"](t)||!!Yn["Yi Radicals"](t))))))))))))))))))))))))))))))}function Jn(t){return!(Zn(t)||function(t){return!(!Yn["Latin-1 Supplement"](t)||167!==t&&169!==t&&174!==t&&177!==t&&188!==t&&189!==t&&190!==t&&215!==t&&247!==t)||(!(!Yn["General Punctuation"](t)||8214!==t&&8224!==t&&8225!==t&&8240!==t&&8241!==t&&8251!==t&&8252!==t&&8258!==t&&8263!==t&&8264!==t&&8265!==t&&8273!==t)||(!!Yn["Letterlike Symbols"](t)||(!!Yn["Number Forms"](t)||(!(!Yn["Miscellaneous Technical"](t)||!(t>=8960&&t<=8967||t>=8972&&t<=8991||t>=8996&&t<=9e3||9003===t||t>=9085&&t<=9114||t>=9150&&t<=9165||9167===t||t>=9169&&t<=9179||t>=9186&&t<=9215))||(!(!Yn["Control Pictures"](t)||9251===t)||(!!Yn["Optical Character Recognition"](t)||(!!Yn["Enclosed Alphanumerics"](t)||(!!Yn["Geometric Shapes"](t)||(!(!Yn["Miscellaneous Symbols"](t)||t>=9754&&t<=9759)||(!(!Yn["Miscellaneous Symbols and Arrows"](t)||!(t>=11026&&t<=11055||t>=11088&&t<=11097||t>=11192&&t<=11243))||(!!Yn["CJK Symbols and Punctuation"](t)||(!!Yn.Katakana(t)||(!!Yn["Private Use Area"](t)||(!!Yn["CJK Compatibility Forms"](t)||(!!Yn["Small Form Variants"](t)||(!!Yn["Halfwidth and Fullwidth Forms"](t)||(8734===t||8756===t||8757===t||t>=9984&&t<=10087||t>=10102&&t<=10131||65532===t||65533===t)))))))))))))))))}(t))}function Kn(t){return t>=1424&&t<=2303||Yn["Arabic Presentation Forms-A"](t)||Yn["Arabic Presentation Forms-B"](t)}function Qn(t,e){return!(!e&&Kn(t))&&!(t>=2304&&t<=3583||t>=3840&&t<=4255||Yn.Khmer(t))}function $n(t){for(var e=0,r=t;e<r.length;e+=1){if(Kn(r[e].charCodeAt(0)))return!0}return!1}var ti="deferred",ei="loading",ri="loaded",ni="error",ii=null,ai="unavailable",oi=null,si=function(t){t&&"string"==typeof t&&t.indexOf("NetworkError")>-1&&(ai=ni),ii&&ii(t)};function li(){ci.fire(new Mt("pluginStateChange",{pluginStatus:ai,pluginURL:oi}))}var ci=new Et,ui=function(){return ai},fi=function(){if(ai!==ti||!oi)throw new Error("rtl-text-plugin cannot be downloaded unless a pluginURL is specified");ai=ei,li(),oi&&xt({url:oi},(function(t){t?si(t):(ai=ri,li())}))},hi={applyArabicShaping:null,processBidirectionalText:null,processStyledBidirectionalText:null,isLoaded:function(){return ai===ri||null!=hi.applyArabicShaping},isLoading:function(){return ai===ei},setState:function(t){ai=t.pluginStatus,oi=t.pluginURL},isParsed:function(){return null!=hi.applyArabicShaping&&null!=hi.processBidirectionalText&&null!=hi.processStyledBidirectionalText},getPluginURL:function(){return oi}},pi=function(t,e){this.zoom=t,e?(this.now=e.now,this.fadeDuration=e.fadeDuration,this.zoomHistory=e.zoomHistory,this.transition=e.transition):(this.now=0,this.fadeDuration=0,this.zoomHistory=new Gn,this.transition={})};pi.prototype.isSupportedScript=function(t){return function(t,e){for(var r=0,n=t;r<n.length;r+=1){if(!Qn(n[r].charCodeAt(0),e))return!1}return!0}(t,hi.isLoaded())},pi.prototype.crossFadingFactor=function(){return 0===this.fadeDuration?1:Math.min((this.now-this.zoomHistory.lastIntegerZoomTime)/this.fadeDuration,1)},pi.prototype.getCrossfadeParameters=function(){var t=this.zoom,e=t-Math.floor(t),r=this.crossFadingFactor();return t>this.zoomHistory.lastIntegerZoom?{fromScale:2,toScale:1,t:e+(1-e)*r}:{fromScale:.5,toScale:1,t:1-(1-r)*e}};var di=function(t,e){this.property=t,this.value=e,this.expression=function(t,e){if(Br(t))return new Kr(t,e);if(Yr(t)){var r=Jr(t,e);if("error"===r.result)throw new Error(r.value.map((function(t){return t.key+": "+t.message})).join(", "));return r.value}var n=t;return"string"==typeof t&&"color"===e.type&&(n=te.parse(t)),{kind:"constant",evaluate:function(){return n}}}(void 0===e?t.specification.default:e,t.specification)};di.prototype.isDataDriven=function(){return"source"===this.expression.kind||"composite"===this.expression.kind},di.prototype.possiblyEvaluate=function(t,e,r){return this.property.possiblyEvaluate(this,t,e,r)};var mi=function(t){this.property=t,this.value=new di(t,void 0)};mi.prototype.transitioned=function(t,e){return new vi(this.property,this.value,e,u({},t.transition,this.transition),t.now)},mi.prototype.untransitioned=function(){return new vi(this.property,this.value,null,{},0)};var gi=function(t){this._properties=t,this._values=Object.create(t.defaultTransitionablePropertyValues)};gi.prototype.getValue=function(t){return x(this._values[t].value.value)},gi.prototype.setValue=function(t,e){this._values.hasOwnProperty(t)||(this._values[t]=new mi(this._values[t].property)),this._values[t].value=new di(this._values[t].property,null===e?void 0:x(e))},gi.prototype.getTransition=function(t){return x(this._values[t].transition)},gi.prototype.setTransition=function(t,e){this._values.hasOwnProperty(t)||(this._values[t]=new mi(this._values[t].property)),this._values[t].transition=x(e)||void 0},gi.prototype.serialize=function(){for(var t={},e=0,r=Object.keys(this._values);e<r.length;e+=1){var n=r[e],i=this.getValue(n);void 0!==i&&(t[n]=i);var a=this.getTransition(n);void 0!==a&&(t[n+"-transition"]=a)}return t},gi.prototype.transitioned=function(t,e){for(var r=new yi(this._properties),n=0,i=Object.keys(this._values);n<i.length;n+=1){var a=i[n];r._values[a]=this._values[a].transitioned(t,e._values[a])}return r},gi.prototype.untransitioned=function(){for(var t=new yi(this._properties),e=0,r=Object.keys(this._values);e<r.length;e+=1){var n=r[e];t._values[n]=this._values[n].untransitioned()}return t};var vi=function(t,e,r,n,i){this.property=t,this.value=e,this.begin=i+n.delay||0,this.end=this.begin+n.duration||0,t.specification.transition&&(n.delay||n.duration)&&(this.prior=r)};vi.prototype.possiblyEvaluate=function(t,e,r){var n=t.now||0,i=this.value.possiblyEvaluate(t,e,r),a=this.prior;if(a){if(n>this.end)return this.prior=null,i;if(this.value.isDataDriven())return this.prior=null,i;if(n<this.begin)return a.possiblyEvaluate(t,e,r);var o=(n-this.begin)/(this.end-this.begin);return this.property.interpolate(a.possiblyEvaluate(t,e,r),i,function(t){if(t<=0)return 0;if(t>=1)return 1;var e=t*t,r=e*t;return 4*(t<.5?r:3*(t-e)+r-.75)}(o))}return i};var yi=function(t){this._properties=t,this._values=Object.create(t.defaultTransitioningPropertyValues)};yi.prototype.possiblyEvaluate=function(t,e,r){for(var n=new _i(this._properties),i=0,a=Object.keys(this._values);i<a.length;i+=1){var o=a[i];n._values[o]=this._values[o].possiblyEvaluate(t,e,r)}return n},yi.prototype.hasTransition=function(){for(var t=0,e=Object.keys(this._values);t<e.length;t+=1){var r=e[t];if(this._values[r].prior)return!0}return!1};var xi=function(t){this._properties=t,this._values=Object.create(t.defaultPropertyValues)};xi.prototype.getValue=function(t){return x(this._values[t].value)},xi.prototype.setValue=function(t,e){this._values[t]=new di(this._values[t].property,null===e?void 0:x(e))},xi.prototype.serialize=function(){for(var t={},e=0,r=Object.keys(this._values);e<r.length;e+=1){var n=r[e],i=this.getValue(n);void 0!==i&&(t[n]=i)}return t},xi.prototype.possiblyEvaluate=function(t,e,r){for(var n=new _i(this._properties),i=0,a=Object.keys(this._values);i<a.length;i+=1){var o=a[i];n._values[o]=this._values[o].possiblyEvaluate(t,e,r)}return n};var bi=function(t,e,r){this.property=t,this.value=e,this.parameters=r};bi.prototype.isConstant=function(){return"constant"===this.value.kind},bi.prototype.constantOr=function(t){return"constant"===this.value.kind?this.value.value:t},bi.prototype.evaluate=function(t,e,r,n){return this.property.evaluate(this.value,this.parameters,t,e,r,n)};var _i=function(t){this._properties=t,this._values=Object.create(t.defaultPossiblyEvaluatedValues)};_i.prototype.get=function(t){return this._values[t]};var wi=function(t){this.specification=t};wi.prototype.possiblyEvaluate=function(t,e){return t.expression.evaluate(e)},wi.prototype.interpolate=function(t,e,r){var n=Ge[this.specification.type];return n?n(t,e,r):t};var Ti=function(t,e){this.specification=t,this.overrides=e};Ti.prototype.possiblyEvaluate=function(t,e,r,n){return"constant"===t.expression.kind||"camera"===t.expression.kind?new bi(this,{kind:"constant",value:t.expression.evaluate(e,null,{},r,n)},e):new bi(this,t.expression,e)},Ti.prototype.interpolate=function(t,e,r){if("constant"!==t.value.kind||"constant"!==e.value.kind)return t;if(void 0===t.value.value||void 0===e.value.value)return new bi(this,{kind:"constant",value:void 0},t.parameters);var n=Ge[this.specification.type];return n?new bi(this,{kind:"constant",value:n(t.value.value,e.value.value,r)},t.parameters):t},Ti.prototype.evaluate=function(t,e,r,n,i,a){return"constant"===t.kind?t.value:t.evaluate(e,r,n,i,a)};var ki=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.possiblyEvaluate=function(t,e,r,n){if(void 0===t.value)return new bi(this,{kind:"constant",value:void 0},e);if("constant"===t.expression.kind){var i=t.expression.evaluate(e,null,{},r,n),a="resolvedImage"===t.property.specification.type&&"string"!=typeof i?i.name:i,o=this._calculate(a,a,a,e);return new bi(this,{kind:"constant",value:o},e)}if("camera"===t.expression.kind){var s=this._calculate(t.expression.evaluate({zoom:e.zoom-1}),t.expression.evaluate({zoom:e.zoom}),t.expression.evaluate({zoom:e.zoom+1}),e);return new bi(this,{kind:"constant",value:s},e)}return new bi(this,t.expression,e)},e.prototype.evaluate=function(t,e,r,n,i,a){if("source"===t.kind){var o=t.evaluate(e,r,n,i,a);return this._calculate(o,o,o,e)}return"composite"===t.kind?this._calculate(t.evaluate({zoom:Math.floor(e.zoom)-1},r,n),t.evaluate({zoom:Math.floor(e.zoom)},r,n),t.evaluate({zoom:Math.floor(e.zoom)+1},r,n),e):t.value},e.prototype._calculate=function(t,e,r,n){return n.zoom>n.zoomHistory.lastIntegerZoom?{from:t,to:e}:{from:r,to:e}},e.prototype.interpolate=function(t){return t},e}(Ti),Ai=function(t){this.specification=t};Ai.prototype.possiblyEvaluate=function(t,e,r,n){if(void 0!==t.value){if("constant"===t.expression.kind){var i=t.expression.evaluate(e,null,{},r,n);return this._calculate(i,i,i,e)}return this._calculate(t.expression.evaluate(new pi(Math.floor(e.zoom-1),e)),t.expression.evaluate(new pi(Math.floor(e.zoom),e)),t.expression.evaluate(new pi(Math.floor(e.zoom+1),e)),e)}},Ai.prototype._calculate=function(t,e,r,n){return n.zoom>n.zoomHistory.lastIntegerZoom?{from:t,to:e}:{from:r,to:e}},Ai.prototype.interpolate=function(t){return t};var Mi=function(t){this.specification=t};Mi.prototype.possiblyEvaluate=function(t,e,r,n){return!!t.expression.evaluate(e,null,{},r,n)},Mi.prototype.interpolate=function(){return!1};var Si=function(t){for(var e in this.properties=t,this.defaultPropertyValues={},this.defaultTransitionablePropertyValues={},this.defaultTransitioningPropertyValues={},this.defaultPossiblyEvaluatedValues={},this.overridableProperties=[],t){var r=t[e];r.specification.overridable&&this.overridableProperties.push(e);var n=this.defaultPropertyValues[e]=new di(r,void 0),i=this.defaultTransitionablePropertyValues[e]=new mi(r);this.defaultTransitioningPropertyValues[e]=i.untransitioned(),this.defaultPossiblyEvaluatedValues[e]=n.possiblyEvaluate({})}};Nn("DataDrivenProperty",Ti),Nn("DataConstantProperty",wi),Nn("CrossFadedDataDrivenProperty",ki),Nn("CrossFadedProperty",Ai),Nn("ColorRampProperty",Mi);var Ei=function(t){function e(e,r){if(t.call(this),this.id=e.id,this.type=e.type,this._featureFilter={filter:function(){return!0},needGeometry:!1},"custom"!==e.type&&(e=e,this.metadata=e.metadata,this.minzoom=e.minzoom,this.maxzoom=e.maxzoom,"background"!==e.type&&(this.source=e.source,this.sourceLayer=e["source-layer"],this.filter=e.filter),r.layout&&(this._unevaluatedLayout=new xi(r.layout)),r.paint)){for(var n in this._transitionablePaint=new gi(r.paint),e.paint)this.setPaintProperty(n,e.paint[n],{validate:!1});for(var i in e.layout)this.setLayoutProperty(i,e.layout[i],{validate:!1});this._transitioningPaint=this._transitionablePaint.untransitioned(),this.paint=new _i(r.paint)}}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getCrossfadeParameters=function(){return this._crossfadeParameters},e.prototype.getLayoutProperty=function(t){return"visibility"===t?this.visibility:this._unevaluatedLayout.getValue(t)},e.prototype.setLayoutProperty=function(t,e,r){if(void 0===r&&(r={}),null!=e){var n="layers."+this.id+".layout."+t;if(this._validate(In,n,t,e,r))return}"visibility"!==t?this._unevaluatedLayout.setValue(t,e):this.visibility=e},e.prototype.getPaintProperty=function(t){return g(t,"-transition")?this._transitionablePaint.getTransition(t.slice(0,-"-transition".length)):this._transitionablePaint.getValue(t)},e.prototype.setPaintProperty=function(t,e,r){if(void 0===r&&(r={}),null!=e){var n="layers."+this.id+".paint."+t;if(this._validate(Pn,n,t,e,r))return!1}if(g(t,"-transition"))return this._transitionablePaint.setTransition(t.slice(0,-"-transition".length),e||void 0),!1;var i=this._transitionablePaint._values[t],a="cross-faded-data-driven"===i.property.specification["property-type"],o=i.value.isDataDriven(),s=i.value;this._transitionablePaint.setValue(t,e),this._handleSpecialPaintPropertyUpdate(t);var l=this._transitionablePaint._values[t].value;return l.isDataDriven()||o||a||this._handleOverridablePaintPropertyUpdate(t,s,l)},e.prototype._handleSpecialPaintPropertyUpdate=function(t){},e.prototype._handleOverridablePaintPropertyUpdate=function(t,e,r){return!1},e.prototype.isHidden=function(t){return!!(this.minzoom&&t<this.minzoom)||(!!(this.maxzoom&&t>=this.maxzoom)||"none"===this.visibility)},e.prototype.updateTransitions=function(t){this._transitioningPaint=this._transitionablePaint.transitioned(t,this._transitioningPaint)},e.prototype.hasTransition=function(){return this._transitioningPaint.hasTransition()},e.prototype.recalculate=function(t,e){t.getCrossfadeParameters&&(this._crossfadeParameters=t.getCrossfadeParameters()),this._unevaluatedLayout&&(this.layout=this._unevaluatedLayout.possiblyEvaluate(t,void 0,e)),this.paint=this._transitioningPaint.possiblyEvaluate(t,void 0,e)},e.prototype.serialize=function(){var t={id:this.id,type:this.type,source:this.source,"source-layer":this.sourceLayer,metadata:this.metadata,minzoom:this.minzoom,maxzoom:this.maxzoom,filter:this.filter,layout:this._unevaluatedLayout&&this._unevaluatedLayout.serialize(),paint:this._transitionablePaint&&this._transitionablePaint.serialize()};return this.visibility&&(t.layout=t.layout||{},t.layout.visibility=this.visibility),y(t,(function(t,e){return!(void 0===t||"layout"===e&&!Object.keys(t).length||"paint"===e&&!Object.keys(t).length)}))},e.prototype._validate=function(t,e,r,n,i){return void 0===i&&(i={}),(!i||!1!==i.validate)&&On(this,t.call(Ln,{key:e,layerType:this.type,objectKey:r,value:n,styleSpec:Lt,style:{glyphs:!0,sprite:!0}}))},e.prototype.is3D=function(){return!1},e.prototype.isTileClipped=function(){return!1},e.prototype.hasOffscreenPass=function(){return!1},e.prototype.resize=function(){},e.prototype.isStateDependent=function(){for(var t in this.paint._values){var e=this.paint.get(t);if(e instanceof bi&&zr(e.property.specification)&&(("source"===e.value.kind||"composite"===e.value.kind)&&e.value.isStateDependent))return!0}return!1},e}(Et),Li={Int8:Int8Array,Uint8:Uint8Array,Int16:Int16Array,Uint16:Uint16Array,Int32:Int32Array,Uint32:Uint32Array,Float32:Float32Array},Ci=function(t,e){this._structArray=t,this._pos1=e*this.size,this._pos2=this._pos1/2,this._pos4=this._pos1/4,this._pos8=this._pos1/8},Pi=function(){this.isTransferred=!1,this.capacity=-1,this.resize(0)};function Ii(t,e){void 0===e&&(e=1);var r=0,n=0;return{members:t.map((function(t){var i,a=(i=t.type,Li[i].BYTES_PER_ELEMENT),o=r=Oi(r,Math.max(e,a)),s=t.components||1;return n=Math.max(n,a),r+=a*s,{name:t.name,type:t.type,components:s,offset:o}})),size:Oi(r,Math.max(n,e)),alignment:e}}function Oi(t,e){return Math.ceil(t/e)*e}Pi.serialize=function(t,e){return t._trim(),e&&(t.isTransferred=!0,e.push(t.arrayBuffer)),{length:t.length,arrayBuffer:t.arrayBuffer}},Pi.deserialize=function(t){var e=Object.create(this.prototype);return e.arrayBuffer=t.arrayBuffer,e.length=t.length,e.capacity=t.arrayBuffer.byteLength/e.bytesPerElement,e._refreshViews(),e},Pi.prototype._trim=function(){this.length!==this.capacity&&(this.capacity=this.length,this.arrayBuffer=this.arrayBuffer.slice(0,this.length*this.bytesPerElement),this._refreshViews())},Pi.prototype.clear=function(){this.length=0},Pi.prototype.resize=function(t){this.reserve(t),this.length=t},Pi.prototype.reserve=function(t){if(t>this.capacity){this.capacity=Math.max(t,Math.floor(5*this.capacity),128),this.arrayBuffer=new ArrayBuffer(this.capacity*this.bytesPerElement);var e=this.uint8;this._refreshViews(),e&&this.uint8.set(e)}},Pi.prototype._refreshViews=function(){throw new Error("_refreshViews() must be implemented by each concrete StructArray layout")};var zi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e){var r=this.length;return this.resize(r+1),this.emplace(r,t,e)},e.prototype.emplace=function(t,e,r){var n=2*t;return this.int16[n+0]=e,this.int16[n+1]=r,t},e}(Pi);zi.prototype.bytesPerElement=4,Nn("StructArrayLayout2i4",zi);var Di=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r,n){var i=this.length;return this.resize(i+1),this.emplace(i,t,e,r,n)},e.prototype.emplace=function(t,e,r,n,i){var a=4*t;return this.int16[a+0]=e,this.int16[a+1]=r,this.int16[a+2]=n,this.int16[a+3]=i,t},e}(Pi);Di.prototype.bytesPerElement=8,Nn("StructArrayLayout4i8",Di);var Ri=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r,n,i,a){var o=this.length;return this.resize(o+1),this.emplace(o,t,e,r,n,i,a)},e.prototype.emplace=function(t,e,r,n,i,a,o){var s=6*t;return this.int16[s+0]=e,this.int16[s+1]=r,this.int16[s+2]=n,this.int16[s+3]=i,this.int16[s+4]=a,this.int16[s+5]=o,t},e}(Pi);Ri.prototype.bytesPerElement=12,Nn("StructArrayLayout2i4i12",Ri);var Fi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r,n,i,a){var o=this.length;return this.resize(o+1),this.emplace(o,t,e,r,n,i,a)},e.prototype.emplace=function(t,e,r,n,i,a,o){var s=4*t,l=8*t;return this.int16[s+0]=e,this.int16[s+1]=r,this.uint8[l+4]=n,this.uint8[l+5]=i,this.uint8[l+6]=a,this.uint8[l+7]=o,t},e}(Pi);Fi.prototype.bytesPerElement=8,Nn("StructArrayLayout2i4ub8",Fi);var Bi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r,n,i,a,o,s,l,c){var u=this.length;return this.resize(u+1),this.emplace(u,t,e,r,n,i,a,o,s,l,c)},e.prototype.emplace=function(t,e,r,n,i,a,o,s,l,c,u){var f=9*t,h=18*t;return this.uint16[f+0]=e,this.uint16[f+1]=r,this.uint16[f+2]=n,this.uint16[f+3]=i,this.uint16[f+4]=a,this.uint16[f+5]=o,this.uint16[f+6]=s,this.uint16[f+7]=l,this.uint8[h+16]=c,this.uint8[h+17]=u,t},e}(Pi);Bi.prototype.bytesPerElement=18,Nn("StructArrayLayout8ui2ub18",Bi);var Ni=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r,n,i,a,o,s,l,c,u,f){var h=this.length;return this.resize(h+1),this.emplace(h,t,e,r,n,i,a,o,s,l,c,u,f)},e.prototype.emplace=function(t,e,r,n,i,a,o,s,l,c,u,f,h){var p=12*t;return this.int16[p+0]=e,this.int16[p+1]=r,this.int16[p+2]=n,this.int16[p+3]=i,this.uint16[p+4]=a,this.uint16[p+5]=o,this.uint16[p+6]=s,this.uint16[p+7]=l,this.int16[p+8]=c,this.int16[p+9]=u,this.int16[p+10]=f,this.int16[p+11]=h,t},e}(Pi);Ni.prototype.bytesPerElement=24,Nn("StructArrayLayout4i4ui4i24",Ni);var ji=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r){var n=this.length;return this.resize(n+1),this.emplace(n,t,e,r)},e.prototype.emplace=function(t,e,r,n){var i=3*t;return this.float32[i+0]=e,this.float32[i+1]=r,this.float32[i+2]=n,t},e}(Pi);ji.prototype.bytesPerElement=12,Nn("StructArrayLayout3f12",ji);var Ui=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.uint32=new Uint32Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t){var e=this.length;return this.resize(e+1),this.emplace(e,t)},e.prototype.emplace=function(t,e){var r=1*t;return this.uint32[r+0]=e,t},e}(Pi);Ui.prototype.bytesPerElement=4,Nn("StructArrayLayout1ul4",Ui);var Vi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer),this.uint32=new Uint32Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r,n,i,a,o,s,l){var c=this.length;return this.resize(c+1),this.emplace(c,t,e,r,n,i,a,o,s,l)},e.prototype.emplace=function(t,e,r,n,i,a,o,s,l,c){var u=10*t,f=5*t;return this.int16[u+0]=e,this.int16[u+1]=r,this.int16[u+2]=n,this.int16[u+3]=i,this.int16[u+4]=a,this.int16[u+5]=o,this.uint32[f+3]=s,this.uint16[u+8]=l,this.uint16[u+9]=c,t},e}(Pi);Vi.prototype.bytesPerElement=20,Nn("StructArrayLayout6i1ul2ui20",Vi);var Hi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r,n,i,a){var o=this.length;return this.resize(o+1),this.emplace(o,t,e,r,n,i,a)},e.prototype.emplace=function(t,e,r,n,i,a,o){var s=6*t;return this.int16[s+0]=e,this.int16[s+1]=r,this.int16[s+2]=n,this.int16[s+3]=i,this.int16[s+4]=a,this.int16[s+5]=o,t},e}(Pi);Hi.prototype.bytesPerElement=12,Nn("StructArrayLayout2i2i2i12",Hi);var qi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r,n,i){var a=this.length;return this.resize(a+1),this.emplace(a,t,e,r,n,i)},e.prototype.emplace=function(t,e,r,n,i,a){var o=4*t,s=8*t;return this.float32[o+0]=e,this.float32[o+1]=r,this.float32[o+2]=n,this.int16[s+6]=i,this.int16[s+7]=a,t},e}(Pi);qi.prototype.bytesPerElement=16,Nn("StructArrayLayout2f1f2i16",qi);var Gi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r,n){var i=this.length;return this.resize(i+1),this.emplace(i,t,e,r,n)},e.prototype.emplace=function(t,e,r,n,i){var a=12*t,o=3*t;return this.uint8[a+0]=e,this.uint8[a+1]=r,this.float32[o+1]=n,this.float32[o+2]=i,t},e}(Pi);Gi.prototype.bytesPerElement=12,Nn("StructArrayLayout2ub2f12",Gi);var Yi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r){var n=this.length;return this.resize(n+1),this.emplace(n,t,e,r)},e.prototype.emplace=function(t,e,r,n){var i=3*t;return this.uint16[i+0]=e,this.uint16[i+1]=r,this.uint16[i+2]=n,t},e}(Pi);Yi.prototype.bytesPerElement=6,Nn("StructArrayLayout3ui6",Yi);var Wi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer),this.uint32=new Uint32Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r,n,i,a,o,s,l,c,u,f,h,p,d,m,g){var v=this.length;return this.resize(v+1),this.emplace(v,t,e,r,n,i,a,o,s,l,c,u,f,h,p,d,m,g)},e.prototype.emplace=function(t,e,r,n,i,a,o,s,l,c,u,f,h,p,d,m,g,v){var y=24*t,x=12*t,b=48*t;return this.int16[y+0]=e,this.int16[y+1]=r,this.uint16[y+2]=n,this.uint16[y+3]=i,this.uint32[x+2]=a,this.uint32[x+3]=o,this.uint32[x+4]=s,this.uint16[y+10]=l,this.uint16[y+11]=c,this.uint16[y+12]=u,this.float32[x+7]=f,this.float32[x+8]=h,this.uint8[b+36]=p,this.uint8[b+37]=d,this.uint8[b+38]=m,this.uint32[x+10]=g,this.int16[y+22]=v,t},e}(Pi);Wi.prototype.bytesPerElement=48,Nn("StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48",Wi);var Xi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer),this.uint32=new Uint32Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r,n,i,a,o,s,l,c,u,f,h,p,d,m,g,v,y,x,b,_,w,T,k,A,M,S){var E=this.length;return this.resize(E+1),this.emplace(E,t,e,r,n,i,a,o,s,l,c,u,f,h,p,d,m,g,v,y,x,b,_,w,T,k,A,M,S)},e.prototype.emplace=function(t,e,r,n,i,a,o,s,l,c,u,f,h,p,d,m,g,v,y,x,b,_,w,T,k,A,M,S,E){var L=34*t,C=17*t;return this.int16[L+0]=e,this.int16[L+1]=r,this.int16[L+2]=n,this.int16[L+3]=i,this.int16[L+4]=a,this.int16[L+5]=o,this.int16[L+6]=s,this.int16[L+7]=l,this.uint16[L+8]=c,this.uint16[L+9]=u,this.uint16[L+10]=f,this.uint16[L+11]=h,this.uint16[L+12]=p,this.uint16[L+13]=d,this.uint16[L+14]=m,this.uint16[L+15]=g,this.uint16[L+16]=v,this.uint16[L+17]=y,this.uint16[L+18]=x,this.uint16[L+19]=b,this.uint16[L+20]=_,this.uint16[L+21]=w,this.uint16[L+22]=T,this.uint32[C+12]=k,this.float32[C+13]=A,this.float32[C+14]=M,this.float32[C+15]=S,this.float32[C+16]=E,t},e}(Pi);Xi.prototype.bytesPerElement=68,Nn("StructArrayLayout8i15ui1ul4f68",Xi);var Zi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t){var e=this.length;return this.resize(e+1),this.emplace(e,t)},e.prototype.emplace=function(t,e){var r=1*t;return this.float32[r+0]=e,t},e}(Pi);Zi.prototype.bytesPerElement=4,Nn("StructArrayLayout1f4",Zi);var Ji=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r){var n=this.length;return this.resize(n+1),this.emplace(n,t,e,r)},e.prototype.emplace=function(t,e,r,n){var i=3*t;return this.int16[i+0]=e,this.int16[i+1]=r,this.int16[i+2]=n,t},e}(Pi);Ji.prototype.bytesPerElement=6,Nn("StructArrayLayout3i6",Ji);var Ki=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.uint32=new Uint32Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r){var n=this.length;return this.resize(n+1),this.emplace(n,t,e,r)},e.prototype.emplace=function(t,e,r,n){var i=2*t,a=4*t;return this.uint32[i+0]=e,this.uint16[a+2]=r,this.uint16[a+3]=n,t},e}(Pi);Ki.prototype.bytesPerElement=8,Nn("StructArrayLayout1ul2ui8",Ki);var Qi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e){var r=this.length;return this.resize(r+1),this.emplace(r,t,e)},e.prototype.emplace=function(t,e,r){var n=2*t;return this.uint16[n+0]=e,this.uint16[n+1]=r,t},e}(Pi);Qi.prototype.bytesPerElement=4,Nn("StructArrayLayout2ui4",Qi);var $i=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t){var e=this.length;return this.resize(e+1),this.emplace(e,t)},e.prototype.emplace=function(t,e){var r=1*t;return this.uint16[r+0]=e,t},e}(Pi);$i.prototype.bytesPerElement=2,Nn("StructArrayLayout1ui2",$i);var ta=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e){var r=this.length;return this.resize(r+1),this.emplace(r,t,e)},e.prototype.emplace=function(t,e,r){var n=2*t;return this.float32[n+0]=e,this.float32[n+1]=r,t},e}(Pi);ta.prototype.bytesPerElement=8,Nn("StructArrayLayout2f8",ta);var ea=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer)},e.prototype.emplaceBack=function(t,e,r,n){var i=this.length;return this.resize(i+1),this.emplace(i,t,e,r,n)},e.prototype.emplace=function(t,e,r,n,i){var a=4*t;return this.float32[a+0]=e,this.float32[a+1]=r,this.float32[a+2]=n,this.float32[a+3]=i,t},e}(Pi);ea.prototype.bytesPerElement=16,Nn("StructArrayLayout4f16",ea);var ra=function(t){function e(){t.apply(this,arguments)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={anchorPointX:{configurable:!0},anchorPointY:{configurable:!0},x1:{configurable:!0},y1:{configurable:!0},x2:{configurable:!0},y2:{configurable:!0},featureIndex:{configurable:!0},sourceLayerIndex:{configurable:!0},bucketIndex:{configurable:!0},anchorPoint:{configurable:!0}};return r.anchorPointX.get=function(){return this._structArray.int16[this._pos2+0]},r.anchorPointY.get=function(){return this._structArray.int16[this._pos2+1]},r.x1.get=function(){return this._structArray.int16[this._pos2+2]},r.y1.get=function(){return this._structArray.int16[this._pos2+3]},r.x2.get=function(){return this._structArray.int16[this._pos2+4]},r.y2.get=function(){return this._structArray.int16[this._pos2+5]},r.featureIndex.get=function(){return this._structArray.uint32[this._pos4+3]},r.sourceLayerIndex.get=function(){return this._structArray.uint16[this._pos2+8]},r.bucketIndex.get=function(){return this._structArray.uint16[this._pos2+9]},r.anchorPoint.get=function(){return new i(this.anchorPointX,this.anchorPointY)},Object.defineProperties(e.prototype,r),e}(Ci);ra.prototype.size=20;var na=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.get=function(t){return new ra(this,t)},e}(Vi);Nn("CollisionBoxArray",na);var ia=function(t){function e(){t.apply(this,arguments)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={anchorX:{configurable:!0},anchorY:{configurable:!0},glyphStartIndex:{configurable:!0},numGlyphs:{configurable:!0},vertexStartIndex:{configurable:!0},lineStartIndex:{configurable:!0},lineLength:{configurable:!0},segment:{configurable:!0},lowerSize:{configurable:!0},upperSize:{configurable:!0},lineOffsetX:{configurable:!0},lineOffsetY:{configurable:!0},writingMode:{configurable:!0},placedOrientation:{configurable:!0},hidden:{configurable:!0},crossTileID:{configurable:!0},associatedIconIndex:{configurable:!0}};return r.anchorX.get=function(){return this._structArray.int16[this._pos2+0]},r.anchorY.get=function(){return this._structArray.int16[this._pos2+1]},r.glyphStartIndex.get=function(){return this._structArray.uint16[this._pos2+2]},r.numGlyphs.get=function(){return this._structArray.uint16[this._pos2+3]},r.vertexStartIndex.get=function(){return this._structArray.uint32[this._pos4+2]},r.lineStartIndex.get=function(){return this._structArray.uint32[this._pos4+3]},r.lineLength.get=function(){return this._structArray.uint32[this._pos4+4]},r.segment.get=function(){return this._structArray.uint16[this._pos2+10]},r.lowerSize.get=function(){return this._structArray.uint16[this._pos2+11]},r.upperSize.get=function(){return this._structArray.uint16[this._pos2+12]},r.lineOffsetX.get=function(){return this._structArray.float32[this._pos4+7]},r.lineOffsetY.get=function(){return this._structArray.float32[this._pos4+8]},r.writingMode.get=function(){return this._structArray.uint8[this._pos1+36]},r.placedOrientation.get=function(){return this._structArray.uint8[this._pos1+37]},r.placedOrientation.set=function(t){this._structArray.uint8[this._pos1+37]=t},r.hidden.get=function(){return this._structArray.uint8[this._pos1+38]},r.hidden.set=function(t){this._structArray.uint8[this._pos1+38]=t},r.crossTileID.get=function(){return this._structArray.uint32[this._pos4+10]},r.crossTileID.set=function(t){this._structArray.uint32[this._pos4+10]=t},r.associatedIconIndex.get=function(){return this._structArray.int16[this._pos2+22]},Object.defineProperties(e.prototype,r),e}(Ci);ia.prototype.size=48;var aa=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.get=function(t){return new ia(this,t)},e}(Wi);Nn("PlacedSymbolArray",aa);var oa=function(t){function e(){t.apply(this,arguments)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={anchorX:{configurable:!0},anchorY:{configurable:!0},rightJustifiedTextSymbolIndex:{configurable:!0},centerJustifiedTextSymbolIndex:{configurable:!0},leftJustifiedTextSymbolIndex:{configurable:!0},verticalPlacedTextSymbolIndex:{configurable:!0},placedIconSymbolIndex:{configurable:!0},verticalPlacedIconSymbolIndex:{configurable:!0},key:{configurable:!0},textBoxStartIndex:{configurable:!0},textBoxEndIndex:{configurable:!0},verticalTextBoxStartIndex:{configurable:!0},verticalTextBoxEndIndex:{configurable:!0},iconBoxStartIndex:{configurable:!0},iconBoxEndIndex:{configurable:!0},verticalIconBoxStartIndex:{configurable:!0},verticalIconBoxEndIndex:{configurable:!0},featureIndex:{configurable:!0},numHorizontalGlyphVertices:{configurable:!0},numVerticalGlyphVertices:{configurable:!0},numIconVertices:{configurable:!0},numVerticalIconVertices:{configurable:!0},useRuntimeCollisionCircles:{configurable:!0},crossTileID:{configurable:!0},textBoxScale:{configurable:!0},textOffset0:{configurable:!0},textOffset1:{configurable:!0},collisionCircleDiameter:{configurable:!0}};return r.anchorX.get=function(){return this._structArray.int16[this._pos2+0]},r.anchorY.get=function(){return this._structArray.int16[this._pos2+1]},r.rightJustifiedTextSymbolIndex.get=function(){return this._structArray.int16[this._pos2+2]},r.centerJustifiedTextSymbolIndex.get=function(){return this._structArray.int16[this._pos2+3]},r.leftJustifiedTextSymbolIndex.get=function(){return this._structArray.int16[this._pos2+4]},r.verticalPlacedTextSymbolIndex.get=function(){return this._structArray.int16[this._pos2+5]},r.placedIconSymbolIndex.get=function(){return this._structArray.int16[this._pos2+6]},r.verticalPlacedIconSymbolIndex.get=function(){return this._structArray.int16[this._pos2+7]},r.key.get=function(){return this._structArray.uint16[this._pos2+8]},r.textBoxStartIndex.get=function(){return this._structArray.uint16[this._pos2+9]},r.textBoxEndIndex.get=function(){return this._structArray.uint16[this._pos2+10]},r.verticalTextBoxStartIndex.get=function(){return this._structArray.uint16[this._pos2+11]},r.verticalTextBoxEndIndex.get=function(){return this._structArray.uint16[this._pos2+12]},r.iconBoxStartIndex.get=function(){return this._structArray.uint16[this._pos2+13]},r.iconBoxEndIndex.get=function(){return this._structArray.uint16[this._pos2+14]},r.verticalIconBoxStartIndex.get=function(){return this._structArray.uint16[this._pos2+15]},r.verticalIconBoxEndIndex.get=function(){return this._structArray.uint16[this._pos2+16]},r.featureIndex.get=function(){return this._structArray.uint16[this._pos2+17]},r.numHorizontalGlyphVertices.get=function(){return this._structArray.uint16[this._pos2+18]},r.numVerticalGlyphVertices.get=function(){return this._structArray.uint16[this._pos2+19]},r.numIconVertices.get=function(){return this._structArray.uint16[this._pos2+20]},r.numVerticalIconVertices.get=function(){return this._structArray.uint16[this._pos2+21]},r.useRuntimeCollisionCircles.get=function(){return this._structArray.uint16[this._pos2+22]},r.crossTileID.get=function(){return this._structArray.uint32[this._pos4+12]},r.crossTileID.set=function(t){this._structArray.uint32[this._pos4+12]=t},r.textBoxScale.get=function(){return this._structArray.float32[this._pos4+13]},r.textOffset0.get=function(){return this._structArray.float32[this._pos4+14]},r.textOffset1.get=function(){return this._structArray.float32[this._pos4+15]},r.collisionCircleDiameter.get=function(){return this._structArray.float32[this._pos4+16]},Object.defineProperties(e.prototype,r),e}(Ci);oa.prototype.size=68;var sa=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.get=function(t){return new oa(this,t)},e}(Xi);Nn("SymbolInstanceArray",sa);var la=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getoffsetX=function(t){return this.float32[1*t+0]},e}(Zi);Nn("GlyphOffsetArray",la);var ca=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getx=function(t){return this.int16[3*t+0]},e.prototype.gety=function(t){return this.int16[3*t+1]},e.prototype.gettileUnitDistanceFromAnchor=function(t){return this.int16[3*t+2]},e}(Ji);Nn("SymbolLineVertexArray",ca);var ua=function(t){function e(){t.apply(this,arguments)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={featureIndex:{configurable:!0},sourceLayerIndex:{configurable:!0},bucketIndex:{configurable:!0}};return r.featureIndex.get=function(){return this._structArray.uint32[this._pos4+0]},r.sourceLayerIndex.get=function(){return this._structArray.uint16[this._pos2+2]},r.bucketIndex.get=function(){return this._structArray.uint16[this._pos2+3]},Object.defineProperties(e.prototype,r),e}(Ci);ua.prototype.size=8;var fa=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.get=function(t){return new ua(this,t)},e}(Ki);Nn("FeatureIndexArray",fa);var ha=Ii([{name:"a_pos",components:2,type:"Int16"}],4).members,pa=function(t){void 0===t&&(t=[]),this.segments=t};function da(t,e){return 256*(t=l(Math.floor(t),0,255))+(e=l(Math.floor(e),0,255))}pa.prototype.prepareSegment=function(t,e,r,n){var i=this.segments[this.segments.length-1];return t>pa.MAX_VERTEX_ARRAY_LENGTH&&_("Max vertices per segment is "+pa.MAX_VERTEX_ARRAY_LENGTH+": bucket requested "+t),(!i||i.vertexLength+t>pa.MAX_VERTEX_ARRAY_LENGTH||i.sortKey!==n)&&(i={vertexOffset:e.length,primitiveOffset:r.length,vertexLength:0,primitiveLength:0},void 0!==n&&(i.sortKey=n),this.segments.push(i)),i},pa.prototype.get=function(){return this.segments},pa.prototype.destroy=function(){for(var t=0,e=this.segments;t<e.length;t+=1){var r=e[t];for(var n in r.vaos)r.vaos[n].destroy()}},pa.simpleSegment=function(t,e,r,n){return new pa([{vertexOffset:t,primitiveOffset:e,vertexLength:r,primitiveLength:n,vaos:{},sortKey:0}])},pa.MAX_VERTEX_ARRAY_LENGTH=Math.pow(2,16)-1,Nn("SegmentVector",pa);var ma=Ii([{name:"a_pattern_from",components:4,type:"Uint16"},{name:"a_pattern_to",components:4,type:"Uint16"},{name:"a_pixel_ratio_from",components:1,type:"Uint8"},{name:"a_pixel_ratio_to",components:1,type:"Uint8"}]),ga=e((function(t){t.exports=function(t,e){var r,n,i,a,o,s,l,c;for(r=3&t.length,n=t.length-r,i=e,o=3432918353,s=461845907,c=0;c<n;)l=255&t.charCodeAt(c)|(255&t.charCodeAt(++c))<<8|(255&t.charCodeAt(++c))<<16|(255&t.charCodeAt(++c))<<24,++c,i=27492+(65535&(a=5*(65535&(i=(i^=l=(65535&(l=(l=(65535&l)*o+(((l>>>16)*o&65535)<<16)&4294967295)<<15|l>>>17))*s+(((l>>>16)*s&65535)<<16)&4294967295)<<13|i>>>19))+((5*(i>>>16)&65535)<<16)&4294967295))+((58964+(a>>>16)&65535)<<16);switch(l=0,r){case 3:l^=(255&t.charCodeAt(c+2))<<16;case 2:l^=(255&t.charCodeAt(c+1))<<8;case 1:i^=l=(65535&(l=(l=(65535&(l^=255&t.charCodeAt(c)))*o+(((l>>>16)*o&65535)<<16)&4294967295)<<15|l>>>17))*s+(((l>>>16)*s&65535)<<16)&4294967295}return i^=t.length,i=2246822507*(65535&(i^=i>>>16))+((2246822507*(i>>>16)&65535)<<16)&4294967295,i=3266489909*(65535&(i^=i>>>13))+((3266489909*(i>>>16)&65535)<<16)&4294967295,(i^=i>>>16)>>>0}})),va=e((function(t){t.exports=function(t,e){for(var r,n=t.length,i=e^n,a=0;n>=4;)r=1540483477*(65535&(r=255&t.charCodeAt(a)|(255&t.charCodeAt(++a))<<8|(255&t.charCodeAt(++a))<<16|(255&t.charCodeAt(++a))<<24))+((1540483477*(r>>>16)&65535)<<16),i=1540483477*(65535&i)+((1540483477*(i>>>16)&65535)<<16)^(r=1540483477*(65535&(r^=r>>>24))+((1540483477*(r>>>16)&65535)<<16)),n-=4,++a;switch(n){case 3:i^=(255&t.charCodeAt(a+2))<<16;case 2:i^=(255&t.charCodeAt(a+1))<<8;case 1:i=1540483477*(65535&(i^=255&t.charCodeAt(a)))+((1540483477*(i>>>16)&65535)<<16)}return i=1540483477*(65535&(i^=i>>>13))+((1540483477*(i>>>16)&65535)<<16),(i^=i>>>15)>>>0}})),ya=ga,xa=ga,ba=va;ya.murmur3=xa,ya.murmur2=ba;var _a=function(){this.ids=[],this.positions=[],this.indexed=!1};_a.prototype.add=function(t,e,r,n){this.ids.push(Ta(t)),this.positions.push(e,r,n)},_a.prototype.getPositions=function(t){for(var e=Ta(t),r=0,n=this.ids.length-1;r<n;){var i=r+n>>1;this.ids[i]>=e?n=i:r=i+1}for(var a=[];this.ids[r]===e;){var o=this.positions[3*r],s=this.positions[3*r+1],l=this.positions[3*r+2];a.push({index:o,start:s,end:l}),r++}return a},_a.serialize=function(t,e){var r=new Float64Array(t.ids),n=new Uint32Array(t.positions);return function t(e,r,n,i){for(;n<i;){for(var a=e[n+i>>1],o=n-1,s=i+1;;){do{o++}while(e[o]<a);do{s--}while(e[s]>a);if(o>=s)break;ka(e,o,s),ka(r,3*o,3*s),ka(r,3*o+1,3*s+1),ka(r,3*o+2,3*s+2)}s-n<i-s?(t(e,r,n,s),n=s+1):(t(e,r,s+1,i),i=s)}}(r,n,0,r.length-1),e&&e.push(r.buffer,n.buffer),{ids:r,positions:n}},_a.deserialize=function(t){var e=new _a;return e.ids=t.ids,e.positions=t.positions,e.indexed=!0,e};var wa=Math.pow(2,53)-1;function Ta(t){var e=+t;return!isNaN(e)&&e<=wa?e:ya(String(t))}function ka(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}Nn("FeaturePositionMap",_a);var Aa=function(t,e){this.gl=t.gl,this.location=e},Ma=function(t){function e(e,r){t.call(this,e,r),this.current=0}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){this.current!==t&&(this.current=t,this.gl.uniform1i(this.location,t))},e}(Aa),Sa=function(t){function e(e,r){t.call(this,e,r),this.current=0}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){this.current!==t&&(this.current=t,this.gl.uniform1f(this.location,t))},e}(Aa),Ea=function(t){function e(e,r){t.call(this,e,r),this.current=[0,0]}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){t[0]===this.current[0]&&t[1]===this.current[1]||(this.current=t,this.gl.uniform2f(this.location,t[0],t[1]))},e}(Aa),La=function(t){function e(e,r){t.call(this,e,r),this.current=[0,0,0]}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){t[0]===this.current[0]&&t[1]===this.current[1]&&t[2]===this.current[2]||(this.current=t,this.gl.uniform3f(this.location,t[0],t[1],t[2]))},e}(Aa),Ca=function(t){function e(e,r){t.call(this,e,r),this.current=[0,0,0,0]}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){t[0]===this.current[0]&&t[1]===this.current[1]&&t[2]===this.current[2]&&t[3]===this.current[3]||(this.current=t,this.gl.uniform4f(this.location,t[0],t[1],t[2],t[3]))},e}(Aa),Pa=function(t){function e(e,r){t.call(this,e,r),this.current=te.transparent}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){t.r===this.current.r&&t.g===this.current.g&&t.b===this.current.b&&t.a===this.current.a||(this.current=t,this.gl.uniform4f(this.location,t.r,t.g,t.b,t.a))},e}(Aa),Ia=new Float32Array(16),Oa=function(t){function e(e,r){t.call(this,e,r),this.current=Ia}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){if(t[12]!==this.current[12]||t[0]!==this.current[0])return this.current=t,void this.gl.uniformMatrix4fv(this.location,!1,t);for(var e=1;e<16;e++)if(t[e]!==this.current[e]){this.current=t,this.gl.uniformMatrix4fv(this.location,!1,t);break}},e}(Aa);function za(t){return[da(255*t.r,255*t.g),da(255*t.b,255*t.a)]}var Da=function(t,e,r){this.value=t,this.uniformNames=e.map((function(t){return"u_"+t})),this.type=r};Da.prototype.setUniform=function(t,e,r){t.set(r.constantOr(this.value))},Da.prototype.getBinding=function(t,e,r){return"color"===this.type?new Pa(t,e):new Sa(t,e)};var Ra=function(t,e){this.uniformNames=e.map((function(t){return"u_"+t})),this.patternFrom=null,this.patternTo=null,this.pixelRatioFrom=1,this.pixelRatioTo=1};Ra.prototype.setConstantPatternPositions=function(t,e){this.pixelRatioFrom=e.pixelRatio,this.pixelRatioTo=t.pixelRatio,this.patternFrom=e.tlbr,this.patternTo=t.tlbr},Ra.prototype.setUniform=function(t,e,r,n){var i="u_pattern_to"===n?this.patternTo:"u_pattern_from"===n?this.patternFrom:"u_pixel_ratio_to"===n?this.pixelRatioTo:"u_pixel_ratio_from"===n?this.pixelRatioFrom:null;i&&t.set(i)},Ra.prototype.getBinding=function(t,e,r){return"u_pattern"===r.substr(0,9)?new Ca(t,e):new Sa(t,e)};var Fa=function(t,e,r,n){this.expression=t,this.type=r,this.maxValue=0,this.paintVertexAttributes=e.map((function(t){return{name:"a_"+t,type:"Float32",components:"color"===r?2:1,offset:0}})),this.paintVertexArray=new n};Fa.prototype.populatePaintArray=function(t,e,r,n,i){var a=this.paintVertexArray.length,o=this.expression.evaluate(new pi(0),e,{},n,[],i);this.paintVertexArray.resize(t),this._setPaintValue(a,t,o)},Fa.prototype.updatePaintArray=function(t,e,r,n){var i=this.expression.evaluate({zoom:0},r,n);this._setPaintValue(t,e,i)},Fa.prototype._setPaintValue=function(t,e,r){if("color"===this.type)for(var n=za(r),i=t;i<e;i++)this.paintVertexArray.emplace(i,n[0],n[1]);else{for(var a=t;a<e;a++)this.paintVertexArray.emplace(a,r);this.maxValue=Math.max(this.maxValue,Math.abs(r))}},Fa.prototype.upload=function(t){this.paintVertexArray&&this.paintVertexArray.arrayBuffer&&(this.paintVertexBuffer&&this.paintVertexBuffer.buffer?this.paintVertexBuffer.updateData(this.paintVertexArray):this.paintVertexBuffer=t.createVertexBuffer(this.paintVertexArray,this.paintVertexAttributes,this.expression.isStateDependent))},Fa.prototype.destroy=function(){this.paintVertexBuffer&&this.paintVertexBuffer.destroy()};var Ba=function(t,e,r,n,i,a){this.expression=t,this.uniformNames=e.map((function(t){return"u_"+t+"_t"})),this.type=r,this.useIntegerZoom=n,this.zoom=i,this.maxValue=0,this.paintVertexAttributes=e.map((function(t){return{name:"a_"+t,type:"Float32",components:"color"===r?4:2,offset:0}})),this.paintVertexArray=new a};Ba.prototype.populatePaintArray=function(t,e,r,n,i){var a=this.expression.evaluate(new pi(this.zoom),e,{},n,[],i),o=this.expression.evaluate(new pi(this.zoom+1),e,{},n,[],i),s=this.paintVertexArray.length;this.paintVertexArray.resize(t),this._setPaintValue(s,t,a,o)},Ba.prototype.updatePaintArray=function(t,e,r,n){var i=this.expression.evaluate({zoom:this.zoom},r,n),a=this.expression.evaluate({zoom:this.zoom+1},r,n);this._setPaintValue(t,e,i,a)},Ba.prototype._setPaintValue=function(t,e,r,n){if("color"===this.type)for(var i=za(r),a=za(n),o=t;o<e;o++)this.paintVertexArray.emplace(o,i[0],i[1],a[0],a[1]);else{for(var s=t;s<e;s++)this.paintVertexArray.emplace(s,r,n);this.maxValue=Math.max(this.maxValue,Math.abs(r),Math.abs(n))}},Ba.prototype.upload=function(t){this.paintVertexArray&&this.paintVertexArray.arrayBuffer&&(this.paintVertexBuffer&&this.paintVertexBuffer.buffer?this.paintVertexBuffer.updateData(this.paintVertexArray):this.paintVertexBuffer=t.createVertexBuffer(this.paintVertexArray,this.paintVertexAttributes,this.expression.isStateDependent))},Ba.prototype.destroy=function(){this.paintVertexBuffer&&this.paintVertexBuffer.destroy()},Ba.prototype.setUniform=function(t,e){var r=this.useIntegerZoom?Math.floor(e.zoom):e.zoom,n=l(this.expression.interpolationFactor(r,this.zoom,this.zoom+1),0,1);t.set(n)},Ba.prototype.getBinding=function(t,e,r){return new Sa(t,e)};var Na=function(t,e,r,n,i,a){this.expression=t,this.type=e,this.useIntegerZoom=r,this.zoom=n,this.layerId=a,this.zoomInPaintVertexArray=new i,this.zoomOutPaintVertexArray=new i};Na.prototype.populatePaintArray=function(t,e,r){var n=this.zoomInPaintVertexArray.length;this.zoomInPaintVertexArray.resize(t),this.zoomOutPaintVertexArray.resize(t),this._setPaintValues(n,t,e.patterns&&e.patterns[this.layerId],r)},Na.prototype.updatePaintArray=function(t,e,r,n,i){this._setPaintValues(t,e,r.patterns&&r.patterns[this.layerId],i)},Na.prototype._setPaintValues=function(t,e,r,n){if(n&&r){var i=r.min,a=r.mid,o=r.max,s=n[i],l=n[a],c=n[o];if(s&&l&&c)for(var u=t;u<e;u++)this.zoomInPaintVertexArray.emplace(u,l.tl[0],l.tl[1],l.br[0],l.br[1],s.tl[0],s.tl[1],s.br[0],s.br[1],l.pixelRatio,s.pixelRatio),this.zoomOutPaintVertexArray.emplace(u,l.tl[0],l.tl[1],l.br[0],l.br[1],c.tl[0],c.tl[1],c.br[0],c.br[1],l.pixelRatio,c.pixelRatio)}},Na.prototype.upload=function(t){this.zoomInPaintVertexArray&&this.zoomInPaintVertexArray.arrayBuffer&&this.zoomOutPaintVertexArray&&this.zoomOutPaintVertexArray.arrayBuffer&&(this.zoomInPaintVertexBuffer=t.createVertexBuffer(this.zoomInPaintVertexArray,ma.members,this.expression.isStateDependent),this.zoomOutPaintVertexBuffer=t.createVertexBuffer(this.zoomOutPaintVertexArray,ma.members,this.expression.isStateDependent))},Na.prototype.destroy=function(){this.zoomOutPaintVertexBuffer&&this.zoomOutPaintVertexBuffer.destroy(),this.zoomInPaintVertexBuffer&&this.zoomInPaintVertexBuffer.destroy()};var ja=function(t,e,r,n){this.binders={},this.layoutAttributes=n,this._buffers=[];var i=[];for(var a in t.paint._values)if(r(a)){var o=t.paint.get(a);if(o instanceof bi&&zr(o.property.specification)){var s=Va(a,t.type),l=o.value,c=o.property.specification.type,u=o.property.useIntegerZoom,f=o.property.specification["property-type"],h="cross-faded"===f||"cross-faded-data-driven"===f;if("constant"===l.kind)this.binders[a]=h?new Ra(l.value,s):new Da(l.value,s,c),i.push("/u_"+a);else if("source"===l.kind||h){var p=Ha(a,c,"source");this.binders[a]=h?new Na(l,c,u,e,p,t.id):new Fa(l,s,c,p),i.push("/a_"+a)}else{var d=Ha(a,c,"composite");this.binders[a]=new Ba(l,s,c,u,e,d),i.push("/z_"+a)}}}this.cacheKey=i.sort().join("")};ja.prototype.getMaxValue=function(t){var e=this.binders[t];return e instanceof Fa||e instanceof Ba?e.maxValue:0},ja.prototype.populatePaintArrays=function(t,e,r,n,i){for(var a in this.binders){var o=this.binders[a];(o instanceof Fa||o instanceof Ba||o instanceof Na)&&o.populatePaintArray(t,e,r,n,i)}},ja.prototype.setConstantPatternPositions=function(t,e){for(var r in this.binders){var n=this.binders[r];n instanceof Ra&&n.setConstantPatternPositions(t,e)}},ja.prototype.updatePaintArrays=function(t,e,r,n,i){var a=!1;for(var o in t)for(var s=0,l=e.getPositions(o);s<l.length;s+=1){var c=l[s],u=r.feature(c.index);for(var f in this.binders){var h=this.binders[f];if((h instanceof Fa||h instanceof Ba||h instanceof Na)&&!0===h.expression.isStateDependent){var p=n.paint.get(f);h.expression=p.value,h.updatePaintArray(c.start,c.end,u,t[o],i),a=!0}}}return a},ja.prototype.defines=function(){var t=[];for(var e in this.binders){var r=this.binders[e];(r instanceof Da||r instanceof Ra)&&t.push.apply(t,r.uniformNames.map((function(t){return"#define HAS_UNIFORM_"+t})))}return t},ja.prototype.getPaintVertexBuffers=function(){return this._buffers},ja.prototype.getUniforms=function(t,e){var r=[];for(var n in this.binders){var i=this.binders[n];if(i instanceof Da||i instanceof Ra||i instanceof Ba)for(var a=0,o=i.uniformNames;a<o.length;a+=1){var s=o[a];if(e[s]){var l=i.getBinding(t,e[s],s);r.push({name:s,property:n,binding:l})}}}return r},ja.prototype.setUniforms=function(t,e,r,n){for(var i=0,a=e;i<a.length;i+=1){var o=a[i],s=o.name,l=o.property,c=o.binding;this.binders[l].setUniform(c,n,r.get(l),s)}},ja.prototype.updatePaintBuffers=function(t){for(var e in this._buffers=[],this.binders){var r=this.binders[e];if(t&&r instanceof Na){var n=2===t.fromScale?r.zoomInPaintVertexBuffer:r.zoomOutPaintVertexBuffer;n&&this._buffers.push(n)}else(r instanceof Fa||r instanceof Ba)&&r.paintVertexBuffer&&this._buffers.push(r.paintVertexBuffer)}},ja.prototype.upload=function(t){for(var e in this.binders){var r=this.binders[e];(r instanceof Fa||r instanceof Ba||r instanceof Na)&&r.upload(t)}this.updatePaintBuffers()},ja.prototype.destroy=function(){for(var t in this.binders){var e=this.binders[t];(e instanceof Fa||e instanceof Ba||e instanceof Na)&&e.destroy()}};var Ua=function(t,e,r,n){void 0===n&&(n=function(){return!0}),this.programConfigurations={};for(var i=0,a=e;i<a.length;i+=1){var o=a[i];this.programConfigurations[o.id]=new ja(o,r,n,t)}this.needsUpload=!1,this._featureMap=new _a,this._bufferOffset=0};function Va(t,e){return{"text-opacity":["opacity"],"icon-opacity":["opacity"],"text-color":["fill_color"],"icon-color":["fill_color"],"text-halo-color":["halo_color"],"icon-halo-color":["halo_color"],"text-halo-blur":["halo_blur"],"icon-halo-blur":["halo_blur"],"text-halo-width":["halo_width"],"icon-halo-width":["halo_width"],"line-gap-width":["gapwidth"],"line-pattern":["pattern_to","pattern_from","pixel_ratio_to","pixel_ratio_from"],"fill-pattern":["pattern_to","pattern_from","pixel_ratio_to","pixel_ratio_from"],"fill-extrusion-pattern":["pattern_to","pattern_from","pixel_ratio_to","pixel_ratio_from"]}[t]||[t.replace(e+"-","").replace(/-/g,"_")]}function Ha(t,e,r){var n={color:{source:ta,composite:ea},number:{source:Zi,composite:ta}},i=function(t){return{"line-pattern":{source:Bi,composite:Bi},"fill-pattern":{source:Bi,composite:Bi},"fill-extrusion-pattern":{source:Bi,composite:Bi}}[t]}(t);return i&&i[r]||n[e][r]}Ua.prototype.populatePaintArrays=function(t,e,r,n,i,a){for(var o in this.programConfigurations)this.programConfigurations[o].populatePaintArrays(t,e,n,i,a);void 0!==e.id&&this._featureMap.add(e.id,r,this._bufferOffset,t),this._bufferOffset=t,this.needsUpload=!0},Ua.prototype.updatePaintArrays=function(t,e,r,n){for(var i=0,a=r;i<a.length;i+=1){var o=a[i];this.needsUpload=this.programConfigurations[o.id].updatePaintArrays(t,this._featureMap,e,o,n)||this.needsUpload}},Ua.prototype.get=function(t){return this.programConfigurations[t]},Ua.prototype.upload=function(t){if(this.needsUpload){for(var e in this.programConfigurations)this.programConfigurations[e].upload(t);this.needsUpload=!1}},Ua.prototype.destroy=function(){for(var t in this.programConfigurations)this.programConfigurations[t].destroy()},Nn("ConstantBinder",Da),Nn("CrossFadedConstantBinder",Ra),Nn("SourceExpressionBinder",Fa),Nn("CrossFadedCompositeBinder",Na),Nn("CompositeExpressionBinder",Ba),Nn("ProgramConfiguration",ja,{omit:["_buffers"]}),Nn("ProgramConfigurationSet",Ua);var qa,Ga=(qa=15,{min:-1*Math.pow(2,qa-1),max:Math.pow(2,qa-1)-1});function Ya(t){for(var e=8192/t.extent,r=t.loadGeometry(),n=0;n<r.length;n++)for(var i=r[n],a=0;a<i.length;a++){var o=i[a];o.x=Math.round(o.x*e),o.y=Math.round(o.y*e),(o.x<Ga.min||o.x>Ga.max||o.y<Ga.min||o.y>Ga.max)&&(_("Geometry exceeds allowed extent, reduce your vector tile buffer size"),o.x=l(o.x,Ga.min,Ga.max),o.y=l(o.y,Ga.min,Ga.max))}return r}function Wa(t,e,r,n,i){t.emplaceBack(2*e+(n+1)/2,2*r+(i+1)/2)}var Xa=function(t){this.zoom=t.zoom,this.overscaling=t.overscaling,this.layers=t.layers,this.layerIds=this.layers.map((function(t){return t.id})),this.index=t.index,this.hasPattern=!1,this.layoutVertexArray=new zi,this.indexArray=new Yi,this.segments=new pa,this.programConfigurations=new Ua(ha,t.layers,t.zoom),this.stateDependentLayerIds=this.layers.filter((function(t){return t.isStateDependent()})).map((function(t){return t.id}))};function Za(t,e){for(var r=0;r<t.length;r++)if(io(e,t[r]))return!0;for(var n=0;n<e.length;n++)if(io(t,e[n]))return!0;return!!$a(t,e)}function Ja(t,e,r){return!!io(t,e)||!!eo(e,t,r)}function Ka(t,e){if(1===t.length)return no(e,t[0]);for(var r=0;r<e.length;r++)for(var n=e[r],i=0;i<n.length;i++)if(io(t,n[i]))return!0;for(var a=0;a<t.length;a++)if(no(e,t[a]))return!0;for(var o=0;o<e.length;o++)if($a(t,e[o]))return!0;return!1}function Qa(t,e,r){if(t.length>1){if($a(t,e))return!0;for(var n=0;n<e.length;n++)if(eo(e[n],t,r))return!0}for(var i=0;i<t.length;i++)if(eo(t[i],e,r))return!0;return!1}function $a(t,e){if(0===t.length||0===e.length)return!1;for(var r=0;r<t.length-1;r++)for(var n=t[r],i=t[r+1],a=0;a<e.length-1;a++){if(to(n,i,e[a],e[a+1]))return!0}return!1}function to(t,e,r,n){return w(t,r,n)!==w(e,r,n)&&w(t,e,r)!==w(t,e,n)}function eo(t,e,r){var n=r*r;if(1===e.length)return t.distSqr(e[0])<n;for(var i=1;i<e.length;i++){if(ro(t,e[i-1],e[i])<n)return!0}return!1}function ro(t,e,r){var n=e.distSqr(r);if(0===n)return t.distSqr(e);var i=((t.x-e.x)*(r.x-e.x)+(t.y-e.y)*(r.y-e.y))/n;return i<0?t.distSqr(e):i>1?t.distSqr(r):t.distSqr(r.sub(e)._mult(i)._add(e))}function no(t,e){for(var r,n,i,a=!1,o=0;o<t.length;o++)for(var s=0,l=(r=t[o]).length-1;s<r.length;l=s++)n=r[s],i=r[l],n.y>e.y!=i.y>e.y&&e.x<(i.x-n.x)*(e.y-n.y)/(i.y-n.y)+n.x&&(a=!a);return a}function io(t,e){for(var r=!1,n=0,i=t.length-1;n<t.length;i=n++){var a=t[n],o=t[i];a.y>e.y!=o.y>e.y&&e.x<(o.x-a.x)*(e.y-a.y)/(o.y-a.y)+a.x&&(r=!r)}return r}function ao(t,e,r){var n=r[0],i=r[2];if(t.x<n.x&&e.x<n.x||t.x>i.x&&e.x>i.x||t.y<n.y&&e.y<n.y||t.y>i.y&&e.y>i.y)return!1;var a=w(t,e,r[0]);return a!==w(t,e,r[1])||a!==w(t,e,r[2])||a!==w(t,e,r[3])}function oo(t,e,r){var n=e.paint.get(t).value;return"constant"===n.kind?n.value:r.programConfigurations.get(e.id).getMaxValue(t)}function so(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])}function lo(t,e,r,n,a){if(!e[0]&&!e[1])return t;var o=i.convert(e)._mult(a);"viewport"===r&&o._rotate(-n);for(var s=[],l=0;l<t.length;l++){var c=t[l];s.push(c.sub(o))}return s}Xa.prototype.populate=function(t,e,r){var n=this.layers[0],i=[],a=null;"circle"===n.type&&(a=n.layout.get("circle-sort-key"));for(var o=0,s=t;o<s.length;o+=1){var l=s[o],c=l.feature,u=l.id,f=l.index,h=l.sourceLayerIndex,p=this.layers[0]._featureFilter.needGeometry,d={type:c.type,id:u,properties:c.properties,geometry:p?Ya(c):[]};if(this.layers[0]._featureFilter.filter(new pi(this.zoom),d,r)){p||(d.geometry=Ya(c));var m=a?a.evaluate(d,{},r):void 0,g={id:u,properties:c.properties,type:c.type,sourceLayerIndex:h,index:f,geometry:d.geometry,patterns:{},sortKey:m};i.push(g)}}a&&i.sort((function(t,e){return t.sortKey-e.sortKey}));for(var v=0,y=i;v<y.length;v+=1){var x=y[v],b=x,_=b.geometry,w=b.index,T=b.sourceLayerIndex,k=t[w].feature;this.addFeature(x,_,w,r),e.featureIndex.insert(k,_,w,T,this.index)}},Xa.prototype.update=function(t,e,r){this.stateDependentLayers.length&&this.programConfigurations.updatePaintArrays(t,e,this.stateDependentLayers,r)},Xa.prototype.isEmpty=function(){return 0===this.layoutVertexArray.length},Xa.prototype.uploadPending=function(){return!this.uploaded||this.programConfigurations.needsUpload},Xa.prototype.upload=function(t){this.uploaded||(this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,ha),this.indexBuffer=t.createIndexBuffer(this.indexArray)),this.programConfigurations.upload(t),this.uploaded=!0},Xa.prototype.destroy=function(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.programConfigurations.destroy(),this.segments.destroy())},Xa.prototype.addFeature=function(t,e,r,n){for(var i=0,a=e;i<a.length;i+=1)for(var o=0,s=a[i];o<s.length;o+=1){var l=s[o],c=l.x,u=l.y;if(!(c<0||c>=8192||u<0||u>=8192)){var f=this.segments.prepareSegment(4,this.layoutVertexArray,this.indexArray,t.sortKey),h=f.vertexLength;Wa(this.layoutVertexArray,c,u,-1,-1),Wa(this.layoutVertexArray,c,u,1,-1),Wa(this.layoutVertexArray,c,u,1,1),Wa(this.layoutVertexArray,c,u,-1,1),this.indexArray.emplaceBack(h,h+1,h+2),this.indexArray.emplaceBack(h,h+3,h+2),f.vertexLength+=4,f.primitiveLength+=2}}this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length,t,r,{},n)},Nn("CircleBucket",Xa,{omit:["layers"]});var co=new Si({"circle-sort-key":new Ti(Lt.layout_circle["circle-sort-key"])}),uo={paint:new Si({"circle-radius":new Ti(Lt.paint_circle["circle-radius"]),"circle-color":new Ti(Lt.paint_circle["circle-color"]),"circle-blur":new Ti(Lt.paint_circle["circle-blur"]),"circle-opacity":new Ti(Lt.paint_circle["circle-opacity"]),"circle-translate":new wi(Lt.paint_circle["circle-translate"]),"circle-translate-anchor":new wi(Lt.paint_circle["circle-translate-anchor"]),"circle-pitch-scale":new wi(Lt.paint_circle["circle-pitch-scale"]),"circle-pitch-alignment":new wi(Lt.paint_circle["circle-pitch-alignment"]),"circle-stroke-width":new Ti(Lt.paint_circle["circle-stroke-width"]),"circle-stroke-color":new Ti(Lt.paint_circle["circle-stroke-color"]),"circle-stroke-opacity":new Ti(Lt.paint_circle["circle-stroke-opacity"])}),layout:co},fo="undefined"!=typeof Float32Array?Float32Array:Array;function ho(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function po(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],l=e[5],c=e[6],u=e[7],f=e[8],h=e[9],p=e[10],d=e[11],m=e[12],g=e[13],v=e[14],y=e[15],x=r[0],b=r[1],_=r[2],w=r[3];return t[0]=x*n+b*s+_*f+w*m,t[1]=x*i+b*l+_*h+w*g,t[2]=x*a+b*c+_*p+w*v,t[3]=x*o+b*u+_*d+w*y,x=r[4],b=r[5],_=r[6],w=r[7],t[4]=x*n+b*s+_*f+w*m,t[5]=x*i+b*l+_*h+w*g,t[6]=x*a+b*c+_*p+w*v,t[7]=x*o+b*u+_*d+w*y,x=r[8],b=r[9],_=r[10],w=r[11],t[8]=x*n+b*s+_*f+w*m,t[9]=x*i+b*l+_*h+w*g,t[10]=x*a+b*c+_*p+w*v,t[11]=x*o+b*u+_*d+w*y,x=r[12],b=r[13],_=r[14],w=r[15],t[12]=x*n+b*s+_*f+w*m,t[13]=x*i+b*l+_*h+w*g,t[14]=x*a+b*c+_*p+w*v,t[15]=x*o+b*u+_*d+w*y,t}Math.hypot||(Math.hypot=function(){for(var t=arguments,e=0,r=arguments.length;r--;)e+=t[r]*t[r];return Math.sqrt(e)});var mo=po;var go,vo,yo=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t};go=new fo(3),fo!=Float32Array&&(go[0]=0,go[1]=0,go[2]=0),vo=go;function xo(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12]*o,t[1]=r[1]*n+r[5]*i+r[9]*a+r[13]*o,t[2]=r[2]*n+r[6]*i+r[10]*a+r[14]*o,t[3]=r[3]*n+r[7]*i+r[11]*a+r[15]*o,t}!function(){var t=function(){var t=new fo(4);return fo!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}()}();var bo=function(t){var e=t[0],r=t[1];return e*e+r*r},_o=(function(){var t=function(){var t=new fo(2);return fo!=Float32Array&&(t[0]=0,t[1]=0),t}()}(),function(t){function e(e){t.call(this,e,uo)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.createBucket=function(t){return new Xa(t)},e.prototype.queryRadius=function(t){var e=t;return oo("circle-radius",this,e)+oo("circle-stroke-width",this,e)+so(this.paint.get("circle-translate"))},e.prototype.queryIntersectsFeature=function(t,e,r,n,i,a,o,s){for(var l=lo(t,this.paint.get("circle-translate"),this.paint.get("circle-translate-anchor"),a.angle,o),c=this.paint.get("circle-radius").evaluate(e,r)+this.paint.get("circle-stroke-width").evaluate(e,r),u="map"===this.paint.get("circle-pitch-alignment"),f=u?l:function(t,e){return t.map((function(t){return wo(t,e)}))}(l,s),h=u?c*o:c,p=0,d=n;p<d.length;p+=1)for(var m=0,g=d[p];m<g.length;m+=1){var v=g[m],y=u?v:wo(v,s),x=h,b=xo([],[v.x,v.y,0,1],s);if("viewport"===this.paint.get("circle-pitch-scale")&&"map"===this.paint.get("circle-pitch-alignment")?x*=b[3]/a.cameraToCenterDistance:"map"===this.paint.get("circle-pitch-scale")&&"viewport"===this.paint.get("circle-pitch-alignment")&&(x*=a.cameraToCenterDistance/b[3]),Ja(f,y,x))return!0}return!1},e}(Ei));function wo(t,e){var r=xo([],[t.x,t.y,0,1],e);return new i(r[0]/r[3],r[1]/r[3])}var To=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Xa);function ko(t,e,r,n){var i=e.width,a=e.height;if(n){if(n instanceof Uint8ClampedArray)n=new Uint8Array(n.buffer);else if(n.length!==i*a*r)throw new RangeError("mismatched image size")}else n=new Uint8Array(i*a*r);return t.width=i,t.height=a,t.data=n,t}function Ao(t,e,r){var n=e.width,i=e.height;if(n!==t.width||i!==t.height){var a=ko({},{width:n,height:i},r);Mo(t,a,{x:0,y:0},{x:0,y:0},{width:Math.min(t.width,n),height:Math.min(t.height,i)},r),t.width=n,t.height=i,t.data=a.data}}function Mo(t,e,r,n,i,a){if(0===i.width||0===i.height)return e;if(i.width>t.width||i.height>t.height||r.x>t.width-i.width||r.y>t.height-i.height)throw new RangeError("out of range source coordinates for image copy");if(i.width>e.width||i.height>e.height||n.x>e.width-i.width||n.y>e.height-i.height)throw new RangeError("out of range destination coordinates for image copy");for(var o=t.data,s=e.data,l=0;l<i.height;l++)for(var c=((r.y+l)*t.width+r.x)*a,u=((n.y+l)*e.width+n.x)*a,f=0;f<i.width*a;f++)s[u+f]=o[c+f];return e}Nn("HeatmapBucket",To,{omit:["layers"]});var So=function(t,e){ko(this,t,1,e)};So.prototype.resize=function(t){Ao(this,t,1)},So.prototype.clone=function(){return new So({width:this.width,height:this.height},new Uint8Array(this.data))},So.copy=function(t,e,r,n,i){Mo(t,e,r,n,i,1)};var Eo=function(t,e){ko(this,t,4,e)};Eo.prototype.resize=function(t){Ao(this,t,4)},Eo.prototype.replace=function(t,e){e?this.data.set(t):t instanceof Uint8ClampedArray?this.data=new Uint8Array(t.buffer):this.data=t},Eo.prototype.clone=function(){return new Eo({width:this.width,height:this.height},new Uint8Array(this.data))},Eo.copy=function(t,e,r,n,i){Mo(t,e,r,n,i,4)},Nn("AlphaImage",So),Nn("RGBAImage",Eo);var Lo={paint:new Si({"heatmap-radius":new Ti(Lt.paint_heatmap["heatmap-radius"]),"heatmap-weight":new Ti(Lt.paint_heatmap["heatmap-weight"]),"heatmap-intensity":new wi(Lt.paint_heatmap["heatmap-intensity"]),"heatmap-color":new Mi(Lt.paint_heatmap["heatmap-color"]),"heatmap-opacity":new wi(Lt.paint_heatmap["heatmap-opacity"])})};function Co(t,e){for(var r=new Uint8Array(1024),n={},i=0,a=0;i<256;i++,a+=4){n[e]=i/255;var o=t.evaluate(n);r[a+0]=Math.floor(255*o.r/o.a),r[a+1]=Math.floor(255*o.g/o.a),r[a+2]=Math.floor(255*o.b/o.a),r[a+3]=Math.floor(255*o.a)}return new Eo({width:256,height:1},r)}var Po=function(t){function e(e){t.call(this,e,Lo),this._updateColorRamp()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.createBucket=function(t){return new To(t)},e.prototype._handleSpecialPaintPropertyUpdate=function(t){"heatmap-color"===t&&this._updateColorRamp()},e.prototype._updateColorRamp=function(){var t=this._transitionablePaint._values["heatmap-color"].value.expression;this.colorRamp=Co(t,"heatmapDensity"),this.colorRampTexture=null},e.prototype.resize=function(){this.heatmapFbo&&(this.heatmapFbo.destroy(),this.heatmapFbo=null)},e.prototype.queryRadius=function(){return 0},e.prototype.queryIntersectsFeature=function(){return!1},e.prototype.hasOffscreenPass=function(){return 0!==this.paint.get("heatmap-opacity")&&"none"!==this.visibility},e}(Ei),Io={paint:new Si({"hillshade-illumination-direction":new wi(Lt.paint_hillshade["hillshade-illumination-direction"]),"hillshade-illumination-anchor":new wi(Lt.paint_hillshade["hillshade-illumination-anchor"]),"hillshade-exaggeration":new wi(Lt.paint_hillshade["hillshade-exaggeration"]),"hillshade-shadow-color":new wi(Lt.paint_hillshade["hillshade-shadow-color"]),"hillshade-highlight-color":new wi(Lt.paint_hillshade["hillshade-highlight-color"]),"hillshade-accent-color":new wi(Lt.paint_hillshade["hillshade-accent-color"])})},Oo=function(t){function e(e){t.call(this,e,Io)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.hasOffscreenPass=function(){return 0!==this.paint.get("hillshade-exaggeration")&&"none"!==this.visibility},e}(Ei),zo=Ii([{name:"a_pos",components:2,type:"Int16"}],4).members,Do=Fo,Ro=Fo;function Fo(t,e,r){r=r||2;var n,i,a,o,s,l,c,u=e&&e.length,f=u?e[0]*r:t.length,h=Bo(t,0,f,r,!0),p=[];if(!h||h.next===h.prev)return p;if(u&&(h=function(t,e,r,n){var i,a,o,s,l,c=[];for(i=0,a=e.length;i<a;i++)o=e[i]*n,s=i<a-1?e[i+1]*n:t.length,(l=Bo(t,o,s,n,!1))===l.next&&(l.steiner=!0),c.push(Zo(l));for(c.sort(Go),i=0;i<c.length;i++)Yo(c[i],r),r=No(r,r.next);return r}(t,e,h,r)),t.length>80*r){n=a=t[0],i=o=t[1];for(var d=r;d<f;d+=r)(s=t[d])<n&&(n=s),(l=t[d+1])<i&&(i=l),s>a&&(a=s),l>o&&(o=l);c=0!==(c=Math.max(a-n,o-i))?1/c:0}return jo(h,p,r,n,i,c),p}function Bo(t,e,r,n,i){var a,o;if(i===ls(t,e,r,n)>0)for(a=e;a<r;a+=n)o=as(a,t[a],t[a+1],o);else for(a=r-n;a>=e;a-=n)o=as(a,t[a],t[a+1],o);return o&&$o(o,o.next)&&(os(o),o=o.next),o}function No(t,e){if(!t)return t;e||(e=t);var r,n=t;do{if(r=!1,n.steiner||!$o(n,n.next)&&0!==Qo(n.prev,n,n.next))n=n.next;else{if(os(n),(n=e=n.prev)===n.next)break;r=!0}}while(r||n!==e);return e}function jo(t,e,r,n,i,a,o){if(t){!o&&a&&function(t,e,r,n){var i=t;do{null===i.z&&(i.z=Xo(i.x,i.y,e,r,n)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next}while(i!==t);i.prevZ.nextZ=null,i.prevZ=null,function(t){var e,r,n,i,a,o,s,l,c=1;do{for(r=t,t=null,a=null,o=0;r;){for(o++,n=r,s=0,e=0;e<c&&(s++,n=n.nextZ);e++);for(l=c;s>0||l>0&&n;)0!==s&&(0===l||!n||r.z<=n.z)?(i=r,r=r.nextZ,s--):(i=n,n=n.nextZ,l--),a?a.nextZ=i:t=i,i.prevZ=a,a=i;r=n}a.nextZ=null,c*=2}while(o>1)}(i)}(t,n,i,a);for(var s,l,c=t;t.prev!==t.next;)if(s=t.prev,l=t.next,a?Vo(t,n,i,a):Uo(t))e.push(s.i/r),e.push(t.i/r),e.push(l.i/r),os(t),t=l.next,c=l.next;else if((t=l)===c){o?1===o?jo(t=Ho(No(t),e,r),e,r,n,i,a,2):2===o&&qo(t,e,r,n,i,a):jo(No(t),e,r,n,i,a,1);break}}}function Uo(t){var e=t.prev,r=t,n=t.next;if(Qo(e,r,n)>=0)return!1;for(var i=t.next.next;i!==t.prev;){if(Jo(e.x,e.y,r.x,r.y,n.x,n.y,i.x,i.y)&&Qo(i.prev,i,i.next)>=0)return!1;i=i.next}return!0}function Vo(t,e,r,n){var i=t.prev,a=t,o=t.next;if(Qo(i,a,o)>=0)return!1;for(var s=i.x<a.x?i.x<o.x?i.x:o.x:a.x<o.x?a.x:o.x,l=i.y<a.y?i.y<o.y?i.y:o.y:a.y<o.y?a.y:o.y,c=i.x>a.x?i.x>o.x?i.x:o.x:a.x>o.x?a.x:o.x,u=i.y>a.y?i.y>o.y?i.y:o.y:a.y>o.y?a.y:o.y,f=Xo(s,l,e,r,n),h=Xo(c,u,e,r,n),p=t.prevZ,d=t.nextZ;p&&p.z>=f&&d&&d.z<=h;){if(p!==t.prev&&p!==t.next&&Jo(i.x,i.y,a.x,a.y,o.x,o.y,p.x,p.y)&&Qo(p.prev,p,p.next)>=0)return!1;if(p=p.prevZ,d!==t.prev&&d!==t.next&&Jo(i.x,i.y,a.x,a.y,o.x,o.y,d.x,d.y)&&Qo(d.prev,d,d.next)>=0)return!1;d=d.nextZ}for(;p&&p.z>=f;){if(p!==t.prev&&p!==t.next&&Jo(i.x,i.y,a.x,a.y,o.x,o.y,p.x,p.y)&&Qo(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;d&&d.z<=h;){if(d!==t.prev&&d!==t.next&&Jo(i.x,i.y,a.x,a.y,o.x,o.y,d.x,d.y)&&Qo(d.prev,d,d.next)>=0)return!1;d=d.nextZ}return!0}function Ho(t,e,r){var n=t;do{var i=n.prev,a=n.next.next;!$o(i,a)&&ts(i,n,n.next,a)&&ns(i,a)&&ns(a,i)&&(e.push(i.i/r),e.push(n.i/r),e.push(a.i/r),os(n),os(n.next),n=t=a),n=n.next}while(n!==t);return No(n)}function qo(t,e,r,n,i,a){var o=t;do{for(var s=o.next.next;s!==o.prev;){if(o.i!==s.i&&Ko(o,s)){var l=is(o,s);return o=No(o,o.next),l=No(l,l.next),jo(o,e,r,n,i,a),void jo(l,e,r,n,i,a)}s=s.next}o=o.next}while(o!==t)}function Go(t,e){return t.x-e.x}function Yo(t,e){if(e=function(t,e){var r,n=e,i=t.x,a=t.y,o=-1/0;do{if(a<=n.y&&a>=n.next.y&&n.next.y!==n.y){var s=n.x+(a-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(s<=i&&s>o){if(o=s,s===i){if(a===n.y)return n;if(a===n.next.y)return n.next}r=n.x<n.next.x?n:n.next}}n=n.next}while(n!==e);if(!r)return null;if(i===o)return r;var l,c=r,u=r.x,f=r.y,h=1/0;n=r;do{i>=n.x&&n.x>=u&&i!==n.x&&Jo(a<f?i:o,a,u,f,a<f?o:i,a,n.x,n.y)&&(l=Math.abs(a-n.y)/(i-n.x),ns(n,t)&&(l<h||l===h&&(n.x>r.x||n.x===r.x&&Wo(r,n)))&&(r=n,h=l)),n=n.next}while(n!==c);return r}(t,e)){var r=is(e,t);No(e,e.next),No(r,r.next)}}function Wo(t,e){return Qo(t.prev,t,e.prev)<0&&Qo(e.next,t,t.next)<0}function Xo(t,e,r,n,i){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-r)*i)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-n)*i)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function Zo(t){var e=t,r=t;do{(e.x<r.x||e.x===r.x&&e.y<r.y)&&(r=e),e=e.next}while(e!==t);return r}function Jo(t,e,r,n,i,a,o,s){return(i-o)*(e-s)-(t-o)*(a-s)>=0&&(t-o)*(n-s)-(r-o)*(e-s)>=0&&(r-o)*(a-s)-(i-o)*(n-s)>=0}function Ko(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var r=t;do{if(r.i!==t.i&&r.next.i!==t.i&&r.i!==e.i&&r.next.i!==e.i&&ts(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(ns(t,e)&&ns(e,t)&&function(t,e){var r=t,n=!1,i=(t.x+e.x)/2,a=(t.y+e.y)/2;do{r.y>a!=r.next.y>a&&r.next.y!==r.y&&i<(r.next.x-r.x)*(a-r.y)/(r.next.y-r.y)+r.x&&(n=!n),r=r.next}while(r!==t);return n}(t,e)&&(Qo(t.prev,t,e.prev)||Qo(t,e.prev,e))||$o(t,e)&&Qo(t.prev,t,t.next)>0&&Qo(e.prev,e,e.next)>0)}function Qo(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function $o(t,e){return t.x===e.x&&t.y===e.y}function ts(t,e,r,n){var i=rs(Qo(t,e,r)),a=rs(Qo(t,e,n)),o=rs(Qo(r,n,t)),s=rs(Qo(r,n,e));return i!==a&&o!==s||(!(0!==i||!es(t,r,e))||(!(0!==a||!es(t,n,e))||(!(0!==o||!es(r,t,n))||!(0!==s||!es(r,e,n)))))}function es(t,e,r){return e.x<=Math.max(t.x,r.x)&&e.x>=Math.min(t.x,r.x)&&e.y<=Math.max(t.y,r.y)&&e.y>=Math.min(t.y,r.y)}function rs(t){return t>0?1:t<0?-1:0}function ns(t,e){return Qo(t.prev,t,t.next)<0?Qo(t,e,t.next)>=0&&Qo(t,t.prev,e)>=0:Qo(t,e,t.prev)<0||Qo(t,t.next,e)<0}function is(t,e){var r=new ss(t.i,t.x,t.y),n=new ss(e.i,e.x,e.y),i=t.next,a=e.prev;return t.next=e,e.prev=t,r.next=i,i.prev=r,n.next=r,r.prev=n,a.next=n,n.prev=a,n}function as(t,e,r,n){var i=new ss(t,e,r);return n?(i.next=n.next,i.prev=n,n.next.prev=i,n.next=i):(i.prev=i,i.next=i),i}function os(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function ss(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function ls(t,e,r,n){for(var i=0,a=e,o=r-n;a<r;a+=n)i+=(t[o]-t[a])*(t[a+1]+t[o+1]),o=a;return i}function cs(t,e,r,n,i){!function t(e,r,n,i,a){for(;i>n;){if(i-n>600){var o=i-n+1,s=r-n+1,l=Math.log(o),c=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*c*(o-c)/o)*(s-o/2<0?-1:1),f=Math.max(n,Math.floor(r-s*c/o+u)),h=Math.min(i,Math.floor(r+(o-s)*c/o+u));t(e,r,f,h,a)}var p=e[r],d=n,m=i;for(us(e,n,r),a(e[i],p)>0&&us(e,n,i);d<m;){for(us(e,d,m),d++,m--;a(e[d],p)<0;)d++;for(;a(e[m],p)>0;)m--}0===a(e[n],p)?us(e,n,m):(m++,us(e,m,i)),m<=r&&(n=m+1),r<=m&&(i=m-1)}}(t,e,r||0,n||t.length-1,i||fs)}function us(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function fs(t,e){return t<e?-1:t>e?1:0}function hs(t,e){var r=t.length;if(r<=1)return[t];for(var n,i,a=[],o=0;o<r;o++){var s=T(t[o]);0!==s&&(t[o].area=Math.abs(s),void 0===i&&(i=s<0),i===s<0?(n&&a.push(n),n=[t[o]]):n.push(t[o]))}if(n&&a.push(n),e>1)for(var l=0;l<a.length;l++)a[l].length<=e||(cs(a[l],e,1,a[l].length-1,ps),a[l]=a[l].slice(0,e));return a}function ps(t,e){return e.area-t.area}function ds(t,e,r){for(var n=r.patternDependencies,i=!1,a=0,o=e;a<o.length;a+=1){var s=o[a].paint.get(t+"-pattern");s.isConstant()||(i=!0);var l=s.constantOr(null);l&&(i=!0,n[l.to]=!0,n[l.from]=!0)}return i}function ms(t,e,r,n,i){for(var a=i.patternDependencies,o=0,s=e;o<s.length;o+=1){var l=s[o],c=l.paint.get(t+"-pattern").value;if("constant"!==c.kind){var u=c.evaluate({zoom:n-1},r,{},i.availableImages),f=c.evaluate({zoom:n},r,{},i.availableImages),h=c.evaluate({zoom:n+1},r,{},i.availableImages);u=u&&u.name?u.name:u,f=f&&f.name?f.name:f,h=h&&h.name?h.name:h,a[u]=!0,a[f]=!0,a[h]=!0,r.patterns[l.id]={min:u,mid:f,max:h}}}return r}Fo.deviation=function(t,e,r,n){var i=e&&e.length,a=i?e[0]*r:t.length,o=Math.abs(ls(t,0,a,r));if(i)for(var s=0,l=e.length;s<l;s++){var c=e[s]*r,u=s<l-1?e[s+1]*r:t.length;o-=Math.abs(ls(t,c,u,r))}var f=0;for(s=0;s<n.length;s+=3){var h=n[s]*r,p=n[s+1]*r,d=n[s+2]*r;f+=Math.abs((t[h]-t[d])*(t[p+1]-t[h+1])-(t[h]-t[p])*(t[d+1]-t[h+1]))}return 0===o&&0===f?0:Math.abs((f-o)/o)},Fo.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},n=0,i=0;i<t.length;i++){for(var a=0;a<t[i].length;a++)for(var o=0;o<e;o++)r.vertices.push(t[i][a][o]);i>0&&(n+=t[i-1].length,r.holes.push(n))}return r},Do.default=Ro;var gs=function(t){this.zoom=t.zoom,this.overscaling=t.overscaling,this.layers=t.layers,this.layerIds=this.layers.map((function(t){return t.id})),this.index=t.index,this.hasPattern=!1,this.patternFeatures=[],this.layoutVertexArray=new zi,this.indexArray=new Yi,this.indexArray2=new Qi,this.programConfigurations=new Ua(zo,t.layers,t.zoom),this.segments=new pa,this.segments2=new pa,this.stateDependentLayerIds=this.layers.filter((function(t){return t.isStateDependent()})).map((function(t){return t.id}))};gs.prototype.populate=function(t,e,r){this.hasPattern=ds("fill",this.layers,e);for(var n=this.layers[0].layout.get("fill-sort-key"),i=[],a=0,o=t;a<o.length;a+=1){var s=o[a],l=s.feature,c=s.id,u=s.index,f=s.sourceLayerIndex,h=this.layers[0]._featureFilter.needGeometry,p={type:l.type,id:c,properties:l.properties,geometry:h?Ya(l):[]};if(this.layers[0]._featureFilter.filter(new pi(this.zoom),p,r)){h||(p.geometry=Ya(l));var d=n?n.evaluate(p,{},r,e.availableImages):void 0,m={id:c,properties:l.properties,type:l.type,sourceLayerIndex:f,index:u,geometry:p.geometry,patterns:{},sortKey:d};i.push(m)}}n&&i.sort((function(t,e){return t.sortKey-e.sortKey}));for(var g=0,v=i;g<v.length;g+=1){var y=v[g],x=y,b=x.geometry,_=x.index,w=x.sourceLayerIndex;if(this.hasPattern){var T=ms("fill",this.layers,y,this.zoom,e);this.patternFeatures.push(T)}else this.addFeature(y,b,_,r,{});var k=t[_].feature;e.featureIndex.insert(k,b,_,w,this.index)}},gs.prototype.update=function(t,e,r){this.stateDependentLayers.length&&this.programConfigurations.updatePaintArrays(t,e,this.stateDependentLayers,r)},gs.prototype.addFeatures=function(t,e,r){for(var n=0,i=this.patternFeatures;n<i.length;n+=1){var a=i[n];this.addFeature(a,a.geometry,a.index,e,r)}},gs.prototype.isEmpty=function(){return 0===this.layoutVertexArray.length},gs.prototype.uploadPending=function(){return!this.uploaded||this.programConfigurations.needsUpload},gs.prototype.upload=function(t){this.uploaded||(this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,zo),this.indexBuffer=t.createIndexBuffer(this.indexArray),this.indexBuffer2=t.createIndexBuffer(this.indexArray2)),this.programConfigurations.upload(t),this.uploaded=!0},gs.prototype.destroy=function(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.indexBuffer2.destroy(),this.programConfigurations.destroy(),this.segments.destroy(),this.segments2.destroy())},gs.prototype.addFeature=function(t,e,r,n,i){for(var a=0,o=hs(e,500);a<o.length;a+=1){for(var s=o[a],l=0,c=0,u=s;c<u.length;c+=1){l+=u[c].length}for(var f=this.segments.prepareSegment(l,this.layoutVertexArray,this.indexArray),h=f.vertexLength,p=[],d=[],m=0,g=s;m<g.length;m+=1){var v=g[m];if(0!==v.length){v!==s[0]&&d.push(p.length/2);var y=this.segments2.prepareSegment(v.length,this.layoutVertexArray,this.indexArray2),x=y.vertexLength;this.layoutVertexArray.emplaceBack(v[0].x,v[0].y),this.indexArray2.emplaceBack(x+v.length-1,x),p.push(v[0].x),p.push(v[0].y);for(var b=1;b<v.length;b++)this.layoutVertexArray.emplaceBack(v[b].x,v[b].y),this.indexArray2.emplaceBack(x+b-1,x+b),p.push(v[b].x),p.push(v[b].y);y.vertexLength+=v.length,y.primitiveLength+=v.length}}for(var _=Do(p,d),w=0;w<_.length;w+=3)this.indexArray.emplaceBack(h+_[w],h+_[w+1],h+_[w+2]);f.vertexLength+=l,f.primitiveLength+=_.length/3}this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length,t,r,i,n)},Nn("FillBucket",gs,{omit:["layers","patternFeatures"]});var vs=new Si({"fill-sort-key":new Ti(Lt.layout_fill["fill-sort-key"])}),ys={paint:new Si({"fill-antialias":new wi(Lt.paint_fill["fill-antialias"]),"fill-opacity":new Ti(Lt.paint_fill["fill-opacity"]),"fill-color":new Ti(Lt.paint_fill["fill-color"]),"fill-outline-color":new Ti(Lt.paint_fill["fill-outline-color"]),"fill-translate":new wi(Lt.paint_fill["fill-translate"]),"fill-translate-anchor":new wi(Lt.paint_fill["fill-translate-anchor"]),"fill-pattern":new ki(Lt.paint_fill["fill-pattern"])}),layout:vs},xs=function(t){function e(e){t.call(this,e,ys)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.recalculate=function(e,r){t.prototype.recalculate.call(this,e,r);var n=this.paint._values["fill-outline-color"];"constant"===n.value.kind&&void 0===n.value.value&&(this.paint._values["fill-outline-color"]=this.paint._values["fill-color"])},e.prototype.createBucket=function(t){return new gs(t)},e.prototype.queryRadius=function(){return so(this.paint.get("fill-translate"))},e.prototype.queryIntersectsFeature=function(t,e,r,n,i,a,o){return Ka(lo(t,this.paint.get("fill-translate"),this.paint.get("fill-translate-anchor"),a.angle,o),n)},e.prototype.isTileClipped=function(){return!0},e}(Ei),bs=Ii([{name:"a_pos",components:2,type:"Int16"},{name:"a_normal_ed",components:4,type:"Int16"}],4).members,_s=ws;function ws(t,e,r,n,i){this.properties={},this.extent=r,this.type=0,this._pbf=t,this._geometry=-1,this._keys=n,this._values=i,t.readFields(Ts,this,e)}function Ts(t,e,r){1==t?e.id=r.readVarint():2==t?function(t,e){var r=t.readVarint()+t.pos;for(;t.pos<r;){var n=e._keys[t.readVarint()],i=e._values[t.readVarint()];e.properties[n]=i}}(r,e):3==t?e.type=r.readVarint():4==t&&(e._geometry=r.pos)}function ks(t){for(var e,r,n=0,i=0,a=t.length,o=a-1;i<a;o=i++)e=t[i],n+=((r=t[o]).x-e.x)*(e.y+r.y);return n}ws.types=["Unknown","Point","LineString","Polygon"],ws.prototype.loadGeometry=function(){var t=this._pbf;t.pos=this._geometry;for(var e,r=t.readVarint()+t.pos,n=1,a=0,o=0,s=0,l=[];t.pos<r;){if(a<=0){var c=t.readVarint();n=7&c,a=c>>3}if(a--,1===n||2===n)o+=t.readSVarint(),s+=t.readSVarint(),1===n&&(e&&l.push(e),e=[]),e.push(new i(o,s));else{if(7!==n)throw new Error("unknown command "+n);e&&e.push(e[0].clone())}}return e&&l.push(e),l},ws.prototype.bbox=function(){var t=this._pbf;t.pos=this._geometry;for(var e=t.readVarint()+t.pos,r=1,n=0,i=0,a=0,o=1/0,s=-1/0,l=1/0,c=-1/0;t.pos<e;){if(n<=0){var u=t.readVarint();r=7&u,n=u>>3}if(n--,1===r||2===r)(i+=t.readSVarint())<o&&(o=i),i>s&&(s=i),(a+=t.readSVarint())<l&&(l=a),a>c&&(c=a);else if(7!==r)throw new Error("unknown command "+r)}return[o,l,s,c]},ws.prototype.toGeoJSON=function(t,e,r){var n,i,a=this.extent*Math.pow(2,r),o=this.extent*t,s=this.extent*e,l=this.loadGeometry(),c=ws.types[this.type];function u(t){for(var e=0;e<t.length;e++){var r=t[e],n=180-360*(r.y+s)/a;t[e]=[360*(r.x+o)/a-180,360/Math.PI*Math.atan(Math.exp(n*Math.PI/180))-90]}}switch(this.type){case 1:var f=[];for(n=0;n<l.length;n++)f[n]=l[n][0];u(l=f);break;case 2:for(n=0;n<l.length;n++)u(l[n]);break;case 3:for(l=function(t){var e=t.length;if(e<=1)return[t];for(var r,n,i=[],a=0;a<e;a++){var o=ks(t[a]);0!==o&&(void 0===n&&(n=o<0),n===o<0?(r&&i.push(r),r=[t[a]]):r.push(t[a]))}r&&i.push(r);return i}(l),n=0;n<l.length;n++)for(i=0;i<l[n].length;i++)u(l[n][i])}1===l.length?l=l[0]:c="Multi"+c;var h={type:"Feature",geometry:{type:c,coordinates:l},properties:this.properties};return"id"in this&&(h.id=this.id),h};var As=Ms;function Ms(t,e){this.version=1,this.name=null,this.extent=4096,this.length=0,this._pbf=t,this._keys=[],this._values=[],this._features=[],t.readFields(Ss,this,e),this.length=this._features.length}function Ss(t,e,r){15===t?e.version=r.readVarint():1===t?e.name=r.readString():5===t?e.extent=r.readVarint():2===t?e._features.push(r.pos):3===t?e._keys.push(r.readString()):4===t&&e._values.push(function(t){var e=null,r=t.readVarint()+t.pos;for(;t.pos<r;){var n=t.readVarint()>>3;e=1===n?t.readString():2===n?t.readFloat():3===n?t.readDouble():4===n?t.readVarint64():5===n?t.readVarint():6===n?t.readSVarint():7===n?t.readBoolean():null}return e}(r))}function Es(t,e,r){if(3===t){var n=new As(r,r.readVarint()+r.pos);n.length&&(e[n.name]=n)}}Ms.prototype.feature=function(t){if(t<0||t>=this._features.length)throw new Error("feature index out of bounds");this._pbf.pos=this._features[t];var e=this._pbf.readVarint()+this._pbf.pos;return new _s(this._pbf,e,this.extent,this._keys,this._values)};var Ls={VectorTile:function(t,e){this.layers=t.readFields(Es,{},e)},VectorTileFeature:_s,VectorTileLayer:As},Cs=Ls.VectorTileFeature.types,Ps=Math.pow(2,13);function Is(t,e,r,n,i,a,o,s){t.emplaceBack(e,r,2*Math.floor(n*Ps)+o,i*Ps*2,a*Ps*2,Math.round(s))}var Os=function(t){this.zoom=t.zoom,this.overscaling=t.overscaling,this.layers=t.layers,this.layerIds=this.layers.map((function(t){return t.id})),this.index=t.index,this.hasPattern=!1,this.layoutVertexArray=new Ri,this.indexArray=new Yi,this.programConfigurations=new Ua(bs,t.layers,t.zoom),this.segments=new pa,this.stateDependentLayerIds=this.layers.filter((function(t){return t.isStateDependent()})).map((function(t){return t.id}))};function zs(t,e){return t.x===e.x&&(t.x<0||t.x>8192)||t.y===e.y&&(t.y<0||t.y>8192)}function Ds(t){return t.every((function(t){return t.x<0}))||t.every((function(t){return t.x>8192}))||t.every((function(t){return t.y<0}))||t.every((function(t){return t.y>8192}))}Os.prototype.populate=function(t,e,r){this.features=[],this.hasPattern=ds("fill-extrusion",this.layers,e);for(var n=0,i=t;n<i.length;n+=1){var a=i[n],o=a.feature,s=a.id,l=a.index,c=a.sourceLayerIndex,u=this.layers[0]._featureFilter.needGeometry,f={type:o.type,id:s,properties:o.properties,geometry:u?Ya(o):[]};if(this.layers[0]._featureFilter.filter(new pi(this.zoom),f,r)){var h={id:s,sourceLayerIndex:c,index:l,geometry:u?f.geometry:Ya(o),properties:o.properties,type:o.type,patterns:{}};void 0!==o.id&&(h.id=o.id),this.hasPattern?this.features.push(ms("fill-extrusion",this.layers,h,this.zoom,e)):this.addFeature(h,h.geometry,l,r,{}),e.featureIndex.insert(o,h.geometry,l,c,this.index,!0)}}},Os.prototype.addFeatures=function(t,e,r){for(var n=0,i=this.features;n<i.length;n+=1){var a=i[n],o=a.geometry;this.addFeature(a,o,a.index,e,r)}},Os.prototype.update=function(t,e,r){this.stateDependentLayers.length&&this.programConfigurations.updatePaintArrays(t,e,this.stateDependentLayers,r)},Os.prototype.isEmpty=function(){return 0===this.layoutVertexArray.length},Os.prototype.uploadPending=function(){return!this.uploaded||this.programConfigurations.needsUpload},Os.prototype.upload=function(t){this.uploaded||(this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,bs),this.indexBuffer=t.createIndexBuffer(this.indexArray)),this.programConfigurations.upload(t),this.uploaded=!0},Os.prototype.destroy=function(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.programConfigurations.destroy(),this.segments.destroy())},Os.prototype.addFeature=function(t,e,r,n,i){for(var a=0,o=hs(e,500);a<o.length;a+=1){for(var s=o[a],l=0,c=0,u=s;c<u.length;c+=1){l+=u[c].length}for(var f=this.segments.prepareSegment(4,this.layoutVertexArray,this.indexArray),h=0,p=s;h<p.length;h+=1){var d=p[h];if(0!==d.length&&!Ds(d))for(var m=0,g=0;g<d.length;g++){var v=d[g];if(g>=1){var y=d[g-1];if(!zs(v,y)){f.vertexLength+4>pa.MAX_VERTEX_ARRAY_LENGTH&&(f=this.segments.prepareSegment(4,this.layoutVertexArray,this.indexArray));var x=v.sub(y)._perp()._unit(),b=y.dist(v);m+b>32768&&(m=0),Is(this.layoutVertexArray,v.x,v.y,x.x,x.y,0,0,m),Is(this.layoutVertexArray,v.x,v.y,x.x,x.y,0,1,m),m+=b,Is(this.layoutVertexArray,y.x,y.y,x.x,x.y,0,0,m),Is(this.layoutVertexArray,y.x,y.y,x.x,x.y,0,1,m);var _=f.vertexLength;this.indexArray.emplaceBack(_,_+2,_+1),this.indexArray.emplaceBack(_+1,_+2,_+3),f.vertexLength+=4,f.primitiveLength+=2}}}}if(f.vertexLength+l>pa.MAX_VERTEX_ARRAY_LENGTH&&(f=this.segments.prepareSegment(l,this.layoutVertexArray,this.indexArray)),"Polygon"===Cs[t.type]){for(var w=[],T=[],k=f.vertexLength,A=0,M=s;A<M.length;A+=1){var S=M[A];if(0!==S.length){S!==s[0]&&T.push(w.length/2);for(var E=0;E<S.length;E++){var L=S[E];Is(this.layoutVertexArray,L.x,L.y,0,0,1,1,0),w.push(L.x),w.push(L.y)}}}for(var C=Do(w,T),P=0;P<C.length;P+=3)this.indexArray.emplaceBack(k+C[P],k+C[P+2],k+C[P+1]);f.primitiveLength+=C.length/3,f.vertexLength+=l}}this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length,t,r,i,n)},Nn("FillExtrusionBucket",Os,{omit:["layers","features"]});var Rs={paint:new Si({"fill-extrusion-opacity":new wi(Lt["paint_fill-extrusion"]["fill-extrusion-opacity"]),"fill-extrusion-color":new Ti(Lt["paint_fill-extrusion"]["fill-extrusion-color"]),"fill-extrusion-translate":new wi(Lt["paint_fill-extrusion"]["fill-extrusion-translate"]),"fill-extrusion-translate-anchor":new wi(Lt["paint_fill-extrusion"]["fill-extrusion-translate-anchor"]),"fill-extrusion-pattern":new ki(Lt["paint_fill-extrusion"]["fill-extrusion-pattern"]),"fill-extrusion-height":new Ti(Lt["paint_fill-extrusion"]["fill-extrusion-height"]),"fill-extrusion-base":new Ti(Lt["paint_fill-extrusion"]["fill-extrusion-base"]),"fill-extrusion-vertical-gradient":new wi(Lt["paint_fill-extrusion"]["fill-extrusion-vertical-gradient"])})},Fs=function(t){function e(e){t.call(this,e,Rs)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.createBucket=function(t){return new Os(t)},e.prototype.queryRadius=function(){return so(this.paint.get("fill-extrusion-translate"))},e.prototype.is3D=function(){return!0},e.prototype.queryIntersectsFeature=function(t,e,r,n,a,o,s,l){var c=lo(t,this.paint.get("fill-extrusion-translate"),this.paint.get("fill-extrusion-translate-anchor"),o.angle,s),u=this.paint.get("fill-extrusion-height").evaluate(e,r),f=this.paint.get("fill-extrusion-base").evaluate(e,r),h=function(t,e,r,n){for(var a=[],o=0,s=t;o<s.length;o+=1){var l=s[o],c=[l.x,l.y,n,1];xo(c,c,e),a.push(new i(c[0]/c[3],c[1]/c[3]))}return a}(c,l,0,0),p=function(t,e,r,n){for(var a=[],o=[],s=n[8]*e,l=n[9]*e,c=n[10]*e,u=n[11]*e,f=n[8]*r,h=n[9]*r,p=n[10]*r,d=n[11]*r,m=0,g=t;m<g.length;m+=1){for(var v=g[m],y=[],x=[],b=0,_=v;b<_.length;b+=1){var w=_[b],T=w.x,k=w.y,A=n[0]*T+n[4]*k+n[12],M=n[1]*T+n[5]*k+n[13],S=n[2]*T+n[6]*k+n[14],E=n[3]*T+n[7]*k+n[15],L=S+c,C=E+u,P=A+f,I=M+h,O=S+p,z=E+d,D=new i((A+s)/C,(M+l)/C);D.z=L/C,y.push(D);var R=new i(P/z,I/z);R.z=O/z,x.push(R)}a.push(y),o.push(x)}return[a,o]}(n,f,u,l);return function(t,e,r){var n=1/0;Ka(r,e)&&(n=Ns(r,e[0]));for(var i=0;i<e.length;i++)for(var a=e[i],o=t[i],s=0;s<a.length-1;s++){var l=a[s],c=a[s+1],u=o[s],f=o[s+1],h=[l,c,f,u,l];Za(r,h)&&(n=Math.min(n,Ns(r,h)))}return n!==1/0&&n}(p[0],p[1],h)},e}(Ei);function Bs(t,e){return t.x*e.x+t.y*e.y}function Ns(t,e){if(1===t.length){for(var r,n=0,i=e[n++];!r||i.equals(r);)if(!(r=e[n++]))return 1/0;for(;n<e.length;n++){var a=e[n],o=t[0],s=r.sub(i),l=a.sub(i),c=o.sub(i),u=Bs(s,s),f=Bs(s,l),h=Bs(l,l),p=Bs(c,s),d=Bs(c,l),m=u*h-f*f,g=(h*p-f*d)/m,v=(u*d-f*p)/m,y=1-g-v,x=i.z*y+r.z*g+a.z*v;if(isFinite(x))return x}return 1/0}for(var b=1/0,_=0,w=e;_<w.length;_+=1){var T=w[_];b=Math.min(b,T.z)}return b}var js=Ii([{name:"a_pos_normal",components:2,type:"Int16"},{name:"a_data",components:4,type:"Uint8"}],4).members,Us=Ls.VectorTileFeature.types,Vs=Math.cos(Math.PI/180*37.5),Hs=Math.pow(2,14)/.5,qs=function(t){this.zoom=t.zoom,this.overscaling=t.overscaling,this.layers=t.layers,this.layerIds=this.layers.map((function(t){return t.id})),this.index=t.index,this.hasPattern=!1,this.patternFeatures=[],this.layoutVertexArray=new Fi,this.indexArray=new Yi,this.programConfigurations=new Ua(js,t.layers,t.zoom),this.segments=new pa,this.stateDependentLayerIds=this.layers.filter((function(t){return t.isStateDependent()})).map((function(t){return t.id}))};qs.prototype.populate=function(t,e,r){this.hasPattern=ds("line",this.layers,e);for(var n=this.layers[0].layout.get("line-sort-key"),i=[],a=0,o=t;a<o.length;a+=1){var s=o[a],l=s.feature,c=s.id,u=s.index,f=s.sourceLayerIndex,h=this.layers[0]._featureFilter.needGeometry,p={type:l.type,id:c,properties:l.properties,geometry:h?Ya(l):[]};if(this.layers[0]._featureFilter.filter(new pi(this.zoom),p,r)){h||(p.geometry=Ya(l));var d=n?n.evaluate(p,{},r):void 0,m={id:c,properties:l.properties,type:l.type,sourceLayerIndex:f,index:u,geometry:p.geometry,patterns:{},sortKey:d};i.push(m)}}n&&i.sort((function(t,e){return t.sortKey-e.sortKey}));for(var g=0,v=i;g<v.length;g+=1){var y=v[g],x=y,b=x.geometry,_=x.index,w=x.sourceLayerIndex;if(this.hasPattern){var T=ms("line",this.layers,y,this.zoom,e);this.patternFeatures.push(T)}else this.addFeature(y,b,_,r,{});var k=t[_].feature;e.featureIndex.insert(k,b,_,w,this.index)}},qs.prototype.update=function(t,e,r){this.stateDependentLayers.length&&this.programConfigurations.updatePaintArrays(t,e,this.stateDependentLayers,r)},qs.prototype.addFeatures=function(t,e,r){for(var n=0,i=this.patternFeatures;n<i.length;n+=1){var a=i[n];this.addFeature(a,a.geometry,a.index,e,r)}},qs.prototype.isEmpty=function(){return 0===this.layoutVertexArray.length},qs.prototype.uploadPending=function(){return!this.uploaded||this.programConfigurations.needsUpload},qs.prototype.upload=function(t){this.uploaded||(this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,js),this.indexBuffer=t.createIndexBuffer(this.indexArray)),this.programConfigurations.upload(t),this.uploaded=!0},qs.prototype.destroy=function(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.programConfigurations.destroy(),this.segments.destroy())},qs.prototype.addFeature=function(t,e,r,n,i){for(var a=this.layers[0].layout,o=a.get("line-join").evaluate(t,{}),s=a.get("line-cap"),l=a.get("line-miter-limit"),c=a.get("line-round-limit"),u=0,f=e;u<f.length;u+=1){var h=f[u];this.addLine(h,t,o,s,l,c)}this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length,t,r,i,n)},qs.prototype.addLine=function(t,e,r,n,i,a){if(this.distance=0,this.scaledDistance=0,this.totalDistance=0,e.properties&&e.properties.hasOwnProperty("mapbox_clip_start")&&e.properties.hasOwnProperty("mapbox_clip_end")){this.clipStart=+e.properties.mapbox_clip_start,this.clipEnd=+e.properties.mapbox_clip_end;for(var o=0;o<t.length-1;o++)this.totalDistance+=t[o].dist(t[o+1]);this.updateScaledDistance()}for(var s="Polygon"===Us[e.type],l=t.length;l>=2&&t[l-1].equals(t[l-2]);)l--;for(var c=0;c<l-1&&t[c].equals(t[c+1]);)c++;if(!(l<(s?3:2))){"bevel"===r&&(i=1.05);var u,f=this.overscaling<=16?122880/(512*this.overscaling):0,h=this.segments.prepareSegment(10*l,this.layoutVertexArray,this.indexArray),p=void 0,d=void 0,m=void 0,g=void 0;this.e1=this.e2=-1,s&&(u=t[l-2],g=t[c].sub(u)._unit()._perp());for(var v=c;v<l;v++)if(!(d=v===l-1?s?t[c+1]:void 0:t[v+1])||!t[v].equals(d)){g&&(m=g),u&&(p=u),u=t[v],g=d?d.sub(u)._unit()._perp():m;var y=(m=m||g).add(g);0===y.x&&0===y.y||y._unit();var x=m.x*g.x+m.y*g.y,b=y.x*g.x+y.y*g.y,_=0!==b?1/b:1/0,w=2*Math.sqrt(2-2*b),T=b<Vs&&p&&d,k=m.x*g.y-m.y*g.x>0;if(T&&v>c){var A=u.dist(p);if(A>2*f){var M=u.sub(u.sub(p)._mult(f/A)._round());this.updateDistance(p,M),this.addCurrentVertex(M,m,0,0,h),p=M}}var S=p&&d,E=S?r:s?"butt":n;if(S&&"round"===E&&(_<a?E="miter":_<=2&&(E="fakeround")),"miter"===E&&_>i&&(E="bevel"),"bevel"===E&&(_>2&&(E="flipbevel"),_<i&&(E="miter")),p&&this.updateDistance(p,u),"miter"===E)y._mult(_),this.addCurrentVertex(u,y,0,0,h);else if("flipbevel"===E){if(_>100)y=g.mult(-1);else{var L=_*m.add(g).mag()/m.sub(g).mag();y._perp()._mult(L*(k?-1:1))}this.addCurrentVertex(u,y,0,0,h),this.addCurrentVertex(u,y.mult(-1),0,0,h)}else if("bevel"===E||"fakeround"===E){var C=-Math.sqrt(_*_-1),P=k?C:0,I=k?0:C;if(p&&this.addCurrentVertex(u,m,P,I,h),"fakeround"===E)for(var O=Math.round(180*w/Math.PI/20),z=1;z<O;z++){var D=z/O;if(.5!==D){var R=D-.5;D+=D*R*(D-1)*((1.0904+x*(x*(3.55645-1.43519*x)-3.2452))*R*R+(.848013+x*(.215638*x-1.06021)))}var F=g.sub(m)._mult(D)._add(m)._unit()._mult(k?-1:1);this.addHalfVertex(u,F.x,F.y,!1,k,0,h)}d&&this.addCurrentVertex(u,g,-P,-I,h)}else if("butt"===E)this.addCurrentVertex(u,y,0,0,h);else if("square"===E){var B=p?1:-1;this.addCurrentVertex(u,y,B,B,h)}else"round"===E&&(p&&(this.addCurrentVertex(u,m,0,0,h),this.addCurrentVertex(u,m,1,1,h,!0)),d&&(this.addCurrentVertex(u,g,-1,-1,h,!0),this.addCurrentVertex(u,g,0,0,h)));if(T&&v<l-1){var N=u.dist(d);if(N>2*f){var j=u.add(d.sub(u)._mult(f/N)._round());this.updateDistance(u,j),this.addCurrentVertex(j,g,0,0,h),u=j}}}}},qs.prototype.addCurrentVertex=function(t,e,r,n,i,a){void 0===a&&(a=!1);var o=e.x+e.y*r,s=e.y-e.x*r,l=-e.x+e.y*n,c=-e.y-e.x*n;this.addHalfVertex(t,o,s,a,!1,r,i),this.addHalfVertex(t,l,c,a,!0,-n,i),this.distance>Hs/2&&0===this.totalDistance&&(this.distance=0,this.addCurrentVertex(t,e,r,n,i,a))},qs.prototype.addHalfVertex=function(t,e,r,n,i,a,o){var s=t.x,l=t.y,c=.5*this.scaledDistance;this.layoutVertexArray.emplaceBack((s<<1)+(n?1:0),(l<<1)+(i?1:0),Math.round(63*e)+128,Math.round(63*r)+128,1+(0===a?0:a<0?-1:1)|(63&c)<<2,c>>6);var u=o.vertexLength++;this.e1>=0&&this.e2>=0&&(this.indexArray.emplaceBack(this.e1,this.e2,u),o.primitiveLength++),i?this.e2=u:this.e1=u},qs.prototype.updateScaledDistance=function(){this.scaledDistance=this.totalDistance>0?(this.clipStart+(this.clipEnd-this.clipStart)*this.distance/this.totalDistance)*(Hs-1):this.distance},qs.prototype.updateDistance=function(t,e){this.distance+=t.dist(e),this.updateScaledDistance()},Nn("LineBucket",qs,{omit:["layers","patternFeatures"]});var Gs=new Si({"line-cap":new wi(Lt.layout_line["line-cap"]),"line-join":new Ti(Lt.layout_line["line-join"]),"line-miter-limit":new wi(Lt.layout_line["line-miter-limit"]),"line-round-limit":new wi(Lt.layout_line["line-round-limit"]),"line-sort-key":new Ti(Lt.layout_line["line-sort-key"])}),Ys={paint:new Si({"line-opacity":new Ti(Lt.paint_line["line-opacity"]),"line-color":new Ti(Lt.paint_line["line-color"]),"line-translate":new wi(Lt.paint_line["line-translate"]),"line-translate-anchor":new wi(Lt.paint_line["line-translate-anchor"]),"line-width":new Ti(Lt.paint_line["line-width"]),"line-gap-width":new Ti(Lt.paint_line["line-gap-width"]),"line-offset":new Ti(Lt.paint_line["line-offset"]),"line-blur":new Ti(Lt.paint_line["line-blur"]),"line-dasharray":new Ai(Lt.paint_line["line-dasharray"]),"line-pattern":new ki(Lt.paint_line["line-pattern"]),"line-gradient":new Mi(Lt.paint_line["line-gradient"])}),layout:Gs},Ws=new(function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.possiblyEvaluate=function(e,r){return r=new pi(Math.floor(r.zoom),{now:r.now,fadeDuration:r.fadeDuration,zoomHistory:r.zoomHistory,transition:r.transition}),t.prototype.possiblyEvaluate.call(this,e,r)},e.prototype.evaluate=function(e,r,n,i){return r=u({},r,{zoom:Math.floor(r.zoom)}),t.prototype.evaluate.call(this,e,r,n,i)},e}(Ti))(Ys.paint.properties["line-width"].specification);Ws.useIntegerZoom=!0;var Xs=function(t){function e(e){t.call(this,e,Ys)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._handleSpecialPaintPropertyUpdate=function(t){"line-gradient"===t&&this._updateGradient()},e.prototype._updateGradient=function(){var t=this._transitionablePaint._values["line-gradient"].value.expression;this.gradient=Co(t,"lineProgress"),this.gradientTexture=null},e.prototype.recalculate=function(e,r){t.prototype.recalculate.call(this,e,r),this.paint._values["line-floorwidth"]=Ws.possiblyEvaluate(this._transitioningPaint._values["line-width"].value,e)},e.prototype.createBucket=function(t){return new qs(t)},e.prototype.queryRadius=function(t){var e=t,r=Zs(oo("line-width",this,e),oo("line-gap-width",this,e)),n=oo("line-offset",this,e);return r/2+Math.abs(n)+so(this.paint.get("line-translate"))},e.prototype.queryIntersectsFeature=function(t,e,r,n,a,o,s){var l=lo(t,this.paint.get("line-translate"),this.paint.get("line-translate-anchor"),o.angle,s),c=s/2*Zs(this.paint.get("line-width").evaluate(e,r),this.paint.get("line-gap-width").evaluate(e,r)),u=this.paint.get("line-offset").evaluate(e,r);return u&&(n=function(t,e){for(var r=[],n=new i(0,0),a=0;a<t.length;a++){for(var o=t[a],s=[],l=0;l<o.length;l++){var c=o[l-1],u=o[l],f=o[l+1],h=0===l?n:u.sub(c)._unit()._perp(),p=l===o.length-1?n:f.sub(u)._unit()._perp(),d=h._add(p)._unit(),m=d.x*p.x+d.y*p.y;d._mult(1/m),s.push(d._mult(e)._add(u))}r.push(s)}return r}(n,u*s)),function(t,e,r){for(var n=0;n<e.length;n++){var i=e[n];if(t.length>=3)for(var a=0;a<i.length;a++)if(io(t,i[a]))return!0;if(Qa(t,i,r))return!0}return!1}(l,n,c)},e.prototype.isTileClipped=function(){return!0},e}(Ei);function Zs(t,e){return e>0?e+2*t:t}var Js=Ii([{name:"a_pos_offset",components:4,type:"Int16"},{name:"a_data",components:4,type:"Uint16"},{name:"a_pixeloffset",components:4,type:"Int16"}],4),Ks=Ii([{name:"a_projected_pos",components:3,type:"Float32"}],4),Qs=(Ii([{name:"a_fade_opacity",components:1,type:"Uint32"}],4),Ii([{name:"a_placed",components:2,type:"Uint8"},{name:"a_shift",components:2,type:"Float32"}])),$s=(Ii([{type:"Int16",name:"anchorPointX"},{type:"Int16",name:"anchorPointY"},{type:"Int16",name:"x1"},{type:"Int16",name:"y1"},{type:"Int16",name:"x2"},{type:"Int16",name:"y2"},{type:"Uint32",name:"featureIndex"},{type:"Uint16",name:"sourceLayerIndex"},{type:"Uint16",name:"bucketIndex"}]),Ii([{name:"a_pos",components:2,type:"Int16"},{name:"a_anchor_pos",components:2,type:"Int16"},{name:"a_extrude",components:2,type:"Int16"}],4)),tl=Ii([{name:"a_pos",components:2,type:"Float32"},{name:"a_radius",components:1,type:"Float32"},{name:"a_flags",components:2,type:"Int16"}],4);Ii([{name:"triangle",components:3,type:"Uint16"}]),Ii([{type:"Int16",name:"anchorX"},{type:"Int16",name:"anchorY"},{type:"Uint16",name:"glyphStartIndex"},{type:"Uint16",name:"numGlyphs"},{type:"Uint32",name:"vertexStartIndex"},{type:"Uint32",name:"lineStartIndex"},{type:"Uint32",name:"lineLength"},{type:"Uint16",name:"segment"},{type:"Uint16",name:"lowerSize"},{type:"Uint16",name:"upperSize"},{type:"Float32",name:"lineOffsetX"},{type:"Float32",name:"lineOffsetY"},{type:"Uint8",name:"writingMode"},{type:"Uint8",name:"placedOrientation"},{type:"Uint8",name:"hidden"},{type:"Uint32",name:"crossTileID"},{type:"Int16",name:"associatedIconIndex"}]),Ii([{type:"Int16",name:"anchorX"},{type:"Int16",name:"anchorY"},{type:"Int16",name:"rightJustifiedTextSymbolIndex"},{type:"Int16",name:"centerJustifiedTextSymbolIndex"},{type:"Int16",name:"leftJustifiedTextSymbolIndex"},{type:"Int16",name:"verticalPlacedTextSymbolIndex"},{type:"Int16",name:"placedIconSymbolIndex"},{type:"Int16",name:"verticalPlacedIconSymbolIndex"},{type:"Uint16",name:"key"},{type:"Uint16",name:"textBoxStartIndex"},{type:"Uint16",name:"textBoxEndIndex"},{type:"Uint16",name:"verticalTextBoxStartIndex"},{type:"Uint16",name:"verticalTextBoxEndIndex"},{type:"Uint16",name:"iconBoxStartIndex"},{type:"Uint16",name:"iconBoxEndIndex"},{type:"Uint16",name:"verticalIconBoxStartIndex"},{type:"Uint16",name:"verticalIconBoxEndIndex"},{type:"Uint16",name:"featureIndex"},{type:"Uint16",name:"numHorizontalGlyphVertices"},{type:"Uint16",name:"numVerticalGlyphVertices"},{type:"Uint16",name:"numIconVertices"},{type:"Uint16",name:"numVerticalIconVertices"},{type:"Uint16",name:"useRuntimeCollisionCircles"},{type:"Uint32",name:"crossTileID"},{type:"Float32",name:"textBoxScale"},{type:"Float32",components:2,name:"textOffset"},{type:"Float32",name:"collisionCircleDiameter"}]),Ii([{type:"Float32",name:"offsetX"}]),Ii([{type:"Int16",name:"x"},{type:"Int16",name:"y"},{type:"Int16",name:"tileUnitDistanceFromAnchor"}]);function el(t,e,r){return t.sections.forEach((function(t){t.text=function(t,e,r){var n=e.layout.get("text-transform").evaluate(r,{});return"uppercase"===n?t=t.toLocaleUpperCase():"lowercase"===n&&(t=t.toLocaleLowerCase()),hi.applyArabicShaping&&(t=hi.applyArabicShaping(t)),t}(t.text,e,r)})),t}var rl={"!":"\ufe15","#":"\uff03",$:"\uff04","%":"\uff05","&":"\uff06","(":"\ufe35",")":"\ufe36","*":"\uff0a","+":"\uff0b",",":"\ufe10","-":"\ufe32",".":"\u30fb","/":"\uff0f",":":"\ufe13",";":"\ufe14","<":"\ufe3f","=":"\uff1d",">":"\ufe40","?":"\ufe16","@":"\uff20","[":"\ufe47","\\":"\uff3c","]":"\ufe48","^":"\uff3e",_:"\ufe33","`":"\uff40","{":"\ufe37","|":"\u2015","}":"\ufe38","~":"\uff5e","\xa2":"\uffe0","\xa3":"\uffe1","\xa5":"\uffe5","\xa6":"\uffe4","\xac":"\uffe2","\xaf":"\uffe3","\u2013":"\ufe32","\u2014":"\ufe31","\u2018":"\ufe43","\u2019":"\ufe44","\u201c":"\ufe41","\u201d":"\ufe42","\u2026":"\ufe19","\u2027":"\u30fb","\u20a9":"\uffe6","\u3001":"\ufe11","\u3002":"\ufe12","\u3008":"\ufe3f","\u3009":"\ufe40","\u300a":"\ufe3d","\u300b":"\ufe3e","\u300c":"\ufe41","\u300d":"\ufe42","\u300e":"\ufe43","\u300f":"\ufe44","\u3010":"\ufe3b","\u3011":"\ufe3c","\u3014":"\ufe39","\u3015":"\ufe3a","\u3016":"\ufe17","\u3017":"\ufe18","\uff01":"\ufe15","\uff08":"\ufe35","\uff09":"\ufe36","\uff0c":"\ufe10","\uff0d":"\ufe32","\uff0e":"\u30fb","\uff1a":"\ufe13","\uff1b":"\ufe14","\uff1c":"\ufe3f","\uff1e":"\ufe40","\uff1f":"\ufe16","\uff3b":"\ufe47","\uff3d":"\ufe48","\uff3f":"\ufe33","\uff5b":"\ufe37","\uff5c":"\u2015","\uff5d":"\ufe38","\uff5f":"\ufe35","\uff60":"\ufe36","\uff61":"\ufe12","\uff62":"\ufe41","\uff63":"\ufe42"};var nl=function(t,e,r,n,i){var a,o,s=8*i-n-1,l=(1<<s)-1,c=l>>1,u=-7,f=r?i-1:0,h=r?-1:1,p=t[e+f];for(f+=h,a=p&(1<<-u)-1,p>>=-u,u+=s;u>0;a=256*a+t[e+f],f+=h,u-=8);for(o=a&(1<<-u)-1,a>>=-u,u+=n;u>0;o=256*o+t[e+f],f+=h,u-=8);if(0===a)a=1-c;else{if(a===l)return o?NaN:1/0*(p?-1:1);o+=Math.pow(2,n),a-=c}return(p?-1:1)*o*Math.pow(2,a-n)},il=function(t,e,r,n,i,a){var o,s,l,c=8*a-i-1,u=(1<<c)-1,f=u>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:a-1,d=n?1:-1,m=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,o=u):(o=Math.floor(Math.log(e)/Math.LN2),e*(l=Math.pow(2,-o))<1&&(o--,l*=2),(e+=o+f>=1?h/l:h*Math.pow(2,1-f))*l>=2&&(o++,l/=2),o+f>=u?(s=0,o=u):o+f>=1?(s=(e*l-1)*Math.pow(2,i),o+=f):(s=e*Math.pow(2,f-1)*Math.pow(2,i),o=0));i>=8;t[r+p]=255&s,p+=d,s/=256,i-=8);for(o=o<<i|s,c+=i;c>0;t[r+p]=255&o,p+=d,o/=256,c-=8);t[r+p-d]|=128*m},al=ol;function ol(t){this.buf=ArrayBuffer.isView&&ArrayBuffer.isView(t)?t:new Uint8Array(t||0),this.pos=0,this.type=0,this.length=this.buf.length}ol.Varint=0,ol.Fixed64=1,ol.Bytes=2,ol.Fixed32=5;var sl="undefined"==typeof TextDecoder?null:new TextDecoder("utf8");function ll(t){return t.type===ol.Bytes?t.readVarint()+t.pos:t.pos+1}function cl(t,e,r){return r?4294967296*e+(t>>>0):4294967296*(e>>>0)+(t>>>0)}function ul(t,e,r){var n=e<=16383?1:e<=2097151?2:e<=268435455?3:Math.floor(Math.log(e)/(7*Math.LN2));r.realloc(n);for(var i=r.pos-1;i>=t;i--)r.buf[i+n]=r.buf[i]}function fl(t,e){for(var r=0;r<t.length;r++)e.writeVarint(t[r])}function hl(t,e){for(var r=0;r<t.length;r++)e.writeSVarint(t[r])}function pl(t,e){for(var r=0;r<t.length;r++)e.writeFloat(t[r])}function dl(t,e){for(var r=0;r<t.length;r++)e.writeDouble(t[r])}function ml(t,e){for(var r=0;r<t.length;r++)e.writeBoolean(t[r])}function gl(t,e){for(var r=0;r<t.length;r++)e.writeFixed32(t[r])}function vl(t,e){for(var r=0;r<t.length;r++)e.writeSFixed32(t[r])}function yl(t,e){for(var r=0;r<t.length;r++)e.writeFixed64(t[r])}function xl(t,e){for(var r=0;r<t.length;r++)e.writeSFixed64(t[r])}function bl(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16)+16777216*t[e+3]}function _l(t,e,r){t[r]=e,t[r+1]=e>>>8,t[r+2]=e>>>16,t[r+3]=e>>>24}function wl(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16)+(t[e+3]<<24)}ol.prototype={destroy:function(){this.buf=null},readFields:function(t,e,r){for(r=r||this.length;this.pos<r;){var n=this.readVarint(),i=n>>3,a=this.pos;this.type=7&n,t(i,e,this),this.pos===a&&this.skip(n)}return e},readMessage:function(t,e){return this.readFields(t,e,this.readVarint()+this.pos)},readFixed32:function(){var t=bl(this.buf,this.pos);return this.pos+=4,t},readSFixed32:function(){var t=wl(this.buf,this.pos);return this.pos+=4,t},readFixed64:function(){var t=bl(this.buf,this.pos)+4294967296*bl(this.buf,this.pos+4);return this.pos+=8,t},readSFixed64:function(){var t=bl(this.buf,this.pos)+4294967296*wl(this.buf,this.pos+4);return this.pos+=8,t},readFloat:function(){var t=nl(this.buf,this.pos,!0,23,4);return this.pos+=4,t},readDouble:function(){var t=nl(this.buf,this.pos,!0,52,8);return this.pos+=8,t},readVarint:function(t){var e,r,n=this.buf;return e=127&(r=n[this.pos++]),r<128?e:(e|=(127&(r=n[this.pos++]))<<7,r<128?e:(e|=(127&(r=n[this.pos++]))<<14,r<128?e:(e|=(127&(r=n[this.pos++]))<<21,r<128?e:function(t,e,r){var n,i,a=r.buf;if(i=a[r.pos++],n=(112&i)>>4,i<128)return cl(t,n,e);if(i=a[r.pos++],n|=(127&i)<<3,i<128)return cl(t,n,e);if(i=a[r.pos++],n|=(127&i)<<10,i<128)return cl(t,n,e);if(i=a[r.pos++],n|=(127&i)<<17,i<128)return cl(t,n,e);if(i=a[r.pos++],n|=(127&i)<<24,i<128)return cl(t,n,e);if(i=a[r.pos++],n|=(1&i)<<31,i<128)return cl(t,n,e);throw new Error("Expected varint not more than 10 bytes")}(e|=(15&(r=n[this.pos]))<<28,t,this))))},readVarint64:function(){return this.readVarint(!0)},readSVarint:function(){var t=this.readVarint();return t%2==1?(t+1)/-2:t/2},readBoolean:function(){return Boolean(this.readVarint())},readString:function(){var t=this.readVarint()+this.pos,e=this.pos;return this.pos=t,t-e>=12&&sl?function(t,e,r){return sl.decode(t.subarray(e,r))}(this.buf,e,t):function(t,e,r){var n="",i=e;for(;i<r;){var a,o,s,l=t[i],c=null,u=l>239?4:l>223?3:l>191?2:1;if(i+u>r)break;1===u?l<128&&(c=l):2===u?128==(192&(a=t[i+1]))&&(c=(31&l)<<6|63&a)<=127&&(c=null):3===u?(a=t[i+1],o=t[i+2],128==(192&a)&&128==(192&o)&&((c=(15&l)<<12|(63&a)<<6|63&o)<=2047||c>=55296&&c<=57343)&&(c=null)):4===u&&(a=t[i+1],o=t[i+2],s=t[i+3],128==(192&a)&&128==(192&o)&&128==(192&s)&&((c=(15&l)<<18|(63&a)<<12|(63&o)<<6|63&s)<=65535||c>=1114112)&&(c=null)),null===c?(c=65533,u=1):c>65535&&(c-=65536,n+=String.fromCharCode(c>>>10&1023|55296),c=56320|1023&c),n+=String.fromCharCode(c),i+=u}return n}(this.buf,e,t)},readBytes:function(){var t=this.readVarint()+this.pos,e=this.buf.subarray(this.pos,t);return this.pos=t,e},readPackedVarint:function(t,e){if(this.type!==ol.Bytes)return t.push(this.readVarint(e));var r=ll(this);for(t=t||[];this.pos<r;)t.push(this.readVarint(e));return t},readPackedSVarint:function(t){if(this.type!==ol.Bytes)return t.push(this.readSVarint());var e=ll(this);for(t=t||[];this.pos<e;)t.push(this.readSVarint());return t},readPackedBoolean:function(t){if(this.type!==ol.Bytes)return t.push(this.readBoolean());var e=ll(this);for(t=t||[];this.pos<e;)t.push(this.readBoolean());return t},readPackedFloat:function(t){if(this.type!==ol.Bytes)return t.push(this.readFloat());var e=ll(this);for(t=t||[];this.pos<e;)t.push(this.readFloat());return t},readPackedDouble:function(t){if(this.type!==ol.Bytes)return t.push(this.readDouble());var e=ll(this);for(t=t||[];this.pos<e;)t.push(this.readDouble());return t},readPackedFixed32:function(t){if(this.type!==ol.Bytes)return t.push(this.readFixed32());var e=ll(this);for(t=t||[];this.pos<e;)t.push(this.readFixed32());return t},readPackedSFixed32:function(t){if(this.type!==ol.Bytes)return t.push(this.readSFixed32());var e=ll(this);for(t=t||[];this.pos<e;)t.push(this.readSFixed32());return t},readPackedFixed64:function(t){if(this.type!==ol.Bytes)return t.push(this.readFixed64());var e=ll(this);for(t=t||[];this.pos<e;)t.push(this.readFixed64());return t},readPackedSFixed64:function(t){if(this.type!==ol.Bytes)return t.push(this.readSFixed64());var e=ll(this);for(t=t||[];this.pos<e;)t.push(this.readSFixed64());return t},skip:function(t){var e=7&t;if(e===ol.Varint)for(;this.buf[this.pos++]>127;);else if(e===ol.Bytes)this.pos=this.readVarint()+this.pos;else if(e===ol.Fixed32)this.pos+=4;else{if(e!==ol.Fixed64)throw new Error("Unimplemented type: "+e);this.pos+=8}},writeTag:function(t,e){this.writeVarint(t<<3|e)},realloc:function(t){for(var e=this.length||16;e<this.pos+t;)e*=2;if(e!==this.length){var r=new Uint8Array(e);r.set(this.buf),this.buf=r,this.length=e}},finish:function(){return this.length=this.pos,this.pos=0,this.buf.subarray(0,this.length)},writeFixed32:function(t){this.realloc(4),_l(this.buf,t,this.pos),this.pos+=4},writeSFixed32:function(t){this.realloc(4),_l(this.buf,t,this.pos),this.pos+=4},writeFixed64:function(t){this.realloc(8),_l(this.buf,-1&t,this.pos),_l(this.buf,Math.floor(t*(1/4294967296)),this.pos+4),this.pos+=8},writeSFixed64:function(t){this.realloc(8),_l(this.buf,-1&t,this.pos),_l(this.buf,Math.floor(t*(1/4294967296)),this.pos+4),this.pos+=8},writeVarint:function(t){(t=+t||0)>268435455||t<0?function(t,e){var r,n;t>=0?(r=t%4294967296|0,n=t/4294967296|0):(n=~(-t/4294967296),4294967295^(r=~(-t%4294967296))?r=r+1|0:(r=0,n=n+1|0));if(t>=0x10000000000000000||t<-0x10000000000000000)throw new Error("Given varint doesn't fit into 10 bytes");e.realloc(10),function(t,e,r){r.buf[r.pos++]=127&t|128,t>>>=7,r.buf[r.pos++]=127&t|128,t>>>=7,r.buf[r.pos++]=127&t|128,t>>>=7,r.buf[r.pos++]=127&t|128,t>>>=7,r.buf[r.pos]=127&t}(r,0,e),function(t,e){var r=(7&t)<<4;if(e.buf[e.pos++]|=r|((t>>>=3)?128:0),!t)return;if(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),!t)return;if(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),!t)return;if(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),!t)return;if(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),!t)return;e.buf[e.pos++]=127&t}(n,e)}(t,this):(this.realloc(4),this.buf[this.pos++]=127&t|(t>127?128:0),t<=127||(this.buf[this.pos++]=127&(t>>>=7)|(t>127?128:0),t<=127||(this.buf[this.pos++]=127&(t>>>=7)|(t>127?128:0),t<=127||(this.buf[this.pos++]=t>>>7&127))))},writeSVarint:function(t){this.writeVarint(t<0?2*-t-1:2*t)},writeBoolean:function(t){this.writeVarint(Boolean(t))},writeString:function(t){t=String(t),this.realloc(4*t.length),this.pos++;var e=this.pos;this.pos=function(t,e,r){for(var n,i,a=0;a<e.length;a++){if((n=e.charCodeAt(a))>55295&&n<57344){if(!i){n>56319||a+1===e.length?(t[r++]=239,t[r++]=191,t[r++]=189):i=n;continue}if(n<56320){t[r++]=239,t[r++]=191,t[r++]=189,i=n;continue}n=i-55296<<10|n-56320|65536,i=null}else i&&(t[r++]=239,t[r++]=191,t[r++]=189,i=null);n<128?t[r++]=n:(n<2048?t[r++]=n>>6|192:(n<65536?t[r++]=n>>12|224:(t[r++]=n>>18|240,t[r++]=n>>12&63|128),t[r++]=n>>6&63|128),t[r++]=63&n|128)}return r}(this.buf,t,this.pos);var r=this.pos-e;r>=128&&ul(e,r,this),this.pos=e-1,this.writeVarint(r),this.pos+=r},writeFloat:function(t){this.realloc(4),il(this.buf,t,this.pos,!0,23,4),this.pos+=4},writeDouble:function(t){this.realloc(8),il(this.buf,t,this.pos,!0,52,8),this.pos+=8},writeBytes:function(t){var e=t.length;this.writeVarint(e),this.realloc(e);for(var r=0;r<e;r++)this.buf[this.pos++]=t[r]},writeRawMessage:function(t,e){this.pos++;var r=this.pos;t(e,this);var n=this.pos-r;n>=128&&ul(r,n,this),this.pos=r-1,this.writeVarint(n),this.pos+=n},writeMessage:function(t,e,r){this.writeTag(t,ol.Bytes),this.writeRawMessage(e,r)},writePackedVarint:function(t,e){e.length&&this.writeMessage(t,fl,e)},writePackedSVarint:function(t,e){e.length&&this.writeMessage(t,hl,e)},writePackedBoolean:function(t,e){e.length&&this.writeMessage(t,ml,e)},writePackedFloat:function(t,e){e.length&&this.writeMessage(t,pl,e)},writePackedDouble:function(t,e){e.length&&this.writeMessage(t,dl,e)},writePackedFixed32:function(t,e){e.length&&this.writeMessage(t,gl,e)},writePackedSFixed32:function(t,e){e.length&&this.writeMessage(t,vl,e)},writePackedFixed64:function(t,e){e.length&&this.writeMessage(t,yl,e)},writePackedSFixed64:function(t,e){e.length&&this.writeMessage(t,xl,e)},writeBytesField:function(t,e){this.writeTag(t,ol.Bytes),this.writeBytes(e)},writeFixed32Field:function(t,e){this.writeTag(t,ol.Fixed32),this.writeFixed32(e)},writeSFixed32Field:function(t,e){this.writeTag(t,ol.Fixed32),this.writeSFixed32(e)},writeFixed64Field:function(t,e){this.writeTag(t,ol.Fixed64),this.writeFixed64(e)},writeSFixed64Field:function(t,e){this.writeTag(t,ol.Fixed64),this.writeSFixed64(e)},writeVarintField:function(t,e){this.writeTag(t,ol.Varint),this.writeVarint(e)},writeSVarintField:function(t,e){this.writeTag(t,ol.Varint),this.writeSVarint(e)},writeStringField:function(t,e){this.writeTag(t,ol.Bytes),this.writeString(e)},writeFloatField:function(t,e){this.writeTag(t,ol.Fixed32),this.writeFloat(e)},writeDoubleField:function(t,e){this.writeTag(t,ol.Fixed64),this.writeDouble(e)},writeBooleanField:function(t,e){this.writeVarintField(t,Boolean(e))}};function Tl(t,e,r){1===t&&r.readMessage(kl,e)}function kl(t,e,r){if(3===t){var n=r.readMessage(Al,{}),i=n.id,a=n.bitmap,o=n.width,s=n.height,l=n.left,c=n.top,u=n.advance;e.push({id:i,bitmap:new So({width:o+6,height:s+6},a),metrics:{width:o,height:s,left:l,top:c,advance:u}})}}function Al(t,e,r){1===t?e.id=r.readVarint():2===t?e.bitmap=r.readBytes():3===t?e.width=r.readVarint():4===t?e.height=r.readVarint():5===t?e.left=r.readSVarint():6===t?e.top=r.readSVarint():7===t&&(e.advance=r.readVarint())}function Ml(t){for(var e=0,r=0,n=0,i=t;n<i.length;n+=1){var a=i[n];e+=a.w*a.h,r=Math.max(r,a.w)}t.sort((function(t,e){return e.h-t.h}));for(var o=[{x:0,y:0,w:Math.max(Math.ceil(Math.sqrt(e/.95)),r),h:1/0}],s=0,l=0,c=0,u=t;c<u.length;c+=1)for(var f=u[c],h=o.length-1;h>=0;h--){var p=o[h];if(!(f.w>p.w||f.h>p.h)){if(f.x=p.x,f.y=p.y,l=Math.max(l,f.y+f.h),s=Math.max(s,f.x+f.w),f.w===p.w&&f.h===p.h){var d=o.pop();h<o.length&&(o[h]=d)}else f.h===p.h?(p.x+=f.w,p.w-=f.w):f.w===p.w?(p.y+=f.h,p.h-=f.h):(o.push({x:p.x+f.w,y:p.y,w:p.w-f.w,h:f.h}),p.y+=f.h,p.h-=f.h);break}}return{w:s,h:l,fill:e/(s*l)||0}}var Sl=function(t,e){var r=e.pixelRatio,n=e.version,i=e.stretchX,a=e.stretchY,o=e.content;this.paddedRect=t,this.pixelRatio=r,this.stretchX=i,this.stretchY=a,this.content=o,this.version=n},El={tl:{configurable:!0},br:{configurable:!0},tlbr:{configurable:!0},displaySize:{configurable:!0}};El.tl.get=function(){return[this.paddedRect.x+1,this.paddedRect.y+1]},El.br.get=function(){return[this.paddedRect.x+this.paddedRect.w-1,this.paddedRect.y+this.paddedRect.h-1]},El.tlbr.get=function(){return this.tl.concat(this.br)},El.displaySize.get=function(){return[(this.paddedRect.w-2)/this.pixelRatio,(this.paddedRect.h-2)/this.pixelRatio]},Object.defineProperties(Sl.prototype,El);var Ll=function(t,e){var r={},n={};this.haveRenderCallbacks=[];var i=[];this.addImages(t,r,i),this.addImages(e,n,i);var a=Ml(i),o=a.w,s=a.h,l=new Eo({width:o||1,height:s||1});for(var c in t){var u=t[c],f=r[c].paddedRect;Eo.copy(u.data,l,{x:0,y:0},{x:f.x+1,y:f.y+1},u.data)}for(var h in e){var p=e[h],d=n[h].paddedRect,m=d.x+1,g=d.y+1,v=p.data.width,y=p.data.height;Eo.copy(p.data,l,{x:0,y:0},{x:m,y:g},p.data),Eo.copy(p.data,l,{x:0,y:y-1},{x:m,y:g-1},{width:v,height:1}),Eo.copy(p.data,l,{x:0,y:0},{x:m,y:g+y},{width:v,height:1}),Eo.copy(p.data,l,{x:v-1,y:0},{x:m-1,y:g},{width:1,height:y}),Eo.copy(p.data,l,{x:0,y:0},{x:m+v,y:g},{width:1,height:y})}this.image=l,this.iconPositions=r,this.patternPositions=n};Ll.prototype.addImages=function(t,e,r){for(var n in t){var i=t[n],a={x:0,y:0,w:i.data.width+2,h:i.data.height+2};r.push(a),e[n]=new Sl(a,i),i.hasRenderCallback&&this.haveRenderCallbacks.push(n)}},Ll.prototype.patchUpdatedImages=function(t,e){for(var r in t.dispatchRenderCallbacks(this.haveRenderCallbacks),t.updatedImages)this.patchUpdatedImage(this.iconPositions[r],t.getImage(r),e),this.patchUpdatedImage(this.patternPositions[r],t.getImage(r),e)},Ll.prototype.patchUpdatedImage=function(t,e,r){if(t&&e&&t.version!==e.version){t.version=e.version;var n=t.tl,i=n[0],a=n[1];r.update(e.data,void 0,{x:i,y:a})}},Nn("ImagePosition",Sl),Nn("ImageAtlas",Ll);var Cl={horizontal:1,vertical:2,horizontalOnly:3};var Pl=function(){this.scale=1,this.fontStack="",this.imageName=null};Pl.forText=function(t,e){var r=new Pl;return r.scale=t||1,r.fontStack=e,r},Pl.forImage=function(t){var e=new Pl;return e.imageName=t,e};var Il=function(){this.text="",this.sectionIndex=[],this.sections=[],this.imageSectionID=null};function Ol(t,e,r,n,i,a,o,s,l,c,u,f,h,p,d,m){var g,v=Il.fromFeature(t,i);f===Cl.vertical&&v.verticalizePunctuation();var y=hi.processBidirectionalText,x=hi.processStyledBidirectionalText;if(y&&1===v.sections.length){g=[];for(var b=0,_=y(v.toString(),jl(v,c,a,e,n,p,d));b<_.length;b+=1){var w=_[b],T=new Il;T.text=w,T.sections=v.sections;for(var k=0;k<w.length;k++)T.sectionIndex.push(0);g.push(T)}}else if(x){g=[];for(var A=0,M=x(v.text,v.sectionIndex,jl(v,c,a,e,n,p,d));A<M.length;A+=1){var S=M[A],E=new Il;E.text=S[0],E.sectionIndex=S[1],E.sections=v.sections,g.push(E)}}else g=function(t,e){for(var r=[],n=t.text,i=0,a=0,o=e;a<o.length;a+=1){var s=o[a];r.push(t.substring(i,s)),i=s}return i<n.length&&r.push(t.substring(i,n.length)),r}(v,jl(v,c,a,e,n,p,d));var L=[],C={positionedLines:L,text:v.toString(),top:u[1],bottom:u[1],left:u[0],right:u[0],writingMode:f,iconsInText:!1,verticalizable:!1};return function(t,e,r,n,i,a,o,s,l,c,u,f){for(var h=0,p=-17,d=0,m=0,g="right"===s?1:"left"===s?0:.5,v=0,y=0,x=i;y<x.length;y+=1){var b=x[y];b.trim();var _=b.getMaxScale(),w=24*(_-1),T={positionedGlyphs:[],lineOffset:0};t.positionedLines[v]=T;var k=T.positionedGlyphs,A=0;if(b.length()){for(var M=0;M<b.length();M++){var S=b.getSection(M),E=b.getSectionIndex(M),L=b.getCharCode(M),C=0,P=null,I=null,O=null,z=24,D=!(l===Cl.horizontal||!u&&!Zn(L)||u&&(zl[L]||(Y=L,Yn.Arabic(Y)||Yn["Arabic Supplement"](Y)||Yn["Arabic Extended-A"](Y)||Yn["Arabic Presentation Forms-A"](Y)||Yn["Arabic Presentation Forms-B"](Y))));if(S.imageName){var R=n[S.imageName];if(!R)continue;O=S.imageName,t.iconsInText=t.iconsInText||!0,I=R.paddedRect;var F=R.displaySize;S.scale=24*S.scale/f,P={width:F[0],height:F[1],left:1,top:-3,advance:D?F[1]:F[0]};var B=24-F[1]*S.scale;C=w+B,z=P.advance;var N=D?F[0]*S.scale-24*_:F[1]*S.scale-24*_;N>0&&N>A&&(A=N)}else{var j=r[S.fontStack],U=j&&j[L];if(U&&U.rect)I=U.rect,P=U.metrics;else{var V=e[S.fontStack],H=V&&V[L];if(!H)continue;P=H.metrics}C=24*(_-S.scale)}D?(t.verticalizable=!0,k.push({glyph:L,imageName:O,x:h,y:p+C,vertical:D,scale:S.scale,fontStack:S.fontStack,sectionIndex:E,metrics:P,rect:I}),h+=z*S.scale+c):(k.push({glyph:L,imageName:O,x:h,y:p+C,vertical:D,scale:S.scale,fontStack:S.fontStack,sectionIndex:E,metrics:P,rect:I}),h+=P.advance*S.scale+c)}if(0!==k.length){var q=h-c;d=Math.max(q,d),Vl(k,0,k.length-1,g,A)}h=0;var G=a*_+A;T.lineOffset=Math.max(A,w),p+=G,m=Math.max(G,m),++v}else p+=a,++v}var Y;var W=p- -17,X=Ul(o),Z=X.horizontalAlign,J=X.verticalAlign;(function(t,e,r,n,i,a,o,s,l){var c=(e-r)*i,u=0;u=a!==o?-s*n- -17:(-n*l+.5)*o;for(var f=0,h=t;f<h.length;f+=1)for(var p=h[f],d=0,m=p.positionedGlyphs;d<m.length;d+=1){var g=m[d];g.x+=c,g.y+=u}})(t.positionedLines,g,Z,J,d,m,a,W,i.length),t.top+=-J*W,t.bottom=t.top+W,t.left+=-Z*d,t.right=t.left+d}(C,e,r,n,g,o,s,l,f,c,h,m),!function(t){for(var e=0,r=t;e<r.length;e+=1){if(0!==r[e].positionedGlyphs.length)return!1}return!0}(L)&&C}Il.fromFeature=function(t,e){for(var r=new Il,n=0;n<t.sections.length;n++){var i=t.sections[n];i.image?r.addImageSection(i):r.addTextSection(i,e)}return r},Il.prototype.length=function(){return this.text.length},Il.prototype.getSection=function(t){return this.sections[this.sectionIndex[t]]},Il.prototype.getSectionIndex=function(t){return this.sectionIndex[t]},Il.prototype.getCharCode=function(t){return this.text.charCodeAt(t)},Il.prototype.verticalizePunctuation=function(){this.text=function(t){for(var e="",r=0;r<t.length;r++){var n=t.charCodeAt(r+1)||null,i=t.charCodeAt(r-1)||null;(!n||!Jn(n)||rl[t[r+1]])&&(!i||!Jn(i)||rl[t[r-1]])&&rl[t[r]]?e+=rl[t[r]]:e+=t[r]}return e}(this.text)},Il.prototype.trim=function(){for(var t=0,e=0;e<this.text.length&&zl[this.text.charCodeAt(e)];e++)t++;for(var r=this.text.length,n=this.text.length-1;n>=0&&n>=t&&zl[this.text.charCodeAt(n)];n--)r--;this.text=this.text.substring(t,r),this.sectionIndex=this.sectionIndex.slice(t,r)},Il.prototype.substring=function(t,e){var r=new Il;return r.text=this.text.substring(t,e),r.sectionIndex=this.sectionIndex.slice(t,e),r.sections=this.sections,r},Il.prototype.toString=function(){return this.text},Il.prototype.getMaxScale=function(){var t=this;return this.sectionIndex.reduce((function(e,r){return Math.max(e,t.sections[r].scale)}),0)},Il.prototype.addTextSection=function(t,e){this.text+=t.text,this.sections.push(Pl.forText(t.scale,t.fontStack||e));for(var r=this.sections.length-1,n=0;n<t.text.length;++n)this.sectionIndex.push(r)},Il.prototype.addImageSection=function(t){var e=t.image?t.image.name:"";if(0!==e.length){var r=this.getNextImageSectionCharCode();r?(this.text+=String.fromCharCode(r),this.sections.push(Pl.forImage(e)),this.sectionIndex.push(this.sections.length-1)):_("Reached maximum number of images 6401")}else _("Can't add FormattedSection with an empty image.")},Il.prototype.getNextImageSectionCharCode=function(){return this.imageSectionID?this.imageSectionID>=63743?null:++this.imageSectionID:(this.imageSectionID=57344,this.imageSectionID)};var zl={9:!0,10:!0,11:!0,12:!0,13:!0,32:!0},Dl={};function Rl(t,e,r,n,i,a){if(e.imageName){var o=n[e.imageName];return o?o.displaySize[0]*e.scale*24/a+i:0}var s=r[e.fontStack],l=s&&s[t];return l?l.metrics.advance*e.scale+i:0}function Fl(t,e,r,n){var i=Math.pow(t-e,2);return n?t<e?i/2:2*i:i+Math.abs(r)*r}function Bl(t,e,r){var n=0;return 10===t&&(n-=1e4),r&&(n+=150),40!==t&&65288!==t||(n+=50),41!==e&&65289!==e||(n+=50),n}function Nl(t,e,r,n,i,a){for(var o=null,s=Fl(e,r,i,a),l=0,c=n;l<c.length;l+=1){var u=c[l],f=Fl(e-u.x,r,i,a)+u.badness;f<=s&&(o=u,s=f)}return{index:t,x:e,priorBreak:o,badness:s}}function jl(t,e,r,n,i,a,o){if("point"!==a)return[];if(!t)return[];for(var s,l=[],c=function(t,e,r,n,i,a){for(var o=0,s=0;s<t.length();s++){var l=t.getSection(s);o+=Rl(t.getCharCode(s),l,n,i,e,a)}return o/Math.max(1,Math.ceil(o/r))}(t,e,r,n,i,o),u=t.text.indexOf("\u200b")>=0,f=0,h=0;h<t.length();h++){var p=t.getSection(h),d=t.getCharCode(h);if(zl[d]||(f+=Rl(d,p,n,i,e,o)),h<t.length()-1){var m=!!(!((s=d)<11904)&&(Yn["Bopomofo Extended"](s)||Yn.Bopomofo(s)||Yn["CJK Compatibility Forms"](s)||Yn["CJK Compatibility Ideographs"](s)||Yn["CJK Compatibility"](s)||Yn["CJK Radicals Supplement"](s)||Yn["CJK Strokes"](s)||Yn["CJK Symbols and Punctuation"](s)||Yn["CJK Unified Ideographs Extension A"](s)||Yn["CJK Unified Ideographs"](s)||Yn["Enclosed CJK Letters and Months"](s)||Yn["Halfwidth and Fullwidth Forms"](s)||Yn.Hiragana(s)||Yn["Ideographic Description Characters"](s)||Yn["Kangxi Radicals"](s)||Yn["Katakana Phonetic Extensions"](s)||Yn.Katakana(s)||Yn["Vertical Forms"](s)||Yn["Yi Radicals"](s)||Yn["Yi Syllables"](s)));(Dl[d]||m||p.imageName)&&l.push(Nl(h+1,f,c,l,Bl(d,t.getCharCode(h+1),m&&u),!1))}}return function t(e){return e?t(e.priorBreak).concat(e.index):[]}(Nl(t.length(),f,c,l,0,!0))}function Ul(t){var e=.5,r=.5;switch(t){case"right":case"top-right":case"bottom-right":e=1;break;case"left":case"top-left":case"bottom-left":e=0}switch(t){case"bottom":case"bottom-right":case"bottom-left":r=1;break;case"top":case"top-right":case"top-left":r=0}return{horizontalAlign:e,verticalAlign:r}}function Vl(t,e,r,n,i){if(n||i)for(var a=t[r],o=a.metrics.advance*a.scale,s=(t[r].x+o)*n,l=e;l<=r;l++)t[l].x-=s,t[l].y+=i}function Hl(t,e,r,n,i,a){var o,s=t.image;if(s.content){var l=s.content,c=s.pixelRatio||1;o=[l[0]/c,l[1]/c,s.displaySize[0]-l[2]/c,s.displaySize[1]-l[3]/c]}var u,f,h,p,d=e.left*a,m=e.right*a;"width"===r||"both"===r?(p=i[0]+d-n[3],f=i[0]+m+n[1]):f=(p=i[0]+(d+m-s.displaySize[0])/2)+s.displaySize[0];var g=e.top*a,v=e.bottom*a;return"height"===r||"both"===r?(u=i[1]+g-n[0],h=i[1]+v+n[2]):h=(u=i[1]+(g+v-s.displaySize[1])/2)+s.displaySize[1],{image:s,top:u,right:f,bottom:h,left:p,collisionPadding:o}}Dl[10]=!0,Dl[32]=!0,Dl[38]=!0,Dl[40]=!0,Dl[41]=!0,Dl[43]=!0,Dl[45]=!0,Dl[47]=!0,Dl[173]=!0,Dl[183]=!0,Dl[8203]=!0,Dl[8208]=!0,Dl[8211]=!0,Dl[8231]=!0;var ql=function(t){function e(e,r,n,i){t.call(this,e,r),this.angle=n,void 0!==i&&(this.segment=i)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.clone=function(){return new e(this.x,this.y,this.angle,this.segment)},e}(i);Nn("Anchor",ql);function Gl(t,e){var r=e.expression;if("constant"===r.kind)return{kind:"constant",layoutSize:r.evaluate(new pi(t+1))};if("source"===r.kind)return{kind:"source"};for(var n=r.zoomStops,i=r.interpolationType,a=0;a<n.length&&n[a]<=t;)a++;for(var o=a=Math.max(0,a-1);o<n.length&&n[o]<t+1;)o++;o=Math.min(n.length-1,o);var s=n[a],l=n[o];return"composite"===r.kind?{kind:"composite",minZoom:s,maxZoom:l,interpolationType:i}:{kind:"camera",minZoom:s,maxZoom:l,minSize:r.evaluate(new pi(s)),maxSize:r.evaluate(new pi(l)),interpolationType:i}}function Yl(t,e,r){var n=e.uSize,i=e.uSizeT,a=r.lowerSize,o=r.upperSize;return"source"===t.kind?a/128:"composite"===t.kind?qe(a/128,o/128,i):n}function Wl(t,e){var r=0,n=0;if("constant"===t.kind)n=t.layoutSize;else if("source"!==t.kind){var i=t.interpolationType,a=t.minZoom,o=t.maxZoom,s=i?l(or.interpolationFactor(i,e,a,o),0,1):0;"camera"===t.kind?n=qe(t.minSize,t.maxSize,s):r=s}return{uSizeT:r,uSize:n}}var Xl=Object.freeze({__proto__:null,getSizeData:Gl,evaluateSizeForFeature:Yl,evaluateSizeForZoom:Wl,SIZE_PACK_FACTOR:128});function Zl(t,e,r,n,i){if(void 0===e.segment)return!0;for(var a=e,o=e.segment+1,s=0;s>-r/2;){if(--o<0)return!1;s-=t[o].dist(a),a=t[o]}s+=t[o].dist(t[o+1]),o++;for(var l=[],c=0;s<r/2;){var u=t[o-1],f=t[o],h=t[o+1];if(!h)return!1;var p=u.angleTo(f)-f.angleTo(h);for(p=Math.abs((p+3*Math.PI)%(2*Math.PI)-Math.PI),l.push({distance:s,angleDelta:p}),c+=p;s-l[0].distance>n;)c-=l.shift().angleDelta;if(c>i)return!1;o++,s+=f.dist(h)}return!0}function Jl(t){for(var e=0,r=0;r<t.length-1;r++)e+=t[r].dist(t[r+1]);return e}function Kl(t,e,r){return t?.6*e*r:0}function Ql(t,e){return Math.max(t?t.right-t.left:0,e?e.right-e.left:0)}function $l(t,e,r,n,i,a){for(var o=Kl(r,i,a),s=Ql(r,n)*a,l=0,c=Jl(t)/2,u=0;u<t.length-1;u++){var f=t[u],h=t[u+1],p=f.dist(h);if(l+p>c){var d=(c-l)/p,m=qe(f.x,h.x,d),g=qe(f.y,h.y,d),v=new ql(m,g,h.angleTo(f),u);return v._round(),!o||Zl(t,v,s,o,e)?v:void 0}l+=p}}function tc(t,e,r,n,i,a,o,s,l){var c=Kl(n,a,o),u=Ql(n,i),f=u*o,h=0===t[0].x||t[0].x===l||0===t[0].y||t[0].y===l;return e-f<e/4&&(e=f+e/4),function t(e,r,n,i,a,o,s,l,c){for(var u=o/2,f=Jl(e),h=0,p=r-n,d=[],m=0;m<e.length-1;m++){for(var g=e[m],v=e[m+1],y=g.dist(v),x=v.angleTo(g);p+n<h+y;){var b=((p+=n)-h)/y,_=qe(g.x,v.x,b),w=qe(g.y,v.y,b);if(_>=0&&_<c&&w>=0&&w<c&&p-u>=0&&p+u<=f){var T=new ql(_,w,x,m);T._round(),i&&!Zl(e,T,o,i,a)||d.push(T)}}h+=y}l||d.length||s||(d=t(e,h/2,n,i,a,o,s,!0,c));return d}(t,h?e/2*s%e:(u/2+2*a)*o*s%e,e,c,r,f,h,!1,l)}function ec(t,e,r,n,a){for(var o=[],s=0;s<t.length;s++)for(var l=t[s],c=void 0,u=0;u<l.length-1;u++){var f=l[u],h=l[u+1];f.x<e&&h.x<e||(f.x<e?f=new i(e,f.y+(h.y-f.y)*((e-f.x)/(h.x-f.x)))._round():h.x<e&&(h=new i(e,f.y+(h.y-f.y)*((e-f.x)/(h.x-f.x)))._round()),f.y<r&&h.y<r||(f.y<r?f=new i(f.x+(h.x-f.x)*((r-f.y)/(h.y-f.y)),r)._round():h.y<r&&(h=new i(f.x+(h.x-f.x)*((r-f.y)/(h.y-f.y)),r)._round()),f.x>=n&&h.x>=n||(f.x>=n?f=new i(n,f.y+(h.y-f.y)*((n-f.x)/(h.x-f.x)))._round():h.x>=n&&(h=new i(n,f.y+(h.y-f.y)*((n-f.x)/(h.x-f.x)))._round()),f.y>=a&&h.y>=a||(f.y>=a?f=new i(f.x+(h.x-f.x)*((a-f.y)/(h.y-f.y)),a)._round():h.y>=a&&(h=new i(f.x+(h.x-f.x)*((a-f.y)/(h.y-f.y)),a)._round()),c&&f.equals(c[c.length-1])||(c=[f],o.push(c)),c.push(h)))))}return o}function rc(t,e,r,n){var a=[],o=t.image,s=o.pixelRatio,l=o.paddedRect.w-2,c=o.paddedRect.h-2,u=t.right-t.left,f=t.bottom-t.top,h=o.stretchX||[[0,l]],p=o.stretchY||[[0,c]],d=function(t,e){return t+e[1]-e[0]},m=h.reduce(d,0),g=p.reduce(d,0),v=l-m,y=c-g,x=0,b=m,_=0,w=g,T=0,k=v,A=0,M=y;if(o.content&&n){var S=o.content;x=nc(h,0,S[0]),_=nc(p,0,S[1]),b=nc(h,S[0],S[2]),w=nc(p,S[1],S[3]),T=S[0]-x,A=S[1]-_,k=S[2]-S[0]-b,M=S[3]-S[1]-w}var E=function(n,a,l,c){var h=ac(n.stretch-x,b,u,t.left),p=oc(n.fixed-T,k,n.stretch,m),d=ac(a.stretch-_,w,f,t.top),v=oc(a.fixed-A,M,a.stretch,g),y=ac(l.stretch-x,b,u,t.left),S=oc(l.fixed-T,k,l.stretch,m),E=ac(c.stretch-_,w,f,t.top),L=oc(c.fixed-A,M,c.stretch,g),C=new i(h,d),P=new i(y,d),I=new i(y,E),O=new i(h,E),z=new i(p/s,v/s),D=new i(S/s,L/s),R=e*Math.PI/180;if(R){var F=Math.sin(R),B=Math.cos(R),N=[B,-F,F,B];C._matMult(N),P._matMult(N),O._matMult(N),I._matMult(N)}var j=n.stretch+n.fixed,U=l.stretch+l.fixed,V=a.stretch+a.fixed,H=c.stretch+c.fixed;return{tl:C,tr:P,bl:O,br:I,tex:{x:o.paddedRect.x+1+j,y:o.paddedRect.y+1+V,w:U-j,h:H-V},writingMode:void 0,glyphOffset:[0,0],sectionIndex:0,pixelOffsetTL:z,pixelOffsetBR:D,minFontScaleX:k/s/u,minFontScaleY:M/s/f,isSDF:r}};if(n&&(o.stretchX||o.stretchY))for(var L=ic(h,v,m),C=ic(p,y,g),P=0;P<L.length-1;P++)for(var I=L[P],O=L[P+1],z=0;z<C.length-1;z++){var D=C[z],R=C[z+1];a.push(E(I,D,O,R))}else a.push(E({fixed:0,stretch:-1},{fixed:0,stretch:-1},{fixed:0,stretch:l+1},{fixed:0,stretch:c+1}));return a}function nc(t,e,r){for(var n=0,i=0,a=t;i<a.length;i+=1){var o=a[i];n+=Math.max(e,Math.min(r,o[1]))-Math.max(e,Math.min(r,o[0]))}return n}function ic(t,e,r){for(var n=[{fixed:-1,stretch:0}],i=0,a=t;i<a.length;i+=1){var o=a[i],s=o[0],l=o[1],c=n[n.length-1];n.push({fixed:s-c.stretch,stretch:c.stretch}),n.push({fixed:s-c.stretch,stretch:c.stretch+(l-s)})}return n.push({fixed:e+1,stretch:r}),n}function ac(t,e,r,n){return t/e*r+n}function oc(t,e,r,n){return t-e*r/n}var sc=function(t,e,r,n,a,o,s,l,c,u){if(this.boxStartIndex=t.length,c){var f=o.top,h=o.bottom,p=o.collisionPadding;p&&(f-=p[1],h+=p[3]);var d=h-f;d>0&&(d=Math.max(10,d),this.circleDiameter=d)}else{var m=o.top*s-l,g=o.bottom*s+l,v=o.left*s-l,y=o.right*s+l,x=o.collisionPadding;if(x&&(v-=x[0]*s,m-=x[1]*s,y+=x[2]*s,g+=x[3]*s),u){var b=new i(v,m),_=new i(y,m),w=new i(v,g),T=new i(y,g),k=u*Math.PI/180;b._rotate(k),_._rotate(k),w._rotate(k),T._rotate(k),v=Math.min(b.x,_.x,w.x,T.x),y=Math.max(b.x,_.x,w.x,T.x),m=Math.min(b.y,_.y,w.y,T.y),g=Math.max(b.y,_.y,w.y,T.y)}t.emplaceBack(e.x,e.y,v,m,y,g,r,n,a)}this.boxEndIndex=t.length},lc=function(t,e){if(void 0===t&&(t=[]),void 0===e&&(e=cc),this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(var r=(this.length>>1)-1;r>=0;r--)this._down(r)};function cc(t,e){return t<e?-1:t>e?1:0}function uc(t,e,r){void 0===e&&(e=1),void 0===r&&(r=!1);for(var n=1/0,a=1/0,o=-1/0,s=-1/0,l=t[0],c=0;c<l.length;c++){var u=l[c];(!c||u.x<n)&&(n=u.x),(!c||u.y<a)&&(a=u.y),(!c||u.x>o)&&(o=u.x),(!c||u.y>s)&&(s=u.y)}var f=o-n,h=s-a,p=Math.min(f,h),d=p/2,m=new lc([],fc);if(0===p)return new i(n,a);for(var g=n;g<o;g+=p)for(var v=a;v<s;v+=p)m.push(new hc(g+d,v+d,d,t));for(var y=function(t){for(var e=0,r=0,n=0,i=t[0],a=0,o=i.length,s=o-1;a<o;s=a++){var l=i[a],c=i[s],u=l.x*c.y-c.x*l.y;r+=(l.x+c.x)*u,n+=(l.y+c.y)*u,e+=3*u}return new hc(r/e,n/e,0,t)}(t),x=m.length;m.length;){var b=m.pop();(b.d>y.d||!y.d)&&(y=b,r&&console.log("found best %d after %d probes",Math.round(1e4*b.d)/1e4,x)),b.max-y.d<=e||(d=b.h/2,m.push(new hc(b.p.x-d,b.p.y-d,d,t)),m.push(new hc(b.p.x+d,b.p.y-d,d,t)),m.push(new hc(b.p.x-d,b.p.y+d,d,t)),m.push(new hc(b.p.x+d,b.p.y+d,d,t)),x+=4)}return r&&(console.log("num probes: "+x),console.log("best distance: "+y.d)),y.p}function fc(t,e){return e.max-t.max}function hc(t,e,r,n){this.p=new i(t,e),this.h=r,this.d=function(t,e){for(var r=!1,n=1/0,i=0;i<e.length;i++)for(var a=e[i],o=0,s=a.length,l=s-1;o<s;l=o++){var c=a[o],u=a[l];c.y>t.y!=u.y>t.y&&t.x<(u.x-c.x)*(t.y-c.y)/(u.y-c.y)+c.x&&(r=!r),n=Math.min(n,ro(t,c,u))}return(r?1:-1)*Math.sqrt(n)}(this.p,n),this.max=this.d+this.h*Math.SQRT2}lc.prototype.push=function(t){this.data.push(t),this.length++,this._up(this.length-1)},lc.prototype.pop=function(){if(0!==this.length){var t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}},lc.prototype.peek=function(){return this.data[0]},lc.prototype._up=function(t){for(var e=this.data,r=this.compare,n=e[t];t>0;){var i=t-1>>1,a=e[i];if(r(n,a)>=0)break;e[t]=a,t=i}e[t]=n},lc.prototype._down=function(t){for(var e=this.data,r=this.compare,n=this.length>>1,i=e[t];t<n;){var a=1+(t<<1),o=e[a],s=a+1;if(s<this.length&&r(e[s],o)<0&&(a=s,o=e[s]),r(o,i)>=0)break;e[t]=o,t=a}e[t]=i};var pc=Number.POSITIVE_INFINITY;function dc(t,e){return e[1]!==pc?function(t,e,r){var n=0,i=0;switch(e=Math.abs(e),r=Math.abs(r),t){case"top-right":case"top-left":case"top":i=r-7;break;case"bottom-right":case"bottom-left":case"bottom":i=7-r}switch(t){case"top-right":case"bottom-right":case"right":n=-e;break;case"top-left":case"bottom-left":case"left":n=e}return[n,i]}(t,e[0],e[1]):function(t,e){var r=0,n=0;e<0&&(e=0);var i=e/Math.sqrt(2);switch(t){case"top-right":case"top-left":n=i-7;break;case"bottom-right":case"bottom-left":n=7-i;break;case"bottom":n=7-e;break;case"top":n=e-7}switch(t){case"top-right":case"bottom-right":r=-i;break;case"top-left":case"bottom-left":r=i;break;case"left":r=e;break;case"right":r=-e}return[r,n]}(t,e[0])}function mc(t){switch(t){case"right":case"top-right":case"bottom-right":return"right";case"left":case"top-left":case"bottom-left":return"left"}return"center"}function gc(t,e,r,n,a,o,s,l,c,u,f,h,p,d,m){var g=function(t,e,r,n,a,o,s,l){for(var c=n.layout.get("text-rotate").evaluate(o,{})*Math.PI/180,u=[],f=0,h=e.positionedLines;f<h.length;f+=1)for(var p=h[f],d=0,m=p.positionedGlyphs;d<m.length;d+=1){var g=m[d];if(g.rect){var v=g.rect||{},y=4,x=!0,b=1,_=0,w=(a||l)&&g.vertical,T=g.metrics.advance*g.scale/2;if(l&&e.verticalizable){var k=24*(g.scale-1),A=(24-g.metrics.width*g.scale)/2;_=p.lineOffset/2-(g.imageName?-A:k)}if(g.imageName){var M=s[g.imageName];x=M.sdf,y=1/(b=M.pixelRatio)}var S=a?[g.x+T,g.y]:[0,0],E=a?[0,0]:[g.x+T+r[0],g.y+r[1]-_],L=[0,0];w&&(L=E,E=[0,0]);var C=(g.metrics.left-y)*g.scale-T+E[0],P=(-g.metrics.top-y)*g.scale+E[1],I=C+v.w*g.scale/b,O=P+v.h*g.scale/b,z=new i(C,P),D=new i(I,P),R=new i(C,O),F=new i(I,O);if(w){var B=new i(-T,T- -17),N=-Math.PI/2,j=12-T,U=g.imageName?j:0,V=new i(22-j,-U),H=new(Function.prototype.bind.apply(i,[null].concat(L)));z._rotateAround(N,B)._add(V)._add(H),D._rotateAround(N,B)._add(V)._add(H),R._rotateAround(N,B)._add(V)._add(H),F._rotateAround(N,B)._add(V)._add(H)}if(c){var q=Math.sin(c),G=Math.cos(c),Y=[G,-q,q,G];z._matMult(Y),D._matMult(Y),R._matMult(Y),F._matMult(Y)}var W=new i(0,0),X=new i(0,0);u.push({tl:z,tr:D,bl:R,br:F,tex:v,writingMode:e.writingMode,glyphOffset:S,sectionIndex:g.sectionIndex,isSDF:x,pixelOffsetTL:W,pixelOffsetBR:X,minFontScaleX:0,minFontScaleY:0})}}return u}(0,r,l,a,o,s,n,t.allowVerticalPlacement),v=t.textSizeData,y=null;"source"===v.kind?(y=[128*a.layout.get("text-size").evaluate(s,{})])[0]>32640&&_(t.layerIds[0]+': Value for "text-size" is >= 255. Reduce your "text-size".'):"composite"===v.kind&&((y=[128*d.compositeTextSizes[0].evaluate(s,{},m),128*d.compositeTextSizes[1].evaluate(s,{},m)])[0]>32640||y[1]>32640)&&_(t.layerIds[0]+': Value for "text-size" is >= 255. Reduce your "text-size".'),t.addSymbols(t.text,g,y,l,o,s,u,e,c.lineStartIndex,c.lineLength,p,m);for(var x=0,b=f;x<b.length;x+=1){h[b[x]]=t.text.placedSymbolArray.length-1}return 4*g.length}function vc(t){for(var e in t)return t[e];return null}function yc(t,e,r,n){var i=t.compareText;if(e in i){for(var a=i[e],o=a.length-1;o>=0;o--)if(n.dist(a[o])<r)return!0}else i[e]=[];return i[e].push(n),!1}var xc=Ls.VectorTileFeature.types,bc=[{name:"a_fade_opacity",components:1,type:"Uint8",offset:0}];function _c(t,e,r,n,i,a,o,s,l,c,u,f,h){var p=s?Math.min(32640,Math.round(s[0])):0,d=s?Math.min(32640,Math.round(s[1])):0;t.emplaceBack(e,r,Math.round(32*n),Math.round(32*i),a,o,(p<<1)+(l?1:0),d,16*c,16*u,256*f,256*h)}function wc(t,e,r){t.emplaceBack(e.x,e.y,r),t.emplaceBack(e.x,e.y,r),t.emplaceBack(e.x,e.y,r),t.emplaceBack(e.x,e.y,r)}function Tc(t){for(var e=0,r=t.sections;e<r.length;e+=1){if($n(r[e].text))return!0}return!1}var kc=function(t){this.layoutVertexArray=new Ni,this.indexArray=new Yi,this.programConfigurations=t,this.segments=new pa,this.dynamicLayoutVertexArray=new ji,this.opacityVertexArray=new Ui,this.placedSymbolArray=new aa};kc.prototype.isEmpty=function(){return 0===this.layoutVertexArray.length&&0===this.indexArray.length&&0===this.dynamicLayoutVertexArray.length&&0===this.opacityVertexArray.length},kc.prototype.upload=function(t,e,r,n){this.isEmpty()||(r&&(this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,Js.members),this.indexBuffer=t.createIndexBuffer(this.indexArray,e),this.dynamicLayoutVertexBuffer=t.createVertexBuffer(this.dynamicLayoutVertexArray,Ks.members,!0),this.opacityVertexBuffer=t.createVertexBuffer(this.opacityVertexArray,bc,!0),this.opacityVertexBuffer.itemSize=1),(r||n)&&this.programConfigurations.upload(t))},kc.prototype.destroy=function(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.programConfigurations.destroy(),this.segments.destroy(),this.dynamicLayoutVertexBuffer.destroy(),this.opacityVertexBuffer.destroy())},Nn("SymbolBuffers",kc);var Ac=function(t,e,r){this.layoutVertexArray=new t,this.layoutAttributes=e,this.indexArray=new r,this.segments=new pa,this.collisionVertexArray=new Gi};Ac.prototype.upload=function(t){this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,this.layoutAttributes),this.indexBuffer=t.createIndexBuffer(this.indexArray),this.collisionVertexBuffer=t.createVertexBuffer(this.collisionVertexArray,Qs.members,!0)},Ac.prototype.destroy=function(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.segments.destroy(),this.collisionVertexBuffer.destroy())},Nn("CollisionBuffers",Ac);var Mc=function(t){this.collisionBoxArray=t.collisionBoxArray,this.zoom=t.zoom,this.overscaling=t.overscaling,this.layers=t.layers,this.layerIds=this.layers.map((function(t){return t.id})),this.index=t.index,this.pixelRatio=t.pixelRatio,this.sourceLayerIndex=t.sourceLayerIndex,this.hasPattern=!1,this.hasRTLText=!1,this.sortKeyRanges=[],this.collisionCircleArray=[],this.placementInvProjMatrix=ho([]),this.placementViewportMatrix=ho([]);var e=this.layers[0]._unevaluatedLayout._values;this.textSizeData=Gl(this.zoom,e["text-size"]),this.iconSizeData=Gl(this.zoom,e["icon-size"]);var r=this.layers[0].layout,n=r.get("symbol-sort-key"),i=r.get("symbol-z-order");this.sortFeaturesByKey="viewport-y"!==i&&void 0!==n.constantOr(1);var a="viewport-y"===i||"auto"===i&&!this.sortFeaturesByKey;this.sortFeaturesByY=a&&(r.get("text-allow-overlap")||r.get("icon-allow-overlap")||r.get("text-ignore-placement")||r.get("icon-ignore-placement")),"point"===r.get("symbol-placement")&&(this.writingModes=r.get("text-writing-mode").map((function(t){return Cl[t]}))),this.stateDependentLayerIds=this.layers.filter((function(t){return t.isStateDependent()})).map((function(t){return t.id})),this.sourceID=t.sourceID};Mc.prototype.createArrays=function(){this.text=new kc(new Ua(Js.members,this.layers,this.zoom,(function(t){return/^text/.test(t)}))),this.icon=new kc(new Ua(Js.members,this.layers,this.zoom,(function(t){return/^icon/.test(t)}))),this.glyphOffsetArray=new la,this.lineVertexArray=new ca,this.symbolInstances=new sa},Mc.prototype.calculateGlyphDependencies=function(t,e,r,n,i){for(var a=0;a<t.length;a++)if(e[t.charCodeAt(a)]=!0,(r||n)&&i){var o=rl[t.charAt(a)];o&&(e[o.charCodeAt(0)]=!0)}},Mc.prototype.populate=function(t,e,r){var n=this.layers[0],i=n.layout,a=i.get("text-font"),o=i.get("text-field"),s=i.get("icon-image"),l=("constant"!==o.value.kind||o.value.value instanceof ne&&!o.value.value.isEmpty()||o.value.value.toString().length>0)&&("constant"!==a.value.kind||a.value.value.length>0),c="constant"!==s.value.kind||!!s.value.value||Object.keys(s.parameters).length>0,u=i.get("symbol-sort-key");if(this.features=[],l||c){for(var f=e.iconDependencies,h=e.glyphDependencies,p=e.availableImages,d=new pi(this.zoom),m=0,g=t;m<g.length;m+=1){var v=g[m],y=v.feature,x=v.id,b=v.index,_=v.sourceLayerIndex,w=n._featureFilter.needGeometry,T={type:y.type,id:x,properties:y.properties,geometry:w?Ya(y):[]};if(n._featureFilter.filter(d,T,r)){w||(T.geometry=Ya(y));var k=void 0;if(l){var A=n.getValueAndResolveTokens("text-field",T,r,p),M=ne.factory(A);Tc(M)&&(this.hasRTLText=!0),(!this.hasRTLText||"unavailable"===ui()||this.hasRTLText&&hi.isParsed())&&(k=el(M,n,T))}var S=void 0;if(c){var E=n.getValueAndResolveTokens("icon-image",T,r,p);S=E instanceof ie?E:ie.fromString(E)}if(k||S){var L=this.sortFeaturesByKey?u.evaluate(T,{},r):void 0,C={id:x,text:k,icon:S,index:b,sourceLayerIndex:_,geometry:Ya(y),properties:y.properties,type:xc[y.type],sortKey:L};if(this.features.push(C),S&&(f[S.name]=!0),k){var P=a.evaluate(T,{},r).join(","),I="map"===i.get("text-rotation-alignment")&&"point"!==i.get("symbol-placement");this.allowVerticalPlacement=this.writingModes&&this.writingModes.indexOf(Cl.vertical)>=0;for(var O=0,z=k.sections;O<z.length;O+=1){var D=z[O];if(D.image)f[D.image.name]=!0;else{var R=Wn(k.toString()),F=D.fontStack||P,B=h[F]=h[F]||{};this.calculateGlyphDependencies(D.text,B,I,this.allowVerticalPlacement,R)}}}}}}"line"===i.get("symbol-placement")&&(this.features=function(t){var e={},r={},n=[],i=0;function a(e){n.push(t[e]),i++}function o(t,e,i){var a=r[t];return delete r[t],r[e]=a,n[a].geometry[0].pop(),n[a].geometry[0]=n[a].geometry[0].concat(i[0]),a}function s(t,r,i){var a=e[r];return delete e[r],e[t]=a,n[a].geometry[0].shift(),n[a].geometry[0]=i[0].concat(n[a].geometry[0]),a}function l(t,e,r){var n=r?e[0][e[0].length-1]:e[0][0];return t+":"+n.x+":"+n.y}for(var c=0;c<t.length;c++){var u=t[c],f=u.geometry,h=u.text?u.text.toString():null;if(h){var p=l(h,f),d=l(h,f,!0);if(p in r&&d in e&&r[p]!==e[d]){var m=s(p,d,f),g=o(p,d,n[m].geometry);delete e[p],delete r[d],r[l(h,n[g].geometry,!0)]=g,n[m].geometry=null}else p in r?o(p,d,f):d in e?s(p,d,f):(a(c),e[p]=i-1,r[d]=i-1)}else a(c)}return n.filter((function(t){return t.geometry}))}(this.features)),this.sortFeaturesByKey&&this.features.sort((function(t,e){return t.sortKey-e.sortKey}))}},Mc.prototype.update=function(t,e,r){this.stateDependentLayers.length&&(this.text.programConfigurations.updatePaintArrays(t,e,this.layers,r),this.icon.programConfigurations.updatePaintArrays(t,e,this.layers,r))},Mc.prototype.isEmpty=function(){return 0===this.symbolInstances.length&&!this.hasRTLText},Mc.prototype.uploadPending=function(){return!this.uploaded||this.text.programConfigurations.needsUpload||this.icon.programConfigurations.needsUpload},Mc.prototype.upload=function(t){!this.uploaded&&this.hasDebugData()&&(this.textCollisionBox.upload(t),this.iconCollisionBox.upload(t)),this.text.upload(t,this.sortFeaturesByY,!this.uploaded,this.text.programConfigurations.needsUpload),this.icon.upload(t,this.sortFeaturesByY,!this.uploaded,this.icon.programConfigurations.needsUpload),this.uploaded=!0},Mc.prototype.destroyDebugData=function(){this.textCollisionBox.destroy(),this.iconCollisionBox.destroy()},Mc.prototype.destroy=function(){this.text.destroy(),this.icon.destroy(),this.hasDebugData()&&this.destroyDebugData()},Mc.prototype.addToLineVertexArray=function(t,e){var r=this.lineVertexArray.length;if(void 0!==t.segment){for(var n=t.dist(e[t.segment+1]),i=t.dist(e[t.segment]),a={},o=t.segment+1;o<e.length;o++)a[o]={x:e[o].x,y:e[o].y,tileUnitDistanceFromAnchor:n},o<e.length-1&&(n+=e[o+1].dist(e[o]));for(var s=t.segment||0;s>=0;s--)a[s]={x:e[s].x,y:e[s].y,tileUnitDistanceFromAnchor:i},s>0&&(i+=e[s-1].dist(e[s]));for(var l=0;l<e.length;l++){var c=a[l];this.lineVertexArray.emplaceBack(c.x,c.y,c.tileUnitDistanceFromAnchor)}}return{lineStartIndex:r,lineLength:this.lineVertexArray.length-r}},Mc.prototype.addSymbols=function(t,e,r,n,i,a,o,s,l,c,u,f){for(var h=t.indexArray,p=t.layoutVertexArray,d=t.segments.prepareSegment(4*e.length,p,h,a.sortKey),m=this.glyphOffsetArray.length,g=d.vertexLength,v=this.allowVerticalPlacement&&o===Cl.vertical?Math.PI/2:0,y=a.text&&a.text.sections,x=0;x<e.length;x++){var b=e[x],_=b.tl,w=b.tr,T=b.bl,k=b.br,A=b.tex,M=b.pixelOffsetTL,S=b.pixelOffsetBR,E=b.minFontScaleX,L=b.minFontScaleY,C=b.glyphOffset,P=b.isSDF,I=b.sectionIndex,O=d.vertexLength,z=C[1];_c(p,s.x,s.y,_.x,z+_.y,A.x,A.y,r,P,M.x,M.y,E,L),_c(p,s.x,s.y,w.x,z+w.y,A.x+A.w,A.y,r,P,S.x,M.y,E,L),_c(p,s.x,s.y,T.x,z+T.y,A.x,A.y+A.h,r,P,M.x,S.y,E,L),_c(p,s.x,s.y,k.x,z+k.y,A.x+A.w,A.y+A.h,r,P,S.x,S.y,E,L),wc(t.dynamicLayoutVertexArray,s,v),h.emplaceBack(O,O+1,O+2),h.emplaceBack(O+1,O+2,O+3),d.vertexLength+=4,d.primitiveLength+=2,this.glyphOffsetArray.emplaceBack(C[0]),x!==e.length-1&&I===e[x+1].sectionIndex||t.programConfigurations.populatePaintArrays(p.length,a,a.index,{},f,y&&y[I])}t.placedSymbolArray.emplaceBack(s.x,s.y,m,this.glyphOffsetArray.length-m,g,l,c,s.segment,r?r[0]:0,r?r[1]:0,n[0],n[1],o,0,!1,0,u)},Mc.prototype._addCollisionDebugVertex=function(t,e,r,n,i,a){return e.emplaceBack(0,0),t.emplaceBack(r.x,r.y,n,i,Math.round(a.x),Math.round(a.y))},Mc.prototype.addCollisionDebugVertices=function(t,e,r,n,a,o,s){var l=a.segments.prepareSegment(4,a.layoutVertexArray,a.indexArray),c=l.vertexLength,u=a.layoutVertexArray,f=a.collisionVertexArray,h=s.anchorX,p=s.anchorY;this._addCollisionDebugVertex(u,f,o,h,p,new i(t,e)),this._addCollisionDebugVertex(u,f,o,h,p,new i(r,e)),this._addCollisionDebugVertex(u,f,o,h,p,new i(r,n)),this._addCollisionDebugVertex(u,f,o,h,p,new i(t,n)),l.vertexLength+=4;var d=a.indexArray;d.emplaceBack(c,c+1),d.emplaceBack(c+1,c+2),d.emplaceBack(c+2,c+3),d.emplaceBack(c+3,c),l.primitiveLength+=4},Mc.prototype.addDebugCollisionBoxes=function(t,e,r,n){for(var i=t;i<e;i++){var a=this.collisionBoxArray.get(i),o=a.x1,s=a.y1,l=a.x2,c=a.y2;this.addCollisionDebugVertices(o,s,l,c,n?this.textCollisionBox:this.iconCollisionBox,a.anchorPoint,r)}},Mc.prototype.generateCollisionDebugBuffers=function(){this.hasDebugData()&&this.destroyDebugData(),this.textCollisionBox=new Ac(Hi,$s.members,Qi),this.iconCollisionBox=new Ac(Hi,$s.members,Qi);for(var t=0;t<this.symbolInstances.length;t++){var e=this.symbolInstances.get(t);this.addDebugCollisionBoxes(e.textBoxStartIndex,e.textBoxEndIndex,e,!0),this.addDebugCollisionBoxes(e.verticalTextBoxStartIndex,e.verticalTextBoxEndIndex,e,!0),this.addDebugCollisionBoxes(e.iconBoxStartIndex,e.iconBoxEndIndex,e,!1),this.addDebugCollisionBoxes(e.verticalIconBoxStartIndex,e.verticalIconBoxEndIndex,e,!1)}},Mc.prototype._deserializeCollisionBoxesForSymbol=function(t,e,r,n,i,a,o,s,l){for(var c={},u=e;u<r;u++){var f=t.get(u);c.textBox={x1:f.x1,y1:f.y1,x2:f.x2,y2:f.y2,anchorPointX:f.anchorPointX,anchorPointY:f.anchorPointY},c.textFeatureIndex=f.featureIndex;break}for(var h=n;h<i;h++){var p=t.get(h);c.verticalTextBox={x1:p.x1,y1:p.y1,x2:p.x2,y2:p.y2,anchorPointX:p.anchorPointX,anchorPointY:p.anchorPointY},c.verticalTextFeatureIndex=p.featureIndex;break}for(var d=a;d<o;d++){var m=t.get(d);c.iconBox={x1:m.x1,y1:m.y1,x2:m.x2,y2:m.y2,anchorPointX:m.anchorPointX,anchorPointY:m.anchorPointY},c.iconFeatureIndex=m.featureIndex;break}for(var g=s;g<l;g++){var v=t.get(g);c.verticalIconBox={x1:v.x1,y1:v.y1,x2:v.x2,y2:v.y2,anchorPointX:v.anchorPointX,anchorPointY:v.anchorPointY},c.verticalIconFeatureIndex=v.featureIndex;break}return c},Mc.prototype.deserializeCollisionBoxes=function(t){this.collisionArrays=[];for(var e=0;e<this.symbolInstances.length;e++){var r=this.symbolInstances.get(e);this.collisionArrays.push(this._deserializeCollisionBoxesForSymbol(t,r.textBoxStartIndex,r.textBoxEndIndex,r.verticalTextBoxStartIndex,r.verticalTextBoxEndIndex,r.iconBoxStartIndex,r.iconBoxEndIndex,r.verticalIconBoxStartIndex,r.verticalIconBoxEndIndex))}},Mc.prototype.hasTextData=function(){return this.text.segments.get().length>0},Mc.prototype.hasIconData=function(){return this.icon.segments.get().length>0},Mc.prototype.hasDebugData=function(){return this.textCollisionBox&&this.iconCollisionBox},Mc.prototype.hasTextCollisionBoxData=function(){return this.hasDebugData()&&this.textCollisionBox.segments.get().length>0},Mc.prototype.hasIconCollisionBoxData=function(){return this.hasDebugData()&&this.iconCollisionBox.segments.get().length>0},Mc.prototype.addIndicesForPlacedSymbol=function(t,e){for(var r=t.placedSymbolArray.get(e),n=r.vertexStartIndex+4*r.numGlyphs,i=r.vertexStartIndex;i<n;i+=4)t.indexArray.emplaceBack(i,i+1,i+2),t.indexArray.emplaceBack(i+1,i+2,i+3)},Mc.prototype.getSortedSymbolIndexes=function(t){if(this.sortedAngle===t&&void 0!==this.symbolInstanceIndexes)return this.symbolInstanceIndexes;for(var e=Math.sin(t),r=Math.cos(t),n=[],i=[],a=[],o=0;o<this.symbolInstances.length;++o){a.push(o);var s=this.symbolInstances.get(o);n.push(0|Math.round(e*s.anchorX+r*s.anchorY)),i.push(s.featureIndex)}return a.sort((function(t,e){return n[t]-n[e]||i[e]-i[t]})),a},Mc.prototype.addToSortKeyRanges=function(t,e){var r=this.sortKeyRanges[this.sortKeyRanges.length-1];r&&r.sortKey===e?r.symbolInstanceEnd=t+1:this.sortKeyRanges.push({sortKey:e,symbolInstanceStart:t,symbolInstanceEnd:t+1})},Mc.prototype.sortFeatures=function(t){var e=this;if(this.sortFeaturesByY&&this.sortedAngle!==t&&!(this.text.segments.get().length>1||this.icon.segments.get().length>1)){this.symbolInstanceIndexes=this.getSortedSymbolIndexes(t),this.sortedAngle=t,this.text.indexArray.clear(),this.icon.indexArray.clear(),this.featureSortOrder=[];for(var r=0,n=this.symbolInstanceIndexes;r<n.length;r+=1){var i=n[r],a=this.symbolInstances.get(i);this.featureSortOrder.push(a.featureIndex),[a.rightJustifiedTextSymbolIndex,a.centerJustifiedTextSymbolIndex,a.leftJustifiedTextSymbolIndex].forEach((function(t,r,n){t>=0&&n.indexOf(t)===r&&e.addIndicesForPlacedSymbol(e.text,t)})),a.verticalPlacedTextSymbolIndex>=0&&this.addIndicesForPlacedSymbol(this.text,a.verticalPlacedTextSymbolIndex),a.placedIconSymbolIndex>=0&&this.addIndicesForPlacedSymbol(this.icon,a.placedIconSymbolIndex),a.verticalPlacedIconSymbolIndex>=0&&this.addIndicesForPlacedSymbol(this.icon,a.verticalPlacedIconSymbolIndex)}this.text.indexBuffer&&this.text.indexBuffer.updateData(this.text.indexArray),this.icon.indexBuffer&&this.icon.indexBuffer.updateData(this.icon.indexArray)}},Nn("SymbolBucket",Mc,{omit:["layers","collisionBoxArray","features","compareText"]}),Mc.MAX_GLYPHS=65535,Mc.addDynamicAttributes=wc;var Sc=new Si({"symbol-placement":new wi(Lt.layout_symbol["symbol-placement"]),"symbol-spacing":new wi(Lt.layout_symbol["symbol-spacing"]),"symbol-avoid-edges":new wi(Lt.layout_symbol["symbol-avoid-edges"]),"symbol-sort-key":new Ti(Lt.layout_symbol["symbol-sort-key"]),"symbol-z-order":new wi(Lt.layout_symbol["symbol-z-order"]),"icon-allow-overlap":new wi(Lt.layout_symbol["icon-allow-overlap"]),"icon-ignore-placement":new wi(Lt.layout_symbol["icon-ignore-placement"]),"icon-optional":new wi(Lt.layout_symbol["icon-optional"]),"icon-rotation-alignment":new wi(Lt.layout_symbol["icon-rotation-alignment"]),"icon-size":new Ti(Lt.layout_symbol["icon-size"]),"icon-text-fit":new wi(Lt.layout_symbol["icon-text-fit"]),"icon-text-fit-padding":new wi(Lt.layout_symbol["icon-text-fit-padding"]),"icon-image":new Ti(Lt.layout_symbol["icon-image"]),"icon-rotate":new Ti(Lt.layout_symbol["icon-rotate"]),"icon-padding":new wi(Lt.layout_symbol["icon-padding"]),"icon-keep-upright":new wi(Lt.layout_symbol["icon-keep-upright"]),"icon-offset":new Ti(Lt.layout_symbol["icon-offset"]),"icon-anchor":new Ti(Lt.layout_symbol["icon-anchor"]),"icon-pitch-alignment":new wi(Lt.layout_symbol["icon-pitch-alignment"]),"text-pitch-alignment":new wi(Lt.layout_symbol["text-pitch-alignment"]),"text-rotation-alignment":new wi(Lt.layout_symbol["text-rotation-alignment"]),"text-field":new Ti(Lt.layout_symbol["text-field"]),"text-font":new Ti(Lt.layout_symbol["text-font"]),"text-size":new Ti(Lt.layout_symbol["text-size"]),"text-max-width":new Ti(Lt.layout_symbol["text-max-width"]),"text-line-height":new wi(Lt.layout_symbol["text-line-height"]),"text-letter-spacing":new Ti(Lt.layout_symbol["text-letter-spacing"]),"text-justify":new Ti(Lt.layout_symbol["text-justify"]),"text-radial-offset":new Ti(Lt.layout_symbol["text-radial-offset"]),"text-variable-anchor":new wi(Lt.layout_symbol["text-variable-anchor"]),"text-anchor":new Ti(Lt.layout_symbol["text-anchor"]),"text-max-angle":new wi(Lt.layout_symbol["text-max-angle"]),"text-writing-mode":new wi(Lt.layout_symbol["text-writing-mode"]),"text-rotate":new Ti(Lt.layout_symbol["text-rotate"]),"text-padding":new wi(Lt.layout_symbol["text-padding"]),"text-keep-upright":new wi(Lt.layout_symbol["text-keep-upright"]),"text-transform":new Ti(Lt.layout_symbol["text-transform"]),"text-offset":new Ti(Lt.layout_symbol["text-offset"]),"text-allow-overlap":new wi(Lt.layout_symbol["text-allow-overlap"]),"text-ignore-placement":new wi(Lt.layout_symbol["text-ignore-placement"]),"text-optional":new wi(Lt.layout_symbol["text-optional"])}),Ec={paint:new Si({"icon-opacity":new Ti(Lt.paint_symbol["icon-opacity"]),"icon-color":new Ti(Lt.paint_symbol["icon-color"]),"icon-halo-color":new Ti(Lt.paint_symbol["icon-halo-color"]),"icon-halo-width":new Ti(Lt.paint_symbol["icon-halo-width"]),"icon-halo-blur":new Ti(Lt.paint_symbol["icon-halo-blur"]),"icon-translate":new wi(Lt.paint_symbol["icon-translate"]),"icon-translate-anchor":new wi(Lt.paint_symbol["icon-translate-anchor"]),"text-opacity":new Ti(Lt.paint_symbol["text-opacity"]),"text-color":new Ti(Lt.paint_symbol["text-color"],{runtimeType:Ut,getOverride:function(t){return t.textColor},hasOverride:function(t){return!!t.textColor}}),"text-halo-color":new Ti(Lt.paint_symbol["text-halo-color"]),"text-halo-width":new Ti(Lt.paint_symbol["text-halo-width"]),"text-halo-blur":new Ti(Lt.paint_symbol["text-halo-blur"]),"text-translate":new wi(Lt.paint_symbol["text-translate"]),"text-translate-anchor":new wi(Lt.paint_symbol["text-translate-anchor"])}),layout:Sc},Lc=function(t){this.type=t.property.overrides?t.property.overrides.runtimeType:Ft,this.defaultValue=t};Lc.prototype.evaluate=function(t){if(t.formattedSection){var e=this.defaultValue.property.overrides;if(e&&e.hasOverride(t.formattedSection))return e.getOverride(t.formattedSection)}return t.feature&&t.featureState?this.defaultValue.evaluate(t.feature,t.featureState):this.defaultValue.property.specification.default},Lc.prototype.eachChild=function(t){this.defaultValue.isConstant()||t(this.defaultValue.value._styleExpression.expression)},Lc.prototype.outputDefined=function(){return!1},Lc.prototype.serialize=function(){return null},Nn("FormatSectionOverride",Lc,{omit:["defaultValue"]});var Cc=function(t){function e(e){t.call(this,e,Ec)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.recalculate=function(e,r){if(t.prototype.recalculate.call(this,e,r),"auto"===this.layout.get("icon-rotation-alignment")&&("point"!==this.layout.get("symbol-placement")?this.layout._values["icon-rotation-alignment"]="map":this.layout._values["icon-rotation-alignment"]="viewport"),"auto"===this.layout.get("text-rotation-alignment")&&("point"!==this.layout.get("symbol-placement")?this.layout._values["text-rotation-alignment"]="map":this.layout._values["text-rotation-alignment"]="viewport"),"auto"===this.layout.get("text-pitch-alignment")&&(this.layout._values["text-pitch-alignment"]=this.layout.get("text-rotation-alignment")),"auto"===this.layout.get("icon-pitch-alignment")&&(this.layout._values["icon-pitch-alignment"]=this.layout.get("icon-rotation-alignment")),"point"===this.layout.get("symbol-placement")){var n=this.layout.get("text-writing-mode");if(n){for(var i=[],a=0,o=n;a<o.length;a+=1){var s=o[a];i.indexOf(s)<0&&i.push(s)}this.layout._values["text-writing-mode"]=i}else this.layout._values["text-writing-mode"]=["horizontal"]}this._setPaintOverrides()},e.prototype.getValueAndResolveTokens=function(t,e,r,n){var i=this.layout.get(t).evaluate(e,{},r,n),a=this._unevaluatedLayout._values[t];return a.isDataDriven()||Yr(a.value)||!i?i:function(t,e){return e.replace(/{([^{}]+)}/g,(function(e,r){return r in t?String(t[r]):""}))}(e.properties,i)},e.prototype.createBucket=function(t){return new Mc(t)},e.prototype.queryRadius=function(){return 0},e.prototype.queryIntersectsFeature=function(){return!1},e.prototype._setPaintOverrides=function(){for(var t=0,r=Ec.paint.overridableProperties;t<r.length;t+=1){var n=r[t];if(e.hasPaintOverride(this.layout,n)){var i=this.paint.get(n),a=new Lc(i),o=new Gr(a,i.property.specification),s=null;s="constant"===i.value.kind||"source"===i.value.kind?new Xr("source",o):new Zr("composite",o,i.value.zoomStops,i.value._interpolationType),this.paint._values[n]=new bi(i.property,s,i.parameters)}}},e.prototype._handleOverridablePaintPropertyUpdate=function(t,r,n){return!(!this.layout||r.isDataDriven()||n.isDataDriven())&&e.hasPaintOverride(this.layout,t)},e.hasPaintOverride=function(t,e){var r=t.get("text-field"),n=Ec.paint.properties[e],i=!1,a=function(t){for(var e=0,r=t;e<r.length;e+=1){var a=r[e];if(n.overrides&&n.overrides.hasOverride(a))return void(i=!0)}};if("constant"===r.value.kind&&r.value.value instanceof ne)a(r.value.value.sections);else if("source"===r.value.kind){var o=function(t){if(!i)if(t instanceof ce&&se(t.value)===Gt){var e=t.value;a(e.sections)}else t instanceof pe?a(t.sections):t.eachChild(o)},s=r.value;s._styleExpression&&o(s._styleExpression.expression)}return i},e}(Ei),Pc={paint:new Si({"background-color":new wi(Lt.paint_background["background-color"]),"background-pattern":new Ai(Lt.paint_background["background-pattern"]),"background-opacity":new wi(Lt.paint_background["background-opacity"])})},Ic=function(t){function e(e){t.call(this,e,Pc)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Ei),Oc={paint:new Si({"raster-opacity":new wi(Lt.paint_raster["raster-opacity"]),"raster-hue-rotate":new wi(Lt.paint_raster["raster-hue-rotate"]),"raster-brightness-min":new wi(Lt.paint_raster["raster-brightness-min"]),"raster-brightness-max":new wi(Lt.paint_raster["raster-brightness-max"]),"raster-saturation":new wi(Lt.paint_raster["raster-saturation"]),"raster-contrast":new wi(Lt.paint_raster["raster-contrast"]),"raster-resampling":new wi(Lt.paint_raster["raster-resampling"]),"raster-fade-duration":new wi(Lt.paint_raster["raster-fade-duration"])})},zc=function(t){function e(e){t.call(this,e,Oc)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Ei);var Dc=function(t){function e(e){t.call(this,e,{}),this.implementation=e}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.is3D=function(){return"3d"===this.implementation.renderingMode},e.prototype.hasOffscreenPass=function(){return void 0!==this.implementation.prerender},e.prototype.recalculate=function(){},e.prototype.updateTransitions=function(){},e.prototype.hasTransition=function(){},e.prototype.serialize=function(){},e.prototype.onAdd=function(t){this.implementation.onAdd&&this.implementation.onAdd(t,t.painter.context.gl)},e.prototype.onRemove=function(t){this.implementation.onRemove&&this.implementation.onRemove(t,t.painter.context.gl)},e}(Ei),Rc={circle:_o,heatmap:Po,hillshade:Oo,fill:xs,"fill-extrusion":Fs,line:Xs,symbol:Cc,background:Ic,raster:zc};var Fc=self.HTMLImageElement,Bc=self.HTMLCanvasElement,Nc=self.HTMLVideoElement,jc=self.ImageData,Uc=self.ImageBitmap,Vc=function(t,e,r,n){this.context=t,this.format=r,this.texture=t.gl.createTexture(),this.update(e,n)};Vc.prototype.update=function(t,e,r){var n=t.width,i=t.height,a=!(this.size&&this.size[0]===n&&this.size[1]===i||r),o=this.context,s=o.gl;if(this.useMipmap=Boolean(e&&e.useMipmap),s.bindTexture(s.TEXTURE_2D,this.texture),o.pixelStoreUnpackFlipY.set(!1),o.pixelStoreUnpack.set(1),o.pixelStoreUnpackPremultiplyAlpha.set(this.format===s.RGBA&&(!e||!1!==e.premultiply)),a)this.size=[n,i],t instanceof Fc||t instanceof Bc||t instanceof Nc||t instanceof jc||Uc&&t instanceof Uc?s.texImage2D(s.TEXTURE_2D,0,this.format,this.format,s.UNSIGNED_BYTE,t):s.texImage2D(s.TEXTURE_2D,0,this.format,n,i,0,this.format,s.UNSIGNED_BYTE,t.data);else{var l=r||{x:0,y:0},c=l.x,u=l.y;t instanceof Fc||t instanceof Bc||t instanceof Nc||t instanceof jc||Uc&&t instanceof Uc?s.texSubImage2D(s.TEXTURE_2D,0,c,u,s.RGBA,s.UNSIGNED_BYTE,t):s.texSubImage2D(s.TEXTURE_2D,0,c,u,n,i,s.RGBA,s.UNSIGNED_BYTE,t.data)}this.useMipmap&&this.isSizePowerOfTwo()&&s.generateMipmap(s.TEXTURE_2D)},Vc.prototype.bind=function(t,e,r){var n=this.context.gl;n.bindTexture(n.TEXTURE_2D,this.texture),r!==n.LINEAR_MIPMAP_NEAREST||this.isSizePowerOfTwo()||(r=n.LINEAR),t!==this.filter&&(n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,t),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,r||t),this.filter=t),e!==this.wrap&&(n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,e),this.wrap=e)},Vc.prototype.isSizePowerOfTwo=function(){return this.size[0]===this.size[1]&&Math.log(this.size[0])/Math.LN2%1==0},Vc.prototype.destroy=function(){this.context.gl.deleteTexture(this.texture),this.texture=null};var Hc=function(t){var e=this;this._callback=t,this._triggered=!1,"undefined"!=typeof MessageChannel&&(this._channel=new MessageChannel,this._channel.port2.onmessage=function(){e._triggered=!1,e._callback()})};Hc.prototype.trigger=function(){var t=this;this._triggered||(this._triggered=!0,this._channel?this._channel.port1.postMessage(!0):setTimeout((function(){t._triggered=!1,t._callback()}),0))},Hc.prototype.remove=function(){delete this._channel,this._callback=function(){}};var qc=function(t,e,r){this.target=t,this.parent=e,this.mapId=r,this.callbacks={},this.tasks={},this.taskQueue=[],this.cancelCallbacks={},m(["receive","process"],this),this.invoker=new Hc(this.process),this.target.addEventListener("message",this.receive,!1),this.globalScope=k()?t:self};function Gc(t,e,r){var n=2*Math.PI*6378137/256/Math.pow(2,r);return[t*n-2*Math.PI*6378137/2,e*n-2*Math.PI*6378137/2]}qc.prototype.send=function(t,e,r,n,i){var a=this;void 0===i&&(i=!1);var o=Math.round(1e18*Math.random()).toString(36).substring(0,10);r&&(this.callbacks[o]=r);var s=S(this.globalScope)?void 0:[];return this.target.postMessage({id:o,type:t,hasCallback:!!r,targetMapId:n,mustQueue:i,sourceMapId:this.mapId,data:Hn(e,s)},s),{cancel:function(){r&&delete a.callbacks[o],a.target.postMessage({id:o,type:"<cancel>",targetMapId:n,sourceMapId:a.mapId})}}},qc.prototype.receive=function(t){var e=t.data,r=e.id;if(r&&(!e.targetMapId||this.mapId===e.targetMapId))if("<cancel>"===e.type){delete this.tasks[r];var n=this.cancelCallbacks[r];delete this.cancelCallbacks[r],n&&n()}else k()||e.mustQueue?(this.tasks[r]=e,this.taskQueue.push(r),this.invoker.trigger()):this.processTask(r,e)},qc.prototype.process=function(){if(this.taskQueue.length){var t=this.taskQueue.shift(),e=this.tasks[t];delete this.tasks[t],this.taskQueue.length&&this.invoker.trigger(),e&&this.processTask(t,e)}},qc.prototype.processTask=function(t,e){var r=this;if("<response>"===e.type){var n=this.callbacks[t];delete this.callbacks[t],n&&(e.error?n(qn(e.error)):n(null,qn(e.data)))}else{var i=!1,a=S(this.globalScope)?void 0:[],o=e.hasCallback?function(e,n){i=!0,delete r.cancelCallbacks[t],r.target.postMessage({id:t,type:"<response>",sourceMapId:r.mapId,error:e?Hn(e):null,data:Hn(n,a)},a)}:function(t){i=!0},s=null,l=qn(e.data);if(this.parent[e.type])s=this.parent[e.type](e.sourceMapId,l,o);else if(this.parent.getWorkerSource){var c=e.type.split(".");s=this.parent.getWorkerSource(e.sourceMapId,c[0],l.source)[c[1]](l,o)}else o(new Error("Could not find function "+e.type));!i&&s&&s.cancel&&(this.cancelCallbacks[t]=s.cancel)}},qc.prototype.remove=function(){this.invoker.remove(),this.target.removeEventListener("message",this.receive,!1)};var Yc=function(t,e){t&&(e?this.setSouthWest(t).setNorthEast(e):4===t.length?this.setSouthWest([t[0],t[1]]).setNorthEast([t[2],t[3]]):this.setSouthWest(t[0]).setNorthEast(t[1]))};Yc.prototype.setNorthEast=function(t){return this._ne=t instanceof Wc?new Wc(t.lng,t.lat):Wc.convert(t),this},Yc.prototype.setSouthWest=function(t){return this._sw=t instanceof Wc?new Wc(t.lng,t.lat):Wc.convert(t),this},Yc.prototype.extend=function(t){var e,r,n=this._sw,i=this._ne;if(t instanceof Wc)e=t,r=t;else{if(!(t instanceof Yc)){if(Array.isArray(t)){if(4===t.length||t.every(Array.isArray)){var a=t;return this.extend(Yc.convert(a))}var o=t;return this.extend(Wc.convert(o))}return this}if(e=t._sw,r=t._ne,!e||!r)return this}return n||i?(n.lng=Math.min(e.lng,n.lng),n.lat=Math.min(e.lat,n.lat),i.lng=Math.max(r.lng,i.lng),i.lat=Math.max(r.lat,i.lat)):(this._sw=new Wc(e.lng,e.lat),this._ne=new Wc(r.lng,r.lat)),this},Yc.prototype.getCenter=function(){return new Wc((this._sw.lng+this._ne.lng)/2,(this._sw.lat+this._ne.lat)/2)},Yc.prototype.getSouthWest=function(){return this._sw},Yc.prototype.getNorthEast=function(){return this._ne},Yc.prototype.getNorthWest=function(){return new Wc(this.getWest(),this.getNorth())},Yc.prototype.getSouthEast=function(){return new Wc(this.getEast(),this.getSouth())},Yc.prototype.getWest=function(){return this._sw.lng},Yc.prototype.getSouth=function(){return this._sw.lat},Yc.prototype.getEast=function(){return this._ne.lng},Yc.prototype.getNorth=function(){return this._ne.lat},Yc.prototype.toArray=function(){return[this._sw.toArray(),this._ne.toArray()]},Yc.prototype.toString=function(){return"LngLatBounds("+this._sw.toString()+", "+this._ne.toString()+")"},Yc.prototype.isEmpty=function(){return!(this._sw&&this._ne)},Yc.prototype.contains=function(t){var e=Wc.convert(t),r=e.lng,n=e.lat,i=this._sw.lat<=n&&n<=this._ne.lat,a=this._sw.lng<=r&&r<=this._ne.lng;return this._sw.lng>this._ne.lng&&(a=this._sw.lng>=r&&r>=this._ne.lng),i&&a},Yc.convert=function(t){return!t||t instanceof Yc?t:new Yc(t)};var Wc=function(t,e){if(isNaN(t)||isNaN(e))throw new Error("Invalid LngLat object: ("+t+", "+e+")");if(this.lng=+t,this.lat=+e,this.lat>90||this.lat<-90)throw new Error("Invalid LngLat latitude value: must be between -90 and 90")};Wc.prototype.wrap=function(){return new Wc(c(this.lng,-180,180),this.lat)},Wc.prototype.toArray=function(){return[this.lng,this.lat]},Wc.prototype.toString=function(){return"LngLat("+this.lng+", "+this.lat+")"},Wc.prototype.distanceTo=function(t){var e=Math.PI/180,r=this.lat*e,n=t.lat*e,i=Math.sin(r)*Math.sin(n)+Math.cos(r)*Math.cos(n)*Math.cos((t.lng-this.lng)*e);return 6371008.8*Math.acos(Math.min(i,1))},Wc.prototype.toBounds=function(t){void 0===t&&(t=0);var e=360*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return new Yc(new Wc(this.lng-r,this.lat-e),new Wc(this.lng+r,this.lat+e))},Wc.convert=function(t){if(t instanceof Wc)return t;if(Array.isArray(t)&&(2===t.length||3===t.length))return new Wc(Number(t[0]),Number(t[1]));if(!Array.isArray(t)&&"object"==typeof t&&null!==t)return new Wc(Number("lng"in t?t.lng:t.lon),Number(t.lat));throw new Error("`LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]")};var Xc=2*Math.PI*6371008.8;function Zc(t){return Xc*Math.cos(t*Math.PI/180)}function Jc(t){return(180+t)/360}function Kc(t){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+t*Math.PI/360)))/360}function Qc(t,e){return t/Zc(e)}function $c(t){var e=180-360*t;return 360/Math.PI*Math.atan(Math.exp(e*Math.PI/180))-90}var tu=function(t,e,r){void 0===r&&(r=0),this.x=+t,this.y=+e,this.z=+r};tu.fromLngLat=function(t,e){void 0===e&&(e=0);var r=Wc.convert(t);return new tu(Jc(r.lng),Kc(r.lat),Qc(e,r.lat))},tu.prototype.toLngLat=function(){return new Wc(360*this.x-180,$c(this.y))},tu.prototype.toAltitude=function(){return t=this.z,e=this.y,t*Zc($c(e));var t,e},tu.prototype.meterInMercatorCoordinateUnits=function(){return 1/Xc*(t=$c(this.y),1/Math.cos(t*Math.PI/180));var t};var eu=function(t,e,r){this.z=t,this.x=e,this.y=r,this.key=iu(0,t,t,e,r)};eu.prototype.equals=function(t){return this.z===t.z&&this.x===t.x&&this.y===t.y},eu.prototype.url=function(t,e){var r,n,i,a,o,s=(r=this.x,n=this.y,i=this.z,a=Gc(256*r,256*(n=Math.pow(2,i)-n-1),i),o=Gc(256*(r+1),256*(n+1),i),a[0]+","+a[1]+","+o[0]+","+o[1]),l=function(t,e,r){for(var n,i="",a=t;a>0;a--)i+=(e&(n=1<<a-1)?1:0)+(r&n?2:0);return i}(this.z,this.x,this.y);return t[(this.x+this.y)%t.length].replace("{prefix}",(this.x%16).toString(16)+(this.y%16).toString(16)).replace("{z}",String(this.z)).replace("{x}",String(this.x)).replace("{y}",String("tms"===e?Math.pow(2,this.z)-this.y-1:this.y)).replace("{quadkey}",l).replace("{bbox-epsg-3857}",s)},eu.prototype.getTilePoint=function(t){var e=Math.pow(2,this.z);return new i(8192*(t.x*e-this.x),8192*(t.y*e-this.y))},eu.prototype.toString=function(){return this.z+"/"+this.x+"/"+this.y};var ru=function(t,e){this.wrap=t,this.canonical=e,this.key=iu(t,e.z,e.z,e.x,e.y)},nu=function(t,e,r,n,i){this.overscaledZ=t,this.wrap=e,this.canonical=new eu(r,+n,+i),this.key=iu(e,t,r,n,i)};function iu(t,e,r,n,i){(t*=2)<0&&(t=-1*t-1);var a=1<<r;return(a*a*t+a*i+n).toString(36)+r.toString(36)+e.toString(36)}nu.prototype.equals=function(t){return this.overscaledZ===t.overscaledZ&&this.wrap===t.wrap&&this.canonical.equals(t.canonical)},nu.prototype.scaledTo=function(t){var e=this.canonical.z-t;return t>this.canonical.z?new nu(t,this.wrap,this.canonical.z,this.canonical.x,this.canonical.y):new nu(t,this.wrap,t,this.canonical.x>>e,this.canonical.y>>e)},nu.prototype.calculateScaledKey=function(t,e){var r=this.canonical.z-t;return t>this.canonical.z?iu(this.wrap*+e,t,this.canonical.z,this.canonical.x,this.canonical.y):iu(this.wrap*+e,t,t,this.canonical.x>>r,this.canonical.y>>r)},nu.prototype.isChildOf=function(t){if(t.wrap!==this.wrap)return!1;var e=this.canonical.z-t.canonical.z;return 0===t.overscaledZ||t.overscaledZ<this.overscaledZ&&t.canonical.x===this.canonical.x>>e&&t.canonical.y===this.canonical.y>>e},nu.prototype.children=function(t){if(this.overscaledZ>=t)return[new nu(this.overscaledZ+1,this.wrap,this.canonical.z,this.canonical.x,this.canonical.y)];var e=this.canonical.z+1,r=2*this.canonical.x,n=2*this.canonical.y;return[new nu(e,this.wrap,e,r,n),new nu(e,this.wrap,e,r+1,n),new nu(e,this.wrap,e,r,n+1),new nu(e,this.wrap,e,r+1,n+1)]},nu.prototype.isLessThan=function(t){return this.wrap<t.wrap||!(this.wrap>t.wrap)&&(this.overscaledZ<t.overscaledZ||!(this.overscaledZ>t.overscaledZ)&&(this.canonical.x<t.canonical.x||!(this.canonical.x>t.canonical.x)&&this.canonical.y<t.canonical.y))},nu.prototype.wrapped=function(){return new nu(this.overscaledZ,0,this.canonical.z,this.canonical.x,this.canonical.y)},nu.prototype.unwrapTo=function(t){return new nu(this.overscaledZ,t,this.canonical.z,this.canonical.x,this.canonical.y)},nu.prototype.overscaleFactor=function(){return Math.pow(2,this.overscaledZ-this.canonical.z)},nu.prototype.toUnwrapped=function(){return new ru(this.wrap,this.canonical)},nu.prototype.toString=function(){return this.overscaledZ+"/"+this.canonical.x+"/"+this.canonical.y},nu.prototype.getTilePoint=function(t){return this.canonical.getTilePoint(new tu(t.x-this.wrap,t.y))},Nn("CanonicalTileID",eu),Nn("OverscaledTileID",nu,{omit:["posMatrix"]});var au=function(t,e,r){if(this.uid=t,e.height!==e.width)throw new RangeError("DEM tiles must be square");if(r&&"mapbox"!==r&&"terrarium"!==r)return _('"'+r+'" is not a valid encoding type. Valid types include "mapbox" and "terrarium".');this.stride=e.height;var n=this.dim=e.height-2;this.data=new Uint32Array(e.data.buffer),this.encoding=r||"mapbox";for(var i=0;i<n;i++)this.data[this._idx(-1,i)]=this.data[this._idx(0,i)],this.data[this._idx(n,i)]=this.data[this._idx(n-1,i)],this.data[this._idx(i,-1)]=this.data[this._idx(i,0)],this.data[this._idx(i,n)]=this.data[this._idx(i,n-1)];this.data[this._idx(-1,-1)]=this.data[this._idx(0,0)],this.data[this._idx(n,-1)]=this.data[this._idx(n-1,0)],this.data[this._idx(-1,n)]=this.data[this._idx(0,n-1)],this.data[this._idx(n,n)]=this.data[this._idx(n-1,n-1)]};au.prototype.get=function(t,e){var r=new Uint8Array(this.data.buffer),n=4*this._idx(t,e);return("terrarium"===this.encoding?this._unpackTerrarium:this._unpackMapbox)(r[n],r[n+1],r[n+2])},au.prototype.getUnpackVector=function(){return"terrarium"===this.encoding?[256,1,1/256,32768]:[6553.6,25.6,.1,1e4]},au.prototype._idx=function(t,e){if(t<-1||t>=this.dim+1||e<-1||e>=this.dim+1)throw new RangeError("out of range source coordinates for DEM data");return(e+1)*this.stride+(t+1)},au.prototype._unpackMapbox=function(t,e,r){return(256*t*256+256*e+r)/10-1e4},au.prototype._unpackTerrarium=function(t,e,r){return 256*t+e+r/256-32768},au.prototype.getPixels=function(){return new Eo({width:this.stride,height:this.stride},new Uint8Array(this.data.buffer))},au.prototype.backfillBorder=function(t,e,r){if(this.dim!==t.dim)throw new Error("dem dimension mismatch");var n=e*this.dim,i=e*this.dim+this.dim,a=r*this.dim,o=r*this.dim+this.dim;switch(e){case-1:n=i-1;break;case 1:i=n+1}switch(r){case-1:a=o-1;break;case 1:o=a+1}for(var s=-e*this.dim,l=-r*this.dim,c=a;c<o;c++)for(var u=n;u<i;u++)this.data[this._idx(u,c)]=t.data[this._idx(u+s,c+l)]},Nn("DEMData",au);var ou=function(t){this._stringToNumber={},this._numberToString=[];for(var e=0;e<t.length;e++){var r=t[e];this._stringToNumber[r]=e,this._numberToString[e]=r}};ou.prototype.encode=function(t){return this._stringToNumber[t]},ou.prototype.decode=function(t){return this._numberToString[t]};var su=function(t,e,r,n,i){this.type="Feature",this._vectorTileFeature=t,t._z=e,t._x=r,t._y=n,this.properties=t.properties,this.id=i},lu={geometry:{configurable:!0}};lu.geometry.get=function(){return void 0===this._geometry&&(this._geometry=this._vectorTileFeature.toGeoJSON(this._vectorTileFeature._x,this._vectorTileFeature._y,this._vectorTileFeature._z).geometry),this._geometry},lu.geometry.set=function(t){this._geometry=t},su.prototype.toJSON=function(){var t={geometry:this.geometry};for(var e in this)"_geometry"!==e&&"_vectorTileFeature"!==e&&(t[e]=this[e]);return t},Object.defineProperties(su.prototype,lu);var cu=function(){this.state={},this.stateChanges={},this.deletedStates={}};cu.prototype.updateState=function(t,e,r){var n=String(e);if(this.stateChanges[t]=this.stateChanges[t]||{},this.stateChanges[t][n]=this.stateChanges[t][n]||{},u(this.stateChanges[t][n],r),null===this.deletedStates[t])for(var i in this.deletedStates[t]={},this.state[t])i!==n&&(this.deletedStates[t][i]=null);else if(this.deletedStates[t]&&null===this.deletedStates[t][n])for(var a in this.deletedStates[t][n]={},this.state[t][n])r[a]||(this.deletedStates[t][n][a]=null);else for(var o in r){this.deletedStates[t]&&this.deletedStates[t][n]&&null===this.deletedStates[t][n][o]&&delete this.deletedStates[t][n][o]}},cu.prototype.removeFeatureState=function(t,e,r){if(!(null===this.deletedStates[t])){var n=String(e);if(this.deletedStates[t]=this.deletedStates[t]||{},r&&void 0!==e)null!==this.deletedStates[t][n]&&(this.deletedStates[t][n]=this.deletedStates[t][n]||{},this.deletedStates[t][n][r]=null);else if(void 0!==e){if(this.stateChanges[t]&&this.stateChanges[t][n])for(r in this.deletedStates[t][n]={},this.stateChanges[t][n])this.deletedStates[t][n][r]=null;else this.deletedStates[t][n]=null}else this.deletedStates[t]=null}},cu.prototype.getState=function(t,e){var r=String(e),n=this.state[t]||{},i=this.stateChanges[t]||{},a=u({},n[r],i[r]);if(null===this.deletedStates[t])return{};if(this.deletedStates[t]){var o=this.deletedStates[t][e];if(null===o)return{};for(var s in o)delete a[s]}return a},cu.prototype.initializeTileState=function(t,e){t.setFeatureState(this.state,e)},cu.prototype.coalesceChanges=function(t,e){var r={};for(var n in this.stateChanges){this.state[n]=this.state[n]||{};var i={};for(var a in this.stateChanges[n])this.state[n][a]||(this.state[n][a]={}),u(this.state[n][a],this.stateChanges[n][a]),i[a]=this.state[n][a];r[n]=i}for(var o in this.deletedStates){this.state[o]=this.state[o]||{};var s={};if(null===this.deletedStates[o])for(var l in this.state[o])s[l]={},this.state[o][l]={};else for(var c in this.deletedStates[o]){if(null===this.deletedStates[o][c])this.state[o][c]={};else for(var f=0,h=Object.keys(this.deletedStates[o][c]);f<h.length;f+=1){var p=h[f];delete this.state[o][c][p]}s[c]=this.state[o][c]}r[o]=r[o]||{},u(r[o],s)}if(this.stateChanges={},this.deletedStates={},0!==Object.keys(r).length)for(var d in t){t[d].setFeatureState(r,e)}};var uu=function(t,e){this.tileID=t,this.x=t.canonical.x,this.y=t.canonical.y,this.z=t.canonical.z,this.grid=new zn(8192,16,0),this.grid3D=new zn(8192,16,0),this.featureIndexArray=new fa,this.promoteId=e};function fu(t,e,r,n,i){return v(t,(function(t,a){var o=e instanceof _i?e.get(a):null;return o&&o.evaluate?o.evaluate(r,n,i):o}))}function hu(t){for(var e=1/0,r=1/0,n=-1/0,i=-1/0,a=0,o=t;a<o.length;a+=1){var s=o[a];e=Math.min(e,s.x),r=Math.min(r,s.y),n=Math.max(n,s.x),i=Math.max(i,s.y)}return{minX:e,minY:r,maxX:n,maxY:i}}function pu(t,e){return e-t}uu.prototype.insert=function(t,e,r,n,i,a){var o=this.featureIndexArray.length;this.featureIndexArray.emplaceBack(r,n,i);for(var s=a?this.grid3D:this.grid,l=0;l<e.length;l++){for(var c=e[l],u=[1/0,1/0,-1/0,-1/0],f=0;f<c.length;f++){var h=c[f];u[0]=Math.min(u[0],h.x),u[1]=Math.min(u[1],h.y),u[2]=Math.max(u[2],h.x),u[3]=Math.max(u[3],h.y)}u[0]<8192&&u[1]<8192&&u[2]>=0&&u[3]>=0&&s.insert(o,u[0],u[1],u[2],u[3])}},uu.prototype.loadVTLayers=function(){return this.vtLayers||(this.vtLayers=new Ls.VectorTile(new al(this.rawTileData)).layers,this.sourceLayerCoder=new ou(this.vtLayers?Object.keys(this.vtLayers).sort():["_geojsonTileLayer"])),this.vtLayers},uu.prototype.query=function(t,e,r,n){var a=this;this.loadVTLayers();for(var o=t.params||{},s=8192/t.tileSize/t.scale,l=sn(o.filter),c=t.queryGeometry,u=t.queryPadding*s,f=hu(c),h=this.grid.query(f.minX-u,f.minY-u,f.maxX+u,f.maxY+u),p=hu(t.cameraQueryGeometry),d=this.grid3D.query(p.minX-u,p.minY-u,p.maxX+u,p.maxY+u,(function(e,r,n,a){return function(t,e,r,n,a){for(var o=0,s=t;o<s.length;o+=1){var l=s[o];if(e<=l.x&&r<=l.y&&n>=l.x&&a>=l.y)return!0}var c=[new i(e,r),new i(e,a),new i(n,a),new i(n,r)];if(t.length>2)for(var u=0,f=c;u<f.length;u+=1){if(io(t,f[u]))return!0}for(var h=0;h<t.length-1;h++){if(ao(t[h],t[h+1],c))return!0}return!1}(t.cameraQueryGeometry,e-u,r-u,n+u,a+u)})),m=0,g=d;m<g.length;m+=1){var v=g[m];h.push(v)}h.sort(pu);for(var y,x={},b=function(i){var u=h[i];if(u!==y){y=u;var f=a.featureIndexArray.get(u),p=null;a.loadMatchingFeature(x,f.bucketIndex,f.sourceLayerIndex,f.featureIndex,l,o.layers,o.availableImages,e,r,n,(function(e,r,n){return p||(p=Ya(e)),r.queryIntersectsFeature(c,e,n,p,a.z,t.transform,s,t.pixelPosMatrix)}))}},_=0;_<h.length;_++)b(_);return x},uu.prototype.loadMatchingFeature=function(t,e,r,n,i,a,o,s,l,c,u){var f=this.bucketLayerIDs[e];if(!a||function(t,e){for(var r=0;r<t.length;r++)if(e.indexOf(t[r])>=0)return!0;return!1}(a,f)){var h=this.sourceLayerCoder.decode(r),p=this.vtLayers[h].feature(n);if(i.filter(new pi(this.tileID.overscaledZ),p))for(var d=this.getId(p,h),m=0;m<f.length;m++){var g=f[m];if(!(a&&a.indexOf(g)<0)){var v=s[g];if(v){var y={};void 0!==d&&c&&(y=c.getState(v.sourceLayer||"_geojsonTileLayer",d));var x=l[g];x.paint=fu(x.paint,v.paint,p,y,o),x.layout=fu(x.layout,v.layout,p,y,o);var b=!u||u(p,v,y);if(b){var _=new su(p,this.z,this.x,this.y,d);_.layer=x;var w=t[g];void 0===w&&(w=t[g]=[]),w.push({featureIndex:n,feature:_,intersectionZ:b})}}}}}},uu.prototype.lookupSymbolFeatures=function(t,e,r,n,i,a,o,s){var l={};this.loadVTLayers();for(var c=sn(i),u=0,f=t;u<f.length;u+=1){var h=f[u];this.loadMatchingFeature(l,r,n,h,c,a,o,s,e)}return l},uu.prototype.hasLayer=function(t){for(var e=0,r=this.bucketLayerIDs;e<r.length;e+=1)for(var n=0,i=r[e];n<i.length;n+=1){if(t===i[n])return!0}return!1},uu.prototype.getId=function(t,e){var r=t.id;if(this.promoteId){var n="string"==typeof this.promoteId?this.promoteId:this.promoteId[e];"boolean"==typeof(r=t.properties[n])&&(r=Number(r))}return r},Nn("FeatureIndex",uu,{omit:["rawTileData","sourceLayerCoder"]});var du=function(t,e){this.tileID=t,this.uid=h(),this.uses=0,this.tileSize=e,this.buckets={},this.expirationTime=null,this.queryPadding=0,this.hasSymbolBuckets=!1,this.hasRTLText=!1,this.dependencies={},this.expiredRequestCount=0,this.state="loading"};du.prototype.registerFadeDuration=function(t){var e=t+this.timeAdded;e<R.now()||this.fadeEndTime&&e<this.fadeEndTime||(this.fadeEndTime=e)},du.prototype.wasRequested=function(){return"errored"===this.state||"loaded"===this.state||"reloading"===this.state},du.prototype.loadVectorData=function(t,e,r){if(this.hasData()&&this.unloadVectorData(),this.state="loaded",t){for(var n in t.featureIndex&&(this.latestFeatureIndex=t.featureIndex,t.rawTileData?(this.latestRawTileData=t.rawTileData,this.latestFeatureIndex.rawTileData=t.rawTileData):this.latestRawTileData&&(this.latestFeatureIndex.rawTileData=this.latestRawTileData)),this.collisionBoxArray=t.collisionBoxArray,this.buckets=function(t,e){var r={};if(!e)return r;for(var n=function(){var t=a[i],n=t.layerIds.map((function(t){return e.getLayer(t)})).filter(Boolean);if(0!==n.length){t.layers=n,t.stateDependentLayerIds&&(t.stateDependentLayers=t.stateDependentLayerIds.map((function(t){return n.filter((function(e){return e.id===t}))[0]})));for(var o=0,s=n;o<s.length;o+=1){var l=s[o];r[l.id]=t}}},i=0,a=t;i<a.length;i+=1)n();return r}(t.buckets,e.style),this.hasSymbolBuckets=!1,this.buckets){var i=this.buckets[n];if(i instanceof Mc){if(this.hasSymbolBuckets=!0,!r)break;i.justReloaded=!0}}if(this.hasRTLText=!1,this.hasSymbolBuckets)for(var a in this.buckets){var o=this.buckets[a];if(o instanceof Mc&&o.hasRTLText){this.hasRTLText=!0,hi.isLoading()||hi.isLoaded()||"deferred"!==ui()||fi();break}}for(var s in this.queryPadding=0,this.buckets){var l=this.buckets[s];this.queryPadding=Math.max(this.queryPadding,e.style.getLayer(s).queryRadius(l))}t.imageAtlas&&(this.imageAtlas=t.imageAtlas),t.glyphAtlasImage&&(this.glyphAtlasImage=t.glyphAtlasImage)}else this.collisionBoxArray=new na},du.prototype.unloadVectorData=function(){for(var t in this.buckets)this.buckets[t].destroy();this.buckets={},this.imageAtlasTexture&&this.imageAtlasTexture.destroy(),this.imageAtlas&&(this.imageAtlas=null),this.glyphAtlasTexture&&this.glyphAtlasTexture.destroy(),this.latestFeatureIndex=null,this.state="unloaded"},du.prototype.getBucket=function(t){return this.buckets[t.id]},du.prototype.upload=function(t){for(var e in this.buckets){var r=this.buckets[e];r.uploadPending()&&r.upload(t)}var n=t.gl;this.imageAtlas&&!this.imageAtlas.uploaded&&(this.imageAtlasTexture=new Vc(t,this.imageAtlas.image,n.RGBA),this.imageAtlas.uploaded=!0),this.glyphAtlasImage&&(this.glyphAtlasTexture=new Vc(t,this.glyphAtlasImage,n.ALPHA),this.glyphAtlasImage=null)},du.prototype.prepare=function(t){this.imageAtlas&&this.imageAtlas.patchUpdatedImages(t,this.imageAtlasTexture)},du.prototype.queryRenderedFeatures=function(t,e,r,n,i,a,o,s,l,c){return this.latestFeatureIndex&&this.latestFeatureIndex.rawTileData?this.latestFeatureIndex.query({queryGeometry:n,cameraQueryGeometry:i,scale:a,tileSize:this.tileSize,pixelPosMatrix:c,transform:s,params:o,queryPadding:this.queryPadding*l},t,e,r):{}},du.prototype.querySourceFeatures=function(t,e){var r=this.latestFeatureIndex;if(r&&r.rawTileData){var n=r.loadVTLayers(),i=e?e.sourceLayer:"",a=n._geojsonTileLayer||n[i];if(a)for(var o=sn(e&&e.filter),s=this.tileID.canonical,l=s.z,c=s.x,u=s.y,f={z:l,x:c,y:u},h=0;h<a.length;h++){var p=a.feature(h);if(o.filter(new pi(this.tileID.overscaledZ),p)){var d=r.getId(p,i),m=new su(p,l,c,u,d);m.tile=f,t.push(m)}}}},du.prototype.hasData=function(){return"loaded"===this.state||"reloading"===this.state||"expired"===this.state},du.prototype.patternsLoaded=function(){return this.imageAtlas&&!!Object.keys(this.imageAtlas.patternPositions).length},du.prototype.setExpiryData=function(t){var e=this.expirationTime;if(t.cacheControl){var r=A(t.cacheControl);r["max-age"]&&(this.expirationTime=Date.now()+1e3*r["max-age"])}else t.expires&&(this.expirationTime=new Date(t.expires).getTime());if(this.expirationTime){var n=Date.now(),i=!1;if(this.expirationTime>n)i=!1;else if(e)if(this.expirationTime<e)i=!0;else{var a=this.expirationTime-e;a?this.expirationTime=n+Math.max(a,3e4):i=!0}else i=!0;i?(this.expiredRequestCount++,this.state="expired"):this.expiredRequestCount=0}},du.prototype.getExpiryTimeout=function(){if(this.expirationTime)return this.expiredRequestCount?1e3*(1<<Math.min(this.expiredRequestCount-1,31)):Math.min(this.expirationTime-(new Date).getTime(),Math.pow(2,31)-1)},du.prototype.setFeatureState=function(t,e){if(this.latestFeatureIndex&&this.latestFeatureIndex.rawTileData&&0!==Object.keys(t).length){var r=this.latestFeatureIndex.loadVTLayers();for(var n in this.buckets)if(e.style.hasLayer(n)){var i=this.buckets[n],a=i.layers[0].sourceLayer||"_geojsonTileLayer",o=r[a],s=t[a];if(o&&s&&0!==Object.keys(s).length){i.update(s,o,this.imageAtlas&&this.imageAtlas.patternPositions||{});var l=e&&e.style&&e.style.getLayer(n);l&&(this.queryPadding=Math.max(this.queryPadding,l.queryRadius(i)))}}}},du.prototype.holdingForFade=function(){return void 0!==this.symbolFadeHoldUntil},du.prototype.symbolFadeFinished=function(){return!this.symbolFadeHoldUntil||this.symbolFadeHoldUntil<R.now()},du.prototype.clearFadeHold=function(){this.symbolFadeHoldUntil=void 0},du.prototype.setHoldDuration=function(t){this.symbolFadeHoldUntil=R.now()+t},du.prototype.setDependencies=function(t,e){for(var r={},n=0,i=e;n<i.length;n+=1){r[i[n]]=!0}this.dependencies[t]=r},du.prototype.hasDependency=function(t,e){for(var r=0,n=t;r<n.length;r+=1){var i=n[r],a=this.dependencies[i];if(a)for(var o=0,s=e;o<s.length;o+=1){if(a[s[o]])return!0}}return!1};var mu=self.performance,gu=function(t){this._marks={start:[t.url,"start"].join("#"),end:[t.url,"end"].join("#"),measure:t.url.toString()},mu.mark(this._marks.start)};gu.prototype.finish=function(){mu.mark(this._marks.end);var t=mu.getEntriesByName(this._marks.measure);return 0===t.length&&(mu.measure(this._marks.measure,this._marks.start,this._marks.end),t=mu.getEntriesByName(this._marks.measure),mu.clearMarks(this._marks.start),mu.clearMarks(this._marks.end),mu.clearMeasures(this._marks.measure)),t},t.Actor=qc,t.AlphaImage=So,t.CanonicalTileID=eu,t.CollisionBoxArray=na,t.Color=te,t.DEMData=au,t.DataConstantProperty=wi,t.DictionaryCoder=ou,t.EXTENT=8192,t.ErrorEvent=St,t.EvaluationParameters=pi,t.Event=Mt,t.Evented=Et,t.FeatureIndex=uu,t.FillBucket=gs,t.FillExtrusionBucket=Os,t.ImageAtlas=Ll,t.ImagePosition=Sl,t.LineBucket=qs,t.LngLat=Wc,t.LngLatBounds=Yc,t.MercatorCoordinate=tu,t.ONE_EM=24,t.OverscaledTileID=nu,t.Point=i,t.Point$1=i,t.Properties=Si,t.Protobuf=al,t.RGBAImage=Eo,t.RequestManager=H,t.RequestPerformance=gu,t.ResourceType=dt,t.SegmentVector=pa,t.SourceFeatureState=cu,t.StructArrayLayout1ui2=$i,t.StructArrayLayout2f1f2i16=qi,t.StructArrayLayout2i4=zi,t.StructArrayLayout3ui6=Yi,t.StructArrayLayout4i8=Di,t.SymbolBucket=Mc,t.Texture=Vc,t.Tile=du,t.Transitionable=gi,t.Uniform1f=Sa,t.Uniform1i=Ma,t.Uniform2f=Ea,t.Uniform3f=La,t.Uniform4f=Ca,t.UniformColor=Pa,t.UniformMatrix4f=Oa,t.UnwrappedTileID=ru,t.ValidationError=Ct,t.WritingMode=Cl,t.ZoomHistory=Gn,t.add=function(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t},t.addDynamicAttributes=wc,t.asyncAll=function(t,e,r){if(!t.length)return r(null,[]);var n=t.length,i=new Array(t.length),a=null;t.forEach((function(t,o){e(t,(function(t,e){t&&(a=t),i[o]=e,0==--n&&r(a,i)}))}))},t.bezier=o,t.bindAll=m,t.browser=R,t.cacheEntryPossiblyAdded=function(t){++ht>ot&&(t.getActor().send("enforceCacheSizeLimit",at),ht=0)},t.clamp=l,t.clearTileCache=function(t){var e=self.caches.delete("mapbox-tiles");t&&e.catch(t).then((function(){return t()}))},t.clipLine=ec,t.clone=function(t){var e=new fo(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},t.clone$1=x,t.clone$2=function(t){var e=new fo(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e},t.collisionCircleLayout=tl,t.config=F,t.create=function(){var t=new fo(16);return fo!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t},t.create$1=function(){var t=new fo(9);return fo!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t},t.create$2=function(){var t=new fo(4);return fo!=Float32Array&&(t[1]=0,t[2]=0),t[0]=1,t[3]=1,t},t.createCommonjsModule=e,t.createExpression=Wr,t.createLayout=Ii,t.createStyleLayer=function(t){return"custom"===t.type?new Dc(t):new Rc[t.type](t)},t.cross=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],l=r[2];return t[0]=i*l-a*s,t[1]=a*o-n*l,t[2]=n*s-i*o,t},t.deepEqual=function t(e,r){if(Array.isArray(e)){if(!Array.isArray(r)||e.length!==r.length)return!1;for(var n=0;n<e.length;n++)if(!t(e[n],r[n]))return!1;return!0}if("object"==typeof e&&null!==e&&null!==r){if("object"!=typeof r)return!1;if(Object.keys(e).length!==Object.keys(r).length)return!1;for(var i in e)if(!t(e[i],r[i]))return!1;return!0}return e===r},t.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]},t.dot$1=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]},t.ease=s,t.emitValidationErrors=On,t.endsWith=g,t.enforceCacheSizeLimit=function(t){st(),Q&&Q.then((function(e){e.keys().then((function(r){for(var n=0;n<r.length-t;n++)e.delete(r[n])}))}))},t.evaluateSizeForFeature=Yl,t.evaluateSizeForZoom=Wl,t.evaluateVariableOffset=dc,t.evented=ci,t.extend=u,t.featureFilter=sn,t.filterObject=y,t.fromRotation=function(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=-r,t[4]=n,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},t.getAnchorAlignment=Ul,t.getAnchorJustification=mc,t.getArrayBuffer=xt,t.getImage=Tt,t.getJSON=function(t,e){return yt(u(t,{type:"json"}),e)},t.getRTLTextPluginStatus=ui,t.getReferrer=gt,t.getVideo=function(t,e){var r,n,i=self.document.createElement("video");i.muted=!0,i.onloadstart=function(){e(null,i)};for(var a=0;a<t.length;a++){var o=self.document.createElement("source");r=t[a],n=void 0,(n=self.document.createElement("a")).href=r,(n.protocol!==self.document.location.protocol||n.host!==self.document.location.host)&&(i.crossOrigin="Anonymous"),o.src=t[a],i.appendChild(o)}return{cancel:function(){}}},t.identity=ho,t.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],l=e[6],c=e[7],u=e[8],f=e[9],h=e[10],p=e[11],d=e[12],m=e[13],g=e[14],v=e[15],y=r*s-n*o,x=r*l-i*o,b=r*c-a*o,_=n*l-i*s,w=n*c-a*s,T=i*c-a*l,k=u*m-f*d,A=u*g-h*d,M=u*v-p*d,S=f*g-h*m,E=f*v-p*m,L=h*v-p*g,C=y*L-x*E+b*S+_*M-w*A+T*k;return C?(C=1/C,t[0]=(s*L-l*E+c*S)*C,t[1]=(i*E-n*L-a*S)*C,t[2]=(m*T-g*w+v*_)*C,t[3]=(h*w-f*T-p*_)*C,t[4]=(l*M-o*L-c*A)*C,t[5]=(r*L-i*M+a*A)*C,t[6]=(g*b-d*T-v*x)*C,t[7]=(u*T-h*b+p*x)*C,t[8]=(o*E-s*M+c*k)*C,t[9]=(n*M-r*E-a*k)*C,t[10]=(d*w-m*b+v*y)*C,t[11]=(f*b-u*w-p*y)*C,t[12]=(s*A-o*S-l*k)*C,t[13]=(r*S-n*A+i*k)*C,t[14]=(m*x-d*_-g*y)*C,t[15]=(u*_-f*x+h*y)*C,t):null},t.isChar=Yn,t.isMapboxURL=q,t.keysDifference=function(t,e){var r=[];for(var n in t)n in e||r.push(n);return r},t.makeRequest=yt,t.mapObject=v,t.mercatorXfromLng=Jc,t.mercatorYfromLat=Kc,t.mercatorZfromAltitude=Qc,t.mul=mo,t.multiply=po,t.mvt=Ls,t.normalize=function(t,e){var r=e[0],n=e[1],i=e[2],a=r*r+n*n+i*i;return a>0&&(a=1/Math.sqrt(a)),t[0]=e[0]*a,t[1]=e[1]*a,t[2]=e[2]*a,t},t.number=qe,t.offscreenCanvasSupported=pt,t.ortho=function(t,e,r,n,i,a,o){var s=1/(e-r),l=1/(n-i),c=1/(a-o);return t[0]=-2*s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*l,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*c,t[11]=0,t[12]=(e+r)*s,t[13]=(i+n)*l,t[14]=(o+a)*c,t[15]=1,t},t.parseGlyphPBF=function(t){return new al(t).readFields(Tl,[])},t.pbf=al,t.performSymbolLayout=function(t,e,r,n,i,a,o){t.createArrays();var s=512*t.overscaling;t.tilePixelRatio=8192/s,t.compareText={},t.iconsNeedLinear=!1;var l=t.layers[0].layout,c=t.layers[0]._unevaluatedLayout._values,u={};if("composite"===t.textSizeData.kind){var f=t.textSizeData,h=f.minZoom,p=f.maxZoom;u.compositeTextSizes=[c["text-size"].possiblyEvaluate(new pi(h),o),c["text-size"].possiblyEvaluate(new pi(p),o)]}if("composite"===t.iconSizeData.kind){var d=t.iconSizeData,m=d.minZoom,g=d.maxZoom;u.compositeIconSizes=[c["icon-size"].possiblyEvaluate(new pi(m),o),c["icon-size"].possiblyEvaluate(new pi(g),o)]}u.layoutTextSize=c["text-size"].possiblyEvaluate(new pi(t.zoom+1),o),u.layoutIconSize=c["icon-size"].possiblyEvaluate(new pi(t.zoom+1),o),u.textMaxSize=c["text-size"].possiblyEvaluate(new pi(18));for(var v=24*l.get("text-line-height"),y="map"===l.get("text-rotation-alignment")&&"point"!==l.get("symbol-placement"),x=l.get("text-keep-upright"),b=l.get("text-size"),w=function(){var a=k[T],s=l.get("text-font").evaluate(a,{},o).join(","),c=b.evaluate(a,{},o),f=u.layoutTextSize.evaluate(a,{},o),h=u.layoutIconSize.evaluate(a,{},o),p={horizontal:{},vertical:void 0},d=a.text,m=[0,0];if(d){var g=d.toString(),w=24*l.get("text-letter-spacing").evaluate(a,{},o),A=function(t){for(var e=0,r=t;e<r.length;e+=1){if(!Xn(r[e].charCodeAt(0)))return!1}return!0}(g)?w:0,M=l.get("text-anchor").evaluate(a,{},o),S=l.get("text-variable-anchor");if(!S){var E=l.get("text-radial-offset").evaluate(a,{},o);m=E?dc(M,[24*E,pc]):l.get("text-offset").evaluate(a,{},o).map((function(t){return 24*t}))}var L=y?"center":l.get("text-justify").evaluate(a,{},o),C=l.get("symbol-placement"),P="point"===C?24*l.get("text-max-width").evaluate(a,{},o):0,I=function(){t.allowVerticalPlacement&&Wn(g)&&(p.vertical=Ol(d,e,r,i,s,P,v,M,"left",A,m,Cl.vertical,!0,C,f,c))};if(!y&&S){for(var O="auto"===L?S.map((function(t){return mc(t)})):[L],z=!1,D=0;D<O.length;D++){var R=O[D];if(!p.horizontal[R])if(z)p.horizontal[R]=p.horizontal[0];else{var F=Ol(d,e,r,i,s,P,v,"center",R,A,m,Cl.horizontal,!1,C,f,c);F&&(p.horizontal[R]=F,z=1===F.positionedLines.length)}}I()}else{"auto"===L&&(L=mc(M));var B=Ol(d,e,r,i,s,P,v,M,L,A,m,Cl.horizontal,!1,C,f,c);B&&(p.horizontal[L]=B),I(),Wn(g)&&y&&x&&(p.vertical=Ol(d,e,r,i,s,P,v,M,L,A,m,Cl.vertical,!1,C,f,c))}}var N=void 0,j=!1;if(a.icon&&a.icon.name){var U=n[a.icon.name];U&&(N=function(t,e,r){var n=Ul(r),i=n.horizontalAlign,a=n.verticalAlign,o=e[0],s=e[1],l=o-t.displaySize[0]*i,c=l+t.displaySize[0],u=s-t.displaySize[1]*a;return{image:t,top:u,bottom:u+t.displaySize[1],left:l,right:c}}(i[a.icon.name],l.get("icon-offset").evaluate(a,{},o),l.get("icon-anchor").evaluate(a,{},o)),j=U.sdf,void 0===t.sdfIcons?t.sdfIcons=U.sdf:t.sdfIcons!==U.sdf&&_("Style sheet warning: Cannot mix SDF and non-SDF icons in one buffer"),(U.pixelRatio!==t.pixelRatio||0!==l.get("icon-rotate").constantOr(1))&&(t.iconsNeedLinear=!0))}var V=vc(p.horizontal)||p.vertical;t.iconsInText=!!V&&V.iconsInText,(V||N)&&function(t,e,r,n,i,a,o,s,l,c,u){var f=a.textMaxSize.evaluate(e,{});void 0===f&&(f=o);var h,p=t.layers[0].layout,d=p.get("icon-offset").evaluate(e,{},u),m=vc(r.horizontal),g=o/24,v=t.tilePixelRatio*g,y=t.tilePixelRatio*f/24,x=t.tilePixelRatio*s,b=t.tilePixelRatio*p.get("symbol-spacing"),w=p.get("text-padding")*t.tilePixelRatio,T=p.get("icon-padding")*t.tilePixelRatio,k=p.get("text-max-angle")/180*Math.PI,A="map"===p.get("text-rotation-alignment")&&"point"!==p.get("symbol-placement"),M="map"===p.get("icon-rotation-alignment")&&"point"!==p.get("symbol-placement"),S=p.get("symbol-placement"),E=b/2,L=p.get("icon-text-fit");n&&"none"!==L&&(t.allowVerticalPlacement&&r.vertical&&(h=Hl(n,r.vertical,L,p.get("icon-text-fit-padding"),d,g)),m&&(n=Hl(n,m,L,p.get("icon-text-fit-padding"),d,g)));var C=function(s,f){f.x<0||f.x>=8192||f.y<0||f.y>=8192||function(t,e,r,n,i,a,o,s,l,c,u,f,h,p,d,m,g,v,y,x,b,w,T,k,A){var M,S,E,L,C,P=t.addToLineVertexArray(e,r),I=0,O=0,z=0,D=0,R=-1,F=-1,B={},N=ya(""),j=0,U=0;void 0===s._unevaluatedLayout.getValue("text-radial-offset")?(M=s.layout.get("text-offset").evaluate(b,{},k).map((function(t){return 24*t})),j=M[0],U=M[1]):(j=24*s.layout.get("text-radial-offset").evaluate(b,{},k),U=pc);if(t.allowVerticalPlacement&&n.vertical){var V=s.layout.get("text-rotate").evaluate(b,{},k)+90,H=n.vertical;L=new sc(l,e,c,u,f,H,h,p,d,V),o&&(C=new sc(l,e,c,u,f,o,g,v,d,V))}if(i){var q=s.layout.get("icon-rotate").evaluate(b,{}),G="none"!==s.layout.get("icon-text-fit"),Y=rc(i,q,T,G),W=o?rc(o,q,T,G):void 0;E=new sc(l,e,c,u,f,i,g,v,!1,q),I=4*Y.length;var X=t.iconSizeData,Z=null;"source"===X.kind?(Z=[128*s.layout.get("icon-size").evaluate(b,{})])[0]>32640&&_(t.layerIds[0]+': Value for "icon-size" is >= 255. Reduce your "icon-size".'):"composite"===X.kind&&((Z=[128*w.compositeIconSizes[0].evaluate(b,{},k),128*w.compositeIconSizes[1].evaluate(b,{},k)])[0]>32640||Z[1]>32640)&&_(t.layerIds[0]+': Value for "icon-size" is >= 255. Reduce your "icon-size".'),t.addSymbols(t.icon,Y,Z,x,y,b,!1,e,P.lineStartIndex,P.lineLength,-1,k),R=t.icon.placedSymbolArray.length-1,W&&(O=4*W.length,t.addSymbols(t.icon,W,Z,x,y,b,Cl.vertical,e,P.lineStartIndex,P.lineLength,-1,k),F=t.icon.placedSymbolArray.length-1)}for(var J in n.horizontal){var K=n.horizontal[J];if(!S){N=ya(K.text);var Q=s.layout.get("text-rotate").evaluate(b,{},k);S=new sc(l,e,c,u,f,K,h,p,d,Q)}var $=1===K.positionedLines.length;if(z+=gc(t,e,K,a,s,d,b,m,P,n.vertical?Cl.horizontal:Cl.horizontalOnly,$?Object.keys(n.horizontal):[J],B,R,w,k),$)break}n.vertical&&(D+=gc(t,e,n.vertical,a,s,d,b,m,P,Cl.vertical,["vertical"],B,F,w,k));var tt=S?S.boxStartIndex:t.collisionBoxArray.length,et=S?S.boxEndIndex:t.collisionBoxArray.length,rt=L?L.boxStartIndex:t.collisionBoxArray.length,nt=L?L.boxEndIndex:t.collisionBoxArray.length,it=E?E.boxStartIndex:t.collisionBoxArray.length,at=E?E.boxEndIndex:t.collisionBoxArray.length,ot=C?C.boxStartIndex:t.collisionBoxArray.length,st=C?C.boxEndIndex:t.collisionBoxArray.length,lt=-1,ct=function(t,e){return t&&t.circleDiameter?Math.max(t.circleDiameter,e):e};lt=ct(S,lt),lt=ct(L,lt),lt=ct(E,lt);var ut=(lt=ct(C,lt))>-1?1:0;ut&&(lt*=A/24);t.glyphOffsetArray.length>=Mc.MAX_GLYPHS&&_("Too many glyphs being rendered in a tile. See https://github.com/mapbox/mapbox-gl-js/issues/2907");void 0!==b.sortKey&&t.addToSortKeyRanges(t.symbolInstances.length,b.sortKey);t.symbolInstances.emplaceBack(e.x,e.y,B.right>=0?B.right:-1,B.center>=0?B.center:-1,B.left>=0?B.left:-1,B.vertical||-1,R,F,N,tt,et,rt,nt,it,at,ot,st,c,z,D,I,O,ut,0,h,j,U,lt)}(t,f,s,r,n,i,h,t.layers[0],t.collisionBoxArray,e.index,e.sourceLayerIndex,t.index,v,w,A,l,x,T,M,d,e,a,c,u,o)};if("line"===S)for(var P=0,I=ec(e.geometry,0,0,8192,8192);P<I.length;P+=1)for(var O=I[P],z=tc(O,b,k,r.vertical||m,n,24,y,t.overscaling,8192),D=0,R=z;D<R.length;D+=1){var F=R[D],B=m;B&&yc(t,B.text,E,F)||C(O,F)}else if("line-center"===S)for(var N=0,j=e.geometry;N<j.length;N+=1){var U=j[N];if(U.length>1){var V=$l(U,k,r.vertical||m,n,24,y);V&&C(U,V)}}else if("Polygon"===e.type)for(var H=0,q=hs(e.geometry,0);H<q.length;H+=1){var G=q[H],Y=uc(G,16);C(G[0],new ql(Y.x,Y.y,0))}else if("LineString"===e.type)for(var W=0,X=e.geometry;W<X.length;W+=1){var Z=X[W];C(Z,new ql(Z[0].x,Z[0].y,0))}else if("Point"===e.type)for(var J=0,K=e.geometry;J<K.length;J+=1)for(var Q=K[J],$=0,tt=Q;$<tt.length;$+=1){var et=tt[$];C([et],new ql(et.x,et.y,0))}}(t,a,p,N,n,u,f,h,m,j,o)},T=0,k=t.features;T<k.length;T+=1)w();a&&t.generateCollisionDebugBuffers()},t.perspective=function(t,e,r,n,i){var a,o=1/Math.tan(e/2);return t[0]=o/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,null!=i&&i!==1/0?(a=1/(n-i),t[10]=(i+n)*a,t[14]=2*i*n*a):(t[10]=-1,t[14]=-2*n),t},t.pick=function(t,e){for(var r={},n=0;n<e.length;n++){var i=e[n];i in t&&(r[i]=t[i])}return r},t.plugin=hi,t.polygonIntersectsPolygon=Za,t.postMapLoadEvent=it,t.postTurnstileEvent=rt,t.potpack=Ml,t.refProperties=["type","source","source-layer","minzoom","maxzoom","filter","layout"],t.register=Nn,t.registerForPluginStateChange=function(t){return t({pluginStatus:ai,pluginURL:oi}),ci.on("pluginStateChange",t),t},t.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),l=Math.cos(r);return t[0]=n*l+a*s,t[1]=i*l+o*s,t[2]=n*-s+a*l,t[3]=i*-s+o*l,t},t.rotateX=function(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[4],o=e[5],s=e[6],l=e[7],c=e[8],u=e[9],f=e[10],h=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=a*i+c*n,t[5]=o*i+u*n,t[6]=s*i+f*n,t[7]=l*i+h*n,t[8]=c*i-a*n,t[9]=u*i-o*n,t[10]=f*i-s*n,t[11]=h*i-l*n,t},t.rotateZ=function(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[0],o=e[1],s=e[2],l=e[3],c=e[4],u=e[5],f=e[6],h=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=a*i+c*n,t[1]=o*i+u*n,t[2]=s*i+f*n,t[3]=l*i+h*n,t[4]=c*i-a*n,t[5]=u*i-o*n,t[6]=f*i-s*n,t[7]=h*i-l*n,t},t.scale=function(t,e,r){var n=r[0],i=r[1],a=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*a,t[9]=e[9]*a,t[10]=e[10]*a,t[11]=e[11]*a,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},t.scale$1=function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t},t.scale$2=function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t},t.setCacheLimits=function(t,e){at=t,ot=e},t.setRTLTextPlugin=function(t,e,r){if(void 0===r&&(r=!1),ai===ti||ai===ei||ai===ri)throw new Error("setRTLTextPlugin cannot be called multiple times.");oi=R.resolveURL(t),ai=ti,ii=e,li(),r||fi()},t.sphericalToCartesian=function(t){var e=t[0],r=t[1],n=t[2];return r+=90,r*=Math.PI/180,n*=Math.PI/180,{x:e*Math.cos(r)*Math.sin(n),y:e*Math.sin(r)*Math.sin(n),z:e*Math.cos(n)}},t.sqrLen=bo,t.styleSpec=Lt,t.sub=yo,t.symbolSize=Xl,t.transformMat3=function(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=n*r[0]+i*r[3]+a*r[6],t[1]=n*r[1]+i*r[4]+a*r[7],t[2]=n*r[2]+i*r[5]+a*r[8],t},t.transformMat4=xo,t.translate=function(t,e,r){var n,i,a,o,s,l,c,u,f,h,p,d,m=r[0],g=r[1],v=r[2];return e===t?(t[12]=e[0]*m+e[4]*g+e[8]*v+e[12],t[13]=e[1]*m+e[5]*g+e[9]*v+e[13],t[14]=e[2]*m+e[6]*g+e[10]*v+e[14],t[15]=e[3]*m+e[7]*g+e[11]*v+e[15]):(n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],l=e[5],c=e[6],u=e[7],f=e[8],h=e[9],p=e[10],d=e[11],t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=l,t[6]=c,t[7]=u,t[8]=f,t[9]=h,t[10]=p,t[11]=d,t[12]=n*m+s*g+f*v+e[12],t[13]=i*m+l*g+h*v+e[13],t[14]=a*m+c*g+p*v+e[14],t[15]=o*m+u*g+d*v+e[15]),t},t.triggerPluginCompletionEvent=si,t.uniqueId=h,t.validateCustomStyleLayer=function(t){var e=[],r=t.id;return void 0===r&&e.push({message:"layers."+r+': missing required property "id"'}),void 0===t.render&&e.push({message:"layers."+r+': missing required method "render"'}),t.renderingMode&&"2d"!==t.renderingMode&&"3d"!==t.renderingMode&&e.push({message:"layers."+r+': property "renderingMode" must be either "2d" or "3d"'}),e},t.validateLight=Cn,t.validateStyle=Ln,t.values=function(t){var e=[];for(var r in t)e.push(t[r]);return e},t.vectorTile=Ls,t.version="1.10.1",t.warnOnce=_,t.webpSupported=B,t.window=self,t.wrap=c})),n(0,(function(t){function e(t){var r=typeof t;if("number"===r||"boolean"===r||"string"===r||null==t)return JSON.stringify(t);if(Array.isArray(t)){for(var n="[",i=0,a=t;i<a.length;i+=1){n+=e(a[i])+","}return n+"]"}for(var o=Object.keys(t).sort(),s="{",l=0;l<o.length;l++)s+=JSON.stringify(o[l])+":"+e(t[o[l]])+",";return s+"}"}function r(r){for(var n="",i=0,a=t.refProperties;i<a.length;i+=1){n+="/"+e(r[a[i]])}return n}var n=function(t){this.keyCache={},t&&this.replace(t)};n.prototype.replace=function(t){this._layerConfigs={},this._layers={},this.update(t,[])},n.prototype.update=function(e,n){for(var i=this,a=0,o=e;a<o.length;a+=1){var s=o[a];this._layerConfigs[s.id]=s;var l=this._layers[s.id]=t.createStyleLayer(s);l._featureFilter=t.featureFilter(l.filter),this.keyCache[s.id]&&delete this.keyCache[s.id]}for(var c=0,u=n;c<u.length;c+=1){var f=u[c];delete this.keyCache[f],delete this._layerConfigs[f],delete this._layers[f]}this.familiesBySource={};for(var h=0,p=function(t,e){for(var n={},i=0;i<t.length;i++){var a=e&&e[t[i].id]||r(t[i]);e&&(e[t[i].id]=a);var o=n[a];o||(o=n[a]=[]),o.push(t[i])}var s=[];for(var l in n)s.push(n[l]);return s}(t.values(this._layerConfigs),this.keyCache);h<p.length;h+=1){var d=p[h].map((function(t){return i._layers[t.id]})),m=d[0];if("none"!==m.visibility){var g=m.source||"",v=this.familiesBySource[g];v||(v=this.familiesBySource[g]={});var y=m.sourceLayer||"_geojsonTileLayer",x=v[y];x||(x=v[y]=[]),x.push(d)}}};var i=function(e){var r={},n=[];for(var i in e){var a=e[i],o=r[i]={};for(var s in a){var l=a[+s];if(l&&0!==l.bitmap.width&&0!==l.bitmap.height){var c={x:0,y:0,w:l.bitmap.width+2,h:l.bitmap.height+2};n.push(c),o[s]={rect:c,metrics:l.metrics}}}}var u=t.potpack(n),f=u.w,h=u.h,p=new t.AlphaImage({width:f||1,height:h||1});for(var d in e){var m=e[d];for(var g in m){var v=m[+g];if(v&&0!==v.bitmap.width&&0!==v.bitmap.height){var y=r[d][g].rect;t.AlphaImage.copy(v.bitmap,p,{x:0,y:0},{x:y.x+1,y:y.y+1},v.bitmap)}}}this.image=p,this.positions=r};t.register("GlyphAtlas",i);var a=function(e){this.tileID=new t.OverscaledTileID(e.tileID.overscaledZ,e.tileID.wrap,e.tileID.canonical.z,e.tileID.canonical.x,e.tileID.canonical.y),this.uid=e.uid,this.zoom=e.zoom,this.pixelRatio=e.pixelRatio,this.tileSize=e.tileSize,this.source=e.source,this.overscaling=this.tileID.overscaleFactor(),this.showCollisionBoxes=e.showCollisionBoxes,this.collectResourceTiming=!!e.collectResourceTiming,this.returnDependencies=!!e.returnDependencies,this.promoteId=e.promoteId};function o(e,r,n){for(var i=new t.EvaluationParameters(r),a=0,o=e;a<o.length;a+=1){o[a].recalculate(i,n)}}function s(e,r){var n=t.getArrayBuffer(e.request,(function(e,n,i,a){e?r(e):n&&r(null,{vectorTile:new t.vectorTile.VectorTile(new t.pbf(n)),rawData:n,cacheControl:i,expires:a})}));return function(){n.cancel(),r()}}a.prototype.parse=function(e,r,n,a,s){var l=this;this.status="parsing",this.data=e,this.collisionBoxArray=new t.CollisionBoxArray;var c=new t.DictionaryCoder(Object.keys(e.layers).sort()),u=new t.FeatureIndex(this.tileID,this.promoteId);u.bucketLayerIDs=[];var f,h,p,d,m={},g={featureIndex:u,iconDependencies:{},patternDependencies:{},glyphDependencies:{},availableImages:n},v=r.familiesBySource[this.source];for(var y in v){var x=e.layers[y];if(x){1===x.version&&t.warnOnce('Vector tile source "'+this.source+'" layer "'+y+'" does not use vector tile spec v2 and therefore may have some rendering errors.');for(var b=c.encode(y),_=[],w=0;w<x.length;w++){var T=x.feature(w),k=u.getId(T,y);_.push({feature:T,id:k,index:w,sourceLayerIndex:b})}for(var A=0,M=v[y];A<M.length;A+=1){var S=M[A],E=S[0];if(!(E.minzoom&&this.zoom<Math.floor(E.minzoom)))if(!(E.maxzoom&&this.zoom>=E.maxzoom))if("none"!==E.visibility)o(S,this.zoom,n),(m[E.id]=E.createBucket({index:u.bucketLayerIDs.length,layers:S,zoom:this.zoom,pixelRatio:this.pixelRatio,overscaling:this.overscaling,collisionBoxArray:this.collisionBoxArray,sourceLayerIndex:b,sourceID:this.source})).populate(_,g,this.tileID.canonical),u.bucketLayerIDs.push(S.map((function(t){return t.id})))}}}var L=t.mapObject(g.glyphDependencies,(function(t){return Object.keys(t).map(Number)}));Object.keys(L).length?a.send("getGlyphs",{uid:this.uid,stacks:L},(function(t,e){f||(f=t,h=e,I.call(l))})):h={};var C=Object.keys(g.iconDependencies);C.length?a.send("getImages",{icons:C,source:this.source,tileID:this.tileID,type:"icons"},(function(t,e){f||(f=t,p=e,I.call(l))})):p={};var P=Object.keys(g.patternDependencies);function I(){if(f)return s(f);if(h&&p&&d){var e=new i(h),r=new t.ImageAtlas(p,d);for(var a in m){var l=m[a];l instanceof t.SymbolBucket?(o(l.layers,this.zoom,n),t.performSymbolLayout(l,h,e.positions,p,r.iconPositions,this.showCollisionBoxes,this.tileID.canonical)):l.hasPattern&&(l instanceof t.LineBucket||l instanceof t.FillBucket||l instanceof t.FillExtrusionBucket)&&(o(l.layers,this.zoom,n),l.addFeatures(g,this.tileID.canonical,r.patternPositions))}this.status="done",s(null,{buckets:t.values(m).filter((function(t){return!t.isEmpty()})),featureIndex:u,collisionBoxArray:this.collisionBoxArray,glyphAtlasImage:e.image,imageAtlas:r,glyphMap:this.returnDependencies?h:null,iconMap:this.returnDependencies?p:null,glyphPositions:this.returnDependencies?e.positions:null})}}P.length?a.send("getImages",{icons:P,source:this.source,tileID:this.tileID,type:"patterns"},(function(t,e){f||(f=t,d=e,I.call(l))})):d={},I.call(this)};var l=function(t,e,r,n){this.actor=t,this.layerIndex=e,this.availableImages=r,this.loadVectorData=n||s,this.loading={},this.loaded={}};l.prototype.loadTile=function(e,r){var n=this,i=e.uid;this.loading||(this.loading={});var o=!!(e&&e.request&&e.request.collectResourceTiming)&&new t.RequestPerformance(e.request),s=this.loading[i]=new a(e);s.abort=this.loadVectorData(e,(function(e,a){if(delete n.loading[i],e||!a)return s.status="done",n.loaded[i]=s,r(e);var l=a.rawData,c={};a.expires&&(c.expires=a.expires),a.cacheControl&&(c.cacheControl=a.cacheControl);var u={};if(o){var f=o.finish();f&&(u.resourceTiming=JSON.parse(JSON.stringify(f)))}s.vectorTile=a.vectorTile,s.parse(a.vectorTile,n.layerIndex,n.availableImages,n.actor,(function(e,n){if(e||!n)return r(e);r(null,t.extend({rawTileData:l.slice(0)},n,c,u))})),n.loaded=n.loaded||{},n.loaded[i]=s}))},l.prototype.reloadTile=function(t,e){var r=this,n=this.loaded,i=t.uid,a=this;if(n&&n[i]){var o=n[i];o.showCollisionBoxes=t.showCollisionBoxes;var s=function(t,n){var i=o.reloadCallback;i&&(delete o.reloadCallback,o.parse(o.vectorTile,a.layerIndex,r.availableImages,a.actor,i)),e(t,n)};"parsing"===o.status?o.reloadCallback=s:"done"===o.status&&(o.vectorTile?o.parse(o.vectorTile,this.layerIndex,this.availableImages,this.actor,s):s())}},l.prototype.abortTile=function(t,e){var r=this.loading,n=t.uid;r&&r[n]&&r[n].abort&&(r[n].abort(),delete r[n]),e()},l.prototype.removeTile=function(t,e){var r=this.loaded,n=t.uid;r&&r[n]&&delete r[n],e()};var c=t.window.ImageBitmap,u=function(){this.loaded={}};u.prototype.loadTile=function(e,r){var n=e.uid,i=e.encoding,a=e.rawImageData,o=c&&a instanceof c?this.getImageData(a):a,s=new t.DEMData(n,o,i);this.loaded=this.loaded||{},this.loaded[n]=s,r(null,s)},u.prototype.getImageData=function(e){this.offscreenCanvas&&this.offscreenCanvasContext||(this.offscreenCanvas=new OffscreenCanvas(e.width,e.height),this.offscreenCanvasContext=this.offscreenCanvas.getContext("2d")),this.offscreenCanvas.width=e.width,this.offscreenCanvas.height=e.height,this.offscreenCanvasContext.drawImage(e,0,0,e.width,e.height);var r=this.offscreenCanvasContext.getImageData(-1,-1,e.width+2,e.height+2);return this.offscreenCanvasContext.clearRect(0,0,this.offscreenCanvas.width,this.offscreenCanvas.height),new t.RGBAImage({width:r.width,height:r.height},r.data)},u.prototype.removeTile=function(t){var e=this.loaded,r=t.uid;e&&e[r]&&delete e[r]};var f=function t(e,r){var n,i=e&&e.type;if("FeatureCollection"===i)for(n=0;n<e.features.length;n++)t(e.features[n],r);else if("GeometryCollection"===i)for(n=0;n<e.geometries.length;n++)t(e.geometries[n],r);else if("Feature"===i)t(e.geometry,r);else if("Polygon"===i)h(e.coordinates,r);else if("MultiPolygon"===i)for(n=0;n<e.coordinates.length;n++)h(e.coordinates[n],r);return e};function h(t,e){if(0!==t.length){p(t[0],e);for(var r=1;r<t.length;r++)p(t[r],!e)}}function p(t,e){for(var r=0,n=0,i=t.length,a=i-1;n<i;a=n++)r+=(t[n][0]-t[a][0])*(t[a][1]+t[n][1]);r>=0!=!!e&&t.reverse()}var d=t.vectorTile.VectorTileFeature.prototype.toGeoJSON,m=function(e){this._feature=e,this.extent=t.EXTENT,this.type=e.type,this.properties=e.tags,"id"in e&&!isNaN(e.id)&&(this.id=parseInt(e.id,10))};m.prototype.loadGeometry=function(){if(1===this._feature.type){for(var e=[],r=0,n=this._feature.geometry;r<n.length;r+=1){var i=n[r];e.push([new t.Point$1(i[0],i[1])])}return e}for(var a=[],o=0,s=this._feature.geometry;o<s.length;o+=1){for(var l=[],c=0,u=s[o];c<u.length;c+=1){var f=u[c];l.push(new t.Point$1(f[0],f[1]))}a.push(l)}return a},m.prototype.toGeoJSON=function(t,e,r){return d.call(this,t,e,r)};var g=function(e){this.layers={_geojsonTileLayer:this},this.name="_geojsonTileLayer",this.extent=t.EXTENT,this.length=e.length,this._features=e};g.prototype.feature=function(t){return new m(this._features[t])};var v=t.vectorTile.VectorTileFeature,y=x;function x(t,e){this.options=e||{},this.features=t,this.length=t.length}function b(t,e){this.id="number"==typeof t.id?t.id:void 0,this.type=t.type,this.rawGeometry=1===t.type?[t.geometry]:t.geometry,this.properties=t.tags,this.extent=e||4096}x.prototype.feature=function(t){return new b(this.features[t],this.options.extent)},b.prototype.loadGeometry=function(){var e=this.rawGeometry;this.geometry=[];for(var r=0;r<e.length;r++){for(var n=e[r],i=[],a=0;a<n.length;a++)i.push(new t.Point$1(n[a][0],n[a][1]));this.geometry.push(i)}return this.geometry},b.prototype.bbox=function(){this.geometry||this.loadGeometry();for(var t=this.geometry,e=1/0,r=-1/0,n=1/0,i=-1/0,a=0;a<t.length;a++)for(var o=t[a],s=0;s<o.length;s++){var l=o[s];e=Math.min(e,l.x),r=Math.max(r,l.x),n=Math.min(n,l.y),i=Math.max(i,l.y)}return[e,n,r,i]},b.prototype.toGeoJSON=v.prototype.toGeoJSON;var _=A,w=A,T=function(t,e){e=e||{};var r={};for(var n in t)r[n]=new y(t[n].features,e),r[n].name=n,r[n].version=e.version,r[n].extent=e.extent;return A({layers:r})},k=y;function A(e){var r=new t.pbf;return function(t,e){for(var r in t.layers)e.writeMessage(3,M,t.layers[r])}(e,r),r.finish()}function M(t,e){var r;e.writeVarintField(15,t.version||1),e.writeStringField(1,t.name||""),e.writeVarintField(5,t.extent||4096);var n={keys:[],values:[],keycache:{},valuecache:{}};for(r=0;r<t.length;r++)n.feature=t.feature(r),e.writeMessage(2,S,n);var i=n.keys;for(r=0;r<i.length;r++)e.writeStringField(3,i[r]);var a=n.values;for(r=0;r<a.length;r++)e.writeMessage(4,I,a[r])}function S(t,e){var r=t.feature;void 0!==r.id&&e.writeVarintField(1,r.id),e.writeMessage(2,E,t),e.writeVarintField(3,r.type),e.writeMessage(4,P,r)}function E(t,e){var r=t.feature,n=t.keys,i=t.values,a=t.keycache,o=t.valuecache;for(var s in r.properties){var l=a[s];void 0===l&&(n.push(s),l=n.length-1,a[s]=l),e.writeVarint(l);var c=r.properties[s],u=typeof c;"string"!==u&&"boolean"!==u&&"number"!==u&&(c=JSON.stringify(c));var f=u+":"+c,h=o[f];void 0===h&&(i.push(c),h=i.length-1,o[f]=h),e.writeVarint(h)}}function L(t,e){return(e<<3)+(7&t)}function C(t){return t<<1^t>>31}function P(t,e){for(var r=t.loadGeometry(),n=t.type,i=0,a=0,o=r.length,s=0;s<o;s++){var l=r[s],c=1;1===n&&(c=l.length),e.writeVarint(L(1,c));for(var u=3===n?l.length-1:l.length,f=0;f<u;f++){1===f&&1!==n&&e.writeVarint(L(2,u-1));var h=l[f].x-i,p=l[f].y-a;e.writeVarint(C(h)),e.writeVarint(C(p)),i+=h,a+=p}3===n&&e.writeVarint(L(7,1))}}function I(t,e){var r=typeof t;"string"===r?e.writeStringField(1,t):"boolean"===r?e.writeBooleanField(7,t):"number"===r&&(t%1!=0?e.writeDoubleField(3,t):t<0?e.writeSVarintField(6,t):e.writeVarintField(5,t))}function O(t,e,r,n,i,a){if(!(i-n<=r)){var o=n+i>>1;!function t(e,r,n,i,a,o){for(;a>i;){if(a-i>600){var s=a-i+1,l=n-i+1,c=Math.log(s),u=.5*Math.exp(2*c/3),f=.5*Math.sqrt(c*u*(s-u)/s)*(l-s/2<0?-1:1),h=Math.max(i,Math.floor(n-l*u/s+f)),p=Math.min(a,Math.floor(n+(s-l)*u/s+f));t(e,r,n,h,p,o)}var d=r[2*n+o],m=i,g=a;for(z(e,r,i,n),r[2*a+o]>d&&z(e,r,i,a);m<g;){for(z(e,r,m,g),m++,g--;r[2*m+o]<d;)m++;for(;r[2*g+o]>d;)g--}r[2*i+o]===d?z(e,r,i,g):(g++,z(e,r,g,a)),g<=n&&(i=g+1),n<=g&&(a=g-1)}}(t,e,o,n,i,a%2),O(t,e,r,n,o-1,a+1),O(t,e,r,o+1,i,a+1)}}function z(t,e,r,n){D(t,r,n),D(e,2*r,2*n),D(e,2*r+1,2*n+1)}function D(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function R(t,e,r,n){var i=t-r,a=e-n;return i*i+a*a}_.fromVectorTileJs=w,_.fromGeojsonVt=T,_.GeoJSONWrapper=k;var F=function(t){return t[0]},B=function(t){return t[1]},N=function(t,e,r,n,i){void 0===e&&(e=F),void 0===r&&(r=B),void 0===n&&(n=64),void 0===i&&(i=Float64Array),this.nodeSize=n,this.points=t;for(var a=t.length<65536?Uint16Array:Uint32Array,o=this.ids=new a(t.length),s=this.coords=new i(2*t.length),l=0;l<t.length;l++)o[l]=l,s[2*l]=e(t[l]),s[2*l+1]=r(t[l]);O(o,s,n,0,o.length-1,0)};N.prototype.range=function(t,e,r,n){return function(t,e,r,n,i,a,o){for(var s,l,c=[0,t.length-1,0],u=[];c.length;){var f=c.pop(),h=c.pop(),p=c.pop();if(h-p<=o)for(var d=p;d<=h;d++)s=e[2*d],l=e[2*d+1],s>=r&&s<=i&&l>=n&&l<=a&&u.push(t[d]);else{var m=Math.floor((p+h)/2);s=e[2*m],l=e[2*m+1],s>=r&&s<=i&&l>=n&&l<=a&&u.push(t[m]);var g=(f+1)%2;(0===f?r<=s:n<=l)&&(c.push(p),c.push(m-1),c.push(g)),(0===f?i>=s:a>=l)&&(c.push(m+1),c.push(h),c.push(g))}}return u}(this.ids,this.coords,t,e,r,n,this.nodeSize)},N.prototype.within=function(t,e,r){return function(t,e,r,n,i,a){for(var o=[0,t.length-1,0],s=[],l=i*i;o.length;){var c=o.pop(),u=o.pop(),f=o.pop();if(u-f<=a)for(var h=f;h<=u;h++)R(e[2*h],e[2*h+1],r,n)<=l&&s.push(t[h]);else{var p=Math.floor((f+u)/2),d=e[2*p],m=e[2*p+1];R(d,m,r,n)<=l&&s.push(t[p]);var g=(c+1)%2;(0===c?r-i<=d:n-i<=m)&&(o.push(f),o.push(p-1),o.push(g)),(0===c?r+i>=d:n+i>=m)&&(o.push(p+1),o.push(u),o.push(g))}}return s}(this.ids,this.coords,t,e,r,this.nodeSize)};var j={minZoom:0,maxZoom:16,radius:40,extent:512,nodeSize:64,log:!1,generateId:!1,reduce:null,map:function(t){return t}},U=function(t){this.options=X(Object.create(j),t),this.trees=new Array(this.options.maxZoom+1)};function V(t,e,r,n,i){return{x:t,y:e,zoom:1/0,id:r,parentId:-1,numPoints:n,properties:i}}function H(t,e){var r=t.geometry.coordinates,n=r[0],i=r[1];return{x:Y(n),y:W(i),zoom:1/0,index:e,parentId:-1}}function q(t){return{type:"Feature",id:t.id,properties:G(t),geometry:{type:"Point",coordinates:[(n=t.x,360*(n-.5)),(e=t.y,r=(180-360*e)*Math.PI/180,360*Math.atan(Math.exp(r))/Math.PI-90)]}};var e,r,n}function G(t){var e=t.numPoints,r=e>=1e4?Math.round(e/1e3)+"k":e>=1e3?Math.round(e/100)/10+"k":e;return X(X({},t.properties),{cluster:!0,cluster_id:t.id,point_count:e,point_count_abbreviated:r})}function Y(t){return t/360+.5}function W(t){var e=Math.sin(t*Math.PI/180),r=.5-.25*Math.log((1+e)/(1-e))/Math.PI;return r<0?0:r>1?1:r}function X(t,e){for(var r in e)t[r]=e[r];return t}function Z(t){return t.x}function J(t){return t.y}function K(t,e,r,n,i,a){var o=i-r,s=a-n;if(0!==o||0!==s){var l=((t-r)*o+(e-n)*s)/(o*o+s*s);l>1?(r=i,n=a):l>0&&(r+=o*l,n+=s*l)}return(o=t-r)*o+(s=e-n)*s}function Q(t,e,r,n){var i={id:void 0===t?null:t,type:e,geometry:r,tags:n,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};return function(t){var e=t.geometry,r=t.type;if("Point"===r||"MultiPoint"===r||"LineString"===r)$(t,e);else if("Polygon"===r||"MultiLineString"===r)for(var n=0;n<e.length;n++)$(t,e[n]);else if("MultiPolygon"===r)for(n=0;n<e.length;n++)for(var i=0;i<e[n].length;i++)$(t,e[n][i])}(i),i}function $(t,e){for(var r=0;r<e.length;r+=3)t.minX=Math.min(t.minX,e[r]),t.minY=Math.min(t.minY,e[r+1]),t.maxX=Math.max(t.maxX,e[r]),t.maxY=Math.max(t.maxY,e[r+1])}function tt(t,e,r,n){if(e.geometry){var i=e.geometry.coordinates,a=e.geometry.type,o=Math.pow(r.tolerance/((1<<r.maxZoom)*r.extent),2),s=[],l=e.id;if(r.promoteId?l=e.properties[r.promoteId]:r.generateId&&(l=n||0),"Point"===a)et(i,s);else if("MultiPoint"===a)for(var c=0;c<i.length;c++)et(i[c],s);else if("LineString"===a)rt(i,s,o,!1);else if("MultiLineString"===a){if(r.lineMetrics){for(c=0;c<i.length;c++)s=[],rt(i[c],s,o,!1),t.push(Q(l,"LineString",s,e.properties));return}nt(i,s,o,!1)}else if("Polygon"===a)nt(i,s,o,!0);else{if("MultiPolygon"!==a){if("GeometryCollection"===a){for(c=0;c<e.geometry.geometries.length;c++)tt(t,{id:l,geometry:e.geometry.geometries[c],properties:e.properties},r,n);return}throw new Error("Input data is not a valid GeoJSON object.")}for(c=0;c<i.length;c++){var u=[];nt(i[c],u,o,!0),s.push(u)}}t.push(Q(l,a,s,e.properties))}}function et(t,e){e.push(it(t[0])),e.push(at(t[1])),e.push(0)}function rt(t,e,r,n){for(var i,a,o=0,s=0;s<t.length;s++){var l=it(t[s][0]),c=at(t[s][1]);e.push(l),e.push(c),e.push(0),s>0&&(o+=n?(i*c-l*a)/2:Math.sqrt(Math.pow(l-i,2)+Math.pow(c-a,2))),i=l,a=c}var u=e.length-3;e[2]=1,function t(e,r,n,i){for(var a,o=i,s=n-r>>1,l=n-r,c=e[r],u=e[r+1],f=e[n],h=e[n+1],p=r+3;p<n;p+=3){var d=K(e[p],e[p+1],c,u,f,h);if(d>o)a=p,o=d;else if(d===o){var m=Math.abs(p-s);m<l&&(a=p,l=m)}}o>i&&(a-r>3&&t(e,r,a,i),e[a+2]=o,n-a>3&&t(e,a,n,i))}(e,0,u,r),e[u+2]=1,e.size=Math.abs(o),e.start=0,e.end=e.size}function nt(t,e,r,n){for(var i=0;i<t.length;i++){var a=[];rt(t[i],a,r,n),e.push(a)}}function it(t){return t/360+.5}function at(t){var e=Math.sin(t*Math.PI/180),r=.5-.25*Math.log((1+e)/(1-e))/Math.PI;return r<0?0:r>1?1:r}function ot(t,e,r,n,i,a,o,s){if(n/=e,a>=(r/=e)&&o<n)return t;if(o<r||a>=n)return null;for(var l=[],c=0;c<t.length;c++){var u=t[c],f=u.geometry,h=u.type,p=0===i?u.minX:u.minY,d=0===i?u.maxX:u.maxY;if(p>=r&&d<n)l.push(u);else if(!(d<r||p>=n)){var m=[];if("Point"===h||"MultiPoint"===h)st(f,m,r,n,i);else if("LineString"===h)lt(f,m,r,n,i,!1,s.lineMetrics);else if("MultiLineString"===h)ut(f,m,r,n,i,!1);else if("Polygon"===h)ut(f,m,r,n,i,!0);else if("MultiPolygon"===h)for(var g=0;g<f.length;g++){var v=[];ut(f[g],v,r,n,i,!0),v.length&&m.push(v)}if(m.length){if(s.lineMetrics&&"LineString"===h){for(g=0;g<m.length;g++)l.push(Q(u.id,h,m[g],u.tags));continue}"LineString"!==h&&"MultiLineString"!==h||(1===m.length?(h="LineString",m=m[0]):h="MultiLineString"),"Point"!==h&&"MultiPoint"!==h||(h=3===m.length?"Point":"MultiPoint"),l.push(Q(u.id,h,m,u.tags))}}}return l.length?l:null}function st(t,e,r,n,i){for(var a=0;a<t.length;a+=3){var o=t[a+i];o>=r&&o<=n&&(e.push(t[a]),e.push(t[a+1]),e.push(t[a+2]))}}function lt(t,e,r,n,i,a,o){for(var s,l,c=ct(t),u=0===i?ht:pt,f=t.start,h=0;h<t.length-3;h+=3){var p=t[h],d=t[h+1],m=t[h+2],g=t[h+3],v=t[h+4],y=0===i?p:d,x=0===i?g:v,b=!1;o&&(s=Math.sqrt(Math.pow(p-g,2)+Math.pow(d-v,2))),y<r?x>r&&(l=u(c,p,d,g,v,r),o&&(c.start=f+s*l)):y>n?x<n&&(l=u(c,p,d,g,v,n),o&&(c.start=f+s*l)):ft(c,p,d,m),x<r&&y>=r&&(l=u(c,p,d,g,v,r),b=!0),x>n&&y<=n&&(l=u(c,p,d,g,v,n),b=!0),!a&&b&&(o&&(c.end=f+s*l),e.push(c),c=ct(t)),o&&(f+=s)}var _=t.length-3;p=t[_],d=t[_+1],m=t[_+2],(y=0===i?p:d)>=r&&y<=n&&ft(c,p,d,m),_=c.length-3,a&&_>=3&&(c[_]!==c[0]||c[_+1]!==c[1])&&ft(c,c[0],c[1],c[2]),c.length&&e.push(c)}function ct(t){var e=[];return e.size=t.size,e.start=t.start,e.end=t.end,e}function ut(t,e,r,n,i,a){for(var o=0;o<t.length;o++)lt(t[o],e,r,n,i,a,!1)}function ft(t,e,r,n){t.push(e),t.push(r),t.push(n)}function ht(t,e,r,n,i,a){var o=(a-e)/(n-e);return t.push(a),t.push(r+(i-r)*o),t.push(1),o}function pt(t,e,r,n,i,a){var o=(a-r)/(i-r);return t.push(e+(n-e)*o),t.push(a),t.push(1),o}function dt(t,e){for(var r=[],n=0;n<t.length;n++){var i,a=t[n],o=a.type;if("Point"===o||"MultiPoint"===o||"LineString"===o)i=mt(a.geometry,e);else if("MultiLineString"===o||"Polygon"===o){i=[];for(var s=0;s<a.geometry.length;s++)i.push(mt(a.geometry[s],e))}else if("MultiPolygon"===o)for(i=[],s=0;s<a.geometry.length;s++){for(var l=[],c=0;c<a.geometry[s].length;c++)l.push(mt(a.geometry[s][c],e));i.push(l)}r.push(Q(a.id,o,i,a.tags))}return r}function mt(t,e){var r=[];r.size=t.size,void 0!==t.start&&(r.start=t.start,r.end=t.end);for(var n=0;n<t.length;n+=3)r.push(t[n]+e,t[n+1],t[n+2]);return r}function gt(t,e){if(t.transformed)return t;var r,n,i,a=1<<t.z,o=t.x,s=t.y;for(r=0;r<t.features.length;r++){var l=t.features[r],c=l.geometry,u=l.type;if(l.geometry=[],1===u)for(n=0;n<c.length;n+=2)l.geometry.push(vt(c[n],c[n+1],e,a,o,s));else for(n=0;n<c.length;n++){var f=[];for(i=0;i<c[n].length;i+=2)f.push(vt(c[n][i],c[n][i+1],e,a,o,s));l.geometry.push(f)}}return t.transformed=!0,t}function vt(t,e,r,n,i,a){return[Math.round(r*(t*n-i)),Math.round(r*(e*n-a))]}function yt(t,e,r,n,i){for(var a=e===i.maxZoom?0:i.tolerance/((1<<e)*i.extent),o={features:[],numPoints:0,numSimplified:0,numFeatures:0,source:null,x:r,y:n,z:e,transformed:!1,minX:2,minY:1,maxX:-1,maxY:0},s=0;s<t.length;s++){o.numFeatures++,xt(o,t[s],a,i);var l=t[s].minX,c=t[s].minY,u=t[s].maxX,f=t[s].maxY;l<o.minX&&(o.minX=l),c<o.minY&&(o.minY=c),u>o.maxX&&(o.maxX=u),f>o.maxY&&(o.maxY=f)}return o}function xt(t,e,r,n){var i=e.geometry,a=e.type,o=[];if("Point"===a||"MultiPoint"===a)for(var s=0;s<i.length;s+=3)o.push(i[s]),o.push(i[s+1]),t.numPoints++,t.numSimplified++;else if("LineString"===a)bt(o,i,t,r,!1,!1);else if("MultiLineString"===a||"Polygon"===a)for(s=0;s<i.length;s++)bt(o,i[s],t,r,"Polygon"===a,0===s);else if("MultiPolygon"===a)for(var l=0;l<i.length;l++){var c=i[l];for(s=0;s<c.length;s++)bt(o,c[s],t,r,!0,0===s)}if(o.length){var u=e.tags||null;if("LineString"===a&&n.lineMetrics){for(var f in u={},e.tags)u[f]=e.tags[f];u.mapbox_clip_start=i.start/i.size,u.mapbox_clip_end=i.end/i.size}var h={geometry:o,type:"Polygon"===a||"MultiPolygon"===a?3:"LineString"===a||"MultiLineString"===a?2:1,tags:u};null!==e.id&&(h.id=e.id),t.features.push(h)}}function bt(t,e,r,n,i,a){var o=n*n;if(n>0&&e.size<(i?o:n))r.numPoints+=e.length/3;else{for(var s=[],l=0;l<e.length;l+=3)(0===n||e[l+2]>o)&&(r.numSimplified++,s.push(e[l]),s.push(e[l+1])),r.numPoints++;i&&function(t,e){for(var r=0,n=0,i=t.length,a=i-2;n<i;a=n,n+=2)r+=(t[n]-t[a])*(t[n+1]+t[a+1]);if(r>0===e)for(n=0,i=t.length;n<i/2;n+=2){var o=t[n],s=t[n+1];t[n]=t[i-2-n],t[n+1]=t[i-1-n],t[i-2-n]=o,t[i-1-n]=s}}(s,a),t.push(s)}}function _t(t,e){var r=(e=this.options=function(t,e){for(var r in e)t[r]=e[r];return t}(Object.create(this.options),e)).debug;if(r&&console.time("preprocess data"),e.maxZoom<0||e.maxZoom>24)throw new Error("maxZoom should be in the 0-24 range");if(e.promoteId&&e.generateId)throw new Error("promoteId and generateId cannot be used together.");var n=function(t,e){var r=[];if("FeatureCollection"===t.type)for(var n=0;n<t.features.length;n++)tt(r,t.features[n],e,n);else"Feature"===t.type?tt(r,t,e):tt(r,{geometry:t},e);return r}(t,e);this.tiles={},this.tileCoords=[],r&&(console.timeEnd("preprocess data"),console.log("index: maxZoom: %d, maxPoints: %d",e.indexMaxZoom,e.indexMaxPoints),console.time("generate tiles"),this.stats={},this.total=0),(n=function(t,e){var r=e.buffer/e.extent,n=t,i=ot(t,1,-1-r,r,0,-1,2,e),a=ot(t,1,1-r,2+r,0,-1,2,e);return(i||a)&&(n=ot(t,1,-r,1+r,0,-1,2,e)||[],i&&(n=dt(i,1).concat(n)),a&&(n=n.concat(dt(a,-1)))),n}(n,e)).length&&this.splitTile(n,0,0,0),r&&(n.length&&console.log("features: %d, points: %d",this.tiles[0].numFeatures,this.tiles[0].numPoints),console.timeEnd("generate tiles"),console.log("tiles generated:",this.total,JSON.stringify(this.stats)))}function wt(t,e,r){return 32*((1<<t)*r+e)+t}function Tt(t,e){var r=t.tileID.canonical;if(!this._geoJSONIndex)return e(null,null);var n=this._geoJSONIndex.getTile(r.z,r.x,r.y);if(!n)return e(null,null);var i=new g(n.features),a=_(i);0===a.byteOffset&&a.byteLength===a.buffer.byteLength||(a=new Uint8Array(a)),e(null,{vectorTile:i,rawData:a.buffer})}U.prototype.load=function(t){var e=this.options,r=e.log,n=e.minZoom,i=e.maxZoom,a=e.nodeSize;r&&console.time("total time");var o="prepare "+t.length+" points";r&&console.time(o),this.points=t;for(var s=[],l=0;l<t.length;l++)t[l].geometry&&s.push(H(t[l],l));this.trees[i+1]=new N(s,Z,J,a,Float32Array),r&&console.timeEnd(o);for(var c=i;c>=n;c--){var u=+Date.now();s=this._cluster(s,c),this.trees[c]=new N(s,Z,J,a,Float32Array),r&&console.log("z%d: %d clusters in %dms",c,s.length,+Date.now()-u)}return r&&console.timeEnd("total time"),this},U.prototype.getClusters=function(t,e){var r=((t[0]+180)%360+360)%360-180,n=Math.max(-90,Math.min(90,t[1])),i=180===t[2]?180:((t[2]+180)%360+360)%360-180,a=Math.max(-90,Math.min(90,t[3]));if(t[2]-t[0]>=360)r=-180,i=180;else if(r>i){var o=this.getClusters([r,n,180,a],e),s=this.getClusters([-180,n,i,a],e);return o.concat(s)}for(var l=this.trees[this._limitZoom(e)],c=[],u=0,f=l.range(Y(r),W(a),Y(i),W(n));u<f.length;u+=1){var h=f[u],p=l.points[h];c.push(p.numPoints?q(p):this.points[p.index])}return c},U.prototype.getChildren=function(t){var e=this._getOriginId(t),r=this._getOriginZoom(t),n="No cluster with the specified id.",i=this.trees[r];if(!i)throw new Error(n);var a=i.points[e];if(!a)throw new Error(n);for(var o=this.options.radius/(this.options.extent*Math.pow(2,r-1)),s=[],l=0,c=i.within(a.x,a.y,o);l<c.length;l+=1){var u=c[l],f=i.points[u];f.parentId===t&&s.push(f.numPoints?q(f):this.points[f.index])}if(0===s.length)throw new Error(n);return s},U.prototype.getLeaves=function(t,e,r){e=e||10,r=r||0;var n=[];return this._appendLeaves(n,t,e,r,0),n},U.prototype.getTile=function(t,e,r){var n=this.trees[this._limitZoom(t)],i=Math.pow(2,t),a=this.options,o=a.extent,s=a.radius/o,l=(r-s)/i,c=(r+1+s)/i,u={features:[]};return this._addTileFeatures(n.range((e-s)/i,l,(e+1+s)/i,c),n.points,e,r,i,u),0===e&&this._addTileFeatures(n.range(1-s/i,l,1,c),n.points,i,r,i,u),e===i-1&&this._addTileFeatures(n.range(0,l,s/i,c),n.points,-1,r,i,u),u.features.length?u:null},U.prototype.getClusterExpansionZoom=function(t){for(var e=this._getOriginZoom(t)-1;e<=this.options.maxZoom;){var r=this.getChildren(t);if(e++,1!==r.length)break;t=r[0].properties.cluster_id}return e},U.prototype._appendLeaves=function(t,e,r,n,i){for(var a=0,o=this.getChildren(e);a<o.length;a+=1){var s=o[a],l=s.properties;if(l&&l.cluster?i+l.point_count<=n?i+=l.point_count:i=this._appendLeaves(t,l.cluster_id,r,n,i):i<n?i++:t.push(s),t.length===r)break}return i},U.prototype._addTileFeatures=function(t,e,r,n,i,a){for(var o=0,s=t;o<s.length;o+=1){var l=e[s[o]],c=l.numPoints,u={type:1,geometry:[[Math.round(this.options.extent*(l.x*i-r)),Math.round(this.options.extent*(l.y*i-n))]],tags:c?G(l):this.points[l.index].properties},f=void 0;c?f=l.id:this.options.generateId?f=l.index:this.points[l.index].id&&(f=this.points[l.index].id),void 0!==f&&(u.id=f),a.features.push(u)}},U.prototype._limitZoom=function(t){return Math.max(this.options.minZoom,Math.min(t,this.options.maxZoom+1))},U.prototype._cluster=function(t,e){for(var r=[],n=this.options,i=n.radius,a=n.extent,o=n.reduce,s=i/(a*Math.pow(2,e)),l=0;l<t.length;l++){var c=t[l];if(!(c.zoom<=e)){c.zoom=e;for(var u=this.trees[e+1],f=u.within(c.x,c.y,s),h=c.numPoints||1,p=c.x*h,d=c.y*h,m=o&&h>1?this._map(c,!0):null,g=(l<<5)+(e+1)+this.points.length,v=0,y=f;v<y.length;v+=1){var x=y[v],b=u.points[x];if(!(b.zoom<=e)){b.zoom=e;var _=b.numPoints||1;p+=b.x*_,d+=b.y*_,h+=_,b.parentId=g,o&&(m||(m=this._map(c,!0)),o(m,this._map(b)))}}1===h?r.push(c):(c.parentId=g,r.push(V(p/h,d/h,g,h,m)))}}return r},U.prototype._getOriginId=function(t){return t-this.points.length>>5},U.prototype._getOriginZoom=function(t){return(t-this.points.length)%32},U.prototype._map=function(t,e){if(t.numPoints)return e?X({},t.properties):t.properties;var r=this.points[t.index].properties,n=this.options.map(r);return e&&n===r?X({},n):n},_t.prototype.options={maxZoom:14,indexMaxZoom:5,indexMaxPoints:1e5,tolerance:3,extent:4096,buffer:64,lineMetrics:!1,promoteId:null,generateId:!1,debug:0},_t.prototype.splitTile=function(t,e,r,n,i,a,o){for(var s=[t,e,r,n],l=this.options,c=l.debug;s.length;){n=s.pop(),r=s.pop(),e=s.pop(),t=s.pop();var u=1<<e,f=wt(e,r,n),h=this.tiles[f];if(!h&&(c>1&&console.time("creation"),h=this.tiles[f]=yt(t,e,r,n,l),this.tileCoords.push({z:e,x:r,y:n}),c)){c>1&&(console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",e,r,n,h.numFeatures,h.numPoints,h.numSimplified),console.timeEnd("creation"));var p="z"+e;this.stats[p]=(this.stats[p]||0)+1,this.total++}if(h.source=t,i){if(e===l.maxZoom||e===i)continue;var d=1<<i-e;if(r!==Math.floor(a/d)||n!==Math.floor(o/d))continue}else if(e===l.indexMaxZoom||h.numPoints<=l.indexMaxPoints)continue;if(h.source=null,0!==t.length){c>1&&console.time("clipping");var m,g,v,y,x,b,_=.5*l.buffer/l.extent,w=.5-_,T=.5+_,k=1+_;m=g=v=y=null,x=ot(t,u,r-_,r+T,0,h.minX,h.maxX,l),b=ot(t,u,r+w,r+k,0,h.minX,h.maxX,l),t=null,x&&(m=ot(x,u,n-_,n+T,1,h.minY,h.maxY,l),g=ot(x,u,n+w,n+k,1,h.minY,h.maxY,l),x=null),b&&(v=ot(b,u,n-_,n+T,1,h.minY,h.maxY,l),y=ot(b,u,n+w,n+k,1,h.minY,h.maxY,l),b=null),c>1&&console.timeEnd("clipping"),s.push(m||[],e+1,2*r,2*n),s.push(g||[],e+1,2*r,2*n+1),s.push(v||[],e+1,2*r+1,2*n),s.push(y||[],e+1,2*r+1,2*n+1)}}},_t.prototype.getTile=function(t,e,r){var n=this.options,i=n.extent,a=n.debug;if(t<0||t>24)return null;var o=1<<t,s=wt(t,e=(e%o+o)%o,r);if(this.tiles[s])return gt(this.tiles[s],i);a>1&&console.log("drilling down to z%d-%d-%d",t,e,r);for(var l,c=t,u=e,f=r;!l&&c>0;)c--,u=Math.floor(u/2),f=Math.floor(f/2),l=this.tiles[wt(c,u,f)];return l&&l.source?(a>1&&console.log("found parent tile z%d-%d-%d",c,u,f),a>1&&console.time("drilling down"),this.splitTile(l.source,c,u,f,t,e,r),a>1&&console.timeEnd("drilling down"),this.tiles[s]?gt(this.tiles[s],i):null):null};var kt=function(e){function r(t,r,n,i){e.call(this,t,r,n,Tt),i&&(this.loadGeoJSON=i)}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.loadData=function(t,e){this._pendingCallback&&this._pendingCallback(null,{abandoned:!0}),this._pendingCallback=e,this._pendingLoadDataParams=t,this._state&&"Idle"!==this._state?this._state="NeedsLoadData":(this._state="Coalescing",this._loadData())},r.prototype._loadData=function(){var e=this;if(this._pendingCallback&&this._pendingLoadDataParams){var r=this._pendingCallback,n=this._pendingLoadDataParams;delete this._pendingCallback,delete this._pendingLoadDataParams;var i=!!(n&&n.request&&n.request.collectResourceTiming)&&new t.RequestPerformance(n.request);this.loadGeoJSON(n,(function(a,o){if(a||!o)return r(a);if("object"!=typeof o)return r(new Error("Input data given to '"+n.source+"' is not a valid GeoJSON object."));f(o,!0);try{e._geoJSONIndex=n.cluster?new U(function(e){var r=e.superclusterOptions,n=e.clusterProperties;if(!n||!r)return r;for(var i={},a={},o={accumulated:null,zoom:0},s={properties:null},l=Object.keys(n),c=0,u=l;c<u.length;c+=1){var f=u[c],h=n[f],p=h[0],d=h[1],m=t.createExpression(d),g=t.createExpression("string"==typeof p?[p,["accumulated"],["get",f]]:p);i[f]=m.value,a[f]=g.value}return r.map=function(t){s.properties=t;for(var e={},r=0,n=l;r<n.length;r+=1){var a=n[r];e[a]=i[a].evaluate(o,s)}return e},r.reduce=function(t,e){s.properties=e;for(var r=0,n=l;r<n.length;r+=1){var i=n[r];o.accumulated=t[i],t[i]=a[i].evaluate(o,s)}},r}(n)).load(o.features):function(t,e){return new _t(t,e)}(o,n.geojsonVtOptions)}catch(a){return r(a)}e.loaded={};var s={};if(i){var l=i.finish();l&&(s.resourceTiming={},s.resourceTiming[n.source]=JSON.parse(JSON.stringify(l)))}r(null,s)}))}},r.prototype.coalesce=function(){"Coalescing"===this._state?this._state="Idle":"NeedsLoadData"===this._state&&(this._state="Coalescing",this._loadData())},r.prototype.reloadTile=function(t,r){var n=this.loaded,i=t.uid;return n&&n[i]?e.prototype.reloadTile.call(this,t,r):this.loadTile(t,r)},r.prototype.loadGeoJSON=function(e,r){if(e.request)t.getJSON(e.request,r);else{if("string"!=typeof e.data)return r(new Error("Input data given to '"+e.source+"' is not a valid GeoJSON object."));try{return r(null,JSON.parse(e.data))}catch(t){return r(new Error("Input data given to '"+e.source+"' is not a valid GeoJSON object."))}}},r.prototype.removeSource=function(t,e){this._pendingCallback&&this._pendingCallback(null,{abandoned:!0}),e()},r.prototype.getClusterExpansionZoom=function(t,e){try{e(null,this._geoJSONIndex.getClusterExpansionZoom(t.clusterId))}catch(t){e(t)}},r.prototype.getClusterChildren=function(t,e){try{e(null,this._geoJSONIndex.getChildren(t.clusterId))}catch(t){e(t)}},r.prototype.getClusterLeaves=function(t,e){try{e(null,this._geoJSONIndex.getLeaves(t.clusterId,t.limit,t.offset))}catch(t){e(t)}},r}(l);var At=function(e){var r=this;this.self=e,this.actor=new t.Actor(e,this),this.layerIndexes={},this.availableImages={},this.workerSourceTypes={vector:l,geojson:kt},this.workerSources={},this.demWorkerSources={},this.self.registerWorkerSource=function(t,e){if(r.workerSourceTypes[t])throw new Error('Worker source with name "'+t+'" already registered.');r.workerSourceTypes[t]=e},this.self.registerRTLTextPlugin=function(e){if(t.plugin.isParsed())throw new Error("RTL text plugin already registered.");t.plugin.applyArabicShaping=e.applyArabicShaping,t.plugin.processBidirectionalText=e.processBidirectionalText,t.plugin.processStyledBidirectionalText=e.processStyledBidirectionalText}};return At.prototype.setReferrer=function(t,e){this.referrer=e},At.prototype.setImages=function(t,e,r){for(var n in this.availableImages[t]=e,this.workerSources[t]){var i=this.workerSources[t][n];for(var a in i)i[a].availableImages=e}r()},At.prototype.setLayers=function(t,e,r){this.getLayerIndex(t).replace(e),r()},At.prototype.updateLayers=function(t,e,r){this.getLayerIndex(t).update(e.layers,e.removedIds),r()},At.prototype.loadTile=function(t,e,r){this.getWorkerSource(t,e.type,e.source).loadTile(e,r)},At.prototype.loadDEMTile=function(t,e,r){this.getDEMWorkerSource(t,e.source).loadTile(e,r)},At.prototype.reloadTile=function(t,e,r){this.getWorkerSource(t,e.type,e.source).reloadTile(e,r)},At.prototype.abortTile=function(t,e,r){this.getWorkerSource(t,e.type,e.source).abortTile(e,r)},At.prototype.removeTile=function(t,e,r){this.getWorkerSource(t,e.type,e.source).removeTile(e,r)},At.prototype.removeDEMTile=function(t,e){this.getDEMWorkerSource(t,e.source).removeTile(e)},At.prototype.removeSource=function(t,e,r){if(this.workerSources[t]&&this.workerSources[t][e.type]&&this.workerSources[t][e.type][e.source]){var n=this.workerSources[t][e.type][e.source];delete this.workerSources[t][e.type][e.source],void 0!==n.removeSource?n.removeSource(e,r):r()}},At.prototype.loadWorkerSource=function(t,e,r){try{this.self.importScripts(e.url),r()}catch(t){r(t.toString())}},At.prototype.syncRTLPluginState=function(e,r,n){try{t.plugin.setState(r);var i=t.plugin.getPluginURL();if(t.plugin.isLoaded()&&!t.plugin.isParsed()&&null!=i){this.self.importScripts(i);var a=t.plugin.isParsed();n(a?void 0:new Error("RTL Text Plugin failed to import scripts from "+i),a)}}catch(t){n(t.toString())}},At.prototype.getAvailableImages=function(t){var e=this.availableImages[t];return e||(e=[]),e},At.prototype.getLayerIndex=function(t){var e=this.layerIndexes[t];return e||(e=this.layerIndexes[t]=new n),e},At.prototype.getWorkerSource=function(t,e,r){var n=this;if(this.workerSources[t]||(this.workerSources[t]={}),this.workerSources[t][e]||(this.workerSources[t][e]={}),!this.workerSources[t][e][r]){var i={send:function(e,r,i){n.actor.send(e,r,i,t)}};this.workerSources[t][e][r]=new this.workerSourceTypes[e](i,this.getLayerIndex(t),this.getAvailableImages(t))}return this.workerSources[t][e][r]},At.prototype.getDEMWorkerSource=function(t,e){return this.demWorkerSources[t]||(this.demWorkerSources[t]={}),this.demWorkerSources[t][e]||(this.demWorkerSources[t][e]=new u),this.demWorkerSources[t][e]},At.prototype.enforceCacheSizeLimit=function(e,r){t.enforceCacheSizeLimit(r)},"undefined"!=typeof WorkerGlobalScope&&void 0!==t.window&&t.window instanceof WorkerGlobalScope&&(t.window.worker=new At(t.window)),At})),n(0,(function(t){var e=t.createCommonjsModule((function(t){function e(t){return!r(t)}function r(t){return"undefined"==typeof window||"undefined"==typeof document?"not a browser":Array.prototype&&Array.prototype.every&&Array.prototype.filter&&Array.prototype.forEach&&Array.prototype.indexOf&&Array.prototype.lastIndexOf&&Array.prototype.map&&Array.prototype.some&&Array.prototype.reduce&&Array.prototype.reduceRight&&Array.isArray?Function.prototype&&Function.prototype.bind?Object.keys&&Object.create&&Object.getPrototypeOf&&Object.getOwnPropertyNames&&Object.isSealed&&Object.isFrozen&&Object.isExtensible&&Object.getOwnPropertyDescriptor&&Object.defineProperty&&Object.defineProperties&&Object.seal&&Object.freeze&&Object.preventExtensions?"JSON"in window&&"parse"in JSON&&"stringify"in JSON?function(){if(!("Worker"in window&&"Blob"in window&&"URL"in window))return!1;var t,e,r=new Blob([""],{type:"text/javascript"}),n=URL.createObjectURL(r);try{e=new Worker(n),t=!0}catch(e){t=!1}e&&e.terminate();return URL.revokeObjectURL(n),t}()?"Uint8ClampedArray"in window?ArrayBuffer.isView?function(){var t=document.createElement("canvas");t.width=t.height=1;var e=t.getContext("2d");if(!e)return!1;var r=e.getImageData(0,0,1,1);return r&&r.width===t.width}()?function(t){void 0===n[t]&&(n[t]=function(t){var r=function(t){var r=document.createElement("canvas"),n=Object.create(e.webGLContextAttributes);return n.failIfMajorPerformanceCaveat=t,r.probablySupportsContext?r.probablySupportsContext("webgl",n)||r.probablySupportsContext("experimental-webgl",n):r.supportsContext?r.supportsContext("webgl",n)||r.supportsContext("experimental-webgl",n):r.getContext("webgl",n)||r.getContext("experimental-webgl",n)}(t);if(!r)return!1;var n=r.createShader(r.VERTEX_SHADER);if(!n||r.isContextLost())return!1;return r.shaderSource(n,"void main() {}"),r.compileShader(n),!0===r.getShaderParameter(n,r.COMPILE_STATUS)}(t));return n[t]}(t&&t.failIfMajorPerformanceCaveat)?void 0:"insufficient WebGL support":"insufficient Canvas/getImageData support":"insufficient ArrayBuffer support":"insufficient Uint8ClampedArray support":"insufficient worker support":"insufficient JSON support":"insufficient Object support":"insufficient Function support":"insufficent Array support"}t.exports?t.exports=e:window&&(window.mapboxgl=window.mapboxgl||{},window.mapboxgl.supported=e,window.mapboxgl.notSupportedReason=r);var n={};e.webGLContextAttributes={antialias:!1,alpha:!0,stencil:!0,depth:!0}})),r={create:function(e,r,n){var i=t.window.document.createElement(e);return void 0!==r&&(i.className=r),n&&n.appendChild(i),i},createNS:function(e,r){return t.window.document.createElementNS(e,r)}},n=t.window.document.documentElement.style;function i(t){if(!n)return t[0];for(var e=0;e<t.length;e++)if(t[e]in n)return t[e];return t[0]}var a,o=i(["userSelect","MozUserSelect","WebkitUserSelect","msUserSelect"]);r.disableDrag=function(){n&&o&&(a=n[o],n[o]="none")},r.enableDrag=function(){n&&o&&(n[o]=a)};var s=i(["transform","WebkitTransform"]);r.setTransform=function(t,e){t.style[s]=e};var l=!1;try{var c=Object.defineProperty({},"passive",{get:function(){l=!0}});t.window.addEventListener("test",c,c),t.window.removeEventListener("test",c,c)}catch(t){l=!1}r.addEventListener=function(t,e,r,n){void 0===n&&(n={}),"passive"in n&&l?t.addEventListener(e,r,n):t.addEventListener(e,r,n.capture)},r.removeEventListener=function(t,e,r,n){void 0===n&&(n={}),"passive"in n&&l?t.removeEventListener(e,r,n):t.removeEventListener(e,r,n.capture)};var u=function(e){e.preventDefault(),e.stopPropagation(),t.window.removeEventListener("click",u,!0)};function f(t){var e=t.userImage;if(e&&e.render&&e.render())return t.data.replace(new Uint8Array(e.data.buffer)),!0;return!1}r.suppressClick=function(){t.window.addEventListener("click",u,!0),t.window.setTimeout((function(){t.window.removeEventListener("click",u,!0)}),0)},r.mousePos=function(e,r){var n=e.getBoundingClientRect();return new t.Point(r.clientX-n.left-e.clientLeft,r.clientY-n.top-e.clientTop)},r.touchPos=function(e,r){for(var n=e.getBoundingClientRect(),i=[],a=0;a<r.length;a++)i.push(new t.Point(r[a].clientX-n.left-e.clientLeft,r[a].clientY-n.top-e.clientTop));return i},r.mouseButton=function(e){return void 0!==t.window.InstallTrigger&&2===e.button&&e.ctrlKey&&t.window.navigator.platform.toUpperCase().indexOf("MAC")>=0?0:e.button},r.remove=function(t){t.parentNode&&t.parentNode.removeChild(t)};var h=function(e){function r(){e.call(this),this.images={},this.updatedImages={},this.callbackDispatchedThisFrame={},this.loaded=!1,this.requestors=[],this.patterns={},this.atlasImage=new t.RGBAImage({width:1,height:1}),this.dirty=!0}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.isLoaded=function(){return this.loaded},r.prototype.setLoaded=function(t){if(this.loaded!==t&&(this.loaded=t,t)){for(var e=0,r=this.requestors;e<r.length;e+=1){var n=r[e],i=n.ids,a=n.callback;this._notify(i,a)}this.requestors=[]}},r.prototype.getImage=function(t){return this.images[t]},r.prototype.addImage=function(t,e){this._validate(t,e)&&(this.images[t]=e)},r.prototype._validate=function(e,r){var n=!0;return this._validateStretch(r.stretchX,r.data&&r.data.width)||(this.fire(new t.ErrorEvent(new Error('Image "'+e+'" has invalid "stretchX" value'))),n=!1),this._validateStretch(r.stretchY,r.data&&r.data.height)||(this.fire(new t.ErrorEvent(new Error('Image "'+e+'" has invalid "stretchY" value'))),n=!1),this._validateContent(r.content,r)||(this.fire(new t.ErrorEvent(new Error('Image "'+e+'" has invalid "content" value'))),n=!1),n},r.prototype._validateStretch=function(t,e){if(!t)return!0;for(var r=0,n=0,i=t;n<i.length;n+=1){var a=i[n];if(a[0]<r||a[1]<a[0]||e<a[1])return!1;r=a[1]}return!0},r.prototype._validateContent=function(t,e){return!t||4===t.length&&(!(t[0]<0||e.data.width<t[0])&&(!(t[1]<0||e.data.height<t[1])&&(!(t[2]<0||e.data.width<t[2])&&(!(t[3]<0||e.data.height<t[3])&&(!(t[2]<t[0])&&!(t[3]<t[1]))))))},r.prototype.updateImage=function(t,e){var r=this.images[t];e.version=r.version+1,this.images[t]=e,this.updatedImages[t]=!0},r.prototype.removeImage=function(t){var e=this.images[t];delete this.images[t],delete this.patterns[t],e.userImage&&e.userImage.onRemove&&e.userImage.onRemove()},r.prototype.listImages=function(){return Object.keys(this.images)},r.prototype.getImages=function(t,e){var r=!0;if(!this.isLoaded())for(var n=0,i=t;n<i.length;n+=1){var a=i[n];this.images[a]||(r=!1)}this.isLoaded()||r?this._notify(t,e):this.requestors.push({ids:t,callback:e})},r.prototype._notify=function(e,r){for(var n={},i=0,a=e;i<a.length;i+=1){var o=a[i];this.images[o]||this.fire(new t.Event("styleimagemissing",{id:o}));var s=this.images[o];s?n[o]={data:s.data.clone(),pixelRatio:s.pixelRatio,sdf:s.sdf,version:s.version,stretchX:s.stretchX,stretchY:s.stretchY,content:s.content,hasRenderCallback:Boolean(s.userImage&&s.userImage.render)}:t.warnOnce('Image "'+o+'" could not be loaded. Please make sure you have added the image with map.addImage() or a "sprite" property in your style. You can provide missing images by listening for the "styleimagemissing" map event.')}r(null,n)},r.prototype.getPixelSize=function(){var t=this.atlasImage;return{width:t.width,height:t.height}},r.prototype.getPattern=function(e){var r=this.patterns[e],n=this.getImage(e);if(!n)return null;if(r&&r.position.version===n.version)return r.position;if(r)r.position.version=n.version;else{var i={w:n.data.width+2,h:n.data.height+2,x:0,y:0},a=new t.ImagePosition(i,n);this.patterns[e]={bin:i,position:a}}return this._updatePatternAtlas(),this.patterns[e].position},r.prototype.bind=function(e){var r=e.gl;this.atlasTexture?this.dirty&&(this.atlasTexture.update(this.atlasImage),this.dirty=!1):this.atlasTexture=new t.Texture(e,this.atlasImage,r.RGBA),this.atlasTexture.bind(r.LINEAR,r.CLAMP_TO_EDGE)},r.prototype._updatePatternAtlas=function(){var e=[];for(var r in this.patterns)e.push(this.patterns[r].bin);var n=t.potpack(e),i=n.w,a=n.h,o=this.atlasImage;for(var s in o.resize({width:i||1,height:a||1}),this.patterns){var l=this.patterns[s].bin,c=l.x+1,u=l.y+1,f=this.images[s].data,h=f.width,p=f.height;t.RGBAImage.copy(f,o,{x:0,y:0},{x:c,y:u},{width:h,height:p}),t.RGBAImage.copy(f,o,{x:0,y:p-1},{x:c,y:u-1},{width:h,height:1}),t.RGBAImage.copy(f,o,{x:0,y:0},{x:c,y:u+p},{width:h,height:1}),t.RGBAImage.copy(f,o,{x:h-1,y:0},{x:c-1,y:u},{width:1,height:p}),t.RGBAImage.copy(f,o,{x:0,y:0},{x:c+h,y:u},{width:1,height:p})}this.dirty=!0},r.prototype.beginFrame=function(){this.callbackDispatchedThisFrame={}},r.prototype.dispatchRenderCallbacks=function(t){for(var e=0,r=t;e<r.length;e+=1){var n=r[e];if(!this.callbackDispatchedThisFrame[n]){this.callbackDispatchedThisFrame[n]=!0;var i=this.images[n];f(i)&&this.updateImage(n,i)}}},r}(t.Evented);var p=g,d=g,m=1e20;function g(t,e,r,n,i,a){this.fontSize=t||24,this.buffer=void 0===e?3:e,this.cutoff=n||.25,this.fontFamily=i||"sans-serif",this.fontWeight=a||"normal",this.radius=r||8;var o=this.size=this.fontSize+2*this.buffer;this.canvas=document.createElement("canvas"),this.canvas.width=this.canvas.height=o,this.ctx=this.canvas.getContext("2d"),this.ctx.font=this.fontWeight+" "+this.fontSize+"px "+this.fontFamily,this.ctx.textBaseline="middle",this.ctx.fillStyle="black",this.gridOuter=new Float64Array(o*o),this.gridInner=new Float64Array(o*o),this.f=new Float64Array(o),this.d=new Float64Array(o),this.z=new Float64Array(o+1),this.v=new Int16Array(o),this.middle=Math.round(o/2*(navigator.userAgent.indexOf("Gecko/")>=0?1.2:1))}function v(t,e,r,n,i,a,o){for(var s=0;s<e;s++){for(var l=0;l<r;l++)n[l]=t[l*e+s];for(y(n,i,a,o,r),l=0;l<r;l++)t[l*e+s]=i[l]}for(l=0;l<r;l++){for(s=0;s<e;s++)n[s]=t[l*e+s];for(y(n,i,a,o,e),s=0;s<e;s++)t[l*e+s]=Math.sqrt(i[s])}}function y(t,e,r,n,i){r[0]=0,n[0]=-m,n[1]=+m;for(var a=1,o=0;a<i;a++){for(var s=(t[a]+a*a-(t[r[o]]+r[o]*r[o]))/(2*a-2*r[o]);s<=n[o];)o--,s=(t[a]+a*a-(t[r[o]]+r[o]*r[o]))/(2*a-2*r[o]);r[++o]=a,n[o]=s,n[o+1]=+m}for(a=0,o=0;a<i;a++){for(;n[o+1]<a;)o++;e[a]=(a-r[o])*(a-r[o])+t[r[o]]}}g.prototype.draw=function(t){this.ctx.clearRect(0,0,this.size,this.size),this.ctx.fillText(t,this.buffer,this.middle);for(var e=this.ctx.getImageData(0,0,this.size,this.size),r=new Uint8ClampedArray(this.size*this.size),n=0;n<this.size*this.size;n++){var i=e.data[4*n+3]/255;this.gridOuter[n]=1===i?0:0===i?m:Math.pow(Math.max(0,.5-i),2),this.gridInner[n]=1===i?m:0===i?0:Math.pow(Math.max(0,i-.5),2)}for(v(this.gridOuter,this.size,this.size,this.f,this.d,this.v,this.z),v(this.gridInner,this.size,this.size,this.f,this.d,this.v,this.z),n=0;n<this.size*this.size;n++){var a=this.gridOuter[n]-this.gridInner[n];r[n]=Math.max(0,Math.min(255,Math.round(255-255*(a/this.radius+this.cutoff))))}return r},p.default=d;var x=function(t,e){this.requestManager=t,this.localIdeographFontFamily=e,this.entries={}};x.prototype.setURL=function(t){this.url=t},x.prototype.getGlyphs=function(e,r){var n=this,i=[];for(var a in e)for(var o=0,s=e[a];o<s.length;o+=1){var l=s[o];i.push({stack:a,id:l})}t.asyncAll(i,(function(t,e){var r=t.stack,i=t.id,a=n.entries[r];a||(a=n.entries[r]={glyphs:{},requests:{},ranges:{}});var o=a.glyphs[i];if(void 0===o){if(o=n._tinySDF(a,r,i))return a.glyphs[i]=o,void e(null,{stack:r,id:i,glyph:o});var s=Math.floor(i/256);if(256*s>65535)e(new Error("glyphs > 65535 not supported"));else if(a.ranges[s])e(null,{stack:r,id:i,glyph:o});else{var l=a.requests[s];l||(l=a.requests[s]=[],x.loadGlyphRange(r,s,n.url,n.requestManager,(function(t,e){if(e){for(var r in e)n._doesCharSupportLocalGlyph(+r)||(a.glyphs[+r]=e[+r]);a.ranges[s]=!0}for(var i=0,o=l;i<o.length;i+=1){(0,o[i])(t,e)}delete a.requests[s]}))),l.push((function(t,n){t?e(t):n&&e(null,{stack:r,id:i,glyph:n[i]||null})}))}}else e(null,{stack:r,id:i,glyph:o})}),(function(t,e){if(t)r(t);else if(e){for(var n={},i=0,a=e;i<a.length;i+=1){var o=a[i],s=o.stack,l=o.id,c=o.glyph;(n[s]||(n[s]={}))[l]=c&&{id:c.id,bitmap:c.bitmap.clone(),metrics:c.metrics}}r(null,n)}}))},x.prototype._doesCharSupportLocalGlyph=function(e){return!!this.localIdeographFontFamily&&(t.isChar["CJK Unified Ideographs"](e)||t.isChar["Hangul Syllables"](e)||t.isChar.Hiragana(e)||t.isChar.Katakana(e))},x.prototype._tinySDF=function(e,r,n){var i=this.localIdeographFontFamily;if(i&&this._doesCharSupportLocalGlyph(n)){var a=e.tinySDF;if(!a){var o="400";/bold/i.test(r)?o="900":/medium/i.test(r)?o="500":/light/i.test(r)&&(o="200"),a=e.tinySDF=new x.TinySDF(24,3,8,.25,i,o)}return{id:n,bitmap:new t.AlphaImage({width:30,height:30},a.draw(String.fromCharCode(n))),metrics:{width:24,height:24,left:0,top:-8,advance:24}}}},x.loadGlyphRange=function(e,r,n,i,a){var o=256*r,s=o+255,l=i.transformRequest(i.normalizeGlyphsURL(n).replace("{fontstack}",e).replace("{range}",o+"-"+s),t.ResourceType.Glyphs);t.getArrayBuffer(l,(function(e,r){if(e)a(e);else if(r){for(var n={},i=0,o=t.parseGlyphPBF(r);i<o.length;i+=1){var s=o[i];n[s.id]=s}a(null,n)}}))},x.TinySDF=p;var b=function(){this.specification=t.styleSpec.light.position};b.prototype.possiblyEvaluate=function(e,r){return t.sphericalToCartesian(e.expression.evaluate(r))},b.prototype.interpolate=function(e,r,n){return{x:t.number(e.x,r.x,n),y:t.number(e.y,r.y,n),z:t.number(e.z,r.z,n)}};var _=new t.Properties({anchor:new t.DataConstantProperty(t.styleSpec.light.anchor),position:new b,color:new t.DataConstantProperty(t.styleSpec.light.color),intensity:new t.DataConstantProperty(t.styleSpec.light.intensity)}),w=function(e){function r(r){e.call(this),this._transitionable=new t.Transitionable(_),this.setLight(r),this._transitioning=this._transitionable.untransitioned()}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.getLight=function(){return this._transitionable.serialize()},r.prototype.setLight=function(e,r){if(void 0===r&&(r={}),!this._validate(t.validateLight,e,r))for(var n in e){var i=e[n];t.endsWith(n,"-transition")?this._transitionable.setTransition(n.slice(0,-"-transition".length),i):this._transitionable.setValue(n,i)}},r.prototype.updateTransitions=function(t){this._transitioning=this._transitionable.transitioned(t,this._transitioning)},r.prototype.hasTransition=function(){return this._transitioning.hasTransition()},r.prototype.recalculate=function(t){this.properties=this._transitioning.possiblyEvaluate(t)},r.prototype._validate=function(e,r,n){return(!n||!1!==n.validate)&&t.emitValidationErrors(this,e.call(t.validateStyle,t.extend({value:r,style:{glyphs:!0,sprite:!0},styleSpec:t.styleSpec})))},r}(t.Evented),T=function(t,e){this.width=t,this.height=e,this.nextRow=0,this.data=new Uint8Array(this.width*this.height),this.dashEntry={}};T.prototype.getDash=function(t,e){var r=t.join(",")+String(e);return this.dashEntry[r]||(this.dashEntry[r]=this.addDash(t,e)),this.dashEntry[r]},T.prototype.getDashRanges=function(t,e,r){var n=[],i=t.length%2==1?-t[t.length-1]*r:0,a=t[0]*r,o=!0;n.push({left:i,right:a,isDash:o,zeroLength:0===t[0]});for(var s=t[0],l=1;l<t.length;l++){o=!o;var c=t[l];i=s*r,a=(s+=c)*r,n.push({left:i,right:a,isDash:o,zeroLength:0===c})}return n},T.prototype.addRoundDash=function(t,e,r){for(var n=e/2,i=-r;i<=r;i++)for(var a=this.nextRow+r+i,o=this.width*a,s=0,l=t[s],c=0;c<this.width;c++){c/l.right>1&&(l=t[++s]);var u=Math.abs(c-l.left),f=Math.abs(c-l.right),h=Math.min(u,f),p=void 0,d=i/r*(n+1);if(l.isDash){var m=n-Math.abs(d);p=Math.sqrt(h*h+m*m)}else p=n-Math.sqrt(h*h+d*d);this.data[o+c]=Math.max(0,Math.min(255,p+128))}},T.prototype.addRegularDash=function(t){for(var e=t.length-1;e>=0;--e){var r=t[e],n=t[e+1];r.zeroLength?t.splice(e,1):n&&n.isDash===r.isDash&&(n.left=r.left,t.splice(e,1))}var i=t[0],a=t[t.length-1];i.isDash===a.isDash&&(i.left=a.left-this.width,a.right=i.right+this.width);for(var o=this.width*this.nextRow,s=0,l=t[s],c=0;c<this.width;c++){c/l.right>1&&(l=t[++s]);var u=Math.abs(c-l.left),f=Math.abs(c-l.right),h=Math.min(u,f),p=l.isDash?h:-h;this.data[o+c]=Math.max(0,Math.min(255,p+128))}},T.prototype.addDash=function(e,r){var n=r?7:0,i=2*n+1;if(this.nextRow+i>this.height)return t.warnOnce("LineAtlas out of space"),null;for(var a=0,o=0;o<e.length;o++)a+=e[o];if(0!==a){var s=this.width/a,l=this.getDashRanges(e,this.width,s);r?this.addRoundDash(l,s,n):this.addRegularDash(l)}var c={y:(this.nextRow+n+.5)/this.height,height:2*n/this.height,width:a};return this.nextRow+=i,this.dirty=!0,c},T.prototype.bind=function(t){var e=t.gl;this.texture?(e.bindTexture(e.TEXTURE_2D,this.texture),this.dirty&&(this.dirty=!1,e.texSubImage2D(e.TEXTURE_2D,0,0,0,this.width,this.height,e.ALPHA,e.UNSIGNED_BYTE,this.data))):(this.texture=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.texture),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texImage2D(e.TEXTURE_2D,0,e.ALPHA,this.width,this.height,0,e.ALPHA,e.UNSIGNED_BYTE,this.data))};var k=function e(r,n){this.workerPool=r,this.actors=[],this.currentActor=0,this.id=t.uniqueId();for(var i=this.workerPool.acquire(this.id),a=0;a<i.length;a++){var o=i[a],s=new e.Actor(o,n,this.id);s.name="Worker "+a,this.actors.push(s)}};function A(e,r,n){var i=function(i,a){if(i)return n(i);if(a){var o=t.pick(t.extend(a,e),["tiles","minzoom","maxzoom","attribution","mapbox_logo","bounds","scheme","tileSize","encoding"]);a.vector_layers&&(o.vectorLayers=a.vector_layers,o.vectorLayerIds=o.vectorLayers.map((function(t){return t.id}))),o.tiles=r.canonicalizeTileset(o,e.url),n(null,o)}};return e.url?t.getJSON(r.transformRequest(r.normalizeSourceURL(e.url),t.ResourceType.Source),i):t.browser.frame((function(){return i(null,e)}))}k.prototype.broadcast=function(e,r,n){n=n||function(){},t.asyncAll(this.actors,(function(t,n){t.send(e,r,n)}),n)},k.prototype.getActor=function(){return this.currentActor=(this.currentActor+1)%this.actors.length,this.actors[this.currentActor]},k.prototype.remove=function(){this.actors.forEach((function(t){t.remove()})),this.actors=[],this.workerPool.release(this.id)},k.Actor=t.Actor;var M=function(e,r,n){this.bounds=t.LngLatBounds.convert(this.validateBounds(e)),this.minzoom=r||0,this.maxzoom=n||24};M.prototype.validateBounds=function(t){return Array.isArray(t)&&4===t.length?[Math.max(-180,t[0]),Math.max(-90,t[1]),Math.min(180,t[2]),Math.min(90,t[3])]:[-180,-90,180,90]},M.prototype.contains=function(e){var r=Math.pow(2,e.z),n=Math.floor(t.mercatorXfromLng(this.bounds.getWest())*r),i=Math.floor(t.mercatorYfromLat(this.bounds.getNorth())*r),a=Math.ceil(t.mercatorXfromLng(this.bounds.getEast())*r),o=Math.ceil(t.mercatorYfromLat(this.bounds.getSouth())*r);return e.x>=n&&e.x<a&&e.y>=i&&e.y<o};var S=function(e){function r(r,n,i,a){if(e.call(this),this.id=r,this.dispatcher=i,this.type="vector",this.minzoom=0,this.maxzoom=22,this.scheme="xyz",this.tileSize=512,this.reparseOverscaled=!0,this.isTileClipped=!0,this._loaded=!1,t.extend(this,t.pick(n,["url","scheme","tileSize","promoteId"])),this._options=t.extend({type:"vector"},n),this._collectResourceTiming=n.collectResourceTiming,512!==this.tileSize)throw new Error("vector tile sources must have a tileSize of 512");this.setEventedParent(a)}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.load=function(){var e=this;this._loaded=!1,this.fire(new t.Event("dataloading",{dataType:"source"})),this._tileJSONRequest=A(this._options,this.map._requestManager,(function(r,n){e._tileJSONRequest=null,e._loaded=!0,r?e.fire(new t.ErrorEvent(r)):n&&(t.extend(e,n),n.bounds&&(e.tileBounds=new M(n.bounds,e.minzoom,e.maxzoom)),t.postTurnstileEvent(n.tiles,e.map._requestManager._customAccessToken),t.postMapLoadEvent(n.tiles,e.map._getMapId(),e.map._requestManager._skuToken,e.map._requestManager._customAccessToken),e.fire(new t.Event("data",{dataType:"source",sourceDataType:"metadata"})),e.fire(new t.Event("data",{dataType:"source",sourceDataType:"content"})))}))},r.prototype.loaded=function(){return this._loaded},r.prototype.hasTile=function(t){return!this.tileBounds||this.tileBounds.contains(t.canonical)},r.prototype.onAdd=function(t){this.map=t,this.load()},r.prototype.onRemove=function(){this._tileJSONRequest&&(this._tileJSONRequest.cancel(),this._tileJSONRequest=null)},r.prototype.serialize=function(){return t.extend({},this._options)},r.prototype.loadTile=function(e,r){var n=this.map._requestManager.normalizeTileURL(e.tileID.canonical.url(this.tiles,this.scheme)),i={request:this.map._requestManager.transformRequest(n,t.ResourceType.Tile),uid:e.uid,tileID:e.tileID,zoom:e.tileID.overscaledZ,tileSize:this.tileSize*e.tileID.overscaleFactor(),type:this.type,source:this.id,pixelRatio:t.browser.devicePixelRatio,showCollisionBoxes:this.map.showCollisionBoxes,promoteId:this.promoteId};function a(n,i){return delete e.request,e.aborted?r(null):n&&404!==n.status?r(n):(i&&i.resourceTiming&&(e.resourceTiming=i.resourceTiming),this.map._refreshExpiredTiles&&i&&e.setExpiryData(i),e.loadVectorData(i,this.map.painter),t.cacheEntryPossiblyAdded(this.dispatcher),r(null),void(e.reloadCallback&&(this.loadTile(e,e.reloadCallback),e.reloadCallback=null)))}i.request.collectResourceTiming=this._collectResourceTiming,e.actor&&"expired"!==e.state?"loading"===e.state?e.reloadCallback=r:e.request=e.actor.send("reloadTile",i,a.bind(this)):(e.actor=this.dispatcher.getActor(),e.request=e.actor.send("loadTile",i,a.bind(this)))},r.prototype.abortTile=function(t){t.request&&(t.request.cancel(),delete t.request),t.actor&&t.actor.send("abortTile",{uid:t.uid,type:this.type,source:this.id},void 0)},r.prototype.unloadTile=function(t){t.unloadVectorData(),t.actor&&t.actor.send("removeTile",{uid:t.uid,type:this.type,source:this.id},void 0)},r.prototype.hasTransition=function(){return!1},r}(t.Evented),E=function(e){function r(r,n,i,a){e.call(this),this.id=r,this.dispatcher=i,this.setEventedParent(a),this.type="raster",this.minzoom=0,this.maxzoom=22,this.roundZoom=!0,this.scheme="xyz",this.tileSize=512,this._loaded=!1,this._options=t.extend({type:"raster"},n),t.extend(this,t.pick(n,["url","scheme","tileSize"]))}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.load=function(){var e=this;this._loaded=!1,this.fire(new t.Event("dataloading",{dataType:"source"})),this._tileJSONRequest=A(this._options,this.map._requestManager,(function(r,n){e._tileJSONRequest=null,e._loaded=!0,r?e.fire(new t.ErrorEvent(r)):n&&(t.extend(e,n),n.bounds&&(e.tileBounds=new M(n.bounds,e.minzoom,e.maxzoom)),t.postTurnstileEvent(n.tiles),t.postMapLoadEvent(n.tiles,e.map._getMapId(),e.map._requestManager._skuToken),e.fire(new t.Event("data",{dataType:"source",sourceDataType:"metadata"})),e.fire(new t.Event("data",{dataType:"source",sourceDataType:"content"})))}))},r.prototype.loaded=function(){return this._loaded},r.prototype.onAdd=function(t){this.map=t,this.load()},r.prototype.onRemove=function(){this._tileJSONRequest&&(this._tileJSONRequest.cancel(),this._tileJSONRequest=null)},r.prototype.serialize=function(){return t.extend({},this._options)},r.prototype.hasTile=function(t){return!this.tileBounds||this.tileBounds.contains(t.canonical)},r.prototype.loadTile=function(e,r){var n=this,i=this.map._requestManager.normalizeTileURL(e.tileID.canonical.url(this.tiles,this.scheme),this.tileSize);e.request=t.getImage(this.map._requestManager.transformRequest(i,t.ResourceType.Tile),(function(i,a){if(delete e.request,e.aborted)e.state="unloaded",r(null);else if(i)e.state="errored",r(i);else if(a){n.map._refreshExpiredTiles&&e.setExpiryData(a),delete a.cacheControl,delete a.expires;var o=n.map.painter.context,s=o.gl;e.texture=n.map.painter.getTileTexture(a.width),e.texture?e.texture.update(a,{useMipmap:!0}):(e.texture=new t.Texture(o,a,s.RGBA,{useMipmap:!0}),e.texture.bind(s.LINEAR,s.CLAMP_TO_EDGE,s.LINEAR_MIPMAP_NEAREST),o.extTextureFilterAnisotropic&&s.texParameterf(s.TEXTURE_2D,o.extTextureFilterAnisotropic.TEXTURE_MAX_ANISOTROPY_EXT,o.extTextureFilterAnisotropicMax)),e.state="loaded",t.cacheEntryPossiblyAdded(n.dispatcher),r(null)}}))},r.prototype.abortTile=function(t,e){t.request&&(t.request.cancel(),delete t.request),e()},r.prototype.unloadTile=function(t,e){t.texture&&this.map.painter.saveTileTexture(t.texture),e()},r.prototype.hasTransition=function(){return!1},r}(t.Evented),L=function(e){function r(r,n,i,a){e.call(this,r,n,i,a),this.type="raster-dem",this.maxzoom=22,this._options=t.extend({type:"raster-dem"},n),this.encoding=n.encoding||"mapbox"}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.serialize=function(){return{type:"raster-dem",url:this.url,tileSize:this.tileSize,tiles:this.tiles,bounds:this.bounds,encoding:this.encoding}},r.prototype.loadTile=function(e,r){var n=this.map._requestManager.normalizeTileURL(e.tileID.canonical.url(this.tiles,this.scheme),this.tileSize);function i(t,n){t&&(e.state="errored",r(t)),n&&(e.dem=n,e.needsHillshadePrepare=!0,e.state="loaded",r(null))}e.request=t.getImage(this.map._requestManager.transformRequest(n,t.ResourceType.Tile),function(n,a){if(delete e.request,e.aborted)e.state="unloaded",r(null);else if(n)e.state="errored",r(n);else if(a){this.map._refreshExpiredTiles&&e.setExpiryData(a),delete a.cacheControl,delete a.expires;var o=t.window.ImageBitmap&&a instanceof t.window.ImageBitmap&&t.offscreenCanvasSupported()?a:t.browser.getImageData(a,1),s={uid:e.uid,coord:e.tileID,source:this.id,rawImageData:o,encoding:this.encoding};e.actor&&"expired"!==e.state||(e.actor=this.dispatcher.getActor(),e.actor.send("loadDEMTile",s,i.bind(this)))}}.bind(this)),e.neighboringTiles=this._getNeighboringTiles(e.tileID)},r.prototype._getNeighboringTiles=function(e){var r=e.canonical,n=Math.pow(2,r.z),i=(r.x-1+n)%n,a=0===r.x?e.wrap-1:e.wrap,o=(r.x+1+n)%n,s=r.x+1===n?e.wrap+1:e.wrap,l={};return l[new t.OverscaledTileID(e.overscaledZ,a,r.z,i,r.y).key]={backfilled:!1},l[new t.OverscaledTileID(e.overscaledZ,s,r.z,o,r.y).key]={backfilled:!1},r.y>0&&(l[new t.OverscaledTileID(e.overscaledZ,a,r.z,i,r.y-1).key]={backfilled:!1},l[new t.OverscaledTileID(e.overscaledZ,e.wrap,r.z,r.x,r.y-1).key]={backfilled:!1},l[new t.OverscaledTileID(e.overscaledZ,s,r.z,o,r.y-1).key]={backfilled:!1}),r.y+1<n&&(l[new t.OverscaledTileID(e.overscaledZ,a,r.z,i,r.y+1).key]={backfilled:!1},l[new t.OverscaledTileID(e.overscaledZ,e.wrap,r.z,r.x,r.y+1).key]={backfilled:!1},l[new t.OverscaledTileID(e.overscaledZ,s,r.z,o,r.y+1).key]={backfilled:!1}),l},r.prototype.unloadTile=function(t){t.demTexture&&this.map.painter.saveTileTexture(t.demTexture),t.fbo&&(t.fbo.destroy(),delete t.fbo),t.dem&&delete t.dem,delete t.neighboringTiles,t.state="unloaded",t.actor&&t.actor.send("removeDEMTile",{uid:t.uid,source:this.id})},r}(E),C=function(e){function r(r,n,i,a){e.call(this),this.id=r,this.type="geojson",this.minzoom=0,this.maxzoom=18,this.tileSize=512,this.isTileClipped=!0,this.reparseOverscaled=!0,this._removed=!1,this._loaded=!1,this.actor=i.getActor(),this.setEventedParent(a),this._data=n.data,this._options=t.extend({},n),this._collectResourceTiming=n.collectResourceTiming,this._resourceTiming=[],void 0!==n.maxzoom&&(this.maxzoom=n.maxzoom),n.type&&(this.type=n.type),n.attribution&&(this.attribution=n.attribution),this.promoteId=n.promoteId;var o=t.EXTENT/this.tileSize;this.workerOptions=t.extend({source:this.id,cluster:n.cluster||!1,geojsonVtOptions:{buffer:(void 0!==n.buffer?n.buffer:128)*o,tolerance:(void 0!==n.tolerance?n.tolerance:.375)*o,extent:t.EXTENT,maxZoom:this.maxzoom,lineMetrics:n.lineMetrics||!1,generateId:n.generateId||!1},superclusterOptions:{maxZoom:void 0!==n.clusterMaxZoom?Math.min(n.clusterMaxZoom,this.maxzoom-1):this.maxzoom-1,extent:t.EXTENT,radius:(n.clusterRadius||50)*o,log:!1,generateId:n.generateId||!1},clusterProperties:n.clusterProperties},n.workerOptions)}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.load=function(){var e=this;this.fire(new t.Event("dataloading",{dataType:"source"})),this._updateWorkerData((function(r){if(r)e.fire(new t.ErrorEvent(r));else{var n={dataType:"source",sourceDataType:"metadata"};e._collectResourceTiming&&e._resourceTiming&&e._resourceTiming.length>0&&(n.resourceTiming=e._resourceTiming,e._resourceTiming=[]),e.fire(new t.Event("data",n))}}))},r.prototype.onAdd=function(t){this.map=t,this.load()},r.prototype.setData=function(e){var r=this;return this._data=e,this.fire(new t.Event("dataloading",{dataType:"source"})),this._updateWorkerData((function(e){if(e)r.fire(new t.ErrorEvent(e));else{var n={dataType:"source",sourceDataType:"content"};r._collectResourceTiming&&r._resourceTiming&&r._resourceTiming.length>0&&(n.resourceTiming=r._resourceTiming,r._resourceTiming=[]),r.fire(new t.Event("data",n))}})),this},r.prototype.getClusterExpansionZoom=function(t,e){return this.actor.send("geojson.getClusterExpansionZoom",{clusterId:t,source:this.id},e),this},r.prototype.getClusterChildren=function(t,e){return this.actor.send("geojson.getClusterChildren",{clusterId:t,source:this.id},e),this},r.prototype.getClusterLeaves=function(t,e,r,n){return this.actor.send("geojson.getClusterLeaves",{source:this.id,clusterId:t,limit:e,offset:r},n),this},r.prototype._updateWorkerData=function(e){var r=this;this._loaded=!1;var n=t.extend({},this.workerOptions),i=this._data;"string"==typeof i?(n.request=this.map._requestManager.transformRequest(t.browser.resolveURL(i),t.ResourceType.Source),n.request.collectResourceTiming=this._collectResourceTiming):n.data=JSON.stringify(i),this.actor.send(this.type+".loadData",n,(function(t,i){r._removed||i&&i.abandoned||(r._loaded=!0,i&&i.resourceTiming&&i.resourceTiming[r.id]&&(r._resourceTiming=i.resourceTiming[r.id].slice(0)),r.actor.send(r.type+".coalesce",{source:n.source},null),e(t))}))},r.prototype.loaded=function(){return this._loaded},r.prototype.loadTile=function(e,r){var n=this,i=e.actor?"reloadTile":"loadTile";e.actor=this.actor;var a={type:this.type,uid:e.uid,tileID:e.tileID,zoom:e.tileID.overscaledZ,maxZoom:this.maxzoom,tileSize:this.tileSize,source:this.id,pixelRatio:t.browser.devicePixelRatio,showCollisionBoxes:this.map.showCollisionBoxes,promoteId:this.promoteId};e.request=this.actor.send(i,a,(function(t,a){return delete e.request,e.unloadVectorData(),e.aborted?r(null):t?r(t):(e.loadVectorData(a,n.map.painter,"reloadTile"===i),r(null))}))},r.prototype.abortTile=function(t){t.request&&(t.request.cancel(),delete t.request),t.aborted=!0},r.prototype.unloadTile=function(t){t.unloadVectorData(),this.actor.send("removeTile",{uid:t.uid,type:this.type,source:this.id})},r.prototype.onRemove=function(){this._removed=!0,this.actor.send("removeSource",{type:this.type,source:this.id})},r.prototype.serialize=function(){return t.extend({},this._options,{type:this.type,data:this._data})},r.prototype.hasTransition=function(){return!1},r}(t.Evented),P=t.createLayout([{name:"a_pos",type:"Int16",components:2},{name:"a_texture_pos",type:"Int16",components:2}]),I=function(e){function r(t,r,n,i){e.call(this),this.id=t,this.dispatcher=n,this.coordinates=r.coordinates,this.type="image",this.minzoom=0,this.maxzoom=22,this.tileSize=512,this.tiles={},this._loaded=!1,this.setEventedParent(i),this.options=r}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.load=function(e,r){var n=this;this._loaded=!1,this.fire(new t.Event("dataloading",{dataType:"source"})),this.url=this.options.url,t.getImage(this.map._requestManager.transformRequest(this.url,t.ResourceType.Image),(function(i,a){n._loaded=!0,i?n.fire(new t.ErrorEvent(i)):a&&(n.image=a,e&&(n.coordinates=e),r&&r(),n._finishLoading())}))},r.prototype.loaded=function(){return this._loaded},r.prototype.updateImage=function(t){var e=this;return this.image&&t.url?(this.options.url=t.url,this.load(t.coordinates,(function(){e.texture=null})),this):this},r.prototype._finishLoading=function(){this.map&&(this.setCoordinates(this.coordinates),this.fire(new t.Event("data",{dataType:"source",sourceDataType:"metadata"})))},r.prototype.onAdd=function(t){this.map=t,this.load()},r.prototype.setCoordinates=function(e){var r=this;this.coordinates=e;var n=e.map(t.MercatorCoordinate.fromLngLat);this.tileID=function(e){for(var r=1/0,n=1/0,i=-1/0,a=-1/0,o=0,s=e;o<s.length;o+=1){var l=s[o];r=Math.min(r,l.x),n=Math.min(n,l.y),i=Math.max(i,l.x),a=Math.max(a,l.y)}var c=i-r,u=a-n,f=Math.max(c,u),h=Math.max(0,Math.floor(-Math.log(f)/Math.LN2)),p=Math.pow(2,h);return new t.CanonicalTileID(h,Math.floor((r+i)/2*p),Math.floor((n+a)/2*p))}(n),this.minzoom=this.maxzoom=this.tileID.z;var i=n.map((function(t){return r.tileID.getTilePoint(t)._round()}));return this._boundsArray=new t.StructArrayLayout4i8,this._boundsArray.emplaceBack(i[0].x,i[0].y,0,0),this._boundsArray.emplaceBack(i[1].x,i[1].y,t.EXTENT,0),this._boundsArray.emplaceBack(i[3].x,i[3].y,0,t.EXTENT),this._boundsArray.emplaceBack(i[2].x,i[2].y,t.EXTENT,t.EXTENT),this.boundsBuffer&&(this.boundsBuffer.destroy(),delete this.boundsBuffer),this.fire(new t.Event("data",{dataType:"source",sourceDataType:"content"})),this},r.prototype.prepare=function(){if(0!==Object.keys(this.tiles).length&&this.image){var e=this.map.painter.context,r=e.gl;for(var n in this.boundsBuffer||(this.boundsBuffer=e.createVertexBuffer(this._boundsArray,P.members)),this.boundsSegments||(this.boundsSegments=t.SegmentVector.simpleSegment(0,0,4,2)),this.texture||(this.texture=new t.Texture(e,this.image,r.RGBA),this.texture.bind(r.LINEAR,r.CLAMP_TO_EDGE)),this.tiles){var i=this.tiles[n];"loaded"!==i.state&&(i.state="loaded",i.texture=this.texture)}}},r.prototype.loadTile=function(t,e){this.tileID&&this.tileID.equals(t.tileID.canonical)?(this.tiles[String(t.tileID.wrap)]=t,t.buckets={},e(null)):(t.state="errored",e(null))},r.prototype.serialize=function(){return{type:"image",url:this.options.url,coordinates:this.coordinates}},r.prototype.hasTransition=function(){return!1},r}(t.Evented);var O=function(e){function r(t,r,n,i){e.call(this,t,r,n,i),this.roundZoom=!0,this.type="video",this.options=r}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.load=function(){var e=this;this._loaded=!1;var r=this.options;this.urls=[];for(var n=0,i=r.urls;n<i.length;n+=1){var a=i[n];this.urls.push(this.map._requestManager.transformRequest(a,t.ResourceType.Source).url)}t.getVideo(this.urls,(function(r,n){e._loaded=!0,r?e.fire(new t.ErrorEvent(r)):n&&(e.video=n,e.video.loop=!0,e.video.addEventListener("playing",(function(){e.map.triggerRepaint()})),e.map&&e.video.play(),e._finishLoading())}))},r.prototype.pause=function(){this.video&&this.video.pause()},r.prototype.play=function(){this.video&&this.video.play()},r.prototype.seek=function(e){if(this.video){var r=this.video.seekable;e<r.start(0)||e>r.end(0)?this.fire(new t.ErrorEvent(new t.ValidationError("sources."+this.id,null,"Playback for this video can be set only between the "+r.start(0)+" and "+r.end(0)+"-second mark."))):this.video.currentTime=e}},r.prototype.getVideo=function(){return this.video},r.prototype.onAdd=function(t){this.map||(this.map=t,this.load(),this.video&&(this.video.play(),this.setCoordinates(this.coordinates)))},r.prototype.prepare=function(){if(!(0===Object.keys(this.tiles).length||this.video.readyState<2)){var e=this.map.painter.context,r=e.gl;for(var n in this.boundsBuffer||(this.boundsBuffer=e.createVertexBuffer(this._boundsArray,P.members)),this.boundsSegments||(this.boundsSegments=t.SegmentVector.simpleSegment(0,0,4,2)),this.texture?this.video.paused||(this.texture.bind(r.LINEAR,r.CLAMP_TO_EDGE),r.texSubImage2D(r.TEXTURE_2D,0,0,0,r.RGBA,r.UNSIGNED_BYTE,this.video)):(this.texture=new t.Texture(e,this.video,r.RGBA),this.texture.bind(r.LINEAR,r.CLAMP_TO_EDGE)),this.tiles){var i=this.tiles[n];"loaded"!==i.state&&(i.state="loaded",i.texture=this.texture)}}},r.prototype.serialize=function(){return{type:"video",urls:this.urls,coordinates:this.coordinates}},r.prototype.hasTransition=function(){return this.video&&!this.video.paused},r}(I),z=function(e){function r(r,n,i,a){e.call(this,r,n,i,a),n.coordinates?Array.isArray(n.coordinates)&&4===n.coordinates.length&&!n.coordinates.some((function(t){return!Array.isArray(t)||2!==t.length||t.some((function(t){return"number"!=typeof t}))}))||this.fire(new t.ErrorEvent(new t.ValidationError("sources."+r,null,'"coordinates" property must be an array of 4 longitude/latitude array pairs'))):this.fire(new t.ErrorEvent(new t.ValidationError("sources."+r,null,'missing required property "coordinates"'))),n.animate&&"boolean"!=typeof n.animate&&this.fire(new t.ErrorEvent(new t.ValidationError("sources."+r,null,'optional "animate" property must be a boolean value'))),n.canvas?"string"==typeof n.canvas||n.canvas instanceof t.window.HTMLCanvasElement||this.fire(new t.ErrorEvent(new t.ValidationError("sources."+r,null,'"canvas" must be either a string representing the ID of the canvas element from which to read, or an HTMLCanvasElement instance'))):this.fire(new t.ErrorEvent(new t.ValidationError("sources."+r,null,'missing required property "canvas"'))),this.options=n,this.animate=void 0===n.animate||n.animate}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.load=function(){this._loaded=!0,this.canvas||(this.canvas=this.options.canvas instanceof t.window.HTMLCanvasElement?this.options.canvas:t.window.document.getElementById(this.options.canvas)),this.width=this.canvas.width,this.height=this.canvas.height,this._hasInvalidDimensions()?this.fire(new t.ErrorEvent(new Error("Canvas dimensions cannot be less than or equal to zero."))):(this.play=function(){this._playing=!0,this.map.triggerRepaint()},this.pause=function(){this._playing&&(this.prepare(),this._playing=!1)},this._finishLoading())},r.prototype.getCanvas=function(){return this.canvas},r.prototype.onAdd=function(t){this.map=t,this.load(),this.canvas&&this.animate&&this.play()},r.prototype.onRemove=function(){this.pause()},r.prototype.prepare=function(){var e=!1;if(this.canvas.width!==this.width&&(this.width=this.canvas.width,e=!0),this.canvas.height!==this.height&&(this.height=this.canvas.height,e=!0),!this._hasInvalidDimensions()&&0!==Object.keys(this.tiles).length){var r=this.map.painter.context,n=r.gl;for(var i in this.boundsBuffer||(this.boundsBuffer=r.createVertexBuffer(this._boundsArray,P.members)),this.boundsSegments||(this.boundsSegments=t.SegmentVector.simpleSegment(0,0,4,2)),this.texture?(e||this._playing)&&this.texture.update(this.canvas,{premultiply:!0}):this.texture=new t.Texture(r,this.canvas,n.RGBA,{premultiply:!0}),this.tiles){var a=this.tiles[i];"loaded"!==a.state&&(a.state="loaded",a.texture=this.texture)}}},r.prototype.serialize=function(){return{type:"canvas",coordinates:this.coordinates}},r.prototype.hasTransition=function(){return this._playing},r.prototype._hasInvalidDimensions=function(){for(var t=0,e=[this.canvas.width,this.canvas.height];t<e.length;t+=1){var r=e[t];if(isNaN(r)||r<=0)return!0}return!1},r}(I),D={vector:S,raster:E,"raster-dem":L,geojson:C,video:O,image:I,canvas:z};function R(e,r){var n=t.identity([]);return t.translate(n,n,[1,1,0]),t.scale(n,n,[.5*e.width,.5*e.height,1]),t.multiply(n,n,e.calculatePosMatrix(r.toUnwrapped()))}function F(t,e,r,n,i,a){var o=function(t,e,r){if(t)for(var n=0,i=t;n<i.length;n+=1){var a=e[i[n]];if(a&&a.source===r&&"fill-extrusion"===a.type)return!0}else for(var o in e){var s=e[o];if(s.source===r&&"fill-extrusion"===s.type)return!0}return!1}(i&&i.layers,e,t.id),s=a.maxPitchScaleFactor(),l=t.tilesIn(n,s,o);l.sort(B);for(var c=[],u=0,f=l;u<f.length;u+=1){var h=f[u];c.push({wrappedTileID:h.tileID.wrapped().key,queryResults:h.tile.queryRenderedFeatures(e,r,t._state,h.queryGeometry,h.cameraQueryGeometry,h.scale,i,a,s,R(t.transform,h.tileID))})}var p=function(t){for(var e={},r={},n=0,i=t;n<i.length;n+=1){var a=i[n],o=a.queryResults,s=a.wrappedTileID,l=r[s]=r[s]||{};for(var c in o)for(var u=o[c],f=l[c]=l[c]||{},h=e[c]=e[c]||[],p=0,d=u;p<d.length;p+=1){var m=d[p];f[m.featureIndex]||(f[m.featureIndex]=!0,h.push(m))}}return e}(c);for(var d in p)p[d].forEach((function(e){var r=e.feature,n=t.getFeatureState(r.layer["source-layer"],r.id);r.source=r.layer.source,r.layer["source-layer"]&&(r.sourceLayer=r.layer["source-layer"]),r.state=n}));return p}function B(t,e){var r=t.tileID,n=e.tileID;return r.overscaledZ-n.overscaledZ||r.canonical.y-n.canonical.y||r.wrap-n.wrap||r.canonical.x-n.canonical.x}var N=function(t,e){this.max=t,this.onRemove=e,this.reset()};N.prototype.reset=function(){for(var t in this.data)for(var e=0,r=this.data[t];e<r.length;e+=1){var n=r[e];n.timeout&&clearTimeout(n.timeout),this.onRemove(n.value)}return this.data={},this.order=[],this},N.prototype.add=function(t,e,r){var n=this,i=t.wrapped().key;void 0===this.data[i]&&(this.data[i]=[]);var a={value:e,timeout:void 0};if(void 0!==r&&(a.timeout=setTimeout((function(){n.remove(t,a)}),r)),this.data[i].push(a),this.order.push(i),this.order.length>this.max){var o=this._getAndRemoveByKey(this.order[0]);o&&this.onRemove(o)}return this},N.prototype.has=function(t){return t.wrapped().key in this.data},N.prototype.getAndRemove=function(t){return this.has(t)?this._getAndRemoveByKey(t.wrapped().key):null},N.prototype._getAndRemoveByKey=function(t){var e=this.data[t].shift();return e.timeout&&clearTimeout(e.timeout),0===this.data[t].length&&delete this.data[t],this.order.splice(this.order.indexOf(t),1),e.value},N.prototype.getByKey=function(t){var e=this.data[t];return e?e[0].value:null},N.prototype.get=function(t){return this.has(t)?this.data[t.wrapped().key][0].value:null},N.prototype.remove=function(t,e){if(!this.has(t))return this;var r=t.wrapped().key,n=void 0===e?0:this.data[r].indexOf(e),i=this.data[r][n];return this.data[r].splice(n,1),i.timeout&&clearTimeout(i.timeout),0===this.data[r].length&&delete this.data[r],this.onRemove(i.value),this.order.splice(this.order.indexOf(r),1),this},N.prototype.setMaxSize=function(t){for(this.max=t;this.order.length>this.max;){var e=this._getAndRemoveByKey(this.order[0]);e&&this.onRemove(e)}return this},N.prototype.filter=function(t){var e=[];for(var r in this.data)for(var n=0,i=this.data[r];n<i.length;n+=1){var a=i[n];t(a.value)||e.push(a)}for(var o=0,s=e;o<s.length;o+=1){var l=s[o];this.remove(l.value.tileID,l)}};var j=function(t,e,r){this.context=t;var n=t.gl;this.buffer=n.createBuffer(),this.dynamicDraw=Boolean(r),this.context.unbindVAO(),t.bindElementBuffer.set(this.buffer),n.bufferData(n.ELEMENT_ARRAY_BUFFER,e.arrayBuffer,this.dynamicDraw?n.DYNAMIC_DRAW:n.STATIC_DRAW),this.dynamicDraw||delete e.arrayBuffer};j.prototype.bind=function(){this.context.bindElementBuffer.set(this.buffer)},j.prototype.updateData=function(t){var e=this.context.gl;this.context.unbindVAO(),this.bind(),e.bufferSubData(e.ELEMENT_ARRAY_BUFFER,0,t.arrayBuffer)},j.prototype.destroy=function(){var t=this.context.gl;this.buffer&&(t.deleteBuffer(this.buffer),delete this.buffer)};var U={Int8:"BYTE",Uint8:"UNSIGNED_BYTE",Int16:"SHORT",Uint16:"UNSIGNED_SHORT",Int32:"INT",Uint32:"UNSIGNED_INT",Float32:"FLOAT"},V=function(t,e,r,n){this.length=e.length,this.attributes=r,this.itemSize=e.bytesPerElement,this.dynamicDraw=n,this.context=t;var i=t.gl;this.buffer=i.createBuffer(),t.bindVertexBuffer.set(this.buffer),i.bufferData(i.ARRAY_BUFFER,e.arrayBuffer,this.dynamicDraw?i.DYNAMIC_DRAW:i.STATIC_DRAW),this.dynamicDraw||delete e.arrayBuffer};V.prototype.bind=function(){this.context.bindVertexBuffer.set(this.buffer)},V.prototype.updateData=function(t){var e=this.context.gl;this.bind(),e.bufferSubData(e.ARRAY_BUFFER,0,t.arrayBuffer)},V.prototype.enableAttributes=function(t,e){for(var r=0;r<this.attributes.length;r++){var n=this.attributes[r],i=e.attributes[n.name];void 0!==i&&t.enableVertexAttribArray(i)}},V.prototype.setVertexAttribPointers=function(t,e,r){for(var n=0;n<this.attributes.length;n++){var i=this.attributes[n],a=e.attributes[i.name];void 0!==a&&t.vertexAttribPointer(a,i.components,t[U[i.type]],!1,this.itemSize,i.offset+this.itemSize*(r||0))}},V.prototype.destroy=function(){var t=this.context.gl;this.buffer&&(t.deleteBuffer(this.buffer),delete this.buffer)};var H=function(t){this.gl=t.gl,this.default=this.getDefault(),this.current=this.default,this.dirty=!1};H.prototype.get=function(){return this.current},H.prototype.set=function(t){},H.prototype.getDefault=function(){return this.default},H.prototype.setDefault=function(){this.set(this.default)};var q=function(e){function r(){e.apply(this,arguments)}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.getDefault=function(){return t.Color.transparent},r.prototype.set=function(t){var e=this.current;(t.r!==e.r||t.g!==e.g||t.b!==e.b||t.a!==e.a||this.dirty)&&(this.gl.clearColor(t.r,t.g,t.b,t.a),this.current=t,this.dirty=!1)},r}(H),G=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return 1},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.clearDepth(t),this.current=t,this.dirty=!1)},e}(H),Y=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return 0},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.clearStencil(t),this.current=t,this.dirty=!1)},e}(H),W=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return[!0,!0,!0,!0]},e.prototype.set=function(t){var e=this.current;(t[0]!==e[0]||t[1]!==e[1]||t[2]!==e[2]||t[3]!==e[3]||this.dirty)&&(this.gl.colorMask(t[0],t[1],t[2],t[3]),this.current=t,this.dirty=!1)},e}(H),X=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return!0},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.depthMask(t),this.current=t,this.dirty=!1)},e}(H),Z=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return 255},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.stencilMask(t),this.current=t,this.dirty=!1)},e}(H),J=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return{func:this.gl.ALWAYS,ref:0,mask:255}},e.prototype.set=function(t){var e=this.current;(t.func!==e.func||t.ref!==e.ref||t.mask!==e.mask||this.dirty)&&(this.gl.stencilFunc(t.func,t.ref,t.mask),this.current=t,this.dirty=!1)},e}(H),K=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){var t=this.gl;return[t.KEEP,t.KEEP,t.KEEP]},e.prototype.set=function(t){var e=this.current;(t[0]!==e[0]||t[1]!==e[1]||t[2]!==e[2]||this.dirty)&&(this.gl.stencilOp(t[0],t[1],t[2]),this.current=t,this.dirty=!1)},e}(H),Q=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return!1},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;t?e.enable(e.STENCIL_TEST):e.disable(e.STENCIL_TEST),this.current=t,this.dirty=!1}},e}(H),$=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return[0,1]},e.prototype.set=function(t){var e=this.current;(t[0]!==e[0]||t[1]!==e[1]||this.dirty)&&(this.gl.depthRange(t[0],t[1]),this.current=t,this.dirty=!1)},e}(H),tt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return!1},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;t?e.enable(e.DEPTH_TEST):e.disable(e.DEPTH_TEST),this.current=t,this.dirty=!1}},e}(H),et=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return this.gl.LESS},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.depthFunc(t),this.current=t,this.dirty=!1)},e}(H),rt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return!1},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;t?e.enable(e.BLEND):e.disable(e.BLEND),this.current=t,this.dirty=!1}},e}(H),nt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){var t=this.gl;return[t.ONE,t.ZERO]},e.prototype.set=function(t){var e=this.current;(t[0]!==e[0]||t[1]!==e[1]||this.dirty)&&(this.gl.blendFunc(t[0],t[1]),this.current=t,this.dirty=!1)},e}(H),it=function(e){function r(){e.apply(this,arguments)}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.getDefault=function(){return t.Color.transparent},r.prototype.set=function(t){var e=this.current;(t.r!==e.r||t.g!==e.g||t.b!==e.b||t.a!==e.a||this.dirty)&&(this.gl.blendColor(t.r,t.g,t.b,t.a),this.current=t,this.dirty=!1)},r}(H),at=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return this.gl.FUNC_ADD},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.blendEquation(t),this.current=t,this.dirty=!1)},e}(H),ot=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return!1},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;t?e.enable(e.CULL_FACE):e.disable(e.CULL_FACE),this.current=t,this.dirty=!1}},e}(H),st=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return this.gl.BACK},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.cullFace(t),this.current=t,this.dirty=!1)},e}(H),lt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return this.gl.CCW},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.frontFace(t),this.current=t,this.dirty=!1)},e}(H),ct=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.useProgram(t),this.current=t,this.dirty=!1)},e}(H),ut=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return this.gl.TEXTURE0},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.activeTexture(t),this.current=t,this.dirty=!1)},e}(H),ft=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){var t=this.gl;return[0,0,t.drawingBufferWidth,t.drawingBufferHeight]},e.prototype.set=function(t){var e=this.current;(t[0]!==e[0]||t[1]!==e[1]||t[2]!==e[2]||t[3]!==e[3]||this.dirty)&&(this.gl.viewport(t[0],t[1],t[2],t[3]),this.current=t,this.dirty=!1)},e}(H),ht=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,t),this.current=t,this.dirty=!1}},e}(H),pt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.bindRenderbuffer(e.RENDERBUFFER,t),this.current=t,this.dirty=!1}},e}(H),dt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.bindTexture(e.TEXTURE_2D,t),this.current=t,this.dirty=!1}},e}(H),mt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.bindBuffer(e.ARRAY_BUFFER,t),this.current=t,this.dirty=!1}},e}(H),gt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){var e=this.gl;e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t),this.current=t,this.dirty=!1},e}(H),vt=function(t){function e(e){t.call(this,e),this.vao=e.extVertexArrayObject}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){this.vao&&(t!==this.current||this.dirty)&&(this.vao.bindVertexArrayOES(t),this.current=t,this.dirty=!1)},e}(H),yt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return 4},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.pixelStorei(e.UNPACK_ALIGNMENT,t),this.current=t,this.dirty=!1}},e}(H),xt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return!1},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t),this.current=t,this.dirty=!1}},e}(H),bt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return!1},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,t),this.current=t,this.dirty=!1}},e}(H),_t=function(t){function e(e,r){t.call(this,e),this.context=e,this.parent=r}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e}(H),wt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setDirty=function(){this.dirty=!0},e.prototype.set=function(t){if(t!==this.current||this.dirty){this.context.bindFramebuffer.set(this.parent);var e=this.gl;e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t,0),this.current=t,this.dirty=!1}},e}(_t),Tt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){if(t!==this.current||this.dirty){this.context.bindFramebuffer.set(this.parent);var e=this.gl;e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,t),this.current=t,this.dirty=!1}},e}(_t),kt=function(t,e,r,n){this.context=t,this.width=e,this.height=r;var i=t.gl,a=this.framebuffer=i.createFramebuffer();this.colorAttachment=new wt(t,a),n&&(this.depthAttachment=new Tt(t,a))};kt.prototype.destroy=function(){var t=this.context.gl,e=this.colorAttachment.get();if(e&&t.deleteTexture(e),this.depthAttachment){var r=this.depthAttachment.get();r&&t.deleteRenderbuffer(r)}t.deleteFramebuffer(this.framebuffer)};var At=function(t,e,r){this.func=t,this.mask=e,this.range=r};At.ReadOnly=!1,At.ReadWrite=!0,At.disabled=new At(519,At.ReadOnly,[0,1]);var Mt=function(t,e,r,n,i,a){this.test=t,this.ref=e,this.mask=r,this.fail=n,this.depthFail=i,this.pass=a};Mt.disabled=new Mt({func:519,mask:0},0,0,7680,7680,7680);var St=function(t,e,r){this.blendFunction=t,this.blendColor=e,this.mask=r};St.disabled=new St(St.Replace=[1,0],t.Color.transparent,[!1,!1,!1,!1]),St.unblended=new St(St.Replace,t.Color.transparent,[!0,!0,!0,!0]),St.alphaBlended=new St([1,771],t.Color.transparent,[!0,!0,!0,!0]);var Et=function(t,e,r){this.enable=t,this.mode=e,this.frontFace=r};Et.disabled=new Et(!1,1029,2305),Et.backCCW=new Et(!0,1029,2305);var Lt=function(t){this.gl=t,this.extVertexArrayObject=this.gl.getExtension("OES_vertex_array_object"),this.clearColor=new q(this),this.clearDepth=new G(this),this.clearStencil=new Y(this),this.colorMask=new W(this),this.depthMask=new X(this),this.stencilMask=new Z(this),this.stencilFunc=new J(this),this.stencilOp=new K(this),this.stencilTest=new Q(this),this.depthRange=new $(this),this.depthTest=new tt(this),this.depthFunc=new et(this),this.blend=new rt(this),this.blendFunc=new nt(this),this.blendColor=new it(this),this.blendEquation=new at(this),this.cullFace=new ot(this),this.cullFaceSide=new st(this),this.frontFace=new lt(this),this.program=new ct(this),this.activeTexture=new ut(this),this.viewport=new ft(this),this.bindFramebuffer=new ht(this),this.bindRenderbuffer=new pt(this),this.bindTexture=new dt(this),this.bindVertexBuffer=new mt(this),this.bindElementBuffer=new gt(this),this.bindVertexArrayOES=this.extVertexArrayObject&&new vt(this),this.pixelStoreUnpack=new yt(this),this.pixelStoreUnpackPremultiplyAlpha=new xt(this),this.pixelStoreUnpackFlipY=new bt(this),this.extTextureFilterAnisotropic=t.getExtension("EXT_texture_filter_anisotropic")||t.getExtension("MOZ_EXT_texture_filter_anisotropic")||t.getExtension("WEBKIT_EXT_texture_filter_anisotropic"),this.extTextureFilterAnisotropic&&(this.extTextureFilterAnisotropicMax=t.getParameter(this.extTextureFilterAnisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT)),this.extTextureHalfFloat=t.getExtension("OES_texture_half_float"),this.extTextureHalfFloat&&(t.getExtension("OES_texture_half_float_linear"),this.extRenderToTextureHalfFloat=t.getExtension("EXT_color_buffer_half_float")),this.extTimerQuery=t.getExtension("EXT_disjoint_timer_query")};Lt.prototype.setDefault=function(){this.unbindVAO(),this.clearColor.setDefault(),this.clearDepth.setDefault(),this.clearStencil.setDefault(),this.colorMask.setDefault(),this.depthMask.setDefault(),this.stencilMask.setDefault(),this.stencilFunc.setDefault(),this.stencilOp.setDefault(),this.stencilTest.setDefault(),this.depthRange.setDefault(),this.depthTest.setDefault(),this.depthFunc.setDefault(),this.blend.setDefault(),this.blendFunc.setDefault(),this.blendColor.setDefault(),this.blendEquation.setDefault(),this.cullFace.setDefault(),this.cullFaceSide.setDefault(),this.frontFace.setDefault(),this.program.setDefault(),this.activeTexture.setDefault(),this.bindFramebuffer.setDefault(),this.pixelStoreUnpack.setDefault(),this.pixelStoreUnpackPremultiplyAlpha.setDefault(),this.pixelStoreUnpackFlipY.setDefault()},Lt.prototype.setDirty=function(){this.clearColor.dirty=!0,this.clearDepth.dirty=!0,this.clearStencil.dirty=!0,this.colorMask.dirty=!0,this.depthMask.dirty=!0,this.stencilMask.dirty=!0,this.stencilFunc.dirty=!0,this.stencilOp.dirty=!0,this.stencilTest.dirty=!0,this.depthRange.dirty=!0,this.depthTest.dirty=!0,this.depthFunc.dirty=!0,this.blend.dirty=!0,this.blendFunc.dirty=!0,this.blendColor.dirty=!0,this.blendEquation.dirty=!0,this.cullFace.dirty=!0,this.cullFaceSide.dirty=!0,this.frontFace.dirty=!0,this.program.dirty=!0,this.activeTexture.dirty=!0,this.viewport.dirty=!0,this.bindFramebuffer.dirty=!0,this.bindRenderbuffer.dirty=!0,this.bindTexture.dirty=!0,this.bindVertexBuffer.dirty=!0,this.bindElementBuffer.dirty=!0,this.extVertexArrayObject&&(this.bindVertexArrayOES.dirty=!0),this.pixelStoreUnpack.dirty=!0,this.pixelStoreUnpackPremultiplyAlpha.dirty=!0,this.pixelStoreUnpackFlipY.dirty=!0},Lt.prototype.createIndexBuffer=function(t,e){return new j(this,t,e)},Lt.prototype.createVertexBuffer=function(t,e,r){return new V(this,t,e,r)},Lt.prototype.createRenderbuffer=function(t,e,r){var n=this.gl,i=n.createRenderbuffer();return this.bindRenderbuffer.set(i),n.renderbufferStorage(n.RENDERBUFFER,t,e,r),this.bindRenderbuffer.set(null),i},Lt.prototype.createFramebuffer=function(t,e,r){return new kt(this,t,e,r)},Lt.prototype.clear=function(t){var e=t.color,r=t.depth,n=this.gl,i=0;e&&(i|=n.COLOR_BUFFER_BIT,this.clearColor.set(e),this.colorMask.set([!0,!0,!0,!0])),void 0!==r&&(i|=n.DEPTH_BUFFER_BIT,this.depthRange.set([0,1]),this.clearDepth.set(r),this.depthMask.set(!0)),n.clear(i)},Lt.prototype.setCullFace=function(t){!1===t.enable?this.cullFace.set(!1):(this.cullFace.set(!0),this.cullFaceSide.set(t.mode),this.frontFace.set(t.frontFace))},Lt.prototype.setDepthMode=function(t){t.func!==this.gl.ALWAYS||t.mask?(this.depthTest.set(!0),this.depthFunc.set(t.func),this.depthMask.set(t.mask),this.depthRange.set(t.range)):this.depthTest.set(!1)},Lt.prototype.setStencilMode=function(t){t.test.func!==this.gl.ALWAYS||t.mask?(this.stencilTest.set(!0),this.stencilMask.set(t.mask),this.stencilOp.set([t.fail,t.depthFail,t.pass]),this.stencilFunc.set({func:t.test.func,ref:t.ref,mask:t.test.mask})):this.stencilTest.set(!1)},Lt.prototype.setColorMode=function(e){t.deepEqual(e.blendFunction,St.Replace)?this.blend.set(!1):(this.blend.set(!0),this.blendFunc.set(e.blendFunction),this.blendColor.set(e.blendColor)),this.colorMask.set(e.mask)},Lt.prototype.unbindVAO=function(){this.extVertexArrayObject&&this.bindVertexArrayOES.set(null)};var Ct=function(e){function r(r,n,i){var a=this;e.call(this),this.id=r,this.dispatcher=i,this.on("data",(function(t){"source"===t.dataType&&"metadata"===t.sourceDataType&&(a._sourceLoaded=!0),a._sourceLoaded&&!a._paused&&"source"===t.dataType&&"content"===t.sourceDataType&&(a.reload(),a.transform&&a.update(a.transform))})),this.on("error",(function(){a._sourceErrored=!0})),this._source=function(e,r,n,i){var a=new D[r.type](e,r,n,i);if(a.id!==e)throw new Error("Expected Source id to be "+e+" instead of "+a.id);return t.bindAll(["load","abort","unload","serialize","prepare"],a),a}(r,n,i,this),this._tiles={},this._cache=new N(0,this._unloadTile.bind(this)),this._timers={},this._cacheTimers={},this._maxTileCacheSize=null,this._loadedParentTiles={},this._coveredTiles={},this._state=new t.SourceFeatureState}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.onAdd=function(t){this.map=t,this._maxTileCacheSize=t?t._maxTileCacheSize:null,this._source&&this._source.onAdd&&this._source.onAdd(t)},r.prototype.onRemove=function(t){this._source&&this._source.onRemove&&this._source.onRemove(t)},r.prototype.loaded=function(){if(this._sourceErrored)return!0;if(!this._sourceLoaded)return!1;if(!this._source.loaded())return!1;for(var t in this._tiles){var e=this._tiles[t];if("loaded"!==e.state&&"errored"!==e.state)return!1}return!0},r.prototype.getSource=function(){return this._source},r.prototype.pause=function(){this._paused=!0},r.prototype.resume=function(){if(this._paused){var t=this._shouldReloadOnResume;this._paused=!1,this._shouldReloadOnResume=!1,t&&this.reload(),this.transform&&this.update(this.transform)}},r.prototype._loadTile=function(t,e){return this._source.loadTile(t,e)},r.prototype._unloadTile=function(t){if(this._source.unloadTile)return this._source.unloadTile(t,(function(){}))},r.prototype._abortTile=function(t){if(this._source.abortTile)return this._source.abortTile(t,(function(){}))},r.prototype.serialize=function(){return this._source.serialize()},r.prototype.prepare=function(t){for(var e in this._source.prepare&&this._source.prepare(),this._state.coalesceChanges(this._tiles,this.map?this.map.painter:null),this._tiles){var r=this._tiles[e];r.upload(t),r.prepare(this.map.style.imageManager)}},r.prototype.getIds=function(){return t.values(this._tiles).map((function(t){return t.tileID})).sort(Pt).map((function(t){return t.key}))},r.prototype.getRenderableIds=function(e){var r=this,n=[];for(var i in this._tiles)this._isIdRenderable(i,e)&&n.push(this._tiles[i]);return e?n.sort((function(e,n){var i=e.tileID,a=n.tileID,o=new t.Point(i.canonical.x,i.canonical.y)._rotate(r.transform.angle),s=new t.Point(a.canonical.x,a.canonical.y)._rotate(r.transform.angle);return i.overscaledZ-a.overscaledZ||s.y-o.y||s.x-o.x})).map((function(t){return t.tileID.key})):n.map((function(t){return t.tileID})).sort(Pt).map((function(t){return t.key}))},r.prototype.hasRenderableParent=function(t){var e=this.findLoadedParent(t,0);return!!e&&this._isIdRenderable(e.tileID.key)},r.prototype._isIdRenderable=function(t,e){return this._tiles[t]&&this._tiles[t].hasData()&&!this._coveredTiles[t]&&(e||!this._tiles[t].holdingForFade())},r.prototype.reload=function(){if(this._paused)this._shouldReloadOnResume=!0;else for(var t in this._cache.reset(),this._tiles)"errored"!==this._tiles[t].state&&this._reloadTile(t,"reloading")},r.prototype._reloadTile=function(t,e){var r=this._tiles[t];r&&("loading"!==r.state&&(r.state=e),this._loadTile(r,this._tileLoaded.bind(this,r,t,e)))},r.prototype._tileLoaded=function(e,r,n,i){if(i)return e.state="errored",void(404!==i.status?this._source.fire(new t.ErrorEvent(i,{tile:e})):this.update(this.transform));e.timeAdded=t.browser.now(),"expired"===n&&(e.refreshedUponExpiration=!0),this._setTileReloadTimer(r,e),"raster-dem"===this.getSource().type&&e.dem&&this._backfillDEM(e),this._state.initializeTileState(e,this.map?this.map.painter:null),this._source.fire(new t.Event("data",{dataType:"source",tile:e,coord:e.tileID}))},r.prototype._backfillDEM=function(t){for(var e=this.getRenderableIds(),r=0;r<e.length;r++){var n=e[r];if(t.neighboringTiles&&t.neighboringTiles[n]){var i=this.getTileByID(n);a(t,i),a(i,t)}}function a(t,e){t.needsHillshadePrepare=!0;var r=e.tileID.canonical.x-t.tileID.canonical.x,n=e.tileID.canonical.y-t.tileID.canonical.y,i=Math.pow(2,t.tileID.canonical.z),a=e.tileID.key;0===r&&0===n||Math.abs(n)>1||(Math.abs(r)>1&&(1===Math.abs(r+i)?r+=i:1===Math.abs(r-i)&&(r-=i)),e.dem&&t.dem&&(t.dem.backfillBorder(e.dem,r,n),t.neighboringTiles&&t.neighboringTiles[a]&&(t.neighboringTiles[a].backfilled=!0)))}},r.prototype.getTile=function(t){return this.getTileByID(t.key)},r.prototype.getTileByID=function(t){return this._tiles[t]},r.prototype._retainLoadedChildren=function(t,e,r,n){for(var i in this._tiles){var a=this._tiles[i];if(!(n[i]||!a.hasData()||a.tileID.overscaledZ<=e||a.tileID.overscaledZ>r)){for(var o=a.tileID;a&&a.tileID.overscaledZ>e+1;){var s=a.tileID.scaledTo(a.tileID.overscaledZ-1);(a=this._tiles[s.key])&&a.hasData()&&(o=s)}for(var l=o;l.overscaledZ>e;)if(t[(l=l.scaledTo(l.overscaledZ-1)).key]){n[o.key]=o;break}}}},r.prototype.findLoadedParent=function(t,e){if(t.key in this._loadedParentTiles){var r=this._loadedParentTiles[t.key];return r&&r.tileID.overscaledZ>=e?r:null}for(var n=t.overscaledZ-1;n>=e;n--){var i=t.scaledTo(n),a=this._getLoadedTile(i);if(a)return a}},r.prototype._getLoadedTile=function(t){var e=this._tiles[t.key];return e&&e.hasData()?e:this._cache.getByKey(t.wrapped().key)},r.prototype.updateCacheSize=function(t){var e=(Math.ceil(t.width/this._source.tileSize)+1)*(Math.ceil(t.height/this._source.tileSize)+1),r=Math.floor(5*e),n="number"==typeof this._maxTileCacheSize?Math.min(this._maxTileCacheSize,r):r;this._cache.setMaxSize(n)},r.prototype.handleWrapJump=function(t){var e=(t-(void 0===this._prevLng?t:this._prevLng))/360,r=Math.round(e);if(this._prevLng=t,r){var n={};for(var i in this._tiles){var a=this._tiles[i];a.tileID=a.tileID.unwrapTo(a.tileID.wrap+r),n[a.tileID.key]=a}for(var o in this._tiles=n,this._timers)clearTimeout(this._timers[o]),delete this._timers[o];for(var s in this._tiles){var l=this._tiles[s];this._setTileReloadTimer(s,l)}}},r.prototype.update=function(e){var n=this;if(this.transform=e,this._sourceLoaded&&!this._paused){var i;this.updateCacheSize(e),this.handleWrapJump(this.transform.center.lng),this._coveredTiles={},this.used?this._source.tileID?i=e.getVisibleUnwrappedCoordinates(this._source.tileID).map((function(e){return new t.OverscaledTileID(e.canonical.z,e.wrap,e.canonical.z,e.canonical.x,e.canonical.y)})):(i=e.coveringTiles({tileSize:this._source.tileSize,minzoom:this._source.minzoom,maxzoom:this._source.maxzoom,roundZoom:this._source.roundZoom,reparseOverscaled:this._source.reparseOverscaled}),this._source.hasTile&&(i=i.filter((function(t){return n._source.hasTile(t)})))):i=[];var a=e.coveringZoomLevel(this._source),o=Math.max(a-r.maxOverzooming,this._source.minzoom),s=Math.max(a+r.maxUnderzooming,this._source.minzoom),l=this._updateRetainedTiles(i,a);if(It(this._source.type)){for(var c={},u={},f=0,h=Object.keys(l);f<h.length;f+=1){var p=h[f],d=l[p],m=this._tiles[p];if(m&&!(m.fadeEndTime&&m.fadeEndTime<=t.browser.now())){var g=this.findLoadedParent(d,o);g&&(this._addTile(g.tileID),c[g.tileID.key]=g.tileID),u[p]=d}}for(var v in this._retainLoadedChildren(u,a,s,l),c)l[v]||(this._coveredTiles[v]=!0,l[v]=c[v])}for(var y in l)this._tiles[y].clearFadeHold();for(var x=0,b=t.keysDifference(this._tiles,l);x<b.length;x+=1){var _=b[x],w=this._tiles[_];w.hasSymbolBuckets&&!w.holdingForFade()?w.setHoldDuration(this.map._fadeDuration):w.hasSymbolBuckets&&!w.symbolFadeFinished()||this._removeTile(_)}this._updateLoadedParentTileCache()}},r.prototype.releaseSymbolFadeTiles=function(){for(var t in this._tiles)this._tiles[t].holdingForFade()&&this._removeTile(t)},r.prototype._updateRetainedTiles=function(t,e){for(var n={},i={},a=Math.max(e-r.maxOverzooming,this._source.minzoom),o=Math.max(e+r.maxUnderzooming,this._source.minzoom),s={},l=0,c=t;l<c.length;l+=1){var u=c[l],f=this._addTile(u);n[u.key]=u,f.hasData()||e<this._source.maxzoom&&(s[u.key]=u)}this._retainLoadedChildren(s,e,o,n);for(var h=0,p=t;h<p.length;h+=1){var d=p[h],m=this._tiles[d.key];if(!m.hasData()){if(e+1>this._source.maxzoom){var g=d.children(this._source.maxzoom)[0],v=this.getTile(g);if(v&&v.hasData()){n[g.key]=g;continue}}else{var y=d.children(this._source.maxzoom);if(n[y[0].key]&&n[y[1].key]&&n[y[2].key]&&n[y[3].key])continue}for(var x=m.wasRequested(),b=d.overscaledZ-1;b>=a;--b){var _=d.scaledTo(b);if(i[_.key])break;if(i[_.key]=!0,!(m=this.getTile(_))&&x&&(m=this._addTile(_)),m&&(n[_.key]=_,x=m.wasRequested(),m.hasData()))break}}}return n},r.prototype._updateLoadedParentTileCache=function(){for(var t in this._loadedParentTiles={},this._tiles){for(var e=[],r=void 0,n=this._tiles[t].tileID;n.overscaledZ>0;){if(n.key in this._loadedParentTiles){r=this._loadedParentTiles[n.key];break}e.push(n.key);var i=n.scaledTo(n.overscaledZ-1);if(r=this._getLoadedTile(i))break;n=i}for(var a=0,o=e;a<o.length;a+=1){var s=o[a];this._loadedParentTiles[s]=r}}},r.prototype._addTile=function(e){var r=this._tiles[e.key];if(r)return r;(r=this._cache.getAndRemove(e))&&(this._setTileReloadTimer(e.key,r),r.tileID=e,this._state.initializeTileState(r,this.map?this.map.painter:null),this._cacheTimers[e.key]&&(clearTimeout(this._cacheTimers[e.key]),delete this._cacheTimers[e.key],this._setTileReloadTimer(e.key,r)));var n=Boolean(r);return n||(r=new t.Tile(e,this._source.tileSize*e.overscaleFactor()),this._loadTile(r,this._tileLoaded.bind(this,r,e.key,r.state))),r?(r.uses++,this._tiles[e.key]=r,n||this._source.fire(new t.Event("dataloading",{tile:r,coord:r.tileID,dataType:"source"})),r):null},r.prototype._setTileReloadTimer=function(t,e){var r=this;t in this._timers&&(clearTimeout(this._timers[t]),delete this._timers[t]);var n=e.getExpiryTimeout();n&&(this._timers[t]=setTimeout((function(){r._reloadTile(t,"expired"),delete r._timers[t]}),n))},r.prototype._removeTile=function(t){var e=this._tiles[t];e&&(e.uses--,delete this._tiles[t],this._timers[t]&&(clearTimeout(this._timers[t]),delete this._timers[t]),e.uses>0||(e.hasData()&&"reloading"!==e.state?this._cache.add(e.tileID,e,e.getExpiryTimeout()):(e.aborted=!0,this._abortTile(e),this._unloadTile(e))))},r.prototype.clearTiles=function(){for(var t in this._shouldReloadOnResume=!1,this._paused=!1,this._tiles)this._removeTile(t);this._cache.reset()},r.prototype.tilesIn=function(e,r,n){var i=this,a=[],o=this.transform;if(!o)return a;for(var s=n?o.getCameraQueryGeometry(e):e,l=e.map((function(t){return o.pointCoordinate(t)})),c=s.map((function(t){return o.pointCoordinate(t)})),u=this.getIds(),f=1/0,h=1/0,p=-1/0,d=-1/0,m=0,g=c;m<g.length;m+=1){var v=g[m];f=Math.min(f,v.x),h=Math.min(h,v.y),p=Math.max(p,v.x),d=Math.max(d,v.y)}for(var y=function(e){var n=i._tiles[u[e]];if(!n.holdingForFade()){var s=n.tileID,m=Math.pow(2,o.zoom-n.tileID.overscaledZ),g=r*n.queryPadding*t.EXTENT/n.tileSize/m,v=[s.getTilePoint(new t.MercatorCoordinate(f,h)),s.getTilePoint(new t.MercatorCoordinate(p,d))];if(v[0].x-g<t.EXTENT&&v[0].y-g<t.EXTENT&&v[1].x+g>=0&&v[1].y+g>=0){var y=l.map((function(t){return s.getTilePoint(t)})),x=c.map((function(t){return s.getTilePoint(t)}));a.push({tile:n,tileID:s,queryGeometry:y,cameraQueryGeometry:x,scale:m})}}},x=0;x<u.length;x++)y(x);return a},r.prototype.getVisibleCoordinates=function(t){for(var e=this,r=this.getRenderableIds(t).map((function(t){return e._tiles[t].tileID})),n=0,i=r;n<i.length;n+=1){var a=i[n];a.posMatrix=this.transform.calculatePosMatrix(a.toUnwrapped())}return r},r.prototype.hasTransition=function(){if(this._source.hasTransition())return!0;if(It(this._source.type))for(var e in this._tiles){var r=this._tiles[e];if(void 0!==r.fadeEndTime&&r.fadeEndTime>=t.browser.now())return!0}return!1},r.prototype.setFeatureState=function(t,e,r){t=t||"_geojsonTileLayer",this._state.updateState(t,e,r)},r.prototype.removeFeatureState=function(t,e,r){t=t||"_geojsonTileLayer",this._state.removeFeatureState(t,e,r)},r.prototype.getFeatureState=function(t,e){return t=t||"_geojsonTileLayer",this._state.getState(t,e)},r.prototype.setDependencies=function(t,e,r){var n=this._tiles[t];n&&n.setDependencies(e,r)},r.prototype.reloadTilesForDependencies=function(t,e){for(var r in this._tiles){this._tiles[r].hasDependency(t,e)&&this._reloadTile(r,"reloading")}this._cache.filter((function(r){return!r.hasDependency(t,e)}))},r}(t.Evented);function Pt(t,e){var r=Math.abs(2*t.wrap)-+(t.wrap<0),n=Math.abs(2*e.wrap)-+(e.wrap<0);return t.overscaledZ-e.overscaledZ||n-r||e.canonical.y-t.canonical.y||e.canonical.x-t.canonical.x}function It(t){return"raster"===t||"image"===t||"video"===t}function Ot(){return new t.window.Worker(Zi.workerUrl)}Ct.maxOverzooming=10,Ct.maxUnderzooming=3;var zt="mapboxgl_preloaded_worker_pool",Dt=function(){this.active={}};Dt.prototype.acquire=function(t){if(!this.workers)for(this.workers=[];this.workers.length<Dt.workerCount;)this.workers.push(new Ot);return this.active[t]=!0,this.workers.slice()},Dt.prototype.release=function(t){delete this.active[t],0===this.numActive()&&(this.workers.forEach((function(t){t.terminate()})),this.workers=null)},Dt.prototype.isPreloaded=function(){return!!this.active[zt]},Dt.prototype.numActive=function(){return Object.keys(this.active).length};var Rt,Ft=Math.floor(t.browser.hardwareConcurrency/2);function Bt(){return Rt||(Rt=new Dt),Rt}function Nt(e,r){var n={};for(var i in e)"ref"!==i&&(n[i]=e[i]);return t.refProperties.forEach((function(t){t in r&&(n[t]=r[t])})),n}function jt(t){t=t.slice();for(var e=Object.create(null),r=0;r<t.length;r++)e[t[r].id]=t[r];for(var n=0;n<t.length;n++)"ref"in t[n]&&(t[n]=Nt(t[n],e[t[n].ref]));return t}Dt.workerCount=Math.max(Math.min(Ft,6),1);var Ut={setStyle:"setStyle",addLayer:"addLayer",removeLayer:"removeLayer",setPaintProperty:"setPaintProperty",setLayoutProperty:"setLayoutProperty",setFilter:"setFilter",addSource:"addSource",removeSource:"removeSource",setGeoJSONSourceData:"setGeoJSONSourceData",setLayerZoomRange:"setLayerZoomRange",setLayerProperty:"setLayerProperty",setCenter:"setCenter",setZoom:"setZoom",setBearing:"setBearing",setPitch:"setPitch",setSprite:"setSprite",setGlyphs:"setGlyphs",setTransition:"setTransition",setLight:"setLight"};function Vt(t,e,r){r.push({command:Ut.addSource,args:[t,e[t]]})}function Ht(t,e,r){e.push({command:Ut.removeSource,args:[t]}),r[t]=!0}function qt(t,e,r,n){Ht(t,r,n),Vt(t,e,r)}function Gt(e,r,n){var i;for(i in e[n])if(e[n].hasOwnProperty(i)&&"data"!==i&&!t.deepEqual(e[n][i],r[n][i]))return!1;for(i in r[n])if(r[n].hasOwnProperty(i)&&"data"!==i&&!t.deepEqual(e[n][i],r[n][i]))return!1;return!0}function Yt(e,r,n,i,a,o){var s;for(s in r=r||{},e=e||{})e.hasOwnProperty(s)&&(t.deepEqual(e[s],r[s])||n.push({command:o,args:[i,s,r[s],a]}));for(s in r)r.hasOwnProperty(s)&&!e.hasOwnProperty(s)&&(t.deepEqual(e[s],r[s])||n.push({command:o,args:[i,s,r[s],a]}))}function Wt(t){return t.id}function Xt(t,e){return t[e.id]=e,t}function Zt(e,r){if(!e)return[{command:Ut.setStyle,args:[r]}];var n=[];try{if(!t.deepEqual(e.version,r.version))return[{command:Ut.setStyle,args:[r]}];t.deepEqual(e.center,r.center)||n.push({command:Ut.setCenter,args:[r.center]}),t.deepEqual(e.zoom,r.zoom)||n.push({command:Ut.setZoom,args:[r.zoom]}),t.deepEqual(e.bearing,r.bearing)||n.push({command:Ut.setBearing,args:[r.bearing]}),t.deepEqual(e.pitch,r.pitch)||n.push({command:Ut.setPitch,args:[r.pitch]}),t.deepEqual(e.sprite,r.sprite)||n.push({command:Ut.setSprite,args:[r.sprite]}),t.deepEqual(e.glyphs,r.glyphs)||n.push({command:Ut.setGlyphs,args:[r.glyphs]}),t.deepEqual(e.transition,r.transition)||n.push({command:Ut.setTransition,args:[r.transition]}),t.deepEqual(e.light,r.light)||n.push({command:Ut.setLight,args:[r.light]});var i={},a=[];!function(e,r,n,i){var a;for(a in r=r||{},e=e||{})e.hasOwnProperty(a)&&(r.hasOwnProperty(a)||Ht(a,n,i));for(a in r)r.hasOwnProperty(a)&&(e.hasOwnProperty(a)?t.deepEqual(e[a],r[a])||("geojson"===e[a].type&&"geojson"===r[a].type&&Gt(e,r,a)?n.push({command:Ut.setGeoJSONSourceData,args:[a,r[a].data]}):qt(a,r,n,i)):Vt(a,r,n))}(e.sources,r.sources,a,i);var o=[];e.layers&&e.layers.forEach((function(t){i[t.source]?n.push({command:Ut.removeLayer,args:[t.id]}):o.push(t)})),n=n.concat(a),function(e,r,n){r=r||[];var i,a,o,s,l,c,u,f=(e=e||[]).map(Wt),h=r.map(Wt),p=e.reduce(Xt,{}),d=r.reduce(Xt,{}),m=f.slice(),g=Object.create(null);for(i=0,a=0;i<f.length;i++)o=f[i],d.hasOwnProperty(o)?a++:(n.push({command:Ut.removeLayer,args:[o]}),m.splice(m.indexOf(o,a),1));for(i=0,a=0;i<h.length;i++)o=h[h.length-1-i],m[m.length-1-i]!==o&&(p.hasOwnProperty(o)?(n.push({command:Ut.removeLayer,args:[o]}),m.splice(m.lastIndexOf(o,m.length-a),1)):a++,c=m[m.length-i],n.push({command:Ut.addLayer,args:[d[o],c]}),m.splice(m.length-i,0,o),g[o]=!0);for(i=0;i<h.length;i++)if(s=p[o=h[i]],l=d[o],!g[o]&&!t.deepEqual(s,l))if(t.deepEqual(s.source,l.source)&&t.deepEqual(s["source-layer"],l["source-layer"])&&t.deepEqual(s.type,l.type)){for(u in Yt(s.layout,l.layout,n,o,null,Ut.setLayoutProperty),Yt(s.paint,l.paint,n,o,null,Ut.setPaintProperty),t.deepEqual(s.filter,l.filter)||n.push({command:Ut.setFilter,args:[o,l.filter]}),t.deepEqual(s.minzoom,l.minzoom)&&t.deepEqual(s.maxzoom,l.maxzoom)||n.push({command:Ut.setLayerZoomRange,args:[o,l.minzoom,l.maxzoom]}),s)s.hasOwnProperty(u)&&"layout"!==u&&"paint"!==u&&"filter"!==u&&"metadata"!==u&&"minzoom"!==u&&"maxzoom"!==u&&(0===u.indexOf("paint.")?Yt(s[u],l[u],n,o,u.slice(6),Ut.setPaintProperty):t.deepEqual(s[u],l[u])||n.push({command:Ut.setLayerProperty,args:[o,u,l[u]]}));for(u in l)l.hasOwnProperty(u)&&!s.hasOwnProperty(u)&&"layout"!==u&&"paint"!==u&&"filter"!==u&&"metadata"!==u&&"minzoom"!==u&&"maxzoom"!==u&&(0===u.indexOf("paint.")?Yt(s[u],l[u],n,o,u.slice(6),Ut.setPaintProperty):t.deepEqual(s[u],l[u])||n.push({command:Ut.setLayerProperty,args:[o,u,l[u]]}))}else n.push({command:Ut.removeLayer,args:[o]}),c=m[m.lastIndexOf(o)+1],n.push({command:Ut.addLayer,args:[l,c]})}(o,r.layers,n)}catch(t){console.warn("Unable to compute style diff:",t),n=[{command:Ut.setStyle,args:[r]}]}return n}var Jt=function(t,e){this.reset(t,e)};Jt.prototype.reset=function(t,e){this.points=t||[],this._distances=[0];for(var r=1;r<this.points.length;r++)this._distances[r]=this._distances[r-1]+this.points[r].dist(this.points[r-1]);this.length=this._distances[this._distances.length-1],this.padding=Math.min(e||0,.5*this.length),this.paddedLength=this.length-2*this.padding},Jt.prototype.lerp=function(e){if(1===this.points.length)return this.points[0];e=t.clamp(e,0,1);for(var r=1,n=this._distances[r],i=e*this.paddedLength+this.padding;n<i&&r<this._distances.length;)n=this._distances[++r];var a=r-1,o=this._distances[a],s=n-o,l=s>0?(i-o)/s:0;return this.points[a].mult(1-l).add(this.points[r].mult(l))};var Kt=function(t,e,r){var n=this.boxCells=[],i=this.circleCells=[];this.xCellCount=Math.ceil(t/r),this.yCellCount=Math.ceil(e/r);for(var a=0;a<this.xCellCount*this.yCellCount;a++)n.push([]),i.push([]);this.circleKeys=[],this.boxKeys=[],this.bboxes=[],this.circles=[],this.width=t,this.height=e,this.xScale=this.xCellCount/t,this.yScale=this.yCellCount/e,this.boxUid=0,this.circleUid=0};function Qt(e,r,n,i,a){var o=t.create();return r?(t.scale(o,o,[1/a,1/a,1]),n||t.rotateZ(o,o,i.angle)):t.multiply(o,i.labelPlaneMatrix,e),o}function $t(e,r,n,i,a){if(r){var o=t.clone(e);return t.scale(o,o,[a,a,1]),n||t.rotateZ(o,o,-i.angle),o}return i.glCoordMatrix}function te(e,r){var n=[e.x,e.y,0,1];fe(n,n,r);var i=n[3];return{point:new t.Point(n[0]/i,n[1]/i),signedDistanceFromCamera:i}}function ee(t,e){return.5+t/e*.5}function re(t,e){var r=t[0]/t[3],n=t[1]/t[3];return r>=-e[0]&&r<=e[0]&&n>=-e[1]&&n<=e[1]}function ne(e,r,n,i,a,o,s,l){var c=i?e.textSizeData:e.iconSizeData,u=t.evaluateSizeForZoom(c,n.transform.zoom),f=[256/n.width*2+1,256/n.height*2+1],h=i?e.text.dynamicLayoutVertexArray:e.icon.dynamicLayoutVertexArray;h.clear();for(var p=e.lineVertexArray,d=i?e.text.placedSymbolArray:e.icon.placedSymbolArray,m=n.transform.width/n.transform.height,g=!1,v=0;v<d.length;v++){var y=d.get(v);if(y.hidden||y.writingMode===t.WritingMode.vertical&&!g)ue(y.numGlyphs,h);else{g=!1;var x=[y.anchorX,y.anchorY,0,1];if(t.transformMat4(x,x,r),re(x,f)){var b=x[3],_=ee(n.transform.cameraToCenterDistance,b),w=t.evaluateSizeForFeature(c,u,y),T=s?w/_:w*_,k=new t.Point(y.anchorX,y.anchorY),A=te(k,a).point,M={},S=oe(y,T,!1,l,r,a,o,e.glyphOffsetArray,p,h,A,k,M,m);g=S.useVertical,(S.notEnoughRoom||g||S.needsFlipping&&oe(y,T,!0,l,r,a,o,e.glyphOffsetArray,p,h,A,k,M,m).notEnoughRoom)&&ue(y.numGlyphs,h)}else ue(y.numGlyphs,h)}}i?e.text.dynamicLayoutVertexBuffer.updateData(h):e.icon.dynamicLayoutVertexBuffer.updateData(h)}function ie(t,e,r,n,i,a,o,s,l,c,u){var f=s.glyphStartIndex+s.numGlyphs,h=s.lineStartIndex,p=s.lineStartIndex+s.lineLength,d=e.getoffsetX(s.glyphStartIndex),m=e.getoffsetX(f-1),g=le(t*d,r,n,i,a,o,s.segment,h,p,l,c,u);if(!g)return null;var v=le(t*m,r,n,i,a,o,s.segment,h,p,l,c,u);return v?{first:g,last:v}:null}function ae(e,r,n,i){if(e===t.WritingMode.horizontal&&Math.abs(n.y-r.y)>Math.abs(n.x-r.x)*i)return{useVertical:!0};return(e===t.WritingMode.vertical?r.y<n.y:r.x>n.x)?{needsFlipping:!0}:null}function oe(e,r,n,i,a,o,s,l,c,u,f,h,p,d){var m,g=r/24,v=e.lineOffsetX*g,y=e.lineOffsetY*g;if(e.numGlyphs>1){var x=e.glyphStartIndex+e.numGlyphs,b=e.lineStartIndex,_=e.lineStartIndex+e.lineLength,w=ie(g,l,v,y,n,f,h,e,c,o,p);if(!w)return{notEnoughRoom:!0};var T=te(w.first.point,s).point,k=te(w.last.point,s).point;if(i&&!n){var A=ae(e.writingMode,T,k,d);if(A)return A}m=[w.first];for(var M=e.glyphStartIndex+1;M<x-1;M++)m.push(le(g*l.getoffsetX(M),v,y,n,f,h,e.segment,b,_,c,o,p));m.push(w.last)}else{if(i&&!n){var S=te(h,a).point,E=e.lineStartIndex+e.segment+1,L=new t.Point(c.getx(E),c.gety(E)),C=te(L,a),P=C.signedDistanceFromCamera>0?C.point:se(h,L,S,1,a),I=ae(e.writingMode,S,P,d);if(I)return I}var O=le(g*l.getoffsetX(e.glyphStartIndex),v,y,n,f,h,e.segment,e.lineStartIndex,e.lineStartIndex+e.lineLength,c,o,p);if(!O)return{notEnoughRoom:!0};m=[O]}for(var z=0,D=m;z<D.length;z+=1){var R=D[z];t.addDynamicAttributes(u,R.point,R.angle)}return{}}function se(t,e,r,n,i){var a=te(t.add(t.sub(e)._unit()),i).point,o=r.sub(a);return r.add(o._mult(n/o.mag()))}function le(e,r,n,i,a,o,s,l,c,u,f,h){var p=i?e-r:e+r,d=p>0?1:-1,m=0;i&&(d*=-1,m=Math.PI),d<0&&(m+=Math.PI);for(var g=d>0?l+s:l+s+1,v=a,y=a,x=0,b=0,_=Math.abs(p),w=[];x+b<=_;){if((g+=d)<l||g>=c)return null;if(y=v,w.push(v),void 0===(v=h[g])){var T=new t.Point(u.getx(g),u.gety(g)),k=te(T,f);if(k.signedDistanceFromCamera>0)v=h[g]=k.point;else{var A=g-d;v=se(0===x?o:new t.Point(u.getx(A),u.gety(A)),T,y,_-x+1,f)}}x+=b,b=y.dist(v)}var M=(_-x)/b,S=v.sub(y),E=S.mult(M)._add(y);E._add(S._unit()._perp()._mult(n*d));var L=m+Math.atan2(v.y-y.y,v.x-y.x);return w.push(E),{point:E,angle:L,path:w}}Kt.prototype.keysLength=function(){return this.boxKeys.length+this.circleKeys.length},Kt.prototype.insert=function(t,e,r,n,i){this._forEachCell(e,r,n,i,this._insertBoxCell,this.boxUid++),this.boxKeys.push(t),this.bboxes.push(e),this.bboxes.push(r),this.bboxes.push(n),this.bboxes.push(i)},Kt.prototype.insertCircle=function(t,e,r,n){this._forEachCell(e-n,r-n,e+n,r+n,this._insertCircleCell,this.circleUid++),this.circleKeys.push(t),this.circles.push(e),this.circles.push(r),this.circles.push(n)},Kt.prototype._insertBoxCell=function(t,e,r,n,i,a){this.boxCells[i].push(a)},Kt.prototype._insertCircleCell=function(t,e,r,n,i,a){this.circleCells[i].push(a)},Kt.prototype._query=function(t,e,r,n,i,a){if(r<0||t>this.width||n<0||e>this.height)return!i&&[];var o=[];if(t<=0&&e<=0&&this.width<=r&&this.height<=n){if(i)return!0;for(var s=0;s<this.boxKeys.length;s++)o.push({key:this.boxKeys[s],x1:this.bboxes[4*s],y1:this.bboxes[4*s+1],x2:this.bboxes[4*s+2],y2:this.bboxes[4*s+3]});for(var l=0;l<this.circleKeys.length;l++){var c=this.circles[3*l],u=this.circles[3*l+1],f=this.circles[3*l+2];o.push({key:this.circleKeys[l],x1:c-f,y1:u-f,x2:c+f,y2:u+f})}return a?o.filter(a):o}var h={hitTest:i,seenUids:{box:{},circle:{}}};return this._forEachCell(t,e,r,n,this._queryCell,o,h,a),i?o.length>0:o},Kt.prototype._queryCircle=function(t,e,r,n,i){var a=t-r,o=t+r,s=e-r,l=e+r;if(o<0||a>this.width||l<0||s>this.height)return!n&&[];var c=[],u={hitTest:n,circle:{x:t,y:e,radius:r},seenUids:{box:{},circle:{}}};return this._forEachCell(a,s,o,l,this._queryCellCircle,c,u,i),n?c.length>0:c},Kt.prototype.query=function(t,e,r,n,i){return this._query(t,e,r,n,!1,i)},Kt.prototype.hitTest=function(t,e,r,n,i){return this._query(t,e,r,n,!0,i)},Kt.prototype.hitTestCircle=function(t,e,r,n){return this._queryCircle(t,e,r,!0,n)},Kt.prototype._queryCell=function(t,e,r,n,i,a,o,s){var l=o.seenUids,c=this.boxCells[i];if(null!==c)for(var u=this.bboxes,f=0,h=c;f<h.length;f+=1){var p=h[f];if(!l.box[p]){l.box[p]=!0;var d=4*p;if(t<=u[d+2]&&e<=u[d+3]&&r>=u[d+0]&&n>=u[d+1]&&(!s||s(this.boxKeys[p]))){if(o.hitTest)return a.push(!0),!0;a.push({key:this.boxKeys[p],x1:u[d],y1:u[d+1],x2:u[d+2],y2:u[d+3]})}}}var m=this.circleCells[i];if(null!==m)for(var g=this.circles,v=0,y=m;v<y.length;v+=1){var x=y[v];if(!l.circle[x]){l.circle[x]=!0;var b=3*x;if(this._circleAndRectCollide(g[b],g[b+1],g[b+2],t,e,r,n)&&(!s||s(this.circleKeys[x]))){if(o.hitTest)return a.push(!0),!0;var _=g[b],w=g[b+1],T=g[b+2];a.push({key:this.circleKeys[x],x1:_-T,y1:w-T,x2:_+T,y2:w+T})}}}},Kt.prototype._queryCellCircle=function(t,e,r,n,i,a,o,s){var l=o.circle,c=o.seenUids,u=this.boxCells[i];if(null!==u)for(var f=this.bboxes,h=0,p=u;h<p.length;h+=1){var d=p[h];if(!c.box[d]){c.box[d]=!0;var m=4*d;if(this._circleAndRectCollide(l.x,l.y,l.radius,f[m+0],f[m+1],f[m+2],f[m+3])&&(!s||s(this.boxKeys[d])))return a.push(!0),!0}}var g=this.circleCells[i];if(null!==g)for(var v=this.circles,y=0,x=g;y<x.length;y+=1){var b=x[y];if(!c.circle[b]){c.circle[b]=!0;var _=3*b;if(this._circlesCollide(v[_],v[_+1],v[_+2],l.x,l.y,l.radius)&&(!s||s(this.circleKeys[b])))return a.push(!0),!0}}},Kt.prototype._forEachCell=function(t,e,r,n,i,a,o,s){for(var l=this._convertToXCellCoord(t),c=this._convertToYCellCoord(e),u=this._convertToXCellCoord(r),f=this._convertToYCellCoord(n),h=l;h<=u;h++)for(var p=c;p<=f;p++){var d=this.xCellCount*p+h;if(i.call(this,t,e,r,n,d,a,o,s))return}},Kt.prototype._convertToXCellCoord=function(t){return Math.max(0,Math.min(this.xCellCount-1,Math.floor(t*this.xScale)))},Kt.prototype._convertToYCellCoord=function(t){return Math.max(0,Math.min(this.yCellCount-1,Math.floor(t*this.yScale)))},Kt.prototype._circlesCollide=function(t,e,r,n,i,a){var o=n-t,s=i-e,l=r+a;return l*l>o*o+s*s},Kt.prototype._circleAndRectCollide=function(t,e,r,n,i,a,o){var s=(a-n)/2,l=Math.abs(t-(n+s));if(l>s+r)return!1;var c=(o-i)/2,u=Math.abs(e-(i+c));if(u>c+r)return!1;if(l<=s||u<=c)return!0;var f=l-s,h=u-c;return f*f+h*h<=r*r};var ce=new Float32Array([-1/0,-1/0,0,-1/0,-1/0,0,-1/0,-1/0,0,-1/0,-1/0,0]);function ue(t,e){for(var r=0;r<t;r++){var n=e.length;e.resize(n+4),e.float32.set(ce,3*n)}}function fe(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[4]*i+r[12],t[1]=r[1]*n+r[5]*i+r[13],t[3]=r[3]*n+r[7]*i+r[15],t}var he=function(t,e,r){void 0===e&&(e=new Kt(t.width+200,t.height+200,25)),void 0===r&&(r=new Kt(t.width+200,t.height+200,25)),this.transform=t,this.grid=e,this.ignoredGrid=r,this.pitchfactor=Math.cos(t._pitch)*t.cameraToCenterDistance,this.screenRightBoundary=t.width+100,this.screenBottomBoundary=t.height+100,this.gridRightBoundary=t.width+200,this.gridBottomBoundary=t.height+200};function pe(e,r,n){return r*(t.EXTENT/(e.tileSize*Math.pow(2,n-e.tileID.overscaledZ)))}he.prototype.placeCollisionBox=function(t,e,r,n,i){var a=this.projectAndGetPerspectiveRatio(n,t.anchorPointX,t.anchorPointY),o=r*a.perspectiveRatio,s=t.x1*o+a.point.x,l=t.y1*o+a.point.y,c=t.x2*o+a.point.x,u=t.y2*o+a.point.y;return!this.isInsideGrid(s,l,c,u)||!e&&this.grid.hitTest(s,l,c,u,i)?{box:[],offscreen:!1}:{box:[s,l,c,u],offscreen:this.isOffscreen(s,l,c,u)}},he.prototype.placeCollisionCircles=function(e,r,n,i,a,o,s,l,c,u,f,h,p){var d=[],m=new t.Point(r.anchorX,r.anchorY),g=te(m,o),v=ee(this.transform.cameraToCenterDistance,g.signedDistanceFromCamera),y=(u?a/v:a*v)/t.ONE_EM,x=te(m,s).point,b=ie(y,i,r.lineOffsetX*y,r.lineOffsetY*y,!1,x,m,r,n,s,{}),_=!1,w=!1,T=!0;if(b){for(var k=.5*h*v+p,A=new t.Point(-100,-100),M=new t.Point(this.screenRightBoundary,this.screenBottomBoundary),S=new Jt,E=b.first,L=b.last,C=[],P=E.path.length-1;P>=1;P--)C.push(E.path[P]);for(var I=1;I<L.path.length;I++)C.push(L.path[I]);var O=2.5*k;if(l){var z=C.map((function(t){return te(t,l)}));C=z.some((function(t){return t.signedDistanceFromCamera<=0}))?[]:z.map((function(t){return t.point}))}var D=[];if(C.length>0){for(var R=C[0].clone(),F=C[0].clone(),B=1;B<C.length;B++)R.x=Math.min(R.x,C[B].x),R.y=Math.min(R.y,C[B].y),F.x=Math.max(F.x,C[B].x),F.y=Math.max(F.y,C[B].y);D=R.x>=A.x&&F.x<=M.x&&R.y>=A.y&&F.y<=M.y?[C]:F.x<A.x||R.x>M.x||F.y<A.y||R.y>M.y?[]:t.clipLine([C],A.x,A.y,M.x,M.y)}for(var N=0,j=D;N<j.length;N+=1){var U=j[N];S.reset(U,.25*k);var V=0;V=S.length<=.5*k?1:Math.ceil(S.paddedLength/O)+1;for(var H=0;H<V;H++){var q=H/Math.max(V-1,1),G=S.lerp(q),Y=G.x+100,W=G.y+100;d.push(Y,W,k,0);var X=Y-k,Z=W-k,J=Y+k,K=W+k;if(T=T&&this.isOffscreen(X,Z,J,K),w=w||this.isInsideGrid(X,Z,J,K),!e&&this.grid.hitTestCircle(Y,W,k,f)&&(_=!0,!c))return{circles:[],offscreen:!1,collisionDetected:_}}}}return{circles:!c&&_||!w?[]:d,offscreen:T,collisionDetected:_}},he.prototype.queryRenderedSymbols=function(e){if(0===e.length||0===this.grid.keysLength()&&0===this.ignoredGrid.keysLength())return{};for(var r=[],n=1/0,i=1/0,a=-1/0,o=-1/0,s=0,l=e;s<l.length;s+=1){var c=l[s],u=new t.Point(c.x+100,c.y+100);n=Math.min(n,u.x),i=Math.min(i,u.y),a=Math.max(a,u.x),o=Math.max(o,u.y),r.push(u)}for(var f={},h={},p=0,d=this.grid.query(n,i,a,o).concat(this.ignoredGrid.query(n,i,a,o));p<d.length;p+=1){var m=d[p],g=m.key;if(void 0===f[g.bucketInstanceId]&&(f[g.bucketInstanceId]={}),!f[g.bucketInstanceId][g.featureIndex]){var v=[new t.Point(m.x1,m.y1),new t.Point(m.x2,m.y1),new t.Point(m.x2,m.y2),new t.Point(m.x1,m.y2)];t.polygonIntersectsPolygon(r,v)&&(f[g.bucketInstanceId][g.featureIndex]=!0,void 0===h[g.bucketInstanceId]&&(h[g.bucketInstanceId]=[]),h[g.bucketInstanceId].push(g.featureIndex))}}return h},he.prototype.insertCollisionBox=function(t,e,r,n,i){var a={bucketInstanceId:r,featureIndex:n,collisionGroupID:i};(e?this.ignoredGrid:this.grid).insert(a,t[0],t[1],t[2],t[3])},he.prototype.insertCollisionCircles=function(t,e,r,n,i){for(var a=e?this.ignoredGrid:this.grid,o={bucketInstanceId:r,featureIndex:n,collisionGroupID:i},s=0;s<t.length;s+=4)a.insertCircle(o,t[s],t[s+1],t[s+2])},he.prototype.projectAndGetPerspectiveRatio=function(e,r,n){var i=[r,n,0,1];return fe(i,i,e),{point:new t.Point((i[0]/i[3]+1)/2*this.transform.width+100,(-i[1]/i[3]+1)/2*this.transform.height+100),perspectiveRatio:.5+this.transform.cameraToCenterDistance/i[3]*.5}},he.prototype.isOffscreen=function(t,e,r,n){return r<100||t>=this.screenRightBoundary||n<100||e>this.screenBottomBoundary},he.prototype.isInsideGrid=function(t,e,r,n){return r>=0&&t<this.gridRightBoundary&&n>=0&&e<this.gridBottomBoundary},he.prototype.getViewportMatrix=function(){var e=t.identity([]);return t.translate(e,e,[-100,-100,0]),e};var de=function(t,e,r,n){this.opacity=t?Math.max(0,Math.min(1,t.opacity+(t.placed?e:-e))):n&&r?1:0,this.placed=r};de.prototype.isHidden=function(){return 0===this.opacity&&!this.placed};var me=function(t,e,r,n,i){this.text=new de(t?t.text:null,e,r,i),this.icon=new de(t?t.icon:null,e,n,i)};me.prototype.isHidden=function(){return this.text.isHidden()&&this.icon.isHidden()};var ge=function(t,e,r){this.text=t,this.icon=e,this.skipFade=r},ve=function(){this.invProjMatrix=t.create(),this.viewportMatrix=t.create(),this.circles=[]},ye=function(t,e,r,n,i){this.bucketInstanceId=t,this.featureIndex=e,this.sourceLayerIndex=r,this.bucketIndex=n,this.tileID=i},xe=function(t){this.crossSourceCollisions=t,this.maxGroupID=0,this.collisionGroups={}};function be(e,r,n,i,a){var o=t.getAnchorAlignment(e),s=-(o.horizontalAlign-.5)*r,l=-(o.verticalAlign-.5)*n,c=t.evaluateVariableOffset(e,i);return new t.Point(s+c[0]*a,l+c[1]*a)}function _e(e,r,n,i,a,o){var s=e.x1,l=e.x2,c=e.y1,u=e.y2,f=e.anchorPointX,h=e.anchorPointY,p=new t.Point(r,n);return i&&p._rotate(a?o:-o),{x1:s+p.x,y1:c+p.y,x2:l+p.x,y2:u+p.y,anchorPointX:f,anchorPointY:h}}xe.prototype.get=function(t){if(this.crossSourceCollisions)return{ID:0,predicate:null};if(!this.collisionGroups[t]){var e=++this.maxGroupID;this.collisionGroups[t]={ID:e,predicate:function(t){return t.collisionGroupID===e}}}return this.collisionGroups[t]};var we=function(t,e,r,n){this.transform=t.clone(),this.collisionIndex=new he(this.transform),this.placements={},this.opacities={},this.variableOffsets={},this.stale=!1,this.commitTime=0,this.fadeDuration=e,this.retainedQueryData={},this.collisionGroups=new xe(r),this.collisionCircleArrays={},this.prevPlacement=n,n&&(n.prevPlacement=void 0),this.placedOrientations={}};function Te(t,e,r,n,i){t.emplaceBack(e?1:0,r?1:0,n||0,i||0),t.emplaceBack(e?1:0,r?1:0,n||0,i||0),t.emplaceBack(e?1:0,r?1:0,n||0,i||0),t.emplaceBack(e?1:0,r?1:0,n||0,i||0)}we.prototype.getBucketParts=function(e,r,n,i){var a=n.getBucket(r),o=n.latestFeatureIndex;if(a&&o&&r.id===a.layerIds[0]){var s=n.collisionBoxArray,l=a.layers[0].layout,c=Math.pow(2,this.transform.zoom-n.tileID.overscaledZ),u=n.tileSize/t.EXTENT,f=this.transform.calculatePosMatrix(n.tileID.toUnwrapped()),h="map"===l.get("text-pitch-alignment"),p="map"===l.get("text-rotation-alignment"),d=pe(n,1,this.transform.zoom),m=Qt(f,h,p,this.transform,d),g=null;if(h){var v=$t(f,h,p,this.transform,d);g=t.multiply([],this.transform.labelPlaneMatrix,v)}this.retainedQueryData[a.bucketInstanceId]=new ye(a.bucketInstanceId,o,a.sourceLayerIndex,a.index,n.tileID);var y={bucket:a,layout:l,posMatrix:f,textLabelPlaneMatrix:m,labelToScreenMatrix:g,scale:c,textPixelRatio:u,holdingForFade:n.holdingForFade(),collisionBoxArray:s,partiallyEvaluatedTextSize:t.evaluateSizeForZoom(a.textSizeData,this.transform.zoom),collisionGroup:this.collisionGroups.get(a.sourceID)};if(i)for(var x=0,b=a.sortKeyRanges;x<b.length;x+=1){var _=b[x],w=_.sortKey,T=_.symbolInstanceStart,k=_.symbolInstanceEnd;e.push({sortKey:w,symbolInstanceStart:T,symbolInstanceEnd:k,parameters:y})}else e.push({symbolInstanceStart:0,symbolInstanceEnd:a.symbolInstances.length,parameters:y})}},we.prototype.attemptAnchorPlacement=function(t,e,r,n,i,a,o,s,l,c,u,f,h,p,d){var m,g=[f.textOffset0,f.textOffset1],v=be(t,r,n,g,i),y=this.collisionIndex.placeCollisionBox(_e(e,v.x,v.y,a,o,this.transform.angle),u,s,l,c.predicate);if(d&&0===this.collisionIndex.placeCollisionBox(_e(d,v.x,v.y,a,o,this.transform.angle),u,s,l,c.predicate).box.length)return;if(y.box.length>0)return this.prevPlacement&&this.prevPlacement.variableOffsets[f.crossTileID]&&this.prevPlacement.placements[f.crossTileID]&&this.prevPlacement.placements[f.crossTileID].text&&(m=this.prevPlacement.variableOffsets[f.crossTileID].anchor),this.variableOffsets[f.crossTileID]={textOffset:g,width:r,height:n,anchor:t,textBoxScale:i,prevAnchor:m},this.markUsedJustification(h,t,f,p),h.allowVerticalPlacement&&(this.markUsedOrientation(h,p,f),this.placedOrientations[f.crossTileID]=p),{shift:v,placedGlyphBoxes:y}},we.prototype.placeLayerBucketPart=function(e,r,n){var i=this,a=e.parameters,o=a.bucket,s=a.layout,l=a.posMatrix,c=a.textLabelPlaneMatrix,u=a.labelToScreenMatrix,f=a.textPixelRatio,h=a.holdingForFade,p=a.collisionBoxArray,d=a.partiallyEvaluatedTextSize,m=a.collisionGroup,g=s.get("text-optional"),v=s.get("icon-optional"),y=s.get("text-allow-overlap"),x=s.get("icon-allow-overlap"),b="map"===s.get("text-rotation-alignment"),_="map"===s.get("text-pitch-alignment"),w="none"!==s.get("icon-text-fit"),T="viewport-y"===s.get("symbol-z-order"),k=y&&(x||!o.hasIconData()||v),A=x&&(y||!o.hasTextData()||g);!o.collisionArrays&&p&&o.deserializeCollisionBoxes(p);var M=function(e,a){if(!r[e.crossTileID])if(h)i.placements[e.crossTileID]=new ge(!1,!1,!1);else{var p,T=!1,M=!1,S=!0,E=null,L={box:null,offscreen:null},C={box:null,offscreen:null},P=null,I=null,O=0,z=0,D=0;a.textFeatureIndex?O=a.textFeatureIndex:e.useRuntimeCollisionCircles&&(O=e.featureIndex),a.verticalTextFeatureIndex&&(z=a.verticalTextFeatureIndex);var R=a.textBox;if(R){var F=function(r){var n=t.WritingMode.horizontal;if(o.allowVerticalPlacement&&!r&&i.prevPlacement){var a=i.prevPlacement.placedOrientations[e.crossTileID];a&&(i.placedOrientations[e.crossTileID]=a,n=a,i.markUsedOrientation(o,n,e))}return n},B=function(r,n){if(o.allowVerticalPlacement&&e.numVerticalGlyphVertices>0&&a.verticalTextBox)for(var i=0,s=o.writingModes;i<s.length;i+=1){if(s[i]===t.WritingMode.vertical?(L=n(),C=L):L=r(),L&&L.box&&L.box.length)break}else L=r()};if(s.get("text-variable-anchor")){var N=s.get("text-variable-anchor");if(i.prevPlacement&&i.prevPlacement.variableOffsets[e.crossTileID]){var j=i.prevPlacement.variableOffsets[e.crossTileID];N.indexOf(j.anchor)>0&&(N=N.filter((function(t){return t!==j.anchor}))).unshift(j.anchor)}var U=function(t,r,n){for(var a=t.x2-t.x1,s=t.y2-t.y1,c=e.textBoxScale,u=w&&!x?r:null,h={box:[],offscreen:!1},p=y?2*N.length:N.length,d=0;d<p;++d){var g=N[d%N.length],v=d>=N.length,k=i.attemptAnchorPlacement(g,t,a,s,c,b,_,f,l,m,v,e,o,n,u);if(k&&(h=k.placedGlyphBoxes)&&h.box&&h.box.length){T=!0,E=k.shift;break}}return h};B((function(){return U(R,a.iconBox,t.WritingMode.horizontal)}),(function(){var r=a.verticalTextBox,n=L&&L.box&&L.box.length;return o.allowVerticalPlacement&&!n&&e.numVerticalGlyphVertices>0&&r?U(r,a.verticalIconBox,t.WritingMode.vertical):{box:null,offscreen:null}})),L&&(T=L.box,S=L.offscreen);var V=F(L&&L.box);if(!T&&i.prevPlacement){var H=i.prevPlacement.variableOffsets[e.crossTileID];H&&(i.variableOffsets[e.crossTileID]=H,i.markUsedJustification(o,H.anchor,e,V))}}else{var q=function(t,r){var n=i.collisionIndex.placeCollisionBox(t,y,f,l,m.predicate);return n&&n.box&&n.box.length&&(i.markUsedOrientation(o,r,e),i.placedOrientations[e.crossTileID]=r),n};B((function(){return q(R,t.WritingMode.horizontal)}),(function(){var r=a.verticalTextBox;return o.allowVerticalPlacement&&e.numVerticalGlyphVertices>0&&r?q(r,t.WritingMode.vertical):{box:null,offscreen:null}})),F(L&&L.box&&L.box.length)}}if(T=(p=L)&&p.box&&p.box.length>0,S=p&&p.offscreen,e.useRuntimeCollisionCircles){var G=o.text.placedSymbolArray.get(e.centerJustifiedTextSymbolIndex),Y=t.evaluateSizeForFeature(o.textSizeData,d,G),W=s.get("text-padding"),X=e.collisionCircleDiameter;P=i.collisionIndex.placeCollisionCircles(y,G,o.lineVertexArray,o.glyphOffsetArray,Y,l,c,u,n,_,m.predicate,X,W),T=y||P.circles.length>0&&!P.collisionDetected,S=S&&P.offscreen}if(a.iconFeatureIndex&&(D=a.iconFeatureIndex),a.iconBox){var Z=function(t){var e=w&&E?_e(t,E.x,E.y,b,_,i.transform.angle):t;return i.collisionIndex.placeCollisionBox(e,x,f,l,m.predicate)};M=C&&C.box&&C.box.length&&a.verticalIconBox?(I=Z(a.verticalIconBox)).box.length>0:(I=Z(a.iconBox)).box.length>0,S=S&&I.offscreen}var J=g||0===e.numHorizontalGlyphVertices&&0===e.numVerticalGlyphVertices,K=v||0===e.numIconVertices;if(J||K?K?J||(M=M&&T):T=M&&T:M=T=M&&T,T&&p&&p.box&&(C&&C.box&&z?i.collisionIndex.insertCollisionBox(p.box,s.get("text-ignore-placement"),o.bucketInstanceId,z,m.ID):i.collisionIndex.insertCollisionBox(p.box,s.get("text-ignore-placement"),o.bucketInstanceId,O,m.ID)),M&&I&&i.collisionIndex.insertCollisionBox(I.box,s.get("icon-ignore-placement"),o.bucketInstanceId,D,m.ID),P&&(T&&i.collisionIndex.insertCollisionCircles(P.circles,s.get("text-ignore-placement"),o.bucketInstanceId,O,m.ID),n)){var Q=o.bucketInstanceId,$=i.collisionCircleArrays[Q];void 0===$&&($=i.collisionCircleArrays[Q]=new ve);for(var tt=0;tt<P.circles.length;tt+=4)$.circles.push(P.circles[tt+0]),$.circles.push(P.circles[tt+1]),$.circles.push(P.circles[tt+2]),$.circles.push(P.collisionDetected?1:0)}i.placements[e.crossTileID]=new ge(T||k,M||A,S||o.justReloaded),r[e.crossTileID]=!0}};if(T)for(var S=o.getSortedSymbolIndexes(this.transform.angle),E=S.length-1;E>=0;--E){var L=S[E];M(o.symbolInstances.get(L),o.collisionArrays[L])}else for(var C=e.symbolInstanceStart;C<e.symbolInstanceEnd;C++)M(o.symbolInstances.get(C),o.collisionArrays[C]);if(n&&o.bucketInstanceId in this.collisionCircleArrays){var P=this.collisionCircleArrays[o.bucketInstanceId];t.invert(P.invProjMatrix,l),P.viewportMatrix=this.collisionIndex.getViewportMatrix()}o.justReloaded=!1},we.prototype.markUsedJustification=function(e,r,n,i){var a,o={left:n.leftJustifiedTextSymbolIndex,center:n.centerJustifiedTextSymbolIndex,right:n.rightJustifiedTextSymbolIndex};a=i===t.WritingMode.vertical?n.verticalPlacedTextSymbolIndex:o[t.getAnchorJustification(r)];for(var s=0,l=[n.leftJustifiedTextSymbolIndex,n.centerJustifiedTextSymbolIndex,n.rightJustifiedTextSymbolIndex,n.verticalPlacedTextSymbolIndex];s<l.length;s+=1){var c=l[s];c>=0&&(e.text.placedSymbolArray.get(c).crossTileID=a>=0&&c!==a?0:n.crossTileID)}},we.prototype.markUsedOrientation=function(e,r,n){for(var i=r===t.WritingMode.horizontal||r===t.WritingMode.horizontalOnly?r:0,a=r===t.WritingMode.vertical?r:0,o=0,s=[n.leftJustifiedTextSymbolIndex,n.centerJustifiedTextSymbolIndex,n.rightJustifiedTextSymbolIndex];o<s.length;o+=1){var l=s[o];e.text.placedSymbolArray.get(l).placedOrientation=i}n.verticalPlacedTextSymbolIndex&&(e.text.placedSymbolArray.get(n.verticalPlacedTextSymbolIndex).placedOrientation=a)},we.prototype.commit=function(t){this.commitTime=t,this.zoomAtLastRecencyCheck=this.transform.zoom;var e=this.prevPlacement,r=!1;this.prevZoomAdjustment=e?e.zoomAdjustment(this.transform.zoom):0;var n=e?e.symbolFadeChange(t):1,i=e?e.opacities:{},a=e?e.variableOffsets:{},o=e?e.placedOrientations:{};for(var s in this.placements){var l=this.placements[s],c=i[s];c?(this.opacities[s]=new me(c,n,l.text,l.icon),r=r||l.text!==c.text.placed||l.icon!==c.icon.placed):(this.opacities[s]=new me(null,n,l.text,l.icon,l.skipFade),r=r||l.text||l.icon)}for(var u in i){var f=i[u];if(!this.opacities[u]){var h=new me(f,n,!1,!1);h.isHidden()||(this.opacities[u]=h,r=r||f.text.placed||f.icon.placed)}}for(var p in a)this.variableOffsets[p]||!this.opacities[p]||this.opacities[p].isHidden()||(this.variableOffsets[p]=a[p]);for(var d in o)this.placedOrientations[d]||!this.opacities[d]||this.opacities[d].isHidden()||(this.placedOrientations[d]=o[d]);r?this.lastPlacementChangeTime=t:"number"!=typeof this.lastPlacementChangeTime&&(this.lastPlacementChangeTime=e?e.lastPlacementChangeTime:t)},we.prototype.updateLayerOpacities=function(t,e){for(var r={},n=0,i=e;n<i.length;n+=1){var a=i[n],o=a.getBucket(t);o&&a.latestFeatureIndex&&t.id===o.layerIds[0]&&this.updateBucketOpacities(o,r,a.collisionBoxArray)}},we.prototype.updateBucketOpacities=function(e,r,n){var i=this;e.hasTextData()&&e.text.opacityVertexArray.clear(),e.hasIconData()&&e.icon.opacityVertexArray.clear(),e.hasIconCollisionBoxData()&&e.iconCollisionBox.collisionVertexArray.clear(),e.hasTextCollisionBoxData()&&e.textCollisionBox.collisionVertexArray.clear();var a=e.layers[0].layout,o=new me(null,0,!1,!1,!0),s=a.get("text-allow-overlap"),l=a.get("icon-allow-overlap"),c=a.get("text-variable-anchor"),u="map"===a.get("text-rotation-alignment"),f="map"===a.get("text-pitch-alignment"),h="none"!==a.get("icon-text-fit"),p=new me(null,0,s&&(l||!e.hasIconData()||a.get("icon-optional")),l&&(s||!e.hasTextData()||a.get("text-optional")),!0);!e.collisionArrays&&n&&(e.hasIconCollisionBoxData()||e.hasTextCollisionBoxData())&&e.deserializeCollisionBoxes(n);for(var d=function(t,e,r){for(var n=0;n<e/4;n++)t.opacityVertexArray.emplaceBack(r)},m=function(n){var a=e.symbolInstances.get(n),s=a.numHorizontalGlyphVertices,l=a.numVerticalGlyphVertices,m=a.crossTileID,g=r[m],v=i.opacities[m];g?v=o:v||(v=p,i.opacities[m]=v),r[m]=!0;var y=s>0||l>0,x=a.numIconVertices>0,b=i.placedOrientations[a.crossTileID],_=b===t.WritingMode.vertical,w=b===t.WritingMode.horizontal||b===t.WritingMode.horizontalOnly;if(y){var T=Pe(v.text),k=_?Ie:T;d(e.text,s,k);var A=w?Ie:T;d(e.text,l,A);var M=v.text.isHidden();[a.rightJustifiedTextSymbolIndex,a.centerJustifiedTextSymbolIndex,a.leftJustifiedTextSymbolIndex].forEach((function(t){t>=0&&(e.text.placedSymbolArray.get(t).hidden=M||_?1:0)})),a.verticalPlacedTextSymbolIndex>=0&&(e.text.placedSymbolArray.get(a.verticalPlacedTextSymbolIndex).hidden=M||w?1:0);var S=i.variableOffsets[a.crossTileID];S&&i.markUsedJustification(e,S.anchor,a,b);var E=i.placedOrientations[a.crossTileID];E&&(i.markUsedJustification(e,"left",a,E),i.markUsedOrientation(e,E,a))}if(x){var L=Pe(v.icon),C=!(h&&a.verticalPlacedIconSymbolIndex&&_);if(a.placedIconSymbolIndex>=0){var P=C?L:Ie;d(e.icon,a.numIconVertices,P),e.icon.placedSymbolArray.get(a.placedIconSymbolIndex).hidden=v.icon.isHidden()}if(a.verticalPlacedIconSymbolIndex>=0){var I=C?Ie:L;d(e.icon,a.numVerticalIconVertices,I),e.icon.placedSymbolArray.get(a.verticalPlacedIconSymbolIndex).hidden=v.icon.isHidden()}}if(e.hasIconCollisionBoxData()||e.hasTextCollisionBoxData()){var O=e.collisionArrays[n];if(O){var z=new t.Point(0,0);if(O.textBox||O.verticalTextBox){var D=!0;if(c){var R=i.variableOffsets[m];R?(z=be(R.anchor,R.width,R.height,R.textOffset,R.textBoxScale),u&&z._rotate(f?i.transform.angle:-i.transform.angle)):D=!1}O.textBox&&Te(e.textCollisionBox.collisionVertexArray,v.text.placed,!D||_,z.x,z.y),O.verticalTextBox&&Te(e.textCollisionBox.collisionVertexArray,v.text.placed,!D||w,z.x,z.y)}var F=Boolean(!w&&O.verticalIconBox);O.iconBox&&Te(e.iconCollisionBox.collisionVertexArray,v.icon.placed,F,h?z.x:0,h?z.y:0),O.verticalIconBox&&Te(e.iconCollisionBox.collisionVertexArray,v.icon.placed,!F,h?z.x:0,h?z.y:0)}}},g=0;g<e.symbolInstances.length;g++)m(g);if(e.sortFeatures(this.transform.angle),this.retainedQueryData[e.bucketInstanceId]&&(this.retainedQueryData[e.bucketInstanceId].featureSortOrder=e.featureSortOrder),e.hasTextData()&&e.text.opacityVertexBuffer&&e.text.opacityVertexBuffer.updateData(e.text.opacityVertexArray),e.hasIconData()&&e.icon.opacityVertexBuffer&&e.icon.opacityVertexBuffer.updateData(e.icon.opacityVertexArray),e.hasIconCollisionBoxData()&&e.iconCollisionBox.collisionVertexBuffer&&e.iconCollisionBox.collisionVertexBuffer.updateData(e.iconCollisionBox.collisionVertexArray),e.hasTextCollisionBoxData()&&e.textCollisionBox.collisionVertexBuffer&&e.textCollisionBox.collisionVertexBuffer.updateData(e.textCollisionBox.collisionVertexArray),e.bucketInstanceId in this.collisionCircleArrays){var v=this.collisionCircleArrays[e.bucketInstanceId];e.placementInvProjMatrix=v.invProjMatrix,e.placementViewportMatrix=v.viewportMatrix,e.collisionCircleArray=v.circles,delete this.collisionCircleArrays[e.bucketInstanceId]}},we.prototype.symbolFadeChange=function(t){return 0===this.fadeDuration?1:(t-this.commitTime)/this.fadeDuration+this.prevZoomAdjustment},we.prototype.zoomAdjustment=function(t){return Math.max(0,(this.transform.zoom-t)/1.5)},we.prototype.hasTransitions=function(t){return this.stale||t-this.lastPlacementChangeTime<this.fadeDuration},we.prototype.stillRecent=function(t,e){var r=this.zoomAtLastRecencyCheck===e?1-this.zoomAdjustment(e):1;return this.zoomAtLastRecencyCheck=e,this.commitTime+this.fadeDuration*r>t},we.prototype.setStale=function(){this.stale=!0};var ke=Math.pow(2,25),Ae=Math.pow(2,24),Me=Math.pow(2,17),Se=Math.pow(2,16),Ee=Math.pow(2,9),Le=Math.pow(2,8),Ce=Math.pow(2,1);function Pe(t){if(0===t.opacity&&!t.placed)return 0;if(1===t.opacity&&t.placed)return 4294967295;var e=t.placed?1:0,r=Math.floor(127*t.opacity);return r*ke+e*Ae+r*Me+e*Se+r*Ee+e*Le+r*Ce+e}var Ie=0,Oe=function(t){this._sortAcrossTiles="viewport-y"!==t.layout.get("symbol-z-order")&&void 0!==t.layout.get("symbol-sort-key").constantOr(1),this._currentTileIndex=0,this._currentPartIndex=0,this._seenCrossTileIDs={},this._bucketParts=[]};Oe.prototype.continuePlacement=function(t,e,r,n,i){for(var a=this._bucketParts;this._currentTileIndex<t.length;){var o=t[this._currentTileIndex];if(e.getBucketParts(a,n,o,this._sortAcrossTiles),this._currentTileIndex++,i())return!0}for(this._sortAcrossTiles&&(this._sortAcrossTiles=!1,a.sort((function(t,e){return t.sortKey-e.sortKey})));this._currentPartIndex<a.length;){var s=a[this._currentPartIndex];if(e.placeLayerBucketPart(s,this._seenCrossTileIDs,r),this._currentPartIndex++,i())return!0}return!1};var ze=function(t,e,r,n,i,a,o){this.placement=new we(t,i,a,o),this._currentPlacementIndex=e.length-1,this._forceFullPlacement=r,this._showCollisionBoxes=n,this._done=!1};ze.prototype.isDone=function(){return this._done},ze.prototype.continuePlacement=function(e,r,n){for(var i=this,a=t.browser.now(),o=function(){var e=t.browser.now()-a;return!i._forceFullPlacement&&e>2};this._currentPlacementIndex>=0;){var s=r[e[this._currentPlacementIndex]],l=this.placement.collisionIndex.transform.zoom;if("symbol"===s.type&&(!s.minzoom||s.minzoom<=l)&&(!s.maxzoom||s.maxzoom>l)){if(this._inProgressLayer||(this._inProgressLayer=new Oe(s)),this._inProgressLayer.continuePlacement(n[s.source],this.placement,this._showCollisionBoxes,s,o))return;delete this._inProgressLayer}this._currentPlacementIndex--}this._done=!0},ze.prototype.commit=function(t){return this.placement.commit(t),this.placement};var De=512/t.EXTENT/2,Re=function(t,e,r){this.tileID=t,this.indexedSymbolInstances={},this.bucketInstanceId=r;for(var n=0;n<e.length;n++){var i=e.get(n),a=i.key;this.indexedSymbolInstances[a]||(this.indexedSymbolInstances[a]=[]),this.indexedSymbolInstances[a].push({crossTileID:i.crossTileID,coord:this.getScaledCoordinates(i,t)})}};Re.prototype.getScaledCoordinates=function(e,r){var n=r.canonical.z-this.tileID.canonical.z,i=De/Math.pow(2,n);return{x:Math.floor((r.canonical.x*t.EXTENT+e.anchorX)*i),y:Math.floor((r.canonical.y*t.EXTENT+e.anchorY)*i)}},Re.prototype.findMatches=function(t,e,r){for(var n=this.tileID.canonical.z<e.canonical.z?1:Math.pow(2,this.tileID.canonical.z-e.canonical.z),i=0;i<t.length;i++){var a=t.get(i);if(!a.crossTileID){var o=this.indexedSymbolInstances[a.key];if(o)for(var s=this.getScaledCoordinates(a,e),l=0,c=o;l<c.length;l+=1){var u=c[l];if(Math.abs(u.coord.x-s.x)<=n&&Math.abs(u.coord.y-s.y)<=n&&!r[u.crossTileID]){r[u.crossTileID]=!0,a.crossTileID=u.crossTileID;break}}}}};var Fe=function(){this.maxCrossTileID=0};Fe.prototype.generate=function(){return++this.maxCrossTileID};var Be=function(){this.indexes={},this.usedCrossTileIDs={},this.lng=0};Be.prototype.handleWrapJump=function(t){var e=Math.round((t-this.lng)/360);if(0!==e)for(var r in this.indexes){var n=this.indexes[r],i={};for(var a in n){var o=n[a];o.tileID=o.tileID.unwrapTo(o.tileID.wrap+e),i[o.tileID.key]=o}this.indexes[r]=i}this.lng=t},Be.prototype.addBucket=function(t,e,r){if(this.indexes[t.overscaledZ]&&this.indexes[t.overscaledZ][t.key]){if(this.indexes[t.overscaledZ][t.key].bucketInstanceId===e.bucketInstanceId)return!1;this.removeBucketCrossTileIDs(t.overscaledZ,this.indexes[t.overscaledZ][t.key])}for(var n=0;n<e.symbolInstances.length;n++){e.symbolInstances.get(n).crossTileID=0}this.usedCrossTileIDs[t.overscaledZ]||(this.usedCrossTileIDs[t.overscaledZ]={});var i=this.usedCrossTileIDs[t.overscaledZ];for(var a in this.indexes){var o=this.indexes[a];if(Number(a)>t.overscaledZ)for(var s in o){var l=o[s];l.tileID.isChildOf(t)&&l.findMatches(e.symbolInstances,t,i)}else{var c=o[t.scaledTo(Number(a)).key];c&&c.findMatches(e.symbolInstances,t,i)}}for(var u=0;u<e.symbolInstances.length;u++){var f=e.symbolInstances.get(u);f.crossTileID||(f.crossTileID=r.generate(),i[f.crossTileID]=!0)}return void 0===this.indexes[t.overscaledZ]&&(this.indexes[t.overscaledZ]={}),this.indexes[t.overscaledZ][t.key]=new Re(t,e.symbolInstances,e.bucketInstanceId),!0},Be.prototype.removeBucketCrossTileIDs=function(t,e){for(var r in e.indexedSymbolInstances)for(var n=0,i=e.indexedSymbolInstances[r];n<i.length;n+=1){var a=i[n];delete this.usedCrossTileIDs[t][a.crossTileID]}},Be.prototype.removeStaleBuckets=function(t){var e=!1;for(var r in this.indexes){var n=this.indexes[r];for(var i in n)t[n[i].bucketInstanceId]||(this.removeBucketCrossTileIDs(r,n[i]),delete n[i],e=!0)}return e};var Ne=function(){this.layerIndexes={},this.crossTileIDs=new Fe,this.maxBucketInstanceId=0,this.bucketsInCurrentPlacement={}};Ne.prototype.addLayer=function(t,e,r){var n=this.layerIndexes[t.id];void 0===n&&(n=this.layerIndexes[t.id]=new Be);var i=!1,a={};n.handleWrapJump(r);for(var o=0,s=e;o<s.length;o+=1){var l=s[o],c=l.getBucket(t);c&&t.id===c.layerIds[0]&&(c.bucketInstanceId||(c.bucketInstanceId=++this.maxBucketInstanceId),n.addBucket(l.tileID,c,this.crossTileIDs)&&(i=!0),a[c.bucketInstanceId]=!0)}return n.removeStaleBuckets(a)&&(i=!0),i},Ne.prototype.pruneUnusedLayers=function(t){var e={};for(var r in t.forEach((function(t){e[t]=!0})),this.layerIndexes)e[r]||delete this.layerIndexes[r]};var je=function(e,r){return t.emitValidationErrors(e,r&&r.filter((function(t){return"source.canvas"!==t.identifier})))},Ue=t.pick(Ut,["addLayer","removeLayer","setPaintProperty","setLayoutProperty","setFilter","addSource","removeSource","setLayerZoomRange","setLight","setTransition","setGeoJSONSourceData"]),Ve=t.pick(Ut,["setCenter","setZoom","setBearing","setPitch"]),He=function(){var e={},r=t.styleSpec.$version;for(var n in t.styleSpec.$root){var i=t.styleSpec.$root[n];if(i.required){var a=null;null!=(a="version"===n?r:"array"===i.type?[]:{})&&(e[n]=a)}}return e}(),qe=function(e){function r(n,i){var a=this;void 0===i&&(i={}),e.call(this),this.map=n,this.dispatcher=new k(Bt(),this),this.imageManager=new h,this.imageManager.setEventedParent(this),this.glyphManager=new x(n._requestManager,i.localIdeographFontFamily),this.lineAtlas=new T(256,512),this.crossTileSymbolIndex=new Ne,this._layers={},this._serializedLayers={},this._order=[],this.sourceCaches={},this.zoomHistory=new t.ZoomHistory,this._loaded=!1,this._availableImages=[],this._resetUpdates(),this.dispatcher.broadcast("setReferrer",t.getReferrer());var o=this;this._rtlTextPluginCallback=r.registerForPluginStateChange((function(e){var r={pluginStatus:e.pluginStatus,pluginURL:e.pluginURL};o.dispatcher.broadcast("syncRTLPluginState",r,(function(e,r){if((t.triggerPluginCompletionEvent(e),r)&&r.every((function(t){return t})))for(var n in o.sourceCaches)o.sourceCaches[n].reload()}))})),this.on("data",(function(t){if("source"===t.dataType&&"metadata"===t.sourceDataType){var e=a.sourceCaches[t.sourceId];if(e){var r=e.getSource();if(r&&r.vectorLayerIds)for(var n in a._layers){var i=a._layers[n];i.source===r.id&&a._validateLayer(i)}}}}))}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.loadURL=function(e,r){var n=this;void 0===r&&(r={}),this.fire(new t.Event("dataloading",{dataType:"style"}));var i="boolean"==typeof r.validate?r.validate:!t.isMapboxURL(e);e=this.map._requestManager.normalizeStyleURL(e,r.accessToken);var a=this.map._requestManager.transformRequest(e,t.ResourceType.Style);this._request=t.getJSON(a,(function(e,r){n._request=null,e?n.fire(new t.ErrorEvent(e)):r&&n._load(r,i)}))},r.prototype.loadJSON=function(e,r){var n=this;void 0===r&&(r={}),this.fire(new t.Event("dataloading",{dataType:"style"})),this._request=t.browser.frame((function(){n._request=null,n._load(e,!1!==r.validate)}))},r.prototype.loadEmpty=function(){this.fire(new t.Event("dataloading",{dataType:"style"})),this._load(He,!1)},r.prototype._load=function(e,r){if(!r||!je(this,t.validateStyle(e))){for(var n in this._loaded=!0,this.stylesheet=e,e.sources)this.addSource(n,e.sources[n],{validate:!1});e.sprite?this._loadSprite(e.sprite):this.imageManager.setLoaded(!0),this.glyphManager.setURL(e.glyphs);var i=jt(this.stylesheet.layers);this._order=i.map((function(t){return t.id})),this._layers={},this._serializedLayers={};for(var a=0,o=i;a<o.length;a+=1){var s=o[a];(s=t.createStyleLayer(s)).setEventedParent(this,{layer:{id:s.id}}),this._layers[s.id]=s,this._serializedLayers[s.id]=s.serialize()}this.dispatcher.broadcast("setLayers",this._serializeLayers(this._order)),this.light=new w(this.stylesheet.light),this.fire(new t.Event("data",{dataType:"style"})),this.fire(new t.Event("style.load"))}},r.prototype._loadSprite=function(e){var r=this;this._spriteRequest=function(e,r,n){var i,a,o,s=t.browser.devicePixelRatio>1?"@2x":"",l=t.getJSON(r.transformRequest(r.normalizeSpriteURL(e,s,".json"),t.ResourceType.SpriteJSON),(function(t,e){l=null,o||(o=t,i=e,u())})),c=t.getImage(r.transformRequest(r.normalizeSpriteURL(e,s,".png"),t.ResourceType.SpriteImage),(function(t,e){c=null,o||(o=t,a=e,u())}));function u(){if(o)n(o);else if(i&&a){var e=t.browser.getImageData(a),r={};for(var s in i){var l=i[s],c=l.width,u=l.height,f=l.x,h=l.y,p=l.sdf,d=l.pixelRatio,m=l.stretchX,g=l.stretchY,v=l.content,y=new t.RGBAImage({width:c,height:u});t.RGBAImage.copy(e,y,{x:f,y:h},{x:0,y:0},{width:c,height:u}),r[s]={data:y,pixelRatio:d,sdf:p,stretchX:m,stretchY:g,content:v}}n(null,r)}}return{cancel:function(){l&&(l.cancel(),l=null),c&&(c.cancel(),c=null)}}}(e,this.map._requestManager,(function(e,n){if(r._spriteRequest=null,e)r.fire(new t.ErrorEvent(e));else if(n)for(var i in n)r.imageManager.addImage(i,n[i]);r.imageManager.setLoaded(!0),r._availableImages=r.imageManager.listImages(),r.dispatcher.broadcast("setImages",r._availableImages),r.fire(new t.Event("data",{dataType:"style"}))}))},r.prototype._validateLayer=function(e){var r=this.sourceCaches[e.source];if(r){var n=e.sourceLayer;if(n){var i=r.getSource();("geojson"===i.type||i.vectorLayerIds&&-1===i.vectorLayerIds.indexOf(n))&&this.fire(new t.ErrorEvent(new Error('Source layer "'+n+'" does not exist on source "'+i.id+'" as specified by style layer "'+e.id+'"')))}}},r.prototype.loaded=function(){if(!this._loaded)return!1;if(Object.keys(this._updatedSources).length)return!1;for(var t in this.sourceCaches)if(!this.sourceCaches[t].loaded())return!1;return!!this.imageManager.isLoaded()},r.prototype._serializeLayers=function(t){for(var e=[],r=0,n=t;r<n.length;r+=1){var i=n[r],a=this._layers[i];"custom"!==a.type&&e.push(a.serialize())}return e},r.prototype.hasTransitions=function(){if(this.light&&this.light.hasTransition())return!0;for(var t in this.sourceCaches)if(this.sourceCaches[t].hasTransition())return!0;for(var e in this._layers)if(this._layers[e].hasTransition())return!0;return!1},r.prototype._checkLoaded=function(){if(!this._loaded)throw new Error("Style is not done loading")},r.prototype.update=function(e){if(this._loaded){var r=this._changed;if(this._changed){var n=Object.keys(this._updatedLayers),i=Object.keys(this._removedLayers);for(var a in(n.length||i.length)&&this._updateWorkerLayers(n,i),this._updatedSources){var o=this._updatedSources[a];"reload"===o?this._reloadSource(a):"clear"===o&&this._clearSource(a)}for(var s in this._updateTilesForChangedImages(),this._updatedPaintProps)this._layers[s].updateTransitions(e);this.light.updateTransitions(e),this._resetUpdates()}for(var l in this.sourceCaches)this.sourceCaches[l].used=!1;for(var c=0,u=this._order;c<u.length;c+=1){var f=u[c],h=this._layers[f];h.recalculate(e,this._availableImages),!h.isHidden(e.zoom)&&h.source&&(this.sourceCaches[h.source].used=!0)}this.light.recalculate(e),this.z=e.zoom,r&&this.fire(new t.Event("data",{dataType:"style"}))}},r.prototype._updateTilesForChangedImages=function(){var t=Object.keys(this._changedImages);if(t.length){for(var e in this.sourceCaches)this.sourceCaches[e].reloadTilesForDependencies(["icons","patterns"],t);this._changedImages={}}},r.prototype._updateWorkerLayers=function(t,e){this.dispatcher.broadcast("updateLayers",{layers:this._serializeLayers(t),removedIds:e})},r.prototype._resetUpdates=function(){this._changed=!1,this._updatedLayers={},this._removedLayers={},this._updatedSources={},this._updatedPaintProps={},this._changedImages={}},r.prototype.setState=function(e){var r=this;if(this._checkLoaded(),je(this,t.validateStyle(e)))return!1;(e=t.clone$1(e)).layers=jt(e.layers);var n=Zt(this.serialize(),e).filter((function(t){return!(t.command in Ve)}));if(0===n.length)return!1;var i=n.filter((function(t){return!(t.command in Ue)}));if(i.length>0)throw new Error("Unimplemented: "+i.map((function(t){return t.command})).join(", ")+".");return n.forEach((function(t){"setTransition"!==t.command&&r[t.command].apply(r,t.args)})),this.stylesheet=e,!0},r.prototype.addImage=function(e,r){if(this.getImage(e))return this.fire(new t.ErrorEvent(new Error("An image with this name already exists.")));this.imageManager.addImage(e,r),this._availableImages=this.imageManager.listImages(),this._changedImages[e]=!0,this._changed=!0,this.fire(new t.Event("data",{dataType:"style"}))},r.prototype.updateImage=function(t,e){this.imageManager.updateImage(t,e)},r.prototype.getImage=function(t){return this.imageManager.getImage(t)},r.prototype.removeImage=function(e){if(!this.getImage(e))return this.fire(new t.ErrorEvent(new Error("No image with this name exists.")));this.imageManager.removeImage(e),this._availableImages=this.imageManager.listImages(),this._changedImages[e]=!0,this._changed=!0,this.fire(new t.Event("data",{dataType:"style"}))},r.prototype.listImages=function(){return this._checkLoaded(),this.imageManager.listImages()},r.prototype.addSource=function(e,r,n){var i=this;if(void 0===n&&(n={}),this._checkLoaded(),void 0!==this.sourceCaches[e])throw new Error("There is already a source with this ID");if(!r.type)throw new Error("The type property must be defined, but the only the following properties were given: "+Object.keys(r).join(", ")+".");if(!(["vector","raster","geojson","video","image"].indexOf(r.type)>=0)||!this._validate(t.validateStyle.source,"sources."+e,r,null,n)){this.map&&this.map._collectResourceTiming&&(r.collectResourceTiming=!0);var a=this.sourceCaches[e]=new Ct(e,r,this.dispatcher);a.style=this,a.setEventedParent(this,(function(){return{isSourceLoaded:i.loaded(),source:a.serialize(),sourceId:e}})),a.onAdd(this.map),this._changed=!0}},r.prototype.removeSource=function(e){if(this._checkLoaded(),void 0===this.sourceCaches[e])throw new Error("There is no source with this ID");for(var r in this._layers)if(this._layers[r].source===e)return this.fire(new t.ErrorEvent(new Error('Source "'+e+'" cannot be removed while layer "'+r+'" is using it.')));var n=this.sourceCaches[e];delete this.sourceCaches[e],delete this._updatedSources[e],n.fire(new t.Event("data",{sourceDataType:"metadata",dataType:"source",sourceId:e})),n.setEventedParent(null),n.clearTiles(),n.onRemove&&n.onRemove(this.map),this._changed=!0},r.prototype.setGeoJSONSourceData=function(t,e){this._checkLoaded(),this.sourceCaches[t].getSource().setData(e),this._changed=!0},r.prototype.getSource=function(t){return this.sourceCaches[t]&&this.sourceCaches[t].getSource()},r.prototype.addLayer=function(e,r,n){void 0===n&&(n={}),this._checkLoaded();var i=e.id;if(this.getLayer(i))this.fire(new t.ErrorEvent(new Error('Layer with id "'+i+'" already exists on this map')));else{var a;if("custom"===e.type){if(je(this,t.validateCustomStyleLayer(e)))return;a=t.createStyleLayer(e)}else{if("object"==typeof e.source&&(this.addSource(i,e.source),e=t.clone$1(e),e=t.extend(e,{source:i})),this._validate(t.validateStyle.layer,"layers."+i,e,{arrayIndex:-1},n))return;a=t.createStyleLayer(e),this._validateLayer(a),a.setEventedParent(this,{layer:{id:i}}),this._serializedLayers[a.id]=a.serialize()}var o=r?this._order.indexOf(r):this._order.length;if(r&&-1===o)this.fire(new t.ErrorEvent(new Error('Layer with id "'+r+'" does not exist on this map.')));else{if(this._order.splice(o,0,i),this._layerOrderChanged=!0,this._layers[i]=a,this._removedLayers[i]&&a.source&&"custom"!==a.type){var s=this._removedLayers[i];delete this._removedLayers[i],s.type!==a.type?this._updatedSources[a.source]="clear":(this._updatedSources[a.source]="reload",this.sourceCaches[a.source].pause())}this._updateLayer(a),a.onAdd&&a.onAdd(this.map)}}},r.prototype.moveLayer=function(e,r){if(this._checkLoaded(),this._changed=!0,this._layers[e]){if(e!==r){var n=this._order.indexOf(e);this._order.splice(n,1);var i=r?this._order.indexOf(r):this._order.length;r&&-1===i?this.fire(new t.ErrorEvent(new Error('Layer with id "'+r+'" does not exist on this map.'))):(this._order.splice(i,0,e),this._layerOrderChanged=!0)}}else this.fire(new t.ErrorEvent(new Error("The layer '"+e+"' does not exist in the map's style and cannot be moved.")))},r.prototype.removeLayer=function(e){this._checkLoaded();var r=this._layers[e];if(r){r.setEventedParent(null);var n=this._order.indexOf(e);this._order.splice(n,1),this._layerOrderChanged=!0,this._changed=!0,this._removedLayers[e]=r,delete this._layers[e],delete this._serializedLayers[e],delete this._updatedLayers[e],delete this._updatedPaintProps[e],r.onRemove&&r.onRemove(this.map)}else this.fire(new t.ErrorEvent(new Error("The layer '"+e+"' does not exist in the map's style and cannot be removed.")))},r.prototype.getLayer=function(t){return this._layers[t]},r.prototype.hasLayer=function(t){return t in this._layers},r.prototype.setLayerZoomRange=function(e,r,n){this._checkLoaded();var i=this.getLayer(e);i?i.minzoom===r&&i.maxzoom===n||(null!=r&&(i.minzoom=r),null!=n&&(i.maxzoom=n),this._updateLayer(i)):this.fire(new t.ErrorEvent(new Error("The layer '"+e+"' does not exist in the map's style and cannot have zoom extent.")))},r.prototype.setFilter=function(e,r,n){void 0===n&&(n={}),this._checkLoaded();var i=this.getLayer(e);if(i){if(!t.deepEqual(i.filter,r))return null==r?(i.filter=void 0,void this._updateLayer(i)):void(this._validate(t.validateStyle.filter,"layers."+i.id+".filter",r,null,n)||(i.filter=t.clone$1(r),this._updateLayer(i)))}else this.fire(new t.ErrorEvent(new Error("The layer '"+e+"' does not exist in the map's style and cannot be filtered.")))},r.prototype.getFilter=function(e){return t.clone$1(this.getLayer(e).filter)},r.prototype.setLayoutProperty=function(e,r,n,i){void 0===i&&(i={}),this._checkLoaded();var a=this.getLayer(e);a?t.deepEqual(a.getLayoutProperty(r),n)||(a.setLayoutProperty(r,n,i),this._updateLayer(a)):this.fire(new t.ErrorEvent(new Error("The layer '"+e+"' does not exist in the map's style and cannot be styled.")))},r.prototype.getLayoutProperty=function(e,r){var n=this.getLayer(e);if(n)return n.getLayoutProperty(r);this.fire(new t.ErrorEvent(new Error("The layer '"+e+"' does not exist in the map's style.")))},r.prototype.setPaintProperty=function(e,r,n,i){void 0===i&&(i={}),this._checkLoaded();var a=this.getLayer(e);a?t.deepEqual(a.getPaintProperty(r),n)||(a.setPaintProperty(r,n,i)&&this._updateLayer(a),this._changed=!0,this._updatedPaintProps[e]=!0):this.fire(new t.ErrorEvent(new Error("The layer '"+e+"' does not exist in the map's style and cannot be styled.")))},r.prototype.getPaintProperty=function(t,e){return this.getLayer(t).getPaintProperty(e)},r.prototype.setFeatureState=function(e,r){this._checkLoaded();var n=e.source,i=e.sourceLayer,a=this.sourceCaches[n];if(void 0!==a){var o=a.getSource().type;"geojson"===o&&i?this.fire(new t.ErrorEvent(new Error("GeoJSON sources cannot have a sourceLayer parameter."))):"vector"!==o||i?(void 0===e.id&&this.fire(new t.ErrorEvent(new Error("The feature id parameter must be provided."))),a.setFeatureState(i,e.id,r)):this.fire(new t.ErrorEvent(new Error("The sourceLayer parameter must be provided for vector source types.")))}else this.fire(new t.ErrorEvent(new Error("The source '"+n+"' does not exist in the map's style.")))},r.prototype.removeFeatureState=function(e,r){this._checkLoaded();var n=e.source,i=this.sourceCaches[n];if(void 0!==i){var a=i.getSource().type,o="vector"===a?e.sourceLayer:void 0;"vector"!==a||o?r&&"string"!=typeof e.id&&"number"!=typeof e.id?this.fire(new t.ErrorEvent(new Error("A feature id is requred to remove its specific state property."))):i.removeFeatureState(o,e.id,r):this.fire(new t.ErrorEvent(new Error("The sourceLayer parameter must be provided for vector source types.")))}else this.fire(new t.ErrorEvent(new Error("The source '"+n+"' does not exist in the map's style.")))},r.prototype.getFeatureState=function(e){this._checkLoaded();var r=e.source,n=e.sourceLayer,i=this.sourceCaches[r];if(void 0!==i){if("vector"!==i.getSource().type||n)return void 0===e.id&&this.fire(new t.ErrorEvent(new Error("The feature id parameter must be provided."))),i.getFeatureState(n,e.id);this.fire(new t.ErrorEvent(new Error("The sourceLayer parameter must be provided for vector source types.")))}else this.fire(new t.ErrorEvent(new Error("The source '"+r+"' does not exist in the map's style.")))},r.prototype.getTransition=function(){return t.extend({duration:300,delay:0},this.stylesheet&&this.stylesheet.transition)},r.prototype.serialize=function(){return t.filterObject({version:this.stylesheet.version,name:this.stylesheet.name,metadata:this.stylesheet.metadata,light:this.stylesheet.light,center:this.stylesheet.center,zoom:this.stylesheet.zoom,bearing:this.stylesheet.bearing,pitch:this.stylesheet.pitch,sprite:this.stylesheet.sprite,glyphs:this.stylesheet.glyphs,transition:this.stylesheet.transition,sources:t.mapObject(this.sourceCaches,(function(t){return t.serialize()})),layers:this._serializeLayers(this._order)},(function(t){return void 0!==t}))},r.prototype._updateLayer=function(t){this._updatedLayers[t.id]=!0,t.source&&!this._updatedSources[t.source]&&"raster"!==this.sourceCaches[t.source].getSource().type&&(this._updatedSources[t.source]="reload",this.sourceCaches[t.source].pause()),this._changed=!0},r.prototype._flattenAndSortRenderedFeatures=function(t){for(var e=this,r=function(t){return"fill-extrusion"===e._layers[t].type},n={},i=[],a=this._order.length-1;a>=0;a--){var o=this._order[a];if(r(o)){n[o]=a;for(var s=0,l=t;s<l.length;s+=1){var c=l[s][o];if(c)for(var u=0,f=c;u<f.length;u+=1){var h=f[u];i.push(h)}}}}i.sort((function(t,e){return e.intersectionZ-t.intersectionZ}));for(var p=[],d=this._order.length-1;d>=0;d--){var m=this._order[d];if(r(m))for(var g=i.length-1;g>=0;g--){var v=i[g].feature;if(n[v.layer.id]<d)break;p.push(v),i.pop()}else for(var y=0,x=t;y<x.length;y+=1){var b=x[y][m];if(b)for(var _=0,w=b;_<w.length;_+=1){var T=w[_];p.push(T.feature)}}}return p},r.prototype.queryRenderedFeatures=function(e,r,n){r&&r.filter&&this._validate(t.validateStyle.filter,"queryRenderedFeatures.filter",r.filter,null,r);var i={};if(r&&r.layers){if(!Array.isArray(r.layers))return this.fire(new t.ErrorEvent(new Error("parameters.layers must be an Array."))),[];for(var a=0,o=r.layers;a<o.length;a+=1){var s=o[a],l=this._layers[s];if(!l)return this.fire(new t.ErrorEvent(new Error("The layer '"+s+"' does not exist in the map's style and cannot be queried for features."))),[];i[l.source]=!0}}var c=[];for(var u in r.availableImages=this._availableImages,this.sourceCaches)r.layers&&!i[u]||c.push(F(this.sourceCaches[u],this._layers,this._serializedLayers,e,r,n));return this.placement&&c.push(function(t,e,r,n,i,a,o){for(var s={},l=a.queryRenderedSymbols(n),c=[],u=0,f=Object.keys(l).map(Number);u<f.length;u+=1){var h=f[u];c.push(o[h])}c.sort(B);for(var p=function(){var r=m[d],n=r.featureIndex.lookupSymbolFeatures(l[r.bucketInstanceId],e,r.bucketIndex,r.sourceLayerIndex,i.filter,i.layers,i.availableImages,t);for(var a in n){var o=s[a]=s[a]||[],c=n[a];c.sort((function(t,e){var n=r.featureSortOrder;if(n){var i=n.indexOf(t.featureIndex);return n.indexOf(e.featureIndex)-i}return e.featureIndex-t.featureIndex}));for(var u=0,f=c;u<f.length;u+=1){var h=f[u];o.push(h)}}},d=0,m=c;d<m.length;d+=1)p();var g=function(e){s[e].forEach((function(n){var i=n.feature,a=t[e],o=r[a.source].getFeatureState(i.layer["source-layer"],i.id);i.source=i.layer.source,i.layer["source-layer"]&&(i.sourceLayer=i.layer["source-layer"]),i.state=o}))};for(var v in s)g(v);return s}(this._layers,this._serializedLayers,this.sourceCaches,e,r,this.placement.collisionIndex,this.placement.retainedQueryData)),this._flattenAndSortRenderedFeatures(c)},r.prototype.querySourceFeatures=function(e,r){r&&r.filter&&this._validate(t.validateStyle.filter,"querySourceFeatures.filter",r.filter,null,r);var n=this.sourceCaches[e];return n?function(t,e){for(var r=t.getRenderableIds().map((function(e){return t.getTileByID(e)})),n=[],i={},a=0;a<r.length;a++){var o=r[a],s=o.tileID.canonical.key;i[s]||(i[s]=!0,o.querySourceFeatures(n,e))}return n}(n,r):[]},r.prototype.addSourceType=function(t,e,n){return r.getSourceType(t)?n(new Error('A source type called "'+t+'" already exists.')):(r.setSourceType(t,e),e.workerSourceURL?void this.dispatcher.broadcast("loadWorkerSource",{name:t,url:e.workerSourceURL},n):n(null,null))},r.prototype.getLight=function(){return this.light.getLight()},r.prototype.setLight=function(e,r){void 0===r&&(r={}),this._checkLoaded();var n=this.light.getLight(),i=!1;for(var a in e)if(!t.deepEqual(e[a],n[a])){i=!0;break}if(i){var o={now:t.browser.now(),transition:t.extend({duration:300,delay:0},this.stylesheet.transition)};this.light.setLight(e,r),this.light.updateTransitions(o)}},r.prototype._validate=function(e,r,n,i,a){return void 0===a&&(a={}),(!a||!1!==a.validate)&&je(this,e.call(t.validateStyle,t.extend({key:r,style:this.serialize(),value:n,styleSpec:t.styleSpec},i)))},r.prototype._remove=function(){for(var e in this._request&&(this._request.cancel(),this._request=null),this._spriteRequest&&(this._spriteRequest.cancel(),this._spriteRequest=null),t.evented.off("pluginStateChange",this._rtlTextPluginCallback),this._layers){this._layers[e].setEventedParent(null)}for(var r in this.sourceCaches)this.sourceCaches[r].clearTiles(),this.sourceCaches[r].setEventedParent(null);this.imageManager.setEventedParent(null),this.setEventedParent(null),this.dispatcher.remove()},r.prototype._clearSource=function(t){this.sourceCaches[t].clearTiles()},r.prototype._reloadSource=function(t){this.sourceCaches[t].resume(),this.sourceCaches[t].reload()},r.prototype._updateSources=function(t){for(var e in this.sourceCaches)this.sourceCaches[e].update(t)},r.prototype._generateCollisionBoxes=function(){for(var t in this.sourceCaches)this._reloadSource(t)},r.prototype._updatePlacement=function(e,r,n,i,a){void 0===a&&(a=!1);for(var o=!1,s=!1,l={},c=0,u=this._order;c<u.length;c+=1){var f=u[c],h=this._layers[f];if("symbol"===h.type){if(!l[h.source]){var p=this.sourceCaches[h.source];l[h.source]=p.getRenderableIds(!0).map((function(t){return p.getTileByID(t)})).sort((function(t,e){return e.tileID.overscaledZ-t.tileID.overscaledZ||(t.tileID.isLessThan(e.tileID)?-1:1)}))}var d=this.crossTileSymbolIndex.addLayer(h,l[h.source],e.center.lng);o=o||d}}if(this.crossTileSymbolIndex.pruneUnusedLayers(this._order),((a=a||this._layerOrderChanged||0===n)||!this.pauseablePlacement||this.pauseablePlacement.isDone()&&!this.placement.stillRecent(t.browser.now(),e.zoom))&&(this.pauseablePlacement=new ze(e,this._order,a,r,n,i,this.placement),this._layerOrderChanged=!1),this.pauseablePlacement.isDone()?this.placement.setStale():(this.pauseablePlacement.continuePlacement(this._order,this._layers,l),this.pauseablePlacement.isDone()&&(this.placement=this.pauseablePlacement.commit(t.browser.now()),s=!0),o&&this.pauseablePlacement.placement.setStale()),s||o)for(var m=0,g=this._order;m<g.length;m+=1){var v=g[m],y=this._layers[v];"symbol"===y.type&&this.placement.updateLayerOpacities(y,l[y.source])}return!this.pauseablePlacement.isDone()||this.placement.hasTransitions(t.browser.now())},r.prototype._releaseSymbolFadeTiles=function(){for(var t in this.sourceCaches)this.sourceCaches[t].releaseSymbolFadeTiles()},r.prototype.getImages=function(t,e,r){this.imageManager.getImages(e.icons,r),this._updateTilesForChangedImages();var n=this.sourceCaches[e.source];n&&n.setDependencies(e.tileID.key,e.type,e.icons)},r.prototype.getGlyphs=function(t,e,r){this.glyphManager.getGlyphs(e.stacks,r)},r.prototype.getResource=function(e,r,n){return t.makeRequest(r,n)},r}(t.Evented);qe.getSourceType=function(t){return D[t]},qe.setSourceType=function(t,e){D[t]=e},qe.registerForPluginStateChange=t.registerForPluginStateChange;var Ge=t.createLayout([{name:"a_pos",type:"Int16",components:2}]),Ye=yr("#ifdef GL_ES\nprecision mediump float;\n#else\n#if !defined(lowp)\n#define lowp\n#endif\n#if !defined(mediump)\n#define mediump\n#endif\n#if !defined(highp)\n#define highp\n#endif\n#endif","#ifdef GL_ES\nprecision highp float;\n#else\n#if !defined(lowp)\n#define lowp\n#endif\n#if !defined(mediump)\n#define mediump\n#endif\n#if !defined(highp)\n#define highp\n#endif\n#endif\nvec2 unpack_float(const float packedValue) {int packedIntValue=int(packedValue);int v0=packedIntValue/256;return vec2(v0,packedIntValue-v0*256);}vec2 unpack_opacity(const float packedOpacity) {int intOpacity=int(packedOpacity)/2;return vec2(float(intOpacity)/127.0,mod(packedOpacity,2.0));}vec4 decode_color(const vec2 encodedColor) {return vec4(unpack_float(encodedColor[0])/255.0,unpack_float(encodedColor[1])/255.0\n);}float unpack_mix_vec2(const vec2 packedValue,const float t) {return mix(packedValue[0],packedValue[1],t);}vec4 unpack_mix_color(const vec4 packedColors,const float t) {vec4 minColor=decode_color(vec2(packedColors[0],packedColors[1]));vec4 maxColor=decode_color(vec2(packedColors[2],packedColors[3]));return mix(minColor,maxColor,t);}vec2 get_pattern_pos(const vec2 pixel_coord_upper,const vec2 pixel_coord_lower,const vec2 pattern_size,const float tile_units_to_pixels,const vec2 pos) {vec2 offset=mod(mod(mod(pixel_coord_upper,pattern_size)*256.0,pattern_size)*256.0+pixel_coord_lower,pattern_size);return (tile_units_to_pixels*pos+offset)/pattern_size;}"),We=yr("uniform vec4 u_color;uniform float u_opacity;void main() {gl_FragColor=u_color*u_opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","attribute vec2 a_pos;uniform mat4 u_matrix;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);}"),Xe=yr("uniform vec2 u_pattern_tl_a;uniform vec2 u_pattern_br_a;uniform vec2 u_pattern_tl_b;uniform vec2 u_pattern_br_b;uniform vec2 u_texsize;uniform float u_mix;uniform float u_opacity;uniform sampler2D u_image;varying vec2 v_pos_a;varying vec2 v_pos_b;void main() {vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(u_pattern_tl_a/u_texsize,u_pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(u_pattern_tl_b/u_texsize,u_pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);gl_FragColor=mix(color1,color2,u_mix)*u_opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","uniform mat4 u_matrix;uniform vec2 u_pattern_size_a;uniform vec2 u_pattern_size_b;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform float u_scale_a;uniform float u_scale_b;uniform float u_tile_units_to_pixels;attribute vec2 a_pos;varying vec2 v_pos_a;varying vec2 v_pos_b;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,u_scale_a*u_pattern_size_a,u_tile_units_to_pixels,a_pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,u_scale_b*u_pattern_size_b,u_tile_units_to_pixels,a_pos);}"),Ze=yr("varying vec3 v_data;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define mediump float radius\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define highp vec4 stroke_color\n#pragma mapbox: define mediump float stroke_width\n#pragma mapbox: define lowp float stroke_opacity\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize mediump float radius\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize highp vec4 stroke_color\n#pragma mapbox: initialize mediump float stroke_width\n#pragma mapbox: initialize lowp float stroke_opacity\nvec2 extrude=v_data.xy;float extrude_length=length(extrude);lowp float antialiasblur=v_data.z;float antialiased_blur=-max(blur,antialiasblur);float opacity_t=smoothstep(0.0,antialiased_blur,extrude_length-1.0);float color_t=stroke_width < 0.01 ? 0.0 : smoothstep(antialiased_blur,0.0,extrude_length-radius/(radius+stroke_width));gl_FragColor=opacity_t*mix(color*opacity,stroke_color*stroke_opacity,color_t);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","uniform mat4 u_matrix;uniform bool u_scale_with_map;uniform bool u_pitch_with_map;uniform vec2 u_extrude_scale;uniform lowp float u_device_pixel_ratio;uniform highp float u_camera_to_center_distance;attribute vec2 a_pos;varying vec3 v_data;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define mediump float radius\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define highp vec4 stroke_color\n#pragma mapbox: define mediump float stroke_width\n#pragma mapbox: define lowp float stroke_opacity\nvoid main(void) {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize mediump float radius\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize highp vec4 stroke_color\n#pragma mapbox: initialize mediump float stroke_width\n#pragma mapbox: initialize lowp float stroke_opacity\nvec2 extrude=vec2(mod(a_pos,2.0)*2.0-1.0);vec2 circle_center=floor(a_pos*0.5);if (u_pitch_with_map) {vec2 corner_position=circle_center;if (u_scale_with_map) {corner_position+=extrude*(radius+stroke_width)*u_extrude_scale;} else {vec4 projected_center=u_matrix*vec4(circle_center,0,1);corner_position+=extrude*(radius+stroke_width)*u_extrude_scale*(projected_center.w/u_camera_to_center_distance);}gl_Position=u_matrix*vec4(corner_position,0,1);} else {gl_Position=u_matrix*vec4(circle_center,0,1);if (u_scale_with_map) {gl_Position.xy+=extrude*(radius+stroke_width)*u_extrude_scale*u_camera_to_center_distance;} else {gl_Position.xy+=extrude*(radius+stroke_width)*u_extrude_scale*gl_Position.w;}}lowp float antialiasblur=1.0/u_device_pixel_ratio/(radius+stroke_width);v_data=vec3(extrude.x,extrude.y,antialiasblur);}"),Je=yr("void main() {gl_FragColor=vec4(1.0);}","attribute vec2 a_pos;uniform mat4 u_matrix;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);}"),Ke=yr("uniform highp float u_intensity;varying vec2 v_extrude;\n#pragma mapbox: define highp float weight\n#define GAUSS_COEF 0.3989422804014327\nvoid main() {\n#pragma mapbox: initialize highp float weight\nfloat d=-0.5*3.0*3.0*dot(v_extrude,v_extrude);float val=weight*u_intensity*GAUSS_COEF*exp(d);gl_FragColor=vec4(val,1.0,1.0,1.0);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","uniform mat4 u_matrix;uniform float u_extrude_scale;uniform float u_opacity;uniform float u_intensity;attribute vec2 a_pos;varying vec2 v_extrude;\n#pragma mapbox: define highp float weight\n#pragma mapbox: define mediump float radius\nconst highp float ZERO=1.0/255.0/16.0;\n#define GAUSS_COEF 0.3989422804014327\nvoid main(void) {\n#pragma mapbox: initialize highp float weight\n#pragma mapbox: initialize mediump float radius\nvec2 unscaled_extrude=vec2(mod(a_pos,2.0)*2.0-1.0);float S=sqrt(-2.0*log(ZERO/weight/u_intensity/GAUSS_COEF))/3.0;v_extrude=S*unscaled_extrude;vec2 extrude=v_extrude*radius*u_extrude_scale;vec4 pos=vec4(floor(a_pos*0.5)+extrude,0,1);gl_Position=u_matrix*pos;}"),Qe=yr("uniform sampler2D u_image;uniform sampler2D u_color_ramp;uniform float u_opacity;varying vec2 v_pos;void main() {float t=texture2D(u_image,v_pos).r;vec4 color=texture2D(u_color_ramp,vec2(t,0.5));gl_FragColor=color*u_opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(0.0);\n#endif\n}","uniform mat4 u_matrix;uniform vec2 u_world;attribute vec2 a_pos;varying vec2 v_pos;void main() {gl_Position=u_matrix*vec4(a_pos*u_world,0,1);v_pos.x=a_pos.x;v_pos.y=1.0-a_pos.y;}"),$e=yr("varying float v_placed;varying float v_notUsed;void main() {float alpha=0.5;gl_FragColor=vec4(1.0,0.0,0.0,1.0)*alpha;if (v_placed > 0.5) {gl_FragColor=vec4(0.0,0.0,1.0,0.5)*alpha;}if (v_notUsed > 0.5) {gl_FragColor*=.1;}}","attribute vec2 a_pos;attribute vec2 a_anchor_pos;attribute vec2 a_extrude;attribute vec2 a_placed;attribute vec2 a_shift;uniform mat4 u_matrix;uniform vec2 u_extrude_scale;uniform float u_camera_to_center_distance;varying float v_placed;varying float v_notUsed;void main() {vec4 projectedPoint=u_matrix*vec4(a_anchor_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float collision_perspective_ratio=clamp(0.5+0.5*(u_camera_to_center_distance/camera_to_anchor_distance),0.0,4.0);gl_Position=u_matrix*vec4(a_pos,0.0,1.0);gl_Position.xy+=(a_extrude+a_shift)*u_extrude_scale*gl_Position.w*collision_perspective_ratio;v_placed=a_placed.x;v_notUsed=a_placed.y;}"),tr=yr("varying float v_radius;varying vec2 v_extrude;varying float v_perspective_ratio;varying float v_collision;void main() {float alpha=0.5*min(v_perspective_ratio,1.0);float stroke_radius=0.9*max(v_perspective_ratio,1.0);float distance_to_center=length(v_extrude);float distance_to_edge=abs(distance_to_center-v_radius);float opacity_t=smoothstep(-stroke_radius,0.0,-distance_to_edge);vec4 color=mix(vec4(0.0,0.0,1.0,0.5),vec4(1.0,0.0,0.0,1.0),v_collision);gl_FragColor=color*alpha*opacity_t;}","attribute vec2 a_pos;attribute float a_radius;attribute vec2 a_flags;uniform mat4 u_matrix;uniform mat4 u_inv_matrix;uniform vec2 u_viewport_size;uniform float u_camera_to_center_distance;varying float v_radius;varying vec2 v_extrude;varying float v_perspective_ratio;varying float v_collision;vec3 toTilePosition(vec2 screenPos) {vec4 rayStart=u_inv_matrix*vec4(screenPos,-1.0,1.0);vec4 rayEnd  =u_inv_matrix*vec4(screenPos, 1.0,1.0);rayStart.xyz/=rayStart.w;rayEnd.xyz  /=rayEnd.w;highp float t=(0.0-rayStart.z)/(rayEnd.z-rayStart.z);return mix(rayStart.xyz,rayEnd.xyz,t);}void main() {vec2 quadCenterPos=a_pos;float radius=a_radius;float collision=a_flags.x;float vertexIdx=a_flags.y;vec2 quadVertexOffset=vec2(mix(-1.0,1.0,float(vertexIdx >=2.0)),mix(-1.0,1.0,float(vertexIdx >=1.0 && vertexIdx <=2.0)));vec2 quadVertexExtent=quadVertexOffset*radius;vec3 tilePos=toTilePosition(quadCenterPos);vec4 clipPos=u_matrix*vec4(tilePos,1.0);highp float camera_to_anchor_distance=clipPos.w;highp float collision_perspective_ratio=clamp(0.5+0.5*(u_camera_to_center_distance/camera_to_anchor_distance),0.0,4.0);float padding_factor=1.2;v_radius=radius;v_extrude=quadVertexExtent*padding_factor;v_perspective_ratio=collision_perspective_ratio;v_collision=collision;gl_Position=vec4(clipPos.xyz/clipPos.w,1.0)+vec4(quadVertexExtent*padding_factor/u_viewport_size*2.0,0.0,0.0);}"),er=yr("uniform highp vec4 u_color;uniform sampler2D u_overlay;varying vec2 v_uv;void main() {vec4 overlay_color=texture2D(u_overlay,v_uv);gl_FragColor=mix(u_color,overlay_color,overlay_color.a);}","attribute vec2 a_pos;varying vec2 v_uv;uniform mat4 u_matrix;uniform float u_overlay_scale;void main() {v_uv=a_pos/8192.0;gl_Position=u_matrix*vec4(a_pos*u_overlay_scale,0,1);}"),rr=yr("#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float opacity\ngl_FragColor=color*opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","attribute vec2 a_pos;uniform mat4 u_matrix;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float opacity\ngl_Position=u_matrix*vec4(a_pos,0,1);}"),nr=yr("varying vec2 v_pos;\n#pragma mapbox: define highp vec4 outline_color\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize highp vec4 outline_color\n#pragma mapbox: initialize lowp float opacity\nfloat dist=length(v_pos-gl_FragCoord.xy);float alpha=1.0-smoothstep(0.0,1.0,dist);gl_FragColor=outline_color*(alpha*opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","attribute vec2 a_pos;uniform mat4 u_matrix;uniform vec2 u_world;varying vec2 v_pos;\n#pragma mapbox: define highp vec4 outline_color\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize highp vec4 outline_color\n#pragma mapbox: initialize lowp float opacity\ngl_Position=u_matrix*vec4(a_pos,0,1);v_pos=(gl_Position.xy/gl_Position.w+1.0)/2.0*u_world;}"),ir=yr("uniform vec2 u_texsize;uniform sampler2D u_image;uniform float u_fade;varying vec2 v_pos_a;varying vec2 v_pos_b;varying vec2 v_pos;\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);float dist=length(v_pos-gl_FragCoord.xy);float alpha=1.0-smoothstep(0.0,1.0,dist);gl_FragColor=mix(color1,color2,u_fade)*alpha*opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","uniform mat4 u_matrix;uniform vec2 u_world;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform vec3 u_scale;attribute vec2 a_pos;varying vec2 v_pos_a;varying vec2 v_pos_b;varying vec2 v_pos;\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;gl_Position=u_matrix*vec4(a_pos,0,1);vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,fromScale*display_size_a,tileRatio,a_pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,toScale*display_size_b,tileRatio,a_pos);v_pos=(gl_Position.xy/gl_Position.w+1.0)/2.0*u_world;}"),ar=yr("uniform vec2 u_texsize;uniform float u_fade;uniform sampler2D u_image;varying vec2 v_pos_a;varying vec2 v_pos_b;\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);gl_FragColor=mix(color1,color2,u_fade)*opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","uniform mat4 u_matrix;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform vec3 u_scale;attribute vec2 a_pos;varying vec2 v_pos_a;varying vec2 v_pos_b;\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileZoomRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;gl_Position=u_matrix*vec4(a_pos,0,1);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,fromScale*display_size_a,tileZoomRatio,a_pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,toScale*display_size_b,tileZoomRatio,a_pos);}"),or=yr("varying vec4 v_color;void main() {gl_FragColor=v_color;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","uniform mat4 u_matrix;uniform vec3 u_lightcolor;uniform lowp vec3 u_lightpos;uniform lowp float u_lightintensity;uniform float u_vertical_gradient;uniform lowp float u_opacity;attribute vec2 a_pos;attribute vec4 a_normal_ed;varying vec4 v_color;\n#pragma mapbox: define highp float base\n#pragma mapbox: define highp float height\n#pragma mapbox: define highp vec4 color\nvoid main() {\n#pragma mapbox: initialize highp float base\n#pragma mapbox: initialize highp float height\n#pragma mapbox: initialize highp vec4 color\nvec3 normal=a_normal_ed.xyz;base=max(0.0,base);height=max(0.0,height);float t=mod(normal.x,2.0);gl_Position=u_matrix*vec4(a_pos,t > 0.0 ? height : base,1);float colorvalue=color.r*0.2126+color.g*0.7152+color.b*0.0722;v_color=vec4(0.0,0.0,0.0,1.0);vec4 ambientlight=vec4(0.03,0.03,0.03,1.0);color+=ambientlight;float directional=clamp(dot(normal/16384.0,u_lightpos),0.0,1.0);directional=mix((1.0-u_lightintensity),max((1.0-colorvalue+u_lightintensity),1.0),directional);if (normal.y !=0.0) {directional*=((1.0-u_vertical_gradient)+(u_vertical_gradient*clamp((t+base)*pow(height/150.0,0.5),mix(0.7,0.98,1.0-u_lightintensity),1.0)));}v_color.r+=clamp(color.r*directional*u_lightcolor.r,mix(0.0,0.3,1.0-u_lightcolor.r),1.0);v_color.g+=clamp(color.g*directional*u_lightcolor.g,mix(0.0,0.3,1.0-u_lightcolor.g),1.0);v_color.b+=clamp(color.b*directional*u_lightcolor.b,mix(0.0,0.3,1.0-u_lightcolor.b),1.0);v_color*=u_opacity;}"),sr=yr("uniform vec2 u_texsize;uniform float u_fade;uniform sampler2D u_image;varying vec2 v_pos_a;varying vec2 v_pos_b;varying vec4 v_lighting;\n#pragma mapbox: define lowp float base\n#pragma mapbox: define lowp float height\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\nvoid main() {\n#pragma mapbox: initialize lowp float base\n#pragma mapbox: initialize lowp float height\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);vec4 mixedColor=mix(color1,color2,u_fade);gl_FragColor=mixedColor*v_lighting;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","uniform mat4 u_matrix;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform float u_height_factor;uniform vec3 u_scale;uniform float u_vertical_gradient;uniform lowp float u_opacity;uniform vec3 u_lightcolor;uniform lowp vec3 u_lightpos;uniform lowp float u_lightintensity;attribute vec2 a_pos;attribute vec4 a_normal_ed;varying vec2 v_pos_a;varying vec2 v_pos_b;varying vec4 v_lighting;\n#pragma mapbox: define lowp float base\n#pragma mapbox: define lowp float height\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\nvoid main() {\n#pragma mapbox: initialize lowp float base\n#pragma mapbox: initialize lowp float height\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;vec3 normal=a_normal_ed.xyz;float edgedistance=a_normal_ed.w;vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;base=max(0.0,base);height=max(0.0,height);float t=mod(normal.x,2.0);float z=t > 0.0 ? height : base;gl_Position=u_matrix*vec4(a_pos,z,1);vec2 pos=normal.x==1.0 && normal.y==0.0 && normal.z==16384.0\n? a_pos\n: vec2(edgedistance,z*u_height_factor);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,fromScale*display_size_a,tileRatio,pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,toScale*display_size_b,tileRatio,pos);v_lighting=vec4(0.0,0.0,0.0,1.0);float directional=clamp(dot(normal/16383.0,u_lightpos),0.0,1.0);directional=mix((1.0-u_lightintensity),max((0.5+u_lightintensity),1.0),directional);if (normal.y !=0.0) {directional*=((1.0-u_vertical_gradient)+(u_vertical_gradient*clamp((t+base)*pow(height/150.0,0.5),mix(0.7,0.98,1.0-u_lightintensity),1.0)));}v_lighting.rgb+=clamp(directional*u_lightcolor,mix(vec3(0.0),vec3(0.3),1.0-u_lightcolor),vec3(1.0));v_lighting*=u_opacity;}"),lr=yr("#ifdef GL_ES\nprecision highp float;\n#endif\nuniform sampler2D u_image;varying vec2 v_pos;uniform vec2 u_dimension;uniform float u_zoom;uniform float u_maxzoom;uniform vec4 u_unpack;float getElevation(vec2 coord,float bias) {vec4 data=texture2D(u_image,coord)*255.0;data.a=-1.0;return dot(data,u_unpack)/4.0;}void main() {vec2 epsilon=1.0/u_dimension;float a=getElevation(v_pos+vec2(-epsilon.x,-epsilon.y),0.0);float b=getElevation(v_pos+vec2(0,-epsilon.y),0.0);float c=getElevation(v_pos+vec2(epsilon.x,-epsilon.y),0.0);float d=getElevation(v_pos+vec2(-epsilon.x,0),0.0);float e=getElevation(v_pos,0.0);float f=getElevation(v_pos+vec2(epsilon.x,0),0.0);float g=getElevation(v_pos+vec2(-epsilon.x,epsilon.y),0.0);float h=getElevation(v_pos+vec2(0,epsilon.y),0.0);float i=getElevation(v_pos+vec2(epsilon.x,epsilon.y),0.0);float exaggeration=u_zoom < 2.0 ? 0.4 : u_zoom < 4.5 ? 0.35 : 0.3;vec2 deriv=vec2((c+f+f+i)-(a+d+d+g),(g+h+h+i)-(a+b+b+c))/ pow(2.0,(u_zoom-u_maxzoom)*exaggeration+19.2562-u_zoom);gl_FragColor=clamp(vec4(deriv.x/2.0+0.5,deriv.y/2.0+0.5,1.0,1.0),0.0,1.0);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","uniform mat4 u_matrix;uniform vec2 u_dimension;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);highp vec2 epsilon=1.0/u_dimension;float scale=(u_dimension.x-2.0)/u_dimension.x;v_pos=(a_texture_pos/8192.0)*scale+epsilon;}"),cr=yr("uniform sampler2D u_image;varying vec2 v_pos;uniform vec2 u_latrange;uniform vec2 u_light;uniform vec4 u_shadow;uniform vec4 u_highlight;uniform vec4 u_accent;\n#define PI 3.141592653589793\nvoid main() {vec4 pixel=texture2D(u_image,v_pos);vec2 deriv=((pixel.rg*2.0)-1.0);float scaleFactor=cos(radians((u_latrange[0]-u_latrange[1])*(1.0-v_pos.y)+u_latrange[1]));float slope=atan(1.25*length(deriv)/scaleFactor);float aspect=deriv.x !=0.0 ? atan(deriv.y,-deriv.x) : PI/2.0*(deriv.y > 0.0 ? 1.0 :-1.0);float intensity=u_light.x;float azimuth=u_light.y+PI;float base=1.875-intensity*1.75;float maxValue=0.5*PI;float scaledSlope=intensity !=0.5 ? ((pow(base,slope)-1.0)/(pow(base,maxValue)-1.0))*maxValue : slope;float accent=cos(scaledSlope);vec4 accent_color=(1.0-accent)*u_accent*clamp(intensity*2.0,0.0,1.0);float shade=abs(mod((aspect+azimuth)/PI+0.5,2.0)-1.0);vec4 shade_color=mix(u_shadow,u_highlight,shade)*sin(scaledSlope)*clamp(intensity*2.0,0.0,1.0);gl_FragColor=accent_color*(1.0-shade_color.a)+shade_color;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","uniform mat4 u_matrix;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);v_pos=a_texture_pos/8192.0;}"),ur=yr("uniform lowp float u_device_pixel_ratio;varying vec2 v_width2;varying vec2 v_normal;varying float v_gamma_scale;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);gl_FragColor=color*(alpha*opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","\n#define scale 0.015873016\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform mediump float u_ratio;uniform vec2 u_units_to_pixels;uniform lowp float u_device_pixel_ratio;varying vec2 v_normal;varying vec2 v_width2;varying float v_gamma_scale;varying highp float v_linesofar;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define mediump float gapwidth\n#pragma mapbox: define lowp float offset\n#pragma mapbox: define mediump float width\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump float gapwidth\n#pragma mapbox: initialize lowp float offset\n#pragma mapbox: initialize mediump float width\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;v_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*2.0;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_width2=vec2(outset,inset);}"),fr=yr("uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;varying vec2 v_width2;varying vec2 v_normal;varying float v_gamma_scale;varying highp float v_lineprogress;\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);vec4 color=texture2D(u_image,vec2(v_lineprogress,0.5));gl_FragColor=color*(alpha*opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","\n#define MAX_LINE_DISTANCE 32767.0\n#define scale 0.015873016\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_units_to_pixels;varying vec2 v_normal;varying vec2 v_width2;varying float v_gamma_scale;varying highp float v_lineprogress;\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define mediump float gapwidth\n#pragma mapbox: define lowp float offset\n#pragma mapbox: define mediump float width\nvoid main() {\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump float gapwidth\n#pragma mapbox: initialize lowp float offset\n#pragma mapbox: initialize mediump float width\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;v_lineprogress=(floor(a_data.z/4.0)+a_data.w*64.0)*2.0/MAX_LINE_DISTANCE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_width2=vec2(outset,inset);}"),hr=yr("uniform lowp float u_device_pixel_ratio;uniform vec2 u_texsize;uniform float u_fade;uniform mediump vec3 u_scale;uniform sampler2D u_image;varying vec2 v_normal;varying vec2 v_width2;varying float v_linesofar;varying float v_gamma_scale;varying float v_width;\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileZoomRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;vec2 pattern_size_a=vec2(display_size_a.x*fromScale/tileZoomRatio,display_size_a.y);vec2 pattern_size_b=vec2(display_size_b.x*toScale/tileZoomRatio,display_size_b.y);float aspect_a=display_size_a.y/v_width;float aspect_b=display_size_b.y/v_width;float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float x_a=mod(v_linesofar/pattern_size_a.x*aspect_a,1.0);float x_b=mod(v_linesofar/pattern_size_b.x*aspect_b,1.0);float y=0.5*v_normal.y+0.5;vec2 texel_size=1.0/u_texsize;vec2 pos_a=mix(pattern_tl_a*texel_size-texel_size,pattern_br_a*texel_size+texel_size,vec2(x_a,y));vec2 pos_b=mix(pattern_tl_b*texel_size-texel_size,pattern_br_b*texel_size+texel_size,vec2(x_b,y));vec4 color=mix(texture2D(u_image,pos_a),texture2D(u_image,pos_b),u_fade);gl_FragColor=color*alpha*opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform vec2 u_units_to_pixels;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;varying vec2 v_normal;varying vec2 v_width2;varying float v_linesofar;varying float v_gamma_scale;varying float v_width;\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float offset\n#pragma mapbox: define mediump float gapwidth\n#pragma mapbox: define mediump float width\n#pragma mapbox: define lowp float floorwidth\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\nvoid main() {\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float offset\n#pragma mapbox: initialize mediump float gapwidth\n#pragma mapbox: initialize mediump float width\n#pragma mapbox: initialize lowp float floorwidth\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_linesofar=a_linesofar;v_width2=vec2(outset,inset);v_width=floorwidth;}"),pr=yr("uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;uniform float u_sdfgamma;uniform float u_mix;varying vec2 v_normal;varying vec2 v_width2;varying vec2 v_tex_a;varying vec2 v_tex_b;varying float v_gamma_scale;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define mediump float width\n#pragma mapbox: define lowp float floorwidth\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump float width\n#pragma mapbox: initialize lowp float floorwidth\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float sdfdist_a=texture2D(u_image,v_tex_a).a;float sdfdist_b=texture2D(u_image,v_tex_b).a;float sdfdist=mix(sdfdist_a,sdfdist_b,u_mix);alpha*=smoothstep(0.5-u_sdfgamma/floorwidth,0.5+u_sdfgamma/floorwidth,sdfdist);gl_FragColor=color*(alpha*opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_patternscale_a;uniform float u_tex_y_a;uniform vec2 u_patternscale_b;uniform float u_tex_y_b;uniform vec2 u_units_to_pixels;varying vec2 v_normal;varying vec2 v_width2;varying vec2 v_tex_a;varying vec2 v_tex_b;varying float v_gamma_scale;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define mediump float gapwidth\n#pragma mapbox: define lowp float offset\n#pragma mapbox: define mediump float width\n#pragma mapbox: define lowp float floorwidth\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump float gapwidth\n#pragma mapbox: initialize lowp float offset\n#pragma mapbox: initialize mediump float width\n#pragma mapbox: initialize lowp float floorwidth\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_tex_a=vec2(a_linesofar*u_patternscale_a.x/floorwidth,normal.y*u_patternscale_a.y+u_tex_y_a);v_tex_b=vec2(a_linesofar*u_patternscale_b.x/floorwidth,normal.y*u_patternscale_b.y+u_tex_y_b);v_width2=vec2(outset,inset);}"),dr=yr("uniform float u_fade_t;uniform float u_opacity;uniform sampler2D u_image0;uniform sampler2D u_image1;varying vec2 v_pos0;varying vec2 v_pos1;uniform float u_brightness_low;uniform float u_brightness_high;uniform float u_saturation_factor;uniform float u_contrast_factor;uniform vec3 u_spin_weights;void main() {vec4 color0=texture2D(u_image0,v_pos0);vec4 color1=texture2D(u_image1,v_pos1);if (color0.a > 0.0) {color0.rgb=color0.rgb/color0.a;}if (color1.a > 0.0) {color1.rgb=color1.rgb/color1.a;}vec4 color=mix(color0,color1,u_fade_t);color.a*=u_opacity;vec3 rgb=color.rgb;rgb=vec3(dot(rgb,u_spin_weights.xyz),dot(rgb,u_spin_weights.zxy),dot(rgb,u_spin_weights.yzx));float average=(color.r+color.g+color.b)/3.0;rgb+=(average-rgb)*u_saturation_factor;rgb=(rgb-0.5)*u_contrast_factor+0.5;vec3 u_high_vec=vec3(u_brightness_low,u_brightness_low,u_brightness_low);vec3 u_low_vec=vec3(u_brightness_high,u_brightness_high,u_brightness_high);gl_FragColor=vec4(mix(u_high_vec,u_low_vec,rgb)*color.a,color.a);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","uniform mat4 u_matrix;uniform vec2 u_tl_parent;uniform float u_scale_parent;uniform float u_buffer_scale;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos0;varying vec2 v_pos1;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);v_pos0=(((a_texture_pos/8192.0)-0.5)/u_buffer_scale )+0.5;v_pos1=(v_pos0*u_scale_parent)+u_tl_parent;}"),mr=yr("uniform sampler2D u_texture;varying vec2 v_tex;varying float v_fade_opacity;\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\nlowp float alpha=opacity*v_fade_opacity;gl_FragColor=texture2D(u_texture,v_tex)*alpha;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","const float PI=3.141592653589793;attribute vec4 a_pos_offset;attribute vec4 a_data;attribute vec4 a_pixeloffset;attribute vec3 a_projected_pos;attribute float a_fade_opacity;uniform bool u_is_size_zoom_constant;uniform bool u_is_size_feature_constant;uniform highp float u_size_t;uniform highp float u_size;uniform highp float u_camera_to_center_distance;uniform highp float u_pitch;uniform bool u_rotate_symbol;uniform highp float u_aspect_ratio;uniform float u_fade_change;uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_coord_matrix;uniform bool u_is_text;uniform bool u_pitch_with_map;uniform vec2 u_texsize;varying vec2 v_tex;varying float v_fade_opacity;\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\nvec2 a_pos=a_pos_offset.xy;vec2 a_offset=a_pos_offset.zw;vec2 a_tex=a_data.xy;vec2 a_size=a_data.zw;float a_size_min=floor(a_size[0]*0.5);vec2 a_pxoffset=a_pixeloffset.xy;vec2 a_minFontScale=a_pixeloffset.zw/256.0;highp float segment_angle=-a_projected_pos[2];float size;if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {size=mix(a_size_min,a_size[1],u_size_t)/128.0;} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {size=a_size_min/128.0;} else {size=u_size;}vec4 projectedPoint=u_matrix*vec4(a_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float distance_ratio=u_pitch_with_map ?\ncamera_to_anchor_distance/u_camera_to_center_distance :\nu_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.0,4.0);size*=perspective_ratio;float fontScale=u_is_text ? size/24.0 : size;highp float symbol_rotation=0.0;if (u_rotate_symbol) {vec4 offsetProjectedPoint=u_matrix*vec4(a_pos+vec2(1,0),0,1);vec2 a=projectedPoint.xy/projectedPoint.w;vec2 b=offsetProjectedPoint.xy/offsetProjectedPoint.w;symbol_rotation=atan((b.y-a.y)/u_aspect_ratio,b.x-a.x);}highp float angle_sin=sin(segment_angle+symbol_rotation);highp float angle_cos=cos(segment_angle+symbol_rotation);mat2 rotation_matrix=mat2(angle_cos,-1.0*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.0,1.0);gl_Position=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.0*max(a_minFontScale,fontScale)+a_pxoffset/16.0),0.0,1.0);v_tex=a_tex/u_texsize;vec2 fade_opacity=unpack_opacity(a_fade_opacity);float fade_change=fade_opacity[1] > 0.5 ? u_fade_change :-u_fade_change;v_fade_opacity=max(0.0,min(1.0,fade_opacity[0]+fade_change));}"),gr=yr("#define SDF_PX 8.0\nuniform bool u_is_halo;uniform sampler2D u_texture;uniform highp float u_gamma_scale;uniform lowp float u_device_pixel_ratio;uniform bool u_is_text;varying vec2 v_data0;varying vec3 v_data1;\n#pragma mapbox: define highp vec4 fill_color\n#pragma mapbox: define highp vec4 halo_color\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float halo_width\n#pragma mapbox: define lowp float halo_blur\nvoid main() {\n#pragma mapbox: initialize highp vec4 fill_color\n#pragma mapbox: initialize highp vec4 halo_color\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float halo_width\n#pragma mapbox: initialize lowp float halo_blur\nfloat EDGE_GAMMA=0.105/u_device_pixel_ratio;vec2 tex=v_data0.xy;float gamma_scale=v_data1.x;float size=v_data1.y;float fade_opacity=v_data1[2];float fontScale=u_is_text ? size/24.0 : size;lowp vec4 color=fill_color;highp float gamma=EDGE_GAMMA/(fontScale*u_gamma_scale);lowp float buff=(256.0-64.0)/256.0;if (u_is_halo) {color=halo_color;gamma=(halo_blur*1.19/SDF_PX+EDGE_GAMMA)/(fontScale*u_gamma_scale);buff=(6.0-halo_width/fontScale)/SDF_PX;}lowp float dist=texture2D(u_texture,tex).a;highp float gamma_scaled=gamma*gamma_scale;highp float alpha=smoothstep(buff-gamma_scaled,buff+gamma_scaled,dist);gl_FragColor=color*(alpha*opacity*fade_opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","const float PI=3.141592653589793;attribute vec4 a_pos_offset;attribute vec4 a_data;attribute vec4 a_pixeloffset;attribute vec3 a_projected_pos;attribute float a_fade_opacity;uniform bool u_is_size_zoom_constant;uniform bool u_is_size_feature_constant;uniform highp float u_size_t;uniform highp float u_size;uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_coord_matrix;uniform bool u_is_text;uniform bool u_pitch_with_map;uniform highp float u_pitch;uniform bool u_rotate_symbol;uniform highp float u_aspect_ratio;uniform highp float u_camera_to_center_distance;uniform float u_fade_change;uniform vec2 u_texsize;varying vec2 v_data0;varying vec3 v_data1;\n#pragma mapbox: define highp vec4 fill_color\n#pragma mapbox: define highp vec4 halo_color\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float halo_width\n#pragma mapbox: define lowp float halo_blur\nvoid main() {\n#pragma mapbox: initialize highp vec4 fill_color\n#pragma mapbox: initialize highp vec4 halo_color\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float halo_width\n#pragma mapbox: initialize lowp float halo_blur\nvec2 a_pos=a_pos_offset.xy;vec2 a_offset=a_pos_offset.zw;vec2 a_tex=a_data.xy;vec2 a_size=a_data.zw;float a_size_min=floor(a_size[0]*0.5);vec2 a_pxoffset=a_pixeloffset.xy;highp float segment_angle=-a_projected_pos[2];float size;if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {size=mix(a_size_min,a_size[1],u_size_t)/128.0;} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {size=a_size_min/128.0;} else {size=u_size;}vec4 projectedPoint=u_matrix*vec4(a_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float distance_ratio=u_pitch_with_map ?\ncamera_to_anchor_distance/u_camera_to_center_distance :\nu_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.0,4.0);size*=perspective_ratio;float fontScale=u_is_text ? size/24.0 : size;highp float symbol_rotation=0.0;if (u_rotate_symbol) {vec4 offsetProjectedPoint=u_matrix*vec4(a_pos+vec2(1,0),0,1);vec2 a=projectedPoint.xy/projectedPoint.w;vec2 b=offsetProjectedPoint.xy/offsetProjectedPoint.w;symbol_rotation=atan((b.y-a.y)/u_aspect_ratio,b.x-a.x);}highp float angle_sin=sin(segment_angle+symbol_rotation);highp float angle_cos=cos(segment_angle+symbol_rotation);mat2 rotation_matrix=mat2(angle_cos,-1.0*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.0,1.0);gl_Position=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.0*fontScale+a_pxoffset),0.0,1.0);float gamma_scale=gl_Position.w;vec2 fade_opacity=unpack_opacity(a_fade_opacity);float fade_change=fade_opacity[1] > 0.5 ? u_fade_change :-u_fade_change;float interpolated_fade_opacity=max(0.0,min(1.0,fade_opacity[0]+fade_change));v_data0=a_tex/u_texsize;v_data1=vec3(gamma_scale,size,interpolated_fade_opacity);}"),vr=yr("#define SDF_PX 8.0\n#define SDF 1.0\n#define ICON 0.0\nuniform bool u_is_halo;uniform sampler2D u_texture;uniform sampler2D u_texture_icon;uniform highp float u_gamma_scale;uniform lowp float u_device_pixel_ratio;varying vec4 v_data0;varying vec4 v_data1;\n#pragma mapbox: define highp vec4 fill_color\n#pragma mapbox: define highp vec4 halo_color\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float halo_width\n#pragma mapbox: define lowp float halo_blur\nvoid main() {\n#pragma mapbox: initialize highp vec4 fill_color\n#pragma mapbox: initialize highp vec4 halo_color\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float halo_width\n#pragma mapbox: initialize lowp float halo_blur\nfloat fade_opacity=v_data1[2];if (v_data1.w==ICON) {vec2 tex_icon=v_data0.zw;lowp float alpha=opacity*fade_opacity;gl_FragColor=texture2D(u_texture_icon,tex_icon)*alpha;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\nreturn;}vec2 tex=v_data0.xy;float EDGE_GAMMA=0.105/u_device_pixel_ratio;float gamma_scale=v_data1.x;float size=v_data1.y;float fontScale=size/24.0;lowp vec4 color=fill_color;highp float gamma=EDGE_GAMMA/(fontScale*u_gamma_scale);lowp float buff=(256.0-64.0)/256.0;if (u_is_halo) {color=halo_color;gamma=(halo_blur*1.19/SDF_PX+EDGE_GAMMA)/(fontScale*u_gamma_scale);buff=(6.0-halo_width/fontScale)/SDF_PX;}lowp float dist=texture2D(u_texture,tex).a;highp float gamma_scaled=gamma*gamma_scale;highp float alpha=smoothstep(buff-gamma_scaled,buff+gamma_scaled,dist);gl_FragColor=color*(alpha*opacity*fade_opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}","const float PI=3.141592653589793;attribute vec4 a_pos_offset;attribute vec4 a_data;attribute vec3 a_projected_pos;attribute float a_fade_opacity;uniform bool u_is_size_zoom_constant;uniform bool u_is_size_feature_constant;uniform highp float u_size_t;uniform highp float u_size;uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_coord_matrix;uniform bool u_is_text;uniform bool u_pitch_with_map;uniform highp float u_pitch;uniform bool u_rotate_symbol;uniform highp float u_aspect_ratio;uniform highp float u_camera_to_center_distance;uniform float u_fade_change;uniform vec2 u_texsize;uniform vec2 u_texsize_icon;varying vec4 v_data0;varying vec4 v_data1;\n#pragma mapbox: define highp vec4 fill_color\n#pragma mapbox: define highp vec4 halo_color\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float halo_width\n#pragma mapbox: define lowp float halo_blur\nvoid main() {\n#pragma mapbox: initialize highp vec4 fill_color\n#pragma mapbox: initialize highp vec4 halo_color\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float halo_width\n#pragma mapbox: initialize lowp float halo_blur\nvec2 a_pos=a_pos_offset.xy;vec2 a_offset=a_pos_offset.zw;vec2 a_tex=a_data.xy;vec2 a_size=a_data.zw;float a_size_min=floor(a_size[0]*0.5);float is_sdf=a_size[0]-2.0*a_size_min;highp float segment_angle=-a_projected_pos[2];float size;if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {size=mix(a_size_min,a_size[1],u_size_t)/128.0;} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {size=a_size_min/128.0;} else {size=u_size;}vec4 projectedPoint=u_matrix*vec4(a_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float distance_ratio=u_pitch_with_map ?\ncamera_to_anchor_distance/u_camera_to_center_distance :\nu_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.0,4.0);size*=perspective_ratio;float fontScale=size/24.0;highp float symbol_rotation=0.0;if (u_rotate_symbol) {vec4 offsetProjectedPoint=u_matrix*vec4(a_pos+vec2(1,0),0,1);vec2 a=projectedPoint.xy/projectedPoint.w;vec2 b=offsetProjectedPoint.xy/offsetProjectedPoint.w;symbol_rotation=atan((b.y-a.y)/u_aspect_ratio,b.x-a.x);}highp float angle_sin=sin(segment_angle+symbol_rotation);highp float angle_cos=cos(segment_angle+symbol_rotation);mat2 rotation_matrix=mat2(angle_cos,-1.0*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.0,1.0);gl_Position=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.0*fontScale),0.0,1.0);float gamma_scale=gl_Position.w;vec2 fade_opacity=unpack_opacity(a_fade_opacity);float fade_change=fade_opacity[1] > 0.5 ? u_fade_change :-u_fade_change;float interpolated_fade_opacity=max(0.0,min(1.0,fade_opacity[0]+fade_change));v_data0.xy=a_tex/u_texsize;v_data0.zw=a_tex/u_texsize_icon;v_data1=vec4(gamma_scale,size,interpolated_fade_opacity,is_sdf);}");function yr(t,e){var r=/#pragma mapbox: ([\w]+) ([\w]+) ([\w]+) ([\w]+)/g,n={};return{fragmentSource:t=t.replace(r,(function(t,e,r,i,a){return n[a]=!0,"define"===e?"\n#ifndef HAS_UNIFORM_u_"+a+"\nvarying "+r+" "+i+" "+a+";\n#else\nuniform "+r+" "+i+" u_"+a+";\n#endif\n":"\n#ifdef HAS_UNIFORM_u_"+a+"\n    "+r+" "+i+" "+a+" = u_"+a+";\n#endif\n"})),vertexSource:e=e.replace(r,(function(t,e,r,i,a){var o="float"===i?"vec2":"vec4",s=a.match(/color/)?"color":o;return n[a]?"define"===e?"\n#ifndef HAS_UNIFORM_u_"+a+"\nuniform lowp float u_"+a+"_t;\nattribute "+r+" "+o+" a_"+a+";\nvarying "+r+" "+i+" "+a+";\n#else\nuniform "+r+" "+i+" u_"+a+";\n#endif\n":"vec4"===s?"\n#ifndef HAS_UNIFORM_u_"+a+"\n    "+a+" = a_"+a+";\n#else\n    "+r+" "+i+" "+a+" = u_"+a+";\n#endif\n":"\n#ifndef HAS_UNIFORM_u_"+a+"\n    "+a+" = unpack_mix_"+s+"(a_"+a+", u_"+a+"_t);\n#else\n    "+r+" "+i+" "+a+" = u_"+a+";\n#endif\n":"define"===e?"\n#ifndef HAS_UNIFORM_u_"+a+"\nuniform lowp float u_"+a+"_t;\nattribute "+r+" "+o+" a_"+a+";\n#else\nuniform "+r+" "+i+" u_"+a+";\n#endif\n":"vec4"===s?"\n#ifndef HAS_UNIFORM_u_"+a+"\n    "+r+" "+i+" "+a+" = a_"+a+";\n#else\n    "+r+" "+i+" "+a+" = u_"+a+";\n#endif\n":"\n#ifndef HAS_UNIFORM_u_"+a+"\n    "+r+" "+i+" "+a+" = unpack_mix_"+s+"(a_"+a+", u_"+a+"_t);\n#else\n    "+r+" "+i+" "+a+" = u_"+a+";\n#endif\n"}))}}var xr=Object.freeze({__proto__:null,prelude:Ye,background:We,backgroundPattern:Xe,circle:Ze,clippingMask:Je,heatmap:Ke,heatmapTexture:Qe,collisionBox:$e,collisionCircle:tr,debug:er,fill:rr,fillOutline:nr,fillOutlinePattern:ir,fillPattern:ar,fillExtrusion:or,fillExtrusionPattern:sr,hillshadePrepare:lr,hillshade:cr,line:ur,lineGradient:fr,linePattern:hr,lineSDF:pr,raster:dr,symbolIcon:mr,symbolSDF:gr,symbolTextAndIcon:vr}),br=function(){this.boundProgram=null,this.boundLayoutVertexBuffer=null,this.boundPaintVertexBuffers=[],this.boundIndexBuffer=null,this.boundVertexOffset=null,this.boundDynamicVertexBuffer=null,this.vao=null};br.prototype.bind=function(t,e,r,n,i,a,o,s){this.context=t;for(var l=this.boundPaintVertexBuffers.length!==n.length,c=0;!l&&c<n.length;c++)this.boundPaintVertexBuffers[c]!==n[c]&&(l=!0);var u=!this.vao||this.boundProgram!==e||this.boundLayoutVertexBuffer!==r||l||this.boundIndexBuffer!==i||this.boundVertexOffset!==a||this.boundDynamicVertexBuffer!==o||this.boundDynamicVertexBuffer2!==s;!t.extVertexArrayObject||u?this.freshBind(e,r,n,i,a,o,s):(t.bindVertexArrayOES.set(this.vao),o&&o.bind(),i&&i.dynamicDraw&&i.bind(),s&&s.bind())},br.prototype.freshBind=function(t,e,r,n,i,a,o){var s,l=t.numAttributes,c=this.context,u=c.gl;if(c.extVertexArrayObject)this.vao&&this.destroy(),this.vao=c.extVertexArrayObject.createVertexArrayOES(),c.bindVertexArrayOES.set(this.vao),s=0,this.boundProgram=t,this.boundLayoutVertexBuffer=e,this.boundPaintVertexBuffers=r,this.boundIndexBuffer=n,this.boundVertexOffset=i,this.boundDynamicVertexBuffer=a,this.boundDynamicVertexBuffer2=o;else{s=c.currentNumAttributes||0;for(var f=l;f<s;f++)u.disableVertexAttribArray(f)}e.enableAttributes(u,t);for(var h=0,p=r;h<p.length;h+=1){p[h].enableAttributes(u,t)}a&&a.enableAttributes(u,t),o&&o.enableAttributes(u,t),e.bind(),e.setVertexAttribPointers(u,t,i);for(var d=0,m=r;d<m.length;d+=1){var g=m[d];g.bind(),g.setVertexAttribPointers(u,t,i)}a&&(a.bind(),a.setVertexAttribPointers(u,t,i)),n&&n.bind(),o&&(o.bind(),o.setVertexAttribPointers(u,t,i)),c.currentNumAttributes=l},br.prototype.destroy=function(){this.vao&&(this.context.extVertexArrayObject.deleteVertexArrayOES(this.vao),this.vao=null)};var _r=function(t,e,r,n,i){var a=t.gl;this.program=a.createProgram();var o=r?r.defines():[];i&&o.push("#define OVERDRAW_INSPECTOR;");var s=o.concat(Ye.fragmentSource,e.fragmentSource).join("\n"),l=o.concat(Ye.vertexSource,e.vertexSource).join("\n"),c=a.createShader(a.FRAGMENT_SHADER);if(a.isContextLost())this.failedToCreate=!0;else{a.shaderSource(c,s),a.compileShader(c),a.attachShader(this.program,c);var u=a.createShader(a.VERTEX_SHADER);if(a.isContextLost())this.failedToCreate=!0;else{a.shaderSource(u,l),a.compileShader(u),a.attachShader(this.program,u);for(var f=r?r.layoutAttributes:[],h=0;h<f.length;h++)a.bindAttribLocation(this.program,h,f[h].name);a.linkProgram(this.program),a.deleteShader(u),a.deleteShader(c),this.numAttributes=a.getProgramParameter(this.program,a.ACTIVE_ATTRIBUTES),this.attributes={};for(var p={},d=0;d<this.numAttributes;d++){var m=a.getActiveAttrib(this.program,d);m&&(this.attributes[m.name]=a.getAttribLocation(this.program,m.name))}for(var g=a.getProgramParameter(this.program,a.ACTIVE_UNIFORMS),v=0;v<g;v++){var y=a.getActiveUniform(this.program,v);y&&(p[y.name]=a.getUniformLocation(this.program,y.name))}this.fixedUniforms=n(t,p),this.binderUniforms=r?r.getUniforms(t,p):[]}}};function wr(t,e,r){var n=1/pe(r,1,e.transform.tileZoom),i=Math.pow(2,r.tileID.overscaledZ),a=r.tileSize*Math.pow(2,e.transform.tileZoom)/i,o=a*(r.tileID.canonical.x+r.tileID.wrap*i),s=a*r.tileID.canonical.y;return{u_image:0,u_texsize:r.imageAtlasTexture.size,u_scale:[n,t.fromScale,t.toScale],u_fade:t.t,u_pixel_coord_upper:[o>>16,s>>16],u_pixel_coord_lower:[65535&o,65535&s]}}_r.prototype.draw=function(t,e,r,n,i,a,o,s,l,c,u,f,h,p,d,m){var g,v=t.gl;if(!this.failedToCreate){for(var y in t.program.set(this.program),t.setDepthMode(r),t.setStencilMode(n),t.setColorMode(i),t.setCullFace(a),this.fixedUniforms)this.fixedUniforms[y].set(o[y]);p&&p.setUniforms(t,this.binderUniforms,f,{zoom:h});for(var x=(g={},g[v.LINES]=2,g[v.TRIANGLES]=3,g[v.LINE_STRIP]=1,g)[e],b=0,_=u.get();b<_.length;b+=1){var w=_[b],T=w.vaos||(w.vaos={});(T[s]||(T[s]=new br)).bind(t,this,l,p?p.getPaintVertexBuffers():[],c,w.vertexOffset,d,m),v.drawElements(e,w.primitiveLength*x,v.UNSIGNED_SHORT,w.primitiveOffset*x*2)}}};var Tr=function(e,r,n,i){var a=r.style.light,o=a.properties.get("position"),s=[o.x,o.y,o.z],l=t.create$1();"viewport"===a.properties.get("anchor")&&t.fromRotation(l,-r.transform.angle),t.transformMat3(s,s,l);var c=a.properties.get("color");return{u_matrix:e,u_lightpos:s,u_lightintensity:a.properties.get("intensity"),u_lightcolor:[c.r,c.g,c.b],u_vertical_gradient:+n,u_opacity:i}},kr=function(e,r,n,i,a,o,s){return t.extend(Tr(e,r,n,i),wr(o,r,s),{u_height_factor:-Math.pow(2,a.overscaledZ)/s.tileSize/8})},Ar=function(t){return{u_matrix:t}},Mr=function(e,r,n,i){return t.extend(Ar(e),wr(n,r,i))},Sr=function(t,e){return{u_matrix:t,u_world:e}},Er=function(e,r,n,i,a){return t.extend(Mr(e,r,n,i),{u_world:a})},Lr=function(e,r,n,i){var a,o,s=e.transform;if("map"===i.paint.get("circle-pitch-alignment")){var l=pe(n,1,s.zoom);a=!0,o=[l,l]}else a=!1,o=s.pixelsToGLUnits;return{u_camera_to_center_distance:s.cameraToCenterDistance,u_scale_with_map:+("map"===i.paint.get("circle-pitch-scale")),u_matrix:e.translatePosMatrix(r.posMatrix,n,i.paint.get("circle-translate"),i.paint.get("circle-translate-anchor")),u_pitch_with_map:+a,u_device_pixel_ratio:t.browser.devicePixelRatio,u_extrude_scale:o}},Cr=function(t,e,r){var n=pe(r,1,e.zoom),i=Math.pow(2,e.zoom-r.tileID.overscaledZ),a=r.tileID.overscaleFactor();return{u_matrix:t,u_camera_to_center_distance:e.cameraToCenterDistance,u_pixels_to_tile_units:n,u_extrude_scale:[e.pixelsToGLUnits[0]/(n*i),e.pixelsToGLUnits[1]/(n*i)],u_overscale_factor:a}},Pr=function(t,e,r){return{u_matrix:t,u_inv_matrix:e,u_camera_to_center_distance:r.cameraToCenterDistance,u_viewport_size:[r.width,r.height]}},Ir=function(t,e,r){return void 0===r&&(r=1),{u_matrix:t,u_color:e,u_overlay:0,u_overlay_scale:r}},Or=function(t){return{u_matrix:t}},zr=function(t,e,r,n){return{u_matrix:t,u_extrude_scale:pe(e,1,r),u_intensity:n}};function Dr(e,r){var n=Math.pow(2,r.canonical.z),i=r.canonical.y;return[new t.MercatorCoordinate(0,i/n).toLngLat().lat,new t.MercatorCoordinate(0,(i+1)/n).toLngLat().lat]}var Rr=function(e,r,n){var i=e.transform;return{u_matrix:Ur(e,r,n),u_ratio:1/pe(r,1,i.zoom),u_device_pixel_ratio:t.browser.devicePixelRatio,u_units_to_pixels:[1/i.pixelsToGLUnits[0],1/i.pixelsToGLUnits[1]]}},Fr=function(e,r,n){return t.extend(Rr(e,r,n),{u_image:0})},Br=function(e,r,n,i){var a=e.transform,o=jr(r,a);return{u_matrix:Ur(e,r,n),u_texsize:r.imageAtlasTexture.size,u_ratio:1/pe(r,1,a.zoom),u_device_pixel_ratio:t.browser.devicePixelRatio,u_image:0,u_scale:[o,i.fromScale,i.toScale],u_fade:i.t,u_units_to_pixels:[1/a.pixelsToGLUnits[0],1/a.pixelsToGLUnits[1]]}},Nr=function(e,r,n,i,a){var o=e.transform,s=e.lineAtlas,l=jr(r,o),c="round"===n.layout.get("line-cap"),u=s.getDash(i.from,c),f=s.getDash(i.to,c),h=u.width*a.fromScale,p=f.width*a.toScale;return t.extend(Rr(e,r,n),{u_patternscale_a:[l/h,-u.height/2],u_patternscale_b:[l/p,-f.height/2],u_sdfgamma:s.width/(256*Math.min(h,p)*t.browser.devicePixelRatio)/2,u_image:0,u_tex_y_a:u.y,u_tex_y_b:f.y,u_mix:a.t})};function jr(t,e){return 1/pe(t,1,e.tileZoom)}function Ur(t,e,r){return t.translatePosMatrix(e.tileID.posMatrix,e,r.paint.get("line-translate"),r.paint.get("line-translate-anchor"))}var Vr=function(t,e,r,n,i){return{u_matrix:t,u_tl_parent:e,u_scale_parent:r,u_buffer_scale:1,u_fade_t:n.mix,u_opacity:n.opacity*i.paint.get("raster-opacity"),u_image0:0,u_image1:1,u_brightness_low:i.paint.get("raster-brightness-min"),u_brightness_high:i.paint.get("raster-brightness-max"),u_saturation_factor:(o=i.paint.get("raster-saturation"),o>0?1-1/(1.001-o):-o),u_contrast_factor:(a=i.paint.get("raster-contrast"),a>0?1/(1-a):1+a),u_spin_weights:Hr(i.paint.get("raster-hue-rotate"))};var a,o};function Hr(t){t*=Math.PI/180;var e=Math.sin(t),r=Math.cos(t);return[(2*r+1)/3,(-Math.sqrt(3)*e-r+1)/3,(Math.sqrt(3)*e-r+1)/3]}var qr,Gr=function(t,e,r,n,i,a,o,s,l,c){var u=i.transform;return{u_is_size_zoom_constant:+("constant"===t||"source"===t),u_is_size_feature_constant:+("constant"===t||"camera"===t),u_size_t:e?e.uSizeT:0,u_size:e?e.uSize:0,u_camera_to_center_distance:u.cameraToCenterDistance,u_pitch:u.pitch/360*2*Math.PI,u_rotate_symbol:+r,u_aspect_ratio:u.width/u.height,u_fade_change:i.options.fadeDuration?i.symbolFadeChange:1,u_matrix:a,u_label_plane_matrix:o,u_coord_matrix:s,u_is_text:+l,u_pitch_with_map:+n,u_texsize:c,u_texture:0}},Yr=function(e,r,n,i,a,o,s,l,c,u,f){var h=a.transform;return t.extend(Gr(e,r,n,i,a,o,s,l,c,u),{u_gamma_scale:i?Math.cos(h._pitch)*h.cameraToCenterDistance:1,u_device_pixel_ratio:t.browser.devicePixelRatio,u_is_halo:+f})},Wr=function(e,r,n,i,a,o,s,l,c,u){return t.extend(Yr(e,r,n,i,a,o,s,l,!0,c,!0),{u_texsize_icon:u,u_texture_icon:1})},Xr=function(t,e,r){return{u_matrix:t,u_opacity:e,u_color:r}},Zr=function(e,r,n,i,a,o){return t.extend(function(t,e,r,n){var i=r.imageManager.getPattern(t.from.toString()),a=r.imageManager.getPattern(t.to.toString()),o=r.imageManager.getPixelSize(),s=o.width,l=o.height,c=Math.pow(2,n.tileID.overscaledZ),u=n.tileSize*Math.pow(2,r.transform.tileZoom)/c,f=u*(n.tileID.canonical.x+n.tileID.wrap*c),h=u*n.tileID.canonical.y;return{u_image:0,u_pattern_tl_a:i.tl,u_pattern_br_a:i.br,u_pattern_tl_b:a.tl,u_pattern_br_b:a.br,u_texsize:[s,l],u_mix:e.t,u_pattern_size_a:i.displaySize,u_pattern_size_b:a.displaySize,u_scale_a:e.fromScale,u_scale_b:e.toScale,u_tile_units_to_pixels:1/pe(n,1,r.transform.tileZoom),u_pixel_coord_upper:[f>>16,h>>16],u_pixel_coord_lower:[65535&f,65535&h]}}(i,o,n,a),{u_matrix:e,u_opacity:r})},Jr={fillExtrusion:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_lightpos:new t.Uniform3f(e,r.u_lightpos),u_lightintensity:new t.Uniform1f(e,r.u_lightintensity),u_lightcolor:new t.Uniform3f(e,r.u_lightcolor),u_vertical_gradient:new t.Uniform1f(e,r.u_vertical_gradient),u_opacity:new t.Uniform1f(e,r.u_opacity)}},fillExtrusionPattern:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_lightpos:new t.Uniform3f(e,r.u_lightpos),u_lightintensity:new t.Uniform1f(e,r.u_lightintensity),u_lightcolor:new t.Uniform3f(e,r.u_lightcolor),u_vertical_gradient:new t.Uniform1f(e,r.u_vertical_gradient),u_height_factor:new t.Uniform1f(e,r.u_height_factor),u_image:new t.Uniform1i(e,r.u_image),u_texsize:new t.Uniform2f(e,r.u_texsize),u_pixel_coord_upper:new t.Uniform2f(e,r.u_pixel_coord_upper),u_pixel_coord_lower:new t.Uniform2f(e,r.u_pixel_coord_lower),u_scale:new t.Uniform3f(e,r.u_scale),u_fade:new t.Uniform1f(e,r.u_fade),u_opacity:new t.Uniform1f(e,r.u_opacity)}},fill:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix)}},fillPattern:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_image:new t.Uniform1i(e,r.u_image),u_texsize:new t.Uniform2f(e,r.u_texsize),u_pixel_coord_upper:new t.Uniform2f(e,r.u_pixel_coord_upper),u_pixel_coord_lower:new t.Uniform2f(e,r.u_pixel_coord_lower),u_scale:new t.Uniform3f(e,r.u_scale),u_fade:new t.Uniform1f(e,r.u_fade)}},fillOutline:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_world:new t.Uniform2f(e,r.u_world)}},fillOutlinePattern:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_world:new t.Uniform2f(e,r.u_world),u_image:new t.Uniform1i(e,r.u_image),u_texsize:new t.Uniform2f(e,r.u_texsize),u_pixel_coord_upper:new t.Uniform2f(e,r.u_pixel_coord_upper),u_pixel_coord_lower:new t.Uniform2f(e,r.u_pixel_coord_lower),u_scale:new t.Uniform3f(e,r.u_scale),u_fade:new t.Uniform1f(e,r.u_fade)}},circle:function(e,r){return{u_camera_to_center_distance:new t.Uniform1f(e,r.u_camera_to_center_distance),u_scale_with_map:new t.Uniform1i(e,r.u_scale_with_map),u_pitch_with_map:new t.Uniform1i(e,r.u_pitch_with_map),u_extrude_scale:new t.Uniform2f(e,r.u_extrude_scale),u_device_pixel_ratio:new t.Uniform1f(e,r.u_device_pixel_ratio),u_matrix:new t.UniformMatrix4f(e,r.u_matrix)}},collisionBox:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_camera_to_center_distance:new t.Uniform1f(e,r.u_camera_to_center_distance),u_pixels_to_tile_units:new t.Uniform1f(e,r.u_pixels_to_tile_units),u_extrude_scale:new t.Uniform2f(e,r.u_extrude_scale),u_overscale_factor:new t.Uniform1f(e,r.u_overscale_factor)}},collisionCircle:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_inv_matrix:new t.UniformMatrix4f(e,r.u_inv_matrix),u_camera_to_center_distance:new t.Uniform1f(e,r.u_camera_to_center_distance),u_viewport_size:new t.Uniform2f(e,r.u_viewport_size)}},debug:function(e,r){return{u_color:new t.UniformColor(e,r.u_color),u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_overlay:new t.Uniform1i(e,r.u_overlay),u_overlay_scale:new t.Uniform1f(e,r.u_overlay_scale)}},clippingMask:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix)}},heatmap:function(e,r){return{u_extrude_scale:new t.Uniform1f(e,r.u_extrude_scale),u_intensity:new t.Uniform1f(e,r.u_intensity),u_matrix:new t.UniformMatrix4f(e,r.u_matrix)}},heatmapTexture:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_world:new t.Uniform2f(e,r.u_world),u_image:new t.Uniform1i(e,r.u_image),u_color_ramp:new t.Uniform1i(e,r.u_color_ramp),u_opacity:new t.Uniform1f(e,r.u_opacity)}},hillshade:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_image:new t.Uniform1i(e,r.u_image),u_latrange:new t.Uniform2f(e,r.u_latrange),u_light:new t.Uniform2f(e,r.u_light),u_shadow:new t.UniformColor(e,r.u_shadow),u_highlight:new t.UniformColor(e,r.u_highlight),u_accent:new t.UniformColor(e,r.u_accent)}},hillshadePrepare:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_image:new t.Uniform1i(e,r.u_image),u_dimension:new t.Uniform2f(e,r.u_dimension),u_zoom:new t.Uniform1f(e,r.u_zoom),u_maxzoom:new t.Uniform1f(e,r.u_maxzoom),u_unpack:new t.Uniform4f(e,r.u_unpack)}},line:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_ratio:new t.Uniform1f(e,r.u_ratio),u_device_pixel_ratio:new t.Uniform1f(e,r.u_device_pixel_ratio),u_units_to_pixels:new t.Uniform2f(e,r.u_units_to_pixels)}},lineGradient:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_ratio:new t.Uniform1f(e,r.u_ratio),u_device_pixel_ratio:new t.Uniform1f(e,r.u_device_pixel_ratio),u_units_to_pixels:new t.Uniform2f(e,r.u_units_to_pixels),u_image:new t.Uniform1i(e,r.u_image)}},linePattern:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_texsize:new t.Uniform2f(e,r.u_texsize),u_ratio:new t.Uniform1f(e,r.u_ratio),u_device_pixel_ratio:new t.Uniform1f(e,r.u_device_pixel_ratio),u_image:new t.Uniform1i(e,r.u_image),u_units_to_pixels:new t.Uniform2f(e,r.u_units_to_pixels),u_scale:new t.Uniform3f(e,r.u_scale),u_fade:new t.Uniform1f(e,r.u_fade)}},lineSDF:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_ratio:new t.Uniform1f(e,r.u_ratio),u_device_pixel_ratio:new t.Uniform1f(e,r.u_device_pixel_ratio),u_units_to_pixels:new t.Uniform2f(e,r.u_units_to_pixels),u_patternscale_a:new t.Uniform2f(e,r.u_patternscale_a),u_patternscale_b:new t.Uniform2f(e,r.u_patternscale_b),u_sdfgamma:new t.Uniform1f(e,r.u_sdfgamma),u_image:new t.Uniform1i(e,r.u_image),u_tex_y_a:new t.Uniform1f(e,r.u_tex_y_a),u_tex_y_b:new t.Uniform1f(e,r.u_tex_y_b),u_mix:new t.Uniform1f(e,r.u_mix)}},raster:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_tl_parent:new t.Uniform2f(e,r.u_tl_parent),u_scale_parent:new t.Uniform1f(e,r.u_scale_parent),u_buffer_scale:new t.Uniform1f(e,r.u_buffer_scale),u_fade_t:new t.Uniform1f(e,r.u_fade_t),u_opacity:new t.Uniform1f(e,r.u_opacity),u_image0:new t.Uniform1i(e,r.u_image0),u_image1:new t.Uniform1i(e,r.u_image1),u_brightness_low:new t.Uniform1f(e,r.u_brightness_low),u_brightness_high:new t.Uniform1f(e,r.u_brightness_high),u_saturation_factor:new t.Uniform1f(e,r.u_saturation_factor),u_contrast_factor:new t.Uniform1f(e,r.u_contrast_factor),u_spin_weights:new t.Uniform3f(e,r.u_spin_weights)}},symbolIcon:function(e,r){return{u_is_size_zoom_constant:new t.Uniform1i(e,r.u_is_size_zoom_constant),u_is_size_feature_constant:new t.Uniform1i(e,r.u_is_size_feature_constant),u_size_t:new t.Uniform1f(e,r.u_size_t),u_size:new t.Uniform1f(e,r.u_size),u_camera_to_center_distance:new t.Uniform1f(e,r.u_camera_to_center_distance),u_pitch:new t.Uniform1f(e,r.u_pitch),u_rotate_symbol:new t.Uniform1i(e,r.u_rotate_symbol),u_aspect_ratio:new t.Uniform1f(e,r.u_aspect_ratio),u_fade_change:new t.Uniform1f(e,r.u_fade_change),u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_label_plane_matrix:new t.UniformMatrix4f(e,r.u_label_plane_matrix),u_coord_matrix:new t.UniformMatrix4f(e,r.u_coord_matrix),u_is_text:new t.Uniform1i(e,r.u_is_text),u_pitch_with_map:new t.Uniform1i(e,r.u_pitch_with_map),u_texsize:new t.Uniform2f(e,r.u_texsize),u_texture:new t.Uniform1i(e,r.u_texture)}},symbolSDF:function(e,r){return{u_is_size_zoom_constant:new t.Uniform1i(e,r.u_is_size_zoom_constant),u_is_size_feature_constant:new t.Uniform1i(e,r.u_is_size_feature_constant),u_size_t:new t.Uniform1f(e,r.u_size_t),u_size:new t.Uniform1f(e,r.u_size),u_camera_to_center_distance:new t.Uniform1f(e,r.u_camera_to_center_distance),u_pitch:new t.Uniform1f(e,r.u_pitch),u_rotate_symbol:new t.Uniform1i(e,r.u_rotate_symbol),u_aspect_ratio:new t.Uniform1f(e,r.u_aspect_ratio),u_fade_change:new t.Uniform1f(e,r.u_fade_change),u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_label_plane_matrix:new t.UniformMatrix4f(e,r.u_label_plane_matrix),u_coord_matrix:new t.UniformMatrix4f(e,r.u_coord_matrix),u_is_text:new t.Uniform1i(e,r.u_is_text),u_pitch_with_map:new t.Uniform1i(e,r.u_pitch_with_map),u_texsize:new t.Uniform2f(e,r.u_texsize),u_texture:new t.Uniform1i(e,r.u_texture),u_gamma_scale:new t.Uniform1f(e,r.u_gamma_scale),u_device_pixel_ratio:new t.Uniform1f(e,r.u_device_pixel_ratio),u_is_halo:new t.Uniform1i(e,r.u_is_halo)}},symbolTextAndIcon:function(e,r){return{u_is_size_zoom_constant:new t.Uniform1i(e,r.u_is_size_zoom_constant),u_is_size_feature_constant:new t.Uniform1i(e,r.u_is_size_feature_constant),u_size_t:new t.Uniform1f(e,r.u_size_t),u_size:new t.Uniform1f(e,r.u_size),u_camera_to_center_distance:new t.Uniform1f(e,r.u_camera_to_center_distance),u_pitch:new t.Uniform1f(e,r.u_pitch),u_rotate_symbol:new t.Uniform1i(e,r.u_rotate_symbol),u_aspect_ratio:new t.Uniform1f(e,r.u_aspect_ratio),u_fade_change:new t.Uniform1f(e,r.u_fade_change),u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_label_plane_matrix:new t.UniformMatrix4f(e,r.u_label_plane_matrix),u_coord_matrix:new t.UniformMatrix4f(e,r.u_coord_matrix),u_is_text:new t.Uniform1i(e,r.u_is_text),u_pitch_with_map:new t.Uniform1i(e,r.u_pitch_with_map),u_texsize:new t.Uniform2f(e,r.u_texsize),u_texsize_icon:new t.Uniform2f(e,r.u_texsize_icon),u_texture:new t.Uniform1i(e,r.u_texture),u_texture_icon:new t.Uniform1i(e,r.u_texture_icon),u_gamma_scale:new t.Uniform1f(e,r.u_gamma_scale),u_device_pixel_ratio:new t.Uniform1f(e,r.u_device_pixel_ratio),u_is_halo:new t.Uniform1i(e,r.u_is_halo)}},background:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_opacity:new t.Uniform1f(e,r.u_opacity),u_color:new t.UniformColor(e,r.u_color)}},backgroundPattern:function(e,r){return{u_matrix:new t.UniformMatrix4f(e,r.u_matrix),u_opacity:new t.Uniform1f(e,r.u_opacity),u_image:new t.Uniform1i(e,r.u_image),u_pattern_tl_a:new t.Uniform2f(e,r.u_pattern_tl_a),u_pattern_br_a:new t.Uniform2f(e,r.u_pattern_br_a),u_pattern_tl_b:new t.Uniform2f(e,r.u_pattern_tl_b),u_pattern_br_b:new t.Uniform2f(e,r.u_pattern_br_b),u_texsize:new t.Uniform2f(e,r.u_texsize),u_mix:new t.Uniform1f(e,r.u_mix),u_pattern_size_a:new t.Uniform2f(e,r.u_pattern_size_a),u_pattern_size_b:new t.Uniform2f(e,r.u_pattern_size_b),u_scale_a:new t.Uniform1f(e,r.u_scale_a),u_scale_b:new t.Uniform1f(e,r.u_scale_b),u_pixel_coord_upper:new t.Uniform2f(e,r.u_pixel_coord_upper),u_pixel_coord_lower:new t.Uniform2f(e,r.u_pixel_coord_lower),u_tile_units_to_pixels:new t.Uniform1f(e,r.u_tile_units_to_pixels)}}};function Kr(e,r,n,i,a,o,s){for(var l=e.context,c=l.gl,u=e.useProgram("collisionBox"),f=[],h=0,p=0,d=0;d<i.length;d++){var m=i[d],g=r.getTile(m),v=g.getBucket(n);if(v){var y=m.posMatrix;0===a[0]&&0===a[1]||(y=e.translatePosMatrix(m.posMatrix,g,a,o));var x=s?v.textCollisionBox:v.iconCollisionBox,b=v.collisionCircleArray;if(b.length>0){var _=t.create(),w=y;t.mul(_,v.placementInvProjMatrix,e.transform.glCoordMatrix),t.mul(_,_,v.placementViewportMatrix),f.push({circleArray:b,circleOffset:p,transform:w,invTransform:_}),p=h+=b.length/4}x&&u.draw(l,c.LINES,At.disabled,Mt.disabled,e.colorModeForRenderPass(),Et.disabled,Cr(y,e.transform,g),n.id,x.layoutVertexBuffer,x.indexBuffer,x.segments,null,e.transform.zoom,null,null,x.collisionVertexBuffer)}}if(s&&f.length){var T=e.useProgram("collisionCircle"),k=new t.StructArrayLayout2f1f2i16;k.resize(4*h),k._trim();for(var A=0,M=0,S=f;M<S.length;M+=1)for(var E=S[M],L=0;L<E.circleArray.length/4;L++){var C=4*L,P=E.circleArray[C+0],I=E.circleArray[C+1],O=E.circleArray[C+2],z=E.circleArray[C+3];k.emplace(A++,P,I,O,z,0),k.emplace(A++,P,I,O,z,1),k.emplace(A++,P,I,O,z,2),k.emplace(A++,P,I,O,z,3)}(!qr||qr.length<2*h)&&(qr=function(e){var r=2*e,n=new t.StructArrayLayout3ui6;n.resize(r),n._trim();for(var i=0;i<r;i++){var a=6*i;n.uint16[a+0]=4*i+0,n.uint16[a+1]=4*i+1,n.uint16[a+2]=4*i+2,n.uint16[a+3]=4*i+2,n.uint16[a+4]=4*i+3,n.uint16[a+5]=4*i+0}return n}(h));for(var D=l.createIndexBuffer(qr,!0),R=l.createVertexBuffer(k,t.collisionCircleLayout.members,!0),F=0,B=f;F<B.length;F+=1){var N=B[F],j=Pr(N.transform,N.invTransform,e.transform);T.draw(l,c.TRIANGLES,At.disabled,Mt.disabled,e.colorModeForRenderPass(),Et.disabled,j,n.id,R,D,t.SegmentVector.simpleSegment(0,2*N.circleOffset,N.circleArray.length,N.circleArray.length/2),null,e.transform.zoom,null,null,null)}R.destroy(),D.destroy()}}var Qr=t.identity(new Float32Array(16));function $r(e,r,n,i,a,o){var s=t.getAnchorAlignment(e),l=-(s.horizontalAlign-.5)*r,c=-(s.verticalAlign-.5)*n,u=t.evaluateVariableOffset(e,i);return new t.Point((l/a+u[0])*o,(c/a+u[1])*o)}function tn(e,r,n,i,a,o,s,l,c,u,f){var h=e.text.placedSymbolArray,p=e.text.dynamicLayoutVertexArray,d=e.icon.dynamicLayoutVertexArray,m={};p.clear();for(var g=0;g<h.length;g++){var v=h.get(g),y=e.allowVerticalPlacement&&!v.placedOrientation,x=v.hidden||!v.crossTileID||y?null:i[v.crossTileID];if(x){var b=new t.Point(v.anchorX,v.anchorY),_=te(b,n?l:s),w=ee(o.cameraToCenterDistance,_.signedDistanceFromCamera),T=a.evaluateSizeForFeature(e.textSizeData,u,v)*w/t.ONE_EM;n&&(T*=e.tilePixelRatio/c);for(var k=x.width,A=x.height,M=$r(x.anchor,k,A,x.textOffset,x.textBoxScale,T),S=n?te(b.add(M),s).point:_.point.add(r?M.rotate(-o.angle):M),E=e.allowVerticalPlacement&&v.placedOrientation===t.WritingMode.vertical?Math.PI/2:0,L=0;L<v.numGlyphs;L++)t.addDynamicAttributes(p,S,E);f&&v.associatedIconIndex>=0&&(m[v.associatedIconIndex]={shiftedAnchor:S,angle:E})}else ue(v.numGlyphs,p)}if(f){d.clear();for(var C=e.icon.placedSymbolArray,P=0;P<C.length;P++){var I=C.get(P);if(I.hidden)ue(I.numGlyphs,d);else{var O=m[P];if(O)for(var z=0;z<I.numGlyphs;z++)t.addDynamicAttributes(d,O.shiftedAnchor,O.angle);else ue(I.numGlyphs,d)}}e.icon.dynamicLayoutVertexBuffer.updateData(d)}e.text.dynamicLayoutVertexBuffer.updateData(p)}function en(t,e,r){return r.iconsInText&&e?"symbolTextAndIcon":t?"symbolSDF":"symbolIcon"}function rn(e,r,n,i,a,o,s,l,c,u,f,h){for(var p=e.context,d=p.gl,m=e.transform,g="map"===l,v="map"===c,y=g&&"point"!==n.layout.get("symbol-placement"),x=g&&!v&&!y,b=void 0!==n.layout.get("symbol-sort-key").constantOr(1),_=e.depthModeForSublayer(0,At.ReadOnly),w=n.layout.get("text-variable-anchor"),T=[],k=0,A=i;k<A.length;k+=1){var M=A[k],S=r.getTile(M),E=S.getBucket(n);if(E){var L=a?E.text:E.icon;if(L&&L.segments.get().length){var C=L.programConfigurations.get(n.id),P=a||E.sdfIcons,I=a?E.textSizeData:E.iconSizeData,O=v||0!==m.pitch,z=e.useProgram(en(P,a,E),C),D=t.evaluateSizeForZoom(I,m.zoom),R=void 0,F=[0,0],B=void 0,N=void 0,j=null,U=void 0;if(a){if(B=S.glyphAtlasTexture,N=d.LINEAR,R=S.glyphAtlasTexture.size,E.iconsInText){F=S.imageAtlasTexture.size,j=S.imageAtlasTexture;var V="composite"===I.kind||"camera"===I.kind;U=O||e.options.rotating||e.options.zooming||V?d.LINEAR:d.NEAREST}}else{var H=1!==n.layout.get("icon-size").constantOr(0)||E.iconsNeedLinear;B=S.imageAtlasTexture,N=P||e.options.rotating||e.options.zooming||H||O?d.LINEAR:d.NEAREST,R=S.imageAtlasTexture.size}var q=pe(S,1,e.transform.zoom),G=Qt(M.posMatrix,v,g,e.transform,q),Y=$t(M.posMatrix,v,g,e.transform,q),W=w&&E.hasTextData(),X="none"!==n.layout.get("icon-text-fit")&&W&&E.hasIconData();y&&ne(E,M.posMatrix,e,a,G,Y,v,u);var Z=e.translatePosMatrix(M.posMatrix,S,o,s),J=y||a&&w||X?Qr:G,K=e.translatePosMatrix(Y,S,o,s,!0),Q=P&&0!==n.paint.get(a?"text-halo-width":"icon-halo-width").constantOr(1),$={program:z,buffers:L,uniformValues:P?E.iconsInText?Wr(I.kind,D,x,v,e,Z,J,K,R,F):Yr(I.kind,D,x,v,e,Z,J,K,a,R,!0):Gr(I.kind,D,x,v,e,Z,J,K,a,R),atlasTexture:B,atlasTextureIcon:j,atlasInterpolation:N,atlasInterpolationIcon:U,isSDF:P,hasHalo:Q};if(b)for(var tt=0,et=L.segments.get();tt<et.length;tt+=1){var rt=et[tt];T.push({segments:new t.SegmentVector([rt]),sortKey:rt.sortKey,state:$})}else T.push({segments:L.segments,sortKey:0,state:$})}}}b&&T.sort((function(t,e){return t.sortKey-e.sortKey}));for(var nt=0,it=T;nt<it.length;nt+=1){var at=it[nt],ot=at.state;if(p.activeTexture.set(d.TEXTURE0),ot.atlasTexture.bind(ot.atlasInterpolation,d.CLAMP_TO_EDGE),ot.atlasTextureIcon&&(p.activeTexture.set(d.TEXTURE1),ot.atlasTextureIcon&&ot.atlasTextureIcon.bind(ot.atlasInterpolationIcon,d.CLAMP_TO_EDGE)),ot.isSDF){var st=ot.uniformValues;ot.hasHalo&&(st.u_is_halo=1,nn(ot.buffers,at.segments,n,e,ot.program,_,f,h,st)),st.u_is_halo=0}nn(ot.buffers,at.segments,n,e,ot.program,_,f,h,ot.uniformValues)}}function nn(t,e,r,n,i,a,o,s,l){var c=n.context,u=c.gl;i.draw(c,u.TRIANGLES,a,o,s,Et.disabled,l,r.id,t.layoutVertexBuffer,t.indexBuffer,e,r.paint,n.transform.zoom,t.programConfigurations.get(r.id),t.dynamicLayoutVertexBuffer,t.opacityVertexBuffer)}function an(t,e,r,n,i,a,o){var s,l,c,u,f,h=t.context.gl,p=r.paint.get("fill-pattern"),d=p&&p.constantOr(1),m=r.getCrossfadeParameters();o?(l=d&&!r.getPaintProperty("fill-outline-color")?"fillOutlinePattern":"fillOutline",s=h.LINES):(l=d?"fillPattern":"fill",s=h.TRIANGLES);for(var g=0,v=n;g<v.length;g+=1){var y=v[g],x=e.getTile(y);if(!d||x.patternsLoaded()){var b=x.getBucket(r);if(b){var _=b.programConfigurations.get(r.id),w=t.useProgram(l,_);d&&(t.context.activeTexture.set(h.TEXTURE0),x.imageAtlasTexture.bind(h.LINEAR,h.CLAMP_TO_EDGE),_.updatePaintBuffers(m));var T=p.constantOr(null);if(T&&x.imageAtlas){var k=x.imageAtlas,A=k.patternPositions[T.to.toString()],M=k.patternPositions[T.from.toString()];A&&M&&_.setConstantPatternPositions(A,M)}var S=t.translatePosMatrix(y.posMatrix,x,r.paint.get("fill-translate"),r.paint.get("fill-translate-anchor"));if(o){u=b.indexBuffer2,f=b.segments2;var E=[h.drawingBufferWidth,h.drawingBufferHeight];c="fillOutlinePattern"===l&&d?Er(S,t,m,x,E):Sr(S,E)}else u=b.indexBuffer,f=b.segments,c=d?Mr(S,t,m,x):Ar(S);w.draw(t.context,s,i,t.stencilModeForClipping(y),a,Et.disabled,c,r.id,b.layoutVertexBuffer,u,f,r.paint,t.transform.zoom,_)}}}}function on(t,e,r,n,i,a,o){for(var s=t.context,l=s.gl,c=r.paint.get("fill-extrusion-pattern"),u=c.constantOr(1),f=r.getCrossfadeParameters(),h=r.paint.get("fill-extrusion-opacity"),p=0,d=n;p<d.length;p+=1){var m=d[p],g=e.getTile(m),v=g.getBucket(r);if(v){var y=v.programConfigurations.get(r.id),x=t.useProgram(u?"fillExtrusionPattern":"fillExtrusion",y);u&&(t.context.activeTexture.set(l.TEXTURE0),g.imageAtlasTexture.bind(l.LINEAR,l.CLAMP_TO_EDGE),y.updatePaintBuffers(f));var b=c.constantOr(null);if(b&&g.imageAtlas){var _=g.imageAtlas,w=_.patternPositions[b.to.toString()],T=_.patternPositions[b.from.toString()];w&&T&&y.setConstantPatternPositions(w,T)}var k=t.translatePosMatrix(m.posMatrix,g,r.paint.get("fill-extrusion-translate"),r.paint.get("fill-extrusion-translate-anchor")),A=r.paint.get("fill-extrusion-vertical-gradient"),M=u?kr(k,t,A,h,m,f,g):Tr(k,t,A,h);x.draw(s,s.gl.TRIANGLES,i,a,o,Et.backCCW,M,r.id,v.layoutVertexBuffer,v.indexBuffer,v.segments,r.paint,t.transform.zoom,y)}}}function sn(t,e,r,n,i,a){var o=t.context,s=o.gl,l=e.fbo;if(l){var c=t.useProgram("hillshade");o.activeTexture.set(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,l.colorAttachment.get());var u=function(t,e,r){var n=r.paint.get("hillshade-shadow-color"),i=r.paint.get("hillshade-highlight-color"),a=r.paint.get("hillshade-accent-color"),o=r.paint.get("hillshade-illumination-direction")*(Math.PI/180);"viewport"===r.paint.get("hillshade-illumination-anchor")&&(o-=t.transform.angle);var s=!t.options.moving;return{u_matrix:t.transform.calculatePosMatrix(e.tileID.toUnwrapped(),s),u_image:0,u_latrange:Dr(t,e.tileID),u_light:[r.paint.get("hillshade-exaggeration"),o],u_shadow:n,u_highlight:i,u_accent:a}}(t,e,r);c.draw(o,s.TRIANGLES,n,i,a,Et.disabled,u,r.id,t.rasterBoundsBuffer,t.quadTriangleIndexBuffer,t.rasterBoundsSegments)}}function ln(e,r,n,i,a,o,s){var l=e.context,c=l.gl,u=r.dem;if(u&&u.data){var f=u.dim,h=u.stride,p=u.getPixels();if(l.activeTexture.set(c.TEXTURE1),l.pixelStoreUnpackPremultiplyAlpha.set(!1),r.demTexture=r.demTexture||e.getTileTexture(h),r.demTexture){var d=r.demTexture;d.update(p,{premultiply:!1}),d.bind(c.NEAREST,c.CLAMP_TO_EDGE)}else r.demTexture=new t.Texture(l,p,c.RGBA,{premultiply:!1}),r.demTexture.bind(c.NEAREST,c.CLAMP_TO_EDGE);l.activeTexture.set(c.TEXTURE0);var m=r.fbo;if(!m){var g=new t.Texture(l,{width:f,height:f,data:null},c.RGBA);g.bind(c.LINEAR,c.CLAMP_TO_EDGE),(m=r.fbo=l.createFramebuffer(f,f,!0)).colorAttachment.set(g.texture)}l.bindFramebuffer.set(m.framebuffer),l.viewport.set([0,0,f,f]),e.useProgram("hillshadePrepare").draw(l,c.TRIANGLES,a,o,s,Et.disabled,function(e,r,n){var i=r.stride,a=t.create();return t.ortho(a,0,t.EXTENT,-t.EXTENT,0,0,1),t.translate(a,a,[0,-t.EXTENT,0]),{u_matrix:a,u_image:1,u_dimension:[i,i],u_zoom:e.overscaledZ,u_maxzoom:n,u_unpack:r.getUnpackVector()}}(r.tileID,u,i),n.id,e.rasterBoundsBuffer,e.quadTriangleIndexBuffer,e.rasterBoundsSegments),r.needsHillshadePrepare=!1}}function cn(e,r,n,i,a){var o=i.paint.get("raster-fade-duration");if(o>0){var s=t.browser.now(),l=(s-e.timeAdded)/o,c=r?(s-r.timeAdded)/o:-1,u=n.getSource(),f=a.coveringZoomLevel({tileSize:u.tileSize,roundZoom:u.roundZoom}),h=!r||Math.abs(r.tileID.overscaledZ-f)>Math.abs(e.tileID.overscaledZ-f),p=h&&e.refreshedUponExpiration?1:t.clamp(h?l:1-c,0,1);return e.refreshedUponExpiration&&l>=1&&(e.refreshedUponExpiration=!1),r?{opacity:1,mix:1-p}:{opacity:p,mix:0}}return{opacity:1,mix:0}}var un=new t.Color(1,0,0,1),fn=new t.Color(0,1,0,1),hn=new t.Color(0,0,1,1),pn=new t.Color(1,0,1,1),dn=new t.Color(0,1,1,1);function mn(t){var e=t.transform.padding;gn(t,t.transform.height-(e.top||0),3,un),gn(t,e.bottom||0,3,fn),vn(t,e.left||0,3,hn),vn(t,t.transform.width-(e.right||0),3,pn);var r=t.transform.centerPoint;!function(t,e,r,n){yn(t,e-1,r-10,2,20,n),yn(t,e-10,r-1,20,2,n)}(t,r.x,t.transform.height-r.y,dn)}function gn(t,e,r,n){yn(t,0,e+r/2,t.transform.width,r,n)}function vn(t,e,r,n){yn(t,e-r/2,0,r,t.transform.height,n)}function yn(e,r,n,i,a,o){var s=e.context,l=s.gl;l.enable(l.SCISSOR_TEST),l.scissor(r*t.browser.devicePixelRatio,n*t.browser.devicePixelRatio,i*t.browser.devicePixelRatio,a*t.browser.devicePixelRatio),s.clear({color:o}),l.disable(l.SCISSOR_TEST)}function xn(e,r,n){var i=e.context,a=i.gl,o=n.posMatrix,s=e.useProgram("debug"),l=At.disabled,c=Mt.disabled,u=e.colorModeForRenderPass();i.activeTexture.set(a.TEXTURE0),e.emptyTexture.bind(a.LINEAR,a.CLAMP_TO_EDGE),s.draw(i,a.LINE_STRIP,l,c,u,Et.disabled,Ir(o,t.Color.red),"$debug",e.debugBuffer,e.tileBorderIndexBuffer,e.debugSegments);var f=r.getTileByID(n.key).latestRawTileData,h=f&&f.byteLength||0,p=Math.floor(h/1024),d=r.getTile(n).tileSize,m=512/Math.min(d,512)*(n.overscaledZ/e.transform.zoom)*.5,g=n.canonical.toString();n.overscaledZ!==n.canonical.z&&(g+=" => "+n.overscaledZ),function(t,e){t.initDebugOverlayCanvas();var r=t.debugOverlayCanvas,n=t.context.gl,i=t.debugOverlayCanvas.getContext("2d");i.clearRect(0,0,r.width,r.height),i.shadowColor="white",i.shadowBlur=2,i.lineWidth=1.5,i.strokeStyle="white",i.textBaseline="top",i.font="bold 36px Open Sans, sans-serif",i.fillText(e,5,5),i.strokeText(e,5,5),t.debugOverlayTexture.update(r),t.debugOverlayTexture.bind(n.LINEAR,n.CLAMP_TO_EDGE)}(e,g+" "+p+"kb"),s.draw(i,a.TRIANGLES,l,c,St.alphaBlended,Et.disabled,Ir(o,t.Color.transparent,m),"$debug",e.debugBuffer,e.quadTriangleIndexBuffer,e.debugSegments)}var bn={symbol:function(e,r,n,i,a){if("translucent"===e.renderPass){var o=Mt.disabled,s=e.colorModeForRenderPass();n.layout.get("text-variable-anchor")&&function(e,r,n,i,a,o,s){for(var l=r.transform,c="map"===a,u="map"===o,f=0,h=e;f<h.length;f+=1){var p=h[f],d=i.getTile(p),m=d.getBucket(n);if(m&&m.text&&m.text.segments.get().length){var g=m.textSizeData,v=t.evaluateSizeForZoom(g,l.zoom),y=pe(d,1,r.transform.zoom),x=Qt(p.posMatrix,u,c,r.transform,y),b="none"!==n.layout.get("icon-text-fit")&&m.hasIconData();if(v){var _=Math.pow(2,l.zoom-d.tileID.overscaledZ);tn(m,c,u,s,t.symbolSize,l,x,p.posMatrix,_,v,b)}}}}(i,e,n,r,n.layout.get("text-rotation-alignment"),n.layout.get("text-pitch-alignment"),a),0!==n.paint.get("icon-opacity").constantOr(1)&&rn(e,r,n,i,!1,n.paint.get("icon-translate"),n.paint.get("icon-translate-anchor"),n.layout.get("icon-rotation-alignment"),n.layout.get("icon-pitch-alignment"),n.layout.get("icon-keep-upright"),o,s),0!==n.paint.get("text-opacity").constantOr(1)&&rn(e,r,n,i,!0,n.paint.get("text-translate"),n.paint.get("text-translate-anchor"),n.layout.get("text-rotation-alignment"),n.layout.get("text-pitch-alignment"),n.layout.get("text-keep-upright"),o,s),r.map.showCollisionBoxes&&(Kr(e,r,n,i,n.paint.get("text-translate"),n.paint.get("text-translate-anchor"),!0),Kr(e,r,n,i,n.paint.get("icon-translate"),n.paint.get("icon-translate-anchor"),!1))}},circle:function(e,r,n,i){if("translucent"===e.renderPass){var a=n.paint.get("circle-opacity"),o=n.paint.get("circle-stroke-width"),s=n.paint.get("circle-stroke-opacity"),l=void 0!==n.layout.get("circle-sort-key").constantOr(1);if(0!==a.constantOr(1)||0!==o.constantOr(1)&&0!==s.constantOr(1)){for(var c=e.context,u=c.gl,f=e.depthModeForSublayer(0,At.ReadOnly),h=Mt.disabled,p=e.colorModeForRenderPass(),d=[],m=0;m<i.length;m++){var g=i[m],v=r.getTile(g),y=v.getBucket(n);if(y){var x=y.programConfigurations.get(n.id),b={programConfiguration:x,program:e.useProgram("circle",x),layoutVertexBuffer:y.layoutVertexBuffer,indexBuffer:y.indexBuffer,uniformValues:Lr(e,g,v,n)};if(l)for(var _=0,w=y.segments.get();_<w.length;_+=1){var T=w[_];d.push({segments:new t.SegmentVector([T]),sortKey:T.sortKey,state:b})}else d.push({segments:y.segments,sortKey:0,state:b})}}l&&d.sort((function(t,e){return t.sortKey-e.sortKey}));for(var k=0,A=d;k<A.length;k+=1){var M=A[k],S=M.state,E=S.programConfiguration,L=S.program,C=S.layoutVertexBuffer,P=S.indexBuffer,I=S.uniformValues,O=M.segments;L.draw(c,u.TRIANGLES,f,h,p,Et.disabled,I,n.id,C,P,O,n.paint,e.transform.zoom,E)}}}},heatmap:function(e,r,n,i){if(0!==n.paint.get("heatmap-opacity"))if("offscreen"===e.renderPass){var a=e.context,o=a.gl,s=Mt.disabled,l=new St([o.ONE,o.ONE],t.Color.transparent,[!0,!0,!0,!0]);!function(t,e,r){var n=t.gl;t.activeTexture.set(n.TEXTURE1),t.viewport.set([0,0,e.width/4,e.height/4]);var i=r.heatmapFbo;if(i)n.bindTexture(n.TEXTURE_2D,i.colorAttachment.get()),t.bindFramebuffer.set(i.framebuffer);else{var a=n.createTexture();n.bindTexture(n.TEXTURE_2D,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),i=r.heatmapFbo=t.createFramebuffer(e.width/4,e.height/4,!1),function(t,e,r,n){var i=t.gl,a=t.extRenderToTextureHalfFloat?t.extTextureHalfFloat.HALF_FLOAT_OES:i.UNSIGNED_BYTE;i.texImage2D(i.TEXTURE_2D,0,i.RGBA,e.width/4,e.height/4,0,i.RGBA,a,null),n.colorAttachment.set(r)}(t,e,a,i)}}(a,e,n),a.clear({color:t.Color.transparent});for(var c=0;c<i.length;c++){var u=i[c];if(!r.hasRenderableParent(u)){var f=r.getTile(u),h=f.getBucket(n);if(h){var p=h.programConfigurations.get(n.id),d=e.useProgram("heatmap",p),m=e.transform.zoom;d.draw(a,o.TRIANGLES,At.disabled,s,l,Et.disabled,zr(u.posMatrix,f,m,n.paint.get("heatmap-intensity")),n.id,h.layoutVertexBuffer,h.indexBuffer,h.segments,n.paint,e.transform.zoom,p)}}}a.viewport.set([0,0,e.width,e.height])}else"translucent"===e.renderPass&&(e.context.setColorMode(e.colorModeForRenderPass()),function(e,r){var n=e.context,i=n.gl,a=r.heatmapFbo;if(!a)return;n.activeTexture.set(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,a.colorAttachment.get()),n.activeTexture.set(i.TEXTURE1);var o=r.colorRampTexture;o||(o=r.colorRampTexture=new t.Texture(n,r.colorRamp,i.RGBA));o.bind(i.LINEAR,i.CLAMP_TO_EDGE),e.useProgram("heatmapTexture").draw(n,i.TRIANGLES,At.disabled,Mt.disabled,e.colorModeForRenderPass(),Et.disabled,function(e,r,n,i){var a=t.create();t.ortho(a,0,e.width,e.height,0,0,1);var o=e.context.gl;return{u_matrix:a,u_world:[o.drawingBufferWidth,o.drawingBufferHeight],u_image:n,u_color_ramp:i,u_opacity:r.paint.get("heatmap-opacity")}}(e,r,0,1),r.id,e.viewportBuffer,e.quadTriangleIndexBuffer,e.viewportSegments,r.paint,e.transform.zoom)}(e,n))},line:function(e,r,n,i){if("translucent"===e.renderPass){var a=n.paint.get("line-opacity"),o=n.paint.get("line-width");if(0!==a.constantOr(1)&&0!==o.constantOr(1)){var s=e.depthModeForSublayer(0,At.ReadOnly),l=e.colorModeForRenderPass(),c=n.paint.get("line-dasharray"),u=n.paint.get("line-pattern"),f=u.constantOr(1),h=n.paint.get("line-gradient"),p=n.getCrossfadeParameters(),d=f?"linePattern":c?"lineSDF":h?"lineGradient":"line",m=e.context,g=m.gl,v=!0;if(h){m.activeTexture.set(g.TEXTURE0);var y=n.gradientTexture;if(!n.gradient)return;y||(y=n.gradientTexture=new t.Texture(m,n.gradient,g.RGBA)),y.bind(g.LINEAR,g.CLAMP_TO_EDGE)}for(var x=0,b=i;x<b.length;x+=1){var _=b[x],w=r.getTile(_);if(!f||w.patternsLoaded()){var T=w.getBucket(n);if(T){var k=T.programConfigurations.get(n.id),A=e.context.program.get(),M=e.useProgram(d,k),S=v||M.program!==A,E=u.constantOr(null);if(E&&w.imageAtlas){var L=w.imageAtlas,C=L.patternPositions[E.to.toString()],P=L.patternPositions[E.from.toString()];C&&P&&k.setConstantPatternPositions(C,P)}var I=f?Br(e,w,n,p):c?Nr(e,w,n,c,p):h?Fr(e,w,n):Rr(e,w,n);f?(m.activeTexture.set(g.TEXTURE0),w.imageAtlasTexture.bind(g.LINEAR,g.CLAMP_TO_EDGE),k.updatePaintBuffers(p)):c&&(S||e.lineAtlas.dirty)&&(m.activeTexture.set(g.TEXTURE0),e.lineAtlas.bind(m)),M.draw(m,g.TRIANGLES,s,e.stencilModeForClipping(_),l,Et.disabled,I,n.id,T.layoutVertexBuffer,T.indexBuffer,T.segments,n.paint,e.transform.zoom,k),v=!1}}}}}},fill:function(e,r,n,i){var a=n.paint.get("fill-color"),o=n.paint.get("fill-opacity");if(0!==o.constantOr(1)){var s=e.colorModeForRenderPass(),l=n.paint.get("fill-pattern"),c=e.opaquePassEnabledForLayer()&&!l.constantOr(1)&&1===a.constantOr(t.Color.transparent).a&&1===o.constantOr(0)?"opaque":"translucent";if(e.renderPass===c){var u=e.depthModeForSublayer(1,"opaque"===e.renderPass?At.ReadWrite:At.ReadOnly);an(e,r,n,i,u,s,!1)}if("translucent"===e.renderPass&&n.paint.get("fill-antialias")){var f=e.depthModeForSublayer(n.getPaintProperty("fill-outline-color")?2:0,At.ReadOnly);an(e,r,n,i,f,s,!0)}}},"fill-extrusion":function(t,e,r,n){var i=r.paint.get("fill-extrusion-opacity");if(0!==i&&"translucent"===t.renderPass){var a=new At(t.context.gl.LEQUAL,At.ReadWrite,t.depthRangeFor3D);if(1!==i||r.paint.get("fill-extrusion-pattern").constantOr(1))on(t,e,r,n,a,Mt.disabled,St.disabled),on(t,e,r,n,a,t.stencilModeFor3D(),t.colorModeForRenderPass());else{var o=t.colorModeForRenderPass();on(t,e,r,n,a,Mt.disabled,o)}}},hillshade:function(t,e,r,n){if("offscreen"===t.renderPass||"translucent"===t.renderPass){for(var i=t.context,a=e.getSource().maxzoom,o=t.depthModeForSublayer(0,At.ReadOnly),s=t.colorModeForRenderPass(),l="translucent"===t.renderPass?t.stencilConfigForOverlap(n):[{},n],c=l[0],u=0,f=l[1];u<f.length;u+=1){var h=f[u],p=e.getTile(h);p.needsHillshadePrepare&&"offscreen"===t.renderPass?ln(t,p,r,a,o,Mt.disabled,s):"translucent"===t.renderPass&&sn(t,p,r,o,c[h.overscaledZ],s)}i.viewport.set([0,0,t.width,t.height])}},raster:function(t,e,r,n){if("translucent"===t.renderPass&&0!==r.paint.get("raster-opacity")&&n.length)for(var i=t.context,a=i.gl,o=e.getSource(),s=t.useProgram("raster"),l=t.colorModeForRenderPass(),c=o instanceof I?[{},n]:t.stencilConfigForOverlap(n),u=c[0],f=c[1],h=f[f.length-1].overscaledZ,p=!t.options.moving,d=0,m=f;d<m.length;d+=1){var g=m[d],v=t.depthModeForSublayer(g.overscaledZ-h,1===r.paint.get("raster-opacity")?At.ReadWrite:At.ReadOnly,a.LESS),y=e.getTile(g),x=t.transform.calculatePosMatrix(g.toUnwrapped(),p);y.registerFadeDuration(r.paint.get("raster-fade-duration"));var b=e.findLoadedParent(g,0),_=cn(y,b,e,r,t.transform),w=void 0,T=void 0,k="nearest"===r.paint.get("raster-resampling")?a.NEAREST:a.LINEAR;i.activeTexture.set(a.TEXTURE0),y.texture.bind(k,a.CLAMP_TO_EDGE,a.LINEAR_MIPMAP_NEAREST),i.activeTexture.set(a.TEXTURE1),b?(b.texture.bind(k,a.CLAMP_TO_EDGE,a.LINEAR_MIPMAP_NEAREST),w=Math.pow(2,b.tileID.overscaledZ-y.tileID.overscaledZ),T=[y.tileID.canonical.x*w%1,y.tileID.canonical.y*w%1]):y.texture.bind(k,a.CLAMP_TO_EDGE,a.LINEAR_MIPMAP_NEAREST);var A=Vr(x,T||[0,0],w||1,_,r);o instanceof I?s.draw(i,a.TRIANGLES,v,Mt.disabled,l,Et.disabled,A,r.id,o.boundsBuffer,t.quadTriangleIndexBuffer,o.boundsSegments):s.draw(i,a.TRIANGLES,v,u[g.overscaledZ],l,Et.disabled,A,r.id,t.rasterBoundsBuffer,t.quadTriangleIndexBuffer,t.rasterBoundsSegments)}},background:function(t,e,r){var n=r.paint.get("background-color"),i=r.paint.get("background-opacity");if(0!==i){var a=t.context,o=a.gl,s=t.transform,l=s.tileSize,c=r.paint.get("background-pattern");if(!t.isPatternMissing(c)){var u=!c&&1===n.a&&1===i&&t.opaquePassEnabledForLayer()?"opaque":"translucent";if(t.renderPass===u){var f=Mt.disabled,h=t.depthModeForSublayer(0,"opaque"===u?At.ReadWrite:At.ReadOnly),p=t.colorModeForRenderPass(),d=t.useProgram(c?"backgroundPattern":"background"),m=s.coveringTiles({tileSize:l});c&&(a.activeTexture.set(o.TEXTURE0),t.imageManager.bind(t.context));for(var g=r.getCrossfadeParameters(),v=0,y=m;v<y.length;v+=1){var x=y[v],b=t.transform.calculatePosMatrix(x.toUnwrapped()),_=c?Zr(b,i,t,c,{tileID:x,tileSize:l},g):Xr(b,i,n);d.draw(a,o.TRIANGLES,h,f,p,Et.disabled,_,r.id,t.tileExtentBuffer,t.quadTriangleIndexBuffer,t.tileExtentSegments)}}}}},debug:function(t,e,r){for(var n=0;n<r.length;n++)xn(t,e,r[n])},custom:function(t,e,r){var n=t.context,i=r.implementation;if("offscreen"===t.renderPass){var a=i.prerender;a&&(t.setCustomLayerDefaults(),n.setColorMode(t.colorModeForRenderPass()),a.call(i,n.gl,t.transform.customLayerMatrix()),n.setDirty(),t.setBaseState())}else if("translucent"===t.renderPass){t.setCustomLayerDefaults(),n.setColorMode(t.colorModeForRenderPass()),n.setStencilMode(Mt.disabled);var o="3d"===i.renderingMode?new At(t.context.gl.LEQUAL,At.ReadWrite,t.depthRangeFor3D):t.depthModeForSublayer(0,At.ReadOnly);n.setDepthMode(o),i.render(n.gl,t.transform.customLayerMatrix()),n.setDirty(),t.setBaseState(),n.bindFramebuffer.set(null)}}},_n=function(t,e){this.context=new Lt(t),this.transform=e,this._tileTextures={},this.setup(),this.numSublayers=Ct.maxUnderzooming+Ct.maxOverzooming+1,this.depthEpsilon=1/Math.pow(2,16),this.crossTileSymbolIndex=new Ne,this.gpuTimers={}};_n.prototype.resize=function(e,r){if(this.width=e*t.browser.devicePixelRatio,this.height=r*t.browser.devicePixelRatio,this.context.viewport.set([0,0,this.width,this.height]),this.style)for(var n=0,i=this.style._order;n<i.length;n+=1){var a=i[n];this.style._layers[a].resize()}},_n.prototype.setup=function(){var e=this.context,r=new t.StructArrayLayout2i4;r.emplaceBack(0,0),r.emplaceBack(t.EXTENT,0),r.emplaceBack(0,t.EXTENT),r.emplaceBack(t.EXTENT,t.EXTENT),this.tileExtentBuffer=e.createVertexBuffer(r,Ge.members),this.tileExtentSegments=t.SegmentVector.simpleSegment(0,0,4,2);var n=new t.StructArrayLayout2i4;n.emplaceBack(0,0),n.emplaceBack(t.EXTENT,0),n.emplaceBack(0,t.EXTENT),n.emplaceBack(t.EXTENT,t.EXTENT),this.debugBuffer=e.createVertexBuffer(n,Ge.members),this.debugSegments=t.SegmentVector.simpleSegment(0,0,4,5);var i=new t.StructArrayLayout4i8;i.emplaceBack(0,0,0,0),i.emplaceBack(t.EXTENT,0,t.EXTENT,0),i.emplaceBack(0,t.EXTENT,0,t.EXTENT),i.emplaceBack(t.EXTENT,t.EXTENT,t.EXTENT,t.EXTENT),this.rasterBoundsBuffer=e.createVertexBuffer(i,P.members),this.rasterBoundsSegments=t.SegmentVector.simpleSegment(0,0,4,2);var a=new t.StructArrayLayout2i4;a.emplaceBack(0,0),a.emplaceBack(1,0),a.emplaceBack(0,1),a.emplaceBack(1,1),this.viewportBuffer=e.createVertexBuffer(a,Ge.members),this.viewportSegments=t.SegmentVector.simpleSegment(0,0,4,2);var o=new t.StructArrayLayout1ui2;o.emplaceBack(0),o.emplaceBack(1),o.emplaceBack(3),o.emplaceBack(2),o.emplaceBack(0),this.tileBorderIndexBuffer=e.createIndexBuffer(o);var s=new t.StructArrayLayout3ui6;s.emplaceBack(0,1,2),s.emplaceBack(2,1,3),this.quadTriangleIndexBuffer=e.createIndexBuffer(s),this.emptyTexture=new t.Texture(e,{width:1,height:1,data:new Uint8Array([0,0,0,0])},e.gl.RGBA);var l=this.context.gl;this.stencilClearMode=new Mt({func:l.ALWAYS,mask:0},0,255,l.ZERO,l.ZERO,l.ZERO)},_n.prototype.clearStencil=function(){var e=this.context,r=e.gl;this.nextStencilID=1,this.currentStencilSource=void 0;var n=t.create();t.ortho(n,0,this.width,this.height,0,0,1),t.scale(n,n,[r.drawingBufferWidth,r.drawingBufferHeight,0]),this.useProgram("clippingMask").draw(e,r.TRIANGLES,At.disabled,this.stencilClearMode,St.disabled,Et.disabled,Or(n),"$clipping",this.viewportBuffer,this.quadTriangleIndexBuffer,this.viewportSegments)},_n.prototype._renderTileClippingMasks=function(t,e){if(this.currentStencilSource!==t.source&&t.isTileClipped()&&e&&e.length){this.currentStencilSource=t.source;var r=this.context,n=r.gl;this.nextStencilID+e.length>256&&this.clearStencil(),r.setColorMode(St.disabled),r.setDepthMode(At.disabled);var i=this.useProgram("clippingMask");this._tileClippingMaskIDs={};for(var a=0,o=e;a<o.length;a+=1){var s=o[a],l=this._tileClippingMaskIDs[s.key]=this.nextStencilID++;i.draw(r,n.TRIANGLES,At.disabled,new Mt({func:n.ALWAYS,mask:0},l,255,n.KEEP,n.KEEP,n.REPLACE),St.disabled,Et.disabled,Or(s.posMatrix),"$clipping",this.tileExtentBuffer,this.quadTriangleIndexBuffer,this.tileExtentSegments)}}},_n.prototype.stencilModeFor3D=function(){this.currentStencilSource=void 0,this.nextStencilID+1>256&&this.clearStencil();var t=this.nextStencilID++,e=this.context.gl;return new Mt({func:e.NOTEQUAL,mask:255},t,255,e.KEEP,e.KEEP,e.REPLACE)},_n.prototype.stencilModeForClipping=function(t){var e=this.context.gl;return new Mt({func:e.EQUAL,mask:255},this._tileClippingMaskIDs[t.key],0,e.KEEP,e.KEEP,e.REPLACE)},_n.prototype.stencilConfigForOverlap=function(t){var e,r=this.context.gl,n=t.sort((function(t,e){return e.overscaledZ-t.overscaledZ})),i=n[n.length-1].overscaledZ,a=n[0].overscaledZ-i+1;if(a>1){this.currentStencilSource=void 0,this.nextStencilID+a>256&&this.clearStencil();for(var o={},s=0;s<a;s++)o[s+i]=new Mt({func:r.GEQUAL,mask:255},s+this.nextStencilID,255,r.KEEP,r.KEEP,r.REPLACE);return this.nextStencilID+=a,[o,n]}return[(e={},e[i]=Mt.disabled,e),n]},_n.prototype.colorModeForRenderPass=function(){var e=this.context.gl;if(this._showOverdrawInspector){return new St([e.CONSTANT_COLOR,e.ONE],new t.Color(1/8,1/8,1/8,0),[!0,!0,!0,!0])}return"opaque"===this.renderPass?St.unblended:St.alphaBlended},_n.prototype.depthModeForSublayer=function(t,e,r){if(!this.opaquePassEnabledForLayer())return At.disabled;var n=1-((1+this.currentLayer)*this.numSublayers+t)*this.depthEpsilon;return new At(r||this.context.gl.LEQUAL,e,[n,n])},_n.prototype.opaquePassEnabledForLayer=function(){return this.currentLayer<this.opaquePassCutoff},_n.prototype.render=function(e,r){var n=this;this.style=e,this.options=r,this.lineAtlas=e.lineAtlas,this.imageManager=e.imageManager,this.glyphManager=e.glyphManager,this.symbolFadeChange=e.placement.symbolFadeChange(t.browser.now()),this.imageManager.beginFrame();var i=this.style._order,a=this.style.sourceCaches;for(var o in a){var s=a[o];s.used&&s.prepare(this.context)}var l,c,u={},f={},h={};for(var p in a){var d=a[p];u[p]=d.getVisibleCoordinates(),f[p]=u[p].slice().reverse(),h[p]=d.getVisibleCoordinates(!0).reverse()}this.opaquePassCutoff=1/0;for(var m=0;m<i.length;m++){var g=i[m];if(this.style._layers[g].is3D()){this.opaquePassCutoff=m;break}}this.renderPass="offscreen";for(var v=0,y=i;v<y.length;v+=1){var x=y[v],b=this.style._layers[x];if(b.hasOffscreenPass()&&!b.isHidden(this.transform.zoom)){var _=f[b.source];("custom"===b.type||_.length)&&this.renderLayer(this,a[b.source],b,_)}}for(this.context.bindFramebuffer.set(null),this.context.clear({color:r.showOverdrawInspector?t.Color.black:t.Color.transparent,depth:1}),this.clearStencil(),this._showOverdrawInspector=r.showOverdrawInspector,this.depthRangeFor3D=[0,1-(e._order.length+2)*this.numSublayers*this.depthEpsilon],this.renderPass="opaque",this.currentLayer=i.length-1;this.currentLayer>=0;this.currentLayer--){var w=this.style._layers[i[this.currentLayer]],T=a[w.source],k=u[w.source];this._renderTileClippingMasks(w,k),this.renderLayer(this,T,w,k)}for(this.renderPass="translucent",this.currentLayer=0;this.currentLayer<i.length;this.currentLayer++){var A=this.style._layers[i[this.currentLayer]],M=a[A.source],S=("symbol"===A.type?h:f)[A.source];this._renderTileClippingMasks(A,u[A.source]),this.renderLayer(this,M,A,S)}this.options.showTileBoundaries&&(t.values(this.style._layers).forEach((function(t){t.source&&!t.isHidden(n.transform.zoom)&&(t.source!==(c&&c.id)&&(c=n.style.sourceCaches[t.source]),(!l||l.getSource().maxzoom<c.getSource().maxzoom)&&(l=c))})),l&&bn.debug(this,l,l.getVisibleCoordinates()));this.options.showPadding&&mn(this),this.context.setDefault()},_n.prototype.renderLayer=function(t,e,r,n){r.isHidden(this.transform.zoom)||("background"===r.type||"custom"===r.type||n.length)&&(this.id=r.id,this.gpuTimingStart(r),bn[r.type](t,e,r,n,this.style.placement.variableOffsets),this.gpuTimingEnd())},_n.prototype.gpuTimingStart=function(t){if(this.options.gpuTiming){var e=this.context.extTimerQuery,r=this.gpuTimers[t.id];r||(r=this.gpuTimers[t.id]={calls:0,cpuTime:0,query:e.createQueryEXT()}),r.calls++,e.beginQueryEXT(e.TIME_ELAPSED_EXT,r.query)}},_n.prototype.gpuTimingEnd=function(){if(this.options.gpuTiming){var t=this.context.extTimerQuery;t.endQueryEXT(t.TIME_ELAPSED_EXT)}},_n.prototype.collectGpuTimers=function(){var t=this.gpuTimers;return this.gpuTimers={},t},_n.prototype.queryGpuTimers=function(t){var e={};for(var r in t){var n=t[r],i=this.context.extTimerQuery,a=i.getQueryObjectEXT(n.query,i.QUERY_RESULT_EXT)/1e6;i.deleteQueryEXT(n.query),e[r]=a}return e},_n.prototype.translatePosMatrix=function(e,r,n,i,a){if(!n[0]&&!n[1])return e;var o=a?"map"===i?this.transform.angle:0:"viewport"===i?-this.transform.angle:0;if(o){var s=Math.sin(o),l=Math.cos(o);n=[n[0]*l-n[1]*s,n[0]*s+n[1]*l]}var c=[a?n[0]:pe(r,n[0],this.transform.zoom),a?n[1]:pe(r,n[1],this.transform.zoom),0],u=new Float32Array(16);return t.translate(u,e,c),u},_n.prototype.saveTileTexture=function(t){var e=this._tileTextures[t.size[0]];e?e.push(t):this._tileTextures[t.size[0]]=[t]},_n.prototype.getTileTexture=function(t){var e=this._tileTextures[t];return e&&e.length>0?e.pop():null},_n.prototype.isPatternMissing=function(t){if(!t)return!1;if(!t.from||!t.to)return!0;var e=this.imageManager.getPattern(t.from.toString()),r=this.imageManager.getPattern(t.to.toString());return!e||!r},_n.prototype.useProgram=function(t,e){this.cache=this.cache||{};var r=""+t+(e?e.cacheKey:"")+(this._showOverdrawInspector?"/overdraw":"");return this.cache[r]||(this.cache[r]=new _r(this.context,xr[t],e,Jr[t],this._showOverdrawInspector)),this.cache[r]},_n.prototype.setCustomLayerDefaults=function(){this.context.unbindVAO(),this.context.cullFace.setDefault(),this.context.activeTexture.setDefault(),this.context.pixelStoreUnpack.setDefault(),this.context.pixelStoreUnpackPremultiplyAlpha.setDefault(),this.context.pixelStoreUnpackFlipY.setDefault()},_n.prototype.setBaseState=function(){var t=this.context.gl;this.context.cullFace.set(!1),this.context.viewport.set([0,0,this.width,this.height]),this.context.blendEquation.set(t.FUNC_ADD)},_n.prototype.initDebugOverlayCanvas=function(){if(null==this.debugOverlayCanvas){this.debugOverlayCanvas=t.window.document.createElement("canvas"),this.debugOverlayCanvas.width=512,this.debugOverlayCanvas.height=512;var e=this.context.gl;this.debugOverlayTexture=new t.Texture(this.context,this.debugOverlayCanvas,e.RGBA)}},_n.prototype.destroy=function(){this.emptyTexture.destroy(),this.debugOverlayTexture&&this.debugOverlayTexture.destroy()};var wn=function(t,e){this.points=t,this.planes=e};wn.fromInvProjectionMatrix=function(e,r,n){var i=Math.pow(2,n),a=[[-1,1,-1,1],[1,1,-1,1],[1,-1,-1,1],[-1,-1,-1,1],[-1,1,1,1],[1,1,1,1],[1,-1,1,1],[-1,-1,1,1]].map((function(r){return t.transformMat4([],r,e)})).map((function(e){return t.scale$1([],e,1/e[3]/r*i)})),o=[[0,1,2],[6,5,4],[0,3,7],[2,1,5],[3,2,6],[0,4,5]].map((function(e){var r=t.sub([],a[e[0]],a[e[1]]),n=t.sub([],a[e[2]],a[e[1]]),i=t.normalize([],t.cross([],r,n)),o=-t.dot(i,a[e[1]]);return i.concat(o)}));return new wn(a,o)};var Tn=function(e,r){this.min=e,this.max=r,this.center=t.scale$2([],t.add([],this.min,this.max),.5)};Tn.prototype.quadrant=function(e){for(var r=[e%2==0,e<2],n=t.clone$2(this.min),i=t.clone$2(this.max),a=0;a<r.length;a++)n[a]=r[a]?this.min[a]:this.center[a],i[a]=r[a]?this.center[a]:this.max[a];return i[2]=this.max[2],new Tn(n,i)},Tn.prototype.distanceX=function(t){return Math.max(Math.min(this.max[0],t[0]),this.min[0])-t[0]},Tn.prototype.distanceY=function(t){return Math.max(Math.min(this.max[1],t[1]),this.min[1])-t[1]},Tn.prototype.intersects=function(e){for(var r=[[this.min[0],this.min[1],0,1],[this.max[0],this.min[1],0,1],[this.max[0],this.max[1],0,1],[this.min[0],this.max[1],0,1]],n=!0,i=0;i<e.planes.length;i++){for(var a=e.planes[i],o=0,s=0;s<r.length;s++)o+=t.dot$1(a,r[s])>=0;if(0===o)return 0;o!==r.length&&(n=!1)}if(n)return 2;for(var l=0;l<3;l++){for(var c=Number.MAX_VALUE,u=-Number.MAX_VALUE,f=0;f<e.points.length;f++){var h=e.points[f][l]-this.min[l];c=Math.min(c,h),u=Math.max(u,h)}if(u<0||c>this.max[l]-this.min[l])return 0}return 1};var kn=function(t,e,r,n){if(void 0===t&&(t=0),void 0===e&&(e=0),void 0===r&&(r=0),void 0===n&&(n=0),isNaN(t)||t<0||isNaN(e)||e<0||isNaN(r)||r<0||isNaN(n)||n<0)throw new Error("Invalid value for edge-insets, top, bottom, left and right must all be numbers");this.top=t,this.bottom=e,this.left=r,this.right=n};kn.prototype.interpolate=function(e,r,n){return null!=r.top&&null!=e.top&&(this.top=t.number(e.top,r.top,n)),null!=r.bottom&&null!=e.bottom&&(this.bottom=t.number(e.bottom,r.bottom,n)),null!=r.left&&null!=e.left&&(this.left=t.number(e.left,r.left,n)),null!=r.right&&null!=e.right&&(this.right=t.number(e.right,r.right,n)),this},kn.prototype.getCenter=function(e,r){var n=t.clamp((this.left+e-this.right)/2,0,e),i=t.clamp((this.top+r-this.bottom)/2,0,r);return new t.Point(n,i)},kn.prototype.equals=function(t){return this.top===t.top&&this.bottom===t.bottom&&this.left===t.left&&this.right===t.right},kn.prototype.clone=function(){return new kn(this.top,this.bottom,this.left,this.right)},kn.prototype.toJSON=function(){return{top:this.top,bottom:this.bottom,left:this.left,right:this.right}};var An=function(e,r,n,i,a){this.tileSize=512,this.maxValidLatitude=85.051129,this._renderWorldCopies=void 0===a||a,this._minZoom=e||0,this._maxZoom=r||22,this._minPitch=null==n?0:n,this._maxPitch=null==i?60:i,this.setMaxBounds(),this.width=0,this.height=0,this._center=new t.LngLat(0,0),this.zoom=0,this.angle=0,this._fov=.6435011087932844,this._pitch=0,this._unmodified=!0,this._edgeInsets=new kn,this._posMatrixCache={},this._alignedPosMatrixCache={}},Mn={minZoom:{configurable:!0},maxZoom:{configurable:!0},minPitch:{configurable:!0},maxPitch:{configurable:!0},renderWorldCopies:{configurable:!0},worldSize:{configurable:!0},centerOffset:{configurable:!0},size:{configurable:!0},bearing:{configurable:!0},pitch:{configurable:!0},fov:{configurable:!0},zoom:{configurable:!0},center:{configurable:!0},padding:{configurable:!0},centerPoint:{configurable:!0},unmodified:{configurable:!0},point:{configurable:!0}};An.prototype.clone=function(){var t=new An(this._minZoom,this._maxZoom,this._minPitch,this.maxPitch,this._renderWorldCopies);return t.tileSize=this.tileSize,t.latRange=this.latRange,t.width=this.width,t.height=this.height,t._center=this._center,t.zoom=this.zoom,t.angle=this.angle,t._fov=this._fov,t._pitch=this._pitch,t._unmodified=this._unmodified,t._edgeInsets=this._edgeInsets.clone(),t._calcMatrices(),t},Mn.minZoom.get=function(){return this._minZoom},Mn.minZoom.set=function(t){this._minZoom!==t&&(this._minZoom=t,this.zoom=Math.max(this.zoom,t))},Mn.maxZoom.get=function(){return this._maxZoom},Mn.maxZoom.set=function(t){this._maxZoom!==t&&(this._maxZoom=t,this.zoom=Math.min(this.zoom,t))},Mn.minPitch.get=function(){return this._minPitch},Mn.minPitch.set=function(t){this._minPitch!==t&&(this._minPitch=t,this.pitch=Math.max(this.pitch,t))},Mn.maxPitch.get=function(){return this._maxPitch},Mn.maxPitch.set=function(t){this._maxPitch!==t&&(this._maxPitch=t,this.pitch=Math.min(this.pitch,t))},Mn.renderWorldCopies.get=function(){return this._renderWorldCopies},Mn.renderWorldCopies.set=function(t){void 0===t?t=!0:null===t&&(t=!1),this._renderWorldCopies=t},Mn.worldSize.get=function(){return this.tileSize*this.scale},Mn.centerOffset.get=function(){return this.centerPoint._sub(this.size._div(2))},Mn.size.get=function(){return new t.Point(this.width,this.height)},Mn.bearing.get=function(){return-this.angle/Math.PI*180},Mn.bearing.set=function(e){var r=-t.wrap(e,-180,180)*Math.PI/180;this.angle!==r&&(this._unmodified=!1,this.angle=r,this._calcMatrices(),this.rotationMatrix=t.create$2(),t.rotate(this.rotationMatrix,this.rotationMatrix,this.angle))},Mn.pitch.get=function(){return this._pitch/Math.PI*180},Mn.pitch.set=function(e){var r=t.clamp(e,this.minPitch,this.maxPitch)/180*Math.PI;this._pitch!==r&&(this._unmodified=!1,this._pitch=r,this._calcMatrices())},Mn.fov.get=function(){return this._fov/Math.PI*180},Mn.fov.set=function(t){t=Math.max(.01,Math.min(60,t)),this._fov!==t&&(this._unmodified=!1,this._fov=t/180*Math.PI,this._calcMatrices())},Mn.zoom.get=function(){return this._zoom},Mn.zoom.set=function(t){var e=Math.min(Math.max(t,this.minZoom),this.maxZoom);this._zoom!==e&&(this._unmodified=!1,this._zoom=e,this.scale=this.zoomScale(e),this.tileZoom=Math.floor(e),this.zoomFraction=e-this.tileZoom,this._constrain(),this._calcMatrices())},Mn.center.get=function(){return this._center},Mn.center.set=function(t){t.lat===this._center.lat&&t.lng===this._center.lng||(this._unmodified=!1,this._center=t,this._constrain(),this._calcMatrices())},Mn.padding.get=function(){return this._edgeInsets.toJSON()},Mn.padding.set=function(t){this._edgeInsets.equals(t)||(this._unmodified=!1,this._edgeInsets.interpolate(this._edgeInsets,t,1),this._calcMatrices())},Mn.centerPoint.get=function(){return this._edgeInsets.getCenter(this.width,this.height)},An.prototype.isPaddingEqual=function(t){return this._edgeInsets.equals(t)},An.prototype.interpolatePadding=function(t,e,r){this._unmodified=!1,this._edgeInsets.interpolate(t,e,r),this._constrain(),this._calcMatrices()},An.prototype.coveringZoomLevel=function(t){var e=(t.roundZoom?Math.round:Math.floor)(this.zoom+this.scaleZoom(this.tileSize/t.tileSize));return Math.max(0,e)},An.prototype.getVisibleUnwrappedCoordinates=function(e){var r=[new t.UnwrappedTileID(0,e)];if(this._renderWorldCopies)for(var n=this.pointCoordinate(new t.Point(0,0)),i=this.pointCoordinate(new t.Point(this.width,0)),a=this.pointCoordinate(new t.Point(this.width,this.height)),o=this.pointCoordinate(new t.Point(0,this.height)),s=Math.floor(Math.min(n.x,i.x,a.x,o.x)),l=Math.floor(Math.max(n.x,i.x,a.x,o.x)),c=s-1;c<=l+1;c++)0!==c&&r.push(new t.UnwrappedTileID(c,e));return r},An.prototype.coveringTiles=function(e){var r=this.coveringZoomLevel(e),n=r;if(void 0!==e.minzoom&&r<e.minzoom)return[];void 0!==e.maxzoom&&r>e.maxzoom&&(r=e.maxzoom);var i=t.MercatorCoordinate.fromLngLat(this.center),a=Math.pow(2,r),o=[a*i.x,a*i.y,0],s=wn.fromInvProjectionMatrix(this.invProjMatrix,this.worldSize,r),l=e.minzoom||0;this.pitch<=60&&this._edgeInsets.top<.1&&(l=r);var c=function(t){return{aabb:new Tn([t*a,0,0],[(t+1)*a,a,0]),zoom:0,x:0,y:0,wrap:t,fullyVisible:!1}},u=[],f=[],h=r,p=e.reparseOverscaled?n:r;if(this._renderWorldCopies)for(var d=1;d<=3;d++)u.push(c(-d)),u.push(c(d));for(u.push(c(0));u.length>0;){var m=u.pop(),g=m.x,v=m.y,y=m.fullyVisible;if(!y){var x=m.aabb.intersects(s);if(0===x)continue;y=2===x}var b=m.aabb.distanceX(o),_=m.aabb.distanceY(o),w=Math.max(Math.abs(b),Math.abs(_)),T=3+(1<<h-m.zoom)-2;if(m.zoom===h||w>T&&m.zoom>=l)f.push({tileID:new t.OverscaledTileID(m.zoom===h?p:m.zoom,m.wrap,m.zoom,g,v),distanceSq:t.sqrLen([o[0]-.5-g,o[1]-.5-v])});else for(var k=0;k<4;k++){var A=(g<<1)+k%2,M=(v<<1)+(k>>1);u.push({aabb:m.aabb.quadrant(k),zoom:m.zoom+1,x:A,y:M,wrap:m.wrap,fullyVisible:y})}}return f.sort((function(t,e){return t.distanceSq-e.distanceSq})).map((function(t){return t.tileID}))},An.prototype.resize=function(t,e){this.width=t,this.height=e,this.pixelsToGLUnits=[2/t,-2/e],this._constrain(),this._calcMatrices()},Mn.unmodified.get=function(){return this._unmodified},An.prototype.zoomScale=function(t){return Math.pow(2,t)},An.prototype.scaleZoom=function(t){return Math.log(t)/Math.LN2},An.prototype.project=function(e){var r=t.clamp(e.lat,-this.maxValidLatitude,this.maxValidLatitude);return new t.Point(t.mercatorXfromLng(e.lng)*this.worldSize,t.mercatorYfromLat(r)*this.worldSize)},An.prototype.unproject=function(e){return new t.MercatorCoordinate(e.x/this.worldSize,e.y/this.worldSize).toLngLat()},Mn.point.get=function(){return this.project(this.center)},An.prototype.setLocationAtPoint=function(e,r){var n=this.pointCoordinate(r),i=this.pointCoordinate(this.centerPoint),a=this.locationCoordinate(e),o=new t.MercatorCoordinate(a.x-(n.x-i.x),a.y-(n.y-i.y));this.center=this.coordinateLocation(o),this._renderWorldCopies&&(this.center=this.center.wrap())},An.prototype.locationPoint=function(t){return this.coordinatePoint(this.locationCoordinate(t))},An.prototype.pointLocation=function(t){return this.coordinateLocation(this.pointCoordinate(t))},An.prototype.locationCoordinate=function(e){return t.MercatorCoordinate.fromLngLat(e)},An.prototype.coordinateLocation=function(t){return t.toLngLat()},An.prototype.pointCoordinate=function(e){var r=[e.x,e.y,0,1],n=[e.x,e.y,1,1];t.transformMat4(r,r,this.pixelMatrixInverse),t.transformMat4(n,n,this.pixelMatrixInverse);var i=r[3],a=n[3],o=r[0]/i,s=n[0]/a,l=r[1]/i,c=n[1]/a,u=r[2]/i,f=n[2]/a,h=u===f?0:(0-u)/(f-u);return new t.MercatorCoordinate(t.number(o,s,h)/this.worldSize,t.number(l,c,h)/this.worldSize)},An.prototype.coordinatePoint=function(e){var r=[e.x*this.worldSize,e.y*this.worldSize,0,1];return t.transformMat4(r,r,this.pixelMatrix),new t.Point(r[0]/r[3],r[1]/r[3])},An.prototype.getBounds=function(){return(new t.LngLatBounds).extend(this.pointLocation(new t.Point(0,0))).extend(this.pointLocation(new t.Point(this.width,0))).extend(this.pointLocation(new t.Point(this.width,this.height))).extend(this.pointLocation(new t.Point(0,this.height)))},An.prototype.getMaxBounds=function(){return this.latRange&&2===this.latRange.length&&this.lngRange&&2===this.lngRange.length?new t.LngLatBounds([this.lngRange[0],this.latRange[0]],[this.lngRange[1],this.latRange[1]]):null},An.prototype.setMaxBounds=function(t){t?(this.lngRange=[t.getWest(),t.getEast()],this.latRange=[t.getSouth(),t.getNorth()],this._constrain()):(this.lngRange=null,this.latRange=[-this.maxValidLatitude,this.maxValidLatitude])},An.prototype.calculatePosMatrix=function(e,r){void 0===r&&(r=!1);var n=e.key,i=r?this._alignedPosMatrixCache:this._posMatrixCache;if(i[n])return i[n];var a=e.canonical,o=this.worldSize/this.zoomScale(a.z),s=a.x+Math.pow(2,a.z)*e.wrap,l=t.identity(new Float64Array(16));return t.translate(l,l,[s*o,a.y*o,0]),t.scale(l,l,[o/t.EXTENT,o/t.EXTENT,1]),t.multiply(l,r?this.alignedProjMatrix:this.projMatrix,l),i[n]=new Float32Array(l),i[n]},An.prototype.customLayerMatrix=function(){return this.mercatorMatrix.slice()},An.prototype._constrain=function(){if(this.center&&this.width&&this.height&&!this._constraining){this._constraining=!0;var e,r,n,i,a=-90,o=90,s=-180,l=180,c=this.size,u=this._unmodified;if(this.latRange){var f=this.latRange;a=t.mercatorYfromLat(f[1])*this.worldSize,e=(o=t.mercatorYfromLat(f[0])*this.worldSize)-a<c.y?c.y/(o-a):0}if(this.lngRange){var h=this.lngRange;s=t.mercatorXfromLng(h[0])*this.worldSize,r=(l=t.mercatorXfromLng(h[1])*this.worldSize)-s<c.x?c.x/(l-s):0}var p=this.point,d=Math.max(r||0,e||0);if(d)return this.center=this.unproject(new t.Point(r?(l+s)/2:p.x,e?(o+a)/2:p.y)),this.zoom+=this.scaleZoom(d),this._unmodified=u,void(this._constraining=!1);if(this.latRange){var m=p.y,g=c.y/2;m-g<a&&(i=a+g),m+g>o&&(i=o-g)}if(this.lngRange){var v=p.x,y=c.x/2;v-y<s&&(n=s+y),v+y>l&&(n=l-y)}void 0===n&&void 0===i||(this.center=this.unproject(new t.Point(void 0!==n?n:p.x,void 0!==i?i:p.y))),this._unmodified=u,this._constraining=!1}},An.prototype._calcMatrices=function(){if(this.height){var e=this._fov/2,r=this.centerOffset;this.cameraToCenterDistance=.5/Math.tan(e)*this.height;var n=Math.PI/2+this._pitch,i=this._fov*(.5+r.y/this.height),a=Math.sin(i)*this.cameraToCenterDistance/Math.sin(t.clamp(Math.PI-n-i,.01,Math.PI-.01)),o=this.point,s=o.x,l=o.y,c=1.01*(Math.cos(Math.PI/2-this._pitch)*a+this.cameraToCenterDistance),u=this.height/50,f=new Float64Array(16);t.perspective(f,this._fov,this.width/this.height,u,c),f[8]=2*-r.x/this.width,f[9]=2*r.y/this.height,t.scale(f,f,[1,-1,1]),t.translate(f,f,[0,0,-this.cameraToCenterDistance]),t.rotateX(f,f,this._pitch),t.rotateZ(f,f,this.angle),t.translate(f,f,[-s,-l,0]),this.mercatorMatrix=t.scale([],f,[this.worldSize,this.worldSize,this.worldSize]),t.scale(f,f,[1,1,t.mercatorZfromAltitude(1,this.center.lat)*this.worldSize,1]),this.projMatrix=f,this.invProjMatrix=t.invert([],this.projMatrix);var h=this.width%2/2,p=this.height%2/2,d=Math.cos(this.angle),m=Math.sin(this.angle),g=s-Math.round(s)+d*h+m*p,v=l-Math.round(l)+d*p+m*h,y=new Float64Array(f);if(t.translate(y,y,[g>.5?g-1:g,v>.5?v-1:v,0]),this.alignedProjMatrix=y,f=t.create(),t.scale(f,f,[this.width/2,-this.height/2,1]),t.translate(f,f,[1,-1,0]),this.labelPlaneMatrix=f,f=t.create(),t.scale(f,f,[1,-1,1]),t.translate(f,f,[-1,-1,0]),t.scale(f,f,[2/this.width,2/this.height,1]),this.glCoordMatrix=f,this.pixelMatrix=t.multiply(new Float64Array(16),this.labelPlaneMatrix,this.projMatrix),!(f=t.invert(new Float64Array(16),this.pixelMatrix)))throw new Error("failed to invert matrix");this.pixelMatrixInverse=f,this._posMatrixCache={},this._alignedPosMatrixCache={}}},An.prototype.maxPitchScaleFactor=function(){if(!this.pixelMatrixInverse)return 1;var e=this.pointCoordinate(new t.Point(0,0)),r=[e.x*this.worldSize,e.y*this.worldSize,0,1];return t.transformMat4(r,r,this.pixelMatrix)[3]/this.cameraToCenterDistance},An.prototype.getCameraPoint=function(){var e=this._pitch,r=Math.tan(e)*(this.cameraToCenterDistance||1);return this.centerPoint.add(new t.Point(0,r))},An.prototype.getCameraQueryGeometry=function(e){var r=this.getCameraPoint();if(1===e.length)return[e[0],r];for(var n=r.x,i=r.y,a=r.x,o=r.y,s=0,l=e;s<l.length;s+=1){var c=l[s];n=Math.min(n,c.x),i=Math.min(i,c.y),a=Math.max(a,c.x),o=Math.max(o,c.y)}return[new t.Point(n,i),new t.Point(a,i),new t.Point(a,o),new t.Point(n,o),new t.Point(n,i)]},Object.defineProperties(An.prototype,Mn);var Sn=function(e){var r,n,i,a,o;this._hashName=e&&encodeURIComponent(e),t.bindAll(["_getCurrentHash","_onHashChange","_updateHash"],this),this._updateHash=(r=this._updateHashUnthrottled.bind(this),n=300,i=!1,a=null,o=function(){a=null,i&&(r(),a=setTimeout(o,n),i=!1)},function(){return i=!0,a||o(),a})};Sn.prototype.addTo=function(e){return this._map=e,t.window.addEventListener("hashchange",this._onHashChange,!1),this._map.on("moveend",this._updateHash),this},Sn.prototype.remove=function(){return t.window.removeEventListener("hashchange",this._onHashChange,!1),this._map.off("moveend",this._updateHash),clearTimeout(this._updateHash()),delete this._map,this},Sn.prototype.getHashString=function(e){var r=this._map.getCenter(),n=Math.round(100*this._map.getZoom())/100,i=Math.ceil((n*Math.LN2+Math.log(512/360/.5))/Math.LN10),a=Math.pow(10,i),o=Math.round(r.lng*a)/a,s=Math.round(r.lat*a)/a,l=this._map.getBearing(),c=this._map.getPitch(),u="";if(u+=e?"/"+o+"/"+s+"/"+n:n+"/"+s+"/"+o,(l||c)&&(u+="/"+Math.round(10*l)/10),c&&(u+="/"+Math.round(c)),this._hashName){var f=this._hashName,h=!1,p=t.window.location.hash.slice(1).split("&").map((function(t){var e=t.split("=")[0];return e===f?(h=!0,e+"="+u):t})).filter((function(t){return t}));return h||p.push(f+"="+u),"#"+p.join("&")}return"#"+u},Sn.prototype._getCurrentHash=function(){var e,r=this,n=t.window.location.hash.replace("#","");return this._hashName?(n.split("&").map((function(t){return t.split("=")})).forEach((function(t){t[0]===r._hashName&&(e=t)})),(e&&e[1]||"").split("/")):n.split("/")},Sn.prototype._onHashChange=function(){var t=this._getCurrentHash();if(t.length>=3&&!t.some((function(t){return isNaN(t)}))){var e=this._map.dragRotate.isEnabled()&&this._map.touchZoomRotate.isEnabled()?+(t[3]||0):this._map.getBearing();return this._map.jumpTo({center:[+t[2],+t[1]],zoom:+t[0],bearing:e,pitch:+(t[4]||0)}),!0}return!1},Sn.prototype._updateHashUnthrottled=function(){var e=this.getHashString();try{t.window.history.replaceState(t.window.history.state,"",e)}catch(t){}};var En={linearity:.3,easing:t.bezier(0,0,.3,1)},Ln=t.extend({deceleration:2500,maxSpeed:1400},En),Cn=t.extend({deceleration:20,maxSpeed:1400},En),Pn=t.extend({deceleration:1e3,maxSpeed:360},En),In=t.extend({deceleration:1e3,maxSpeed:90},En),On=function(t){this._map=t,this.clear()};function zn(t,e){(!t.duration||t.duration<e.duration)&&(t.duration=e.duration,t.easing=e.easing)}function Dn(e,r,n){var i=n.maxSpeed,a=n.linearity,o=n.deceleration,s=t.clamp(e*a/(r/1e3),-i,i),l=Math.abs(s)/(o*a);return{easing:n.easing,duration:1e3*l,amount:s*(l/2)}}On.prototype.clear=function(){this._inertiaBuffer=[]},On.prototype.record=function(e){this._drainInertiaBuffer(),this._inertiaBuffer.push({time:t.browser.now(),settings:e})},On.prototype._drainInertiaBuffer=function(){for(var e=this._inertiaBuffer,r=t.browser.now();e.length>0&&r-e[0].time>160;)e.shift()},On.prototype._onMoveEnd=function(e){if(this._drainInertiaBuffer(),!(this._inertiaBuffer.length<2)){for(var r={zoom:0,bearing:0,pitch:0,pan:new t.Point(0,0),pinchAround:void 0,around:void 0},n=0,i=this._inertiaBuffer;n<i.length;n+=1){var a=i[n].settings;r.zoom+=a.zoomDelta||0,r.bearing+=a.bearingDelta||0,r.pitch+=a.pitchDelta||0,a.panDelta&&r.pan._add(a.panDelta),a.around&&(r.around=a.around),a.pinchAround&&(r.pinchAround=a.pinchAround)}var o=this._inertiaBuffer[this._inertiaBuffer.length-1].time-this._inertiaBuffer[0].time,s={};if(r.pan.mag()){var l=Dn(r.pan.mag(),o,t.extend({},Ln,e||{}));s.offset=r.pan.mult(l.amount/r.pan.mag()),s.center=this._map.transform.center,zn(s,l)}if(r.zoom){var c=Dn(r.zoom,o,Cn);s.zoom=this._map.transform.zoom+c.amount,zn(s,c)}if(r.bearing){var u=Dn(r.bearing,o,Pn);s.bearing=this._map.transform.bearing+t.clamp(u.amount,-179,179),zn(s,u)}if(r.pitch){var f=Dn(r.pitch,o,In);s.pitch=this._map.transform.pitch+f.amount,zn(s,f)}if(s.zoom||s.bearing){var h=void 0===r.pinchAround?r.around:r.pinchAround;s.around=h?this._map.unproject(h):this._map.getCenter()}return this.clear(),t.extend(s,{noMoveStart:!0})}};var Rn=function(e){function n(n,i,a,o){void 0===o&&(o={});var s=r.mousePos(i.getCanvasContainer(),a),l=i.unproject(s);e.call(this,n,t.extend({point:s,lngLat:l,originalEvent:a},o)),this._defaultPrevented=!1,this.target=i}e&&(n.__proto__=e),n.prototype=Object.create(e&&e.prototype),n.prototype.constructor=n;var i={defaultPrevented:{configurable:!0}};return n.prototype.preventDefault=function(){this._defaultPrevented=!0},i.defaultPrevented.get=function(){return this._defaultPrevented},Object.defineProperties(n.prototype,i),n}(t.Event),Fn=function(e){function n(n,i,a){var o="touchend"===n?a.changedTouches:a.touches,s=r.touchPos(i.getCanvasContainer(),o),l=s.map((function(t){return i.unproject(t)})),c=s.reduce((function(t,e,r,n){return t.add(e.div(n.length))}),new t.Point(0,0)),u=i.unproject(c);e.call(this,n,{points:s,point:c,lngLats:l,lngLat:u,originalEvent:a}),this._defaultPrevented=!1}e&&(n.__proto__=e),n.prototype=Object.create(e&&e.prototype),n.prototype.constructor=n;var i={defaultPrevented:{configurable:!0}};return n.prototype.preventDefault=function(){this._defaultPrevented=!0},i.defaultPrevented.get=function(){return this._defaultPrevented},Object.defineProperties(n.prototype,i),n}(t.Event),Bn=function(t){function e(e,r,n){t.call(this,e,{originalEvent:n}),this._defaultPrevented=!1}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={defaultPrevented:{configurable:!0}};return e.prototype.preventDefault=function(){this._defaultPrevented=!0},r.defaultPrevented.get=function(){return this._defaultPrevented},Object.defineProperties(e.prototype,r),e}(t.Event),Nn=function(t,e){this._map=t,this._clickTolerance=e.clickTolerance};Nn.prototype.reset=function(){delete this._mousedownPos},Nn.prototype.wheel=function(t){return this._firePreventable(new Bn(t.type,this._map,t))},Nn.prototype.mousedown=function(t,e){return this._mousedownPos=e,this._firePreventable(new Rn(t.type,this._map,t))},Nn.prototype.mouseup=function(t){this._map.fire(new Rn(t.type,this._map,t))},Nn.prototype.click=function(t,e){this._mousedownPos&&this._mousedownPos.dist(e)>=this._clickTolerance||this._map.fire(new Rn(t.type,this._map,t))},Nn.prototype.dblclick=function(t){return this._firePreventable(new Rn(t.type,this._map,t))},Nn.prototype.mouseover=function(t){this._map.fire(new Rn(t.type,this._map,t))},Nn.prototype.mouseout=function(t){this._map.fire(new Rn(t.type,this._map,t))},Nn.prototype.touchstart=function(t){return this._firePreventable(new Fn(t.type,this._map,t))},Nn.prototype.touchmove=function(t){this._map.fire(new Fn(t.type,this._map,t))},Nn.prototype.touchend=function(t){this._map.fire(new Fn(t.type,this._map,t))},Nn.prototype.touchcancel=function(t){this._map.fire(new Fn(t.type,this._map,t))},Nn.prototype._firePreventable=function(t){if(this._map.fire(t),t.defaultPrevented)return{}},Nn.prototype.isEnabled=function(){return!0},Nn.prototype.isActive=function(){return!1},Nn.prototype.enable=function(){},Nn.prototype.disable=function(){};var jn=function(t){this._map=t};jn.prototype.reset=function(){this._delayContextMenu=!1,delete this._contextMenuEvent},jn.prototype.mousemove=function(t){this._map.fire(new Rn(t.type,this._map,t))},jn.prototype.mousedown=function(){this._delayContextMenu=!0},jn.prototype.mouseup=function(){this._delayContextMenu=!1,this._contextMenuEvent&&(this._map.fire(new Rn("contextmenu",this._map,this._contextMenuEvent)),delete this._contextMenuEvent)},jn.prototype.contextmenu=function(t){this._delayContextMenu?this._contextMenuEvent=t:this._map.fire(new Rn(t.type,this._map,t)),this._map.listens("contextmenu")&&t.preventDefault()},jn.prototype.isEnabled=function(){return!0},jn.prototype.isActive=function(){return!1},jn.prototype.enable=function(){},jn.prototype.disable=function(){};var Un=function(t,e){this._map=t,this._el=t.getCanvasContainer(),this._container=t.getContainer(),this._clickTolerance=e.clickTolerance||1};function Vn(t,e){for(var r={},n=0;n<t.length;n++)r[t[n].identifier]=e[n];return r}Un.prototype.isEnabled=function(){return!!this._enabled},Un.prototype.isActive=function(){return!!this._active},Un.prototype.enable=function(){this.isEnabled()||(this._enabled=!0)},Un.prototype.disable=function(){this.isEnabled()&&(this._enabled=!1)},Un.prototype.mousedown=function(t,e){this.isEnabled()&&t.shiftKey&&0===t.button&&(r.disableDrag(),this._startPos=this._lastPos=e,this._active=!0)},Un.prototype.mousemoveWindow=function(t,e){if(this._active){var n=e;if(!(this._lastPos.equals(n)||!this._box&&n.dist(this._startPos)<this._clickTolerance)){var i=this._startPos;this._lastPos=n,this._box||(this._box=r.create("div","mapboxgl-boxzoom",this._container),this._container.classList.add("mapboxgl-crosshair"),this._fireEvent("boxzoomstart",t));var a=Math.min(i.x,n.x),o=Math.max(i.x,n.x),s=Math.min(i.y,n.y),l=Math.max(i.y,n.y);r.setTransform(this._box,"translate("+a+"px,"+s+"px)"),this._box.style.width=o-a+"px",this._box.style.height=l-s+"px"}}},Un.prototype.mouseupWindow=function(e,n){var i=this;if(this._active&&0===e.button){var a=this._startPos,o=n;if(this.reset(),r.suppressClick(),a.x!==o.x||a.y!==o.y)return this._map.fire(new t.Event("boxzoomend",{originalEvent:e})),{cameraAnimation:function(t){return t.fitScreenCoordinates(a,o,i._map.getBearing(),{linear:!0})}};this._fireEvent("boxzoomcancel",e)}},Un.prototype.keydown=function(t){this._active&&27===t.keyCode&&(this.reset(),this._fireEvent("boxzoomcancel",t))},Un.prototype.reset=function(){this._active=!1,this._container.classList.remove("mapboxgl-crosshair"),this._box&&(r.remove(this._box),this._box=null),r.enableDrag(),delete this._startPos,delete this._lastPos},Un.prototype._fireEvent=function(e,r){return this._map.fire(new t.Event(e,{originalEvent:r}))};var Hn=function(t){this.reset(),this.numTouches=t.numTouches};Hn.prototype.reset=function(){delete this.centroid,delete this.startTime,delete this.touches,this.aborted=!1},Hn.prototype.touchstart=function(e,r,n){(this.centroid||n.length>this.numTouches)&&(this.aborted=!0),this.aborted||(void 0===this.startTime&&(this.startTime=e.timeStamp),n.length===this.numTouches&&(this.centroid=function(e){for(var r=new t.Point(0,0),n=0,i=e;n<i.length;n+=1){var a=i[n];r._add(a)}return r.div(e.length)}(r),this.touches=Vn(n,r)))},Hn.prototype.touchmove=function(t,e,r){if(!this.aborted&&this.centroid){var n=Vn(r,e);for(var i in this.touches){var a=this.touches[i],o=n[i];(!o||o.dist(a)>30)&&(this.aborted=!0)}}},Hn.prototype.touchend=function(t,e,r){if((!this.centroid||t.timeStamp-this.startTime>500)&&(this.aborted=!0),0===r.length){var n=!this.aborted&&this.centroid;if(this.reset(),n)return n}};var qn=function(t){this.singleTap=new Hn(t),this.numTaps=t.numTaps,this.reset()};qn.prototype.reset=function(){this.lastTime=1/0,delete this.lastTap,this.count=0,this.singleTap.reset()},qn.prototype.touchstart=function(t,e,r){this.singleTap.touchstart(t,e,r)},qn.prototype.touchmove=function(t,e,r){this.singleTap.touchmove(t,e,r)},qn.prototype.touchend=function(t,e,r){var n=this.singleTap.touchend(t,e,r);if(n){var i=t.timeStamp-this.lastTime<500,a=!this.lastTap||this.lastTap.dist(n)<30;if(i&&a||this.reset(),this.count++,this.lastTime=t.timeStamp,this.lastTap=n,this.count===this.numTaps)return this.reset(),n}};var Gn=function(){this._zoomIn=new qn({numTouches:1,numTaps:2}),this._zoomOut=new qn({numTouches:2,numTaps:1}),this.reset()};Gn.prototype.reset=function(){this._active=!1,this._zoomIn.reset(),this._zoomOut.reset()},Gn.prototype.touchstart=function(t,e,r){this._zoomIn.touchstart(t,e,r),this._zoomOut.touchstart(t,e,r)},Gn.prototype.touchmove=function(t,e,r){this._zoomIn.touchmove(t,e,r),this._zoomOut.touchmove(t,e,r)},Gn.prototype.touchend=function(t,e,r){var n=this,i=this._zoomIn.touchend(t,e,r),a=this._zoomOut.touchend(t,e,r);return i?(this._active=!0,t.preventDefault(),setTimeout((function(){return n.reset()}),0),{cameraAnimation:function(e){return e.easeTo({duration:300,zoom:e.getZoom()+1,around:e.unproject(i)},{originalEvent:t})}}):a?(this._active=!0,t.preventDefault(),setTimeout((function(){return n.reset()}),0),{cameraAnimation:function(e){return e.easeTo({duration:300,zoom:e.getZoom()-1,around:e.unproject(a)},{originalEvent:t})}}):void 0},Gn.prototype.touchcancel=function(){this.reset()},Gn.prototype.enable=function(){this._enabled=!0},Gn.prototype.disable=function(){this._enabled=!1,this.reset()},Gn.prototype.isEnabled=function(){return this._enabled},Gn.prototype.isActive=function(){return this._active};var Yn=function(t){this.reset(),this._clickTolerance=t.clickTolerance||1};Yn.prototype.reset=function(){this._active=!1,this._moved=!1,delete this._lastPoint,delete this._eventButton},Yn.prototype._correctButton=function(t,e){return!1},Yn.prototype._move=function(t,e){return{}},Yn.prototype.mousedown=function(t,e){if(!this._lastPoint){var n=r.mouseButton(t);this._correctButton(t,n)&&(this._lastPoint=e,this._eventButton=n)}},Yn.prototype.mousemoveWindow=function(t,e){var r=this._lastPoint;if(r&&(t.preventDefault(),this._moved||!(e.dist(r)<this._clickTolerance)))return this._moved=!0,this._lastPoint=e,this._move(r,e)},Yn.prototype.mouseupWindow=function(t){r.mouseButton(t)===this._eventButton&&(this._moved&&r.suppressClick(),this.reset())},Yn.prototype.enable=function(){this._enabled=!0},Yn.prototype.disable=function(){this._enabled=!1,this.reset()},Yn.prototype.isEnabled=function(){return this._enabled},Yn.prototype.isActive=function(){return this._active};var Wn=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.mousedown=function(e,r){t.prototype.mousedown.call(this,e,r),this._lastPoint&&(this._active=!0)},e.prototype._correctButton=function(t,e){return 0===e&&!t.ctrlKey},e.prototype._move=function(t,e){return{around:e,panDelta:e.sub(t)}},e}(Yn),Xn=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._correctButton=function(t,e){return 0===e&&t.ctrlKey||2===e},e.prototype._move=function(t,e){var r=.8*(e.x-t.x);if(r)return this._active=!0,{bearingDelta:r}},e.prototype.contextmenu=function(t){t.preventDefault()},e}(Yn),Zn=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._correctButton=function(t,e){return 0===e&&t.ctrlKey||2===e},e.prototype._move=function(t,e){var r=-.5*(e.y-t.y);if(r)return this._active=!0,{pitchDelta:r}},e.prototype.contextmenu=function(t){t.preventDefault()},e}(Yn),Jn=function(t){this._minTouches=1,this._clickTolerance=t.clickTolerance||1,this.reset()};Jn.prototype.reset=function(){this._active=!1,this._touches={},this._sum=new t.Point(0,0)},Jn.prototype.touchstart=function(t,e,r){return this._calculateTransform(t,e,r)},Jn.prototype.touchmove=function(t,e,r){if(this._active)return t.preventDefault(),this._calculateTransform(t,e,r)},Jn.prototype.touchend=function(t,e,r){this._calculateTransform(t,e,r),this._active&&r.length<this._minTouches&&this.reset()},Jn.prototype.touchcancel=function(){this.reset()},Jn.prototype._calculateTransform=function(e,r,n){n.length>0&&(this._active=!0);var i=Vn(n,r),a=new t.Point(0,0),o=new t.Point(0,0),s=0;for(var l in i){var c=i[l],u=this._touches[l];u&&(a._add(c),o._add(c.sub(u)),s++,i[l]=c)}if(this._touches=i,!(s<this._minTouches)&&o.mag()){var f=o.div(s);if(this._sum._add(f),!(this._sum.mag()<this._clickTolerance))return{around:a.div(s),panDelta:f}}},Jn.prototype.enable=function(){this._enabled=!0},Jn.prototype.disable=function(){this._enabled=!1,this.reset()},Jn.prototype.isEnabled=function(){return this._enabled},Jn.prototype.isActive=function(){return this._active};var Kn=function(){this.reset()};function Qn(t,e,r){for(var n=0;n<t.length;n++)if(t[n].identifier===r)return e[n]}Kn.prototype.reset=function(){this._active=!1,delete this._firstTwoTouches},Kn.prototype._start=function(t){},Kn.prototype._move=function(t,e,r){return{}},Kn.prototype.touchstart=function(t,e,r){this._firstTwoTouches||r.length<2||(this._firstTwoTouches=[r[0].identifier,r[1].identifier],this._start([e[0],e[1]]))},Kn.prototype.touchmove=function(t,e,r){if(this._firstTwoTouches){t.preventDefault();var n=this._firstTwoTouches,i=n[0],a=n[1],o=Qn(r,e,i),s=Qn(r,e,a);if(o&&s){var l=this._aroundCenter?null:o.add(s).div(2);return this._move([o,s],l,t)}}},Kn.prototype.touchend=function(t,e,n){if(this._firstTwoTouches){var i=this._firstTwoTouches,a=i[0],o=i[1],s=Qn(n,e,a),l=Qn(n,e,o);s&&l||(this._active&&r.suppressClick(),this.reset())}},Kn.prototype.touchcancel=function(){this.reset()},Kn.prototype.enable=function(t){this._enabled=!0,this._aroundCenter=!!t&&"center"===t.around},Kn.prototype.disable=function(){this._enabled=!1,this.reset()},Kn.prototype.isEnabled=function(){return this._enabled},Kn.prototype.isActive=function(){return this._active};function $n(t,e){return Math.log(t/e)/Math.LN2}var ti=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){t.prototype.reset.call(this),delete this._distance,delete this._startDistance},e.prototype._start=function(t){this._startDistance=this._distance=t[0].dist(t[1])},e.prototype._move=function(t,e){var r=this._distance;if(this._distance=t[0].dist(t[1]),this._active||!(Math.abs($n(this._distance,this._startDistance))<.1))return this._active=!0,{zoomDelta:$n(this._distance,r),pinchAround:e}},e}(Kn);function ei(t,e){return 180*t.angleWith(e)/Math.PI}var ri=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){t.prototype.reset.call(this),delete this._minDiameter,delete this._startVector,delete this._vector},e.prototype._start=function(t){this._startVector=this._vector=t[0].sub(t[1]),this._minDiameter=t[0].dist(t[1])},e.prototype._move=function(t,e){var r=this._vector;if(this._vector=t[0].sub(t[1]),this._active||!this._isBelowThreshold(this._vector))return this._active=!0,{bearingDelta:ei(this._vector,r),pinchAround:e}},e.prototype._isBelowThreshold=function(t){this._minDiameter=Math.min(this._minDiameter,t.mag());var e=25/(Math.PI*this._minDiameter)*360,r=ei(t,this._startVector);return Math.abs(r)<e},e}(Kn);function ni(t){return Math.abs(t.y)>Math.abs(t.x)}var ii=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){t.prototype.reset.call(this),this._valid=void 0,delete this._firstMove,delete this._lastPoints},e.prototype._start=function(t){this._lastPoints=t,ni(t[0].sub(t[1]))&&(this._valid=!1)},e.prototype._move=function(t,e,r){var n=t[0].sub(this._lastPoints[0]),i=t[1].sub(this._lastPoints[1]);if(this._valid=this.gestureBeginsVertically(n,i,r.timeStamp),this._valid){this._lastPoints=t,this._active=!0;return{pitchDelta:-.5*((n.y+i.y)/2)}}},e.prototype.gestureBeginsVertically=function(t,e,r){if(void 0!==this._valid)return this._valid;var n=t.mag()>=2,i=e.mag()>=2;if(n||i){if(!n||!i)return void 0===this._firstMove&&(this._firstMove=r),r-this._firstMove<100&&void 0;var a=t.y>0==e.y>0;return ni(t)&&ni(e)&&a}},e}(Kn),ai={panStep:100,bearingStep:15,pitchStep:10},oi=function(){var t=ai;this._panStep=t.panStep,this._bearingStep=t.bearingStep,this._pitchStep=t.pitchStep};function si(t){return t*(2-t)}oi.prototype.reset=function(){this._active=!1},oi.prototype.keydown=function(t){var e=this;if(!(t.altKey||t.ctrlKey||t.metaKey)){var r=0,n=0,i=0,a=0,o=0;switch(t.keyCode){case 61:case 107:case 171:case 187:r=1;break;case 189:case 109:case 173:r=-1;break;case 37:t.shiftKey?n=-1:(t.preventDefault(),a=-1);break;case 39:t.shiftKey?n=1:(t.preventDefault(),a=1);break;case 38:t.shiftKey?i=1:(t.preventDefault(),o=-1);break;case 40:t.shiftKey?i=-1:(t.preventDefault(),o=1);break;default:return}return{cameraAnimation:function(s){var l=s.getZoom();s.easeTo({duration:300,easeId:"keyboardHandler",easing:si,zoom:r?Math.round(l)+r*(t.shiftKey?2:1):l,bearing:s.getBearing()+n*e._bearingStep,pitch:s.getPitch()+i*e._pitchStep,offset:[-a*e._panStep,-o*e._panStep],center:s.getCenter()},{originalEvent:t})}}}},oi.prototype.enable=function(){this._enabled=!0},oi.prototype.disable=function(){this._enabled=!1,this.reset()},oi.prototype.isEnabled=function(){return this._enabled},oi.prototype.isActive=function(){return this._active};var li=function(e,r){this._map=e,this._el=e.getCanvasContainer(),this._handler=r,this._delta=0,this._defaultZoomRate=.01,this._wheelZoomRate=1/450,t.bindAll(["_onWheel","_onTimeout","_onScrollFrame","_onScrollFinished"],this)};li.prototype.setZoomRate=function(t){this._defaultZoomRate=t},li.prototype.setWheelZoomRate=function(t){this._wheelZoomRate=t},li.prototype.isEnabled=function(){return!!this._enabled},li.prototype.isActive=function(){return!!this._active||void 0!==this._finishTimeout},li.prototype.isZooming=function(){return!!this._zooming},li.prototype.enable=function(t){this.isEnabled()||(this._enabled=!0,this._aroundCenter=t&&"center"===t.around)},li.prototype.disable=function(){this.isEnabled()&&(this._enabled=!1)},li.prototype.wheel=function(e){if(this.isEnabled()){var r=e.deltaMode===t.window.WheelEvent.DOM_DELTA_LINE?40*e.deltaY:e.deltaY,n=t.browser.now(),i=n-(this._lastWheelEventTime||0);this._lastWheelEventTime=n,0!==r&&r%4.000244140625==0?this._type="wheel":0!==r&&Math.abs(r)<4?this._type="trackpad":i>400?(this._type=null,this._lastValue=r,this._timeout=setTimeout(this._onTimeout,40,e)):this._type||(this._type=Math.abs(i*r)<200?"trackpad":"wheel",this._timeout&&(clearTimeout(this._timeout),this._timeout=null,r+=this._lastValue)),e.shiftKey&&r&&(r/=4),this._type&&(this._lastWheelEvent=e,this._delta-=r,this._active||this._start(e)),e.preventDefault()}},li.prototype._onTimeout=function(t){this._type="wheel",this._delta-=this._lastValue,this._active||this._start(t)},li.prototype._start=function(e){if(this._delta){this._frameId&&(this._frameId=null),this._active=!0,this.isZooming()||(this._zooming=!0),this._finishTimeout&&(clearTimeout(this._finishTimeout),delete this._finishTimeout);var n=r.mousePos(this._el,e);this._around=t.LngLat.convert(this._aroundCenter?this._map.getCenter():this._map.unproject(n)),this._aroundPoint=this._map.transform.locationPoint(this._around),this._frameId||(this._frameId=!0,this._handler._triggerRenderFrame())}},li.prototype.renderFrame=function(){return this._onScrollFrame()},li.prototype._onScrollFrame=function(){var e=this;if(this._frameId&&(this._frameId=null,this.isActive())){var r=this._map.transform;if(0!==this._delta){var n="wheel"===this._type&&Math.abs(this._delta)>4.000244140625?this._wheelZoomRate:this._defaultZoomRate,i=2/(1+Math.exp(-Math.abs(this._delta*n)));this._delta<0&&0!==i&&(i=1/i);var a="number"==typeof this._targetZoom?r.zoomScale(this._targetZoom):r.scale;this._targetZoom=Math.min(r.maxZoom,Math.max(r.minZoom,r.scaleZoom(a*i))),"wheel"===this._type&&(this._startZoom=r.zoom,this._easing=this._smoothOutEasing(200)),this._delta=0}var o,s="number"==typeof this._targetZoom?this._targetZoom:r.zoom,l=this._startZoom,c=this._easing,u=!1;if("wheel"===this._type&&l&&c){var f=Math.min((t.browser.now()-this._lastWheelEventTime)/200,1),h=c(f);o=t.number(l,s,h),f<1?this._frameId||(this._frameId=!0):u=!0}else o=s,u=!0;return this._active=!0,u&&(this._active=!1,this._finishTimeout=setTimeout((function(){e._zooming=!1,e._handler._triggerRenderFrame(),delete e._targetZoom,delete e._finishTimeout}),200)),{noInertia:!0,needsRenderFrame:!u,zoomDelta:o-r.zoom,around:this._aroundPoint,originalEvent:this._lastWheelEvent}}},li.prototype._smoothOutEasing=function(e){var r=t.ease;if(this._prevEase){var n=this._prevEase,i=(t.browser.now()-n.start)/n.duration,a=n.easing(i+.01)-n.easing(i),o=.27/Math.sqrt(a*a+1e-4)*.01,s=Math.sqrt(.0729-o*o);r=t.bezier(o,s,.25,1)}return this._prevEase={start:t.browser.now(),duration:e,easing:r},r},li.prototype.reset=function(){this._active=!1};var ci=function(t,e){this._clickZoom=t,this._tapZoom=e};ci.prototype.enable=function(){this._clickZoom.enable(),this._tapZoom.enable()},ci.prototype.disable=function(){this._clickZoom.disable(),this._tapZoom.disable()},ci.prototype.isEnabled=function(){return this._clickZoom.isEnabled()&&this._tapZoom.isEnabled()},ci.prototype.isActive=function(){return this._clickZoom.isActive()||this._tapZoom.isActive()};var ui=function(){this.reset()};ui.prototype.reset=function(){this._active=!1},ui.prototype.dblclick=function(t,e){return t.preventDefault(),{cameraAnimation:function(r){r.easeTo({duration:300,zoom:r.getZoom()+(t.shiftKey?-1:1),around:r.unproject(e)},{originalEvent:t})}}},ui.prototype.enable=function(){this._enabled=!0},ui.prototype.disable=function(){this._enabled=!1,this.reset()},ui.prototype.isEnabled=function(){return this._enabled},ui.prototype.isActive=function(){return this._active};var fi=function(){this._tap=new qn({numTouches:1,numTaps:1}),this.reset()};fi.prototype.reset=function(){this._active=!1,delete this._swipePoint,delete this._swipeTouch,delete this._tapTime,this._tap.reset()},fi.prototype.touchstart=function(t,e,r){this._swipePoint||(this._tapTime&&t.timeStamp-this._tapTime>500&&this.reset(),this._tapTime?r.length>0&&(this._swipePoint=e[0],this._swipeTouch=r[0].identifier):this._tap.touchstart(t,e,r))},fi.prototype.touchmove=function(t,e,r){if(this._tapTime){if(this._swipePoint){if(r[0].identifier!==this._swipeTouch)return;var n=e[0],i=n.y-this._swipePoint.y;return this._swipePoint=n,t.preventDefault(),this._active=!0,{zoomDelta:i/128}}}else this._tap.touchmove(t,e,r)},fi.prototype.touchend=function(t,e,r){this._tapTime?this._swipePoint&&0===r.length&&this.reset():this._tap.touchend(t,e,r)&&(this._tapTime=t.timeStamp)},fi.prototype.touchcancel=function(){this.reset()},fi.prototype.enable=function(){this._enabled=!0},fi.prototype.disable=function(){this._enabled=!1,this.reset()},fi.prototype.isEnabled=function(){return this._enabled},fi.prototype.isActive=function(){return this._active};var hi=function(t,e,r){this._el=t,this._mousePan=e,this._touchPan=r};hi.prototype.enable=function(t){this._inertiaOptions=t||{},this._mousePan.enable(),this._touchPan.enable(),this._el.classList.add("mapboxgl-touch-drag-pan")},hi.prototype.disable=function(){this._mousePan.disable(),this._touchPan.disable(),this._el.classList.remove("mapboxgl-touch-drag-pan")},hi.prototype.isEnabled=function(){return this._mousePan.isEnabled()&&this._touchPan.isEnabled()},hi.prototype.isActive=function(){return this._mousePan.isActive()||this._touchPan.isActive()};var pi=function(t,e,r){this._pitchWithRotate=t.pitchWithRotate,this._mouseRotate=e,this._mousePitch=r};pi.prototype.enable=function(){this._mouseRotate.enable(),this._pitchWithRotate&&this._mousePitch.enable()},pi.prototype.disable=function(){this._mouseRotate.disable(),this._mousePitch.disable()},pi.prototype.isEnabled=function(){return this._mouseRotate.isEnabled()&&(!this._pitchWithRotate||this._mousePitch.isEnabled())},pi.prototype.isActive=function(){return this._mouseRotate.isActive()||this._mousePitch.isActive()};var di=function(t,e,r,n){this._el=t,this._touchZoom=e,this._touchRotate=r,this._tapDragZoom=n,this._rotationDisabled=!1,this._enabled=!0};di.prototype.enable=function(t){this._touchZoom.enable(t),this._rotationDisabled||this._touchRotate.enable(t),this._tapDragZoom.enable(),this._el.classList.add("mapboxgl-touch-zoom-rotate")},di.prototype.disable=function(){this._touchZoom.disable(),this._touchRotate.disable(),this._tapDragZoom.disable(),this._el.classList.remove("mapboxgl-touch-zoom-rotate")},di.prototype.isEnabled=function(){return this._touchZoom.isEnabled()&&(this._rotationDisabled||this._touchRotate.isEnabled())&&this._tapDragZoom.isEnabled()},di.prototype.isActive=function(){return this._touchZoom.isActive()||this._touchRotate.isActive()||this._tapDragZoom.isActive()},di.prototype.disableRotation=function(){this._rotationDisabled=!0,this._touchRotate.disable()},di.prototype.enableRotation=function(){this._rotationDisabled=!1,this._touchZoom.isEnabled()&&this._touchRotate.enable()};var mi=function(t){return t.zoom||t.drag||t.pitch||t.rotate},gi=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(t.Event);function vi(t){return t.panDelta&&t.panDelta.mag()||t.zoomDelta||t.bearingDelta||t.pitchDelta}var yi=function(e,n){this._map=e,this._el=this._map.getCanvasContainer(),this._handlers=[],this._handlersById={},this._changes=[],this._inertia=new On(e),this._bearingSnap=n.bearingSnap,this._previousActiveHandlers={},this._eventsInProgress={},this._addDefaultHandlers(n),t.bindAll(["handleEvent","handleWindowEvent"],this);var i=this._el;this._listeners=[[i,"touchstart",{passive:!1}],[i,"touchmove",{passive:!1}],[i,"touchend",void 0],[i,"touchcancel",void 0],[i,"mousedown",void 0],[i,"mousemove",void 0],[i,"mouseup",void 0],[t.window.document,"mousemove",{capture:!0}],[t.window.document,"mouseup",void 0],[i,"mouseover",void 0],[i,"mouseout",void 0],[i,"dblclick",void 0],[i,"click",void 0],[i,"keydown",{capture:!1}],[i,"keyup",void 0],[i,"wheel",{passive:!1}],[i,"contextmenu",void 0],[t.window,"blur",void 0]];for(var a=0,o=this._listeners;a<o.length;a+=1){var s=o[a],l=s[0],c=s[1],u=s[2];r.addEventListener(l,c,l===t.window.document?this.handleWindowEvent:this.handleEvent,u)}};yi.prototype.destroy=function(){for(var e=0,n=this._listeners;e<n.length;e+=1){var i=n[e],a=i[0],o=i[1],s=i[2];r.removeEventListener(a,o,a===t.window.document?this.handleWindowEvent:this.handleEvent,s)}},yi.prototype._addDefaultHandlers=function(t){var e=this._map,r=e.getCanvasContainer();this._add("mapEvent",new Nn(e,t));var n=e.boxZoom=new Un(e,t);this._add("boxZoom",n);var i=new Gn,a=new ui;e.doubleClickZoom=new ci(a,i),this._add("tapZoom",i),this._add("clickZoom",a);var o=new fi;this._add("tapDragZoom",o);var s=e.touchPitch=new ii;this._add("touchPitch",s);var l=new Xn(t),c=new Zn(t);e.dragRotate=new pi(t,l,c),this._add("mouseRotate",l,["mousePitch"]),this._add("mousePitch",c,["mouseRotate"]);var u=new Wn(t),f=new Jn(t);e.dragPan=new hi(r,u,f),this._add("mousePan",u),this._add("touchPan",f,["touchZoom","touchRotate"]);var h=new ri,p=new ti;e.touchZoomRotate=new di(r,p,h,o),this._add("touchRotate",h,["touchPan","touchZoom"]),this._add("touchZoom",p,["touchPan","touchRotate"]);var d=e.scrollZoom=new li(e,this);this._add("scrollZoom",d,["mousePan"]);var m=e.keyboard=new oi;this._add("keyboard",m),this._add("blockableMapEvent",new jn(e));for(var g=0,v=["boxZoom","doubleClickZoom","tapDragZoom","touchPitch","dragRotate","dragPan","touchZoomRotate","scrollZoom","keyboard"];g<v.length;g+=1){var y=v[g];t.interactive&&t[y]&&e[y].enable(t[y])}},yi.prototype._add=function(t,e,r){this._handlers.push({handlerName:t,handler:e,allowed:r}),this._handlersById[t]=e},yi.prototype.stop=function(){if(!this._updatingCamera){for(var t=0,e=this._handlers;t<e.length;t+=1){e[t].handler.reset()}this._inertia.clear(),this._fireEvents({},{}),this._changes=[]}},yi.prototype.isActive=function(){for(var t=0,e=this._handlers;t<e.length;t+=1){if(e[t].handler.isActive())return!0}return!1},yi.prototype.isZooming=function(){return!!this._eventsInProgress.zoom||this._map.scrollZoom.isZooming()},yi.prototype.isRotating=function(){return!!this._eventsInProgress.rotate},yi.prototype.isMoving=function(){return Boolean(mi(this._eventsInProgress))||this.isZooming()},yi.prototype._blockedByActive=function(t,e,r){for(var n in t)if(n!==r&&(!e||e.indexOf(n)<0))return!0;return!1},yi.prototype.handleWindowEvent=function(t){this.handleEvent(t,t.type+"Window")},yi.prototype._getMapTouches=function(t){for(var e=[],r=0,n=t;r<n.length;r+=1){var i=n[r],a=i.target;this._el.contains(a)&&e.push(i)}return e},yi.prototype.handleEvent=function(t,e){if("blur"!==t.type){this._updatingCamera=!0;for(var n="renderFrame"===t.type?void 0:t,i={needsRenderFrame:!1},a={},o={},s=t.touches?this._getMapTouches(t.touches):void 0,l=s?r.touchPos(this._el,s):r.mousePos(this._el,t),c=0,u=this._handlers;c<u.length;c+=1){var f=u[c],h=f.handlerName,p=f.handler,d=f.allowed;if(p.isEnabled()){var m=void 0;this._blockedByActive(o,d,h)?p.reset():p[e||t.type]&&(m=p[e||t.type](t,l,s),this.mergeHandlerResult(i,a,m,h,n),m&&m.needsRenderFrame&&this._triggerRenderFrame()),(m||p.isActive())&&(o[h]=p)}}var g={};for(var v in this._previousActiveHandlers)o[v]||(g[v]=n);this._previousActiveHandlers=o,(Object.keys(g).length||vi(i))&&(this._changes.push([i,a,g]),this._triggerRenderFrame()),(Object.keys(o).length||vi(i))&&this._map._stop(!0),this._updatingCamera=!1;var y=i.cameraAnimation;y&&(this._inertia.clear(),this._fireEvents({},{}),this._changes=[],y(this._map))}else this.stop()},yi.prototype.mergeHandlerResult=function(e,r,n,i,a){if(n){t.extend(e,n);var o={handlerName:i,originalEvent:n.originalEvent||a};void 0!==n.zoomDelta&&(r.zoom=o),void 0!==n.panDelta&&(r.drag=o),void 0!==n.pitchDelta&&(r.pitch=o),void 0!==n.bearingDelta&&(r.rotate=o)}},yi.prototype._applyChanges=function(){for(var e={},r={},n={},i=0,a=this._changes;i<a.length;i+=1){var o=a[i],s=o[0],l=o[1],c=o[2];s.panDelta&&(e.panDelta=(e.panDelta||new t.Point(0,0))._add(s.panDelta)),s.zoomDelta&&(e.zoomDelta=(e.zoomDelta||0)+s.zoomDelta),s.bearingDelta&&(e.bearingDelta=(e.bearingDelta||0)+s.bearingDelta),s.pitchDelta&&(e.pitchDelta=(e.pitchDelta||0)+s.pitchDelta),void 0!==s.around&&(e.around=s.around),void 0!==s.pinchAround&&(e.pinchAround=s.pinchAround),s.noInertia&&(e.noInertia=s.noInertia),t.extend(r,l),t.extend(n,c)}this._updateMapTransform(e,r,n),this._changes=[]},yi.prototype._updateMapTransform=function(t,e,r){var n=this._map,i=n.transform;if(!vi(t))return this._fireEvents(e,r);var a=t.panDelta,o=t.zoomDelta,s=t.bearingDelta,l=t.pitchDelta,c=t.around,u=t.pinchAround;void 0!==u&&(c=u),n._stop(!0),c=c||n.transform.centerPoint;var f=i.pointLocation(a?c.sub(a):c);s&&(i.bearing+=s),l&&(i.pitch+=l),o&&(i.zoom+=o),i.setLocationAtPoint(f,c),this._map._update(),t.noInertia||this._inertia.record(t),this._fireEvents(e,r)},yi.prototype._fireEvents=function(e,r){var n=this,i=mi(this._eventsInProgress),a=mi(e),o={};for(var s in e){var l=e[s].originalEvent;this._eventsInProgress[s]||(o[s+"start"]=l),this._eventsInProgress[s]=e[s]}for(var c in!i&&a&&this._fireEvent("movestart",a.originalEvent),o)this._fireEvent(c,o[c]);for(var u in e.rotate&&(this._bearingChanged=!0),a&&this._fireEvent("move",a.originalEvent),e){var f=e[u].originalEvent;this._fireEvent(u,f)}var h,p={};for(var d in this._eventsInProgress){var m=this._eventsInProgress[d],g=m.handlerName,v=m.originalEvent;this._handlersById[g].isActive()||(delete this._eventsInProgress[d],h=r[g]||v,p[d+"end"]=h)}for(var y in p)this._fireEvent(y,p[y]);var x=mi(this._eventsInProgress);if((i||a)&&!x){this._updatingCamera=!0;var b=this._inertia._onMoveEnd(this._map.dragPan._inertiaOptions),_=function(t){return 0!==t&&-n._bearingSnap<t&&t<n._bearingSnap};b?(_(b.bearing||this._map.getBearing())&&(b.bearing=0),this._map.easeTo(b,{originalEvent:h})):(this._map.fire(new t.Event("moveend",{originalEvent:h})),_(this._map.getBearing())&&this._map.resetNorth()),this._bearingChanged=!1,this._updatingCamera=!1}},yi.prototype._fireEvent=function(e,r){this._map.fire(new t.Event(e,r?{originalEvent:r}:{}))},yi.prototype._triggerRenderFrame=function(){var t=this;void 0===this._frameId&&(this._frameId=this._map._requestRenderFrame((function(e){delete t._frameId,t.handleEvent(new gi("renderFrame",{timeStamp:e})),t._applyChanges()})))};var xi=function(e){function r(r,n){e.call(this),this._moving=!1,this._zooming=!1,this.transform=r,this._bearingSnap=n.bearingSnap,t.bindAll(["_renderFrameCallback"],this)}return e&&(r.__proto__=e),r.prototype=Object.create(e&&e.prototype),r.prototype.constructor=r,r.prototype.getCenter=function(){return new t.LngLat(this.transform.center.lng,this.transform.center.lat)},r.prototype.setCenter=function(t,e){return this.jumpTo({center:t},e)},r.prototype.panBy=function(e,r,n){return e=t.Point.convert(e).mult(-1),this.panTo(this.transform.center,t.extend({offset:e},r),n)},r.prototype.panTo=function(e,r,n){return this.easeTo(t.extend({center:e},r),n)},r.prototype.getZoom=function(){return this.transform.zoom},r.prototype.setZoom=function(t,e){return this.jumpTo({zoom:t},e),this},r.prototype.zoomTo=function(e,r,n){return this.easeTo(t.extend({zoom:e},r),n)},r.prototype.zoomIn=function(t,e){return this.zoomTo(this.getZoom()+1,t,e),this},r.prototype.zoomOut=function(t,e){return this.zoomTo(this.getZoom()-1,t,e),this},r.prototype.getBearing=function(){return this.transform.bearing},r.prototype.setBearing=function(t,e){return this.jumpTo({bearing:t},e),this},r.prototype.getPadding=function(){return this.transform.padding},r.prototype.setPadding=function(t,e){return this.jumpTo({padding:t},e),this},r.prototype.rotateTo=function(e,r,n){return this.easeTo(t.extend({bearing:e},r),n)},r.prototype.resetNorth=function(e,r){return this.rotateTo(0,t.extend({duration:1e3},e),r),this},r.prototype.resetNorthPitch=function(e,r){return this.easeTo(t.extend({bearing:0,pitch:0,duration:1e3},e),r),this},r.prototype.snapToNorth=function(t,e){return Math.abs(this.getBearing())<this._bearingSnap?this.resetNorth(t,e):this},r.prototype.getPitch=function(){return this.transform.pitch},r.prototype.setPitch=function(t,e){return this.jumpTo({pitch:t},e),this},r.prototype.cameraForBounds=function(e,r){return e=t.LngLatBounds.convert(e),this._cameraForBoxAndBearing(e.getNorthWest(),e.getSouthEast(),0,r)},r.prototype._cameraForBoxAndBearing=function(e,r,n,i){var a={top:0,bottom:0,right:0,left:0};if("number"==typeof(i=t.extend({padding:a,offset:[0,0],maxZoom:this.transform.maxZoom},i)).padding){var o=i.padding;i.padding={top:o,bottom:o,right:o,left:o}}i.padding=t.extend(a,i.padding);var s=this.transform,l=s.padding,c=s.project(t.LngLat.convert(e)),u=s.project(t.LngLat.convert(r)),f=c.rotate(-n*Math.PI/180),h=u.rotate(-n*Math.PI/180),p=new t.Point(Math.max(f.x,h.x),Math.max(f.y,h.y)),d=new t.Point(Math.min(f.x,h.x),Math.min(f.y,h.y)),m=p.sub(d),g=(s.width-(l.left+l.right+i.padding.left+i.padding.right))/m.x,v=(s.height-(l.top+l.bottom+i.padding.top+i.padding.bottom))/m.y;if(!(v<0||g<0)){var y=Math.min(s.scaleZoom(s.scale*Math.min(g,v)),i.maxZoom),x=t.Point.convert(i.offset),b=(i.padding.left-i.padding.right)/2,_=(i.padding.top-i.padding.bottom)/2,w=new t.Point(x.x+b,x.y+_).mult(s.scale/s.zoomScale(y));return{center:s.unproject(c.add(u).div(2).sub(w)),zoom:y,bearing:n}}t.warnOnce("Map cannot fit within canvas with the given bounds, padding, and/or offset.")},r.prototype.fitBounds=function(t,e,r){return this._fitInternal(this.cameraForBounds(t,e),e,r)},r.prototype.fitScreenCoordinates=function(e,r,n,i,a){return this._fitInternal(this._cameraForBoxAndBearing(this.transform.pointLocation(t.Point.convert(e)),this.transform.pointLocation(t.Point.convert(r)),n,i),i,a)},r.prototype._fitInternal=function(e,r,n){return e?(delete(r=t.extend(e,r)).padding,r.linear?this.easeTo(r,n):this.flyTo(r,n)):this},r.prototype.jumpTo=function(e,r){this.stop();var n=this.transform,i=!1,a=!1,o=!1;return"zoom"in e&&n.zoom!==+e.zoom&&(i=!0,n.zoom=+e.zoom),void 0!==e.center&&(n.center=t.LngLat.convert(e.center)),"bearing"in e&&n.bearing!==+e.bearing&&(a=!0,n.bearing=+e.bearing),"pitch"in e&&n.pitch!==+e.pitch&&(o=!0,n.pitch=+e.pitch),null==e.padding||n.isPaddingEqual(e.padding)||(n.padding=e.padding),this.fire(new t.Event("movestart",r)).fire(new t.Event("move",r)),i&&this.fire(new t.Event("zoomstart",r)).fire(new t.Event("zoom",r)).fire(new t.Event("zoomend",r)),a&&this.fire(new t.Event("rotatestart",r)).fire(new t.Event("rotate",r)).fire(new t.Event("rotateend",r)),o&&this.fire(new t.Event("pitchstart",r)).fire(new t.Event("pitch",r)).fire(new t.Event("pitchend",r)),this.fire(new t.Event("moveend",r))},r.prototype.easeTo=function(e,r){var n=this;this._stop(!1,e.easeId),(!1===(e=t.extend({offset:[0,0],duration:500,easing:t.ease},e)).animate||!e.essential&&t.browser.prefersReducedMotion)&&(e.duration=0);var i=this.transform,a=this.getZoom(),o=this.getBearing(),s=this.getPitch(),l=this.getPadding(),c="zoom"in e?+e.zoom:a,u="bearing"in e?this._normalizeBearing(e.bearing,o):o,f="pitch"in e?+e.pitch:s,h="padding"in e?e.padding:i.padding,p=t.Point.convert(e.offset),d=i.centerPoint.add(p),m=i.pointLocation(d),g=t.LngLat.convert(e.center||m);this._normalizeCenter(g);var v,y,x=i.project(m),b=i.project(g).sub(x),_=i.zoomScale(c-a);e.around&&(v=t.LngLat.convert(e.around),y=i.locationPoint(v));var w={moving:this._moving,zooming:this._zooming,rotating:this._rotating,pitching:this._pitching};return this._zooming=this._zooming||c!==a,this._rotating=this._rotating||o!==u,this._pitching=this._pitching||f!==s,this._padding=!i.isPaddingEqual(h),this._easeId=e.easeId,this._prepareEase(r,e.noMoveStart,w),clearTimeout(this._easeEndTimeoutID),this._ease((function(e){if(n._zooming&&(i.zoom=t.number(a,c,e)),n._rotating&&(i.bearing=t.number(o,u,e)),n._pitching&&(i.pitch=t.number(s,f,e)),n._padding&&(i.interpolatePadding(l,h,e),d=i.centerPoint.add(p)),v)i.setLocationAtPoint(v,y);else{var m=i.zoomScale(i.zoom-a),g=c>a?Math.min(2,_):Math.max(.5,_),w=Math.pow(g,1-e),T=i.unproject(x.add(b.mult(e*w)).mult(m));i.setLocationAtPoint(i.renderWorldCopies?T.wrap():T,d)}n._fireMoveEvents(r)}),(function(t){n._afterEase(r,t)}),e),this},r.prototype._prepareEase=function(e,r,n){void 0===n&&(n={}),this._moving=!0,r||n.moving||this.fire(new t.Event("movestart",e)),this._zooming&&!n.zooming&&this.fire(new t.Event("zoomstart",e)),this._rotating&&!n.rotating&&this.fire(new t.Event("rotatestart",e)),this._pitching&&!n.pitching&&this.fire(new t.Event("pitchstart",e))},r.prototype._fireMoveEvents=function(e){this.fire(new t.Event("move",e)),this._zooming&&this.fire(new t.Event("zoom",e)),this._rotating&&this.fire(new t.Event("rotate",e)),this._pitching&&this.fire(new t.Event("pitch",e))},r.prototype._afterEase=function(e,r){if(!this._easeId||!r||this._easeId!==r){delete this._easeId;var n=this._zooming,i=this._rotating,a=this._pitching;this._moving=!1,this._zooming=!1,this._rotating=!1,this._pitching=!1,this._padding=!1,n&&this.fire(new t.Event("zoomend",e)),i&&this.fire(new t.Event("rotateend",e)),a&&this.fire(new t.Event("pitchend",e)),this.fire(new t.Event("moveend",e))}},r.prototype.flyTo=function(e,r){var n=this;if(!e.essential&&t.browser.prefersReducedMotion){var i=t.pick(e,["center","zoom","bearing","pitch","around"]);return this.jumpTo(i,r)}this.stop(),e=t.extend({offset:[0,0],speed:1.2,curve:1.42,easing:t.ease},e);var a=this.transform,o=this.getZoom(),s=this.getBearing(),l=this.getPitch(),c=this.getPadding(),u="zoom"in e?t.clamp(+e.zoom,a.minZoom,a.maxZoom):o,f="bearing"in e?this._normalizeBearing(e.bearing,s):s,h="pitch"in e?+e.pitch:l,p="padding"in e?e.padding:a.padding,d=a.zoomScale(u-o),m=t.Point.convert(e.offset),g=a.centerPoint.add(m),v=a.pointLocation(g),y=t.LngLat.convert(e.center||v);this._normalizeCenter(y);var x=a.project(v),b=a.project(y).sub(x),_=e.curve,w=Math.max(a.width,a.height),T=w/d,k=b.mag();if("minZoom"in e){var A=t.clamp(Math.min(e.minZoom,o,u),a.minZoom,a.maxZoom),M=w/a.zoomScale(A-o);_=Math.sqrt(M/k*2)}var S=_*_;function E(t){var e=(T*T-w*w+(t?-1:1)*S*S*k*k)/(2*(t?T:w)*S*k);return Math.log(Math.sqrt(e*e+1)-e)}function L(t){return(Math.exp(t)-Math.exp(-t))/2}function C(t){return(Math.exp(t)+Math.exp(-t))/2}var P=E(0),I=function(t){return C(P)/C(P+_*t)},O=function(t){return w*((C(P)*(L(e=P+_*t)/C(e))-L(P))/S)/k;var e},z=(E(1)-P)/_;if(Math.abs(k)<1e-6||!isFinite(z)){if(Math.abs(w-T)<1e-6)return this.easeTo(e,r);var D=T<w?-1:1;z=Math.abs(Math.log(T/w))/_,O=function(){return 0},I=function(t){return Math.exp(D*_*t)}}if("duration"in e)e.duration=+e.duration;else{var R="screenSpeed"in e?+e.screenSpeed/_:+e.speed;e.duration=1e3*z/R}return e.maxDuration&&e.duration>e.maxDuration&&(e.duration=0),this._zooming=!0,this._rotating=s!==f,this._pitching=h!==l,this._padding=!a.isPaddingEqual(p),this._prepareEase(r,!1),this._ease((function(e){var i=e*z,d=1/I(i);a.zoom=1===e?u:o+a.scaleZoom(d),n._rotating&&(a.bearing=t.number(s,f,e)),n._pitching&&(a.pitch=t.number(l,h,e)),n._padding&&(a.interpolatePadding(c,p,e),g=a.centerPoint.add(m));var v=1===e?y:a.unproject(x.add(b.mult(O(i))).mult(d));a.setLocationAtPoint(a.renderWorldCopies?v.wrap():v,g),n._fireMoveEvents(r)}),(function(){return n._afterEase(r)}),e),this},r.prototype.isEasing=function(){return!!this._easeFrameId},r.prototype.stop=function(){return this._stop()},r.prototype._stop=function(t,e){if(this._easeFrameId&&(this._cancelRenderFrame(this._easeFrameId),delete this._easeFrameId,delete this._onEaseFrame),this._onEaseEnd){var r=this._onEaseEnd;delete this._onEaseEnd,r.call(this,e)}if(!t){var n=this.handlers;n&&n.stop()}return this},r.prototype._ease=function(e,r,n){!1===n.animate||0===n.duration?(e(1),r()):(this._easeStart=t.browser.now(),this._easeOptions=n,this._onEaseFrame=e,this._onEaseEnd=r,this._easeFrameId=this._requestRenderFrame(this._renderFrameCallback))},r.prototype._renderFrameCallback=function(){var e=Math.min((t.browser.now()-this._easeStart)/this._easeOptions.duration,1);this._onEaseFrame(this._easeOptions.easing(e)),e<1?this._easeFrameId=this._requestRenderFrame(this._renderFrameCallback):this.stop()},r.prototype._normalizeBearing=function(e,r){e=t.wrap(e,-180,180);var n=Math.abs(e-r);return Math.abs(e-360-r)<n&&(e-=360),Math.abs(e+360-r)<n&&(e+=360),e},r.prototype._normalizeCenter=function(t){var e=this.transform;if(e.renderWorldCopies&&!e.lngRange){var r=t.lng-e.center.lng;t.lng+=r>180?-360:r<-180?360:0}},r}(t.Evented),bi=function(e){void 0===e&&(e={}),this.options=e,t.bindAll(["_updateEditLink","_updateData","_updateCompact"],this)};bi.prototype.getDefaultPosition=function(){return"bottom-right"},bi.prototype.onAdd=function(t){var e=this.options&&this.options.compact;return this._map=t,this._container=r.create("div","mapboxgl-ctrl mapboxgl-ctrl-attrib"),this._innerContainer=r.create("div","mapboxgl-ctrl-attrib-inner",this._container),e&&this._container.classList.add("mapboxgl-compact"),this._updateAttributions(),this._updateEditLink(),this._map.on("styledata",this._updateData),this._map.on("sourcedata",this._updateData),this._map.on("moveend",this._updateEditLink),void 0===e&&(this._map.on("resize",this._updateCompact),this._updateCompact()),this._container},bi.prototype.onRemove=function(){r.remove(this._container),this._map.off("styledata",this._updateData),this._map.off("sourcedata",this._updateData),this._map.off("moveend",this._updateEditLink),this._map.off("resize",this._updateCompact),this._map=void 0,this._attribHTML=void 0},bi.prototype._updateEditLink=function(){var e=this._editLink;e||(e=this._editLink=this._container.querySelector(".mapbox-improve-map"));var r=[{key:"owner",value:this.styleOwner},{key:"id",value:this.styleId},{key:"access_token",value:this._map._requestManager._customAccessToken||t.config.ACCESS_TOKEN}];if(e){var n=r.reduce((function(t,e,n){return e.value&&(t+=e.key+"="+e.value+(n<r.length-1?"&":"")),t}),"?");e.href=t.config.FEEDBACK_URL+"/"+n+(this._map._hash?this._map._hash.getHashString(!0):""),e.rel="noopener nofollow"}},bi.prototype._updateData=function(t){!t||"metadata"!==t.sourceDataType&&"style"!==t.dataType||(this._updateAttributions(),this._updateEditLink())},bi.prototype._updateAttributions=function(){if(this._map.style){var t=[];if(this.options.customAttribution&&(Array.isArray(this.options.customAttribution)?t=t.concat(this.options.customAttribution.map((function(t){return"string"!=typeof t?"":t}))):"string"==typeof this.options.customAttribution&&t.push(this.options.customAttribution)),this._map.style.stylesheet){var e=this._map.style.stylesheet;this.styleOwner=e.owner,this.styleId=e.id}var r=this._map.style.sourceCaches;for(var n in r){var i=r[n];if(i.used){var a=i.getSource();a.attribution&&t.indexOf(a.attribution)<0&&t.push(a.attribution)}}t.sort((function(t,e){return t.length-e.length}));var o=(t=t.filter((function(e,r){for(var n=r+1;n<t.length;n++)if(t[n].indexOf(e)>=0)return!1;return!0}))).join(" | ");o!==this._attribHTML&&(this._attribHTML=o,t.length?(this._innerContainer.innerHTML=o,this._container.classList.remove("mapboxgl-attrib-empty")):this._container.classList.add("mapboxgl-attrib-empty"),this._editLink=null)}},bi.prototype._updateCompact=function(){this._map.getCanvasContainer().offsetWidth<=640?this._container.classList.add("mapboxgl-compact"):this._container.classList.remove("mapboxgl-compact")};var _i=function(){t.bindAll(["_updateLogo"],this),t.bindAll(["_updateCompact"],this)};_i.prototype.onAdd=function(t){this._map=t,this._container=r.create("div","mapboxgl-ctrl");var e=r.create("a","mapboxgl-ctrl-logo");return e.target="_blank",e.rel="noopener nofollow",e.href="https://www.mapbox.com/",e.setAttribute("aria-label",this._map._getUIString("LogoControl.Title")),e.setAttribute("rel","noopener nofollow"),this._container.appendChild(e),this._container.style.display="none",this._map.on("sourcedata",this._updateLogo),this._updateLogo(),this._map.on("resize",this._updateCompact),this._updateCompact(),this._container},_i.prototype.onRemove=function(){r.remove(this._container),this._map.off("sourcedata",this._updateLogo),this._map.off("resize",this._updateCompact)},_i.prototype.getDefaultPosition=function(){return"bottom-left"},_i.prototype._updateLogo=function(t){t&&"metadata"!==t.sourceDataType||(this._container.style.display=this._logoRequired()?"block":"none")},_i.prototype._logoRequired=function(){if(this._map.style){var t=this._map.style.sourceCaches;for(var e in t){if(t[e].getSource().mapbox_logo)return!0}return!1}},_i.prototype._updateCompact=function(){var t=this._container.children;if(t.length){var e=t[0];this._map.getCanvasContainer().offsetWidth<250?e.classList.add("mapboxgl-compact"):e.classList.remove("mapboxgl-compact")}};var wi=function(){this._queue=[],this._id=0,this._cleared=!1,this._currentlyRunning=!1};wi.prototype.add=function(t){var e=++this._id;return this._queue.push({callback:t,id:e,cancelled:!1}),e},wi.prototype.remove=function(t){for(var e=this._currentlyRunning,r=0,n=e?this._queue.concat(e):this._queue;r<n.length;r+=1){var i=n[r];if(i.id===t)return void(i.cancelled=!0)}},wi.prototype.run=function(t){void 0===t&&(t=0);var e=this._currentlyRunning=this._queue;this._queue=[];for(var r=0,n=e;r<n.length;r+=1){var i=n[r];if(!i.cancelled&&(i.callback(t),this._cleared))break}this._cleared=!1,this._currentlyRunning=!1},wi.prototype.clear=function(){this._currentlyRunning&&(this._cleared=!0),this._queue=[]};var Ti={"FullscreenControl.Enter":"Enter fullscreen","FullscreenControl.Exit":"Exit fullscreen","GeolocateControl.FindMyLocation":"Find my location","GeolocateControl.LocationNotAvailable":"Location not available","LogoControl.Title":"Mapbox logo","NavigationControl.ResetBearing":"Reset bearing to north","NavigationControl.ZoomIn":"Zoom in","NavigationControl.ZoomOut":"Zoom out","ScaleControl.Feet":"ft","ScaleControl.Meters":"m","ScaleControl.Kilometers":"km","ScaleControl.Miles":"mi","ScaleControl.NauticalMiles":"nm"},ki=t.window.HTMLImageElement,Ai=t.window.HTMLElement,Mi=t.window.ImageBitmap,Si={center:[0,0],zoom:0,bearing:0,pitch:0,minZoom:-2,maxZoom:22,minPitch:0,maxPitch:60,interactive:!0,scrollZoom:!0,boxZoom:!0,dragRotate:!0,dragPan:!0,keyboard:!0,doubleClickZoom:!0,touchZoomRotate:!0,touchPitch:!0,bearingSnap:7,clickTolerance:3,pitchWithRotate:!0,hash:!1,attributionControl:!0,failIfMajorPerformanceCaveat:!1,preserveDrawingBuffer:!1,trackResize:!0,renderWorldCopies:!0,refreshExpiredTiles:!0,maxTileCacheSize:null,localIdeographFontFamily:"sans-serif",transformRequest:null,accessToken:null,fadeDuration:300,crossSourceCollisions:!0},Ei=function(n){function i(e){var r=this;if(null!=(e=t.extend({},Si,e)).minZoom&&null!=e.maxZoom&&e.minZoom>e.maxZoom)throw new Error("maxZoom must be greater than or equal to minZoom");if(null!=e.minPitch&&null!=e.maxPitch&&e.minPitch>e.maxPitch)throw new Error("maxPitch must be greater than or equal to minPitch");if(null!=e.minPitch&&e.minPitch<0)throw new Error("minPitch must be greater than or equal to 0");if(null!=e.maxPitch&&e.maxPitch>60)throw new Error("maxPitch must be less than or equal to 60");var i=new An(e.minZoom,e.maxZoom,e.minPitch,e.maxPitch,e.renderWorldCopies);if(n.call(this,i,e),this._interactive=e.interactive,this._maxTileCacheSize=e.maxTileCacheSize,this._failIfMajorPerformanceCaveat=e.failIfMajorPerformanceCaveat,this._preserveDrawingBuffer=e.preserveDrawingBuffer,this._antialias=e.antialias,this._trackResize=e.trackResize,this._bearingSnap=e.bearingSnap,this._refreshExpiredTiles=e.refreshExpiredTiles,this._fadeDuration=e.fadeDuration,this._crossSourceCollisions=e.crossSourceCollisions,this._crossFadingFactor=1,this._collectResourceTiming=e.collectResourceTiming,this._renderTaskQueue=new wi,this._controls=[],this._mapId=t.uniqueId(),this._locale=t.extend({},Ti,e.locale),this._requestManager=new t.RequestManager(e.transformRequest,e.accessToken),"string"==typeof e.container){if(this._container=t.window.document.getElementById(e.container),!this._container)throw new Error("Container '"+e.container+"' not found.")}else{if(!(e.container instanceof Ai))throw new Error("Invalid type: 'container' must be a String or HTMLElement.");this._container=e.container}if(e.maxBounds&&this.setMaxBounds(e.maxBounds),t.bindAll(["_onWindowOnline","_onWindowResize","_contextLost","_contextRestored"],this),this._setupContainer(),this._setupPainter(),void 0===this.painter)throw new Error("Failed to initialize WebGL.");this.on("move",(function(){return r._update(!1)})),this.on("moveend",(function(){return r._update(!1)})),this.on("zoom",(function(){return r._update(!0)})),void 0!==t.window&&(t.window.addEventListener("online",this._onWindowOnline,!1),t.window.addEventListener("resize",this._onWindowResize,!1)),this.handlers=new yi(this,e);var a="string"==typeof e.hash&&e.hash||void 0;this._hash=e.hash&&new Sn(a).addTo(this),this._hash&&this._hash._onHashChange()||(this.jumpTo({center:e.center,zoom:e.zoom,bearing:e.bearing,pitch:e.pitch}),e.bounds&&(this.resize(),this.fitBounds(e.bounds,t.extend({},e.fitBoundsOptions,{duration:0})))),this.resize(),this._localIdeographFontFamily=e.localIdeographFontFamily,e.style&&this.setStyle(e.style,{localIdeographFontFamily:e.localIdeographFontFamily}),e.attributionControl&&this.addControl(new bi({customAttribution:e.customAttribution})),this.addControl(new _i,e.logoPosition),this.on("style.load",(function(){r.transform.unmodified&&r.jumpTo(r.style.stylesheet)})),this.on("data",(function(e){r._update("style"===e.dataType),r.fire(new t.Event(e.dataType+"data",e))})),this.on("dataloading",(function(e){r.fire(new t.Event(e.dataType+"dataloading",e))}))}n&&(i.__proto__=n),i.prototype=Object.create(n&&n.prototype),i.prototype.constructor=i;var a={showTileBoundaries:{configurable:!0},showPadding:{configurable:!0},showCollisionBoxes:{configurable:!0},showOverdrawInspector:{configurable:!0},repaint:{configurable:!0},vertices:{configurable:!0},version:{configurable:!0}};return i.prototype._getMapId=function(){return this._mapId},i.prototype.addControl=function(e,r){if(void 0===r&&e.getDefaultPosition&&(r=e.getDefaultPosition()),void 0===r&&(r="top-right"),!e||!e.onAdd)return this.fire(new t.ErrorEvent(new Error("Invalid argument to map.addControl(). Argument must be a control with onAdd and onRemove methods.")));var n=e.onAdd(this);this._controls.push(e);var i=this._controlPositions[r];return-1!==r.indexOf("bottom")?i.insertBefore(n,i.firstChild):i.appendChild(n),this},i.prototype.removeControl=function(e){if(!e||!e.onRemove)return this.fire(new t.ErrorEvent(new Error("Invalid argument to map.removeControl(). Argument must be a control with onAdd and onRemove methods.")));var r=this._controls.indexOf(e);return r>-1&&this._controls.splice(r,1),e.onRemove(this),this},i.prototype.resize=function(e){var r=this._containerDimensions(),n=r[0],i=r[1];this._resizeCanvas(n,i),this.transform.resize(n,i),this.painter.resize(n,i);var a=!this._moving;return a&&(this.stop(),this.fire(new t.Event("movestart",e)).fire(new t.Event("move",e))),this.fire(new t.Event("resize",e)),a&&this.fire(new t.Event("moveend",e)),this},i.prototype.getBounds=function(){return this.transform.getBounds()},i.prototype.getMaxBounds=function(){return this.transform.getMaxBounds()},i.prototype.setMaxBounds=function(e){return this.transform.setMaxBounds(t.LngLatBounds.convert(e)),this._update()},i.prototype.setMinZoom=function(t){if((t=null==t?-2:t)>=-2&&t<=this.transform.maxZoom)return this.transform.minZoom=t,this._update(),this.getZoom()<t&&this.setZoom(t),this;throw new Error("minZoom must be between -2 and the current maxZoom, inclusive")},i.prototype.getMinZoom=function(){return this.transform.minZoom},i.prototype.setMaxZoom=function(t){if((t=null==t?22:t)>=this.transform.minZoom)return this.transform.maxZoom=t,this._update(),this.getZoom()>t&&this.setZoom(t),this;throw new Error("maxZoom must be greater than the current minZoom")},i.prototype.getMaxZoom=function(){return this.transform.maxZoom},i.prototype.setMinPitch=function(t){if((t=null==t?0:t)<0)throw new Error("minPitch must be greater than or equal to 0");if(t>=0&&t<=this.transform.maxPitch)return this.transform.minPitch=t,this._update(),this.getPitch()<t&&this.setPitch(t),this;throw new Error("minPitch must be between 0 and the current maxPitch, inclusive")},i.prototype.getMinPitch=function(){return this.transform.minPitch},i.prototype.setMaxPitch=function(t){if((t=null==t?60:t)>60)throw new Error("maxPitch must be less than or equal to 60");if(t>=this.transform.minPitch)return this.transform.maxPitch=t,this._update(),this.getPitch()>t&&this.setPitch(t),this;throw new Error("maxPitch must be greater than the current minPitch")},i.prototype.getMaxPitch=function(){return this.transform.maxPitch},i.prototype.getRenderWorldCopies=function(){return this.transform.renderWorldCopies},i.prototype.setRenderWorldCopies=function(t){return this.transform.renderWorldCopies=t,this._update()},i.prototype.project=function(e){return this.transform.locationPoint(t.LngLat.convert(e))},i.prototype.unproject=function(e){return this.transform.pointLocation(t.Point.convert(e))},i.prototype.isMoving=function(){return this._moving||this.handlers.isMoving()},i.prototype.isZooming=function(){return this._zooming||this.handlers.isZooming()},i.prototype.isRotating=function(){return this._rotating||this.handlers.isRotating()},i.prototype._createDelegatedListener=function(t,e,r){var n,i=this;if("mouseenter"===t||"mouseover"===t){var a=!1;return{layer:e,listener:r,delegates:{mousemove:function(n){var o=i.getLayer(e)?i.queryRenderedFeatures(n.point,{layers:[e]}):[];o.length?a||(a=!0,r.call(i,new Rn(t,i,n.originalEvent,{features:o}))):a=!1},mouseout:function(){a=!1}}}}if("mouseleave"===t||"mouseout"===t){var o=!1;return{layer:e,listener:r,delegates:{mousemove:function(n){(i.getLayer(e)?i.queryRenderedFeatures(n.point,{layers:[e]}):[]).length?o=!0:o&&(o=!1,r.call(i,new Rn(t,i,n.originalEvent)))},mouseout:function(e){o&&(o=!1,r.call(i,new Rn(t,i,e.originalEvent)))}}}}return{layer:e,listener:r,delegates:(n={},n[t]=function(t){var n=i.getLayer(e)?i.queryRenderedFeatures(t.point,{layers:[e]}):[];n.length&&(t.features=n,r.call(i,t),delete t.features)},n)}},i.prototype.on=function(t,e,r){if(void 0===r)return n.prototype.on.call(this,t,e);var i=this._createDelegatedListener(t,e,r);for(var a in this._delegatedListeners=this._delegatedListeners||{},this._delegatedListeners[t]=this._delegatedListeners[t]||[],this._delegatedListeners[t].push(i),i.delegates)this.on(a,i.delegates[a]);return this},i.prototype.once=function(t,e,r){if(void 0===r)return n.prototype.once.call(this,t,e);var i=this._createDelegatedListener(t,e,r);for(var a in i.delegates)this.once(a,i.delegates[a]);return this},i.prototype.off=function(t,e,r){var i=this;if(void 0===r)return n.prototype.off.call(this,t,e);return this._delegatedListeners&&this._delegatedListeners[t]&&function(n){for(var a=n[t],o=0;o<a.length;o++){var s=a[o];if(s.layer===e&&s.listener===r){for(var l in s.delegates)i.off(l,s.delegates[l]);return a.splice(o,1),i}}}(this._delegatedListeners),this},i.prototype.queryRenderedFeatures=function(e,r){if(!this.style)return[];var n;if(void 0!==r||void 0===e||e instanceof t.Point||Array.isArray(e)||(r=e,e=void 0),r=r||{},(e=e||[[0,0],[this.transform.width,this.transform.height]])instanceof t.Point||"number"==typeof e[0])n=[t.Point.convert(e)];else{var i=t.Point.convert(e[0]),a=t.Point.convert(e[1]);n=[i,new t.Point(a.x,i.y),a,new t.Point(i.x,a.y),i]}return this.style.queryRenderedFeatures(n,r,this.transform)},i.prototype.querySourceFeatures=function(t,e){return this.style.querySourceFeatures(t,e)},i.prototype.setStyle=function(e,r){return!1!==(r=t.extend({},{localIdeographFontFamily:this._localIdeographFontFamily},r)).diff&&r.localIdeographFontFamily===this._localIdeographFontFamily&&this.style&&e?(this._diffStyle(e,r),this):(this._localIdeographFontFamily=r.localIdeographFontFamily,this._updateStyle(e,r))},i.prototype._getUIString=function(t){var e=this._locale[t];if(null==e)throw new Error("Missing UI string '"+t+"'");return e},i.prototype._updateStyle=function(t,e){return this.style&&(this.style.setEventedParent(null),this.style._remove()),t?(this.style=new qe(this,e||{}),this.style.setEventedParent(this,{style:this.style}),"string"==typeof t?this.style.loadURL(t):this.style.loadJSON(t),this):(delete this.style,this)},i.prototype._lazyInitEmptyStyle=function(){this.style||(this.style=new qe(this,{}),this.style.setEventedParent(this,{style:this.style}),this.style.loadEmpty())},i.prototype._diffStyle=function(e,r){var n=this;if("string"==typeof e){var i=this._requestManager.normalizeStyleURL(e),a=this._requestManager.transformRequest(i,t.ResourceType.Style);t.getJSON(a,(function(e,i){e?n.fire(new t.ErrorEvent(e)):i&&n._updateDiff(i,r)}))}else"object"==typeof e&&this._updateDiff(e,r)},i.prototype._updateDiff=function(e,r){try{this.style.setState(e)&&this._update(!0)}catch(n){t.warnOnce("Unable to perform style diff: "+(n.message||n.error||n)+".  Rebuilding the style from scratch."),this._updateStyle(e,r)}},i.prototype.getStyle=function(){if(this.style)return this.style.serialize()},i.prototype.isStyleLoaded=function(){return this.style?this.style.loaded():t.warnOnce("There is no style added to the map.")},i.prototype.addSource=function(t,e){return this._lazyInitEmptyStyle(),this.style.addSource(t,e),this._update(!0)},i.prototype.isSourceLoaded=function(e){var r=this.style&&this.style.sourceCaches[e];if(void 0!==r)return r.loaded();this.fire(new t.ErrorEvent(new Error("There is no source with ID '"+e+"'")))},i.prototype.areTilesLoaded=function(){var t=this.style&&this.style.sourceCaches;for(var e in t){var r=t[e]._tiles;for(var n in r){var i=r[n];if("loaded"!==i.state&&"errored"!==i.state)return!1}}return!0},i.prototype.addSourceType=function(t,e,r){return this._lazyInitEmptyStyle(),this.style.addSourceType(t,e,r)},i.prototype.removeSource=function(t){return this.style.removeSource(t),this._update(!0)},i.prototype.getSource=function(t){return this.style.getSource(t)},i.prototype.addImage=function(e,r,n){void 0===n&&(n={});var i=n.pixelRatio;void 0===i&&(i=1);var a=n.sdf;void 0===a&&(a=!1);var o=n.stretchX,s=n.stretchY,l=n.content;this._lazyInitEmptyStyle();if(r instanceof ki||Mi&&r instanceof Mi){var c=t.browser.getImageData(r),u=c.width,f=c.height,h=c.data;this.style.addImage(e,{data:new t.RGBAImage({width:u,height:f},h),pixelRatio:i,stretchX:o,stretchY:s,content:l,sdf:a,version:0})}else{if(void 0===r.width||void 0===r.height)return this.fire(new t.ErrorEvent(new Error("Invalid arguments to map.addImage(). The second argument must be an `HTMLImageElement`, `ImageData`, `ImageBitmap`, or object with `width`, `height`, and `data` properties with the same format as `ImageData`")));var p=r.width,d=r.height,m=r.data,g=r;this.style.addImage(e,{data:new t.RGBAImage({width:p,height:d},new Uint8Array(m)),pixelRatio:i,stretchX:o,stretchY:s,content:l,sdf:a,version:0,userImage:g}),g.onAdd&&g.onAdd(this,e)}},i.prototype.updateImage=function(e,r){var n=this.style.getImage(e);if(!n)return this.fire(new t.ErrorEvent(new Error("The map has no image with that id. If you are adding a new image use `map.addImage(...)` instead.")));var i=r instanceof ki||Mi&&r instanceof Mi?t.browser.getImageData(r):r,a=i.width,o=i.height,s=i.data;if(void 0===a||void 0===o)return this.fire(new t.ErrorEvent(new Error("Invalid arguments to map.updateImage(). The second argument must be an `HTMLImageElement`, `ImageData`, `ImageBitmap`, or object with `width`, `height`, and `data` properties with the same format as `ImageData`")));if(a!==n.data.width||o!==n.data.height)return this.fire(new t.ErrorEvent(new Error("The width and height of the updated image must be that same as the previous version of the image")));var l=!(r instanceof ki||Mi&&r instanceof Mi);n.data.replace(s,l),this.style.updateImage(e,n)},i.prototype.hasImage=function(e){return e?!!this.style.getImage(e):(this.fire(new t.ErrorEvent(new Error("Missing required image id"))),!1)},i.prototype.removeImage=function(t){this.style.removeImage(t)},i.prototype.loadImage=function(e,r){t.getImage(this._requestManager.transformRequest(e,t.ResourceType.Image),r)},i.prototype.listImages=function(){return this.style.listImages()},i.prototype.addLayer=function(t,e){return this._lazyInitEmptyStyle(),this.style.addLayer(t,e),this._update(!0)},i.prototype.moveLayer=function(t,e){return this.style.moveLayer(t,e),this._update(!0)},i.prototype.removeLayer=function(t){return this.style.removeLayer(t),this._update(!0)},i.prototype.getLayer=function(t){return this.style.getLayer(t)},i.prototype.setLayerZoomRange=function(t,e,r){return this.style.setLayerZoomRange(t,e,r),this._update(!0)},i.prototype.setFilter=function(t,e,r){return void 0===r&&(r={}),this.style.setFilter(t,e,r),this._update(!0)},i.prototype.getFilter=function(t){return this.style.getFilter(t)},i.prototype.setPaintProperty=function(t,e,r,n){return void 0===n&&(n={}),this.style.setPaintProperty(t,e,r,n),this._update(!0)},i.prototype.getPaintProperty=function(t,e){return this.style.getPaintProperty(t,e)},i.prototype.setLayoutProperty=function(t,e,r,n){return void 0===n&&(n={}),this.style.setLayoutProperty(t,e,r,n),this._update(!0)},i.prototype.getLayoutProperty=function(t,e){return this.style.getLayoutProperty(t,e)},i.prototype.setLight=function(t,e){return void 0===e&&(e={}),this._lazyInitEmptyStyle(),this.style.setLight(t,e),this._update(!0)},i.prototype.getLight=function(){return this.style.getLight()},i.prototype.setFeatureState=function(t,e){return this.style.setFeatureState(t,e),this._update()},i.prototype.removeFeatureState=function(t,e){return this.style.removeFeatureState(t,e),this._update()},i.prototype.getFeatureState=function(t){return this.style.getFeatureState(t)},i.prototype.getContainer=function(){return this._container},i.prototype.getCanvasContainer=function(){return this._canvasContainer},i.prototype.getCanvas=function(){return this._canvas},i.prototype._containerDimensions=function(){var t=0,e=0;return this._container&&(t=this._container.clientWidth||400,e=this._container.clientHeight||300),[t,e]},i.prototype._detectMissingCSS=function(){"rgb(250, 128, 114)"!==t.window.getComputedStyle(this._missingCSSCanary).getPropertyValue("background-color")&&t.warnOnce("This page appears to be missing CSS declarations for Mapbox GL JS, which may cause the map to display incorrectly. Please ensure your page includes mapbox-gl.css, as described in https://www.mapbox.com/mapbox-gl-js/api/.")},i.prototype._setupContainer=function(){var t=this._container;t.classList.add("mapboxgl-map"),(this._missingCSSCanary=r.create("div","mapboxgl-canary",t)).style.visibility="hidden",this._detectMissingCSS();var e=this._canvasContainer=r.create("div","mapboxgl-canvas-container",t);this._interactive&&e.classList.add("mapboxgl-interactive"),this._canvas=r.create("canvas","mapboxgl-canvas",e),this._canvas.addEventListener("webglcontextlost",this._contextLost,!1),this._canvas.addEventListener("webglcontextrestored",this._contextRestored,!1),this._canvas.setAttribute("tabindex","0"),this._canvas.setAttribute("aria-label","Map");var n=this._containerDimensions();this._resizeCanvas(n[0],n[1]);var i=this._controlContainer=r.create("div","mapboxgl-control-container",t),a=this._controlPositions={};["top-left","top-right","bottom-left","bottom-right"].forEach((function(t){a[t]=r.create("div","mapboxgl-ctrl-"+t,i)}))},i.prototype._resizeCanvas=function(e,r){var n=t.browser.devicePixelRatio||1;this._canvas.width=n*e,this._canvas.height=n*r,this._canvas.style.width=e+"px",this._canvas.style.height=r+"px"},i.prototype._setupPainter=function(){var r=t.extend({},e.webGLContextAttributes,{failIfMajorPerformanceCaveat:this._failIfMajorPerformanceCaveat,preserveDrawingBuffer:this._preserveDrawingBuffer,antialias:this._antialias||!1}),n=this._canvas.getContext("webgl",r)||this._canvas.getContext("experimental-webgl",r);n?(this.painter=new _n(n,this.transform),t.webpSupported.testSupport(n)):this.fire(new t.ErrorEvent(new Error("Failed to initialize WebGL")))},i.prototype._contextLost=function(e){e.preventDefault(),this._frame&&(this._frame.cancel(),this._frame=null),this.fire(new t.Event("webglcontextlost",{originalEvent:e}))},i.prototype._contextRestored=function(e){this._setupPainter(),this.resize(),this._update(),this.fire(new t.Event("webglcontextrestored",{originalEvent:e}))},i.prototype.loaded=function(){return!this._styleDirty&&!this._sourcesDirty&&!!this.style&&this.style.loaded()},i.prototype._update=function(t){return this.style?(this._styleDirty=this._styleDirty||t,this._sourcesDirty=!0,this.triggerRepaint(),this):this},i.prototype._requestRenderFrame=function(t){return this._update(),this._renderTaskQueue.add(t)},i.prototype._cancelRenderFrame=function(t){this._renderTaskQueue.remove(t)},i.prototype._render=function(e){var r,n=this,i=0,a=this.painter.context.extTimerQuery;if(this.listens("gpu-timing-frame")&&(r=a.createQueryEXT(),a.beginQueryEXT(a.TIME_ELAPSED_EXT,r),i=t.browser.now()),this.painter.context.setDirty(),this.painter.setBaseState(),this._renderTaskQueue.run(e),!this._removed){var o=!1;if(this.style&&this._styleDirty){this._styleDirty=!1;var s=this.transform.zoom,l=t.browser.now();this.style.zoomHistory.update(s,l);var c=new t.EvaluationParameters(s,{now:l,fadeDuration:this._fadeDuration,zoomHistory:this.style.zoomHistory,transition:this.style.getTransition()}),u=c.crossFadingFactor();1===u&&u===this._crossFadingFactor||(o=!0,this._crossFadingFactor=u),this.style.update(c)}if(this.style&&this._sourcesDirty&&(this._sourcesDirty=!1,this.style._updateSources(this.transform)),this._placementDirty=this.style&&this.style._updatePlacement(this.painter.transform,this.showCollisionBoxes,this._fadeDuration,this._crossSourceCollisions),this.painter.render(this.style,{showTileBoundaries:this.showTileBoundaries,showOverdrawInspector:this._showOverdrawInspector,rotating:this.isRotating(),zooming:this.isZooming(),moving:this.isMoving(),fadeDuration:this._fadeDuration,showPadding:this.showPadding,gpuTiming:!!this.listens("gpu-timing-layer")}),this.fire(new t.Event("render")),this.loaded()&&!this._loaded&&(this._loaded=!0,this.fire(new t.Event("load"))),this.style&&(this.style.hasTransitions()||o)&&(this._styleDirty=!0),this.style&&!this._placementDirty&&this.style._releaseSymbolFadeTiles(),this.listens("gpu-timing-frame")){var f=t.browser.now()-i;a.endQueryEXT(a.TIME_ELAPSED_EXT,r),setTimeout((function(){var e=a.getQueryObjectEXT(r,a.QUERY_RESULT_EXT)/1e6;a.deleteQueryEXT(r),n.fire(new t.Event("gpu-timing-frame",{cpuTime:f,gpuTime:e}))}),50)}if(this.listens("gpu-timing-layer")){var h=this.painter.collectGpuTimers();setTimeout((function(){var e=n.painter.queryGpuTimers(h);n.fire(new t.Event("gpu-timing-layer",{layerTimes:e}))}),50)}return this._sourcesDirty||this._styleDirty||this._placementDirty||this._repaint?this.triggerRepaint():!this.isMoving()&&this.loaded()&&(this._fullyLoaded||(this._fullyLoaded=!0),this.fire(new t.Event("idle"))),this}},i.prototype.remove=function(){this._hash&&this._hash.remove();for(var e=0,r=this._controls;e<r.length;e+=1){r[e].onRemove(this)}this._controls=[],this._frame&&(this._frame.cancel(),this._frame=null),this._renderTaskQueue.clear(),this.painter.destroy(),this.handlers.destroy(),delete this.handlers,this.setStyle(null),void 0!==t.window&&(t.window.removeEventListener("resize",this._onWindowResize,!1),t.window.removeEventListener("online",this._onWindowOnline,!1));var n=this.painter.context.gl.getExtension("WEBGL_lose_context");n&&n.loseContext(),Li(this._canvasContainer),Li(this._controlContainer),Li(this._missingCSSCanary),this._container.classList.remove("mapboxgl-map"),this._removed=!0,this.fire(new t.Event("remove"))},i.prototype.triggerRepaint=function(){var e=this;this.style&&!this._frame&&(this._frame=t.browser.frame((function(t){e._frame=null,e._render(t)})))},i.prototype._onWindowOnline=function(){this._update()},i.prototype._onWindowResize=function(t){this._trackResize&&this.resize({originalEvent:t})._update()},a.showTileBoundaries.get=function(){return!!this._showTileBoundaries},a.showTileBoundaries.set=function(t){this._showTileBoundaries!==t&&(this._showTileBoundaries=t,this._update())},a.showPadding.get=function(){return!!this._showPadding},a.showPadding.set=function(t){this._showPadding!==t&&(this._showPadding=t,this._update())},a.showCollisionBoxes.get=function(){return!!this._showCollisionBoxes},a.showCollisionBoxes.set=function(t){this._showCollisionBoxes!==t&&(this._showCollisionBoxes=t,t?this.style._generateCollisionBoxes():this._update())},a.showOverdrawInspector.get=function(){return!!this._showOverdrawInspector},a.showOverdrawInspector.set=function(t){this._showOverdrawInspector!==t&&(this._showOverdrawInspector=t,this._update())},a.repaint.get=function(){return!!this._repaint},a.repaint.set=function(t){this._repaint!==t&&(this._repaint=t,this.triggerRepaint())},a.vertices.get=function(){return!!this._vertices},a.vertices.set=function(t){this._vertices=t,this._update()},i.prototype._setCacheLimits=function(e,r){t.setCacheLimits(e,r)},a.version.get=function(){return t.version},Object.defineProperties(i.prototype,a),i}(xi);function Li(t){t.parentNode&&t.parentNode.removeChild(t)}var Ci={showCompass:!0,showZoom:!0,visualizePitch:!1},Pi=function(e){var n=this;this.options=t.extend({},Ci,e),this._container=r.create("div","mapboxgl-ctrl mapboxgl-ctrl-group"),this._container.addEventListener("contextmenu",(function(t){return t.preventDefault()})),this.options.showZoom&&(t.bindAll(["_setButtonTitle","_updateZoomButtons"],this),this._zoomInButton=this._createButton("mapboxgl-ctrl-zoom-in",(function(t){return n._map.zoomIn({},{originalEvent:t})})),r.create("span","mapboxgl-ctrl-icon",this._zoomInButton).setAttribute("aria-hidden",!0),this._zoomOutButton=this._createButton("mapboxgl-ctrl-zoom-out",(function(t){return n._map.zoomOut({},{originalEvent:t})})),r.create("span","mapboxgl-ctrl-icon",this._zoomOutButton).setAttribute("aria-hidden",!0)),this.options.showCompass&&(t.bindAll(["_rotateCompassArrow"],this),this._compass=this._createButton("mapboxgl-ctrl-compass",(function(t){n.options.visualizePitch?n._map.resetNorthPitch({},{originalEvent:t}):n._map.resetNorth({},{originalEvent:t})})),this._compassIcon=r.create("span","mapboxgl-ctrl-icon",this._compass),this._compassIcon.setAttribute("aria-hidden",!0))};Pi.prototype._updateZoomButtons=function(){var t=this._map.getZoom();this._zoomInButton.disabled=t===this._map.getMaxZoom(),this._zoomOutButton.disabled=t===this._map.getMinZoom()},Pi.prototype._rotateCompassArrow=function(){var t=this.options.visualizePitch?"scale("+1/Math.pow(Math.cos(this._map.transform.pitch*(Math.PI/180)),.5)+") rotateX("+this._map.transform.pitch+"deg) rotateZ("+this._map.transform.angle*(180/Math.PI)+"deg)":"rotate("+this._map.transform.angle*(180/Math.PI)+"deg)";this._compassIcon.style.transform=t},Pi.prototype.onAdd=function(t){return this._map=t,this.options.showZoom&&(this._setButtonTitle(this._zoomInButton,"ZoomIn"),this._setButtonTitle(this._zoomOutButton,"ZoomOut"),this._map.on("zoom",this._updateZoomButtons),this._updateZoomButtons()),this.options.showCompass&&(this._setButtonTitle(this._compass,"ResetBearing"),this.options.visualizePitch&&this._map.on("pitch",this._rotateCompassArrow),this._map.on("rotate",this._rotateCompassArrow),this._rotateCompassArrow(),this._handler=new Ii(this._map,this._compass,this.options.visualizePitch)),this._container},Pi.prototype.onRemove=function(){r.remove(this._container),this.options.showZoom&&this._map.off("zoom",this._updateZoomButtons),this.options.showCompass&&(this.options.visualizePitch&&this._map.off("pitch",this._rotateCompassArrow),this._map.off("rotate",this._rotateCompassArrow),this._handler.off(),delete this._handler),delete this._map},Pi.prototype._createButton=function(t,e){var n=r.create("button",t,this._container);return n.type="button",n.addEventListener("click",e),n},Pi.prototype._setButtonTitle=function(t,e){var r=this._map._getUIString("NavigationControl."+e);t.title=r,t.setAttribute("aria-label",r)};var Ii=function(e,n,i){void 0===i&&(i=!1),this._clickTolerance=10,this.element=n,this.mouseRotate=new Xn({clickTolerance:e.dragRotate._mouseRotate._clickTolerance}),this.map=e,i&&(this.mousePitch=new Zn({clickTolerance:e.dragRotate._mousePitch._clickTolerance})),t.bindAll(["mousedown","mousemove","mouseup","touchstart","touchmove","touchend","reset"],this),r.addEventListener(n,"mousedown",this.mousedown),r.addEventListener(n,"touchstart",this.touchstart,{passive:!1}),r.addEventListener(n,"touchmove",this.touchmove),r.addEventListener(n,"touchend",this.touchend),r.addEventListener(n,"touchcancel",this.reset)};function Oi(e,r,n){if(e=new t.LngLat(e.lng,e.lat),r){var i=new t.LngLat(e.lng-360,e.lat),a=new t.LngLat(e.lng+360,e.lat),o=n.locationPoint(e).distSqr(r);n.locationPoint(i).distSqr(r)<o?e=i:n.locationPoint(a).distSqr(r)<o&&(e=a)}for(;Math.abs(e.lng-n.center.lng)>180;){var s=n.locationPoint(e);if(s.x>=0&&s.y>=0&&s.x<=n.width&&s.y<=n.height)break;e.lng>n.center.lng?e.lng-=360:e.lng+=360}return e}Ii.prototype.down=function(t,e){this.mouseRotate.mousedown(t,e),this.mousePitch&&this.mousePitch.mousedown(t,e),r.disableDrag()},Ii.prototype.move=function(t,e){var r=this.map,n=this.mouseRotate.mousemoveWindow(t,e);if(n&&n.bearingDelta&&r.setBearing(r.getBearing()+n.bearingDelta),this.mousePitch){var i=this.mousePitch.mousemoveWindow(t,e);i&&i.pitchDelta&&r.setPitch(r.getPitch()+i.pitchDelta)}},Ii.prototype.off=function(){var t=this.element;r.removeEventListener(t,"mousedown",this.mousedown),r.removeEventListener(t,"touchstart",this.touchstart,{passive:!1}),r.removeEventListener(t,"touchmove",this.touchmove),r.removeEventListener(t,"touchend",this.touchend),r.removeEventListener(t,"touchcancel",this.reset),this.offTemp()},Ii.prototype.offTemp=function(){r.enableDrag(),r.removeEventListener(t.window,"mousemove",this.mousemove),r.removeEventListener(t.window,"mouseup",this.mouseup)},Ii.prototype.mousedown=function(e){this.down(t.extend({},e,{ctrlKey:!0,preventDefault:function(){return e.preventDefault()}}),r.mousePos(this.element,e)),r.addEventListener(t.window,"mousemove",this.mousemove),r.addEventListener(t.window,"mouseup",this.mouseup)},Ii.prototype.mousemove=function(t){this.move(t,r.mousePos(this.element,t))},Ii.prototype.mouseup=function(t){this.mouseRotate.mouseupWindow(t),this.mousePitch&&this.mousePitch.mouseupWindow(t),this.offTemp()},Ii.prototype.touchstart=function(t){1!==t.targetTouches.length?this.reset():(this._startPos=this._lastPos=r.touchPos(this.element,t.targetTouches)[0],this.down({type:"mousedown",button:0,ctrlKey:!0,preventDefault:function(){return t.preventDefault()}},this._startPos))},Ii.prototype.touchmove=function(t){1!==t.targetTouches.length?this.reset():(this._lastPos=r.touchPos(this.element,t.targetTouches)[0],this.move({preventDefault:function(){return t.preventDefault()}},this._lastPos))},Ii.prototype.touchend=function(t){0===t.targetTouches.length&&this._startPos&&this._lastPos&&this._startPos.dist(this._lastPos)<this._clickTolerance&&this.element.click(),this.reset()},Ii.prototype.reset=function(){this.mouseRotate.reset(),this.mousePitch&&this.mousePitch.reset(),delete this._startPos,delete this._lastPos,this.offTemp()};var zi={center:"translate(-50%,-50%)",top:"translate(-50%,0)","top-left":"translate(0,0)","top-right":"translate(-100%,0)",bottom:"translate(-50%,-100%)","bottom-left":"translate(0,-100%)","bottom-right":"translate(-100%,-100%)",left:"translate(0,-50%)",right:"translate(-100%,-50%)"};function Di(t,e,r){var n=t.classList;for(var i in zi)n.remove("mapboxgl-"+r+"-anchor-"+i);n.add("mapboxgl-"+r+"-anchor-"+e)}var Ri,Fi=function(e){function n(n,i){var a=this;if(e.call(this),(n instanceof t.window.HTMLElement||i)&&(n=t.extend({element:n},i)),t.bindAll(["_update","_onMove","_onUp","_addDragHandler","_onMapClick","_onKeyPress"],this),this._anchor=n&&n.anchor||"center",this._color=n&&n.color||"#3FB1CE",this._draggable=n&&n.draggable||!1,this._state="inactive",this._rotation=n&&n.rotation||0,this._rotationAlignment=n&&n.rotationAlignment||"auto",this._pitchAlignment=n&&n.pitchAlignment&&"auto"!==n.pitchAlignment?n.pitchAlignment:this._rotationAlignment,n&&n.element)this._element=n.element,this._offset=t.Point.convert(n&&n.offset||[0,0]);else{this._defaultMarker=!0,this._element=r.create("div"),this._element.setAttribute("aria-label","Map marker");var o=r.createNS("http://www.w3.org/2000/svg","svg");o.setAttributeNS(null,"display","block"),o.setAttributeNS(null,"height","41px"),o.setAttributeNS(null,"width","27px"),o.setAttributeNS(null,"viewBox","0 0 27 41");var s=r.createNS("http://www.w3.org/2000/svg","g");s.setAttributeNS(null,"stroke","none"),s.setAttributeNS(null,"stroke-width","1"),s.setAttributeNS(null,"fill","none"),s.setAttributeNS(null,"fill-rule","evenodd");var l=r.createNS("http://www.w3.org/2000/svg","g");l.setAttributeNS(null,"fill-rule","nonzero");var c=r.createNS("http://www.w3.org/2000/svg","g");c.setAttributeNS(null,"transform","translate(3.0, 29.0)"),c.setAttributeNS(null,"fill","#000000");for(var u=0,f=[{rx:"10.5",ry:"5.25002273"},{rx:"10.5",ry:"5.25002273"},{rx:"9.5",ry:"4.77275007"},{rx:"8.5",ry:"4.29549936"},{rx:"7.5",ry:"3.81822308"},{rx:"6.5",ry:"3.34094679"},{rx:"5.5",ry:"2.86367051"},{rx:"4.5",ry:"2.38636864"}];u<f.length;u+=1){var h=f[u],p=r.createNS("http://www.w3.org/2000/svg","ellipse");p.setAttributeNS(null,"opacity","0.04"),p.setAttributeNS(null,"cx","10.5"),p.setAttributeNS(null,"cy","5.80029008"),p.setAttributeNS(null,"rx",h.rx),p.setAttributeNS(null,"ry",h.ry),c.appendChild(p)}var d=r.createNS("http://www.w3.org/2000/svg","g");d.setAttributeNS(null,"fill",this._color);var m=r.createNS("http://www.w3.org/2000/svg","path");m.setAttributeNS(null,"d","M27,13.5 C27,19.074644 20.250001,27.000002 14.75,34.500002 C14.016665,35.500004 12.983335,35.500004 12.25,34.500002 C6.7499993,27.000002 0,19.222562 0,13.5 C0,6.0441559 6.0441559,0 13.5,0 C20.955844,0 27,6.0441559 27,13.5 Z"),d.appendChild(m);var g=r.createNS("http://www.w3.org/2000/svg","g");g.setAttributeNS(null,"opacity","0.25"),g.setAttributeNS(null,"fill","#000000");var v=r.createNS("http://www.w3.org/2000/svg","path");v.setAttributeNS(null,"d","M13.5,0 C6.0441559,0 0,6.0441559 0,13.5 C0,19.222562 6.7499993,27 12.25,34.5 C13,35.522727 14.016664,35.500004 14.75,34.5 C20.250001,27 27,19.074644 27,13.5 C27,6.0441559 20.955844,0 13.5,0 Z M13.5,1 C20.415404,1 26,6.584596 26,13.5 C26,15.898657 24.495584,19.181431 22.220703,22.738281 C19.945823,26.295132 16.705119,30.142167 13.943359,33.908203 C13.743445,34.180814 13.612715,34.322738 13.5,34.441406 C13.387285,34.322738 13.256555,34.180814 13.056641,33.908203 C10.284481,30.127985 7.4148684,26.314159 5.015625,22.773438 C2.6163816,19.232715 1,15.953538 1,13.5 C1,6.584596 6.584596,1 13.5,1 Z"),g.appendChild(v);var y=r.createNS("http://www.w3.org/2000/svg","g");y.setAttributeNS(null,"transform","translate(6.0, 7.0)"),y.setAttributeNS(null,"fill","#FFFFFF");var x=r.createNS("http://www.w3.org/2000/svg","g");x.setAttributeNS(null,"transform","translate(8.0, 8.0)");var b=r.createNS("http://www.w3.org/2000/svg","circle");b.setAttributeNS(null,"fill","#000000"),b.setAttributeNS(null,"opacity","0.25"),b.setAttributeNS(null,"cx","5.5"),b.setAttributeNS(null,"cy","5.5"),b.setAttributeNS(null,"r","5.4999962");var _=r.createNS("http://www.w3.org/2000/svg","circle");_.setAttributeNS(null,"fill","#FFFFFF"),_.setAttributeNS(null,"cx","5.5"),_.setAttributeNS(null,"cy","5.5"),_.setAttributeNS(null,"r","5.4999962"),x.appendChild(b),x.appendChild(_),l.appendChild(c),l.appendChild(d),l.appendChild(g),l.appendChild(y),l.appendChild(x),o.appendChild(l),this._element.appendChild(o),this._offset=t.Point.convert(n&&n.offset||[0,-14])}this._element.classList.add("mapboxgl-marker"),this._element.addEventListener("dragstart",(function(t){t.preventDefault()})),this._element.addEventListener("mousedown",(function(t){t.preventDefault()})),this._element.addEventListener("focus",(function(){var t=a._map.getContainer();t.scrollTop=0,t.scrollLeft=0})),Di(this._element,this._anchor,"marker"),this._popup=null}return e&&(n.__proto__=e),n.prototype=Object.create(e&&e.prototype),n.prototype.constructor=n,n.prototype.addTo=function(t){return this.remove(),this._map=t,t.getCanvasContainer().appendChild(this._element),t.on("move",this._update),t.on("moveend",this._update),this.setDraggable(this._draggable),this._update(),this._map.on("click",this._onMapClick),this},n.prototype.remove=function(){return this._map&&(this._map.off("click",this._onMapClick),this._map.off("move",this._update),this._map.off("moveend",this._update),this._map.off("mousedown",this._addDragHandler),this._map.off("touchstart",this._addDragHandler),this._map.off("mouseup",this._onUp),this._map.off("touchend",this._onUp),this._map.off("mousemove",this._onMove),this._map.off("touchmove",this._onMove),delete this._map),r.remove(this._element),this._popup&&this._popup.remove(),this},n.prototype.getLngLat=function(){return this._lngLat},n.prototype.setLngLat=function(e){return this._lngLat=t.LngLat.convert(e),this._pos=null,this._popup&&this._popup.setLngLat(this._lngLat),this._update(),this},n.prototype.getElement=function(){return this._element},n.prototype.setPopup=function(t){if(this._popup&&(this._popup.remove(),this._popup=null,this._element.removeEventListener("keypress",this._onKeyPress),this._originalTabIndex||this._element.removeAttribute("tabindex")),t){if(!("offset"in t.options)){var e=Math.sqrt(Math.pow(13.5,2)/2);t.options.offset=this._defaultMarker?{top:[0,0],"top-left":[0,0],"top-right":[0,0],bottom:[0,-38.1],"bottom-left":[e,-1*(24.6+e)],"bottom-right":[-e,-1*(24.6+e)],left:[13.5,-24.6],right:[-13.5,-24.6]}:this._offset}this._popup=t,this._lngLat&&this._popup.setLngLat(this._lngLat),this._originalTabIndex=this._element.getAttribute("tabindex"),this._originalTabIndex||this._element.setAttribute("tabindex","0"),this._element.addEventListener("keypress",this._onKeyPress)}return this},n.prototype._onKeyPress=function(t){var e=t.code,r=t.charCode||t.keyCode;"Space"!==e&&"Enter"!==e&&32!==r&&13!==r||this.togglePopup()},n.prototype._onMapClick=function(t){var e=t.originalEvent.target,r=this._element;this._popup&&(e===r||r.contains(e))&&this.togglePopup()},n.prototype.getPopup=function(){return this._popup},n.prototype.togglePopup=function(){var t=this._popup;return t?(t.isOpen()?t.remove():t.addTo(this._map),this):this},n.prototype._update=function(t){if(this._map){this._map.transform.renderWorldCopies&&(this._lngLat=Oi(this._lngLat,this._pos,this._map.transform)),this._pos=this._map.project(this._lngLat)._add(this._offset);var e="";"viewport"===this._rotationAlignment||"auto"===this._rotationAlignment?e="rotateZ("+this._rotation+"deg)":"map"===this._rotationAlignment&&(e="rotateZ("+(this._rotation-this._map.getBearing())+"deg)");var n="";"viewport"===this._pitchAlignment||"auto"===this._pitchAlignment?n="rotateX(0deg)":"map"===this._pitchAlignment&&(n="rotateX("+this._map.getPitch()+"deg)"),t&&"moveend"!==t.type||(this._pos=this._pos.round()),r.setTransform(this._element,zi[this._anchor]+" translate("+this._pos.x+"px, "+this._pos.y+"px) "+n+" "+e)}},n.prototype.getOffset=function(){return this._offset},n.prototype.setOffset=function(e){return this._offset=t.Point.convert(e),this._update(),this},n.prototype._onMove=function(e){this._pos=e.point.sub(this._positionDelta),this._lngLat=this._map.unproject(this._pos),this.setLngLat(this._lngLat),this._element.style.pointerEvents="none","pending"===this._state&&(this._state="active",this.fire(new t.Event("dragstart"))),this.fire(new t.Event("drag"))},n.prototype._onUp=function(){this._element.style.pointerEvents="auto",this._positionDelta=null,this._map.off("mousemove",this._onMove),this._map.off("touchmove",this._onMove),"active"===this._state&&this.fire(new t.Event("dragend")),this._state="inactive"},n.prototype._addDragHandler=function(t){this._element.contains(t.originalEvent.target)&&(t.preventDefault(),this._positionDelta=t.point.sub(this._pos).add(this._offset),this._state="pending",this._map.on("mousemove",this._onMove),this._map.on("touchmove",this._onMove),this._map.once("mouseup",this._onUp),this._map.once("touchend",this._onUp))},n.prototype.setDraggable=function(t){return this._draggable=!!t,this._map&&(t?(this._map.on("mousedown",this._addDragHandler),this._map.on("touchstart",this._addDragHandler)):(this._map.off("mousedown",this._addDragHandler),this._map.off("touchstart",this._addDragHandler))),this},n.prototype.isDraggable=function(){return this._draggable},n.prototype.setRotation=function(t){return this._rotation=t||0,this._update(),this},n.prototype.getRotation=function(){return this._rotation},n.prototype.setRotationAlignment=function(t){return this._rotationAlignment=t||"auto",this._update(),this},n.prototype.getRotationAlignment=function(){return this._rotationAlignment},n.prototype.setPitchAlignment=function(t){return this._pitchAlignment=t&&"auto"!==t?t:this._rotationAlignment,this._update(),this},n.prototype.getPitchAlignment=function(){return this._pitchAlignment},n}(t.Evented),Bi={positionOptions:{enableHighAccuracy:!1,maximumAge:0,timeout:6e3},fitBoundsOptions:{maxZoom:15},trackUserLocation:!1,showAccuracyCircle:!0,showUserLocation:!0};var Ni=0,ji=!1,Ui=function(e){function n(r){e.call(this),this.options=t.extend({},Bi,r),t.bindAll(["_onSuccess","_onError","_onZoom","_finish","_setupUI","_updateCamera","_updateMarker"],this)}return e&&(n.__proto__=e),n.prototype=Object.create(e&&e.prototype),n.prototype.constructor=n,n.prototype.onAdd=function(e){var n;return this._map=e,this._container=r.create("div","mapboxgl-ctrl mapboxgl-ctrl-group"),n=this._setupUI,void 0!==Ri?n(Ri):void 0!==t.window.navigator.permissions?t.window.navigator.permissions.query({name:"geolocation"}).then((function(t){Ri="denied"!==t.state,n(Ri)})):(Ri=!!t.window.navigator.geolocation,n(Ri)),this._container},n.prototype.onRemove=function(){void 0!==this._geolocationWatchID&&(t.window.navigator.geolocation.clearWatch(this._geolocationWatchID),this._geolocationWatchID=void 0),this.options.showUserLocation&&this._userLocationDotMarker&&this._userLocationDotMarker.remove(),this.options.showAccuracyCircle&&this._accuracyCircleMarker&&this._accuracyCircleMarker.remove(),r.remove(this._container),this._map.off("zoom",this._onZoom),this._map=void 0,Ni=0,ji=!1},n.prototype._isOutOfMapMaxBounds=function(t){var e=this._map.getMaxBounds(),r=t.coords;return e&&(r.longitude<e.getWest()||r.longitude>e.getEast()||r.latitude<e.getSouth()||r.latitude>e.getNorth())},n.prototype._setErrorState=function(){switch(this._watchState){case"WAITING_ACTIVE":this._watchState="ACTIVE_ERROR",this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-active"),this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-active-error");break;case"ACTIVE_LOCK":this._watchState="ACTIVE_ERROR",this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-active"),this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-active-error"),this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-waiting");break;case"BACKGROUND":this._watchState="BACKGROUND_ERROR",this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-background"),this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-background-error"),this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-waiting")}},n.prototype._onSuccess=function(e){if(this._map){if(this._isOutOfMapMaxBounds(e))return this._setErrorState(),this.fire(new t.Event("outofmaxbounds",e)),this._updateMarker(),void this._finish();if(this.options.trackUserLocation)switch(this._lastKnownPosition=e,this._watchState){case"WAITING_ACTIVE":case"ACTIVE_LOCK":case"ACTIVE_ERROR":this._watchState="ACTIVE_LOCK",this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-waiting"),this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-active-error"),this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-active");break;case"BACKGROUND":case"BACKGROUND_ERROR":this._watchState="BACKGROUND",this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-waiting"),this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-background-error"),this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-background")}this.options.showUserLocation&&"OFF"!==this._watchState&&this._updateMarker(e),this.options.trackUserLocation&&"ACTIVE_LOCK"!==this._watchState||this._updateCamera(e),this.options.showUserLocation&&this._dotElement.classList.remove("mapboxgl-user-location-dot-stale"),this.fire(new t.Event("geolocate",e)),this._finish()}},n.prototype._updateCamera=function(e){var r=new t.LngLat(e.coords.longitude,e.coords.latitude),n=e.coords.accuracy,i=this._map.getBearing(),a=t.extend({bearing:i},this.options.fitBoundsOptions);this._map.fitBounds(r.toBounds(n),a,{geolocateSource:!0})},n.prototype._updateMarker=function(e){if(e){var r=new t.LngLat(e.coords.longitude,e.coords.latitude);this._accuracyCircleMarker.setLngLat(r).addTo(this._map),this._userLocationDotMarker.setLngLat(r).addTo(this._map),this._accuracy=e.coords.accuracy,this.options.showUserLocation&&this.options.showAccuracyCircle&&this._updateCircleRadius()}else this._userLocationDotMarker.remove(),this._accuracyCircleMarker.remove()},n.prototype._updateCircleRadius=function(){var t=this._map._container.clientHeight/2,e=this._map.unproject([0,t]),r=this._map.unproject([1,t]),n=e.distanceTo(r),i=Math.ceil(2*this._accuracy/n);this._circleElement.style.width=i+"px",this._circleElement.style.height=i+"px"},n.prototype._onZoom=function(){this.options.showUserLocation&&this.options.showAccuracyCircle&&this._updateCircleRadius()},n.prototype._onError=function(e){if(this._map){if(this.options.trackUserLocation)if(1===e.code){this._watchState="OFF",this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-waiting"),this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-active"),this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-active-error"),this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-background"),this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-background-error"),this._geolocateButton.disabled=!0;var r=this._map._getUIString("GeolocateControl.LocationNotAvailable");this._geolocateButton.title=r,this._geolocateButton.setAttribute("aria-label",r),void 0!==this._geolocationWatchID&&this._clearWatch()}else{if(3===e.code&&ji)return;this._setErrorState()}"OFF"!==this._watchState&&this.options.showUserLocation&&this._dotElement.classList.add("mapboxgl-user-location-dot-stale"),this.fire(new t.Event("error",e)),this._finish()}},n.prototype._finish=function(){this._timeoutId&&clearTimeout(this._timeoutId),this._timeoutId=void 0},n.prototype._setupUI=function(e){var n=this;if(this._container.addEventListener("contextmenu",(function(t){return t.preventDefault()})),this._geolocateButton=r.create("button","mapboxgl-ctrl-geolocate",this._container),r.create("span","mapboxgl-ctrl-icon",this._geolocateButton).setAttribute("aria-hidden",!0),this._geolocateButton.type="button",!1===e){t.warnOnce("Geolocation support is not available so the GeolocateControl will be disabled.");var i=this._map._getUIString("GeolocateControl.LocationNotAvailable");this._geolocateButton.disabled=!0,this._geolocateButton.title=i,this._geolocateButton.setAttribute("aria-label",i)}else{var a=this._map._getUIString("GeolocateControl.FindMyLocation");this._geolocateButton.title=a,this._geolocateButton.setAttribute("aria-label",a)}this.options.trackUserLocation&&(this._geolocateButton.setAttribute("aria-pressed","false"),this._watchState="OFF"),this.options.showUserLocation&&(this._dotElement=r.create("div","mapboxgl-user-location-dot"),this._userLocationDotMarker=new Fi(this._dotElement),this._circleElement=r.create("div","mapboxgl-user-location-accuracy-circle"),this._accuracyCircleMarker=new Fi({element:this._circleElement,pitchAlignment:"map"}),this.options.trackUserLocation&&(this._watchState="OFF"),this._map.on("zoom",this._onZoom)),this._geolocateButton.addEventListener("click",this.trigger.bind(this)),this._setup=!0,this.options.trackUserLocation&&this._map.on("movestart",(function(e){var r=e.originalEvent&&"resize"===e.originalEvent.type;e.geolocateSource||"ACTIVE_LOCK"!==n._watchState||r||(n._watchState="BACKGROUND",n._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-background"),n._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-active"),n.fire(new t.Event("trackuserlocationend")))}))},n.prototype.trigger=function(){if(!this._setup)return t.warnOnce("Geolocate control triggered before added to a map"),!1;if(this.options.trackUserLocation){switch(this._watchState){case"OFF":this._watchState="WAITING_ACTIVE",this.fire(new t.Event("trackuserlocationstart"));break;case"WAITING_ACTIVE":case"ACTIVE_LOCK":case"ACTIVE_ERROR":case"BACKGROUND_ERROR":Ni--,ji=!1,this._watchState="OFF",this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-waiting"),this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-active"),this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-active-error"),this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-background"),this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-background-error"),this.fire(new t.Event("trackuserlocationend"));break;case"BACKGROUND":this._watchState="ACTIVE_LOCK",this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-background"),this._lastKnownPosition&&this._updateCamera(this._lastKnownPosition),this.fire(new t.Event("trackuserlocationstart"))}switch(this._watchState){case"WAITING_ACTIVE":this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-waiting"),this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-active");break;case"ACTIVE_LOCK":this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-active");break;case"ACTIVE_ERROR":this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-waiting"),this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-active-error");break;case"BACKGROUND":this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-background");break;case"BACKGROUND_ERROR":this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-waiting"),this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-background-error")}if("OFF"===this._watchState&&void 0!==this._geolocationWatchID)this._clearWatch();else if(void 0===this._geolocationWatchID){var e;this._geolocateButton.classList.add("mapboxgl-ctrl-geolocate-waiting"),this._geolocateButton.setAttribute("aria-pressed","true"),++Ni>1?(e={maximumAge:6e5,timeout:0},ji=!0):(e=this.options.positionOptions,ji=!1),this._geolocationWatchID=t.window.navigator.geolocation.watchPosition(this._onSuccess,this._onError,e)}}else t.window.navigator.geolocation.getCurrentPosition(this._onSuccess,this._onError,this.options.positionOptions),this._timeoutId=setTimeout(this._finish,1e4);return!0},n.prototype._clearWatch=function(){t.window.navigator.geolocation.clearWatch(this._geolocationWatchID),this._geolocationWatchID=void 0,this._geolocateButton.classList.remove("mapboxgl-ctrl-geolocate-waiting"),this._geolocateButton.setAttribute("aria-pressed","false"),this.options.showUserLocation&&this._updateMarker(null)},n}(t.Evented),Vi={maxWidth:100,unit:"metric"},Hi=function(e){this.options=t.extend({},Vi,e),t.bindAll(["_onMove","setUnit"],this)};function qi(t,e,r){var n=r&&r.maxWidth||100,i=t._container.clientHeight/2,a=t.unproject([0,i]),o=t.unproject([n,i]),s=a.distanceTo(o);if(r&&"imperial"===r.unit){var l=3.2808*s;if(l>5280)Gi(e,n,l/5280,t._getUIString("ScaleControl.Miles"));else Gi(e,n,l,t._getUIString("ScaleControl.Feet"))}else if(r&&"nautical"===r.unit){Gi(e,n,s/1852,t._getUIString("ScaleControl.NauticalMiles"))}else s>=1e3?Gi(e,n,s/1e3,t._getUIString("ScaleControl.Kilometers")):Gi(e,n,s,t._getUIString("ScaleControl.Meters"))}function Gi(t,e,r,n){var i,a,o,s=(i=r,a=Math.pow(10,(""+Math.floor(i)).length-1),o=(o=i/a)>=10?10:o>=5?5:o>=3?3:o>=2?2:o>=1?1:function(t){var e=Math.pow(10,Math.ceil(-Math.log(t)/Math.LN10));return Math.round(t*e)/e}(o),a*o),l=s/r;t.style.width=e*l+"px",t.innerHTML=s+"&nbsp;"+n}Hi.prototype.getDefaultPosition=function(){return"bottom-left"},Hi.prototype._onMove=function(){qi(this._map,this._container,this.options)},Hi.prototype.onAdd=function(t){return this._map=t,this._container=r.create("div","mapboxgl-ctrl mapboxgl-ctrl-scale",t.getContainer()),this._map.on("move",this._onMove),this._onMove(),this._container},Hi.prototype.onRemove=function(){r.remove(this._container),this._map.off("move",this._onMove),this._map=void 0},Hi.prototype.setUnit=function(t){this.options.unit=t,qi(this._map,this._container,this.options)};var Yi=function(e){this._fullscreen=!1,e&&e.container&&(e.container instanceof t.window.HTMLElement?this._container=e.container:t.warnOnce("Full screen control 'container' must be a DOM element.")),t.bindAll(["_onClickFullscreen","_changeIcon"],this),"onfullscreenchange"in t.window.document?this._fullscreenchange="fullscreenchange":"onmozfullscreenchange"in t.window.document?this._fullscreenchange="mozfullscreenchange":"onwebkitfullscreenchange"in t.window.document?this._fullscreenchange="webkitfullscreenchange":"onmsfullscreenchange"in t.window.document&&(this._fullscreenchange="MSFullscreenChange")};Yi.prototype.onAdd=function(e){return this._map=e,this._container||(this._container=this._map.getContainer()),this._controlContainer=r.create("div","mapboxgl-ctrl mapboxgl-ctrl-group"),this._checkFullscreenSupport()?this._setupUI():(this._controlContainer.style.display="none",t.warnOnce("This device does not support fullscreen mode.")),this._controlContainer},Yi.prototype.onRemove=function(){r.remove(this._controlContainer),this._map=null,t.window.document.removeEventListener(this._fullscreenchange,this._changeIcon)},Yi.prototype._checkFullscreenSupport=function(){return!!(t.window.document.fullscreenEnabled||t.window.document.mozFullScreenEnabled||t.window.document.msFullscreenEnabled||t.window.document.webkitFullscreenEnabled)},Yi.prototype._setupUI=function(){var e=this._fullscreenButton=r.create("button","mapboxgl-ctrl-fullscreen",this._controlContainer);r.create("span","mapboxgl-ctrl-icon",e).setAttribute("aria-hidden",!0),e.type="button",this._updateTitle(),this._fullscreenButton.addEventListener("click",this._onClickFullscreen),t.window.document.addEventListener(this._fullscreenchange,this._changeIcon)},Yi.prototype._updateTitle=function(){var t=this._getTitle();this._fullscreenButton.setAttribute("aria-label",t),this._fullscreenButton.title=t},Yi.prototype._getTitle=function(){return this._map._getUIString(this._isFullscreen()?"FullscreenControl.Exit":"FullscreenControl.Enter")},Yi.prototype._isFullscreen=function(){return this._fullscreen},Yi.prototype._changeIcon=function(){(t.window.document.fullscreenElement||t.window.document.mozFullScreenElement||t.window.document.webkitFullscreenElement||t.window.document.msFullscreenElement)===this._container!==this._fullscreen&&(this._fullscreen=!this._fullscreen,this._fullscreenButton.classList.toggle("mapboxgl-ctrl-shrink"),this._fullscreenButton.classList.toggle("mapboxgl-ctrl-fullscreen"),this._updateTitle())},Yi.prototype._onClickFullscreen=function(){this._isFullscreen()?t.window.document.exitFullscreen?t.window.document.exitFullscreen():t.window.document.mozCancelFullScreen?t.window.document.mozCancelFullScreen():t.window.document.msExitFullscreen?t.window.document.msExitFullscreen():t.window.document.webkitCancelFullScreen&&t.window.document.webkitCancelFullScreen():this._container.requestFullscreen?this._container.requestFullscreen():this._container.mozRequestFullScreen?this._container.mozRequestFullScreen():this._container.msRequestFullscreen?this._container.msRequestFullscreen():this._container.webkitRequestFullscreen&&this._container.webkitRequestFullscreen()};var Wi={closeButton:!0,closeOnClick:!0,className:"",maxWidth:"240px"},Xi=function(e){function n(r){e.call(this),this.options=t.extend(Object.create(Wi),r),t.bindAll(["_update","_onClose","remove","_onMouseMove","_onMouseUp","_onDrag"],this)}return e&&(n.__proto__=e),n.prototype=Object.create(e&&e.prototype),n.prototype.constructor=n,n.prototype.addTo=function(e){return this._map&&this.remove(),this._map=e,this.options.closeOnClick&&this._map.on("click",this._onClose),this.options.closeOnMove&&this._map.on("move",this._onClose),this._map.on("remove",this.remove),this._update(),this._trackPointer?(this._map.on("mousemove",this._onMouseMove),this._map.on("mouseup",this._onMouseUp),this._container&&this._container.classList.add("mapboxgl-popup-track-pointer"),this._map._canvasContainer.classList.add("mapboxgl-track-pointer")):this._map.on("move",this._update),this.fire(new t.Event("open")),this},n.prototype.isOpen=function(){return!!this._map},n.prototype.remove=function(){return this._content&&r.remove(this._content),this._container&&(r.remove(this._container),delete this._container),this._map&&(this._map.off("move",this._update),this._map.off("move",this._onClose),this._map.off("click",this._onClose),this._map.off("remove",this.remove),this._map.off("mousemove",this._onMouseMove),this._map.off("mouseup",this._onMouseUp),this._map.off("drag",this._onDrag),delete this._map),this.fire(new t.Event("close")),this},n.prototype.getLngLat=function(){return this._lngLat},n.prototype.setLngLat=function(e){return this._lngLat=t.LngLat.convert(e),this._pos=null,this._trackPointer=!1,this._update(),this._map&&(this._map.on("move",this._update),this._map.off("mousemove",this._onMouseMove),this._container&&this._container.classList.remove("mapboxgl-popup-track-pointer"),this._map._canvasContainer.classList.remove("mapboxgl-track-pointer")),this},n.prototype.trackPointer=function(){return this._trackPointer=!0,this._pos=null,this._update(),this._map&&(this._map.off("move",this._update),this._map.on("mousemove",this._onMouseMove),this._map.on("drag",this._onDrag),this._container&&this._container.classList.add("mapboxgl-popup-track-pointer"),this._map._canvasContainer.classList.add("mapboxgl-track-pointer")),this},n.prototype.getElement=function(){return this._container},n.prototype.setText=function(e){return this.setDOMContent(t.window.document.createTextNode(e))},n.prototype.setHTML=function(e){var r,n=t.window.document.createDocumentFragment(),i=t.window.document.createElement("body");for(i.innerHTML=e;r=i.firstChild;)n.appendChild(r);return this.setDOMContent(n)},n.prototype.getMaxWidth=function(){return this._container&&this._container.style.maxWidth},n.prototype.setMaxWidth=function(t){return this.options.maxWidth=t,this._update(),this},n.prototype.setDOMContent=function(t){return this._createContent(),this._content.appendChild(t),this._update(),this},n.prototype.addClassName=function(t){this._container&&this._container.classList.add(t)},n.prototype.removeClassName=function(t){this._container&&this._container.classList.remove(t)},n.prototype.toggleClassName=function(t){if(this._container)return this._container.classList.toggle(t)},n.prototype._createContent=function(){this._content&&r.remove(this._content),this._content=r.create("div","mapboxgl-popup-content",this._container),this.options.closeButton&&(this._closeButton=r.create("button","mapboxgl-popup-close-button",this._content),this._closeButton.type="button",this._closeButton.setAttribute("aria-label","Close popup"),this._closeButton.innerHTML="&#215;",this._closeButton.addEventListener("click",this._onClose))},n.prototype._onMouseUp=function(t){this._update(t.point)},n.prototype._onMouseMove=function(t){this._update(t.point)},n.prototype._onDrag=function(t){this._update(t.point)},n.prototype._update=function(e){var n=this,i=this._lngLat||this._trackPointer;if(this._map&&i&&this._content&&(this._container||(this._container=r.create("div","mapboxgl-popup",this._map.getContainer()),this._tip=r.create("div","mapboxgl-popup-tip",this._container),this._container.appendChild(this._content),this.options.className&&this.options.className.split(" ").forEach((function(t){return n._container.classList.add(t)})),this._trackPointer&&this._container.classList.add("mapboxgl-popup-track-pointer")),this.options.maxWidth&&this._container.style.maxWidth!==this.options.maxWidth&&(this._container.style.maxWidth=this.options.maxWidth),this._map.transform.renderWorldCopies&&!this._trackPointer&&(this._lngLat=Oi(this._lngLat,this._pos,this._map.transform)),!this._trackPointer||e)){var a=this._pos=this._trackPointer&&e?e:this._map.project(this._lngLat),o=this.options.anchor,s=function e(r){if(r){if("number"==typeof r){var n=Math.round(Math.sqrt(.5*Math.pow(r,2)));return{center:new t.Point(0,0),top:new t.Point(0,r),"top-left":new t.Point(n,n),"top-right":new t.Point(-n,n),bottom:new t.Point(0,-r),"bottom-left":new t.Point(n,-n),"bottom-right":new t.Point(-n,-n),left:new t.Point(r,0),right:new t.Point(-r,0)}}if(r instanceof t.Point||Array.isArray(r)){var i=t.Point.convert(r);return{center:i,top:i,"top-left":i,"top-right":i,bottom:i,"bottom-left":i,"bottom-right":i,left:i,right:i}}return{center:t.Point.convert(r.center||[0,0]),top:t.Point.convert(r.top||[0,0]),"top-left":t.Point.convert(r["top-left"]||[0,0]),"top-right":t.Point.convert(r["top-right"]||[0,0]),bottom:t.Point.convert(r.bottom||[0,0]),"bottom-left":t.Point.convert(r["bottom-left"]||[0,0]),"bottom-right":t.Point.convert(r["bottom-right"]||[0,0]),left:t.Point.convert(r.left||[0,0]),right:t.Point.convert(r.right||[0,0])}}return e(new t.Point(0,0))}(this.options.offset);if(!o){var l,c=this._container.offsetWidth,u=this._container.offsetHeight;l=a.y+s.bottom.y<u?["top"]:a.y>this._map.transform.height-u?["bottom"]:[],a.x<c/2?l.push("left"):a.x>this._map.transform.width-c/2&&l.push("right"),o=0===l.length?"bottom":l.join("-")}var f=a.add(s[o]).round();r.setTransform(this._container,zi[o]+" translate("+f.x+"px,"+f.y+"px)"),Di(this._container,o,"popup")}},n.prototype._onClose=function(){this.remove()},n}(t.Evented);var Zi={version:t.version,supported:e,setRTLTextPlugin:t.setRTLTextPlugin,getRTLTextPluginStatus:t.getRTLTextPluginStatus,Map:Ei,NavigationControl:Pi,GeolocateControl:Ui,AttributionControl:bi,ScaleControl:Hi,FullscreenControl:Yi,Popup:Xi,Marker:Fi,Style:qe,LngLat:t.LngLat,LngLatBounds:t.LngLatBounds,Point:t.Point,MercatorCoordinate:t.MercatorCoordinate,Evented:t.Evented,config:t.config,prewarm:function(){Bt().acquire(zt)},clearPrewarmedResources:function(){var t=Rt;t&&(t.isPreloaded()&&1===t.numActive()?(t.release(zt),Rt=null):console.warn("Could not clear WebWorkers since there are active Map instances that still reference it. The pre-warmed WebWorker pool can only be cleared when all map instances have been removed with map.remove()"))},get accessToken(){return t.config.ACCESS_TOKEN},set accessToken(e){t.config.ACCESS_TOKEN=e},get baseApiUrl(){return t.config.API_URL},set baseApiUrl(e){t.config.API_URL=e},get workerCount(){return Dt.workerCount},set workerCount(t){Dt.workerCount=t},get maxParallelImageRequests(){return t.config.MAX_PARALLEL_IMAGE_REQUESTS},set maxParallelImageRequests(e){t.config.MAX_PARALLEL_IMAGE_REQUESTS=e},clearStorage:function(e){t.clearTileCache(e)},workerUrl:""};return Zi})),r}))},{}],240:[function(t,e,r){"use strict";e.exports=Math.log2||function(t){return Math.log(t)*Math.LOG2E}},{}],241:[function(t,e,r){"use strict";e.exports=function(t,e){e||(e=t,t=window);var r=0,i=0,a=0,o={shift:!1,alt:!1,control:!1,meta:!1},s=!1;function l(t){var e=!1;return"altKey"in t&&(e=e||t.altKey!==o.alt,o.alt=!!t.altKey),"shiftKey"in t&&(e=e||t.shiftKey!==o.shift,o.shift=!!t.shiftKey),"ctrlKey"in t&&(e=e||t.ctrlKey!==o.control,o.control=!!t.ctrlKey),"metaKey"in t&&(e=e||t.metaKey!==o.meta,o.meta=!!t.metaKey),e}function c(t,s){var c=n.x(s),u=n.y(s);"buttons"in s&&(t=0|s.buttons),(t!==r||c!==i||u!==a||l(s))&&(r=0|t,i=c||0,a=u||0,e&&e(r,i,a,o))}function u(t){c(0,t)}function f(){(r||i||a||o.shift||o.alt||o.meta||o.control)&&(i=a=0,r=0,o.shift=o.alt=o.control=o.meta=!1,e&&e(0,0,0,o))}function h(t){l(t)&&e&&e(r,i,a,o)}function p(t){0===n.buttons(t)?c(0,t):c(r,t)}function d(t){c(r|n.buttons(t),t)}function m(t){c(r&~n.buttons(t),t)}function g(){s||(s=!0,t.addEventListener("mousemove",p),t.addEventListener("mousedown",d),t.addEventListener("mouseup",m),t.addEventListener("mouseleave",u),t.addEventListener("mouseenter",u),t.addEventListener("mouseout",u),t.addEventListener("mouseover",u),t.addEventListener("blur",f),t.addEventListener("keyup",h),t.addEventListener("keydown",h),t.addEventListener("keypress",h),t!==window&&(window.addEventListener("blur",f),window.addEventListener("keyup",h),window.addEventListener("keydown",h),window.addEventListener("keypress",h)))}g();var v={element:t};return Object.defineProperties(v,{enabled:{get:function(){return s},set:function(e){e?g():function(){if(!s)return;s=!1,t.removeEventListener("mousemove",p),t.removeEventListener("mousedown",d),t.removeEventListener("mouseup",m),t.removeEventListener("mouseleave",u),t.removeEventListener("mouseenter",u),t.removeEventListener("mouseout",u),t.removeEventListener("mouseover",u),t.removeEventListener("blur",f),t.removeEventListener("keyup",h),t.removeEventListener("keydown",h),t.removeEventListener("keypress",h),t!==window&&(window.removeEventListener("blur",f),window.removeEventListener("keyup",h),window.removeEventListener("keydown",h),window.removeEventListener("keypress",h))}()},enumerable:!0},buttons:{get:function(){return r},enumerable:!0},x:{get:function(){return i},enumerable:!0},y:{get:function(){return a},enumerable:!0},mods:{get:function(){return o},enumerable:!0}}),v};var n=t("mouse-event")},{"mouse-event":243}],242:[function(t,e,r){var n={left:0,top:0};e.exports=function(t,e,r){e=e||t.currentTarget||t.srcElement,Array.isArray(r)||(r=[0,0]);var i=t.clientX||0,a=t.clientY||0,o=(s=e,s===window||s===document||s===document.body?n:s.getBoundingClientRect());var s;return r[0]=i-o.left,r[1]=a-o.top,r}},{}],243:[function(t,e,r){"use strict";function n(t){return t.target||t.srcElement||window}r.buttons=function(t){if("object"==typeof t){if("buttons"in t)return t.buttons;if("which"in t){if(2===(e=t.which))return 4;if(3===e)return 2;if(e>0)return 1<<e-1}else if("button"in t){var e;if(1===(e=t.button))return 4;if(2===e)return 2;if(e>=0)return 1<<e}}return 0},r.element=n,r.x=function(t){if("object"==typeof t){if("offsetX"in t)return t.offsetX;var e=n(t).getBoundingClientRect();return t.clientX-e.left}return 0},r.y=function(t){if("object"==typeof t){if("offsetY"in t)return t.offsetY;var e=n(t).getBoundingClientRect();return t.clientY-e.top}return 0}},{}],244:[function(t,e,r){"use strict";var n=t("to-px");e.exports=function(t,e,r){"function"==typeof t&&(r=!!e,e=t,t=window);var i=n("ex",t),a=function(t){r&&t.preventDefault();var n=t.deltaX||0,a=t.deltaY||0,o=t.deltaZ||0,s=1;switch(t.deltaMode){case 1:s=i;break;case 2:s=window.innerHeight}if(a*=s,o*=s,(n*=s)||a||o)return e(n,a,o,t)};return t.addEventListener("wheel",a),a}},{"to-px":314}],245:[function(t,e,r){(function(t,r){(function(){
/*! Native Promise Only
    v0.8.1 (c) Kyle Simpson
    MIT License: http://getify.mit-license.org
*/
!function(t,r,n){r[t]=r[t]||n(),void 0!==e&&e.exports&&(e.exports=r[t])}("Promise",void 0!==t?t:this,(function(){"use strict";var t,e,n,i=Object.prototype.toString,a=void 0!==r?function(t){return r(t)}:setTimeout;try{Object.defineProperty({},"x",{}),t=function(t,e,r,n){return Object.defineProperty(t,e,{value:r,writable:!0,configurable:!1!==n})}}catch(e){t=function(t,e,r){return t[e]=r,t}}function o(t,r){n.add(t,r),e||(e=a(n.drain))}function s(t){var e,r=typeof t;return null==t||"object"!=r&&"function"!=r||(e=t.then),"function"==typeof e&&e}function l(){for(var t=0;t<this.chain.length;t++)c(this,1===this.state?this.chain[t].success:this.chain[t].failure,this.chain[t]);this.chain.length=0}function c(t,e,r){var n,i;try{!1===e?r.reject(t.msg):(n=!0===e?t.msg:e.call(void 0,t.msg))===r.promise?r.reject(TypeError("Promise-chain cycle")):(i=s(n))?i.call(n,r.resolve,r.reject):r.resolve(n)}catch(t){r.reject(t)}}function u(t){var e,r=this;if(!r.triggered){r.triggered=!0,r.def&&(r=r.def);try{(e=s(t))?o((function(){var n=new p(r);try{e.call(t,(function(){u.apply(n,arguments)}),(function(){f.apply(n,arguments)}))}catch(t){f.call(n,t)}})):(r.msg=t,r.state=1,r.chain.length>0&&o(l,r))}catch(t){f.call(new p(r),t)}}}function f(t){var e=this;e.triggered||(e.triggered=!0,e.def&&(e=e.def),e.msg=t,e.state=2,e.chain.length>0&&o(l,e))}function h(t,e,r,n){for(var i=0;i<e.length;i++)!function(i){t.resolve(e[i]).then((function(t){r(i,t)}),n)}(i)}function p(t){this.def=t,this.triggered=!1}function d(t){this.promise=t,this.state=0,this.triggered=!1,this.chain=[],this.msg=void 0}function m(t){if("function"!=typeof t)throw TypeError("Not a function");if(0!==this.__NPO__)throw TypeError("Not a promise");this.__NPO__=1;var e=new d(this);this.then=function(t,r){var n={success:"function"!=typeof t||t,failure:"function"==typeof r&&r};return n.promise=new this.constructor((function(t,e){if("function"!=typeof t||"function"!=typeof e)throw TypeError("Not a function");n.resolve=t,n.reject=e})),e.chain.push(n),0!==e.state&&o(l,e),n.promise},this.catch=function(t){return this.then(void 0,t)};try{t.call(void 0,(function(t){u.call(e,t)}),(function(t){f.call(e,t)}))}catch(t){f.call(e,t)}}n=function(){var t,r,n;function i(t,e){this.fn=t,this.self=e,this.next=void 0}return{add:function(e,a){n=new i(e,a),r?r.next=n:t=n,r=n,n=void 0},drain:function(){var n=t;for(t=r=e=void 0;n;)n.fn.call(n.self),n=n.next}}}();var g=t({},"constructor",m,!1);return m.prototype=g,t(g,"__NPO__",0,!1),t(m,"resolve",(function(t){return t&&"object"==typeof t&&1===t.__NPO__?t:new this((function(e,r){if("function"!=typeof e||"function"!=typeof r)throw TypeError("Not a function");e(t)}))})),t(m,"reject",(function(t){return new this((function(e,r){if("function"!=typeof e||"function"!=typeof r)throw TypeError("Not a function");r(t)}))})),t(m,"all",(function(t){var e=this;return"[object Array]"!=i.call(t)?e.reject(TypeError("Not an array")):0===t.length?e.resolve([]):new e((function(r,n){if("function"!=typeof r||"function"!=typeof n)throw TypeError("Not a function");var i=t.length,a=Array(i),o=0;h(e,t,(function(t,e){a[t]=e,++o===i&&r(a)}),n)}))})),t(m,"race",(function(t){var e=this;return"[object Array]"!=i.call(t)?e.reject(TypeError("Not an array")):new e((function(r,n){if("function"!=typeof r||"function"!=typeof n)throw TypeError("Not a function");h(e,t,(function(t,e){r(e)}),n)}))})),m}))}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},t("timers").setImmediate)},{timers:311}],246:[function(t,e,r){var n=Math.PI,i=c(120);function a(t,e,r,n){return["C",t,e,r,n,r,n]}function o(t,e,r,n,i,a){return["C",t/3+2/3*r,e/3+2/3*n,i/3+2/3*r,a/3+2/3*n,i,a]}function s(t,e,r,a,o,c,u,f,h,p){if(p)T=p[0],k=p[1],_=p[2],w=p[3];else{var d=l(t,e,-o);t=d.x,e=d.y;var m=(t-(f=(d=l(f,h,-o)).x))/2,g=(e-(h=d.y))/2,v=m*m/(r*r)+g*g/(a*a);v>1&&(r*=v=Math.sqrt(v),a*=v);var y=r*r,x=a*a,b=(c==u?-1:1)*Math.sqrt(Math.abs((y*x-y*g*g-x*m*m)/(y*g*g+x*m*m)));b==1/0&&(b=1);var _=b*r*g/a+(t+f)/2,w=b*-a*m/r+(e+h)/2,T=Math.asin(((e-w)/a).toFixed(9)),k=Math.asin(((h-w)/a).toFixed(9));(T=t<_?n-T:T)<0&&(T=2*n+T),(k=f<_?n-k:k)<0&&(k=2*n+k),u&&T>k&&(T-=2*n),!u&&k>T&&(k-=2*n)}if(Math.abs(k-T)>i){var A=k,M=f,S=h;k=T+i*(u&&k>T?1:-1);var E=s(f=_+r*Math.cos(k),h=w+a*Math.sin(k),r,a,o,0,u,M,S,[k,A,_,w])}var L=Math.tan((k-T)/4),C=4/3*r*L,P=4/3*a*L,I=[2*t-(t+C*Math.sin(T)),2*e-(e-P*Math.cos(T)),f+C*Math.sin(k),h-P*Math.cos(k),f,h];if(p)return I;E&&(I=I.concat(E));for(var O=0;O<I.length;){var z=l(I[O],I[O+1],o);I[O++]=z.x,I[O++]=z.y}return I}function l(t,e,r){return{x:t*Math.cos(r)-e*Math.sin(r),y:t*Math.sin(r)+e*Math.cos(r)}}function c(t){return t*(n/180)}e.exports=function(t){for(var e,r=[],n=0,i=0,l=0,u=0,f=null,h=null,p=0,d=0,m=0,g=t.length;m<g;m++){var v=t[m],y=v[0];switch(y){case"M":l=v[1],u=v[2];break;case"A":(v=s(p,d,v[1],v[2],c(v[3]),v[4],v[5],v[6],v[7])).unshift("C"),v.length>7&&(r.push(v.splice(0,7)),v.unshift("C"));break;case"S":var x=p,b=d;"C"!=e&&"S"!=e||(x+=x-n,b+=b-i),v=["C",x,b,v[1],v[2],v[3],v[4]];break;case"T":"Q"==e||"T"==e?(f=2*p-f,h=2*d-h):(f=p,h=d),v=o(p,d,f,h,v[1],v[2]);break;case"Q":f=v[1],h=v[2],v=o(p,d,v[1],v[2],v[3],v[4]);break;case"L":v=a(p,d,v[1],v[2]);break;case"H":v=a(p,d,v[1],d);break;case"V":v=a(p,d,p,v[1]);break;case"Z":v=a(p,d,l,u)}e=y,p=v[v.length-2],d=v[v.length-1],v.length>4?(n=v[v.length-4],i=v[v.length-3]):(n=p,i=d),r.push(v)}return r}},{}],247:[function(t,e,r){
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
"use strict";var n=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;function o(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}e.exports=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},r=0;r<10;r++)e["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(e).map((function(t){return e[t]})).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach((function(t){n[t]=t})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var r,s,l=o(t),c=1;c<arguments.length;c++){for(var u in r=Object(arguments[c]))i.call(r,u)&&(l[u]=r[u]);if(n){s=n(r);for(var f=0;f<s.length;f++)a.call(r,s[f])&&(l[s[f]]=r[s[f]])}}return l}},{}],248:[function(t,e,r){"use strict";function n(t,e){if("string"!=typeof t)return[t];var r=[t];"string"==typeof e||Array.isArray(e)?e={brackets:e}:e||(e={});var n=e.brackets?Array.isArray(e.brackets)?e.brackets:[e.brackets]:["{}","[]","()"],i=e.escape||"___",a=!!e.flat;n.forEach((function(t){var e=new RegExp(["\\",t[0],"[^\\",t[0],"\\",t[1],"]*\\",t[1]].join("")),n=[];function a(e,a,o){var s=r.push(e.slice(t[0].length,-t[1].length))-1;return n.push(s),i+s+i}r.forEach((function(t,n){for(var i,o=0;t!=i;)if(i=t,t=t.replace(e,a),o++>1e4)throw Error("References have circular dependency. Please, check them.");r[n]=t})),n=n.reverse(),r=r.map((function(e){return n.forEach((function(r){e=e.replace(new RegExp("(\\"+i+r+"\\"+i+")","g"),t[0]+"$1"+t[1])})),e}))}));var o=new RegExp("\\"+i+"([0-9]+)\\"+i);return a?r:function t(e,r,n){for(var i,a=[],s=0;i=o.exec(e);){if(s++>1e4)throw Error("Circular references in parenthesis");a.push(e.slice(0,i.index)),a.push(t(r[i[1]],r)),e=e.slice(i.index+i[0].length)}return a.push(e),a}(r[0],r)}function i(t,e){if(e&&e.flat){var r,n=e&&e.escape||"___",i=t[0];if(!i)return"";for(var a=new RegExp("\\"+n+"([0-9]+)\\"+n),o=0;i!=r;){if(o++>1e4)throw Error("Circular references in "+t);r=i,i=i.replace(a,s)}return i}return t.reduce((function t(e,r){return Array.isArray(r)&&(r=r.reduce(t,"")),e+r}),"");function s(e,r){if(null==t[r])throw Error("Reference "+r+"is undefined");return t[r]}}function a(t,e){return Array.isArray(t)?i(t,e):n(t,e)}a.parse=n,a.stringify=i,e.exports=a},{}],249:[function(t,e,r){"use strict";var n=t("pick-by-alias");e.exports=function(t){var e;arguments.length>1&&(t=arguments);"string"==typeof t?t=t.split(/\s/).map(parseFloat):"number"==typeof t&&(t=[t]);t.length&&"number"==typeof t[0]?e=1===t.length?{width:t[0],height:t[0],x:0,y:0}:2===t.length?{width:t[0],height:t[1],x:0,y:0}:{x:t[0],y:t[1],width:t[2]-t[0]||0,height:t[3]-t[1]||0}:t&&(t=n(t,{left:"x l left Left",top:"y t top Top",width:"w width W Width",height:"h height W Width",bottom:"b bottom Bottom",right:"r right Right"}),e={x:t.left||0,y:t.top||0},null==t.width?t.right?e.width=t.right-e.x:e.width=0:e.width=t.width,null==t.height?t.bottom?e.height=t.bottom-e.y:e.height=0:e.height=t.height);return e}},{"pick-by-alias":253}],250:[function(t,e,r){e.exports=function(t){var e=[];return t.replace(i,(function(t,r,i){var o=r.toLowerCase();for(i=function(t){var e=t.match(a);return e?e.map(Number):[]}(i),"m"==o&&i.length>2&&(e.push([r].concat(i.splice(0,2))),o="l",r="m"==r?"l":"L");;){if(i.length==n[o])return i.unshift(r),e.push(i);if(i.length<n[o])throw new Error("malformed path data");e.push([r].concat(i.splice(0,n[o])))}})),e};var n={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},i=/([astvzqmhlc])([^astvzqmhlc]*)/gi;var a=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi},{}],251:[function(t,e,r){e.exports=function(t,e){e||(e=[0,""]),t=String(t);var r=parseFloat(t,10);return e[0]=r,e[1]=t.match(/[\d.\-\+]*\s*(.*)/)[1]||"",e}},{}],252:[function(t,e,r){(function(t){(function(){(function(){var r,n,i,a,o,s;"undefined"!=typeof performance&&null!==performance&&performance.now?e.exports=function(){return performance.now()}:null!=t&&t.hrtime?(e.exports=function(){return(r()-o)/1e6},n=t.hrtime,a=(r=function(){var t;return 1e9*(t=n())[0]+t[1]})(),s=1e9*t.uptime(),o=a-s):Date.now?(e.exports=function(){return Date.now()-i},i=Date.now()):(e.exports=function(){return(new Date).getTime()-i},i=(new Date).getTime())}).call(this)}).call(this)}).call(this,t("_process"))},{_process:277}],253:[function(t,e,r){"use strict";e.exports=function(t,e,r){var n,a,o={};if("string"==typeof e&&(e=i(e)),Array.isArray(e)){var s={};for(a=0;a<e.length;a++)s[e[a]]=!0;e=s}for(n in e)e[n]=i(e[n]);var l={};for(n in e){var c=e[n];if(Array.isArray(c))for(a=0;a<c.length;a++){var u=c[a];if(r&&(l[u]=!0),u in t){if(o[n]=t[u],r)for(var f=a;f<c.length;f++)l[c[f]]=!0;break}}else n in t&&(e[n]&&(o[n]=t[n]),r&&(l[n]=!0))}if(r)for(n in t)l[n]||(o[n]=t[n]);return o};var n={};function i(t){return n[t]?n[t]:("string"==typeof t&&(t=n[t]=t.split(/\s*,\s*|\s+/)),t)}},{}],254:[function(t,e,r){
/*
 * @copyright 2016 Sean Connelly (@voidqk), http://syntheti.cc
 * @license MIT
 * @preserve Project Home: https://github.com/voidqk/polybooljs
 */
var n,i=t("./lib/build-log"),a=t("./lib/epsilon"),o=t("./lib/intersecter"),s=t("./lib/segment-chainer"),l=t("./lib/segment-selector"),c=t("./lib/geojson"),u=!1,f=a();function h(t,e,r){var i=n.segments(t),a=n.segments(e),o=r(n.combine(i,a));return n.polygon(o)}n={buildLog:function(t){return!0===t?u=i():!1===t&&(u=!1),!1!==u&&u.list},epsilon:function(t){return f.epsilon(t)},segments:function(t){var e=o(!0,f,u);return t.regions.forEach(e.addRegion),{segments:e.calculate(t.inverted),inverted:t.inverted}},combine:function(t,e){return{combined:o(!1,f,u).calculate(t.segments,t.inverted,e.segments,e.inverted),inverted1:t.inverted,inverted2:e.inverted}},selectUnion:function(t){return{segments:l.union(t.combined,u),inverted:t.inverted1||t.inverted2}},selectIntersect:function(t){return{segments:l.intersect(t.combined,u),inverted:t.inverted1&&t.inverted2}},selectDifference:function(t){return{segments:l.difference(t.combined,u),inverted:t.inverted1&&!t.inverted2}},selectDifferenceRev:function(t){return{segments:l.differenceRev(t.combined,u),inverted:!t.inverted1&&t.inverted2}},selectXor:function(t){return{segments:l.xor(t.combined,u),inverted:t.inverted1!==t.inverted2}},polygon:function(t){return{regions:s(t.segments,f,u),inverted:t.inverted}},polygonFromGeoJSON:function(t){return c.toPolygon(n,t)},polygonToGeoJSON:function(t){return c.fromPolygon(n,f,t)},union:function(t,e){return h(t,e,n.selectUnion)},intersect:function(t,e){return h(t,e,n.selectIntersect)},difference:function(t,e){return h(t,e,n.selectDifference)},differenceRev:function(t,e){return h(t,e,n.selectDifferenceRev)},xor:function(t,e){return h(t,e,n.selectXor)}},"object"==typeof window&&(window.PolyBool=n),e.exports=n},{"./lib/build-log":255,"./lib/epsilon":256,"./lib/geojson":257,"./lib/intersecter":258,"./lib/segment-chainer":260,"./lib/segment-selector":261}],255:[function(t,e,r){e.exports=function(){var t,e=0,r=!1;function n(e,r){return t.list.push({type:e,data:r?JSON.parse(JSON.stringify(r)):void 0}),t}return t={list:[],segmentId:function(){return e++},checkIntersection:function(t,e){return n("check",{seg1:t,seg2:e})},segmentChop:function(t,e){return n("div_seg",{seg:t,pt:e}),n("chop",{seg:t,pt:e})},statusRemove:function(t){return n("pop_seg",{seg:t})},segmentUpdate:function(t){return n("seg_update",{seg:t})},segmentNew:function(t,e){return n("new_seg",{seg:t,primary:e})},segmentRemove:function(t){return n("rem_seg",{seg:t})},tempStatus:function(t,e,r){return n("temp_status",{seg:t,above:e,below:r})},rewind:function(t){return n("rewind",{seg:t})},status:function(t,e,r){return n("status",{seg:t,above:e,below:r})},vert:function(e){return e===r?t:(r=e,n("vert",{x:e}))},log:function(t){return"string"!=typeof t&&(t=JSON.stringify(t,!1,"  ")),n("log",{txt:t})},reset:function(){return n("reset")},selected:function(t){return n("selected",{segs:t})},chainStart:function(t){return n("chain_start",{seg:t})},chainRemoveHead:function(t,e){return n("chain_rem_head",{index:t,pt:e})},chainRemoveTail:function(t,e){return n("chain_rem_tail",{index:t,pt:e})},chainNew:function(t,e){return n("chain_new",{pt1:t,pt2:e})},chainMatch:function(t){return n("chain_match",{index:t})},chainClose:function(t){return n("chain_close",{index:t})},chainAddHead:function(t,e){return n("chain_add_head",{index:t,pt:e})},chainAddTail:function(t,e){return n("chain_add_tail",{index:t,pt:e})},chainConnect:function(t,e){return n("chain_con",{index1:t,index2:e})},chainReverse:function(t){return n("chain_rev",{index:t})},chainJoin:function(t,e){return n("chain_join",{index1:t,index2:e})},done:function(){return n("done")}}}},{}],256:[function(t,e,r){e.exports=function(t){"number"!=typeof t&&(t=1e-10);var e={epsilon:function(e){return"number"==typeof e&&(t=e),t},pointAboveOrOnLine:function(e,r,n){var i=r[0],a=r[1],o=n[0],s=n[1],l=e[0];return(o-i)*(e[1]-a)-(s-a)*(l-i)>=-t},pointBetween:function(e,r,n){var i=e[1]-r[1],a=n[0]-r[0],o=e[0]-r[0],s=n[1]-r[1],l=o*a+i*s;return!(l<t)&&!(l-(a*a+s*s)>-t)},pointsSameX:function(e,r){return Math.abs(e[0]-r[0])<t},pointsSameY:function(e,r){return Math.abs(e[1]-r[1])<t},pointsSame:function(t,r){return e.pointsSameX(t,r)&&e.pointsSameY(t,r)},pointsCompare:function(t,r){return e.pointsSameX(t,r)?e.pointsSameY(t,r)?0:t[1]<r[1]?-1:1:t[0]<r[0]?-1:1},pointsCollinear:function(e,r,n){var i=e[0]-r[0],a=e[1]-r[1],o=r[0]-n[0],s=r[1]-n[1];return Math.abs(i*s-o*a)<t},linesIntersect:function(e,r,n,i){var a=r[0]-e[0],o=r[1]-e[1],s=i[0]-n[0],l=i[1]-n[1],c=a*l-o*s;if(Math.abs(c)<t)return!1;var u=e[0]-n[0],f=e[1]-n[1],h=(s*f-l*u)/c,p=(a*f-o*u)/c,d={alongA:0,alongB:0,pt:[e[0]+h*a,e[1]+h*o]};return d.alongA=h<=-t?-2:h<t?-1:h-1<=-t?0:h-1<t?1:2,d.alongB=p<=-t?-2:p<t?-1:p-1<=-t?0:p-1<t?1:2,d},pointInsideRegion:function(e,r){for(var n=e[0],i=e[1],a=r[r.length-1][0],o=r[r.length-1][1],s=!1,l=0;l<r.length;l++){var c=r[l][0],u=r[l][1];u-i>t!=o-i>t&&(a-c)*(i-u)/(o-u)+c-n>t&&(s=!s),a=c,o=u}return s}};return e}},{}],257:[function(t,e,r){var n={toPolygon:function(t,e){function r(e){if(e.length<=0)return t.segments({inverted:!1,regions:[]});function r(e){var r=e.slice(0,e.length-1);return t.segments({inverted:!1,regions:[r]})}for(var n=r(e[0]),i=1;i<e.length;i++)n=t.selectDifference(t.combine(n,r(e[i])));return n}if("Polygon"===e.type)return t.polygon(r(e.coordinates));if("MultiPolygon"===e.type){for(var n=t.segments({inverted:!1,regions:[]}),i=0;i<e.coordinates.length;i++)n=t.selectUnion(t.combine(n,r(e.coordinates[i])));return t.polygon(n)}throw new Error("PolyBool: Cannot convert GeoJSON object to PolyBool polygon")},fromPolygon:function(t,e,r){function n(t,r){return e.pointInsideRegion([.5*(t[0][0]+t[1][0]),.5*(t[0][1]+t[1][1])],r)}function i(t){return{region:t,children:[]}}r=t.polygon(t.segments(r));var a=i(null);function o(t,e){for(var r=0;r<t.children.length;r++){if(n(e,(s=t.children[r]).region))return void o(s,e)}var a=i(e);for(r=0;r<t.children.length;r++){var s;n((s=t.children[r]).region,e)&&(a.children.push(s),t.children.splice(r,1),r--)}t.children.push(a)}for(var s=0;s<r.regions.length;s++){var l=r.regions[s];l.length<3||o(a,l)}function c(t,e){for(var r=0,n=t[t.length-1][0],i=t[t.length-1][1],a=[],o=0;o<t.length;o++){var s=t[o][0],l=t[o][1];a.push([s,l]),r+=l*n-s*i,n=s,i=l}return r<0!==e&&a.reverse(),a.push([a[0][0],a[0][1]]),a}var u=[];function f(t){var e=[c(t.region,!1)];u.push(e);for(var r=0;r<t.children.length;r++)e.push(h(t.children[r]))}function h(t){for(var e=0;e<t.children.length;e++)f(t.children[e]);return c(t.region,!0)}for(s=0;s<a.children.length;s++)f(a.children[s]);return u.length<=0?{type:"Polygon",coordinates:[]}:1==u.length?{type:"Polygon",coordinates:u[0]}:{type:"MultiPolygon",coordinates:u}}};e.exports=n},{}],258:[function(t,e,r){var n=t("./linked-list");e.exports=function(t,e,r){function i(t,e,n){return{id:r?r.segmentId():-1,start:t,end:e,myFill:{above:n.myFill.above,below:n.myFill.below},otherFill:null}}var a=n.create();function o(t,r){a.insertBefore(t,(function(n){return function(t,r,n,i,a,o){var s=e.pointsCompare(r,a);return 0!==s?s:e.pointsSame(n,o)?0:t!==i?t?1:-1:e.pointAboveOrOnLine(n,i?a:o,i?o:a)?1:-1}(t.isStart,t.pt,r,n.isStart,n.pt,n.other.pt)<0}))}function s(t,e){var r=function(t,e){var r=n.node({isStart:!0,pt:t.start,seg:t,primary:e,other:null,status:null});return o(r,t.end),r}(t,e);return function(t,e,r){var i=n.node({isStart:!1,pt:e.end,seg:e,primary:r,other:t,status:null});t.other=i,o(i,t.pt)}(r,t,e),r}function l(t,e){var n=i(e,t.seg.end,t.seg);return function(t,e){r&&r.segmentChop(t.seg,e),t.other.remove(),t.seg.end=e,t.other.pt=e,o(t.other,t.pt)}(t,e),s(n,t.primary)}function c(i,o){var s=n.create();function c(t){return s.findTransition((function(r){var n,i,a,o,s,l;return(n=t,i=r.ev,a=n.seg.start,o=n.seg.end,s=i.seg.start,l=i.seg.end,e.pointsCollinear(a,s,l)?e.pointsCollinear(o,s,l)||e.pointAboveOrOnLine(o,s,l)?1:-1:e.pointAboveOrOnLine(a,s,l)?1:-1)>0}))}function u(t,n){var i=t.seg,a=n.seg,o=i.start,s=i.end,c=a.start,u=a.end;r&&r.checkIntersection(i,a);var f=e.linesIntersect(o,s,c,u);if(!1===f){if(!e.pointsCollinear(o,s,c))return!1;if(e.pointsSame(o,u)||e.pointsSame(s,c))return!1;var h=e.pointsSame(o,c),p=e.pointsSame(s,u);if(h&&p)return n;var d=!h&&e.pointBetween(o,c,u),m=!p&&e.pointBetween(s,c,u);if(h)return m?l(n,s):l(t,u),n;d&&(p||(m?l(n,s):l(t,u)),l(n,o))}else 0===f.alongA&&(-1===f.alongB?l(t,c):0===f.alongB?l(t,f.pt):1===f.alongB&&l(t,u)),0===f.alongB&&(-1===f.alongA?l(n,o):0===f.alongA?l(n,f.pt):1===f.alongA&&l(n,s));return!1}for(var f=[];!a.isEmpty();){var h=a.getHead();if(r&&r.vert(h.pt[0]),h.isStart){r&&r.segmentNew(h.seg,h.primary);var p=c(h),d=p.before?p.before.ev:null,m=p.after?p.after.ev:null;function g(){if(d){var t=u(h,d);if(t)return t}return!!m&&u(h,m)}r&&r.tempStatus(h.seg,!!d&&d.seg,!!m&&m.seg);var v,y=g();if(y){var x;if(t)(x=null===h.seg.myFill.below||h.seg.myFill.above!==h.seg.myFill.below)&&(y.seg.myFill.above=!y.seg.myFill.above);else y.seg.otherFill=h.seg.myFill;r&&r.segmentUpdate(y.seg),h.other.remove(),h.remove()}if(a.getHead()!==h){r&&r.rewind(h.seg);continue}if(t)x=null===h.seg.myFill.below||h.seg.myFill.above!==h.seg.myFill.below,h.seg.myFill.below=m?m.seg.myFill.above:i,h.seg.myFill.above=x?!h.seg.myFill.below:h.seg.myFill.below;else if(null===h.seg.otherFill)v=m?h.primary===m.primary?m.seg.otherFill.above:m.seg.myFill.above:h.primary?o:i,h.seg.otherFill={above:v,below:v};r&&r.status(h.seg,!!d&&d.seg,!!m&&m.seg),h.other.status=p.insert(n.node({ev:h}))}else{var b=h.status;if(null===b)throw new Error("PolyBool: Zero-length segment detected; your epsilon is probably too small or too large");if(s.exists(b.prev)&&s.exists(b.next)&&u(b.prev.ev,b.next.ev),r&&r.statusRemove(b.ev.seg),b.remove(),!h.primary){var _=h.seg.myFill;h.seg.myFill=h.seg.otherFill,h.seg.otherFill=_}f.push(h.seg)}a.getHead().remove()}return r&&r.done(),f}return t?{addRegion:function(t){for(var n,i,a,o=t[t.length-1],l=0;l<t.length;l++){n=o,o=t[l];var c=e.pointsCompare(n,o);0!==c&&s((i=c<0?n:o,a=c<0?o:n,{id:r?r.segmentId():-1,start:i,end:a,myFill:{above:null,below:null},otherFill:null}),!0)}},calculate:function(t){return c(t,!1)}}:{calculate:function(t,e,r,n){return t.forEach((function(t){s(i(t.start,t.end,t),!0)})),r.forEach((function(t){s(i(t.start,t.end,t),!1)})),c(e,n)}}}},{"./linked-list":259}],259:[function(t,e,r){e.exports={create:function(){var t={root:{root:!0,next:null},exists:function(e){return null!==e&&e!==t.root},isEmpty:function(){return null===t.root.next},getHead:function(){return t.root.next},insertBefore:function(e,r){for(var n=t.root,i=t.root.next;null!==i;){if(r(i))return e.prev=i.prev,e.next=i,i.prev.next=e,void(i.prev=e);n=i,i=i.next}n.next=e,e.prev=n,e.next=null},findTransition:function(e){for(var r=t.root,n=t.root.next;null!==n&&!e(n);)r=n,n=n.next;return{before:r===t.root?null:r,after:n,insert:function(t){return t.prev=r,t.next=n,r.next=t,null!==n&&(n.prev=t),t}}}};return t},node:function(t){return t.prev=null,t.next=null,t.remove=function(){t.prev.next=t.next,t.next&&(t.next.prev=t.prev),t.prev=null,t.next=null},t}}},{}],260:[function(t,e,r){e.exports=function(t,e,r){var n=[],i=[];return t.forEach((function(t){var a=t.start,o=t.end;if(e.pointsSame(a,o))console.warn("PolyBool: Warning: Zero-length segment detected; your epsilon is probably too small or too large");else{r&&r.chainStart(t);for(var s={index:0,matches_head:!1,matches_pt1:!1},l={index:0,matches_head:!1,matches_pt1:!1},c=s,u=0;u<n.length;u++){var f=(g=n[u])[0],h=(g[1],g[g.length-1]);g[g.length-2];if(e.pointsSame(f,a)){if(k(u,!0,!0))break}else if(e.pointsSame(f,o)){if(k(u,!0,!1))break}else if(e.pointsSame(h,a)){if(k(u,!1,!0))break}else if(e.pointsSame(h,o)&&k(u,!1,!1))break}if(c===s)return n.push([a,o]),void(r&&r.chainNew(a,o));if(c===l){r&&r.chainMatch(s.index);var p=s.index,d=s.matches_pt1?o:a,m=s.matches_head,g=n[p],v=m?g[0]:g[g.length-1],y=m?g[1]:g[g.length-2],x=m?g[g.length-1]:g[0],b=m?g[g.length-2]:g[1];return e.pointsCollinear(y,v,d)&&(m?(r&&r.chainRemoveHead(s.index,d),g.shift()):(r&&r.chainRemoveTail(s.index,d),g.pop()),v=y),e.pointsSame(x,d)?(n.splice(p,1),e.pointsCollinear(b,x,v)&&(m?(r&&r.chainRemoveTail(s.index,v),g.pop()):(r&&r.chainRemoveHead(s.index,v),g.shift())),r&&r.chainClose(s.index),void i.push(g)):void(m?(r&&r.chainAddHead(s.index,d),g.unshift(d)):(r&&r.chainAddTail(s.index,d),g.push(d)))}var _=s.index,w=l.index;r&&r.chainConnect(_,w);var T=n[_].length<n[w].length;s.matches_head?l.matches_head?T?(A(_),M(_,w)):(A(w),M(w,_)):M(w,_):l.matches_head?M(_,w):T?(A(_),M(w,_)):(A(w),M(_,w))}function k(t,e,r){return c.index=t,c.matches_head=e,c.matches_pt1=r,c===s?(c=l,!1):(c=null,!0)}function A(t){r&&r.chainReverse(t),n[t].reverse()}function M(t,i){var a=n[t],o=n[i],s=a[a.length-1],l=a[a.length-2],c=o[0],u=o[1];e.pointsCollinear(l,s,c)&&(r&&r.chainRemoveTail(t,s),a.pop(),s=l),e.pointsCollinear(s,c,u)&&(r&&r.chainRemoveHead(i,c),o.shift()),r&&r.chainJoin(t,i),n[t]=a.concat(o),n.splice(i,1)}})),i}},{}],261:[function(t,e,r){function n(t,e,r){var n=[];return t.forEach((function(t){var i=(t.myFill.above?8:0)+(t.myFill.below?4:0)+(t.otherFill&&t.otherFill.above?2:0)+(t.otherFill&&t.otherFill.below?1:0);0!==e[i]&&n.push({id:r?r.segmentId():-1,start:t.start,end:t.end,myFill:{above:1===e[i],below:2===e[i]},otherFill:null})})),r&&r.selected(n),n}var i={union:function(t,e){return n(t,[0,2,1,0,2,2,0,0,1,0,1,0,0,0,0,0],e)},intersect:function(t,e){return n(t,[0,0,0,0,0,2,0,2,0,0,1,1,0,2,1,0],e)},difference:function(t,e){return n(t,[0,0,0,0,2,0,2,0,1,1,0,0,0,1,2,0],e)},differenceRev:function(t,e){return n(t,[0,2,1,0,0,0,1,1,0,2,0,2,0,0,0,0],e)},xor:function(t,e){return n(t,[0,2,1,0,2,0,0,1,1,0,0,2,0,1,2,0],e)}};e.exports=i},{}],262:[function(t,e,r){"use strict";var n=t("stream").Transform,i=t("stream-parser");function a(){n.call(this,{readableObjectMode:!0})}function o(t,e,r){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack||"",this.name=this.constructor.name,this.message=t,e&&(this.code=e),r&&(this.statusCode=r)}a.prototype=Object.create(n.prototype),a.prototype.constructor=a,i(a.prototype),r.ParserStream=a,r.sliceEq=function(t,e,r){for(var n=e,i=0;i<r.length;)if(t[n++]!==r[i++])return!1;return!0},r.str2arr=function(t,e){var r=[],n=0;if(e&&"hex"===e)for(;n<t.length;)r.push(parseInt(t.slice(n,n+2),16)),n+=2;else for(;n<t.length;n++)r.push(255&t.charCodeAt(n));return r},r.readUInt16LE=function(t,e){return t[e]|t[e+1]<<8},r.readUInt16BE=function(t,e){return t[e+1]|t[e]<<8},r.readUInt32LE=function(t,e){return t[e]|t[e+1]<<8|t[e+2]<<16|16777216*t[e+3]},r.readUInt32BE=function(t,e){return t[e+3]|t[e+2]<<8|t[e+1]<<16|16777216*t[e]},o.prototype=Object.create(Error.prototype),o.prototype.constructor=o,r.ProbeError=o},{stream:285,"stream-parser":301}],263:[function(t,e,r){"use strict";function n(t,e){var r=new Error(t);return r.code=e,r}function i(t){try{return decodeURIComponent(escape(t))}catch(e){return t}}function a(t,e,r){this.input=t.subarray(e,r),this.start=e;var i=String.fromCharCode.apply(null,this.input.subarray(0,4));if("II*\0"!==i&&"MM\0*"!==i)throw n("invalid TIFF signature","EBADDATA");this.big_endian="M"===i[0]}a.prototype.each=function(t){this.aborted=!1;var e=this.read_uint32(4);for(this.ifds_to_read=[{id:0,offset:e}];this.ifds_to_read.length>0&&!this.aborted;){var r=this.ifds_to_read.shift();r.offset&&this.scan_ifd(r.id,r.offset,t)}},a.prototype.read_uint16=function(t){var e=this.input;if(t+2>e.length)throw n("unexpected EOF","EBADDATA");return this.big_endian?256*e[t]+e[t+1]:e[t]+256*e[t+1]},a.prototype.read_uint32=function(t){var e=this.input;if(t+4>e.length)throw n("unexpected EOF","EBADDATA");return this.big_endian?16777216*e[t]+65536*e[t+1]+256*e[t+2]+e[t+3]:e[t]+256*e[t+1]+65536*e[t+2]+16777216*e[t+3]},a.prototype.is_subifd_link=function(t,e){return 0===t&&34665===e||0===t&&34853===e||34665===t&&40965===e},a.prototype.exif_format_length=function(t){switch(t){case 1:case 2:case 6:case 7:return 1;case 3:case 8:return 2;case 4:case 9:case 11:return 4;case 5:case 10:case 12:return 8;default:return 0}},a.prototype.exif_format_read=function(t,e){var r;switch(t){case 1:case 2:return r=this.input[e];case 6:return(r=this.input[e])|33554430*(128&r);case 3:return r=this.read_uint16(e);case 8:return(r=this.read_uint16(e))|131070*(32768&r);case 4:return r=this.read_uint32(e);case 9:return 0|(r=this.read_uint32(e));case 5:case 10:case 11:case 12:case 7:default:return null}},a.prototype.scan_ifd=function(t,e,r){var a=this.read_uint16(e);e+=2;for(var o=0;o<a;o++){var s=this.read_uint16(e),l=this.read_uint16(e+2),c=this.read_uint32(e+4),u=this.exif_format_length(l),f=c*u,h=f<=4?e+8:this.read_uint32(e+8),p=!1;if(h+f>this.input.length)throw n("unexpected EOF","EBADDATA");for(var d=[],m=h,g=0;g<c;g++,m+=u){var v=this.exif_format_read(l,m);if(null===v){d=null;break}d.push(v)}if(Array.isArray(d)&&2===l&&(d=i(String.fromCharCode.apply(null,d)))&&"\0"===d[d.length-1]&&(d=d.slice(0,-1)),this.is_subifd_link(t,s)&&Array.isArray(d)&&Number.isInteger(d[0])&&d[0]>0&&(this.ifds_to_read.push({id:s,offset:d[0]}),p=!0),!1===r({is_big_endian:this.big_endian,ifd:t,tag:s,format:l,count:c,entry_offset:e+this.start,data_length:f,data_offset:h+this.start,value:d,is_subifd_link:p}))return void(this.aborted=!0);e+=12}0===t&&this.ifds_to_read.push({id:1,offset:this.read_uint32(e)})},e.exports.ExifParser=a,e.exports.get_orientation=function(t){var e=0;try{return new a(t,0,t.length).each((function(t){if(0===t.ifd&&274===t.tag&&Array.isArray(t.value))return e=t.value[0],!1})),e}catch(t){return-1}}},{}],264:[function(t,e,r){"use strict";var n=t("./common").readUInt16BE,i=t("./common").readUInt32BE;function a(t,e){if(t.length<4+e)return null;var r=i(t,e);return t.length<r+e||r<8?null:{boxtype:String.fromCharCode.apply(null,t.slice(e+4,e+8)),data:t.slice(e+8,e+r),end:e+r}}function o(t,e){for(var r=0;;){var n=a(t,r);if(!n)break;switch(n.boxtype){case"ispe":e.sizes.push({width:i(n.data,4),height:i(n.data,8)});break;case"irot":e.transforms.push({type:"irot",value:3&n.data[0]});break;case"imir":e.transforms.push({type:"imir",value:1&n.data[0]})}r=n.end}}function s(t,e,r){for(var n=0,i=0;i<r;i++)n=256*n+(t[e+i]||0);return n}function l(t,e){for(var r=t[4]>>4&15,i=15&t[4],a=t[5]>>4&15,o=n(t,6),l=8,c=0;c<o;c++){var u=n(t,l),f=n(t,l+=2),h=s(t,l+=2,a),p=n(t,l+=a);if(l+=2,0===f&&1===p){var d=s(t,l,r),m=s(t,l+r,i);e.item_loc[u]={length:m,offset:d+h}}l+=p*(r+i)}}function c(t,e){for(var r=n(t,4),i=6,o=0;o<r;o++){var s=a(t,i);if(!s)break;if("infe"===s.boxtype){for(var l=n(s.data,4),c="",u=8;u<s.data.length&&s.data[u];u++)c+=String.fromCharCode(s.data[u]);e.item_inf[c]=l}i=s.end}}function u(t,e){for(var r=0;;){var n=a(t,r);if(!n)break;"ipco"===n.boxtype&&o(n.data,e),r=n.end}}e.exports.unbox=a,e.exports.readSizeFromMeta=function(t){var e={sizes:[],transforms:[],item_inf:{},item_loc:{}};if(function(t,e){for(var r=4;;){var n=a(t,r);if(!n)break;"iprp"===n.boxtype&&u(n.data,e),"iloc"===n.boxtype&&l(n.data,e),"iinf"===n.boxtype&&c(n.data,e),r=n.end}}(t,e),e.sizes.length){var r,n,i,o=(r=e.sizes,n=r.reduce((function(t,e){return t.width>e.width||t.width===e.width&&t.height>e.height?t:e})),i=r.reduce((function(t,e){return t.height>e.height||t.height===e.height&&t.width>e.width?t:e})),n.width>i.height||n.width===i.height&&n.height>i.width?n:i),s=1;e.transforms.forEach((function(t){var e={1:6,2:5,3:8,4:7,5:4,6:3,7:2,8:1},r={1:4,2:3,3:2,4:1,5:6,6:5,7:8,8:7};if("imir"===t.type&&(s=0===t.value?r[s]:e[s=e[s=r[s]]]),"irot"===t.type)for(var n=0;n<t.value;n++)s=e[s]}));var f=null;return e.item_inf.Exif&&(f=e.item_loc[e.item_inf.Exif]),{width:o.width,height:o.height,orientation:e.transforms.length?s:null,variants:e.sizes,exif_location:f}}},e.exports.getMimeType=function(t){var e=String.fromCharCode.apply(null,t.slice(0,4)),r={};r[e]=!0;for(var n=8;n<t.length;n+=4)r[String.fromCharCode.apply(null,t.slice(n,n+4))]=!0;if(r.mif1||r.msf1||r.miaf)return"avif"===e||"avis"===e||"avio"===e?{type:"avif",mime:"image/avif"}:"heic"===e||"heix"===e?{type:"heic",mime:"image/heic"}:"hevc"===e||"hevx"===e?{type:"heic",mime:"image/heic-sequence"}:r.avif||r.avis?{type:"avif",mime:"image/avif"}:r.heic||r.heix||r.hevc||r.hevx||r.heis?r.msf1?{type:"heif",mime:"image/heif-sequence"}:{type:"heif",mime:"image/heif"}:{type:"avif",mime:"image/avif"}}},{"./common":262}],265:[function(t,e,r){"use strict";var n=t("../common").str2arr,i=t("../common").sliceEq,a=t("../common").readUInt32BE,o=t("../miaf_utils"),s=t("../exif_utils"),l=n("ftyp");e.exports=function(t){if(i(t,4,l)){var e=o.unbox(t,0);if(e){var r=o.getMimeType(e.data);if(r){for(var n,c=e.end;;){var u=o.unbox(t,c);if(!u)break;if(c=u.end,"mdat"===u.boxtype)return;if("meta"===u.boxtype){n=u.data;break}}if(n){var f=o.readSizeFromMeta(n);if(f){var h={width:f.width,height:f.height,type:r.type,mime:r.mime,wUnits:"px",hUnits:"px"};if(f.variants.length>1&&(h.variants=f.variants),f.orientation&&(h.orientation=f.orientation),f.exif_location&&f.exif_location.offset+f.exif_location.length<=t.length){var p=a(t,f.exif_location.offset),d=t.slice(f.exif_location.offset+p+4,f.exif_location.offset+f.exif_location.length),m=s.get_orientation(d);m>0&&(h.orientation=m)}return h}}}}}}},{"../common":262,"../exif_utils":263,"../miaf_utils":264}],266:[function(t,e,r){"use strict";var n=t("../common").str2arr,i=t("../common").sliceEq,a=t("../common").readUInt16LE,o=n("BM");e.exports=function(t){if(!(t.length<26)&&i(t,0,o))return{width:a(t,18),height:a(t,22),type:"bmp",mime:"image/bmp",wUnits:"px",hUnits:"px"}}},{"../common":262}],267:[function(t,e,r){"use strict";var n=t("../common").str2arr,i=t("../common").sliceEq,a=t("../common").readUInt16LE,o=n("GIF87a"),s=n("GIF89a");e.exports=function(t){if(!(t.length<10)&&(i(t,0,o)||i(t,0,s)))return{width:a(t,6),height:a(t,8),type:"gif",mime:"image/gif",wUnits:"px",hUnits:"px"}}},{"../common":262}],268:[function(t,e,r){"use strict";var n=t("../common").readUInt16LE;e.exports=function(t){var e=n(t,0),r=n(t,2),i=n(t,4);if(0===e&&1===r&&i){for(var a=[],o={width:0,height:0},s=0;s<i;s++){var l=t[6+16*s]||256,c=t[6+16*s+1]||256,u={width:l,height:c};a.push(u),(l>o.width||c>o.height)&&(o=u)}return{width:o.width,height:o.height,variants:a,type:"ico",mime:"image/x-icon",wUnits:"px",hUnits:"px"}}}},{"../common":262}],269:[function(t,e,r){"use strict";var n=t("../common").readUInt16BE,i=t("../common").str2arr,a=t("../common").sliceEq,o=t("../exif_utils"),s=i("Exif\0\0");e.exports=function(t){if(!(t.length<2)&&255===t[0]&&216===t[1]&&255===t[2])for(var e=2;;){for(;;){if(t.length-e<2)return;if(255===t[e++])break}for(var r,i,l=t[e++];255===l;)l=t[e++];if(208<=l&&l<=217||1===l)r=0;else{if(!(192<=l&&l<=254))return;if(t.length-e<2)return;r=n(t,e)-2,e+=2}if(217===l||218===l)return;if(225===l&&r>=10&&a(t,e,s)&&(i=o.get_orientation(t.slice(e+6,e+r))),r>=5&&192<=l&&l<=207&&196!==l&&200!==l&&204!==l){if(t.length-e<r)return;var c={width:n(t,e+3),height:n(t,e+1),type:"jpg",mime:"image/jpeg",wUnits:"px",hUnits:"px"};return i>0&&(c.orientation=i),c}e+=r}}},{"../common":262,"../exif_utils":263}],270:[function(t,e,r){"use strict";var n=t("../common").str2arr,i=t("../common").sliceEq,a=t("../common").readUInt32BE,o=n("\x89PNG\r\n\x1a\n"),s=n("IHDR");e.exports=function(t){if(!(t.length<24)&&i(t,0,o)&&i(t,12,s))return{width:a(t,16),height:a(t,20),type:"png",mime:"image/png",wUnits:"px",hUnits:"px"}}},{"../common":262}],271:[function(t,e,r){"use strict";var n=t("../common").str2arr,i=t("../common").sliceEq,a=t("../common").readUInt32BE,o=n("8BPS\0\x01");e.exports=function(t){if(!(t.length<22)&&i(t,0,o))return{width:a(t,18),height:a(t,14),type:"psd",mime:"image/vnd.adobe.photoshop",wUnits:"px",hUnits:"px"}}},{"../common":262}],272:[function(t,e,r){"use strict";function n(t){return"number"==typeof t&&isFinite(t)&&t>0}var i=/<[-_.:a-zA-Z0-9][^>]*>/,a=/^<([-_.:a-zA-Z0-9]+:)?svg\s/,o=/[^-]\bwidth="([^%]+?)"|[^-]\bwidth='([^%]+?)'/,s=/\bheight="([^%]+?)"|\bheight='([^%]+?)'/,l=/\bview[bB]ox="(.+?)"|\bview[bB]ox='(.+?)'/,c=/in$|mm$|cm$|pt$|pc$|px$|em$|ex$/;function u(t){return c.test(t)?t.match(c)[0]:"px"}e.exports=function(t){if(function(t){var e,r=0,n=t.length;for(239===t[0]&&187===t[1]&&191===t[2]&&(r=3);r<n&&(32===(e=t[r])||9===e||13===e||10===e);)r++;return r!==n&&60===t[r]}(t)){for(var e="",r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);var c=(e.match(i)||[""])[0];if(a.test(c)){var f=function(t){var e=t.match(o),r=t.match(s),n=t.match(l);return{width:e&&(e[1]||e[2]),height:r&&(r[1]||r[2]),viewbox:n&&(n[1]||n[2])}}(c),h=parseFloat(f.width),p=parseFloat(f.height);if(f.width&&f.height){if(!n(h)||!n(p))return;return{width:h,height:p,type:"svg",mime:"image/svg+xml",wUnits:u(f.width),hUnits:u(f.height)}}var d=(f.viewbox||"").split(" "),m={width:d[2],height:d[3]},g=parseFloat(m.width),v=parseFloat(m.height);if(n(g)&&n(v)&&u(m.width)===u(m.height)){var y=g/v;if(f.width){if(!n(h))return;return{width:h,height:h/y,type:"svg",mime:"image/svg+xml",wUnits:u(f.width),hUnits:u(f.width)}}if(f.height){if(!n(p))return;return{width:p*y,height:p,type:"svg",mime:"image/svg+xml",wUnits:u(f.height),hUnits:u(f.height)}}return{width:g,height:v,type:"svg",mime:"image/svg+xml",wUnits:u(m.width),hUnits:u(m.height)}}}}}},{}],273:[function(t,e,r){"use strict";var n=t("../common").str2arr,i=t("../common").sliceEq,a=t("../common").readUInt16LE,o=t("../common").readUInt16BE,s=t("../common").readUInt32LE,l=t("../common").readUInt32BE,c=n("II*\0"),u=n("MM\0*");function f(t,e,r){return r?o(t,e):a(t,e)}function h(t,e,r){return r?l(t,e):s(t,e)}function p(t,e,r){var n=f(t,e+2,r);return 1!==h(t,e+4,r)||3!==n&&4!==n?null:3===n?f(t,e+8,r):h(t,e+8,r)}e.exports=function(t){if(!(t.length<8)&&(i(t,0,c)||i(t,0,u))){var e=77===t[0],r=h(t,4,e)-8;if(!(r<0)){var n=r+8;if(!(t.length-n<2)){var a=12*f(t,n+0,e);if(!(a<=0||(n+=2,t.length-n<a))){var o,s,l,d;for(o=0;o<a;o+=12)256===(d=f(t,n+o,e))?s=p(t,n+o,e):257===d&&(l=p(t,n+o,e));return s&&l?{width:s,height:l,type:"tiff",mime:"image/tiff",wUnits:"px",hUnits:"px"}:void 0}}}}}},{"../common":262}],274:[function(t,e,r){"use strict";var n=t("../common").str2arr,i=t("../common").sliceEq,a=t("../common").readUInt16LE,o=t("../common").readUInt32LE,s=t("../exif_utils"),l=n("RIFF"),c=n("WEBP");function u(t,e){if(157===t[e+3]&&1===t[e+4]&&42===t[e+5])return{width:16383&a(t,e+6),height:16383&a(t,e+8),type:"webp",mime:"image/webp",wUnits:"px",hUnits:"px"}}function f(t,e){if(47===t[e]){var r=o(t,e+1);return{width:1+(16383&r),height:1+(r>>14&16383),type:"webp",mime:"image/webp",wUnits:"px",hUnits:"px"}}}function h(t,e){return{width:1+(t[e+6]<<16|t[e+5]<<8|t[e+4]),height:1+(t[e+9]<<e|t[e+8]<<8|t[e+7]),type:"webp",mime:"image/webp",wUnits:"px",hUnits:"px"}}e.exports=function(t){if(!(t.length<16)&&(i(t,0,l)||i(t,8,c))){var e=12,r=null,n=0,a=o(t,4)+8;if(!(a>t.length)){for(;e+8<a;)if(0!==t[e]){var p=String.fromCharCode.apply(null,t.slice(e,e+4)),d=o(t,e+4);"VP8 "===p&&d>=10?r=r||u(t,e+8):"VP8L"===p&&d>=9?r=r||f(t,e+8):"VP8X"===p&&d>=10?r=r||h(t,e+8):"EXIF"===p&&(n=s.get_orientation(t.slice(e+8,e+8+d)),e=1/0),e+=8+d}else e++;if(r)return n>0&&(r.orientation=n),r}}}},{"../common":262,"../exif_utils":263}],275:[function(t,e,r){"use strict";e.exports={avif:t("./parse_sync/avif"),bmp:t("./parse_sync/bmp"),gif:t("./parse_sync/gif"),ico:t("./parse_sync/ico"),jpeg:t("./parse_sync/jpeg"),png:t("./parse_sync/png"),psd:t("./parse_sync/psd"),svg:t("./parse_sync/svg"),tiff:t("./parse_sync/tiff"),webp:t("./parse_sync/webp")}},{"./parse_sync/avif":265,"./parse_sync/bmp":266,"./parse_sync/gif":267,"./parse_sync/ico":268,"./parse_sync/jpeg":269,"./parse_sync/png":270,"./parse_sync/psd":271,"./parse_sync/svg":272,"./parse_sync/tiff":273,"./parse_sync/webp":274}],276:[function(t,e,r){"use strict";var n=t("./lib/parsers_sync");e.exports=function(t){return function(t){for(var e=Object.keys(n),r=0;r<e.length;r++){var i=n[e[r]](t);if(i)return i}return null}(t)},e.exports.parsers=n},{"./lib/parsers_sync":275}],277:[function(t,e,r){var n,i,a=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function l(t){if(n===setTimeout)return setTimeout(t,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(t){n=o}try{i="function"==typeof clearTimeout?clearTimeout:s}catch(t){i=s}}();var c,u=[],f=!1,h=-1;function p(){f&&c&&(f=!1,c.length?u=c.concat(u):h=-1,u.length&&d())}function d(){if(!f){var t=l(p);f=!0;for(var e=u.length;e;){for(c=u,u=[];++h<e;)c&&c[h].run();h=-1,e=u.length}c=null,f=!1,function(t){if(i===clearTimeout)return clearTimeout(t);if((i===s||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(t);try{i(t)}catch(e){try{return i.call(null,t)}catch(e){return i.call(this,t)}}}(t)}}function m(t,e){this.fun=t,this.array=e}function g(){}a.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];u.push(new m(t,e)),1!==u.length||f||l(d)},m.prototype.run=function(){this.fun.apply(null,this.array)},a.title="browser",a.browser=!0,a.env={},a.argv=[],a.version="",a.versions={},a.on=g,a.addListener=g,a.once=g,a.off=g,a.removeListener=g,a.removeAllListeners=g,a.emit=g,a.prependListener=g,a.prependOnceListener=g,a.listeners=function(t){return[]},a.binding=function(t){throw new Error("process.binding is not supported")},a.cwd=function(){return"/"},a.chdir=function(t){throw new Error("process.chdir is not supported")},a.umask=function(){return 0}},{}],278:[function(t,e,r){(function(r){(function(){for(var n=t("performance-now"),i="undefined"==typeof window?r:window,a=["moz","webkit"],o="AnimationFrame",s=i["request"+o],l=i["cancel"+o]||i["cancelRequest"+o],c=0;!s&&c<a.length;c++)s=i[a[c]+"Request"+o],l=i[a[c]+"Cancel"+o]||i[a[c]+"CancelRequest"+o];if(!s||!l){var u=0,f=0,h=[];s=function(t){if(0===h.length){var e=n(),r=Math.max(0,1e3/60-(e-u));u=r+e,setTimeout((function(){var t=h.slice(0);h.length=0;for(var e=0;e<t.length;e++)if(!t[e].cancelled)try{t[e].callback(u)}catch(t){setTimeout((function(){throw t}),0)}}),Math.round(r))}return h.push({handle:++f,callback:t,cancelled:!1}),f},l=function(t){for(var e=0;e<h.length;e++)h[e].handle===t&&(h[e].cancelled=!0)}}e.exports=function(t){return s.call(i,t)},e.exports.cancel=function(){l.apply(i,arguments)},e.exports.polyfill=function(t){t||(t=i),t.requestAnimationFrame=s,t.cancelAnimationFrame=l}}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"performance-now":252}],279:[function(t,e,r){"use strict";var n=t("array-bounds"),i=t("color-normalize"),a=t("update-diff"),o=t("pick-by-alias"),s=t("object-assign"),l=t("flatten-vertex-data"),c=t("to-float32"),u=c.float32,f=c.fract32;e.exports=function(t,e){"function"==typeof t?(e||(e={}),e.regl=t):e=t;e.length&&(e.positions=e);if(!(t=e.regl).hasExtension("ANGLE_instanced_arrays"))throw Error("regl-error2d: `ANGLE_instanced_arrays` extension should be enabled");var r,c,p,d,m,g,v=t._gl,y={color:"black",capSize:5,lineWidth:1,opacity:1,viewport:null,range:null,offset:0,count:0,bounds:null,positions:[],errors:[]},x=[];return d=t.buffer({usage:"dynamic",type:"uint8",data:new Uint8Array(0)}),c=t.buffer({usage:"dynamic",type:"float",data:new Uint8Array(0)}),p=t.buffer({usage:"dynamic",type:"float",data:new Uint8Array(0)}),m=t.buffer({usage:"dynamic",type:"float",data:new Uint8Array(0)}),g=t.buffer({usage:"static",type:"float",data:h}),T(e),r=t({vert:"\n\t\tprecision highp float;\n\n\t\tattribute vec2 position, positionFract;\n\t\tattribute vec4 error;\n\t\tattribute vec4 color;\n\n\t\tattribute vec2 direction, lineOffset, capOffset;\n\n\t\tuniform vec4 viewport;\n\t\tuniform float lineWidth, capSize;\n\t\tuniform vec2 scale, scaleFract, translate, translateFract;\n\n\t\tvarying vec4 fragColor;\n\n\t\tvoid main() {\n\t\t\tfragColor = color / 255.;\n\n\t\t\tvec2 pixelOffset = lineWidth * lineOffset + (capSize + lineWidth) * capOffset;\n\n\t\t\tvec2 dxy = -step(.5, direction.xy) * error.xz + step(direction.xy, vec2(-.5)) * error.yw;\n\n\t\t\tvec2 position = position + dxy;\n\n\t\t\tvec2 pos = (position + translate) * scale\n\t\t\t\t+ (positionFract + translateFract) * scale\n\t\t\t\t+ (position + translate) * scaleFract\n\t\t\t\t+ (positionFract + translateFract) * scaleFract;\n\n\t\t\tpos += pixelOffset / viewport.zw;\n\n\t\t\tgl_Position = vec4(pos * 2. - 1., 0, 1);\n\t\t}\n\t\t",frag:"\n\t\tprecision highp float;\n\n\t\tvarying vec4 fragColor;\n\n\t\tuniform float opacity;\n\n\t\tvoid main() {\n\t\t\tgl_FragColor = fragColor;\n\t\t\tgl_FragColor.a *= opacity;\n\t\t}\n\t\t",uniforms:{range:t.prop("range"),lineWidth:t.prop("lineWidth"),capSize:t.prop("capSize"),opacity:t.prop("opacity"),scale:t.prop("scale"),translate:t.prop("translate"),scaleFract:t.prop("scaleFract"),translateFract:t.prop("translateFract"),viewport:function(t,e){return[e.viewport.x,e.viewport.y,t.viewportWidth,t.viewportHeight]}},attributes:{color:{buffer:d,offset:function(t,e){return 4*e.offset},divisor:1},position:{buffer:c,offset:function(t,e){return 8*e.offset},divisor:1},positionFract:{buffer:p,offset:function(t,e){return 8*e.offset},divisor:1},error:{buffer:m,offset:function(t,e){return 16*e.offset},divisor:1},direction:{buffer:g,stride:24,offset:0},lineOffset:{buffer:g,stride:24,offset:8},capOffset:{buffer:g,stride:24,offset:16}},primitive:"triangles",blend:{enable:!0,color:[0,0,0,0],equation:{rgb:"add",alpha:"add"},func:{srcRGB:"src alpha",dstRGB:"one minus src alpha",srcAlpha:"one minus dst alpha",dstAlpha:"one"}},depth:{enable:!1},scissor:{enable:!0,box:t.prop("viewport")},viewport:t.prop("viewport"),stencil:!1,instances:t.prop("count"),count:h.length}),s(b,{update:T,draw:_,destroy:k,regl:t,gl:v,canvas:v.canvas,groups:x}),b;function b(t){t?T(t):null===t&&k(),_()}function _(e){if("number"==typeof e)return w(e);e&&!Array.isArray(e)&&(e=[e]),t._refresh(),x.forEach((function(t,r){t&&(e&&(e[r]?t.draw=!0:t.draw=!1),t.draw?w(r):t.draw=!0)}))}function w(t){"number"==typeof t&&(t=x[t]),null!=t&&t&&t.count&&t.color&&t.opacity&&t.positions&&t.positions.length>1&&(t.scaleRatio=[t.scale[0]*t.viewport.width,t.scale[1]*t.viewport.height],r(t),t.after&&t.after(t))}function T(t){if(t){null!=t.length?"number"==typeof t[0]&&(t=[{positions:t}]):Array.isArray(t)||(t=[t]);var e=0,r=0;if(b.groups=x=t.map((function(t,c){var u=x[c];return t?("function"==typeof t?t={after:t}:"number"==typeof t[0]&&(t={positions:t}),t=o(t,{color:"color colors fill",capSize:"capSize cap capsize cap-size",lineWidth:"lineWidth line-width width line thickness",opacity:"opacity alpha",range:"range dataBox",viewport:"viewport viewBox",errors:"errors error",positions:"positions position data points"}),u||(x[c]=u={id:c,scale:null,translate:null,scaleFract:null,translateFract:null,draw:!0},t=s({},y,t)),a(u,t,[{lineWidth:function(t){return.5*+t},capSize:function(t){return.5*+t},opacity:parseFloat,errors:function(t){return t=l(t),r+=t.length,t},positions:function(t,r){return t=l(t,"float64"),r.count=Math.floor(t.length/2),r.bounds=n(t,2),r.offset=e,e+=r.count,t}},{color:function(t,e){var r=e.count;if(t||(t="transparent"),!Array.isArray(t)||"number"==typeof t[0]){var n=t;t=Array(r);for(var a=0;a<r;a++)t[a]=n}if(t.length<r)throw Error("Not enough colors");for(var o=new Uint8Array(4*r),s=0;s<r;s++){var l=i(t[s],"uint8");o.set(l,4*s)}return o},range:function(t,e,r){var n=e.bounds;return t||(t=n),e.scale=[1/(t[2]-t[0]),1/(t[3]-t[1])],e.translate=[-t[0],-t[1]],e.scaleFract=f(e.scale),e.translateFract=f(e.translate),t},viewport:function(t){var e;return Array.isArray(t)?e={x:t[0],y:t[1],width:t[2]-t[0],height:t[3]-t[1]}:t?(e={x:t.x||t.left||0,y:t.y||t.top||0},t.right?e.width=t.right-e.x:e.width=t.w||t.width||0,t.bottom?e.height=t.bottom-e.y:e.height=t.h||t.height||0):e={x:0,y:0,width:v.drawingBufferWidth,height:v.drawingBufferHeight},e}}]),u):u})),e||r){var h=x.reduce((function(t,e,r){return t+(e?e.count:0)}),0),g=new Float64Array(2*h),_=new Uint8Array(4*h),w=new Float32Array(4*h);x.forEach((function(t,e){if(t){var r=t.positions,n=t.count,i=t.offset,a=t.color,o=t.errors;n&&(_.set(a,4*i),w.set(o,4*i),g.set(r,2*i))}}));var T=u(g);c(T);var k=f(g,T);p(k),d(_),m(w)}}}function k(){c.destroy(),p.destroy(),d.destroy(),m.destroy(),g.destroy()}};var h=[[1,0,0,1,0,0],[1,0,0,-1,0,0],[-1,0,0,-1,0,0],[-1,0,0,-1,0,0],[-1,0,0,1,0,0],[1,0,0,1,0,0],[1,0,-1,0,0,1],[1,0,-1,0,0,-1],[1,0,1,0,0,-1],[1,0,1,0,0,-1],[1,0,1,0,0,1],[1,0,-1,0,0,1],[-1,0,-1,0,0,1],[-1,0,-1,0,0,-1],[-1,0,1,0,0,-1],[-1,0,1,0,0,-1],[-1,0,1,0,0,1],[-1,0,-1,0,0,1],[0,1,1,0,0,0],[0,1,-1,0,0,0],[0,-1,-1,0,0,0],[0,-1,-1,0,0,0],[0,1,1,0,0,0],[0,-1,1,0,0,0],[0,1,0,-1,1,0],[0,1,0,-1,-1,0],[0,1,0,1,-1,0],[0,1,0,1,1,0],[0,1,0,-1,1,0],[0,1,0,1,-1,0],[0,-1,0,-1,1,0],[0,-1,0,-1,-1,0],[0,-1,0,1,-1,0],[0,-1,0,1,1,0],[0,-1,0,-1,1,0],[0,-1,0,1,-1,0]]},{"array-bounds":71,"color-normalize":89,"flatten-vertex-data":191,"object-assign":247,"pick-by-alias":253,"to-float32":313,"update-diff":329}],280:[function(t,e,r){"use strict";var n=t("color-normalize"),i=t("array-bounds"),a=t("object-assign"),o=t("glslify"),s=t("pick-by-alias"),l=t("flatten-vertex-data"),c=t("earcut"),u=t("array-normalize"),f=t("to-float32"),h=f.float32,p=f.fract32,d=t("es6-weak-map"),m=t("parse-rect"),g=t("array-find-index");function v(t,e){if(!(this instanceof v))return new v(t,e);if("function"==typeof t?(e||(e={}),e.regl=t):e=t,e.length&&(e.positions=e),!(t=e.regl).hasExtension("ANGLE_instanced_arrays"))throw Error("regl-error2d: `ANGLE_instanced_arrays` extension should be enabled");this.gl=t._gl,this.regl=t,this.passes=[],this.shaders=v.shaders.has(t)?v.shaders.get(t):v.shaders.set(t,v.createShaders(t)).get(t),this.update(e)}e.exports=v,v.dashMult=2,v.maxPatternLength=256,v.precisionThreshold=3e6,v.maxPoints=1e4,v.maxLines=2048,v.shaders=new d,v.createShaders=function(t){var e,r=t.buffer({usage:"static",type:"float",data:[0,1,0,0,1,1,1,0]}),n={primitive:"triangle strip",instances:t.prop("count"),count:4,offset:0,uniforms:{miterMode:function(t,e){return"round"===e.join?2:1},miterLimit:t.prop("miterLimit"),scale:t.prop("scale"),scaleFract:t.prop("scaleFract"),translateFract:t.prop("translateFract"),translate:t.prop("translate"),thickness:t.prop("thickness"),dashTexture:t.prop("dashTexture"),opacity:t.prop("opacity"),pixelRatio:t.context("pixelRatio"),id:t.prop("id"),dashLength:t.prop("dashLength"),viewport:function(t,e){return[e.viewport.x,e.viewport.y,t.viewportWidth,t.viewportHeight]},depth:t.prop("depth")},blend:{enable:!0,color:[0,0,0,0],equation:{rgb:"add",alpha:"add"},func:{srcRGB:"src alpha",dstRGB:"one minus src alpha",srcAlpha:"one minus dst alpha",dstAlpha:"one"}},depth:{enable:function(t,e){return!e.overlay}},stencil:{enable:!1},scissor:{enable:!0,box:t.prop("viewport")},viewport:t.prop("viewport")},i=t(a({vert:o(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec2 aCoord, bCoord, aCoordFract, bCoordFract;\nattribute vec4 color;\nattribute float lineEnd, lineTop;\n\nuniform vec2 scale, scaleFract, translate, translateFract;\nuniform float thickness, pixelRatio, id, depth;\nuniform vec4 viewport;\n\nvarying vec4 fragColor;\nvarying vec2 tangent;\n\nvec2 project(vec2 position, vec2 positionFract, vec2 scale, vec2 scaleFract, vec2 translate, vec2 translateFract) {\n\t// the order is important\n\treturn position * scale + translate\n       + positionFract * scale + translateFract\n       + position * scaleFract\n       + positionFract * scaleFract;\n}\n\nvoid main() {\n\tfloat lineStart = 1. - lineEnd;\n\tfloat lineOffset = lineTop * 2. - 1.;\n\n\tvec2 diff = (bCoord + bCoordFract - aCoord - aCoordFract);\n\ttangent = normalize(diff * scale * viewport.zw);\n\tvec2 normal = vec2(-tangent.y, tangent.x);\n\n\tvec2 position = project(aCoord, aCoordFract, scale, scaleFract, translate, translateFract) * lineStart\n\t\t+ project(bCoord, bCoordFract, scale, scaleFract, translate, translateFract) * lineEnd\n\n\t\t+ thickness * normal * .5 * lineOffset / viewport.zw;\n\n\tgl_Position = vec4(position * 2.0 - 1.0, depth, 1);\n\n\tfragColor = color / 255.;\n}\n"]),frag:o(["precision highp float;\n#define GLSLIFY 1\n\nuniform float dashLength, pixelRatio, thickness, opacity, id;\nuniform sampler2D dashTexture;\n\nvarying vec4 fragColor;\nvarying vec2 tangent;\n\nvoid main() {\n\tfloat alpha = 1.;\n\n\tfloat t = fract(dot(tangent, gl_FragCoord.xy) / dashLength) * .5 + .25;\n\tfloat dash = texture2D(dashTexture, vec2(t, .5)).r;\n\n\tgl_FragColor = fragColor;\n\tgl_FragColor.a *= alpha * opacity * dash;\n}\n"]),attributes:{lineEnd:{buffer:r,divisor:0,stride:8,offset:0},lineTop:{buffer:r,divisor:0,stride:8,offset:4},aCoord:{buffer:t.prop("positionBuffer"),stride:8,offset:8,divisor:1},bCoord:{buffer:t.prop("positionBuffer"),stride:8,offset:16,divisor:1},aCoordFract:{buffer:t.prop("positionFractBuffer"),stride:8,offset:8,divisor:1},bCoordFract:{buffer:t.prop("positionFractBuffer"),stride:8,offset:16,divisor:1},color:{buffer:t.prop("colorBuffer"),stride:4,offset:0,divisor:1}}},n));try{e=t(a({cull:{enable:!0,face:"back"},vert:o(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec2 aCoord, bCoord, nextCoord, prevCoord;\nattribute vec4 aColor, bColor;\nattribute float lineEnd, lineTop;\n\nuniform vec2 scale, translate;\nuniform float thickness, pixelRatio, id, depth;\nuniform vec4 viewport;\nuniform float miterLimit, miterMode;\n\nvarying vec4 fragColor;\nvarying vec4 startCutoff, endCutoff;\nvarying vec2 tangent;\nvarying vec2 startCoord, endCoord;\nvarying float enableStartMiter, enableEndMiter;\n\nconst float REVERSE_THRESHOLD = -.875;\nconst float MIN_DIFF = 1e-6;\n\n// TODO: possible optimizations: avoid overcalculating all for vertices and calc just one instead\n// TODO: precalculate dot products, normalize things beforehead etc.\n// TODO: refactor to rectangular algorithm\n\nfloat distToLine(vec2 p, vec2 a, vec2 b) {\n\tvec2 diff = b - a;\n\tvec2 perp = normalize(vec2(-diff.y, diff.x));\n\treturn dot(p - a, perp);\n}\n\nbool isNaN( float val ){\n  return ( val < 0.0 || 0.0 < val || val == 0.0 ) ? false : true;\n}\n\nvoid main() {\n\tvec2 aCoord = aCoord, bCoord = bCoord, prevCoord = prevCoord, nextCoord = nextCoord;\n\n  vec2 adjustedScale;\n  adjustedScale.x = (abs(scale.x) < MIN_DIFF) ? MIN_DIFF : scale.x;\n  adjustedScale.y = (abs(scale.y) < MIN_DIFF) ? MIN_DIFF : scale.y;\n\n  vec2 scaleRatio = adjustedScale * viewport.zw;\n\tvec2 normalWidth = thickness / scaleRatio;\n\n\tfloat lineStart = 1. - lineEnd;\n\tfloat lineBot = 1. - lineTop;\n\n\tfragColor = (lineStart * aColor + lineEnd * bColor) / 255.;\n\n\tif (isNaN(aCoord.x) || isNaN(aCoord.y) || isNaN(bCoord.x) || isNaN(bCoord.y)) return;\n\n\tif (aCoord == prevCoord) prevCoord = aCoord + normalize(bCoord - aCoord);\n\tif (bCoord == nextCoord) nextCoord = bCoord - normalize(bCoord - aCoord);\n\n\tvec2 prevDiff = aCoord - prevCoord;\n\tvec2 currDiff = bCoord - aCoord;\n\tvec2 nextDiff = nextCoord - bCoord;\n\n\tvec2 prevTangent = normalize(prevDiff * scaleRatio);\n\tvec2 currTangent = normalize(currDiff * scaleRatio);\n\tvec2 nextTangent = normalize(nextDiff * scaleRatio);\n\n\tvec2 prevNormal = vec2(-prevTangent.y, prevTangent.x);\n\tvec2 currNormal = vec2(-currTangent.y, currTangent.x);\n\tvec2 nextNormal = vec2(-nextTangent.y, nextTangent.x);\n\n\tvec2 startJoinDirection = normalize(prevTangent - currTangent);\n\tvec2 endJoinDirection = normalize(currTangent - nextTangent);\n\n\t// collapsed/unidirectional segment cases\n\t// FIXME: there should be more elegant solution\n\tvec2 prevTanDiff = abs(prevTangent - currTangent);\n\tvec2 nextTanDiff = abs(nextTangent - currTangent);\n\tif (max(prevTanDiff.x, prevTanDiff.y) < MIN_DIFF) {\n\t\tstartJoinDirection = currNormal;\n\t}\n\tif (max(nextTanDiff.x, nextTanDiff.y) < MIN_DIFF) {\n\t\tendJoinDirection = currNormal;\n\t}\n\tif (aCoord == bCoord) {\n\t\tendJoinDirection = startJoinDirection;\n\t\tcurrNormal = prevNormal;\n\t\tcurrTangent = prevTangent;\n\t}\n\n\ttangent = currTangent;\n\n\t//calculate join shifts relative to normals\n\tfloat startJoinShift = dot(currNormal, startJoinDirection);\n\tfloat endJoinShift = dot(currNormal, endJoinDirection);\n\n\tfloat startMiterRatio = abs(1. / startJoinShift);\n\tfloat endMiterRatio = abs(1. / endJoinShift);\n\n\tvec2 startJoin = startJoinDirection * startMiterRatio;\n\tvec2 endJoin = endJoinDirection * endMiterRatio;\n\n\tvec2 startTopJoin, startBotJoin, endTopJoin, endBotJoin;\n\tstartTopJoin = sign(startJoinShift) * startJoin * .5;\n\tstartBotJoin = -startTopJoin;\n\n\tendTopJoin = sign(endJoinShift) * endJoin * .5;\n\tendBotJoin = -endTopJoin;\n\n\tvec2 aTopCoord = aCoord + normalWidth * startTopJoin;\n\tvec2 bTopCoord = bCoord + normalWidth * endTopJoin;\n\tvec2 aBotCoord = aCoord + normalWidth * startBotJoin;\n\tvec2 bBotCoord = bCoord + normalWidth * endBotJoin;\n\n\t//miter anti-clipping\n\tfloat baClipping = distToLine(bCoord, aCoord, aBotCoord) / dot(normalize(normalWidth * endBotJoin), normalize(normalWidth.yx * vec2(-startBotJoin.y, startBotJoin.x)));\n\tfloat abClipping = distToLine(aCoord, bCoord, bTopCoord) / dot(normalize(normalWidth * startBotJoin), normalize(normalWidth.yx * vec2(-endBotJoin.y, endBotJoin.x)));\n\n\t//prevent close to reverse direction switch\n\tbool prevReverse = dot(currTangent, prevTangent) <= REVERSE_THRESHOLD && abs(dot(currTangent, prevNormal)) * min(length(prevDiff), length(currDiff)) <  length(normalWidth * currNormal);\n\tbool nextReverse = dot(currTangent, nextTangent) <= REVERSE_THRESHOLD && abs(dot(currTangent, nextNormal)) * min(length(nextDiff), length(currDiff)) <  length(normalWidth * currNormal);\n\n\tif (prevReverse) {\n\t\t//make join rectangular\n\t\tvec2 miterShift = normalWidth * startJoinDirection * miterLimit * .5;\n\t\tfloat normalAdjust = 1. - min(miterLimit / startMiterRatio, 1.);\n\t\taBotCoord = aCoord + miterShift - normalAdjust * normalWidth * currNormal * .5;\n\t\taTopCoord = aCoord + miterShift + normalAdjust * normalWidth * currNormal * .5;\n\t}\n\telse if (!nextReverse && baClipping > 0. && baClipping < length(normalWidth * endBotJoin)) {\n\t\t//handle miter clipping\n\t\tbTopCoord -= normalWidth * endTopJoin;\n\t\tbTopCoord += normalize(endTopJoin * normalWidth) * baClipping;\n\t}\n\n\tif (nextReverse) {\n\t\t//make join rectangular\n\t\tvec2 miterShift = normalWidth * endJoinDirection * miterLimit * .5;\n\t\tfloat normalAdjust = 1. - min(miterLimit / endMiterRatio, 1.);\n\t\tbBotCoord = bCoord + miterShift - normalAdjust * normalWidth * currNormal * .5;\n\t\tbTopCoord = bCoord + miterShift + normalAdjust * normalWidth * currNormal * .5;\n\t}\n\telse if (!prevReverse && abClipping > 0. && abClipping < length(normalWidth * startBotJoin)) {\n\t\t//handle miter clipping\n\t\taBotCoord -= normalWidth * startBotJoin;\n\t\taBotCoord += normalize(startBotJoin * normalWidth) * abClipping;\n\t}\n\n\tvec2 aTopPosition = (aTopCoord) * adjustedScale + translate;\n\tvec2 aBotPosition = (aBotCoord) * adjustedScale + translate;\n\n\tvec2 bTopPosition = (bTopCoord) * adjustedScale + translate;\n\tvec2 bBotPosition = (bBotCoord) * adjustedScale + translate;\n\n\t//position is normalized 0..1 coord on the screen\n\tvec2 position = (aTopPosition * lineTop + aBotPosition * lineBot) * lineStart + (bTopPosition * lineTop + bBotPosition * lineBot) * lineEnd;\n\n\tstartCoord = aCoord * scaleRatio + translate * viewport.zw + viewport.xy;\n\tendCoord = bCoord * scaleRatio + translate * viewport.zw + viewport.xy;\n\n\tgl_Position = vec4(position  * 2.0 - 1.0, depth, 1);\n\n\tenableStartMiter = step(dot(currTangent, prevTangent), .5);\n\tenableEndMiter = step(dot(currTangent, nextTangent), .5);\n\n\t//bevel miter cutoffs\n\tif (miterMode == 1.) {\n\t\tif (enableStartMiter == 1.) {\n\t\t\tvec2 startMiterWidth = vec2(startJoinDirection) * thickness * miterLimit * .5;\n\t\t\tstartCutoff = vec4(aCoord, aCoord);\n\t\t\tstartCutoff.zw += vec2(-startJoinDirection.y, startJoinDirection.x) / scaleRatio;\n\t\t\tstartCutoff = startCutoff * scaleRatio.xyxy + translate.xyxy * viewport.zwzw;\n\t\t\tstartCutoff += viewport.xyxy;\n\t\t\tstartCutoff += startMiterWidth.xyxy;\n\t\t}\n\n\t\tif (enableEndMiter == 1.) {\n\t\t\tvec2 endMiterWidth = vec2(endJoinDirection) * thickness * miterLimit * .5;\n\t\t\tendCutoff = vec4(bCoord, bCoord);\n\t\t\tendCutoff.zw += vec2(-endJoinDirection.y, endJoinDirection.x)  / scaleRatio;\n\t\t\tendCutoff = endCutoff * scaleRatio.xyxy + translate.xyxy * viewport.zwzw;\n\t\t\tendCutoff += viewport.xyxy;\n\t\t\tendCutoff += endMiterWidth.xyxy;\n\t\t}\n\t}\n\n\t//round miter cutoffs\n\telse if (miterMode == 2.) {\n\t\tif (enableStartMiter == 1.) {\n\t\t\tvec2 startMiterWidth = vec2(startJoinDirection) * thickness * abs(dot(startJoinDirection, currNormal)) * .5;\n\t\t\tstartCutoff = vec4(aCoord, aCoord);\n\t\t\tstartCutoff.zw += vec2(-startJoinDirection.y, startJoinDirection.x) / scaleRatio;\n\t\t\tstartCutoff = startCutoff * scaleRatio.xyxy + translate.xyxy * viewport.zwzw;\n\t\t\tstartCutoff += viewport.xyxy;\n\t\t\tstartCutoff += startMiterWidth.xyxy;\n\t\t}\n\n\t\tif (enableEndMiter == 1.) {\n\t\t\tvec2 endMiterWidth = vec2(endJoinDirection) * thickness * abs(dot(endJoinDirection, currNormal)) * .5;\n\t\t\tendCutoff = vec4(bCoord, bCoord);\n\t\t\tendCutoff.zw += vec2(-endJoinDirection.y, endJoinDirection.x)  / scaleRatio;\n\t\t\tendCutoff = endCutoff * scaleRatio.xyxy + translate.xyxy * viewport.zwzw;\n\t\t\tendCutoff += viewport.xyxy;\n\t\t\tendCutoff += endMiterWidth.xyxy;\n\t\t}\n\t}\n}\n"]),frag:o(["precision highp float;\n#define GLSLIFY 1\n\nuniform float dashLength, pixelRatio, thickness, opacity, id, miterMode;\nuniform sampler2D dashTexture;\n\nvarying vec4 fragColor;\nvarying vec2 tangent;\nvarying vec4 startCutoff, endCutoff;\nvarying vec2 startCoord, endCoord;\nvarying float enableStartMiter, enableEndMiter;\n\nfloat distToLine(vec2 p, vec2 a, vec2 b) {\n\tvec2 diff = b - a;\n\tvec2 perp = normalize(vec2(-diff.y, diff.x));\n\treturn dot(p - a, perp);\n}\n\nvoid main() {\n\tfloat alpha = 1., distToStart, distToEnd;\n\tfloat cutoff = thickness * .5;\n\n\t//bevel miter\n\tif (miterMode == 1.) {\n\t\tif (enableStartMiter == 1.) {\n\t\t\tdistToStart = distToLine(gl_FragCoord.xy, startCutoff.xy, startCutoff.zw);\n\t\t\tif (distToStart < -1.) {\n\t\t\t\tdiscard;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\talpha *= min(max(distToStart + 1., 0.), 1.);\n\t\t}\n\n\t\tif (enableEndMiter == 1.) {\n\t\t\tdistToEnd = distToLine(gl_FragCoord.xy, endCutoff.xy, endCutoff.zw);\n\t\t\tif (distToEnd < -1.) {\n\t\t\t\tdiscard;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\talpha *= min(max(distToEnd + 1., 0.), 1.);\n\t\t}\n\t}\n\n\t// round miter\n\telse if (miterMode == 2.) {\n\t\tif (enableStartMiter == 1.) {\n\t\t\tdistToStart = distToLine(gl_FragCoord.xy, startCutoff.xy, startCutoff.zw);\n\t\t\tif (distToStart < 0.) {\n\t\t\t\tfloat radius = length(gl_FragCoord.xy - startCoord);\n\n\t\t\t\tif(radius > cutoff + .5) {\n\t\t\t\t\tdiscard;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\talpha -= smoothstep(cutoff - .5, cutoff + .5, radius);\n\t\t\t}\n\t\t}\n\n\t\tif (enableEndMiter == 1.) {\n\t\t\tdistToEnd = distToLine(gl_FragCoord.xy, endCutoff.xy, endCutoff.zw);\n\t\t\tif (distToEnd < 0.) {\n\t\t\t\tfloat radius = length(gl_FragCoord.xy - endCoord);\n\n\t\t\t\tif(radius > cutoff + .5) {\n\t\t\t\t\tdiscard;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\talpha -= smoothstep(cutoff - .5, cutoff + .5, radius);\n\t\t\t}\n\t\t}\n\t}\n\n\tfloat t = fract(dot(tangent, gl_FragCoord.xy) / dashLength) * .5 + .25;\n\tfloat dash = texture2D(dashTexture, vec2(t, .5)).r;\n\n\tgl_FragColor = fragColor;\n\tgl_FragColor.a *= alpha * opacity * dash;\n}\n"]),attributes:{lineEnd:{buffer:r,divisor:0,stride:8,offset:0},lineTop:{buffer:r,divisor:0,stride:8,offset:4},aColor:{buffer:t.prop("colorBuffer"),stride:4,offset:0,divisor:1},bColor:{buffer:t.prop("colorBuffer"),stride:4,offset:4,divisor:1},prevCoord:{buffer:t.prop("positionBuffer"),stride:8,offset:0,divisor:1},aCoord:{buffer:t.prop("positionBuffer"),stride:8,offset:8,divisor:1},bCoord:{buffer:t.prop("positionBuffer"),stride:8,offset:16,divisor:1},nextCoord:{buffer:t.prop("positionBuffer"),stride:8,offset:24,divisor:1}}},n))}catch(t){e=i}return{fill:t({primitive:"triangle",elements:function(t,e){return e.triangles},offset:0,vert:o(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec2 position, positionFract;\n\nuniform vec4 color;\nuniform vec2 scale, scaleFract, translate, translateFract;\nuniform float pixelRatio, id;\nuniform vec4 viewport;\nuniform float opacity;\n\nvarying vec4 fragColor;\n\nconst float MAX_LINES = 256.;\n\nvoid main() {\n\tfloat depth = (MAX_LINES - 4. - id) / (MAX_LINES);\n\n\tvec2 position = position * scale + translate\n       + positionFract * scale + translateFract\n       + position * scaleFract\n       + positionFract * scaleFract;\n\n\tgl_Position = vec4(position * 2.0 - 1.0, depth, 1);\n\n\tfragColor = color / 255.;\n\tfragColor.a *= opacity;\n}\n"]),frag:o(["precision highp float;\n#define GLSLIFY 1\n\nvarying vec4 fragColor;\n\nvoid main() {\n\tgl_FragColor = fragColor;\n}\n"]),uniforms:{scale:t.prop("scale"),color:t.prop("fill"),scaleFract:t.prop("scaleFract"),translateFract:t.prop("translateFract"),translate:t.prop("translate"),opacity:t.prop("opacity"),pixelRatio:t.context("pixelRatio"),id:t.prop("id"),viewport:function(t,e){return[e.viewport.x,e.viewport.y,t.viewportWidth,t.viewportHeight]}},attributes:{position:{buffer:t.prop("positionBuffer"),stride:8,offset:8},positionFract:{buffer:t.prop("positionFractBuffer"),stride:8,offset:8}},blend:n.blend,depth:{enable:!1},scissor:n.scissor,stencil:n.stencil,viewport:n.viewport}),rect:i,miter:e}},v.defaults={dashes:null,join:"miter",miterLimit:1,thickness:10,cap:"square",color:"black",opacity:1,overlay:!1,viewport:null,range:null,close:!1,fill:null},v.prototype.render=function(){for(var t,e=[],r=arguments.length;r--;)e[r]=arguments[r];e.length&&(t=this).update.apply(t,e),this.draw()},v.prototype.draw=function(){for(var t=this,e=[],r=arguments.length;r--;)e[r]=arguments[r];return(e.length?e:this.passes).forEach((function(e,r){var n;if(e&&Array.isArray(e))return(n=t).draw.apply(n,e);"number"==typeof e&&(e=t.passes[e]),e&&e.count>1&&e.opacity&&(t.regl._refresh(),e.fill&&e.triangles&&e.triangles.length>2&&t.shaders.fill(e),e.thickness&&(e.scale[0]*e.viewport.width>v.precisionThreshold||e.scale[1]*e.viewport.height>v.precisionThreshold||"rect"===e.join||!e.join&&(e.thickness<=2||e.count>=v.maxPoints)?t.shaders.rect(e):t.shaders.miter(e)))})),this},v.prototype.update=function(t){var e=this;if(t){null!=t.length?"number"==typeof t[0]&&(t=[{positions:t}]):Array.isArray(t)||(t=[t]);var r=this.regl,o=this.gl;if(t.forEach((function(t,f){var d=e.passes[f];if(void 0!==t)if(null!==t){if("number"==typeof t[0]&&(t={positions:t}),t=s(t,{positions:"positions points data coords",thickness:"thickness lineWidth lineWidths line-width linewidth width stroke-width strokewidth strokeWidth",join:"lineJoin linejoin join type mode",miterLimit:"miterlimit miterLimit",dashes:"dash dashes dasharray dash-array dashArray",color:"color colour stroke colors colours stroke-color strokeColor",fill:"fill fill-color fillColor",opacity:"alpha opacity",overlay:"overlay crease overlap intersect",close:"closed close closed-path closePath",range:"range dataBox",viewport:"viewport viewBox",hole:"holes hole hollow",splitNull:"splitNull"}),d||(e.passes[f]=d={id:f,scale:null,scaleFract:null,translate:null,translateFract:null,count:0,hole:[],depth:0,dashLength:1,dashTexture:r.texture({channels:1,data:new Uint8Array([255]),width:1,height:1,mag:"linear",min:"linear"}),colorBuffer:r.buffer({usage:"dynamic",type:"uint8",data:new Uint8Array}),positionBuffer:r.buffer({usage:"dynamic",type:"float",data:new Uint8Array}),positionFractBuffer:r.buffer({usage:"dynamic",type:"float",data:new Uint8Array})},t=a({},v.defaults,t)),null!=t.thickness&&(d.thickness=parseFloat(t.thickness)),null!=t.opacity&&(d.opacity=parseFloat(t.opacity)),null!=t.miterLimit&&(d.miterLimit=parseFloat(t.miterLimit)),null!=t.overlay&&(d.overlay=!!t.overlay,f<v.maxLines&&(d.depth=2*(v.maxLines-1-f%v.maxLines)/v.maxLines-1)),null!=t.join&&(d.join=t.join),null!=t.hole&&(d.hole=t.hole),null!=t.fill&&(d.fill=t.fill?n(t.fill,"uint8"):null),null!=t.viewport&&(d.viewport=m(t.viewport)),d.viewport||(d.viewport=m([o.drawingBufferWidth,o.drawingBufferHeight])),null!=t.close&&(d.close=t.close),null===t.positions&&(t.positions=[]),t.positions){var y,x;if(t.positions.x&&t.positions.y){var b=t.positions.x,_=t.positions.y;x=d.count=Math.max(b.length,_.length),y=new Float64Array(2*x);for(var w=0;w<x;w++)y[2*w]=b[w],y[2*w+1]=_[w]}else y=l(t.positions,"float64"),x=d.count=Math.floor(y.length/2);var T=d.bounds=i(y,2);if(d.fill){for(var k=[],A={},M=0,S=0,E=0,L=d.count;S<L;S++){var C=y[2*S],P=y[2*S+1];isNaN(C)||isNaN(P)||null==C||null==P?(C=y[2*M],P=y[2*M+1],A[S]=M):M=S,k[E++]=C,k[E++]=P}if(t.splitNull){d.count-1 in A||(A[d.count]=d.count-1);var I=Object.keys(A).map(Number).sort((function(t,e){return t-e})),O=[],z=0,D=null!=d.hole?d.hole[0]:null;if(null!=D){var R=g(I,(function(t){return t>=D}));(I=I.slice(0,R)).push(D)}for(var F=function(t){var e=k.slice(2*z,2*I[t]).concat(D?k.slice(2*D):[]),r=(d.hole||[]).map((function(e){return e-D+(I[t]-z)})),n=c(e,r);n=n.map((function(e){return e+z+(e+z<I[t]?0:D-I[t])})),O.push.apply(O,n),z=I[t]+1},B=0;B<I.length;B++)F(B);for(var N=0,j=O.length;N<j;N++)null!=A[O[N]]&&(O[N]=A[O[N]]);d.triangles=O}else{for(var U=c(k,d.hole||[]),V=0,H=U.length;V<H;V++)null!=A[U[V]]&&(U[V]=A[U[V]]);d.triangles=U}}var q=new Float64Array(y);u(q,2,T);var G=new Float64Array(2*x+6);d.close?y[0]===y[2*x-2]&&y[1]===y[2*x-1]?(G[0]=q[2*x-4],G[1]=q[2*x-3]):(G[0]=q[2*x-2],G[1]=q[2*x-1]):(G[0]=q[0],G[1]=q[1]),G.set(q,2),d.close?y[0]===y[2*x-2]&&y[1]===y[2*x-1]?(G[2*x+2]=q[2],G[2*x+3]=q[3],d.count-=1):(G[2*x+2]=q[0],G[2*x+3]=q[1],G[2*x+4]=q[2],G[2*x+5]=q[3]):(G[2*x+2]=q[2*x-2],G[2*x+3]=q[2*x-1],G[2*x+4]=q[2*x-2],G[2*x+5]=q[2*x-1]);var Y=h(G);d.positionBuffer(Y);var W=p(G,Y);d.positionFractBuffer(W)}if(t.range?d.range=t.range:d.range||(d.range=d.bounds),(t.range||t.positions)&&d.count){var X=d.bounds,Z=X[2]-X[0],J=X[3]-X[1],K=d.range[2]-d.range[0],Q=d.range[3]-d.range[1];d.scale=[Z/K,J/Q],d.translate=[-d.range[0]/K+X[0]/K||0,-d.range[1]/Q+X[1]/Q||0],d.scaleFract=p(d.scale),d.translateFract=p(d.translate)}if(t.dashes){var $,tt=0;if(!t.dashes||t.dashes.length<2)tt=1,$=new Uint8Array([255,255,255,255,255,255,255,255]);else{tt=0;for(var et=0;et<t.dashes.length;++et)tt+=t.dashes[et];$=new Uint8Array(tt*v.dashMult);for(var rt=0,nt=255,it=0;it<2;it++)for(var at=0;at<t.dashes.length;++at){for(var ot=0,st=t.dashes[at]*v.dashMult*.5;ot<st;++ot)$[rt++]=nt;nt^=255}}d.dashLength=tt,d.dashTexture({channels:1,data:$,width:$.length,height:1,mag:"linear",min:"linear"},0,0)}if(t.color){var lt=d.count,ct=t.color;ct||(ct="transparent");var ut=new Uint8Array(4*lt+4);if(Array.isArray(ct)&&"number"!=typeof ct[0]){for(var ft=0;ft<lt;ft++){var ht=n(ct[ft],"uint8");ut.set(ht,4*ft)}ut.set(n(ct[0],"uint8"),4*lt)}else for(var pt=n(ct,"uint8"),dt=0;dt<lt+1;dt++)ut.set(pt,4*dt);d.colorBuffer({usage:"dynamic",type:"uint8",data:ut})}}else e.passes[f]=null})),t.length<this.passes.length){for(var f=t.length;f<this.passes.length;f++){var d=this.passes[f];d&&(d.colorBuffer.destroy(),d.positionBuffer.destroy(),d.dashTexture.destroy())}this.passes.length=t.length}for(var y=[],x=0;x<this.passes.length;x++)null!==this.passes[x]&&y.push(this.passes[x]);return this.passes=y,this}},v.prototype.destroy=function(){return this.passes.forEach((function(t){t.colorBuffer.destroy(),t.positionBuffer.destroy(),t.dashTexture.destroy()})),this.passes.length=0,this}},{"array-bounds":71,"array-find-index":72,"array-normalize":73,"color-normalize":89,earcut:129,"es6-weak-map":183,"flatten-vertex-data":191,glslify:227,"object-assign":247,"parse-rect":249,"pick-by-alias":253,"to-float32":313}],281:[function(t,e,r){"use strict";function n(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==r)return;var n,i,a=[],o=!0,s=!1;try{for(r=r.call(t);!(o=(n=r.next()).done)&&(a.push(n.value),!e||a.length!==e);o=!0);}catch(t){s=!0,i=t}finally{try{o||null==r.return||r.return()}finally{if(s)throw i}}return a}(t,e)||a(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||a(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var s=t("color-normalize"),l=t("array-bounds"),c=t("color-id"),u=t("@plotly/point-cluster"),f=t("object-assign"),h=t("glslify"),p=t("pick-by-alias"),d=t("update-diff"),m=t("flatten-vertex-data"),g=t("is-iexplorer"),v=t("to-float32"),y=t("parse-rect"),x=b;function b(t,e){var r=this;if(!(this instanceof b))return new b(t,e);"function"==typeof t?(e||(e={}),e.regl=t):(e=t,t=null),e&&e.length&&(e.positions=e);var n,i=(t=e.regl)._gl,a=[];this.tooManyColors=g,n=t.texture({data:new Uint8Array(1020),width:255,height:1,type:"uint8",format:"rgba",wrapS:"clamp",wrapT:"clamp",mag:"nearest",min:"nearest"}),f(this,{regl:t,gl:i,groups:[],markerCache:[null],markerTextures:[null],palette:a,paletteIds:{},paletteTexture:n,maxColors:255,maxSize:100,canvas:i.canvas}),this.update(e);var o={uniforms:{constPointSize:!!e.constPointSize,opacity:t.prop("opacity"),paletteSize:function(t,e){return[r.tooManyColors?0:255,n.height]},pixelRatio:t.context("pixelRatio"),scale:t.prop("scale"),scaleFract:t.prop("scaleFract"),translate:t.prop("translate"),translateFract:t.prop("translateFract"),markerTexture:t.prop("markerTexture"),paletteTexture:n},attributes:{x:function(t,e){return e.xAttr||{buffer:e.positionBuffer,stride:8,offset:0}},y:function(t,e){return e.yAttr||{buffer:e.positionBuffer,stride:8,offset:4}},xFract:function(t,e){return e.xAttr?{constant:[0,0]}:{buffer:e.positionFractBuffer,stride:8,offset:0}},yFract:function(t,e){return e.yAttr?{constant:[0,0]}:{buffer:e.positionFractBuffer,stride:8,offset:4}},size:function(t,e){return e.size.length?{buffer:e.sizeBuffer,stride:2,offset:0}:{constant:[Math.round(255*e.size/r.maxSize)]}},borderSize:function(t,e){return e.borderSize.length?{buffer:e.sizeBuffer,stride:2,offset:1}:{constant:[Math.round(255*e.borderSize/r.maxSize)]}},colorId:function(t,e){return e.color.length?{buffer:e.colorBuffer,stride:r.tooManyColors?8:4,offset:0}:{constant:r.tooManyColors?a.slice(4*e.color,4*e.color+4):[e.color]}},borderColorId:function(t,e){return e.borderColor.length?{buffer:e.colorBuffer,stride:r.tooManyColors?8:4,offset:r.tooManyColors?4:2}:{constant:r.tooManyColors?a.slice(4*e.borderColor,4*e.borderColor+4):[e.borderColor]}},isActive:function(t,e){return!0===e.activation?{constant:[1]}:e.activation?e.activation:{constant:[0]}}},blend:{enable:!0,color:[0,0,0,1],func:{srcRGB:"src alpha",dstRGB:"one minus src alpha",srcAlpha:"one minus dst alpha",dstAlpha:"one"}},scissor:{enable:!0,box:t.prop("viewport")},viewport:t.prop("viewport"),stencil:{enable:!1},depth:{enable:!1},elements:t.prop("elements"),count:t.prop("count"),offset:t.prop("offset"),primitive:"points"},s=f({},o);s.frag=h(["precision highp float;\n#define GLSLIFY 1\n\nuniform float opacity;\nuniform sampler2D markerTexture;\n\nvarying vec4 fragColor, fragBorderColor;\nvarying float fragWidth, fragBorderColorLevel, fragColorLevel;\n\nfloat smoothStep(float x, float y) {\n  return 1.0 / (1.0 + exp(50.0*(x - y)));\n}\n\nvoid main() {\n  float dist = texture2D(markerTexture, gl_PointCoord).r, delta = fragWidth;\n\n  // max-distance alpha\n  if (dist < 0.003) discard;\n\n  // null-border case\n  if (fragBorderColorLevel == fragColorLevel || fragBorderColor.a == 0.) {\n    float colorAmt = smoothstep(.5 - delta, .5 + delta, dist);\n    gl_FragColor = vec4(fragColor.rgb, colorAmt * fragColor.a * opacity);\n  }\n  else {\n    float borderColorAmt = smoothstep(fragBorderColorLevel - delta, fragBorderColorLevel + delta, dist);\n    float colorAmt = smoothstep(fragColorLevel - delta, fragColorLevel + delta, dist);\n\n    vec4 color = fragBorderColor;\n    color.a *= borderColorAmt;\n    color = mix(color, fragColor, colorAmt);\n    color.a *= opacity;\n\n    gl_FragColor = color;\n  }\n\n}\n"]),s.vert=h(["precision highp float;\n#define GLSLIFY 1\n\nattribute float x, y, xFract, yFract;\nattribute float size, borderSize;\nattribute vec4 colorId, borderColorId;\nattribute float isActive;\n\nuniform bool constPointSize;\nuniform float pixelRatio;\nuniform vec2 scale, scaleFract, translate, translateFract, paletteSize;\nuniform sampler2D paletteTexture;\n\nconst float maxSize = 100.;\nconst float borderLevel = .5;\n\nvarying vec4 fragColor, fragBorderColor;\nvarying float fragPointSize, fragBorderRadius, fragWidth, fragBorderColorLevel, fragColorLevel;\n\nfloat pointSizeScale = (constPointSize) ? 2. : pixelRatio;\n\nbool isDirect = (paletteSize.x < 1.);\n\nvec4 getColor(vec4 id) {\n  return isDirect ? id / 255. : texture2D(paletteTexture,\n    vec2(\n      (id.x + .5) / paletteSize.x,\n      (id.y + .5) / paletteSize.y\n    )\n  );\n}\n\nvoid main() {\n  // ignore inactive points\n  if (isActive == 0.) return;\n\n  vec2 position = vec2(x, y);\n  vec2 positionFract = vec2(xFract, yFract);\n\n  vec4 color = getColor(colorId);\n  vec4 borderColor = getColor(borderColorId);\n\n  float size = size * maxSize / 255.;\n  float borderSize = borderSize * maxSize / 255.;\n\n  gl_PointSize = 2. * size * pointSizeScale;\n  fragPointSize = size * pixelRatio;\n\n  vec2 pos = (position + translate) * scale\n      + (positionFract + translateFract) * scale\n      + (position + translate) * scaleFract\n      + (positionFract + translateFract) * scaleFract;\n\n  gl_Position = vec4(pos * 2. - 1., 0., 1.);\n\n  fragColor = color;\n  fragBorderColor = borderColor;\n  fragWidth = 1. / gl_PointSize;\n\n  fragBorderColorLevel = clamp(borderLevel - borderLevel * borderSize / size, 0., 1.);\n  fragColorLevel = clamp(borderLevel + (1. - borderLevel) * borderSize / size, 0., 1.);\n}"]),this.drawMarker=t(s);var l=f({},o);l.frag=h(["precision highp float;\n#define GLSLIFY 1\n\nvarying vec4 fragColor, fragBorderColor;\nvarying float fragBorderRadius, fragWidth;\n\nuniform float opacity;\n\nfloat smoothStep(float edge0, float edge1, float x) {\n\tfloat t;\n\tt = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);\n\treturn t * t * (3.0 - 2.0 * t);\n}\n\nvoid main() {\n\tfloat radius, alpha = 1.0, delta = fragWidth;\n\n\tradius = length(2.0 * gl_PointCoord.xy - 1.0);\n\n\tif (radius > 1.0 + delta) {\n\t\tdiscard;\n\t}\n\n\talpha -= smoothstep(1.0 - delta, 1.0 + delta, radius);\n\n\tfloat borderRadius = fragBorderRadius;\n\tfloat ratio = smoothstep(borderRadius - delta, borderRadius + delta, radius);\n\tvec4 color = mix(fragColor, fragBorderColor, ratio);\n\tcolor.a *= alpha * opacity;\n\tgl_FragColor = color;\n}\n"]),l.vert=h(["precision highp float;\n#define GLSLIFY 1\n\nattribute float x, y, xFract, yFract;\nattribute float size, borderSize;\nattribute vec4 colorId, borderColorId;\nattribute float isActive;\n\nuniform bool constPointSize;\nuniform float pixelRatio;\nuniform vec2 paletteSize, scale, scaleFract, translate, translateFract;\nuniform sampler2D paletteTexture;\n\nconst float maxSize = 100.;\n\nvarying vec4 fragColor, fragBorderColor;\nvarying float fragBorderRadius, fragWidth;\n\nfloat pointSizeScale = (constPointSize) ? 2. : pixelRatio;\n\nbool isDirect = (paletteSize.x < 1.);\n\nvec4 getColor(vec4 id) {\n  return isDirect ? id / 255. : texture2D(paletteTexture,\n    vec2(\n      (id.x + .5) / paletteSize.x,\n      (id.y + .5) / paletteSize.y\n    )\n  );\n}\n\nvoid main() {\n  // ignore inactive points\n  if (isActive == 0.) return;\n\n  vec2 position = vec2(x, y);\n  vec2 positionFract = vec2(xFract, yFract);\n\n  vec4 color = getColor(colorId);\n  vec4 borderColor = getColor(borderColorId);\n\n  float size = size * maxSize / 255.;\n  float borderSize = borderSize * maxSize / 255.;\n\n  gl_PointSize = (size + borderSize) * pointSizeScale;\n\n  vec2 pos = (position + translate) * scale\n      + (positionFract + translateFract) * scale\n      + (position + translate) * scaleFract\n      + (positionFract + translateFract) * scaleFract;\n\n  gl_Position = vec4(pos * 2. - 1., 0., 1.);\n\n  fragBorderRadius = 1. - 2. * borderSize / (size + borderSize);\n  fragColor = color;\n  fragBorderColor = borderColor.a == 0. || borderSize == 0. ? vec4(color.rgb, 0.) : borderColor;\n  fragWidth = 1. / gl_PointSize;\n}\n"]),g&&(l.frag=l.frag.replace("smoothstep","smoothStep"),s.frag=s.frag.replace("smoothstep","smoothStep")),this.drawCircle=t(l)}b.defaults={color:"black",borderColor:"transparent",borderSize:0,size:12,opacity:1,marker:void 0,viewport:null,range:null,pixelSize:null,count:0,offset:0,bounds:null,positions:[],snap:1e4},b.prototype.render=function(){return arguments.length&&this.update.apply(this,arguments),this.draw(),this},b.prototype.draw=function(){for(var t=this,e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];var i=this.groups;if(1===r.length&&Array.isArray(r[0])&&(null===r[0][0]||Array.isArray(r[0][0]))&&(r=r[0]),this.regl._refresh(),r.length)for(var a=0;a<r.length;a++)this.drawItem(a,r[a]);else i.forEach((function(e,r){t.drawItem(r)}));return this},b.prototype.drawItem=function(t,e){var r=this.groups,n=r[t];if("number"==typeof e&&(t=e,n=r[e],e=null),n&&n.count&&n.opacity){n.activation[0]&&this.drawCircle(this.getMarkerDrawOptions(0,n,e));for(var a=[],o=1;o<n.activation.length;o++)n.activation[o]&&(!0===n.activation[o]||n.activation[o].data.length)&&a.push.apply(a,i(this.getMarkerDrawOptions(o,n,e)));a.length&&this.drawMarker(a)}},b.prototype.getMarkerDrawOptions=function(t,e,r){var i=e.range,a=e.tree,o=e.viewport,s=e.activation,l=e.selectionBuffer,c=e.count;this.regl;if(!a)return r?[f({},e,{markerTexture:this.markerTextures[t],activation:s[t],count:r.length,elements:r,offset:0})]:[f({},e,{markerTexture:this.markerTextures[t],activation:s[t],offset:0})];var u=[],h=a.range(i,{lod:!0,px:[(i[2]-i[0])/o.width,(i[3]-i[1])/o.height]});if(r){for(var p=s[t].data,d=new Uint8Array(c),m=0;m<r.length;m++){var g=r[m];d[g]=p?p[g]:1}l.subdata(d)}for(var v=h.length;v--;){var y=n(h[v],2),x=y[0],b=y[1];u.push(f({},e,{markerTexture:this.markerTextures[t],activation:r?l:s[t],offset:x,count:b-x}))}return u},b.prototype.update=function(){for(var t=this,e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];if(r.length){1===r.length&&Array.isArray(r[0])&&(r=r[0]);var i=this.groups,a=this.gl,o=this.regl,s=this.maxSize,c=this.maxColors,h=this.palette;this.groups=i=r.map((function(e,r){var n=i[r];if(void 0===e)return n;null===e?e={positions:null}:"function"==typeof e?e={ondraw:e}:"number"==typeof e[0]&&(e={positions:e}),null===(e=p(e,{positions:"positions data points",snap:"snap cluster lod tree",size:"sizes size radius",borderSize:"borderSizes borderSize border-size bordersize borderWidth borderWidths border-width borderwidth stroke-width strokeWidth strokewidth outline",color:"colors color fill fill-color fillColor",borderColor:"borderColors borderColor stroke stroke-color strokeColor",marker:"markers marker shape",range:"range dataBox databox",viewport:"viewport viewPort viewBox viewbox",opacity:"opacity alpha transparency",bounds:"bound bounds boundaries limits",tooManyColors:"tooManyColors palette paletteMode optimizePalette enablePalette"})).positions&&(e.positions=[]),null!=e.tooManyColors&&(t.tooManyColors=e.tooManyColors),n||(i[r]=n={id:r,scale:null,translate:null,scaleFract:null,translateFract:null,activation:[],selectionBuffer:o.buffer({data:new Uint8Array(0),usage:"stream",type:"uint8"}),sizeBuffer:o.buffer({data:new Uint8Array(0),usage:"dynamic",type:"uint8"}),colorBuffer:o.buffer({data:new Uint8Array(0),usage:"dynamic",type:"uint8"}),positionBuffer:o.buffer({data:new Uint8Array(0),usage:"dynamic",type:"float"}),positionFractBuffer:o.buffer({data:new Uint8Array(0),usage:"dynamic",type:"float"})},e=f({},b.defaults,e)),e.positions&&!("marker"in e)&&(e.marker=n.marker,delete n.marker),e.marker&&!("positions"in e)&&(e.positions=n.positions,delete n.positions);var g=0,x=0;if(d(n,e,[{snap:!0,size:function(t,e){return null==t&&(t=b.defaults.size),g+=t&&t.length?1:0,t},borderSize:function(t,e){return null==t&&(t=b.defaults.borderSize),g+=t&&t.length?1:0,t},opacity:parseFloat,color:function(e,r){return null==e&&(e=b.defaults.color),e=t.updateColor(e),x++,e},borderColor:function(e,r){return null==e&&(e=b.defaults.borderColor),e=t.updateColor(e),x++,e},bounds:function(t,e,r){return"range"in r||(r.range=null),t},positions:function(t,e,r){var n=e.snap,i=e.positionBuffer,a=e.positionFractBuffer,s=e.selectionBuffer;if(t.x||t.y)return t.x.length?e.xAttr={buffer:o.buffer(t.x),offset:0,stride:4,count:t.x.length}:e.xAttr={buffer:t.x.buffer,offset:4*t.x.offset||0,stride:4*(t.x.stride||1),count:t.x.count},t.y.length?e.yAttr={buffer:o.buffer(t.y),offset:0,stride:4,count:t.y.length}:e.yAttr={buffer:t.y.buffer,offset:4*t.y.offset||0,stride:4*(t.y.stride||1),count:t.y.count},e.count=Math.max(e.xAttr.count,e.yAttr.count),t;t=m(t,"float64");var c=e.count=Math.floor(t.length/2),f=e.bounds=c?l(t,2):null;if(r.range||e.range||(delete e.range,r.range=f),r.marker||e.marker||(delete e.marker,r.marker=null),n&&(!0===n||c>n)?e.tree=u(t,{bounds:f}):n&&n.length&&(e.tree=n),e.tree){var h={primitive:"points",usage:"static",data:e.tree,type:"uint32"};e.elements?e.elements(h):e.elements=o.elements(h)}var p=v.float32(t);return i({data:p,usage:"dynamic"}),a({data:v.fract32(t,p),usage:"dynamic"}),s({data:new Uint8Array(c),type:"uint8",usage:"stream"}),t}},{marker:function(e,r,n){var i=r.activation;if(i.forEach((function(t){return t&&t.destroy&&t.destroy()})),i.length=0,e&&"number"!=typeof e[0]){for(var a=[],s=0,l=Math.min(e.length,r.count);s<l;s++){var c=t.addMarker(e[s]);a[c]||(a[c]=new Uint8Array(r.count)),a[c][s]=1}for(var u=0;u<a.length;u++)if(a[u]){var f={data:a[u],type:"uint8",usage:"static"};i[u]?i[u](f):i[u]=o.buffer(f),i[u].data=a[u]}}else{i[t.addMarker(e)]=!0}return e},range:function(t,e,r){var n=e.bounds;if(n)return t||(t=n),e.scale=[1/(t[2]-t[0]),1/(t[3]-t[1])],e.translate=[-t[0],-t[1]],e.scaleFract=v.fract(e.scale),e.translateFract=v.fract(e.translate),t},viewport:function(t){return y(t||[a.drawingBufferWidth,a.drawingBufferHeight])}}]),g){var _=n,w=_.count,T=_.size,k=_.borderSize,A=_.sizeBuffer,M=new Uint8Array(2*w);if(T.length||k.length)for(var S=0;S<w;S++)M[2*S]=Math.round(255*(null==T[S]?T:T[S])/s),M[2*S+1]=Math.round(255*(null==k[S]?k:k[S])/s);A({data:M,usage:"dynamic"})}if(x){var E,L=n,C=L.count,P=L.color,I=L.borderColor,O=L.colorBuffer;if(t.tooManyColors){if(P.length||I.length){E=new Uint8Array(8*C);for(var z=0;z<C;z++){var D=P[z];E[8*z]=h[4*D],E[8*z+1]=h[4*D+1],E[8*z+2]=h[4*D+2],E[8*z+3]=h[4*D+3];var R=I[z];E[8*z+4]=h[4*R],E[8*z+5]=h[4*R+1],E[8*z+6]=h[4*R+2],E[8*z+7]=h[4*R+3]}}}else if(P.length||I.length){E=new Uint8Array(4*C+2);for(var F=0;F<C;F++)null!=P[F]&&(E[4*F]=P[F]%c,E[4*F+1]=Math.floor(P[F]/c)),null!=I[F]&&(E[4*F+2]=I[F]%c,E[4*F+3]=Math.floor(I[F]/c))}O({data:E||new Uint8Array(0),type:"uint8",usage:"dynamic"})}return n}))}},b.prototype.addMarker=function(t){var e,r=this.markerTextures,n=this.regl,i=this.markerCache,a=null==t?0:i.indexOf(t);if(a>=0)return a;if(t instanceof Uint8Array||t instanceof Uint8ClampedArray)e=t;else{e=new Uint8Array(t.length);for(var o=0,s=t.length;o<s;o++)e[o]=255*t[o]}var l=Math.floor(Math.sqrt(e.length));return a=r.length,i.push(t),r.push(n.texture({channels:1,data:e,radius:l,mag:"linear",min:"linear"})),a},b.prototype.updateColor=function(t){var e=this.paletteIds,r=this.palette,n=this.maxColors;Array.isArray(t)||(t=[t]);var i=[];if("number"==typeof t[0]){var a=[];if(Array.isArray(t))for(var o=0;o<t.length;o+=4)a.push(t.slice(o,o+4));else for(var l=0;l<t.length;l+=4)a.push(t.subarray(l,l+4));t=a}for(var u=0;u<t.length;u++){var f=t[u];f=s(f,"uint8");var h=c(f,!1);if(null==e[h]){var p=r.length;e[h]=Math.floor(p/4),r[p]=f[0],r[p+1]=f[1],r[p+2]=f[2],r[p+3]=f[3]}i[u]=e[h]}return!this.tooManyColors&&r.length>4*n&&(this.tooManyColors=!0),this.updatePalette(r),1===i.length?i[0]:i},b.prototype.updatePalette=function(t){if(!this.tooManyColors){var e=this.maxColors,r=this.paletteTexture,n=Math.ceil(.25*t.length/e);if(n>1)for(var i=.25*(t=t.slice()).length%e;i<n*e;i++)t.push(0,0,0,0);r.height<n&&r.resize(e,n),r.subimage({width:Math.min(.25*t.length,e),height:n,data:t},0,0)}},b.prototype.destroy=function(){return this.groups.forEach((function(t){t.sizeBuffer.destroy(),t.positionBuffer.destroy(),t.positionFractBuffer.destroy(),t.colorBuffer.destroy(),t.activation.forEach((function(t){return t&&t.destroy&&t.destroy()})),t.selectionBuffer.destroy(),t.elements&&t.elements.destroy()})),this.groups.length=0,this.paletteTexture.destroy(),this.markerTextures.forEach((function(t){return t&&t.destroy&&t.destroy()})),this};var _=t("object-assign");e.exports=function(t,e){var r=new x(t,e),n=r.render.bind(r);return _(n,{render:n,update:r.update.bind(r),draw:r.draw.bind(r),destroy:r.destroy.bind(r),regl:r.regl,gl:r.gl,canvas:r.gl.canvas,groups:r.groups,markers:r.markerCache,palette:r.palette}),n}},{"@plotly/point-cluster":59,"array-bounds":71,"color-id":87,"color-normalize":89,"flatten-vertex-data":191,glslify:227,"is-iexplorer":233,"object-assign":247,"parse-rect":249,"pick-by-alias":253,"to-float32":313,"update-diff":329}],282:[function(t,e,r){"use strict";var n=t("regl-scatter2d"),i=t("pick-by-alias"),a=t("array-bounds"),o=t("raf"),s=t("array-range"),l=t("parse-rect"),c=t("flatten-vertex-data");function u(t,e){if(!(this instanceof u))return new u(t,e);this.traces=[],this.passes={},this.regl=t,this.scatter=n(t),this.canvas=this.scatter.canvas}function f(t,e,r){return(null!=t.id?t.id:t)<<16|(255&e)<<8|255&r}function h(t,e,r){var n,i,a,o,s=t[e],l=t[r];return s.length>2?(s[0],s[2],n=s[1],i=s[3]):s.length?(n=s[0],i=s[1]):(s.x,n=s.y,s.x+s.width,i=s.y+s.height),l.length>2?(a=l[0],o=l[2],l[1],l[3]):l.length?(a=l[0],o=l[1]):(a=l.x,l.y,o=l.x+l.width,l.y+l.height),[a,n,o,i]}function p(t){if("number"==typeof t)return[t,t,t,t];if(2===t.length)return[t[0],t[1],t[0],t[1]];var e=l(t);return[e.x,e.y,e.x+e.width,e.y+e.height]}e.exports=u,u.prototype.render=function(){for(var t,e=this,r=[],n=arguments.length;n--;)r[n]=arguments[n];return r.length&&(t=this).update.apply(t,r),this.regl.attributes.preserveDrawingBuffer?this.draw():(this.dirty?null==this.planned&&(this.planned=o((function(){e.draw(),e.dirty=!0,e.planned=null}))):(this.draw(),this.dirty=!0,o((function(){e.dirty=!1}))),this)},u.prototype.update=function(){for(var t,e=[],r=arguments.length;r--;)e[r]=arguments[r];if(e.length){for(var n=0;n<e.length;n++)this.updateItem(n,e[n]);this.traces=this.traces.filter(Boolean);for(var i=[],a=0,o=0;o<this.traces.length;o++){for(var s=this.traces[o],l=this.traces[o].passes,c=0;c<l.length;c++)i.push(this.passes[l[c]]);s.passOffset=a,a+=s.passes.length}return(t=this.scatter).update.apply(t,i),this}},u.prototype.updateItem=function(t,e){var r=this.regl;if(null===e)return this.traces[t]=null,this;if(!e)return this;var n,o=i(e,{data:"data items columns rows values dimensions samples x",snap:"snap cluster",size:"sizes size radius",color:"colors color fill fill-color fillColor",opacity:"opacity alpha transparency opaque",borderSize:"borderSizes borderSize border-size bordersize borderWidth borderWidths border-width borderwidth stroke-width strokeWidth strokewidth outline",borderColor:"borderColors borderColor bordercolor stroke stroke-color strokeColor",marker:"markers marker shape",range:"range ranges databox dataBox",viewport:"viewport viewBox viewbox",domain:"domain domains area areas",padding:"pad padding paddings pads margin margins",transpose:"transpose transposed",diagonal:"diagonal diag showDiagonal",upper:"upper up top upperhalf upperHalf showupperhalf showUpper showUpperHalf",lower:"lower low bottom lowerhalf lowerHalf showlowerhalf showLowerHalf showLower"}),s=this.traces[t]||(this.traces[t]={id:t,buffer:r.buffer({usage:"dynamic",type:"float",data:new Uint8Array}),color:"black",marker:null,size:12,borderColor:"transparent",borderSize:1,viewport:l([r._gl.drawingBufferWidth,r._gl.drawingBufferHeight]),padding:[0,0,0,0],opacity:1,diagonal:!0,upper:!0,lower:!0});if(null!=o.color&&(s.color=o.color),null!=o.size&&(s.size=o.size),null!=o.marker&&(s.marker=o.marker),null!=o.borderColor&&(s.borderColor=o.borderColor),null!=o.borderSize&&(s.borderSize=o.borderSize),null!=o.opacity&&(s.opacity=o.opacity),o.viewport&&(s.viewport=l(o.viewport)),null!=o.diagonal&&(s.diagonal=o.diagonal),null!=o.upper&&(s.upper=o.upper),null!=o.lower&&(s.lower=o.lower),o.data){s.buffer(c(o.data)),s.columns=o.data.length,s.count=o.data[0].length,s.bounds=[];for(var u=0;u<s.columns;u++)s.bounds[u]=a(o.data[u],1)}o.range&&(s.range=o.range,n=s.range&&"number"!=typeof s.range[0]),o.domain&&(s.domain=o.domain);var d=!1;null!=o.padding&&(Array.isArray(o.padding)&&o.padding.length===s.columns&&"number"==typeof o.padding[o.padding.length-1]?(s.padding=o.padding.map(p),d=!0):s.padding=p(o.padding));var m=s.columns,g=s.count,v=s.viewport.width,y=s.viewport.height,x=s.viewport.x,b=s.viewport.y,_=v/m,w=y/m;s.passes=[];for(var T=0;T<m;T++)for(var k=0;k<m;k++)if((s.diagonal||k!==T)&&(s.upper||!(T>k))&&(s.lower||!(T<k))){var A=f(s.id,T,k),M=this.passes[A]||(this.passes[A]={});if(o.data&&(o.transpose?M.positions={x:{buffer:s.buffer,offset:k,count:g,stride:m},y:{buffer:s.buffer,offset:T,count:g,stride:m}}:M.positions={x:{buffer:s.buffer,offset:k*g,count:g},y:{buffer:s.buffer,offset:T*g,count:g}},M.bounds=h(s.bounds,T,k)),o.domain||o.viewport||o.data){var S=d?h(s.padding,T,k):s.padding;if(s.domain){var E=h(s.domain,T,k),L=E[0],C=E[1],P=E[2],I=E[3];M.viewport=[x+L*v+S[0],b+C*y+S[1],x+P*v-S[2],b+I*y-S[3]]}else M.viewport=[x+k*_+_*S[0],b+T*w+w*S[1],x+(k+1)*_-_*S[2],b+(T+1)*w-w*S[3]]}o.color&&(M.color=s.color),o.size&&(M.size=s.size),o.marker&&(M.marker=s.marker),o.borderSize&&(M.borderSize=s.borderSize),o.borderColor&&(M.borderColor=s.borderColor),o.opacity&&(M.opacity=s.opacity),o.range&&(M.range=n?h(s.range,T,k):s.range||M.bounds),s.passes.push(A)}return this},u.prototype.draw=function(){for(var t,e=[],r=arguments.length;r--;)e[r]=arguments[r];if(e.length){for(var n=[],i=0;i<e.length;i++)if("number"==typeof e[i]){var a=this.traces[e[i]],o=a.passes,l=a.passOffset;n.push.apply(n,s(l,l+o.length))}else if(e[i].length){var c=e[i],u=this.traces[i],f=u.passes,h=u.passOffset;f=f.map((function(t,e){n[h+e]=c}))}(t=this.scatter).draw.apply(t,n)}else this.scatter.draw();return this},u.prototype.destroy=function(){return this.traces.forEach((function(t){t.buffer&&t.buffer.destroy&&t.buffer.destroy()})),this.traces=null,this.passes=null,this.scatter.destroy(),this}},{"array-bounds":71,"array-range":74,"flatten-vertex-data":191,"parse-rect":249,"pick-by-alias":253,raf:278,"regl-scatter2d":281}],283:[function(t,e,r){!function(t,n){"object"==typeof r&&void 0!==e?e.exports=n():t.createREGL=n()}(this,(function(){function t(t,e){this.id=q++,this.type=t,this.data=e}function e(t){return"["+function t(e){if(0===e.length)return[];var r=e.charAt(0),n=e.charAt(e.length-1);if(1<e.length&&r===n&&('"'===r||"'"===r))return['"'+e.substr(1,e.length-2).replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'];if(r=/\[(false|true|null|\d+|'[^']*'|"[^"]*")\]/.exec(e))return t(e.substr(0,r.index)).concat(t(r[1])).concat(t(e.substr(r.index+r[0].length)));if(1===(r=e.split(".")).length)return['"'+e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'];for(e=[],n=0;n<r.length;++n)e=e.concat(t(r[n]));return e}(t).join("][")+"]"}function r(t){return"string"==typeof t?t.split():t}function n(t){return"string"==typeof t?document.querySelector(t):t}function i(t){var e,i,a,o,s=t||{};t={};var l=[],c=[],u="undefined"==typeof window?1:window.devicePixelRatio,f=!1,h={},p=function(t){},d=function(){};if("string"==typeof s?e=document.querySelector(s):"object"==typeof s&&("string"==typeof s.nodeName&&"function"==typeof s.appendChild&&"function"==typeof s.getBoundingClientRect?e=s:"function"==typeof s.drawArrays||"function"==typeof s.drawElements?a=(o=s).canvas:("gl"in s?o=s.gl:"canvas"in s?a=n(s.canvas):"container"in s&&(i=n(s.container)),"attributes"in s&&(t=s.attributes),"extensions"in s&&(l=r(s.extensions)),"optionalExtensions"in s&&(c=r(s.optionalExtensions)),"onDone"in s&&(p=s.onDone),"profile"in s&&(f=!!s.profile),"pixelRatio"in s&&(u=+s.pixelRatio),"cachedCode"in s&&(h=s.cachedCode))),e&&("canvas"===e.nodeName.toLowerCase()?a=e:i=e),!o){if(!a){if(!(e=function(t,e,r){function n(){var e=window.innerWidth,n=window.innerHeight;t!==document.body&&(e=(n=a.getBoundingClientRect()).right-n.left,n=n.bottom-n.top),a.width=r*e,a.height=r*n}var i,a=document.createElement("canvas");return H(a.style,{border:0,margin:0,padding:0,top:0,left:0,width:"100%",height:"100%"}),t.appendChild(a),t===document.body&&(a.style.position="absolute",H(t.style,{margin:0,padding:0})),t!==document.body&&"function"==typeof ResizeObserver?(i=new ResizeObserver((function(){setTimeout(n)}))).observe(t):window.addEventListener("resize",n,!1),n(),{canvas:a,onDestroy:function(){i?i.disconnect():window.removeEventListener("resize",n),t.removeChild(a)}}}(i||document.body,0,u)))return null;a=e.canvas,d=e.onDestroy}void 0===t.premultipliedAlpha&&(t.premultipliedAlpha=!0),o=function(t,e){function r(r){try{return t.getContext(r,e)}catch(t){return null}}return r("webgl")||r("experimental-webgl")||r("webgl-experimental")}(a,t)}return o?{gl:o,canvas:a,container:i,extensions:l,optionalExtensions:c,pixelRatio:u,profile:f,cachedCode:h,onDone:p,onDestroy:d}:(d(),p("webgl not supported, try upgrading your browser or graphics drivers http://get.webgl.org"),null)}function a(t,e){for(var r=Array(t),n=0;n<t;++n)r[n]=e(n);return r}function o(t){var e,r;return e=(65535<t)<<4,e|=r=(255<(t>>>=e))<<3,(e|=r=(15<(t>>>=r))<<2)|(r=(3<(t>>>=r))<<1)|t>>>r>>1}function s(){function t(t){t:{for(var e=16;268435456>=e;e*=16)if(t<=e){t=e;break t}t=0}return 0<(e=r[o(t)>>2]).length?e.pop():new ArrayBuffer(t)}function e(t){r[o(t.byteLength)>>2].push(t)}var r=a(8,(function(){return[]}));return{alloc:t,free:e,allocType:function(e,r){var n=null;switch(e){case 5120:n=new Int8Array(t(r),0,r);break;case 5121:n=new Uint8Array(t(r),0,r);break;case 5122:n=new Int16Array(t(2*r),0,r);break;case 5123:n=new Uint16Array(t(2*r),0,r);break;case 5124:n=new Int32Array(t(4*r),0,r);break;case 5125:n=new Uint32Array(t(4*r),0,r);break;case 5126:n=new Float32Array(t(4*r),0,r);break;default:return null}return n.length!==r?n.subarray(0,r):n},freeType:function(t){e(t.buffer)}}}function l(t){return!!t&&"object"==typeof t&&Array.isArray(t.shape)&&Array.isArray(t.stride)&&"number"==typeof t.offset&&t.shape.length===t.stride.length&&(Array.isArray(t.data)||J(t.data))}function c(t,e,r,n,i,a){for(var o=0;o<e;++o)for(var s=t[o],l=0;l<r;++l)for(var c=s[l],u=0;u<n;++u)i[a++]=c[u]}function u(t){return 0|$[Object.prototype.toString.call(t)]}function f(t,e){for(var r=0;r<e.length;++r)t[r]=e[r]}function h(t,e,r,n,i,a,o){for(var s=0,l=0;l<r;++l)for(var c=0;c<n;++c)t[s++]=e[i*l+a*c+o]}function p(t,e,r,n){function i(e){this.id=c++,this.buffer=t.createBuffer(),this.type=e,this.usage=35044,this.byteLength=0,this.dimension=1,this.dtype=5121,this.persistentData=null,r.profile&&(this.stats={size:0})}function a(e,r,n){e.byteLength=r.byteLength,t.bufferData(e.type,r,n)}function o(t,e,r,n,i,o){if(t.usage=r,Array.isArray(e)){if(t.dtype=n||5126,0<e.length)if(Array.isArray(e[0])){i=nt(e);for(var s=n=1;s<i.length;++s)n*=i[s];t.dimension=n,a(t,e=rt(e,i,t.dtype),r),o?t.persistentData=e:X.freeType(e)}else"number"==typeof e[0]?(t.dimension=i,f(i=X.allocType(t.dtype,e.length),e),a(t,i,r),o?t.persistentData=i:X.freeType(i)):J(e[0])&&(t.dimension=e[0].length,t.dtype=n||u(e[0])||5126,a(t,e=rt(e,[e.length,e[0].length],t.dtype),r),o?t.persistentData=e:X.freeType(e))}else if(J(e))t.dtype=n||u(e),t.dimension=i,a(t,e,r),o&&(t.persistentData=new Uint8Array(new Uint8Array(e.buffer)));else if(l(e)){i=e.shape;var c=e.stride,p=(s=e.offset,0),d=0,m=0,g=0;1===i.length?(p=i[0],d=1,m=c[0],g=0):2===i.length&&(p=i[0],d=i[1],m=c[0],g=c[1]),t.dtype=n||u(e.data)||5126,t.dimension=d,h(i=X.allocType(t.dtype,p*d),e.data,p,d,m,g,s),a(t,i,r),o?t.persistentData=i:X.freeType(i)}else e instanceof ArrayBuffer&&(t.dtype=5121,t.dimension=i,a(t,e,r),o&&(t.persistentData=new Uint8Array(new Uint8Array(e))))}function s(r){e.bufferCount--,n(r),t.deleteBuffer(r.buffer),r.buffer=null,delete p[r.id]}var c=0,p={};i.prototype.bind=function(){t.bindBuffer(this.type,this.buffer)},i.prototype.destroy=function(){s(this)};var d=[];return r.profile&&(e.getTotalBufferSize=function(){var t=0;return Object.keys(p).forEach((function(e){t+=p[e].stats.size})),t}),{create:function(n,a,c,d){function m(e){var n=35044,i=null,a=0,s=0,c=1;return Array.isArray(e)||J(e)||l(e)||e instanceof ArrayBuffer?i=e:"number"==typeof e?a=0|e:e&&("data"in e&&(i=e.data),"usage"in e&&(n=et[e.usage]),"type"in e&&(s=tt[e.type]),"dimension"in e&&(c=0|e.dimension),"length"in e&&(a=0|e.length)),g.bind(),i?o(g,i,n,s,c,d):(a&&t.bufferData(g.type,a,n),g.dtype=s||5121,g.usage=n,g.dimension=c,g.byteLength=a),r.profile&&(g.stats.size=g.byteLength*it[g.dtype]),m}e.bufferCount++;var g=new i(a);return p[g.id]=g,c||m(n),m._reglType="buffer",m._buffer=g,m.subdata=function(e,r){var n,i=0|(r||0);if(g.bind(),J(e)||e instanceof ArrayBuffer)t.bufferSubData(g.type,i,e);else if(Array.isArray(e)){if(0<e.length)if("number"==typeof e[0]){var a=X.allocType(g.dtype,e.length);f(a,e),t.bufferSubData(g.type,i,a),X.freeType(a)}else(Array.isArray(e[0])||J(e[0]))&&(n=nt(e),a=rt(e,n,g.dtype),t.bufferSubData(g.type,i,a),X.freeType(a))}else if(l(e)){n=e.shape;var o=e.stride,s=a=0,c=0,p=0;1===n.length?(a=n[0],s=1,c=o[0],p=0):2===n.length&&(a=n[0],s=n[1],c=o[0],p=o[1]),n=Array.isArray(e.data)?g.dtype:u(e.data),h(n=X.allocType(n,a*s),e.data,a,s,c,p,e.offset),t.bufferSubData(g.type,i,n),X.freeType(n)}return m},r.profile&&(m.stats=g.stats),m.destroy=function(){s(g)},m},createStream:function(t,e){var r=d.pop();return r||(r=new i(t)),r.bind(),o(r,e,35040,0,1,!1),r},destroyStream:function(t){d.push(t)},clear:function(){K(p).forEach(s),d.forEach(s)},getBuffer:function(t){return t&&t._buffer instanceof i?t._buffer:null},restore:function(){K(p).forEach((function(e){e.buffer=t.createBuffer(),t.bindBuffer(e.type,e.buffer),t.bufferData(e.type,e.persistentData||e.byteLength,e.usage)}))},_initBuffer:o}}function d(t,e,r,n){function i(t){this.id=c++,s[this.id]=this,this.buffer=t,this.primType=4,this.type=this.vertCount=0}function a(n,i,a,o,s,c,u){var f;if(n.buffer.bind(),i?((f=u)||J(i)&&(!l(i)||J(i.data))||(f=e.oes_element_index_uint?5125:5123),r._initBuffer(n.buffer,i,a,f,3)):(t.bufferData(34963,c,a),n.buffer.dtype=f||5121,n.buffer.usage=a,n.buffer.dimension=3,n.buffer.byteLength=c),f=u,!u){switch(n.buffer.dtype){case 5121:case 5120:f=5121;break;case 5123:case 5122:f=5123;break;case 5125:case 5124:f=5125}n.buffer.dtype=f}n.type=f,0>(i=s)&&(i=n.buffer.byteLength,5123===f?i>>=1:5125===f&&(i>>=2)),n.vertCount=i,i=o,0>o&&(i=4,1===(o=n.buffer.dimension)&&(i=0),2===o&&(i=1),3===o&&(i=4)),n.primType=i}function o(t){n.elementsCount--,delete s[t.id],t.buffer.destroy(),t.buffer=null}var s={},c=0,u={uint8:5121,uint16:5123};e.oes_element_index_uint&&(u.uint32=5125),i.prototype.bind=function(){this.buffer.bind()};var f=[];return{create:function(t,e){function s(t){if(t)if("number"==typeof t)c(t),f.primType=4,f.vertCount=0|t,f.type=5121;else{var e=null,r=35044,n=-1,i=-1,o=0,h=0;Array.isArray(t)||J(t)||l(t)?e=t:("data"in t&&(e=t.data),"usage"in t&&(r=et[t.usage]),"primitive"in t&&(n=at[t.primitive]),"count"in t&&(i=0|t.count),"type"in t&&(h=u[t.type]),"length"in t?o=0|t.length:(o=i,5123===h||5122===h?o*=2:5125!==h&&5124!==h||(o*=4))),a(f,e,r,n,i,o,h)}else c(),f.primType=4,f.vertCount=0,f.type=5121;return s}var c=r.create(null,34963,!0),f=new i(c._buffer);return n.elementsCount++,s(t),s._reglType="elements",s._elements=f,s.subdata=function(t,e){return c.subdata(t,e),s},s.destroy=function(){o(f)},s},createStream:function(t){var e=f.pop();return e||(e=new i(r.create(null,34963,!0,!1)._buffer)),a(e,t,35040,-1,-1,0,0),e},destroyStream:function(t){f.push(t)},getElements:function(t){return"function"==typeof t&&t._elements instanceof i?t._elements:null},clear:function(){K(s).forEach(o)}}}function m(t){for(var e=X.allocType(5123,t.length),r=0;r<t.length;++r)if(isNaN(t[r]))e[r]=65535;else if(1/0===t[r])e[r]=31744;else if(-1/0===t[r])e[r]=64512;else{ot[0]=t[r];var n=(a=st[0])>>>31<<15,i=(a<<1>>>24)-127,a=a>>13&1023;e[r]=-24>i?n:-14>i?n+(a+1024>>-14-i):15<i?n+31744:n+(i+15<<10)+a}return e}function g(t){return Array.isArray(t)||J(t)}function v(t){return"[object "+t+"]"}function y(t){return Array.isArray(t)&&(0===t.length||"number"==typeof t[0])}function x(t){return!(!Array.isArray(t)||0===t.length||!g(t[0]))}function b(t){return Object.prototype.toString.call(t)}function _(t){if(!t)return!1;var e=b(t);return 0<=vt.indexOf(e)||(y(t)||x(t)||l(t))}function w(t,e){36193===t.type?(t.data=m(e),X.freeType(e)):t.data=e}function T(t,e,r,n,i,a){if(t=void 0!==xt[t]?xt[t]:ut[t]*yt[e],a&&(t*=6),i){for(n=0;1<=r;)n+=t*r*r,r/=2;return n}return t*r*n}function k(t,e,r,n,i,a,o){function s(){this.format=this.internalformat=6408,this.type=5121,this.flipY=this.premultiplyAlpha=this.compressed=!1,this.unpackAlignment=1,this.colorSpace=37444,this.channels=this.height=this.width=0}function c(t,e){t.internalformat=e.internalformat,t.format=e.format,t.type=e.type,t.compressed=e.compressed,t.premultiplyAlpha=e.premultiplyAlpha,t.flipY=e.flipY,t.unpackAlignment=e.unpackAlignment,t.colorSpace=e.colorSpace,t.width=e.width,t.height=e.height,t.channels=e.channels}function u(t,e){if("object"==typeof e&&e){"premultiplyAlpha"in e&&(t.premultiplyAlpha=e.premultiplyAlpha),"flipY"in e&&(t.flipY=e.flipY),"alignment"in e&&(t.unpackAlignment=e.alignment),"colorSpace"in e&&(t.colorSpace=V[e.colorSpace]),"type"in e&&(t.type=q[e.type]);var r=t.width,n=t.height,i=t.channels,a=!1;"shape"in e?(r=e.shape[0],n=e.shape[1],3===e.shape.length&&(i=e.shape[2],a=!0)):("radius"in e&&(r=n=e.radius),"width"in e&&(r=e.width),"height"in e&&(n=e.height),"channels"in e&&(i=e.channels,a=!0)),t.width=0|r,t.height=0|n,t.channels=0|i,r=!1,"format"in e&&(r=e.format,n=t.internalformat=G[r],t.format=at[n],r in q&&!("type"in e)&&(t.type=q[r]),r in Y&&(t.compressed=!0),r=!0),!a&&r?t.channels=ut[t.format]:a&&!r&&t.channels!==ct[t.format]&&(t.format=t.internalformat=ct[t.channels])}}function f(e){t.pixelStorei(37440,e.flipY),t.pixelStorei(37441,e.premultiplyAlpha),t.pixelStorei(37443,e.colorSpace),t.pixelStorei(3317,e.unpackAlignment)}function h(){s.call(this),this.yOffset=this.xOffset=0,this.data=null,this.needsFree=!1,this.element=null,this.needsCopy=!1}function p(t,e){var r=null;if(_(e)?r=e:e&&(u(t,e),"x"in e&&(t.xOffset=0|e.x),"y"in e&&(t.yOffset=0|e.y),_(e.data)&&(r=e.data)),e.copy){var n=i.viewportWidth,a=i.viewportHeight;t.width=t.width||n-t.xOffset,t.height=t.height||a-t.yOffset,t.needsCopy=!0}else if(r){if(J(r))t.channels=t.channels||4,t.data=r,"type"in e||5121!==t.type||(t.type=0|$[Object.prototype.toString.call(r)]);else if(y(r)){switch(t.channels=t.channels||4,a=(n=r).length,t.type){case 5121:case 5123:case 5125:case 5126:(a=X.allocType(t.type,a)).set(n),t.data=a;break;case 36193:t.data=m(n)}t.alignment=1,t.needsFree=!0}else if(l(r)){n=r.data,Array.isArray(n)||5121!==t.type||(t.type=0|$[Object.prototype.toString.call(n)]);a=r.shape;var o,s,c,f,h=r.stride;3===a.length?(c=a[2],f=h[2]):f=c=1,o=a[0],s=a[1],a=h[0],h=h[1],t.alignment=1,t.width=o,t.height=s,t.channels=c,t.format=t.internalformat=ct[c],t.needsFree=!0,o=f,r=r.offset,c=t.width,f=t.height,s=t.channels;for(var p=X.allocType(36193===t.type?5126:t.type,c*f*s),d=0,v=0;v<f;++v)for(var T=0;T<c;++T)for(var k=0;k<s;++k)p[d++]=n[a*T+h*v+o*k+r];w(t,p)}else if(b(r)===ft||b(r)===ht||b(r)===pt)b(r)===ft||b(r)===ht?t.element=r:t.element=r.canvas,t.width=t.element.width,t.height=t.element.height,t.channels=4;else if(b(r)===dt)t.element=r,t.width=r.width,t.height=r.height,t.channels=4;else if(b(r)===mt)t.element=r,t.width=r.naturalWidth,t.height=r.naturalHeight,t.channels=4;else if(b(r)===gt)t.element=r,t.width=r.videoWidth,t.height=r.videoHeight,t.channels=4;else if(x(r)){for(n=t.width||r[0].length,a=t.height||r.length,h=t.channels,h=g(r[0][0])?h||r[0][0].length:h||1,o=Q.shape(r),c=1,f=0;f<o.length;++f)c*=o[f];c=X.allocType(36193===t.type?5126:t.type,c),Q.flatten(r,o,"",c),w(t,c),t.alignment=1,t.width=n,t.height=a,t.channels=h,t.format=t.internalformat=ct[h],t.needsFree=!0}}else t.width=t.width||1,t.height=t.height||1,t.channels=t.channels||4}function d(e,r,i,a,o){var s=e.element,l=e.data,c=e.internalformat,u=e.format,h=e.type,p=e.width,d=e.height;f(e),s?t.texSubImage2D(r,o,i,a,u,h,s):e.compressed?t.compressedTexSubImage2D(r,o,i,a,c,p,d,l):e.needsCopy?(n(),t.copyTexSubImage2D(r,o,i,a,e.xOffset,e.yOffset,p,d)):t.texSubImage2D(r,o,i,a,p,d,u,h,l)}function v(){return ot.pop()||new h}function k(t){t.needsFree&&X.freeType(t.data),h.call(t),ot.push(t)}function A(){s.call(this),this.genMipmaps=!1,this.mipmapHint=4352,this.mipmask=0,this.images=Array(16)}function M(t,e,r){var n=t.images[0]=v();t.mipmask=1,n.width=t.width=e,n.height=t.height=r,n.channels=t.channels=4}function S(t,e){var r=null;if(_(e))c(r=t.images[0]=v(),t),p(r,e),t.mipmask=1;else if(u(t,e),Array.isArray(e.mipmap))for(var n=e.mipmap,i=0;i<n.length;++i)c(r=t.images[i]=v(),t),r.width>>=i,r.height>>=i,p(r,n[i]),t.mipmask|=1<<i;else c(r=t.images[0]=v(),t),p(r,e),t.mipmask=1;c(t,t.images[0])}function E(e,r){for(var i=e.images,a=0;a<i.length&&i[a];++a){var o=i[a],s=r,l=a,c=o.element,u=o.data,h=o.internalformat,p=o.format,d=o.type,m=o.width,g=o.height;f(o),c?t.texImage2D(s,l,p,p,d,c):o.compressed?t.compressedTexImage2D(s,l,h,m,g,0,u):o.needsCopy?(n(),t.copyTexImage2D(s,l,p,o.xOffset,o.yOffset,m,g,0)):t.texImage2D(s,l,p,m,g,0,p,d,u||null)}}function L(){var t=st.pop()||new A;s.call(t);for(var e=t.mipmask=0;16>e;++e)t.images[e]=null;return t}function C(t){for(var e=t.images,r=0;r<e.length;++r)e[r]&&k(e[r]),e[r]=null;st.push(t)}function P(){this.magFilter=this.minFilter=9728,this.wrapT=this.wrapS=33071,this.anisotropic=1,this.genMipmaps=!1,this.mipmapHint=4352}function I(t,e){"min"in e&&(t.minFilter=U[e.min],0<=lt.indexOf(t.minFilter)&&!("faces"in e)&&(t.genMipmaps=!0)),"mag"in e&&(t.magFilter=j[e.mag]);var r=t.wrapS,n=t.wrapT;if("wrap"in e){var i=e.wrap;"string"==typeof i?r=n=N[i]:Array.isArray(i)&&(r=N[i[0]],n=N[i[1]])}else"wrapS"in e&&(r=N[e.wrapS]),"wrapT"in e&&(n=N[e.wrapT]);if(t.wrapS=r,t.wrapT=n,"anisotropic"in e&&(t.anisotropic=e.anisotropic),"mipmap"in e){switch(r=!1,typeof e.mipmap){case"string":t.mipmapHint=B[e.mipmap],r=t.genMipmaps=!0;break;case"boolean":r=t.genMipmaps=e.mipmap;break;case"object":t.genMipmaps=!1,r=!0}!r||"min"in e||(t.minFilter=9984)}}function O(r,n){t.texParameteri(n,10241,r.minFilter),t.texParameteri(n,10240,r.magFilter),t.texParameteri(n,10242,r.wrapS),t.texParameteri(n,10243,r.wrapT),e.ext_texture_filter_anisotropic&&t.texParameteri(n,34046,r.anisotropic),r.genMipmaps&&(t.hint(33170,r.mipmapHint),t.generateMipmap(n))}function z(e){s.call(this),this.mipmask=0,this.internalformat=6408,this.id=vt++,this.refCount=1,this.target=e,this.texture=t.createTexture(),this.unit=-1,this.bindCount=0,this.texInfo=new P,o.profile&&(this.stats={size:0})}function D(e){t.activeTexture(33984),t.bindTexture(e.target,e.texture)}function R(){var e=bt[0];e?t.bindTexture(e.target,e.texture):t.bindTexture(3553,null)}function F(e){var r=e.texture,n=e.unit,i=e.target;0<=n&&(t.activeTexture(33984+n),t.bindTexture(i,null),bt[n]=null),t.deleteTexture(r),e.texture=null,e.params=null,e.pixels=null,e.refCount=0,delete yt[e.id],a.textureCount--}var B={"don't care":4352,"dont care":4352,nice:4354,fast:4353},N={repeat:10497,clamp:33071,mirror:33648},j={nearest:9728,linear:9729},U=H({mipmap:9987,"nearest mipmap nearest":9984,"linear mipmap nearest":9985,"nearest mipmap linear":9986,"linear mipmap linear":9987},j),V={none:0,browser:37444},q={uint8:5121,rgba4:32819,rgb565:33635,"rgb5 a1":32820},G={alpha:6406,luminance:6409,"luminance alpha":6410,rgb:6407,rgba:6408,rgba4:32854,"rgb5 a1":32855,rgb565:36194},Y={};e.ext_srgb&&(G.srgb=35904,G.srgba=35906),e.oes_texture_float&&(q.float32=q.float=5126),e.oes_texture_half_float&&(q.float16=q["half float"]=36193),e.webgl_depth_texture&&(H(G,{depth:6402,"depth stencil":34041}),H(q,{uint16:5123,uint32:5125,"depth stencil":34042})),e.webgl_compressed_texture_s3tc&&H(Y,{"rgb s3tc dxt1":33776,"rgba s3tc dxt1":33777,"rgba s3tc dxt3":33778,"rgba s3tc dxt5":33779}),e.webgl_compressed_texture_atc&&H(Y,{"rgb atc":35986,"rgba atc explicit alpha":35987,"rgba atc interpolated alpha":34798}),e.webgl_compressed_texture_pvrtc&&H(Y,{"rgb pvrtc 4bppv1":35840,"rgb pvrtc 2bppv1":35841,"rgba pvrtc 4bppv1":35842,"rgba pvrtc 2bppv1":35843}),e.webgl_compressed_texture_etc1&&(Y["rgb etc1"]=36196);var W=Array.prototype.slice.call(t.getParameter(34467));Object.keys(Y).forEach((function(t){var e=Y[t];0<=W.indexOf(e)&&(G[t]=e)}));var Z=Object.keys(G);r.textureFormats=Z;var tt=[];Object.keys(G).forEach((function(t){tt[G[t]]=t}));var et=[];Object.keys(q).forEach((function(t){et[q[t]]=t}));var rt=[];Object.keys(j).forEach((function(t){rt[j[t]]=t}));var nt=[];Object.keys(U).forEach((function(t){nt[U[t]]=t}));var it=[];Object.keys(N).forEach((function(t){it[N[t]]=t}));var at=Z.reduce((function(t,r){var n=G[r];return 6409===n||6406===n||6409===n||6410===n||6402===n||34041===n||e.ext_srgb&&(35904===n||35906===n)?t[n]=n:32855===n||0<=r.indexOf("rgba")?t[n]=6408:t[n]=6407,t}),{}),ot=[],st=[],vt=0,yt={},xt=r.maxTextureUnits,bt=Array(xt).map((function(){return null}));return H(z.prototype,{bind:function(){this.bindCount+=1;var e=this.unit;if(0>e){for(var r=0;r<xt;++r){var n=bt[r];if(n){if(0<n.bindCount)continue;n.unit=-1}bt[r]=this,e=r;break}o.profile&&a.maxTextureUnits<e+1&&(a.maxTextureUnits=e+1),this.unit=e,t.activeTexture(33984+e),t.bindTexture(this.target,this.texture)}return e},unbind:function(){--this.bindCount},decRef:function(){0>=--this.refCount&&F(this)}}),o.profile&&(a.getTotalTextureSize=function(){var t=0;return Object.keys(yt).forEach((function(e){t+=yt[e].stats.size})),t}),{create2D:function(e,r){function n(t,e){var r=i.texInfo;P.call(r);var a=L();return"number"==typeof t?M(a,0|t,"number"==typeof e?0|e:0|t):t?(I(r,t),S(a,t)):M(a,1,1),r.genMipmaps&&(a.mipmask=(a.width<<1)-1),i.mipmask=a.mipmask,c(i,a),i.internalformat=a.internalformat,n.width=a.width,n.height=a.height,D(i),E(a,3553),O(r,3553),R(),C(a),o.profile&&(i.stats.size=T(i.internalformat,i.type,a.width,a.height,r.genMipmaps,!1)),n.format=tt[i.internalformat],n.type=et[i.type],n.mag=rt[r.magFilter],n.min=nt[r.minFilter],n.wrapS=it[r.wrapS],n.wrapT=it[r.wrapT],n}var i=new z(3553);return yt[i.id]=i,a.textureCount++,n(e,r),n.subimage=function(t,e,r,a){e|=0,r|=0,a|=0;var o=v();return c(o,i),o.width=0,o.height=0,p(o,t),o.width=o.width||(i.width>>a)-e,o.height=o.height||(i.height>>a)-r,D(i),d(o,3553,e,r,a),R(),k(o),n},n.resize=function(e,r){var a=0|e,s=0|r||a;if(a===i.width&&s===i.height)return n;n.width=i.width=a,n.height=i.height=s,D(i);for(var l=0;i.mipmask>>l;++l){var c=a>>l,u=s>>l;if(!c||!u)break;t.texImage2D(3553,l,i.format,c,u,0,i.format,i.type,null)}return R(),o.profile&&(i.stats.size=T(i.internalformat,i.type,a,s,!1,!1)),n},n._reglType="texture2d",n._texture=i,o.profile&&(n.stats=i.stats),n.destroy=function(){i.decRef()},n},createCube:function(e,r,n,i,s,l){function f(t,e,r,n,i,a){var s,l=h.texInfo;for(P.call(l),s=0;6>s;++s)m[s]=L();if("number"!=typeof t&&t){if("object"==typeof t)if(e)S(m[0],t),S(m[1],e),S(m[2],r),S(m[3],n),S(m[4],i),S(m[5],a);else if(I(l,t),u(h,t),"faces"in t)for(t=t.faces,s=0;6>s;++s)c(m[s],h),S(m[s],t[s]);else for(s=0;6>s;++s)S(m[s],t)}else for(t=0|t||1,s=0;6>s;++s)M(m[s],t,t);for(c(h,m[0]),h.mipmask=l.genMipmaps?(m[0].width<<1)-1:m[0].mipmask,h.internalformat=m[0].internalformat,f.width=m[0].width,f.height=m[0].height,D(h),s=0;6>s;++s)E(m[s],34069+s);for(O(l,34067),R(),o.profile&&(h.stats.size=T(h.internalformat,h.type,f.width,f.height,l.genMipmaps,!0)),f.format=tt[h.internalformat],f.type=et[h.type],f.mag=rt[l.magFilter],f.min=nt[l.minFilter],f.wrapS=it[l.wrapS],f.wrapT=it[l.wrapT],s=0;6>s;++s)C(m[s]);return f}var h=new z(34067);yt[h.id]=h,a.cubeCount++;var m=Array(6);return f(e,r,n,i,s,l),f.subimage=function(t,e,r,n,i){r|=0,n|=0,i|=0;var a=v();return c(a,h),a.width=0,a.height=0,p(a,e),a.width=a.width||(h.width>>i)-r,a.height=a.height||(h.height>>i)-n,D(h),d(a,34069+t,r,n,i),R(),k(a),f},f.resize=function(e){if((e|=0)!==h.width){f.width=h.width=e,f.height=h.height=e,D(h);for(var r=0;6>r;++r)for(var n=0;h.mipmask>>n;++n)t.texImage2D(34069+r,n,h.format,e>>n,e>>n,0,h.format,h.type,null);return R(),o.profile&&(h.stats.size=T(h.internalformat,h.type,f.width,f.height,!1,!0)),f}},f._reglType="textureCube",f._texture=h,o.profile&&(f.stats=h.stats),f.destroy=function(){h.decRef()},f},clear:function(){for(var e=0;e<xt;++e)t.activeTexture(33984+e),t.bindTexture(3553,null),bt[e]=null;K(yt).forEach(F),a.cubeCount=0,a.textureCount=0},getTexture:function(t){return null},restore:function(){for(var e=0;e<xt;++e){var r=bt[e];r&&(r.bindCount=0,r.unit=-1,bt[e]=null)}K(yt).forEach((function(e){e.texture=t.createTexture(),t.bindTexture(e.target,e.texture);for(var r=0;32>r;++r)if(0!=(e.mipmask&1<<r))if(3553===e.target)t.texImage2D(3553,r,e.internalformat,e.width>>r,e.height>>r,0,e.internalformat,e.type,null);else for(var n=0;6>n;++n)t.texImage2D(34069+n,r,e.internalformat,e.width>>r,e.height>>r,0,e.internalformat,e.type,null);O(e.texInfo,e.target)}))},refresh:function(){for(var e=0;e<xt;++e){var r=bt[e];r&&(r.bindCount=0,r.unit=-1,bt[e]=null),t.activeTexture(33984+e),t.bindTexture(3553,null),t.bindTexture(34067,null)}}}}function A(t,e,r,n,i,a){function o(t,e,r){this.target=t,this.texture=e,this.renderbuffer=r;var n=t=0;e?(t=e.width,n=e.height):r&&(t=r.width,n=r.height),this.width=t,this.height=n}function s(t){t&&(t.texture&&t.texture._texture.decRef(),t.renderbuffer&&t.renderbuffer._renderbuffer.decRef())}function l(t,e,r){t&&(t.texture?t.texture._texture.refCount+=1:t.renderbuffer._renderbuffer.refCount+=1)}function c(e,r){r&&(r.texture?t.framebufferTexture2D(36160,e,r.target,r.texture._texture.texture,0):t.framebufferRenderbuffer(36160,e,36161,r.renderbuffer._renderbuffer.renderbuffer))}function u(t){var e=3553,r=null,n=null,i=t;return"object"==typeof t&&(i=t.data,"target"in t&&(e=0|t.target)),"texture2d"===(t=i._reglType)||"textureCube"===t?r=i:"renderbuffer"===t&&(n=i,e=36161),new o(e,r,n)}function f(t,e,r,a,s){return r?((t=n.create2D({width:t,height:e,format:a,type:s}))._texture.refCount=0,new o(3553,t,null)):((t=i.create({width:t,height:e,format:a}))._renderbuffer.refCount=0,new o(36161,null,t))}function h(t){return t&&(t.texture||t.renderbuffer)}function p(t,e,r){t&&(t.texture?t.texture.resize(e,r):t.renderbuffer&&t.renderbuffer.resize(e,r),t.width=e,t.height=r)}function d(){this.id=T++,k[this.id]=this,this.framebuffer=t.createFramebuffer(),this.height=this.width=0,this.colorAttachments=[],this.depthStencilAttachment=this.stencilAttachment=this.depthAttachment=null}function m(t){t.colorAttachments.forEach(s),s(t.depthAttachment),s(t.stencilAttachment),s(t.depthStencilAttachment)}function g(e){t.deleteFramebuffer(e.framebuffer),e.framebuffer=null,a.framebufferCount--,delete k[e.id]}function v(e){var n;t.bindFramebuffer(36160,e.framebuffer);var i=e.colorAttachments;for(n=0;n<i.length;++n)c(36064+n,i[n]);for(n=i.length;n<r.maxColorAttachments;++n)t.framebufferTexture2D(36160,36064+n,3553,null,0);t.framebufferTexture2D(36160,33306,3553,null,0),t.framebufferTexture2D(36160,36096,3553,null,0),t.framebufferTexture2D(36160,36128,3553,null,0),c(36096,e.depthAttachment),c(36128,e.stencilAttachment),c(33306,e.depthStencilAttachment),t.checkFramebufferStatus(36160),t.isContextLost(),t.bindFramebuffer(36160,x.next?x.next.framebuffer:null),x.cur=x.next,t.getError()}function y(t,e){function r(t,e){var i,a=0,o=0,s=!0,c=!0;i=null;var p=!0,d="rgba",g="uint8",y=1,x=null,w=null,T=null,k=!1;"number"==typeof t?(a=0|t,o=0|e||a):t?("shape"in t?(a=(o=t.shape)[0],o=o[1]):("radius"in t&&(a=o=t.radius),"width"in t&&(a=t.width),"height"in t&&(o=t.height)),("color"in t||"colors"in t)&&(i=t.color||t.colors,Array.isArray(i)),i||("colorCount"in t&&(y=0|t.colorCount),"colorTexture"in t&&(p=!!t.colorTexture,d="rgba4"),"colorType"in t&&(g=t.colorType,!p)&&("half float"===g||"float16"===g?d="rgba16f":"float"!==g&&"float32"!==g||(d="rgba32f")),"colorFormat"in t&&(d=t.colorFormat,0<=b.indexOf(d)?p=!0:0<=_.indexOf(d)&&(p=!1))),("depthTexture"in t||"depthStencilTexture"in t)&&(k=!(!t.depthTexture&&!t.depthStencilTexture)),"depth"in t&&("boolean"==typeof t.depth?s=t.depth:(x=t.depth,c=!1)),"stencil"in t&&("boolean"==typeof t.stencil?c=t.stencil:(w=t.stencil,s=!1)),"depthStencil"in t&&("boolean"==typeof t.depthStencil?s=c=t.depthStencil:(T=t.depthStencil,c=s=!1))):a=o=1;var A=null,M=null,S=null,E=null;if(Array.isArray(i))A=i.map(u);else if(i)A=[u(i)];else for(A=Array(y),i=0;i<y;++i)A[i]=f(a,o,p,d,g);for(a=a||A[0].width,o=o||A[0].height,x?M=u(x):s&&!c&&(M=f(a,o,k,"depth","uint32")),w?S=u(w):c&&!s&&(S=f(a,o,!1,"stencil","uint8")),T?E=u(T):!x&&!w&&c&&s&&(E=f(a,o,k,"depth stencil","depth stencil")),s=null,i=0;i<A.length;++i)l(A[i]),A[i]&&A[i].texture&&(c=wt[A[i].texture._texture.format]*Tt[A[i].texture._texture.type],null===s&&(s=c));return l(M),l(S),l(E),m(n),n.width=a,n.height=o,n.colorAttachments=A,n.depthAttachment=M,n.stencilAttachment=S,n.depthStencilAttachment=E,r.color=A.map(h),r.depth=h(M),r.stencil=h(S),r.depthStencil=h(E),r.width=n.width,r.height=n.height,v(n),r}var n=new d;return a.framebufferCount++,r(t,e),H(r,{resize:function(t,e){var i=Math.max(0|t,1),a=Math.max(0|e||i,1);if(i===n.width&&a===n.height)return r;for(var o=n.colorAttachments,s=0;s<o.length;++s)p(o[s],i,a);return p(n.depthAttachment,i,a),p(n.stencilAttachment,i,a),p(n.depthStencilAttachment,i,a),n.width=r.width=i,n.height=r.height=a,v(n),r},_reglType:"framebuffer",_framebuffer:n,destroy:function(){g(n),m(n)},use:function(t){x.setFBO({framebuffer:r},t)}})}var x={cur:null,next:null,dirty:!1,setFBO:null},b=["rgba"],_=["rgba4","rgb565","rgb5 a1"];e.ext_srgb&&_.push("srgba"),e.ext_color_buffer_half_float&&_.push("rgba16f","rgb16f"),e.webgl_color_buffer_float&&_.push("rgba32f");var w=["uint8"];e.oes_texture_half_float&&w.push("half float","float16"),e.oes_texture_float&&w.push("float","float32");var T=0,k={};return H(x,{getFramebuffer:function(t){return"function"==typeof t&&"framebuffer"===t._reglType&&(t=t._framebuffer)instanceof d?t:null},create:y,createCube:function(t){function e(t){var i,a={color:null},o=0,s=null;i="rgba";var l="uint8",c=1;if("number"==typeof t?o=0|t:t?("shape"in t?o=t.shape[0]:("radius"in t&&(o=0|t.radius),"width"in t?o=0|t.width:"height"in t&&(o=0|t.height)),("color"in t||"colors"in t)&&(s=t.color||t.colors,Array.isArray(s)),s||("colorCount"in t&&(c=0|t.colorCount),"colorType"in t&&(l=t.colorType),"colorFormat"in t&&(i=t.colorFormat)),"depth"in t&&(a.depth=t.depth),"stencil"in t&&(a.stencil=t.stencil),"depthStencil"in t&&(a.depthStencil=t.depthStencil)):o=1,s)if(Array.isArray(s))for(t=[],i=0;i<s.length;++i)t[i]=s[i];else t=[s];else for(t=Array(c),s={radius:o,format:i,type:l},i=0;i<c;++i)t[i]=n.createCube(s);for(a.color=Array(t.length),i=0;i<t.length;++i)c=t[i],o=o||c.width,a.color[i]={target:34069,data:t[i]};for(i=0;6>i;++i){for(c=0;c<t.length;++c)a.color[c].target=34069+i;0<i&&(a.depth=r[0].depth,a.stencil=r[0].stencil,a.depthStencil=r[0].depthStencil),r[i]?r[i](a):r[i]=y(a)}return H(e,{width:o,height:o,color:t})}var r=Array(6);return e(t),H(e,{faces:r,resize:function(t){var n=0|t;if(n===e.width)return e;var i=e.color;for(t=0;t<i.length;++t)i[t].resize(n);for(t=0;6>t;++t)r[t].resize(n);return e.width=e.height=n,e},_reglType:"framebufferCube",destroy:function(){r.forEach((function(t){t.destroy()}))}})},clear:function(){K(k).forEach(g)},restore:function(){x.cur=null,x.next=null,x.dirty=!0,K(k).forEach((function(e){e.framebuffer=t.createFramebuffer(),v(e)}))}})}function M(){this.w=this.z=this.y=this.x=this.state=0,this.buffer=null,this.size=0,this.normalized=!1,this.type=5126,this.divisor=this.stride=this.offset=0}function S(t,e,r,n,i,a,o){function s(){this.id=++f,this.attributes=[],this.elements=null,this.ownsElements=!1,this.offset=this.count=0,this.instances=-1,this.primitive=4;var t=e.oes_vertex_array_object;this.vao=t?t.createVertexArrayOES():null,h[this.id]=this,this.buffers=[]}var c=r.maxAttributes,u=Array(c);for(r=0;r<c;++r)u[r]=new M;var f=0,h={},p={Record:M,scope:{},state:u,currentVAO:null,targetVAO:null,restore:e.oes_vertex_array_object?function(){e.oes_vertex_array_object&&K(h).forEach((function(t){t.refresh()}))}:function(){},createVAO:function(t){function e(t){var n;Array.isArray(t)?(n=t,r.elements&&r.ownsElements&&r.elements.destroy(),r.elements=null,r.ownsElements=!1,r.offset=0,r.count=0,r.instances=-1,r.primitive=4):(t.elements?(n=t.elements,r.ownsElements?("function"==typeof n&&"elements"===n._reglType?r.elements.destroy():r.elements(n),r.ownsElements=!1):a.getElements(t.elements)?(r.elements=t.elements,r.ownsElements=!1):(r.elements=a.create(t.elements),r.ownsElements=!0)):(r.elements=null,r.ownsElements=!1),n=t.attributes,r.offset=0,r.count=-1,r.instances=-1,r.primitive=4,r.elements&&(r.count=r.elements._elements.vertCount,r.primitive=r.elements._elements.primType),"offset"in t&&(r.offset=0|t.offset),"count"in t&&(r.count=0|t.count),"instances"in t&&(r.instances=0|t.instances),"primitive"in t&&(r.primitive=at[t.primitive])),t={};var o=r.attributes;o.length=n.length;for(var s=0;s<n.length;++s){var c,u=n[s],f=o[s]=new M,h=u.data||u;if(Array.isArray(h)||J(h)||l(h))r.buffers[s]&&(c=r.buffers[s],J(h)&&c._buffer.byteLength>=h.byteLength?c.subdata(h):(c.destroy(),r.buffers[s]=null)),r.buffers[s]||(c=r.buffers[s]=i.create(u,34962,!1,!0)),f.buffer=i.getBuffer(c),f.size=0|f.buffer.dimension,f.normalized=!1,f.type=f.buffer.dtype,f.offset=0,f.stride=0,f.divisor=0,f.state=1,t[s]=1;else i.getBuffer(u)?(f.buffer=i.getBuffer(u),f.size=0|f.buffer.dimension,f.normalized=!1,f.type=f.buffer.dtype,f.offset=0,f.stride=0,f.divisor=0,f.state=1):i.getBuffer(u.buffer)?(f.buffer=i.getBuffer(u.buffer),f.size=0|(+u.size||f.buffer.dimension),f.normalized=!!u.normalized||!1,f.type="type"in u?tt[u.type]:f.buffer.dtype,f.offset=0|(u.offset||0),f.stride=0|(u.stride||0),f.divisor=0|(u.divisor||0),f.state=1):"x"in u&&(f.x=+u.x||0,f.y=+u.y||0,f.z=+u.z||0,f.w=+u.w||0,f.state=2)}for(c=0;c<r.buffers.length;++c)!t[c]&&r.buffers[c]&&(r.buffers[c].destroy(),r.buffers[c]=null);return r.refresh(),e}var r=new s;return n.vaoCount+=1,e.destroy=function(){for(var t=0;t<r.buffers.length;++t)r.buffers[t]&&r.buffers[t].destroy();r.buffers.length=0,r.ownsElements&&(r.elements.destroy(),r.elements=null,r.ownsElements=!1),r.destroy()},e._vao=r,e._reglType="vao",e(t)},getVAO:function(t){return"function"==typeof t&&t._vao?t._vao:null},destroyBuffer:function(e){for(var r=0;r<u.length;++r){var n=u[r];n.buffer===e&&(t.disableVertexAttribArray(r),n.buffer=null)}},setVAO:e.oes_vertex_array_object?function(t){if(t!==p.currentVAO){var r=e.oes_vertex_array_object;t?r.bindVertexArrayOES(t.vao):r.bindVertexArrayOES(null),p.currentVAO=t}}:function(r){if(r!==p.currentVAO){if(r)r.bindAttrs();else{for(var n=e.angle_instanced_arrays,i=0;i<u.length;++i){var a=u[i];a.buffer?(t.enableVertexAttribArray(i),a.buffer.bind(),t.vertexAttribPointer(i,a.size,a.type,a.normalized,a.stride,a.offfset),n&&a.divisor&&n.vertexAttribDivisorANGLE(i,a.divisor)):(t.disableVertexAttribArray(i),t.vertexAttrib4f(i,a.x,a.y,a.z,a.w))}o.elements?t.bindBuffer(34963,o.elements.buffer.buffer):t.bindBuffer(34963,null)}p.currentVAO=r}},clear:e.oes_vertex_array_object?function(){K(h).forEach((function(t){t.destroy()}))}:function(){}};return s.prototype.bindAttrs=function(){for(var r=e.angle_instanced_arrays,n=this.attributes,i=0;i<n.length;++i){var o=n[i];o.buffer?(t.enableVertexAttribArray(i),t.bindBuffer(34962,o.buffer.buffer),t.vertexAttribPointer(i,o.size,o.type,o.normalized,o.stride,o.offset),r&&o.divisor&&r.vertexAttribDivisorANGLE(i,o.divisor)):(t.disableVertexAttribArray(i),t.vertexAttrib4f(i,o.x,o.y,o.z,o.w))}for(r=n.length;r<c;++r)t.disableVertexAttribArray(r);(r=a.getElements(this.elements))?t.bindBuffer(34963,r.buffer.buffer):t.bindBuffer(34963,null)},s.prototype.refresh=function(){var t=e.oes_vertex_array_object;t&&(t.bindVertexArrayOES(this.vao),this.bindAttrs(),p.currentVAO=null,t.bindVertexArrayOES(null))},s.prototype.destroy=function(){if(this.vao){var t=e.oes_vertex_array_object;this===p.currentVAO&&(p.currentVAO=null,t.bindVertexArrayOES(null)),t.deleteVertexArrayOES(this.vao),this.vao=null}this.ownsElements&&(this.elements.destroy(),this.elements=null,this.ownsElements=!1),h[this.id]&&(delete h[this.id],--n.vaoCount)},p}function E(t,e,r,n){function i(t,e,r,n){this.name=t,this.id=e,this.location=r,this.info=n}function a(t,e){for(var r=0;r<t.length;++r)if(t[r].id===e.id)return void(t[r].location=e.location);t.push(e)}function o(r,n,i){if(!(o=(i=35632===r?c:u)[n])){var a=e.str(n),o=t.createShader(r);t.shaderSource(o,a),t.compileShader(o),i[n]=o}return o}function s(t,e){this.id=p++,this.fragId=t,this.vertId=e,this.program=null,this.uniforms=[],this.attributes=[],this.refCount=1,n.profile&&(this.stats={uniformsCount:0,attributesCount:0})}function l(r,s,l){var c;c=o(35632,r.fragId);var u=o(35633,r.vertId);if(s=r.program=t.createProgram(),t.attachShader(s,c),t.attachShader(s,u),l)for(c=0;c<l.length;++c)u=l[c],t.bindAttribLocation(s,u[0],u[1]);t.linkProgram(s),u=t.getProgramParameter(s,35718),n.profile&&(r.stats.uniformsCount=u);var f=r.uniforms;for(c=0;c<u;++c)if(l=t.getActiveUniform(s,c))if(1<l.size)for(var h=0;h<l.size;++h){var p=l.name.replace("[0]","["+h+"]");a(f,new i(p,e.id(p),t.getUniformLocation(s,p),l))}else a(f,new i(l.name,e.id(l.name),t.getUniformLocation(s,l.name),l));for(u=t.getProgramParameter(s,35721),n.profile&&(r.stats.attributesCount=u),r=r.attributes,c=0;c<u;++c)(l=t.getActiveAttrib(s,c))&&a(r,new i(l.name,e.id(l.name),t.getAttribLocation(s,l.name),l))}var c={},u={},f={},h=[],p=0;return n.profile&&(r.getMaxUniformsCount=function(){var t=0;return h.forEach((function(e){e.stats.uniformsCount>t&&(t=e.stats.uniformsCount)})),t},r.getMaxAttributesCount=function(){var t=0;return h.forEach((function(e){e.stats.attributesCount>t&&(t=e.stats.attributesCount)})),t}),{clear:function(){var e=t.deleteShader.bind(t);K(c).forEach(e),c={},K(u).forEach(e),u={},h.forEach((function(e){t.deleteProgram(e.program)})),h.length=0,f={},r.shaderCount=0},program:function(e,n,i,a){var o=f[n];o||(o=f[n]={});var p=o[e];if(p&&(p.refCount++,!a))return p;var d=new s(n,e);return r.shaderCount++,l(d,i,a),p||(o[e]=d),h.push(d),H(d,{destroy:function(){if(d.refCount--,0>=d.refCount){t.deleteProgram(d.program);var e=h.indexOf(d);h.splice(e,1),r.shaderCount--}0>=o[d.vertId].refCount&&(t.deleteShader(u[d.vertId]),delete u[d.vertId],delete f[d.fragId][d.vertId]),Object.keys(f[d.fragId]).length||(t.deleteShader(c[d.fragId]),delete c[d.fragId],delete f[d.fragId])}})},restore:function(){c={},u={};for(var t=0;t<h.length;++t)l(h[t],null,h[t].attributes.map((function(t){return[t.location,t.name]})))},shader:o,frag:-1,vert:-1}}function L(t,e,r,n,i,a,o){function s(i){var a;a=null===e.next?5121:e.next.colorAttachments[0].texture._texture.type;var o=0,s=0,l=n.framebufferWidth,c=n.framebufferHeight,u=null;return J(i)?u=i:i&&(o=0|i.x,s=0|i.y,l=0|(i.width||n.framebufferWidth-o),c=0|(i.height||n.framebufferHeight-s),u=i.data||null),r(),i=l*c*4,u||(5121===a?u=new Uint8Array(i):5126===a&&(u=u||new Float32Array(i))),t.pixelStorei(3333,4),t.readPixels(o,s,l,c,6408,a,u),u}return function(t){return t&&"framebuffer"in t?function(t){var r;return e.setFBO({framebuffer:t.framebuffer},(function(){r=s(t)})),r}(t):s(t)}}function C(t,e){return t>>>e|t<<32-e}function P(t,e){var r=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(r>>16)<<16|65535&r}function I(t){return Array.prototype.slice.call(t)}function O(t){return I(t).join("")}function z(t){function e(){var t=[],e=[];return H((function(){t.push.apply(t,I(arguments))}),{def:function(){var r="v"+i++;return e.push(r),0<arguments.length&&(t.push(r,"="),t.push.apply(t,I(arguments)),t.push(";")),r},toString:function(){return O([0<e.length?"var "+e.join(",")+";":"",O(t)])}})}function r(){function t(t,e){n(t,e,"=",r.def(t,e),";")}var r=e(),n=e(),i=r.toString,a=n.toString;return H((function(){r.apply(r,I(arguments))}),{def:r.def,entry:r,exit:n,save:t,set:function(e,n,i){t(e,n),r(e,n,"=",i,";")},toString:function(){return i()+a()}})}var n=t&&t.cache,i=0,a=[],o=[],s=[],l=e(),c={};return{global:l,link:function(t,e){var r=e&&e.stable;if(!r)for(var n=0;n<o.length;++n)if(o[n]===t&&!s[n])return a[n];return n="g"+i++,a.push(n),o.push(t),s.push(r),n},block:e,proc:function(t,e){function n(){var t="a"+i.length;return i.push(t),t}var i=[];e=e||0;for(var a=0;a<e;++a)n();var o=(a=r()).toString;return c[t]=H(a,{arg:n,toString:function(){return O(["function(",i.join(),"){",o(),"}"])}})},scope:r,cond:function(){var t=O(arguments),e=r(),n=r(),i=e.toString,a=n.toString;return H(e,{then:function(){return e.apply(e,I(arguments)),this},else:function(){return n.apply(n,I(arguments)),this},toString:function(){var e=a();return e&&(e="else{"+e+"}"),O(["if(",t,"){",i(),"}",e])}})},compile:function(){var t=['"use strict";',l,"return {"];Object.keys(c).forEach((function(e){t.push('"',e,'":',c[e].toString(),",")})),t.push("}");var e,r=O(t).replace(/;/g,";\n").replace(/}/g,"}\n").replace(/{/g,"{\n");return n&&(e=function(t){for(var e,r="",n=0;n<t.length;n++)e=t.charCodeAt(n),r+="0123456789abcdef".charAt(e>>>4&15)+"0123456789abcdef".charAt(15&e);return r}(function(t){for(var e=Array(t.length>>2),r=0;r<e.length;r++)e[r]=0;for(r=0;r<8*t.length;r+=8)e[r>>5]|=(255&t.charCodeAt(r/8))<<24-r%32;var n,i,a,o,s,l,c,u,f,h,p,d=8*t.length;for(t=[1779033703,-1150833019,1013904242,-1521486534,1359893119,-1694144372,528734635,1541459225],r=Array(64),e[d>>5]|=128<<24-d%32,e[15+(d+64>>9<<4)]=d,u=0;u<e.length;u+=16){for(d=t[0],n=t[1],i=t[2],a=t[3],o=t[4],s=t[5],l=t[6],c=t[7],f=0;64>f;f++){var m;if(16>f)r[f]=e[f+u];else h=f,p=P(p=C(p=r[f-2],17)^C(p,19)^p>>>10,r[f-7]),m=C(m=r[f-15],7)^C(m,18)^m>>>3,r[h]=P(P(p,m),r[f-16]);h=P(P(P(P(c,h=C(h=o,6)^C(h,11)^C(h,25)),o&s^~o&l),kt[f]),r[f]),p=P(c=C(c=d,2)^C(c,13)^C(c,22),d&n^d&i^n&i),c=l,l=s,s=o,o=P(a,h),a=i,i=n,n=d,d=P(h,p)}t[0]=P(d,t[0]),t[1]=P(n,t[1]),t[2]=P(i,t[2]),t[3]=P(a,t[3]),t[4]=P(o,t[4]),t[5]=P(s,t[5]),t[6]=P(l,t[6]),t[7]=P(c,t[7])}for(e="",r=0;r<32*t.length;r+=8)e+=String.fromCharCode(t[r>>5]>>>24-r%32&255);return e}(function(t){for(var e,r,n="",i=-1;++i<t.length;)e=t.charCodeAt(i),r=i+1<t.length?t.charCodeAt(i+1):0,55296<=e&&56319>=e&&56320<=r&&57343>=r&&(e=65536+((1023&e)<<10)+(1023&r),i++),127>=e?n+=String.fromCharCode(e):2047>=e?n+=String.fromCharCode(192|e>>>6&31,128|63&e):65535>=e?n+=String.fromCharCode(224|e>>>12&15,128|e>>>6&63,128|63&e):2097151>=e&&(n+=String.fromCharCode(240|e>>>18&7,128|e>>>12&63,128|e>>>6&63,128|63&e));return n}(r))),n[e])?n[e].apply(null,o):(r=Function.apply(null,a.concat(r)),n&&(n[e]=r),r.apply(null,o))}}}function D(t){return Array.isArray(t)||J(t)||l(t)}function R(t){return t.sort((function(t,e){return"viewport"===t?-1:"viewport"===e?1:t<e?-1:1}))}function F(t,e,r,n){this.thisDep=t,this.contextDep=e,this.propDep=r,this.append=n}function B(t){return t&&!(t.thisDep||t.contextDep||t.propDep)}function N(t){return new F(!1,!1,!1,t)}function j(t,e){var r=t.type;if(0===r)return new F(!0,1<=(r=t.data.length),2<=r,e);if(4===r)return new F((r=t.data).thisDep,r.contextDep,r.propDep,e);if(5===r)return new F(!1,!1,!1,e);if(6===r){for(var n=r=!1,i=!1,a=0;a<t.data.length;++a){var o=t.data[a];1===o.type?i=!0:2===o.type?n=!0:3===o.type?r=!0:0===o.type?(r=!0,1<=(o=o.data)&&(n=!0),2<=o&&(i=!0)):4===o.type&&(r=r||o.data.thisDep,n=n||o.data.contextDep,i=i||o.data.propDep)}return new F(r,n,i,e)}return new F(3===r,2===r,1===r,e)}function U(t,e,r,n,i,o,s,l,c,u,f,h,p,d,m,v){function y(t){return t.replace(".","_")}function x(t,e,r){var n=y(t);ot.push(t),it[n]=nt[n]=!!r,st[n]=e}function b(t,e,r){var n=y(t);ot.push(t),Array.isArray(r)?(nt[n]=r.slice(),it[n]=r.slice()):nt[n]=it[n]=r,lt[n]=e}function _(){var t=z({cache:m}),r=t.link,n=t.global;t.id=ft++,t.batchId="0";var i=r(ct),a=t.shared={props:"a0"};Object.keys(ct).forEach((function(t){a[t]=n.def(i,".",t)}));var o=t.next={},s=t.current={};Object.keys(lt).forEach((function(t){Array.isArray(nt[t])&&(o[t]=n.def(a.next,".",t),s[t]=n.def(a.current,".",t))}));var l=t.constants={};Object.keys(ut).forEach((function(t){l[t]=n.def(JSON.stringify(ut[t]))})),t.invoke=function(e,n){switch(n.type){case 0:var i=["this",a.context,a.props,t.batchId];return e.def(r(n.data),".call(",i.slice(0,Math.max(n.data.length+1,4)),")");case 1:return e.def(a.props,n.data);case 2:return e.def(a.context,n.data);case 3:return e.def("this",n.data);case 4:return n.data.append(t,e),n.data.ref;case 5:return n.data.toString();case 6:return n.data.map((function(r){return t.invoke(e,r)}))}},t.attribCache={};var c={};return t.scopeAttrib=function(t){if((t=e.id(t))in c)return c[t];var n=u.scope[t];return n||(n=u.scope[t]=new K),c[t]=r(n)},t}function w(t,e){var r=t.static,n=t.dynamic;if("framebuffer"in r){var i=r.framebuffer;return i?(i=l.getFramebuffer(i),N((function(t,e){var r=t.link(i),n=t.shared;return e.set(n.framebuffer,".next",r),n=n.context,e.set(n,".framebufferWidth",r+".width"),e.set(n,".framebufferHeight",r+".height"),r}))):N((function(t,e){var r=t.shared;return e.set(r.framebuffer,".next","null"),r=r.context,e.set(r,".framebufferWidth",r+".drawingBufferWidth"),e.set(r,".framebufferHeight",r+".drawingBufferHeight"),"null"}))}if("framebuffer"in n){var a=n.framebuffer;return j(a,(function(t,e){var r=t.invoke(e,a),n=t.shared,i=n.framebuffer;r=e.def(i,".getFramebuffer(",r,")");return e.set(i,".next",r),n=n.context,e.set(n,".framebufferWidth",r+"?"+r+".width:"+n+".drawingBufferWidth"),e.set(n,".framebufferHeight",r+"?"+r+".height:"+n+".drawingBufferHeight"),r}))}return null}function T(t,r,n){function i(t){if(t in a){var r=e.id(a[t]);return(t=N((function(){return r}))).id=r,t}if(t in o){var n=o[t];return j(n,(function(t,e){var r=t.invoke(e,n);return e.def(t.shared.strings,".id(",r,")")}))}return null}var a=t.static,o=t.dynamic,s=i("frag"),l=i("vert"),c=null;return B(s)&&B(l)?(c=f.program(l.id,s.id,null,n),t=N((function(t,e){return t.link(c)}))):t=new F(s&&s.thisDep||l&&l.thisDep,s&&s.contextDep||l&&l.contextDep,s&&s.propDep||l&&l.propDep,(function(t,e){var r,n,i=t.shared.shader;return r=s?s.append(t,e):e.def(i,".","frag"),n=l?l.append(t,e):e.def(i,".","vert"),e.def(i+".program("+n+","+r+")")})),{frag:s,vert:l,progVar:t,program:c}}function k(t,e){function r(t,e){if(t in n){var r=0|n[t];return e?a.offset=r:a.instances=r,N((function(t,n){return e&&(t.OFFSET=r),r}))}if(t in i){var o=i[t];return j(o,(function(t,r){var n=t.invoke(r,o);return e&&(t.OFFSET=n),n}))}if(e){if(c)return N((function(t,e){return t.OFFSET=0}));if(s)return new F(l.thisDep,l.contextDep,l.propDep,(function(t,e){return e.def(t.shared.vao+".currentVAO?"+t.shared.vao+".currentVAO.offset:0")}))}else if(s)return new F(l.thisDep,l.contextDep,l.propDep,(function(t,e){return e.def(t.shared.vao+".currentVAO?"+t.shared.vao+".currentVAO.instances:-1")}));return null}var n=t.static,i=t.dynamic,a={},s=!1,l=function(){if("vao"in n){var t=n.vao;return null!==t&&null===u.getVAO(t)&&(t=u.createVAO(t)),s=!0,a.vao=t,N((function(e){var r=u.getVAO(t);return r?e.link(r):"null"}))}if("vao"in i){s=!0;var e=i.vao;return j(e,(function(t,r){var n=t.invoke(r,e);return r.def(t.shared.vao+".getVAO("+n+")")}))}return null}(),c=!1,f=function(){if("elements"in n){var t=n.elements;if(a.elements=t,D(t)){var e=a.elements=o.create(t,!0);t=o.getElements(e);c=!0}else t&&(t=o.getElements(t),c=!0);return(e=N((function(e,r){if(t){var n=e.link(t);return e.ELEMENTS=n}return e.ELEMENTS=null}))).value=t,e}if("elements"in i){c=!0;var r=i.elements;return j(r,(function(t,e){var n=(i=t.shared).isBufferArgs,i=i.elements,a=t.invoke(e,r),o=e.def("null");n=e.def(n,"(",a,")"),a=t.cond(n).then(o,"=",i,".createStream(",a,");").else(o,"=",i,".getElements(",a,");");return e.entry(a),e.exit(t.cond(n).then(i,".destroyStream(",o,");")),t.ELEMENTS=o}))}return s?new F(l.thisDep,l.contextDep,l.propDep,(function(t,e){return e.def(t.shared.vao+".currentVAO?"+t.shared.elements+".getElements("+t.shared.vao+".currentVAO.elements):null")})):null}(),h=r("offset",!0),p=function(){if("primitive"in n){var t=n.primitive;return a.primitive=t,N((function(e,r){return at[t]}))}if("primitive"in i){var e=i.primitive;return j(e,(function(t,r){var n=t.constants.primTypes,i=t.invoke(r,e);return r.def(n,"[",i,"]")}))}return c?B(f)?f.value?N((function(t,e){return e.def(t.ELEMENTS,".primType")})):N((function(){return 4})):new F(f.thisDep,f.contextDep,f.propDep,(function(t,e){var r=t.ELEMENTS;return e.def(r,"?",r,".primType:",4)})):s?new F(l.thisDep,l.contextDep,l.propDep,(function(t,e){return e.def(t.shared.vao+".currentVAO?"+t.shared.vao+".currentVAO.primitive:4")})):null}(),d=function(){if("count"in n){var t=0|n.count;return a.count=t,N((function(){return t}))}if("count"in i){var e=i.count;return j(e,(function(t,r){return t.invoke(r,e)}))}return c?B(f)?f?h?new F(h.thisDep,h.contextDep,h.propDep,(function(t,e){return e.def(t.ELEMENTS,".vertCount-",t.OFFSET)})):N((function(t,e){return e.def(t.ELEMENTS,".vertCount")})):N((function(){return-1})):new F(f.thisDep||h.thisDep,f.contextDep||h.contextDep,f.propDep||h.propDep,(function(t,e){var r=t.ELEMENTS;return t.OFFSET?e.def(r,"?",r,".vertCount-",t.OFFSET,":-1"):e.def(r,"?",r,".vertCount:-1")})):s?new F(l.thisDep,l.contextDep,l.propDep,(function(t,e){return e.def(t.shared.vao,".currentVAO?",t.shared.vao,".currentVAO.count:-1")})):null}(),m=r("instances",!1);return{elements:f,primitive:p,count:d,instances:m,offset:h,vao:l,vaoActive:s,elementsActive:c,static:a}}function A(t,r){var n=t.static,a=t.dynamic,o={};return Object.keys(n).forEach((function(t){var r=n[t],a=e.id(t),s=new K;if(D(r))s.state=1,s.buffer=i.getBuffer(i.create(r,34962,!1,!0)),s.type=0;else if(c=i.getBuffer(r))s.state=1,s.buffer=c,s.type=0;else if("constant"in r){var l=r.constant;s.buffer="null",s.state=2,"number"==typeof l?s.x=l:At.forEach((function(t,e){e<l.length&&(s[t]=l[e])}))}else{var c=D(r.buffer)?i.getBuffer(i.create(r.buffer,34962,!1,!0)):i.getBuffer(r.buffer),u=0|r.offset,f=0|r.stride,h=0|r.size,p=!!r.normalized,d=0;"type"in r&&(d=tt[r.type]),r=0|r.divisor,s.buffer=c,s.state=1,s.size=h,s.normalized=p,s.type=d||c.dtype,s.offset=u,s.stride=f,s.divisor=r}o[t]=N((function(t,e){var r=t.attribCache;if(a in r)return r[a];var n={isStream:!1};return Object.keys(s).forEach((function(t){n[t]=s[t]})),s.buffer&&(n.buffer=t.link(s.buffer),n.type=n.type||n.buffer+".dtype"),r[a]=n}))})),Object.keys(a).forEach((function(t){var e=a[t];o[t]=j(e,(function(t,r){function n(t){r(l[t],"=",i,".",t,"|0;")}var i=t.invoke(r,e),a=t.shared,o=t.constants,s=a.isBufferArgs,l=(a=a.buffer,{isStream:r.def(!1)}),c=new K;c.state=1,Object.keys(c).forEach((function(t){l[t]=r.def(""+c[t])}));var u=l.buffer,f=l.type;return r("if(",s,"(",i,")){",l.isStream,"=true;",u,"=",a,".createStream(",34962,",",i,");",f,"=",u,".dtype;","}else{",u,"=",a,".getBuffer(",i,");","if(",u,"){",f,"=",u,".dtype;",'}else if("constant" in ',i,"){",l.state,"=",2,";","if(typeof "+i+'.constant === "number"){',l[At[0]],"=",i,".constant;",At.slice(1).map((function(t){return l[t]})).join("="),"=0;","}else{",At.map((function(t,e){return l[t]+"="+i+".constant.length>"+e+"?"+i+".constant["+e+"]:0;"})).join(""),"}}else{","if(",s,"(",i,".buffer)){",u,"=",a,".createStream(",34962,",",i,".buffer);","}else{",u,"=",a,".getBuffer(",i,".buffer);","}",f,'="type" in ',i,"?",o.glTypes,"[",i,".type]:",u,".dtype;",l.normalized,"=!!",i,".normalized;"),n("size"),n("offset"),n("stride"),n("divisor"),r("}}"),r.exit("if(",l.isStream,"){",a,".destroyStream(",u,");","}"),l}))})),o}function M(t,e,n,i,o){function s(t){var e=c[t];e&&(h[t]=e)}var l=function(t,e){if("string"==typeof(r=t.static).frag&&"string"==typeof r.vert){if(0<Object.keys(e.dynamic).length)return null;var r=e.static,n=Object.keys(r);if(0<n.length&&"number"==typeof r[n[0]]){for(var i=[],a=0;a<n.length;++a)i.push([0|r[n[a]],n[a]]);return i}}return null}(t,e),c=function(t,e,r){function n(t){if(t in i){var r=i[t];t=!0;var n,o,s=0|r.x,l=0|r.y;return"width"in r?n=0|r.width:t=!1,"height"in r?o=0|r.height:t=!1,new F(!t&&e&&e.thisDep,!t&&e&&e.contextDep,!t&&e&&e.propDep,(function(t,e){var i=t.shared.context,a=n;"width"in r||(a=e.def(i,".","framebufferWidth","-",s));var c=o;return"height"in r||(c=e.def(i,".","framebufferHeight","-",l)),[s,l,a,c]}))}if(t in a){var c=a[t];return t=j(c,(function(t,e){var r=t.invoke(e,c),n=t.shared.context,i=e.def(r,".x|0"),a=e.def(r,".y|0");return[i,a,e.def('"width" in ',r,"?",r,".width|0:","(",n,".","framebufferWidth","-",i,")"),r=e.def('"height" in ',r,"?",r,".height|0:","(",n,".","framebufferHeight","-",a,")")]})),e&&(t.thisDep=t.thisDep||e.thisDep,t.contextDep=t.contextDep||e.contextDep,t.propDep=t.propDep||e.propDep),t}return e?new F(e.thisDep,e.contextDep,e.propDep,(function(t,e){var r=t.shared.context;return[0,0,e.def(r,".","framebufferWidth"),e.def(r,".","framebufferHeight")]})):null}var i=t.static,a=t.dynamic;if(t=n("viewport")){var o=t;t=new F(t.thisDep,t.contextDep,t.propDep,(function(t,e){var r=o.append(t,e),n=t.shared.context;return e.set(n,".viewportWidth",r[2]),e.set(n,".viewportHeight",r[3]),r}))}return{viewport:t,scissor_box:n("scissor.box")}}(t,d=w(t)),f=k(t),h=function(t,e){var r=t.static,n=t.dynamic,i={};return ot.forEach((function(t){function e(e,a){if(t in r){var s=e(r[t]);i[o]=N((function(){return s}))}else if(t in n){var l=n[t];i[o]=j(l,(function(t,e){return a(t,e,t.invoke(e,l))}))}}var o=y(t);switch(t){case"cull.enable":case"blend.enable":case"dither":case"stencil.enable":case"depth.enable":case"scissor.enable":case"polygonOffset.enable":case"sample.alpha":case"sample.enable":case"depth.mask":return e((function(t){return t}),(function(t,e,r){return r}));case"depth.func":return e((function(t){return Et[t]}),(function(t,e,r){return e.def(t.constants.compareFuncs,"[",r,"]")}));case"depth.range":return e((function(t){return t}),(function(t,e,r){return[e.def("+",r,"[0]"),e=e.def("+",r,"[1]")]}));case"blend.func":return e((function(t){return[St["srcRGB"in t?t.srcRGB:t.src],St["dstRGB"in t?t.dstRGB:t.dst],St["srcAlpha"in t?t.srcAlpha:t.src],St["dstAlpha"in t?t.dstAlpha:t.dst]]}),(function(t,e,r){function n(t,n){return e.def('"',t,n,'" in ',r,"?",r,".",t,n,":",r,".",t)}t=t.constants.blendFuncs;var i=n("src","RGB"),a=n("dst","RGB"),o=(i=e.def(t,"[",i,"]"),e.def(t,"[",n("src","Alpha"),"]"));return[i,a=e.def(t,"[",a,"]"),o,t=e.def(t,"[",n("dst","Alpha"),"]")]}));case"blend.equation":return e((function(t){return"string"==typeof t?[Q[t],Q[t]]:"object"==typeof t?[Q[t.rgb],Q[t.alpha]]:void 0}),(function(t,e,r){var n=t.constants.blendEquations,i=e.def(),a=e.def();return(t=t.cond("typeof ",r,'==="string"')).then(i,"=",a,"=",n,"[",r,"];"),t.else(i,"=",n,"[",r,".rgb];",a,"=",n,"[",r,".alpha];"),e(t),[i,a]}));case"blend.color":return e((function(t){return a(4,(function(e){return+t[e]}))}),(function(t,e,r){return a(4,(function(t){return e.def("+",r,"[",t,"]")}))}));case"stencil.mask":return e((function(t){return 0|t}),(function(t,e,r){return e.def(r,"|0")}));case"stencil.func":return e((function(t){return[Et[t.cmp||"keep"],t.ref||0,"mask"in t?t.mask:-1]}),(function(t,e,r){return[t=e.def('"cmp" in ',r,"?",t.constants.compareFuncs,"[",r,".cmp]",":",7680),e.def(r,".ref|0"),e=e.def('"mask" in ',r,"?",r,".mask|0:-1")]}));case"stencil.opFront":case"stencil.opBack":return e((function(e){return["stencil.opBack"===t?1029:1028,Lt[e.fail||"keep"],Lt[e.zfail||"keep"],Lt[e.zpass||"keep"]]}),(function(e,r,n){function i(t){return r.def('"',t,'" in ',n,"?",a,"[",n,".",t,"]:",7680)}var a=e.constants.stencilOps;return["stencil.opBack"===t?1029:1028,i("fail"),i("zfail"),i("zpass")]}));case"polygonOffset.offset":return e((function(t){return[0|t.factor,0|t.units]}),(function(t,e,r){return[e.def(r,".factor|0"),e=e.def(r,".units|0")]}));case"cull.face":return e((function(t){var e=0;return"front"===t?e=1028:"back"===t&&(e=1029),e}),(function(t,e,r){return e.def(r,'==="front"?',1028,":",1029)}));case"lineWidth":return e((function(t){return t}),(function(t,e,r){return r}));case"frontFace":return e((function(t){return Ct[t]}),(function(t,e,r){return e.def(r+'==="cw"?2304:2305')}));case"colorMask":return e((function(t){return t.map((function(t){return!!t}))}),(function(t,e,r){return a(4,(function(t){return"!!"+r+"["+t+"]"}))}));case"sample.coverage":return e((function(t){return["value"in t?t.value:1,!!t.invert]}),(function(t,e,r){return[e.def('"value" in ',r,"?+",r,".value:1"),e=e.def("!!",r,".invert")]}))}})),i}(t),p=T(t,0,l);s("viewport"),s(y("scissor.box"));var d,m=0<Object.keys(h).length;if((d={framebuffer:d,draw:f,shader:p,state:h,dirty:m,scopeVAO:null,drawVAO:null,useVAO:!1,attributes:{}}).profile=function(t){var e,r=t.static;if(t=t.dynamic,"profile"in r){var n=!!r.profile;(e=N((function(t,e){return n}))).enable=n}else if("profile"in t){var i=t.profile;e=j(i,(function(t,e){return t.invoke(e,i)}))}return e}(t),d.uniforms=function(t,e){var r=t.static,n=t.dynamic,i={};return Object.keys(r).forEach((function(t){var e,n=r[t];if("number"==typeof n||"boolean"==typeof n)e=N((function(){return n}));else if("function"==typeof n){var o=n._reglType;"texture2d"===o||"textureCube"===o?e=N((function(t){return t.link(n)})):"framebuffer"!==o&&"framebufferCube"!==o||(e=N((function(t){return t.link(n.color[0])})))}else g(n)&&(e=N((function(t){return t.global.def("[",a(n.length,(function(t){return n[t]})),"]")})));e.value=n,i[t]=e})),Object.keys(n).forEach((function(t){var e=n[t];i[t]=j(e,(function(t,r){return t.invoke(r,e)}))})),i}(n),d.drawVAO=d.scopeVAO=f.vao,!d.drawVAO&&p.program&&!l&&r.angle_instanced_arrays&&f.static.elements){var v=!0;if(t=p.program.attributes.map((function(t){return t=e.static[t],v=v&&!!t,t})),v&&0<t.length){var x=u.getVAO(u.createVAO({attributes:t,elements:f.static.elements}));d.drawVAO=new F(null,null,null,(function(t,e){return t.link(x)})),d.useVAO=!0}}return l?d.useVAO=!0:d.attributes=A(e),d.context=function(t){var e=t.static,r=t.dynamic,n={};return Object.keys(e).forEach((function(t){var r=e[t];n[t]=N((function(t,e){return"number"==typeof r||"boolean"==typeof r?""+r:t.link(r)}))})),Object.keys(r).forEach((function(t){var e=r[t];n[t]=j(e,(function(t,r){return t.invoke(r,e)}))})),n}(i),d}function S(t,e,r){var n=t.shared.context,i=t.scope();Object.keys(r).forEach((function(a){e.save(n,"."+a);var o=r[a].append(t,e);Array.isArray(o)?i(n,".",a,"=[",o.join(),"];"):i(n,".",a,"=",o,";")})),e(i)}function E(t,e,r,n){var i,a=(s=t.shared).gl,o=s.framebuffer;et&&(i=e.def(s.extensions,".webgl_draw_buffers"));var s=(l=t.constants).drawBuffer,l=l.backBuffer;t=r?r.append(t,e):e.def(o,".next"),n||e("if(",t,"!==",o,".cur){"),e("if(",t,"){",a,".bindFramebuffer(",36160,",",t,".framebuffer);"),et&&e(i,".drawBuffersWEBGL(",s,"[",t,".colorAttachments.length]);"),e("}else{",a,".bindFramebuffer(",36160,",null);"),et&&e(i,".drawBuffersWEBGL(",l,");"),e("}",o,".cur=",t,";"),n||e("}")}function L(t,e,r){var n=t.shared,i=n.gl,o=t.current,s=t.next,l=n.current,c=n.next,u=t.cond(l,".dirty");ot.forEach((function(e){var n,f;if(!((e=y(e))in r.state))if(e in s){n=s[e],f=o[e];var h=a(nt[e].length,(function(t){return u.def(n,"[",t,"]")}));u(t.cond(h.map((function(t,e){return t+"!=="+f+"["+e+"]"})).join("||")).then(i,".",lt[e],"(",h,");",h.map((function(t,e){return f+"["+e+"]="+t})).join(";"),";"))}else n=u.def(c,".",e),h=t.cond(n,"!==",l,".",e),u(h),e in st?h(t.cond(n).then(i,".enable(",st[e],");").else(i,".disable(",st[e],");"),l,".",e,"=",n,";"):h(i,".",lt[e],"(",n,");",l,".",e,"=",n,";")})),0===Object.keys(r.state).length&&u(l,".dirty=false;"),e(u)}function C(t,e,r,n){var i,a=t.shared,o=t.current,s=a.current,l=a.gl;R(Object.keys(r)).forEach((function(a){var c=r[a];if(!n||n(c)){var u=c.append(t,e);if(st[a]){var f=st[a];B(c)?(i=t.link(u,{stable:!0}),e(t.cond(i).then(l,".enable(",f,");").else(l,".disable(",f,");")),e(s,".",a,"=",i,";")):(e(t.cond(u).then(l,".enable(",f,");").else(l,".disable(",f,");")),e(s,".",a,"=",u,";"))}else if(g(u)){var h=o[a];e(l,".",lt[a],"(",u,");",u.map((function(t,e){return h+"["+e+"]="+t})).join(";"),";")}else B(c)?(i=t.link(u,{stable:!0}),e(l,".",lt[a],"(",i,");",s,".",a,"=",i,";")):e(l,".",lt[a],"(",u,");",s,".",a,"=",u,";")}}))}function P(t,e){$&&(t.instancing=e.def(t.shared.extensions,".angle_instanced_arrays"))}function I(t,e,r,n,i){function a(){return"undefined"==typeof performance?"Date.now()":"performance.now()"}function o(t){t(c=e.def(),"=",a(),";"),"string"==typeof i?t(h,".count+=",i,";"):t(h,".count++;"),d&&(n?t(u=e.def(),"=",m,".getNumPendingQueries();"):t(m,".beginQuery(",h,");"))}function s(t){t(h,".cpuTime+=",a(),"-",c,";"),d&&(n?t(m,".pushScopeStats(",u,",",m,".getNumPendingQueries(),",h,");"):t(m,".endQuery();"))}function l(t){var r=e.def(p,".profile");e(p,".profile=",t,";"),e.exit(p,".profile=",r,";")}var c,u,f=t.shared,h=t.stats,p=f.current,m=f.timer;if(r=r.profile){if(B(r))return void(r.enable?(o(e),s(e.exit),l("true")):l("false"));l(r=r.append(t,e))}else r=e.def(p,".profile");o(f=t.block()),e("if(",r,"){",f,"}"),s(t=t.block()),e.exit("if(",r,"){",t,"}")}function O(t,e,r,n,i){function a(r,n,i){function a(){e("if(!",u,".buffer){",l,".enableVertexAttribArray(",c,");}");var r,a=i.type;r=i.size?e.def(i.size,"||",n):n,e("if(",u,".type!==",a,"||",u,".size!==",r,"||",p.map((function(t){return u+"."+t+"!=="+i[t]})).join("||"),"){",l,".bindBuffer(",34962,",",f,".buffer);",l,".vertexAttribPointer(",[c,r,a,i.normalized,i.stride,i.offset],");",u,".type=",a,";",u,".size=",r,";",p.map((function(t){return u+"."+t+"="+i[t]+";"})).join(""),"}"),$&&(a=i.divisor,e("if(",u,".divisor!==",a,"){",t.instancing,".vertexAttribDivisorANGLE(",[c,a],");",u,".divisor=",a,";}"))}function s(){e("if(",u,".buffer){",l,".disableVertexAttribArray(",c,");",u,".buffer=null;","}if(",At.map((function(t,e){return u+"."+t+"!=="+h[e]})).join("||"),"){",l,".vertexAttrib4f(",c,",",h,");",At.map((function(t,e){return u+"."+t+"="+h[e]+";"})).join(""),"}")}var l=o.gl,c=e.def(r,".location"),u=e.def(o.attributes,"[",c,"]");r=i.state;var f=i.buffer,h=[i.x,i.y,i.z,i.w],p=["buffer","normalized","offset","stride"];1===r?a():2===r?s():(e("if(",r,"===",1,"){"),a(),e("}else{"),s(),e("}"))}var o=t.shared;n.forEach((function(n){var o,s=n.name,l=r.attributes[s];if(l){if(!i(l))return;o=l.append(t,e)}else{if(!i(Pt))return;var c=t.scopeAttrib(s);o={},Object.keys(new K).forEach((function(t){o[t]=e.def(c,".",t)}))}a(t.link(n),function(t){switch(t){case 35664:case 35667:case 35671:return 2;case 35665:case 35668:case 35672:return 3;case 35666:case 35669:case 35673:return 4;default:return 1}}(n.info.type),o)}))}function U(t,r,n,i,o,s){for(var l,c=t.shared,u=c.gl,f=0;f<i.length;++f){var h,p=(v=i[f]).name,d=v.info.type,m=n.uniforms[p],v=t.link(v)+".location";if(m){if(!o(m))continue;if(B(m)){if(p=m.value,35678===d||35680===d)r(u,".uniform1i(",v,",",(d=t.link(p._texture||p.color[0]._texture))+".bind());"),r.exit(d,".unbind();");else if(35674===d||35675===d||35676===d)m=2,35675===d?m=3:35676===d&&(m=4),r(u,".uniformMatrix",m,"fv(",v,",false,",p=t.global.def("new Float32Array(["+Array.prototype.slice.call(p)+"])"),");");else{switch(d){case 5126:l="1f";break;case 35664:l="2f";break;case 35665:l="3f";break;case 35666:l="4f";break;case 35670:case 5124:l="1i";break;case 35671:case 35667:l="2i";break;case 35672:case 35668:l="3i";break;case 35673:l="4i";break;case 35669:l="4i"}r(u,".uniform",l,"(",v,",",g(p)?Array.prototype.slice.call(p):p,");")}continue}h=m.append(t,r)}else{if(!o(Pt))continue;h=r.def(c.uniforms,"[",e.id(p),"]")}switch(35678===d?r("if(",h,"&&",h,'._reglType==="framebuffer"){',h,"=",h,".color[0];","}"):35680===d&&r("if(",h,"&&",h,'._reglType==="framebufferCube"){',h,"=",h,".color[0];","}"),p=1,d){case 35678:case 35680:d=r.def(h,"._texture"),r(u,".uniform1i(",v,",",d,".bind());"),r.exit(d,".unbind();");continue;case 5124:case 35670:l="1i";break;case 35667:case 35671:l="2i",p=2;break;case 35668:case 35672:l="3i",p=3;break;case 35669:case 35673:l="4i",p=4;break;case 5126:l="1f";break;case 35664:l="2f",p=2;break;case 35665:l="3f",p=3;break;case 35666:l="4f",p=4;break;case 35674:l="Matrix2fv";break;case 35675:l="Matrix3fv";break;case 35676:l="Matrix4fv"}if("M"===l.charAt(0)){r(u,".uniform",l,"(",v,",");v=Math.pow(d-35674+2,2);var y=t.global.def("new Float32Array(",v,")");Array.isArray(h)?r("false,(",a(v,(function(t){return y+"["+t+"]="+h[t]})),",",y,")"):r("false,(Array.isArray(",h,")||",h," instanceof Float32Array)?",h,":(",a(v,(function(t){return y+"["+t+"]="+h+"["+t+"]"})),",",y,")"),r(");")}else{if(1<p){d=[];var x=[];for(m=0;m<p;++m)Array.isArray(h)?x.push(h[m]):x.push(r.def(h+"["+m+"]")),s&&d.push(r.def());s&&r("if(!",t.batchId,"||",d.map((function(t,e){return t+"!=="+x[e]})).join("||"),"){",d.map((function(t,e){return t+"="+x[e]+";"})).join("")),r(u,".uniform",l,"(",v,",",x.join(","),");")}else s&&(d=r.def(),r("if(!",t.batchId,"||",d,"!==",h,"){",d,"=",h,";")),r(u,".uniform",l,"(",v,",",h,");");s&&r("}")}}}function V(t,e,r,n){function i(i){var a=h[i];return a?a.contextDep&&n.contextDynamic||a.propDep?a.append(t,r):a.append(t,e):e.def(f,".",i)}function a(){function t(){r(l,".drawElementsInstancedANGLE(",[d,g,v,m+"<<(("+v+"-5121)>>1)",s],");")}function e(){r(l,".drawArraysInstancedANGLE(",[d,m,g,s],");")}p&&"null"!==p?y?t():(r("if(",p,"){"),t(),r("}else{"),e(),r("}")):e()}function o(){function t(){r(u+".drawElements("+[d,g,v,m+"<<(("+v+"-5121)>>1)"]+");")}function e(){r(u+".drawArrays("+[d,m,g]+");")}p&&"null"!==p?y?t():(r("if(",p,"){"),t(),r("}else{"),e(),r("}")):e()}var s,l,c=t.shared,u=c.gl,f=c.draw,h=n.draw,p=function(){var i=h.elements,a=e;return i?((i.contextDep&&n.contextDynamic||i.propDep)&&(a=r),i=i.append(t,a),h.elementsActive&&a("if("+i+")"+u+".bindBuffer(34963,"+i+".buffer.buffer);")):(i=a.def(),a(i,"=",f,".","elements",";","if(",i,"){",u,".bindBuffer(",34963,",",i,".buffer.buffer);}","else if(",c.vao,".currentVAO){",i,"=",t.shared.elements+".getElements("+c.vao,".currentVAO.elements);",rt?"":"if("+i+")"+u+".bindBuffer(34963,"+i+".buffer.buffer);","}")),i}(),d=i("primitive"),m=i("offset"),g=function(){var i=h.count,a=e;return i?((i.contextDep&&n.contextDynamic||i.propDep)&&(a=r),i=i.append(t,a)):i=a.def(f,".","count"),i}();if("number"==typeof g){if(0===g)return}else r("if(",g,"){"),r.exit("}");$&&(s=i("instances"),l=t.instancing);var v=p+".type",y=h.elements&&B(h.elements)&&!h.vaoActive;$&&("number"!=typeof s||0<=s)?"string"==typeof s?(r("if(",s,">0){"),a(),r("}else if(",s,"<0){"),o(),r("}")):a():o()}function q(t,e,r,n,i){return i=(e=_()).proc("body",i),$&&(e.instancing=i.def(e.shared.extensions,".angle_instanced_arrays")),t(e,i,r,n),e.compile().body}function Y(t,e,r,n){P(t,e),r.useVAO?r.drawVAO?e(t.shared.vao,".setVAO(",r.drawVAO.append(t,e),");"):e(t.shared.vao,".setVAO(",t.shared.vao,".targetVAO);"):(e(t.shared.vao,".setVAO(null);"),O(t,e,r,n.attributes,(function(){return!0}))),U(t,e,r,n.uniforms,(function(){return!0}),!1),V(t,e,e,r)}function W(t,e,r,n){function i(){return!0}t.batchId="a1",P(t,e),O(t,e,r,n.attributes,i),U(t,e,r,n.uniforms,i,!1),V(t,e,e,r)}function X(t,e,r,n){function i(t){return t.contextDep&&o||t.propDep}function a(t){return!i(t)}P(t,e);var o=r.contextDep,s=e.def(),l=e.def();t.shared.props=l,t.batchId=s;var c=t.scope(),u=t.scope();e(c.entry,"for(",s,"=0;",s,"<","a1",";++",s,"){",l,"=","a0","[",s,"];",u,"}",c.exit),r.needsContext&&S(t,u,r.context),r.needsFramebuffer&&E(t,u,r.framebuffer),C(t,u,r.state,i),r.profile&&i(r.profile)&&I(t,u,r,!1,!0),n?(r.useVAO?r.drawVAO?i(r.drawVAO)?u(t.shared.vao,".setVAO(",r.drawVAO.append(t,u),");"):c(t.shared.vao,".setVAO(",r.drawVAO.append(t,c),");"):c(t.shared.vao,".setVAO(",t.shared.vao,".targetVAO);"):(c(t.shared.vao,".setVAO(null);"),O(t,c,r,n.attributes,a),O(t,u,r,n.attributes,i)),U(t,c,r,n.uniforms,a,!1),U(t,u,r,n.uniforms,i,!0),V(t,c,u,r)):(e=t.global.def("{}"),n=r.shader.progVar.append(t,u),l=u.def(n,".id"),c=u.def(e,"[",l,"]"),u(t.shared.gl,".useProgram(",n,".program);","if(!",c,"){",c,"=",e,"[",l,"]=",t.link((function(e){return q(W,t,r,e,2)})),"(",n,");}",c,".call(this,a0[",s,"],",s,");"))}function Z(t,r){function n(e){var n=r.shader[e];n&&(n=n.append(t,i),isNaN(n)?i.set(a.shader,"."+e,n):i.set(a.shader,"."+e,t.link(n,{stable:!0})))}var i=t.proc("scope",3);t.batchId="a2";var a=t.shared,o=a.current;if(S(t,i,r.context),r.framebuffer&&r.framebuffer.append(t,i),R(Object.keys(r.state)).forEach((function(e){var n=r.state[e],o=n.append(t,i);g(o)?o.forEach((function(r,n){isNaN(r)?i.set(t.next[e],"["+n+"]",r):i.set(t.next[e],"["+n+"]",t.link(r,{stable:!0}))})):B(n)?i.set(a.next,"."+e,t.link(o,{stable:!0})):i.set(a.next,"."+e,o)})),I(t,i,r,!0,!0),["elements","offset","count","instances","primitive"].forEach((function(e){var n=r.draw[e];n&&(n=n.append(t,i),isNaN(n)?i.set(a.draw,"."+e,n):i.set(a.draw,"."+e,t.link(n),{stable:!0}))})),Object.keys(r.uniforms).forEach((function(n){var o=r.uniforms[n].append(t,i);Array.isArray(o)&&(o="["+o.map((function(e){return isNaN(e)?e:t.link(e,{stable:!0})}))+"]"),i.set(a.uniforms,"["+t.link(e.id(n),{stable:!0})+"]",o)})),Object.keys(r.attributes).forEach((function(e){var n=r.attributes[e].append(t,i),a=t.scopeAttrib(e);Object.keys(new K).forEach((function(t){i.set(a,"."+t,n[t])}))})),r.scopeVAO){var s=r.scopeVAO.append(t,i);isNaN(s)?i.set(a.vao,".targetVAO",s):i.set(a.vao,".targetVAO",t.link(s,{stable:!0}))}n("vert"),n("frag"),0<Object.keys(r.state).length&&(i(o,".dirty=true;"),i.exit(o,".dirty=true;")),i("a1(",t.shared.context,",a0,",t.batchId,");")}function J(t,e,r){var n=e.static[r];if(n&&function(t){if("object"==typeof t&&!g(t)){for(var e=Object.keys(t),r=0;r<e.length;++r)if(G.isDynamic(t[e[r]]))return!0;return!1}}(n)){var i=t.global,a=Object.keys(n),o=!1,s=!1,l=!1,c=t.global.def("{}");a.forEach((function(e){var r=n[e];if(G.isDynamic(r))"function"==typeof r&&(r=n[e]=G.unbox(r)),e=j(r,null),o=o||e.thisDep,l=l||e.propDep,s=s||e.contextDep;else{switch(i(c,".",e,"="),typeof r){case"number":i(r);break;case"string":i('"',r,'"');break;case"object":Array.isArray(r)&&i("[",r.join(),"]");break;default:i(t.link(r))}i(";")}})),e.dynamic[r]=new G.DynamicVariable(4,{thisDep:o,contextDep:s,propDep:l,ref:c,append:function(t,e){a.forEach((function(r){var i=n[r];G.isDynamic(i)&&(i=t.invoke(e,i),e(c,".",r,"=",i,";"))}))}}),delete e.static[r]}}var K=u.Record,Q={add:32774,subtract:32778,"reverse subtract":32779};r.ext_blend_minmax&&(Q.min=32775,Q.max=32776);var $=r.angle_instanced_arrays,et=r.webgl_draw_buffers,rt=r.oes_vertex_array_object,nt={dirty:!0,profile:v.profile},it={},ot=[],st={},lt={};x("dither",3024),x("blend.enable",3042),b("blend.color","blendColor",[0,0,0,0]),b("blend.equation","blendEquationSeparate",[32774,32774]),b("blend.func","blendFuncSeparate",[1,0,1,0]),x("depth.enable",2929,!0),b("depth.func","depthFunc",513),b("depth.range","depthRange",[0,1]),b("depth.mask","depthMask",!0),b("colorMask","colorMask",[!0,!0,!0,!0]),x("cull.enable",2884),b("cull.face","cullFace",1029),b("frontFace","frontFace",2305),b("lineWidth","lineWidth",1),x("polygonOffset.enable",32823),b("polygonOffset.offset","polygonOffset",[0,0]),x("sample.alpha",32926),x("sample.enable",32928),b("sample.coverage","sampleCoverage",[1,!1]),x("stencil.enable",2960),b("stencil.mask","stencilMask",-1),b("stencil.func","stencilFunc",[519,0,-1]),b("stencil.opFront","stencilOpSeparate",[1028,7680,7680,7680]),b("stencil.opBack","stencilOpSeparate",[1029,7680,7680,7680]),x("scissor.enable",3089),b("scissor.box","scissor",[0,0,t.drawingBufferWidth,t.drawingBufferHeight]),b("viewport","viewport",[0,0,t.drawingBufferWidth,t.drawingBufferHeight]);var ct={gl:t,context:p,strings:e,next:it,current:nt,draw:h,elements:o,buffer:i,shader:f,attributes:u.state,vao:u,uniforms:c,framebuffer:l,extensions:r,timer:d,isBufferArgs:D},ut={primTypes:at,compareFuncs:Et,blendFuncs:St,blendEquations:Q,stencilOps:Lt,glTypes:tt,orientationType:Ct};et&&(ut.backBuffer=[1029],ut.drawBuffer=a(n.maxDrawbuffers,(function(t){return 0===t?[0]:a(t,(function(t){return 36064+t}))})));var ft=0;return{next:it,current:nt,procs:function(){var t=_(),e=t.proc("poll"),i=t.proc("refresh"),o=t.block();e(o),i(o);var s,l=(f=t.shared).gl,c=f.next,u=f.current;o(u,".dirty=false;"),E(t,e),E(t,i,null,!0),$&&(s=t.link($)),r.oes_vertex_array_object&&i(t.link(r.oes_vertex_array_object),".bindVertexArrayOES(null);");var f=i.def(f.attributes),h=i.def(0),p=t.cond(h,".buffer");p.then(l,".enableVertexAttribArray(i);",l,".bindBuffer(",34962,",",h,".buffer.buffer);",l,".vertexAttribPointer(i,",h,".size,",h,".type,",h,".normalized,",h,".stride,",h,".offset);").else(l,".disableVertexAttribArray(i);",l,".vertexAttrib4f(i,",h,".x,",h,".y,",h,".z,",h,".w);",h,".buffer=null;");var d=t.link(n.maxAttributes,{stable:!0});return i("for(var i=0;i<",d,";++i){",h,"=",f,"[i];",p,"}"),$&&i("for(var i=0;i<",d,";++i){",s,".vertexAttribDivisorANGLE(i,",f,"[i].divisor);","}"),i(t.shared.vao,".currentVAO=null;",t.shared.vao,".setVAO(",t.shared.vao,".targetVAO);"),Object.keys(st).forEach((function(r){var n=st[r],a=o.def(c,".",r),s=t.block();s("if(",a,"){",l,".enable(",n,")}else{",l,".disable(",n,")}",u,".",r,"=",a,";"),i(s),e("if(",a,"!==",u,".",r,"){",s,"}")})),Object.keys(lt).forEach((function(r){var n,s,f=lt[r],h=nt[r],p=t.block();p(l,".",f,"("),g(h)?(f=h.length,n=t.global.def(c,".",r),s=t.global.def(u,".",r),p(a(f,(function(t){return n+"["+t+"]"})),");",a(f,(function(t){return s+"["+t+"]="+n+"["+t+"];"})).join("")),e("if(",a(f,(function(t){return n+"["+t+"]!=="+s+"["+t+"]"})).join("||"),"){",p,"}")):(n=o.def(c,".",r),s=o.def(u,".",r),p(n,");",u,".",r,"=",n,";"),e("if(",n,"!==",s,"){",p,"}")),i(p)})),t.compile()}(),compile:function(t,e,r,n,i){var a=_();a.stats=a.link(i),Object.keys(e.static).forEach((function(t){J(a,e,t)})),Mt.forEach((function(e){J(a,t,e)}));var o=M(t,e,r,n);return o.shader.program&&(o.shader.program.attributes.sort((function(t,e){return t.name<e.name?-1:1})),o.shader.program.uniforms.sort((function(t,e){return t.name<e.name?-1:1}))),function(t,e){var r=t.proc("draw",1);P(t,r),S(t,r,e.context),E(t,r,e.framebuffer),L(t,r,e),C(t,r,e.state),I(t,r,e,!1,!0);var n=e.shader.progVar.append(t,r);if(r(t.shared.gl,".useProgram(",n,".program);"),e.shader.program)Y(t,r,e,e.shader.program);else{r(t.shared.vao,".setVAO(null);");var i=t.global.def("{}"),a=r.def(n,".id"),o=r.def(i,"[",a,"]");r(t.cond(o).then(o,".call(this,a0);").else(o,"=",i,"[",a,"]=",t.link((function(r){return q(Y,t,e,r,1)})),"(",n,");",o,".call(this,a0);"))}0<Object.keys(e.state).length&&r(t.shared.current,".dirty=true;"),t.shared.vao&&r(t.shared.vao,".setVAO(null);")}(a,o),Z(a,o),function(t,e){function r(t){return t.contextDep&&i||t.propDep}var n=t.proc("batch",2);t.batchId="0",P(t,n);var i=!1,a=!0;Object.keys(e.context).forEach((function(t){i=i||e.context[t].propDep})),i||(S(t,n,e.context),a=!1);var o=!1;if((s=e.framebuffer)?(s.propDep?i=o=!0:s.contextDep&&i&&(o=!0),o||E(t,n,s)):E(t,n,null),e.state.viewport&&e.state.viewport.propDep&&(i=!0),L(t,n,e),C(t,n,e.state,(function(t){return!r(t)})),e.profile&&r(e.profile)||I(t,n,e,!1,"a1"),e.contextDep=i,e.needsContext=a,e.needsFramebuffer=o,(a=e.shader.progVar).contextDep&&i||a.propDep)X(t,n,e,null);else if(a=a.append(t,n),n(t.shared.gl,".useProgram(",a,".program);"),e.shader.program)X(t,n,e,e.shader.program);else{n(t.shared.vao,".setVAO(null);");var s=t.global.def("{}"),l=(o=n.def(a,".id"),n.def(s,"[",o,"]"));n(t.cond(l).then(l,".call(this,a0,a1);").else(l,"=",s,"[",o,"]=",t.link((function(r){return q(X,t,e,r,2)})),"(",a,");",l,".call(this,a0,a1);"))}0<Object.keys(e.state).length&&n(t.shared.current,".dirty=true;"),t.shared.vao&&n(t.shared.vao,".setVAO(null);")}(a,o),H(a.compile(),{destroy:function(){o.shader.program.destroy()}})}}}function V(t,e){for(var r=0;r<t.length;++r)if(t[r]===e)return r;return-1}var H=function(t,e){for(var r=Object.keys(e),n=0;n<r.length;++n)t[r[n]]=e[r[n]];return t},q=0,G={DynamicVariable:t,define:function(r,n){return new t(r,e(n+""))},isDynamic:function(e){return"function"==typeof e&&!e._reglType||e instanceof t},unbox:function e(r,n){return"function"==typeof r?new t(0,r):"number"==typeof r||"boolean"==typeof r?new t(5,r):Array.isArray(r)?new t(6,r.map((function(t,r){return e(t,n+"["+r+"]")}))):r instanceof t?r:void 0},accessor:e},Y={next:"function"==typeof requestAnimationFrame?function(t){return requestAnimationFrame(t)}:function(t){return setTimeout(t,16)},cancel:"function"==typeof cancelAnimationFrame?function(t){return cancelAnimationFrame(t)}:clearTimeout},W="undefined"!=typeof performance&&performance.now?function(){return performance.now()}:function(){return+new Date},X=s();X.zero=s();var Z=function(t,e){var r=1;e.ext_texture_filter_anisotropic&&(r=t.getParameter(34047));var n=1,i=1;e.webgl_draw_buffers&&(n=t.getParameter(34852),i=t.getParameter(36063));var a=!!e.oes_texture_float;if(a){a=t.createTexture(),t.bindTexture(3553,a),t.texImage2D(3553,0,6408,1,1,0,6408,5126,null);var o=t.createFramebuffer();if(t.bindFramebuffer(36160,o),t.framebufferTexture2D(36160,36064,3553,a,0),t.bindTexture(3553,null),36053!==t.checkFramebufferStatus(36160))a=!1;else{t.viewport(0,0,1,1),t.clearColor(1,0,0,1),t.clear(16384);var s=X.allocType(5126,4);t.readPixels(0,0,1,1,6408,5126,s),t.getError()?a=!1:(t.deleteFramebuffer(o),t.deleteTexture(a),a=1===s[0]),X.freeType(s)}}return s=!0,"undefined"!=typeof navigator&&(/MSIE/.test(navigator.userAgent)||/Trident\//.test(navigator.appVersion)||/Edge/.test(navigator.userAgent))||(s=t.createTexture(),o=X.allocType(5121,36),t.activeTexture(33984),t.bindTexture(34067,s),t.texImage2D(34069,0,6408,3,3,0,6408,5121,o),X.freeType(o),t.bindTexture(34067,null),t.deleteTexture(s),s=!t.getError()),{colorBits:[t.getParameter(3410),t.getParameter(3411),t.getParameter(3412),t.getParameter(3413)],depthBits:t.getParameter(3414),stencilBits:t.getParameter(3415),subpixelBits:t.getParameter(3408),extensions:Object.keys(e).filter((function(t){return!!e[t]})),maxAnisotropic:r,maxDrawbuffers:n,maxColorAttachments:i,pointSizeDims:t.getParameter(33901),lineWidthDims:t.getParameter(33902),maxViewportDims:t.getParameter(3386),maxCombinedTextureUnits:t.getParameter(35661),maxCubeMapSize:t.getParameter(34076),maxRenderbufferSize:t.getParameter(34024),maxTextureUnits:t.getParameter(34930),maxTextureSize:t.getParameter(3379),maxAttributes:t.getParameter(34921),maxVertexUniforms:t.getParameter(36347),maxVertexTextureUnits:t.getParameter(35660),maxVaryingVectors:t.getParameter(36348),maxFragmentUniforms:t.getParameter(36349),glsl:t.getParameter(35724),renderer:t.getParameter(7937),vendor:t.getParameter(7936),version:t.getParameter(7938),readFloat:a,npotTextureCube:s}},J=function(t){return t instanceof Uint8Array||t instanceof Uint16Array||t instanceof Uint32Array||t instanceof Int8Array||t instanceof Int16Array||t instanceof Int32Array||t instanceof Float32Array||t instanceof Float64Array||t instanceof Uint8ClampedArray},K=function(t){return Object.keys(t).map((function(e){return t[e]}))},Q={shape:function(t){for(var e=[];t.length;t=t[0])e.push(t.length);return e},flatten:function(t,e,r,n){var i=1;if(e.length)for(var a=0;a<e.length;++a)i*=e[a];else i=0;switch(r=n||X.allocType(r,i),e.length){case 0:break;case 1:for(n=e[0],e=0;e<n;++e)r[e]=t[e];break;case 2:for(n=e[0],e=e[1],a=i=0;a<n;++a)for(var o=t[a],s=0;s<e;++s)r[i++]=o[s];break;case 3:c(t,e[0],e[1],e[2],r,0);break;default:!function t(e,r,n,i,a){for(var o=1,s=n+1;s<r.length;++s)o*=r[s];var l=r[n];if(4==r.length-n){var u=r[n+1],f=r[n+2];for(r=r[n+3],s=0;s<l;++s)c(e[s],u,f,r,i,a),a+=o}else for(s=0;s<l;++s)t(e[s],r,n+1,i,a),a+=o}(t,e,0,r,0)}return r}},$={"[object Int8Array]":5120,"[object Int16Array]":5122,"[object Int32Array]":5124,"[object Uint8Array]":5121,"[object Uint8ClampedArray]":5121,"[object Uint16Array]":5123,"[object Uint32Array]":5125,"[object Float32Array]":5126,"[object Float64Array]":5121,"[object ArrayBuffer]":5121},tt={int8:5120,int16:5122,int32:5124,uint8:5121,uint16:5123,uint32:5125,float:5126,float32:5126},et={dynamic:35048,stream:35040,static:35044},rt=Q.flatten,nt=Q.shape,it=[];it[5120]=1,it[5122]=2,it[5124]=4,it[5121]=1,it[5123]=2,it[5125]=4,it[5126]=4;var at={points:0,point:0,lines:1,line:1,triangles:4,triangle:4,"line loop":2,"line strip":3,"triangle strip":5,"triangle fan":6},ot=new Float32Array(1),st=new Uint32Array(ot.buffer),lt=[9984,9986,9985,9987],ct=[0,6409,6410,6407,6408],ut={};ut[6409]=ut[6406]=ut[6402]=1,ut[34041]=ut[6410]=2,ut[6407]=ut[35904]=3,ut[6408]=ut[35906]=4;var ft=v("HTMLCanvasElement"),ht=v("OffscreenCanvas"),pt=v("CanvasRenderingContext2D"),dt=v("ImageBitmap"),mt=v("HTMLImageElement"),gt=v("HTMLVideoElement"),vt=Object.keys($).concat([ft,ht,pt,dt,mt,gt]),yt=[];yt[5121]=1,yt[5126]=4,yt[36193]=2,yt[5123]=2,yt[5125]=4;var xt=[];xt[32854]=2,xt[32855]=2,xt[36194]=2,xt[34041]=4,xt[33776]=.5,xt[33777]=.5,xt[33778]=1,xt[33779]=1,xt[35986]=.5,xt[35987]=1,xt[34798]=1,xt[35840]=.5,xt[35841]=.25,xt[35842]=.5,xt[35843]=.25,xt[36196]=.5;var bt=[];bt[32854]=2,bt[32855]=2,bt[36194]=2,bt[33189]=2,bt[36168]=1,bt[34041]=4,bt[35907]=4,bt[34836]=16,bt[34842]=8,bt[34843]=6;var _t=function(t,e,r,n,i){function a(t){this.id=c++,this.refCount=1,this.renderbuffer=t,this.format=32854,this.height=this.width=0,i.profile&&(this.stats={size:0})}function o(e){var r=e.renderbuffer;t.bindRenderbuffer(36161,null),t.deleteRenderbuffer(r),e.renderbuffer=null,e.refCount=0,delete u[e.id],n.renderbufferCount--}var s={rgba4:32854,rgb565:36194,"rgb5 a1":32855,depth:33189,stencil:36168,"depth stencil":34041};e.ext_srgb&&(s.srgba=35907),e.ext_color_buffer_half_float&&(s.rgba16f=34842,s.rgb16f=34843),e.webgl_color_buffer_float&&(s.rgba32f=34836);var l=[];Object.keys(s).forEach((function(t){l[s[t]]=t}));var c=0,u={};return a.prototype.decRef=function(){0>=--this.refCount&&o(this)},i.profile&&(n.getTotalRenderbufferSize=function(){var t=0;return Object.keys(u).forEach((function(e){t+=u[e].stats.size})),t}),{create:function(e,r){function o(e,r){var n=0,a=0,u=32854;if("object"==typeof e&&e?("shape"in e?(n=0|(a=e.shape)[0],a=0|a[1]):("radius"in e&&(n=a=0|e.radius),"width"in e&&(n=0|e.width),"height"in e&&(a=0|e.height)),"format"in e&&(u=s[e.format])):"number"==typeof e?(n=0|e,a="number"==typeof r?0|r:n):e||(n=a=1),n!==c.width||a!==c.height||u!==c.format)return o.width=c.width=n,o.height=c.height=a,c.format=u,t.bindRenderbuffer(36161,c.renderbuffer),t.renderbufferStorage(36161,u,n,a),i.profile&&(c.stats.size=bt[c.format]*c.width*c.height),o.format=l[c.format],o}var c=new a(t.createRenderbuffer());return u[c.id]=c,n.renderbufferCount++,o(e,r),o.resize=function(e,r){var n=0|e,a=0|r||n;return n===c.width&&a===c.height||(o.width=c.width=n,o.height=c.height=a,t.bindRenderbuffer(36161,c.renderbuffer),t.renderbufferStorage(36161,c.format,n,a),i.profile&&(c.stats.size=bt[c.format]*c.width*c.height)),o},o._reglType="renderbuffer",o._renderbuffer=c,i.profile&&(o.stats=c.stats),o.destroy=function(){c.decRef()},o},clear:function(){K(u).forEach(o)},restore:function(){K(u).forEach((function(e){e.renderbuffer=t.createRenderbuffer(),t.bindRenderbuffer(36161,e.renderbuffer),t.renderbufferStorage(36161,e.format,e.width,e.height)})),t.bindRenderbuffer(36161,null)}}},wt=[];wt[6408]=4,wt[6407]=3;var Tt=[];Tt[5121]=1,Tt[5126]=4,Tt[36193]=2;var kt=[1116352408,1899447441,-1245643825,-373957723,961987163,1508970993,-1841331548,-1424204075,-670586216,310598401,607225278,1426881987,1925078388,-2132889090,-1680079193,-1046744716,-459576895,-272742522,264347078,604807628,770255983,1249150122,1555081692,1996064986,-1740746414,-1473132947,-1341970488,-1084653625,-958395405,-710438585,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,-2117940946,-1838011259,-1564481375,-1474664885,-1035236496,-949202525,-778901479,-694614492,-200395387,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,-2067236844,-1933114872,-1866530822,-1538233109,-1090935817,-965641998],At=["x","y","z","w"],Mt="blend.func blend.equation stencil.func stencil.opFront stencil.opBack sample.coverage viewport scissor.box polygonOffset.offset".split(" "),St={0:0,1:1,zero:0,one:1,"src color":768,"one minus src color":769,"src alpha":770,"one minus src alpha":771,"dst color":774,"one minus dst color":775,"dst alpha":772,"one minus dst alpha":773,"constant color":32769,"one minus constant color":32770,"constant alpha":32771,"one minus constant alpha":32772,"src alpha saturate":776},Et={never:512,less:513,"<":513,equal:514,"=":514,"==":514,"===":514,lequal:515,"<=":515,greater:516,">":516,notequal:517,"!=":517,"!==":517,gequal:518,">=":518,always:519},Lt={0:0,zero:0,keep:7680,replace:7681,increment:7682,decrement:7683,"increment wrap":34055,"decrement wrap":34056,invert:5386},Ct={cw:2304,ccw:2305},Pt=new F(!1,!1,!1,(function(){}));return function(t){function e(){if(0===K.length)T&&T.update(),et=null;else{et=Y.next(e),f();for(var t=K.length-1;0<=t;--t){var r=K[t];r&&r(I,null,0)}g.flush(),T&&T.update()}}function r(){!et&&0<K.length&&(et=Y.next(e))}function n(){et&&(Y.cancel(e),et=null)}function a(t){t.preventDefault(),n(),Q.forEach((function(t){t()}))}function o(t){g.getError(),y.restore(),F.restore(),z.restore(),B.restore(),N.restore(),j.restore(),R.restore(),T&&T.restore(),q.procs.refresh(),r(),$.forEach((function(t){t()}))}function s(t){function e(t,e){var r={},n={};return Object.keys(t).forEach((function(i){var a=t[i];if(G.isDynamic(a))n[i]=G.unbox(a,i);else{if(e&&Array.isArray(a))for(var o=0;o<a.length;++o)if(G.isDynamic(a[o]))return void(n[i]=G.unbox(a,i));r[i]=a}})),{dynamic:n,static:r}}var r=e(t.context||{},!0),n=e(t.uniforms||{},!0),i=e(t.attributes||{},!1);t=e(function(t){function e(t){if(t in r){var e=r[t];delete r[t],Object.keys(e).forEach((function(n){r[t+"."+n]=e[n]}))}}var r=H({},t);return delete r.uniforms,delete r.attributes,delete r.context,delete r.vao,"stencil"in r&&r.stencil.op&&(r.stencil.opBack=r.stencil.opFront=r.stencil.op,delete r.stencil.op),e("blend"),e("depth"),e("cull"),e("stencil"),e("polygonOffset"),e("scissor"),e("sample"),"vao"in t&&(r.vao=t.vao),r}(t),!1);var a={gpuTime:0,cpuTime:0,count:0},o=q.compile(t,i,n,r,a),s=o.draw,l=o.batch,c=o.scope,u=[];return H((function(t,e){var r;if("function"==typeof t)return c.call(this,null,t,0);if("function"==typeof e)if("number"==typeof t)for(r=0;r<t;++r)c.call(this,null,e,r);else{if(!Array.isArray(t))return c.call(this,t,e,0);for(r=0;r<t.length;++r)c.call(this,t[r],e,r)}else if("number"==typeof t){if(0<t)return l.call(this,function(t){for(;u.length<t;)u.push(null);return u}(0|t),0|t)}else{if(!Array.isArray(t))return s.call(this,t);if(t.length)return l.call(this,t,t.length)}}),{stats:a,destroy:function(){o.destroy()}})}function l(t,e){var r=0;q.procs.poll();var n=e.color;n&&(g.clearColor(+n[0]||0,+n[1]||0,+n[2]||0,+n[3]||0),r|=16384),"depth"in e&&(g.clearDepth(+e.depth),r|=256),"stencil"in e&&(g.clearStencil(0|e.stencil),r|=1024),g.clear(r)}function c(t){return K.push(t),r(),{cancel:function(){var e=V(K,t);K[e]=function t(){var e=V(K,t);K[e]=K[K.length-1],--K.length,0>=K.length&&n()}}}}function u(){var t=X.viewport,e=X.scissor_box;t[0]=t[1]=e[0]=e[1]=0,I.viewportWidth=I.framebufferWidth=I.drawingBufferWidth=t[2]=e[2]=g.drawingBufferWidth,I.viewportHeight=I.framebufferHeight=I.drawingBufferHeight=t[3]=e[3]=g.drawingBufferHeight}function f(){I.tick+=1,I.time=m(),u(),q.procs.poll()}function h(){B.refresh(),u(),q.procs.refresh(),T&&T.update()}function m(){return(W()-M)/1e3}if(!(t=i(t)))return null;var g=t.gl,v=g.getContextAttributes();g.isContextLost();var y=function(t,e){function r(e){var r;e=e.toLowerCase();try{r=n[e]=t.getExtension(e)}catch(t){}return!!r}for(var n={},i=0;i<e.extensions.length;++i){var a=e.extensions[i];if(!r(a))return e.onDestroy(),e.onDone('"'+a+'" extension is not supported by the current WebGL context, try upgrading your system or a different browser'),null}return e.optionalExtensions.forEach(r),{extensions:n,restore:function(){Object.keys(n).forEach((function(t){if(n[t]&&!r(t))throw Error("(regl): error restoring extension "+t)}))}}}(g,t);if(!y)return null;var x=function(){var t={"":0},e=[""];return{id:function(r){var n=t[r];return n||(n=t[r]=e.length,e.push(r),n)},str:function(t){return e[t]}}}(),b={vaoCount:0,bufferCount:0,elementsCount:0,framebufferCount:0,shaderCount:0,textureCount:0,cubeCount:0,renderbufferCount:0,maxTextureUnits:0},_=t.cachedCode||{},w=y.extensions,T=function(t,e){function r(){this.endQueryIndex=this.startQueryIndex=-1,this.sum=0,this.stats=null}function n(t,e,n){var i=o.pop()||new r;i.startQueryIndex=t,i.endQueryIndex=e,i.sum=0,i.stats=n,s.push(i)}if(!e.ext_disjoint_timer_query)return null;var i=[],a=[],o=[],s=[],l=[],c=[];return{beginQuery:function(t){var r=i.pop()||e.ext_disjoint_timer_query.createQueryEXT();e.ext_disjoint_timer_query.beginQueryEXT(35007,r),a.push(r),n(a.length-1,a.length,t)},endQuery:function(){e.ext_disjoint_timer_query.endQueryEXT(35007)},pushScopeStats:n,update:function(){var t,r;if(0!==(t=a.length)){c.length=Math.max(c.length,t+1),l.length=Math.max(l.length,t+1),l[0]=0;var n=c[0]=0;for(r=t=0;r<a.length;++r){var u=a[r];e.ext_disjoint_timer_query.getQueryObjectEXT(u,34919)?(n+=e.ext_disjoint_timer_query.getQueryObjectEXT(u,34918),i.push(u)):a[t++]=u,l[r+1]=n,c[r+1]=t}for(a.length=t,r=t=0;r<s.length;++r){var f=(n=s[r]).startQueryIndex;u=n.endQueryIndex;n.sum+=l[u]-l[f],f=c[f],(u=c[u])===f?(n.stats.gpuTime+=n.sum/1e6,o.push(n)):(n.startQueryIndex=f,n.endQueryIndex=u,s[t++]=n)}s.length=t}},getNumPendingQueries:function(){return a.length},clear:function(){i.push.apply(i,a);for(var t=0;t<i.length;t++)e.ext_disjoint_timer_query.deleteQueryEXT(i[t]);a.length=0,i.length=0},restore:function(){a.length=0,i.length=0}}}(0,w),M=W(),C=g.drawingBufferWidth,P=g.drawingBufferHeight,I={tick:0,time:0,viewportWidth:C,viewportHeight:P,framebufferWidth:C,framebufferHeight:P,drawingBufferWidth:C,drawingBufferHeight:P,pixelRatio:t.pixelRatio},O=(C={elements:null,primitive:4,count:-1,offset:0,instances:-1},Z(g,w)),z=p(g,b,t,(function(t){return R.destroyBuffer(t)})),D=d(g,w,z,b),R=S(g,w,O,b,z,D,C),F=E(g,x,b,t),B=k(g,w,O,(function(){q.procs.poll()}),I,b,t),N=_t(g,w,0,b,t),j=A(g,w,O,B,N,b),q=U(g,x,w,O,z,D,0,j,{},R,F,C,I,T,_,t),X=(x=L(g,j,q.procs.poll,I),q.next),J=g.canvas,K=[],Q=[],$=[],tt=[t.onDestroy],et=null;J&&(J.addEventListener("webglcontextlost",a,!1),J.addEventListener("webglcontextrestored",o,!1));var rt=j.setFBO=s({framebuffer:G.define.call(null,1,"framebuffer")});return h(),v=H(s,{clear:function(t){if("framebuffer"in t)if(t.framebuffer&&"framebufferCube"===t.framebuffer_reglType)for(var e=0;6>e;++e)rt(H({framebuffer:t.framebuffer.faces[e]},t),l);else rt(t,l);else l(0,t)},prop:G.define.bind(null,1),context:G.define.bind(null,2),this:G.define.bind(null,3),draw:s({}),buffer:function(t){return z.create(t,34962,!1,!1)},elements:function(t){return D.create(t,!1)},texture:B.create2D,cube:B.createCube,renderbuffer:N.create,framebuffer:j.create,framebufferCube:j.createCube,vao:R.createVAO,attributes:v,frame:c,on:function(t,e){var r;switch(t){case"frame":return c(e);case"lost":r=Q;break;case"restore":r=$;break;case"destroy":r=tt}return r.push(e),{cancel:function(){for(var t=0;t<r.length;++t)if(r[t]===e){r[t]=r[r.length-1],r.pop();break}}}},limits:O,hasExtension:function(t){return 0<=O.extensions.indexOf(t.toLowerCase())},read:x,destroy:function(){K.length=0,n(),J&&(J.removeEventListener("webglcontextlost",a),J.removeEventListener("webglcontextrestored",o)),F.clear(),j.clear(),N.clear(),R.clear(),B.clear(),D.clear(),z.clear(),T&&T.clear(),tt.forEach((function(t){t()}))},_gl:g,_refresh:h,poll:function(){f(),T&&T.update()},now:m,stats:b,getCachedCode:function(){return _},preloadCachedCode:function(t){Object.entries(t).forEach((function(t){_[t[0]]=t[1]}))}}),t.onDone(null,v),v}}))},{}],284:[function(t,e,r){var n=t("buffer"),i=n.Buffer;function a(t,e){for(var r in t)e[r]=t[r]}function o(t,e,r){return i(t,e,r)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?e.exports=n:(a(n,r),r.Buffer=o),o.prototype=Object.create(i.prototype),a(i,o),o.from=function(t,e,r){if("number"==typeof t)throw new TypeError("Argument must not be a number");return i(t,e,r)},o.alloc=function(t,e,r){if("number"!=typeof t)throw new TypeError("Argument must be a number");var n=i(t);return void 0!==e?"string"==typeof r?n.fill(e,r):n.fill(e):n.fill(0),n},o.allocUnsafe=function(t){if("number"!=typeof t)throw new TypeError("Argument must be a number");return i(t)},o.allocUnsafeSlow=function(t){if("number"!=typeof t)throw new TypeError("Argument must be a number");return n.SlowBuffer(t)}},{buffer:85}],285:[function(t,e,r){e.exports=i;var n=t("events").EventEmitter;function i(){n.call(this)}t("inherits")(i,n),i.Readable=t("readable-stream/lib/_stream_readable.js"),i.Writable=t("readable-stream/lib/_stream_writable.js"),i.Duplex=t("readable-stream/lib/_stream_duplex.js"),i.Transform=t("readable-stream/lib/_stream_transform.js"),i.PassThrough=t("readable-stream/lib/_stream_passthrough.js"),i.finished=t("readable-stream/lib/internal/streams/end-of-stream.js"),i.pipeline=t("readable-stream/lib/internal/streams/pipeline.js"),i.Stream=i,i.prototype.pipe=function(t,e){var r=this;function i(e){t.writable&&!1===t.write(e)&&r.pause&&r.pause()}function a(){r.readable&&r.resume&&r.resume()}r.on("data",i),t.on("drain",a),t._isStdio||e&&!1===e.end||(r.on("end",s),r.on("close",l));var o=!1;function s(){o||(o=!0,t.end())}function l(){o||(o=!0,"function"==typeof t.destroy&&t.destroy())}function c(t){if(u(),0===n.listenerCount(this,"error"))throw t}function u(){r.removeListener("data",i),t.removeListener("drain",a),r.removeListener("end",s),r.removeListener("close",l),r.removeListener("error",c),t.removeListener("error",c),r.removeListener("end",u),r.removeListener("close",u),t.removeListener("close",u)}return r.on("error",c),t.on("error",c),r.on("end",u),r.on("close",u),t.on("close",u),t.emit("pipe",r),t}},{events:84,inherits:231,"readable-stream/lib/_stream_duplex.js":287,"readable-stream/lib/_stream_passthrough.js":288,"readable-stream/lib/_stream_readable.js":289,"readable-stream/lib/_stream_transform.js":290,"readable-stream/lib/_stream_writable.js":291,"readable-stream/lib/internal/streams/end-of-stream.js":295,"readable-stream/lib/internal/streams/pipeline.js":297}],286:[function(t,e,r){"use strict";var n={};function i(t,e,r){r||(r=Error);var i=function(t){var r,n;function i(r,n,i){return t.call(this,function(t,r,n){return"string"==typeof e?e:e(t,r,n)}(r,n,i))||this}return n=t,(r=i).prototype=Object.create(n.prototype),r.prototype.constructor=r,r.__proto__=n,i}(r);i.prototype.name=r.name,i.prototype.code=t,n[t]=i}function a(t,e){if(Array.isArray(t)){var r=t.length;return t=t.map((function(t){return String(t)})),r>2?"one of ".concat(e," ").concat(t.slice(0,r-1).join(", "),", or ")+t[r-1]:2===r?"one of ".concat(e," ").concat(t[0]," or ").concat(t[1]):"of ".concat(e," ").concat(t[0])}return"of ".concat(e," ").concat(String(t))}i("ERR_INVALID_OPT_VALUE",(function(t,e){return'The value "'+e+'" is invalid for option "'+t+'"'}),TypeError),i("ERR_INVALID_ARG_TYPE",(function(t,e,r){var n,i,o,s;if("string"==typeof e&&(i="not ",e.substr(!o||o<0?0:+o,i.length)===i)?(n="must not be",e=e.replace(/^not /,"")):n="must be",function(t,e,r){return(void 0===r||r>t.length)&&(r=t.length),t.substring(r-e.length,r)===e}(t," argument"))s="The ".concat(t," ").concat(n," ").concat(a(e,"type"));else{var l=function(t,e,r){return"number"!=typeof r&&(r=0),!(r+e.length>t.length)&&-1!==t.indexOf(e,r)}(t,".")?"property":"argument";s='The "'.concat(t,'" ').concat(l," ").concat(n," ").concat(a(e,"type"))}return s+=". Received type ".concat(typeof r)}),TypeError),i("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),i("ERR_METHOD_NOT_IMPLEMENTED",(function(t){return"The "+t+" method is not implemented"})),i("ERR_STREAM_PREMATURE_CLOSE","Premature close"),i("ERR_STREAM_DESTROYED",(function(t){return"Cannot call "+t+" after a stream was destroyed"})),i("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),i("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),i("ERR_STREAM_WRITE_AFTER_END","write after end"),i("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),i("ERR_UNKNOWN_ENCODING",(function(t){return"Unknown encoding: "+t}),TypeError),i("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),e.exports.codes=n},{}],287:[function(t,e,r){(function(r){(function(){"use strict";var n=Object.keys||function(t){var e=[];for(var r in t)e.push(r);return e};e.exports=c;var i=t("./_stream_readable"),a=t("./_stream_writable");t("inherits")(c,i);for(var o=n(a.prototype),s=0;s<o.length;s++){var l=o[s];c.prototype[l]||(c.prototype[l]=a.prototype[l])}function c(t){if(!(this instanceof c))return new c(t);i.call(this,t),a.call(this,t),this.allowHalfOpen=!0,t&&(!1===t.readable&&(this.readable=!1),!1===t.writable&&(this.writable=!1),!1===t.allowHalfOpen&&(this.allowHalfOpen=!1,this.once("end",u)))}function u(){this._writableState.ended||r.nextTick(f,this)}function f(t){t.end()}Object.defineProperty(c.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(c.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(c.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(c.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed&&this._writableState.destroyed)},set:function(t){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=t,this._writableState.destroyed=t)}})}).call(this)}).call(this,t("_process"))},{"./_stream_readable":289,"./_stream_writable":291,_process:277,inherits:231}],288:[function(t,e,r){"use strict";e.exports=i;var n=t("./_stream_transform");function i(t){if(!(this instanceof i))return new i(t);n.call(this,t)}t("inherits")(i,n),i.prototype._transform=function(t,e,r){r(null,t)}},{"./_stream_transform":290,inherits:231}],289:[function(t,e,r){(function(r,n){(function(){"use strict";var i;e.exports=A,A.ReadableState=k;t("events").EventEmitter;var a=function(t,e){return t.listeners(e).length},o=t("./internal/streams/stream"),s=t("buffer").Buffer,l=n.Uint8Array||function(){};var c,u=t("util");c=u&&u.debuglog?u.debuglog("stream"):function(){};var f,h,p,d=t("./internal/streams/buffer_list"),m=t("./internal/streams/destroy"),g=t("./internal/streams/state").getHighWaterMark,v=t("../errors").codes,y=v.ERR_INVALID_ARG_TYPE,x=v.ERR_STREAM_PUSH_AFTER_EOF,b=v.ERR_METHOD_NOT_IMPLEMENTED,_=v.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;t("inherits")(A,o);var w=m.errorOrDestroy,T=["error","close","destroy","pause","resume"];function k(e,r,n){i=i||t("./_stream_duplex"),e=e||{},"boolean"!=typeof n&&(n=r instanceof i),this.objectMode=!!e.objectMode,n&&(this.objectMode=this.objectMode||!!e.readableObjectMode),this.highWaterMark=g(this,e,"readableHighWaterMark",n),this.buffer=new d,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(f||(f=t("string_decoder/").StringDecoder),this.decoder=new f(e.encoding),this.encoding=e.encoding)}function A(e){if(i=i||t("./_stream_duplex"),!(this instanceof A))return new A(e);var r=this instanceof i;this._readableState=new k(e,this,r),this.readable=!0,e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy)),o.call(this)}function M(t,e,r,n,i){c("readableAddChunk",e);var a,o=t._readableState;if(null===e)o.reading=!1,function(t,e){if(c("onEofChunk"),e.ended)return;if(e.decoder){var r=e.decoder.end();r&&r.length&&(e.buffer.push(r),e.length+=e.objectMode?1:r.length)}e.ended=!0,e.sync?L(t):(e.needReadable=!1,e.emittedReadable||(e.emittedReadable=!0,C(t)))}(t,o);else if(i||(a=function(t,e){var r;n=e,s.isBuffer(n)||n instanceof l||"string"==typeof e||void 0===e||t.objectMode||(r=new y("chunk",["string","Buffer","Uint8Array"],e));var n;return r}(o,e)),a)w(t,a);else if(o.objectMode||e&&e.length>0)if("string"==typeof e||o.objectMode||Object.getPrototypeOf(e)===s.prototype||(e=function(t){return s.from(t)}(e)),n)o.endEmitted?w(t,new _):S(t,o,e,!0);else if(o.ended)w(t,new x);else{if(o.destroyed)return!1;o.reading=!1,o.decoder&&!r?(e=o.decoder.write(e),o.objectMode||0!==e.length?S(t,o,e,!1):P(t,o)):S(t,o,e,!1)}else n||(o.reading=!1,P(t,o));return!o.ended&&(o.length<o.highWaterMark||0===o.length)}function S(t,e,r,n){e.flowing&&0===e.length&&!e.sync?(e.awaitDrain=0,t.emit("data",r)):(e.length+=e.objectMode?1:r.length,n?e.buffer.unshift(r):e.buffer.push(r),e.needReadable&&L(t)),P(t,e)}Object.defineProperty(A.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(t){this._readableState&&(this._readableState.destroyed=t)}}),A.prototype.destroy=m.destroy,A.prototype._undestroy=m.undestroy,A.prototype._destroy=function(t,e){e(t)},A.prototype.push=function(t,e){var r,n=this._readableState;return n.objectMode?r=!0:"string"==typeof t&&((e=e||n.defaultEncoding)!==n.encoding&&(t=s.from(t,e),e=""),r=!0),M(this,t,e,!1,r)},A.prototype.unshift=function(t){return M(this,t,null,!0,!1)},A.prototype.isPaused=function(){return!1===this._readableState.flowing},A.prototype.setEncoding=function(e){f||(f=t("string_decoder/").StringDecoder);var r=new f(e);this._readableState.decoder=r,this._readableState.encoding=this._readableState.decoder.encoding;for(var n=this._readableState.buffer.head,i="";null!==n;)i+=r.write(n.data),n=n.next;return this._readableState.buffer.clear(),""!==i&&this._readableState.buffer.push(i),this._readableState.length=i.length,this};function E(t,e){return t<=0||0===e.length&&e.ended?0:e.objectMode?1:t!=t?e.flowing&&e.length?e.buffer.head.data.length:e.length:(t>e.highWaterMark&&(e.highWaterMark=function(t){return t>=1073741824?t=1073741824:(t--,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t++),t}(t)),t<=e.length?t:e.ended?e.length:(e.needReadable=!0,0))}function L(t){var e=t._readableState;c("emitReadable",e.needReadable,e.emittedReadable),e.needReadable=!1,e.emittedReadable||(c("emitReadable",e.flowing),e.emittedReadable=!0,r.nextTick(C,t))}function C(t){var e=t._readableState;c("emitReadable_",e.destroyed,e.length,e.ended),e.destroyed||!e.length&&!e.ended||(t.emit("readable"),e.emittedReadable=!1),e.needReadable=!e.flowing&&!e.ended&&e.length<=e.highWaterMark,R(t)}function P(t,e){e.readingMore||(e.readingMore=!0,r.nextTick(I,t,e))}function I(t,e){for(;!e.reading&&!e.ended&&(e.length<e.highWaterMark||e.flowing&&0===e.length);){var r=e.length;if(c("maybeReadMore read 0"),t.read(0),r===e.length)break}e.readingMore=!1}function O(t){var e=t._readableState;e.readableListening=t.listenerCount("readable")>0,e.resumeScheduled&&!e.paused?e.flowing=!0:t.listenerCount("data")>0&&t.resume()}function z(t){c("readable nexttick read 0"),t.read(0)}function D(t,e){c("resume",e.reading),e.reading||t.read(0),e.resumeScheduled=!1,t.emit("resume"),R(t),e.flowing&&!e.reading&&t.read(0)}function R(t){var e=t._readableState;for(c("flow",e.flowing);e.flowing&&null!==t.read(););}function F(t,e){return 0===e.length?null:(e.objectMode?r=e.buffer.shift():!t||t>=e.length?(r=e.decoder?e.buffer.join(""):1===e.buffer.length?e.buffer.first():e.buffer.concat(e.length),e.buffer.clear()):r=e.buffer.consume(t,e.decoder),r);var r}function B(t){var e=t._readableState;c("endReadable",e.endEmitted),e.endEmitted||(e.ended=!0,r.nextTick(N,e,t))}function N(t,e){if(c("endReadableNT",t.endEmitted,t.length),!t.endEmitted&&0===t.length&&(t.endEmitted=!0,e.readable=!1,e.emit("end"),t.autoDestroy)){var r=e._writableState;(!r||r.autoDestroy&&r.finished)&&e.destroy()}}function j(t,e){for(var r=0,n=t.length;r<n;r++)if(t[r]===e)return r;return-1}A.prototype.read=function(t){c("read",t),t=parseInt(t,10);var e=this._readableState,r=t;if(0!==t&&(e.emittedReadable=!1),0===t&&e.needReadable&&((0!==e.highWaterMark?e.length>=e.highWaterMark:e.length>0)||e.ended))return c("read: emitReadable",e.length,e.ended),0===e.length&&e.ended?B(this):L(this),null;if(0===(t=E(t,e))&&e.ended)return 0===e.length&&B(this),null;var n,i=e.needReadable;return c("need readable",i),(0===e.length||e.length-t<e.highWaterMark)&&c("length less than watermark",i=!0),e.ended||e.reading?c("reading or ended",i=!1):i&&(c("do read"),e.reading=!0,e.sync=!0,0===e.length&&(e.needReadable=!0),this._read(e.highWaterMark),e.sync=!1,e.reading||(t=E(r,e))),null===(n=t>0?F(t,e):null)?(e.needReadable=e.length<=e.highWaterMark,t=0):(e.length-=t,e.awaitDrain=0),0===e.length&&(e.ended||(e.needReadable=!0),r!==t&&e.ended&&B(this)),null!==n&&this.emit("data",n),n},A.prototype._read=function(t){w(this,new b("_read()"))},A.prototype.pipe=function(t,e){var n=this,i=this._readableState;switch(i.pipesCount){case 0:i.pipes=t;break;case 1:i.pipes=[i.pipes,t];break;default:i.pipes.push(t)}i.pipesCount+=1,c("pipe count=%d opts=%j",i.pipesCount,e);var o=(!e||!1!==e.end)&&t!==r.stdout&&t!==r.stderr?l:g;function s(e,r){c("onunpipe"),e===n&&r&&!1===r.hasUnpiped&&(r.hasUnpiped=!0,c("cleanup"),t.removeListener("close",d),t.removeListener("finish",m),t.removeListener("drain",u),t.removeListener("error",p),t.removeListener("unpipe",s),n.removeListener("end",l),n.removeListener("end",g),n.removeListener("data",h),f=!0,!i.awaitDrain||t._writableState&&!t._writableState.needDrain||u())}function l(){c("onend"),t.end()}i.endEmitted?r.nextTick(o):n.once("end",o),t.on("unpipe",s);var u=function(t){return function(){var e=t._readableState;c("pipeOnDrain",e.awaitDrain),e.awaitDrain&&e.awaitDrain--,0===e.awaitDrain&&a(t,"data")&&(e.flowing=!0,R(t))}}(n);t.on("drain",u);var f=!1;function h(e){c("ondata");var r=t.write(e);c("dest.write",r),!1===r&&((1===i.pipesCount&&i.pipes===t||i.pipesCount>1&&-1!==j(i.pipes,t))&&!f&&(c("false write response, pause",i.awaitDrain),i.awaitDrain++),n.pause())}function p(e){c("onerror",e),g(),t.removeListener("error",p),0===a(t,"error")&&w(t,e)}function d(){t.removeListener("finish",m),g()}function m(){c("onfinish"),t.removeListener("close",d),g()}function g(){c("unpipe"),n.unpipe(t)}return n.on("data",h),function(t,e,r){if("function"==typeof t.prependListener)return t.prependListener(e,r);t._events&&t._events[e]?Array.isArray(t._events[e])?t._events[e].unshift(r):t._events[e]=[r,t._events[e]]:t.on(e,r)}(t,"error",p),t.once("close",d),t.once("finish",m),t.emit("pipe",n),i.flowing||(c("pipe resume"),n.resume()),t},A.prototype.unpipe=function(t){var e=this._readableState,r={hasUnpiped:!1};if(0===e.pipesCount)return this;if(1===e.pipesCount)return t&&t!==e.pipes||(t||(t=e.pipes),e.pipes=null,e.pipesCount=0,e.flowing=!1,t&&t.emit("unpipe",this,r)),this;if(!t){var n=e.pipes,i=e.pipesCount;e.pipes=null,e.pipesCount=0,e.flowing=!1;for(var a=0;a<i;a++)n[a].emit("unpipe",this,{hasUnpiped:!1});return this}var o=j(e.pipes,t);return-1===o||(e.pipes.splice(o,1),e.pipesCount-=1,1===e.pipesCount&&(e.pipes=e.pipes[0]),t.emit("unpipe",this,r)),this},A.prototype.on=function(t,e){var n=o.prototype.on.call(this,t,e),i=this._readableState;return"data"===t?(i.readableListening=this.listenerCount("readable")>0,!1!==i.flowing&&this.resume()):"readable"===t&&(i.endEmitted||i.readableListening||(i.readableListening=i.needReadable=!0,i.flowing=!1,i.emittedReadable=!1,c("on readable",i.length,i.reading),i.length?L(this):i.reading||r.nextTick(z,this))),n},A.prototype.addListener=A.prototype.on,A.prototype.removeListener=function(t,e){var n=o.prototype.removeListener.call(this,t,e);return"readable"===t&&r.nextTick(O,this),n},A.prototype.removeAllListeners=function(t){var e=o.prototype.removeAllListeners.apply(this,arguments);return"readable"!==t&&void 0!==t||r.nextTick(O,this),e},A.prototype.resume=function(){var t=this._readableState;return t.flowing||(c("resume"),t.flowing=!t.readableListening,function(t,e){e.resumeScheduled||(e.resumeScheduled=!0,r.nextTick(D,t,e))}(this,t)),t.paused=!1,this},A.prototype.pause=function(){return c("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(c("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},A.prototype.wrap=function(t){var e=this,r=this._readableState,n=!1;for(var i in t.on("end",(function(){if(c("wrapped end"),r.decoder&&!r.ended){var t=r.decoder.end();t&&t.length&&e.push(t)}e.push(null)})),t.on("data",(function(i){(c("wrapped data"),r.decoder&&(i=r.decoder.write(i)),r.objectMode&&null==i)||(r.objectMode||i&&i.length)&&(e.push(i)||(n=!0,t.pause()))})),t)void 0===this[i]&&"function"==typeof t[i]&&(this[i]=function(e){return function(){return t[e].apply(t,arguments)}}(i));for(var a=0;a<T.length;a++)t.on(T[a],this.emit.bind(this,T[a]));return this._read=function(e){c("wrapped _read",e),n&&(n=!1,t.resume())},this},"function"==typeof Symbol&&(A.prototype[Symbol.asyncIterator]=function(){return void 0===h&&(h=t("./internal/streams/async_iterator")),h(this)}),Object.defineProperty(A.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(A.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(A.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(t){this._readableState&&(this._readableState.flowing=t)}}),A._fromList=F,Object.defineProperty(A.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),"function"==typeof Symbol&&(A.from=function(e,r){return void 0===p&&(p=t("./internal/streams/from")),p(A,e,r)})}).call(this)}).call(this,t("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../errors":286,"./_stream_duplex":287,"./internal/streams/async_iterator":292,"./internal/streams/buffer_list":293,"./internal/streams/destroy":294,"./internal/streams/from":296,"./internal/streams/state":298,"./internal/streams/stream":299,_process:277,buffer:85,events:84,inherits:231,"string_decoder/":300,util:83}],290:[function(t,e,r){"use strict";e.exports=u;var n=t("../errors").codes,i=n.ERR_METHOD_NOT_IMPLEMENTED,a=n.ERR_MULTIPLE_CALLBACK,o=n.ERR_TRANSFORM_ALREADY_TRANSFORMING,s=n.ERR_TRANSFORM_WITH_LENGTH_0,l=t("./_stream_duplex");function c(t,e){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(null===n)return this.emit("error",new a);r.writechunk=null,r.writecb=null,null!=e&&this.push(e),n(t);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function u(t){if(!(this instanceof u))return new u(t);l.call(this,t),this._transformState={afterTransform:c.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,t&&("function"==typeof t.transform&&(this._transform=t.transform),"function"==typeof t.flush&&(this._flush=t.flush)),this.on("prefinish",f)}function f(){var t=this;"function"!=typeof this._flush||this._readableState.destroyed?h(this,null,null):this._flush((function(e,r){h(t,e,r)}))}function h(t,e,r){if(e)return t.emit("error",e);if(null!=r&&t.push(r),t._writableState.length)throw new s;if(t._transformState.transforming)throw new o;return t.push(null)}t("inherits")(u,l),u.prototype.push=function(t,e){return this._transformState.needTransform=!1,l.prototype.push.call(this,t,e)},u.prototype._transform=function(t,e,r){r(new i("_transform()"))},u.prototype._write=function(t,e,r){var n=this._transformState;if(n.writecb=r,n.writechunk=t,n.writeencoding=e,!n.transforming){var i=this._readableState;(n.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},u.prototype._read=function(t){var e=this._transformState;null===e.writechunk||e.transforming?e.needTransform=!0:(e.transforming=!0,this._transform(e.writechunk,e.writeencoding,e.afterTransform))},u.prototype._destroy=function(t,e){l.prototype._destroy.call(this,t,(function(t){e(t)}))}},{"../errors":286,"./_stream_duplex":287,inherits:231}],291:[function(t,e,r){(function(r,n){(function(){"use strict";function i(t){var e=this;this.next=null,this.entry=null,this.finish=function(){!function(t,e,r){var n=t.entry;t.entry=null;for(;n;){var i=n.callback;e.pendingcb--,i(r),n=n.next}e.corkedRequestsFree.next=t}(e,t)}}var a;e.exports=A,A.WritableState=k;var o={deprecate:t("util-deprecate")},s=t("./internal/streams/stream"),l=t("buffer").Buffer,c=n.Uint8Array||function(){};var u,f=t("./internal/streams/destroy"),h=t("./internal/streams/state").getHighWaterMark,p=t("../errors").codes,d=p.ERR_INVALID_ARG_TYPE,m=p.ERR_METHOD_NOT_IMPLEMENTED,g=p.ERR_MULTIPLE_CALLBACK,v=p.ERR_STREAM_CANNOT_PIPE,y=p.ERR_STREAM_DESTROYED,x=p.ERR_STREAM_NULL_VALUES,b=p.ERR_STREAM_WRITE_AFTER_END,_=p.ERR_UNKNOWN_ENCODING,w=f.errorOrDestroy;function T(){}function k(e,n,o){a=a||t("./_stream_duplex"),e=e||{},"boolean"!=typeof o&&(o=n instanceof a),this.objectMode=!!e.objectMode,o&&(this.objectMode=this.objectMode||!!e.writableObjectMode),this.highWaterMark=h(this,e,"writableHighWaterMark",o),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var s=!1===e.decodeStrings;this.decodeStrings=!s,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(t){!function(t,e){var n=t._writableState,i=n.sync,a=n.writecb;if("function"!=typeof a)throw new g;if(function(t){t.writing=!1,t.writecb=null,t.length-=t.writelen,t.writelen=0}(n),e)!function(t,e,n,i,a){--e.pendingcb,n?(r.nextTick(a,i),r.nextTick(P,t,e),t._writableState.errorEmitted=!0,w(t,i)):(a(i),t._writableState.errorEmitted=!0,w(t,i),P(t,e))}(t,n,i,e,a);else{var o=L(n)||t.destroyed;o||n.corked||n.bufferProcessing||!n.bufferedRequest||E(t,n),i?r.nextTick(S,t,n,o,a):S(t,n,o,a)}}(n,t)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new i(this)}function A(e){var r=this instanceof(a=a||t("./_stream_duplex"));if(!r&&!u.call(A,this))return new A(e);this._writableState=new k(e,this,r),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),s.call(this)}function M(t,e,r,n,i,a,o){e.writelen=n,e.writecb=o,e.writing=!0,e.sync=!0,e.destroyed?e.onwrite(new y("write")):r?t._writev(i,e.onwrite):t._write(i,a,e.onwrite),e.sync=!1}function S(t,e,r,n){r||function(t,e){0===e.length&&e.needDrain&&(e.needDrain=!1,t.emit("drain"))}(t,e),e.pendingcb--,n(),P(t,e)}function E(t,e){e.bufferProcessing=!0;var r=e.bufferedRequest;if(t._writev&&r&&r.next){var n=e.bufferedRequestCount,a=new Array(n),o=e.corkedRequestsFree;o.entry=r;for(var s=0,l=!0;r;)a[s]=r,r.isBuf||(l=!1),r=r.next,s+=1;a.allBuffers=l,M(t,e,!0,e.length,a,"",o.finish),e.pendingcb++,e.lastBufferedRequest=null,o.next?(e.corkedRequestsFree=o.next,o.next=null):e.corkedRequestsFree=new i(e),e.bufferedRequestCount=0}else{for(;r;){var c=r.chunk,u=r.encoding,f=r.callback;if(M(t,e,!1,e.objectMode?1:c.length,c,u,f),r=r.next,e.bufferedRequestCount--,e.writing)break}null===r&&(e.lastBufferedRequest=null)}e.bufferedRequest=r,e.bufferProcessing=!1}function L(t){return t.ending&&0===t.length&&null===t.bufferedRequest&&!t.finished&&!t.writing}function C(t,e){t._final((function(r){e.pendingcb--,r&&w(t,r),e.prefinished=!0,t.emit("prefinish"),P(t,e)}))}function P(t,e){var n=L(e);if(n&&(function(t,e){e.prefinished||e.finalCalled||("function"!=typeof t._final||e.destroyed?(e.prefinished=!0,t.emit("prefinish")):(e.pendingcb++,e.finalCalled=!0,r.nextTick(C,t,e)))}(t,e),0===e.pendingcb&&(e.finished=!0,t.emit("finish"),e.autoDestroy))){var i=t._readableState;(!i||i.autoDestroy&&i.endEmitted)&&t.destroy()}return n}t("inherits")(A,s),k.prototype.getBuffer=function(){for(var t=this.bufferedRequest,e=[];t;)e.push(t),t=t.next;return e},function(){try{Object.defineProperty(k.prototype,"buffer",{get:o.deprecate((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(t){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(u=Function.prototype[Symbol.hasInstance],Object.defineProperty(A,Symbol.hasInstance,{value:function(t){return!!u.call(this,t)||this===A&&(t&&t._writableState instanceof k)}})):u=function(t){return t instanceof this},A.prototype.pipe=function(){w(this,new v)},A.prototype.write=function(t,e,n){var i,a=this._writableState,o=!1,s=!a.objectMode&&(i=t,l.isBuffer(i)||i instanceof c);return s&&!l.isBuffer(t)&&(t=function(t){return l.from(t)}(t)),"function"==typeof e&&(n=e,e=null),s?e="buffer":e||(e=a.defaultEncoding),"function"!=typeof n&&(n=T),a.ending?function(t,e){var n=new b;w(t,n),r.nextTick(e,n)}(this,n):(s||function(t,e,n,i){var a;return null===n?a=new x:"string"==typeof n||e.objectMode||(a=new d("chunk",["string","Buffer"],n)),!a||(w(t,a),r.nextTick(i,a),!1)}(this,a,t,n))&&(a.pendingcb++,o=function(t,e,r,n,i,a){if(!r){var o=function(t,e,r){t.objectMode||!1===t.decodeStrings||"string"!=typeof e||(e=l.from(e,r));return e}(e,n,i);n!==o&&(r=!0,i="buffer",n=o)}var s=e.objectMode?1:n.length;e.length+=s;var c=e.length<e.highWaterMark;c||(e.needDrain=!0);if(e.writing||e.corked){var u=e.lastBufferedRequest;e.lastBufferedRequest={chunk:n,encoding:i,isBuf:r,callback:a,next:null},u?u.next=e.lastBufferedRequest:e.bufferedRequest=e.lastBufferedRequest,e.bufferedRequestCount+=1}else M(t,e,!1,s,n,i,a);return c}(this,a,s,t,e,n)),o},A.prototype.cork=function(){this._writableState.corked++},A.prototype.uncork=function(){var t=this._writableState;t.corked&&(t.corked--,t.writing||t.corked||t.bufferProcessing||!t.bufferedRequest||E(this,t))},A.prototype.setDefaultEncoding=function(t){if("string"==typeof t&&(t=t.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((t+"").toLowerCase())>-1))throw new _(t);return this._writableState.defaultEncoding=t,this},Object.defineProperty(A.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(A.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),A.prototype._write=function(t,e,r){r(new m("_write()"))},A.prototype._writev=null,A.prototype.end=function(t,e,n){var i=this._writableState;return"function"==typeof t?(n=t,t=null,e=null):"function"==typeof e&&(n=e,e=null),null!=t&&this.write(t,e),i.corked&&(i.corked=1,this.uncork()),i.ending||function(t,e,n){e.ending=!0,P(t,e),n&&(e.finished?r.nextTick(n):t.once("finish",n));e.ended=!0,t.writable=!1}(this,i,n),this},Object.defineProperty(A.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(A.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(t){this._writableState&&(this._writableState.destroyed=t)}}),A.prototype.destroy=f.destroy,A.prototype._undestroy=f.undestroy,A.prototype._destroy=function(t,e){e(t)}}).call(this)}).call(this,t("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../errors":286,"./_stream_duplex":287,"./internal/streams/destroy":294,"./internal/streams/state":298,"./internal/streams/stream":299,_process:277,buffer:85,inherits:231,"util-deprecate":330}],292:[function(t,e,r){(function(r){(function(){"use strict";var n;function i(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var a=t("./end-of-stream"),o=Symbol("lastResolve"),s=Symbol("lastReject"),l=Symbol("error"),c=Symbol("ended"),u=Symbol("lastPromise"),f=Symbol("handlePromise"),h=Symbol("stream");function p(t,e){return{value:t,done:e}}function d(t){var e=t[o];if(null!==e){var r=t[h].read();null!==r&&(t[u]=null,t[o]=null,t[s]=null,e(p(r,!1)))}}function m(t){r.nextTick(d,t)}var g=Object.getPrototypeOf((function(){})),v=Object.setPrototypeOf((i(n={get stream(){return this[h]},next:function(){var t=this,e=this[l];if(null!==e)return Promise.reject(e);if(this[c])return Promise.resolve(p(void 0,!0));if(this[h].destroyed)return new Promise((function(e,n){r.nextTick((function(){t[l]?n(t[l]):e(p(void 0,!0))}))}));var n,i=this[u];if(i)n=new Promise(function(t,e){return function(r,n){t.then((function(){e[c]?r(p(void 0,!0)):e[f](r,n)}),n)}}(i,this));else{var a=this[h].read();if(null!==a)return Promise.resolve(p(a,!1));n=new Promise(this[f])}return this[u]=n,n}},Symbol.asyncIterator,(function(){return this})),i(n,"return",(function(){var t=this;return new Promise((function(e,r){t[h].destroy(null,(function(t){t?r(t):e(p(void 0,!0))}))}))})),n),g);e.exports=function(t){var e,r=Object.create(v,(i(e={},h,{value:t,writable:!0}),i(e,o,{value:null,writable:!0}),i(e,s,{value:null,writable:!0}),i(e,l,{value:null,writable:!0}),i(e,c,{value:t._readableState.endEmitted,writable:!0}),i(e,f,{value:function(t,e){var n=r[h].read();n?(r[u]=null,r[o]=null,r[s]=null,t(p(n,!1))):(r[o]=t,r[s]=e)},writable:!0}),e));return r[u]=null,a(t,(function(t){if(t&&"ERR_STREAM_PREMATURE_CLOSE"!==t.code){var e=r[s];return null!==e&&(r[u]=null,r[o]=null,r[s]=null,e(t)),void(r[l]=t)}var n=r[o];null!==n&&(r[u]=null,r[o]=null,r[s]=null,n(p(void 0,!0))),r[c]=!0})),t.on("readable",m.bind(null,r)),r}}).call(this)}).call(this,t("_process"))},{"./end-of-stream":295,_process:277}],293:[function(t,e,r){"use strict";function n(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function i(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var o=t("buffer").Buffer,s=t("util").inspect,l=s&&s.custom||"inspect";e.exports=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.head=null,this.tail=null,this.length=0}var e,r,c;return e=t,(r=[{key:"push",value:function(t){var e={data:t,next:null};this.length>0?this.tail.next=e:this.head=e,this.tail=e,++this.length}},{key:"unshift",value:function(t){var e={data:t,next:this.head};0===this.length&&(this.tail=e),this.head=e,++this.length}},{key:"shift",value:function(){if(0!==this.length){var t=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,t}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(t){if(0===this.length)return"";for(var e=this.head,r=""+e.data;e=e.next;)r+=t+e.data;return r}},{key:"concat",value:function(t){if(0===this.length)return o.alloc(0);for(var e,r,n,i=o.allocUnsafe(t>>>0),a=this.head,s=0;a;)e=a.data,r=i,n=s,o.prototype.copy.call(e,r,n),s+=a.data.length,a=a.next;return i}},{key:"consume",value:function(t,e){var r;return t<this.head.data.length?(r=this.head.data.slice(0,t),this.head.data=this.head.data.slice(t)):r=t===this.head.data.length?this.shift():e?this._getString(t):this._getBuffer(t),r}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(t){var e=this.head,r=1,n=e.data;for(t-=n.length;e=e.next;){var i=e.data,a=t>i.length?i.length:t;if(a===i.length?n+=i:n+=i.slice(0,t),0==(t-=a)){a===i.length?(++r,e.next?this.head=e.next:this.head=this.tail=null):(this.head=e,e.data=i.slice(a));break}++r}return this.length-=r,n}},{key:"_getBuffer",value:function(t){var e=o.allocUnsafe(t),r=this.head,n=1;for(r.data.copy(e),t-=r.data.length;r=r.next;){var i=r.data,a=t>i.length?i.length:t;if(i.copy(e,e.length-t,0,a),0==(t-=a)){a===i.length?(++n,r.next?this.head=r.next:this.head=this.tail=null):(this.head=r,r.data=i.slice(a));break}++n}return this.length-=n,e}},{key:l,value:function(t,e){return s(this,function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}({},e,{depth:0,customInspect:!1}))}}])&&a(e.prototype,r),c&&a(e,c),t}()},{buffer:85,util:83}],294:[function(t,e,r){(function(t){(function(){"use strict";function r(t,e){i(t,e),n(t)}function n(t){t._writableState&&!t._writableState.emitClose||t._readableState&&!t._readableState.emitClose||t.emit("close")}function i(t,e){t.emit("error",e)}e.exports={destroy:function(e,a){var o=this,s=this._readableState&&this._readableState.destroyed,l=this._writableState&&this._writableState.destroyed;return s||l?(a?a(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,t.nextTick(i,this,e)):t.nextTick(i,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,(function(e){!a&&e?o._writableState?o._writableState.errorEmitted?t.nextTick(n,o):(o._writableState.errorEmitted=!0,t.nextTick(r,o,e)):t.nextTick(r,o,e):a?(t.nextTick(n,o),a(e)):t.nextTick(n,o)})),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)},errorOrDestroy:function(t,e){var r=t._readableState,n=t._writableState;r&&r.autoDestroy||n&&n.autoDestroy?t.destroy(e):t.emit("error",e)}}}).call(this)}).call(this,t("_process"))},{_process:277}],295:[function(t,e,r){"use strict";var n=t("../../../errors").codes.ERR_STREAM_PREMATURE_CLOSE;function i(){}e.exports=function t(e,r,a){if("function"==typeof r)return t(e,null,r);r||(r={}),a=function(t){var e=!1;return function(){if(!e){e=!0;for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];t.apply(this,n)}}}(a||i);var o=r.readable||!1!==r.readable&&e.readable,s=r.writable||!1!==r.writable&&e.writable,l=function(){e.writable||u()},c=e._writableState&&e._writableState.finished,u=function(){s=!1,c=!0,o||a.call(e)},f=e._readableState&&e._readableState.endEmitted,h=function(){o=!1,f=!0,s||a.call(e)},p=function(t){a.call(e,t)},d=function(){var t;return o&&!f?(e._readableState&&e._readableState.ended||(t=new n),a.call(e,t)):s&&!c?(e._writableState&&e._writableState.ended||(t=new n),a.call(e,t)):void 0},m=function(){e.req.on("finish",u)};return!function(t){return t.setHeader&&"function"==typeof t.abort}(e)?s&&!e._writableState&&(e.on("end",l),e.on("close",l)):(e.on("complete",u),e.on("abort",d),e.req?m():e.on("request",m)),e.on("end",h),e.on("finish",u),!1!==r.error&&e.on("error",p),e.on("close",d),function(){e.removeListener("complete",u),e.removeListener("abort",d),e.removeListener("request",m),e.req&&e.req.removeListener("finish",u),e.removeListener("end",l),e.removeListener("close",l),e.removeListener("finish",u),e.removeListener("end",h),e.removeListener("error",p),e.removeListener("close",d)}}},{"../../../errors":286}],296:[function(t,e,r){e.exports=function(){throw new Error("Readable.from is not available in the browser")}},{}],297:[function(t,e,r){"use strict";var n;var i=t("../../../errors").codes,a=i.ERR_MISSING_ARGS,o=i.ERR_STREAM_DESTROYED;function s(t){if(t)throw t}function l(e,r,i,a){a=function(t){var e=!1;return function(){e||(e=!0,t.apply(void 0,arguments))}}(a);var s=!1;e.on("close",(function(){s=!0})),void 0===n&&(n=t("./end-of-stream")),n(e,{readable:r,writable:i},(function(t){if(t)return a(t);s=!0,a()}));var l=!1;return function(t){if(!s&&!l)return l=!0,function(t){return t.setHeader&&"function"==typeof t.abort}(e)?e.abort():"function"==typeof e.destroy?e.destroy():void a(t||new o("pipe"))}}function c(t){t()}function u(t,e){return t.pipe(e)}function f(t){return t.length?"function"!=typeof t[t.length-1]?s:t.pop():s}e.exports=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n,i=f(e);if(Array.isArray(e[0])&&(e=e[0]),e.length<2)throw new a("streams");var o=e.map((function(t,r){var a=r<e.length-1;return l(t,a,r>0,(function(t){n||(n=t),t&&o.forEach(c),a||(o.forEach(c),i(n))}))}));return e.reduce(u)}},{"../../../errors":286,"./end-of-stream":295}],298:[function(t,e,r){"use strict";var n=t("../../../errors").codes.ERR_INVALID_OPT_VALUE;e.exports={getHighWaterMark:function(t,e,r,i){var a=function(t,e,r){return null!=t.highWaterMark?t.highWaterMark:e?t[r]:null}(e,i,r);if(null!=a){if(!isFinite(a)||Math.floor(a)!==a||a<0)throw new n(i?r:"highWaterMark",a);return Math.floor(a)}return t.objectMode?16:16384}}},{"../../../errors":286}],299:[function(t,e,r){e.exports=t("events").EventEmitter},{events:84}],300:[function(t,e,r){"use strict";var n=t("safe-buffer").Buffer,i=n.isEncoding||function(t){switch((t=""+t)&&t.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function a(t){var e;switch(this.encoding=function(t){var e=function(t){if(!t)return"utf8";for(var e;;)switch(t){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return t;default:if(e)return;t=(""+t).toLowerCase(),e=!0}}(t);if("string"!=typeof e&&(n.isEncoding===i||!i(t)))throw new Error("Unknown encoding: "+t);return e||t}(t),this.encoding){case"utf16le":this.text=l,this.end=c,e=4;break;case"utf8":this.fillLast=s,e=4;break;case"base64":this.text=u,this.end=f,e=3;break;default:return this.write=h,void(this.end=p)}this.lastNeed=0,this.lastTotal=0,this.lastChar=n.allocUnsafe(e)}function o(t){return t<=127?0:t>>5==6?2:t>>4==14?3:t>>3==30?4:t>>6==2?-1:-2}function s(t){var e=this.lastTotal-this.lastNeed,r=function(t,e,r){if(128!=(192&e[0]))return t.lastNeed=0,"\ufffd";if(t.lastNeed>1&&e.length>1){if(128!=(192&e[1]))return t.lastNeed=1,"\ufffd";if(t.lastNeed>2&&e.length>2&&128!=(192&e[2]))return t.lastNeed=2,"\ufffd"}}(this,t);return void 0!==r?r:this.lastNeed<=t.length?(t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(t.copy(this.lastChar,e,0,t.length),void(this.lastNeed-=t.length))}function l(t,e){if((t.length-e)%2==0){var r=t.toString("utf16le",e);if(r){var n=r.charCodeAt(r.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function c(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,r)}return e}function u(t,e){var r=(t.length-e)%3;return 0===r?t.toString("base64",e):(this.lastNeed=3-r,this.lastTotal=3,1===r?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-r))}function f(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function h(t){return t.toString(this.encoding)}function p(t){return t&&t.length?this.write(t):""}r.StringDecoder=a,a.prototype.write=function(t){if(0===t.length)return"";var e,r;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<t.length?e?e+this.text(t,r):this.text(t,r):e||""},a.prototype.end=function(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+"\ufffd":e},a.prototype.text=function(t,e){var r=function(t,e,r){var n=e.length-1;if(n<r)return 0;var i=o(e[n]);if(i>=0)return i>0&&(t.lastNeed=i-1),i;if(--n<r||-2===i)return 0;if((i=o(e[n]))>=0)return i>0&&(t.lastNeed=i-2),i;if(--n<r||-2===i)return 0;if((i=o(e[n]))>=0)return i>0&&(2===i?i=0:t.lastNeed=i-3),i;return 0}(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=r;var n=t.length-(r-this.lastNeed);return t.copy(this.lastChar,0,n),t.toString("utf8",e,n)},a.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length}},{"safe-buffer":284}],301:[function(t,e,r){(function(r,n){(function(){var r=t("assert"),i=t("debug")("stream-parser");e.exports=function(t){var e=t&&"function"==typeof t._transform,r=t&&"function"==typeof t._write;if(!e&&!r)throw new Error("must pass a Writable or Transform stream in");i("extending Parser into stream"),t._bytes=o,t._skipBytes=s,e&&(t._passthrough=l);e?t._transform=u:t._write=c};function a(t){i("initializing parser stream"),t._parserBytesLeft=0,t._parserBuffers=[],t._parserBuffered=0,t._parserState=-1,t._parserCallback=null,"function"==typeof t.push&&(t._parserOutput=t.push.bind(t)),t._parserInit=!0}function o(t,e){r(!this._parserCallback,'there is already a "callback" set!'),r(isFinite(t)&&t>0,'can only buffer a finite number of bytes > 0, got "'+t+'"'),this._parserInit||a(this),i("buffering %o bytes",t),this._parserBytesLeft=t,this._parserCallback=e,this._parserState=0}function s(t,e){r(!this._parserCallback,'there is already a "callback" set!'),r(t>0,'can only skip > 0 bytes, got "'+t+'"'),this._parserInit||a(this),i("skipping %o bytes",t),this._parserBytesLeft=t,this._parserCallback=e,this._parserState=1}function l(t,e){r(!this._parserCallback,'There is already a "callback" set!'),r(t>0,'can only pass through > 0 bytes, got "'+t+'"'),this._parserInit||a(this),i("passing through %o bytes",t),this._parserBytesLeft=t,this._parserCallback=e,this._parserState=2}function c(t,e,r){this._parserInit||a(this),i("write(%o bytes)",t.length),"function"==typeof e&&(r=e),h(this,t,null,r)}function u(t,e,r){this._parserInit||a(this),i("transform(%o bytes)",t.length),"function"!=typeof e&&(e=this._parserOutput),h(this,t,e,r)}function f(t,e,r,a){if(t._parserBytesLeft-=e.length,i("%o bytes left for stream piece",t._parserBytesLeft),0===t._parserState?(t._parserBuffers.push(e),t._parserBuffered+=e.length):2===t._parserState&&r(e),0!==t._parserBytesLeft)return a;var o=t._parserCallback;if(o&&0===t._parserState&&t._parserBuffers.length>1&&(e=n.concat(t._parserBuffers,t._parserBuffered)),0!==t._parserState&&(e=null),t._parserCallback=null,t._parserBuffered=0,t._parserState=-1,t._parserBuffers.splice(0),o){var s=[];e&&s.push(e),r&&s.push(r);var l=o.length>s.length;l&&s.push(p(a));var c=o.apply(t,s);if(!l||a===c)return a}}var h=p((function t(e,r,n,i){return e._parserBytesLeft<=0?i(new Error("got data but not currently parsing anything")):r.length<=e._parserBytesLeft?function(){return f(e,r,n,i)}:function(){var a=r.slice(0,e._parserBytesLeft);return f(e,a,n,(function(o){return o?i(o):r.length>a.length?function(){return t(e,r.slice(a.length),n,i)}:void 0}))}}));function p(t){return function(){for(var e=t.apply(this,arguments);"function"==typeof e;)e=e();return e}}}).call(this)}).call(this,t("_process"),t("buffer").Buffer)},{_process:277,assert:75,buffer:85,debug:302}],302:[function(t,e,r){(function(n){(function(){function i(){var t;try{t=r.storage.debug}catch(t){}return!t&&void 0!==n&&"env"in n&&(t=n.env.DEBUG),t}(r=e.exports=t("./debug")).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},r.formatArgs=function(t){var e=this.useColors;if(t[0]=(e?"%c":"")+this.namespace+(e?" %c":" ")+t[0]+(e?"%c ":" ")+"+"+r.humanize(this.diff),!e)return;var n="color: "+this.color;t.splice(1,0,n,"color: inherit");var i=0,a=0;t[0].replace(/%[a-zA-Z%]/g,(function(t){"%%"!==t&&(i++,"%c"===t&&(a=i))})),t.splice(a,0,n)},r.save=function(t){try{null==t?r.storage.removeItem("debug"):r.storage.debug=t}catch(t){}},r.load=i,r.useColors=function(){if("undefined"!=typeof window&&window.process&&"renderer"===window.process.type)return!0;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},r.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(t){}}(),r.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],r.formatters.j=function(t){try{return JSON.stringify(t)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}},r.enable(i())}).call(this)}).call(this,t("_process"))},{"./debug":303,_process:277}],303:[function(t,e,r){var n;function i(t){function e(){if(e.enabled){var t=e,i=+new Date,a=i-(n||i);t.diff=a,t.prev=n,t.curr=i,n=i;for(var o=new Array(arguments.length),s=0;s<o.length;s++)o[s]=arguments[s];o[0]=r.coerce(o[0]),"string"!=typeof o[0]&&o.unshift("%O");var l=0;o[0]=o[0].replace(/%([a-zA-Z%])/g,(function(e,n){if("%%"===e)return e;l++;var i=r.formatters[n];if("function"==typeof i){var a=o[l];e=i.call(t,a),o.splice(l,1),l--}return e})),r.formatArgs.call(t,o);var c=e.log||r.log||console.log.bind(console);c.apply(t,o)}}return e.namespace=t,e.enabled=r.enabled(t),e.useColors=r.useColors(),e.color=function(t){var e,n=0;for(e in t)n=(n<<5)-n+t.charCodeAt(e),n|=0;return r.colors[Math.abs(n)%r.colors.length]}(t),"function"==typeof r.init&&r.init(e),e}(r=e.exports=i.debug=i.default=i).coerce=function(t){return t instanceof Error?t.stack||t.message:t},r.disable=function(){r.enable("")},r.enable=function(t){r.save(t),r.names=[],r.skips=[];for(var e=("string"==typeof t?t:"").split(/[\s,]+/),n=e.length,i=0;i<n;i++)e[i]&&("-"===(t=e[i].replace(/\*/g,".*?"))[0]?r.skips.push(new RegExp("^"+t.substr(1)+"$")):r.names.push(new RegExp("^"+t+"$")))},r.enabled=function(t){var e,n;for(e=0,n=r.skips.length;e<n;e++)if(r.skips[e].test(t))return!1;for(e=0,n=r.names.length;e<n;e++)if(r.names[e].test(t))return!0;return!1},r.humanize=t("ms"),r.names=[],r.skips=[],r.formatters={}},{ms:304}],304:[function(t,e,r){var n=1e3,i=6e4,a=60*i,o=24*a;function s(t,e,r){if(!(t<e))return t<1.5*e?Math.floor(t/e)+" "+r:Math.ceil(t/e)+" "+r+"s"}e.exports=function(t,e){e=e||{};var r,l=typeof t;if("string"===l&&t.length>0)return function(t){if((t=String(t)).length>100)return;var e=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(t);if(!e)return;var r=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*r;case"days":case"day":case"d":return r*o;case"hours":case"hour":case"hrs":case"hr":case"h":return r*a;case"minutes":case"minute":case"mins":case"min":case"m":return r*i;case"seconds":case"second":case"secs":case"sec":case"s":return r*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}(t);if("number"===l&&!1===isNaN(t))return e.long?s(r=t,o,"day")||s(r,a,"hour")||s(r,i,"minute")||s(r,n,"second")||r+" ms":function(t){if(t>=o)return Math.round(t/o)+"d";if(t>=a)return Math.round(t/a)+"h";if(t>=i)return Math.round(t/i)+"m";if(t>=n)return Math.round(t/n)+"s";return t+"ms"}(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))}},{}],305:[function(t,e,r){"use strict";var n=t("parenthesis");e.exports=function(t,e,r){if(null==t)throw Error("First argument should be a string");if(null==e)throw Error("Separator should be a string or a RegExp");r?("string"==typeof r||Array.isArray(r))&&(r={ignore:r}):r={},null==r.escape&&(r.escape=!0),null==r.ignore?r.ignore=["[]","()","{}","<>",'""',"''","``","\u201c\u201d","\xab\xbb"]:("string"==typeof r.ignore&&(r.ignore=[r.ignore]),r.ignore=r.ignore.map((function(t){return 1===t.length&&(t+=t),t})));var i=n.parse(t,{flat:!0,brackets:r.ignore}),a=i[0].split(e);if(r.escape){for(var o=[],s=0;s<a.length;s++){var l=a[s],c=a[s+1];"\\"===l[l.length-1]&&"\\"!==l[l.length-2]?(o.push(l+e+c),s++):o.push(l)}a=o}for(s=0;s<a.length;s++)i[0]=a[s],a[s]=n.stringify(i,{flat:!0});return a}},{parenthesis:248}],306:[function(t,e,r){"use strict";e.exports=function(t){for(var e=t.length,r=new Array(e),n=new Array(e),i=new Array(e),a=new Array(e),o=new Array(e),s=new Array(e),l=0;l<e;++l)r[l]=-1,n[l]=0,i[l]=!1,a[l]=0,o[l]=-1,s[l]=[];var c,u=0,f=[],h=[];function p(e){var l=[e],c=[e];for(r[e]=n[e]=u,i[e]=!0,u+=1;c.length>0;){e=c[c.length-1];var p=t[e];if(a[e]<p.length){for(var d=a[e];d<p.length;++d){var m=p[d];if(r[m]<0){r[m]=n[m]=u,i[m]=!0,u+=1,l.push(m),c.push(m);break}i[m]&&(n[e]=0|Math.min(n[e],n[m])),o[m]>=0&&s[e].push(o[m])}a[e]=d}else{if(n[e]===r[e]){var g=[],v=[],y=0;for(d=l.length-1;d>=0;--d){var x=l[d];if(i[x]=!1,g.push(x),v.push(s[x]),y+=s[x].length,o[x]=f.length,x===e){l.length=d;break}}f.push(g);var b=new Array(y);for(d=0;d<v.length;d++)for(var _=0;_<v[d].length;_++)b[--y]=v[d][_];h.push(b)}c.pop()}}}for(l=0;l<e;++l)r[l]<0&&p(l);for(l=0;l<h.length;l++){var d=h[l];if(0!==d.length){d.sort((function(t,e){return t-e})),c=[d[0]];for(var m=1;m<d.length;m++)d[m]!==d[m-1]&&c.push(d[m]);h[l]=c}}return{components:f,adjacencyList:h}}},{}],307:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var r=[],n=!0,i=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(n=(o=s.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(t){i=!0,a=t}finally{try{!n&&s.return&&s.return()}finally{if(i)throw a}}return r}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")},i=2*Math.PI,a=function(t,e,r,n,i,a,o){var s=t.x,l=t.y;return{x:n*(s*=e)-i*(l*=r)+a,y:i*s+n*l+o}},o=function(t,e){var r=1.5707963267948966===e?.551915024494:-1.5707963267948966===e?-.551915024494:4/3*Math.tan(e/4),n=Math.cos(t),i=Math.sin(t),a=Math.cos(t+e),o=Math.sin(t+e);return[{x:n-i*r,y:i+n*r},{x:a+o*r,y:o-a*r},{x:a,y:o}]},s=function(t,e,r,n){var i=t*r+e*n;return i>1&&(i=1),i<-1&&(i=-1),(t*n-e*r<0?-1:1)*Math.acos(i)};r.default=function(t){var e=t.px,r=t.py,l=t.cx,c=t.cy,u=t.rx,f=t.ry,h=t.xAxisRotation,p=void 0===h?0:h,d=t.largeArcFlag,m=void 0===d?0:d,g=t.sweepFlag,v=void 0===g?0:g,y=[];if(0===u||0===f)return[];var x=Math.sin(p*i/360),b=Math.cos(p*i/360),_=b*(e-l)/2+x*(r-c)/2,w=-x*(e-l)/2+b*(r-c)/2;if(0===_&&0===w)return[];u=Math.abs(u),f=Math.abs(f);var T=Math.pow(_,2)/Math.pow(u,2)+Math.pow(w,2)/Math.pow(f,2);T>1&&(u*=Math.sqrt(T),f*=Math.sqrt(T));var k=function(t,e,r,n,a,o,l,c,u,f,h,p){var d=Math.pow(a,2),m=Math.pow(o,2),g=Math.pow(h,2),v=Math.pow(p,2),y=d*m-d*v-m*g;y<0&&(y=0),y/=d*v+m*g;var x=(y=Math.sqrt(y)*(l===c?-1:1))*a/o*p,b=y*-o/a*h,_=f*x-u*b+(t+r)/2,w=u*x+f*b+(e+n)/2,T=(h-x)/a,k=(p-b)/o,A=(-h-x)/a,M=(-p-b)/o,S=s(1,0,T,k),E=s(T,k,A,M);return 0===c&&E>0&&(E-=i),1===c&&E<0&&(E+=i),[_,w,S,E]}(e,r,l,c,u,f,m,v,x,b,_,w),A=n(k,4),M=A[0],S=A[1],E=A[2],L=A[3],C=Math.abs(L)/(i/4);Math.abs(1-C)<1e-7&&(C=1);var P=Math.max(Math.ceil(C),1);L/=P;for(var I=0;I<P;I++)y.push(o(E,L)),E+=L;return y.map((function(t){var e=a(t[0],u,f,b,x,M,S),r=e.x,n=e.y,i=a(t[1],u,f,b,x,M,S),o=i.x,s=i.y,l=a(t[2],u,f,b,x,M,S);return{x1:r,y1:n,x2:o,y2:s,x:l.x,y:l.y}}))},e.exports=r.default},{}],308:[function(t,e,r){"use strict";var n=t("parse-svg-path"),i=t("abs-svg-path"),a=t("normalize-svg-path"),o=t("is-svg-path"),s=t("assert");e.exports=function(t){Array.isArray(t)&&1===t.length&&"string"==typeof t[0]&&(t=t[0]);"string"==typeof t&&(s(o(t),"String is not an SVG path."),t=n(t));if(s(Array.isArray(t),"Argument should be a string or an array of path segments."),t=i(t),!(t=a(t)).length)return[0,0,0,0];for(var e=[1/0,1/0,-1/0,-1/0],r=0,l=t.length;r<l;r++)for(var c=t[r].slice(1),u=0;u<c.length;u+=2)c[u+0]<e[0]&&(e[0]=c[u+0]),c[u+1]<e[1]&&(e[1]=c[u+1]),c[u+0]>e[2]&&(e[2]=c[u+0]),c[u+1]>e[3]&&(e[3]=c[u+1]);return e}},{"abs-svg-path":70,assert:75,"is-svg-path":238,"normalize-svg-path":309,"parse-svg-path":250}],309:[function(t,e,r){"use strict";e.exports=function(t){for(var e,r=[],o=0,s=0,l=0,c=0,u=null,f=null,h=0,p=0,d=0,m=t.length;d<m;d++){var g=t[d],v=g[0];switch(v){case"M":l=g[1],c=g[2];break;case"A":var y=n({px:h,py:p,cx:g[6],cy:g[7],rx:g[1],ry:g[2],xAxisRotation:g[3],largeArcFlag:g[4],sweepFlag:g[5]});if(!y.length)continue;for(var x,b=0;b<y.length;b++)x=y[b],g=["C",x.x1,x.y1,x.x2,x.y2,x.x,x.y],b<y.length-1&&r.push(g);break;case"S":var _=h,w=p;"C"!=e&&"S"!=e||(_+=_-o,w+=w-s),g=["C",_,w,g[1],g[2],g[3],g[4]];break;case"T":"Q"==e||"T"==e?(u=2*h-u,f=2*p-f):(u=h,f=p),g=a(h,p,u,f,g[1],g[2]);break;case"Q":u=g[1],f=g[2],g=a(h,p,g[1],g[2],g[3],g[4]);break;case"L":g=i(h,p,g[1],g[2]);break;case"H":g=i(h,p,g[1],p);break;case"V":g=i(h,p,h,g[1]);break;case"Z":g=i(h,p,l,c)}e=v,h=g[g.length-2],p=g[g.length-1],g.length>4?(o=g[g.length-4],s=g[g.length-3]):(o=h,s=p),r.push(g)}return r};var n=t("svg-arc-to-cubic-bezier");function i(t,e,r,n){return["C",t,e,r,n,r,n]}function a(t,e,r,n,i,a){return["C",t/3+2/3*r,e/3+2/3*n,i/3+2/3*r,a/3+2/3*n,i,a]}},{"svg-arc-to-cubic-bezier":307}],310:[function(t,e,r){"use strict";var n,i=t("svg-path-bounds"),a=t("parse-svg-path"),o=t("draw-svg-path"),s=t("is-svg-path"),l=t("bitmap-sdf"),c=document.createElement("canvas"),u=c.getContext("2d");e.exports=function(t,e){if(!s(t))throw Error("Argument should be valid svg path string");e||(e={});var r,f;e.shape?(r=e.shape[0],f=e.shape[1]):(r=c.width=e.w||e.width||200,f=c.height=e.h||e.height||200);var h=Math.min(r,f),p=e.stroke||0,d=e.viewbox||e.viewBox||i(t),m=[r/(d[2]-d[0]),f/(d[3]-d[1])],g=Math.min(m[0]||0,m[1]||0)/2;u.fillStyle="black",u.fillRect(0,0,r,f),u.fillStyle="white",p&&("number"!=typeof p&&(p=1),u.strokeStyle=p>0?"white":"black",u.lineWidth=Math.abs(p));if(u.translate(.5*r,.5*f),u.scale(g,g),function(){if(null!=n)return n;var t=document.createElement("canvas").getContext("2d");if(t.canvas.width=t.canvas.height=1,!window.Path2D)return n=!1;var e=new Path2D("M0,0h1v1h-1v-1Z");t.fillStyle="black",t.fill(e);var r=t.getImageData(0,0,1,1);return n=r&&r.data&&255===r.data[3]}()){var v=new Path2D(t);u.fill(v),p&&u.stroke(v)}else{var y=a(t);o(u,y),u.fill(),p&&u.stroke()}return u.setTransform(1,0,0,1,0,0),l(u,{cutoff:null!=e.cutoff?e.cutoff:.5,radius:null!=e.radius?e.radius:.5*h})}},{"bitmap-sdf":82,"draw-svg-path":126,"is-svg-path":238,"parse-svg-path":250,"svg-path-bounds":308}],311:[function(t,e,r){(function(e,n){(function(){var i=t("process/browser.js").nextTick,a=Function.prototype.apply,o=Array.prototype.slice,s={},l=0;function c(t,e){this._id=t,this._clearFn=e}r.setTimeout=function(){return new c(a.call(setTimeout,window,arguments),clearTimeout)},r.setInterval=function(){return new c(a.call(setInterval,window,arguments),clearInterval)},r.clearTimeout=r.clearInterval=function(t){t.close()},c.prototype.unref=c.prototype.ref=function(){},c.prototype.close=function(){this._clearFn.call(window,this._id)},r.enroll=function(t,e){clearTimeout(t._idleTimeoutId),t._idleTimeout=e},r.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},r._unrefActive=r.active=function(t){clearTimeout(t._idleTimeoutId);var e=t._idleTimeout;e>=0&&(t._idleTimeoutId=setTimeout((function(){t._onTimeout&&t._onTimeout()}),e))},r.setImmediate="function"==typeof e?e:function(t){var e=l++,n=!(arguments.length<2)&&o.call(arguments,1);return s[e]=!0,i((function(){s[e]&&(n?t.apply(null,n):t.call(null),r.clearImmediate(e))})),e},r.clearImmediate="function"==typeof n?n:function(t){delete s[t]}}).call(this)}).call(this,t("timers").setImmediate,t("timers").clearImmediate)},{"process/browser.js":277,timers:311}],312:[function(t,e,r){!function(t){var r=/^\s+/,n=/\s+$/,i=0,a=t.round,o=t.min,s=t.max,l=t.random;function c(e,l){if(l=l||{},(e=e||"")instanceof c)return e;if(!(this instanceof c))return new c(e,l);var u=function(e){var i={r:0,g:0,b:0},a=1,l=null,c=null,u=null,f=!1,h=!1;"string"==typeof e&&(e=function(t){t=t.replace(r,"").replace(n,"").toLowerCase();var e,i=!1;if(S[t])t=S[t],i=!0;else if("transparent"==t)return{r:0,g:0,b:0,a:0,format:"name"};if(e=j.rgb.exec(t))return{r:e[1],g:e[2],b:e[3]};if(e=j.rgba.exec(t))return{r:e[1],g:e[2],b:e[3],a:e[4]};if(e=j.hsl.exec(t))return{h:e[1],s:e[2],l:e[3]};if(e=j.hsla.exec(t))return{h:e[1],s:e[2],l:e[3],a:e[4]};if(e=j.hsv.exec(t))return{h:e[1],s:e[2],v:e[3]};if(e=j.hsva.exec(t))return{h:e[1],s:e[2],v:e[3],a:e[4]};if(e=j.hex8.exec(t))return{r:I(e[1]),g:I(e[2]),b:I(e[3]),a:R(e[4]),format:i?"name":"hex8"};if(e=j.hex6.exec(t))return{r:I(e[1]),g:I(e[2]),b:I(e[3]),format:i?"name":"hex"};if(e=j.hex4.exec(t))return{r:I(e[1]+""+e[1]),g:I(e[2]+""+e[2]),b:I(e[3]+""+e[3]),a:R(e[4]+""+e[4]),format:i?"name":"hex8"};if(e=j.hex3.exec(t))return{r:I(e[1]+""+e[1]),g:I(e[2]+""+e[2]),b:I(e[3]+""+e[3]),format:i?"name":"hex"};return!1}(e));"object"==typeof e&&(U(e.r)&&U(e.g)&&U(e.b)?(p=e.r,d=e.g,m=e.b,i={r:255*C(p,255),g:255*C(d,255),b:255*C(m,255)},f=!0,h="%"===String(e.r).substr(-1)?"prgb":"rgb"):U(e.h)&&U(e.s)&&U(e.v)?(l=z(e.s),c=z(e.v),i=function(e,r,n){e=6*C(e,360),r=C(r,100),n=C(n,100);var i=t.floor(e),a=e-i,o=n*(1-r),s=n*(1-a*r),l=n*(1-(1-a)*r),c=i%6;return{r:255*[n,s,o,o,l,n][c],g:255*[l,n,n,s,o,o][c],b:255*[o,o,l,n,n,s][c]}}(e.h,l,c),f=!0,h="hsv"):U(e.h)&&U(e.s)&&U(e.l)&&(l=z(e.s),u=z(e.l),i=function(t,e,r){var n,i,a;function o(t,e,r){return r<0&&(r+=1),r>1&&(r-=1),r<1/6?t+6*(e-t)*r:r<.5?e:r<2/3?t+(e-t)*(2/3-r)*6:t}if(t=C(t,360),e=C(e,100),r=C(r,100),0===e)n=i=a=r;else{var s=r<.5?r*(1+e):r+e-r*e,l=2*r-s;n=o(l,s,t+1/3),i=o(l,s,t),a=o(l,s,t-1/3)}return{r:255*n,g:255*i,b:255*a}}(e.h,l,u),f=!0,h="hsl"),e.hasOwnProperty("a")&&(a=e.a));var p,d,m;return a=L(a),{ok:f,format:e.format||h,r:o(255,s(i.r,0)),g:o(255,s(i.g,0)),b:o(255,s(i.b,0)),a:a}}(e);this._originalInput=e,this._r=u.r,this._g=u.g,this._b=u.b,this._a=u.a,this._roundA=a(100*this._a)/100,this._format=l.format||u.format,this._gradientType=l.gradientType,this._r<1&&(this._r=a(this._r)),this._g<1&&(this._g=a(this._g)),this._b<1&&(this._b=a(this._b)),this._ok=u.ok,this._tc_id=i++}function u(t,e,r){t=C(t,255),e=C(e,255),r=C(r,255);var n,i,a=s(t,e,r),l=o(t,e,r),c=(a+l)/2;if(a==l)n=i=0;else{var u=a-l;switch(i=c>.5?u/(2-a-l):u/(a+l),a){case t:n=(e-r)/u+(e<r?6:0);break;case e:n=(r-t)/u+2;break;case r:n=(t-e)/u+4}n/=6}return{h:n,s:i,l:c}}function f(t,e,r){t=C(t,255),e=C(e,255),r=C(r,255);var n,i,a=s(t,e,r),l=o(t,e,r),c=a,u=a-l;if(i=0===a?0:u/a,a==l)n=0;else{switch(a){case t:n=(e-r)/u+(e<r?6:0);break;case e:n=(r-t)/u+2;break;case r:n=(t-e)/u+4}n/=6}return{h:n,s:i,v:c}}function h(t,e,r,n){var i=[O(a(t).toString(16)),O(a(e).toString(16)),O(a(r).toString(16))];return n&&i[0].charAt(0)==i[0].charAt(1)&&i[1].charAt(0)==i[1].charAt(1)&&i[2].charAt(0)==i[2].charAt(1)?i[0].charAt(0)+i[1].charAt(0)+i[2].charAt(0):i.join("")}function p(t,e,r,n){return[O(D(n)),O(a(t).toString(16)),O(a(e).toString(16)),O(a(r).toString(16))].join("")}function d(t,e){e=0===e?0:e||10;var r=c(t).toHsl();return r.s-=e/100,r.s=P(r.s),c(r)}function m(t,e){e=0===e?0:e||10;var r=c(t).toHsl();return r.s+=e/100,r.s=P(r.s),c(r)}function g(t){return c(t).desaturate(100)}function v(t,e){e=0===e?0:e||10;var r=c(t).toHsl();return r.l+=e/100,r.l=P(r.l),c(r)}function y(t,e){e=0===e?0:e||10;var r=c(t).toRgb();return r.r=s(0,o(255,r.r-a(-e/100*255))),r.g=s(0,o(255,r.g-a(-e/100*255))),r.b=s(0,o(255,r.b-a(-e/100*255))),c(r)}function x(t,e){e=0===e?0:e||10;var r=c(t).toHsl();return r.l-=e/100,r.l=P(r.l),c(r)}function b(t,e){var r=c(t).toHsl(),n=(r.h+e)%360;return r.h=n<0?360+n:n,c(r)}function _(t){var e=c(t).toHsl();return e.h=(e.h+180)%360,c(e)}function w(t){var e=c(t).toHsl(),r=e.h;return[c(t),c({h:(r+120)%360,s:e.s,l:e.l}),c({h:(r+240)%360,s:e.s,l:e.l})]}function T(t){var e=c(t).toHsl(),r=e.h;return[c(t),c({h:(r+90)%360,s:e.s,l:e.l}),c({h:(r+180)%360,s:e.s,l:e.l}),c({h:(r+270)%360,s:e.s,l:e.l})]}function k(t){var e=c(t).toHsl(),r=e.h;return[c(t),c({h:(r+72)%360,s:e.s,l:e.l}),c({h:(r+216)%360,s:e.s,l:e.l})]}function A(t,e,r){e=e||6,r=r||30;var n=c(t).toHsl(),i=360/r,a=[c(t)];for(n.h=(n.h-(i*e>>1)+720)%360;--e;)n.h=(n.h+i)%360,a.push(c(n));return a}function M(t,e){e=e||6;for(var r=c(t).toHsv(),n=r.h,i=r.s,a=r.v,o=[],s=1/e;e--;)o.push(c({h:n,s:i,v:a})),a=(a+s)%1;return o}c.prototype={isDark:function(){return this.getBrightness()<128},isLight:function(){return!this.isDark()},isValid:function(){return this._ok},getOriginalInput:function(){return this._originalInput},getFormat:function(){return this._format},getAlpha:function(){return this._a},getBrightness:function(){var t=this.toRgb();return(299*t.r+587*t.g+114*t.b)/1e3},getLuminance:function(){var e,r,n,i=this.toRgb();return e=i.r/255,r=i.g/255,n=i.b/255,.2126*(e<=.03928?e/12.92:t.pow((e+.055)/1.055,2.4))+.7152*(r<=.03928?r/12.92:t.pow((r+.055)/1.055,2.4))+.0722*(n<=.03928?n/12.92:t.pow((n+.055)/1.055,2.4))},setAlpha:function(t){return this._a=L(t),this._roundA=a(100*this._a)/100,this},toHsv:function(){var t=f(this._r,this._g,this._b);return{h:360*t.h,s:t.s,v:t.v,a:this._a}},toHsvString:function(){var t=f(this._r,this._g,this._b),e=a(360*t.h),r=a(100*t.s),n=a(100*t.v);return 1==this._a?"hsv("+e+", "+r+"%, "+n+"%)":"hsva("+e+", "+r+"%, "+n+"%, "+this._roundA+")"},toHsl:function(){var t=u(this._r,this._g,this._b);return{h:360*t.h,s:t.s,l:t.l,a:this._a}},toHslString:function(){var t=u(this._r,this._g,this._b),e=a(360*t.h),r=a(100*t.s),n=a(100*t.l);return 1==this._a?"hsl("+e+", "+r+"%, "+n+"%)":"hsla("+e+", "+r+"%, "+n+"%, "+this._roundA+")"},toHex:function(t){return h(this._r,this._g,this._b,t)},toHexString:function(t){return"#"+this.toHex(t)},toHex8:function(t){return function(t,e,r,n,i){var o=[O(a(t).toString(16)),O(a(e).toString(16)),O(a(r).toString(16)),O(D(n))];if(i&&o[0].charAt(0)==o[0].charAt(1)&&o[1].charAt(0)==o[1].charAt(1)&&o[2].charAt(0)==o[2].charAt(1)&&o[3].charAt(0)==o[3].charAt(1))return o[0].charAt(0)+o[1].charAt(0)+o[2].charAt(0)+o[3].charAt(0);return o.join("")}(this._r,this._g,this._b,this._a,t)},toHex8String:function(t){return"#"+this.toHex8(t)},toRgb:function(){return{r:a(this._r),g:a(this._g),b:a(this._b),a:this._a}},toRgbString:function(){return 1==this._a?"rgb("+a(this._r)+", "+a(this._g)+", "+a(this._b)+")":"rgba("+a(this._r)+", "+a(this._g)+", "+a(this._b)+", "+this._roundA+")"},toPercentageRgb:function(){return{r:a(100*C(this._r,255))+"%",g:a(100*C(this._g,255))+"%",b:a(100*C(this._b,255))+"%",a:this._a}},toPercentageRgbString:function(){return 1==this._a?"rgb("+a(100*C(this._r,255))+"%, "+a(100*C(this._g,255))+"%, "+a(100*C(this._b,255))+"%)":"rgba("+a(100*C(this._r,255))+"%, "+a(100*C(this._g,255))+"%, "+a(100*C(this._b,255))+"%, "+this._roundA+")"},toName:function(){return 0===this._a?"transparent":!(this._a<1)&&(E[h(this._r,this._g,this._b,!0)]||!1)},toFilter:function(t){var e="#"+p(this._r,this._g,this._b,this._a),r=e,n=this._gradientType?"GradientType = 1, ":"";if(t){var i=c(t);r="#"+p(i._r,i._g,i._b,i._a)}return"progid:DXImageTransform.Microsoft.gradient("+n+"startColorstr="+e+",endColorstr="+r+")"},toString:function(t){var e=!!t;t=t||this._format;var r=!1,n=this._a<1&&this._a>=0;return e||!n||"hex"!==t&&"hex6"!==t&&"hex3"!==t&&"hex4"!==t&&"hex8"!==t&&"name"!==t?("rgb"===t&&(r=this.toRgbString()),"prgb"===t&&(r=this.toPercentageRgbString()),"hex"!==t&&"hex6"!==t||(r=this.toHexString()),"hex3"===t&&(r=this.toHexString(!0)),"hex4"===t&&(r=this.toHex8String(!0)),"hex8"===t&&(r=this.toHex8String()),"name"===t&&(r=this.toName()),"hsl"===t&&(r=this.toHslString()),"hsv"===t&&(r=this.toHsvString()),r||this.toHexString()):"name"===t&&0===this._a?this.toName():this.toRgbString()},clone:function(){return c(this.toString())},_applyModification:function(t,e){var r=t.apply(null,[this].concat([].slice.call(e)));return this._r=r._r,this._g=r._g,this._b=r._b,this.setAlpha(r._a),this},lighten:function(){return this._applyModification(v,arguments)},brighten:function(){return this._applyModification(y,arguments)},darken:function(){return this._applyModification(x,arguments)},desaturate:function(){return this._applyModification(d,arguments)},saturate:function(){return this._applyModification(m,arguments)},greyscale:function(){return this._applyModification(g,arguments)},spin:function(){return this._applyModification(b,arguments)},_applyCombination:function(t,e){return t.apply(null,[this].concat([].slice.call(e)))},analogous:function(){return this._applyCombination(A,arguments)},complement:function(){return this._applyCombination(_,arguments)},monochromatic:function(){return this._applyCombination(M,arguments)},splitcomplement:function(){return this._applyCombination(k,arguments)},triad:function(){return this._applyCombination(w,arguments)},tetrad:function(){return this._applyCombination(T,arguments)}},c.fromRatio=function(t,e){if("object"==typeof t){var r={};for(var n in t)t.hasOwnProperty(n)&&(r[n]="a"===n?t[n]:z(t[n]));t=r}return c(t,e)},c.equals=function(t,e){return!(!t||!e)&&c(t).toRgbString()==c(e).toRgbString()},c.random=function(){return c.fromRatio({r:l(),g:l(),b:l()})},c.mix=function(t,e,r){r=0===r?0:r||50;var n=c(t).toRgb(),i=c(e).toRgb(),a=r/100;return c({r:(i.r-n.r)*a+n.r,g:(i.g-n.g)*a+n.g,b:(i.b-n.b)*a+n.b,a:(i.a-n.a)*a+n.a})},c.readability=function(e,r){var n=c(e),i=c(r);return(t.max(n.getLuminance(),i.getLuminance())+.05)/(t.min(n.getLuminance(),i.getLuminance())+.05)},c.isReadable=function(t,e,r){var n,i,a=c.readability(t,e);switch(i=!1,(n=function(t){var e,r;e=((t=t||{level:"AA",size:"small"}).level||"AA").toUpperCase(),r=(t.size||"small").toLowerCase(),"AA"!==e&&"AAA"!==e&&(e="AA");"small"!==r&&"large"!==r&&(r="small");return{level:e,size:r}}(r)).level+n.size){case"AAsmall":case"AAAlarge":i=a>=4.5;break;case"AAlarge":i=a>=3;break;case"AAAsmall":i=a>=7}return i},c.mostReadable=function(t,e,r){var n,i,a,o,s=null,l=0;i=(r=r||{}).includeFallbackColors,a=r.level,o=r.size;for(var u=0;u<e.length;u++)(n=c.readability(t,e[u]))>l&&(l=n,s=c(e[u]));return c.isReadable(t,s,{level:a,size:o})||!i?s:(r.includeFallbackColors=!1,c.mostReadable(t,["#fff","#000"],r))};var S=c.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"663399",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},E=c.hexNames=function(t){var e={};for(var r in t)t.hasOwnProperty(r)&&(e[t[r]]=r);return e}(S);function L(t){return t=parseFloat(t),(isNaN(t)||t<0||t>1)&&(t=1),t}function C(e,r){(function(t){return"string"==typeof t&&-1!=t.indexOf(".")&&1===parseFloat(t)})(e)&&(e="100%");var n=function(t){return"string"==typeof t&&-1!=t.indexOf("%")}(e);return e=o(r,s(0,parseFloat(e))),n&&(e=parseInt(e*r,10)/100),t.abs(e-r)<1e-6?1:e%r/parseFloat(r)}function P(t){return o(1,s(0,t))}function I(t){return parseInt(t,16)}function O(t){return 1==t.length?"0"+t:""+t}function z(t){return t<=1&&(t=100*t+"%"),t}function D(e){return t.round(255*parseFloat(e)).toString(16)}function R(t){return I(t)/255}var F,B,N,j=(B="[\\s|\\(]+("+(F="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)")+")[,|\\s]+("+F+")[,|\\s]+("+F+")\\s*\\)?",N="[\\s|\\(]+("+F+")[,|\\s]+("+F+")[,|\\s]+("+F+")[,|\\s]+("+F+")\\s*\\)?",{CSS_UNIT:new RegExp(F),rgb:new RegExp("rgb"+B),rgba:new RegExp("rgba"+N),hsl:new RegExp("hsl"+B),hsla:new RegExp("hsla"+N),hsv:new RegExp("hsv"+B),hsva:new RegExp("hsva"+N),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/});function U(t){return!!j.CSS_UNIT.exec(t)}void 0!==e&&e.exports?e.exports=c:window.tinycolor=c}(Math)},{}],313:[function(t,e,r){"use strict";e.exports=i,e.exports.float32=e.exports.float=i,e.exports.fract32=e.exports.fract=function(t,e){if(t.length){if(t instanceof Float32Array)return new Float32Array(t.length);e instanceof Float32Array||(e=i(t));for(var r=0,n=e.length;r<n;r++)e[r]=t[r]-e[r];return e}return i(t-i(t))};var n=new Float32Array(1);function i(t){return t.length?t instanceof Float32Array?t:new Float32Array(t):(n[0]=t,n[0])}},{}],314:[function(t,e,r){"use strict";var n=t("parse-unit");e.exports=a;function i(t,e){var r=n(getComputedStyle(t).getPropertyValue(e));return r[0]*a(r[1],t)}function a(t,e){switch(e=e||document.body,t=(t||"px").trim().toLowerCase(),e!==window&&e!==document||(e=document.body),t){case"%":return e.clientHeight/100;case"ch":case"ex":return function(t,e){var r=document.createElement("div");r.style["font-size"]="128"+t,e.appendChild(r);var n=i(r,"font-size")/128;return e.removeChild(r),n}(t,e);case"em":return i(e,"font-size");case"rem":return i(document.body,"font-size");case"vw":return window.innerWidth/100;case"vh":return window.innerHeight/100;case"vmin":return Math.min(window.innerWidth,window.innerHeight)/100;case"vmax":return Math.max(window.innerWidth,window.innerHeight)/100;case"in":return 96;case"cm":return 96/2.54;case"mm":return 96/25.4;case"pt":return 96/72;case"pc":return 16}return 1}},{"parse-unit":251}],315:[function(t,e,r){!function(t,n){"object"==typeof r&&void 0!==e?n(r):n((t=t||self).topojson=t.topojson||{})}(this,(function(t){"use strict";function e(t){return t}function r(t){if(null==t)return e;var r,n,i=t.scale[0],a=t.scale[1],o=t.translate[0],s=t.translate[1];return function(t,e){e||(r=n=0);var l=2,c=t.length,u=new Array(c);for(u[0]=(r+=t[0])*i+o,u[1]=(n+=t[1])*a+s;l<c;)u[l]=t[l],++l;return u}}function n(t){var e,n=r(t.transform),i=1/0,a=i,o=-i,s=-i;function l(t){(t=n(t))[0]<i&&(i=t[0]),t[0]>o&&(o=t[0]),t[1]<a&&(a=t[1]),t[1]>s&&(s=t[1])}function c(t){switch(t.type){case"GeometryCollection":t.geometries.forEach(c);break;case"Point":l(t.coordinates);break;case"MultiPoint":t.coordinates.forEach(l)}}for(e in t.arcs.forEach((function(t){for(var e,r=-1,l=t.length;++r<l;)(e=n(t[r],r))[0]<i&&(i=e[0]),e[0]>o&&(o=e[0]),e[1]<a&&(a=e[1]),e[1]>s&&(s=e[1])})),t.objects)c(t.objects[e]);return[i,a,o,s]}function i(t,e){var r=e.id,n=e.bbox,i=null==e.properties?{}:e.properties,o=a(t,e);return null==r&&null==n?{type:"Feature",properties:i,geometry:o}:null==n?{type:"Feature",id:r,properties:i,geometry:o}:{type:"Feature",id:r,bbox:n,properties:i,geometry:o}}function a(t,e){var n=r(t.transform),i=t.arcs;function a(t,e){e.length&&e.pop();for(var r=i[t<0?~t:t],a=0,o=r.length;a<o;++a)e.push(n(r[a],a));t<0&&function(t,e){for(var r,n=t.length,i=n-e;i<--n;)r=t[i],t[i++]=t[n],t[n]=r}(e,o)}function o(t){return n(t)}function s(t){for(var e=[],r=0,n=t.length;r<n;++r)a(t[r],e);return e.length<2&&e.push(e[0]),e}function l(t){for(var e=s(t);e.length<4;)e.push(e[0]);return e}function c(t){return t.map(l)}return function t(e){var r,n=e.type;switch(n){case"GeometryCollection":return{type:n,geometries:e.geometries.map(t)};case"Point":r=o(e.coordinates);break;case"MultiPoint":r=e.coordinates.map(o);break;case"LineString":r=s(e.arcs);break;case"MultiLineString":r=e.arcs.map(s);break;case"Polygon":r=c(e.arcs);break;case"MultiPolygon":r=e.arcs.map(c);break;default:return null}return{type:n,coordinates:r}}(e)}function o(t,e){var r={},n={},i={},a=[],o=-1;function s(t,e){for(var n in t){var i=t[n];delete e[i.start],delete i.start,delete i.end,i.forEach((function(t){r[t<0?~t:t]=1})),a.push(i)}}return e.forEach((function(r,n){var i,a=t.arcs[r<0?~r:r];a.length<3&&!a[1][0]&&!a[1][1]&&(i=e[++o],e[o]=r,e[n]=i)})),e.forEach((function(e){var r,a,o=function(e){var r,n=t.arcs[e<0?~e:e],i=n[0];t.transform?(r=[0,0],n.forEach((function(t){r[0]+=t[0],r[1]+=t[1]}))):r=n[n.length-1];return e<0?[r,i]:[i,r]}(e),s=o[0],l=o[1];if(r=i[s])if(delete i[r.end],r.push(e),r.end=l,a=n[l]){delete n[a.start];var c=a===r?r:r.concat(a);n[c.start=r.start]=i[c.end=a.end]=c}else n[r.start]=i[r.end]=r;else if(r=n[l])if(delete n[r.start],r.unshift(e),r.start=s,a=i[s]){delete i[a.end];var u=a===r?r:a.concat(r);n[u.start=a.start]=i[u.end=r.end]=u}else n[r.start]=i[r.end]=r;else n[(r=[e]).start=s]=i[r.end=l]=r})),s(i,n),s(n,i),e.forEach((function(t){r[t<0?~t:t]||a.push([t])})),a}function s(t,e,r){var n,i,a;if(arguments.length>1)n=l(t,e,r);else for(i=0,n=new Array(a=t.arcs.length);i<a;++i)n[i]=i;return{type:"MultiLineString",arcs:o(t,n)}}function l(t,e,r){var n,i=[],a=[];function o(t){var e=t<0?~t:t;(a[e]||(a[e]=[])).push({i:t,g:n})}function s(t){t.forEach(o)}function l(t){t.forEach(s)}return function t(e){switch(n=e,e.type){case"GeometryCollection":e.geometries.forEach(t);break;case"LineString":s(e.arcs);break;case"MultiLineString":case"Polygon":l(e.arcs);break;case"MultiPolygon":!function(t){t.forEach(l)}(e.arcs)}}(e),a.forEach(null==r?function(t){i.push(t[0].i)}:function(t){r(t[0].g,t[t.length-1].g)&&i.push(t[0].i)}),i}function c(t,e){var r={},n=[],i=[];function s(t){t.forEach((function(e){e.forEach((function(e){(r[e=e<0?~e:e]||(r[e]=[])).push(t)}))})),n.push(t)}function l(e){return function(t){for(var e,r=-1,n=t.length,i=t[n-1],a=0;++r<n;)e=i,i=t[r],a+=e[0]*i[1]-e[1]*i[0];return Math.abs(a)}(a(t,{type:"Polygon",arcs:[e]}).coordinates[0])}return e.forEach((function t(e){switch(e.type){case"GeometryCollection":e.geometries.forEach(t);break;case"Polygon":s(e.arcs);break;case"MultiPolygon":e.arcs.forEach(s)}})),n.forEach((function(t){if(!t._){var e=[],n=[t];for(t._=1,i.push(e);t=n.pop();)e.push(t),t.forEach((function(t){t.forEach((function(t){r[t<0?~t:t].forEach((function(t){t._||(t._=1,n.push(t))}))}))}))}})),n.forEach((function(t){delete t._})),{type:"MultiPolygon",arcs:i.map((function(e){var n,i=[];if(e.forEach((function(t){t.forEach((function(t){t.forEach((function(t){r[t<0?~t:t].length<2&&i.push(t)}))}))})),(n=(i=o(t,i)).length)>1)for(var a,s,c=1,u=l(i[0]);c<n;++c)(a=l(i[c]))>u&&(s=i[0],i[0]=i[c],i[c]=s,u=a);return i})).filter((function(t){return t.length>0}))}}function u(t,e){for(var r=0,n=t.length;r<n;){var i=r+n>>>1;t[i]<e?r=i+1:n=i}return r}function f(t){if(null==t)return e;var r,n,i=t.scale[0],a=t.scale[1],o=t.translate[0],s=t.translate[1];return function(t,e){e||(r=n=0);var l=2,c=t.length,u=new Array(c),f=Math.round((t[0]-o)/i),h=Math.round((t[1]-s)/a);for(u[0]=f-r,r=f,u[1]=h-n,n=h;l<c;)u[l]=t[l],++l;return u}}t.bbox=n,t.feature=function(t,e){return"string"==typeof e&&(e=t.objects[e]),"GeometryCollection"===e.type?{type:"FeatureCollection",features:e.geometries.map((function(e){return i(t,e)}))}:i(t,e)},t.merge=function(t){return a(t,c.apply(this,arguments))},t.mergeArcs=c,t.mesh=function(t){return a(t,s.apply(this,arguments))},t.meshArcs=s,t.neighbors=function(t){var e={},r=t.map((function(){return[]}));function n(t,r){t.forEach((function(t){t<0&&(t=~t);var n=e[t];n?n.push(r):e[t]=[r]}))}function i(t,e){t.forEach((function(t){n(t,e)}))}var a={LineString:n,MultiLineString:i,Polygon:i,MultiPolygon:function(t,e){t.forEach((function(t){i(t,e)}))}};for(var o in t.forEach((function t(e,r){"GeometryCollection"===e.type?e.geometries.forEach((function(e){t(e,r)})):e.type in a&&a[e.type](e.arcs,r)})),e)for(var s=e[o],l=s.length,c=0;c<l;++c)for(var f=c+1;f<l;++f){var h,p=s[c],d=s[f];(h=r[p])[o=u(h,d)]!==d&&h.splice(o,0,d),(h=r[d])[o=u(h,p)]!==p&&h.splice(o,0,p)}return r},t.quantize=function(t,e){if(t.transform)throw new Error("already quantized");if(e&&e.scale)l=t.bbox;else{if(!((r=Math.floor(e))>=2))throw new Error("n must be \u22652");var r,i=(l=t.bbox||n(t))[0],a=l[1],o=l[2],s=l[3];e={scale:[o-i?(o-i)/(r-1):1,s-a?(s-a)/(r-1):1],translate:[i,a]}}var l,c,u=f(e),h=t.objects,p={};function d(t){return u(t)}function m(t){var e;switch(t.type){case"GeometryCollection":e={type:"GeometryCollection",geometries:t.geometries.map(m)};break;case"Point":e={type:"Point",coordinates:d(t.coordinates)};break;case"MultiPoint":e={type:"MultiPoint",coordinates:t.coordinates.map(d)};break;default:return t}return null!=t.id&&(e.id=t.id),null!=t.bbox&&(e.bbox=t.bbox),null!=t.properties&&(e.properties=t.properties),e}for(c in h)p[c]=m(h[c]);return{type:"Topology",bbox:l,transform:e,objects:p,arcs:t.arcs.map((function(t){var e,r=0,n=1,i=t.length,a=new Array(i);for(a[0]=u(t[0],0);++r<i;)((e=u(t[r],r))[0]||e[1])&&(a[n++]=e);return 1===n&&(a[n++]=[0,0]),a.length=n,a}))}},t.transform=r,t.untransform=f,Object.defineProperty(t,"__esModule",{value:!0})}))},{}],316:[function(t,e,r){"use strict";var n=t("../prototype/is");e.exports=function(t){if("function"!=typeof t)return!1;if(!hasOwnProperty.call(t,"length"))return!1;try{if("number"!=typeof t.length)return!1;if("function"!=typeof t.call)return!1;if("function"!=typeof t.apply)return!1}catch(t){return!1}return!n(t)}},{"../prototype/is":323}],317:[function(t,e,r){"use strict";var n=t("../value/is"),i=t("../object/is"),a=t("../string/coerce"),o=t("./to-short-string"),s=function(t,e){return t.replace("%v",o(e))};e.exports=function(t,e,r){if(!i(r))throw new TypeError(s(e,t));if(!n(t)){if("default"in r)return r.default;if(r.isOptional)return null}var o=a(r.errorMessage);throw n(o)||(o=e),new TypeError(s(o,t))}},{"../object/is":320,"../string/coerce":324,"../value/is":326,"./to-short-string":319}],318:[function(t,e,r){"use strict";e.exports=function(t){try{return t.toString()}catch(e){try{return String(t)}catch(t){return null}}}},{}],319:[function(t,e,r){"use strict";var n=t("./safe-to-string"),i=/[\n\r\u2028\u2029]/g;e.exports=function(t){var e=n(t);return null===e?"<Non-coercible to string value>":(e.length>100&&(e=e.slice(0,99)+"\u2026"),e=e.replace(i,(function(t){switch(t){case"\n":return"\\n";case"\r":return"\\r";case"\u2028":return"\\u2028";case"\u2029":return"\\u2029";default:throw new Error("Unexpected character")}})))}},{"./safe-to-string":318}],320:[function(t,e,r){"use strict";var n=t("../value/is"),i={object:!0,function:!0,undefined:!0};e.exports=function(t){return!!n(t)&&hasOwnProperty.call(i,typeof t)}},{"../value/is":326}],321:[function(t,e,r){"use strict";var n=t("../lib/resolve-exception"),i=t("./is");e.exports=function(t){return i(t)?t:n(t,"%v is not a plain function",arguments[1])}},{"../lib/resolve-exception":317,"./is":322}],322:[function(t,e,r){"use strict";var n=t("../function/is"),i=/^\s*class[\s{/}]/,a=Function.prototype.toString;e.exports=function(t){return!!n(t)&&!i.test(a.call(t))}},{"../function/is":316}],323:[function(t,e,r){"use strict";var n=t("../object/is");e.exports=function(t){if(!n(t))return!1;try{return!!t.constructor&&t.constructor.prototype===t}catch(t){return!1}}},{"../object/is":320}],324:[function(t,e,r){"use strict";var n=t("../value/is"),i=t("../object/is"),a=Object.prototype.toString;e.exports=function(t){if(!n(t))return null;if(i(t)){var e=t.toString;if("function"!=typeof e)return null;if(e===a)return null}try{return""+t}catch(t){return null}}},{"../object/is":320,"../value/is":326}],325:[function(t,e,r){"use strict";var n=t("../lib/resolve-exception"),i=t("./is");e.exports=function(t){return i(t)?t:n(t,"Cannot use %v",arguments[1])}},{"../lib/resolve-exception":317,"./is":326}],326:[function(t,e,r){"use strict";e.exports=function(t){return null!=t}},{}],327:[function(t,e,r){(function(e){(function(){"use strict";var n=t("bit-twiddle"),i=t("dup"),a=t("buffer").Buffer;e.__TYPEDARRAY_POOL||(e.__TYPEDARRAY_POOL={UINT8:i([32,0]),UINT16:i([32,0]),UINT32:i([32,0]),BIGUINT64:i([32,0]),INT8:i([32,0]),INT16:i([32,0]),INT32:i([32,0]),BIGINT64:i([32,0]),FLOAT:i([32,0]),DOUBLE:i([32,0]),DATA:i([32,0]),UINT8C:i([32,0]),BUFFER:i([32,0])});var o="undefined"!=typeof Uint8ClampedArray,s="undefined"!=typeof BigUint64Array,l="undefined"!=typeof BigInt64Array,c=e.__TYPEDARRAY_POOL;c.UINT8C||(c.UINT8C=i([32,0])),c.BIGUINT64||(c.BIGUINT64=i([32,0])),c.BIGINT64||(c.BIGINT64=i([32,0])),c.BUFFER||(c.BUFFER=i([32,0]));var u=c.DATA,f=c.BUFFER;function h(t){if(t){var e=t.length||t.byteLength,r=n.log2(e);u[r].push(t)}}function p(t){t=n.nextPow2(t);var e=n.log2(t),r=u[e];return r.length>0?r.pop():new ArrayBuffer(t)}function d(t){return new Uint8Array(p(t),0,t)}function m(t){return new Uint16Array(p(2*t),0,t)}function g(t){return new Uint32Array(p(4*t),0,t)}function v(t){return new Int8Array(p(t),0,t)}function y(t){return new Int16Array(p(2*t),0,t)}function x(t){return new Int32Array(p(4*t),0,t)}function b(t){return new Float32Array(p(4*t),0,t)}function _(t){return new Float64Array(p(8*t),0,t)}function w(t){return o?new Uint8ClampedArray(p(t),0,t):d(t)}function T(t){return s?new BigUint64Array(p(8*t),0,t):null}function k(t){return l?new BigInt64Array(p(8*t),0,t):null}function A(t){return new DataView(p(t),0,t)}function M(t){t=n.nextPow2(t);var e=n.log2(t),r=f[e];return r.length>0?r.pop():new a(t)}r.free=function(t){if(a.isBuffer(t))f[n.log2(t.length)].push(t);else{if("[object ArrayBuffer]"!==Object.prototype.toString.call(t)&&(t=t.buffer),!t)return;var e=t.length||t.byteLength,r=0|n.log2(e);u[r].push(t)}},r.freeUint8=r.freeUint16=r.freeUint32=r.freeBigUint64=r.freeInt8=r.freeInt16=r.freeInt32=r.freeBigInt64=r.freeFloat32=r.freeFloat=r.freeFloat64=r.freeDouble=r.freeUint8Clamped=r.freeDataView=function(t){h(t.buffer)},r.freeArrayBuffer=h,r.freeBuffer=function(t){f[n.log2(t.length)].push(t)},r.malloc=function(t,e){if(void 0===e||"arraybuffer"===e)return p(t);switch(e){case"uint8":return d(t);case"uint16":return m(t);case"uint32":return g(t);case"int8":return v(t);case"int16":return y(t);case"int32":return x(t);case"float":case"float32":return b(t);case"double":case"float64":return _(t);case"uint8_clamped":return w(t);case"bigint64":return k(t);case"biguint64":return T(t);case"buffer":return M(t);case"data":case"dataview":return A(t);default:return null}return null},r.mallocArrayBuffer=p,r.mallocUint8=d,r.mallocUint16=m,r.mallocUint32=g,r.mallocInt8=v,r.mallocInt16=y,r.mallocInt32=x,r.mallocFloat32=r.mallocFloat=b,r.mallocFloat64=r.mallocDouble=_,r.mallocUint8Clamped=w,r.mallocBigUint64=T,r.mallocBigInt64=k,r.mallocDataView=A,r.mallocBuffer=M,r.clearCache=function(){for(var t=0;t<32;++t)c.UINT8[t].length=0,c.UINT16[t].length=0,c.UINT32[t].length=0,c.INT8[t].length=0,c.INT16[t].length=0,c.INT32[t].length=0,c.FLOAT[t].length=0,c.DOUBLE[t].length=0,c.BIGUINT64[t].length=0,c.BIGINT64[t].length=0,c.UINT8C[t].length=0,u[t].length=0,f[t].length=0}}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":81,buffer:85,dup:128}],328:[function(t,e,r){var n=/[\'\"]/;e.exports=function(t){return t?(n.test(t.charAt(0))&&(t=t.substr(1)),n.test(t.charAt(t.length-1))&&(t=t.substr(0,t.length-1)),t):""}},{}],329:[function(t,e,r){"use strict";e.exports=function(t,e,r){Array.isArray(r)||(r=[].slice.call(arguments,2));for(var n=0,i=r.length;n<i;n++){var a=r[n];for(var o in a)if((void 0===e[o]||Array.isArray(e[o])||t[o]!==e[o])&&o in e){var s;if(!0===a[o])s=e[o];else{if(!1===a[o])continue;if("function"==typeof a[o]&&void 0===(s=a[o](e[o],t,e)))continue}t[o]=s}}return t}},{}],330:[function(t,e,r){(function(t){(function(){function r(e){try{if(!t.localStorage)return!1}catch(t){return!1}var r=t.localStorage[e];return null!=r&&"true"===String(r).toLowerCase()}e.exports=function(t,e){if(r("noDeprecation"))return t;var n=!1;return function(){if(!n){if(r("throwDeprecation"))throw new Error(e);r("traceDeprecation")?console.trace(e):console.warn(e),n=!0}return t.apply(this,arguments)}}}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],331:[function(t,e,r){var n=t("get-canvas-context");e.exports=function(t){return n("webgl",t)}},{"get-canvas-context":194}],332:[function(t,e,r){var n=t("../main"),i=t("object-assign"),a=n.instance();function o(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}o.prototype=new n.baseCalendar,i(o.prototype,{name:"Chinese",jdEpoch:1721425.5,hasYearZero:!1,minMonth:0,firstMonth:0,minDay:1,regionalOptions:{"":{name:"Chinese",epochs:["BEC","EC"],monthNumbers:function(t,e){if("string"==typeof t){var r=t.match(l);return r?r[0]:""}var n=this._validateYear(t),i=t.month(),a=""+this.toChineseMonth(n,i);return e&&a.length<2&&(a="0"+a),this.isIntercalaryMonth(n,i)&&(a+="i"),a},monthNames:function(t){if("string"==typeof t){var e=t.match(c);return e?e[0]:""}var r=this._validateYear(t),n=t.month(),i=["\u4e00\u6708","\u4e8c\u6708","\u4e09\u6708","\u56db\u6708","\u4e94\u6708","\u516d\u6708","\u4e03\u6708","\u516b\u6708","\u4e5d\u6708","\u5341\u6708","\u5341\u4e00\u6708","\u5341\u4e8c\u6708"][this.toChineseMonth(r,n)-1];return this.isIntercalaryMonth(r,n)&&(i="\u95f0"+i),i},monthNamesShort:function(t){if("string"==typeof t){var e=t.match(u);return e?e[0]:""}var r=this._validateYear(t),n=t.month(),i=["\u4e00","\u4e8c","\u4e09","\u56db","\u4e94","\u516d","\u4e03","\u516b","\u4e5d","\u5341","\u5341\u4e00","\u5341\u4e8c"][this.toChineseMonth(r,n)-1];return this.isIntercalaryMonth(r,n)&&(i="\u95f0"+i),i},parseMonth:function(t,e){t=this._validateYear(t);var r,n=parseInt(e);if(isNaN(n))"\u95f0"===e[0]&&(r=!0,e=e.substring(1)),"\u6708"===e[e.length-1]&&(e=e.substring(0,e.length-1)),n=1+["\u4e00","\u4e8c","\u4e09","\u56db","\u4e94","\u516d","\u4e03","\u516b","\u4e5d","\u5341","\u5341\u4e00","\u5341\u4e8c"].indexOf(e);else{var i=e[e.length-1];r="i"===i||"I"===i}return this.toMonthIndex(t,n,r)},dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayNamesShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dayNamesMin:["Su","Mo","Tu","We","Th","Fr","Sa"],digits:null,dateFormat:"yyyy/mm/dd",firstDay:1,isRTL:!1}},_validateYear:function(t,e){if(t.year&&(t=t.year()),"number"!=typeof t||t<1888||t>2111)throw e.replace(/\{0\}/,this.local.name);return t},toMonthIndex:function(t,e,r){var i=this.intercalaryMonth(t);if(r&&e!==i||e<1||e>12)throw n.local.invalidMonth.replace(/\{0\}/,this.local.name);return i?!r&&e<=i?e-1:e:e-1},toChineseMonth:function(t,e){t.year&&(e=(t=t.year()).month());var r=this.intercalaryMonth(t);if(e<0||e>(r?12:11))throw n.local.invalidMonth.replace(/\{0\}/,this.local.name);return r?e<r?e+1:e:e+1},intercalaryMonth:function(t){return t=this._validateYear(t),f[t-f[0]]>>13},isIntercalaryMonth:function(t,e){t.year&&(e=(t=t.year()).month());var r=this.intercalaryMonth(t);return!!r&&r===e},leapYear:function(t){return 0!==this.intercalaryMonth(t)},weekOfYear:function(t,e,r){var i,o=this._validateYear(t,n.local.invalidyear),s=h[o-h[0]],l=s>>9&4095,c=s>>5&15,u=31&s;(i=a.newDate(l,c,u)).add(4-(i.dayOfWeek()||7),"d");var f=this.toJD(t,e,r)-i.toJD();return 1+Math.floor(f/7)},monthsInYear:function(t){return this.leapYear(t)?13:12},daysInMonth:function(t,e){t.year&&(e=t.month(),t=t.year()),t=this._validateYear(t);var r=f[t-f[0]];if(e>(r>>13?12:11))throw n.local.invalidMonth.replace(/\{0\}/,this.local.name);return r&1<<12-e?30:29},weekDay:function(t,e,r){return(this.dayOfWeek(t,e,r)||7)<6},toJD:function(t,e,r){var i=this._validate(t,s,r,n.local.invalidDate);t=this._validateYear(i.year()),e=i.month(),r=i.day();var o=this.isIntercalaryMonth(t,e),s=this.toChineseMonth(t,e),l=function(t,e,r,n,i){var a,o,s;if("object"==typeof t)o=t,a=e||{};else{var l;if(!("number"==typeof t&&t>=1888&&t<=2111))throw new Error("Lunar year outside range 1888-2111");if(!("number"==typeof e&&e>=1&&e<=12))throw new Error("Lunar month outside range 1 - 12");if(!("number"==typeof r&&r>=1&&r<=30))throw new Error("Lunar day outside range 1 - 30");"object"==typeof n?(l=!1,a=n):(l=!!n,a=i||{}),o={year:t,month:e,day:r,isIntercalary:l}}s=o.day-1;var c,u=f[o.year-f[0]],p=u>>13;c=p&&(o.month>p||o.isIntercalary)?o.month:o.month-1;for(var d=0;d<c;d++){s+=u&1<<12-d?30:29}var m=h[o.year-h[0]],g=new Date(m>>9&4095,(m>>5&15)-1,(31&m)+s);return a.year=g.getFullYear(),a.month=1+g.getMonth(),a.day=g.getDate(),a}(t,s,r,o);return a.toJD(l.year,l.month,l.day)},fromJD:function(t){var e=a.fromJD(t),r=function(t,e,r,n){var i,a;if("object"==typeof t)i=t,a=e||{};else{if(!("number"==typeof t&&t>=1888&&t<=2111))throw new Error("Solar year outside range 1888-2111");if(!("number"==typeof e&&e>=1&&e<=12))throw new Error("Solar month outside range 1 - 12");if(!("number"==typeof r&&r>=1&&r<=31))throw new Error("Solar day outside range 1 - 31");i={year:t,month:e,day:r},a=n||{}}var o=h[i.year-h[0]],s=i.year<<9|i.month<<5|i.day;a.year=s>=o?i.year:i.year-1,o=h[a.year-h[0]];var l,c=new Date(o>>9&4095,(o>>5&15)-1,31&o),u=new Date(i.year,i.month-1,i.day);l=Math.round((u-c)/864e5);var p,d=f[a.year-f[0]];for(p=0;p<13;p++){var m=d&1<<12-p?30:29;if(l<m)break;l-=m}var g=d>>13;!g||p<g?(a.isIntercalary=!1,a.month=1+p):p===g?(a.isIntercalary=!0,a.month=p):(a.isIntercalary=!1,a.month=p);return a.day=1+l,a}(e.year(),e.month(),e.day()),n=this.toMonthIndex(r.year,r.month,r.isIntercalary);return this.newDate(r.year,n,r.day)},fromString:function(t){var e=t.match(s),r=this._validateYear(+e[1]),n=+e[2],i=!!e[3],a=this.toMonthIndex(r,n,i),o=+e[4];return this.newDate(r,a,o)},add:function(t,e,r){var n=t.year(),i=t.month(),a=this.isIntercalaryMonth(n,i),s=this.toChineseMonth(n,i),l=Object.getPrototypeOf(o.prototype).add.call(this,t,e,r);if("y"===r){var c=l.year(),u=l.month(),f=this.isIntercalaryMonth(c,s),h=a&&f?this.toMonthIndex(c,s,!0):this.toMonthIndex(c,s,!1);h!==u&&l.month(h)}return l}});var s=/^\s*(-?\d\d\d\d|\d\d)[-/](\d?\d)([iI]?)[-/](\d?\d)/m,l=/^\d?\d[iI]?/m,c=/^\u95f0?\u5341?[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d]?\u6708/m,u=/^\u95f0?\u5341?[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d]?/m;n.calendars.chinese=o;var f=[1887,5780,5802,19157,2742,50359,1198,2646,46378,7466,3412,30122,5482,67949,2396,5294,43597,6732,6954,36181,2772,4954,18781,2396,54427,5274,6730,47781,5800,6868,21210,4790,59703,2350,5270,46667,3402,3496,38325,1388,4782,18735,2350,52374,6804,7498,44457,2906,1388,29294,4700,63789,6442,6804,56138,5802,2772,38235,1210,4698,22827,5418,63125,3476,5802,43701,2484,5302,27223,2646,70954,7466,3412,54698,5482,2412,38062,5294,2636,32038,6954,60245,2772,4826,43357,2394,5274,39501,6730,72357,5800,5844,53978,4790,2358,38039,5270,87627,3402,3496,54708,5484,4782,43311,2350,3222,27978,7498,68965,2904,5484,45677,4700,6444,39573,6804,6986,19285,2772,62811,1210,4698,47403,5418,5780,38570,5546,76469,2420,5302,51799,2646,5414,36501,3412,5546,18869,2412,54446,5276,6732,48422,6822,2900,28010,4826,92509,2394,5274,55883,6730,6820,47956,5812,2778,18779,2358,62615,5270,5450,46757,3492,5556,27318,4718,67887,2350,3222,52554,7498,3428,38252,5468,4700,31022,6444,64149,6804,6986,43861,2772,5338,35421,2650,70955,5418,5780,54954,5546,2740,38074,5302,2646,29991,3366,61011,3412,5546,43445,2412,5294,35406,6732,72998,6820,6996,52586,2778,2396,38045,5274,6698,23333,6820,64338,5812,2746,43355,2358,5270,39499,5450,79525,3492,5548],h=[1887,966732,967231,967733,968265,968766,969297,969798,970298,970829,971330,971830,972362,972863,973395,973896,974397,974928,975428,975929,976461,976962,977462,977994,978494,979026,979526,980026,980558,981059,981559,982091,982593,983124,983624,984124,984656,985157,985656,986189,986690,987191,987722,988222,988753,989254,989754,990286,990788,991288,991819,992319,992851,993352,993851,994383,994885,995385,995917,996418,996918,997450,997949,998481,998982,999483,1000014,1000515,1001016,1001548,1002047,1002578,1003080,1003580,1004111,1004613,1005113,1005645,1006146,1006645,1007177,1007678,1008209,1008710,1009211,1009743,1010243,1010743,1011275,1011775,1012306,1012807,1013308,1013840,1014341,1014841,1015373,1015874,1016404,1016905,1017405,1017937,1018438,1018939,1019471,1019972,1020471,1021002,1021503,1022035,1022535,1023036,1023568,1024069,1024568,1025100,1025601,1026102,1026633,1027133,1027666,1028167,1028666,1029198,1029699,1030199,1030730,1031231,1031763,1032264,1032764,1033296,1033797,1034297,1034828,1035329,1035830,1036362,1036861,1037393,1037894,1038394,1038925,1039427,1039927,1040459,1040959,1041491,1041992,1042492,1043023,1043524,1044024,1044556,1045057,1045558,1046090,1046590,1047121,1047622,1048122,1048654,1049154,1049655,1050187,1050689,1051219,1051720,1052220,1052751,1053252,1053752,1054284,1054786,1055285,1055817,1056317,1056849,1057349,1057850,1058382,1058883,1059383,1059915,1060415,1060947,1061447,1061947,1062479,1062981,1063480,1064012,1064514,1065014,1065545,1066045,1066577,1067078,1067578,1068110,1068611,1069112,1069642,1070142,1070674,1071175,1071675,1072207,1072709,1073209,1073740,1074241,1074741,1075273,1075773,1076305,1076807,1077308,1077839,1078340,1078840,1079372,1079871,1080403,1080904]},{"../main":346,"object-assign":247}],333:[function(t,e,r){var n=t("../main"),i=t("object-assign");function a(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}a.prototype=new n.baseCalendar,i(a.prototype,{name:"Coptic",jdEpoch:1825029.5,daysPerMonth:[30,30,30,30,30,30,30,30,30,30,30,30,5],hasYearZero:!1,minMonth:1,firstMonth:1,minDay:1,regionalOptions:{"":{name:"Coptic",epochs:["BAM","AM"],monthNames:["Thout","Paopi","Hathor","Koiak","Tobi","Meshir","Paremhat","Paremoude","Pashons","Paoni","Epip","Mesori","Pi Kogi Enavot"],monthNamesShort:["Tho","Pao","Hath","Koi","Tob","Mesh","Pat","Pad","Pash","Pao","Epi","Meso","PiK"],dayNames:["Tkyriaka","Pesnau","Pshoment","Peftoou","Ptiou","Psoou","Psabbaton"],dayNamesShort:["Tky","Pes","Psh","Pef","Pti","Pso","Psa"],dayNamesMin:["Tk","Pes","Psh","Pef","Pt","Pso","Psa"],digits:null,dateFormat:"dd/mm/yyyy",firstDay:0,isRTL:!1}},leapYear:function(t){var e=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear);return(t=e.year()+(e.year()<0?1:0))%4==3||t%4==-1},monthsInYear:function(t){return this._validate(t,this.minMonth,this.minDay,n.local.invalidYear||n.regionalOptions[""].invalidYear),13},weekOfYear:function(t,e,r){var n=this.newDate(t,e,r);return n.add(-n.dayOfWeek(),"d"),Math.floor((n.dayOfYear()-1)/7)+1},daysInMonth:function(t,e){var r=this._validate(t,e,this.minDay,n.local.invalidMonth);return this.daysPerMonth[r.month()-1]+(13===r.month()&&this.leapYear(r.year())?1:0)},weekDay:function(t,e,r){return(this.dayOfWeek(t,e,r)||7)<6},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);return(t=i.year())<0&&t++,i.day()+30*(i.month()-1)+365*(t-1)+Math.floor(t/4)+this.jdEpoch-1},fromJD:function(t){var e=Math.floor(t)+.5-this.jdEpoch,r=Math.floor((e-Math.floor((e+366)/1461))/365)+1;r<=0&&r--,e=Math.floor(t)+.5-this.newDate(r,1,1).toJD();var n=Math.floor(e/30)+1,i=e-30*(n-1)+1;return this.newDate(r,n,i)}}),n.calendars.coptic=a},{"../main":346,"object-assign":247}],334:[function(t,e,r){var n=t("../main"),i=t("object-assign");function a(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}a.prototype=new n.baseCalendar,i(a.prototype,{name:"Discworld",jdEpoch:1721425.5,daysPerMonth:[16,32,32,32,32,32,32,32,32,32,32,32,32],hasYearZero:!1,minMonth:1,firstMonth:1,minDay:1,regionalOptions:{"":{name:"Discworld",epochs:["BUC","UC"],monthNames:["Ick","Offle","February","March","April","May","June","Grune","August","Spune","Sektober","Ember","December"],monthNamesShort:["Ick","Off","Feb","Mar","Apr","May","Jun","Gru","Aug","Spu","Sek","Emb","Dec"],dayNames:["Sunday","Octeday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayNamesShort:["Sun","Oct","Mon","Tue","Wed","Thu","Fri","Sat"],dayNamesMin:["Su","Oc","Mo","Tu","We","Th","Fr","Sa"],digits:null,dateFormat:"yyyy/mm/dd",firstDay:2,isRTL:!1}},leapYear:function(t){return this._validate(t,this.minMonth,this.minDay,n.local.invalidYear),!1},monthsInYear:function(t){return this._validate(t,this.minMonth,this.minDay,n.local.invalidYear),13},daysInYear:function(t){return this._validate(t,this.minMonth,this.minDay,n.local.invalidYear),400},weekOfYear:function(t,e,r){var n=this.newDate(t,e,r);return n.add(-n.dayOfWeek(),"d"),Math.floor((n.dayOfYear()-1)/8)+1},daysInMonth:function(t,e){var r=this._validate(t,e,this.minDay,n.local.invalidMonth);return this.daysPerMonth[r.month()-1]},daysInWeek:function(){return 8},dayOfWeek:function(t,e,r){return(this._validate(t,e,r,n.local.invalidDate).day()+1)%8},weekDay:function(t,e,r){var n=this.dayOfWeek(t,e,r);return n>=2&&n<=6},extraInfo:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);return{century:o[Math.floor((i.year()-1)/100)+1]||""}},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);return t=i.year()+(i.year()<0?1:0),e=i.month(),(r=i.day())+(e>1?16:0)+(e>2?32*(e-2):0)+400*(t-1)+this.jdEpoch-1},fromJD:function(t){t=Math.floor(t+.5)-Math.floor(this.jdEpoch)-1;var e=Math.floor(t/400)+1;t-=400*(e-1),t+=t>15?16:0;var r=Math.floor(t/32)+1,n=t-32*(r-1)+1;return this.newDate(e<=0?e-1:e,r,n)}});var o={20:"Fruitbat",21:"Anchovy"};n.calendars.discworld=a},{"../main":346,"object-assign":247}],335:[function(t,e,r){var n=t("../main"),i=t("object-assign");function a(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}a.prototype=new n.baseCalendar,i(a.prototype,{name:"Ethiopian",jdEpoch:1724220.5,daysPerMonth:[30,30,30,30,30,30,30,30,30,30,30,30,5],hasYearZero:!1,minMonth:1,firstMonth:1,minDay:1,regionalOptions:{"":{name:"Ethiopian",epochs:["BEE","EE"],monthNames:["Meskerem","Tikemet","Hidar","Tahesas","Tir","Yekatit","Megabit","Miazia","Genbot","Sene","Hamle","Nehase","Pagume"],monthNamesShort:["Mes","Tik","Hid","Tah","Tir","Yek","Meg","Mia","Gen","Sen","Ham","Neh","Pag"],dayNames:["Ehud","Segno","Maksegno","Irob","Hamus","Arb","Kidame"],dayNamesShort:["Ehu","Seg","Mak","Iro","Ham","Arb","Kid"],dayNamesMin:["Eh","Se","Ma","Ir","Ha","Ar","Ki"],digits:null,dateFormat:"dd/mm/yyyy",firstDay:0,isRTL:!1}},leapYear:function(t){var e=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear);return(t=e.year()+(e.year()<0?1:0))%4==3||t%4==-1},monthsInYear:function(t){return this._validate(t,this.minMonth,this.minDay,n.local.invalidYear||n.regionalOptions[""].invalidYear),13},weekOfYear:function(t,e,r){var n=this.newDate(t,e,r);return n.add(-n.dayOfWeek(),"d"),Math.floor((n.dayOfYear()-1)/7)+1},daysInMonth:function(t,e){var r=this._validate(t,e,this.minDay,n.local.invalidMonth);return this.daysPerMonth[r.month()-1]+(13===r.month()&&this.leapYear(r.year())?1:0)},weekDay:function(t,e,r){return(this.dayOfWeek(t,e,r)||7)<6},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);return(t=i.year())<0&&t++,i.day()+30*(i.month()-1)+365*(t-1)+Math.floor(t/4)+this.jdEpoch-1},fromJD:function(t){var e=Math.floor(t)+.5-this.jdEpoch,r=Math.floor((e-Math.floor((e+366)/1461))/365)+1;r<=0&&r--,e=Math.floor(t)+.5-this.newDate(r,1,1).toJD();var n=Math.floor(e/30)+1,i=e-30*(n-1)+1;return this.newDate(r,n,i)}}),n.calendars.ethiopian=a},{"../main":346,"object-assign":247}],336:[function(t,e,r){var n=t("../main"),i=t("object-assign");function a(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}function o(t,e){return t-e*Math.floor(t/e)}a.prototype=new n.baseCalendar,i(a.prototype,{name:"Hebrew",jdEpoch:347995.5,daysPerMonth:[30,29,30,29,30,29,30,29,30,29,30,29,29],hasYearZero:!1,minMonth:1,firstMonth:7,minDay:1,regionalOptions:{"":{name:"Hebrew",epochs:["BAM","AM"],monthNames:["Nisan","Iyar","Sivan","Tammuz","Av","Elul","Tishrei","Cheshvan","Kislev","Tevet","Shevat","Adar","Adar II"],monthNamesShort:["Nis","Iya","Siv","Tam","Av","Elu","Tis","Che","Kis","Tev","She","Ada","Ad2"],dayNames:["Yom Rishon","Yom Sheni","Yom Shlishi","Yom Revi'i","Yom Chamishi","Yom Shishi","Yom Shabbat"],dayNamesShort:["Ris","She","Shl","Rev","Cha","Shi","Sha"],dayNamesMin:["Ri","She","Shl","Re","Ch","Shi","Sha"],digits:null,dateFormat:"dd/mm/yyyy",firstDay:0,isRTL:!1}},leapYear:function(t){var e=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear);return this._leapYear(e.year())},_leapYear:function(t){return o(7*(t=t<0?t+1:t)+1,19)<7},monthsInYear:function(t){return this._validate(t,this.minMonth,this.minDay,n.local.invalidYear),this._leapYear(t.year?t.year():t)?13:12},weekOfYear:function(t,e,r){var n=this.newDate(t,e,r);return n.add(-n.dayOfWeek(),"d"),Math.floor((n.dayOfYear()-1)/7)+1},daysInYear:function(t){return t=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear).year(),this.toJD(-1===t?1:t+1,7,1)-this.toJD(t,7,1)},daysInMonth:function(t,e){return t.year&&(e=t.month(),t=t.year()),this._validate(t,e,this.minDay,n.local.invalidMonth),12===e&&this.leapYear(t)||8===e&&5===o(this.daysInYear(t),10)?30:9===e&&3===o(this.daysInYear(t),10)?29:this.daysPerMonth[e-1]},weekDay:function(t,e,r){return 6!==this.dayOfWeek(t,e,r)},extraInfo:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);return{yearType:(this.leapYear(i)?"embolismic":"common")+" "+["deficient","regular","complete"][this.daysInYear(i)%10-3]}},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);t=i.year(),e=i.month(),r=i.day();var a=t<=0?t+1:t,o=this.jdEpoch+this._delay1(a)+this._delay2(a)+r+1;if(e<7){for(var s=7;s<=this.monthsInYear(t);s++)o+=this.daysInMonth(t,s);for(s=1;s<e;s++)o+=this.daysInMonth(t,s)}else for(s=7;s<e;s++)o+=this.daysInMonth(t,s);return o},_delay1:function(t){var e=Math.floor((235*t-234)/19),r=12084+13753*e,n=29*e+Math.floor(r/25920);return o(3*(n+1),7)<3&&n++,n},_delay2:function(t){var e=this._delay1(t-1),r=this._delay1(t);return this._delay1(t+1)-r==356?2:r-e==382?1:0},fromJD:function(t){t=Math.floor(t)+.5;for(var e=Math.floor(98496*(t-this.jdEpoch)/35975351)-1;t>=this.toJD(-1===e?1:e+1,7,1);)e++;for(var r=t<this.toJD(e,1,1)?7:1;t>this.toJD(e,r,this.daysInMonth(e,r));)r++;var n=t-this.toJD(e,r,1)+1;return this.newDate(e,r,n)}}),n.calendars.hebrew=a},{"../main":346,"object-assign":247}],337:[function(t,e,r){var n=t("../main"),i=t("object-assign");function a(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}a.prototype=new n.baseCalendar,i(a.prototype,{name:"Islamic",jdEpoch:1948439.5,daysPerMonth:[30,29,30,29,30,29,30,29,30,29,30,29],hasYearZero:!1,minMonth:1,firstMonth:1,minDay:1,regionalOptions:{"":{name:"Islamic",epochs:["BH","AH"],monthNames:["Muharram","Safar","Rabi' al-awwal","Rabi' al-thani","Jumada al-awwal","Jumada al-thani","Rajab","Sha'aban","Ramadan","Shawwal","Dhu al-Qi'dah","Dhu al-Hijjah"],monthNamesShort:["Muh","Saf","Rab1","Rab2","Jum1","Jum2","Raj","Sha'","Ram","Shaw","DhuQ","DhuH"],dayNames:["Yawm al-ahad","Yawm al-ithnayn","Yawm ath-thulaathaa'","Yawm al-arbi'aa'","Yawm al-kham\u012bs","Yawm al-jum'a","Yawm as-sabt"],dayNamesShort:["Aha","Ith","Thu","Arb","Kha","Jum","Sab"],dayNamesMin:["Ah","It","Th","Ar","Kh","Ju","Sa"],digits:null,dateFormat:"yyyy/mm/dd",firstDay:6,isRTL:!1}},leapYear:function(t){return(11*this._validate(t,this.minMonth,this.minDay,n.local.invalidYear).year()+14)%30<11},weekOfYear:function(t,e,r){var n=this.newDate(t,e,r);return n.add(-n.dayOfWeek(),"d"),Math.floor((n.dayOfYear()-1)/7)+1},daysInYear:function(t){return this.leapYear(t)?355:354},daysInMonth:function(t,e){var r=this._validate(t,e,this.minDay,n.local.invalidMonth);return this.daysPerMonth[r.month()-1]+(12===r.month()&&this.leapYear(r.year())?1:0)},weekDay:function(t,e,r){return 5!==this.dayOfWeek(t,e,r)},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);return t=i.year(),e=i.month(),t=t<=0?t+1:t,(r=i.day())+Math.ceil(29.5*(e-1))+354*(t-1)+Math.floor((3+11*t)/30)+this.jdEpoch-1},fromJD:function(t){t=Math.floor(t)+.5;var e=Math.floor((30*(t-this.jdEpoch)+10646)/10631);e=e<=0?e-1:e;var r=Math.min(12,Math.ceil((t-29-this.toJD(e,1,1))/29.5)+1),n=t-this.toJD(e,r,1)+1;return this.newDate(e,r,n)}}),n.calendars.islamic=a},{"../main":346,"object-assign":247}],338:[function(t,e,r){var n=t("../main"),i=t("object-assign");function a(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}a.prototype=new n.baseCalendar,i(a.prototype,{name:"Julian",jdEpoch:1721423.5,daysPerMonth:[31,28,31,30,31,30,31,31,30,31,30,31],hasYearZero:!1,minMonth:1,firstMonth:1,minDay:1,regionalOptions:{"":{name:"Julian",epochs:["BC","AD"],monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],monthNamesShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayNamesShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dayNamesMin:["Su","Mo","Tu","We","Th","Fr","Sa"],digits:null,dateFormat:"mm/dd/yyyy",firstDay:0,isRTL:!1}},leapYear:function(t){var e=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear);return(t=e.year()<0?e.year()+1:e.year())%4==0},weekOfYear:function(t,e,r){var n=this.newDate(t,e,r);return n.add(4-(n.dayOfWeek()||7),"d"),Math.floor((n.dayOfYear()-1)/7)+1},daysInMonth:function(t,e){var r=this._validate(t,e,this.minDay,n.local.invalidMonth);return this.daysPerMonth[r.month()-1]+(2===r.month()&&this.leapYear(r.year())?1:0)},weekDay:function(t,e,r){return(this.dayOfWeek(t,e,r)||7)<6},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);return t=i.year(),e=i.month(),r=i.day(),t<0&&t++,e<=2&&(t--,e+=12),Math.floor(365.25*(t+4716))+Math.floor(30.6001*(e+1))+r-1524.5},fromJD:function(t){var e=Math.floor(t+.5)+1524,r=Math.floor((e-122.1)/365.25),n=Math.floor(365.25*r),i=Math.floor((e-n)/30.6001),a=i-Math.floor(i<14?1:13),o=r-Math.floor(a>2?4716:4715),s=e-n-Math.floor(30.6001*i);return o<=0&&o--,this.newDate(o,a,s)}}),n.calendars.julian=a},{"../main":346,"object-assign":247}],339:[function(t,e,r){var n=t("../main"),i=t("object-assign");function a(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}function o(t,e){return t-e*Math.floor(t/e)}function s(t,e){return o(t-1,e)+1}a.prototype=new n.baseCalendar,i(a.prototype,{name:"Mayan",jdEpoch:584282.5,hasYearZero:!0,minMonth:0,firstMonth:0,minDay:0,regionalOptions:{"":{name:"Mayan",epochs:["",""],monthNames:["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17"],monthNamesShort:["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17"],dayNames:["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"],dayNamesShort:["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"],dayNamesMin:["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"],digits:null,dateFormat:"YYYY.m.d",firstDay:0,isRTL:!1,haabMonths:["Pop","Uo","Zip","Zotz","Tzec","Xul","Yaxkin","Mol","Chen","Yax","Zac","Ceh","Mac","Kankin","Muan","Pax","Kayab","Cumku","Uayeb"],tzolkinMonths:["Imix","Ik","Akbal","Kan","Chicchan","Cimi","Manik","Lamat","Muluc","Oc","Chuen","Eb","Ben","Ix","Men","Cib","Caban","Etznab","Cauac","Ahau"]}},leapYear:function(t){return this._validate(t,this.minMonth,this.minDay,n.local.invalidYear),!1},formatYear:function(t){t=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear).year();var e=Math.floor(t/400);return t%=400,t+=t<0?400:0,e+"."+Math.floor(t/20)+"."+t%20},forYear:function(t){if((t=t.split(".")).length<3)throw"Invalid Mayan year";for(var e=0,r=0;r<t.length;r++){var n=parseInt(t[r],10);if(Math.abs(n)>19||r>0&&n<0)throw"Invalid Mayan year";e=20*e+n}return e},monthsInYear:function(t){return this._validate(t,this.minMonth,this.minDay,n.local.invalidYear),18},weekOfYear:function(t,e,r){return this._validate(t,e,r,n.local.invalidDate),0},daysInYear:function(t){return this._validate(t,this.minMonth,this.minDay,n.local.invalidYear),360},daysInMonth:function(t,e){return this._validate(t,e,this.minDay,n.local.invalidMonth),20},daysInWeek:function(){return 5},dayOfWeek:function(t,e,r){return this._validate(t,e,r,n.local.invalidDate).day()},weekDay:function(t,e,r){return this._validate(t,e,r,n.local.invalidDate),!0},extraInfo:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate).toJD(),a=this._toHaab(i),o=this._toTzolkin(i);return{haabMonthName:this.local.haabMonths[a[0]-1],haabMonth:a[0],haabDay:a[1],tzolkinDayName:this.local.tzolkinMonths[o[0]-1],tzolkinDay:o[0],tzolkinTrecena:o[1]}},_toHaab:function(t){var e=o((t-=this.jdEpoch)+8+340,365);return[Math.floor(e/20)+1,o(e,20)]},_toTzolkin:function(t){return[s((t-=this.jdEpoch)+20,20),s(t+4,13)]},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);return i.day()+20*i.month()+360*i.year()+this.jdEpoch},fromJD:function(t){t=Math.floor(t)+.5-this.jdEpoch;var e=Math.floor(t/360);t%=360,t+=t<0?360:0;var r=Math.floor(t/20),n=t%20;return this.newDate(e,r,n)}}),n.calendars.mayan=a},{"../main":346,"object-assign":247}],340:[function(t,e,r){var n=t("../main"),i=t("object-assign");function a(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}a.prototype=new n.baseCalendar;var o=n.instance("gregorian");i(a.prototype,{name:"Nanakshahi",jdEpoch:2257673.5,daysPerMonth:[31,31,31,31,31,30,30,30,30,30,30,30],hasYearZero:!1,minMonth:1,firstMonth:1,minDay:1,regionalOptions:{"":{name:"Nanakshahi",epochs:["BN","AN"],monthNames:["Chet","Vaisakh","Jeth","Harh","Sawan","Bhadon","Assu","Katak","Maghar","Poh","Magh","Phagun"],monthNamesShort:["Che","Vai","Jet","Har","Saw","Bha","Ass","Kat","Mgr","Poh","Mgh","Pha"],dayNames:["Somvaar","Mangalvar","Budhvaar","Veervaar","Shukarvaar","Sanicharvaar","Etvaar"],dayNamesShort:["Som","Mangal","Budh","Veer","Shukar","Sanichar","Et"],dayNamesMin:["So","Ma","Bu","Ve","Sh","Sa","Et"],digits:null,dateFormat:"dd-mm-yyyy",firstDay:0,isRTL:!1}},leapYear:function(t){var e=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear||n.regionalOptions[""].invalidYear);return o.leapYear(e.year()+(e.year()<1?1:0)+1469)},weekOfYear:function(t,e,r){var n=this.newDate(t,e,r);return n.add(1-(n.dayOfWeek()||7),"d"),Math.floor((n.dayOfYear()-1)/7)+1},daysInMonth:function(t,e){var r=this._validate(t,e,this.minDay,n.local.invalidMonth);return this.daysPerMonth[r.month()-1]+(12===r.month()&&this.leapYear(r.year())?1:0)},weekDay:function(t,e,r){return(this.dayOfWeek(t,e,r)||7)<6},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidMonth);(t=i.year())<0&&t++;for(var a=i.day(),s=1;s<i.month();s++)a+=this.daysPerMonth[s-1];return a+o.toJD(t+1468,3,13)},fromJD:function(t){t=Math.floor(t+.5);for(var e=Math.floor((t-(this.jdEpoch-1))/366);t>=this.toJD(e+1,1,1);)e++;for(var r=t-Math.floor(this.toJD(e,1,1)+.5)+1,n=1;r>this.daysInMonth(e,n);)r-=this.daysInMonth(e,n),n++;return this.newDate(e,n,r)}}),n.calendars.nanakshahi=a},{"../main":346,"object-assign":247}],341:[function(t,e,r){var n=t("../main"),i=t("object-assign");function a(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}a.prototype=new n.baseCalendar,i(a.prototype,{name:"Nepali",jdEpoch:1700709.5,daysPerMonth:[31,31,32,32,31,30,30,29,30,29,30,30],hasYearZero:!1,minMonth:1,firstMonth:1,minDay:1,daysPerYear:365,regionalOptions:{"":{name:"Nepali",epochs:["BBS","ABS"],monthNames:["Baisakh","Jestha","Ashadh","Shrawan","Bhadra","Ashwin","Kartik","Mangsir","Paush","Mangh","Falgun","Chaitra"],monthNamesShort:["Bai","Je","As","Shra","Bha","Ash","Kar","Mang","Pau","Ma","Fal","Chai"],dayNames:["Aaitabaar","Sombaar","Manglbaar","Budhabaar","Bihibaar","Shukrabaar","Shanibaar"],dayNamesShort:["Aaita","Som","Mangl","Budha","Bihi","Shukra","Shani"],dayNamesMin:["Aai","So","Man","Bu","Bi","Shu","Sha"],digits:null,dateFormat:"dd/mm/yyyy",firstDay:1,isRTL:!1}},leapYear:function(t){return this.daysInYear(t)!==this.daysPerYear},weekOfYear:function(t,e,r){var n=this.newDate(t,e,r);return n.add(-n.dayOfWeek(),"d"),Math.floor((n.dayOfYear()-1)/7)+1},daysInYear:function(t){if(t=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear).year(),void 0===this.NEPALI_CALENDAR_DATA[t])return this.daysPerYear;for(var e=0,r=this.minMonth;r<=12;r++)e+=this.NEPALI_CALENDAR_DATA[t][r];return e},daysInMonth:function(t,e){return t.year&&(e=t.month(),t=t.year()),this._validate(t,e,this.minDay,n.local.invalidMonth),void 0===this.NEPALI_CALENDAR_DATA[t]?this.daysPerMonth[e-1]:this.NEPALI_CALENDAR_DATA[t][e]},weekDay:function(t,e,r){return 6!==this.dayOfWeek(t,e,r)},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);t=i.year(),e=i.month(),r=i.day();var a=n.instance(),o=0,s=e,l=t;this._createMissingCalendarData(t);var c=t-(s>9||9===s&&r>=this.NEPALI_CALENDAR_DATA[l][0]?56:57);for(9!==e&&(o=r,s--);9!==s;)s<=0&&(s=12,l--),o+=this.NEPALI_CALENDAR_DATA[l][s],s--;return 9===e?(o+=r-this.NEPALI_CALENDAR_DATA[l][0])<0&&(o+=a.daysInYear(c)):o+=this.NEPALI_CALENDAR_DATA[l][9]-this.NEPALI_CALENDAR_DATA[l][0],a.newDate(c,1,1).add(o,"d").toJD()},fromJD:function(t){var e=n.instance().fromJD(t),r=e.year(),i=e.dayOfYear(),a=r+56;this._createMissingCalendarData(a);for(var o=9,s=this.NEPALI_CALENDAR_DATA[a][0],l=this.NEPALI_CALENDAR_DATA[a][o]-s+1;i>l;)++o>12&&(o=1,a++),l+=this.NEPALI_CALENDAR_DATA[a][o];var c=this.NEPALI_CALENDAR_DATA[a][o]-(l-i);return this.newDate(a,o,c)},_createMissingCalendarData:function(t){var e=this.daysPerMonth.slice(0);e.unshift(17);for(var r=t-1;r<t+2;r++)void 0===this.NEPALI_CALENDAR_DATA[r]&&(this.NEPALI_CALENDAR_DATA[r]=e)},NEPALI_CALENDAR_DATA:{1970:[18,31,31,32,31,31,31,30,29,30,29,30,30],1971:[18,31,31,32,31,32,30,30,29,30,29,30,30],1972:[17,31,32,31,32,31,30,30,30,29,29,30,30],1973:[19,30,32,31,32,31,30,30,30,29,30,29,31],1974:[19,31,31,32,30,31,31,30,29,30,29,30,30],1975:[18,31,31,32,32,30,31,30,29,30,29,30,30],1976:[17,31,32,31,32,31,30,30,30,29,29,30,31],1977:[18,31,32,31,32,31,31,29,30,29,30,29,31],1978:[18,31,31,32,31,31,31,30,29,30,29,30,30],1979:[18,31,31,32,32,31,30,30,29,30,29,30,30],1980:[17,31,32,31,32,31,30,30,30,29,29,30,31],1981:[18,31,31,31,32,31,31,29,30,30,29,30,30],1982:[18,31,31,32,31,31,31,30,29,30,29,30,30],1983:[18,31,31,32,32,31,30,30,29,30,29,30,30],1984:[17,31,32,31,32,31,30,30,30,29,29,30,31],1985:[18,31,31,31,32,31,31,29,30,30,29,30,30],1986:[18,31,31,32,31,31,31,30,29,30,29,30,30],1987:[18,31,32,31,32,31,30,30,29,30,29,30,30],1988:[17,31,32,31,32,31,30,30,30,29,29,30,31],1989:[18,31,31,31,32,31,31,30,29,30,29,30,30],1990:[18,31,31,32,31,31,31,30,29,30,29,30,30],1991:[18,31,32,31,32,31,30,30,29,30,29,30,30],1992:[17,31,32,31,32,31,30,30,30,29,30,29,31],1993:[18,31,31,31,32,31,31,30,29,30,29,30,30],1994:[18,31,31,32,31,31,31,30,29,30,29,30,30],1995:[17,31,32,31,32,31,30,30,30,29,29,30,30],1996:[17,31,32,31,32,31,30,30,30,29,30,29,31],1997:[18,31,31,32,31,31,31,30,29,30,29,30,30],1998:[18,31,31,32,31,31,31,30,29,30,29,30,30],1999:[17,31,32,31,32,31,30,30,30,29,29,30,31],2e3:[17,30,32,31,32,31,30,30,30,29,30,29,31],2001:[18,31,31,32,31,31,31,30,29,30,29,30,30],2002:[18,31,31,32,32,31,30,30,29,30,29,30,30],2003:[17,31,32,31,32,31,30,30,30,29,29,30,31],2004:[17,30,32,31,32,31,30,30,30,29,30,29,31],2005:[18,31,31,32,31,31,31,30,29,30,29,30,30],2006:[18,31,31,32,32,31,30,30,29,30,29,30,30],2007:[17,31,32,31,32,31,30,30,30,29,29,30,31],2008:[17,31,31,31,32,31,31,29,30,30,29,29,31],2009:[18,31,31,32,31,31,31,30,29,30,29,30,30],2010:[18,31,31,32,32,31,30,30,29,30,29,30,30],2011:[17,31,32,31,32,31,30,30,30,29,29,30,31],2012:[17,31,31,31,32,31,31,29,30,30,29,30,30],2013:[18,31,31,32,31,31,31,30,29,30,29,30,30],2014:[18,31,31,32,32,31,30,30,29,30,29,30,30],2015:[17,31,32,31,32,31,30,30,30,29,29,30,31],2016:[17,31,31,31,32,31,31,29,30,30,29,30,30],2017:[18,31,31,32,31,31,31,30,29,30,29,30,30],2018:[18,31,32,31,32,31,30,30,29,30,29,30,30],2019:[17,31,32,31,32,31,30,30,30,29,30,29,31],2020:[17,31,31,31,32,31,31,30,29,30,29,30,30],2021:[18,31,31,32,31,31,31,30,29,30,29,30,30],2022:[17,31,32,31,32,31,30,30,30,29,29,30,30],2023:[17,31,32,31,32,31,30,30,30,29,30,29,31],2024:[17,31,31,31,32,31,31,30,29,30,29,30,30],2025:[18,31,31,32,31,31,31,30,29,30,29,30,30],2026:[17,31,32,31,32,31,30,30,30,29,29,30,31],2027:[17,30,32,31,32,31,30,30,30,29,30,29,31],2028:[17,31,31,32,31,31,31,30,29,30,29,30,30],2029:[18,31,31,32,31,32,30,30,29,30,29,30,30],2030:[17,31,32,31,32,31,30,30,30,30,30,30,31],2031:[17,31,32,31,32,31,31,31,31,31,31,31,31],2032:[17,32,32,32,32,32,32,32,32,32,32,32,32],2033:[18,31,31,32,32,31,30,30,29,30,29,30,30],2034:[17,31,32,31,32,31,30,30,30,29,29,30,31],2035:[17,30,32,31,32,31,31,29,30,30,29,29,31],2036:[17,31,31,32,31,31,31,30,29,30,29,30,30],2037:[18,31,31,32,32,31,30,30,29,30,29,30,30],2038:[17,31,32,31,32,31,30,30,30,29,29,30,31],2039:[17,31,31,31,32,31,31,29,30,30,29,30,30],2040:[17,31,31,32,31,31,31,30,29,30,29,30,30],2041:[18,31,31,32,32,31,30,30,29,30,29,30,30],2042:[17,31,32,31,32,31,30,30,30,29,29,30,31],2043:[17,31,31,31,32,31,31,29,30,30,29,30,30],2044:[17,31,31,32,31,31,31,30,29,30,29,30,30],2045:[18,31,32,31,32,31,30,30,29,30,29,30,30],2046:[17,31,32,31,32,31,30,30,30,29,29,30,31],2047:[17,31,31,31,32,31,31,30,29,30,29,30,30],2048:[17,31,31,32,31,31,31,30,29,30,29,30,30],2049:[17,31,32,31,32,31,30,30,30,29,29,30,30],2050:[17,31,32,31,32,31,30,30,30,29,30,29,31],2051:[17,31,31,31,32,31,31,30,29,30,29,30,30],2052:[17,31,31,32,31,31,31,30,29,30,29,30,30],2053:[17,31,32,31,32,31,30,30,30,29,29,30,30],2054:[17,31,32,31,32,31,30,30,30,29,30,29,31],2055:[17,31,31,32,31,31,31,30,29,30,30,29,30],2056:[17,31,31,32,31,32,30,30,29,30,29,30,30],2057:[17,31,32,31,32,31,30,30,30,29,29,30,31],2058:[17,30,32,31,32,31,30,30,30,29,30,29,31],2059:[17,31,31,32,31,31,31,30,29,30,29,30,30],2060:[17,31,31,32,32,31,30,30,29,30,29,30,30],2061:[17,31,32,31,32,31,30,30,30,29,29,30,31],2062:[17,30,32,31,32,31,31,29,30,29,30,29,31],2063:[17,31,31,32,31,31,31,30,29,30,29,30,30],2064:[17,31,31,32,32,31,30,30,29,30,29,30,30],2065:[17,31,32,31,32,31,30,30,30,29,29,30,31],2066:[17,31,31,31,32,31,31,29,30,30,29,29,31],2067:[17,31,31,32,31,31,31,30,29,30,29,30,30],2068:[17,31,31,32,32,31,30,30,29,30,29,30,30],2069:[17,31,32,31,32,31,30,30,30,29,29,30,31],2070:[17,31,31,31,32,31,31,29,30,30,29,30,30],2071:[17,31,31,32,31,31,31,30,29,30,29,30,30],2072:[17,31,32,31,32,31,30,30,29,30,29,30,30],2073:[17,31,32,31,32,31,30,30,30,29,29,30,31],2074:[17,31,31,31,32,31,31,30,29,30,29,30,30],2075:[17,31,31,32,31,31,31,30,29,30,29,30,30],2076:[16,31,32,31,32,31,30,30,30,29,29,30,30],2077:[17,31,32,31,32,31,30,30,30,29,30,29,31],2078:[17,31,31,31,32,31,31,30,29,30,29,30,30],2079:[17,31,31,32,31,31,31,30,29,30,29,30,30],2080:[16,31,32,31,32,31,30,30,30,29,29,30,30],2081:[17,31,31,32,32,31,30,30,30,29,30,30,30],2082:[17,31,32,31,32,31,30,30,30,29,30,30,30],2083:[17,31,31,32,31,31,30,30,30,29,30,30,30],2084:[17,31,31,32,31,31,30,30,30,29,30,30,30],2085:[17,31,32,31,32,31,31,30,30,29,30,30,30],2086:[17,31,32,31,32,31,30,30,30,29,30,30,30],2087:[16,31,31,32,31,31,31,30,30,29,30,30,30],2088:[16,30,31,32,32,30,31,30,30,29,30,30,30],2089:[17,31,32,31,32,31,30,30,30,29,30,30,30],2090:[17,31,32,31,32,31,30,30,30,29,30,30,30],2091:[16,31,31,32,31,31,31,30,30,29,30,30,30],2092:[16,31,31,32,32,31,30,30,30,29,30,30,30],2093:[17,31,32,31,32,31,30,30,30,29,30,30,30],2094:[17,31,31,32,31,31,30,30,30,29,30,30,30],2095:[17,31,31,32,31,31,31,30,29,30,30,30,30],2096:[17,30,31,32,32,31,30,30,29,30,29,30,30],2097:[17,31,32,31,32,31,30,30,30,29,30,30,30],2098:[17,31,31,32,31,31,31,29,30,29,30,30,31],2099:[17,31,31,32,31,31,31,30,29,29,30,30,30],2100:[17,31,32,31,32,30,31,30,29,30,29,30,30]}}),n.calendars.nepali=a},{"../main":346,"object-assign":247}],342:[function(t,e,r){var n=t("../main"),i=t("object-assign");function a(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}function o(t,e){return t-e*Math.floor(t/e)}a.prototype=new n.baseCalendar,i(a.prototype,{name:"Persian",jdEpoch:1948320.5,daysPerMonth:[31,31,31,31,31,31,30,30,30,30,30,29],hasYearZero:!1,minMonth:1,firstMonth:1,minDay:1,regionalOptions:{"":{name:"Persian",epochs:["BP","AP"],monthNames:["Farvardin","Ordibehesht","Khordad","Tir","Mordad","Shahrivar","Mehr","Aban","Azar","Day","Bahman","Esfand"],monthNamesShort:["Far","Ord","Kho","Tir","Mor","Sha","Meh","Aba","Aza","Day","Bah","Esf"],dayNames:["Yekshambe","Doshambe","Seshambe","Ch\xe6harshambe","Panjshambe","Jom'e","Shambe"],dayNamesShort:["Yek","Do","Se","Ch\xe6","Panj","Jom","Sha"],dayNamesMin:["Ye","Do","Se","Ch","Pa","Jo","Sh"],digits:null,dateFormat:"yyyy/mm/dd",firstDay:6,isRTL:!1}},leapYear:function(t){var e=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear);return 682*((e.year()-(e.year()>0?474:473))%2820+474+38)%2816<682},weekOfYear:function(t,e,r){var n=this.newDate(t,e,r);return n.add(-(n.dayOfWeek()+1)%7,"d"),Math.floor((n.dayOfYear()-1)/7)+1},daysInMonth:function(t,e){var r=this._validate(t,e,this.minDay,n.local.invalidMonth);return this.daysPerMonth[r.month()-1]+(12===r.month()&&this.leapYear(r.year())?1:0)},weekDay:function(t,e,r){return 5!==this.dayOfWeek(t,e,r)},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);t=i.year(),e=i.month(),r=i.day();var a=t-(t>=0?474:473),s=474+o(a,2820);return r+(e<=7?31*(e-1):30*(e-1)+6)+Math.floor((682*s-110)/2816)+365*(s-1)+1029983*Math.floor(a/2820)+this.jdEpoch-1},fromJD:function(t){var e=(t=Math.floor(t)+.5)-this.toJD(475,1,1),r=Math.floor(e/1029983),n=o(e,1029983),i=2820;if(1029982!==n){var a=Math.floor(n/366),s=o(n,366);i=Math.floor((2134*a+2816*s+2815)/1028522)+a+1}var l=i+2820*r+474;l=l<=0?l-1:l;var c=t-this.toJD(l,1,1)+1,u=c<=186?Math.ceil(c/31):Math.ceil((c-6)/30),f=t-this.toJD(l,u,1)+1;return this.newDate(l,u,f)}}),n.calendars.persian=a,n.calendars.jalali=a},{"../main":346,"object-assign":247}],343:[function(t,e,r){var n=t("../main"),i=t("object-assign"),a=n.instance();function o(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}o.prototype=new n.baseCalendar,i(o.prototype,{name:"Taiwan",jdEpoch:2419402.5,yearsOffset:1911,daysPerMonth:[31,28,31,30,31,30,31,31,30,31,30,31],hasYearZero:!1,minMonth:1,firstMonth:1,minDay:1,regionalOptions:{"":{name:"Taiwan",epochs:["BROC","ROC"],monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],monthNamesShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayNamesShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dayNamesMin:["Su","Mo","Tu","We","Th","Fr","Sa"],digits:null,dateFormat:"yyyy/mm/dd",firstDay:1,isRTL:!1}},leapYear:function(t){var e=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear);t=this._t2gYear(e.year());return a.leapYear(t)},weekOfYear:function(t,e,r){var i=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear);t=this._t2gYear(i.year());return a.weekOfYear(t,i.month(),i.day())},daysInMonth:function(t,e){var r=this._validate(t,e,this.minDay,n.local.invalidMonth);return this.daysPerMonth[r.month()-1]+(2===r.month()&&this.leapYear(r.year())?1:0)},weekDay:function(t,e,r){return(this.dayOfWeek(t,e,r)||7)<6},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);t=this._t2gYear(i.year());return a.toJD(t,i.month(),i.day())},fromJD:function(t){var e=a.fromJD(t),r=this._g2tYear(e.year());return this.newDate(r,e.month(),e.day())},_t2gYear:function(t){return t+this.yearsOffset+(t>=-this.yearsOffset&&t<=-1?1:0)},_g2tYear:function(t){return t-this.yearsOffset-(t>=1&&t<=this.yearsOffset?1:0)}}),n.calendars.taiwan=o},{"../main":346,"object-assign":247}],344:[function(t,e,r){var n=t("../main"),i=t("object-assign"),a=n.instance();function o(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}o.prototype=new n.baseCalendar,i(o.prototype,{name:"Thai",jdEpoch:1523098.5,yearsOffset:543,daysPerMonth:[31,28,31,30,31,30,31,31,30,31,30,31],hasYearZero:!1,minMonth:1,firstMonth:1,minDay:1,regionalOptions:{"":{name:"Thai",epochs:["BBE","BE"],monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],monthNamesShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayNamesShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dayNamesMin:["Su","Mo","Tu","We","Th","Fr","Sa"],digits:null,dateFormat:"dd/mm/yyyy",firstDay:0,isRTL:!1}},leapYear:function(t){var e=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear);t=this._t2gYear(e.year());return a.leapYear(t)},weekOfYear:function(t,e,r){var i=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear);t=this._t2gYear(i.year());return a.weekOfYear(t,i.month(),i.day())},daysInMonth:function(t,e){var r=this._validate(t,e,this.minDay,n.local.invalidMonth);return this.daysPerMonth[r.month()-1]+(2===r.month()&&this.leapYear(r.year())?1:0)},weekDay:function(t,e,r){return(this.dayOfWeek(t,e,r)||7)<6},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate);t=this._t2gYear(i.year());return a.toJD(t,i.month(),i.day())},fromJD:function(t){var e=a.fromJD(t),r=this._g2tYear(e.year());return this.newDate(r,e.month(),e.day())},_t2gYear:function(t){return t-this.yearsOffset-(t>=1&&t<=this.yearsOffset?1:0)},_g2tYear:function(t){return t+this.yearsOffset+(t>=-this.yearsOffset&&t<=-1?1:0)}}),n.calendars.thai=o},{"../main":346,"object-assign":247}],345:[function(t,e,r){var n=t("../main"),i=t("object-assign");function a(t){this.local=this.regionalOptions[t||""]||this.regionalOptions[""]}a.prototype=new n.baseCalendar,i(a.prototype,{name:"UmmAlQura",hasYearZero:!1,minMonth:1,firstMonth:1,minDay:1,regionalOptions:{"":{name:"Umm al-Qura",epochs:["BH","AH"],monthNames:["Al-Muharram","Safar","Rabi' al-awwal","Rabi' Al-Thani","Jumada Al-Awwal","Jumada Al-Thani","Rajab","Sha'aban","Ramadan","Shawwal","Dhu al-Qi'dah","Dhu al-Hijjah"],monthNamesShort:["Muh","Saf","Rab1","Rab2","Jum1","Jum2","Raj","Sha'","Ram","Shaw","DhuQ","DhuH"],dayNames:["Yawm al-Ahad","Yawm al-Ithnain","Yawm al-Thal\u0101th\u0101\u2019","Yawm al-Arba\u2018\u0101\u2019","Yawm al-Kham\u012bs","Yawm al-Jum\u2018a","Yawm al-Sabt"],dayNamesMin:["Ah","Ith","Th","Ar","Kh","Ju","Sa"],digits:null,dateFormat:"yyyy/mm/dd",firstDay:6,isRTL:!0}},leapYear:function(t){var e=this._validate(t,this.minMonth,this.minDay,n.local.invalidYear);return 355===this.daysInYear(e.year())},weekOfYear:function(t,e,r){var n=this.newDate(t,e,r);return n.add(-n.dayOfWeek(),"d"),Math.floor((n.dayOfYear()-1)/7)+1},daysInYear:function(t){for(var e=0,r=1;r<=12;r++)e+=this.daysInMonth(t,r);return e},daysInMonth:function(t,e){for(var r=this._validate(t,e,this.minDay,n.local.invalidMonth).toJD()-24e5+.5,i=0,a=0;a<o.length;a++){if(o[a]>r)return o[i]-o[i-1];i++}return 30},weekDay:function(t,e,r){return 5!==this.dayOfWeek(t,e,r)},toJD:function(t,e,r){var i=this._validate(t,e,r,n.local.invalidDate),a=12*(i.year()-1)+i.month()-15292;return i.day()+o[a-1]-1+24e5-.5},fromJD:function(t){for(var e=t-24e5+.5,r=0,n=0;n<o.length&&!(o[n]>e);n++)r++;var i=r+15292,a=Math.floor((i-1)/12),s=a+1,l=i-12*a,c=e-o[r-1]+1;return this.newDate(s,l,c)},isValid:function(t,e,r){var i=n.baseCalendar.prototype.isValid.apply(this,arguments);return i&&(i=(t=null!=t.year?t.year:t)>=1276&&t<=1500),i},_validate:function(t,e,r,i){var a=n.baseCalendar.prototype._validate.apply(this,arguments);if(a.year<1276||a.year>1500)throw i.replace(/\{0\}/,this.local.name);return a}}),n.calendars.ummalqura=a;var o=[20,50,79,109,138,168,197,227,256,286,315,345,374,404,433,463,492,522,551,581,611,641,670,700,729,759,788,818,847,877,906,936,965,995,1024,1054,1083,1113,1142,1172,1201,1231,1260,1290,1320,1350,1379,1409,1438,1468,1497,1527,1556,1586,1615,1645,1674,1704,1733,1763,1792,1822,1851,1881,1910,1940,1969,1999,2028,2058,2087,2117,2146,2176,2205,2235,2264,2294,2323,2353,2383,2413,2442,2472,2501,2531,2560,2590,2619,2649,2678,2708,2737,2767,2796,2826,2855,2885,2914,2944,2973,3003,3032,3062,3091,3121,3150,3180,3209,3239,3268,3298,3327,3357,3386,3416,3446,3476,3505,3535,3564,3594,3623,3653,3682,3712,3741,3771,3800,3830,3859,3889,3918,3948,3977,4007,4036,4066,4095,4125,4155,4185,4214,4244,4273,4303,4332,4362,4391,4421,4450,4480,4509,4539,4568,4598,4627,4657,4686,4716,4745,4775,4804,4834,4863,4893,4922,4952,4981,5011,5040,5070,5099,5129,5158,5188,5218,5248,5277,5307,5336,5366,5395,5425,5454,5484,5513,5543,5572,5602,5631,5661,5690,5720,5749,5779,5808,5838,5867,5897,5926,5956,5985,6015,6044,6074,6103,6133,6162,6192,6221,6251,6281,6311,6340,6370,6399,6429,6458,6488,6517,6547,6576,6606,6635,6665,6694,6724,6753,6783,6812,6842,6871,6901,6930,6960,6989,7019,7048,7078,7107,7137,7166,7196,7225,7255,7284,7314,7344,7374,7403,7433,7462,7492,7521,7551,7580,7610,7639,7669,7698,7728,7757,7787,7816,7846,7875,7905,7934,7964,7993,8023,8053,8083,8112,8142,8171,8201,8230,8260,8289,8319,8348,8378,8407,8437,8466,8496,8525,8555,8584,8614,8643,8673,8702,8732,8761,8791,8821,8850,8880,8909,8938,8968,8997,9027,9056,9086,9115,9145,9175,9205,9234,9264,9293,9322,9352,9381,9410,9440,9470,9499,9529,9559,9589,9618,9648,9677,9706,9736,9765,9794,9824,9853,9883,9913,9943,9972,10002,10032,10061,10090,10120,10149,10178,10208,10237,10267,10297,10326,10356,10386,10415,10445,10474,10504,10533,10562,10592,10621,10651,10680,10710,10740,10770,10799,10829,10858,10888,10917,10947,10976,11005,11035,11064,11094,11124,11153,11183,11213,11242,11272,11301,11331,11360,11389,11419,11448,11478,11507,11537,11567,11596,11626,11655,11685,11715,11744,11774,11803,11832,11862,11891,11921,11950,11980,12010,12039,12069,12099,12128,12158,12187,12216,12246,12275,12304,12334,12364,12393,12423,12453,12483,12512,12542,12571,12600,12630,12659,12688,12718,12747,12777,12807,12837,12866,12896,12926,12955,12984,13014,13043,13072,13102,13131,13161,13191,13220,13250,13280,13310,13339,13368,13398,13427,13456,13486,13515,13545,13574,13604,13634,13664,13693,13723,13752,13782,13811,13840,13870,13899,13929,13958,13988,14018,14047,14077,14107,14136,14166,14195,14224,14254,14283,14313,14342,14372,14401,14431,14461,14490,14520,14550,14579,14609,14638,14667,14697,14726,14756,14785,14815,14844,14874,14904,14933,14963,14993,15021,15051,15081,15110,15140,15169,15199,15228,15258,15287,15317,15347,15377,15406,15436,15465,15494,15524,15553,15582,15612,15641,15671,15701,15731,15760,15790,15820,15849,15878,15908,15937,15966,15996,16025,16055,16085,16114,16144,16174,16204,16233,16262,16292,16321,16350,16380,16409,16439,16468,16498,16528,16558,16587,16617,16646,16676,16705,16734,16764,16793,16823,16852,16882,16912,16941,16971,17001,17030,17060,17089,17118,17148,17177,17207,17236,17266,17295,17325,17355,17384,17414,17444,17473,17502,17532,17561,17591,17620,17650,17679,17709,17738,17768,17798,17827,17857,17886,17916,17945,17975,18004,18034,18063,18093,18122,18152,18181,18211,18241,18270,18300,18330,18359,18388,18418,18447,18476,18506,18535,18565,18595,18625,18654,18684,18714,18743,18772,18802,18831,18860,18890,18919,18949,18979,19008,19038,19068,19098,19127,19156,19186,19215,19244,19274,19303,19333,19362,19392,19422,19452,19481,19511,19540,19570,19599,19628,19658,19687,19717,19746,19776,19806,19836,19865,19895,19924,19954,19983,20012,20042,20071,20101,20130,20160,20190,20219,20249,20279,20308,20338,20367,20396,20426,20455,20485,20514,20544,20573,20603,20633,20662,20692,20721,20751,20780,20810,20839,20869,20898,20928,20957,20987,21016,21046,21076,21105,21135,21164,21194,21223,21253,21282,21312,21341,21371,21400,21430,21459,21489,21519,21548,21578,21607,21637,21666,21696,21725,21754,21784,21813,21843,21873,21902,21932,21962,21991,22021,22050,22080,22109,22138,22168,22197,22227,22256,22286,22316,22346,22375,22405,22434,22464,22493,22522,22552,22581,22611,22640,22670,22700,22730,22759,22789,22818,22848,22877,22906,22936,22965,22994,23024,23054,23083,23113,23143,23173,23202,23232,23261,23290,23320,23349,23379,23408,23438,23467,23497,23527,23556,23586,23616,23645,23674,23704,23733,23763,23792,23822,23851,23881,23910,23940,23970,23999,24029,24058,24088,24117,24147,24176,24206,24235,24265,24294,24324,24353,24383,24413,24442,24472,24501,24531,24560,24590,24619,24648,24678,24707,24737,24767,24796,24826,24856,24885,24915,24944,24974,25003,25032,25062,25091,25121,25150,25180,25210,25240,25269,25299,25328,25358,25387,25416,25446,25475,25505,25534,25564,25594,25624,25653,25683,25712,25742,25771,25800,25830,25859,25888,25918,25948,25977,26007,26037,26067,26096,26126,26155,26184,26214,26243,26272,26302,26332,26361,26391,26421,26451,26480,26510,26539,26568,26598,26627,26656,26686,26715,26745,26775,26805,26834,26864,26893,26923,26952,26982,27011,27041,27070,27099,27129,27159,27188,27218,27248,27277,27307,27336,27366,27395,27425,27454,27484,27513,27542,27572,27602,27631,27661,27691,27720,27750,27779,27809,27838,27868,27897,27926,27956,27985,28015,28045,28074,28104,28134,28163,28193,28222,28252,28281,28310,28340,28369,28399,28428,28458,28488,28517,28547,28577,28607,28636,28665,28695,28724,28754,28783,28813,28843,28872,28901,28931,28960,28990,29019,29049,29078,29108,29137,29167,29196,29226,29255,29285,29315,29345,29375,29404,29434,29463,29492,29522,29551,29580,29610,29640,29669,29699,29729,29759,29788,29818,29847,29876,29906,29935,29964,29994,30023,30053,30082,30112,30141,30171,30200,30230,30259,30289,30318,30348,30378,30408,30437,30467,30496,30526,30555,30585,30614,30644,30673,30703,30732,30762,30791,30821,30850,30880,30909,30939,30968,30998,31027,31057,31086,31116,31145,31175,31204,31234,31263,31293,31322,31352,31381,31411,31441,31471,31500,31530,31559,31589,31618,31648,31676,31706,31736,31766,31795,31825,31854,31884,31913,31943,31972,32002,32031,32061,32090,32120,32150,32180,32209,32239,32268,32298,32327,32357,32386,32416,32445,32475,32504,32534,32563,32593,32622,32652,32681,32711,32740,32770,32799,32829,32858,32888,32917,32947,32976,33006,33035,33065,33094,33124,33153,33183,33213,33243,33272,33302,33331,33361,33390,33420,33450,33479,33509,33539,33568,33598,33627,33657,33686,33716,33745,33775,33804,33834,33863,33893,33922,33952,33981,34011,34040,34069,34099,34128,34158,34187,34217,34247,34277,34306,34336,34365,34395,34424,34454,34483,34512,34542,34571,34601,34631,34660,34690,34719,34749,34778,34808,34837,34867,34896,34926,34955,34985,35015,35044,35074,35103,35133,35162,35192,35222,35251,35280,35310,35340,35370,35399,35429,35458,35488,35517,35547,35576,35605,35635,35665,35694,35723,35753,35782,35811,35841,35871,35901,35930,35960,35989,36019,36048,36078,36107,36136,36166,36195,36225,36254,36284,36314,36343,36373,36403,36433,36462,36492,36521,36551,36580,36610,36639,36669,36698,36728,36757,36786,36816,36845,36875,36904,36934,36963,36993,37022,37052,37081,37111,37141,37170,37200,37229,37259,37288,37318,37347,37377,37406,37436,37465,37495,37524,37554,37584,37613,37643,37672,37701,37731,37760,37790,37819,37849,37878,37908,37938,37967,37997,38027,38056,38085,38115,38144,38174,38203,38233,38262,38292,38322,38351,38381,38410,38440,38469,38499,38528,38558,38587,38617,38646,38676,38705,38735,38764,38794,38823,38853,38882,38912,38941,38971,39001,39030,39059,39089,39118,39148,39178,39208,39237,39267,39297,39326,39355,39385,39414,39444,39473,39503,39532,39562,39592,39621,39650,39680,39709,39739,39768,39798,39827,39857,39886,39916,39946,39975,40005,40035,40064,40094,40123,40153,40182,40212,40241,40271,40300,40330,40359,40389,40418,40448,40477,40507,40536,40566,40595,40625,40655,40685,40714,40744,40773,40803,40832,40862,40892,40921,40951,40980,41009,41039,41068,41098,41127,41157,41186,41216,41245,41275,41304,41334,41364,41393,41422,41452,41481,41511,41540,41570,41599,41629,41658,41688,41718,41748,41777,41807,41836,41865,41894,41924,41953,41983,42012,42042,42072,42102,42131,42161,42190,42220,42249,42279,42308,42337,42367,42397,42426,42456,42485,42515,42545,42574,42604,42633,42662,42692,42721,42751,42780,42810,42839,42869,42899,42929,42958,42988,43017,43046,43076,43105,43135,43164,43194,43223,43253,43283,43312,43342,43371,43401,43430,43460,43489,43519,43548,43578,43607,43637,43666,43696,43726,43755,43785,43814,43844,43873,43903,43932,43962,43991,44021,44050,44080,44109,44139,44169,44198,44228,44258,44287,44317,44346,44375,44405,44434,44464,44493,44523,44553,44582,44612,44641,44671,44700,44730,44759,44788,44818,44847,44877,44906,44936,44966,44996,45025,45055,45084,45114,45143,45172,45202,45231,45261,45290,45320,45350,45380,45409,45439,45468,45498,45527,45556,45586,45615,45644,45674,45704,45733,45763,45793,45823,45852,45882,45911,45940,45970,45999,46028,46058,46088,46117,46147,46177,46206,46236,46265,46295,46324,46354,46383,46413,46442,46472,46501,46531,46560,46590,46620,46649,46679,46708,46738,46767,46797,46826,46856,46885,46915,46944,46974,47003,47033,47063,47092,47122,47151,47181,47210,47240,47269,47298,47328,47357,47387,47417,47446,47476,47506,47535,47565,47594,47624,47653,47682,47712,47741,47771,47800,47830,47860,47890,47919,47949,47978,48008,48037,48066,48096,48125,48155,48184,48214,48244,48273,48303,48333,48362,48392,48421,48450,48480,48509,48538,48568,48598,48627,48657,48687,48717,48746,48776,48805,48834,48864,48893,48922,48952,48982,49011,49041,49071,49100,49130,49160,49189,49218,49248,49277,49306,49336,49365,49395,49425,49455,49484,49514,49543,49573,49602,49632,49661,49690,49720,49749,49779,49809,49838,49868,49898,49927,49957,49986,50016,50045,50075,50104,50133,50163,50192,50222,50252,50281,50311,50340,50370,50400,50429,50459,50488,50518,50547,50576,50606,50635,50665,50694,50724,50754,50784,50813,50843,50872,50902,50931,50960,50990,51019,51049,51078,51108,51138,51167,51197,51227,51256,51286,51315,51345,51374,51403,51433,51462,51492,51522,51552,51582,51611,51641,51670,51699,51729,51758,51787,51816,51846,51876,51906,51936,51965,51995,52025,52054,52083,52113,52142,52171,52200,52230,52260,52290,52319,52349,52379,52408,52438,52467,52497,52526,52555,52585,52614,52644,52673,52703,52733,52762,52792,52822,52851,52881,52910,52939,52969,52998,53028,53057,53087,53116,53146,53176,53205,53235,53264,53294,53324,53353,53383,53412,53441,53471,53500,53530,53559,53589,53619,53648,53678,53708,53737,53767,53796,53825,53855,53884,53913,53943,53973,54003,54032,54062,54092,54121,54151,54180,54209,54239,54268,54297,54327,54357,54387,54416,54446,54476,54505,54535,54564,54593,54623,54652,54681,54711,54741,54770,54800,54830,54859,54889,54919,54948,54977,55007,55036,55066,55095,55125,55154,55184,55213,55243,55273,55302,55332,55361,55391,55420,55450,55479,55508,55538,55567,55597,55627,55657,55686,55716,55745,55775,55804,55834,55863,55892,55922,55951,55981,56011,56040,56070,56100,56129,56159,56188,56218,56247,56276,56306,56335,56365,56394,56424,56454,56483,56513,56543,56572,56601,56631,56660,56690,56719,56749,56778,56808,56837,56867,56897,56926,56956,56985,57015,57044,57074,57103,57133,57162,57192,57221,57251,57280,57310,57340,57369,57399,57429,57458,57487,57517,57546,57576,57605,57634,57664,57694,57723,57753,57783,57813,57842,57871,57901,57930,57959,57989,58018,58048,58077,58107,58137,58167,58196,58226,58255,58285,58314,58343,58373,58402,58432,58461,58491,58521,58551,58580,58610,58639,58669,58698,58727,58757,58786,58816,58845,58875,58905,58934,58964,58994,59023,59053,59082,59111,59141,59170,59200,59229,59259,59288,59318,59348,59377,59407,59436,59466,59495,59525,59554,59584,59613,59643,59672,59702,59731,59761,59791,59820,59850,59879,59909,59939,59968,59997,60027,60056,60086,60115,60145,60174,60204,60234,60264,60293,60323,60352,60381,60411,60440,60469,60499,60528,60558,60588,60618,60648,60677,60707,60736,60765,60795,60824,60853,60883,60912,60942,60972,61002,61031,61061,61090,61120,61149,61179,61208,61237,61267,61296,61326,61356,61385,61415,61445,61474,61504,61533,61563,61592,61621,61651,61680,61710,61739,61769,61799,61828,61858,61888,61917,61947,61976,62006,62035,62064,62094,62123,62153,62182,62212,62242,62271,62301,62331,62360,62390,62419,62448,62478,62507,62537,62566,62596,62625,62655,62685,62715,62744,62774,62803,62832,62862,62891,62921,62950,62980,63009,63039,63069,63099,63128,63157,63187,63216,63246,63275,63305,63334,63363,63393,63423,63453,63482,63512,63541,63571,63600,63630,63659,63689,63718,63747,63777,63807,63836,63866,63895,63925,63955,63984,64014,64043,64073,64102,64131,64161,64190,64220,64249,64279,64309,64339,64368,64398,64427,64457,64486,64515,64545,64574,64603,64633,64663,64692,64722,64752,64782,64811,64841,64870,64899,64929,64958,64987,65017,65047,65076,65106,65136,65166,65195,65225,65254,65283,65313,65342,65371,65401,65431,65460,65490,65520,65549,65579,65608,65638,65667,65697,65726,65755,65785,65815,65844,65874,65903,65933,65963,65992,66022,66051,66081,66110,66140,66169,66199,66228,66258,66287,66317,66346,66376,66405,66435,66465,66494,66524,66553,66583,66612,66641,66671,66700,66730,66760,66789,66819,66849,66878,66908,66937,66967,66996,67025,67055,67084,67114,67143,67173,67203,67233,67262,67292,67321,67351,67380,67409,67439,67468,67497,67527,67557,67587,67617,67646,67676,67705,67735,67764,67793,67823,67852,67882,67911,67941,67971,68e3,68030,68060,68089,68119,68148,68177,68207,68236,68266,68295,68325,68354,68384,68414,68443,68473,68502,68532,68561,68591,68620,68650,68679,68708,68738,68768,68797,68827,68857,68886,68916,68946,68975,69004,69034,69063,69092,69122,69152,69181,69211,69240,69270,69300,69330,69359,69388,69418,69447,69476,69506,69535,69565,69595,69624,69654,69684,69713,69743,69772,69802,69831,69861,69890,69919,69949,69978,70008,70038,70067,70097,70126,70156,70186,70215,70245,70274,70303,70333,70362,70392,70421,70451,70481,70510,70540,70570,70599,70629,70658,70687,70717,70746,70776,70805,70835,70864,70894,70924,70954,70983,71013,71042,71071,71101,71130,71159,71189,71218,71248,71278,71308,71337,71367,71397,71426,71455,71485,71514,71543,71573,71602,71632,71662,71691,71721,71751,71781,71810,71839,71869,71898,71927,71957,71986,72016,72046,72075,72105,72135,72164,72194,72223,72253,72282,72311,72341,72370,72400,72429,72459,72489,72518,72548,72577,72607,72637,72666,72695,72725,72754,72784,72813,72843,72872,72902,72931,72961,72991,73020,73050,73080,73109,73139,73168,73197,73227,73256,73286,73315,73345,73375,73404,73434,73464,73493,73523,73552,73581,73611,73640,73669,73699,73729,73758,73788,73818,73848,73877,73907,73936,73965,73995,74024,74053,74083,74113,74142,74172,74202,74231,74261,74291,74320,74349,74379,74408,74437,74467,74497,74526,74556,74586,74615,74645,74675,74704,74733,74763,74792,74822,74851,74881,74910,74940,74969,74999,75029,75058,75088,75117,75147,75176,75206,75235,75264,75294,75323,75353,75383,75412,75442,75472,75501,75531,75560,75590,75619,75648,75678,75707,75737,75766,75796,75826,75856,75885,75915,75944,75974,76003,76032,76062,76091,76121,76150,76180,76210,76239,76269,76299,76328,76358,76387,76416,76446,76475,76505,76534,76564,76593,76623,76653,76682,76712,76741,76771,76801,76830,76859,76889,76918,76948,76977,77007,77036,77066,77096,77125,77155,77185,77214,77243,77273,77302,77332,77361,77390,77420,77450,77479,77509,77539,77569,77598,77627,77657,77686,77715,77745,77774,77804,77833,77863,77893,77923,77952,77982,78011,78041,78070,78099,78129,78158,78188,78217,78247,78277,78307,78336,78366,78395,78425,78454,78483,78513,78542,78572,78601,78631,78661,78690,78720,78750,78779,78808,78838,78867,78897,78926,78956,78985,79015,79044,79074,79104,79133,79163,79192,79222,79251,79281,79310,79340,79369,79399,79428,79458,79487,79517,79546,79576,79606,79635,79665,79695,79724,79753,79783,79812,79841,79871,79900,79930,79960,79990]},{"../main":346,"object-assign":247}],346:[function(t,e,r){var n=t("object-assign");function i(){this.regionalOptions=[],this.regionalOptions[""]={invalidCalendar:"Calendar {0} not found",invalidDate:"Invalid {0} date",invalidMonth:"Invalid {0} month",invalidYear:"Invalid {0} year",differentCalendars:"Cannot mix {0} and {1} dates"},this.local=this.regionalOptions[""],this.calendars={},this._localCals={}}function a(t,e,r,n){if(this._calendar=t,this._year=e,this._month=r,this._day=n,0===this._calendar._validateLevel&&!this._calendar.isValid(this._year,this._month,this._day))throw(c.local.invalidDate||c.regionalOptions[""].invalidDate).replace(/\{0\}/,this._calendar.local.name)}function o(t,e){return"000000".substring(0,e-(t=""+t).length)+t}function s(){this.shortYearCutoff="+10"}function l(t){this.local=this.regionalOptions[t]||this.regionalOptions[""]}n(i.prototype,{instance:function(t,e){t=(t||"gregorian").toLowerCase(),e=e||"";var r=this._localCals[t+"-"+e];if(!r&&this.calendars[t]&&(r=new this.calendars[t](e),this._localCals[t+"-"+e]=r),!r)throw(this.local.invalidCalendar||this.regionalOptions[""].invalidCalendar).replace(/\{0\}/,t);return r},newDate:function(t,e,r,n,i){return(n=(null!=t&&t.year?t.calendar():"string"==typeof n?this.instance(n,i):n)||this.instance()).newDate(t,e,r)},substituteDigits:function(t){return function(e){return(e+"").replace(/[0-9]/g,(function(e){return t[e]}))}},substituteChineseDigits:function(t,e){return function(r){for(var n="",i=0;r>0;){var a=r%10;n=(0===a?"":t[a]+e[i])+n,i++,r=Math.floor(r/10)}return 0===n.indexOf(t[1]+e[1])&&(n=n.substr(1)),n||t[0]}}}),n(a.prototype,{newDate:function(t,e,r){return this._calendar.newDate(null==t?this:t,e,r)},year:function(t){return 0===arguments.length?this._year:this.set(t,"y")},month:function(t){return 0===arguments.length?this._month:this.set(t,"m")},day:function(t){return 0===arguments.length?this._day:this.set(t,"d")},date:function(t,e,r){if(!this._calendar.isValid(t,e,r))throw(c.local.invalidDate||c.regionalOptions[""].invalidDate).replace(/\{0\}/,this._calendar.local.name);return this._year=t,this._month=e,this._day=r,this},leapYear:function(){return this._calendar.leapYear(this)},epoch:function(){return this._calendar.epoch(this)},formatYear:function(){return this._calendar.formatYear(this)},monthOfYear:function(){return this._calendar.monthOfYear(this)},weekOfYear:function(){return this._calendar.weekOfYear(this)},daysInYear:function(){return this._calendar.daysInYear(this)},dayOfYear:function(){return this._calendar.dayOfYear(this)},daysInMonth:function(){return this._calendar.daysInMonth(this)},dayOfWeek:function(){return this._calendar.dayOfWeek(this)},weekDay:function(){return this._calendar.weekDay(this)},extraInfo:function(){return this._calendar.extraInfo(this)},add:function(t,e){return this._calendar.add(this,t,e)},set:function(t,e){return this._calendar.set(this,t,e)},compareTo:function(t){if(this._calendar.name!==t._calendar.name)throw(c.local.differentCalendars||c.regionalOptions[""].differentCalendars).replace(/\{0\}/,this._calendar.local.name).replace(/\{1\}/,t._calendar.local.name);var e=this._year!==t._year?this._year-t._year:this._month!==t._month?this.monthOfYear()-t.monthOfYear():this._day-t._day;return 0===e?0:e<0?-1:1},calendar:function(){return this._calendar},toJD:function(){return this._calendar.toJD(this)},fromJD:function(t){return this._calendar.fromJD(t)},toJSDate:function(){return this._calendar.toJSDate(this)},fromJSDate:function(t){return this._calendar.fromJSDate(t)},toString:function(){return(this.year()<0?"-":"")+o(Math.abs(this.year()),4)+"-"+o(this.month(),2)+"-"+o(this.day(),2)}}),n(s.prototype,{_validateLevel:0,newDate:function(t,e,r){return null==t?this.today():(t.year&&(this._validate(t,e,r,c.local.invalidDate||c.regionalOptions[""].invalidDate),r=t.day(),e=t.month(),t=t.year()),new a(this,t,e,r))},today:function(){return this.fromJSDate(new Date)},epoch:function(t){return this._validate(t,this.minMonth,this.minDay,c.local.invalidYear||c.regionalOptions[""].invalidYear).year()<0?this.local.epochs[0]:this.local.epochs[1]},formatYear:function(t){var e=this._validate(t,this.minMonth,this.minDay,c.local.invalidYear||c.regionalOptions[""].invalidYear);return(e.year()<0?"-":"")+o(Math.abs(e.year()),4)},monthsInYear:function(t){return this._validate(t,this.minMonth,this.minDay,c.local.invalidYear||c.regionalOptions[""].invalidYear),12},monthOfYear:function(t,e){var r=this._validate(t,e,this.minDay,c.local.invalidMonth||c.regionalOptions[""].invalidMonth);return(r.month()+this.monthsInYear(r)-this.firstMonth)%this.monthsInYear(r)+this.minMonth},fromMonthOfYear:function(t,e){var r=(e+this.firstMonth-2*this.minMonth)%this.monthsInYear(t)+this.minMonth;return this._validate(t,r,this.minDay,c.local.invalidMonth||c.regionalOptions[""].invalidMonth),r},daysInYear:function(t){var e=this._validate(t,this.minMonth,this.minDay,c.local.invalidYear||c.regionalOptions[""].invalidYear);return this.leapYear(e)?366:365},dayOfYear:function(t,e,r){var n=this._validate(t,e,r,c.local.invalidDate||c.regionalOptions[""].invalidDate);return n.toJD()-this.newDate(n.year(),this.fromMonthOfYear(n.year(),this.minMonth),this.minDay).toJD()+1},daysInWeek:function(){return 7},dayOfWeek:function(t,e,r){var n=this._validate(t,e,r,c.local.invalidDate||c.regionalOptions[""].invalidDate);return(Math.floor(this.toJD(n))+2)%this.daysInWeek()},extraInfo:function(t,e,r){return this._validate(t,e,r,c.local.invalidDate||c.regionalOptions[""].invalidDate),{}},add:function(t,e,r){return this._validate(t,this.minMonth,this.minDay,c.local.invalidDate||c.regionalOptions[""].invalidDate),this._correctAdd(t,this._add(t,e,r),e,r)},_add:function(t,e,r){if(this._validateLevel++,"d"===r||"w"===r){var n=t.toJD()+e*("w"===r?this.daysInWeek():1),i=t.calendar().fromJD(n);return this._validateLevel--,[i.year(),i.month(),i.day()]}try{var a=t.year()+("y"===r?e:0),o=t.monthOfYear()+("m"===r?e:0);i=t.day();"y"===r?(t.month()!==this.fromMonthOfYear(a,o)&&(o=this.newDate(a,t.month(),this.minDay).monthOfYear()),o=Math.min(o,this.monthsInYear(a)),i=Math.min(i,this.daysInMonth(a,this.fromMonthOfYear(a,o)))):"m"===r&&(!function(t){for(;o<t.minMonth;)a--,o+=t.monthsInYear(a);for(var e=t.monthsInYear(a);o>e-1+t.minMonth;)a++,o-=e,e=t.monthsInYear(a)}(this),i=Math.min(i,this.daysInMonth(a,this.fromMonthOfYear(a,o))));var s=[a,this.fromMonthOfYear(a,o),i];return this._validateLevel--,s}catch(t){throw this._validateLevel--,t}},_correctAdd:function(t,e,r,n){if(!(this.hasYearZero||"y"!==n&&"m"!==n||0!==e[0]&&t.year()>0==e[0]>0)){var i={y:[1,1,"y"],m:[1,this.monthsInYear(-1),"m"],w:[this.daysInWeek(),this.daysInYear(-1),"d"],d:[1,this.daysInYear(-1),"d"]}[n],a=r<0?-1:1;e=this._add(t,r*i[0]+a*i[1],i[2])}return t.date(e[0],e[1],e[2])},set:function(t,e,r){this._validate(t,this.minMonth,this.minDay,c.local.invalidDate||c.regionalOptions[""].invalidDate);var n="y"===r?e:t.year(),i="m"===r?e:t.month(),a="d"===r?e:t.day();return"y"!==r&&"m"!==r||(a=Math.min(a,this.daysInMonth(n,i))),t.date(n,i,a)},isValid:function(t,e,r){this._validateLevel++;var n=this.hasYearZero||0!==t;if(n){var i=this.newDate(t,e,this.minDay);n=e>=this.minMonth&&e-this.minMonth<this.monthsInYear(i)&&r>=this.minDay&&r-this.minDay<this.daysInMonth(i)}return this._validateLevel--,n},toJSDate:function(t,e,r){var n=this._validate(t,e,r,c.local.invalidDate||c.regionalOptions[""].invalidDate);return c.instance().fromJD(this.toJD(n)).toJSDate()},fromJSDate:function(t){return this.fromJD(c.instance().fromJSDate(t).toJD())},_validate:function(t,e,r,n){if(t.year){if(0===this._validateLevel&&this.name!==t.calendar().name)throw(c.local.differentCalendars||c.regionalOptions[""].differentCalendars).replace(/\{0\}/,this.local.name).replace(/\{1\}/,t.calendar().local.name);return t}try{if(this._validateLevel++,1===this._validateLevel&&!this.isValid(t,e,r))throw n.replace(/\{0\}/,this.local.name);var i=this.newDate(t,e,r);return this._validateLevel--,i}catch(t){throw this._validateLevel--,t}}}),l.prototype=new s,n(l.prototype,{name:"Gregorian",jdEpoch:1721425.5,daysPerMonth:[31,28,31,30,31,30,31,31,30,31,30,31],hasYearZero:!1,minMonth:1,firstMonth:1,minDay:1,regionalOptions:{"":{name:"Gregorian",epochs:["BCE","CE"],monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],monthNamesShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayNamesShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dayNamesMin:["Su","Mo","Tu","We","Th","Fr","Sa"],digits:null,dateFormat:"mm/dd/yyyy",firstDay:0,isRTL:!1}},leapYear:function(t){var e=this._validate(t,this.minMonth,this.minDay,c.local.invalidYear||c.regionalOptions[""].invalidYear);return(t=e.year()+(e.year()<0?1:0))%4==0&&(t%100!=0||t%400==0)},weekOfYear:function(t,e,r){var n=this.newDate(t,e,r);return n.add(4-(n.dayOfWeek()||7),"d"),Math.floor((n.dayOfYear()-1)/7)+1},daysInMonth:function(t,e){var r=this._validate(t,e,this.minDay,c.local.invalidMonth||c.regionalOptions[""].invalidMonth);return this.daysPerMonth[r.month()-1]+(2===r.month()&&this.leapYear(r.year())?1:0)},weekDay:function(t,e,r){return(this.dayOfWeek(t,e,r)||7)<6},toJD:function(t,e,r){var n=this._validate(t,e,r,c.local.invalidDate||c.regionalOptions[""].invalidDate);t=n.year(),e=n.month(),r=n.day(),t<0&&t++,e<3&&(e+=12,t--);var i=Math.floor(t/100),a=2-i+Math.floor(i/4);return Math.floor(365.25*(t+4716))+Math.floor(30.6001*(e+1))+r+a-1524.5},fromJD:function(t){var e=Math.floor(t+.5),r=Math.floor((e-1867216.25)/36524.25),n=(r=e+1+r-Math.floor(r/4))+1524,i=Math.floor((n-122.1)/365.25),a=Math.floor(365.25*i),o=Math.floor((n-a)/30.6001),s=n-a-Math.floor(30.6001*o),l=o-(o>13.5?13:1),c=i-(l>2.5?4716:4715);return c<=0&&c--,this.newDate(c,l,s)},toJSDate:function(t,e,r){var n=this._validate(t,e,r,c.local.invalidDate||c.regionalOptions[""].invalidDate),i=new Date(n.year(),n.month()-1,n.day());return i.setHours(0),i.setMinutes(0),i.setSeconds(0),i.setMilliseconds(0),i.setHours(i.getHours()>12?i.getHours()+2:0),i},fromJSDate:function(t){return this.newDate(t.getFullYear(),t.getMonth()+1,t.getDate())}});var c=e.exports=new i;c.cdate=a,c.baseCalendar=s,c.calendars.gregorian=l},{"object-assign":247}],347:[function(t,e,r){var n=t("object-assign"),i=t("./main");n(i.regionalOptions[""],{invalidArguments:"Invalid arguments",invalidFormat:"Cannot format a date from another calendar",missingNumberAt:"Missing number at position {0}",unknownNameAt:"Unknown name at position {0}",unexpectedLiteralAt:"Unexpected literal at position {0}",unexpectedText:"Additional text found at end"}),i.local=i.regionalOptions[""],n(i.cdate.prototype,{formatDate:function(t,e){return"string"!=typeof t&&(e=t,t=""),this._calendar.formatDate(t||"",this,e)}}),n(i.baseCalendar.prototype,{UNIX_EPOCH:i.instance().newDate(1970,1,1).toJD(),SECS_PER_DAY:86400,TICKS_EPOCH:i.instance().jdEpoch,TICKS_PER_DAY:864e9,ATOM:"yyyy-mm-dd",COOKIE:"D, dd M yyyy",FULL:"DD, MM d, yyyy",ISO_8601:"yyyy-mm-dd",JULIAN:"J",RFC_822:"D, d M yy",RFC_850:"DD, dd-M-yy",RFC_1036:"D, d M yy",RFC_1123:"D, d M yyyy",RFC_2822:"D, d M yyyy",RSS:"D, d M yy",TICKS:"!",TIMESTAMP:"@",W3C:"yyyy-mm-dd",formatDate:function(t,e,r){if("string"!=typeof t&&(r=e,e=t,t=""),!e)return"";if(e.calendar()!==this)throw i.local.invalidFormat||i.regionalOptions[""].invalidFormat;t=t||this.local.dateFormat;for(var n,a,o,s,l=(r=r||{}).dayNamesShort||this.local.dayNamesShort,c=r.dayNames||this.local.dayNames,u=r.monthNumbers||this.local.monthNumbers,f=r.monthNamesShort||this.local.monthNamesShort,h=r.monthNames||this.local.monthNames,p=(r.calculateWeek||this.local.calculateWeek,function(e,r){for(var n=1;w+n<t.length&&t.charAt(w+n)===e;)n++;return w+=n-1,Math.floor(n/(r||1))>1}),d=function(t,e,r,n){var i=""+e;if(p(t,n))for(;i.length<r;)i="0"+i;return i},m=this,g=function(t){return"function"==typeof u?u.call(m,t,p("m")):x(d("m",t.month(),2))},v=function(t,e){return e?"function"==typeof h?h.call(m,t):h[t.month()-m.minMonth]:"function"==typeof f?f.call(m,t):f[t.month()-m.minMonth]},y=this.local.digits,x=function(t){return r.localNumbers&&y?y(t):t},b="",_=!1,w=0;w<t.length;w++)if(_)"'"!==t.charAt(w)||p("'")?b+=t.charAt(w):_=!1;else switch(t.charAt(w)){case"d":b+=x(d("d",e.day(),2));break;case"D":b+=(n="D",a=e.dayOfWeek(),o=l,s=c,p(n)?s[a]:o[a]);break;case"o":b+=d("o",e.dayOfYear(),3);break;case"w":b+=d("w",e.weekOfYear(),2);break;case"m":b+=g(e);break;case"M":b+=v(e,p("M"));break;case"y":b+=p("y",2)?e.year():(e.year()%100<10?"0":"")+e.year()%100;break;case"Y":p("Y",2),b+=e.formatYear();break;case"J":b+=e.toJD();break;case"@":b+=(e.toJD()-this.UNIX_EPOCH)*this.SECS_PER_DAY;break;case"!":b+=(e.toJD()-this.TICKS_EPOCH)*this.TICKS_PER_DAY;break;case"'":p("'")?b+="'":_=!0;break;default:b+=t.charAt(w)}return b},parseDate:function(t,e,r){if(null==e)throw i.local.invalidArguments||i.regionalOptions[""].invalidArguments;if(""===(e="object"==typeof e?e.toString():e+""))return null;t=t||this.local.dateFormat;var n=(r=r||{}).shortYearCutoff||this.shortYearCutoff;n="string"!=typeof n?n:this.today().year()%100+parseInt(n,10);for(var a=r.dayNamesShort||this.local.dayNamesShort,o=r.dayNames||this.local.dayNames,s=r.parseMonth||this.local.parseMonth,l=r.monthNumbers||this.local.monthNumbers,c=r.monthNamesShort||this.local.monthNamesShort,u=r.monthNames||this.local.monthNames,f=-1,h=-1,p=-1,d=-1,m=-1,g=!1,v=!1,y=function(e,r){for(var n=1;M+n<t.length&&t.charAt(M+n)===e;)n++;return M+=n-1,Math.floor(n/(r||1))>1},x=function(t,r){var n=y(t,r),a=[2,3,n?4:2,n?4:2,10,11,20]["oyYJ@!".indexOf(t)+1],o=new RegExp("^-?\\d{1,"+a+"}"),s=e.substring(A).match(o);if(!s)throw(i.local.missingNumberAt||i.regionalOptions[""].missingNumberAt).replace(/\{0\}/,A);return A+=s[0].length,parseInt(s[0],10)},b=this,_=function(){if("function"==typeof l){y("m");var t=l.call(b,e.substring(A));return A+=t.length,t}return x("m")},w=function(t,r,n,a){for(var o=y(t,a)?n:r,s=0;s<o.length;s++)if(e.substr(A,o[s].length).toLowerCase()===o[s].toLowerCase())return A+=o[s].length,s+b.minMonth;throw(i.local.unknownNameAt||i.regionalOptions[""].unknownNameAt).replace(/\{0\}/,A)},T=function(){if("function"==typeof u){var t=y("M")?u.call(b,e.substring(A)):c.call(b,e.substring(A));return A+=t.length,t}return w("M",c,u)},k=function(){if(e.charAt(A)!==t.charAt(M))throw(i.local.unexpectedLiteralAt||i.regionalOptions[""].unexpectedLiteralAt).replace(/\{0\}/,A);A++},A=0,M=0;M<t.length;M++)if(v)"'"!==t.charAt(M)||y("'")?k():v=!1;else switch(t.charAt(M)){case"d":d=x("d");break;case"D":w("D",a,o);break;case"o":m=x("o");break;case"w":x("w");break;case"m":p=_();break;case"M":p=T();break;case"y":var S=M;g=!y("y",2),M=S,h=x("y",2);break;case"Y":h=x("Y",2);break;case"J":f=x("J")+.5,"."===e.charAt(A)&&(A++,x("J"));break;case"@":f=x("@")/this.SECS_PER_DAY+this.UNIX_EPOCH;break;case"!":f=x("!")/this.TICKS_PER_DAY+this.TICKS_EPOCH;break;case"*":A=e.length;break;case"'":y("'")?k():v=!0;break;default:k()}if(A<e.length)throw i.local.unexpectedText||i.regionalOptions[""].unexpectedText;if(-1===h?h=this.today().year():h<100&&g&&(h+=-1===n?1900:this.today().year()-this.today().year()%100-(h<=n?0:100)),"string"==typeof p&&(p=s.call(this,h,p)),m>-1){p=1,d=m;for(var E=this.daysInMonth(h,p);d>E;E=this.daysInMonth(h,p))p++,d-=E}return f>-1?this.fromJD(f):this.newDate(h,p,d)},determineDate:function(t,e,r,n,i){r&&"object"!=typeof r&&(i=n,n=r,r=null),"string"!=typeof n&&(i=n,n="");var a=this;return e=e?e.newDate():null,t=null==t?e:"string"==typeof t?function(t){try{return a.parseDate(n,t,i)}catch(t){}for(var e=((t=t.toLowerCase()).match(/^c/)&&r?r.newDate():null)||a.today(),o=/([+-]?[0-9]+)\s*(d|w|m|y)?/g,s=o.exec(t);s;)e.add(parseInt(s[1],10),s[2]||"d"),s=o.exec(t);return e}(t):"number"==typeof t?isNaN(t)||t===1/0||t===-1/0?e:a.today().add(t,"d"):a.newDate(t)}})},{"./main":346,"object-assign":247}],348:[function(t,e,r){"use strict";e.exports=[{path:"",backoff:0},{path:"M-2.4,-3V3L0.6,0Z",backoff:.6},{path:"M-3.7,-2.5V2.5L1.3,0Z",backoff:1.3},{path:"M-4.45,-3L-1.65,-0.2V0.2L-4.45,3L1.55,0Z",backoff:1.55},{path:"M-2.2,-2.2L-0.2,-0.2V0.2L-2.2,2.2L-1.4,3L1.6,0L-1.4,-3Z",backoff:1.6},{path:"M-4.4,-2.1L-0.6,-0.2V0.2L-4.4,2.1L-4,3L2,0L-4,-3Z",backoff:2},{path:"M2,0A2,2 0 1,1 0,-2A2,2 0 0,1 2,0Z",backoff:0,noRotate:!0},{path:"M2,2V-2H-2V2Z",backoff:0,noRotate:!0}]},{}],349:[function(t,e,r){"use strict";var n=t("./arrow_paths"),i=t("../../plots/font_attributes"),a=t("../../plots/cartesian/constants"),o=t("../../plot_api/plot_template").templatedArray;t("../../constants/axis_placeable_objects");e.exports=o("annotation",{visible:{valType:"boolean",dflt:!0,editType:"calc+arraydraw"},text:{valType:"string",editType:"calc+arraydraw"},textangle:{valType:"angle",dflt:0,editType:"calc+arraydraw"},font:i({editType:"calc+arraydraw",colorEditType:"arraydraw"}),width:{valType:"number",min:1,dflt:null,editType:"calc+arraydraw"},height:{valType:"number",min:1,dflt:null,editType:"calc+arraydraw"},opacity:{valType:"number",min:0,max:1,dflt:1,editType:"arraydraw"},align:{valType:"enumerated",values:["left","center","right"],dflt:"center",editType:"arraydraw"},valign:{valType:"enumerated",values:["top","middle","bottom"],dflt:"middle",editType:"arraydraw"},bgcolor:{valType:"color",dflt:"rgba(0,0,0,0)",editType:"arraydraw"},bordercolor:{valType:"color",dflt:"rgba(0,0,0,0)",editType:"arraydraw"},borderpad:{valType:"number",min:0,dflt:1,editType:"calc+arraydraw"},borderwidth:{valType:"number",min:0,dflt:1,editType:"calc+arraydraw"},showarrow:{valType:"boolean",dflt:!0,editType:"calc+arraydraw"},arrowcolor:{valType:"color",editType:"arraydraw"},arrowhead:{valType:"integer",min:0,max:n.length,dflt:1,editType:"arraydraw"},startarrowhead:{valType:"integer",min:0,max:n.length,dflt:1,editType:"arraydraw"},arrowside:{valType:"flaglist",flags:["end","start"],extras:["none"],dflt:"end",editType:"arraydraw"},arrowsize:{valType:"number",min:.3,dflt:1,editType:"calc+arraydraw"},startarrowsize:{valType:"number",min:.3,dflt:1,editType:"calc+arraydraw"},arrowwidth:{valType:"number",min:.1,editType:"calc+arraydraw"},standoff:{valType:"number",min:0,dflt:0,editType:"calc+arraydraw"},startstandoff:{valType:"number",min:0,dflt:0,editType:"calc+arraydraw"},ax:{valType:"any",editType:"calc+arraydraw"},ay:{valType:"any",editType:"calc+arraydraw"},axref:{valType:"enumerated",dflt:"pixel",values:["pixel",a.idRegex.x.toString()],editType:"calc"},ayref:{valType:"enumerated",dflt:"pixel",values:["pixel",a.idRegex.y.toString()],editType:"calc"},xref:{valType:"enumerated",values:["paper",a.idRegex.x.toString()],editType:"calc"},x:{valType:"any",editType:"calc+arraydraw"},xanchor:{valType:"enumerated",values:["auto","left","center","right"],dflt:"auto",editType:"calc+arraydraw"},xshift:{valType:"number",dflt:0,editType:"calc+arraydraw"},yref:{valType:"enumerated",values:["paper",a.idRegex.y.toString()],editType:"calc"},y:{valType:"any",editType:"calc+arraydraw"},yanchor:{valType:"enumerated",values:["auto","top","middle","bottom"],dflt:"auto",editType:"calc+arraydraw"},yshift:{valType:"number",dflt:0,editType:"calc+arraydraw"},clicktoshow:{valType:"enumerated",values:[!1,"onoff","onout"],dflt:!1,editType:"arraydraw"},xclick:{valType:"any",editType:"arraydraw"},yclick:{valType:"any",editType:"arraydraw"},hovertext:{valType:"string",editType:"arraydraw"},hoverlabel:{bgcolor:{valType:"color",editType:"arraydraw"},bordercolor:{valType:"color",editType:"arraydraw"},font:i({editType:"arraydraw"}),editType:"arraydraw"},captureevents:{valType:"boolean",editType:"arraydraw"},editType:"calc",_deprecated:{ref:{valType:"string",editType:"calc"}}})},{"../../constants/axis_placeable_objects":472,"../../plot_api/plot_template":543,"../../plots/cartesian/constants":561,"../../plots/font_attributes":585,"./arrow_paths":348}],350:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axes"),a=t("./draw").draw;function o(t){var e=t._fullLayout;n.filterVisible(e.annotations).forEach((function(e){var r=i.getFromId(t,e.xref),n=i.getFromId(t,e.yref),a=i.getRefType(e.xref),o=i.getRefType(e.yref);e._extremes={},"range"===a&&s(e,r),"range"===o&&s(e,n)}))}function s(t,e){var r,n=e._id,a=n.charAt(0),o=t[a],s=t["a"+a],l=t[a+"ref"],c=t["a"+a+"ref"],u=t["_"+a+"padplus"],f=t["_"+a+"padminus"],h={x:1,y:-1}[a]*t[a+"shift"],p=3*t.arrowsize*t.arrowwidth||0,d=p+h,m=p-h,g=3*t.startarrowsize*t.arrowwidth||0,v=g+h,y=g-h;if(c===l){var x=i.findExtremes(e,[e.r2c(o)],{ppadplus:d,ppadminus:m}),b=i.findExtremes(e,[e.r2c(s)],{ppadplus:Math.max(u,v),ppadminus:Math.max(f,y)});r={min:[x.min[0],b.min[0]],max:[x.max[0],b.max[0]]}}else v=s?v+s:v,y=s?y-s:y,r=i.findExtremes(e,[e.r2c(o)],{ppadplus:Math.max(u,d,v),ppadminus:Math.max(f,m,y)});t._extremes[n]=r}e.exports=function(t){var e=t._fullLayout;if(n.filterVisible(e.annotations).length&&t._fullData.length)return n.syncOrAsync([a,o],t)}},{"../../lib":503,"../../plots/cartesian/axes":554,"./draw":355}],351:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../registry"),a=t("../../plot_api/plot_template").arrayEditor;function o(t,e){var r,n,i,a,o,l,c,u=t._fullLayout.annotations,f=[],h=[],p=[],d=(e||[]).length;for(r=0;r<u.length;r++)if(a=(i=u[r]).clicktoshow){for(n=0;n<d;n++)if(l=(o=e[n]).xaxis,c=o.yaxis,l._id===i.xref&&c._id===i.yref&&l.d2r(o.x)===s(i._xclick,l)&&c.d2r(o.y)===s(i._yclick,c)){(i.visible?"onout"===a?h:p:f).push(r);break}n===d&&i.visible&&"onout"===a&&h.push(r)}return{on:f,off:h,explicitOff:p}}function s(t,e){return"log"===e.type?e.l2r(t):e.d2r(t)}e.exports={hasClickToShow:function(t,e){var r=o(t,e);return r.on.length>0||r.explicitOff.length>0},onClick:function(t,e){var r,s,l=o(t,e),c=l.on,u=l.off.concat(l.explicitOff),f={},h=t._fullLayout.annotations;if(!c.length&&!u.length)return;for(r=0;r<c.length;r++)(s=a(t.layout,"annotations",h[c[r]])).modifyItem("visible",!0),n.extendFlat(f,s.getUpdateObj());for(r=0;r<u.length;r++)(s=a(t.layout,"annotations",h[u[r]])).modifyItem("visible",!1),n.extendFlat(f,s.getUpdateObj());return i.call("update",t,{},f)}}},{"../../lib":503,"../../plot_api/plot_template":543,"../../registry":638}],352:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../color");e.exports=function(t,e,r,a){a("opacity");var o=a("bgcolor"),s=a("bordercolor"),l=i.opacity(s);a("borderpad");var c=a("borderwidth"),u=a("showarrow");if(a("text",u?" ":r._dfltTitle.annotation),a("textangle"),n.coerceFont(a,"font",r.font),a("width"),a("align"),a("height")&&a("valign"),u){var f,h,p=a("arrowside");-1!==p.indexOf("end")&&(f=a("arrowhead"),h=a("arrowsize")),-1!==p.indexOf("start")&&(a("startarrowhead",f),a("startarrowsize",h)),a("arrowcolor",l?e.bordercolor:i.defaultLine),a("arrowwidth",2*(l&&c||1)),a("standoff"),a("startstandoff")}var d=a("hovertext"),m=r.hoverlabel||{};if(d){var g=a("hoverlabel.bgcolor",m.bgcolor||(i.opacity(o)?i.rgb(o):i.defaultLine)),v=a("hoverlabel.bordercolor",m.bordercolor||i.contrast(g));n.coerceFont(a,"hoverlabel.font",{family:m.font.family,size:m.font.size,color:m.font.color||v})}a("captureevents",!!d)}},{"../../lib":503,"../color":366}],353:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib/to_log_range");e.exports=function(t,e,r,a){e=e||{};var o="log"===r&&"linear"===e.type,s="linear"===r&&"log"===e.type;if(o||s)for(var l,c,u=t._fullLayout.annotations,f=e._id.charAt(0),h=0;h<u.length;h++)l=u[h],c="annotations["+h+"].",l[f+"ref"]===e._id&&p(f),l["a"+f+"ref"]===e._id&&p("a"+f);function p(t){var r=l[t],s=null;s=o?i(r,e.range):Math.pow(10,r),n(s)||(s=null),a(c+t,s)}}},{"../../lib/to_log_range":531,"fast-isnumeric":190}],354:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axes"),a=t("../../plots/array_container_defaults"),o=t("./common_defaults"),s=t("./attributes");function l(t,e,r){function a(r,i){return n.coerce(t,e,s,r,i)}var l=a("visible"),c=a("clicktoshow");if(l||c){o(t,e,r,a);for(var u=e.showarrow,f=["x","y"],h=[-10,-30],p={_fullLayout:r},d=0;d<2;d++){var m=f[d],g=i.coerceRef(t,e,p,m,"","paper");if("paper"!==g)i.getFromId(p,g)._annIndices.push(e._index);if(i.coercePosition(e,p,a,g,m,.5),u){var v="a"+m,y=i.coerceRef(t,e,p,v,"pixel",["pixel","paper"]);"pixel"!==y&&y!==g&&(y=e[v]="pixel");var x="pixel"===y?h[d]:.4;i.coercePosition(e,p,a,y,v,x)}a(m+"anchor"),a(m+"shift")}if(n.noneOrAll(t,e,["x","y"]),u&&n.noneOrAll(t,e,["ax","ay"]),c){var b=a("xclick"),_=a("yclick");e._xclick=void 0===b?e.x:i.cleanPosition(b,p,e.xref),e._yclick=void 0===_?e.y:i.cleanPosition(_,p,e.yref)}}}e.exports=function(t,e){a(t,e,{name:"annotations",handleItemDefaults:l})}},{"../../lib":503,"../../plots/array_container_defaults":549,"../../plots/cartesian/axes":554,"./attributes":349,"./common_defaults":352}],355:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../registry"),a=t("../../plots/plots"),o=t("../../lib"),s=o.strTranslate,l=t("../../plots/cartesian/axes"),c=t("../color"),u=t("../drawing"),f=t("../fx"),h=t("../../lib/svg_text_utils"),p=t("../../lib/setcursor"),d=t("../dragelement"),m=t("../../plot_api/plot_template").arrayEditor,g=t("./draw_arrow_head");function v(t,e){var r=t._fullLayout.annotations[e]||{},n=l.getFromId(t,r.xref),i=l.getFromId(t,r.yref);n&&n.setScale(),i&&i.setScale(),x(t,r,e,!1,n,i)}function y(t,e,r,n,i){var a=i[r],o=i[r+"ref"],s=-1!==r.indexOf("y"),c="domain"===l.getRefType(o),u=s?n.h:n.w;return t?c?a+(s?-e:e)/t._length:t.p2r(t.r2p(a)+e):a+(s?-e:e)/u}function x(t,e,r,a,v,x){var b,_,w=t._fullLayout,T=t._fullLayout._size,k=t._context.edits;a?(b="annotation-"+a,_=a+".annotations"):(b="annotation",_="annotations");var A=m(t.layout,_,e),M=A.modifyBase,S=A.modifyItem,E=A.getUpdateObj;w._infolayer.selectAll("."+b+'[data-index="'+r+'"]').remove();var L="clip"+w._uid+"_ann"+r;if(e._input&&!1!==e.visible){var C={x:{},y:{}},P=+e.textangle||0,I=w._infolayer.append("g").classed(b,!0).attr("data-index",String(r)).style("opacity",e.opacity),O=I.append("g").classed("annotation-text-g",!0),z=k[e.showarrow?"annotationTail":"annotationPosition"],D=e.captureevents||k.annotationText||z,R=O.append("g").style("pointer-events",D?"all":null).call(p,"pointer").on("click",(function(){t._dragging=!1,t.emit("plotly_clickannotation",Y(n.event))}));e.hovertext&&R.on("mouseover",(function(){var r=e.hoverlabel,n=r.font,i=this.getBoundingClientRect(),a=t.getBoundingClientRect();f.loneHover({x0:i.left-a.left,x1:i.right-a.left,y:(i.top+i.bottom)/2-a.top,text:e.hovertext,color:r.bgcolor,borderColor:r.bordercolor,fontFamily:n.family,fontSize:n.size,fontColor:n.color},{container:w._hoverlayer.node(),outerContainer:w._paper.node(),gd:t})})).on("mouseout",(function(){f.loneUnhover(w._hoverlayer.node())}));var F=e.borderwidth,B=e.borderpad,N=F+B,j=R.append("rect").attr("class","bg").style("stroke-width",F+"px").call(c.stroke,e.bordercolor).call(c.fill,e.bgcolor),U=e.width||e.height,V=w._topclips.selectAll("#"+L).data(U?[0]:[]);V.enter().append("clipPath").classed("annclip",!0).attr("id",L).append("rect"),V.exit().remove();var H=e.font,q=w._meta?o.templateString(e.text,w._meta):e.text,G=R.append("text").classed("annotation-text",!0).text(q);k.annotationText?G.call(h.makeEditable,{delegate:R,gd:t}).call(W).on("edit",(function(r){e.text=r,this.call(W),S("text",r),v&&v.autorange&&M(v._name+".autorange",!0),x&&x.autorange&&M(x._name+".autorange",!0),i.call("_guiRelayout",t,E())})):G.call(W)}else n.selectAll("#"+L).remove();function Y(t){var n={index:r,annotation:e._input,fullAnnotation:e,event:t};return a&&(n.subplotId=a),n}function W(r){return r.call(u.font,H).attr({"text-anchor":{left:"start",right:"end"}[e.align]||"middle"}),h.convertToTspans(r,t,X),r}function X(){var r=G.selectAll("a");1===r.size()&&r.text()===G.text()&&R.insert("a",":first-child").attr({"xlink:xlink:href":r.attr("xlink:href"),"xlink:xlink:show":r.attr("xlink:show")}).style({cursor:"pointer"}).node().appendChild(j.node());var n=R.select(".annotation-text-math-group"),f=!n.empty(),m=u.bBox((f?n:G).node()),b=m.width,_=m.height,A=e.width||b,D=e.height||_,B=Math.round(A+2*N),H=Math.round(D+2*N);function q(t,e){return"auto"===e&&(e=t<1/3?"left":t>2/3?"right":"center"),{center:0,middle:0,left:.5,bottom:-.5,right:-.5,top:.5}[e]}for(var W=!1,X=["x","y"],Z=0;Z<X.length;Z++){var J,K,Q,$,tt,et=X[Z],rt=e[et+"ref"]||et,nt=e["a"+et+"ref"],it={x:v,y:x}[et],at=(P+("x"===et?0:-90))*Math.PI/180,ot=B*Math.cos(at),st=H*Math.sin(at),lt=Math.abs(ot)+Math.abs(st),ct=e[et+"anchor"],ut=e[et+"shift"]*("x"===et?1:-1),ft=C[et],ht=l.getRefType(rt);if(it&&"domain"!==ht){var pt=it.r2fraction(e[et]);(pt<0||pt>1)&&(nt===rt?((pt=it.r2fraction(e["a"+et]))<0||pt>1)&&(W=!0):W=!0),J=it._offset+it.r2p(e[et]),$=.5}else{var dt="domain"===ht;"x"===et?(Q=e[et],J=dt?it._offset+it._length*Q:J=T.l+T.w*Q):(Q=1-e[et],J=dt?it._offset+it._length*Q:J=T.t+T.h*Q),$=e.showarrow?.5:Q}if(e.showarrow){ft.head=J;var mt=e["a"+et];if(tt=ot*q(.5,e.xanchor)-st*q(.5,e.yanchor),nt===rt){var gt=l.getRefType(nt);"domain"===gt?("y"===et&&(mt=1-mt),ft.tail=it._offset+it._length*mt):"paper"===gt?"y"===et?(mt=1-mt,ft.tail=T.t+T.h*mt):ft.tail=T.l+T.w*mt:ft.tail=it._offset+it.r2p(mt),K=tt}else ft.tail=J+mt,K=tt+mt;ft.text=ft.tail+tt;var vt=w["x"===et?"width":"height"];if("paper"===rt&&(ft.head=o.constrain(ft.head,1,vt-1)),"pixel"===nt){var yt=-Math.max(ft.tail-3,ft.text),xt=Math.min(ft.tail+3,ft.text)-vt;yt>0?(ft.tail+=yt,ft.text+=yt):xt>0&&(ft.tail-=xt,ft.text-=xt)}ft.tail+=ut,ft.head+=ut}else K=tt=lt*q($,ct),ft.text=J+tt;ft.text+=ut,tt+=ut,K+=ut,e["_"+et+"padplus"]=lt/2+K,e["_"+et+"padminus"]=lt/2-K,e["_"+et+"size"]=lt,e["_"+et+"shift"]=tt}if(W)R.remove();else{var bt=0,_t=0;if("left"!==e.align&&(bt=(A-b)*("center"===e.align?.5:1)),"top"!==e.valign&&(_t=(D-_)*("middle"===e.valign?.5:1)),f)n.select("svg").attr({x:N+bt-1,y:N+_t}).call(u.setClipUrl,U?L:null,t);else{var wt=N+_t-m.top,Tt=N+bt-m.left;G.call(h.positionText,Tt,wt).call(u.setClipUrl,U?L:null,t)}V.select("rect").call(u.setRect,N,N,A,D),j.call(u.setRect,F/2,F/2,B-F,H-F),R.call(u.setTranslate,Math.round(C.x.text-B/2),Math.round(C.y.text-H/2)),O.attr({transform:"rotate("+P+","+C.x.text+","+C.y.text+")"});var kt,At=function(r,n){I.selectAll(".annotation-arrow-g").remove();var l=C.x.head,f=C.y.head,h=C.x.tail+r,p=C.y.tail+n,m=C.x.text+r,b=C.y.text+n,_=o.rotationXYMatrix(P,m,b),w=o.apply2DTransform(_),A=o.apply2DTransform2(_),L=+j.attr("width"),z=+j.attr("height"),D=m-.5*L,F=D+L,B=b-.5*z,N=B+z,U=[[D,B,D,N],[D,N,F,N],[F,N,F,B],[F,B,D,B]].map(A);if(!U.reduce((function(t,e){return t^!!o.segmentsIntersect(l,f,l+1e6,f+1e6,e[0],e[1],e[2],e[3])}),!1)){U.forEach((function(t){var e=o.segmentsIntersect(h,p,l,f,t[0],t[1],t[2],t[3]);e&&(h=e.x,p=e.y)}));var V=e.arrowwidth,H=e.arrowcolor,q=e.arrowside,G=I.append("g").style({opacity:c.opacity(H)}).classed("annotation-arrow-g",!0),Y=G.append("path").attr("d","M"+h+","+p+"L"+l+","+f).style("stroke-width",V+"px").call(c.stroke,c.rgb(H));if(g(Y,q,e),k.annotationPosition&&Y.node().parentNode&&!a){var W=l,X=f;if(e.standoff){var Z=Math.sqrt(Math.pow(l-h,2)+Math.pow(f-p,2));W+=e.standoff*(h-l)/Z,X+=e.standoff*(p-f)/Z}var J,K,Q=G.append("path").classed("annotation-arrow",!0).classed("anndrag",!0).classed("cursor-move",!0).attr({d:"M3,3H-3V-3H3ZM0,0L"+(h-W)+","+(p-X),transform:s(W,X)}).style("stroke-width",V+6+"px").call(c.stroke,"rgba(0,0,0,0)").call(c.fill,"rgba(0,0,0,0)");d.init({element:Q.node(),gd:t,prepFn:function(){var t=u.getTranslate(R);J=t.x,K=t.y,v&&v.autorange&&M(v._name+".autorange",!0),x&&x.autorange&&M(x._name+".autorange",!0)},moveFn:function(t,r){var n=w(J,K),i=n[0]+t,a=n[1]+r;R.call(u.setTranslate,i,a),S("x",y(v,t,"x",T,e)),S("y",y(x,r,"y",T,e)),e.axref===e.xref&&S("ax",y(v,t,"ax",T,e)),e.ayref===e.yref&&S("ay",y(x,r,"ay",T,e)),G.attr("transform",s(t,r)),O.attr({transform:"rotate("+P+","+i+","+a+")"})},doneFn:function(){i.call("_guiRelayout",t,E());var e=document.querySelector(".js-notes-box-panel");e&&e.redraw(e.selectedObj)}})}}};if(e.showarrow&&At(0,0),z)d.init({element:R.node(),gd:t,prepFn:function(){kt=O.attr("transform")},moveFn:function(t,r){var n="pointer";if(e.showarrow)e.axref===e.xref?S("ax",y(v,t,"ax",T,e)):S("ax",e.ax+t),e.ayref===e.yref?S("ay",y(x,r,"ay",T.w,e)):S("ay",e.ay+r),At(t,r);else{if(a)return;var i,o;if(v)i=y(v,t,"x",T,e);else{var l=e._xsize/T.w,c=e.x+(e._xshift-e.xshift)/T.w-l/2;i=d.align(c+t/T.w,l,0,1,e.xanchor)}if(x)o=y(x,r,"y",T,e);else{var u=e._ysize/T.h,f=e.y-(e._yshift+e.yshift)/T.h-u/2;o=d.align(f-r/T.h,u,0,1,e.yanchor)}S("x",i),S("y",o),v&&x||(n=d.getCursor(v?.5:i,x?.5:o,e.xanchor,e.yanchor))}O.attr({transform:s(t,r)+kt}),p(R,n)},clickFn:function(r,n){e.captureevents&&t.emit("plotly_clickannotation",Y(n))},doneFn:function(){p(R),i.call("_guiRelayout",t,E());var e=document.querySelector(".js-notes-box-panel");e&&e.redraw(e.selectedObj)}})}}}e.exports={draw:function(t){var e=t._fullLayout;e._infolayer.selectAll(".annotation").remove();for(var r=0;r<e.annotations.length;r++)e.annotations[r].visible&&v(t,r);return a.previousPromises(t)},drawOne:v,drawRaw:x}},{"../../lib":503,"../../lib/setcursor":524,"../../lib/svg_text_utils":529,"../../plot_api/plot_template":543,"../../plots/cartesian/axes":554,"../../plots/plots":619,"../../registry":638,"../color":366,"../dragelement":385,"../drawing":388,"../fx":406,"./draw_arrow_head":356,"@plotly/d3":58}],356:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../color"),a=t("./arrow_paths"),o=t("../../lib"),s=o.strScale,l=o.strRotate,c=o.strTranslate;e.exports=function(t,e,r){var o,u,f,h,p=t.node(),d=a[r.arrowhead||0],m=a[r.startarrowhead||0],g=(r.arrowwidth||1)*(r.arrowsize||1),v=(r.arrowwidth||1)*(r.startarrowsize||1),y=e.indexOf("start")>=0,x=e.indexOf("end")>=0,b=d.backoff*g+r.standoff,_=m.backoff*v+r.startstandoff;if("line"===p.nodeName){o={x:+t.attr("x1"),y:+t.attr("y1")},u={x:+t.attr("x2"),y:+t.attr("y2")};var w=o.x-u.x,T=o.y-u.y;if(h=(f=Math.atan2(T,w))+Math.PI,b&&_&&b+_>Math.sqrt(w*w+T*T))return void z();if(b){if(b*b>w*w+T*T)return void z();var k=b*Math.cos(f),A=b*Math.sin(f);u.x+=k,u.y+=A,t.attr({x2:u.x,y2:u.y})}if(_){if(_*_>w*w+T*T)return void z();var M=_*Math.cos(f),S=_*Math.sin(f);o.x-=M,o.y-=S,t.attr({x1:o.x,y1:o.y})}}else if("path"===p.nodeName){var E=p.getTotalLength(),L="";if(E<b+_)return void z();var C=p.getPointAtLength(0),P=p.getPointAtLength(.1);f=Math.atan2(C.y-P.y,C.x-P.x),o=p.getPointAtLength(Math.min(_,E)),L="0px,"+_+"px,";var I=p.getPointAtLength(E),O=p.getPointAtLength(E-.1);h=Math.atan2(I.y-O.y,I.x-O.x),u=p.getPointAtLength(Math.max(0,E-b)),L+=E-(L?_+b:b)+"px,"+E+"px",t.style("stroke-dasharray",L)}function z(){t.style("stroke-dasharray","0px,100px")}function D(e,a,o,u){e.path&&(e.noRotate&&(o=0),n.select(p.parentNode).append("path").attr({class:t.attr("class"),d:e.path,transform:c(a.x,a.y)+l(180*o/Math.PI)+s(u)}).style({fill:i.rgb(r.arrowcolor),"stroke-width":0}))}y&&D(m,o,f,v),x&&D(d,u,h,g)}},{"../../lib":503,"../color":366,"./arrow_paths":348,"@plotly/d3":58}],357:[function(t,e,r){"use strict";var n=t("./draw"),i=t("./click");e.exports={moduleType:"component",name:"annotations",layoutAttributes:t("./attributes"),supplyLayoutDefaults:t("./defaults"),includeBasePlot:t("../../plots/cartesian/include_components")("annotations"),calcAutorange:t("./calc_autorange"),draw:n.draw,drawOne:n.drawOne,drawRaw:n.drawRaw,hasClickToShow:i.hasClickToShow,onClick:i.onClick,convertCoords:t("./convert_coords")}},{"../../plots/cartesian/include_components":567,"./attributes":349,"./calc_autorange":350,"./click":351,"./convert_coords":353,"./defaults":354,"./draw":355}],358:[function(t,e,r){"use strict";var n=t("../annotations/attributes"),i=t("../../plot_api/edit_types").overrideAll,a=t("../../plot_api/plot_template").templatedArray;e.exports=i(a("annotation",{visible:n.visible,x:{valType:"any"},y:{valType:"any"},z:{valType:"any"},ax:{valType:"number"},ay:{valType:"number"},xanchor:n.xanchor,xshift:n.xshift,yanchor:n.yanchor,yshift:n.yshift,text:n.text,textangle:n.textangle,font:n.font,width:n.width,height:n.height,opacity:n.opacity,align:n.align,valign:n.valign,bgcolor:n.bgcolor,bordercolor:n.bordercolor,borderpad:n.borderpad,borderwidth:n.borderwidth,showarrow:n.showarrow,arrowcolor:n.arrowcolor,arrowhead:n.arrowhead,startarrowhead:n.startarrowhead,arrowside:n.arrowside,arrowsize:n.arrowsize,startarrowsize:n.startarrowsize,arrowwidth:n.arrowwidth,standoff:n.standoff,startstandoff:n.startstandoff,hovertext:n.hovertext,hoverlabel:n.hoverlabel,captureevents:n.captureevents}),"calc","from-root")},{"../../plot_api/edit_types":536,"../../plot_api/plot_template":543,"../annotations/attributes":349}],359:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axes");function a(t,e){var r=e.fullSceneLayout.domain,a=e.fullLayout._size,o={pdata:null,type:"linear",autorange:!1,range:[-1/0,1/0]};t._xa={},n.extendFlat(t._xa,o),i.setConvert(t._xa),t._xa._offset=a.l+r.x[0]*a.w,t._xa.l2p=function(){return.5*(1+t._pdata[0]/t._pdata[3])*a.w*(r.x[1]-r.x[0])},t._ya={},n.extendFlat(t._ya,o),i.setConvert(t._ya),t._ya._offset=a.t+(1-r.y[1])*a.h,t._ya.l2p=function(){return.5*(1-t._pdata[1]/t._pdata[3])*a.h*(r.y[1]-r.y[0])}}e.exports=function(t){for(var e=t.fullSceneLayout.annotations,r=0;r<e.length;r++)a(e[r],t);t.fullLayout._infolayer.selectAll(".annotation-"+t.id).remove()}},{"../../lib":503,"../../plots/cartesian/axes":554}],360:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axes"),a=t("../../plots/array_container_defaults"),o=t("../annotations/common_defaults"),s=t("./attributes");function l(t,e,r,a){function l(r,i){return n.coerce(t,e,s,r,i)}function c(t){var n=t+"axis",a={_fullLayout:{}};return a._fullLayout[n]=r[n],i.coercePosition(e,a,l,t,t,.5)}l("visible")&&(o(t,e,a.fullLayout,l),c("x"),c("y"),c("z"),n.noneOrAll(t,e,["x","y","z"]),e.xref="x",e.yref="y",e.zref="z",l("xanchor"),l("yanchor"),l("xshift"),l("yshift"),e.showarrow&&(e.axref="pixel",e.ayref="pixel",l("ax",-10),l("ay",-30),n.noneOrAll(t,e,["ax","ay"])))}e.exports=function(t,e,r){a(t,e,{name:"annotations",handleItemDefaults:l,fullLayout:r.fullLayout})}},{"../../lib":503,"../../plots/array_container_defaults":549,"../../plots/cartesian/axes":554,"../annotations/common_defaults":352,"./attributes":358}],361:[function(t,e,r){"use strict";var n=t("../annotations/draw").drawRaw,i=t("../../plots/gl3d/project"),a=["x","y","z"];e.exports=function(t){for(var e=t.fullSceneLayout,r=t.dataScale,o=e.annotations,s=0;s<o.length;s++){for(var l=o[s],c=!1,u=0;u<3;u++){var f=a[u],h=l[f],p=e[f+"axis"].r2fraction(h);if(p<0||p>1){c=!0;break}}c?t.fullLayout._infolayer.select(".annotation-"+t.id+'[data-index="'+s+'"]').remove():(l._pdata=i(t.glplot.cameraParams,[e.xaxis.r2l(l.x)*r[0],e.yaxis.r2l(l.y)*r[1],e.zaxis.r2l(l.z)*r[2]]),n(t.graphDiv,l,s,t.id,l._xa,l._ya))}}},{"../../plots/gl3d/project":607,"../annotations/draw":355}],362:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib");e.exports={moduleType:"component",name:"annotations3d",schema:{subplots:{scene:{annotations:t("./attributes")}}},layoutAttributes:t("./attributes"),handleDefaults:t("./defaults"),includeBasePlot:function(t,e){var r=n.subplotsRegistry.gl3d;if(!r)return;for(var a=r.attrRegex,o=Object.keys(t),s=0;s<o.length;s++){var l=o[s];a.test(l)&&(t[l].annotations||[]).length&&(i.pushUnique(e._basePlotModules,r),i.pushUnique(e._subplots.gl3d,l))}},convert:t("./convert"),draw:t("./draw")}},{"../../lib":503,"../../registry":638,"./attributes":358,"./convert":359,"./defaults":360,"./draw":361}],363:[function(t,e,r){"use strict";e.exports=t("world-calendars/dist/main"),t("world-calendars/dist/plus"),t("world-calendars/dist/calendars/chinese"),t("world-calendars/dist/calendars/coptic"),t("world-calendars/dist/calendars/discworld"),t("world-calendars/dist/calendars/ethiopian"),t("world-calendars/dist/calendars/hebrew"),t("world-calendars/dist/calendars/islamic"),t("world-calendars/dist/calendars/julian"),t("world-calendars/dist/calendars/mayan"),t("world-calendars/dist/calendars/nanakshahi"),t("world-calendars/dist/calendars/nepali"),t("world-calendars/dist/calendars/persian"),t("world-calendars/dist/calendars/taiwan"),t("world-calendars/dist/calendars/thai"),t("world-calendars/dist/calendars/ummalqura")},{"world-calendars/dist/calendars/chinese":332,"world-calendars/dist/calendars/coptic":333,"world-calendars/dist/calendars/discworld":334,"world-calendars/dist/calendars/ethiopian":335,"world-calendars/dist/calendars/hebrew":336,"world-calendars/dist/calendars/islamic":337,"world-calendars/dist/calendars/julian":338,"world-calendars/dist/calendars/mayan":339,"world-calendars/dist/calendars/nanakshahi":340,"world-calendars/dist/calendars/nepali":341,"world-calendars/dist/calendars/persian":342,"world-calendars/dist/calendars/taiwan":343,"world-calendars/dist/calendars/thai":344,"world-calendars/dist/calendars/ummalqura":345,"world-calendars/dist/main":346,"world-calendars/dist/plus":347}],364:[function(t,e,r){"use strict";var n=t("./calendars"),i=t("../../lib"),a=t("../../constants/numerical"),o=a.EPOCHJD,s=a.ONEDAY,l={valType:"enumerated",values:i.sortObjectKeys(n.calendars),editType:"calc",dflt:"gregorian"},c=function(t,e,r,n){var a={};return a[r]=l,i.coerce(t,e,a,r,n)},u={d:{0:"dd","-":"d"},e:{0:"d","-":"d"},a:{0:"D","-":"D"},A:{0:"DD","-":"DD"},j:{0:"oo","-":"o"},W:{0:"ww","-":"w"},m:{0:"mm","-":"m"},b:{0:"M","-":"M"},B:{0:"MM","-":"MM"},y:{0:"yy","-":"yy"},Y:{0:"yyyy","-":"yyyy"},U:"##",w:"##",c:{0:"D M d %X yyyy","-":"D M d %X yyyy"},x:{0:"mm/dd/yyyy","-":"mm/dd/yyyy"}};var f={};function h(t){var e=f[t];return e||(e=f[t]=n.instance(t))}function p(t){return i.extendFlat({},l,{description:t})}function d(t){return"Sets the calendar system to use with `"+t+"` date data."}var m={xcalendar:p(d("x"))},g=i.extendFlat({},m,{ycalendar:p(d("y"))}),v=i.extendFlat({},g,{zcalendar:p(d("z"))}),y=p(["Sets the calendar system to use for `range` and `tick0`","if this is a date axis. This does not set the calendar for","interpreting data on this axis, that's specified in the trace","or via the global `layout.calendar`"].join(" "));e.exports={moduleType:"component",name:"calendars",schema:{traces:{scatter:g,bar:g,box:g,heatmap:g,contour:g,histogram:g,histogram2d:g,histogram2dcontour:g,scatter3d:v,surface:v,mesh3d:v,scattergl:g,ohlc:m,candlestick:m},layout:{calendar:p(["Sets the default calendar system to use for interpreting and","displaying dates throughout the plot."].join(" "))},subplots:{xaxis:{calendar:y},yaxis:{calendar:y},scene:{xaxis:{calendar:y},yaxis:{calendar:y},zaxis:{calendar:y}},polar:{radialaxis:{calendar:y}}},transforms:{filter:{valuecalendar:p(["WARNING: All transforms are deprecated and may be removed from the API in next major version.","Sets the calendar system to use for `value`, if it is a date."].join(" ")),targetcalendar:p(["WARNING: All transforms are deprecated and may be removed from the API in next major version.","Sets the calendar system to use for `target`, if it is an","array of dates. If `target` is a string (eg *x*) we use the","corresponding trace attribute (eg `xcalendar`) if it exists,","even if `targetcalendar` is provided."].join(" "))}}},layoutAttributes:l,handleDefaults:c,handleTraceDefaults:function(t,e,r,n){for(var i=0;i<r.length;i++)c(t,e,r[i]+"calendar",n.calendar)},CANONICAL_SUNDAY:{chinese:"2000-01-02",coptic:"2000-01-03",discworld:"2000-01-03",ethiopian:"2000-01-05",hebrew:"5000-01-01",islamic:"1000-01-02",julian:"2000-01-03",mayan:"5000-01-01",nanakshahi:"1000-01-05",nepali:"2000-01-05",persian:"1000-01-01",jalali:"1000-01-01",taiwan:"1000-01-04",thai:"2000-01-04",ummalqura:"1400-01-06"},CANONICAL_TICK:{chinese:"2000-01-01",coptic:"2000-01-01",discworld:"2000-01-01",ethiopian:"2000-01-01",hebrew:"5000-01-01",islamic:"1000-01-01",julian:"2000-01-01",mayan:"5000-01-01",nanakshahi:"1000-01-01",nepali:"2000-01-01",persian:"1000-01-01",jalali:"1000-01-01",taiwan:"1000-01-01",thai:"2000-01-01",ummalqura:"1400-01-01"},DFLTRANGE:{chinese:["2000-01-01","2001-01-01"],coptic:["1700-01-01","1701-01-01"],discworld:["1800-01-01","1801-01-01"],ethiopian:["2000-01-01","2001-01-01"],hebrew:["5700-01-01","5701-01-01"],islamic:["1400-01-01","1401-01-01"],julian:["2000-01-01","2001-01-01"],mayan:["5200-01-01","5201-01-01"],nanakshahi:["0500-01-01","0501-01-01"],nepali:["2000-01-01","2001-01-01"],persian:["1400-01-01","1401-01-01"],jalali:["1400-01-01","1401-01-01"],taiwan:["0100-01-01","0101-01-01"],thai:["2500-01-01","2501-01-01"],ummalqura:["1400-01-01","1401-01-01"]},getCal:h,worldCalFmt:function(t,e,r){for(var n,i,a,l,c,f=Math.floor((e+.05)/s)+o,p=h(r).fromJD(f),d=0;-1!==(d=t.indexOf("%",d));)"0"===(n=t.charAt(d+1))||"-"===n||"_"===n?(a=3,i=t.charAt(d+2),"_"===n&&(n="-")):(i=n,n="0",a=2),(l=u[i])?(c="##"===l?"##":p.formatDate(l[n]),t=t.substr(0,d)+c+t.substr(d+a),d+=c.length):d+=a;return t}}},{"../../constants/numerical":479,"../../lib":503,"./calendars":363}],365:[function(t,e,r){"use strict";r.defaults=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],r.defaultLine="#444",r.lightLine="#eee",r.background="#fff",r.borderLine="#BEC8D9",r.lightFraction=1e3/11},{}],366:[function(t,e,r){"use strict";var n=t("tinycolor2"),i=t("fast-isnumeric"),a=t("../../lib/array").isTypedArray,o=e.exports={},s=t("./attributes");o.defaults=s.defaults;var l=o.defaultLine=s.defaultLine;o.lightLine=s.lightLine;var c=o.background=s.background;function u(t){if(i(t)||"string"!=typeof t)return t;var e=t.trim();if("rgb"!==e.substr(0,3))return t;var r=e.match(/^rgba?\s*\(([^()]*)\)$/);if(!r)return t;var n=r[1].trim().split(/\s*[\s,]\s*/),a="a"===e.charAt(3)&&4===n.length;if(!a&&3!==n.length)return t;for(var o=0;o<n.length;o++){if(!n[o].length)return t;if(n[o]=Number(n[o]),!(n[o]>=0))return t;if(3===o)n[o]>1&&(n[o]=1);else if(n[o]>=1)return t}var s=Math.round(255*n[0])+", "+Math.round(255*n[1])+", "+Math.round(255*n[2]);return a?"rgba("+s+", "+n[3]+")":"rgb("+s+")"}o.tinyRGB=function(t){var e=t.toRgb();return"rgb("+Math.round(e.r)+", "+Math.round(e.g)+", "+Math.round(e.b)+")"},o.rgb=function(t){return o.tinyRGB(n(t))},o.opacity=function(t){return t?n(t).getAlpha():0},o.addOpacity=function(t,e){var r=n(t).toRgb();return"rgba("+Math.round(r.r)+", "+Math.round(r.g)+", "+Math.round(r.b)+", "+e+")"},o.combine=function(t,e){var r=n(t).toRgb();if(1===r.a)return n(t).toRgbString();var i=n(e||c).toRgb(),a=1===i.a?i:{r:255*(1-i.a)+i.r*i.a,g:255*(1-i.a)+i.g*i.a,b:255*(1-i.a)+i.b*i.a},o={r:a.r*(1-r.a)+r.r*r.a,g:a.g*(1-r.a)+r.g*r.a,b:a.b*(1-r.a)+r.b*r.a};return n(o).toRgbString()},o.contrast=function(t,e,r){var i=n(t);return 1!==i.getAlpha()&&(i=n(o.combine(t,c))),(i.isDark()?e?i.lighten(e):c:r?i.darken(r):l).toString()},o.stroke=function(t,e){var r=n(e);t.style({stroke:o.tinyRGB(r),"stroke-opacity":r.getAlpha()})},o.fill=function(t,e){var r=n(e);t.style({fill:o.tinyRGB(r),"fill-opacity":r.getAlpha()})},o.clean=function(t){if(t&&"object"==typeof t){var e,r,n,i,s=Object.keys(t);for(e=0;e<s.length;e++)if(i=t[n=s[e]],"color"===n.substr(n.length-5))if(Array.isArray(i))for(r=0;r<i.length;r++)i[r]=u(i[r]);else t[n]=u(i);else if("colorscale"===n.substr(n.length-10)&&Array.isArray(i))for(r=0;r<i.length;r++)Array.isArray(i[r])&&(i[r][1]=u(i[r][1]));else if(Array.isArray(i)){var l=i[0];if(!Array.isArray(l)&&l&&"object"==typeof l)for(r=0;r<i.length;r++)o.clean(i[r])}else i&&"object"==typeof i&&!a(i)&&o.clean(i)}}},{"../../lib/array":485,"./attributes":365,"fast-isnumeric":190,tinycolor2:312}],367:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/layout_attributes"),i=t("../../plots/font_attributes"),a=t("../../lib/extend").extendFlat,o=t("../../plot_api/edit_types").overrideAll;e.exports=o({orientation:{valType:"enumerated",values:["h","v"],dflt:"v"},thicknessmode:{valType:"enumerated",values:["fraction","pixels"],dflt:"pixels"},thickness:{valType:"number",min:0,dflt:30},lenmode:{valType:"enumerated",values:["fraction","pixels"],dflt:"fraction"},len:{valType:"number",min:0,dflt:1},x:{valType:"number",min:-2,max:3},xanchor:{valType:"enumerated",values:["left","center","right"]},xpad:{valType:"number",min:0,dflt:10},y:{valType:"number",min:-2,max:3},yanchor:{valType:"enumerated",values:["top","middle","bottom"]},ypad:{valType:"number",min:0,dflt:10},outlinecolor:n.linecolor,outlinewidth:n.linewidth,bordercolor:n.linecolor,borderwidth:{valType:"number",min:0,dflt:0},bgcolor:{valType:"color",dflt:"rgba(0,0,0,0)"},tickmode:n.tickmode,nticks:n.nticks,tick0:n.tick0,dtick:n.dtick,tickvals:n.tickvals,ticktext:n.ticktext,ticks:a({},n.ticks,{dflt:""}),ticklabeloverflow:a({},n.ticklabeloverflow,{}),ticklabelposition:{valType:"enumerated",values:["outside","inside","outside top","inside top","outside left","inside left","outside right","inside right","outside bottom","inside bottom"],dflt:"outside"},ticklen:n.ticklen,tickwidth:n.tickwidth,tickcolor:n.tickcolor,ticklabelstep:n.ticklabelstep,showticklabels:n.showticklabels,tickfont:i({}),tickangle:n.tickangle,tickformat:n.tickformat,tickformatstops:n.tickformatstops,tickprefix:n.tickprefix,showtickprefix:n.showtickprefix,ticksuffix:n.ticksuffix,showticksuffix:n.showticksuffix,separatethousands:n.separatethousands,exponentformat:n.exponentformat,minexponent:n.minexponent,showexponent:n.showexponent,title:{text:{valType:"string"},font:i({}),side:{valType:"enumerated",values:["right","top","bottom"]}},_deprecated:{title:{valType:"string"},titlefont:i({}),titleside:{valType:"enumerated",values:["right","top","bottom"],dflt:"top"}}},"colorbars","from-root")},{"../../lib/extend":493,"../../plot_api/edit_types":536,"../../plots/cartesian/layout_attributes":569,"../../plots/font_attributes":585}],368:[function(t,e,r){"use strict";e.exports={cn:{colorbar:"colorbar",cbbg:"cbbg",cbfill:"cbfill",cbfills:"cbfills",cbline:"cbline",cblines:"cblines",cbaxis:"cbaxis",cbtitleunshift:"cbtitleunshift",cbtitle:"cbtitle",cboutline:"cboutline",crisp:"crisp",jsPlaceholder:"js-placeholder"}}},{}],369:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plot_api/plot_template"),a=t("../../plots/cartesian/tick_value_defaults"),o=t("../../plots/cartesian/tick_mark_defaults"),s=t("../../plots/cartesian/tick_label_defaults"),l=t("../../plots/cartesian/prefix_suffix_defaults"),c=t("./attributes");e.exports=function(t,e,r){var u=i.newContainer(e,"colorbar"),f=t.colorbar||{};function h(t,e){return n.coerce(f,u,c,t,e)}var p=r.margin||{t:0,b:0,l:0,r:0},d=r.width-p.l-p.r,m=r.height-p.t-p.b,g="v"===h("orientation"),v=h("thicknessmode");h("thickness","fraction"===v?30/(g?d:m):30);var y=h("lenmode");h("len","fraction"===y?1:g?m:d),h("x",g?1.02:.5),h("xanchor",g?"left":"center"),h("xpad"),h("y",g?.5:1.02),h("yanchor",g?"middle":"bottom"),h("ypad"),n.noneOrAll(f,u,["x","y"]),h("outlinecolor"),h("outlinewidth"),h("bordercolor"),h("borderwidth"),h("bgcolor");var x=n.coerce(f,u,{ticklabelposition:{valType:"enumerated",dflt:"outside",values:g?["outside","inside","outside top","inside top","outside bottom","inside bottom"]:["outside","inside","outside left","inside left","outside right","inside right"]}},"ticklabelposition");h("ticklabeloverflow",-1!==x.indexOf("inside")?"hide past domain":"hide past div"),a(f,u,h,"linear");var b=r.font,_={outerTicks:!1,font:b};-1!==x.indexOf("inside")&&(_.bgColor="black"),l(f,u,h,"linear",_),s(f,u,h,"linear",_),o(f,u,h,"linear",_),h("title.text",r._dfltTitle.colorbar);var w=u.tickfont,T=n.extendFlat({},w,{color:b.color,size:n.bigFont(w.size)});n.coerceFont(h,"title.font",T),h("title.side",g?"top":"right")}},{"../../lib":503,"../../plot_api/plot_template":543,"../../plots/cartesian/prefix_suffix_defaults":573,"../../plots/cartesian/tick_label_defaults":578,"../../plots/cartesian/tick_mark_defaults":579,"../../plots/cartesian/tick_value_defaults":580,"./attributes":367}],370:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("tinycolor2"),a=t("../../plots/plots"),o=t("../../registry"),s=t("../../plots/cartesian/axes"),l=t("../dragelement"),c=t("../../lib"),u=c.strTranslate,f=t("../../lib/extend").extendFlat,h=t("../../lib/setcursor"),p=t("../drawing"),d=t("../color"),m=t("../titles"),g=t("../../lib/svg_text_utils"),v=t("../colorscale/helpers").flipScale,y=t("../../plots/cartesian/axis_defaults"),x=t("../../plots/cartesian/position_defaults"),b=t("../../plots/cartesian/layout_attributes"),_=t("../../constants/alignment"),w=_.LINE_SPACING,T=_.FROM_TL,k=_.FROM_BR,A=t("./constants").cn;e.exports={draw:function(t){var e=t._fullLayout._infolayer.selectAll("g."+A.colorbar).data(function(t){var e,r,n,i,a=t._fullLayout,o=t.calcdata,s=[];function l(t){return f(t,{_fillcolor:null,_line:{color:null,width:null,dash:null},_levels:{start:null,end:null,size:null},_filllevels:null,_fillgradient:null,_zrange:null})}function c(){"function"==typeof i.calc?i.calc(t,n,e):(e._fillgradient=r.reversescale?v(r.colorscale):r.colorscale,e._zrange=[r[i.min],r[i.max]])}for(var u=0;u<o.length;u++){var h=o[u],p=(n=h[0].trace)._module.colorbar;if(!0===n.visible&&p)for(var d=Array.isArray(p),m=d?p:[p],g=0;g<m.length;g++){var y=(i=m[g]).container;(r=y?n[y]:n)&&r.showscale&&((e=l(r.colorbar))._id="cb"+n.uid+(d&&y?"-"+y:""),e._traceIndex=n.index,e._propPrefix=(y?y+".":"")+"colorbar.",e._meta=n._meta,c(),s.push(e))}}for(var x in a._colorAxes)if((r=a[x]).showscale){var b=a._colorAxes[x];(e=l(r.colorbar))._id="cb"+x,e._propPrefix=x+".colorbar.",e._meta=a._meta,i={min:"cmin",max:"cmax"},"heatmap"!==b[0]&&(n=b[1],i.calc=n._module.colorbar.calc),c(),s.push(e)}return s}(t),(function(t){return t._id}));e.enter().append("g").attr("class",(function(t){return t._id})).classed(A.colorbar,!0),e.each((function(e){var r=n.select(this);c.ensureSingle(r,"rect",A.cbbg),c.ensureSingle(r,"g",A.cbfills),c.ensureSingle(r,"g",A.cblines),c.ensureSingle(r,"g",A.cbaxis,(function(t){t.classed(A.crisp,!0)})),c.ensureSingle(r,"g",A.cbtitleunshift,(function(t){t.append("g").classed(A.cbtitle,!0)})),c.ensureSingle(r,"rect",A.cboutline);var v=function(t,e,r){var o="v"===e.orientation,l=e.len,h=e.lenmode,v=e.thickness,_=e.thicknessmode,M=e.outlinewidth,S=e.borderwidth,E=e.bgcolor,L=e.xanchor,C=e.yanchor,P=e.xpad,I=e.ypad,O=e.x,z=o?e.y:1-e.y,D=r._fullLayout,R=D._size,F=e._fillcolor,B=e._line,N=e.title,j=N.side,U=e._zrange||n.extent(("function"==typeof F?F:B.color).domain()),V="function"==typeof B.color?B.color:function(){return B.color},H="function"==typeof F?F:function(){return F},q=e._levels,G=function(t,e,r){var n,i,a=e._levels,o=[],s=[],l=a.end+a.size/100,c=a.size,u=1.001*r[0]-.001*r[1],f=1.001*r[1]-.001*r[0];for(i=0;i<1e5&&(n=a.start+i*c,!(c>0?n>=l:n<=l));i++)n>u&&n<f&&o.push(n);if(e._fillgradient)s=[0];else if("function"==typeof e._fillcolor){var h=e._filllevels;if(h)for(l=h.end+h.size/100,c=h.size,i=0;i<1e5&&(n=h.start+i*c,!(c>0?n>=l:n<=l));i++)n>r[0]&&n<r[1]&&s.push(n);else(s=o.map((function(t){return t-a.size/2}))).push(s[s.length-1]+a.size)}else e._fillcolor&&"string"==typeof e._fillcolor&&(s=[0]);a.size<0&&(o.reverse(),s.reverse());return{line:o,fill:s}}(0,e,U),Y=G.fill,W=G.line,X=Math.round(v*("fraction"===_?o?R.w:R.h:1)),Z=X/(o?R.w:R.h),J=Math.round(l*("fraction"===h?o?R.h:R.w:1)),K=J/(o?R.h:R.w),Q=Math.round(o?O*R.w+P:z*R.h+I),$={center:.5,right:1}[L]||0,tt={top:1,middle:.5}[C]||0,et=o?O-$*Z:z-tt*Z,rt=o?z-tt*K:O-$*K,nt=Math.round(o?R.h*(1-rt):R.w*rt);e._lenFrac=K,e._thickFrac=Z,e._uFrac=et,e._vFrac=rt;var it=e._axis=function(t,e,r){var n=t._fullLayout,i="v"===e.orientation,a={type:"linear",range:r,tickmode:e.tickmode,nticks:e.nticks,tick0:e.tick0,dtick:e.dtick,tickvals:e.tickvals,ticktext:e.ticktext,ticks:e.ticks,ticklen:e.ticklen,tickwidth:e.tickwidth,tickcolor:e.tickcolor,showticklabels:e.showticklabels,ticklabelposition:e.ticklabelposition,ticklabeloverflow:e.ticklabeloverflow,ticklabelstep:e.ticklabelstep,tickfont:e.tickfont,tickangle:e.tickangle,tickformat:e.tickformat,exponentformat:e.exponentformat,minexponent:e.minexponent,separatethousands:e.separatethousands,showexponent:e.showexponent,showtickprefix:e.showtickprefix,tickprefix:e.tickprefix,showticksuffix:e.showticksuffix,ticksuffix:e.ticksuffix,title:e.title,showline:!0,anchor:"free",side:i?"right":"bottom",position:1},o=i?"y":"x",s={type:"linear",_id:o+e._id},l={letter:o,font:n.font,noHover:!0,noTickson:!0,noTicklabelmode:!0,calendar:n.calendar};function u(t,e){return c.coerce(a,s,b,t,e)}return y(a,s,u,l,n),x(a,s,u,l),s}(r,e,U);it.position=Z+(o?O+P/R.w:z+I/R.h);var at=-1!==["top","bottom"].indexOf(j);o&&at&&(it.title.side=j,it.titlex=O+P/R.w,it.titley=rt+("top"===N.side?K-I/R.h:I/R.h));o||at||(it.title.side=j,it.titley=z+I/R.h,it.titlex=rt+P/R.w);if(B.color&&"auto"===e.tickmode){it.tickmode="linear",it.tick0=q.start;var ot=q.size,st=c.constrain(J/50,4,15)+1,lt=(U[1]-U[0])/((e.nticks||st)*ot);if(lt>1){var ct=Math.pow(10,Math.floor(Math.log(lt)/Math.LN10));ot*=ct*c.roundUp(lt/ct,[2,5,10]),(Math.abs(q.start)/q.size+1e-6)%1<2e-6&&(it.tick0=0)}it.dtick=ot}it.domain=o?[rt+I/R.h,rt+K-I/R.h]:[rt+P/R.w,rt+K-P/R.w],it.setScale(),t.attr("transform",u(Math.round(R.l),Math.round(R.t)));var ut,ft=t.select("."+A.cbtitleunshift).attr("transform",u(-Math.round(R.l),-Math.round(R.t))),ht=it.ticklabelposition,pt=it.title.font.size,dt=t.select("."+A.cbaxis),mt=0,gt=0;function vt(n,i){var a={propContainer:it,propName:e._propPrefix+"title",traceIndex:e._traceIndex,_meta:e._meta,placeholder:D._dfltTitle.colorbar,containerGroup:t.select("."+A.cbtitle)},o="h"===n.charAt(0)?n.substr(1):"h"+n;t.selectAll("."+o+",."+o+"-math-group").remove(),m.draw(r,n,f(a,i||{}))}return c.syncOrAsync([a.previousPromises,function(){var t,e;(o&&at||!o&&!at)&&("top"===j&&(t=P+R.l+R.w*O,e=I+R.t+R.h*(1-rt-K)+3+.75*pt),"bottom"===j&&(t=P+R.l+R.w*O,e=I+R.t+R.h*(1-rt)-3-.25*pt),"right"===j&&(e=I+R.t+R.h*z+3+.75*pt,t=P+R.l+R.w*rt),vt(it._id+"title",{attributes:{x:t,y:e,"text-anchor":o?"start":"middle"}}))},function(){if(!o&&!at||o&&at){var a,l=t.select("."+A.cbtitle),f=l.select("text"),h=[-M/2,M/2],d=l.select(".h"+it._id+"title-math-group").node(),m=15.6;if(f.node()&&(m=parseInt(f.node().style.fontSize,10)*w),d?(a=p.bBox(d),gt=a.width,(mt=a.height)>m&&(h[1]-=(mt-m)/2)):f.node()&&!f.classed(A.jsPlaceholder)&&(a=p.bBox(f.node()),gt=a.width,mt=a.height),o){if(mt){if(mt+=5,"top"===j)it.domain[1]-=mt/R.h,h[1]*=-1;else{it.domain[0]+=mt/R.h;var v=g.lineCount(f);h[1]+=(1-v)*m}l.attr("transform",u(h[0],h[1])),it.setScale()}}else gt&&("right"===j&&(it.domain[0]+=(gt+pt/2)/R.w),l.attr("transform",u(h[0],h[1])),it.setScale())}t.selectAll("."+A.cbfills+",."+A.cblines).attr("transform",o?u(0,Math.round(R.h*(1-it.domain[1]))):u(Math.round(R.w*it.domain[0]),0)),dt.attr("transform",o?u(0,Math.round(-R.t)):u(Math.round(-R.l),0));var y=t.select("."+A.cbfills).selectAll("rect."+A.cbfill).attr("style","").data(Y);y.enter().append("rect").classed(A.cbfill,!0).style("stroke","none"),y.exit().remove();var x=U.map(it.c2p).map(Math.round).sort((function(t,e){return t-e}));y.each((function(t,a){var s=[0===a?U[0]:(Y[a]+Y[a-1])/2,a===Y.length-1?U[1]:(Y[a]+Y[a+1])/2].map(it.c2p).map(Math.round);o&&(s[1]=c.constrain(s[1]+(s[1]>s[0])?1:-1,x[0],x[1]));var l=n.select(this).attr(o?"x":"y",Q).attr(o?"y":"x",n.min(s)).attr(o?"width":"height",Math.max(X,2)).attr(o?"height":"width",Math.max(n.max(s)-n.min(s),2));if(e._fillgradient)p.gradient(l,r,e._id,o?"vertical":"horizontalreversed",e._fillgradient,"fill");else{var u=H(t).replace("e-","");l.attr("fill",i(u).toHexString())}}));var b=t.select("."+A.cblines).selectAll("path."+A.cbline).data(B.color&&B.width?W:[]);b.enter().append("path").classed(A.cbline,!0),b.exit().remove(),b.each((function(t){var e=Q,r=Math.round(it.c2p(t))+B.width/2%1;n.select(this).attr("d","M"+(o?e+","+r:r+","+e)+(o?"h":"v")+X).call(p.lineGroupStyle,B.width,V(t),B.dash)})),dt.selectAll("g."+it._id+"tick,path").remove();var _=Q+X+(M||0)/2-("outside"===e.ticks?1:0),T=s.calcTicks(it),k=s.getTickSigns(it)[2];return s.drawTicks(r,it,{vals:"inside"===it.ticks?s.clipEnds(it,T):T,layer:dt,path:s.makeTickPath(it,_,k),transFn:s.makeTransTickFn(it)}),s.drawLabels(r,it,{vals:T,layer:dt,transFn:s.makeTransTickLabelFn(it),labelFns:s.makeLabelFns(it,_)})},function(){if(o&&!at||!o&&at){var t,i,a=it.position||0,s=it._offset+it._length/2;if("right"===j)i=s,t=R.l+R.w*a+10+pt*(it.showticklabels?1:.5);else if(t=s,"bottom"===j&&(i=R.t+R.h*a+10+(-1===ht.indexOf("inside")?it.tickfont.size:0)+("intside"!==it.ticks&&e.ticklen||0)),"top"===j){var l=N.text.split("<br>").length;i=R.t+R.h*a+10-X-w*pt*l}vt((o?"h":"v")+it._id+"title",{avoid:{selection:n.select(r).selectAll("g."+it._id+"tick"),side:j,offsetTop:o?0:R.t,offsetLeft:o?R.l:0,maxShift:o?D.width:D.height},attributes:{x:t,y:i,"text-anchor":"middle"},transform:{rotate:o?-90:0,offset:0}})}},a.previousPromises,function(){var n,s=X+M/2;-1===ht.indexOf("inside")&&(n=p.bBox(dt.node()),s+=o?n.width:n.height),ut=ft.select("text");var c=0,f=o&&"top"===j,m=!o&&"right"===j,g=0;if(ut.node()&&!ut.classed(A.jsPlaceholder)){var y,x=ft.select(".h"+it._id+"title-math-group").node();x&&(o&&at||!o&&!at)?(c=(n=p.bBox(x)).width,y=n.height):(c=(n=p.bBox(ft.node())).right-R.l-(o?Q:nt),y=n.bottom-R.t-(o?nt:Q),o||"top"!==j||(s+=n.height,g=n.height)),m&&(ut.attr("transform",u(c/2+pt/2,0)),c*=2),s=Math.max(s,o?c:y)}var b=2*(o?P:I)+s+S+M/2,w=0;!o&&N.text&&"bottom"===C&&z<=0&&(b+=w=b/2,g+=w),D._hColorbarMoveTitle=w,D._hColorbarMoveCBTitle=g;var F=S+M;t.select("."+A.cbbg).attr("x",(o?Q:nt)-F/2-(o?P:0)).attr("y",(o?nt:Q)-(o?J:I+g-w)).attr(o?"width":"height",Math.max(b-w,2)).attr(o?"height":"width",Math.max(J+F,2)).call(d.fill,E).call(d.stroke,e.bordercolor).style("stroke-width",S);var B=m?Math.max(c-10,0):0;if(t.selectAll("."+A.cboutline).attr("x",(o?Q:nt+P)+B).attr("y",(o?nt+I-J:Q)+(f?mt:0)).attr(o?"width":"height",Math.max(X,2)).attr(o?"height":"width",Math.max(J-(o?2*I+mt:2*P+B),2)).call(d.stroke,e.outlinecolor).style({fill:"none","stroke-width":M}),t.attr("transform",u(R.l-(o?$*b:0),R.t-(o?0:(1-tt)*b-g))),!o&&(S||i(E).getAlpha()&&!i.equals(D.paper_bgcolor,E))){var U=dt.selectAll("text"),V=U[0].length,H=t.select("."+A.cbbg).node(),q=p.bBox(H),G=p.getTranslate(t);U.each((function(t,e){var r=V-1;if(0===e||e===r){var n,i=p.bBox(this),a=p.getTranslate(this);if(e===r){var o=i.right+a.x;(n=q.right+G.x+nt-S-2+O-o)>0&&(n=0)}else if(0===e){var s=i.left+a.x;(n=q.left+G.x+nt+S+2-s)<0&&(n=0)}n&&(V<3?this.setAttribute("transform","translate("+n+",0) "+this.getAttribute("transform")):this.setAttribute("visibility","hidden"))}}))}var Y={},W=T[L],Z=k[L],K=T[C],et=k[C],rt=b-X;o?("pixels"===h?(Y.y=z,Y.t=J*K,Y.b=J*et):(Y.t=Y.b=0,Y.yt=z+l*K,Y.yb=z-l*et),"pixels"===_?(Y.x=O,Y.l=b*W,Y.r=b*Z):(Y.l=rt*W,Y.r=rt*Z,Y.xl=O-v*W,Y.xr=O+v*Z)):("pixels"===h?(Y.x=O,Y.l=J*W,Y.r=J*Z):(Y.l=Y.r=0,Y.xl=O+l*W,Y.xr=O-l*Z),"pixels"===_?(Y.y=1-z,Y.t=b*K,Y.b=b*et):(Y.t=rt*K,Y.b=rt*et,Y.yt=z-v*K,Y.yb=z+v*et)),a.autoMargin(r,e._id,Y)}],r)}(r,e,t);v&&v.then&&(t._promises||[]).push(v),t._context.edits.colorbarPosition&&function(t,e,r){var n,i,a,s="v"===e.orientation,c=r._fullLayout._size;l.init({element:t.node(),gd:r,prepFn:function(){n=t.attr("transform"),h(t)},moveFn:function(r,o){t.attr("transform",n+u(r,o)),i=l.align((s?e._uFrac:e._vFrac)+r/c.w,s?e._thickFrac:e._lenFrac,0,1,e.xanchor),a=l.align((s?e._vFrac:1-e._uFrac)-o/c.h,s?e._lenFrac:e._thickFrac,0,1,e.yanchor);var f=l.getCursor(i,a,e.xanchor,e.yanchor);h(t,f)},doneFn:function(){if(h(t),void 0!==i&&void 0!==a){var n={};n[e._propPrefix+"x"]=i,n[e._propPrefix+"y"]=a,void 0!==e._traceIndex?o.call("_guiRestyle",r,n,e._traceIndex):o.call("_guiRelayout",r,n)}}})}(r,e,t)})),e.exit().each((function(e){a.autoMargin(t,e._id)})).remove(),e.order()}}},{"../../constants/alignment":471,"../../lib":503,"../../lib/extend":493,"../../lib/setcursor":524,"../../lib/svg_text_utils":529,"../../plots/cartesian/axes":554,"../../plots/cartesian/axis_defaults":556,"../../plots/cartesian/layout_attributes":569,"../../plots/cartesian/position_defaults":572,"../../plots/plots":619,"../../registry":638,"../color":366,"../colorscale/helpers":377,"../dragelement":385,"../drawing":388,"../titles":464,"./constants":368,"@plotly/d3":58,tinycolor2:312}],371:[function(t,e,r){"use strict";var n=t("../../lib");e.exports=function(t){return n.isPlainObject(t.colorbar)}},{"../../lib":503}],372:[function(t,e,r){"use strict";e.exports={moduleType:"component",name:"colorbar",attributes:t("./attributes"),supplyDefaults:t("./defaults"),draw:t("./draw").draw,hasColorbar:t("./has_colorbar")}},{"./attributes":367,"./defaults":369,"./draw":370,"./has_colorbar":371}],373:[function(t,e,r){"use strict";var n=t("../colorbar/attributes"),i=t("../../lib/regex").counter,a=t("../../lib/sort_object_keys"),o=t("./scales.js").scales;a(o);function s(t){return"`"+t+"`"}e.exports=function(t,e){t=t||"";var r,a=(e=e||{}).cLetter||"c",l=("onlyIfNumerical"in e?e.onlyIfNumerical:Boolean(t),"noScale"in e?e.noScale:"marker.line"===t),c="showScaleDflt"in e?e.showScaleDflt:"z"===a,u="string"==typeof e.colorscaleDflt?o[e.colorscaleDflt]:null,f=e.editTypeOverride||"",h=t?t+".":"";"colorAttr"in e?(r=e.colorAttr,e.colorAttr):s(h+(r={z:"z",c:"color"}[a]));var p=a+"auto",d=a+"min",m=a+"max",g=a+"mid",v=(s(h+p),s(h+d),s(h+m),{});v[d]=v[m]=void 0;var y={};y[p]=!1;var x={};return"color"===r&&(x.color={valType:"color",arrayOk:!0,editType:f||"style"},e.anim&&(x.color.anim=!0)),x[p]={valType:"boolean",dflt:!0,editType:"calc",impliedEdits:v},x[d]={valType:"number",dflt:null,editType:f||"plot",impliedEdits:y},x[m]={valType:"number",dflt:null,editType:f||"plot",impliedEdits:y},x[g]={valType:"number",dflt:null,editType:"calc",impliedEdits:v},x.colorscale={valType:"colorscale",editType:"calc",dflt:u,impliedEdits:{autocolorscale:!1}},x.autocolorscale={valType:"boolean",dflt:!1!==e.autoColorDflt,editType:"calc",impliedEdits:{colorscale:void 0}},x.reversescale={valType:"boolean",dflt:!1,editType:"plot"},l||(x.showscale={valType:"boolean",dflt:c,editType:"calc"},x.colorbar=n),e.noColorAxis||(x.coloraxis={valType:"subplotid",regex:i("coloraxis"),dflt:null,editType:"calc"}),x}},{"../../lib/regex":520,"../../lib/sort_object_keys":526,"../colorbar/attributes":367,"./scales.js":381}],374:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=t("./helpers").extractOpts;e.exports=function(t,e,r){var o,s=t._fullLayout,l=r.vals,c=r.containerStr,u=c?i.nestedProperty(e,c).get():e,f=a(u),h=!1!==f.auto,p=f.min,d=f.max,m=f.mid,g=function(){return i.aggNums(Math.min,null,l)},v=function(){return i.aggNums(Math.max,null,l)};(void 0===p?p=g():h&&(p=u._colorAx&&n(p)?Math.min(p,g()):g()),void 0===d?d=v():h&&(d=u._colorAx&&n(d)?Math.max(d,v()):v()),h&&void 0!==m&&(d-m>m-p?p=m-(d-m):d-m<m-p&&(d=m+(m-p))),p===d&&(p-=.5,d+=.5),f._sync("min",p),f._sync("max",d),f.autocolorscale)&&(o=p*d<0?s.colorscale.diverging:p>=0?s.colorscale.sequential:s.colorscale.sequentialminus,f._sync("colorscale",o))}},{"../../lib":503,"./helpers":377,"fast-isnumeric":190}],375:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./helpers").hasColorscale,a=t("./helpers").extractOpts;e.exports=function(t,e){function r(t,e){var r=t["_"+e];void 0!==r&&(t[e]=r)}function o(t,i){var o=i.container?n.nestedProperty(t,i.container).get():t;if(o)if(o.coloraxis)o._colorAx=e[o.coloraxis];else{var s=a(o),l=s.auto;(l||void 0===s.min)&&r(o,i.min),(l||void 0===s.max)&&r(o,i.max),s.autocolorscale&&r(o,"colorscale")}}for(var s=0;s<t.length;s++){var l=t[s],c=l._module.colorbar;if(c)if(Array.isArray(c))for(var u=0;u<c.length;u++)o(l,c[u]);else o(l,c);i(l,"marker.line")&&o(l,{container:"marker.line",min:"cmin",max:"cmax"})}for(var f in e._colorAxes)o(e[f],{min:"cmin",max:"cmax"})}},{"../../lib":503,"./helpers":377}],376:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=t("../colorbar/has_colorbar"),o=t("../colorbar/defaults"),s=t("./scales").isValid,l=t("../../registry").traceIs;function c(t,e){var r=e.slice(0,e.length-1);return e?i.nestedProperty(t,r).get()||{}:t}e.exports=function t(e,r,u,f,h){var p=h.prefix,d=h.cLetter,m="_module"in r,g=c(e,p),v=c(r,p),y=c(r._template||{},p)||{},x=function(){return delete e.coloraxis,delete r.coloraxis,t(e,r,u,f,h)};if(m){var b=u._colorAxes||{},_=f(p+"coloraxis");if(_){var w=l(r,"contour")&&i.nestedProperty(r,"contours.coloring").get()||"heatmap",T=b[_];return void(T?(T[2].push(x),T[0]!==w&&(T[0]=!1,i.warn(["Ignoring coloraxis:",_,"setting","as it is linked to incompatible colorscales."].join(" ")))):b[_]=[w,r,[x]])}}var k=g[d+"min"],A=g[d+"max"],M=n(k)&&n(A)&&k<A;f(p+d+"auto",!M)?f(p+d+"mid"):(f(p+d+"min"),f(p+d+"max"));var S,E,L=g.colorscale,C=y.colorscale;(void 0!==L&&(S=!s(L)),void 0!==C&&(S=!s(C)),f(p+"autocolorscale",S),f(p+"colorscale"),f(p+"reversescale"),"marker.line."!==p)&&(p&&m&&(E=a(g)),f(p+"showscale",E)&&(p&&y&&(v._template=y),o(g,v,u)))}},{"../../lib":503,"../../registry":638,"../colorbar/defaults":369,"../colorbar/has_colorbar":371,"./scales":381,"fast-isnumeric":190}],377:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("tinycolor2"),a=t("fast-isnumeric"),o=t("../../lib"),s=t("../color"),l=t("./scales").isValid;var c=["showscale","autocolorscale","colorscale","reversescale","colorbar"],u=["min","max","mid","auto"];function f(t){var e,r,n,i=t._colorAx,a=i||t,o={};for(r=0;r<c.length;r++)o[n=c[r]]=a[n];if(i)for(e="c",r=0;r<u.length;r++)o[n=u[r]]=a["c"+n];else{var s;for(r=0;r<u.length;r++)((s="c"+(n=u[r]))in a||(s="z"+n)in a)&&(o[n]=a[s]);e=s.charAt(0)}return o._sync=function(t,r){var n=-1!==u.indexOf(t)?e+t:t;a[n]=a["_"+n]=r},o}function h(t){for(var e=f(t),r=e.min,n=e.max,i=e.reversescale?p(e.colorscale):e.colorscale,a=i.length,o=new Array(a),s=new Array(a),l=0;l<a;l++){var c=i[l];o[l]=r+c[0]*(n-r),s[l]=c[1]}return{domain:o,range:s}}function p(t){for(var e=t.length,r=new Array(e),n=e-1,i=0;n>=0;n--,i++){var a=t[n];r[i]=[1-a[0],a[1]]}return r}function d(t,e){e=e||{};for(var r=t.domain,o=t.range,l=o.length,c=new Array(l),u=0;u<l;u++){var f=i(o[u]).toRgb();c[u]=[f.r,f.g,f.b,f.a]}var h,p=n.scale.linear().domain(r).range(c).clamp(!0),d=e.noNumericCheck,g=e.returnArray;return(h=d&&g?p:d?function(t){return m(p(t))}:g?function(t){return a(t)?p(t):i(t).isValid()?t:s.defaultLine}:function(t){return a(t)?m(p(t)):i(t).isValid()?t:s.defaultLine}).domain=p.domain,h.range=function(){return o},h}function m(t){var e={r:t[0],g:t[1],b:t[2],a:t[3]};return i(e).toRgbString()}e.exports={hasColorscale:function(t,e,r){var n=e?o.nestedProperty(t,e).get()||{}:t,i=n[r||"color"],s=!1;if(o.isArrayOrTypedArray(i))for(var c=0;c<i.length;c++)if(a(i[c])){s=!0;break}return o.isPlainObject(n)&&(s||!0===n.showscale||a(n.cmin)&&a(n.cmax)||l(n.colorscale)||o.isPlainObject(n.colorbar))},extractOpts:f,extractScale:h,flipScale:p,makeColorScaleFunc:d,makeColorScaleFuncFromTrace:function(t,e){return d(h(t),e)}}},{"../../lib":503,"../color":366,"./scales":381,"@plotly/d3":58,"fast-isnumeric":190,tinycolor2:312}],378:[function(t,e,r){"use strict";var n=t("./scales"),i=t("./helpers");e.exports={moduleType:"component",name:"colorscale",attributes:t("./attributes"),layoutAttributes:t("./layout_attributes"),supplyLayoutDefaults:t("./layout_defaults"),handleDefaults:t("./defaults"),crossTraceDefaults:t("./cross_trace_defaults"),calc:t("./calc"),scales:n.scales,defaultScale:n.defaultScale,getScale:n.get,isValidScale:n.isValid,hasColorscale:i.hasColorscale,extractOpts:i.extractOpts,extractScale:i.extractScale,flipScale:i.flipScale,makeColorScaleFunc:i.makeColorScaleFunc,makeColorScaleFuncFromTrace:i.makeColorScaleFuncFromTrace}},{"./attributes":373,"./calc":374,"./cross_trace_defaults":375,"./defaults":376,"./helpers":377,"./layout_attributes":379,"./layout_defaults":380,"./scales":381}],379:[function(t,e,r){"use strict";var n=t("../../lib/extend").extendFlat,i=t("./attributes"),a=t("./scales").scales;e.exports={editType:"calc",colorscale:{editType:"calc",sequential:{valType:"colorscale",dflt:a.Reds,editType:"calc"},sequentialminus:{valType:"colorscale",dflt:a.Blues,editType:"calc"},diverging:{valType:"colorscale",dflt:a.RdBu,editType:"calc"}},coloraxis:n({_isSubplotObj:!0,editType:"calc"},i("",{colorAttr:"corresponding trace color array(s)",noColorAxis:!0,showScaleDflt:!0}))}},{"../../lib/extend":493,"./attributes":373,"./scales":381}],380:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plot_api/plot_template"),a=t("./layout_attributes"),o=t("./defaults");e.exports=function(t,e){function r(r,i){return n.coerce(t,e,a,r,i)}r("colorscale.sequential"),r("colorscale.sequentialminus"),r("colorscale.diverging");var s,l,c=e._colorAxes;function u(t,e){return n.coerce(s,l,a.coloraxis,t,e)}for(var f in c){var h=c[f];if(h[0])s=t[f]||{},(l=i.newContainer(e,f,"coloraxis"))._name=f,o(s,l,e,u,{prefix:"",cLetter:"c"});else{for(var p=0;p<h[2].length;p++)h[2][p]();delete e._colorAxes[f]}}}},{"../../lib":503,"../../plot_api/plot_template":543,"./defaults":376,"./layout_attributes":379}],381:[function(t,e,r){"use strict";var n=t("tinycolor2"),i={Greys:[[0,"rgb(0,0,0)"],[1,"rgb(255,255,255)"]],YlGnBu:[[0,"rgb(8,29,88)"],[.125,"rgb(37,52,148)"],[.25,"rgb(34,94,168)"],[.375,"rgb(29,145,192)"],[.5,"rgb(65,182,196)"],[.625,"rgb(127,205,187)"],[.75,"rgb(199,233,180)"],[.875,"rgb(237,248,217)"],[1,"rgb(255,255,217)"]],Greens:[[0,"rgb(0,68,27)"],[.125,"rgb(0,109,44)"],[.25,"rgb(35,139,69)"],[.375,"rgb(65,171,93)"],[.5,"rgb(116,196,118)"],[.625,"rgb(161,217,155)"],[.75,"rgb(199,233,192)"],[.875,"rgb(229,245,224)"],[1,"rgb(247,252,245)"]],YlOrRd:[[0,"rgb(128,0,38)"],[.125,"rgb(189,0,38)"],[.25,"rgb(227,26,28)"],[.375,"rgb(252,78,42)"],[.5,"rgb(253,141,60)"],[.625,"rgb(254,178,76)"],[.75,"rgb(254,217,118)"],[.875,"rgb(255,237,160)"],[1,"rgb(255,255,204)"]],Bluered:[[0,"rgb(0,0,255)"],[1,"rgb(255,0,0)"]],RdBu:[[0,"rgb(5,10,172)"],[.35,"rgb(106,137,247)"],[.5,"rgb(190,190,190)"],[.6,"rgb(220,170,132)"],[.7,"rgb(230,145,90)"],[1,"rgb(178,10,28)"]],Reds:[[0,"rgb(220,220,220)"],[.2,"rgb(245,195,157)"],[.4,"rgb(245,160,105)"],[1,"rgb(178,10,28)"]],Blues:[[0,"rgb(5,10,172)"],[.35,"rgb(40,60,190)"],[.5,"rgb(70,100,245)"],[.6,"rgb(90,120,245)"],[.7,"rgb(106,137,247)"],[1,"rgb(220,220,220)"]],Picnic:[[0,"rgb(0,0,255)"],[.1,"rgb(51,153,255)"],[.2,"rgb(102,204,255)"],[.3,"rgb(153,204,255)"],[.4,"rgb(204,204,255)"],[.5,"rgb(255,255,255)"],[.6,"rgb(255,204,255)"],[.7,"rgb(255,153,255)"],[.8,"rgb(255,102,204)"],[.9,"rgb(255,102,102)"],[1,"rgb(255,0,0)"]],Rainbow:[[0,"rgb(150,0,90)"],[.125,"rgb(0,0,200)"],[.25,"rgb(0,25,255)"],[.375,"rgb(0,152,255)"],[.5,"rgb(44,255,150)"],[.625,"rgb(151,255,0)"],[.75,"rgb(255,234,0)"],[.875,"rgb(255,111,0)"],[1,"rgb(255,0,0)"]],Portland:[[0,"rgb(12,51,131)"],[.25,"rgb(10,136,186)"],[.5,"rgb(242,211,56)"],[.75,"rgb(242,143,56)"],[1,"rgb(217,30,30)"]],Jet:[[0,"rgb(0,0,131)"],[.125,"rgb(0,60,170)"],[.375,"rgb(5,255,255)"],[.625,"rgb(255,255,0)"],[.875,"rgb(250,0,0)"],[1,"rgb(128,0,0)"]],Hot:[[0,"rgb(0,0,0)"],[.3,"rgb(230,0,0)"],[.6,"rgb(255,210,0)"],[1,"rgb(255,255,255)"]],Blackbody:[[0,"rgb(0,0,0)"],[.2,"rgb(230,0,0)"],[.4,"rgb(230,210,0)"],[.7,"rgb(255,255,255)"],[1,"rgb(160,200,255)"]],Earth:[[0,"rgb(0,0,130)"],[.1,"rgb(0,180,180)"],[.2,"rgb(40,210,40)"],[.4,"rgb(230,230,50)"],[.6,"rgb(120,70,20)"],[1,"rgb(255,255,255)"]],Electric:[[0,"rgb(0,0,0)"],[.15,"rgb(30,0,100)"],[.4,"rgb(120,0,100)"],[.6,"rgb(160,90,0)"],[.8,"rgb(230,200,0)"],[1,"rgb(255,250,220)"]],Viridis:[[0,"#440154"],[.06274509803921569,"#48186a"],[.12549019607843137,"#472d7b"],[.18823529411764706,"#424086"],[.25098039215686274,"#3b528b"],[.3137254901960784,"#33638d"],[.3764705882352941,"#2c728e"],[.4392156862745098,"#26828e"],[.5019607843137255,"#21918c"],[.5647058823529412,"#1fa088"],[.6274509803921569,"#28ae80"],[.6901960784313725,"#3fbc73"],[.7529411764705882,"#5ec962"],[.8156862745098039,"#84d44b"],[.8784313725490196,"#addc30"],[.9411764705882353,"#d8e219"],[1,"#fde725"]],Cividis:[[0,"rgb(0,32,76)"],[.058824,"rgb(0,42,102)"],[.117647,"rgb(0,52,110)"],[.176471,"rgb(39,63,108)"],[.235294,"rgb(60,74,107)"],[.294118,"rgb(76,85,107)"],[.352941,"rgb(91,95,109)"],[.411765,"rgb(104,106,112)"],[.470588,"rgb(117,117,117)"],[.529412,"rgb(131,129,120)"],[.588235,"rgb(146,140,120)"],[.647059,"rgb(161,152,118)"],[.705882,"rgb(176,165,114)"],[.764706,"rgb(192,177,109)"],[.823529,"rgb(209,191,102)"],[.882353,"rgb(225,204,92)"],[.941176,"rgb(243,219,79)"],[1,"rgb(255,233,69)"]]},a=i.RdBu;function o(t){var e=0;if(!Array.isArray(t)||t.length<2)return!1;if(!t[0]||!t[t.length-1])return!1;if(0!=+t[0][0]||1!=+t[t.length-1][0])return!1;for(var r=0;r<t.length;r++){var i=t[r];if(2!==i.length||+i[0]<e||!n(i[1]).isValid())return!1;e=+i[0]}return!0}e.exports={scales:i,defaultScale:a,get:function(t,e){if(e||(e=a),!t)return e;function r(){try{t=i[t]||JSON.parse(t)}catch(r){t=e}}return"string"==typeof t&&(r(),"string"==typeof t&&r()),o(t)?t:e},isValid:function(t){return void 0!==i[t]||o(t)}}},{tinycolor2:312}],382:[function(t,e,r){"use strict";e.exports=function(t,e,r,n,i){var a=(t-r)/(n-r),o=a+e/(n-r),s=(a+o)/2;return"left"===i||"bottom"===i?a:"center"===i||"middle"===i?s:"right"===i||"top"===i?o:a<2/3-s?a:o>4/3-s?o:s}},{}],383:[function(t,e,r){"use strict";var n=t("../../lib"),i=[["sw-resize","s-resize","se-resize"],["w-resize","move","e-resize"],["nw-resize","n-resize","ne-resize"]];e.exports=function(t,e,r,a){return t="left"===r?0:"center"===r?1:"right"===r?2:n.constrain(Math.floor(3*t),0,2),e="bottom"===a?0:"middle"===a?1:"top"===a?2:n.constrain(Math.floor(3*e),0,2),i[e][t]}},{"../../lib":503}],384:[function(t,e,r){"use strict";r.selectMode=function(t){return"lasso"===t||"select"===t},r.drawMode=function(t){return"drawclosedpath"===t||"drawopenpath"===t||"drawline"===t||"drawrect"===t||"drawcircle"===t},r.openMode=function(t){return"drawline"===t||"drawopenpath"===t},r.rectMode=function(t){return"select"===t||"drawline"===t||"drawrect"===t||"drawcircle"===t},r.freeMode=function(t){return"lasso"===t||"drawclosedpath"===t||"drawopenpath"===t},r.selectingOrDrawing=function(t){return r.freeMode(t)||r.rectMode(t)}},{}],385:[function(t,e,r){"use strict";var n=t("mouse-event-offset"),i=t("has-hover"),a=t("has-passive-events"),o=t("../../lib").removeElement,s=t("../../plots/cartesian/constants"),l=e.exports={};l.align=t("./align"),l.getCursor=t("./cursor");var c=t("./unhover");function u(){var t=document.createElement("div");t.className="dragcover";var e=t.style;return e.position="fixed",e.left=0,e.right=0,e.top=0,e.bottom=0,e.zIndex=999999999,e.background="none",document.body.appendChild(t),t}function f(t){return n(t.changedTouches?t.changedTouches[0]:t,document.body)}l.unhover=c.wrapped,l.unhoverRaw=c.raw,l.init=function(t){var e,r,n,c,h,p,d,m,g=t.gd,v=1,y=g._context.doubleClickDelay,x=t.element;g._mouseDownTime||(g._mouseDownTime=0),x.style.pointerEvents="all",x.onmousedown=_,a?(x._ontouchstart&&x.removeEventListener("touchstart",x._ontouchstart),x._ontouchstart=_,x.addEventListener("touchstart",_,{passive:!1})):x.ontouchstart=_;var b=t.clampFn||function(t,e,r){return Math.abs(t)<r&&(t=0),Math.abs(e)<r&&(e=0),[t,e]};function _(a){g._dragged=!1,g._dragging=!0;var o=f(a);e=o[0],r=o[1],d=a.target,p=a,m=2===a.buttons||a.ctrlKey,void 0===a.clientX&&void 0===a.clientY&&(a.clientX=e,a.clientY=r),(n=(new Date).getTime())-g._mouseDownTime<y?v+=1:(v=1,g._mouseDownTime=n),t.prepFn&&t.prepFn(a,e,r),i&&!m?(h=u()).style.cursor=window.getComputedStyle(x).cursor:i||(h=document,c=window.getComputedStyle(document.documentElement).cursor,document.documentElement.style.cursor=window.getComputedStyle(x).cursor),document.addEventListener("mouseup",T),document.addEventListener("touchend",T),!1!==t.dragmode&&(a.preventDefault(),document.addEventListener("mousemove",w),document.addEventListener("touchmove",w,{passive:!1}))}function w(n){n.preventDefault();var i=f(n),a=t.minDrag||s.MINDRAG,o=b(i[0]-e,i[1]-r,a),c=o[0],u=o[1];(c||u)&&(g._dragged=!0,l.unhover(g,n)),g._dragged&&t.moveFn&&!m&&(g._dragdata={element:x,dx:c,dy:u},t.moveFn(c,u))}function T(e){if(delete g._dragdata,!1!==t.dragmode&&(e.preventDefault(),document.removeEventListener("mousemove",w),document.removeEventListener("touchmove",w)),document.removeEventListener("mouseup",T),document.removeEventListener("touchend",T),i?o(h):c&&(h.documentElement.style.cursor=c,c=null),g._dragging){if(g._dragging=!1,(new Date).getTime()-g._mouseDownTime>y&&(v=Math.max(v-1,1)),g._dragged)t.doneFn&&t.doneFn();else if(t.clickFn&&t.clickFn(v,p),!m){var r;try{r=new MouseEvent("click",e)}catch(t){var n=f(e);(r=document.createEvent("MouseEvents")).initMouseEvent("click",e.bubbles,e.cancelable,e.view,e.detail,e.screenX,e.screenY,n[0],n[1],e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,e.button,e.relatedTarget)}d.dispatchEvent(r)}g._dragging=!1,g._dragged=!1}else g._dragged=!1}},l.coverSlip=u},{"../../lib":503,"../../plots/cartesian/constants":561,"./align":382,"./cursor":383,"./unhover":386,"has-hover":228,"has-passive-events":229,"mouse-event-offset":242}],386:[function(t,e,r){"use strict";var n=t("../../lib/events"),i=t("../../lib/throttle"),a=t("../../lib/dom").getGraphDiv,o=t("../fx/constants"),s=e.exports={};s.wrapped=function(t,e,r){(t=a(t))._fullLayout&&i.clear(t._fullLayout._uid+o.HOVERID),s.raw(t,e,r)},s.raw=function(t,e){var r=t._fullLayout,i=t._hoverdata;e||(e={}),e.target&&!t._dragged&&!1===n.triggerHandler(t,"plotly_beforehover",e)||(r._hoverlayer.selectAll("g").remove(),r._hoverlayer.selectAll("line").remove(),r._hoverlayer.selectAll("circle").remove(),t._hoverdata=void 0,e.target&&i&&t.emit("plotly_unhover",{event:e,points:i}))}},{"../../lib/dom":491,"../../lib/events":492,"../../lib/throttle":530,"../fx/constants":400}],387:[function(t,e,r){"use strict";r.dash={valType:"string",values:["solid","dot","dash","longdash","dashdot","longdashdot"],dflt:"solid",editType:"style"},r.pattern={shape:{valType:"enumerated",values:["","/","\\","x","-","|","+","."],dflt:"",arrayOk:!0,editType:"style"},fillmode:{valType:"enumerated",values:["replace","overlay"],dflt:"replace",editType:"style"},bgcolor:{valType:"color",arrayOk:!0,editType:"style"},fgcolor:{valType:"color",arrayOk:!0,editType:"style"},fgopacity:{valType:"number",editType:"style",min:0,max:1},size:{valType:"number",min:0,dflt:8,arrayOk:!0,editType:"style"},solidity:{valType:"number",min:0,max:1,dflt:.3,arrayOk:!0,editType:"style"},editType:"style"}},{}],388:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=i.numberFormat,o=t("fast-isnumeric"),s=t("tinycolor2"),l=t("../../registry"),c=t("../color"),u=t("../colorscale"),f=i.strTranslate,h=t("../../lib/svg_text_utils"),p=t("../../constants/xmlns_namespaces"),d=t("../../constants/alignment").LINE_SPACING,m=t("../../constants/interactions").DESELECTDIM,g=t("../../traces/scatter/subtypes"),v=t("../../traces/scatter/make_bubble_size_func"),y=t("../../components/fx/helpers").appendArrayPointValue,x=e.exports={};function b(t,e,r){var n=e.fillpattern,i=n&&x.getPatternAttr(n.shape,0,"");if(i){var a=x.getPatternAttr(n.bgcolor,0,null),o=x.getPatternAttr(n.fgcolor,0,null),s=n.fgopacity,l=x.getPatternAttr(n.size,0,8),u=x.getPatternAttr(n.solidity,0,.3),f=e.uid;x.pattern(t,"point",r,f,i,l,u,void 0,n.fillmode,a,o,s)}else e.fillcolor&&t.call(c.fill,e.fillcolor)}x.font=function(t,e,r,n){i.isPlainObject(e)&&(n=e.color,r=e.size,e=e.family),e&&t.style("font-family",e),r+1&&t.style("font-size",r+"px"),n&&t.call(c.fill,n)},x.setPosition=function(t,e,r){t.attr("x",e).attr("y",r)},x.setSize=function(t,e,r){t.attr("width",e).attr("height",r)},x.setRect=function(t,e,r,n,i){t.call(x.setPosition,e,r).call(x.setSize,n,i)},x.translatePoint=function(t,e,r,n){var i=r.c2p(t.x),a=n.c2p(t.y);return!!(o(i)&&o(a)&&e.node())&&("text"===e.node().nodeName?e.attr("x",i).attr("y",a):e.attr("transform",f(i,a)),!0)},x.translatePoints=function(t,e,r){t.each((function(t){var i=n.select(this);x.translatePoint(t,i,e,r)}))},x.hideOutsideRangePoint=function(t,e,r,n,i,a){e.attr("display",r.isPtWithinRange(t,i)&&n.isPtWithinRange(t,a)?null:"none")},x.hideOutsideRangePoints=function(t,e){if(e._hasClipOnAxisFalse){var r=e.xaxis,i=e.yaxis;t.each((function(e){var a=e[0].trace,o=a.xcalendar,s=a.ycalendar,c=l.traceIs(a,"bar-like")?".bartext":".point,.textpoint";t.selectAll(c).each((function(t){x.hideOutsideRangePoint(t,n.select(this),r,i,o,s)}))}))}},x.crispRound=function(t,e,r){return e&&o(e)?t._context.staticPlot?e:e<1?1:Math.round(e):r||0},x.singleLineStyle=function(t,e,r,n,i){e.style("fill","none");var a=(((t||[])[0]||{}).trace||{}).line||{},o=r||a.width||0,s=i||a.dash||"";c.stroke(e,n||a.color),x.dashLine(e,s,o)},x.lineGroupStyle=function(t,e,r,i){t.style("fill","none").each((function(t){var a=(((t||[])[0]||{}).trace||{}).line||{},o=e||a.width||0,s=i||a.dash||"";n.select(this).call(c.stroke,r||a.color).call(x.dashLine,s,o)}))},x.dashLine=function(t,e,r){r=+r||0,e=x.dashStyle(e,r),t.style({"stroke-dasharray":e,"stroke-width":r+"px"})},x.dashStyle=function(t,e){e=+e||1;var r=Math.max(e,3);return"solid"===t?t="":"dot"===t?t=r+"px,"+r+"px":"dash"===t?t=3*r+"px,"+3*r+"px":"longdash"===t?t=5*r+"px,"+5*r+"px":"dashdot"===t?t=3*r+"px,"+r+"px,"+r+"px,"+r+"px":"longdashdot"===t&&(t=5*r+"px,"+2*r+"px,"+r+"px,"+2*r+"px"),t},x.singleFillStyle=function(t,e){var r=n.select(t.node());b(t,((r.data()[0]||[])[0]||{}).trace||{},e)},x.fillGroupStyle=function(t,e){t.style("stroke-width",0).each((function(t){var r=n.select(this);t[0].trace&&b(r,t[0].trace,e)}))};var _=t("./symbol_defs");x.symbolNames=[],x.symbolFuncs=[],x.symbolNeedLines={},x.symbolNoDot={},x.symbolNoFill={},x.symbolList=[],Object.keys(_).forEach((function(t){var e=_[t],r=e.n;x.symbolList.push(r,String(r),t,r+100,String(r+100),t+"-open"),x.symbolNames[r]=t,x.symbolFuncs[r]=e.f,e.needLine&&(x.symbolNeedLines[r]=!0),e.noDot?x.symbolNoDot[r]=!0:x.symbolList.push(r+200,String(r+200),t+"-dot",r+300,String(r+300),t+"-open-dot"),e.noFill&&(x.symbolNoFill[r]=!0)}));var w=x.symbolNames.length;function T(t,e){var r=t%100;return x.symbolFuncs[r](e)+(t>=200?"M0,0.5L0.5,0L0,-0.5L-0.5,0Z":"")}x.symbolNumber=function(t){if(o(t))t=+t;else if("string"==typeof t){var e=0;t.indexOf("-open")>0&&(e=100,t=t.replace("-open","")),t.indexOf("-dot")>0&&(e+=200,t=t.replace("-dot","")),(t=x.symbolNames.indexOf(t))>=0&&(t+=e)}return t%100>=w||t>=400?0:Math.floor(Math.max(t,0))};var k={x1:1,x2:0,y1:0,y2:0},A={x1:0,x2:0,y1:1,y2:0},M=a("~f"),S={radial:{node:"radialGradient"},radialreversed:{node:"radialGradient",reversed:!0},horizontal:{node:"linearGradient",attrs:k},horizontalreversed:{node:"linearGradient",attrs:k,reversed:!0},vertical:{node:"linearGradient",attrs:A},verticalreversed:{node:"linearGradient",attrs:A,reversed:!0}};x.gradient=function(t,e,r,a,o,l){for(var u=o.length,f=S[a],h=new Array(u),p=0;p<u;p++)f.reversed?h[u-1-p]=[M(100*(1-o[p][0])),o[p][1]]:h[p]=[M(100*o[p][0]),o[p][1]];var d=e._fullLayout,m="g"+d._uid+"-"+r,g=d._defs.select(".gradients").selectAll("#"+m).data([a+h.join(";")],i.identity);g.exit().remove(),g.enter().append(f.node).each((function(){var t=n.select(this);f.attrs&&t.attr(f.attrs),t.attr("id",m);var e=t.selectAll("stop").data(h);e.exit().remove(),e.enter().append("stop"),e.each((function(t){var e=s(t[1]);n.select(this).attr({offset:t[0]+"%","stop-color":c.tinyRGB(e),"stop-opacity":e.getAlpha()})}))})),t.style(l,R(m,e)).style(l+"-opacity",null),t.classed("gradient_filled",!0)},x.pattern=function(t,e,r,a,o,s,l,u,f,h,p,d){var m="legend"===e;u&&("overlay"===f?(h=u,p=c.contrast(h)):(h=void 0,p=u));var g,v,y,x,b,_,w,T,k,A,M,S=r._fullLayout,E="p"+S._uid+"-"+a,L={};switch(o){case"/":g=s*Math.sqrt(2),v=s*Math.sqrt(2),_="path",L={d:y="M-"+g/4+","+v/4+"l"+g/2+",-"+v/2+"M0,"+v+"L"+g+",0M"+g/4*3+","+v/4*5+"l"+g/2+",-"+v/2,opacity:d,stroke:p,"stroke-width":(x=l*s)+"px"};break;case"\\":g=s*Math.sqrt(2),v=s*Math.sqrt(2),_="path",L={d:y="M"+g/4*3+",-"+v/4+"l"+g/2+","+v/2+"M0,0L"+g+","+v+"M-"+g/4+","+v/4*3+"l"+g/2+","+v/2,opacity:d,stroke:p,"stroke-width":(x=l*s)+"px"};break;case"x":g=s*Math.sqrt(2),v=s*Math.sqrt(2),y="M-"+g/4+","+v/4+"l"+g/2+",-"+v/2+"M0,"+v+"L"+g+",0M"+g/4*3+","+v/4*5+"l"+g/2+",-"+v/2+"M"+g/4*3+",-"+v/4+"l"+g/2+","+v/2+"M0,0L"+g+","+v+"M-"+g/4+","+v/4*3+"l"+g/2+","+v/2,x=s-s*Math.sqrt(1-l),_="path",L={d:y,opacity:d,stroke:p,"stroke-width":x+"px"};break;case"|":_="path",_="path",L={d:y="M"+(g=s)/2+",0L"+g/2+","+(v=s),opacity:d,stroke:p,"stroke-width":(x=l*s)+"px"};break;case"-":_="path",_="path",L={d:y="M0,"+(v=s)/2+"L"+(g=s)+","+v/2,opacity:d,stroke:p,"stroke-width":(x=l*s)+"px"};break;case"+":_="path",y="M"+(g=s)/2+",0L"+g/2+","+(v=s)+"M0,"+v/2+"L"+g+","+v/2,x=s-s*Math.sqrt(1-l),_="path",L={d:y,opacity:d,stroke:p,"stroke-width":x+"px"};break;case".":g=s,v=s,l<Math.PI/4?b=Math.sqrt(l*s*s/Math.PI):(w=l,T=Math.PI/4,k=1,A=s/2,M=s/Math.sqrt(2),b=A+(M-A)*(w-T)/(k-T)),_="circle",L={cx:g/2,cy:v/2,r:b,opacity:d,fill:p}}var C=[o||"noSh",h||"noBg",p||"noFg",s,l].join(";"),P=S._defs.select(".patterns").selectAll("#"+E).data([C],i.identity);P.exit().remove(),P.enter().append("pattern").each((function(){var t=n.select(this);if(t.attr({id:E,width:g+"px",height:v+"px",patternUnits:"userSpaceOnUse",patternTransform:m?"scale(0.8)":""}),h){var e=t.selectAll("rect").data([0]);e.exit().remove(),e.enter().append("rect").attr({width:g+"px",height:v+"px",fill:h})}var r=t.selectAll(_).data([0]);r.exit().remove(),r.enter().append(_).attr(L)})),t.style("fill",R(E,r)).style("fill-opacity",null),t.classed("pattern_filled",!0)},x.initGradients=function(t){var e=t._fullLayout;i.ensureSingle(e._defs,"g","gradients").selectAll("linearGradient,radialGradient").remove(),n.select(t).selectAll(".gradient_filled").classed("gradient_filled",!1)},x.initPatterns=function(t){var e=t._fullLayout;i.ensureSingle(e._defs,"g","patterns").selectAll("pattern").remove(),n.select(t).selectAll(".pattern_filled").classed("pattern_filled",!1)},x.getPatternAttr=function(t,e,r){return t&&i.isArrayOrTypedArray(t)?e<t.length?t[e]:r:t},x.pointStyle=function(t,e,r){if(t.size()){var i=x.makePointStyleFns(e);t.each((function(t){x.singlePointStyle(t,n.select(this),e,i,r)}))}},x.singlePointStyle=function(t,e,r,n,a){var o=r.marker,s=o.line;if(e.style("opacity",n.selectedOpacityFn?n.selectedOpacityFn(t):void 0===t.mo?o.opacity:t.mo),n.ms2mrc){var l;l="various"===t.ms||"various"===o.size?3:n.ms2mrc(t.ms),t.mrc=l,n.selectedSizeFn&&(l=t.mrc=n.selectedSizeFn(t));var u=x.symbolNumber(t.mx||o.symbol)||0;t.om=u%200>=100,e.attr("d",T(u,l))}var f,h,p,d=!1;if(t.so)p=s.outlierwidth,h=s.outliercolor,f=o.outliercolor;else{var m=(s||{}).width;p=(t.mlw+1||m+1||(t.trace?(t.trace.marker.line||{}).width:0)+1)-1||0,h="mlc"in t?t.mlcc=n.lineScale(t.mlc):i.isArrayOrTypedArray(s.color)?c.defaultLine:s.color,i.isArrayOrTypedArray(o.color)&&(f=c.defaultLine,d=!0),f="mc"in t?t.mcc=n.markerScale(t.mc):o.color||"rgba(0,0,0,0)",n.selectedColorFn&&(f=n.selectedColorFn(t))}if(t.om)e.call(c.stroke,f).style({"stroke-width":(p||1)+"px",fill:"none"});else{e.style("stroke-width",(t.isBlank?0:p)+"px");var g=o.gradient,v=t.mgt;v?d=!0:v=g&&g.type,i.isArrayOrTypedArray(v)&&(v=v[0],S[v]||(v=0));var y=o.pattern,b=y&&x.getPatternAttr(y.shape,t.i,"");if(v&&"none"!==v){var _=t.mgc;_?d=!0:_=g.color;var w=r.uid;d&&(w+="-"+t.i),x.gradient(e,a,w,v,[[0,_],[1,f]],"fill")}else if(b){var k=x.getPatternAttr(y.bgcolor,t.i,null),A=x.getPatternAttr(y.fgcolor,t.i,null),M=y.fgopacity,E=x.getPatternAttr(y.size,t.i,8),L=x.getPatternAttr(y.solidity,t.i,.3),C=t.mcc||i.isArrayOrTypedArray(y.shape)||i.isArrayOrTypedArray(y.bgcolor)||i.isArrayOrTypedArray(y.size)||i.isArrayOrTypedArray(y.solidity),P=r.uid;C&&(P+="-"+t.i),x.pattern(e,"point",a,P,b,E,L,t.mcc,y.fillmode,k,A,M)}else c.fill(e,f);p&&c.stroke(e,h)}},x.makePointStyleFns=function(t){var e={},r=t.marker;return e.markerScale=x.tryColorscale(r,""),e.lineScale=x.tryColorscale(r,"line"),l.traceIs(t,"symbols")&&(e.ms2mrc=g.isBubble(t)?v(t):function(){return(r.size||6)/2}),t.selectedpoints&&i.extendFlat(e,x.makeSelectedPointStyleFns(t)),e},x.makeSelectedPointStyleFns=function(t){var e={},r=t.selected||{},n=t.unselected||{},a=t.marker||{},o=r.marker||{},s=n.marker||{},c=a.opacity,u=o.opacity,f=s.opacity,h=void 0!==u,p=void 0!==f;(i.isArrayOrTypedArray(c)||h||p)&&(e.selectedOpacityFn=function(t){var e=void 0===t.mo?a.opacity:t.mo;return t.selected?h?u:e:p?f:m*e});var d=a.color,g=o.color,v=s.color;(g||v)&&(e.selectedColorFn=function(t){var e=t.mcc||d;return t.selected?g||e:v||e});var y=a.size,x=o.size,b=s.size,_=void 0!==x,w=void 0!==b;return l.traceIs(t,"symbols")&&(_||w)&&(e.selectedSizeFn=function(t){var e=t.mrc||y/2;return t.selected?_?x/2:e:w?b/2:e}),e},x.makeSelectedTextStyleFns=function(t){var e={},r=t.selected||{},n=t.unselected||{},i=t.textfont||{},a=r.textfont||{},o=n.textfont||{},s=i.color,l=a.color,u=o.color;return e.selectedTextColorFn=function(t){var e=t.tc||s;return t.selected?l||e:u||(l?e:c.addOpacity(e,m))},e},x.selectedPointStyle=function(t,e){if(t.size()&&e.selectedpoints){var r=x.makeSelectedPointStyleFns(e),i=e.marker||{},a=[];r.selectedOpacityFn&&a.push((function(t,e){t.style("opacity",r.selectedOpacityFn(e))})),r.selectedColorFn&&a.push((function(t,e){c.fill(t,r.selectedColorFn(e))})),r.selectedSizeFn&&a.push((function(t,e){var n=e.mx||i.symbol||0,a=r.selectedSizeFn(e);t.attr("d",T(x.symbolNumber(n),a)),e.mrc2=a})),a.length&&t.each((function(t){for(var e=n.select(this),r=0;r<a.length;r++)a[r](e,t)}))}},x.tryColorscale=function(t,e){var r=e?i.nestedProperty(t,e).get():t;if(r){var n=r.color;if((r.colorscale||r._colorAx)&&i.isArrayOrTypedArray(n))return u.makeColorScaleFuncFromTrace(r)}return i.identity};var E={start:1,end:-1,middle:0,bottom:1,top:-1};function L(t,e,r,i,a){var o=n.select(t.node().parentNode),s=-1!==e.indexOf("top")?"top":-1!==e.indexOf("bottom")?"bottom":"middle",l=-1!==e.indexOf("left")?"end":-1!==e.indexOf("right")?"start":"middle",c=i?i/.8+1:0,u=(h.lineCount(t)-1)*d+1,p=E[l]*c,m=.75*r+E[s]*c+(E[s]-1)*u*r/2;t.attr("text-anchor",l),a||o.attr("transform",f(p,m))}function C(t,e){var r=t.ts||e.textfont.size;return o(r)&&r>0?r:0}x.textPointStyle=function(t,e,r){if(t.size()){var a;if(e.selectedpoints){var o=x.makeSelectedTextStyleFns(e);a=o.selectedTextColorFn}var s=e.texttemplate,l=r._fullLayout;t.each((function(t){var o=n.select(this),c=s?i.extractOption(t,e,"txt","texttemplate"):i.extractOption(t,e,"tx","text");if(c||0===c){if(s){var u=e._module.formatLabels,f=u?u(t,e,l):{},p={};y(p,e,t.i);var d=e._meta||{};c=i.texttemplateString(c,f,l._d3locale,p,t,d)}var m=t.tp||e.textposition,g=C(t,e),v=a?a(t):t.tc||e.textfont.color;o.call(x.font,t.tf||e.textfont.family,g,v).text(c).call(h.convertToTspans,r).call(L,m,g,t.mrc)}else o.remove()}))}},x.selectedTextStyle=function(t,e){if(t.size()&&e.selectedpoints){var r=x.makeSelectedTextStyleFns(e);t.each((function(t){var i=n.select(this),a=r.selectedTextColorFn(t),o=t.tp||e.textposition,s=C(t,e);c.fill(i,a);var u=l.traceIs(e,"bar-like");L(i,o,s,t.mrc2||t.mrc,u)}))}};function P(t,e,r,i){var a=t[0]-e[0],o=t[1]-e[1],s=r[0]-e[0],l=r[1]-e[1],c=Math.pow(a*a+o*o,.25),u=Math.pow(s*s+l*l,.25),f=(u*u*a-c*c*s)*i,h=(u*u*o-c*c*l)*i,p=3*u*(c+u),d=3*c*(c+u);return[[n.round(e[0]+(p&&f/p),2),n.round(e[1]+(p&&h/p),2)],[n.round(e[0]-(d&&f/d),2),n.round(e[1]-(d&&h/d),2)]]}x.smoothopen=function(t,e){if(t.length<3)return"M"+t.join("L");var r,n="M"+t[0],i=[];for(r=1;r<t.length-1;r++)i.push(P(t[r-1],t[r],t[r+1],e));for(n+="Q"+i[0][0]+" "+t[1],r=2;r<t.length-1;r++)n+="C"+i[r-2][1]+" "+i[r-1][0]+" "+t[r];return n+="Q"+i[t.length-3][1]+" "+t[t.length-1]},x.smoothclosed=function(t,e){if(t.length<3)return"M"+t.join("L")+"Z";var r,n="M"+t[0],i=t.length-1,a=[P(t[i],t[0],t[1],e)];for(r=1;r<i;r++)a.push(P(t[r-1],t[r],t[r+1],e));for(a.push(P(t[i-1],t[i],t[0],e)),r=1;r<=i;r++)n+="C"+a[r-1][1]+" "+a[r][0]+" "+t[r];return n+="C"+a[i][1]+" "+a[0][0]+" "+t[0]+"Z"};var I={hv:function(t,e){return"H"+n.round(e[0],2)+"V"+n.round(e[1],2)},vh:function(t,e){return"V"+n.round(e[1],2)+"H"+n.round(e[0],2)},hvh:function(t,e){return"H"+n.round((t[0]+e[0])/2,2)+"V"+n.round(e[1],2)+"H"+n.round(e[0],2)},vhv:function(t,e){return"V"+n.round((t[1]+e[1])/2,2)+"H"+n.round(e[0],2)+"V"+n.round(e[1],2)}},O=function(t,e){return"L"+n.round(e[0],2)+","+n.round(e[1],2)};x.steps=function(t){var e=I[t]||O;return function(t){for(var r="M"+n.round(t[0][0],2)+","+n.round(t[0][1],2),i=1;i<t.length;i++)r+=e(t[i-1],t[i]);return r}},x.makeTester=function(){var t=i.ensureSingleById(n.select("body"),"svg","js-plotly-tester",(function(t){t.attr(p.svgAttrs).style({position:"absolute",left:"-10000px",top:"-10000px",width:"9000px",height:"9000px","z-index":"1"})})),e=i.ensureSingle(t,"path","js-reference-point",(function(t){t.attr("d","M0,0H1V1H0Z").style({"stroke-width":0,fill:"black"})}));x.tester=t,x.testref=e},x.savedBBoxes={};var z=0;function D(t){var e=t.getAttribute("data-unformatted");if(null!==e)return e+t.getAttribute("data-math")+t.getAttribute("text-anchor")+t.getAttribute("style")}function R(t,e){if(!t)return null;var r=e._context,n=r._exportedPlot?"":r._baseUrl||"";return n?"url('"+n+"#"+t+"')":"url(#"+t+")"}x.bBox=function(t,e,r){var a,o,s;if(r||(r=D(t)),r){if(a=x.savedBBoxes[r])return i.extendFlat({},a)}else if(1===t.childNodes.length){var l=t.childNodes[0];if(r=D(l)){var c=+l.getAttribute("x")||0,u=+l.getAttribute("y")||0,f=l.getAttribute("transform");if(!f){var p=x.bBox(l,!1,r);return c&&(p.left+=c,p.right+=c),u&&(p.top+=u,p.bottom+=u),p}if(r+="~"+c+"~"+u+"~"+f,a=x.savedBBoxes[r])return i.extendFlat({},a)}}e?o=t:(s=x.tester.node(),o=t.cloneNode(!0),s.appendChild(o)),n.select(o).attr("transform",null).call(h.positionText,0,0);var d=o.getBoundingClientRect(),m=x.testref.node().getBoundingClientRect();e||s.removeChild(o);var g={height:d.height,width:d.width,left:d.left-m.left,top:d.top-m.top,right:d.right-m.left,bottom:d.bottom-m.top};return z>=1e4&&(x.savedBBoxes={},z=0),r&&(x.savedBBoxes[r]=g),z++,i.extendFlat({},g)},x.setClipUrl=function(t,e,r){t.attr("clip-path",R(e,r))},x.getTranslate=function(t){var e=(t[t.attr?"attr":"getAttribute"]("transform")||"").replace(/.*\btranslate\((-?\d*\.?\d*)[^-\d]*(-?\d*\.?\d*)[^\d].*/,(function(t,e,r){return[e,r].join(" ")})).split(" ");return{x:+e[0]||0,y:+e[1]||0}},x.setTranslate=function(t,e,r){var n=t.attr?"attr":"getAttribute",i=t.attr?"attr":"setAttribute",a=t[n]("transform")||"";return e=e||0,r=r||0,a=a.replace(/(\btranslate\(.*?\);?)/,"").trim(),a=(a+=f(e,r)).trim(),t[i]("transform",a),a},x.getScale=function(t){var e=(t[t.attr?"attr":"getAttribute"]("transform")||"").replace(/.*\bscale\((\d*\.?\d*)[^\d]*(\d*\.?\d*)[^\d].*/,(function(t,e,r){return[e,r].join(" ")})).split(" ");return{x:+e[0]||1,y:+e[1]||1}},x.setScale=function(t,e,r){var n=t.attr?"attr":"getAttribute",i=t.attr?"attr":"setAttribute",a=t[n]("transform")||"";return e=e||1,r=r||1,a=a.replace(/(\bscale\(.*?\);?)/,"").trim(),a=(a+="scale("+e+","+r+")").trim(),t[i]("transform",a),a};var F=/\s*sc.*/;x.setPointGroupScale=function(t,e,r){if(e=e||1,r=r||1,t){var n=1===e&&1===r?"":"scale("+e+","+r+")";t.each((function(){var t=(this.getAttribute("transform")||"").replace(F,"");t=(t+=n).trim(),this.setAttribute("transform",t)}))}};var B=/translate\([^)]*\)\s*$/;x.setTextPointsScale=function(t,e,r){t&&t.each((function(){var t,i=n.select(this),a=i.select("text");if(a.node()){var o=parseFloat(a.attr("x")||0),s=parseFloat(a.attr("y")||0),l=(i.attr("transform")||"").match(B);t=1===e&&1===r?[]:[f(o,s),"scale("+e+","+r+")",f(-o,-s)],l&&t.push(l),i.attr("transform",t.join(""))}}))}},{"../../components/fx/helpers":402,"../../constants/alignment":471,"../../constants/interactions":478,"../../constants/xmlns_namespaces":480,"../../lib":503,"../../lib/svg_text_utils":529,"../../registry":638,"../../traces/scatter/make_bubble_size_func":944,"../../traces/scatter/subtypes":952,"../color":366,"../colorscale":378,"./symbol_defs":389,"@plotly/d3":58,"fast-isnumeric":190,tinycolor2:312}],389:[function(t,e,r){"use strict";var n=t("@plotly/d3");e.exports={circle:{n:0,f:function(t){var e=n.round(t,2);return"M"+e+",0A"+e+","+e+" 0 1,1 0,-"+e+"A"+e+","+e+" 0 0,1 "+e+",0Z"}},square:{n:1,f:function(t){var e=n.round(t,2);return"M"+e+","+e+"H-"+e+"V-"+e+"H"+e+"Z"}},diamond:{n:2,f:function(t){var e=n.round(1.3*t,2);return"M"+e+",0L0,"+e+"L-"+e+",0L0,-"+e+"Z"}},cross:{n:3,f:function(t){var e=n.round(.4*t,2),r=n.round(1.2*t,2);return"M"+r+","+e+"H"+e+"V"+r+"H-"+e+"V"+e+"H-"+r+"V-"+e+"H-"+e+"V-"+r+"H"+e+"V-"+e+"H"+r+"Z"}},x:{n:4,f:function(t){var e=n.round(.8*t/Math.sqrt(2),2),r="l"+e+","+e,i="l"+e+",-"+e,a="l-"+e+",-"+e,o="l-"+e+","+e;return"M0,"+e+r+i+a+i+a+o+a+o+r+o+r+"Z"}},"triangle-up":{n:5,f:function(t){var e=n.round(2*t/Math.sqrt(3),2);return"M-"+e+","+n.round(t/2,2)+"H"+e+"L0,-"+n.round(t,2)+"Z"}},"triangle-down":{n:6,f:function(t){var e=n.round(2*t/Math.sqrt(3),2);return"M-"+e+",-"+n.round(t/2,2)+"H"+e+"L0,"+n.round(t,2)+"Z"}},"triangle-left":{n:7,f:function(t){var e=n.round(2*t/Math.sqrt(3),2);return"M"+n.round(t/2,2)+",-"+e+"V"+e+"L-"+n.round(t,2)+",0Z"}},"triangle-right":{n:8,f:function(t){var e=n.round(2*t/Math.sqrt(3),2);return"M-"+n.round(t/2,2)+",-"+e+"V"+e+"L"+n.round(t,2)+",0Z"}},"triangle-ne":{n:9,f:function(t){var e=n.round(.6*t,2),r=n.round(1.2*t,2);return"M-"+r+",-"+e+"H"+e+"V"+r+"Z"}},"triangle-se":{n:10,f:function(t){var e=n.round(.6*t,2),r=n.round(1.2*t,2);return"M"+e+",-"+r+"V"+e+"H-"+r+"Z"}},"triangle-sw":{n:11,f:function(t){var e=n.round(.6*t,2),r=n.round(1.2*t,2);return"M"+r+","+e+"H-"+e+"V-"+r+"Z"}},"triangle-nw":{n:12,f:function(t){var e=n.round(.6*t,2),r=n.round(1.2*t,2);return"M-"+e+","+r+"V-"+e+"H"+r+"Z"}},pentagon:{n:13,f:function(t){var e=n.round(.951*t,2),r=n.round(.588*t,2),i=n.round(-t,2),a=n.round(-.309*t,2);return"M"+e+","+a+"L"+r+","+n.round(.809*t,2)+"H-"+r+"L-"+e+","+a+"L0,"+i+"Z"}},hexagon:{n:14,f:function(t){var e=n.round(t,2),r=n.round(t/2,2),i=n.round(t*Math.sqrt(3)/2,2);return"M"+i+",-"+r+"V"+r+"L0,"+e+"L-"+i+","+r+"V-"+r+"L0,-"+e+"Z"}},hexagon2:{n:15,f:function(t){var e=n.round(t,2),r=n.round(t/2,2),i=n.round(t*Math.sqrt(3)/2,2);return"M-"+r+","+i+"H"+r+"L"+e+",0L"+r+",-"+i+"H-"+r+"L-"+e+",0Z"}},octagon:{n:16,f:function(t){var e=n.round(.924*t,2),r=n.round(.383*t,2);return"M-"+r+",-"+e+"H"+r+"L"+e+",-"+r+"V"+r+"L"+r+","+e+"H-"+r+"L-"+e+","+r+"V-"+r+"Z"}},star:{n:17,f:function(t){var e=1.4*t,r=n.round(.225*e,2),i=n.round(.951*e,2),a=n.round(.363*e,2),o=n.round(.588*e,2),s=n.round(-e,2),l=n.round(-.309*e,2),c=n.round(.118*e,2),u=n.round(.809*e,2);return"M"+r+","+l+"H"+i+"L"+a+","+c+"L"+o+","+u+"L0,"+n.round(.382*e,2)+"L-"+o+","+u+"L-"+a+","+c+"L-"+i+","+l+"H-"+r+"L0,"+s+"Z"}},hexagram:{n:18,f:function(t){var e=n.round(.66*t,2),r=n.round(.38*t,2),i=n.round(.76*t,2);return"M-"+i+",0l-"+r+",-"+e+"h"+i+"l"+r+",-"+e+"l"+r+","+e+"h"+i+"l-"+r+","+e+"l"+r+","+e+"h-"+i+"l-"+r+","+e+"l-"+r+",-"+e+"h-"+i+"Z"}},"star-triangle-up":{n:19,f:function(t){var e=n.round(t*Math.sqrt(3)*.8,2),r=n.round(.8*t,2),i=n.round(1.6*t,2),a=n.round(4*t,2),o="A "+a+","+a+" 0 0 1 ";return"M-"+e+","+r+o+e+","+r+o+"0,-"+i+o+"-"+e+","+r+"Z"}},"star-triangle-down":{n:20,f:function(t){var e=n.round(t*Math.sqrt(3)*.8,2),r=n.round(.8*t,2),i=n.round(1.6*t,2),a=n.round(4*t,2),o="A "+a+","+a+" 0 0 1 ";return"M"+e+",-"+r+o+"-"+e+",-"+r+o+"0,"+i+o+e+",-"+r+"Z"}},"star-square":{n:21,f:function(t){var e=n.round(1.1*t,2),r=n.round(2*t,2),i="A "+r+","+r+" 0 0 1 ";return"M-"+e+",-"+e+i+"-"+e+","+e+i+e+","+e+i+e+",-"+e+i+"-"+e+",-"+e+"Z"}},"star-diamond":{n:22,f:function(t){var e=n.round(1.4*t,2),r=n.round(1.9*t,2),i="A "+r+","+r+" 0 0 1 ";return"M-"+e+",0"+i+"0,"+e+i+e+",0"+i+"0,-"+e+i+"-"+e+",0Z"}},"diamond-tall":{n:23,f:function(t){var e=n.round(.7*t,2),r=n.round(1.4*t,2);return"M0,"+r+"L"+e+",0L0,-"+r+"L-"+e+",0Z"}},"diamond-wide":{n:24,f:function(t){var e=n.round(1.4*t,2),r=n.round(.7*t,2);return"M0,"+r+"L"+e+",0L0,-"+r+"L-"+e+",0Z"}},hourglass:{n:25,f:function(t){var e=n.round(t,2);return"M"+e+","+e+"H-"+e+"L"+e+",-"+e+"H-"+e+"Z"},noDot:!0},bowtie:{n:26,f:function(t){var e=n.round(t,2);return"M"+e+","+e+"V-"+e+"L-"+e+","+e+"V-"+e+"Z"},noDot:!0},"circle-cross":{n:27,f:function(t){var e=n.round(t,2);return"M0,"+e+"V-"+e+"M"+e+",0H-"+e+"M"+e+",0A"+e+","+e+" 0 1,1 0,-"+e+"A"+e+","+e+" 0 0,1 "+e+",0Z"},needLine:!0,noDot:!0},"circle-x":{n:28,f:function(t){var e=n.round(t,2),r=n.round(t/Math.sqrt(2),2);return"M"+r+","+r+"L-"+r+",-"+r+"M"+r+",-"+r+"L-"+r+","+r+"M"+e+",0A"+e+","+e+" 0 1,1 0,-"+e+"A"+e+","+e+" 0 0,1 "+e+",0Z"},needLine:!0,noDot:!0},"square-cross":{n:29,f:function(t){var e=n.round(t,2);return"M0,"+e+"V-"+e+"M"+e+",0H-"+e+"M"+e+","+e+"H-"+e+"V-"+e+"H"+e+"Z"},needLine:!0,noDot:!0},"square-x":{n:30,f:function(t){var e=n.round(t,2);return"M"+e+","+e+"L-"+e+",-"+e+"M"+e+",-"+e+"L-"+e+","+e+"M"+e+","+e+"H-"+e+"V-"+e+"H"+e+"Z"},needLine:!0,noDot:!0},"diamond-cross":{n:31,f:function(t){var e=n.round(1.3*t,2);return"M"+e+",0L0,"+e+"L-"+e+",0L0,-"+e+"ZM0,-"+e+"V"+e+"M-"+e+",0H"+e},needLine:!0,noDot:!0},"diamond-x":{n:32,f:function(t){var e=n.round(1.3*t,2),r=n.round(.65*t,2);return"M"+e+",0L0,"+e+"L-"+e+",0L0,-"+e+"ZM-"+r+",-"+r+"L"+r+","+r+"M-"+r+","+r+"L"+r+",-"+r},needLine:!0,noDot:!0},"cross-thin":{n:33,f:function(t){var e=n.round(1.4*t,2);return"M0,"+e+"V-"+e+"M"+e+",0H-"+e},needLine:!0,noDot:!0,noFill:!0},"x-thin":{n:34,f:function(t){var e=n.round(t,2);return"M"+e+","+e+"L-"+e+",-"+e+"M"+e+",-"+e+"L-"+e+","+e},needLine:!0,noDot:!0,noFill:!0},asterisk:{n:35,f:function(t){var e=n.round(1.2*t,2),r=n.round(.85*t,2);return"M0,"+e+"V-"+e+"M"+e+",0H-"+e+"M"+r+","+r+"L-"+r+",-"+r+"M"+r+",-"+r+"L-"+r+","+r},needLine:!0,noDot:!0,noFill:!0},hash:{n:36,f:function(t){var e=n.round(t/2,2),r=n.round(t,2);return"M"+e+","+r+"V-"+r+"m-"+r+",0V"+r+"M"+r+","+e+"H-"+r+"m0,-"+r+"H"+r},needLine:!0,noFill:!0},"y-up":{n:37,f:function(t){var e=n.round(1.2*t,2),r=n.round(1.6*t,2),i=n.round(.8*t,2);return"M-"+e+","+i+"L0,0M"+e+","+i+"L0,0M0,-"+r+"L0,0"},needLine:!0,noDot:!0,noFill:!0},"y-down":{n:38,f:function(t){var e=n.round(1.2*t,2),r=n.round(1.6*t,2),i=n.round(.8*t,2);return"M-"+e+",-"+i+"L0,0M"+e+",-"+i+"L0,0M0,"+r+"L0,0"},needLine:!0,noDot:!0,noFill:!0},"y-left":{n:39,f:function(t){var e=n.round(1.2*t,2),r=n.round(1.6*t,2),i=n.round(.8*t,2);return"M"+i+","+e+"L0,0M"+i+",-"+e+"L0,0M-"+r+",0L0,0"},needLine:!0,noDot:!0,noFill:!0},"y-right":{n:40,f:function(t){var e=n.round(1.2*t,2),r=n.round(1.6*t,2),i=n.round(.8*t,2);return"M-"+i+","+e+"L0,0M-"+i+",-"+e+"L0,0M"+r+",0L0,0"},needLine:!0,noDot:!0,noFill:!0},"line-ew":{n:41,f:function(t){var e=n.round(1.4*t,2);return"M"+e+",0H-"+e},needLine:!0,noDot:!0,noFill:!0},"line-ns":{n:42,f:function(t){var e=n.round(1.4*t,2);return"M0,"+e+"V-"+e},needLine:!0,noDot:!0,noFill:!0},"line-ne":{n:43,f:function(t){var e=n.round(t,2);return"M"+e+",-"+e+"L-"+e+","+e},needLine:!0,noDot:!0,noFill:!0},"line-nw":{n:44,f:function(t){var e=n.round(t,2);return"M"+e+","+e+"L-"+e+",-"+e},needLine:!0,noDot:!0,noFill:!0},"arrow-up":{n:45,f:function(t){var e=n.round(t,2);return"M0,0L-"+e+","+n.round(2*t,2)+"H"+e+"Z"},noDot:!0},"arrow-down":{n:46,f:function(t){var e=n.round(t,2);return"M0,0L-"+e+",-"+n.round(2*t,2)+"H"+e+"Z"},noDot:!0},"arrow-left":{n:47,f:function(t){var e=n.round(2*t,2),r=n.round(t,2);return"M0,0L"+e+",-"+r+"V"+r+"Z"},noDot:!0},"arrow-right":{n:48,f:function(t){var e=n.round(2*t,2),r=n.round(t,2);return"M0,0L-"+e+",-"+r+"V"+r+"Z"},noDot:!0},"arrow-bar-up":{n:49,f:function(t){var e=n.round(t,2);return"M-"+e+",0H"+e+"M0,0L-"+e+","+n.round(2*t,2)+"H"+e+"Z"},needLine:!0,noDot:!0},"arrow-bar-down":{n:50,f:function(t){var e=n.round(t,2);return"M-"+e+",0H"+e+"M0,0L-"+e+",-"+n.round(2*t,2)+"H"+e+"Z"},needLine:!0,noDot:!0},"arrow-bar-left":{n:51,f:function(t){var e=n.round(2*t,2),r=n.round(t,2);return"M0,-"+r+"V"+r+"M0,0L"+e+",-"+r+"V"+r+"Z"},needLine:!0,noDot:!0},"arrow-bar-right":{n:52,f:function(t){var e=n.round(2*t,2),r=n.round(t,2);return"M0,-"+r+"V"+r+"M0,0L-"+e+",-"+r+"V"+r+"Z"},needLine:!0,noDot:!0}}},{"@plotly/d3":58}],390:[function(t,e,r){"use strict";e.exports={visible:{valType:"boolean",editType:"calc"},type:{valType:"enumerated",values:["percent","constant","sqrt","data"],editType:"calc"},symmetric:{valType:"boolean",editType:"calc"},array:{valType:"data_array",editType:"calc"},arrayminus:{valType:"data_array",editType:"calc"},value:{valType:"number",min:0,dflt:10,editType:"calc"},valueminus:{valType:"number",min:0,dflt:10,editType:"calc"},traceref:{valType:"integer",min:0,dflt:0,editType:"style"},tracerefminus:{valType:"integer",min:0,dflt:0,editType:"style"},copy_ystyle:{valType:"boolean",editType:"plot"},copy_zstyle:{valType:"boolean",editType:"style"},color:{valType:"color",editType:"style"},thickness:{valType:"number",min:0,dflt:2,editType:"style"},width:{valType:"number",min:0,editType:"plot"},editType:"calc",_deprecated:{opacity:{valType:"number",editType:"style"}}}},{}],391:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../registry"),a=t("../../plots/cartesian/axes"),o=t("../../lib"),s=t("./compute_error");function l(t,e,r,i){var l=e["error_"+i]||{},c=[];if(l.visible&&-1!==["linear","log"].indexOf(r.type)){for(var u=s(l),f=0;f<t.length;f++){var h=t[f],p=h.i;if(void 0===p)p=f;else if(null===p)continue;var d=h[i];if(n(r.c2l(d))){var m=u(d,p);if(n(m[0])&&n(m[1])){var g=h[i+"s"]=d-m[0],v=h[i+"h"]=d+m[1];c.push(g,v)}}}var y=r._id,x=e._extremes[y],b=a.findExtremes(r,c,o.extendFlat({tozero:x.opts.tozero},{padded:!0}));x.min=x.min.concat(b.min),x.max=x.max.concat(b.max)}}e.exports=function(t){for(var e=t.calcdata,r=0;r<e.length;r++){var n=e[r],o=n[0].trace;if(!0===o.visible&&i.traceIs(o,"errorBarsOK")){var s=a.getFromId(t,o.xaxis),c=a.getFromId(t,o.yaxis);l(n,o,s,"x"),l(n,o,c,"y")}}}},{"../../lib":503,"../../plots/cartesian/axes":554,"../../registry":638,"./compute_error":392,"fast-isnumeric":190}],392:[function(t,e,r){"use strict";function n(t,e){return"percent"===t?function(t){return Math.abs(t*e/100)}:"constant"===t?function(){return Math.abs(e)}:"sqrt"===t?function(t){return Math.sqrt(Math.abs(t))}:void 0}e.exports=function(t){var e=t.type,r=t.symmetric;if("data"===e){var i=t.array||[];if(r)return function(t,e){var r=+i[e];return[r,r]};var a=t.arrayminus||[];return function(t,e){var r=+i[e],n=+a[e];return isNaN(r)&&isNaN(n)?[NaN,NaN]:[n||0,r||0]}}var o=n(e,t.value),s=n(e,t.valueminus);return r||void 0===t.valueminus?function(t){var e=o(t);return[e,e]}:function(t){return[s(t),o(t)]}}},{}],393:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../registry"),a=t("../../lib"),o=t("../../plot_api/plot_template"),s=t("./attributes");e.exports=function(t,e,r,l){var c="error_"+l.axis,u=o.newContainer(e,c),f=t[c]||{};function h(t,e){return a.coerce(f,u,s,t,e)}if(!1!==h("visible",void 0!==f.array||void 0!==f.value||"sqrt"===f.type)){var p=h("type","array"in f?"data":"percent"),d=!0;"sqrt"!==p&&(d=h("symmetric",!(("data"===p?"arrayminus":"valueminus")in f))),"data"===p?(h("array"),h("traceref"),d||(h("arrayminus"),h("tracerefminus"))):"percent"!==p&&"constant"!==p||(h("value"),d||h("valueminus"));var m="copy_"+l.inherit+"style";if(l.inherit)(e["error_"+l.inherit]||{}).visible&&h(m,!(f.color||n(f.thickness)||n(f.width)));l.inherit&&u[m]||(h("color",r),h("thickness"),h("width",i.traceIs(e,"gl3d")?0:4))}}},{"../../lib":503,"../../plot_api/plot_template":543,"../../registry":638,"./attributes":390,"fast-isnumeric":190}],394:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plot_api/edit_types").overrideAll,a=t("./attributes"),o={error_x:n.extendFlat({},a),error_y:n.extendFlat({},a)};delete o.error_x.copy_zstyle,delete o.error_y.copy_zstyle,delete o.error_y.copy_ystyle;var s={error_x:n.extendFlat({},a),error_y:n.extendFlat({},a),error_z:n.extendFlat({},a)};delete s.error_x.copy_ystyle,delete s.error_y.copy_ystyle,delete s.error_z.copy_ystyle,delete s.error_z.copy_zstyle,e.exports={moduleType:"component",name:"errorbars",schema:{traces:{scatter:o,bar:o,histogram:o,scatter3d:i(s,"calc","nested"),scattergl:i(o,"calc","nested")}},supplyDefaults:t("./defaults"),calc:t("./calc"),makeComputeError:t("./compute_error"),plot:t("./plot"),style:t("./style"),hoverInfo:function(t,e,r){(e.error_y||{}).visible&&(r.yerr=t.yh-t.y,e.error_y.symmetric||(r.yerrneg=t.y-t.ys));(e.error_x||{}).visible&&(r.xerr=t.xh-t.x,e.error_x.symmetric||(r.xerrneg=t.x-t.xs))}}},{"../../lib":503,"../../plot_api/edit_types":536,"./attributes":390,"./calc":391,"./compute_error":392,"./defaults":393,"./plot":395,"./style":396}],395:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("fast-isnumeric"),a=t("../drawing"),o=t("../../traces/scatter/subtypes");e.exports=function(t,e,r,s){var l=r.xaxis,c=r.yaxis,u=s&&s.duration>0;e.each((function(e){var f,h=e[0].trace,p=h.error_x||{},d=h.error_y||{};h.ids&&(f=function(t){return t.id});var m=o.hasMarkers(h)&&h.marker.maxdisplayed>0;d.visible||p.visible||(e=[]);var g=n.select(this).selectAll("g.errorbar").data(e,f);if(g.exit().remove(),e.length){p.visible||g.selectAll("path.xerror").remove(),d.visible||g.selectAll("path.yerror").remove(),g.style("opacity",1);var v=g.enter().append("g").classed("errorbar",!0);u&&v.style("opacity",0).transition().duration(s.duration).style("opacity",1),a.setClipUrl(g,r.layerClipId,t),g.each((function(t){var e=n.select(this),r=function(t,e,r){var n={x:e.c2p(t.x),y:r.c2p(t.y)};void 0!==t.yh&&(n.yh=r.c2p(t.yh),n.ys=r.c2p(t.ys),i(n.ys)||(n.noYS=!0,n.ys=r.c2p(t.ys,!0)));void 0!==t.xh&&(n.xh=e.c2p(t.xh),n.xs=e.c2p(t.xs),i(n.xs)||(n.noXS=!0,n.xs=e.c2p(t.xs,!0)));return n}(t,l,c);if(!m||t.vis){var a,o=e.select("path.yerror");if(d.visible&&i(r.x)&&i(r.yh)&&i(r.ys)){var f=d.width;a="M"+(r.x-f)+","+r.yh+"h"+2*f+"m-"+f+",0V"+r.ys,r.noYS||(a+="m-"+f+",0h"+2*f),!o.size()?o=e.append("path").style("vector-effect","non-scaling-stroke").classed("yerror",!0):u&&(o=o.transition().duration(s.duration).ease(s.easing)),o.attr("d",a)}else o.remove();var h=e.select("path.xerror");if(p.visible&&i(r.y)&&i(r.xh)&&i(r.xs)){var g=(p.copy_ystyle?d:p).width;a="M"+r.xh+","+(r.y-g)+"v"+2*g+"m0,-"+g+"H"+r.xs,r.noXS||(a+="m0,-"+g+"v"+2*g),!h.size()?h=e.append("path").style("vector-effect","non-scaling-stroke").classed("xerror",!0):u&&(h=h.transition().duration(s.duration).ease(s.easing)),h.attr("d",a)}else h.remove()}}))}}))}},{"../../traces/scatter/subtypes":952,"../drawing":388,"@plotly/d3":58,"fast-isnumeric":190}],396:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../color");e.exports=function(t){t.each((function(t){var e=t[0].trace,r=e.error_y||{},a=e.error_x||{},o=n.select(this);o.selectAll("path.yerror").style("stroke-width",r.thickness+"px").call(i.stroke,r.color),a.copy_ystyle&&(a=r),o.selectAll("path.xerror").style("stroke-width",a.thickness+"px").call(i.stroke,a.color)}))}},{"../color":366,"@plotly/d3":58}],397:[function(t,e,r){"use strict";var n=t("../../plots/font_attributes"),i=t("./layout_attributes").hoverlabel,a=t("../../lib/extend").extendFlat;e.exports={hoverlabel:{bgcolor:a({},i.bgcolor,{arrayOk:!0}),bordercolor:a({},i.bordercolor,{arrayOk:!0}),font:n({arrayOk:!0,editType:"none"}),align:a({},i.align,{arrayOk:!0}),namelength:a({},i.namelength,{arrayOk:!0}),editType:"none"}}},{"../../lib/extend":493,"../../plots/font_attributes":585,"./layout_attributes":407}],398:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../registry");function a(t,e,r,i){i=i||n.identity,Array.isArray(t)&&(e[0][r]=i(t))}e.exports=function(t){var e=t.calcdata,r=t._fullLayout;function o(t){return function(e){return n.coerceHoverinfo({hoverinfo:e},{_module:t._module},r)}}for(var s=0;s<e.length;s++){var l=e[s],c=l[0].trace;if(!i.traceIs(c,"pie-like")){var u=i.traceIs(c,"2dMap")?a:n.fillArray;u(c.hoverinfo,l,"hi",o(c)),c.hovertemplate&&u(c.hovertemplate,l,"ht"),c.hoverlabel&&(u(c.hoverlabel.bgcolor,l,"hbg"),u(c.hoverlabel.bordercolor,l,"hbc"),u(c.hoverlabel.font.size,l,"hts"),u(c.hoverlabel.font.color,l,"htc"),u(c.hoverlabel.font.family,l,"htf"),u(c.hoverlabel.namelength,l,"hnl"),u(c.hoverlabel.align,l,"hta"))}}}},{"../../lib":503,"../../registry":638}],399:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("./hover").hover;e.exports=function(t,e,r){var a=n.getComponentMethod("annotations","onClick")(t,t._hoverdata);function o(){t.emit("plotly_click",{points:t._hoverdata,event:e})}void 0!==r&&i(t,e,r,!0),t._hoverdata&&e&&e.target&&(a&&a.then?a.then(o):o(),e.stopImmediatePropagation&&e.stopImmediatePropagation())}},{"../../registry":638,"./hover":403}],400:[function(t,e,r){"use strict";e.exports={YANGLE:60,HOVERARROWSIZE:6,HOVERTEXTPAD:3,HOVERFONTSIZE:13,HOVERFONT:"Arial, sans-serif",HOVERMINTIME:50,HOVERID:"-hover"}},{}],401:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./attributes"),a=t("./hoverlabel_defaults");e.exports=function(t,e,r,o){var s=n.extendFlat({},o.hoverlabel);e.hovertemplate&&(s.namelength=-1),a(t,e,(function(r,a){return n.coerce(t,e,i,r,a)}),s)}},{"../../lib":503,"./attributes":397,"./hoverlabel_defaults":404}],402:[function(t,e,r){"use strict";var n=t("../../lib");r.getSubplot=function(t){return t.subplot||t.xaxis+t.yaxis||t.geo},r.isTraceInSubplots=function(t,e){if("splom"===t.type){for(var n=t.xaxes||[],i=t.yaxes||[],a=0;a<n.length;a++)for(var o=0;o<i.length;o++)if(-1!==e.indexOf(n[a]+i[o]))return!0;return!1}return-1!==e.indexOf(r.getSubplot(t))},r.flat=function(t,e){for(var r=new Array(t.length),n=0;n<t.length;n++)r[n]=e;return r},r.p2c=function(t,e){for(var r=new Array(t.length),n=0;n<t.length;n++)r[n]=t[n].p2c(e);return r},r.getDistanceFunction=function(t,e,n,i){return"closest"===t?i||r.quadrature(e,n):"x"===t.charAt(0)?e:n},r.getClosest=function(t,e,r){if(!1!==r.index)r.index>=0&&r.index<t.length?r.distance=0:r.index=!1;else for(var n=0;n<t.length;n++){var i=e(t[n]);i<=r.distance&&(r.index=n,r.distance=i)}return r},r.inbox=function(t,e,r){return t*e<0||0===t?r:1/0},r.quadrature=function(t,e){return function(r){var n=t(r),i=e(r);return Math.sqrt(n*n+i*i)}},r.makeEventData=function(t,e,n){var i="index"in t?t.index:t.pointNumber,a={data:e._input,fullData:e,curveNumber:e.index,pointNumber:i};if(e._indexToPoints){var o=e._indexToPoints[i];1===o.length?a.pointIndex=o[0]:a.pointIndices=o}else a.pointIndex=i;return e._module.eventData?a=e._module.eventData(a,t,e,n,i):("xVal"in t?a.x=t.xVal:"x"in t&&(a.x=t.x),"yVal"in t?a.y=t.yVal:"y"in t&&(a.y=t.y),t.xa&&(a.xaxis=t.xa),t.ya&&(a.yaxis=t.ya),void 0!==t.zLabelVal&&(a.z=t.zLabelVal)),r.appendArrayPointValue(a,e,i),a},r.appendArrayPointValue=function(t,e,r){var i=e._arrayAttrs;if(i)for(var s=0;s<i.length;s++){var l=i[s],c=a(l);if(void 0===t[c]){var u=o(n.nestedProperty(e,l).get(),r);void 0!==u&&(t[c]=u)}}},r.appendArrayMultiPointValues=function(t,e,r){var i=e._arrayAttrs;if(i)for(var s=0;s<i.length;s++){var l=i[s],c=a(l);if(void 0===t[c]){for(var u=n.nestedProperty(e,l).get(),f=new Array(r.length),h=0;h<r.length;h++)f[h]=o(u,r[h]);t[c]=f}}};var i={ids:"id",locations:"location",labels:"label",values:"value","marker.colors":"color",parents:"parent"};function a(t){return i[t]||t}function o(t,e){return Array.isArray(e)?Array.isArray(t)&&Array.isArray(t[e[0]])?t[e[0]][e[1]]:void 0:t[e]}var s={x:!0,y:!0},l={"x unified":!0,"y unified":!0};r.isUnifiedHover=function(t){return"string"==typeof t&&!!l[t]},r.isXYhover=function(t){return"string"==typeof t&&!!s[t]}},{"../../lib":503}],403:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("fast-isnumeric"),a=t("tinycolor2"),o=t("../../lib"),s=o.strTranslate,l=o.strRotate,c=t("../../lib/events"),u=t("../../lib/svg_text_utils"),f=t("../../lib/override_cursor"),h=t("../drawing"),p=t("../color"),d=t("../dragelement"),m=t("../../plots/cartesian/axes"),g=t("../../registry"),v=t("./helpers"),y=t("./constants"),x=t("../legend/defaults"),b=t("../legend/draw"),_=y.YANGLE,w=Math.PI*_/180,T=1/Math.sin(w),k=Math.cos(w),A=Math.sin(w),M=y.HOVERARROWSIZE,S=y.HOVERTEXTPAD,E={box:!0,ohlc:!0,violin:!0,candlestick:!0},L={scatter:!0,scattergl:!0,splom:!0};function C(t){return[t.trace.index,t.index,t.x0,t.y0,t.name,t.attr,t.xa?t.xa._id:"",t.ya?t.ya._id:""].join(",")}r.hover=function(t,e,r,a){t=o.getGraphDiv(t);var s=e.target;o.throttle(t._fullLayout._uid+y.HOVERID,y.HOVERMINTIME,(function(){!function(t,e,r,a,s){r||(r="xy");var l=Array.isArray(r)?r:[r],u=t._fullLayout,h=u._plots||[],m=h[r],y=u._has("cartesian");if(m){var x=m.overlays.map((function(t){return t.id}));l=l.concat(x)}for(var b=l.length,_=new Array(b),w=new Array(b),k=!1,A=0;A<b;A++){var M=l[A];if(h[M])k=!0,_[A]=h[M].xaxis,w[A]=h[M].yaxis;else{if(!u[M]||!u[M]._subplot)return void o.warn("Unrecognized subplot: "+M);var S=u[M]._subplot;_[A]=S.xaxis,w[A]=S.yaxis}}var P=e.hovermode||u.hovermode;P&&!k&&(P="closest");if(-1===["x","y","closest","x unified","y unified"].indexOf(P)||!t.calcdata||t.querySelector(".zoombox")||t._dragging)return d.unhoverRaw(t,e);var O=u.hoverdistance;-1===O&&(O=1/0);var B=u.spikedistance;-1===B&&(B=1/0);var V,H,q,G,Y,W,X,Z,J,K,Q,$,tt,et=[],rt=[],nt={hLinePoint:null,vLinePoint:null},it=!1;if(Array.isArray(e))for(P="array",q=0;q<e.length;q++)(Y=t.calcdata[e[q].curveNumber||0])&&(W=Y[0].trace,"skip"!==Y[0].trace.hoverinfo&&(rt.push(Y),"h"===W.orientation&&(it=!0)));else{for(G=0;G<t.calcdata.length;G++)Y=t.calcdata[G],"skip"!==(W=Y[0].trace).hoverinfo&&v.isTraceInSubplots(W,l)&&(rt.push(Y),"h"===W.orientation&&(it=!0));var at,ot;if(!s)at="xpx"in e?e.xpx:_[0]._length/2,ot="ypx"in e?e.ypx:w[0]._length/2;else{if(!1===c.triggerHandler(t,"plotly_beforehover",e))return;var st=s.getBoundingClientRect();at=e.clientX-st.left,ot=e.clientY-st.top,u._calcInverseTransform(t);var lt=o.apply3DTransform(u._invTransform)(at,ot);if(at=lt[0],ot=lt[1],at<0||at>_[0]._length||ot<0||ot>w[0]._length)return d.unhoverRaw(t,e)}if(e.pointerX=at+_[0]._offset,e.pointerY=ot+w[0]._offset,V="xval"in e?v.flat(l,e.xval):v.p2c(_,at),H="yval"in e?v.flat(l,e.yval):v.p2c(w,ot),!i(V[0])||!i(H[0]))return o.warn("Fx.hover failed",e,t),d.unhoverRaw(t,e)}var ct=1/0;function ut(t,r){for(G=0;G<rt.length;G++)if((Y=rt[G])&&Y[0]&&Y[0].trace&&!0===(W=Y[0].trace).visible&&0!==W._length&&-1===["carpet","contourcarpet"].indexOf(W._module.name)){if("splom"===W.type?X=l[Z=0]:(X=v.getSubplot(W),Z=l.indexOf(X)),J=P,v.isUnifiedHover(J)&&(J=J.charAt(0)),$={cd:Y,trace:W,xa:_[Z],ya:w[Z],maxHoverDistance:O,maxSpikeDistance:B,index:!1,distance:Math.min(ct,O),spikeDistance:1/0,xSpike:void 0,ySpike:void 0,color:p.defaultLine,name:W.name,x0:void 0,x1:void 0,y0:void 0,y1:void 0,xLabelVal:void 0,yLabelVal:void 0,zLabelVal:void 0,text:void 0},u[X]&&($.subplot=u[X]._subplot),u._splomScenes&&u._splomScenes[W.uid]&&($.scene=u._splomScenes[W.uid]),tt=et.length,"array"===J){var n=e[G];"pointNumber"in n?($.index=n.pointNumber,J="closest"):(J="","xval"in n&&(K=n.xval,J="x"),"yval"in n&&(Q=n.yval,J=J?"closest":"y"))}else void 0!==t&&void 0!==r?(K=t,Q=r):(K=V[Z],Q=H[Z]);if(0!==O)if(W._module&&W._module.hoverPoints){var a=W._module.hoverPoints($,K,Q,J,{finiteRange:!0,hoverLayer:u._hoverlayer});if(a)for(var s,c=0;c<a.length;c++)s=a[c],i(s.x0)&&i(s.y0)&&et.push(D(s,P))}else o.log("Unrecognized trace type in hover:",W);if("closest"===P&&et.length>tt&&(et.splice(0,tt),ct=et[0].distance),y&&0!==B&&0===et.length){$.distance=B,$.index=!1;var f=W._module.hoverPoints($,K,Q,"closest",{hoverLayer:u._hoverlayer});if(f&&(f=f.filter((function(t){return t.spikeDistance<=B}))),f&&f.length){var h,d=f.filter((function(t){return t.xa.showspikes&&"hovered data"!==t.xa.spikesnap}));if(d.length){var m=d[0];i(m.x0)&&i(m.y0)&&(h=ht(m),(!nt.vLinePoint||nt.vLinePoint.spikeDistance>h.spikeDistance)&&(nt.vLinePoint=h))}var g=f.filter((function(t){return t.ya.showspikes&&"hovered data"!==t.ya.spikesnap}));if(g.length){var x=g[0];i(x.x0)&&i(x.y0)&&(h=ht(x),(!nt.hLinePoint||nt.hLinePoint.spikeDistance>h.spikeDistance)&&(nt.hLinePoint=h))}}}}}function ft(t,e,r){for(var n,i=null,a=1/0,o=0;o<t.length;o++)n=t[o].spikeDistance,r&&0===o&&(n=-1/0),n<=a&&n<=e&&(i=t[o],a=n);return i}function ht(t){return t?{xa:t.xa,ya:t.ya,x:void 0!==t.xSpike?t.xSpike:(t.x0+t.x1)/2,y:void 0!==t.ySpike?t.ySpike:(t.y0+t.y1)/2,distance:t.distance,spikeDistance:t.spikeDistance,curveNumber:t.trace.index,color:t.color,pointNumber:t.index}:null}ut();var pt={fullLayout:u,container:u._hoverlayer,event:e},dt=t._spikepoints,mt={vLinePoint:nt.vLinePoint,hLinePoint:nt.hLinePoint};t._spikepoints=mt;var gt=function(){et.sort((function(t,e){return t.distance-e.distance})),et=function(t,e){for(var r=e.charAt(0),n=[],i=[],a=[],o=0;o<t.length;o++){var s=t[o];g.traceIs(s.trace,"bar-like")||g.traceIs(s.trace,"box-violin")?a.push(s):s.trace[r+"period"]?i.push(s):n.push(s)}return n.concat(i).concat(a)}(et,P)};gt();var vt=P.charAt(0),yt=("x"===vt||"y"===vt)&&et[0]&&L[et[0].trace.type];if(y&&0!==B&&0!==et.length){var xt=ft(et.filter((function(t){return t.ya.showspikes})),B,yt);nt.hLinePoint=ht(xt);var bt=ft(et.filter((function(t){return t.xa.showspikes})),B,yt);nt.vLinePoint=ht(bt)}if(0===et.length){var _t=d.unhoverRaw(t,e);return!y||null===nt.hLinePoint&&null===nt.vLinePoint||F(dt)&&R(t,nt,pt),_t}y&&F(dt)&&R(t,nt,pt);if(v.isXYhover(J)&&0!==et[0].length&&"splom"!==et[0].trace.type){var wt=et[0],Tt=(et=E[wt.trace.type]?et.filter((function(t){return t.trace.index===wt.trace.index})):[wt]).length,kt=N("x",wt,u),At=N("y",wt,u);ut(kt,At);var Mt,St=[],Et={},Lt=0,Ct=function(t){var e=E[t.trace.type]?C(t):t.trace.index;if(Et[e]){var r=Et[e]-1,n=St[r];r>0&&Math.abs(t.distance)<Math.abs(n.distance)&&(St[r]=t)}else Lt++,Et[e]=Lt,St.push(t)};for(Mt=0;Mt<Tt;Mt++)Ct(et[Mt]);for(Mt=et.length-1;Mt>Tt-1;Mt--)Ct(et[Mt]);et=St,gt()}var Pt=t._hoverdata,It=[],Ot=j(t),zt=U(t);for(q=0;q<et.length;q++){var Dt=et[q],Rt=v.makeEventData(Dt,Dt.trace,Dt.cd);if(!1!==Dt.hovertemplate){var Ft=!1;Dt.cd[Dt.index]&&Dt.cd[Dt.index].ht&&(Ft=Dt.cd[Dt.index].ht),Dt.hovertemplate=Ft||Dt.trace.hovertemplate||!1}if(Dt.xa&&Dt.ya){var Bt=Dt.x0+Dt.xa._offset,Nt=Dt.x1+Dt.xa._offset,jt=Dt.y0+Dt.ya._offset,Ut=Dt.y1+Dt.ya._offset,Vt=Math.min(Bt,Nt),Ht=Math.max(Bt,Nt),qt=Math.min(jt,Ut),Gt=Math.max(jt,Ut);Rt.bbox={x0:Vt+zt,x1:Ht+zt,y0:qt+Ot,y1:Gt+Ot}}Dt.eventData=[Rt],It.push(Rt)}t._hoverdata=It;var Yt="y"===P&&(rt.length>1||et.length>1)||"closest"===P&&it&&et.length>1,Wt=p.combine(u.plot_bgcolor||p.background,u.paper_bgcolor),Xt=I(et,{gd:t,hovermode:P,rotateLabels:Yt,bgColor:Wt,container:u._hoverlayer,outerContainer:u._paper.node(),commonLabelOpts:u.hoverlabel,hoverdistance:u.hoverdistance});v.isUnifiedHover(P)||(!function(t,e,r){var n,i,a,o,s,l,c,u=0,f=1,h=t.size(),p=new Array(h),d=0;function m(t){var e=t[0],r=t[t.length-1];if(i=e.pmin-e.pos-e.dp+e.size,a=r.pos+r.dp+r.size-e.pmax,i>.01){for(s=t.length-1;s>=0;s--)t[s].dp+=i;n=!1}if(!(a<.01)){if(i<-.01){for(s=t.length-1;s>=0;s--)t[s].dp-=a;n=!1}if(n){var c=0;for(o=0;o<t.length;o++)(l=t[o]).pos+l.dp+l.size>e.pmax&&c++;for(o=t.length-1;o>=0&&!(c<=0);o--)(l=t[o]).pos>e.pmax-1&&(l.del=!0,c--);for(o=0;o<t.length&&!(c<=0);o++)if((l=t[o]).pos<e.pmin+1)for(l.del=!0,c--,a=2*l.size,s=t.length-1;s>=0;s--)t[s].dp-=a;for(o=t.length-1;o>=0&&!(c<=0);o--)(l=t[o]).pos+l.dp+l.size>e.pmax&&(l.del=!0,c--)}}}t.each((function(t){var n=t[e],i="x"===n._id.charAt(0),a=n.range;0===d&&a&&a[0]>a[1]!==i&&(f=-1),p[d++]=[{datum:t,traceIndex:t.trace.index,dp:0,pos:t.pos,posref:t.posref,size:t.by*(i?T:1)/2,pmin:0,pmax:i?r.width:r.height}]})),p.sort((function(t,e){return t[0].posref-e[0].posref||f*(e[0].traceIndex-t[0].traceIndex)}));for(;!n&&u<=h;){for(u++,n=!0,o=0;o<p.length-1;){var g=p[o],v=p[o+1],y=g[g.length-1],x=v[0];if((i=y.pos+y.dp+y.size-x.pos-x.dp+x.size)>.01&&y.pmin===x.pmin&&y.pmax===x.pmax){for(s=v.length-1;s>=0;s--)v[s].dp+=i;for(g.push.apply(g,v),p.splice(o+1,1),c=0,s=g.length-1;s>=0;s--)c+=g[s].dp;for(a=c/g.length,s=g.length-1;s>=0;s--)g[s].dp-=a;n=!1}else o++}p.forEach(m)}for(o=p.length-1;o>=0;o--){var b=p[o];for(s=b.length-1;s>=0;s--){var _=b[s],w=_.datum;w.offset=_.dp,w.del=_.del}}}(Xt,Yt?"xa":"ya",u),z(Xt,Yt,u._invScaleX,u._invScaleY));if(s&&s.tagName){var Zt=g.getComponentMethod("annotations","hasClickToShow")(t,It);f(n.select(s),Zt?"pointer":"")}if(!s||a||!function(t,e,r){if(!r||r.length!==t._hoverdata.length)return!0;for(var n=r.length-1;n>=0;n--){var i=r[n],a=t._hoverdata[n];if(i.curveNumber!==a.curveNumber||String(i.pointNumber)!==String(a.pointNumber)||String(i.pointNumbers)!==String(a.pointNumbers))return!0}return!1}(t,0,Pt))return;Pt&&t.emit("plotly_unhover",{event:e,points:Pt});t.emit("plotly_hover",{event:e,points:t._hoverdata,xaxes:_,yaxes:w,xvals:V,yvals:H})}(t,e,r,a,s)}))},r.loneHover=function(t,e){var r=!0;Array.isArray(t)||(r=!1,t=[t]);var i=e.gd,a=j(i),o=U(i),s=I(t.map((function(t){var r=t._x0||t.x0||t.x||0,n=t._x1||t.x1||t.x||0,s=t._y0||t.y0||t.y||0,l=t._y1||t.y1||t.y||0,c=t.eventData;if(c){var u=Math.min(r,n),f=Math.max(r,n),h=Math.min(s,l),d=Math.max(s,l),m=t.trace;if(g.traceIs(m,"gl3d")){var v=i._fullLayout[m.scene]._scene.container,y=v.offsetLeft,x=v.offsetTop;u+=y,f+=y,h+=x,d+=x}c.bbox={x0:u+o,x1:f+o,y0:h+a,y1:d+a},e.inOut_bbox&&e.inOut_bbox.push(c.bbox)}else c=!1;return{color:t.color||p.defaultLine,x0:t.x0||t.x||0,x1:t.x1||t.x||0,y0:t.y0||t.y||0,y1:t.y1||t.y||0,xLabel:t.xLabel,yLabel:t.yLabel,zLabel:t.zLabel,text:t.text,name:t.name,idealAlign:t.idealAlign,borderColor:t.borderColor,fontFamily:t.fontFamily,fontSize:t.fontSize,fontColor:t.fontColor,nameLength:t.nameLength,textAlign:t.textAlign,trace:t.trace||{index:0,hoverinfo:""},xa:{_offset:0},ya:{_offset:0},index:0,hovertemplate:t.hovertemplate||!1,hovertemplateLabels:t.hovertemplateLabels||!1,eventData:c}})),{gd:i,hovermode:"closest",rotateLabels:!1,bgColor:e.bgColor||p.background,container:n.select(e.container),outerContainer:e.outerContainer||e.container}),l=0,c=0;return s.sort((function(t,e){return t.y0-e.y0})).each((function(t,r){var n=t.y0-t.by/2;t.offset=n-5<l?l-n+5:0,l=n+t.by+t.offset,r===e.anchorIndex&&(c=t.offset)})).each((function(t){t.offset-=c})),z(s,!1,i._fullLayout._invScaleX,i._fullLayout._invScaleY),r?s:s.node()};var P=/<extra>([\s\S]*)<\/extra>/;function I(t,e){var r=e.gd,i=r._fullLayout,a=e.hovermode,c=e.rotateLabels,f=e.bgColor,d=e.container,m=e.outerContainer,w=e.commonLabelOpts||{};if(0===t.length)return[[]];var T=e.fontFamily||y.HOVERFONT,k=e.fontSize||y.HOVERFONTSIZE,A=t[0],E=A.xa,L=A.ya,P=a.charAt(0),I=A[P+"Label"],z=V(r,m),D=z.top,R=z.width,F=z.height,B=void 0!==I&&A.distance<=e.hoverdistance&&("x"===a||"y"===a);if(B){var N,j,U=!0;for(N=0;N<t.length;N++)if(U&&void 0===t[N].zLabel&&(U=!1),j=t[N].hoverinfo||t[N].trace.hoverinfo){var H=Array.isArray(j)?j:j.split("+");if(-1===H.indexOf("all")&&-1===H.indexOf(a)){B=!1;break}}U&&(B=!1)}var q=d.selectAll("g.axistext").data(B?[0]:[]);if(q.enter().append("g").classed("axistext",!0),q.exit().remove(),q.each((function(){var t=n.select(this),e=o.ensureSingle(t,"path","",(function(t){t.style({"stroke-width":"1px"})})),l=o.ensureSingle(t,"text","",(function(t){t.attr("data-notex",1)})),c=w.bgcolor||p.defaultLine,f=w.bordercolor||p.contrast(c),d=p.contrast(c),m={family:w.font.family||T,size:w.font.size||k,color:w.font.color||d};e.style({fill:c,stroke:f}),l.text(I).call(h.font,m).call(u.positionText,0,0).call(u.convertToTspans,r),t.attr("transform","");var g,v,y=V(r,l.node());if("x"===a){var x="top"===E.side?"-":"";l.attr("text-anchor","middle").call(u.positionText,0,"top"===E.side?D-y.bottom-M-S:D-y.top+M+S),g=E._offset+(A.x0+A.x1)/2,v=L._offset+("top"===E.side?0:L._length);var b=y.width/2+S;g<b?(g=b,e.attr("d","M-"+(b-M)+",0L-"+(b-2*M)+","+x+M+"H"+(S+y.width/2)+"v"+x+(2*S+y.height)+"H-"+b+"V"+x+M+"Z")):g>i.width-b?(g=i.width-b,e.attr("d","M"+(b-M)+",0L"+b+","+x+M+"v"+x+(2*S+y.height)+"H-"+b+"V"+x+M+"H"+(b-2*M)+"Z")):e.attr("d","M0,0L"+M+","+x+M+"H"+(S+y.width/2)+"v"+x+(2*S+y.height)+"H-"+(S+y.width/2)+"V"+x+M+"H-"+M+"Z")}else{var _,C,P;"right"===L.side?(_="start",C=1,P="",g=E._offset+E._length):(_="end",C=-1,P="-",g=E._offset),v=L._offset+(A.y0+A.y1)/2,l.attr("text-anchor",_),e.attr("d","M0,0L"+P+M+","+M+"V"+(S+y.height/2)+"h"+P+(2*S+y.width)+"V-"+(S+y.height/2)+"H"+P+M+"V-"+M+"Z");var O,z=y.height/2,R=D-y.top-z,F="clip"+i._uid+"commonlabel"+L._id;if(g<y.width+2*S+M){O="M-"+(M+S)+"-"+z+"h-"+(y.width-S)+"V"+z+"h"+(y.width-S)+"Z";var B=y.width-g+S;u.positionText(l,B,R),"end"===_&&l.selectAll("tspan").each((function(){var t=n.select(this),e=h.tester.append("text").text(t.text()).call(h.font,m),i=V(r,e.node());Math.round(i.width)<Math.round(y.width)&&t.attr("x",B-i.width),e.remove()}))}else u.positionText(l,C*(S+M),R),O=null;var N=i._topclips.selectAll("#"+F).data(O?[0]:[]);N.enter().append("clipPath").attr("id",F).append("path"),N.exit().remove(),N.select("path").attr("d",O),h.setClipUrl(l,O?F:null,r)}t.attr("transform",s(g,v))})),v.isUnifiedHover(a)){d.selectAll("g.hovertext").remove();var G=t.filter((function(t){return"none"!==t.hoverinfo}));if(0===G.length)return;var Y=i.hoverlabel,W=Y.font,X={showlegend:!0,legend:{title:{text:I,font:W},font:W,bgcolor:Y.bgcolor,bordercolor:Y.bordercolor,borderwidth:1,tracegroupgap:7,traceorder:i.legend?i.legend.traceorder:void 0,orientation:"v"}},Z={font:W};x(X,Z,r._fullData);var J=Z.legend;J.entries=[];for(var K=0;K<G.length;K++){var Q=G[K];if("none"!==Q.hoverinfo){var $=O(Q,!0,a,i,I),tt=$[0],et=$[1];Q.name=et,Q.text=""!==et?et+" : "+tt:tt;var rt=Q.cd[Q.index];rt&&(rt.mc&&(Q.mc=rt.mc),rt.mcc&&(Q.mc=rt.mcc),rt.mlc&&(Q.mlc=rt.mlc),rt.mlcc&&(Q.mlc=rt.mlcc),rt.mlw&&(Q.mlw=rt.mlw),rt.mrc&&(Q.mrc=rt.mrc),rt.dir&&(Q.dir=rt.dir)),Q._distinct=!0,J.entries.push([Q])}}J.entries.sort((function(t,e){return t[0].trace.index-e[0].trace.index})),J.layer=d,J._inHover=!0,J._groupTitleFont=Y.grouptitlefont,b(r,J);var nt,it,at,ot,st=d.select("g.legend"),lt=V(r,st.node()),ct=lt.width+2*S,ut=lt.height+2*S,ft=G[0],ht=(ft.x0+ft.x1)/2,pt=(ft.y0+ft.y1)/2,dt=!(g.traceIs(ft.trace,"bar-like")||g.traceIs(ft.trace,"box-violin"));"y"===P?dt?(it=pt-S,nt=pt+S):(it=Math.min.apply(null,G.map((function(t){return Math.min(t.y0,t.y1)}))),nt=Math.max.apply(null,G.map((function(t){return Math.max(t.y0,t.y1)})))):it=nt=o.mean(G.map((function(t){return(t.y0+t.y1)/2})))-ut/2,"x"===P?dt?(at=ht+S,ot=ht-S):(at=Math.max.apply(null,G.map((function(t){return Math.max(t.x0,t.x1)}))),ot=Math.min.apply(null,G.map((function(t){return Math.min(t.x0,t.x1)})))):at=ot=o.mean(G.map((function(t){return(t.x0+t.x1)/2})))-ct/2;var mt,gt,vt=E._offset,yt=L._offset;return ot+=vt-ct,it+=yt-ut,mt=(at+=vt)+ct<R&&at>=0?at:ot+ct<R&&ot>=0?ot:vt+ct<R?vt:at-ht<ht-ot+ct?R-ct:0,mt+=S,gt=(nt+=yt)+ut<F&&nt>=0?nt:it+ut<F&&it>=0?it:yt+ut<F?yt:nt-pt<pt-it+ut?F-ut:0,gt+=S,st.attr("transform",s(mt-1,gt-1)),st}var xt=d.selectAll("g.hovertext").data(t,(function(t){return C(t)}));return xt.enter().append("g").classed("hovertext",!0).each((function(){var t=n.select(this);t.append("rect").call(p.fill,p.addOpacity(f,.8)),t.append("text").classed("name",!0),t.append("path").style("stroke-width","1px"),t.append("text").classed("nums",!0).call(h.font,T,k)})),xt.exit().remove(),xt.each((function(t){var e=n.select(this).attr("transform",""),o=t.color;Array.isArray(o)&&(o=o[t.eventData[0].pointNumber]);var d=t.bgcolor||o,m=p.combine(p.opacity(d)?d:p.defaultLine,f),g=p.combine(p.opacity(o)?o:p.defaultLine,f),v=t.borderColor||p.contrast(m),y=O(t,B,a,i,I,e),x=y[0],b=y[1],w=e.select("text.nums").call(h.font,t.fontFamily||T,t.fontSize||k,t.fontColor||v).text(x).attr("data-notex",1).call(u.positionText,0,0).call(u.convertToTspans,r),A=e.select("text.name"),E=0,L=0;if(b&&b!==x){A.call(h.font,t.fontFamily||T,t.fontSize||k,g).text(b).attr("data-notex",1).call(u.positionText,0,0).call(u.convertToTspans,r);var C=V(r,A.node());E=C.width+2*S,L=C.height+2*S}else A.remove(),e.select("rect").remove();e.select("path").style({fill:m,stroke:v});var P=t.xa._offset+(t.x0+t.x1)/2,z=t.ya._offset+(t.y0+t.y1)/2,N=Math.abs(t.x1-t.x0),j=Math.abs(t.y1-t.y0),U=V(r,w.node()),H=U.width/i._invScaleX,q=U.height/i._invScaleY;t.ty0=(D-U.top)/i._invScaleY,t.bx=H+2*S,t.by=Math.max(q+2*S,L),t.anchor="start",t.txwidth=H,t.tx2width=E,t.offset=0;var G,Y,W=(H+M+S+E)*i._invScaleX;if(c)t.pos=P,G=z+j/2+W<=F,Y=z-j/2-W>=0,"top"!==t.idealAlign&&G||!Y?G?(z+=j/2,t.anchor="start"):t.anchor="middle":(z-=j/2,t.anchor="end");else if(t.pos=z,G=P+N/2+W<=R,Y=P-N/2-W>=0,"left"!==t.idealAlign&&G||!Y)if(G)P+=N/2,t.anchor="start";else{t.anchor="middle";var X=W/2,Z=P+X-R,J=P-X;Z>0&&(P-=Z),J<0&&(P+=-J)}else P-=N/2,t.anchor="end";w.attr("text-anchor",t.anchor),E&&A.attr("text-anchor",t.anchor),e.attr("transform",s(P,z)+(c?l(_):""))})),xt}function O(t,e,r,n,i,a){var s="",l="";void 0!==t.nameOverride&&(t.name=t.nameOverride),t.name&&(t.trace._meta&&(t.name=o.templateString(t.name,t.trace._meta)),s=B(t.name,t.nameLength));var c=r.charAt(0),u="x"===c?"y":"x";void 0!==t.zLabel?(void 0!==t.xLabel&&(l+="x: "+t.xLabel+"<br>"),void 0!==t.yLabel&&(l+="y: "+t.yLabel+"<br>"),"choropleth"!==t.trace.type&&"choroplethmapbox"!==t.trace.type&&(l+=(l?"z: ":"")+t.zLabel)):e&&t[c+"Label"]===i?l=t[u+"Label"]||"":void 0===t.xLabel?void 0!==t.yLabel&&"scattercarpet"!==t.trace.type&&(l=t.yLabel):l=void 0===t.yLabel?t.xLabel:"("+t.xLabel+", "+t.yLabel+")",!t.text&&0!==t.text||Array.isArray(t.text)||(l+=(l?"<br>":"")+t.text),void 0!==t.extraText&&(l+=(l?"<br>":"")+t.extraText),a&&""===l&&!t.hovertemplate&&(""===s&&a.remove(),l=s);var f=t.hovertemplate||!1;if(f){var h=t.hovertemplateLabels||t;t[c+"Label"]!==i&&(h[c+"other"]=h[c+"Val"],h[c+"otherLabel"]=h[c+"Label"]),l=(l=o.hovertemplateString(f,h,n._d3locale,t.eventData[0]||{},t.trace._meta)).replace(P,(function(e,r){return s=B(r,t.nameLength),""}))}return[l,s]}function z(t,e,r,i){var a=function(t){return t*r},o=function(t){return t*i};t.each((function(t){var r=n.select(this);if(t.del)return r.remove();var i=r.select("text.nums"),s=t.anchor,l="end"===s?-1:1,c={start:1,end:-1,middle:0}[s],f=c*(M+S),p=f+c*(t.txwidth+S),d=0,m=t.offset,g="middle"===s;g&&(f-=t.tx2width/2,p+=t.txwidth/2+S),e&&(m*=-A,d=t.offset*k),r.select("path").attr("d",g?"M-"+a(t.bx/2+t.tx2width/2)+","+o(m-t.by/2)+"h"+a(t.bx)+"v"+o(t.by)+"h-"+a(t.bx)+"Z":"M0,0L"+a(l*M+d)+","+o(M+m)+"v"+o(t.by/2-M)+"h"+a(l*t.bx)+"v-"+o(t.by)+"H"+a(l*M+d)+"V"+o(m-M)+"Z");var v=d+f,y=m+t.ty0-t.by/2+S,x=t.textAlign||"auto";"auto"!==x&&("left"===x&&"start"!==s?(i.attr("text-anchor","start"),v=g?-t.bx/2-t.tx2width/2+S:-t.bx-S):"right"===x&&"end"!==s&&(i.attr("text-anchor","end"),v=g?t.bx/2-t.tx2width/2-S:t.bx+S)),i.call(u.positionText,a(v),o(y)),t.tx2width&&(r.select("text.name").call(u.positionText,a(p+c*S+d),o(m+t.ty0-t.by/2+S)),r.select("rect").call(h.setRect,a(p+(c-1)*t.tx2width/2+d),o(m-t.by/2-1),a(t.tx2width),o(t.by+2)))}))}function D(t,e){var r=t.index,n=t.trace||{},a=t.cd[0],s=t.cd[r]||{};function l(t){return t||i(t)&&0===t}var c=Array.isArray(r)?function(t,e){var i=o.castOption(a,r,t);return l(i)?i:o.extractOption({},n,"",e)}:function(t,e){return o.extractOption(s,n,t,e)};function u(e,r,n){var i=c(r,n);l(i)&&(t[e]=i)}if(u("hoverinfo","hi","hoverinfo"),u("bgcolor","hbg","hoverlabel.bgcolor"),u("borderColor","hbc","hoverlabel.bordercolor"),u("fontFamily","htf","hoverlabel.font.family"),u("fontSize","hts","hoverlabel.font.size"),u("fontColor","htc","hoverlabel.font.color"),u("nameLength","hnl","hoverlabel.namelength"),u("textAlign","hta","hoverlabel.align"),t.posref="y"===e||"closest"===e&&"h"===n.orientation?t.xa._offset+(t.x0+t.x1)/2:t.ya._offset+(t.y0+t.y1)/2,t.x0=o.constrain(t.x0,0,t.xa._length),t.x1=o.constrain(t.x1,0,t.xa._length),t.y0=o.constrain(t.y0,0,t.ya._length),t.y1=o.constrain(t.y1,0,t.ya._length),void 0!==t.xLabelVal&&(t.xLabel="xLabel"in t?t.xLabel:m.hoverLabelText(t.xa,t.xLabelVal,n.xhoverformat),t.xVal=t.xa.c2d(t.xLabelVal)),void 0!==t.yLabelVal&&(t.yLabel="yLabel"in t?t.yLabel:m.hoverLabelText(t.ya,t.yLabelVal,n.yhoverformat),t.yVal=t.ya.c2d(t.yLabelVal)),void 0!==t.zLabelVal&&void 0===t.zLabel&&(t.zLabel=String(t.zLabelVal)),!(isNaN(t.xerr)||"log"===t.xa.type&&t.xerr<=0)){var f=m.tickText(t.xa,t.xa.c2l(t.xerr),"hover").text;void 0!==t.xerrneg?t.xLabel+=" +"+f+" / -"+m.tickText(t.xa,t.xa.c2l(t.xerrneg),"hover").text:t.xLabel+=" \xb1 "+f,"x"===e&&(t.distance+=1)}if(!(isNaN(t.yerr)||"log"===t.ya.type&&t.yerr<=0)){var h=m.tickText(t.ya,t.ya.c2l(t.yerr),"hover").text;void 0!==t.yerrneg?t.yLabel+=" +"+h+" / -"+m.tickText(t.ya,t.ya.c2l(t.yerrneg),"hover").text:t.yLabel+=" \xb1 "+h,"y"===e&&(t.distance+=1)}var p=t.hoverinfo||t.trace.hoverinfo;return p&&"all"!==p&&(-1===(p=Array.isArray(p)?p:p.split("+")).indexOf("x")&&(t.xLabel=void 0),-1===p.indexOf("y")&&(t.yLabel=void 0),-1===p.indexOf("z")&&(t.zLabel=void 0),-1===p.indexOf("text")&&(t.text=void 0),-1===p.indexOf("name")&&(t.name=void 0)),t}function R(t,e,r){var n,i,o=r.container,s=r.fullLayout,l=s._size,c=r.event,u=!!e.hLinePoint,f=!!e.vLinePoint;if(o.selectAll(".spikeline").remove(),f||u){var d=p.combine(s.plot_bgcolor,s.paper_bgcolor);if(u){var g,v,y=e.hLinePoint;n=y&&y.xa,"cursor"===(i=y&&y.ya).spikesnap?(g=c.pointerX,v=c.pointerY):(g=n._offset+y.x,v=i._offset+y.y);var x,b,_=a.readability(y.color,d)<1.5?p.contrast(d):y.color,w=i.spikemode,T=i.spikethickness,k=i.spikecolor||_,A=m.getPxPosition(t,i);if(-1!==w.indexOf("toaxis")||-1!==w.indexOf("across")){if(-1!==w.indexOf("toaxis")&&(x=A,b=g),-1!==w.indexOf("across")){var M=i._counterDomainMin,S=i._counterDomainMax;"free"===i.anchor&&(M=Math.min(M,i.position),S=Math.max(S,i.position)),x=l.l+M*l.w,b=l.l+S*l.w}o.insert("line",":first-child").attr({x1:x,x2:b,y1:v,y2:v,"stroke-width":T,stroke:k,"stroke-dasharray":h.dashStyle(i.spikedash,T)}).classed("spikeline",!0).classed("crisp",!0),o.insert("line",":first-child").attr({x1:x,x2:b,y1:v,y2:v,"stroke-width":T+2,stroke:d}).classed("spikeline",!0).classed("crisp",!0)}-1!==w.indexOf("marker")&&o.insert("circle",":first-child").attr({cx:A+("right"!==i.side?T:-T),cy:v,r:T,fill:k}).classed("spikeline",!0)}if(f){var E,L,C=e.vLinePoint;n=C&&C.xa,i=C&&C.ya,"cursor"===n.spikesnap?(E=c.pointerX,L=c.pointerY):(E=n._offset+C.x,L=i._offset+C.y);var P,I,O=a.readability(C.color,d)<1.5?p.contrast(d):C.color,z=n.spikemode,D=n.spikethickness,R=n.spikecolor||O,F=m.getPxPosition(t,n);if(-1!==z.indexOf("toaxis")||-1!==z.indexOf("across")){if(-1!==z.indexOf("toaxis")&&(P=F,I=L),-1!==z.indexOf("across")){var B=n._counterDomainMin,N=n._counterDomainMax;"free"===n.anchor&&(B=Math.min(B,n.position),N=Math.max(N,n.position)),P=l.t+(1-N)*l.h,I=l.t+(1-B)*l.h}o.insert("line",":first-child").attr({x1:E,x2:E,y1:P,y2:I,"stroke-width":D,stroke:R,"stroke-dasharray":h.dashStyle(n.spikedash,D)}).classed("spikeline",!0).classed("crisp",!0),o.insert("line",":first-child").attr({x1:E,x2:E,y1:P,y2:I,"stroke-width":D+2,stroke:d}).classed("spikeline",!0).classed("crisp",!0)}-1!==z.indexOf("marker")&&o.insert("circle",":first-child").attr({cx:E,cy:F-("top"!==n.side?D:-D),r:D,fill:R}).classed("spikeline",!0)}}}function F(t,e){return!e||(e.vLinePoint!==t._spikepoints.vLinePoint||e.hLinePoint!==t._spikepoints.hLinePoint)}function B(t,e){return u.plainText(t||"",{len:e,allowedTags:["br","sub","sup","b","i","em"]})}function N(t,e,r){var n=e[t+"a"],i=e[t+"Val"],a=e.cd[0];if("category"===n.type)i=n._categoriesMap[i];else if("date"===n.type){var o=e.trace[t+"periodalignment"];if(o){var s=e.cd[e.index],l=s[t+"Start"];void 0===l&&(l=s[t]);var c=s[t+"End"];void 0===c&&(c=s[t]);var u=c-l;"end"===o?i+=u:"middle"===o&&(i+=u/2)}i=n.d2c(i)}return a&&a.t&&a.t.posLetter===n._id&&("group"!==r.boxmode&&"group"!==r.violinmode||(i+=a.t.dPos)),i}function j(t){return t.offsetTop+t.clientTop}function U(t){return t.offsetLeft+t.clientLeft}function V(t,e){var r=t._fullLayout,n=e.getBoundingClientRect(),i=n.x,a=n.y,s=i+n.width,l=a+n.height,c=o.apply3DTransform(r._invTransform)(i,a),u=o.apply3DTransform(r._invTransform)(s,l),f=c[0],h=c[1],p=u[0],d=u[1];return{x:f,y:h,width:p-f,height:d-h,top:Math.min(h,d),left:Math.min(f,p),right:Math.max(f,p),bottom:Math.max(h,d)}}},{"../../lib":503,"../../lib/events":492,"../../lib/override_cursor":514,"../../lib/svg_text_utils":529,"../../plots/cartesian/axes":554,"../../registry":638,"../color":366,"../dragelement":385,"../drawing":388,"../legend/defaults":418,"../legend/draw":419,"./constants":400,"./helpers":402,"@plotly/d3":58,"fast-isnumeric":190,tinycolor2:312}],404:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../color"),a=t("./helpers").isUnifiedHover;e.exports=function(t,e,r,o){o=o||{};var s=e.legend;function l(t){o.font[t]||(o.font[t]=s?e.legend.font[t]:e.font[t])}e&&a(e.hovermode)&&(o.font||(o.font={}),l("size"),l("family"),l("color"),s?(o.bgcolor||(o.bgcolor=i.combine(e.legend.bgcolor,e.paper_bgcolor)),o.bordercolor||(o.bordercolor=e.legend.bordercolor)):o.bgcolor||(o.bgcolor=e.paper_bgcolor)),r("hoverlabel.bgcolor",o.bgcolor),r("hoverlabel.bordercolor",o.bordercolor),r("hoverlabel.namelength",o.namelength),n.coerceFont(r,"hoverlabel.font",o.font),r("hoverlabel.align",o.align)}},{"../../lib":503,"../color":366,"./helpers":402}],405:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./layout_attributes");e.exports=function(t,e){function r(r,a){return void 0!==e[r]?e[r]:n.coerce(t,e,i,r,a)}return r("clickmode"),r("hovermode")}},{"../../lib":503,"./layout_attributes":407}],406:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../dragelement"),o=t("./helpers"),s=t("./layout_attributes"),l=t("./hover");e.exports={moduleType:"component",name:"fx",constants:t("./constants"),schema:{layout:s},attributes:t("./attributes"),layoutAttributes:s,supplyLayoutGlobalDefaults:t("./layout_global_defaults"),supplyDefaults:t("./defaults"),supplyLayoutDefaults:t("./layout_defaults"),calc:t("./calc"),getDistanceFunction:o.getDistanceFunction,getClosest:o.getClosest,inbox:o.inbox,quadrature:o.quadrature,appendArrayPointValue:o.appendArrayPointValue,castHoverOption:function(t,e,r){return i.castOption(t,e,"hoverlabel."+r)},castHoverinfo:function(t,e,r){return i.castOption(t,r,"hoverinfo",(function(r){return i.coerceHoverinfo({hoverinfo:r},{_module:t._module},e)}))},hover:l.hover,unhover:a.unhover,loneHover:l.loneHover,loneUnhover:function(t){var e=i.isD3Selection(t)?t:n.select(t);e.selectAll("g.hovertext").remove(),e.selectAll(".spikeline").remove()},click:t("./click")}},{"../../lib":503,"../dragelement":385,"./attributes":397,"./calc":398,"./click":399,"./constants":400,"./defaults":401,"./helpers":402,"./hover":403,"./layout_attributes":407,"./layout_defaults":408,"./layout_global_defaults":409,"@plotly/d3":58}],407:[function(t,e,r){"use strict";var n=t("./constants"),i=t("../../plots/font_attributes"),a=i({editType:"none"});a.family.dflt=n.HOVERFONT,a.size.dflt=n.HOVERFONTSIZE,e.exports={clickmode:{valType:"flaglist",flags:["event","select"],dflt:"event",editType:"plot",extras:["none"]},dragmode:{valType:"enumerated",values:["zoom","pan","select","lasso","drawclosedpath","drawopenpath","drawline","drawrect","drawcircle","orbit","turntable",!1],dflt:"zoom",editType:"modebar"},hovermode:{valType:"enumerated",values:["x","y","closest",!1,"x unified","y unified"],dflt:"closest",editType:"modebar"},hoverdistance:{valType:"integer",min:-1,dflt:20,editType:"none"},spikedistance:{valType:"integer",min:-1,dflt:-1,editType:"none"},hoverlabel:{bgcolor:{valType:"color",editType:"none"},bordercolor:{valType:"color",editType:"none"},font:a,grouptitlefont:i({editType:"none"}),align:{valType:"enumerated",values:["left","right","auto"],dflt:"auto",editType:"none"},namelength:{valType:"integer",min:-1,dflt:15,editType:"none"},editType:"none"},selectdirection:{valType:"enumerated",values:["h","v","d","any"],dflt:"any",editType:"none"}}},{"../../plots/font_attributes":585,"./constants":400}],408:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./layout_attributes"),a=t("./hovermode_defaults"),o=t("./hoverlabel_defaults");e.exports=function(t,e){function r(r,a){return n.coerce(t,e,i,r,a)}a(t,e)&&(r("hoverdistance"),r("spikedistance")),"select"===r("dragmode")&&r("selectdirection");var s=e._has("mapbox"),l=e._has("geo"),c=e._basePlotModules.length;"zoom"===e.dragmode&&((s||l)&&1===c||s&&l&&2===c)&&(e.dragmode="pan"),o(t,e,r),n.coerceFont(r,"hoverlabel.grouptitlefont",e.hoverlabel.font)}},{"../../lib":503,"./hoverlabel_defaults":404,"./hovermode_defaults":405,"./layout_attributes":407}],409:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./hoverlabel_defaults"),a=t("./layout_attributes");e.exports=function(t,e){i(t,e,(function(r,i){return n.coerce(t,e,a,r,i)}))}},{"../../lib":503,"./hoverlabel_defaults":404,"./layout_attributes":407}],410:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../lib/regex").counter,a=t("../../plots/domain").attributes,o=t("../../plots/cartesian/constants").idRegex,s=t("../../plot_api/plot_template"),l={rows:{valType:"integer",min:1,editType:"plot"},roworder:{valType:"enumerated",values:["top to bottom","bottom to top"],dflt:"top to bottom",editType:"plot"},columns:{valType:"integer",min:1,editType:"plot"},subplots:{valType:"info_array",freeLength:!0,dimensions:2,items:{valType:"enumerated",values:[i("xy").toString(),""],editType:"plot"},editType:"plot"},xaxes:{valType:"info_array",freeLength:!0,items:{valType:"enumerated",values:[o.x.toString(),""],editType:"plot"},editType:"plot"},yaxes:{valType:"info_array",freeLength:!0,items:{valType:"enumerated",values:[o.y.toString(),""],editType:"plot"},editType:"plot"},pattern:{valType:"enumerated",values:["independent","coupled"],dflt:"coupled",editType:"plot"},xgap:{valType:"number",min:0,max:1,editType:"plot"},ygap:{valType:"number",min:0,max:1,editType:"plot"},domain:a({name:"grid",editType:"plot",noGridCell:!0},{}),xside:{valType:"enumerated",values:["bottom","bottom plot","top plot","top"],dflt:"bottom plot",editType:"plot"},yside:{valType:"enumerated",values:["left","left plot","right plot","right"],dflt:"left plot",editType:"plot"},editType:"plot"};function c(t,e,r){var n=e[r+"axes"],i=Object.keys((t._splomAxes||{})[r]||{});return Array.isArray(n)?n:i.length?i:void 0}function u(t,e,r,n,i,a){var o=e(t+"gap",r),s=e("domain."+t);e(t+"side",n);for(var l=new Array(i),c=s[0],u=(s[1]-c)/(i-o),f=u*(1-o),h=0;h<i;h++){var p=c+u*h;l[a?i-1-h:h]=[p,p+f]}return l}function f(t,e,r,n,i){var a,o=new Array(r);function s(t,r){-1!==e.indexOf(r)&&void 0===n[r]?(o[t]=r,n[r]=t):o[t]=""}if(Array.isArray(t))for(a=0;a<r;a++)s(a,t[a]);else for(s(0,i),a=1;a<r;a++)s(a,i+(a+1));return o}e.exports={moduleType:"component",name:"grid",schema:{layout:{grid:l}},layoutAttributes:l,sizeDefaults:function(t,e){var r=t.grid||{},i=c(e,r,"x"),a=c(e,r,"y");if(t.grid||i||a){var o,f,h=Array.isArray(r.subplots)&&Array.isArray(r.subplots[0]),p=Array.isArray(i),d=Array.isArray(a),m=p&&i!==r.xaxes&&d&&a!==r.yaxes;h?(o=r.subplots.length,f=r.subplots[0].length):(d&&(o=a.length),p&&(f=i.length));var g=s.newContainer(e,"grid"),v=k("rows",o),y=k("columns",f);if(v*y>1){if(!h&&!p&&!d)"independent"===k("pattern")&&(h=!0);g._hasSubplotGrid=h;var x,b,_="top to bottom"===k("roworder"),w=h?.2:.1,T=h?.3:.1;m&&e._splomGridDflt&&(x=e._splomGridDflt.xside,b=e._splomGridDflt.yside),g._domains={x:u("x",k,w,x,y),y:u("y",k,T,b,v,_)}}else delete e.grid}function k(t,e){return n.coerce(r,g,l,t,e)}},contentDefaults:function(t,e){var r=e.grid;if(r&&r._domains){var n,i,a,o,s,l,u,h=t.grid||{},p=e._subplots,d=r._hasSubplotGrid,m=r.rows,g=r.columns,v="independent"===r.pattern,y=r._axisMap={};if(d){var x=h.subplots||[];l=r.subplots=new Array(m);var b=1;for(n=0;n<m;n++){var _=l[n]=new Array(g),w=x[n]||[];for(i=0;i<g;i++)if(v?(s=1===b?"xy":"x"+b+"y"+b,b++):s=w[i],_[i]="",-1!==p.cartesian.indexOf(s)){if(u=s.indexOf("y"),a=s.slice(0,u),o=s.slice(u),void 0!==y[a]&&y[a]!==i||void 0!==y[o]&&y[o]!==n)continue;_[i]=s,y[a]=i,y[o]=n}}}else{var T=c(e,h,"x"),k=c(e,h,"y");r.xaxes=f(T,p.xaxis,g,y,"x"),r.yaxes=f(k,p.yaxis,m,y,"y")}var A=r._anchors={},M="top to bottom"===r.roworder;for(var S in y){var E,L,C,P=S.charAt(0),I=r[P+"side"];if(I.length<8)A[S]="free";else if("x"===P){if("t"===I.charAt(0)===M?(E=0,L=1,C=m):(E=m-1,L=-1,C=-1),d){var O=y[S];for(n=E;n!==C;n+=L)if((s=l[n][O])&&(u=s.indexOf("y"),s.slice(0,u)===S)){A[S]=s.slice(u);break}}else for(n=E;n!==C;n+=L)if(o=r.yaxes[n],-1!==p.cartesian.indexOf(S+o)){A[S]=o;break}}else if("l"===I.charAt(0)?(E=0,L=1,C=g):(E=g-1,L=-1,C=-1),d){var z=y[S];for(n=E;n!==C;n+=L)if((s=l[z][n])&&(u=s.indexOf("y"),s.slice(u)===S)){A[S]=s.slice(0,u);break}}else for(n=E;n!==C;n+=L)if(a=r.xaxes[n],-1!==p.cartesian.indexOf(a+S)){A[S]=a;break}}}}}},{"../../lib":503,"../../lib/regex":520,"../../plot_api/plot_template":543,"../../plots/cartesian/constants":561,"../../plots/domain":584}],411:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/constants"),i=t("../../plot_api/plot_template").templatedArray;t("../../constants/axis_placeable_objects");e.exports=i("image",{visible:{valType:"boolean",dflt:!0,editType:"arraydraw"},source:{valType:"string",editType:"arraydraw"},layer:{valType:"enumerated",values:["below","above"],dflt:"above",editType:"arraydraw"},sizex:{valType:"number",dflt:0,editType:"arraydraw"},sizey:{valType:"number",dflt:0,editType:"arraydraw"},sizing:{valType:"enumerated",values:["fill","contain","stretch"],dflt:"contain",editType:"arraydraw"},opacity:{valType:"number",min:0,max:1,dflt:1,editType:"arraydraw"},x:{valType:"any",dflt:0,editType:"arraydraw"},y:{valType:"any",dflt:0,editType:"arraydraw"},xanchor:{valType:"enumerated",values:["left","center","right"],dflt:"left",editType:"arraydraw"},yanchor:{valType:"enumerated",values:["top","middle","bottom"],dflt:"top",editType:"arraydraw"},xref:{valType:"enumerated",values:["paper",n.idRegex.x.toString()],dflt:"paper",editType:"arraydraw"},yref:{valType:"enumerated",values:["paper",n.idRegex.y.toString()],dflt:"paper",editType:"arraydraw"},editType:"arraydraw"})},{"../../constants/axis_placeable_objects":472,"../../plot_api/plot_template":543,"../../plots/cartesian/constants":561}],412:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib/to_log_range");e.exports=function(t,e,r,a){e=e||{};var o="log"===r&&"linear"===e.type,s="linear"===r&&"log"===e.type;if(o||s)for(var l,c,u=t._fullLayout.images,f=e._id.charAt(0),h=0;h<u.length;h++)if(c="images["+h+"].",(l=u[h])[f+"ref"]===e._id){var p=l[f],d=l["size"+f],m=null,g=null;if(o){m=i(p,e.range);var v=d/Math.pow(10,m)/2;g=2*Math.log(v+Math.sqrt(1+v*v))/Math.LN10}else g=(m=Math.pow(10,p))*(Math.pow(10,d/2)-Math.pow(10,-d/2));n(m)?n(g)||(g=null):(m=null,g=null),a(c+f,m),a(c+"size"+f,g)}}},{"../../lib/to_log_range":531,"fast-isnumeric":190}],413:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axes"),a=t("../../plots/array_container_defaults"),o=t("./attributes");function s(t,e,r){function a(r,i){return n.coerce(t,e,o,r,i)}var s=a("source");if(!a("visible",!!s))return e;a("layer"),a("xanchor"),a("yanchor"),a("sizex"),a("sizey"),a("sizing"),a("opacity");for(var l={_fullLayout:r},c=["x","y"],u=0;u<2;u++){var f=c[u],h=i.coerceRef(t,e,l,f,"paper",void 0);if("paper"!==h)i.getFromId(l,h)._imgIndices.push(e._index);i.coercePosition(e,l,a,h,f,0)}return e}e.exports=function(t,e){a(t,e,{name:"images",handleItemDefaults:s})}},{"../../lib":503,"../../plots/array_container_defaults":549,"../../plots/cartesian/axes":554,"./attributes":411}],414:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../drawing"),a=t("../../plots/cartesian/axes"),o=t("../../plots/cartesian/axis_ids"),s=t("../../constants/xmlns_namespaces");e.exports=function(t){var e,r,l=t._fullLayout,c=[],u={},f=[];for(r=0;r<l.images.length;r++){var h=l.images[r];if(h.visible)if("below"===h.layer&&"paper"!==h.xref&&"paper"!==h.yref){e=o.ref2id(h.xref)+o.ref2id(h.yref);var p=l._plots[e];if(!p){f.push(h);continue}p.mainplot&&(e=p.mainplot.id),u[e]||(u[e]=[]),u[e].push(h)}else"above"===h.layer?c.push(h):f.push(h)}var d={left:{sizing:"xMin",offset:0},center:{sizing:"xMid",offset:-.5},right:{sizing:"xMax",offset:-1}},m={top:{sizing:"YMin",offset:0},middle:{sizing:"YMid",offset:-.5},bottom:{sizing:"YMax",offset:-1}};function g(e){var r=n.select(this);if(this._imgSrc!==e.source)if(r.attr("xmlns",s.svg),e.source&&"data:"===e.source.slice(0,5))r.attr("xlink:href",e.source),this._imgSrc=e.source;else{var i=new Promise(function(t){var n=new Image;function i(){r.remove(),t()}this.img=n,n.setAttribute("crossOrigin","anonymous"),n.onerror=i,n.onload=function(){var e=document.createElement("canvas");e.width=this.width,e.height=this.height,e.getContext("2d",{willReadFrequently:!0}).drawImage(this,0,0);var n=e.toDataURL("image/png");r.attr("xlink:href",n),t()},r.on("error",i),n.src=e.source,this._imgSrc=e.source}.bind(this));t._promises.push(i)}}function v(e){var r,o,s=n.select(this),c=a.getFromId(t,e.xref),u=a.getFromId(t,e.yref),f="domain"===a.getRefType(e.xref),h="domain"===a.getRefType(e.yref),p=l._size;r=void 0!==c?"string"==typeof e.xref&&f?c._length*e.sizex:Math.abs(c.l2p(e.sizex)-c.l2p(0)):e.sizex*p.w,o=void 0!==u?"string"==typeof e.yref&&h?u._length*e.sizey:Math.abs(u.l2p(e.sizey)-u.l2p(0)):e.sizey*p.h;var g,v,y=r*d[e.xanchor].offset,x=o*m[e.yanchor].offset,b=d[e.xanchor].sizing+m[e.yanchor].sizing;switch(g=void 0!==c?"string"==typeof e.xref&&f?c._length*e.x+c._offset:c.r2p(e.x)+c._offset:e.x*p.w+p.l,g+=y,v=void 0!==u?"string"==typeof e.yref&&h?u._length*(1-e.y)+u._offset:u.r2p(e.y)+u._offset:p.h-e.y*p.h+p.t,v+=x,e.sizing){case"fill":b+=" slice";break;case"stretch":b="none"}s.attr({x:g,y:v,width:r,height:o,preserveAspectRatio:b,opacity:e.opacity});var _=(c&&"domain"!==a.getRefType(e.xref)?c._id:"")+(u&&"domain"!==a.getRefType(e.yref)?u._id:"");i.setClipUrl(s,_?"clip"+l._uid+_:null,t)}var y=l._imageLowerLayer.selectAll("image").data(f),x=l._imageUpperLayer.selectAll("image").data(c);y.enter().append("image"),x.enter().append("image"),y.exit().remove(),x.exit().remove(),y.each((function(t){g.bind(this)(t),v.bind(this)(t)})),x.each((function(t){g.bind(this)(t),v.bind(this)(t)}));var b=Object.keys(l._plots);for(r=0;r<b.length;r++){e=b[r];var _=l._plots[e];if(_.imagelayer){var w=_.imagelayer.selectAll("image").data(u[e]||[]);w.enter().append("image"),w.exit().remove(),w.each((function(t){g.bind(this)(t),v.bind(this)(t)}))}}}},{"../../constants/xmlns_namespaces":480,"../../plots/cartesian/axes":554,"../../plots/cartesian/axis_ids":558,"../drawing":388,"@plotly/d3":58}],415:[function(t,e,r){"use strict";e.exports={moduleType:"component",name:"images",layoutAttributes:t("./attributes"),supplyLayoutDefaults:t("./defaults"),includeBasePlot:t("../../plots/cartesian/include_components")("images"),draw:t("./draw"),convertCoords:t("./convert_coords")}},{"../../plots/cartesian/include_components":567,"./attributes":411,"./convert_coords":412,"./defaults":413,"./draw":414}],416:[function(t,e,r){"use strict";var n=t("../../plots/font_attributes"),i=t("../color/attributes");e.exports={bgcolor:{valType:"color",editType:"legend"},bordercolor:{valType:"color",dflt:i.defaultLine,editType:"legend"},borderwidth:{valType:"number",min:0,dflt:0,editType:"legend"},font:n({editType:"legend"}),grouptitlefont:n({editType:"legend"}),orientation:{valType:"enumerated",values:["v","h"],dflt:"v",editType:"legend"},traceorder:{valType:"flaglist",flags:["reversed","grouped"],extras:["normal"],editType:"legend"},tracegroupgap:{valType:"number",min:0,dflt:10,editType:"legend"},itemsizing:{valType:"enumerated",values:["trace","constant"],dflt:"trace",editType:"legend"},itemwidth:{valType:"number",min:30,dflt:30,editType:"legend"},itemclick:{valType:"enumerated",values:["toggle","toggleothers",!1],dflt:"toggle",editType:"legend"},itemdoubleclick:{valType:"enumerated",values:["toggle","toggleothers",!1],dflt:"toggleothers",editType:"legend"},groupclick:{valType:"enumerated",values:["toggleitem","togglegroup"],dflt:"togglegroup",editType:"legend"},x:{valType:"number",min:-2,max:3,editType:"legend"},xanchor:{valType:"enumerated",values:["auto","left","center","right"],dflt:"left",editType:"legend"},y:{valType:"number",min:-2,max:3,editType:"legend"},yanchor:{valType:"enumerated",values:["auto","top","middle","bottom"],editType:"legend"},uirevision:{valType:"any",editType:"none"},valign:{valType:"enumerated",values:["top","middle","bottom"],dflt:"middle",editType:"legend"},title:{text:{valType:"string",dflt:"",editType:"legend"},font:n({editType:"legend"}),side:{valType:"enumerated",values:["top","left","top left"],editType:"legend"},editType:"legend"},editType:"legend"}},{"../../plots/font_attributes":585,"../color/attributes":365}],417:[function(t,e,r){"use strict";e.exports={scrollBarWidth:6,scrollBarMinHeight:20,scrollBarColor:"#808BA4",scrollBarMargin:4,scrollBarEnterAttrs:{rx:20,ry:3,width:0,height:0},titlePad:2,itemGap:5}},{}],418:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib"),a=t("../../plot_api/plot_template"),o=t("../../plots/attributes"),s=t("./attributes"),l=t("../../plots/layout_attributes"),c=t("./helpers");e.exports=function(t,e,r){var u,f=t.legend||{},h=a.newContainer(e,"legend");function p(t,e){return i.coerce(f,h,s,t,e)}for(var d=function(t,e){var r=u._input,n=u;return i.coerce(r,n,o,t,e)},m=e.font||{},g=i.coerceFont(p,"grouptitlefont",i.extendFlat({},m,{size:Math.round(1.1*m.size)})),v=0,y=!1,x="normal",b=0;b<r.length;b++)(u=r[b]).visible&&((u.showlegend||u._dfltShowLegend&&!(u._module&&u._module.attributes&&u._module.attributes.showlegend&&!1===u._module.attributes.showlegend.dflt))&&(v++,u.showlegend&&(y=!0,(n.traceIs(u,"pie-like")||!0===u._input.showlegend)&&v++),i.coerceFont(d,"legendgrouptitle.font",g)),(n.traceIs(u,"bar")&&"stack"===e.barmode||-1!==["tonextx","tonexty"].indexOf(u.fill))&&(x=c.isGrouped({traceorder:x})?"grouped+reversed":"reversed"),void 0!==u.legendgroup&&""!==u.legendgroup&&(x=c.isReversed({traceorder:x})?"reversed+grouped":"grouped"));var _=i.coerce(t,e,l,"showlegend",y&&v>1);if(!1===_&&(e.legend=void 0),(!1!==_||f.uirevision)&&(p("uirevision",e.uirevision),!1!==_)){p("bgcolor",e.paper_bgcolor),p("bordercolor"),p("borderwidth");var w,T,k,A=i.coerceFont(p,"font",e.font),M="h"===p("orientation");if(M?(w=0,n.getComponentMethod("rangeslider","isVisible")(t.xaxis)?(T=1.1,k="bottom"):(T=-.1,k="top")):(w=1.02,T=1,k="auto"),p("traceorder",x),c.isGrouped(e.legend)&&p("tracegroupgap"),p("itemsizing"),p("itemwidth"),p("itemclick"),p("itemdoubleclick"),p("groupclick"),p("x",w),p("xanchor"),p("y",T),p("yanchor",k),p("valign"),i.noneOrAll(f,h,["x","y"]),p("title.text")){p("title.side",M?"left":"top");var S=i.extendFlat({},A,{size:i.bigFont(A.size)});i.coerceFont(p,"title.font",S)}}}},{"../../lib":503,"../../plot_api/plot_template":543,"../../plots/attributes":550,"../../plots/layout_attributes":610,"../../registry":638,"./attributes":416,"./helpers":422}],419:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../../plots/plots"),o=t("../../registry"),s=t("../../lib/events"),l=t("../dragelement"),c=t("../drawing"),u=t("../color"),f=t("../../lib/svg_text_utils"),h=t("./handle_click"),p=t("./constants"),d=t("../../constants/alignment"),m=d.LINE_SPACING,g=d.FROM_TL,v=d.FROM_BR,y=t("./get_legend_data"),x=t("./style"),b=t("./helpers");function _(t,e,r,n,i){var a=r.data()[0][0].trace,l={event:i,node:r.node(),curveNumber:a.index,expandedIndex:a._expandedIndex,data:t.data,layout:t.layout,frames:t._transitionData._frames,config:t._context,fullData:t._fullData,fullLayout:t._fullLayout};if(a._group&&(l.group=a._group),o.traceIs(a,"pie-like")&&(l.label=r.datum()[0].label),!1!==s.triggerHandler(t,"plotly_legendclick",l))if(1===n)e._clickTimeout=setTimeout((function(){t._fullLayout&&h(r,t,n)}),t._context.doubleClickDelay);else if(2===n){e._clickTimeout&&clearTimeout(e._clickTimeout),t._legendMouseDownTime=0,!1!==s.triggerHandler(t,"plotly_legenddoubleclick",l)&&h(r,t,n)}}function w(t,e,r){var n,a,s=t.data()[0][0],l=s.trace,u=o.traceIs(l,"pie-like"),h=!r._inHover&&e._context.edits.legendText&&!u,d=r._maxNameLength;s.groupTitle?(n=s.groupTitle.text,a=s.groupTitle.font):(a=r.font,r.entries?n=s.text:(n=u?s.label:l.name,l._meta&&(n=i.templateString(n,l._meta))));var m=i.ensureSingle(t,"text","legendtext");m.attr("text-anchor","start").call(c.font,a).text(h?T(n,d):n);var g=r.itemwidth+2*p.itemGap;f.positionText(m,g,0),h?m.call(f.makeEditable,{gd:e,text:n}).call(A,t,e,r).on("edit",(function(n){this.text(T(n,d)).call(A,t,e,r);var a=s.trace._fullInput||{},c={};if(o.hasTransform(a,"groupby")){var u=o.getTransformIndices(a,"groupby"),f=u[u.length-1],h=i.keyedContainer(a,"transforms["+f+"].styles","target","value.name");h.set(s.trace._group,n),c=h.constructUpdate()}else c.name=n;return o.call("_guiRestyle",e,c,l.index)})):A(m,t,e,r)}function T(t,e){var r=Math.max(4,e);if(t&&t.trim().length>=r/2)return t;for(var n=r-(t=t||"").length;n>0;n--)t+=" ";return t}function k(t,e){var r,a=e._context.doubleClickDelay,o=1,s=i.ensureSingle(t,"rect","legendtoggle",(function(t){e._context.staticPlot||t.style("cursor","pointer").attr("pointer-events","all"),t.call(u.fill,"rgba(0,0,0,0)")}));e._context.staticPlot||(s.on("mousedown",(function(){(r=(new Date).getTime())-e._legendMouseDownTime<a?o+=1:(o=1,e._legendMouseDownTime=r)})),s.on("mouseup",(function(){if(!e._dragged&&!e._editing){var r=e._fullLayout.legend;(new Date).getTime()-e._legendMouseDownTime>a&&(o=Math.max(o-1,1)),_(e,r,t,o,n.event)}})))}function A(t,e,r,n,i){n._inHover&&t.attr("data-notex",!0),f.convertToTspans(t,r,(function(){!function(t,e,r,n){var i=t.data()[0][0];if(!r._inHover&&i&&!i.trace.showlegend)return void t.remove();var a=t.select("g[class*=math-group]"),o=a.node();r||(r=e._fullLayout.legend);var s,l=r.borderwidth;s=1===n?r.title.font:i.groupTitle?i.groupTitle.font:r.font;var u,h,d=s.size*m;if(o){var g=c.bBox(o);u=g.height,h=g.width,1===n?c.setTranslate(a,l,l+.75*u):c.setTranslate(a,0,.25*u)}else{var v=t.select(1===n?".legendtitletext":".legendtext"),y=f.lineCount(v),x=v.node();if(u=d*y,h=x?c.bBox(x).width:0,1===n)"left"===r.title.side&&(h+=2*p.itemGap),f.positionText(v,l+p.titlePad,l+d);else{var b=2*p.itemGap+r.itemwidth;i.groupTitle&&(b=p.itemGap,h-=r.itemwidth),f.positionText(v,b,-d*((y-1)/2-.3))}}1===n?(r._titleWidth=h,r._titleHeight=u):(i.lineHeight=d,i.height=Math.max(u,16)+3,i.width=h)}(e,r,n,i)}))}function M(t){return i.isRightAnchor(t)?"right":i.isCenterAnchor(t)?"center":"left"}function S(t){return i.isBottomAnchor(t)?"bottom":i.isMiddleAnchor(t)?"middle":"top"}e.exports=function(t,e){return e||(e=t._fullLayout.legend||{}),function(t,e){var r,s,f=t._fullLayout,h="legend"+f._uid,d=e._inHover;d?(r=e.layer,h+="-hover"):r=f._infolayer;if(!r)return;t._legendMouseDownTime||(t._legendMouseDownTime=0);if(d){if(!e.entries)return;s=y(e.entries,e)}else{if(!t.calcdata)return;s=f.showlegend&&y(t.calcdata,e)}var m=f.hiddenlabels||[];if(!(d||f.showlegend&&s.length))return r.selectAll(".legend").remove(),f._topdefs.select("#"+h).remove(),a.autoMargin(t,"legend");var T=i.ensureSingle(r,"g","legend",(function(t){d||t.attr("pointer-events","all")})),E=i.ensureSingleById(f._topdefs,"clipPath",h,(function(t){t.append("rect")})),L=i.ensureSingle(T,"rect","bg",(function(t){t.attr("shape-rendering","crispEdges")}));L.call(u.stroke,e.bordercolor).call(u.fill,e.bgcolor).style("stroke-width",e.borderwidth+"px");var C=i.ensureSingle(T,"g","scrollbox"),P=e.title;if(e._titleWidth=0,e._titleHeight=0,P.text){var I=i.ensureSingle(C,"text","legendtitletext");I.attr("text-anchor","start").call(c.font,P.font).text(P.text),A(I,C,t,e,1)}else C.selectAll(".legendtitletext").remove();var O=i.ensureSingle(T,"rect","scrollbar",(function(t){t.attr(p.scrollBarEnterAttrs).call(u.fill,p.scrollBarColor)})),z=C.selectAll("g.groups").data(s);z.enter().append("g").attr("class","groups"),z.exit().remove();var D=z.selectAll("g.traces").data(i.identity);D.enter().append("g").attr("class","traces"),D.exit().remove(),D.style("opacity",(function(t){var e=t[0].trace;return o.traceIs(e,"pie-like")?-1!==m.indexOf(t[0].label)?.5:1:"legendonly"===e.visible?.5:1})).each((function(){n.select(this).call(w,t,e)})).call(x,t,e).each((function(){d||n.select(this).call(k,t)})),i.syncOrAsync([a.previousPromises,function(){return function(t,e,r,i){var a=t._fullLayout;i||(i=a.legend);var o=a._size,s=b.isVertical(i),l=b.isGrouped(i),u=i.borderwidth,f=2*u,h=p.itemGap,d=i.itemwidth+2*h,m=2*(u+h),g=S(i),v=i.y<0||0===i.y&&"top"===g,y=i.y>1||1===i.y&&"bottom"===g,x=i.tracegroupgap;i._maxHeight=Math.max(v||y?a.height/2:o.h,30);var _=0;i._width=0,i._height=0;var w=function(t){var e=0,r=0,n=t.title.side;n&&(-1!==n.indexOf("left")&&(e=t._titleWidth),-1!==n.indexOf("top")&&(r=t._titleHeight));return[e,r]}(i);if(s)r.each((function(t){var e=t[0].height;c.setTranslate(this,u+w[0],u+w[1]+i._height+e/2+h),i._height+=e,i._width=Math.max(i._width,t[0].width)})),_=d+i._width,i._width+=h+d+f,i._height+=m,l&&(e.each((function(t,e){c.setTranslate(this,0,e*i.tracegroupgap)})),i._height+=(i._lgroupsLength-1)*i.tracegroupgap);else{var T=M(i),k=i.x<0||0===i.x&&"right"===T,A=i.x>1||1===i.x&&"left"===T,E=y||v,L=a.width/2;i._maxWidth=Math.max(k?E&&"left"===T?o.l+o.w:L:A?E&&"right"===T?o.r+o.w:L:o.w,2*d);var C=0,P=0;r.each((function(t){var e=t[0].width+d;C=Math.max(C,e),P+=e})),_=null;var I=0;if(l){var O=0,z=0,D=0;e.each((function(){var t=0,e=0;n.select(this).selectAll("g.traces").each((function(r){var n=r[0].width,i=r[0].height;c.setTranslate(this,w[0],w[1]+u+h+i/2+e),e+=i,t=Math.max(t,d+n)}));var r=t+h;z>0&&r+u+z>i._maxWidth?(I=Math.max(I,z),z=0,D+=O+x,O=e):O=Math.max(O,e),c.setTranslate(this,z,D),z+=r})),i._width=Math.max(I,z)+u,i._height=D+O+m}else{var R=r.size(),F=P+f+(R-1)*h<i._maxWidth,B=0,N=0,j=0,U=0;r.each((function(t){var e=t[0].height,r=d+t[0].width,n=(F?r:C)+h;n+u+N-h>=i._maxWidth&&(I=Math.max(I,U),N=0,j+=B,i._height+=B,B=0),c.setTranslate(this,w[0]+u+N,w[1]+u+j+e/2+h),U=N+r+h,N+=n,B=Math.max(B,e)})),F?(i._width=N+f,i._height=B+m):(i._width=Math.max(I,U)+f,i._height+=B+m)}}i._width=Math.ceil(Math.max(i._width+w[0],i._titleWidth+2*(u+p.titlePad))),i._height=Math.ceil(Math.max(i._height+w[1],i._titleHeight+2*(u+p.itemGap))),i._effHeight=Math.min(i._height,i._maxHeight);var V=t._context.edits,H=V.legendText||V.legendPosition;r.each((function(t){var e=n.select(this).select(".legendtoggle"),r=t[0].height,i=H?d:_||d+t[0].width;s||(i+=h/2),c.setRect(e,0,-r/2,i,r)}))}(t,z,D,e)},function(){var s,u,m,y,x=f._size,b=e.borderwidth;if(!d){if(function(t){var e=t._fullLayout.legend,r=M(e),n=S(e);return a.autoMargin(t,"legend",{x:e.x,y:e.y,l:e._width*g[r],r:e._width*v[r],b:e._effHeight*v[n],t:e._effHeight*g[n]})}(t))return;var w=x.l+x.w*e.x-g[M(e)]*e._width,k=x.t+x.h*(1-e.y)-g[S(e)]*e._effHeight;if(f.margin.autoexpand){var A=w,P=k;w=i.constrain(w,0,f.width-e._width),k=i.constrain(k,0,f.height-e._effHeight),w!==A&&i.log("Constrain legend.x to make legend fit inside graph"),k!==P&&i.log("Constrain legend.y to make legend fit inside graph")}c.setTranslate(T,w,k)}if(O.on(".drag",null),T.on("wheel",null),d||e._height<=e._maxHeight||t._context.staticPlot){var I=e._effHeight;d&&(I=e._height),L.attr({width:e._width-b,height:I-b,x:b/2,y:b/2}),c.setTranslate(C,0,0),E.select("rect").attr({width:e._width-2*b,height:I-2*b,x:b,y:b}),c.setClipUrl(C,h,t),c.setRect(O,0,0,0,0),delete e._scrollY}else{var z,D,R,F=Math.max(p.scrollBarMinHeight,e._effHeight*e._effHeight/e._height),B=e._effHeight-F-2*p.scrollBarMargin,N=e._height-e._effHeight,j=B/N,U=Math.min(e._scrollY||0,N);L.attr({width:e._width-2*b+p.scrollBarWidth+p.scrollBarMargin,height:e._effHeight-b,x:b/2,y:b/2}),E.select("rect").attr({width:e._width-2*b+p.scrollBarWidth+p.scrollBarMargin,height:e._effHeight-2*b,x:b,y:b+U}),c.setClipUrl(C,h,t),q(U,F,j),T.on("wheel",(function(){q(U=i.constrain(e._scrollY+n.event.deltaY/B*N,0,N),F,j),0!==U&&U!==N&&n.event.preventDefault()}));var V=n.behavior.drag().on("dragstart",(function(){var t=n.event.sourceEvent;z="touchstart"===t.type?t.changedTouches[0].clientY:t.clientY,R=U})).on("drag",(function(){var t=n.event.sourceEvent;2===t.buttons||t.ctrlKey||(D="touchmove"===t.type?t.changedTouches[0].clientY:t.clientY,q(U=function(t,e,r){var n=(r-e)/j+t;return i.constrain(n,0,N)}(R,z,D),F,j))}));O.call(V);var H=n.behavior.drag().on("dragstart",(function(){var t=n.event.sourceEvent;"touchstart"===t.type&&(z=t.changedTouches[0].clientY,R=U)})).on("drag",(function(){var t=n.event.sourceEvent;"touchmove"===t.type&&(D=t.changedTouches[0].clientY,q(U=function(t,e,r){var n=(e-r)/j+t;return i.constrain(n,0,N)}(R,z,D),F,j))}));C.call(H)}function q(r,n,i){e._scrollY=t._fullLayout.legend._scrollY=r,c.setTranslate(C,0,-r),c.setRect(O,e._width,p.scrollBarMargin+r*i,p.scrollBarWidth,n),E.select("rect").attr("y",b+r)}t._context.edits.legendPosition&&(T.classed("cursor-move",!0),l.init({element:T.node(),gd:t,prepFn:function(){var t=c.getTranslate(T);m=t.x,y=t.y},moveFn:function(t,r){var n=m+t,i=y+r;c.setTranslate(T,n,i),s=l.align(n,0,x.l,x.l+x.w,e.xanchor),u=l.align(i,0,x.t+x.h,x.t,e.yanchor)},doneFn:function(){void 0!==s&&void 0!==u&&o.call("_guiRelayout",t,{"legend.x":s,"legend.y":u})},clickFn:function(e,n){var i=r.selectAll("g.traces").filter((function(){var t=this.getBoundingClientRect();return n.clientX>=t.left&&n.clientX<=t.right&&n.clientY>=t.top&&n.clientY<=t.bottom}));i.size()>0&&_(t,T,i,e,n)}}))}],t)}(t,e)}},{"../../constants/alignment":471,"../../lib":503,"../../lib/events":492,"../../lib/svg_text_utils":529,"../../plots/plots":619,"../../registry":638,"../color":366,"../dragelement":385,"../drawing":388,"./constants":417,"./get_legend_data":420,"./handle_click":421,"./helpers":422,"./style":424,"@plotly/d3":58}],420:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("./helpers");e.exports=function(t,e){var r,a,o=e._inHover,s=i.isGrouped(e),l=i.isReversed(e),c={},u=[],f=!1,h={},p=0,d=0;function m(t,r){if(""!==t&&i.isGrouped(e))-1===u.indexOf(t)?(u.push(t),f=!0,c[t]=[r]):c[t].push(r);else{var n="~~i"+p;u.push(n),c[n]=[r],p++}}for(r=0;r<t.length;r++){var g=t[r],v=g[0],y=v.trace,x=y.legendgroup;if(o||y.visible&&y.showlegend)if(n.traceIs(y,"pie-like"))for(h[x]||(h[x]={}),a=0;a<g.length;a++){var b=g[a].label;h[x][b]||(m(x,{label:b,color:g[a].color,i:g[a].i,trace:y,pts:g[a].pts}),h[x][b]=!0,d=Math.max(d,(b||"").length))}else m(x,v),d=Math.max(d,(y.name||"").length)}if(!u.length)return[];var _=!f||!s,w=[];for(r=0;r<u.length;r++){var T=c[u[r]];_?w.push(T[0]):w.push(T)}for(_&&(w=[w]),r=0;r<w.length;r++){var k=1/0;for(a=0;a<w[r].length;a++){var A=w[r][a].trace.legendrank;k>A&&(k=A)}w[r][0]._groupMinRank=k,w[r][0]._preGroupSort=r}var M=function(t,e){return t.trace.legendrank-e.trace.legendrank||t._preSort-e._preSort};for(w.forEach((function(t,e){t[0]._preGroupSort=e})),w.sort((function(t,e){return t[0]._groupMinRank-e[0]._groupMinRank||t[0]._preGroupSort-e[0]._preGroupSort})),r=0;r<w.length;r++){w[r].forEach((function(t,e){t._preSort=e})),w[r].sort(M);var S=w[r][0].trace,E=null;for(a=0;a<w[r].length;a++){var L=w[r][a].trace.legendgrouptitle;if(L&&L.text){E=L,o&&(L.font=e._groupTitleFont);break}}if(l&&w[r].reverse(),E){var C=!1;for(a=0;a<w[r].length;a++)if(n.traceIs(w[r][a].trace,"pie-like")){C=!0;break}w[r].unshift({i:-1,groupTitle:E,noClick:C,trace:{showlegend:S.showlegend,legendgroup:S.legendgroup,visible:"toggleitem"===e.groupclick||S.visible}})}for(a=0;a<w[r].length;a++)w[r][a]=[w[r][a]]}return e._lgroupsLength=w.length,e._maxNameLength=d,w}},{"../../registry":638,"./helpers":422}],421:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../registry"),a=!0;e.exports=function(t,e,r){var o=e._fullLayout;if(!e._dragged&&!e._editing){var s,l=o.legend.itemclick,c=o.legend.itemdoubleclick,u=o.legend.groupclick;if(1===r&&"toggle"===l&&"toggleothers"===c&&a&&e.data&&e._context.showTips?(n.notifier(n._(e,"Double-click on legend to isolate one trace"),"long"),a=!1):a=!1,1===r?s=l:2===r&&(s=c),s){var f="togglegroup"===u,h=o.hiddenlabels?o.hiddenlabels.slice():[],p=t.data()[0][0];if(!p.groupTitle||!p.noClick){var d,m,g,v,y,x=e._fullData,b=p.trace,_=b.legendgroup,w={},T=[],k=[],A=[];if(i.traceIs(b,"pie-like")){var M=p.label,S=h.indexOf(M);"toggle"===s?-1===S?h.push(M):h.splice(S,1):"toggleothers"===s&&(h=[],e.calcdata[0].forEach((function(t){M!==t.label&&h.push(t.label)})),e._fullLayout.hiddenlabels&&e._fullLayout.hiddenlabels.length===h.length&&-1===S&&(h=[])),i.call("_guiRelayout",e,"hiddenlabels",h)}else{var E,L=_&&_.length,C=[];if(L)for(d=0;d<x.length;d++)(E=x[d]).visible&&E.legendgroup===_&&C.push(d);if("toggle"===s){var P;switch(b.visible){case!0:P="legendonly";break;case!1:P=!1;break;case"legendonly":P=!0}if(L)if(f)for(d=0;d<x.length;d++)!1!==x[d].visible&&x[d].legendgroup===_&&j(x[d],P);else j(b,P);else j(b,P)}else if("toggleothers"===s){var I,O,z,D,R=!0;for(d=0;d<x.length;d++)if(I=x[d]===b,z=!0!==x[d].showlegend,!(I||z||(O=L&&x[d].legendgroup===_)||!0!==x[d].visible||i.traceIs(x[d],"notLegendIsolatable"))){R=!1;break}for(d=0;d<x.length;d++)if(!1!==x[d].visible&&!i.traceIs(x[d],"notLegendIsolatable"))switch(b.visible){case"legendonly":j(x[d],!0);break;case!0:D=!!R||"legendonly",I=x[d]===b,z=!0!==x[d].showlegend&&!x[d].legendgroup,O=I||L&&x[d].legendgroup===_,j(x[d],!(!O&&!z)||D)}}for(d=0;d<k.length;d++)if(g=k[d]){var F=g.constructUpdate(),B=Object.keys(F);for(m=0;m<B.length;m++)v=B[m],(w[v]=w[v]||[])[A[d]]=F[v]}for(y=Object.keys(w),d=0;d<y.length;d++)for(v=y[d],m=0;m<T.length;m++)w[v].hasOwnProperty(m)||(w[v][m]=void 0);i.call("_guiRestyle",e,w,T)}}}}function N(t,e,r){var n=T.indexOf(t),i=w[e];return i||(i=w[e]=[]),-1===T.indexOf(t)&&(T.push(t),n=T.length-1),i[n]=r,n}function j(t,e){if(!p.groupTitle||f){var r=t._fullInput;if(i.hasTransform(r,"groupby")){var a=k[r.index];if(!a){var o=i.getTransformIndices(r,"groupby"),s=o[o.length-1];a=n.keyedContainer(r,"transforms["+s+"].styles","target","value.visible"),k[r.index]=a}var l=a.get(t._group);void 0===l&&(l=!0),!1!==l&&a.set(t._group,e),A[r.index]=N(r.index,"visible",!1!==r.visible)}else{var c=!1!==r.visible&&e;N(r.index,"visible",c)}}}}},{"../../lib":503,"../../registry":638}],422:[function(t,e,r){"use strict";r.isGrouped=function(t){return-1!==(t.traceorder||"").indexOf("grouped")},r.isVertical=function(t){return"h"!==t.orientation},r.isReversed=function(t){return-1!==(t.traceorder||"").indexOf("reversed")}},{}],423:[function(t,e,r){"use strict";e.exports={moduleType:"component",name:"legend",layoutAttributes:t("./attributes"),supplyLayoutDefaults:t("./defaults"),draw:t("./draw"),style:t("./style")}},{"./attributes":416,"./defaults":418,"./draw":419,"./style":424}],424:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../registry"),a=t("../../lib"),o=a.strTranslate,s=t("../drawing"),l=t("../color"),c=t("../colorscale/helpers").extractOpts,u=t("../../traces/scatter/subtypes"),f=t("../../traces/pie/style_one"),h=t("../../traces/pie/helpers").castOption,p=t("./constants");function d(t,e){return(e?"radial":"horizontal")+(t?"":"reversed")}function m(t){var e=t[0].trace,r=e.contours,n=u.hasLines(e),i=u.hasMarkers(e),a=e.visible&&e.fill&&"none"!==e.fill,o=!1,s=!1;if(r){var l=r.coloring;"lines"===l?o=!0:n="none"===l||"heatmap"===l||r.showlines,"constraint"===r.type?a="="!==r._operation:"fill"!==l&&"heatmap"!==l||(s=!0)}return{showMarker:i,showLine:n,showFill:a,showGradientLine:o,showGradientFill:s,anyLine:n||o,anyFill:a||s}}function g(t,e,r){return t&&a.isArrayOrTypedArray(t)?e:t>r?r:t}e.exports=function(t,e,r){var v=e._fullLayout;r||(r=v.legend);var y="constant"===r.itemsizing,x=r.itemwidth,b=(x+2*p.itemGap)/2,_=o(b,0),w=function(t,e,r,n){var i;if(t+1)i=t;else{if(!(e&&e.width>0))return 0;i=e.width}return y?n:Math.min(i,r)};function T(t,a,o){var u=t[0].trace,f=u.marker||{},h=f.line||{},p=o?u.visible&&u.type===o:i.traceIs(u,"bar"),d=n.select(a).select("g.legendpoints").selectAll("path.legend"+o).data(p?[t]:[]);d.enter().append("path").classed("legend"+o,!0).attr("d","M6,6H-6V-6H6Z").attr("transform",_),d.exit().remove(),d.each((function(t){var i=n.select(this),a=t[0],o=w(a.mlw,f.line,5,2);i.style("stroke-width",o+"px");var p=a.mcc;if(!r._inHover&&"mc"in a){var d=c(f),m=d.mid;void 0===m&&(m=(d.max+d.min)/2),p=s.tryColorscale(f,"")(m)}var v=p||a.mc||f.color,y=f.pattern,x=y&&s.getPatternAttr(y.shape,0,"");if(x){var b=s.getPatternAttr(y.bgcolor,0,null),_=s.getPatternAttr(y.fgcolor,0,null),T=y.fgopacity,k=g(y.size,8,10),A=g(y.solidity,.5,1),M="legend-"+u.uid;i.call(s.pattern,"legend",e,M,x,k,A,p,y.fillmode,b,_,T)}else i.call(l.fill,v);o&&l.stroke(i,a.mlc||h.color)}))}function k(t,e,r){var o=t[0],s=o.trace,l=r?s.visible&&s.type===r:i.traceIs(s,r),c=n.select(e).select("g.legendpoints").selectAll("path.legend"+r).data(l?[t]:[]);if(c.enter().append("path").classed("legend"+r,!0).attr("d","M6,6H-6V-6H6Z").attr("transform",_),c.exit().remove(),c.size()){var u=(s.marker||{}).line,p=w(h(u.width,o.pts),u,5,2),d=a.minExtend(s,{marker:{line:{width:p}}});d.marker.line.color=u.color;var m=a.minExtend(o,{trace:d});f(c,m,d)}}t.each((function(t){var e=n.select(this),i=a.ensureSingle(e,"g","layers");i.style("opacity",t[0].trace.opacity);var s=r.valign,l=t[0].lineHeight,c=t[0].height;if("middle"!==s&&l&&c){var u={top:1,bottom:-1}[s]*(.5*(l-c+3));i.attr("transform",o(0,u))}else i.attr("transform",null);i.selectAll("g.legendfill").data([t]).enter().append("g").classed("legendfill",!0),i.selectAll("g.legendlines").data([t]).enter().append("g").classed("legendlines",!0);var f=i.selectAll("g.legendsymbols").data([t]);f.enter().append("g").classed("legendsymbols",!0),f.selectAll("g.legendpoints").data([t]).enter().append("g").classed("legendpoints",!0)})).each((function(t){var r,i=t[0].trace,o=[];if(i.visible)switch(i.type){case"histogram2d":case"heatmap":o=[["M-15,-2V4H15V-2Z"]],r=!0;break;case"choropleth":case"choroplethmapbox":o=[["M-6,-6V6H6V-6Z"]],r=!0;break;case"densitymapbox":o=[["M-6,0 a6,6 0 1,0 12,0 a 6,6 0 1,0 -12,0"]],r="radial";break;case"cone":o=[["M-6,2 A2,2 0 0,0 -6,6 V6L6,4Z"],["M-6,-6 A2,2 0 0,0 -6,-2 L6,-4Z"],["M-6,-2 A2,2 0 0,0 -6,2 L6,0Z"]],r=!1;break;case"streamtube":o=[["M-6,2 A2,2 0 0,0 -6,6 H6 A2,2 0 0,1 6,2 Z"],["M-6,-6 A2,2 0 0,0 -6,-2 H6 A2,2 0 0,1 6,-6 Z"],["M-6,-2 A2,2 0 0,0 -6,2 H6 A2,2 0 0,1 6,-2 Z"]],r=!1;break;case"surface":o=[["M-6,-6 A2,3 0 0,0 -6,0 H6 A2,3 0 0,1 6,-6 Z"],["M-6,1 A2,3 0 0,1 -6,6 H6 A2,3 0 0,0 6,0 Z"]],r=!0;break;case"mesh3d":o=[["M-6,6H0L-6,-6Z"],["M6,6H0L6,-6Z"],["M-6,-6H6L0,6Z"]],r=!1;break;case"volume":o=[["M-6,6H0L-6,-6Z"],["M6,6H0L6,-6Z"],["M-6,-6H6L0,6Z"]],r=!0;break;case"isosurface":o=[["M-6,6H0L-6,-6Z"],["M6,6H0L6,-6Z"],["M-6,-6 A12,24 0 0,0 6,-6 L0,6Z"]],r=!1}var u=n.select(this).select("g.legendpoints").selectAll("path.legend3dandfriends").data(o);u.enter().append("path").classed("legend3dandfriends",!0).attr("transform",_).style("stroke-miterlimit",1),u.exit().remove(),u.each((function(t,o){var u,f=n.select(this),h=c(i),p=h.colorscale,m=h.reversescale;if(p){if(!r){var g=p.length;u=0===o?p[m?g-1:0][1]:1===o?p[m?0:g-1][1]:p[Math.floor((g-1)/2)][1]}}else{var v=i.vertexcolor||i.facecolor||i.color;u=a.isArrayOrTypedArray(v)?v[o]||v[0]:v}f.attr("d",t[0]),u?f.call(l.fill,u):f.call((function(t){if(t.size()){var n="legendfill-"+i.uid;s.gradient(t,e,n,d(m,"radial"===r),p,"fill")}}))}))})).each((function(t){var e=t[0].trace,r="waterfall"===e.type;if(t[0]._distinct&&r){var i=t[0].trace[t[0].dir].marker;return t[0].mc=i.color,t[0].mlw=i.line.width,t[0].mlc=i.line.color,T(t,this,"waterfall")}var a=[];e.visible&&r&&(a=t[0].hasTotals?[["increasing","M-6,-6V6H0Z"],["totals","M6,6H0L-6,-6H-0Z"],["decreasing","M6,6V-6H0Z"]]:[["increasing","M-6,-6V6H6Z"],["decreasing","M6,6V-6H-6Z"]]);var o=n.select(this).select("g.legendpoints").selectAll("path.legendwaterfall").data(a);o.enter().append("path").classed("legendwaterfall",!0).attr("transform",_).style("stroke-miterlimit",1),o.exit().remove(),o.each((function(t){var r=n.select(this),i=e[t[0]].marker,a=w(void 0,i.line,5,2);r.attr("d",t[1]).style("stroke-width",a+"px").call(l.fill,i.color),a&&r.call(l.stroke,i.line.color)}))})).each((function(t){T(t,this,"funnel")})).each((function(t){T(t,this)})).each((function(t){var r=t[0].trace,o=n.select(this).select("g.legendpoints").selectAll("path.legendbox").data(r.visible&&i.traceIs(r,"box-violin")?[t]:[]);o.enter().append("path").classed("legendbox",!0).attr("d","M6,6H-6V-6H6Z").attr("transform",_),o.exit().remove(),o.each((function(){var t=n.select(this);if("all"!==r.boxpoints&&"all"!==r.points||0!==l.opacity(r.fillcolor)||0!==l.opacity((r.line||{}).color)){var i=w(void 0,r.line,5,2);t.style("stroke-width",i+"px").call(l.fill,r.fillcolor),i&&l.stroke(t,r.line.color)}else{var c=a.minExtend(r,{marker:{size:y?12:a.constrain(r.marker.size,2,16),sizeref:1,sizemin:1,sizemode:"diameter"}});o.call(s.pointStyle,c,e)}}))})).each((function(t){k(t,this,"funnelarea")})).each((function(t){k(t,this,"pie")})).each((function(t){var r,i,o=m(t),l=o.showFill,f=o.showLine,h=o.showGradientLine,p=o.showGradientFill,g=o.anyFill,v=o.anyLine,y=t[0],b=y.trace,_=c(b),T=_.colorscale,k=_.reversescale,A=u.hasMarkers(b)||!g?"M5,0":v?"M5,-2":"M5,-3",M=n.select(this),S=M.select(".legendfill").selectAll("path").data(l||p?[t]:[]);if(S.enter().append("path").classed("js-fill",!0),S.exit().remove(),S.attr("d",A+"h"+x+"v6h-"+x+"z").call((function(t){if(t.size())if(l)s.fillGroupStyle(t,e);else{var r="legendfill-"+b.uid;s.gradient(t,e,r,d(k),T,"fill")}})),f||h){var E=w(void 0,b.line,10,5);i=a.minExtend(b,{line:{width:E}}),r=[a.minExtend(y,{trace:i})]}var L=M.select(".legendlines").selectAll("path").data(f||h?[r]:[]);L.enter().append("path").classed("js-line",!0),L.exit().remove(),L.attr("d",A+(h?"l"+x+",0.0001":"h"+x)).call(f?s.lineGroupStyle:function(t){if(t.size()){var r="legendline-"+b.uid;s.lineGroupStyle(t),s.gradient(t,e,r,d(k),T,"stroke")}})})).each((function(t){var r,i,o=m(t),l=o.anyFill,c=o.anyLine,f=o.showLine,h=o.showMarker,p=t[0],d=p.trace,g=!h&&!c&&!l&&u.hasText(d);function v(t,e,r,n){var i=a.nestedProperty(d,t).get(),o=a.isArrayOrTypedArray(i)&&e?e(i):i;if(y&&o&&void 0!==n&&(o=n),r){if(o<r[0])return r[0];if(o>r[1])return r[1]}return o}function x(t){return p._distinct&&p.index&&t[p.index]?t[p.index]:t[0]}if(h||g||f){var b={},w={};if(h){b.mc=v("marker.color",x),b.mx=v("marker.symbol",x),b.mo=v("marker.opacity",a.mean,[.2,1]),b.mlc=v("marker.line.color",x),b.mlw=v("marker.line.width",a.mean,[0,5],2),w.marker={sizeref:1,sizemin:1,sizemode:"diameter"};var T=v("marker.size",a.mean,[2,16],12);b.ms=T,w.marker.size=T}f&&(w.line={width:v("line.width",x,[0,10],5)}),g&&(b.tx="Aa",b.tp=v("textposition",x),b.ts=10,b.tc=v("textfont.color",x),b.tf=v("textfont.family",x)),r=[a.minExtend(p,b)],(i=a.minExtend(d,w)).selectedpoints=null,i.texttemplate=null}var k=n.select(this).select("g.legendpoints"),A=k.selectAll("path.scatterpts").data(h?r:[]);A.enter().insert("path",":first-child").classed("scatterpts",!0).attr("transform",_),A.exit().remove(),A.call(s.pointStyle,i,e),h&&(r[0].mrc=3);var M=k.selectAll("g.pointtext").data(g?r:[]);M.enter().append("g").classed("pointtext",!0).append("text").attr("transform",_),M.exit().remove(),M.selectAll("text").call(s.textPointStyle,i,e)})).each((function(t){var e=t[0].trace,r=n.select(this).select("g.legendpoints").selectAll("path.legendcandle").data(e.visible&&"candlestick"===e.type?[t,t]:[]);r.enter().append("path").classed("legendcandle",!0).attr("d",(function(t,e){return e?"M-15,0H-8M-8,6V-6H8Z":"M15,0H8M8,-6V6H-8Z"})).attr("transform",_).style("stroke-miterlimit",1),r.exit().remove(),r.each((function(t,r){var i=n.select(this),a=e[r?"increasing":"decreasing"],o=w(void 0,a.line,5,2);i.style("stroke-width",o+"px").call(l.fill,a.fillcolor),o&&l.stroke(i,a.line.color)}))})).each((function(t){var e=t[0].trace,r=n.select(this).select("g.legendpoints").selectAll("path.legendohlc").data(e.visible&&"ohlc"===e.type?[t,t]:[]);r.enter().append("path").classed("legendohlc",!0).attr("d",(function(t,e){return e?"M-15,0H0M-8,-6V0":"M15,0H0M8,6V0"})).attr("transform",_).style("stroke-miterlimit",1),r.exit().remove(),r.each((function(t,r){var i=n.select(this),a=e[r?"increasing":"decreasing"],o=w(void 0,a.line,5,2);i.style("fill","none").call(s.dashLine,a.line.dash,o),o&&l.stroke(i,a.line.color)}))}))}},{"../../lib":503,"../../registry":638,"../../traces/pie/helpers":906,"../../traces/pie/style_one":912,"../../traces/scatter/subtypes":952,"../color":366,"../colorscale/helpers":377,"../drawing":388,"./constants":417,"@plotly/d3":58}],425:[function(t,e,r){"use strict";t("./constants");e.exports={editType:"modebar",orientation:{valType:"enumerated",values:["v","h"],dflt:"h",editType:"modebar"},bgcolor:{valType:"color",editType:"modebar"},color:{valType:"color",editType:"modebar"},activecolor:{valType:"color",editType:"modebar"},uirevision:{valType:"any",editType:"none"},add:{valType:"string",arrayOk:!0,dflt:"",editType:"modebar"},remove:{valType:"string",arrayOk:!0,dflt:"",editType:"modebar"}}},{"./constants":427}],426:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../plots/plots"),a=t("../../plots/cartesian/axis_ids"),o=t("../../fonts/ploticon"),s=t("../shapes/draw").eraseActiveShape,l=t("../../lib"),c=l._,u=e.exports={};function f(t,e){var r,i,o=e.currentTarget,s=o.getAttribute("data-attr"),l=o.getAttribute("data-val")||!0,c=t._fullLayout,u={},f=a.list(t,null,!0),h=c._cartesianSpikesEnabled;if("zoom"===s){var p,d="in"===l?.5:2,m=(1+d)/2,g=(1-d)/2;for(i=0;i<f.length;i++)if(!(r=f[i]).fixedrange)if(p=r._name,"auto"===l)u[p+".autorange"]=!0;else if("reset"===l){if(void 0===r._rangeInitial)u[p+".autorange"]=!0;else{var v=r._rangeInitial.slice();u[p+".range[0]"]=v[0],u[p+".range[1]"]=v[1]}void 0!==r._showSpikeInitial&&(u[p+".showspikes"]=r._showSpikeInitial,"on"!==h||r._showSpikeInitial||(h="off"))}else{var y=[r.r2l(r.range[0]),r.r2l(r.range[1])],x=[m*y[0]+g*y[1],m*y[1]+g*y[0]];u[p+".range[0]"]=r.l2r(x[0]),u[p+".range[1]"]=r.l2r(x[1])}}else"hovermode"!==s||"x"!==l&&"y"!==l||(l=c._isHoriz?"y":"x",o.setAttribute("data-val",l)),u[s]=l;c._cartesianSpikesEnabled=h,n.call("_guiRelayout",t,u)}function h(t,e){for(var r=e.currentTarget,i=r.getAttribute("data-attr"),a=r.getAttribute("data-val")||!0,o=t._fullLayout._subplots.gl3d||[],s={},l=i.split("."),c=0;c<o.length;c++)s[o[c]+"."+l[1]]=a;var u="pan"===a?a:"zoom";s.dragmode=u,n.call("_guiRelayout",t,s)}function p(t,e){for(var r=e.currentTarget.getAttribute("data-attr"),i="resetLastSave"===r,a="resetDefault"===r,o=t._fullLayout,s=o._subplots.gl3d||[],l={},c=0;c<s.length;c++){var u,f=s[c],h=f+".camera",p=f+".aspectratio",d=f+".aspectmode",m=o[f]._scene;i?(l[h+".up"]=m.viewInitial.up,l[h+".eye"]=m.viewInitial.eye,l[h+".center"]=m.viewInitial.center,u=!0):a&&(l[h+".up"]=null,l[h+".eye"]=null,l[h+".center"]=null,u=!0),u&&(l[p+".x"]=m.viewInitial.aspectratio.x,l[p+".y"]=m.viewInitial.aspectratio.y,l[p+".z"]=m.viewInitial.aspectratio.z,l[d]=m.viewInitial.aspectmode)}n.call("_guiRelayout",t,l)}function d(t,e){var r=e.currentTarget,n=r._previousVal,i=t._fullLayout,a=i._subplots.gl3d||[],o=["xaxis","yaxis","zaxis"],s={},l={};if(n)l=n,r._previousVal=null;else{for(var c=0;c<a.length;c++){var u=a[c],f=i[u],h=u+".hovermode";s[h]=f.hovermode,l[h]=!1;for(var p=0;p<3;p++){var d=o[p],m=u+"."+d+".showspikes";l[m]=!1,s[m]=f[d].showspikes}}r._previousVal=s}return l}function m(t,e){for(var r=e.currentTarget,i=r.getAttribute("data-attr"),a=r.getAttribute("data-val")||!0,o=t._fullLayout,s=o._subplots.geo||[],l=0;l<s.length;l++){var c=s[l],u=o[c];if("zoom"===i){var f=u.projection.scale,h="in"===a?2*f:.5*f;n.call("_guiRelayout",t,c+".projection.scale",h)}}"reset"===i&&x(t,"geo")}function g(t){var e=t._fullLayout;return!e.hovermode&&(e._has("cartesian")?e._isHoriz?"y":"x":"closest")}function v(t){var e=g(t);n.call("_guiRelayout",t,"hovermode",e)}function y(t,e){for(var r=e.currentTarget.getAttribute("data-val"),i=t._fullLayout,a=i._subplots.mapbox||[],o={},s=0;s<a.length;s++){var l=a[s],c=i[l].zoom,u="in"===r?1.05*c:c/1.05;o[l+".zoom"]=u}n.call("_guiRelayout",t,o)}function x(t,e){for(var r=t._fullLayout,i=r._subplots[e]||[],a={},o=0;o<i.length;o++)for(var s=i[o],l=r[s]._subplot.viewInitial,c=Object.keys(l),u=0;u<c.length;u++){var f=c[u];a[s+"."+f]=l[f]}n.call("_guiRelayout",t,a)}u.toImage={name:"toImage",title:function(t){var e=(t._context.toImageButtonOptions||{}).format||"png";return c(t,"png"===e?"Download plot as a png":"Download plot")},icon:o.camera,click:function(t){var e=t._context.toImageButtonOptions,r={format:e.format||"png"};l.notifier(c(t,"Taking snapshot - this may take a few seconds"),"long"),"svg"!==r.format&&l.isIE()&&(l.notifier(c(t,"IE only supports svg.  Changing format to svg."),"long"),r.format="svg"),["filename","width","height","scale"].forEach((function(t){t in e&&(r[t]=e[t])})),n.call("downloadImage",t,r).then((function(e){l.notifier(c(t,"Snapshot succeeded")+" - "+e,"long")})).catch((function(){l.notifier(c(t,"Sorry, there was a problem downloading your snapshot!"),"long")}))}},u.sendDataToCloud={name:"sendDataToCloud",title:function(t){return c(t,"Edit in Chart Studio")},icon:o.disk,click:function(t){i.sendDataToCloud(t)}},u.editInChartStudio={name:"editInChartStudio",title:function(t){return c(t,"Edit in Chart Studio")},icon:o.pencil,click:function(t){i.sendDataToCloud(t)}},u.zoom2d={name:"zoom2d",_cat:"zoom",title:function(t){return c(t,"Zoom")},attr:"dragmode",val:"zoom",icon:o.zoombox,click:f},u.pan2d={name:"pan2d",_cat:"pan",title:function(t){return c(t,"Pan")},attr:"dragmode",val:"pan",icon:o.pan,click:f},u.select2d={name:"select2d",_cat:"select",title:function(t){return c(t,"Box Select")},attr:"dragmode",val:"select",icon:o.selectbox,click:f},u.lasso2d={name:"lasso2d",_cat:"lasso",title:function(t){return c(t,"Lasso Select")},attr:"dragmode",val:"lasso",icon:o.lasso,click:f},u.drawclosedpath={name:"drawclosedpath",title:function(t){return c(t,"Draw closed freeform")},attr:"dragmode",val:"drawclosedpath",icon:o.drawclosedpath,click:f},u.drawopenpath={name:"drawopenpath",title:function(t){return c(t,"Draw open freeform")},attr:"dragmode",val:"drawopenpath",icon:o.drawopenpath,click:f},u.drawline={name:"drawline",title:function(t){return c(t,"Draw line")},attr:"dragmode",val:"drawline",icon:o.drawline,click:f},u.drawrect={name:"drawrect",title:function(t){return c(t,"Draw rectangle")},attr:"dragmode",val:"drawrect",icon:o.drawrect,click:f},u.drawcircle={name:"drawcircle",title:function(t){return c(t,"Draw circle")},attr:"dragmode",val:"drawcircle",icon:o.drawcircle,click:f},u.eraseshape={name:"eraseshape",title:function(t){return c(t,"Erase active shape")},icon:o.eraseshape,click:s},u.zoomIn2d={name:"zoomIn2d",_cat:"zoomin",title:function(t){return c(t,"Zoom in")},attr:"zoom",val:"in",icon:o.zoom_plus,click:f},u.zoomOut2d={name:"zoomOut2d",_cat:"zoomout",title:function(t){return c(t,"Zoom out")},attr:"zoom",val:"out",icon:o.zoom_minus,click:f},u.autoScale2d={name:"autoScale2d",_cat:"autoscale",title:function(t){return c(t,"Autoscale")},attr:"zoom",val:"auto",icon:o.autoscale,click:f},u.resetScale2d={name:"resetScale2d",_cat:"resetscale",title:function(t){return c(t,"Reset axes")},attr:"zoom",val:"reset",icon:o.home,click:f},u.hoverClosestCartesian={name:"hoverClosestCartesian",_cat:"hoverclosest",title:function(t){return c(t,"Show closest data on hover")},attr:"hovermode",val:"closest",icon:o.tooltip_basic,gravity:"ne",click:f},u.hoverCompareCartesian={name:"hoverCompareCartesian",_cat:"hoverCompare",title:function(t){return c(t,"Compare data on hover")},attr:"hovermode",val:function(t){return t._fullLayout._isHoriz?"y":"x"},icon:o.tooltip_compare,gravity:"ne",click:f},u.zoom3d={name:"zoom3d",_cat:"zoom",title:function(t){return c(t,"Zoom")},attr:"scene.dragmode",val:"zoom",icon:o.zoombox,click:h},u.pan3d={name:"pan3d",_cat:"pan",title:function(t){return c(t,"Pan")},attr:"scene.dragmode",val:"pan",icon:o.pan,click:h},u.orbitRotation={name:"orbitRotation",title:function(t){return c(t,"Orbital rotation")},attr:"scene.dragmode",val:"orbit",icon:o["3d_rotate"],click:h},u.tableRotation={name:"tableRotation",title:function(t){return c(t,"Turntable rotation")},attr:"scene.dragmode",val:"turntable",icon:o["z-axis"],click:h},u.resetCameraDefault3d={name:"resetCameraDefault3d",_cat:"resetCameraDefault",title:function(t){return c(t,"Reset camera to default")},attr:"resetDefault",icon:o.home,click:p},u.resetCameraLastSave3d={name:"resetCameraLastSave3d",_cat:"resetCameraLastSave",title:function(t){return c(t,"Reset camera to last save")},attr:"resetLastSave",icon:o.movie,click:p},u.hoverClosest3d={name:"hoverClosest3d",_cat:"hoverclosest",title:function(t){return c(t,"Toggle show closest data on hover")},attr:"hovermode",val:null,toggle:!0,icon:o.tooltip_basic,gravity:"ne",click:function(t,e){var r=d(t,e);n.call("_guiRelayout",t,r)}},u.zoomInGeo={name:"zoomInGeo",_cat:"zoomin",title:function(t){return c(t,"Zoom in")},attr:"zoom",val:"in",icon:o.zoom_plus,click:m},u.zoomOutGeo={name:"zoomOutGeo",_cat:"zoomout",title:function(t){return c(t,"Zoom out")},attr:"zoom",val:"out",icon:o.zoom_minus,click:m},u.resetGeo={name:"resetGeo",_cat:"reset",title:function(t){return c(t,"Reset")},attr:"reset",val:null,icon:o.autoscale,click:m},u.hoverClosestGeo={name:"hoverClosestGeo",_cat:"hoverclosest",title:function(t){return c(t,"Toggle show closest data on hover")},attr:"hovermode",val:null,toggle:!0,icon:o.tooltip_basic,gravity:"ne",click:v},u.hoverClosestGl2d={name:"hoverClosestGl2d",_cat:"hoverclosest",title:function(t){return c(t,"Toggle show closest data on hover")},attr:"hovermode",val:null,toggle:!0,icon:o.tooltip_basic,gravity:"ne",click:v},u.hoverClosestPie={name:"hoverClosestPie",_cat:"hoverclosest",title:function(t){return c(t,"Toggle show closest data on hover")},attr:"hovermode",val:"closest",icon:o.tooltip_basic,gravity:"ne",click:v},u.resetViewSankey={name:"resetSankeyGroup",title:function(t){return c(t,"Reset view")},icon:o.home,click:function(t){for(var e={"node.groups":[],"node.x":[],"node.y":[]},r=0;r<t._fullData.length;r++){var i=t._fullData[r]._viewInitial;e["node.groups"].push(i.node.groups.slice()),e["node.x"].push(i.node.x.slice()),e["node.y"].push(i.node.y.slice())}n.call("restyle",t,e)}},u.toggleHover={name:"toggleHover",title:function(t){return c(t,"Toggle show closest data on hover")},attr:"hovermode",val:null,toggle:!0,icon:o.tooltip_basic,gravity:"ne",click:function(t,e){var r=d(t,e);r.hovermode=g(t),n.call("_guiRelayout",t,r)}},u.resetViews={name:"resetViews",title:function(t){return c(t,"Reset views")},icon:o.home,click:function(t,e){var r=e.currentTarget;r.setAttribute("data-attr","zoom"),r.setAttribute("data-val","reset"),f(t,e),r.setAttribute("data-attr","resetLastSave"),p(t,e),x(t,"geo"),x(t,"mapbox")}},u.toggleSpikelines={name:"toggleSpikelines",title:function(t){return c(t,"Toggle Spike Lines")},icon:o.spikeline,attr:"_cartesianSpikesEnabled",val:"on",click:function(t){var e=t._fullLayout,r=e._cartesianSpikesEnabled;e._cartesianSpikesEnabled="on"===r?"off":"on",n.call("_guiRelayout",t,function(t){for(var e="on"===t._fullLayout._cartesianSpikesEnabled,r=a.list(t,null,!0),n={},i=0;i<r.length;i++){var o=r[i];n[o._name+".showspikes"]=!!e||o._showSpikeInitial}return n}(t))}},u.resetViewMapbox={name:"resetViewMapbox",_cat:"resetView",title:function(t){return c(t,"Reset view")},attr:"reset",icon:o.home,click:function(t){x(t,"mapbox")}},u.zoomInMapbox={name:"zoomInMapbox",_cat:"zoomin",title:function(t){return c(t,"Zoom in")},attr:"zoom",val:"in",icon:o.zoom_plus,click:y},u.zoomOutMapbox={name:"zoomOutMapbox",_cat:"zoomout",title:function(t){return c(t,"Zoom out")},attr:"zoom",val:"out",icon:o.zoom_minus,click:y}},{"../../fonts/ploticon":482,"../../lib":503,"../../plots/cartesian/axis_ids":558,"../../plots/plots":619,"../../registry":638,"../shapes/draw":450}],427:[function(t,e,r){"use strict";var n=t("./buttons"),i=Object.keys(n),a=["drawline","drawopenpath","drawclosedpath","drawcircle","drawrect","eraseshape"],o=["v1hovermode","hoverclosest","hovercompare","togglehover","togglespikelines"].concat(a),s=[];i.forEach((function(t){!function(t){if(-1===o.indexOf(t._cat||t.name)){var e=t.name,r=(t._cat||t.name).toLowerCase();-1===s.indexOf(e)&&s.push(e),-1===s.indexOf(r)&&s.push(r)}}(n[t])})),s.sort(),e.exports={DRAW_MODES:a,backButtons:o,foreButtons:s}},{"./buttons":426}],428:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../color"),a=t("../../plot_api/plot_template"),o=t("./attributes");e.exports=function(t,e){var r=t.modebar||{},s=a.newContainer(e,"modebar");function l(t,e){return n.coerce(r,s,o,t,e)}l("orientation"),l("bgcolor",i.addOpacity(e.paper_bgcolor,.5));var c=i.contrast(i.rgb(e.modebar.bgcolor));l("color",i.addOpacity(c,.3)),l("activecolor",i.addOpacity(c,.7)),l("uirevision",e.uirevision),l("add"),l("remove")}},{"../../lib":503,"../../plot_api/plot_template":543,"../color":366,"./attributes":425}],429:[function(t,e,r){"use strict";e.exports={moduleType:"component",name:"modebar",layoutAttributes:t("./attributes"),supplyLayoutDefaults:t("./defaults"),manage:t("./manage")}},{"./attributes":425,"./defaults":428,"./manage":430}],430:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axis_ids"),i=t("../../traces/scatter/subtypes"),a=t("../../registry"),o=t("../fx/helpers").isUnifiedHover,s=t("./modebar"),l=t("./buttons"),c=t("./constants").DRAW_MODES,u=t("../../lib").extendDeep;e.exports=function(t){var e=t._fullLayout,r=t._context,f=e._modeBar;if(r.displayModeBar||r.watermark){if(!Array.isArray(r.modeBarButtonsToRemove))throw new Error(["*modeBarButtonsToRemove* configuration options","must be an array."].join(" "));if(!Array.isArray(r.modeBarButtonsToAdd))throw new Error(["*modeBarButtonsToAdd* configuration options","must be an array."].join(" "));var h,p=r.modeBarButtons;h=Array.isArray(p)&&p.length?function(t){for(var e=u([],t),r=0;r<e.length;r++)for(var n=e[r],i=0;i<n.length;i++){var a=n[i];if("string"==typeof a){if(void 0===l[a])throw new Error(["*modeBarButtons* configuration options","invalid button name"].join(" "));e[r][i]=l[a]}}return e}(p):!r.displayModeBar&&r.watermark?[]:function(t){var e=t._fullLayout,r=t._fullData,s=t._context;function u(t,e){if("string"==typeof e){if(e.toLowerCase()===t.toLowerCase())return!0}else{var r=e.name,n=e._cat||e.name;if(r===t||n===t.toLowerCase())return!0}return!1}var f=e.modebar.add;"string"==typeof f&&(f=[f]);var h=e.modebar.remove;"string"==typeof h&&(h=[h]);var p=s.modeBarButtonsToAdd.concat(f.filter((function(t){for(var e=0;e<s.modeBarButtonsToRemove.length;e++)if(u(t,s.modeBarButtonsToRemove[e]))return!1;return!0}))),d=s.modeBarButtonsToRemove.concat(h.filter((function(t){for(var e=0;e<s.modeBarButtonsToAdd.length;e++)if(u(t,s.modeBarButtonsToAdd[e]))return!1;return!0}))),m=e._has("cartesian"),g=e._has("gl3d"),v=e._has("geo"),y=e._has("pie"),x=e._has("funnelarea"),b=e._has("gl2d"),_=e._has("ternary"),w=e._has("mapbox"),T=e._has("polar"),k=e._has("smith"),A=e._has("sankey"),M=function(t){for(var e=n.list({_fullLayout:t},null,!0),r=0;r<e.length;r++)if(!e[r].fixedrange)return!1;return!0}(e),S=o(e.hovermode),E=[];function L(t){if(t.length){for(var e=[],r=0;r<t.length;r++){for(var n=t[r],i=l[n],a=i.name.toLowerCase(),o=(i._cat||i.name).toLowerCase(),s=!1,c=0;c<d.length;c++){var u=d[c].toLowerCase();if(u===a||u===o){s=!0;break}}s||e.push(l[n])}E.push(e)}}var C=["toImage"];s.showEditInChartStudio?C.push("editInChartStudio"):s.showSendToCloud&&C.push("sendDataToCloud");L(C);var P=[],I=[],O=[],z=[];(m||b||y||x||_)+v+g+w+T+k>1?(I=["toggleHover"],O=["resetViews"]):v?(P=["zoomInGeo","zoomOutGeo"],I=["hoverClosestGeo"],O=["resetGeo"]):g?(I=["hoverClosest3d"],O=["resetCameraDefault3d","resetCameraLastSave3d"]):w?(P=["zoomInMapbox","zoomOutMapbox"],I=["toggleHover"],O=["resetViewMapbox"]):b?I=["hoverClosestGl2d"]:y?I=["hoverClosestPie"]:A?(I=["hoverClosestCartesian","hoverCompareCartesian"],O=["resetViewSankey"]):I=["toggleHover"];m&&(I=["toggleSpikelines","hoverClosestCartesian","hoverCompareCartesian"]);(function(t){for(var e=0;e<t.length;e++)if(!a.traceIs(t[e],"noHover"))return!1;return!0}(r)||S)&&(I=[]);!m&&!b||M||(P=["zoomIn2d","zoomOut2d","autoScale2d"],"resetViews"!==O[0]&&(O=["resetScale2d"]));g?z=["zoom3d","pan3d","orbitRotation","tableRotation"]:(m||b)&&!M||_?z=["zoom2d","pan2d"]:w||v?z=["pan2d"]:T&&(z=["zoom2d"]);(function(t){for(var e=!1,r=0;r<t.length&&!e;r++){var n=t[r];n._module&&n._module.selectPoints&&(a.traceIs(n,"scatter-like")?(i.hasMarkers(n)||i.hasText(n))&&(e=!0):a.traceIs(n,"box-violin")&&"all"!==n.boxpoints&&"all"!==n.points||(e=!0))}return e})(r)&&z.push("select2d","lasso2d");var D=[],R=function(t){-1===D.indexOf(t)&&-1!==I.indexOf(t)&&D.push(t)};if(Array.isArray(p)){for(var F=[],B=0;B<p.length;B++){var N=p[B];"string"==typeof N?(N=N.toLowerCase(),-1!==c.indexOf(N)?(e._has("mapbox")||e._has("cartesian"))&&z.push(N):"togglespikelines"===N?R("toggleSpikelines"):"togglehover"===N?R("toggleHover"):"hovercompare"===N?R("hoverCompareCartesian"):"hoverclosest"===N?(R("hoverClosestCartesian"),R("hoverClosestGeo"),R("hoverClosest3d"),R("hoverClosestGl2d"),R("hoverClosestPie")):"v1hovermode"===N&&(R("toggleHover"),R("hoverClosestCartesian"),R("hoverCompareCartesian"),R("hoverClosestGeo"),R("hoverClosest3d"),R("hoverClosestGl2d"),R("hoverClosestPie"))):F.push(N)}p=F}return L(z),L(P.concat(O)),L(D),function(t,e){if(e.length)if(Array.isArray(e[0]))for(var r=0;r<e.length;r++)t.push(e[r]);else t.push(e);return t}(E,p)}(t),f?f.update(t,h):e._modeBar=s(t,h)}else f&&(f.destroy(),delete e._modeBar)}},{"../../lib":503,"../../plots/cartesian/axis_ids":558,"../../registry":638,"../../traces/scatter/subtypes":952,"../fx/helpers":402,"./buttons":426,"./constants":427,"./modebar":431}],431:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("fast-isnumeric"),a=t("../../lib"),o=t("../../fonts/ploticon"),s=t("../../version").version,l=new DOMParser;function c(t){this.container=t.container,this.element=document.createElement("div"),this.update(t.graphInfo,t.buttons),this.container.appendChild(this.element)}var u=c.prototype;u.update=function(t,e){this.graphInfo=t;var r=this.graphInfo._context,n=this.graphInfo._fullLayout,i="modebar-"+n._uid;this.element.setAttribute("id",i),this._uid=i,this.element.className="modebar","hover"===r.displayModeBar&&(this.element.className+=" modebar--hover ease-bg"),"v"===n.modebar.orientation&&(this.element.className+=" vertical",e=e.reverse());var o=n.modebar,s="hover"===r.displayModeBar?".js-plotly-plot .plotly:hover ":"";a.deleteRelatedStyleRule(i),a.addRelatedStyleRule(i,s+"#"+i+" .modebar-group","background-color: "+o.bgcolor),a.addRelatedStyleRule(i,"#"+i+" .modebar-btn .icon path","fill: "+o.color),a.addRelatedStyleRule(i,"#"+i+" .modebar-btn:hover .icon path","fill: "+o.activecolor),a.addRelatedStyleRule(i,"#"+i+" .modebar-btn.active .icon path","fill: "+o.activecolor);var l=!this.hasButtons(e),c=this.hasLogo!==r.displaylogo,u=this.locale!==r.locale;if(this.locale=r.locale,(l||c||u)&&(this.removeAllButtons(),this.updateButtons(e),r.watermark||r.displaylogo)){var f=this.getLogo();r.watermark&&(f.className=f.className+" watermark"),"v"===n.modebar.orientation?this.element.insertBefore(f,this.element.childNodes[0]):this.element.appendChild(f),this.hasLogo=!0}this.updateActiveButton()},u.updateButtons=function(t){var e=this;this.buttons=t,this.buttonElements=[],this.buttonsNames=[],this.buttons.forEach((function(t){var r=e.createGroup();t.forEach((function(t){var n=t.name;if(!n)throw new Error("must provide button 'name' in button config");if(-1!==e.buttonsNames.indexOf(n))throw new Error("button name '"+n+"' is taken");e.buttonsNames.push(n);var i=e.createButton(t);e.buttonElements.push(i),r.appendChild(i)})),e.element.appendChild(r)}))},u.createGroup=function(){var t=document.createElement("div");return t.className="modebar-group",t},u.createButton=function(t){var e=this,r=document.createElement("a");r.setAttribute("rel","tooltip"),r.className="modebar-btn";var i=t.title;void 0===i?i=t.name:"function"==typeof i&&(i=i(this.graphInfo)),(i||0===i)&&r.setAttribute("data-title",i),void 0!==t.attr&&r.setAttribute("data-attr",t.attr);var a=t.val;if(void 0!==a&&("function"==typeof a&&(a=a(this.graphInfo)),r.setAttribute("data-val",a)),"function"!=typeof t.click)throw new Error("must provide button 'click' function in button config");r.addEventListener("click",(function(r){t.click(e.graphInfo,r),e.updateActiveButton(r.currentTarget)})),r.setAttribute("data-toggle",t.toggle||!1),t.toggle&&n.select(r).classed("active",!0);var s=t.icon;return"function"==typeof s?r.appendChild(s()):r.appendChild(this.createIcon(s||o.question)),r.setAttribute("data-gravity",t.gravity||"n"),r},u.createIcon=function(t){var e,r=i(t.height)?Number(t.height):t.ascent-t.descent,n="http://www.w3.org/2000/svg";if(t.path){(e=document.createElementNS(n,"svg")).setAttribute("viewBox",[0,0,t.width,r].join(" ")),e.setAttribute("class","icon");var a=document.createElementNS(n,"path");a.setAttribute("d",t.path),t.transform?a.setAttribute("transform",t.transform):void 0!==t.ascent&&a.setAttribute("transform","matrix(1 0 0 -1 0 "+t.ascent+")"),e.appendChild(a)}t.svg&&(e=l.parseFromString(t.svg,"application/xml").childNodes[0]);return e.setAttribute("height","1em"),e.setAttribute("width","1em"),e},u.updateActiveButton=function(t){var e=this.graphInfo._fullLayout,r=void 0!==t?t.getAttribute("data-attr"):null;this.buttonElements.forEach((function(t){var i=t.getAttribute("data-val")||!0,o=t.getAttribute("data-attr"),s="true"===t.getAttribute("data-toggle"),l=n.select(t);if(s)o===r&&l.classed("active",!l.classed("active"));else{var c=null===o?o:a.nestedProperty(e,o).get();l.classed("active",c===i)}}))},u.hasButtons=function(t){var e=this.buttons;if(!e)return!1;if(t.length!==e.length)return!1;for(var r=0;r<t.length;++r){if(t[r].length!==e[r].length)return!1;for(var n=0;n<t[r].length;n++)if(t[r][n].name!==e[r][n].name)return!1}return!0},u.getLogo=function(){var t=this.createGroup(),e=document.createElement("a");return e.href="https://plotly.com/",e.target="_blank",e.setAttribute("data-title",a._(this.graphInfo,"Produced with Plotly.js")+" (v"+s+")"),e.className="modebar-btn plotlyjsicon modebar-btn--logo",e.appendChild(this.createIcon(o.newplotlylogo)),t.appendChild(e),t},u.removeAllButtons=function(){for(;this.element.firstChild;)this.element.removeChild(this.element.firstChild);this.hasLogo=!1},u.destroy=function(){a.removeElement(this.container.querySelector(".modebar")),a.deleteRelatedStyleRule(this._uid)},e.exports=function(t,e){var r=t._fullLayout,i=new c({graphInfo:t,container:r._modebardiv.node(),buttons:e});return r._privateplot&&n.select(i.element).append("span").classed("badge-private float--left",!0).text("PRIVATE"),i}},{"../../fonts/ploticon":482,"../../lib":503,"../../version":1123,"@plotly/d3":58,"fast-isnumeric":190}],432:[function(t,e,r){"use strict";var n=t("../../plots/font_attributes"),i=t("../color/attributes"),a=(0,t("../../plot_api/plot_template").templatedArray)("button",{visible:{valType:"boolean",dflt:!0,editType:"plot"},step:{valType:"enumerated",values:["month","year","day","hour","minute","second","all"],dflt:"month",editType:"plot"},stepmode:{valType:"enumerated",values:["backward","todate"],dflt:"backward",editType:"plot"},count:{valType:"number",min:0,dflt:1,editType:"plot"},label:{valType:"string",editType:"plot"},editType:"plot"});e.exports={visible:{valType:"boolean",editType:"plot"},buttons:a,x:{valType:"number",min:-2,max:3,editType:"plot"},xanchor:{valType:"enumerated",values:["auto","left","center","right"],dflt:"left",editType:"plot"},y:{valType:"number",min:-2,max:3,editType:"plot"},yanchor:{valType:"enumerated",values:["auto","top","middle","bottom"],dflt:"bottom",editType:"plot"},font:n({editType:"plot"}),bgcolor:{valType:"color",dflt:i.lightLine,editType:"plot"},activecolor:{valType:"color",editType:"plot"},bordercolor:{valType:"color",dflt:i.defaultLine,editType:"plot"},borderwidth:{valType:"number",min:0,dflt:0,editType:"plot"},editType:"plot"}},{"../../plot_api/plot_template":543,"../../plots/font_attributes":585,"../color/attributes":365}],433:[function(t,e,r){"use strict";e.exports={yPad:.02,minButtonWidth:30,rx:3,ry:3,lightAmount:25,darkAmount:10}},{}],434:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../color"),a=t("../../plot_api/plot_template"),o=t("../../plots/array_container_defaults"),s=t("./attributes"),l=t("./constants");function c(t,e,r,i){var a=i.calendar;function o(r,i){return n.coerce(t,e,s.buttons,r,i)}if(o("visible")){var l=o("step");"all"!==l&&(!a||"gregorian"===a||"month"!==l&&"year"!==l?o("stepmode"):e.stepmode="backward",o("count")),o("label")}}e.exports=function(t,e,r,u,f){var h=t.rangeselector||{},p=a.newContainer(e,"rangeselector");function d(t,e){return n.coerce(h,p,s,t,e)}if(d("visible",o(h,p,{name:"buttons",handleItemDefaults:c,calendar:f}).length>0)){var m=function(t,e,r){for(var n=r.filter((function(r){return e[r].anchor===t._id})),i=0,a=0;a<n.length;a++){var o=e[n[a]].domain;o&&(i=Math.max(o[1],i))}return[t.domain[0],i+l.yPad]}(e,r,u);d("x",m[0]),d("y",m[1]),n.noneOrAll(t,e,["x","y"]),d("xanchor"),d("yanchor"),n.coerceFont(d,"font",r.font);var g=d("bgcolor");d("activecolor",i.contrast(g,l.lightAmount,l.darkAmount)),d("bordercolor"),d("borderwidth")}}},{"../../lib":503,"../../plot_api/plot_template":543,"../../plots/array_container_defaults":549,"../color":366,"./attributes":432,"./constants":433}],435:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../registry"),a=t("../../plots/plots"),o=t("../color"),s=t("../drawing"),l=t("../../lib"),c=l.strTranslate,u=t("../../lib/svg_text_utils"),f=t("../../plots/cartesian/axis_ids"),h=t("../../constants/alignment"),p=h.LINE_SPACING,d=h.FROM_TL,m=h.FROM_BR,g=t("./constants"),v=t("./get_update_object");function y(t){return t._id}function x(t,e,r){var n=l.ensureSingle(t,"rect","selector-rect",(function(t){t.attr("shape-rendering","crispEdges")}));n.attr({rx:g.rx,ry:g.ry}),n.call(o.stroke,e.bordercolor).call(o.fill,function(t,e){return e._isActive||e._isHovered?t.activecolor:t.bgcolor}(e,r)).style("stroke-width",e.borderwidth+"px")}function b(t,e,r,n){l.ensureSingle(t,"text","selector-text",(function(t){t.attr("text-anchor","middle")})).call(s.font,e.font).text(function(t,e){if(t.label)return e?l.templateString(t.label,e):t.label;return"all"===t.step?"all":t.count+t.step.charAt(0)}(r,n._fullLayout._meta)).call((function(t){u.convertToTspans(t,n)}))}e.exports=function(t){var e=t._fullLayout._infolayer.selectAll(".rangeselector").data(function(t){for(var e=f.list(t,"x",!0),r=[],n=0;n<e.length;n++){var i=e[n];i.rangeselector&&i.rangeselector.visible&&r.push(i)}return r}(t),y);e.enter().append("g").classed("rangeselector",!0),e.exit().remove(),e.style({cursor:"pointer","pointer-events":"all"}),e.each((function(e){var r=n.select(this),o=e,f=o.rangeselector,h=r.selectAll("g.button").data(l.filterVisible(f.buttons));h.enter().append("g").classed("button",!0),h.exit().remove(),h.each((function(e){var r=n.select(this),a=v(o,e);e._isActive=function(t,e,r){if("all"===e.step)return!0===t.autorange;var n=Object.keys(r);return t.range[0]===r[n[0]]&&t.range[1]===r[n[1]]}(o,e,a),r.call(x,f,e),r.call(b,f,e,t),r.on("click",(function(){t._dragged||i.call("_guiRelayout",t,a)})),r.on("mouseover",(function(){e._isHovered=!0,r.call(x,f,e)})),r.on("mouseout",(function(){e._isHovered=!1,r.call(x,f,e)}))})),function(t,e,r,i,o){var f=0,h=0,v=r.borderwidth;e.each((function(){var t=n.select(this).select(".selector-text"),e=r.font.size*p,i=Math.max(e*u.lineCount(t),16)+3;h=Math.max(h,i)})),e.each((function(){var t=n.select(this),e=t.select(".selector-rect"),i=t.select(".selector-text"),a=i.node()&&s.bBox(i.node()).width,o=r.font.size*p,l=u.lineCount(i),d=Math.max(a+10,g.minButtonWidth);t.attr("transform",c(v+f,v)),e.attr({x:0,y:0,width:d,height:h}),u.positionText(i,d/2,h/2-(l-1)*o/2+3),f+=d+5}));var y=t._fullLayout._size,x=y.l+y.w*r.x,b=y.t+y.h*(1-r.y),_="left";l.isRightAnchor(r)&&(x-=f,_="right");l.isCenterAnchor(r)&&(x-=f/2,_="center");var w="top";l.isBottomAnchor(r)&&(b-=h,w="bottom");l.isMiddleAnchor(r)&&(b-=h/2,w="middle");f=Math.ceil(f),h=Math.ceil(h),x=Math.round(x),b=Math.round(b),a.autoMargin(t,i+"-range-selector",{x:r.x,y:r.y,l:f*d[_],r:f*m[_],b:h*m[w],t:h*d[w]}),o.attr("transform",c(x,b))}(t,h,f,o._name,r)}))}},{"../../constants/alignment":471,"../../lib":503,"../../lib/svg_text_utils":529,"../../plots/cartesian/axis_ids":558,"../../plots/plots":619,"../../registry":638,"../color":366,"../drawing":388,"./constants":433,"./get_update_object":436,"@plotly/d3":58}],436:[function(t,e,r){"use strict";var n=t("d3-time"),i=t("../../lib").titleCase;e.exports=function(t,e){var r=t._name,a={};if("all"===e.step)a[r+".autorange"]=!0;else{var o=function(t,e){var r,a=t.range,o=new Date(t.r2l(a[1])),s=e.step,l=n["utc"+i(s)],c=e.count;switch(e.stepmode){case"backward":r=t.l2r(+l.offset(o,-c));break;case"todate":var u=l.offset(o,-c);r=t.l2r(+l.ceil(u))}var f=a[1];return[r,f]}(t,e);a[r+".range[0]"]=o[0],a[r+".range[1]"]=o[1]}return a}},{"../../lib":503,"d3-time":122}],437:[function(t,e,r){"use strict";e.exports={moduleType:"component",name:"rangeselector",schema:{subplots:{xaxis:{rangeselector:t("./attributes")}}},layoutAttributes:t("./attributes"),handleDefaults:t("./defaults"),draw:t("./draw")}},{"./attributes":432,"./defaults":434,"./draw":435}],438:[function(t,e,r){"use strict";var n=t("../color/attributes");e.exports={bgcolor:{valType:"color",dflt:n.background,editType:"plot"},bordercolor:{valType:"color",dflt:n.defaultLine,editType:"plot"},borderwidth:{valType:"integer",dflt:0,min:0,editType:"plot"},autorange:{valType:"boolean",dflt:!0,editType:"calc",impliedEdits:{"range[0]":void 0,"range[1]":void 0}},range:{valType:"info_array",items:[{valType:"any",editType:"calc",impliedEdits:{"^autorange":!1}},{valType:"any",editType:"calc",impliedEdits:{"^autorange":!1}}],editType:"calc",impliedEdits:{autorange:!1}},thickness:{valType:"number",dflt:.15,min:0,max:1,editType:"plot"},visible:{valType:"boolean",dflt:!0,editType:"calc"},editType:"calc"}},{"../color/attributes":365}],439:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axis_ids").list,i=t("../../plots/cartesian/autorange").getAutoRange,a=t("./constants");e.exports=function(t){for(var e=n(t,"x",!0),r=0;r<e.length;r++){var o=e[r],s=o[a.name];s&&s.visible&&s.autorange&&(s._input.autorange=!0,s._input.range=s.range=i(t,o))}}},{"../../plots/cartesian/autorange":553,"../../plots/cartesian/axis_ids":558,"./constants":440}],440:[function(t,e,r){"use strict";e.exports={name:"rangeslider",containerClassName:"rangeslider-container",bgClassName:"rangeslider-bg",rangePlotClassName:"rangeslider-rangeplot",maskMinClassName:"rangeslider-mask-min",maskMaxClassName:"rangeslider-mask-max",slideBoxClassName:"rangeslider-slidebox",grabberMinClassName:"rangeslider-grabber-min",grabAreaMinClassName:"rangeslider-grabarea-min",handleMinClassName:"rangeslider-handle-min",grabberMaxClassName:"rangeslider-grabber-max",grabAreaMaxClassName:"rangeslider-grabarea-max",handleMaxClassName:"rangeslider-handle-max",maskMinOppAxisClassName:"rangeslider-mask-min-opp-axis",maskMaxOppAxisClassName:"rangeslider-mask-max-opp-axis",maskColor:"rgba(0,0,0,0.4)",maskOppAxisColor:"rgba(0,0,0,0.2)",slideBoxFill:"transparent",slideBoxCursor:"ew-resize",grabAreaFill:"transparent",grabAreaCursor:"col-resize",grabAreaWidth:10,handleWidth:4,handleRadius:1,handleStrokeWidth:1,extraPad:15}},{}],441:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plot_api/plot_template"),a=t("../../plots/cartesian/axis_ids"),o=t("./attributes"),s=t("./oppaxis_attributes");e.exports=function(t,e,r){var l=t[r],c=e[r];if(l.rangeslider||e._requestRangeslider[c._id]){n.isPlainObject(l.rangeslider)||(l.rangeslider={});var u,f,h=l.rangeslider,p=i.newContainer(c,"rangeslider");if(_("visible")){_("bgcolor",e.plot_bgcolor),_("bordercolor"),_("borderwidth"),_("thickness"),_("autorange",!c.isValidRange(h.range)),_("range");var d=e._subplots;if(d)for(var m=d.cartesian.filter((function(t){return t.substr(0,t.indexOf("y"))===a.name2id(r)})).map((function(t){return t.substr(t.indexOf("y"),t.length)})),g=n.simpleMap(m,a.id2name),v=0;v<g.length;v++){var y=g[v];u=h[y]||{},f=i.newContainer(p,y,"yaxis");var x,b=e[y];u.range&&b.isValidRange(u.range)&&(x="fixed"),"match"!==w("rangemode",x)&&w("range",b.range.slice())}p._input=h}}function _(t,e){return n.coerce(h,p,o,t,e)}function w(t,e){return n.coerce(u,f,s,t,e)}}},{"../../lib":503,"../../plot_api/plot_template":543,"../../plots/cartesian/axis_ids":558,"./attributes":438,"./oppaxis_attributes":445}],442:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../registry"),a=t("../../plots/plots"),o=t("../../lib"),s=o.strTranslate,l=t("../drawing"),c=t("../color"),u=t("../titles"),f=t("../../plots/cartesian"),h=t("../../plots/cartesian/axis_ids"),p=t("../dragelement"),d=t("../../lib/setcursor"),m=t("./constants");function g(t,e,r,n){var i=o.ensureSingle(t,"rect",m.bgClassName,(function(t){t.attr({x:0,y:0,"shape-rendering":"crispEdges"})})),a=n.borderwidth%2==0?n.borderwidth:n.borderwidth-1,c=-n._offsetShift,u=l.crispRound(e,n.borderwidth);i.attr({width:n._width+a,height:n._height+a,transform:s(c,c),fill:n.bgcolor,stroke:n.bordercolor,"stroke-width":u})}function v(t,e,r,n){var i=e._fullLayout;o.ensureSingleById(i._topdefs,"clipPath",n._clipId,(function(t){t.append("rect").attr({x:0,y:0})})).select("rect").attr({width:n._width,height:n._height})}function y(t,e,r,i){var s,c=e.calcdata,u=t.selectAll("g."+m.rangePlotClassName).data(r._subplotsWith,o.identity);u.enter().append("g").attr("class",(function(t){return m.rangePlotClassName+" "+t})).call(l.setClipUrl,i._clipId,e),u.order(),u.exit().remove(),u.each((function(t,o){var l=n.select(this),u=0===o,p=h.getFromId(e,t,"y"),d=p._name,m=i[d],g={data:[],layout:{xaxis:{type:r.type,domain:[0,1],range:i.range.slice(),calendar:r.calendar},width:i._width,height:i._height,margin:{t:0,b:0,l:0,r:0}},_context:e._context};r.rangebreaks&&(g.layout.xaxis.rangebreaks=r.rangebreaks),g.layout[d]={type:p.type,domain:[0,1],range:"match"!==m.rangemode?m.range.slice():p.range.slice(),calendar:p.calendar},p.rangebreaks&&(g.layout[d].rangebreaks=p.rangebreaks),a.supplyDefaults(g);var v=g._fullLayout.xaxis,y=g._fullLayout[d];v.clearCalc(),v.setScale(),y.clearCalc(),y.setScale();var x={id:t,plotgroup:l,xaxis:v,yaxis:y,isRangePlot:!0};u?s=x:(x.mainplot="xy",x.mainplotinfo=s),f.rangePlot(e,x,function(t,e){for(var r=[],n=0;n<t.length;n++){var i=t[n],a=i[0].trace;a.xaxis+a.yaxis===e&&r.push(i)}return r}(c,t))}))}function x(t,e,r,n,i){(o.ensureSingle(t,"rect",m.maskMinClassName,(function(t){t.attr({x:0,y:0,"shape-rendering":"crispEdges"})})).attr("height",n._height).call(c.fill,m.maskColor),o.ensureSingle(t,"rect",m.maskMaxClassName,(function(t){t.attr({y:0,"shape-rendering":"crispEdges"})})).attr("height",n._height).call(c.fill,m.maskColor),"match"!==i.rangemode)&&(o.ensureSingle(t,"rect",m.maskMinOppAxisClassName,(function(t){t.attr({y:0,"shape-rendering":"crispEdges"})})).attr("width",n._width).call(c.fill,m.maskOppAxisColor),o.ensureSingle(t,"rect",m.maskMaxOppAxisClassName,(function(t){t.attr({y:0,"shape-rendering":"crispEdges"})})).attr("width",n._width).style("border-top",m.maskOppBorder).call(c.fill,m.maskOppAxisColor))}function b(t,e,r,n){e._context.staticPlot||o.ensureSingle(t,"rect",m.slideBoxClassName,(function(t){t.attr({y:0,cursor:m.slideBoxCursor,"shape-rendering":"crispEdges"})})).attr({height:n._height,fill:m.slideBoxFill})}function _(t,e,r,n){var i=o.ensureSingle(t,"g",m.grabberMinClassName),a=o.ensureSingle(t,"g",m.grabberMaxClassName),s={x:0,width:m.handleWidth,rx:m.handleRadius,fill:c.background,stroke:c.defaultLine,"stroke-width":m.handleStrokeWidth,"shape-rendering":"crispEdges"},l={y:Math.round(n._height/4),height:Math.round(n._height/2)};o.ensureSingle(i,"rect",m.handleMinClassName,(function(t){t.attr(s)})).attr(l),o.ensureSingle(a,"rect",m.handleMaxClassName,(function(t){t.attr(s)})).attr(l);var u={width:m.grabAreaWidth,x:0,y:0,fill:m.grabAreaFill,cursor:e._context.staticPlot?void 0:m.grabAreaCursor};o.ensureSingle(i,"rect",m.grabAreaMinClassName,(function(t){t.attr(u)})).attr("height",n._height),o.ensureSingle(a,"rect",m.grabAreaMaxClassName,(function(t){t.attr(u)})).attr("height",n._height)}e.exports=function(t){for(var e=t._fullLayout,r=e._rangeSliderData,a=0;a<r.length;a++){var l=r[a][m.name];l._clipId=l._id+"-"+e._uid}var c=e._infolayer.selectAll("g."+m.containerClassName).data(r,(function(t){return t._name}));c.exit().each((function(t){var r=t[m.name];e._topdefs.select("#"+r._clipId).remove()})).remove(),0!==r.length&&(c.enter().append("g").classed(m.containerClassName,!0).attr("pointer-events","all"),c.each((function(r){var a=n.select(this),l=r[m.name],c=e[h.id2name(r.anchor)],f=l[h.id2name(r.anchor)];if(l.range){var w,T=o.simpleMap(l.range,r.r2l),k=o.simpleMap(r.range,r.r2l);w=k[0]<k[1]?[Math.min(T[0],k[0]),Math.max(T[1],k[1])]:[Math.max(T[0],k[0]),Math.min(T[1],k[1])],l.range=l._input.range=o.simpleMap(w,r.l2r)}r.cleanRange("rangeslider.range");var A=e._size,M=r.domain;l._width=A.w*(M[1]-M[0]);var S=Math.round(A.l+A.w*M[0]),E=Math.round(A.t+A.h*(1-r._counterDomainMin)+("bottom"===r.side?r._depth:0)+l._offsetShift+m.extraPad);a.attr("transform",s(S,E)),l._rl=o.simpleMap(l.range,r.r2l);var L=l._rl[0],C=l._rl[1],P=C-L;if(l.p2d=function(t){return t/l._width*P+L},l.d2p=function(t){return(t-L)/P*l._width},r.rangebreaks){var I=r.locateBreaks(L,C);if(I.length){var O,z,D=0;for(O=0;O<I.length;O++)D+=(z=I[O]).max-z.min;var R=l._width/(C-L-D),F=[-R*L];for(O=0;O<I.length;O++)z=I[O],F.push(F[F.length-1]-R*(z.max-z.min));for(l.d2p=function(t){for(var e=F[0],r=0;r<I.length;r++){var n=I[r];if(t>=n.max)e=F[r+1];else if(t<n.min)break}return e+R*t},O=0;O<I.length;O++)(z=I[O]).pmin=l.d2p(z.min),z.pmax=l.d2p(z.max);l.p2d=function(t){for(var e=F[0],r=0;r<I.length;r++){var n=I[r];if(t>=n.pmax)e=F[r+1];else if(t<n.pmin)break}return(t-e)/R}}}if("match"!==f.rangemode){var B=c.r2l(f.range[0]),N=c.r2l(f.range[1])-B;l.d2pOppAxis=function(t){return(t-B)/N*l._height}}a.call(g,t,r,l).call(v,t,r,l).call(y,t,r,l).call(x,t,r,l,f).call(b,t,r,l).call(_,t,r,l),function(t,e,r,a){if(e._context.staticPlot)return;var s=t.select("rect."+m.slideBoxClassName).node(),l=t.select("rect."+m.grabAreaMinClassName).node(),c=t.select("rect."+m.grabAreaMaxClassName).node();function u(){var u=n.event,f=u.target,h=u.clientX||u.touches[0].clientX,m=h-t.node().getBoundingClientRect().left,g=a.d2p(r._rl[0]),v=a.d2p(r._rl[1]),y=p.coverSlip();function x(t){var u,p,x,b=+(t.clientX||t.touches[0].clientX)-h;switch(f){case s:x="ew-resize",u=g+b,p=v+b;break;case l:x="col-resize",u=g+b,p=v;break;case c:x="col-resize",u=g,p=v+b;break;default:x="ew-resize",u=m,p=m+b}if(p<u){var _=p;p=u,u=_}a._pixelMin=u,a._pixelMax=p,d(n.select(y),x),function(t,e,r,n){function a(t){return r.l2r(o.constrain(t,n._rl[0],n._rl[1]))}var s=a(n.p2d(n._pixelMin)),l=a(n.p2d(n._pixelMax));window.requestAnimationFrame((function(){i.call("_guiRelayout",e,r._name+".range",[s,l])}))}(0,e,r,a)}function b(){y.removeEventListener("mousemove",x),y.removeEventListener("mouseup",b),this.removeEventListener("touchmove",x),this.removeEventListener("touchend",b),o.removeElement(y)}this.addEventListener("touchmove",x),this.addEventListener("touchend",b),y.addEventListener("mousemove",x),y.addEventListener("mouseup",b)}t.on("mousedown",u),t.on("touchstart",u)}(a,t,r,l),function(t,e,r,n,i,a){var l=m.handleWidth/2;function c(t){return o.constrain(t,0,n._width)}function u(t){return o.constrain(t,0,n._height)}function f(t){return o.constrain(t,-l,n._width+l)}var h=c(n.d2p(r._rl[0])),p=c(n.d2p(r._rl[1]));if(t.select("rect."+m.slideBoxClassName).attr("x",h).attr("width",p-h),t.select("rect."+m.maskMinClassName).attr("width",h),t.select("rect."+m.maskMaxClassName).attr("x",p).attr("width",n._width-p),"match"!==a.rangemode){var d=n._height-u(n.d2pOppAxis(i._rl[1])),g=n._height-u(n.d2pOppAxis(i._rl[0]));t.select("rect."+m.maskMinOppAxisClassName).attr("x",h).attr("height",d).attr("width",p-h),t.select("rect."+m.maskMaxOppAxisClassName).attr("x",h).attr("y",g).attr("height",n._height-g).attr("width",p-h),t.select("rect."+m.slideBoxClassName).attr("y",d).attr("height",g-d)}var v=Math.round(f(h-l))-.5,y=Math.round(f(p-l))+.5;t.select("g."+m.grabberMinClassName).attr("transform",s(v,.5)),t.select("g."+m.grabberMaxClassName).attr("transform",s(y,.5))}(a,0,r,l,c,f),"bottom"===r.side&&u.draw(t,r._id+"title",{propContainer:r,propName:r._name+".title",placeholder:e._dfltTitle.x,attributes:{x:r._offset+r._length/2,y:E+l._height+l._offsetShift+10+1.5*r.title.font.size,"text-anchor":"middle"}})})))}},{"../../lib":503,"../../lib/setcursor":524,"../../plots/cartesian":568,"../../plots/cartesian/axis_ids":558,"../../plots/plots":619,"../../registry":638,"../color":366,"../dragelement":385,"../drawing":388,"../titles":464,"./constants":440,"@plotly/d3":58}],443:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axis_ids"),i=t("../../lib/svg_text_utils"),a=t("./constants"),o=t("../../constants/alignment").LINE_SPACING,s=a.name;function l(t){var e=t&&t[s];return e&&e.visible}r.isVisible=l,r.makeData=function(t){var e=n.list({_fullLayout:t},"x",!0),r=t.margin,i=[];if(!t._has("gl2d"))for(var a=0;a<e.length;a++){var o=e[a];if(l(o)){i.push(o);var c=o[s];c._id=s+o._id,c._height=(t.height-r.b-r.t)*c.thickness,c._offsetShift=Math.floor(c.borderwidth/2)}}t._rangeSliderData=i},r.autoMarginOpts=function(t,e){var r=t._fullLayout,n=e[s],l=e._id.charAt(0),c=0,u=0;"bottom"===e.side&&(c=e._depth,e.title.text!==r._dfltTitle[l]&&(u=1.5*e.title.font.size+10+n._offsetShift,u+=(e.title.text.match(i.BR_TAG_ALL)||[]).length*e.title.font.size*o));return{x:0,y:e._counterDomainMin,l:0,r:0,t:0,b:n._height+c+Math.max(r.margin.b,u),pad:a.extraPad+2*n._offsetShift}}},{"../../constants/alignment":471,"../../lib/svg_text_utils":529,"../../plots/cartesian/axis_ids":558,"./constants":440}],444:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./attributes"),a=t("./oppaxis_attributes"),o=t("./helpers");e.exports={moduleType:"component",name:"rangeslider",schema:{subplots:{xaxis:{rangeslider:n.extendFlat({},i,{yaxis:a})}}},layoutAttributes:t("./attributes"),handleDefaults:t("./defaults"),calcAutorange:t("./calc_autorange"),draw:t("./draw"),isVisible:o.isVisible,makeData:o.makeData,autoMarginOpts:o.autoMarginOpts}},{"../../lib":503,"./attributes":438,"./calc_autorange":439,"./defaults":441,"./draw":442,"./helpers":443,"./oppaxis_attributes":445}],445:[function(t,e,r){"use strict";e.exports={_isSubplotObj:!0,rangemode:{valType:"enumerated",values:["auto","fixed","match"],dflt:"match",editType:"calc"},range:{valType:"info_array",items:[{valType:"any",editType:"plot"},{valType:"any",editType:"plot"}],editType:"plot"},editType:"calc"}},{}],446:[function(t,e,r){"use strict";var n=t("../annotations/attributes"),i=t("../../traces/scatter/attributes").line,a=t("../drawing/attributes").dash,o=t("../../lib/extend").extendFlat,s=t("../../plot_api/plot_template").templatedArray;t("../../constants/axis_placeable_objects");e.exports=s("shape",{visible:{valType:"boolean",dflt:!0,editType:"calc+arraydraw"},type:{valType:"enumerated",values:["circle","rect","path","line"],editType:"calc+arraydraw"},layer:{valType:"enumerated",values:["below","above"],dflt:"above",editType:"arraydraw"},xref:o({},n.xref,{}),xsizemode:{valType:"enumerated",values:["scaled","pixel"],dflt:"scaled",editType:"calc+arraydraw"},xanchor:{valType:"any",editType:"calc+arraydraw"},x0:{valType:"any",editType:"calc+arraydraw"},x1:{valType:"any",editType:"calc+arraydraw"},yref:o({},n.yref,{}),ysizemode:{valType:"enumerated",values:["scaled","pixel"],dflt:"scaled",editType:"calc+arraydraw"},yanchor:{valType:"any",editType:"calc+arraydraw"},y0:{valType:"any",editType:"calc+arraydraw"},y1:{valType:"any",editType:"calc+arraydraw"},path:{valType:"string",editType:"calc+arraydraw"},opacity:{valType:"number",min:0,max:1,dflt:1,editType:"arraydraw"},line:{color:o({},i.color,{editType:"arraydraw"}),width:o({},i.width,{editType:"calc+arraydraw"}),dash:o({},a,{editType:"arraydraw"}),editType:"calc+arraydraw"},fillcolor:{valType:"color",dflt:"rgba(0,0,0,0)",editType:"arraydraw"},fillrule:{valType:"enumerated",values:["evenodd","nonzero"],dflt:"evenodd",editType:"arraydraw"},editable:{valType:"boolean",dflt:!1,editType:"calc+arraydraw"},editType:"arraydraw"})},{"../../constants/axis_placeable_objects":472,"../../lib/extend":493,"../../plot_api/plot_template":543,"../../traces/scatter/attributes":927,"../annotations/attributes":349,"../drawing/attributes":387}],447:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axes"),a=t("./constants"),o=t("./helpers");function s(t){return c(t.line.width,t.xsizemode,t.x0,t.x1,t.path,!1)}function l(t){return c(t.line.width,t.ysizemode,t.y0,t.y1,t.path,!0)}function c(t,e,r,i,s,l){var c=t/2,u=l;if("pixel"===e){var f=s?o.extractPathCoords(s,l?a.paramIsY:a.paramIsX):[r,i],h=n.aggNums(Math.max,null,f),p=n.aggNums(Math.min,null,f),d=p<0?Math.abs(p)+c:c,m=h>0?h+c:c;return{ppad:c,ppadplus:u?d:m,ppadminus:u?m:d}}return{ppad:c}}function u(t,e,r,n,i){var s="category"===t.type||"multicategory"===t.type?t.r2c:t.d2c;if(void 0!==e)return[s(e),s(r)];if(n){var l,c,u,f,h=1/0,p=-1/0,d=n.match(a.segmentRE);for("date"===t.type&&(s=o.decodeDate(s)),l=0;l<d.length;l++)void 0!==(c=i[d[l].charAt(0)].drawn)&&(!(u=d[l].substr(1).match(a.paramRE))||u.length<c||((f=s(u[c]))<h&&(h=f),f>p&&(p=f)));return p>=h?[h,p]:void 0}}e.exports=function(t){var e=t._fullLayout,r=n.filterVisible(e.shapes);if(r.length&&t._fullData.length)for(var o=0;o<r.length;o++){var c,f,h=r[o];h._extremes={};var p=i.getRefType(h.xref),d=i.getRefType(h.yref);if("paper"!==h.xref&&"domain"!==p){var m="pixel"===h.xsizemode?h.xanchor:h.x0,g="pixel"===h.xsizemode?h.xanchor:h.x1;(f=u(c=i.getFromId(t,h.xref),m,g,h.path,a.paramIsX))&&(h._extremes[c._id]=i.findExtremes(c,f,s(h)))}if("paper"!==h.yref&&"domain"!==d){var v="pixel"===h.ysizemode?h.yanchor:h.y0,y="pixel"===h.ysizemode?h.yanchor:h.y1;(f=u(c=i.getFromId(t,h.yref),v,y,h.path,a.paramIsY))&&(h._extremes[c._id]=i.findExtremes(c,f,l(h)))}}}},{"../../lib":503,"../../plots/cartesian/axes":554,"./constants":448,"./helpers":457}],448:[function(t,e,r){"use strict";e.exports={segmentRE:/[MLHVQCTSZ][^MLHVQCTSZ]*/g,paramRE:/[^\s,]+/g,paramIsX:{M:{0:!0,drawn:0},L:{0:!0,drawn:0},H:{0:!0,drawn:0},V:{},Q:{0:!0,2:!0,drawn:2},C:{0:!0,2:!0,4:!0,drawn:4},T:{0:!0,drawn:0},S:{0:!0,2:!0,drawn:2},Z:{}},paramIsY:{M:{1:!0,drawn:1},L:{1:!0,drawn:1},H:{},V:{0:!0,drawn:0},Q:{1:!0,3:!0,drawn:3},C:{1:!0,3:!0,5:!0,drawn:5},T:{1:!0,drawn:1},S:{1:!0,3:!0,drawn:5},Z:{}},numParams:{M:2,L:2,H:1,V:1,Q:4,C:6,T:2,S:4,Z:0}}},{}],449:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axes"),a=t("../../plots/array_container_defaults"),o=t("./attributes"),s=t("./helpers");function l(t,e,r){function a(r,i){return n.coerce(t,e,o,r,i)}if(a("visible")){var l=a("path"),c=a("type",l?"path":"rect");"path"!==e.type&&delete e.path,a("editable"),a("layer"),a("opacity"),a("fillcolor"),a("fillrule"),a("line.width")&&(a("line.color"),a("line.dash"));for(var u=a("xsizemode"),f=a("ysizemode"),h=["x","y"],p=0;p<2;p++){var d,m,g,v=h[p],y=v+"anchor",x="x"===v?u:f,b={_fullLayout:r},_=i.coerceRef(t,e,b,v,void 0,"paper");if("range"===i.getRefType(_)?((d=i.getFromId(b,_))._shapeIndices.push(e._index),g=s.rangeToShapePosition(d),m=s.shapePositionToRange(d)):m=g=n.identity,"path"!==c){var w=v+"0",T=v+"1",k=t[w],A=t[T];t[w]=m(t[w],!0),t[T]=m(t[T],!0),"pixel"===x?(a(w,0),a(T,10)):(i.coercePosition(e,b,a,_,w,.25),i.coercePosition(e,b,a,_,T,.75)),e[w]=g(e[w]),e[T]=g(e[T]),t[w]=k,t[T]=A}if("pixel"===x){var M=t[y];t[y]=m(t[y],!0),i.coercePosition(e,b,a,_,y,.25),e[y]=g(e[y]),t[y]=M}}"path"===c?a("path"):n.noneOrAll(t,e,["x0","x1","y0","y1"])}}e.exports=function(t,e){a(t,e,{name:"shapes",handleItemDefaults:l})}},{"../../lib":503,"../../plots/array_container_defaults":549,"../../plots/cartesian/axes":554,"./attributes":446,"./helpers":457}],450:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib"),a=t("../../plots/cartesian/axes"),o=t("./draw_newshape/helpers").readPaths,s=t("./draw_newshape/display_outlines"),l=t("../../plots/cartesian/handle_outline").clearOutlineControllers,c=t("../color"),u=t("../drawing"),f=t("../../plot_api/plot_template").arrayEditor,h=t("../dragelement"),p=t("../../lib/setcursor"),d=t("./constants"),m=t("./helpers");function g(t){var e=t._fullLayout;for(var r in e._shapeUpperLayer.selectAll("path").remove(),e._shapeLowerLayer.selectAll("path").remove(),e._plots){var n=e._plots[r].shapelayer;n&&n.selectAll("path").remove()}for(var i=0;i<e.shapes.length;i++)e.shapes[i].visible&&x(t,i)}function v(t){return!!t._fullLayout._drawing}function y(t){return!t._context.edits.shapePosition}function x(t,e){t._fullLayout._paperdiv.selectAll('.shapelayer [data-index="'+e+'"]').remove();var r=m.makeOptionsAndPlotinfo(t,e),l=r.options,x=r.plotinfo;if(l._input&&!1!==l.visible)if("below"!==l.layer)k(t._fullLayout._shapeUpperLayer);else if("paper"===l.xref||"paper"===l.yref)k(t._fullLayout._shapeLowerLayer);else{if(x._hadPlotinfo)k((x.mainplotinfo||x).shapelayer);else k(t._fullLayout._shapeLowerLayer)}function k(r){var k=_(t,l),A={"data-index":e,"fill-rule":l.fillrule,d:k},M=l.opacity,S=l.fillcolor,E=l.line.width?l.line.color:"rgba(0,0,0,0)",L=l.line.width,C=l.line.dash;L||!0!==l.editable||(L=5,C="solid");var P="Z"!==k[k.length-1],I=y(t)&&l.editable&&t._fullLayout._activeShapeIndex===e;I&&(S=P?"rgba(0,0,0,0)":t._fullLayout.activeshape.fillcolor,M=t._fullLayout.activeshape.opacity);var O,z=r.append("path").attr(A).style("opacity",M).call(c.stroke,E).call(c.fill,S).call(u.dashLine,C,L);if(b(z,t,l),(I||t._context.edits.shapePosition)&&(O=f(t.layout,"shapes",l)),I){z.style({cursor:"move"});var D={element:z.node(),plotinfo:x,gd:t,editHelpers:O,isActiveShape:!0},R=o(k,t);s(R,z,D)}else t._context.edits.shapePosition?function(t,e,r,o,s,l){var c,f,g,y,x,T,k,A,M,S,E,L,C,P,I,O,z="pixel"===r.xsizemode,D="pixel"===r.ysizemode,R="line"===r.type,F="path"===r.type,B=l.modifyItem,N=a.getFromId(t,r.xref),j=a.getRefType(r.xref),U=a.getFromId(t,r.yref),V=a.getRefType(r.yref),H=m.getDataToPixel(t,N,!1,j),q=m.getDataToPixel(t,U,!0,V),G=m.getPixelToData(t,N,!1,j),Y=m.getPixelToData(t,U,!0,V),W=R?function(){var t=Math.max(r.line.width,10),n=s.append("g").attr("data-index",o);n.append("path").attr("d",e.attr("d")).style({cursor:"move","stroke-width":t,"stroke-opacity":"0"});var i={"fill-opacity":"0"},a=Math.max(t/2,10);return n.append("circle").attr({"data-line-point":"start-point",cx:z?H(r.xanchor)+r.x0:H(r.x0),cy:D?q(r.yanchor)-r.y0:q(r.y0),r:a}).style(i).classed("cursor-grab",!0),n.append("circle").attr({"data-line-point":"end-point",cx:z?H(r.xanchor)+r.x1:H(r.x1),cy:D?q(r.yanchor)-r.y1:q(r.y1),r:a}).style(i).classed("cursor-grab",!0),n}():e,X={element:W.node(),gd:t,prepFn:function(n){if(v(t))return;z&&(x=H(r.xanchor));D&&(T=q(r.yanchor));"path"===r.type?I=r.path:(c=z?r.x0:H(r.x0),f=D?r.y0:q(r.y0),g=z?r.x1:H(r.x1),y=D?r.y1:q(r.y1));c<g?(M=c,C="x0",S=g,P="x1"):(M=g,C="x1",S=c,P="x0");!D&&f<y||D&&f>y?(k=f,E="y0",A=y,L="y1"):(k=y,E="y1",A=f,L="y0");Z(n),Q(s,r),function(t,e,r){var n=e.xref,i=e.yref,o=a.getFromId(r,n),s=a.getFromId(r,i),l="";"paper"===n||o.autorange||(l+=n);"paper"===i||s.autorange||(l+=i);u.setClipUrl(t,l?"clip"+r._fullLayout._uid+l:null,r)}(e,r,t),X.moveFn="move"===O?J:K,X.altKey=n.altKey},doneFn:function(){if(v(t))return;p(e),$(s),b(e,t,r),n.call("_guiRelayout",t,l.getUpdateObj())},clickFn:function(){if(v(t))return;$(s)}};function Z(r){if(v(t))O=null;else if(R)O="path"===r.target.tagName?"move":"start-point"===r.target.attributes["data-line-point"].value?"resize-over-start-point":"resize-over-end-point";else{var n=X.element.getBoundingClientRect(),i=n.right-n.left,a=n.bottom-n.top,o=r.clientX-n.left,s=r.clientY-n.top,l=!F&&i>10&&a>10&&!r.shiftKey?h.getCursor(o/i,1-s/a):"move";p(e,l),O=l.split("-")[0]}}function J(n,i){if("path"===r.type){var a=function(t){return t},o=a,l=a;z?B("xanchor",r.xanchor=G(x+n)):(o=function(t){return G(H(t)+n)},N&&"date"===N.type&&(o=m.encodeDate(o))),D?B("yanchor",r.yanchor=Y(T+i)):(l=function(t){return Y(q(t)+i)},U&&"date"===U.type&&(l=m.encodeDate(l))),B("path",r.path=w(I,o,l))}else z?B("xanchor",r.xanchor=G(x+n)):(B("x0",r.x0=G(c+n)),B("x1",r.x1=G(g+n))),D?B("yanchor",r.yanchor=Y(T+i)):(B("y0",r.y0=Y(f+i)),B("y1",r.y1=Y(y+i)));e.attr("d",_(t,r)),Q(s,r)}function K(n,i){if(F){var a=function(t){return t},o=a,l=a;z?B("xanchor",r.xanchor=G(x+n)):(o=function(t){return G(H(t)+n)},N&&"date"===N.type&&(o=m.encodeDate(o))),D?B("yanchor",r.yanchor=Y(T+i)):(l=function(t){return Y(q(t)+i)},U&&"date"===U.type&&(l=m.encodeDate(l))),B("path",r.path=w(I,o,l))}else if(R){if("resize-over-start-point"===O){var u=c+n,h=D?f-i:f+i;B("x0",r.x0=z?u:G(u)),B("y0",r.y0=D?h:Y(h))}else if("resize-over-end-point"===O){var p=g+n,d=D?y-i:y+i;B("x1",r.x1=z?p:G(p)),B("y1",r.y1=D?d:Y(d))}}else{var v=function(t){return-1!==O.indexOf(t)},b=v("n"),j=v("s"),V=v("w"),W=v("e"),X=b?k+i:k,Z=j?A+i:A,J=V?M+n:M,K=W?S+n:S;D&&(b&&(X=k-i),j&&(Z=A-i)),(!D&&Z-X>10||D&&X-Z>10)&&(B(E,r[E]=D?X:Y(X)),B(L,r[L]=D?Z:Y(Z))),K-J>10&&(B(C,r[C]=z?J:G(J)),B(P,r[P]=z?K:G(K)))}e.attr("d",_(t,r)),Q(s,r)}function Q(t,e){(z||D)&&function(){var r="path"!==e.type,n=t.selectAll(".visual-cue").data([0]);n.enter().append("path").attr({fill:"#fff","fill-rule":"evenodd",stroke:"#000","stroke-width":1}).classed("visual-cue",!0);var a=H(z?e.xanchor:i.midRange(r?[e.x0,e.x1]:m.extractPathCoords(e.path,d.paramIsX))),o=q(D?e.yanchor:i.midRange(r?[e.y0,e.y1]:m.extractPathCoords(e.path,d.paramIsY)));if(a=m.roundPositionForSharpStrokeRendering(a,1),o=m.roundPositionForSharpStrokeRendering(o,1),z&&D){var s="M"+(a-1-1)+","+(o-1-1)+"h-8v2h8 v8h2v-8 h8v-2h-8 v-8h-2 Z";n.attr("d",s)}else if(z){var l="M"+(a-1-1)+","+(o-9-1)+"v18 h2 v-18 Z";n.attr("d",l)}else{var c="M"+(a-9-1)+","+(o-1-1)+"h18 v2 h-18 Z";n.attr("d",c)}}()}function $(t){t.selectAll(".visual-cue").remove()}h.init(X),W.node().onmousemove=Z}(t,z,l,e,r,O):!0===l.editable&&z.style("pointer-events",P||c.opacity(S)*M<=.5?"stroke":"all");z.node().addEventListener("click",(function(){return function(t,e){if(!y(t))return;var r=+e.node().getAttribute("data-index");if(r>=0){if(r===t._fullLayout._activeShapeIndex)return void T(t);t._fullLayout._activeShapeIndex=r,t._fullLayout._deactivateShape=T,g(t)}}(t,z)}))}}function b(t,e,r){var n=(r.xref+r.yref).replace(/paper/g,"").replace(/[xyz][1-9]* *domain/g,"");u.setClipUrl(t,n?"clip"+e._fullLayout._uid+n:null,e)}function _(t,e){var r,n,o,s,l,c,u,f,h=e.type,p=a.getRefType(e.xref),g=a.getRefType(e.yref),v=a.getFromId(t,e.xref),y=a.getFromId(t,e.yref),x=t._fullLayout._size;if(v?"domain"===p?n=function(t){return v._offset+v._length*t}:(r=m.shapePositionToRange(v),n=function(t){return v._offset+v.r2p(r(t,!0))}):n=function(t){return x.l+x.w*t},y?"domain"===g?s=function(t){return y._offset+y._length*(1-t)}:(o=m.shapePositionToRange(y),s=function(t){return y._offset+y.r2p(o(t,!0))}):s=function(t){return x.t+x.h*(1-t)},"path"===h)return v&&"date"===v.type&&(n=m.decodeDate(n)),y&&"date"===y.type&&(s=m.decodeDate(s)),function(t,e,r){var n=t.path,a=t.xsizemode,o=t.ysizemode,s=t.xanchor,l=t.yanchor;return n.replace(d.segmentRE,(function(t){var n=0,c=t.charAt(0),u=d.paramIsX[c],f=d.paramIsY[c],h=d.numParams[c],p=t.substr(1).replace(d.paramRE,(function(t){return u[n]?t="pixel"===a?e(s)+Number(t):e(t):f[n]&&(t="pixel"===o?r(l)-Number(t):r(t)),++n>h&&(t="X"),t}));return n>h&&(p=p.replace(/[\s,]*X.*/,""),i.log("Ignoring extra params in segment "+t)),c+p}))}(e,n,s);if("pixel"===e.xsizemode){var b=n(e.xanchor);l=b+e.x0,c=b+e.x1}else l=n(e.x0),c=n(e.x1);if("pixel"===e.ysizemode){var _=s(e.yanchor);u=_-e.y0,f=_-e.y1}else u=s(e.y0),f=s(e.y1);if("line"===h)return"M"+l+","+u+"L"+c+","+f;if("rect"===h)return"M"+l+","+u+"H"+c+"V"+f+"H"+l+"Z";var w=(l+c)/2,T=(u+f)/2,k=Math.abs(w-l),A=Math.abs(T-u),M="A"+k+","+A,S=w+k+","+T;return"M"+S+M+" 0 1,1 "+(w+","+(T-A))+M+" 0 0,1 "+S+"Z"}function w(t,e,r){return t.replace(d.segmentRE,(function(t){var n=0,i=t.charAt(0),a=d.paramIsX[i],o=d.paramIsY[i],s=d.numParams[i];return i+t.substr(1).replace(d.paramRE,(function(t){return n>=s||(a[n]?t=e(t):o[n]&&(t=r(t)),n++),t}))}))}function T(t){y(t)&&(t._fullLayout._activeShapeIndex>=0&&(l(t),delete t._fullLayout._activeShapeIndex,g(t)))}e.exports={draw:g,drawOne:x,eraseActiveShape:function(t){if(!y(t))return;l(t);var e=t._fullLayout._activeShapeIndex,r=(t.layout||{}).shapes||[];if(e<r.length){for(var i=[],a=0;a<r.length;a++)a!==e&&i.push(r[a]);delete t._fullLayout._activeShapeIndex,n.call("_guiRelayout",t,{shapes:i})}}}},{"../../lib":503,"../../lib/setcursor":524,"../../plot_api/plot_template":543,"../../plots/cartesian/axes":554,"../../plots/cartesian/handle_outline":565,"../../registry":638,"../color":366,"../dragelement":385,"../drawing":388,"./constants":448,"./draw_newshape/display_outlines":454,"./draw_newshape/helpers":455,"./helpers":457}],451:[function(t,e,r){"use strict";var n=t("../../drawing/attributes").dash,i=t("../../../lib/extend").extendFlat;e.exports={newshape:{line:{color:{valType:"color",editType:"none"},width:{valType:"number",min:0,dflt:4,editType:"none"},dash:i({},n,{dflt:"solid",editType:"none"}),editType:"none"},fillcolor:{valType:"color",dflt:"rgba(0,0,0,0)",editType:"none"},fillrule:{valType:"enumerated",values:["evenodd","nonzero"],dflt:"evenodd",editType:"none"},opacity:{valType:"number",min:0,max:1,dflt:1,editType:"none"},layer:{valType:"enumerated",values:["below","above"],dflt:"above",editType:"none"},drawdirection:{valType:"enumerated",values:["ortho","horizontal","vertical","diagonal"],dflt:"diagonal",editType:"none"},editType:"none"},activeshape:{fillcolor:{valType:"color",dflt:"rgb(255,0,255)",editType:"none"},opacity:{valType:"number",min:0,max:1,dflt:.5,editType:"none"},editType:"none"}}},{"../../../lib/extend":493,"../../drawing/attributes":387}],452:[function(t,e,r){"use strict";e.exports={CIRCLE_SIDES:32,i000:0,i090:8,i180:16,i270:24,cos45:Math.cos(Math.PI/4),sin45:Math.sin(Math.PI/4),SQRT2:Math.sqrt(2)}},{}],453:[function(t,e,r){"use strict";var n=t("../../color");e.exports=function(t,e,r){if(r("newshape.drawdirection"),r("newshape.layer"),r("newshape.fillcolor"),r("newshape.fillrule"),r("newshape.opacity"),r("newshape.line.width")){var i=(t||{}).plot_bgcolor||"#FFF";r("newshape.line.color",n.contrast(i)),r("newshape.line.dash")}r("activeshape.fillcolor"),r("activeshape.opacity")}},{"../../color":366}],454:[function(t,e,r){"use strict";var n=t("../../dragelement"),i=t("../../dragelement/helpers").drawMode,a=t("../../../registry"),o=t("./constants"),s=o.i000,l=o.i090,c=o.i180,u=o.i270,f=t("../../../plots/cartesian/handle_outline").clearOutlineControllers,h=t("./helpers"),p=h.pointsShapeRectangle,d=h.pointsShapeEllipse,m=h.writePaths,g=t("./newshapes");e.exports=function t(e,r,o,h){h||(h=0);var v=o.gd;function y(){t(e,r,o,h++),d(e[0])&&x({redrawing:!0})}function x(t){o.isActiveShape=!1;var e=g(r,o);Object.keys(e).length&&a.call((t||{}).redrawing?"relayout":"_guiRelayout",v,e)}var b,_,w,T,k,A=o.isActiveShape,M=v._fullLayout._zoomlayer,S=o.dragmode;(i(S)?v._fullLayout._drawing=!0:v._fullLayout._activeShapeIndex>=0&&f(v),r.attr("d",m(e)),A&&!h)&&(k=function(t,e){for(var r=0;r<e.length;r++){var n=e[r];t[r]=[];for(var i=0;i<n.length;i++){t[r][i]=[];for(var a=0;a<n[i].length;a++)t[r][i][a]=n[i][a]}}return t}([],e),function(t){b=[];for(var r=0;r<e.length;r++){var i=e[r],a=!p(i)&&d(i);b[r]=[];for(var o=0;o<i.length;o++)if("Z"!==i[o][0]&&(!a||o===s||o===l||o===c||o===u)){var f=i[o][1],h=i[o][2],m=t.append("circle").classed("cursor-grab",!0).attr("data-i",r).attr("data-j",o).attr("cx",f).attr("cy",h).attr("r",4).style({"mix-blend-mode":"luminosity",fill:"black",stroke:"white","stroke-width":1});b[r][o]={element:m.node(),gd:v,prepFn:E,doneFn:C,clickFn:P},n.init(b[r][o])}}}(M.append("g").attr("class","outline-controllers")),function(){if(_=[],!e.length)return;_[0]={element:r[0][0],gd:v,prepFn:O,doneFn:z},n.init(_[0])}());function E(t){w=+t.srcElement.getAttribute("data-i"),T=+t.srcElement.getAttribute("data-j"),b[w][T].moveFn=L}function L(t,r){if(e.length){var n=k[w][T][1],i=k[w][T][2],a=e[w],o=a.length;if(p(a)){for(var s=0;s<o;s++)if(s!==T){var l=a[s];l[1]===a[T][1]&&(l[1]=n+t),l[2]===a[T][2]&&(l[2]=i+r)}if(a[T][1]=n+t,a[T][2]=i+r,!p(a))for(var c=0;c<o;c++)for(var u=0;u<a[c].length;u++)a[c][u]=k[w][c][u]}else a[T][1]=n+t,a[T][2]=i+r;y()}}function C(){x()}function P(t,r){if(2===t){w=+r.srcElement.getAttribute("data-i"),T=+r.srcElement.getAttribute("data-j");var n=e[w];p(n)||d(n)||function(){if(e.length&&e[w]&&e[w].length){for(var t=[],r=0;r<e[w].length;r++)r!==T&&t.push(e[w][r]);t.length>1&&(2!==t.length||"Z"!==t[1][0])&&(0===T&&(t[0][0]="M"),e[w]=t,y(),x())}}()}}function I(t,r){!function(t,r){if(e.length)for(var n=0;n<e.length;n++)for(var i=0;i<e[n].length;i++)for(var a=0;a+2<e[n][i].length;a+=2)e[n][i][a+1]=k[n][i][a+1]+t,e[n][i][a+2]=k[n][i][a+2]+r}(t,r),y()}function O(t){(w=+t.srcElement.getAttribute("data-i"))||(w=0),_[w].moveFn=I}function z(){x()}}},{"../../../plots/cartesian/handle_outline":565,"../../../registry":638,"../../dragelement":385,"../../dragelement/helpers":384,"./constants":452,"./helpers":455,"./newshapes":456}],455:[function(t,e,r){"use strict";var n=t("parse-svg-path"),i=t("./constants"),a=i.CIRCLE_SIDES,o=i.SQRT2,s=t("../../../plots/cartesian/helpers"),l=s.p2r,c=s.r2p,u=[0,3,4,5,6,1,2],f=[0,3,4,1,2];function h(t,e){return Math.abs(t-e)<=1e-6}function p(t,e){var r=e[1]-t[1],n=e[2]-t[2];return Math.sqrt(r*r+n*n)}r.writePaths=function(t){var e=t.length;if(!e)return"M0,0Z";for(var r="",n=0;n<e;n++)for(var i=t[n].length,a=0;a<i;a++){var o=t[n][a][0];if("Z"===o)r+="Z";else for(var s=t[n][a].length,l=0;l<s;l++){var c=l;"Q"===o||"S"===o?c=f[l]:"C"===o&&(c=u[l]),r+=t[n][a][c],l>0&&l<s-1&&(r+=",")}}return r},r.readPaths=function(t,e,r,i){var o,s,u,f=n(t),h=[],p=-1,d=0,m=0,g=function(){s=d,u=m};g();for(var v=0;v<f.length;v++){var y,x,b,_,w=[],T=f[v][0],k=T;switch(T){case"M":p++,h[p]=[],d=+f[v][1],m=+f[v][2],w.push([k,d,m]),g();break;case"Q":case"S":y=+f[v][1],b=+f[v][2],d=+f[v][3],m=+f[v][4],w.push([k,d,m,y,b]);break;case"C":y=+f[v][1],b=+f[v][2],x=+f[v][3],_=+f[v][4],d=+f[v][5],m=+f[v][6],w.push([k,d,m,y,b,x,_]);break;case"T":case"L":d=+f[v][1],m=+f[v][2],w.push([k,d,m]);break;case"H":k="L",d=+f[v][1],w.push([k,d,m]);break;case"V":k="L",m=+f[v][1],w.push([k,d,m]);break;case"A":k="L";var A=+f[v][1],M=+f[v][2];+f[v][4]||(A=-A,M=-M);var S=d-A,E=m;for(o=1;o<=a/2;o++){var L=2*Math.PI*o/a;w.push([k,S+A*Math.cos(L),E+M*Math.sin(L)])}break;case"Z":d===s&&m===u||(d=s,m=u,w.push([k,d,m]))}for(var C=(r||{}).domain,P=e._fullLayout._size,I=r&&"pixel"===r.xsizemode,O=r&&"pixel"===r.ysizemode,z=!1===i,D=0;D<w.length;D++){for(o=0;o+2<7;o+=2){var R=w[D][o+1],F=w[D][o+2];void 0!==R&&void 0!==F&&(d=R,m=F,r&&(r.xaxis&&r.xaxis.p2r?(z&&(R-=r.xaxis._offset),R=I?c(r.xaxis,r.xanchor)+R:l(r.xaxis,R)):(z&&(R-=P.l),C?R=C.x[0]+R/P.w:R/=P.w),r.yaxis&&r.yaxis.p2r?(z&&(F-=r.yaxis._offset),F=O?c(r.yaxis,r.yanchor)-F:l(r.yaxis,F)):(z&&(F-=P.t),F=C?C.y[1]-F/P.h:1-F/P.h)),w[D][o+1]=R,w[D][o+2]=F)}h[p].push(w[D].slice())}}return h},r.pointsShapeRectangle=function(t){if(5!==t.length)return!1;for(var e=1;e<3;e++){if(!h(t[0][e]-t[1][e],t[3][e]-t[2][e]))return!1;if(!h(t[0][e]-t[3][e],t[1][e]-t[2][e]))return!1}return!(!h(t[0][1],t[1][1])&&!h(t[0][1],t[3][1]))&&!!(p(t[0],t[1])*p(t[0],t[3]))},r.pointsShapeEllipse=function(t){var e=t.length;if(e!==a+1)return!1;e=a;for(var r=0;r<e;r++){var n=(2*e-r)%e,i=(e/2+n)%e,o=(e/2+r)%e;if(!h(p(t[r],t[o]),p(t[n],t[i])))return!1}return!0},r.handleEllipse=function(t,e,n){if(!t)return[e,n];var i=r.ellipseOver({x0:e[0],y0:e[1],x1:n[0],y1:n[1]}),s=(i.x1+i.x0)/2,l=(i.y1+i.y0)/2,c=(i.x1-i.x0)/2,u=(i.y1-i.y0)/2;c||(c=u/=o),u||(u=c/=o);for(var f=[],h=0;h<a;h++){var p=2*h*Math.PI/a;f.push([s+c*Math.cos(p),l+u*Math.sin(p)])}return f},r.ellipseOver=function(t){var e=t.x0,r=t.y0,n=t.x1,i=t.y1,a=n-e,s=i-r,l=((e-=a)+n)/2,c=((r-=s)+i)/2;return{x0:l-(a*=o),y0:c-(s*=o),x1:l+a,y1:c+s}}},{"../../../plots/cartesian/helpers":566,"./constants":452,"parse-svg-path":250}],456:[function(t,e,r){"use strict";var n=t("../../dragelement/helpers"),i=n.drawMode,a=n.openMode,o=t("./constants"),s=o.i000,l=o.i090,c=o.i180,u=o.i270,f=o.cos45,h=o.sin45,p=t("../../../plots/cartesian/helpers"),d=p.p2r,m=p.r2p,g=t("../../../plots/cartesian/handle_outline").clearSelect,v=t("./helpers"),y=v.readPaths,x=v.writePaths,b=v.ellipseOver;e.exports=function(t,e){if(t.length){var r=t[0][0];if(r){var n=r.getAttribute("d"),o=e.gd,p=o._fullLayout.newshape,v=e.plotinfo,_=v.xaxis,w=v.yaxis,T=!!v.domain||!v.xaxis,k=!!v.domain||!v.yaxis,A=e.isActiveShape,M=e.dragmode,S=(o.layout||{}).shapes||[];if(!i(M)&&void 0!==A){var E=o._fullLayout._activeShapeIndex;if(E<S.length)switch(o._fullLayout.shapes[E].type){case"rect":M="drawrect";break;case"circle":M="drawcircle";break;case"line":M="drawline";break;case"path":var L=S[E].path||"";M="Z"===L[L.length-1]?"drawclosedpath":"drawopenpath"}}var C,P=a(M),I=y(n,o,v,A),O={editable:!0,xref:T?"paper":_._id,yref:k?"paper":w._id,layer:p.layer,opacity:p.opacity,line:{color:p.line.color,width:p.line.width,dash:p.line.dash}};if(P||(O.fillcolor=p.fillcolor,O.fillrule=p.fillrule),1===I.length&&(C=I[0]),C&&"drawrect"===M)O.type="rect",O.x0=C[0][1],O.y0=C[0][2],O.x1=C[2][1],O.y1=C[2][2];else if(C&&"drawline"===M)O.type="line",O.x0=C[0][1],O.y0=C[0][2],O.x1=C[1][1],O.y1=C[1][2];else if(C&&"drawcircle"===M){O.type="circle";var z=C[s][1],D=C[l][1],R=C[c][1],F=C[u][1],B=C[s][2],N=C[l][2],j=C[c][2],U=C[u][2],V=v.xaxis&&("date"===v.xaxis.type||"log"===v.xaxis.type),H=v.yaxis&&("date"===v.yaxis.type||"log"===v.yaxis.type);V&&(z=m(v.xaxis,z),D=m(v.xaxis,D),R=m(v.xaxis,R),F=m(v.xaxis,F)),H&&(B=m(v.yaxis,B),N=m(v.yaxis,N),j=m(v.yaxis,j),U=m(v.yaxis,U));var q=(D+F)/2,G=(B+j)/2,Y=b({x0:q,y0:G,x1:q+(F-D+R-z)/2*f,y1:G+(U-N+j-B)/2*h});V&&(Y.x0=d(v.xaxis,Y.x0),Y.x1=d(v.xaxis,Y.x1)),H&&(Y.y0=d(v.yaxis,Y.y0),Y.y1=d(v.yaxis,Y.y1)),O.x0=Y.x0,O.y0=Y.y0,O.x1=Y.x1,O.y1=Y.y1}else O.type="path",_&&w&&function(t,e,r){var n="date"===e.type,i="date"===r.type;if(!n&&!i)return t;for(var a=0;a<t.length;a++)for(var o=0;o<t[a].length;o++)for(var s=0;s+2<t[a][o].length;s+=2)n&&(t[a][o][s+1]=t[a][o][s+1].replace(" ","_")),i&&(t[a][o][s+2]=t[a][o][s+2].replace(" ","_"))}(I,_,w),O.path=x(I),C=null;g(o);for(var W=e.editHelpers,X=(W||{}).modifyItem,Z=[],J=0;J<S.length;J++){var K=o._fullLayout.shapes[J];if(Z[J]=K._input,void 0!==A&&J===o._fullLayout._activeShapeIndex){var Q=O;switch(K.type){case"line":case"rect":case"circle":X("x0",Q.x0),X("x1",Q.x1),X("y0",Q.y0),X("y1",Q.y1);break;case"path":X("path",Q.path)}}}return void 0===A?(Z.push(O),Z):W?W.getUpdateObj():{}}}}},{"../../../plots/cartesian/handle_outline":565,"../../../plots/cartesian/helpers":566,"../../dragelement/helpers":384,"./constants":452,"./helpers":455}],457:[function(t,e,r){"use strict";var n=t("./constants"),i=t("../../lib");r.rangeToShapePosition=function(t){return"log"===t.type?t.r2d:function(t){return t}},r.shapePositionToRange=function(t){return"log"===t.type?t.d2r:function(t){return t}},r.decodeDate=function(t){return function(e){return e.replace&&(e=e.replace("_"," ")),t(e)}},r.encodeDate=function(t){return function(e){return t(e).replace(" ","_")}},r.extractPathCoords=function(t,e){var r=[];return t.match(n.segmentRE).forEach((function(t){var a=e[t.charAt(0)].drawn;if(void 0!==a){var o=t.substr(1).match(n.paramRE);!o||o.length<a||r.push(i.cleanNumber(o[a]))}})),r},r.getDataToPixel=function(t,e,n,i){var a,o=t._fullLayout._size;if(e)if("domain"===i)a=function(t){return e._length*(n?1-t:t)+e._offset};else{var s=r.shapePositionToRange(e);a=function(t){return e._offset+e.r2p(s(t,!0))},"date"===e.type&&(a=r.decodeDate(a))}else a=n?function(t){return o.t+o.h*(1-t)}:function(t){return o.l+o.w*t};return a},r.getPixelToData=function(t,e,n,i){var a,o=t._fullLayout._size;if(e)if("domain"===i)a=function(t){var r=(t-e._offset)/e._length;return n?1-r:r};else{var s=r.rangeToShapePosition(e);a=function(t){return s(e.p2r(t-e._offset))}}else a=n?function(t){return 1-(t-o.t)/o.h}:function(t){return(t-o.l)/o.w};return a},r.roundPositionForSharpStrokeRendering=function(t,e){var r=1===Math.round(e%2),n=Math.round(t);return r?n+.5:n},r.makeOptionsAndPlotinfo=function(t,e){var r=t._fullLayout.shapes[e]||{},n=t._fullLayout._plots[r.xref+r.yref];return!!n?n._hadPlotinfo=!0:(n={},r.xref&&"paper"!==r.xref&&(n.xaxis=t._fullLayout[r.xref+"axis"]),r.yref&&"paper"!==r.yref&&(n.yaxis=t._fullLayout[r.yref+"axis"])),n.xsizemode=r.xsizemode,n.ysizemode=r.ysizemode,n.xanchor=r.xanchor,n.yanchor=r.yanchor,{options:r,plotinfo:n}}},{"../../lib":503,"./constants":448}],458:[function(t,e,r){"use strict";var n=t("./draw");e.exports={moduleType:"component",name:"shapes",layoutAttributes:t("./attributes"),supplyLayoutDefaults:t("./defaults"),supplyDrawNewShapeDefaults:t("./draw_newshape/defaults"),includeBasePlot:t("../../plots/cartesian/include_components")("shapes"),calcAutorange:t("./calc_autorange"),draw:n.draw,drawOne:n.drawOne}},{"../../plots/cartesian/include_components":567,"./attributes":446,"./calc_autorange":447,"./defaults":449,"./draw":450,"./draw_newshape/defaults":453}],459:[function(t,e,r){"use strict";var n=t("../../plots/font_attributes"),i=t("../../plots/pad_attributes"),a=t("../../lib/extend").extendDeepAll,o=t("../../plot_api/edit_types").overrideAll,s=t("../../plots/animation_attributes"),l=t("../../plot_api/plot_template").templatedArray,c=t("./constants"),u=l("step",{visible:{valType:"boolean",dflt:!0},method:{valType:"enumerated",values:["restyle","relayout","animate","update","skip"],dflt:"restyle"},args:{valType:"info_array",freeLength:!0,items:[{valType:"any"},{valType:"any"},{valType:"any"}]},label:{valType:"string"},value:{valType:"string"},execute:{valType:"boolean",dflt:!0}});e.exports=o(l("slider",{visible:{valType:"boolean",dflt:!0},active:{valType:"number",min:0,dflt:0},steps:u,lenmode:{valType:"enumerated",values:["fraction","pixels"],dflt:"fraction"},len:{valType:"number",min:0,dflt:1},x:{valType:"number",min:-2,max:3,dflt:0},pad:a(i({editType:"arraydraw"}),{},{t:{dflt:20}}),xanchor:{valType:"enumerated",values:["auto","left","center","right"],dflt:"left"},y:{valType:"number",min:-2,max:3,dflt:0},yanchor:{valType:"enumerated",values:["auto","top","middle","bottom"],dflt:"top"},transition:{duration:{valType:"number",min:0,dflt:150},easing:{valType:"enumerated",values:s.transition.easing.values,dflt:"cubic-in-out"}},currentvalue:{visible:{valType:"boolean",dflt:!0},xanchor:{valType:"enumerated",values:["left","center","right"],dflt:"left"},offset:{valType:"number",dflt:10},prefix:{valType:"string"},suffix:{valType:"string"},font:n({})},font:n({}),activebgcolor:{valType:"color",dflt:c.gripBgActiveColor},bgcolor:{valType:"color",dflt:c.railBgColor},bordercolor:{valType:"color",dflt:c.railBorderColor},borderwidth:{valType:"number",min:0,dflt:c.railBorderWidth},ticklen:{valType:"number",min:0,dflt:c.tickLength},tickcolor:{valType:"color",dflt:c.tickColor},tickwidth:{valType:"number",min:0,dflt:1},minorticklen:{valType:"number",min:0,dflt:c.minorTickLength}}),"arraydraw","from-root")},{"../../lib/extend":493,"../../plot_api/edit_types":536,"../../plot_api/plot_template":543,"../../plots/animation_attributes":548,"../../plots/font_attributes":585,"../../plots/pad_attributes":618,"./constants":460}],460:[function(t,e,r){"use strict";e.exports={name:"sliders",containerClassName:"slider-container",groupClassName:"slider-group",inputAreaClass:"slider-input-area",railRectClass:"slider-rail-rect",railTouchRectClass:"slider-rail-touch-rect",gripRectClass:"slider-grip-rect",tickRectClass:"slider-tick-rect",inputProxyClass:"slider-input-proxy",labelsClass:"slider-labels",labelGroupClass:"slider-label-group",labelClass:"slider-label",currentValueClass:"slider-current-value",railHeight:5,menuIndexAttrName:"slider-active-index",autoMarginIdRoot:"slider-",minWidth:30,minHeight:30,textPadX:40,arrowOffsetX:4,railRadius:2,railWidth:5,railBorder:4,railBorderWidth:1,railBorderColor:"#bec8d9",railBgColor:"#f8fafc",railInset:8,stepInset:10,gripRadius:10,gripWidth:20,gripHeight:20,gripBorder:20,gripBorderWidth:1,gripBorderColor:"#bec8d9",gripBgColor:"#f6f8fa",gripBgActiveColor:"#dbdde0",labelPadding:8,labelOffset:0,tickWidth:1,tickColor:"#333",tickOffset:25,tickLength:7,minorTickOffset:25,minorTickColor:"#333",minorTickLength:4,currentValuePadding:8,currentValueInset:0}},{}],461:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/array_container_defaults"),a=t("./attributes"),o=t("./constants").name,s=a.steps;function l(t,e,r){function o(r,i){return n.coerce(t,e,a,r,i)}for(var s=i(t,e,{name:"steps",handleItemDefaults:c}),l=0,u=0;u<s.length;u++)s[u].visible&&l++;if(l<2?e.visible=!1:o("visible")){e._stepCount=l;var f=e._visibleSteps=n.filterVisible(s);(s[o("active")]||{}).visible||(e.active=f[0]._index),o("x"),o("y"),n.noneOrAll(t,e,["x","y"]),o("xanchor"),o("yanchor"),o("len"),o("lenmode"),o("pad.t"),o("pad.r"),o("pad.b"),o("pad.l"),n.coerceFont(o,"font",r.font),o("currentvalue.visible")&&(o("currentvalue.xanchor"),o("currentvalue.prefix"),o("currentvalue.suffix"),o("currentvalue.offset"),n.coerceFont(o,"currentvalue.font",e.font)),o("transition.duration"),o("transition.easing"),o("bgcolor"),o("activebgcolor"),o("bordercolor"),o("borderwidth"),o("ticklen"),o("tickwidth"),o("tickcolor"),o("minorticklen")}}function c(t,e){function r(r,i){return n.coerce(t,e,s,r,i)}if("skip"===t.method||Array.isArray(t.args)?r("visible"):e.visible=!1){r("method"),r("args");var i=r("label","step-"+e._index);r("value",i),r("execute")}}e.exports=function(t,e){i(t,e,{name:o,handleItemDefaults:l})}},{"../../lib":503,"../../plots/array_container_defaults":549,"./attributes":459,"./constants":460}],462:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../plots/plots"),a=t("../color"),o=t("../drawing"),s=t("../../lib"),l=s.strTranslate,c=t("../../lib/svg_text_utils"),u=t("../../plot_api/plot_template").arrayEditor,f=t("./constants"),h=t("../../constants/alignment"),p=h.LINE_SPACING,d=h.FROM_TL,m=h.FROM_BR;function g(t){return f.autoMarginIdRoot+t._index}function v(t){return t._index}function y(t,e){var r=o.tester.selectAll("g."+f.labelGroupClass).data(e._visibleSteps);r.enter().append("g").classed(f.labelGroupClass,!0);var a=0,l=0;r.each((function(t){var r=_(n.select(this),{step:t},e).node();if(r){var i=o.bBox(r);l=Math.max(l,i.height),a=Math.max(a,i.width)}})),r.remove();var u=e._dims={};u.inputAreaWidth=Math.max(f.railWidth,f.gripHeight);var h=t._fullLayout._size;u.lx=h.l+h.w*e.x,u.ly=h.t+h.h*(1-e.y),"fraction"===e.lenmode?u.outerLength=Math.round(h.w*e.len):u.outerLength=e.len,u.inputAreaStart=0,u.inputAreaLength=Math.round(u.outerLength-e.pad.l-e.pad.r);var p=(u.inputAreaLength-2*f.stepInset)/(e._stepCount-1),v=a+f.labelPadding;if(u.labelStride=Math.max(1,Math.ceil(v/p)),u.labelHeight=l,u.currentValueMaxWidth=0,u.currentValueHeight=0,u.currentValueTotalHeight=0,u.currentValueMaxLines=1,e.currentvalue.visible){var y=o.tester.append("g");r.each((function(t){var r=x(y,e,t.label),n=r.node()&&o.bBox(r.node())||{width:0,height:0},i=c.lineCount(r);u.currentValueMaxWidth=Math.max(u.currentValueMaxWidth,Math.ceil(n.width)),u.currentValueHeight=Math.max(u.currentValueHeight,Math.ceil(n.height)),u.currentValueMaxLines=Math.max(u.currentValueMaxLines,i)})),u.currentValueTotalHeight=u.currentValueHeight+e.currentvalue.offset,y.remove()}u.height=u.currentValueTotalHeight+f.tickOffset+e.ticklen+f.labelOffset+u.labelHeight+e.pad.t+e.pad.b;var b="left";s.isRightAnchor(e)&&(u.lx-=u.outerLength,b="right"),s.isCenterAnchor(e)&&(u.lx-=u.outerLength/2,b="center");var w="top";s.isBottomAnchor(e)&&(u.ly-=u.height,w="bottom"),s.isMiddleAnchor(e)&&(u.ly-=u.height/2,w="middle"),u.outerLength=Math.ceil(u.outerLength),u.height=Math.ceil(u.height),u.lx=Math.round(u.lx),u.ly=Math.round(u.ly);var T={y:e.y,b:u.height*m[w],t:u.height*d[w]};"fraction"===e.lenmode?(T.l=0,T.xl=e.x-e.len*d[b],T.r=0,T.xr=e.x+e.len*m[b]):(T.x=e.x,T.l=u.outerLength*d[b],T.r=u.outerLength*m[b]),i.autoMargin(t,g(e),T)}function x(t,e,r){if(e.currentvalue.visible){var n,i,a=e._dims;switch(e.currentvalue.xanchor){case"right":n=a.inputAreaLength-f.currentValueInset-a.currentValueMaxWidth,i="left";break;case"center":n=.5*a.inputAreaLength,i="middle";break;default:n=f.currentValueInset,i="left"}var l=s.ensureSingle(t,"text",f.labelClass,(function(t){t.attr({"text-anchor":i,"data-notex":1})})),u=e.currentvalue.prefix?e.currentvalue.prefix:"";if("string"==typeof r)u+=r;else{var h=e.steps[e.active].label,d=e._gd._fullLayout._meta;d&&(h=s.templateString(h,d)),u+=h}e.currentvalue.suffix&&(u+=e.currentvalue.suffix),l.call(o.font,e.currentvalue.font).text(u).call(c.convertToTspans,e._gd);var m=c.lineCount(l),g=(a.currentValueMaxLines+1-m)*e.currentvalue.font.size*p;return c.positionText(l,n,g),l}}function b(t,e,r){s.ensureSingle(t,"rect",f.gripRectClass,(function(n){n.call(A,e,t,r).style("pointer-events","all")})).attr({width:f.gripWidth,height:f.gripHeight,rx:f.gripRadius,ry:f.gripRadius}).call(a.stroke,r.bordercolor).call(a.fill,r.bgcolor).style("stroke-width",r.borderwidth+"px")}function _(t,e,r){var n=s.ensureSingle(t,"text",f.labelClass,(function(t){t.attr({"text-anchor":"middle","data-notex":1})})),i=e.step.label,a=r._gd._fullLayout._meta;return a&&(i=s.templateString(i,a)),n.call(o.font,r.font).text(i).call(c.convertToTspans,r._gd),n}function w(t,e){var r=s.ensureSingle(t,"g",f.labelsClass),i=e._dims,a=r.selectAll("g."+f.labelGroupClass).data(i.labelSteps);a.enter().append("g").classed(f.labelGroupClass,!0),a.exit().remove(),a.each((function(t){var r=n.select(this);r.call(_,t,e),o.setTranslate(r,E(e,t.fraction),f.tickOffset+e.ticklen+e.font.size*p+f.labelOffset+i.currentValueTotalHeight)}))}function T(t,e,r,n,i){var a=Math.round(n*(r._stepCount-1)),o=r._visibleSteps[a]._index;o!==r.active&&k(t,e,r,o,!0,i)}function k(t,e,r,n,a,o){var s=r.active;r.active=n,u(t.layout,f.name,r).applyUpdate("active",n);var l=r.steps[r.active];e.call(S,r,o),e.call(x,r),t.emit("plotly_sliderchange",{slider:r,step:r.steps[r.active],interaction:a,previousActive:s}),l&&l.method&&a&&(e._nextMethod?(e._nextMethod.step=l,e._nextMethod.doCallback=a,e._nextMethod.doTransition=o):(e._nextMethod={step:l,doCallback:a,doTransition:o},e._nextMethodRaf=window.requestAnimationFrame((function(){var r=e._nextMethod.step;r.method&&(r.execute&&i.executeAPICommand(t,r.method,r.args),e._nextMethod=null,e._nextMethodRaf=null)}))))}function A(t,e,r){var i=r.node(),o=n.select(e);function s(){return r.data()[0]}function l(){var t=s();e.emit("plotly_sliderstart",{slider:t});var l=r.select("."+f.gripRectClass);n.event.stopPropagation(),n.event.preventDefault(),l.call(a.fill,t.activebgcolor);var c=L(t,n.mouse(i)[0]);function u(){var t=s(),a=L(t,n.mouse(i)[0]);T(e,r,t,a,!1)}function h(){var t=s();t._dragging=!1,l.call(a.fill,t.bgcolor),o.on("mouseup",null),o.on("mousemove",null),o.on("touchend",null),o.on("touchmove",null),e.emit("plotly_sliderend",{slider:t,step:t.steps[t.active]})}T(e,r,t,c,!0),t._dragging=!0,o.on("mousemove",u),o.on("touchmove",u),o.on("mouseup",h),o.on("touchend",h)}t.on("mousedown",l),t.on("touchstart",l)}function M(t,e){var r=t.selectAll("rect."+f.tickRectClass).data(e._visibleSteps),i=e._dims;r.enter().append("rect").classed(f.tickRectClass,!0),r.exit().remove(),r.attr({width:e.tickwidth+"px","shape-rendering":"crispEdges"}),r.each((function(t,r){var s=r%i.labelStride==0,l=n.select(this);l.attr({height:s?e.ticklen:e.minorticklen}).call(a.fill,e.tickcolor),o.setTranslate(l,E(e,r/(e._stepCount-1))-.5*e.tickwidth,(s?f.tickOffset:f.minorTickOffset)+i.currentValueTotalHeight)}))}function S(t,e,r){for(var n=t.select("rect."+f.gripRectClass),i=0,a=0;a<e._stepCount;a++)if(e._visibleSteps[a]._index===e.active){i=a;break}var o=E(e,i/(e._stepCount-1));if(!e._invokingCommand){var s=n;r&&e.transition.duration>0&&(s=s.transition().duration(e.transition.duration).ease(e.transition.easing)),s.attr("transform",l(o-.5*f.gripWidth,e._dims.currentValueTotalHeight))}}function E(t,e){var r=t._dims;return r.inputAreaStart+f.stepInset+(r.inputAreaLength-2*f.stepInset)*Math.min(1,Math.max(0,e))}function L(t,e){var r=t._dims;return Math.min(1,Math.max(0,(e-f.stepInset-r.inputAreaStart)/(r.inputAreaLength-2*f.stepInset-2*r.inputAreaStart)))}function C(t,e,r){var n=r._dims,i=s.ensureSingle(t,"rect",f.railTouchRectClass,(function(n){n.call(A,e,t,r).style("pointer-events","all")}));i.attr({width:n.inputAreaLength,height:Math.max(n.inputAreaWidth,f.tickOffset+r.ticklen+n.labelHeight)}).call(a.fill,r.bgcolor).attr("opacity",0),o.setTranslate(i,0,n.currentValueTotalHeight)}function P(t,e){var r=e._dims,n=r.inputAreaLength-2*f.railInset,i=s.ensureSingle(t,"rect",f.railRectClass);i.attr({width:n,height:f.railWidth,rx:f.railRadius,ry:f.railRadius,"shape-rendering":"crispEdges"}).call(a.stroke,e.bordercolor).call(a.fill,e.bgcolor).style("stroke-width",e.borderwidth+"px"),o.setTranslate(i,f.railInset,.5*(r.inputAreaWidth-f.railWidth)+r.currentValueTotalHeight)}e.exports=function(t){var e=t._fullLayout,r=function(t,e){for(var r=t[f.name],n=[],i=0;i<r.length;i++){var a=r[i];a.visible&&(a._gd=e,n.push(a))}return n}(e,t),a=e._infolayer.selectAll("g."+f.containerClassName).data(r.length>0?[0]:[]);function s(e){e._commandObserver&&(e._commandObserver.remove(),delete e._commandObserver),i.autoMargin(t,g(e))}if(a.enter().append("g").classed(f.containerClassName,!0).style("cursor","ew-resize"),a.exit().each((function(){n.select(this).selectAll("g."+f.groupClassName).each(s)})).remove(),0!==r.length){var l=a.selectAll("g."+f.groupClassName).data(r,v);l.enter().append("g").classed(f.groupClassName,!0),l.exit().each(s).remove();for(var c=0;c<r.length;c++){var u=r[c];y(t,u)}l.each((function(e){var r=n.select(this);!function(t){var e=t._dims;e.labelSteps=[];for(var r=t._stepCount,n=0;n<r;n+=e.labelStride)e.labelSteps.push({fraction:n/(r-1),step:t._visibleSteps[n]})}(e),i.manageCommandObserver(t,e,e._visibleSteps,(function(e){var n=r.data()[0];n.active!==e.index&&(n._dragging||k(t,r,n,e.index,!1,!0))})),function(t,e,r){(r.steps[r.active]||{}).visible||(r.active=r._visibleSteps[0]._index);e.call(x,r).call(P,r).call(w,r).call(M,r).call(C,t,r).call(b,t,r);var n=r._dims;o.setTranslate(e,n.lx+r.pad.l,n.ly+r.pad.t),e.call(S,r,!1),e.call(x,r)}(t,n.select(this),e)}))}}},{"../../constants/alignment":471,"../../lib":503,"../../lib/svg_text_utils":529,"../../plot_api/plot_template":543,"../../plots/plots":619,"../color":366,"../drawing":388,"./constants":460,"@plotly/d3":58}],463:[function(t,e,r){"use strict";var n=t("./constants");e.exports={moduleType:"component",name:n.name,layoutAttributes:t("./attributes"),supplyLayoutDefaults:t("./defaults"),draw:t("./draw")}},{"./attributes":459,"./constants":460,"./defaults":461,"./draw":462}],464:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("fast-isnumeric"),a=t("../../plots/plots"),o=t("../../registry"),s=t("../../lib"),l=s.strTranslate,c=t("../drawing"),u=t("../color"),f=t("../../lib/svg_text_utils"),h=t("../../constants/interactions"),p=t("../../constants/alignment").OPPOSITE_SIDE,d=/ [XY][0-9]* /;e.exports={draw:function(t,e,r){var m,g=r.propContainer,v=r.propName,y=r.placeholder,x=r.traceIndex,b=r.avoid||{},_=r.attributes,w=r.transform,T=r.containerGroup,k=t._fullLayout,A=1,M=!1,S=g.title,E=(S&&S.text?S.text:"").trim(),L=S&&S.font?S.font:{},C=L.family,P=L.size,I=L.color;"title.text"===v?m="titleText":-1!==v.indexOf("axis")?m="axisTitleText":v.indexOf(!0)&&(m="colorbarTitleText");var O=t._context.edits[m];""===E?A=0:E.replace(d," % ")===y.replace(d," % ")&&(A=.2,M=!0,O||(E="")),r._meta?E=s.templateString(E,r._meta):k._meta&&(E=s.templateString(E,k._meta));var z,D=E||O;T||(T=s.ensureSingle(k._infolayer,"g","g-"+e),z=k._hColorbarMoveTitle);var R=T.selectAll("text").data(D?[0]:[]);if(R.enter().append("text"),R.text(E).attr("class",e),R.exit().remove(),!D)return T;function F(t){s.syncOrAsync([B,N],t)}function B(e){var r;return!w&&z&&(w={}),w?(r="",w.rotate&&(r+="rotate("+[w.rotate,_.x,_.y]+")"),(w.offset||z)&&(r+=l(0,(w.offset||0)-(z||0)))):r=null,e.attr("transform",r),e.style({"font-family":C,"font-size":n.round(P,2)+"px",fill:u.rgb(I),opacity:A*u.opacity(I),"font-weight":a.fontWeight}).attr(_).call(f.convertToTspans,t),a.previousPromises(t)}function N(t){var e=n.select(t.node().parentNode);if(b&&b.selection&&b.side&&E){e.attr("transform",null);var r=p[b.side],a="left"===b.side||"top"===b.side?-1:1,o=i(b.pad)?b.pad:2,u=c.bBox(e.node()),f={left:0,top:0,right:k.width,bottom:k.height},h=b.maxShift||a*(f[b.side]-u[b.side]),d=0;if(h<0)d=h;else{var m=b.offsetLeft||0,g=b.offsetTop||0;u.left-=m,u.right-=m,u.top-=g,u.bottom-=g,b.selection.each((function(){var t=c.bBox(this);s.bBoxIntersect(u,t,o)&&(d=Math.max(d,a*(t[b.side]-u[r])+o))})),d=Math.min(h,d)}if(d>0||h<0){var v={left:[-d,0],right:[d,0],top:[0,-d],bottom:[0,d]}[b.side];e.attr("transform",l(v[0],v[1]))}}}return R.call(F),O&&(E?R.on(".opacity",null):(A=0,M=!0,R.text(y).on("mouseover.opacity",(function(){n.select(this).transition().duration(h.SHOW_PLACEHOLDER).style("opacity",1)})).on("mouseout.opacity",(function(){n.select(this).transition().duration(h.HIDE_PLACEHOLDER).style("opacity",0)}))),R.call(f.makeEditable,{gd:t}).on("edit",(function(e){void 0!==x?o.call("_guiRestyle",t,v,e,x):o.call("_guiRelayout",t,v,e)})).on("cancel",(function(){this.text(this.attr("data-unformatted")).call(F)})).on("input",(function(t){this.text(t||" ").call(f.positionText,_.x,_.y)}))),R.classed("js-placeholder",M),T}}},{"../../constants/alignment":471,"../../constants/interactions":478,"../../lib":503,"../../lib/svg_text_utils":529,"../../plots/plots":619,"../../registry":638,"../color":366,"../drawing":388,"@plotly/d3":58,"fast-isnumeric":190}],465:[function(t,e,r){"use strict";var n=t("../../plots/font_attributes"),i=t("../color/attributes"),a=t("../../lib/extend").extendFlat,o=t("../../plot_api/edit_types").overrideAll,s=t("../../plots/pad_attributes"),l=t("../../plot_api/plot_template").templatedArray,c=l("button",{visible:{valType:"boolean"},method:{valType:"enumerated",values:["restyle","relayout","animate","update","skip"],dflt:"restyle"},args:{valType:"info_array",freeLength:!0,items:[{valType:"any"},{valType:"any"},{valType:"any"}]},args2:{valType:"info_array",freeLength:!0,items:[{valType:"any"},{valType:"any"},{valType:"any"}]},label:{valType:"string",dflt:""},execute:{valType:"boolean",dflt:!0}});e.exports=o(l("updatemenu",{_arrayAttrRegexps:[/^updatemenus\[(0|[1-9][0-9]+)\]\.buttons/],visible:{valType:"boolean"},type:{valType:"enumerated",values:["dropdown","buttons"],dflt:"dropdown"},direction:{valType:"enumerated",values:["left","right","up","down"],dflt:"down"},active:{valType:"integer",min:-1,dflt:0},showactive:{valType:"boolean",dflt:!0},buttons:c,x:{valType:"number",min:-2,max:3,dflt:-.05},xanchor:{valType:"enumerated",values:["auto","left","center","right"],dflt:"right"},y:{valType:"number",min:-2,max:3,dflt:1},yanchor:{valType:"enumerated",values:["auto","top","middle","bottom"],dflt:"top"},pad:a(s({editType:"arraydraw"}),{}),font:n({}),bgcolor:{valType:"color"},bordercolor:{valType:"color",dflt:i.borderLine},borderwidth:{valType:"number",min:0,dflt:1,editType:"arraydraw"}}),"arraydraw","from-root")},{"../../lib/extend":493,"../../plot_api/edit_types":536,"../../plot_api/plot_template":543,"../../plots/font_attributes":585,"../../plots/pad_attributes":618,"../color/attributes":365}],466:[function(t,e,r){"use strict";e.exports={name:"updatemenus",containerClassName:"updatemenu-container",headerGroupClassName:"updatemenu-header-group",headerClassName:"updatemenu-header",headerArrowClassName:"updatemenu-header-arrow",dropdownButtonGroupClassName:"updatemenu-dropdown-button-group",dropdownButtonClassName:"updatemenu-dropdown-button",buttonClassName:"updatemenu-button",itemRectClassName:"updatemenu-item-rect",itemTextClassName:"updatemenu-item-text",menuIndexAttrName:"updatemenu-active-index",autoMarginIdRoot:"updatemenu-",blankHeaderOpts:{label:"  "},minWidth:30,minHeight:30,textPadX:24,arrowPadX:16,rx:2,ry:2,textOffsetX:12,textOffsetY:3,arrowOffsetX:4,gapButtonHeader:5,gapButton:2,activeColor:"#F4FAFF",hoverColor:"#F4FAFF",arrowSymbol:{left:"\u25c4",right:"\u25ba",up:"\u25b2",down:"\u25bc"}}},{}],467:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/array_container_defaults"),a=t("./attributes"),o=t("./constants").name,s=a.buttons;function l(t,e,r){function o(r,i){return n.coerce(t,e,a,r,i)}o("visible",i(t,e,{name:"buttons",handleItemDefaults:c}).length>0)&&(o("active"),o("direction"),o("type"),o("showactive"),o("x"),o("y"),n.noneOrAll(t,e,["x","y"]),o("xanchor"),o("yanchor"),o("pad.t"),o("pad.r"),o("pad.b"),o("pad.l"),n.coerceFont(o,"font",r.font),o("bgcolor",r.paper_bgcolor),o("bordercolor"),o("borderwidth"))}function c(t,e){function r(r,i){return n.coerce(t,e,s,r,i)}r("visible","skip"===t.method||Array.isArray(t.args))&&(r("method"),r("args"),r("args2"),r("label"),r("execute"))}e.exports=function(t,e){i(t,e,{name:o,handleItemDefaults:l})}},{"../../lib":503,"../../plots/array_container_defaults":549,"./attributes":465,"./constants":466}],468:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../plots/plots"),a=t("../color"),o=t("../drawing"),s=t("../../lib"),l=t("../../lib/svg_text_utils"),c=t("../../plot_api/plot_template").arrayEditor,u=t("../../constants/alignment").LINE_SPACING,f=t("./constants"),h=t("./scrollbox");function p(t){return t._index}function d(t,e){return+t.attr(f.menuIndexAttrName)===e._index}function m(t,e,r,n,i,a,o,s){e.active=o,c(t.layout,f.name,e).applyUpdate("active",o),"buttons"===e.type?v(t,n,null,null,e):"dropdown"===e.type&&(i.attr(f.menuIndexAttrName,"-1"),g(t,n,i,a,e),s||v(t,n,i,a,e))}function g(t,e,r,n,i){var a=s.ensureSingle(e,"g",f.headerClassName,(function(t){t.style("pointer-events","all")})),l=i._dims,c=i.active,u=i.buttons[c]||f.blankHeaderOpts,h={y:i.pad.t,yPad:0,x:i.pad.l,xPad:0,index:0},p={width:l.headerWidth,height:l.headerHeight};a.call(y,i,u,t).call(M,i,h,p),s.ensureSingle(e,"text",f.headerArrowClassName,(function(t){t.attr("text-anchor","end").call(o.font,i.font).text(f.arrowSymbol[i.direction])})).attr({x:l.headerWidth-f.arrowOffsetX+i.pad.l,y:l.headerHeight/2+f.textOffsetY+i.pad.t}),a.on("click",(function(){r.call(S,String(d(r,i)?-1:i._index)),v(t,e,r,n,i)})),a.on("mouseover",(function(){a.call(w)})),a.on("mouseout",(function(){a.call(T,i)})),o.setTranslate(e,l.lx,l.ly)}function v(t,e,r,a,o){r||(r=e).attr("pointer-events","all");var l=function(t){return-1==+t.attr(f.menuIndexAttrName)}(r)&&"buttons"!==o.type?[]:o.buttons,c="dropdown"===o.type?f.dropdownButtonClassName:f.buttonClassName,u=r.selectAll("g."+c).data(s.filterVisible(l)),h=u.enter().append("g").classed(c,!0),p=u.exit();"dropdown"===o.type?(h.attr("opacity","0").transition().attr("opacity","1"),p.transition().attr("opacity","0").remove()):p.remove();var d=0,g=0,v=o._dims,x=-1!==["up","down"].indexOf(o.direction);"dropdown"===o.type&&(x?g=v.headerHeight+f.gapButtonHeader:d=v.headerWidth+f.gapButtonHeader),"dropdown"===o.type&&"up"===o.direction&&(g=-f.gapButtonHeader+f.gapButton-v.openHeight),"dropdown"===o.type&&"left"===o.direction&&(d=-f.gapButtonHeader+f.gapButton-v.openWidth);var b={x:v.lx+d+o.pad.l,y:v.ly+g+o.pad.t,yPad:f.gapButton,xPad:f.gapButton,index:0},k={l:b.x+o.borderwidth,t:b.y+o.borderwidth};u.each((function(s,l){var c=n.select(this);c.call(y,o,s,t).call(M,o,b),c.on("click",(function(){n.event.defaultPrevented||(s.execute&&(s.args2&&o.active===l?(m(t,o,0,e,r,a,-1),i.executeAPICommand(t,s.method,s.args2)):(m(t,o,0,e,r,a,l),i.executeAPICommand(t,s.method,s.args))),t.emit("plotly_buttonclicked",{menu:o,button:s,active:o.active}))})),c.on("mouseover",(function(){c.call(w)})),c.on("mouseout",(function(){c.call(T,o),u.call(_,o)}))})),u.call(_,o),x?(k.w=Math.max(v.openWidth,v.headerWidth),k.h=b.y-k.t):(k.w=b.x-k.l,k.h=Math.max(v.openHeight,v.headerHeight)),k.direction=o.direction,a&&(u.size()?function(t,e,r,n,i,a){var o,s,l,c=i.direction,u="up"===c||"down"===c,h=i._dims,p=i.active;if(u)for(s=0,l=0;l<p;l++)s+=h.heights[l]+f.gapButton;else for(o=0,l=0;l<p;l++)o+=h.widths[l]+f.gapButton;n.enable(a,o,s),n.hbar&&n.hbar.attr("opacity","0").transition().attr("opacity","1");n.vbar&&n.vbar.attr("opacity","0").transition().attr("opacity","1")}(0,0,0,a,o,k):function(t){var e=!!t.hbar,r=!!t.vbar;e&&t.hbar.transition().attr("opacity","0").each("end",(function(){e=!1,r||t.disable()}));r&&t.vbar.transition().attr("opacity","0").each("end",(function(){r=!1,e||t.disable()}))}(a))}function y(t,e,r,n){t.call(x,e).call(b,e,r,n)}function x(t,e){s.ensureSingle(t,"rect",f.itemRectClassName,(function(t){t.attr({rx:f.rx,ry:f.ry,"shape-rendering":"crispEdges"})})).call(a.stroke,e.bordercolor).call(a.fill,e.bgcolor).style("stroke-width",e.borderwidth+"px")}function b(t,e,r,n){var i=s.ensureSingle(t,"text",f.itemTextClassName,(function(t){t.attr({"text-anchor":"start","data-notex":1})})),a=r.label,c=n._fullLayout._meta;c&&(a=s.templateString(a,c)),i.call(o.font,e.font).text(a).call(l.convertToTspans,n)}function _(t,e){var r=e.active;t.each((function(t,i){var o=n.select(this);i===r&&e.showactive&&o.select("rect."+f.itemRectClassName).call(a.fill,f.activeColor)}))}function w(t){t.select("rect."+f.itemRectClassName).call(a.fill,f.hoverColor)}function T(t,e){t.select("rect."+f.itemRectClassName).call(a.fill,e.bgcolor)}function k(t,e){var r=e._dims={width1:0,height1:0,heights:[],widths:[],totalWidth:0,totalHeight:0,openWidth:0,openHeight:0,lx:0,ly:0},a=o.tester.selectAll("g."+f.dropdownButtonClassName).data(s.filterVisible(e.buttons));a.enter().append("g").classed(f.dropdownButtonClassName,!0);var c=-1!==["up","down"].indexOf(e.direction);a.each((function(i,a){var s=n.select(this);s.call(y,e,i,t);var h=s.select("."+f.itemTextClassName),p=h.node()&&o.bBox(h.node()).width,d=Math.max(p+f.textPadX,f.minWidth),m=e.font.size*u,g=l.lineCount(h),v=Math.max(m*g,f.minHeight)+f.textOffsetY;v=Math.ceil(v),d=Math.ceil(d),r.widths[a]=d,r.heights[a]=v,r.height1=Math.max(r.height1,v),r.width1=Math.max(r.width1,d),c?(r.totalWidth=Math.max(r.totalWidth,d),r.openWidth=r.totalWidth,r.totalHeight+=v+f.gapButton,r.openHeight+=v+f.gapButton):(r.totalWidth+=d+f.gapButton,r.openWidth+=d+f.gapButton,r.totalHeight=Math.max(r.totalHeight,v),r.openHeight=r.totalHeight)})),c?r.totalHeight-=f.gapButton:r.totalWidth-=f.gapButton,r.headerWidth=r.width1+f.arrowPadX,r.headerHeight=r.height1,"dropdown"===e.type&&(c?(r.width1+=f.arrowPadX,r.totalHeight=r.height1):r.totalWidth=r.width1,r.totalWidth+=f.arrowPadX),a.remove();var h=r.totalWidth+e.pad.l+e.pad.r,p=r.totalHeight+e.pad.t+e.pad.b,d=t._fullLayout._size;r.lx=d.l+d.w*e.x,r.ly=d.t+d.h*(1-e.y);var m="left";s.isRightAnchor(e)&&(r.lx-=h,m="right"),s.isCenterAnchor(e)&&(r.lx-=h/2,m="center");var g="top";s.isBottomAnchor(e)&&(r.ly-=p,g="bottom"),s.isMiddleAnchor(e)&&(r.ly-=p/2,g="middle"),r.totalWidth=Math.ceil(r.totalWidth),r.totalHeight=Math.ceil(r.totalHeight),r.lx=Math.round(r.lx),r.ly=Math.round(r.ly),i.autoMargin(t,A(e),{x:e.x,y:e.y,l:h*({right:1,center:.5}[m]||0),r:h*({left:1,center:.5}[m]||0),b:p*({top:1,middle:.5}[g]||0),t:p*({bottom:1,middle:.5}[g]||0)})}function A(t){return f.autoMarginIdRoot+t._index}function M(t,e,r,n){n=n||{};var i=t.select("."+f.itemRectClassName),a=t.select("."+f.itemTextClassName),s=e.borderwidth,c=r.index,h=e._dims;o.setTranslate(t,s+r.x,s+r.y);var p=-1!==["up","down"].indexOf(e.direction),d=n.height||(p?h.heights[c]:h.height1);i.attr({x:0,y:0,width:n.width||(p?h.width1:h.widths[c]),height:d});var m=e.font.size*u,g=(l.lineCount(a)-1)*m/2;l.positionText(a,f.textOffsetX,d/2-g+f.textOffsetY),p?r.y+=h.heights[c]+r.yPad:r.x+=h.widths[c]+r.xPad,r.index++}function S(t,e){t.attr(f.menuIndexAttrName,e||"-1").selectAll("g."+f.dropdownButtonClassName).remove()}e.exports=function(t){var e=t._fullLayout,r=s.filterVisible(e[f.name]);function a(e){i.autoMargin(t,A(e))}var o=e._menulayer.selectAll("g."+f.containerClassName).data(r.length>0?[0]:[]);if(o.enter().append("g").classed(f.containerClassName,!0).style("cursor","pointer"),o.exit().each((function(){n.select(this).selectAll("g."+f.headerGroupClassName).each(a)})).remove(),0!==r.length){var l=o.selectAll("g."+f.headerGroupClassName).data(r,p);l.enter().append("g").classed(f.headerGroupClassName,!0);for(var c=s.ensureSingle(o,"g",f.dropdownButtonGroupClassName,(function(t){t.style("pointer-events","all")})),u=0;u<r.length;u++){var y=r[u];k(t,y)}var x="updatemenus"+e._uid,b=new h(t,c,x);l.enter().size()&&(c.node().parentNode.appendChild(c.node()),c.call(S)),l.exit().each((function(t){c.call(S),a(t)})).remove(),l.each((function(e){var r=n.select(this),a="dropdown"===e.type?c:null;i.manageCommandObserver(t,e,e.buttons,(function(n){m(t,e,e.buttons[n.index],r,a,b,n.index,!0)})),"dropdown"===e.type?(g(t,r,c,b,e),d(c,e)&&v(t,r,c,b,e)):v(t,r,null,null,e)}))}}},{"../../constants/alignment":471,"../../lib":503,"../../lib/svg_text_utils":529,"../../plot_api/plot_template":543,"../../plots/plots":619,"../color":366,"../drawing":388,"./constants":466,"./scrollbox":470,"@plotly/d3":58}],469:[function(t,e,r){arguments[4][463][0].apply(r,arguments)},{"./attributes":465,"./constants":466,"./defaults":467,"./draw":468,dup:463}],470:[function(t,e,r){"use strict";e.exports=s;var n=t("@plotly/d3"),i=t("../color"),a=t("../drawing"),o=t("../../lib");function s(t,e,r){this.gd=t,this.container=e,this.id=r,this.position=null,this.translateX=null,this.translateY=null,this.hbar=null,this.vbar=null,this.bg=this.container.selectAll("rect.scrollbox-bg").data([0]),this.bg.exit().on(".drag",null).on("wheel",null).remove(),this.bg.enter().append("rect").classed("scrollbox-bg",!0).style("pointer-events","all").attr({opacity:0,x:0,y:0,width:0,height:0})}s.barWidth=2,s.barLength=20,s.barRadius=2,s.barPad=1,s.barColor="#808BA4",s.prototype.enable=function(t,e,r){var o=this.gd._fullLayout,l=o.width,c=o.height;this.position=t;var u,f,h,p,d=this.position.l,m=this.position.w,g=this.position.t,v=this.position.h,y=this.position.direction,x="down"===y,b="left"===y,_="up"===y,w=m,T=v;x||b||"right"===y||_||(this.position.direction="down",x=!0),x||_?(f=(u=d)+w,x?(h=g,T=(p=Math.min(h+T,c))-h):T=(p=g+T)-(h=Math.max(p-T,0))):(p=(h=g)+T,b?w=(f=d+w)-(u=Math.max(f-w,0)):(u=d,w=(f=Math.min(u+w,l))-u)),this._box={l:u,t:h,w:w,h:T};var k=m>w,A=s.barLength+2*s.barPad,M=s.barWidth+2*s.barPad,S=d,E=g+v;E+M>c&&(E=c-M);var L=this.container.selectAll("rect.scrollbar-horizontal").data(k?[0]:[]);L.exit().on(".drag",null).remove(),L.enter().append("rect").classed("scrollbar-horizontal",!0).call(i.fill,s.barColor),k?(this.hbar=L.attr({rx:s.barRadius,ry:s.barRadius,x:S,y:E,width:A,height:M}),this._hbarXMin=S+A/2,this._hbarTranslateMax=w-A):(delete this.hbar,delete this._hbarXMin,delete this._hbarTranslateMax);var C=v>T,P=s.barWidth+2*s.barPad,I=s.barLength+2*s.barPad,O=d+m,z=g;O+P>l&&(O=l-P);var D=this.container.selectAll("rect.scrollbar-vertical").data(C?[0]:[]);D.exit().on(".drag",null).remove(),D.enter().append("rect").classed("scrollbar-vertical",!0).call(i.fill,s.barColor),C?(this.vbar=D.attr({rx:s.barRadius,ry:s.barRadius,x:O,y:z,width:P,height:I}),this._vbarYMin=z+I/2,this._vbarTranslateMax=T-I):(delete this.vbar,delete this._vbarYMin,delete this._vbarTranslateMax);var R=this.id,F=u-.5,B=C?f+P+.5:f+.5,N=h-.5,j=k?p+M+.5:p+.5,U=o._topdefs.selectAll("#"+R).data(k||C?[0]:[]);if(U.exit().remove(),U.enter().append("clipPath").attr("id",R).append("rect"),k||C?(this._clipRect=U.select("rect").attr({x:Math.floor(F),y:Math.floor(N),width:Math.ceil(B)-Math.floor(F),height:Math.ceil(j)-Math.floor(N)}),this.container.call(a.setClipUrl,R,this.gd),this.bg.attr({x:d,y:g,width:m,height:v})):(this.bg.attr({width:0,height:0}),this.container.on("wheel",null).on(".drag",null).call(a.setClipUrl,null),delete this._clipRect),k||C){var V=n.behavior.drag().on("dragstart",(function(){n.event.sourceEvent.preventDefault()})).on("drag",this._onBoxDrag.bind(this));this.container.on("wheel",null).on("wheel",this._onBoxWheel.bind(this)).on(".drag",null).call(V);var H=n.behavior.drag().on("dragstart",(function(){n.event.sourceEvent.preventDefault(),n.event.sourceEvent.stopPropagation()})).on("drag",this._onBarDrag.bind(this));k&&this.hbar.on(".drag",null).call(H),C&&this.vbar.on(".drag",null).call(H)}this.setTranslate(e,r)},s.prototype.disable=function(){(this.hbar||this.vbar)&&(this.bg.attr({width:0,height:0}),this.container.on("wheel",null).on(".drag",null).call(a.setClipUrl,null),delete this._clipRect),this.hbar&&(this.hbar.on(".drag",null),this.hbar.remove(),delete this.hbar,delete this._hbarXMin,delete this._hbarTranslateMax),this.vbar&&(this.vbar.on(".drag",null),this.vbar.remove(),delete this.vbar,delete this._vbarYMin,delete this._vbarTranslateMax)},s.prototype._onBoxDrag=function(){var t=this.translateX,e=this.translateY;this.hbar&&(t-=n.event.dx),this.vbar&&(e-=n.event.dy),this.setTranslate(t,e)},s.prototype._onBoxWheel=function(){var t=this.translateX,e=this.translateY;this.hbar&&(t+=n.event.deltaY),this.vbar&&(e+=n.event.deltaY),this.setTranslate(t,e)},s.prototype._onBarDrag=function(){var t=this.translateX,e=this.translateY;if(this.hbar){var r=t+this._hbarXMin,i=r+this._hbarTranslateMax;t=(o.constrain(n.event.x,r,i)-r)/(i-r)*(this.position.w-this._box.w)}if(this.vbar){var a=e+this._vbarYMin,s=a+this._vbarTranslateMax;e=(o.constrain(n.event.y,a,s)-a)/(s-a)*(this.position.h-this._box.h)}this.setTranslate(t,e)},s.prototype.setTranslate=function(t,e){var r=this.position.w-this._box.w,n=this.position.h-this._box.h;if(t=o.constrain(t||0,0,r),e=o.constrain(e||0,0,n),this.translateX=t,this.translateY=e,this.container.call(a.setTranslate,this._box.l-this.position.l-t,this._box.t-this.position.t-e),this._clipRect&&this._clipRect.attr({x:Math.floor(this.position.l+t-.5),y:Math.floor(this.position.t+e-.5)}),this.hbar){var i=t/r;this.hbar.call(a.setTranslate,t+i*this._hbarTranslateMax,e)}if(this.vbar){var s=e/n;this.vbar.call(a.setTranslate,t,e+s*this._vbarTranslateMax)}}},{"../../lib":503,"../color":366,"../drawing":388,"@plotly/d3":58}],471:[function(t,e,r){"use strict";e.exports={FROM_BL:{left:0,center:.5,right:1,bottom:0,middle:.5,top:1},FROM_TL:{left:0,center:.5,right:1,bottom:1,middle:.5,top:0},FROM_BR:{left:1,center:.5,right:0,bottom:0,middle:.5,top:1},LINE_SPACING:1.3,CAP_SHIFT:.7,MID_SHIFT:.35,OPPOSITE_SIDE:{left:"right",right:"left",top:"bottom",bottom:"top"}}},{}],472:[function(t,e,r){"use strict";e.exports={axisRefDescription:function(t,e,r){return["If set to a",t,"axis id (e.g. *"+t+"* or","*"+t+"2*), the `"+t+"` position refers to a",t,"coordinate. If set to *paper*, the `"+t+"`","position refers to the distance from the",e,"of the plotting","area in normalized coordinates where *0* (*1*) corresponds to the",e,"("+r+"). If set to a",t,"axis ID followed by","*domain* (separated by a space), the position behaves like for","*paper*, but refers to the distance in fractions of the domain","length from the",e,"of the domain of that axis: e.g.,","*"+t+"2 domain* refers to the domain of the second",t," axis and a",t,"position of 0.5 refers to the","point between the",e,"and the",r,"of the domain of the","second",t,"axis."].join(" ")}}},{}],473:[function(t,e,r){"use strict";e.exports={INCREASING:{COLOR:"#3D9970",SYMBOL:"\u25b2"},DECREASING:{COLOR:"#FF4136",SYMBOL:"\u25bc"}}},{}],474:[function(t,e,r){"use strict";e.exports={FORMAT_LINK:"https://github.com/d3/d3-format/tree/v1.4.5#d3-format",DATE_FORMAT_LINK:"https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format"}},{}],475:[function(t,e,r){"use strict";e.exports={COMPARISON_OPS:["=","!=","<",">=",">","<="],COMPARISON_OPS2:["=","<",">=",">","<="],INTERVAL_OPS:["[]","()","[)","(]","][",")(","](",")["],SET_OPS:["{}","}{"],CONSTRAINT_REDUCTION:{"=":"=","<":"<","<=":"<",">":">",">=":">","[]":"[]","()":"[]","[)":"[]","(]":"[]","][":"][",")(":"][","](":"][",")[":"]["}}},{}],476:[function(t,e,r){"use strict";e.exports={solid:[[],0],dot:[[.5,1],200],dash:[[.5,1],50],longdash:[[.5,1],10],dashdot:[[.5,.625,.875,1],50],longdashdot:[[.5,.7,.8,1],10]}},{}],477:[function(t,e,r){"use strict";e.exports={circle:"\u25cf","circle-open":"\u25cb",square:"\u25a0","square-open":"\u25a1",diamond:"\u25c6","diamond-open":"\u25c7",cross:"+",x:"\u274c"}},{}],478:[function(t,e,r){"use strict";e.exports={SHOW_PLACEHOLDER:100,HIDE_PLACEHOLDER:1e3,DESELECTDIM:.2}},{}],479:[function(t,e,r){"use strict";e.exports={BADNUM:void 0,FP_SAFE:1e-4*Number.MAX_VALUE,ONEMAXYEAR:316224e5,ONEAVGYEAR:315576e5,ONEMINYEAR:31536e6,ONEMAXQUARTER:79488e5,ONEAVGQUARTER:78894e5,ONEMINQUARTER:76896e5,ONEMAXMONTH:26784e5,ONEAVGMONTH:26298e5,ONEMINMONTH:24192e5,ONEWEEK:6048e5,ONEDAY:864e5,ONEHOUR:36e5,ONEMIN:6e4,ONESEC:1e3,EPOCHJD:2440587.5,ALMOST_EQUAL:.999999,LOG_CLIP:10,MINUS_SIGN:"\u2212"}},{}],480:[function(t,e,r){"use strict";r.xmlns="http://www.w3.org/2000/xmlns/",r.svg="http://www.w3.org/2000/svg",r.xlink="http://www.w3.org/1999/xlink",r.svgAttrs={xmlns:r.svg,"xmlns:xlink":r.xlink}},{}],481:[function(t,e,r){"use strict";r.version=t("./version").version,t("native-promise-only"),t("../build/plotcss");for(var n=t("./registry"),i=r.register=n.register,a=t("./plot_api"),o=Object.keys(a),s=0;s<o.length;s++){var l=o[s];"_"!==l.charAt(0)&&(r[l]=a[l]),i({moduleType:"apiMethod",name:l,fn:a[l]})}i(t("./traces/scatter")),i([t("./components/legend"),t("./components/fx"),t("./components/annotations"),t("./components/annotations3d"),t("./components/shapes"),t("./components/images"),t("./components/updatemenus"),t("./components/sliders"),t("./components/rangeslider"),t("./components/rangeselector"),t("./components/grid"),t("./components/errorbars"),t("./components/colorscale"),t("./components/colorbar"),t("./components/modebar")]),i([t("./locale-en"),t("./locale-en-us")]),window.PlotlyLocales&&Array.isArray(window.PlotlyLocales)&&(i(window.PlotlyLocales),delete window.PlotlyLocales),r.Icons=t("./fonts/ploticon");var c=t("./components/fx"),u=t("./plots/plots");r.Plots={resize:u.resize,graphJson:u.graphJson,sendDataToCloud:u.sendDataToCloud},r.Fx={hover:c.hover,unhover:c.unhover,loneHover:c.loneHover,loneUnhover:c.loneUnhover},r.Snapshot=t("./snapshot"),r.PlotSchema=t("./plot_api/plot_schema")},{"../build/plotcss":1,"./components/annotations":357,"./components/annotations3d":362,"./components/colorbar":372,"./components/colorscale":378,"./components/errorbars":394,"./components/fx":406,"./components/grid":410,"./components/images":415,"./components/legend":423,"./components/modebar":429,"./components/rangeselector":437,"./components/rangeslider":444,"./components/shapes":458,"./components/sliders":463,"./components/updatemenus":469,"./fonts/ploticon":482,"./locale-en":534,"./locale-en-us":533,"./plot_api":538,"./plot_api/plot_schema":542,"./plots/plots":619,"./registry":638,"./snapshot":643,"./traces/scatter":939,"./version":1123,"native-promise-only":245}],482:[function(t,e,r){"use strict";e.exports={undo:{width:857.1,height:1e3,path:"m857 350q0-87-34-166t-91-137-137-92-166-34q-96 0-183 41t-147 114q-4 6-4 13t5 11l76 77q6 5 14 5 9-1 13-7 41-53 100-82t126-29q58 0 110 23t92 61 61 91 22 111-22 111-61 91-92 61-110 23q-55 0-105-20t-90-57l77-77q17-16 8-38-10-23-33-23h-250q-15 0-25 11t-11 25v250q0 24 22 33 22 10 39-8l72-72q60 57 137 88t159 31q87 0 166-34t137-92 91-137 34-166z",transform:"matrix(1 0 0 -1 0 850)"},home:{width:928.6,height:1e3,path:"m786 296v-267q0-15-11-26t-25-10h-214v214h-143v-214h-214q-15 0-25 10t-11 26v267q0 1 0 2t0 2l321 264 321-264q1-1 1-4z m124 39l-34-41q-5-5-12-6h-2q-7 0-12 3l-386 322-386-322q-7-4-13-4-7 2-12 7l-35 41q-4 5-3 13t6 12l401 334q18 15 42 15t43-15l136-114v109q0 8 5 13t13 5h107q8 0 13-5t5-13v-227l122-102q5-5 6-12t-4-13z",transform:"matrix(1 0 0 -1 0 850)"},"camera-retro":{width:1e3,height:1e3,path:"m518 386q0 8-5 13t-13 5q-37 0-63-27t-26-63q0-8 5-13t13-5 12 5 5 13q0 23 16 38t38 16q8 0 13 5t5 13z m125-73q0-59-42-101t-101-42-101 42-42 101 42 101 101 42 101-42 42-101z m-572-320h858v71h-858v-71z m643 320q0 89-62 152t-152 62-151-62-63-152 63-151 151-63 152 63 62 151z m-571 358h214v72h-214v-72z m-72-107h858v143h-462l-36-71h-360v-72z m929 143v-714q0-30-21-51t-50-21h-858q-29 0-50 21t-21 51v714q0 30 21 51t50 21h858q29 0 50-21t21-51z",transform:"matrix(1 0 0 -1 0 850)"},zoombox:{width:1e3,height:1e3,path:"m1000-25l-250 251c40 63 63 138 63 218 0 224-182 406-407 406-224 0-406-182-406-406s183-406 407-406c80 0 155 22 218 62l250-250 125 125z m-812 250l0 438 437 0 0-438-437 0z m62 375l313 0 0-312-313 0 0 312z",transform:"matrix(1 0 0 -1 0 850)"},pan:{width:1e3,height:1e3,path:"m1000 350l-187 188 0-125-250 0 0 250 125 0-188 187-187-187 125 0 0-250-250 0 0 125-188-188 186-187 0 125 252 0 0-250-125 0 187-188 188 188-125 0 0 250 250 0 0-126 187 188z",transform:"matrix(1 0 0 -1 0 850)"},zoom_plus:{width:875,height:1e3,path:"m1 787l0-875 875 0 0 875-875 0z m687-500l-187 0 0-187-125 0 0 187-188 0 0 125 188 0 0 187 125 0 0-187 187 0 0-125z",transform:"matrix(1 0 0 -1 0 850)"},zoom_minus:{width:875,height:1e3,path:"m0 788l0-876 875 0 0 876-875 0z m688-500l-500 0 0 125 500 0 0-125z",transform:"matrix(1 0 0 -1 0 850)"},autoscale:{width:1e3,height:1e3,path:"m250 850l-187 0-63 0 0-62 0-188 63 0 0 188 187 0 0 62z m688 0l-188 0 0-62 188 0 0-188 62 0 0 188 0 62-62 0z m-875-938l0 188-63 0 0-188 0-62 63 0 187 0 0 62-187 0z m875 188l0-188-188 0 0-62 188 0 62 0 0 62 0 188-62 0z m-125 188l-1 0-93-94-156 156 156 156 92-93 2 0 0 250-250 0 0-2 93-92-156-156-156 156 94 92 0 2-250 0 0-250 0 0 93 93 157-156-157-156-93 94 0 0 0-250 250 0 0 0-94 93 156 157 156-157-93-93 0 0 250 0 0 250z",transform:"matrix(1 0 0 -1 0 850)"},tooltip_basic:{width:1500,height:1e3,path:"m375 725l0 0-375-375 375-374 0-1 1125 0 0 750-1125 0z",transform:"matrix(1 0 0 -1 0 850)"},tooltip_compare:{width:1125,height:1e3,path:"m187 786l0 2-187-188 188-187 0 0 937 0 0 373-938 0z m0-499l0 1-187-188 188-188 0 0 937 0 0 376-938-1z",transform:"matrix(1 0 0 -1 0 850)"},plotlylogo:{width:1542,height:1e3,path:"m0-10h182v-140h-182v140z m228 146h183v-286h-183v286z m225 714h182v-1000h-182v1000z m225-285h182v-715h-182v715z m225 142h183v-857h-183v857z m231-428h182v-429h-182v429z m225-291h183v-138h-183v138z",transform:"matrix(1 0 0 -1 0 850)"},"z-axis":{width:1e3,height:1e3,path:"m833 5l-17 108v41l-130-65 130-66c0 0 0 38 0 39 0-1 36-14 39-25 4-15-6-22-16-30-15-12-39-16-56-20-90-22-187-23-279-23-261 0-341 34-353 59 3 60 228 110 228 110-140-8-351-35-351-116 0-120 293-142 474-142 155 0 477 22 477 142 0 50-74 79-163 96z m-374 94c-58-5-99-21-99-40 0-24 65-43 144-43 79 0 143 19 143 43 0 19-42 34-98 40v216h87l-132 135-133-135h88v-216z m167 515h-136v1c16 16 31 34 46 52l84 109v54h-230v-71h124v-1c-16-17-28-32-44-51l-89-114v-51h245v72z",transform:"matrix(1 0 0 -1 0 850)"},"3d_rotate":{width:1e3,height:1e3,path:"m922 660c-5 4-9 7-14 11-359 263-580-31-580-31l-102 28 58-400c0 1 1 1 2 2 118 108 351 249 351 249s-62 27-100 42c88 83 222 183 347 122 16-8 30-17 44-27-2 1-4 2-6 4z m36-329c0 0 64 229-88 296-62 27-124 14-175-11 157-78 225-208 249-266 8-19 11-31 11-31 2 5 6 15 11 32-5-13-8-20-8-20z m-775-239c70-31 117-50 198-32-121 80-199 346-199 346l-96-15-58-12c0 0 55-226 155-287z m603 133l-317-139c0 0 4-4 19-14 7-5 24-15 24-15s-177-147-389 4c235-287 536-112 536-112l31-22 100 299-4-1z m-298-153c6-4 14-9 24-15 0 0-17 10-24 15z",transform:"matrix(1 0 0 -1 0 850)"},camera:{width:1e3,height:1e3,path:"m500 450c-83 0-150-67-150-150 0-83 67-150 150-150 83 0 150 67 150 150 0 83-67 150-150 150z m400 150h-120c-16 0-34 13-39 29l-31 93c-6 15-23 28-40 28h-340c-16 0-34-13-39-28l-31-94c-6-15-23-28-40-28h-120c-55 0-100-45-100-100v-450c0-55 45-100 100-100h800c55 0 100 45 100 100v450c0 55-45 100-100 100z m-400-550c-138 0-250 112-250 250 0 138 112 250 250 250 138 0 250-112 250-250 0-138-112-250-250-250z m365 380c-19 0-35 16-35 35 0 19 16 35 35 35 19 0 35-16 35-35 0-19-16-35-35-35z",transform:"matrix(1 0 0 -1 0 850)"},movie:{width:1e3,height:1e3,path:"m938 413l-188-125c0 37-17 71-44 94 64 38 107 107 107 187 0 121-98 219-219 219-121 0-219-98-219-219 0-61 25-117 66-156h-115c30 33 49 76 49 125 0 103-84 187-187 187s-188-84-188-187c0-57 26-107 65-141-38-22-65-62-65-109v-250c0-70 56-126 125-126h500c69 0 125 56 125 126l188-126c34 0 62 28 62 63v375c0 35-28 63-62 63z m-750 0c-69 0-125 56-125 125s56 125 125 125 125-56 125-125-56-125-125-125z m406-1c-87 0-157 70-157 157 0 86 70 156 157 156s156-70 156-156-70-157-156-157z",transform:"matrix(1 0 0 -1 0 850)"},question:{width:857.1,height:1e3,path:"m500 82v107q0 8-5 13t-13 5h-107q-8 0-13-5t-5-13v-107q0-8 5-13t13-5h107q8 0 13 5t5 13z m143 375q0 49-31 91t-77 65-95 23q-136 0-207-119-9-14 4-24l74-55q4-4 10-4 9 0 14 7 30 38 48 51 19 14 48 14 27 0 48-15t21-33q0-21-11-34t-38-25q-35-16-65-48t-29-70v-20q0-8 5-13t13-5h107q8 0 13 5t5 13q0 10 12 27t30 28q18 10 28 16t25 19 25 27 16 34 7 45z m214-107q0-117-57-215t-156-156-215-58-216 58-155 156-58 215 58 215 155 156 216 58 215-58 156-156 57-215z",transform:"matrix(1 0 0 -1 0 850)"},disk:{width:857.1,height:1e3,path:"m214-7h429v214h-429v-214z m500 0h72v500q0 8-6 21t-11 20l-157 156q-5 6-19 12t-22 5v-232q0-22-15-38t-38-16h-322q-22 0-37 16t-16 38v232h-72v-714h72v232q0 22 16 38t37 16h465q22 0 38-16t15-38v-232z m-214 518v178q0 8-5 13t-13 5h-107q-7 0-13-5t-5-13v-178q0-8 5-13t13-5h107q7 0 13 5t5 13z m357-18v-518q0-22-15-38t-38-16h-750q-23 0-38 16t-16 38v750q0 22 16 38t38 16h517q23 0 50-12t42-26l156-157q16-15 27-42t11-49z",transform:"matrix(1 0 0 -1 0 850)"},drawopenpath:{width:70,height:70,path:"M33.21,85.65a7.31,7.31,0,0,1-2.59-.48c-8.16-3.11-9.27-19.8-9.88-41.3-.1-3.58-.19-6.68-.35-9-.15-2.1-.67-3.48-1.43-3.79-2.13-.88-7.91,2.32-12,5.86L3,32.38c1.87-1.64,11.55-9.66,18.27-6.9,2.13.87,4.75,3.14,5.17,9,.17,2.43.26,5.59.36,9.25a224.17,224.17,0,0,0,1.5,23.4c1.54,10.76,4,12.22,4.48,12.4.84.32,2.79-.46,5.76-3.59L43,80.07C41.53,81.57,37.68,85.64,33.21,85.65ZM74.81,69a11.34,11.34,0,0,0,6.09-6.72L87.26,44.5,74.72,32,56.9,38.35c-2.37.86-5.57,3.42-6.61,6L38.65,72.14l8.42,8.43ZM55,46.27a7.91,7.91,0,0,1,3.64-3.17l14.8-5.3,8,8L76.11,60.6l-.06.19a6.37,6.37,0,0,1-3,3.43L48.25,74.59,44.62,71Zm16.57,7.82A6.9,6.9,0,1,0,64.64,61,6.91,6.91,0,0,0,71.54,54.09Zm-4.05,0a2.85,2.85,0,1,1-2.85-2.85A2.86,2.86,0,0,1,67.49,54.09Zm-4.13,5.22L60.5,56.45,44.26,72.7l2.86,2.86ZM97.83,35.67,84.14,22l-8.57,8.57L89.26,44.24Zm-13.69-8,8,8-2.85,2.85-8-8Z",transform:"matrix(1 0 0 1 -15 -15)"},drawclosedpath:{width:90,height:90,path:"M88.41,21.12a26.56,26.56,0,0,0-36.18,0l-2.07,2-2.07-2a26.57,26.57,0,0,0-36.18,0,23.74,23.74,0,0,0,0,34.8L48,90.12a3.22,3.22,0,0,0,4.42,0l36-34.21a23.73,23.73,0,0,0,0-34.79ZM84,51.24,50.16,83.35,16.35,51.25a17.28,17.28,0,0,1,0-25.47,20,20,0,0,1,27.3,0l4.29,4.07a3.23,3.23,0,0,0,4.44,0l4.29-4.07a20,20,0,0,1,27.3,0,17.27,17.27,0,0,1,0,25.46ZM66.76,47.68h-33v6.91h33ZM53.35,35H46.44V68h6.91Z",transform:"matrix(1 0 0 1 -5 -5)"},lasso:{width:1031,height:1e3,path:"m1018 538c-36 207-290 336-568 286-277-48-473-256-436-463 10-57 36-108 76-151-13-66 11-137 68-183 34-28 75-41 114-42l-55-70 0 0c-2-1-3-2-4-3-10-14-8-34 5-45 14-11 34-8 45 4 1 1 2 3 2 5l0 0 113 140c16 11 31 24 45 40 4 3 6 7 8 11 48-3 100 0 151 9 278 48 473 255 436 462z m-624-379c-80 14-149 48-197 96 42 42 109 47 156 9 33-26 47-66 41-105z m-187-74c-19 16-33 37-39 60 50-32 109-55 174-68-42-25-95-24-135 8z m360 75c-34-7-69-9-102-8 8 62-16 128-68 170-73 59-175 54-244-5-9 20-16 40-20 61-28 159 121 317 333 354s407-60 434-217c28-159-121-318-333-355z",transform:"matrix(1 0 0 -1 0 850)"},selectbox:{width:1e3,height:1e3,path:"m0 850l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z m285 0l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z m-857-286l0-143 143 0 0 143-143 0z m857 0l0-143 143 0 0 143-143 0z m-857-285l0-143 143 0 0 143-143 0z m857 0l0-143 143 0 0 143-143 0z m-857-286l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z m285 0l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z",transform:"matrix(1 0 0 -1 0 850)"},drawline:{width:70,height:70,path:"M60.64,62.3a11.29,11.29,0,0,0,6.09-6.72l6.35-17.72L60.54,25.31l-17.82,6.4c-2.36.86-5.57,3.41-6.6,6L24.48,65.5l8.42,8.42ZM40.79,39.63a7.89,7.89,0,0,1,3.65-3.17l14.79-5.31,8,8L61.94,54l-.06.19a6.44,6.44,0,0,1-3,3.43L34.07,68l-3.62-3.63Zm16.57,7.81a6.9,6.9,0,1,0-6.89,6.9A6.9,6.9,0,0,0,57.36,47.44Zm-4,0a2.86,2.86,0,1,1-2.85-2.85A2.86,2.86,0,0,1,53.32,47.44Zm-4.13,5.22L46.33,49.8,30.08,66.05l2.86,2.86ZM83.65,29,70,15.34,61.4,23.9,75.09,37.59ZM70,21.06l8,8-2.84,2.85-8-8ZM87,80.49H10.67V87H87Z",transform:"matrix(1 0 0 1 -15 -15)"},drawrect:{width:80,height:80,path:"M78,22V79H21V22H78m9-9H12V88H87V13ZM68,46.22H31V54H68ZM53,32H45.22V69H53Z",transform:"matrix(1 0 0 1 -10 -10)"},drawcircle:{width:80,height:80,path:"M50,84.72C26.84,84.72,8,69.28,8,50.3S26.84,15.87,50,15.87,92,31.31,92,50.3,73.16,84.72,50,84.72Zm0-60.59c-18.6,0-33.74,11.74-33.74,26.17S31.4,76.46,50,76.46,83.74,64.72,83.74,50.3,68.6,24.13,50,24.13Zm17.15,22h-34v7.11h34Zm-13.8-13H46.24v34h7.11Z",transform:"matrix(1 0 0 1 -10 -10)"},eraseshape:{width:80,height:80,path:"M82.77,78H31.85L6,49.57,31.85,21.14H82.77a8.72,8.72,0,0,1,8.65,8.77V69.24A8.72,8.72,0,0,1,82.77,78ZM35.46,69.84H82.77a.57.57,0,0,0,.49-.6V29.91a.57.57,0,0,0-.49-.61H35.46L17,49.57Zm32.68-34.7-24,24,5,5,24-24Zm-19,.53-5,5,24,24,5-5Z",transform:"matrix(1 0 0 1 -10 -10)"},spikeline:{width:1e3,height:1e3,path:"M512 409c0-57-46-104-103-104-57 0-104 47-104 104 0 57 47 103 104 103 57 0 103-46 103-103z m-327-39l92 0 0 92-92 0z m-185 0l92 0 0 92-92 0z m370-186l92 0 0 93-92 0z m0-184l92 0 0 92-92 0z",transform:"matrix(1.5 0 0 -1.5 0 850)"},pencil:{width:1792,height:1792,path:"M491 1536l91-91-235-235-91 91v107h128v128h107zm523-928q0-22-22-22-10 0-17 7l-542 542q-7 7-7 17 0 22 22 22 10 0 17-7l542-542q7-7 7-17zm-54-192l416 416-832 832h-416v-416zm683 96q0 53-37 90l-166 166-416-416 166-165q36-38 90-38 53 0 91 38l235 234q37 39 37 91z",transform:"matrix(1 0 0 1 0 1)"},newplotlylogo:{name:"newplotlylogo",svg:"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 132 132'><defs><style>.cls-1 {fill: #3f4f75;} .cls-2 {fill: #80cfbe;} .cls-3 {fill: #fff;}</style></defs><title>plotly-logomark</title><g id='symbol'><rect class='cls-1' width='132' height='132' rx='6' ry='6'/><circle class='cls-2' cx='78' cy='54' r='6'/><circle class='cls-2' cx='102' cy='30' r='6'/><circle class='cls-2' cx='78' cy='30' r='6'/><circle class='cls-2' cx='54' cy='30' r='6'/><circle class='cls-2' cx='30' cy='30' r='6'/><circle class='cls-2' cx='30' cy='54' r='6'/><path class='cls-3' d='M30,72a6,6,0,0,0-6,6v24a6,6,0,0,0,12,0V78A6,6,0,0,0,30,72Z'/><path class='cls-3' d='M78,72a6,6,0,0,0-6,6v24a6,6,0,0,0,12,0V78A6,6,0,0,0,78,72Z'/><path class='cls-3' d='M54,48a6,6,0,0,0-6,6v48a6,6,0,0,0,12,0V54A6,6,0,0,0,54,48Z'/><path class='cls-3' d='M102,48a6,6,0,0,0-6,6v48a6,6,0,0,0,12,0V54A6,6,0,0,0,102,48Z'/></g></svg>"}}},{}],483:[function(t,e,r){"use strict";r.isLeftAnchor=function(t){return"left"===t.xanchor||"auto"===t.xanchor&&t.x<=1/3},r.isCenterAnchor=function(t){return"center"===t.xanchor||"auto"===t.xanchor&&t.x>1/3&&t.x<2/3},r.isRightAnchor=function(t){return"right"===t.xanchor||"auto"===t.xanchor&&t.x>=2/3},r.isTopAnchor=function(t){return"top"===t.yanchor||"auto"===t.yanchor&&t.y>=2/3},r.isMiddleAnchor=function(t){return"middle"===t.yanchor||"auto"===t.yanchor&&t.y>1/3&&t.y<2/3},r.isBottomAnchor=function(t){return"bottom"===t.yanchor||"auto"===t.yanchor&&t.y<=1/3}},{}],484:[function(t,e,r){"use strict";var n=t("./mod"),i=n.mod,a=n.modHalf,o=Math.PI,s=2*o;function l(t){return Math.abs(t[1]-t[0])>s-1e-14}function c(t,e){return a(e-t,s)}function u(t,e){if(l(e))return!0;var r,n;e[0]<e[1]?(r=e[0],n=e[1]):(r=e[1],n=e[0]),(r=i(r,s))>(n=i(n,s))&&(n+=s);var a=i(t,s),o=a+s;return a>=r&&a<=n||o>=r&&o<=n}function f(t,e,r,n,i,a,c){i=i||0,a=a||0;var u,f,h,p,d,m=l([r,n]);function g(t,e){return[t*Math.cos(e)+i,a-t*Math.sin(e)]}m?(u=0,f=o,h=s):r<n?(u=r,h=n):(u=n,h=r),t<e?(p=t,d=e):(p=e,d=t);var v,y=Math.abs(h-u)<=o?0:1;function x(t,e,r){return"A"+[t,t]+" "+[0,y,r]+" "+g(t,e)}return m?v=null===p?"M"+g(d,u)+x(d,f,0)+x(d,h,0)+"Z":"M"+g(p,u)+x(p,f,0)+x(p,h,0)+"ZM"+g(d,u)+x(d,f,1)+x(d,h,1)+"Z":null===p?(v="M"+g(d,u)+x(d,h,0),c&&(v+="L0,0Z")):v="M"+g(p,u)+"L"+g(d,u)+x(d,h,0)+"L"+g(p,h)+x(p,u,1)+"Z",v}e.exports={deg2rad:function(t){return t/180*o},rad2deg:function(t){return t/o*180},angleDelta:c,angleDist:function(t,e){return Math.abs(c(t,e))},isFullCircle:l,isAngleInsideSector:u,isPtInsideSector:function(t,e,r,n){return!!u(e,n)&&(r[0]<r[1]?(i=r[0],a=r[1]):(i=r[1],a=r[0]),t>=i&&t<=a);var i,a},pathArc:function(t,e,r,n,i){return f(null,t,e,r,n,i,0)},pathSector:function(t,e,r,n,i){return f(null,t,e,r,n,i,1)},pathAnnulus:function(t,e,r,n,i,a){return f(t,e,r,n,i,a,1)}}},{"./mod":510}],485:[function(t,e,r){"use strict";var n=Array.isArray,i=ArrayBuffer,a=DataView;function o(t){return i.isView(t)&&!(t instanceof a)}function s(t){return n(t)||o(t)}function l(t,e,r){if(s(t)){if(s(t[0])){for(var n=r,i=0;i<t.length;i++)n=e(n,t[i].length);return n}return t.length}return 0}r.isTypedArray=o,r.isArrayOrTypedArray=s,r.isArray1D=function(t){return!s(t[0])},r.ensureArray=function(t,e){return n(t)||(t=[]),t.length=e,t},r.concat=function(){var t,e,r,i,a,o,s,l,c=[],u=!0,f=0;for(r=0;r<arguments.length;r++)(o=(i=arguments[r]).length)&&(e?c.push(i):(e=i,a=o),n(i)?t=!1:(u=!1,f?t!==i.constructor&&(t=!1):t=i.constructor),f+=o);if(!f)return[];if(!c.length)return e;if(u)return e.concat.apply(e,c);if(t){for((s=new t(f)).set(e),r=0;r<c.length;r++)i=c[r],s.set(i,a),a+=i.length;return s}for(s=new Array(f),l=0;l<e.length;l++)s[l]=e[l];for(r=0;r<c.length;r++){for(i=c[r],l=0;l<i.length;l++)s[a+l]=i[l];a+=l}return s},r.maxRowLength=function(t){return l(t,Math.max,0)},r.minRowLength=function(t){return l(t,Math.min,1/0)}},{}],486:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../constants/numerical").BADNUM,a=/^['"%,$#\s']+|[, ]|['"%,$#\s']+$/g;e.exports=function(t){return"string"==typeof t&&(t=t.replace(a,"")),n(t)?Number(t):i}},{"../constants/numerical":479,"fast-isnumeric":190}],487:[function(t,e,r){"use strict";e.exports=function(t){var e=t._fullLayout;e._glcanvas&&e._glcanvas.size()&&e._glcanvas.each((function(t){t.regl&&t.regl.clear({color:!0,depth:!0})}))}},{}],488:[function(t,e,r){"use strict";e.exports=function(t){t._responsiveChartHandler&&(window.removeEventListener("resize",t._responsiveChartHandler),delete t._responsiveChartHandler)}},{}],489:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("tinycolor2"),a=t("../plots/attributes"),o=t("../components/colorscale/scales"),s=t("../components/color"),l=t("../constants/interactions").DESELECTDIM,c=t("./nested_property"),u=t("./regex").counter,f=t("./mod").modHalf,h=t("./array").isArrayOrTypedArray;function p(t,e){var n=r.valObjectMeta[e.valType];if(e.arrayOk&&h(t))return!0;if(n.validateFunction)return n.validateFunction(t,e);var i={},a=i,o={set:function(t){a=t}};return n.coerceFunction(t,o,i,e),a!==i}r.valObjectMeta={data_array:{coerceFunction:function(t,e,r){h(t)?e.set(t):void 0!==r&&e.set(r)}},enumerated:{coerceFunction:function(t,e,r,n){n.coerceNumber&&(t=+t),-1===n.values.indexOf(t)?e.set(r):e.set(t)},validateFunction:function(t,e){e.coerceNumber&&(t=+t);for(var r=e.values,n=0;n<r.length;n++){var i=String(r[n]);if("/"===i.charAt(0)&&"/"===i.charAt(i.length-1)){if(new RegExp(i.substr(1,i.length-2)).test(t))return!0}else if(t===r[n])return!0}return!1}},boolean:{coerceFunction:function(t,e,r){!0===t||!1===t?e.set(t):e.set(r)}},number:{coerceFunction:function(t,e,r,i){!n(t)||void 0!==i.min&&t<i.min||void 0!==i.max&&t>i.max?e.set(r):e.set(+t)}},integer:{coerceFunction:function(t,e,r,i){t%1||!n(t)||void 0!==i.min&&t<i.min||void 0!==i.max&&t>i.max?e.set(r):e.set(+t)}},string:{coerceFunction:function(t,e,r,n){if("string"!=typeof t){var i="number"==typeof t;!0!==n.strict&&i?e.set(String(t)):e.set(r)}else n.noBlank&&!t?e.set(r):e.set(t)}},color:{coerceFunction:function(t,e,r){i(t).isValid()?e.set(t):e.set(r)}},colorlist:{coerceFunction:function(t,e,r){Array.isArray(t)&&t.length&&t.every((function(t){return i(t).isValid()}))?e.set(t):e.set(r)}},colorscale:{coerceFunction:function(t,e,r){e.set(o.get(t,r))}},angle:{coerceFunction:function(t,e,r){"auto"===t?e.set("auto"):n(t)?e.set(f(+t,360)):e.set(r)}},subplotid:{coerceFunction:function(t,e,r,n){var i=n.regex||u(r);"string"==typeof t&&i.test(t)?e.set(t):e.set(r)},validateFunction:function(t,e){var r=e.dflt;return t===r||"string"==typeof t&&!!u(r).test(t)}},flaglist:{coerceFunction:function(t,e,r,n){if("string"==typeof t)if(-1===(n.extras||[]).indexOf(t)){for(var i=t.split("+"),a=0;a<i.length;){var o=i[a];-1===n.flags.indexOf(o)||i.indexOf(o)<a?i.splice(a,1):a++}i.length?e.set(i.join("+")):e.set(r)}else e.set(t);else e.set(r)}},any:{coerceFunction:function(t,e,r){void 0===t?e.set(r):e.set(t)}},info_array:{coerceFunction:function(t,e,n,i){function a(t,e,n){var i,a={set:function(t){i=t}};return void 0===n&&(n=e.dflt),r.valObjectMeta[e.valType].coerceFunction(t,a,n,e),i}var o=2===i.dimensions||"1-2"===i.dimensions&&Array.isArray(t)&&Array.isArray(t[0]);if(Array.isArray(t)){var s,l,c,u,f,h,p=i.items,d=[],m=Array.isArray(p),g=m&&o&&Array.isArray(p[0]),v=o&&m&&!g,y=m&&!v?p.length:t.length;if(n=Array.isArray(n)?n:[],o)for(s=0;s<y;s++)for(d[s]=[],c=Array.isArray(t[s])?t[s]:[],f=v?p.length:m?p[s].length:c.length,l=0;l<f;l++)u=v?p[l]:m?p[s][l]:p,void 0!==(h=a(c[l],u,(n[s]||[])[l]))&&(d[s][l]=h);else for(s=0;s<y;s++)void 0!==(h=a(t[s],m?p[s]:p,n[s]))&&(d[s]=h);e.set(d)}else e.set(n)},validateFunction:function(t,e){if(!Array.isArray(t))return!1;var r=e.items,n=Array.isArray(r),i=2===e.dimensions;if(!e.freeLength&&t.length!==r.length)return!1;for(var a=0;a<t.length;a++)if(i){if(!Array.isArray(t[a])||!e.freeLength&&t[a].length!==r[a].length)return!1;for(var o=0;o<t[a].length;o++)if(!p(t[a][o],n?r[a][o]:r))return!1}else if(!p(t[a],n?r[a]:r))return!1;return!0}}},r.coerce=function(t,e,n,i,a){var o=c(n,i).get(),s=c(t,i),l=c(e,i),u=s.get(),f=e._template;if(void 0===u&&f&&(u=c(f,i).get(),f=0),void 0===a&&(a=o.dflt),o.arrayOk&&h(u))return l.set(u),u;var d=r.valObjectMeta[o.valType].coerceFunction;d(u,l,a,o);var m=l.get();return f&&m===a&&!p(u,o)&&(d(u=c(f,i).get(),l,a,o),m=l.get()),m},r.coerce2=function(t,e,n,i,a){var o=c(t,i),s=r.coerce(t,e,n,i,a),l=o.get();return null!=l&&s},r.coerceFont=function(t,e,r){var n={};return r=r||{},n.family=t(e+".family",r.family),n.size=t(e+".size",r.size),n.color=t(e+".color",r.color),n},r.coercePattern=function(t,e,r,n){if(t(e+".shape")){t(e+".solidity"),t(e+".size");var i="overlay"===t(e+".fillmode");if(!n){var a=t(e+".bgcolor",i?r:void 0);t(e+".fgcolor",i?s.contrast(a):r)}t(e+".fgopacity",i?.5:1)}},r.coerceHoverinfo=function(t,e,n){var i,o=e._module.attributes,s=o.hoverinfo?o:a,l=s.hoverinfo;if(1===n._dataLength){var c="all"===l.dflt?l.flags.slice():l.dflt.split("+");c.splice(c.indexOf("name"),1),i=c.join("+")}return r.coerce(t,e,s,"hoverinfo",i)},r.coerceSelectionMarkerOpacity=function(t,e){if(t.marker){var r,n,i=t.marker.opacity;if(void 0!==i)h(i)||t.selected||t.unselected||(r=i,n=l*i),e("selected.marker.opacity",r),e("unselected.marker.opacity",n)}},r.validate=p},{"../components/color":366,"../components/colorscale/scales":381,"../constants/interactions":478,"../plots/attributes":550,"./array":485,"./mod":510,"./nested_property":511,"./regex":520,"fast-isnumeric":190,tinycolor2:312}],490:[function(t,e,r){"use strict";var n,i,a=t("d3-time-format").timeFormat,o=t("fast-isnumeric"),s=t("./loggers"),l=t("./mod").mod,c=t("../constants/numerical"),u=c.BADNUM,f=c.ONEDAY,h=c.ONEHOUR,p=c.ONEMIN,d=c.ONESEC,m=c.EPOCHJD,g=t("../registry"),v=t("d3-time-format").utcFormat,y=/^\s*(-?\d\d\d\d|\d\d)(-(\d?\d)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d(:?\d\d)?)?)?)?)?)?\s*$/m,x=/^\s*(-?\d\d\d\d|\d\d)(-(\d?\di?)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d(:?\d\d)?)?)?)?)?)?\s*$/m,b=(new Date).getFullYear()-70;function _(t){return t&&g.componentsRegistry.calendars&&"string"==typeof t&&"gregorian"!==t}function w(t,e){return String(t+Math.pow(10,e)).substr(1)}r.dateTick0=function(t,e){var n=function(t,e){return _(t)?e?g.getComponentMethod("calendars","CANONICAL_SUNDAY")[t]:g.getComponentMethod("calendars","CANONICAL_TICK")[t]:e?"2000-01-02":"2000-01-01"}(t,!!e);if(e<2)return n;var i=r.dateTime2ms(n,t);return i+=f*(e-1),r.ms2DateTime(i,0,t)},r.dfltRange=function(t){return _(t)?g.getComponentMethod("calendars","DFLTRANGE")[t]:["2000-01-01","2001-01-01"]},r.isJSDate=function(t){return"object"==typeof t&&null!==t&&"function"==typeof t.getTime},r.dateTime2ms=function(t,e){if(r.isJSDate(t)){var a=t.getTimezoneOffset()*p,o=(t.getUTCMinutes()-t.getMinutes())*p+(t.getUTCSeconds()-t.getSeconds())*d+(t.getUTCMilliseconds()-t.getMilliseconds());if(o){var s=3*p;a=a-s/2+l(o-a+s/2,s)}return(t=Number(t)-a)>=n&&t<=i?t:u}if("string"!=typeof t&&"number"!=typeof t)return u;t=String(t);var c=_(e),v=t.charAt(0);!c||"G"!==v&&"g"!==v||(t=t.substr(1),e="");var w=c&&"chinese"===e.substr(0,7),T=t.match(w?x:y);if(!T)return u;var k=T[1],A=T[3]||"1",M=Number(T[5]||1),S=Number(T[7]||0),E=Number(T[9]||0),L=Number(T[11]||0);if(c){if(2===k.length)return u;var C;k=Number(k);try{var P=g.getComponentMethod("calendars","getCal")(e);if(w){var I="i"===A.charAt(A.length-1);A=parseInt(A,10),C=P.newDate(k,P.toMonthIndex(k,A,I),M)}else C=P.newDate(k,Number(A),M)}catch(t){return u}return C?(C.toJD()-m)*f+S*h+E*p+L*d:u}k=2===k.length?(Number(k)+2e3-b)%100+b:Number(k),A-=1;var O=new Date(Date.UTC(2e3,A,M,S,E));return O.setUTCFullYear(k),O.getUTCMonth()!==A||O.getUTCDate()!==M?u:O.getTime()+L*d},n=r.MIN_MS=r.dateTime2ms("-9999"),i=r.MAX_MS=r.dateTime2ms("9999-12-31 23:59:59.9999"),r.isDateTime=function(t,e){return r.dateTime2ms(t,e)!==u};var T=90*f,k=3*h,A=5*p;function M(t,e,r,n,i){if((e||r||n||i)&&(t+=" "+w(e,2)+":"+w(r,2),(n||i)&&(t+=":"+w(n,2),i))){for(var a=4;i%10==0;)a-=1,i/=10;t+="."+w(i,a)}return t}r.ms2DateTime=function(t,e,r){if("number"!=typeof t||!(t>=n&&t<=i))return u;e||(e=0);var a,o,s,c,y,x,b=Math.floor(10*l(t+.05,1)),w=Math.round(t-b/10);if(_(r)){var S=Math.floor(w/f)+m,E=Math.floor(l(t,f));try{a=g.getComponentMethod("calendars","getCal")(r).fromJD(S).formatDate("yyyy-mm-dd")}catch(t){a=v("G%Y-%m-%d")(new Date(w))}if("-"===a.charAt(0))for(;a.length<11;)a="-0"+a.substr(1);else for(;a.length<10;)a="0"+a;o=e<T?Math.floor(E/h):0,s=e<T?Math.floor(E%h/p):0,c=e<k?Math.floor(E%p/d):0,y=e<A?E%d*10+b:0}else x=new Date(w),a=v("%Y-%m-%d")(x),o=e<T?x.getUTCHours():0,s=e<T?x.getUTCMinutes():0,c=e<k?x.getUTCSeconds():0,y=e<A?10*x.getUTCMilliseconds()+b:0;return M(a,o,s,c,y)},r.ms2DateTimeLocal=function(t){if(!(t>=n+f&&t<=i-f))return u;var e=Math.floor(10*l(t+.05,1)),r=new Date(Math.round(t-e/10));return M(a("%Y-%m-%d")(r),r.getHours(),r.getMinutes(),r.getSeconds(),10*r.getUTCMilliseconds()+e)},r.cleanDate=function(t,e,n){if(t===u)return e;if(r.isJSDate(t)||"number"==typeof t&&isFinite(t)){if(_(n))return s.error("JS Dates and milliseconds are incompatible with world calendars",t),e;if(!(t=r.ms2DateTimeLocal(+t))&&void 0!==e)return e}else if(!r.isDateTime(t,n))return s.error("unrecognized date",t),e;return t};var S=/%\d?f/g,E=/%h/g,L={1:"1",2:"1",3:"2",4:"2"};function C(t,e,r,n){t=t.replace(S,(function(t){var r=Math.min(+t.charAt(1)||6,6);return(e/1e3%1+2).toFixed(r).substr(2).replace(/0+$/,"")||"0"}));var i=new Date(Math.floor(e+.05));if(t=t.replace(E,(function(){return L[r("%q")(i)]})),_(n))try{t=g.getComponentMethod("calendars","worldCalFmt")(t,e,n)}catch(t){return"Invalid"}return r(t)(i)}var P=[59,59.9,59.99,59.999,59.9999];r.formatDate=function(t,e,r,n,i,a){if(i=_(i)&&i,!e)if("y"===r)e=a.year;else if("m"===r)e=a.month;else{if("d"!==r)return function(t,e){var r=l(t+.05,f),n=w(Math.floor(r/h),2)+":"+w(l(Math.floor(r/p),60),2);if("M"!==e){o(e)||(e=0);var i=(100+Math.min(l(t/d,60),P[e])).toFixed(e).substr(1);e>0&&(i=i.replace(/0+$/,"").replace(/[\.]$/,"")),n+=":"+i}return n}(t,r)+"\n"+C(a.dayMonthYear,t,n,i);e=a.dayMonth+"\n"+a.year}return C(e,t,n,i)};var I=3*f;r.incrementMonth=function(t,e,r){r=_(r)&&r;var n=l(t,f);if(t=Math.round(t-n),r)try{var i=Math.round(t/f)+m,a=g.getComponentMethod("calendars","getCal")(r),o=a.fromJD(i);return e%12?a.add(o,e,"m"):a.add(o,e/12,"y"),(o.toJD()-m)*f+n}catch(e){s.error("invalid ms "+t+" in calendar "+r)}var c=new Date(t+I);return c.setUTCMonth(c.getUTCMonth()+e)+n-I},r.findExactDates=function(t,e){for(var r,n,i=0,a=0,s=0,l=0,c=_(e)&&g.getComponentMethod("calendars","getCal")(e),u=0;u<t.length;u++)if(n=t[u],o(n)){if(!(n%f))if(c)try{1===(r=c.fromJD(n/f+m)).day()?1===r.month()?i++:a++:s++}catch(t){}else 1===(r=new Date(n)).getUTCDate()?0===r.getUTCMonth()?i++:a++:s++}else l++;s+=a+=i;var h=t.length-l;return{exactYears:i/h,exactMonths:a/h,exactDays:s/h}}},{"../constants/numerical":479,"../registry":638,"./loggers":507,"./mod":510,"d3-time-format":120,"fast-isnumeric":190}],491:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("./loggers"),a=t("./matrix"),o=t("gl-mat4");function s(t){var e=t&&t.parentNode;e&&e.removeChild(t)}function l(t,e,r){var n="plotly.js-style-"+t,a=document.getElementById(n);a||((a=document.createElement("style")).setAttribute("id",n),a.appendChild(document.createTextNode("")),document.head.appendChild(a));var o=a.sheet;o.insertRule?o.insertRule(e+"{"+r+"}",0):o.addRule?o.addRule(e,r,0):i.warn("addStyleRule failed")}function c(t){var e=window.getComputedStyle(t,null),r=e.getPropertyValue("-webkit-transform")||e.getPropertyValue("-moz-transform")||e.getPropertyValue("-ms-transform")||e.getPropertyValue("-o-transform")||e.getPropertyValue("transform");return"none"===r?null:r.replace("matrix","").replace("3d","").slice(1,-1).split(",").map((function(t){return+t}))}function u(t){for(var e=[];f(t);)e.push(t),t=t.parentNode;return e}function f(t){return t&&(t instanceof Element||t instanceof HTMLElement)}e.exports={getGraphDiv:function(t){var e;if("string"==typeof t){if(null===(e=document.getElementById(t)))throw new Error("No DOM element with id '"+t+"' exists on the page.");return e}if(null==t)throw new Error("DOM element provided is null or undefined");return t},isPlotDiv:function(t){var e=n.select(t);return e.node()instanceof HTMLElement&&e.size()&&e.classed("js-plotly-plot")},removeElement:s,addStyleRule:function(t,e){l("global",t,e)},addRelatedStyleRule:l,deleteRelatedStyleRule:function(t){var e="plotly.js-style-"+t,r=document.getElementById(e);r&&s(r)},getFullTransformMatrix:function(t){var e=u(t),r=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];return e.forEach((function(t){var e=c(t);if(e){var n=a.convertCssMatrix(e);r=o.multiply(r,r,n)}})),r},getElementTransformMatrix:c,getElementAndAncestors:u,equalDomRects:function(t,e){return t&&e&&t.x===e.x&&t.y===e.y&&t.top===e.top&&t.left===e.left&&t.right===e.right&&t.bottom===e.bottom}}},{"./loggers":507,"./matrix":509,"@plotly/d3":58,"gl-mat4":210}],492:[function(t,e,r){"use strict";var n=t("events").EventEmitter,i={init:function(t){if(t._ev instanceof n)return t;var e=new n,r=new n;return t._ev=e,t._internalEv=r,t.on=e.on.bind(e),t.once=e.once.bind(e),t.removeListener=e.removeListener.bind(e),t.removeAllListeners=e.removeAllListeners.bind(e),t._internalOn=r.on.bind(r),t._internalOnce=r.once.bind(r),t._removeInternalListener=r.removeListener.bind(r),t._removeAllInternalListeners=r.removeAllListeners.bind(r),t.emit=function(n,i){"undefined"!=typeof jQuery&&jQuery(t).trigger(n,i),e.emit(n,i),r.emit(n,i)},t},triggerHandler:function(t,e,r){var n,i;"undefined"!=typeof jQuery&&(n=jQuery(t).triggerHandler(e,r));var a=t._ev;if(!a)return n;var o,s=a._events[e];if(!s)return n;function l(t){return t.listener?(a.removeListener(e,t.listener),t.fired?void 0:(t.fired=!0,t.listener.apply(a,[r]))):t.apply(a,[r])}for(s=Array.isArray(s)?s:[s],o=0;o<s.length-1;o++)l(s[o]);return i=l(s[o]),void 0!==n?n:i},purge:function(t){return delete t._ev,delete t.on,delete t.once,delete t.removeListener,delete t.removeAllListeners,delete t.emit,delete t._ev,delete t._internalEv,delete t._internalOn,delete t._internalOnce,delete t._removeInternalListener,delete t._removeAllInternalListeners,t}};e.exports=i},{events:84}],493:[function(t,e,r){"use strict";var n=t("./is_plain_object.js"),i=Array.isArray;function a(t,e,r,o){var s,l,c,u,f,h,p=t[0],d=t.length;if(2===d&&i(p)&&i(t[1])&&0===p.length){if(function(t,e){var r,n;for(r=0;r<t.length;r++){if(null!==(n=t[r])&&"object"==typeof n)return!1;void 0!==n&&(e[r]=n)}return!0}(t[1],p))return p;p.splice(0,p.length)}for(var m=1;m<d;m++)for(l in s=t[m])c=p[l],u=s[l],o&&i(u)?p[l]=u:e&&u&&(n(u)||(f=i(u)))?(f?(f=!1,h=c&&i(c)?c:[]):h=c&&n(c)?c:{},p[l]=a([h,u],e,r,o)):(void 0!==u||r)&&(p[l]=u);return p}r.extendFlat=function(){return a(arguments,!1,!1,!1)},r.extendDeep=function(){return a(arguments,!0,!1,!1)},r.extendDeepAll=function(){return a(arguments,!0,!0,!1)},r.extendDeepNoArrays=function(){return a(arguments,!0,!1,!0)}},{"./is_plain_object.js":504}],494:[function(t,e,r){"use strict";e.exports=function(t){for(var e={},r=[],n=0,i=0;i<t.length;i++){var a=t[i];1!==e[a]&&(e[a]=1,r[n++]=a)}return r}},{}],495:[function(t,e,r){"use strict";function n(t){return!0===t.visible}function i(t){var e=t[0].trace;return!0===e.visible&&0!==e._length}e.exports=function(t){for(var e,r=(e=t,Array.isArray(e)&&Array.isArray(e[0])&&e[0][0]&&e[0][0].trace?i:n),a=[],o=0;o<t.length;o++){var s=t[o];r(s)&&a.push(s)}return a}},{}],496:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("country-regex"),a=t("@turf/area"),o=t("@turf/centroid"),s=t("@turf/bbox"),l=t("./identity"),c=t("./loggers"),u=t("./is_plain_object"),f=t("./nested_property"),h=t("./polygon"),p=Object.keys(i),d={"ISO-3":l,"USA-states":l,"country names":function(t){for(var e=0;e<p.length;e++){var r=p[e];if(new RegExp(i[r]).test(t.trim().toLowerCase()))return r}return c.log("Unrecognized country name: "+t+"."),!1}};function m(t){var e=t.geojson,r=window.PlotlyGeoAssets||{},n="string"==typeof e?r[e]:e;return u(n)?n:(c.error("Oops ... something went wrong when fetching "+e),!1)}e.exports={locationToFeature:function(t,e,r){if(!e||"string"!=typeof e)return!1;var n,i,a,o=d[t](e);if(o){if("USA-states"===t)for(n=[],a=0;a<r.length;a++)(i=r[a]).properties&&i.properties.gu&&"USA"===i.properties.gu&&n.push(i);else n=r;for(a=0;a<n.length;a++)if((i=n[a]).id===o)return i;c.log(["Location with id",o,"does not have a matching topojson feature at this resolution."].join(" "))}return!1},feature2polygons:function(t){var e,r,n,i,a=t.geometry,o=a.coordinates,s=t.id,l=[];function c(t){for(var e=0;e<t.length-1;e++)if(t[e][0]>0&&t[e+1][0]<0)return e;return null}switch(e="RUS"===s||"FJI"===s?function(t){var e;if(null===c(t))e=t;else for(e=new Array(t.length),i=0;i<t.length;i++)e[i]=[t[i][0]<0?t[i][0]+360:t[i][0],t[i][1]];l.push(h.tester(e))}:"ATA"===s?function(t){var e=c(t);if(null===e)return l.push(h.tester(t));var r=new Array(t.length+1),n=0;for(i=0;i<t.length;i++)i>e?r[n++]=[t[i][0]+360,t[i][1]]:i===e?(r[n++]=t[i],r[n++]=[t[i][0],-90]):r[n++]=t[i];var a=h.tester(r);a.pts.pop(),l.push(a)}:function(t){l.push(h.tester(t))},a.type){case"MultiPolygon":for(r=0;r<o.length;r++)for(n=0;n<o[r].length;n++)e(o[r][n]);break;case"Polygon":for(r=0;r<o.length;r++)e(o[r])}return l},getTraceGeojson:m,extractTraceFeature:function(t){var e=t[0].trace,r=m(e);if(!r)return!1;var n,i={},s=[];for(n=0;n<e._length;n++){var l=t[n];(l.loc||0===l.loc)&&(i[l.loc]=l)}function u(t){var r=f(t,e.featureidkey||"id").get(),n=i[r];if(n){var l=t.geometry;if("Polygon"===l.type||"MultiPolygon"===l.type){var u={type:"Feature",id:r,geometry:l,properties:{}};u.properties.ct=function(t){var e,r=t.geometry;if("MultiPolygon"===r.type)for(var n=r.coordinates,i=0,s=0;s<n.length;s++){var l={type:"Polygon",coordinates:n[s]},c=a.default(l);c>i&&(i=c,e=l)}else e=r;return o.default(e).geometry.coordinates}(u),n.fIn=t,n.fOut=u,s.push(u)}else c.log(["Location",n.loc,"does not have a valid GeoJSON geometry.","Traces with locationmode *geojson-id* only support","*Polygon* and *MultiPolygon* geometries."].join(" "))}delete i[r]}switch(r.type){case"FeatureCollection":var h=r.features;for(n=0;n<h.length;n++)u(h[n]);break;case"Feature":u(r);break;default:return c.warn(["Invalid GeoJSON type",(r.type||"none")+".","Traces with locationmode *geojson-id* only support","*FeatureCollection* and *Feature* types."].join(" ")),!1}for(var p in i)c.log(["Location *"+p+"*","does not have a matching feature with id-key","*"+e.featureidkey+"*."].join(" "));return s},fetchTraceGeoData:function(t){var e=window.PlotlyGeoAssets||{},r=[];function i(t){return new Promise((function(r,i){n.json(t,(function(n,a){if(n){delete e[t];var o=404===n.status?'GeoJSON at URL "'+t+'" does not exist.':"Unexpected error while fetching from "+t;return i(new Error(o))}return e[t]=a,r(a)}))}))}function a(t){return new Promise((function(r,n){var i=0,a=setInterval((function(){return e[t]&&"pending"!==e[t]?(clearInterval(a),r(e[t])):i>100?(clearInterval(a),n("Unexpected error while fetching from "+t)):void i++}),50)}))}for(var o=0;o<t.length;o++){var s=t[o][0].trace.geojson;"string"==typeof s&&(e[s]?"pending"===e[s]&&r.push(a(s)):(e[s]="pending",r.push(i(s))))}return r},computeBbox:function(t){return s.default(t)}}},{"./identity":501,"./is_plain_object":504,"./loggers":507,"./nested_property":511,"./polygon":515,"@plotly/d3":58,"@turf/area":61,"@turf/bbox":64,"@turf/centroid":67,"country-regex":94}],497:[function(t,e,r){"use strict";var n=t("../constants/numerical").BADNUM;r.calcTraceToLineCoords=function(t){for(var e=t[0].trace.connectgaps,r=[],i=[],a=0;a<t.length;a++){var o=t[a].lonlat;o[0]!==n?i.push(o):!e&&i.length>0&&(r.push(i),i=[])}return i.length>0&&r.push(i),r},r.makeLine=function(t){return 1===t.length?{type:"LineString",coordinates:t[0]}:{type:"MultiLineString",coordinates:t}},r.makePolygon=function(t){if(1===t.length)return{type:"Polygon",coordinates:t};for(var e=new Array(t.length),r=0;r<t.length;r++)e[r]=[t[r]];return{type:"MultiPolygon",coordinates:e}},r.makeBlank=function(){return{type:"Point",coordinates:[]}}},{"../constants/numerical":479}],498:[function(t,e,r){"use strict";var n,i,a,o=t("./mod").mod;function s(t,e,r,n,i,a,o,s){var l=r-t,c=i-t,u=o-i,f=n-e,h=a-e,p=s-a,d=l*p-u*f;if(0===d)return null;var m=(c*p-u*h)/d,g=(c*f-l*h)/d;return g<0||g>1||m<0||m>1?null:{x:t+l*m,y:e+f*m}}function l(t,e,r,n,i){var a=n*t+i*e;if(a<0)return n*n+i*i;if(a>r){var o=n-t,s=i-e;return o*o+s*s}var l=n*e-i*t;return l*l/r}r.segmentsIntersect=s,r.segmentDistance=function(t,e,r,n,i,a,o,c){if(s(t,e,r,n,i,a,o,c))return 0;var u=r-t,f=n-e,h=o-i,p=c-a,d=u*u+f*f,m=h*h+p*p,g=Math.min(l(u,f,d,i-t,a-e),l(u,f,d,o-t,c-e),l(h,p,m,t-i,e-a),l(h,p,m,r-i,n-a));return Math.sqrt(g)},r.getTextLocation=function(t,e,r,s){if(t===i&&s===a||(n={},i=t,a=s),n[r])return n[r];var l=t.getPointAtLength(o(r-s/2,e)),c=t.getPointAtLength(o(r+s/2,e)),u=Math.atan((c.y-l.y)/(c.x-l.x)),f=t.getPointAtLength(o(r,e)),h={x:(4*f.x+l.x+c.x)/6,y:(4*f.y+l.y+c.y)/6,theta:u};return n[r]=h,h},r.clearLocationCache=function(){i=null},r.getVisibleSegment=function(t,e,r){var n,i,a=e.left,o=e.right,s=e.top,l=e.bottom,c=0,u=t.getTotalLength(),f=u;function h(e){var r=t.getPointAtLength(e);0===e?n=r:e===u&&(i=r);var c=r.x<a?a-r.x:r.x>o?r.x-o:0,f=r.y<s?s-r.y:r.y>l?r.y-l:0;return Math.sqrt(c*c+f*f)}for(var p=h(c);p;){if((c+=p+r)>f)return;p=h(c)}for(p=h(f);p;){if(c>(f-=p+r))return;p=h(f)}return{min:c,max:f,len:f-c,total:u,isClosed:0===c&&f===u&&Math.abs(n.x-i.x)<.1&&Math.abs(n.y-i.y)<.1}},r.findPointOnPath=function(t,e,r,n){for(var i,a,o,s=(n=n||{}).pathLength||t.getTotalLength(),l=n.tolerance||.001,c=n.iterationLimit||30,u=t.getPointAtLength(0)[r]>t.getPointAtLength(s)[r]?-1:1,f=0,h=0,p=s;f<c;){if(i=(h+p)/2,o=(a=t.getPointAtLength(i))[r]-e,Math.abs(o)<l)return a;u*o>0?p=i:h=i,f++}return a}},{"./mod":510}],499:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("tinycolor2"),a=t("color-normalize"),o=t("../components/colorscale"),s=t("../components/color/attributes").defaultLine,l=t("./array").isArrayOrTypedArray,c=a(s);function u(t,e){var r=t;return r[3]*=e,r}function f(t){if(n(t))return c;var e=a(t);return e.length?e:c}function h(t){return n(t)?t:1}e.exports={formatColor:function(t,e,r){var n,i,s,p,d,m=t.color,g=l(m),v=l(e),y=o.extractOpts(t),x=[];if(n=void 0!==y.colorscale?o.makeColorScaleFuncFromTrace(t):f,i=g?function(t,e){return void 0===t[e]?c:a(n(t[e]))}:f,s=v?function(t,e){return void 0===t[e]?1:h(t[e])}:h,g||v)for(var b=0;b<r;b++)p=i(m,b),d=s(e,b),x[b]=u(p,d);else x=u(a(m),e);return x},parseColorScale:function(t){var e=o.extractOpts(t),r=e.colorscale;return e.reversescale&&(r=o.flipScale(e.colorscale)),r.map((function(t){var e=t[0],r=i(t[1]).toRgb();return{index:e,rgb:[r.r,r.g,r.b,r.a]}}))}}},{"../components/color/attributes":365,"../components/colorscale":378,"./array":485,"color-normalize":89,"fast-isnumeric":190,tinycolor2:312}],500:[function(t,e,r){"use strict";var n=t("./identity");function i(t){return[t]}e.exports={keyFun:function(t){return t.key},repeat:i,descend:n,wrap:i,unwrap:function(t){return t[0]}}},{"./identity":501}],501:[function(t,e,r){"use strict";e.exports=function(t){return t}},{}],502:[function(t,e,r){"use strict";e.exports=function(t,e){if(!e)return t;var r=1/Math.abs(e),n=r>1?(r*t+r*e)/r:t+e,i=String(n).length;if(i>16){var a=String(e).length;if(i>=String(t).length+a){var o=parseFloat(n).toPrecision(12);-1===o.indexOf("e+")&&(n=+o)}}return n}},{}],503:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("d3-time-format").utcFormat,a=t("d3-format").format,o=t("fast-isnumeric"),s=t("../constants/numerical"),l=s.FP_SAFE,c=-l,u=s.BADNUM,f=e.exports={};f.adjustFormat=function(t){return!t||/^\d[.]\df/.test(t)||/[.]\d%/.test(t)?t:"0.f"===t?"~f":/^\d%/.test(t)?"~%":/^\ds/.test(t)?"~s":!/^[~,.0$]/.test(t)&&/[&fps]/.test(t)?"~"+t:t};var h={};f.warnBadFormat=function(t){var e=String(t);h[e]||(h[e]=1,f.warn('encountered bad format: "'+e+'"'))},f.noFormat=function(t){return String(t)},f.numberFormat=function(t){var e;try{e=a(f.adjustFormat(t))}catch(e){return f.warnBadFormat(t),f.noFormat}return e},f.nestedProperty=t("./nested_property"),f.keyedContainer=t("./keyed_container"),f.relativeAttr=t("./relative_attr"),f.isPlainObject=t("./is_plain_object"),f.toLogRange=t("./to_log_range"),f.relinkPrivateKeys=t("./relink_private");var p=t("./array");f.isTypedArray=p.isTypedArray,f.isArrayOrTypedArray=p.isArrayOrTypedArray,f.isArray1D=p.isArray1D,f.ensureArray=p.ensureArray,f.concat=p.concat,f.maxRowLength=p.maxRowLength,f.minRowLength=p.minRowLength;var d=t("./mod");f.mod=d.mod,f.modHalf=d.modHalf;var m=t("./coerce");f.valObjectMeta=m.valObjectMeta,f.coerce=m.coerce,f.coerce2=m.coerce2,f.coerceFont=m.coerceFont,f.coercePattern=m.coercePattern,f.coerceHoverinfo=m.coerceHoverinfo,f.coerceSelectionMarkerOpacity=m.coerceSelectionMarkerOpacity,f.validate=m.validate;var g=t("./dates");f.dateTime2ms=g.dateTime2ms,f.isDateTime=g.isDateTime,f.ms2DateTime=g.ms2DateTime,f.ms2DateTimeLocal=g.ms2DateTimeLocal,f.cleanDate=g.cleanDate,f.isJSDate=g.isJSDate,f.formatDate=g.formatDate,f.incrementMonth=g.incrementMonth,f.dateTick0=g.dateTick0,f.dfltRange=g.dfltRange,f.findExactDates=g.findExactDates,f.MIN_MS=g.MIN_MS,f.MAX_MS=g.MAX_MS;var v=t("./search");f.findBin=v.findBin,f.sorterAsc=v.sorterAsc,f.sorterDes=v.sorterDes,f.distinctVals=v.distinctVals,f.roundUp=v.roundUp,f.sort=v.sort,f.findIndexOfMin=v.findIndexOfMin,f.sortObjectKeys=t("./sort_object_keys");var y=t("./stats");f.aggNums=y.aggNums,f.len=y.len,f.mean=y.mean,f.median=y.median,f.midRange=y.midRange,f.variance=y.variance,f.stdev=y.stdev,f.interp=y.interp;var x=t("./matrix");f.init2dArray=x.init2dArray,f.transposeRagged=x.transposeRagged,f.dot=x.dot,f.translationMatrix=x.translationMatrix,f.rotationMatrix=x.rotationMatrix,f.rotationXYMatrix=x.rotationXYMatrix,f.apply3DTransform=x.apply3DTransform,f.apply2DTransform=x.apply2DTransform,f.apply2DTransform2=x.apply2DTransform2,f.convertCssMatrix=x.convertCssMatrix,f.inverseTransformMatrix=x.inverseTransformMatrix;var b=t("./angles");f.deg2rad=b.deg2rad,f.rad2deg=b.rad2deg,f.angleDelta=b.angleDelta,f.angleDist=b.angleDist,f.isFullCircle=b.isFullCircle,f.isAngleInsideSector=b.isAngleInsideSector,f.isPtInsideSector=b.isPtInsideSector,f.pathArc=b.pathArc,f.pathSector=b.pathSector,f.pathAnnulus=b.pathAnnulus;var _=t("./anchor_utils");f.isLeftAnchor=_.isLeftAnchor,f.isCenterAnchor=_.isCenterAnchor,f.isRightAnchor=_.isRightAnchor,f.isTopAnchor=_.isTopAnchor,f.isMiddleAnchor=_.isMiddleAnchor,f.isBottomAnchor=_.isBottomAnchor;var w=t("./geometry2d");f.segmentsIntersect=w.segmentsIntersect,f.segmentDistance=w.segmentDistance,f.getTextLocation=w.getTextLocation,f.clearLocationCache=w.clearLocationCache,f.getVisibleSegment=w.getVisibleSegment,f.findPointOnPath=w.findPointOnPath;var T=t("./extend");f.extendFlat=T.extendFlat,f.extendDeep=T.extendDeep,f.extendDeepAll=T.extendDeepAll,f.extendDeepNoArrays=T.extendDeepNoArrays;var k=t("./loggers");f.log=k.log,f.warn=k.warn,f.error=k.error;var A=t("./regex");f.counterRegex=A.counter;var M=t("./throttle");f.throttle=M.throttle,f.throttleDone=M.done,f.clearThrottle=M.clear;var S=t("./dom");function E(t){var e={};for(var r in t)for(var n=t[r],i=0;i<n.length;i++)e[n[i]]=+r;return e}f.getGraphDiv=S.getGraphDiv,f.isPlotDiv=S.isPlotDiv,f.removeElement=S.removeElement,f.addStyleRule=S.addStyleRule,f.addRelatedStyleRule=S.addRelatedStyleRule,f.deleteRelatedStyleRule=S.deleteRelatedStyleRule,f.getFullTransformMatrix=S.getFullTransformMatrix,f.getElementTransformMatrix=S.getElementTransformMatrix,f.getElementAndAncestors=S.getElementAndAncestors,f.equalDomRects=S.equalDomRects,f.clearResponsive=t("./clear_responsive"),f.preserveDrawingBuffer=t("./preserve_drawing_buffer"),f.makeTraceGroups=t("./make_trace_groups"),f._=t("./localize"),f.notifier=t("./notifier"),f.filterUnique=t("./filter_unique"),f.filterVisible=t("./filter_visible"),f.pushUnique=t("./push_unique"),f.increment=t("./increment"),f.cleanNumber=t("./clean_number"),f.ensureNumber=function(t){return o(t)?(t=Number(t))>l||t<c?u:t:u},f.isIndex=function(t,e){return!(void 0!==e&&t>=e)&&(o(t)&&t>=0&&t%1==0)},f.noop=t("./noop"),f.identity=t("./identity"),f.repeat=function(t,e){for(var r=new Array(e),n=0;n<e;n++)r[n]=t;return r},f.swapAttrs=function(t,e,r,n){r||(r="x"),n||(n="y");for(var i=0;i<e.length;i++){var a=e[i],o=f.nestedProperty(t,a.replace("?",r)),s=f.nestedProperty(t,a.replace("?",n)),l=o.get();o.set(s.get()),s.set(l)}},f.raiseToTop=function(t){t.parentNode.appendChild(t)},f.cancelTransition=function(t){return t.transition().duration(0)},f.constrain=function(t,e,r){return e>r?Math.max(r,Math.min(e,t)):Math.max(e,Math.min(r,t))},f.bBoxIntersect=function(t,e,r){return r=r||0,t.left<=e.right+r&&e.left<=t.right+r&&t.top<=e.bottom+r&&e.top<=t.bottom+r},f.simpleMap=function(t,e,r,n,i){for(var a=t.length,o=new Array(a),s=0;s<a;s++)o[s]=e(t[s],r,n,i);return o},f.randstr=function t(e,r,n,i){if(n||(n=16),void 0===r&&(r=24),r<=0)return"0";var a,o,s=Math.log(Math.pow(2,r))/Math.log(n),l="";for(a=2;s===1/0;a*=2)s=Math.log(Math.pow(2,r/a))/Math.log(n)*a;var c=s-Math.floor(s);for(a=0;a<Math.floor(s);a++)l=Math.floor(Math.random()*n).toString(n)+l;c&&(o=Math.pow(n,c),l=Math.floor(Math.random()*o).toString(n)+l);var u=parseInt(l,n);return e&&e[l]||u!==1/0&&u>=Math.pow(2,r)?i>10?(f.warn("randstr failed uniqueness"),l):t(e,r,n,(i||0)+1):l},f.OptionControl=function(t,e){t||(t={}),e||(e="opt");var r={optionList:[],_newoption:function(n){n[e]=t,r[n.name]=n,r.optionList.push(n)}};return r["_"+e]=t,r},f.smooth=function(t,e){if((e=Math.round(e)||0)<2)return t;var r,n,i,a,o=t.length,s=2*o,l=2*e-1,c=new Array(l),u=new Array(o);for(r=0;r<l;r++)c[r]=(1-Math.cos(Math.PI*(r+1)/e))/(2*e);for(r=0;r<o;r++){for(a=0,n=0;n<l;n++)(i=r+n+1-e)<-o?i-=s*Math.round(i/s):i>=s&&(i-=s*Math.floor(i/s)),i<0?i=-1-i:i>=o&&(i=s-1-i),a+=t[i]*c[n];u[r]=a}return u},f.syncOrAsync=function(t,e,r){var n;function i(){return f.syncOrAsync(t,e,r)}for(;t.length;)if((n=(0,t.splice(0,1)[0])(e))&&n.then)return n.then(i);return r&&r(e)},f.stripTrailingSlash=function(t){return"/"===t.substr(-1)?t.substr(0,t.length-1):t},f.noneOrAll=function(t,e,r){if(t){var n,i=!1,a=!0;for(n=0;n<r.length;n++)null!=t[r[n]]?i=!0:a=!1;if(i&&!a)for(n=0;n<r.length;n++)t[r[n]]=e[r[n]]}},f.mergeArray=function(t,e,r,n){var i="function"==typeof n;if(f.isArrayOrTypedArray(t))for(var a=Math.min(t.length,e.length),o=0;o<a;o++){var s=t[o];e[o][r]=i?n(s):s}},f.mergeArrayCastPositive=function(t,e,r){return f.mergeArray(t,e,r,(function(t){var e=+t;return isFinite(e)&&e>0?e:0}))},f.fillArray=function(t,e,r,n){if(n=n||f.identity,f.isArrayOrTypedArray(t))for(var i=0;i<e.length;i++)e[i][r]=n(t[i])},f.castOption=function(t,e,r,n){n=n||f.identity;var i=f.nestedProperty(t,r).get();return f.isArrayOrTypedArray(i)?Array.isArray(e)&&f.isArrayOrTypedArray(i[e[0]])?n(i[e[0]][e[1]]):n(i[e]):i},f.extractOption=function(t,e,r,n){if(r in t)return t[r];var i=f.nestedProperty(e,n).get();return Array.isArray(i)?void 0:i},f.tagSelected=function(t,e,r){var n,i,a=e.selectedpoints,o=e._indexToPoints;o&&(n=E(o));for(var s=0;s<a.length;s++){var l=a[s];if(f.isIndex(l)||f.isArrayOrTypedArray(l)&&f.isIndex(l[0])&&f.isIndex(l[1])){var c=n?n[l]:l,u=r?r[c]:c;void 0!==(i=u)&&i<t.length&&(t[u].selected=1)}}},f.selIndices2selPoints=function(t){var e=t.selectedpoints,r=t._indexToPoints;if(r){for(var n=E(r),i=[],a=0;a<e.length;a++){var o=e[a];if(f.isIndex(o)){var s=n[o];f.isIndex(s)&&i.push(s)}}return i}return e},f.getTargetArray=function(t,e){var r=e.target;if("string"==typeof r&&r){var n=f.nestedProperty(t,r).get();return!!Array.isArray(n)&&n}return!!Array.isArray(r)&&r},f.minExtend=function(t,e){var r={};"object"!=typeof e&&(e={});var n,i,a,o=Object.keys(t);for(n=0;n<o.length;n++)a=t[i=o[n]],"_"!==i.charAt(0)&&"function"!=typeof a&&("module"===i?r[i]=a:Array.isArray(a)?r[i]="colorscale"===i?a.slice():a.slice(0,3):f.isTypedArray(a)?r[i]=a.subarray(0,3):r[i]=a&&"object"==typeof a?f.minExtend(t[i],e[i]):a);for(o=Object.keys(e),n=0;n<o.length;n++)"object"==typeof(a=e[i=o[n]])&&i in r&&"object"==typeof r[i]||(r[i]=a);return r},f.titleCase=function(t){return t.charAt(0).toUpperCase()+t.substr(1)},f.containsAny=function(t,e){for(var r=0;r<e.length;r++)if(-1!==t.indexOf(e[r]))return!0;return!1},f.isIE=function(){return void 0!==window.navigator.msSaveBlob};var L=/Version\/[\d\.]+.*Safari/;f.isSafari=function(){return L.test(window.navigator.userAgent)};var C=/iPad|iPhone|iPod/;f.isIOS=function(){return C.test(window.navigator.userAgent)};var P=/Firefox\/(\d+)\.\d+/;f.getFirefoxVersion=function(){var t=P.exec(window.navigator.userAgent);if(t&&2===t.length){var e=parseInt(t[1]);if(!isNaN(e))return e}return null},f.isD3Selection=function(t){return t instanceof n.selection},f.ensureSingle=function(t,e,r,n){var i=t.select(e+(r?"."+r:""));if(i.size())return i;var a=t.append(e);return r&&a.classed(r,!0),n&&a.call(n),a},f.ensureSingleById=function(t,e,r,n){var i=t.select(e+"#"+r);if(i.size())return i;var a=t.append(e).attr("id",r);return n&&a.call(n),a},f.objectFromPath=function(t,e){for(var r,n=t.split("."),i=r={},a=0;a<n.length;a++){var o=n[a],s=null,l=n[a].match(/(.*)\[([0-9]+)\]/);l?(o=l[1],s=l[2],r=r[o]=[],a===n.length-1?r[s]=e:r[s]={},r=r[s]):(a===n.length-1?r[o]=e:r[o]={},r=r[o])}return i};var I=/^([^\[\.]+)\.(.+)?/,O=/^([^\.]+)\[([0-9]+)\](\.)?(.+)?/;f.expandObjectPaths=function(t){var e,r,n,i,a,o,s;if("object"==typeof t&&!Array.isArray(t))for(r in t)t.hasOwnProperty(r)&&((e=r.match(I))?(i=t[r],n=e[1],delete t[r],t[n]=f.extendDeepNoArrays(t[n]||{},f.objectFromPath(r,f.expandObjectPaths(i))[n])):(e=r.match(O))?(i=t[r],n=e[1],a=parseInt(e[2]),delete t[r],t[n]=t[n]||[],"."===e[3]?(s=e[4],o=t[n][a]=t[n][a]||{},f.extendDeepNoArrays(o,f.objectFromPath(s,f.expandObjectPaths(i)))):t[n][a]=f.expandObjectPaths(i)):t[r]=f.expandObjectPaths(t[r]));return t},f.numSeparate=function(t,e,r){if(r||(r=!1),"string"!=typeof e||0===e.length)throw new Error("Separator string required for formatting!");"number"==typeof t&&(t=String(t));var n=/(\d+)(\d{3})/,i=e.charAt(0),a=e.charAt(1),o=t.split("."),s=o[0],l=o.length>1?i+o[1]:"";if(a&&(o.length>1||s.length>4||r))for(;n.test(s);)s=s.replace(n,"$1"+a+"$2");return s+l},f.TEMPLATE_STRING_REGEX=/%{([^\s%{}:]*)([:|\|][^}]*)?}/g;var z=/^\w*$/;f.templateString=function(t,e){var r={};return t.replace(f.TEMPLATE_STRING_REGEX,(function(t,n){var i;return z.test(n)?i=e[n]:(r[n]=r[n]||f.nestedProperty(e,n).get,i=r[n]()),f.isValidTextValue(i)?i:""}))};var D={max:10,count:0,name:"hovertemplate"};f.hovertemplateString=function(){return B.apply(D,arguments)};var R={max:10,count:0,name:"texttemplate"};f.texttemplateString=function(){return B.apply(R,arguments)};var F=/^[:|\|]/;function B(t,e,r){var n=this,a=arguments;e||(e={});var o={};return t.replace(f.TEMPLATE_STRING_REGEX,(function(t,s,l){var c,u,h,p="_xother"===s||"_yother"===s,d="_xother_"===s||"_yother_"===s,m="xother_"===s||"yother_"===s,g="xother"===s||"yother"===s||p||m||d,v=s;if((p||d)&&(v=v.substring(1)),(m||d)&&(v=v.substring(0,v.length-1)),g){if(void 0===(c=e[v]))return""}else for(h=3;h<a.length;h++)if(u=a[h]){if(u.hasOwnProperty(v)){c=u[v];break}if(z.test(v)||(c=f.nestedProperty(u,v).get(),(c=o[v]||f.nestedProperty(u,v).get())&&(o[v]=c)),void 0!==c)break}if(void 0===c&&n)return n.count<n.max&&(f.warn("Variable '"+v+"' in "+n.name+" could not be found!"),c=t),n.count===n.max&&f.warn("Too many "+n.name+" warnings - additional warnings will be suppressed"),n.count++,t;if(l){var y;if(":"===l[0]&&(c=(y=r?r.numberFormat:f.numberFormat)(l.replace(F,""))(c)),"|"===l[0]){y=r?r.timeFormat:i;var x=f.dateTime2ms(c);c=f.formatDate(x,l.replace(F,""),!1,y)}}else{var b=v+"Label";e.hasOwnProperty(b)&&(c=e[b])}return g&&(c="("+c+")",(p||d)&&(c=" "+c),(m||d)&&(c+=" ")),c}))}f.subplotSort=function(t,e){for(var r=Math.min(t.length,e.length)+1,n=0,i=0,a=0;a<r;a++){var o=t.charCodeAt(a)||0,s=e.charCodeAt(a)||0,l=o>=48&&o<=57,c=s>=48&&s<=57;if(l&&(n=10*n+o-48),c&&(i=10*i+s-48),!l||!c){if(n!==i)return n-i;if(o!==s)return o-s}}return i-n};var N=2e9;f.seedPseudoRandom=function(){N=2e9},f.pseudoRandom=function(){var t=N;return N=(69069*N+1)%4294967296,Math.abs(N-t)<429496729?f.pseudoRandom():N/4294967296},f.fillText=function(t,e,r){var n=Array.isArray(r)?function(t){r.push(t)}:function(t){r.text=t},i=f.extractOption(t,e,"htx","hovertext");if(f.isValidTextValue(i))return n(i);var a=f.extractOption(t,e,"tx","text");return f.isValidTextValue(a)?n(a):void 0},f.isValidTextValue=function(t){return t||0===t},f.formatPercent=function(t,e){e=e||0;for(var r=(Math.round(100*t*Math.pow(10,e))*Math.pow(.1,e)).toFixed(e)+"%",n=0;n<e;n++)-1!==r.indexOf(".")&&(r=(r=r.replace("0%","%")).replace(".%","%"));return r},f.isHidden=function(t){var e=window.getComputedStyle(t).display;return!e||"none"===e},f.strTranslate=function(t,e){return t||e?"translate("+t+","+e+")":""},f.strRotate=function(t){return t?"rotate("+t+")":""},f.strScale=function(t){return 1!==t?"scale("+t+")":""},f.getTextTransform=function(t){var e=t.noCenter,r=t.textX,n=t.textY,i=t.targetX,a=t.targetY,o=t.anchorX||0,s=t.anchorY||0,l=t.rotate,c=t.scale;return c?c>1&&(c=1):c=0,f.strTranslate(i-c*(r+o),a-c*(n+s))+f.strScale(c)+(l?"rotate("+l+(e?"":" "+r+" "+n)+")":"")},f.ensureUniformFontSize=function(t,e){var r=f.extendFlat({},e);return r.size=Math.max(e.size,t._fullLayout.uniformtext.minsize||0),r},f.join2=function(t,e,r){var n=t.length;return n>1?t.slice(0,-1).join(e)+r+t[n-1]:t.join(e)},f.bigFont=function(t){return Math.round(1.2*t)};var j=f.getFirefoxVersion(),U=null!==j&&j<86;f.getPositionFromD3Event=function(){return U?[n.event.layerX,n.event.layerY]:[n.event.offsetX,n.event.offsetY]}},{"../constants/numerical":479,"./anchor_utils":483,"./angles":484,"./array":485,"./clean_number":486,"./clear_responsive":488,"./coerce":489,"./dates":490,"./dom":491,"./extend":493,"./filter_unique":494,"./filter_visible":495,"./geometry2d":498,"./identity":501,"./increment":502,"./is_plain_object":504,"./keyed_container":505,"./localize":506,"./loggers":507,"./make_trace_groups":508,"./matrix":509,"./mod":510,"./nested_property":511,"./noop":512,"./notifier":513,"./preserve_drawing_buffer":517,"./push_unique":518,"./regex":520,"./relative_attr":521,"./relink_private":522,"./search":523,"./sort_object_keys":526,"./stats":527,"./throttle":530,"./to_log_range":531,"@plotly/d3":58,"d3-format":112,"d3-time-format":120,"fast-isnumeric":190}],504:[function(t,e,r){"use strict";e.exports=function(t){return window&&window.process&&window.process.versions?"[object Object]"===Object.prototype.toString.call(t):"[object Object]"===Object.prototype.toString.call(t)&&Object.getPrototypeOf(t).hasOwnProperty("hasOwnProperty")}},{}],505:[function(t,e,r){"use strict";var n=t("./nested_property"),i=/^\w*$/;e.exports=function(t,e,r,a){var o,s,l;r=r||"name",a=a||"value";var c={};e&&e.length?(l=n(t,e),s=l.get()):s=t,e=e||"";var u={};if(s)for(o=0;o<s.length;o++)u[s[o][r]]=o;var f=i.test(a),h={set:function(t,e){var i=null===e?4:0;if(!s){if(!l||4===i)return;s=[],l.set(s)}var o=u[t];if(void 0===o){if(4===i)return;i|=3,o=s.length,u[t]=o}else e!==(f?s[o][a]:n(s[o],a).get())&&(i|=2);var p=s[o]=s[o]||{};return p[r]=t,f?p[a]=e:n(p,a).set(e),null!==e&&(i&=-5),c[o]=c[o]|i,h},get:function(t){if(s){var e=u[t];return void 0===e?void 0:f?s[e][a]:n(s[e],a).get()}},rename:function(t,e){var n=u[t];return void 0===n||(c[n]=1|c[n],u[e]=n,delete u[t],s[n][r]=e),h},remove:function(t){var e=u[t];if(void 0===e)return h;var i=s[e];if(Object.keys(i).length>2)return c[e]=2|c[e],h.set(t,null);if(f){for(o=e;o<s.length;o++)c[o]=3|c[o];for(o=e;o<s.length;o++)u[s[o][r]]--;s.splice(e,1),delete u[t]}else n(i,a).set(null),c[e]=6|c[e];return h},constructUpdate:function(){for(var t,i,o={},l=Object.keys(c),u=0;u<l.length;u++)i=l[u],t=e+"["+i+"]",s[i]?(1&c[i]&&(o[t+"."+r]=s[i][r]),2&c[i]&&(o[t+"."+a]=f?4&c[i]?null:s[i][a]:4&c[i]?null:n(s[i],a).get())):o[t]=null;return o}};return h}},{"./nested_property":511}],506:[function(t,e,r){"use strict";var n=t("../registry");e.exports=function(t,e){for(var r=t._context.locale,i=0;i<2;i++){for(var a=t._context.locales,o=0;o<2;o++){var s=(a[r]||{}).dictionary;if(s){var l=s[e];if(l)return l}a=n.localeRegistry}var c=r.split("-")[0];if(c===r)break;r=c}return e}},{"../registry":638}],507:[function(t,e,r){"use strict";var n=t("../plot_api/plot_config").dfltConfig,i=t("./notifier"),a=e.exports={};a.log=function(){var t;if(n.logging>1){var e=["LOG:"];for(t=0;t<arguments.length;t++)e.push(arguments[t]);console.trace.apply(console,e)}if(n.notifyOnLogging>1){var r=[];for(t=0;t<arguments.length;t++)r.push(arguments[t]);i(r.join("<br>"),"long")}},a.warn=function(){var t;if(n.logging>0){var e=["WARN:"];for(t=0;t<arguments.length;t++)e.push(arguments[t]);console.trace.apply(console,e)}if(n.notifyOnLogging>0){var r=[];for(t=0;t<arguments.length;t++)r.push(arguments[t]);i(r.join("<br>"),"stick")}},a.error=function(){var t;if(n.logging>0){var e=["ERROR:"];for(t=0;t<arguments.length;t++)e.push(arguments[t]);console.error.apply(console,e)}if(n.notifyOnLogging>0){var r=[];for(t=0;t<arguments.length;t++)r.push(arguments[t]);i(r.join("<br>"),"stick")}}},{"../plot_api/plot_config":541,"./notifier":513}],508:[function(t,e,r){"use strict";var n=t("@plotly/d3");e.exports=function(t,e,r){var i=t.selectAll("g."+r.replace(/\s/g,".")).data(e,(function(t){return t[0].trace.uid}));i.exit().remove(),i.enter().append("g").attr("class",r),i.order();var a=t.classed("rangeplot")?"nodeRangePlot3":"node3";return i.each((function(t){t[0][a]=n.select(this)})),i}},{"@plotly/d3":58}],509:[function(t,e,r){"use strict";var n=t("gl-mat4");r.init2dArray=function(t,e){for(var r=new Array(t),n=0;n<t;n++)r[n]=new Array(e);return r},r.transposeRagged=function(t){var e,r,n=0,i=t.length;for(e=0;e<i;e++)n=Math.max(n,t[e].length);var a=new Array(n);for(e=0;e<n;e++)for(a[e]=new Array(i),r=0;r<i;r++)a[e][r]=t[r][e];return a},r.dot=function(t,e){if(!t.length||!e.length||t.length!==e.length)return null;var n,i,a=t.length;if(t[0].length)for(n=new Array(a),i=0;i<a;i++)n[i]=r.dot(t[i],e);else if(e[0].length){var o=r.transposeRagged(e);for(n=new Array(o.length),i=0;i<o.length;i++)n[i]=r.dot(t,o[i])}else for(n=0,i=0;i<a;i++)n+=t[i]*e[i];return n},r.translationMatrix=function(t,e){return[[1,0,t],[0,1,e],[0,0,1]]},r.rotationMatrix=function(t){var e=t*Math.PI/180;return[[Math.cos(e),-Math.sin(e),0],[Math.sin(e),Math.cos(e),0],[0,0,1]]},r.rotationXYMatrix=function(t,e,n){return r.dot(r.dot(r.translationMatrix(e,n),r.rotationMatrix(t)),r.translationMatrix(-e,-n))},r.apply3DTransform=function(t){return function(){var e=arguments,n=1===arguments.length?e[0]:[e[0],e[1],e[2]||0];return r.dot(t,[n[0],n[1],n[2],1]).slice(0,3)}},r.apply2DTransform=function(t){return function(){var e=arguments;3===e.length&&(e=e[0]);var n=1===arguments.length?e[0]:[e[0],e[1]];return r.dot(t,[n[0],n[1],1]).slice(0,2)}},r.apply2DTransform2=function(t){var e=r.apply2DTransform(t);return function(t){return e(t.slice(0,2)).concat(e(t.slice(2,4)))}},r.convertCssMatrix=function(t){if(t){var e=t.length;if(16===e)return t;if(6===e)return[t[0],t[1],0,0,t[2],t[3],0,0,0,0,1,0,t[4],t[5],0,1]}return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]},r.inverseTransformMatrix=function(t){var e=[];return n.invert(e,t),[[e[0],e[1],e[2],e[3]],[e[4],e[5],e[6],e[7]],[e[8],e[9],e[10],e[11]],[e[12],e[13],e[14],e[15]]]}},{"gl-mat4":210}],510:[function(t,e,r){"use strict";e.exports={mod:function(t,e){var r=t%e;return r<0?r+e:r},modHalf:function(t,e){return Math.abs(t)>e/2?t-Math.round(t/e)*e:t}}},{}],511:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("./array").isArrayOrTypedArray;function a(t,e){return function(){var r,n,o,s,l,c=t;for(s=0;s<e.length-1;s++){if(-1===(r=e[s])){for(n=!0,o=[],l=0;l<c.length;l++)o[l]=a(c[l],e.slice(s+1))(),o[l]!==o[0]&&(n=!1);return n?o[0]:o}if("number"==typeof r&&!i(c))return;if("object"!=typeof(c=c[r])||null===c)return}if("object"==typeof c&&null!==c&&null!==(o=c[e[s]]))return o}}e.exports=function(t,e){if(n(e))e=String(e);else if("string"!=typeof e||"[-1]"===e.substr(e.length-4))throw"bad property string";for(var r,i,o,s=0,c=e.split(".");s<c.length;){if(r=String(c[s]).match(/^([^\[\]]*)((\[\-?[0-9]*\])+)$/)){if(r[1])c[s]=r[1];else{if(0!==s)throw"bad property string";c.splice(0,1)}for(i=r[2].substr(1,r[2].length-2).split("]["),o=0;o<i.length;o++)s++,c.splice(s,0,Number(i[o]))}s++}return"object"!=typeof t?function(t,e,r){return{set:function(){throw"bad container"},get:function(){},astr:e,parts:r,obj:t}}(t,e,c):{set:l(t,c,e),get:a(t,c),astr:e,parts:c,obj:t}};var o=/(^|\.)args\[/;function s(t,e){return void 0===t||null===t&&!e.match(o)}function l(t,e,r){return function(n){var a,o,l=t,h="",p=[[t,h]],d=s(n,r);for(o=0;o<e.length-1;o++){if("number"==typeof(a=e[o])&&!i(l))throw"array index but container is not an array";if(-1===a){if(d=!u(l,e.slice(o+1),n,r))break;return}if(!f(l,a,e[o+1],d))break;if("object"!=typeof(l=l[a])||null===l)throw"container is not an object";h=c(h,a),p.push([l,h])}if(d){if(o===e.length-1&&(delete l[e[o]],Array.isArray(l)&&+e[o]==l.length-1))for(;l.length&&void 0===l[l.length-1];)l.pop()}else l[e[o]]=n}}function c(t,e){var r=e;return n(e)?r="["+e+"]":t&&(r="."+e),t+r}function u(t,e,r,n){var a,o=i(r),c=!0,u=r,h=n.replace("-1",0),p=!o&&s(r,h),d=e[0];for(a=0;a<t.length;a++)h=n.replace("-1",a),o&&(p=s(u=r[a%r.length],h)),p&&(c=!1),f(t,a,d,p)&&l(t[a],e,n.replace("-1",a))(u);return c}function f(t,e,r,n){if(void 0===t[e]){if(n)return!1;t[e]="number"==typeof r?[]:{}}return!0}},{"./array":485,"fast-isnumeric":190}],512:[function(t,e,r){"use strict";e.exports=function(){}},{}],513:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("fast-isnumeric"),a=[];e.exports=function(t,e){if(-1===a.indexOf(t)){a.push(t);var r=1e3;i(e)?r=e:"long"===e&&(r=3e3);var o=n.select("body").selectAll(".plotly-notifier").data([0]);o.enter().append("div").classed("plotly-notifier",!0),o.selectAll(".notifier-note").data(a).enter().append("div").classed("notifier-note",!0).style("opacity",0).each((function(t){var i=n.select(this);i.append("button").classed("notifier-close",!0).html("&times;").on("click",(function(){i.transition().call(s)}));for(var a=i.append("p"),o=t.split(/<br\s*\/?>/g),l=0;l<o.length;l++)l&&a.append("br"),a.append("span").text(o[l]);"stick"===e?i.transition().duration(350).style("opacity",1):i.transition().duration(700).style("opacity",1).transition().delay(r).call(s)}))}function s(t){t.duration(700).style("opacity",0).each("end",(function(t){var e=a.indexOf(t);-1!==e&&a.splice(e,1),n.select(this).remove()}))}}},{"@plotly/d3":58,"fast-isnumeric":190}],514:[function(t,e,r){"use strict";var n=t("./setcursor"),i="data-savedcursor";e.exports=function(t,e){var r=t.attr(i);if(e){if(!r){for(var a=(t.attr("class")||"").split(" "),o=0;o<a.length;o++){var s=a[o];0===s.indexOf("cursor-")&&t.attr(i,s.substr(7)).classed(s,!1)}t.attr(i)||t.attr(i,"!!")}n(t,e)}else r&&(t.attr(i,null),"!!"===r?n(t):n(t,r))}},{"./setcursor":524}],515:[function(t,e,r){"use strict";var n=t("./matrix").dot,i=t("../constants/numerical").BADNUM,a=e.exports={};a.tester=function(t){var e,r=t.slice(),n=r[0][0],a=n,o=r[0][1],s=o;for(r.push(r[0]),e=1;e<r.length;e++)n=Math.min(n,r[e][0]),a=Math.max(a,r[e][0]),o=Math.min(o,r[e][1]),s=Math.max(s,r[e][1]);var l,c=!1;5===r.length&&(r[0][0]===r[1][0]?r[2][0]===r[3][0]&&r[0][1]===r[3][1]&&r[1][1]===r[2][1]&&(c=!0,l=function(t){return t[0]===r[0][0]}):r[0][1]===r[1][1]&&r[2][1]===r[3][1]&&r[0][0]===r[3][0]&&r[1][0]===r[2][0]&&(c=!0,l=function(t){return t[1]===r[0][1]}));var u=!0,f=r[0];for(e=1;e<r.length;e++)if(f[0]!==r[e][0]||f[1]!==r[e][1]){u=!1;break}return{xmin:n,xmax:a,ymin:o,ymax:s,pts:r,contains:c?function(t,e){var r=t[0],c=t[1];return!(r===i||r<n||r>a||c===i||c<o||c>s)&&(!e||!l(t))}:function(t,e){var l=t[0],c=t[1];if(l===i||l<n||l>a||c===i||c<o||c>s)return!1;var u,f,h,p,d,m=r.length,g=r[0][0],v=r[0][1],y=0;for(u=1;u<m;u++)if(f=g,h=v,g=r[u][0],v=r[u][1],!(l<(p=Math.min(f,g))||l>Math.max(f,g)||c>Math.max(h,v)))if(c<Math.min(h,v))l!==p&&y++;else{if(c===(d=g===f?c:h+(l-f)*(v-h)/(g-f)))return 1!==u||!e;c<=d&&l!==p&&y++}return y%2==1},isRect:c,degenerate:u}},a.isSegmentBent=function(t,e,r,i){var a,o,s,l=t[e],c=[t[r][0]-l[0],t[r][1]-l[1]],u=n(c,c),f=Math.sqrt(u),h=[-c[1]/f,c[0]/f];for(a=e+1;a<r;a++)if(o=[t[a][0]-l[0],t[a][1]-l[1]],(s=n(o,c))<0||s>u||Math.abs(n(o,h))>i)return!0;return!1},a.filter=function(t,e){var r=[t[0]],n=0,i=0;function o(o){t.push(o);var s=r.length,l=n;r.splice(i+1);for(var c=l+1;c<t.length;c++)(c===t.length-1||a.isSegmentBent(t,l,c+1,e))&&(r.push(t[c]),r.length<s-2&&(n=c,i=r.length-1),l=c)}t.length>1&&o(t.pop());return{addPt:o,raw:t,filtered:r}}},{"../constants/numerical":479,"./matrix":509}],516:[function(t,e,r){(function(r){(function(){"use strict";var n=t("./show_no_webgl_msg"),i=t("regl");e.exports=function(t,e,a){var o=t._fullLayout,s=!0;return o._glcanvas.each((function(n){if(n.regl)n.regl.preloadCachedCode(a);else if(!n.pick||o._has("parcoords")){try{n.regl=i({canvas:this,attributes:{antialias:!n.pick,preserveDrawingBuffer:!0},pixelRatio:t._context.plotGlPixelRatio||r.devicePixelRatio,extensions:e||[],cachedCode:a||{}})}catch(t){s=!1}n.regl||(s=!1),s&&this.addEventListener("webglcontextlost",(function(e){t&&t.emit&&t.emit("plotly_webglcontextlost",{event:e,layer:n.key})}),!1)}})),s||n({container:o._glcontainer.node()}),s}}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./show_no_webgl_msg":525,regl:283}],517:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("is-mobile");e.exports=function(t){var e;if("string"!=typeof(e=t&&t.hasOwnProperty("userAgent")?t.userAgent:function(){var t;"undefined"!=typeof navigator&&(t=navigator.userAgent);t&&t.headers&&"string"==typeof t.headers["user-agent"]&&(t=t.headers["user-agent"]);return t}()))return!0;var r=i({ua:{headers:{"user-agent":e}},tablet:!0,featureDetect:!1});if(!r)for(var a=e.split(" "),o=1;o<a.length;o++){if(-1!==a[o].indexOf("Safari"))for(var s=o-1;s>-1;s--){var l=a[s];if("Version/"===l.substr(0,8)){var c=l.substr(8).split(".")[0];if(n(c)&&(c=+c),c>=13)return!0}}}return r}},{"fast-isnumeric":190,"is-mobile":234}],518:[function(t,e,r){"use strict";e.exports=function(t,e){if(e instanceof RegExp){for(var r=e.toString(),n=0;n<t.length;n++)if(t[n]instanceof RegExp&&t[n].toString()===r)return t;t.push(e)}else!e&&0!==e||-1!==t.indexOf(e)||t.push(e);return t}},{}],519:[function(t,e,r){"use strict";var n=t("../lib"),i=t("../plot_api/plot_config").dfltConfig;var a={add:function(t,e,r,n,a){var o,s;t.undoQueue=t.undoQueue||{index:0,queue:[],sequence:!1},s=t.undoQueue.index,t.autoplay?t.undoQueue.inSequence||(t.autoplay=!1):(!t.undoQueue.sequence||t.undoQueue.beginSequence?(o={undo:{calls:[],args:[]},redo:{calls:[],args:[]}},t.undoQueue.queue.splice(s,t.undoQueue.queue.length-s,o),t.undoQueue.index+=1):o=t.undoQueue.queue[s-1],t.undoQueue.beginSequence=!1,o&&(o.undo.calls.unshift(e),o.undo.args.unshift(r),o.redo.calls.push(n),o.redo.args.push(a)),t.undoQueue.queue.length>i.queueLength&&(t.undoQueue.queue.shift(),t.undoQueue.index--))},startSequence:function(t){t.undoQueue=t.undoQueue||{index:0,queue:[],sequence:!1},t.undoQueue.sequence=!0,t.undoQueue.beginSequence=!0},stopSequence:function(t){t.undoQueue=t.undoQueue||{index:0,queue:[],sequence:!1},t.undoQueue.sequence=!1,t.undoQueue.beginSequence=!1},undo:function(t){var e,r;if(!(void 0===t.undoQueue||isNaN(t.undoQueue.index)||t.undoQueue.index<=0)){for(t.undoQueue.index--,e=t.undoQueue.queue[t.undoQueue.index],t.undoQueue.inSequence=!0,r=0;r<e.undo.calls.length;r++)a.plotDo(t,e.undo.calls[r],e.undo.args[r]);t.undoQueue.inSequence=!1,t.autoplay=!1}},redo:function(t){var e,r;if(!(void 0===t.undoQueue||isNaN(t.undoQueue.index)||t.undoQueue.index>=t.undoQueue.queue.length)){for(e=t.undoQueue.queue[t.undoQueue.index],t.undoQueue.inSequence=!0,r=0;r<e.redo.calls.length;r++)a.plotDo(t,e.redo.calls[r],e.redo.args[r]);t.undoQueue.inSequence=!1,t.autoplay=!1,t.undoQueue.index++}}};a.plotDo=function(t,e,r){t.autoplay=!0,r=function(t,e){for(var r,i=[],a=0;a<e.length;a++)r=e[a],i[a]=r===t?r:"object"==typeof r?Array.isArray(r)?n.extendDeep([],r):n.extendDeepAll({},r):r;return i}(t,r),e.apply(null,r)},e.exports=a},{"../lib":503,"../plot_api/plot_config":541}],520:[function(t,e,r){"use strict";r.counter=function(t,e,r,n){var i=(e||"")+(r?"":"$"),a=!1===n?"":"^";return"xy"===t?new RegExp(a+"x([2-9]|[1-9][0-9]+)?y([2-9]|[1-9][0-9]+)?"+i):new RegExp(a+t+"([2-9]|[1-9][0-9]+)?"+i)}},{}],521:[function(t,e,r){"use strict";var n=/^(.*)(\.[^\.\[\]]+|\[\d\])$/,i=/^[^\.\[\]]+$/;e.exports=function(t,e){for(;e;){var r=t.match(n);if(r)t=r[1];else{if(!t.match(i))throw new Error("bad relativeAttr call:"+[t,e]);t=""}if("^"!==e.charAt(0))break;e=e.slice(1)}return t&&"["!==e.charAt(0)?t+"."+e:t+e}},{}],522:[function(t,e,r){"use strict";var n=t("./array").isArrayOrTypedArray,i=t("./is_plain_object");e.exports=function t(e,r){for(var a in r){var o=r[a],s=e[a];if(s!==o)if("_"===a.charAt(0)||"function"==typeof o){if(a in e)continue;e[a]=o}else if(n(o)&&n(s)&&i(o[0])){if("customdata"===a||"ids"===a)continue;for(var l=Math.min(o.length,s.length),c=0;c<l;c++)s[c]!==o[c]&&i(o[c])&&i(s[c])&&t(s[c],o[c])}else i(o)&&i(s)&&(t(s,o),Object.keys(s).length||delete e[a])}}},{"./array":485,"./is_plain_object":504}],523:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("./loggers"),a=t("./identity"),o=t("../constants/numerical").BADNUM;function s(t,e){return t<e}function l(t,e){return t<=e}function c(t,e){return t>e}function u(t,e){return t>=e}r.findBin=function(t,e,r){if(n(e.start))return r?Math.ceil((t-e.start)/e.size-1e-9)-1:Math.floor((t-e.start)/e.size+1e-9);var a,o,f=0,h=e.length,p=0,d=h>1?(e[h-1]-e[0])/(h-1):1;for(o=d>=0?r?s:l:r?u:c,t+=1e-9*d*(r?-1:1)*(d>=0?1:-1);f<h&&p++<100;)o(e[a=Math.floor((f+h)/2)],t)?f=a+1:h=a;return p>90&&i.log("Long binary search..."),f-1},r.sorterAsc=function(t,e){return t-e},r.sorterDes=function(t,e){return e-t},r.distinctVals=function(t){var e,n=t.slice();for(n.sort(r.sorterAsc),e=n.length-1;e>-1&&n[e]===o;e--);for(var i,a=n[e]-n[0]||1,s=a/(e||1)/1e4,l=[],c=0;c<=e;c++){var u=n[c],f=u-i;void 0===i?(l.push(u),i=u):f>s&&(a=Math.min(a,f),l.push(u),i=u)}return{vals:l,minDiff:a}},r.roundUp=function(t,e,r){for(var n,i=0,a=e.length-1,o=0,s=r?0:1,l=r?1:0,c=r?Math.ceil:Math.floor;i<a&&o++<100;)e[n=c((i+a)/2)]<=t?i=n+s:a=n-l;return e[i]},r.sort=function(t,e){for(var r=0,n=0,i=1;i<t.length;i++){var a=e(t[i],t[i-1]);if(a<0?r=1:a>0&&(n=1),r&&n)return t.sort(e)}return n?t:t.reverse()},r.findIndexOfMin=function(t,e){e=e||a;for(var r,n=1/0,i=0;i<t.length;i++){var o=e(t[i]);o<n&&(n=o,r=i)}return r}},{"../constants/numerical":479,"./identity":501,"./loggers":507,"fast-isnumeric":190}],524:[function(t,e,r){"use strict";e.exports=function(t,e){(t.attr("class")||"").split(" ").forEach((function(e){0===e.indexOf("cursor-")&&t.classed(e,!1)})),e&&t.classed("cursor-"+e,!0)}},{}],525:[function(t,e,r){"use strict";var n=t("../components/color"),i=function(){};e.exports=function(t){for(var e in t)"function"==typeof t[e]&&(t[e]=i);t.destroy=function(){t.container.parentNode.removeChild(t.container)};var r=document.createElement("div");r.className="no-webgl",r.style.cursor="pointer",r.style.fontSize="24px",r.style.color=n.defaults[0],r.style.position="absolute",r.style.left=r.style.top="0px",r.style.width=r.style.height="100%",r.style["background-color"]=n.lightLine,r.style["z-index"]=30;var a=document.createElement("p");return a.textContent="WebGL is not supported by your browser - visit https://get.webgl.org for more info",a.style.position="relative",a.style.top="50%",a.style.left="50%",a.style.height="30%",a.style.width="50%",a.style.margin="-15% 0 0 -25%",r.appendChild(a),t.container.appendChild(r),t.container.style.background="#FFFFFF",t.container.onclick=function(){window.open("https://get.webgl.org")},!1}},{"../components/color":366}],526:[function(t,e,r){"use strict";e.exports=function(t){return Object.keys(t).sort()}},{}],527:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("./array").isArrayOrTypedArray;r.aggNums=function(t,e,a,o){var s,l;if((!o||o>a.length)&&(o=a.length),n(e)||(e=!1),i(a[0])){for(l=new Array(o),s=0;s<o;s++)l[s]=r.aggNums(t,e,a[s]);a=l}for(s=0;s<o;s++)n(e)?n(a[s])&&(e=t(+e,+a[s])):e=a[s];return e},r.len=function(t){return r.aggNums((function(t){return t+1}),0,t)},r.mean=function(t,e){return e||(e=r.len(t)),r.aggNums((function(t,e){return t+e}),0,t)/e},r.midRange=function(t){if(void 0!==t&&0!==t.length)return(r.aggNums(Math.max,null,t)+r.aggNums(Math.min,null,t))/2},r.variance=function(t,e,i){return e||(e=r.len(t)),n(i)||(i=r.mean(t,e)),r.aggNums((function(t,e){return t+Math.pow(e-i,2)}),0,t)/e},r.stdev=function(t,e,n){return Math.sqrt(r.variance(t,e,n))},r.median=function(t){var e=t.slice().sort();return r.interp(e,.5)},r.interp=function(t,e){if(!n(e))throw"n should be a finite number";if((e=e*t.length-.5)<0)return t[0];if(e>t.length-1)return t[t.length-1];var r=e%1;return r*t[Math.ceil(e)]+(1-r)*t[Math.floor(e)]}},{"./array":485,"fast-isnumeric":190}],528:[function(t,e,r){"use strict";var n=t("color-normalize");e.exports=function(t){return t?n(t):[0,0,0,1]}},{"color-normalize":89}],529:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../lib"),a=i.strTranslate,o=t("../constants/xmlns_namespaces"),s=t("../constants/alignment").LINE_SPACING,l=/([^$]*)([$]+[^$]*[$]+)([^$]*)/;r.convertToTspans=function(t,e,m){var M=t.text(),S=!t.attr("data-notex")&&e&&e._context.typesetMath&&"undefined"!=typeof MathJax&&M.match(l),C=n.select(t.node().parentNode);if(!C.empty()){var P=t.attr("class")?t.attr("class").split(" ")[0]:"text";return P+="-math",C.selectAll("svg."+P).remove(),C.selectAll("g."+P+"-group").remove(),t.style("display",null).attr({"data-unformatted":M,"data-math":"N"}),S?(e&&e._promises||[]).push(new Promise((function(e){t.style("display","none");var r=parseInt(t.node().style.fontSize,10),o={fontSize:r};!function(t,e,r){var a,o,s,l,h=parseInt((MathJax.version||"").split(".")[0]);if(2!==h&&3!==h)return void i.warn("No MathJax version:",MathJax.version);var p=function(){var r="math-output-"+i.randstr({},64),a=(l=n.select("body").append("div").attr({id:r}).style({visibility:"hidden",position:"absolute","font-size":e.fontSize+"px"}).text(t.replace(c,"\\lt ").replace(u,"\\gt "))).node();return 2===h?MathJax.Hub.Typeset(a):MathJax.typeset([a])},d=function(){var e=l.select(2===h?".MathJax_SVG":".MathJax"),a=!e.empty()&&l.select("svg").node();if(a){var o,s=a.getBoundingClientRect();o=2===h?n.select("body").select("#MathJax_SVG_glyphs"):e.select("defs"),r(e,o,s)}else i.log("There was an error in the tex syntax.",t),r();l.remove()};2===h?MathJax.Hub.Queue((function(){return o=i.extendDeepAll({},MathJax.Hub.config),s=MathJax.Hub.processSectionDelay,void 0!==MathJax.Hub.processSectionDelay&&(MathJax.Hub.processSectionDelay=0),MathJax.Hub.Config({messageStyle:"none",tex2jax:{inlineMath:f},displayAlign:"left"})}),(function(){if("SVG"!==(a=MathJax.Hub.config.menuSettings.renderer))return MathJax.Hub.setRenderer("SVG")}),p,d,(function(){if("SVG"!==a)return MathJax.Hub.setRenderer(a)}),(function(){return void 0!==s&&(MathJax.Hub.processSectionDelay=s),MathJax.Hub.Config(o)})):3===h&&(o=i.extendDeepAll({},MathJax.config),MathJax.config.tex||(MathJax.config.tex={}),MathJax.config.tex.inlineMath=f,"svg"!==(a=MathJax.config.startup.output)&&(MathJax.config.startup.output="svg"),MathJax.startup.defaultReady(),MathJax.startup.promise.then((function(){p(),d(),"svg"!==a&&(MathJax.config.startup.output=a),MathJax.config=o})))}(S[2],o,(function(n,i,o){C.selectAll("svg."+P).remove(),C.selectAll("g."+P+"-group").remove();var s=n&&n.select("svg");if(!s||!s.node())return I(),void e();var l=C.append("g").classed(P+"-group",!0).attr({"pointer-events":"none","data-unformatted":M,"data-math":"Y"});l.node().appendChild(s.node()),i&&i.node()&&s.node().insertBefore(i.node().cloneNode(!0),s.node().firstChild);var c=o.width,u=o.height;s.attr({class:P,height:u,preserveAspectRatio:"xMinYMin meet"}).style({overflow:"visible","pointer-events":"none"});var f=t.node().style.fill||"black",h=s.select("g");h.attr({fill:f,stroke:f});var p=h.node().getBoundingClientRect(),d=p.width,g=p.height;(d>c||g>u)&&(s.style("overflow","hidden"),d=(p=s.node().getBoundingClientRect()).width,g=p.height);var v=+t.attr("x"),y=+t.attr("y"),x=-(r||t.node().getBoundingClientRect().height)/4;if("y"===P[0])l.attr({transform:"rotate("+[-90,v,y]+")"+a(-d/2,x-g/2)});else if("l"===P[0])y=x-g/2;else if("a"===P[0]&&0!==P.indexOf("atitle"))v=0,y=x;else{var b=t.attr("text-anchor");v-=d*("middle"===b?.5:"end"===b?1:0),y=y+x-g/2}s.attr({x:v,y:y}),m&&m.call(t,l),e(l)}))}))):I(),t}function I(){C.empty()||(P=t.attr("class")+"-math",C.select("svg."+P).remove()),t.text("").style("white-space","pre"),function(t,e){e=e.replace(g," ");var r,a=!1,l=[],c=-1;function u(){c++;var e=document.createElementNS(o.svg,"tspan");n.select(e).attr({class:"line",dy:c*s+"em"}),t.appendChild(e),r=e;var i=l;if(l=[{node:e}],i.length>1)for(var a=1;a<i.length;a++)f(i[a])}function f(t){var e,i=t.type,a={};if("a"===i){e="a";var s=t.target,c=t.href,u=t.popup;c&&(a={"xlink:xlink:show":"_blank"===s||"_"!==s.charAt(0)?"new":"replace",target:s,"xlink:xlink:href":c},u&&(a.onclick='window.open(this.href.baseVal,this.target.baseVal,"'+u+'");return false;'))}else e="tspan";t.style&&(a.style=t.style);var f=document.createElementNS(o.svg,e);if("sup"===i||"sub"===i){m(r,"\u200b"),r.appendChild(f);var h=document.createElementNS(o.svg,"tspan");m(h,"\u200b"),n.select(h).attr("dy",d[i]),a.dy=p[i],r.appendChild(f),r.appendChild(h)}else r.appendChild(f);n.select(f).attr(a),r=t.node=f,l.push(t)}function m(t,e){t.appendChild(document.createTextNode(e))}function M(t){if(1!==l.length){var n=l.pop();t!==n.type&&i.log("Start tag <"+n.type+"> doesnt match end tag <"+t+">. Pretending it did match.",e),r=l[l.length-1].node}else i.log("Ignoring unexpected end tag </"+t+">.",e)}x.test(e)?u():(r=t,l=[{node:t}]);for(var S=e.split(v),C=0;C<S.length;C++){var P=S[C],I=P.match(y),O=I&&I[2].toLowerCase(),z=h[O];if("br"===O)u();else if(void 0===z)m(r,E(P));else if(I[1])M(O);else{var D=I[4],R={type:O},F=k(D,b);if(F?(F=F.replace(A,"$1 fill:"),z&&(F+=";"+z)):z&&(F=z),F&&(R.style=F),"a"===O){a=!0;var B=k(D,_);if(B){var N=L(B);N&&(R.href=N,R.target=k(D,w)||"_blank",R.popup=k(D,T))}}f(R)}}return a}(t.node(),M)&&t.style("pointer-events","all"),r.positionText(t),m&&m.call(t)}};var c=/(<|&lt;|&#60;)/g,u=/(>|&gt;|&#62;)/g;var f=[["$","$"],["\\(","\\)"]];var h={sup:"font-size:70%",sub:"font-size:70%",b:"font-weight:bold",i:"font-style:italic",a:"cursor:pointer",span:"",em:"font-style:italic;font-weight:bold"},p={sub:"0.3em",sup:"-0.6em"},d={sub:"-0.21em",sup:"0.42em"},m=["http:","https:","mailto:","",void 0,":"],g=r.NEWLINES=/(\r\n?|\n)/g,v=/(<[^<>]*>)/,y=/<(\/?)([^ >]*)(\s+(.*))?>/i,x=/<br(\s+.*)?>/i;r.BR_TAG_ALL=/<br(\s+.*)?>/gi;var b=/(^|[\s"'])style\s*=\s*("([^"]*);?"|'([^']*);?')/i,_=/(^|[\s"'])href\s*=\s*("([^"]*)"|'([^']*)')/i,w=/(^|[\s"'])target\s*=\s*("([^"\s]*)"|'([^'\s]*)')/i,T=/(^|[\s"'])popup\s*=\s*("([\w=,]*)"|'([\w=,]*)')/i;function k(t,e){if(!t)return null;var r=t.match(e),n=r&&(r[3]||r[4]);return n&&E(n)}var A=/(^|;)\s*color:/;r.plainText=function(t,e){for(var r=void 0!==(e=e||{}).len&&-1!==e.len?e.len:1/0,n=void 0!==e.allowedTags?e.allowedTags:["br"],i="...".length,a=t.split(v),o=[],s="",l=0,c=0;c<a.length;c++){var u=a[c],f=u.match(y),h=f&&f[2].toLowerCase();if(h)-1!==n.indexOf(h)&&(o.push(u),s=h);else{var p=u.length;if(l+p<r)o.push(u),l+=p;else if(l<r){var d=r-l;s&&("br"!==s||d<=i||p<=i)&&o.pop(),r>i?o.push(u.substr(0,d-i)+"..."):o.push(u.substr(0,d));break}s=""}}return o.join("")};var M={mu:"\u03bc",amp:"&",lt:"<",gt:">",nbsp:"\xa0",times:"\xd7",plusmn:"\xb1",deg:"\xb0"},S=/&(#\d+|#x[\da-fA-F]+|[a-z]+);/g;function E(t){return t.replace(S,(function(t,e){return("#"===e.charAt(0)?function(t){if(t>1114111)return;var e=String.fromCodePoint;if(e)return e(t);var r=String.fromCharCode;return t<=65535?r(t):r(55232+(t>>10),t%1024+56320)}("x"===e.charAt(1)?parseInt(e.substr(2),16):parseInt(e.substr(1),10)):M[e])||t}))}function L(t){var e=encodeURI(decodeURI(t)),r=document.createElement("a"),n=document.createElement("a");r.href=t,n.href=e;var i=r.protocol,a=n.protocol;return-1!==m.indexOf(i)&&-1!==m.indexOf(a)?e:""}function C(t,e,r){var n,a,o,s=r.horizontalAlign,l=r.verticalAlign||"top",c=t.node().getBoundingClientRect(),u=e.node().getBoundingClientRect();return a="bottom"===l?function(){return c.bottom-n.height}:"middle"===l?function(){return c.top+(c.height-n.height)/2}:function(){return c.top},o="right"===s?function(){return c.right-n.width}:"center"===s?function(){return c.left+(c.width-n.width)/2}:function(){return c.left},function(){n=this.node().getBoundingClientRect();var t=o()-u.left,e=a()-u.top,s=r.gd||{};if(r.gd){s._fullLayout._calcInverseTransform(s);var l=i.apply3DTransform(s._fullLayout._invTransform)(t,e);t=l[0],e=l[1]}return this.style({top:e+"px",left:t+"px","z-index":1e3}),this}}r.convertEntities=E,r.sanitizeHTML=function(t){t=t.replace(g," ");for(var e=document.createElement("p"),r=e,i=[],a=t.split(v),o=0;o<a.length;o++){var s=a[o],l=s.match(y),c=l&&l[2].toLowerCase();if(c in h)if(l[1])i.length&&(r=i.pop());else{var u=l[4],f=k(u,b),p=f?{style:f}:{};if("a"===c){var d=k(u,_);if(d){var m=L(d);if(m){p.href=m;var x=k(u,w);x&&(p.target=x)}}}var T=document.createElement(c);r.appendChild(T),n.select(T).attr(p),r=T,i.push(T)}else r.appendChild(document.createTextNode(E(s)))}return e.innerHTML},r.lineCount=function(t){return t.selectAll("tspan.line").size()||1},r.positionText=function(t,e,r){return t.each((function(){var t=n.select(this);function i(e,r){return void 0===r?null===(r=t.attr(e))&&(t.attr(e,0),r=0):t.attr(e,r),r}var a=i("x",e),o=i("y",r);"text"===this.nodeName&&t.selectAll("tspan.line").attr({x:a,y:o})}))};r.makeTextShadow=function(t){var e="1px ",r="1px ",n="1px ";return e+r+n+t+", -"+e+"-"+r+n+t+", "+e+"-"+r+n+t+", -"+e+r+n+t},r.makeEditable=function(t,e){var r=e.gd,i=e.delegate,a=n.dispatch("edit","input","cancel"),o=i||t;if(t.style({"pointer-events":i?"none":"all"}),1!==t.size())throw new Error("boo");function s(){!function(){var i=n.select(r).select(".svg-container"),o=i.append("div"),s=t.node().style,c=parseFloat(s.fontSize||12),u=e.text;void 0===u&&(u=t.attr("data-unformatted"));o.classed("plugin-editable editable",!0).style({position:"absolute","font-family":s.fontFamily||"Arial","font-size":c,color:e.fill||s.fill||"black",opacity:1,"background-color":e.background||"transparent",outline:"#ffffff33 1px solid",margin:[-c/8+1,0,0,-1].join("px ")+"px",padding:"0","box-sizing":"border-box"}).attr({contenteditable:!0}).text(u).call(C(t,i,e)).on("blur",(function(){r._editing=!1,t.text(this.textContent).style({opacity:1});var e,i=n.select(this).attr("class");(e=i?"."+i.split(" ")[0]+"-math-group":"[class*=-math-group]")&&n.select(t.node().parentNode).select(e).style({opacity:0});var o=this.textContent;n.select(this).transition().duration(0).remove(),n.select(document).on("mouseup",null),a.edit.call(t,o)})).on("focus",(function(){var t=this;r._editing=!0,n.select(document).on("mouseup",(function(){if(n.event.target===t)return!1;document.activeElement===o.node()&&o.node().blur()}))})).on("keyup",(function(){27===n.event.which?(r._editing=!1,t.style({opacity:1}),n.select(this).style({opacity:0}).on("blur",(function(){return!1})).transition().remove(),a.cancel.call(t,this.textContent)):(a.input.call(t,this.textContent),n.select(this).call(C(t,i,e)))})).on("keydown",(function(){13===n.event.which&&this.blur()})).call(l)}(),t.style({opacity:0});var i,s=o.attr("class");(i=s?"."+s.split(" ")[0]+"-math-group":"[class*=-math-group]")&&n.select(t.node().parentNode).select(i).style({opacity:0})}function l(t){var e=t.node(),r=document.createRange();r.selectNodeContents(e);var n=window.getSelection();n.removeAllRanges(),n.addRange(r),e.focus()}return e.immediate?s():o.on("click",s),n.rebind(t,a,"on")}},{"../constants/alignment":471,"../constants/xmlns_namespaces":480,"../lib":503,"@plotly/d3":58}],530:[function(t,e,r){"use strict";var n={};function i(t){t&&null!==t.timer&&(clearTimeout(t.timer),t.timer=null)}r.throttle=function(t,e,r){var a=n[t],o=Date.now();if(!a){for(var s in n)n[s].ts<o-6e4&&delete n[s];a=n[t]={ts:0,timer:null}}function l(){r(),a.ts=Date.now(),a.onDone&&(a.onDone(),a.onDone=null)}i(a),o>a.ts+e?l():a.timer=setTimeout((function(){l(),a.timer=null}),e)},r.done=function(t){var e=n[t];return e&&e.timer?new Promise((function(t){var r=e.onDone;e.onDone=function(){r&&r(),t(),e.onDone=null}})):Promise.resolve()},r.clear=function(t){if(t)i(n[t]),delete n[t];else for(var e in n)r.clear(e)}},{}],531:[function(t,e,r){"use strict";var n=t("fast-isnumeric");e.exports=function(t,e){if(t>0)return Math.log(t)/Math.LN10;var r=Math.log(Math.min(e[0],e[1]))/Math.LN10;return n(r)||(r=Math.log(Math.max(e[0],e[1]))/Math.LN10-6),r}},{"fast-isnumeric":190}],532:[function(t,e,r){"use strict";var n=e.exports={},i=t("../plots/geo/constants").locationmodeToLayer,a=t("topojson-client").feature;n.getTopojsonName=function(t){return[t.scope.replace(/ /g,"-"),"_",t.resolution.toString(),"m"].join("")},n.getTopojsonPath=function(t,e){return t+e+".json"},n.getTopojsonFeatures=function(t,e){var r=i[t.locationmode],n=e.objects[r];return a(e,n).features}},{"../plots/geo/constants":587,"topojson-client":315}],533:[function(t,e,r){"use strict";e.exports={moduleType:"locale",name:"en-US",dictionary:{"Click to enter Colorscale title":"Click to enter Colorscale title"},format:{date:"%m/%d/%Y"}}},{}],534:[function(t,e,r){"use strict";e.exports={moduleType:"locale",name:"en",dictionary:{"Click to enter Colorscale title":"Click to enter Colourscale title"},format:{days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],periods:["AM","PM"],dateTime:"%a %b %e %X %Y",date:"%d/%m/%Y",time:"%H:%M:%S",decimal:".",thousands:",",grouping:[3],currency:["$",""],year:"%Y",month:"%b %Y",dayMonth:"%b %-d",dayMonthYear:"%b %-d, %Y"}}},{}],535:[function(t,e,r){"use strict";var n=t("../registry");e.exports=function(t){for(var e,r,i=n.layoutArrayContainers,a=n.layoutArrayRegexes,o=t.split("[")[0],s=0;s<a.length;s++)if((r=t.match(a[s]))&&0===r.index){e=r[0];break}if(e||(e=i[i.indexOf(o)]),!e)return!1;var l=t.substr(e.length);return l?!!(r=l.match(/^\[(0|[1-9][0-9]*)\](\.(.+))?$/))&&{array:e,index:Number(r[1]),property:r[3]||""}:{array:e,index:"",property:""}}},{"../registry":638}],536:[function(t,e,r){"use strict";var n=t("../lib"),i=n.extendFlat,a=n.isPlainObject,o={valType:"flaglist",extras:["none"],flags:["calc","clearAxisTypes","plot","style","markerSize","colorbars"]},s={valType:"flaglist",extras:["none"],flags:["calc","plot","legend","ticks","axrange","layoutstyle","modebar","camera","arraydraw","colorbars"]},l=o.flags.slice().concat(["fullReplot"]),c=s.flags.slice().concat("layoutReplot");function u(t){for(var e={},r=0;r<t.length;r++)e[t[r]]=!1;return e}function f(t,e,r){var n=i({},t);for(var o in n){var s=n[o];a(s)&&(n[o]=h(s,e,r,o))}return"from-root"===r&&(n.editType=e),n}function h(t,e,r,n){if(t.valType){var a=i({},t);if(a.editType=e,Array.isArray(t.items)){a.items=new Array(t.items.length);for(var o=0;o<t.items.length;o++)a.items[o]=h(t.items[o],e,"from-root")}return a}return f(t,e,"_"===n.charAt(0)?"nested":"from-root")}e.exports={traces:o,layout:s,traceFlags:function(){return u(l)},layoutFlags:function(){return u(c)},update:function(t,e){var r=e.editType;if(r&&"none"!==r)for(var n=r.split("+"),i=0;i<n.length;i++)t[n[i]]=!0},overrideAll:f}},{"../lib":503}],537:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("gl-mat4/fromQuat"),a=t("../registry"),o=t("../lib"),s=t("../plots/plots"),l=t("../plots/cartesian/axis_ids"),c=t("../components/color"),u=l.cleanId,f=l.getFromTrace,h=a.traceIs;function p(t,e){var r=t[e],n=e.charAt(0);r&&"paper"!==r&&(t[e]=u(r,n,!0))}function d(t){function e(e,r){var n=t[e],i=t.title&&t.title[r];n&&!i&&(t.title||(t.title={}),t.title[r]=t[e],delete t[e])}t&&("string"!=typeof t.title&&"number"!=typeof t.title||(t.title={text:t.title}),e("titlefont","font"),e("titleposition","position"),e("titleside","side"),e("titleoffset","offset"))}function m(t){if(!o.isPlainObject(t))return!1;var e=t.name;return delete t.name,delete t.showlegend,("string"==typeof e||"number"==typeof e)&&String(e)}function g(t,e,r,n){if(r&&!n)return t;if(n&&!r)return e;if(!t.trim())return e;if(!e.trim())return t;var i,a=Math.min(t.length,e.length);for(i=0;i<a&&t.charAt(i)===e.charAt(i);i++);return t.substr(0,i).trim()}function v(t){var e="middle",r="center";return"string"==typeof t&&(-1!==t.indexOf("top")?e="top":-1!==t.indexOf("bottom")&&(e="bottom"),-1!==t.indexOf("left")?r="left":-1!==t.indexOf("right")&&(r="right")),e+" "+r}function y(t,e){return e in t&&"object"==typeof t[e]&&0===Object.keys(t[e]).length}r.clearPromiseQueue=function(t){Array.isArray(t._promises)&&t._promises.length>0&&o.log("Clearing previous rejected promises from queue."),t._promises=[]},r.cleanLayout=function(t){var e,n;t||(t={}),t.xaxis1&&(t.xaxis||(t.xaxis=t.xaxis1),delete t.xaxis1),t.yaxis1&&(t.yaxis||(t.yaxis=t.yaxis1),delete t.yaxis1),t.scene1&&(t.scene||(t.scene=t.scene1),delete t.scene1);var a=(s.subplotsRegistry.cartesian||{}).attrRegex,l=(s.subplotsRegistry.polar||{}).attrRegex,f=(s.subplotsRegistry.ternary||{}).attrRegex,h=(s.subplotsRegistry.gl3d||{}).attrRegex,m=Object.keys(t);for(e=0;e<m.length;e++){var g=m[e];if(a&&a.test(g)){var v=t[g];v.anchor&&"free"!==v.anchor&&(v.anchor=u(v.anchor)),v.overlaying&&(v.overlaying=u(v.overlaying)),v.type||(v.isdate?v.type="date":v.islog?v.type="log":!1===v.isdate&&!1===v.islog&&(v.type="linear")),"withzero"!==v.autorange&&"tozero"!==v.autorange||(v.autorange=!0,v.rangemode="tozero"),delete v.islog,delete v.isdate,delete v.categories,y(v,"domain")&&delete v.domain,void 0!==v.autotick&&(void 0===v.tickmode&&(v.tickmode=v.autotick?"auto":"linear"),delete v.autotick),d(v)}else if(l&&l.test(g)){d(t[g].radialaxis)}else if(f&&f.test(g)){var x=t[g];d(x.aaxis),d(x.baxis),d(x.caxis)}else if(h&&h.test(g)){var b=t[g],_=b.cameraposition;if(Array.isArray(_)&&4===_[0].length){var w=_[0],T=_[1],k=_[2],A=i([],w),M=[];for(n=0;n<3;++n)M[n]=T[n]+k*A[2+4*n];b.camera={eye:{x:M[0],y:M[1],z:M[2]},center:{x:T[0],y:T[1],z:T[2]},up:{x:0,y:0,z:1}},delete b.cameraposition}d(b.xaxis),d(b.yaxis),d(b.zaxis)}}var S=Array.isArray(t.annotations)?t.annotations.length:0;for(e=0;e<S;e++){var E=t.annotations[e];o.isPlainObject(E)&&(E.ref&&("paper"===E.ref?(E.xref="paper",E.yref="paper"):"data"===E.ref&&(E.xref="x",E.yref="y"),delete E.ref),p(E,"xref"),p(E,"yref"))}var L=Array.isArray(t.shapes)?t.shapes.length:0;for(e=0;e<L;e++){var C=t.shapes[e];o.isPlainObject(C)&&(p(C,"xref"),p(C,"yref"))}var P=Array.isArray(t.images)?t.images.length:0;for(e=0;e<P;e++){var I=t.images[e];o.isPlainObject(I)&&(p(I,"xref"),p(I,"yref"))}var O=t.legend;return O&&(O.x>3?(O.x=1.02,O.xanchor="left"):O.x<-2&&(O.x=-.02,O.xanchor="right"),O.y>3?(O.y=1.02,O.yanchor="bottom"):O.y<-2&&(O.y=-.02,O.yanchor="top")),d(t),"rotate"===t.dragmode&&(t.dragmode="orbit"),c.clean(t),t.template&&t.template.layout&&r.cleanLayout(t.template.layout),t},r.cleanData=function(t){for(var e=0;e<t.length;e++){var n,i=t[e];if("histogramy"===i.type&&"xbins"in i&&!("ybins"in i)&&(i.ybins=i.xbins,delete i.xbins),i.error_y&&"opacity"in i.error_y){var l=c.defaults,f=i.error_y.color||(h(i,"bar")?c.defaultLine:l[e%l.length]);i.error_y.color=c.addOpacity(c.rgb(f),c.opacity(f)*i.error_y.opacity),delete i.error_y.opacity}if("bardir"in i&&("h"!==i.bardir||!h(i,"bar")&&"histogram"!==i.type.substr(0,9)||(i.orientation="h",r.swapXYData(i)),delete i.bardir),"histogramy"===i.type&&r.swapXYData(i),"histogramx"!==i.type&&"histogramy"!==i.type||(i.type="histogram"),"scl"in i&&!("colorscale"in i)&&(i.colorscale=i.scl,delete i.scl),"reversescl"in i&&!("reversescale"in i)&&(i.reversescale=i.reversescl,delete i.reversescl),i.xaxis&&(i.xaxis=u(i.xaxis,"x")),i.yaxis&&(i.yaxis=u(i.yaxis,"y")),h(i,"gl3d")&&i.scene&&(i.scene=s.subplotsRegistry.gl3d.cleanId(i.scene)),!h(i,"pie-like")&&!h(i,"bar-like"))if(Array.isArray(i.textposition))for(n=0;n<i.textposition.length;n++)i.textposition[n]=v(i.textposition[n]);else i.textposition&&(i.textposition=v(i.textposition));var p=a.getModule(i);if(p&&p.colorbar){var x=p.colorbar.container,b=x?i[x]:i;b&&b.colorscale&&("YIGnBu"===b.colorscale&&(b.colorscale="YlGnBu"),"YIOrRd"===b.colorscale&&(b.colorscale="YlOrRd"))}if("surface"===i.type&&o.isPlainObject(i.contours)){var _=["x","y","z"];for(n=0;n<_.length;n++){var w=i.contours[_[n]];o.isPlainObject(w)&&(w.highlightColor&&(w.highlightcolor=w.highlightColor,delete w.highlightColor),w.highlightWidth&&(w.highlightwidth=w.highlightWidth,delete w.highlightWidth))}}if("candlestick"===i.type||"ohlc"===i.type){var T=!1!==(i.increasing||{}).showlegend,k=!1!==(i.decreasing||{}).showlegend,A=m(i.increasing),M=m(i.decreasing);if(!1!==A&&!1!==M){var S=g(A,M,T,k);S&&(i.name=S)}else!A&&!M||i.name||(i.name=A||M)}if(Array.isArray(i.transforms)){var E=i.transforms;for(n=0;n<E.length;n++){var L=E[n];if(o.isPlainObject(L))switch(L.type){case"filter":L.filtersrc&&(L.target=L.filtersrc,delete L.filtersrc),L.calendar&&(L.valuecalendar||(L.valuecalendar=L.calendar),delete L.calendar);break;case"groupby":if(L.styles=L.styles||L.style,L.styles&&!Array.isArray(L.styles)){var C=L.styles,P=Object.keys(C);L.styles=[];for(var I=0;I<P.length;I++)L.styles.push({target:P[I],value:C[P[I]]})}}}}y(i,"line")&&delete i.line,"marker"in i&&(y(i.marker,"line")&&delete i.marker.line,y(i,"marker")&&delete i.marker),c.clean(i),i.autobinx&&(delete i.autobinx,delete i.xbins),i.autobiny&&(delete i.autobiny,delete i.ybins),d(i),i.colorbar&&d(i.colorbar),i.marker&&i.marker.colorbar&&d(i.marker.colorbar),i.line&&i.line.colorbar&&d(i.line.colorbar),i.aaxis&&d(i.aaxis),i.baxis&&d(i.baxis)}},r.swapXYData=function(t){var e;if(o.swapAttrs(t,["?","?0","d?","?bins","nbins?","autobin?","?src","error_?"]),Array.isArray(t.z)&&Array.isArray(t.z[0])&&(t.transpose?delete t.transpose:t.transpose=!0),t.error_x&&t.error_y){var r=t.error_y,n="copy_ystyle"in r?r.copy_ystyle:!(r.color||r.thickness||r.width);o.swapAttrs(t,["error_?.copy_ystyle"]),n&&o.swapAttrs(t,["error_?.color","error_?.thickness","error_?.width"])}if("string"==typeof t.hoverinfo){var i=t.hoverinfo.split("+");for(e=0;e<i.length;e++)"x"===i[e]?i[e]="y":"y"===i[e]&&(i[e]="x");t.hoverinfo=i.join("+")}},r.coerceTraceIndices=function(t,e){if(n(e))return[e];if(!Array.isArray(e)||!e.length)return t.data.map((function(t,e){return e}));if(Array.isArray(e)){for(var r=[],i=0;i<e.length;i++)o.isIndex(e[i],t.data.length)?r.push(e[i]):o.warn("trace index (",e[i],") is not a number or is out of bounds");return r}return e},r.manageArrayContainers=function(t,e,r){var i=t.obj,a=t.parts,s=a.length,l=a[s-1],c=n(l);if(c&&null===e){var u=a.slice(0,s-1).join(".");o.nestedProperty(i,u).get().splice(l,1)}else c&&void 0===t.get()?(void 0===t.get()&&(r[t.astr]=null),t.set(e)):t.set(e)};var x=/(\.[^\[\]\.]+|\[[^\[\]\.]+\])$/;function b(t){var e=t.search(x);if(e>0)return t.substr(0,e)}r.hasParent=function(t,e){for(var r=b(e);r;){if(r in t)return!0;r=b(r)}return!1};var _=["x","y","z"];r.clearAxisTypes=function(t,e,r){for(var n=0;n<e.length;n++)for(var i=t._fullData[n],a=0;a<3;a++){var s=f(t,i,_[a]);if(s&&"log"!==s.type){var l=s._name,c=s._id.substr(1);if("scene"===c.substr(0,5)){if(void 0!==r[c])continue;l=c+"."+l}var u=l+".type";void 0===r[l]&&void 0===r[u]&&o.nestedProperty(t.layout,u).set(null)}}}},{"../components/color":366,"../lib":503,"../plots/cartesian/axis_ids":558,"../plots/plots":619,"../registry":638,"fast-isnumeric":190,"gl-mat4/fromQuat":200}],538:[function(t,e,r){"use strict";var n=t("./plot_api");r._doPlot=n._doPlot,r.newPlot=n.newPlot,r.restyle=n.restyle,r.relayout=n.relayout,r.redraw=n.redraw,r.update=n.update,r._guiRestyle=n._guiRestyle,r._guiRelayout=n._guiRelayout,r._guiUpdate=n._guiUpdate,r._storeDirectGUIEdit=n._storeDirectGUIEdit,r.react=n.react,r.extendTraces=n.extendTraces,r.prependTraces=n.prependTraces,r.addTraces=n.addTraces,r.deleteTraces=n.deleteTraces,r.moveTraces=n.moveTraces,r.purge=n.purge,r.addFrames=n.addFrames,r.deleteFrames=n.deleteFrames,r.animate=n.animate,r.setPlotConfig=n.setPlotConfig,r.toImage=t("./to_image"),r.validate=t("./validate"),r.downloadImage=t("../snapshot/download");var i=t("./template_api");r.makeTemplate=i.makeTemplate,r.validateTemplate=i.validateTemplate},{"../snapshot/download":640,"./plot_api":540,"./template_api":545,"./to_image":546,"./validate":547}],539:[function(t,e,r){"use strict";var n=t("../lib/is_plain_object"),i=t("../lib/noop"),a=t("../lib/loggers"),o=t("../lib/search").sorterAsc,s=t("../registry");r.containerArrayMatch=t("./container_array_match");var l=r.isAddVal=function(t){return"add"===t||n(t)},c=r.isRemoveVal=function(t){return null===t||"remove"===t};r.applyContainerArrayChanges=function(t,e,r,n,u){var f=e.astr,h=s.getComponentMethod(f,"supplyLayoutDefaults"),p=s.getComponentMethod(f,"draw"),d=s.getComponentMethod(f,"drawOne"),m=n.replot||n.recalc||h===i||p===i,g=t.layout,v=t._fullLayout;if(r[""]){Object.keys(r).length>1&&a.warn("Full array edits are incompatible with other edits",f);var y=r[""][""];if(c(y))e.set(null);else{if(!Array.isArray(y))return a.warn("Unrecognized full array edit value",f,y),!0;e.set(y)}return!m&&(h(g,v),p(t),!0)}var x,b,_,w,T,k,A,M,S=Object.keys(r).map(Number).sort(o),E=e.get(),L=E||[],C=u(v,f).get(),P=[],I=-1,O=L.length;for(x=0;x<S.length;x++)if(w=r[_=S[x]],T=Object.keys(w),k=w[""],A=l(k),_<0||_>L.length-(A?0:1))a.warn("index out of range",f,_);else if(void 0!==k)T.length>1&&a.warn("Insertion & removal are incompatible with edits to the same index.",f,_),c(k)?P.push(_):A?("add"===k&&(k={}),L.splice(_,0,k),C&&C.splice(_,0,{})):a.warn("Unrecognized full object edit value",f,_,k),-1===I&&(I=_);else for(b=0;b<T.length;b++)M=f+"["+_+"].",u(L[_],T[b],M).set(w[T[b]]);for(x=P.length-1;x>=0;x--)L.splice(P[x],1),C&&C.splice(P[x],1);if(L.length?E||e.set(L):e.set(null),m)return!1;if(h(g,v),d!==i){var z;if(-1===I)z=S;else{for(O=Math.max(L.length,O),z=[],x=0;x<S.length&&!((_=S[x])>=I);x++)z.push(_);for(x=I;x<O;x++)z.push(x)}for(x=0;x<z.length;x++)d(t,z[x])}else p(t);return!0}},{"../lib/is_plain_object":504,"../lib/loggers":507,"../lib/noop":512,"../lib/search":523,"../registry":638,"./container_array_match":535}],540:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("fast-isnumeric"),a=t("has-hover"),o=t("../lib"),s=o.nestedProperty,l=t("../lib/events"),c=t("../lib/queue"),u=t("../registry"),f=t("./plot_schema"),h=t("../plots/plots"),p=t("../plots/cartesian/axes"),d=t("../components/drawing"),m=t("../components/color"),g=t("../plots/cartesian/graph_interact").initInteractions,v=t("../constants/xmlns_namespaces"),y=t("../plots/cartesian/select").clearSelect,x=t("./plot_config").dfltConfig,b=t("./manage_arrays"),_=t("./helpers"),w=t("./subroutines"),T=t("./edit_types"),k=t("../plots/cartesian/constants").AX_NAME_PATTERN,A=0;function M(t){var e=t._fullLayout;e._redrawFromAutoMarginCount?e._redrawFromAutoMarginCount--:t.emit("plotly_afterplot")}function S(t,e){try{t._fullLayout._paper.style("background",e)}catch(t){o.error(t)}}function E(t,e){S(t,m.combine(e,"white"))}function L(t,e){if(!t._context){t._context=o.extendDeep({},x);var r=n.select("base");t._context._baseUrl=r.size()&&r.attr("href")?window.location.href.split("#")[0]:""}var i,s,l,c=t._context;if(e){for(s=Object.keys(e),i=0;i<s.length;i++)"editable"!==(l=s[i])&&"edits"!==l&&l in c&&("setBackground"===l&&"opaque"===e[l]?c[l]=E:c[l]=e[l]);e.plot3dPixelRatio&&!c.plotGlPixelRatio&&(c.plotGlPixelRatio=c.plot3dPixelRatio);var u=e.editable;if(void 0!==u)for(c.editable=u,s=Object.keys(c.edits),i=0;i<s.length;i++)c.edits[s[i]]=u;if(e.edits)for(s=Object.keys(e.edits),i=0;i<s.length;i++)(l=s[i])in c.edits&&(c.edits[l]=e.edits[l]);c._exportedPlot=e._exportedPlot}c.staticPlot&&(c.editable=!1,c.edits={},c.autosizable=!1,c.scrollZoom=!1,c.doubleClick=!1,c.showTips=!1,c.showLink=!1,c.displayModeBar=!1),"hover"!==c.displayModeBar||a||(c.displayModeBar=!0),"transparent"!==c.setBackground&&"function"==typeof c.setBackground||(c.setBackground=S),c._hasZeroHeight=c._hasZeroHeight||0===t.clientHeight,c._hasZeroWidth=c._hasZeroWidth||0===t.clientWidth;var f=c.scrollZoom,h=c._scrollZoom={};if(!0===f)h.cartesian=1,h.gl3d=1,h.geo=1,h.mapbox=1;else if("string"==typeof f){var p=f.split("+");for(i=0;i<p.length;i++)h[p[i]]=1}else!1!==f&&(h.gl3d=1,h.geo=1,h.mapbox=1)}function C(t,e){var r,n,i=e+1,a=[];for(r=0;r<t.length;r++)(n=t[r])<0?a.push(i+n):a.push(n);return a}function P(t,e,r){var n,i;for(n=0;n<e.length;n++){if((i=e[n])!==parseInt(i,10))throw new Error("all values in "+r+" must be integers");if(i>=t.data.length||i<-t.data.length)throw new Error(r+" must be valid indices for gd.data.");if(e.indexOf(i,n+1)>-1||i>=0&&e.indexOf(-t.data.length+i)>-1||i<0&&e.indexOf(t.data.length+i)>-1)throw new Error("each index in "+r+" must be unique.")}}function I(t,e,r){if(!Array.isArray(t.data))throw new Error("gd.data must be an array.");if(void 0===e)throw new Error("currentIndices is a required argument.");if(Array.isArray(e)||(e=[e]),P(t,e,"currentIndices"),void 0===r||Array.isArray(r)||(r=[r]),void 0!==r&&P(t,r,"newIndices"),void 0!==r&&e.length!==r.length)throw new Error("current and new indices must be of equal length.")}function O(t,e,r,n,a){!function(t,e,r,n){var i=o.isPlainObject(n);if(!Array.isArray(t.data))throw new Error("gd.data must be an array");if(!o.isPlainObject(e))throw new Error("update must be a key:value object");if(void 0===r)throw new Error("indices must be an integer or array of integers");for(var a in P(t,r,"indices"),e){if(!Array.isArray(e[a])||e[a].length!==r.length)throw new Error("attribute "+a+" must be an array of length equal to indices array length");if(i&&(!(a in n)||!Array.isArray(n[a])||n[a].length!==e[a].length))throw new Error("when maxPoints is set as a key:value object it must contain a 1:1 corrispondence with the keys and number of traces in the update object")}}(t,e,r,n);for(var l=function(t,e,r,n){var a,l,c,u,f,h=o.isPlainObject(n),p=[];for(var d in Array.isArray(r)||(r=[r]),r=C(r,t.data.length-1),e)for(var m=0;m<r.length;m++){if(a=t.data[r[m]],l=(c=s(a,d)).get(),u=e[d][m],!o.isArrayOrTypedArray(u))throw new Error("attribute: "+d+" index: "+m+" must be an array");if(!o.isArrayOrTypedArray(l))throw new Error("cannot extend missing or non-array attribute: "+d);if(l.constructor!==u.constructor)throw new Error("cannot extend array with an array of a different type: "+d);f=h?n[d][m]:n,i(f)||(f=-1),p.push({prop:c,target:l,insert:u,maxp:Math.floor(f)})}return p}(t,e,r,n),c={},u={},f=0;f<l.length;f++){var h=l[f].prop,p=l[f].maxp,d=a(l[f].target,l[f].insert,p);h.set(d[0]),Array.isArray(c[h.astr])||(c[h.astr]=[]),c[h.astr].push(d[1]),Array.isArray(u[h.astr])||(u[h.astr]=[]),u[h.astr].push(l[f].target.length)}return{update:c,maxPoints:u}}function z(t,e){var r=new t.constructor(t.length+e.length);return r.set(t),r.set(e,t.length),r}function D(t,e,n,i){t=o.getGraphDiv(t),_.clearPromiseQueue(t);var a={};if("string"==typeof e)a[e]=n;else{if(!o.isPlainObject(e))return o.warn("Restyle fail.",e,n,i),Promise.reject();a=o.extendFlat({},e),void 0===i&&(i=n)}Object.keys(a).length&&(t.changed=!0);var s=_.coerceTraceIndices(t,i),l=N(t,a,s),u=l.flags;u.calc&&(t.calcdata=void 0),u.clearAxisTypes&&_.clearAxisTypes(t,s,{});var f=[];u.fullReplot?f.push(r._doPlot):(f.push(h.previousPromises),h.supplyDefaults(t),u.markerSize&&(h.doCalcdata(t),H(f)),u.style&&f.push(w.doTraceStyle),u.colorbars&&f.push(w.doColorBars),f.push(M)),f.push(h.rehover,h.redrag),c.add(t,D,[t,l.undoit,l.traces],D,[t,l.redoit,l.traces]);var p=o.syncOrAsync(f,t);return p&&p.then||(p=Promise.resolve()),p.then((function(){return t.emit("plotly_restyle",l.eventData),t}))}function R(t){return void 0===t?null:t}function F(t,e){return e?function(e,r,n){var i=s(e,r),a=i.set;return i.set=function(e){B((n||"")+r,i.get(),e,t),a(e)},i}:s}function B(t,e,r,n){if(Array.isArray(e)||Array.isArray(r))for(var i=Array.isArray(e)?e:[],a=Array.isArray(r)?r:[],s=Math.max(i.length,a.length),l=0;l<s;l++)B(t+"["+l+"]",i[l],a[l],n);else if(o.isPlainObject(e)||o.isPlainObject(r)){var c=o.isPlainObject(e)?e:{},u=o.isPlainObject(r)?r:{},f=o.extendFlat({},c,u);for(var h in f)B(t+"."+h,c[h],u[h],n)}else void 0===n[t]&&(n[t]=R(e))}function N(t,e,r){var n,i=t._fullLayout,a=t._fullData,l=t.data,c=i._guiEditing,d=F(i._preGUI,c),m=o.extendDeepAll({},e);j(e);var g,v=T.traceFlags(),y={},x={};function b(){return r.map((function(){}))}function w(t){var e=p.id2name(t);-1===g.indexOf(e)&&g.push(e)}function k(t){return"LAYOUT"+t+".autorange"}function A(t){return"LAYOUT"+t+".range"}function M(t){for(var e=t;e<a.length;e++)if(a[e]._input===l[t])return a[e]}function S(n,a,o){if(Array.isArray(n))n.forEach((function(t){S(t,a,o)}));else if(!(n in e)&&!_.hasParent(e,n)){var s;if("LAYOUT"===n.substr(0,6))s=d(t.layout,n.replace("LAYOUT",""));else{var u=r[o];s=F(i._tracePreGUI[M(u)._fullInput.uid],c)(l[u],n)}n in x||(x[n]=b()),void 0===x[n][o]&&(x[n][o]=R(s.get())),void 0!==a&&s.set(a)}}function E(t){return function(e){return a[e][t]}}function L(t){return function(e,n){return!1===e?a[r[n]][t]:null}}for(var C in e){if(_.hasParent(e,C))throw new Error("cannot set "+C+" and a parent attribute simultaneously");var P,I,O,z,D,B,N=e[C];if("autobinx"!==C&&"autobiny"!==C||(C=C.charAt(C.length-1)+"bins",N=Array.isArray(N)?N.map(L(C)):!1===N?r.map(E(C)):null),y[C]=N,"LAYOUT"!==C.substr(0,6)){for(x[C]=b(),n=0;n<r.length;n++){if(P=l[r[n]],I=M(r[n]),z=(O=F(i._tracePreGUI[I._fullInput.uid],c)(P,C)).get(),void 0!==(D=Array.isArray(N)?N[n%N.length]:N)){var U=O.parts[O.parts.length-1],V=C.substr(0,C.length-U.length-1),H=V?V+".":"",q=V?s(I,V).get():I;if((B=f.getTraceValObject(I,O.parts))&&B.impliedEdits&&null!==D)for(var G in B.impliedEdits)S(o.relativeAttr(C,G),B.impliedEdits[G],n);else if("thicknessmode"!==U&&"lenmode"!==U||z===D||"fraction"!==D&&"pixels"!==D||!q){if("type"===C&&("pie"===D!=("pie"===z)||"funnelarea"===D!=("funnelarea"===z))){var Y="x",W="y";"bar"!==D&&"bar"!==z||"h"!==P.orientation||(Y="y",W="x"),o.swapAttrs(P,["?","?src"],"labels",Y),o.swapAttrs(P,["d?","?0"],"label",Y),o.swapAttrs(P,["?","?src"],"values",W),"pie"===z||"funnelarea"===z?(s(P,"marker.color").set(s(P,"marker.colors").get()),i._pielayer.selectAll("g.trace").remove()):u.traceIs(P,"cartesian")&&s(P,"marker.colors").set(s(P,"marker.color").get())}}else{var X=i._size,Z=q.orient,J="top"===Z||"bottom"===Z;if("thicknessmode"===U){var K=J?X.h:X.w;S(H+"thickness",q.thickness*("fraction"===D?1/K:K),n)}else{var Q=J?X.w:X.h;S(H+"len",q.len*("fraction"===D?1/Q:Q),n)}}x[C][n]=R(z);if(-1!==["swapxy","swapxyaxes","orientation","orientationaxes"].indexOf(C)){if("orientation"===C){O.set(D);var $=P.x&&!P.y?"h":"v";if((O.get()||$)===I.orientation)continue}else"orientationaxes"===C&&(P.orientation={v:"h",h:"v"}[I.orientation]);_.swapXYData(P),v.calc=v.clearAxisTypes=!0}else-1!==h.dataArrayContainers.indexOf(O.parts[0])?(_.manageArrayContainers(O,D,x),v.calc=!0):(B?B.arrayOk&&!u.traceIs(I,"regl")&&(o.isArrayOrTypedArray(D)||o.isArrayOrTypedArray(z))?v.calc=!0:T.update(v,B):v.calc=!0,O.set(D))}}if(-1!==["swapxyaxes","orientationaxes"].indexOf(C)&&p.swap(t,r),"orientationaxes"===C){var tt=s(t.layout,"hovermode"),et=tt.get();"x"===et?tt.set("y"):"y"===et?tt.set("x"):"x unified"===et?tt.set("y unified"):"y unified"===et&&tt.set("x unified")}if(-1!==["orientation","type"].indexOf(C)){for(g=[],n=0;n<r.length;n++){var rt=l[r[n]];u.traceIs(rt,"cartesian")&&(w(rt.xaxis||"x"),w(rt.yaxis||"y"))}S(g.map(k),!0,0),S(g.map(A),[0,1],0)}}else O=d(t.layout,C.replace("LAYOUT","")),x[C]=[R(O.get())],O.set(Array.isArray(N)?N[0]:N),v.calc=!0}return(v.calc||v.plot)&&(v.fullReplot=!0),{flags:v,undoit:x,redoit:y,traces:r,eventData:o.extendDeepNoArrays([],[m,r])}}function j(t){var e,r,n,i=o.counterRegex("axis",".title",!1,!1),a=/colorbar\.title$/,s=Object.keys(t);for(e=0;e<s.length;e++)r=s[e],n=t[r],"title"!==r&&!i.test(r)&&!a.test(r)||"string"!=typeof n&&"number"!=typeof n?r.indexOf("titlefont")>-1&&-1===r.indexOf("grouptitlefont")?l(r,r.replace("titlefont","title.font")):r.indexOf("titleposition")>-1?l(r,r.replace("titleposition","title.position")):r.indexOf("titleside")>-1?l(r,r.replace("titleside","title.side")):r.indexOf("titleoffset")>-1&&l(r,r.replace("titleoffset","title.offset")):l(r,r.replace("title","title.text"));function l(e,r){t[r]=t[e],delete t[e]}}function U(t,e,r){t=o.getGraphDiv(t),_.clearPromiseQueue(t);var n={};if("string"==typeof e)n[e]=r;else{if(!o.isPlainObject(e))return o.warn("Relayout fail.",e,r),Promise.reject();n=o.extendFlat({},e)}Object.keys(n).length&&(t.changed=!0);var i=W(t,n),a=i.flags;a.calc&&(t.calcdata=void 0);var s=[h.previousPromises];a.layoutReplot?s.push(w.layoutReplot):Object.keys(n).length&&(V(t,a,i)||h.supplyDefaults(t),a.legend&&s.push(w.doLegend),a.layoutstyle&&s.push(w.layoutStyles),a.axrange&&H(s,i.rangesAltered),a.ticks&&s.push(w.doTicksRelayout),a.modebar&&s.push(w.doModeBar),a.camera&&s.push(w.doCamera),a.colorbars&&s.push(w.doColorBars),s.push(M)),s.push(h.rehover,h.redrag),c.add(t,U,[t,i.undoit],U,[t,i.redoit]);var l=o.syncOrAsync(s,t);return l&&l.then||(l=Promise.resolve(t)),l.then((function(){return t.emit("plotly_relayout",i.eventData),t}))}function V(t,e,r){var n=t._fullLayout;if(!e.axrange)return!1;for(var i in e)if("axrange"!==i&&e[i])return!1;for(var a in r.rangesAltered){var o=p.id2name(a),s=t.layout[o],l=n[o];if(l.autorange=s.autorange,s.range&&(l.range=s.range.slice()),l.cleanRange(),l._matchGroup)for(var c in l._matchGroup)if(c!==a){var u=n[p.id2name(c)];u.autorange=l.autorange,u.range=l.range.slice(),u._input.range=l.range.slice()}}return!0}function H(t,e){var r=e?function(t){var r=[],n=!0;for(var i in e){var a=p.getFromId(t,i);if(r.push(i),-1!==(a.ticklabelposition||"").indexOf("inside")&&a._anchorAxis&&r.push(a._anchorAxis._id),a._matchGroup)for(var o in a._matchGroup)e[o]||r.push(o);a.automargin&&(n=!1)}return p.draw(t,r,{skipTitle:n})}:function(t){return p.draw(t,"redraw")};t.push(y,w.doAutoRangeAndConstraints,r,w.drawData,w.finalDraw)}var q=/^[xyz]axis[0-9]*\.range(\[[0|1]\])?$/,G=/^[xyz]axis[0-9]*\.autorange$/,Y=/^[xyz]axis[0-9]*\.domain(\[[0|1]\])?$/;function W(t,e){var r,n,i,a=t.layout,l=t._fullLayout,c=l._guiEditing,h=F(l._preGUI,c),d=Object.keys(e),m=p.list(t),g=o.extendDeepAll({},e),v={};for(j(e),d=Object.keys(e),n=0;n<d.length;n++)if(0===d[n].indexOf("allaxes")){for(i=0;i<m.length;i++){var y=m[i]._id.substr(1),x=-1!==y.indexOf("scene")?y+".":"",w=d[n].replace("allaxes",x+m[i]._name);e[w]||(e[w]=e[d[n]])}delete e[d[n]]}var A=T.layoutFlags(),M={},S={};function E(t,r){if(Array.isArray(t))t.forEach((function(t){E(t,r)}));else if(!(t in e)&&!_.hasParent(e,t)){var n=h(a,t);t in S||(S[t]=R(n.get())),void 0!==r&&n.set(r)}}var L,C={};function P(t){var e=p.name2id(t.split(".")[0]);return C[e]=1,e}for(var I in e){if(_.hasParent(e,I))throw new Error("cannot set "+I+" and a parent attribute simultaneously");for(var O=h(a,I),z=e[I],D=O.parts.length-1;D>0&&"string"!=typeof O.parts[D];)D--;var B=O.parts[D],N=O.parts[D-1]+"."+B,U=O.parts.slice(0,D).join("."),V=s(t.layout,U).get(),H=s(l,U).get(),W=O.get();if(void 0!==z){M[I]=z,S[I]="reverse"===B?z:R(W);var Z=f.getLayoutValObject(l,O.parts);if(Z&&Z.impliedEdits&&null!==z)for(var J in Z.impliedEdits)E(o.relativeAttr(I,J),Z.impliedEdits[J]);if(-1!==["width","height"].indexOf(I))if(z){E("autosize",null);var K="height"===I?"width":"height";E(K,l[K])}else l[I]=t._initialAutoSize[I];else if("autosize"===I)E("width",z?null:l.width),E("height",z?null:l.height);else if(N.match(q))P(N),s(l,U+"._inputRange").set(null);else if(N.match(G)){P(N),s(l,U+"._inputRange").set(null);var Q=s(l,U).get();Q._inputDomain&&(Q._input.domain=Q._inputDomain.slice())}else N.match(Y)&&s(l,U+"._inputDomain").set(null);if("type"===B){L=V;var $="linear"===H.type&&"log"===z,tt="log"===H.type&&"linear"===z;if($||tt){if(L&&L.range)if(H.autorange)$&&(L.range=L.range[1]>L.range[0]?[1,2]:[2,1]);else{var et=L.range[0],rt=L.range[1];$?(et<=0&&rt<=0&&E(U+".autorange",!0),et<=0?et=rt/1e6:rt<=0&&(rt=et/1e6),E(U+".range[0]",Math.log(et)/Math.LN10),E(U+".range[1]",Math.log(rt)/Math.LN10)):(E(U+".range[0]",Math.pow(10,et)),E(U+".range[1]",Math.pow(10,rt)))}else E(U+".autorange",!0);Array.isArray(l._subplots.polar)&&l._subplots.polar.length&&l[O.parts[0]]&&"radialaxis"===O.parts[1]&&delete l[O.parts[0]]._subplot.viewInitial["radialaxis.range"],u.getComponentMethod("annotations","convertCoords")(t,H,z,E),u.getComponentMethod("images","convertCoords")(t,H,z,E)}else E(U+".autorange",!0),E(U+".range",null);s(l,U+"._inputRange").set(null)}else if(B.match(k)){var nt=s(l,I).get(),it=(z||{}).type;it&&"-"!==it||(it="linear"),u.getComponentMethod("annotations","convertCoords")(t,nt,it,E),u.getComponentMethod("images","convertCoords")(t,nt,it,E)}var at=b.containerArrayMatch(I);if(at){r=at.array,n=at.index;var ot=at.property,st=Z||{editType:"calc"};""!==n&&""===ot&&(b.isAddVal(z)?S[I]=null:b.isRemoveVal(z)?S[I]=(s(a,r).get()||[])[n]:o.warn("unrecognized full object value",e)),T.update(A,st),v[r]||(v[r]={});var lt=v[r][n];lt||(lt=v[r][n]={}),lt[ot]=z,delete e[I]}else"reverse"===B?(V.range?V.range.reverse():(E(U+".autorange",!0),V.range=[1,0]),H.autorange?A.calc=!0:A.plot=!0):("dragmode"===I&&(!1===z&&!1!==W||!1!==z&&!1===W)||l._has("scatter-like")&&l._has("regl")&&"dragmode"===I&&("lasso"===z||"select"===z)&&"lasso"!==W&&"select"!==W||l._has("gl2d")?A.plot=!0:Z?T.update(A,Z):A.calc=!0,O.set(z))}}for(r in v){b.applyContainerArrayChanges(t,h(a,r),v[r],A,h)||(A.plot=!0)}for(var ct in C){var ut=(L=p.getFromId(t,ct))&&L._constraintGroup;if(ut)for(var ft in A.calc=!0,ut)C[ft]||(p.getFromId(t,ft)._constraintShrinkable=!0)}return(X(t)||e.height||e.width)&&(A.plot=!0),(A.plot||A.calc)&&(A.layoutReplot=!0),{flags:A,rangesAltered:C,undoit:S,redoit:M,eventData:g}}function X(t){var e=t._fullLayout,r=e.width,n=e.height;return t.layout.autosize&&h.plotAutoSize(t,t.layout,e),e.width!==r||e.height!==n}function Z(t,e,n,i){t=o.getGraphDiv(t),_.clearPromiseQueue(t),o.isPlainObject(e)||(e={}),o.isPlainObject(n)||(n={}),Object.keys(e).length&&(t.changed=!0),Object.keys(n).length&&(t.changed=!0);var a=_.coerceTraceIndices(t,i),s=N(t,o.extendFlat({},e),a),l=s.flags,u=W(t,o.extendFlat({},n)),f=u.flags;(l.calc||f.calc)&&(t.calcdata=void 0),l.clearAxisTypes&&_.clearAxisTypes(t,a,n);var p=[];f.layoutReplot?p.push(w.layoutReplot):l.fullReplot?p.push(r._doPlot):(p.push(h.previousPromises),V(t,f,u)||h.supplyDefaults(t),l.style&&p.push(w.doTraceStyle),(l.colorbars||f.colorbars)&&p.push(w.doColorBars),f.legend&&p.push(w.doLegend),f.layoutstyle&&p.push(w.layoutStyles),f.axrange&&H(p,u.rangesAltered),f.ticks&&p.push(w.doTicksRelayout),f.modebar&&p.push(w.doModeBar),f.camera&&p.push(w.doCamera),p.push(M)),p.push(h.rehover,h.redrag),c.add(t,Z,[t,s.undoit,u.undoit,s.traces],Z,[t,s.redoit,u.redoit,s.traces]);var d=o.syncOrAsync(p,t);return d&&d.then||(d=Promise.resolve(t)),d.then((function(){return t.emit("plotly_update",{data:s.eventData,layout:u.eventData}),t}))}function J(t){return function(e){e._fullLayout._guiEditing=!0;var r=t.apply(null,arguments);return e._fullLayout._guiEditing=!1,r}}var K=[{pattern:/^hiddenlabels/,attr:"legend.uirevision"},{pattern:/^((x|y)axis\d*)\.((auto)?range|title\.text)/},{pattern:/axis\d*\.showspikes$/,attr:"modebar.uirevision"},{pattern:/(hover|drag)mode$/,attr:"modebar.uirevision"},{pattern:/^(scene\d*)\.camera/},{pattern:/^(geo\d*)\.(projection|center|fitbounds)/},{pattern:/^(ternary\d*\.[abc]axis)\.(min|title\.text)$/},{pattern:/^(polar\d*\.radialaxis)\.((auto)?range|angle|title\.text)/},{pattern:/^(polar\d*\.angularaxis)\.rotation/},{pattern:/^(mapbox\d*)\.(center|zoom|bearing|pitch)/},{pattern:/^legend\.(x|y)$/,attr:"editrevision"},{pattern:/^(shapes|annotations)/,attr:"editrevision"},{pattern:/^title\.text$/,attr:"editrevision"}],Q=[{pattern:/^selectedpoints$/,attr:"selectionrevision"},{pattern:/(^|value\.)visible$/,attr:"legend.uirevision"},{pattern:/^dimensions\[\d+\]\.constraintrange/},{pattern:/^node\.(x|y|groups)/},{pattern:/^level$/},{pattern:/(^|value\.)name$/},{pattern:/colorbar\.title\.text$/},{pattern:/colorbar\.(x|y)$/,attr:"editrevision"}];function $(t,e){for(var r=0;r<e.length;r++){var n=e[r],i=t.match(n.pattern);if(i){var a=i[1]||"";return{head:a,tail:t.substr(a.length+1),attr:n.attr}}}}function tt(t,e){var r=s(e,t).get();if(void 0!==r)return r;var n=t.split(".");for(n.pop();n.length>1;)if(n.pop(),void 0!==(r=s(e,n.join(".")+".uirevision").get()))return r;return e.uirevision}function et(t,e){for(var r=0;r<e.length;r++)if(e[r]._fullInput.uid===t)return r;return-1}function rt(t,e,r){for(var n=0;n<e.length;n++)if(e[n].uid===t)return n;return!e[r]||e[r].uid?-1:r}function nt(t,e){var r=o.isPlainObject(t),n=Array.isArray(t);return r||n?(r&&o.isPlainObject(e)||n&&Array.isArray(e))&&JSON.stringify(t)===JSON.stringify(e):t===e}function it(t,e,r,n){var i,a,l,c=n.getValObject,u=n.flags,f=n.immutable,h=n.inArray,p=n.arrayIndex;function d(){var t=i.editType;h&&-1!==t.indexOf("arraydraw")?o.pushUnique(u.arrays[h],p):(T.update(u,i),"none"!==t&&u.nChanges++,n.transition&&i.anim&&u.nChangesAnim++,(q.test(l)||G.test(l))&&(u.rangesAltered[r[0]]=1),Y.test(l)&&s(e,"_inputDomain").set(null),"datarevision"===a&&(u.newDataRevision=1))}function m(t){return"data_array"===t.valType||t.arrayOk}for(a in t){if(u.calc&&!n.transition)return;var g=t[a],v=e[a],y=r.concat(a);if(l=y.join("."),"_"!==a.charAt(0)&&"function"!=typeof g&&g!==v){if(("tick0"===a||"dtick"===a)&&"geo"!==r[0]){var x=e.tickmode;if("auto"===x||"array"===x||!x)continue}if(("range"!==a||!e.autorange)&&("zmin"!==a&&"zmax"!==a||"contourcarpet"!==e.type)&&(i=c(y))&&(!i._compareAsJSON||JSON.stringify(g)!==JSON.stringify(v))){var b,_=i.valType,w=m(i),k=Array.isArray(g),A=Array.isArray(v);if(k&&A){var M="_input_"+a,S=t[M],E=e[M];if(Array.isArray(S)&&S===E)continue}if(void 0===v)w&&k?u.calc=!0:d();else if(i._isLinkedToArray){var L=[],C=!1;h||(u.arrays[a]=L);var P=Math.min(g.length,v.length),I=Math.max(g.length,v.length);if(P!==I){if("arraydraw"!==i.editType){d();continue}C=!0}for(b=0;b<P;b++)it(g[b],v[b],y.concat(b),o.extendFlat({inArray:a,arrayIndex:b},n));if(C)for(b=P;b<I;b++)L.push(b)}else!_&&o.isPlainObject(g)?it(g,v,y,n):w?k&&A?(f&&(u.calc=!0),(f||n.newDataRevision)&&d()):k!==A?u.calc=!0:d():k&&A&&g.length===v.length&&String(g)===String(v)||d()}}}for(a in e)if(!(a in t)&&"_"!==a.charAt(0)&&"function"!=typeof e[a]){if(m(i=c(r.concat(a)))&&Array.isArray(e[a]))return void(u.calc=!0);d()}}function at(t){var e=t._fullLayout,r=t.getBoundingClientRect();if(!o.equalDomRects(r,e._lastBBox)){var n=e._invTransform=o.inverseTransformMatrix(o.getFullTransformMatrix(t));e._invScaleX=Math.sqrt(n[0][0]*n[0][0]+n[0][1]*n[0][1]+n[0][2]*n[0][2]),e._invScaleY=Math.sqrt(n[1][0]*n[1][0]+n[1][1]*n[1][1]+n[1][2]*n[1][2]),e._lastBBox=r}}r.animate=function(t,e,r){if(t=o.getGraphDiv(t),!o.isPlotDiv(t))throw new Error("This element is not a Plotly plot: "+t+". It's likely that you've failed to create a plot before animating it. For more details, see https://plotly.com/javascript/animations/");var n=t._transitionData;n._frameQueue||(n._frameQueue=[]);var i=(r=h.supplyAnimationDefaults(r)).transition,a=r.frame;function s(t){return Array.isArray(i)?t>=i.length?i[0]:i[t]:i}function l(t){return Array.isArray(a)?t>=a.length?a[0]:a[t]:a}function c(t,e){var r=0;return function(){if(t&&++r===e)return t()}}return void 0===n._frameWaitingCnt&&(n._frameWaitingCnt=0),new Promise((function(a,u){function f(){n._currentFrame&&n._currentFrame.onComplete&&n._currentFrame.onComplete();var e=n._currentFrame=n._frameQueue.shift();if(e){var r=e.name?e.name.toString():null;t._fullLayout._currentFrame=r,n._lastFrameAt=Date.now(),n._timeToNext=e.frameOpts.duration,h.transition(t,e.frame.data,e.frame.layout,_.coerceTraceIndices(t,e.frame.traces),e.frameOpts,e.transitionOpts).then((function(){e.onComplete&&e.onComplete()})),t.emit("plotly_animatingframe",{name:r,frame:e.frame,animation:{frame:e.frameOpts,transition:e.transitionOpts}})}else t.emit("plotly_animated"),window.cancelAnimationFrame(n._animationRaf),n._animationRaf=null}function p(){t.emit("plotly_animating"),n._lastFrameAt=-1/0,n._timeToNext=0,n._runningTransitions=0,n._currentFrame=null;var e=function(){n._animationRaf=window.requestAnimationFrame(e),Date.now()-n._lastFrameAt>n._timeToNext&&f()};e()}var d,m,g=0;function v(t){return Array.isArray(i)?g>=i.length?t.transitionOpts=i[g]:t.transitionOpts=i[0]:t.transitionOpts=i,g++,t}var y=[],x=null==e,b=Array.isArray(e);if(!x&&!b&&o.isPlainObject(e))y.push({type:"object",data:v(o.extendFlat({},e))});else if(x||-1!==["string","number"].indexOf(typeof e))for(d=0;d<n._frames.length;d++)(m=n._frames[d])&&(x||String(m.group)===String(e))&&y.push({type:"byname",name:String(m.name),data:v({name:m.name})});else if(b)for(d=0;d<e.length;d++){var w=e[d];-1!==["number","string"].indexOf(typeof w)?(w=String(w),y.push({type:"byname",name:w,data:v({name:w})})):o.isPlainObject(w)&&y.push({type:"object",data:v(o.extendFlat({},w))})}for(d=0;d<y.length;d++)if("byname"===(m=y[d]).type&&!n._frameHash[m.data.name])return o.warn('animate failure: frame not found: "'+m.data.name+'"'),void u();-1!==["next","immediate"].indexOf(r.mode)&&function(){if(0!==n._frameQueue.length){for(;n._frameQueue.length;){var e=n._frameQueue.pop();e.onInterrupt&&e.onInterrupt()}t.emit("plotly_animationinterrupted",[])}}(),"reverse"===r.direction&&y.reverse();var T=t._fullLayout._currentFrame;if(T&&r.fromcurrent){var k=-1;for(d=0;d<y.length;d++)if("byname"===(m=y[d]).type&&m.name===T){k=d;break}if(k>0&&k<y.length-1){var A=[];for(d=0;d<y.length;d++)m=y[d],("byname"!==y[d].type||d>k)&&A.push(m);y=A}}y.length>0?function(e){if(0!==e.length){for(var i=0;i<e.length;i++){var o;o="byname"===e[i].type?h.computeFrame(t,e[i].name):e[i].data;var f=l(i),d=s(i);d.duration=Math.min(d.duration,f.duration);var m={frame:o,name:e[i].name,frameOpts:f,transitionOpts:d};i===e.length-1&&(m.onComplete=c(a,2),m.onInterrupt=u),n._frameQueue.push(m)}"immediate"===r.mode&&(n._lastFrameAt=-1/0),n._animationRaf||p()}}(y):(t.emit("plotly_animated"),a())}))},r.addFrames=function(t,e,r){if(t=o.getGraphDiv(t),null==e)return Promise.resolve();if(!o.isPlotDiv(t))throw new Error("This element is not a Plotly plot: "+t+". It's likely that you've failed to create a plot before adding frames. For more details, see https://plotly.com/javascript/animations/");var n,i,a,s,l=t._transitionData._frames,u=t._transitionData._frameHash;if(!Array.isArray(e))throw new Error("addFrames failure: frameList must be an Array of frame definitions"+e);var f=l.length+2*e.length,p=[],d={};for(n=e.length-1;n>=0;n--)if(o.isPlainObject(e[n])){var m=e[n].name,g=(u[m]||d[m]||{}).name,v=e[n].name,y=u[g]||d[g];g&&v&&"number"==typeof v&&y&&A<5&&(A++,o.warn('addFrames: overwriting frame "'+(u[g]||d[g]).name+'" with a frame whose name of type "number" also equates to "'+g+'". This is valid but may potentially lead to unexpected behavior since all plotly.js frame names are stored internally as strings.'),5===A&&o.warn("addFrames: This API call has yielded too many of these warnings. For the rest of this call, further warnings about numeric frame names will be suppressed.")),d[m]={name:m},p.push({frame:h.supplyFrameDefaults(e[n]),index:r&&void 0!==r[n]&&null!==r[n]?r[n]:f+n})}p.sort((function(t,e){return t.index>e.index?-1:t.index<e.index?1:0}));var x=[],b=[],_=l.length;for(n=p.length-1;n>=0;n--){if("number"==typeof(i=p[n].frame).name&&o.warn("Warning: addFrames accepts frames with numeric names, but the numbers areimplicitly cast to strings"),!i.name)for(;u[i.name="frame "+t._transitionData._counter++];);if(u[i.name]){for(a=0;a<l.length&&(l[a]||{}).name!==i.name;a++);x.push({type:"replace",index:a,value:i}),b.unshift({type:"replace",index:a,value:l[a]})}else s=Math.max(0,Math.min(p[n].index,_)),x.push({type:"insert",index:s,value:i}),b.unshift({type:"delete",index:s}),_++}var w=h.modifyFrames,T=h.modifyFrames,k=[t,b],M=[t,x];return c&&c.add(t,w,k,T,M),h.modifyFrames(t,x)},r.deleteFrames=function(t,e){if(t=o.getGraphDiv(t),!o.isPlotDiv(t))throw new Error("This element is not a Plotly plot: "+t);var r,n,i=t._transitionData._frames,a=[],s=[];if(!e)for(e=[],r=0;r<i.length;r++)e.push(r);for((e=e.slice()).sort(),r=e.length-1;r>=0;r--)n=e[r],a.push({type:"delete",index:n}),s.unshift({type:"insert",index:n,value:i[n]});var l=h.modifyFrames,u=h.modifyFrames,f=[t,s],p=[t,a];return c&&c.add(t,l,f,u,p),h.modifyFrames(t,a)},r.addTraces=function t(e,n,i){e=o.getGraphDiv(e);var a,s,l=[],u=r.deleteTraces,f=t,h=[e,l],p=[e,n];for(function(t,e,r){var n,i;if(!Array.isArray(t.data))throw new Error("gd.data must be an array.");if(void 0===e)throw new Error("traces must be defined.");for(Array.isArray(e)||(e=[e]),n=0;n<e.length;n++)if("object"!=typeof(i=e[n])||Array.isArray(i)||null===i)throw new Error("all values in traces array must be non-array objects");if(void 0===r||Array.isArray(r)||(r=[r]),void 0!==r&&r.length!==e.length)throw new Error("if indices is specified, traces.length must equal indices.length")}(e,n,i),Array.isArray(n)||(n=[n]),n=n.map((function(t){return o.extendFlat({},t)})),_.cleanData(n),a=0;a<n.length;a++)e.data.push(n[a]);for(a=0;a<n.length;a++)l.push(-n.length+a);if(void 0===i)return s=r.redraw(e),c.add(e,u,h,f,p),s;Array.isArray(i)||(i=[i]);try{I(e,l,i)}catch(t){throw e.data.splice(e.data.length-n.length,n.length),t}return c.startSequence(e),c.add(e,u,h,f,p),s=r.moveTraces(e,l,i),c.stopSequence(e),s},r.deleteTraces=function t(e,n){e=o.getGraphDiv(e);var i,a,s=[],l=r.addTraces,u=t,f=[e,s,n],h=[e,n];if(void 0===n)throw new Error("indices must be an integer or array of integers.");for(Array.isArray(n)||(n=[n]),P(e,n,"indices"),(n=C(n,e.data.length-1)).sort(o.sorterDes),i=0;i<n.length;i+=1)a=e.data.splice(n[i],1)[0],s.push(a);var p=r.redraw(e);return c.add(e,l,f,u,h),p},r.extendTraces=function t(e,n,i,a){function s(t,e,r){var n,i;if(o.isTypedArray(t))if(r<0){var a=new t.constructor(0),s=z(t,e);r<0?(n=s,i=a):(n=a,i=s)}else if(n=new t.constructor(r),i=new t.constructor(t.length+e.length-r),r===e.length)n.set(e),i.set(t);else if(r<e.length){var l=e.length-r;n.set(e.subarray(l)),i.set(t),i.set(e.subarray(0,l),t.length)}else{var c=r-e.length,u=t.length-c;n.set(t.subarray(u)),n.set(e,c),i.set(t.subarray(0,u))}else n=t.concat(e),i=r>=0&&r<n.length?n.splice(0,n.length-r):[];return[n,i]}var l=O(e=o.getGraphDiv(e),n,i,a,s),u=r.redraw(e),f=[e,l.update,i,l.maxPoints];return c.add(e,r.prependTraces,f,t,arguments),u},r.moveTraces=function t(e,n,i){var a,s=[],l=[],u=t,f=t,h=[e=o.getGraphDiv(e),i,n],p=[e,n,i];if(I(e,n,i),n=Array.isArray(n)?n:[n],void 0===i)for(i=[],a=0;a<n.length;a++)i.push(-n.length+a);for(i=Array.isArray(i)?i:[i],n=C(n,e.data.length-1),i=C(i,e.data.length-1),a=0;a<e.data.length;a++)-1===n.indexOf(a)&&s.push(e.data[a]);for(a=0;a<n.length;a++)l.push({newIndex:i[a],trace:e.data[n[a]]});for(l.sort((function(t,e){return t.newIndex-e.newIndex})),a=0;a<l.length;a+=1)s.splice(l[a].newIndex,0,l[a].trace);e.data=s;var d=r.redraw(e);return c.add(e,u,h,f,p),d},r.prependTraces=function t(e,n,i,a){function s(t,e,r){var n,i;if(o.isTypedArray(t))if(r<=0){var a=new t.constructor(0),s=z(e,t);r<0?(n=s,i=a):(n=a,i=s)}else if(n=new t.constructor(r),i=new t.constructor(t.length+e.length-r),r===e.length)n.set(e),i.set(t);else if(r<e.length){var l=e.length-r;n.set(e.subarray(0,l)),i.set(e.subarray(l)),i.set(t,l)}else{var c=r-e.length;n.set(e),n.set(t.subarray(0,c),e.length),i.set(t.subarray(c))}else n=e.concat(t),i=r>=0&&r<n.length?n.splice(r,n.length):[];return[n,i]}var l=O(e=o.getGraphDiv(e),n,i,a,s),u=r.redraw(e),f=[e,l.update,i,l.maxPoints];return c.add(e,r.extendTraces,f,t,arguments),u},r.newPlot=function(t,e,n,i){return t=o.getGraphDiv(t),h.cleanPlot([],{},t._fullData||[],t._fullLayout||{}),h.purge(t),r._doPlot(t,e,n,i)},r._doPlot=function(t,e,i,a){var s;if(t=o.getGraphDiv(t),l.init(t),o.isPlainObject(e)){var c=e;e=c.data,i=c.layout,a=c.config,s=c.frames}if(!1===l.triggerHandler(t,"plotly_beforeplot",[e,i,a]))return Promise.reject();e||i||o.isPlotDiv(t)||o.warn("Calling _doPlot as if redrawing but this container doesn't yet have a plot.",t),L(t,a),i||(i={}),n.select(t).classed("js-plotly-plot",!0),d.makeTester(),Array.isArray(t._promises)||(t._promises=[]);var f=0===(t.data||[]).length&&Array.isArray(e);Array.isArray(e)&&(_.cleanData(e),f?t.data=e:t.data.push.apply(t.data,e),t.empty=!1),t.layout&&!f||(t.layout=_.cleanLayout(i)),h.supplyDefaults(t);var m=t._fullLayout,y=m._has("cartesian");m._replotting=!0,(f||m._shouldCreateBgLayer)&&(!function(t){var e=n.select(t),r=t._fullLayout;if(r._calcInverseTransform=at,r._calcInverseTransform(t),r._container=e.selectAll(".plot-container").data([0]),r._container.enter().insert("div",":first-child").classed("plot-container",!0).classed("plotly",!0),r._paperdiv=r._container.selectAll(".svg-container").data([0]),r._paperdiv.enter().append("div").classed("user-select-none",!0).classed("svg-container",!0).style("position","relative"),r._glcontainer=r._paperdiv.selectAll(".gl-container").data([{}]),r._glcontainer.enter().append("div").classed("gl-container",!0),r._paperdiv.selectAll(".main-svg").remove(),r._paperdiv.select(".modebar-container").remove(),r._paper=r._paperdiv.insert("svg",":first-child").classed("main-svg",!0),r._toppaper=r._paperdiv.append("svg").classed("main-svg",!0),r._modebardiv=r._paperdiv.append("div"),delete r._modeBar,r._hoverpaper=r._paperdiv.append("svg").classed("main-svg",!0),!r._uid){var i={};n.selectAll("defs").each((function(){this.id&&(i[this.id.split("-")[1]]=1)})),r._uid=o.randstr(i)}r._paperdiv.selectAll(".main-svg").attr(v.svgAttrs),r._defs=r._paper.append("defs").attr("id","defs-"+r._uid),r._clips=r._defs.append("g").classed("clips",!0),r._topdefs=r._toppaper.append("defs").attr("id","topdefs-"+r._uid),r._topclips=r._topdefs.append("g").classed("clips",!0),r._bgLayer=r._paper.append("g").classed("bglayer",!0),r._draggers=r._paper.append("g").classed("draglayer",!0);var a=r._paper.append("g").classed("layer-below",!0);r._imageLowerLayer=a.append("g").classed("imagelayer",!0),r._shapeLowerLayer=a.append("g").classed("shapelayer",!0),r._cartesianlayer=r._paper.append("g").classed("cartesianlayer",!0),r._polarlayer=r._paper.append("g").classed("polarlayer",!0),r._smithlayer=r._paper.append("g").classed("smithlayer",!0),r._ternarylayer=r._paper.append("g").classed("ternarylayer",!0),r._geolayer=r._paper.append("g").classed("geolayer",!0),r._funnelarealayer=r._paper.append("g").classed("funnelarealayer",!0),r._pielayer=r._paper.append("g").classed("pielayer",!0),r._iciclelayer=r._paper.append("g").classed("iciclelayer",!0),r._treemaplayer=r._paper.append("g").classed("treemaplayer",!0),r._sunburstlayer=r._paper.append("g").classed("sunburstlayer",!0),r._indicatorlayer=r._toppaper.append("g").classed("indicatorlayer",!0),r._glimages=r._paper.append("g").classed("glimages",!0);var s=r._toppaper.append("g").classed("layer-above",!0);r._imageUpperLayer=s.append("g").classed("imagelayer",!0),r._shapeUpperLayer=s.append("g").classed("shapelayer",!0),r._infolayer=r._toppaper.append("g").classed("infolayer",!0),r._menulayer=r._toppaper.append("g").classed("menulayer",!0),r._zoomlayer=r._toppaper.append("g").classed("zoomlayer",!0),r._hoverlayer=r._hoverpaper.append("g").classed("hoverlayer",!0),r._modebardiv.classed("modebar-container",!0).style("position","absolute").style("top","0px").style("right","0px"),t.emit("plotly_framework")}(t),m._shouldCreateBgLayer&&delete m._shouldCreateBgLayer),d.initGradients(t),d.initPatterns(t),f&&p.saveShowSpikeInitial(t);var x=!t.calcdata||t.calcdata.length!==(t._fullData||[]).length;x&&h.doCalcdata(t);for(var b=0;b<t.calcdata.length;b++)t.calcdata[b][0].trace=t._fullData[b];t._context.responsive?t._responsiveChartHandler||(t._responsiveChartHandler=function(){o.isHidden(t)||h.resize(t)},window.addEventListener("resize",t._responsiveChartHandler)):o.clearResponsive(t);var T=o.extendFlat({},m._size),k=0;function A(){if(h.clearAutoMarginIds(t),w.drawMarginPushers(t),p.allowAutoMargin(t),m._has("pie"))for(var e=t._fullData,r=0;r<e.length;r++){var n=e[r];"pie"===n.type&&n.automargin&&h.allowAutoMargin(t,"pie."+n.uid+".automargin")}return h.doAutoMargin(t),h.previousPromises(t)}function S(){t._transitioning||(w.doAutoRangeAndConstraints(t),f&&p.saveRangeInitial(t),u.getComponentMethod("rangeslider","calcAutorange")(t))}var E=[h.previousPromises,function(){if(s)return r.addFrames(t,s)},function e(){for(var r=m._basePlotModules,n=0;n<r.length;n++)r[n].drawFramework&&r[n].drawFramework(t);!m._glcanvas&&m._has("gl")&&(m._glcanvas=m._glcontainer.selectAll(".gl-canvas").data([{key:"contextLayer",context:!0,pick:!1},{key:"focusLayer",context:!1,pick:!1},{key:"pickLayer",context:!1,pick:!0}],(function(t){return t.key})),m._glcanvas.enter().append("canvas").attr("class",(function(t){return"gl-canvas gl-canvas-"+t.key.replace("Layer","")})).style({position:"absolute",top:0,left:0,overflow:"visible","pointer-events":"none"}));var i=t._context.plotGlPixelRatio;if(m._glcanvas){m._glcanvas.attr("width",m.width*i).attr("height",m.height*i).style("width",m.width+"px").style("height",m.height+"px");var a=m._glcanvas.data()[0].regl;if(a&&(Math.floor(m.width*i)!==a._gl.drawingBufferWidth||Math.floor(m.height*i)!==a._gl.drawingBufferHeight)){var s="WebGL context buffer and canvas dimensions do not match due to browser/WebGL bug.";if(!k)return o.log(s+" Clearing graph and plotting again."),h.cleanPlot([],{},t._fullData,m),h.supplyDefaults(t),m=t._fullLayout,h.doCalcdata(t),k++,e();o.error(s)}}return"h"===m.modebar.orientation?m._modebardiv.style("height",null).style("width","100%"):m._modebardiv.style("width",null).style("height",m.height+"px"),h.previousPromises(t)},A,function(){if(h.didMarginChange(T,m._size))return o.syncOrAsync([A,w.layoutStyles],t)}];y&&E.push((function(){if(x)return o.syncOrAsync([u.getComponentMethod("shapes","calcAutorange"),u.getComponentMethod("annotations","calcAutorange"),S],t);S()})),E.push(w.layoutStyles),y&&E.push((function(){return p.draw(t,f?"":"redraw")}),(function(t){t._fullLayout._insideTickLabelsAutorange&&U(t,t._fullLayout._insideTickLabelsAutorange).then((function(){t._fullLayout._insideTickLabelsAutorange=void 0}))})),E.push(w.drawData,w.finalDraw,g,h.addLinks,h.rehover,h.redrag,h.doAutoMargin,(function(t){t._fullLayout._insideTickLabelsAutorange&&f&&p.saveRangeInitial(t,!0)}),h.previousPromises);var C=o.syncOrAsync(E,t);return C&&C.then||(C=Promise.resolve()),C.then((function(){return M(t),t}))},r.purge=function(t){var e=(t=o.getGraphDiv(t))._fullLayout||{},r=t._fullData||[];return h.cleanPlot([],{},r,e),h.purge(t),l.purge(t),e._container&&e._container.remove(),delete t._context,t},r.react=function(t,e,n,i){var a,l;t=o.getGraphDiv(t),_.clearPromiseQueue(t);var c=t._fullData,p=t._fullLayout;if(o.isPlotDiv(t)&&c&&p){if(o.isPlainObject(e)){var d=e;e=d.data,n=d.layout,i=d.config,a=d.frames}var m=!1;if(i){var g=o.extendDeep({},t._context);t._context=void 0,L(t,i),m=function t(e,r){var n;for(n in e)if("_"!==n.charAt(0)){var i=e[n],a=r[n];if(i!==a)if(o.isPlainObject(i)&&o.isPlainObject(a)){if(t(i,a))return!0}else{if(!Array.isArray(i)||!Array.isArray(a))return!0;if(i.length!==a.length)return!0;for(var s=0;s<i.length;s++)if(i[s]!==a[s]){if(!o.isPlainObject(i[s])||!o.isPlainObject(a[s]))return!0;if(t(i[s],a[s]))return!0}}}}(g,t._context)}t.data=e||[],_.cleanData(t.data),t.layout=n||{},_.cleanLayout(t.layout),function(t,e,r,n){var i,a,l,c,u,f,h,p,d,m,g=n._preGUI,v=[],y={},x={};for(i in g){if(u=$(i,K)){if(d=u.head,m=u.tail,a=u.attr||d+".uirevision",(c=(l=s(n,a).get())&&tt(a,e))&&c===l){if(null===(f=g[i])&&(f=void 0),nt(p=(h=s(e,i)).get(),f)){void 0===p&&"autorange"===m&&v.push(d),h.set(R(s(n,i).get()));continue}if("autorange"===m||"range["===m.substr(0,6)){var b=g[d+".range[0]"],_=g[d+".range[1]"],w=g[d+".autorange"];if(w||null===w&&null===b&&null===_){if(!(d in y)){var T=s(e,d).get();y[d]=T&&(T.autorange||!1!==T.autorange&&(!T.range||2!==T.range.length))}if(y[d]){h.set(R(s(n,i).get()));continue}}}}}else o.warn("unrecognized GUI edit: "+i);delete g[i],u&&"range["===u.tail.substr(0,6)&&(x[u.head]=1)}for(var k=0;k<v.length;k++){var A=v[k];if(x[A]){var M=s(e,A).get();M&&delete M.autorange}}var S=n._tracePreGUI;for(var E in S){var L,C=S[E],P=null;for(i in C){if(!P){var I=et(E,r);if(I<0){delete S[E];break}var O=rt(E,t,(L=r[I]._fullInput).index);if(O<0){delete S[E];break}P=t[O]}if(u=$(i,Q)){if(u.attr?c=(l=s(n,u.attr).get())&&tt(u.attr,e):(l=L.uirevision,void 0===(c=P.uirevision)&&(c=e.uirevision)),c&&c===l&&(null===(f=C[i])&&(f=void 0),nt(p=(h=s(P,i)).get(),f))){h.set(R(s(L,i).get()));continue}}else o.warn("unrecognized GUI edit: "+i+" in trace uid "+E);delete C[i]}}}(t.data,t.layout,c,p),h.supplyDefaults(t,{skipUpdateCalc:!0});var v=t._fullData,y=t._fullLayout,x=void 0===y.datarevision,b=y.transition,k=function(t,e,r,n,i){var a=T.layoutFlags();function o(t){return f.getLayoutValObject(r,t)}a.arrays={},a.rangesAltered={},a.nChanges=0,a.nChangesAnim=0,it(e,r,[],{getValObject:o,flags:a,immutable:n,transition:i,gd:t}),(a.plot||a.calc)&&(a.layoutReplot=!0);i&&a.nChanges&&a.nChangesAnim&&(a.anim=a.nChanges===a.nChangesAnim?"all":"some");return a}(t,p,y,x,b),A=k.newDataRevision,S=function(t,e,r,n,i,a){var o=e.length===r.length;if(!i&&!o)return{fullReplot:!0,calc:!0};var s,l,c=T.traceFlags();c.arrays={},c.nChanges=0,c.nChangesAnim=0;var u={getValObject:function(t){var e=f.getTraceValObject(l,t);return!l._module.animatable&&e.anim&&(e.anim=!1),e},flags:c,immutable:n,transition:i,newDataRevision:a,gd:t},p={};for(s=0;s<e.length;s++)if(r[s]){if(l=r[s]._fullInput,h.hasMakesDataTransform(l)&&(l=r[s]),p[l.uid])continue;p[l.uid]=1,it(e[s]._fullInput,l,[],u)}(c.calc||c.plot)&&(c.fullReplot=!0);i&&c.nChanges&&c.nChangesAnim&&(c.anim=c.nChanges===c.nChangesAnim&&o?"all":"some");return c}(t,c,v,x,b,A);if(X(t)&&(k.layoutReplot=!0),S.calc||k.calc){t.calcdata=void 0;for(var E=Object.getOwnPropertyNames(y),C=0;C<E.length;C++){var P=E[C],I=P.substring(0,5);if("xaxis"===I||"yaxis"===I){var O=y[P]._emptyCategories;O&&O()}}}else h.supplyDefaultsUpdateCalc(t.calcdata,v);var z=[];if(a&&(t._transitionData={},h.createTransitionData(t),z.push((function(){return r.addFrames(t,a)}))),y.transition&&!m&&(S.anim||k.anim))k.ticks&&z.push(w.doTicksRelayout),h.doCalcdata(t),w.doAutoRangeAndConstraints(t),z.push((function(){return h.transitionFromReact(t,S,k,p)}));else if(S.fullReplot||k.layoutReplot||m)t._fullLayout._skipDefaults=!0,z.push(r._doPlot);else{for(var D in k.arrays){var F=k.arrays[D];if(F.length){var B=u.getComponentMethod(D,"drawOne");if(B!==o.noop)for(var N=0;N<F.length;N++)B(t,F[N]);else{var j=u.getComponentMethod(D,"draw");if(j===o.noop)throw new Error("cannot draw components: "+D);j(t)}}}z.push(h.previousPromises),S.style&&z.push(w.doTraceStyle),(S.colorbars||k.colorbars)&&z.push(w.doColorBars),k.legend&&z.push(w.doLegend),k.layoutstyle&&z.push(w.layoutStyles),k.axrange&&H(z),k.ticks&&z.push(w.doTicksRelayout),k.modebar&&z.push(w.doModeBar),k.camera&&z.push(w.doCamera),z.push(M)}z.push(h.rehover,h.redrag),(l=o.syncOrAsync(z,t))&&l.then||(l=Promise.resolve(t))}else l=r.newPlot(t,e,n,i);return l.then((function(){return t.emit("plotly_react",{data:e,layout:n}),t}))},r.redraw=function(t){if(t=o.getGraphDiv(t),!o.isPlotDiv(t))throw new Error("This element is not a Plotly plot: "+t);return _.cleanData(t.data),_.cleanLayout(t.layout),t.calcdata=void 0,r._doPlot(t).then((function(){return t.emit("plotly_redraw"),t}))},r.relayout=U,r.restyle=D,r.setPlotConfig=function(t){return o.extendFlat(x,t)},r.update=Z,r._guiRelayout=J(U),r._guiRestyle=J(D),r._guiUpdate=J(Z),r._storeDirectGUIEdit=function(t,e,r){for(var n in r){B(n,s(t,n).get(),r[n],e)}}},{"../components/color":366,"../components/drawing":388,"../constants/xmlns_namespaces":480,"../lib":503,"../lib/events":492,"../lib/queue":519,"../plots/cartesian/axes":554,"../plots/cartesian/constants":561,"../plots/cartesian/graph_interact":564,"../plots/cartesian/select":575,"../plots/plots":619,"../registry":638,"./edit_types":536,"./helpers":537,"./manage_arrays":539,"./plot_config":541,"./plot_schema":542,"./subroutines":544,"@plotly/d3":58,"fast-isnumeric":190,"has-hover":228}],541:[function(t,e,r){"use strict";var n={staticPlot:{valType:"boolean",dflt:!1},typesetMath:{valType:"boolean",dflt:!0},plotlyServerURL:{valType:"string",dflt:""},editable:{valType:"boolean",dflt:!1},edits:{annotationPosition:{valType:"boolean",dflt:!1},annotationTail:{valType:"boolean",dflt:!1},annotationText:{valType:"boolean",dflt:!1},axisTitleText:{valType:"boolean",dflt:!1},colorbarPosition:{valType:"boolean",dflt:!1},colorbarTitleText:{valType:"boolean",dflt:!1},legendPosition:{valType:"boolean",dflt:!1},legendText:{valType:"boolean",dflt:!1},shapePosition:{valType:"boolean",dflt:!1},titleText:{valType:"boolean",dflt:!1}},autosizable:{valType:"boolean",dflt:!1},responsive:{valType:"boolean",dflt:!1},fillFrame:{valType:"boolean",dflt:!1},frameMargins:{valType:"number",dflt:0,min:0,max:.5},scrollZoom:{valType:"flaglist",flags:["cartesian","gl3d","geo","mapbox"],extras:[!0,!1],dflt:"gl3d+geo+mapbox"},doubleClick:{valType:"enumerated",values:[!1,"reset","autosize","reset+autosize"],dflt:"reset+autosize"},doubleClickDelay:{valType:"number",dflt:300,min:0},showAxisDragHandles:{valType:"boolean",dflt:!0},showAxisRangeEntryBoxes:{valType:"boolean",dflt:!0},showTips:{valType:"boolean",dflt:!0},showLink:{valType:"boolean",dflt:!1},linkText:{valType:"string",dflt:"Edit chart",noBlank:!0},sendData:{valType:"boolean",dflt:!0},showSources:{valType:"any",dflt:!1},displayModeBar:{valType:"enumerated",values:["hover",!0,!1],dflt:"hover"},showSendToCloud:{valType:"boolean",dflt:!1},showEditInChartStudio:{valType:"boolean",dflt:!1},modeBarButtonsToRemove:{valType:"any",dflt:[]},modeBarButtonsToAdd:{valType:"any",dflt:[]},modeBarButtons:{valType:"any",dflt:!1},toImageButtonOptions:{valType:"any",dflt:{}},displaylogo:{valType:"boolean",dflt:!0},watermark:{valType:"boolean",dflt:!1},plotGlPixelRatio:{valType:"number",dflt:2,min:1,max:4},setBackground:{valType:"any",dflt:"transparent"},topojsonURL:{valType:"string",noBlank:!0,dflt:"https://cdn.plot.ly/"},mapboxAccessToken:{valType:"string",dflt:null},logging:{valType:"integer",min:0,max:2,dflt:1},notifyOnLogging:{valType:"integer",min:0,max:2,dflt:0},queueLength:{valType:"integer",min:0,dflt:0},globalTransforms:{valType:"any",dflt:[]},locale:{valType:"string",dflt:"en-US"},locales:{valType:"any",dflt:{}}},i={};!function t(e,r){for(var n in e){var i=e[n];i.valType?r[n]=i.dflt:(r[n]||(r[n]={}),t(i,r[n]))}}(n,i),e.exports={configAttributes:n,dfltConfig:i}},{}],542:[function(t,e,r){"use strict";var n=t("../registry"),i=t("../lib"),a=t("../plots/attributes"),o=t("../plots/layout_attributes"),s=t("../plots/frame_attributes"),l=t("../plots/animation_attributes"),c=t("./plot_config").configAttributes,u=t("./edit_types"),f=i.extendDeepAll,h=i.isPlainObject,p=i.isArrayOrTypedArray,d=i.nestedProperty,m=i.valObjectMeta,g=["_isSubplotObj","_isLinkedToArray","_arrayAttrRegexps","_deprecated"];function v(t,e,r){if(!t)return!1;if(t._isLinkedToArray)if(y(e[r]))r++;else if(r<e.length)return!1;for(;r<e.length;r++){var n=t[e[r]];if(!h(n))break;if(t=n,r===e.length-1)break;if(t._isLinkedToArray){if(!y(e[++r]))return!1}else if("info_array"===t.valType){var i=e[++r];if(!y(i))return!1;var a=t.items;if(Array.isArray(a)){if(i>=a.length)return!1;if(2===t.dimensions){if(r++,e.length===r)return t;var o=e[r];if(!y(o))return!1;t=a[i][o]}else t=a[i]}else t=a}}return t}function y(t){return t===Math.round(t)&&t>=0}function x(){var t,e,r={};for(t in f(r,o),n.subplotsRegistry){if((e=n.subplotsRegistry[t]).layoutAttributes)if(Array.isArray(e.attr))for(var i=0;i<e.attr.length;i++)w(r,e,e.attr[i]);else w(r,e,"subplot"===e.attr?e.name:e.attr)}for(t in n.componentsRegistry){var a=(e=n.componentsRegistry[t]).schema;if(a&&(a.subplots||a.layout)){var s=a.subplots;if(s&&s.xaxis&&!s.yaxis)for(var l in s.xaxis)delete r.yaxis[l]}else"colorscale"===e.name?f(r,e.layoutAttributes):e.layoutAttributes&&T(r,e.layoutAttributes,e.name)}return{layoutAttributes:_(r)}}function b(){var t={frames:f({},s)};return _(t),t.frames}function _(t){return function(t){r.crawl(t,(function(t,e,n){r.isValObject(t)?!0!==t.arrayOk&&"data_array"!==t.valType||(n[e+"src"]={valType:"string",editType:"none"}):h(t)&&(t.role="object")}))}(t),function(t){r.crawl(t,(function(t,e,r){if(t){var n=t._isLinkedToArray;n&&(delete t._isLinkedToArray,r[e]={items:{}},r[e].items[n]=t,r[e].role="object")}}))}(t),function(t){!function t(e){for(var r in e)if(h(e[r]))t(e[r]);else if(Array.isArray(e[r]))for(var n=0;n<e[r].length;n++)t(e[r][n]);else e[r]instanceof RegExp&&(e[r]=e[r].toString())}(t)}(t),t}function w(t,e,r){var n=d(t,r),i=f({},e.layoutAttributes);i._isSubplotObj=!0,n.set(i)}function T(t,e,r){var n=d(t,r);n.set(f(n.get()||{},e))}r.IS_SUBPLOT_OBJ="_isSubplotObj",r.IS_LINKED_TO_ARRAY="_isLinkedToArray",r.DEPRECATED="_deprecated",r.UNDERSCORE_ATTRS=g,r.get=function(){var t={};n.allTypes.forEach((function(e){t[e]=function(t){var e,i;e=n.modules[t]._module,i=e.basePlotModule;var o={type:null},s=f({},a),l=f({},e.attributes);r.crawl(l,(function(t,e,r,n,i){d(s,i).set(void 0),void 0===t&&d(l,i).set(void 0)})),f(o,s),n.traceIs(t,"noOpacity")&&delete o.opacity;n.traceIs(t,"showLegend")||(delete o.showlegend,delete o.legendgroup);n.traceIs(t,"noHover")&&(delete o.hoverinfo,delete o.hoverlabel);e.selectPoints||delete o.selectedpoints;f(o,l),i.attributes&&f(o,i.attributes);o.type=t;var c={meta:e.meta||{},categories:e.categories||{},animatable:Boolean(e.animatable),type:t,attributes:_(o)};if(e.layoutAttributes){var u={};f(u,e.layoutAttributes),c.layoutAttributes=_(u)}e.animatable||r.crawl(c,(function(t){r.isValObject(t)&&"anim"in t&&delete t.anim}));return c}(e)}));var e={};return Object.keys(n.transformsRegistry).forEach((function(t){e[t]=function(t){var e=n.transformsRegistry[t],r=f({},e.attributes);return Object.keys(n.componentsRegistry).forEach((function(e){var i=n.componentsRegistry[e];i.schema&&i.schema.transforms&&i.schema.transforms[t]&&Object.keys(i.schema.transforms[t]).forEach((function(e){T(r,i.schema.transforms[t][e],e)}))})),{attributes:_(r)}}(t)})),{defs:{valObjects:m,metaKeys:g.concat(["description","role","editType","impliedEdits"]),editType:{traces:u.traces,layout:u.layout},impliedEdits:{}},traces:t,layout:x(),transforms:e,frames:b(),animation:_(l),config:_(c)}},r.crawl=function(t,e,n,i){var a=n||0;i=i||"",Object.keys(t).forEach((function(n){var o=t[n];if(-1===g.indexOf(n)){var s=(i?i+".":"")+n;e(o,n,t,a,s),r.isValObject(o)||h(o)&&"impliedEdits"!==n&&r.crawl(o,e,a+1,s)}}))},r.isValObject=function(t){return t&&void 0!==t.valType},r.findArrayAttributes=function(t){var e,n,i=[],o=[],s=[];function l(t,r,a,l){o=o.slice(0,l).concat([r]),s=s.slice(0,l).concat([t&&t._isLinkedToArray]),t&&("data_array"===t.valType||!0===t.arrayOk)&&!("colorbar"===o[l-1]&&("ticktext"===r||"tickvals"===r))&&function t(e,r,a){var l=e[o[r]],c=a+o[r];if(r===o.length-1)p(l)&&i.push(n+c);else if(s[r]){if(Array.isArray(l))for(var u=0;u<l.length;u++)h(l[u])&&t(l[u],r+1,c+"["+u+"].")}else h(l)&&t(l,r+1,c+".")}(e,0,"")}e=t,n="",r.crawl(a,l),t._module&&t._module.attributes&&r.crawl(t._module.attributes,l);var c=t.transforms;if(c)for(var u=0;u<c.length;u++){var f=c[u],d=f._module;d&&(n="transforms["+u+"].",e=f,r.crawl(d.attributes,l))}return i},r.getTraceValObject=function(t,e){var r,i,o=e[0],s=1;if("transforms"===o){if(1===e.length)return a.transforms;var l=t.transforms;if(!Array.isArray(l)||!l.length)return!1;var c=e[1];if(!y(c)||c>=l.length)return!1;i=(r=(n.transformsRegistry[l[c].type]||{}).attributes)&&r[e[2]],s=3}else{var u=t._module;if(u||(u=(n.modules[t.type||a.type.dflt]||{})._module),!u)return!1;if(!(i=(r=u.attributes)&&r[o])){var f=u.basePlotModule;f&&f.attributes&&(i=f.attributes[o])}i||(i=a[o])}return v(i,e,s)},r.getLayoutValObject=function(t,e){return v(function(t,e){var r,i,a,s,l=t._basePlotModules;if(l){var c;for(r=0;r<l.length;r++){if((a=l[r]).attrRegex&&a.attrRegex.test(e)){if(a.layoutAttrOverrides)return a.layoutAttrOverrides;!c&&a.layoutAttributes&&(c=a.layoutAttributes)}var u=a.baseLayoutAttrOverrides;if(u&&e in u)return u[e]}if(c)return c}var f=t._modules;if(f)for(r=0;r<f.length;r++)if((s=f[r].layoutAttributes)&&e in s)return s[e];for(i in n.componentsRegistry){if("colorscale"===(a=n.componentsRegistry[i]).name&&0===e.indexOf("coloraxis"))return a.layoutAttributes[e];if(!a.schema&&e===a.name)return a.layoutAttributes}return e in o&&o[e]}(t,e[0]),e,1)}},{"../lib":503,"../plots/animation_attributes":548,"../plots/attributes":550,"../plots/frame_attributes":586,"../plots/layout_attributes":610,"../registry":638,"./edit_types":536,"./plot_config":541}],543:[function(t,e,r){"use strict";var n=t("../lib"),i=t("../plots/attributes"),a={name:{valType:"string",editType:"none"}};function o(t){return t&&"string"==typeof t}function s(t){var e=t.length-1;return"s"!==t.charAt(e)&&n.warn("bad argument to arrayDefaultKey: "+t),t.substr(0,t.length-1)+"defaults"}a.templateitemname={valType:"string",editType:"calc"},r.templatedArray=function(t,e){return e._isLinkedToArray=t,e.name=a.name,e.templateitemname=a.templateitemname,e},r.traceTemplater=function(t){var e,r,a={};for(e in t)r=t[e],Array.isArray(r)&&r.length&&(a[e]=0);return{newTrace:function(o){var s={type:e=n.coerce(o,{},i,"type"),_template:null};if(e in a){r=t[e];var l=a[e]%r.length;a[e]++,s._template=r[l]}return s}}},r.newContainer=function(t,e,r){var i=t._template,a=i&&(i[e]||r&&i[r]);return n.isPlainObject(a)||(a=null),t[e]={_template:a}},r.arrayTemplater=function(t,e,r){var n=t._template,i=n&&n[s(e)],a=n&&n[e];Array.isArray(a)&&a.length||(a=[]);var l={};return{newItem:function(t){var e={name:t.name,_input:t},n=e.templateitemname=t.templateitemname;if(!o(n))return e._template=i,e;for(var s=0;s<a.length;s++){var c=a[s];if(c.name===n)return l[n]=1,e._template=c,e}return e[r]=t[r]||!1,e._template=!1,e},defaultItems:function(){for(var t=[],e=0;e<a.length;e++){var r=a[e],n=r.name;if(o(n)&&!l[n]){var i={_template:r,name:n,_input:{_templateitemname:n}};i.templateitemname=r.templateitemname,t.push(i),l[n]=1}}return t}}},r.arrayDefaultKey=s,r.arrayEditor=function(t,e,r){var i=(n.nestedProperty(t,e).get()||[]).length,a=r._index,o=a>=i&&(r._input||{})._templateitemname;o&&(a=i);var s,l=e+"["+a+"]";function c(){s={},o&&(s[l]={},s[l].templateitemname=o)}function u(t,e){o?n.nestedProperty(s[l],t).set(e):s[l+"."+t]=e}function f(){var t=s;return c(),t}return c(),{modifyBase:function(t,e){s[t]=e},modifyItem:u,getUpdateObj:f,applyUpdate:function(e,r){e&&u(e,r);var i=f();for(var a in i)n.nestedProperty(t,a).set(i[a])}}}},{"../lib":503,"../plots/attributes":550}],544:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../registry"),a=t("../plots/plots"),o=t("../lib"),s=t("../lib/clear_gl_canvases"),l=t("../components/color"),c=t("../components/drawing"),u=t("../components/titles"),f=t("../components/modebar"),h=t("../plots/cartesian/axes"),p=t("../constants/alignment"),d=t("../plots/cartesian/constraints"),m=d.enforce,g=d.clean,v=t("../plots/cartesian/autorange").doAutoRange;function y(t,e,r){for(var n=0;n<r.length;n++){var i=r[n][0],a=r[n][1];if(!(i[0]>=t[1]||i[1]<=t[0])&&(a[0]<e[1]&&a[1]>e[0]))return!0}return!1}function x(t){var e,i,s,u,d,m,g=t._fullLayout,v=g._size,x=v.p,_=h.list(t,"",!0);if(g._paperdiv.style({width:t._context.responsive&&g.autosize&&!t._context._hasZeroWidth&&!t.layout.width?"100%":g.width+"px",height:t._context.responsive&&g.autosize&&!t._context._hasZeroHeight&&!t.layout.height?"100%":g.height+"px"}).selectAll(".main-svg").call(c.setSize,g.width,g.height),t._context.setBackground(t,g.paper_bgcolor),r.drawMainTitle(t),f.manage(t),!g._has("cartesian"))return a.previousPromises(t);function T(t,e,r){var n=t._lw/2;return"x"===t._id.charAt(0)?e?"top"===r?e._offset-x-n:e._offset+e._length+x+n:v.t+v.h*(1-(t.position||0))+n%1:e?"right"===r?e._offset+e._length+x+n:e._offset-x-n:v.l+v.w*(t.position||0)+n%1}for(e=0;e<_.length;e++){var k=(u=_[e])._anchorAxis;u._linepositions={},u._lw=c.crispRound(t,u.linewidth,1),u._mainLinePosition=T(u,k,u.side),u._mainMirrorPosition=u.mirror&&k?T(u,k,p.OPPOSITE_SIDE[u.side]):null}var A=[],M=[],S=[],E=1===l.opacity(g.paper_bgcolor)&&1===l.opacity(g.plot_bgcolor)&&g.paper_bgcolor===g.plot_bgcolor;for(i in g._plots)if((s=g._plots[i]).mainplot)s.bg&&s.bg.remove(),s.bg=void 0;else{var L=s.xaxis.domain,C=s.yaxis.domain,P=s.plotgroup;if(y(L,C,S)){var I=P.node(),O=s.bg=o.ensureSingle(P,"rect","bg");I.insertBefore(O.node(),I.childNodes[0]),M.push(i)}else P.select("rect.bg").remove(),S.push([L,C]),E||(A.push(i),M.push(i))}var z,D,R,F,B,N,j,U,V,H,q,G,Y,W=g._bgLayer.selectAll(".bg").data(A);for(W.enter().append("rect").classed("bg",!0),W.exit().remove(),W.each((function(t){g._plots[t].bg=n.select(this)})),e=0;e<M.length;e++)s=g._plots[M[e]],d=s.xaxis,m=s.yaxis,s.bg&&void 0!==d._offset&&void 0!==m._offset&&s.bg.call(c.setRect,d._offset-x,m._offset-x,d._length+2*x,m._length+2*x).call(l.fill,g.plot_bgcolor).style("stroke-width",0);if(!g._hasOnlyLargeSploms)for(i in g._plots){s=g._plots[i],d=s.xaxis,m=s.yaxis;var X,Z,J=s.clipId="clip"+g._uid+i+"plot",K=o.ensureSingleById(g._clips,"clipPath",J,(function(t){t.classed("plotclip",!0).append("rect")}));s.clipRect=K.select("rect").attr({width:d._length,height:m._length}),c.setTranslate(s.plot,d._offset,m._offset),s._hasClipOnAxisFalse?(X=null,Z=J):(X=J,Z=null),c.setClipUrl(s.plot,X,t),s.layerClipId=Z}function Q(t){return"M"+z+","+t+"H"+D}function $(t){return"M"+d._offset+","+t+"h"+d._length}function tt(t){return"M"+t+","+U+"V"+j}function et(t){return"M"+t+","+m._offset+"v"+m._length}function rt(t,e,r){if(!t.showline||i!==t._mainSubplot)return"";if(!t._anchorAxis)return r(t._mainLinePosition);var n=e(t._mainLinePosition);return t.mirror&&(n+=e(t._mainMirrorPosition)),n}for(i in g._plots){s=g._plots[i],d=s.xaxis,m=s.yaxis;var nt="M0,0";b(d,i)&&(B=w(d,"left",m,_),z=d._offset-(B?x+B:0),N=w(d,"right",m,_),D=d._offset+d._length+(N?x+N:0),R=T(d,m,"bottom"),F=T(d,m,"top"),!(Y=!d._anchorAxis||i!==d._mainSubplot)||"allticks"!==d.mirror&&"all"!==d.mirror||(d._linepositions[i]=[R,F]),nt=rt(d,Q,$),Y&&d.showline&&("all"===d.mirror||"allticks"===d.mirror)&&(nt+=Q(R)+Q(F)),s.xlines.style("stroke-width",d._lw+"px").call(l.stroke,d.showline?d.linecolor:"rgba(0,0,0,0)")),s.xlines.attr("d",nt);var it="M0,0";b(m,i)&&(q=w(m,"bottom",d,_),j=m._offset+m._length+(q?x:0),G=w(m,"top",d,_),U=m._offset-(G?x:0),V=T(m,d,"left"),H=T(m,d,"right"),!(Y=!m._anchorAxis||i!==m._mainSubplot)||"allticks"!==m.mirror&&"all"!==m.mirror||(m._linepositions[i]=[V,H]),it=rt(m,tt,et),Y&&m.showline&&("all"===m.mirror||"allticks"===m.mirror)&&(it+=tt(V)+tt(H)),s.ylines.style("stroke-width",m._lw+"px").call(l.stroke,m.showline?m.linecolor:"rgba(0,0,0,0)")),s.ylines.attr("d",it)}return h.makeClipPaths(t),a.previousPromises(t)}function b(t,e){return(t.ticks||t.showline)&&(e===t._mainSubplot||"all"===t.mirror||"allticks"===t.mirror)}function _(t,e,r){if(!r.showline||!r._lw)return!1;if("all"===r.mirror||"allticks"===r.mirror)return!0;var n=r._anchorAxis;if(!n)return!1;var i=p.FROM_BL[e];return r.side===e?n.domain[i]===t.domain[i]:r.mirror&&n.domain[1-i]===t.domain[1-i]}function w(t,e,r,n){if(_(t,e,r))return r._lw;for(var i=0;i<n.length;i++){var a=n[i];if(a._mainAxis===r._mainAxis&&_(t,e,a))return a._lw}return 0}function T(t,e){var r=t.title,n=t._size,i=0;switch("start"===e?i=r.pad.l:"end"===e&&(i=-r.pad.r),r.xref){case"paper":return n.l+n.w*r.x+i;case"container":default:return t.width*r.x+i}}function k(t,e){var r=t.title,n=t._size,i=0;if("0em"!==e&&e?e===p.CAP_SHIFT+"em"&&(i=r.pad.t):i=-r.pad.b,"auto"===r.y)return n.t/2;switch(r.yref){case"paper":return n.t+n.h-n.h*r.y+i;case"container":default:return t.height-t.height*r.y+i}}r.layoutStyles=function(t){return o.syncOrAsync([a.doAutoMargin,x],t)},r.drawMainTitle=function(t){var e=t._fullLayout,r=function(t){var e=t.title,r="middle";o.isRightAnchor(e)?r="end":o.isLeftAnchor(e)&&(r="start");return r}(e),n=function(t){var e=t.title,r="0em";o.isTopAnchor(e)?r=p.CAP_SHIFT+"em":o.isMiddleAnchor(e)&&(r=p.MID_SHIFT+"em");return r}(e);u.draw(t,"gtitle",{propContainer:e,propName:"title.text",placeholder:e._dfltTitle.plot,attributes:{x:T(e,r),y:k(e,n),"text-anchor":r,dy:n}})},r.doTraceStyle=function(t){var e,n=t.calcdata,o=[];for(e=0;e<n.length;e++){var l=n[e],c=l[0]||{},u=c.trace||{},f=u._module||{},h=f.arraysToCalcdata;h&&h(l,u);var p=f.editStyle;p&&o.push({fn:p,cd0:c})}if(o.length){for(e=0;e<o.length;e++){var d=o[e];d.fn(t,d.cd0)}s(t),r.redrawReglTraces(t)}return a.style(t),i.getComponentMethod("legend","draw")(t),a.previousPromises(t)},r.doColorBars=function(t){return i.getComponentMethod("colorbar","draw")(t),a.previousPromises(t)},r.layoutReplot=function(t){var e=t.layout;return t.layout=void 0,i.call("_doPlot",t,"",e)},r.doLegend=function(t){return i.getComponentMethod("legend","draw")(t),a.previousPromises(t)},r.doTicksRelayout=function(t){return h.draw(t,"redraw"),t._fullLayout._hasOnlyLargeSploms&&(i.subplotsRegistry.splom.updateGrid(t),s(t),r.redrawReglTraces(t)),r.drawMainTitle(t),a.previousPromises(t)},r.doModeBar=function(t){var e=t._fullLayout;f.manage(t);for(var r=0;r<e._basePlotModules.length;r++){var n=e._basePlotModules[r].updateFx;n&&n(t)}return a.previousPromises(t)},r.doCamera=function(t){for(var e=t._fullLayout,r=e._subplots.gl3d,n=0;n<r.length;n++){var i=e[r[n]];i._scene.setViewport(i)}},r.drawData=function(t){var e=t._fullLayout;s(t);for(var n=e._basePlotModules,o=0;o<n.length;o++)n[o].plot(t);return r.redrawReglTraces(t),a.style(t),i.getComponentMethod("shapes","draw")(t),i.getComponentMethod("annotations","draw")(t),i.getComponentMethod("images","draw")(t),e._replotting=!1,a.previousPromises(t)},r.redrawReglTraces=function(t){var e=t._fullLayout;if(e._has("regl")){var r,n,i=t._fullData,a=[],s=[];for(e._hasOnlyLargeSploms&&e._splomGrid.draw(),r=0;r<i.length;r++){var l=i[r];!0===l.visible&&0!==l._length&&("splom"===l.type?e._splomScenes[l.uid].draw():"scattergl"===l.type?o.pushUnique(a,l.xaxis+l.yaxis):"scatterpolargl"===l.type&&o.pushUnique(s,l.subplot))}for(r=0;r<a.length;r++)(n=e._plots[a[r]])._scene&&n._scene.draw();for(r=0;r<s.length;r++)(n=e[s[r]]._subplot)._scene&&n._scene.draw()}},r.doAutoRangeAndConstraints=function(t){for(var e,r=h.list(t,"",!0),n={},i=0;i<r.length;i++)if(!n[(e=r[i])._id]){n[e._id]=1,g(t,e),v(t,e);var a=e._matchGroup;if(a)for(var o in a){var s=h.getFromId(t,o);v(t,s,e.range),n[o]=1}}m(t)},r.finalDraw=function(t){i.getComponentMethod("rangeslider","draw")(t),i.getComponentMethod("rangeselector","draw")(t)},r.drawMarginPushers=function(t){i.getComponentMethod("legend","draw")(t),i.getComponentMethod("rangeselector","draw")(t),i.getComponentMethod("sliders","draw")(t),i.getComponentMethod("updatemenus","draw")(t),i.getComponentMethod("colorbar","draw")(t)}},{"../components/color":366,"../components/drawing":388,"../components/modebar":429,"../components/titles":464,"../constants/alignment":471,"../lib":503,"../lib/clear_gl_canvases":487,"../plots/cartesian/autorange":553,"../plots/cartesian/axes":554,"../plots/cartesian/constraints":562,"../plots/plots":619,"../registry":638,"@plotly/d3":58}],545:[function(t,e,r){"use strict";var n=t("../lib"),i=n.isPlainObject,a=t("./plot_schema"),o=t("../plots/plots"),s=t("../plots/attributes"),l=t("./plot_template"),c=t("./plot_config").dfltConfig;function u(t,e){t=n.extendDeep({},t);var r,a,o=Object.keys(t).sort();function s(e,r,n){if(i(r)&&i(e))u(e,r);else if(Array.isArray(r)&&Array.isArray(e)){var o=l.arrayTemplater({_template:t},n);for(a=0;a<r.length;a++){var s=r[a],c=o.newItem(s)._template;c&&u(c,s)}var f=o.defaultItems();for(a=0;a<f.length;a++)r.push(f[a]._template);for(a=0;a<r.length;a++)delete r[a].templateitemname}}for(r=0;r<o.length;r++){var c=o[r],h=t[c];if(c in e?s(h,e[c],c):e[c]=h,f(c)===c)for(var p in e){var d=f(p);p===d||d!==c||p in t||s(h,e[p],c)}}}function f(t){return t.replace(/[0-9]+$/,"")}function h(t,e,r,a,o){var s=o&&r(o);for(var c in t){var u=t[c],p=m(t,c,a),d=m(t,c,o),g=r(d);if(!g){var v=f(c);v!==c&&(g=r(d=m(t,v,o)))}if((!s||s!==g)&&!(!g||g._noTemplating||"data_array"===g.valType||g.arrayOk&&Array.isArray(u)))if(!g.valType&&i(u))h(u,e,r,p,d);else if(g._isLinkedToArray&&Array.isArray(u))for(var y=!1,x=0,b={},_=0;_<u.length;_++){var w=u[_];if(i(w)){var T=w.name;if(T)b[T]||(h(w,e,r,m(u,x,p),m(u,x,d)),x++,b[T]=1);else if(!y){var k=m(t,l.arrayDefaultKey(c),a),A=m(u,x,p);h(w,e,r,A,m(u,x,d));var M=n.nestedProperty(e,A);n.nestedProperty(e,k).set(M.get()),M.set(null),y=!0}}}else{n.nestedProperty(e,p).set(u)}}}function p(t,e){return a.getLayoutValObject(t,n.nestedProperty({},e).parts)}function d(t,e){return a.getTraceValObject(t,n.nestedProperty({},e).parts)}function m(t,e,r){return r?Array.isArray(t)?r+"["+e+"]":r+"."+e:e}function g(t){for(var e=0;e<t.length;e++)if(i(t[e]))return!0}function v(t){var e;switch(t.code){case"data":e="The template has no key data.";break;case"layout":e="The template has no key layout.";break;case"missing":e=t.path?"There are no templates for item "+t.path+" with name "+t.templateitemname:"There are no templates for trace "+t.index+", of type "+t.traceType+".";break;case"unused":e=t.path?"The template item at "+t.path+" was not used in constructing the plot.":t.dataCount?"Some of the templates of type "+t.traceType+" were not used. The template has "+t.templateCount+" traces, the data only has "+t.dataCount+" of this type.":"The template has "+t.templateCount+" traces of type "+t.traceType+" but there are none in the data.";break;case"reused":e="Some of the templates of type "+t.traceType+" were used more than once. The template has "+t.templateCount+" traces, the data has "+t.dataCount+" of this type."}return t.msg=e,t}r.makeTemplate=function(t){t=n.isPlainObject(t)?t:n.getGraphDiv(t),t=n.extendDeep({_context:c},{data:t.data,layout:t.layout}),o.supplyDefaults(t);var e=t.data||[],r=t.layout||{};r._basePlotModules=t._fullLayout._basePlotModules,r._modules=t._fullLayout._modules;var a={data:{},layout:{}};e.forEach((function(t){var e={};h(t,e,d.bind(null,t));var r=n.coerce(t,{},s,"type"),i=a.data[r];i||(i=a.data[r]=[]),i.push(e)})),h(r,a.layout,p.bind(null,r)),delete a.layout.template;var l=r.template;if(i(l)){var f,m,g,v,y,x,b=l.layout;i(b)&&u(b,a.layout);var _=l.data;if(i(_)){for(m in a.data)if(g=_[m],Array.isArray(g)){for(x=(y=a.data[m]).length,v=g.length,f=0;f<x;f++)u(g[f%v],y[f]);for(f=x;f<v;f++)y.push(n.extendDeep({},g[f]))}for(m in _)m in a.data||(a.data[m]=n.extendDeep([],_[m]))}}return a},r.validateTemplate=function(t,e){var r=n.extendDeep({},{_context:c,data:t.data,layout:t.layout}),a=r.layout||{};i(e)||(e=a.template||{});var s=e.layout,l=e.data,u=[];r.layout=a,r.layout.template=e,o.supplyDefaults(r);var h=r._fullLayout,p=r._fullData,d={};if(i(s)?(!function t(e,r){for(var n in e)if("_"!==n.charAt(0)&&i(e[n])){var a,o=f(n),s=[];for(a=0;a<r.length;a++)s.push(m(e,n,r[a])),o!==n&&s.push(m(e,o,r[a]));for(a=0;a<s.length;a++)d[s[a]]=1;t(e[n],s)}}(h,["layout"]),function t(e,r){for(var n in e)if(-1===n.indexOf("defaults")&&i(e[n])){var a=m(e,n,r);d[a]?t(e[n],a):u.push({code:"unused",path:a})}}(s,"layout")):u.push({code:"layout"}),i(l)){for(var y,x={},b=0;b<p.length;b++){var _=p[b];x[y=_.type]=(x[y]||0)+1,_._fullInput._template||u.push({code:"missing",index:_._fullInput.index,traceType:y})}for(y in l){var w=l[y].length,T=x[y]||0;w>T?u.push({code:"unused",traceType:y,templateCount:w,dataCount:T}):T>w&&u.push({code:"reused",traceType:y,templateCount:w,dataCount:T})}}else u.push({code:"data"});if(function t(e,r){for(var n in e)if("_"!==n.charAt(0)){var a=e[n],o=m(e,n,r);i(a)?(Array.isArray(e)&&!1===a._template&&a.templateitemname&&u.push({code:"missing",path:o,templateitemname:a.templateitemname}),t(a,o)):Array.isArray(a)&&g(a)&&t(a,o)}}({data:p,layout:h},""),u.length)return u.map(v)}},{"../lib":503,"../plots/attributes":550,"../plots/plots":619,"./plot_config":541,"./plot_schema":542,"./plot_template":543}],546:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("./plot_api"),a=t("../plots/plots"),o=t("../lib"),s=t("../snapshot/helpers"),l=t("../snapshot/tosvg"),c=t("../snapshot/svgtoimg"),u=t("../version").version,f={format:{valType:"enumerated",values:["png","jpeg","webp","svg","full-json"],dflt:"png"},width:{valType:"number",min:1},height:{valType:"number",min:1},scale:{valType:"number",min:0,dflt:1},setBackground:{valType:"any",dflt:!1},imageDataOnly:{valType:"boolean",dflt:!1}};e.exports=function(t,e){var r,h,p,d;function m(t){return!(t in e)||o.validate(e[t],f[t])}if(e=e||{},o.isPlainObject(t)?(r=t.data||[],h=t.layout||{},p=t.config||{},d={}):(t=o.getGraphDiv(t),r=o.extendDeep([],t.data),h=o.extendDeep({},t.layout),p=t._context,d=t._fullLayout||{}),!m("width")&&null!==e.width||!m("height")&&null!==e.height)throw new Error("Height and width should be pixel values.");if(!m("format"))throw new Error("Export format is not "+o.join2(f.format.values,", "," or ")+".");var g={};function v(t,r){return o.coerce(e,g,f,t,r)}var y=v("format"),x=v("width"),b=v("height"),_=v("scale"),w=v("setBackground"),T=v("imageDataOnly"),k=document.createElement("div");k.style.position="absolute",k.style.left="-5000px",document.body.appendChild(k);var A=o.extendFlat({},h);x?A.width=x:null===e.width&&n(d.width)&&(A.width=d.width),b?A.height=b:null===e.height&&n(d.height)&&(A.height=d.height);var M=o.extendFlat({},p,{_exportedPlot:!0,staticPlot:!0,setBackground:w}),S=s.getRedrawFunc(k);function E(){return new Promise((function(t){setTimeout(t,s.getDelay(k._fullLayout))}))}function L(){return new Promise((function(t,e){var r=l(k,y,_),n=k._fullLayout.width,f=k._fullLayout.height;function h(){i.purge(k),document.body.removeChild(k)}if("full-json"===y){var p=a.graphJson(k,!1,"keepdata","object",!0,!0);return p.version=u,p=JSON.stringify(p),h(),t(T?p:s.encodeJSON(p))}if(h(),"svg"===y)return t(T?r:s.encodeSVG(r));var d=document.createElement("canvas");d.id=o.randstr(),c({format:y,width:n,height:f,scale:_,canvas:d,svg:r,promise:!0}).then(t).catch(e)}))}return new Promise((function(t,e){i.newPlot(k,r,A,M).then(S).then(E).then(L).then((function(e){t(function(t){return T?t.replace(s.IMAGE_URL_PREFIX,""):t}(e))})).catch((function(t){e(t)}))}))}},{"../lib":503,"../plots/plots":619,"../snapshot/helpers":642,"../snapshot/svgtoimg":644,"../snapshot/tosvg":646,"../version":1123,"./plot_api":540,"fast-isnumeric":190}],547:[function(t,e,r){"use strict";var n=t("../lib"),i=t("../plots/plots"),a=t("./plot_schema"),o=t("./plot_config").dfltConfig,s=n.isPlainObject,l=Array.isArray,c=n.isArrayOrTypedArray;function u(t,e,r,i,a,o){o=o||[];for(var f=Object.keys(t),h=0;h<f.length;h++){var p=f[h];if("transforms"!==p){var v=o.slice();v.push(p);var y=t[p],x=e[p],b=g(r,p),_=(b||{}).valType,w="info_array"===_,T="colorscale"===_,k=(b||{}).items;if(m(r,p))if(s(y)&&s(x)&&"any"!==_)u(y,x,b,i,a,v);else if(w&&l(y)){y.length>x.length&&i.push(d("unused",a,v.concat(x.length)));var A,M,S,E,L,C=x.length,P=Array.isArray(k);if(P&&(C=Math.min(C,k.length)),2===b.dimensions)for(M=0;M<C;M++)if(l(y[M])){y[M].length>x[M].length&&i.push(d("unused",a,v.concat(M,x[M].length)));var I=x[M].length;for(A=0;A<(P?Math.min(I,k[M].length):I);A++)S=P?k[M][A]:k,E=y[M][A],L=x[M][A],n.validate(E,S)?L!==E&&L!==+E&&i.push(d("dynamic",a,v.concat(M,A),E,L)):i.push(d("value",a,v.concat(M,A),E))}else i.push(d("array",a,v.concat(M),y[M]));else for(M=0;M<C;M++)S=P?k[M]:k,E=y[M],L=x[M],n.validate(E,S)?L!==E&&L!==+E&&i.push(d("dynamic",a,v.concat(M),E,L)):i.push(d("value",a,v.concat(M),E))}else if(b.items&&!w&&l(y)){var O,z,D=k[Object.keys(k)[0]],R=[];for(O=0;O<x.length;O++){var F=x[O]._index||O;if((z=v.slice()).push(F),s(y[F])&&s(x[O])){R.push(F);var B=y[F],N=x[O];s(B)&&!1!==B.visible&&!1===N.visible?i.push(d("invisible",a,z)):u(B,N,D,i,a,z)}}for(O=0;O<y.length;O++)(z=v.slice()).push(O),s(y[O])?-1===R.indexOf(O)&&i.push(d("unused",a,z)):i.push(d("object",a,z,y[O]))}else!s(y)&&s(x)?i.push(d("object",a,v,y)):c(y)||!c(x)||w||T?p in e?n.validate(y,b)?"enumerated"===b.valType&&(b.coerceNumber&&y!==+x||y!==x)&&i.push(d("dynamic",a,v,y,x)):i.push(d("value",a,v,y)):i.push(d("unused",a,v,y)):i.push(d("array",a,v,y));else i.push(d("schema",a,v))}}return i}function f(t,e){for(var r=t.layout.layoutAttributes,i=0;i<e.length;i++){var a=e[i],o=t.traces[a.type],s=o.layoutAttributes;s&&(a.subplot?n.extendFlat(r[o.attributes.subplot.dflt],s):n.extendFlat(r,s))}return r}e.exports=function(t,e){void 0===t&&(t=[]),void 0===e&&(e={});var r,c,h=a.get(),p=[],m={_context:n.extendFlat({},o)};l(t)?(m.data=n.extendDeep([],t),r=t):(m.data=[],r=[],p.push(d("array","data"))),s(e)?(m.layout=n.extendDeep({},e),c=e):(m.layout={},c={},arguments.length>1&&p.push(d("object","layout"))),i.supplyDefaults(m);for(var g=m._fullData,v=r.length,y=0;y<v;y++){var x=r[y],b=["data",y];if(s(x)){var _=g[y],w=_.type,T=h.traces[w].attributes;T.type={valType:"enumerated",values:[w]},!1===_.visible&&!1!==x.visible&&p.push(d("invisible",b)),u(x,_,T,p,b);var k=x.transforms,A=_.transforms;if(k){l(k)||p.push(d("array",b,["transforms"])),b.push("transforms");for(var M=0;M<k.length;M++){var S=["transforms",M],E=k[M].type;if(s(k[M])){var L=h.transforms[E]?h.transforms[E].attributes:{};L.type={valType:"enumerated",values:Object.keys(h.transforms)},u(k[M],A[M],L,p,b,S)}else p.push(d("object",b,S))}}}else p.push(d("object",b))}var C=m._fullLayout,P=f(h,g);return u(c,C,P,p,"layout"),0===p.length?void 0:p};var h={object:function(t,e){return("layout"===t&&""===e?"The layout argument":"data"===t[0]&&""===e?"Trace "+t[1]+" in the data argument":p(t)+"key "+e)+" must be linked to an object container"},array:function(t,e){return("data"===t?"The data argument":p(t)+"key "+e)+" must be linked to an array container"},schema:function(t,e){return p(t)+"key "+e+" is not part of the schema"},unused:function(t,e,r){var n=s(r)?"container":"key";return p(t)+n+" "+e+" did not get coerced"},dynamic:function(t,e,r,n){return[p(t)+"key",e,"(set to '"+r+"')","got reset to","'"+n+"'","during defaults."].join(" ")},invisible:function(t,e){return(e?p(t)+"item "+e:"Trace "+t[1])+" got defaulted to be not visible"},value:function(t,e,r){return[p(t)+"key "+e,"is set to an invalid value ("+r+")"].join(" ")}};function p(t){return l(t)?"In data trace "+t[1]+", ":"In "+t+", "}function d(t,e,r,i,a){var o,s;r=r||"",l(e)?(o=e[0],s=e[1]):(o=e,s=null);var c=function(t){if(!l(t))return String(t);for(var e="",r=0;r<t.length;r++){var n=t[r];"number"==typeof n?e=e.substr(0,e.length-1)+"["+n+"]":e+=n,r<t.length-1&&(e+=".")}return e}(r),u=h[t](e,c,i,a);return n.log(u),{code:t,container:o,trace:s,path:r,astr:c,msg:u}}function m(t,e){var r=y(e),n=r.keyMinusId,i=r.id;return!!(n in t&&t[n]._isSubplotObj&&i)||e in t}function g(t,e){return e in t?t[e]:t[y(e).keyMinusId]}var v=n.counterRegex("([a-z]+)");function y(t){var e=t.match(v);return{keyMinusId:e&&e[1],id:e&&e[2]}}},{"../lib":503,"../plots/plots":619,"./plot_config":541,"./plot_schema":542}],548:[function(t,e,r){"use strict";e.exports={mode:{valType:"enumerated",dflt:"afterall",values:["immediate","next","afterall"]},direction:{valType:"enumerated",values:["forward","reverse"],dflt:"forward"},fromcurrent:{valType:"boolean",dflt:!1},frame:{duration:{valType:"number",min:0,dflt:500},redraw:{valType:"boolean",dflt:!0}},transition:{duration:{valType:"number",min:0,dflt:500,editType:"none"},easing:{valType:"enumerated",dflt:"cubic-in-out",values:["linear","quad","cubic","sin","exp","circle","elastic","back","bounce","linear-in","quad-in","cubic-in","sin-in","exp-in","circle-in","elastic-in","back-in","bounce-in","linear-out","quad-out","cubic-out","sin-out","exp-out","circle-out","elastic-out","back-out","bounce-out","linear-in-out","quad-in-out","cubic-in-out","sin-in-out","exp-in-out","circle-in-out","elastic-in-out","back-in-out","bounce-in-out"],editType:"none"},ordering:{valType:"enumerated",values:["layout first","traces first"],dflt:"layout first",editType:"none"}}}},{}],549:[function(t,e,r){"use strict";var n=t("../lib"),i=t("../plot_api/plot_template");e.exports=function(t,e,r){var a,o,s=r.name,l=r.inclusionAttr||"visible",c=e[s],u=n.isArrayOrTypedArray(t[s])?t[s]:[],f=e[s]=[],h=i.arrayTemplater(e,s,l);for(a=0;a<u.length;a++){var p=u[a];n.isPlainObject(p)?o=h.newItem(p):(o=h.newItem({}))[l]=!1,o._index=a,!1!==o[l]&&r.handleItemDefaults(p,o,e,r),f.push(o)}var d=h.defaultItems();for(a=0;a<d.length;a++)(o=d[a])._index=f.length,r.handleItemDefaults({},o,e,r,{}),f.push(o);if(n.isArrayOrTypedArray(c)){var m=Math.min(c.length,f.length);for(a=0;a<m;a++)n.relinkPrivateKeys(f[a],c[a])}return f}},{"../lib":503,"../plot_api/plot_template":543}],550:[function(t,e,r){"use strict";var n=t("./font_attributes"),i=t("../components/fx/attributes");e.exports={type:{valType:"enumerated",values:[],dflt:"scatter",editType:"calc+clearAxisTypes",_noTemplating:!0},visible:{valType:"enumerated",values:[!0,!1,"legendonly"],dflt:!0,editType:"calc"},showlegend:{valType:"boolean",dflt:!0,editType:"style"},legendgroup:{valType:"string",dflt:"",editType:"style"},legendgrouptitle:{text:{valType:"string",dflt:"",editType:"style"},font:n({editType:"style"}),editType:"style"},legendrank:{valType:"number",dflt:1e3,editType:"style"},opacity:{valType:"number",min:0,max:1,dflt:1,editType:"style"},name:{valType:"string",editType:"style"},uid:{valType:"string",editType:"plot",anim:!0},ids:{valType:"data_array",editType:"calc",anim:!0},customdata:{valType:"data_array",editType:"calc"},meta:{valType:"any",arrayOk:!0,editType:"plot"},selectedpoints:{valType:"any",editType:"calc"},hoverinfo:{valType:"flaglist",flags:["x","y","z","text","name"],extras:["all","none","skip"],arrayOk:!0,dflt:"all",editType:"none"},hoverlabel:i.hoverlabel,stream:{token:{valType:"string",noBlank:!0,strict:!0,editType:"calc"},maxpoints:{valType:"number",min:0,max:1e4,dflt:500,editType:"calc"},editType:"calc"},transforms:{_isLinkedToArray:"transform",editType:"calc"},uirevision:{valType:"any",editType:"none"}}},{"../components/fx/attributes":397,"./font_attributes":585}],551:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=i.dateTime2ms,o=i.incrementMonth,s=t("../../constants/numerical").ONEAVGMONTH;e.exports=function(t,e,r,i){if("date"!==e.type)return{vals:i};var l=t[r+"periodalignment"];if(!l)return{vals:i};var c,u=t[r+"period"];if(n(u)){if((u=+u)<=0)return{vals:i}}else if("string"==typeof u&&"M"===u.charAt(0)){var f=+u.substring(1);if(!(f>0&&Math.round(f)===f))return{vals:i};c=f}for(var h=e.calendar,p="start"===l,d="end"===l,m=t[r+"period0"],g=a(m,h)||0,v=[],y=[],x=[],b=i.length,_=0;_<b;_++){var w,T,k,A=i[_];if(c){for(w=Math.round((A-g)/(c*s)),k=o(g,c*w,h);k>A;)k=o(k,-c,h);for(;k<=A;)k=o(k,c,h);T=o(k,-c,h)}else{for(k=g+(w=Math.round((A-g)/u))*u;k>A;)k-=u;for(;k<=A;)k+=u;T=k-u}v[_]=p?T:d?k:(T+k)/2,y[_]=T,x[_]=k}return{vals:v,starts:y,ends:x}}},{"../../constants/numerical":479,"../../lib":503,"fast-isnumeric":190}],552:[function(t,e,r){"use strict";e.exports={xaxis:{valType:"subplotid",dflt:"x",editType:"calc+clearAxisTypes"},yaxis:{valType:"subplotid",dflt:"y",editType:"calc+clearAxisTypes"}}},{}],553:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("fast-isnumeric"),a=t("../../lib"),o=t("../../constants/numerical").FP_SAFE,s=t("../../registry"),l=t("../../components/drawing"),c=t("./axis_ids"),u=c.getFromId,f=c.isLinked;function h(t,e){var r,n,i=[],o=t._fullLayout,s=d(o,e,0),l=d(o,e,1),c=m(t,e),u=c.min,f=c.max;if(0===u.length||0===f.length)return a.simpleMap(e.range,e.r2l);var h=u[0].val,g=f[0].val;for(r=1;r<u.length&&h===g;r++)h=Math.min(h,u[r].val);for(r=1;r<f.length&&h===g;r++)g=Math.max(g,f[r].val);var v=!1;if(e.range){var y=a.simpleMap(e.range,e.r2l);v=y[1]<y[0]}"reversed"===e.autorange&&(v=!0,e.autorange=!0);var x,b,_,w,T,k,A=e.rangemode,M="tozero"===A,S="nonnegative"===A,E=e._length,L=E/10,C=0;for(r=0;r<u.length;r++)for(x=u[r],n=0;n<f.length;n++)(k=(b=f[n]).val-x.val-p(e,x.val,b.val))>0&&((T=E-s(x)-l(b))>L?k/T>C&&(_=x,w=b,C=k/T):k/E>C&&(_={val:x.val,nopad:1},w={val:b.val,nopad:1},C=k/E));if(h===g){var P=h-1,I=h+1;if(M)if(0===h)i=[0,1];else{var O=(h>0?f:u).reduce((function(t,e){return Math.max(t,l(e))}),0),z=h/(1-Math.min(.5,O/E));i=h>0?[0,z]:[z,0]}else i=S?[Math.max(0,P),Math.max(1,I)]:[P,I]}else M?(_.val>=0&&(_={val:0,nopad:1}),w.val<=0&&(w={val:0,nopad:1})):S&&(_.val-C*s(_)<0&&(_={val:0,nopad:1}),w.val<=0&&(w={val:1,nopad:1})),C=(w.val-_.val-p(e,x.val,b.val))/(E-s(_)-l(w)),i=[_.val-C*s(_),w.val+C*l(w)];return v&&i.reverse(),a.simpleMap(i,e.l2r||Number)}function p(t,e,r){var n=0;if(t.rangebreaks)for(var i=t.locateBreaks(e,r),a=0;a<i.length;a++){var o=i[a];n+=o.max-o.min}return n}function d(t,e,r){var i=.05*e._length,o=e._anchorAxis||{};if(-1!==(e.ticklabelposition||"").indexOf("inside")||-1!==(o.ticklabelposition||"").indexOf("inside")){var s="reversed"===e.autorange;if(!s){var c=a.simpleMap(e.range,e.r2l);s=c[1]<c[0]}s&&(r=!r)}var u=0;return f(t,e._id)||(u=function(t,e,r){var i=0,o="x"===e._id.charAt(0);for(var s in t._plots){var c=t._plots[s];if(e._id===c.xaxis._id||e._id===c.yaxis._id){var u=(o?c.yaxis:c.xaxis)||{};if(-1!==(u.ticklabelposition||"").indexOf("inside")&&(!r&&("left"===u.side||"bottom"===u.side)||r&&("top"===u.side||"right"===u.side))){if(u._vals){var f=a.deg2rad(u._tickAngles[u._id+"tick"]||0),h=Math.abs(Math.cos(f)),p=Math.abs(Math.sin(f));if(!u._vals[0].bb){var d=u._id+"tick";u._selections[d].each((function(t){var e=n.select(this);e.select(".text-math-group").empty()&&(t.bb=l.bBox(e.node()))}))}for(var m=0;m<u._vals.length;m++){var g=u._vals[m].bb;if(g){var v=6+g.width,y=6+g.height;i=Math.max(i,o?Math.max(v*h,y*p):Math.max(y*h,v*p))}}}"inside"===u.ticks&&"inside"===u.ticklabelposition&&(i+=u.ticklen||0)}}}return i}(t,e,r)),i=Math.max(u,i),"domain"===e.constrain&&e._inputDomain&&(i*=(e._inputDomain[1]-e._inputDomain[0])/(e.domain[1]-e.domain[0])),function(t){return t.nopad?0:t.pad+(t.extrapad?i:u)}}e.exports={getAutoRange:h,makePadFn:d,doAutoRange:function(t,e,r){if(e.setScale(),e.autorange){e.range=r?r.slice():h(t,e),e._r=e.range.slice(),e._rl=a.simpleMap(e._r,e.r2l);var n=e._input,i={};i[e._attr+".range"]=e.range,i[e._attr+".autorange"]=e.autorange,s.call("_storeDirectGUIEdit",t.layout,t._fullLayout._preGUI,i),n.range=e.range.slice(),n.autorange=e.autorange}var o=e._anchorAxis;if(o&&o.rangeslider){var l=o.rangeslider[e._name];l&&"auto"===l.rangemode&&(l.range=h(t,e)),o._input.rangeslider[e._name]=a.extendFlat({},l)}},findExtremes:function(t,e,r){r||(r={});t._m||t.setScale();var n,a,s,l,c,u,f,h,p,d=[],m=[],y=e.length,b=r.padded||!1,_=r.tozero&&("linear"===t.type||"-"===t.type),w="log"===t.type,T=!1,k=r.vpadLinearized||!1;function A(t){if(Array.isArray(t))return T=!0,function(e){return Math.max(Number(t[e]||0),0)};var e=Math.max(Number(t||0),0);return function(){return e}}var M=A((t._m>0?r.ppadplus:r.ppadminus)||r.ppad||0),S=A((t._m>0?r.ppadminus:r.ppadplus)||r.ppad||0),E=A(r.vpadplus||r.vpad),L=A(r.vpadminus||r.vpad);if(!T){if(h=1/0,p=-1/0,w)for(n=0;n<y;n++)(a=e[n])<h&&a>0&&(h=a),a>p&&a<o&&(p=a);else for(n=0;n<y;n++)(a=e[n])<h&&a>-o&&(h=a),a>p&&a<o&&(p=a);e=[h,p],y=2}var C={tozero:_,extrapad:b};function P(r){s=e[r],i(s)&&(u=M(r),f=S(r),k?(l=t.c2l(s)-L(r),c=t.c2l(s)+E(r)):(h=s-L(r),p=s+E(r),w&&h<p/10&&(h=p/10),l=t.c2l(h),c=t.c2l(p)),_&&(l=Math.min(0,l),c=Math.max(0,c)),x(l)&&g(d,l,f,C),x(c)&&v(m,c,u,C))}var I=Math.min(6,y);for(n=0;n<I;n++)P(n);for(n=y-1;n>=I;n--)P(n);return{min:d,max:m,opts:r}},concatExtremes:m};function m(t,e,r){var n,i,a,o=e._id,s=t._fullData,l=t._fullLayout,c=[],f=[];function h(t,e){for(n=0;n<e.length;n++){var r=t[e[n]],s=(r._extremes||{})[o];if(!0===r.visible&&s){for(i=0;i<s.min.length;i++)a=s.min[i],g(c,a.val,a.pad,{extrapad:a.extrapad});for(i=0;i<s.max.length;i++)a=s.max[i],v(f,a.val,a.pad,{extrapad:a.extrapad})}}}if(h(s,e._traceIndices),h(l.annotations||[],e._annIndices||[]),h(l.shapes||[],e._shapeIndices||[]),e._matchGroup&&!r)for(var p in e._matchGroup)if(p!==e._id){var d=u(t,p),y=m(t,d,!0),x=e._length/d._length;for(i=0;i<y.min.length;i++)a=y.min[i],g(c,a.val,a.pad*x,{extrapad:a.extrapad});for(i=0;i<y.max.length;i++)a=y.max[i],v(f,a.val,a.pad*x,{extrapad:a.extrapad})}return{min:c,max:f}}function g(t,e,r,n){y(t,e,r,n,b)}function v(t,e,r,n){y(t,e,r,n,_)}function y(t,e,r,n,i){for(var a=n.tozero,o=n.extrapad,s=!0,l=0;l<t.length&&s;l++){var c=t[l];if(i(c.val,e)&&c.pad>=r&&(c.extrapad||!o)){s=!1;break}i(e,c.val)&&c.pad<=r&&(o||!c.extrapad)&&(t.splice(l,1),l--)}if(s){var u=a&&0===e;t.push({val:e,pad:u?0:r,extrapad:!u&&o})}}function x(t){return i(t)&&Math.abs(t)<o}function b(t,e){return t<=e}function _(t,e){return t>=e}},{"../../components/drawing":388,"../../constants/numerical":479,"../../lib":503,"../../registry":638,"./axis_ids":558,"@plotly/d3":58,"fast-isnumeric":190}],554:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("fast-isnumeric"),a=t("../../plots/plots"),o=t("../../registry"),s=t("../../lib"),l=s.strTranslate,c=t("../../lib/svg_text_utils"),u=t("../../components/titles"),f=t("../../components/color"),h=t("../../components/drawing"),p=t("./layout_attributes"),d=t("./clean_ticks"),m=t("../../constants/numerical"),g=m.ONEMAXYEAR,v=m.ONEAVGYEAR,y=m.ONEMINYEAR,x=m.ONEMAXQUARTER,b=m.ONEAVGQUARTER,_=m.ONEMINQUARTER,w=m.ONEMAXMONTH,T=m.ONEAVGMONTH,k=m.ONEMINMONTH,A=m.ONEWEEK,M=m.ONEDAY,S=M/2,E=m.ONEHOUR,L=m.ONEMIN,C=m.ONESEC,P=m.MINUS_SIGN,I=m.BADNUM,O={K:"zeroline"},z={K:"gridline",L:"path"},D={K:"minor-gridline",L:"path"},R={K:"tick",L:"path"},F={K:"tick",L:"text"},B=t("../../constants/alignment"),N=B.MID_SHIFT,j=B.CAP_SHIFT,U=B.LINE_SPACING,V=B.OPPOSITE_SIDE,H=e.exports={};H.setConvert=t("./set_convert");var q=t("./axis_autotype"),G=t("./axis_ids"),Y=G.idSort,W=G.isLinked;H.id2name=G.id2name,H.name2id=G.name2id,H.cleanId=G.cleanId,H.list=G.list,H.listIds=G.listIds,H.getFromId=G.getFromId,H.getFromTrace=G.getFromTrace;var X=t("./autorange");H.getAutoRange=X.getAutoRange,H.findExtremes=X.findExtremes;function Z(t){var e=1e-4*(t[1]-t[0]);return[t[0]-e,t[1]+e]}H.coerceRef=function(t,e,r,n,i,a){var o=n.charAt(n.length-1),l=r._fullLayout._subplots[o+"axis"],c=n+"ref",u={};return i||(i=l[0]||("string"==typeof a?a:a[0])),a||(a=i),l=l.concat(l.map((function(t){return t+" domain"}))),u[c]={valType:"enumerated",values:l.concat(a?"string"==typeof a?[a]:a:[]),dflt:i},s.coerce(t,e,u,c)},H.getRefType=function(t){return void 0===t?t:"paper"===t?"paper":"pixel"===t?"pixel":/( domain)$/.test(t)?"domain":"range"},H.coercePosition=function(t,e,r,n,i,a){var o,l;if("range"!==H.getRefType(n))o=s.ensureNumber,l=r(i,a);else{var c=H.getFromId(e,n);l=r(i,a=c.fraction2r(a)),o=c.cleanPos}t[i]=o(l)},H.cleanPosition=function(t,e,r){return("paper"===r||"pixel"===r?s.ensureNumber:H.getFromId(e,r).cleanPos)(t)},H.redrawComponents=function(t,e){e=e||H.listIds(t);var r=t._fullLayout;function n(n,i,a,s){for(var l=o.getComponentMethod(n,i),c={},u=0;u<e.length;u++)for(var f=r[H.id2name(e[u])][a],h=0;h<f.length;h++){var p=f[h];if(!c[p]&&(l(t,p),c[p]=1,s))return}}n("annotations","drawOne","_annIndices"),n("shapes","drawOne","_shapeIndices"),n("images","draw","_imgIndices",!0)};var J=H.getDataConversions=function(t,e,r,n){var i,a="x"===r||"y"===r||"z"===r?r:n;if(Array.isArray(a)){if(i={type:q(n,void 0,{autotypenumbers:t._fullLayout.autotypenumbers}),_categories:[]},H.setConvert(i),"category"===i.type)for(var o=0;o<n.length;o++)i.d2c(n[o])}else i=H.getFromTrace(t,e,a);return i?{d2c:i.d2c,c2d:i.c2d}:"ids"===a?{d2c:Q,c2d:Q}:{d2c:K,c2d:K}};function K(t){return+t}function Q(t){return String(t)}function $(t,e){return Math.abs((t/e+.5)%1-.5)<.001}function tt(t,e){return Math.abs(t/e-1)<.001}function et(t){return+t.substring(1)}function rt(t){var e=Z(s.simpleMap(t.range,t.r2l)),r=Math.min(e[0],e[1]),n=Math.max(e[0],e[1]),i="category"===t.type?t.d2l_noadd:t.d2l;"log"===t.type&&"L"!==String(t.dtick).charAt(0)&&(t.dtick="L"+Math.pow(10,Math.floor(Math.min(t.range[0],t.range[1]))-1));for(var a=[],o=0;o<=1;o++)if(!o||t.minor){var l=o?t.minor.tickvals:t.tickvals,c=o?[]:t.ticktext;if(l){Array.isArray(c)||(c=[]);for(var u=0;u<l.length;u++){var f=i(l[u]);if(f>r&&f<n){var h=void 0===c[u]?H.tickText(t,f):ht(t,f,String(c[u]));o&&(h.minor=!0,h.text=""),a.push(h)}}}}return t.rangebreaks&&(a=a.filter((function(e){return t.maskBreaks(e.x)!==I}))),a}H.getDataToCoordFunc=function(t,e,r,n){return J(t,e,r,n).d2c},H.counterLetter=function(t){var e=t.charAt(0);return"x"===e?"y":"y"===e?"x":void 0},H.minDtick=function(t,e,r,n){-1===["log","category","multicategory"].indexOf(t.type)&&n?void 0===t._minDtick?(t._minDtick=e,t._forceTick0=r):t._minDtick&&((t._minDtick/e+1e-6)%1<2e-6&&((r-t._forceTick0)/e%1+1.000001)%1<2e-6?(t._minDtick=e,t._forceTick0=r):((e/t._minDtick+1e-6)%1>2e-6||((r-t._forceTick0)/t._minDtick%1+1.000001)%1>2e-6)&&(t._minDtick=0)):t._minDtick=0},H.saveRangeInitial=function(t,e){for(var r=H.list(t,"",!0),n=!1,i=0;i<r.length;i++){var a=r[i],o=void 0===a._rangeInitial,s=o||!(a.range[0]===a._rangeInitial[0]&&a.range[1]===a._rangeInitial[1]);(o&&!1===a.autorange||e&&s)&&(a._rangeInitial=a.range.slice(),n=!0)}return n},H.saveShowSpikeInitial=function(t,e){for(var r=H.list(t,"",!0),n=!1,i="on",a=0;a<r.length;a++){var o=r[a],s=void 0===o._showSpikeInitial,l=s||!(o.showspikes===o._showspikes);(s||e&&l)&&(o._showSpikeInitial=o.showspikes,n=!0),"on"!==i||o.showspikes||(i="off")}return t._fullLayout._cartesianSpikesEnabled=i,n},H.autoBin=function(t,e,r,n,a,o){var l,c=s.aggNums(Math.min,null,t),u=s.aggNums(Math.max,null,t);if("category"===e.type||"multicategory"===e.type)return{start:c-.5,end:u+.5,size:Math.max(1,Math.round(o)||1),_dataSpan:u-c};if(a||(a=e.calendar),l="log"===e.type?{type:"linear",range:[c,u]}:{type:e.type,range:s.simpleMap([c,u],e.c2r,0,a),calendar:a},H.setConvert(l),o=o&&d.dtick(o,l.type))l.dtick=o,l.tick0=d.tick0(void 0,l.type,a);else{var f;if(r)f=(u-c)/r;else{var h=s.distinctVals(t),p=Math.pow(10,Math.floor(Math.log(h.minDiff)/Math.LN10)),m=p*s.roundUp(h.minDiff/p,[.9,1.9,4.9,9.9],!0);f=Math.max(m,2*s.stdev(t)/Math.pow(t.length,n?.25:.4)),i(f)||(f=1)}H.autoTicks(l,f)}var g,v=l.dtick,y=H.tickIncrement(H.tickFirst(l),v,"reverse",a);if("number"==typeof v)g=(y=function(t,e,r,n,a){var o=0,s=0,l=0,c=0;function u(e){return(1+100*(e-t)/r.dtick)%100<2}for(var f=0;f<e.length;f++)e[f]%1==0?l++:i(e[f])||c++,u(e[f])&&o++,u(e[f]+r.dtick/2)&&s++;var h=e.length-c;if(l===h&&"date"!==r.type)r.dtick<1?t=n-.5*r.dtick:(t-=.5)+r.dtick<n&&(t+=r.dtick);else if(s<.1*h&&(o>.3*h||u(n)||u(a))){var p=r.dtick/2;t+=t+p<n?p:-p}return t}(y,t,l,c,u))+(1+Math.floor((u-y)/v))*v;else for("M"===l.dtick.charAt(0)&&(y=function(t,e,r,n,i){var a=s.findExactDates(e,i);if(a.exactDays>.8){var o=Number(r.substr(1));a.exactYears>.8&&o%12==0?t=H.tickIncrement(t,"M6","reverse")+1.5*M:a.exactMonths>.8?t=H.tickIncrement(t,"M1","reverse")+15.5*M:t-=S;var l=H.tickIncrement(t,r);if(l<=n)return l}return t}(y,t,v,c,a)),g=y,0;g<=u;)g=H.tickIncrement(g,v,!1,a);return{start:e.c2r(y,0,a),end:e.c2r(g,0,a),size:v,_dataSpan:u-c}},H.prepMinorTicks=function(t,e,r){if(!e.minor.dtick){delete t.dtick;var n,a=e.dtick&&i(e._tmin);if(a){var o=H.tickIncrement(e._tmin,e.dtick,!0);n=[e._tmin,.99*o+.01*e._tmin]}else{var l=s.simpleMap(e.range,e.r2l);n=[l[0],.8*l[0]+.2*l[1]]}if(t.range=s.simpleMap(n,e.l2r),t._isMinor=!0,H.prepTicks(t,r),a){var c=i(e.dtick),u=i(t.dtick),f=c?e.dtick:+e.dtick.substring(1),h=u?t.dtick:+t.dtick.substring(1);c&&u?$(f,h)?f===2*A&&h===2*M&&(t.dtick=A):f===2*A&&h===3*M?t.dtick=A:f!==A||(e._input.minor||{}).nticks?tt(f/h,2.5)?t.dtick=f/2:t.dtick=f:t.dtick=M:"M"===String(e.dtick).charAt(0)?u?t.dtick="M1":$(f,h)?f>=12&&2===h&&(t.dtick="M3"):t.dtick=e.dtick:"L"===String(t.dtick).charAt(0)?"L"===String(e.dtick).charAt(0)?$(f,h)||(t.dtick=tt(f/h,2.5)?e.dtick/2:e.dtick):t.dtick="D1":"D2"===t.dtick&&+e.dtick>1&&(t.dtick=1)}t.range=e.range}void 0===e.minor._tick0Init&&(t.tick0=e.tick0)},H.prepTicks=function(t,e){var r=s.simpleMap(t.range,t.r2l,void 0,void 0,e);if("auto"===t.tickmode||!t.dtick){var n,a=t.nticks;a||("category"===t.type||"multicategory"===t.type?(n=t.tickfont?s.bigFont(t.tickfont.size||12):15,a=t._length/n):(n="y"===t._id.charAt(0)?40:80,a=s.constrain(t._length/n,4,9)+1),"radialaxis"===t._name&&(a*=2)),t.minor&&"array"!==t.minor.tickmode||"array"===t.tickmode&&(a*=100),t._roughDTick=Math.abs(r[1]-r[0])/a,H.autoTicks(t,t._roughDTick),t._minDtick>0&&t.dtick<2*t._minDtick&&(t.dtick=t._minDtick,t.tick0=t.l2r(t._forceTick0))}"period"===t.ticklabelmode&&function(t){var e;function r(){return!(i(t.dtick)||"M"!==t.dtick.charAt(0))}var n=r(),a=H.getTickFormat(t);if(a){var o=t._dtickInit!==t.dtick;/%[fLQsSMX]/.test(a)||(/%[HI]/.test(a)?(e=E,o&&!n&&t.dtick<E&&(t.dtick=E)):/%p/.test(a)?(e=S,o&&!n&&t.dtick<S&&(t.dtick=S)):/%[Aadejuwx]/.test(a)?(e=M,o&&!n&&t.dtick<M&&(t.dtick=M)):/%[UVW]/.test(a)?(e=A,o&&!n&&t.dtick<A&&(t.dtick=A)):/%[Bbm]/.test(a)?(e=T,o&&(n?et(t.dtick)<1:t.dtick<k)&&(t.dtick="M1")):/%[q]/.test(a)?(e=b,o&&(n?et(t.dtick)<3:t.dtick<_)&&(t.dtick="M3")):/%[Yy]/.test(a)&&(e=v,o&&(n?et(t.dtick)<12:t.dtick<y)&&(t.dtick="M12")))}(n=r())&&t.tick0===t._dowTick0&&(t.tick0=t._rawTick0);t._definedDelta=e}(t),t.tick0||(t.tick0="date"===t.type?"2000-01-01":0),"date"===t.type&&t.dtick<.1&&(t.dtick=.1),ft(t)},H.calcTicks=function(t,e){for(var r,n,a=t.type,o=t.calendar,l=t.ticklabelstep,c="period"===t.ticklabelmode,u=s.simpleMap(t.range,t.r2l,void 0,void 0,e),f=u[1]<u[0],h=Math.min(u[0],u[1]),p=Math.max(u[0],u[1]),d=Math.max(1e3,t._length||0),m=[],L=[],C=[],P=[],O=t.minor&&(t.minor.ticks||t.minor.showgrid),z=1;z>=(O?0:1);z--){var D=!z;z?(t._dtickInit=t.dtick,t._tick0Init=t.tick0):(t.minor._dtickInit=t.minor.dtick,t.minor._tick0Init=t.minor.tick0);var R=z?t:s.extendFlat({},t,t.minor);if(D?H.prepMinorTicks(R,t,e):H.prepTicks(R,e),"array"!==R.tickmode){var F=Z(u),B=F[0],N=F[1],j=i(R.dtick),U="log"===a&&!(j||"L"===R.dtick.charAt(0)),V=H.tickFirst(R,e);if(z){if(t._tmin=V,V<B!==f)break;"category"!==a&&"multicategory"!==a||(N=f?Math.max(-.5,N):Math.min(t._categories.length-.5,N))}var q,G,Y=null,W=V;if(z)j?G=t.dtick:"date"===a?"string"==typeof t.dtick&&"M"===t.dtick.charAt(0)&&(G=T*t.dtick.substring(1)):G=t._roughDTick,q=Math.round((t.r2l(W)-t.r2l(t.tick0))/G)-1;var X=R.dtick;for(R.rangebreaks&&R._tick0Init!==R.tick0&&(W=Ct(W,t),f||(W=H.tickIncrement(W,X,!f,o))),z&&c&&(W=H.tickIncrement(W,X,!f,o),q--);f?W>=N:W<=N;W=H.tickIncrement(W,X,f,o)){if(z&&q++,R.rangebreaks&&!f){if(W<B)continue;if(R.maskBreaks(W)===I&&Ct(W,R)>=p)break}if(C.length>d||W===Y)break;Y=W;var J={value:W};z?(U&&W!==(0|W)&&(J.simpleLabel=!0),l>1&&q%l&&(J.skipLabel=!0),C.push(J)):(J.minor=!0,P.push(J))}}else z?(C=[],m=rt(t)):(P=[],L=rt(t))}if(O&&!("inside"===t.minor.ticks&&"outside"===t.ticks||"outside"===t.minor.ticks&&"inside"===t.ticks)){for(var K=C.map((function(t){return t.value})),Q=[],$=0;$<P.length;$++){var tt=P[$],et=tt.value;if(-1===K.indexOf(et)){for(var nt=!1,it=0;!nt&&it<C.length;it++)1e7+C[it].value===1e7+et&&(nt=!0);nt||Q.push(tt)}}P=Q}if(c&&function(t,e,r){for(var n=0;n<t.length;n++){var i=t[n].value,a=n,o=n+1;n<t.length-1?(a=n,o=n+1):n>0?(a=n-1,o=n):(a=n,o=n);var s,l=t[a].value,c=t[o].value,u=Math.abs(c-l),f=r||u,h=0;f>=y?h=u>=y&&u<=g?u:v:r===b&&f>=_?h=u>=_&&u<=x?u:b:f>=k?h=u>=k&&u<=w?u:T:r===A&&f>=A?h=A:f>=M?h=M:r===S&&f>=S?h=S:r===E&&f>=E&&(h=E),h>=u&&(h=u,s=!0);var p=i+h;if(e.rangebreaks&&h>0){for(var d=0,m=0;m<84;m++){var L=(m+.5)/84;e.maskBreaks(i*(1-L)+L*p)!==I&&d++}(h*=d/84)||(t[n].drop=!0),s&&u>A&&(h=u)}(h>0||0===n)&&(t[n].periodX=i+h/2)}}(C,t,t._definedDelta),t.rangebreaks){var at="y"===t._id.charAt(0),ot=1;"auto"===t.tickmode&&(ot=t.tickfont?t.tickfont.size:12);var st=NaN;for(r=C.length-1;r>-1;r--)if(C[r].drop)C.splice(r,1);else{C[r].value=Ct(C[r].value,t);var lt=t.c2p(C[r].value);(at?st>lt-ot:st<lt+ot)?C.splice(f?r+1:r,1):st=lt}}Lt(t)&&360===Math.abs(u[1]-u[0])&&C.pop(),t._tmax=(C[C.length-1]||{}).value,t._prevDateHead="",t._inCalcTicks=!0;var ct,ut,ft=function(e){e.text="",t._prevDateHead=n};for(C=C.concat(P),r=0;r<C.length;r++){var ht=C[r].minor,pt=C[r].value;ht?L.push({x:pt,minor:!0}):(n=t._prevDateHead,ct=H.tickText(t,pt,!1,C[r].simpleLabel),void 0!==(ut=C[r].periodX)&&(ct.periodX=ut,(ut>p||ut<h)&&(ut>p&&(ct.periodX=p),ut<h&&(ct.periodX=h),ft(ct))),C[r].skipLabel&&ft(ct),m.push(ct))}return m=m.concat(L),t._inCalcTicks=!1,c&&m.length&&(m[0].noTick=!0),m};var nt=[2,5,10],it=[1,2,3,6,12],at=[1,2,5,10,15,30],ot=[1,2,3,7,14],st=[-.046,0,.301,.477,.602,.699,.778,.845,.903,.954,1],lt=[-.301,0,.301,.699,1],ct=[15,30,45,90,180];function ut(t,e,r){return e*s.roundUp(t/e,r)}function ft(t){var e=t.dtick;if(t._tickexponent=0,i(e)||"string"==typeof e||(e=1),"category"!==t.type&&"multicategory"!==t.type||(t._tickround=null),"date"===t.type){var r=t.r2l(t.tick0),n=t.l2r(r).replace(/(^-|i)/g,""),a=n.length;if("M"===String(e).charAt(0))a>10||"01-01"!==n.substr(5)?t._tickround="d":t._tickround=+e.substr(1)%12==0?"y":"m";else if(e>=M&&a<=10||e>=15*M)t._tickround="d";else if(e>=L&&a<=16||e>=E)t._tickround="M";else if(e>=C&&a<=19||e>=L)t._tickround="S";else{var o=t.l2r(r+e).replace(/^-/,"").length;t._tickround=Math.max(a,o)-20,t._tickround<0&&(t._tickround=4)}}else if(i(e)||"L"===e.charAt(0)){var s=t.range.map(t.r2d||Number);i(e)||(e=Number(e.substr(1))),t._tickround=2-Math.floor(Math.log(e)/Math.LN10+.01);var l=Math.max(Math.abs(s[0]),Math.abs(s[1])),c=Math.floor(Math.log(l)/Math.LN10+.01),u=void 0===t.minexponent?3:t.minexponent;Math.abs(c)>u&&(dt(t.exponentformat)&&!mt(c)?t._tickexponent=3*Math.round((c-1)/3):t._tickexponent=c)}else t._tickround=null}function ht(t,e,r){var n=t.tickfont||{};return{x:e,dx:0,dy:0,text:r||"",fontSize:n.size,font:n.family,fontColor:n.color}}H.autoTicks=function(t,e,r){var n;function a(t){return Math.pow(t,Math.floor(Math.log(e)/Math.LN10))}if("date"===t.type){t.tick0=s.dateTick0(t.calendar,0);var o=2*e;if(o>v)e/=v,n=a(10),t.dtick="M"+12*ut(e,n,nt);else if(o>T)e/=T,t.dtick="M"+ut(e,1,it);else if(o>M){if(t.dtick=ut(e,M,t._hasDayOfWeekBreaks?[1,2,7,14]:ot),!r){var l=H.getTickFormat(t),c="period"===t.ticklabelmode;c&&(t._rawTick0=t.tick0),/%[uVW]/.test(l)?t.tick0=s.dateTick0(t.calendar,2):t.tick0=s.dateTick0(t.calendar,1),c&&(t._dowTick0=t.tick0)}}else o>E?t.dtick=ut(e,E,it):o>L?t.dtick=ut(e,L,at):o>C?t.dtick=ut(e,C,at):(n=a(10),t.dtick=ut(e,n,nt))}else if("log"===t.type){t.tick0=0;var u=s.simpleMap(t.range,t.r2l);if(t._isMinor&&(e*=1.5),e>.7)t.dtick=Math.ceil(e);else if(Math.abs(u[1]-u[0])<1){var f=1.5*Math.abs((u[1]-u[0])/e);e=Math.abs(Math.pow(10,u[1])-Math.pow(10,u[0]))/f,n=a(10),t.dtick="L"+ut(e,n,nt)}else t.dtick=e>.3?"D2":"D1"}else"category"===t.type||"multicategory"===t.type?(t.tick0=0,t.dtick=Math.ceil(Math.max(e,1))):Lt(t)?(t.tick0=0,n=1,t.dtick=ut(e,n,ct)):(t.tick0=0,n=a(10),t.dtick=ut(e,n,nt));if(0===t.dtick&&(t.dtick=1),!i(t.dtick)&&"string"!=typeof t.dtick){var h=t.dtick;throw t.dtick=1,"ax.dtick error: "+String(h)}},H.tickIncrement=function(t,e,r,a){var o=r?-1:1;if(i(e))return s.increment(t,o*e);var l=e.charAt(0),c=o*Number(e.substr(1));if("M"===l)return s.incrementMonth(t,c,a);if("L"===l)return Math.log(Math.pow(10,t)+c)/Math.LN10;if("D"===l){var u="D2"===e?lt:st,f=t+.01*o,h=s.roundUp(s.mod(f,1),u,r);return Math.floor(f)+Math.log(n.round(Math.pow(10,h),1))/Math.LN10}throw"unrecognized dtick "+String(e)},H.tickFirst=function(t,e){var r=t.r2l||Number,a=s.simpleMap(t.range,r,void 0,void 0,e),o=a[1]<a[0],l=o?Math.floor:Math.ceil,c=Z(a)[0],u=t.dtick,f=r(t.tick0);if(i(u)){var h=l((c-f)/u)*u+f;return"category"!==t.type&&"multicategory"!==t.type||(h=s.constrain(h,0,t._categories.length-1)),h}var p=u.charAt(0),d=Number(u.substr(1));if("M"===p){for(var m,g,v,y=0,x=f;y<10;){if(((m=H.tickIncrement(x,u,o,t.calendar))-c)*(x-c)<=0)return o?Math.min(x,m):Math.max(x,m);g=(c-(x+m)/2)/(m-x),v=p+(Math.abs(Math.round(g))||1)*d,x=H.tickIncrement(x,v,g<0?!o:o,t.calendar),y++}return s.error("tickFirst did not converge",t),x}if("L"===p)return Math.log(l((Math.pow(10,c)-f)/d)*d+f)/Math.LN10;if("D"===p){var b="D2"===u?lt:st,_=s.roundUp(s.mod(c,1),b,o);return Math.floor(c)+Math.log(n.round(Math.pow(10,_),1))/Math.LN10}throw"unrecognized dtick "+String(u)},H.tickText=function(t,e,r,n){var a,o=ht(t,e),l="array"===t.tickmode,c=r||l,u=t.type,f="category"===u?t.d2l_noadd:t.d2l;if(l&&Array.isArray(t.ticktext)){var h=s.simpleMap(t.range,t.r2l),p=(Math.abs(h[1]-h[0])-(t._lBreaks||0))/1e4;for(a=0;a<t.ticktext.length&&!(Math.abs(e-f(t.tickvals[a]))<p);a++);if(a<t.ticktext.length)return o.text=String(t.ticktext[a]),o}function d(n){if(void 0===n)return!0;if(r)return"none"===n;var i={first:t._tmin,last:t._tmax}[n];return"all"!==n&&e!==i}var m=r?"never":"none"!==t.exponentformat&&d(t.showexponent)?"hide":"";if("date"===u?function(t,e,r,n){var a=t._tickround,o=r&&t.hoverformat||H.getTickFormat(t);n&&(a=i(a)?4:{y:"m",m:"d",d:"M",M:"S",S:4}[a]);var l,c=s.formatDate(e.x,o,a,t._dateFormat,t.calendar,t._extraFormat),u=c.indexOf("\n");-1!==u&&(l=c.substr(u+1),c=c.substr(0,u));n&&("00:00:00"===c||"00:00"===c?(c=l,l=""):8===c.length&&(c=c.replace(/:00$/,"")));if(l)if(r)"d"===a?c+=", "+l:c=l+(c?", "+c:"");else if(t._inCalcTicks&&t._prevDateHead===l){var f=Pt(t),h=t._trueSide||t.side;(!f&&"top"===h||f&&"bottom"===h)&&(c+="<br> ")}else t._prevDateHead=l,c+="<br>"+l;e.text=c}(t,o,r,c):"log"===u?function(t,e,r,n,a){var o=t.dtick,l=e.x,c=t.tickformat,u="string"==typeof o&&o.charAt(0);"never"===a&&(a="");n&&"L"!==u&&(o="L3",u="L");if(c||"L"===u)e.text=gt(Math.pow(10,l),t,a,n);else if(i(o)||"D"===u&&s.mod(l+.01,1)<.1){var f=Math.round(l),h=Math.abs(f),p=t.exponentformat;"power"===p||dt(p)&&mt(f)?(e.text=0===f?1:1===f?"10":"10<sup>"+(f>1?"":P)+h+"</sup>",e.fontSize*=1.25):("e"===p||"E"===p)&&h>2?e.text="1"+p+(f>0?"+":P)+h:(e.text=gt(Math.pow(10,l),t,"","fakehover"),"D1"===o&&"y"===t._id.charAt(0)&&(e.dy-=e.fontSize/6))}else{if("D"!==u)throw"unrecognized dtick "+String(o);e.text=String(Math.round(Math.pow(10,s.mod(l,1)))),e.fontSize*=.75}if("D1"===t.dtick){var d=String(e.text).charAt(0);"0"!==d&&"1"!==d||("y"===t._id.charAt(0)?e.dx-=e.fontSize/4:(e.dy+=e.fontSize/2,e.dx+=(t.range[1]>t.range[0]?1:-1)*e.fontSize*(l<0?.5:.25)))}}(t,o,0,c,m):"category"===u?function(t,e){var r=t._categories[Math.round(e.x)];void 0===r&&(r="");e.text=String(r)}(t,o):"multicategory"===u?function(t,e,r){var n=Math.round(e.x),i=t._categories[n]||[],a=void 0===i[1]?"":String(i[1]),o=void 0===i[0]?"":String(i[0]);r?e.text=o+" - "+a:(e.text=a,e.text2=o)}(t,o,r):Lt(t)?function(t,e,r,n,i){if("radians"!==t.thetaunit||r)e.text=gt(e.x,t,i,n);else{var a=e.x/180;if(0===a)e.text="0";else{var o=function(t){function e(t,e){return Math.abs(t-e)<=1e-6}var r=function(t){for(var r=1;!e(Math.round(t*r)/r,t);)r*=10;return r}(t),n=t*r,i=Math.abs(function t(r,n){return e(n,0)?r:t(n,r%n)}(n,r));return[Math.round(n/i),Math.round(r/i)]}(a);if(o[1]>=100)e.text=gt(s.deg2rad(e.x),t,i,n);else{var l=e.x<0;1===o[1]?1===o[0]?e.text="\u03c0":e.text=o[0]+"\u03c0":e.text=["<sup>",o[0],"</sup>","\u2044","<sub>",o[1],"</sub>","\u03c0"].join(""),l&&(e.text=P+e.text)}}}}(t,o,r,c,m):function(t,e,r,n,i){"never"===i?i="":"all"===t.showexponent&&Math.abs(e.x/t.dtick)<1e-6&&(i="hide");e.text=gt(e.x,t,i,n)}(t,o,0,c,m),n||(t.tickprefix&&!d(t.showtickprefix)&&(o.text=t.tickprefix+o.text),t.ticksuffix&&!d(t.showticksuffix)&&(o.text+=t.ticksuffix)),"boundaries"===t.tickson||t.showdividers){var g=function(e){var r=t.l2p(e);return r>=0&&r<=t._length?e:null};o.xbnd=[g(o.x-.5),g(o.x+t.dtick-.5)]}return o},H.hoverLabelText=function(t,e,r){r&&(t=s.extendFlat({},t,{hoverformat:r}));var n=Array.isArray(e)?e[0]:e,i=Array.isArray(e)?e[1]:void 0;if(void 0!==i&&i!==n)return H.hoverLabelText(t,n,r)+" - "+H.hoverLabelText(t,i,r);var a="log"===t.type&&n<=0,o=H.tickText(t,t.c2l(a?-n:n),"hover").text;return a?0===n?"0":P+o:o};var pt=["f","p","n","\u03bc","m","","k","M","G","T"];function dt(t){return"SI"===t||"B"===t}function mt(t){return t>14||t<-15}function gt(t,e,r,n){var a=t<0,o=e._tickround,l=r||e.exponentformat||"B",c=e._tickexponent,u=H.getTickFormat(e),f=e.separatethousands;if(n){var h={exponentformat:l,minexponent:e.minexponent,dtick:"none"===e.showexponent?e.dtick:i(t)&&Math.abs(t)||1,range:"none"===e.showexponent?e.range.map(e.r2d):[0,t||1]};ft(h),o=(Number(h._tickround)||0)+4,c=h._tickexponent,e.hoverformat&&(u=e.hoverformat)}if(u)return e._numFormat(u)(t).replace(/-/g,P);var p,d=Math.pow(10,-o)/2;if("none"===l&&(c=0),(t=Math.abs(t))<d)t="0",a=!1;else{if(t+=d,c&&(t*=Math.pow(10,-c),o+=c),0===o)t=String(Math.floor(t));else if(o<0){t=(t=String(Math.round(t))).substr(0,t.length+o);for(var m=o;m<0;m++)t+="0"}else{var g=(t=String(t)).indexOf(".")+1;g&&(t=t.substr(0,g+o).replace(/\.?0+$/,""))}t=s.numSeparate(t,e._separators,f)}c&&"hide"!==l&&(dt(l)&&mt(c)&&(l="power"),p=c<0?P+-c:"power"!==l?"+"+c:String(c),"e"===l||"E"===l?t+=l+p:"power"===l?t+="\xd710<sup>"+p+"</sup>":"B"===l&&9===c?t+="B":dt(l)&&(t+=pt[c/3+5]));return a?P+t:t}function vt(t,e){for(var r=[],n={},i=0;i<e.length;i++){var a=e[i];n[a.text2]?n[a.text2].push(a.x):n[a.text2]=[a.x]}for(var o in n)r.push(ht(t,s.interp(n[o],.5),o));return r}function yt(t){return void 0!==t.periodX?t.periodX:t.x}function xt(t){return[t.text,t.x,t.axInfo,t.font,t.fontSize,t.fontColor].join("_")}function bt(t){var e=t.title.font.size,r=(t.title.text.match(c.BR_TAG_ALL)||[]).length;return t.title.hasOwnProperty("standoff")?r?e*(j+r*U):e*j:r?e*(r+1)*U:e}function _t(t,e){var r=t.l2p(e);return r>1&&r<t._length-1}function wt(t){var e=n.select(t),r=e.select(".text-math-group");return r.empty()?e.select("text"):r}function Tt(t){return t._id+".automargin"}function kt(t){return Tt(t)+".mirror"}function At(t){return t._id+".rangeslider"}function Mt(t,e){for(var r=0;r<e.length;r++)-1===t.indexOf(e[r])&&t.push(e[r])}function St(t,e,r){var n,i,a=[],o=[],l=t.layout;for(n=0;n<e.length;n++)a.push(H.getFromId(t,e[n]));for(n=0;n<r.length;n++)o.push(H.getFromId(t,r[n]));var c=Object.keys(p),u=["anchor","domain","overlaying","position","side","tickangle","editType"],f=["linear","log"];for(n=0;n<c.length;n++){var h=c[n],d=a[0][h],m=o[0][h],g=!0,v=!1,y=!1;if("_"!==h.charAt(0)&&"function"!=typeof d&&-1===u.indexOf(h)){for(i=1;i<a.length&&g;i++){var x=a[i][h];"type"===h&&-1!==f.indexOf(d)&&-1!==f.indexOf(x)&&d!==x?v=!0:x!==d&&(g=!1)}for(i=1;i<o.length&&g;i++){var b=o[i][h];"type"===h&&-1!==f.indexOf(m)&&-1!==f.indexOf(b)&&m!==b?y=!0:o[i][h]!==m&&(g=!1)}g&&(v&&(l[a[0]._name].type="linear"),y&&(l[o[0]._name].type="linear"),Et(l,h,a,o,t._fullLayout._dfltTitle))}}for(n=0;n<t._fullLayout.annotations.length;n++){var _=t._fullLayout.annotations[n];-1!==e.indexOf(_.xref)&&-1!==r.indexOf(_.yref)&&s.swapAttrs(l.annotations[n],["?"])}}function Et(t,e,r,n,i){var a,o=s.nestedProperty,l=o(t[r[0]._name],e).get(),c=o(t[n[0]._name],e).get();for("title"===e&&(l&&l.text===i.x&&(l.text=i.y),c&&c.text===i.y&&(c.text=i.x)),a=0;a<r.length;a++)o(t,r[a]._name+"."+e).set(c);for(a=0;a<n.length;a++)o(t,n[a]._name+"."+e).set(l)}function Lt(t){return"angularaxis"===t._id}function Ct(t,e){for(var r=e._rangebreaks.length,n=0;n<r;n++){var i=e._rangebreaks[n];if(t>=i.min&&t<i.max)return i.max}return t}function Pt(t){return-1!==(t.ticklabelposition||"").indexOf("inside")}function It(t,e){Pt(t._anchorAxis||{})&&t._hideCounterAxisInsideTickLabels&&t._hideCounterAxisInsideTickLabels(e)}H.getTickFormat=function(t){var e,r,n,i,a,o,s,l;function c(t){return"string"!=typeof t?t:Number(t.replace("M",""))*T}function u(t,e){var r=["L","D"];if(typeof t==typeof e){if("number"==typeof t)return t-e;var n=r.indexOf(t.charAt(0)),i=r.indexOf(e.charAt(0));return n===i?Number(t.replace(/(L|D)/g,""))-Number(e.replace(/(L|D)/g,"")):n-i}return"number"==typeof t?1:-1}function f(t,e){var r=null===e[0],n=null===e[1],i=u(t,e[0])>=0,a=u(t,e[1])<=0;return(r||i)&&(n||a)}if(t.tickformatstops&&t.tickformatstops.length>0)switch(t.type){case"date":case"linear":for(e=0;e<t.tickformatstops.length;e++)if((n=t.tickformatstops[e]).enabled&&(i=t.dtick,a=n.dtickrange,o=void 0,s=void 0,l=void 0,o=c||function(t){return t},s=a[0],l=a[1],(!s&&"number"!=typeof s||o(s)<=o(i))&&(!l&&"number"!=typeof l||o(l)>=o(i)))){r=n;break}break;case"log":for(e=0;e<t.tickformatstops.length;e++)if((n=t.tickformatstops[e]).enabled&&f(t.dtick,n.dtickrange)){r=n;break}}return r?r.value:t.tickformat},H.getSubplots=function(t,e){var r=t._fullLayout._subplots,n=r.cartesian.concat(r.gl2d||[]),i=e?H.findSubplotsWithAxis(n,e):n;return i.sort((function(t,e){var r=t.substr(1).split("y"),n=e.substr(1).split("y");return r[0]===n[0]?+r[1]-+n[1]:+r[0]-+n[0]})),i},H.findSubplotsWithAxis=function(t,e){for(var r=new RegExp("x"===e._id.charAt(0)?"^"+e._id+"y":e._id+"$"),n=[],i=0;i<t.length;i++){var a=t[i];r.test(a)&&n.push(a)}return n},H.makeClipPaths=function(t){var e=t._fullLayout;if(!e._hasOnlyLargeSploms){var r,i,a={_offset:0,_length:e.width,_id:""},o={_offset:0,_length:e.height,_id:""},s=H.list(t,"x",!0),l=H.list(t,"y",!0),c=[];for(r=0;r<s.length;r++)for(c.push({x:s[r],y:o}),i=0;i<l.length;i++)0===r&&c.push({x:a,y:l[i]}),c.push({x:s[r],y:l[i]});var u=e._clips.selectAll(".axesclip").data(c,(function(t){return t.x._id+t.y._id}));u.enter().append("clipPath").classed("axesclip",!0).attr("id",(function(t){return"clip"+e._uid+t.x._id+t.y._id})).append("rect"),u.exit().remove(),u.each((function(t){n.select(this).select("rect").attr({x:t.x._offset||0,y:t.y._offset||0,width:t.x._length||1,height:t.y._length||1})}))}},H.draw=function(t,e,r){var n=t._fullLayout;"redraw"===e&&n._paper.selectAll("g.subplot").each((function(t){var e=t[0],r=n._plots[e];if(r){var i=r.xaxis,a=r.yaxis;r.xaxislayer.selectAll("."+i._id+"tick").remove(),r.yaxislayer.selectAll("."+a._id+"tick").remove(),r.xaxislayer.selectAll("."+i._id+"tick2").remove(),r.yaxislayer.selectAll("."+a._id+"tick2").remove(),r.xaxislayer.selectAll("."+i._id+"divider").remove(),r.yaxislayer.selectAll("."+a._id+"divider").remove(),r.minorGridlayer&&r.minorGridlayer.selectAll("path").remove(),r.gridlayer&&r.gridlayer.selectAll("path").remove(),r.zerolinelayer&&r.zerolinelayer.selectAll("path").remove(),n._infolayer.select(".g-"+i._id+"title").remove(),n._infolayer.select(".g-"+a._id+"title").remove()}}));var i=e&&"redraw"!==e?e:H.listIds(t);return s.syncOrAsync(i.map((function(e){return function(){if(e){var n=H.getFromId(t,e),i=H.drawOne(t,n,r);return n._r=n.range.slice(),n._rl=s.simpleMap(n._r,n.r2l),i}}})))},H.drawOne=function(t,e,r){var n,i,l;r=r||{},e.setScale();var c=t._fullLayout,p=e._id,d=p.charAt(0),m=H.counterLetter(p),g=c._plots[e._mainSubplot];if(g){var v=g[d+"axislayer"],y=e._mainLinePosition,x=e._mainMirrorPosition,b=e._vals=H.calcTicks(e),_=[e.mirror,y,x].join("_");for(n=0;n<b.length;n++)b[n].axInfo=_;e._selections={},e._tickAngles&&(e._prevTickAngles=e._tickAngles),e._tickAngles={},e._depth=null;var w={};if(e.visible){var T,k,A=H.makeTransTickFn(e),M=H.makeTransTickLabelFn(e),S="inside"===e.ticks,E="outside"===e.ticks;if("boundaries"===e.tickson){var L=function(t,e){var r,n=[],i=function(t,e){var r=t.xbnd[e];null!==r&&n.push(s.extendFlat({},t,{x:r}))};if(e.length){for(r=0;r<e.length;r++)i(e[r],0);i(e[r-1],1)}return n}(0,b);k=H.clipEnds(e,L),T=S?k:L}else k=H.clipEnds(e,b),T=S&&"period"!==e.ticklabelmode?k:b;var C,P=e._gridVals=k,I=function(t,e){var r,n,i=[],a=e.length&&e[e.length-1].x<e[0].x,o=function(t,e){var r=t.xbnd[e];null!==r&&i.push(s.extendFlat({},t,{x:r}))};if(t.showdividers&&e.length){for(r=0;r<e.length;r++){var l=e[r];l.text2!==n&&o(l,a?1:0),n=l.text2}o(e[r-1],a?0:1)}return i}(e,b);if(!c._hasOnlyLargeSploms){var O=e._subplotsWith,z={};for(n=0;n<O.length;n++){i=O[n];var D=(l=c._plots[i])[m+"axis"],R=D._mainAxis._id;if(!z[R]){z[R]=1;var F="x"===d?"M0,"+D._offset+"v"+D._length:"M"+D._offset+",0h"+D._length;H.drawGrid(t,e,{vals:P,counterAxis:D,layer:l.gridlayer.select("."+p),minorLayer:l.minorGridlayer.select("."+p),path:F,transFn:A}),H.drawZeroLine(t,e,{counterAxis:D,layer:l.zerolinelayer,path:F,transFn:A})}}}var B=H.getTickSigns(e),N=H.getTickSigns(e,"minor");if(e.ticks||e.minor&&e.minor.ticks){var j,q,G,Y,W=H.makeTickPath(e,y,B[2]),X=H.makeTickPath(e,y,N[2],{minor:!0});if(e._anchorAxis&&e.mirror&&!0!==e.mirror?(j=H.makeTickPath(e,x,B[3]),q=H.makeTickPath(e,x,N[3],{minor:!0}),G=W+j,Y=X+q):(j="",q="",G=W,Y=X),e.showdividers&&E&&"boundaries"===e.tickson){var Z={};for(n=0;n<I.length;n++)Z[I[n].x]=1;C=function(t){return Z[t.x]?j:G}}else C=function(t){return t.minor?Y:G}}if(H.drawTicks(t,e,{vals:T,layer:v,path:C,transFn:A}),"allticks"===e.mirror){var J=Object.keys(e._linepositions||{});for(n=0;n<J.length;n++){i=J[n],l=c._plots[i];var K=e._linepositions[i]||[],Q=K[0],$=K[1],tt=K[2],et=H.makeTickPath(e,Q,tt?B[0]:N[0],{minor:tt})+H.makeTickPath(e,$,tt?B[1]:N[1],{minor:tt});H.drawTicks(t,e,{vals:T,layer:l[d+"axislayer"],path:et,transFn:A})}}var rt=[];if(rt.push((function(){return H.drawLabels(t,e,{vals:b,layer:v,plotinfo:l,transFn:M,labelFns:H.makeLabelFns(e,y)})})),"multicategory"===e.type){var nt={x:2,y:10}[d];rt.push((function(){var r={x:"height",y:"width"}[d],n=at()[r]+nt+(e._tickAngles[p+"tick"]?e.tickfont.size*U:0);return H.drawLabels(t,e,{vals:vt(e,b),layer:v,cls:p+"tick2",repositionOnUpdate:!0,secondary:!0,transFn:A,labelFns:H.makeLabelFns(e,y+n*B[4])})})),rt.push((function(){return e._depth=B[4]*(at("tick2")[e.side]-y),function(t,e,r){var n=e._id+"divider",i=r.vals,a=r.layer.selectAll("path."+n).data(i,xt);a.exit().remove(),a.enter().insert("path",":first-child").classed(n,1).classed("crisp",1).call(f.stroke,e.dividercolor).style("stroke-width",h.crispRound(t,e.dividerwidth,1)+"px"),a.attr("transform",r.transFn).attr("d",r.path)}(t,e,{vals:I,layer:v,path:H.makeTickPath(e,y,B[4],{len:e._depth}),transFn:A})}))}else e.title.hasOwnProperty("standoff")&&rt.push((function(){e._depth=B[4]*(at()[e.side]-y)}));var it=o.getComponentMethod("rangeslider","isVisible")(e);return rt.push((function(){var r,n,i,s,l=e.side.charAt(0),u=V[e.side].charAt(0),f=H.getPxPosition(t,e),h=E?e.ticklen:0;if((e.automargin||it)&&("multicategory"===e.type?r=at("tick2"):(r=at(),"x"===d&&"b"===l&&(e._depth=Math.max(r.width>0?r.bottom-f:0,h)))),e.automargin){n={x:0,y:0,r:0,l:0,t:0,b:0};var p=[0,1];if("x"===d){if("b"===l?n[l]=e._depth:(n[l]=e._depth=Math.max(r.width>0?f-r.top:0,h),p.reverse()),r.width>0){var g=r.right-(e._offset+e._length);g>0&&(n.xr=1,n.r=g);var v=e._offset-r.left;v>0&&(n.xl=0,n.l=v)}}else if("l"===l?n[l]=e._depth=Math.max(r.height>0?f-r.left:0,h):(n[l]=e._depth=Math.max(r.height>0?r.right-f:0,h),p.reverse()),r.height>0){var y=r.bottom-(e._offset+e._length);y>0&&(n.yb=0,n.b=y);var x=e._offset-r.top;x>0&&(n.yt=1,n.t=x)}n[m]="free"===e.anchor?e.position:e._anchorAxis.domain[p[0]],e.title.text!==c._dfltTitle[d]&&(n[l]+=bt(e)+(e.title.standoff||0)),e.mirror&&"free"!==e.anchor&&((i={x:0,y:0,r:0,l:0,t:0,b:0})[u]=e.linewidth,e.mirror&&!0!==e.mirror&&(i[u]+=h),!0===e.mirror||"ticks"===e.mirror?i[m]=e._anchorAxis.domain[p[1]]:"all"!==e.mirror&&"allticks"!==e.mirror||(i[m]=[e._counterDomainMin,e._counterDomainMax][p[1]]))}it&&(s=o.getComponentMethod("rangeslider","autoMarginOpts")(t,e)),a.autoMargin(t,Tt(e),n),a.autoMargin(t,kt(e),i),a.autoMargin(t,At(e),s)})),r.skipTitle||it&&"bottom"===e.side||rt.push((function(){return function(t,e){var r,n=t._fullLayout,i=e._id,a=i.charAt(0),o=e.title.font.size;if(e.title.hasOwnProperty("standoff"))r=e._depth+e.title.standoff+bt(e);else{var s=Pt(e);if("multicategory"===e.type)r=e._depth;else{var l=1.5*o;s&&(l=.5*o,"outside"===e.ticks&&(l+=e.ticklen)),r=10+l+(e.linewidth?e.linewidth-1:0)}s||(r+="x"===a?"top"===e.side?o*(e.showticklabels?1:0):o*(e.showticklabels?1.5:.5):"right"===e.side?o*(e.showticklabels?1:.5):o*(e.showticklabels?.5:0))}var c,f,p,d,m=H.getPxPosition(t,e);"x"===a?(f=e._offset+e._length/2,p="top"===e.side?m-r:m+r):(p=e._offset+e._length/2,f="right"===e.side?m+r:m-r,c={rotate:"-90",offset:0});if("multicategory"!==e.type){var g=e._selections[e._id+"tick"];if(d={selection:g,side:e.side},g&&g.node()&&g.node().parentNode){var v=h.getTranslate(g.node().parentNode);d.offsetLeft=v.x,d.offsetTop=v.y}e.title.hasOwnProperty("standoff")&&(d.pad=0)}return u.draw(t,i+"title",{propContainer:e,propName:e._name+".title.text",placeholder:n._dfltTitle[a],avoid:d,transform:c,attributes:{x:f,y:p,"text-anchor":"middle"}})}(t,e)})),s.syncOrAsync(rt)}}function at(t){var r=p+(t||"tick");return w[r]||(w[r]=function(t,e){var r,n,i,a;t._selections[e].size()?(r=1/0,n=-1/0,i=1/0,a=-1/0,t._selections[e].each((function(){var t=wt(this),e=h.bBox(t.node().parentNode);r=Math.min(r,e.top),n=Math.max(n,e.bottom),i=Math.min(i,e.left),a=Math.max(a,e.right)}))):(r=0,n=0,i=0,a=0);return{top:r,bottom:n,left:i,right:a,height:n-r,width:a-i}}(e,r)),w[r]}},H.getTickSigns=function(t,e){var r=t._id.charAt(0),n={x:"top",y:"right"}[r],i=t.side===n?1:-1,a=[-1,1,i,-i];return"inside"!==(e?(t.minor||{}).ticks:t.ticks)==("x"===r)&&(a=a.map((function(t){return-t}))),t.side&&a.push({l:-1,t:-1,r:1,b:1}[t.side.charAt(0)]),a},H.makeTransTickFn=function(t){return"x"===t._id.charAt(0)?function(e){return l(t._offset+t.l2p(e.x),0)}:function(e){return l(0,t._offset+t.l2p(e.x))}},H.makeTransTickLabelFn=function(t){var e=function(t){var e=t.ticklabelposition||"",r=function(t){return-1!==e.indexOf(t)},n=r("top"),i=r("left"),a=r("right"),o=r("bottom"),s=r("inside"),l=o||i||n||a;if(!l&&!s)return[0,0];var c=t.side,u=l?(t.tickwidth||0)/2:0,f=3,h=t.tickfont?t.tickfont.size:12;(o||n)&&(u+=h*j,f+=(t.linewidth||0)/2);(i||a)&&(u+=(t.linewidth||0)/2,f+=3);s&&"top"===c&&(f-=h*(1-j));(i||n)&&(u=-u);"bottom"!==c&&"right"!==c||(f=-f);return[l?u:0,s?f:0]}(t),r=e[0],n=e[1];return"x"===t._id.charAt(0)?function(e){return l(r+t._offset+t.l2p(yt(e)),n)}:function(e){return l(n,r+t._offset+t.l2p(yt(e)))}},H.makeTickPath=function(t,e,r,n){n||(n={});var i=n.minor;if(i&&!t.minor)return"";var a=void 0!==n.len?n.len:i?t.minor.ticklen:t.ticklen,o=t._id.charAt(0),s=(t.linewidth||1)/2;return"x"===o?"M0,"+(e+s*r)+"v"+a*r:"M"+(e+s*r)+",0h"+a*r},H.makeLabelFns=function(t,e,r){var n=t.ticklabelposition||"",a=function(t){return-1!==n.indexOf(t)},o=a("top"),l=a("left"),c=a("right"),u=a("bottom")||l||o||c,f=a("inside"),h="inside"===n&&"inside"===t.ticks||!f&&"outside"===t.ticks&&"boundaries"!==t.tickson,p=0,d=0,m=h?t.ticklen:0;if(f?m*=-1:u&&(m=0),h&&(p+=m,r)){var g=s.deg2rad(r);p=m*Math.cos(g)+1,d=m*Math.sin(g)}t.showticklabels&&(h||t.showline)&&(p+=.2*t.tickfont.size);var v,y,x,b,_,w={labelStandoff:p+=(t.linewidth||1)/2*(f?-1:1),labelShift:d},T=0,k=t.side,A=t._id.charAt(0),M=t.tickangle;if("x"===A)b=(_=!f&&"bottom"===k||f&&"top"===k)?1:-1,f&&(b*=-1),v=d*b,y=e+p*b,x=_?1:-.2,90===Math.abs(M)&&(f?x+=N:x=-90===M&&"bottom"===k?j:90===M&&"top"===k?N:.5,T=N/2*(M/90)),w.xFn=function(t){return t.dx+v+T*t.fontSize},w.yFn=function(t){return t.dy+y+t.fontSize*x},w.anchorFn=function(t,e){if(u){if(l)return"end";if(c)return"start"}return i(e)&&0!==e&&180!==e?e*b<0!==f?"end":"start":"middle"},w.heightFn=function(e,r,n){return r<-60||r>60?-.5*n:"top"===t.side!==f?-n:0};else if("y"===A){if(b=(_=!f&&"left"===k||f&&"right"===k)?1:-1,f&&(b*=-1),v=p,y=d*b,x=0,f||90!==Math.abs(M)||(x=-90===M&&"left"===k||90===M&&"right"===k?j:.5),f){var S=i(M)?+M:0;if(0!==S){var E=s.deg2rad(S);T=Math.abs(Math.sin(E))*j*b,x=0}}w.xFn=function(t){return t.dx+e-(v+t.fontSize*x)*b+T*t.fontSize},w.yFn=function(t){return t.dy+y+t.fontSize*N},w.anchorFn=function(t,e){return i(e)&&90===Math.abs(e)?"middle":_?"end":"start"},w.heightFn=function(e,r,n){return"right"===t.side&&(r*=-1),r<-30?-n:r<30?-.5*n:0}}return w},H.drawTicks=function(t,e,r){r=r||{};var i=e._id+"tick",a=[].concat(e.minor&&e.minor.ticks?r.vals.filter((function(t){return t.minor&&!t.noTick})):[]).concat(e.ticks?r.vals.filter((function(t){return!t.minor&&!t.noTick})):[]),o=r.layer.selectAll("path."+i).data(a,xt);o.exit().remove(),o.enter().append("path").classed(i,1).classed("ticks",1).classed("crisp",!1!==r.crisp).each((function(t){return f.stroke(n.select(this),t.minor?e.minor.tickcolor:e.tickcolor)})).style("stroke-width",(function(r){return h.crispRound(t,r.minor?e.minor.tickwidth:e.tickwidth,1)+"px"})).attr("d",r.path).style("display",null),It(e,[R]),o.attr("transform",r.transFn)},H.drawGrid=function(t,e,r){r=r||{};var i=e._id+"grid",a=e.minor&&e.minor.showgrid,o=a?r.vals.filter((function(t){return t.minor})):[],s=e.showgrid?r.vals.filter((function(t){return!t.minor})):[],l=r.counterAxis;if(l&&H.shouldShowZeroLine(t,e,l))for(var c="array"===e.tickmode,u=0;u<s.length;u++){var p=s[u].x;if(c?!p:Math.abs(p)<e.dtick/100){if(s=s.slice(0,u).concat(s.slice(u+1)),!c)break;u--}}e._gw=h.crispRound(t,e.gridwidth,1);for(var d=a?h.crispRound(t,e.minor.gridwidth,1):0,m=r.layer,g=r.minorLayer,v=1;v>=0;v--){var y=v?m:g;if(y){var x=y.selectAll("path."+i).data(v?s:o,xt);x.exit().remove(),x.enter().append("path").classed(i,1).classed("crisp",!1!==r.crisp),x.attr("transform",r.transFn).attr("d",r.path).each((function(t){return f.stroke(n.select(this),t.minor?e.minor.gridcolor:e.gridcolor||"#ddd")})).style("stroke-dasharray",(function(t){return h.dashStyle(t.minor?e.minor.griddash:e.griddash,t.minor?e.minor.gridwidth:e.gridwidth)})).style("stroke-width",(function(t){return(t.minor?d:e._gw)+"px"})).style("display",null),"function"==typeof r.path&&x.attr("d",r.path)}}It(e,[z,D])},H.drawZeroLine=function(t,e,r){r=r||r;var n=e._id+"zl",i=H.shouldShowZeroLine(t,e,r.counterAxis),a=r.layer.selectAll("path."+n).data(i?[{x:0,id:e._id}]:[]);a.exit().remove(),a.enter().append("path").classed(n,1).classed("zl",1).classed("crisp",!1!==r.crisp).each((function(){r.layer.selectAll("path").sort((function(t,e){return Y(t.id,e.id)}))})),a.attr("transform",r.transFn).attr("d",r.path).call(f.stroke,e.zerolinecolor||f.defaultLine).style("stroke-width",h.crispRound(t,e.zerolinewidth,e._gw||1)+"px").style("display",null),It(e,[O])},H.drawLabels=function(t,e,r){r=r||{};var a=t._fullLayout,o=e._id,u=o.charAt(0),f=r.cls||o+"tick",p=r.vals.filter((function(t){return t.text})),d=r.labelFns,m=r.secondary?0:e.tickangle,g=(e._prevTickAngles||{})[f],v=r.layer.selectAll("g."+f).data(e.showticklabels?p:[],xt),y=[];function x(t,a){t.each((function(t){var o=n.select(this),s=o.select(".text-math-group"),u=d.anchorFn(t,a),f=r.transFn.call(o.node(),t)+(i(a)&&0!=+a?" rotate("+a+","+d.xFn(t)+","+(d.yFn(t)-t.fontSize/2)+")":""),p=c.lineCount(o),m=U*t.fontSize,g=d.heightFn(t,i(a)?+a:0,(p-1)*m);if(g&&(f+=l(0,g)),s.empty()){var v=o.select("text");v.attr({transform:f,"text-anchor":u}),v.style("opacity",1),e._adjustTickLabelsOverflow&&e._adjustTickLabelsOverflow()}else{var y=h.bBox(s.node()).width*{end:-.5,start:.5}[u];s.attr("transform",f+l(y,0))}}))}v.enter().append("g").classed(f,1).append("text").attr("text-anchor","middle").each((function(e){var r=n.select(this),i=t._promises.length;r.call(c.positionText,d.xFn(e),d.yFn(e)).call(h.font,e.font,e.fontSize,e.fontColor).text(e.text).call(c.convertToTspans,t),t._promises[i]?y.push(t._promises.pop().then((function(){x(r,m)}))):x(r,m)})),It(e,[F]),v.exit().remove(),r.repositionOnUpdate&&v.each((function(t){n.select(this).select("text").call(c.positionText,d.xFn(t),d.yFn(t))})),e._adjustTickLabelsOverflow=function(){var r=e.ticklabeloverflow;if(r&&"allow"!==r){var i=-1!==r.indexOf("hide"),o="x"===e._id.charAt(0),l=0,c=o?t._fullLayout.width:t._fullLayout.height;if(-1!==r.indexOf("domain")){var u=s.simpleMap(e.range,e.r2l);l=e.l2p(u[0])+e._offset,c=e.l2p(u[1])+e._offset}var f=Math.min(l,c),p=Math.max(l,c),d=e.side,m=1/0,g=-1/0;for(var y in v.each((function(t){var r=n.select(this);if(r.select(".text-math-group").empty()){var a=h.bBox(r.node()),s=0;o?(a.right>p||a.left<f)&&(s=1):(a.bottom>p||a.top+(e.tickangle?0:t.fontSize/4)<f)&&(s=1);var l=r.select("text");s?i&&l.style("opacity",0):(l.style("opacity",1),m="bottom"===d||"right"===d?Math.min(m,o?a.top:a.left):-1/0,g="top"===d||"left"===d?Math.max(g,o?a.bottom:a.right):1/0)}})),a._plots){var x=a._plots[y];if(e._id===x.xaxis._id||e._id===x.yaxis._id){var b=o?x.yaxis:x.xaxis;b&&(b["_visibleLabelMin_"+e._id]=m,b["_visibleLabelMax_"+e._id]=g)}}}},e._hideCounterAxisInsideTickLabels=function(t){var r="x"===e._id.charAt(0),i=[];for(var o in a._plots){var s=a._plots[o];e._id!==s.xaxis._id&&e._id!==s.yaxis._id||i.push(r?s.yaxis:s.xaxis)}i.forEach((function(r,i){r&&Pt(r)&&(t||[O,D,z,R,F]).forEach((function(t){var o="tick"===t.K&&"text"===t.L&&"period"===e.ticklabelmode,s=a._plots[e._mainSubplot];(t.K===O.K?s.zerolinelayer.selectAll("."+e._id+"zl"):t.K===D.K?s.minorGridlayer.selectAll("."+e._id):t.K===z.K?s.gridlayer.selectAll("."+e._id):s[e._id.charAt(0)+"axislayer"]).each((function(){var a=n.select(this);t.L&&(a=a.selectAll(t.L)),a.each((function(a){var s=e.l2p(o?yt(a):a.x)+e._offset,l=n.select(this);s<e["_visibleLabelMax_"+r._id]&&s>e["_visibleLabelMin_"+r._id]?l.style("display","none"):"tick"!==t.K||i||l.style("display",null)}))}))}))}))},x(v,g+1?g:m);var b=null;e._selections&&(e._selections[f]=v);var _=[function(){return y.length&&Promise.all(y)}];e.automargin&&a._redrawFromAutoMarginCount&&90===g?(b=90,_.push((function(){x(v,g)}))):_.push((function(){if(x(v,m),p.length&&"x"===u&&!i(m)&&("log"!==e.type||"D"!==String(e.dtick).charAt(0))){b=0;var t,n=0,a=[];if(v.each((function(t){n=Math.max(n,t.fontSize);var r=e.l2p(t.x),i=wt(this),o=h.bBox(i.node());a.push({top:0,bottom:10,height:10,left:r-o.width/2,right:r+o.width/2+2,width:o.width+2})})),"boundaries"!==e.tickson&&!e.showdividers||r.secondary){var o=p.length,l=Math.abs((p[o-1].x-p[0].x)*e._m)/(o-1),c=e.ticklabelposition||"",f=function(t){return-1!==c.indexOf(t)},d=f("top"),g=f("left"),y=f("right"),_=f("bottom")||g||d||y?(e.tickwidth||0)+6:0,w=l<2.5*n||"multicategory"===e.type||"realaxis"===e._name;for(t=0;t<a.length-1;t++)if(s.bBoxIntersect(a[t],a[t+1],_)){b=w?90:30;break}}else{var T=2;for(e.ticks&&(T+=e.tickwidth/2),t=0;t<a.length;t++){var k=p[t].xbnd,A=a[t];if(null!==k[0]&&A.left-e.l2p(k[0])<T||null!==k[1]&&e.l2p(k[1])-A.right<T){b=90;break}}}b&&x(v,b)}})),e._tickAngles&&_.push((function(){e._tickAngles[f]=null===b?i(m)?m:0:b}));var w=e._anchorAxis;w&&w.autorange&&Pt(e)&&!W(a,e._id)&&(a._insideTickLabelsAutorange||(a._insideTickLabelsAutorange={}),a._insideTickLabelsAutorange[w._name+".autorange"]=w.autorange,_.push((function(){v.each((function(t,r){var n=wt(this);n.select(".text-math-group").empty()&&(e._vals[r].bb=h.bBox(n.node()))}))})));var T=s.syncOrAsync(_);return T&&T.then&&t._promises.push(T),T},H.getPxPosition=function(t,e){var r,n=t._fullLayout._size,i=e._id.charAt(0),a=e.side;return"free"!==e.anchor?r=e._anchorAxis:"x"===i?r={_offset:n.t+(1-(e.position||0))*n.h,_length:0}:"y"===i&&(r={_offset:n.l+(e.position||0)*n.w,_length:0}),"top"===a||"left"===a?r._offset:"bottom"===a||"right"===a?r._offset+r._length:void 0},H.shouldShowZeroLine=function(t,e,r){var n=s.simpleMap(e.range,e.r2l);return n[0]*n[1]<=0&&e.zeroline&&("linear"===e.type||"-"===e.type)&&!(e.rangebreaks&&e.maskBreaks(0)===I)&&(_t(e,0)||!function(t,e,r,n){var i=r._mainAxis;if(!i)return;var a=t._fullLayout,o=e._id.charAt(0),s=H.counterLetter(e._id),l=e._offset+(Math.abs(n[0])<Math.abs(n[1])==("x"===o)?0:e._length);function c(t){if(!t.showline||!t.linewidth)return!1;var r=Math.max((t.linewidth+e.zerolinewidth)/2,1);function n(t){return"number"==typeof t&&Math.abs(t-l)<r}if(n(t._mainLinePosition)||n(t._mainMirrorPosition))return!0;var i=t._linepositions||{};for(var a in i)if(n(i[a][0])||n(i[a][1]))return!0}var u=a._plots[r._mainSubplot];if(!(u.mainplotinfo||u).overlays.length)return c(r);for(var f=H.list(t,s),h=0;h<f.length;h++){var p=f[h];if(p._mainAxis===i&&c(p))return!0}}(t,e,r,n)||function(t,e){for(var r=t._fullData,n=e._mainSubplot,i=e._id.charAt(0),a=0;a<r.length;a++){var s=r[a];if(!0===s.visible&&s.xaxis+s.yaxis===n){if(o.traceIs(s,"bar-like")&&s.orientation==={x:"h",y:"v"}[i])return!0;if(s.fill&&s.fill.charAt(s.fill.length-1)===i)return!0}}return!1}(t,e))},H.clipEnds=function(t,e){return e.filter((function(e){return _t(t,e.x)}))},H.allowAutoMargin=function(t){for(var e=H.list(t,"",!0),r=0;r<e.length;r++){var n=e[r];n.automargin&&(a.allowAutoMargin(t,Tt(n)),n.mirror&&a.allowAutoMargin(t,kt(n))),o.getComponentMethod("rangeslider","isVisible")(n)&&a.allowAutoMargin(t,At(n))}},H.swap=function(t,e){for(var r=function(t,e){var r,n,i=[];for(r=0;r<e.length;r++){var a=[],o=t._fullData[e[r]].xaxis,s=t._fullData[e[r]].yaxis;if(o&&s){for(n=0;n<i.length;n++)-1===i[n].x.indexOf(o)&&-1===i[n].y.indexOf(s)||a.push(n);if(a.length){var l,c=i[a[0]];if(a.length>1)for(n=1;n<a.length;n++)l=i[a[n]],Mt(c.x,l.x),Mt(c.y,l.y);Mt(c.x,[o]),Mt(c.y,[s])}else i.push({x:[o],y:[s]})}}return i}(t,e),n=0;n<r.length;n++)St(t,r[n].x,r[n].y)}},{"../../components/color":366,"../../components/drawing":388,"../../components/titles":464,"../../constants/alignment":471,"../../constants/numerical":479,"../../lib":503,"../../lib/svg_text_utils":529,"../../plots/plots":619,"../../registry":638,"./autorange":553,"./axis_autotype":555,"./axis_ids":558,"./clean_ticks":560,"./layout_attributes":569,"./set_convert":576,"@plotly/d3":58,"fast-isnumeric":190}],555:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=t("../../constants/numerical").BADNUM,o=i.isArrayOrTypedArray,s=i.isDateTime,l=i.cleanNumber,c=Math.round;function u(t,e){return e?n(t):"number"==typeof t}function f(t){return Math.max(1,(t-1)/1e3)}e.exports=function(t,e,r){var i=t,h=r.noMultiCategory;if(o(i)&&!i.length)return"-";if(!h&&function(t){return o(t[0])&&o(t[1])}(i))return"multicategory";if(h&&Array.isArray(i[0])){for(var p=[],d=0;d<i.length;d++)if(o(i[d]))for(var m=0;m<i[d].length;m++)p.push(i[d][m]);i=p}if(function(t,e){for(var r=t.length,i=f(r),a=0,o=0,l={},u=0;u<r;u+=i){var h=c(u),p=t[h],d=String(p);l[d]||(l[d]=1,s(p,e)&&a++,n(p)&&o++)}return a>2*o}(i,e))return"date";var g="strict"!==r.autotypenumbers;return function(t,e){for(var r=t.length,n=f(r),i=0,o=0,s={},u=0;u<r;u+=n){var h=c(u),p=t[h],d=String(p);if(!s[d]){s[d]=1;var m=typeof p;"boolean"===m?o++:(e?l(p)!==a:"number"===m)?i++:"string"===m&&o++}}return o>2*i}(i,g)?"category":function(t,e){for(var r=t.length,n=0;n<r;n++)if(u(t[n],e))return!0;return!1}(i,g)?"linear":"-"}},{"../../constants/numerical":479,"../../lib":503,"fast-isnumeric":190}],556:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../registry"),a=t("../../lib"),o=t("../../plot_api/plot_template"),s=t("../array_container_defaults"),l=t("./layout_attributes"),c=t("./tick_value_defaults"),u=t("./tick_mark_defaults"),f=t("./tick_label_defaults"),h=t("./prefix_suffix_defaults"),p=t("./category_order_defaults"),d=t("./line_grid_defaults"),m=t("./set_convert"),g=t("./constants").WEEKDAY_PATTERN,v=t("./constants").HOUR_PATTERN;function y(t,e,r){function i(r,n){return a.coerce(t,e,l.rangebreaks,r,n)}if(i("enabled")){var o=i("bounds");if(o&&o.length>=2){var s,c,u="";if(2===o.length)for(s=0;s<2;s++)if(c=b(o[s])){u=g;break}var f=i("pattern",u);if(f===g)for(s=0;s<2;s++)(c=b(o[s]))&&(e.bounds[s]=o[s]=c-1);if(f)for(s=0;s<2;s++)switch(c=o[s],f){case g:if(!n(c))return void(e.enabled=!1);if((c=+c)!==Math.floor(c)||c<0||c>=7)return void(e.enabled=!1);e.bounds[s]=o[s]=c;break;case v:if(!n(c))return void(e.enabled=!1);if((c=+c)<0||c>24)return void(e.enabled=!1);e.bounds[s]=o[s]=c}if(!1===r.autorange){var h=r.range;if(h[0]<h[1]){if(o[0]<h[0]&&o[1]>h[1])return void(e.enabled=!1)}else if(o[0]>h[0]&&o[1]<h[1])return void(e.enabled=!1)}}else{var p=i("values");if(!p||!p.length)return void(e.enabled=!1);i("dvalue")}}}e.exports=function(t,e,r,n,v){var x,b=n.letter,_=n.font||{},w=n.splomStash||{},T=r("visible",!n.visibleDflt),k=e._template||{},A=e.type||k.type||"-";"date"===A&&(i.getComponentMethod("calendars","handleDefaults")(t,e,"calendar",n.calendar),n.noTicklabelmode||(x=r("ticklabelmode")));var M="";n.noTicklabelposition&&"multicategory"!==A||(M=a.coerce(t,e,{ticklabelposition:{valType:"enumerated",dflt:"outside",values:"period"===x?["outside","inside"]:"x"===b?["outside","inside","outside left","inside left","outside right","inside right"]:["outside","inside","outside top","inside top","outside bottom","inside bottom"]}},"ticklabelposition")),n.noTicklabeloverflow||r("ticklabeloverflow",-1!==M.indexOf("inside")?"hide past domain":"category"===A||"multicategory"===A?"allow":"hide past div"),m(e,v);var S=!e.isValidRange(t.range);S&&n.reverseDflt&&(S="reversed"),!r("autorange",S)||"linear"!==A&&"-"!==A||r("rangemode"),r("range"),e.cleanRange(),p(t,e,r,n),"category"===A||n.noHover||r("hoverformat");var E=r("color"),L=E!==l.color.dflt?E:_.color,C=w.label||v._dfltTitle[b];if(h(t,e,r,A,n),!T)return e;r("title.text",C),a.coerceFont(r,"title.font",{family:_.family,size:a.bigFont(_.size),color:L}),c(t,e,r,A);var P=n.hasMinor;if(P&&(o.newContainer(e,"minor"),c(t,e,r,A,{isMinor:!0})),f(t,e,r,A,n),u(t,e,r,n),P){var I=n.isMinor;n.isMinor=!0,u(t,e,r,n),n.isMinor=I}d(t,e,r,{dfltColor:E,bgColor:n.bgColor,showGrid:n.showGrid,hasMinor:P,attributes:l}),!P||e.minor.ticks||e.minor.showgrid||delete e.minor,(e.showline||e.ticks)&&r("mirror"),n.automargin&&r("automargin");var O,z="multicategory"===A;n.noTickson||"category"!==A&&!z||!e.ticks&&!e.showgrid||(z&&(O="boundaries"),"boundaries"===r("tickson",O)&&delete e.ticklabelposition);z&&(r("showdividers")&&(r("dividercolor"),r("dividerwidth")));if("date"===A)if(s(t,e,{name:"rangebreaks",inclusionAttr:"enabled",handleItemDefaults:y}),e.rangebreaks.length){for(var D=0;D<e.rangebreaks.length;D++)if(e.rangebreaks[D].pattern===g){e._hasDayOfWeekBreaks=!0;break}if(m(e,v),v._has("scattergl")||v._has("splom"))for(var R=0;R<n.data.length;R++){var F=n.data[R];"scattergl"!==F.type&&"splom"!==F.type||(F.visible=!1,a.warn(F.type+" traces do not work on axes with rangebreaks. Setting trace "+F.index+" to `visible: false`."))}}else delete e.rangebreaks;return e};var x={sun:1,mon:2,tue:3,wed:4,thu:5,fri:6,sat:7};function b(t){if("string"==typeof t)return x[t.substr(0,3).toLowerCase()]}},{"../../lib":503,"../../plot_api/plot_template":543,"../../registry":638,"../array_container_defaults":549,"./category_order_defaults":559,"./constants":561,"./layout_attributes":569,"./line_grid_defaults":571,"./prefix_suffix_defaults":573,"./set_convert":576,"./tick_label_defaults":578,"./tick_mark_defaults":579,"./tick_value_defaults":580,"fast-isnumeric":190}],557:[function(t,e,r){"use strict";var n=t("../../constants/docs"),i=n.FORMAT_LINK,a=n.DATE_FORMAT_LINK;function o(t,e){return["Sets the "+t+" formatting rule"+(e?"for `"+e+"` ":""),"using d3 formatting mini-languages","which are very similar to those in Python. For numbers, see: "+i+"."].join(" ")}function s(t,e){return o(t,e)+[" And for dates see: "+a+".","We add two items to d3's date formatter:","*%h* for half of the year as a decimal number as well as","*%{n}f* for fractional seconds","with n digits. For example, *2016-10-13 09:15:23.456* with tickformat","*%H~%M~%S.%2f* would display *09~15~23.46*"].join(" ")}e.exports={axisHoverFormat:function(t,e){return{valType:"string",dflt:"",editType:"none",description:(e?o:s)("hover text",t)+["By default the values are formatted using "+(e?"generic number format":"`"+t+"axis.hoverformat`")+"."].join(" ")}},descriptionOnlyNumbers:o,descriptionWithDates:s}},{"../../constants/docs":474}],558:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("./constants");function a(t,e){if(e&&e.length)for(var r=0;r<e.length;r++)if(e[r][t])return!0;return!1}r.id2name=function(t){if("string"==typeof t&&t.match(i.AX_ID_PATTERN)){var e=t.split(" ")[0].substr(1);return"1"===e&&(e=""),t.charAt(0)+"axis"+e}},r.name2id=function(t){if(t.match(i.AX_NAME_PATTERN)){var e=t.substr(5);return"1"===e&&(e=""),t.charAt(0)+e}},r.cleanId=function(t,e,r){var n=/( domain)$/.test(t);if("string"==typeof t&&t.match(i.AX_ID_PATTERN)&&(!e||t.charAt(0)===e)&&(!n||r)){var a=t.split(" ")[0].substr(1).replace(/^0+/,"");return"1"===a&&(a=""),t.charAt(0)+a+(n&&r?" domain":"")}},r.list=function(t,e,n){var i=t._fullLayout;if(!i)return[];var a,o=r.listIds(t,e),s=new Array(o.length);for(a=0;a<o.length;a++){var l=o[a];s[a]=i[l.charAt(0)+"axis"+l.substr(1)]}if(!n){var c=i._subplots.gl3d||[];for(a=0;a<c.length;a++){var u=i[c[a]];e?s.push(u[e+"axis"]):s.push(u.xaxis,u.yaxis,u.zaxis)}}return s},r.listIds=function(t,e){var r=t._fullLayout;if(!r)return[];var n=r._subplots;return e?n[e+"axis"]:n.xaxis.concat(n.yaxis)},r.getFromId=function(t,e,n){var i=t._fullLayout;return e=void 0===e||"string"!=typeof e?e:e.replace(" domain",""),"x"===n?e=e.replace(/y[0-9]*/,""):"y"===n&&(e=e.replace(/x[0-9]*/,"")),i[r.id2name(e)]},r.getFromTrace=function(t,e,i){var a=t._fullLayout,o=null;if(n.traceIs(e,"gl3d")){var s=e.scene;"scene"===s.substr(0,5)&&(o=a[s][i+"axis"])}else o=r.getFromId(t,e[i+"axis"]||i);return o},r.idSort=function(t,e){var r=t.charAt(0),n=e.charAt(0);return r!==n?r>n?1:-1:+(t.substr(1)||1)-+(e.substr(1)||1)},r.ref2id=function(t){return!!/^[xyz]/.test(t)&&t.split(" ")[0]},r.isLinked=function(t,e){return a(e,t._axisMatchGroups)||a(e,t._axisConstraintGroups)}},{"../../registry":638,"./constants":561}],559:[function(t,e,r){"use strict";e.exports=function(t,e,r,n){if("category"===e.type){var i,a=t.categoryarray,o=Array.isArray(a)&&a.length>0;o&&(i="array");var s,l=r("categoryorder",i);"array"===l&&(s=r("categoryarray")),o||"array"!==l||(l=e.categoryorder="trace"),"trace"===l?e._initialCategories=[]:"array"===l?e._initialCategories=s.slice():(s=function(t,e){var r,n,i,a=e.dataAttr||t._id.charAt(0),o={};if(e.axData)r=e.axData;else for(r=[],n=0;n<e.data.length;n++){var s=e.data[n];s[a+"axis"]===t._id&&r.push(s)}for(n=0;n<r.length;n++){var l=r[n][a];for(i=0;i<l.length;i++){var c=l[i];null!=c&&(o[c]=1)}}return Object.keys(o)}(e,n).sort(),"category ascending"===l?e._initialCategories=s:"category descending"===l&&(e._initialCategories=s.reverse()))}}},{}],560:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=t("../../constants/numerical"),o=a.ONEDAY,s=a.ONEWEEK;r.dtick=function(t,e){var r="log"===e,i="date"===e,a="category"===e,s=i?o:1;if(!t)return s;if(n(t))return(t=Number(t))<=0?s:a?Math.max(1,Math.round(t)):i?Math.max(.1,t):t;if("string"!=typeof t||!i&&!r)return s;var l=t.charAt(0),c=t.substr(1);return(c=n(c)?Number(c):0)<=0||!(i&&"M"===l&&c===Math.round(c)||r&&"L"===l||r&&"D"===l&&(1===c||2===c))?s:t},r.tick0=function(t,e,r,a){return"date"===e?i.cleanDate(t,i.dateTick0(r,a%s==0?1:0)):"D1"!==a&&"D2"!==a?n(t)?Number(t):0:void 0}},{"../../constants/numerical":479,"../../lib":503,"fast-isnumeric":190}],561:[function(t,e,r){"use strict";var n=t("../../lib/regex").counter;e.exports={idRegex:{x:n("x","( domain)?"),y:n("y","( domain)?")},attrRegex:n("[xy]axis"),xAxisMatch:n("xaxis"),yAxisMatch:n("yaxis"),AX_ID_PATTERN:/^[xyz][0-9]*( domain)?$/,AX_NAME_PATTERN:/^[xyz]axis[0-9]*$/,SUBPLOT_PATTERN:/^x([0-9]*)y([0-9]*)$/,HOUR_PATTERN:"hour",WEEKDAY_PATTERN:"day of week",MINDRAG:8,MINSELECT:12,MINZOOM:20,DRAGGERSIZE:20,BENDPX:1.5,REDRAWDELAY:50,SELECTDELAY:100,SELECTID:"-select",DFLTRANGEX:[-1,6],DFLTRANGEY:[-1,4],traceLayerClasses:["imagelayer","heatmaplayer","contourcarpetlayer","contourlayer","funnellayer","waterfalllayer","barlayer","carpetlayer","violinlayer","boxlayer","ohlclayer","scattercarpetlayer","scatterlayer"],clipOnAxisFalseQuery:[".scatterlayer",".barlayer",".funnellayer",".waterfalllayer"],layerValue2layerClass:{"above traces":"above","below traces":"below"}}},{"../../lib/regex":520}],562:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./autorange"),a=t("./axis_ids").id2name,o=t("./layout_attributes"),s=t("./scale_zoom"),l=t("./set_convert"),c=t("../../constants/numerical").ALMOST_EQUAL,u=t("../../constants/alignment").FROM_BL;function f(t,e,r){var i=r.axIds,s=r.layoutOut,l=r.hasImage,c=s._axisConstraintGroups,u=s._axisMatchGroups,f=e._id,m=f.charAt(0),g=((s._splomAxes||{})[m]||{})[f]||{},v=e._id,y="x"===v.charAt(0);function x(r,i){return n.coerce(t,e,o,r,i)}e._matchGroup=null,e._constraintGroup=null,x("constrain",l?"domain":"range"),n.coerce(t,e,{constraintoward:{valType:"enumerated",values:y?["left","center","right"]:["bottom","middle","top"],dflt:y?"center":"middle"}},"constraintoward");var b,_,w=e.type,T=[];for(b=0;b<i.length;b++){if((_=i[b])!==v)s[a(_)].type===w&&T.push(_)}var k=p(c,v);if(k){var A=[];for(b=0;b<T.length;b++)k[_=T[b]]||A.push(_);T=A}var M,S,E=T.length;E&&(t.matches||g.matches)&&(M=n.coerce(t,e,{matches:{valType:"enumerated",values:T,dflt:-1!==T.indexOf(g.matches)?g.matches:void 0}},"matches"));var L=l&&!y?e.anchor:void 0;if(E&&!M&&(t.scaleanchor||L)&&(S=n.coerce(t,e,{scaleanchor:{valType:"enumerated",values:T}},"scaleanchor",L)),M){e._matchGroup=d(u,v,M,1);var C=s[a(M)],P=h(s,e)/h(s,C);y!==("x"===M.charAt(0))&&(P=(y?"x":"y")+P),d(c,v,M,P)}else t.matches&&-1!==i.indexOf(t.matches)&&n.warn("ignored "+e._name+'.matches: "'+t.matches+'" to avoid an infinite loop');if(S){var I=x("scaleratio");I||(I=e.scaleratio=1),d(c,v,S,I)}else t.scaleanchor&&-1!==i.indexOf(t.scaleanchor)&&n.warn("ignored "+e._name+'.scaleanchor: "'+t.scaleanchor+'" to avoid either an infinite loop and possibly inconsistent scaleratios, or because this axis declares a *matches* constraint.')}function h(t,e){var r=e.domain;return r||(r=t[a(e.overlaying)].domain),r[1]-r[0]}function p(t,e){for(var r=0;r<t.length;r++)if(t[r][e])return t[r];return null}function d(t,e,r,n){var i,a,o,s,l,c=p(t,e);null===c?((c={})[e]=1,l=t.length,t.push(c)):l=t.indexOf(c);var u=Object.keys(c);for(i=0;i<t.length;i++)if(o=t[i],i!==l&&o[r]){var f=o[r];for(a=0;a<u.length;a++)o[s=u[a]]=m(f,m(n,c[s]));return void t.splice(l,1)}if(1!==n)for(a=0;a<u.length;a++){var h=u[a];c[h]=m(n,c[h])}c[r]=1}function m(t,e){var r,n,i="",a="";"string"==typeof t&&(r=(i=t.match(/^[xy]*/)[0]).length,t=+t.substr(r)),"string"==typeof e&&(n=(a=e.match(/^[xy]*/)[0]).length,e=+e.substr(n));var o=t*e;return r||n?r&&n&&i.charAt(0)!==a.charAt(0)?r===n?o:(r>n?i.substr(n):a.substr(r))+o:i+a+t*e:o}function g(t,e){for(var r=e._size,n=r.h/r.w,i={},a=Object.keys(t),o=0;o<a.length;o++){var s=a[o],l=t[s];if("string"==typeof l){var c=l.match(/^[xy]*/)[0],u=c.length;l=+l.substr(u);for(var f="y"===c.charAt(0)?n:1/n,h=0;h<u;h++)l*=f}i[s]=l}return i}function v(t,e){var r=t._inputDomain,n=u[t.constraintoward],i=r[0]+(r[1]-r[0])*n;t.domain=t._input.domain=[i+(r[0]-i)/e,i+(r[1]-i)/e],t.setScale()}r.handleDefaults=function(t,e,r){var i,o,s,c,u,h,p,d,m=r.axIds,g=r.axHasImage,v=e._axisConstraintGroups=[],y=e._axisMatchGroups=[];for(i=0;i<m.length;i++)f(u=t[c=a(m[i])],h=e[c],{axIds:m,layoutOut:e,hasImage:g[c]});function x(t,r){for(i=0;i<t.length;i++)for(s in o=t[i])e[a(s)][r]=o}for(x(y,"_matchGroup"),i=0;i<v.length;i++)for(s in o=v[i])if((h=e[a(s)]).fixedrange){for(var b in o){var _=a(b);!1===(t[_]||{}).fixedrange&&n.warn("fixedrange was specified as false for axis "+_+" but was overridden because another axis in its constraint group has fixedrange true"),e[_].fixedrange=!0}break}for(i=0;i<v.length;){for(s in o=v[i]){(h=e[a(s)])._matchGroup&&Object.keys(h._matchGroup).length===Object.keys(o).length&&(v.splice(i,1),i--);break}i++}x(v,"_constraintGroup");var w=["constrain","range","autorange","rangemode","rangebreaks","categoryorder","categoryarray"],T=!1,k=!1;function A(){d=h[p],"rangebreaks"===p&&(k=h._hasDayOfWeekBreaks)}for(i=0;i<y.length;i++){o=y[i];for(var M=0;M<w.length;M++){var S;for(s in p=w[M],d=null,o)if(u=t[c=a(s)],h=e[c],p in h){if(!h.matches&&(S=h,p in u)){A();break}null===d&&p in u&&A()}if("range"===p&&d&&(T=!0),"autorange"===p&&null===d&&T&&(d=!1),null===d&&p in S&&(d=S[p]),null!==d)for(s in o)(h=e[a(s)])[p]="range"===p?d.slice():d,"rangebreaks"===p&&(h._hasDayOfWeekBreaks=k,l(h,e))}}},r.enforce=function(t){var e,r,n,o,l,u,f,h,p=t._fullLayout,d=p._axisConstraintGroups||[];for(e=0;e<d.length;e++){n=g(d[e],p);var m=Object.keys(n),y=1/0,x=0,b=1/0,_={},w={},T=!1;for(r=0;r<m.length;r++)w[o=m[r]]=l=p[a(o)],l._inputDomain?l.domain=l._inputDomain.slice():l._inputDomain=l.domain.slice(),l._inputRange||(l._inputRange=l.range.slice()),l.setScale(),_[o]=u=Math.abs(l._m)/n[o],y=Math.min(y,u),"domain"!==l.constrain&&l._constraintShrinkable||(b=Math.min(b,u)),delete l._constraintShrinkable,x=Math.max(x,u),"domain"===l.constrain&&(T=!0);if(!(y>c*x)||T)for(r=0;r<m.length;r++)if(u=_[o=m[r]],f=(l=w[o]).constrain,u!==b||"domain"===f)if(h=u/b,"range"===f)s(l,h);else{var k=l._inputDomain,A=(l.domain[1]-l.domain[0])/(k[1]-k[0]),M=(l.r2l(l.range[1])-l.r2l(l.range[0]))/(l.r2l(l._inputRange[1])-l.r2l(l._inputRange[0]));if((h/=A)*M<1){l.domain=l._input.domain=k.slice(),s(l,h);continue}if(M<1&&(l.range=l._input.range=l._inputRange.slice(),h*=M),l.autorange){var S=l.r2l(l.range[0]),E=l.r2l(l.range[1]),L=(S+E)/2,C=L,P=L,I=Math.abs(E-L),O=L-I*h*1.0001,z=L+I*h*1.0001,D=i.makePadFn(p,l,0),R=i.makePadFn(p,l,1);v(l,h);var F,B,N=Math.abs(l._m),j=i.concatExtremes(t,l),U=j.min,V=j.max;for(B=0;B<U.length;B++)(F=U[B].val-D(U[B])/N)>O&&F<C&&(C=F);for(B=0;B<V.length;B++)(F=V[B].val+R(V[B])/N)<z&&F>P&&(P=F);h/=(P-C)/(2*I),C=l.l2r(C),P=l.l2r(P),l.range=l._input.range=S<E?[C,P]:[P,C]}v(l,h)}}},r.getAxisGroup=function(t,e){for(var r=t._axisMatchGroups,n=0;n<r.length;n++){if(r[n][e])return"g"+n}return e},r.clean=function(t,e){if(e._inputDomain){for(var r=!1,n=e._id,i=t._fullLayout._axisConstraintGroups,a=0;a<i.length;a++)if(i[a][n]){r=!0;break}r&&"domain"===e.constrain||(e._input.domain=e.domain=e._inputDomain,delete e._inputDomain)}}},{"../../constants/alignment":471,"../../constants/numerical":479,"../../lib":503,"./autorange":553,"./axis_ids":558,"./layout_attributes":569,"./scale_zoom":574,"./set_convert":576}],563:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=i.numberFormat,o=t("tinycolor2"),s=t("has-passive-events"),l=t("../../registry"),c=i.strTranslate,u=t("../../lib/svg_text_utils"),f=t("../../components/color"),h=t("../../components/drawing"),p=t("../../components/fx"),d=t("./axes"),m=t("../../lib/setcursor"),g=t("../../components/dragelement"),v=t("../../components/dragelement/helpers"),y=v.selectingOrDrawing,x=v.freeMode,b=t("../../constants/alignment").FROM_TL,_=t("../../lib/clear_gl_canvases"),w=t("../../plot_api/subroutines").redrawReglTraces,T=t("../plots"),k=t("./axis_ids").getFromId,A=t("./select").prepSelect,M=t("./select").clearSelect,S=t("./select").selectOnClick,E=t("./scale_zoom"),L=t("./constants"),C=L.MINDRAG,P=L.MINZOOM,I=!0;function O(t,e,r,n){var a=i.ensureSingle(t.draglayer,e,r,(function(e){e.classed("drag",!0).style({fill:"transparent","stroke-width":0}).attr("data-subplot",t.id)}));return a.call(m,n),a.node()}function z(t,e,r,i,a,o,s){var l=O(t,"rect",e,r);return n.select(l).call(h.setRect,i,a,o,s),l}function D(t,e){for(var r=0;r<t.length;r++)if(!t[r].fixedrange)return e;return""}function R(t,e,r,n,i){for(var a=0;a<t.length;a++){var o=t[a];if(!o.fixedrange)if(o.rangebreaks){var s="y"===o._id.charAt(0),l=s?1-e:e,c=s?1-r:r;n[o._name+".range[0]"]=o.l2r(o.p2l(l*o._length)),n[o._name+".range[1]"]=o.l2r(o.p2l(c*o._length))}else{var u=o._rl[0],f=o._rl[1]-u;n[o._name+".range[0]"]=o.l2r(u+f*e),n[o._name+".range[1]"]=o.l2r(u+f*r)}}if(i&&i.length){var h=(e+(1-r))/2;R(i,h,1-h,n,[])}}function F(t,e){for(var r=0;r<t.length;r++){var n=t[r];if(!n.fixedrange)if(n.rangebreaks){var i=n._length,a=(n.p2l(0+e)-n.p2l(0)+(n.p2l(i+e)-n.p2l(i)))/2;n.range=[n.l2r(n._rl[0]-a),n.l2r(n._rl[1]-a)]}else n.range=[n.l2r(n._rl[0]-e/n._m),n.l2r(n._rl[1]-e/n._m)]}}function B(t){return 1-(t>=0?Math.min(t,.9):1/(1/Math.max(t,-.3)+3.222))}function N(t,e,r,n,i){return t.append("path").attr("class","zoombox").style({fill:e>.2?"rgba(0,0,0,0)":"rgba(255,255,255,0)","stroke-width":0}).attr("transform",c(r,n)).attr("d",i+"Z")}function j(t,e,r){return t.append("path").attr("class","zoombox-corners").style({fill:f.background,stroke:f.defaultLine,"stroke-width":1,opacity:0}).attr("transform",c(e,r)).attr("d","M0,0Z")}function U(t,e,r,n,i,a){t.attr("d",n+"M"+r.l+","+r.t+"v"+r.h+"h"+r.w+"v-"+r.h+"h-"+r.w+"Z"),V(t,e,i,a)}function V(t,e,r,n){r||(t.transition().style("fill",n>.2?"rgba(0,0,0,0.4)":"rgba(255,255,255,0.3)").duration(200),e.transition().style("opacity",1).duration(200))}function H(t){n.select(t).selectAll(".zoombox,.js-zoombox-backdrop,.js-zoombox-menu,.zoombox-corners").remove()}function q(t){I&&t.data&&t._context.showTips&&(i.notifier(i._(t,"Double-click to zoom back out"),"long"),I=!1)}function G(t){var e=Math.floor(Math.min(t.b-t.t,t.r-t.l,P)/2);return"M"+(t.l-3.5)+","+(t.t-.5+e)+"h3v"+-e+"h"+e+"v-3h-"+(e+3)+"ZM"+(t.r+3.5)+","+(t.t-.5+e)+"h-3v"+-e+"h"+-e+"v-3h"+(e+3)+"ZM"+(t.r+3.5)+","+(t.b+.5-e)+"h-3v"+e+"h"+-e+"v3h"+(e+3)+"ZM"+(t.l-3.5)+","+(t.b+.5-e)+"h3v"+e+"h"+e+"v3h-"+(e+3)+"Z"}function Y(t,e,r,n,a){for(var o,s,l,c,u=!1,f={},h={},p=(a||{}).xaHash,d=(a||{}).yaHash,m=0;m<e.length;m++){var g=e[m];for(o in r)if(g[o]){for(l in g)a&&(p[l]||d[l])||("x"===l.charAt(0)?r:n)[l]||(f[l]=o);for(s in n)a&&(p[s]||d[s])||!g[s]||(u=!0)}for(s in n)if(g[s])for(c in g)a&&(p[c]||d[c])||("x"===c.charAt(0)?r:n)[c]||(h[c]=s)}u&&(i.extendFlat(f,h),h={});var v={},y=[];for(l in f){var x=k(t,l);y.push(x),v[x._id]=x}var b={},_=[];for(c in h){var w=k(t,c);_.push(w),b[w._id]=w}return{xaHash:v,yaHash:b,xaxes:y,yaxes:_,xLinks:f,yLinks:h,isSubplotConstrained:u}}function W(t,e){if(s){var r=void 0!==t.onwheel?"wheel":"mousewheel";t._onwheel&&t.removeEventListener(r,t._onwheel),t._onwheel=e,t.addEventListener(r,e,{passive:!1})}else void 0!==t.onwheel?t.onwheel=e:void 0!==t.onmousewheel?t.onmousewheel=e:t.isAddedWheelEvent||(t.isAddedWheelEvent=!0,t.addEventListener("wheel",e,{passive:!1}))}function X(t){var e=[];for(var r in t)e.push(t[r]);return e}e.exports={makeDragBox:function(t,e,r,s,c,f,m,v){var I,O,V,Z,J,K,Q,$,tt,et,rt,nt,it,at,ot,st,lt,ct,ut,ft,ht,pt,dt,mt=t._fullLayout._zoomlayer,gt=m+v==="nsew",vt=1===(m+v).length;function yt(){if(I=e.xaxis,O=e.yaxis,tt=I._length,et=O._length,Q=I._offset,$=O._offset,(V={})[I._id]=I,(Z={})[O._id]=O,m&&v)for(var r=e.overlays,n=0;n<r.length;n++){var i=r[n].xaxis;V[i._id]=i;var a=r[n].yaxis;Z[a._id]=a}J=X(V),K=X(Z),it=D(J,v),at=D(K,m),ot=!at&&!it,nt=Y(t,t._fullLayout._axisMatchGroups,V,Z);var o=(rt=Y(t,t._fullLayout._axisConstraintGroups,V,Z,nt)).isSubplotConstrained||nt.isSubplotConstrained;st=v||o,lt=m||o;var s=t._fullLayout;ct=s._has("scattergl"),ut=s._has("splom"),ft=s._has("svg")}yt();var xt=function(t,e,r){if(!t)return"pointer";if("nsew"===t)return r?"":"pan"===e?"move":"crosshair";return t.toLowerCase()+"-resize"}(at+it,t._fullLayout.dragmode,gt),bt=z(e,m+v+"drag",xt,r,s,c,f);if(ot&&!gt)return bt.onmousedown=null,bt.style.pointerEvents="none",bt;var _t,wt,Tt,kt,At,Mt,St,Et,Lt,Ct,Pt={element:bt,gd:t,plotinfo:e};function It(){Pt.plotinfo.selection=!1,M(t)}function Ot(t,r){var i=Pt.gd;if(i._fullLayout._activeShapeIndex>=0)i._fullLayout._deactivateShape(i);else{var o=i._fullLayout.clickmode;if(H(i),2!==t||vt||qt(),gt)o.indexOf("select")>-1&&S(r,i,J,K,e.id,Pt),o.indexOf("event")>-1&&p.click(i,r,e.id);else if(1===t&&vt){var s=m?O:I,c="s"===m||"w"===v?0:1,f=s._name+".range["+c+"]",h=function(t,e){var r,n=t.range[e],i=Math.abs(n-t.range[1-e]);return"date"===t.type?n:"log"===t.type?(r=Math.ceil(Math.max(0,-Math.log(i)/Math.LN10))+3,a("."+r+"g")(Math.pow(10,n))):(r=Math.floor(Math.log(Math.abs(n))/Math.LN10)-Math.floor(Math.log(i)/Math.LN10)+4,a("."+String(r)+"g")(n))}(s,c),d="left",g="middle";if(s.fixedrange)return;m?(g="n"===m?"top":"bottom","right"===s.side&&(d="right")):"e"===v&&(d="right"),i._context.showAxisRangeEntryBoxes&&n.select(bt).call(u.makeEditable,{gd:i,immediate:!0,background:i._fullLayout.paper_bgcolor,text:String(h),fill:s.tickfont?s.tickfont.color:"#444",horizontalAlign:d,verticalAlign:g}).on("edit",(function(t){var e=s.d2r(t);void 0!==e&&l.call("_guiRelayout",i,f,e)}))}}}function zt(e,r){if(t._transitioningWithDuration)return!1;var n=Math.max(0,Math.min(tt,pt*e+_t)),i=Math.max(0,Math.min(et,dt*r+wt)),a=Math.abs(n-_t),o=Math.abs(i-wt);function s(){St="",Tt.r=Tt.l,Tt.t=Tt.b,Lt.attr("d","M0,0Z")}if(Tt.l=Math.min(_t,n),Tt.r=Math.max(_t,n),Tt.t=Math.min(wt,i),Tt.b=Math.max(wt,i),rt.isSubplotConstrained)a>P||o>P?(St="xy",a/tt>o/et?(o=a*et/tt,wt>i?Tt.t=wt-o:Tt.b=wt+o):(a=o*tt/et,_t>n?Tt.l=_t-a:Tt.r=_t+a),Lt.attr("d",G(Tt))):s();else if(nt.isSubplotConstrained)if(a>P||o>P){St="xy";var l=Math.min(Tt.l/tt,(et-Tt.b)/et),c=Math.max(Tt.r/tt,(et-Tt.t)/et);Tt.l=l*tt,Tt.r=c*tt,Tt.b=(1-l)*et,Tt.t=(1-c)*et,Lt.attr("d",G(Tt))}else s();else!at||o<Math.min(Math.max(.6*a,C),P)?a<C||!it?s():(Tt.t=0,Tt.b=et,St="x",Lt.attr("d",function(t,e){return"M"+(t.l-.5)+","+(e-P-.5)+"h-3v"+(2*P+1)+"h3ZM"+(t.r+.5)+","+(e-P-.5)+"h3v"+(2*P+1)+"h-3Z"}(Tt,wt))):!it||a<Math.min(.6*o,P)?(Tt.l=0,Tt.r=tt,St="y",Lt.attr("d",function(t,e){return"M"+(e-P-.5)+","+(t.t-.5)+"v-3h"+(2*P+1)+"v3ZM"+(e-P-.5)+","+(t.b+.5)+"v3h"+(2*P+1)+"v-3Z"}(Tt,_t))):(St="xy",Lt.attr("d",G(Tt)));Tt.w=Tt.r-Tt.l,Tt.h=Tt.b-Tt.t,St&&(Ct=!0),t._dragged=Ct,U(Et,Lt,Tt,At,Mt,kt),Dt(),t.emit("plotly_relayouting",ht),Mt=!0}function Dt(){ht={},"xy"!==St&&"x"!==St||(R(J,Tt.l/tt,Tt.r/tt,ht,rt.xaxes),Vt("x",ht)),"xy"!==St&&"y"!==St||(R(K,(et-Tt.b)/et,(et-Tt.t)/et,ht,rt.yaxes),Vt("y",ht))}function Rt(){Dt(),H(t),Gt(),q(t)}Pt.prepFn=function(e,r,n){var a=Pt.dragmode,s=t._fullLayout.dragmode;s!==a&&(Pt.dragmode=s),yt(),pt=t._fullLayout._invScaleX,dt=t._fullLayout._invScaleY,ot||(gt?e.shiftKey?"pan"===s?s="zoom":y(s)||(s="pan"):e.ctrlKey&&(s="pan"):s="pan"),x(s)?Pt.minDrag=1:Pt.minDrag=void 0,y(s)?(Pt.xaxes=J,Pt.yaxes=K,A(e,r,n,Pt,s)):(Pt.clickFn=Ot,y(a)&&It(),ot||("zoom"===s?(Pt.moveFn=zt,Pt.doneFn=Rt,Pt.minDrag=1,function(e,r,n){var a=bt.getBoundingClientRect();_t=r-a.left,wt=n-a.top,t._fullLayout._calcInverseTransform(t);var s=i.apply3DTransform(t._fullLayout._invTransform)(_t,wt);_t=s[0],wt=s[1],Tt={l:_t,r:_t,w:0,t:wt,b:wt,h:0},kt=t._hmpixcount?t._hmlumcount/t._hmpixcount:o(t._fullLayout.plot_bgcolor).getLuminance(),Mt=!1,St="xy",Ct=!1,Et=N(mt,kt,Q,$,At="M0,0H"+tt+"V"+et+"H0V0"),Lt=j(mt,Q,$)}(0,r,n)):"pan"===s&&(Pt.moveFn=Ut,Pt.doneFn=Gt))),t._fullLayout._redrag=function(){var e=t._dragdata;if(e&&e.element===bt){var r=t._fullLayout.dragmode;y(r)||(yt(),Yt([0,0,tt,et]),Pt.moveFn(e.dx,e.dy))}}},g.init(Pt);var Ft=[0,0,tt,et],Bt=null,Nt=L.REDRAWDELAY,jt=e.mainplot?t._fullLayout._plots[e.mainplot]:e;function Ut(e,r){if(e*=pt,r*=dt,!t._transitioningWithDuration){if(t._fullLayout._replotting=!0,"ew"===it||"ns"===at){var n=it?-e:0,i=at?-r:0;if(nt.isSubplotConstrained){if(it&&at){var a=(e/tt-r/et)/2;n=-(e=a*tt),i=-(r=-a*et)}at?n=-i*tt/et:i=-n*et/tt}return it&&(F(J,e),Vt("x")),at&&(F(K,r),Vt("y")),Yt([n,i,tt,et]),Ht(),void t.emit("plotly_relayouting",ht)}var o,s,l="w"===it==("n"===at)?1:-1;if(it&&at&&(rt.isSubplotConstrained||nt.isSubplotConstrained)){var c=(e/tt+l*r/et)/2;e=c*tt,r=l*c*et}if("w"===it?e=p(J,0,e):"e"===it?e=p(J,1,-e):it||(e=0),"n"===at?r=p(K,1,r):"s"===at?r=p(K,0,-r):at||(r=0),o="w"===it?e:0,s="n"===at?r:0,rt.isSubplotConstrained&&!nt.isSubplotConstrained||nt.isSubplotConstrained&&it&&at&&l>0){var u;if(nt.isSubplotConstrained||!it&&1===at.length){for(u=0;u<J.length;u++)J[u].range=J[u]._r.slice(),E(J[u],1-r/et);o=(e=r*tt/et)/2}if(nt.isSubplotConstrained||!at&&1===it.length){for(u=0;u<K.length;u++)K[u].range=K[u]._r.slice(),E(K[u],1-e/tt);s=(r=e*et/tt)/2}}nt.isSubplotConstrained&&at||Vt("x"),nt.isSubplotConstrained&&it||Vt("y");var f=tt-e,h=et-r;!nt.isSubplotConstrained||it&&at||(it?(s=o?0:e*et/tt,h=f*et/tt):(o=s?0:r*tt/et,f=h*tt/et)),Yt([o,s,f,h]),Ht(),t.emit("plotly_relayouting",ht)}function p(t,e,r){for(var n,i,a=1-e,o=0;o<t.length;o++){var s=t[o];if(!s.fixedrange){n=s,i=s._rl[a]+(s._rl[e]-s._rl[a])/B(r/s._length);var l=s.l2r(i);!1!==l&&void 0!==l&&(s.range[e]=l)}}return n._length*(n._rl[e]-i)/(n._rl[e]-n._rl[a])}}function Vt(t,e){for(var r=nt.isSubplotConstrained?{x:K,y:J}[t]:nt[t+"axes"],n=nt.isSubplotConstrained?{x:J,y:K}[t]:[],i=0;i<r.length;i++){var a=r[i],o=a._id,s=nt.xLinks[o]||nt.yLinks[o],l=n[0]||V[s]||Z[s];l&&(e?(e[a._name+".range[0]"]=e[l._name+".range[0]"],e[a._name+".range[1]"]=e[l._name+".range[1]"]):a.range=l.range.slice())}}function Ht(){var e,r=[];function n(t){for(e=0;e<t.length;e++)t[e].fixedrange||r.push(t[e]._id)}for(st&&(n(J),n(rt.xaxes),n(nt.xaxes)),lt&&(n(K),n(rt.yaxes),n(nt.yaxes)),ht={},e=0;e<r.length;e++){var i=r[e],a=k(t,i);d.drawOne(t,a,{skipTitle:!0}),ht[a._name+".range[0]"]=a.range[0],ht[a._name+".range[1]"]=a.range[1]}d.redrawComponents(t,r)}function qt(){if(!t._transitioningWithDuration){var e=t._context.doubleClick,r=[];it&&(r=r.concat(J)),at&&(r=r.concat(K)),nt.xaxes&&(r=r.concat(nt.xaxes)),nt.yaxes&&(r=r.concat(nt.yaxes));var n,i,a,o={};if("reset+autosize"===e)for(e="autosize",i=0;i<r.length;i++)if((n=r[i])._rangeInitial&&(n.range[0]!==n._rangeInitial[0]||n.range[1]!==n._rangeInitial[1])||!n._rangeInitial&&!n.autorange){e="reset";break}if("autosize"===e)for(i=0;i<r.length;i++)(n=r[i]).fixedrange||(o[n._name+".autorange"]=!0);else if("reset"===e)for((it||rt.isSubplotConstrained)&&(r=r.concat(rt.xaxes)),at&&!rt.isSubplotConstrained&&(r=r.concat(rt.yaxes)),rt.isSubplotConstrained&&(it?at||(r=r.concat(K)):r=r.concat(J)),i=0;i<r.length;i++)(n=r[i]).fixedrange||(n._rangeInitial?(a=n._rangeInitial,o[n._name+".range[0]"]=a[0],o[n._name+".range[1]"]=a[1]):o[n._name+".autorange"]=!0);t.emit("plotly_doubleclick",null),l.call("_guiRelayout",t,o)}}function Gt(){Yt([0,0,tt,et]),i.syncOrAsync([T.previousPromises,function(){t._fullLayout._replotting=!1,l.call("_guiRelayout",t,ht)}],t)}function Yt(e){var r,n,a,o,s=t._fullLayout,c=s._plots,u=s._subplots.cartesian;if(ut&&l.subplotsRegistry.splom.drag(t),ct)for(r=0;r<u.length;r++)if(a=(n=c[u[r]]).xaxis,o=n.yaxis,n._scene){var f=i.simpleMap(a.range,a.r2l),p=i.simpleMap(o.range,o.r2l);n._scene.update({range:[f[0],p[0],f[1],p[1]]})}if((ut||ct)&&(_(t),w(t)),ft){var d=e[2]/I._length,g=e[3]/O._length;for(r=0;r<u.length;r++){a=(n=c[u[r]]).xaxis,o=n.yaxis;var y,x,b,T,k=(st||nt.isSubplotConstrained)&&!a.fixedrange&&V[a._id],A=(lt||nt.isSubplotConstrained)&&!o.fixedrange&&Z[o._id];if(k?(y=d,b=v||nt.isSubplotConstrained?e[0]:Zt(a,y)):nt.xaHash[a._id]?(y=d,b=e[0]*a._length/I._length):nt.yaHash[a._id]?(y=g,b="ns"===at?-e[1]*a._length/O._length:Zt(a,y,{n:"top",s:"bottom"}[at])):b=Xt(a,y=Wt(a,d,g)),A?(x=g,T=m||nt.isSubplotConstrained?e[1]:Zt(o,x)):nt.yaHash[o._id]?(x=g,T=e[1]*o._length/O._length):nt.xaHash[o._id]?(x=d,T="ew"===it?-e[0]*o._length/I._length:Zt(o,x,{e:"right",w:"left"}[it])):T=Xt(o,x=Wt(o,d,g)),y||x){y||(y=1),x||(x=1);var M=a._offset-b/y,S=o._offset-T/x;n.clipRect.call(h.setTranslate,b,T).call(h.setScale,y,x),n.plot.call(h.setTranslate,M,S).call(h.setScale,1/y,1/x),y===n.xScaleFactor&&x===n.yScaleFactor||(h.setPointGroupScale(n.zoomScalePts,y,x),h.setTextPointsScale(n.zoomScaleTxt,y,x)),h.hideOutsideRangePoints(n.clipOnAxisFalseTraces,n),n.xScaleFactor=y,n.yScaleFactor=x}}}}function Wt(t,e,r){return t.fixedrange?0:st&&rt.xaHash[t._id]?e:lt&&(rt.isSubplotConstrained?rt.xaHash:rt.yaHash)[t._id]?r:0}function Xt(t,e){return e?(t.range=t._r.slice(),E(t,e),Zt(t,e)):0}function Zt(t,e,r){return t._length*(1-e)*b[r||t.constraintoward||"middle"]}return m.length*v.length!=1&&W(bt,(function(e){if(t._context._scrollZoom.cartesian||t._fullLayout._enablescrollzoom){if(It(),t._transitioningWithDuration)return e.preventDefault(),void e.stopPropagation();yt(),clearTimeout(Bt);var r=-e.deltaY;if(isFinite(r)||(r=e.wheelDelta/10),isFinite(r)){var n,a=Math.exp(-Math.min(Math.max(r,-20),20)/200),o=jt.draglayer.select(".nsewdrag").node().getBoundingClientRect(),s=(e.clientX-o.left)/o.width,l=(o.bottom-e.clientY)/o.height;if(st){for(v||(s=.5),n=0;n<J.length;n++)c(J[n],s,a);Vt("x"),Ft[2]*=a,Ft[0]+=Ft[2]*s*(1/a-1)}if(lt){for(m||(l=.5),n=0;n<K.length;n++)c(K[n],l,a);Vt("y"),Ft[3]*=a,Ft[1]+=Ft[3]*(1-l)*(1/a-1)}Yt(Ft),Ht(),t.emit("plotly_relayouting",ht),Bt=setTimeout((function(){t._fullLayout&&(Ft=[0,0,tt,et],Gt())}),Nt),e.preventDefault()}else i.log("Did not find wheel motion attributes: ",e)}function c(t,e,r){if(!t.fixedrange){var n=i.simpleMap(t.range,t.r2l),a=n[0]+(n[1]-n[0])*e;t.range=n.map((function(e){return t.l2r(a+(e-a)*r)}))}}})),bt},makeDragger:O,makeRectDragger:z,makeZoombox:N,makeCorners:j,updateZoombox:U,xyCorners:G,transitionZoombox:V,removeZoombox:H,showDoubleClickNotifier:q,attachWheelEventHandler:W}},{"../../components/color":366,"../../components/dragelement":385,"../../components/dragelement/helpers":384,"../../components/drawing":388,"../../components/fx":406,"../../constants/alignment":471,"../../lib":503,"../../lib/clear_gl_canvases":487,"../../lib/setcursor":524,"../../lib/svg_text_utils":529,"../../plot_api/subroutines":544,"../../registry":638,"../plots":619,"./axes":554,"./axis_ids":558,"./constants":561,"./scale_zoom":574,"./select":575,"@plotly/d3":58,"has-passive-events":229,tinycolor2:312}],564:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/fx"),a=t("../../components/dragelement"),o=t("../../lib/setcursor"),s=t("./dragbox").makeDragBox,l=t("./constants").DRAGGERSIZE;r.initInteractions=function(t){var e=t._fullLayout;if(t._context.staticPlot)n.select(t).selectAll(".drag").remove();else if(e._has("cartesian")||e._has("splom")){Object.keys(e._plots||{}).sort((function(t,r){if((e._plots[t].mainplot&&!0)===(e._plots[r].mainplot&&!0)){var n=t.split("y"),i=r.split("y");return n[0]===i[0]?Number(n[1]||1)-Number(i[1]||1):Number(n[0]||1)-Number(i[0]||1)}return e._plots[t].mainplot?1:-1})).forEach((function(r){var n=e._plots[r],o=n.xaxis,c=n.yaxis;if(!n.mainplot){var u=s(t,n,o._offset,c._offset,o._length,c._length,"ns","ew");u.onmousemove=function(e){t._fullLayout._rehover=function(){t._fullLayout._hoversubplot===r&&t._fullLayout._plots[r]&&i.hover(t,e,r)},i.hover(t,e,r),t._fullLayout._lasthover=u,t._fullLayout._hoversubplot=r},u.onmouseout=function(e){t._dragging||(t._fullLayout._hoversubplot=null,a.unhover(t,e))},t._context.showAxisDragHandles&&(s(t,n,o._offset-l,c._offset-l,l,l,"n","w"),s(t,n,o._offset+o._length,c._offset-l,l,l,"n","e"),s(t,n,o._offset-l,c._offset+c._length,l,l,"s","w"),s(t,n,o._offset+o._length,c._offset+c._length,l,l,"s","e"))}if(t._context.showAxisDragHandles){if(r===o._mainSubplot){var f=o._mainLinePosition;"top"===o.side&&(f-=l),s(t,n,o._offset+.1*o._length,f,.8*o._length,l,"","ew"),s(t,n,o._offset,f,.1*o._length,l,"","w"),s(t,n,o._offset+.9*o._length,f,.1*o._length,l,"","e")}if(r===c._mainSubplot){var h=c._mainLinePosition;"right"!==c.side&&(h-=l),s(t,n,h,c._offset+.1*c._length,l,.8*c._length,"ns",""),s(t,n,h,c._offset+.9*c._length,l,.1*c._length,"s",""),s(t,n,h,c._offset,l,.1*c._length,"n","")}}}));var o=e._hoverlayer.node();o.onmousemove=function(r){r.target=t._fullLayout._lasthover,i.hover(t,r,e._hoversubplot)},o.onclick=function(e){e.target=t._fullLayout._lasthover,i.click(t,e)},o.onmousedown=function(e){t._fullLayout._lasthover.onmousedown(e)},r.updateFx(t)}},r.updateFx=function(t){var e=t._fullLayout,r="pan"===e.dragmode?"move":"crosshair";o(e._draggers,r)}},{"../../components/dragelement":385,"../../components/fx":406,"../../lib/setcursor":524,"./constants":561,"./dragbox":563,"@plotly/d3":58}],565:[function(t,e,r){"use strict";e.exports={clearOutlineControllers:function(t){var e=t._fullLayout._zoomlayer;e&&e.selectAll(".outline-controllers").remove()},clearSelect:function(t){var e=t._fullLayout._zoomlayer;e&&e.selectAll(".select-outline").remove(),t._fullLayout._drawing=!1}}},{}],566:[function(t,e,r){"use strict";var n=t("../../lib").strTranslate;function i(t,e){switch(t.type){case"log":return t.p2d(e);case"date":return t.p2r(e,0,t.calendar);default:return t.p2r(e)}}e.exports={p2r:i,r2p:function(t,e){switch(t.type){case"log":return t.d2p(e);case"date":return t.r2p(e,0,t.calendar);default:return t.r2p(e)}},axValue:function(t){var e="y"===t._id.charAt(0)?1:0;return function(r){return i(t,r[e])}},getTransform:function(t){return n(t.xaxis._offset,t.yaxis._offset)}}},{"../../lib":503}],567:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib"),a=t("./axis_ids");e.exports=function(t){return function(e,r){var o=e[t];if(Array.isArray(o))for(var s=n.subplotsRegistry.cartesian,l=s.idRegex,c=r._subplots,u=c.xaxis,f=c.yaxis,h=c.cartesian,p=r._has("cartesian")||r._has("gl2d"),d=0;d<o.length;d++){var m=o[d];if(i.isPlainObject(m)){var g=a.cleanId(m.xref,"x",!1),v=a.cleanId(m.yref,"y",!1),y=l.x.test(g),x=l.y.test(v);if(y||x){p||i.pushUnique(r._basePlotModules,s);var b=!1;y&&-1===u.indexOf(g)&&(u.push(g),b=!0),x&&-1===f.indexOf(v)&&(f.push(v),b=!0),b&&y&&x&&h.push(g+v)}}}}}},{"../../lib":503,"../../registry":638,"./axis_ids":558}],568:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../registry"),a=t("../../lib"),o=t("../plots"),s=t("../../components/drawing"),l=t("../get_data").getModuleCalcData,c=t("./axis_ids"),u=t("./constants"),f=t("../../constants/xmlns_namespaces"),h=a.ensureSingle;function p(t,e,r){return a.ensureSingle(t,e,r,(function(t){t.datum(r)}))}function d(t,e,r,a,o){for(var c,f,h,p=u.traceLayerClasses,d=t._fullLayout,m=d._modules,g=[],v=[],y=0;y<m.length;y++){var x=(c=m[y]).name,b=i.modules[x].categories;if(b.svg){var _=c.layerName||x+"layer",w=c.plot;h=(f=l(r,w))[0],r=f[1],h.length&&g.push({i:p.indexOf(_),className:_,plotMethod:w,cdModule:h}),b.zoomScale&&v.push("."+_)}}g.sort((function(t,e){return t.i-e.i}));var T=e.plot.selectAll("g.mlayer").data(g,(function(t){return t.className}));if(T.enter().append("g").attr("class",(function(t){return t.className})).classed("mlayer",!0).classed("rangeplot",e.isRangePlot),T.exit().remove(),T.order(),T.each((function(r){var i=n.select(this),l=r.className;r.plotMethod(t,e,r.cdModule,i,a,o),-1===u.clipOnAxisFalseQuery.indexOf("."+l)&&s.setClipUrl(i,e.layerClipId,t)})),d._has("scattergl")&&(c=i.getModule("scattergl"),h=l(r,c)[0],c.plot(t,e,h)),!t._context.staticPlot&&(e._hasClipOnAxisFalse&&(e.clipOnAxisFalseTraces=e.plot.selectAll(u.clipOnAxisFalseQuery.join(",")).selectAll(".trace")),v.length)){var k=e.plot.selectAll(v.join(",")).selectAll(".trace");e.zoomScalePts=k.selectAll("path.point"),e.zoomScaleTxt=k.selectAll(".textpoint")}}function m(t,e){var r=e.plotgroup,n=e.id,i=u.layerValue2layerClass[e.xaxis.layer],a=u.layerValue2layerClass[e.yaxis.layer],o=t._fullLayout._hasOnlyLargeSploms;if(e.mainplot){var s=e.mainplotinfo,l=s.plotgroup,f=n+"-x",d=n+"-y";e.minorGridlayer=s.minorGridlayer,e.gridlayer=s.gridlayer,e.zerolinelayer=s.zerolinelayer,h(s.overlinesBelow,"path",f),h(s.overlinesBelow,"path",d),h(s.overaxesBelow,"g",f),h(s.overaxesBelow,"g",d),e.plot=h(s.overplot,"g",n),h(s.overlinesAbove,"path",f),h(s.overlinesAbove,"path",d),h(s.overaxesAbove,"g",f),h(s.overaxesAbove,"g",d),e.xlines=l.select(".overlines-"+i).select("."+f),e.ylines=l.select(".overlines-"+a).select("."+d),e.xaxislayer=l.select(".overaxes-"+i).select("."+f),e.yaxislayer=l.select(".overaxes-"+a).select("."+d)}else if(o)e.xlines=h(r,"path","xlines-above"),e.ylines=h(r,"path","ylines-above"),e.xaxislayer=h(r,"g","xaxislayer-above"),e.yaxislayer=h(r,"g","yaxislayer-above");else{var m=h(r,"g","layer-subplot");e.shapelayer=h(m,"g","shapelayer"),e.imagelayer=h(m,"g","imagelayer"),e.minorGridlayer=h(r,"g","minor-gridlayer"),e.gridlayer=h(r,"g","gridlayer"),e.zerolinelayer=h(r,"g","zerolinelayer"),h(r,"path","xlines-below"),h(r,"path","ylines-below"),e.overlinesBelow=h(r,"g","overlines-below"),h(r,"g","xaxislayer-below"),h(r,"g","yaxislayer-below"),e.overaxesBelow=h(r,"g","overaxes-below"),e.plot=h(r,"g","plot"),e.overplot=h(r,"g","overplot"),e.xlines=h(r,"path","xlines-above"),e.ylines=h(r,"path","ylines-above"),e.overlinesAbove=h(r,"g","overlines-above"),h(r,"g","xaxislayer-above"),h(r,"g","yaxislayer-above"),e.overaxesAbove=h(r,"g","overaxes-above"),e.xlines=r.select(".xlines-"+i),e.ylines=r.select(".ylines-"+a),e.xaxislayer=r.select(".xaxislayer-"+i),e.yaxislayer=r.select(".yaxislayer-"+a)}o||(p(e.minorGridlayer,"g",e.xaxis._id),p(e.minorGridlayer,"g",e.yaxis._id),e.minorGridlayer.selectAll("g").map((function(t){return t[0]})).sort(c.idSort),p(e.gridlayer,"g",e.xaxis._id),p(e.gridlayer,"g",e.yaxis._id),e.gridlayer.selectAll("g").map((function(t){return t[0]})).sort(c.idSort)),e.xlines.style("fill","none").classed("crisp",!0),e.ylines.style("fill","none").classed("crisp",!0)}function g(t,e){if(t){var r={};for(var i in t.each((function(t){var i=t[0];n.select(this).remove(),v(i,e),r[i]=!0})),e._plots)for(var a=e._plots[i].overlays||[],o=0;o<a.length;o++){var s=a[o];r[s.id]&&s.plot.selectAll(".trace").remove()}}}function v(t,e){e._draggers.selectAll("g."+t).remove(),e._defs.select("#clip"+e._uid+t+"plot").remove()}r.name="cartesian",r.attr=["xaxis","yaxis"],r.idRoot=["x","y"],r.idRegex=u.idRegex,r.attrRegex=u.attrRegex,r.attributes=t("./attributes"),r.layoutAttributes=t("./layout_attributes"),r.supplyLayoutDefaults=t("./layout_defaults"),r.transitionAxes=t("./transition_axes"),r.finalizeSubplots=function(t,e){var r,n,i,o=e._subplots,s=o.xaxis,l=o.yaxis,f=o.cartesian,h=f.concat(o.gl2d||[]),p={},d={};for(r=0;r<h.length;r++){var m=h[r].split("y");p[m[0]]=1,d["y"+m[1]]=1}for(r=0;r<s.length;r++)p[n=s[r]]||(i=(t[c.id2name(n)]||{}).anchor,u.idRegex.y.test(i)||(i="y"),f.push(n+i),h.push(n+i),d[i]||(d[i]=1,a.pushUnique(l,i)));for(r=0;r<l.length;r++)d[i=l[r]]||(n=(t[c.id2name(i)]||{}).anchor,u.idRegex.x.test(n)||(n="x"),f.push(n+i),h.push(n+i),p[n]||(p[n]=1,a.pushUnique(s,n)));if(!h.length){for(var g in n="",i="",t){if(u.attrRegex.test(g))"x"===g.charAt(0)?(!n||+g.substr(5)<+n.substr(5))&&(n=g):(!i||+g.substr(5)<+i.substr(5))&&(i=g)}n=n?c.name2id(n):"x",i=i?c.name2id(i):"y",s.push(n),l.push(i),f.push(n+i)}},r.plot=function(t,e,r,n){var i,a=t._fullLayout,o=a._subplots.cartesian,s=t.calcdata;if(!Array.isArray(e))for(e=[],i=0;i<s.length;i++)e.push(i);for(i=0;i<o.length;i++){for(var l,c=o[i],u=a._plots[c],f=[],h=0;h<s.length;h++){var p=s[h],m=p[0].trace;m.xaxis+m.yaxis===c&&((-1!==e.indexOf(m.index)||m.carpet)&&(l&&l[0].trace.xaxis+l[0].trace.yaxis===c&&-1!==["tonextx","tonexty","tonext"].indexOf(m.fill)&&-1===f.indexOf(l)&&f.push(l),f.push(p)),l=p)}d(t,u,f,r,n)}},r.clean=function(t,e,r,n){var i,a,o,s=n._plots||{},l=e._plots||{},u=n._subplots||{};if(n._hasOnlyLargeSploms&&!e._hasOnlyLargeSploms)for(o in s)(i=s[o]).plotgroup&&i.plotgroup.remove();var f=n._has&&n._has("gl"),h=e._has&&e._has("gl");if(f&&!h)for(o in s)(i=s[o])._scene&&i._scene.destroy();if(u.xaxis&&u.yaxis){var p=c.listIds({_fullLayout:n});for(a=0;a<p.length;a++){var d=p[a];e[c.id2name(d)]||n._infolayer.selectAll(".g-"+d+"title").remove()}}var m=n._has&&n._has("cartesian"),y=e._has&&e._has("cartesian");if(m&&!y)g(n._cartesianlayer.selectAll(".subplot"),n),n._defs.selectAll(".axesclip").remove(),delete n._axisConstraintGroups,delete n._axisMatchGroups;else if(u.cartesian)for(a=0;a<u.cartesian.length;a++){var x=u.cartesian[a];if(!l[x]){var b="."+x+",."+x+"-x,."+x+"-y";n._cartesianlayer.selectAll(b).remove(),v(x,n)}}},r.drawFramework=function(t){var e=t._fullLayout,r=function(t){var e,r,n,i,a,o,s=t._fullLayout,l=s._subplots.cartesian,c=l.length,u=[],f=[];for(e=0;e<c;e++){n=l[e],i=s._plots[n],a=i.xaxis,o=i.yaxis;var h=a._mainAxis,p=o._mainAxis,d=h._id+p._id,m=s._plots[d];i.overlays=[],d!==n&&m?(i.mainplot=d,i.mainplotinfo=m,f.push(n)):(i.mainplot=void 0,i.mainplotinfo=void 0,u.push(n))}for(e=0;e<f.length;e++)n=f[e],(i=s._plots[n]).mainplotinfo.overlays.push(i);var g=u.concat(f),v=new Array(c);for(e=0;e<c;e++){n=g[e],i=s._plots[n],a=i.xaxis,o=i.yaxis;var y=[n,a.layer,o.layer,a.overlaying||"",o.overlaying||""];for(r=0;r<i.overlays.length;r++)y.push(i.overlays[r].id);v[e]=y}return v}(t),i=e._cartesianlayer.selectAll(".subplot").data(r,String);i.enter().append("g").attr("class",(function(t){return"subplot "+t[0]})),i.order(),i.exit().call(g,e),i.each((function(r){var i=r[0],a=e._plots[i];a.plotgroup=n.select(this),m(t,a),a.draglayer=h(e._draggers,"g",i)}))},r.rangePlot=function(t,e,r){m(t,e),d(t,e,r),o.style(t)},r.toSVG=function(t){var e=t._fullLayout._glimages,r=n.select(t).selectAll(".svg-container");r.filter((function(t,e){return e===r.size()-1})).selectAll(".gl-canvas-context, .gl-canvas-focus").each((function(){var t=this.toDataURL("image/png");e.append("svg:image").attr({xmlns:f.svg,"xlink:href":t,preserveAspectRatio:"none",x:0,y:0,width:this.style.width,height:this.style.height})}))},r.updateFx=t("./graph_interact").updateFx},{"../../components/drawing":388,"../../constants/xmlns_namespaces":480,"../../lib":503,"../../registry":638,"../get_data":593,"../plots":619,"./attributes":552,"./axis_ids":558,"./constants":561,"./graph_interact":564,"./layout_attributes":569,"./layout_defaults":570,"./transition_axes":581,"@plotly/d3":58}],569:[function(t,e,r){"use strict";var n=t("../font_attributes"),i=t("../../components/color/attributes"),a=t("../../components/drawing/attributes").dash,o=t("../../lib/extend").extendFlat,s=t("../../plot_api/plot_template").templatedArray,l=t("../../plots/cartesian/axis_format_attributes").descriptionWithDates,c=t("../../constants/numerical").ONEDAY,u=t("./constants"),f=u.HOUR_PATTERN,h=u.WEEKDAY_PATTERN,p={valType:"enumerated",values:["auto","linear","array"],editType:"ticks",impliedEdits:{tick0:void 0,dtick:void 0}};function d(t){return{valType:"integer",min:0,dflt:t?5:0,editType:"ticks"}}var m={valType:"any",editType:"ticks",impliedEdits:{tickmode:"linear"}},g={valType:"any",editType:"ticks",impliedEdits:{tickmode:"linear"}},v={valType:"data_array",editType:"ticks"},y={valType:"enumerated",values:["outside","inside",""],editType:"ticks"};function x(t){var e={valType:"number",min:0,editType:"ticks"};return t||(e.dflt=5),e}function b(t){var e={valType:"number",min:0,editType:"ticks"};return t||(e.dflt=1),e}var _={valType:"color",dflt:i.defaultLine,editType:"ticks"},w={valType:"color",dflt:i.lightLine,editType:"ticks"};function T(t){var e={valType:"number",min:0,editType:"ticks"};return t||(e.dflt=1),e}var k=o({},a,{editType:"ticks"}),A={valType:"boolean",editType:"ticks"};e.exports={visible:{valType:"boolean",editType:"plot"},color:{valType:"color",dflt:i.defaultLine,editType:"ticks"},title:{text:{valType:"string",editType:"ticks"},font:n({editType:"ticks"}),standoff:{valType:"number",min:0,editType:"ticks"},editType:"ticks"},type:{valType:"enumerated",values:["-","linear","log","date","category","multicategory"],dflt:"-",editType:"calc",_noTemplating:!0},autotypenumbers:{valType:"enumerated",values:["convert types","strict"],dflt:"convert types",editType:"calc"},autorange:{valType:"enumerated",values:[!0,!1,"reversed"],dflt:!0,editType:"axrange",impliedEdits:{"range[0]":void 0,"range[1]":void 0}},rangemode:{valType:"enumerated",values:["normal","tozero","nonnegative"],dflt:"normal",editType:"plot"},range:{valType:"info_array",items:[{valType:"any",editType:"axrange",impliedEdits:{"^autorange":!1},anim:!0},{valType:"any",editType:"axrange",impliedEdits:{"^autorange":!1},anim:!0}],editType:"axrange",impliedEdits:{autorange:!1},anim:!0},fixedrange:{valType:"boolean",dflt:!1,editType:"calc"},scaleanchor:{valType:"enumerated",values:[u.idRegex.x.toString(),u.idRegex.y.toString()],editType:"plot"},scaleratio:{valType:"number",min:0,dflt:1,editType:"plot"},constrain:{valType:"enumerated",values:["range","domain"],editType:"plot"},constraintoward:{valType:"enumerated",values:["left","center","right","top","middle","bottom"],editType:"plot"},matches:{valType:"enumerated",values:[u.idRegex.x.toString(),u.idRegex.y.toString()],editType:"calc"},rangebreaks:s("rangebreak",{enabled:{valType:"boolean",dflt:!0,editType:"calc"},bounds:{valType:"info_array",items:[{valType:"any",editType:"calc"},{valType:"any",editType:"calc"}],editType:"calc"},pattern:{valType:"enumerated",values:[h,f,""],editType:"calc"},values:{valType:"info_array",freeLength:!0,editType:"calc",items:{valType:"any",editType:"calc"}},dvalue:{valType:"number",editType:"calc",min:0,dflt:c},editType:"calc"}),tickmode:p,nticks:d(),tick0:m,dtick:g,ticklabelstep:{valType:"integer",min:1,dflt:1,editType:"ticks"},tickvals:v,ticktext:{valType:"data_array",editType:"ticks"},ticks:y,tickson:{valType:"enumerated",values:["labels","boundaries"],dflt:"labels",editType:"ticks"},ticklabelmode:{valType:"enumerated",values:["instant","period"],dflt:"instant",editType:"ticks"},ticklabelposition:{valType:"enumerated",values:["outside","inside","outside top","inside top","outside left","inside left","outside right","inside right","outside bottom","inside bottom"],dflt:"outside",editType:"calc"},ticklabeloverflow:{valType:"enumerated",values:["allow","hide past div","hide past domain"],editType:"calc"},mirror:{valType:"enumerated",values:[!0,"ticks",!1,"all","allticks"],dflt:!1,editType:"ticks+layoutstyle"},ticklen:x(),tickwidth:b(),tickcolor:_,showticklabels:{valType:"boolean",dflt:!0,editType:"ticks"},automargin:{valType:"boolean",dflt:!1,editType:"ticks"},showspikes:{valType:"boolean",dflt:!1,editType:"modebar"},spikecolor:{valType:"color",dflt:null,editType:"none"},spikethickness:{valType:"number",dflt:3,editType:"none"},spikedash:o({},a,{dflt:"dash",editType:"none"}),spikemode:{valType:"flaglist",flags:["toaxis","across","marker"],dflt:"toaxis",editType:"none"},spikesnap:{valType:"enumerated",values:["data","cursor","hovered data"],dflt:"hovered data",editType:"none"},tickfont:n({editType:"ticks"}),tickangle:{valType:"angle",dflt:"auto",editType:"ticks"},tickprefix:{valType:"string",dflt:"",editType:"ticks"},showtickprefix:{valType:"enumerated",values:["all","first","last","none"],dflt:"all",editType:"ticks"},ticksuffix:{valType:"string",dflt:"",editType:"ticks"},showticksuffix:{valType:"enumerated",values:["all","first","last","none"],dflt:"all",editType:"ticks"},showexponent:{valType:"enumerated",values:["all","first","last","none"],dflt:"all",editType:"ticks"},exponentformat:{valType:"enumerated",values:["none","e","E","power","SI","B"],dflt:"B",editType:"ticks"},minexponent:{valType:"number",dflt:3,min:0,editType:"ticks"},separatethousands:{valType:"boolean",dflt:!1,editType:"ticks"},tickformat:{valType:"string",dflt:"",editType:"ticks",description:l("tick label")},tickformatstops:s("tickformatstop",{enabled:{valType:"boolean",dflt:!0,editType:"ticks"},dtickrange:{valType:"info_array",items:[{valType:"any",editType:"ticks"},{valType:"any",editType:"ticks"}],editType:"ticks"},value:{valType:"string",dflt:"",editType:"ticks"},editType:"ticks"}),hoverformat:{valType:"string",dflt:"",editType:"none",description:l("hover text")},showline:{valType:"boolean",dflt:!1,editType:"ticks+layoutstyle"},linecolor:{valType:"color",dflt:i.defaultLine,editType:"layoutstyle"},linewidth:{valType:"number",min:0,dflt:1,editType:"ticks+layoutstyle"},showgrid:A,gridcolor:w,gridwidth:T(),griddash:k,zeroline:{valType:"boolean",editType:"ticks"},zerolinecolor:{valType:"color",dflt:i.defaultLine,editType:"ticks"},zerolinewidth:{valType:"number",dflt:1,editType:"ticks"},showdividers:{valType:"boolean",dflt:!0,editType:"ticks"},dividercolor:{valType:"color",dflt:i.defaultLine,editType:"ticks"},dividerwidth:{valType:"number",dflt:1,editType:"ticks"},anchor:{valType:"enumerated",values:["free",u.idRegex.x.toString(),u.idRegex.y.toString()],editType:"plot"},side:{valType:"enumerated",values:["top","bottom","left","right"],editType:"plot"},overlaying:{valType:"enumerated",values:["free",u.idRegex.x.toString(),u.idRegex.y.toString()],editType:"plot"},minor:{tickmode:p,nticks:d("minor"),tick0:m,dtick:g,tickvals:v,ticks:y,ticklen:x("minor"),tickwidth:b("minor"),tickcolor:_,gridcolor:w,gridwidth:T("minor"),griddash:k,showgrid:A,editType:"ticks"},layer:{valType:"enumerated",values:["above traces","below traces"],dflt:"above traces",editType:"plot"},domain:{valType:"info_array",items:[{valType:"number",min:0,max:1,editType:"plot"},{valType:"number",min:0,max:1,editType:"plot"}],dflt:[0,1],editType:"plot"},position:{valType:"number",min:0,max:1,dflt:0,editType:"plot"},categoryorder:{valType:"enumerated",values:["trace","category ascending","category descending","array","total ascending","total descending","min ascending","min descending","max ascending","max descending","sum ascending","sum descending","mean ascending","mean descending","median ascending","median descending"],dflt:"trace",editType:"calc"},categoryarray:{valType:"data_array",editType:"calc"},uirevision:{valType:"any",editType:"none"},editType:"calc",_deprecated:{autotick:{valType:"boolean",editType:"ticks"},title:{valType:"string",editType:"ticks"},titlefont:n({editType:"ticks"})}}},{"../../components/color/attributes":365,"../../components/drawing/attributes":387,"../../constants/numerical":479,"../../lib/extend":493,"../../plot_api/plot_template":543,"../../plots/cartesian/axis_format_attributes":557,"../font_attributes":585,"./constants":561}],570:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/color"),a=t("../../components/fx/helpers").isUnifiedHover,o=t("../../components/fx/hovermode_defaults"),s=t("../../plot_api/plot_template"),l=t("../layout_attributes"),c=t("./layout_attributes"),u=t("./type_defaults"),f=t("./axis_defaults"),h=t("./constraints"),p=t("./position_defaults"),d=t("./axis_ids"),m=d.id2name,g=d.name2id,v=t("./constants").AX_ID_PATTERN,y=t("../../registry"),x=y.traceIs,b=y.getComponentMethod;function _(t,e,r){Array.isArray(t[e])?t[e].push(r):t[e]=[r]}e.exports=function(t,e,r){var y,w,T=e.autotypenumbers,k={},A={},M={},S={},E={},L={},C={},P={},I={},O={};for(y=0;y<r.length;y++){var z=r[y];if(x(z,"cartesian")||x(z,"gl2d")){var D,R;if(z.xaxis)D=m(z.xaxis),_(k,D,z);else if(z.xaxes)for(w=0;w<z.xaxes.length;w++)_(k,m(z.xaxes[w]),z);if(z.yaxis)R=m(z.yaxis),_(k,R,z);else if(z.yaxes)for(w=0;w<z.yaxes.length;w++)_(k,m(z.yaxes[w]),z);if("funnel"===z.type?"h"===z.orientation?(D&&(A[D]=!0),R&&(C[R]=!0)):R&&(M[R]=!0):"image"===z.type?(R&&(P[R]=!0),D&&(P[D]=!0)):(R&&(E[R]=!0,L[R]=!0),x(z,"carpet")&&("carpet"!==z.type||z._cheater)||D&&(S[D]=!0)),"carpet"===z.type&&z._cheater&&D&&(A[D]=!0),x(z,"2dMap")&&(I[D]=!0,I[R]=!0),x(z,"oriented"))O["h"===z.orientation?R:D]=!0}}var F=e._subplots,B=F.xaxis,N=F.yaxis,j=n.simpleMap(B,m),U=n.simpleMap(N,m),V=j.concat(U),H=i.background;B.length&&N.length&&(H=n.coerce(t,e,l,"plot_bgcolor"));var q,G,Y,W,X,Z=i.combine(H,e.paper_bgcolor);function J(){var t=k[q]||[];X._traceIndices=t.map((function(t){return t._expandedIndex})),X._annIndices=[],X._shapeIndices=[],X._imgIndices=[],X._subplotsWith=[],X._counterAxes=[],X._name=X._attr=q,X._id=G}function K(t,e){return n.coerce(W,X,c,t,e)}function Q(t,e){return n.coerce2(W,X,c,t,e)}function $(t){return"x"===t?N:B}function tt(e,r){for(var n="x"===e?j:U,i=[],a=0;a<n.length;a++){var o=n[a];o===r||(t[o]||{}).overlaying||i.push(g(o))}return i}var et={x:$("x"),y:$("y")},rt=et.x.concat(et.y),nt={},it=[];function at(){var t=W.matches;v.test(t)&&-1===rt.indexOf(t)&&(nt[t]=W.type,it=Object.keys(nt))}var ot=o(t,e),st=a(ot);for(y=0;y<V.length;y++){q=V[y],G=g(q),Y=q.charAt(0),n.isPlainObject(t[q])||(t[q]={}),W=t[q],X=s.newContainer(e,q,Y+"axis"),J();var lt="x"===Y&&!S[q]&&A[q]||"y"===Y&&!E[q]&&M[q],ct="y"===Y&&(!L[q]&&C[q]||P[q]),ut={hasMinor:!0,letter:Y,font:e.font,outerTicks:I[q],showGrid:!O[q],data:k[q]||[],bgColor:Z,calendar:e.calendar,automargin:!0,visibleDflt:lt,reverseDflt:ct,autotypenumbersDflt:T,splomStash:((e._splomAxes||{})[Y]||{})[G]};K("uirevision",e.uirevision),u(W,X,K,ut),f(W,X,K,ut,e);var ft=st&&Y===ot.charAt(0),ht=Q("spikecolor",st?X.color:void 0),pt=Q("spikethickness",st?1.5:void 0),dt=Q("spikedash",st?"dot":void 0),mt=Q("spikemode",st?"across":void 0),gt=Q("spikesnap");K("showspikes",!!(ft||ht||pt||dt||mt||gt))||(delete X.spikecolor,delete X.spikethickness,delete X.spikedash,delete X.spikemode,delete X.spikesnap),p(W,X,K,{letter:Y,counterAxes:et[Y],overlayableAxes:tt(Y,q),grid:e.grid}),K("title.standoff"),at(),X._input=W}for(y=0;y<it.length;){G=it[y++],Y=(q=m(G)).charAt(0),n.isPlainObject(t[q])||(t[q]={}),W=t[q],X=s.newContainer(e,q,Y+"axis"),J();var vt={letter:Y,font:e.font,outerTicks:I[q],showGrid:!O[q],data:[],bgColor:Z,calendar:e.calendar,automargin:!0,visibleDflt:!1,reverseDflt:!1,autotypenumbersDflt:T,splomStash:((e._splomAxes||{})[Y]||{})[G]};K("uirevision",e.uirevision),X.type=nt[G]||"linear",f(W,X,K,vt,e),p(W,X,K,{letter:Y,counterAxes:et[Y],overlayableAxes:tt(Y,q),grid:e.grid}),K("fixedrange"),at(),X._input=W}var yt=b("rangeslider","handleDefaults"),xt=b("rangeselector","handleDefaults");for(y=0;y<j.length;y++)q=j[y],W=t[q],X=e[q],yt(t,e,q),"date"===X.type&&xt(W,X,e,U,X.calendar),K("fixedrange");for(y=0;y<U.length;y++){q=U[y],W=t[q],X=e[q];var bt=e[m(X.anchor)];K("fixedrange",b("rangeslider","isVisible")(bt))}h.handleDefaults(t,e,{axIds:rt.concat(it).sort(d.idSort),axHasImage:P})}},{"../../components/color":366,"../../components/fx/helpers":402,"../../components/fx/hovermode_defaults":405,"../../lib":503,"../../plot_api/plot_template":543,"../../registry":638,"../layout_attributes":610,"./axis_defaults":556,"./axis_ids":558,"./constants":561,"./constraints":562,"./layout_attributes":569,"./position_defaults":572,"./type_defaults":582}],571:[function(t,e,r){"use strict";var n=t("tinycolor2").mix,i=t("../../components/color/attributes"),a=t("../../lib");e.exports=function(t,e,r,o){var s=(o=o||{}).dfltColor;function l(r,n){return a.coerce2(t,e,o.attributes,r,n)}var c=l("linecolor",s),u=l("linewidth");r("showline",o.showLine||!!c||!!u)||(delete e.linecolor,delete e.linewidth);var f=l("gridcolor",n(s,o.bgColor,o.blend||i.lightFraction).toRgbString()),h=l("gridwidth"),p=l("griddash");if(r("showgrid",o.showGrid||!!f||!!h||!!p)||(delete e.gridcolor,delete e.gridwidth,delete e.griddash),o.hasMinor){var d=l("minor.gridcolor",n(e.gridcolor,o.bgColor,67).toRgbString()),m=l("minor.gridwidth",e.gridwidth||1),g=l("minor.griddash",e.griddash||"solid");r("minor.showgrid",!!d||!!m||!!g)||(delete e.minor.gridcolor,delete e.minor.gridwidth,delete e.minor.griddash)}if(!o.noZeroLine){var v=l("zerolinecolor",s),y=l("zerolinewidth");r("zeroline",o.showGrid||!!v||!!y)||(delete e.zerolinecolor,delete e.zerolinewidth)}}},{"../../components/color/attributes":365,"../../lib":503,tinycolor2:312}],572:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib");e.exports=function(t,e,r,a){var o,s,l,c,u=a.counterAxes||[],f=a.overlayableAxes||[],h=a.letter,p=a.grid;p&&(s=p._domains[h][p._axisMap[e._id]],o=p._anchors[e._id],s&&(l=p[h+"side"].split(" ")[0],c=p.domain[h]["right"===l||"top"===l?1:0])),s=s||[0,1],o=o||(n(t.position)?"free":u[0]||"free"),l=l||("x"===h?"bottom":"left"),c=c||0,"free"===i.coerce(t,e,{anchor:{valType:"enumerated",values:["free"].concat(u),dflt:o}},"anchor")&&r("position",c),i.coerce(t,e,{side:{valType:"enumerated",values:"x"===h?["bottom","top"]:["left","right"],dflt:l}},"side");var d=!1;if(f.length&&(d=i.coerce(t,e,{overlaying:{valType:"enumerated",values:[!1].concat(f),dflt:!1}},"overlaying")),!d){var m=r("domain",s);m[0]>m[1]-1/4096&&(e.domain=s),i.noneOrAll(t.domain,e.domain,s)}return r("layer"),e}},{"../../lib":503,"fast-isnumeric":190}],573:[function(t,e,r){"use strict";var n=t("./show_dflt");e.exports=function(t,e,r,i,a){a||(a={});var o=a.tickSuffixDflt,s=n(t);r("tickprefix")&&r("showtickprefix",s),r("ticksuffix",o)&&r("showticksuffix",s)}},{"./show_dflt":577}],574:[function(t,e,r){"use strict";var n=t("../../constants/alignment").FROM_BL;e.exports=function(t,e,r){void 0===r&&(r=n[t.constraintoward||"center"]);var i=[t.r2l(t.range[0]),t.r2l(t.range[1])],a=i[0]+(i[1]-i[0])*r;t.range=t._input.range=[t.l2r(a+(i[0]-a)*e),t.l2r(a+(i[1]-a)*e)],t.setScale()}},{"../../constants/alignment":471}],575:[function(t,e,r){"use strict";var n=t("polybooljs"),i=t("../../registry"),a=t("../../components/drawing").dashStyle,o=t("../../components/color"),s=t("../../components/fx"),l=t("../../components/fx/helpers").makeEventData,c=t("../../components/dragelement/helpers"),u=c.freeMode,f=c.rectMode,h=c.drawMode,p=c.openMode,d=c.selectMode,m=t("../../components/shapes/draw_newshape/display_outlines"),g=t("../../components/shapes/draw_newshape/helpers").handleEllipse,v=t("../../components/shapes/draw_newshape/newshapes"),y=t("../../lib"),x=t("../../lib/polygon"),b=t("../../lib/throttle"),_=t("./axis_ids").getFromId,w=t("../../lib/clear_gl_canvases"),T=t("../../plot_api/subroutines").redrawReglTraces,k=t("./constants"),A=k.MINSELECT,M=x.filter,S=x.tester,E=t("./handle_outline").clearSelect,L=t("./helpers"),C=L.p2r,P=L.axValue,I=L.getTransform;function O(t,e,r,n,i,a,o){var s,l,c,u,f,h,d,g,v,y=e._hoverdata,x=e._fullLayout.clickmode.indexOf("event")>-1,b=[];if(function(t){return t&&Array.isArray(t)&&!0!==t[0].hoverOnBox}(y)){F(t,e,a);var _=function(t,e){var r,n,i=t[0],a=-1,o=[];for(n=0;n<e.length;n++)if(r=e[n],i.fullData._expandedIndex===r.cd[0].trace._expandedIndex){if(!0===i.hoverOnBox)break;void 0!==i.pointNumber?a=i.pointNumber:void 0!==i.binNumber&&(a=i.binNumber,o=i.pointNumbers);break}return{pointNumber:a,pointNumbers:o,searchInfo:r}}(y,s=N(e,r,n,i));if(_.pointNumbers.length>0?function(t,e){var r,n,i,a=[];for(i=0;i<t.length;i++)(r=t[i]).cd[0].trace.selectedpoints&&r.cd[0].trace.selectedpoints.length>0&&a.push(r);if(1===a.length&&a[0]===e.searchInfo&&(n=e.searchInfo.cd[0].trace).selectedpoints.length===e.pointNumbers.length){for(i=0;i<e.pointNumbers.length;i++)if(n.selectedpoints.indexOf(e.pointNumbers[i])<0)return!1;return!0}return!1}(s,_):function(t){var e,r,n,i=0;for(n=0;n<t.length;n++)if(e=t[n],(r=e.cd[0].trace).selectedpoints){if(r.selectedpoints.length>1)return!1;if((i+=r.selectedpoints.length)>1)return!1}return 1===i}(s)&&(h=j(_))){for(o&&o.remove(),v=0;v<s.length;v++)(l=s[v])._module.selectPoints(l,!1);U(e,s),B(a),x&&e.emit("plotly_deselect",null)}else{for(d=t.shiftKey&&(void 0!==h?h:j(_)),c=function(t,e,r){return{pointNumber:t,searchInfo:e,subtract:r}}(_.pointNumber,_.searchInfo,d),u=R(a.selectionDefs.concat([c])),v=0;v<s.length;v++)if(f=V(s[v]._module.selectPoints(s[v],u),s[v]),b.length)for(var w=0;w<f.length;w++)b.push(f[w]);else b=f;if(U(e,s,g={points:b}),c&&a&&a.selectionDefs.push(c),o){var T=a.mergedPolygons,k=p(a.dragmode);m(H(T,k),o,a)}x&&e.emit("plotly_selected",g)}}}function z(t){return"pointNumber"in t&&"searchInfo"in t}function D(t){return{xmin:0,xmax:0,ymin:0,ymax:0,pts:[],contains:function(e,r,n,i){var a=t.searchInfo.cd[0].trace._expandedIndex;return i.cd[0].trace._expandedIndex===a&&n===t.pointNumber},isRect:!1,degenerate:!1,subtract:t.subtract}}function R(t){for(var e=[],r=z(t[0])?0:t[0][0][0],n=r,i=z(t[0])?0:t[0][0][1],a=i,o=0;o<t.length;o++)if(z(t[o]))e.push(D(t[o]));else{var s=x.tester(t[o]);s.subtract=t[o].subtract,e.push(s),r=Math.min(r,s.xmin),n=Math.max(n,s.xmax),i=Math.min(i,s.ymin),a=Math.max(a,s.ymax)}return{xmin:r,xmax:n,ymin:i,ymax:a,pts:[],contains:function(t,r,n,i){for(var a=!1,o=0;o<e.length;o++)e[o].contains(t,r,n,i)&&(a=!1===e[o].subtract);return a},isRect:!1,degenerate:!1}}function F(t,e,r){e._fullLayout._drawing=!1;var n=e._fullLayout,i=r.plotinfo,a=r.dragmode,o=n._lastSelectedSubplot&&n._lastSelectedSubplot===i.id,s=(t.shiftKey||t.altKey)&&!(h(a)&&p(a));o&&s&&i.selection&&i.selection.selectionDefs&&!r.selectionDefs?(r.selectionDefs=i.selection.selectionDefs,r.mergedPolygons=i.selection.mergedPolygons):s&&i.selection||B(r),o||(E(e),n._lastSelectedSubplot=i.id)}function B(t){var e=t.dragmode,r=t.plotinfo,n=t.gd;if(n._fullLayout._activeShapeIndex>=0&&n._fullLayout._deactivateShape(n),h(e)){var a=n._fullLayout._zoomlayer.selectAll(".select-outline-"+r.id);if(a&&n._fullLayout._drawing){var o=v(a,t);o&&i.call("_guiRelayout",n,{shapes:o}),n._fullLayout._drawing=!1}}r.selection={},r.selection.selectionDefs=t.selectionDefs=[],r.selection.mergedPolygons=t.mergedPolygons=[]}function N(t,e,r,n){var i,a,o,s=[],l=e.map((function(t){return t._id})),c=r.map((function(t){return t._id}));for(o=0;o<t.calcdata.length;o++)if(!0===(a=(i=t.calcdata[o])[0].trace).visible&&a._module&&a._module.selectPoints)if(!n||a.subplot!==n&&a.geo!==n)if("splom"===a.type&&a._xaxes[l[0]]&&a._yaxes[c[0]]){var u=h(a._module,i,e[0],r[0]);u.scene=t._fullLayout._splomScenes[a.uid],s.push(u)}else if("sankey"===a.type){var f=h(a._module,i,e[0],r[0]);s.push(f)}else{if(-1===l.indexOf(a.xaxis))continue;if(-1===c.indexOf(a.yaxis))continue;s.push(h(a._module,i,_(t,a.xaxis),_(t,a.yaxis)))}else s.push(h(a._module,i,e[0],r[0]));return s;function h(t,e,r,n){return{_module:t,cd:e,xaxis:r,yaxis:n}}}function j(t){var e=t.searchInfo.cd[0].trace,r=t.pointNumber,n=t.pointNumbers,i=n.length>0?n[0]:r;return!!e.selectedpoints&&e.selectedpoints.indexOf(i)>-1}function U(t,e,r){var n,a,o,s;for(n=0;n<e.length;n++){var l=e[n].cd[0].trace._fullInput,c=t._fullLayout._tracePreGUI[l.uid]||{};void 0===c.selectedpoints&&(c.selectedpoints=l._input.selectedpoints||null)}if(r){var u=r.points||[];for(n=0;n<e.length;n++)(s=e[n].cd[0].trace)._input.selectedpoints=s._fullInput.selectedpoints=[],s._fullInput!==s&&(s.selectedpoints=[]);for(n=0;n<u.length;n++){var f=u[n],h=f.data,p=f.fullData;f.pointIndices?([].push.apply(h.selectedpoints,f.pointIndices),s._fullInput!==s&&[].push.apply(p.selectedpoints,f.pointIndices)):(h.selectedpoints.push(f.pointIndex),s._fullInput!==s&&p.selectedpoints.push(f.pointIndex))}}else for(n=0;n<e.length;n++)delete(s=e[n].cd[0].trace).selectedpoints,delete s._input.selectedpoints,s._fullInput!==s&&delete s._fullInput.selectedpoints;var d=!1;for(n=0;n<e.length;n++){s=(o=(a=e[n]).cd)[0].trace,i.traceIs(s,"regl")&&(d=!0);var m=a._module,g=m.styleOnSelect||m.style;g&&(g(t,o,o[0].node3),o[0].nodeRangePlot3&&g(t,o,o[0].nodeRangePlot3))}d&&(w(t),T(t))}function V(t,e){if(Array.isArray(t))for(var r=e.cd,n=e.cd[0].trace,i=0;i<t.length;i++)t[i]=l(t[i],n,r);return t}function H(t,e){for(var r=[],n=0;n<t.length;n++){r[n]=[];for(var i=0;i<t[n].length;i++){r[n][i]=[],r[n][i][0]=i?"L":"M";for(var a=0;a<t[n][i].length;a++)r[n][i].push(t[n][i][a])}e||r[n].push(["Z",r[n][0][1],r[n][0][2]])}return r}e.exports={prepSelect:function(t,e,r,i,l){var c=u(l),v=f(l),x=p(l),_=h(l),w=d(l),T="drawcircle"===l,E="drawline"===l||T,L=i.gd,z=L._fullLayout,D=z._zoomlayer,j=i.element.getBoundingClientRect(),q=i.plotinfo,G=I(q),Y=e-j.left,W=r-j.top;z._calcInverseTransform(L);var X=y.apply3DTransform(z._invTransform)(Y,W);Y=X[0],W=X[1];var Z,J,K,Q,$,tt,et,rt=z._invScaleX,nt=z._invScaleY,it=Y,at=W,ot="M"+Y+","+W,st=i.xaxes[0]._length,lt=i.yaxes[0]._length,ct=i.xaxes.concat(i.yaxes),ut=t.altKey&&!(h(l)&&x);F(t,L,i),c&&(Z=M([[Y,W]],k.BENDPX));var ft=D.selectAll("path.select-outline-"+q.id).data(_?[0]:[1,2]),ht=z.newshape;ft.enter().append("path").attr("class",(function(t){return"select-outline select-outline-"+t+" select-outline-"+q.id})).style(_?{opacity:ht.opacity/2,fill:x?void 0:ht.fillcolor,stroke:ht.line.color,"stroke-dasharray":a(ht.line.dash,ht.line.width),"stroke-width":ht.line.width+"px"}:{}).attr("fill-rule",ht.fillrule).classed("cursor-move",!!_).attr("transform",G).attr("d",ot+"Z");var pt,dt=D.append("path").attr("class","zoombox-corners").style({fill:o.background,stroke:o.defaultLine,"stroke-width":1}).attr("transform",G).attr("d","M0,0Z"),mt=z._uid+k.SELECTID,gt=[],vt=N(L,i.xaxes,i.yaxes,i.subplot);function yt(t,e){return t-e}pt=q.fillRangeItems?q.fillRangeItems:v?function(t,e){var r=t.range={};for($=0;$<ct.length;$++){var n=ct[$],i=n._id.charAt(0);r[n._id]=[C(n,e[i+"min"]),C(n,e[i+"max"])].sort(yt)}}:function(t,e,r){var n=t.lassoPoints={};for($=0;$<ct.length;$++){var i=ct[$];n[i._id]=r.filtered.map(P(i))}},i.moveFn=function(t,e){it=Math.max(0,Math.min(st,rt*t+Y)),at=Math.max(0,Math.min(lt,nt*e+W));var r=Math.abs(it-Y),a=Math.abs(at-W);if(v){var o,s,l;if(w){var u=z.selectdirection;switch(o="any"===u?a<Math.min(.6*r,A)?"h":r<Math.min(.6*a,A)?"v":"d":u){case"h":s=T?lt/2:0,l=lt;break;case"v":s=T?st/2:0,l=st}}if(_)switch(z.newshape.drawdirection){case"vertical":o="h",s=T?lt/2:0,l=lt;break;case"horizontal":o="v",s=T?st/2:0,l=st;break;case"ortho":r<a?(o="h",s=W,l=at):(o="v",s=Y,l=it);break;default:o="d"}"h"===o?((Q=E?g(T,[it,s],[it,l]):[[Y,s],[Y,l],[it,l],[it,s]]).xmin=E?it:Math.min(Y,it),Q.xmax=E?it:Math.max(Y,it),Q.ymin=Math.min(s,l),Q.ymax=Math.max(s,l),dt.attr("d","M"+Q.xmin+","+(W-A)+"h-4v"+2*A+"h4ZM"+(Q.xmax-1)+","+(W-A)+"h4v"+2*A+"h-4Z")):"v"===o?((Q=E?g(T,[s,at],[l,at]):[[s,W],[s,at],[l,at],[l,W]]).xmin=Math.min(s,l),Q.xmax=Math.max(s,l),Q.ymin=E?at:Math.min(W,at),Q.ymax=E?at:Math.max(W,at),dt.attr("d","M"+(Y-A)+","+Q.ymin+"v-4h"+2*A+"v4ZM"+(Y-A)+","+(Q.ymax-1)+"v4h"+2*A+"v-4Z")):"d"===o&&((Q=E?g(T,[Y,W],[it,at]):[[Y,W],[Y,at],[it,at],[it,W]]).xmin=Math.min(Y,it),Q.xmax=Math.max(Y,it),Q.ymin=Math.min(W,at),Q.ymax=Math.max(W,at),dt.attr("d","M0,0Z"))}else c&&(Z.addPt([it,at]),Q=Z.filtered);i.selectionDefs&&i.selectionDefs.length?(K=function(t,e,r){if(r)return n.difference({regions:t,inverted:!1},{regions:[e],inverted:!1}).regions;return n.union({regions:t,inverted:!1},{regions:[e],inverted:!1}).regions}(i.mergedPolygons,Q,ut),Q.subtract=ut,J=R(i.selectionDefs.concat([Q]))):(K=[Q],J=S(Q)),m(H(K,x),ft,i),w&&b.throttle(mt,k.SELECTDELAY,(function(){var t;gt=[];var e,r=[];for($=0;$<vt.length;$++)if(e=(tt=vt[$])._module.selectPoints(tt,J),r.push(e),t=V(e,tt),gt.length)for(var n=0;n<t.length;n++)gt.push(t[n]);else gt=t;U(L,vt,et={points:gt}),pt(et,Q,Z),i.gd.emit("plotly_selecting",et)}))},i.clickFn=function(t,e){if(dt.remove(),L._fullLayout._activeShapeIndex>=0)L._fullLayout._deactivateShape(L);else if(!_){var r=z.clickmode;b.done(mt).then((function(){if(b.clear(mt),2===t){for(ft.remove(),$=0;$<vt.length;$++)(tt=vt[$])._module.selectPoints(tt,!1);U(L,vt),B(i),L.emit("plotly_deselect",null)}else r.indexOf("select")>-1&&O(e,L,i.xaxes,i.yaxes,i.subplot,i,ft),"event"===r&&L.emit("plotly_selected",void 0);s.click(L,e)})).catch(y.error)}},i.doneFn=function(){dt.remove(),b.done(mt).then((function(){b.clear(mt),i.gd.emit("plotly_selected",et),Q&&i.selectionDefs&&(Q.subtract=ut,i.selectionDefs.push(Q),i.mergedPolygons.length=0,[].push.apply(i.mergedPolygons,K)),i.doneFnCompleted&&i.doneFnCompleted(gt)})).catch(y.error),_&&B(i)}},clearSelect:E,clearSelectionsCache:B,selectOnClick:O}},{"../../components/color":366,"../../components/dragelement/helpers":384,"../../components/drawing":388,"../../components/fx":406,"../../components/fx/helpers":402,"../../components/shapes/draw_newshape/display_outlines":454,"../../components/shapes/draw_newshape/helpers":455,"../../components/shapes/draw_newshape/newshapes":456,"../../lib":503,"../../lib/clear_gl_canvases":487,"../../lib/polygon":515,"../../lib/throttle":530,"../../plot_api/subroutines":544,"../../registry":638,"./axis_ids":558,"./constants":561,"./handle_outline":565,"./helpers":566,polybooljs:254}],576:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("d3-time-format").utcFormat,a=t("../../lib"),o=a.numberFormat,s=t("fast-isnumeric"),l=a.cleanNumber,c=a.ms2DateTime,u=a.dateTime2ms,f=a.ensureNumber,h=a.isArrayOrTypedArray,p=t("../../constants/numerical"),d=p.FP_SAFE,m=p.BADNUM,g=p.LOG_CLIP,v=p.ONEWEEK,y=p.ONEDAY,x=p.ONEHOUR,b=p.ONEMIN,_=p.ONESEC,w=t("./axis_ids"),T=t("./constants"),k=T.HOUR_PATTERN,A=T.WEEKDAY_PATTERN;function M(t){return Math.pow(10,t)}function S(t){return null!=t}e.exports=function(t,e){e=e||{};var r=t._id||"x",p=r.charAt(0);function E(e,r){if(e>0)return Math.log(e)/Math.LN10;if(e<=0&&r&&t.range&&2===t.range.length){var n=t.range[0],i=t.range[1];return.5*(n+i-2*g*Math.abs(n-i))}return m}function L(e,r,n,i){if((i||{}).msUTC&&s(e))return+e;var o=u(e,n||t.calendar);if(o===m){if(!s(e))return m;e=+e;var l=Math.floor(10*a.mod(e+.05,1)),c=Math.round(e-l/10);o=u(new Date(c))+l/10}return o}function C(e,r,n){return c(e,r,n||t.calendar)}function P(e){return t._categories[Math.round(e)]}function I(e){if(S(e)){if(void 0===t._categoriesMap&&(t._categoriesMap={}),void 0!==t._categoriesMap[e])return t._categoriesMap[e];t._categories.push("number"==typeof e?String(e):e);var r=t._categories.length-1;return t._categoriesMap[e]=r,r}return m}function O(e){if(t._categoriesMap)return t._categoriesMap[e]}function z(t){var e=O(t);return void 0!==e?e:s(t)?+t:void 0}function D(t){return s(t)?+t:O(t)}function R(t,e,r){return n.round(r+e*t,2)}function F(t,e,r){return(t-r)/e}var B=function(e){return s(e)?R(e,t._m,t._b):m},N=function(e){return F(e,t._m,t._b)};if(t.rangebreaks){var j="y"===p;B=function(e){if(!s(e))return m;var r=t._rangebreaks.length;if(!r)return R(e,t._m,t._b);var n=j;t.range[0]>t.range[1]&&(n=!n);for(var i=n?-1:1,a=i*e,o=0,l=0;l<r;l++){var c=i*t._rangebreaks[l].min,u=i*t._rangebreaks[l].max;if(a<c)break;if(!(a>u)){o=a<(c+u)/2?l:l+1;break}o=l+1}var f=t._B[o]||0;return isFinite(f)?R(e,t._m2,f):0},N=function(e){var r=t._rangebreaks.length;if(!r)return F(e,t._m,t._b);for(var n=0,i=0;i<r&&!(e<t._rangebreaks[i].pmin);i++)e>t._rangebreaks[i].pmax&&(n=i+1);return F(e,t._m2,t._B[n])}}t.c2l="log"===t.type?E:f,t.l2c="log"===t.type?M:f,t.l2p=B,t.p2l=N,t.c2p="log"===t.type?function(t,e){return B(E(t,e))}:B,t.p2c="log"===t.type?function(t){return M(N(t))}:N,-1!==["linear","-"].indexOf(t.type)?(t.d2r=t.r2d=t.d2c=t.r2c=t.d2l=t.r2l=l,t.c2d=t.c2r=t.l2d=t.l2r=f,t.d2p=t.r2p=function(e){return t.l2p(l(e))},t.p2d=t.p2r=N,t.cleanPos=f):"log"===t.type?(t.d2r=t.d2l=function(t,e){return E(l(t),e)},t.r2d=t.r2c=function(t){return M(l(t))},t.d2c=t.r2l=l,t.c2d=t.l2r=f,t.c2r=E,t.l2d=M,t.d2p=function(e,r){return t.l2p(t.d2r(e,r))},t.p2d=function(t){return M(N(t))},t.r2p=function(e){return t.l2p(l(e))},t.p2r=N,t.cleanPos=f):"date"===t.type?(t.d2r=t.r2d=a.identity,t.d2c=t.r2c=t.d2l=t.r2l=L,t.c2d=t.c2r=t.l2d=t.l2r=C,t.d2p=t.r2p=function(e,r,n){return t.l2p(L(e,0,n))},t.p2d=t.p2r=function(t,e,r){return C(N(t),e,r)},t.cleanPos=function(e){return a.cleanDate(e,m,t.calendar)}):"category"===t.type?(t.d2c=t.d2l=I,t.r2d=t.c2d=t.l2d=P,t.d2r=t.d2l_noadd=z,t.r2c=function(e){var r=D(e);return void 0!==r?r:t.fraction2r(.5)},t.l2r=t.c2r=f,t.r2l=D,t.d2p=function(e){return t.l2p(t.r2c(e))},t.p2d=function(t){return P(N(t))},t.r2p=t.d2p,t.p2r=N,t.cleanPos=function(t){return"string"==typeof t&&""!==t?t:f(t)}):"multicategory"===t.type&&(t.r2d=t.c2d=t.l2d=P,t.d2r=t.d2l_noadd=z,t.r2c=function(e){var r=z(e);return void 0!==r?r:t.fraction2r(.5)},t.r2c_just_indices=O,t.l2r=t.c2r=f,t.r2l=z,t.d2p=function(e){return t.l2p(t.r2c(e))},t.p2d=function(t){return P(N(t))},t.r2p=t.d2p,t.p2r=N,t.cleanPos=function(t){return Array.isArray(t)||"string"==typeof t&&""!==t?t:f(t)},t.setupMultiCategory=function(n){var i,o,s=t._traceIndices,l=t._matchGroup;if(l&&0===t._categories.length)for(var c in l)if(c!==r){var u=e[w.id2name(c)];s=s.concat(u._traceIndices)}var f=[[0,{}],[0,{}]],d=[];for(i=0;i<s.length;i++){var m=n[s[i]];if(p in m){var g=m[p],v=m._length||a.minRowLength(g);if(h(g[0])&&h(g[1]))for(o=0;o<v;o++){var y=g[0][o],x=g[1][o];S(y)&&S(x)&&(d.push([y,x]),y in f[0][1]||(f[0][1][y]=f[0][0]++),x in f[1][1]||(f[1][1][x]=f[1][0]++))}}}for(d.sort((function(t,e){var r=f[0][1],n=r[t[0]]-r[e[0]];if(n)return n;var i=f[1][1];return i[t[1]]-i[e[1]]})),i=0;i<d.length;i++)I(d[i])}),t.fraction2r=function(e){var r=t.r2l(t.range[0]),n=t.r2l(t.range[1]);return t.l2r(r+e*(n-r))},t.r2fraction=function(e){var r=t.r2l(t.range[0]),n=t.r2l(t.range[1]);return(t.r2l(e)-r)/(n-r)},t.cleanRange=function(e,r){r||(r={}),e||(e="range");var n,i,o=a.nestedProperty(t,e).get();if(i=(i="date"===t.type?a.dfltRange(t.calendar):"y"===p?T.DFLTRANGEY:"realaxis"===t._name?[0,1]:r.dfltRange||T.DFLTRANGEX).slice(),"tozero"!==t.rangemode&&"nonnegative"!==t.rangemode||(i[0]=0),o&&2===o.length)for("date"!==t.type||t.autorange||(o[0]=a.cleanDate(o[0],m,t.calendar),o[1]=a.cleanDate(o[1],m,t.calendar)),n=0;n<2;n++)if("date"===t.type){if(!a.isDateTime(o[n],t.calendar)){t[e]=i;break}if(t.r2l(o[0])===t.r2l(o[1])){var l=a.constrain(t.r2l(o[0]),a.MIN_MS+1e3,a.MAX_MS-1e3);o[0]=t.l2r(l-1e3),o[1]=t.l2r(l+1e3);break}}else{if(!s(o[n])){if(!s(o[1-n])){t[e]=i;break}o[n]=o[1-n]*(n?10:.1)}if(o[n]<-d?o[n]=-d:o[n]>d&&(o[n]=d),o[0]===o[1]){var c=Math.max(1,Math.abs(1e-6*o[0]));o[0]-=c,o[1]+=c}}else a.nestedProperty(t,e).set(i)},t.setScale=function(r){var n=e._size;if(t.overlaying){var i=w.getFromId({_fullLayout:e},t.overlaying);t.domain=i.domain}var a=r&&t._r?"_r":"range",o=t.calendar;t.cleanRange(a);var s,l,c=t.r2l(t[a][0],o),u=t.r2l(t[a][1],o),f="y"===p;if((f?(t._offset=n.t+(1-t.domain[1])*n.h,t._length=n.h*(t.domain[1]-t.domain[0]),t._m=t._length/(c-u),t._b=-t._m*u):(t._offset=n.l+t.domain[0]*n.w,t._length=n.w*(t.domain[1]-t.domain[0]),t._m=t._length/(u-c),t._b=-t._m*c),t._rangebreaks=[],t._lBreaks=0,t._m2=0,t._B=[],t.rangebreaks)&&(t._rangebreaks=t.locateBreaks(Math.min(c,u),Math.max(c,u)),t._rangebreaks.length)){for(s=0;s<t._rangebreaks.length;s++)l=t._rangebreaks[s],t._lBreaks+=Math.abs(l.max-l.min);var h=f;c>u&&(h=!h),h&&t._rangebreaks.reverse();var d=h?-1:1;for(t._m2=d*t._length/(Math.abs(u-c)-t._lBreaks),t._B.push(-t._m2*(f?u:c)),s=0;s<t._rangebreaks.length;s++)l=t._rangebreaks[s],t._B.push(t._B[t._B.length-1]-d*t._m2*(l.max-l.min));for(s=0;s<t._rangebreaks.length;s++)(l=t._rangebreaks[s]).pmin=B(l.min),l.pmax=B(l.max)}if(!isFinite(t._m)||!isFinite(t._b)||t._length<0)throw e._replotting=!1,new Error("Something went wrong with axis scaling")},t.maskBreaks=function(e){var r,n,i,o,s,c=t.rangebreaks||[];c._cachedPatterns||(c._cachedPatterns=c.map((function(e){return e.enabled&&e.bounds?a.simpleMap(e.bounds,e.pattern?l:t.d2c):null}))),c._cachedValues||(c._cachedValues=c.map((function(e){return e.enabled&&e.values?a.simpleMap(e.values,t.d2c).sort(a.sorterAsc):null})));for(var u=0;u<c.length;u++){var f=c[u];if(f.enabled)if(f.bounds){var h=f.pattern;switch(n=(r=c._cachedPatterns[u])[0],i=r[1],h){case A:o=(s=new Date(e)).getUTCDay(),n>i&&(i+=7,o<n&&(o+=7));break;case k:o=(s=new Date(e)).getUTCHours()+(s.getUTCMinutes()/60+s.getUTCSeconds()/3600+s.getUTCMilliseconds()/36e5),n>i&&(i+=24,o<n&&(o+=24));break;case"":o=e}if(o>=n&&o<i)return m}else for(var p=c._cachedValues[u],d=0;d<p.length;d++)if(i=(n=p[d])+f.dvalue,e>=n&&e<i)return m}return e},t.locateBreaks=function(e,r){var n,i,o,s,c=[];if(!t.rangebreaks)return c;var u=t.rangebreaks.slice().sort((function(t,e){return t.pattern===A&&e.pattern===k?-1:e.pattern===A&&t.pattern===k?1:0})),f=function(t,n){if((t=a.constrain(t,e,r))!==(n=a.constrain(n,e,r))){for(var i=!0,o=0;o<c.length;o++){var s=c[o];t<s.max&&n>=s.min&&(t<s.min&&(s.min=t),n>s.max&&(s.max=n),i=!1)}i&&c.push({min:t,max:n})}};for(n=0;n<u.length;n++){var h=u[n];if(h.enabled)if(h.bounds){var p=e,d=r;h.pattern&&(p=Math.floor(p)),o=(i=a.simpleMap(h.bounds,h.pattern?l:t.r2l))[0],s=i[1];var m,g,w=new Date(p);switch(h.pattern){case A:g=v,m=(s-o+(s<o?7:0))*y,p+=o*y-(w.getUTCDay()*y+w.getUTCHours()*x+w.getUTCMinutes()*b+w.getUTCSeconds()*_+w.getUTCMilliseconds());break;case k:g=y,m=(s-o+(s<o?24:0))*x,p+=o*x-(w.getUTCHours()*x+w.getUTCMinutes()*b+w.getUTCSeconds()*_+w.getUTCMilliseconds());break;default:p=Math.min(i[0],i[1]),m=g=(d=Math.max(i[0],i[1]))-p}for(var T=p;T<d;T+=g)f(T,T+m)}else for(var M=a.simpleMap(h.values,t.d2c),S=0;S<M.length;S++)f(o=M[S],s=o+h.dvalue)}return c.sort((function(t,e){return t.min-e.min})),c},t.makeCalcdata=function(e,r,n){var i,o,s,l,c=t.type,u="date"===c&&e[r+"calendar"];if(r in e){if(i=e[r],l=e._length||a.minRowLength(i),a.isTypedArray(i)&&("linear"===c||"log"===c)){if(l===i.length)return i;if(i.subarray)return i.subarray(0,l)}if("multicategory"===c)return function(t,e){for(var r=new Array(e),n=0;n<e;n++){var i=(t[0]||[])[n],a=(t[1]||[])[n];r[n]=O([i,a])}return r}(i,l);for(o=new Array(l),s=0;s<l;s++)o[s]=t.d2c(i[s],0,u,n)}else{var f=r+"0"in e?t.d2c(e[r+"0"],0,u):0,h=e["d"+r]?Number(e["d"+r]):1;for(i=e[{x:"y",y:"x"}[r]],l=e._length||i.length,o=new Array(l),s=0;s<l;s++)o[s]=f+s*h}if(t.rangebreaks)for(s=0;s<l;s++)o[s]=t.maskBreaks(o[s]);return o},t.isValidRange=function(e){return Array.isArray(e)&&2===e.length&&s(t.r2l(e[0]))&&s(t.r2l(e[1]))},t.isPtWithinRange=function(e,r){var n=t.c2l(e[p],null,r),i=t.r2l(t.range[0]),a=t.r2l(t.range[1]);return i<a?i<=n&&n<=a:a<=n&&n<=i},t._emptyCategories=function(){t._categories=[],t._categoriesMap={}},t.clearCalc=function(){var r=t._matchGroup;if(r){var n=null,i=null;for(var a in r){var o=e[w.id2name(a)];if(o._categories){n=o._categories,i=o._categoriesMap;break}}n&&i?(t._categories=n,t._categoriesMap=i):t._emptyCategories()}else t._emptyCategories();if(t._initialCategories)for(var s=0;s<t._initialCategories.length;s++)I(t._initialCategories[s])},t.sortByInitialCategories=function(){var n=[];if(t._emptyCategories(),t._initialCategories)for(var i=0;i<t._initialCategories.length;i++)I(t._initialCategories[i]);n=n.concat(t._traceIndices);var a=t._matchGroup;for(var o in a)if(r!==o){var s=e[w.id2name(o)];s._categories=t._categories,s._categoriesMap=t._categoriesMap,n=n.concat(s._traceIndices)}return n};var U=e._d3locale;"date"===t.type&&(t._dateFormat=U?U.timeFormat:i,t._extraFormat=e._extraFormat),t._separators=e.separators,t._numFormat=U?U.numberFormat:o,delete t._minDtick,delete t._forceTick0}},{"../../constants/numerical":479,"../../lib":503,"./axis_ids":558,"./constants":561,"@plotly/d3":58,"d3-time-format":120,"fast-isnumeric":190}],577:[function(t,e,r){"use strict";e.exports=function(t){var e=["showexponent","showtickprefix","showticksuffix"].filter((function(e){return void 0!==t[e]}));if(e.every((function(r){return t[r]===t[e[0]]}))||1===e.length)return t[e[0]]}},{}],578:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/color").contrast,a=t("./layout_attributes"),o=t("./show_dflt"),s=t("../array_container_defaults");function l(t,e){function r(r,i){return n.coerce(t,e,a.tickformatstops,r,i)}r("enabled")&&(r("dtickrange"),r("value"))}e.exports=function(t,e,r,c,u){u||(u={});var f=o(t);if(r("showticklabels")){var h=u.font||{},p=e.color,d=-1!==(e.ticklabelposition||"").indexOf("inside")?i(u.bgColor):p&&p!==a.color.dflt?p:h.color;if(n.coerceFont(r,"tickfont",{family:h.family,size:h.size,color:d}),u.noTicklabelstep||"multicategory"===c||"log"===c||r("ticklabelstep"),u.noAng||r("tickangle"),"category"!==c){var m=r("tickformat");s(t,e,{name:"tickformatstops",inclusionAttr:"enabled",handleItemDefaults:l}),e.tickformatstops.length||delete e.tickformatstops,u.noExp||m||"date"===c||(r("showexponent",f),r("exponentformat"),r("minexponent"),r("separatethousands"))}}}},{"../../components/color":366,"../../lib":503,"../array_container_defaults":549,"./layout_attributes":569,"./show_dflt":577}],579:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./layout_attributes");e.exports=function(t,e,r,a){var o=a.isMinor,s=o?t.minor||{}:t,l=o?e.minor:e,c=o?i.minor:i,u=o?"minor.":"",f=n.coerce2(s,l,c,"ticklen",o?.6*(e.ticklen||5):void 0),h=n.coerce2(s,l,c,"tickwidth",o?e.tickwidth||1:void 0),p=n.coerce2(s,l,c,"tickcolor",(o?e.tickcolor:void 0)||l.color);r(u+"ticks",!o&&a.outerTicks||f||h||p?"outside":"")||(delete l.ticklen,delete l.tickwidth,delete l.tickcolor)}},{"../../lib":503,"./layout_attributes":569}],580:[function(t,e,r){"use strict";var n=t("./clean_ticks"),i=t("../../lib").isArrayOrTypedArray;e.exports=function(t,e,r,a,o){o||(o={});var s=o.isMinor,l=s?t.minor||{}:t,c=s?e.minor:e,u=s?"minor.":"";function f(t){var e=l[t];return void 0!==e?e:(c._template||{})[t]}var h=f("tick0"),p=f("dtick"),d=f("tickvals"),m=r(u+"tickmode",i(d)?"array":p?"linear":"auto");if("auto"===m)r(u+"nticks");else if("linear"===m){var g=c.dtick=n.dtick(p,a);c.tick0=n.tick0(h,a,e.calendar,g)}else if("multicategory"!==a){void 0===r(u+"tickvals")?c.tickmode="auto":s||r("ticktext")}}},{"../../lib":503,"./clean_ticks":560}],581:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../registry"),a=t("../../lib"),o=t("../../components/drawing"),s=t("./axes");e.exports=function(t,e,r,l){var c=t._fullLayout;if(0!==e.length){var u,f,h,p;l&&(u=l());var d=n.ease(r.easing);return t._transitionData._interruptCallbacks.push((function(){return window.cancelAnimationFrame(p),p=null,function(){for(var r={},n=0;n<e.length;n++){var a=e[n],o=a.plotinfo.xaxis,s=a.plotinfo.yaxis;a.xr0&&(r[o._name+".range"]=a.xr0.slice()),a.yr0&&(r[s._name+".range"]=a.yr0.slice())}return i.call("relayout",t,r).then((function(){for(var t=0;t<e.length;t++)m(e[t].plotinfo)}))}()})),f=Date.now(),p=window.requestAnimationFrame((function n(){h=Date.now();for(var a=Math.min(1,(h-f)/r.duration),o=d(a),s=0;s<e.length;s++)g(e[s],o);h-f>r.duration?(!function(){for(var r={},n=0;n<e.length;n++){var a=e[n],o=a.plotinfo.xaxis,s=a.plotinfo.yaxis;a.xr1&&(r[o._name+".range"]=a.xr1.slice()),a.yr1&&(r[s._name+".range"]=a.yr1.slice())}u&&u(),i.call("relayout",t,r).then((function(){for(var t=0;t<e.length;t++)m(e[t].plotinfo)}))}(),p=window.cancelAnimationFrame(n)):p=window.requestAnimationFrame(n)})),Promise.resolve()}function m(t){var e=t.xaxis,r=t.yaxis;c._defs.select("#"+t.clipId+"> rect").call(o.setTranslate,0,0).call(o.setScale,1,1),t.plot.call(o.setTranslate,e._offset,r._offset).call(o.setScale,1,1);var n=t.plot.selectAll(".scatterlayer .trace");n.selectAll(".point").call(o.setPointGroupScale,1,1),n.selectAll(".textpoint").call(o.setTextPointsScale,1,1),n.call(o.hideOutsideRangePoints,t)}function g(e,r){var n=e.plotinfo,i=n.xaxis,l=n.yaxis,c=i._length,u=l._length,f=!!e.xr1,h=!!e.yr1,p=[];if(f){var d=a.simpleMap(e.xr0,i.r2l),m=a.simpleMap(e.xr1,i.r2l),g=d[1]-d[0],v=m[1]-m[0];p[0]=(d[0]*(1-r)+r*m[0]-d[0])/(d[1]-d[0])*c,p[2]=c*(1-r+r*v/g),i.range[0]=i.l2r(d[0]*(1-r)+r*m[0]),i.range[1]=i.l2r(d[1]*(1-r)+r*m[1])}else p[0]=0,p[2]=c;if(h){var y=a.simpleMap(e.yr0,l.r2l),x=a.simpleMap(e.yr1,l.r2l),b=y[1]-y[0],_=x[1]-x[0];p[1]=(y[1]*(1-r)+r*x[1]-y[1])/(y[0]-y[1])*u,p[3]=u*(1-r+r*_/b),l.range[0]=i.l2r(y[0]*(1-r)+r*x[0]),l.range[1]=l.l2r(y[1]*(1-r)+r*x[1])}else p[1]=0,p[3]=u;s.drawOne(t,i,{skipTitle:!0}),s.drawOne(t,l,{skipTitle:!0}),s.redrawComponents(t,[i._id,l._id]);var w=f?c/p[2]:1,T=h?u/p[3]:1,k=f?p[0]:0,A=h?p[1]:0,M=f?p[0]/p[2]*c:0,S=h?p[1]/p[3]*u:0,E=i._offset-M,L=l._offset-S;n.clipRect.call(o.setTranslate,k,A).call(o.setScale,1/w,1/T),n.plot.call(o.setTranslate,E,L).call(o.setScale,w,T),o.setPointGroupScale(n.zoomScalePts,1/w,1/T),o.setTextPointsScale(n.zoomScaleTxt,1/w,1/T)}s.redrawComponents(t)}},{"../../components/drawing":388,"../../lib":503,"../../registry":638,"./axes":554,"@plotly/d3":58}],582:[function(t,e,r){"use strict";var n=t("../../registry").traceIs,i=t("./axis_autotype");function a(t){return{v:"x",h:"y"}[t.orientation||"v"]}function o(t,e){var r=a(t),i=n(t,"box-violin"),o=n(t._fullInput||{},"candlestick");return i&&!o&&e===r&&void 0===t[r]&&void 0===t[r+"0"]}e.exports=function(t,e,r,s){r("autotypenumbers",s.autotypenumbersDflt),"-"===r("type",(s.splomStash||{}).type)&&(!function(t,e){if("-"!==t.type)return;var r,s=t._id,l=s.charAt(0);-1!==s.indexOf("scene")&&(s=l);var c=function(t,e,r){for(var n=0;n<t.length;n++){var i=t[n];if("splom"===i.type&&i._length>0&&(i["_"+r+"axes"]||{})[e])return i;if((i[r+"axis"]||r)===e){if(o(i,r))return i;if((i[r]||[]).length||i[r+"0"])return i}}}(e,s,l);if(!c)return;if("histogram"===c.type&&l==={v:"y",h:"x"}[c.orientation||"v"])return void(t.type="linear");var u=l+"calendar",f=c[u],h={noMultiCategory:!n(c,"cartesian")||n(c,"noMultiCategory")};"box"===c.type&&c._hasPreCompStats&&l==={h:"x",v:"y"}[c.orientation||"v"]&&(h.noMultiCategory=!0);if(h.autotypenumbers=t.autotypenumbers,o(c,l)){var p=a(c),d=[];for(r=0;r<e.length;r++){var m=e[r];n(m,"box-violin")&&(m[l+"axis"]||l)===s&&(void 0!==m[p]?d.push(m[p][0]):void 0!==m.name?d.push(m.name):d.push("text"),m[u]!==f&&(f=void 0))}t.type=i(d,f,h)}else if("splom"===c.type){var g=c.dimensions[c._axesDim[s]];g.visible&&(t.type=i(g.values,f,h))}else t.type=i(c[l]||[c[l+"0"]],f,h)}(e,s.data),"-"===e.type?e.type="linear":t.type=e.type)}},{"../../registry":638,"./axis_autotype":555}],583:[function(t,e,r){"use strict";var n=t("../registry"),i=t("../lib");function a(t,e,r){var n,a,o,s=!1;if("data"===e.type)n=t._fullData[null!==e.traces?e.traces[0]:0];else{if("layout"!==e.type)return!1;n=t._fullLayout}return a=i.nestedProperty(n,e.prop).get(),(o=r[e.type]=r[e.type]||{}).hasOwnProperty(e.prop)&&o[e.prop]!==a&&(s=!0),o[e.prop]=a,{changed:s,value:a}}function o(t,e){var r=[],n=e[0],a={};if("string"==typeof n)a[n]=e[1];else{if(!i.isPlainObject(n))return r;a=n}return l(a,(function(t,e,n){r.push({type:"layout",prop:t,value:n})}),"",0),r}function s(t,e){var r,n,a,o,s=[];if(n=e[0],a=e[1],r=e[2],o={},"string"==typeof n)o[n]=a;else{if(!i.isPlainObject(n))return s;o=n,void 0===r&&(r=a)}return void 0===r&&(r=null),l(o,(function(e,n,i){var a,o;if(Array.isArray(i)){o=i.slice();var l=Math.min(o.length,t.data.length);r&&(l=Math.min(l,r.length)),a=[];for(var c=0;c<l;c++)a[c]=r?r[c]:c}else o=i,a=r?r.slice():null;if(null===a)Array.isArray(o)&&(o=o[0]);else if(Array.isArray(a)){if(!Array.isArray(o)){var u=o;o=[];for(var f=0;f<a.length;f++)o[f]=u}o.length=Math.min(a.length,o.length)}s.push({type:"data",prop:e,traces:a,value:o})}),"",0),s}function l(t,e,r,n){Object.keys(t).forEach((function(a){var o=t[a];if("_"!==a[0]){var s=r+(n>0?".":"")+a;i.isPlainObject(o)?l(o,e,s,n+1):e(s,a,o)}}))}r.manageCommandObserver=function(t,e,n,o){var s={},l=!0;e&&e._commandObserver&&(s=e._commandObserver),s.cache||(s.cache={}),s.lookupTable={};var c=r.hasSimpleAPICommandBindings(t,n,s.lookupTable);if(e&&e._commandObserver){if(c)return s;if(e._commandObserver.remove)return e._commandObserver.remove(),e._commandObserver=null,s}if(c){a(t,c,s.cache),s.check=function(){if(l){var e=a(t,c,s.cache);return e.changed&&o&&void 0!==s.lookupTable[e.value]&&(s.disable(),Promise.resolve(o({value:e.value,type:c.type,prop:c.prop,traces:c.traces,index:s.lookupTable[e.value]})).then(s.enable,s.enable)),e.changed}};for(var u=["plotly_relayout","plotly_redraw","plotly_restyle","plotly_update","plotly_animatingframe","plotly_afterplot"],f=0;f<u.length;f++)t._internalOn(u[f],s.check);s.remove=function(){for(var e=0;e<u.length;e++)t._removeInternalListener(u[e],s.check)}}else i.log("Unable to automatically bind plot updates to API command"),s.lookupTable={},s.remove=function(){};return s.disable=function(){l=!1},s.enable=function(){l=!0},e&&(e._commandObserver=s),s},r.hasSimpleAPICommandBindings=function(t,e,n){var i,a,o=e.length;for(i=0;i<o;i++){var s,l=e[i],c=l.method,u=l.args;if(Array.isArray(u)||(u=[]),!c)return!1;var f=r.computeAPICommandBindings(t,c,u);if(1!==f.length)return!1;if(a){if((s=f[0]).type!==a.type)return!1;if(s.prop!==a.prop)return!1;if(Array.isArray(a.traces)){if(!Array.isArray(s.traces))return!1;s.traces.sort();for(var h=0;h<a.traces.length;h++)if(a.traces[h]!==s.traces[h])return!1}else if(s.prop!==a.prop)return!1}else a=f[0],Array.isArray(a.traces)&&a.traces.sort();var p=(s=f[0]).value;if(Array.isArray(p)){if(1!==p.length)return!1;p=p[0]}n&&(n[p]=i)}return a},r.executeAPICommand=function(t,e,r){if("skip"===e)return Promise.resolve();var a=n.apiMethodRegistry[e],o=[t];Array.isArray(r)||(r=[]);for(var s=0;s<r.length;s++)o.push(r[s]);return a.apply(null,o).catch((function(t){return i.warn("API call to Plotly."+e+" rejected.",t),Promise.reject(t)}))},r.computeAPICommandBindings=function(t,e,r){var n;switch(Array.isArray(r)||(r=[]),e){case"restyle":n=s(t,r);break;case"relayout":n=o(t,r);break;case"update":n=s(t,[r[0],r[2]]).concat(o(t,[r[1]]));break;case"animate":n=function(t,e){return Array.isArray(e[0])&&1===e[0].length&&-1!==["string","number"].indexOf(typeof e[0][0])?[{type:"layout",prop:"_currentFrame",value:e[0][0].toString()}]:[]}(0,r);break;default:n=[]}return n}},{"../lib":503,"../registry":638}],584:[function(t,e,r){"use strict";var n=t("../lib/extend").extendFlat;r.attributes=function(t,e){e=e||{};var r={valType:"info_array",editType:(t=t||{}).editType,items:[{valType:"number",min:0,max:1,editType:t.editType},{valType:"number",min:0,max:1,editType:t.editType}],dflt:[0,1]},i=(t.name&&t.name,t.trace,e.description&&e.description,{x:n({},r,{}),y:n({},r,{}),editType:t.editType});return t.noGridCell||(i.row={valType:"integer",min:0,dflt:0,editType:t.editType},i.column={valType:"integer",min:0,dflt:0,editType:t.editType}),i},r.defaults=function(t,e,r,n){var i=n&&n.x||[0,1],a=n&&n.y||[0,1],o=e.grid;if(o){var s=r("domain.column");void 0!==s&&(s<o.columns?i=o._domains.x[s]:delete t.domain.column);var l=r("domain.row");void 0!==l&&(l<o.rows?a=o._domains.y[l]:delete t.domain.row)}var c=r("domain.x",i),u=r("domain.y",a);c[0]<c[1]||(t.domain.x=i.slice()),u[0]<u[1]||(t.domain.y=a.slice())}},{"../lib/extend":493}],585:[function(t,e,r){"use strict";e.exports=function(t){var e=t.editType,r=t.colorEditType;void 0===r&&(r=e);var n={family:{valType:"string",noBlank:!0,strict:!0,editType:e},size:{valType:"number",min:1,editType:e},color:{valType:"color",editType:r},editType:e};return t.autoSize&&(n.size.dflt="auto"),t.autoColor&&(n.color.dflt="auto"),t.arrayOk&&(n.family.arrayOk=!0,n.size.arrayOk=!0,n.color.arrayOk=!0),n}},{}],586:[function(t,e,r){"use strict";e.exports={_isLinkedToArray:"frames_entry",group:{valType:"string"},name:{valType:"string"},traces:{valType:"any"},baseframe:{valType:"string"},data:{valType:"any"},layout:{valType:"any"}}},{}],587:[function(t,e,r){"use strict";r.projNames={airy:"airy",aitoff:"aitoff","albers usa":"albersUsa",albers:"albers",august:"august","azimuthal equal area":"azimuthalEqualArea","azimuthal equidistant":"azimuthalEquidistant",baker:"baker",bertin1953:"bertin1953",boggs:"boggs",bonne:"bonne",bottomley:"bottomley",bromley:"bromley",collignon:"collignon","conic conformal":"conicConformal","conic equal area":"conicEqualArea","conic equidistant":"conicEquidistant",craig:"craig",craster:"craster","cylindrical equal area":"cylindricalEqualArea","cylindrical stereographic":"cylindricalStereographic",eckert1:"eckert1",eckert2:"eckert2",eckert3:"eckert3",eckert4:"eckert4",eckert5:"eckert5",eckert6:"eckert6",eisenlohr:"eisenlohr",equirectangular:"equirectangular",fahey:"fahey","foucaut sinusoidal":"foucautSinusoidal",foucaut:"foucaut",ginzburg4:"ginzburg4",ginzburg5:"ginzburg5",ginzburg6:"ginzburg6",ginzburg8:"ginzburg8",ginzburg9:"ginzburg9",gnomonic:"gnomonic","gringorten quincuncial":"gringortenQuincuncial",gringorten:"gringorten",guyou:"guyou",hammer:"hammer",hill:"hill",homolosine:"homolosine",hufnagel:"hufnagel",hyperelliptical:"hyperelliptical",kavrayskiy7:"kavrayskiy7",lagrange:"lagrange",larrivee:"larrivee",laskowski:"laskowski",loximuthal:"loximuthal",mercator:"mercator",miller:"miller",mollweide:"mollweide","mt flat polar parabolic":"mtFlatPolarParabolic","mt flat polar quartic":"mtFlatPolarQuartic","mt flat polar sinusoidal":"mtFlatPolarSinusoidal","natural earth":"naturalEarth","natural earth1":"naturalEarth1","natural earth2":"naturalEarth2","nell hammer":"nellHammer",nicolosi:"nicolosi",orthographic:"orthographic",patterson:"patterson","peirce quincuncial":"peirceQuincuncial",polyconic:"polyconic","rectangular polyconic":"rectangularPolyconic",robinson:"robinson",satellite:"satellite","sinu mollweide":"sinuMollweide",sinusoidal:"sinusoidal",stereographic:"stereographic",times:"times","transverse mercator":"transverseMercator","van der grinten":"vanDerGrinten","van der grinten2":"vanDerGrinten2","van der grinten3":"vanDerGrinten3","van der grinten4":"vanDerGrinten4",wagner4:"wagner4",wagner6:"wagner6",wiechel:"wiechel","winkel tripel":"winkel3",winkel3:"winkel3"},r.axesNames=["lonaxis","lataxis"],r.lonaxisSpan={orthographic:180,"azimuthal equal area":360,"azimuthal equidistant":360,"conic conformal":180,gnomonic:160,stereographic:180,"transverse mercator":180,"*":360},r.lataxisSpan={"conic conformal":150,stereographic:179.5,"*":180},r.scopeDefaults={world:{lonaxisRange:[-180,180],lataxisRange:[-90,90],projType:"equirectangular",projRotate:[0,0,0]},usa:{lonaxisRange:[-180,-50],lataxisRange:[15,80],projType:"albers usa"},europe:{lonaxisRange:[-30,60],lataxisRange:[30,85],projType:"conic conformal",projRotate:[15,0,0],projParallels:[0,60]},asia:{lonaxisRange:[22,160],lataxisRange:[-15,55],projType:"mercator",projRotate:[0,0,0]},africa:{lonaxisRange:[-30,60],lataxisRange:[-40,40],projType:"mercator",projRotate:[0,0,0]},"north america":{lonaxisRange:[-180,-45],lataxisRange:[5,85],projType:"conic conformal",projRotate:[-100,0,0],projParallels:[29.5,45.5]},"south america":{lonaxisRange:[-100,-30],lataxisRange:[-60,15],projType:"mercator",projRotate:[0,0,0]}},r.clipPad=.001,r.precision=.1,r.landColor="#F0DC82",r.waterColor="#3399FF",r.locationmodeToLayer={"ISO-3":"countries","USA-states":"subunits","country names":"countries"},r.sphereSVG={type:"Sphere"},r.fillLayers={ocean:1,land:1,lakes:1},r.lineLayers={subunits:1,countries:1,coastlines:1,rivers:1,frame:1},r.layers=["bg","ocean","land","lakes","subunits","countries","coastlines","rivers","lataxis","lonaxis","frame","backplot","frontplot"],r.layersForChoropleth=["bg","ocean","land","subunits","countries","coastlines","lataxis","lonaxis","frame","backplot","rivers","lakes","frontplot"],r.layerNameToAdjective={ocean:"ocean",land:"land",lakes:"lake",subunits:"subunit",countries:"country",coastlines:"coastline",rivers:"river",frame:"frame"}},{}],588:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("d3-geo"),a=i.geoPath,o=i.geoDistance,s=t("d3-geo-projection"),l=t("../../registry"),c=t("../../lib"),u=c.strTranslate,f=t("../../components/color"),h=t("../../components/drawing"),p=t("../../components/fx"),d=t("../plots"),m=t("../cartesian/axes"),g=t("../cartesian/autorange").getAutoRange,v=t("../../components/dragelement"),y=t("../cartesian/select").prepSelect,x=t("../cartesian/select").clearSelect,b=t("../cartesian/select").selectOnClick,_=t("./zoom"),w=t("./constants"),T=t("../../lib/geo_location_utils"),k=t("../../lib/topojson_utils"),A=t("topojson-client").feature;function M(t){this.id=t.id,this.graphDiv=t.graphDiv,this.container=t.container,this.topojsonURL=t.topojsonURL,this.isStatic=t.staticPlot,this.topojsonName=null,this.topojson=null,this.projection=null,this.scope=null,this.viewInitial=null,this.fitScale=null,this.bounds=null,this.midPt=null,this.hasChoropleth=!1,this.traceHash={},this.layers={},this.basePaths={},this.dataPaths={},this.dataPoints={},this.clipDef=null,this.clipRect=null,this.bgRect=null,this.makeFramework()}var S=M.prototype;function E(t,e){var r=w.clipPad,n=t[0]+r,i=t[1]-r,a=e[0]+r,o=e[1]-r;n>0&&i<0&&(i+=360);var s=(i-n)/4;return{type:"Polygon",coordinates:[[[n,a],[n,o],[n+s,o],[n+2*s,o],[n+3*s,o],[i,o],[i,a],[i-s,a],[i-2*s,a],[i-3*s,a],[n,a]]]}}e.exports=function(t){return new M(t)},S.plot=function(t,e,r){var n=this,i=e[this.id],a=[],o=!1;for(var s in w.layerNameToAdjective)if("frame"!==s&&i["show"+s]){o=!0;break}for(var l=0;l<t.length;l++)if(t[0][0].trace.locationmode){o=!0;break}if(o){var c=k.getTopojsonName(i);null!==n.topojson&&c===n.topojsonName||(n.topojsonName=c,void 0===PlotlyGeoAssets.topojson[n.topojsonName]&&a.push(n.fetchTopojson()))}a=a.concat(T.fetchTraceGeoData(t)),r.push(new Promise((function(r,i){Promise.all(a).then((function(){n.topojson=PlotlyGeoAssets.topojson[n.topojsonName],n.update(t,e),r()})).catch(i)})))},S.fetchTopojson=function(){var t=this,e=k.getTopojsonPath(t.topojsonURL,t.topojsonName);return new Promise((function(r,i){n.json(e,(function(n,a){if(n)return 404===n.status?i(new Error(["plotly.js could not find topojson file at",e+".","Make sure the *topojsonURL* plot config option","is set properly."].join(" "))):i(new Error(["unexpected error while fetching topojson file at",e].join(" ")));PlotlyGeoAssets.topojson[t.topojsonName]=a,r()}))}))},S.update=function(t,e){var r=e[this.id];this.hasChoropleth=!1;for(var n=0;n<t.length;n++){var i=t[n],a=i[0].trace;"choropleth"===a.type&&(this.hasChoropleth=!0),!0===a.visible&&a._length>0&&a._module.calcGeoJSON(i,e)}if(!this.updateProjection(t,e)){this.viewInitial&&this.scope===r.scope||this.saveViewInitial(r),this.scope=r.scope,this.updateBaseLayers(e,r),this.updateDims(e,r),this.updateFx(e,r),d.generalUpdatePerTraceModule(this.graphDiv,this,t,r);var o=this.layers.frontplot.select(".scatterlayer");this.dataPoints.point=o.selectAll(".point"),this.dataPoints.text=o.selectAll("text"),this.dataPaths.line=o.selectAll(".js-line");var s=this.layers.backplot.select(".choroplethlayer");this.dataPaths.choropleth=s.selectAll("path"),this.render()}},S.updateProjection=function(t,e){var r=this.graphDiv,n=e[this.id],l=e._size,u=n.domain,f=n.projection,h=n.lonaxis,p=n.lataxis,d=h._ax,m=p._ax,v=this.projection=function(t){var e=t.projection,r=e.type,n=w.projNames[r];n="geo"+c.titleCase(n);for(var l=(i[n]||s[n])(),u=t._isSatellite?180*Math.acos(1/e.distance)/Math.PI:t._isClipped?w.lonaxisSpan[r]/2:null,f=["center","rotate","parallels","clipExtent"],h=function(t){return t?l:[]},p=0;p<f.length;p++){var d=f[p];"function"!=typeof l[d]&&(l[d]=h)}l.isLonLatOverEdges=function(t){if(null===l(t))return!0;if(u){var e=l.rotate();return o(t,[-e[0],-e[1]])>u*Math.PI/180}return!1},l.getPath=function(){return a().projection(l)},l.getBounds=function(t){return l.getPath().bounds(t)},l.precision(w.precision),t._isSatellite&&l.tilt(e.tilt).distance(e.distance);u&&l.clipAngle(u-w.clipPad);return l}(n),y=[[l.l+l.w*u.x[0],l.t+l.h*(1-u.y[1])],[l.l+l.w*u.x[1],l.t+l.h*(1-u.y[0])]],x=n.center||{},b=f.rotation||{},_=h.range||[],T=p.range||[];if(n.fitbounds){d._length=y[1][0]-y[0][0],m._length=y[1][1]-y[0][1],d.range=g(r,d),m.range=g(r,m);var k=(d.range[0]+d.range[1])/2,A=(m.range[0]+m.range[1])/2;if(n._isScoped)x={lon:k,lat:A};else if(n._isClipped){x={lon:k,lat:A},b={lon:k,lat:A,roll:b.roll};var M=f.type,S=w.lonaxisSpan[M]/2||180,L=w.lataxisSpan[M]/2||90;_=[k-S,k+S],T=[A-L,A+L]}else x={lon:k,lat:A},b={lon:k,lat:b.lat,roll:b.roll}}v.center([x.lon-b.lon,x.lat-b.lat]).rotate([-b.lon,-b.lat,b.roll]).parallels(f.parallels);var C=E(_,T);v.fitExtent(y,C);var P=this.bounds=v.getBounds(C),I=this.fitScale=v.scale(),O=v.translate();if(n.fitbounds){var z=v.getBounds(E(d.range,m.range)),D=Math.min((P[1][0]-P[0][0])/(z[1][0]-z[0][0]),(P[1][1]-P[0][1])/(z[1][1]-z[0][1]));isFinite(D)?v.scale(D*I):c.warn("Something went wrong during"+this.id+"fitbounds computations.")}else v.scale(f.scale*I);var R=this.midPt=[(P[0][0]+P[1][0])/2,(P[0][1]+P[1][1])/2];if(v.translate([O[0]+(R[0]-O[0]),O[1]+(R[1]-O[1])]).clipExtent(P),n._isAlbersUsa){var F=v([x.lon,x.lat]),B=v.translate();v.translate([B[0]-(F[0]-B[0]),B[1]-(F[1]-B[1])])}},S.updateBaseLayers=function(t,e){var r=this,i=r.topojson,a=r.layers,o=r.basePaths;function s(t){return"lonaxis"===t||"lataxis"===t}function l(t){return Boolean(w.lineLayers[t])}function c(t){return Boolean(w.fillLayers[t])}var u=(this.hasChoropleth?w.layersForChoropleth:w.layers).filter((function(t){return l(t)||c(t)?e["show"+t]:!s(t)||e[t].showgrid})),p=r.framework.selectAll(".layer").data(u,String);p.exit().each((function(t){delete a[t],delete o[t],n.select(this).remove()})),p.enter().append("g").attr("class",(function(t){return"layer "+t})).each((function(t){var e=a[t]=n.select(this);"bg"===t?r.bgRect=e.append("rect").style("pointer-events","all"):s(t)?o[t]=e.append("path").style("fill","none"):"backplot"===t?e.append("g").classed("choroplethlayer",!0):"frontplot"===t?e.append("g").classed("scatterlayer",!0):l(t)?o[t]=e.append("path").style("fill","none").style("stroke-miterlimit",2):c(t)&&(o[t]=e.append("path").style("stroke","none"))})),p.order(),p.each((function(r){var n=o[r],a=w.layerNameToAdjective[r];"frame"===r?n.datum(w.sphereSVG):l(r)||c(r)?n.datum(A(i,i.objects[r])):s(r)&&n.datum(function(t,e,r){var n,i,a,o=e[t],s=w.scopeDefaults[e.scope];"lonaxis"===t?(n=s.lonaxisRange,i=s.lataxisRange,a=function(t,e){return[t,e]}):"lataxis"===t&&(n=s.lataxisRange,i=s.lonaxisRange,a=function(t,e){return[e,t]});var l={type:"linear",range:[n[0],n[1]-1e-6],tick0:o.tick0,dtick:o.dtick};m.setConvert(l,r);var c=m.calcTicks(l);e.isScoped||"lonaxis"!==t||c.pop();for(var u=c.length,f=new Array(u),h=0;h<u;h++)for(var p=c[h].x,d=f[h]=[],g=i[0];g<i[1]+2.5;g+=2.5)d.push(a(p,g));return{type:"MultiLineString",coordinates:f}}(r,e,t)).call(f.stroke,e[r].gridcolor).call(h.dashLine,e[r].griddash,e[r].gridwidth),l(r)?n.call(f.stroke,e[a+"color"]).call(h.dashLine,"",e[a+"width"]):c(r)&&n.call(f.fill,e[a+"color"])}))},S.updateDims=function(t,e){var r=this.bounds,n=(e.framewidth||0)/2,i=r[0][0]-n,a=r[0][1]-n,o=r[1][0]-i+n,s=r[1][1]-a+n;h.setRect(this.clipRect,i,a,o,s),this.bgRect.call(h.setRect,i,a,o,s).call(f.fill,e.bgcolor),this.xaxis._offset=i,this.xaxis._length=o,this.yaxis._offset=a,this.yaxis._length=s},S.updateFx=function(t,e){var r=this,i=r.graphDiv,a=r.bgRect,o=t.dragmode,s=t.clickmode;if(!r.isStatic){var u;"select"===o?u=function(t,e){(t.range={})[r.id]=[h([e.xmin,e.ymin]),h([e.xmax,e.ymax])]}:"lasso"===o&&(u=function(t,e,n){(t.lassoPoints={})[r.id]=n.filtered.map(h)});var f={element:r.bgRect.node(),gd:i,plotinfo:{id:r.id,xaxis:r.xaxis,yaxis:r.yaxis,fillRangeItems:u},xaxes:[r.xaxis],yaxes:[r.yaxis],subplot:r.id,clickFn:function(t){2===t&&x(i)}};"pan"===o?(a.node().onmousedown=null,a.call(_(r,e)),a.on("dblclick.zoom",(function(){var t=r.viewInitial,e={};for(var n in t)e[r.id+"."+n]=t[n];l.call("_guiRelayout",i,e),i.emit("plotly_doubleclick",null)})),i._context._scrollZoom.geo||a.on("wheel.zoom",null)):"select"!==o&&"lasso"!==o||(a.on(".zoom",null),f.prepFn=function(t,e,r){y(t,e,r,f,o)},v.init(f)),a.on("mousemove",(function(){var t=r.projection.invert(c.getPositionFromD3Event());if(!t)return v.unhover(i,n.event);r.xaxis.p2c=function(){return t[0]},r.yaxis.p2c=function(){return t[1]},p.hover(i,n.event,r.id)})),a.on("mouseout",(function(){i._dragging||v.unhover(i,n.event)})),a.on("click",(function(){"select"!==o&&"lasso"!==o&&(s.indexOf("select")>-1&&b(n.event,i,[r.xaxis],[r.yaxis],r.id,f),s.indexOf("event")>-1&&p.click(i,n.event))}))}function h(t){return r.projection.invert([t[0]+r.xaxis._offset,t[1]+r.yaxis._offset])}},S.makeFramework=function(){var t=this,e=t.graphDiv,r=e._fullLayout,i="clip"+r._uid+t.id;t.clipDef=r._clips.append("clipPath").attr("id",i),t.clipRect=t.clipDef.append("rect"),t.framework=n.select(t.container).append("g").attr("class","geo "+t.id).call(h.setClipUrl,i,e),t.project=function(e){var r=t.projection(e);return r?[r[0]-t.xaxis._offset,r[1]-t.yaxis._offset]:[null,null]},t.xaxis={_id:"x",c2p:function(e){return t.project(e)[0]}},t.yaxis={_id:"y",c2p:function(e){return t.project(e)[1]}},t.mockAxis={type:"linear",showexponent:"all",exponentformat:"B"},m.setConvert(t.mockAxis,r)},S.saveViewInitial=function(t){var e,r=t.center||{},n=t.projection,i=n.rotation||{};this.viewInitial={fitbounds:t.fitbounds,"projection.scale":n.scale},e=t._isScoped?{"center.lon":r.lon,"center.lat":r.lat}:t._isClipped?{"projection.rotation.lon":i.lon,"projection.rotation.lat":i.lat}:{"center.lon":r.lon,"center.lat":r.lat,"projection.rotation.lon":i.lon},c.extendFlat(this.viewInitial,e)},S.render=function(){var t,e=this.projection,r=e.getPath();function n(t){var r=e(t.lonlat);return r?u(r[0],r[1]):null}function i(t){return e.isLonLatOverEdges(t.lonlat)?"none":null}for(t in this.basePaths)this.basePaths[t].attr("d",r);for(t in this.dataPaths)this.dataPaths[t].attr("d",(function(t){return r(t.geojson)}));for(t in this.dataPoints)this.dataPoints[t].attr("display",i).attr("transform",n)}},{"../../components/color":366,"../../components/dragelement":385,"../../components/drawing":388,"../../components/fx":406,"../../lib":503,"../../lib/geo_location_utils":496,"../../lib/topojson_utils":532,"../../registry":638,"../cartesian/autorange":553,"../cartesian/axes":554,"../cartesian/select":575,"../plots":619,"./constants":587,"./zoom":592,"@plotly/d3":58,"d3-geo":114,"d3-geo-projection":113,"topojson-client":315}],589:[function(t,e,r){"use strict";var n=t("../../plots/get_data").getSubplotCalcData,i=t("../../lib").counterRegex,a=t("./geo"),o="geo",s=i(o),l={};l.geo={valType:"subplotid",dflt:o,editType:"calc"},e.exports={attr:o,name:o,idRoot:o,idRegex:s,attrRegex:s,attributes:l,layoutAttributes:t("./layout_attributes"),supplyLayoutDefaults:t("./layout_defaults"),plot:function(t){for(var e=t._fullLayout,r=t.calcdata,i=e._subplots.geo,s=0;s<i.length;s++){var l=i[s],c=n(r,o,l),u=e[l]._subplot;u||(u=a({id:l,graphDiv:t,container:e._geolayer.node(),topojsonURL:t._context.topojsonURL,staticPlot:t._context.staticPlot}),e[l]._subplot=u),u.plot(c,e,t._promises)}},updateFx:function(t){for(var e=t._fullLayout,r=e._subplots.geo,n=0;n<r.length;n++){var i=e[r[n]];i._subplot.updateFx(e,i)}},clean:function(t,e,r,n){for(var i=n._subplots.geo||[],a=0;a<i.length;a++){var o=i[a],s=n[o]._subplot;!e[o]&&s&&(s.framework.remove(),s.clipDef.remove())}}}},{"../../lib":503,"../../plots/get_data":593,"./geo":588,"./layout_attributes":590,"./layout_defaults":591}],590:[function(t,e,r){"use strict";var n=t("../../components/color/attributes"),i=t("../domain").attributes,a=t("../../components/drawing/attributes").dash,o=t("./constants"),s=t("../../plot_api/edit_types").overrideAll,l=t("../../lib/sort_object_keys"),c={range:{valType:"info_array",items:[{valType:"number"},{valType:"number"}]},showgrid:{valType:"boolean",dflt:!1},tick0:{valType:"number",dflt:0},dtick:{valType:"number"},gridcolor:{valType:"color",dflt:n.lightLine},gridwidth:{valType:"number",min:0,dflt:1},griddash:a};(e.exports=s({domain:i({name:"geo"},{}),fitbounds:{valType:"enumerated",values:[!1,"locations","geojson"],dflt:!1,editType:"plot"},resolution:{valType:"enumerated",values:[110,50],dflt:110,coerceNumber:!0},scope:{valType:"enumerated",values:l(o.scopeDefaults),dflt:"world"},projection:{type:{valType:"enumerated",values:l(o.projNames)},rotation:{lon:{valType:"number"},lat:{valType:"number"},roll:{valType:"number"}},tilt:{valType:"number",dflt:0},distance:{valType:"number",min:1.001,dflt:2},parallels:{valType:"info_array",items:[{valType:"number"},{valType:"number"}]},scale:{valType:"number",min:0,dflt:1}},center:{lon:{valType:"number"},lat:{valType:"number"}},visible:{valType:"boolean",dflt:!0},showcoastlines:{valType:"boolean"},coastlinecolor:{valType:"color",dflt:n.defaultLine},coastlinewidth:{valType:"number",min:0,dflt:1},showland:{valType:"boolean",dflt:!1},landcolor:{valType:"color",dflt:o.landColor},showocean:{valType:"boolean",dflt:!1},oceancolor:{valType:"color",dflt:o.waterColor},showlakes:{valType:"boolean",dflt:!1},lakecolor:{valType:"color",dflt:o.waterColor},showrivers:{valType:"boolean",dflt:!1},rivercolor:{valType:"color",dflt:o.waterColor},riverwidth:{valType:"number",min:0,dflt:1},showcountries:{valType:"boolean"},countrycolor:{valType:"color",dflt:n.defaultLine},countrywidth:{valType:"number",min:0,dflt:1},showsubunits:{valType:"boolean"},subunitcolor:{valType:"color",dflt:n.defaultLine},subunitwidth:{valType:"number",min:0,dflt:1},showframe:{valType:"boolean"},framecolor:{valType:"color",dflt:n.defaultLine},framewidth:{valType:"number",min:0,dflt:1},bgcolor:{valType:"color",dflt:n.background},lonaxis:c,lataxis:c},"plot","from-root")).uirevision={valType:"any",editType:"none"}},{"../../components/color/attributes":365,"../../components/drawing/attributes":387,"../../lib/sort_object_keys":526,"../../plot_api/edit_types":536,"../domain":584,"./constants":587}],591:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../subplot_defaults"),a=t("../get_data").getSubplotData,o=t("./constants"),s=t("./layout_attributes"),l=o.axesNames;function c(t,e,r,i){var s=a(i.fullData,"geo",i.id).map((function(t){return t._expandedIndex})),c=r("resolution"),u=r("scope"),f=o.scopeDefaults[u],h=r("projection.type",f.projType),p=e._isAlbersUsa="albers usa"===h;p&&(u=e.scope="usa");var d=e._isScoped="world"!==u,m=e._isSatellite="satellite"===h,g=e._isConic=-1!==h.indexOf("conic")||"albers"===h,v=e._isClipped=!!o.lonaxisSpan[h];if(!1===t.visible){var y=n.extendDeep({},e._template);y.showcoastlines=!1,y.showcountries=!1,y.showframe=!1,y.showlakes=!1,y.showland=!1,y.showocean=!1,y.showrivers=!1,y.showsubunits=!1,y.lonaxis&&(y.lonaxis.showgrid=!1),y.lataxis&&(y.lataxis.showgrid=!1),e._template=y}for(var x=r("visible"),b=0;b<l.length;b++){var _,w=l[b],T=[30,10][b];if(d)_=f[w+"Range"];else{var k=o[w+"Span"],A=(k[h]||k["*"])/2,M=r("projection.rotation."+w.substr(0,3),f.projRotate[b]);_=[M-A,M+A]}var S=r(w+".range",_);r(w+".tick0"),r(w+".dtick",T),r(w+".showgrid",!!x&&void 0)&&(r(w+".gridcolor"),r(w+".gridwidth"),r(w+".griddash")),e[w]._ax={type:"linear",_id:w.slice(0,3),_traceIndices:s,setScale:n.identity,c2l:n.identity,r2l:n.identity,autorange:!0,range:S.slice(),_m:1,_input:{}}}var E=e.lonaxis.range,L=e.lataxis.range,C=E[0],P=E[1];C>0&&P<0&&(P+=360);var I,O,z,D=(C+P)/2;if(!p){var R=d?f.projRotate:[D,0,0];I=r("projection.rotation.lon",R[0]),r("projection.rotation.lat",R[1]),r("projection.rotation.roll",R[2]),r("showcoastlines",!d&&x)&&(r("coastlinecolor"),r("coastlinewidth")),r("showocean",!!x&&void 0)&&r("oceancolor")}(p?(O=-96.6,z=38.7):(O=d?D:I,z=(L[0]+L[1])/2),r("center.lon",O),r("center.lat",z),m&&(r("projection.tilt"),r("projection.distance")),g)&&r("projection.parallels",f.projParallels||[0,60]);r("projection.scale"),r("showland",!!x&&void 0)&&r("landcolor"),r("showlakes",!!x&&void 0)&&r("lakecolor"),r("showrivers",!!x&&void 0)&&(r("rivercolor"),r("riverwidth")),r("showcountries",d&&"usa"!==u&&x)&&(r("countrycolor"),r("countrywidth")),("usa"===u||"north america"===u&&50===c)&&(r("showsubunits",x),r("subunitcolor"),r("subunitwidth")),d||r("showframe",x)&&(r("framecolor"),r("framewidth")),r("bgcolor"),r("fitbounds")&&(delete e.projection.scale,d?(delete e.center.lon,delete e.center.lat):v?(delete e.center.lon,delete e.center.lat,delete e.projection.rotation.lon,delete e.projection.rotation.lat,delete e.lonaxis.range,delete e.lataxis.range):(delete e.center.lon,delete e.center.lat,delete e.projection.rotation.lon))}e.exports=function(t,e,r){i(t,e,r,{type:"geo",attributes:s,handleDefaults:c,fullData:r,partition:"y"})}},{"../../lib":503,"../get_data":593,"../subplot_defaults":632,"./constants":587,"./layout_attributes":590}],592:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../../registry"),o=Math.PI/180,s=180/Math.PI,l={cursor:"pointer"},c={cursor:"auto"};function u(t,e){return n.behavior.zoom().translate(e.translate()).scale(e.scale())}function f(t,e,r){var n=t.id,o=t.graphDiv,s=o.layout,l=s[n],c=o._fullLayout,u=c[n],f={},h={};function p(t,e){f[n+"."+t]=i.nestedProperty(l,t).get(),a.call("_storeDirectGUIEdit",s,c._preGUI,f);var r=i.nestedProperty(u,t);r.get()!==e&&(r.set(e),i.nestedProperty(l,t).set(e),h[n+"."+t]=e)}r(p),p("projection.scale",e.scale()/t.fitScale),p("fitbounds",!1),o.emit("plotly_relayout",h)}function h(t,e){var r=u(0,e);function i(r){var n=e.invert(t.midPt);r("center.lon",n[0]),r("center.lat",n[1])}return r.on("zoomstart",(function(){n.select(this).style(l)})).on("zoom",(function(){e.scale(n.event.scale).translate(n.event.translate),t.render();var r=e.invert(t.midPt);t.graphDiv.emit("plotly_relayouting",{"geo.projection.scale":e.scale()/t.fitScale,"geo.center.lon":r[0],"geo.center.lat":r[1]})})).on("zoomend",(function(){n.select(this).style(c),f(t,e,i)})),r}function p(t,e){var r,i,a,o,s,h,p,d,m,g=u(0,e);function v(t){return e.invert(t)}function y(r){var n=e.rotate(),i=e.invert(t.midPt);r("projection.rotation.lon",-n[0]),r("center.lon",i[0]),r("center.lat",i[1])}return g.on("zoomstart",(function(){n.select(this).style(l),r=n.mouse(this),i=e.rotate(),a=e.translate(),o=i,s=v(r)})).on("zoom",(function(){if(h=n.mouse(this),function(t){var r=v(t);if(!r)return!0;var n=e(r);return Math.abs(n[0]-t[0])>2||Math.abs(n[1]-t[1])>2}(r))return g.scale(e.scale()),void g.translate(e.translate());e.scale(n.event.scale),e.translate([a[0],n.event.translate[1]]),s?v(h)&&(d=v(h),p=[o[0]+(d[0]-s[0]),i[1],i[2]],e.rotate(p),o=p):s=v(r=h),m=!0,t.render();var l=e.rotate(),c=e.invert(t.midPt);t.graphDiv.emit("plotly_relayouting",{"geo.projection.scale":e.scale()/t.fitScale,"geo.center.lon":c[0],"geo.center.lat":c[1],"geo.projection.rotation.lon":-l[0]})})).on("zoomend",(function(){n.select(this).style(c),m&&f(t,e,y)})),g}function d(t,e){var r,i={r:e.rotate(),k:e.scale()},a=u(0,e),o=function(t){var e=0,r=arguments.length,i=[];for(;++e<r;)i.push(arguments[e]);var a=n.dispatch.apply(null,i);return a.of=function(e,r){return function(i){var o;try{o=i.sourceEvent=n.event,i.target=t,n.event=i,a[i.type].apply(e,r)}finally{n.event=o}}},a}(a,"zoomstart","zoom","zoomend"),s=0,h=a.on;function p(t){s++||t({type:"zoomstart"})}function d(t){t({type:"zoom"})}function b(t){--s||t({type:"zoomend"})}function _(t){var r=e.rotate();t("projection.rotation.lon",-r[0]),t("projection.rotation.lat",-r[1])}return a.on("zoomstart",(function(){n.select(this).style(l);var t=n.mouse(this),s=e.rotate(),c=s,u=e.translate(),f=g(s);r=m(e,t),h.call(a,"zoom",(function(){var a=n.mouse(this);if(e.scale(i.k=n.event.scale),r){if(m(e,a)){e.rotate(s).translate(u);var l=m(e,a),h=y(r,l),p=T(v(f,h)),g=i.r=x(p,r,c);isFinite(g[0])&&isFinite(g[1])&&isFinite(g[2])||(g=c),e.rotate(g),c=g}}else r=m(e,t=a);d(o.of(this,arguments))})),p(o.of(this,arguments))})).on("zoomend",(function(){n.select(this).style(c),h.call(a,"zoom",null),b(o.of(this,arguments)),f(t,e,_)})).on("zoom.redraw",(function(){t.render();var r=e.rotate();t.graphDiv.emit("plotly_relayouting",{"geo.projection.scale":e.scale()/t.fitScale,"geo.projection.rotation.lon":-r[0],"geo.projection.rotation.lat":-r[1]})})),n.rebind(a,o,"on")}function m(t,e){var r=t.invert(e);return r&&isFinite(r[0])&&isFinite(r[1])&&function(t){var e=t[0]*o,r=t[1]*o,n=Math.cos(r);return[n*Math.cos(e),n*Math.sin(e),Math.sin(r)]}(r)}function g(t){var e=.5*t[0]*o,r=.5*t[1]*o,n=.5*t[2]*o,i=Math.sin(e),a=Math.cos(e),s=Math.sin(r),l=Math.cos(r),c=Math.sin(n),u=Math.cos(n);return[a*l*u+i*s*c,i*l*u-a*s*c,a*s*u+i*l*c,a*l*c-i*s*u]}function v(t,e){var r=t[0],n=t[1],i=t[2],a=t[3],o=e[0],s=e[1],l=e[2],c=e[3];return[r*o-n*s-i*l-a*c,r*s+n*o+i*c-a*l,r*l-n*c+i*o+a*s,r*c+n*l-i*s+a*o]}function y(t,e){if(t&&e){var r=function(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}(t,e),n=Math.sqrt(k(r,r)),i=.5*Math.acos(Math.max(-1,Math.min(1,k(t,e)))),a=Math.sin(i)/n;return n&&[Math.cos(i),r[2]*a,-r[1]*a,r[0]*a]}}function x(t,e,r){var n=w(e,2,t[0]);n=w(n,1,t[1]),n=w(n,0,t[2]-r[2]);var i,a,o=e[0],l=e[1],c=e[2],u=n[0],f=n[1],h=n[2],p=Math.atan2(l,o)*s,d=Math.sqrt(o*o+l*l);Math.abs(f)>d?(a=(f>0?90:-90)-p,i=0):(a=Math.asin(f/d)*s-p,i=Math.sqrt(d*d-f*f));var m=180-a-2*p,g=(Math.atan2(h,u)-Math.atan2(c,i))*s,v=(Math.atan2(h,u)-Math.atan2(c,-i))*s;return b(r[0],r[1],a,g)<=b(r[0],r[1],m,v)?[a,g,r[2]]:[m,v,r[2]]}function b(t,e,r,n){var i=_(r-t),a=_(n-e);return Math.sqrt(i*i+a*a)}function _(t){return(t%360+540)%360-180}function w(t,e,r){var n=r*o,i=t.slice(),a=0===e?1:0,s=2===e?1:2,l=Math.cos(n),c=Math.sin(n);return i[a]=t[a]*l-t[s]*c,i[s]=t[s]*l+t[a]*c,i}function T(t){return[Math.atan2(2*(t[0]*t[1]+t[2]*t[3]),1-2*(t[1]*t[1]+t[2]*t[2]))*s,Math.asin(Math.max(-1,Math.min(1,2*(t[0]*t[2]-t[3]*t[1]))))*s,Math.atan2(2*(t[0]*t[3]+t[1]*t[2]),1-2*(t[2]*t[2]+t[3]*t[3]))*s]}function k(t,e){for(var r=0,n=0,i=t.length;n<i;++n)r+=t[n]*e[n];return r}e.exports=function(t,e){var r=t.projection;return(e._isScoped?h:e._isClipped?d:p)(t,r)}},{"../../lib":503,"../../registry":638,"@plotly/d3":58}],593:[function(t,e,r){"use strict";var n=t("../registry"),i=t("./cartesian/constants").SUBPLOT_PATTERN;r.getSubplotCalcData=function(t,e,r){var i=n.subplotsRegistry[e];if(!i)return[];for(var a=i.attr,o=[],s=0;s<t.length;s++){var l=t[s];l[0].trace[a]===r&&o.push(l)}return o},r.getModuleCalcData=function(t,e){var r,i=[],a=[];if(!(r="string"==typeof e?n.getModule(e).plot:"function"==typeof e?e:e.plot))return[i,t];for(var o=0;o<t.length;o++){var s=t[o],l=s[0].trace;!0===l.visible&&0!==l._length&&(l._module.plot===r?i.push(s):a.push(s))}return[i,a]},r.getSubplotData=function(t,e,r){if(!n.subplotsRegistry[e])return[];var a,o,s,l=n.subplotsRegistry[e].attr,c=[];if("gl2d"===e){var u=r.match(i);o="x"+u[1],s="y"+u[2]}for(var f=0;f<t.length;f++)a=t[f],"gl2d"===e&&n.traceIs(a,"gl2d")?a[l[0]]===o&&a[l[1]]===s&&c.push(a):a[l]===r&&c.push(a);return c}},{"../registry":638,"./cartesian/constants":561}],594:[function(t,e,r){"use strict";var n=t("mouse-change"),i=t("mouse-wheel"),a=t("mouse-event-offset"),o=t("../cartesian/constants"),s=t("has-passive-events");function l(t,e){this.element=t,this.plot=e,this.mouseListener=null,this.wheelListener=null,this.lastInputTime=Date.now(),this.lastPos=[0,0],this.boxEnabled=!1,this.boxInited=!1,this.boxStart=[0,0],this.boxEnd=[0,0],this.dragStart=[0,0]}e.exports=function(t){var e=t.mouseContainer,r=t.glplot,c=new l(e,r);function u(){t.xaxis.autorange=!1,t.yaxis.autorange=!1}function f(e,n,i){var a,s,l=t.calcDataBox(),f=r.viewBox,h=c.lastPos[0],p=c.lastPos[1],d=o.MINDRAG*r.pixelRatio,m=o.MINZOOM*r.pixelRatio;function g(e,r,n){var i=Math.min(r,n),a=Math.max(r,n);i!==a?(l[e]=i,l[e+2]=a,c.dataBox=l,t.setRanges(l)):(t.selectBox.selectBox=[0,0,1,1],t.glplot.setDirty())}switch(n*=r.pixelRatio,i*=r.pixelRatio,i=f[3]-f[1]-i,t.fullLayout.dragmode){case"zoom":if(e){var v=n/(f[2]-f[0])*(l[2]-l[0])+l[0],y=i/(f[3]-f[1])*(l[3]-l[1])+l[1];c.boxInited||(c.boxStart[0]=v,c.boxStart[1]=y,c.dragStart[0]=n,c.dragStart[1]=i),c.boxEnd[0]=v,c.boxEnd[1]=y,c.boxInited=!0,c.boxEnabled||c.boxStart[0]===c.boxEnd[0]&&c.boxStart[1]===c.boxEnd[1]||(c.boxEnabled=!0);var x=Math.abs(c.dragStart[0]-n)<m,b=Math.abs(c.dragStart[1]-i)<m;if(!function(){for(var e=t.graphDiv._fullLayout._axisConstraintGroups,r=t.xaxis._id,n=t.yaxis._id,i=0;i<e.length;i++)if(-1!==e[i][r]){if(-1!==e[i][n])return!0;break}return!1}()||x&&b)x&&(c.boxEnd[0]=c.boxStart[0]),b&&(c.boxEnd[1]=c.boxStart[1]);else{a=c.boxEnd[0]-c.boxStart[0],s=c.boxEnd[1]-c.boxStart[1];var _=(l[3]-l[1])/(l[2]-l[0]);Math.abs(a*_)>Math.abs(s)?(c.boxEnd[1]=c.boxStart[1]+Math.abs(a)*_*(s>=0?1:-1),c.boxEnd[1]<l[1]?(c.boxEnd[1]=l[1],c.boxEnd[0]=c.boxStart[0]+(l[1]-c.boxStart[1])/Math.abs(_)):c.boxEnd[1]>l[3]&&(c.boxEnd[1]=l[3],c.boxEnd[0]=c.boxStart[0]+(l[3]-c.boxStart[1])/Math.abs(_))):(c.boxEnd[0]=c.boxStart[0]+Math.abs(s)/_*(a>=0?1:-1),c.boxEnd[0]<l[0]?(c.boxEnd[0]=l[0],c.boxEnd[1]=c.boxStart[1]+(l[0]-c.boxStart[0])*Math.abs(_)):c.boxEnd[0]>l[2]&&(c.boxEnd[0]=l[2],c.boxEnd[1]=c.boxStart[1]+(l[2]-c.boxStart[0])*Math.abs(_)))}}else c.boxEnabled?(a=c.boxStart[0]!==c.boxEnd[0],s=c.boxStart[1]!==c.boxEnd[1],a||s?(a&&(g(0,c.boxStart[0],c.boxEnd[0]),t.xaxis.autorange=!1),s&&(g(1,c.boxStart[1],c.boxEnd[1]),t.yaxis.autorange=!1),t.relayoutCallback()):t.glplot.setDirty(),c.boxEnabled=!1,c.boxInited=!1):c.boxInited&&(c.boxInited=!1);break;case"pan":c.boxEnabled=!1,c.boxInited=!1,e?(c.panning||(c.dragStart[0]=n,c.dragStart[1]=i),Math.abs(c.dragStart[0]-n)<d&&(n=c.dragStart[0]),Math.abs(c.dragStart[1]-i)<d&&(i=c.dragStart[1]),a=(h-n)*(l[2]-l[0])/(r.viewBox[2]-r.viewBox[0]),s=(p-i)*(l[3]-l[1])/(r.viewBox[3]-r.viewBox[1]),l[0]+=a,l[2]+=a,l[1]+=s,l[3]+=s,t.setRanges(l),c.panning=!0,c.lastInputTime=Date.now(),u(),t.cameraChanged(),t.handleAnnotations()):c.panning&&(c.panning=!1,t.relayoutCallback())}c.lastPos[0]=n,c.lastPos[1]=i}return c.mouseListener=n(e,f),e.addEventListener("touchstart",(function(t){var r=a(t.changedTouches[0],e);f(0,r[0],r[1]),f(1,r[0],r[1]),t.preventDefault()}),!!s&&{passive:!1}),e.addEventListener("touchmove",(function(t){t.preventDefault();var r=a(t.changedTouches[0],e);f(1,r[0],r[1]),t.preventDefault()}),!!s&&{passive:!1}),e.addEventListener("touchend",(function(t){f(0,c.lastPos[0],c.lastPos[1]),t.preventDefault()}),!!s&&{passive:!1}),c.wheelListener=i(e,(function(e,n){if(!t.scrollZoom)return!1;var i=t.calcDataBox(),a=r.viewBox,o=c.lastPos[0],s=c.lastPos[1],l=Math.exp(5*n/(a[3]-a[1])),f=o/(a[2]-a[0])*(i[2]-i[0])+i[0],h=s/(a[3]-a[1])*(i[3]-i[1])+i[1];return i[0]=(i[0]-f)*l+f,i[2]=(i[2]-f)*l+f,i[1]=(i[1]-h)*l+h,i[3]=(i[3]-h)*l+h,t.setRanges(i),c.lastInputTime=Date.now(),u(),t.cameraChanged(),t.handleAnnotations(),t.relayoutCallback(),!0}),!0),c}},{"../cartesian/constants":561,"has-passive-events":229,"mouse-change":241,"mouse-event-offset":242,"mouse-wheel":244}],595:[function(t,e,r){"use strict";var n=t("../cartesian/axes"),i=t("../../lib/str2rgbarray");function a(t){this.scene=t,this.gl=t.gl,this.pixelRatio=t.pixelRatio,this.screenBox=[0,0,1,1],this.viewBox=[0,0,1,1],this.dataBox=[-1,-1,1,1],this.borderLineEnable=[!1,!1,!1,!1],this.borderLineWidth=[1,1,1,1],this.borderLineColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.ticks=[[],[]],this.tickEnable=[!0,!0,!1,!1],this.tickPad=[15,15,15,15],this.tickAngle=[0,0,0,0],this.tickColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.tickMarkLength=[0,0,0,0],this.tickMarkWidth=[0,0,0,0],this.tickMarkColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.labels=["x","y"],this.labelEnable=[!0,!0,!1,!1],this.labelAngle=[0,Math.PI/2,0,3*Math.PI/2],this.labelPad=[15,15,15,15],this.labelSize=[12,12],this.labelFont=["sans-serif","sans-serif"],this.labelColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.title="",this.titleEnable=!0,this.titleCenter=[0,0,0,0],this.titleAngle=0,this.titleColor=[0,0,0,1],this.titleFont="sans-serif",this.titleSize=18,this.gridLineEnable=[!0,!0],this.gridLineColor=[[0,0,0,.5],[0,0,0,.5]],this.gridLineWidth=[1,1],this.zeroLineEnable=[!0,!0],this.zeroLineWidth=[1,1],this.zeroLineColor=[[0,0,0,1],[0,0,0,1]],this.borderColor=[0,0,0,0],this.backgroundColor=[0,0,0,0],this.static=this.scene.staticPlot}var o=a.prototype,s=["xaxis","yaxis"];o.merge=function(t){var e,r,n,a,o,l,c,u,f,h,p;for(this.titleEnable=!1,this.backgroundColor=i(t.plot_bgcolor),h=0;h<2;++h){var d=(e=s[h]).charAt(0);for(n=(r=t[this.scene[e]._name]).title.text===this.scene.fullLayout._dfltTitle[d]?"":r.title.text,p=0;p<=2;p+=2)this.labelEnable[h+p]=!1,this.labels[h+p]=n,this.labelColor[h+p]=i(r.title.font.color),this.labelFont[h+p]=r.title.font.family,this.labelSize[h+p]=r.title.font.size,this.labelPad[h+p]=this.getLabelPad(e,r),this.tickEnable[h+p]=!1,this.tickColor[h+p]=i((r.tickfont||{}).color),this.tickAngle[h+p]="auto"===r.tickangle?0:Math.PI*-r.tickangle/180,this.tickPad[h+p]=this.getTickPad(r),this.tickMarkLength[h+p]=0,this.tickMarkWidth[h+p]=r.tickwidth||0,this.tickMarkColor[h+p]=i(r.tickcolor),this.borderLineEnable[h+p]=!1,this.borderLineColor[h+p]=i(r.linecolor),this.borderLineWidth[h+p]=r.linewidth||0;c=this.hasSharedAxis(r),o=this.hasAxisInDfltPos(e,r)&&!c,l=this.hasAxisInAltrPos(e,r)&&!c,a=r.mirror||!1,u=c?-1!==String(a).indexOf("all"):!!a,f=c?"allticks"===a:-1!==String(a).indexOf("ticks"),o?this.labelEnable[h]=!0:l&&(this.labelEnable[h+2]=!0),o?this.tickEnable[h]=r.showticklabels:l&&(this.tickEnable[h+2]=r.showticklabels),(o||u)&&(this.borderLineEnable[h]=r.showline),(l||u)&&(this.borderLineEnable[h+2]=r.showline),(o||f)&&(this.tickMarkLength[h]=this.getTickMarkLength(r)),(l||f)&&(this.tickMarkLength[h+2]=this.getTickMarkLength(r)),this.gridLineEnable[h]=r.showgrid,this.gridLineColor[h]=i(r.gridcolor),this.gridLineWidth[h]=r.gridwidth,this.zeroLineEnable[h]=r.zeroline,this.zeroLineColor[h]=i(r.zerolinecolor),this.zeroLineWidth[h]=r.zerolinewidth}},o.hasSharedAxis=function(t){var e=this.scene,r=e.fullLayout._subplots.gl2d;return 0!==n.findSubplotsWithAxis(r,t).indexOf(e.id)},o.hasAxisInDfltPos=function(t,e){var r=e.side;return"xaxis"===t?"bottom"===r:"yaxis"===t?"left"===r:void 0},o.hasAxisInAltrPos=function(t,e){var r=e.side;return"xaxis"===t?"top"===r:"yaxis"===t?"right"===r:void 0},o.getLabelPad=function(t,e){var r=e.title.font.size,n=e.showticklabels;return"xaxis"===t?"top"===e.side?r*(1.5+(n?1:0))-10:r*(1.5+(n?.5:0))-10:"yaxis"===t?"right"===e.side?10+r*(1.5+(n?1:.5)):10+r*(1.5+(n?.5:0)):void 0},o.getTickPad=function(t){return"outside"===t.ticks?10+t.ticklen:15},o.getTickMarkLength=function(t){if(!t.ticks)return 0;var e=t.ticklen;return"inside"===t.ticks?-e:e},e.exports=function(t){return new a(t)}},{"../../lib/str2rgbarray":528,"../cartesian/axes":554}],596:[function(t,e,r){"use strict";var n=t("../../plot_api/edit_types").overrideAll,i=t("./scene2d"),a=t("../layout_attributes"),o=t("../../constants/xmlns_namespaces"),s=t("../cartesian/constants"),l=t("../cartesian"),c=t("../../components/fx/layout_attributes"),u=t("../get_data").getSubplotData;r.name="gl2d",r.attr=["xaxis","yaxis"],r.idRoot=["x","y"],r.idRegex=s.idRegex,r.attrRegex=s.attrRegex,r.attributes=t("../cartesian/attributes"),r.supplyLayoutDefaults=function(t,e,r){e._has("cartesian")||l.supplyLayoutDefaults(t,e,r)},r.layoutAttrOverrides=n(l.layoutAttributes,"plot","from-root"),r.baseLayoutAttrOverrides=n({plot_bgcolor:a.plot_bgcolor,hoverlabel:c.hoverlabel},"plot","nested"),r.plot=function(t){for(var e=t._fullLayout,r=t._fullData,n=e._subplots.gl2d,a=0;a<n.length;a++){var o=n[a],s=e._plots[o],l=u(r,"gl2d",o),c=s._scene2d;void 0===c&&(c=new i({id:o,graphDiv:t,container:t.querySelector(".gl-container"),staticPlot:t._context.staticPlot,plotGlPixelRatio:t._context.plotGlPixelRatio},e),s._scene2d=c),c.plot(l,t.calcdata,e,t.layout)}},r.clean=function(t,e,r,n){for(var i=n._subplots.gl2d||[],a=0;a<i.length;a++){var o=i[a],s=n._plots[o];if(s._scene2d){var c=u(t,"gl2d",o);0===c.length&&(s._scene2d.destroy(),delete n._plots[o])}}l.clean.apply(this,arguments)},r.drawFramework=function(t){t._context.staticPlot||l.drawFramework(t)},r.toSVG=function(t){for(var e=t._fullLayout,r=e._subplots.gl2d,n=0;n<r.length;n++){var i=e._plots[r[n]]._scene2d,a=i.toImage("png");e._glimages.append("svg:image").attr({xmlns:o.svg,"xlink:href":a,x:0,y:0,width:"100%",height:"100%",preserveAspectRatio:"none"}),i.destroy()}},r.updateFx=function(t){for(var e=t._fullLayout,r=e._subplots.gl2d,n=0;n<r.length;n++){e._plots[r[n]]._scene2d.updateFx(e.dragmode)}}},{"../../components/fx/layout_attributes":407,"../../constants/xmlns_namespaces":480,"../../plot_api/edit_types":536,"../cartesian":568,"../cartesian/attributes":552,"../cartesian/constants":561,"../get_data":593,"../layout_attributes":610,"./scene2d":597}],597:[function(t,e,r){"use strict";var n,i,a=t("../../registry"),o=t("../../plots/cartesian/axes"),s=t("../../components/fx"),l=t("../../../stackgl_modules").gl_plot2d,c=t("../../../stackgl_modules").gl_spikes2d,u=t("../../../stackgl_modules").gl_select_box,f=t("webgl-context"),h=t("./convert"),p=t("./camera"),d=t("../../lib/show_no_webgl_msg"),m=t("../cartesian/constraints"),g=m.enforce,v=m.clean,y=t("../cartesian/autorange").doAutoRange,x=t("../../components/dragelement/helpers"),b=x.drawMode,_=x.selectMode,w=["xaxis","yaxis"],T=t("../cartesian/constants").SUBPLOT_PATTERN;function k(t,e){this.container=t.container,this.graphDiv=t.graphDiv,this.pixelRatio=t.plotGlPixelRatio||window.devicePixelRatio,this.id=t.id,this.staticPlot=!!t.staticPlot,this.scrollZoom=this.graphDiv._context._scrollZoom.cartesian,this.fullData=null,this.updateRefs(e),this.makeFramework(),this.stopped||(this.glplotOptions=h(this),this.glplotOptions.merge(e),this.glplot=l(this.glplotOptions),this.camera=p(this),this.traces={},this.spikes=c(this.glplot),this.selectBox=u(this.glplot,{innerFill:!1,outerFill:!0}),this.lastButtonState=0,this.pickResult=null,this.isMouseOver=!0,this.stopped=!1,this.redraw=this.draw.bind(this),this.redraw())}e.exports=k;var A=k.prototype;A.makeFramework=function(){if(this.staticPlot){if(!(i||(n=document.createElement("canvas"),i=f({canvas:n,preserveDrawingBuffer:!1,premultipliedAlpha:!0,antialias:!0}))))throw new Error("Error creating static canvas/context for image server");this.canvas=n,this.gl=i}else{var t=this.container.querySelector(".gl-canvas-focus"),e=f({canvas:t,preserveDrawingBuffer:!0,premultipliedAlpha:!0});if(!e)return d(this),void(this.stopped=!0);this.canvas=t,this.gl=e}var r=this.canvas;r.style.width="100%",r.style.height="100%",r.style.position="absolute",r.style.top="0px",r.style.left="0px",r.style["pointer-events"]="none",this.updateSize(r);var a=this.svgContainer=document.createElementNS("http://www.w3.org/2000/svg","svg");a.style.position="absolute",a.style.top=a.style.left="0px",a.style.width=a.style.height="100%",a.style["z-index"]=20,a.style["pointer-events"]="none";var o=this.mouseContainer=document.createElement("div");o.style.position="absolute",o.style["pointer-events"]="auto",this.pickCanvas=this.container.querySelector(".gl-canvas-pick");var s=this.container;s.appendChild(a),s.appendChild(o);var l=this;o.addEventListener("mouseout",(function(){l.isMouseOver=!1,l.unhover()})),o.addEventListener("mouseover",(function(){l.isMouseOver=!0}))},A.toImage=function(t){t||(t="png"),this.stopped=!0,this.staticPlot&&this.container.appendChild(n),this.updateSize(this.canvas);var e=this.glplot.gl,r=e.drawingBufferWidth,i=e.drawingBufferHeight;e.clearColor(1,1,1,0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT),this.glplot.setDirty(),this.glplot.draw(),e.bindFramebuffer(e.FRAMEBUFFER,null);var a=new Uint8Array(r*i*4);e.readPixels(0,0,r,i,e.RGBA,e.UNSIGNED_BYTE,a);for(var o=0,s=i-1;o<s;++o,--s)for(var l=0;l<r;++l)for(var c=0;c<4;++c){var u=a[4*(r*o+l)+c];a[4*(r*o+l)+c]=a[4*(r*s+l)+c],a[4*(r*s+l)+c]=u}var f=document.createElement("canvas");f.width=r,f.height=i;var h,p=f.getContext("2d",{willReadFrequently:!0}),d=p.createImageData(r,i);switch(d.data.set(a),p.putImageData(d,0,0),t){case"jpeg":h=f.toDataURL("image/jpeg");break;case"webp":h=f.toDataURL("image/webp");break;default:h=f.toDataURL("image/png")}return this.staticPlot&&this.container.removeChild(n),h},A.updateSize=function(t){t||(t=this.canvas);var e=this.pixelRatio,r=this.fullLayout,n=r.width,i=r.height,a=0|Math.ceil(e*n),o=0|Math.ceil(e*i);return t.width===a&&t.height===o||(t.width=a,t.height=o),t},A.computeTickMarks=function(){this.xaxis.setScale(),this.yaxis.setScale();for(var t=[o.calcTicks(this.xaxis),o.calcTicks(this.yaxis)],e=0;e<2;++e)for(var r=0;r<t[e].length;++r)t[e][r].text=t[e][r].text+"";return t},A.updateRefs=function(t){this.fullLayout=t;var e=this.id.match(T),r="xaxis"+e[1],n="yaxis"+e[2];this.xaxis=this.fullLayout[r],this.yaxis=this.fullLayout[n]},A.relayoutCallback=function(){var t=this.graphDiv,e=this.xaxis,r=this.yaxis,n=t.layout,i={},o=i[e._name+".range"]=e.range.slice(),s=i[r._name+".range"]=r.range.slice();i[e._name+".autorange"]=e.autorange,i[r._name+".autorange"]=r.autorange,a.call("_storeDirectGUIEdit",t.layout,t._fullLayout._preGUI,i);var l=n[e._name];l.range=o,l.autorange=e.autorange;var c=n[r._name];c.range=s,c.autorange=r.autorange,i.lastInputTime=this.camera.lastInputTime,t.emit("plotly_relayout",i)},A.cameraChanged=function(){var t=this.camera;this.glplot.setDataBox(this.calcDataBox());var e=this.computeTickMarks();(function(t,e){for(var r=0;r<2;++r){var n=t[r],i=e[r];if(n.length!==i.length)return!0;for(var a=0;a<n.length;++a)if(n[a].x!==i[a].x)return!0}return!1})(e,this.glplotOptions.ticks)&&(this.glplotOptions.ticks=e,this.glplotOptions.dataBox=t.dataBox,this.glplot.update(this.glplotOptions),this.handleAnnotations())},A.handleAnnotations=function(){for(var t=this.graphDiv,e=this.fullLayout.annotations,r=0;r<e.length;r++){var n=e[r];n.xref===this.xaxis._id&&n.yref===this.yaxis._id&&a.getComponentMethod("annotations","drawOne")(t,r)}},A.destroy=function(){if(this.glplot){var t=this.traces;t&&Object.keys(t).map((function(e){t[e].dispose(),delete t[e]})),this.glplot.dispose(),this.container.removeChild(this.svgContainer),this.container.removeChild(this.mouseContainer),this.fullData=null,this.glplot=null,this.stopped=!0,this.camera.mouseListener.enabled=!1,this.mouseContainer.removeEventListener("wheel",this.camera.wheelListener),this.camera=null}},A.plot=function(t,e,r){var n=this.glplot;this.updateRefs(r),this.xaxis.clearCalc(),this.yaxis.clearCalc(),this.updateTraces(t,e),this.updateFx(r.dragmode);var i=r.width,a=r.height;this.updateSize(this.canvas);var o=this.glplotOptions;o.merge(r),o.screenBox=[0,0,i,a];var s={_fullLayout:{_axisConstraintGroups:r._axisConstraintGroups,xaxis:this.xaxis,yaxis:this.yaxis,_size:r._size}};v(s,this.xaxis),v(s,this.yaxis);var l,c,u=r._size,f=this.xaxis.domain,h=this.yaxis.domain;for(o.viewBox=[u.l+f[0]*u.w,u.b+h[0]*u.h,i-u.r-(1-f[1])*u.w,a-u.t-(1-h[1])*u.h],this.mouseContainer.style.width=u.w*(f[1]-f[0])+"px",this.mouseContainer.style.height=u.h*(h[1]-h[0])+"px",this.mouseContainer.height=u.h*(h[1]-h[0]),this.mouseContainer.style.left=u.l+f[0]*u.w+"px",this.mouseContainer.style.top=u.t+(1-h[1])*u.h+"px",c=0;c<2;++c)(l=this[w[c]])._length=o.viewBox[c+2]-o.viewBox[c],y(this.graphDiv,l),l.setScale();g(s),o.ticks=this.computeTickMarks(),o.dataBox=this.calcDataBox(),o.merge(r),n.update(o),this.glplot.draw()},A.calcDataBox=function(){var t=this.xaxis,e=this.yaxis,r=t.range,n=e.range,i=t.r2l,a=e.r2l;return[i(r[0]),a(n[0]),i(r[1]),a(n[1])]},A.setRanges=function(t){var e=this.xaxis,r=this.yaxis,n=e.l2r,i=r.l2r;e.range=[n(t[0]),n(t[2])],r.range=[i(t[1]),i(t[3])]},A.updateTraces=function(t,e){var r,n,i,a=Object.keys(this.traces);this.fullData=t;t:for(r=0;r<a.length;r++){var o=a[r],s=this.traces[o];for(n=0;n<t.length;n++)if((i=t[n]).uid===o&&i.type===s.type)continue t;s.dispose(),delete this.traces[o]}for(r=0;r<t.length;r++){i=t[r];var l=e[r],c=this.traces[i.uid];c?c.update(i,l):(c=i._module.plot(this,i,l),this.traces[i.uid]=c)}this.glplot.objects.sort((function(t,e){return t._trace.index-e._trace.index}))},A.updateFx=function(t){_(t)||b(t)?(this.pickCanvas.style["pointer-events"]="none",this.mouseContainer.style["pointer-events"]="none"):(this.pickCanvas.style["pointer-events"]="auto",this.mouseContainer.style["pointer-events"]="auto"),this.mouseContainer.style.cursor="pan"===t?"move":"zoom"===t?"crosshair":null},A.emitPointAction=function(t,e){for(var r,n=t.trace.uid,i=t.pointIndex,a=0;a<this.fullData.length;a++)this.fullData[a].uid===n&&(r=this.fullData[a]);var o={x:t.traceCoord[0],y:t.traceCoord[1],curveNumber:r.index,pointNumber:i,data:r._input,fullData:this.fullData,xaxis:this.xaxis,yaxis:this.yaxis};s.appendArrayPointValue(o,r,i),this.graphDiv.emit(e,{points:[o]})},A.draw=function(){if(!this.stopped){requestAnimationFrame(this.redraw);var t=this.glplot,e=this.camera,r=e.mouseListener,n=1===this.lastButtonState&&0===r.buttons,i=this.fullLayout;this.lastButtonState=r.buttons,this.cameraChanged();var a,o=r.x*t.pixelRatio,l=this.canvas.height-t.pixelRatio*r.y;if(e.boxEnabled&&"zoom"===i.dragmode){this.selectBox.enabled=!0;for(var c=this.selectBox.selectBox=[Math.min(e.boxStart[0],e.boxEnd[0]),Math.min(e.boxStart[1],e.boxEnd[1]),Math.max(e.boxStart[0],e.boxEnd[0]),Math.max(e.boxStart[1],e.boxEnd[1])],u=0;u<2;u++)e.boxStart[u]===e.boxEnd[u]&&(c[u]=t.dataBox[u],c[u+2]=t.dataBox[u+2]);t.setDirty()}else if(!e.panning&&this.isMouseOver){this.selectBox.enabled=!1;var f=i._size,h=this.xaxis.domain,p=this.yaxis.domain,d=(a=t.pick(o/t.pixelRatio+f.l+h[0]*f.w,l/t.pixelRatio-(f.t+(1-p[1])*f.h)))&&a.object._trace.handlePick(a);if(d&&n&&this.emitPointAction(d,"plotly_click"),a&&"skip"!==a.object._trace.hoverinfo&&i.hovermode&&d&&(!this.lastPickResult||this.lastPickResult.traceUid!==d.trace.uid||this.lastPickResult.dataCoord[0]!==d.dataCoord[0]||this.lastPickResult.dataCoord[1]!==d.dataCoord[1])){var m=d;this.lastPickResult={traceUid:d.trace?d.trace.uid:null,dataCoord:d.dataCoord.slice()},this.spikes.update({center:a.dataCoord}),m.screenCoord=[((t.viewBox[2]-t.viewBox[0])*(a.dataCoord[0]-t.dataBox[0])/(t.dataBox[2]-t.dataBox[0])+t.viewBox[0])/t.pixelRatio,(this.canvas.height-(t.viewBox[3]-t.viewBox[1])*(a.dataCoord[1]-t.dataBox[1])/(t.dataBox[3]-t.dataBox[1])-t.viewBox[1])/t.pixelRatio],this.emitPointAction(d,"plotly_hover");var g=this.fullData[m.trace.index]||{},v=m.pointIndex,y=s.castHoverinfo(g,i,v);if(y&&"all"!==y){var x=y.split("+");-1===x.indexOf("x")&&(m.traceCoord[0]=void 0),-1===x.indexOf("y")&&(m.traceCoord[1]=void 0),-1===x.indexOf("z")&&(m.traceCoord[2]=void 0),-1===x.indexOf("text")&&(m.textLabel=void 0),-1===x.indexOf("name")&&(m.name=void 0)}s.loneHover({x:m.screenCoord[0],y:m.screenCoord[1],xLabel:this.hoverFormatter("xaxis",m.traceCoord[0]),yLabel:this.hoverFormatter("yaxis",m.traceCoord[1]),zLabel:m.traceCoord[2],text:m.textLabel,name:m.name,color:s.castHoverOption(g,v,"bgcolor")||m.color,borderColor:s.castHoverOption(g,v,"bordercolor"),fontFamily:s.castHoverOption(g,v,"font.family"),fontSize:s.castHoverOption(g,v,"font.size"),fontColor:s.castHoverOption(g,v,"font.color"),nameLength:s.castHoverOption(g,v,"namelength"),textAlign:s.castHoverOption(g,v,"align")},{container:this.svgContainer,gd:this.graphDiv})}}a||this.unhover(),t.draw()}},A.unhover=function(){this.lastPickResult&&(this.spikes.update({}),this.lastPickResult=null,this.graphDiv.emit("plotly_unhover"),s.loneUnhover(this.svgContainer))},A.hoverFormatter=function(t,e){if(void 0!==e){var r=this[t];return o.tickText(r,r.c2l(e),"hover").text}}},{"../../../stackgl_modules":1124,"../../components/dragelement/helpers":384,"../../components/fx":406,"../../lib/show_no_webgl_msg":525,"../../plots/cartesian/axes":554,"../../registry":638,"../cartesian/autorange":553,"../cartesian/constants":561,"../cartesian/constraints":562,"./camera":594,"./convert":595,"webgl-context":331}],598:[function(t,e,r){"use strict";var n=t("../../plot_api/edit_types").overrideAll,i=t("../../components/fx/layout_attributes"),a=t("./scene"),o=t("../get_data").getSubplotData,s=t("../../lib"),l=t("../../constants/xmlns_namespaces");r.name="gl3d",r.attr="scene",r.idRoot="scene",r.idRegex=r.attrRegex=s.counterRegex("scene"),r.attributes=t("./layout/attributes"),r.layoutAttributes=t("./layout/layout_attributes"),r.baseLayoutAttrOverrides=n({hoverlabel:i.hoverlabel},"plot","nested"),r.supplyLayoutDefaults=t("./layout/defaults"),r.plot=function(t){for(var e=t._fullLayout,r=t._fullData,n=e._subplots.gl3d,i=0;i<n.length;i++){var s=n[i],l=o(r,"gl3d",s),c=e[s],u=c.camera,f=c._scene;f||(f=new a({id:s,graphDiv:t,container:t.querySelector(".gl-container"),staticPlot:t._context.staticPlot,plotGlPixelRatio:t._context.plotGlPixelRatio,camera:u},e),c._scene=f),f.viewInitial||(f.viewInitial={up:{x:u.up.x,y:u.up.y,z:u.up.z},eye:{x:u.eye.x,y:u.eye.y,z:u.eye.z},center:{x:u.center.x,y:u.center.y,z:u.center.z}}),f.plot(l,e,t.layout)}},r.clean=function(t,e,r,n){for(var i=n._subplots.gl3d||[],a=0;a<i.length;a++){var o=i[a];!e[o]&&n[o]._scene&&(n[o]._scene.destroy(),n._infolayer&&n._infolayer.selectAll(".annotation-"+o).remove())}},r.toSVG=function(t){for(var e=t._fullLayout,r=e._subplots.gl3d,n=e._size,i=0;i<r.length;i++){var a=e[r[i]],o=a.domain,s=a._scene,c=s.toImage("png");e._glimages.append("svg:image").attr({xmlns:l.svg,"xlink:href":c,x:n.l+n.w*o.x[0],y:n.t+n.h*(1-o.y[1]),width:n.w*(o.x[1]-o.x[0]),height:n.h*(o.y[1]-o.y[0]),preserveAspectRatio:"none"}),s.destroy()}},r.cleanId=function(t){if(t.match(/^scene[0-9]*$/)){var e=t.substr(5);return"1"===e&&(e=""),"scene"+e}},r.updateFx=function(t){for(var e=t._fullLayout,r=e._subplots.gl3d,n=0;n<r.length;n++){e[r[n]]._scene.updateFx(e.dragmode,e.hovermode)}}},{"../../components/fx/layout_attributes":407,"../../constants/xmlns_namespaces":480,"../../lib":503,"../../plot_api/edit_types":536,"../get_data":593,"./layout/attributes":599,"./layout/defaults":603,"./layout/layout_attributes":604,"./scene":608}],599:[function(t,e,r){"use strict";e.exports={scene:{valType:"subplotid",dflt:"scene",editType:"calc+clearAxisTypes"}}},{}],600:[function(t,e,r){"use strict";var n=t("../../../components/color"),i=t("../../cartesian/layout_attributes"),a=t("../../../lib/extend").extendFlat,o=t("../../../plot_api/edit_types").overrideAll;e.exports=o({visible:i.visible,showspikes:{valType:"boolean",dflt:!0},spikesides:{valType:"boolean",dflt:!0},spikethickness:{valType:"number",min:0,dflt:2},spikecolor:{valType:"color",dflt:n.defaultLine},showbackground:{valType:"boolean",dflt:!1},backgroundcolor:{valType:"color",dflt:"rgba(204, 204, 204, 0.5)"},showaxeslabels:{valType:"boolean",dflt:!0},color:i.color,categoryorder:i.categoryorder,categoryarray:i.categoryarray,title:{text:i.title.text,font:i.title.font},type:a({},i.type,{values:["-","linear","log","date","category"]}),autotypenumbers:i.autotypenumbers,autorange:i.autorange,rangemode:i.rangemode,range:a({},i.range,{items:[{valType:"any",editType:"plot",impliedEdits:{"^autorange":!1}},{valType:"any",editType:"plot",impliedEdits:{"^autorange":!1}}],anim:!1}),tickmode:i.tickmode,nticks:i.nticks,tick0:i.tick0,dtick:i.dtick,tickvals:i.tickvals,ticktext:i.ticktext,ticks:i.ticks,mirror:i.mirror,ticklen:i.ticklen,tickwidth:i.tickwidth,tickcolor:i.tickcolor,showticklabels:i.showticklabels,tickfont:i.tickfont,tickangle:i.tickangle,tickprefix:i.tickprefix,showtickprefix:i.showtickprefix,ticksuffix:i.ticksuffix,showticksuffix:i.showticksuffix,showexponent:i.showexponent,exponentformat:i.exponentformat,minexponent:i.minexponent,separatethousands:i.separatethousands,tickformat:i.tickformat,tickformatstops:i.tickformatstops,hoverformat:i.hoverformat,showline:i.showline,linecolor:i.linecolor,linewidth:i.linewidth,showgrid:i.showgrid,gridcolor:a({},i.gridcolor,{dflt:"rgb(204, 204, 204)"}),gridwidth:i.gridwidth,zeroline:i.zeroline,zerolinecolor:i.zerolinecolor,zerolinewidth:i.zerolinewidth,_deprecated:{title:i._deprecated.title,titlefont:i._deprecated.titlefont}},"plot","from-root")},{"../../../components/color":366,"../../../lib/extend":493,"../../../plot_api/edit_types":536,"../../cartesian/layout_attributes":569}],601:[function(t,e,r){"use strict";var n=t("tinycolor2").mix,i=t("../../../lib"),a=t("../../../plot_api/plot_template"),o=t("./axis_attributes"),s=t("../../cartesian/type_defaults"),l=t("../../cartesian/axis_defaults"),c=["xaxis","yaxis","zaxis"];e.exports=function(t,e,r){var u,f;function h(t,e){return i.coerce(u,f,o,t,e)}for(var p=0;p<c.length;p++){var d=c[p];u=t[d]||{},(f=a.newContainer(e,d))._id=d[0]+r.scene,f._name=d,s(u,f,h,r),l(u,f,h,{font:r.font,letter:d[0],data:r.data,showGrid:!0,noTickson:!0,noTicklabelmode:!0,noTicklabelstep:!0,noTicklabelposition:!0,noTicklabeloverflow:!0,bgColor:r.bgColor,calendar:r.calendar},r.fullLayout),h("gridcolor",n(f.color,r.bgColor,13600/187).toRgbString()),h("title.text",d[0]),f.setScale=i.noop,h("showspikes")&&(h("spikesides"),h("spikethickness"),h("spikecolor",f.color)),h("showaxeslabels"),h("showbackground")&&h("backgroundcolor")}}},{"../../../lib":503,"../../../plot_api/plot_template":543,"../../cartesian/axis_defaults":556,"../../cartesian/type_defaults":582,"./axis_attributes":600,tinycolor2:312}],602:[function(t,e,r){"use strict";var n=t("../../../lib/str2rgbarray"),i=t("../../../lib"),a=["xaxis","yaxis","zaxis"];function o(){this.bounds=[[-10,-10,-10],[10,10,10]],this.ticks=[[],[],[]],this.tickEnable=[!0,!0,!0],this.tickFont=["sans-serif","sans-serif","sans-serif"],this.tickSize=[12,12,12],this.tickAngle=[0,0,0],this.tickColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.tickPad=[18,18,18],this.labels=["x","y","z"],this.labelEnable=[!0,!0,!0],this.labelFont=["Open Sans","Open Sans","Open Sans"],this.labelSize=[20,20,20],this.labelColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.labelPad=[30,30,30],this.lineEnable=[!0,!0,!0],this.lineMirror=[!1,!1,!1],this.lineWidth=[1,1,1],this.lineColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.lineTickEnable=[!0,!0,!0],this.lineTickMirror=[!1,!1,!1],this.lineTickLength=[10,10,10],this.lineTickWidth=[1,1,1],this.lineTickColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.gridEnable=[!0,!0,!0],this.gridWidth=[1,1,1],this.gridColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.zeroEnable=[!0,!0,!0],this.zeroLineColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.zeroLineWidth=[2,2,2],this.backgroundEnable=[!0,!0,!0],this.backgroundColor=[[.8,.8,.8,.5],[.8,.8,.8,.5],[.8,.8,.8,.5]],this._defaultTickPad=this.tickPad.slice(),this._defaultLabelPad=this.labelPad.slice(),this._defaultLineTickLength=this.lineTickLength.slice()}o.prototype.merge=function(t,e){for(var r=0;r<3;++r){var o=e[a[r]];o.visible?(this.labels[r]=t._meta?i.templateString(o.title.text,t._meta):o.title.text,"font"in o.title&&(o.title.font.color&&(this.labelColor[r]=n(o.title.font.color)),o.title.font.family&&(this.labelFont[r]=o.title.font.family),o.title.font.size&&(this.labelSize[r]=o.title.font.size)),"showline"in o&&(this.lineEnable[r]=o.showline),"linecolor"in o&&(this.lineColor[r]=n(o.linecolor)),"linewidth"in o&&(this.lineWidth[r]=o.linewidth),"showgrid"in o&&(this.gridEnable[r]=o.showgrid),"gridcolor"in o&&(this.gridColor[r]=n(o.gridcolor)),"gridwidth"in o&&(this.gridWidth[r]=o.gridwidth),"log"===o.type?this.zeroEnable[r]=!1:"zeroline"in o&&(this.zeroEnable[r]=o.zeroline),"zerolinecolor"in o&&(this.zeroLineColor[r]=n(o.zerolinecolor)),"zerolinewidth"in o&&(this.zeroLineWidth[r]=o.zerolinewidth),"ticks"in o&&o.ticks?this.lineTickEnable[r]=!0:this.lineTickEnable[r]=!1,"ticklen"in o&&(this.lineTickLength[r]=this._defaultLineTickLength[r]=o.ticklen),"tickcolor"in o&&(this.lineTickColor[r]=n(o.tickcolor)),"tickwidth"in o&&(this.lineTickWidth[r]=o.tickwidth),"tickangle"in o&&(this.tickAngle[r]="auto"===o.tickangle?-3600:Math.PI*-o.tickangle/180),"showticklabels"in o&&(this.tickEnable[r]=o.showticklabels),"tickfont"in o&&(o.tickfont.color&&(this.tickColor[r]=n(o.tickfont.color)),o.tickfont.family&&(this.tickFont[r]=o.tickfont.family),o.tickfont.size&&(this.tickSize[r]=o.tickfont.size)),"mirror"in o?-1!==["ticks","all","allticks"].indexOf(o.mirror)?(this.lineTickMirror[r]=!0,this.lineMirror[r]=!0):!0===o.mirror?(this.lineTickMirror[r]=!1,this.lineMirror[r]=!0):(this.lineTickMirror[r]=!1,this.lineMirror[r]=!1):this.lineMirror[r]=!1,"showbackground"in o&&!1!==o.showbackground?(this.backgroundEnable[r]=!0,this.backgroundColor[r]=n(o.backgroundcolor)):this.backgroundEnable[r]=!1):(this.tickEnable[r]=!1,this.labelEnable[r]=!1,this.lineEnable[r]=!1,this.lineTickEnable[r]=!1,this.gridEnable[r]=!1,this.zeroEnable[r]=!1,this.backgroundEnable[r]=!1)}},e.exports=function(t,e){var r=new o;return r.merge(t,e),r}},{"../../../lib":503,"../../../lib/str2rgbarray":528}],603:[function(t,e,r){"use strict";var n=t("../../../lib"),i=t("../../../components/color"),a=t("../../../registry"),o=t("../../subplot_defaults"),s=t("./axis_defaults"),l=t("./layout_attributes"),c=t("../../get_data").getSubplotData;function u(t,e,r,n){for(var o=r("bgcolor"),l=i.combine(o,n.paper_bgcolor),u=["up","center","eye"],f=0;f<u.length;f++)r("camera."+u[f]+".x"),r("camera."+u[f]+".y"),r("camera."+u[f]+".z");r("camera.projection.type");var h=!!r("aspectratio.x")&&!!r("aspectratio.y")&&!!r("aspectratio.z"),p=r("aspectmode",h?"manual":"auto");h||(t.aspectratio=e.aspectratio={x:1,y:1,z:1},"manual"===p&&(e.aspectmode="auto"),t.aspectmode=e.aspectmode);var d=c(n.fullData,"gl3d",n.id);s(t,e,{font:n.font,scene:n.id,data:d,bgColor:l,calendar:n.calendar,autotypenumbersDflt:n.autotypenumbersDflt,fullLayout:n.fullLayout}),a.getComponentMethod("annotations3d","handleDefaults")(t,e,n);var m=n.getDfltFromLayout("dragmode");if(!1!==m&&!m)if(m="orbit",t.camera&&t.camera.up){var g=t.camera.up.x,v=t.camera.up.y,y=t.camera.up.z;0!==y&&(g&&v&&y?y/Math.sqrt(g*g+v*v+y*y)>.999&&(m="turntable"):m="turntable")}else m="turntable";r("dragmode",m),r("hovermode",n.getDfltFromLayout("hovermode"))}e.exports=function(t,e,r){var i=e._basePlotModules.length>1;o(t,e,r,{type:"gl3d",attributes:l,handleDefaults:u,fullLayout:e,font:e.font,fullData:r,getDfltFromLayout:function(e){if(!i)return n.validate(t[e],l[e])?t[e]:void 0},autotypenumbersDflt:e.autotypenumbers,paper_bgcolor:e.paper_bgcolor,calendar:e.calendar})}},{"../../../components/color":366,"../../../lib":503,"../../../registry":638,"../../get_data":593,"../../subplot_defaults":632,"./axis_defaults":601,"./layout_attributes":604}],604:[function(t,e,r){"use strict";var n=t("./axis_attributes"),i=t("../../domain").attributes,a=t("../../../lib/extend").extendFlat,o=t("../../../lib").counterRegex;function s(t,e,r){return{x:{valType:"number",dflt:t,editType:"camera"},y:{valType:"number",dflt:e,editType:"camera"},z:{valType:"number",dflt:r,editType:"camera"},editType:"camera"}}e.exports={_arrayAttrRegexps:[o("scene",".annotations",!0)],bgcolor:{valType:"color",dflt:"rgba(0,0,0,0)",editType:"plot"},camera:{up:a(s(0,0,1),{}),center:a(s(0,0,0),{}),eye:a(s(1.25,1.25,1.25),{}),projection:{type:{valType:"enumerated",values:["perspective","orthographic"],dflt:"perspective",editType:"calc"},editType:"calc"},editType:"camera"},domain:i({name:"scene",editType:"plot"}),aspectmode:{valType:"enumerated",values:["auto","cube","data","manual"],dflt:"auto",editType:"plot",impliedEdits:{"aspectratio.x":void 0,"aspectratio.y":void 0,"aspectratio.z":void 0}},aspectratio:{x:{valType:"number",min:0,editType:"plot",impliedEdits:{"^aspectmode":"manual"}},y:{valType:"number",min:0,editType:"plot",impliedEdits:{"^aspectmode":"manual"}},z:{valType:"number",min:0,editType:"plot",impliedEdits:{"^aspectmode":"manual"}},editType:"plot",impliedEdits:{aspectmode:"manual"}},xaxis:n,yaxis:n,zaxis:n,dragmode:{valType:"enumerated",values:["orbit","turntable","zoom","pan",!1],editType:"plot"},hovermode:{valType:"enumerated",values:["closest",!1],dflt:"closest",editType:"modebar"},uirevision:{valType:"any",editType:"none"},editType:"plot",_deprecated:{cameraposition:{valType:"info_array",editType:"camera"}}}},{"../../../lib":503,"../../../lib/extend":493,"../../domain":584,"./axis_attributes":600}],605:[function(t,e,r){"use strict";var n=t("../../../lib/str2rgbarray"),i=["xaxis","yaxis","zaxis"];function a(){this.enabled=[!0,!0,!0],this.colors=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.drawSides=[!0,!0,!0],this.lineWidth=[1,1,1]}a.prototype.merge=function(t){for(var e=0;e<3;++e){var r=t[i[e]];r.visible?(this.enabled[e]=r.showspikes,this.colors[e]=n(r.spikecolor),this.drawSides[e]=r.spikesides,this.lineWidth[e]=r.spikethickness):(this.enabled[e]=!1,this.drawSides[e]=!1)}},e.exports=function(t){var e=new a;return e.merge(t),e}},{"../../../lib/str2rgbarray":528}],606:[function(t,e,r){"use strict";e.exports=function(t){for(var e=t.axesOptions,r=t.glplot.axesPixels,s=t.fullSceneLayout,l=[[],[],[]],c=0;c<3;++c){var u=s[a[c]];if(u._length=(r[c].hi-r[c].lo)*r[c].pixelsPerDataUnit/t.dataScale[c],Math.abs(u._length)===1/0||isNaN(u._length))l[c]=[];else{u._input_range=u.range.slice(),u.range[0]=r[c].lo/t.dataScale[c],u.range[1]=r[c].hi/t.dataScale[c],u._m=1/(t.dataScale[c]*r[c].pixelsPerDataUnit),u.range[0]===u.range[1]&&(u.range[0]-=1,u.range[1]+=1);var f=u.tickmode;if("auto"===u.tickmode){u.tickmode="linear";var h=u.nticks||i.constrain(u._length/40,4,9);n.autoTicks(u,Math.abs(u.range[1]-u.range[0])/h)}for(var p=n.calcTicks(u,{msUTC:!0}),d=0;d<p.length;++d)p[d].x=p[d].x*t.dataScale[c],"date"===u.type&&(p[d].text=p[d].text.replace(/\<br\>/g," "));l[c]=p,u.tickmode=f}}e.ticks=l;for(c=0;c<3;++c){o[c]=.5*(t.glplot.bounds[0][c]+t.glplot.bounds[1][c]);for(d=0;d<2;++d)e.bounds[d][c]=t.glplot.bounds[d][c]}t.contourLevels=function(t){for(var e=new Array(3),r=0;r<3;++r){for(var n=t[r],i=new Array(n.length),a=0;a<n.length;++a)i[a]=n[a].x;e[r]=i}return e}(l)};var n=t("../../cartesian/axes"),i=t("../../../lib"),a=["xaxis","yaxis","zaxis"],o=[0,0,0]},{"../../../lib":503,"../../cartesian/axes":554}],607:[function(t,e,r){"use strict";function n(t,e){var r,n,i=[0,0,0,0];for(r=0;r<4;++r)for(n=0;n<4;++n)i[n]+=t[4*r+n]*e[r];return i}e.exports=function(t,e){return n(t.projection,n(t.view,n(t.model,[e[0],e[1],e[2],1])))}},{}],608:[function(t,e,r){"use strict";var n,i,a=t("../../../stackgl_modules").gl_plot3d,o=a.createCamera,s=a.createScene,l=t("webgl-context"),c=t("has-passive-events"),u=t("../../registry"),f=t("../../lib"),h=f.preserveDrawingBuffer(),p=t("../../plots/cartesian/axes"),d=t("../../components/fx"),m=t("../../lib/str2rgbarray"),g=t("../../lib/show_no_webgl_msg"),v=t("./project"),y=t("./layout/convert"),x=t("./layout/spikes"),b=t("./layout/tick_marks");function _(t,e){var r=document.createElement("div"),n=t.container;this.graphDiv=t.graphDiv;var i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.style.position="absolute",i.style.top=i.style.left="0px",i.style.width=i.style.height="100%",i.style["z-index"]=20,i.style["pointer-events"]="none",r.appendChild(i),this.svgContainer=i,r.id=t.id,r.style.position="absolute",r.style.top=r.style.left="0px",r.style.width=r.style.height="100%",n.appendChild(r),this.fullLayout=e,this.id=t.id||"scene",this.fullSceneLayout=e[this.id],this.plotArgs=[[],{},{}],this.axesOptions=y(e,e[this.id]),this.spikeOptions=x(e[this.id]),this.container=r,this.staticMode=!!t.staticPlot,this.pixelRatio=this.pixelRatio||t.plotGlPixelRatio||2,this.dataScale=[1,1,1],this.contourLevels=[[],[],[]],this.convertAnnotations=u.getComponentMethod("annotations3d","convert"),this.drawAnnotations=u.getComponentMethod("annotations3d","draw"),this.initializeGLPlot()}var w=_.prototype;w.prepareOptions=function(){var t={canvas:this.canvas,gl:this.gl,glOptions:{preserveDrawingBuffer:h,premultipliedAlpha:!0,antialias:!0},container:this.container,axes:this.axesOptions,spikes:this.spikeOptions,pickRadius:10,snapToData:!0,autoScale:!0,autoBounds:!1,cameraObject:this.camera,pixelRatio:this.pixelRatio};if(this.staticMode){if(!(i||(n=document.createElement("canvas"),i=l({canvas:n,preserveDrawingBuffer:!0,premultipliedAlpha:!0,antialias:!0}))))throw new Error("error creating static canvas/context for image server");t.gl=i,t.canvas=n}return t};var T=!0;w.tryCreatePlot=function(){var t=this.prepareOptions(),e=!0;try{this.glplot=s(t)}catch(r){if(this.staticMode||!T||h)e=!1;else{f.warn(["webgl setup failed possibly due to","false preserveDrawingBuffer config.","The mobile/tablet device may not be detected by is-mobile module.","Enabling preserveDrawingBuffer in second attempt to create webgl scene..."].join(" "));try{h=t.glOptions.preserveDrawingBuffer=!0,this.glplot=s(t)}catch(r){h=t.glOptions.preserveDrawingBuffer=!1,e=!1}}}return T=!1,e},w.initializeGLCamera=function(){var t=this.fullSceneLayout.camera,e="orthographic"===t.projection.type;this.camera=o(this.container,{center:[t.center.x,t.center.y,t.center.z],eye:[t.eye.x,t.eye.y,t.eye.z],up:[t.up.x,t.up.y,t.up.z],_ortho:e,zoomMin:.01,zoomMax:100,mode:"orbit"})},w.initializeGLPlot=function(){var t=this;if(t.initializeGLCamera(),!t.tryCreatePlot())return g(t);t.traces={},t.make4thDimension();var e=t.graphDiv,r=e.layout,n=function(){var e={};return t.isCameraChanged(r)&&(e[t.id+".camera"]=t.getCamera()),t.isAspectChanged(r)&&(e[t.id+".aspectratio"]=t.glplot.getAspectratio(),"manual"!==r[t.id].aspectmode&&(t.fullSceneLayout.aspectmode=r[t.id].aspectmode=e[t.id+".aspectmode"]="manual")),e},i=function(t){if(!1!==t.fullSceneLayout.dragmode){var e=n();t.saveLayout(r),t.graphDiv.emit("plotly_relayout",e)}};return t.glplot.canvas&&(t.glplot.canvas.addEventListener("mouseup",(function(){i(t)})),t.glplot.canvas.addEventListener("wheel",(function(r){if(e._context._scrollZoom.gl3d){if(t.camera._ortho){var n=r.deltaX>r.deltaY?1.1:1/1.1,a=t.glplot.getAspectratio();t.glplot.setAspectratio({x:n*a.x,y:n*a.y,z:n*a.z})}i(t)}}),!!c&&{passive:!1}),t.glplot.canvas.addEventListener("mousemove",(function(){if(!1!==t.fullSceneLayout.dragmode&&0!==t.camera.mouseListener.buttons){var e=n();t.graphDiv.emit("plotly_relayouting",e)}})),t.staticMode||t.glplot.canvas.addEventListener("webglcontextlost",(function(r){e&&e.emit&&e.emit("plotly_webglcontextlost",{event:r,layer:t.id})}),!1)),t.glplot.oncontextloss=function(){t.recoverContext()},t.glplot.onrender=function(){t.render()},!0},w.render=function(){var t,e=this,r=e.graphDiv,n=e.svgContainer,i=e.container.getBoundingClientRect();r._fullLayout._calcInverseTransform(r);var a=r._fullLayout._invScaleX,o=r._fullLayout._invScaleY,s=i.width*a,l=i.height*o;n.setAttributeNS(null,"viewBox","0 0 "+s+" "+l),n.setAttributeNS(null,"width",s),n.setAttributeNS(null,"height",l),b(e),e.glplot.axes.update(e.axesOptions);for(var c=Object.keys(e.traces),u=null,h=e.glplot.selection,m=0;m<c.length;++m)"skip"!==(t=e.traces[c[m]]).data.hoverinfo&&t.handlePick(h)&&(u=t),t.setContourLevels&&t.setContourLevels();function g(t,r,n){var i=e.fullSceneLayout[t+"axis"];return"log"!==i.type&&(r=i.d2l(r)),p.hoverLabelText(i,r,n)}if(null!==u){var y=v(e.glplot.cameraParams,h.dataCoordinate);t=u.data;var x,_=r._fullData[t.index],w=h.index,T={xLabel:g("x",h.traceCoordinate[0],t.xhoverformat),yLabel:g("y",h.traceCoordinate[1],t.yhoverformat),zLabel:g("z",h.traceCoordinate[2],t.zhoverformat)},k=d.castHoverinfo(_,e.fullLayout,w),A=(k||"").split("+"),M=k&&"all"===k;_.hovertemplate||M||(-1===A.indexOf("x")&&(T.xLabel=void 0),-1===A.indexOf("y")&&(T.yLabel=void 0),-1===A.indexOf("z")&&(T.zLabel=void 0),-1===A.indexOf("text")&&(h.textLabel=void 0),-1===A.indexOf("name")&&(u.name=void 0));var S=[];"cone"===t.type||"streamtube"===t.type?(T.uLabel=g("x",h.traceCoordinate[3],t.uhoverformat),(M||-1!==A.indexOf("u"))&&S.push("u: "+T.uLabel),T.vLabel=g("y",h.traceCoordinate[4],t.vhoverformat),(M||-1!==A.indexOf("v"))&&S.push("v: "+T.vLabel),T.wLabel=g("z",h.traceCoordinate[5],t.whoverformat),(M||-1!==A.indexOf("w"))&&S.push("w: "+T.wLabel),T.normLabel=h.traceCoordinate[6].toPrecision(3),(M||-1!==A.indexOf("norm"))&&S.push("norm: "+T.normLabel),"streamtube"===t.type&&(T.divergenceLabel=h.traceCoordinate[7].toPrecision(3),(M||-1!==A.indexOf("divergence"))&&S.push("divergence: "+T.divergenceLabel)),h.textLabel&&S.push(h.textLabel),x=S.join("<br>")):"isosurface"===t.type||"volume"===t.type?(T.valueLabel=p.hoverLabelText(e._mockAxis,e._mockAxis.d2l(h.traceCoordinate[3]),t.valuehoverformat),S.push("value: "+T.valueLabel),h.textLabel&&S.push(h.textLabel),x=S.join("<br>")):x=h.textLabel;var E={x:h.traceCoordinate[0],y:h.traceCoordinate[1],z:h.traceCoordinate[2],data:_._input,fullData:_,curveNumber:_.index,pointNumber:w};d.appendArrayPointValue(E,_,w),t._module.eventData&&(E=_._module.eventData(E,h,_,{},w));var L={points:[E]};if(e.fullSceneLayout.hovermode){var C=[];d.loneHover({trace:_,x:(.5+.5*y[0]/y[3])*s,y:(.5-.5*y[1]/y[3])*l,xLabel:T.xLabel,yLabel:T.yLabel,zLabel:T.zLabel,text:x,name:u.name,color:d.castHoverOption(_,w,"bgcolor")||u.color,borderColor:d.castHoverOption(_,w,"bordercolor"),fontFamily:d.castHoverOption(_,w,"font.family"),fontSize:d.castHoverOption(_,w,"font.size"),fontColor:d.castHoverOption(_,w,"font.color"),nameLength:d.castHoverOption(_,w,"namelength"),textAlign:d.castHoverOption(_,w,"align"),hovertemplate:f.castOption(_,w,"hovertemplate"),hovertemplateLabels:f.extendFlat({},E,T),eventData:[E]},{container:n,gd:r,inOut_bbox:C}),E.bbox=C[0]}h.buttons&&h.distance<5?r.emit("plotly_click",L):r.emit("plotly_hover",L),this.oldEventData=L}else d.loneUnhover(n),this.oldEventData&&r.emit("plotly_unhover",this.oldEventData),this.oldEventData=void 0;e.drawAnnotations(e)},w.recoverContext=function(){var t=this;t.glplot.dispose();var e=function(){t.glplot.gl.isContextLost()?requestAnimationFrame(e):t.initializeGLPlot()?t.plot.apply(t,t.plotArgs):f.error("Catastrophic and unrecoverable WebGL error. Context lost.")};requestAnimationFrame(e)};var k=["xaxis","yaxis","zaxis"];function A(t,e,r){for(var n=t.fullSceneLayout,i=0;i<3;i++){var a=k[i],o=a.charAt(0),s=n[a],l=e[o],c=e[o+"calendar"],u=e["_"+o+"length"];if(f.isArrayOrTypedArray(l))for(var h,p=0;p<(u||l.length);p++)if(f.isArrayOrTypedArray(l[p]))for(var d=0;d<l[p].length;++d)h=s.d2l(l[p][d],0,c),!isNaN(h)&&isFinite(h)&&(r[0][i]=Math.min(r[0][i],h),r[1][i]=Math.max(r[1][i],h));else h=s.d2l(l[p],0,c),!isNaN(h)&&isFinite(h)&&(r[0][i]=Math.min(r[0][i],h),r[1][i]=Math.max(r[1][i],h));else r[0][i]=Math.min(r[0][i],0),r[1][i]=Math.max(r[1][i],u-1)}}w.plot=function(t,e,r){if(this.plotArgs=[t,e,r],!this.glplot.contextLost){var n,i,a,o,s,l,c=e[this.id],u=r[this.id];this.fullLayout=e,this.fullSceneLayout=c,this.axesOptions.merge(e,c),this.spikeOptions.merge(c),this.setViewport(c),this.updateFx(c.dragmode,c.hovermode),this.camera.enableWheel=this.graphDiv._context._scrollZoom.gl3d,this.glplot.setClearColor(m(c.bgcolor)),this.setConvert(s),t?Array.isArray(t)||(t=[t]):t=[];var f=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];for(a=0;a<t.length;++a)!0===(n=t[a]).visible&&0!==n._length&&A(this,n,f);!function(t,e){for(var r=t.fullSceneLayout,n=r.annotations||[],i=0;i<3;i++)for(var a=k[i],o=a.charAt(0),s=r[a],l=0;l<n.length;l++){var c=n[l];if(c.visible){var u=s.r2l(c[o]);!isNaN(u)&&isFinite(u)&&(e[0][i]=Math.min(e[0][i],u),e[1][i]=Math.max(e[1][i],u))}}}(this,f);var h=[1,1,1];for(o=0;o<3;++o)f[1][o]===f[0][o]?h[o]=1:h[o]=1/(f[1][o]-f[0][o]);for(this.dataScale=h,this.convertAnnotations(this),a=0;a<t.length;++a)!0===(n=t[a]).visible&&0!==n._length&&((i=this.traces[n.uid])?i.data.type===n.type?i.update(n):(i.dispose(),i=n._module.plot(this,n),this.traces[n.uid]=i):(i=n._module.plot(this,n),this.traces[n.uid]=i),i.name=n.name);var p=Object.keys(this.traces);t:for(a=0;a<p.length;++a){for(o=0;o<t.length;++o)if(t[o].uid===p[a]&&!0===t[o].visible&&0!==t[o]._length)continue t;(i=this.traces[p[a]]).dispose(),delete this.traces[p[a]]}this.glplot.objects.sort((function(t,e){return t._trace.data.index-e._trace.data.index}));var d,g=[[0,0,0],[0,0,0]],v=[],y={};for(a=0;a<3;++a){if((l=(s=c[k[a]]).type)in y?(y[l].acc*=h[a],y[l].count+=1):y[l]={acc:h[a],count:1},s.autorange){g[0][a]=1/0,g[1][a]=-1/0;var x=this.glplot.objects,b=this.fullSceneLayout.annotations||[],_=s._name.charAt(0);for(o=0;o<x.length;o++){var w=x[o],T=w.bounds,M=w._trace.data._pad||0;"ErrorBars"===w.constructor.name&&s._lowerLogErrorBound?g[0][a]=Math.min(g[0][a],s._lowerLogErrorBound):g[0][a]=Math.min(g[0][a],T[0][a]/h[a]-M),g[1][a]=Math.max(g[1][a],T[1][a]/h[a]+M)}for(o=0;o<b.length;o++){var S=b[o];if(S.visible){var E=s.r2l(S[_]);g[0][a]=Math.min(g[0][a],E),g[1][a]=Math.max(g[1][a],E)}}if("rangemode"in s&&"tozero"===s.rangemode&&(g[0][a]=Math.min(g[0][a],0),g[1][a]=Math.max(g[1][a],0)),g[0][a]>g[1][a])g[0][a]=-1,g[1][a]=1;else{var L=g[1][a]-g[0][a];g[0][a]-=L/32,g[1][a]+=L/32}if("reversed"===s.autorange){var C=g[0][a];g[0][a]=g[1][a],g[1][a]=C}}else{var P=s.range;g[0][a]=s.r2l(P[0]),g[1][a]=s.r2l(P[1])}g[0][a]===g[1][a]&&(g[0][a]-=1,g[1][a]+=1),v[a]=g[1][a]-g[0][a],this.glplot.setBounds(a,{min:g[0][a]*h[a],max:g[1][a]*h[a]})}var I=c.aspectmode;if("cube"===I)d=[1,1,1];else if("manual"===I){var O=c.aspectratio;d=[O.x,O.y,O.z]}else{if("auto"!==I&&"data"!==I)throw new Error("scene.js aspectRatio was not one of the enumerated types");var z=[1,1,1];for(a=0;a<3;++a){var D=y[l=(s=c[k[a]]).type];z[a]=Math.pow(D.acc,1/D.count)/h[a]}d="data"===I||Math.max.apply(null,z)/Math.min.apply(null,z)<=4?z:[1,1,1]}c.aspectratio.x=u.aspectratio.x=d[0],c.aspectratio.y=u.aspectratio.y=d[1],c.aspectratio.z=u.aspectratio.z=d[2],this.glplot.setAspectratio(c.aspectratio),this.viewInitial.aspectratio||(this.viewInitial.aspectratio={x:c.aspectratio.x,y:c.aspectratio.y,z:c.aspectratio.z}),this.viewInitial.aspectmode||(this.viewInitial.aspectmode=c.aspectmode);var R=c.domain||null,F=e._size||null;if(R&&F){var B=this.container.style;B.position="absolute",B.left=F.l+R.x[0]*F.w+"px",B.top=F.t+(1-R.y[1])*F.h+"px",B.width=F.w*(R.x[1]-R.x[0])+"px",B.height=F.h*(R.y[1]-R.y[0])+"px"}this.glplot.redraw()}},w.destroy=function(){this.glplot&&(this.camera.mouseListener.enabled=!1,this.container.removeEventListener("wheel",this.camera.wheelListener),this.camera=null,this.glplot.dispose(),this.container.parentNode.removeChild(this.container),this.glplot=null)},w.getCamera=function(){var t;return this.camera.view.recalcMatrix(this.camera.view.lastT()),{up:{x:(t=this.camera).up[0],y:t.up[1],z:t.up[2]},center:{x:t.center[0],y:t.center[1],z:t.center[2]},eye:{x:t.eye[0],y:t.eye[1],z:t.eye[2]},projection:{type:!0===t._ortho?"orthographic":"perspective"}}},w.setViewport=function(t){var e,r=t.camera;this.camera.lookAt.apply(this,[[(e=r).eye.x,e.eye.y,e.eye.z],[e.center.x,e.center.y,e.center.z],[e.up.x,e.up.y,e.up.z]]),this.glplot.setAspectratio(t.aspectratio),"orthographic"===r.projection.type!==this.camera._ortho&&(this.glplot.redraw(),this.glplot.clearRGBA(),this.glplot.dispose(),this.initializeGLPlot())},w.isCameraChanged=function(t){var e=this.getCamera(),r=f.nestedProperty(t,this.id+".camera").get();function n(t,e,r,n){var i=["up","center","eye"],a=["x","y","z"];return e[i[r]]&&t[i[r]][a[n]]===e[i[r]][a[n]]}var i=!1;if(void 0===r)i=!0;else{for(var a=0;a<3;a++)for(var o=0;o<3;o++)if(!n(e,r,a,o)){i=!0;break}(!r.projection||e.projection&&e.projection.type!==r.projection.type)&&(i=!0)}return i},w.isAspectChanged=function(t){var e=this.glplot.getAspectratio(),r=f.nestedProperty(t,this.id+".aspectratio").get();return void 0===r||r.x!==e.x||r.y!==e.y||r.z!==e.z},w.saveLayout=function(t){var e,r,n,i,a,o,s=this.fullLayout,l=this.isCameraChanged(t),c=this.isAspectChanged(t),h=l||c;if(h){var p={};if(l&&(e=this.getCamera(),n=(r=f.nestedProperty(t,this.id+".camera")).get(),p[this.id+".camera"]=n),c&&(i=this.glplot.getAspectratio(),o=(a=f.nestedProperty(t,this.id+".aspectratio")).get(),p[this.id+".aspectratio"]=o),u.call("_storeDirectGUIEdit",t,s._preGUI,p),l)r.set(e),f.nestedProperty(s,this.id+".camera").set(e);if(c)a.set(i),f.nestedProperty(s,this.id+".aspectratio").set(i),this.glplot.redraw()}return h},w.updateFx=function(t,e){var r=this.camera;if(r)if("orbit"===t)r.mode="orbit",r.keyBindingMode="rotate";else if("turntable"===t){r.up=[0,0,1],r.mode="turntable",r.keyBindingMode="rotate";var n=this.graphDiv,i=n._fullLayout,a=this.fullSceneLayout.camera,o=a.up.x,s=a.up.y,l=a.up.z;if(l/Math.sqrt(o*o+s*s+l*l)<.999){var c=this.id+".camera.up",h={x:0,y:0,z:1},p={};p[c]=h;var d=n.layout;u.call("_storeDirectGUIEdit",d,i._preGUI,p),a.up=h,f.nestedProperty(d,c).set(h)}}else r.keyBindingMode=t;this.fullSceneLayout.hovermode=e},w.toImage=function(t){t||(t="png"),this.staticMode&&this.container.appendChild(n),this.glplot.redraw();var e=this.glplot.gl,r=e.drawingBufferWidth,i=e.drawingBufferHeight;e.bindFramebuffer(e.FRAMEBUFFER,null);var a=new Uint8Array(r*i*4);e.readPixels(0,0,r,i,e.RGBA,e.UNSIGNED_BYTE,a),function(t,e,r){for(var n=0,i=r-1;n<i;++n,--i)for(var a=0;a<e;++a)for(var o=0;o<4;++o){var s=4*(e*n+a)+o,l=4*(e*i+a)+o,c=t[s];t[s]=t[l],t[l]=c}}(a,r,i),function(t,e,r){for(var n=0;n<r;++n)for(var i=0;i<e;++i){var a=4*(e*n+i),o=t[a+3];if(o>0)for(var s=255/o,l=0;l<3;++l)t[a+l]=Math.min(s*t[a+l],255)}}(a,r,i);var o=document.createElement("canvas");o.width=r,o.height=i;var s,l=o.getContext("2d",{willReadFrequently:!0}),c=l.createImageData(r,i);switch(c.data.set(a),l.putImageData(c,0,0),t){case"jpeg":s=o.toDataURL("image/jpeg");break;case"webp":s=o.toDataURL("image/webp");break;default:s=o.toDataURL("image/png")}return this.staticMode&&this.container.removeChild(n),s},w.setConvert=function(){for(var t=0;t<3;t++){var e=this.fullSceneLayout[k[t]];p.setConvert(e,this.fullLayout),e.setScale=f.noop}},w.make4thDimension=function(){var t=this.graphDiv._fullLayout;this._mockAxis={type:"linear",showexponent:"all",exponentformat:"B"},p.setConvert(this._mockAxis,t)},e.exports=_},{"../../../stackgl_modules":1124,"../../components/fx":406,"../../lib":503,"../../lib/show_no_webgl_msg":525,"../../lib/str2rgbarray":528,"../../plots/cartesian/axes":554,"../../registry":638,"./layout/convert":602,"./layout/spikes":605,"./layout/tick_marks":606,"./project":607,"has-passive-events":229,"webgl-context":331}],609:[function(t,e,r){"use strict";e.exports=function(t,e,r,n){n=n||t.length;for(var i=new Array(n),a=0;a<n;a++)i[a]=[t[a],e[a],r[a]];return i}},{}],610:[function(t,e,r){"use strict";var n=t("./font_attributes"),i=t("./animation_attributes"),a=t("../components/color/attributes"),o=t("../components/shapes/draw_newshape/attributes"),s=t("./pad_attributes"),l=t("../lib/extend").extendFlat,c=n({editType:"calc"});c.family.dflt='"Open Sans", verdana, arial, sans-serif',c.size.dflt=12,c.color.dflt=a.defaultLine,e.exports={font:c,title:{text:{valType:"string",editType:"layoutstyle"},font:n({editType:"layoutstyle"}),xref:{valType:"enumerated",dflt:"container",values:["container","paper"],editType:"layoutstyle"},yref:{valType:"enumerated",dflt:"container",values:["container","paper"],editType:"layoutstyle"},x:{valType:"number",min:0,max:1,dflt:.5,editType:"layoutstyle"},y:{valType:"number",min:0,max:1,dflt:"auto",editType:"layoutstyle"},xanchor:{valType:"enumerated",dflt:"auto",values:["auto","left","center","right"],editType:"layoutstyle"},yanchor:{valType:"enumerated",dflt:"auto",values:["auto","top","middle","bottom"],editType:"layoutstyle"},pad:l(s({editType:"layoutstyle"}),{}),editType:"layoutstyle"},uniformtext:{mode:{valType:"enumerated",values:[!1,"hide","show"],dflt:!1,editType:"plot"},minsize:{valType:"number",min:0,dflt:0,editType:"plot"},editType:"plot"},autosize:{valType:"boolean",dflt:!1,editType:"none"},width:{valType:"number",min:10,dflt:700,editType:"plot"},height:{valType:"number",min:10,dflt:450,editType:"plot"},margin:{l:{valType:"number",min:0,dflt:80,editType:"plot"},r:{valType:"number",min:0,dflt:80,editType:"plot"},t:{valType:"number",min:0,dflt:100,editType:"plot"},b:{valType:"number",min:0,dflt:80,editType:"plot"},pad:{valType:"number",min:0,dflt:0,editType:"plot"},autoexpand:{valType:"boolean",dflt:!0,editType:"plot"},editType:"plot"},computed:{valType:"any",editType:"none"},paper_bgcolor:{valType:"color",dflt:a.background,editType:"plot"},plot_bgcolor:{valType:"color",dflt:a.background,editType:"layoutstyle"},autotypenumbers:{valType:"enumerated",values:["convert types","strict"],dflt:"convert types",editType:"calc"},separators:{valType:"string",editType:"plot"},hidesources:{valType:"boolean",dflt:!1,editType:"plot"},showlegend:{valType:"boolean",editType:"legend"},colorway:{valType:"colorlist",dflt:a.defaults,editType:"calc"},datarevision:{valType:"any",editType:"calc"},uirevision:{valType:"any",editType:"none"},editrevision:{valType:"any",editType:"none"},selectionrevision:{valType:"any",editType:"none"},template:{valType:"any",editType:"calc"},newshape:o.newshape,activeshape:o.activeshape,meta:{valType:"any",arrayOk:!0,editType:"plot"},transition:l({},i.transition,{editType:"none"}),_deprecated:{title:{valType:"string",editType:"layoutstyle"},titlefont:n({editType:"layoutstyle"})}}},{"../components/color/attributes":365,"../components/shapes/draw_newshape/attributes":451,"../lib/extend":493,"./animation_attributes":548,"./font_attributes":585,"./pad_attributes":618}],611:[function(t,e,r){"use strict";var n=t("../../lib/sort_object_keys"),i='\xa9 <a target="_blank" href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',a=['\xa9 <a target="_blank" href="https://carto.com/">Carto</a>',i].join(" "),o=['Map tiles by <a target="_blank" href="https://stamen.com">Stamen Design</a>','under <a target="_blank" href="https://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>',"|",'Data by <a target="_blank" href="https://openstreetmap.org">OpenStreetMap</a> contributors','under <a target="_blank" href="https://www.openstreetmap.org/copyright">ODbL</a>'].join(" "),s={"open-street-map":{id:"osm",version:8,sources:{"plotly-osm-tiles":{type:"raster",attribution:i,tiles:["https://a.tile.openstreetmap.org/{z}/{x}/{y}.png","https://b.tile.openstreetmap.org/{z}/{x}/{y}.png"],tileSize:256}},layers:[{id:"plotly-osm-tiles",type:"raster",source:"plotly-osm-tiles",minzoom:0,maxzoom:22}]},"white-bg":{id:"white-bg",version:8,sources:{},layers:[{id:"white-bg",type:"background",paint:{"background-color":"#FFFFFF"},minzoom:0,maxzoom:22}]},"carto-positron":{id:"carto-positron",version:8,sources:{"plotly-carto-positron":{type:"raster",attribution:a,tiles:["https://cartodb-basemaps-c.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png"],tileSize:256}},layers:[{id:"plotly-carto-positron",type:"raster",source:"plotly-carto-positron",minzoom:0,maxzoom:22}]},"carto-darkmatter":{id:"carto-darkmatter",version:8,sources:{"plotly-carto-darkmatter":{type:"raster",attribution:a,tiles:["https://cartodb-basemaps-c.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png"],tileSize:256}},layers:[{id:"plotly-carto-darkmatter",type:"raster",source:"plotly-carto-darkmatter",minzoom:0,maxzoom:22}]},"stamen-terrain":{id:"stamen-terrain",version:8,sources:{"plotly-stamen-terrain":{type:"raster",attribution:o,tiles:["https://stamen-tiles.a.ssl.fastly.net/terrain/{z}/{x}/{y}.png"],tileSize:256}},layers:[{id:"plotly-stamen-terrain",type:"raster",source:"plotly-stamen-terrain",minzoom:0,maxzoom:22}]},"stamen-toner":{id:"stamen-toner",version:8,sources:{"plotly-stamen-toner":{type:"raster",attribution:o,tiles:["https://stamen-tiles.a.ssl.fastly.net/toner/{z}/{x}/{y}.png"],tileSize:256}},layers:[{id:"plotly-stamen-toner",type:"raster",source:"plotly-stamen-toner",minzoom:0,maxzoom:22}]},"stamen-watercolor":{id:"stamen-watercolor",version:8,sources:{"plotly-stamen-watercolor":{type:"raster",attribution:['Map tiles by <a target="_blank" href="https://stamen.com">Stamen Design</a>','under <a target="_blank" href="https://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>',"|",'Data by <a target="_blank" href="https://openstreetmap.org">OpenStreetMap</a> contributors','under <a target="_blank" href="https://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>'].join(" "),tiles:["https://stamen-tiles.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png"],tileSize:256}},layers:[{id:"plotly-stamen-watercolor",type:"raster",source:"plotly-stamen-watercolor",minzoom:0,maxzoom:22}]}},l=n(s);e.exports={requiredVersion:"1.10.1",styleUrlPrefix:"mapbox://styles/mapbox/",styleUrlSuffix:"v9",styleValuesMapbox:["basic","streets","outdoors","light","dark","satellite","satellite-streets"],styleValueDflt:"basic",stylesNonMapbox:s,styleValuesNonMapbox:l,traceLayerPrefix:"plotly-trace-layer-",layoutLayerPrefix:"plotly-layout-layer-",wrongVersionErrorMsg:["Your custom plotly.js bundle is not using the correct mapbox-gl version","Please install mapbox-gl@1.10.1."].join("\n"),noAccessTokenErrorMsg:["Missing Mapbox access token.","Mapbox trace type require a Mapbox access token to be registered.","For example:","  Plotly.newPlot(gd, data, layout, { mapboxAccessToken: 'my-access-token' });","More info here: https://www.mapbox.com/help/define-access-token/"].join("\n"),missingStyleErrorMsg:["No valid mapbox style found, please set `mapbox.style` to one of:",l.join(", "),"or register a Mapbox access token to use a Mapbox-served style."].join("\n"),multipleTokensErrorMsg:["Set multiple mapbox access token across different mapbox subplot,","using first token found as mapbox-gl does not allow multipleaccess tokens on the same page."].join("\n"),mapOnErrorMsg:"Mapbox error.",mapboxLogo:{path0:"m 10.5,1.24 c -5.11,0 -9.25,4.15 -9.25,9.25 0,5.1 4.15,9.25 9.25,9.25 5.1,0 9.25,-4.15 9.25,-9.25 0,-5.11 -4.14,-9.25 -9.25,-9.25 z m 4.39,11.53 c -1.93,1.93 -4.78,2.31 -6.7,2.31 -0.7,0 -1.41,-0.05 -2.1,-0.16 0,0 -1.02,-5.64 2.14,-8.81 0.83,-0.83 1.95,-1.28 3.13,-1.28 1.27,0 2.49,0.51 3.39,1.42 1.84,1.84 1.89,4.75 0.14,6.52 z",path1:"M 10.5,-0.01 C 4.7,-0.01 0,4.7 0,10.49 c 0,5.79 4.7,10.5 10.5,10.5 5.8,0 10.5,-4.7 10.5,-10.5 C 20.99,4.7 16.3,-0.01 10.5,-0.01 Z m 0,19.75 c -5.11,0 -9.25,-4.15 -9.25,-9.25 0,-5.1 4.14,-9.26 9.25,-9.26 5.11,0 9.25,4.15 9.25,9.25 0,5.13 -4.14,9.26 -9.25,9.26 z",path2:"M 14.74,6.25 C 12.9,4.41 9.98,4.35 8.23,6.1 5.07,9.27 6.09,14.91 6.09,14.91 c 0,0 5.64,1.02 8.81,-2.14 C 16.64,11 16.59,8.09 14.74,6.25 Z m -2.27,4.09 -0.91,1.87 -0.9,-1.87 -1.86,-0.91 1.86,-0.9 0.9,-1.87 0.91,1.87 1.86,0.9 z",polygon:"11.56,12.21 10.66,10.34 8.8,9.43 10.66,8.53 11.56,6.66 12.47,8.53 14.33,9.43 12.47,10.34"},styleRules:{map:"overflow:hidden;position:relative;","missing-css":"display:none;",canary:"background-color:salmon;","ctrl-bottom-left":"position: absolute; pointer-events: none; z-index: 2; bottom: 0; left: 0;","ctrl-bottom-right":"position: absolute; pointer-events: none; z-index: 2; right: 0; bottom: 0;",ctrl:"clear: both; pointer-events: auto; transform: translate(0, 0);","ctrl-attrib.mapboxgl-compact .mapboxgl-ctrl-attrib-inner":"display: none;","ctrl-attrib.mapboxgl-compact:hover .mapboxgl-ctrl-attrib-inner":"display: block; margin-top:2px","ctrl-attrib.mapboxgl-compact:hover":"padding: 2px 24px 2px 4px; visibility: visible; margin-top: 6px;","ctrl-attrib.mapboxgl-compact::after":'content: ""; cursor: pointer; position: absolute; background-image: url(\'data:image/svg+xml;charset=utf-8,%3Csvg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"%3E %3Cpath fill="%23333333" fill-rule="evenodd" d="M4,10a6,6 0 1,0 12,0a6,6 0 1,0 -12,0 M9,7a1,1 0 1,0 2,0a1,1 0 1,0 -2,0 M9,10a1,1 0 1,1 2,0l0,3a1,1 0 1,1 -2,0"/%3E %3C/svg%3E\'); background-color: rgba(255, 255, 255, 0.5); width: 24px; height: 24px; box-sizing: border-box; border-radius: 12px;',"ctrl-attrib.mapboxgl-compact":"min-height: 20px; padding: 0; margin: 10px; position: relative; background-color: #fff; border-radius: 3px 12px 12px 3px;","ctrl-bottom-right > .mapboxgl-ctrl-attrib.mapboxgl-compact::after":"bottom: 0; right: 0","ctrl-bottom-left > .mapboxgl-ctrl-attrib.mapboxgl-compact::after":"bottom: 0; left: 0","ctrl-bottom-left .mapboxgl-ctrl":"margin: 0 0 10px 10px; float: left;","ctrl-bottom-right .mapboxgl-ctrl":"margin: 0 10px 10px 0; float: right;","ctrl-attrib":"color: rgba(0, 0, 0, 0.75); text-decoration: none; font-size: 12px","ctrl-attrib a":"color: rgba(0, 0, 0, 0.75); text-decoration: none; font-size: 12px","ctrl-attrib a:hover":"color: inherit; text-decoration: underline;","ctrl-attrib .mapbox-improve-map":"font-weight: bold; margin-left: 2px;","attrib-empty":"display: none;","ctrl-logo":'display:block; width: 21px; height: 21px; background-image: url(\'data:image/svg+xml;charset=utf-8,%3C?xml version="1.0" encoding="utf-8"?%3E %3Csvg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 21 21" style="enable-background:new 0 0 21 21;" xml:space="preserve"%3E%3Cg transform="translate(0,0.01)"%3E%3Cpath d="m 10.5,1.24 c -5.11,0 -9.25,4.15 -9.25,9.25 0,5.1 4.15,9.25 9.25,9.25 5.1,0 9.25,-4.15 9.25,-9.25 0,-5.11 -4.14,-9.25 -9.25,-9.25 z m 4.39,11.53 c -1.93,1.93 -4.78,2.31 -6.7,2.31 -0.7,0 -1.41,-0.05 -2.1,-0.16 0,0 -1.02,-5.64 2.14,-8.81 0.83,-0.83 1.95,-1.28 3.13,-1.28 1.27,0 2.49,0.51 3.39,1.42 1.84,1.84 1.89,4.75 0.14,6.52 z" style="opacity:0.9;fill:%23ffffff;enable-background:new" class="st0"/%3E%3Cpath d="M 10.5,-0.01 C 4.7,-0.01 0,4.7 0,10.49 c 0,5.79 4.7,10.5 10.5,10.5 5.8,0 10.5,-4.7 10.5,-10.5 C 20.99,4.7 16.3,-0.01 10.5,-0.01 Z m 0,19.75 c -5.11,0 -9.25,-4.15 -9.25,-9.25 0,-5.1 4.14,-9.26 9.25,-9.26 5.11,0 9.25,4.15 9.25,9.25 0,5.13 -4.14,9.26 -9.25,9.26 z" style="opacity:0.35;enable-background:new" class="st1"/%3E%3Cpath d="M 14.74,6.25 C 12.9,4.41 9.98,4.35 8.23,6.1 5.07,9.27 6.09,14.91 6.09,14.91 c 0,0 5.64,1.02 8.81,-2.14 C 16.64,11 16.59,8.09 14.74,6.25 Z m -2.27,4.09 -0.91,1.87 -0.9,-1.87 -1.86,-0.91 1.86,-0.9 0.9,-1.87 0.91,1.87 1.86,0.9 z" style="opacity:0.35;enable-background:new" class="st1"/%3E%3Cpolygon points="11.56,12.21 10.66,10.34 8.8,9.43 10.66,8.53 11.56,6.66 12.47,8.53 14.33,9.43 12.47,10.34 " style="opacity:0.9;fill:%23ffffff;enable-background:new" class="st0"/%3E%3C/g%3E%3C/svg%3E\')'}}},{"../../lib/sort_object_keys":526}],612:[function(t,e,r){"use strict";var n=t("../../lib");e.exports=function(t,e){var r=t.split(" "),i=r[0],a=r[1],o=n.isArrayOrTypedArray(e)?n.mean(e):e,s=.5+o/100,l=1.5+o/100,c=["",""],u=[0,0];switch(i){case"top":c[0]="top",u[1]=-l;break;case"bottom":c[0]="bottom",u[1]=l}switch(a){case"left":c[1]="right",u[0]=-s;break;case"right":c[1]="left",u[0]=s}return{anchor:c[0]&&c[1]?c.join("-"):c[0]?c[0]:c[1]?c[1]:"center",offset:u}}},{"../../lib":503}],613:[function(t,e,r){"use strict";var n=t("mapbox-gl/dist/mapbox-gl-unminified"),i=t("../../lib"),a=i.strTranslate,o=i.strScale,s=t("../../plots/get_data").getSubplotCalcData,l=t("../../constants/xmlns_namespaces"),c=t("@plotly/d3"),u=t("../../components/drawing"),f=t("../../lib/svg_text_utils"),h=t("./mapbox"),p=r.constants=t("./constants");function d(t){return"string"==typeof t&&(-1!==p.styleValuesMapbox.indexOf(t)||0===t.indexOf("mapbox://"))}r.name="mapbox",r.attr="subplot",r.idRoot="mapbox",r.idRegex=r.attrRegex=i.counterRegex("mapbox"),r.attributes={subplot:{valType:"subplotid",dflt:"mapbox",editType:"calc"}},r.layoutAttributes=t("./layout_attributes"),r.supplyLayoutDefaults=t("./layout_defaults"),r.plot=function(t){var e=t._fullLayout,r=t.calcdata,a=e._subplots.mapbox;if(n.version!==p.requiredVersion)throw new Error(p.wrongVersionErrorMsg);var o=function(t,e){var r=t._fullLayout;if(""===t._context.mapboxAccessToken)return"";for(var n=[],a=[],o=!1,s=!1,l=0;l<e.length;l++){var c=r[e[l]],u=c.accesstoken;d(c.style)&&(u?i.pushUnique(n,u):(d(c._input.style)&&(i.error("Uses Mapbox map style, but did not set an access token."),o=!0),s=!0)),u&&i.pushUnique(a,u)}if(s){var f=o?p.noAccessTokenErrorMsg:p.missingStyleErrorMsg;throw i.error(f),new Error(f)}return n.length?(n.length>1&&i.warn(p.multipleTokensErrorMsg),n[0]):(a.length&&i.log(["Listed mapbox access token(s)",a.join(","),"but did not use a Mapbox map style, ignoring token(s)."].join(" ")),"")}(t,a);n.accessToken=o;for(var l=0;l<a.length;l++){var c=a[l],u=s(r,"mapbox",c),f=e[c],m=f._subplot;m||(m=new h(t,c),e[c]._subplot=m),m.viewInitial||(m.viewInitial={center:i.extendFlat({},f.center),zoom:f.zoom,bearing:f.bearing,pitch:f.pitch}),m.plot(u,e,t._promises)}},r.clean=function(t,e,r,n){for(var i=n._subplots.mapbox||[],a=0;a<i.length;a++){var o=i[a];!e[o]&&n[o]._subplot&&n[o]._subplot.destroy()}},r.toSVG=function(t){for(var e=t._fullLayout,r=e._subplots.mapbox,n=e._size,i=0;i<r.length;i++){var s=e[r[i]],h=s.domain,d=s._subplot.toImage("png");e._glimages.append("svg:image").attr({xmlns:l.svg,"xlink:href":d,x:n.l+n.w*h.x[0],y:n.t+n.h*(1-h.y[1]),width:n.w*(h.x[1]-h.x[0]),height:n.h*(h.y[1]-h.y[0]),preserveAspectRatio:"none"});var m=c.select(s._subplot.div);if(!(null===m.select(".mapboxgl-ctrl-logo").node().offsetParent)){var g=e._glimages.append("g");g.attr("transform",a(n.l+n.w*h.x[0]+10,n.t+n.h*(1-h.y[0])-31)),g.append("path").attr("d",p.mapboxLogo.path0).style({opacity:.9,fill:"#ffffff","enable-background":"new"}),g.append("path").attr("d",p.mapboxLogo.path1).style("opacity",.35).style("enable-background","new"),g.append("path").attr("d",p.mapboxLogo.path2).style("opacity",.35).style("enable-background","new"),g.append("polygon").attr("points",p.mapboxLogo.polygon).style({opacity:.9,fill:"#ffffff","enable-background":"new"})}var v=m.select(".mapboxgl-ctrl-attrib").text().replace("Improve this map",""),y=e._glimages.append("g"),x=y.append("text");x.text(v).classed("static-attribution",!0).attr({"font-size":12,"font-family":"Arial",color:"rgba(0, 0, 0, 0.75)","text-anchor":"end","data-unformatted":v});var b=u.bBox(x.node()),_=n.w*(h.x[1]-h.x[0]);if(b.width>_/2){var w=v.split("|").join("<br>");x.text(w).attr("data-unformatted",w).call(f.convertToTspans,t),b=u.bBox(x.node())}x.attr("transform",a(-3,8-b.height)),y.insert("rect",".static-attribution").attr({x:-b.width-6,y:-b.height-3,width:b.width+6,height:b.height+3,fill:"rgba(255, 255, 255, 0.75)"});var T=1;b.width+6>_&&(T=_/(b.width+6));var k=[n.l+n.w*h.x[1],n.t+n.h*(1-h.y[0])];y.attr("transform",a(k[0],k[1])+o(T))}},r.updateFx=function(t){for(var e=t._fullLayout,r=e._subplots.mapbox,n=0;n<r.length;n++){e[r[n]]._subplot.updateFx(e)}}},{"../../components/drawing":388,"../../constants/xmlns_namespaces":480,"../../lib":503,"../../lib/svg_text_utils":529,"../../plots/get_data":593,"./constants":611,"./layout_attributes":615,"./layout_defaults":616,"./mapbox":617,"@plotly/d3":58,"mapbox-gl/dist/mapbox-gl-unminified":239}],614:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../lib/svg_text_utils").sanitizeHTML,a=t("./convert_text_opts"),o=t("./constants");function s(t,e){this.subplot=t,this.uid=t.uid+"-"+e,this.index=e,this.idSource="source-"+this.uid,this.idLayer=o.layoutLayerPrefix+this.uid,this.sourceType=null,this.source=null,this.layerType=null,this.below=null,this.visible=!1}var l=s.prototype;function c(t){if(!t.visible)return!1;var e=t.source;if(Array.isArray(e)&&e.length>0){for(var r=0;r<e.length;r++)if("string"!=typeof e[r]||0===e[r].length)return!1;return!0}return n.isPlainObject(e)||"string"==typeof e&&e.length>0}function u(t){var e={},r={};switch(t.type){case"circle":n.extendFlat(r,{"circle-radius":t.circle.radius,"circle-color":t.color,"circle-opacity":t.opacity});break;case"line":n.extendFlat(r,{"line-width":t.line.width,"line-color":t.color,"line-opacity":t.opacity,"line-dasharray":t.line.dash});break;case"fill":n.extendFlat(r,{"fill-color":t.color,"fill-outline-color":t.fill.outlinecolor,"fill-opacity":t.opacity});break;case"symbol":var i=t.symbol,o=a(i.textposition,i.iconsize);n.extendFlat(e,{"icon-image":i.icon+"-15","icon-size":i.iconsize/10,"text-field":i.text,"text-size":i.textfont.size,"text-anchor":o.anchor,"text-offset":o.offset,"symbol-placement":i.placement}),n.extendFlat(r,{"icon-color":t.color,"text-color":i.textfont.color,"text-opacity":t.opacity});break;case"raster":n.extendFlat(r,{"raster-fade-duration":0,"raster-opacity":t.opacity})}return{layout:e,paint:r}}l.update=function(t){this.visible?this.needsNewImage(t)?this.updateImage(t):this.needsNewSource(t)?(this.removeLayer(),this.updateSource(t),this.updateLayer(t)):this.needsNewLayer(t)?this.updateLayer(t):this.updateStyle(t):(this.updateSource(t),this.updateLayer(t)),this.visible=c(t)},l.needsNewImage=function(t){return this.subplot.map.getSource(this.idSource)&&"image"===this.sourceType&&"image"===t.sourcetype&&(this.source!==t.source||JSON.stringify(this.coordinates)!==JSON.stringify(t.coordinates))},l.needsNewSource=function(t){return this.sourceType!==t.sourcetype||JSON.stringify(this.source)!==JSON.stringify(t.source)||this.layerType!==t.type},l.needsNewLayer=function(t){return this.layerType!==t.type||this.below!==this.subplot.belowLookup["layout-"+this.index]},l.lookupBelow=function(){return this.subplot.belowLookup["layout-"+this.index]},l.updateImage=function(t){this.subplot.map.getSource(this.idSource).updateImage({url:t.source,coordinates:t.coordinates});var e=this.findFollowingMapboxLayerId(this.lookupBelow());null!==e&&this.subplot.map.moveLayer(this.idLayer,e)},l.updateSource=function(t){var e=this.subplot.map;if(e.getSource(this.idSource)&&e.removeSource(this.idSource),this.sourceType=t.sourcetype,this.source=t.source,c(t)){var r=function(t){var e,r=t.sourcetype,n=t.source,a={type:r};"geojson"===r?e="data":"vector"===r?e="string"==typeof n?"url":"tiles":"raster"===r?(e="tiles",a.tileSize=256):"image"===r&&(e="url",a.coordinates=t.coordinates);a[e]=n,t.sourceattribution&&(a.attribution=i(t.sourceattribution));return a}(t);e.addSource(this.idSource,r)}},l.findFollowingMapboxLayerId=function(t){if("traces"===t)for(var e=this.subplot.getMapLayers(),r=0;r<e.length;r++){var n=e[r].id;if("string"==typeof n&&0===n.indexOf(o.traceLayerPrefix)){t=n;break}}return t},l.updateLayer=function(t){var e=this.subplot,r=u(t),n=this.lookupBelow(),i=this.findFollowingMapboxLayerId(n);this.removeLayer(),c(t)&&e.addLayer({id:this.idLayer,source:this.idSource,"source-layer":t.sourcelayer||"",type:t.type,minzoom:t.minzoom,maxzoom:t.maxzoom,layout:r.layout,paint:r.paint},i),this.layerType=t.type,this.below=n},l.updateStyle=function(t){if(c(t)){var e=u(t);this.subplot.setOptions(this.idLayer,"setLayoutProperty",e.layout),this.subplot.setOptions(this.idLayer,"setPaintProperty",e.paint)}},l.removeLayer=function(){var t=this.subplot.map;t.getLayer(this.idLayer)&&t.removeLayer(this.idLayer)},l.dispose=function(){var t=this.subplot.map;t.getLayer(this.idLayer)&&t.removeLayer(this.idLayer),t.getSource(this.idSource)&&t.removeSource(this.idSource)},e.exports=function(t,e,r){var n=new s(t,e);return n.update(r),n}},{"../../lib":503,"../../lib/svg_text_utils":529,"./constants":611,"./convert_text_opts":612}],615:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/color").defaultLine,a=t("../domain").attributes,o=t("../font_attributes"),s=t("../../traces/scatter/attributes").textposition,l=t("../../plot_api/edit_types").overrideAll,c=t("../../plot_api/plot_template").templatedArray,u=t("./constants"),f=o({});f.family.dflt="Open Sans Regular, Arial Unicode MS Regular",(e.exports=l({_arrayAttrRegexps:[n.counterRegex("mapbox",".layers",!0)],domain:a({name:"mapbox"}),accesstoken:{valType:"string",noBlank:!0,strict:!0},style:{valType:"any",values:u.styleValuesMapbox.concat(u.styleValuesNonMapbox),dflt:u.styleValueDflt},center:{lon:{valType:"number",dflt:0},lat:{valType:"number",dflt:0}},zoom:{valType:"number",dflt:1},bearing:{valType:"number",dflt:0},pitch:{valType:"number",dflt:0},layers:c("layer",{visible:{valType:"boolean",dflt:!0},sourcetype:{valType:"enumerated",values:["geojson","vector","raster","image"],dflt:"geojson"},source:{valType:"any"},sourcelayer:{valType:"string",dflt:""},sourceattribution:{valType:"string"},type:{valType:"enumerated",values:["circle","line","fill","symbol","raster"],dflt:"circle"},coordinates:{valType:"any"},below:{valType:"string"},color:{valType:"color",dflt:i},opacity:{valType:"number",min:0,max:1,dflt:1},minzoom:{valType:"number",min:0,max:24,dflt:0},maxzoom:{valType:"number",min:0,max:24,dflt:24},circle:{radius:{valType:"number",dflt:15}},line:{width:{valType:"number",dflt:2},dash:{valType:"data_array"}},fill:{outlinecolor:{valType:"color",dflt:i}},symbol:{icon:{valType:"string",dflt:"marker"},iconsize:{valType:"number",dflt:10},text:{valType:"string",dflt:""},placement:{valType:"enumerated",values:["point","line","line-center"],dflt:"point"},textfont:f,textposition:n.extendFlat({},s,{arrayOk:!1})}})},"plot","from-root")).uirevision={valType:"any",editType:"none"}},{"../../components/color":366,"../../lib":503,"../../plot_api/edit_types":536,"../../plot_api/plot_template":543,"../../traces/scatter/attributes":927,"../domain":584,"../font_attributes":585,"./constants":611}],616:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../subplot_defaults"),a=t("../array_container_defaults"),o=t("./layout_attributes");function s(t,e,r,n){r("accesstoken",n.accessToken),r("style"),r("center.lon"),r("center.lat"),r("zoom"),r("bearing"),r("pitch"),a(t,e,{name:"layers",handleItemDefaults:l}),e._input=t}function l(t,e){function r(r,i){return n.coerce(t,e,o.layers,r,i)}if(r("visible")){var i,a=r("sourcetype"),s="raster"===a||"image"===a;r("source"),r("sourceattribution"),"vector"===a&&r("sourcelayer"),"image"===a&&r("coordinates"),s&&(i="raster");var l=r("type",i);s&&"raster"!==l&&(l=e.type="raster",n.log("Source types *raster* and *image* must drawn *raster* layer type.")),r("below"),r("color"),r("opacity"),r("minzoom"),r("maxzoom"),"circle"===l&&r("circle.radius"),"line"===l&&(r("line.width"),r("line.dash")),"fill"===l&&r("fill.outlinecolor"),"symbol"===l&&(r("symbol.icon"),r("symbol.iconsize"),r("symbol.text"),n.coerceFont(r,"symbol.textfont"),r("symbol.textposition"),r("symbol.placement"))}}e.exports=function(t,e,r){i(t,e,r,{type:"mapbox",attributes:o,handleDefaults:s,partition:"y",accessToken:e._mapboxAccessToken})}},{"../../lib":503,"../array_container_defaults":549,"../subplot_defaults":632,"./layout_attributes":615}],617:[function(t,e,r){"use strict";var n=t("mapbox-gl/dist/mapbox-gl-unminified"),i=t("../../lib"),a=t("../../lib/geo_location_utils"),o=t("../../registry"),s=t("../cartesian/axes"),l=t("../../components/dragelement"),c=t("../../components/fx"),u=t("../../components/dragelement/helpers"),f=u.rectMode,h=u.drawMode,p=u.selectMode,d=t("../cartesian/select").prepSelect,m=t("../cartesian/select").clearSelect,g=t("../cartesian/select").clearSelectionsCache,v=t("../cartesian/select").selectOnClick,y=t("./constants"),x=t("./layers");function b(t,e){this.id=e,this.gd=t;var r=t._fullLayout,n=t._context;this.container=r._glcontainer.node(),this.isStatic=n.staticPlot,this.uid=r._uid+"-"+this.id,this.div=null,this.xaxis=null,this.yaxis=null,this.createFramework(r),this.map=null,this.accessToken=null,this.styleObj=null,this.traceHash={},this.layerList=[],this.belowLookup={},this.dragging=!1,this.wheeling=!1}var _=b.prototype;_.plot=function(t,e,r){var n,i=this,a=e[i.id];i.map&&a.accesstoken!==i.accessToken&&(i.map.remove(),i.map=null,i.styleObj=null,i.traceHash={},i.layerList=[]),n=i.map?new Promise((function(r,n){i.updateMap(t,e,r,n)})):new Promise((function(r,n){i.createMap(t,e,r,n)})),r.push(n)},_.createMap=function(t,e,r,i){var o=this,s=e[o.id],l=o.styleObj=T(s.style);o.accessToken=s.accesstoken;var c=o.map=new n.Map({container:o.div,style:l.style,center:A(s.center),zoom:s.zoom,bearing:s.bearing,pitch:s.pitch,interactive:!o.isStatic,preserveDrawingBuffer:o.isStatic,doubleClickZoom:!1,boxZoom:!1,attributionControl:!1}).addControl(new n.AttributionControl({compact:!0}));c._canvas.style.left="0px",c._canvas.style.top="0px",o.rejectOnError(i),o.isStatic||o.initFx(t,e);var u=[];u.push(new Promise((function(t){c.once("load",t)}))),u=u.concat(a.fetchTraceGeoData(t)),Promise.all(u).then((function(){o.fillBelowLookup(t,e),o.updateData(t),o.updateLayout(e),o.resolveOnRender(r)})).catch(i)},_.updateMap=function(t,e,r,n){var i=this,o=i.map,s=e[this.id];i.rejectOnError(n);var l=[],c=T(s.style);JSON.stringify(i.styleObj)!==JSON.stringify(c)&&(i.styleObj=c,o.setStyle(c.style),i.traceHash={},l.push(new Promise((function(t){o.once("styledata",t)})))),l=l.concat(a.fetchTraceGeoData(t)),Promise.all(l).then((function(){i.fillBelowLookup(t,e),i.updateData(t),i.updateLayout(e),i.resolveOnRender(r)})).catch(n)},_.fillBelowLookup=function(t,e){var r,n,i=e[this.id].layers,a=this.belowLookup={},o=!1;for(r=0;r<t.length;r++){var s=t[r][0].trace,l=s._module;"string"==typeof s.below?n=s.below:l.getBelow&&(n=l.getBelow(s,this)),""===n&&(o=!0),a["trace-"+s.uid]=n||""}for(r=0;r<i.length;r++){var c=i[r];n="string"==typeof c.below?c.below:o?"traces":"",a["layout-"+r]=n}var u,f,h={};for(u in a)h[n=a[u]]?h[n].push(u):h[n]=[u];for(n in h){var p=h[n];if(p.length>1)for(r=0;r<p.length;r++)0===(u=p[r]).indexOf("trace-")?(f=u.split("trace-")[1],this.traceHash[f]&&(this.traceHash[f].below=null)):0===u.indexOf("layout-")&&(f=u.split("layout-")[1],this.layerList[f]&&(this.layerList[f].below=null))}};var w={choroplethmapbox:0,densitymapbox:1,scattermapbox:2};function T(t){var e={};return i.isPlainObject(t)?(e.id=t.id,e.style=t):"string"==typeof t?(e.id=t,-1!==y.styleValuesMapbox.indexOf(t)?e.style=k(t):y.stylesNonMapbox[t]?e.style=y.stylesNonMapbox[t]:e.style=t):(e.id=y.styleValueDflt,e.style=k(y.styleValueDflt)),e.transition={duration:0,delay:0},e}function k(t){return y.styleUrlPrefix+t+"-"+y.styleUrlSuffix}function A(t){return[t.lon,t.lat]}_.updateData=function(t){var e,r,n,i,a=this.traceHash,o=t.slice().sort((function(t,e){return w[t[0].trace.type]-w[e[0].trace.type]}));for(n=0;n<o.length;n++){var s=o[n],l=!1;(e=a[(r=s[0].trace).uid])&&(e.type===r.type?(e.update(s),l=!0):e.dispose()),!l&&r._module&&(a[r.uid]=r._module.plot(this,s))}var c=Object.keys(a);t:for(n=0;n<c.length;n++){var u=c[n];for(i=0;i<t.length;i++)if(u===(r=t[i][0].trace).uid)continue t;(e=a[u]).dispose(),delete a[u]}},_.updateLayout=function(t){var e=this.map,r=t[this.id];this.dragging||this.wheeling||(e.setCenter(A(r.center)),e.setZoom(r.zoom),e.setBearing(r.bearing),e.setPitch(r.pitch)),this.updateLayers(t),this.updateFramework(t),this.updateFx(t),this.map.resize(),this.gd._context._scrollZoom.mapbox?e.scrollZoom.enable():e.scrollZoom.disable()},_.resolveOnRender=function(t){var e=this.map;e.on("render",(function r(){e.loaded()&&(e.off("render",r),setTimeout(t,10))}))},_.rejectOnError=function(t){var e=this.map;function r(){t(new Error(y.mapOnErrorMsg))}e.once("error",r),e.once("style.error",r),e.once("source.error",r),e.once("tile.error",r),e.once("layer.error",r)},_.createFramework=function(t){var e=this,r=e.div=document.createElement("div");r.id=e.uid,r.style.position="absolute",e.container.appendChild(r),e.xaxis={_id:"x",c2p:function(t){return e.project(t).x}},e.yaxis={_id:"y",c2p:function(t){return e.project(t).y}},e.updateFramework(t),e.mockAxis={type:"linear",showexponent:"all",exponentformat:"B"},s.setConvert(e.mockAxis,t)},_.initFx=function(t,e){var r=this,n=r.gd,i=r.map;function a(){c.loneUnhover(e._hoverlayer)}function s(){var t=r.getView();n.emit("plotly_relayouting",r.getViewEditsWithDerived(t))}i.on("moveend",(function(t){if(r.map){var e=n._fullLayout;if(t.originalEvent||r.wheeling){var i=e[r.id];o.call("_storeDirectGUIEdit",n.layout,e._preGUI,r.getViewEdits(i));var a=r.getView();i._input.center=i.center=a.center,i._input.zoom=i.zoom=a.zoom,i._input.bearing=i.bearing=a.bearing,i._input.pitch=i.pitch=a.pitch,n.emit("plotly_relayout",r.getViewEditsWithDerived(a))}t.originalEvent&&"mouseup"===t.originalEvent.type?r.dragging=!1:r.wheeling&&(r.wheeling=!1),e._rehover&&e._rehover()}})),i.on("wheel",(function(){r.wheeling=!0})),i.on("mousemove",(function(t){var e=r.div.getBoundingClientRect(),a=[t.originalEvent.offsetX,t.originalEvent.offsetY];t.target.getBoundingClientRect=function(){return e},r.xaxis.p2c=function(){return i.unproject(a).lng},r.yaxis.p2c=function(){return i.unproject(a).lat},n._fullLayout._rehover=function(){n._fullLayout._hoversubplot===r.id&&n._fullLayout[r.id]&&c.hover(n,t,r.id)},c.hover(n,t,r.id),n._fullLayout._hoversubplot=r.id})),i.on("dragstart",(function(){r.dragging=!0,a()})),i.on("zoomstart",a),i.on("mouseout",(function(){n._fullLayout._hoversubplot=null})),i.on("drag",s),i.on("zoom",s),i.on("dblclick",(function(){var t=n._fullLayout[r.id];o.call("_storeDirectGUIEdit",n.layout,n._fullLayout._preGUI,r.getViewEdits(t));var e=r.viewInitial;i.setCenter(A(e.center)),i.setZoom(e.zoom),i.setBearing(e.bearing),i.setPitch(e.pitch);var a=r.getView();t._input.center=t.center=a.center,t._input.zoom=t.zoom=a.zoom,t._input.bearing=t.bearing=a.bearing,t._input.pitch=t.pitch=a.pitch,n.emit("plotly_doubleclick",null),n.emit("plotly_relayout",r.getViewEditsWithDerived(a))})),r.clearSelect=function(){g(r.dragOptions),m(r.dragOptions.gd)},r.onClickInPanFn=function(t){return function(e){var i=n._fullLayout.clickmode;i.indexOf("select")>-1&&v(e.originalEvent,n,[r.xaxis],[r.yaxis],r.id,t),i.indexOf("event")>-1&&c.click(n,e.originalEvent)}}},_.updateFx=function(t){var e=this,r=e.map,n=e.gd;if(!e.isStatic){var a,o=t.dragmode;a=f(o)?function(t,r){(t.range={})[e.id]=[c([r.xmin,r.ymin]),c([r.xmax,r.ymax])]}:function(t,r,n){(t.lassoPoints={})[e.id]=n.filtered.map(c)};var s=e.dragOptions;e.dragOptions=i.extendDeep(s||{},{dragmode:t.dragmode,element:e.div,gd:n,plotinfo:{id:e.id,domain:t[e.id].domain,xaxis:e.xaxis,yaxis:e.yaxis,fillRangeItems:a},xaxes:[e.xaxis],yaxes:[e.yaxis],subplot:e.id}),r.off("click",e.onClickInPanHandler),p(o)||h(o)?(r.dragPan.disable(),r.on("zoomstart",e.clearSelect),e.dragOptions.prepFn=function(t,r,n){d(t,r,n,e.dragOptions,o)},l.init(e.dragOptions)):(r.dragPan.enable(),r.off("zoomstart",e.clearSelect),e.div.onmousedown=null,e.onClickInPanHandler=e.onClickInPanFn(e.dragOptions),r.on("click",e.onClickInPanHandler))}function c(t){var r=e.map.unproject(t);return[r.lng,r.lat]}},_.updateFramework=function(t){var e=t[this.id].domain,r=t._size,n=this.div.style;n.width=r.w*(e.x[1]-e.x[0])+"px",n.height=r.h*(e.y[1]-e.y[0])+"px",n.left=r.l+e.x[0]*r.w+"px",n.top=r.t+(1-e.y[1])*r.h+"px",this.xaxis._offset=r.l+e.x[0]*r.w,this.xaxis._length=r.w*(e.x[1]-e.x[0]),this.yaxis._offset=r.t+(1-e.y[1])*r.h,this.yaxis._length=r.h*(e.y[1]-e.y[0])},_.updateLayers=function(t){var e,r=t[this.id].layers,n=this.layerList;if(r.length!==n.length){for(e=0;e<n.length;e++)n[e].dispose();for(n=this.layerList=[],e=0;e<r.length;e++)n.push(x(this,e,r[e]))}else for(e=0;e<r.length;e++)n[e].update(r[e])},_.destroy=function(){this.map&&(this.map.remove(),this.map=null,this.container.removeChild(this.div))},_.toImage=function(){return this.map.stop(),this.map.getCanvas().toDataURL()},_.setOptions=function(t,e,r){for(var n in r)this.map[e](t,n,r[n])},_.getMapLayers=function(){return this.map.getStyle().layers},_.addLayer=function(t,e){var r=this.map;if("string"==typeof e){if(""===e)return void r.addLayer(t,e);for(var n=this.getMapLayers(),a=0;a<n.length;a++)if(e===n[a].id)return void r.addLayer(t,e);i.warn(["Trying to add layer with *below* value",e,"referencing a layer that does not exist","or that does not yet exist."].join(" "))}r.addLayer(t)},_.project=function(t){return this.map.project(new n.LngLat(t[0],t[1]))},_.getView=function(){var t=this.map,e=t.getCenter(),r={lon:e.lng,lat:e.lat},n=t.getCanvas(),i=parseInt(n.style.width),a=parseInt(n.style.height);return{center:r,zoom:t.getZoom(),bearing:t.getBearing(),pitch:t.getPitch(),_derived:{coordinates:[t.unproject([0,0]).toArray(),t.unproject([i,0]).toArray(),t.unproject([i,a]).toArray(),t.unproject([0,a]).toArray()]}}},_.getViewEdits=function(t){for(var e=this.id,r=["center","zoom","bearing","pitch"],n={},i=0;i<r.length;i++){var a=r[i];n[e+"."+a]=t[a]}return n},_.getViewEditsWithDerived=function(t){var e=this.id,r=this.getViewEdits(t);return r[e+"._derived"]=t._derived,r},e.exports=b},{"../../components/dragelement":385,"../../components/dragelement/helpers":384,"../../components/fx":406,"../../lib":503,"../../lib/geo_location_utils":496,"../../registry":638,"../cartesian/axes":554,"../cartesian/select":575,"./constants":611,"./layers":614,"mapbox-gl/dist/mapbox-gl-unminified":239}],618:[function(t,e,r){"use strict";e.exports=function(t){var e=t.editType;return{t:{valType:"number",dflt:0,editType:e},r:{valType:"number",dflt:0,editType:e},b:{valType:"number",dflt:0,editType:e},l:{valType:"number",dflt:0,editType:e},editType:e}}},{}],619:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("d3-time-format").timeFormatLocale,a=t("d3-format").formatLocale,o=t("fast-isnumeric"),s=t("../registry"),l=t("../plot_api/plot_schema"),c=t("../plot_api/plot_template"),u=t("../lib"),f=t("../components/color"),h=t("../constants/numerical").BADNUM,p=t("./cartesian/axis_ids"),d=t("./cartesian/handle_outline").clearSelect,m=t("./animation_attributes"),g=t("./frame_attributes"),v=t("../plots/get_data").getModuleCalcData,y=u.relinkPrivateKeys,x=u._,b=e.exports={};u.extendFlat(b,s),b.attributes=t("./attributes"),b.attributes.type.values=b.allTypes,b.fontAttrs=t("./font_attributes"),b.layoutAttributes=t("./layout_attributes"),b.fontWeight="normal";var _=b.transformsRegistry,w=t("./command");b.executeAPICommand=w.executeAPICommand,b.computeAPICommandBindings=w.computeAPICommandBindings,b.manageCommandObserver=w.manageCommandObserver,b.hasSimpleAPICommandBindings=w.hasSimpleAPICommandBindings,b.redrawText=function(t){return t=u.getGraphDiv(t),new Promise((function(e){setTimeout((function(){t._fullLayout&&(s.getComponentMethod("annotations","draw")(t),s.getComponentMethod("legend","draw")(t),s.getComponentMethod("colorbar","draw")(t),e(b.previousPromises(t)))}),300)}))},b.resize=function(t){var e;t=u.getGraphDiv(t);var r=new Promise((function(r,n){t&&!u.isHidden(t)||n(new Error("Resize must be passed a displayed plot div element.")),t._redrawTimer&&clearTimeout(t._redrawTimer),t._resolveResize&&(e=t._resolveResize),t._resolveResize=r,t._redrawTimer=setTimeout((function(){if(!t.layout||t.layout.width&&t.layout.height||u.isHidden(t))r(t);else{delete t.layout.width,delete t.layout.height;var e=t.changed;t.autoplay=!0,s.call("relayout",t,{autosize:!0}).then((function(){t.changed=e,t._resolveResize===r&&(delete t._resolveResize,r(t))}))}}),100)}));return e&&e(r),r},b.previousPromises=function(t){if((t._promises||[]).length)return Promise.all(t._promises).then((function(){t._promises=[]}))},b.addLinks=function(t){if(t._context.showLink||t._context.showSources){var e=t._fullLayout,r=u.ensureSingle(e._paper,"text","js-plot-link-container",(function(t){t.style({"font-family":'"Open Sans", Arial, sans-serif',"font-size":"12px",fill:f.defaultLine,"pointer-events":"all"}).each((function(){var t=n.select(this);t.append("tspan").classed("js-link-to-tool",!0),t.append("tspan").classed("js-link-spacer",!0),t.append("tspan").classed("js-sourcelinks",!0)}))})),i=r.node(),a={y:e._paper.attr("height")-9};document.body.contains(i)&&i.getComputedTextLength()>=e.width-20?(a["text-anchor"]="start",a.x=5):(a["text-anchor"]="end",a.x=e._paper.attr("width")-7),r.attr(a);var o=r.select(".js-link-to-tool"),s=r.select(".js-link-spacer"),l=r.select(".js-sourcelinks");t._context.showSources&&t._context.showSources(t),t._context.showLink&&function(t,e){e.text("");var r=e.append("a").attr({"xlink:xlink:href":"#",class:"link--impt link--embedview","font-weight":"bold"}).text(t._context.linkText+" "+String.fromCharCode(187));if(t._context.sendData)r.on("click",(function(){b.sendDataToCloud(t)}));else{var n=window.location.pathname.split("/"),i=window.location.search;r.attr({"xlink:xlink:show":"new","xlink:xlink:href":"/"+n[2].split(".")[0]+"/"+n[1]+i})}}(t,o),s.text(o.text()&&l.text()?" - ":"")}},b.sendDataToCloud=function(t){var e=(window.PLOTLYENV||{}).BASE_URL||t._context.plotlyServerURL;if(e){t.emit("plotly_beforeexport");var r=n.select(t).append("div").attr("id","hiddenform").style("display","none"),i=r.append("form").attr({action:e+"/external",method:"post",target:"_blank"});return i.append("input").attr({type:"text",name:"data"}).node().value=b.graphJson(t,!1,"keepdata"),i.node().submit(),r.remove(),t.emit("plotly_afterexport"),!1}};var T=["days","shortDays","months","shortMonths","periods","dateTime","date","time","decimal","thousands","grouping","currency"],k=["year","month","dayMonth","dayMonthYear"];function A(t,e){var r=t._context.locale;r||(r="en-US");var n=!1,i={};function a(t){for(var r=!0,a=0;a<e.length;a++){var o=e[a];i[o]||(t[o]?i[o]=t[o]:r=!1)}r&&(n=!0)}for(var o=0;o<2;o++){for(var l=t._context.locales,c=0;c<2;c++){var u=(l[r]||{}).format;if(u&&(a(u),n))break;l=s.localeRegistry}var f=r.split("-")[0];if(n||f===r)break;r=f}return n||a(s.localeRegistry.en.format),i}function M(t,e){var r={_fullLayout:e},n="x"===t._id.charAt(0),i=t._mainAxis._anchorAxis,a="",o="",s="";if(i&&(s=i._mainAxis._id,a=n?t._id+s:s+t._id),!a||!e._plots[a]){a="";for(var l=t._counterAxes,c=0;c<l.length;c++){var u=l[c],f=n?t._id+u:u+t._id;o||(o=f);var h=p.getFromId(r,u);if(s&&h.overlaying===s){a=f;break}}}return a||o}function S(t){var e=t.transforms;if(Array.isArray(e)&&e.length)for(var r=0;r<e.length;r++){var n=e[r],i=n._module||_[n.type];if(i&&i.makesData)return!0}return!1}function E(t,e,r,n){for(var i=t.transforms,a=[t],o=0;o<i.length;o++){var s=i[o],l=_[s.type];l&&l.transform&&(a=l.transform(a,{transform:s,fullTrace:t,fullData:e,layout:r,fullLayout:n,transformIndex:o}))}return a}function L(t){return"string"==typeof t&&"px"===t.substr(t.length-2)&&parseFloat(t)}function C(t){var e=t.margin;if(!t._size){var r=t._size={l:Math.round(e.l),r:Math.round(e.r),t:Math.round(e.t),b:Math.round(e.b),p:Math.round(e.pad)};r.w=Math.round(t.width)-r.l-r.r,r.h=Math.round(t.height)-r.t-r.b}t._pushmargin||(t._pushmargin={}),t._pushmarginIds||(t._pushmarginIds={})}b.supplyDefaults=function(t,e){var r=e&&e.skipUpdateCalc,n=t._fullLayout||{};if(n._skipDefaults)delete n._skipDefaults;else{var o,l=t._fullLayout={},c=t.layout||{},f=t._fullData||[],h=t._fullData=[],p=t.data||[],m=t.calcdata||[],g=t._context||{};t._transitionData||b.createTransitionData(t),l._dfltTitle={plot:x(t,"Click to enter Plot title"),x:x(t,"Click to enter X axis title"),y:x(t,"Click to enter Y axis title"),colorbar:x(t,"Click to enter Colorscale title"),annotation:x(t,"new text")},l._traceWord=x(t,"trace");var v=A(t,T);if(l._mapboxAccessToken=g.mapboxAccessToken,n._initialAutoSizeIsDone){var _=n.width,w=n.height;b.supplyLayoutGlobalDefaults(c,l,v),c.width||(l.width=_),c.height||(l.height=w),b.sanitizeMargins(l)}else{b.supplyLayoutGlobalDefaults(c,l,v);var M=!c.width||!c.height,S=l.autosize,E=g.autosizable;M&&(S||E)?b.plotAutoSize(t,c,l):M&&b.sanitizeMargins(l),!S&&M&&(c.width=l.width,c.height=l.height)}l._d3locale=function(t,e){return t.decimal=e.charAt(0),t.thousands=e.charAt(1),{numberFormat:function(e){try{e=a(t).format(u.adjustFormat(e))}catch(t){return u.warnBadFormat(e),u.noFormat}return e},timeFormat:i(t).utcFormat}}(v,l.separators),l._extraFormat=A(t,k),l._initialAutoSizeIsDone=!0,l._dataLength=p.length,l._modules=[],l._visibleModules=[],l._basePlotModules=[];var L=l._subplots=function(){var t,e,r=s.collectableSubplotTypes,n={};if(!r){r=[];var i=s.subplotsRegistry;for(var a in i){var o=i[a].attr;if(o&&(r.push(a),Array.isArray(o)))for(e=0;e<o.length;e++)u.pushUnique(r,o[e])}}for(t=0;t<r.length;t++)n[r[t]]=[];return n}(),P=l._splomAxes={x:{},y:{}},I=l._splomSubplots={};l._splomGridDflt={},l._scatterStackOpts={},l._firstScatter={},l._alignmentOpts={},l._colorAxes={},l._requestRangeslider={},l._traceUids=function(t,e){var r,n,i=e.length,a=[];for(r=0;r<t.length;r++){var o=t[r]._fullInput;o!==n&&a.push(o),n=o}var s=a.length,l=new Array(i),c={};function f(t,e){l[e]=t,c[t]=1}function h(t,e){if(t&&"string"==typeof t&&!c[t])return f(t,e),!0}for(r=0;r<i;r++){var p=e[r].uid;"number"==typeof p&&(p=String(p)),h(p,r)||(r<s&&h(a[r].uid,r)||f(u.randstr(c),r))}return l}(f,p),l._globalTransforms=(t._context||{}).globalTransforms,b.supplyDataDefaults(p,h,c,l);var O=Object.keys(P.x),z=Object.keys(P.y);if(O.length>1&&z.length>1){for(s.getComponentMethod("grid","sizeDefaults")(c,l),o=0;o<O.length;o++)u.pushUnique(L.xaxis,O[o]);for(o=0;o<z.length;o++)u.pushUnique(L.yaxis,z[o]);for(var D in I)u.pushUnique(L.cartesian,D)}if(l._has=b._hasPlotType.bind(l),f.length===h.length)for(o=0;o<h.length;o++)y(h[o],f[o]);b.supplyLayoutModuleDefaults(c,l,h,t._transitionData);var R=l._visibleModules,F=[];for(o=0;o<R.length;o++){var B=R[o].crossTraceDefaults;B&&u.pushUnique(F,B)}for(o=0;o<F.length;o++)F[o](h,l);l._hasOnlyLargeSploms=1===l._basePlotModules.length&&"splom"===l._basePlotModules[0].name&&O.length>15&&z.length>15&&0===l.shapes.length&&0===l.images.length,b.linkSubplots(h,l,f,n),b.cleanPlot(h,l,f,n);var N=!(!n._has||!n._has("gl2d")),j=!(!l._has||!l._has("gl2d")),U=!(!n._has||!n._has("cartesian"))||N,V=!(!l._has||!l._has("cartesian"))||j;U&&!V?n._bgLayer.remove():V&&!U&&(l._shouldCreateBgLayer=!0),n._zoomlayer&&!t._dragging&&d({_fullLayout:n}),function(t,e){var r,n=[];e.meta&&(r=e._meta={meta:e.meta,layout:{meta:e.meta}});for(var i=0;i<t.length;i++){var a=t[i];a.meta?n[a.index]=a._meta={meta:a.meta}:e.meta&&(a._meta={meta:e.meta}),e.meta&&(a._meta.layout={meta:e.meta})}n.length&&(r||(r=e._meta={}),r.data=n)}(h,l),y(l,n),s.getComponentMethod("colorscale","crossTraceDefaults")(h,l),l._preGUI||(l._preGUI={}),l._tracePreGUI||(l._tracePreGUI={});var H,q=l._tracePreGUI,G={};for(H in q)G[H]="old";for(o=0;o<h.length;o++)G[H=h[o]._fullInput.uid]||(q[H]={}),G[H]="new";for(H in G)"old"===G[H]&&delete q[H];C(l),s.getComponentMethod("rangeslider","makeData")(l),r||m.length!==h.length||b.supplyDefaultsUpdateCalc(m,h)}},b.supplyDefaultsUpdateCalc=function(t,e){for(var r=0;r<e.length;r++){var n=e[r],i=(t[r]||[])[0];if(i&&i.trace){var a=i.trace;if(a._hasCalcTransform){var o,s,l,c=a._arrayAttrs;for(o=0;o<c.length;o++)s=c[o],l=u.nestedProperty(a,s).get().slice(),u.nestedProperty(n,s).set(l)}i.trace=n}}},b.createTransitionData=function(t){t._transitionData||(t._transitionData={}),t._transitionData._frames||(t._transitionData._frames=[]),t._transitionData._frameHash||(t._transitionData._frameHash={}),t._transitionData._counter||(t._transitionData._counter=0),t._transitionData._interruptCallbacks||(t._transitionData._interruptCallbacks=[])},b._hasPlotType=function(t){var e,r=this._basePlotModules||[];for(e=0;e<r.length;e++)if(r[e].name===t)return!0;var n=this._modules||[];for(e=0;e<n.length;e++){var i=n[e].name;if(i===t)return!0;var a=s.modules[i];if(a&&a.categories[t])return!0}return!1},b.cleanPlot=function(t,e,r,n){var i,a,o=n._basePlotModules||[];for(i=0;i<o.length;i++){var s=o[i];s.clean&&s.clean(t,e,r,n)}var l=n._has&&n._has("gl"),c=e._has&&e._has("gl");l&&!c&&void 0!==n._glcontainer&&(n._glcontainer.selectAll(".gl-canvas").remove(),n._glcontainer.selectAll(".no-webgl").remove(),n._glcanvas=null);var u=!!n._infolayer;t:for(i=0;i<r.length;i++){var f=r[i].uid;for(a=0;a<t.length;a++){if(f===t[a].uid)continue t}u&&n._infolayer.select(".cb"+f).remove()}},b.linkSubplots=function(t,e,r,n){var i,a,o=n._plots||{},l=e._plots={},c=e._subplots,f={_fullData:t,_fullLayout:e},h=c.cartesian.concat(c.gl2d||[]);for(i=0;i<h.length;i++){var d,m=h[i],g=o[m],v=p.getFromId(f,m,"x"),y=p.getFromId(f,m,"y");for(g?d=l[m]=g:(d=l[m]={}).id=m,v._counterAxes.push(y._id),y._counterAxes.push(v._id),v._subplotsWith.push(m),y._subplotsWith.push(m),d.xaxis=v,d.yaxis=y,d._hasClipOnAxisFalse=!1,a=0;a<t.length;a++){var x=t[a];if(x.xaxis===d.xaxis._id&&x.yaxis===d.yaxis._id&&!1===x.cliponaxis){d._hasClipOnAxisFalse=!0;break}}}var b,_=p.list(f,null,!0);for(i=0;i<_.length;i++){var w=null;(b=_[i]).overlaying&&(w=p.getFromId(f,b.overlaying))&&w.overlaying&&(b.overlaying=!1,w=null),b._mainAxis=w||b,w&&(b.domain=w.domain.slice()),b._anchorAxis="free"===b.anchor?null:p.getFromId(f,b.anchor)}for(i=0;i<_.length;i++)if((b=_[i])._counterAxes.sort(p.idSort),b._subplotsWith.sort(u.subplotSort),b._mainSubplot=M(b,e),b._counterAxes.length&&(b.spikemode&&-1!==b.spikemode.indexOf("across")||b.automargin&&b.mirror&&"free"!==b.anchor||s.getComponentMethod("rangeslider","isVisible")(b))){var T=1,k=0;for(a=0;a<b._counterAxes.length;a++){var A=p.getFromId(f,b._counterAxes[a]);T=Math.min(T,A.domain[0]),k=Math.max(k,A.domain[1])}T<k&&(b._counterDomainMin=T,b._counterDomainMax=k)}},b.clearExpandedTraceDefaultColors=function(t){var e,r,n;for(r=[],(e=t._module._colorAttrs)||(t._module._colorAttrs=e=[],l.crawl(t._module.attributes,(function(t,n,i,a){r[a]=n,r.length=a+1,"color"===t.valType&&void 0===t.dflt&&e.push(r.join("."))}))),n=0;n<e.length;n++){u.nestedProperty(t,"_input."+e[n]).get()||u.nestedProperty(t,e[n]).set(null)}},b.supplyDataDefaults=function(t,e,r,n){var i,a,o,l=n._modules,f=n._visibleModules,h=n._basePlotModules,p=0,d=0;function m(t){e.push(t);var r=t._module;r&&(u.pushUnique(l,r),!0===t.visible&&u.pushUnique(f,r),u.pushUnique(h,t._module.basePlotModule),p++,!1!==t._input.visible&&d++)}n._transformModules=[];var g={},v=[],x=(r.template||{}).data||{},_=c.traceTemplater(x);for(i=0;i<t.length;i++){if(o=t[i],(a=_.newTrace(o)).uid=n._traceUids[i],b.supplyTraceDefaults(o,a,d,n,i),a.index=i,a._input=o,a._expandedIndex=p,a.transforms&&a.transforms.length)for(var w=!1!==o.visible&&!1===a.visible,T=E(a,e,r,n),k=0;k<T.length;k++){var A=T[k],M={_template:a._template,type:a.type,uid:a.uid+k};w&&!1===A.visible&&delete A.visible,b.supplyTraceDefaults(A,M,p,n,i),y(M,A),M.index=i,M._input=o,M._fullInput=a,M._expandedIndex=p,M._expandedInput=A,m(M)}else a._fullInput=a,a._expandedInput=a,m(a);s.traceIs(a,"carpetAxis")&&(g[a.carpet]=a),s.traceIs(a,"carpetDependent")&&v.push(i)}for(i=0;i<v.length;i++)if((a=e[v[i]]).visible){var S=g[a.carpet];a._carpet=S,S&&S.visible?(a.xaxis=S.xaxis,a.yaxis=S.yaxis):a.visible=!1}},b.supplyAnimationDefaults=function(t){var e;t=t||{};var r={};function n(e,n){return u.coerce(t||{},r,m,e,n)}if(n("mode"),n("direction"),n("fromcurrent"),Array.isArray(t.frame))for(r.frame=[],e=0;e<t.frame.length;e++)r.frame[e]=b.supplyAnimationFrameDefaults(t.frame[e]||{});else r.frame=b.supplyAnimationFrameDefaults(t.frame||{});if(Array.isArray(t.transition))for(r.transition=[],e=0;e<t.transition.length;e++)r.transition[e]=b.supplyAnimationTransitionDefaults(t.transition[e]||{});else r.transition=b.supplyAnimationTransitionDefaults(t.transition||{});return r},b.supplyAnimationFrameDefaults=function(t){var e={};function r(r,n){return u.coerce(t||{},e,m.frame,r,n)}return r("duration"),r("redraw"),e},b.supplyAnimationTransitionDefaults=function(t){var e={};function r(r,n){return u.coerce(t||{},e,m.transition,r,n)}return r("duration"),r("easing"),e},b.supplyFrameDefaults=function(t){var e={};function r(r,n){return u.coerce(t,e,g,r,n)}return r("group"),r("name"),r("traces"),r("baseframe"),r("data"),r("layout"),e},b.supplyTraceDefaults=function(t,e,r,n,i){var a,o=n.colorway||f.defaults,l=o[r%o.length];function c(r,n){return u.coerce(t,e,b.attributes,r,n)}var h=c("visible");c("type"),c("name",n._traceWord+" "+i),c("uirevision",n.uirevision);var p=b.getModule(e);if(e._module=p,p){var d=p.basePlotModule,m=d.attr,g=d.attributes;if(m&&g){var v=n._subplots,y="";if(h||"gl2d"!==d.name){if(Array.isArray(m))for(a=0;a<m.length;a++){var x=m[a],_=u.coerce(t,e,g,x);v[x]&&u.pushUnique(v[x],_),y+=_}else y=u.coerce(t,e,g,m);v[d.name]&&u.pushUnique(v[d.name],y)}}}return h&&(c("customdata"),c("ids"),c("meta"),s.traceIs(e,"showLegend")?(u.coerce(t,e,p.attributes.showlegend?p.attributes:b.attributes,"showlegend"),c("legendgroup"),c("legendgrouptitle.text"),c("legendrank"),e._dfltShowLegend=!0):e._dfltShowLegend=!1,p&&p.supplyDefaults(t,e,l,n),s.traceIs(e,"noOpacity")||c("opacity"),s.traceIs(e,"notLegendIsolatable")&&(e.visible=!!e.visible),s.traceIs(e,"noHover")||(e.hovertemplate||u.coerceHoverinfo(t,e,n),"parcats"!==e.type&&s.getComponentMethod("fx","supplyDefaults")(t,e,l,n)),p&&p.selectPoints&&c("selectedpoints"),b.supplyTransformDefaults(t,e,n)),e},b.hasMakesDataTransform=S,b.supplyTransformDefaults=function(t,e,r){if(e._length||S(t)){var n=r._globalTransforms||[],i=r._transformModules||[];if(Array.isArray(t.transforms)||0!==n.length)for(var a=t.transforms||[],o=n.concat(a),s=e.transforms=[],l=0;l<o.length;l++){var c,f=o[l],h=f.type,p=_[h],d=!(f._module&&f._module===p),m=p&&"function"==typeof p.transform;p||u.warn("Unrecognized transform type "+h+"."),p&&p.supplyDefaults&&(d||m)?((c=p.supplyDefaults(f,e,r,t)).type=h,c._module=p,u.pushUnique(i,p)):c=u.extendFlat({},f),s.push(c)}}},b.supplyLayoutGlobalDefaults=function(t,e,r){function n(r,n){return u.coerce(t,e,b.layoutAttributes,r,n)}var i=t.template;u.isPlainObject(i)&&(e.template=i,e._template=i.layout,e._dataTemplate=i.data),n("autotypenumbers");var a=u.coerceFont(n,"font"),o=a.size;u.coerceFont(n,"title.font",u.extendFlat({},a,{size:Math.round(1.4*o)})),n("title.text",e._dfltTitle.plot),n("title.xref"),n("title.yref"),n("title.x"),n("title.y"),n("title.xanchor"),n("title.yanchor"),n("title.pad.t"),n("title.pad.r"),n("title.pad.b"),n("title.pad.l"),n("uniformtext.mode")&&n("uniformtext.minsize"),n("autosize",!(t.width&&t.height)),n("width"),n("height"),n("margin.l"),n("margin.r"),n("margin.t"),n("margin.b"),n("margin.pad"),n("margin.autoexpand"),t.width&&t.height&&b.sanitizeMargins(e),s.getComponentMethod("grid","sizeDefaults")(t,e),n("paper_bgcolor"),n("separators",r.decimal+r.thousands),n("hidesources"),n("colorway"),n("datarevision");var l=n("uirevision");n("editrevision",l),n("selectionrevision",l),s.getComponentMethod("modebar","supplyLayoutDefaults")(t,e),s.getComponentMethod("shapes","supplyDrawNewShapeDefaults")(t,e,n),n("meta"),u.isPlainObject(t.transition)&&(n("transition.duration"),n("transition.easing"),n("transition.ordering")),s.getComponentMethod("calendars","handleDefaults")(t,e,"calendar"),s.getComponentMethod("fx","supplyLayoutGlobalDefaults")(t,e,n)},b.plotAutoSize=function(t,e,r){var n,i,a=t._context||{},s=a.frameMargins,l=u.isPlotDiv(t);if(l&&t.emit("plotly_autosize"),a.fillFrame)n=window.innerWidth,i=window.innerHeight,document.body.style.overflow="hidden";else{var c=l?window.getComputedStyle(t):{};if(n=L(c.width)||L(c.maxWidth)||r.width,i=L(c.height)||L(c.maxHeight)||r.height,o(s)&&s>0){var f=1-2*s;n=Math.round(f*n),i=Math.round(f*i)}}var h=b.layoutAttributes.width.min,p=b.layoutAttributes.height.min;n<h&&(n=h),i<p&&(i=p);var d=!e.width&&Math.abs(r.width-n)>1,m=!e.height&&Math.abs(r.height-i)>1;(m||d)&&(d&&(r.width=n),m&&(r.height=i)),t._initialAutoSize||(t._initialAutoSize={width:n,height:i}),b.sanitizeMargins(r)},b.supplyLayoutModuleDefaults=function(t,e,r,n){var i,a,o,l=s.componentsRegistry,c=e._basePlotModules,f=s.subplotsRegistry.cartesian;for(i in l)(o=l[i]).includeBasePlot&&o.includeBasePlot(t,e);for(var h in c.length||c.push(f),e._has("cartesian")&&(s.getComponentMethod("grid","contentDefaults")(t,e),f.finalizeSubplots(t,e)),e._subplots)e._subplots[h].sort(u.subplotSort);for(a=0;a<c.length;a++)(o=c[a]).supplyLayoutDefaults&&o.supplyLayoutDefaults(t,e,r);var p=e._modules;for(a=0;a<p.length;a++)(o=p[a]).supplyLayoutDefaults&&o.supplyLayoutDefaults(t,e,r);var d=e._transformModules;for(a=0;a<d.length;a++)(o=d[a]).supplyLayoutDefaults&&o.supplyLayoutDefaults(t,e,r,n);for(i in l)(o=l[i]).supplyLayoutDefaults&&o.supplyLayoutDefaults(t,e,r)},b.purge=function(t){var e=t._fullLayout||{};void 0!==e._glcontainer&&(e._glcontainer.selectAll(".gl-canvas").remove(),e._glcontainer.remove(),e._glcanvas=null),e._modeBar&&e._modeBar.destroy(),t._transitionData&&(t._transitionData._interruptCallbacks&&(t._transitionData._interruptCallbacks.length=0),t._transitionData._animationRaf&&window.cancelAnimationFrame(t._transitionData._animationRaf)),u.clearThrottle(),u.clearResponsive(t),delete t.data,delete t.layout,delete t._fullData,delete t._fullLayout,delete t.calcdata,delete t.empty,delete t.fid,delete t.undoqueue,delete t.undonum,delete t.autoplay,delete t.changed,delete t._promises,delete t._redrawTimer,delete t._hmlumcount,delete t._hmpixcount,delete t._transitionData,delete t._transitioning,delete t._initialAutoSize,delete t._transitioningWithDuration,delete t._dragging,delete t._dragged,delete t._dragdata,delete t._hoverdata,delete t._snapshotInProgress,delete t._editing,delete t._mouseDownTime,delete t._legendMouseDownTime,t.removeAllListeners&&t.removeAllListeners()},b.style=function(t){var e,r=t._fullLayout._visibleModules,n=[];for(e=0;e<r.length;e++){var i=r[e];i.style&&u.pushUnique(n,i.style)}for(e=0;e<n.length;e++)n[e](t)},b.sanitizeMargins=function(t){if(t&&t.margin){var e,r=t.width,n=t.height,i=t.margin,a=r-(i.l+i.r),o=n-(i.t+i.b);a<0&&(e=(r-1)/(i.l+i.r),i.l=Math.floor(e*i.l),i.r=Math.floor(e*i.r)),o<0&&(e=(n-1)/(i.t+i.b),i.t=Math.floor(e*i.t),i.b=Math.floor(e*i.b))}},b.clearAutoMarginIds=function(t){t._fullLayout._pushmarginIds={}},b.allowAutoMargin=function(t,e){t._fullLayout._pushmarginIds[e]=1};b.autoMargin=function(t,e,r){var n=t._fullLayout,i=n.width,a=n.height,o=n.margin,s=u.constrain(i-o.l-o.r,2,64),l=u.constrain(a-o.t-o.b,2,64),c=Math.max(0,i-s),f=Math.max(0,a-l),h=n._pushmargin,p=n._pushmarginIds;if(!1!==o.autoexpand){if(r){var d=r.pad;if(void 0===d&&(d=Math.min(12,o.l,o.r,o.t,o.b)),c){var m=(r.l+r.r)/c;m>1&&(r.l/=m,r.r/=m)}if(f){var g=(r.t+r.b)/f;g>1&&(r.t/=g,r.b/=g)}var v=void 0!==r.xl?r.xl:r.x,y=void 0!==r.xr?r.xr:r.x,x=void 0!==r.yt?r.yt:r.y,_=void 0!==r.yb?r.yb:r.y;h[e]={l:{val:v,size:r.l+d},r:{val:y,size:r.r+d},b:{val:_,size:r.b+d},t:{val:x,size:r.t+d}},p[e]=1}else delete h[e],delete p[e];if(!n._replotting)return b.doAutoMargin(t)}},b.doAutoMargin=function(t){var e=t._fullLayout,r=e.width,n=e.height;e._size||(e._size={}),C(e);var i=e._size,a=e.margin,l=u.extendFlat({},i),c=a.l,f=a.r,h=a.t,d=a.b,m=e._pushmargin,g=e._pushmarginIds;if(!1!==e.margin.autoexpand){for(var v in m)g[v]||delete m[v];for(var y in m.base={l:{val:0,size:c},r:{val:1,size:f},t:{val:1,size:h},b:{val:0,size:d}},m){var x=m[y].l||{},_=m[y].b||{},w=x.val,T=x.size,k=_.val,A=_.size;for(var M in m){if(o(T)&&m[M].r){var S=m[M].r.val,E=m[M].r.size;if(S>w){var L=(T*S+(E-r)*w)/(S-w),P=(E*(1-w)+(T-r)*(1-S))/(S-w);L+P>c+f&&(c=L,f=P)}}if(o(A)&&m[M].t){var I=m[M].t.val,O=m[M].t.size;if(I>k){var z=(A*I+(O-n)*k)/(I-k),D=(O*(1-k)+(A-n)*(1-I))/(I-k);z+D>d+h&&(d=z,h=D)}}}}}var R=u.constrain(r-a.l-a.r,2,64),F=u.constrain(n-a.t-a.b,2,64),B=Math.max(0,r-R),N=Math.max(0,n-F);if(B){var j=(c+f)/B;j>1&&(c/=j,f/=j)}if(N){var U=(d+h)/N;U>1&&(d/=U,h/=U)}if(i.l=Math.round(c),i.r=Math.round(f),i.t=Math.round(h),i.b=Math.round(d),i.p=Math.round(a.pad),i.w=Math.round(r)-i.l-i.r,i.h=Math.round(n)-i.t-i.b,!e._replotting&&b.didMarginChange(l,i)){"_redrawFromAutoMarginCount"in e?e._redrawFromAutoMarginCount++:e._redrawFromAutoMarginCount=1;var V=3*(1+Object.keys(g).length);if(e._redrawFromAutoMarginCount<V)return s.call("_doPlot",t);e._size=l,u.warn("Too many auto-margin redraws.")}!function(t){var e=p.list(t,"",!0);["_adjustTickLabelsOverflow","_hideCounterAxisInsideTickLabels"].forEach((function(t){for(var r=0;r<e.length;r++){var n=e[r][t];n&&n()}}))}(t)};var P=["l","r","t","b","p","w","h"];function I(t,e,r){var n=!1;var i=[b.previousPromises,function(){if(t._transitionData)return t._transitioning=!1,function(t){var e=Promise.resolve();if(!t)return e;for(;t.length;)e=e.then(t.shift());return e}(t._transitionData._interruptCallbacks)},r.prepareFn,b.rehover,function(){return t.emit("plotly_transitioning",[]),new Promise((function(i){t._transitioning=!0,e.duration>0&&(t._transitioningWithDuration=!0),t._transitionData._interruptCallbacks.push((function(){n=!0})),r.redraw&&t._transitionData._interruptCallbacks.push((function(){return s.call("redraw",t)})),t._transitionData._interruptCallbacks.push((function(){t.emit("plotly_transitioninterrupted",[])}));var a=0,o=0;function l(){return a++,function(){o++,n||o!==a||function(e){if(!t._transitionData)return;(function(t){if(t)for(;t.length;)t.shift()})(t._transitionData._interruptCallbacks),Promise.resolve().then((function(){if(r.redraw)return s.call("redraw",t)})).then((function(){t._transitioning=!1,t._transitioningWithDuration=!1,t.emit("plotly_transitioned",[])})).then(e)}(i)}}r.runFn(l),setTimeout(l())}))}],a=u.syncOrAsync(i,t);return a&&a.then||(a=Promise.resolve()),a.then((function(){return t}))}b.didMarginChange=function(t,e){for(var r=0;r<P.length;r++){var n=P[r],i=t[n],a=e[n];if(!o(i)||Math.abs(a-i)>1)return!0}return!1},b.graphJson=function(t,e,r,n,i,a){(i&&e&&!t._fullData||i&&!e&&!t._fullLayout)&&b.supplyDefaults(t);var o=i?t._fullData:t.data,s=i?t._fullLayout:t.layout,l=(t._transitionData||{})._frames;function c(t,e){if("function"==typeof t)return e?"_function_":null;if(u.isPlainObject(t)){var n,i={};return Object.keys(t).sort().forEach((function(a){if(-1===["_","["].indexOf(a.charAt(0)))if("function"!=typeof t[a]){if("keepdata"===r){if("src"===a.substr(a.length-3))return}else if("keepstream"===r){if("string"==typeof(n=t[a+"src"])&&n.indexOf(":")>0&&!u.isPlainObject(t.stream))return}else if("keepall"!==r&&"string"==typeof(n=t[a+"src"])&&n.indexOf(":")>0)return;i[a]=c(t[a],e)}else e&&(i[a]="_function")})),i}return Array.isArray(t)?t.map((function(t){return c(t,e)})):u.isTypedArray(t)?u.simpleMap(t,u.identity):u.isJSDate(t)?u.ms2DateTimeLocal(+t):t}var f={data:(o||[]).map((function(t){var r=c(t);return e&&delete r.fit,r}))};if(!e&&(f.layout=c(s),i)){var h=s._size;f.layout.computed={margin:{b:h.b,l:h.l,r:h.r,t:h.t}}}return l&&(f.frames=c(l)),a&&(f.config=c(t._context,!0)),"object"===n?f:JSON.stringify(f)},b.modifyFrames=function(t,e){var r,n,i,a=t._transitionData._frames,o=t._transitionData._frameHash;for(r=0;r<e.length;r++)switch((n=e[r]).type){case"replace":i=n.value;var s=(a[n.index]||{}).name,l=i.name;a[n.index]=o[l]=i,l!==s&&(delete o[s],o[l]=i);break;case"insert":o[(i=n.value).name]=i,a.splice(n.index,0,i);break;case"delete":delete o[(i=a[n.index]).name],a.splice(n.index,1)}return Promise.resolve()},b.computeFrame=function(t,e){var r,n,i,a,o=t._transitionData._frameHash;if(!e)throw new Error("computeFrame must be given a string frame name");var s=o[e.toString()];if(!s)return!1;for(var l=[s],c=[s.name];s.baseframe&&(s=o[s.baseframe.toString()])&&-1===c.indexOf(s.name);)l.push(s),c.push(s.name);for(var u={};s=l.pop();)if(s.layout&&(u.layout=b.extendLayout(u.layout,s.layout)),s.data){if(u.data||(u.data=[]),!(n=s.traces))for(n=[],r=0;r<s.data.length;r++)n[r]=r;for(u.traces||(u.traces=[]),r=0;r<s.data.length;r++)null!=(i=n[r])&&(-1===(a=u.traces.indexOf(i))&&(a=u.data.length,u.traces[a]=i),u.data[a]=b.extendTrace(u.data[a],s.data[r]))}return u},b.recomputeFrameHash=function(t){for(var e=t._transitionData._frameHash={},r=t._transitionData._frames,n=0;n<r.length;n++){var i=r[n];i&&i.name&&(e[i.name]=i)}},b.extendObjectWithContainers=function(t,e,r){var n,i,a,o,s,l,c,f=u.extendDeepNoArrays({},e||{}),h=u.expandObjectPaths(f),p={};if(r&&r.length)for(a=0;a<r.length;a++)void 0===(i=(n=u.nestedProperty(h,r[a])).get())?u.nestedProperty(p,r[a]).set(null):(n.set(null),u.nestedProperty(p,r[a]).set(i));if(t=u.extendDeepNoArrays(t||{},h),r&&r.length)for(a=0;a<r.length;a++)if(l=u.nestedProperty(p,r[a]).get()){for(c=(s=u.nestedProperty(t,r[a])).get(),Array.isArray(c)||(c=[],s.set(c)),o=0;o<l.length;o++){var d=l[o];c[o]=null===d?null:b.extendObjectWithContainers(c[o],d)}s.set(c)}return t},b.dataArrayContainers=["transforms","dimensions"],b.layoutArrayContainers=s.layoutArrayContainers,b.extendTrace=function(t,e){return b.extendObjectWithContainers(t,e,b.dataArrayContainers)},b.extendLayout=function(t,e){return b.extendObjectWithContainers(t,e,b.layoutArrayContainers)},b.transition=function(t,e,r,n,i,a){var o={redraw:i.redraw},s={},l=[];return o.prepareFn=function(){for(var i=Array.isArray(e)?e.length:0,a=n.slice(0,i),o=0;o<a.length;o++){var c=a[o],f=t._fullData[c]._module;if(f){if(f.animatable){var h=f.basePlotModule.name;s[h]||(s[h]=[]),s[h].push(c)}t.data[a[o]]=b.extendTrace(t.data[a[o]],e[o])}}var p=u.expandObjectPaths(u.extendDeepNoArrays({},r)),d=/^[xy]axis[0-9]*$/;for(var m in p)d.test(m)&&delete p[m].range;b.extendLayout(t.layout,p),delete t.calcdata,b.supplyDefaults(t),b.doCalcdata(t);var g=u.expandObjectPaths(r);if(g){var v=t._fullLayout._plots;for(var y in v){var x=v[y],_=x.xaxis,w=x.yaxis,T=_.range.slice(),k=w.range.slice(),A=null,M=null,S=null,E=null;Array.isArray(g[_._name+".range"])?A=g[_._name+".range"].slice():Array.isArray((g[_._name]||{}).range)&&(A=g[_._name].range.slice()),Array.isArray(g[w._name+".range"])?M=g[w._name+".range"].slice():Array.isArray((g[w._name]||{}).range)&&(M=g[w._name].range.slice()),T&&A&&(_.r2l(T[0])!==_.r2l(A[0])||_.r2l(T[1])!==_.r2l(A[1]))&&(S={xr0:T,xr1:A}),k&&M&&(w.r2l(k[0])!==w.r2l(M[0])||w.r2l(k[1])!==w.r2l(M[1]))&&(E={yr0:k,yr1:M}),(S||E)&&l.push(u.extendFlat({plotinfo:x},S,E))}}return Promise.resolve()},o.runFn=function(e){var n,i,o=t._fullLayout._basePlotModules,c=l.length;if(r)for(i=0;i<o.length;i++)o[i].transitionAxes&&o[i].transitionAxes(t,l,a,e);for(var f in c?((n=u.extendFlat({},a)).duration=0,delete s.cartesian):n=a,s){var h=s[f];t._fullData[h[0]]._module.basePlotModule.plot(t,h,n,e)}},I(t,a,o)},b.transitionFromReact=function(t,e,r,n){var i=t._fullLayout,a=i.transition,o={},s=[];return o.prepareFn=function(){var t=i._plots;for(var a in o.redraw=!1,"some"===e.anim&&(o.redraw=!0),"some"===r.anim&&(o.redraw=!0),t){var l=t[a],c=l.xaxis,f=l.yaxis,h=n[c._name].range.slice(),p=n[f._name].range.slice(),d=c.range.slice(),m=f.range.slice();c.setScale(),f.setScale();var g=null,v=null;c.r2l(h[0])===c.r2l(d[0])&&c.r2l(h[1])===c.r2l(d[1])||(g={xr0:h,xr1:d}),f.r2l(p[0])===f.r2l(m[0])&&f.r2l(p[1])===f.r2l(m[1])||(v={yr0:p,yr1:m}),(g||v)&&s.push(u.extendFlat({plotinfo:l},g,v))}return Promise.resolve()},o.runFn=function(r){for(var n,i,o,l=t._fullData,c=t._fullLayout._basePlotModules,f=[],h=0;h<l.length;h++)f.push(h);function p(){if(t._fullLayout)for(var e=0;e<c.length;e++)c[e].transitionAxes&&c[e].transitionAxes(t,s,n,r)}function d(){if(t._fullLayout)for(var e=0;e<c.length;e++)c[e].plot(t,o,i,r)}s.length&&e.anim?"traces first"===a.ordering?(n=u.extendFlat({},a,{duration:0}),o=f,i=a,setTimeout(p,a.duration),d()):(n=a,o=null,i=u.extendFlat({},a,{duration:0}),setTimeout(d,n.duration),p()):s.length?(n=a,p()):e.anim&&(o=f,i=a,d())},I(t,a,o)},b.doCalcdata=function(t,e){var r,n,i,a,o=p.list(t),c=t._fullData,f=t._fullLayout,d=new Array(c.length),m=(t.calcdata||[]).slice();for(t.calcdata=d,f._numBoxes=0,f._numViolins=0,f._violinScaleGroupStats={},t._hmpixcount=0,t._hmlumcount=0,f._piecolormap={},f._sunburstcolormap={},f._treemapcolormap={},f._iciclecolormap={},f._funnelareacolormap={},i=0;i<c.length;i++)Array.isArray(e)&&-1===e.indexOf(i)&&(d[i]=m[i]);for(i=0;i<c.length;i++)(r=c[i])._arrayAttrs=l.findArrayAttributes(r),r._extremes={};var g=f._subplots.polar||[];for(i=0;i<g.length;i++)o.push(f[g[i]].radialaxis,f[g[i]].angularaxis);for(var v in f._colorAxes){var y=f[v];!1!==y.cauto&&(delete y.cmin,delete y.cmax)}var x=!1;function b(e){if(r=c[e],n=r._module,!0===r.visible&&r.transforms){if(n&&n.calc){var i=n.calc(t,r);i[0]&&i[0].t&&i[0].t._scene&&delete i[0].t._scene.dirty}for(a=0;a<r.transforms.length;a++){var o=r.transforms[a];(n=_[o.type])&&n.calcTransform&&(r._hasCalcTransform=!0,x=!0,n.calcTransform(t,r,o))}}}function w(e,i){if(r=c[e],!!(n=r._module).isContainer===i){var o=[];if(!0===r.visible&&0!==r._length){delete r._indexToPoints;var s=r.transforms||[];for(a=s.length-1;a>=0;a--)if(s[a].enabled){r._indexToPoints=s[a]._indexToPoints;break}n&&n.calc&&(o=n.calc(t,r))}Array.isArray(o)&&o[0]||(o=[{x:h,y:h}]),o[0].t||(o[0].t={}),o[0].trace=r,d[e]=o}}for(z(o,c,f),i=0;i<c.length;i++)w(i,!0);for(i=0;i<c.length;i++)b(i);for(x&&z(o,c,f),i=0;i<c.length;i++)w(i,!0);for(i=0;i<c.length;i++)w(i,!1);D(t);var T=function(t,e){var r,n,i,a,o,l=[];function c(t,r,n){var i=r._id.charAt(0);if("histogram2dcontour"===t){var a=r._counterAxes[0],o=p.getFromId(e,a),s="x"===i||"x"===a&&"category"===o.type,l="y"===i||"y"===a&&"category"===o.type;return function(t,e){return 0===t||0===e||s&&t===n[e].length-1||l&&e===n.length-1?-1:("y"===i?e:t)-1}}return function(t,e){return"y"===i?e:t}}var f={min:function(t){return u.aggNums(Math.min,null,t)},max:function(t){return u.aggNums(Math.max,null,t)},sum:function(t){return u.aggNums((function(t,e){return t+e}),null,t)},total:function(t){return u.aggNums((function(t,e){return t+e}),null,t)},mean:function(t){return u.mean(t)},median:function(t){return u.median(t)}};for(r=0;r<t.length;r++){var h=t[r];if("category"===h.type){var d=h.categoryorder.match(O);if(d){var m=d[1],g=d[2],v=h._id.charAt(0),y="x"===v,x=[];for(n=0;n<h._categories.length;n++)x.push([h._categories[n],[]]);for(n=0;n<h._traceIndices.length;n++){var b=h._traceIndices[n],_=e._fullData[b];if(!0===_.visible){var w=_.type;s.traceIs(_,"histogram")&&(delete _._xautoBinFinished,delete _._yautoBinFinished);var T="splom"===w,k="scattergl"===w,A=e.calcdata[b];for(i=0;i<A.length;i++){var M,S,E=A[i];if(T){var L=_._axesDim[h._id];if(!y){var C=_._diag[L][0];C&&(h=e._fullLayout[p.id2name(C)])}var P=E.trace.dimensions[L].values;for(a=0;a<P.length;a++)for(M=h._categoriesMap[P[a]],o=0;o<E.trace.dimensions.length;o++)if(o!==L){var I=E.trace.dimensions[o];x[M][1].push(I.values[a])}}else if(k){for(a=0;a<E.t.x.length;a++)y?(M=E.t.x[a],S=E.t.y[a]):(M=E.t.y[a],S=E.t.x[a]),x[M][1].push(S);E.t&&E.t._scene&&delete E.t._scene.dirty}else if(E.hasOwnProperty("z")){S=E.z;var z=c(_.type,h,S);for(a=0;a<S.length;a++)for(o=0;o<S[a].length;o++)(M=z(o,a))+1&&x[M][1].push(S[a][o])}else for(void 0===(M=E.p)&&(M=E[v]),void 0===(S=E.s)&&(S=E.v),void 0===S&&(S=y?E.y:E.x),Array.isArray(S)||(S=void 0===S?[]:[S]),a=0;a<S.length;a++)x[M][1].push(S[a])}}}h._categoriesValue=x;var D=[];for(n=0;n<x.length;n++)D.push([x[n][0],f[m](x[n][1])]);D.sort((function(t,e){return t[1]-e[1]})),h._categoriesAggregatedValue=D,h._initialCategories=D.map((function(t){return t[0]})),"descending"===g&&h._initialCategories.reverse(),l=l.concat(h.sortByInitialCategories())}}}return l}(o,t);if(T.length){for(f._numBoxes=0,f._numViolins=0,i=0;i<T.length;i++)w(T[i],!0);for(i=0;i<T.length;i++)w(T[i],!1);D(t)}s.getComponentMethod("fx","calc")(t),s.getComponentMethod("errorbars","calc")(t)};var O=/(total|sum|min|max|mean|median) (ascending|descending)/;function z(t,e,r){var n={};function i(t){t.clearCalc(),"multicategory"===t.type&&t.setupMultiCategory(e),n[t._id]=1}u.simpleMap(t,i);for(var a=r._axisMatchGroups||[],o=0;o<a.length;o++)for(var s in a[o])n[s]||i(r[p.id2name(s)])}function D(t){var e,r,n,i=t._fullLayout,a=i._visibleModules,o={};for(r=0;r<a.length;r++){var s=a[r],l=s.crossTraceCalc;if(l){var c=s.basePlotModule.name;o[c]?u.pushUnique(o[c],l):o[c]=[l]}}for(n in o){var f=o[n],h=i._subplots[n];if(Array.isArray(h))for(e=0;e<h.length;e++){var p=h[e],d="cartesian"===n?i._plots[p]:i[p];for(r=0;r<f.length;r++)f[r](t,d,p)}else for(r=0;r<f.length;r++)f[r](t)}}b.rehover=function(t){t._fullLayout._rehover&&t._fullLayout._rehover()},b.redrag=function(t){t._fullLayout._redrag&&t._fullLayout._redrag()},b.generalUpdatePerTraceModule=function(t,e,r,n){var i,a=e.traceHash,o={};for(i=0;i<r.length;i++){var s=r[i],l=s[0].trace;l.visible&&(o[l.type]=o[l.type]||[],o[l.type].push(s))}for(var c in a)if(!o[c]){var f=a[c][0];f[0].trace.visible=!1,o[c]=[f]}for(var h in o){var p=o[h];p[0][0].trace._module.plot(t,e,u.filterVisible(p),n)}e.traceHash=o},b.plotBasePlot=function(t,e,r,n,i){var a=s.getModule(t),o=v(e.calcdata,a)[0];a.plot(e,o,n,i)},b.cleanBasePlot=function(t,e,r,n,i){var a=i._has&&i._has(t),o=r._has&&r._has(t);a&&!o&&i["_"+t+"layer"].selectAll("g.trace").remove()}},{"../components/color":366,"../constants/numerical":479,"../lib":503,"../plot_api/plot_schema":542,"../plot_api/plot_template":543,"../plots/get_data":593,"../registry":638,"./animation_attributes":548,"./attributes":550,"./cartesian/axis_ids":558,"./cartesian/handle_outline":565,"./command":583,"./font_attributes":585,"./frame_attributes":586,"./layout_attributes":610,"@plotly/d3":58,"d3-format":112,"d3-time-format":120,"fast-isnumeric":190}],620:[function(t,e,r){"use strict";e.exports={attr:"subplot",name:"polar",axisNames:["angularaxis","radialaxis"],axisName2dataArray:{angularaxis:"theta",radialaxis:"r"},layerNames:["draglayer","plotbg","backplot","angular-grid","radial-grid","frontplot","angular-line","radial-line","angular-axis","radial-axis"],radialDragBoxSize:50,angularDragBoxSize:30,cornerLen:25,cornerHalfWidth:2,MINDRAG:8,MINZOOM:20,OFFEDGE:20}},{}],621:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../lib/polygon").tester,a=n.findIndexOfMin,o=n.isAngleInsideSector,s=n.angleDelta,l=n.angleDist;function c(t,e,r,n){var i,a,o=n[0],s=n[1],l=f(Math.sin(e)-Math.sin(t)),c=f(Math.cos(e)-Math.cos(t)),u=Math.tan(r),h=f(1/u),p=l/c,d=s-p*o;return h?l&&c?a=u*(i=d/(u-p)):c?(i=s*h,a=s):(i=o,a=o*u):l&&c?(i=0,a=d):c?(i=0,a=s):i=a=NaN,[i,a]}function u(t,e,r,i){return n.isFullCircle([e,r])?function(t,e){var r,n=e.length,i=new Array(n+1);for(r=0;r<n;r++){var a=e[r];i[r]=[t*Math.cos(a),t*Math.sin(a)]}return i[r]=i[0].slice(),i}(t,i):function(t,e,r,i){var s,u,f=i.length,h=[];function p(e){return[t*Math.cos(e),t*Math.sin(e)]}function d(t,e,r){return c(t,e,r,p(t))}function m(t){return n.mod(t,f)}function g(t){return o(t,[e,r])}var v=a(i,(function(t){return g(t)?l(t,e):1/0})),y=d(i[v],i[m(v-1)],e);for(h.push(y),s=v,u=0;u<f;s++,u++){var x=i[m(s)];if(!g(x))break;h.push(p(x))}var b=a(i,(function(t){return g(t)?l(t,r):1/0})),_=d(i[b],i[m(b+1)],r);return h.push(_),h.push([0,0]),h.push(h[0].slice()),h}(t,e,r,i)}function f(t){return Math.abs(t)>1e-10?t:0}function h(t,e,r){e=e||0,r=r||0;for(var n=t.length,i=new Array(n),a=0;a<n;a++){var o=t[a];i[a]=[e+o[0],r-o[1]]}return i}e.exports={isPtInsidePolygon:function(t,e,r,n,a){if(!o(e,n))return!1;var s,l;r[0]<r[1]?(s=r[0],l=r[1]):(s=r[1],l=r[0]);var c=i(u(s,n[0],n[1],a)),f=i(u(l,n[0],n[1],a)),h=[t*Math.cos(e),t*Math.sin(e)];return f.contains(h)&&!c.contains(h)},findPolygonOffset:function(t,e,r,n){for(var i=1/0,a=1/0,o=u(t,e,r,n),s=0;s<o.length;s++){var l=o[s];i=Math.min(i,l[0]),a=Math.min(a,-l[1])}return[i,a]},findEnclosingVertexAngles:function(t,e){var r=a(e,(function(e){var r=s(e,t);return r>0?r:1/0})),i=n.mod(r+1,e.length);return[e[r],e[i]]},findIntersectionXY:c,findXYatLength:function(t,e,r,n){var i=-e*r,a=e*e+1,o=2*(e*i-r),s=i*i+r*r-t*t,l=Math.sqrt(o*o-4*a*s),c=(-o+l)/(2*a),u=(-o-l)/(2*a);return[[c,e*c+i+n],[u,e*u+i+n]]},clampTiny:f,pathPolygon:function(t,e,r,n,i,a){return"M"+h(u(t,e,r,n),i,a).join("L")},pathPolygonAnnulus:function(t,e,r,n,i,a,o){var s,l;t<e?(s=t,l=e):(s=e,l=t);var c=h(u(s,r,n,i),a,o);return"M"+h(u(l,r,n,i),a,o).reverse().join("L")+"M"+c.join("L")}}},{"../../lib":503,"../../lib/polygon":515}],622:[function(t,e,r){"use strict";var n=t("../get_data").getSubplotCalcData,i=t("../../lib").counterRegex,a=t("./polar"),o=t("./constants"),s=o.attr,l=o.name,c=i(l),u={};u[s]={valType:"subplotid",dflt:l,editType:"calc"},e.exports={attr:s,name:l,idRoot:l,idRegex:c,attrRegex:c,attributes:u,layoutAttributes:t("./layout_attributes"),supplyLayoutDefaults:t("./layout_defaults"),plot:function(t){for(var e=t._fullLayout,r=t.calcdata,i=e._subplots[l],o=0;o<i.length;o++){var s=i[o],c=n(r,l,s),u=e[s]._subplot;u||(u=a(t,s),e[s]._subplot=u),u.plot(c,e,t._promises)}},clean:function(t,e,r,n){for(var i=n._subplots[l]||[],a=n._has&&n._has("gl"),o=e._has&&e._has("gl"),s=a&&!o,c=0;c<i.length;c++){var u=i[c],f=n[u]._subplot;if(!e[u]&&f)for(var h in f.framework.remove(),f.layers["radial-axis-title"].remove(),f.clipPaths)f.clipPaths[h].remove();s&&f._scene&&(f._scene.destroy(),f._scene=null)}},toSVG:t("../cartesian").toSVG}},{"../../lib":503,"../cartesian":568,"../get_data":593,"./constants":620,"./layout_attributes":623,"./layout_defaults":624,"./polar":625}],623:[function(t,e,r){"use strict";var n=t("../../components/color/attributes"),i=t("../cartesian/layout_attributes"),a=t("../domain").attributes,o=t("../../lib").extendFlat,s=t("../../plot_api/edit_types").overrideAll,l=s({color:i.color,showline:o({},i.showline,{dflt:!0}),linecolor:i.linecolor,linewidth:i.linewidth,showgrid:o({},i.showgrid,{dflt:!0}),gridcolor:i.gridcolor,gridwidth:i.gridwidth,griddash:i.griddash},"plot","from-root"),c=s({tickmode:i.tickmode,nticks:i.nticks,tick0:i.tick0,dtick:i.dtick,tickvals:i.tickvals,ticktext:i.ticktext,ticks:i.ticks,ticklen:i.ticklen,tickwidth:i.tickwidth,tickcolor:i.tickcolor,ticklabelstep:i.ticklabelstep,showticklabels:i.showticklabels,showtickprefix:i.showtickprefix,tickprefix:i.tickprefix,showticksuffix:i.showticksuffix,ticksuffix:i.ticksuffix,showexponent:i.showexponent,exponentformat:i.exponentformat,minexponent:i.minexponent,separatethousands:i.separatethousands,tickfont:i.tickfont,tickangle:i.tickangle,tickformat:i.tickformat,tickformatstops:i.tickformatstops,layer:i.layer},"plot","from-root"),u={visible:o({},i.visible,{dflt:!0}),type:o({},i.type,{values:["-","linear","log","date","category"]}),autotypenumbers:i.autotypenumbers,autorange:o({},i.autorange,{editType:"plot"}),rangemode:{valType:"enumerated",values:["tozero","nonnegative","normal"],dflt:"tozero",editType:"calc"},range:o({},i.range,{items:[{valType:"any",editType:"plot",impliedEdits:{"^autorange":!1}},{valType:"any",editType:"plot",impliedEdits:{"^autorange":!1}}],editType:"plot"}),categoryorder:i.categoryorder,categoryarray:i.categoryarray,angle:{valType:"angle",editType:"plot"},side:{valType:"enumerated",values:["clockwise","counterclockwise"],dflt:"clockwise",editType:"plot"},title:{text:o({},i.title.text,{editType:"plot",dflt:""}),font:o({},i.title.font,{editType:"plot"}),editType:"plot"},hoverformat:i.hoverformat,uirevision:{valType:"any",editType:"none"},editType:"calc",_deprecated:{title:i._deprecated.title,titlefont:i._deprecated.titlefont}};o(u,l,c);var f={visible:o({},i.visible,{dflt:!0}),type:{valType:"enumerated",values:["-","linear","category"],dflt:"-",editType:"calc",_noTemplating:!0},autotypenumbers:i.autotypenumbers,categoryorder:i.categoryorder,categoryarray:i.categoryarray,thetaunit:{valType:"enumerated",values:["radians","degrees"],dflt:"degrees",editType:"calc"},period:{valType:"number",editType:"calc",min:0},direction:{valType:"enumerated",values:["counterclockwise","clockwise"],dflt:"counterclockwise",editType:"calc"},rotation:{valType:"angle",editType:"calc"},hoverformat:i.hoverformat,uirevision:{valType:"any",editType:"none"},editType:"calc"};o(f,l,c),e.exports={domain:a({name:"polar",editType:"plot"}),sector:{valType:"info_array",items:[{valType:"number",editType:"plot"},{valType:"number",editType:"plot"}],dflt:[0,360],editType:"plot"},hole:{valType:"number",min:0,max:1,dflt:0,editType:"plot"},bgcolor:{valType:"color",editType:"plot",dflt:n.background},radialaxis:u,angularaxis:f,gridshape:{valType:"enumerated",values:["circular","linear"],dflt:"circular",editType:"plot"},uirevision:{valType:"any",editType:"none"},editType:"calc"}},{"../../components/color/attributes":365,"../../lib":503,"../../plot_api/edit_types":536,"../cartesian/layout_attributes":569,"../domain":584}],624:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/color"),a=t("../../plot_api/plot_template"),o=t("../subplot_defaults"),s=t("../get_data").getSubplotData,l=t("../cartesian/tick_value_defaults"),c=t("../cartesian/tick_mark_defaults"),u=t("../cartesian/tick_label_defaults"),f=t("../cartesian/prefix_suffix_defaults"),h=t("../cartesian/category_order_defaults"),p=t("../cartesian/line_grid_defaults"),d=t("../cartesian/axis_autotype"),m=t("./layout_attributes"),g=t("./set_convert"),v=t("./constants"),y=v.axisNames;function x(t,e,r,o){var d=r("bgcolor");o.bgColor=i.combine(d,o.paper_bgcolor);var x=r("sector");r("hole");var _,w=s(o.fullData,v.name,o.id),T=o.layoutOut;function k(t,e){return r(_+"."+t,e)}for(var A=0;A<y.length;A++){_=y[A],n.isPlainObject(t[_])||(t[_]={});var M=t[_],S=a.newContainer(e,_);S._id=S._name=_,S._attr=o.id+"."+_,S._traceIndices=w.map((function(t){return t._expandedIndex}));var E=v.axisName2dataArray[_],L=b(M,S,k,w,E,o);h(M,S,k,{axData:w,dataAttr:E});var C=k("visible");switch(g(S,e,T),k("uirevision",e.uirevision),S._m=1,_){case"radialaxis":var P=k("autorange",!S.isValidRange(M.range));M.autorange=P,!P||"linear"!==L&&"-"!==L||k("rangemode"),"reversed"===P&&(S._m=-1),k("range"),S.cleanRange("range",{dfltRange:[0,1]});break;case"angularaxis":if("date"===L){n.log("Polar plots do not support date angular axes yet.");for(var I=0;I<w.length;I++)w[I].visible=!1;L=M.type=S.type="linear"}k("linear"===L?"thetaunit":"period");var O=k("direction");k("rotation",{counterclockwise:0,clockwise:90}[O])}if(f(M,S,k,S.type,{tickSuffixDflt:"degrees"===S.thetaunit?"\xb0":void 0}),C){var z,D,R,F,B=o.font||{};D=(z=k("color"))===M.color?z:B.color,R=B.size,F=B.family,l(M,S,k,S.type),u(M,S,k,S.type,{font:{color:D,size:R,family:F}}),c(M,S,k,{outerTicks:!0}),p(M,S,k,{dfltColor:z,bgColor:o.bgColor,blend:60,showLine:!0,showGrid:!0,noZeroLine:!0,attributes:m[_]}),k("layer"),"radialaxis"===_&&(k("side"),k("angle",x[0]),k("title.text"),n.coerceFont(k,"title.font",{color:D,size:n.bigFont(R),family:F}))}"category"!==L&&k("hoverformat"),S._input=M}"category"===e.angularaxis.type&&r("gridshape")}function b(t,e,r,n,i,a){var o=r("autotypenumbers",a.autotypenumbersDflt);if("-"===r("type")){for(var s,l=0;l<n.length;l++)if(n[l].visible){s=n[l];break}s&&s[i]&&(e.type=d(s[i],"gregorian",{noMultiCategory:!0,autotypenumbers:o})),"-"===e.type?e.type="linear":t.type=e.type}return e.type}e.exports=function(t,e,r){o(t,e,r,{type:v.name,attributes:m,handleDefaults:x,font:e.font,autotypenumbersDflt:e.autotypenumbers,paper_bgcolor:e.paper_bgcolor,fullData:r,layoutOut:e})}},{"../../components/color":366,"../../lib":503,"../../plot_api/plot_template":543,"../cartesian/axis_autotype":555,"../cartesian/category_order_defaults":559,"../cartesian/line_grid_defaults":571,"../cartesian/prefix_suffix_defaults":573,"../cartesian/tick_label_defaults":578,"../cartesian/tick_mark_defaults":579,"../cartesian/tick_value_defaults":580,"../get_data":593,"../subplot_defaults":632,"./constants":620,"./layout_attributes":623,"./set_convert":626}],625:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("tinycolor2"),a=t("../../registry"),o=t("../../lib"),s=o.strRotate,l=o.strTranslate,c=t("../../components/color"),u=t("../../components/drawing"),f=t("../plots"),h=t("../../plots/cartesian/axes"),p=t("../cartesian/set_convert"),d=t("./set_convert"),m=t("../cartesian/autorange").doAutoRange,g=t("../cartesian/dragbox"),v=t("../../components/dragelement"),y=t("../../components/fx"),x=t("../../components/titles"),b=t("../cartesian/select").prepSelect,_=t("../cartesian/select").selectOnClick,w=t("../cartesian/select").clearSelect,T=t("../../lib/setcursor"),k=t("../../lib/clear_gl_canvases"),A=t("../../plot_api/subroutines").redrawReglTraces,M=t("../../constants/alignment").MID_SHIFT,S=t("./constants"),E=t("./helpers"),L=t("../smith/helpers"),C=L.smith,P=L.reactanceArc,I=L.resistanceArc,O=L.smithTransform,z=o._,D=o.mod,R=o.deg2rad,F=o.rad2deg;function B(t,e,r){this.isSmith=r||!1,this.id=e,this.gd=t,this._hasClipOnAxisFalse=null,this.vangles=null,this.radialAxisAngle=null,this.traceHash={},this.layers={},this.clipPaths={},this.clipIds={},this.viewInitial={};var n=t._fullLayout,i="clip"+n._uid+e;this.clipIds.forTraces=i+"-for-traces",this.clipPaths.forTraces=n._clips.append("clipPath").attr("id",this.clipIds.forTraces),this.clipPaths.forTraces.append("path"),this.framework=n["_"+(r?"smith":"polar")+"layer"].append("g").attr("class",e),this.getHole=function(t){return this.isSmith?0:t.hole},this.getSector=function(t){return this.isSmith?[0,360]:t.sector},this.getRadial=function(t){return this.isSmith?t.realaxis:t.radialaxis},this.getAngular=function(t){return this.isSmith?t.imaginaryaxis:t.angularaxis},r||(this.radialTickLayout=null,this.angularTickLayout=null)}var N=B.prototype;function j(t){var e=t.ticks+String(t.ticklen)+String(t.showticklabels);return"side"in t&&(e+=t.side),e}function U(t,e){return e[o.findIndexOfMin(e,(function(e){return o.angleDist(t,e)}))]}function V(t,e,r){return e?(t.attr("display",null),t.attr(r)):t&&t.attr("display","none"),t}e.exports=function(t,e,r){return new B(t,e,r)},N.plot=function(t,e){for(var r=e[this.id],n=!1,i=0;i<t.length;i++){if(!1===t[i][0].trace.cliponaxis){n=!0;break}}this._hasClipOnAxisFalse=n,this.updateLayers(e,r),this.updateLayout(e,r),f.generalUpdatePerTraceModule(this.gd,this,t,r),this.updateFx(e,r),this.isSmith&&(delete r.realaxis.range,delete r.imaginaryaxis.range)},N.updateLayers=function(t,e){var r=this.isSmith,i=this.layers,a=this.getRadial(e),o=this.getAngular(e),s=S.layerNames,l=s.indexOf("frontplot"),c=s.slice(0,l),u="below traces"===o.layer,f="below traces"===a.layer;u&&c.push("angular-line"),f&&c.push("radial-line"),u&&c.push("angular-axis"),f&&c.push("radial-axis"),c.push("frontplot"),u||c.push("angular-line"),f||c.push("radial-line"),u||c.push("angular-axis"),f||c.push("radial-axis");var h=(r?"smith":"polar")+"sublayer",p=this.framework.selectAll("."+h).data(c,String);p.enter().append("g").attr("class",(function(t){return h+" "+t})).each((function(t){var e=i[t]=n.select(this);switch(t){case"frontplot":r||e.append("g").classed("barlayer",!0),e.append("g").classed("scatterlayer",!0);break;case"backplot":e.append("g").classed("maplayer",!0);break;case"plotbg":i.bg=e.append("path");break;case"radial-grid":case"angular-grid":e.style("fill","none");break;case"radial-line":e.append("line").style("fill","none");break;case"angular-line":e.append("path").style("fill","none")}})),p.order()},N.updateLayout=function(t,e){var r=this.layers,n=t._size,i=this.getRadial(e),a=this.getAngular(e),o=e.domain.x,s=e.domain.y;this.xOffset=n.l+n.w*o[0],this.yOffset=n.t+n.h*(1-s[1]);var f=this.xLength=n.w*(o[1]-o[0]),h=this.yLength=n.h*(s[1]-s[0]),p=this.getSector(e);this.sectorInRad=p.map(R);var d,m,g,v,y,x=this.sectorBBox=function(t){var e,r,n,i,a=t[0],o=t[1]-a,s=D(a,360),l=s+o,c=Math.cos(R(s)),u=Math.sin(R(s)),f=Math.cos(R(l)),h=Math.sin(R(l));i=s<=90&&l>=90||s>90&&l>=450?1:u<=0&&h<=0?0:Math.max(u,h);e=s<=180&&l>=180||s>180&&l>=540?-1:c>=0&&f>=0?0:Math.min(c,f);r=s<=270&&l>=270||s>270&&l>=630?-1:u>=0&&h>=0?0:Math.min(u,h);n=l>=360?1:c<=0&&f<=0?0:Math.max(c,f);return[e,r,n,i]}(p),b=x[2]-x[0],_=x[3]-x[1],w=h/f,T=Math.abs(_/b);w>T?(d=f,y=(h-(m=f*T))/n.h/2,g=[o[0],o[1]],v=[s[0]+y,s[1]-y]):(m=h,y=(f-(d=h/T))/n.w/2,g=[o[0]+y,o[1]-y],v=[s[0],s[1]]),this.xLength2=d,this.yLength2=m,this.xDomain2=g,this.yDomain2=v;var k,A=this.xOffset2=n.l+n.w*g[0],M=this.yOffset2=n.t+n.h*(1-v[1]),S=this.radius=d/b,E=this.innerRadius=this.getHole(e)*S,L=this.cx=A-S*x[0],C=this.cy=M+S*x[3],P=this.cxx=L-A,I=this.cyy=C-M,O=i.side;"counterclockwise"===O?(k=O,O="top"):"clockwise"===O&&(k=O,O="bottom"),this.radialAxis=this.mockAxis(t,e,i,{_id:"x",side:O,_trueSide:k,domain:[E/n.w,S/n.w]}),this.angularAxis=this.mockAxis(t,e,a,{side:"right",domain:[0,Math.PI],autorange:!1}),this.doAutoRange(t,e),this.updateAngularAxis(t,e),this.updateRadialAxis(t,e),this.updateRadialAxisTitle(t,e),this.xaxis=this.mockCartesianAxis(t,e,{_id:"x",domain:g}),this.yaxis=this.mockCartesianAxis(t,e,{_id:"y",domain:v});var z=this.pathSubplot();this.clipPaths.forTraces.select("path").attr("d",z).attr("transform",l(P,I)),r.frontplot.attr("transform",l(A,M)).call(u.setClipUrl,this._hasClipOnAxisFalse?null:this.clipIds.forTraces,this.gd),r.bg.attr("d",z).attr("transform",l(L,C)).call(c.fill,e.bgcolor)},N.mockAxis=function(t,e,r,n){var i=o.extendFlat({},r,n);return d(i,e,t),i},N.mockCartesianAxis=function(t,e,r){var n=this,i=n.isSmith,a=r._id,s=o.extendFlat({type:"linear"},r);p(s,t);var l={x:[0,2],y:[1,3]};return s.setRange=function(){var t=n.sectorBBox,r=l[a],i=n.radialAxis._rl,o=(i[1]-i[0])/(1-n.getHole(e));s.range=[t[r[0]]*o,t[r[1]]*o]},s.isPtWithinRange="x"!==a||i?function(){return!0}:function(t){return n.isPtInside(t)},s.setRange(),s.setScale(),s},N.doAutoRange=function(t,e){var r=this.gd,n=this.radialAxis,i=this.getRadial(e);m(r,n);var a=n.range;i.range=a.slice(),i._input.range=a.slice(),n._rl=[n.r2l(a[0],null,"gregorian"),n.r2l(a[1],null,"gregorian")]},N.updateRadialAxis=function(t,e){var r=this,n=r.gd,i=r.layers,a=r.radius,u=r.innerRadius,f=r.cx,p=r.cy,d=r.getRadial(e),m=D(r.getSector(e)[0],360),g=r.radialAxis,v=u<a,y=r.isSmith;y||(r.fillViewInitialKey("radialaxis.angle",d.angle),r.fillViewInitialKey("radialaxis.range",g.range.slice()),g.setGeometry()),"auto"===g.tickangle&&m>90&&m<=270&&(g.tickangle=180);var x=y?function(t){var e=O(r,C([t.x,0]));return l(e[0]-f,e[1]-p)}:function(t){return l(g.l2p(t.x)+u,0)},b=y?function(t){return I(r,t.x,-1/0,1/0)}:function(t){return r.pathArc(g.r2p(t.x)+u)},_=j(d);if(r.radialTickLayout!==_&&(i["radial-axis"].selectAll(".xtick").remove(),r.radialTickLayout=_),v){g.setScale();var w=0,T=y?(g.tickvals||[]).filter((function(t){return t>=0})).map((function(t){return h.tickText(g,t,!0,!1)})):h.calcTicks(g),k=y?T:h.clipEnds(g,T),A=h.getTickSigns(g)[2];y&&(("top"===g.ticks&&"bottom"===g.side||"bottom"===g.ticks&&"top"===g.side)&&(A=-A),"top"===g.ticks&&"top"===g.side&&(w=-g.ticklen),"bottom"===g.ticks&&"bottom"===g.side&&(w=g.ticklen)),h.drawTicks(n,g,{vals:T,layer:i["radial-axis"],path:h.makeTickPath(g,0,A),transFn:x,crisp:!1}),h.drawGrid(n,g,{vals:k,layer:i["radial-grid"],path:b,transFn:o.noop,crisp:!1}),h.drawLabels(n,g,{vals:T,layer:i["radial-axis"],transFn:x,labelFns:h.makeLabelFns(g,w)})}var M=r.radialAxisAngle=r.vangles?F(U(R(d.angle),r.vangles)):d.angle,S=l(f,p),E=S+s(-M);V(i["radial-axis"],v&&(d.showticklabels||d.ticks),{transform:E}),V(i["radial-grid"],v&&d.showgrid,{transform:y?"":S}),V(i["radial-line"].select("line"),v&&d.showline,{x1:y?-a:u,y1:0,x2:a,y2:0,transform:E}).attr("stroke-width",d.linewidth).call(c.stroke,d.linecolor)},N.updateRadialAxisTitle=function(t,e,r){if(!this.isSmith){var n=this.gd,i=this.radius,a=this.cx,o=this.cy,s=this.getRadial(e),l=this.id+"title",c=0;if(s.title){var f=u.bBox(this.layers["radial-axis"].node()).height,h=s.title.font.size,p=s.side;c="top"===p?h:"counterclockwise"===p?-(f+.4*h):f+.8*h}var d=void 0!==r?r:this.radialAxisAngle,m=R(d),g=Math.cos(m),v=Math.sin(m),y=a+i/2*g+c*v,b=o-i/2*v+c*g;this.layers["radial-axis-title"]=x.draw(n,l,{propContainer:s,propName:this.id+".radialaxis.title",placeholder:z(n,"Click to enter radial axis title"),attributes:{x:y,y:b,"text-anchor":"middle"},transform:{rotate:-d}})}},N.updateAngularAxis=function(t,e){var r=this,n=r.gd,i=r.layers,a=r.radius,u=r.innerRadius,f=r.cx,p=r.cy,d=r.getAngular(e),m=r.angularAxis,g=r.isSmith;g||(r.fillViewInitialKey("angularaxis.rotation",d.rotation),m.setGeometry(),m.setScale());var v=g?function(t){var e=O(r,C([0,t.x]));return Math.atan2(e[0]-f,e[1]-p)-Math.PI/2}:function(t){return m.t2g(t.x)};"linear"===m.type&&"radians"===m.thetaunit&&(m.tick0=F(m.tick0),m.dtick=F(m.dtick));var y=function(t){return l(f+a*Math.cos(t),p-a*Math.sin(t))},x=g?function(t){var e=O(r,C([0,t.x]));return l(e[0],e[1])}:function(t){return y(v(t))},b=g?function(t){var e=O(r,C([0,t.x])),n=Math.atan2(e[0]-f,e[1]-p)-Math.PI/2;return l(e[0],e[1])+s(-F(n))}:function(t){var e=v(t);return y(e)+s(-F(e))},_=g?function(t){return P(r,t.x,0,1/0)}:function(t){var e=v(t),r=Math.cos(e),n=Math.sin(e);return"M"+[f+u*r,p-u*n]+"L"+[f+a*r,p-a*n]},w=h.makeLabelFns(m,0).labelStandoff,T={xFn:function(t){var e=v(t);return Math.cos(e)*w},yFn:function(t){var e=v(t),r=Math.sin(e)>0?.2:1;return-Math.sin(e)*(w+t.fontSize*r)+Math.abs(Math.cos(e))*(t.fontSize*M)},anchorFn:function(t){var e=v(t),r=Math.cos(e);return Math.abs(r)<.1?"middle":r>0?"start":"end"},heightFn:function(t,e,r){var n=v(t);return-.5*(1+Math.sin(n))*r}},k=j(d);r.angularTickLayout!==k&&(i["angular-axis"].selectAll("."+m._id+"tick").remove(),r.angularTickLayout=k);var A,S=g?[1/0].concat(m.tickvals||[]).map((function(t){return h.tickText(m,t,!0,!1)})):h.calcTicks(m);if(g&&(S[0].text="\u221e",S[0].fontSize*=1.75),"linear"===e.gridshape?(A=S.map(v),o.angleDelta(A[0],A[1])<0&&(A=A.slice().reverse())):A=null,r.vangles=A,"category"===m.type&&(S=S.filter((function(t){return o.isAngleInsideSector(v(t),r.sectorInRad)}))),m.visible){var E="inside"===m.ticks?-1:1,L=(m.linewidth||1)/2;h.drawTicks(n,m,{vals:S,layer:i["angular-axis"],path:"M"+E*L+",0h"+E*m.ticklen,transFn:b,crisp:!1}),h.drawGrid(n,m,{vals:S,layer:i["angular-grid"],path:_,transFn:o.noop,crisp:!1}),h.drawLabels(n,m,{vals:S,layer:i["angular-axis"],repositionOnUpdate:!0,transFn:x,labelFns:T})}V(i["angular-line"].select("path"),d.showline,{d:r.pathSubplot(),transform:l(f,p)}).attr("stroke-width",d.linewidth).call(c.stroke,d.linecolor)},N.updateFx=function(t,e){this.gd._context.staticPlot||(!this.isSmith&&(this.updateAngularDrag(t),this.updateRadialDrag(t,e,0),this.updateRadialDrag(t,e,1)),this.updateHoverAndMainDrag(t))},N.updateHoverAndMainDrag=function(t){var e,r,s=this,c=s.isSmith,u=s.gd,f=s.layers,h=t._zoomlayer,p=S.MINZOOM,d=S.OFFEDGE,m=s.radius,x=s.innerRadius,T=s.cx,k=s.cy,A=s.cxx,M=s.cyy,L=s.sectorInRad,C=s.vangles,P=s.radialAxis,I=E.clampTiny,O=E.findXYatLength,z=E.findEnclosingVertexAngles,D=S.cornerHalfWidth,R=S.cornerLen/2,F=g.makeDragger(f,"path","maindrag",!1===t.dragmode?"none":"crosshair");n.select(F).attr("d",s.pathSubplot()).attr("transform",l(T,k)),F.onmousemove=function(t){y.hover(u,t,s.id),u._fullLayout._lasthover=F,u._fullLayout._hoversubplot=s.id},F.onmouseout=function(t){u._dragging||v.unhover(u,t)};var B,N,j,U,V,H,q,G,Y,W={element:F,gd:u,subplot:s.id,plotinfo:{id:s.id,xaxis:s.xaxis,yaxis:s.yaxis},xaxes:[s.xaxis],yaxes:[s.yaxis]};function X(t,e){return Math.sqrt(t*t+e*e)}function Z(t,e){return X(t-A,e-M)}function J(t,e){return Math.atan2(M-e,t-A)}function K(t,e){return[t*Math.cos(e),t*Math.sin(-e)]}function Q(t,e){if(0===t)return s.pathSector(2*D);var r=R/t,n=e-r,i=e+r,a=Math.max(0,Math.min(t,m)),o=a-D,l=a+D;return"M"+K(o,n)+"A"+[o,o]+" 0,0,0 "+K(o,i)+"L"+K(l,i)+"A"+[l,l]+" 0,0,1 "+K(l,n)+"Z"}function $(t,e,r){if(0===t)return s.pathSector(2*D);var n,i,a=K(t,e),o=K(t,r),l=I((a[0]+o[0])/2),c=I((a[1]+o[1])/2);if(l&&c){var u=c/l,f=-1/u,h=O(D,u,l,c);n=O(R,f,h[0][0],h[0][1]),i=O(R,f,h[1][0],h[1][1])}else{var p,d;c?(p=R,d=D):(p=D,d=R),n=[[l-p,c-d],[l+p,c-d]],i=[[l-p,c+d],[l+p,c+d]]}return"M"+n.join("L")+"L"+i.reverse().join("L")+"Z"}function tt(t,e){return e=Math.max(Math.min(e,m),x),t<d?t=0:m-t<d?t=m:e<d?e=0:m-e<d&&(e=m),Math.abs(e-t)>p?(t<e?(j=t,U=e):(j=e,U=t),!0):(j=null,U=null,!1)}function et(t,e){t=t||V,e=e||"M0,0Z",G.attr("d",t),Y.attr("d",e),g.transitionZoombox(G,Y,H,q),H=!0;var r={};ot(r),u.emit("plotly_relayouting",r)}function rt(t,n){var i,a,o=B+(t*=e),l=N+(n*=r),c=Z(B,N),u=Math.min(Z(o,l),m),f=J(B,N);tt(c,u)&&(i=V+s.pathSector(U),j&&(i+=s.pathSector(j)),a=Q(j,f)+Q(U,f)),et(i,a)}function nt(t,e,r,n){var i=E.findIntersectionXY(r,n,r,[t-A,M-e]);return X(i[0],i[1])}function it(t,e){var r,n,i=B+t,a=N+e,o=J(B,N),l=J(i,a),c=z(o,C),u=z(l,C);tt(nt(B,N,c[0],c[1]),Math.min(nt(i,a,u[0],u[1]),m))&&(r=V+s.pathSector(U),j&&(r+=s.pathSector(j)),n=[$(j,c[0],c[1]),$(U,c[0],c[1])].join(" ")),et(r,n)}function at(){if(g.removeZoombox(u),null!==j&&null!==U){var t={};ot(t),g.showDoubleClickNotifier(u),a.call("_guiRelayout",u,t)}}function ot(t){var e=P._rl,r=(e[1]-e[0])/(1-x/m)/m,n=[e[0]+(j-x)*r,e[0]+(U-x)*r];t[s.id+".radialaxis.range"]=n}function st(t,e){var r=u._fullLayout.clickmode;if(g.removeZoombox(u),2===t){var n={};for(var i in s.viewInitial)n[s.id+"."+i]=s.viewInitial[i];u.emit("plotly_doubleclick",null),a.call("_guiRelayout",u,n)}r.indexOf("select")>-1&&1===t&&_(e,u,[s.xaxis],[s.yaxis],s.id,W),r.indexOf("event")>-1&&y.click(u,e,s.id)}W.prepFn=function(t,n,a){var l=u._fullLayout.dragmode,f=F.getBoundingClientRect();u._fullLayout._calcInverseTransform(u);var p=u._fullLayout._invTransform;e=u._fullLayout._invScaleX,r=u._fullLayout._invScaleY;var d=o.apply3DTransform(p)(n-f.left,a-f.top);if(B=d[0],N=d[1],C){var v=E.findPolygonOffset(m,L[0],L[1],C);B+=A+v[0],N+=M+v[1]}switch(l){case"zoom":W.clickFn=st,c||(W.moveFn=C?it:rt,W.doneFn=at,function(){j=null,U=null,V=s.pathSubplot(),H=!1;var t=u._fullLayout[s.id];q=i(t.bgcolor).getLuminance(),(G=g.makeZoombox(h,q,T,k,V)).attr("fill-rule","evenodd"),Y=g.makeCorners(h,T,k),w(u)}());break;case"select":case"lasso":b(t,n,a,W,l)}},v.init(W)},N.updateRadialDrag=function(t,e,r){var i=this,c=i.gd,u=i.layers,f=i.radius,h=i.innerRadius,p=i.cx,d=i.cy,m=i.radialAxis,y=S.radialDragBoxSize,x=y/2;if(m.visible){var b,_,T,M=R(i.radialAxisAngle),E=m._rl,L=E[0],C=E[1],P=E[r],I=.75*(E[1]-E[0])/(1-i.getHole(e))/f;r?(b=p+(f+x)*Math.cos(M),_=d-(f+x)*Math.sin(M),T="radialdrag"):(b=p+(h-x)*Math.cos(M),_=d-(h-x)*Math.sin(M),T="radialdrag-inner");var O,z,D,B=g.makeRectDragger(u,T,"crosshair",-x,-x,y,y),N={element:B,gd:c};!1===t.dragmode&&(N.dragmode=!1),V(n.select(B),m.visible&&h<f,{transform:l(b,_)}),N.prepFn=function(){O=null,z=null,D=null,N.moveFn=j,N.doneFn=H,w(c)},N.clampFn=function(t,e){return Math.sqrt(t*t+e*e)<S.MINDRAG&&(t=0,e=0),[t,e]},v.init(N)}function j(t,e){if(O)O(t,e);else{var n=[t,-e],a=[Math.cos(M),Math.sin(M)],s=Math.abs(o.dot(n,a)/Math.sqrt(o.dot(n,n)));isNaN(s)||(O=s<.5?q:G)}var l={};!function(t){null!==z?t[i.id+".radialaxis.angle"]=z:null!==D&&(t[i.id+".radialaxis.range["+r+"]"]=D)}(l),c.emit("plotly_relayouting",l)}function H(){null!==z?a.call("_guiRelayout",c,i.id+".radialaxis.angle",z):null!==D&&a.call("_guiRelayout",c,i.id+".radialaxis.range["+r+"]",D)}function q(t,e){if(0!==r){var n=b+t,a=_+e;z=Math.atan2(d-a,n-p),i.vangles&&(z=U(z,i.vangles)),z=F(z);var o=l(p,d)+s(-z);u["radial-axis"].attr("transform",o),u["radial-line"].select("line").attr("transform",o);var c=i.gd._fullLayout,f=c[i.id];i.updateRadialAxisTitle(c,f,z)}}function G(t,e){var n=o.dot([t,-e],[Math.cos(M),Math.sin(M)]);if(D=P-I*n,I>0==(r?D>L:D<C)){var s=c._fullLayout,l=s[i.id];m.range[r]=D,m._rl[r]=D,i.updateRadialAxis(s,l),i.xaxis.setRange(),i.xaxis.setScale(),i.yaxis.setRange(),i.yaxis.setScale();var u=!1;for(var f in i.traceHash){var h=i.traceHash[f],p=o.filterVisible(h);h[0][0].trace._module.plot(c,i,p,l),a.traceIs(f,"gl")&&p.length&&(u=!0)}u&&(k(c),A(c))}else D=null}},N.updateAngularDrag=function(t){var e=this,r=e.gd,i=e.layers,c=e.radius,f=e.angularAxis,h=e.cx,p=e.cy,d=e.cxx,m=e.cyy,y=S.angularDragBoxSize,x=g.makeDragger(i,"path","angulardrag",!1===t.dragmode?"none":"move"),b={element:x,gd:r};function _(t,e){return Math.atan2(m+y-e,t-d-y)}!1===t.dragmode?b.dragmode=!1:n.select(x).attr("d",e.pathAnnulus(c,c+y)).attr("transform",l(h,p)).call(T,"move");var M,E,L,C,P,I,O=i.frontplot.select(".scatterlayer").selectAll(".trace"),z=O.selectAll(".point"),D=O.selectAll(".textpoint");function R(c,g){var v=e.gd._fullLayout,y=v[e.id],x=_(M+c*t._invScaleX,E+g*t._invScaleY),b=F(x-I);if(C=L+b,i.frontplot.attr("transform",l(e.xOffset2,e.yOffset2)+s([-b,d,m])),e.vangles){P=e.radialAxisAngle+b;var w=l(h,p)+s(-b),T=l(h,p)+s(-P);i.bg.attr("transform",w),i["radial-grid"].attr("transform",w),i["radial-axis"].attr("transform",T),i["radial-line"].select("line").attr("transform",T),e.updateRadialAxisTitle(v,y,P)}else e.clipPaths.forTraces.select("path").attr("transform",l(d,m)+s(b));z.each((function(){var t=n.select(this),e=u.getTranslate(t);t.attr("transform",l(e.x,e.y)+s([b]))})),D.each((function(){var t=n.select(this),e=t.select("text"),r=u.getTranslate(t);t.attr("transform",s([b,e.attr("x"),e.attr("y")])+l(r.x,r.y))})),f.rotation=o.modHalf(C,360),e.updateAngularAxis(v,y),e._hasClipOnAxisFalse&&!o.isFullCircle(e.sectorInRad)&&O.call(u.hideOutsideRangePoints,e);var S=!1;for(var R in e.traceHash)if(a.traceIs(R,"gl")){var N=e.traceHash[R],j=o.filterVisible(N);N[0][0].trace._module.plot(r,e,j,y),j.length&&(S=!0)}S&&(k(r),A(r));var U={};B(U),r.emit("plotly_relayouting",U)}function B(t){t[e.id+".angularaxis.rotation"]=C,e.vangles&&(t[e.id+".radialaxis.angle"]=P)}function N(){D.select("text").attr("transform",null);var t={};B(t),a.call("_guiRelayout",r,t)}b.prepFn=function(n,i,a){var s=t[e.id];L=s.angularaxis.rotation;var l=x.getBoundingClientRect();M=i-l.left,E=a-l.top,r._fullLayout._calcInverseTransform(r);var c=o.apply3DTransform(t._invTransform)(M,E);M=c[0],E=c[1],I=_(M,E),b.moveFn=R,b.doneFn=N,w(r)},e.vangles&&!o.isFullCircle(e.sectorInRad)&&(b.prepFn=o.noop,T(n.select(x),null)),v.init(b)},N.isPtInside=function(t){if(this.isSmith)return!0;var e=this.sectorInRad,r=this.vangles,n=this.angularAxis.c2g(t.theta),i=this.radialAxis,a=i.c2l(t.r),s=i._rl;return(r?E.isPtInsidePolygon:o.isPtInsideSector)(a,n,s,e,r)},N.pathArc=function(t){var e=this.sectorInRad,r=this.vangles;return(r?E.pathPolygon:o.pathArc)(t,e[0],e[1],r)},N.pathSector=function(t){var e=this.sectorInRad,r=this.vangles;return(r?E.pathPolygon:o.pathSector)(t,e[0],e[1],r)},N.pathAnnulus=function(t,e){var r=this.sectorInRad,n=this.vangles;return(n?E.pathPolygonAnnulus:o.pathAnnulus)(t,e,r[0],r[1],n)},N.pathSubplot=function(){var t=this.innerRadius,e=this.radius;return t?this.pathAnnulus(t,e):this.pathSector(e)},N.fillViewInitialKey=function(t,e){t in this.viewInitial||(this.viewInitial[t]=e)}},{"../../components/color":366,"../../components/dragelement":385,"../../components/drawing":388,"../../components/fx":406,"../../components/titles":464,"../../constants/alignment":471,"../../lib":503,"../../lib/clear_gl_canvases":487,"../../lib/setcursor":524,"../../plot_api/subroutines":544,"../../plots/cartesian/axes":554,"../../registry":638,"../cartesian/autorange":553,"../cartesian/dragbox":563,"../cartesian/select":575,"../cartesian/set_convert":576,"../plots":619,"../smith/helpers":628,"./constants":620,"./helpers":621,"./set_convert":626,"@plotly/d3":58,tinycolor2:312}],626:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../cartesian/set_convert"),a=n.deg2rad,o=n.rad2deg;e.exports=function(t,e,r){switch(i(t,r),t._id){case"x":case"radialaxis":!function(t,e){var r=e._subplot;t.setGeometry=function(){var e=t._rl[0],n=t._rl[1],i=r.innerRadius,a=(r.radius-i)/(n-e),o=i/a,s=e>n?function(t){return t<=0}:function(t){return t>=0};t.c2g=function(r){var n=t.c2l(r)-e;return(s(n)?n:0)+o},t.g2c=function(r){return t.l2c(r+e-o)},t.g2p=function(t){return t*a},t.c2p=function(e){return t.g2p(t.c2g(e))}}}(t,e);break;case"angularaxis":!function(t,e){var r=t.type;if("linear"===r){var i=t.d2c,s=t.c2d;t.d2c=function(t,e){return function(t,e){return"degrees"===e?a(t):t}(i(t),e)},t.c2d=function(t,e){return s(function(t,e){return"degrees"===e?o(t):t}(t,e))}}t.makeCalcdata=function(e,i){var a,o,s=e[i],l=e._length,c=function(r){return t.d2c(r,e.thetaunit)};if(s){if(n.isTypedArray(s)&&"linear"===r){if(l===s.length)return s;if(s.subarray)return s.subarray(0,l)}for(a=new Array(l),o=0;o<l;o++)a[o]=c(s[o])}else{var u=i+"0",f="d"+i,h=u in e?c(e[u]):0,p=e[f]?c(e[f]):(t.period||2*Math.PI)/l;for(a=new Array(l),o=0;o<l;o++)a[o]=h+o*p}return a},t.setGeometry=function(){var i,s,l,c,u=e.sector,f=u.map(a),h={clockwise:-1,counterclockwise:1}[t.direction],p=a(t.rotation),d=function(t){return h*t+p},m=function(t){return(t-p)/h};switch(r){case"linear":s=i=n.identity,c=a,l=o,t.range=n.isFullCircle(f)?[u[0],u[0]+360]:f.map(m).map(o);break;case"category":var g=t._categories.length,v=t.period?Math.max(t.period,g):g;0===v&&(v=1),s=c=function(t){return 2*t*Math.PI/v},i=l=function(t){return t*v/Math.PI/2},t.range=[0,v]}t.c2g=function(t){return d(s(t))},t.g2c=function(t){return i(m(t))},t.t2g=function(t){return d(c(t))},t.g2t=function(t){return l(m(t))}}}(t,e)}}},{"../../lib":503,"../cartesian/set_convert":576}],627:[function(t,e,r){"use strict";e.exports={attr:"subplot",name:"smith",axisNames:["realaxis","imaginaryaxis"],axisName2dataArray:{imaginaryaxis:"imag",realaxis:"real"}}},{}],628:[function(t,e,r){"use strict";function n(t){return t<0?-1:t>0?1:0}function i(t){var e=t[0],r=t[1];if(!isFinite(e)||!isFinite(r))return[1,0];var n=(e+1)*(e+1)+r*r;return[(e*e+r*r-1)/n,2*r/n]}function a(t,e){var r=e[0],n=e[1];return[r*t.radius+t.cx,-n*t.radius+t.cy]}function o(t,e){return e*t.radius}e.exports={smith:i,reactanceArc:function(t,e,r,n){var s=a(t,i([r,e])),l=s[0],c=s[1],u=a(t,i([n,e])),f=u[0],h=u[1];if(0===e)return["M"+l+","+c,"L"+f+","+h].join(" ");var p=o(t,1/Math.abs(e));return["M"+l+","+c,"A"+p+","+p+" 0 0,"+(e<0?1:0)+" "+f+","+h].join(" ")},resistanceArc:function(t,e,r,s){var l=o(t,1/(e+1)),c=a(t,i([e,r])),u=c[0],f=c[1],h=a(t,i([e,s])),p=h[0],d=h[1];if(n(r)!==n(s)){var m=a(t,i([e,0]));return["M"+u+","+f,"A"+l+","+l+" 0 0,"+(0<r?0:1)+" "+m[0]+","+m[1],"A"+l+","+l+" 0 0,"+(s<0?0:1)+p+","+d].join(" ")}return["M"+u+","+f,"A"+l+","+l+" 0 0,"+(s<r?0:1)+" "+p+","+d].join(" ")},smithTransform:a}},{}],629:[function(t,e,r){"use strict";var n=t("../get_data").getSubplotCalcData,i=t("../../lib").counterRegex,a=t("../polar/polar"),o=t("./constants"),s=o.attr,l=o.name,c=i(l),u={};u[s]={valType:"subplotid",dflt:l,editType:"calc"},e.exports={attr:s,name:l,idRoot:l,idRegex:c,attrRegex:c,attributes:u,layoutAttributes:t("./layout_attributes"),supplyLayoutDefaults:t("./layout_defaults"),plot:function(t){for(var e=t._fullLayout,r=t.calcdata,i=e._subplots[l],o=0;o<i.length;o++){var s=i[o],c=n(r,l,s),u=e[s]._subplot;u||(u=a(t,s,!0),e[s]._subplot=u),u.plot(c,e,t._promises)}},clean:function(t,e,r,n){for(var i=n._subplots[l]||[],a=0;a<i.length;a++){var o=i[a],s=n[o]._subplot;if(!e[o]&&s)for(var c in s.framework.remove(),s.clipPaths)s.clipPaths[c].remove()}},toSVG:t("../cartesian").toSVG}},{"../../lib":503,"../cartesian":568,"../get_data":593,"../polar/polar":625,"./constants":627,"./layout_attributes":630,"./layout_defaults":631}],630:[function(t,e,r){"use strict";var n=t("../../components/color/attributes"),i=t("../cartesian/layout_attributes"),a=t("../domain").attributes,o=t("../../lib").extendFlat,s=t("../../plot_api/edit_types").overrideAll,l=s({color:i.color,showline:o({},i.showline,{dflt:!0}),linecolor:i.linecolor,linewidth:i.linewidth,showgrid:o({},i.showgrid,{dflt:!0}),gridcolor:i.gridcolor,gridwidth:i.gridwidth,griddash:i.griddash},"plot","from-root"),c=s({ticklen:i.ticklen,tickwidth:o({},i.tickwidth,{dflt:2}),tickcolor:i.tickcolor,showticklabels:i.showticklabels,showtickprefix:i.showtickprefix,tickprefix:i.tickprefix,showticksuffix:i.showticksuffix,ticksuffix:i.ticksuffix,tickfont:i.tickfont,tickformat:i.tickformat,hoverformat:i.hoverformat,layer:i.layer},"plot","from-root"),u=o({visible:o({},i.visible,{dflt:!0}),tickvals:{dflt:[.2,.5,1,2,5],valType:"data_array",editType:"plot"},tickangle:o({},i.tickangle,{dflt:90}),ticks:{valType:"enumerated",values:["top","bottom",""],editType:"ticks"},side:{valType:"enumerated",values:["top","bottom"],dflt:"top",editType:"plot"},editType:"calc"},l,c),f=o({visible:o({},i.visible,{dflt:!0}),tickvals:{valType:"data_array",editType:"plot"},ticks:i.ticks,editType:"calc"},l,c);e.exports={domain:a({name:"smith",editType:"plot"}),bgcolor:{valType:"color",editType:"plot",dflt:n.background},realaxis:u,imaginaryaxis:f,editType:"calc"}},{"../../components/color/attributes":365,"../../lib":503,"../../plot_api/edit_types":536,"../cartesian/layout_attributes":569,"../domain":584}],631:[function(t,e,r){"use strict";var n,i,a,o=t("../../lib"),s=t("../../components/color"),l=t("../../plot_api/plot_template"),c=t("../subplot_defaults"),u=t("../get_data").getSubplotData,f=t("../cartesian/prefix_suffix_defaults"),h=t("../cartesian/tick_label_defaults"),p=t("../cartesian/line_grid_defaults"),d=t("../cartesian/set_convert"),m=t("./layout_attributes"),g=t("./constants"),v=g.axisNames,y=(n=function(t){return t.slice().reverse().map((function(t){return-t})).concat([0]).concat(t)},i=String,a={},function(t){var e=i?i(t):t;if(e in a)return a[e];var r=n(t);return a[e]=r,r});function x(t,e,r,n){var i=r("bgcolor");n.bgColor=s.combine(i,n.paper_bgcolor);var a,c=u(n.fullData,g.name,n.id),x=n.layoutOut;function b(t,e){return r(a+"."+t,e)}for(var _=0;_<v.length;_++){a=v[_],o.isPlainObject(t[a])||(t[a]={});var w=t[a],T=l.newContainer(e,a);T._id=T._name=a,T._attr=n.id+"."+a,T._traceIndices=c.map((function(t){return t._expandedIndex}));var k=b("visible");if(T.type="linear",d(T,x),f(w,T,b,T.type),k){var A,M,S,E,L="realaxis"===a;if(L&&b("side"),L)b("tickvals");else b("tickvals",y(e.realaxis.tickvals||m.realaxis.tickvals.dflt));var C=n.font||{};k&&(M=(A=b("color"))===w.color?A:C.color,S=C.size,E=C.family),h(w,T,b,T.type,{noTicklabelstep:!0,noAng:!L,noExp:!0,font:{color:M,size:S,family:E}}),o.coerce2(t,e,m,a+".ticklen"),o.coerce2(t,e,m,a+".tickwidth"),o.coerce2(t,e,m,a+".tickcolor",e.color),b("ticks")||(delete e[a].ticklen,delete e[a].tickwidth,delete e[a].tickcolor),p(w,T,b,{dfltColor:A,bgColor:n.bgColor,blend:60,showLine:!0,showGrid:!0,noZeroLine:!0,attributes:m[a]}),b("layer")}b("hoverformat"),delete T.type,T._input=w}}e.exports=function(t,e,r){c(t,e,r,{noUirevision:!0,type:g.name,attributes:m,handleDefaults:x,font:e.font,paper_bgcolor:e.paper_bgcolor,fullData:r,layoutOut:e})}},{"../../components/color":366,"../../lib":503,"../../plot_api/plot_template":543,"../cartesian/line_grid_defaults":571,"../cartesian/prefix_suffix_defaults":573,"../cartesian/set_convert":576,"../cartesian/tick_label_defaults":578,"../get_data":593,"../subplot_defaults":632,"./constants":627,"./layout_attributes":630}],632:[function(t,e,r){"use strict";var n=t("../lib"),i=t("../plot_api/plot_template"),a=t("./domain").defaults;e.exports=function(t,e,r,o){var s,l,c=o.type,u=o.attributes,f=o.handleDefaults,h=o.partition||"x",p=e._subplots[c],d=p.length,m=d&&p[0].replace(/\d+$/,"");function g(t,e){return n.coerce(s,l,u,t,e)}for(var v=0;v<d;v++){var y=p[v];s=t[y]?t[y]:t[y]={},l=i.newContainer(e,y,m),o.noUirevision||g("uirevision",e.uirevision);var x={};x[h]=[v/d,(v+1)/d],a(l,e,g,x),o.id=y,f(s,l,g,o)}}},{"../lib":503,"../plot_api/plot_template":543,"./domain":584}],633:[function(t,e,r){"use strict";var n=t("../constants/docs");n.FORMAT_LINK,n.DATE_FORMAT_LINK;function i(t){var e=t.description?" "+t.description:"",r=t.keys||[];if(r.length>0){for(var n=[],i=0;i<r.length;i++)n[i]="`"+r[i]+"`";e+="Finally, the template string has access to ",e=1===r.length?"variable "+n[0]:"variables "+n.slice(0,-1).join(", ")+" and "+n.slice(-1)+"."}return e}r.hovertemplateAttrs=function(t,e){t=t||{};i(e=e||{});var r={valType:"string",dflt:"",editType:t.editType||"none"};return!1!==t.arrayOk&&(r.arrayOk=!0),r},r.texttemplateAttrs=function(t,e){t=t||{};i(e=e||{});var r={valType:"string",dflt:"",editType:t.editType||"calc"};return!1!==t.arrayOk&&(r.arrayOk=!0),r}},{"../constants/docs":474}],634:[function(t,e,r){"use strict";var n=t("./ternary"),i=t("../../plots/get_data").getSubplotCalcData,a=t("../../lib").counterRegex;r.name="ternary";var o=r.attr="subplot";r.idRoot="ternary",r.idRegex=r.attrRegex=a("ternary"),(r.attributes={})[o]={valType:"subplotid",dflt:"ternary",editType:"calc"},r.layoutAttributes=t("./layout_attributes"),r.supplyLayoutDefaults=t("./layout_defaults"),r.plot=function(t){for(var e=t._fullLayout,r=t.calcdata,a=e._subplots.ternary,o=0;o<a.length;o++){var s=a[o],l=i(r,"ternary",s),c=e[s]._subplot;c||(c=new n({id:s,graphDiv:t,container:e._ternarylayer.node()},e),e[s]._subplot=c),c.plot(l,e,t._promises)}},r.clean=function(t,e,r,n){for(var i=n._subplots.ternary||[],a=0;a<i.length;a++){var o=i[a],s=n[o]._subplot;!e[o]&&s&&(s.plotContainer.remove(),s.clipDef.remove(),s.clipDefRelative.remove(),s.layers["a-title"].remove(),s.layers["b-title"].remove(),s.layers["c-title"].remove())}}},{"../../lib":503,"../../plots/get_data":593,"./layout_attributes":635,"./layout_defaults":636,"./ternary":637}],635:[function(t,e,r){"use strict";var n=t("../../components/color/attributes"),i=t("../domain").attributes,a=t("../cartesian/layout_attributes"),o=t("../../plot_api/edit_types").overrideAll,s=t("../../lib/extend").extendFlat,l={title:{text:a.title.text,font:a.title.font},color:a.color,tickmode:a.tickmode,nticks:s({},a.nticks,{dflt:6,min:1}),tick0:a.tick0,dtick:a.dtick,tickvals:a.tickvals,ticktext:a.ticktext,ticks:a.ticks,ticklen:a.ticklen,tickwidth:a.tickwidth,tickcolor:a.tickcolor,ticklabelstep:a.ticklabelstep,showticklabels:a.showticklabels,showtickprefix:a.showtickprefix,tickprefix:a.tickprefix,showticksuffix:a.showticksuffix,ticksuffix:a.ticksuffix,showexponent:a.showexponent,exponentformat:a.exponentformat,minexponent:a.minexponent,separatethousands:a.separatethousands,tickfont:a.tickfont,tickangle:a.tickangle,tickformat:a.tickformat,tickformatstops:a.tickformatstops,hoverformat:a.hoverformat,showline:s({},a.showline,{dflt:!0}),linecolor:a.linecolor,linewidth:a.linewidth,showgrid:s({},a.showgrid,{dflt:!0}),gridcolor:a.gridcolor,gridwidth:a.gridwidth,griddash:a.griddash,layer:a.layer,min:{valType:"number",dflt:0,min:0},_deprecated:{title:a._deprecated.title,titlefont:a._deprecated.titlefont}},c=e.exports=o({domain:i({name:"ternary"}),bgcolor:{valType:"color",dflt:n.background},sum:{valType:"number",dflt:1,min:0},aaxis:l,baxis:l,caxis:l},"plot","from-root");c.uirevision={valType:"any",editType:"none"},c.aaxis.uirevision=c.baxis.uirevision=c.caxis.uirevision={valType:"any",editType:"none"}},{"../../components/color/attributes":365,"../../lib/extend":493,"../../plot_api/edit_types":536,"../cartesian/layout_attributes":569,"../domain":584}],636:[function(t,e,r){"use strict";var n=t("../../components/color"),i=t("../../plot_api/plot_template"),a=t("../../lib"),o=t("../subplot_defaults"),s=t("../cartesian/tick_label_defaults"),l=t("../cartesian/prefix_suffix_defaults"),c=t("../cartesian/tick_mark_defaults"),u=t("../cartesian/tick_value_defaults"),f=t("../cartesian/line_grid_defaults"),h=t("./layout_attributes"),p=["aaxis","baxis","caxis"];function d(t,e,r,a){var o,s,l,c=r("bgcolor"),u=r("sum");a.bgColor=n.combine(c,a.paper_bgcolor);for(var f=0;f<p.length;f++)s=t[o=p[f]]||{},(l=i.newContainer(e,o))._name=o,m(s,l,a,e);var h=e.aaxis,d=e.baxis,g=e.caxis;h.min+d.min+g.min>=u&&(h.min=0,d.min=0,g.min=0,t.aaxis&&delete t.aaxis.min,t.baxis&&delete t.baxis.min,t.caxis&&delete t.caxis.min)}function m(t,e,r,n){var i=h[e._name];function o(r,n){return a.coerce(t,e,i,r,n)}o("uirevision",n.uirevision),e.type="linear";var p=o("color"),d=p!==i.color.dflt?p:r.font.color,m=e._name.charAt(0).toUpperCase(),g="Component "+m,v=o("title.text",g);e._hovertitle=v===g?v:m,a.coerceFont(o,"title.font",{family:r.font.family,size:a.bigFont(r.font.size),color:d}),o("min"),u(t,e,o,"linear"),l(t,e,o,"linear"),s(t,e,o,"linear"),c(t,e,o,{outerTicks:!0}),o("showticklabels")&&(a.coerceFont(o,"tickfont",{family:r.font.family,size:r.font.size,color:d}),o("tickangle"),o("tickformat")),f(t,e,o,{dfltColor:p,bgColor:r.bgColor,blend:60,showLine:!0,showGrid:!0,noZeroLine:!0,attributes:i}),o("hoverformat"),o("layer")}e.exports=function(t,e,r){o(t,e,r,{type:"ternary",attributes:h,handleDefaults:d,font:e.font,paper_bgcolor:e.paper_bgcolor})}},{"../../components/color":366,"../../lib":503,"../../plot_api/plot_template":543,"../cartesian/line_grid_defaults":571,"../cartesian/prefix_suffix_defaults":573,"../cartesian/tick_label_defaults":578,"../cartesian/tick_mark_defaults":579,"../cartesian/tick_value_defaults":580,"../subplot_defaults":632,"./layout_attributes":635}],637:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("tinycolor2"),a=t("../../registry"),o=t("../../lib"),s=o.strTranslate,l=o._,c=t("../../components/color"),u=t("../../components/drawing"),f=t("../cartesian/set_convert"),h=t("../../lib/extend").extendFlat,p=t("../plots"),d=t("../cartesian/axes"),m=t("../../components/dragelement"),g=t("../../components/fx"),v=t("../../components/dragelement/helpers"),y=v.freeMode,x=v.rectMode,b=t("../../components/titles"),_=t("../cartesian/select").prepSelect,w=t("../cartesian/select").selectOnClick,T=t("../cartesian/select").clearSelect,k=t("../cartesian/select").clearSelectionsCache,A=t("../cartesian/constants");function M(t,e){this.id=t.id,this.graphDiv=t.graphDiv,this.init(e),this.makeFramework(e),this.aTickLayout=null,this.bTickLayout=null,this.cTickLayout=null}e.exports=M;var S=M.prototype;S.init=function(t){this.container=t._ternarylayer,this.defs=t._defs,this.layoutId=t._uid,this.traceHash={},this.layers={}},S.plot=function(t,e){var r=e[this.id],n=e._size;this._hasClipOnAxisFalse=!1;for(var i=0;i<t.length;i++){if(!1===t[i][0].trace.cliponaxis){this._hasClipOnAxisFalse=!0;break}}this.updateLayers(r),this.adjustLayout(r,n),p.generalUpdatePerTraceModule(this.graphDiv,this,t,r),this.layers.plotbg.select("path").call(c.fill,r.bgcolor)},S.makeFramework=function(t){var e=this.graphDiv,r=t[this.id],n=this.clipId="clip"+this.layoutId+this.id,i=this.clipIdRelative="clip-relative"+this.layoutId+this.id;this.clipDef=o.ensureSingleById(t._clips,"clipPath",n,(function(t){t.append("path").attr("d","M0,0Z")})),this.clipDefRelative=o.ensureSingleById(t._clips,"clipPath",i,(function(t){t.append("path").attr("d","M0,0Z")})),this.plotContainer=o.ensureSingle(this.container,"g",this.id),this.updateLayers(r),u.setClipUrl(this.layers.backplot,n,e),u.setClipUrl(this.layers.grids,n,e)},S.updateLayers=function(t){var e=this.layers,r=["draglayer","plotbg","backplot","grids"];"below traces"===t.aaxis.layer&&r.push("aaxis","aline"),"below traces"===t.baxis.layer&&r.push("baxis","bline"),"below traces"===t.caxis.layer&&r.push("caxis","cline"),r.push("frontplot"),"above traces"===t.aaxis.layer&&r.push("aaxis","aline"),"above traces"===t.baxis.layer&&r.push("baxis","bline"),"above traces"===t.caxis.layer&&r.push("caxis","cline");var i=this.plotContainer.selectAll("g.toplevel").data(r,String),a=["agrid","bgrid","cgrid"];i.enter().append("g").attr("class",(function(t){return"toplevel "+t})).each((function(t){var r=n.select(this);e[t]=r,"frontplot"===t?r.append("g").classed("scatterlayer",!0):"backplot"===t?r.append("g").classed("maplayer",!0):"plotbg"===t?r.append("path").attr("d","M0,0Z"):"aline"===t||"bline"===t||"cline"===t?r.append("path"):"grids"===t&&a.forEach((function(t){e[t]=r.append("g").classed("grid "+t,!0)}))})),i.order()};var E=Math.sqrt(4/3);S.adjustLayout=function(t,e){var r,n,i,a,o,l,p=this,d=t.domain,m=(d.x[0]+d.x[1])/2,g=(d.y[0]+d.y[1])/2,v=d.x[1]-d.x[0],y=d.y[1]-d.y[0],x=v*e.w,b=y*e.h,_=t.sum,w=t.aaxis.min,T=t.baxis.min,k=t.caxis.min;x>E*b?i=(a=b)*E:a=(i=x)/E,o=v*i/x,l=y*a/b,r=e.l+e.w*m-i/2,n=e.t+e.h*(1-g)-a/2,p.x0=r,p.y0=n,p.w=i,p.h=a,p.sum=_,p.xaxis={type:"linear",range:[w+2*k-_,_-w-2*T],domain:[m-o/2,m+o/2],_id:"x"},f(p.xaxis,p.graphDiv._fullLayout),p.xaxis.setScale(),p.xaxis.isPtWithinRange=function(t){return t.a>=p.aaxis.range[0]&&t.a<=p.aaxis.range[1]&&t.b>=p.baxis.range[1]&&t.b<=p.baxis.range[0]&&t.c>=p.caxis.range[1]&&t.c<=p.caxis.range[0]},p.yaxis={type:"linear",range:[w,_-T-k],domain:[g-l/2,g+l/2],_id:"y"},f(p.yaxis,p.graphDiv._fullLayout),p.yaxis.setScale(),p.yaxis.isPtWithinRange=function(){return!0};var A=p.yaxis.domain[0],M=p.aaxis=h({},t.aaxis,{range:[w,_-T-k],side:"left",tickangle:(+t.aaxis.tickangle||0)-30,domain:[A,A+l*E],anchor:"free",position:0,_id:"y",_length:i});f(M,p.graphDiv._fullLayout),M.setScale();var S=p.baxis=h({},t.baxis,{range:[_-w-k,T],side:"bottom",domain:p.xaxis.domain,anchor:"free",position:0,_id:"x",_length:i});f(S,p.graphDiv._fullLayout),S.setScale();var L=p.caxis=h({},t.caxis,{range:[_-w-T,k],side:"right",tickangle:(+t.caxis.tickangle||0)+30,domain:[A,A+l*E],anchor:"free",position:0,_id:"y",_length:i});f(L,p.graphDiv._fullLayout),L.setScale();var C="M"+r+","+(n+a)+"h"+i+"l-"+i/2+",-"+a+"Z";p.clipDef.select("path").attr("d",C),p.layers.plotbg.select("path").attr("d",C);var P="M0,"+a+"h"+i+"l-"+i/2+",-"+a+"Z";p.clipDefRelative.select("path").attr("d",P);var I=s(r,n);p.plotContainer.selectAll(".scatterlayer,.maplayer").attr("transform",I),p.clipDefRelative.select("path").attr("transform",null);var O=s(r-S._offset,n+a);p.layers.baxis.attr("transform",O),p.layers.bgrid.attr("transform",O);var z=s(r+i/2,n)+"rotate(30)"+s(0,-M._offset);p.layers.aaxis.attr("transform",z),p.layers.agrid.attr("transform",z);var D=s(r+i/2,n)+"rotate(-30)"+s(0,-L._offset);p.layers.caxis.attr("transform",D),p.layers.cgrid.attr("transform",D),p.drawAxes(!0),p.layers.aline.select("path").attr("d",M.showline?"M"+r+","+(n+a)+"l"+i/2+",-"+a:"M0,0").call(c.stroke,M.linecolor||"#000").style("stroke-width",(M.linewidth||0)+"px"),p.layers.bline.select("path").attr("d",S.showline?"M"+r+","+(n+a)+"h"+i:"M0,0").call(c.stroke,S.linecolor||"#000").style("stroke-width",(S.linewidth||0)+"px"),p.layers.cline.select("path").attr("d",L.showline?"M"+(r+i/2)+","+n+"l"+i/2+","+a:"M0,0").call(c.stroke,L.linecolor||"#000").style("stroke-width",(L.linewidth||0)+"px"),p.graphDiv._context.staticPlot||p.initInteractions(),u.setClipUrl(p.layers.frontplot,p._hasClipOnAxisFalse?null:p.clipId,p.graphDiv)},S.drawAxes=function(t){var e=this.graphDiv,r=this.id.substr(7)+"title",n=this.layers,i=this.aaxis,a=this.baxis,o=this.caxis;if(this.drawAx(i),this.drawAx(a),this.drawAx(o),t){var s=Math.max(i.showticklabels?i.tickfont.size/2:0,(o.showticklabels?.75*o.tickfont.size:0)+("outside"===o.ticks?.87*o.ticklen:0)),c=(a.showticklabels?a.tickfont.size:0)+("outside"===a.ticks?a.ticklen:0)+3;n["a-title"]=b.draw(e,"a"+r,{propContainer:i,propName:this.id+".aaxis.title",placeholder:l(e,"Click to enter Component A title"),attributes:{x:this.x0+this.w/2,y:this.y0-i.title.font.size/3-s,"text-anchor":"middle"}}),n["b-title"]=b.draw(e,"b"+r,{propContainer:a,propName:this.id+".baxis.title",placeholder:l(e,"Click to enter Component B title"),attributes:{x:this.x0-c,y:this.y0+this.h+.83*a.title.font.size+c,"text-anchor":"middle"}}),n["c-title"]=b.draw(e,"c"+r,{propContainer:o,propName:this.id+".caxis.title",placeholder:l(e,"Click to enter Component C title"),attributes:{x:this.x0+this.w+c,y:this.y0+this.h+.83*o.title.font.size+c,"text-anchor":"middle"}})}},S.drawAx=function(t){var e,r=this.graphDiv,n=t._name,i=n.charAt(0),a=t._id,s=this.layers[n],l=i+"tickLayout",c=(e=t).ticks+String(e.ticklen)+String(e.showticklabels);this[l]!==c&&(s.selectAll("."+a+"tick").remove(),this[l]=c),t.setScale();var u=d.calcTicks(t),f=d.clipEnds(t,u),h=d.makeTransTickFn(t),p=d.getTickSigns(t)[2],m=o.deg2rad(30),g=p*(t.linewidth||1)/2,v=p*t.ticklen,y=this.w,x=this.h,b="b"===i?"M0,"+g+"l"+Math.sin(m)*v+","+Math.cos(m)*v:"M"+g+",0l"+Math.cos(m)*v+","+-Math.sin(m)*v,_={a:"M0,0l"+x+",-"+y/2,b:"M0,0l-"+y/2+",-"+x,c:"M0,0l-"+x+","+y/2}[i];d.drawTicks(r,t,{vals:"inside"===t.ticks?f:u,layer:s,path:b,transFn:h,crisp:!1}),d.drawGrid(r,t,{vals:f,layer:this.layers[i+"grid"],path:_,transFn:h,crisp:!1}),d.drawLabels(r,t,{vals:u,layer:s,transFn:h,labelFns:d.makeLabelFns(t,0,30)})};var L=A.MINZOOM/2+.87,C="m-0.87,.5h"+L+"v3h-"+(L+5.2)+"l"+(L/2+2.6)+",-"+(.87*L+4.5)+"l2.6,1.5l-"+L/2+","+.87*L+"Z",P="m0.87,.5h-"+L+"v3h"+(L+5.2)+"l-"+(L/2+2.6)+",-"+(.87*L+4.5)+"l-2.6,1.5l"+L/2+","+.87*L+"Z",I="m0,1l"+L/2+","+.87*L+"l2.6,-1.5l-"+(L/2+2.6)+",-"+(.87*L+4.5)+"l-"+(L/2+2.6)+","+(.87*L+4.5)+"l2.6,1.5l"+L/2+",-"+.87*L+"Z",O=!0;function z(t){n.select(t).selectAll(".zoombox,.js-zoombox-backdrop,.js-zoombox-menu,.zoombox-corners").remove()}S.clearSelect=function(){k(this.dragOptions),T(this.dragOptions.gd)},S.initInteractions=function(){var t,e,r,n,f,h,p,d,v,b,T,k,M=this,S=M.layers.plotbg.select("path").node(),L=M.graphDiv,D=L._fullLayout._zoomlayer;function R(t){var e={};return e[M.id+".aaxis.min"]=t.a,e[M.id+".baxis.min"]=t.b,e[M.id+".caxis.min"]=t.c,e}function F(t,e){var r=L._fullLayout.clickmode;z(L),2===t&&(L.emit("plotly_doubleclick",null),a.call("_guiRelayout",L,R({a:0,b:0,c:0}))),r.indexOf("select")>-1&&1===t&&w(e,L,[M.xaxis],[M.yaxis],M.id,M.dragOptions),r.indexOf("event")>-1&&g.click(L,e,M.id)}function B(t,e){return 1-e/M.h}function N(t,e){return 1-(t+(M.h-e)/Math.sqrt(3))/M.w}function j(t,e){return(t-(M.h-e)/Math.sqrt(3))/M.w}function U(i,a){var o=r+i*t,s=n+a*e,l=Math.max(0,Math.min(1,B(0,n),B(0,s))),c=Math.max(0,Math.min(1,N(r,n),N(o,s))),u=Math.max(0,Math.min(1,j(r,n),j(o,s))),m=(l/2+u)*M.w,g=(1-l/2-c)*M.w,y=(m+g)/2,x=g-m,_=(1-l)*M.h,w=_-x/E;x<A.MINZOOM?(p=f,T.attr("d",v),k.attr("d","M0,0Z")):(p={a:f.a+l*h,b:f.b+c*h,c:f.c+u*h},T.attr("d",v+"M"+m+","+_+"H"+g+"L"+y+","+w+"L"+m+","+_+"Z"),k.attr("d","M"+r+","+n+"m0.5,0.5h5v-2h-5v-5h-2v5h-5v2h5v5h2ZM"+m+","+_+C+"M"+g+","+_+P+"M"+y+","+w+I)),b||(T.transition().style("fill",d>.2?"rgba(0,0,0,0.4)":"rgba(255,255,255,0.3)").duration(200),k.transition().style("opacity",1).duration(200),b=!0),L.emit("plotly_relayouting",R(p))}function V(){z(L),p!==f&&(a.call("_guiRelayout",L,R(p)),O&&L.data&&L._context.showTips&&(o.notifier(l(L,"Double-click to zoom back out"),"long"),O=!1))}function H(t,e){var r=t/M.xaxis._m,n=e/M.yaxis._m,i=[(p={a:f.a-n,b:f.b+(r+n)/2,c:f.c-(r-n)/2}).a,p.b,p.c].sort(o.sorterAsc),a=i.indexOf(p.a),l=i.indexOf(p.b),c=i.indexOf(p.c);i[0]<0&&(i[1]+i[0]/2<0?(i[2]+=i[0]+i[1],i[0]=i[1]=0):(i[2]+=i[0]/2,i[1]+=i[0]/2,i[0]=0),p={a:i[a],b:i[l],c:i[c]},e=(f.a-p.a)*M.yaxis._m,t=(f.c-p.c-f.b+p.b)*M.xaxis._m);var h=s(M.x0+t,M.y0+e);M.plotContainer.selectAll(".scatterlayer,.maplayer").attr("transform",h);var d=s(-t,-e);M.clipDefRelative.select("path").attr("transform",d),M.aaxis.range=[p.a,M.sum-p.b-p.c],M.baxis.range=[M.sum-p.a-p.c,p.b],M.caxis.range=[M.sum-p.a-p.b,p.c],M.drawAxes(!1),M._hasClipOnAxisFalse&&M.plotContainer.select(".scatterlayer").selectAll(".trace").call(u.hideOutsideRangePoints,M),L.emit("plotly_relayouting",R(p))}function q(){a.call("_guiRelayout",L,R(p))}this.dragOptions={element:S,gd:L,plotinfo:{id:M.id,domain:L._fullLayout[M.id].domain,xaxis:M.xaxis,yaxis:M.yaxis},subplot:M.id,prepFn:function(a,l,u){M.dragOptions.xaxes=[M.xaxis],M.dragOptions.yaxes=[M.yaxis],t=L._fullLayout._invScaleX,e=L._fullLayout._invScaleY;var m=M.dragOptions.dragmode=L._fullLayout.dragmode;y(m)?M.dragOptions.minDrag=1:M.dragOptions.minDrag=void 0,"zoom"===m?(M.dragOptions.moveFn=U,M.dragOptions.clickFn=F,M.dragOptions.doneFn=V,function(t,e,a){var l=S.getBoundingClientRect();r=e-l.left,n=a-l.top,L._fullLayout._calcInverseTransform(L);var u=L._fullLayout._invTransform,m=o.apply3DTransform(u)(r,n);r=m[0],n=m[1],f={a:M.aaxis.range[0],b:M.baxis.range[1],c:M.caxis.range[1]},p=f,h=M.aaxis.range[1]-f.a,d=i(M.graphDiv._fullLayout[M.id].bgcolor).getLuminance(),v="M0,"+M.h+"L"+M.w/2+", 0L"+M.w+","+M.h+"Z",b=!1,T=D.append("path").attr("class","zoombox").attr("transform",s(M.x0,M.y0)).style({fill:d>.2?"rgba(0,0,0,0)":"rgba(255,255,255,0)","stroke-width":0}).attr("d",v),k=D.append("path").attr("class","zoombox-corners").attr("transform",s(M.x0,M.y0)).style({fill:c.background,stroke:c.defaultLine,"stroke-width":1,opacity:0}).attr("d","M0,0Z"),M.clearSelect(L)}(0,l,u)):"pan"===m?(M.dragOptions.moveFn=H,M.dragOptions.clickFn=F,M.dragOptions.doneFn=q,f={a:M.aaxis.range[0],b:M.baxis.range[1],c:M.caxis.range[1]},p=f,M.clearSelect(L)):(x(m)||y(m))&&_(a,l,u,M.dragOptions,m)}},S.onmousemove=function(t){g.hover(L,t,M.id),L._fullLayout._lasthover=S,L._fullLayout._hoversubplot=M.id},S.onmouseout=function(t){L._dragging||m.unhover(L,t)},m.init(this.dragOptions)}},{"../../components/color":366,"../../components/dragelement":385,"../../components/dragelement/helpers":384,"../../components/drawing":388,"../../components/fx":406,"../../components/titles":464,"../../lib":503,"../../lib/extend":493,"../../registry":638,"../cartesian/axes":554,"../cartesian/constants":561,"../cartesian/select":575,"../cartesian/set_convert":576,"../plots":619,"@plotly/d3":58,tinycolor2:312}],638:[function(t,e,r){"use strict";var n=t("./lib/loggers"),i=t("./lib/noop"),a=t("./lib/push_unique"),o=t("./lib/is_plain_object"),s=t("./lib/dom").addStyleRule,l=t("./lib/extend"),c=t("./plots/attributes"),u=t("./plots/layout_attributes"),f=l.extendFlat,h=l.extendDeepAll;function p(t){var e=t.name,i=t.categories,a=t.meta;if(r.modules[e])n.log("Type "+e+" already registered");else{r.subplotsRegistry[t.basePlotModule.name]||function(t){var e=t.name;if(r.subplotsRegistry[e])return void n.log("Plot type "+e+" already registered.");for(var i in v(t),r.subplotsRegistry[e]=t,r.componentsRegistry)b(i,t.name)}(t.basePlotModule);for(var o={},l=0;l<i.length;l++)o[i[l]]=!0,r.allCategories[i[l]]=!0;for(var c in r.modules[e]={_module:t,categories:o},a&&Object.keys(a).length&&(r.modules[e].meta=a),r.allTypes.push(e),r.componentsRegistry)y(c,e);t.layoutAttributes&&f(r.traceLayoutAttributes,t.layoutAttributes);var u=t.basePlotModule,h=u.name;if("mapbox"===h){var p=u.constants.styleRules;for(var d in p)s(".js-plotly-plot .plotly .mapboxgl-"+d,p[d])}"geo"!==h&&"mapbox"!==h||void 0!==window.PlotlyGeoAssets||(window.PlotlyGeoAssets={topojson:{}})}}function d(t){if("string"!=typeof t.name)throw new Error("Component module *name* must be a string.");var e=t.name;for(var n in r.componentsRegistry[e]=t,t.layoutAttributes&&(t.layoutAttributes._isLinkedToArray&&a(r.layoutArrayContainers,e),v(t)),r.modules)y(e,n);for(var i in r.subplotsRegistry)b(e,i);for(var o in r.transformsRegistry)x(e,o);t.schema&&t.schema.layout&&h(u,t.schema.layout)}function m(t){if("string"!=typeof t.name)throw new Error("Transform module *name* must be a string.");var e="Transform module "+t.name,i="function"==typeof t.transform,a="function"==typeof t.calcTransform;if(!i&&!a)throw new Error(e+" is missing a *transform* or *calcTransform* method.");for(var s in i&&a&&n.log([e+" has both a *transform* and *calcTransform* methods.","Please note that all *transform* methods are executed","before all *calcTransform* methods."].join(" ")),o(t.attributes)||n.log(e+" registered without an *attributes* object."),"function"!=typeof t.supplyDefaults&&n.log(e+" registered without a *supplyDefaults* method."),r.transformsRegistry[t.name]=t,r.componentsRegistry)x(s,t.name)}function g(t){var e=t.name,n=e.split("-")[0],i=t.dictionary,a=t.format,o=i&&Object.keys(i).length,s=a&&Object.keys(a).length,l=r.localeRegistry,c=l[e];if(c||(l[e]=c={}),n!==e){var u=l[n];u||(l[n]=u={}),o&&u.dictionary===c.dictionary&&(u.dictionary=i),s&&u.format===c.format&&(u.format=a)}o&&(c.dictionary=i),s&&(c.format=a)}function v(t){if(t.layoutAttributes){var e=t.layoutAttributes._arrayAttrRegexps;if(e)for(var n=0;n<e.length;n++)a(r.layoutArrayRegexes,e[n])}}function y(t,e){var n=r.componentsRegistry[t].schema;if(n&&n.traces){var i=n.traces[e];i&&h(r.modules[e]._module.attributes,i)}}function x(t,e){var n=r.componentsRegistry[t].schema;if(n&&n.transforms){var i=n.transforms[e];i&&h(r.transformsRegistry[e].attributes,i)}}function b(t,e){var n=r.componentsRegistry[t].schema;if(n&&n.subplots){var i=r.subplotsRegistry[e],a=i.layoutAttributes,o="subplot"===i.attr?i.name:i.attr;Array.isArray(o)&&(o=o[0]);var s=n.subplots[o];a&&s&&h(a,s)}}function _(t){return"object"==typeof t&&(t=t.type),t}r.modules={},r.allCategories={},r.allTypes=[],r.subplotsRegistry={},r.transformsRegistry={},r.componentsRegistry={},r.layoutArrayContainers=[],r.layoutArrayRegexes=[],r.traceLayoutAttributes={},r.localeRegistry={},r.apiMethodRegistry={},r.collectableSubplotTypes=null,r.register=function(t){if(r.collectableSubplotTypes=null,!t)throw new Error("No argument passed to Plotly.register.");t&&!Array.isArray(t)&&(t=[t]);for(var e=0;e<t.length;e++){var n=t[e];if(!n)throw new Error("Invalid module was attempted to be registered!");switch(n.moduleType){case"trace":p(n);break;case"transform":m(n);break;case"component":d(n);break;case"locale":g(n);break;case"apiMethod":var i=n.name;r.apiMethodRegistry[i]=n.fn;break;default:throw new Error("Invalid module was attempted to be registered!")}}},r.getModule=function(t){var e=r.modules[_(t)];return!!e&&e._module},r.traceIs=function(t,e){if("various"===(t=_(t)))return!1;var i=r.modules[t];return i||(t&&n.log("Unrecognized trace type "+t+"."),i=r.modules[c.type.dflt]),!!i.categories[e]},r.getTransformIndices=function(t,e){for(var r=[],n=t.transforms||[],i=0;i<n.length;i++)n[i].type===e&&r.push(i);return r},r.hasTransform=function(t,e){for(var r=t.transforms||[],n=0;n<r.length;n++)if(r[n].type===e)return!0;return!1},r.getComponentMethod=function(t,e){var n=r.componentsRegistry[t];return n&&n[e]||i},r.call=function(){var t=arguments[0],e=[].slice.call(arguments,1);return r.apiMethodRegistry[t].apply(null,e)}},{"./lib/dom":491,"./lib/extend":493,"./lib/is_plain_object":504,"./lib/loggers":507,"./lib/noop":512,"./lib/push_unique":518,"./plots/attributes":550,"./plots/layout_attributes":610}],639:[function(t,e,r){"use strict";var n=t("../registry"),i=t("../lib"),a=i.extendFlat,o=i.extendDeep;function s(t){var e;switch(t){case"themes__thumb":e={autosize:!0,width:150,height:150,title:{text:""},showlegend:!1,margin:{l:5,r:5,t:5,b:5,pad:0},annotations:[]};break;case"thumbnail":e={title:{text:""},hidesources:!0,showlegend:!1,borderwidth:0,bordercolor:"",margin:{l:1,r:1,t:1,b:1,pad:0},annotations:[]};break;default:e={}}return e}e.exports=function(t,e){var r,i,l=t.data,c=t.layout,u=o([],l),f=o({},c,s(e.tileClass)),h=t._context||{};if(e.width&&(f.width=e.width),e.height&&(f.height=e.height),"thumbnail"===e.tileClass||"themes__thumb"===e.tileClass){f.annotations=[];var p=Object.keys(f);for(r=0;r<p.length;r++)i=p[r],["xaxis","yaxis","zaxis"].indexOf(i.slice(0,5))>-1&&(f[p[r]].title={text:""});for(r=0;r<u.length;r++){var d=u[r];d.showscale=!1,d.marker&&(d.marker.showscale=!1),n.traceIs(d,"pie-like")&&(d.textposition="none")}}if(Array.isArray(e.annotations))for(r=0;r<e.annotations.length;r++)f.annotations.push(e.annotations[r]);var m=Object.keys(f).filter((function(t){return t.match(/^scene\d*$/)}));if(m.length){var g={};for("thumbnail"===e.tileClass&&(g={title:{text:""},showaxeslabels:!1,showticklabels:!1,linetickenable:!1}),r=0;r<m.length;r++){var v=f[m[r]];v.xaxis||(v.xaxis={}),v.yaxis||(v.yaxis={}),v.zaxis||(v.zaxis={}),a(v.xaxis,g),a(v.yaxis,g),a(v.zaxis,g),v._scene=null}}var y=document.createElement("div");e.tileClass&&(y.className=e.tileClass);var x={gd:y,td:y,layout:f,data:u,config:{staticPlot:void 0===e.staticPlot||e.staticPlot,plotGlPixelRatio:void 0===e.plotGlPixelRatio?2:e.plotGlPixelRatio,displaylogo:e.displaylogo||!1,showLink:e.showLink||!1,showTips:e.showTips||!1,mapboxAccessToken:h.mapboxAccessToken}};return"transparent"!==e.setBackground&&(x.config.setBackground=e.setBackground||"opaque"),x.gd.defaultLayout=s(e.tileClass),x}},{"../lib":503,"../registry":638}],640:[function(t,e,r){"use strict";var n=t("../lib"),i=t("../plot_api/to_image"),a=t("./filesaver"),o=t("./helpers");e.exports=function(t,e){var r;return n.isPlainObject(t)||(r=n.getGraphDiv(t)),(e=e||{}).format=e.format||"png",e.width=e.width||null,e.height=e.height||null,e.imageDataOnly=!0,new Promise((function(s,l){r&&r._snapshotInProgress&&l(new Error("Snapshotting already in progress.")),n.isIE()&&"svg"!==e.format&&l(new Error(o.MSG_IE_BAD_FORMAT)),r&&(r._snapshotInProgress=!0);var c=i(t,e),u=e.filename||t.fn||"newplot";u+="."+e.format.replace("-","."),c.then((function(t){return r&&(r._snapshotInProgress=!1),a(t,u,e.format)})).then((function(t){s(t)})).catch((function(t){r&&(r._snapshotInProgress=!1),l(t)}))}))}},{"../lib":503,"../plot_api/to_image":546,"./filesaver":641,"./helpers":642}],641:[function(t,e,r){"use strict";var n=t("../lib"),i=t("./helpers");e.exports=function(t,e,r){var a=document.createElement("a"),o="download"in a;return new Promise((function(s,l){var c,u;if(n.isIE())return c=i.createBlob(t,"svg"),window.navigator.msSaveBlob(c,e),c=null,s(e);if(o)return c=i.createBlob(t,r),u=i.createObjectURL(c),a.href=u,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),i.revokeObjectURL(u),c=null,s(e);if(n.isSafari()){var f="svg"===r?",":";base64,";return i.octetStream(f+encodeURIComponent(t)),s(e)}l(new Error("download error"))}))}},{"../lib":503,"./helpers":642}],642:[function(t,e,r){"use strict";var n=t("../registry");r.getDelay=function(t){return t._has&&(t._has("gl3d")||t._has("gl2d")||t._has("mapbox"))?500:0},r.getRedrawFunc=function(t){return function(){n.getComponentMethod("colorbar","draw")(t)}},r.encodeSVG=function(t){return"data:image/svg+xml,"+encodeURIComponent(t)},r.encodeJSON=function(t){return"data:application/json,"+encodeURIComponent(t)};var i=window.URL||window.webkitURL;r.createObjectURL=function(t){return i.createObjectURL(t)},r.revokeObjectURL=function(t){return i.revokeObjectURL(t)},r.createBlob=function(t,e){if("svg"===e)return new window.Blob([t],{type:"image/svg+xml;charset=utf-8"});if("full-json"===e)return new window.Blob([t],{type:"application/json;charset=utf-8"});var r=function(t){for(var e=t.length,r=new ArrayBuffer(e),n=new Uint8Array(r),i=0;i<e;i++)n[i]=t.charCodeAt(i);return r}(window.atob(t));return new window.Blob([r],{type:"image/"+e})},r.octetStream=function(t){document.location.href="data:application/octet-stream"+t},r.IMAGE_URL_PREFIX=/^data:image\/\w+;base64,/,r.MSG_IE_BAD_FORMAT="Sorry IE does not support downloading from canvas. Try {format:'svg'} instead."},{"../registry":638}],643:[function(t,e,r){"use strict";var n=t("./helpers"),i={getDelay:n.getDelay,getRedrawFunc:n.getRedrawFunc,clone:t("./cloneplot"),toSVG:t("./tosvg"),svgToImg:t("./svgtoimg"),toImage:t("./toimage"),downloadImage:t("./download")};e.exports=i},{"./cloneplot":639,"./download":640,"./helpers":642,"./svgtoimg":644,"./toimage":645,"./tosvg":646}],644:[function(t,e,r){"use strict";var n=t("../lib"),i=t("events").EventEmitter,a=t("./helpers");e.exports=function(t){var e=t.emitter||new i,r=new Promise((function(i,o){var s=window.Image,l=t.svg,c=t.format||"png";if(n.isIE()&&"svg"!==c){var u=new Error(a.MSG_IE_BAD_FORMAT);return o(u),t.promise?r:e.emit("error",u)}var f,h,p=t.canvas,d=t.scale||1,m=t.width||300,g=t.height||150,v=d*m,y=d*g,x=p.getContext("2d",{willReadFrequently:!0}),b=new s;"svg"===c||n.isSafari()?h=a.encodeSVG(l):(f=a.createBlob(l,"svg"),h=a.createObjectURL(f)),p.width=v,p.height=y,b.onload=function(){var r;switch(f=null,a.revokeObjectURL(h),"svg"!==c&&x.drawImage(b,0,0,v,y),c){case"jpeg":r=p.toDataURL("image/jpeg");break;case"png":r=p.toDataURL("image/png");break;case"webp":r=p.toDataURL("image/webp");break;case"svg":r=h;break;default:var n="Image format is not jpeg, png, svg or webp.";if(o(new Error(n)),!t.promise)return e.emit("error",n)}i(r),t.promise||e.emit("success",r)},b.onerror=function(r){if(f=null,a.revokeObjectURL(h),o(r),!t.promise)return e.emit("error",r)},b.src=h}));return t.promise?r:e}},{"../lib":503,"./helpers":642,events:84}],645:[function(t,e,r){"use strict";var n=t("events").EventEmitter,i=t("../registry"),a=t("../lib"),o=t("./helpers"),s=t("./cloneplot"),l=t("./tosvg"),c=t("./svgtoimg");e.exports=function(t,e){var r=new n,u=s(t,{format:"png"}),f=u.gd;f.style.position="absolute",f.style.left="-5000px",document.body.appendChild(f);var h=o.getRedrawFunc(f);return i.call("_doPlot",f,u.data,u.layout,u.config).then(h).then((function(){var t=o.getDelay(f._fullLayout);setTimeout((function(){var t=l(f),n=document.createElement("canvas");n.id=a.randstr(),(r=c({format:e.format,width:f._fullLayout.width,height:f._fullLayout.height,canvas:n,emitter:r,svg:t})).clean=function(){f&&document.body.removeChild(f)}}),t)})).catch((function(t){r.emit("error",t)})),r}},{"../lib":503,"../registry":638,"./cloneplot":639,"./helpers":642,"./svgtoimg":644,"./tosvg":646,events:84}],646:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../lib"),a=t("../components/drawing"),o=t("../components/color"),s=t("../constants/xmlns_namespaces"),l=/"/g,c=new RegExp('("TOBESTRIPPED)|(TOBESTRIPPED")',"g");e.exports=function(t,e,r){var u,f=t._fullLayout,h=f._paper,p=f._toppaper,d=f.width,m=f.height;h.insert("rect",":first-child").call(a.setRect,0,0,d,m).call(o.fill,f.paper_bgcolor);var g=f._basePlotModules||[];for(u=0;u<g.length;u++){var v=g[u];v.toSVG&&v.toSVG(t)}if(p){var y=p.node().childNodes,x=Array.prototype.slice.call(y);for(u=0;u<x.length;u++){var b=x[u];b.childNodes.length&&h.node().appendChild(b)}}f._draggers&&f._draggers.remove(),h.node().style.background="",h.selectAll("text").attr({"data-unformatted":null,"data-math":null}).each((function(){var t=n.select(this);if("hidden"!==this.style.visibility&&"none"!==this.style.display){t.style({visibility:null,display:null});var e=this.style.fontFamily;e&&-1!==e.indexOf('"')&&t.style("font-family",e.replace(l,"TOBESTRIPPED"))}else t.remove()})),h.selectAll(".gradient_filled,.pattern_filled").each((function(){var t=n.select(this),e=this.style.fill;e&&-1!==e.indexOf("url(")&&t.style("fill",e.replace(l,"TOBESTRIPPED"));var r=this.style.stroke;r&&-1!==r.indexOf("url(")&&t.style("stroke",r.replace(l,"TOBESTRIPPED"))})),"pdf"!==e&&"eps"!==e||h.selectAll("#MathJax_SVG_glyphs path").attr("stroke-width",0),h.node().setAttributeNS(s.xmlns,"xmlns",s.svg),h.node().setAttributeNS(s.xmlns,"xmlns:xlink",s.xlink),"svg"===e&&r&&(h.attr("width",r*d),h.attr("height",r*m),h.attr("viewBox","0 0 "+d+" "+m));var _=(new window.XMLSerializer).serializeToString(h.node());return _=function(t){var e=n.select("body").append("div").style({display:"none"}).html(""),r=t.replace(/(&[^;]*;)/gi,(function(t){return"&lt;"===t?"&#60;":"&rt;"===t?"&#62;":-1!==t.indexOf("<")||-1!==t.indexOf(">")?"":e.html(t).text()}));return e.remove(),r}(_),_=(_=_.replace(/&(?!\w+;|\#[0-9]+;| \#x[0-9A-F]+;)/g,"&amp;")).replace(c,"'"),i.isIE()&&(_=(_=(_=_.replace(/"/gi,"'")).replace(/(\('#)([^']*)('\))/gi,'("#$2")')).replace(/(\\')/gi,'"')),_}},{"../components/color":366,"../components/drawing":388,"../constants/xmlns_namespaces":480,"../lib":503,"@plotly/d3":58}],647:[function(t,e,r){"use strict";var n=t("../../lib");e.exports=function(t,e){for(var r=0;r<t.length;r++)t[r].i=r;n.mergeArray(e.text,t,"tx"),n.mergeArray(e.hovertext,t,"htx");var i=e.marker;if(i){n.mergeArray(i.opacity,t,"mo",!0),n.mergeArray(i.color,t,"mc");var a=i.line;a&&(n.mergeArray(a.color,t,"mlc"),n.mergeArrayCastPositive(a.width,t,"mlw"))}}},{"../../lib":503}],648:[function(t,e,r){"use strict";var n=t("../scatter/attributes"),i=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,a=t("../../plots/template_attributes").hovertemplateAttrs,o=t("../../plots/template_attributes").texttemplateAttrs,s=t("../../components/colorscale/attributes"),l=t("../../plots/font_attributes"),c=t("./constants"),u=t("../../components/drawing/attributes").pattern,f=t("../../lib/extend").extendFlat,h=l({editType:"calc",arrayOk:!0,colorEditType:"style"}),p=f({},n.marker.line.width,{dflt:0}),d=f({width:p,editType:"calc"},s("marker.line")),m=f({line:d,editType:"calc"},s("marker"),{opacity:{valType:"number",arrayOk:!0,dflt:1,min:0,max:1,editType:"style"},pattern:u});e.exports={x:n.x,x0:n.x0,dx:n.dx,y:n.y,y0:n.y0,dy:n.dy,xperiod:n.xperiod,yperiod:n.yperiod,xperiod0:n.xperiod0,yperiod0:n.yperiod0,xperiodalignment:n.xperiodalignment,yperiodalignment:n.yperiodalignment,xhoverformat:i("x"),yhoverformat:i("y"),text:n.text,texttemplate:o({editType:"plot"},{keys:c.eventDataKeys}),hovertext:n.hovertext,hovertemplate:a({},{keys:c.eventDataKeys}),textposition:{valType:"enumerated",values:["inside","outside","auto","none"],dflt:"auto",arrayOk:!0,editType:"calc"},insidetextanchor:{valType:"enumerated",values:["end","middle","start"],dflt:"end",editType:"plot"},textangle:{valType:"angle",dflt:"auto",editType:"plot"},textfont:f({},h,{}),insidetextfont:f({},h,{}),outsidetextfont:f({},h,{}),constraintext:{valType:"enumerated",values:["inside","outside","both","none"],dflt:"both",editType:"calc"},cliponaxis:f({},n.cliponaxis,{}),orientation:{valType:"enumerated",values:["v","h"],editType:"calc+clearAxisTypes"},base:{valType:"any",dflt:null,arrayOk:!0,editType:"calc"},offset:{valType:"number",dflt:null,arrayOk:!0,editType:"calc"},width:{valType:"number",dflt:null,min:0,arrayOk:!0,editType:"calc"},marker:m,offsetgroup:{valType:"string",dflt:"",editType:"calc"},alignmentgroup:{valType:"string",dflt:"",editType:"calc"},selected:{marker:{opacity:n.selected.marker.opacity,color:n.selected.marker.color,editType:"style"},textfont:n.selected.textfont,editType:"style"},unselected:{marker:{opacity:n.unselected.marker.opacity,color:n.unselected.marker.color,editType:"style"},textfont:n.unselected.textfont,editType:"style"},_deprecated:{bardir:{valType:"enumerated",editType:"calc",values:["v","h"]}}}},{"../../components/colorscale/attributes":373,"../../components/drawing/attributes":387,"../../lib/extend":493,"../../plots/cartesian/axis_format_attributes":557,"../../plots/font_attributes":585,"../../plots/template_attributes":633,"../scatter/attributes":927,"./constants":650}],649:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes"),i=t("../../plots/cartesian/align_period"),a=t("../../components/colorscale/helpers").hasColorscale,o=t("../../components/colorscale/calc"),s=t("./arrays_to_calcdata"),l=t("../scatter/calc_selection");e.exports=function(t,e){var r,c,u,f,h,p,d=n.getFromId(t,e.xaxis||"x"),m=n.getFromId(t,e.yaxis||"y"),g={msUTC:!(!e.base&&0!==e.base)};"h"===e.orientation?(r=d.makeCalcdata(e,"x",g),u=m.makeCalcdata(e,"y"),f=i(e,m,"y",u),h=!!e.yperiodalignment,p="y"):(r=m.makeCalcdata(e,"y",g),u=d.makeCalcdata(e,"x"),f=i(e,d,"x",u),h=!!e.xperiodalignment,p="x"),c=f.vals;for(var v=Math.min(c.length,r.length),y=new Array(v),x=0;x<v;x++)y[x]={p:c[x],s:r[x]},h&&(y[x].orig_p=u[x],y[x][p+"End"]=f.ends[x],y[x][p+"Start"]=f.starts[x]),e.ids&&(y[x].id=String(e.ids[x]));return a(e,"marker")&&o(t,e,{vals:e.marker.color,containerStr:"marker",cLetter:"c"}),a(e,"marker.line")&&o(t,e,{vals:e.marker.line.color,containerStr:"marker.line",cLetter:"c"}),s(y,e),l(y,e),y}},{"../../components/colorscale/calc":374,"../../components/colorscale/helpers":377,"../../plots/cartesian/align_period":551,"../../plots/cartesian/axes":554,"../scatter/calc_selection":929,"./arrays_to_calcdata":647}],650:[function(t,e,r){"use strict";e.exports={TEXTPAD:3,eventDataKeys:["value","label"]}},{}],651:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib").isArrayOrTypedArray,a=t("../../constants/numerical").BADNUM,o=t("../../registry"),s=t("../../plots/cartesian/axes"),l=t("../../plots/cartesian/constraints").getAxisGroup,c=t("./sieve.js");function u(t,e,r,o,u){if(o.length){var b,_,w,T;switch(function(t,e){var r,a;for(r=0;r<e.length;r++){var o,s=e[r],l=s[0].trace,c="funnel"===l.type?l._base:l.base,u="h"===l.orientation?l.xcalendar:l.ycalendar,f="category"===t.type||"multicategory"===t.type?function(){return null}:t.d2c;if(i(c)){for(a=0;a<Math.min(c.length,s.length);a++)o=f(c[a],0,u),n(o)?(s[a].b=+o,s[a].hasB=1):s[a].b=0;for(;a<s.length;a++)s[a].b=0}else{o=f(c,0,u);var h=n(o);for(o=h?o:0,a=0;a<s.length;a++)s[a].b=o,h&&(s[a].hasB=1)}}}(r,o),u.mode){case"overlay":f(e,r,o,u);break;case"group":for(b=[],_=[],w=0;w<o.length;w++)void 0===(T=o[w])[0].trace.offset?_.push(T):b.push(T);_.length&&function(t,e,r,n,i){var o=new c(n,{posAxis:e,sepNegVal:!1,overlapNoMerge:!i.norm});(function(t,e,r,n){for(var i=t._fullLayout,a=r.positions,o=r.distinctPositions,s=r.minDiff,c=r.traces,u=c.length,f=a.length!==o.length,h=s*(1-n.gap),g=l(i,e._id)+c[0][0].trace.orientation,v=i._alignmentOpts[g]||{},y=0;y<u;y++){var x,b,_=c[y],w=_[0].trace,T=v[w.alignmentgroup]||{},k=Object.keys(T.offsetGroups||{}).length,A=(x=k?h/k:f?h/u:h)*(1-(n.groupgap||0));b=k?((2*w._offsetIndex+1-k)*x-A)/2:f?((2*y+1-u)*x-A)/2:-A/2;var M=_[0].t;M.barwidth=A,M.poffset=b,M.bargroupwidth=h,M.bardelta=s}r.binWidth=c[0][0].t.barwidth/100,p(r),d(e,r),m(e,r,f)})(t,e,o,i),function(t,e){for(var r=t.traces,n=0;n<r.length;n++){var i=r[n];if(void 0===i[0].trace.base)for(var o=new c([i],{posAxis:e,sepNegVal:!0,overlapNoMerge:!0}),s=0;s<i.length;s++){var l=i[s];if(l.p!==a){var u=o.put(l.p,l.b+l.s);u&&(l.b=u)}}}}(o,e),i.norm?(v(o),y(r,o,i)):g(r,o)}(t,e,r,_,u),b.length&&f(e,r,b,u);break;case"stack":case"relative":for(b=[],_=[],w=0;w<o.length;w++)void 0===(T=o[w])[0].trace.base?_.push(T):b.push(T);_.length&&function(t,e,r,n,i){var o=new c(n,{posAxis:e,sepNegVal:"relative"===i.mode,overlapNoMerge:!(i.norm||"stack"===i.mode||"relative"===i.mode)});h(e,o,i),function(t,e,r){var n,i,o,l,c,u,f=x(t),h=e.traces;for(l=0;l<h.length;l++)if(n=h[l],"funnel"===(i=n[0].trace).type)for(c=0;c<n.length;c++)(u=n[c]).s!==a&&e.put(u.p,-.5*u.s);for(l=0;l<h.length;l++){n=h[l],i=n[0].trace,o="funnel"===i.type;var p=[];for(c=0;c<n.length;c++)if((u=n[c]).s!==a){var d;d=o?u.s:u.s+u.b;var m=e.put(u.p,d),g=m+d;u.b=m,u[f]=g,r.norm||(p.push(g),u.hasB&&p.push(m))}r.norm||(i._extremes[t._id]=s.findExtremes(t,p,{tozero:!0,padded:!0}))}}(r,o,i);for(var l=0;l<n.length;l++)for(var u=n[l],f=0;f<u.length;f++){var p=u[f];if(p.s!==a)p.b+p.s===o.get(p.p,p.s)&&(p._outmost=!0)}i.norm&&y(r,o,i)}(0,e,r,_,u),b.length&&f(e,r,b,u)}!function(t,e){var r,i,a,o=x(e),s={},l=1/0,c=-1/0;for(r=0;r<t.length;r++)for(a=t[r],i=0;i<a.length;i++){var u=a[i].p;n(u)&&(l=Math.min(l,u),c=Math.max(c,u))}var f=1e4/(c-l),h=s.round=function(t){return String(Math.round(f*(t-l)))};for(r=0;r<t.length;r++){(a=t[r])[0].t.extents=s;var p=a[0].t.poffset,d=Array.isArray(p);for(i=0;i<a.length;i++){var m=a[i],g=m[o]-m.w/2;if(n(g)){var v=m[o]+m.w/2,y=h(m.p);s[y]?s[y]=[Math.min(g,s[y][0]),Math.max(v,s[y][1])]:s[y]=[g,v]}m.p0=m.p+(d?p[i]:p),m.p1=m.p0+m.w,m.s0=m.b,m.s1=m.s0+m.s}}}(o,e)}}function f(t,e,r,n){for(var i=0;i<r.length;i++){var a=r[i],o=new c([a],{posAxis:t,sepNegVal:!1,overlapNoMerge:!n.norm});h(t,o,n),n.norm?(v(o),y(e,o,n)):g(e,o)}}function h(t,e,r){for(var n=e.minDiff,i=e.traces,a=n*(1-r.gap),o=a*(1-(r.groupgap||0)),s=-o/2,l=0;l<i.length;l++){var c=i[l][0].t;c.barwidth=o,c.poffset=s,c.bargroupwidth=a,c.bardelta=n}e.binWidth=i[0][0].t.barwidth/100,p(e),d(t,e),m(t,e)}function p(t){var e,r,a=t.traces;for(e=0;e<a.length;e++){var o,s=a[e],l=s[0],c=l.trace,u=l.t,f=c._offset||c.offset,h=u.poffset;if(i(f)){for(o=Array.prototype.slice.call(f,0,s.length),r=0;r<o.length;r++)n(o[r])||(o[r]=h);for(r=o.length;r<s.length;r++)o.push(h);u.poffset=o}else void 0!==f&&(u.poffset=f);var p=c._width||c.width,d=u.barwidth;if(i(p)){var m=Array.prototype.slice.call(p,0,s.length);for(r=0;r<m.length;r++)n(m[r])||(m[r]=d);for(r=m.length;r<s.length;r++)m.push(d);if(u.barwidth=m,void 0===f){for(o=[],r=0;r<s.length;r++)o.push(h+(d-m[r])/2);u.poffset=o}}else void 0!==p&&(u.barwidth=p,void 0===f&&(u.poffset=h+(d-p)/2))}}function d(t,e){for(var r=e.traces,n=x(t),i=0;i<r.length;i++)for(var a=r[i],o=a[0].t,s=o.poffset,l=Array.isArray(s),c=o.barwidth,u=Array.isArray(c),f=0;f<a.length;f++){var h=a[f],p=h.w=u?c[f]:c;h[n]=h.p+(l?s[f]:s)+p/2}}function m(t,e,r){var n=e.traces,i=e.minDiff/2;s.minDtick(t,e.minDiff,e.distinctPositions[0],r);for(var a=0;a<n.length;a++){var o,l,c,u,f=n[a],h=f[0],p=h.trace,d=[];for(u=0;u<f.length;u++)l=(o=f[u]).p-i,c=o.p+i,d.push(l,c);if(p.width||p.offset){var m=h.t,g=m.poffset,v=m.barwidth,y=Array.isArray(g),x=Array.isArray(v);for(u=0;u<f.length;u++){o=f[u];var b=y?g[u]:g,_=x?v[u]:v;c=(l=o.p+b)+_,d.push(l,c)}}p._extremes[t._id]=s.findExtremes(t,d,{padded:!1})}}function g(t,e){for(var r=e.traces,n=x(t),i=0;i<r.length;i++){for(var a=r[i],o=a[0].trace,l=[],c=!1,u=0;u<a.length;u++){var f=a[u],h=f.b,p=h+f.s;f[n]=p,l.push(p),f.hasB&&l.push(h),f.hasB&&f.b||(c=!0)}o._extremes[t._id]=s.findExtremes(t,l,{tozero:c,padded:!0})}}function v(t){for(var e=t.traces,r=0;r<e.length;r++)for(var n=e[r],i=0;i<n.length;i++){var o=n[i];o.s!==a&&t.put(o.p,o.b+o.s)}}function y(t,e,r){var i=e.traces,o=x(t),l="fraction"===r.norm?1:100,c=l/1e9,u=t.l2c(t.c2l(0)),f="stack"===r.mode?l:u;function h(e){return n(t.c2l(e))&&(e<u-c||e>f+c||!n(u))}for(var p=0;p<i.length;p++){for(var d=i[p],m=d[0].trace,g=[],v=!1,y=!1,b=0;b<d.length;b++){var _=d[b];if(_.s!==a){var w=Math.abs(l/e.get(_.p,_.s));_.b*=w,_.s*=w;var T=_.b,k=T+_.s;_[o]=k,g.push(k),y=y||h(k),_.hasB&&(g.push(T),y=y||h(T)),_.hasB&&_.b||(v=!0)}}m._extremes[t._id]=s.findExtremes(t,g,{tozero:v,padded:y})}}function x(t){return t._id.charAt(0)}e.exports={crossTraceCalc:function(t,e){for(var r=e.xaxis,n=e.yaxis,i=t._fullLayout,a=t._fullData,s=t.calcdata,l=[],c=[],f=0;f<a.length;f++){var h=a[f];if(!0===h.visible&&o.traceIs(h,"bar")&&h.xaxis===r._id&&h.yaxis===n._id&&("h"===h.orientation?l.push(s[f]):c.push(s[f]),h._computePh))for(var p=t.calcdata[f],d=0;d<p.length;d++)"function"==typeof p[d].ph0&&(p[d].ph0=p[d].ph0()),"function"==typeof p[d].ph1&&(p[d].ph1=p[d].ph1())}var m={xCat:"category"===r.type||"multicategory"===r.type,yCat:"category"===n.type||"multicategory"===n.type,mode:i.barmode,norm:i.barnorm,gap:i.bargap,groupgap:i.bargroupgap};u(t,r,n,c,m),u(t,n,r,l,m)},setGroupPositions:u}},{"../../constants/numerical":479,"../../lib":503,"../../plots/cartesian/axes":554,"../../plots/cartesian/constraints":562,"../../registry":638,"./sieve.js":661,"fast-isnumeric":190}],652:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/color"),a=t("../../registry"),o=t("../scatter/xy_defaults"),s=t("../scatter/period_defaults"),l=t("./style_defaults"),c=t("../../plots/cartesian/constraints").getAxisGroup,u=t("./attributes"),f=n.coerceFont;function h(t,e,r,n){var i=e.orientation,a=e[{v:"x",h:"y"}[i]+"axis"],o=c(r,a)+i,s=r._alignmentOpts||{},l=n("alignmentgroup"),u=s[o];u||(u=s[o]={});var f=u[l];f?f.traces.push(e):f=u[l]={traces:[e],alignmentIndex:Object.keys(u).length,offsetGroups:{}};var h=n("offsetgroup"),p=f.offsetGroups,d=p[h];h&&(d||(d=p[h]={offsetIndex:Object.keys(p).length}),e._offsetIndex=d.offsetIndex)}function p(t,e,r,i,a,o){var s=!(!1===(o=o||{}).moduleHasSelected),l=!(!1===o.moduleHasUnselected),c=!(!1===o.moduleHasConstrain),u=!(!1===o.moduleHasCliponaxis),h=!(!1===o.moduleHasTextangle),p=!(!1===o.moduleHasInsideanchor),d=!!o.hasPathbar,m=Array.isArray(a)||"auto"===a,g=m||"inside"===a,v=m||"outside"===a;if(g||v){var y=f(i,"textfont",r.font),x=n.extendFlat({},y),b=!(t.textfont&&t.textfont.color);if(b&&delete x.color,f(i,"insidetextfont",x),d){var _=n.extendFlat({},y);b&&delete _.color,f(i,"pathbar.textfont",_)}v&&f(i,"outsidetextfont",y),s&&i("selected.textfont.color"),l&&i("unselected.textfont.color"),c&&i("constraintext"),u&&i("cliponaxis"),h&&i("textangle"),i("texttemplate")}g&&p&&i("insidetextanchor")}e.exports={supplyDefaults:function(t,e,r,c){function f(r,i){return n.coerce(t,e,u,r,i)}if(o(t,e,c,f)){s(t,e,c,f),f("xhoverformat"),f("yhoverformat"),f("orientation",e.x&&!e.y?"h":"v"),f("base"),f("offset"),f("width"),f("text"),f("hovertext"),f("hovertemplate");var h=f("textposition");p(t,e,c,f,h,{moduleHasSelected:!0,moduleHasUnselected:!0,moduleHasConstrain:!0,moduleHasCliponaxis:!0,moduleHasTextangle:!0,moduleHasInsideanchor:!0}),l(t,e,f,r,c);var d=(e.marker.line||{}).color,m=a.getComponentMethod("errorbars","supplyDefaults");m(t,e,d||i.defaultLine,{axis:"y"}),m(t,e,d||i.defaultLine,{axis:"x",inherit:"y"}),n.coerceSelectionMarkerOpacity(e,f)}else e.visible=!1},crossTraceDefaults:function(t,e){var r;function i(t){return n.coerce(r._input,r,u,t)}if("group"===e.barmode)for(var a=0;a<t.length;a++)"bar"===(r=t[a]).type&&(r._input,h(0,r,e,i))},handleGroupingDefaults:h,handleText:p}},{"../../components/color":366,"../../lib":503,"../../plots/cartesian/constraints":562,"../../registry":638,"../scatter/period_defaults":947,"../scatter/xy_defaults":954,"./attributes":648,"./style_defaults":663}],653:[function(t,e,r){"use strict";e.exports=function(t,e,r){return t.x="xVal"in e?e.xVal:e.x,t.y="yVal"in e?e.yVal:e.y,e.xa&&(t.xaxis=e.xa),e.ya&&(t.yaxis=e.ya),"h"===r.orientation?(t.label=t.y,t.value=t.x):(t.label=t.x,t.value=t.y),t}},{}],654:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("tinycolor2"),a=t("../../lib").isArrayOrTypedArray;r.coerceString=function(t,e,r){if("string"==typeof e){if(e||!t.noBlank)return e}else if(("number"==typeof e||!0===e)&&!t.strict)return String(e);return void 0!==r?r:t.dflt},r.coerceNumber=function(t,e,r){if(n(e)){e=+e;var i=t.min,a=t.max;if(!(void 0!==i&&e<i||void 0!==a&&e>a))return e}return void 0!==r?r:t.dflt},r.coerceColor=function(t,e,r){return i(e).isValid()?e:void 0!==r?r:t.dflt},r.coerceEnumerated=function(t,e,r){return t.coerceNumber&&(e=+e),-1!==t.values.indexOf(e)?e:void 0!==r?r:t.dflt},r.getValue=function(t,e){var r;return Array.isArray(t)?e<t.length&&(r=t[e]):r=t,r},r.getLineWidth=function(t,e){return 0<e.mlw?e.mlw:a(t.marker.line.width)?0:t.marker.line.width}},{"../../lib":503,"fast-isnumeric":190,tinycolor2:312}],655:[function(t,e,r){"use strict";var n=t("../../components/fx"),i=t("../../registry"),a=t("../../components/color"),o=t("../../lib").fillText,s=t("./helpers").getLineWidth,l=t("../../plots/cartesian/axes").hoverLabelText,c=t("../../constants/numerical").BADNUM;function u(t,e,r,i,a){var s,u,f,h,p,d,m,g=t.cd,v=g[0].trace,y=g[0].t,x="closest"===i,b="waterfall"===v.type,_=t.maxHoverDistance,w=t.maxSpikeDistance;"h"===v.orientation?(s=r,u=e,f="y",h="x",p=z,d=I):(s=e,u=r,f="x",h="y",d=z,p=I);var T=v[f+"period"],k=x||T;function A(t){return S(t,-1)}function M(t){return S(t,1)}function S(t,e){var r=t.w;return t[f]+e*r/2}function E(t){return t[f+"End"]-t[f+"Start"]}var L=x?A:T?function(t){return t.p-E(t)/2}:function(t){return Math.min(A(t),t.p-y.bardelta/2)},C=x?M:T?function(t){return t.p+E(t)/2}:function(t){return Math.max(M(t),t.p+y.bardelta/2)};function P(t,e,r){return a.finiteRange&&(r=0),n.inbox(t-s,e-s,r+Math.min(1,Math.abs(e-t)/m)-1)}function I(t){return P(L(t),C(t),_)}function O(t){var e=t[h];if(b){var r=Math.abs(t.rawS)||0;u>0?e+=r:u<0&&(e-=r)}return e}function z(t){var e=u,r=t.b,i=O(t);return n.inbox(r-e,i-e,_+(i-e)/(i-r)-1)}var D=t[f+"a"],R=t[h+"a"];m=Math.abs(D.r2c(D.range[1])-D.r2c(D.range[0]));var F=n.getDistanceFunction(i,p,d,(function(t){return(p(t)+d(t))/2}));if(n.getClosest(g,F,t),!1!==t.index&&g[t.index].p!==c){k||(L=function(t){return Math.min(A(t),t.p-y.bargroupwidth/2)},C=function(t){return Math.max(M(t),t.p+y.bargroupwidth/2)});var B=g[t.index],N=v.base?B.b+B.s:B.s;t[h+"0"]=t[h+"1"]=R.c2p(B[h],!0),t[h+"LabelVal"]=N;var j=y.extents[y.extents.round(B.p)];t[f+"0"]=D.c2p(x?L(B):j[0],!0),t[f+"1"]=D.c2p(x?C(B):j[1],!0);var U=void 0!==B.orig_p;return t[f+"LabelVal"]=U?B.orig_p:B.p,t.labelLabel=l(D,t[f+"LabelVal"],v[f+"hoverformat"]),t.valueLabel=l(R,t[h+"LabelVal"],v[h+"hoverformat"]),t.baseLabel=l(R,B.b,v[h+"hoverformat"]),t.spikeDistance=(function(t){var e=u,r=t.b,i=O(t);return n.inbox(r-e,i-e,w+(i-e)/(i-r)-1)}(B)+function(t){return P(A(t),M(t),w)}(B))/2,t[f+"Spike"]=D.c2p(B.p,!0),o(B,v,t),t.hovertemplate=v.hovertemplate,t}}function f(t,e){var r=e.mcc||t.marker.color,n=e.mlcc||t.marker.line.color,i=s(t,e);return a.opacity(r)?r:a.opacity(n)&&i?n:void 0}e.exports={hoverPoints:function(t,e,r,n,a){var o=u(t,e,r,n,a);if(o){var s=o.cd,l=s[0].trace,c=s[o.index];return o.color=f(l,c),i.getComponentMethod("errorbars","hoverInfo")(c,l,o),[o]}},hoverOnBars:u,getTraceColor:f}},{"../../components/color":366,"../../components/fx":406,"../../constants/numerical":479,"../../lib":503,"../../plots/cartesian/axes":554,"../../registry":638,"./helpers":654}],656:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),layoutAttributes:t("./layout_attributes"),supplyDefaults:t("./defaults").supplyDefaults,crossTraceDefaults:t("./defaults").crossTraceDefaults,supplyLayoutDefaults:t("./layout_defaults"),calc:t("./calc"),crossTraceCalc:t("./cross_trace_calc").crossTraceCalc,colorbar:t("../scatter/marker_colorbar"),arraysToCalcdata:t("./arrays_to_calcdata"),plot:t("./plot").plot,style:t("./style").style,styleOnSelect:t("./style").styleOnSelect,hoverPoints:t("./hover").hoverPoints,eventData:t("./event_data"),selectPoints:t("./select"),moduleType:"trace",name:"bar",basePlotModule:t("../../plots/cartesian"),categories:["bar-like","cartesian","svg","bar","oriented","errorBarsOK","showLegend","zoomScale"],animatable:!0,meta:{}}},{"../../plots/cartesian":568,"../scatter/marker_colorbar":945,"./arrays_to_calcdata":647,"./attributes":648,"./calc":649,"./cross_trace_calc":651,"./defaults":652,"./event_data":653,"./hover":655,"./layout_attributes":657,"./layout_defaults":658,"./plot":659,"./select":660,"./style":662}],657:[function(t,e,r){"use strict";e.exports={barmode:{valType:"enumerated",values:["stack","group","overlay","relative"],dflt:"group",editType:"calc"},barnorm:{valType:"enumerated",values:["","fraction","percent"],dflt:"",editType:"calc"},bargap:{valType:"number",min:0,max:1,editType:"calc"},bargroupgap:{valType:"number",min:0,max:1,dflt:0,editType:"calc"}}},{}],658:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../plots/cartesian/axes"),a=t("../../lib"),o=t("./layout_attributes");e.exports=function(t,e,r){function s(r,n){return a.coerce(t,e,o,r,n)}for(var l=!1,c=!1,u=!1,f={},h=s("barmode"),p=0;p<r.length;p++){var d=r[p];if(n.traceIs(d,"bar")&&d.visible){if(l=!0,"group"===h){var m=d.xaxis+d.yaxis;f[m]&&(u=!0),f[m]=!0}if(d.visible&&"histogram"===d.type)"category"!==i.getFromId({_fullLayout:e},d["v"===d.orientation?"xaxis":"yaxis"]).type&&(c=!0)}}l?("overlay"!==h&&s("barnorm"),s("bargap",c&&!u?0:.2),s("bargroupgap")):delete e.barmode}},{"../../lib":503,"../../plots/cartesian/axes":554,"../../registry":638,"./layout_attributes":657}],659:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("fast-isnumeric"),a=t("../../lib"),o=t("../../lib/svg_text_utils"),s=t("../../components/color"),l=t("../../components/drawing"),c=t("../../registry"),u=t("../../plots/cartesian/axes").tickText,f=t("./uniform_text"),h=f.recordMinTextSize,p=f.clearMinTextSize,d=t("./style"),m=t("./helpers"),g=t("./constants"),v=t("./attributes"),y=v.text,x=v.textposition,b=t("../../components/fx/helpers").appendArrayPointValue,_=g.TEXTPAD;function w(t){return t.id}function T(t){if(t.ids)return w}function k(t,e){return t<e?1:-1}function A(t,e,r,n){var i;return!e.uniformtext.mode&&M(r)?(n&&(i=n()),t.transition().duration(r.duration).ease(r.easing).each("end",(function(){i&&i()})).each("interrupt",(function(){i&&i()}))):t}function M(t){return t&&t.duration>0}function S(t){return"auto"===t?0:t}function E(t,e){var r=Math.PI/180*e,n=Math.abs(Math.sin(r)),i=Math.abs(Math.cos(r));return{x:t.width*i+t.height*n,y:t.width*n+t.height*i}}function L(t,e,r,n,i,a){var o=!!a.isHorizontal,s=!!a.constrained,l=a.angle||0,c=a.anchor||"end",u="end"===c,f="start"===c,h=((a.leftToRight||0)+1)/2,p=1-h,d=i.width,m=i.height,g=Math.abs(e-t),v=Math.abs(n-r),y=g>2*_&&v>2*_?_:0;g-=2*y,v-=2*y;var x=S(l);"auto"!==l||d<=g&&m<=v||!(d>g||m>v)||(d>v||m>g)&&d<m==g<v||(x+=90);var b=E(i,x),w=1;s&&(w=Math.min(1,g/b.x,v/b.y));var T=i.left*p+i.right*h,A=(i.top+i.bottom)/2,M=(t+_)*p+(e-_)*h,L=(r+n)/2,C=0,P=0;if(f||u){var I=(o?b.x:b.y)/2,O=o?k(t,e):k(r,n);o?f?(M=t+O*y,C=-O*I):(M=e-O*y,C=O*I):f?(L=r+O*y,P=-O*I):(L=n-O*y,P=O*I)}return{textX:T,textY:A,targetX:M,targetY:L,anchorX:C,anchorY:P,scale:w,rotate:x}}e.exports={plot:function(t,e,r,f,g,v){var w=e.xaxis,C=e.yaxis,P=t._fullLayout;g||(g={mode:P.barmode,norm:P.barmode,gap:P.bargap,groupgap:P.bargroupgap},p("bar",P));var I=a.makeTraceGroups(f,r,"trace bars").each((function(r){var c=n.select(this),f=r[0].trace,p="waterfall"===f.type,I="funnel"===f.type,O="bar"===f.type||I,z=0;p&&f.connector.visible&&"between"===f.connector.mode&&(z=f.connector.line.width/2);var D="h"===f.orientation,R=M(g),F=a.ensureSingle(c,"g","points"),B=T(f),N=F.selectAll("g.point").data(a.identity,B);N.enter().append("g").classed("point",!0),N.exit().remove(),N.each((function(c,p){var T,M,I=n.select(this),F=function(t,e,r,n){var i=[],a=[],o=n?e:r,s=n?r:e;return i[0]=o.c2p(t.s0,!0),a[0]=s.c2p(t.p0,!0),i[1]=o.c2p(t.s1,!0),a[1]=s.c2p(t.p1,!0),n?[i,a]:[a,i]}(c,w,C,D),B=F[0][0],N=F[0][1],j=F[1][0],U=F[1][1],V=0==(D?N-B:U-j);if(V&&O&&m.getLineWidth(f,c)&&(V=!1),V||(V=!(i(B)&&i(N)&&i(j)&&i(U))),c.isBlank=V,V&&(D?N=B:U=j),z&&!V&&(D?(B-=k(B,N)*z,N+=k(B,N)*z):(j-=k(j,U)*z,U+=k(j,U)*z)),"waterfall"===f.type){if(!V){var H=f[c.dir].marker;T=H.line.width,M=H.color}}else T=m.getLineWidth(f,c),M=c.mc||f.marker.color;function q(t){var e=n.round(T/2%1,2);return 0===g.gap&&0===g.groupgap?n.round(Math.round(t)-e,2):t}if(!t._context.staticPlot){var G=s.opacity(M)<1||T>.01?q:function(t,e,r){return r&&t===e?t:Math.abs(t-e)>=2?q(t):t>e?Math.ceil(t):Math.floor(t)};B=G(B,N,D),N=G(N,B,D),j=G(j,U,!D),U=G(U,j,!D)}var Y=A(a.ensureSingle(I,"path"),P,g,v);if(Y.style("vector-effect","non-scaling-stroke").attr("d",isNaN((N-B)*(U-j))||V&&t._context.staticPlot?"M0,0Z":"M"+B+","+j+"V"+U+"H"+N+"V"+j+"Z").call(l.setClipUrl,e.layerClipId,t),!P.uniformtext.mode&&R){var W=l.makePointStyleFns(f);l.singlePointStyle(c,Y,f,W,t)}!function(t,e,r,n,i,s,c,f,p,g,v){var w,T=e.xaxis,M=e.yaxis,C=t._fullLayout;function P(e,r,n){return a.ensureSingle(e,"text").text(r).attr({class:"bartext bartext-"+w,"text-anchor":"middle","data-notex":1}).call(l.font,n).call(o.convertToTspans,t)}var I=n[0].trace,O="h"===I.orientation,z=function(t,e,r,n,i){var o,s=e[0].trace;o=s.texttemplate?function(t,e,r,n,i){var o=e[0].trace,s=a.castOption(o,r,"texttemplate");if(!s)return"";var l,c,f,h,p="histogram"===o.type,d="waterfall"===o.type,m="funnel"===o.type,g="h"===o.orientation;g?(l="y",c=i,f="x",h=n):(l="x",c=n,f="y",h=i);function v(t){return u(h,h.c2l(t),!0).text}var y=e[r],x={};x.label=y.p,x.labelLabel=x[l+"Label"]=(_=y.p,u(c,c.c2l(_),!0).text);var _;var w=a.castOption(o,y.i,"text");(0===w||w)&&(x.text=w);x.value=y.s,x.valueLabel=x[f+"Label"]=v(y.s);var T={};b(T,o,y.i),(p||void 0===T.x)&&(T.x=g?x.value:x.label);(p||void 0===T.y)&&(T.y=g?x.label:x.value);(p||void 0===T.xLabel)&&(T.xLabel=g?x.valueLabel:x.labelLabel);(p||void 0===T.yLabel)&&(T.yLabel=g?x.labelLabel:x.valueLabel);d&&(x.delta=+y.rawS||y.s,x.deltaLabel=v(x.delta),x.final=y.v,x.finalLabel=v(x.final),x.initial=x.final-x.delta,x.initialLabel=v(x.initial));m&&(x.value=y.s,x.valueLabel=v(x.value),x.percentInitial=y.begR,x.percentInitialLabel=a.formatPercent(y.begR),x.percentPrevious=y.difR,x.percentPreviousLabel=a.formatPercent(y.difR),x.percentTotal=y.sumR,x.percenTotalLabel=a.formatPercent(y.sumR));var k=a.castOption(o,y.i,"customdata");k&&(x.customdata=k);return a.texttemplateString(s,x,t._d3locale,T,x,o._meta||{})}(t,e,r,n,i):s.textinfo?function(t,e,r,n){var i=t[0].trace,o="h"===i.orientation,s="waterfall"===i.type,l="funnel"===i.type;function c(t){return u(o?r:n,+t,!0).text}var f,h=i.textinfo,p=t[e],d=h.split("+"),m=[],g=function(t){return-1!==d.indexOf(t)};g("label")&&m.push((v=t[e].p,u(o?n:r,v,!0).text));var v;g("text")&&(0===(f=a.castOption(i,p.i,"text"))||f)&&m.push(f);if(s){var y=+p.rawS||p.s,x=p.v,b=x-y;g("initial")&&m.push(c(b)),g("delta")&&m.push(c(y)),g("final")&&m.push(c(x))}if(l){g("value")&&m.push(c(p.s));var _=0;g("percent initial")&&_++,g("percent previous")&&_++,g("percent total")&&_++;var w=_>1;g("percent initial")&&(f=a.formatPercent(p.begR),w&&(f+=" of initial"),m.push(f)),g("percent previous")&&(f=a.formatPercent(p.difR),w&&(f+=" of previous"),m.push(f)),g("percent total")&&(f=a.formatPercent(p.sumR),w&&(f+=" of total"),m.push(f))}return m.join("<br>")}(e,r,n,i):m.getValue(s.text,r);return m.coerceString(y,o)}(C,n,i,T,M);w=function(t,e){var r=m.getValue(t.textposition,e);return m.coerceEnumerated(x,r)}(I,i);var D="stack"===g.mode||"relative"===g.mode,R=n[i],F=!D||R._outmost;if(!z||"none"===w||(R.isBlank||s===c||f===p)&&("auto"===w||"inside"===w))return void r.select("text").remove();var B=C.font,N=d.getBarColor(n[i],I),j=d.getInsideTextFont(I,i,B,N),U=d.getOutsideTextFont(I,i,B),V=r.datum();O?"log"===T.type&&V.s0<=0&&(s=T.range[0]<T.range[1]?0:T._length):"log"===M.type&&V.s0<=0&&(f=M.range[0]<M.range[1]?M._length:0);var H,q,G,Y,W,X=Math.abs(c-s)-2*_,Z=Math.abs(p-f)-2*_;"outside"===w&&(F||R.hasB||(w="inside"));if("auto"===w)if(F){w="inside",W=a.ensureUniformFontSize(t,j),H=P(r,z,W),q=l.bBox(H.node()),G=q.width,Y=q.height;var J=G<=X&&Y<=Z,K=G<=Z&&Y<=X,Q=O?X>=G*(Z/Y):Z>=Y*(X/G);G>0&&Y>0&&(J||K||Q)?w="inside":(w="outside",H.remove(),H=null)}else w="inside";if(!H){W=a.ensureUniformFontSize(t,"outside"===w?U:j);var $=(H=P(r,z,W)).attr("transform");if(H.attr("transform",""),q=l.bBox(H.node()),G=q.width,Y=q.height,H.attr("transform",$),G<=0||Y<=0)return void H.remove()}var tt,et,rt=I.textangle;"outside"===w?(et="both"===I.constraintext||"outside"===I.constraintext,tt=function(t,e,r,n,i,a){var o,s=!!a.isHorizontal,l=!!a.constrained,c=a.angle||0,u=i.width,f=i.height,h=Math.abs(e-t),p=Math.abs(n-r);o=s?p>2*_?_:0:h>2*_?_:0;var d=1;l&&(d=s?Math.min(1,p/f):Math.min(1,h/u));var m=S(c),g=E(i,m),v=(s?g.x:g.y)/2,y=(i.left+i.right)/2,x=(i.top+i.bottom)/2,b=(t+e)/2,w=(r+n)/2,T=0,A=0,M=s?k(e,t):k(r,n);s?(b=e-M*o,T=M*v):(w=n+M*o,A=-M*v);return{textX:y,textY:x,targetX:b,targetY:w,anchorX:T,anchorY:A,scale:d,rotate:m}}(s,c,f,p,q,{isHorizontal:O,constrained:et,angle:rt})):(et="both"===I.constraintext||"inside"===I.constraintext,tt=L(s,c,f,p,q,{isHorizontal:O,constrained:et,angle:rt,anchor:I.insidetextanchor}));tt.fontSize=W.size,h("histogram"===I.type?"bar":I.type,tt,C),R.transform=tt,A(H,C,g,v).attr("transform",a.getTextTransform(tt))}(t,e,I,r,p,B,N,j,U,g,v),e.layerClipId&&l.hideOutsideRangePoint(c,I.select("text"),w,C,f.xcalendar,f.ycalendar)}));var j=!1===f.cliponaxis;l.setClipUrl(c,j?null:e.layerClipId,t)}));c.getComponentMethod("errorbars","plot")(t,I,e,g)},toMoveInsideBar:L}},{"../../components/color":366,"../../components/drawing":388,"../../components/fx/helpers":402,"../../lib":503,"../../lib/svg_text_utils":529,"../../plots/cartesian/axes":554,"../../registry":638,"./attributes":648,"./constants":650,"./helpers":654,"./style":662,"./uniform_text":664,"@plotly/d3":58,"fast-isnumeric":190}],660:[function(t,e,r){"use strict";function n(t,e,r,n,i){var a=e.c2p(n?t.s0:t.p0,!0),o=e.c2p(n?t.s1:t.p1,!0),s=r.c2p(n?t.p0:t.s0,!0),l=r.c2p(n?t.p1:t.s1,!0);return i?[(a+o)/2,(s+l)/2]:n?[o,(s+l)/2]:[(a+o)/2,l]}e.exports=function(t,e){var r,i=t.cd,a=t.xaxis,o=t.yaxis,s=i[0].trace,l="funnel"===s.type,c="h"===s.orientation,u=[];if(!1===e)for(r=0;r<i.length;r++)i[r].selected=0;else for(r=0;r<i.length;r++){var f=i[r],h="ct"in f?f.ct:n(f,a,o,c,l);e.contains(h,!1,r,t)?(u.push({pointNumber:r,x:a.c2d(f.x),y:o.c2d(f.y)}),f.selected=1):f.selected=0}return u}},{}],661:[function(t,e,r){"use strict";e.exports=a;var n=t("../../lib").distinctVals,i=t("../../constants/numerical").BADNUM;function a(t,e){this.traces=t,this.sepNegVal=e.sepNegVal,this.overlapNoMerge=e.overlapNoMerge;for(var r=1/0,a=[],o=0;o<t.length;o++){for(var s=t[o],l=0;l<s.length;l++){var c=s[l];c.p!==i&&a.push(c.p)}s[0]&&s[0].width1&&(r=Math.min(s[0].width1,r))}this.positions=a;var u=n(a);this.distinctPositions=u.vals,1===u.vals.length&&r!==1/0?this.minDiff=r:this.minDiff=Math.min(u.minDiff,r);var f=(e.posAxis||{}).type;"category"!==f&&"multicategory"!==f||(this.minDiff=1),this.binWidth=this.minDiff,this.bins={}}a.prototype.put=function(t,e){var r=this.getLabel(t,e),n=this.bins[r]||0;return this.bins[r]=n+e,n},a.prototype.get=function(t,e){var r=this.getLabel(t,e);return this.bins[r]||0},a.prototype.getLabel=function(t,e){return(e<0&&this.sepNegVal?"v":"^")+(this.overlapNoMerge?t:Math.round(t/this.binWidth))}},{"../../constants/numerical":479,"../../lib":503}],662:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/color"),a=t("../../components/drawing"),o=t("../../lib"),s=t("../../registry"),l=t("./uniform_text").resizeText,c=t("./attributes"),u=c.textfont,f=c.insidetextfont,h=c.outsidetextfont,p=t("./helpers");function d(t,e,r){a.pointStyle(t.selectAll("path"),e,r),m(t,e,r)}function m(t,e,r){t.selectAll("text").each((function(t){var i=n.select(this),s=o.ensureUniformFontSize(r,g(i,t,e,r));a.font(i,s)}))}function g(t,e,r,n){var i=n._fullLayout.font,a=r.textfont;if(t.classed("bartext-inside")){var o=_(e,r);a=y(r,e.i,i,o)}else t.classed("bartext-outside")&&(a=x(r,e.i,i));return a}function v(t,e,r){return b(u,t.textfont,e,r)}function y(t,e,r,n){var a=v(t,e,r);return(void 0===t._input.textfont||void 0===t._input.textfont.color||Array.isArray(t.textfont.color)&&void 0===t.textfont.color[e])&&(a={color:i.contrast(n),family:a.family,size:a.size}),b(f,t.insidetextfont,e,a)}function x(t,e,r){var n=v(t,e,r);return b(h,t.outsidetextfont,e,n)}function b(t,e,r,n){e=e||{};var i=p.getValue(e.family,r),a=p.getValue(e.size,r),o=p.getValue(e.color,r);return{family:p.coerceString(t.family,i,n.family),size:p.coerceNumber(t.size,a,n.size),color:p.coerceColor(t.color,o,n.color)}}function _(t,e){return"waterfall"===e.type?e[t.dir].marker.color:t.mcc||t.mc||e.marker.color}e.exports={style:function(t){var e=n.select(t).selectAll("g.barlayer").selectAll("g.trace");l(t,e,"bar");var r=e.size(),i=t._fullLayout;e.style("opacity",(function(t){return t[0].trace.opacity})).each((function(t){("stack"===i.barmode&&r>1||0===i.bargap&&0===i.bargroupgap&&!t[0].trace.marker.line.width)&&n.select(this).attr("shape-rendering","crispEdges")})),e.selectAll("g.points").each((function(e){d(n.select(this),e[0].trace,t)})),s.getComponentMethod("errorbars","style")(e)},styleTextPoints:m,styleOnSelect:function(t,e,r){var i=e[0].trace;i.selectedpoints?function(t,e,r){a.selectedPointStyle(t.selectAll("path"),e),function(t,e,r){t.each((function(t){var i,s=n.select(this);if(t.selected){i=o.ensureUniformFontSize(r,g(s,t,e,r));var l=e.selected.textfont&&e.selected.textfont.color;l&&(i.color=l),a.font(s,i)}else a.selectedTextStyle(s,e)}))}(t.selectAll("text"),e,r)}(r,i,t):(d(r,i,t),s.getComponentMethod("errorbars","style")(r))},getInsideTextFont:y,getOutsideTextFont:x,getBarColor:_,resizeText:l}},{"../../components/color":366,"../../components/drawing":388,"../../lib":503,"../../registry":638,"./attributes":648,"./helpers":654,"./uniform_text":664,"@plotly/d3":58}],663:[function(t,e,r){"use strict";var n=t("../../components/color"),i=t("../../components/colorscale/helpers").hasColorscale,a=t("../../components/colorscale/defaults"),o=t("../../lib").coercePattern;e.exports=function(t,e,r,s,l){var c=r("marker.color",s),u=i(t,"marker");u&&a(t,e,l,r,{prefix:"marker.",cLetter:"c"}),r("marker.line.color",n.defaultLine),i(t,"marker.line")&&a(t,e,l,r,{prefix:"marker.line.",cLetter:"c"}),r("marker.line.width"),r("marker.opacity"),o(r,"marker.pattern",c,u),r("selected.marker.color"),r("unselected.marker.color")}},{"../../components/color":366,"../../components/colorscale/defaults":376,"../../components/colorscale/helpers":377,"../../lib":503}],664:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib");function a(t){return"_"+t+"Text_minsize"}e.exports={recordMinTextSize:function(t,e,r){if(r.uniformtext.mode){var n=a(t),i=r.uniformtext.minsize,o=e.scale*e.fontSize;e.hide=o<i,r[n]=r[n]||1/0,e.hide||(r[n]=Math.min(r[n],Math.max(o,i)))}},clearMinTextSize:function(t,e){e[a(t)]=void 0},resizeText:function(t,e,r){var a=t._fullLayout,o=a["_"+r+"Text_minsize"];if(o){var s,l="hide"===a.uniformtext.mode;switch(r){case"funnelarea":case"pie":case"sunburst":s="g.slice";break;case"treemap":case"icicle":s="g.slice, g.pathbar";break;default:s="g.points > g.point"}e.selectAll(s).each((function(t){var e=t.transform;e&&(e.scale=l&&e.hide?0:o/e.fontSize,n.select(this).select("text").attr("transform",i.getTextTransform(e)))}))}}}},{"../../lib":503,"@plotly/d3":58}],665:[function(t,e,r){"use strict";var n=t("../../plots/template_attributes").hovertemplateAttrs,i=t("../../lib/extend").extendFlat,a=t("../scatterpolar/attributes"),o=t("../bar/attributes");e.exports={r:a.r,theta:a.theta,r0:a.r0,dr:a.dr,theta0:a.theta0,dtheta:a.dtheta,thetaunit:a.thetaunit,base:i({},o.base,{}),offset:i({},o.offset,{}),width:i({},o.width,{}),text:i({},o.text,{}),hovertext:i({},o.hovertext,{}),marker:o.marker,hoverinfo:a.hoverinfo,hovertemplate:n(),selected:o.selected,unselected:o.unselected}},{"../../lib/extend":493,"../../plots/template_attributes":633,"../bar/attributes":648,"../scatterpolar/attributes":1002}],666:[function(t,e,r){"use strict";var n=t("../../components/colorscale/helpers").hasColorscale,i=t("../../components/colorscale/calc"),a=t("../bar/arrays_to_calcdata"),o=t("../bar/cross_trace_calc").setGroupPositions,s=t("../scatter/calc_selection"),l=t("../../registry").traceIs,c=t("../../lib").extendFlat;e.exports={calc:function(t,e){for(var r=t._fullLayout,o=e.subplot,l=r[o].radialaxis,c=r[o].angularaxis,u=l.makeCalcdata(e,"r"),f=c.makeCalcdata(e,"theta"),h=e._length,p=new Array(h),d=u,m=f,g=0;g<h;g++)p[g]={p:m[g],s:d[g]};function v(t){var r=e[t];void 0!==r&&(e["_"+t]=Array.isArray(r)?c.makeCalcdata(e,t):c.d2c(r,e.thetaunit))}return"linear"===c.type&&(v("width"),v("offset")),n(e,"marker")&&i(t,e,{vals:e.marker.color,containerStr:"marker",cLetter:"c"}),n(e,"marker.line")&&i(t,e,{vals:e.marker.line.color,containerStr:"marker.line",cLetter:"c"}),a(p,e),s(p,e),p},crossTraceCalc:function(t,e,r){for(var n=t.calcdata,i=[],a=0;a<n.length;a++){var s=n[a],u=s[0].trace;!0===u.visible&&l(u,"bar")&&u.subplot===r&&i.push(s)}var f=c({},e.radialaxis,{_id:"x"}),h=e.angularaxis;o(t,h,f,i,{mode:e.barmode,norm:e.barnorm,gap:e.bargap,groupgap:e.bargroupgap})}}},{"../../components/colorscale/calc":374,"../../components/colorscale/helpers":377,"../../lib":503,"../../registry":638,"../bar/arrays_to_calcdata":647,"../bar/cross_trace_calc":651,"../scatter/calc_selection":929}],667:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../scatterpolar/defaults").handleRThetaDefaults,a=t("../bar/style_defaults"),o=t("./attributes");e.exports=function(t,e,r,s){function l(r,i){return n.coerce(t,e,o,r,i)}i(t,e,s,l)?(l("thetaunit"),l("base"),l("offset"),l("width"),l("text"),l("hovertext"),l("hovertemplate"),a(t,e,l,r,s),n.coerceSelectionMarkerOpacity(e,l)):e.visible=!1}},{"../../lib":503,"../bar/style_defaults":663,"../scatterpolar/defaults":1004,"./attributes":665}],668:[function(t,e,r){"use strict";var n=t("../../components/fx"),i=t("../../lib"),a=t("../bar/hover").getTraceColor,o=i.fillText,s=t("../scatterpolar/hover").makeHoverPointText,l=t("../../plots/polar/helpers").isPtInsidePolygon;e.exports=function(t,e,r){var c=t.cd,u=c[0].trace,f=t.subplot,h=f.radialAxis,p=f.angularAxis,d=f.vangles,m=d?l:i.isPtInsideSector,g=t.maxHoverDistance,v=p._period||2*Math.PI,y=Math.abs(h.g2p(Math.sqrt(e*e+r*r))),x=Math.atan2(r,e);h.range[0]>h.range[1]&&(x+=Math.PI);if(n.getClosest(c,(function(t){return m(y,x,[t.rp0,t.rp1],[t.thetag0,t.thetag1],d)?g+Math.min(1,Math.abs(t.thetag1-t.thetag0)/v)-1+(t.rp1-y)/(t.rp1-t.rp0)-1:1/0}),t),!1!==t.index){var b=c[t.index];t.x0=t.x1=b.ct[0],t.y0=t.y1=b.ct[1];var _=i.extendFlat({},b,{r:b.s,theta:b.p});return o(b,u,t),s(_,u,f,t),t.hovertemplate=u.hovertemplate,t.color=a(u,b),t.xLabelVal=t.yLabelVal=void 0,b.s<0&&(t.idealAlign="left"),[t]}}},{"../../components/fx":406,"../../lib":503,"../../plots/polar/helpers":621,"../bar/hover":655,"../scatterpolar/hover":1006}],669:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"barpolar",basePlotModule:t("../../plots/polar"),categories:["polar","bar","showLegend"],attributes:t("./attributes"),layoutAttributes:t("./layout_attributes"),supplyDefaults:t("./defaults"),supplyLayoutDefaults:t("./layout_defaults"),calc:t("./calc").calc,crossTraceCalc:t("./calc").crossTraceCalc,plot:t("./plot"),colorbar:t("../scatter/marker_colorbar"),formatLabels:t("../scatterpolar/format_labels"),style:t("../bar/style").style,styleOnSelect:t("../bar/style").styleOnSelect,hoverPoints:t("./hover"),selectPoints:t("../bar/select"),meta:{}}},{"../../plots/polar":622,"../bar/select":660,"../bar/style":662,"../scatter/marker_colorbar":945,"../scatterpolar/format_labels":1005,"./attributes":665,"./calc":666,"./defaults":667,"./hover":668,"./layout_attributes":670,"./layout_defaults":671,"./plot":672}],670:[function(t,e,r){"use strict";e.exports={barmode:{valType:"enumerated",values:["stack","overlay"],dflt:"stack",editType:"calc"},bargap:{valType:"number",dflt:.1,min:0,max:1,editType:"calc"}}},{}],671:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./layout_attributes");e.exports=function(t,e,r){var a,o={};function s(r,o){return n.coerce(t[a]||{},e[a],i,r,o)}for(var l=0;l<r.length;l++){var c=r[l];"barpolar"===c.type&&!0===c.visible&&(o[a=c.subplot]||(s("barmode"),s("bargap"),o[a]=1))}}},{"../../lib":503,"./layout_attributes":670}],672:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("fast-isnumeric"),a=t("../../lib"),o=t("../../components/drawing"),s=t("../../plots/polar/helpers");e.exports=function(t,e,r){var l=e.xaxis,c=e.yaxis,u=e.radialAxis,f=e.angularAxis,h=function(t){var e=t.cxx,r=t.cyy;if(t.vangles)return function(n,i,o,l){var c,u;a.angleDelta(o,l)>0?(c=o,u=l):(c=l,u=o);var f=[s.findEnclosingVertexAngles(c,t.vangles)[0],(c+u)/2,s.findEnclosingVertexAngles(u,t.vangles)[1]];return s.pathPolygonAnnulus(n,i,c,u,f,e,r)};return function(t,n,i,o){return a.pathAnnulus(t,n,i,o,e,r)}}(e),p=e.layers.frontplot.select("g.barlayer");a.makeTraceGroups(p,r,"trace bars").each((function(){var r=n.select(this),s=a.ensureSingle(r,"g","points").selectAll("g.point").data(a.identity);s.enter().append("g").style("vector-effect","non-scaling-stroke").style("stroke-miterlimit",2).classed("point",!0),s.exit().remove(),s.each((function(t){var e,r=n.select(this),o=t.rp0=u.c2p(t.s0),s=t.rp1=u.c2p(t.s1),p=t.thetag0=f.c2g(t.p0),d=t.thetag1=f.c2g(t.p1);if(i(o)&&i(s)&&i(p)&&i(d)&&o!==s&&p!==d){var m=u.c2g(t.s1),g=(p+d)/2;t.ct=[l.c2p(m*Math.cos(g)),c.c2p(m*Math.sin(g))],e=h(o,s,p,d)}else e="M0,0Z";a.ensureSingle(r,"path").attr("d",e)})),o.setClipUrl(r,e._hasClipOnAxisFalse?e.clipIds.forTraces:null,t)}))}},{"../../components/drawing":388,"../../lib":503,"../../plots/polar/helpers":621,"@plotly/d3":58,"fast-isnumeric":190}],673:[function(t,e,r){"use strict";var n=t("../scatter/attributes"),i=t("../bar/attributes"),a=t("../../components/color/attributes"),o=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,s=t("../../plots/template_attributes").hovertemplateAttrs,l=t("../../lib/extend").extendFlat,c=n.marker,u=c.line;e.exports={y:{valType:"data_array",editType:"calc+clearAxisTypes"},x:{valType:"data_array",editType:"calc+clearAxisTypes"},x0:{valType:"any",editType:"calc+clearAxisTypes"},y0:{valType:"any",editType:"calc+clearAxisTypes"},dx:{valType:"number",editType:"calc"},dy:{valType:"number",editType:"calc"},xperiod:n.xperiod,yperiod:n.yperiod,xperiod0:n.xperiod0,yperiod0:n.yperiod0,xperiodalignment:n.xperiodalignment,yperiodalignment:n.yperiodalignment,xhoverformat:o("x"),yhoverformat:o("y"),name:{valType:"string",editType:"calc+clearAxisTypes"},q1:{valType:"data_array",editType:"calc+clearAxisTypes"},median:{valType:"data_array",editType:"calc+clearAxisTypes"},q3:{valType:"data_array",editType:"calc+clearAxisTypes"},lowerfence:{valType:"data_array",editType:"calc"},upperfence:{valType:"data_array",editType:"calc"},notched:{valType:"boolean",editType:"calc"},notchwidth:{valType:"number",min:0,max:.5,dflt:.25,editType:"calc"},notchspan:{valType:"data_array",editType:"calc"},boxpoints:{valType:"enumerated",values:["all","outliers","suspectedoutliers",!1],editType:"calc"},jitter:{valType:"number",min:0,max:1,editType:"calc"},pointpos:{valType:"number",min:-2,max:2,editType:"calc"},boxmean:{valType:"enumerated",values:[!0,"sd",!1],editType:"calc"},mean:{valType:"data_array",editType:"calc"},sd:{valType:"data_array",editType:"calc"},orientation:{valType:"enumerated",values:["v","h"],editType:"calc+clearAxisTypes"},quartilemethod:{valType:"enumerated",values:["linear","exclusive","inclusive"],dflt:"linear",editType:"calc"},width:{valType:"number",min:0,dflt:0,editType:"calc"},marker:{outliercolor:{valType:"color",dflt:"rgba(0, 0, 0, 0)",editType:"style"},symbol:l({},c.symbol,{arrayOk:!1,editType:"plot"}),opacity:l({},c.opacity,{arrayOk:!1,dflt:1,editType:"style"}),size:l({},c.size,{arrayOk:!1,editType:"calc"}),color:l({},c.color,{arrayOk:!1,editType:"style"}),line:{color:l({},u.color,{arrayOk:!1,dflt:a.defaultLine,editType:"style"}),width:l({},u.width,{arrayOk:!1,dflt:0,editType:"style"}),outliercolor:{valType:"color",editType:"style"},outlierwidth:{valType:"number",min:0,dflt:1,editType:"style"},editType:"style"},editType:"plot"},line:{color:{valType:"color",editType:"style"},width:{valType:"number",min:0,dflt:2,editType:"style"},editType:"plot"},fillcolor:n.fillcolor,whiskerwidth:{valType:"number",min:0,max:1,dflt:.5,editType:"calc"},offsetgroup:i.offsetgroup,alignmentgroup:i.alignmentgroup,selected:{marker:n.selected.marker,editType:"style"},unselected:{marker:n.unselected.marker,editType:"style"},text:l({},n.text,{}),hovertext:l({},n.hovertext,{}),hovertemplate:s({}),hoveron:{valType:"flaglist",flags:["boxes","points"],dflt:"boxes+points",editType:"style"}}},{"../../components/color/attributes":365,"../../lib/extend":493,"../../plots/cartesian/axis_format_attributes":557,"../../plots/template_attributes":633,"../bar/attributes":648,"../scatter/attributes":927}],674:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../plots/cartesian/axes"),a=t("../../plots/cartesian/align_period"),o=t("../../lib"),s=t("../../constants/numerical").BADNUM,l=o._;e.exports=function(t,e){var r,c,y,x,b,_,w,T=t._fullLayout,k=i.getFromId(t,e.xaxis||"x"),A=i.getFromId(t,e.yaxis||"y"),M=[],S="violin"===e.type?"_numViolins":"_numBoxes";"h"===e.orientation?(y=k,x="x",b=A,_="y",w=!!e.yperiodalignment):(y=A,x="y",b=k,_="x",w=!!e.xperiodalignment);var E,L,C,P,I,O,z=function(t,e,r,i){var s,l=e+"0"in t,c="d"+e in t;if(e in t||l&&c){var u=r.makeCalcdata(t,e);return[a(t,r,e,u).vals,u]}s=l?t[e+"0"]:"name"in t&&("category"===r.type||n(t.name)&&-1!==["linear","log"].indexOf(r.type)||o.isDateTime(t.name)&&"date"===r.type)?t.name:i;for(var f="multicategory"===r.type?r.r2c_just_indices(s):r.d2c(s,0,t[e+"calendar"]),h=t._length,p=new Array(h),d=0;d<h;d++)p[d]=f;return[p]}(e,_,b,T[S]),D=z[0],R=z[1],F=o.distinctVals(D,b),B=F.vals,N=F.minDiff/2,j="all"===(e.boxpoints||e.points)?o.identity:function(t){return t.v<E.lf||t.v>E.uf};if(e._hasPreCompStats){var U=e[x],V=function(t){return y.d2c((e[t]||[])[r])},H=1/0,q=-1/0;for(r=0;r<e._length;r++){var G=D[r];if(n(G)){if((E={}).pos=E[_]=G,w&&R&&(E.orig_p=R[r]),E.q1=V("q1"),E.med=V("median"),E.q3=V("q3"),L=[],U&&o.isArrayOrTypedArray(U[r]))for(c=0;c<U[r].length;c++)(O=y.d2c(U[r][c]))!==s&&(u(I={v:O,i:[r,c]},e,[r,c]),L.push(I));if(E.pts=L.sort(f),P=(C=E[x]=L.map(h)).length,E.med!==s&&E.q1!==s&&E.q3!==s&&E.med>=E.q1&&E.q3>=E.med){var Y=V("lowerfence");E.lf=Y!==s&&Y<=E.q1?Y:p(E,C,P);var W=V("upperfence");E.uf=W!==s&&W>=E.q3?W:d(E,C,P);var X=V("mean");E.mean=X!==s?X:P?o.mean(C,P):(E.q1+E.q3)/2;var Z=V("sd");E.sd=X!==s&&Z>=0?Z:P?o.stdev(C,P,E.mean):E.q3-E.q1,E.lo=m(E),E.uo=g(E);var J=V("notchspan");J=J!==s&&J>0?J:v(E,P),E.ln=E.med-J,E.un=E.med+J;var K=E.lf,Q=E.uf;e.boxpoints&&C.length&&(K=Math.min(K,C[0]),Q=Math.max(Q,C[P-1])),e.notched&&(K=Math.min(K,E.ln),Q=Math.max(Q,E.un)),E.min=K,E.max=Q}else{var $;o.warn(["Invalid input - make sure that q1 <= median <= q3","q1 = "+E.q1,"median = "+E.med,"q3 = "+E.q3].join("\n")),$=E.med!==s?E.med:E.q1!==s?E.q3!==s?(E.q1+E.q3)/2:E.q1:E.q3!==s?E.q3:0,E.med=$,E.q1=E.q3=$,E.lf=E.uf=$,E.mean=E.sd=$,E.ln=E.un=$,E.min=E.max=$}H=Math.min(H,E.min),q=Math.max(q,E.max),E.pts2=L.filter(j),M.push(E)}}e._extremes[y._id]=i.findExtremes(y,[H,q],{padded:!0})}else{var tt=y.makeCalcdata(e,x),et=function(t,e){for(var r=t.length,n=new Array(r+1),i=0;i<r;i++)n[i]=t[i]-e;return n[r]=t[r-1]+e,n}(B,N),rt=B.length,nt=function(t){for(var e=new Array(t),r=0;r<t;r++)e[r]=[];return e}(rt);for(r=0;r<e._length;r++)if(O=tt[r],n(O)){var it=o.findBin(D[r],et);it>=0&&it<rt&&(u(I={v:O,i:r},e,r),nt[it].push(I))}var at=1/0,ot=-1/0,st=e.quartilemethod,lt="exclusive"===st,ct="inclusive"===st;for(r=0;r<rt;r++)if(nt[r].length>0){var ut,ft;if((E={}).pos=E[_]=B[r],L=E.pts=nt[r].sort(f),P=(C=E[x]=L.map(h)).length,E.min=C[0],E.max=C[P-1],E.mean=o.mean(C,P),E.sd=o.stdev(C,P,E.mean),E.med=o.interp(C,.5),P%2&&(lt||ct))lt?(ut=C.slice(0,P/2),ft=C.slice(P/2+1)):ct&&(ut=C.slice(0,P/2+1),ft=C.slice(P/2)),E.q1=o.interp(ut,.5),E.q3=o.interp(ft,.5);else E.q1=o.interp(C,.25),E.q3=o.interp(C,.75);E.lf=p(E,C,P),E.uf=d(E,C,P),E.lo=m(E),E.uo=g(E);var ht=v(E,P);E.ln=E.med-ht,E.un=E.med+ht,at=Math.min(at,E.ln),ot=Math.max(ot,E.un),E.pts2=L.filter(j),M.push(E)}e._extremes[y._id]=i.findExtremes(y,e.notched?tt.concat([at,ot]):tt,{padded:!0})}return function(t,e){if(o.isArrayOrTypedArray(e.selectedpoints))for(var r=0;r<t.length;r++){for(var n=t[r].pts||[],i={},a=0;a<n.length;a++)i[n[a].i]=a;o.tagSelected(n,e,i)}}(M,e),M.length>0?(M[0].t={num:T[S],dPos:N,posLetter:_,valLetter:x,labels:{med:l(t,"median:"),min:l(t,"min:"),q1:l(t,"q1:"),q3:l(t,"q3:"),max:l(t,"max:"),mean:"sd"===e.boxmean?l(t,"mean \xb1 \u03c3:"):l(t,"mean:"),lf:l(t,"lower fence:"),uf:l(t,"upper fence:")}},T[S]++,M):[{t:{empty:!0}}]};var c={text:"tx",hovertext:"htx"};function u(t,e,r){for(var n in c)o.isArrayOrTypedArray(e[n])&&(Array.isArray(r)?o.isArrayOrTypedArray(e[n][r[0]])&&(t[c[n]]=e[n][r[0]][r[1]]):t[c[n]]=e[n][r])}function f(t,e){return t.v-e.v}function h(t){return t.v}function p(t,e,r){return 0===r?t.q1:Math.min(t.q1,e[Math.min(o.findBin(2.5*t.q1-1.5*t.q3,e,!0)+1,r-1)])}function d(t,e,r){return 0===r?t.q3:Math.max(t.q3,e[Math.max(o.findBin(2.5*t.q3-1.5*t.q1,e),0)])}function m(t){return 4*t.q1-3*t.q3}function g(t){return 4*t.q3-3*t.q1}function v(t,e){return 0===e?0:1.57*(t.q3-t.q1)/Math.sqrt(e)}},{"../../constants/numerical":479,"../../lib":503,"../../plots/cartesian/align_period":551,"../../plots/cartesian/axes":554,"fast-isnumeric":190}],675:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes"),i=t("../../lib"),a=t("../../plots/cartesian/constraints").getAxisGroup,o=["v","h"];function s(t,e,r,o){var s,l,c,u=e.calcdata,f=e._fullLayout,h=o._id,p=h.charAt(0),d=[],m=0;for(s=0;s<r.length;s++)for(c=u[r[s]],l=0;l<c.length;l++)d.push(o.c2l(c[l].pos,!0)),m+=(c[l].pts2||[]).length;if(d.length){var g=i.distinctVals(d);"category"!==o.type&&"multicategory"!==o.type||(g.minDiff=1);var v=g.minDiff/2;n.minDtick(o,g.minDiff,g.vals[0],!0);var y=f["violin"===t?"_numViolins":"_numBoxes"],x="group"===f[t+"mode"]&&y>1,b=1-f[t+"gap"],_=1-f[t+"groupgap"];for(s=0;s<r.length;s++){var w,T,k,A,M,S,E=(c=u[r[s]])[0].trace,L=c[0].t,C=E.width,P=E.side;if(C)w=T=A=C/2,k=0;else if(w=v,x){var I=a(f,o._id)+E.orientation,O=(f._alignmentOpts[I]||{})[E.alignmentgroup]||{},z=Object.keys(O.offsetGroups||{}).length,D=z||y;T=w*b*_/D,k=2*w*(((z?E._offsetIndex:L.num)+.5)/D-.5)*b,A=w*b/D}else T=w*b*_,k=0,A=w;L.dPos=w,L.bPos=k,L.bdPos=T,L.wHover=A;var R,F,B,N,j,U,V=k+T,H=Boolean(C);if("positive"===P?(M=w*(C?1:.5),R=V,S=R=k):"negative"===P?(M=R=k,S=w*(C?1:.5),F=V):(M=S=w,R=F=V),(E.boxpoints||E.points)&&m>0){var q=E.pointpos,G=E.jitter,Y=E.marker.size/2,W=0;q+G>=0&&((W=V*(q+G))>M?(H=!0,j=Y,B=W):W>R&&(j=Y,B=M)),W<=M&&(B=M);var X=0;q-G<=0&&((X=-V*(q-G))>S?(H=!0,U=Y,N=X):X>F&&(U=Y,N=S)),X<=S&&(N=S)}else B=M,N=S;var Z=new Array(c.length);for(l=0;l<c.length;l++)Z[l]=c[l].pos;E._extremes[h]=n.findExtremes(o,Z,{padded:H,vpadminus:N,vpadplus:B,vpadLinearized:!0,ppadminus:{x:U,y:j}[p],ppadplus:{x:j,y:U}[p]})}}}e.exports={crossTraceCalc:function(t,e){for(var r=t.calcdata,n=e.xaxis,i=e.yaxis,a=0;a<o.length;a++){for(var l=o[a],c="h"===l?i:n,u=[],f=0;f<r.length;f++){var h=r[f],p=h[0].t,d=h[0].trace;!0!==d.visible||"box"!==d.type&&"candlestick"!==d.type||p.empty||(d.orientation||"v")!==l||d.xaxis!==n._id||d.yaxis!==i._id||u.push(f)}s("box",t,u,c)}},setPositionOffset:s}},{"../../lib":503,"../../plots/cartesian/axes":554,"../../plots/cartesian/constraints":562}],676:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../registry"),a=t("../../components/color"),o=t("../scatter/period_defaults"),s=t("../bar/defaults").handleGroupingDefaults,l=t("../../plots/cartesian/axis_autotype"),c=t("./attributes");function u(t,e,r,a){function o(t){var e=0;return t&&t.length&&(e+=1,n.isArrayOrTypedArray(t[0])&&t[0].length&&(e+=1)),e}function s(e){return n.validate(t[e],c[e])}var u,f=r("y"),h=r("x");if("box"===e.type){var p=r("q1"),d=r("median"),m=r("q3");e._hasPreCompStats=p&&p.length&&d&&d.length&&m&&m.length,u=Math.min(n.minRowLength(p),n.minRowLength(d),n.minRowLength(m))}var g,v,y=o(f),x=o(h),b=y&&n.minRowLength(f),_=x&&n.minRowLength(h),w=a.calendar,T={autotypenumbers:a.autotypenumbers};if(e._hasPreCompStats)switch(String(x)+String(y)){case"00":var k=s("x0")||s("dx");g=(s("y0")||s("dy"))&&!k?"h":"v",v=u;break;case"10":g="v",v=Math.min(u,_);break;case"20":g="h",v=Math.min(u,h.length);break;case"01":g="h",v=Math.min(u,b);break;case"02":g="v",v=Math.min(u,f.length);break;case"12":g="v",v=Math.min(u,_,f.length);break;case"21":g="h",v=Math.min(u,h.length,b);break;case"11":v=0;break;case"22":var A,M=!1;for(A=0;A<h.length;A++)if("category"===l(h[A],w,T)){M=!0;break}if(M)g="v",v=Math.min(u,_,f.length);else{for(A=0;A<f.length;A++)if("category"===l(f[A],w,T)){M=!0;break}M?(g="h",v=Math.min(u,h.length,b)):(g="v",v=Math.min(u,_,f.length))}}else y>0?(g="v",v=x>0?Math.min(_,b):Math.min(b)):x>0?(g="h",v=Math.min(_)):v=0;if(v){e._length=v;var S=r("orientation",g);e._hasPreCompStats?"v"===S&&0===x?(r("x0",0),r("dx",1)):"h"===S&&0===y&&(r("y0",0),r("dy",1)):"v"===S&&0===x?r("x0"):"h"===S&&0===y&&r("y0"),i.getComponentMethod("calendars","handleTraceDefaults")(t,e,["x","y"],a)}else e.visible=!1}function f(t,e,r,i){var a=i.prefix,o=n.coerce2(t,e,c,"marker.outliercolor"),s=r("marker.line.outliercolor"),l="outliers";e._hasPreCompStats?l="all":(o||s)&&(l="suspectedoutliers");var u=r(a+"points",l);u?(r("jitter","all"===u?.3:0),r("pointpos","all"===u?-1.5:0),r("marker.symbol"),r("marker.opacity"),r("marker.size"),r("marker.color",e.line.color),r("marker.line.color"),r("marker.line.width"),"suspectedoutliers"===u&&(r("marker.line.outliercolor",e.marker.color),r("marker.line.outlierwidth")),r("selected.marker.color"),r("unselected.marker.color"),r("selected.marker.size"),r("unselected.marker.size"),r("text"),r("hovertext")):delete e.marker;var f=r("hoveron");"all"!==f&&-1===f.indexOf("points")||r("hovertemplate"),n.coerceSelectionMarkerOpacity(e,r)}e.exports={supplyDefaults:function(t,e,r,i){function s(r,i){return n.coerce(t,e,c,r,i)}if(u(t,e,s,i),!1!==e.visible){o(t,e,i,s),s("xhoverformat"),s("yhoverformat");var l=e._hasPreCompStats;l&&(s("lowerfence"),s("upperfence")),s("line.color",(t.marker||{}).color||r),s("line.width"),s("fillcolor",a.addOpacity(e.line.color,.5));var h=!1;if(l){var p=s("mean"),d=s("sd");p&&p.length&&(h=!0,d&&d.length&&(h="sd"))}s("boxmean",h),s("whiskerwidth"),s("width"),s("quartilemethod");var m=!1;if(l){var g=s("notchspan");g&&g.length&&(m=!0)}else n.validate(t.notchwidth,c.notchwidth)&&(m=!0);s("notched",m)&&s("notchwidth"),f(t,e,s,{prefix:"box"})}},crossTraceDefaults:function(t,e){var r,i;function a(t){return n.coerce(i._input,i,c,t)}for(var o=0;o<t.length;o++){var l=(i=t[o]).type;"box"!==l&&"violin"!==l||(r=i._input,"group"===e[l+"mode"]&&s(r,i,e,a))}},handleSampleDefaults:u,handlePointsDefaults:f}},{"../../components/color":366,"../../lib":503,"../../plots/cartesian/axis_autotype":555,"../../registry":638,"../bar/defaults":652,"../scatter/period_defaults":947,"./attributes":673}],677:[function(t,e,r){"use strict";e.exports=function(t,e){return e.hoverOnBox&&(t.hoverOnBox=e.hoverOnBox),"xVal"in e&&(t.x=e.xVal),"yVal"in e&&(t.y=e.yVal),e.xa&&(t.xaxis=e.xa),e.ya&&(t.yaxis=e.ya),t}},{}],678:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes"),i=t("../../lib"),a=t("../../components/fx"),o=t("../../components/color"),s=i.fillText;function l(t,e,r,s){var l,c,u,f,h,p,d,m,g,v,y,x,b,_,w=t.cd,T=t.xa,k=t.ya,A=w[0].trace,M=w[0].t,S="violin"===A.type,E=[],L=M.bdPos,C=M.wHover,P=function(t){return u.c2l(t.pos)+M.bPos-u.c2l(p)};S&&"both"!==A.side?("positive"===A.side&&(g=function(t){var e=P(t);return a.inbox(e,e+C,v)},x=L,b=0),"negative"===A.side&&(g=function(t){var e=P(t);return a.inbox(e-C,e,v)},x=0,b=L)):(g=function(t){var e=P(t);return a.inbox(e-C,e+C,v)},x=b=L),_=S?function(t){return a.inbox(t.span[0]-h,t.span[1]-h,v)}:function(t){return a.inbox(t.min-h,t.max-h,v)},"h"===A.orientation?(h=e,p=r,d=_,m=g,l="y",u=k,c="x",f=T):(h=r,p=e,d=g,m=_,l="x",u=T,c="y",f=k);var I=Math.min(1,L/Math.abs(u.r2c(u.range[1])-u.r2c(u.range[0])));function O(t){return(d(t)+m(t))/2}v=t.maxHoverDistance-I,y=t.maxSpikeDistance-I;var z=a.getDistanceFunction(s,d,m,O);if(a.getClosest(w,z,t),!1===t.index)return[];var D=w[t.index],R=A.line.color,F=(A.marker||{}).color;o.opacity(R)&&A.line.width?t.color=R:o.opacity(F)&&A.boxpoints?t.color=F:t.color=A.fillcolor,t[l+"0"]=u.c2p(D.pos+M.bPos-b,!0),t[l+"1"]=u.c2p(D.pos+M.bPos+x,!0),t[l+"LabelVal"]=void 0!==D.orig_p?D.orig_p:D.pos;var B=l+"Spike";t.spikeDistance=O(D)*y/v,t[B]=u.c2p(D.pos,!0);var N={},j=["med","q1","q3","min","max"];(A.boxmean||(A.meanline||{}).visible)&&j.push("mean"),(A.boxpoints||A.points)&&j.push("lf","uf");for(var U=0;U<j.length;U++){var V=j[U];if(V in D&&!(D[V]in N)){N[D[V]]=!0;var H=D[V],q=f.c2p(H,!0),G=i.extendFlat({},t);G.attr=V,G[c+"0"]=G[c+"1"]=q,G[c+"LabelVal"]=H,G[c+"Label"]=(M.labels?M.labels[V]+" ":"")+n.hoverLabelText(f,H,A[c+"hoverformat"]),G.hoverOnBox=!0,"mean"===V&&"sd"in D&&"sd"===A.boxmean&&(G[c+"err"]=D.sd),t.name="",t.spikeDistance=void 0,t[B]=void 0,G.hovertemplate=!1,E.push(G)}}return E}function c(t,e,r){for(var n,o,l,c=t.cd,u=t.xa,f=t.ya,h=c[0].trace,p=u.c2p(e),d=f.c2p(r),m=a.quadrature((function(t){var e=Math.max(3,t.mrc||0);return Math.max(Math.abs(u.c2p(t.x)-p)-e,1-3/e)}),(function(t){var e=Math.max(3,t.mrc||0);return Math.max(Math.abs(f.c2p(t.y)-d)-e,1-3/e)})),g=!1,v=0;v<c.length;v++){o=c[v];for(var y=0;y<(o.pts||[]).length;y++){var x=m(l=o.pts[y]);x<=t.distance&&(t.distance=x,g=[v,y])}}if(!g)return!1;l=(o=c[g[0]]).pts[g[1]];var b=u.c2p(l.x,!0),_=f.c2p(l.y,!0),w=l.mrc||1;n=i.extendFlat({},t,{index:l.i,color:(h.marker||{}).color,name:h.name,x0:b-w,x1:b+w,y0:_-w,y1:_+w,spikeDistance:t.distance,hovertemplate:h.hovertemplate});var T,k=o.orig_p,A=void 0!==k?k:o.pos;return"h"===h.orientation?(T=f,n.xLabelVal=l.x,n.yLabelVal=A):(T=u,n.xLabelVal=A,n.yLabelVal=l.y),n[T._id.charAt(0)+"Spike"]=T.c2p(o.pos,!0),s(l,h,n),n}e.exports={hoverPoints:function(t,e,r,n){var i,a=t.cd[0].trace.hoveron,o=[];return-1!==a.indexOf("boxes")&&(o=o.concat(l(t,e,r,n))),-1!==a.indexOf("points")&&(i=c(t,e,r)),"closest"===n?i?[i]:o:i?(o.push(i),o):o},hoverOnBoxes:l,hoverOnPoints:c}},{"../../components/color":366,"../../components/fx":406,"../../lib":503,"../../plots/cartesian/axes":554}],679:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),layoutAttributes:t("./layout_attributes"),supplyDefaults:t("./defaults").supplyDefaults,crossTraceDefaults:t("./defaults").crossTraceDefaults,supplyLayoutDefaults:t("./layout_defaults").supplyLayoutDefaults,calc:t("./calc"),crossTraceCalc:t("./cross_trace_calc").crossTraceCalc,plot:t("./plot").plot,style:t("./style").style,styleOnSelect:t("./style").styleOnSelect,hoverPoints:t("./hover").hoverPoints,eventData:t("./event_data"),selectPoints:t("./select"),moduleType:"trace",name:"box",basePlotModule:t("../../plots/cartesian"),categories:["cartesian","svg","symbols","oriented","box-violin","showLegend","boxLayout","zoomScale"],meta:{}}},{"../../plots/cartesian":568,"./attributes":673,"./calc":674,"./cross_trace_calc":675,"./defaults":676,"./event_data":677,"./hover":678,"./layout_attributes":680,"./layout_defaults":681,"./plot":682,"./select":683,"./style":684}],680:[function(t,e,r){"use strict";e.exports={boxmode:{valType:"enumerated",values:["group","overlay"],dflt:"overlay",editType:"calc"},boxgap:{valType:"number",min:0,max:1,dflt:.3,editType:"calc"},boxgroupgap:{valType:"number",min:0,max:1,dflt:.3,editType:"calc"}}},{}],681:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib"),a=t("./layout_attributes");function o(t,e,r,i,a){for(var o=a+"Layout",s=!1,l=0;l<r.length;l++){var c=r[l];if(n.traceIs(c,o)){s=!0;break}}s&&(i(a+"mode"),i(a+"gap"),i(a+"groupgap"))}e.exports={supplyLayoutDefaults:function(t,e,r){o(0,0,r,(function(r,n){return i.coerce(t,e,a,r,n)}),"box")},_supply:o}},{"../../lib":503,"../../registry":638,"./layout_attributes":680}],682:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../../components/drawing");function o(t,e,r,a){var o,s,l="h"===r.orientation,c=e.val,u=e.pos,f=!!u.rangebreaks,h=a.bPos,p=a.wdPos||0,d=a.bPosPxOffset||0,m=r.whiskerwidth||0,g=r.notched||!1,v=g?1-2*r.notchwidth:1;Array.isArray(a.bdPos)?(o=a.bdPos[0],s=a.bdPos[1]):(o=a.bdPos,s=a.bdPos);var y=t.selectAll("path.box").data("violin"!==r.type||r.box.visible?i.identity:[]);y.enter().append("path").style("vector-effect","non-scaling-stroke").attr("class","box"),y.exit().remove(),y.each((function(t){if(t.empty)return"M0,0Z";var e=u.c2l(t.pos+h,!0),a=u.l2p(e-o)+d,y=u.l2p(e+s)+d,x=f?(a+y)/2:u.l2p(e)+d,b=r.whiskerwidth,_=f?a*b+(1-b)*x:u.l2p(e-p)+d,w=f?y*b+(1-b)*x:u.l2p(e+p)+d,T=u.l2p(e-o*v)+d,k=u.l2p(e+s*v)+d,A=c.c2p(t.q1,!0),M=c.c2p(t.q3,!0),S=i.constrain(c.c2p(t.med,!0),Math.min(A,M)+1,Math.max(A,M)-1),E=void 0===t.lf||!1===r.boxpoints,L=c.c2p(E?t.min:t.lf,!0),C=c.c2p(E?t.max:t.uf,!0),P=c.c2p(t.ln,!0),I=c.c2p(t.un,!0);l?n.select(this).attr("d","M"+S+","+T+"V"+k+"M"+A+","+a+"V"+y+(g?"H"+P+"L"+S+","+k+"L"+I+","+y:"")+"H"+M+"V"+a+(g?"H"+I+"L"+S+","+T+"L"+P+","+a:"")+"ZM"+A+","+x+"H"+L+"M"+M+","+x+"H"+C+(0===m?"":"M"+L+","+_+"V"+w+"M"+C+","+_+"V"+w)):n.select(this).attr("d","M"+T+","+S+"H"+k+"M"+a+","+A+"H"+y+(g?"V"+P+"L"+k+","+S+"L"+y+","+I:"")+"V"+M+"H"+a+(g?"V"+I+"L"+T+","+S+"L"+a+","+P:"")+"ZM"+x+","+A+"V"+L+"M"+x+","+M+"V"+C+(0===m?"":"M"+_+","+L+"H"+w+"M"+_+","+C+"H"+w))}))}function s(t,e,r,n){var o=e.x,s=e.y,l=n.bdPos,c=n.bPos,u=r.boxpoints||r.points;i.seedPseudoRandom();var f=t.selectAll("g.points").data(u?function(t){return t.forEach((function(t){t.t=n,t.trace=r})),t}:[]);f.enter().append("g").attr("class","points"),f.exit().remove();var h=f.selectAll("path").data((function(t){var e,n,a=t.pts2,o=Math.max((t.max-t.min)/10,t.q3-t.q1),s=1e-9*o,f=.01*o,h=[],p=0;if(r.jitter){if(0===o)for(p=1,h=new Array(a.length),e=0;e<a.length;e++)h[e]=1;else for(e=0;e<a.length;e++){var d=Math.max(0,e-5),m=a[d].v,g=Math.min(a.length-1,e+5),v=a[g].v;"all"!==u&&(a[e].v<t.lf?v=Math.min(v,t.lf):m=Math.max(m,t.uf));var y=Math.sqrt(f*(g-d)/(v-m+s))||0;y=i.constrain(Math.abs(y),0,1),h.push(y),p=Math.max(y,p)}n=2*r.jitter/(p||1)}for(e=0;e<a.length;e++){var x=a[e],b=x.v,_=r.jitter?n*h[e]*(i.pseudoRandom()-.5):0,w=t.pos+c+l*(r.pointpos+_);"h"===r.orientation?(x.y=w,x.x=b):(x.x=w,x.y=b),"suspectedoutliers"===u&&b<t.uo&&b>t.lo&&(x.so=!0)}return a}));h.enter().append("path").classed("point",!0),h.exit().remove(),h.call(a.translatePoints,o,s)}function l(t,e,r,a){var o,s,l=e.val,c=e.pos,u=!!c.rangebreaks,f=a.bPos,h=a.bPosPxOffset||0,p=r.boxmean||(r.meanline||{}).visible;Array.isArray(a.bdPos)?(o=a.bdPos[0],s=a.bdPos[1]):(o=a.bdPos,s=a.bdPos);var d=t.selectAll("path.mean").data("box"===r.type&&r.boxmean||"violin"===r.type&&r.box.visible&&r.meanline.visible?i.identity:[]);d.enter().append("path").attr("class","mean").style({fill:"none","vector-effect":"non-scaling-stroke"}),d.exit().remove(),d.each((function(t){var e=c.c2l(t.pos+f,!0),i=c.l2p(e-o)+h,a=c.l2p(e+s)+h,d=u?(i+a)/2:c.l2p(e)+h,m=l.c2p(t.mean,!0),g=l.c2p(t.mean-t.sd,!0),v=l.c2p(t.mean+t.sd,!0);"h"===r.orientation?n.select(this).attr("d","M"+m+","+i+"V"+a+("sd"===p?"m0,0L"+g+","+d+"L"+m+","+i+"L"+v+","+d+"Z":"")):n.select(this).attr("d","M"+i+","+m+"H"+a+("sd"===p?"m0,0L"+d+","+g+"L"+i+","+m+"L"+d+","+v+"Z":""))}))}e.exports={plot:function(t,e,r,a){var c=e.xaxis,u=e.yaxis;i.makeTraceGroups(a,r,"trace boxes").each((function(t){var e,r,i=n.select(this),a=t[0],f=a.t,h=a.trace;(f.wdPos=f.bdPos*h.whiskerwidth,!0!==h.visible||f.empty)?i.remove():("h"===h.orientation?(e=u,r=c):(e=c,r=u),o(i,{pos:e,val:r},h,f),s(i,{x:c,y:u},h,f),l(i,{pos:e,val:r},h,f))}))},plotBoxAndWhiskers:o,plotPoints:s,plotBoxMean:l}},{"../../components/drawing":388,"../../lib":503,"@plotly/d3":58}],683:[function(t,e,r){"use strict";e.exports=function(t,e){var r,n,i=t.cd,a=t.xaxis,o=t.yaxis,s=[];if(!1===e)for(r=0;r<i.length;r++)for(n=0;n<(i[r].pts||[]).length;n++)i[r].pts[n].selected=0;else for(r=0;r<i.length;r++)for(n=0;n<(i[r].pts||[]).length;n++){var l=i[r].pts[n],c=a.c2p(l.x),u=o.c2p(l.y);e.contains([c,u],null,l.i,t)?(s.push({pointNumber:l.i,x:a.c2d(l.x),y:o.c2d(l.y)}),l.selected=1):l.selected=0}return s}},{}],684:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/color"),a=t("../../components/drawing");e.exports={style:function(t,e,r){var o=r||n.select(t).selectAll("g.trace.boxes");o.style("opacity",(function(t){return t[0].trace.opacity})),o.each((function(e){var r=n.select(this),o=e[0].trace,s=o.line.width;function l(t,e,r,n){t.style("stroke-width",e+"px").call(i.stroke,r).call(i.fill,n)}var c=r.selectAll("path.box");if("candlestick"===o.type)c.each((function(t){if(!t.empty){var e=n.select(this),r=o[t.dir];l(e,r.line.width,r.line.color,r.fillcolor),e.style("opacity",o.selectedpoints&&!t.selected?.3:1)}}));else{l(c,s,o.line.color,o.fillcolor),r.selectAll("path.mean").style({"stroke-width":s,"stroke-dasharray":2*s+"px,"+s+"px"}).call(i.stroke,o.line.color);var u=r.selectAll("path.point");a.pointStyle(u,o,t)}}))},styleOnSelect:function(t,e,r){var n=e[0].trace,i=r.selectAll("path.point");n.selectedpoints?a.selectedPointStyle(i,n):a.pointStyle(i,n,t)}}},{"../../components/color":366,"../../components/drawing":388,"@plotly/d3":58}],685:[function(t,e,r){"use strict";var n=t("../../lib").extendFlat,i=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,a=t("../ohlc/attributes"),o=t("../box/attributes");function s(t){return{line:{color:n({},o.line.color,{dflt:t}),width:o.line.width,editType:"style"},fillcolor:o.fillcolor,editType:"style"}}e.exports={xperiod:a.xperiod,xperiod0:a.xperiod0,xperiodalignment:a.xperiodalignment,xhoverformat:i("x"),yhoverformat:i("y"),x:a.x,open:a.open,high:a.high,low:a.low,close:a.close,line:{width:n({},o.line.width,{}),editType:"style"},increasing:s(a.increasing.line.color.dflt),decreasing:s(a.decreasing.line.color.dflt),text:a.text,hovertext:a.hovertext,whiskerwidth:n({},o.whiskerwidth,{dflt:0}),hoverlabel:a.hoverlabel}},{"../../lib":503,"../../plots/cartesian/axis_format_attributes":557,"../box/attributes":673,"../ohlc/attributes":872}],686:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axes"),a=t("../../plots/cartesian/align_period"),o=t("../ohlc/calc").calcCommon;function s(t,e,r,n){return{min:r,q1:Math.min(t,n),med:n,q3:Math.max(t,n),max:e}}e.exports=function(t,e){var r=t._fullLayout,l=i.getFromId(t,e.xaxis),c=i.getFromId(t,e.yaxis),u=l.makeCalcdata(e,"x"),f=a(e,l,"x",u).vals,h=o(t,e,u,f,c,s);return h.length?(n.extendFlat(h[0].t,{num:r._numBoxes,dPos:n.distinctVals(f).minDiff/2,posLetter:"x",valLetter:"y"}),r._numBoxes++,h):[{t:{empty:!0}}]}},{"../../lib":503,"../../plots/cartesian/align_period":551,"../../plots/cartesian/axes":554,"../ohlc/calc":873}],687:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/color"),a=t("../ohlc/ohlc_defaults"),o=t("../scatter/period_defaults"),s=t("./attributes");function l(t,e,r,n){var a=r(n+".line.color");r(n+".line.width",e.line.width),r(n+".fillcolor",i.addOpacity(a,.5))}e.exports=function(t,e,r,i){function c(r,i){return n.coerce(t,e,s,r,i)}a(t,e,c,i)?(o(t,e,i,c,{x:!0}),c("xhoverformat"),c("yhoverformat"),c("line.width"),l(t,e,c,"increasing"),l(t,e,c,"decreasing"),c("text"),c("hovertext"),c("whiskerwidth"),i._requestRangeslider[e.xaxis]=!0):e.visible=!1}},{"../../components/color":366,"../../lib":503,"../ohlc/ohlc_defaults":877,"../scatter/period_defaults":947,"./attributes":685}],688:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"candlestick",basePlotModule:t("../../plots/cartesian"),categories:["cartesian","svg","showLegend","candlestick","boxLayout"],meta:{},attributes:t("./attributes"),layoutAttributes:t("../box/layout_attributes"),supplyLayoutDefaults:t("../box/layout_defaults").supplyLayoutDefaults,crossTraceCalc:t("../box/cross_trace_calc").crossTraceCalc,supplyDefaults:t("./defaults"),calc:t("./calc"),plot:t("../box/plot").plot,layerName:"boxlayer",style:t("../box/style").style,hoverPoints:t("../ohlc/hover").hoverPoints,selectPoints:t("../ohlc/select")}},{"../../plots/cartesian":568,"../box/cross_trace_calc":675,"../box/layout_attributes":680,"../box/layout_defaults":681,"../box/plot":682,"../box/style":684,"../ohlc/hover":875,"../ohlc/select":879,"./attributes":685,"./calc":686,"./defaults":687}],689:[function(t,e,r){"use strict";var n=t("./axis_defaults"),i=t("../../plot_api/plot_template");e.exports=function(t,e,r,a,o){a("a")||(a("da"),a("a0")),a("b")||(a("db"),a("b0")),function(t,e,r,a){["aaxis","baxis"].forEach((function(o){var s=o.charAt(0),l=t[o]||{},c=i.newContainer(e,o),u={noTicklabelstep:!0,tickfont:"x",id:s+"axis",letter:s,font:e.font,name:o,data:t[s],calendar:e.calendar,dfltColor:a,bgColor:r.paper_bgcolor,autotypenumbersDflt:r.autotypenumbers,fullLayout:r};n(l,c,u),c._categories=c._categories||[],t[o]||"-"===l.type||(t[o]={type:l.type})}))}(t,e,r,o)}},{"../../plot_api/plot_template":543,"./axis_defaults":694}],690:[function(t,e,r){"use strict";var n=t("../../lib").isArrayOrTypedArray;e.exports=function(t){return function t(e,r){if(!n(e)||r>=10)return null;for(var i=1/0,a=-1/0,o=e.length,s=0;s<o;s++){var l=e[s];if(n(l)){var c=t(l,r+1);c&&(i=Math.min(c[0],i),a=Math.max(c[1],a))}else i=Math.min(l,i),a=Math.max(l,a)}return[i,a]}(t,0)}},{"../../lib":503}],691:[function(t,e,r){"use strict";var n=t("../../plots/font_attributes"),i=t("./axis_attributes"),a=t("../../components/color/attributes"),o=n({editType:"calc"});o.family.dflt='"Open Sans", verdana, arial, sans-serif',o.size.dflt=12,o.color.dflt=a.defaultLine,e.exports={carpet:{valType:"string",editType:"calc"},x:{valType:"data_array",editType:"calc+clearAxisTypes"},y:{valType:"data_array",editType:"calc+clearAxisTypes"},a:{valType:"data_array",editType:"calc"},a0:{valType:"number",dflt:0,editType:"calc"},da:{valType:"number",dflt:1,editType:"calc"},b:{valType:"data_array",editType:"calc"},b0:{valType:"number",dflt:0,editType:"calc"},db:{valType:"number",dflt:1,editType:"calc"},cheaterslope:{valType:"number",dflt:1,editType:"calc"},aaxis:i,baxis:i,font:o,color:{valType:"color",dflt:a.defaultLine,editType:"plot"},transforms:void 0}},{"../../components/color/attributes":365,"../../plots/font_attributes":585,"./axis_attributes":693}],692:[function(t,e,r){"use strict";var n=t("../../lib").isArrayOrTypedArray;e.exports=function(t,e,r,i){var a,o,s,l,c,u,f,h,p,d,m,g,v,y=n(r)?"a":"b",x=("a"===y?t.aaxis:t.baxis).smoothing,b="a"===y?t.a2i:t.b2j,_="a"===y?r:i,w="a"===y?i:r,T="a"===y?e.a.length:e.b.length,k="a"===y?e.b.length:e.a.length,A=Math.floor("a"===y?t.b2j(w):t.a2i(w)),M="a"===y?function(e){return t.evalxy([],e,A)}:function(e){return t.evalxy([],A,e)};x&&(s=Math.max(0,Math.min(k-2,A)),l=A-s,o="a"===y?function(e,r){return t.dxydi([],e,s,r,l)}:function(e,r){return t.dxydj([],s,e,l,r)});var S=b(_[0]),E=b(_[1]),L=S<E?1:-1,C=1e-8*(E-S),P=L>0?Math.floor:Math.ceil,I=L>0?Math.ceil:Math.floor,O=L>0?Math.min:Math.max,z=L>0?Math.max:Math.min,D=P(S+C),R=I(E-C),F=[[f=M(S)]];for(a=D;a*L<R*L;a+=L)c=[],m=z(S,a),v=(g=O(E,a+L))-m,u=Math.max(0,Math.min(T-2,Math.floor(.5*(m+g)))),h=M(g),x&&(p=o(u,m-u),d=o(u,g-u),c.push([f[0]+p[0]/3*v,f[1]+p[1]/3*v]),c.push([h[0]-d[0]/3*v,h[1]-d[1]/3*v])),c.push(h),F.push(c),f=h;return F}},{"../../lib":503}],693:[function(t,e,r){"use strict";var n=t("../../plots/font_attributes"),i=t("../../components/color/attributes"),a=t("../../plots/cartesian/layout_attributes"),o=t("../../plots/cartesian/axis_format_attributes").descriptionWithDates,s=t("../../plot_api/edit_types").overrideAll,l=t("../../components/drawing/attributes").dash,c=t("../../lib/extend").extendFlat;e.exports={color:{valType:"color",editType:"calc"},smoothing:{valType:"number",dflt:1,min:0,max:1.3,editType:"calc"},title:{text:{valType:"string",dflt:"",editType:"calc"},font:n({editType:"calc"}),offset:{valType:"number",dflt:10,editType:"calc"},editType:"calc"},type:{valType:"enumerated",values:["-","linear","date","category"],dflt:"-",editType:"calc"},autotypenumbers:a.autotypenumbers,autorange:{valType:"enumerated",values:[!0,!1,"reversed"],dflt:!0,editType:"calc"},rangemode:{valType:"enumerated",values:["normal","tozero","nonnegative"],dflt:"normal",editType:"calc"},range:{valType:"info_array",editType:"calc",items:[{valType:"any",editType:"calc"},{valType:"any",editType:"calc"}]},fixedrange:{valType:"boolean",dflt:!1,editType:"calc"},cheatertype:{valType:"enumerated",values:["index","value"],dflt:"value",editType:"calc"},tickmode:{valType:"enumerated",values:["linear","array"],dflt:"array",editType:"calc"},nticks:{valType:"integer",min:0,dflt:0,editType:"calc"},tickvals:{valType:"data_array",editType:"calc"},ticktext:{valType:"data_array",editType:"calc"},showticklabels:{valType:"enumerated",values:["start","end","both","none"],dflt:"start",editType:"calc"},tickfont:n({editType:"calc"}),tickangle:{valType:"angle",dflt:"auto",editType:"calc"},tickprefix:{valType:"string",dflt:"",editType:"calc"},showtickprefix:{valType:"enumerated",values:["all","first","last","none"],dflt:"all",editType:"calc"},ticksuffix:{valType:"string",dflt:"",editType:"calc"},showticksuffix:{valType:"enumerated",values:["all","first","last","none"],dflt:"all",editType:"calc"},showexponent:{valType:"enumerated",values:["all","first","last","none"],dflt:"all",editType:"calc"},exponentformat:{valType:"enumerated",values:["none","e","E","power","SI","B"],dflt:"B",editType:"calc"},minexponent:{valType:"number",dflt:3,min:0,editType:"calc"},separatethousands:{valType:"boolean",dflt:!1,editType:"calc"},tickformat:{valType:"string",dflt:"",editType:"calc",description:o("tick label")},tickformatstops:s(a.tickformatstops,"calc","from-root"),categoryorder:{valType:"enumerated",values:["trace","category ascending","category descending","array"],dflt:"trace",editType:"calc"},categoryarray:{valType:"data_array",editType:"calc"},labelpadding:{valType:"integer",dflt:10,editType:"calc"},labelprefix:{valType:"string",editType:"calc"},labelsuffix:{valType:"string",dflt:"",editType:"calc"},showline:{valType:"boolean",dflt:!1,editType:"calc"},linecolor:{valType:"color",dflt:i.defaultLine,editType:"calc"},linewidth:{valType:"number",min:0,dflt:1,editType:"calc"},gridcolor:{valType:"color",editType:"calc"},gridwidth:{valType:"number",min:0,dflt:1,editType:"calc"},griddash:c({},l,{editType:"calc"}),showgrid:{valType:"boolean",dflt:!0,editType:"calc"},minorgridcount:{valType:"integer",min:0,dflt:0,editType:"calc"},minorgridwidth:{valType:"number",min:0,dflt:1,editType:"calc"},minorgriddash:c({},l,{editType:"calc"}),minorgridcolor:{valType:"color",dflt:i.lightLine,editType:"calc"},startline:{valType:"boolean",editType:"calc"},startlinecolor:{valType:"color",editType:"calc"},startlinewidth:{valType:"number",dflt:1,editType:"calc"},endline:{valType:"boolean",editType:"calc"},endlinewidth:{valType:"number",dflt:1,editType:"calc"},endlinecolor:{valType:"color",editType:"calc"},tick0:{valType:"number",min:0,dflt:0,editType:"calc"},dtick:{valType:"number",min:0,dflt:1,editType:"calc"},arraytick0:{valType:"integer",min:0,dflt:0,editType:"calc"},arraydtick:{valType:"integer",min:1,dflt:1,editType:"calc"},_deprecated:{title:{valType:"string",editType:"calc"},titlefont:n({editType:"calc"}),titleoffset:{valType:"number",dflt:10,editType:"calc"}},editType:"calc"}},{"../../components/color/attributes":365,"../../components/drawing/attributes":387,"../../lib/extend":493,"../../plot_api/edit_types":536,"../../plots/cartesian/axis_format_attributes":557,"../../plots/cartesian/layout_attributes":569,"../../plots/font_attributes":585}],694:[function(t,e,r){"use strict";var n=t("./attributes"),i=t("../../components/color").addOpacity,a=t("../../registry"),o=t("../../lib"),s=t("../../plots/cartesian/tick_value_defaults"),l=t("../../plots/cartesian/tick_label_defaults"),c=t("../../plots/cartesian/prefix_suffix_defaults"),u=t("../../plots/cartesian/category_order_defaults"),f=t("../../plots/cartesian/set_convert"),h=t("../../plots/cartesian/axis_autotype");e.exports=function(t,e,r){var p=r.letter,d=r.font||{},m=n[p+"axis"];function g(r,n){return o.coerce(t,e,m,r,n)}function v(r,n){return o.coerce2(t,e,m,r,n)}r.name&&(e._name=r.name,e._id=r.name),g("autotypenumbers",r.autotypenumbersDflt);var y=g("type");("-"===y&&(r.data&&function(t,e){if("-"!==t.type)return;var r=t._id.charAt(0),n=t[r+"calendar"];t.type=h(e,n,{autotypenumbers:t.autotypenumbers})}(e,r.data),"-"===e.type?e.type="linear":y=t.type=e.type),g("smoothing"),g("cheatertype"),g("showticklabels"),g("labelprefix",p+" = "),g("labelsuffix"),g("showtickprefix"),g("showticksuffix"),g("separatethousands"),g("tickformat"),g("exponentformat"),g("minexponent"),g("showexponent"),g("categoryorder"),g("tickmode"),g("tickvals"),g("ticktext"),g("tick0"),g("dtick"),"array"===e.tickmode&&(g("arraytick0"),g("arraydtick")),g("labelpadding"),e._hovertitle=p,"date"===y)&&a.getComponentMethod("calendars","handleDefaults")(t,e,"calendar",r.calendar);f(e,r.fullLayout),e.c2p=o.identity;var x=g("color",r.dfltColor),b=x===t.color?x:d.color;g("title.text")&&(o.coerceFont(g,"title.font",{family:d.family,size:o.bigFont(d.size),color:b}),g("title.offset")),g("tickangle"),g("autorange",!e.isValidRange(t.range))&&g("rangemode"),g("range"),e.cleanRange(),g("fixedrange"),s(t,e,g,y),c(t,e,g,y,r),l(t,e,g,y,r),u(t,e,g,{data:r.data,dataAttr:p});var _=v("gridcolor",i(x,.3)),w=v("gridwidth"),T=v("griddash"),k=g("showgrid");k||(delete e.gridcolor,delete e.gridwidth,delete e.griddash);var A=v("startlinecolor",x),M=v("startlinewidth",w);g("startline",e.showgrid||!!A||!!M)||(delete e.startlinecolor,delete e.startlinewidth);var S=v("endlinecolor",x),E=v("endlinewidth",w);return g("endline",e.showgrid||!!S||!!E)||(delete e.endlinecolor,delete e.endlinewidth),k?(g("minorgridcount"),g("minorgridwidth",w),g("minorgriddash",T),g("minorgridcolor",i(_,.06)),e.minorgridcount||(delete e.minorgridwidth,delete e.minorgriddash,delete e.minorgridcolor)):(delete e.gridcolor,delete e.gridwidth,delete e.griddash),"none"===e.showticklabels&&(delete e.tickfont,delete e.tickangle,delete e.showexponent,delete e.exponentformat,delete e.minexponent,delete e.tickformat,delete e.showticksuffix,delete e.showtickprefix),e.showticksuffix||delete e.ticksuffix,e.showtickprefix||delete e.tickprefix,g("tickmode"),e}},{"../../components/color":366,"../../lib":503,"../../plots/cartesian/axis_autotype":555,"../../plots/cartesian/category_order_defaults":559,"../../plots/cartesian/prefix_suffix_defaults":573,"../../plots/cartesian/set_convert":576,"../../plots/cartesian/tick_label_defaults":578,"../../plots/cartesian/tick_value_defaults":580,"../../registry":638,"./attributes":691}],695:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes"),i=t("../../lib").isArray1D,a=t("./cheater_basis"),o=t("./array_minmax"),s=t("./calc_gridlines"),l=t("./calc_labels"),c=t("./calc_clippath"),u=t("../heatmap/clean_2d_array"),f=t("./smooth_fill_2d_array"),h=t("../heatmap/convert_column_xyz"),p=t("./set_convert");e.exports=function(t,e){var r=n.getFromId(t,e.xaxis),d=n.getFromId(t,e.yaxis),m=e.aaxis,g=e.baxis,v=e.x,y=e.y,x=[];v&&i(v)&&x.push("x"),y&&i(y)&&x.push("y"),x.length&&h(e,m,g,"a","b",x);var b=e._a=e._a||e.a,_=e._b=e._b||e.b;v=e._x||e.x,y=e._y||e.y;var w={};if(e._cheater){var T="index"===m.cheatertype?b.length:b,k="index"===g.cheatertype?_.length:_;v=a(T,k,e.cheaterslope)}e._x=v=u(v),e._y=y=u(y),f(v,b,_),f(y,b,_),p(e),e.setScale();var A=o(v),M=o(y),S=.5*(A[1]-A[0]),E=.5*(A[1]+A[0]),L=.5*(M[1]-M[0]),C=.5*(M[1]+M[0]);return A=[E-1.3*S,E+1.3*S],M=[C-1.3*L,C+1.3*L],e._extremes[r._id]=n.findExtremes(r,A,{padded:!0}),e._extremes[d._id]=n.findExtremes(d,M,{padded:!0}),s(e,"a","b"),s(e,"b","a"),l(e,m),l(e,g),w.clipsegments=c(e._xctrl,e._yctrl,m,g),w.x=v,w.y=y,w.a=b,w.b=_,[w]}},{"../../lib":503,"../../plots/cartesian/axes":554,"../heatmap/clean_2d_array":794,"../heatmap/convert_column_xyz":796,"./array_minmax":690,"./calc_clippath":696,"./calc_gridlines":697,"./calc_labels":698,"./cheater_basis":700,"./set_convert":713,"./smooth_fill_2d_array":714}],696:[function(t,e,r){"use strict";e.exports=function(t,e,r,n){var i,a,o,s=[],l=!!r.smoothing,c=!!n.smoothing,u=t[0].length-1,f=t.length-1;for(i=0,a=[],o=[];i<=u;i++)a[i]=t[0][i],o[i]=e[0][i];for(s.push({x:a,y:o,bicubic:l}),i=0,a=[],o=[];i<=f;i++)a[i]=t[i][u],o[i]=e[i][u];for(s.push({x:a,y:o,bicubic:c}),i=u,a=[],o=[];i>=0;i--)a[u-i]=t[f][i],o[u-i]=e[f][i];for(s.push({x:a,y:o,bicubic:l}),i=f,a=[],o=[];i>=0;i--)a[f-i]=t[i][0],o[f-i]=e[i][0];return s.push({x:a,y:o,bicubic:c}),s}},{}],697:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes"),i=t("../../lib/extend").extendFlat;e.exports=function(t,e,r){var a,o,s,l,c,u,f,h,p,d,m,g,v,y,x=t["_"+e],b=t[e+"axis"],_=b._gridlines=[],w=b._minorgridlines=[],T=b._boundarylines=[],k=t["_"+r],A=t[r+"axis"];"array"===b.tickmode&&(b.tickvals=x.slice());var M=t._xctrl,S=t._yctrl,E=M[0].length,L=M.length,C=t._a.length,P=t._b.length;n.prepTicks(b),"array"===b.tickmode&&delete b.tickvals;var I=b.smoothing?3:1;function O(n){var i,a,o,s,l,c,u,f,p,d,m,g,v=[],y=[],x={};if("b"===e)for(a=t.b2j(n),o=Math.floor(Math.max(0,Math.min(P-2,a))),s=a-o,x.length=P,x.crossLength=C,x.xy=function(e){return t.evalxy([],e,a)},x.dxy=function(e,r){return t.dxydi([],e,o,r,s)},i=0;i<C;i++)c=Math.min(C-2,i),u=i-c,f=t.evalxy([],i,a),A.smoothing&&i>0&&(p=t.dxydi([],i-1,o,0,s),v.push(l[0]+p[0]/3),y.push(l[1]+p[1]/3),d=t.dxydi([],i-1,o,1,s),v.push(f[0]-d[0]/3),y.push(f[1]-d[1]/3)),v.push(f[0]),y.push(f[1]),l=f;else for(i=t.a2i(n),c=Math.floor(Math.max(0,Math.min(C-2,i))),u=i-c,x.length=C,x.crossLength=P,x.xy=function(e){return t.evalxy([],i,e)},x.dxy=function(e,r){return t.dxydj([],c,e,u,r)},a=0;a<P;a++)o=Math.min(P-2,a),s=a-o,f=t.evalxy([],i,a),A.smoothing&&a>0&&(m=t.dxydj([],c,a-1,u,0),v.push(l[0]+m[0]/3),y.push(l[1]+m[1]/3),g=t.dxydj([],c,a-1,u,1),v.push(f[0]-g[0]/3),y.push(f[1]-g[1]/3)),v.push(f[0]),y.push(f[1]),l=f;return x.axisLetter=e,x.axis=b,x.crossAxis=A,x.value=n,x.constvar=r,x.index=h,x.x=v,x.y=y,x.smoothing=A.smoothing,x}function z(n){var i,a,o,s,l,c=[],u=[],f={};if(f.length=x.length,f.crossLength=k.length,"b"===e)for(o=Math.max(0,Math.min(P-2,n)),l=Math.min(1,Math.max(0,n-o)),f.xy=function(e){return t.evalxy([],e,n)},f.dxy=function(e,r){return t.dxydi([],e,o,r,l)},i=0;i<E;i++)c[i]=M[n*I][i],u[i]=S[n*I][i];else for(a=Math.max(0,Math.min(C-2,n)),s=Math.min(1,Math.max(0,n-a)),f.xy=function(e){return t.evalxy([],n,e)},f.dxy=function(e,r){return t.dxydj([],a,e,s,r)},i=0;i<L;i++)c[i]=M[i][n*I],u[i]=S[i][n*I];return f.axisLetter=e,f.axis=b,f.crossAxis=A,f.value=x[n],f.constvar=r,f.index=n,f.x=c,f.y=u,f.smoothing=A.smoothing,f}if("array"===b.tickmode){for(l=5e-15,u=(c=[Math.floor((x.length-1-b.arraytick0)/b.arraydtick*(1+l)),Math.ceil(-b.arraytick0/b.arraydtick/(1+l))].sort((function(t,e){return t-e})))[0]-1,f=c[1]+1,h=u;h<f;h++)(o=b.arraytick0+b.arraydtick*h)<0||o>x.length-1||_.push(i(z(o),{color:b.gridcolor,width:b.gridwidth,dash:b.griddash}));for(h=u;h<f;h++)if(s=b.arraytick0+b.arraydtick*h,m=Math.min(s+b.arraydtick,x.length-1),!(s<0||s>x.length-1||m<0||m>x.length-1))for(g=x[s],v=x[m],a=0;a<b.minorgridcount;a++)(y=m-s)<=0||(d=g+(v-g)*(a+1)/(b.minorgridcount+1)*(b.arraydtick/y))<x[0]||d>x[x.length-1]||w.push(i(O(d),{color:b.minorgridcolor,width:b.minorgridwidth,dash:b.minorgriddash}));b.startline&&T.push(i(z(0),{color:b.startlinecolor,width:b.startlinewidth})),b.endline&&T.push(i(z(x.length-1),{color:b.endlinecolor,width:b.endlinewidth}))}else{for(l=5e-15,u=(c=[Math.floor((x[x.length-1]-b.tick0)/b.dtick*(1+l)),Math.ceil((x[0]-b.tick0)/b.dtick/(1+l))].sort((function(t,e){return t-e})))[0],f=c[1],h=u;h<=f;h++)p=b.tick0+b.dtick*h,_.push(i(O(p),{color:b.gridcolor,width:b.gridwidth,dash:b.griddash}));for(h=u-1;h<f+1;h++)for(p=b.tick0+b.dtick*h,a=0;a<b.minorgridcount;a++)(d=p+b.dtick*(a+1)/(b.minorgridcount+1))<x[0]||d>x[x.length-1]||w.push(i(O(d),{color:b.minorgridcolor,width:b.minorgridwidth,dash:b.minorgriddash}));b.startline&&T.push(i(O(x[0]),{color:b.startlinecolor,width:b.startlinewidth})),b.endline&&T.push(i(O(x[x.length-1]),{color:b.endlinecolor,width:b.endlinewidth}))}}},{"../../lib/extend":493,"../../plots/cartesian/axes":554}],698:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes"),i=t("../../lib/extend").extendFlat;e.exports=function(t,e){var r,a,o,s=e._labels=[],l=e._gridlines;for(r=0;r<l.length;r++)o=l[r],-1!==["start","both"].indexOf(e.showticklabels)&&(a=n.tickText(e,o.value),i(a,{prefix:void 0,suffix:void 0,endAnchor:!0,xy:o.xy(0),dxy:o.dxy(0,0),axis:o.axis,length:o.crossAxis.length,font:o.axis.tickfont,isFirst:0===r,isLast:r===l.length-1}),s.push(a)),-1!==["end","both"].indexOf(e.showticklabels)&&(a=n.tickText(e,o.value),i(a,{endAnchor:!1,xy:o.xy(o.crossLength-1),dxy:o.dxy(o.crossLength-2,1),axis:o.axis,length:o.crossAxis.length,font:o.axis.tickfont,isFirst:0===r,isLast:r===l.length-1}),s.push(a))}},{"../../lib/extend":493,"../../plots/cartesian/axes":554}],699:[function(t,e,r){"use strict";e.exports=function(t,e,r,n){var i=t[0]-e[0],a=t[1]-e[1],o=r[0]-e[0],s=r[1]-e[1],l=Math.pow(i*i+a*a,.25),c=Math.pow(o*o+s*s,.25),u=(c*c*i-l*l*o)*n,f=(c*c*a-l*l*s)*n,h=c*(l+c)*3,p=l*(l+c)*3;return[[e[0]+(h&&u/h),e[1]+(h&&f/h)],[e[0]-(p&&u/p),e[1]-(p&&f/p)]]}},{}],700:[function(t,e,r){"use strict";var n=t("../../lib").isArrayOrTypedArray;e.exports=function(t,e,r){var i,a,o,s,l,c,u=[],f=n(t)?t.length:t,h=n(e)?e.length:e,p=n(t)?t:null,d=n(e)?e:null;p&&(o=(p.length-1)/(p[p.length-1]-p[0])/(f-1)),d&&(s=(d.length-1)/(d[d.length-1]-d[0])/(h-1));var m=1/0,g=-1/0;for(a=0;a<h;a++)for(u[a]=[],l=d?(d[a]-d[0])*s:a/(h-1),i=0;i<f;i++)c=(p?(p[i]-p[0])*o:i/(f-1))-l*r,m=Math.min(c,m),g=Math.max(c,g),u[a][i]=c;var v=1/(g-m),y=-m*v;for(a=0;a<h;a++)for(i=0;i<f;i++)u[a][i]=v*u[a][i]+y;return u}},{"../../lib":503}],701:[function(t,e,r){"use strict";var n=t("./catmull_rom"),i=t("../../lib").ensureArray;function a(t,e,r){var n=-.5*r[0]+1.5*e[0],i=-.5*r[1]+1.5*e[1];return[(2*n+t[0])/3,(2*i+t[1])/3]}e.exports=function(t,e,r,o,s,l){var c,u,f,h,p,d,m,g,v,y,x=r[0].length,b=r.length,_=s?3*x-2:x,w=l?3*b-2:b;for(t=i(t,w),e=i(e,w),f=0;f<w;f++)t[f]=i(t[f],_),e[f]=i(e[f],_);for(u=0,h=0;u<b;u++,h+=l?3:1)for(p=t[h],d=e[h],m=r[u],g=o[u],c=0,f=0;c<x;c++,f+=s?3:1)p[f]=m[c],d[f]=g[c];if(s)for(u=0,h=0;u<b;u++,h+=l?3:1){for(c=1,f=3;c<x-1;c++,f+=3)v=n([r[u][c-1],o[u][c-1]],[r[u][c],o[u][c]],[r[u][c+1],o[u][c+1]],s),t[h][f-1]=v[0][0],e[h][f-1]=v[0][1],t[h][f+1]=v[1][0],e[h][f+1]=v[1][1];y=a([t[h][0],e[h][0]],[t[h][2],e[h][2]],[t[h][3],e[h][3]]),t[h][1]=y[0],e[h][1]=y[1],y=a([t[h][_-1],e[h][_-1]],[t[h][_-3],e[h][_-3]],[t[h][_-4],e[h][_-4]]),t[h][_-2]=y[0],e[h][_-2]=y[1]}if(l)for(f=0;f<_;f++){for(h=3;h<w-3;h+=3)v=n([t[h-3][f],e[h-3][f]],[t[h][f],e[h][f]],[t[h+3][f],e[h+3][f]],l),t[h-1][f]=v[0][0],e[h-1][f]=v[0][1],t[h+1][f]=v[1][0],e[h+1][f]=v[1][1];y=a([t[0][f],e[0][f]],[t[2][f],e[2][f]],[t[3][f],e[3][f]]),t[1][f]=y[0],e[1][f]=y[1],y=a([t[w-1][f],e[w-1][f]],[t[w-3][f],e[w-3][f]],[t[w-4][f],e[w-4][f]]),t[w-2][f]=y[0],e[w-2][f]=y[1]}if(s&&l)for(h=1;h<w;h+=(h+1)%3==0?2:1){for(f=3;f<_-3;f+=3)v=n([t[h][f-3],e[h][f-3]],[t[h][f],e[h][f]],[t[h][f+3],e[h][f+3]],s),t[h][f-1]=.5*(t[h][f-1]+v[0][0]),e[h][f-1]=.5*(e[h][f-1]+v[0][1]),t[h][f+1]=.5*(t[h][f+1]+v[1][0]),e[h][f+1]=.5*(e[h][f+1]+v[1][1]);y=a([t[h][0],e[h][0]],[t[h][2],e[h][2]],[t[h][3],e[h][3]]),t[h][1]=.5*(t[h][1]+y[0]),e[h][1]=.5*(e[h][1]+y[1]),y=a([t[h][_-1],e[h][_-1]],[t[h][_-3],e[h][_-3]],[t[h][_-4],e[h][_-4]]),t[h][_-2]=.5*(t[h][_-2]+y[0]),e[h][_-2]=.5*(e[h][_-2]+y[1])}return[t,e]}},{"../../lib":503,"./catmull_rom":699}],702:[function(t,e,r){"use strict";e.exports={RELATIVE_CULL_TOLERANCE:1e-6}},{}],703:[function(t,e,r){"use strict";e.exports=function(t,e,r){return e&&r?function(e,r,n,i,a){var o,s,l,c,u,f;e||(e=[]),r*=3,n*=3;var h=i*i,p=1-i,d=p*p,m=p*i*2,g=-3*d,v=3*(d-m),y=3*(m-h),x=3*h,b=a*a,_=b*a,w=1-a,T=w*w,k=T*w;for(f=0;f<t.length;f++)o=g*(u=t[f])[n][r]+v*u[n][r+1]+y*u[n][r+2]+x*u[n][r+3],s=g*u[n+1][r]+v*u[n+1][r+1]+y*u[n+1][r+2]+x*u[n+1][r+3],l=g*u[n+2][r]+v*u[n+2][r+1]+y*u[n+2][r+2]+x*u[n+2][r+3],c=g*u[n+3][r]+v*u[n+3][r+1]+y*u[n+3][r+2]+x*u[n+3][r+3],e[f]=k*o+3*(T*a*s+w*b*l)+_*c;return e}:e?function(e,r,n,i,a){var o,s,l,c;e||(e=[]),r*=3;var u=i*i,f=1-i,h=f*f,p=f*i*2,d=-3*h,m=3*(h-p),g=3*(p-u),v=3*u,y=1-a;for(l=0;l<t.length;l++)o=d*(c=t[l])[n][r]+m*c[n][r+1]+g*c[n][r+2]+v*c[n][r+3],s=d*c[n+1][r]+m*c[n+1][r+1]+g*c[n+1][r+2]+v*c[n+1][r+3],e[l]=y*o+a*s;return e}:r?function(e,r,n,i,a){var o,s,l,c,u,f;e||(e=[]),n*=3;var h=a*a,p=h*a,d=1-a,m=d*d,g=m*d;for(u=0;u<t.length;u++)o=(f=t[u])[n][r+1]-f[n][r],s=f[n+1][r+1]-f[n+1][r],l=f[n+2][r+1]-f[n+2][r],c=f[n+3][r+1]-f[n+3][r],e[u]=g*o+3*(m*a*s+d*h*l)+p*c;return e}:function(e,r,n,i,a){var o,s,l,c;e||(e=[]);var u=1-a;for(l=0;l<t.length;l++)o=(c=t[l])[n][r+1]-c[n][r],s=c[n+1][r+1]-c[n+1][r],e[l]=u*o+a*s;return e}}},{}],704:[function(t,e,r){"use strict";e.exports=function(t,e,r){return e&&r?function(e,r,n,i,a){var o,s,l,c,u,f;e||(e=[]),r*=3,n*=3;var h=i*i,p=h*i,d=1-i,m=d*d,g=m*d,v=a*a,y=1-a,x=y*y,b=y*a*2,_=-3*x,w=3*(x-b),T=3*(b-v),k=3*v;for(f=0;f<t.length;f++)o=_*(u=t[f])[n][r]+w*u[n+1][r]+T*u[n+2][r]+k*u[n+3][r],s=_*u[n][r+1]+w*u[n+1][r+1]+T*u[n+2][r+1]+k*u[n+3][r+1],l=_*u[n][r+2]+w*u[n+1][r+2]+T*u[n+2][r+2]+k*u[n+3][r+2],c=_*u[n][r+3]+w*u[n+1][r+3]+T*u[n+2][r+3]+k*u[n+3][r+3],e[f]=g*o+3*(m*i*s+d*h*l)+p*c;return e}:e?function(e,r,n,i,a){var o,s,l,c,u,f;e||(e=[]),r*=3;var h=a*a,p=h*a,d=1-a,m=d*d,g=m*d;for(u=0;u<t.length;u++)o=(f=t[u])[n+1][r]-f[n][r],s=f[n+1][r+1]-f[n][r+1],l=f[n+1][r+2]-f[n][r+2],c=f[n+1][r+3]-f[n][r+3],e[u]=g*o+3*(m*a*s+d*h*l)+p*c;return e}:r?function(e,r,n,i,a){var o,s,l,c;e||(e=[]),n*=3;var u=1-i,f=a*a,h=1-a,p=h*h,d=h*a*2,m=-3*p,g=3*(p-d),v=3*(d-f),y=3*f;for(l=0;l<t.length;l++)o=m*(c=t[l])[n][r]+g*c[n+1][r]+v*c[n+2][r]+y*c[n+3][r],s=m*c[n][r+1]+g*c[n+1][r+1]+v*c[n+2][r+1]+y*c[n+3][r+1],e[l]=u*o+i*s;return e}:function(e,r,n,i,a){var o,s,l,c;e||(e=[]);var u=1-i;for(l=0;l<t.length;l++)o=(c=t[l])[n+1][r]-c[n][r],s=c[n+1][r+1]-c[n][r+1],e[l]=u*o+i*s;return e}}},{}],705:[function(t,e,r){"use strict";e.exports=function(t,e,r,n,i){var a=e-2,o=r-2;return n&&i?function(e,r,n){var i,s,l,c,u,f;e||(e=[]);var h=Math.max(0,Math.min(Math.floor(r),a)),p=Math.max(0,Math.min(Math.floor(n),o)),d=Math.max(0,Math.min(1,r-h)),m=Math.max(0,Math.min(1,n-p));h*=3,p*=3;var g=d*d,v=g*d,y=1-d,x=y*y,b=x*y,_=m*m,w=_*m,T=1-m,k=T*T,A=k*T;for(f=0;f<t.length;f++)i=b*(u=t[f])[p][h]+3*(x*d*u[p][h+1]+y*g*u[p][h+2])+v*u[p][h+3],s=b*u[p+1][h]+3*(x*d*u[p+1][h+1]+y*g*u[p+1][h+2])+v*u[p+1][h+3],l=b*u[p+2][h]+3*(x*d*u[p+2][h+1]+y*g*u[p+2][h+2])+v*u[p+2][h+3],c=b*u[p+3][h]+3*(x*d*u[p+3][h+1]+y*g*u[p+3][h+2])+v*u[p+3][h+3],e[f]=A*i+3*(k*m*s+T*_*l)+w*c;return e}:n?function(e,r,n){e||(e=[]);var i,s,l,c,u,f,h=Math.max(0,Math.min(Math.floor(r),a)),p=Math.max(0,Math.min(Math.floor(n),o)),d=Math.max(0,Math.min(1,r-h)),m=Math.max(0,Math.min(1,n-p));h*=3;var g=d*d,v=g*d,y=1-d,x=y*y,b=x*y,_=1-m;for(u=0;u<t.length;u++)i=_*(f=t[u])[p][h]+m*f[p+1][h],s=_*f[p][h+1]+m*f[p+1][h+1],l=_*f[p][h+2]+m*f[p+1][h+1],c=_*f[p][h+3]+m*f[p+1][h+1],e[u]=b*i+3*(x*d*s+y*g*l)+v*c;return e}:i?function(e,r,n){e||(e=[]);var i,s,l,c,u,f,h=Math.max(0,Math.min(Math.floor(r),a)),p=Math.max(0,Math.min(Math.floor(n),o)),d=Math.max(0,Math.min(1,r-h)),m=Math.max(0,Math.min(1,n-p));p*=3;var g=m*m,v=g*m,y=1-m,x=y*y,b=x*y,_=1-d;for(u=0;u<t.length;u++)i=_*(f=t[u])[p][h]+d*f[p][h+1],s=_*f[p+1][h]+d*f[p+1][h+1],l=_*f[p+2][h]+d*f[p+2][h+1],c=_*f[p+3][h]+d*f[p+3][h+1],e[u]=b*i+3*(x*m*s+y*g*l)+v*c;return e}:function(e,r,n){e||(e=[]);var i,s,l,c,u=Math.max(0,Math.min(Math.floor(r),a)),f=Math.max(0,Math.min(Math.floor(n),o)),h=Math.max(0,Math.min(1,r-u)),p=Math.max(0,Math.min(1,n-f)),d=1-p,m=1-h;for(l=0;l<t.length;l++)i=m*(c=t[l])[f][u]+h*c[f][u+1],s=m*c[f+1][u]+h*c[f+1][u+1],e[l]=d*i+p*s;return e}}},{}],706:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./xy_defaults"),a=t("./ab_defaults"),o=t("./attributes"),s=t("../../components/color/attributes");e.exports=function(t,e,r,l){function c(r,i){return n.coerce(t,e,o,r,i)}e._clipPathId="clip"+e.uid+"carpet";var u=c("color",s.defaultLine);(n.coerceFont(c,"font"),c("carpet"),a(t,e,l,c,u),e.a&&e.b)?(e.a.length<3&&(e.aaxis.smoothing=0),e.b.length<3&&(e.baxis.smoothing=0),i(t,e,c)||(e.visible=!1),e._cheater&&c("cheaterslope")):e.visible=!1}},{"../../components/color/attributes":365,"../../lib":503,"./ab_defaults":689,"./attributes":691,"./xy_defaults":715}],707:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),plot:t("./plot"),calc:t("./calc"),animatable:!0,isContainer:!0,moduleType:"trace",name:"carpet",basePlotModule:t("../../plots/cartesian"),categories:["cartesian","svg","carpet","carpetAxis","notLegendIsolatable","noMultiCategory","noHover","noSortingByValue"],meta:{}}},{"../../plots/cartesian":568,"./attributes":691,"./calc":695,"./defaults":706,"./plot":712}],708:[function(t,e,r){"use strict";e.exports=function(t,e){for(var r,n=t._fullData.length,i=0;i<n;i++){var a=t._fullData[i];if(a.index!==e.index&&("carpet"===a.type&&(r||(r=a),a.carpet===e.carpet)))return a}return r}},{}],709:[function(t,e,r){"use strict";e.exports=function(t,e,r){if(0===t.length)return"";var n,i=[],a=r?3:1;for(n=0;n<t.length;n+=a)i.push(t[n]+","+e[n]),r&&n<t.length-a&&(i.push("C"),i.push([t[n+1]+","+e[n+1],t[n+2]+","+e[n+2]+" "].join(" ")));return i.join(r?"":"L")}},{}],710:[function(t,e,r){"use strict";var n=t("../../lib").isArrayOrTypedArray;e.exports=function(t,e,r){var i;for(n(t)?t.length>e.length&&(t=t.slice(0,e.length)):t=[],i=0;i<e.length;i++)t[i]=r(e[i]);return t}},{"../../lib":503}],711:[function(t,e,r){"use strict";e.exports=function(t,e,r,n,i,a){var o=i[0]*t.dpdx(e),s=i[1]*t.dpdy(r),l=1,c=1;if(a){var u=Math.sqrt(i[0]*i[0]+i[1]*i[1]),f=Math.sqrt(a[0]*a[0]+a[1]*a[1]),h=(i[0]*a[0]+i[1]*a[1])/u/f;c=Math.max(0,h)}var p=180*Math.atan2(s,o)/Math.PI;return p<-90?(p+=180,l=-l):p>90&&(p-=180,l=-l),{angle:p,flip:l,p:t.c2p(n,e,r),offsetMultplier:c}}},{}],712:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/drawing"),a=t("./map_1d_array"),o=t("./makepath"),s=t("./orient_text"),l=t("../../lib/svg_text_utils"),c=t("../../lib"),u=c.strRotate,f=c.strTranslate,h=t("../../constants/alignment");function p(t,e,r,s,l,c){var u="const-"+l+"-lines",f=r.selectAll("."+u).data(c);f.enter().append("path").classed(u,!0).style("vector-effect","non-scaling-stroke"),f.each((function(r){var s=r,l=s.x,c=s.y,u=a([],l,t.c2p),f=a([],c,e.c2p),h="M"+o(u,f,s.smoothing);n.select(this).attr("d",h).style("stroke-width",s.width).style("stroke",s.color).style("stroke-dasharray",i.dashStyle(s.dash,s.width)).style("fill","none")})),f.exit().remove()}function d(t,e,r,a,o,c,h,p){var d=c.selectAll("text."+p).data(h);d.enter().append("text").classed(p,!0);var m=0,g={};return d.each((function(o,c){var h;if("auto"===o.axis.tickangle)h=s(a,e,r,o.xy,o.dxy);else{var p=(o.axis.tickangle+180)*Math.PI/180;h=s(a,e,r,o.xy,[Math.cos(p),Math.sin(p)])}c||(g={angle:h.angle,flip:h.flip});var d=(o.endAnchor?-1:1)*h.flip,v=n.select(this).attr({"text-anchor":d>0?"start":"end","data-notex":1}).call(i.font,o.font).text(o.text).call(l.convertToTspans,t),y=i.bBox(this);v.attr("transform",f(h.p[0],h.p[1])+u(h.angle)+f(o.axis.labelpadding*d,.3*y.height)),m=Math.max(m,y.width+o.axis.labelpadding)})),d.exit().remove(),g.maxExtent=m,g}e.exports=function(t,e,r,i){var l=e.xaxis,u=e.yaxis,f=t._fullLayout._clips;c.makeTraceGroups(i,r,"trace").each((function(e){var r=n.select(this),i=e[0],h=i.trace,m=h.aaxis,g=h.baxis,y=c.ensureSingle(r,"g","minorlayer"),x=c.ensureSingle(r,"g","majorlayer"),b=c.ensureSingle(r,"g","boundarylayer"),_=c.ensureSingle(r,"g","labellayer");r.style("opacity",h.opacity),p(l,u,x,m,"a",m._gridlines),p(l,u,x,g,"b",g._gridlines),p(l,u,y,m,"a",m._minorgridlines),p(l,u,y,g,"b",g._minorgridlines),p(l,u,b,m,"a-boundary",m._boundarylines),p(l,u,b,g,"b-boundary",g._boundarylines);var w=d(t,l,u,h,i,_,m._labels,"a-label"),T=d(t,l,u,h,i,_,g._labels,"b-label");!function(t,e,r,n,i,a,o,l){var u,f,h,p,d=c.aggNums(Math.min,null,r.a),m=c.aggNums(Math.max,null,r.a),g=c.aggNums(Math.min,null,r.b),y=c.aggNums(Math.max,null,r.b);u=.5*(d+m),f=g,h=r.ab2xy(u,f,!0),p=r.dxyda_rough(u,f),void 0===o.angle&&c.extendFlat(o,s(r,i,a,h,r.dxydb_rough(u,f)));v(t,e,r,n,h,p,r.aaxis,i,a,o,"a-title"),u=d,f=.5*(g+y),h=r.ab2xy(u,f,!0),p=r.dxydb_rough(u,f),void 0===l.angle&&c.extendFlat(l,s(r,i,a,h,r.dxyda_rough(u,f)));v(t,e,r,n,h,p,r.baxis,i,a,l,"b-title")}(t,_,h,i,l,u,w,T),function(t,e,r,n,i){var s,l,u,f,h=r.select("#"+t._clipPathId);h.size()||(h=r.append("clipPath").classed("carpetclip",!0));var p=c.ensureSingle(h,"path","carpetboundary"),d=e.clipsegments,m=[];for(f=0;f<d.length;f++)s=d[f],l=a([],s.x,n.c2p),u=a([],s.y,i.c2p),m.push(o(l,u,s.bicubic));var g="M"+m.join("L")+"Z";h.attr("id",t._clipPathId),p.attr("d",g)}(h,i,f,l,u)}))};var m=h.LINE_SPACING,g=(1-h.MID_SHIFT)/m+1;function v(t,e,r,a,o,c,h,p,d,v,y){var x=[];h.title.text&&x.push(h.title.text);var b=e.selectAll("text."+y).data(x),_=v.maxExtent;b.enter().append("text").classed(y,!0),b.each((function(){var e=s(r,p,d,o,c);-1===["start","both"].indexOf(h.showticklabels)&&(_=0);var a=h.title.font.size;_+=a+h.title.offset;var y=(v.angle+(v.flip<0?180:0)-e.angle+450)%360,x=y>90&&y<270,b=n.select(this);b.text(h.title.text).call(l.convertToTspans,t),x&&(_=(-l.lineCount(b)+g)*m*a-_),b.attr("transform",f(e.p[0],e.p[1])+u(e.angle)+f(0,_)).attr("text-anchor","middle").call(i.font,h.title.font)})),b.exit().remove()}},{"../../components/drawing":388,"../../constants/alignment":471,"../../lib":503,"../../lib/svg_text_utils":529,"./makepath":709,"./map_1d_array":710,"./orient_text":711,"@plotly/d3":58}],713:[function(t,e,r){"use strict";var n=t("./constants"),i=t("../../lib/search").findBin,a=t("./compute_control_points"),o=t("./create_spline_evaluator"),s=t("./create_i_derivative_evaluator"),l=t("./create_j_derivative_evaluator");e.exports=function(t){var e=t._a,r=t._b,c=e.length,u=r.length,f=t.aaxis,h=t.baxis,p=e[0],d=e[c-1],m=r[0],g=r[u-1],v=e[e.length-1]-e[0],y=r[r.length-1]-r[0],x=v*n.RELATIVE_CULL_TOLERANCE,b=y*n.RELATIVE_CULL_TOLERANCE;p-=x,d+=x,m-=b,g+=b,t.isVisible=function(t,e){return t>p&&t<d&&e>m&&e<g},t.isOccluded=function(t,e){return t<p||t>d||e<m||e>g},t.setScale=function(){var e=t._x,r=t._y,n=a(t._xctrl,t._yctrl,e,r,f.smoothing,h.smoothing);t._xctrl=n[0],t._yctrl=n[1],t.evalxy=o([t._xctrl,t._yctrl],c,u,f.smoothing,h.smoothing),t.dxydi=s([t._xctrl,t._yctrl],f.smoothing,h.smoothing),t.dxydj=l([t._xctrl,t._yctrl],f.smoothing,h.smoothing)},t.i2a=function(t){var r=Math.max(0,Math.floor(t[0]),c-2),n=t[0]-r;return(1-n)*e[r]+n*e[r+1]},t.j2b=function(t){var e=Math.max(0,Math.floor(t[1]),c-2),n=t[1]-e;return(1-n)*r[e]+n*r[e+1]},t.ij2ab=function(e){return[t.i2a(e[0]),t.j2b(e[1])]},t.a2i=function(t){var r=Math.max(0,Math.min(i(t,e),c-2)),n=e[r],a=e[r+1];return Math.max(0,Math.min(c-1,r+(t-n)/(a-n)))},t.b2j=function(t){var e=Math.max(0,Math.min(i(t,r),u-2)),n=r[e],a=r[e+1];return Math.max(0,Math.min(u-1,e+(t-n)/(a-n)))},t.ab2ij=function(e){return[t.a2i(e[0]),t.b2j(e[1])]},t.i2c=function(e,r){return t.evalxy([],e,r)},t.ab2xy=function(n,i,a){if(!a&&(n<e[0]||n>e[c-1]|i<r[0]||i>r[u-1]))return[!1,!1];var o=t.a2i(n),s=t.b2j(i),l=t.evalxy([],o,s);if(a){var f,h,p,d,m=0,g=0,v=[];n<e[0]?(f=0,h=0,m=(n-e[0])/(e[1]-e[0])):n>e[c-1]?(f=c-2,h=1,m=(n-e[c-1])/(e[c-1]-e[c-2])):h=o-(f=Math.max(0,Math.min(c-2,Math.floor(o)))),i<r[0]?(p=0,d=0,g=(i-r[0])/(r[1]-r[0])):i>r[u-1]?(p=u-2,d=1,g=(i-r[u-1])/(r[u-1]-r[u-2])):d=s-(p=Math.max(0,Math.min(u-2,Math.floor(s)))),m&&(t.dxydi(v,f,p,h,d),l[0]+=v[0]*m,l[1]+=v[1]*m),g&&(t.dxydj(v,f,p,h,d),l[0]+=v[0]*g,l[1]+=v[1]*g)}return l},t.c2p=function(t,e,r){return[e.c2p(t[0]),r.c2p(t[1])]},t.p2x=function(t,e,r){return[e.p2c(t[0]),r.p2c(t[1])]},t.dadi=function(t){var r=Math.max(0,Math.min(e.length-2,t));return e[r+1]-e[r]},t.dbdj=function(t){var e=Math.max(0,Math.min(r.length-2,t));return r[e+1]-r[e]},t.dxyda=function(e,r,n,i){var a=t.dxydi(null,e,r,n,i),o=t.dadi(e,n);return[a[0]/o,a[1]/o]},t.dxydb=function(e,r,n,i){var a=t.dxydj(null,e,r,n,i),o=t.dbdj(r,i);return[a[0]/o,a[1]/o]},t.dxyda_rough=function(e,r,n){var i=v*(n||.1),a=t.ab2xy(e+i,r,!0),o=t.ab2xy(e-i,r,!0);return[.5*(a[0]-o[0])/i,.5*(a[1]-o[1])/i]},t.dxydb_rough=function(e,r,n){var i=y*(n||.1),a=t.ab2xy(e,r+i,!0),o=t.ab2xy(e,r-i,!0);return[.5*(a[0]-o[0])/i,.5*(a[1]-o[1])/i]},t.dpdx=function(t){return t._m},t.dpdy=function(t){return t._m}}},{"../../lib/search":523,"./compute_control_points":701,"./constants":702,"./create_i_derivative_evaluator":703,"./create_j_derivative_evaluator":704,"./create_spline_evaluator":705}],714:[function(t,e,r){"use strict";var n=t("../../lib");e.exports=function(t,e,r){var i,a,o,s=[],l=[],c=t[0].length,u=t.length;function f(e,r){var n,i=0,a=0;return e>0&&void 0!==(n=t[r][e-1])&&(a++,i+=n),e<c-1&&void 0!==(n=t[r][e+1])&&(a++,i+=n),r>0&&void 0!==(n=t[r-1][e])&&(a++,i+=n),r<u-1&&void 0!==(n=t[r+1][e])&&(a++,i+=n),i/Math.max(1,a)}var h,p,d,m,g,v,y,x,b,_,w,T=0;for(i=0;i<c;i++)for(a=0;a<u;a++)void 0===t[a][i]&&(s.push(i),l.push(a),t[a][i]=f(i,a)),T=Math.max(T,Math.abs(t[a][i]));if(!s.length)return t;var k=0,A=0,M=s.length;do{for(k=0,o=0;o<M;o++){i=s[o],a=l[o];var S,E,L,C,P,I,O=0,z=0;0===i?(L=e[P=Math.min(c-1,2)],C=e[1],S=t[a][P],z+=(E=t[a][1])+(E-S)*(e[0]-C)/(C-L),O++):i===c-1&&(L=e[P=Math.max(0,c-3)],C=e[c-2],S=t[a][P],z+=(E=t[a][c-2])+(E-S)*(e[c-1]-C)/(C-L),O++),(0===i||i===c-1)&&a>0&&a<u-1&&(h=r[a+1]-r[a],z+=((p=r[a]-r[a-1])*t[a+1][i]+h*t[a-1][i])/(p+h),O++),0===a?(L=r[I=Math.min(u-1,2)],C=r[1],S=t[I][i],z+=(E=t[1][i])+(E-S)*(r[0]-C)/(C-L),O++):a===u-1&&(L=r[I=Math.max(0,u-3)],C=r[u-2],S=t[I][i],z+=(E=t[u-2][i])+(E-S)*(r[u-1]-C)/(C-L),O++),(0===a||a===u-1)&&i>0&&i<c-1&&(h=e[i+1]-e[i],z+=((p=e[i]-e[i-1])*t[a][i+1]+h*t[a][i-1])/(p+h),O++),O?z/=O:(d=e[i+1]-e[i],m=e[i]-e[i-1],x=(g=r[a+1]-r[a])*(v=r[a]-r[a-1])*(g+v),z=((y=d*m*(d+m))*(v*t[a+1][i]+g*t[a-1][i])+x*(m*t[a][i+1]+d*t[a][i-1]))/(x*(m+d)+y*(v+g))),k+=(_=(b=z-t[a][i])/T)*_,w=O?0:.85,t[a][i]+=b*(1+w)}k=Math.sqrt(k)}while(A++<100&&k>1e-5);return n.log("Smoother converged to",k,"after",A,"iterations"),t}},{"../../lib":503}],715:[function(t,e,r){"use strict";var n=t("../../lib").isArray1D;e.exports=function(t,e,r){var i=r("x"),a=i&&i.length,o=r("y"),s=o&&o.length;if(!a&&!s)return!1;if(e._cheater=!i,a&&!n(i)||s&&!n(o))e._length=null;else{var l=a?i.length:1/0;s&&(l=Math.min(l,o.length)),e.a&&e.a.length&&(l=Math.min(l,e.a.length)),e.b&&e.b.length&&(l=Math.min(l,e.b.length)),e._length=l}return!0}},{"../../lib":503}],716:[function(t,e,r){"use strict";var n=t("../../plots/template_attributes").hovertemplateAttrs,i=t("../scattergeo/attributes"),a=t("../../components/colorscale/attributes"),o=t("../../plots/attributes"),s=t("../../components/color/attributes").defaultLine,l=t("../../lib/extend").extendFlat,c=i.marker.line;e.exports=l({locations:{valType:"data_array",editType:"calc"},locationmode:i.locationmode,z:{valType:"data_array",editType:"calc"},geojson:l({},i.geojson,{}),featureidkey:i.featureidkey,text:l({},i.text,{}),hovertext:l({},i.hovertext,{}),marker:{line:{color:l({},c.color,{dflt:s}),width:l({},c.width,{dflt:1}),editType:"calc"},opacity:{valType:"number",arrayOk:!0,min:0,max:1,dflt:1,editType:"style"},editType:"calc"},selected:{marker:{opacity:i.selected.marker.opacity,editType:"plot"},editType:"plot"},unselected:{marker:{opacity:i.unselected.marker.opacity,editType:"plot"},editType:"plot"},hoverinfo:l({},o.hoverinfo,{editType:"calc",flags:["location","z","text","name"]}),hovertemplate:n(),showlegend:l({},o.showlegend,{dflt:!1})},a("",{cLetter:"z",editTypeOverride:"calc"}))},{"../../components/color/attributes":365,"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/template_attributes":633,"../scattergeo/attributes":969}],717:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../constants/numerical").BADNUM,a=t("../../components/colorscale/calc"),o=t("../scatter/arrays_to_calcdata"),s=t("../scatter/calc_selection");function l(t){return t&&"string"==typeof t}e.exports=function(t,e){var r,c=e._length,u=new Array(c);r=e.geojson?function(t){return l(t)||n(t)}:l;for(var f=0;f<c;f++){var h=u[f]={},p=e.locations[f],d=e.z[f];r(p)&&n(d)?(h.loc=p,h.z=d):(h.loc=null,h.z=i),h.index=f}return o(u,e),a(t,e,{vals:e.z,containerStr:"",cLetter:"z"}),s(u,e),u}},{"../../components/colorscale/calc":374,"../../constants/numerical":479,"../scatter/arrays_to_calcdata":926,"../scatter/calc_selection":929,"fast-isnumeric":190}],718:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/colorscale/defaults"),a=t("./attributes");e.exports=function(t,e,r,o){function s(r,i){return n.coerce(t,e,a,r,i)}var l=s("locations"),c=s("z");if(l&&l.length&&n.isArrayOrTypedArray(c)&&c.length){e._length=Math.min(l.length,c.length);var u,f=s("geojson");("string"==typeof f&&""!==f||n.isPlainObject(f))&&(u="geojson-id"),"geojson-id"===s("locationmode",u)&&s("featureidkey"),s("text"),s("hovertext"),s("hovertemplate"),s("marker.line.width")&&s("marker.line.color"),s("marker.opacity"),i(t,e,o,s,{prefix:"",cLetter:"z"}),n.coerceSelectionMarkerOpacity(e,s)}else e.visible=!1}},{"../../components/colorscale/defaults":376,"../../lib":503,"./attributes":716}],719:[function(t,e,r){"use strict";e.exports=function(t,e,r,n,i){t.location=e.location,t.z=e.z;var a=n[i];return a.fIn&&a.fIn.properties&&(t.properties=a.fIn.properties),t.ct=a.ct,t}},{}],720:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes"),i=t("./attributes"),a=t("../../lib").fillText;e.exports=function(t,e,r){var o,s,l,c,u=t.cd,f=u[0].trace,h=t.subplot,p=[e,r],d=[e+360,r];for(s=0;s<u.length;s++)if(c=!1,(o=u[s])._polygons){for(l=0;l<o._polygons.length;l++)o._polygons[l].contains(p)&&(c=!c),o._polygons[l].contains(d)&&(c=!c);if(c)break}if(c&&o)return t.x0=t.x1=t.xa.c2p(o.ct),t.y0=t.y1=t.ya.c2p(o.ct),t.index=o.index,t.location=o.loc,t.z=o.z,t.zLabel=n.tickText(h.mockAxis,h.mockAxis.c2l(o.z),"hover").text,t.hovertemplate=o.hovertemplate,function(t,e,r){if(e.hovertemplate)return;var n=r.hi||e.hoverinfo,o=String(r.loc),s="all"===n?i.hoverinfo.flags:n.split("+"),l=-1!==s.indexOf("name"),c=-1!==s.indexOf("location"),u=-1!==s.indexOf("z"),f=-1!==s.indexOf("text"),h=[];!l&&c?t.nameOverride=o:(l&&(t.nameOverride=e.name),c&&h.push(o));u&&h.push(t.zLabel);f&&a(r,e,h);t.extraText=h.join("<br>")}(t,f,o),[t]}},{"../../lib":503,"../../plots/cartesian/axes":554,"./attributes":716}],721:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:t("../heatmap/colorbar"),calc:t("./calc"),calcGeoJSON:t("./plot").calcGeoJSON,plot:t("./plot").plot,style:t("./style").style,styleOnSelect:t("./style").styleOnSelect,hoverPoints:t("./hover"),eventData:t("./event_data"),selectPoints:t("./select"),moduleType:"trace",name:"choropleth",basePlotModule:t("../../plots/geo"),categories:["geo","noOpacity","showLegend"],meta:{}}},{"../../plots/geo":589,"../heatmap/colorbar":795,"./attributes":716,"./calc":717,"./defaults":718,"./event_data":719,"./hover":720,"./plot":722,"./select":723,"./style":724}],722:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../../lib/geo_location_utils"),o=t("../../lib/topojson_utils").getTopojsonFeatures,s=t("../../plots/cartesian/autorange").findExtremes,l=t("./style").style;e.exports={calcGeoJSON:function(t,e){for(var r=t[0].trace,n=e[r.geo],i=n._subplot,l=r.locationmode,c=r._length,u="geojson-id"===l?a.extractTraceFeature(t):o(r,i.topojson),f=[],h=[],p=0;p<c;p++){var d=t[p],m="geojson-id"===l?d.fOut:a.locationToFeature(l,d.loc,u);if(m){d.geojson=m,d.ct=m.properties.ct,d._polygons=a.feature2polygons(m);var g=a.computeBbox(m);f.push(g[0],g[2]),h.push(g[1],g[3])}else d.geojson=null}if("geojson"===n.fitbounds&&"geojson-id"===l){var v=a.computeBbox(a.getTraceGeojson(r));f=[v[0],v[2]],h=[v[1],v[3]]}var y={padded:!0};r._extremes.lon=s(n.lonaxis._ax,f,y),r._extremes.lat=s(n.lataxis._ax,h,y)},plot:function(t,e,r){var a=e.layers.backplot.select(".choroplethlayer");i.makeTraceGroups(a,r,"trace choropleth").each((function(e){var r=n.select(this).selectAll("path.choroplethlocation").data(i.identity);r.enter().append("path").classed("choroplethlocation",!0),r.exit().remove(),l(t,e)}))}}},{"../../lib":503,"../../lib/geo_location_utils":496,"../../lib/topojson_utils":532,"../../plots/cartesian/autorange":553,"./style":724,"@plotly/d3":58}],723:[function(t,e,r){"use strict";e.exports=function(t,e){var r,n,i,a,o,s=t.cd,l=t.xaxis,c=t.yaxis,u=[];if(!1===e)for(r=0;r<s.length;r++)s[r].selected=0;else for(r=0;r<s.length;r++)(i=(n=s[r]).ct)&&(a=l.c2p(i),o=c.c2p(i),e.contains([a,o],null,r,t)?(u.push({pointNumber:r,lon:i[0],lat:i[1]}),n.selected=1):n.selected=0);return u}},{}],724:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/color"),a=t("../../components/drawing"),o=t("../../components/colorscale");function s(t,e){var r=e[0].trace,s=e[0].node3.selectAll(".choroplethlocation"),l=r.marker||{},c=l.line||{},u=o.makeColorScaleFuncFromTrace(r);s.each((function(t){n.select(this).attr("fill",u(t.z)).call(i.stroke,t.mlc||c.color).call(a.dashLine,"",t.mlw||c.width||0).style("opacity",l.opacity)})),a.selectedPointStyle(s,r,t)}e.exports={style:function(t,e){e&&s(t,e)},styleOnSelect:function(t,e){var r=e[0].node3,n=e[0].trace;n.selectedpoints?a.selectedPointStyle(r.selectAll(".choroplethlocation"),n,t):s(t,e)}}},{"../../components/color":366,"../../components/colorscale":378,"../../components/drawing":388,"@plotly/d3":58}],725:[function(t,e,r){"use strict";var n=t("../choropleth/attributes"),i=t("../../components/colorscale/attributes"),a=t("../../plots/template_attributes").hovertemplateAttrs,o=t("../../plots/attributes"),s=t("../../lib/extend").extendFlat;e.exports=s({locations:{valType:"data_array",editType:"calc"},z:{valType:"data_array",editType:"calc"},geojson:{valType:"any",editType:"calc"},featureidkey:s({},n.featureidkey,{}),below:{valType:"string",editType:"plot"},text:n.text,hovertext:n.hovertext,marker:{line:{color:s({},n.marker.line.color,{editType:"plot"}),width:s({},n.marker.line.width,{editType:"plot"}),editType:"calc"},opacity:s({},n.marker.opacity,{editType:"plot"}),editType:"calc"},selected:{marker:{opacity:s({},n.selected.marker.opacity,{editType:"plot"}),editType:"plot"},editType:"plot"},unselected:{marker:{opacity:s({},n.unselected.marker.opacity,{editType:"plot"}),editType:"plot"},editType:"plot"},hoverinfo:n.hoverinfo,hovertemplate:a({},{keys:["properties"]}),showlegend:s({},o.showlegend,{dflt:!1})},i("",{cLetter:"z",editTypeOverride:"calc"}))},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/template_attributes":633,"../choropleth/attributes":716}],726:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=t("../../components/colorscale"),o=t("../../components/drawing"),s=t("../../lib/geojson_utils").makeBlank,l=t("../../lib/geo_location_utils");function c(t){var e,r=t[0].trace,n=r._opts;if(r.selectedpoints){for(var a=o.makeSelectedPointStyleFns(r),s=0;s<t.length;s++){var l=t[s];l.fOut&&(l.fOut.properties.mo2=a.selectedOpacityFn(l))}e={type:"identity",property:"mo2"}}else e=i.isArrayOrTypedArray(r.marker.opacity)?{type:"identity",property:"mo"}:r.marker.opacity;return i.extendFlat(n.fill.paint,{"fill-opacity":e}),i.extendFlat(n.line.paint,{"line-opacity":e}),n}e.exports={convert:function(t){var e=t[0].trace,r=!0===e.visible&&0!==e._length,o={layout:{visibility:"none"},paint:{}},u={layout:{visibility:"none"},paint:{}},f=e._opts={fill:o,line:u,geojson:s()};if(!r)return f;var h=l.extractTraceFeature(t);if(!h)return f;var p,d,m,g=a.makeColorScaleFuncFromTrace(e),v=e.marker,y=v.line||{};i.isArrayOrTypedArray(v.opacity)&&(p=function(t){var e=t.mo;return n(e)?+i.constrain(e,0,1):0}),i.isArrayOrTypedArray(y.color)&&(d=function(t){return t.mlc}),i.isArrayOrTypedArray(y.width)&&(m=function(t){return t.mlw});for(var x=0;x<t.length;x++){var b=t[x],_=b.fOut;if(_){var w=_.properties;w.fc=g(b.z),p&&(w.mo=p(b)),d&&(w.mlc=d(b)),m&&(w.mlw=m(b)),b.ct=w.ct,b._polygons=l.feature2polygons(_)}}var T=p?{type:"identity",property:"mo"}:v.opacity;return i.extendFlat(o.paint,{"fill-color":{type:"identity",property:"fc"},"fill-opacity":T}),i.extendFlat(u.paint,{"line-color":d?{type:"identity",property:"mlc"}:y.color,"line-width":m?{type:"identity",property:"mlw"}:y.width,"line-opacity":T}),o.layout.visibility="visible",u.layout.visibility="visible",f.geojson={type:"FeatureCollection",features:h},c(t),f},convertOnSelect:c}},{"../../components/colorscale":378,"../../components/drawing":388,"../../lib":503,"../../lib/geo_location_utils":496,"../../lib/geojson_utils":497,"fast-isnumeric":190}],727:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/colorscale/defaults"),a=t("./attributes");e.exports=function(t,e,r,o){function s(r,i){return n.coerce(t,e,a,r,i)}var l=s("locations"),c=s("z"),u=s("geojson");n.isArrayOrTypedArray(l)&&l.length&&n.isArrayOrTypedArray(c)&&c.length&&("string"==typeof u&&""!==u||n.isPlainObject(u))?(s("featureidkey"),e._length=Math.min(l.length,c.length),s("below"),s("text"),s("hovertext"),s("hovertemplate"),s("marker.line.width")&&s("marker.line.color"),s("marker.opacity"),i(t,e,o,s,{prefix:"",cLetter:"z"}),n.coerceSelectionMarkerOpacity(e,s)):e.visible=!1}},{"../../components/colorscale/defaults":376,"../../lib":503,"./attributes":725}],728:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:t("../heatmap/colorbar"),calc:t("../choropleth/calc"),plot:t("./plot"),hoverPoints:t("../choropleth/hover"),eventData:t("../choropleth/event_data"),selectPoints:t("../choropleth/select"),styleOnSelect:function(t,e){e&&e[0].trace._glTrace.updateOnSelect(e)},getBelow:function(t,e){for(var r=e.getMapLayers(),n=r.length-2;n>=0;n--){var i=r[n].id;if("string"==typeof i&&0===i.indexOf("water"))for(var a=n+1;a<r.length;a++)if("string"==typeof(i=r[a].id)&&-1===i.indexOf("plotly-"))return i}},moduleType:"trace",name:"choroplethmapbox",basePlotModule:t("../../plots/mapbox"),categories:["mapbox","gl","noOpacity","showLegend"],meta:{hr_name:"choropleth_mapbox"}}},{"../../plots/mapbox":613,"../choropleth/calc":717,"../choropleth/event_data":719,"../choropleth/hover":720,"../choropleth/select":723,"../heatmap/colorbar":795,"./attributes":725,"./defaults":727,"./plot":729}],729:[function(t,e,r){"use strict";var n=t("./convert").convert,i=t("./convert").convertOnSelect,a=t("../../plots/mapbox/constants").traceLayerPrefix;function o(t,e){this.type="choroplethmapbox",this.subplot=t,this.uid=e,this.sourceId="source-"+e,this.layerList=[["fill",a+e+"-fill"],["line",a+e+"-line"]],this.below=null}var s=o.prototype;s.update=function(t){this._update(n(t))},s.updateOnSelect=function(t){this._update(i(t))},s._update=function(t){var e=this.subplot,r=this.layerList,n=e.belowLookup["trace-"+this.uid];e.map.getSource(this.sourceId).setData(t.geojson),n!==this.below&&(this._removeLayers(),this._addLayers(t,n),this.below=n);for(var i=0;i<r.length;i++){var a=r[i],o=a[0],s=a[1],l=t[o];e.setOptions(s,"setLayoutProperty",l.layout),"visible"===l.layout.visibility&&e.setOptions(s,"setPaintProperty",l.paint)}},s._addLayers=function(t,e){for(var r=this.subplot,n=this.layerList,i=this.sourceId,a=0;a<n.length;a++){var o=n[a],s=o[0],l=t[s];r.addLayer({type:s,id:o[1],source:i,layout:l.layout,paint:l.paint},e)}},s._removeLayers=function(){for(var t=this.subplot.map,e=this.layerList,r=e.length-1;r>=0;r--)t.removeLayer(e[r][1])},s.dispose=function(){var t=this.subplot.map;this._removeLayers(),t.removeSource(this.sourceId)},e.exports=function(t,e){var r=e[0].trace,i=new o(t,r.uid),a=i.sourceId,s=n(e),l=i.below=t.belowLookup["trace-"+r.uid];return t.map.addSource(a,{type:"geojson",data:s.geojson}),i._addLayers(s,l),e[0].trace._glTrace=i,i}},{"../../plots/mapbox/constants":611,"./convert":726}],730:[function(t,e,r){"use strict";var n=t("../../components/colorscale/attributes"),i=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,a=t("../../plots/template_attributes").hovertemplateAttrs,o=t("../mesh3d/attributes"),s=t("../../plots/attributes"),l=t("../../lib/extend").extendFlat,c={x:{valType:"data_array",editType:"calc+clearAxisTypes"},y:{valType:"data_array",editType:"calc+clearAxisTypes"},z:{valType:"data_array",editType:"calc+clearAxisTypes"},u:{valType:"data_array",editType:"calc"},v:{valType:"data_array",editType:"calc"},w:{valType:"data_array",editType:"calc"},sizemode:{valType:"enumerated",values:["scaled","absolute"],editType:"calc",dflt:"scaled"},sizeref:{valType:"number",editType:"calc",min:0},anchor:{valType:"enumerated",editType:"calc",values:["tip","tail","cm","center"],dflt:"cm"},text:{valType:"string",dflt:"",arrayOk:!0,editType:"calc"},hovertext:{valType:"string",dflt:"",arrayOk:!0,editType:"calc"},hovertemplate:a({editType:"calc"},{keys:["norm"]}),uhoverformat:i("u",1),vhoverformat:i("v",1),whoverformat:i("w",1),xhoverformat:i("x"),yhoverformat:i("y"),zhoverformat:i("z"),showlegend:l({},s.showlegend,{dflt:!1})};l(c,n("",{colorAttr:"u/v/w norm",showScaleDflt:!0,editTypeOverride:"calc"}));["opacity","lightposition","lighting"].forEach((function(t){c[t]=o[t]})),c.hoverinfo=l({},s.hoverinfo,{editType:"calc",flags:["x","y","z","u","v","w","norm","text","name"],dflt:"x+y+z+norm+text+name"}),c.transforms=void 0,e.exports=c},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/cartesian/axis_format_attributes":557,"../../plots/template_attributes":633,"../mesh3d/attributes":867}],731:[function(t,e,r){"use strict";var n=t("../../components/colorscale/calc");e.exports=function(t,e){for(var r=e.u,i=e.v,a=e.w,o=Math.min(e.x.length,e.y.length,e.z.length,r.length,i.length,a.length),s=-1/0,l=1/0,c=0;c<o;c++){var u=r[c],f=i[c],h=a[c],p=Math.sqrt(u*u+f*f+h*h);s=Math.max(s,p),l=Math.min(l,p)}e._len=o,e._normMax=s,n(t,e,{vals:[l,s],containerStr:"",cLetter:"c"})}},{"../../components/colorscale/calc":374}],732:[function(t,e,r){"use strict";var n=t("../../../stackgl_modules").gl_cone3d,i=t("../../../stackgl_modules").gl_cone3d.createConeMesh,a=t("../../lib").simpleMap,o=t("../../lib/gl_format_color").parseColorScale,s=t("../../components/colorscale").extractOpts,l=t("../../plots/gl3d/zip3");function c(t,e){this.scene=t,this.uid=e,this.mesh=null,this.data=null}var u=c.prototype;u.handlePick=function(t){if(t.object===this.mesh){var e=t.index=t.data.index,r=this.data.x[e],n=this.data.y[e],i=this.data.z[e],a=this.data.u[e],o=this.data.v[e],s=this.data.w[e];t.traceCoordinate=[r,n,i,a,o,s,Math.sqrt(a*a+o*o+s*s)];var l=this.data.hovertext||this.data.text;return Array.isArray(l)&&void 0!==l[e]?t.textLabel=l[e]:l&&(t.textLabel=l),!0}};var f={xaxis:0,yaxis:1,zaxis:2},h={tip:1,tail:0,cm:.25,center:.5},p={tip:1,tail:1,cm:.75,center:.5};function d(t,e){var r=t.fullSceneLayout,i=t.dataScale,c={};function u(t,e){var n=r[e],o=i[f[e]];return a(t,(function(t){return n.d2l(t)*o}))}c.vectors=l(u(e.u,"xaxis"),u(e.v,"yaxis"),u(e.w,"zaxis"),e._len),c.positions=l(u(e.x,"xaxis"),u(e.y,"yaxis"),u(e.z,"zaxis"),e._len);var d=s(e);c.colormap=o(e),c.vertexIntensityBounds=[d.min/e._normMax,d.max/e._normMax],c.coneOffset=h[e.anchor],"scaled"===e.sizemode?c.coneSize=e.sizeref||.5:c.coneSize=e.sizeref&&e._normMax?e.sizeref/e._normMax:.5;var m=n(c),g=e.lightposition;return m.lightPosition=[g.x,g.y,g.z],m.ambient=e.lighting.ambient,m.diffuse=e.lighting.diffuse,m.specular=e.lighting.specular,m.roughness=e.lighting.roughness,m.fresnel=e.lighting.fresnel,m.opacity=e.opacity,e._pad=p[e.anchor]*m.vectorScale*m.coneScale*e._normMax,m}u.update=function(t){this.data=t;var e=d(this.scene,t);this.mesh.update(e)},u.dispose=function(){this.scene.glplot.remove(this.mesh),this.mesh.dispose()},e.exports=function(t,e){var r=t.glplot.gl,n=d(t,e),a=i(r,n),o=new c(t,e.uid);return o.mesh=a,o.data=e,a._trace=o,t.glplot.add(a),o}},{"../../../stackgl_modules":1124,"../../components/colorscale":378,"../../lib":503,"../../lib/gl_format_color":499,"../../plots/gl3d/zip3":609}],733:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/colorscale/defaults"),a=t("./attributes");e.exports=function(t,e,r,o){function s(r,i){return n.coerce(t,e,a,r,i)}var l=s("u"),c=s("v"),u=s("w"),f=s("x"),h=s("y"),p=s("z");l&&l.length&&c&&c.length&&u&&u.length&&f&&f.length&&h&&h.length&&p&&p.length?(s("sizeref"),s("sizemode"),s("anchor"),s("lighting.ambient"),s("lighting.diffuse"),s("lighting.specular"),s("lighting.roughness"),s("lighting.fresnel"),s("lightposition.x"),s("lightposition.y"),s("lightposition.z"),i(t,e,o,s,{prefix:"",cLetter:"c"}),s("text"),s("hovertext"),s("hovertemplate"),s("uhoverformat"),s("vhoverformat"),s("whoverformat"),s("xhoverformat"),s("yhoverformat"),s("zhoverformat"),e._length=null):e.visible=!1}},{"../../components/colorscale/defaults":376,"../../lib":503,"./attributes":730}],734:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"cone",basePlotModule:t("../../plots/gl3d"),categories:["gl3d","showLegend"],attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:{min:"cmin",max:"cmax"},calc:t("./calc"),plot:t("./convert"),eventData:function(t,e){return t.norm=e.traceCoordinate[6],t},meta:{}}},{"../../plots/gl3d":598,"./attributes":730,"./calc":731,"./convert":732,"./defaults":733}],735:[function(t,e,r){"use strict";var n=t("../heatmap/attributes"),i=t("../scatter/attributes"),a=t("../../plots/cartesian/axis_format_attributes"),o=a.axisHoverFormat,s=a.descriptionOnlyNumbers,l=t("../../components/colorscale/attributes"),c=t("../../components/drawing/attributes").dash,u=t("../../plots/font_attributes"),f=t("../../lib/extend").extendFlat,h=t("../../constants/filter_ops"),p=h.COMPARISON_OPS2,d=h.INTERVAL_OPS,m=i.line;e.exports=f({z:n.z,x:n.x,x0:n.x0,dx:n.dx,y:n.y,y0:n.y0,dy:n.dy,xperiod:n.xperiod,yperiod:n.yperiod,xperiod0:i.xperiod0,yperiod0:i.yperiod0,xperiodalignment:n.xperiodalignment,yperiodalignment:n.yperiodalignment,text:n.text,hovertext:n.hovertext,transpose:n.transpose,xtype:n.xtype,ytype:n.ytype,xhoverformat:o("x"),yhoverformat:o("y"),zhoverformat:o("z",1),hovertemplate:n.hovertemplate,texttemplate:f({},n.texttemplate,{}),textfont:f({},n.textfont,{}),hoverongaps:n.hoverongaps,connectgaps:f({},n.connectgaps,{}),fillcolor:{valType:"color",editType:"calc"},autocontour:{valType:"boolean",dflt:!0,editType:"calc",impliedEdits:{"contours.start":void 0,"contours.end":void 0,"contours.size":void 0}},ncontours:{valType:"integer",dflt:15,min:1,editType:"calc"},contours:{type:{valType:"enumerated",values:["levels","constraint"],dflt:"levels",editType:"calc"},start:{valType:"number",dflt:null,editType:"plot",impliedEdits:{"^autocontour":!1}},end:{valType:"number",dflt:null,editType:"plot",impliedEdits:{"^autocontour":!1}},size:{valType:"number",dflt:null,min:0,editType:"plot",impliedEdits:{"^autocontour":!1}},coloring:{valType:"enumerated",values:["fill","heatmap","lines","none"],dflt:"fill",editType:"calc"},showlines:{valType:"boolean",dflt:!0,editType:"plot"},showlabels:{valType:"boolean",dflt:!1,editType:"plot"},labelfont:u({editType:"plot",colorEditType:"style"}),labelformat:{valType:"string",dflt:"",editType:"plot",description:s("contour label")},operation:{valType:"enumerated",values:[].concat(p).concat(d),dflt:"=",editType:"calc"},value:{valType:"any",dflt:0,editType:"calc"},editType:"calc",impliedEdits:{autocontour:!1}},line:{color:f({},m.color,{editType:"style+colorbars"}),width:{valType:"number",min:0,editType:"style+colorbars"},dash:c,smoothing:f({},m.smoothing,{}),editType:"plot"}},l("",{cLetter:"z",autoColorDflt:!1,editTypeOverride:"calc"}))},{"../../components/colorscale/attributes":373,"../../components/drawing/attributes":387,"../../constants/filter_ops":475,"../../lib/extend":493,"../../plots/cartesian/axis_format_attributes":557,"../../plots/font_attributes":585,"../heatmap/attributes":792,"../scatter/attributes":927}],736:[function(t,e,r){"use strict";var n=t("../../components/colorscale"),i=t("../heatmap/calc"),a=t("./set_contours"),o=t("./end_plus");e.exports=function(t,e){var r=i(t,e),s=r[0].z;a(e,s);var l,c=e.contours,u=n.extractOpts(e);if("heatmap"===c.coloring&&u.auto&&!1===e.autocontour){var f=c.start,h=o(c),p=c.size||1,d=Math.floor((h-f)/p)+1;isFinite(p)||(p=1,d=1);var m=f-p/2;l=[m,m+d*p]}else l=s;return n.calc(t,e,{vals:l,cLetter:"z"}),r}},{"../../components/colorscale":378,"../heatmap/calc":793,"./end_plus":746,"./set_contours":754}],737:[function(t,e,r){"use strict";e.exports=function(t,e){var r,n=t[0],i=n.z;switch(e.type){case"levels":var a=Math.min(i[0][0],i[0][1]);for(r=0;r<t.length;r++){var o=t[r];o.prefixBoundary=!o.edgepaths.length&&(a>o.level||o.starts.length&&a===o.level)}break;case"constraint":if(n.prefixBoundary=!1,n.edgepaths.length)return;var s=n.x.length,l=n.y.length,c=-1/0,u=1/0;for(r=0;r<l;r++)u=Math.min(u,i[r][0]),u=Math.min(u,i[r][s-1]),c=Math.max(c,i[r][0]),c=Math.max(c,i[r][s-1]);for(r=1;r<s-1;r++)u=Math.min(u,i[0][r]),u=Math.min(u,i[l-1][r]),c=Math.max(c,i[0][r]),c=Math.max(c,i[l-1][r]);var f,h,p=e.value;switch(e._operation){case">":p>c&&(n.prefixBoundary=!0);break;case"<":(p<u||n.starts.length&&p===u)&&(n.prefixBoundary=!0);break;case"[]":f=Math.min(p[0],p[1]),((h=Math.max(p[0],p[1]))<u||f>c||n.starts.length&&h===u)&&(n.prefixBoundary=!0);break;case"][":f=Math.min(p[0],p[1]),h=Math.max(p[0],p[1]),f<u&&h>c&&(n.prefixBoundary=!0)}}}},{}],738:[function(t,e,r){"use strict";var n=t("../../components/colorscale"),i=t("./make_color_map"),a=t("./end_plus");e.exports={min:"zmin",max:"zmax",calc:function(t,e,r){var o=e.contours,s=e.line,l=o.size||1,c=o.coloring,u=i(e,{isColorbar:!0});if("heatmap"===c){var f=n.extractOpts(e);r._fillgradient=f.reversescale?n.flipScale(f.colorscale):f.colorscale,r._zrange=[f.min,f.max]}else"fill"===c&&(r._fillcolor=u);r._line={color:"lines"===c?u:s.color,width:!1!==o.showlines?s.width:0,dash:s.dash},r._levels={start:o.start,end:a(o),size:l}}}},{"../../components/colorscale":378,"./end_plus":746,"./make_color_map":751}],739:[function(t,e,r){"use strict";e.exports={BOTTOMSTART:[1,9,13,104,713],TOPSTART:[4,6,7,104,713],LEFTSTART:[8,12,14,208,1114],RIGHTSTART:[2,3,11,208,1114],NEWDELTA:[null,[-1,0],[0,-1],[-1,0],[1,0],null,[0,-1],[-1,0],[0,1],[0,1],null,[0,1],[1,0],[1,0],[0,-1]],CHOOSESADDLE:{104:[4,1],208:[2,8],713:[7,13],1114:[11,14]},SADDLEREMAINDER:{1:4,2:8,4:1,7:13,8:2,11:14,13:7,14:11},LABELDISTANCE:2,LABELINCREASE:10,LABELMIN:3,LABELMAX:10,LABELOPTIMIZER:{EDGECOST:1,ANGLECOST:1,NEIGHBORCOST:5,SAMELEVELFACTOR:10,SAMELEVELDISTANCE:5,MAXCOST:100,INITIALSEARCHPOINTS:10,ITERATIONS:5}}},{}],740:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("./label_defaults"),a=t("../../components/color"),o=a.addOpacity,s=a.opacity,l=t("../../constants/filter_ops"),c=l.CONSTRAINT_REDUCTION,u=l.COMPARISON_OPS2;e.exports=function(t,e,r,a,l,f){var h,p,d,m=e.contours,g=r("contours.operation");(m._operation=c[g],function(t,e){var r;-1===u.indexOf(e.operation)?(t("contours.value",[0,1]),Array.isArray(e.value)?e.value.length>2?e.value=e.value.slice(2):0===e.length?e.value=[0,1]:e.length<2?(r=parseFloat(e.value[0]),e.value=[r,r+1]):e.value=[parseFloat(e.value[0]),parseFloat(e.value[1])]:n(e.value)&&(r=parseFloat(e.value),e.value=[r,r+1])):(t("contours.value",0),n(e.value)||(Array.isArray(e.value)?e.value=parseFloat(e.value[0]):e.value=0))}(r,m),"="===g?h=m.showlines=!0:(h=r("contours.showlines"),d=r("fillcolor",o((t.line||{}).color||l,.5))),h)&&(p=r("line.color",d&&s(d)?o(e.fillcolor,1):l),r("line.width",2),r("line.dash"));r("line.smoothing"),i(r,a,p,f)}},{"../../components/color":366,"../../constants/filter_ops":475,"./label_defaults":750,"fast-isnumeric":190}],741:[function(t,e,r){"use strict";var n=t("../../constants/filter_ops"),i=t("fast-isnumeric");function a(t,e){var r,a=Array.isArray(e);function o(t){return i(t)?+t:null}return-1!==n.COMPARISON_OPS2.indexOf(t)?r=o(a?e[0]:e):-1!==n.INTERVAL_OPS.indexOf(t)?r=a?[o(e[0]),o(e[1])]:[o(e),o(e)]:-1!==n.SET_OPS.indexOf(t)&&(r=a?e.map(o):[o(e)]),r}function o(t){return function(e){e=a(t,e);var r=Math.min(e[0],e[1]),n=Math.max(e[0],e[1]);return{start:r,end:n,size:n-r}}}function s(t){return function(e){return{start:e=a(t,e),end:1/0,size:1/0}}}e.exports={"[]":o("[]"),"][":o("]["),">":s(">"),"<":s("<"),"=":s("=")}},{"../../constants/filter_ops":475,"fast-isnumeric":190}],742:[function(t,e,r){"use strict";e.exports=function(t,e,r,n){var i=n("contours.start"),a=n("contours.end"),o=!1===i||!1===a,s=r("contours.size");!(o?e.autocontour=!0:r("autocontour",!1))&&s||r("ncontours")}},{}],743:[function(t,e,r){"use strict";var n=t("../../lib");function i(t){return n.extendFlat({},t,{edgepaths:n.extendDeep([],t.edgepaths),paths:n.extendDeep([],t.paths),starts:n.extendDeep([],t.starts)})}e.exports=function(t,e){var r,a,o,s=function(t){return t.reverse()},l=function(t){return t};switch(e){case"=":case"<":return t;case">":for(1!==t.length&&n.warn("Contour data invalid for the specified inequality operation."),a=t[0],r=0;r<a.edgepaths.length;r++)a.edgepaths[r]=s(a.edgepaths[r]);for(r=0;r<a.paths.length;r++)a.paths[r]=s(a.paths[r]);for(r=0;r<a.starts.length;r++)a.starts[r]=s(a.starts[r]);return t;case"][":var c=s;s=l,l=c;case"[]":for(2!==t.length&&n.warn("Contour data invalid for the specified inequality range operation."),a=i(t[0]),o=i(t[1]),r=0;r<a.edgepaths.length;r++)a.edgepaths[r]=s(a.edgepaths[r]);for(r=0;r<a.paths.length;r++)a.paths[r]=s(a.paths[r]);for(r=0;r<a.starts.length;r++)a.starts[r]=s(a.starts[r]);for(;o.edgepaths.length;)a.edgepaths.push(l(o.edgepaths.shift()));for(;o.paths.length;)a.paths.push(l(o.paths.shift()));for(;o.starts.length;)a.starts.push(l(o.starts.shift()));return[a]}}},{"../../lib":503}],744:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../heatmap/xyz_defaults"),a=t("../scatter/period_defaults"),o=t("./constraint_defaults"),s=t("./contours_defaults"),l=t("./style_defaults"),c=t("../heatmap/label_defaults"),u=t("./attributes");e.exports=function(t,e,r,f){function h(r,i){return n.coerce(t,e,u,r,i)}if(i(t,e,h,f)){a(t,e,f,h),h("xhoverformat"),h("yhoverformat"),h("text"),h("hovertext"),h("hoverongaps"),h("hovertemplate");var p="constraint"===h("contours.type");h("connectgaps",n.isArray1D(e.z)),p?o(t,e,h,f,r):(s(t,e,h,(function(r){return n.coerce2(t,e,u,r)})),l(t,e,h,f)),e.contours&&"heatmap"===e.contours.coloring&&c(h,f)}else e.visible=!1}},{"../../lib":503,"../heatmap/label_defaults":802,"../heatmap/xyz_defaults":807,"../scatter/period_defaults":947,"./attributes":735,"./constraint_defaults":740,"./contours_defaults":742,"./style_defaults":756}],745:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./constraint_mapping"),a=t("./end_plus");e.exports=function(t,e,r){for(var o="constraint"===t.type?i[t._operation](t.value):t,s=o.size,l=[],c=a(o),u=r.trace._carpetTrace,f=u?{xaxis:u.aaxis,yaxis:u.baxis,x:r.a,y:r.b}:{xaxis:e.xaxis,yaxis:e.yaxis,x:r.x,y:r.y},h=o.start;h<c;h+=s)if(l.push(n.extendFlat({level:h,crossings:{},starts:[],edgepaths:[],paths:[],z:r.z,smoothing:r.trace.line.smoothing},f)),l.length>1e3){n.warn("Too many contours, clipping at 1000",t);break}return l}},{"../../lib":503,"./constraint_mapping":741,"./end_plus":746}],746:[function(t,e,r){"use strict";e.exports=function(t){return t.end+t.size/1e6}},{}],747:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./constants");function a(t,e,r,n){return Math.abs(t[0]-e[0])<r&&Math.abs(t[1]-e[1])<n}function o(t,e,r,o,l){var c,u=e.join(","),f=t.crossings[u],h=function(t,e,r){var n=0,a=0;t>20&&e?208===t||1114===t?n=0===r[0]?1:-1:a=0===r[1]?1:-1:-1!==i.BOTTOMSTART.indexOf(t)?a=1:-1!==i.LEFTSTART.indexOf(t)?n=1:-1!==i.TOPSTART.indexOf(t)?a=-1:n=-1;return[n,a]}(f,r,e),p=[s(t,e,[-h[0],-h[1]])],d=t.z.length,m=t.z[0].length,g=e.slice(),v=h.slice();for(c=0;c<1e4;c++){if(f>20?(f=i.CHOOSESADDLE[f][(h[0]||h[1])<0?0:1],t.crossings[u]=i.SADDLEREMAINDER[f]):delete t.crossings[u],!(h=i.NEWDELTA[f])){n.log("Found bad marching index:",f,e,t.level);break}p.push(s(t,e,h)),e[0]+=h[0],e[1]+=h[1],u=e.join(","),a(p[p.length-1],p[p.length-2],o,l)&&p.pop();var y=h[0]&&(e[0]<0||e[0]>m-2)||h[1]&&(e[1]<0||e[1]>d-2);if(e[0]===g[0]&&e[1]===g[1]&&h[0]===v[0]&&h[1]===v[1]||r&&y)break;f=t.crossings[u]}1e4===c&&n.log("Infinite loop in contour?");var x,b,_,w,T,k,A,M,S,E,L,C,P,I,O,z=a(p[0],p[p.length-1],o,l),D=0,R=.2*t.smoothing,F=[],B=0;for(c=1;c<p.length;c++)C=p[c],P=p[c-1],I=void 0,O=void 0,I=C[2]-P[2],O=C[3]-P[3],D+=A=Math.sqrt(I*I+O*O),F.push(A);var N=D/F.length*R;function j(t){return p[t%p.length]}for(c=p.length-2;c>=B;c--)if((x=F[c])<N){for(_=0,b=c-1;b>=B&&x+F[b]<N;b--)x+=F[b];if(z&&c===p.length-2)for(_=0;_<b&&x+F[_]<N;_++)x+=F[_];T=c-b+_+1,k=Math.floor((c+b+_+2)/2),w=z||c!==p.length-2?z||-1!==b?T%2?j(k):[(j(k)[0]+j(k+1)[0])/2,(j(k)[1]+j(k+1)[1])/2]:p[0]:p[p.length-1],p.splice(b+1,c-b+1,w),c=b+1,_&&(B=_),z&&(c===p.length-2?p[_]=p[p.length-1]:0===c&&(p[p.length-1]=p[0]))}for(p.splice(0,B),c=0;c<p.length;c++)p[c].length=2;if(!(p.length<2))if(z)p.pop(),t.paths.push(p);else{r||n.log("Unclosed interior contour?",t.level,g.join(","),p.join("L"));var U=!1;for(M=0;M<t.edgepaths.length;M++)if(E=t.edgepaths[M],!U&&a(E[0],p[p.length-1],o,l)){p.pop(),U=!0;var V=!1;for(S=0;S<t.edgepaths.length;S++)if(a((L=t.edgepaths[S])[L.length-1],p[0],o,l)){V=!0,p.shift(),t.edgepaths.splice(M,1),S===M?t.paths.push(p.concat(L)):(S>M&&S--,t.edgepaths[S]=L.concat(p,E));break}V||(t.edgepaths[M]=p.concat(E))}for(M=0;M<t.edgepaths.length&&!U;M++)a((E=t.edgepaths[M])[E.length-1],p[0],o,l)&&(p.shift(),t.edgepaths[M]=E.concat(p),U=!0);U||t.edgepaths.push(p)}}function s(t,e,r){var n=e[0]+Math.max(r[0],0),i=e[1]+Math.max(r[1],0),a=t.z[i][n],o=t.xaxis,s=t.yaxis;if(r[1]){var l=(t.level-a)/(t.z[i][n+1]-a),c=(1!==l?(1-l)*o.c2l(t.x[n]):0)+(0!==l?l*o.c2l(t.x[n+1]):0);return[o.c2p(o.l2c(c),!0),s.c2p(t.y[i],!0),n+l,i]}var u=(t.level-a)/(t.z[i+1][n]-a),f=(1!==u?(1-u)*s.c2l(t.y[i]):0)+(0!==u?u*s.c2l(t.y[i+1]):0);return[o.c2p(t.x[n],!0),s.c2p(s.l2c(f),!0),n,i+u]}e.exports=function(t,e,r){var i,a,s,l;for(e=e||.01,r=r||.01,a=0;a<t.length;a++){for(s=t[a],l=0;l<s.starts.length;l++)o(s,s.starts[l],"edge",e,r);for(i=0;Object.keys(s.crossings).length&&i<1e4;)i++,o(s,Object.keys(s.crossings)[0].split(",").map(Number),void 0,e,r);1e4===i&&n.log("Infinite loop in contour?")}}},{"../../lib":503,"./constants":739}],748:[function(t,e,r){"use strict";var n=t("../../components/color"),i=t("../heatmap/hover");e.exports=function(t,e,r,a,o){o||(o={}),o.isContour=!0;var s=i(t,e,r,a,o);return s&&s.forEach((function(t){var e=t.trace;"constraint"===e.contours.type&&(e.fillcolor&&n.opacity(e.fillcolor)?t.color=n.addOpacity(e.fillcolor,1):e.contours.showlines&&n.opacity(e.line.color)&&(t.color=n.addOpacity(e.line.color,1)))})),s}},{"../../components/color":366,"../heatmap/hover":799}],749:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),calc:t("./calc"),plot:t("./plot").plot,style:t("./style"),colorbar:t("./colorbar"),hoverPoints:t("./hover"),moduleType:"trace",name:"contour",basePlotModule:t("../../plots/cartesian"),categories:["cartesian","svg","2dMap","contour","showLegend"],meta:{}}},{"../../plots/cartesian":568,"./attributes":735,"./calc":736,"./colorbar":738,"./defaults":744,"./hover":748,"./plot":753,"./style":755}],750:[function(t,e,r){"use strict";var n=t("../../lib");e.exports=function(t,e,r,i){if(i||(i={}),t("contours.showlabels")){var a=e.font;n.coerceFont(t,"contours.labelfont",{family:a.family,size:a.size,color:r}),t("contours.labelformat")}!1!==i.hasHover&&t("zhoverformat")}},{"../../lib":503}],751:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/colorscale"),a=t("./end_plus");e.exports=function(t){var e=t.contours,r=e.start,o=a(e),s=e.size||1,l=Math.floor((o-r)/s)+1,c="lines"===e.coloring?0:1,u=i.extractOpts(t);isFinite(s)||(s=1,l=1);var f,h,p=u.reversescale?i.flipScale(u.colorscale):u.colorscale,d=p.length,m=new Array(d),g=new Array(d);if("heatmap"===e.coloring){var v=u.min,y=u.max;for(h=0;h<d;h++)f=p[h],m[h]=f[0]*(y-v)+v,g[h]=f[1];var x=n.extent([v,y,e.start,e.start+s*(l-1)]),b=x[v<y?0:1],_=x[v<y?1:0];b!==v&&(m.splice(0,0,b),g.splice(0,0,g[0])),_!==y&&(m.push(_),g.push(g[g.length-1]))}else for(h=0;h<d;h++)f=p[h],m[h]=(f[0]*(l+c-1)-c/2)*s+r,g[h]=f[1];return i.makeColorScaleFunc({domain:m,range:g},{noNumericCheck:!0})}},{"../../components/colorscale":378,"./end_plus":746,"@plotly/d3":58}],752:[function(t,e,r){"use strict";var n=t("./constants");function i(t,e){var r=(e[0][0]>t?0:1)+(e[0][1]>t?0:2)+(e[1][1]>t?0:4)+(e[1][0]>t?0:8);return 5===r||10===r?t>(e[0][0]+e[0][1]+e[1][0]+e[1][1])/4?5===r?713:1114:5===r?104:208:15===r?0:r}e.exports=function(t){var e,r,a,o,s,l,c,u,f,h=t[0].z,p=h.length,d=h[0].length,m=2===p||2===d;for(r=0;r<p-1;r++)for(o=[],0===r&&(o=o.concat(n.BOTTOMSTART)),r===p-2&&(o=o.concat(n.TOPSTART)),e=0;e<d-1;e++)for(a=o.slice(),0===e&&(a=a.concat(n.LEFTSTART)),e===d-2&&(a=a.concat(n.RIGHTSTART)),s=e+","+r,l=[[h[r][e],h[r][e+1]],[h[r+1][e],h[r+1][e+1]]],f=0;f<t.length;f++)(c=i((u=t[f]).level,l))&&(u.crossings[s]=c,-1!==a.indexOf(c)&&(u.starts.push([e,r]),m&&-1!==a.indexOf(c,a.indexOf(c)+1)&&u.starts.push([e,r])))}},{"./constants":739}],753:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../../components/drawing"),o=t("../../components/colorscale"),s=t("../../lib/svg_text_utils"),l=t("../../plots/cartesian/axes"),c=t("../../plots/cartesian/set_convert"),u=t("../heatmap/plot"),f=t("./make_crossings"),h=t("./find_all_paths"),p=t("./empty_pathinfo"),d=t("./convert_to_constraints"),m=t("./close_boundaries"),g=t("./constants"),v=g.LABELOPTIMIZER;function y(t,e){var r,n,o,s,l,c,u,f="",h=0,p=t.edgepaths.map((function(t,e){return e})),d=!0;function m(t){return Math.abs(t[1]-e[2][1])<.01}function g(t){return Math.abs(t[0]-e[0][0])<.01}function v(t){return Math.abs(t[0]-e[2][0])<.01}for(;p.length;){for(c=a.smoothopen(t.edgepaths[h],t.smoothing),f+=d?c:c.replace(/^M/,"L"),p.splice(p.indexOf(h),1),r=t.edgepaths[h][t.edgepaths[h].length-1],s=-1,o=0;o<4;o++){if(!r){i.log("Missing end?",h,t);break}for(u=r,Math.abs(u[1]-e[0][1])<.01&&!v(r)?n=e[1]:g(r)?n=e[0]:m(r)?n=e[3]:v(r)&&(n=e[2]),l=0;l<t.edgepaths.length;l++){var y=t.edgepaths[l][0];Math.abs(r[0]-n[0])<.01?Math.abs(r[0]-y[0])<.01&&(y[1]-r[1])*(n[1]-y[1])>=0&&(n=y,s=l):Math.abs(r[1]-n[1])<.01?Math.abs(r[1]-y[1])<.01&&(y[0]-r[0])*(n[0]-y[0])>=0&&(n=y,s=l):i.log("endpt to newendpt is not vert. or horz.",r,n,y)}if(r=n,s>=0)break;f+="L"+n}if(s===t.edgepaths.length){i.log("unclosed perimeter path");break}h=s,(d=-1===p.indexOf(h))&&(h=p[0],f+="Z")}for(h=0;h<t.paths.length;h++)f+=a.smoothclosed(t.paths[h],t.smoothing);return f}function x(t,e,r,n){var a=e.width/2,o=e.height/2,s=t.x,l=t.y,c=t.theta,u=Math.cos(c)*a,f=Math.sin(c)*a,h=(s>n.center?n.right-s:s-n.left)/(u+Math.abs(Math.sin(c)*o)),p=(l>n.middle?n.bottom-l:l-n.top)/(Math.abs(f)+Math.cos(c)*o);if(h<1||p<1)return 1/0;var d=v.EDGECOST*(1/(h-1)+1/(p-1));d+=v.ANGLECOST*c*c;for(var m=s-u,g=l-f,y=s+u,x=l+f,b=0;b<r.length;b++){var _=r[b],w=Math.cos(_.theta)*_.width/2,T=Math.sin(_.theta)*_.width/2,k=2*i.segmentDistance(m,g,y,x,_.x-w,_.y-T,_.x+w,_.y+T)/(e.height+_.height),A=_.level===e.level,M=A?v.SAMELEVELDISTANCE:1;if(k<=M)return 1/0;d+=v.NEIGHBORCOST*(A?v.SAMELEVELFACTOR:1)/(k-M)}return d}function b(t){var e,r,n=t.trace._emptypoints,i=[],a=t.z.length,o=t.z[0].length,s=[];for(e=0;e<o;e++)s.push(1);for(e=0;e<a;e++)i.push(s.slice());for(e=0;e<n.length;e++)i[(r=n[e])[0]][r[1]]=0;return t.zmask=i,i}r.plot=function(t,e,o,s){var l=e.xaxis,c=e.yaxis;i.makeTraceGroups(s,o,"contour").each((function(o){var s=n.select(this),v=o[0],x=v.trace,_=v.x,w=v.y,T=x.contours,k=p(T,e,v),A=i.ensureSingle(s,"g","heatmapcoloring"),M=[];"heatmap"===T.coloring&&(M=[o]),u(t,e,M,A),f(k),h(k);var S=l.c2p(_[0],!0),E=l.c2p(_[_.length-1],!0),L=c.c2p(w[0],!0),C=c.c2p(w[w.length-1],!0),P=[[S,C],[E,C],[E,L],[S,L]],I=k;"constraint"===T.type&&(I=d(k,T._operation)),function(t,e,r){var n=i.ensureSingle(t,"g","contourbg").selectAll("path").data("fill"===r.coloring?[0]:[]);n.enter().append("path"),n.exit().remove(),n.attr("d","M"+e.join("L")+"Z").style("stroke","none")}(s,P,T),function(t,e,r,a){var o="fill"===a.coloring||"constraint"===a.type&&"="!==a._operation,s="M"+r.join("L")+"Z";o&&m(e,a);var l=i.ensureSingle(t,"g","contourfill").selectAll("path").data(o?e:[]);l.enter().append("path"),l.exit().remove(),l.each((function(t){var e=(t.prefixBoundary?s:"")+y(t,r);e?n.select(this).attr("d",e).style("stroke","none"):n.select(this).remove()}))}(s,I,P,T),function(t,e,o,s,l){var c=i.ensureSingle(t,"g","contourlines"),u=!1!==l.showlines,f=l.showlabels,h=u&&f,p=r.createLines(c,u||f,e),d=r.createLineClip(c,h,o,s.trace.uid),m=t.selectAll("g.contourlabels").data(f?[0]:[]);if(m.exit().remove(),m.enter().append("g").classed("contourlabels",!0),f){var v=[],y=[];i.clearLocationCache();var x=r.labelFormatter(o,s),b=a.tester.append("text").attr("data-notex",1).call(a.font,l.labelfont),_=e[0].xaxis,w=e[0].yaxis,T=_._length,k=w._length,A=_.range,M=w.range,S=i.aggNums(Math.min,null,s.x),E=i.aggNums(Math.max,null,s.x),L=i.aggNums(Math.min,null,s.y),C=i.aggNums(Math.max,null,s.y),P=Math.max(_.c2p(S,!0),0),I=Math.min(_.c2p(E,!0),T),O=Math.max(w.c2p(C,!0),0),z=Math.min(w.c2p(L,!0),k),D={};A[0]<A[1]?(D.left=P,D.right=I):(D.left=I,D.right=P),M[0]<M[1]?(D.top=O,D.bottom=z):(D.top=z,D.bottom=O),D.middle=(D.top+D.bottom)/2,D.center=(D.left+D.right)/2,v.push([[D.left,D.top],[D.right,D.top],[D.right,D.bottom],[D.left,D.bottom]]);var R=Math.sqrt(T*T+k*k),F=g.LABELDISTANCE*R/Math.max(1,e.length/g.LABELINCREASE);p.each((function(t){var e=r.calcTextOpts(t.level,x,b,o);n.select(this).selectAll("path").each((function(){var t=i.getVisibleSegment(this,D,e.height/2);if(t&&!(t.len<(e.width+e.height)*g.LABELMIN))for(var n=Math.min(Math.ceil(t.len/F),g.LABELMAX),a=0;a<n;a++){var o=r.findBestTextLocation(this,t,e,y,D);if(!o)break;r.addLabelData(o,e,y,v)}}))})),b.remove(),r.drawLabels(m,y,o,d,h?v:null)}f&&!u&&p.remove()}(s,k,t,v,T),function(t,e,r,n,o){var s=n.trace,l=r._fullLayout._clips,c="clip"+s.uid,u=l.selectAll("#"+c).data(s.connectgaps?[]:[0]);if(u.enter().append("clipPath").classed("contourclip",!0).attr("id",c),u.exit().remove(),!1===s.connectgaps){var p={level:.9,crossings:{},starts:[],edgepaths:[],paths:[],xaxis:e.xaxis,yaxis:e.yaxis,x:n.x,y:n.y,z:b(n),smoothing:0};f([p]),h([p]),m([p],{type:"levels"}),i.ensureSingle(u,"path","").attr("d",(p.prefixBoundary?"M"+o.join("L")+"Z":"")+y(p,o))}else c=null;a.setClipUrl(t,c,r)}(s,e,t,v,P)}))},r.createLines=function(t,e,r){var n=r[0].smoothing,i=t.selectAll("g.contourlevel").data(e?r:[]);if(i.exit().remove(),i.enter().append("g").classed("contourlevel",!0),e){var o=i.selectAll("path.openline").data((function(t){return t.pedgepaths||t.edgepaths}));o.exit().remove(),o.enter().append("path").classed("openline",!0),o.attr("d",(function(t){return a.smoothopen(t,n)})).style("stroke-miterlimit",1).style("vector-effect","non-scaling-stroke");var s=i.selectAll("path.closedline").data((function(t){return t.ppaths||t.paths}));s.exit().remove(),s.enter().append("path").classed("closedline",!0),s.attr("d",(function(t){return a.smoothclosed(t,n)})).style("stroke-miterlimit",1).style("vector-effect","non-scaling-stroke")}return i},r.createLineClip=function(t,e,r,n){var i=e?"clipline"+n:null,o=r._fullLayout._clips.selectAll("#"+i).data(e?[0]:[]);return o.exit().remove(),o.enter().append("clipPath").classed("contourlineclip",!0).attr("id",i),a.setClipUrl(t,i,r),o},r.labelFormatter=function(t,e){var r=t._fullLayout,n=e.trace,i=n.contours,a={type:"linear",_id:"ycontour",showexponent:"all",exponentformat:"B"};if(i.labelformat)a.tickformat=i.labelformat,c(a,r);else{var s=o.extractOpts(n);if(s&&s.colorbar&&s.colorbar._axis)a=s.colorbar._axis;else{if("constraint"===i.type){var u=i.value;Array.isArray(u)?a.range=[u[0],u[u.length-1]]:a.range=[u,u]}else a.range=[i.start,i.end],a.nticks=(i.end-i.start)/i.size;a.range[0]===a.range[1]&&(a.range[1]+=a.range[0]||1),a.nticks||(a.nticks=1e3),c(a,r),l.prepTicks(a),a._tmin=null,a._tmax=null}}return function(t){return l.tickText(a,t).text}},r.calcTextOpts=function(t,e,r,n){var i=e(t);r.text(i).call(s.convertToTspans,n);var o=r.node(),l=a.bBox(o,!0);return{text:i,width:l.width,height:l.height,fontSize:+o.style["font-size"].replace("px",""),level:t,dy:(l.top+l.bottom)/2}},r.findBestTextLocation=function(t,e,r,n,a){var o,s,l,c,u,f=r.width;e.isClosed?(s=e.len/v.INITIALSEARCHPOINTS,o=e.min+s/2,l=e.max):(s=(e.len-f)/(v.INITIALSEARCHPOINTS+1),o=e.min+s+f/2,l=e.max-(s+f)/2);for(var h=1/0,p=0;p<v.ITERATIONS;p++){for(var d=o;d<l;d+=s){var m=i.getTextLocation(t,e.total,d,f),g=x(m,r,n,a);g<h&&(h=g,u=m,c=d)}if(h>2*v.MAXCOST)break;p&&(s/=2),l=(o=c-s/2)+1.5*s}if(h<=v.MAXCOST)return u},r.addLabelData=function(t,e,r,n){var i=e.fontSize,a=e.width+i/3,o=Math.max(0,e.height-i/3),s=t.x,l=t.y,c=t.theta,u=Math.sin(c),f=Math.cos(c),h=function(t,e){return[s+t*f-e*u,l+t*u+e*f]},p=[h(-a/2,-o/2),h(-a/2,o/2),h(a/2,o/2),h(a/2,-o/2)];r.push({text:e.text,x:s,y:l,dy:e.dy,theta:c,level:e.level,width:a,height:o}),n.push(p)},r.drawLabels=function(t,e,r,a,o){var l=t.selectAll("text").data(e,(function(t){return t.text+","+t.x+","+t.y+","+t.theta}));if(l.exit().remove(),l.enter().append("text").attr({"data-notex":1,"text-anchor":"middle"}).each((function(t){var e=t.x+Math.sin(t.theta)*t.dy,i=t.y-Math.cos(t.theta)*t.dy;n.select(this).text(t.text).attr({x:e,y:i,transform:"rotate("+180*t.theta/Math.PI+" "+e+" "+i+")"}).call(s.convertToTspans,r)})),o){for(var c="",u=0;u<o.length;u++)c+="M"+o[u].join("L")+"Z";i.ensureSingle(a,"path","").attr("d",c)}}},{"../../components/colorscale":378,"../../components/drawing":388,"../../lib":503,"../../lib/svg_text_utils":529,"../../plots/cartesian/axes":554,"../../plots/cartesian/set_convert":576,"../heatmap/plot":804,"./close_boundaries":737,"./constants":739,"./convert_to_constraints":743,"./empty_pathinfo":745,"./find_all_paths":747,"./make_crossings":752,"@plotly/d3":58}],754:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes"),i=t("../../lib");function a(t,e,r){var i={type:"linear",range:[t,e]};return n.autoTicks(i,(e-t)/(r||15)),i}e.exports=function(t,e){var r=t.contours;if(t.autocontour){var o=t.zmin,s=t.zmax;(t.zauto||void 0===o)&&(o=i.aggNums(Math.min,null,e)),(t.zauto||void 0===s)&&(s=i.aggNums(Math.max,null,e));var l=a(o,s,t.ncontours);r.size=l.dtick,r.start=n.tickFirst(l),l.range.reverse(),r.end=n.tickFirst(l),r.start===o&&(r.start+=r.size),r.end===s&&(r.end-=r.size),r.start>r.end&&(r.start=r.end=(r.start+r.end)/2),t._input.contours||(t._input.contours={}),i.extendFlat(t._input.contours,{start:r.start,end:r.end,size:r.size}),t._input.autocontour=!0}else if("constraint"!==r.type){var c,u=r.start,f=r.end,h=t._input.contours;if(u>f&&(r.start=h.start=f,f=r.end=h.end=u,u=r.start),!(r.size>0))c=u===f?1:a(u,f,t.ncontours).dtick,h.size=r.size=c}}},{"../../lib":503,"../../plots/cartesian/axes":554}],755:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/drawing"),a=t("../heatmap/style"),o=t("./make_color_map");e.exports=function(t){var e=n.select(t).selectAll("g.contour");e.style("opacity",(function(t){return t[0].trace.opacity})),e.each((function(t){var e=n.select(this),r=t[0].trace,a=r.contours,s=r.line,l=a.size||1,c=a.start,u="constraint"===a.type,f=!u&&"lines"===a.coloring,h=!u&&"fill"===a.coloring,p=f||h?o(r):null;e.selectAll("g.contourlevel").each((function(t){n.select(this).selectAll("path").call(i.lineGroupStyle,s.width,f?p(t.level):s.color,s.dash)}));var d=a.labelfont;if(e.selectAll("g.contourlabels text").each((function(t){i.font(n.select(this),{family:d.family,size:d.size,color:d.color||(f?p(t.level):s.color)})})),u)e.selectAll("g.contourfill path").style("fill",r.fillcolor);else if(h){var m;e.selectAll("g.contourfill path").style("fill",(function(t){return void 0===m&&(m=t.level),p(t.level+.5*l)})),void 0===m&&(m=c),e.selectAll("g.contourbg path").style("fill",p(m-.5*l))}})),a(t)}},{"../../components/drawing":388,"../heatmap/style":805,"./make_color_map":751,"@plotly/d3":58}],756:[function(t,e,r){"use strict";var n=t("../../components/colorscale/defaults"),i=t("./label_defaults");e.exports=function(t,e,r,a,o){var s,l=r("contours.coloring"),c="";"fill"===l&&(s=r("contours.showlines")),!1!==s&&("lines"!==l&&(c=r("line.color","#000")),r("line.width",.5),r("line.dash")),"none"!==l&&(!0!==t.showlegend&&(e.showlegend=!1),e._dfltShowLegend=!1,n(t,e,a,r,{prefix:"",cLetter:"z"})),r("line.smoothing"),i(r,a,c,o)}},{"../../components/colorscale/defaults":376,"./label_defaults":750}],757:[function(t,e,r){"use strict";var n=t("../heatmap/attributes"),i=t("../contour/attributes"),a=t("../../components/colorscale/attributes"),o=t("../../lib/extend").extendFlat,s=i.contours;e.exports=o({carpet:{valType:"string",editType:"calc"},z:n.z,a:n.x,a0:n.x0,da:n.dx,b:n.y,b0:n.y0,db:n.dy,text:n.text,hovertext:n.hovertext,transpose:n.transpose,atype:n.xtype,btype:n.ytype,fillcolor:i.fillcolor,autocontour:i.autocontour,ncontours:i.ncontours,contours:{type:s.type,start:s.start,end:s.end,size:s.size,coloring:{valType:"enumerated",values:["fill","lines","none"],dflt:"fill",editType:"calc"},showlines:s.showlines,showlabels:s.showlabels,labelfont:s.labelfont,labelformat:s.labelformat,operation:s.operation,value:s.value,editType:"calc",impliedEdits:{autocontour:!1}},line:{color:i.line.color,width:i.line.width,dash:i.line.dash,smoothing:i.line.smoothing,editType:"plot"},transforms:void 0},a("",{cLetter:"z",autoColorDflt:!1}))},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../contour/attributes":735,"../heatmap/attributes":792}],758:[function(t,e,r){"use strict";var n=t("../../components/colorscale/calc"),i=t("../../lib"),a=t("../heatmap/convert_column_xyz"),o=t("../heatmap/clean_2d_array"),s=t("../heatmap/interp2d"),l=t("../heatmap/find_empties"),c=t("../heatmap/make_bound_array"),u=t("./defaults"),f=t("../carpet/lookup_carpetid"),h=t("../contour/set_contours");e.exports=function(t,e){var r=e._carpetTrace=f(t,e);if(r&&r.visible&&"legendonly"!==r.visible){if(!e.a||!e.b){var p=t.data[r.index],d=t.data[e.index];d.a||(d.a=p.a),d.b||(d.b=p.b),u(d,e,e._defaultColor,t._fullLayout)}var m=function(t,e){var r,u,f,h,p,d,m,g=e._carpetTrace,v=g.aaxis,y=g.baxis;v._minDtick=0,y._minDtick=0,i.isArray1D(e.z)&&a(e,v,y,"a","b",["z"]);r=e._a=e._a||e.a,h=e._b=e._b||e.b,r=r?v.makeCalcdata(e,"_a"):[],h=h?y.makeCalcdata(e,"_b"):[],u=e.a0||0,f=e.da||1,p=e.b0||0,d=e.db||1,m=e._z=o(e._z||e.z,e.transpose),e._emptypoints=l(m),s(m,e._emptypoints);var x=i.maxRowLength(m),b="scaled"===e.xtype?"":r,_=c(e,b,u,f,x,v),w="scaled"===e.ytype?"":h,T=c(e,w,p,d,m.length,y),k={a:_,b:T,z:m};"levels"===e.contours.type&&"none"!==e.contours.coloring&&n(t,e,{vals:m,containerStr:"",cLetter:"z"});return[k]}(t,e);return h(e,e._z),m}}},{"../../components/colorscale/calc":374,"../../lib":503,"../carpet/lookup_carpetid":708,"../contour/set_contours":754,"../heatmap/clean_2d_array":794,"../heatmap/convert_column_xyz":796,"../heatmap/find_empties":798,"../heatmap/interp2d":801,"../heatmap/make_bound_array":803,"./defaults":759}],759:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../heatmap/xyz_defaults"),a=t("./attributes"),o=t("../contour/constraint_defaults"),s=t("../contour/contours_defaults"),l=t("../contour/style_defaults");e.exports=function(t,e,r,c){function u(r,i){return n.coerce(t,e,a,r,i)}if(u("carpet"),t.a&&t.b){if(!i(t,e,u,c,"a","b"))return void(e.visible=!1);u("text"),"constraint"===u("contours.type")?o(t,e,u,c,r,{hasHover:!1}):(s(t,e,u,(function(r){return n.coerce2(t,e,a,r)})),l(t,e,u,c,{hasHover:!1}))}else e._defaultColor=r,e._length=null}},{"../../lib":503,"../contour/constraint_defaults":740,"../contour/contours_defaults":742,"../contour/style_defaults":756,"../heatmap/xyz_defaults":807,"./attributes":757}],760:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:t("../contour/colorbar"),calc:t("./calc"),plot:t("./plot"),style:t("../contour/style"),moduleType:"trace",name:"contourcarpet",basePlotModule:t("../../plots/cartesian"),categories:["cartesian","svg","carpet","contour","symbols","showLegend","hasLines","carpetDependent","noHover","noSortingByValue"],meta:{}}},{"../../plots/cartesian":568,"../contour/colorbar":738,"../contour/style":755,"./attributes":757,"./calc":758,"./defaults":759,"./plot":761}],761:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../carpet/map_1d_array"),a=t("../carpet/makepath"),o=t("../../components/drawing"),s=t("../../lib"),l=t("../contour/make_crossings"),c=t("../contour/find_all_paths"),u=t("../contour/plot"),f=t("../contour/constants"),h=t("../contour/convert_to_constraints"),p=t("../contour/empty_pathinfo"),d=t("../contour/close_boundaries"),m=t("../carpet/lookup_carpetid"),g=t("../carpet/axis_aligned_line");function v(t,e,r){var n=t.getPointAtLength(e),i=t.getPointAtLength(r),a=i.x-n.x,o=i.y-n.y,s=Math.sqrt(a*a+o*o);return[a/s,o/s]}function y(t){var e=Math.sqrt(t[0]*t[0]+t[1]*t[1]);return[t[0]/e,t[1]/e]}function x(t,e){var r=Math.abs(t[0]*e[0]+t[1]*e[1]);return Math.sqrt(1-r*r)/r}e.exports=function(t,e,r,b){var _=e.xaxis,w=e.yaxis;s.makeTraceGroups(b,r,"contour").each((function(r){var b=n.select(this),T=r[0],k=T.trace,A=k._carpetTrace=m(t,k),M=t.calcdata[A.index][0];if(A.visible&&"legendonly"!==A.visible){var S=T.a,E=T.b,L=k.contours,C=p(L,e,T),P="constraint"===L.type,I=L._operation,O=P?"="===I?"lines":"fill":L.coloring,z=[[S[0],E[E.length-1]],[S[S.length-1],E[E.length-1]],[S[S.length-1],E[0]],[S[0],E[0]]];l(C);var D=1e-8*(S[S.length-1]-S[0]),R=1e-8*(E[E.length-1]-E[0]);c(C,D,R);var F,B,N,j,U=C;"constraint"===L.type&&(U=h(C,I)),function(t,e){var r,n,i,a,o,s,l,c,u;for(r=0;r<t.length;r++){for(a=t[r],o=a.pedgepaths=[],s=a.ppaths=[],n=0;n<a.edgepaths.length;n++){for(u=a.edgepaths[n],l=[],i=0;i<u.length;i++)l[i]=e(u[i]);o.push(l)}for(n=0;n<a.paths.length;n++){for(u=a.paths[n],c=[],i=0;i<u.length;i++)c[i]=e(u[i]);s.push(c)}}}(C,q);var V=[];for(j=M.clipsegments.length-1;j>=0;j--)F=M.clipsegments[j],B=i([],F.x,_.c2p),N=i([],F.y,w.c2p),B.reverse(),N.reverse(),V.push(a(B,N,F.bicubic));var H="M"+V.join("L")+"Z";!function(t,e,r,n,o,l){var c,u,f,h,p=s.ensureSingle(t,"g","contourbg").selectAll("path").data("fill"!==l||o?[]:[0]);p.enter().append("path"),p.exit().remove();var d=[];for(h=0;h<e.length;h++)c=e[h],u=i([],c.x,r.c2p),f=i([],c.y,n.c2p),d.push(a(u,f,c.bicubic));p.attr("d","M"+d.join("L")+"Z").style("stroke","none")}(b,M.clipsegments,_,w,P,O),function(t,e,r,i,a,l,c,u,f,h,p){var m="fill"===h;m&&d(a,t.contours);var v=s.ensureSingle(e,"g","contourfill").selectAll("path").data(m?a:[]);v.enter().append("path"),v.exit().remove(),v.each((function(t){var e=(t.prefixBoundary?p:"")+function(t,e,r,n,i,a,l,c){var u,f,h,p,d,m,v,y="",x=e.edgepaths.map((function(t,e){return e})),b=!0,_=1e-4*Math.abs(r[0][0]-r[2][0]),w=1e-4*Math.abs(r[0][1]-r[2][1]);function T(t){return Math.abs(t[1]-r[0][1])<w}function k(t){return Math.abs(t[1]-r[2][1])<w}function A(t){return Math.abs(t[0]-r[0][0])<_}function M(t){return Math.abs(t[0]-r[2][0])<_}function S(t,e){var r,n,o,s,u="";for(T(t)&&!M(t)||k(t)&&!A(t)?(s=i.aaxis,o=g(i,a,[t[0],e[0]],.5*(t[1]+e[1]))):(s=i.baxis,o=g(i,a,.5*(t[0]+e[0]),[t[1],e[1]])),r=1;r<o.length;r++)for(u+=s.smoothing?"C":"L",n=0;n<o[r].length;n++){var f=o[r][n];u+=[l.c2p(f[0]),c.c2p(f[1])]+" "}return u}u=0,f=null;for(;x.length;){var E=e.edgepaths[u][0];for(f&&(y+=S(f,E)),v=o.smoothopen(e.edgepaths[u].map(n),e.smoothing),y+=b?v:v.replace(/^M/,"L"),x.splice(x.indexOf(u),1),f=e.edgepaths[u][e.edgepaths[u].length-1],d=-1,p=0;p<4;p++){if(!f){s.log("Missing end?",u,e);break}for(T(f)&&!M(f)?h=r[1]:A(f)?h=r[0]:k(f)?h=r[3]:M(f)&&(h=r[2]),m=0;m<e.edgepaths.length;m++){var L=e.edgepaths[m][0];Math.abs(f[0]-h[0])<_?Math.abs(f[0]-L[0])<_&&(L[1]-f[1])*(h[1]-L[1])>=0&&(h=L,d=m):Math.abs(f[1]-h[1])<w?Math.abs(f[1]-L[1])<w&&(L[0]-f[0])*(h[0]-L[0])>=0&&(h=L,d=m):s.log("endpt to newendpt is not vert. or horz.",f,h,L)}if(d>=0)break;y+=S(f,h),f=h}if(d===e.edgepaths.length){s.log("unclosed perimeter path");break}u=d,(b=-1===x.indexOf(u))&&(u=x[0],y+=S(f,h)+"Z",f=null)}for(u=0;u<e.paths.length;u++)y+=o.smoothclosed(e.paths[u].map(n),e.smoothing);return y}(0,t,l,c,u,f,r,i);e?n.select(this).attr("d",e).style("stroke","none"):n.select(this).remove()}))}(k,b,_,w,U,z,q,A,M,O,H),function(t,e,r,i,a,l,c){var h=s.ensureSingle(t,"g","contourlines"),p=!1!==a.showlines,d=a.showlabels,m=p&&d,g=u.createLines(h,p||d,e),b=u.createLineClip(h,m,r,i.trace.uid),_=t.selectAll("g.contourlabels").data(d?[0]:[]);if(_.exit().remove(),_.enter().append("g").classed("contourlabels",!0),d){var w=l.xaxis,T=l.yaxis,k=w._length,A=T._length,M=[[[0,0],[k,0],[k,A],[0,A]]],S=[];s.clearLocationCache();var E=u.labelFormatter(r,i),L=o.tester.append("text").attr("data-notex",1).call(o.font,a.labelfont),C={left:0,right:k,center:k/2,top:0,bottom:A,middle:A/2},P=Math.sqrt(k*k+A*A),I=f.LABELDISTANCE*P/Math.max(1,e.length/f.LABELINCREASE);g.each((function(t){var e=u.calcTextOpts(t.level,E,L,r);n.select(this).selectAll("path").each((function(r){var n=s.getVisibleSegment(this,C,e.height/2);if(n&&(function(t,e,r,n,i,a){for(var o,s=0;s<r.pedgepaths.length;s++)e===r.pedgepaths[s]&&(o=r.edgepaths[s]);if(!o)return;var l=i.a[0],c=i.a[i.a.length-1],u=i.b[0],f=i.b[i.b.length-1];function h(t,e){var r,n=0;return(Math.abs(t[0]-l)<.1||Math.abs(t[0]-c)<.1)&&(r=y(i.dxydb_rough(t[0],t[1],.1)),n=Math.max(n,a*x(e,r)/2)),(Math.abs(t[1]-u)<.1||Math.abs(t[1]-f)<.1)&&(r=y(i.dxyda_rough(t[0],t[1],.1)),n=Math.max(n,a*x(e,r)/2)),n}var p=v(t,0,1),d=v(t,n.total,n.total-1),m=h(o[0],p),g=n.total-h(o[o.length-1],d);n.min<m&&(n.min=m);n.max>g&&(n.max=g);n.len=n.max-n.min}(this,r,t,n,c,e.height),!(n.len<(e.width+e.height)*f.LABELMIN)))for(var i=Math.min(Math.ceil(n.len/I),f.LABELMAX),a=0;a<i;a++){var o=u.findBestTextLocation(this,n,e,S,C);if(!o)break;u.addLabelData(o,e,S,M)}}))})),L.remove(),u.drawLabels(_,S,r,b,m?M:null)}d&&!p&&g.remove()}(b,C,t,T,L,e,A),o.setClipUrl(b,A._clipPathId,t)}function q(t){var e=A.ab2xy(t[0],t[1],!0);return[_.c2p(e[0]),w.c2p(e[1])]}}))}},{"../../components/drawing":388,"../../lib":503,"../carpet/axis_aligned_line":692,"../carpet/lookup_carpetid":708,"../carpet/makepath":709,"../carpet/map_1d_array":710,"../contour/close_boundaries":737,"../contour/constants":739,"../contour/convert_to_constraints":743,"../contour/empty_pathinfo":745,"../contour/find_all_paths":747,"../contour/make_crossings":752,"../contour/plot":753,"@plotly/d3":58}],762:[function(t,e,r){"use strict";var n=t("../../components/colorscale/attributes"),i=t("../../plots/template_attributes").hovertemplateAttrs,a=t("../../plots/attributes"),o=t("../scattermapbox/attributes"),s=t("../../lib/extend").extendFlat;e.exports=s({lon:o.lon,lat:o.lat,z:{valType:"data_array",editType:"calc"},radius:{valType:"number",editType:"plot",arrayOk:!0,min:1,dflt:30},below:{valType:"string",editType:"plot"},text:o.text,hovertext:o.hovertext,hoverinfo:s({},a.hoverinfo,{flags:["lon","lat","z","text","name"]}),hovertemplate:i(),showlegend:s({},a.showlegend,{dflt:!1})},n("",{cLetter:"z",editTypeOverride:"calc"}))},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/template_attributes":633,"../scattermapbox/attributes":993}],763:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib").isArrayOrTypedArray,a=t("../../constants/numerical").BADNUM,o=t("../../components/colorscale/calc"),s=t("../../lib")._;e.exports=function(t,e){for(var r=e._length,l=new Array(r),c=e.z,u=i(c)&&c.length,f=0;f<r;f++){var h=l[f]={},p=e.lon[f],d=e.lat[f];if(h.lonlat=n(p)&&n(d)?[+p,+d]:[a,a],u){var m=c[f];h.z=n(m)?m:a}}return o(t,e,{vals:u?c:[0,1],containerStr:"",cLetter:"z"}),r&&(l[0].t={labels:{lat:s(t,"lat:")+" ",lon:s(t,"lon:")+" "}}),l}},{"../../components/colorscale/calc":374,"../../constants/numerical":479,"../../lib":503,"fast-isnumeric":190}],764:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=t("../../components/color"),o=t("../../components/colorscale"),s=t("../../constants/numerical").BADNUM,l=t("../../lib/geojson_utils").makeBlank;e.exports=function(t){var e=t[0].trace,r=!0===e.visible&&0!==e._length,c=e._opts={heatmap:{layout:{visibility:"none"},paint:{}},geojson:l()};if(!r)return c;var u,f=[],h=e.z,p=e.radius,d=i.isArrayOrTypedArray(h)&&h.length,m=i.isArrayOrTypedArray(p);for(u=0;u<t.length;u++){var g=t[u],v=g.lonlat;if(v[0]!==s){var y={};if(d){var x=g.z;y.z=x!==s?x:0}m&&(y.r=n(p[u])&&p[u]>0?+p[u]:0),f.push({type:"Feature",geometry:{type:"Point",coordinates:v},properties:y})}}var b=o.extractOpts(e),_=b.reversescale?o.flipScale(b.colorscale):b.colorscale,w=_[0][1],T=["interpolate",["linear"],["heatmap-density"],0,a.opacity(w)<1?w:a.addOpacity(w,0)];for(u=1;u<_.length;u++)T.push(_[u][0],_[u][1]);var k=["interpolate",["linear"],["get","z"],b.min,0,b.max,1];return i.extendFlat(c.heatmap.paint,{"heatmap-weight":d?k:1/(b.max-b.min),"heatmap-color":T,"heatmap-radius":m?{type:"identity",property:"r"}:e.radius,"heatmap-opacity":e.opacity}),c.geojson={type:"FeatureCollection",features:f},c.heatmap.layout.visibility="visible",c}},{"../../components/color":366,"../../components/colorscale":378,"../../constants/numerical":479,"../../lib":503,"../../lib/geojson_utils":497,"fast-isnumeric":190}],765:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/colorscale/defaults"),a=t("./attributes");e.exports=function(t,e,r,o){function s(r,i){return n.coerce(t,e,a,r,i)}var l=s("lon")||[],c=s("lat")||[],u=Math.min(l.length,c.length);u?(e._length=u,s("z"),s("radius"),s("below"),s("text"),s("hovertext"),s("hovertemplate"),i(t,e,o,s,{prefix:"",cLetter:"z"})):e.visible=!1}},{"../../components/colorscale/defaults":376,"../../lib":503,"./attributes":762}],766:[function(t,e,r){"use strict";e.exports=function(t,e){return t.lon=e.lon,t.lat=e.lat,t.z=e.z,t}},{}],767:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes"),i=t("../scattermapbox/hover").hoverPoints,a=t("../scattermapbox/hover").getExtraText;e.exports=function(t,e,r){var o=i(t,e,r);if(o){var s=o[0],l=s.cd,c=l[0].trace,u=l[s.index];if(delete s.color,"z"in u){var f=s.subplot.mockAxis;s.z=u.z,s.zLabel=n.tickText(f,f.c2l(u.z),"hover").text}return s.extraText=a(c,u,l[0].t.labels),[s]}}},{"../../plots/cartesian/axes":554,"../scattermapbox/hover":998}],768:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:t("../heatmap/colorbar"),formatLabels:t("../scattermapbox/format_labels"),calc:t("./calc"),plot:t("./plot"),hoverPoints:t("./hover"),eventData:t("./event_data"),getBelow:function(t,e){for(var r=e.getMapLayers(),n=0;n<r.length;n++){var i=r[n],a=i.id;if("symbol"===i.type&&"string"==typeof a&&-1===a.indexOf("plotly-"))return a}},moduleType:"trace",name:"densitymapbox",basePlotModule:t("../../plots/mapbox"),categories:["mapbox","gl","showLegend"],meta:{hr_name:"density_mapbox"}}},{"../../plots/mapbox":613,"../heatmap/colorbar":795,"../scattermapbox/format_labels":997,"./attributes":762,"./calc":763,"./defaults":765,"./event_data":766,"./hover":767,"./plot":769}],769:[function(t,e,r){"use strict";var n=t("./convert"),i=t("../../plots/mapbox/constants").traceLayerPrefix;function a(t,e){this.type="densitymapbox",this.subplot=t,this.uid=e,this.sourceId="source-"+e,this.layerList=[["heatmap",i+e+"-heatmap"]],this.below=null}var o=a.prototype;o.update=function(t){var e=this.subplot,r=this.layerList,i=n(t),a=e.belowLookup["trace-"+this.uid];e.map.getSource(this.sourceId).setData(i.geojson),a!==this.below&&(this._removeLayers(),this._addLayers(i,a),this.below=a);for(var o=0;o<r.length;o++){var s=r[o],l=s[0],c=s[1],u=i[l];e.setOptions(c,"setLayoutProperty",u.layout),"visible"===u.layout.visibility&&e.setOptions(c,"setPaintProperty",u.paint)}},o._addLayers=function(t,e){for(var r=this.subplot,n=this.layerList,i=this.sourceId,a=0;a<n.length;a++){var o=n[a],s=o[0],l=t[s];r.addLayer({type:s,id:o[1],source:i,layout:l.layout,paint:l.paint},e)}},o._removeLayers=function(){for(var t=this.subplot.map,e=this.layerList,r=e.length-1;r>=0;r--)t.removeLayer(e[r][1])},o.dispose=function(){var t=this.subplot.map;this._removeLayers(),t.removeSource(this.sourceId)},e.exports=function(t,e){var r=e[0].trace,i=new a(t,r.uid),o=i.sourceId,s=n(e),l=i.below=t.belowLookup["trace-"+r.uid];return t.map.addSource(o,{type:"geojson",data:s.geojson}),i._addLayers(s,l),i}},{"../../plots/mapbox/constants":611,"./convert":764}],770:[function(t,e,r){"use strict";var n=t("../../lib");e.exports=function(t,e){for(var r=0;r<t.length;r++)t[r].i=r;n.mergeArray(e.text,t,"tx"),n.mergeArray(e.hovertext,t,"htx");var i=e.marker;if(i){n.mergeArray(i.opacity,t,"mo"),n.mergeArray(i.color,t,"mc");var a=i.line;a&&(n.mergeArray(a.color,t,"mlc"),n.mergeArrayCastPositive(a.width,t,"mlw"))}}},{"../../lib":503}],771:[function(t,e,r){"use strict";var n,i=t("../bar/attributes"),a=t("../scatter/attributes").line,o=t("../../plots/attributes"),s=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,l=t("../../plots/template_attributes").hovertemplateAttrs,c=t("../../plots/template_attributes").texttemplateAttrs,u=t("./constants"),f=t("../../lib/extend").extendFlat,h=t("../../components/color");e.exports={x:i.x,x0:i.x0,dx:i.dx,y:i.y,y0:i.y0,dy:i.dy,xperiod:i.xperiod,yperiod:i.yperiod,xperiod0:i.xperiod0,yperiod0:i.yperiod0,xperiodalignment:i.xperiodalignment,yperiodalignment:i.yperiodalignment,xhoverformat:s("x"),yhoverformat:s("y"),hovertext:i.hovertext,hovertemplate:l({},{keys:u.eventDataKeys}),hoverinfo:f({},o.hoverinfo,{flags:["name","x","y","text","percent initial","percent previous","percent total"]}),textinfo:{valType:"flaglist",flags:["label","text","percent initial","percent previous","percent total","value"],extras:["none"],editType:"plot",arrayOk:!1},texttemplate:c({editType:"plot"},{keys:u.eventDataKeys.concat(["label","value"])}),text:i.text,textposition:i.textposition,insidetextanchor:f({},i.insidetextanchor,{dflt:"middle"}),textangle:f({},i.textangle,{dflt:0}),textfont:i.textfont,insidetextfont:i.insidetextfont,outsidetextfont:i.outsidetextfont,constraintext:i.constraintext,cliponaxis:i.cliponaxis,orientation:f({},i.orientation,{}),offset:f({},i.offset,{arrayOk:!1}),width:f({},i.width,{arrayOk:!1}),marker:(n=f({},i.marker),delete n.pattern,n),connector:{fillcolor:{valType:"color",editType:"style"},line:{color:f({},a.color,{dflt:h.defaultLine}),width:f({},a.width,{dflt:0,editType:"plot"}),dash:a.dash,editType:"style"},visible:{valType:"boolean",dflt:!0,editType:"plot"},editType:"plot"},offsetgroup:i.offsetgroup,alignmentgroup:i.alignmentgroup}},{"../../components/color":366,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/cartesian/axis_format_attributes":557,"../../plots/template_attributes":633,"../bar/attributes":648,"../scatter/attributes":927,"./constants":773}],772:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes"),i=t("../../plots/cartesian/align_period"),a=t("./arrays_to_calcdata"),o=t("../scatter/calc_selection"),s=t("../../constants/numerical").BADNUM;function l(t){return t===s?0:t}e.exports=function(t,e){var r,c,u,f,h,p,d,m,g=n.getFromId(t,e.xaxis||"x"),v=n.getFromId(t,e.yaxis||"y");"h"===e.orientation?(r=g.makeCalcdata(e,"x"),u=v.makeCalcdata(e,"y"),f=i(e,v,"y",u),h=!!e.yperiodalignment,p="y"):(r=v.makeCalcdata(e,"y"),u=g.makeCalcdata(e,"x"),f=i(e,g,"x",u),h=!!e.xperiodalignment,p="x"),c=f.vals;var y,x=Math.min(c.length,r.length),b=new Array(x);for(e._base=[],d=0;d<x;d++){r[d]<0&&(r[d]=s);var _=!1;r[d]!==s&&d+1<x&&r[d+1]!==s&&(_=!0),m=b[d]={p:c[d],s:r[d],cNext:_},e._base[d]=-.5*m.s,h&&(b[d].orig_p=u[d],b[d][p+"End"]=f.ends[d],b[d][p+"Start"]=f.starts[d]),e.ids&&(m.id=String(e.ids[d])),0===d&&(b[0].vTotal=0),b[0].vTotal+=l(m.s),m.begR=l(m.s)/l(b[0].s)}for(d=0;d<x;d++)(m=b[d]).s!==s&&(m.sumR=m.s/b[0].vTotal,m.difR=void 0!==y?m.s/y:1,y=m.s);return a(b,e),o(b,e),b}},{"../../constants/numerical":479,"../../plots/cartesian/align_period":551,"../../plots/cartesian/axes":554,"../scatter/calc_selection":929,"./arrays_to_calcdata":770}],773:[function(t,e,r){"use strict";e.exports={eventDataKeys:["percentInitial","percentPrevious","percentTotal"]}},{}],774:[function(t,e,r){"use strict";var n=t("../bar/cross_trace_calc").setGroupPositions;e.exports=function(t,e){var r,i,a=t._fullLayout,o=t._fullData,s=t.calcdata,l=e.xaxis,c=e.yaxis,u=[],f=[],h=[];for(i=0;i<o.length;i++){var p=o[i],d="h"===p.orientation;!0===p.visible&&p.xaxis===l._id&&p.yaxis===c._id&&"funnel"===p.type&&(r=s[i],d?h.push(r):f.push(r),u.push(r))}var m={mode:a.funnelmode,norm:a.funnelnorm,gap:a.funnelgap,groupgap:a.funnelgroupgap};for(n(t,l,c,f,m),n(t,c,l,h,m),i=0;i<u.length;i++){r=u[i];for(var g=0;g<r.length;g++)g+1<r.length&&(r[g].nextP0=r[g+1].p0,r[g].nextS0=r[g+1].s0,r[g].nextP1=r[g+1].p1,r[g].nextS1=r[g+1].s1)}}},{"../bar/cross_trace_calc":651}],775:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../bar/defaults").handleGroupingDefaults,a=t("../bar/defaults").handleText,o=t("../scatter/xy_defaults"),s=t("../scatter/period_defaults"),l=t("./attributes"),c=t("../../components/color");e.exports={supplyDefaults:function(t,e,r,i){function u(r,i){return n.coerce(t,e,l,r,i)}if(o(t,e,i,u)){s(t,e,i,u),u("xhoverformat"),u("yhoverformat"),u("orientation",e.y&&!e.x?"v":"h"),u("offset"),u("width");var f=u("text");u("hovertext"),u("hovertemplate");var h=u("textposition");a(t,e,i,u,h,{moduleHasSelected:!1,moduleHasUnselected:!1,moduleHasConstrain:!0,moduleHasCliponaxis:!0,moduleHasTextangle:!0,moduleHasInsideanchor:!0}),"none"===e.textposition||e.texttemplate||u("textinfo",Array.isArray(f)?"text+value":"value");var p=u("marker.color",r);if(u("marker.line.color",c.defaultLine),u("marker.line.width"),u("connector.visible"))u("connector.fillcolor",function(t){var e=n.isArrayOrTypedArray(t)?"#000":t;return c.addOpacity(e,.5*c.opacity(e))}(p)),u("connector.line.width")&&(u("connector.line.color"),u("connector.line.dash"))}else e.visible=!1},crossTraceDefaults:function(t,e){var r,a;function o(t){return n.coerce(a._input,a,l,t)}if("group"===e.funnelmode)for(var s=0;s<t.length;s++)r=(a=t[s])._input,i(r,a,e,o)}}},{"../../components/color":366,"../../lib":503,"../bar/defaults":652,"../scatter/period_defaults":947,"../scatter/xy_defaults":954,"./attributes":771}],776:[function(t,e,r){"use strict";e.exports=function(t,e){return t.x="xVal"in e?e.xVal:e.x,t.y="yVal"in e?e.yVal:e.y,"percentInitial"in e&&(t.percentInitial=e.percentInitial),"percentPrevious"in e&&(t.percentPrevious=e.percentPrevious),"percentTotal"in e&&(t.percentTotal=e.percentTotal),e.xa&&(t.xaxis=e.xa),e.ya&&(t.yaxis=e.ya),t}},{}],777:[function(t,e,r){"use strict";var n=t("../../components/color").opacity,i=t("../bar/hover").hoverOnBars,a=t("../../lib").formatPercent;e.exports=function(t,e,r,o,s){var l=i(t,e,r,o,s);if(l){var c=l.cd,u=c[0].trace,f="h"===u.orientation,h=c[l.index];l[(f?"x":"y")+"LabelVal"]=h.s,l.percentInitial=h.begR,l.percentInitialLabel=a(h.begR,1),l.percentPrevious=h.difR,l.percentPreviousLabel=a(h.difR,1),l.percentTotal=h.sumR,l.percentTotalLabel=a(h.sumR,1);var p=h.hi||u.hoverinfo,d=[];if(p&&"none"!==p&&"skip"!==p){var m="all"===p,g=p.split("+"),v=function(t){return m||-1!==g.indexOf(t)};v("percent initial")&&d.push(l.percentInitialLabel+" of initial"),v("percent previous")&&d.push(l.percentPreviousLabel+" of previous"),v("percent total")&&d.push(l.percentTotalLabel+" of total")}return l.extraText=d.join("<br>"),l.color=function(t,e){var r=t.marker,i=e.mc||r.color,a=e.mlc||r.line.color,o=e.mlw||r.line.width;if(n(i))return i;if(n(a)&&o)return a}(u,h),[l]}}},{"../../components/color":366,"../../lib":503,"../bar/hover":655}],778:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),layoutAttributes:t("./layout_attributes"),supplyDefaults:t("./defaults").supplyDefaults,crossTraceDefaults:t("./defaults").crossTraceDefaults,supplyLayoutDefaults:t("./layout_defaults"),calc:t("./calc"),crossTraceCalc:t("./cross_trace_calc"),plot:t("./plot"),style:t("./style").style,hoverPoints:t("./hover"),eventData:t("./event_data"),selectPoints:t("../bar/select"),moduleType:"trace",name:"funnel",basePlotModule:t("../../plots/cartesian"),categories:["bar-like","cartesian","svg","oriented","showLegend","zoomScale"],meta:{}}},{"../../plots/cartesian":568,"../bar/select":660,"./attributes":771,"./calc":772,"./cross_trace_calc":774,"./defaults":775,"./event_data":776,"./hover":777,"./layout_attributes":779,"./layout_defaults":780,"./plot":781,"./style":782}],779:[function(t,e,r){"use strict";e.exports={funnelmode:{valType:"enumerated",values:["stack","group","overlay"],dflt:"stack",editType:"calc"},funnelgap:{valType:"number",min:0,max:1,editType:"calc"},funnelgroupgap:{valType:"number",min:0,max:1,dflt:0,editType:"calc"}}},{}],780:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./layout_attributes");e.exports=function(t,e,r){var a=!1;function o(r,a){return n.coerce(t,e,i,r,a)}for(var s=0;s<r.length;s++){var l=r[s];if(l.visible&&"funnel"===l.type){a=!0;break}}a&&(o("funnelmode"),o("funnelgap",.2),o("funnelgroupgap"))}},{"../../lib":503,"./layout_attributes":779}],781:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../../components/drawing"),o=t("../../constants/numerical").BADNUM,s=t("../bar/plot"),l=t("../bar/uniform_text").clearMinTextSize;function c(t,e,r,n){var i=[],a=[],o=n?e:r,s=n?r:e;return i[0]=o.c2p(t.s0,!0),a[0]=s.c2p(t.p0,!0),i[1]=o.c2p(t.s1,!0),a[1]=s.c2p(t.p1,!0),i[2]=o.c2p(t.nextS0,!0),a[2]=s.c2p(t.nextP0,!0),i[3]=o.c2p(t.nextS1,!0),a[3]=s.c2p(t.nextP1,!0),n?[i,a]:[a,i]}e.exports=function(t,e,r,u){var f=t._fullLayout;l("funnel",f),function(t,e,r,s){var l=e.xaxis,u=e.yaxis;i.makeTraceGroups(s,r,"trace bars").each((function(r){var s=n.select(this),f=r[0].trace,h=i.ensureSingle(s,"g","regions");if(f.connector&&f.connector.visible){var p="h"===f.orientation,d=h.selectAll("g.region").data(i.identity);d.enter().append("g").classed("region",!0),d.exit().remove();var m=d.size();d.each((function(r,s){if(s===m-1||r.cNext){var f=c(r,l,u,p),h=f[0],d=f[1],g="";h[0]!==o&&d[0]!==o&&h[1]!==o&&d[1]!==o&&h[2]!==o&&d[2]!==o&&h[3]!==o&&d[3]!==o&&(g+=p?"M"+h[0]+","+d[1]+"L"+h[2]+","+d[2]+"H"+h[3]+"L"+h[1]+","+d[1]+"Z":"M"+h[1]+","+d[1]+"L"+h[2]+","+d[3]+"V"+d[2]+"L"+h[1]+","+d[0]+"Z"),""===g&&(g="M0,0Z"),i.ensureSingle(n.select(this),"path").attr("d",g).call(a.setClipUrl,e.layerClipId,t)}}))}else h.remove()}))}(t,e,r,u),function(t,e,r,o){var s=e.xaxis,l=e.yaxis;i.makeTraceGroups(o,r,"trace bars").each((function(r){var o=n.select(this),u=r[0].trace,f=i.ensureSingle(o,"g","lines");if(u.connector&&u.connector.visible&&u.connector.line.width){var h="h"===u.orientation,p=f.selectAll("g.line").data(i.identity);p.enter().append("g").classed("line",!0),p.exit().remove();var d=p.size();p.each((function(r,o){if(o===d-1||r.cNext){var u=c(r,s,l,h),f=u[0],p=u[1],m="";void 0!==f[3]&&void 0!==p[3]&&(h?(m+="M"+f[0]+","+p[1]+"L"+f[2]+","+p[2],m+="M"+f[1]+","+p[1]+"L"+f[3]+","+p[2]):(m+="M"+f[1]+","+p[1]+"L"+f[2]+","+p[3],m+="M"+f[1]+","+p[0]+"L"+f[2]+","+p[2])),""===m&&(m="M0,0Z"),i.ensureSingle(n.select(this),"path").attr("d",m).call(a.setClipUrl,e.layerClipId,t)}}))}else f.remove()}))}(t,e,r,u),s.plot(t,e,r,u,{mode:f.funnelmode,norm:f.funnelmode,gap:f.funnelgap,groupgap:f.funnelgroupgap})}},{"../../components/drawing":388,"../../constants/numerical":479,"../../lib":503,"../bar/plot":659,"../bar/uniform_text":664,"@plotly/d3":58}],782:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/drawing"),a=t("../../components/color"),o=t("../../constants/interactions").DESELECTDIM,s=t("../bar/style"),l=t("../bar/uniform_text").resizeText,c=s.styleTextPoints;e.exports={style:function(t,e,r){var s=r||n.select(t).selectAll("g.funnellayer").selectAll("g.trace");l(t,s,"funnel"),s.style("opacity",(function(t){return t[0].trace.opacity})),s.each((function(e){var r=n.select(this),s=e[0].trace;r.selectAll(".point > path").each((function(t){if(!t.isBlank){var e=s.marker;n.select(this).call(a.fill,t.mc||e.color).call(a.stroke,t.mlc||e.line.color).call(i.dashLine,e.line.dash,t.mlw||e.line.width).style("opacity",s.selectedpoints&&!t.selected?o:1)}})),c(r,s,t),r.selectAll(".regions").each((function(){n.select(this).selectAll("path").style("stroke-width",0).call(a.fill,s.connector.fillcolor)})),r.selectAll(".lines").each((function(){var t=s.connector.line;i.lineGroupStyle(n.select(this).selectAll("path"),t.width,t.color,t.dash)}))}))}}},{"../../components/color":366,"../../components/drawing":388,"../../constants/interactions":478,"../bar/style":662,"../bar/uniform_text":664,"@plotly/d3":58}],783:[function(t,e,r){"use strict";var n=t("../pie/attributes"),i=t("../../plots/attributes"),a=t("../../plots/domain").attributes,o=t("../../plots/template_attributes").hovertemplateAttrs,s=t("../../plots/template_attributes").texttemplateAttrs,l=t("../../lib/extend").extendFlat;e.exports={labels:n.labels,label0:n.label0,dlabel:n.dlabel,values:n.values,marker:{colors:n.marker.colors,line:{color:l({},n.marker.line.color,{dflt:null}),width:l({},n.marker.line.width,{dflt:1}),editType:"calc"},editType:"calc"},text:n.text,hovertext:n.hovertext,scalegroup:l({},n.scalegroup,{}),textinfo:l({},n.textinfo,{flags:["label","text","value","percent"]}),texttemplate:s({editType:"plot"},{keys:["label","color","value","text","percent"]}),hoverinfo:l({},i.hoverinfo,{flags:["label","text","value","percent","name"]}),hovertemplate:o({},{keys:["label","color","value","text","percent"]}),textposition:l({},n.textposition,{values:["inside","none"],dflt:"inside"}),textfont:n.textfont,insidetextfont:n.insidetextfont,title:{text:n.title.text,font:n.title.font,position:l({},n.title.position,{values:["top left","top center","top right"],dflt:"top center"}),editType:"plot"},domain:a({name:"funnelarea",trace:!0,editType:"calc"}),aspectratio:{valType:"number",min:0,dflt:1,editType:"plot"},baseratio:{valType:"number",min:0,max:1,dflt:.333,editType:"plot"}}},{"../../lib/extend":493,"../../plots/attributes":550,"../../plots/domain":584,"../../plots/template_attributes":633,"../pie/attributes":901}],784:[function(t,e,r){"use strict";var n=t("../../plots/plots");r.name="funnelarea",r.plot=function(t,e,i,a){n.plotBasePlot(r.name,t,e,i,a)},r.clean=function(t,e,i,a){n.cleanBasePlot(r.name,t,e,i,a)}},{"../../plots/plots":619}],785:[function(t,e,r){"use strict";var n=t("../pie/calc");e.exports={calc:function(t,e){return n.calc(t,e)},crossTraceCalc:function(t){n.crossTraceCalc(t,{type:"funnelarea"})}}},{"../pie/calc":903}],786:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./attributes"),a=t("../../plots/domain").defaults,o=t("../bar/defaults").handleText,s=t("../pie/defaults").handleLabelsAndValues;e.exports=function(t,e,r,l){function c(r,a){return n.coerce(t,e,i,r,a)}var u=c("labels"),f=c("values"),h=s(u,f),p=h.len;if(e._hasLabels=h.hasLabels,e._hasValues=h.hasValues,!e._hasLabels&&e._hasValues&&(c("label0"),c("dlabel")),p){e._length=p,c("marker.line.width")&&c("marker.line.color",l.paper_bgcolor),c("marker.colors"),c("scalegroup");var d,m=c("text"),g=c("texttemplate");if(g||(d=c("textinfo",Array.isArray(m)?"text+percent":"percent")),c("hovertext"),c("hovertemplate"),g||d&&"none"!==d){var v=c("textposition");o(t,e,l,c,v,{moduleHasSelected:!1,moduleHasUnselected:!1,moduleHasConstrain:!1,moduleHasCliponaxis:!1,moduleHasTextangle:!1,moduleHasInsideanchor:!1})}a(e,l,c),c("title.text")&&(c("title.position"),n.coerceFont(c,"title.font",l.font)),c("aspectratio"),c("baseratio")}else e.visible=!1}},{"../../lib":503,"../../plots/domain":584,"../bar/defaults":652,"../pie/defaults":904,"./attributes":783}],787:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"funnelarea",basePlotModule:t("./base_plot"),categories:["pie-like","funnelarea","showLegend"],attributes:t("./attributes"),layoutAttributes:t("./layout_attributes"),supplyDefaults:t("./defaults"),supplyLayoutDefaults:t("./layout_defaults"),calc:t("./calc").calc,crossTraceCalc:t("./calc").crossTraceCalc,plot:t("./plot"),style:t("./style"),styleOne:t("../pie/style_one"),meta:{}}},{"../pie/style_one":912,"./attributes":783,"./base_plot":784,"./calc":785,"./defaults":786,"./layout_attributes":788,"./layout_defaults":789,"./plot":790,"./style":791}],788:[function(t,e,r){"use strict";var n=t("../pie/layout_attributes").hiddenlabels;e.exports={hiddenlabels:n,funnelareacolorway:{valType:"colorlist",editType:"calc"},extendfunnelareacolors:{valType:"boolean",dflt:!0,editType:"calc"}}},{"../pie/layout_attributes":908}],789:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./layout_attributes");e.exports=function(t,e){function r(r,a){return n.coerce(t,e,i,r,a)}r("hiddenlabels"),r("funnelareacolorway",e.colorway),r("extendfunnelareacolors")}},{"../../lib":503,"./layout_attributes":788}],790:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/drawing"),a=t("../../lib"),o=a.strScale,s=a.strTranslate,l=t("../../lib/svg_text_utils"),c=t("../bar/plot").toMoveInsideBar,u=t("../bar/uniform_text"),f=u.recordMinTextSize,h=u.clearMinTextSize,p=t("../pie/helpers"),d=t("../pie/plot"),m=d.attachFxHandlers,g=d.determineInsideTextFont,v=d.layoutAreas,y=d.prerenderTitles,x=d.positionTitleOutside,b=d.formatSliceLabel;function _(t,e){return"l"+(e[0]-t[0])+","+(e[1]-t[1])}e.exports=function(t,e){var r=t._fullLayout;h("funnelarea",r),y(e,t),v(e,r._size),a.makeTraceGroups(r._funnelarealayer,e,"trace").each((function(e){var u=n.select(this),h=e[0],d=h.trace;!function(t){if(!t.length)return;var e=t[0],r=e.trace,n=r.aspectratio,i=r.baseratio;i>.999&&(i=.999);var a,o=Math.pow(i,2),s=e.vTotal,l=s,c=s*o/(1-o)/s;function u(){var t,e={x:t=Math.sqrt(c),y:-t};return[e.x,e.y]}var f,h,p=[];for(p.push(u()),f=t.length-1;f>-1;f--)if(!(h=t[f]).hidden){var d=h.v/l;c+=d,p.push(u())}var m=1/0,g=-1/0;for(f=0;f<p.length;f++)a=p[f],m=Math.min(m,a[1]),g=Math.max(g,a[1]);for(f=0;f<p.length;f++)p[f][1]-=(g+m)/2;var v=p[p.length-1][0],y=e.r,x=(g-m)/2,b=y/v,_=y/x*n;for(e.r=_*x,f=0;f<p.length;f++)p[f][0]*=b,p[f][1]*=_;var w=[-(a=p[0])[0],a[1]],T=[a[0],a[1]],k=0;for(f=t.length-1;f>-1;f--)if(!(h=t[f]).hidden){var A=p[k+=1][0],M=p[k][1];h.TL=[-A,M],h.TR=[A,M],h.BL=w,h.BR=T,h.pxmid=(S=h.TR,E=h.BR,[.5*(S[0]+E[0]),.5*(S[1]+E[1])]),w=h.TL,T=h.TR}var S,E}(e),u.each((function(){var u=n.select(this).selectAll("g.slice").data(e);u.enter().append("g").classed("slice",!0),u.exit().remove(),u.each((function(o,s){if(o.hidden)n.select(this).selectAll("path,g").remove();else{o.pointNumber=o.i,o.curveNumber=d.index;var u=h.cx,v=h.cy,y=n.select(this),x=y.selectAll("path.surface").data([o]);x.enter().append("path").classed("surface",!0).style({"pointer-events":"all"}),y.call(m,t,e);var w="M"+(u+o.TR[0])+","+(v+o.TR[1])+_(o.TR,o.BR)+_(o.BR,o.BL)+_(o.BL,o.TL)+"Z";x.attr("d",w),b(t,o,h);var T=p.castOption(d.textposition,o.pts),k=y.selectAll("g.slicetext").data(o.text&&"none"!==T?[0]:[]);k.enter().append("g").classed("slicetext",!0),k.exit().remove(),k.each((function(){var h=a.ensureSingle(n.select(this),"text","",(function(t){t.attr("data-notex",1)})),p=a.ensureUniformFontSize(t,g(d,o,r.font));h.text(o.text).attr({class:"slicetext",transform:"","text-anchor":"middle"}).call(i.font,p).call(l.convertToTspans,t);var m,y,x,b=i.bBox(h.node()),_=Math.min(o.BL[1],o.BR[1])+v,w=Math.max(o.TL[1],o.TR[1])+v;y=Math.max(o.TL[0],o.BL[0])+u,x=Math.min(o.TR[0],o.BR[0])+u,(m=c(y,x,_,w,b,{isHorizontal:!0,constrained:!0,angle:0,anchor:"middle"})).fontSize=p.size,f(d.type,m,r),e[s].transform=m,h.attr("transform",a.getTextTransform(m))}))}}));var v=n.select(this).selectAll("g.titletext").data(d.title.text?[0]:[]);v.enter().append("g").classed("titletext",!0),v.exit().remove(),v.each((function(){var e=a.ensureSingle(n.select(this),"text","",(function(t){t.attr("data-notex",1)})),c=d.title.text;d._meta&&(c=a.templateString(c,d._meta)),e.text(c).attr({class:"titletext",transform:"","text-anchor":"middle"}).call(i.font,d.title.font).call(l.convertToTspans,t);var u=x(h,r._size);e.attr("transform",s(u.x,u.y)+o(Math.min(1,u.scale))+s(u.tx,u.ty))}))}))}))}},{"../../components/drawing":388,"../../lib":503,"../../lib/svg_text_utils":529,"../bar/plot":659,"../bar/uniform_text":664,"../pie/helpers":906,"../pie/plot":910,"@plotly/d3":58}],791:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../pie/style_one"),a=t("../bar/uniform_text").resizeText;e.exports=function(t){var e=t._fullLayout._funnelarealayer.selectAll(".trace");a(t,e,"funnelarea"),e.each((function(t){var e=t[0].trace,r=n.select(this);r.style({opacity:e.opacity}),r.selectAll("path.surface").each((function(t){n.select(this).call(i,t,e)}))}))}},{"../bar/uniform_text":664,"../pie/style_one":912,"@plotly/d3":58}],792:[function(t,e,r){"use strict";var n=t("../scatter/attributes"),i=t("../../plots/attributes"),a=t("../../plots/font_attributes"),o=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,s=t("../../plots/template_attributes").hovertemplateAttrs,l=t("../../plots/template_attributes").texttemplateAttrs,c=t("../../components/colorscale/attributes"),u=t("../../lib/extend").extendFlat;e.exports=u({z:{valType:"data_array",editType:"calc"},x:u({},n.x,{impliedEdits:{xtype:"array"}}),x0:u({},n.x0,{impliedEdits:{xtype:"scaled"}}),dx:u({},n.dx,{impliedEdits:{xtype:"scaled"}}),y:u({},n.y,{impliedEdits:{ytype:"array"}}),y0:u({},n.y0,{impliedEdits:{ytype:"scaled"}}),dy:u({},n.dy,{impliedEdits:{ytype:"scaled"}}),xperiod:u({},n.xperiod,{impliedEdits:{xtype:"scaled"}}),yperiod:u({},n.yperiod,{impliedEdits:{ytype:"scaled"}}),xperiod0:u({},n.xperiod0,{impliedEdits:{xtype:"scaled"}}),yperiod0:u({},n.yperiod0,{impliedEdits:{ytype:"scaled"}}),xperiodalignment:u({},n.xperiodalignment,{impliedEdits:{xtype:"scaled"}}),yperiodalignment:u({},n.yperiodalignment,{impliedEdits:{ytype:"scaled"}}),text:{valType:"data_array",editType:"calc"},hovertext:{valType:"data_array",editType:"calc"},transpose:{valType:"boolean",dflt:!1,editType:"calc"},xtype:{valType:"enumerated",values:["array","scaled"],editType:"calc+clearAxisTypes"},ytype:{valType:"enumerated",values:["array","scaled"],editType:"calc+clearAxisTypes"},zsmooth:{valType:"enumerated",values:["fast","best",!1],dflt:!1,editType:"calc"},hoverongaps:{valType:"boolean",dflt:!0,editType:"none"},connectgaps:{valType:"boolean",editType:"calc"},xgap:{valType:"number",dflt:0,min:0,editType:"plot"},ygap:{valType:"number",dflt:0,min:0,editType:"plot"},xhoverformat:o("x"),yhoverformat:o("y"),zhoverformat:o("z",1),hovertemplate:s(),texttemplate:l({arrayOk:!1,editType:"plot"},{keys:["x","y","z","text"]}),textfont:a({editType:"plot",autoSize:!0,autoColor:!0,colorEditType:"style"}),showlegend:u({},i.showlegend,{dflt:!1})},{transforms:void 0},c("",{cLetter:"z",autoColorDflt:!1}))},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/cartesian/axis_format_attributes":557,"../../plots/font_attributes":585,"../../plots/template_attributes":633,"../scatter/attributes":927}],793:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib"),a=t("../../plots/cartesian/axes"),o=t("../../plots/cartesian/align_period"),s=t("../histogram2d/calc"),l=t("../../components/colorscale/calc"),c=t("./convert_column_xyz"),u=t("./clean_2d_array"),f=t("./interp2d"),h=t("./find_empties"),p=t("./make_bound_array"),d=t("../../constants/numerical").BADNUM;function m(t){for(var e=[],r=t.length,n=0;n<r;n++){var i=t[n];i!==d&&e.push(i)}return e}e.exports=function(t,e){var r,g,v,y,x,b,_,w,T,k,A,M=a.getFromId(t,e.xaxis||"x"),S=a.getFromId(t,e.yaxis||"y"),E=n.traceIs(e,"contour"),L=n.traceIs(e,"histogram"),C=n.traceIs(e,"gl2d"),P=E?"best":e.zsmooth;if(M._minDtick=0,S._minDtick=0,L)y=(A=s(t,e)).orig_x,r=A.x,g=A.x0,v=A.dx,w=A.orig_y,x=A.y,b=A.y0,_=A.dy,T=A.z;else{var I=e.z;i.isArray1D(I)?(c(e,M,S,"x","y",["z"]),r=e._x,x=e._y,I=e._z):(y=e.x?M.makeCalcdata(e,"x"):[],w=e.y?S.makeCalcdata(e,"y"):[],r=o(e,M,"x",y).vals,x=o(e,S,"y",w).vals,e._x=r,e._y=x),g=e.x0,v=e.dx,b=e.y0,_=e.dy,T=u(I,e,M,S)}function O(t){P=e._input.zsmooth=e.zsmooth=!1,i.warn('cannot use zsmooth: "fast": '+t)}if((M.rangebreaks||S.rangebreaks)&&(T=function(t,e,r){for(var n=[],i=-1,a=0;a<r.length;a++)if(e[a]!==d){i++,n[i]=[];for(var o=0;o<r[a].length;o++)t[o]!==d&&n[i].push(r[a][o])}return n}(r,x,T),L||(r=m(r),x=m(x),e._x=r,e._y=x)),L||!E&&!e.connectgaps||(e._emptypoints=h(T),f(T,e._emptypoints)),"fast"===P)if("log"===M.type||"log"===S.type)O("log axis found");else if(!L){if(r.length){var z=(r[r.length-1]-r[0])/(r.length-1),D=Math.abs(z/100);for(k=0;k<r.length-1;k++)if(Math.abs(r[k+1]-r[k]-z)>D){O("x scale is not linear");break}}if(x.length&&"fast"===P){var R=(x[x.length-1]-x[0])/(x.length-1),F=Math.abs(R/100);for(k=0;k<x.length-1;k++)if(Math.abs(x[k+1]-x[k]-R)>F){O("y scale is not linear");break}}}var B=i.maxRowLength(T),N="scaled"===e.xtype?"":r,j=p(e,N,g,v,B,M),U="scaled"===e.ytype?"":x,V=p(e,U,b,_,T.length,S);C||(e._extremes[M._id]=a.findExtremes(M,j),e._extremes[S._id]=a.findExtremes(S,V));var H={x:j,y:V,z:T,text:e._text||e.text,hovertext:e._hovertext||e.hovertext};if(e.xperiodalignment&&y&&(H.orig_x=y),e.yperiodalignment&&w&&(H.orig_y=w),N&&N.length===j.length-1&&(H.xCenter=N),U&&U.length===V.length-1&&(H.yCenter=U),L&&(H.xRanges=A.xRanges,H.yRanges=A.yRanges,H.pts=A.pts),E||l(t,e,{vals:T,cLetter:"z"}),E&&e.contours&&"heatmap"===e.contours.coloring){var q={type:"contour"===e.type?"heatmap":"histogram2d",xcalendar:e.xcalendar,ycalendar:e.ycalendar};H.xfill=p(q,N,g,v,B,M),H.yfill=p(q,U,b,_,T.length,S)}return[H]}},{"../../components/colorscale/calc":374,"../../constants/numerical":479,"../../lib":503,"../../plots/cartesian/align_period":551,"../../plots/cartesian/axes":554,"../../registry":638,"../histogram2d/calc":826,"./clean_2d_array":794,"./convert_column_xyz":796,"./find_empties":798,"./interp2d":801,"./make_bound_array":803}],794:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=t("../../constants/numerical").BADNUM;e.exports=function(t,e,r,o){var s,l,c,u,f,h;function p(t){if(n(t))return+t}if(e&&e.transpose){for(s=0,f=0;f<t.length;f++)s=Math.max(s,t[f].length);if(0===s)return!1;c=function(t){return t.length},u=function(t,e,r){return(t[r]||[])[e]}}else s=t.length,c=function(t,e){return t[e].length},u=function(t,e,r){return(t[e]||[])[r]};var d=function(t,e,r){return e===a||r===a?a:u(t,e,r)};function m(t){if(e&&"carpet"!==e.type&&"contourcarpet"!==e.type&&t&&"category"===t.type&&e["_"+t._id.charAt(0)].length){var r=t._id.charAt(0),n={},o=e["_"+r+"CategoryMap"]||e[r];for(f=0;f<o.length;f++)n[o[f]]=f;return function(e){var r=n[t._categories[e]];return r+1?r:a}}return i.identity}var g=m(r),v=m(o);o&&"category"===o.type&&(s=o._categories.length);var y=new Array(s);for(f=0;f<s;f++)for(l=r&&"category"===r.type?r._categories.length:c(t,f),y[f]=new Array(l),h=0;h<l;h++)y[f][h]=p(d(t,v(f),g(h)));return y}},{"../../constants/numerical":479,"../../lib":503,"fast-isnumeric":190}],795:[function(t,e,r){"use strict";e.exports={min:"zmin",max:"zmax"}},{}],796:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../constants/numerical").BADNUM,a=t("../../plots/cartesian/align_period");e.exports=function(t,e,r,o,s,l){var c=t._length,u=e.makeCalcdata(t,o),f=r.makeCalcdata(t,s);u=a(t,e,o,u).vals,f=a(t,r,s,f).vals;var h,p,d,m,g=t.text,v=void 0!==g&&n.isArray1D(g),y=t.hovertext,x=void 0!==y&&n.isArray1D(y),b=n.distinctVals(u),_=b.vals,w=n.distinctVals(f),T=w.vals,k=[],A=T.length,M=_.length;for(h=0;h<l.length;h++)k[h]=n.init2dArray(A,M);v&&(d=n.init2dArray(A,M)),x&&(m=n.init2dArray(A,M));var S=n.init2dArray(A,M);for(h=0;h<c;h++)if(u[h]!==i&&f[h]!==i){var E=n.findBin(u[h]+b.minDiff/2,_),L=n.findBin(f[h]+w.minDiff/2,T);for(p=0;p<l.length;p++){var C=t[l[p]];k[p][L][E]=C[h],S[L][E]=h}v&&(d[L][E]=g[h]),x&&(m[L][E]=y[h])}for(t["_"+o]=_,t["_"+s]=T,p=0;p<l.length;p++)t["_"+l[p]]=k[p];v&&(t._text=d),x&&(t._hovertext=m),e&&"category"===e.type&&(t["_"+o+"CategoryMap"]=_.map((function(t){return e._categories[t]}))),r&&"category"===r.type&&(t["_"+s+"CategoryMap"]=T.map((function(t){return r._categories[t]}))),t._after2before=S}},{"../../constants/numerical":479,"../../lib":503,"../../plots/cartesian/align_period":551}],797:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./xyz_defaults"),a=t("./label_defaults"),o=t("../scatter/period_defaults"),s=t("./style_defaults"),l=t("../../components/colorscale/defaults"),c=t("./attributes");e.exports=function(t,e,r,u){function f(r,i){return n.coerce(t,e,c,r,i)}i(t,e,f,u)?(o(t,e,u,f),f("xhoverformat"),f("yhoverformat"),f("text"),f("hovertext"),f("hovertemplate"),a(f,u),s(t,e,f,u),f("hoverongaps"),f("connectgaps",n.isArray1D(e.z)&&!1!==e.zsmooth),l(t,e,u,f,{prefix:"",cLetter:"z"})):e.visible=!1}},{"../../components/colorscale/defaults":376,"../../lib":503,"../scatter/period_defaults":947,"./attributes":792,"./label_defaults":802,"./style_defaults":806,"./xyz_defaults":807}],798:[function(t,e,r){"use strict";var n=t("../../lib").maxRowLength;e.exports=function(t){var e,r,i,a,o,s,l,c,u=[],f={},h=[],p=t[0],d=[],m=[0,0,0],g=n(t);for(r=0;r<t.length;r++)for(e=d,d=p,p=t[r+1]||[],i=0;i<g;i++)void 0===d[i]&&((s=(void 0!==d[i-1]?1:0)+(void 0!==d[i+1]?1:0)+(void 0!==e[i]?1:0)+(void 0!==p[i]?1:0))?(0===r&&s++,0===i&&s++,r===t.length-1&&s++,i===d.length-1&&s++,s<4&&(f[[r,i]]=[r,i,s]),u.push([r,i,s])):h.push([r,i]));for(;h.length;){for(l={},c=!1,o=h.length-1;o>=0;o--)(s=((f[[(r=(a=h[o])[0])-1,i=a[1]]]||m)[2]+(f[[r+1,i]]||m)[2]+(f[[r,i-1]]||m)[2]+(f[[r,i+1]]||m)[2])/20)&&(l[a]=[r,i,s],h.splice(o,1),c=!0);if(!c)throw"findEmpties iterated with no new neighbors";for(a in l)f[a]=l[a],u.push(l[a])}return u.sort((function(t,e){return e[2]-t[2]}))}},{"../../lib":503}],799:[function(t,e,r){"use strict";var n=t("../../components/fx"),i=t("../../lib"),a=t("../../plots/cartesian/axes"),o=t("../../components/colorscale").extractOpts;e.exports=function(t,e,r,s,l){l||(l={});var c,u,f,h,p=l.isContour,d=t.cd[0],m=d.trace,g=t.xa,v=t.ya,y=d.x,x=d.y,b=d.z,_=d.xCenter,w=d.yCenter,T=d.zmask,k=m.zhoverformat,A=y,M=x;if(!1!==t.index){try{f=Math.round(t.index[1]),h=Math.round(t.index[0])}catch(e){return void i.error("Error hovering on heatmap, pointNumber must be [row,col], found:",t.index)}if(f<0||f>=b[0].length||h<0||h>b.length)return}else{if(n.inbox(e-y[0],e-y[y.length-1],0)>0||n.inbox(r-x[0],r-x[x.length-1],0)>0)return;if(p){var S;for(A=[2*y[0]-y[1]],S=1;S<y.length;S++)A.push((y[S]+y[S-1])/2);for(A.push([2*y[y.length-1]-y[y.length-2]]),M=[2*x[0]-x[1]],S=1;S<x.length;S++)M.push((x[S]+x[S-1])/2);M.push([2*x[x.length-1]-x[x.length-2]])}f=Math.max(0,Math.min(A.length-2,i.findBin(e,A))),h=Math.max(0,Math.min(M.length-2,i.findBin(r,M)))}var E,L,C=g.c2p(y[f]),P=g.c2p(y[f+1]),I=v.c2p(x[h]),O=v.c2p(x[h+1]);p?(E=d.orig_x||y,L=d.orig_y||x,P=C,c=E[f],O=I,u=L[h]):(E=d.orig_x||_||y,L=d.orig_y||w||x,c=_?E[f]:(E[f]+E[f+1])/2,u=w?L[h]:(L[h]+L[h+1])/2,g&&"category"===g.type&&(c=y[f]),v&&"category"===v.type&&(u=x[h]),m.zsmooth&&(C=P=g.c2p(c),I=O=v.c2p(u)));var z=b[h][f];if(T&&!T[h][f]&&(z=void 0),void 0!==z||m.hoverongaps){var D;Array.isArray(d.hovertext)&&Array.isArray(d.hovertext[h])?D=d.hovertext[h][f]:Array.isArray(d.text)&&Array.isArray(d.text[h])&&(D=d.text[h][f]);var R=o(m),F={type:"linear",range:[R.min,R.max],hoverformat:k,_separators:g._separators,_numFormat:g._numFormat},B=a.tickText(F,z,"hover").text;return[i.extendFlat(t,{index:m._after2before?m._after2before[h][f]:[h,f],distance:t.maxHoverDistance,spikeDistance:t.maxSpikeDistance,x0:C,x1:P,y0:I,y1:O,xLabelVal:c,yLabelVal:u,zLabelVal:z,zLabel:B,text:D})]}}},{"../../components/colorscale":378,"../../components/fx":406,"../../lib":503,"../../plots/cartesian/axes":554}],800:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),calc:t("./calc"),plot:t("./plot"),colorbar:t("./colorbar"),style:t("./style"),hoverPoints:t("./hover"),moduleType:"trace",name:"heatmap",basePlotModule:t("../../plots/cartesian"),categories:["cartesian","svg","2dMap","showLegend"],meta:{}}},{"../../plots/cartesian":568,"./attributes":792,"./calc":793,"./colorbar":795,"./defaults":797,"./hover":799,"./plot":804,"./style":805}],801:[function(t,e,r){"use strict";var n=t("../../lib"),i=[[-1,0],[1,0],[0,-1],[0,1]];function a(t){return.5-.25*Math.min(1,.5*t)}function o(t,e,r){var n,a,o,s,l,c,u,f,h,p,d,m,g,v=0;for(s=0;s<e.length;s++){for(a=(n=e[s])[0],o=n[1],d=t[a][o],p=0,h=0,l=0;l<4;l++)(u=t[a+(c=i[l])[0]])&&void 0!==(f=u[o+c[1]])&&(0===p?m=g=f:(m=Math.min(m,f),g=Math.max(g,f)),h++,p+=f);if(0===h)throw"iterateInterp2d order is wrong: no defined neighbors";t[a][o]=p/h,void 0===d?h<4&&(v=1):(t[a][o]=(1+r)*t[a][o]-r*d,g>m&&(v=Math.max(v,Math.abs(t[a][o]-d)/(g-m))))}return v}e.exports=function(t,e){var r,i=1;for(o(t,e),r=0;r<e.length&&!(e[r][2]<4);r++);for(e=e.slice(r),r=0;r<100&&i>.01;r++)i=o(t,e,a(i));return i>.01&&n.log("interp2d didn't converge quickly",i),t}},{"../../lib":503}],802:[function(t,e,r){"use strict";var n=t("../../lib");e.exports=function(t,e){t("texttemplate");var r=n.extendFlat({},e.font,{color:"auto",size:"auto"});n.coerceFont(t,"textfont",r)}},{"../../lib":503}],803:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib").isArrayOrTypedArray;e.exports=function(t,e,r,a,o,s){var l,c,u,f=[],h=n.traceIs(t,"contour"),p=n.traceIs(t,"histogram"),d=n.traceIs(t,"gl2d");if(i(e)&&e.length>1&&!p&&"category"!==s.type){var m=e.length;if(!(m<=o))return h?e.slice(0,o):e.slice(0,o+1);if(h||d)f=e.slice(0,o);else if(1===o)f=[e[0]-.5,e[0]+.5];else{for(f=[1.5*e[0]-.5*e[1]],u=1;u<m;u++)f.push(.5*(e[u-1]+e[u]));f.push(1.5*e[m-1]-.5*e[m-2])}if(m<o){var g=f[f.length-1],v=g-f[f.length-2];for(u=m;u<o;u++)g+=v,f.push(g)}}else{var y=t[s._id.charAt(0)+"calendar"];if(p)l=s.r2c(r,0,y);else if(i(e)&&1===e.length)l=e[0];else if(void 0===r)l=0;else{l=("log"===s.type?s.d2c:s.r2c)(r,0,y)}for(c=a||1,u=h||d?0:-.5;u<o;u++)f.push(l+c*u)}return f}},{"../../lib":503,"../../registry":638}],804:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("tinycolor2"),a=t("../../registry"),o=t("../../components/drawing"),s=t("../../plots/cartesian/axes"),l=t("../../lib"),c=t("../../lib/svg_text_utils"),u=t("../scatter/format_labels"),f=t("../../components/color"),h=t("../../components/colorscale").extractOpts,p=t("../../components/colorscale").makeColorScaleFuncFromTrace,d=t("../../constants/xmlns_namespaces"),m=t("../../constants/alignment").LINE_SPACING;function g(t){return t.selectAll("g.heatmap-label")}function v(t){g(t).remove()}function y(t,e){var r=e.length-2,n=l.constrain(l.findBin(t,e),0,r),i=e[n],a=e[n+1],o=l.constrain(n+(t-i)/(a-i)-.5,0,r),s=Math.round(o),c=Math.abs(o-s);return o&&o!==r&&c?{bin0:s,frac:c,bin1:Math.round(s+c/(o-s))}:{bin0:s,bin1:s,frac:0}}function x(t,e){var r=e.length-1,n=l.constrain(l.findBin(t,e),0,r),i=e[n],a=(t-i)/(e[n+1]-i)||0;return a<=0?{bin0:n,bin1:n,frac:0}:a<.5?{bin0:n,bin1:n+1,frac:a}:{bin0:n+1,bin1:n,frac:1-a}}function b(t,e,r){t[e]=r[0],t[e+1]=r[1],t[e+2]=r[2],t[e+3]=Math.round(255*r[3])}e.exports=function(t,e,r,_){var w=e.xaxis,T=e.yaxis;l.makeTraceGroups(_,r,"hm").each((function(e){var r,_,k,A,M,S,E,L,C=n.select(this),P=e[0],I=P.trace,O=I.xgap||0,z=I.ygap||0,D=P.z,R=P.x,F=P.y,B=P.xCenter,N=P.yCenter,j=a.traceIs(I,"contour"),U=j?"best":I.zsmooth,V=D.length,H=l.maxRowLength(D),q=!1,G=!1;for(S=0;void 0===r&&S<R.length-1;)r=w.c2p(R[S]),S++;for(S=R.length-1;void 0===_&&S>0;)_=w.c2p(R[S]),S--;for(_<r&&(k=_,_=r,r=k,q=!0),S=0;void 0===A&&S<F.length-1;)A=T.c2p(F[S]),S++;for(S=F.length-1;void 0===M&&S>0;)M=T.c2p(F[S]),S--;if(M<A&&(k=A,A=M,M=k,G=!0),j&&(B=R,N=F,R=P.xfill,F=P.yfill),"fast"!==U){var Y="best"===U?0:.5;r=Math.max(-Y*w._length,r),_=Math.min((1+Y)*w._length,_),A=Math.max(-Y*T._length,A),M=Math.min((1+Y)*T._length,M)}var W,X,Z=Math.round(_-r),J=Math.round(M-A);if(Z<=0||J<=0)return C.selectAll("image").data([]).exit().remove(),void v(C);"fast"===U?(W=H,X=V):(W=Z,X=J);var K=document.createElement("canvas");K.width=W,K.height=X;var Q,$,tt=K.getContext("2d"),et=p(I,{noNumericCheck:!0,returnArray:!0});"fast"===U?(Q=q?function(t){return H-1-t}:l.identity,$=G?function(t){return V-1-t}:l.identity):(Q=function(t){return l.constrain(Math.round(w.c2p(R[t])-r),0,Z)},$=function(t){return l.constrain(Math.round(T.c2p(F[t])-A),0,J)});var rt,nt,it,at,ot=$(0),st=[ot,ot],lt=q?0:1,ct=G?0:1,ut=0,ft=0,ht=0,pt=0;function dt(t,e){if(void 0!==t){var r=et(t);return r[0]=Math.round(r[0]),r[1]=Math.round(r[1]),r[2]=Math.round(r[2]),ut+=e,ft+=r[0]*e,ht+=r[1]*e,pt+=r[2]*e,r}return[0,0,0,0]}function mt(t,e,r,n){var i=t[r.bin0];if(void 0===i)return dt(void 0,1);var a,o=t[r.bin1],s=e[r.bin0],l=e[r.bin1],c=o-i||0,u=s-i||0;return a=void 0===o?void 0===l?0:void 0===s?2*(l-i):2*(2*l-s-i)/3:void 0===l?void 0===s?0:2*(2*i-o-s)/3:void 0===s?2*(2*l-o-i)/3:l+i-o-s,dt(i+r.frac*c+n.frac*(u+r.frac*a))}if(U){var gt,vt=0;try{gt=new Uint8Array(Z*J*4)}catch(t){gt=new Array(Z*J*4)}if("best"===U){var yt,xt,bt,_t=B||R,wt=N||F,Tt=new Array(_t.length),kt=new Array(wt.length),At=new Array(Z),Mt=B?x:y,St=N?x:y;for(S=0;S<_t.length;S++)Tt[S]=Math.round(w.c2p(_t[S])-r);for(S=0;S<wt.length;S++)kt[S]=Math.round(T.c2p(wt[S])-A);for(S=0;S<Z;S++)At[S]=Mt(S,Tt);for(E=0;E<J;E++)for(xt=D[(yt=St(E,kt)).bin0],bt=D[yt.bin1],S=0;S<Z;S++,vt+=4)b(gt,vt,at=mt(xt,bt,At[S],yt))}else for(E=0;E<V;E++)for(it=D[E],st=$(E),S=0;S<Z;S++)at=dt(it[S],1),b(gt,vt=4*(st*Z+Q(S)),at);var Et=tt.createImageData(Z,J);try{Et.data.set(gt)}catch(t){var Lt=Et.data,Ct=Lt.length;for(E=0;E<Ct;E++)Lt[E]=gt[E]}tt.putImageData(Et,0,0)}else{var Pt=Math.floor(O/2),It=Math.floor(z/2);for(E=0;E<V;E++)if(it=D[E],st.reverse(),st[ct]=$(E+1),st[0]!==st[1]&&void 0!==st[0]&&void 0!==st[1])for(rt=[nt=Q(0),nt],S=0;S<H;S++)rt.reverse(),rt[lt]=Q(S+1),rt[0]!==rt[1]&&void 0!==rt[0]&&void 0!==rt[1]&&(at=dt(it[S],(rt[1]-rt[0])*(st[1]-st[0])),tt.fillStyle="rgba("+at.join(",")+")",tt.fillRect(rt[0]+Pt,st[0]+It,rt[1]-rt[0]-O,st[1]-st[0]-z))}ft=Math.round(ft/ut),ht=Math.round(ht/ut),pt=Math.round(pt/ut);var Ot=i("rgb("+ft+","+ht+","+pt+")");t._hmpixcount=(t._hmpixcount||0)+ut,t._hmlumcount=(t._hmlumcount||0)+ut*Ot.getLuminance();var zt=C.selectAll("image").data(e);zt.enter().append("svg:image").attr({xmlns:d.svg,preserveAspectRatio:"none"}),zt.attr({height:J,width:Z,x:r,y:A,"xlink:href":K.toDataURL("image/png")}),v(C);var Dt=I.texttemplate;if(Dt){var Rt=h(I),Ft={type:"linear",range:[Rt.min,Rt.max],_separators:w._separators,_numFormat:w._numFormat},Bt="histogram2dcontour"===I.type,Nt="contour"===I.type,jt=Nt?V-1:V,Ut=Nt?1:0,Vt=Nt?H-1:H,Ht=[];for(S=Nt?1:0;S<jt;S++){var qt;if(Nt)qt=P.y[S];else if(Bt){if(0===S||S===V-1)continue;qt=P.y[S]}else if(P.yCenter)qt=P.yCenter[S];else{if(S+1===V&&void 0===P.y[S+1])continue;qt=(P.y[S]+P.y[S+1])/2}var Gt=Math.round(T.c2p(qt));if(!(0>Gt||Gt>T._length))for(E=Ut;E<Vt;E++){var Yt;if(Nt)Yt=P.x[E];else if(Bt){if(0===E||E===H-1)continue;Yt=P.x[E]}else if(P.xCenter)Yt=P.xCenter[E];else{if(E+1===H&&void 0===P.x[E+1])continue;Yt=(P.x[E]+P.x[E+1])/2}var Wt=Math.round(w.c2p(Yt));if(!(0>Wt||Wt>w._length)){var Xt=u({x:Yt,y:qt},I,t._fullLayout);Xt.x=Yt,Xt.y=qt;var Zt=P.z[S][E];void 0===Zt?(Xt.z="",Xt.zLabel=""):(Xt.z=Zt,Xt.zLabel=s.tickText(Ft,Zt,"hover").text);var Jt=P.text&&P.text[S]&&P.text[S][E];void 0!==Jt&&!1!==Jt||(Jt=""),Xt.text=Jt;var Kt=l.texttemplateString(Dt,Xt,t._fullLayout._d3locale,Xt,I._meta||{});if(Kt){var Qt=Kt.split("<br>"),$t=Qt.length,te=0;for(L=0;L<$t;L++)te=Math.max(te,Qt[L].length);Ht.push({l:$t,c:te,t:Kt,x:Wt,y:Gt,z:Zt})}}}}var ee=I.textfont,re=ee.family,ne=ee.size,ie=t._fullLayout.font.size;if(!ne||"auto"===ne){var ae=1/0,oe=1/0,se=0,le=0;for(L=0;L<Ht.length;L++){var ce=Ht[L];if(se=Math.max(se,ce.l),le=Math.max(le,ce.c),L<Ht.length-1){var ue=Ht[L+1],fe=Math.abs(ue.x-ce.x),he=Math.abs(ue.y-ce.y);fe&&(ae=Math.min(ae,fe)),he&&(oe=Math.min(oe,he))}}isFinite(ae)&&isFinite(oe)?(ae-=O,oe-=z,ae/=le,oe/=se,ae/=m/2,oe/=m,ne=Math.min(Math.floor(ae),Math.floor(oe),ie)):ne=ie}if(ne<=0||!isFinite(ne))return;g(C).data(Ht).enter().append("g").classed("heatmap-label",1).append("text").attr("text-anchor","middle").each((function(e){var r=n.select(this),i=ee.color;i&&"auto"!==i||(i=f.contrast("rgba("+et(e.z).join()+")")),r.attr("data-notex",1).call(c.positionText,function(t){return t.x}(e),function(t){return t.y-ne*(t.l*m/2-1)}(e)).call(o.font,re,ne,i).text(e.t).call(c.convertToTspans,t)}))}}))}},{"../../components/color":366,"../../components/colorscale":378,"../../components/drawing":388,"../../constants/alignment":471,"../../constants/xmlns_namespaces":480,"../../lib":503,"../../lib/svg_text_utils":529,"../../plots/cartesian/axes":554,"../../registry":638,"../scatter/format_labels":936,"@plotly/d3":58,tinycolor2:312}],805:[function(t,e,r){"use strict";var n=t("@plotly/d3");e.exports=function(t){n.select(t).selectAll(".hm image").style("opacity",(function(t){return t.trace.opacity}))}},{"@plotly/d3":58}],806:[function(t,e,r){"use strict";e.exports=function(t,e,r){!1===r("zsmooth")&&(r("xgap"),r("ygap")),r("zhoverformat")}},{}],807:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=t("../../registry");function o(t,e){var r=e(t);return"scaled"===(r?e(t+"type","array"):"scaled")&&(e(t+"0"),e("d"+t)),r}e.exports=function(t,e,r,s,l,c){var u,f,h=r("z");if(l=l||"x",c=c||"y",void 0===h||!h.length)return 0;if(i.isArray1D(t.z)){u=r(l),f=r(c);var p=i.minRowLength(u),d=i.minRowLength(f);if(0===p||0===d)return 0;e._length=Math.min(p,d,h.length)}else{if(u=o(l,r),f=o(c,r),!function(t){for(var e,r=!0,a=!1,o=!1,s=0;s<t.length;s++){if(e=t[s],!i.isArrayOrTypedArray(e)){r=!1;break}e.length>0&&(a=!0);for(var l=0;l<e.length;l++)if(n(e[l])){o=!0;break}}return r&&a&&o}(h))return 0;r("transpose"),e._length=null}return"heatmapgl"===t.type||a.getComponentMethod("calendars","handleTraceDefaults")(t,e,[l,c],s),!0}},{"../../lib":503,"../../registry":638,"fast-isnumeric":190}],808:[function(t,e,r){"use strict";for(var n=t("../heatmap/attributes"),i=t("../../components/colorscale/attributes"),a=t("../../lib/extend").extendFlat,o=t("../../plot_api/edit_types").overrideAll,s=["z","x","x0","dx","y","y0","dy","text","transpose","xtype","ytype"],l={},c=0;c<s.length;c++){var u=s[c];l[u]=n[u]}l.zsmooth={valType:"enumerated",values:["fast",!1],dflt:"fast",editType:"calc"},a(l,i("",{cLetter:"z",autoColorDflt:!1})),e.exports=o(l,"calc","nested")},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plot_api/edit_types":536,"../heatmap/attributes":792}],809:[function(t,e,r){"use strict";var n=t("../../../stackgl_modules").gl_heatmap2d,i=t("../../plots/cartesian/axes"),a=t("../../lib/str2rgbarray");function o(t,e){this.scene=t,this.uid=e,this.type="heatmapgl",this.name="",this.hoverinfo="all",this.xData=[],this.yData=[],this.zData=[],this.textLabels=[],this.idToIndex=[],this.bounds=[0,0,0,0],this.options={zsmooth:"fast",z:[],x:[],y:[],shape:[0,0],colorLevels:[0],colorValues:[0,0,0,1]},this.heatmap=n(t.glplot,this.options),this.heatmap._trace=this}var s=o.prototype;s.handlePick=function(t){var e=this.options,r=e.shape,n=t.pointId,i=n%r[0],a=Math.floor(n/r[0]),o=n;return{trace:this,dataCoord:t.dataCoord,traceCoord:[e.x[i],e.y[a],e.z[o]],textLabel:this.textLabels[n],name:this.name,pointIndex:[a,i],hoverinfo:this.hoverinfo}},s.update=function(t,e){var r=e[0];this.index=t.index,this.name=t.name,this.hoverinfo=t.hoverinfo;var n=r.z;this.options.z=[].concat.apply([],n);var o=n[0].length,s=n.length;this.options.shape=[o,s],this.options.x=r.x,this.options.y=r.y,this.options.zsmooth=t.zsmooth;var l=function(t){for(var e=t.colorscale,r=t.zmin,n=t.zmax,i=e.length,o=new Array(i),s=new Array(4*i),l=0;l<i;l++){var c=e[l],u=a(c[1]);o[l]=r+c[0]*(n-r);for(var f=0;f<4;f++)s[4*l+f]=u[f]}return{colorLevels:o,colorValues:s}}(t);this.options.colorLevels=l.colorLevels,this.options.colorValues=l.colorValues,this.textLabels=[].concat.apply([],t.text),this.heatmap.update(this.options);var c,u,f=this.scene.xaxis,h=this.scene.yaxis;!1===t.zsmooth&&(c={ppad:r.x[1]-r.x[0]},u={ppad:r.y[1]-r.y[0]}),t._extremes[f._id]=i.findExtremes(f,r.x,c),t._extremes[h._id]=i.findExtremes(h,r.y,u)},s.dispose=function(){this.heatmap.dispose()},e.exports=function(t,e,r){var n=new o(t,e.uid);return n.update(e,r),n}},{"../../../stackgl_modules":1124,"../../lib/str2rgbarray":528,"../../plots/cartesian/axes":554}],810:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../heatmap/xyz_defaults"),a=t("../../components/colorscale/defaults"),o=t("./attributes");e.exports=function(t,e,r,s){function l(r,i){return n.coerce(t,e,o,r,i)}i(t,e,l,s)?(l("text"),l("zsmooth"),a(t,e,s,l,{prefix:"",cLetter:"z"})):e.visible=!1}},{"../../components/colorscale/defaults":376,"../../lib":503,"../heatmap/xyz_defaults":807,"./attributes":808}],811:[function(t,e,r){"use strict";["*heatmapgl* trace is deprecated!","Please consider switching to the *heatmap* or *image* trace types.","Alternatively you could contribute/sponsor rewriting this trace type","based on cartesian features and using regl framework."].join(" ");e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:t("../heatmap/colorbar"),calc:t("../heatmap/calc"),plot:t("./convert"),moduleType:"trace",name:"heatmapgl",basePlotModule:t("../../plots/gl2d"),categories:["gl","gl2d","2dMap"],meta:{}}},{"../../plots/gl2d":596,"../heatmap/calc":793,"../heatmap/colorbar":795,"./attributes":808,"./convert":809,"./defaults":810}],812:[function(t,e,r){"use strict";var n=t("../bar/attributes"),i=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,a=t("../../plots/template_attributes").hovertemplateAttrs,o=t("../../plots/template_attributes").texttemplateAttrs,s=t("../../plots/font_attributes"),l=t("./bin_attributes"),c=t("./constants"),u=t("../../lib/extend").extendFlat;e.exports={x:{valType:"data_array",editType:"calc+clearAxisTypes"},y:{valType:"data_array",editType:"calc+clearAxisTypes"},xhoverformat:i("x"),yhoverformat:i("y"),text:u({},n.text,{}),hovertext:u({},n.hovertext,{}),orientation:n.orientation,histfunc:{valType:"enumerated",values:["count","sum","avg","min","max"],dflt:"count",editType:"calc"},histnorm:{valType:"enumerated",values:["","percent","probability","density","probability density"],dflt:"",editType:"calc"},cumulative:{enabled:{valType:"boolean",dflt:!1,editType:"calc"},direction:{valType:"enumerated",values:["increasing","decreasing"],dflt:"increasing",editType:"calc"},currentbin:{valType:"enumerated",values:["include","exclude","half"],dflt:"include",editType:"calc"},editType:"calc"},nbinsx:{valType:"integer",min:0,dflt:0,editType:"calc"},xbins:l("x",!0),nbinsy:{valType:"integer",min:0,dflt:0,editType:"calc"},ybins:l("y",!0),autobinx:{valType:"boolean",dflt:null,editType:"calc"},autobiny:{valType:"boolean",dflt:null,editType:"calc"},bingroup:{valType:"string",dflt:"",editType:"calc"},hovertemplate:a({},{keys:c.eventDataKeys}),texttemplate:o({arrayOk:!1,editType:"plot"},{keys:["label","value"]}),textposition:u({},n.textposition,{arrayOk:!1}),textfont:s({arrayOk:!1,editType:"plot",colorEditType:"style"}),outsidetextfont:s({arrayOk:!1,editType:"plot",colorEditType:"style"}),insidetextfont:s({arrayOk:!1,editType:"plot",colorEditType:"style"}),insidetextanchor:n.insidetextanchor,textangle:n.textangle,cliponaxis:n.cliponaxis,constraintext:n.constraintext,marker:n.marker,offsetgroup:n.offsetgroup,alignmentgroup:n.alignmentgroup,selected:n.selected,unselected:n.unselected,_deprecated:{bardir:n._deprecated.bardir}}},{"../../lib/extend":493,"../../plots/cartesian/axis_format_attributes":557,"../../plots/font_attributes":585,"../../plots/template_attributes":633,"../bar/attributes":648,"./bin_attributes":814,"./constants":818}],813:[function(t,e,r){"use strict";e.exports=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)e[i]?(t[i]/=e[i],n+=t[i]):t[i]=null;return n}},{}],814:[function(t,e,r){"use strict";e.exports=function(t,e){return{start:{valType:"any",editType:"calc"},end:{valType:"any",editType:"calc"},size:{valType:"any",editType:"calc"},editType:"calc"}}},{}],815:[function(t,e,r){"use strict";var n=t("fast-isnumeric");e.exports={count:function(t,e,r){return r[t]++,1},sum:function(t,e,r,i){var a=i[e];return n(a)?(a=Number(a),r[t]+=a,a):0},avg:function(t,e,r,i,a){var o=i[e];return n(o)&&(o=Number(o),r[t]+=o,a[t]++),0},min:function(t,e,r,i){var a=i[e];if(n(a)){if(a=Number(a),!n(r[t]))return r[t]=a,a;if(r[t]>a){var o=a-r[t];return r[t]=a,o}}return 0},max:function(t,e,r,i){var a=i[e];if(n(a)){if(a=Number(a),!n(r[t]))return r[t]=a,a;if(r[t]<a){var o=a-r[t];return r[t]=a,o}}return 0}}},{"fast-isnumeric":190}],816:[function(t,e,r){"use strict";var n=t("../../constants/numerical"),i=n.ONEAVGYEAR,a=n.ONEAVGMONTH,o=n.ONEDAY,s=n.ONEHOUR,l=n.ONEMIN,c=n.ONESEC,u=t("../../plots/cartesian/axes").tickIncrement;function f(t,e,r,n){if(t*e<=0)return 1/0;for(var i=Math.abs(e-t),a="date"===r.type,o=h(i,a),s=0;s<10;s++){var l=h(80*o,a);if(o===l)break;if(!p(l,t,e,a,r,n))break;o=l}return o}function h(t,e){return e&&t>c?t>o?t>1.1*i?i:t>1.1*a?a:o:t>s?s:t>l?l:c:Math.pow(10,Math.floor(Math.log(t)/Math.LN10))}function p(t,e,r,n,a,s){if(n&&t>o){var l=d(e,a,s),c=d(r,a,s),u=t===i?0:1;return l[u]!==c[u]}return Math.floor(r/t)-Math.floor(e/t)>.1}function d(t,e,r){var n=e.c2d(t,i,r).split("-");return""===n[0]&&(n.unshift(),n[0]="-"+n[0]),n}e.exports=function(t,e,r,n,a){var s,l,c=-1.1*e,h=-.1*e,p=t-h,d=r[0],m=r[1],g=Math.min(f(d+h,d+p,n,a),f(m+h,m+p,n,a)),v=Math.min(f(d+c,d+h,n,a),f(m+c,m+h,n,a));if(g>v&&v<Math.abs(m-d)/4e3?(s=g,l=!1):(s=Math.min(g,v),l=!0),"date"===n.type&&s>o){var y=s===i?1:6,x=s===i?"M12":"M1";return function(e,r){var o=n.c2d(e,i,a),s=o.indexOf("-",y);s>0&&(o=o.substr(0,s));var c=n.d2c(o,0,a);if(c<e){var f=u(c,x,!1,a);(c+f)/2<e+t&&(c=f)}return r&&l?u(c,x,!0,a):c}}return function(e,r){var n=s*Math.round(e/s);return n+s/10<e&&n+.9*s<e+t&&(n+=s),r&&l&&(n-=s),n}}},{"../../constants/numerical":479,"../../plots/cartesian/axes":554}],817:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=t("../../registry"),o=t("../../plots/cartesian/axes"),s=t("../bar/arrays_to_calcdata"),l=t("./bin_functions"),c=t("./norm_functions"),u=t("./average"),f=t("./bin_label_vals");function h(t,e,r,s,l){var c,u,f,p,d,m,g,v=s+"bins",y=t._fullLayout,x=e["_"+s+"bingroup"],b=y._histogramBinOpts[x],_="overlay"===y.barmode,w=function(t){return r.r2c(t,0,p)},T=function(t){return r.c2r(t,0,p)},k="date"===r.type?function(t){return t||0===t?i.cleanDate(t,null,p):null}:function(t){return n(t)?Number(t):null};function A(t,e,r){e[t+"Found"]?(e[t]=k(e[t]),null===e[t]&&(e[t]=r[t])):(m[t]=e[t]=r[t],i.nestedProperty(u[0],v+"."+t).set(r[t]))}if(e["_"+s+"autoBinFinished"])delete e["_"+s+"autoBinFinished"];else{u=b.traces;var M=[],S=!0,E=!1,L=!1;for(c=0;c<u.length;c++)if((f=u[c]).visible){var C=b.dirs[c];d=f["_"+C+"pos0"]=r.makeCalcdata(f,C),M=i.concat(M,d),delete f["_"+s+"autoBinFinished"],!0===e.visible&&(S?S=!1:(delete f._autoBin,f["_"+s+"autoBinFinished"]=1),a.traceIs(f,"2dMap")&&(E=!0),"histogram2dcontour"===f.type&&(L=!0))}p=u[0][s+"calendar"];var P=o.autoBin(M,r,b.nbins,E,p,b.sizeFound&&b.size),I=u[0]._autoBin={};if(m=I[b.dirs[0]]={},L&&(b.size||(P.start=T(o.tickIncrement(w(P.start),P.size,!0,p))),void 0===b.end&&(P.end=T(o.tickIncrement(w(P.end),P.size,!1,p)))),_&&!a.traceIs(e,"2dMap")&&0===P._dataSpan&&"category"!==r.type&&"multicategory"!==r.type){if(l)return[P,d,!0];P=function(t,e,r,n,a){var o,s,l,c=t._fullLayout,u=function(t,e){for(var r=e.xaxis,n=e.yaxis,i=e.orientation,a=[],o=t._fullData,s=0;s<o.length;s++){var l=o[s];"histogram"===l.type&&!0===l.visible&&l.orientation===i&&l.xaxis===r&&l.yaxis===n&&a.push(l)}return a}(t,e),f=!1,p=1/0,d=[e];for(o=0;o<u.length;o++)if((s=u[o])===e)f=!0;else if(f){var m=h(t,s,r,n,!0),g=m[0],v=m[2];s["_"+n+"autoBinFinished"]=1,s["_"+n+"pos0"]=m[1],v?d.push(s):p=Math.min(p,g.size)}else l=c._histogramBinOpts[s["_"+n+"bingroup"]],p=Math.min(p,l.size||s[a].size);var y=new Array(d.length);for(o=0;o<d.length;o++)for(var x=d[o]["_"+n+"pos0"],b=0;b<x.length;b++)if(void 0!==x[b]){y[o]=x[b];break}isFinite(p)||(p=i.distinctVals(y).minDiff);for(o=0;o<d.length;o++){var _=(s=d[o])[n+"calendar"],w={start:r.c2r(y[o]-p/2,0,_),end:r.c2r(y[o]+p/2,0,_),size:p};s._input[a]=s[a]=w,(l=c._histogramBinOpts[s["_"+n+"bingroup"]])&&i.extendFlat(l,w)}return e[a]}(t,e,r,s,v)}(g=f.cumulative||{}).enabled&&"include"!==g.currentbin&&("decreasing"===g.direction?P.start=T(o.tickIncrement(w(P.start),P.size,!0,p)):P.end=T(o.tickIncrement(w(P.end),P.size,!1,p))),b.size=P.size,b.sizeFound||(m.size=P.size,i.nestedProperty(u[0],v+".size").set(P.size)),A("start",b,P),A("end",b,P)}d=e["_"+s+"pos0"],delete e["_"+s+"pos0"];var O=e._input[v]||{},z=i.extendFlat({},b),D=b.start,R=r.r2l(O.start),F=void 0!==R;if((b.startFound||F)&&R!==r.r2l(D)){var B=F?R:i.aggNums(Math.min,null,d),N={type:"category"===r.type||"multicategory"===r.type?"linear":r.type,r2l:r.r2l,dtick:b.size,tick0:D,calendar:p,range:[B,o.tickIncrement(B,b.size,!1,p)].map(r.l2r)},j=o.tickFirst(N);j>r.r2l(B)&&(j=o.tickIncrement(j,b.size,!0,p)),z.start=r.l2r(j),F||i.nestedProperty(e,v+".start").set(z.start)}var U=b.end,V=r.r2l(O.end),H=void 0!==V;if((b.endFound||H)&&V!==r.r2l(U)){var q=H?V:i.aggNums(Math.max,null,d);z.end=r.l2r(q),H||i.nestedProperty(e,v+".start").set(z.end)}var G="autobin"+s;return!1===e._input[G]&&(e._input[v]=i.extendFlat({},e[v]||{}),delete e._input[G],delete e[G]),[z,d]}e.exports={calc:function(t,e){var r,a,p,d,m=[],g=[],v="h"===e.orientation,y=o.getFromId(t,v?e.yaxis:e.xaxis),x=v?"y":"x",b={x:"y",y:"x"}[x],_=e[x+"calendar"],w=e.cumulative,T=h(t,e,y,x),k=T[0],A=T[1],M="string"==typeof k.size,S=[],E=M?S:k,L=[],C=[],P=[],I=0,O=e.histnorm,z=e.histfunc,D=-1!==O.indexOf("density");w.enabled&&D&&(O=O.replace(/ ?density$/,""),D=!1);var R,F="max"===z||"min"===z?null:0,B=l.count,N=c[O],j=!1,U=function(t){return y.r2c(t,0,_)};for(i.isArrayOrTypedArray(e[b])&&"count"!==z&&(R=e[b],j="avg"===z,B=l[z]),r=U(k.start),p=U(k.end)+(r-o.tickIncrement(r,k.size,!1,_))/1e6;r<p&&m.length<1e6&&(a=o.tickIncrement(r,k.size,!1,_),m.push((r+a)/2),g.push(F),P.push([]),S.push(r),D&&L.push(1/(a-r)),j&&C.push(0),!(a<=r));)r=a;S.push(r),M||"date"!==y.type||(E={start:U(E.start),end:U(E.end),size:E.size}),t._fullLayout._roundFnOpts||(t._fullLayout._roundFnOpts={});var V=e["_"+x+"bingroup"],H={leftGap:1/0,rightGap:1/0};V&&(t._fullLayout._roundFnOpts[V]||(t._fullLayout._roundFnOpts[V]=H),H=t._fullLayout._roundFnOpts[V]);var q,G=g.length,Y=!0,W=H.leftGap,X=H.rightGap,Z={};for(r=0;r<A.length;r++){var J=A[r];(d=i.findBin(J,E))>=0&&d<G&&(I+=B(d,r,g,R,C),Y&&P[d].length&&J!==A[P[d][0]]&&(Y=!1),P[d].push(r),Z[r]=d,W=Math.min(W,J-S[d]),X=Math.min(X,S[d+1]-J))}H.leftGap=W,H.rightGap=X,Y||(q=function(e,r){return function(){var n=t._fullLayout._roundFnOpts[V];return f(n.leftGap,n.rightGap,S,y,_)(e,r)}}),j&&(I=u(g,C)),N&&N(g,I,L),w.enabled&&function(t,e,r){var n,i,a;function o(e){a=t[e],t[e]/=2}function s(e){i=t[e],t[e]=a+i/2,a+=i}if("half"===r)if("increasing"===e)for(o(0),n=1;n<t.length;n++)s(n);else for(o(t.length-1),n=t.length-2;n>=0;n--)s(n);else if("increasing"===e){for(n=1;n<t.length;n++)t[n]+=t[n-1];"exclude"===r&&(t.unshift(0),t.pop())}else{for(n=t.length-2;n>=0;n--)t[n]+=t[n+1];"exclude"===r&&(t.push(0),t.shift())}}(g,w.direction,w.currentbin);var K=Math.min(m.length,g.length),Q=[],$=0,tt=K-1;for(r=0;r<K;r++)if(g[r]){$=r;break}for(r=K-1;r>=$;r--)if(g[r]){tt=r;break}for(r=$;r<=tt;r++)if(n(m[r])&&n(g[r])){var et={p:m[r],s:g[r],b:0};w.enabled||(et.pts=P[r],Y?et.ph0=et.ph1=P[r].length?A[P[r][0]]:m[r]:(e._computePh=!0,et.ph0=q(S[r]),et.ph1=q(S[r+1],!0))),Q.push(et)}return 1===Q.length&&(Q[0].width1=o.tickIncrement(Q[0].p,k.size,!1,_)-Q[0].p),s(Q,e),i.isArrayOrTypedArray(e.selectedpoints)&&i.tagSelected(Q,e,Z),Q},calcAllAutoBins:h}},{"../../lib":503,"../../plots/cartesian/axes":554,"../../registry":638,"../bar/arrays_to_calcdata":647,"./average":813,"./bin_functions":815,"./bin_label_vals":816,"./norm_functions":824,"fast-isnumeric":190}],818:[function(t,e,r){"use strict";e.exports={eventDataKeys:["binNumber"]}},{}],819:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axis_ids"),a=t("../../registry").traceIs,o=t("../bar/defaults").handleGroupingDefaults,s=n.nestedProperty,l=t("../../plots/cartesian/constraints").getAxisGroup,c=[{aStr:{x:"xbins.start",y:"ybins.start"},name:"start"},{aStr:{x:"xbins.end",y:"ybins.end"},name:"end"},{aStr:{x:"xbins.size",y:"ybins.size"},name:"size"},{aStr:{x:"nbinsx",y:"nbinsy"},name:"nbins"}],u=["x","y"];e.exports=function(t,e){var r,f,h,p,d,m,g,v=e._histogramBinOpts={},y=[],x={},b=[];function _(t,e){return n.coerce(r._input,r,r._module.attributes,t,e)}function w(t){return"v"===t.orientation?"x":"y"}function T(t,r,a){var o=t.uid+"__"+a;r||(r=o);var s=function(t,r){return i.getFromTrace({_fullLayout:e},t,r).type}(t,a),l=t[a+"calendar"]||"",c=v[r],u=!0;c&&(s===c.axType&&l===c.calendar?(u=!1,c.traces.push(t),c.dirs.push(a)):(r=o,s!==c.axType&&n.warn(["Attempted to group the bins of trace",t.index,"set on a","type:"+s,"axis","with bins on","type:"+c.axType,"axis."].join(" ")),l!==c.calendar&&n.warn(["Attempted to group the bins of trace",t.index,"set with a",l,"calendar","with bins",c.calendar?"on a "+c.calendar+" calendar":"w/o a set calendar"].join(" ")))),u&&(v[r]={traces:[t],dirs:[a],axType:s,calendar:t[a+"calendar"]||""}),t["_"+a+"bingroup"]=r}for(d=0;d<t.length;d++)r=t[d],a(r,"histogram")&&(y.push(r),delete r._xautoBinFinished,delete r._yautoBinFinished,a(r,"2dMap")||o(r._input,r,e,_));var k=e._alignmentOpts||{};for(d=0;d<y.length;d++){if(r=y[d],h="",!a(r,"2dMap")){if(p=w(r),"group"===e.barmode&&r.alignmentgroup){var A=r[p+"axis"],M=l(e,A)+r.orientation;(k[M]||{})[r.alignmentgroup]&&(h=M)}h||"overlay"===e.barmode||(h=l(e,r.xaxis)+l(e,r.yaxis)+w(r))}h?(x[h]||(x[h]=[]),x[h].push(r)):b.push(r)}for(h in x)if(1!==(f=x[h]).length){var S=!1;for(f.length&&(r=f[0],S=_("bingroup")),h=S||h,d=0;d<f.length;d++){var E=(r=f[d])._input.bingroup;E&&E!==h&&n.warn(["Trace",r.index,"must match","within bingroup",h+".","Ignoring its bingroup:",E,"setting."].join(" ")),r.bingroup=h,T(r,h,w(r))}}else b.push(f[0]);for(d=0;d<b.length;d++){r=b[d];var L=_("bingroup");if(a(r,"2dMap"))for(g=0;g<2;g++){var C=_((p=u[g])+"bingroup",L?L+"__"+p:null);T(r,C,p)}else T(r,L,w(r))}for(h in v){var P=v[h];for(f=P.traces,m=0;m<c.length;m++){var I,O,z=c[m],D=z.name;if("nbins"!==D||!P.sizeFound){for(d=0;d<f.length;d++){if(r=f[d],p=P.dirs[d],I=z.aStr[p],void 0!==s(r._input,I).get()){P[D]=_(I),P[D+"Found"]=!0;break}(O=(r._autoBin||{})[p]||{})[D]&&s(r,I).set(O[D])}if("start"===D||"end"===D)for(;d<f.length;d++)(r=f[d])["_"+p+"bingroup"]&&_(I,(O=(r._autoBin||{})[p]||{})[D]);"nbins"!==D||P.sizeFound||P.nbinsFound||(r=f[0],P[D]=_(I))}}}}},{"../../lib":503,"../../plots/cartesian/axis_ids":558,"../../plots/cartesian/constraints":562,"../../registry":638,"../bar/defaults":652}],820:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib"),a=t("../../components/color"),o=t("../bar/defaults").handleText,s=t("../bar/style_defaults"),l=t("./attributes");e.exports=function(t,e,r,c){function u(r,n){return i.coerce(t,e,l,r,n)}var f=u("x"),h=u("y");u("cumulative.enabled")&&(u("cumulative.direction"),u("cumulative.currentbin")),u("text");var p=u("textposition");o(t,e,c,u,p,{moduleHasSelected:!0,moduleHasUnselected:!0,moduleHasConstrain:!0,moduleHasCliponaxis:!0,moduleHasTextangle:!0,moduleHasInsideanchor:!0}),u("hovertext"),u("hovertemplate"),u("xhoverformat"),u("yhoverformat");var d=u("orientation",h&&!f?"h":"v"),m="v"===d?"x":"y",g="v"===d?"y":"x",v=f&&h?Math.min(i.minRowLength(f)&&i.minRowLength(h)):i.minRowLength(e[m]||[]);if(v){e._length=v,n.getComponentMethod("calendars","handleTraceDefaults")(t,e,["x","y"],c),e[g]&&u("histfunc"),u("histnorm"),u("autobin"+m),s(t,e,u,r,c),i.coerceSelectionMarkerOpacity(e,u);var y=(e.marker.line||{}).color,x=n.getComponentMethod("errorbars","supplyDefaults");x(t,e,y||a.defaultLine,{axis:"y"}),x(t,e,y||a.defaultLine,{axis:"x",inherit:"y"})}else e.visible=!1}},{"../../components/color":366,"../../lib":503,"../../registry":638,"../bar/defaults":652,"../bar/style_defaults":663,"./attributes":812}],821:[function(t,e,r){"use strict";e.exports=function(t,e,r,n,i){if(t.x="xVal"in e?e.xVal:e.x,t.y="yVal"in e?e.yVal:e.y,"zLabelVal"in e&&(t.z=e.zLabelVal),e.xa&&(t.xaxis=e.xa),e.ya&&(t.yaxis=e.ya),!(r.cumulative||{}).enabled){var a,o=Array.isArray(i)?n[0].pts[i[0]][i[1]]:n[i].pts;if(t.pointNumbers=o,t.binNumber=t.pointNumber,delete t.pointNumber,delete t.pointIndex,r._indexToPoints){a=[];for(var s=0;s<o.length;s++)a=a.concat(r._indexToPoints[o[s]])}else a=o;t.pointIndices=a}return t}},{}],822:[function(t,e,r){"use strict";var n=t("../bar/hover").hoverPoints,i=t("../../plots/cartesian/axes").hoverLabelText;e.exports=function(t,e,r,a,o){var s=n(t,e,r,a,o);if(s){var l=(t=s[0]).cd[t.index],c=t.cd[0].trace;if(!c.cumulative.enabled){var u="h"===c.orientation?"y":"x";t[u+"Label"]=i(t[u+"a"],[l.ph0,l.ph1],c[u+"hoverformat"])}return s}}},{"../../plots/cartesian/axes":554,"../bar/hover":655}],823:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),layoutAttributes:t("../bar/layout_attributes"),supplyDefaults:t("./defaults"),crossTraceDefaults:t("./cross_trace_defaults"),supplyLayoutDefaults:t("../bar/layout_defaults"),calc:t("./calc").calc,crossTraceCalc:t("../bar/cross_trace_calc").crossTraceCalc,plot:t("../bar/plot").plot,layerName:"barlayer",style:t("../bar/style").style,styleOnSelect:t("../bar/style").styleOnSelect,colorbar:t("../scatter/marker_colorbar"),hoverPoints:t("./hover"),selectPoints:t("../bar/select"),eventData:t("./event_data"),moduleType:"trace",name:"histogram",basePlotModule:t("../../plots/cartesian"),categories:["bar-like","cartesian","svg","bar","histogram","oriented","errorBarsOK","showLegend"],meta:{}}},{"../../plots/cartesian":568,"../bar/cross_trace_calc":651,"../bar/layout_attributes":657,"../bar/layout_defaults":658,"../bar/plot":659,"../bar/select":660,"../bar/style":662,"../scatter/marker_colorbar":945,"./attributes":812,"./calc":817,"./cross_trace_defaults":819,"./defaults":820,"./event_data":821,"./hover":822}],824:[function(t,e,r){"use strict";e.exports={percent:function(t,e){for(var r=t.length,n=100/e,i=0;i<r;i++)t[i]*=n},probability:function(t,e){for(var r=t.length,n=0;n<r;n++)t[n]/=e},density:function(t,e,r,n){var i=t.length;n=n||1;for(var a=0;a<i;a++)t[a]*=r[a]*n},"probability density":function(t,e,r,n){var i=t.length;n&&(e/=n);for(var a=0;a<i;a++)t[a]*=r[a]/e}}},{}],825:[function(t,e,r){"use strict";var n=t("../histogram/attributes"),i=t("../histogram/bin_attributes"),a=t("../heatmap/attributes"),o=t("../../plots/attributes"),s=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,l=t("../../plots/template_attributes").hovertemplateAttrs,c=t("../../plots/template_attributes").texttemplateAttrs,u=t("../../components/colorscale/attributes"),f=t("../../lib/extend").extendFlat;e.exports=f({x:n.x,y:n.y,z:{valType:"data_array",editType:"calc"},marker:{color:{valType:"data_array",editType:"calc"},editType:"calc"},histnorm:n.histnorm,histfunc:n.histfunc,nbinsx:n.nbinsx,xbins:i("x"),nbinsy:n.nbinsy,ybins:i("y"),autobinx:n.autobinx,autobiny:n.autobiny,bingroup:f({},n.bingroup,{}),xbingroup:f({},n.bingroup,{}),ybingroup:f({},n.bingroup,{}),xgap:a.xgap,ygap:a.ygap,zsmooth:a.zsmooth,xhoverformat:s("x"),yhoverformat:s("y"),zhoverformat:s("z",1),hovertemplate:l({},{keys:"z"}),texttemplate:c({arrayOk:!1,editType:"plot"},{keys:"z"}),textfont:a.textfont,showlegend:f({},o.showlegend,{dflt:!1})},u("",{cLetter:"z",autoColorDflt:!1}))},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/cartesian/axis_format_attributes":557,"../../plots/template_attributes":633,"../heatmap/attributes":792,"../histogram/attributes":812,"../histogram/bin_attributes":814}],826:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axes"),a=t("../histogram/bin_functions"),o=t("../histogram/norm_functions"),s=t("../histogram/average"),l=t("../histogram/bin_label_vals"),c=t("../histogram/calc").calcAllAutoBins;function u(t,e,r,n){var i,a=new Array(t);if(n)for(i=0;i<t;i++)a[i]=1/(e[i+1]-e[i]);else{var o=1/r;for(i=0;i<t;i++)a[i]=o}return a}function f(t,e){return{start:t(e.start),end:t(e.end),size:e.size}}function h(t,e,r,n,i,a){var o,s=t.length-1,c=new Array(s),u=l(r,n,t,i,a);for(o=0;o<s;o++){var f=(e||[])[o];c[o]=void 0===f?[u(t[o]),u(t[o+1],!0)]:[f,f]}return c}e.exports=function(t,e){var r,l,p,d,m=i.getFromId(t,e.xaxis),g=i.getFromId(t,e.yaxis),v=e.xcalendar,y=e.ycalendar,x=function(t){return m.r2c(t,0,v)},b=function(t){return g.r2c(t,0,y)},_=c(t,e,m,"x"),w=_[0],T=_[1],k=c(t,e,g,"y"),A=k[0],M=k[1],S=e._length;T.length>S&&T.splice(S,T.length-S),M.length>S&&M.splice(S,M.length-S);var E=[],L=[],C=[],P="string"==typeof w.size,I="string"==typeof A.size,O=[],z=[],D=P?O:w,R=I?z:A,F=0,B=[],N=[],j=e.histnorm,U=e.histfunc,V=-1!==j.indexOf("density"),H="max"===U||"min"===U?null:0,q=a.count,G=o[j],Y=!1,W=[],X=[],Z="z"in e?e.z:"marker"in e&&Array.isArray(e.marker.color)?e.marker.color:"";Z&&"count"!==U&&(Y="avg"===U,q=a[U]);var J=w.size,K=x(w.start),Q=x(w.end)+(K-i.tickIncrement(K,J,!1,v))/1e6;for(r=K;r<Q;r=i.tickIncrement(r,J,!1,v))L.push(H),O.push(r),Y&&C.push(0);O.push(r);var $,tt=L.length,et=(r-K)/tt,rt=($=K+et/2,m.c2r($,0,v)),nt=A.size,it=b(A.start),at=b(A.end)+(it-i.tickIncrement(it,nt,!1,y))/1e6;for(r=it;r<at;r=i.tickIncrement(r,nt,!1,y)){E.push(L.slice()),z.push(r);var ot=new Array(tt);for(l=0;l<tt;l++)ot[l]=[];N.push(ot),Y&&B.push(C.slice())}z.push(r);var st=E.length,lt=(r-it)/st,ct=function(t){return g.c2r(t,0,y)}(it+lt/2);V&&(W=u(L.length,D,et,P),X=u(E.length,R,lt,I)),P||"date"!==m.type||(D=f(x,D)),I||"date"!==g.type||(R=f(b,R));var ut=!0,ft=!0,ht=new Array(tt),pt=new Array(st),dt=1/0,mt=1/0,gt=1/0,vt=1/0;for(r=0;r<S;r++){var yt=T[r],xt=M[r];p=n.findBin(yt,D),d=n.findBin(xt,R),p>=0&&p<tt&&d>=0&&d<st&&(F+=q(p,r,E[d],Z,B[d]),N[d][p].push(r),ut&&(void 0===ht[p]?ht[p]=yt:ht[p]!==yt&&(ut=!1)),ft&&(void 0===pt[d]?pt[d]=xt:pt[d]!==xt&&(ft=!1)),dt=Math.min(dt,yt-O[p]),mt=Math.min(mt,O[p+1]-yt),gt=Math.min(gt,xt-z[d]),vt=Math.min(vt,z[d+1]-xt))}if(Y)for(d=0;d<st;d++)F+=s(E[d],B[d]);if(G)for(d=0;d<st;d++)G(E[d],F,W,X[d]);return{x:T,xRanges:h(O,ut&&ht,dt,mt,m,v),x0:rt,dx:et,y:M,yRanges:h(z,ft&&pt,gt,vt,g,y),y0:ct,dy:lt,z:E,pts:N}}},{"../../lib":503,"../../plots/cartesian/axes":554,"../histogram/average":813,"../histogram/bin_functions":815,"../histogram/bin_label_vals":816,"../histogram/calc":817,"../histogram/norm_functions":824}],827:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./sample_defaults"),a=t("../heatmap/style_defaults"),o=t("../../components/colorscale/defaults"),s=t("../heatmap/label_defaults"),l=t("./attributes");e.exports=function(t,e,r,c){function u(r,i){return n.coerce(t,e,l,r,i)}i(t,e,u,c),!1!==e.visible&&(a(t,e,u,c),o(t,e,c,u,{prefix:"",cLetter:"z"}),u("hovertemplate"),s(u,c),u("xhoverformat"),u("yhoverformat"))}},{"../../components/colorscale/defaults":376,"../../lib":503,"../heatmap/label_defaults":802,"../heatmap/style_defaults":806,"./attributes":825,"./sample_defaults":830}],828:[function(t,e,r){"use strict";var n=t("../heatmap/hover"),i=t("../../plots/cartesian/axes").hoverLabelText;e.exports=function(t,e,r,a,o){var s=n(t,e,r,a,o);if(s){var l=(t=s[0]).index,c=l[0],u=l[1],f=t.cd[0],h=f.trace,p=f.xRanges[u],d=f.yRanges[c];return t.xLabel=i(t.xa,[p[0],p[1]],h.xhoverformat),t.yLabel=i(t.ya,[d[0],d[1]],h.yhoverformat),s}}},{"../../plots/cartesian/axes":554,"../heatmap/hover":799}],829:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),crossTraceDefaults:t("../histogram/cross_trace_defaults"),calc:t("../heatmap/calc"),plot:t("../heatmap/plot"),layerName:"heatmaplayer",colorbar:t("../heatmap/colorbar"),style:t("../heatmap/style"),hoverPoints:t("./hover"),eventData:t("../histogram/event_data"),moduleType:"trace",name:"histogram2d",basePlotModule:t("../../plots/cartesian"),categories:["cartesian","svg","2dMap","histogram","showLegend"],meta:{}}},{"../../plots/cartesian":568,"../heatmap/calc":793,"../heatmap/colorbar":795,"../heatmap/plot":804,"../heatmap/style":805,"../histogram/cross_trace_defaults":819,"../histogram/event_data":821,"./attributes":825,"./defaults":827,"./hover":828}],830:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib");e.exports=function(t,e,r,a){var o=r("x"),s=r("y"),l=i.minRowLength(o),c=i.minRowLength(s);l&&c?(e._length=Math.min(l,c),n.getComponentMethod("calendars","handleTraceDefaults")(t,e,["x","y"],a),(r("z")||r("marker.color"))&&r("histfunc"),r("histnorm"),r("autobinx"),r("autobiny")):e.visible=!1}},{"../../lib":503,"../../registry":638}],831:[function(t,e,r){"use strict";var n=t("../histogram2d/attributes"),i=t("../contour/attributes"),a=t("../../components/colorscale/attributes"),o=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,s=t("../../lib/extend").extendFlat;e.exports=s({x:n.x,y:n.y,z:n.z,marker:n.marker,histnorm:n.histnorm,histfunc:n.histfunc,nbinsx:n.nbinsx,xbins:n.xbins,nbinsy:n.nbinsy,ybins:n.ybins,autobinx:n.autobinx,autobiny:n.autobiny,bingroup:n.bingroup,xbingroup:n.xbingroup,ybingroup:n.ybingroup,autocontour:i.autocontour,ncontours:i.ncontours,contours:i.contours,line:{color:i.line.color,width:s({},i.line.width,{dflt:.5}),dash:i.line.dash,smoothing:i.line.smoothing,editType:"plot"},xhoverformat:o("x"),yhoverformat:o("y"),zhoverformat:o("z",1),hovertemplate:n.hovertemplate,texttemplate:i.texttemplate,textfont:i.textfont},a("",{cLetter:"z",editTypeOverride:"calc"}))},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/cartesian/axis_format_attributes":557,"../contour/attributes":735,"../histogram2d/attributes":825}],832:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../histogram2d/sample_defaults"),a=t("../contour/contours_defaults"),o=t("../contour/style_defaults"),s=t("../heatmap/label_defaults"),l=t("./attributes");e.exports=function(t,e,r,c){function u(r,i){return n.coerce(t,e,l,r,i)}i(t,e,u,c),!1!==e.visible&&(a(t,e,u,(function(r){return n.coerce2(t,e,l,r)})),o(t,e,u,c),u("xhoverformat"),u("yhoverformat"),u("hovertemplate"),e.contours&&"heatmap"===e.contours.coloring&&s(u,c))}},{"../../lib":503,"../contour/contours_defaults":742,"../contour/style_defaults":756,"../heatmap/label_defaults":802,"../histogram2d/sample_defaults":830,"./attributes":831}],833:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),crossTraceDefaults:t("../histogram/cross_trace_defaults"),calc:t("../contour/calc"),plot:t("../contour/plot").plot,layerName:"contourlayer",style:t("../contour/style"),colorbar:t("../contour/colorbar"),hoverPoints:t("../contour/hover"),moduleType:"trace",name:"histogram2dcontour",basePlotModule:t("../../plots/cartesian"),categories:["cartesian","svg","2dMap","contour","histogram","showLegend"],meta:{}}},{"../../plots/cartesian":568,"../contour/calc":736,"../contour/colorbar":738,"../contour/hover":748,"../contour/plot":753,"../contour/style":755,"../histogram/cross_trace_defaults":819,"./attributes":831,"./defaults":832}],834:[function(t,e,r){"use strict";var n=t("../../plots/template_attributes").hovertemplateAttrs,i=t("../../plots/template_attributes").texttemplateAttrs,a=t("../../components/colorscale/attributes"),o=t("../../plots/domain").attributes,s=t("../pie/attributes"),l=t("../sunburst/attributes"),c=t("../treemap/attributes"),u=t("../treemap/constants"),f=t("../../lib/extend").extendFlat;e.exports={labels:l.labels,parents:l.parents,values:l.values,branchvalues:l.branchvalues,count:l.count,level:l.level,maxdepth:l.maxdepth,tiling:{orientation:{valType:"enumerated",values:["v","h"],dflt:"h",editType:"plot"},flip:c.tiling.flip,pad:{valType:"number",min:0,dflt:0,editType:"plot"},editType:"calc"},marker:f({colors:l.marker.colors,line:l.marker.line,editType:"calc"},a("marker",{colorAttr:"colors",anim:!1})),leaf:l.leaf,pathbar:c.pathbar,text:s.text,textinfo:l.textinfo,texttemplate:i({editType:"plot"},{keys:u.eventDataKeys.concat(["label","value"])}),hovertext:s.hovertext,hoverinfo:l.hoverinfo,hovertemplate:n({},{keys:u.eventDataKeys}),textfont:s.textfont,insidetextfont:s.insidetextfont,outsidetextfont:c.outsidetextfont,textposition:c.textposition,sort:s.sort,root:l.root,domain:o({name:"icicle",trace:!0,editType:"calc"})}},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/domain":584,"../../plots/template_attributes":633,"../pie/attributes":901,"../sunburst/attributes":1049,"../treemap/attributes":1075,"../treemap/constants":1078}],835:[function(t,e,r){"use strict";var n=t("../../plots/plots");r.name="icicle",r.plot=function(t,e,i,a){n.plotBasePlot(r.name,t,e,i,a)},r.clean=function(t,e,i,a){n.cleanBasePlot(r.name,t,e,i,a)}},{"../../plots/plots":619}],836:[function(t,e,r){"use strict";var n=t("../sunburst/calc");r.calc=function(t,e){return n.calc(t,e)},r.crossTraceCalc=function(t){return n._runCrossTraceCalc("icicle",t)}},{"../sunburst/calc":1051}],837:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./attributes"),a=t("../../components/color"),o=t("../../plots/domain").defaults,s=t("../bar/defaults").handleText,l=t("../bar/constants").TEXTPAD,c=t("../../components/colorscale"),u=c.hasColorscale,f=c.handleDefaults;e.exports=function(t,e,r,c){function h(r,a){return n.coerce(t,e,i,r,a)}var p=h("labels"),d=h("parents");if(p&&p.length&&d&&d.length){var m=h("values");m&&m.length?h("branchvalues"):h("count"),h("level"),h("maxdepth"),h("tiling.orientation"),h("tiling.flip"),h("tiling.pad");var g=h("text");h("texttemplate"),e.texttemplate||h("textinfo",Array.isArray(g)?"text+label":"label"),h("hovertext"),h("hovertemplate");var v=h("pathbar.visible");s(t,e,c,h,"auto",{hasPathbar:v,moduleHasSelected:!1,moduleHasUnselected:!1,moduleHasConstrain:!1,moduleHasCliponaxis:!1,moduleHasTextangle:!1,moduleHasInsideanchor:!1}),h("textposition"),h("marker.line.width")&&h("marker.line.color",c.paper_bgcolor),h("marker.colors");var y=e._hasColorscale=u(t,"marker","colors")||(t.marker||{}).coloraxis;y&&f(t,e,c,h,{prefix:"marker.",cLetter:"c"}),h("leaf.opacity",y?1:.7),e._hovered={marker:{line:{width:2,color:a.contrast(c.paper_bgcolor)}}},v&&(h("pathbar.thickness",e.pathbar.textfont.size+2*l),h("pathbar.side"),h("pathbar.edgeshape")),h("sort"),h("root.color"),o(e,c,h),e._length=null}else e.visible=!1}},{"../../components/color":366,"../../components/colorscale":378,"../../lib":503,"../../plots/domain":584,"../bar/constants":650,"../bar/defaults":652,"./attributes":834}],838:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../../components/drawing"),o=t("../../lib/svg_text_utils"),s=t("./partition"),l=t("./style").styleOne,c=t("../treemap/constants"),u=t("../sunburst/helpers"),f=t("../sunburst/fx"),h=t("../sunburst/plot").formatSliceLabel;e.exports=function(t,e,r,p,d){var m=d.width,g=d.height,v=d.viewX,y=d.viewY,x=d.pathSlice,b=d.toMoveInsideSlice,_=d.strTransform,w=d.hasTransition,T=d.handleSlicesExit,k=d.makeUpdateSliceInterpolator,A=d.makeUpdateTextInterpolator,M=d.prevEntry,S=t._fullLayout,E=e[0].trace,L=-1!==E.textposition.indexOf("left"),C=-1!==E.textposition.indexOf("right"),P=-1!==E.textposition.indexOf("bottom"),I=s(r,[m,g],{flipX:E.tiling.flip.indexOf("x")>-1,flipY:E.tiling.flip.indexOf("y")>-1,orientation:E.tiling.orientation,pad:{inner:E.tiling.pad},maxDepth:E._maxDepth}).descendants(),O=1/0,z=-1/0;I.forEach((function(t){var e=t.depth;e>=E._maxDepth?(t.x0=t.x1=(t.x0+t.x1)/2,t.y0=t.y1=(t.y0+t.y1)/2):(O=Math.min(O,e),z=Math.max(z,e))})),p=p.data(I,u.getPtId),E._maxVisibleLayers=isFinite(z)?z-O+1:0,p.enter().append("g").classed("slice",!0),T(p,!1,{},[m,g],x),p.order();var D=null;if(w&&M){var R=u.getPtId(M);p.each((function(t){null===D&&u.getPtId(t)===R&&(D={x0:t.x0,x1:t.x1,y0:t.y0,y1:t.y1})}))}var F=function(){return D||{x0:0,x1:m,y0:0,y1:g}},B=p;return w&&(B=B.transition().each("end",(function(){var e=n.select(this);u.setSliceCursor(e,t,{hideOnRoot:!0,hideOnLeaves:!1,isTransitioning:!1})}))),B.each((function(s){s._x0=v(s.x0),s._x1=v(s.x1),s._y0=y(s.y0),s._y1=y(s.y1),s._hoverX=v(s.x1-E.tiling.pad),s._hoverY=y(P?s.y1-E.tiling.pad/2:s.y0+E.tiling.pad/2);var p=n.select(this),d=i.ensureSingle(p,"path","surface",(function(t){t.style("pointer-events","all")}));w?d.transition().attrTween("d",(function(t){var e=k(t,!1,F(),[m,g],{orientation:E.tiling.orientation,flipX:E.tiling.flip.indexOf("x")>-1,flipY:E.tiling.flip.indexOf("y")>-1});return function(t){return x(e(t))}})):d.attr("d",x),p.call(f,r,t,e,{styleOne:l,eventDataKeys:c.eventDataKeys,transitionTime:c.CLICK_TRANSITION_TIME,transitionEasing:c.CLICK_TRANSITION_EASING}).call(u.setSliceCursor,t,{isTransitioning:t._transitioning}),d.call(l,s,E,{hovered:!1}),s.x0===s.x1||s.y0===s.y1?s._text="":s._text=h(s,r,E,e,S)||"";var T=i.ensureSingle(p,"g","slicetext"),M=i.ensureSingle(T,"text","",(function(t){t.attr("data-notex",1)})),I=i.ensureUniformFontSize(t,u.determineTextFont(E,s,S.font));M.text(s._text||" ").classed("slicetext",!0).attr("text-anchor",C?"end":L?"start":"middle").call(a.font,I).call(o.convertToTspans,t),s.textBB=a.bBox(M.node()),s.transform=b(s,{fontSize:I.size}),s.transform.fontSize=I.size,w?M.transition().attrTween("transform",(function(t){var e=A(t,!1,F(),[m,g]);return function(t){return _(e(t))}})):M.attr("transform",_(s))})),D}},{"../../components/drawing":388,"../../lib":503,"../../lib/svg_text_utils":529,"../sunburst/fx":1054,"../sunburst/helpers":1055,"../sunburst/plot":1059,"../treemap/constants":1078,"./partition":842,"./style":844,"@plotly/d3":58}],839:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"icicle",basePlotModule:t("./base_plot"),categories:[],animatable:!0,attributes:t("./attributes"),layoutAttributes:t("./layout_attributes"),supplyDefaults:t("./defaults"),supplyLayoutDefaults:t("./layout_defaults"),calc:t("./calc").calc,crossTraceCalc:t("./calc").crossTraceCalc,plot:t("./plot"),style:t("./style").style,colorbar:t("../scatter/marker_colorbar"),meta:{}}},{"../scatter/marker_colorbar":945,"./attributes":834,"./base_plot":835,"./calc":836,"./defaults":837,"./layout_attributes":840,"./layout_defaults":841,"./plot":843,"./style":844}],840:[function(t,e,r){"use strict";e.exports={iciclecolorway:{valType:"colorlist",editType:"calc"},extendiciclecolors:{valType:"boolean",dflt:!0,editType:"calc"}}},{}],841:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./layout_attributes");e.exports=function(t,e){function r(r,a){return n.coerce(t,e,i,r,a)}r("iciclecolorway",e.colorway),r("extendiciclecolors")}},{"../../lib":503,"./layout_attributes":840}],842:[function(t,e,r){"use strict";var n=t("d3-hierarchy"),i=t("../treemap/flip_tree");e.exports=function(t,e,r){var a=r.flipX,o=r.flipY,s="h"===r.orientation,l=r.maxDepth,c=e[0],u=e[1];l&&(c=(t.height+1)*e[0]/Math.min(t.height+1,l),u=(t.height+1)*e[1]/Math.min(t.height+1,l));var f=n.partition().padding(r.pad.inner).size(s?[e[1],c]:[e[0],u])(t);return(s||a||o)&&i(f,e,{swapXY:s,flipX:a,flipY:o}),f}},{"../treemap/flip_tree":1083,"d3-hierarchy":115}],843:[function(t,e,r){"use strict";var n=t("../treemap/draw"),i=t("./draw_descendants");e.exports=function(t,e,r,a){return n(t,e,r,a,{type:"icicle",drawDescendants:i})}},{"../treemap/draw":1080,"./draw_descendants":838}],844:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/color"),a=t("../../lib"),o=t("../bar/uniform_text").resizeText;function s(t,e,r){var n=e.data.data,o=!e.children,s=n.i,l=a.castOption(r,s,"marker.line.color")||i.defaultLine,c=a.castOption(r,s,"marker.line.width")||0;t.style("stroke-width",c).call(i.fill,n.color).call(i.stroke,l).style("opacity",o?r.leaf.opacity:null)}e.exports={style:function(t){var e=t._fullLayout._iciclelayer.selectAll(".trace");o(t,e,"icicle"),e.each((function(t){var e=n.select(this),r=t[0].trace;e.style("opacity",r.opacity),e.selectAll("path.surface").each((function(t){n.select(this).call(s,t,r)}))}))},styleOne:s}},{"../../components/color":366,"../../lib":503,"../bar/uniform_text":664,"@plotly/d3":58}],845:[function(t,e,r){"use strict";for(var n=t("../../plots/attributes"),i=t("../../plots/template_attributes").hovertemplateAttrs,a=t("../../lib/extend").extendFlat,o=t("./constants").colormodel,s=["rgb","rgba","rgba256","hsl","hsla"],l=[],c=[],u=0;u<s.length;u++){var f=o[s[u]];l.push("For the `"+s[u]+"` colormodel, it is ["+(f.zminDflt||f.min).join(", ")+"]."),c.push("For the `"+s[u]+"` colormodel, it is ["+(f.zmaxDflt||f.max).join(", ")+"].")}e.exports=a({source:{valType:"string",editType:"calc"},z:{valType:"data_array",editType:"calc"},colormodel:{valType:"enumerated",values:s,editType:"calc"},zsmooth:{valType:"enumerated",values:["fast",!1],dflt:!1,editType:"plot"},zmin:{valType:"info_array",items:[{valType:"number",editType:"calc"},{valType:"number",editType:"calc"},{valType:"number",editType:"calc"},{valType:"number",editType:"calc"}],editType:"calc"},zmax:{valType:"info_array",items:[{valType:"number",editType:"calc"},{valType:"number",editType:"calc"},{valType:"number",editType:"calc"},{valType:"number",editType:"calc"}],editType:"calc"},x0:{valType:"any",dflt:0,editType:"calc+clearAxisTypes"},y0:{valType:"any",dflt:0,editType:"calc+clearAxisTypes"},dx:{valType:"number",dflt:1,editType:"calc"},dy:{valType:"number",dflt:1,editType:"calc"},text:{valType:"data_array",editType:"plot"},hovertext:{valType:"data_array",editType:"plot"},hoverinfo:a({},n.hoverinfo,{flags:["x","y","z","color","name","text"],dflt:"x+y+z+text+name"}),hovertemplate:i({},{keys:["z","color","colormodel"]}),transforms:void 0})},{"../../lib/extend":493,"../../plots/attributes":550,"../../plots/template_attributes":633,"./constants":847}],846:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./constants"),a=t("fast-isnumeric"),o=t("../../plots/cartesian/axes"),s=t("../../lib").maxRowLength,l=t("./helpers").getImageSize;function c(t,e,r,i){return function(a){return n.constrain((a-t)*e,r,i)}}function u(t,e){return function(r){return n.constrain(r,t,e)}}e.exports=function(t,e){var r,n;if(e._hasZ)r=e.z.length,n=s(e.z);else if(e._hasSource){var f=l(e.source);r=f.height,n=f.width}var h,p=o.getFromId(t,e.xaxis||"x"),d=o.getFromId(t,e.yaxis||"y"),m=p.d2c(e.x0)-e.dx/2,g=d.d2c(e.y0)-e.dy/2,v=[m,m+n*e.dx],y=[g,g+r*e.dy];if(p&&"log"===p.type)for(h=0;h<n;h++)v.push(m+h*e.dx);if(d&&"log"===d.type)for(h=0;h<r;h++)y.push(g+h*e.dy);return e._extremes[p._id]=o.findExtremes(p,v),e._extremes[d._id]=o.findExtremes(d,y),e._scaler=function(t){var e=i.colormodel[t.colormodel],r=(e.colormodel||t.colormodel).length;t._sArray=[];for(var n=0;n<r;n++)e.min[n]!==t.zmin[n]||e.max[n]!==t.zmax[n]?t._sArray.push(c(t.zmin[n],(e.max[n]-e.min[n])/(t.zmax[n]-t.zmin[n]),e.min[n],e.max[n])):t._sArray.push(u(e.min[n],e.max[n]));return function(e){for(var n=e.slice(0,r),i=0;i<r;i++){var o=n[i];if(!a(o))return!1;n[i]=t._sArray[i](o)}return n}}(e),[{x0:m,y0:g,z:e.z,w:n,h:r}]}},{"../../lib":503,"../../plots/cartesian/axes":554,"./constants":847,"./helpers":850,"fast-isnumeric":190}],847:[function(t,e,r){"use strict";e.exports={colormodel:{rgb:{min:[0,0,0],max:[255,255,255],fmt:function(t){return t.slice(0,3)},suffix:["","",""]},rgba:{min:[0,0,0,0],max:[255,255,255,1],fmt:function(t){return t.slice(0,4)},suffix:["","","",""]},rgba256:{colormodel:"rgba",zminDflt:[0,0,0,0],zmaxDflt:[255,255,255,255],min:[0,0,0,0],max:[255,255,255,1],fmt:function(t){return t.slice(0,4)},suffix:["","","",""]},hsl:{min:[0,0,0],max:[360,100,100],fmt:function(t){var e=t.slice(0,3);return e[1]=e[1]+"%",e[2]=e[2]+"%",e},suffix:["\xb0","%","%"]},hsla:{min:[0,0,0,0],max:[360,100,100,1],fmt:function(t){var e=t.slice(0,4);return e[1]=e[1]+"%",e[2]=e[2]+"%",e},suffix:["\xb0","%","%",""]}},pixelatedStyle:["image-rendering: optimizeSpeed","image-rendering: -moz-crisp-edges","image-rendering: -o-crisp-edges","image-rendering: -webkit-optimize-contrast","image-rendering: optimize-contrast","image-rendering: crisp-edges","image-rendering: pixelated",""].join("; ")}},{}],848:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./attributes"),a=t("./constants"),o=t("../../snapshot/helpers").IMAGE_URL_PREFIX;e.exports=function(t,e){function r(r,a){return n.coerce(t,e,i,r,a)}r("source"),e.source&&!e.source.match(o)&&delete e.source,e._hasSource=!!e.source;var s,l=r("z");(e._hasZ=!(void 0===l||!l.length||!l[0]||!l[0].length),e._hasZ||e._hasSource)?(r("x0"),r("y0"),r("dx"),r("dy"),e._hasZ?(r("colormodel","rgb"),r("zmin",(s=a.colormodel[e.colormodel]).zminDflt||s.min),r("zmax",s.zmaxDflt||s.max)):e._hasSource&&(e.colormodel="rgba256",s=a.colormodel[e.colormodel],e.zmin=s.zminDflt,e.zmax=s.zmaxDflt),r("zsmooth"),r("text"),r("hovertext"),r("hovertemplate"),e._length=null):e.visible=!1}},{"../../lib":503,"../../snapshot/helpers":642,"./attributes":845,"./constants":847}],849:[function(t,e,r){"use strict";e.exports=function(t,e){return"xVal"in e&&(t.x=e.xVal),"yVal"in e&&(t.y=e.yVal),e.xa&&(t.xaxis=e.xa),e.ya&&(t.yaxis=e.ya),t.color=e.color,t.colormodel=e.trace.colormodel,t.z||(t.z=e.color),t}},{}],850:[function(t,e,r){"use strict";var n=t("probe-image-size/sync"),i=t("../../snapshot/helpers").IMAGE_URL_PREFIX,a=t("buffer/").Buffer;r.getImageSize=function(t){var e=t.replace(i,""),r=new a(e,"base64");return n(r)}},{"../../snapshot/helpers":642,"buffer/":85,"probe-image-size/sync":276}],851:[function(t,e,r){"use strict";var n=t("../../components/fx"),i=t("../../lib"),a=t("./constants");e.exports=function(t,e,r){var o=t.cd[0],s=o.trace,l=t.xa,c=t.ya;if(!(n.inbox(e-o.x0,e-(o.x0+o.w*s.dx),0)>0||n.inbox(r-o.y0,r-(o.y0+o.h*s.dy),0)>0)){var u,f=Math.floor((e-o.x0)/s.dx),h=Math.floor(Math.abs(r-o.y0)/s.dy);if(s._hasZ?u=o.z[h][f]:s._hasSource&&(u=s._canvas.el.getContext("2d",{willReadFrequently:!0}).getImageData(f,h,1,1).data),u){var p,d=o.hi||s.hoverinfo;if(d){var m=d.split("+");-1!==m.indexOf("all")&&(m=["color"]),-1!==m.indexOf("color")&&(p=!0)}var g,v=a.colormodel[s.colormodel],y=v.colormodel||s.colormodel,x=y.length,b=s._scaler(u),_=v.suffix,w=[];(s.hovertemplate||p)&&(w.push("["+[b[0]+_[0],b[1]+_[1],b[2]+_[2]].join(", ")),4===x&&w.push(", "+b[3]+_[3]),w.push("]"),w=w.join(""),t.extraText=y.toUpperCase()+": "+w),Array.isArray(s.hovertext)&&Array.isArray(s.hovertext[h])?g=s.hovertext[h][f]:Array.isArray(s.text)&&Array.isArray(s.text[h])&&(g=s.text[h][f]);var T=c.c2p(o.y0+(h+.5)*s.dy),k=o.x0+(f+.5)*s.dx,A=o.y0+(h+.5)*s.dy,M="["+u.slice(0,s.colormodel.length).join(", ")+"]";return[i.extendFlat(t,{index:[h,f],x0:l.c2p(o.x0+f*s.dx),x1:l.c2p(o.x0+(f+1)*s.dx),y0:T,y1:T,color:b,xVal:k,xLabelVal:k,yVal:A,yLabelVal:A,zLabelVal:M,text:g,hovertemplateLabels:{zLabel:M,colorLabel:w,"color[0]Label":b[0]+_[0],"color[1]Label":b[1]+_[1],"color[2]Label":b[2]+_[2],"color[3]Label":b[3]+_[3]}})]}}}},{"../../components/fx":406,"../../lib":503,"./constants":847}],852:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),calc:t("./calc"),plot:t("./plot"),style:t("./style"),hoverPoints:t("./hover"),eventData:t("./event_data"),moduleType:"trace",name:"image",basePlotModule:t("../../plots/cartesian"),categories:["cartesian","svg","2dMap","noSortingByValue"],animatable:!1,meta:{}}},{"../../plots/cartesian":568,"./attributes":845,"./calc":846,"./defaults":848,"./event_data":849,"./hover":851,"./plot":853,"./style":854}],853:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=i.strTranslate,o=t("../../constants/xmlns_namespaces"),s=t("./constants"),l=i.isIOS()||i.isSafari()||i.isIE();e.exports=function(t,e,r,c){var u=e.xaxis,f=e.yaxis,h=!(l||t._context._exportedPlot);i.makeTraceGroups(c,r,"im").each((function(e){var r=n.select(this),l=e[0],c=l.trace,p=("fast"===c.zsmooth||!1===c.zsmooth&&h)&&!c._hasZ&&c._hasSource&&"linear"===u.type&&"linear"===f.type;c._realImage=p;var d,m,g,v,y,x,b=l.z,_=l.x0,w=l.y0,T=l.w,k=l.h,A=c.dx,M=c.dy;for(x=0;void 0===d&&x<T;)d=u.c2p(_+x*A),x++;for(x=T;void 0===m&&x>0;)m=u.c2p(_+x*A),x--;for(x=0;void 0===v&&x<k;)v=f.c2p(w+x*M),x++;for(x=k;void 0===y&&x>0;)y=f.c2p(w+x*M),x--;if(m<d&&(g=m,m=d,d=g),y<v&&(g=v,v=y,y=g),!p){d=Math.max(-.5*u._length,d),m=Math.min(1.5*u._length,m),v=Math.max(-.5*f._length,v),y=Math.min(1.5*f._length,y)}var S=Math.round(m-d),E=Math.round(y-v);if(S<=0||E<=0){r.selectAll("image").data([]).exit().remove()}else{var L=r.selectAll("image").data([e]);L.enter().append("svg:image").attr({xmlns:o.svg,preserveAspectRatio:"none"}),L.exit().remove();var C=!1===c.zsmooth?s.pixelatedStyle:"";if(p){var P=i.simpleMap(u.range,u.r2l),I=i.simpleMap(f.range,f.r2l),O=P[1]<P[0],z=I[1]>I[0];if(O||z){var D=d+S/2,R=v+E/2;C+="transform:"+a(D+"px",R+"px")+"scale("+(O?-1:1)+","+(z?-1:1)+")"+a(-D+"px",-R+"px")+";"}}L.attr("style",C);var F=new Promise((function(t){if(c._hasZ)t();else if(c._hasSource)if(c._canvas&&c._canvas.el.width===T&&c._canvas.el.height===k&&c._canvas.source===c.source)t();else{var e=document.createElement("canvas");e.width=T,e.height=k;var r=e.getContext("2d",{willReadFrequently:!0});c._image=c._image||new Image;var n=c._image;n.onload=function(){r.drawImage(n,0,0),c._canvas={el:e,source:c.source},t()},n.setAttribute("src",c.source)}})).then((function(){var t;if(c._hasZ)t=B((function(t,e){return b[e][t]})).toDataURL("image/png");else if(c._hasSource)if(p)t=c.source;else{var e=c._canvas.el.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,T,k).data;t=B((function(t,r){var n=4*(r*T+t);return[e[n],e[n+1],e[n+2],e[n+3]]})).toDataURL("image/png")}L.attr({"xlink:href":t,height:E,width:S,x:d,y:v})}));t._promises.push(F)}function B(t){var e=document.createElement("canvas");e.width=S,e.height=E;var r,n=e.getContext("2d",{willReadFrequently:!0}),a=function(t){return i.constrain(Math.round(u.c2p(_+t*A)-d),0,S)},o=function(t){return i.constrain(Math.round(f.c2p(w+t*M)-v),0,E)},h=s.colormodel[c.colormodel],p=h.colormodel||c.colormodel,m=h.fmt;for(x=0;x<l.w;x++){var g=a(x),y=a(x+1);if(y!==g&&!isNaN(y)&&!isNaN(g))for(var b=0;b<l.h;b++){var T=o(b),k=o(b+1);k===T||isNaN(k)||isNaN(T)||!t(x,b)||(r=c._scaler(t(x,b)),n.fillStyle=r?p+"("+m(r).join(",")+")":"rgba(0,0,0,0)",n.fillRect(g,T,y-g,k-T))}}return e}}))}},{"../../constants/xmlns_namespaces":480,"../../lib":503,"./constants":847,"@plotly/d3":58}],854:[function(t,e,r){"use strict";var n=t("@plotly/d3");e.exports=function(t){n.select(t).selectAll(".im image").style("opacity",(function(t){return t[0].trace.opacity}))}},{"@plotly/d3":58}],855:[function(t,e,r){"use strict";var n=t("../../lib/extend").extendFlat,i=t("../../lib/extend").extendDeep,a=t("../../plot_api/edit_types").overrideAll,o=t("../../plots/font_attributes"),s=t("../../components/color/attributes"),l=t("../../plots/domain").attributes,c=t("../../plots/cartesian/layout_attributes"),u=t("../../plot_api/plot_template").templatedArray,f=t("../../constants/delta.js"),h=t("../../plots/cartesian/axis_format_attributes").descriptionOnlyNumbers,p=o({editType:"plot",colorEditType:"plot"}),d={color:{valType:"color",editType:"plot"},line:{color:{valType:"color",dflt:s.defaultLine,editType:"plot"},width:{valType:"number",min:0,dflt:0,editType:"plot"},editType:"calc"},thickness:{valType:"number",min:0,max:1,dflt:1,editType:"plot"},editType:"calc"},m={valType:"info_array",items:[{valType:"number",editType:"plot"},{valType:"number",editType:"plot"}],editType:"plot"},g=u("step",i({},d,{range:m}));e.exports={mode:{valType:"flaglist",editType:"calc",flags:["number","delta","gauge"],dflt:"number"},value:{valType:"number",editType:"calc",anim:!0},align:{valType:"enumerated",values:["left","center","right"],editType:"plot"},domain:l({name:"indicator",trace:!0,editType:"calc"}),title:{text:{valType:"string",editType:"plot"},align:{valType:"enumerated",values:["left","center","right"],editType:"plot"},font:n({},p,{}),editType:"plot"},number:{valueformat:{valType:"string",dflt:"",editType:"plot",description:h("value")},font:n({},p,{}),prefix:{valType:"string",dflt:"",editType:"plot"},suffix:{valType:"string",dflt:"",editType:"plot"},editType:"plot"},delta:{reference:{valType:"number",editType:"calc"},position:{valType:"enumerated",values:["top","bottom","left","right"],dflt:"bottom",editType:"plot"},relative:{valType:"boolean",editType:"plot",dflt:!1},valueformat:{valType:"string",editType:"plot",description:h("value")},increasing:{symbol:{valType:"string",dflt:f.INCREASING.SYMBOL,editType:"plot"},color:{valType:"color",dflt:f.INCREASING.COLOR,editType:"plot"},editType:"plot"},decreasing:{symbol:{valType:"string",dflt:f.DECREASING.SYMBOL,editType:"plot"},color:{valType:"color",dflt:f.DECREASING.COLOR,editType:"plot"},editType:"plot"},font:n({},p,{}),editType:"calc"},gauge:{shape:{valType:"enumerated",editType:"plot",dflt:"angular",values:["angular","bullet"]},bar:i({},d,{color:{dflt:"green"}}),bgcolor:{valType:"color",editType:"plot"},bordercolor:{valType:"color",dflt:s.defaultLine,editType:"plot"},borderwidth:{valType:"number",min:0,dflt:1,editType:"plot"},axis:a({range:m,visible:n({},c.visible,{dflt:!0}),tickmode:c.tickmode,nticks:c.nticks,tick0:c.tick0,dtick:c.dtick,tickvals:c.tickvals,ticktext:c.ticktext,ticks:n({},c.ticks,{dflt:"outside"}),ticklen:c.ticklen,tickwidth:c.tickwidth,tickcolor:c.tickcolor,ticklabelstep:c.ticklabelstep,showticklabels:c.showticklabels,tickfont:o({}),tickangle:c.tickangle,tickformat:c.tickformat,tickformatstops:c.tickformatstops,tickprefix:c.tickprefix,showtickprefix:c.showtickprefix,ticksuffix:c.ticksuffix,showticksuffix:c.showticksuffix,separatethousands:c.separatethousands,exponentformat:c.exponentformat,minexponent:c.minexponent,showexponent:c.showexponent,editType:"plot"},"plot"),steps:g,threshold:{line:{color:n({},d.line.color,{}),width:n({},d.line.width,{dflt:1}),editType:"plot"},thickness:n({},d.thickness,{dflt:.85}),value:{valType:"number",editType:"calc",dflt:!1},editType:"plot"},editType:"plot"}}},{"../../components/color/attributes":365,"../../constants/delta.js":473,"../../lib/extend":493,"../../plot_api/edit_types":536,"../../plot_api/plot_template":543,"../../plots/cartesian/axis_format_attributes":557,"../../plots/cartesian/layout_attributes":569,"../../plots/domain":584,"../../plots/font_attributes":585}],856:[function(t,e,r){"use strict";var n=t("../../plots/plots");r.name="indicator",r.plot=function(t,e,i,a){n.plotBasePlot(r.name,t,e,i,a)},r.clean=function(t,e,i,a){n.cleanBasePlot(r.name,t,e,i,a)}},{"../../plots/plots":619}],857:[function(t,e,r){"use strict";e.exports={calc:function(t,e){var r=[],n=e.value;"number"!=typeof e._lastValue&&(e._lastValue=e.value);var i=e._lastValue,a=i;return e._hasDelta&&"number"==typeof e.delta.reference&&(a=e.delta.reference),r[0]={y:n,lastY:i,delta:n-a,relativeDelta:(n-a)/a},r}}},{}],858:[function(t,e,r){"use strict";e.exports={defaultNumberFontSize:80,bulletNumberDomainSize:.25,bulletPadding:.025,innerRadius:.75,valueThickness:.5,titlePadding:5,horizontalPadding:10}},{}],859:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./attributes"),a=t("../../plots/domain").defaults,o=t("../../plot_api/plot_template"),s=t("../../plots/array_container_defaults"),l=t("./constants.js"),c=t("../../plots/cartesian/tick_value_defaults"),u=t("../../plots/cartesian/tick_mark_defaults"),f=t("../../plots/cartesian/tick_label_defaults"),h=t("../../plots/cartesian/prefix_suffix_defaults");function p(t,e){function r(r,a){return n.coerce(t,e,i.gauge.steps,r,a)}r("color"),r("line.color"),r("line.width"),r("range"),r("thickness")}e.exports={supplyDefaults:function(t,e,r,d){function m(r,a){return n.coerce(t,e,i,r,a)}a(e,d,m),m("mode"),e._hasNumber=-1!==e.mode.indexOf("number"),e._hasDelta=-1!==e.mode.indexOf("delta"),e._hasGauge=-1!==e.mode.indexOf("gauge");var g=m("value");e._range=[0,"number"==typeof g?1.5*g:1];var v,y,x,b,_,w,T=new Array(2);function k(t,e){return n.coerce(x,b,i.gauge,t,e)}function A(t,e){return n.coerce(_,w,i.gauge.axis,t,e)}if(e._hasNumber&&(m("number.valueformat"),m("number.font.color",d.font.color),m("number.font.family",d.font.family),m("number.font.size"),void 0===e.number.font.size&&(e.number.font.size=l.defaultNumberFontSize,T[0]=!0),m("number.prefix"),m("number.suffix"),v=e.number.font.size),e._hasDelta&&(m("delta.font.color",d.font.color),m("delta.font.family",d.font.family),m("delta.font.size"),void 0===e.delta.font.size&&(e.delta.font.size=(e._hasNumber?.5:1)*(v||l.defaultNumberFontSize),T[1]=!0),m("delta.reference",e.value),m("delta.relative"),m("delta.valueformat",e.delta.relative?"2%":""),m("delta.increasing.symbol"),m("delta.increasing.color"),m("delta.decreasing.symbol"),m("delta.decreasing.color"),m("delta.position"),y=e.delta.font.size),e._scaleNumbers=(!e._hasNumber||T[0])&&(!e._hasDelta||T[1])||!1,m("title.font.color",d.font.color),m("title.font.family",d.font.family),m("title.font.size",.25*(v||y||l.defaultNumberFontSize)),m("title.text"),e._hasGauge){(x=t.gauge)||(x={}),b=o.newContainer(e,"gauge"),k("shape"),(e._isBullet="bullet"===e.gauge.shape)||m("title.align","center"),(e._isAngular="angular"===e.gauge.shape)||m("align","center"),k("bgcolor",d.paper_bgcolor),k("borderwidth"),k("bordercolor"),k("bar.color"),k("bar.line.color"),k("bar.line.width"),k("bar.thickness",l.valueThickness*("bullet"===e.gauge.shape?.5:1)),s(x,b,{name:"steps",handleItemDefaults:p}),k("threshold.value"),k("threshold.thickness"),k("threshold.line.width"),k("threshold.line.color"),_={},x&&(_=x.axis||{}),w=o.newContainer(b,"axis"),A("visible"),e._range=A("range",e._range);var M={outerTicks:!0};c(_,w,A,"linear"),h(_,w,A,"linear",M),f(_,w,A,"linear",M),u(_,w,A,M)}else m("title.align","center"),m("align","center"),e._isAngular=e._isBullet=!1;e._length=null}}},{"../../lib":503,"../../plot_api/plot_template":543,"../../plots/array_container_defaults":549,"../../plots/cartesian/prefix_suffix_defaults":573,"../../plots/cartesian/tick_label_defaults":578,"../../plots/cartesian/tick_mark_defaults":579,"../../plots/cartesian/tick_value_defaults":580,"../../plots/domain":584,"./attributes":855,"./constants.js":858}],860:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"indicator",basePlotModule:t("./base_plot"),categories:["svg","noOpacity","noHover"],animatable:!0,attributes:t("./attributes"),supplyDefaults:t("./defaults").supplyDefaults,calc:t("./calc").calc,plot:t("./plot"),meta:{}}},{"./attributes":855,"./base_plot":856,"./calc":857,"./defaults":859,"./plot":861}],861:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("d3-interpolate").interpolate,a=t("d3-interpolate").interpolateNumber,o=t("../../lib"),s=o.strScale,l=o.strTranslate,c=o.rad2deg,u=t("../../constants/alignment").MID_SHIFT,f=t("../../components/drawing"),h=t("./constants"),p=t("../../lib/svg_text_utils"),d=t("../../plots/cartesian/axes"),m=t("../../plots/cartesian/axis_defaults"),g=t("../../plots/cartesian/position_defaults"),v=t("../../plots/cartesian/layout_attributes"),y=t("../../components/color"),x={left:"start",center:"middle",right:"end"},b={left:0,center:.5,right:1},_=/[yzafpn\xb5mkMGTPEZY]/;function w(t){return t&&t.duration>0}function T(t){t.each((function(t){y.stroke(n.select(this),t.line.color)})).each((function(t){y.fill(n.select(this),t.color)})).style("stroke-width",(function(t){return t.line.width}))}function k(t,e,r){var n=t._fullLayout,i=o.extendFlat({type:"linear",ticks:"outside",range:r,showline:!0},e),a={type:"linear",_id:"x"+e._id},s={letter:"x",font:n.font,noHover:!0,noTickson:!0};function l(t,e){return o.coerce(i,a,v,t,e)}return m(i,a,l,s,n),g(i,a,l,s),a}function A(t,e,r){return[Math.min(e/t.width,r/t.height),t,e+"x"+r]}function M(t,e,r,i){var a=document.createElementNS("http://www.w3.org/2000/svg","text"),o=n.select(a);return o.text(t).attr("x",0).attr("y",0).attr("text-anchor",r).attr("data-unformatted",t).call(p.convertToTspans,i).call(f.font,e),f.bBox(o.node())}function S(t,e,r,n,i,a){var s="_cache"+e;t[s]&&t[s].key===i||(t[s]={key:i,value:r});var l=o.aggNums(a,null,[t[s].value,n],2);return t[s].value=l,l}e.exports=function(t,e,r,m){var g,v=t._fullLayout;w(r)&&m&&(g=m()),o.makeTraceGroups(v._indicatorlayer,e,"trace").each((function(e){var m,E,L,C,P,I=e[0].trace,O=n.select(this),z=I._hasGauge,D=I._isAngular,R=I._isBullet,F=I.domain,B={w:v._size.w*(F.x[1]-F.x[0]),h:v._size.h*(F.y[1]-F.y[0]),l:v._size.l+v._size.w*F.x[0],r:v._size.r+v._size.w*(1-F.x[1]),t:v._size.t+v._size.h*(1-F.y[1]),b:v._size.b+v._size.h*F.y[0]},N=B.l+B.w/2,j=B.t+B.h/2,U=Math.min(B.w/2,B.h),V=h.innerRadius*U,H=I.align||"center";if(E=j,z){if(D&&(m=N,E=j+U/2,L=function(t){return function(t,e){var r=Math.sqrt(t.width/2*(t.width/2)+t.height*t.height);return[e/r,t,e]}(t,.9*V)}),R){var q=h.bulletPadding,G=1-h.bulletNumberDomainSize+q;m=B.l+(G+(1-G)*b[H])*B.w,L=function(t){return A(t,(h.bulletNumberDomainSize-q)*B.w,B.h)}}}else m=B.l+b[H]*B.w,L=function(t){return A(t,B.w,B.h)};!function(t,e,r,i){var c,u,h,m=r[0].trace,g=i.numbersX,v=i.numbersY,T=m.align||"center",A=x[T],E=i.transitionOpts,L=i.onComplete,C=o.ensureSingle(e,"g","numbers"),P=[];m._hasNumber&&P.push("number");m._hasDelta&&(P.push("delta"),"left"===m.delta.position&&P.reverse());var I=C.selectAll("text").data(P);function O(e,r,n,i){if(!e.match("s")||n>=0==i>=0||r(n).slice(-1).match(_)||r(i).slice(-1).match(_))return r;var a=e.slice().replace("s","f").replace(/\d+/,(function(t){return parseInt(t)-1})),o=k(t,{tickformat:a});return function(t){return Math.abs(t)<1?d.tickText(o,t).text:r(t)}}I.enter().append("text"),I.attr("text-anchor",(function(){return A})).attr("class",(function(t){return t})).attr("x",null).attr("y",null).attr("dx",null).attr("dy",null),I.exit().remove();var z,D=m.mode+m.align;m._hasDelta&&(z=function(){var e=k(t,{tickformat:m.delta.valueformat},m._range);e.setScale(),d.prepTicks(e);var i=function(t){return d.tickText(e,t).text},o=function(t){return m.delta.relative?t.relativeDelta:t.delta},s=function(t,e){return 0===t||"number"!=typeof t||isNaN(t)?"-":(t>0?m.delta.increasing.symbol:m.delta.decreasing.symbol)+e(t)},l=function(t){return t.delta>=0?m.delta.increasing.color:m.delta.decreasing.color};void 0===m._deltaLastValue&&(m._deltaLastValue=o(r[0]));var c=C.select("text.delta");function h(){c.text(s(o(r[0]),i)).call(y.fill,l(r[0])).call(p.convertToTspans,t)}return c.call(f.font,m.delta.font).call(y.fill,l({delta:m._deltaLastValue})),w(E)?c.transition().duration(E.duration).ease(E.easing).tween("text",(function(){var t=n.select(this),e=o(r[0]),c=m._deltaLastValue,u=O(m.delta.valueformat,i,c,e),f=a(c,e);return m._deltaLastValue=e,function(e){t.text(s(f(e),u)),t.call(y.fill,l({delta:f(e)}))}})).each("end",(function(){h(),L&&L()})).each("interrupt",(function(){h(),L&&L()})):h(),u=M(s(o(r[0]),i),m.delta.font,A,t),c}(),D+=m.delta.position+m.delta.font.size+m.delta.font.family+m.delta.valueformat,D+=m.delta.increasing.symbol+m.delta.decreasing.symbol,h=u);m._hasNumber&&(!function(){var e=k(t,{tickformat:m.number.valueformat},m._range);e.setScale(),d.prepTicks(e);var i=function(t){return d.tickText(e,t).text},o=m.number.suffix,s=m.number.prefix,l=C.select("text.number");function u(){var e="number"==typeof r[0].y?s+i(r[0].y)+o:"-";l.text(e).call(f.font,m.number.font).call(p.convertToTspans,t)}w(E)?l.transition().duration(E.duration).ease(E.easing).each("end",(function(){u(),L&&L()})).each("interrupt",(function(){u(),L&&L()})).attrTween("text",(function(){var t=n.select(this),e=a(r[0].lastY,r[0].y);m._lastValue=r[0].y;var l=O(m.number.valueformat,i,r[0].lastY,r[0].y);return function(r){t.text(s+l(e(r))+o)}})):u(),c=M(s+i(r[0].y)+o,m.number.font,A,t)}(),D+=m.number.font.size+m.number.font.family+m.number.valueformat+m.number.suffix+m.number.prefix,h=c);if(m._hasDelta&&m._hasNumber){var R,F,B=[(c.left+c.right)/2,(c.top+c.bottom)/2],N=[(u.left+u.right)/2,(u.top+u.bottom)/2],j=.75*m.delta.font.size;"left"===m.delta.position&&(R=S(m,"deltaPos",0,-1*(c.width*b[m.align]+u.width*(1-b[m.align])+j),D,Math.min),F=B[1]-N[1],h={width:c.width+u.width+j,height:Math.max(c.height,u.height),left:u.left+R,right:c.right,top:Math.min(c.top,u.top+F),bottom:Math.max(c.bottom,u.bottom+F)}),"right"===m.delta.position&&(R=S(m,"deltaPos",0,c.width*(1-b[m.align])+u.width*b[m.align]+j,D,Math.max),F=B[1]-N[1],h={width:c.width+u.width+j,height:Math.max(c.height,u.height),left:c.left,right:u.right+R,top:Math.min(c.top,u.top+F),bottom:Math.max(c.bottom,u.bottom+F)}),"bottom"===m.delta.position&&(R=null,F=u.height,h={width:Math.max(c.width,u.width),height:c.height+u.height,left:Math.min(c.left,u.left),right:Math.max(c.right,u.right),top:c.bottom-c.height,bottom:c.bottom+u.height}),"top"===m.delta.position&&(R=null,F=c.top,h={width:Math.max(c.width,u.width),height:c.height+u.height,left:Math.min(c.left,u.left),right:Math.max(c.right,u.right),top:c.bottom-c.height-u.height,bottom:c.bottom}),z.attr({dx:R,dy:F})}(m._hasNumber||m._hasDelta)&&C.attr("transform",(function(){var t=i.numbersScaler(h);D+=t[2];var e,r=S(m,"numbersScale",1,t[0],D,Math.min);m._scaleNumbers||(r=1),e=m._isAngular?v-r*h.bottom:v-r*(h.top+h.bottom)/2,m._numbersTop=r*h.top+e;var n=h[T];"center"===T&&(n=(h.left+h.right)/2);var a=g-r*n;return a=S(m,"numbersTranslate",0,a,D,Math.max),l(a,e)+s(r)}))}(t,O,e,{numbersX:m,numbersY:E,numbersScaler:L,transitionOpts:r,onComplete:g}),z&&(C={range:I.gauge.axis.range,color:I.gauge.bgcolor,line:{color:I.gauge.bordercolor,width:0},thickness:1},P={range:I.gauge.axis.range,color:"rgba(0, 0, 0, 0)",line:{color:I.gauge.bordercolor,width:I.gauge.borderwidth},thickness:1});var Y=O.selectAll("g.angular").data(D?e:[]);Y.exit().remove();var W=O.selectAll("g.angularaxis").data(D?e:[]);W.exit().remove(),D&&function(t,e,r,a){var o,s,f,h,p=r[0].trace,m=a.size,g=a.radius,v=a.innerRadius,y=a.gaugeBg,x=a.gaugeOutline,b=[m.l+m.w/2,m.t+m.h/2+g/2],_=a.gauge,A=a.layer,M=a.transitionOpts,S=a.onComplete,E=Math.PI/2;function L(t){var e=p.gauge.axis.range[0],r=(t-e)/(p.gauge.axis.range[1]-e)*Math.PI-E;return r<-E?-E:r>E?E:r}function C(t){return n.svg.arc().innerRadius((v+g)/2-t/2*(g-v)).outerRadius((v+g)/2+t/2*(g-v)).startAngle(-E)}function P(t){t.attr("d",(function(t){return C(t.thickness).startAngle(L(t.range[0])).endAngle(L(t.range[1]))()}))}_.enter().append("g").classed("angular",!0),_.attr("transform",l(b[0],b[1])),A.enter().append("g").classed("angularaxis",!0).classed("crisp",!0),A.selectAll("g.xangularaxistick,path,text").remove(),(o=k(t,p.gauge.axis)).type="linear",o.range=p.gauge.axis.range,o._id="xangularaxis",o.ticklabeloverflow="allow",o.setScale();var I=function(t){return(o.range[0]-t.x)/(o.range[1]-o.range[0])*Math.PI+Math.PI},O={},z=d.makeLabelFns(o,0).labelStandoff;O.xFn=function(t){var e=I(t);return Math.cos(e)*z},O.yFn=function(t){var e=I(t),r=Math.sin(e)>0?.2:1;return-Math.sin(e)*(z+t.fontSize*r)+Math.abs(Math.cos(e))*(t.fontSize*u)},O.anchorFn=function(t){var e=I(t),r=Math.cos(e);return Math.abs(r)<.1?"middle":r>0?"start":"end"},O.heightFn=function(t,e,r){var n=I(t);return-.5*(1+Math.sin(n))*r};var D=function(t){return l(b[0]+g*Math.cos(t),b[1]-g*Math.sin(t))};f=function(t){return D(I(t))};if(s=d.calcTicks(o),h=d.getTickSigns(o)[2],o.visible){h="inside"===o.ticks?-1:1;var R=(o.linewidth||1)/2;d.drawTicks(t,o,{vals:s,layer:A,path:"M"+h*R+",0h"+h*o.ticklen,transFn:function(t){var e=I(t);return D(e)+"rotate("+-c(e)+")"}}),d.drawLabels(t,o,{vals:s,layer:A,transFn:f,labelFns:O})}var F=[y].concat(p.gauge.steps),B=_.selectAll("g.bg-arc").data(F);B.enter().append("g").classed("bg-arc",!0).append("path"),B.select("path").call(P).call(T),B.exit().remove();var N=C(p.gauge.bar.thickness),j=_.selectAll("g.value-arc").data([p.gauge.bar]);j.enter().append("g").classed("value-arc",!0).append("path");var U=j.select("path");w(M)?(U.transition().duration(M.duration).ease(M.easing).each("end",(function(){S&&S()})).each("interrupt",(function(){S&&S()})).attrTween("d",(V=N,H=L(r[0].lastY),q=L(r[0].y),function(){var t=i(H,q);return function(e){return V.endAngle(t(e))()}})),p._lastValue=r[0].y):U.attr("d","number"==typeof r[0].y?N.endAngle(L(r[0].y)):"M0,0Z");var V,H,q;U.call(T),j.exit().remove(),F=[];var G=p.gauge.threshold.value;(G||0===G)&&F.push({range:[G,G],color:p.gauge.threshold.color,line:{color:p.gauge.threshold.line.color,width:p.gauge.threshold.line.width},thickness:p.gauge.threshold.thickness});var Y=_.selectAll("g.threshold-arc").data(F);Y.enter().append("g").classed("threshold-arc",!0).append("path"),Y.select("path").call(P).call(T),Y.exit().remove();var W=_.selectAll("g.gauge-outline").data([x]);W.enter().append("g").classed("gauge-outline",!0).append("path"),W.select("path").call(P).call(T),W.exit().remove()}(t,0,e,{radius:U,innerRadius:V,gauge:Y,layer:W,size:B,gaugeBg:C,gaugeOutline:P,transitionOpts:r,onComplete:g});var X=O.selectAll("g.bullet").data(R?e:[]);X.exit().remove();var Z=O.selectAll("g.bulletaxis").data(R?e:[]);Z.exit().remove(),R&&function(t,e,r,n){var i,a,o,s,c,u=r[0].trace,f=n.gauge,p=n.layer,m=n.gaugeBg,g=n.gaugeOutline,v=n.size,x=u.domain,b=n.transitionOpts,_=n.onComplete;f.enter().append("g").classed("bullet",!0),f.attr("transform",l(v.l,v.t)),p.enter().append("g").classed("bulletaxis",!0).classed("crisp",!0),p.selectAll("g.xbulletaxistick,path,text").remove();var A=v.h,M=u.gauge.bar.thickness*A,S=x.x[0],E=x.x[0]+(x.x[1]-x.x[0])*(u._hasNumber||u._hasDelta?1-h.bulletNumberDomainSize:1);(i=k(t,u.gauge.axis))._id="xbulletaxis",i.domain=[S,E],i.setScale(),a=d.calcTicks(i),o=d.makeTransTickFn(i),s=d.getTickSigns(i)[2],c=v.t+v.h,i.visible&&(d.drawTicks(t,i,{vals:"inside"===i.ticks?d.clipEnds(i,a):a,layer:p,path:d.makeTickPath(i,c,s),transFn:o}),d.drawLabels(t,i,{vals:a,layer:p,transFn:o,labelFns:d.makeLabelFns(i,c)}));function L(t){t.attr("width",(function(t){return Math.max(0,i.c2p(t.range[1])-i.c2p(t.range[0]))})).attr("x",(function(t){return i.c2p(t.range[0])})).attr("y",(function(t){return.5*(1-t.thickness)*A})).attr("height",(function(t){return t.thickness*A}))}var C=[m].concat(u.gauge.steps),P=f.selectAll("g.bg-bullet").data(C);P.enter().append("g").classed("bg-bullet",!0).append("rect"),P.select("rect").call(L).call(T),P.exit().remove();var I=f.selectAll("g.value-bullet").data([u.gauge.bar]);I.enter().append("g").classed("value-bullet",!0).append("rect"),I.select("rect").attr("height",M).attr("y",(A-M)/2).call(T),w(b)?I.select("rect").transition().duration(b.duration).ease(b.easing).each("end",(function(){_&&_()})).each("interrupt",(function(){_&&_()})).attr("width",Math.max(0,i.c2p(Math.min(u.gauge.axis.range[1],r[0].y)))):I.select("rect").attr("width","number"==typeof r[0].y?Math.max(0,i.c2p(Math.min(u.gauge.axis.range[1],r[0].y))):0);I.exit().remove();var O=r.filter((function(){return u.gauge.threshold.value||0===u.gauge.threshold.value})),z=f.selectAll("g.threshold-bullet").data(O);z.enter().append("g").classed("threshold-bullet",!0).append("line"),z.select("line").attr("x1",i.c2p(u.gauge.threshold.value)).attr("x2",i.c2p(u.gauge.threshold.value)).attr("y1",(1-u.gauge.threshold.thickness)/2*A).attr("y2",(1-(1-u.gauge.threshold.thickness)/2)*A).call(y.stroke,u.gauge.threshold.line.color).style("stroke-width",u.gauge.threshold.line.width),z.exit().remove();var D=f.selectAll("g.gauge-outline").data([g]);D.enter().append("g").classed("gauge-outline",!0).append("rect"),D.select("rect").call(L).call(T),D.exit().remove()}(t,0,e,{gauge:X,layer:Z,size:B,gaugeBg:C,gaugeOutline:P,transitionOpts:r,onComplete:g});var J=O.selectAll("text.title").data(e);J.exit().remove(),J.enter().append("text").classed("title",!0),J.attr("text-anchor",(function(){return R?x.right:x[I.title.align]})).text(I.title.text).call(f.font,I.title.font).call(p.convertToTspans,t),J.attr("transform",(function(){var t,e=B.l+B.w*b[I.title.align],r=h.titlePadding,n=f.bBox(J.node());if(z){if(D)if(I.gauge.axis.visible)t=f.bBox(W.node()).top-r-n.bottom;else t=B.t+B.h/2-U/2-n.bottom-r;R&&(t=E-(n.top+n.bottom)/2,e=B.l-h.bulletPadding*B.w)}else t=I._numbersTop-r-n.bottom;return l(e,t)}))}))}},{"../../components/color":366,"../../components/drawing":388,"../../constants/alignment":471,"../../lib":503,"../../lib/svg_text_utils":529,"../../plots/cartesian/axes":554,"../../plots/cartesian/axis_defaults":556,"../../plots/cartesian/layout_attributes":569,"../../plots/cartesian/position_defaults":572,"./constants":858,"@plotly/d3":58,"d3-interpolate":116}],862:[function(t,e,r){"use strict";var n=t("../../components/colorscale/attributes"),i=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,a=t("../../plots/template_attributes").hovertemplateAttrs,o=t("../mesh3d/attributes"),s=t("../../plots/attributes"),l=t("../../lib/extend").extendFlat,c=t("../../plot_api/edit_types").overrideAll;var u=e.exports=c(l({x:{valType:"data_array"},y:{valType:"data_array"},z:{valType:"data_array"},value:{valType:"data_array"},isomin:{valType:"number"},isomax:{valType:"number"},surface:{show:{valType:"boolean",dflt:!0},count:{valType:"integer",dflt:2,min:1},fill:{valType:"number",min:0,max:1,dflt:1},pattern:{valType:"flaglist",flags:["A","B","C","D","E"],extras:["all","odd","even"],dflt:"all"}},spaceframe:{show:{valType:"boolean",dflt:!1},fill:{valType:"number",min:0,max:1,dflt:.15}},slices:{x:{show:{valType:"boolean",dflt:!1},locations:{valType:"data_array",dflt:[]},fill:{valType:"number",min:0,max:1,dflt:1}},y:{show:{valType:"boolean",dflt:!1},locations:{valType:"data_array",dflt:[]},fill:{valType:"number",min:0,max:1,dflt:1}},z:{show:{valType:"boolean",dflt:!1},locations:{valType:"data_array",dflt:[]},fill:{valType:"number",min:0,max:1,dflt:1}}},caps:{x:{show:{valType:"boolean",dflt:!0},fill:{valType:"number",min:0,max:1,dflt:1}},y:{show:{valType:"boolean",dflt:!0},fill:{valType:"number",min:0,max:1,dflt:1}},z:{show:{valType:"boolean",dflt:!0},fill:{valType:"number",min:0,max:1,dflt:1}}},text:{valType:"string",dflt:"",arrayOk:!0},hovertext:{valType:"string",dflt:"",arrayOk:!0},hovertemplate:a(),xhoverformat:i("x"),yhoverformat:i("y"),zhoverformat:i("z"),valuehoverformat:i("value",1),showlegend:l({},s.showlegend,{dflt:!1})},n("",{colorAttr:"`value`",showScaleDflt:!0,editTypeOverride:"calc"}),{opacity:o.opacity,lightposition:o.lightposition,lighting:o.lighting,flatshading:o.flatshading,contour:o.contour,hoverinfo:l({},s.hoverinfo)}),"calc","nested");u.flatshading.dflt=!0,u.lighting.facenormalsepsilon.dflt=0,u.x.editType=u.y.editType=u.z.editType=u.value.editType="calc+clearAxisTypes",u.transforms=void 0},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plot_api/edit_types":536,"../../plots/attributes":550,"../../plots/cartesian/axis_format_attributes":557,"../../plots/template_attributes":633,"../mesh3d/attributes":867}],863:[function(t,e,r){"use strict";var n=t("../../components/colorscale/calc"),i=t("../streamtube/calc").processGrid,a=t("../streamtube/calc").filter;e.exports=function(t,e){e._len=Math.min(e.x.length,e.y.length,e.z.length,e.value.length),e._x=a(e.x,e._len),e._y=a(e.y,e._len),e._z=a(e.z,e._len),e._value=a(e.value,e._len);var r=i(e);e._gridFill=r.fill,e._Xs=r.Xs,e._Ys=r.Ys,e._Zs=r.Zs,e._len=r.len;for(var o=1/0,s=-1/0,l=0;l<e._len;l++){var c=e._value[l];o=Math.min(o,c),s=Math.max(s,c)}e._minValues=o,e._maxValues=s,e._vMin=void 0===e.isomin||null===e.isomin?o:e.isomin,e._vMax=void 0===e.isomax||null===e.isomin?s:e.isomax,n(t,e,{vals:[e._vMin,e._vMax],containerStr:"",cLetter:"c"})}},{"../../components/colorscale/calc":374,"../streamtube/calc":1045}],864:[function(t,e,r){"use strict";var n=t("../../../stackgl_modules").gl_mesh3d,i=t("../../lib/gl_format_color").parseColorScale,a=t("../../lib/str2rgbarray"),o=t("../../components/colorscale").extractOpts,s=t("../../plots/gl3d/zip3"),l=function(t,e){for(var r=e.length-1;r>0;r--){var n=Math.min(e[r],e[r-1]),i=Math.max(e[r],e[r-1]);if(i>n&&n<t&&t<=i)return{id:r,distRatio:(i-t)/(i-n)}}return{id:0,distRatio:0}};function c(t,e,r){this.scene=t,this.uid=r,this.mesh=e,this.name="",this.data=null,this.showContour=!1}var u=c.prototype;u.handlePick=function(t){if(t.object===this.mesh){var e=t.data.index,r=this.data._meshX[e],n=this.data._meshY[e],i=this.data._meshZ[e],a=this.data._Ys.length,o=this.data._Zs.length,s=l(r,this.data._Xs).id,c=l(n,this.data._Ys).id,u=l(i,this.data._Zs).id,f=t.index=u+o*c+o*a*s;t.traceCoordinate=[this.data._meshX[f],this.data._meshY[f],this.data._meshZ[f],this.data._value[f]];var h=this.data.hovertext||this.data.text;return Array.isArray(h)&&void 0!==h[f]?t.textLabel=h[f]:h&&(t.textLabel=h),!0}},u.update=function(t){var e=this.scene,r=e.fullSceneLayout;function n(t,e,r,n){return e.map((function(e){return t.d2l(e,0,n)*r}))}this.data=h(t);var l={positions:s(n(r.xaxis,t._meshX,e.dataScale[0],t.xcalendar),n(r.yaxis,t._meshY,e.dataScale[1],t.ycalendar),n(r.zaxis,t._meshZ,e.dataScale[2],t.zcalendar)),cells:s(t._meshI,t._meshJ,t._meshK),lightPosition:[t.lightposition.x,t.lightposition.y,t.lightposition.z],ambient:t.lighting.ambient,diffuse:t.lighting.diffuse,specular:t.lighting.specular,roughness:t.lighting.roughness,fresnel:t.lighting.fresnel,vertexNormalsEpsilon:t.lighting.vertexnormalsepsilon,faceNormalsEpsilon:t.lighting.facenormalsepsilon,opacity:t.opacity,contourEnable:t.contour.show,contourColor:a(t.contour.color).slice(0,3),contourWidth:t.contour.width,useFacetNormals:t.flatshading},c=o(t);l.vertexIntensity=t._meshIntensity,l.vertexIntensityBounds=[c.min,c.max],l.colormap=i(t),this.mesh.update(l)},u.dispose=function(){this.scene.glplot.remove(this.mesh),this.mesh.dispose()};var f=["xyz","xzy","yxz","yzx","zxy","zyx"];function h(t){t._meshI=[],t._meshJ=[],t._meshK=[];var e,r,n,i,a,o,s,c=t.surface.show,u=t.spaceframe.show,h=t.surface.fill,p=t.spaceframe.fill,d=!1,m=!1,g=0,v=t._Xs,y=t._Ys,x=t._Zs,b=v.length,_=y.length,w=x.length,T=f.indexOf(t._gridFill.replace(/-/g,"").replace(/\+/g,"")),k=function(t,e,r){switch(T){case 5:return r+w*e+w*_*t;case 4:return r+w*t+w*b*e;case 3:return e+_*r+_*w*t;case 2:return e+_*t+_*b*r;case 1:return t+b*r+b*w*e;default:return t+b*e+b*_*r}},A=t._minValues,M=t._maxValues,S=t._vMin,E=t._vMax;function L(t,e,s){for(var l=o.length,c=r;c<l;c++)if(t===n[c]&&e===i[c]&&s===a[c])return c;return-1}function C(){r=e}function P(){n=[],i=[],a=[],o=[],e=0,C()}function I(t,r,s,l){return n.push(t),i.push(r),a.push(s),o.push(l),++e-1}function O(t,e,r){for(var n=[],i=0;i<t.length;i++)n[i]=t[i]*(1-r)+r*e[i];return n}function z(t){s=t}function D(t,e){return"all"===t||null===t||t.indexOf(e)>-1}function R(t,e){return null===t?e:t}function F(e,r,n){C();var i,a,o,l=[r],c=[n];if(s>=1)l=[r],c=[n];else if(s>0){var u=function(t,e){var r=t[0],n=t[1],i=t[2],a=function(t,e,r){for(var n=[],i=0;i<t.length;i++)n[i]=(t[i]+e[i]+r[i])/3;return n}(r,n,i),o=Math.sqrt(1-s),l=O(a,r,o),c=O(a,n,o),u=O(a,i,o),f=e[0],h=e[1],p=e[2];return{xyzv:[[r,n,c],[c,l,r],[n,i,u],[u,c,n],[i,r,l],[l,u,i]],abc:[[f,h,-1],[-1,-1,f],[h,p,-1],[-1,-1,h],[p,f,-1],[-1,-1,p]]}}(r,n);l=u.xyzv,c=u.abc}for(var f=0;f<l.length;f++){r=l[f],n=c[f];for(var h=[],p=0;p<3;p++){var d=r[p][0],m=r[p][1],v=r[p][2],y=r[p][3],x=n[p]>-1?n[p]:L(d,m,v);h[p]=x>-1?x:I(d,m,v,R(e,y))}i=h[0],a=h[1],o=h[2],t._meshI.push(i),t._meshJ.push(a),t._meshK.push(o),++g}}function B(t,e,r,n){var i=t[3];i<r&&(i=r),i>n&&(i=n);for(var a=(t[3]-i)/(t[3]-e[3]+1e-9),o=[],s=0;s<4;s++)o[s]=(1-a)*t[s]+a*e[s];return o}function N(t,e,r){return t>=e&&t<=r}function j(t){var e=.001*(E-S);return t>=S-e&&t<=E+e}function U(e){for(var r=[],n=0;n<4;n++){var i=e[n];r.push([t._x[i],t._y[i],t._z[i],t._value[i]])}return r}function V(t,e,r,n,i,a){a||(a=1),r=[-1,-1,-1];var o=!1,s=[N(e[0][3],n,i),N(e[1][3],n,i),N(e[2][3],n,i)];if(!s[0]&&!s[1]&&!s[2])return!1;var l=function(t,e,r){return j(e[0][3])&&j(e[1][3])&&j(e[2][3])?(F(t,e,r),!0):a<3&&V(t,e,r,S,E,++a)};if(s[0]&&s[1]&&s[2])return l(t,e,r)||o;var c=!1;return[[0,1,2],[2,0,1],[1,2,0]].forEach((function(a){if(s[a[0]]&&s[a[1]]&&!s[a[2]]){var u=e[a[0]],f=e[a[1]],h=e[a[2]],p=B(h,u,n,i),d=B(h,f,n,i);o=l(t,[d,p,u],[-1,-1,r[a[0]]])||o,o=l(t,[u,f,d],[r[a[0]],r[a[1]],-1])||o,c=!0}})),c||[[0,1,2],[1,2,0],[2,0,1]].forEach((function(a){if(s[a[0]]&&!s[a[1]]&&!s[a[2]]){var u=e[a[0]],f=e[a[1]],h=e[a[2]],p=B(f,u,n,i),d=B(h,u,n,i);o=l(t,[d,p,u],[-1,-1,r[a[0]]])||o,c=!0}})),o}function H(t,e,r,n){var i=!1,a=U(e),o=[N(a[0][3],r,n),N(a[1][3],r,n),N(a[2][3],r,n),N(a[3][3],r,n)];if(!(o[0]||o[1]||o[2]||o[3]))return i;if(o[0]&&o[1]&&o[2]&&o[3])return m&&(i=function(t,e,r){var n=function(n,i,a){F(t,[e[n],e[i],e[a]],[r[n],r[i],r[a]])};n(0,1,2),n(3,0,1),n(2,3,0),n(1,2,3)}(t,a,e)||i),i;var s=!1;return[[0,1,2,3],[3,0,1,2],[2,3,0,1],[1,2,3,0]].forEach((function(l){if(o[l[0]]&&o[l[1]]&&o[l[2]]&&!o[l[3]]){var c=a[l[0]],u=a[l[1]],f=a[l[2]],h=a[l[3]];if(m)i=F(t,[c,u,f],[e[l[0]],e[l[1]],e[l[2]]])||i;else{var p=B(h,c,r,n),d=B(h,u,r,n),g=B(h,f,r,n);i=F(null,[p,d,g],[-1,-1,-1])||i}s=!0}})),s?i:([[0,1,2,3],[1,2,3,0],[2,3,0,1],[3,0,1,2],[0,2,3,1],[1,3,2,0]].forEach((function(l){if(o[l[0]]&&o[l[1]]&&!o[l[2]]&&!o[l[3]]){var c=a[l[0]],u=a[l[1]],f=a[l[2]],h=a[l[3]],p=B(f,c,r,n),d=B(f,u,r,n),g=B(h,u,r,n),v=B(h,c,r,n);m?(i=F(t,[c,v,p],[e[l[0]],-1,-1])||i,i=F(t,[u,d,g],[e[l[1]],-1,-1])||i):i=function(t,e,r){var n=function(n,i,a){F(t,[e[n],e[i],e[a]],[r[n],r[i],r[a]])};n(0,1,2),n(2,3,0)}(null,[p,d,g,v],[-1,-1,-1,-1])||i,s=!0}})),s||[[0,1,2,3],[1,2,3,0],[2,3,0,1],[3,0,1,2]].forEach((function(l){if(o[l[0]]&&!o[l[1]]&&!o[l[2]]&&!o[l[3]]){var c=a[l[0]],u=a[l[1]],f=a[l[2]],h=a[l[3]],p=B(u,c,r,n),d=B(f,c,r,n),g=B(h,c,r,n);m?(i=F(t,[c,p,d],[e[l[0]],-1,-1])||i,i=F(t,[c,d,g],[e[l[0]],-1,-1])||i,i=F(t,[c,g,p],[e[l[0]],-1,-1])||i):i=F(null,[p,d,g],[-1,-1,-1])||i,s=!0}})),i)}function q(t,e,r,n,i,a,o,s,l,c,u){var f=!1;return d&&(D(t,"A")&&(f=H(null,[e,r,n,a],c,u)||f),D(t,"B")&&(f=H(null,[r,n,i,l],c,u)||f),D(t,"C")&&(f=H(null,[r,a,o,l],c,u)||f),D(t,"D")&&(f=H(null,[n,a,s,l],c,u)||f),D(t,"E")&&(f=H(null,[r,n,a,l],c,u)||f)),m&&(f=H(t,[r,n,a,l],c,u)||f),f}function G(t,e,r,n,i,a,o,s){return[!0===s[0]||V(t,U([e,r,n]),[e,r,n],a,o),!0===s[1]||V(t,U([n,i,e]),[n,i,e],a,o)]}function Y(t,e,r,n,i,a,o,s,l){return s?G(t,e,r,i,n,a,o,l):G(t,r,i,n,e,a,o,l)}function W(t,e,r,n,i,a,o){var s,l,c,u,f=!1,h=function(){f=V(t,[s,l,c],[-1,-1,-1],i,a)||f,f=V(t,[c,u,s],[-1,-1,-1],i,a)||f},p=o[0],d=o[1],m=o[2];return p&&(s=O(U([k(e,r-0,n-0)])[0],U([k(e-1,r-0,n-0)])[0],p),l=O(U([k(e,r-0,n-1)])[0],U([k(e-1,r-0,n-1)])[0],p),c=O(U([k(e,r-1,n-1)])[0],U([k(e-1,r-1,n-1)])[0],p),u=O(U([k(e,r-1,n-0)])[0],U([k(e-1,r-1,n-0)])[0],p),h()),d&&(s=O(U([k(e-0,r,n-0)])[0],U([k(e-0,r-1,n-0)])[0],d),l=O(U([k(e-0,r,n-1)])[0],U([k(e-0,r-1,n-1)])[0],d),c=O(U([k(e-1,r,n-1)])[0],U([k(e-1,r-1,n-1)])[0],d),u=O(U([k(e-1,r,n-0)])[0],U([k(e-1,r-1,n-0)])[0],d),h()),m&&(s=O(U([k(e-0,r-0,n)])[0],U([k(e-0,r-0,n-1)])[0],m),l=O(U([k(e-0,r-1,n)])[0],U([k(e-0,r-1,n-1)])[0],m),c=O(U([k(e-1,r-1,n)])[0],U([k(e-1,r-1,n-1)])[0],m),u=O(U([k(e-1,r-0,n)])[0],U([k(e-1,r-0,n-1)])[0],m),h()),f}function X(t,e,r,n,i,a,o,s,l,c,u,f){var h=t;return f?(d&&"even"===t&&(h=null),q(h,e,r,n,i,a,o,s,l,c,u)):(d&&"odd"===t&&(h=null),q(h,l,s,o,a,i,n,r,e,c,u))}function Z(t,e,r,n,i){for(var a=[],o=0,s=0;s<e.length;s++)for(var l=e[s],c=1;c<w;c++)for(var u=1;u<_;u++)a.push(Y(t,k(l,u-1,c-1),k(l,u-1,c),k(l,u,c-1),k(l,u,c),r,n,(l+u+c)%2,i&&i[o]?i[o]:[])),o++;return a}function J(t,e,r,n,i){for(var a=[],o=0,s=0;s<e.length;s++)for(var l=e[s],c=1;c<b;c++)for(var u=1;u<w;u++)a.push(Y(t,k(c-1,l,u-1),k(c,l,u-1),k(c-1,l,u),k(c,l,u),r,n,(c+l+u)%2,i&&i[o]?i[o]:[])),o++;return a}function K(t,e,r,n,i){for(var a=[],o=0,s=0;s<e.length;s++)for(var l=e[s],c=1;c<_;c++)for(var u=1;u<b;u++)a.push(Y(t,k(u-1,c-1,l),k(u-1,c,l),k(u,c-1,l),k(u,c,l),r,n,(u+c+l)%2,i&&i[o]?i[o]:[])),o++;return a}function Q(t,e,r){for(var n=1;n<w;n++)for(var i=1;i<_;i++)for(var a=1;a<b;a++)X(t,k(a-1,i-1,n-1),k(a-1,i-1,n),k(a-1,i,n-1),k(a-1,i,n),k(a,i-1,n-1),k(a,i-1,n),k(a,i,n-1),k(a,i,n),e,r,(a+i+n)%2)}function $(t,e,r){d=!0,Q(t,e,r),d=!1}function tt(t,e,r,n,i,a){for(var o=[],s=0,l=0;l<e.length;l++)for(var c=e[l],u=1;u<w;u++)for(var f=1;f<_;f++)o.push(W(t,c,f,u,r,n,i[l],a&&a[s]&&a[s])),s++;return o}function et(t,e,r,n,i,a){for(var o=[],s=0,l=0;l<e.length;l++)for(var c=e[l],u=1;u<b;u++)for(var f=1;f<w;f++)o.push(W(t,u,c,f,r,n,i[l],a&&a[s]&&a[s])),s++;return o}function rt(t,e,r,n,i,a){for(var o=[],s=0,l=0;l<e.length;l++)for(var c=e[l],u=1;u<_;u++)for(var f=1;f<b;f++)o.push(W(t,f,u,c,r,n,i[l],a&&a[s]&&a[s])),s++;return o}function nt(t,e){for(var r=[],n=t;n<e;n++)r.push(n);return r}return function(){if(P(),function(){for(var e=0;e<b;e++)for(var r=0;r<_;r++)for(var n=0;n<w;n++){var i=k(e,r,n);I(t._x[i],t._y[i],t._z[i],t._value[i])}}(),u&&p&&(z(p),m=!0,Q(null,S,E),m=!1),c&&h){z(h);for(var e=t.surface.pattern,r=t.surface.count,s=0;s<r;s++){var f=1===r?.5:s/(r-1),d=(1-f)*S+f*E,T=Math.abs(d-A)>Math.abs(d-M)?[A,d]:[d,M];$(e,T[0],T[1])}}var L=[[Math.min(S,M),Math.max(S,M)],[Math.min(A,E),Math.max(A,E)]];["x","y","z"].forEach((function(e){for(var r=[],n=0;n<L.length;n++){var i=0,a=L[n][0],o=L[n][1],s=t.slices[e];if(s.show&&s.fill){z(s.fill);var c=[],u=[],f=[];if(s.locations.length)for(var h=0;h<s.locations.length;h++){var p=l(s.locations[h],"x"===e?v:"y"===e?y:x);0===p.distRatio?c.push(p.id):p.id>0&&(u.push(p.id),"x"===e?f.push([p.distRatio,0,0]):"y"===e?f.push([0,p.distRatio,0]):f.push([0,0,p.distRatio]))}else c=nt(1,"x"===e?b-1:"y"===e?_-1:w-1);u.length>0&&(r[i]="x"===e?tt(null,u,a,o,f,r[i]):"y"===e?et(null,u,a,o,f,r[i]):rt(null,u,a,o,f,r[i]),i++),c.length>0&&(r[i]="x"===e?Z(null,c,a,o,r[i]):"y"===e?J(null,c,a,o,r[i]):K(null,c,a,o,r[i]),i++)}var d=t.caps[e];d.show&&d.fill&&(z(d.fill),r[i]="x"===e?Z(null,[0,b-1],a,o,r[i]):"y"===e?J(null,[0,_-1],a,o,r[i]):K(null,[0,w-1],a,o,r[i]),i++)}})),0===g&&P(),t._meshX=n,t._meshY=i,t._meshZ=a,t._meshIntensity=o,t._Xs=v,t._Ys=y,t._Zs=x}(),t}e.exports={findNearestOnAxis:l,generateIsoMeshes:h,createIsosurfaceTrace:function(t,e){var r=t.glplot.gl,i=n({gl:r}),a=new c(t,i,e.uid);return i._trace=a,a.update(e),t.glplot.add(i),a}}},{"../../../stackgl_modules":1124,"../../components/colorscale":378,"../../lib/gl_format_color":499,"../../lib/str2rgbarray":528,"../../plots/gl3d/zip3":609}],865:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../registry"),a=t("./attributes"),o=t("../../components/colorscale/defaults");function s(t,e,r,n,a){var s=a("isomin"),l=a("isomax");null!=l&&null!=s&&s>l&&(e.isomin=null,e.isomax=null);var c=a("x"),u=a("y"),f=a("z"),h=a("value");c&&c.length&&u&&u.length&&f&&f.length&&h&&h.length?(i.getComponentMethod("calendars","handleTraceDefaults")(t,e,["x","y","z"],n),a("valuehoverformat"),["x","y","z"].forEach((function(t){a(t+"hoverformat");var e="caps."+t;a(e+".show")&&a(e+".fill");var r="slices."+t;a(r+".show")&&(a(r+".fill"),a(r+".locations"))})),a("spaceframe.show")&&a("spaceframe.fill"),a("surface.show")&&(a("surface.count"),a("surface.fill"),a("surface.pattern")),a("contour.show")&&(a("contour.color"),a("contour.width")),["text","hovertext","hovertemplate","lighting.ambient","lighting.diffuse","lighting.specular","lighting.roughness","lighting.fresnel","lighting.vertexnormalsepsilon","lighting.facenormalsepsilon","lightposition.x","lightposition.y","lightposition.z","flatshading","opacity"].forEach((function(t){a(t)})),o(t,e,n,a,{prefix:"",cLetter:"c"}),e._length=null):e.visible=!1}e.exports={supplyDefaults:function(t,e,r,i){s(t,e,r,i,(function(r,i){return n.coerce(t,e,a,r,i)}))},supplyIsoDefaults:s}},{"../../components/colorscale/defaults":376,"../../lib":503,"../../registry":638,"./attributes":862}],866:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults").supplyDefaults,calc:t("./calc"),colorbar:{min:"cmin",max:"cmax"},plot:t("./convert").createIsosurfaceTrace,moduleType:"trace",name:"isosurface",basePlotModule:t("../../plots/gl3d"),categories:["gl3d","showLegend"],meta:{}}},{"../../plots/gl3d":598,"./attributes":862,"./calc":863,"./convert":864,"./defaults":865}],867:[function(t,e,r){"use strict";var n=t("../../components/colorscale/attributes"),i=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,a=t("../../plots/template_attributes").hovertemplateAttrs,o=t("../surface/attributes"),s=t("../../plots/attributes"),l=t("../../lib/extend").extendFlat;e.exports=l({x:{valType:"data_array",editType:"calc+clearAxisTypes"},y:{valType:"data_array",editType:"calc+clearAxisTypes"},z:{valType:"data_array",editType:"calc+clearAxisTypes"},i:{valType:"data_array",editType:"calc"},j:{valType:"data_array",editType:"calc"},k:{valType:"data_array",editType:"calc"},text:{valType:"string",dflt:"",arrayOk:!0,editType:"calc"},hovertext:{valType:"string",dflt:"",arrayOk:!0,editType:"calc"},hovertemplate:a({editType:"calc"}),xhoverformat:i("x"),yhoverformat:i("y"),zhoverformat:i("z"),delaunayaxis:{valType:"enumerated",values:["x","y","z"],dflt:"z",editType:"calc"},alphahull:{valType:"number",dflt:-1,editType:"calc"},intensity:{valType:"data_array",editType:"calc"},intensitymode:{valType:"enumerated",values:["vertex","cell"],dflt:"vertex",editType:"calc"},color:{valType:"color",editType:"calc"},vertexcolor:{valType:"data_array",editType:"calc"},facecolor:{valType:"data_array",editType:"calc"},transforms:void 0},n("",{colorAttr:"`intensity`",showScaleDflt:!0,editTypeOverride:"calc"}),{opacity:o.opacity,flatshading:{valType:"boolean",dflt:!1,editType:"calc"},contour:{show:l({},o.contours.x.show,{}),color:o.contours.x.color,width:o.contours.x.width,editType:"calc"},lightposition:{x:l({},o.lightposition.x,{dflt:1e5}),y:l({},o.lightposition.y,{dflt:1e5}),z:l({},o.lightposition.z,{dflt:0}),editType:"calc"},lighting:l({vertexnormalsepsilon:{valType:"number",min:0,max:1,dflt:1e-12,editType:"calc"},facenormalsepsilon:{valType:"number",min:0,max:1,dflt:1e-6,editType:"calc"},editType:"calc"},o.lighting),hoverinfo:l({},s.hoverinfo,{editType:"calc"}),showlegend:l({},s.showlegend,{dflt:!1})})},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/cartesian/axis_format_attributes":557,"../../plots/template_attributes":633,"../surface/attributes":1061}],868:[function(t,e,r){"use strict";var n=t("../../components/colorscale/calc");e.exports=function(t,e){e.intensity&&n(t,e,{vals:e.intensity,containerStr:"",cLetter:"c"})}},{"../../components/colorscale/calc":374}],869:[function(t,e,r){"use strict";var n=t("../../../stackgl_modules").gl_mesh3d,i=t("../../../stackgl_modules").delaunay_triangulate,a=t("../../../stackgl_modules").alpha_shape,o=t("../../../stackgl_modules").convex_hull,s=t("../../lib/gl_format_color").parseColorScale,l=t("../../lib/str2rgbarray"),c=t("../../components/colorscale").extractOpts,u=t("../../plots/gl3d/zip3");function f(t,e,r){this.scene=t,this.uid=r,this.mesh=e,this.name="",this.color="#fff",this.data=null,this.showContour=!1}var h=f.prototype;function p(t){for(var e=[],r=t.length,n=0;n<r;n++)e[n]=l(t[n]);return e}function d(t,e,r,n){for(var i=[],a=e.length,o=0;o<a;o++)i[o]=t.d2l(e[o],0,n)*r;return i}function m(t){for(var e=[],r=t.length,n=0;n<r;n++)e[n]=Math.round(t[n]);return e}function g(t,e){for(var r=t.length,n=0;n<r;n++)if(t[n]<=-.5||t[n]>=e-.5)return!1;return!0}h.handlePick=function(t){if(t.object===this.mesh){var e=t.index=t.data.index;t.data._cellCenter?t.traceCoordinate=t.data.dataCoordinate:t.traceCoordinate=[this.data.x[e],this.data.y[e],this.data.z[e]];var r=this.data.hovertext||this.data.text;return Array.isArray(r)&&void 0!==r[e]?t.textLabel=r[e]:r&&(t.textLabel=r),!0}},h.update=function(t){var e=this.scene,r=e.fullSceneLayout;this.data=t;var n,f=t.x.length,h=u(d(r.xaxis,t.x,e.dataScale[0],t.xcalendar),d(r.yaxis,t.y,e.dataScale[1],t.ycalendar),d(r.zaxis,t.z,e.dataScale[2],t.zcalendar));if(t.i&&t.j&&t.k){if(t.i.length!==t.j.length||t.j.length!==t.k.length||!g(t.i,f)||!g(t.j,f)||!g(t.k,f))return;n=u(m(t.i),m(t.j),m(t.k))}else n=0===t.alphahull?o(h):t.alphahull>0?a(t.alphahull,h):function(t,e){for(var r=["x","y","z"].indexOf(t),n=[],a=e.length,o=0;o<a;o++)n[o]=[e[o][(r+1)%3],e[o][(r+2)%3]];return i(n)}(t.delaunayaxis,h);var v={positions:h,cells:n,lightPosition:[t.lightposition.x,t.lightposition.y,t.lightposition.z],ambient:t.lighting.ambient,diffuse:t.lighting.diffuse,specular:t.lighting.specular,roughness:t.lighting.roughness,fresnel:t.lighting.fresnel,vertexNormalsEpsilon:t.lighting.vertexnormalsepsilon,faceNormalsEpsilon:t.lighting.facenormalsepsilon,opacity:t.opacity,contourEnable:t.contour.show,contourColor:l(t.contour.color).slice(0,3),contourWidth:t.contour.width,useFacetNormals:t.flatshading};if(t.intensity){var y=c(t);this.color="#fff";var x=t.intensitymode;v[x+"Intensity"]=t.intensity,v[x+"IntensityBounds"]=[y.min,y.max],v.colormap=s(t)}else t.vertexcolor?(this.color=t.vertexcolor[0],v.vertexColors=p(t.vertexcolor)):t.facecolor?(this.color=t.facecolor[0],v.cellColors=p(t.facecolor)):(this.color=t.color,v.meshColor=l(t.color));this.mesh.update(v)},h.dispose=function(){this.scene.glplot.remove(this.mesh),this.mesh.dispose()},e.exports=function(t,e){var r=t.glplot.gl,i=n({gl:r}),a=new f(t,i,e.uid);return i._trace=a,a.update(e),t.glplot.add(i),a}},{"../../../stackgl_modules":1124,"../../components/colorscale":378,"../../lib/gl_format_color":499,"../../lib/str2rgbarray":528,"../../plots/gl3d/zip3":609}],870:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib"),a=t("../../components/colorscale/defaults"),o=t("./attributes");e.exports=function(t,e,r,s){function l(r,n){return i.coerce(t,e,o,r,n)}function c(t){var e=t.map((function(t){var e=l(t);return e&&i.isArrayOrTypedArray(e)?e:null}));return e.every((function(t){return t&&t.length===e[0].length}))&&e}c(["x","y","z"])?(c(["i","j","k"]),(!e.i||e.j&&e.k)&&(!e.j||e.k&&e.i)&&(!e.k||e.i&&e.j)?(n.getComponentMethod("calendars","handleTraceDefaults")(t,e,["x","y","z"],s),["lighting.ambient","lighting.diffuse","lighting.specular","lighting.roughness","lighting.fresnel","lighting.vertexnormalsepsilon","lighting.facenormalsepsilon","lightposition.x","lightposition.y","lightposition.z","flatshading","alphahull","delaunayaxis","opacity"].forEach((function(t){l(t)})),l("contour.show")&&(l("contour.color"),l("contour.width")),"intensity"in t?(l("intensity"),l("intensitymode"),a(t,e,s,l,{prefix:"",cLetter:"c"})):(e.showscale=!1,"facecolor"in t?l("facecolor"):"vertexcolor"in t?l("vertexcolor"):l("color",r)),l("text"),l("hovertext"),l("hovertemplate"),l("xhoverformat"),l("yhoverformat"),l("zhoverformat"),e._length=null):e.visible=!1):e.visible=!1}},{"../../components/colorscale/defaults":376,"../../lib":503,"../../registry":638,"./attributes":867}],871:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),calc:t("./calc"),colorbar:{min:"cmin",max:"cmax"},plot:t("./convert"),moduleType:"trace",name:"mesh3d",basePlotModule:t("../../plots/gl3d"),categories:["gl3d","showLegend"],meta:{}}},{"../../plots/gl3d":598,"./attributes":867,"./calc":868,"./convert":869,"./defaults":870}],872:[function(t,e,r){"use strict";var n=t("../../lib").extendFlat,i=t("../scatter/attributes"),a=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,o=t("../../components/drawing/attributes").dash,s=t("../../components/fx/attributes"),l=t("../../constants/delta.js"),c=l.INCREASING.COLOR,u=l.DECREASING.COLOR,f=i.line;function h(t){return{line:{color:n({},f.color,{dflt:t}),width:f.width,dash:o,editType:"style"},editType:"style"}}e.exports={xperiod:i.xperiod,xperiod0:i.xperiod0,xperiodalignment:i.xperiodalignment,xhoverformat:a("x"),yhoverformat:a("y"),x:{valType:"data_array",editType:"calc+clearAxisTypes"},open:{valType:"data_array",editType:"calc"},high:{valType:"data_array",editType:"calc"},low:{valType:"data_array",editType:"calc"},close:{valType:"data_array",editType:"calc"},line:{width:n({},f.width,{}),dash:n({},o,{}),editType:"style"},increasing:h(c),decreasing:h(u),text:{valType:"string",dflt:"",arrayOk:!0,editType:"calc"},hovertext:{valType:"string",dflt:"",arrayOk:!0,editType:"calc"},tickwidth:{valType:"number",min:0,max:.5,dflt:.3,editType:"calc"},hoverlabel:n({},s.hoverlabel,{split:{valType:"boolean",dflt:!1,editType:"style"}})}},{"../../components/drawing/attributes":387,"../../components/fx/attributes":397,"../../constants/delta.js":473,"../../lib":503,"../../plots/cartesian/axis_format_attributes":557,"../scatter/attributes":927}],873:[function(t,e,r){"use strict";var n=t("../../lib"),i=n._,a=t("../../plots/cartesian/axes"),o=t("../../plots/cartesian/align_period"),s=t("../../constants/numerical").BADNUM;function l(t,e,r,n){return{o:t,h:e,l:r,c:n}}function c(t,e,r,o,l,c){for(var u=l.makeCalcdata(e,"open"),f=l.makeCalcdata(e,"high"),h=l.makeCalcdata(e,"low"),p=l.makeCalcdata(e,"close"),d=Array.isArray(e.text),m=Array.isArray(e.hovertext),g=!0,v=null,y=!!e.xperiodalignment,x=[],b=0;b<o.length;b++){var _=o[b],w=u[b],T=f[b],k=h[b],A=p[b];if(_!==s&&w!==s&&T!==s&&k!==s&&A!==s){A===w?null!==v&&A!==v&&(g=A>v):g=A>w,v=A;var M=c(w,T,k,A);M.pos=_,M.yc=(w+A)/2,M.i=b,M.dir=g?"increasing":"decreasing",M.x=M.pos,M.y=[k,T],y&&(M.orig_p=r[b]),d&&(M.tx=e.text[b]),m&&(M.htx=e.hovertext[b]),x.push(M)}else x.push({pos:_,empty:!0})}return e._extremes[l._id]=a.findExtremes(l,n.concat(h,f),{padded:!0}),x.length&&(x[0].t={labels:{open:i(t,"open:")+" ",high:i(t,"high:")+" ",low:i(t,"low:")+" ",close:i(t,"close:")+" "}}),x}e.exports={calc:function(t,e){var r=a.getFromId(t,e.xaxis),i=a.getFromId(t,e.yaxis),s=function(t,e,r){var i=r._minDiff;if(!i){var a,s=t._fullData,l=[];for(i=1/0,a=0;a<s.length;a++){var c=s[a];if("ohlc"===c.type&&!0===c.visible&&c.xaxis===e._id){l.push(c);var u=e.makeCalcdata(c,"x");c._origX=u;var f=o(r,e,"x",u).vals;c._xcalc=f;var h=n.distinctVals(f).minDiff;h&&isFinite(h)&&(i=Math.min(i,h))}}for(i===1/0&&(i=1),a=0;a<l.length;a++)l[a]._minDiff=i}return i*r.tickwidth}(t,r,e),u=e._minDiff;e._minDiff=null;var f=e._origX;e._origX=null;var h=e._xcalc;e._xcalc=null;var p=c(t,e,f,h,i,l);return e._extremes[r._id]=a.findExtremes(r,h,{vpad:u/2}),p.length?(n.extendFlat(p[0].t,{wHover:u/2,tickLen:s}),p):[{t:{empty:!0}}]},calcCommon:c}},{"../../constants/numerical":479,"../../lib":503,"../../plots/cartesian/align_period":551,"../../plots/cartesian/axes":554}],874:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./ohlc_defaults"),a=t("../scatter/period_defaults"),o=t("./attributes");function s(t,e,r,n){r(n+".line.color"),r(n+".line.width",e.line.width),r(n+".line.dash",e.line.dash)}e.exports=function(t,e,r,l){function c(r,i){return n.coerce(t,e,o,r,i)}i(t,e,c,l)?(a(t,e,l,c,{x:!0}),c("xhoverformat"),c("yhoverformat"),c("line.width"),c("line.dash"),s(t,e,c,"increasing"),s(t,e,c,"decreasing"),c("text"),c("hovertext"),c("tickwidth"),l._requestRangeslider[e.xaxis]=!0):e.visible=!1}},{"../../lib":503,"../scatter/period_defaults":947,"./attributes":872,"./ohlc_defaults":877}],875:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes"),i=t("../../lib"),a=t("../../components/fx"),o=t("../../components/color"),s=t("../../lib").fillText,l=t("../../constants/delta.js"),c={increasing:l.INCREASING.SYMBOL,decreasing:l.DECREASING.SYMBOL};function u(t,e,r,n){var i,s,l=t.cd,c=t.xa,u=l[0].trace,f=l[0].t,h=u.type,p="ohlc"===h?"l":"min",d="ohlc"===h?"h":"max",m=f.bPos||0,g=f.bdPos||f.tickLen,v=f.wHover,y=Math.min(1,g/Math.abs(c.r2c(c.range[1])-c.r2c(c.range[0])));function x(t){var r=function(t){return t.pos+m-e}(t);return a.inbox(r-v,r+v,i)}function b(t){var e=t[p],n=t[d];return e===n||a.inbox(e-r,n-r,i)}function _(t){return(x(t)+b(t))/2}i=t.maxHoverDistance-y,s=t.maxSpikeDistance-y;var w=a.getDistanceFunction(n,x,b,_);if(a.getClosest(l,w,t),!1===t.index)return null;var T=l[t.index];if(T.empty)return null;var k=u[T.dir],A=k.line.color;return o.opacity(A)&&k.line.width?t.color=A:t.color=k.fillcolor,t.x0=c.c2p(T.pos+m-g,!0),t.x1=c.c2p(T.pos+m+g,!0),t.xLabelVal=void 0!==T.orig_p?T.orig_p:T.pos,t.spikeDistance=_(T)*s/i,t.xSpike=c.c2p(T.pos,!0),t}function f(t,e,r,a){var o=t.cd,s=t.ya,l=o[0].trace,c=o[0].t,f=[],h=u(t,e,r,a);if(!h)return[];var p=o[h.index].hi||l.hoverinfo,d=p.split("+");if(!("all"===p||-1!==d.indexOf("y")))return[];for(var m=["high","open","close","low"],g={},v=0;v<m.length;v++){var y,x=m[v],b=l[x][h.index],_=s.c2p(b,!0);b in g?(y=g[b]).yLabel+="<br>"+c.labels[x]+n.hoverLabelText(s,b,l.yhoverformat):((y=i.extendFlat({},h)).y0=y.y1=_,y.yLabelVal=b,y.yLabel=c.labels[x]+n.hoverLabelText(s,b,l.yhoverformat),y.name="",f.push(y),g[b]=y)}return f}function h(t,e,r,i){var a=t.cd,o=t.ya,l=a[0].trace,f=a[0].t,h=u(t,e,r,i);if(!h)return[];var p=a[h.index],d=h.index=p.i,m=p.dir;function g(t){return f.labels[t]+n.hoverLabelText(o,l[t][d],l.yhoverformat)}var v=p.hi||l.hoverinfo,y=v.split("+"),x="all"===v,b=x||-1!==y.indexOf("y"),_=x||-1!==y.indexOf("text"),w=b?[g("open"),g("high"),g("low"),g("close")+"  "+c[m]]:[];return _&&s(p,l,w),h.extraText=w.join("<br>"),h.y0=h.y1=o.c2p(p.yc,!0),[h]}e.exports={hoverPoints:function(t,e,r,n){return t.cd[0].trace.hoverlabel.split?f(t,e,r,n):h(t,e,r,n)},hoverSplit:f,hoverOnPoints:h}},{"../../components/color":366,"../../components/fx":406,"../../constants/delta.js":473,"../../lib":503,"../../plots/cartesian/axes":554}],876:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"ohlc",basePlotModule:t("../../plots/cartesian"),categories:["cartesian","svg","showLegend"],meta:{},attributes:t("./attributes"),supplyDefaults:t("./defaults"),calc:t("./calc").calc,plot:t("./plot"),style:t("./style"),hoverPoints:t("./hover").hoverPoints,selectPoints:t("./select")}},{"../../plots/cartesian":568,"./attributes":872,"./calc":873,"./defaults":874,"./hover":875,"./plot":878,"./select":879,"./style":880}],877:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib");e.exports=function(t,e,r,a){var o=r("x"),s=r("open"),l=r("high"),c=r("low"),u=r("close");if(r("hoverlabel.split"),n.getComponentMethod("calendars","handleTraceDefaults")(t,e,["x"],a),s&&l&&c&&u){var f=Math.min(s.length,l.length,c.length,u.length);return o&&(f=Math.min(f,i.minRowLength(o))),e._length=f,f}}},{"../../lib":503,"../../registry":638}],878:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib");e.exports=function(t,e,r,a){var o=e.yaxis,s=e.xaxis,l=!!s.rangebreaks;i.makeTraceGroups(a,r,"trace ohlc").each((function(t){var e=n.select(this),r=t[0],a=r.t;if(!0!==r.trace.visible||a.empty)e.remove();else{var c=a.tickLen,u=e.selectAll("path").data(i.identity);u.enter().append("path"),u.exit().remove(),u.attr("d",(function(t){if(t.empty)return"M0,0Z";var e=s.c2p(t.pos-c,!0),r=s.c2p(t.pos+c,!0),n=l?(e+r)/2:s.c2p(t.pos,!0);return"M"+e+","+o.c2p(t.o,!0)+"H"+n+"M"+n+","+o.c2p(t.h,!0)+"V"+o.c2p(t.l,!0)+"M"+r+","+o.c2p(t.c,!0)+"H"+n}))}}))}},{"../../lib":503,"@plotly/d3":58}],879:[function(t,e,r){"use strict";e.exports=function(t,e){var r,n=t.cd,i=t.xaxis,a=t.yaxis,o=[],s=n[0].t.bPos||0;if(!1===e)for(r=0;r<n.length;r++)n[r].selected=0;else for(r=0;r<n.length;r++){var l=n[r];e.contains([i.c2p(l.pos+s),a.c2p(l.yc)],null,l.i,t)?(o.push({pointNumber:l.i,x:i.c2d(l.pos),y:a.c2d(l.yc)}),l.selected=1):l.selected=0}return o}},{}],880:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/drawing"),a=t("../../components/color");e.exports=function(t,e,r){var o=r||n.select(t).selectAll("g.ohlclayer").selectAll("g.trace");o.style("opacity",(function(t){return t[0].trace.opacity})),o.each((function(t){var e=t[0].trace;n.select(this).selectAll("path").each((function(t){if(!t.empty){var r=e[t.dir].line;n.select(this).style("fill","none").call(a.stroke,r.color).call(i.dashLine,r.dash,r.width).style("opacity",e.selectedpoints&&!t.selected?.3:1)}}))}))}},{"../../components/color":366,"../../components/drawing":388,"@plotly/d3":58}],881:[function(t,e,r){"use strict";var n=t("../../lib/extend").extendFlat,i=t("../../plots/attributes"),a=t("../../plots/font_attributes"),o=t("../../components/colorscale/attributes"),s=t("../../plots/template_attributes").hovertemplateAttrs,l=t("../../plots/domain").attributes,c=n({editType:"calc"},o("line",{editTypeOverride:"calc"}),{shape:{valType:"enumerated",values:["linear","hspline"],dflt:"linear",editType:"plot"},hovertemplate:s({editType:"plot",arrayOk:!1},{keys:["count","probability"]})});e.exports={domain:l({name:"parcats",trace:!0,editType:"calc"}),hoverinfo:n({},i.hoverinfo,{flags:["count","probability"],editType:"plot",arrayOk:!1}),hoveron:{valType:"enumerated",values:["category","color","dimension"],dflt:"category",editType:"plot"},hovertemplate:s({editType:"plot",arrayOk:!1},{keys:["count","probability","category","categorycount","colorcount","bandcolorcount"]}),arrangement:{valType:"enumerated",values:["perpendicular","freeform","fixed"],dflt:"perpendicular",editType:"plot"},bundlecolors:{valType:"boolean",dflt:!0,editType:"plot"},sortpaths:{valType:"enumerated",values:["forward","backward"],dflt:"forward",editType:"plot"},labelfont:a({editType:"calc"}),tickfont:a({editType:"calc"}),dimensions:{_isLinkedToArray:"dimension",label:{valType:"string",editType:"calc"},categoryorder:{valType:"enumerated",values:["trace","category ascending","category descending","array"],dflt:"trace",editType:"calc"},categoryarray:{valType:"data_array",editType:"calc"},ticktext:{valType:"data_array",editType:"calc"},values:{valType:"data_array",dflt:[],editType:"calc"},displayindex:{valType:"integer",editType:"calc"},editType:"calc",visible:{valType:"boolean",dflt:!0,editType:"calc"}},line:c,counts:{valType:"number",min:0,dflt:1,arrayOk:!0,editType:"calc"},customdata:void 0,hoverlabel:void 0,ids:void 0,legendgroup:void 0,legendrank:void 0,opacity:void 0,selectedpoints:void 0,showlegend:void 0}},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/domain":584,"../../plots/font_attributes":585,"../../plots/template_attributes":633}],882:[function(t,e,r){"use strict";var n=t("../../plots/get_data").getModuleCalcData,i=t("./plot");r.name="parcats",r.plot=function(t,e,r,a){var o=n(t.calcdata,"parcats");if(o.length){var s=o[0];i(t,s,r,a)}},r.clean=function(t,e,r,n){var i=n._has&&n._has("parcats"),a=e._has&&e._has("parcats");i&&!a&&n._paperdiv.selectAll(".parcats").remove()}},{"../../plots/get_data":593,"./plot":887}],883:[function(t,e,r){"use strict";var n=t("../../lib/gup").wrap,i=t("../../components/colorscale/helpers").hasColorscale,a=t("../../components/colorscale/calc"),o=t("../../lib/filter_unique.js"),s=t("../../components/drawing"),l=t("../../lib"),c=t("fast-isnumeric");function u(t,e,r){t.valueInds.push(e),t.count+=r}function f(t,e,r){return{categoryInds:t,color:e,rawColor:r,valueInds:[],count:0}}function h(t,e,r){t.valueInds.push(e),t.count+=r}e.exports=function(t,e){var r=l.filterVisible(e.dimensions);if(0===r.length)return[];var p,d,m,g=r.map((function(t){var e;if("trace"===t.categoryorder)e=null;else if("array"===t.categoryorder)e=t.categoryarray;else{e=o(t.values);for(var r=!0,n=0;n<e.length;n++)if(!c(e[n])){r=!1;break}e.sort(r?l.sorterAsc:void 0),"category descending"===t.categoryorder&&(e=e.reverse())}return function(t,e){e=null==e?[]:e.map((function(t){return t}));var r={},n={},i=[];e.forEach((function(t,e){r[t]=0,n[t]=e}));for(var a=0;a<t.length;a++){var o,s=t[a];void 0===r[s]?(r[s]=1,o=e.push(s)-1,n[s]=o):(r[s]++,o=n[s]),i.push(o)}var l=e.map((function(t){return r[t]}));return{uniqueValues:e,uniqueCounts:l,inds:i}}(t.values,e)}));p=l.isArrayOrTypedArray(e.counts)?e.counts:[e.counts],function(t){var e;if(function(t){for(var e=new Array(t.length),r=0;r<t.length;r++){if(t[r]<0||t[r]>=t.length)return!1;if(void 0!==e[t[r]])return!1;e[t[r]]=!0}return!0}(t.map((function(t){return t.displayindex}))))for(e=0;e<t.length;e++)t[e]._displayindex=t[e].displayindex;else for(e=0;e<t.length;e++)t[e]._displayindex=e}(r),r.forEach((function(t,e){!function(t,e){t._categoryarray=e.uniqueValues,null===t.ticktext||void 0===t.ticktext?t._ticktext=[]:t._ticktext=t.ticktext.slice();for(var r=t._ticktext.length;r<e.uniqueValues.length;r++)t._ticktext.push(e.uniqueValues[r])}(t,g[e])}));var v,y=e.line;y?(i(e,"line")&&a(t,e,{vals:e.line.color,containerStr:"line",cLetter:"c"}),v=s.tryColorscale(y)):v=l.identity;var x,b,_,w,T,k=r[0].values.length,A={},M=g.map((function(t){return t.inds}));for(m=0,x=0;x<k;x++){var S=[];for(b=0;b<M.length;b++)S.push(M[b][x]);d=p[x%p.length],m+=d;var E=(_=x,w=void 0,T=void 0,l.isArrayOrTypedArray(y.color)?T=w=y.color[_%y.color.length]:w=y.color,{color:v(w),rawColor:T}),L=S+"-"+E.rawColor;void 0===A[L]&&(A[L]=f(S,E.color,E.rawColor)),h(A[L],x,d)}var C,P=r.map((function(t,e){return function(t,e,r,n,i){return{dimensionInd:t,containerInd:e,displayInd:r,dimensionLabel:n,count:i,categories:[],dragX:null}}(e,t._index,t._displayindex,t.label,m)}));for(x=0;x<k;x++)for(d=p[x%p.length],b=0;b<P.length;b++){var I=P[b].containerInd,O=g[b].inds[x],z=P[b].categories;if(void 0===z[O]){var D=e.dimensions[I]._categoryarray[O],R=e.dimensions[I]._ticktext[O];z[O]={dimensionInd:b,categoryInd:C=O,categoryValue:D,displayInd:C,categoryLabel:R,valueInds:[],count:0,dragY:null}}u(z[O],x,d)}return n(function(t,e,r){var n=t.map((function(t){return t.categories.length})).reduce((function(t,e){return Math.max(t,e)}));return{dimensions:t,paths:e,trace:void 0,maxCats:n,count:r}}(P,A,m))}},{"../../components/colorscale/calc":374,"../../components/colorscale/helpers":377,"../../components/drawing":388,"../../lib":503,"../../lib/filter_unique.js":494,"../../lib/gup":500,"fast-isnumeric":190}],884:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/colorscale/helpers").hasColorscale,a=t("../../components/colorscale/defaults"),o=t("../../plots/domain").defaults,s=t("../../plots/array_container_defaults"),l=t("./attributes"),c=t("../parcoords/merge_length");function u(t,e){function r(r,i){return n.coerce(t,e,l.dimensions,r,i)}var i=r("values"),a=r("visible");if(i&&i.length||(a=e.visible=!1),a){r("label"),r("displayindex",e._index);var o,s=t.categoryarray,c=Array.isArray(s)&&s.length>0;c&&(o="array");var u=r("categoryorder",o);"array"===u?(r("categoryarray"),r("ticktext")):(delete t.categoryarray,delete t.ticktext),c||"array"!==u||(e.categoryorder="trace")}}e.exports=function(t,e,r,f){function h(r,i){return n.coerce(t,e,l,r,i)}var p=s(t,e,{name:"dimensions",handleItemDefaults:u}),d=function(t,e,r,o,s){s("line.shape"),s("line.hovertemplate");var l=s("line.color",o.colorway[0]);if(i(t,"line")&&n.isArrayOrTypedArray(l)){if(l.length)return s("line.colorscale"),a(t,e,o,s,{prefix:"line.",cLetter:"c"}),l.length;e.line.color=r}return 1/0}(t,e,r,f,h);o(e,f,h),Array.isArray(p)&&p.length||(e.visible=!1),c(e,p,"values",d),h("hoveron"),h("hovertemplate"),h("arrangement"),h("bundlecolors"),h("sortpaths"),h("counts");var m={family:f.font.family,size:Math.round(f.font.size),color:f.font.color};n.coerceFont(h,"labelfont",m);var g={family:f.font.family,size:Math.round(f.font.size/1.2),color:f.font.color};n.coerceFont(h,"tickfont",g)}},{"../../components/colorscale/defaults":376,"../../components/colorscale/helpers":377,"../../lib":503,"../../plots/array_container_defaults":549,"../../plots/domain":584,"../parcoords/merge_length":898,"./attributes":881}],885:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),calc:t("./calc"),plot:t("./plot"),colorbar:{container:"line",min:"cmin",max:"cmax"},moduleType:"trace",name:"parcats",basePlotModule:t("./base_plot"),categories:["noOpacity"],meta:{}}},{"./attributes":881,"./base_plot":882,"./calc":883,"./defaults":884,"./plot":887}],886:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("d3-interpolate").interpolateNumber,a=t("../../plot_api/plot_api"),o=t("../../components/fx"),s=t("../../lib"),l=s.strTranslate,c=t("../../components/drawing"),u=t("tinycolor2"),f=t("../../lib/svg_text_utils");function h(t,e,r,i){var a=t.map(F.bind(0,e,r)),o=i.selectAll("g.parcatslayer").data([null]);o.enter().append("g").attr("class","parcatslayer").style("pointer-events","all");var u=o.selectAll("g.trace.parcats").data(a,p),h=u.enter().append("g").attr("class","trace parcats");u.attr("transform",(function(t){return l(t.x,t.y)})),h.append("g").attr("class","paths");var y=u.select("g.paths").selectAll("path.path").data((function(t){return t.paths}),p);y.attr("fill",(function(t){return t.model.color}));var x=y.enter().append("path").attr("class","path").attr("stroke-opacity",0).attr("fill",(function(t){return t.model.color})).attr("fill-opacity",0);_(x),y.attr("d",(function(t){return t.svgD})),x.empty()||y.sort(m),y.exit().remove(),y.on("mouseover",g).on("mouseout",v).on("click",b),h.append("g").attr("class","dimensions");var w=u.select("g.dimensions").selectAll("g.dimension").data((function(t){return t.dimensions}),p);w.enter().append("g").attr("class","dimension"),w.attr("transform",(function(t){return l(t.x,0)})),w.exit().remove();var A=w.selectAll("g.category").data((function(t){return t.categories}),p),M=A.enter().append("g").attr("class","category");A.attr("transform",(function(t){return l(0,t.y)})),M.append("rect").attr("class","catrect").attr("pointer-events","none"),A.select("rect.catrect").attr("fill","none").attr("width",(function(t){return t.width})).attr("height",(function(t){return t.height})),T(M);var S=A.selectAll("rect.bandrect").data((function(t){return t.bands}),p);S.each((function(){s.raiseToTop(this)})),S.attr("fill",(function(t){return t.color}));var E=S.enter().append("rect").attr("class","bandrect").attr("stroke-opacity",0).attr("fill",(function(t){return t.color})).attr("fill-opacity",0);S.attr("fill",(function(t){return t.color})).attr("width",(function(t){return t.width})).attr("height",(function(t){return t.height})).attr("y",(function(t){return t.y})).attr("cursor",(function(t){return"fixed"===t.parcatsViewModel.arrangement?"default":"perpendicular"===t.parcatsViewModel.arrangement?"ns-resize":"move"})),k(E),S.exit().remove(),M.append("text").attr("class","catlabel").attr("pointer-events","none");var z=e._fullLayout.paper_bgcolor;A.select("text.catlabel").attr("text-anchor",(function(t){return d(t)?"start":"end"})).attr("alignment-baseline","middle").style("text-shadow",f.makeTextShadow(z)).style("fill","rgb(0, 0, 0)").attr("x",(function(t){return d(t)?t.width+5:-5})).attr("y",(function(t){return t.height/2})).text((function(t){return t.model.categoryLabel})).each((function(t){c.font(n.select(this),t.parcatsViewModel.categorylabelfont),f.convertToTspans(n.select(this),e)})),M.append("text").attr("class","dimlabel"),A.select("text.dimlabel").attr("text-anchor","middle").attr("alignment-baseline","baseline").attr("cursor",(function(t){return"fixed"===t.parcatsViewModel.arrangement?"default":"ew-resize"})).attr("x",(function(t){return t.width/2})).attr("y",-5).text((function(t,e){return 0===e?t.parcatsViewModel.model.dimensions[t.model.dimensionInd].dimensionLabel:null})).each((function(t){c.font(n.select(this),t.parcatsViewModel.labelfont)})),A.selectAll("rect.bandrect").on("mouseover",L).on("mouseout",C),A.exit().remove(),w.call(n.behavior.drag().origin((function(t){return{x:t.x,y:0}})).on("dragstart",P).on("drag",I).on("dragend",O)),u.each((function(t){t.traceSelection=n.select(this),t.pathSelection=n.select(this).selectAll("g.paths").selectAll("path.path"),t.dimensionSelection=n.select(this).selectAll("g.dimensions").selectAll("g.dimension")})),u.exit().remove()}function p(t){return t.key}function d(t){var e=t.parcatsViewModel.dimensions.length,r=t.parcatsViewModel.dimensions[e-1].model.dimensionInd;return t.model.dimensionInd===r}function m(t,e){return t.model.rawColor>e.model.rawColor?1:t.model.rawColor<e.model.rawColor?-1:0}function g(t){if(!t.parcatsViewModel.dragDimension&&-1===t.parcatsViewModel.hoverinfoItems.indexOf("skip")){s.raiseToTop(this),w(n.select(this));var e=y(t),r=x(t);if(t.parcatsViewModel.graphDiv.emit("plotly_hover",{points:e,event:n.event,constraints:r}),-1===t.parcatsViewModel.hoverinfoItems.indexOf("none")){var i,a,l,c=n.mouse(this)[0],f=t.parcatsViewModel.graphDiv,h=t.parcatsViewModel.trace,p=f._fullLayout,d=p._paperdiv.node().getBoundingClientRect(),m=t.parcatsViewModel.graphDiv.getBoundingClientRect();for(l=0;l<t.leftXs.length-1;l++)if(t.leftXs[l]+t.dimWidths[l]-2<=c&&c<=t.leftXs[l+1]+2){var g=t.parcatsViewModel.dimensions[l],v=t.parcatsViewModel.dimensions[l+1];i=(g.x+g.width+v.x)/2,a=(t.topYs[l]+t.topYs[l+1]+t.height)/2;break}var b=t.parcatsViewModel.x+i,_=t.parcatsViewModel.y+a,T=u.mostReadable(t.model.color,["black","white"]),k=t.model.count,A=k/t.parcatsViewModel.model.count,M={countLabel:k,probabilityLabel:A.toFixed(3)},S=[];-1!==t.parcatsViewModel.hoverinfoItems.indexOf("count")&&S.push(["Count:",M.countLabel].join(" ")),-1!==t.parcatsViewModel.hoverinfoItems.indexOf("probability")&&S.push(["P:",M.probabilityLabel].join(" "));var E=S.join("<br>"),L=n.mouse(f)[0];o.loneHover({trace:h,x:b-d.left+m.left,y:_-d.top+m.top,text:E,color:t.model.color,borderColor:"black",fontFamily:'Monaco, "Courier New", monospace',fontSize:10,fontColor:T,idealAlign:L<b?"right":"left",hovertemplate:(h.line||{}).hovertemplate,hovertemplateLabels:M,eventData:[{data:h._input,fullData:h,count:k,probability:A}]},{container:p._hoverlayer.node(),outerContainer:p._paper.node(),gd:f})}}}function v(t){if(!t.parcatsViewModel.dragDimension&&(_(n.select(this)),o.loneUnhover(t.parcatsViewModel.graphDiv._fullLayout._hoverlayer.node()),t.parcatsViewModel.pathSelection.sort(m),-1===t.parcatsViewModel.hoverinfoItems.indexOf("skip"))){var e=y(t),r=x(t);t.parcatsViewModel.graphDiv.emit("plotly_unhover",{points:e,event:n.event,constraints:r})}}function y(t){for(var e=[],r=z(t.parcatsViewModel),n=0;n<t.model.valueInds.length;n++){var i=t.model.valueInds[n];e.push({curveNumber:r,pointNumber:i})}return e}function x(t){for(var e={},r=t.parcatsViewModel.model.dimensions,n=0;n<r.length;n++){var i=r[n],a=i.categories[t.model.categoryInds[n]];e[i.containerInd]=a.categoryValue}return void 0!==t.model.rawColor&&(e.color=t.model.rawColor),e}function b(t){if(-1===t.parcatsViewModel.hoverinfoItems.indexOf("skip")){var e=y(t),r=x(t);t.parcatsViewModel.graphDiv.emit("plotly_click",{points:e,event:n.event,constraints:r})}}function _(t){t.attr("fill",(function(t){return t.model.color})).attr("fill-opacity",.6).attr("stroke","lightgray").attr("stroke-width",.2).attr("stroke-opacity",1)}function w(t){t.attr("fill-opacity",.8).attr("stroke",(function(t){return u.mostReadable(t.model.color,["black","white"])})).attr("stroke-width",.3)}function T(t){t.select("rect.catrect").attr("stroke","black").attr("stroke-width",1).attr("stroke-opacity",1)}function k(t){t.attr("stroke","black").attr("stroke-width",.2).attr("stroke-opacity",1).attr("fill-opacity",1)}function A(t){var e=t.parcatsViewModel.pathSelection,r=t.categoryViewModel.model.dimensionInd,n=t.categoryViewModel.model.categoryInd;return e.filter((function(e){return e.model.categoryInds[r]===n&&e.model.color===t.color}))}function M(t,e,r){var i=n.select(t).datum(),a=i.categoryViewModel.model,o=i.parcatsViewModel.graphDiv,s=n.select(t.parentNode).selectAll("rect.bandrect"),l=[];s.each((function(t){A(t).each((function(t){Array.prototype.push.apply(l,y(t))}))}));var c={};c[a.dimensionInd]=a.categoryValue,o.emit(e,{points:l,event:r,constraints:c})}function S(t,e,r){var i=n.select(t).datum(),a=i.categoryViewModel.model,o=i.parcatsViewModel.graphDiv,s=A(i),l=[];s.each((function(t){Array.prototype.push.apply(l,y(t))}));var c={};c[a.dimensionInd]=a.categoryValue,void 0!==i.rawColor&&(c.color=i.rawColor),o.emit(e,{points:l,event:r,constraints:c})}function E(t,e,r){t._fullLayout._calcInverseTransform(t);var i,a,o=t._fullLayout._invScaleX,s=t._fullLayout._invScaleY,l=n.select(r.parentNode).select("rect.catrect"),c=l.node().getBoundingClientRect(),u=l.datum(),f=u.parcatsViewModel,h=f.model.dimensions[u.model.dimensionInd],p=f.trace,d=c.top+c.height/2;f.dimensions.length>1&&h.displayInd===f.dimensions.length-1?(i=c.left,a="left"):(i=c.left+c.width,a="right");var m=u.model.count,g=u.model.categoryLabel,v=m/u.parcatsViewModel.model.count,y={countLabel:m,categoryLabel:g,probabilityLabel:v.toFixed(3)},x=[];-1!==u.parcatsViewModel.hoverinfoItems.indexOf("count")&&x.push(["Count:",y.countLabel].join(" ")),-1!==u.parcatsViewModel.hoverinfoItems.indexOf("probability")&&x.push(["P("+y.categoryLabel+"):",y.probabilityLabel].join(" "));var b=x.join("<br>");return{trace:p,x:o*(i-e.left),y:s*(d-e.top),text:b,color:"lightgray",borderColor:"black",fontFamily:'Monaco, "Courier New", monospace',fontSize:12,fontColor:"black",idealAlign:a,hovertemplate:p.hovertemplate,hovertemplateLabels:y,eventData:[{data:p._input,fullData:p,count:m,category:g,probability:v}]}}function L(t){if(!t.parcatsViewModel.dragDimension&&-1===t.parcatsViewModel.hoverinfoItems.indexOf("skip")){if(n.mouse(this)[1]<-1)return;var e,r=t.parcatsViewModel.graphDiv,i=r._fullLayout,a=i._paperdiv.node().getBoundingClientRect(),l=t.parcatsViewModel.hoveron;if("color"===l?(!function(t){var e=n.select(t).datum(),r=A(e);w(r),r.each((function(){s.raiseToTop(this)})),n.select(t.parentNode).selectAll("rect.bandrect").filter((function(t){return t.color===e.color})).each((function(){s.raiseToTop(this),n.select(this).attr("stroke","black").attr("stroke-width",1.5)}))}(this),S(this,"plotly_hover",n.event)):(!function(t){n.select(t.parentNode).selectAll("rect.bandrect").each((function(t){var e=A(t);w(e),e.each((function(){s.raiseToTop(this)}))})),n.select(t.parentNode).select("rect.catrect").attr("stroke","black").attr("stroke-width",2.5)}(this),M(this,"plotly_hover",n.event)),-1===t.parcatsViewModel.hoverinfoItems.indexOf("none"))"category"===l?e=E(r,a,this):"color"===l?e=function(t,e,r){t._fullLayout._calcInverseTransform(t);var i,a,o=t._fullLayout._invScaleX,s=t._fullLayout._invScaleY,l=r.getBoundingClientRect(),c=n.select(r).datum(),f=c.categoryViewModel,h=f.parcatsViewModel,p=h.model.dimensions[f.model.dimensionInd],d=h.trace,m=l.y+l.height/2;h.dimensions.length>1&&p.displayInd===h.dimensions.length-1?(i=l.left,a="left"):(i=l.left+l.width,a="right");var g=f.model.categoryLabel,v=c.parcatsViewModel.model.count,y=0;c.categoryViewModel.bands.forEach((function(t){t.color===c.color&&(y+=t.count)}));var x=f.model.count,b=0;h.pathSelection.each((function(t){t.model.color===c.color&&(b+=t.model.count)}));var _=y/v,w=y/b,T=y/x,k={countLabel:v,categoryLabel:g,probabilityLabel:_.toFixed(3)},A=[];-1!==f.parcatsViewModel.hoverinfoItems.indexOf("count")&&A.push(["Count:",k.countLabel].join(" ")),-1!==f.parcatsViewModel.hoverinfoItems.indexOf("probability")&&(A.push("P(color \u2229 "+g+"): "+k.probabilityLabel),A.push("P("+g+" | color): "+w.toFixed(3)),A.push("P(color | "+g+"): "+T.toFixed(3)));var M=A.join("<br>"),S=u.mostReadable(c.color,["black","white"]);return{trace:d,x:o*(i-e.left),y:s*(m-e.top),text:M,color:c.color,borderColor:"black",fontFamily:'Monaco, "Courier New", monospace',fontColor:S,fontSize:10,idealAlign:a,hovertemplate:d.hovertemplate,hovertemplateLabels:k,eventData:[{data:d._input,fullData:d,category:g,count:v,probability:_,categorycount:x,colorcount:b,bandcolorcount:y}]}}(r,a,this):"dimension"===l&&(e=function(t,e,r){var i=[];return n.select(r.parentNode.parentNode).selectAll("g.category").select("rect.catrect").each((function(){i.push(E(t,e,this))})),i}(r,a,this)),e&&o.loneHover(e,{container:i._hoverlayer.node(),outerContainer:i._paper.node(),gd:r})}}function C(t){var e=t.parcatsViewModel;if(!e.dragDimension&&(_(e.pathSelection),T(e.dimensionSelection.selectAll("g.category")),k(e.dimensionSelection.selectAll("g.category").selectAll("rect.bandrect")),o.loneUnhover(e.graphDiv._fullLayout._hoverlayer.node()),e.pathSelection.sort(m),-1===e.hoverinfoItems.indexOf("skip"))){"color"===t.parcatsViewModel.hoveron?S(this,"plotly_unhover",n.event):M(this,"plotly_unhover",n.event)}}function P(t){"fixed"!==t.parcatsViewModel.arrangement&&(t.dragDimensionDisplayInd=t.model.displayInd,t.initialDragDimensionDisplayInds=t.parcatsViewModel.model.dimensions.map((function(t){return t.displayInd})),t.dragHasMoved=!1,t.dragCategoryDisplayInd=null,n.select(this).selectAll("g.category").select("rect.catrect").each((function(e){var r=n.mouse(this)[0],i=n.mouse(this)[1];-2<=r&&r<=e.width+2&&-2<=i&&i<=e.height+2&&(t.dragCategoryDisplayInd=e.model.displayInd,t.initialDragCategoryDisplayInds=t.model.categories.map((function(t){return t.displayInd})),e.model.dragY=e.y,s.raiseToTop(this.parentNode),n.select(this.parentNode).selectAll("rect.bandrect").each((function(e){e.y<i&&i<=e.y+e.height&&(t.potentialClickBand=this)})))})),t.parcatsViewModel.dragDimension=t,o.loneUnhover(t.parcatsViewModel.graphDiv._fullLayout._hoverlayer.node()))}function I(t){if("fixed"!==t.parcatsViewModel.arrangement&&(t.dragHasMoved=!0,null!==t.dragDimensionDisplayInd)){var e=t.dragDimensionDisplayInd,r=e-1,i=e+1,a=t.parcatsViewModel.dimensions[e];if(null!==t.dragCategoryDisplayInd){var o=a.categories[t.dragCategoryDisplayInd];o.model.dragY+=n.event.dy;var s=o.model.dragY,l=o.model.displayInd,c=a.categories,u=c[l-1],f=c[l+1];void 0!==u&&s<u.y+u.height/2&&(o.model.displayInd=u.model.displayInd,u.model.displayInd=l),void 0!==f&&s+o.height>f.y+f.height/2&&(o.model.displayInd=f.model.displayInd,f.model.displayInd=l),t.dragCategoryDisplayInd=o.model.displayInd}if(null===t.dragCategoryDisplayInd||"freeform"===t.parcatsViewModel.arrangement){a.model.dragX=n.event.x;var h=t.parcatsViewModel.dimensions[r],p=t.parcatsViewModel.dimensions[i];void 0!==h&&a.model.dragX<h.x+h.width&&(a.model.displayInd=h.model.displayInd,h.model.displayInd=e),void 0!==p&&a.model.dragX+a.width>p.x&&(a.model.displayInd=p.model.displayInd,p.model.displayInd=t.dragDimensionDisplayInd),t.dragDimensionDisplayInd=a.model.displayInd}j(t.parcatsViewModel),N(t.parcatsViewModel),R(t.parcatsViewModel),D(t.parcatsViewModel)}}function O(t){if("fixed"!==t.parcatsViewModel.arrangement&&null!==t.dragDimensionDisplayInd){n.select(this).selectAll("text").attr("font-weight","normal");var e={},r=z(t.parcatsViewModel),i=t.parcatsViewModel.model.dimensions.map((function(t){return t.displayInd})),o=t.initialDragDimensionDisplayInds.some((function(t,e){return t!==i[e]}));o&&i.forEach((function(r,n){var i=t.parcatsViewModel.model.dimensions[n].containerInd;e["dimensions["+i+"].displayindex"]=r}));var s=!1;if(null!==t.dragCategoryDisplayInd){var l=t.model.categories.map((function(t){return t.displayInd}));if(s=t.initialDragCategoryDisplayInds.some((function(t,e){return t!==l[e]}))){var c=t.model.categories.slice().sort((function(t,e){return t.displayInd-e.displayInd})),u=c.map((function(t){return t.categoryValue})),f=c.map((function(t){return t.categoryLabel}));e["dimensions["+t.model.containerInd+"].categoryarray"]=[u],e["dimensions["+t.model.containerInd+"].ticktext"]=[f],e["dimensions["+t.model.containerInd+"].categoryorder"]="array"}}if(-1===t.parcatsViewModel.hoverinfoItems.indexOf("skip")&&!t.dragHasMoved&&t.potentialClickBand&&("color"===t.parcatsViewModel.hoveron?S(t.potentialClickBand,"plotly_click",n.event.sourceEvent):M(t.potentialClickBand,"plotly_click",n.event.sourceEvent)),t.model.dragX=null,null!==t.dragCategoryDisplayInd)t.parcatsViewModel.dimensions[t.dragDimensionDisplayInd].categories[t.dragCategoryDisplayInd].model.dragY=null,t.dragCategoryDisplayInd=null;t.dragDimensionDisplayInd=null,t.parcatsViewModel.dragDimension=null,t.dragHasMoved=null,t.potentialClickBand=null,j(t.parcatsViewModel),N(t.parcatsViewModel),n.transition().duration(300).ease("cubic-in-out").each((function(){R(t.parcatsViewModel,!0),D(t.parcatsViewModel,!0)})).each("end",(function(){(o||s)&&a.restyle(t.parcatsViewModel.graphDiv,e,[r])}))}}function z(t){for(var e,r=t.graphDiv._fullData,n=0;n<r.length;n++)if(t.key===r[n].uid){e=n;break}return e}function D(t,e){var r;void 0===e&&(e=!1),t.pathSelection.data((function(t){return t.paths}),p),(r=t.pathSelection,e?r.transition():r).attr("d",(function(t){return t.svgD}))}function R(t,e){function r(t){return e?t.transition():t}void 0===e&&(e=!1),t.dimensionSelection.data((function(t){return t.dimensions}),p);var i=t.dimensionSelection.selectAll("g.category").data((function(t){return t.categories}),p);r(t.dimensionSelection).attr("transform",(function(t){return l(t.x,0)})),r(i).attr("transform",(function(t){return l(0,t.y)})),i.select(".dimlabel").text((function(t,e){return 0===e?t.parcatsViewModel.model.dimensions[t.model.dimensionInd].dimensionLabel:null})),i.select(".catlabel").attr("text-anchor",(function(t){return d(t)?"start":"end"})).attr("x",(function(t){return d(t)?t.width+5:-5})).each((function(t){var e,r;d(t)?(e=t.width+5,r="start"):(e=-5,r="end"),n.select(this).selectAll("tspan").attr("x",e).attr("text-anchor",r)}));var a=i.selectAll("rect.bandrect").data((function(t){return t.bands}),p),o=a.enter().append("rect").attr("class","bandrect").attr("cursor","move").attr("stroke-opacity",0).attr("fill",(function(t){return t.color})).attr("fill-opacity",0);a.attr("fill",(function(t){return t.color})).attr("width",(function(t){return t.width})).attr("height",(function(t){return t.height})).attr("y",(function(t){return t.y})),k(o),a.each((function(){s.raiseToTop(this)})),a.exit().remove()}function F(t,e,r){var n,i=r[0],a=e.margin||{l:80,r:80,t:100,b:80},o=i.trace,s=o.domain,l=e.width,c=e.height,u=Math.floor(l*(s.x[1]-s.x[0])),f=Math.floor(c*(s.y[1]-s.y[0])),h=s.x[0]*l+a.l,p=e.height-s.y[1]*e.height+a.t,d=o.line.shape;n="all"===o.hoverinfo?["count","probability"]:(o.hoverinfo||"").split("+");var m={trace:o,key:o.uid,model:i,x:h,y:p,width:u,height:f,hoveron:o.hoveron,hoverinfoItems:n,arrangement:o.arrangement,bundlecolors:o.bundlecolors,sortpaths:o.sortpaths,labelfont:o.labelfont,categorylabelfont:o.tickfont,pathShape:d,dragDimension:null,margin:a,paths:[],dimensions:[],graphDiv:t,traceSelection:null,pathSelection:null,dimensionSelection:null};return i.dimensions&&(j(m),N(m)),m}function B(t,e,r,n,a){var o,s,l=[],c=[];for(s=0;s<r.length-1;s++)o=i(r[s]+t[s],t[s+1]),l.push(o(a)),c.push(o(1-a));var u="M "+t[0]+","+e[0];for(u+="l"+r[0]+",0 ",s=1;s<r.length;s++)u+="C"+l[s-1]+","+e[s-1]+" "+c[s-1]+","+e[s]+" "+t[s]+","+e[s],u+="l"+r[s]+",0 ";for(u+="l0,"+n+" ",u+="l -"+r[r.length-1]+",0 ",s=r.length-2;s>=0;s--)u+="C"+c[s]+","+(e[s+1]+n)+" "+l[s]+","+(e[s]+n)+" "+(t[s]+r[s])+","+(e[s]+n),u+="l-"+r[s]+",0 ";return u+="Z"}function N(t){var e=t.dimensions,r=t.model,n=e.map((function(t){return t.categories.map((function(t){return t.y}))})),i=t.model.dimensions.map((function(t){return t.categories.map((function(t){return t.displayInd}))})),a=t.model.dimensions.map((function(t){return t.displayInd})),o=t.dimensions.map((function(t){return t.model.dimensionInd})),s=e.map((function(t){return t.x})),l=e.map((function(t){return t.width})),c=[];for(var u in r.paths)r.paths.hasOwnProperty(u)&&c.push(r.paths[u]);function f(t){var e=t.categoryInds.map((function(t,e){return i[e][t]}));return o.map((function(t){return e[t]}))}c.sort((function(e,r){var n=f(e),i=f(r);return"backward"===t.sortpaths&&(n.reverse(),i.reverse()),n.push(e.valueInds[0]),i.push(r.valueInds[0]),t.bundlecolors&&(n.unshift(e.rawColor),i.unshift(r.rawColor)),n<i?-1:n>i?1:0}));for(var h=new Array(c.length),p=e[0].model.count,d=e[0].categories.map((function(t){return t.height})).reduce((function(t,e){return t+e})),m=0;m<c.length;m++){var g,v=c[m];g=p>0?d*(v.count/p):0;for(var y,x=new Array(n.length),b=0;b<v.categoryInds.length;b++){var _=v.categoryInds[b],w=i[b][_],T=a[b];x[T]=n[T][w],n[T][w]+=g;var k=t.dimensions[T].categories[w],A=k.bands.length,M=k.bands[A-1];if(void 0===M||v.rawColor!==M.rawColor){var S=void 0===M?0:M.y+M.height;k.bands.push({key:S,color:v.color,rawColor:v.rawColor,height:g,width:k.width,count:v.count,y:S,categoryViewModel:k,parcatsViewModel:t})}else{var E=k.bands[A-1];E.height+=g,E.count+=v.count}}y="hspline"===t.pathShape?B(s,x,l,g,.5):B(s,x,l,g,0),h[m]={key:v.valueInds[0],model:v,height:g,leftXs:s,topYs:x,dimWidths:l,svgD:y,parcatsViewModel:t}}t.paths=h}function j(t){var e=t.model.dimensions.map((function(t){return{displayInd:t.displayInd,dimensionInd:t.dimensionInd}}));e.sort((function(t,e){return t.displayInd-e.displayInd}));var r=[];for(var n in e){var i=e[n].dimensionInd,a=t.model.dimensions[i];r.push(U(t,a))}t.dimensions=r}function U(t,e){var r,n=t.model.dimensions.length,i=e.displayInd;r=40+(n>1?(t.width-80-16)/(n-1):0)*i;var a,o,s,l,c,u=[],f=t.model.maxCats,h=e.categories.length,p=e.count,d=t.height-8*(f-1),m=8*(f-h)/2,g=e.categories.map((function(t){return{displayInd:t.displayInd,categoryInd:t.categoryInd}}));for(g.sort((function(t,e){return t.displayInd-e.displayInd})),c=0;c<h;c++)l=g[c].categoryInd,o=e.categories[l],a=p>0?o.count/p*d:0,s={key:o.valueInds[0],model:o,width:16,height:a,y:null!==o.dragY?o.dragY:m,bands:[],parcatsViewModel:t},m=m+a+8,u.push(s);return{key:e.dimensionInd,x:null!==e.dragX?e.dragX:r,y:0,width:16,model:e,categories:u,parcatsViewModel:t,dragCategoryDisplayInd:null,dragDimensionDisplayInd:null,initialDragDimensionDisplayInds:null,initialDragCategoryDisplayInds:null,dragHasMoved:null,potentialClickBand:null}}e.exports=function(t,e,r,n){h(r,t,n,e)}},{"../../components/drawing":388,"../../components/fx":406,"../../lib":503,"../../lib/svg_text_utils":529,"../../plot_api/plot_api":540,"@plotly/d3":58,"d3-interpolate":116,tinycolor2:312}],887:[function(t,e,r){"use strict";var n=t("./parcats");e.exports=function(t,e,r,i){var a=t._fullLayout,o=a._paper,s=a._size;n(t,o,e,{width:s.w,height:s.h,margin:{t:s.t,r:s.r,b:s.b,l:s.l}},r,i)}},{"./parcats":886}],888:[function(t,e,r){"use strict";var n=t("../../components/colorscale/attributes"),i=t("../../plots/cartesian/layout_attributes"),a=t("../../plots/font_attributes"),o=t("../../plots/domain").attributes,s=t("../../lib/extend").extendFlat,l=t("../../plot_api/plot_template").templatedArray;e.exports={domain:o({name:"parcoords",trace:!0,editType:"plot"}),labelangle:{valType:"angle",dflt:0,editType:"plot"},labelside:{valType:"enumerated",values:["top","bottom"],dflt:"top",editType:"plot"},labelfont:a({editType:"plot"}),tickfont:a({editType:"plot"}),rangefont:a({editType:"plot"}),dimensions:l("dimension",{label:{valType:"string",editType:"plot"},tickvals:s({},i.tickvals,{editType:"plot"}),ticktext:s({},i.ticktext,{editType:"plot"}),tickformat:s({},i.tickformat,{editType:"plot"}),visible:{valType:"boolean",dflt:!0,editType:"plot"},range:{valType:"info_array",items:[{valType:"number",editType:"plot"},{valType:"number",editType:"plot"}],editType:"plot"},constraintrange:{valType:"info_array",freeLength:!0,dimensions:"1-2",items:[{valType:"any",editType:"plot"},{valType:"any",editType:"plot"}],editType:"plot"},multiselect:{valType:"boolean",dflt:!0,editType:"plot"},values:{valType:"data_array",editType:"calc"},editType:"calc"}),line:s({editType:"calc"},n("line",{colorscaleDflt:"Viridis",autoColorDflt:!1,editTypeOverride:"calc"}))}},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plot_api/plot_template":543,"../../plots/cartesian/layout_attributes":569,"../../plots/domain":584,"../../plots/font_attributes":585}],889:[function(t,e,r){"use strict";var n=t("./constants"),i=t("@plotly/d3"),a=t("../../lib/gup").keyFun,o=t("../../lib/gup").repeat,s=t("../../lib").sorterAsc,l=t("../../lib").strTranslate,c=n.bar.snapRatio;function u(t,e){return t*(1-c)+e*c}var f=n.bar.snapClose;function h(t,e){return t*(1-f)+e*f}function p(t,e,r,n){if(function(t,e){for(var r=0;r<e.length;r++)if(t>=e[r][0]&&t<=e[r][1])return!0;return!1}(r,n))return r;var i=t?-1:1,a=0,o=e.length-1;if(i<0){var s=a;a=o,o=s}for(var l=e[a],c=l,f=a;i*f<i*o;f+=i){var p=f+i,d=e[p];if(i*r<i*h(l,d))return u(l,c);if(i*r<i*d||p===o)return u(d,l);c=l,l=d}}function d(t){t.attr("x",-n.bar.captureWidth/2).attr("width",n.bar.captureWidth)}function m(t){t.attr("visibility","visible").style("visibility","visible").attr("fill","yellow").attr("opacity",0)}function g(t){if(!t.brush.filterSpecified)return"0,"+t.height;for(var e,r,n,i=v(t.brush.filter.getConsolidated(),t.height),a=[0],o=i.length?i[0][0]:null,s=0;s<i.length;s++)r=(e=i[s])[1]-e[0],a.push(o),a.push(r),(n=s+1)<i.length&&(o=i[n][0]-e[1]);return a.push(t.height),a}function v(t,e){return t.map((function(t){return t.map((function(t){return Math.max(0,t*e)})).sort(s)}))}function y(){i.select(document.body).style("cursor",null)}function x(t){t.attr("stroke-dasharray",g)}function b(t,e){var r=i.select(t).selectAll(".highlight, .highlight-shadow");x(e?r.transition().duration(n.bar.snapDuration).each("end",e):r)}function _(t,e){var r,i=t.brush,a=NaN,o={};if(i.filterSpecified){var s=t.height,l=i.filter.getConsolidated(),c=v(l,s),u=NaN,f=NaN,h=NaN;for(r=0;r<=c.length;r++){var p=c[r];if(p&&p[0]<=e&&e<=p[1]){u=r;break}if(f=r?r-1:NaN,p&&p[0]>e){h=r;break}}if(a=u,isNaN(a)&&(a=isNaN(f)||isNaN(h)?isNaN(f)?h:f:e-c[f][1]<c[h][0]-e?f:h),!isNaN(a)){var d=c[a],m=function(t,e){var r=n.bar.handleHeight;if(!(e>t[1]+r||e<t[0]-r))return e>=.9*t[1]+.1*t[0]?"n":e<=.9*t[0]+.1*t[1]?"s":"ns"}(d,e);m&&(o.interval=l[a],o.intervalPix=d,o.region=m)}}if(t.ordinal&&!o.region){var g=t.unitTickvals,y=t.unitToPaddedPx.invert(e);for(r=0;r<g.length;r++){var x=[.25*g[Math.max(r-1,0)]+.75*g[r],.25*g[Math.min(r+1,g.length-1)]+.75*g[r]];if(y>=x[0]&&y<=x[1]){o.clickableOrdinalRange=x;break}}}return o}function w(t,e){i.event.sourceEvent.stopPropagation();var r=e.height-i.mouse(t)[1]-2*n.verticalPadding,a=e.brush.svgBrush;a.wasDragged=!0,a._dragging=!0,a.grabbingBar?a.newExtent=[r-a.grabPoint,r+a.barLength-a.grabPoint].map(e.unitToPaddedPx.invert):a.newExtent=[a.startExtent,e.unitToPaddedPx.invert(r)].sort(s),e.brush.filterSpecified=!0,a.extent=a.stayingIntervals.concat([a.newExtent]),a.brushCallback(e),b(t.parentNode)}function T(t,e){var r=_(e,e.height-i.mouse(t)[1]-2*n.verticalPadding),a="crosshair";r.clickableOrdinalRange?a="pointer":r.region&&(a=r.region+"-resize"),i.select(document.body).style("cursor",a)}function k(t){t.on("mousemove",(function(t){i.event.preventDefault(),t.parent.inBrushDrag||T(this,t)})).on("mouseleave",(function(t){t.parent.inBrushDrag||y()})).call(i.behavior.drag().on("dragstart",(function(t){!function(t,e){i.event.sourceEvent.stopPropagation();var r=e.height-i.mouse(t)[1]-2*n.verticalPadding,a=e.unitToPaddedPx.invert(r),o=e.brush,s=_(e,r),l=s.interval,c=o.svgBrush;if(c.wasDragged=!1,c.grabbingBar="ns"===s.region,c.grabbingBar){var u=l.map(e.unitToPaddedPx);c.grabPoint=r-u[0]-n.verticalPadding,c.barLength=u[1]-u[0]}c.clickableOrdinalRange=s.clickableOrdinalRange,c.stayingIntervals=e.multiselect&&o.filterSpecified?o.filter.getConsolidated():[],l&&(c.stayingIntervals=c.stayingIntervals.filter((function(t){return t[0]!==l[0]&&t[1]!==l[1]}))),c.startExtent=s.region?l["s"===s.region?1:0]:a,e.parent.inBrushDrag=!0,c.brushStartCallback()}(this,t)})).on("drag",(function(t){w(this,t)})).on("dragend",(function(t){!function(t,e){var r=e.brush,n=r.filter,a=r.svgBrush;a._dragging||(T(t,e),w(t,e),e.brush.svgBrush.wasDragged=!1),a._dragging=!1,i.event.sourceEvent.stopPropagation();var o=a.grabbingBar;if(a.grabbingBar=!1,a.grabLocation=void 0,e.parent.inBrushDrag=!1,y(),!a.wasDragged)return a.wasDragged=void 0,a.clickableOrdinalRange?r.filterSpecified&&e.multiselect?a.extent.push(a.clickableOrdinalRange):(a.extent=[a.clickableOrdinalRange],r.filterSpecified=!0):o?(a.extent=a.stayingIntervals,0===a.extent.length&&M(r)):M(r),a.brushCallback(e),b(t.parentNode),void a.brushEndCallback(r.filterSpecified?n.getConsolidated():[]);var s=function(){n.set(n.getConsolidated())};if(e.ordinal){var l=e.unitTickvals;l[l.length-1]<l[0]&&l.reverse(),a.newExtent=[p(0,l,a.newExtent[0],a.stayingIntervals),p(1,l,a.newExtent[1],a.stayingIntervals)];var c=a.newExtent[1]>a.newExtent[0];a.extent=a.stayingIntervals.concat(c?[a.newExtent]:[]),a.extent.length||M(r),a.brushCallback(e),c?b(t.parentNode,s):(s(),b(t.parentNode))}else s();a.brushEndCallback(r.filterSpecified?n.getConsolidated():[])}(this,t)})))}function A(t,e){return t[0]-e[0]}function M(t){t.filterSpecified=!1,t.svgBrush.extent=[[-1/0,1/0]]}function S(t){for(var e,r=t.slice(),n=[],i=r.shift();i;){for(e=i.slice();(i=r.shift())&&i[0]<=e[1];)e[1]=Math.max(e[1],i[1]);n.push(e)}return 1===n.length&&n[0][0]>n[0][1]&&(n=[]),n}e.exports={makeBrush:function(t,e,r,n,i,a){var o,l=function(){var t,e,r=[];return{set:function(n){1===(r=n.map((function(t){return t.slice().sort(s)})).sort(A)).length&&r[0][0]===-1/0&&r[0][1]===1/0&&(r=[[0,-1]]),t=S(r),e=r.reduce((function(t,e){return[Math.min(t[0],e[0]),Math.max(t[1],e[1])]}),[1/0,-1/0])},get:function(){return r.slice()},getConsolidated:function(){return t},getBounds:function(){return e}}}();return l.set(r),{filter:l,filterSpecified:e,svgBrush:{extent:[],brushStartCallback:n,brushCallback:(o=i,function(t){var e=t.brush,r=function(t){return t.svgBrush.extent.map((function(t){return t.slice()}))}(e).slice();e.filter.set(r),o()}),brushEndCallback:a}}},ensureAxisBrush:function(t,e){var r=t.selectAll("."+n.cn.axisBrush).data(o,a);r.enter().append("g").classed(n.cn.axisBrush,!0),function(t,e){var r=t.selectAll(".background").data(o);r.enter().append("rect").classed("background",!0).call(d).call(m).style("pointer-events","auto").attr("transform",l(0,n.verticalPadding)),r.call(k).attr("height",(function(t){return t.height-n.verticalPadding}));var i=t.selectAll(".highlight-shadow").data(o);i.enter().append("line").classed("highlight-shadow",!0).attr("x",-n.bar.width/2).attr("stroke-width",n.bar.width+n.bar.strokeWidth).attr("stroke",e).attr("opacity",n.bar.strokeOpacity).attr("stroke-linecap","butt"),i.attr("y1",(function(t){return t.height})).call(x);var a=t.selectAll(".highlight").data(o);a.enter().append("line").classed("highlight",!0).attr("x",-n.bar.width/2).attr("stroke-width",n.bar.width-n.bar.strokeWidth).attr("stroke",n.bar.fillColor).attr("opacity",n.bar.fillOpacity).attr("stroke-linecap","butt"),a.attr("y1",(function(t){return t.height})).call(x)}(r,e)},cleanRanges:function(t,e){if(Array.isArray(t[0])?(t=t.map((function(t){return t.sort(s)})),t=e.multiselect?S(t.sort(A)):[t[0]]):t=[t.sort(s)],e.tickvals){var r=e.tickvals.slice().sort(s);if(!(t=t.map((function(t){var e=[p(0,r,t[0],[]),p(1,r,t[1],[])];if(e[1]>e[0])return e})).filter((function(t){return t}))).length)return}return t.length>1?t:t[0]}}},{"../../lib":503,"../../lib/gup":500,"./constants":893,"@plotly/d3":58}],890:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),calc:t("./calc"),colorbar:{container:"line",min:"cmin",max:"cmax"},moduleType:"trace",name:"parcoords",basePlotModule:t("./base_plot"),categories:["gl","regl","noOpacity","noHover"],meta:{}}},{"./attributes":888,"./base_plot":891,"./calc":892,"./defaults":894}],891:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../plots/get_data").getModuleCalcData,a=t("./plot"),o=t("../../constants/xmlns_namespaces");r.name="parcoords",r.plot=function(t){var e=i(t.calcdata,"parcoords")[0];e.length&&a(t,e)},r.clean=function(t,e,r,n){var i=n._has&&n._has("parcoords"),a=e._has&&e._has("parcoords");i&&!a&&(n._paperdiv.selectAll(".parcoords").remove(),n._glimages.selectAll("*").remove())},r.toSVG=function(t){var e=t._fullLayout._glimages,r=n.select(t).selectAll(".svg-container");r.filter((function(t,e){return e===r.size()-1})).selectAll(".gl-canvas-context, .gl-canvas-focus").each((function(){var t=this.toDataURL("image/png");e.append("svg:image").attr({xmlns:o.svg,"xlink:href":t,preserveAspectRatio:"none",x:0,y:0,width:this.style.width,height:this.style.height})})),window.setTimeout((function(){n.selectAll("#filterBarPattern").attr("id","filterBarPattern")}),60)}},{"../../constants/xmlns_namespaces":480,"../../plots/get_data":593,"./plot":900,"@plotly/d3":58}],892:[function(t,e,r){"use strict";var n=t("../../lib").isArrayOrTypedArray,i=t("../../components/colorscale"),a=t("../../lib/gup").wrap;e.exports=function(t,e){var r,o;return i.hasColorscale(e,"line")&&n(e.line.color)?(r=e.line.color,o=i.extractOpts(e.line).colorscale,i.calc(t,e,{vals:r,containerStr:"line",cLetter:"c"})):(r=function(t){for(var e=new Array(t),r=0;r<t;r++)e[r]=.5;return e}(e._length),o=[[0,e.line.color],[1,e.line.color]]),a({lineColor:r,cscale:o})}},{"../../components/colorscale":378,"../../lib":503,"../../lib/gup":500}],893:[function(t,e,r){"use strict";e.exports={maxDimensionCount:60,overdrag:45,verticalPadding:2,tickDistance:50,canvasPixelRatio:1,blockLineCount:5e3,layers:["contextLineLayer","focusLineLayer","pickLineLayer"],axisTitleOffset:28,axisExtentOffset:10,deselectedLineColor:"#777",bar:{width:4,captureWidth:10,fillColor:"magenta",fillOpacity:1,snapDuration:150,snapRatio:.25,snapClose:.01,strokeOpacity:1,strokeWidth:1,handleHeight:8,handleOpacity:1,handleOverlap:0},cn:{axisExtentText:"axis-extent-text",parcoordsLineLayers:"parcoords-line-layers",parcoordsLineLayer:"parcoords-lines",parcoords:"parcoords",parcoordsControlView:"parcoords-control-view",yAxis:"y-axis",axisOverlays:"axis-overlays",axis:"axis",axisHeading:"axis-heading",axisTitle:"axis-title",axisExtent:"axis-extent",axisExtentTop:"axis-extent-top",axisExtentTopText:"axis-extent-top-text",axisExtentBottom:"axis-extent-bottom",axisExtentBottomText:"axis-extent-bottom-text",axisBrush:"axis-brush"},id:{filterBarPattern:"filter-bar-pattern"}}},{}],894:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/colorscale/helpers").hasColorscale,a=t("../../components/colorscale/defaults"),o=t("../../plots/domain").defaults,s=t("../../plots/array_container_defaults"),l=t("../../plots/cartesian/axes"),c=t("./attributes"),u=t("./axisbrush"),f=t("./constants").maxDimensionCount,h=t("./merge_length");function p(t,e,r,i){function a(r,i){return n.coerce(t,e,c.dimensions,r,i)}var o=a("values"),s=a("visible");if(o&&o.length||(s=e.visible=!1),s){a("label"),a("tickvals"),a("ticktext"),a("tickformat");var f=a("range");e._ax={_id:"y",type:"linear",showexponent:"all",exponentformat:"B",range:f},l.setConvert(e._ax,i.layout),a("multiselect");var h=a("constraintrange");h&&(e.constraintrange=u.cleanRanges(h,e))}}e.exports=function(t,e,r,l){function u(r,i){return n.coerce(t,e,c,r,i)}var d=t.dimensions;Array.isArray(d)&&d.length>f&&(n.log("parcoords traces support up to "+f+" dimensions at the moment"),d.splice(f));var m=s(t,e,{name:"dimensions",layout:l,handleItemDefaults:p}),g=function(t,e,r,o,s){var l=s("line.color",r);if(i(t,"line")&&n.isArrayOrTypedArray(l)){if(l.length)return s("line.colorscale"),a(t,e,o,s,{prefix:"line.",cLetter:"c"}),l.length;e.line.color=r}return 1/0}(t,e,r,l,u);o(e,l,u),Array.isArray(m)&&m.length||(e.visible=!1),h(e,m,"values",g);var v={family:l.font.family,size:Math.round(l.font.size/1.2),color:l.font.color};n.coerceFont(u,"labelfont",v),n.coerceFont(u,"tickfont",v),n.coerceFont(u,"rangefont",v),u("labelangle"),u("labelside")}},{"../../components/colorscale/defaults":376,"../../components/colorscale/helpers":377,"../../lib":503,"../../plots/array_container_defaults":549,"../../plots/cartesian/axes":554,"../../plots/domain":584,"./attributes":888,"./axisbrush":889,"./constants":893,"./merge_length":898}],895:[function(t,e,r){"use strict";var n=t("../../lib").isTypedArray;r.convertTypedArray=function(t){return n(t)?Array.prototype.slice.call(t):t},r.isOrdinal=function(t){return!!t.tickvals},r.isVisible=function(t){return t.visible||!("visible"in t)}},{"../../lib":503}],896:[function(t,e,r){"use strict";var n=t("./base_index");n.plot=t("./plot"),e.exports=n},{"./base_index":890,"./plot":900}],897:[function(t,e,r){"use strict";var n=t("glslify"),i=n(["precision highp float;\n#define GLSLIFY 1\n\nvarying vec4 fragColor;\n\nattribute vec4 p01_04, p05_08, p09_12, p13_16,\n               p17_20, p21_24, p25_28, p29_32,\n               p33_36, p37_40, p41_44, p45_48,\n               p49_52, p53_56, p57_60, colors;\n\nuniform mat4 dim0A, dim1A, dim0B, dim1B, dim0C, dim1C, dim0D, dim1D,\n             loA, hiA, loB, hiB, loC, hiC, loD, hiD;\n\nuniform vec2 resolution, viewBoxPos, viewBoxSize;\nuniform float maskHeight;\nuniform float drwLayer; // 0: context, 1: focus, 2: pick\nuniform vec4 contextColor;\nuniform sampler2D maskTexture, palette;\n\nbool isPick    = (drwLayer > 1.5);\nbool isContext = (drwLayer < 0.5);\n\nconst vec4 ZEROS = vec4(0.0, 0.0, 0.0, 0.0);\nconst vec4 UNITS = vec4(1.0, 1.0, 1.0, 1.0);\n\nfloat val(mat4 p, mat4 v) {\n    return dot(matrixCompMult(p, v) * UNITS, UNITS);\n}\n\nfloat axisY(float ratio, mat4 A, mat4 B, mat4 C, mat4 D) {\n    float y1 = val(A, dim0A) + val(B, dim0B) + val(C, dim0C) + val(D, dim0D);\n    float y2 = val(A, dim1A) + val(B, dim1B) + val(C, dim1C) + val(D, dim1D);\n    return y1 * (1.0 - ratio) + y2 * ratio;\n}\n\nint iMod(int a, int b) {\n    return a - b * (a / b);\n}\n\nbool fOutside(float p, float lo, float hi) {\n    return (lo < hi) && (lo > p || p > hi);\n}\n\nbool vOutside(vec4 p, vec4 lo, vec4 hi) {\n    return (\n        fOutside(p[0], lo[0], hi[0]) ||\n        fOutside(p[1], lo[1], hi[1]) ||\n        fOutside(p[2], lo[2], hi[2]) ||\n        fOutside(p[3], lo[3], hi[3])\n    );\n}\n\nbool mOutside(mat4 p, mat4 lo, mat4 hi) {\n    return (\n        vOutside(p[0], lo[0], hi[0]) ||\n        vOutside(p[1], lo[1], hi[1]) ||\n        vOutside(p[2], lo[2], hi[2]) ||\n        vOutside(p[3], lo[3], hi[3])\n    );\n}\n\nbool outsideBoundingBox(mat4 A, mat4 B, mat4 C, mat4 D) {\n    return mOutside(A, loA, hiA) ||\n           mOutside(B, loB, hiB) ||\n           mOutside(C, loC, hiC) ||\n           mOutside(D, loD, hiD);\n}\n\nbool outsideRasterMask(mat4 A, mat4 B, mat4 C, mat4 D) {\n    mat4 pnts[4];\n    pnts[0] = A;\n    pnts[1] = B;\n    pnts[2] = C;\n    pnts[3] = D;\n\n    for(int i = 0; i < 4; ++i) {\n        for(int j = 0; j < 4; ++j) {\n            for(int k = 0; k < 4; ++k) {\n                if(0 == iMod(\n                    int(255.0 * texture2D(maskTexture,\n                        vec2(\n                            (float(i * 2 + j / 2) + 0.5) / 8.0,\n                            (pnts[i][j][k] * (maskHeight - 1.0) + 1.0) / maskHeight\n                        ))[3]\n                    ) / int(pow(2.0, float(iMod(j * 4 + k, 8)))),\n                    2\n                )) return true;\n            }\n        }\n    }\n    return false;\n}\n\nvec4 position(bool isContext, float v, mat4 A, mat4 B, mat4 C, mat4 D) {\n    float x = 0.5 * sign(v) + 0.5;\n    float y = axisY(x, A, B, C, D);\n    float z = 1.0 - abs(v);\n\n    z += isContext ? 0.0 : 2.0 * float(\n        outsideBoundingBox(A, B, C, D) ||\n        outsideRasterMask(A, B, C, D)\n    );\n\n    return vec4(\n        2.0 * (vec2(x, y) * viewBoxSize + viewBoxPos) / resolution - 1.0,\n        z,\n        1.0\n    );\n}\n\nvoid main() {\n    mat4 A = mat4(p01_04, p05_08, p09_12, p13_16);\n    mat4 B = mat4(p17_20, p21_24, p25_28, p29_32);\n    mat4 C = mat4(p33_36, p37_40, p41_44, p45_48);\n    mat4 D = mat4(p49_52, p53_56, p57_60, ZEROS);\n\n    float v = colors[3];\n\n    gl_Position = position(isContext, v, A, B, C, D);\n\n    fragColor =\n        isContext ? vec4(contextColor) :\n        isPick ? vec4(colors.rgb, 1.0) : texture2D(palette, vec2(abs(v), 0.5));\n}\n"]),a=n(["precision highp float;\n#define GLSLIFY 1\n\nvarying vec4 fragColor;\n\nvoid main() {\n    gl_FragColor = fragColor;\n}\n"]),o=t("./constants").maxDimensionCount,s=t("../../lib"),l=new Uint8Array(4),c=new Uint8Array(4),u={shape:[256,1],format:"rgba",type:"uint8",mag:"nearest",min:"nearest"};function f(t,e,r,n,i){var a=t._gl;a.enable(a.SCISSOR_TEST),a.scissor(e,r,n,i),t.clear({color:[0,0,0,0],depth:1})}function h(t,e,r,n,i,a){var o=a.key;r.drawCompleted||(!function(t){t.read({x:0,y:0,width:1,height:1,data:l})}(t),r.drawCompleted=!0),function s(l){var c=Math.min(n,i-l*n);0===l&&(window.cancelAnimationFrame(r.currentRafs[o]),delete r.currentRafs[o],f(t,a.scissorX,a.scissorY,a.scissorWidth,a.viewBoxSize[1])),r.clearOnly||(a.count=2*c,a.offset=2*l*n,e(a),l*n+c<i&&(r.currentRafs[o]=window.requestAnimationFrame((function(){s(l+1)}))),r.drawCompleted=!1)}(0)}function p(t,e){for(var r=new Array(256),n=0;n<256;n++)r[n]=t(n/255).concat(e);return r}function d(t,e){return(t>>>8*e)%256/255}function m(t,e,r){for(var n=new Array(8*e),i=0,a=0;a<e;a++)for(var o=0;o<2;o++)for(var s=0;s<4;s++){var l=4*t+s,c=r[64*a+l];63===l&&0===o&&(c*=-1),n[i++]=c}return n}function g(t){var e="0"+t;return e.substr(e.length-2)}function v(t){return t<o?"p"+g(t+1)+"_"+g(t+4):"colors"}function y(t,e,r,n,i,a,o,l,c,u,f,h,p,d){for(var m=[[],[]],g=0;g<64;g++)m[0][g]=g===i?1:0,m[1][g]=g===a?1:0;o*=d,l*=d,c*=d,u*=d;var v=t.lines.canvasOverdrag*d,y=t.domain,x=t.canvasWidth*d,b=t.canvasHeight*d,_=t.pad.l*d,w=t.pad.b*d,T=t.layoutHeight*d,k=t.layoutWidth*d,A=t.deselectedLines.color;return s.extendFlat({key:f,resolution:[x,b],viewBoxPos:[o+v,l],viewBoxSize:[c,u],i0:i,i1:a,dim0A:m[0].slice(0,16),dim0B:m[0].slice(16,32),dim0C:m[0].slice(32,48),dim0D:m[0].slice(48,64),dim1A:m[1].slice(0,16),dim1B:m[1].slice(16,32),dim1C:m[1].slice(32,48),dim1D:m[1].slice(48,64),drwLayer:h,contextColor:[A[0]/255,A[1]/255,A[2]/255,A[3]<1?A[3]:Math.max(1/255,Math.pow(1/t.lines.color.length,1/3))],scissorX:(n===e?0:o+v)+(_-v)+k*y.x[0],scissorWidth:(n===r?x-o+v:c+.5)+(n===e?o+v:0),scissorY:l+w+T*y.y[0],scissorHeight:u,viewportX:_-v+k*y.x[0],viewportY:w+T*y.y[0],viewportWidth:x,viewportHeight:b},p)}function x(t){var e=Math.max(0,Math.floor(2047*t[0]),0),r=Math.min(2047,Math.ceil(2047*t[1]),2047);return[Math.min(e,r),Math.max(e,r)]}e.exports=function(t,e){var r,n,l,g,b,_=e.context,w=e.pick,T=e.regl,k=T._gl,A=k.getParameter(k.ALIASED_LINE_WIDTH_RANGE),M=Math.max(A[0],Math.min(A[1],e.viewModel.plotGlPixelRatio)),S={currentRafs:{},drawCompleted:!0,clearOnly:!1},E=function(t){for(var e={},r=0;r<=o;r+=4)e[v(r)]=t.buffer({usage:"dynamic",type:"float",data:new Uint8Array(0)});return e}(T),L=T.texture(u),C=[];I(e);var P=T({profile:!1,blend:{enable:_,func:{srcRGB:"src alpha",dstRGB:"one minus src alpha",srcAlpha:1,dstAlpha:1},equation:{rgb:"add",alpha:"add"},color:[0,0,0,0]},depth:{enable:!_,mask:!0,func:"less",range:[0,1]},cull:{enable:!0,face:"back"},scissor:{enable:!0,box:{x:T.prop("scissorX"),y:T.prop("scissorY"),width:T.prop("scissorWidth"),height:T.prop("scissorHeight")}},viewport:{x:T.prop("viewportX"),y:T.prop("viewportY"),width:T.prop("viewportWidth"),height:T.prop("viewportHeight")},dither:!1,vert:i,frag:a,primitive:"lines",lineWidth:M,attributes:E,uniforms:{resolution:T.prop("resolution"),viewBoxPos:T.prop("viewBoxPos"),viewBoxSize:T.prop("viewBoxSize"),dim0A:T.prop("dim0A"),dim1A:T.prop("dim1A"),dim0B:T.prop("dim0B"),dim1B:T.prop("dim1B"),dim0C:T.prop("dim0C"),dim1C:T.prop("dim1C"),dim0D:T.prop("dim0D"),dim1D:T.prop("dim1D"),loA:T.prop("loA"),hiA:T.prop("hiA"),loB:T.prop("loB"),hiB:T.prop("hiB"),loC:T.prop("loC"),hiC:T.prop("hiC"),loD:T.prop("loD"),hiD:T.prop("hiD"),palette:L,contextColor:T.prop("contextColor"),maskTexture:T.prop("maskTexture"),drwLayer:T.prop("drwLayer"),maskHeight:T.prop("maskHeight")},offset:T.prop("offset"),count:T.prop("count")});function I(t){r=t.model,n=t.viewModel,l=n.dimensions.slice(),g=l[0]?l[0].values.length:0;var e=r.lines,i=w?e.color.map((function(t,r){return r/e.color.length})):e.color,a=function(t,e,r){for(var n,i=new Array(t*(o+4)),a=0,s=0;s<t;s++){for(var l=0;l<o;l++)i[a++]=l<e.length?e[l].paddedUnitValues[s]:.5;i[a++]=d(s,2),i[a++]=d(s,1),i[a++]=d(s,0),i[a++]=(n=r[s],Math.max(1e-6,Math.min(.999999,n)))}return i}(g,l,i);!function(t,e,r){for(var n=0;n<=o;n+=4)t[v(n)](m(n/4,e,r))}(E,g,a),_||w||(L=T.texture(s.extendFlat({data:p(r.unitToColor,255)},u)))}return{render:function(t,e,n){var i,a,o,s=t.length,c=1/0,u=-1/0;for(i=0;i<s;i++)t[i].dim0.canvasX<c&&(c=t[i].dim0.canvasX,a=i),t[i].dim1.canvasX>u&&(u=t[i].dim1.canvasX,o=i);0===s&&f(T,0,0,r.canvasWidth,r.canvasHeight);var p=function(t){var e,r,n,i=[[],[]];for(n=0;n<64;n++){var a=!t&&n<l.length?l[n].brush.filter.getBounds():[-1/0,1/0];i[0][n]=a[0],i[1][n]=a[1]}var o=new Array(16384);for(e=0;e<16384;e++)o[e]=255;if(!t)for(e=0;e<l.length;e++){var s=e%8,c=(e-s)/8,u=Math.pow(2,s),f=l[e].brush.filter.get();if(!(f.length<2)){var h=x(f[0])[1];for(r=1;r<f.length;r++){var p=x(f[r]);for(n=h+1;n<p[0];n++)o[8*n+c]&=~u;h=Math.max(h,p[1])}}}var d={shape:[8,2048],format:"alpha",type:"uint8",mag:"nearest",min:"nearest",data:o};return b?b(d):b=T.texture(d),{maskTexture:b,maskHeight:2048,loA:i[0].slice(0,16),loB:i[0].slice(16,32),loC:i[0].slice(32,48),loD:i[0].slice(48,64),hiA:i[1].slice(0,16),hiB:i[1].slice(16,32),hiC:i[1].slice(32,48),hiD:i[1].slice(48,64)}}(_);for(i=0;i<s;i++){var d=t[i],m=d.dim0.crossfilterDimensionIndex,v=d.dim1.crossfilterDimensionIndex,k=d.canvasX,A=d.canvasY,M=k+d.panelSizeX,E=d.plotGlPixelRatio;if(e||!C[m]||C[m][0]!==k||C[m][1]!==M){C[m]=[k,M];var L=y(r,a,o,i,m,v,k,A,d.panelSizeX,d.panelSizeY,d.dim0.crossfilterDimensionIndex,_?0:w?2:1,p,E);S.clearOnly=n;var I=e?r.lines.blockLineCount:g;h(T,P,S,I,g,L)}}},readPixel:function(t,e){return T.read({x:t,y:e,width:1,height:1,data:c}),c},readPixels:function(t,e,r,n){var i=new Uint8Array(4*r*n);return T.read({x:t,y:e,width:r,height:n,data:i}),i},destroy:function(){for(var e in t.style["pointer-events"]="none",L.destroy(),b&&b.destroy(),E)E[e].destroy()},update:I}}},{"../../lib":503,"./constants":893,glslify:227}],898:[function(t,e,r){"use strict";e.exports=function(t,e,r,n){var i,a;for(n||(n=1/0),i=0;i<e.length;i++)(a=e[i]).visible&&(n=Math.min(n,a[r].length));for(n===1/0&&(n=0),t._length=n,i=0;i<e.length;i++)(a=e[i]).visible&&(a._length=n);return n}},{}],899:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=i.numberFormat,o=t("color-rgba"),s=t("../../plots/cartesian/axes"),l=i.strRotate,c=i.strTranslate,u=t("../../lib/svg_text_utils"),f=t("../../components/drawing"),h=t("../../components/colorscale"),p=t("../../lib/gup"),d=p.keyFun,m=p.repeat,g=p.unwrap,v=t("./helpers"),y=t("./constants"),x=t("./axisbrush"),b=t("./lines");function _(t,e,r){return i.aggNums(t,null,e,r)}function w(t,e){return k(_(Math.min,t,e),_(Math.max,t,e))}function T(t){var e=t.range;return e?k(e[0],e[1]):w(t.values,t._length)}function k(t,e){return!isNaN(t)&&isFinite(t)||(t=0),!isNaN(e)&&isFinite(e)||(e=0),t===e&&(0===t?(t-=1,e+=1):(t*=.9,e*=1.1)),[t,e]}function A(t,e,r,i,o){var s,l,c=T(r);return i?n.scale.ordinal().domain(i.map((s=a(r.tickformat),l=o,l?function(t,e){var r=l[e];return null==r?s(t):r}:s))).range(i.map((function(r){var n=(r-c[0])/(c[1]-c[0]);return t-e+n*(2*e-t)}))):n.scale.linear().domain(c).range([t-e,e])}function M(t){if(t.tickvals){var e=T(t);return n.scale.ordinal().domain(t.tickvals).range(t.tickvals.map((function(t){return(t-e[0])/(e[1]-e[0])})))}}function S(t){var e=t.map((function(t){return t[0]})),r=t.map((function(t){var e=o(t[1]);return n.rgb("rgb("+e[0]+","+e[1]+","+e[2]+")")})),i="rgb".split("").map((function(t){return n.scale.linear().clamp(!0).domain(e).range(r.map((i=t,function(t){return t[i]})));var i}));return function(t){return i.map((function(e){return e(t)}))}}function E(t){return t.dimensions.some((function(t){return t.brush.filterSpecified}))}function L(t,e,r){var a=g(e),s=a.trace,l=v.convertTypedArray(a.lineColor),c=s.line,u={color:o(y.deselectedLineColor)},f=h.extractOpts(c),p=f.reversescale?h.flipScale(a.cscale):a.cscale,d=s.domain,m=s.dimensions,x=t.width,b=s.labelangle,_=s.labelside,w=s.labelfont,k=s.tickfont,A=s.rangefont,M=i.extendDeepNoArrays({},c,{color:l.map(n.scale.linear().domain(T({values:l,range:[f.min,f.max],_length:s._length}))),blockLineCount:y.blockLineCount,canvasOverdrag:y.overdrag*y.canvasPixelRatio}),E=Math.floor(x*(d.x[1]-d.x[0])),L=Math.floor(t.height*(d.y[1]-d.y[0])),C=t.margin||{l:80,r:80,t:100,b:80},P=E,I=L;return{key:r,colCount:m.filter(v.isVisible).length,dimensions:m,tickDistance:y.tickDistance,unitToColor:S(p),lines:M,deselectedLines:u,labelAngle:b,labelSide:_,labelFont:w,tickFont:k,rangeFont:A,layoutWidth:x,layoutHeight:t.height,domain:d,translateX:d.x[0]*x,translateY:t.height-d.y[1]*t.height,pad:C,canvasWidth:P*y.canvasPixelRatio+2*M.canvasOverdrag,canvasHeight:I*y.canvasPixelRatio,width:P,height:I,canvasPixelRatio:y.canvasPixelRatio}}function C(t,e,r){var o=r.width,s=r.height,l=r.dimensions,c=r.canvasPixelRatio,u=function(t){return o*t/Math.max(1,r.colCount-1)},f=y.verticalPadding/s,h=function(t,e){return n.scale.linear().range([e,t-e])}(s,y.verticalPadding),p={key:r.key,xScale:u,model:r,inBrushDrag:!1},d={};return p.dimensions=l.filter(v.isVisible).map((function(o,l){var m=function(t,e){return n.scale.linear().domain(T(t)).range([e,1-e])}(o,f),g=d[o.label];d[o.label]=(g||0)+1;var b=o.label+(g?"__"+g:""),_=o.constraintrange,w=_&&_.length;w&&!Array.isArray(_[0])&&(_=[_]);var k=w?_.map((function(t){return t.map(m)})):[[-1/0,1/0]],S=o.values;S.length>o._length&&(S=S.slice(0,o._length));var L,C=o.tickvals;function P(t,e){return{val:t,text:L[e]}}function I(t,e){return t.val-e.val}if(Array.isArray(C)&&C.length){L=o.ticktext,Array.isArray(L)&&L.length?L.length>C.length?L=L.slice(0,C.length):C.length>L.length&&(C=C.slice(0,L.length)):L=C.map(a(o.tickformat));for(var O=1;O<C.length;O++)if(C[O]<C[O-1]){for(var z=C.map(P).sort(I),D=0;D<C.length;D++)C[D]=z[D].val,L[D]=z[D].text;break}}else C=void 0;return S=v.convertTypedArray(S),{key:b,label:o.label,tickFormat:o.tickformat,tickvals:C,ticktext:L,ordinal:v.isOrdinal(o),multiselect:o.multiselect,xIndex:l,crossfilterDimensionIndex:l,visibleIndex:o._index,height:s,values:S,paddedUnitValues:S.map(m),unitTickvals:C&&C.map(m),xScale:u,x:u(l),canvasX:u(l)*c,unitToPaddedPx:h,domainScale:A(s,y.verticalPadding,o,C,L),ordinalScale:M(o),parent:p,model:r,brush:x.makeBrush(t,w,k,(function(){t.linePickActive(!1)}),(function(){var e=p;e.focusLayer&&e.focusLayer.render(e.panels,!0);var r=E(e);!t.contextShown()&&r?(e.contextLayer&&e.contextLayer.render(e.panels,!0),t.contextShown(!0)):t.contextShown()&&!r&&(e.contextLayer&&e.contextLayer.render(e.panels,!0,!0),t.contextShown(!1))}),(function(r){if(p.focusLayer.render(p.panels,!0),p.pickLayer&&p.pickLayer.render(p.panels,!0),t.linePickActive(!0),e&&e.filterChanged){var n=m.invert,a=r.map((function(t){return t.map(n).sort(i.sorterAsc)})).sort((function(t,e){return t[0]-e[0]}));e.filterChanged(p.key,o._index,a)}}))}})),p}function P(t){t.classed(y.cn.axisExtentText,!0).attr("text-anchor","middle").style("cursor","default")}function I(t,e){var r="top"===e?1:-1,n=t*Math.PI/180;return{dir:r,dx:Math.sin(n),dy:Math.cos(n),degrees:t}}function O(t,e,r){for(var n=e.panels||(e.panels=[]),i=t.data(),a=0;a<i.length-1;a++){var o=n[a]||(n[a]={}),s=i[a],l=i[a+1];o.dim0=s,o.dim1=l,o.canvasX=s.canvasX,o.panelSizeX=l.canvasX-s.canvasX,o.panelSizeY=e.model.canvasHeight,o.y=0,o.canvasY=0,o.plotGlPixelRatio=r}}function z(t,e){return s.tickText(t._ax,e,!1).text}function D(t,e){if(t.ordinal)return"";var r=t.domainScale.domain(),n=r[e?r.length-1:0];return z(t.model.dimensions[t.visibleIndex],n)}e.exports=function(t,e,r,a){var o=t._fullLayout,h=o._toppaper,p=o._glcontainer,_=t._context.plotGlPixelRatio,T=t._fullLayout.paper_bgcolor;!function(t){for(var e=0;e<t.length;e++)for(var r=0;r<t[e].length;r++)for(var n=t[e][r].trace,i=n.dimensions,a=0;a<i.length;a++){var o=i[a].values,l=i[a]._ax;l&&(l.range?l.range=k(l.range[0],l.range[1]):l.range=w(o,n._length),l.dtick||(l.dtick=.01*(Math.abs(l.range[1]-l.range[0])||1)),l.tickformat=i[a].tickformat,s.calcTicks(l),l.cleanRange())}}(e);var A,M,S=(A=!0,M=!1,{linePickActive:function(t){return arguments.length?A=!!t:A},contextShown:function(t){return arguments.length?M=!!t:M}}),R=e.filter((function(t){return g(t).trace.visible})).map(L.bind(0,r)).map(C.bind(0,S,a));p.each((function(t,e){return i.extendFlat(t,R[e])}));var F=p.selectAll(".gl-canvas").each((function(t){t.viewModel=R[0],t.viewModel.plotGlPixelRatio=_,t.viewModel.paperColor=T,t.model=t.viewModel?t.viewModel.model:null})),B=null;F.filter((function(t){return t.pick})).style("pointer-events","auto").on("mousemove",(function(t){if(S.linePickActive()&&t.lineLayer&&a&&a.hover){var e=n.event,r=this.width,i=this.height,o=n.mouse(this),s=o[0],l=o[1];if(s<0||l<0||s>=r||l>=i)return;var c=t.lineLayer.readPixel(s,i-1-l),u=0!==c[3],f=u?c[2]+256*(c[1]+256*c[0]):null,h={x:s,y:l,clientX:e.clientX,clientY:e.clientY,dataIndex:t.model.key,curveNumber:f};f!==B&&(u?a.hover(h):a.unhover&&a.unhover(h),B=f)}})),F.style("opacity",(function(t){return t.pick?0:1})),h.style("background","rgba(255, 255, 255, 0)");var N=h.selectAll("."+y.cn.parcoords).data(R,d);N.exit().remove(),N.enter().append("g").classed(y.cn.parcoords,!0).style("shape-rendering","crispEdges").style("pointer-events","none"),N.attr("transform",(function(t){return c(t.model.translateX,t.model.translateY)}));var j=N.selectAll("."+y.cn.parcoordsControlView).data(m,d);j.enter().append("g").classed(y.cn.parcoordsControlView,!0),j.attr("transform",(function(t){return c(t.model.pad.l,t.model.pad.t)}));var U=j.selectAll("."+y.cn.yAxis).data((function(t){return t.dimensions}),d);U.enter().append("g").classed(y.cn.yAxis,!0),j.each((function(t){O(U,t,_)})),F.each((function(t){if(t.viewModel){!t.lineLayer||a?t.lineLayer=b(this,t):t.lineLayer.update(t),(t.key||0===t.key)&&(t.viewModel[t.key]=t.lineLayer);var e=!t.context||a;t.lineLayer.render(t.viewModel.panels,e)}})),U.attr("transform",(function(t){return c(t.xScale(t.xIndex),0)})),U.call(n.behavior.drag().origin((function(t){return t})).on("drag",(function(t){var e=t.parent;S.linePickActive(!1),t.x=Math.max(-y.overdrag,Math.min(t.model.width+y.overdrag,n.event.x)),t.canvasX=t.x*t.model.canvasPixelRatio,U.sort((function(t,e){return t.x-e.x})).each((function(e,r){e.xIndex=r,e.x=t===e?e.x:e.xScale(e.xIndex),e.canvasX=e.x*e.model.canvasPixelRatio})),O(U,e,_),U.filter((function(e){return 0!==Math.abs(t.xIndex-e.xIndex)})).attr("transform",(function(t){return c(t.xScale(t.xIndex),0)})),n.select(this).attr("transform",c(t.x,0)),U.each((function(r,n,i){i===t.parent.key&&(e.dimensions[n]=r)})),e.contextLayer&&e.contextLayer.render(e.panels,!1,!E(e)),e.focusLayer.render&&e.focusLayer.render(e.panels)})).on("dragend",(function(t){var e=t.parent;t.x=t.xScale(t.xIndex),t.canvasX=t.x*t.model.canvasPixelRatio,O(U,e,_),n.select(this).attr("transform",(function(t){return c(t.x,0)})),e.contextLayer&&e.contextLayer.render(e.panels,!1,!E(e)),e.focusLayer&&e.focusLayer.render(e.panels),e.pickLayer&&e.pickLayer.render(e.panels,!0),S.linePickActive(!0),a&&a.axesMoved&&a.axesMoved(e.key,e.dimensions.map((function(t){return t.crossfilterDimensionIndex})))}))),U.exit().remove();var V=U.selectAll("."+y.cn.axisOverlays).data(m,d);V.enter().append("g").classed(y.cn.axisOverlays,!0),V.selectAll("."+y.cn.axis).remove();var H=V.selectAll("."+y.cn.axis).data(m,d);H.enter().append("g").classed(y.cn.axis,!0),H.each((function(t){var e=t.model.height/t.model.tickDistance,r=t.domainScale,i=r.domain();n.select(this).call(n.svg.axis().orient("left").tickSize(4).outerTickSize(2).ticks(e,t.tickFormat).tickValues(t.ordinal?i:null).tickFormat((function(e){return v.isOrdinal(t)?e:z(t.model.dimensions[t.visibleIndex],e)})).scale(r)),f.font(H.selectAll("text"),t.model.tickFont)})),H.selectAll(".domain, .tick>line").attr("fill","none").attr("stroke","black").attr("stroke-opacity",.25).attr("stroke-width","1px"),H.selectAll("text").style("text-shadow",u.makeTextShadow(T)).style("cursor","default");var q=V.selectAll("."+y.cn.axisHeading).data(m,d);q.enter().append("g").classed(y.cn.axisHeading,!0);var G=q.selectAll("."+y.cn.axisTitle).data(m,d);G.enter().append("text").classed(y.cn.axisTitle,!0).attr("text-anchor","middle").style("cursor","ew-resize").style("pointer-events","auto"),G.text((function(t){return t.label})).each((function(e){var r=n.select(this);f.font(r,e.model.labelFont),u.convertToTspans(r,t)})).attr("transform",(function(t){var e=I(t.model.labelAngle,t.model.labelSide),r=y.axisTitleOffset;return(e.dir>0?"":c(0,2*r+t.model.height))+l(e.degrees)+c(-r*e.dx,-r*e.dy)})).attr("text-anchor",(function(t){var e=I(t.model.labelAngle,t.model.labelSide);return 2*Math.abs(e.dx)>Math.abs(e.dy)?e.dir*e.dx<0?"start":"end":"middle"}));var Y=V.selectAll("."+y.cn.axisExtent).data(m,d);Y.enter().append("g").classed(y.cn.axisExtent,!0);var W=Y.selectAll("."+y.cn.axisExtentTop).data(m,d);W.enter().append("g").classed(y.cn.axisExtentTop,!0),W.attr("transform",c(0,-y.axisExtentOffset));var X=W.selectAll("."+y.cn.axisExtentTopText).data(m,d);X.enter().append("text").classed(y.cn.axisExtentTopText,!0).call(P),X.text((function(t){return D(t,!0)})).each((function(t){f.font(n.select(this),t.model.rangeFont)}));var Z=Y.selectAll("."+y.cn.axisExtentBottom).data(m,d);Z.enter().append("g").classed(y.cn.axisExtentBottom,!0),Z.attr("transform",(function(t){return c(0,t.model.height+y.axisExtentOffset)}));var J=Z.selectAll("."+y.cn.axisExtentBottomText).data(m,d);J.enter().append("text").classed(y.cn.axisExtentBottomText,!0).attr("dy","0.75em").call(P),J.text((function(t){return D(t,!1)})).each((function(t){f.font(n.select(this),t.model.rangeFont)})),x.ensureAxisBrush(V,T)}},{"../../components/colorscale":378,"../../components/drawing":388,"../../lib":503,"../../lib/gup":500,"../../lib/svg_text_utils":529,"../../plots/cartesian/axes":554,"./axisbrush":889,"./constants":893,"./helpers":895,"./lines":897,"@plotly/d3":58,"color-rgba":91}],900:[function(t,e,r){"use strict";var n=t("./parcoords"),i=t("../../lib/prepare_regl"),a=t("./helpers").isVisible,o={};function s(t,e,r){var n=e.indexOf(r),i=t.indexOf(n);return-1===i&&(i+=e.length),i}(e.exports=function(t,e){var r=t._fullLayout;if(i(t,[],o)){var l={},c={},u={},f={},h=r._size;e.forEach((function(e,r){var n=e[0].trace;u[r]=n.index;var i=f[r]=n._fullInput.index;l[r]=t.data[i].dimensions,c[r]=t.data[i].dimensions.slice()}));n(t,e,{width:h.w,height:h.h,margin:{t:h.t,r:h.r,b:h.b,l:h.l}},{filterChanged:function(e,n,i){var a=c[e][n],o=i.map((function(t){return t.slice()})),s="dimensions["+n+"].constraintrange",l=r._tracePreGUI[t._fullData[u[e]]._fullInput.uid];if(void 0===l[s]){var h=a.constraintrange;l[s]=h||null}var p=t._fullData[u[e]].dimensions[n];o.length?(1===o.length&&(o=o[0]),a.constraintrange=o,p.constraintrange=o.slice(),o=[o]):(delete a.constraintrange,delete p.constraintrange,o=null);var d={};d[s]=o,t.emit("plotly_restyle",[d,[f[e]]])},hover:function(e){t.emit("plotly_hover",e)},unhover:function(e){t.emit("plotly_unhover",e)},axesMoved:function(e,r){var n=function(t,e){return function(r,n){return s(t,e,r)-s(t,e,n)}}(r,c[e].filter(a));l[e].sort(n),c[e].filter((function(t){return!a(t)})).sort((function(t){return c[e].indexOf(t)})).forEach((function(t){l[e].splice(l[e].indexOf(t),1),l[e].splice(c[e].indexOf(t),0,t)})),t.emit("plotly_restyle",[{dimensions:[l[e]]},[f[e]]])}})}}).reglPrecompiled=o},{"../../lib/prepare_regl":516,"./helpers":895,"./parcoords":899}],901:[function(t,e,r){"use strict";var n=t("../../plots/attributes"),i=t("../../plots/domain").attributes,a=t("../../plots/font_attributes"),o=t("../../components/color/attributes"),s=t("../../plots/template_attributes").hovertemplateAttrs,l=t("../../plots/template_attributes").texttemplateAttrs,c=t("../../lib/extend").extendFlat,u=a({editType:"plot",arrayOk:!0,colorEditType:"plot"});e.exports={labels:{valType:"data_array",editType:"calc"},label0:{valType:"number",dflt:0,editType:"calc"},dlabel:{valType:"number",dflt:1,editType:"calc"},values:{valType:"data_array",editType:"calc"},marker:{colors:{valType:"data_array",editType:"calc"},line:{color:{valType:"color",dflt:o.defaultLine,arrayOk:!0,editType:"style"},width:{valType:"number",min:0,dflt:0,arrayOk:!0,editType:"style"},editType:"calc"},editType:"calc"},text:{valType:"data_array",editType:"plot"},hovertext:{valType:"string",dflt:"",arrayOk:!0,editType:"style"},scalegroup:{valType:"string",dflt:"",editType:"calc"},textinfo:{valType:"flaglist",flags:["label","text","value","percent"],extras:["none"],editType:"calc"},hoverinfo:c({},n.hoverinfo,{flags:["label","text","value","percent","name"]}),hovertemplate:s({},{keys:["label","color","value","percent","text"]}),texttemplate:l({editType:"plot"},{keys:["label","color","value","percent","text"]}),textposition:{valType:"enumerated",values:["inside","outside","auto","none"],dflt:"auto",arrayOk:!0,editType:"plot"},textfont:c({},u,{}),insidetextorientation:{valType:"enumerated",values:["horizontal","radial","tangential","auto"],dflt:"auto",editType:"plot"},insidetextfont:c({},u,{}),outsidetextfont:c({},u,{}),automargin:{valType:"boolean",dflt:!1,editType:"plot"},title:{text:{valType:"string",dflt:"",editType:"plot"},font:c({},u,{}),position:{valType:"enumerated",values:["top left","top center","top right","middle center","bottom left","bottom center","bottom right"],editType:"plot"},editType:"plot"},domain:i({name:"pie",trace:!0,editType:"calc"}),hole:{valType:"number",min:0,max:1,dflt:0,editType:"calc"},sort:{valType:"boolean",dflt:!0,editType:"calc"},direction:{valType:"enumerated",values:["clockwise","counterclockwise"],dflt:"counterclockwise",editType:"calc"},rotation:{valType:"number",min:-360,max:360,dflt:0,editType:"calc"},pull:{valType:"number",min:0,max:1,dflt:0,arrayOk:!0,editType:"calc"},_deprecated:{title:{valType:"string",dflt:"",editType:"calc"},titlefont:c({},u,{}),titleposition:{valType:"enumerated",values:["top left","top center","top right","middle center","bottom left","bottom center","bottom right"],editType:"calc"}}}},{"../../components/color/attributes":365,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/domain":584,"../../plots/font_attributes":585,"../../plots/template_attributes":633}],902:[function(t,e,r){"use strict";var n=t("../../plots/plots");r.name="pie",r.plot=function(t,e,i,a){n.plotBasePlot(r.name,t,e,i,a)},r.clean=function(t,e,i,a){n.cleanBasePlot(r.name,t,e,i,a)}},{"../../plots/plots":619}],903:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("tinycolor2"),a=t("../../components/color"),o={};function s(t){return function(e,r){return!!e&&(!!(e=i(e)).isValid()&&(e=a.addOpacity(e,e.getAlpha()),t[r]||(t[r]=e),e))}}function l(t,e){var r,n=JSON.stringify(t),a=e[n];if(!a){for(a=t.slice(),r=0;r<t.length;r++)a.push(i(t[r]).lighten(20).toHexString());for(r=0;r<t.length;r++)a.push(i(t[r]).darken(20).toHexString());e[n]=a}return a}e.exports={calc:function(t,e){var r,i,a=[],o=t._fullLayout,l=o.hiddenlabels||[],c=e.labels,u=e.marker.colors||[],f=e.values,h=e._length,p=e._hasValues&&h;if(e.dlabel)for(c=new Array(h),r=0;r<h;r++)c[r]=String(e.label0+r*e.dlabel);var d={},m=s(o["_"+e.type+"colormap"]),g=0,v=!1;for(r=0;r<h;r++){var y,x,b;if(p){if(y=f[r],!n(y))continue;y=+y}else y=1;void 0!==(x=c[r])&&""!==x||(x=r);var _=d[x=String(x)];void 0===_?(d[x]=a.length,(b=-1!==l.indexOf(x))||(g+=y),a.push({v:y,label:x,color:m(u[r],x),i:r,pts:[r],hidden:b})):(v=!0,(i=a[_]).v+=y,i.pts.push(r),i.hidden||(g+=y),!1===i.color&&u[r]&&(i.color=m(u[r],x)))}return a=a.filter((function(t){return t.v>=0})),("funnelarea"===e.type?v:e.sort)&&a.sort((function(t,e){return e.v-t.v})),a[0]&&(a[0].vTotal=g),a},crossTraceCalc:function(t,e){var r=(e||{}).type;r||(r="pie");var n=t._fullLayout,i=t.calcdata,a=n[r+"colorway"],s=n["_"+r+"colormap"];n["extend"+r+"colors"]&&(a=l(a,o));for(var c=0,u=0;u<i.length;u++){var f=i[u];if(f[0].trace.type===r)for(var h=0;h<f.length;h++){var p=f[h];!1===p.color&&(s[p.label]?p.color=s[p.label]:(s[p.label]=p.color=a[c%a.length],c++))}}},makePullColorFn:s,generateExtendedColors:l}},{"../../components/color":366,"fast-isnumeric":190,tinycolor2:312}],904:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=t("./attributes"),o=t("../../plots/domain").defaults,s=t("../bar/defaults").handleText;function l(t,e){var r=Array.isArray(t),a=i.isArrayOrTypedArray(e),o=Math.min(r?t.length:1/0,a?e.length:1/0);if(isFinite(o)||(o=0),o&&a){for(var s,l=0;l<o;l++){var c=e[l];if(n(c)&&c>0){s=!0;break}}s||(o=0)}return{hasLabels:r,hasValues:a,len:o}}e.exports={handleLabelsAndValues:l,supplyDefaults:function(t,e,r,n){function c(r,n){return i.coerce(t,e,a,r,n)}var u=l(c("labels"),c("values")),f=u.len;if(e._hasLabels=u.hasLabels,e._hasValues=u.hasValues,!e._hasLabels&&e._hasValues&&(c("label0"),c("dlabel")),f){e._length=f,c("marker.line.width")&&c("marker.line.color"),c("marker.colors"),c("scalegroup");var h,p=c("text"),d=c("texttemplate");if(d||(h=c("textinfo",Array.isArray(p)?"text+percent":"percent")),c("hovertext"),c("hovertemplate"),d||h&&"none"!==h){var m=c("textposition");s(t,e,n,c,m,{moduleHasSelected:!1,moduleHasUnselected:!1,moduleHasConstrain:!1,moduleHasCliponaxis:!1,moduleHasTextangle:!1,moduleHasInsideanchor:!1}),(Array.isArray(m)||"auto"===m||"outside"===m)&&c("automargin"),("inside"===m||"auto"===m||Array.isArray(m))&&c("insidetextorientation")}o(e,n,c);var g=c("hole");if(c("title.text")){var v=c("title.position",g?"middle center":"top center");g||"middle center"!==v||(e.title.position="top center"),i.coerceFont(c,"title.font",n.font)}c("sort"),c("direction"),c("rotation"),c("pull")}else e.visible=!1}}},{"../../lib":503,"../../plots/domain":584,"../bar/defaults":652,"./attributes":901,"fast-isnumeric":190}],905:[function(t,e,r){"use strict";var n=t("../../components/fx/helpers").appendArrayMultiPointValues;e.exports=function(t,e){var r={curveNumber:e.index,pointNumbers:t.pts,data:e._input,fullData:e,label:t.label,color:t.color,value:t.v,percent:t.percent,text:t.text,bbox:t.bbox,v:t.v};return 1===t.pts.length&&(r.pointNumber=r.i=t.pts[0]),n(r,e,t.pts),"funnelarea"===e.type&&(delete r.v,delete r.i),r}},{"../../components/fx/helpers":402}],906:[function(t,e,r){"use strict";var n=t("../../lib");function i(t){return-1!==t.indexOf("e")?t.replace(/[.]?0+e/,"e"):-1!==t.indexOf(".")?t.replace(/[.]?0+$/,""):t}r.formatPiePercent=function(t,e){var r=i((100*t).toPrecision(3));return n.numSeparate(r,e)+"%"},r.formatPieValue=function(t,e){var r=i(t.toPrecision(10));return n.numSeparate(r,e)},r.getFirstFilled=function(t,e){if(Array.isArray(t))for(var r=0;r<e.length;r++){var n=t[e[r]];if(n||0===n||""===n)return n}},r.castOption=function(t,e){return Array.isArray(t)?r.getFirstFilled(t,e):t||void 0},r.getRotationAngle=function(t){return("auto"===t?0:t)*Math.PI/180}},{"../../lib":503}],907:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults").supplyDefaults,supplyLayoutDefaults:t("./layout_defaults"),layoutAttributes:t("./layout_attributes"),calc:t("./calc").calc,crossTraceCalc:t("./calc").crossTraceCalc,plot:t("./plot").plot,style:t("./style"),styleOne:t("./style_one"),moduleType:"trace",name:"pie",basePlotModule:t("./base_plot"),categories:["pie-like","pie","showLegend"],meta:{}}},{"./attributes":901,"./base_plot":902,"./calc":903,"./defaults":904,"./layout_attributes":908,"./layout_defaults":909,"./plot":910,"./style":911,"./style_one":912}],908:[function(t,e,r){"use strict";e.exports={hiddenlabels:{valType:"data_array",editType:"calc"},piecolorway:{valType:"colorlist",editType:"calc"},extendpiecolors:{valType:"boolean",dflt:!0,editType:"calc"}}},{}],909:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./layout_attributes");e.exports=function(t,e){function r(r,a){return n.coerce(t,e,i,r,a)}r("hiddenlabels"),r("piecolorway",e.colorway),r("extendpiecolors")}},{"../../lib":503,"./layout_attributes":908}],910:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../plots/plots"),a=t("../../components/fx"),o=t("../../components/color"),s=t("../../components/drawing"),l=t("../../lib"),c=l.strScale,u=l.strTranslate,f=t("../../lib/svg_text_utils"),h=t("../bar/uniform_text"),p=h.recordMinTextSize,d=h.clearMinTextSize,m=t("../bar/constants").TEXTPAD,g=t("./helpers"),v=t("./event_data"),y=t("../../lib").isValidTextValue;function x(t,e,r){var i=r[0],o=i.cx,s=i.cy,c=i.trace,u="funnelarea"===c.type;"_hasHoverLabel"in c||(c._hasHoverLabel=!1),"_hasHoverEvent"in c||(c._hasHoverEvent=!1),t.on("mouseover",(function(t){var r=e._fullLayout,f=e._fullData[c.index];if(!e._dragging&&!1!==r.hovermode){var h=f.hoverinfo;if(Array.isArray(h)&&(h=a.castHoverinfo({hoverinfo:[g.castOption(h,t.pts)],_module:c._module},r,0)),"all"===h&&(h="label+text+value+percent+name"),f.hovertemplate||"none"!==h&&"skip"!==h&&h){var p=t.rInscribed||0,d=o+t.pxmid[0]*(1-p),m=s+t.pxmid[1]*(1-p),y=r.separators,x=[];if(h&&-1!==h.indexOf("label")&&x.push(t.label),t.text=g.castOption(f.hovertext||f.text,t.pts),h&&-1!==h.indexOf("text")){var b=t.text;l.isValidTextValue(b)&&x.push(b)}t.value=t.v,t.valueLabel=g.formatPieValue(t.v,y),h&&-1!==h.indexOf("value")&&x.push(t.valueLabel),t.percent=t.v/i.vTotal,t.percentLabel=g.formatPiePercent(t.percent,y),h&&-1!==h.indexOf("percent")&&x.push(t.percentLabel);var _=f.hoverlabel,w=_.font,T=[];a.loneHover({trace:c,x0:d-p*i.r,x1:d+p*i.r,y:m,_x0:u?o+t.TL[0]:d-p*i.r,_x1:u?o+t.TR[0]:d+p*i.r,_y0:u?s+t.TL[1]:m-p*i.r,_y1:u?s+t.BL[1]:m+p*i.r,text:x.join("<br>"),name:f.hovertemplate||-1!==h.indexOf("name")?f.name:void 0,idealAlign:t.pxmid[0]<0?"left":"right",color:g.castOption(_.bgcolor,t.pts)||t.color,borderColor:g.castOption(_.bordercolor,t.pts),fontFamily:g.castOption(w.family,t.pts),fontSize:g.castOption(w.size,t.pts),fontColor:g.castOption(w.color,t.pts),nameLength:g.castOption(_.namelength,t.pts),textAlign:g.castOption(_.align,t.pts),hovertemplate:g.castOption(f.hovertemplate,t.pts),hovertemplateLabels:t,eventData:[v(t,f)]},{container:r._hoverlayer.node(),outerContainer:r._paper.node(),gd:e,inOut_bbox:T}),t.bbox=T[0],c._hasHoverLabel=!0}c._hasHoverEvent=!0,e.emit("plotly_hover",{points:[v(t,f)],event:n.event})}})),t.on("mouseout",(function(t){var r=e._fullLayout,i=e._fullData[c.index],o=n.select(this).datum();c._hasHoverEvent&&(t.originalEvent=n.event,e.emit("plotly_unhover",{points:[v(o,i)],event:n.event}),c._hasHoverEvent=!1),c._hasHoverLabel&&(a.loneUnhover(r._hoverlayer.node()),c._hasHoverLabel=!1)})),t.on("click",(function(t){var r=e._fullLayout,i=e._fullData[c.index];e._dragging||!1===r.hovermode||(e._hoverdata=[v(t,i)],a.click(e,n.event))}))}function b(t,e,r){var n=g.castOption(t.insidetextfont.color,e.pts);!n&&t._input.textfont&&(n=g.castOption(t._input.textfont.color,e.pts));var i=g.castOption(t.insidetextfont.family,e.pts)||g.castOption(t.textfont.family,e.pts)||r.family,a=g.castOption(t.insidetextfont.size,e.pts)||g.castOption(t.textfont.size,e.pts)||r.size;return{color:n||o.contrast(e.color),family:i,size:a}}function _(t,e){for(var r,n,i=0;i<t.length;i++)if((n=(r=t[i][0]).trace).title.text){var a=n.title.text;n._meta&&(a=l.templateString(a,n._meta));var o=s.tester.append("text").attr("data-notex",1).text(a).call(s.font,n.title.font).call(f.convertToTspans,e),c=s.bBox(o.node(),!0);r.titleBox={width:c.width,height:c.height},o.remove()}}function w(t,e,r){var n=r.r||e.rpx1,i=e.rInscribed;if(e.startangle===e.stopangle)return{rCenter:1-i,scale:0,rotate:0,textPosAngle:0};var a,o=e.ring,s=1===o&&Math.abs(e.startangle-e.stopangle)===2*Math.PI,l=e.halfangle,c=e.midangle,u=r.trace.insidetextorientation,f="horizontal"===u,h="tangential"===u,p="radial"===u,d="auto"===u,m=[];if(!d){var g,v=function(r,i){if(function(t,e){var r=t.startangle,n=t.stopangle;return r>e&&e>n||r<e&&e<n}(e,r)){var s=Math.abs(r-e.startangle),l=Math.abs(r-e.stopangle),c=s<l?s:l;(a="tan"===i?k(t,n,o,c,0):T(t,n,o,c,Math.PI/2)).textPosAngle=r,m.push(a)}};if(f||h){for(g=4;g>=-4;g-=2)v(Math.PI*g,"tan");for(g=4;g>=-4;g-=2)v(Math.PI*(g+1),"tan")}if(f||p){for(g=4;g>=-4;g-=2)v(Math.PI*(g+1.5),"rad");for(g=4;g>=-4;g-=2)v(Math.PI*(g+.5),"rad")}}if(s||d||f){var y=Math.sqrt(t.width*t.width+t.height*t.height);if((a={scale:i*n*2/y,rCenter:1-i,rotate:0}).textPosAngle=(e.startangle+e.stopangle)/2,a.scale>=1)return a;m.push(a)}(d||p)&&((a=T(t,n,o,l,c)).textPosAngle=(e.startangle+e.stopangle)/2,m.push(a)),(d||h)&&((a=k(t,n,o,l,c)).textPosAngle=(e.startangle+e.stopangle)/2,m.push(a));for(var x=0,b=0,_=0;_<m.length;_++){var w=m[_].scale;if(b<w&&(b=w,x=_),!d&&b>=1)break}return m[x]}function T(t,e,r,n,i){e=Math.max(0,e-2*m);var a=t.width/t.height,o=S(a,n,e,r);return{scale:2*o/t.height,rCenter:A(a,o/e),rotate:M(i)}}function k(t,e,r,n,i){e=Math.max(0,e-2*m);var a=t.height/t.width,o=S(a,n,e,r);return{scale:2*o/t.width,rCenter:A(a,o/e),rotate:M(i+Math.PI/2)}}function A(t,e){return Math.cos(e)-t*e}function M(t){return(180/Math.PI*t+720)%180-90}function S(t,e,r,n){var i=t+1/(2*Math.tan(e));return r*Math.min(1/(Math.sqrt(i*i+.5)+i),n/(Math.sqrt(t*t+n/2)+t))}function E(t,e){return t.v!==e.vTotal||e.trace.hole?Math.min(1/(1+1/Math.sin(t.halfangle)),t.ring/2):1}function L(t,e){var r=e.pxmid[0],n=e.pxmid[1],i=t.width/2,a=t.height/2;return r<0&&(i*=-1),n<0&&(a*=-1),{scale:1,rCenter:1,rotate:0,x:i+Math.abs(a)*(i>0?1:-1)/2,y:a/(1+r*r/(n*n)),outside:!0}}function C(t,e){var r,n,i,a=t.trace,o={x:t.cx,y:t.cy},s={tx:0,ty:0};s.ty+=a.title.font.size,i=I(a),-1!==a.title.position.indexOf("top")?(o.y-=(1+i)*t.r,s.ty-=t.titleBox.height):-1!==a.title.position.indexOf("bottom")&&(o.y+=(1+i)*t.r);var l,c,u=(l=t.r,c=t.trace.aspectratio,l/(void 0===c?1:c)),f=e.w*(a.domain.x[1]-a.domain.x[0])/2;return-1!==a.title.position.indexOf("left")?(f+=u,o.x-=(1+i)*u,s.tx+=t.titleBox.width/2):-1!==a.title.position.indexOf("center")?f*=2:-1!==a.title.position.indexOf("right")&&(f+=u,o.x+=(1+i)*u,s.tx-=t.titleBox.width/2),r=f/t.titleBox.width,n=P(t,e)/t.titleBox.height,{x:o.x,y:o.y,scale:Math.min(r,n),tx:s.tx,ty:s.ty}}function P(t,e){var r=t.trace,n=e.h*(r.domain.y[1]-r.domain.y[0]);return Math.min(t.titleBox.height,n/2)}function I(t){var e,r=t.pull;if(!r)return 0;if(Array.isArray(r))for(r=0,e=0;e<t.pull.length;e++)t.pull[e]>r&&(r=t.pull[e]);return r}function O(t,e){for(var r=[],n=0;n<t.length;n++){var i=t[n][0],a=i.trace,o=a.domain,s=e.w*(o.x[1]-o.x[0]),l=e.h*(o.y[1]-o.y[0]);a.title.text&&"middle center"!==a.title.position&&(l-=P(i,e));var c=s/2,u=l/2;"funnelarea"!==a.type||a.scalegroup||(u/=a.aspectratio),i.r=Math.min(c,u)/(1+I(a)),i.cx=e.l+e.w*(a.domain.x[1]+a.domain.x[0])/2,i.cy=e.t+e.h*(1-a.domain.y[0])-l/2,a.title.text&&-1!==a.title.position.indexOf("bottom")&&(i.cy-=P(i,e)),a.scalegroup&&-1===r.indexOf(a.scalegroup)&&r.push(a.scalegroup)}!function(t,e){for(var r,n,i,a=0;a<e.length;a++){var o=1/0,s=e[a];for(n=0;n<t.length;n++)if(r=t[n][0],(i=r.trace).scalegroup===s){var l;if("pie"===i.type)l=r.r*r.r;else if("funnelarea"===i.type){var c,u;i.aspectratio>1?(c=r.r,u=c/i.aspectratio):(u=r.r,c=u*i.aspectratio),c*=(1+i.baseratio)/2,l=c*u}o=Math.min(o,l/r.vTotal)}for(n=0;n<t.length;n++)if(r=t[n][0],(i=r.trace).scalegroup===s){var f=o*r.vTotal;"funnelarea"===i.type&&(f/=(1+i.baseratio)/2,f/=i.aspectratio),r.r=Math.sqrt(f)}}}(t,r)}function z(t,e){return[t*Math.sin(e),-t*Math.cos(e)]}function D(t,e,r){var n=t._fullLayout,i=r.trace,a=i.texttemplate,o=i.textinfo;if(!a&&o&&"none"!==o){var s,c=o.split("+"),u=function(t){return-1!==c.indexOf(t)},f=u("label"),h=u("text"),p=u("value"),d=u("percent"),m=n.separators;if(s=f?[e.label]:[],h){var v=g.getFirstFilled(i.text,e.pts);y(v)&&s.push(v)}p&&s.push(g.formatPieValue(e.v,m)),d&&s.push(g.formatPiePercent(e.v/r.vTotal,m)),e.text=s.join("<br>")}if(a){var x=l.castOption(i,e.i,"texttemplate");if(x){var b=function(t){return{label:t.label,value:t.v,valueLabel:g.formatPieValue(t.v,n.separators),percent:t.v/r.vTotal,percentLabel:g.formatPiePercent(t.v/r.vTotal,n.separators),color:t.color,text:t.text,customdata:l.castOption(i,t.i,"customdata")}}(e),_=g.getFirstFilled(i.text,e.pts);(y(_)||""===_)&&(b.text=_),e.text=l.texttemplateString(x,b,t._fullLayout._d3locale,b,i._meta||{})}else e.text=""}}function R(t,e){var r=t.rotate*Math.PI/180,n=Math.cos(r),i=Math.sin(r),a=(e.left+e.right)/2,o=(e.top+e.bottom)/2;t.textX=a*n-o*i,t.textY=a*i+o*n,t.noCenter=!0}e.exports={plot:function(t,e){var r=t._fullLayout,a=r._size;d("pie",r),_(e,t),O(e,a);var h=l.makeTraceGroups(r._pielayer,e,"trace").each((function(e){var h=n.select(this),d=e[0],m=d.trace;!function(t){var e,r,n,i=t[0],a=i.r,o=i.trace,s=g.getRotationAngle(o.rotation),l=2*Math.PI/i.vTotal,c="px0",u="px1";if("counterclockwise"===o.direction){for(e=0;e<t.length&&t[e].hidden;e++);if(e===t.length)return;s+=l*t[e].v,l*=-1,c="px1",u="px0"}for(n=z(a,s),e=0;e<t.length;e++)(r=t[e]).hidden||(r[c]=n,r.startangle=s,s+=l*r.v/2,r.pxmid=z(a,s),r.midangle=s,s+=l*r.v/2,n=z(a,s),r.stopangle=s,r[u]=n,r.largeArc=r.v>i.vTotal/2?1:0,r.halfangle=Math.PI*Math.min(r.v/i.vTotal,.5),r.ring=1-o.hole,r.rInscribed=E(r,i))}(e),h.attr("stroke-linejoin","round"),h.each((function(){var v=n.select(this).selectAll("g.slice").data(e);v.enter().append("g").classed("slice",!0),v.exit().remove();var y=[[[],[]],[[],[]]],_=!1;v.each((function(i,a){if(i.hidden)n.select(this).selectAll("path,g").remove();else{i.pointNumber=i.i,i.curveNumber=m.index,y[i.pxmid[1]<0?0:1][i.pxmid[0]<0?0:1].push(i);var o=d.cx,c=d.cy,u=n.select(this),h=u.selectAll("path.surface").data([i]);if(h.enter().append("path").classed("surface",!0).style({"pointer-events":"all"}),u.call(x,t,e),m.pull){var v=+g.castOption(m.pull,i.pts)||0;v>0&&(o+=v*i.pxmid[0],c+=v*i.pxmid[1])}i.cxFinal=o,i.cyFinal=c;var T=m.hole;if(i.v===d.vTotal){var k="M"+(o+i.px0[0])+","+(c+i.px0[1])+C(i.px0,i.pxmid,!0,1)+C(i.pxmid,i.px0,!0,1)+"Z";T?h.attr("d","M"+(o+T*i.px0[0])+","+(c+T*i.px0[1])+C(i.px0,i.pxmid,!1,T)+C(i.pxmid,i.px0,!1,T)+"Z"+k):h.attr("d",k)}else{var A=C(i.px0,i.px1,!0,1);if(T){var M=1-T;h.attr("d","M"+(o+T*i.px1[0])+","+(c+T*i.px1[1])+C(i.px1,i.px0,!1,T)+"l"+M*i.px0[0]+","+M*i.px0[1]+A+"Z")}else h.attr("d","M"+o+","+c+"l"+i.px0[0]+","+i.px0[1]+A+"Z")}D(t,i,d);var S=g.castOption(m.textposition,i.pts),E=u.selectAll("g.slicetext").data(i.text&&"none"!==S?[0]:[]);E.enter().append("g").classed("slicetext",!0),E.exit().remove(),E.each((function(){var u=l.ensureSingle(n.select(this),"text","",(function(t){t.attr("data-notex",1)})),h=l.ensureUniformFontSize(t,"outside"===S?function(t,e,r){var n=g.castOption(t.outsidetextfont.color,e.pts)||g.castOption(t.textfont.color,e.pts)||r.color,i=g.castOption(t.outsidetextfont.family,e.pts)||g.castOption(t.textfont.family,e.pts)||r.family,a=g.castOption(t.outsidetextfont.size,e.pts)||g.castOption(t.textfont.size,e.pts)||r.size;return{color:n,family:i,size:a}}(m,i,r.font):b(m,i,r.font));u.text(i.text).attr({class:"slicetext",transform:"","text-anchor":"middle"}).call(s.font,h).call(f.convertToTspans,t);var v,y=s.bBox(u.node());if("outside"===S)v=L(y,i);else if(v=w(y,i,d),"auto"===S&&v.scale<1){var x=l.ensureUniformFontSize(t,m.outsidetextfont);u.call(s.font,x),v=L(y=s.bBox(u.node()),i)}var T=v.textPosAngle,k=void 0===T?i.pxmid:z(d.r,T);if(v.targetX=o+k[0]*v.rCenter+(v.x||0),v.targetY=c+k[1]*v.rCenter+(v.y||0),R(v,y),v.outside){var A=v.targetY;i.yLabelMin=A-y.height/2,i.yLabelMid=A,i.yLabelMax=A+y.height/2,i.labelExtraX=0,i.labelExtraY=0,_=!0}v.fontSize=h.size,p(m.type,v,r),e[a].transform=v,u.attr("transform",l.getTextTransform(v))}))}function C(t,e,r,n){var a=n*(e[0]-t[0]),o=n*(e[1]-t[1]);return"a"+n*d.r+","+n*d.r+" 0 "+i.largeArc+(r?" 1 ":" 0 ")+a+","+o}}));var T=n.select(this).selectAll("g.titletext").data(m.title.text?[0]:[]);if(T.enter().append("g").classed("titletext",!0),T.exit().remove(),T.each((function(){var e,r=l.ensureSingle(n.select(this),"text","",(function(t){t.attr("data-notex",1)})),i=m.title.text;m._meta&&(i=l.templateString(i,m._meta)),r.text(i).attr({class:"titletext",transform:"","text-anchor":"middle"}).call(s.font,m.title.font).call(f.convertToTspans,t),e="middle center"===m.title.position?function(t){var e=Math.sqrt(t.titleBox.width*t.titleBox.width+t.titleBox.height*t.titleBox.height);return{x:t.cx,y:t.cy,scale:t.trace.hole*t.r*2/e,tx:0,ty:-t.titleBox.height/2+t.trace.title.font.size}}(d):C(d,a),r.attr("transform",u(e.x,e.y)+c(Math.min(1,e.scale))+u(e.tx,e.ty))})),_&&function(t,e){var r,n,i,a,o,s,l,c,u,f,h,p,d;function m(t,e){return t.pxmid[1]-e.pxmid[1]}function v(t,e){return e.pxmid[1]-t.pxmid[1]}function y(t,r){r||(r={});var i,c,u,h,p=r.labelExtraY+(n?r.yLabelMax:r.yLabelMin),d=n?t.yLabelMin:t.yLabelMax,m=n?t.yLabelMax:t.yLabelMin,v=t.cyFinal+o(t.px0[1],t.px1[1]),y=p-d;if(y*l>0&&(t.labelExtraY=y),Array.isArray(e.pull))for(c=0;c<f.length;c++)(u=f[c])===t||(g.castOption(e.pull,t.pts)||0)>=(g.castOption(e.pull,u.pts)||0)||((t.pxmid[1]-u.pxmid[1])*l>0?(y=u.cyFinal+o(u.px0[1],u.px1[1])-d-t.labelExtraY)*l>0&&(t.labelExtraY+=y):(m+t.labelExtraY-v)*l>0&&(i=3*s*Math.abs(c-f.indexOf(t)),(h=u.cxFinal+a(u.px0[0],u.px1[0])+i-(t.cxFinal+t.pxmid[0])-t.labelExtraX)*s>0&&(t.labelExtraX+=h)))}for(n=0;n<2;n++)for(i=n?m:v,o=n?Math.max:Math.min,l=n?1:-1,r=0;r<2;r++){for(a=r?Math.max:Math.min,s=r?1:-1,(c=t[n][r]).sort(i),u=t[1-n][r],f=u.concat(c),p=[],h=0;h<c.length;h++)void 0!==c[h].yLabelMid&&p.push(c[h]);for(d=!1,h=0;n&&h<u.length;h++)if(void 0!==u[h].yLabelMid){d=u[h];break}for(h=0;h<p.length;h++){var x=h&&p[h-1];d&&!h&&(x=d),y(p[h],x)}}}(y,m),function(t,e){t.each((function(t){var r=n.select(this);if(t.labelExtraX||t.labelExtraY){var i=r.select("g.slicetext text");t.transform.targetX+=t.labelExtraX,t.transform.targetY+=t.labelExtraY,i.attr("transform",l.getTextTransform(t.transform));var a=t.cxFinal+t.pxmid[0],s="M"+a+","+(t.cyFinal+t.pxmid[1]),c=(t.yLabelMax-t.yLabelMin)*(t.pxmid[0]<0?-1:1)/4;if(t.labelExtraX){var u=t.labelExtraX*t.pxmid[1]/t.pxmid[0],f=t.yLabelMid+t.labelExtraY-(t.cyFinal+t.pxmid[1]);Math.abs(u)>Math.abs(f)?s+="l"+f*t.pxmid[0]/t.pxmid[1]+","+f+"H"+(a+t.labelExtraX+c):s+="l"+t.labelExtraX+","+u+"v"+(f-u)+"h"+c}else s+="V"+(t.yLabelMid+t.labelExtraY)+"h"+c;l.ensureSingle(r,"path","textline").call(o.stroke,e.outsidetextfont.color).attr({"stroke-width":Math.min(2,e.outsidetextfont.size/8),d:s,fill:"none"})}else r.select("path.textline").remove()}))}(v,m),_&&m.automargin){var k=s.bBox(h.node()),A=m.domain,M=a.w*(A.x[1]-A.x[0]),S=a.h*(A.y[1]-A.y[0]),E=(.5*M-d.r)/a.w,P=(.5*S-d.r)/a.h;i.autoMargin(t,"pie."+m.uid+".automargin",{xl:A.x[0]-E,xr:A.x[1]+E,yb:A.y[0]-P,yt:A.y[1]+P,l:Math.max(d.cx-d.r-k.left,0),r:Math.max(k.right-(d.cx+d.r),0),b:Math.max(k.bottom-(d.cy+d.r),0),t:Math.max(d.cy-d.r-k.top,0),pad:5})}}))}));setTimeout((function(){h.selectAll("tspan").each((function(){var t=n.select(this);t.attr("dy")&&t.attr("dy",t.attr("dy"))}))}),0)},formatSliceLabel:D,transformInsideText:w,determineInsideTextFont:b,positionTitleOutside:C,prerenderTitles:_,layoutAreas:O,attachFxHandlers:x,computeTransform:R}},{"../../components/color":366,"../../components/drawing":388,"../../components/fx":406,"../../lib":503,"../../lib/svg_text_utils":529,"../../plots/plots":619,"../bar/constants":650,"../bar/uniform_text":664,"./event_data":905,"./helpers":906,"@plotly/d3":58}],911:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("./style_one"),a=t("../bar/uniform_text").resizeText;e.exports=function(t){var e=t._fullLayout._pielayer.selectAll(".trace");a(t,e,"pie"),e.each((function(t){var e=t[0].trace,r=n.select(this);r.style({opacity:e.opacity}),r.selectAll("path.surface").each((function(t){n.select(this).call(i,t,e)}))}))}},{"../bar/uniform_text":664,"./style_one":912,"@plotly/d3":58}],912:[function(t,e,r){"use strict";var n=t("../../components/color"),i=t("./helpers").castOption;e.exports=function(t,e,r){var a=r.marker.line,o=i(a.color,e.pts)||n.defaultLine,s=i(a.width,e.pts)||0;t.style("stroke-width",s).call(n.fill,e.color).call(n.stroke,o)}},{"../../components/color":366,"./helpers":906}],913:[function(t,e,r){"use strict";var n=t("../scatter/attributes");e.exports={x:n.x,y:n.y,xy:{valType:"data_array",editType:"calc"},indices:{valType:"data_array",editType:"calc"},xbounds:{valType:"data_array",editType:"calc"},ybounds:{valType:"data_array",editType:"calc"},text:n.text,marker:{color:{valType:"color",arrayOk:!1,editType:"calc"},opacity:{valType:"number",min:0,max:1,dflt:1,arrayOk:!1,editType:"calc"},blend:{valType:"boolean",dflt:null,editType:"calc"},sizemin:{valType:"number",min:.1,max:2,dflt:.5,editType:"calc"},sizemax:{valType:"number",min:.1,dflt:20,editType:"calc"},border:{color:{valType:"color",arrayOk:!1,editType:"calc"},arearatio:{valType:"number",min:0,max:1,dflt:0,editType:"calc"},editType:"calc"},editType:"calc"},transforms:void 0}},{"../scatter/attributes":927}],914:[function(t,e,r){"use strict";var n=t("../../../stackgl_modules").gl_pointcloud2d,i=t("../../lib/str2rgbarray"),a=t("../../plots/cartesian/autorange").findExtremes,o=t("../scatter/get_trace_color");function s(t,e){this.scene=t,this.uid=e,this.type="pointcloud",this.pickXData=[],this.pickYData=[],this.xData=[],this.yData=[],this.textLabels=[],this.color="rgb(0, 0, 0)",this.name="",this.hoverinfo="all",this.idToIndex=new Int32Array(0),this.bounds=[0,0,0,0],this.pointcloudOptions={positions:new Float32Array(0),idToIndex:this.idToIndex,sizemin:.5,sizemax:12,color:[0,0,0,1],areaRatio:1,borderColor:[0,0,0,1]},this.pointcloud=n(t.glplot,this.pointcloudOptions),this.pointcloud._trace=this}var l=s.prototype;l.handlePick=function(t){var e=this.idToIndex[t.pointId];return{trace:this,dataCoord:t.dataCoord,traceCoord:this.pickXYData?[this.pickXYData[2*e],this.pickXYData[2*e+1]]:[this.pickXData[e],this.pickYData[e]],textLabel:Array.isArray(this.textLabels)?this.textLabels[e]:this.textLabels,color:this.color,name:this.name,pointIndex:e,hoverinfo:this.hoverinfo}},l.update=function(t){this.index=t.index,this.textLabels=t.text,this.name=t.name,this.hoverinfo=t.hoverinfo,this.bounds=[1/0,1/0,-1/0,-1/0],this.updateFast(t),this.color=o(t,{})},l.updateFast=function(t){var e,r,n,o,s,l,c=this.xData=this.pickXData=t.x,u=this.yData=this.pickYData=t.y,f=this.pickXYData=t.xy,h=t.xbounds&&t.ybounds,p=t.indices,d=this.bounds;if(f){if(n=f,e=f.length>>>1,h)d[0]=t.xbounds[0],d[2]=t.xbounds[1],d[1]=t.ybounds[0],d[3]=t.ybounds[1];else for(l=0;l<e;l++)o=n[2*l],s=n[2*l+1],o<d[0]&&(d[0]=o),o>d[2]&&(d[2]=o),s<d[1]&&(d[1]=s),s>d[3]&&(d[3]=s);if(p)r=p;else for(r=new Int32Array(e),l=0;l<e;l++)r[l]=l}else for(e=c.length,n=new Float32Array(2*e),r=new Int32Array(e),l=0;l<e;l++)o=c[l],s=u[l],r[l]=l,n[2*l]=o,n[2*l+1]=s,o<d[0]&&(d[0]=o),o>d[2]&&(d[2]=o),s<d[1]&&(d[1]=s),s>d[3]&&(d[3]=s);this.idToIndex=r,this.pointcloudOptions.idToIndex=r,this.pointcloudOptions.positions=n;var m=i(t.marker.color),g=i(t.marker.border.color),v=t.opacity*t.marker.opacity;m[3]*=v,this.pointcloudOptions.color=m;var y=t.marker.blend;if(null===y){y=c.length<100||u.length<100}this.pointcloudOptions.blend=y,g[3]*=v,this.pointcloudOptions.borderColor=g;var x=t.marker.sizemin,b=Math.max(t.marker.sizemax,t.marker.sizemin);this.pointcloudOptions.sizeMin=x,this.pointcloudOptions.sizeMax=b,this.pointcloudOptions.areaRatio=t.marker.border.arearatio,this.pointcloud.update(this.pointcloudOptions);var _=this.scene.xaxis,w=this.scene.yaxis,T=b/2||.5;t._extremes[_._id]=a(_,[d[0],d[2]],{ppad:T}),t._extremes[w._id]=a(w,[d[1],d[3]],{ppad:T})},l.dispose=function(){this.pointcloud.dispose()},e.exports=function(t,e){var r=new s(t,e.uid);return r.update(e),r}},{"../../../stackgl_modules":1124,"../../lib/str2rgbarray":528,"../../plots/cartesian/autorange":553,"../scatter/get_trace_color":937}],915:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./attributes");e.exports=function(t,e,r){function a(r,a){return n.coerce(t,e,i,r,a)}a("x"),a("y"),a("xbounds"),a("ybounds"),t.xy&&t.xy instanceof Float32Array&&(e.xy=t.xy),t.indices&&t.indices instanceof Int32Array&&(e.indices=t.indices),a("text"),a("marker.color",r),a("marker.opacity"),a("marker.blend"),a("marker.sizemin"),a("marker.sizemax"),a("marker.border.color",r),a("marker.border.arearatio"),e._length=null}},{"../../lib":503,"./attributes":913}],916:[function(t,e,r){"use strict";["*pointcloud* trace is deprecated!","Please consider switching to the *scattergl* trace type."].join(" ");e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),calc:t("../scatter3d/calc"),plot:t("./convert"),moduleType:"trace",name:"pointcloud",basePlotModule:t("../../plots/gl2d"),categories:["gl","gl2d","showLegend"],meta:{}}},{"../../plots/gl2d":596,"../scatter3d/calc":956,"./attributes":913,"./convert":914,"./defaults":915}],917:[function(t,e,r){"use strict";var n=t("../../plots/font_attributes"),i=t("../../plots/attributes"),a=t("../../components/color/attributes"),o=t("../../components/fx/attributes"),s=t("../../plots/domain").attributes,l=t("../../plots/template_attributes").hovertemplateAttrs,c=t("../../components/colorscale/attributes"),u=t("../../plot_api/plot_template").templatedArray,f=t("../../plots/cartesian/axis_format_attributes").descriptionOnlyNumbers,h=t("../../lib/extend").extendFlat,p=t("../../plot_api/edit_types").overrideAll;(e.exports=p({hoverinfo:h({},i.hoverinfo,{flags:[],arrayOk:!1}),hoverlabel:o.hoverlabel,domain:s({name:"sankey",trace:!0}),orientation:{valType:"enumerated",values:["v","h"],dflt:"h"},valueformat:{valType:"string",dflt:".3s",description:f("value")},valuesuffix:{valType:"string",dflt:""},arrangement:{valType:"enumerated",values:["snap","perpendicular","freeform","fixed"],dflt:"snap"},textfont:n({}),customdata:void 0,node:{label:{valType:"data_array",dflt:[]},groups:{valType:"info_array",impliedEdits:{x:[],y:[]},dimensions:2,freeLength:!0,dflt:[],items:{valType:"number",editType:"calc"}},x:{valType:"data_array",dflt:[]},y:{valType:"data_array",dflt:[]},color:{valType:"color",arrayOk:!0},customdata:{valType:"data_array",editType:"calc"},line:{color:{valType:"color",dflt:a.defaultLine,arrayOk:!0},width:{valType:"number",min:0,dflt:.5,arrayOk:!0}},pad:{valType:"number",arrayOk:!1,min:0,dflt:20},thickness:{valType:"number",arrayOk:!1,min:1,dflt:20},hoverinfo:{valType:"enumerated",values:["all","none","skip"],dflt:"all"},hoverlabel:o.hoverlabel,hovertemplate:l({},{keys:["value","label"]})},link:{label:{valType:"data_array",dflt:[]},color:{valType:"color",arrayOk:!0},customdata:{valType:"data_array",editType:"calc"},line:{color:{valType:"color",dflt:a.defaultLine,arrayOk:!0},width:{valType:"number",min:0,dflt:0,arrayOk:!0}},source:{valType:"data_array",dflt:[]},target:{valType:"data_array",dflt:[]},value:{valType:"data_array",dflt:[]},hoverinfo:{valType:"enumerated",values:["all","none","skip"],dflt:"all"},hoverlabel:o.hoverlabel,hovertemplate:l({},{keys:["value","label"]}),colorscales:u("concentrationscales",{editType:"calc",label:{valType:"string",editType:"calc",dflt:""},cmax:{valType:"number",editType:"calc",dflt:1},cmin:{valType:"number",editType:"calc",dflt:0},colorscale:h(c().colorscale,{dflt:[[0,"white"],[1,"black"]]})})}},"calc","nested")).transforms=void 0},{"../../components/color/attributes":365,"../../components/colorscale/attributes":373,"../../components/fx/attributes":397,"../../lib/extend":493,"../../plot_api/edit_types":536,"../../plot_api/plot_template":543,"../../plots/attributes":550,"../../plots/cartesian/axis_format_attributes":557,"../../plots/domain":584,"../../plots/font_attributes":585,"../../plots/template_attributes":633}],918:[function(t,e,r){"use strict";var n=t("../../plot_api/edit_types").overrideAll,i=t("../../plots/get_data").getModuleCalcData,a=t("./plot"),o=t("../../components/fx/layout_attributes"),s=t("../../lib/setcursor"),l=t("../../components/dragelement"),c=t("../../plots/cartesian/select").prepSelect,u=t("../../lib"),f=t("../../registry");function h(t,e){var r=t._fullData[e],n=t._fullLayout,i=n.dragmode,a="pan"===n.dragmode?"move":"crosshair",o=r._bgRect;if("pan"!==i&&"zoom"!==i){s(o,a);var h={_id:"x",c2p:u.identity,_offset:r._sankey.translateX,_length:r._sankey.width},p={_id:"y",c2p:u.identity,_offset:r._sankey.translateY,_length:r._sankey.height},d={gd:t,element:o.node(),plotinfo:{id:e,xaxis:h,yaxis:p,fillRangeItems:u.noop},subplot:e,xaxes:[h],yaxes:[p],doneFnCompleted:function(r){var n,i=t._fullData[e],a=i.node.groups.slice(),o=[];function s(t){for(var e=i._sankey.graph.nodes,r=0;r<e.length;r++)if(e[r].pointNumber===t)return e[r]}for(var l=0;l<r.length;l++){var c=s(r[l].pointNumber);if(c)if(c.group){for(var u=0;u<c.childrenNodes.length;u++)o.push(c.childrenNodes[u].pointNumber);a[c.pointNumber-i.node._count]=!1}else o.push(c.pointNumber)}n=a.filter(Boolean).concat([o]),f.call("_guiRestyle",t,{"node.groups":[n]},e)},prepFn:function(t,e,r){c(t,e,r,d,i)}};l.init(d)}}r.name="sankey",r.baseLayoutAttrOverrides=n({hoverlabel:o.hoverlabel},"plot","nested"),r.plot=function(t){var e=i(t.calcdata,"sankey")[0];a(t,e),r.updateFx(t)},r.clean=function(t,e,r,n){var i=n._has&&n._has("sankey"),a=e._has&&e._has("sankey");i&&!a&&(n._paperdiv.selectAll(".sankey").remove(),n._paperdiv.selectAll(".bgsankey").remove())},r.updateFx=function(t){for(var e=0;e<t._fullData.length;e++)h(t,e)}},{"../../components/dragelement":385,"../../components/fx/layout_attributes":407,"../../lib":503,"../../lib/setcursor":524,"../../plot_api/edit_types":536,"../../plots/cartesian/select":575,"../../plots/get_data":593,"../../registry":638,"./plot":923}],919:[function(t,e,r){"use strict";var n=t("strongly-connected-components"),i=t("../../lib"),a=t("../../lib/gup").wrap,o=i.isArrayOrTypedArray,s=i.isIndex,l=t("../../components/colorscale");function c(t){var e,r=t.node,a=t.link,c=[],u=o(a.color),f=o(a.customdata),h={},p={},d=a.colorscales.length;for(e=0;e<d;e++){var m=a.colorscales[e],g=l.extractScale(m,{cLetter:"c"}),v=l.makeColorScaleFunc(g);p[m.label]=v}var y=0;for(e=0;e<a.value.length;e++)a.source[e]>y&&(y=a.source[e]),a.target[e]>y&&(y=a.target[e]);var x,b=y+1;t.node._count=b;var _=t.node.groups,w={};for(e=0;e<_.length;e++){var T=_[e];for(x=0;x<T.length;x++){var k=T[x],A=b+e;w.hasOwnProperty(k)?i.warn("Node "+k+" is already part of a group."):w[k]=A}}var M={source:[],target:[]};for(e=0;e<a.value.length;e++){var S=a.value[e],E=a.source[e],L=a.target[e];if(S>0&&s(E,b)&&s(L,b)&&(!w.hasOwnProperty(E)||!w.hasOwnProperty(L)||w[E]!==w[L])){w.hasOwnProperty(L)&&(L=w[L]),w.hasOwnProperty(E)&&(E=w[E]),L=+L,h[E=+E]=h[L]=!0;var C="";a.label&&a.label[e]&&(C=a.label[e]);var P=null;C&&p.hasOwnProperty(C)&&(P=p[C]),c.push({pointNumber:e,label:C,color:u?a.color[e]:a.color,customdata:f?a.customdata[e]:a.customdata,concentrationscale:P,source:E,target:L,value:+S}),M.source.push(E),M.target.push(L)}}var I=b+_.length,O=o(r.color),z=o(r.customdata),D=[];for(e=0;e<I;e++)if(h[e]){var R=r.label[e];D.push({group:e>b-1,childrenNodes:[],pointNumber:e,label:R,color:O?r.color[e]:r.color,customdata:z?r.customdata[e]:r.customdata})}var F=!1;return function(t,e,r){for(var a=i.init2dArray(t,0),o=0;o<Math.min(e.length,r.length);o++)if(i.isIndex(e[o],t)&&i.isIndex(r[o],t)){if(e[o]===r[o])return!0;a[e[o]].push(r[o])}return n(a).components.some((function(t){return t.length>1}))}(I,M.source,M.target)&&(F=!0),{circular:F,links:c,nodes:D,groups:_,groupLookup:w}}e.exports=function(t,e){var r=c(e);return a({circular:r.circular,_nodes:r.nodes,_links:r.links,_groups:r.groups,_groupLookup:r.groupLookup})}},{"../../components/colorscale":378,"../../lib":503,"../../lib/gup":500,"strongly-connected-components":306}],920:[function(t,e,r){"use strict";e.exports={nodeTextOffsetHorizontal:4,nodeTextOffsetVertical:3,nodePadAcross:10,sankeyIterations:50,forceIterations:5,forceTicksPerFrame:10,duration:500,ease:"linear",cn:{sankey:"sankey",sankeyLinks:"sankey-links",sankeyLink:"sankey-link",sankeyNodeSet:"sankey-node-set",sankeyNode:"sankey-node",nodeRect:"node-rect",nodeLabel:"node-label"}}},{}],921:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./attributes"),a=t("../../components/color"),o=t("tinycolor2"),s=t("../../plots/domain").defaults,l=t("../../components/fx/hoverlabel_defaults"),c=t("../../plot_api/plot_template"),u=t("../../plots/array_container_defaults");function f(t,e){function r(r,a){return n.coerce(t,e,i.link.colorscales,r,a)}r("label"),r("cmin"),r("cmax"),r("colorscale")}e.exports=function(t,e,r,h){function p(r,a){return n.coerce(t,e,i,r,a)}var d=n.extendDeep(h.hoverlabel,t.hoverlabel),m=t.node,g=c.newContainer(e,"node");function v(t,e){return n.coerce(m,g,i.node,t,e)}v("label"),v("groups"),v("x"),v("y"),v("pad"),v("thickness"),v("line.color"),v("line.width"),v("hoverinfo",t.hoverinfo),l(m,g,v,d),v("hovertemplate");var y=h.colorway;v("color",g.label.map((function(t,e){return a.addOpacity(function(t){return y[t%y.length]}(e),.8)}))),v("customdata");var x=t.link||{},b=c.newContainer(e,"link");function _(t,e){return n.coerce(x,b,i.link,t,e)}_("label"),_("source"),_("target"),_("value"),_("line.color"),_("line.width"),_("hoverinfo",t.hoverinfo),l(x,b,_,d),_("hovertemplate");var w,T=o(h.paper_bgcolor).getLuminance()<.333?"rgba(255, 255, 255, 0.6)":"rgba(0, 0, 0, 0.2)";_("color",n.repeat(T,b.value.length)),_("customdata"),u(x,b,{name:"colorscales",handleItemDefaults:f}),s(e,h,p),p("orientation"),p("valueformat"),p("valuesuffix"),g.x.length&&g.y.length&&(w="freeform"),p("arrangement",w),n.coerceFont(p,"textfont",n.extendFlat({},h.font)),e._length=null}},{"../../components/color":366,"../../components/fx/hoverlabel_defaults":404,"../../lib":503,"../../plot_api/plot_template":543,"../../plots/array_container_defaults":549,"../../plots/domain":584,"./attributes":917,tinycolor2:312}],922:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),calc:t("./calc"),plot:t("./plot"),moduleType:"trace",name:"sankey",basePlotModule:t("./base_plot"),selectPoints:t("./select.js"),categories:["noOpacity"],meta:{}}},{"./attributes":917,"./base_plot":918,"./calc":919,"./defaults":921,"./plot":923,"./select.js":925}],923:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=i.numberFormat,o=t("./render"),s=t("../../components/fx"),l=t("../../components/color"),c=t("./constants").cn,u=i._;function f(t){return""!==t}function h(t,e){return t.filter((function(t){return t.key===e.traceId}))}function p(t,e){n.select(t).select("path").style("fill-opacity",e),n.select(t).select("rect").style("fill-opacity",e)}function d(t){n.select(t).select("text.name").style("fill","black")}function m(t){return function(e){return-1!==t.node.sourceLinks.indexOf(e.link)||-1!==t.node.targetLinks.indexOf(e.link)}}function g(t){return function(e){return-1!==e.node.sourceLinks.indexOf(t.link)||-1!==e.node.targetLinks.indexOf(t.link)}}function v(t,e,r){e&&r&&h(r,e).selectAll("."+c.sankeyLink).filter(m(e)).call(x.bind(0,e,r,!1))}function y(t,e,r){e&&r&&h(r,e).selectAll("."+c.sankeyLink).filter(m(e)).call(b.bind(0,e,r,!1))}function x(t,e,r,n){var i=n.datum().link.label;n.style("fill-opacity",(function(t){if(!t.link.concentrationscale)return.4})),i&&h(e,t).selectAll("."+c.sankeyLink).filter((function(t){return t.link.label===i})).style("fill-opacity",(function(t){if(!t.link.concentrationscale)return.4})),r&&h(e,t).selectAll("."+c.sankeyNode).filter(g(t)).call(v)}function b(t,e,r,n){var i=n.datum().link.label;n.style("fill-opacity",(function(t){return t.tinyColorAlpha})),i&&h(e,t).selectAll("."+c.sankeyLink).filter((function(t){return t.link.label===i})).style("fill-opacity",(function(t){return t.tinyColorAlpha})),r&&h(e,t).selectAll(c.sankeyNode).filter(g(t)).call(y)}function _(t,e){var r=t.hoverlabel||{},n=i.nestedProperty(r,e).get();return!Array.isArray(n)&&n}e.exports=function(t,e){for(var r=t._fullLayout,i=r._paper,h=r._size,m=0;m<t._fullData.length;m++)if(t._fullData[m].visible&&t._fullData[m].type===c.sankey&&!t._fullData[m]._viewInitial){var g=t._fullData[m].node;t._fullData[m]._viewInitial={node:{groups:g.groups.slice(),x:g.x.slice(),y:g.y.slice()}}}var w=u(t,"source:")+" ",T=u(t,"target:")+" ",k=u(t,"concentration:")+" ",A=u(t,"incoming flow count:")+" ",M=u(t,"outgoing flow count:")+" ";o(t,i,e,{width:h.w,height:h.h,margin:{t:h.t,r:h.r,b:h.b,l:h.l}},{linkEvents:{hover:function(e,r,i){!1!==t._fullLayout.hovermode&&(n.select(e).call(x.bind(0,r,i,!0)),"skip"!==r.link.trace.link.hoverinfo&&(r.link.fullData=r.link.trace,t.emit("plotly_hover",{event:n.event,points:[r.link]})))},follow:function(e,i){if(!1!==t._fullLayout.hovermode){var o=i.link.trace.link;if("none"!==o.hoverinfo&&"skip"!==o.hoverinfo){for(var c=[],u=0,h=0;h<i.flow.links.length;h++){var m=i.flow.links[h];if("closest"!==t._fullLayout.hovermode||i.link.pointNumber===m.pointNumber){i.link.pointNumber===m.pointNumber&&(u=h),m.fullData=m.trace,o=i.link.trace.link;var g=y(m),v={valueLabel:a(i.valueFormat)(m.value)+i.valueSuffix};c.push({x:g[0],y:g[1],name:v.valueLabel,text:[m.label||"",w+m.source.label,T+m.target.label,m.concentrationscale?k+a("%0.2f")(m.flow.labelConcentration):""].filter(f).join("<br>"),color:_(o,"bgcolor")||l.addOpacity(m.color,1),borderColor:_(o,"bordercolor"),fontFamily:_(o,"font.family"),fontSize:_(o,"font.size"),fontColor:_(o,"font.color"),nameLength:_(o,"namelength"),textAlign:_(o,"align"),idealAlign:n.event.x<g[0]?"right":"left",hovertemplate:o.hovertemplate,hovertemplateLabels:v,eventData:[m]})}}s.loneHover(c,{container:r._hoverlayer.node(),outerContainer:r._paper.node(),gd:t,anchorIndex:u}).each((function(){i.link.concentrationscale||p(this,.65),d(this)}))}}function y(t){var e,r;t.circular?(e=(t.circularPathData.leftInnerExtent+t.circularPathData.rightInnerExtent)/2,r=t.circularPathData.verticalFullExtent):(e=(t.source.x1+t.target.x0)/2,r=(t.y0+t.y1)/2);var n=[e,r];return"v"===t.trace.orientation&&n.reverse(),n[0]+=i.parent.translateX,n[1]+=i.parent.translateY,n}},unhover:function(e,i,a){!1!==t._fullLayout.hovermode&&(n.select(e).call(b.bind(0,i,a,!0)),"skip"!==i.link.trace.link.hoverinfo&&(i.link.fullData=i.link.trace,t.emit("plotly_unhover",{event:n.event,points:[i.link]})),s.loneUnhover(r._hoverlayer.node()))},select:function(e,r){var i=r.link;i.originalEvent=n.event,t._hoverdata=[i],s.click(t,{target:!0})}},nodeEvents:{hover:function(e,r,i){!1!==t._fullLayout.hovermode&&(n.select(e).call(v,r,i),"skip"!==r.node.trace.node.hoverinfo&&(r.node.fullData=r.node.trace,t.emit("plotly_hover",{event:n.event,points:[r.node]})))},follow:function(e,i){if(!1!==t._fullLayout.hovermode){var o=i.node.trace.node;if("none"!==o.hoverinfo&&"skip"!==o.hoverinfo){var l=n.select(e).select("."+c.nodeRect),u=t._fullLayout._paperdiv.node().getBoundingClientRect(),h=l.node().getBoundingClientRect(),m=h.left-2-u.left,g=h.right+2-u.left,v=h.top+h.height/4-u.top,y={valueLabel:a(i.valueFormat)(i.node.value)+i.valueSuffix};i.node.fullData=i.node.trace,t._fullLayout._calcInverseTransform(t);var x=t._fullLayout._invScaleX,b=t._fullLayout._invScaleY,w=s.loneHover({x0:x*m,x1:x*g,y:b*v,name:a(i.valueFormat)(i.node.value)+i.valueSuffix,text:[i.node.label,A+i.node.targetLinks.length,M+i.node.sourceLinks.length].filter(f).join("<br>"),color:_(o,"bgcolor")||i.tinyColorHue,borderColor:_(o,"bordercolor"),fontFamily:_(o,"font.family"),fontSize:_(o,"font.size"),fontColor:_(o,"font.color"),nameLength:_(o,"namelength"),textAlign:_(o,"align"),idealAlign:"left",hovertemplate:o.hovertemplate,hovertemplateLabels:y,eventData:[i.node]},{container:r._hoverlayer.node(),outerContainer:r._paper.node(),gd:t});p(w,.85),d(w)}}},unhover:function(e,i,a){!1!==t._fullLayout.hovermode&&(n.select(e).call(y,i,a),"skip"!==i.node.trace.node.hoverinfo&&(i.node.fullData=i.node.trace,t.emit("plotly_unhover",{event:n.event,points:[i.node]})),s.loneUnhover(r._hoverlayer.node()))},select:function(e,r,i){var a=r.node;a.originalEvent=n.event,t._hoverdata=[a],n.select(e).call(y,r,i),s.click(t,{target:!0})}}})}},{"../../components/color":366,"../../components/fx":406,"../../lib":503,"./constants":920,"./render":924,"@plotly/d3":58}],924:[function(t,e,r){"use strict";var n=t("d3-force"),i=t("d3-interpolate").interpolateNumber,a=t("@plotly/d3"),o=t("@plotly/d3-sankey"),s=t("@plotly/d3-sankey-circular"),l=t("./constants"),c=t("tinycolor2"),u=t("../../components/color"),f=t("../../components/drawing"),h=t("../../lib"),p=h.strTranslate,d=h.strRotate,m=t("../../lib/gup"),g=m.keyFun,v=m.repeat,y=m.unwrap,x=t("../../lib/svg_text_utils"),b=t("../../registry"),_=t("../../constants/alignment"),w=_.CAP_SHIFT,T=_.LINE_SPACING;function k(t,e,r){var n,i=y(e),a=i.trace,u=a.domain,f="h"===a.orientation,p=a.node.pad,d=a.node.thickness,m=t.width*(u.x[1]-u.x[0]),g=t.height*(u.y[1]-u.y[0]),v=i._nodes,x=i._links,b=i.circular;(n=b?s.sankeyCircular().circularLinkGap(0):o.sankey()).iterations(l.sankeyIterations).size(f?[m,g]:[g,m]).nodeWidth(d).nodePadding(p).nodeId((function(t){return t.pointNumber})).nodes(v).links(x);var _,w,T,k=n();for(var A in n.nodePadding()<p&&h.warn("node.pad was reduced to ",n.nodePadding()," to fit within the figure."),i._groupLookup){var M,S=parseInt(i._groupLookup[A]);for(_=0;_<k.nodes.length;_++)if(k.nodes[_].pointNumber===S){M=k.nodes[_];break}if(M){var E={pointNumber:parseInt(A),x0:M.x0,x1:M.x1,y0:M.y0,y1:M.y1,partOfGroup:!0,sourceLinks:[],targetLinks:[]};k.nodes.unshift(E),M.childrenNodes.unshift(E)}}if(function(){for(_=0;_<k.nodes.length;_++){var t,e,r=k.nodes[_],n={};for(w=0;w<r.targetLinks.length;w++)t=(e=r.targetLinks[w]).source.pointNumber+":"+e.target.pointNumber,n.hasOwnProperty(t)||(n[t]=[]),n[t].push(e);var i=Object.keys(n);for(w=0;w<i.length;w++){var a=n[t=i[w]],o=0,s={};for(T=0;T<a.length;T++)s[(e=a[T]).label]||(s[e.label]=0),s[e.label]+=e.value,o+=e.value;for(T=0;T<a.length;T++)(e=a[T]).flow={value:o,labelConcentration:s[e.label]/o,concentration:e.value/o,links:a},e.concentrationscale&&(e.color=c(e.concentrationscale(e.flow.labelConcentration)))}var l=0;for(w=0;w<r.sourceLinks.length;w++)l+=r.sourceLinks[w].value;for(w=0;w<r.sourceLinks.length;w++)(e=r.sourceLinks[w]).concentrationOut=e.value/l;var u=0;for(w=0;w<r.targetLinks.length;w++)u+=r.targetLinks[w].value;for(w=0;w<r.targetLinks.length;w++)(e=r.targetLinks[w]).concenrationIn=e.value/u}}(),a.node.x.length&&a.node.y.length){for(_=0;_<Math.min(a.node.x.length,a.node.y.length,k.nodes.length);_++)if(a.node.x[_]&&a.node.y[_]){var L=[a.node.x[_]*m,a.node.y[_]*g];k.nodes[_].x0=L[0]-d/2,k.nodes[_].x1=L[0]+d/2;var C=k.nodes[_].y1-k.nodes[_].y0;k.nodes[_].y0=L[1]-C/2,k.nodes[_].y1=L[1]+C/2}if("snap"===a.arrangement)!function(t){t.forEach((function(t){var e,r,n,i=0,a=t.length;for(t.sort((function(t,e){return t.y0-e.y0})),n=0;n<a;++n)(e=t[n]).y0>=i||(r=i-e.y0)>1e-6&&(e.y0+=r,e.y1+=r),i=e.y1+p}))}(function(t){var e,r,n=t.map((function(t,e){return{x0:t.x0,index:e}})).sort((function(t,e){return t.x0-e.x0})),i=[],a=-1,o=-1/0;for(_=0;_<n.length;_++){var s=t[n[_].index];s.x0>o+d&&(a+=1,e=s.x0),o=s.x0,i[a]||(i[a]=[]),i[a].push(s),r=e-s.x0,s.x0+=r,s.x1+=r}return i}(v=k.nodes));n.update(k)}return{circular:b,key:r,trace:a,guid:h.randstr(),horizontal:f,width:m,height:g,nodePad:a.node.pad,nodeLineColor:a.node.line.color,nodeLineWidth:a.node.line.width,linkLineColor:a.link.line.color,linkLineWidth:a.link.line.width,valueFormat:a.valueformat,valueSuffix:a.valuesuffix,textFont:a.textfont,translateX:u.x[0]*t.width+t.margin.l,translateY:t.height-u.y[1]*t.height+t.margin.t,dragParallel:f?g:m,dragPerpendicular:f?m:g,arrangement:a.arrangement,sankey:n,graph:k,forceLayouts:{},interactionState:{dragInProgress:!1,hovered:!1}}}function A(t,e,r){var n=c(e.color),i=e.source.label+"|"+e.target.label+"__"+r;return e.trace=t.trace,e.curveNumber=t.trace.index,{circular:t.circular,key:i,traceId:t.key,pointNumber:e.pointNumber,link:e,tinyColorHue:u.tinyRGB(n),tinyColorAlpha:n.getAlpha(),linkPath:M,linkLineColor:t.linkLineColor,linkLineWidth:t.linkLineWidth,valueFormat:t.valueFormat,valueSuffix:t.valueSuffix,sankey:t.sankey,parent:t,interactionState:t.interactionState,flow:e.flow}}function M(){return function(t){if(t.link.circular)return e=t.link,r=e.width/2,n=e.circularPathData,"top"===e.circularLinkType?"M "+n.targetX+" "+(n.targetY+r)+" L"+n.rightInnerExtent+" "+(n.targetY+r)+"A"+(n.rightLargeArcRadius+r)+" "+(n.rightSmallArcRadius+r)+" 0 0 1 "+(n.rightFullExtent-r)+" "+(n.targetY-n.rightSmallArcRadius)+"L"+(n.rightFullExtent-r)+" "+n.verticalRightInnerExtent+"A"+(n.rightLargeArcRadius+r)+" "+(n.rightLargeArcRadius+r)+" 0 0 1 "+n.rightInnerExtent+" "+(n.verticalFullExtent-r)+"L"+n.leftInnerExtent+" "+(n.verticalFullExtent-r)+"A"+(n.leftLargeArcRadius+r)+" "+(n.leftLargeArcRadius+r)+" 0 0 1 "+(n.leftFullExtent+r)+" "+n.verticalLeftInnerExtent+"L"+(n.leftFullExtent+r)+" "+(n.sourceY-n.leftSmallArcRadius)+"A"+(n.leftLargeArcRadius+r)+" "+(n.leftSmallArcRadius+r)+" 0 0 1 "+n.leftInnerExtent+" "+(n.sourceY+r)+"L"+n.sourceX+" "+(n.sourceY+r)+"L"+n.sourceX+" "+(n.sourceY-r)+"L"+n.leftInnerExtent+" "+(n.sourceY-r)+"A"+(n.leftLargeArcRadius-r)+" "+(n.leftSmallArcRadius-r)+" 0 0 0 "+(n.leftFullExtent-r)+" "+(n.sourceY-n.leftSmallArcRadius)+"L"+(n.leftFullExtent-r)+" "+n.verticalLeftInnerExtent+"A"+(n.leftLargeArcRadius-r)+" "+(n.leftLargeArcRadius-r)+" 0 0 0 "+n.leftInnerExtent+" "+(n.verticalFullExtent+r)+"L"+n.rightInnerExtent+" "+(n.verticalFullExtent+r)+"A"+(n.rightLargeArcRadius-r)+" "+(n.rightLargeArcRadius-r)+" 0 0 0 "+(n.rightFullExtent+r)+" "+n.verticalRightInnerExtent+"L"+(n.rightFullExtent+r)+" "+(n.targetY-n.rightSmallArcRadius)+"A"+(n.rightLargeArcRadius-r)+" "+(n.rightSmallArcRadius-r)+" 0 0 0 "+n.rightInnerExtent+" "+(n.targetY-r)+"L"+n.targetX+" "+(n.targetY-r)+"Z":"M "+n.targetX+" "+(n.targetY-r)+" L"+n.rightInnerExtent+" "+(n.targetY-r)+"A"+(n.rightLargeArcRadius+r)+" "+(n.rightSmallArcRadius+r)+" 0 0 0 "+(n.rightFullExtent-r)+" "+(n.targetY+n.rightSmallArcRadius)+"L"+(n.rightFullExtent-r)+" "+n.verticalRightInnerExtent+"A"+(n.rightLargeArcRadius+r)+" "+(n.rightLargeArcRadius+r)+" 0 0 0 "+n.rightInnerExtent+" "+(n.verticalFullExtent+r)+"L"+n.leftInnerExtent+" "+(n.verticalFullExtent+r)+"A"+(n.leftLargeArcRadius+r)+" "+(n.leftLargeArcRadius+r)+" 0 0 0 "+(n.leftFullExtent+r)+" "+n.verticalLeftInnerExtent+"L"+(n.leftFullExtent+r)+" "+(n.sourceY+n.leftSmallArcRadius)+"A"+(n.leftLargeArcRadius+r)+" "+(n.leftSmallArcRadius+r)+" 0 0 0 "+n.leftInnerExtent+" "+(n.sourceY-r)+"L"+n.sourceX+" "+(n.sourceY-r)+"L"+n.sourceX+" "+(n.sourceY+r)+"L"+n.leftInnerExtent+" "+(n.sourceY+r)+"A"+(n.leftLargeArcRadius-r)+" "+(n.leftSmallArcRadius-r)+" 0 0 1 "+(n.leftFullExtent-r)+" "+(n.sourceY+n.leftSmallArcRadius)+"L"+(n.leftFullExtent-r)+" "+n.verticalLeftInnerExtent+"A"+(n.leftLargeArcRadius-r)+" "+(n.leftLargeArcRadius-r)+" 0 0 1 "+n.leftInnerExtent+" "+(n.verticalFullExtent-r)+"L"+n.rightInnerExtent+" "+(n.verticalFullExtent-r)+"A"+(n.rightLargeArcRadius-r)+" "+(n.rightLargeArcRadius-r)+" 0 0 1 "+(n.rightFullExtent+r)+" "+n.verticalRightInnerExtent+"L"+(n.rightFullExtent+r)+" "+(n.targetY+n.rightSmallArcRadius)+"A"+(n.rightLargeArcRadius-r)+" "+(n.rightSmallArcRadius-r)+" 0 0 1 "+n.rightInnerExtent+" "+(n.targetY+r)+"L"+n.targetX+" "+(n.targetY+r)+"Z";var e,r,n,a=t.link.source.x1,o=t.link.target.x0,s=i(a,o),l=s(.5),c=s(.5),u=t.link.y0-t.link.width/2,f=t.link.y0+t.link.width/2,h=t.link.y1-t.link.width/2,p=t.link.y1+t.link.width/2;return"M"+a+","+u+"C"+l+","+u+" "+c+","+h+" "+o+","+h+"L"+o+","+p+"C"+c+","+p+" "+l+","+f+" "+a+","+f+"Z"}}function S(t,e){var r=c(e.color),n=l.nodePadAcross,i=t.nodePad/2;e.dx=e.x1-e.x0,e.dy=e.y1-e.y0;var a=e.dx,o=Math.max(.5,e.dy),s="node_"+e.pointNumber;return e.group&&(s=h.randstr()),e.trace=t.trace,e.curveNumber=t.trace.index,{index:e.pointNumber,key:s,partOfGroup:e.partOfGroup||!1,group:e.group,traceId:t.key,trace:t.trace,node:e,nodePad:t.nodePad,nodeLineColor:t.nodeLineColor,nodeLineWidth:t.nodeLineWidth,textFont:t.textFont,size:t.horizontal?t.height:t.width,visibleWidth:Math.ceil(a),visibleHeight:o,zoneX:-n,zoneY:-i,zoneWidth:a+2*n,zoneHeight:o+2*i,labelY:t.horizontal?e.dy/2+1:e.dx/2+1,left:1===e.originalLayer,sizeAcross:t.width,forceLayouts:t.forceLayouts,horizontal:t.horizontal,darkBackground:r.getBrightness()<=128,tinyColorHue:u.tinyRGB(r),tinyColorAlpha:r.getAlpha(),valueFormat:t.valueFormat,valueSuffix:t.valueSuffix,sankey:t.sankey,graph:t.graph,arrangement:t.arrangement,uniqueNodeLabelPathId:[t.guid,t.key,s].join("_"),interactionState:t.interactionState,figure:t}}function E(t){t.attr("transform",(function(t){return p(t.node.x0.toFixed(3),t.node.y0.toFixed(3))}))}function L(t){t.call(E)}function C(t,e){t.call(L),e.attr("d",M())}function P(t){t.attr("width",(function(t){return t.node.x1-t.node.x0})).attr("height",(function(t){return t.visibleHeight}))}function I(t){return t.link.width>1||t.linkLineWidth>0}function O(t){return p(t.translateX,t.translateY)+(t.horizontal?"matrix(1 0 0 1 0 0)":"matrix(0 1 1 0 0 0)")}function z(t,e,r){t.on(".basic",null).on("mouseover.basic",(function(t){t.interactionState.dragInProgress||t.partOfGroup||(r.hover(this,t,e),t.interactionState.hovered=[this,t])})).on("mousemove.basic",(function(t){t.interactionState.dragInProgress||t.partOfGroup||(r.follow(this,t),t.interactionState.hovered=[this,t])})).on("mouseout.basic",(function(t){t.interactionState.dragInProgress||t.partOfGroup||(r.unhover(this,t,e),t.interactionState.hovered=!1)})).on("click.basic",(function(t){t.interactionState.hovered&&(r.unhover(this,t,e),t.interactionState.hovered=!1),t.interactionState.dragInProgress||t.partOfGroup||r.select(this,t,e)}))}function D(t,e,r,i){var o=a.behavior.drag().origin((function(t){return{x:t.node.x0+t.visibleWidth/2,y:t.node.y0+t.visibleHeight/2}})).on("dragstart",(function(a){if("fixed"!==a.arrangement&&(h.ensureSingle(i._fullLayout._infolayer,"g","dragcover",(function(t){i._fullLayout._dragCover=t})),h.raiseToTop(this),a.interactionState.dragInProgress=a.node,F(a.node),a.interactionState.hovered&&(r.nodeEvents.unhover.apply(0,a.interactionState.hovered),a.interactionState.hovered=!1),"snap"===a.arrangement)){var o=a.traceId+"|"+a.key;a.forceLayouts[o]?a.forceLayouts[o].alpha(1):function(t,e,r,i){!function(t){for(var e=0;e<t.length;e++)t[e].y=(t[e].y0+t[e].y1)/2,t[e].x=(t[e].x0+t[e].x1)/2}(r.graph.nodes);var a=r.graph.nodes.filter((function(t){return t.originalX===r.node.originalX})).filter((function(t){return!t.partOfGroup}));r.forceLayouts[e]=n.forceSimulation(a).alphaDecay(0).force("collide",n.forceCollide().radius((function(t){return t.dy/2+r.nodePad/2})).strength(1).iterations(l.forceIterations)).force("constrain",function(t,e,r,n){return function(){for(var t=0,i=0;i<r.length;i++){var a=r[i];a===n.interactionState.dragInProgress?(a.x=a.lastDraggedX,a.y=a.lastDraggedY):(a.vx=(a.originalX-a.x)/l.forceTicksPerFrame,a.y=Math.min(n.size-a.dy/2,Math.max(a.dy/2,a.y))),t=Math.max(t,Math.abs(a.vx),Math.abs(a.vy))}!n.interactionState.dragInProgress&&t<.1&&n.forceLayouts[e].alpha()>0&&n.forceLayouts[e].alpha(0)}}(0,e,a,r)).stop()}(0,o,a),function(t,e,r,n,i){window.requestAnimationFrame((function a(){var o;for(o=0;o<l.forceTicksPerFrame;o++)r.forceLayouts[n].tick();if(function(t){for(var e=0;e<t.length;e++)t[e].y0=t[e].y-t[e].dy/2,t[e].y1=t[e].y0+t[e].dy,t[e].x0=t[e].x-t[e].dx/2,t[e].x1=t[e].x0+t[e].dx}(r.graph.nodes),r.sankey.update(r.graph),C(t.filter(B(r)),e),r.forceLayouts[n].alpha()>0)window.requestAnimationFrame(a);else{var s=r.node.originalX;r.node.x0=s-r.visibleWidth/2,r.node.x1=s+r.visibleWidth/2,R(r,i)}}))}(t,e,a,o,i)}})).on("drag",(function(r){if("fixed"!==r.arrangement){var n=a.event.x,i=a.event.y;"snap"===r.arrangement?(r.node.x0=n-r.visibleWidth/2,r.node.x1=n+r.visibleWidth/2,r.node.y0=i-r.visibleHeight/2,r.node.y1=i+r.visibleHeight/2):("freeform"===r.arrangement&&(r.node.x0=n-r.visibleWidth/2,r.node.x1=n+r.visibleWidth/2),i=Math.max(0,Math.min(r.size-r.visibleHeight/2,i)),r.node.y0=i-r.visibleHeight/2,r.node.y1=i+r.visibleHeight/2),F(r.node),"snap"!==r.arrangement&&(r.sankey.update(r.graph),C(t.filter(B(r)),e))}})).on("dragend",(function(t){if("fixed"!==t.arrangement){t.interactionState.dragInProgress=!1;for(var e=0;e<t.node.childrenNodes.length;e++)t.node.childrenNodes[e].x=t.node.x,t.node.childrenNodes[e].y=t.node.y;"snap"!==t.arrangement&&R(t,i)}}));t.on(".drag",null).call(o)}function R(t,e){for(var r=[],n=[],i=0;i<t.graph.nodes.length;i++){var a=(t.graph.nodes[i].x0+t.graph.nodes[i].x1)/2,o=(t.graph.nodes[i].y0+t.graph.nodes[i].y1)/2;r.push(a/t.figure.width),n.push(o/t.figure.height)}b.call("_guiRestyle",e,{"node.x":[r],"node.y":[n]},t.trace.index).then((function(){e._fullLayout._dragCover&&e._fullLayout._dragCover.remove()}))}function F(t){t.lastDraggedX=t.x0+t.dx/2,t.lastDraggedY=t.y0+t.dy/2}function B(t){return function(e){return e.node.originalX===t.node.originalX}}e.exports=function(t,e,r,n,i){var o=!1;h.ensureSingle(t._fullLayout._infolayer,"g","first-render",(function(){o=!0}));var s=t._fullLayout._dragCover,m=r.filter((function(t){return y(t).trace.visible})).map(k.bind(null,n)),b=e.selectAll("."+l.cn.sankey).data(m,g);b.exit().remove(),b.enter().append("g").classed(l.cn.sankey,!0).style("box-sizing","content-box").style("position","absolute").style("left",0).style("shape-rendering","geometricPrecision").style("pointer-events","auto").attr("transform",O),b.each((function(e,r){t._fullData[r]._sankey=e;var n="bgsankey-"+e.trace.uid+"-"+r;h.ensureSingle(t._fullLayout._draggers,"rect",n),t._fullData[r]._bgRect=a.select("."+n),t._fullData[r]._bgRect.style("pointer-events","all").attr("width",e.width).attr("height",e.height).attr("x",e.translateX).attr("y",e.translateY).classed("bgsankey",!0).style({fill:"transparent","stroke-width":0})})),b.transition().ease(l.ease).duration(l.duration).attr("transform",O);var _=b.selectAll("."+l.cn.sankeyLinks).data(v,g);_.enter().append("g").classed(l.cn.sankeyLinks,!0).style("fill","none");var L=_.selectAll("."+l.cn.sankeyLink).data((function(t){return t.graph.links.filter((function(t){return t.value})).map(A.bind(null,t))}),g);L.enter().append("path").classed(l.cn.sankeyLink,!0).call(z,b,i.linkEvents),L.style("stroke",(function(t){return I(t)?u.tinyRGB(c(t.linkLineColor)):t.tinyColorHue})).style("stroke-opacity",(function(t){return I(t)?u.opacity(t.linkLineColor):t.tinyColorAlpha})).style("fill",(function(t){return t.tinyColorHue})).style("fill-opacity",(function(t){return t.tinyColorAlpha})).style("stroke-width",(function(t){return I(t)?t.linkLineWidth:1})).attr("d",M()),L.style("opacity",(function(){return t._context.staticPlot||o||s?1:0})).transition().ease(l.ease).duration(l.duration).style("opacity",1),L.exit().transition().ease(l.ease).duration(l.duration).style("opacity",0).remove();var C=b.selectAll("."+l.cn.sankeyNodeSet).data(v,g);C.enter().append("g").classed(l.cn.sankeyNodeSet,!0),C.style("cursor",(function(t){switch(t.arrangement){case"fixed":return"default";case"perpendicular":return"ns-resize";default:return"move"}}));var R=C.selectAll("."+l.cn.sankeyNode).data((function(t){var e=t.graph.nodes;return function(t){var e,r=[];for(e=0;e<t.length;e++)t[e].originalX=(t[e].x0+t[e].x1)/2,t[e].originalY=(t[e].y0+t[e].y1)/2,-1===r.indexOf(t[e].originalX)&&r.push(t[e].originalX);for(r.sort((function(t,e){return t-e})),e=0;e<t.length;e++)t[e].originalLayerIndex=r.indexOf(t[e].originalX),t[e].originalLayer=t[e].originalLayerIndex/(r.length-1)}(e),e.map(S.bind(null,t))}),g);R.enter().append("g").classed(l.cn.sankeyNode,!0).call(E).style("opacity",(function(e){return!t._context.staticPlot&&!o||e.partOfGroup?0:1})),R.call(z,b,i.nodeEvents).call(D,L,i,t),R.transition().ease(l.ease).duration(l.duration).call(E).style("opacity",(function(t){return t.partOfGroup?0:1})),R.exit().transition().ease(l.ease).duration(l.duration).style("opacity",0).remove();var F=R.selectAll("."+l.cn.nodeRect).data(v);F.enter().append("rect").classed(l.cn.nodeRect,!0).call(P),F.style("stroke-width",(function(t){return t.nodeLineWidth})).style("stroke",(function(t){return u.tinyRGB(c(t.nodeLineColor))})).style("stroke-opacity",(function(t){return u.opacity(t.nodeLineColor)})).style("fill",(function(t){return t.tinyColorHue})).style("fill-opacity",(function(t){return t.tinyColorAlpha})),F.transition().ease(l.ease).duration(l.duration).call(P);var B=R.selectAll("."+l.cn.nodeLabel).data(v);B.enter().append("text").classed(l.cn.nodeLabel,!0).style("cursor","default"),B.attr("data-notex",1).text((function(t){return t.node.label})).each((function(e){var r=a.select(this);f.font(r,e.textFont),x.convertToTspans(r,t)})).style("text-shadow",x.makeTextShadow(t._fullLayout.paper_bgcolor)).attr("text-anchor",(function(t){return t.horizontal&&t.left?"end":"start"})).attr("transform",(function(t){var e=a.select(this),r=x.lineCount(e),n=t.textFont.size*((r-1)*T-w),i=t.nodeLineWidth/2+3,o=((t.horizontal?t.visibleHeight:t.visibleWidth)-n)/2;t.horizontal&&(t.left?i=-i:i+=t.visibleWidth);var s=t.horizontal?"":"scale(-1,1)"+d(90);return p(t.horizontal?i:o,t.horizontal?o:i)+s})),B.transition().ease(l.ease).duration(l.duration)}},{"../../components/color":366,"../../components/drawing":388,"../../constants/alignment":471,"../../lib":503,"../../lib/gup":500,"../../lib/svg_text_utils":529,"../../registry":638,"./constants":920,"@plotly/d3":58,"@plotly/d3-sankey":57,"@plotly/d3-sankey-circular":56,"d3-force":111,"d3-interpolate":116,tinycolor2:312}],925:[function(t,e,r){"use strict";e.exports=function(t,e){for(var r=[],n=t.cd[0].trace,i=n._sankey.graph.nodes,a=0;a<i.length;a++){var o=i[a];if(!o.partOfGroup){var s=[(o.x0+o.x1)/2,(o.y0+o.y1)/2];"v"===n.orientation&&s.reverse(),e&&e.contains(s,!1,a,t)&&r.push({pointNumber:o.pointNumber})}}return r}},{}],926:[function(t,e,r){"use strict";var n=t("../../lib");e.exports=function(t,e){for(var r=0;r<t.length;r++)t[r].i=r;n.mergeArray(e.text,t,"tx"),n.mergeArray(e.texttemplate,t,"txt"),n.mergeArray(e.hovertext,t,"htx"),n.mergeArray(e.customdata,t,"data"),n.mergeArray(e.textposition,t,"tp"),e.textfont&&(n.mergeArrayCastPositive(e.textfont.size,t,"ts"),n.mergeArray(e.textfont.color,t,"tc"),n.mergeArray(e.textfont.family,t,"tf"));var i=e.marker;if(i){n.mergeArrayCastPositive(i.size,t,"ms"),n.mergeArrayCastPositive(i.opacity,t,"mo"),n.mergeArray(i.symbol,t,"mx"),n.mergeArray(i.color,t,"mc");var a=i.line;i.line&&(n.mergeArray(a.color,t,"mlc"),n.mergeArrayCastPositive(a.width,t,"mlw"));var o=i.gradient;o&&"none"!==o.type&&(n.mergeArray(o.type,t,"mgt"),n.mergeArray(o.color,t,"mgc"))}}},{"../../lib":503}],927:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,i=t("../../plots/template_attributes").texttemplateAttrs,a=t("../../plots/template_attributes").hovertemplateAttrs,o=t("../../components/colorscale/attributes"),s=t("../../plots/font_attributes"),l=t("../../components/drawing/attributes").dash,c=t("../../components/drawing/attributes").pattern,u=t("../../components/drawing"),f=t("./constants"),h=t("../../lib/extend").extendFlat;e.exports={x:{valType:"data_array",editType:"calc+clearAxisTypes",anim:!0},x0:{valType:"any",dflt:0,editType:"calc+clearAxisTypes",anim:!0},dx:{valType:"number",dflt:1,editType:"calc",anim:!0},y:{valType:"data_array",editType:"calc+clearAxisTypes",anim:!0},y0:{valType:"any",dflt:0,editType:"calc+clearAxisTypes",anim:!0},dy:{valType:"number",dflt:1,editType:"calc",anim:!0},xperiod:{valType:"any",dflt:0,editType:"calc"},yperiod:{valType:"any",dflt:0,editType:"calc"},xperiod0:{valType:"any",editType:"calc"},yperiod0:{valType:"any",editType:"calc"},xperiodalignment:{valType:"enumerated",values:["start","middle","end"],dflt:"middle",editType:"calc"},yperiodalignment:{valType:"enumerated",values:["start","middle","end"],dflt:"middle",editType:"calc"},xhoverformat:n("x"),yhoverformat:n("y"),stackgroup:{valType:"string",dflt:"",editType:"calc"},orientation:{valType:"enumerated",values:["v","h"],editType:"calc"},groupnorm:{valType:"enumerated",values:["","fraction","percent"],dflt:"",editType:"calc"},stackgaps:{valType:"enumerated",values:["infer zero","interpolate"],dflt:"infer zero",editType:"calc"},text:{valType:"string",dflt:"",arrayOk:!0,editType:"calc"},texttemplate:i({},{}),hovertext:{valType:"string",dflt:"",arrayOk:!0,editType:"style"},mode:{valType:"flaglist",flags:["lines","markers","text"],extras:["none"],editType:"calc"},hoveron:{valType:"flaglist",flags:["points","fills"],editType:"style"},hovertemplate:a({},{keys:f.eventDataKeys}),line:{color:{valType:"color",editType:"style",anim:!0},width:{valType:"number",min:0,dflt:2,editType:"style",anim:!0},shape:{valType:"enumerated",values:["linear","spline","hv","vh","hvh","vhv"],dflt:"linear",editType:"plot"},smoothing:{valType:"number",min:0,max:1.3,dflt:1,editType:"plot"},dash:h({},l,{editType:"style"}),simplify:{valType:"boolean",dflt:!0,editType:"plot"},editType:"plot"},connectgaps:{valType:"boolean",dflt:!1,editType:"calc"},cliponaxis:{valType:"boolean",dflt:!0,editType:"plot"},fill:{valType:"enumerated",values:["none","tozeroy","tozerox","tonexty","tonextx","toself","tonext"],editType:"calc"},fillcolor:{valType:"color",editType:"style",anim:!0},fillpattern:c,marker:h({symbol:{valType:"enumerated",values:u.symbolList,dflt:"circle",arrayOk:!0,editType:"style"},opacity:{valType:"number",min:0,max:1,arrayOk:!0,editType:"style",anim:!0},size:{valType:"number",min:0,dflt:6,arrayOk:!0,editType:"calc",anim:!0},maxdisplayed:{valType:"number",min:0,dflt:0,editType:"plot"},sizeref:{valType:"number",dflt:1,editType:"calc"},sizemin:{valType:"number",min:0,dflt:0,editType:"calc"},sizemode:{valType:"enumerated",values:["diameter","area"],dflt:"diameter",editType:"calc"},line:h({width:{valType:"number",min:0,arrayOk:!0,editType:"style",anim:!0},editType:"calc"},o("marker.line",{anim:!0})),gradient:{type:{valType:"enumerated",values:["radial","horizontal","vertical","none"],arrayOk:!0,dflt:"none",editType:"calc"},color:{valType:"color",arrayOk:!0,editType:"calc"},editType:"calc"},editType:"calc"},o("marker",{anim:!0})),selected:{marker:{opacity:{valType:"number",min:0,max:1,editType:"style"},color:{valType:"color",editType:"style"},size:{valType:"number",min:0,editType:"style"},editType:"style"},textfont:{color:{valType:"color",editType:"style"},editType:"style"},editType:"style"},unselected:{marker:{opacity:{valType:"number",min:0,max:1,editType:"style"},color:{valType:"color",editType:"style"},size:{valType:"number",min:0,editType:"style"},editType:"style"},textfont:{color:{valType:"color",editType:"style"},editType:"style"},editType:"style"},textposition:{valType:"enumerated",values:["top left","top center","top right","middle left","middle center","middle right","bottom left","bottom center","bottom right"],dflt:"middle center",arrayOk:!0,editType:"calc"},textfont:s({editType:"calc",colorEditType:"style",arrayOk:!0})}},{"../../components/colorscale/attributes":373,"../../components/drawing":388,"../../components/drawing/attributes":387,"../../lib/extend":493,"../../plots/cartesian/axis_format_attributes":557,"../../plots/font_attributes":585,"../../plots/template_attributes":633,"./constants":931}],928:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=t("../../plots/cartesian/axes"),o=t("../../plots/cartesian/align_period"),s=t("../../constants/numerical").BADNUM,l=t("./subtypes"),c=t("./colorscale_calc"),u=t("./arrays_to_calcdata"),f=t("./calc_selection");function h(t,e,r,n,i,o,s){var c=e._length,u=t._fullLayout,f=r._id,h=n._id,p=u._firstScatter[m(e)]===e.uid,d=(g(e,u,r,n)||{}).orientation,v=e.fill;r._minDtick=0,n._minDtick=0;var y={padded:!0},x={padded:!0};s&&(y.ppad=x.ppad=s);var b=c<2||i[0]!==i[c-1]||o[0]!==o[c-1];b&&("tozerox"===v||"tonextx"===v&&(p||"h"===d))?y.tozero=!0:(e.error_y||{}).visible||"tonexty"!==v&&"tozeroy"!==v&&(l.hasMarkers(e)||l.hasText(e))||(y.padded=!1,y.ppad=0),b&&("tozeroy"===v||"tonexty"===v&&(p||"v"===d))?x.tozero=!0:"tonextx"!==v&&"tozerox"!==v||(x.padded=!1),f&&(e._extremes[f]=a.findExtremes(r,i,y)),h&&(e._extremes[h]=a.findExtremes(n,o,x))}function p(t,e){if(l.hasMarkers(t)){var r,n=t.marker,o=1.6*(t.marker.sizeref||1);if(r="area"===t.marker.sizemode?function(t){return Math.max(Math.sqrt((t||0)/o),3)}:function(t){return Math.max((t||0)/o,3)},i.isArrayOrTypedArray(n.size)){var s={type:"linear"};a.setConvert(s);for(var c=s.makeCalcdata(t.marker,"size"),u=new Array(e),f=0;f<e;f++)u[f]=r(c[f]);return u}return r(n.size)}}function d(t,e){var r=m(e),n=t._firstScatter;n[r]||(n[r]=e.uid)}function m(t){var e=t.stackgroup;return t.xaxis+t.yaxis+t.type+(e?"-"+e:"")}function g(t,e,r,n){var i=t.stackgroup;if(i){var a=e._scatterStackOpts[r._id+n._id][i],o="v"===a.orientation?n:r;return"linear"===o.type||"log"===o.type?a:void 0}}e.exports={calc:function(t,e){var r,l,m,v,y,x,b=t._fullLayout,_=a.getFromId(t,e.xaxis||"x"),w=a.getFromId(t,e.yaxis||"y"),T=_.makeCalcdata(e,"x"),k=w.makeCalcdata(e,"y"),A=o(e,_,"x",T),M=o(e,w,"y",k),S=A.vals,E=M.vals,L=e._length,C=new Array(L),P=e.ids,I=g(e,b,_,w),O=!1;d(b,e);var z,D="x",R="y";I?(i.pushUnique(I.traceIndices,e._expandedIndex),(r="v"===I.orientation)?(R="s",z="x"):(D="s",z="y"),y="interpolate"===I.stackgaps):h(t,e,_,w,S,E,p(e,L));var F=!!e.xperiodalignment,B=!!e.yperiodalignment;for(l=0;l<L;l++){var N=C[l]={},j=n(S[l]),U=n(E[l]);j&&U?(N[D]=S[l],N[R]=E[l],F&&(N.orig_x=T[l],N.xEnd=A.ends[l],N.xStart=A.starts[l]),B&&(N.orig_y=k[l],N.yEnd=M.ends[l],N.yStart=M.starts[l])):I&&(r?j:U)?(N[z]=r?S[l]:E[l],N.gap=!0,y?(N.s=s,O=!0):N.s=0):N[D]=N[R]=s,P&&(N.id=String(P[l]))}if(u(C,e),c(t,e),f(C,e),I){for(l=0;l<C.length;)C[l][z]===s?C.splice(l,1):l++;if(i.sort(C,(function(t,e){return t[z]-e[z]||t.i-e.i})),O){for(l=0;l<C.length-1&&C[l].gap;)l++;for((x=C[l].s)||(x=C[l].s=0),m=0;m<l;m++)C[m].s=x;for(v=C.length-1;v>l&&C[v].gap;)v--;for(x=C[v].s,m=C.length-1;m>v;m--)C[m].s=x;for(;l<v;)if(C[++l].gap){for(m=l+1;C[m].gap;)m++;for(var V=C[l-1][z],H=C[l-1].s,q=(C[m].s-H)/(C[m][z]-V);l<m;)C[l].s=H+(C[l][z]-V)*q,l++}}}return C},calcMarkerSize:p,calcAxisExpansion:h,setFirstScatter:d,getStackOpts:g}},{"../../constants/numerical":479,"../../lib":503,"../../plots/cartesian/align_period":551,"../../plots/cartesian/axes":554,"./arrays_to_calcdata":926,"./calc_selection":929,"./colorscale_calc":930,"./subtypes":952,"fast-isnumeric":190}],929:[function(t,e,r){"use strict";var n=t("../../lib");e.exports=function(t,e){n.isArrayOrTypedArray(e.selectedpoints)&&n.tagSelected(t,e)}},{"../../lib":503}],930:[function(t,e,r){"use strict";var n=t("../../components/colorscale/helpers").hasColorscale,i=t("../../components/colorscale/calc"),a=t("./subtypes");e.exports=function(t,e){a.hasLines(e)&&n(e,"line")&&i(t,e,{vals:e.line.color,containerStr:"line",cLetter:"c"}),a.hasMarkers(e)&&(n(e,"marker")&&i(t,e,{vals:e.marker.color,containerStr:"marker",cLetter:"c"}),n(e,"marker.line")&&i(t,e,{vals:e.marker.line.color,containerStr:"marker.line",cLetter:"c"}))}},{"../../components/colorscale/calc":374,"../../components/colorscale/helpers":377,"./subtypes":952}],931:[function(t,e,r){"use strict";e.exports={PTS_LINESONLY:20,minTolerance:.2,toleranceGrowth:10,maxScreensAway:20,eventDataKeys:[]}},{}],932:[function(t,e,r){"use strict";var n=t("./calc");function i(t,e,r,n,i,a,o){i[n]=!0;var s={i:null,gap:!0,s:0};if(s[o]=r,t.splice(e,0,s),e&&r===t[e-1][o]){var l=t[e-1];s.s=l.s,s.i=l.i,s.gap=l.gap}else a&&(s.s=function(t,e,r,n){var i=t[e-1],a=t[e+1];return a?i?i.s+(a.s-i.s)*(r-i[n])/(a[n]-i[n]):a.s:i.s}(t,e,r,o));e||(t[0].t=t[1].t,t[0].trace=t[1].trace,delete t[1].t,delete t[1].trace)}e.exports=function(t,e){var r=e.xaxis,a=e.yaxis,o=r._id+a._id,s=t._fullLayout._scatterStackOpts[o];if(s){var l,c,u,f,h,p,d,m,g,v,y,x,b,_,w,T=t.calcdata;for(var k in s){var A=(v=s[k]).traceIndices;if(A.length){for(y="interpolate"===v.stackgaps,x=v.groupnorm,"v"===v.orientation?(b="x",_="y"):(b="y",_="x"),w=new Array(A.length),l=0;l<w.length;l++)w[l]=!1;p=T[A[0]];var M=new Array(p.length);for(l=0;l<p.length;l++)M[l]=p[l][b];for(l=1;l<A.length;l++){for(h=T[A[l]],c=u=0;c<h.length;c++){for(d=h[c][b];d>M[u]&&u<M.length;u++)i(h,c,M[u],l,w,y,b),c++;if(d!==M[u]){for(f=0;f<l;f++)i(T[A[f]],u,d,f,w,y,b);M.splice(u,0,d)}u++}for(;u<M.length;u++)i(h,c,M[u],l,w,y,b),c++}var S=M.length;for(c=0;c<p.length;c++){for(m=p[c][_]=p[c].s,l=1;l<A.length;l++)(h=T[A[l]])[0].trace._rawLength=h[0].trace._length,h[0].trace._length=S,m+=h[c].s,h[c][_]=m;if(x)for(g=("fraction"===x?m:m/100)||1,l=0;l<A.length;l++){var E=T[A[l]][c];E[_]/=g,E.sNorm=E.s/g}}for(l=0;l<A.length;l++){var L=(h=T[A[l]])[0].trace,C=n.calcMarkerSize(L,L._rawLength),P=Array.isArray(C);if(C&&w[l]||P){var I=C;for(C=new Array(S),c=0;c<S;c++)C[c]=h[c].gap?0:P?I[h[c].i]:I}var O=new Array(S),z=new Array(S);for(c=0;c<S;c++)O[c]=h[c].x,z[c]=h[c].y;n.calcAxisExpansion(t,L,r,a,O,z,C),h[0].t.orientation=v.orientation}}}}}},{"./calc":928}],933:[function(t,e,r){"use strict";e.exports=function(t){for(var e=0;e<t.length;e++){var r=t[e];if("scatter"===r.type){var n=r.fill;if("none"!==n&&"toself"!==n&&(r.opacity=void 0,"tonexty"===n||"tonextx"===n))for(var i=e-1;i>=0;i--){var a=t[i];if("scatter"===a.type&&a.xaxis===r.xaxis&&a.yaxis===r.yaxis){a.opacity=void 0;break}}}}}},{}],934:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../registry"),a=t("./attributes"),o=t("./constants"),s=t("./subtypes"),l=t("./xy_defaults"),c=t("./period_defaults"),u=t("./stack_defaults"),f=t("./marker_defaults"),h=t("./line_defaults"),p=t("./line_shape_defaults"),d=t("./text_defaults"),m=t("./fillcolor_defaults"),g=t("../../lib").coercePattern;e.exports=function(t,e,r,v){function y(r,i){return n.coerce(t,e,a,r,i)}var x=l(t,e,v,y);if(x||(e.visible=!1),e.visible){c(t,e,v,y),y("xhoverformat"),y("yhoverformat");var b=u(t,e,v,y),_=!b&&x<o.PTS_LINESONLY?"lines+markers":"lines";y("text"),y("hovertext"),y("mode",_),s.hasLines(e)&&(h(t,e,r,v,y),p(t,e,y),y("connectgaps"),y("line.simplify")),s.hasMarkers(e)&&f(t,e,r,v,y,{gradient:!0}),s.hasText(e)&&(y("texttemplate"),d(t,e,v,y));var w=[];(s.hasMarkers(e)||s.hasText(e))&&(y("cliponaxis"),y("marker.maxdisplayed"),w.push("points")),y("fill",b?b.fillDflt:"none"),"none"!==e.fill&&(m(t,e,r,y),s.hasLines(e)||p(t,e,y),g(y,"fillpattern",e.fillcolor,!1));var T=(e.line||{}).color,k=(e.marker||{}).color;"tonext"!==e.fill&&"toself"!==e.fill||w.push("fills"),y("hoveron",w.join("+")||"points"),"fills"!==e.hoveron&&y("hovertemplate");var A=i.getComponentMethod("errorbars","supplyDefaults");A(t,e,T||k||r,{axis:"y"}),A(t,e,T||k||r,{axis:"x",inherit:"y"}),n.coerceSelectionMarkerOpacity(e,y)}}},{"../../lib":503,"../../registry":638,"./attributes":927,"./constants":931,"./fillcolor_defaults":935,"./line_defaults":940,"./line_shape_defaults":942,"./marker_defaults":946,"./period_defaults":947,"./stack_defaults":950,"./subtypes":952,"./text_defaults":953,"./xy_defaults":954}],935:[function(t,e,r){"use strict";var n=t("../../components/color"),i=t("../../lib").isArrayOrTypedArray;e.exports=function(t,e,r,a){var o=!1;if(e.marker){var s=e.marker.color,l=(e.marker.line||{}).color;s&&!i(s)?o=s:l&&!i(l)&&(o=l)}a("fillcolor",n.addOpacity((e.line||{}).color||o||r,.5))}},{"../../components/color":366,"../../lib":503}],936:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes");e.exports=function(t,e,r){var i={},a={_fullLayout:r},o=n.getFromTrace(a,e,"x"),s=n.getFromTrace(a,e,"y");return i.xLabel=n.tickText(o,o.c2l(t.x),!0).text,i.yLabel=n.tickText(s,s.c2l(t.y),!0).text,i}},{"../../plots/cartesian/axes":554}],937:[function(t,e,r){"use strict";var n=t("../../components/color"),i=t("./subtypes");e.exports=function(t,e){var r,a;if("lines"===t.mode)return(r=t.line.color)&&n.opacity(r)?r:t.fillcolor;if("none"===t.mode)return t.fill?t.fillcolor:"";var o=e.mcc||(t.marker||{}).color,s=e.mlcc||((t.marker||{}).line||{}).color;return(a=o&&n.opacity(o)?o:s&&n.opacity(s)&&(e.mlw||((t.marker||{}).line||{}).width)?s:"")?n.opacity(a)<.3?n.addOpacity(a,.3):a:(r=(t.line||{}).color)&&n.opacity(r)&&i.hasLines(t)&&t.line.width?r:t.fillcolor}},{"../../components/color":366,"./subtypes":952}],938:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/fx"),a=t("../../registry"),o=t("./get_trace_color"),s=t("../../components/color"),l=n.fillText;e.exports=function(t,e,r,c){var u=t.cd,f=u[0].trace,h=t.xa,p=t.ya,d=h.c2p(e),m=p.c2p(r),g=[d,m],v=f.hoveron||"",y=-1!==f.mode.indexOf("markers")?3:.5,x=!!f.xperiodalignment,b=!!f.yperiodalignment;if(-1!==v.indexOf("points")){var _=function(t){var e=Math.max(y,t.mrc||0),r=h.c2p(t.x)-d,n=p.c2p(t.y)-m;return Math.max(Math.sqrt(r*r+n*n)-e,1-y/e)},w=i.getDistanceFunction(c,(function(t){if(x){var e=h.c2p(t.xStart),r=h.c2p(t.xEnd);return d>=Math.min(e,r)&&d<=Math.max(e,r)?0:1/0}var n=Math.max(3,t.mrc||0),i=1-1/n,a=Math.abs(h.c2p(t.x)-d);return a<n?i*a/n:a-n+i}),(function(t){if(b){var e=p.c2p(t.yStart),r=p.c2p(t.yEnd);return m>=Math.min(e,r)&&m<=Math.max(e,r)?0:1/0}var n=Math.max(3,t.mrc||0),i=1-1/n,a=Math.abs(p.c2p(t.y)-m);return a<n?i*a/n:a-n+i}),_);if(i.getClosest(u,w,t),!1!==t.index){var T=u[t.index],k=h.c2p(T.x,!0),A=p.c2p(T.y,!0),M=T.mrc||1;t.index=T.i;var S=u[0].t.orientation,E=S&&(T.sNorm||T.s),L="h"===S?E:void 0!==T.orig_x?T.orig_x:T.x,C="v"===S?E:void 0!==T.orig_y?T.orig_y:T.y;return n.extendFlat(t,{color:o(f,T),x0:k-M,x1:k+M,xLabelVal:L,y0:A-M,y1:A+M,yLabelVal:C,spikeDistance:_(T),hovertemplate:f.hovertemplate}),l(T,f,t),a.getComponentMethod("errorbars","hoverInfo")(T,f,t),[t]}}if(-1!==v.indexOf("fills")&&f._polygons){var P,I,O,z,D,R,F,B,N,j=f._polygons,U=[],V=!1,H=1/0,q=-1/0,G=1/0,Y=-1/0;for(P=0;P<j.length;P++)(O=j[P]).contains(g)&&(V=!V,U.push(O),G=Math.min(G,O.ymin),Y=Math.max(Y,O.ymax));if(V){var W=((G=Math.max(G,0))+(Y=Math.min(Y,p._length)))/2;for(P=0;P<U.length;P++)for(z=U[P].pts,I=1;I<z.length;I++)(B=z[I-1][1])>W!=(N=z[I][1])>=W&&(R=z[I-1][0],F=z[I][0],N-B&&(D=R+(F-R)*(W-B)/(N-B),H=Math.min(H,D),q=Math.max(q,D)));H=Math.max(H,0),q=Math.min(q,h._length);var X=s.defaultLine;return s.opacity(f.fillcolor)?X=f.fillcolor:s.opacity((f.line||{}).color)&&(X=f.line.color),n.extendFlat(t,{distance:t.maxHoverDistance,x0:H,x1:q,y0:W,y1:W,color:X,hovertemplate:!1}),delete t.index,f.text&&!Array.isArray(f.text)?t.text=String(f.text):t.text=f.name,[t]}}}},{"../../components/color":366,"../../components/fx":406,"../../lib":503,"../../registry":638,"./get_trace_color":937}],939:[function(t,e,r){"use strict";var n=t("./subtypes");e.exports={hasLines:n.hasLines,hasMarkers:n.hasMarkers,hasText:n.hasText,isBubble:n.isBubble,attributes:t("./attributes"),supplyDefaults:t("./defaults"),crossTraceDefaults:t("./cross_trace_defaults"),calc:t("./calc").calc,crossTraceCalc:t("./cross_trace_calc"),arraysToCalcdata:t("./arrays_to_calcdata"),plot:t("./plot"),colorbar:t("./marker_colorbar"),formatLabels:t("./format_labels"),style:t("./style").style,styleOnSelect:t("./style").styleOnSelect,hoverPoints:t("./hover"),selectPoints:t("./select"),animatable:!0,moduleType:"trace",name:"scatter",basePlotModule:t("../../plots/cartesian"),categories:["cartesian","svg","symbols","errorBarsOK","showLegend","scatter-like","zoomScale"],meta:{}}},{"../../plots/cartesian":568,"./arrays_to_calcdata":926,"./attributes":927,"./calc":928,"./cross_trace_calc":932,"./cross_trace_defaults":933,"./defaults":934,"./format_labels":936,"./hover":938,"./marker_colorbar":945,"./plot":948,"./select":949,"./style":951,"./subtypes":952}],940:[function(t,e,r){"use strict";var n=t("../../lib").isArrayOrTypedArray,i=t("../../components/colorscale/helpers").hasColorscale,a=t("../../components/colorscale/defaults");e.exports=function(t,e,r,o,s,l){var c=(t.marker||{}).color;(s("line.color",r),i(t,"line"))?a(t,e,o,s,{prefix:"line.",cLetter:"c"}):s("line.color",!n(c)&&c||r);s("line.width"),(l||{}).noDash||s("line.dash")}},{"../../components/colorscale/defaults":376,"../../components/colorscale/helpers":377,"../../lib":503}],941:[function(t,e,r){"use strict";var n=t("../../constants/numerical"),i=n.BADNUM,a=n.LOG_CLIP,o=a+.5,s=a-.5,l=t("../../lib"),c=l.segmentsIntersect,u=l.constrain,f=t("./constants");e.exports=function(t,e){var r,n,a,h,p,d,m,g,v,y,x,b,_,w,T,k,A,M,S=e.xaxis,E=e.yaxis,L="log"===S.type,C="log"===E.type,P=S._length,I=E._length,O=e.connectGaps,z=e.baseTolerance,D=e.shape,R="linear"===D,F=e.fill&&"none"!==e.fill,B=[],N=f.minTolerance,j=t.length,U=new Array(j),V=0;function H(r){var n=t[r];if(!n)return!1;var a=e.linearized?S.l2p(n.x):S.c2p(n.x),l=e.linearized?E.l2p(n.y):E.c2p(n.y);if(a===i){if(L&&(a=S.c2p(n.x,!0)),a===i)return!1;C&&l===i&&(a*=Math.abs(S._m*I*(S._m>0?o:s)/(E._m*P*(E._m>0?o:s)))),a*=1e3}if(l===i){if(C&&(l=E.c2p(n.y,!0)),l===i)return!1;l*=1e3}return[a,l]}function q(t,e,r,n){var i=r-t,a=n-e,o=.5-t,s=.5-e,l=i*i+a*a,c=i*o+a*s;if(c>0&&c<l){var u=o*a-s*i;if(u*u<l)return!0}}function G(t,e){var r=t[0]/P,n=t[1]/I,i=Math.max(0,-r,r-1,-n,n-1);return i&&void 0!==A&&q(r,n,A,M)&&(i=0),i&&e&&q(r,n,e[0]/P,e[1]/I)&&(i=0),(1+f.toleranceGrowth*i)*z}function Y(t,e){var r=t[0]-e[0],n=t[1]-e[1];return Math.sqrt(r*r+n*n)}var W,X,Z,J,K,Q,$,tt=f.maxScreensAway,et=-P*tt,rt=P*(1+tt),nt=-I*tt,it=I*(1+tt),at=[[et,nt,rt,nt],[rt,nt,rt,it],[rt,it,et,it],[et,it,et,nt]];function ot(t){if(t[0]<et||t[0]>rt||t[1]<nt||t[1]>it)return[u(t[0],et,rt),u(t[1],nt,it)]}function st(t,e){return t[0]===e[0]&&(t[0]===et||t[0]===rt)||(t[1]===e[1]&&(t[1]===nt||t[1]===it)||void 0)}function lt(t,e,r){return function(n,i){var a=ot(n),o=ot(i),s=[];if(a&&o&&st(a,o))return s;a&&s.push(a),o&&s.push(o);var c=2*l.constrain((n[t]+i[t])/2,e,r)-((a||n)[t]+(o||i)[t]);c&&((a&&o?c>0==a[t]>o[t]?a:o:a||o)[t]+=c);return s}}function ct(t){var e=t[0],r=t[1],n=e===U[V-1][0],i=r===U[V-1][1];if(!n||!i)if(V>1){var a=e===U[V-2][0],o=r===U[V-2][1];n&&(e===et||e===rt)&&a?o?V--:U[V-1]=t:i&&(r===nt||r===it)&&o?a?V--:U[V-1]=t:U[V++]=t}else U[V++]=t}function ut(t){U[V-1][0]!==t[0]&&U[V-1][1]!==t[1]&&ct([Z,J]),ct(t),K=null,Z=J=0}function ft(t){if(A=t[0]/P,M=t[1]/I,W=t[0]<et?et:t[0]>rt?rt:0,X=t[1]<nt?nt:t[1]>it?it:0,W||X){if(V)if(K){var e=$(K,t);e.length>1&&(ut(e[0]),U[V++]=e[1])}else Q=$(U[V-1],t)[0],U[V++]=Q;else U[V++]=[W||t[0],X||t[1]];var r=U[V-1];W&&X&&(r[0]!==W||r[1]!==X)?(K&&(Z!==W&&J!==X?ct(Z&&J?(n=K,a=(i=t)[0]-n[0],o=(i[1]-n[1])/a,(n[1]*i[0]-i[1]*n[0])/a>0?[o>0?et:rt,it]:[o>0?rt:et,nt]):[Z||W,J||X]):Z&&J&&ct([Z,J])),ct([W,X])):Z-W&&J-X&&ct([W||Z,X||J]),K=t,Z=W,J=X}else K&&ut($(K,t)[0]),U[V++]=t;var n,i,a,o}for("linear"===D||"spline"===D?$=function(t,e){for(var r=[],n=0,i=0;i<4;i++){var a=at[i],o=c(t[0],t[1],e[0],e[1],a[0],a[1],a[2],a[3]);o&&(!n||Math.abs(o.x-r[0][0])>1||Math.abs(o.y-r[0][1])>1)&&(o=[o.x,o.y],n&&Y(o,t)<Y(r[0],t)?r.unshift(o):r.push(o),n++)}return r}:"hv"===D||"vh"===D?$=function(t,e){var r=[],n=ot(t),i=ot(e);return n&&i&&st(n,i)||(n&&r.push(n),i&&r.push(i)),r}:"hvh"===D?$=lt(0,et,rt):"vhv"===D&&($=lt(1,nt,it)),r=0;r<j;r++)if(n=H(r)){for(V=0,K=null,ft(n),r++;r<j;r++){if(!(h=H(r))){if(O)continue;break}if(R&&e.simplify){var ht=H(r+1);if(y=Y(h,n),F&&(0===V||V===j-1)||!(y<G(h,ht)*N)){for(g=[(h[0]-n[0])/y,(h[1]-n[1])/y],p=n,x=y,b=w=T=0,m=!1,a=h,r++;r<t.length;r++){if(d=ht,ht=H(r+1),!d){if(O)continue;break}if(k=(v=[d[0]-n[0],d[1]-n[1]])[0]*g[1]-v[1]*g[0],w=Math.min(w,k),(T=Math.max(T,k))-w>G(d,ht))break;a=d,(_=v[0]*g[0]+v[1]*g[1])>x?(x=_,h=d,m=!1):_<b&&(b=_,p=d,m=!0)}if(m?(ft(h),a!==p&&ft(p)):(p!==n&&ft(p),a!==h&&ft(h)),ft(a),r>=t.length||!d)break;ft(d),n=d}}else ft(h)}K&&ct([Z||K[0],J||K[1]]),B.push(U.slice(0,V))}return B}},{"../../constants/numerical":479,"../../lib":503,"./constants":931}],942:[function(t,e,r){"use strict";e.exports=function(t,e,r){"spline"===r("line.shape")&&r("line.smoothing")}},{}],943:[function(t,e,r){"use strict";var n={tonextx:1,tonexty:1,tonext:1};e.exports=function(t,e,r){var i,a,o,s,l,c={},u=!1,f=-1,h=0,p=-1;for(a=0;a<r.length;a++)(o=(i=r[a][0].trace).stackgroup||"")?o in c?l=c[o]:(l=c[o]=h,h++):i.fill in n&&p>=0?l=p:(l=p=h,h++),l<f&&(u=!0),i._groupIndex=f=l;var d=r.slice();u&&d.sort((function(t,e){var r=t[0].trace,n=e[0].trace;return r._groupIndex-n._groupIndex||r.index-n.index}));var m={};for(a=0;a<d.length;a++)o=(i=d[a][0].trace).stackgroup||"",!0===i.visible?(i._nexttrace=null,i.fill in n&&(s=m[o],i._prevtrace=s||null,s&&(s._nexttrace=i)),i._ownfill=i.fill&&("tozero"===i.fill.substr(0,6)||"toself"===i.fill||"to"===i.fill.substr(0,2)&&!i._prevtrace),m[o]=i):i._prevtrace=i._nexttrace=i._ownfill=null;return d}},{}],944:[function(t,e,r){"use strict";var n=t("fast-isnumeric");e.exports=function(t,e){e||(e=2);var r=t.marker,i=r.sizeref||1,a=r.sizemin||0,o="area"===r.sizemode?function(t){return Math.sqrt(t/i)}:function(t){return t/i};return function(t){var r=o(t/e);return n(r)&&r>0?Math.max(r,a):0}}},{"fast-isnumeric":190}],945:[function(t,e,r){"use strict";e.exports={container:"marker",min:"cmin",max:"cmax"}},{}],946:[function(t,e,r){"use strict";var n=t("../../components/color"),i=t("../../components/colorscale/helpers").hasColorscale,a=t("../../components/colorscale/defaults"),o=t("./subtypes");e.exports=function(t,e,r,s,l,c){var u=o.isBubble(t),f=(t.line||{}).color;(c=c||{},f&&(r=f),l("marker.symbol"),l("marker.opacity",u?.7:1),l("marker.size"),l("marker.color",r),i(t,"marker")&&a(t,e,s,l,{prefix:"marker.",cLetter:"c"}),c.noSelect||(l("selected.marker.color"),l("unselected.marker.color"),l("selected.marker.size"),l("unselected.marker.size")),c.noLine||(l("marker.line.color",f&&!Array.isArray(f)&&e.marker.color!==f?f:u?n.background:n.defaultLine),i(t,"marker.line")&&a(t,e,s,l,{prefix:"marker.line.",cLetter:"c"}),l("marker.line.width",u?1:0)),u&&(l("marker.sizeref"),l("marker.sizemin"),l("marker.sizemode")),c.gradient)&&("none"!==l("marker.gradient.type")&&l("marker.gradient.color"))}},{"../../components/color":366,"../../components/colorscale/defaults":376,"../../components/colorscale/helpers":377,"./subtypes":952}],947:[function(t,e,r){"use strict";var n=t("../../lib").dateTick0,i=t("../../constants/numerical").ONEWEEK;function a(t,e){return n(e,t%i==0?1:0)}e.exports=function(t,e,r,n,i){if(i||(i={x:!0,y:!0}),i.x){var o=n("xperiod");o&&(n("xperiod0",a(o,e.xcalendar)),n("xperiodalignment"))}if(i.y){var s=n("yperiod");s&&(n("yperiod0",a(s,e.ycalendar)),n("yperiodalignment"))}}},{"../../constants/numerical":479,"../../lib":503}],948:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../registry"),a=t("../../lib"),o=a.ensureSingle,s=a.identity,l=t("../../components/drawing"),c=t("./subtypes"),u=t("./line_points"),f=t("./link_traces"),h=t("../../lib/polygon").tester;function p(t,e,r,f,p,d,m){var g;!function(t,e,r,i,o){var s=r.xaxis,l=r.yaxis,u=n.extent(a.simpleMap(s.range,s.r2c)),f=n.extent(a.simpleMap(l.range,l.r2c)),h=i[0].trace;if(!c.hasMarkers(h))return;var p=h.marker.maxdisplayed;if(0===p)return;var d=i.filter((function(t){return t.x>=u[0]&&t.x<=u[1]&&t.y>=f[0]&&t.y<=f[1]})),m=Math.ceil(d.length/p),g=0;o.forEach((function(t,r){var n=t[0].trace;c.hasMarkers(n)&&n.marker.maxdisplayed>0&&r<e&&g++}));var v=Math.round(g*m/3+Math.floor(g/3)*m/7.1);i.forEach((function(t){delete t.vis})),d.forEach((function(t,e){0===Math.round((e+v)%m)&&(t.vis=!0)}))}(0,e,r,f,p);var v=!!m&&m.duration>0;function y(t){return v?t.transition():t}var x=r.xaxis,b=r.yaxis,_=f[0].trace,w=_.line,T=n.select(d),k=o(T,"g","errorbars"),A=o(T,"g","lines"),M=o(T,"g","points"),S=o(T,"g","text");if(i.getComponentMethod("errorbars","plot")(t,k,r,m),!0===_.visible){var E,L;y(T).style("opacity",_.opacity);var C=_.fill.charAt(_.fill.length-1);"x"!==C&&"y"!==C&&(C=""),f[0][r.isRangePlot?"nodeRangePlot3":"node3"]=T;var P,I,O="",z=[],D=_._prevtrace;D&&(O=D._prevRevpath||"",L=D._nextFill,z=D._polygons);var R,F,B,N,j,U,V,H="",q="",G=[],Y=a.noop;if(E=_._ownFill,c.hasLines(_)||"none"!==_.fill){for(L&&L.datum(f),-1!==["hv","vh","hvh","vhv"].indexOf(w.shape)?(R=l.steps(w.shape),F=l.steps(w.shape.split("").reverse().join(""))):R=F="spline"===w.shape?function(t){var e=t[t.length-1];return t.length>1&&t[0][0]===e[0]&&t[0][1]===e[1]?l.smoothclosed(t.slice(1),w.smoothing):l.smoothopen(t,w.smoothing)}:function(t){return"M"+t.join("L")},B=function(t){return F(t.reverse())},G=u(f,{xaxis:x,yaxis:b,connectGaps:_.connectgaps,baseTolerance:Math.max(w.width||1,3)/4,shape:w.shape,simplify:w.simplify,fill:_.fill}),V=_._polygons=new Array(G.length),g=0;g<G.length;g++)_._polygons[g]=h(G[g]);G.length&&(N=G[0][0],U=(j=G[G.length-1])[j.length-1]),Y=function(t){return function(e){if(P=R(e),I=B(e),H?C?(H+="L"+P.substr(1),q=I+"L"+q.substr(1)):(H+="Z"+P,q=I+"Z"+q):(H=P,q=I),c.hasLines(_)&&e.length>1){var r=n.select(this);if(r.datum(f),t)y(r.style("opacity",0).attr("d",P).call(l.lineGroupStyle)).style("opacity",1);else{var i=y(r);i.attr("d",P),l.singleLineStyle(f,i)}}}}}var W=A.selectAll(".js-line").data(G);y(W.exit()).style("opacity",0).remove(),W.each(Y(!1)),W.enter().append("path").classed("js-line",!0).style("vector-effect","non-scaling-stroke").call(l.lineGroupStyle).each(Y(!0)),l.setClipUrl(W,r.layerClipId,t),G.length?(E?(E.datum(f),N&&U&&(C?("y"===C?N[1]=U[1]=b.c2p(0,!0):"x"===C&&(N[0]=U[0]=x.c2p(0,!0)),y(E).attr("d","M"+U+"L"+N+"L"+H.substr(1)).call(l.singleFillStyle,t)):y(E).attr("d",H+"Z").call(l.singleFillStyle,t))):L&&("tonext"===_.fill.substr(0,6)&&H&&O?("tonext"===_.fill?y(L).attr("d",H+"Z"+O+"Z").call(l.singleFillStyle,t):y(L).attr("d",H+"L"+O.substr(1)+"Z").call(l.singleFillStyle,t),_._polygons=_._polygons.concat(z)):(Z(L),_._polygons=null)),_._prevRevpath=q,_._prevPolygons=V):(E?Z(E):L&&Z(L),_._polygons=_._prevRevpath=_._prevPolygons=null),M.datum(f),S.datum(f),function(e,i,a){var o,u=a[0].trace,f=c.hasMarkers(u),h=c.hasText(u),p=tt(u),d=et,m=et;if(f||h){var g=s,_=u.stackgroup,w=_&&"infer zero"===t._fullLayout._scatterStackOpts[x._id+b._id][_].stackgaps;u.marker.maxdisplayed||u._needsCull?g=w?K:J:_&&!w&&(g=Q),f&&(d=g),h&&(m=g)}var T,k=(o=e.selectAll("path.point").data(d,p)).enter().append("path").classed("point",!0);v&&k.call(l.pointStyle,u,t).call(l.translatePoints,x,b).style("opacity",0).transition().style("opacity",1),o.order(),f&&(T=l.makePointStyleFns(u)),o.each((function(e){var i=n.select(this),a=y(i);l.translatePoint(e,a,x,b)?(l.singlePointStyle(e,a,u,T,t),r.layerClipId&&l.hideOutsideRangePoint(e,a,x,b,u.xcalendar,u.ycalendar),u.customdata&&i.classed("plotly-customdata",null!==e.data&&void 0!==e.data)):a.remove()})),v?o.exit().transition().style("opacity",0).remove():o.exit().remove(),(o=i.selectAll("g").data(m,p)).enter().append("g").classed("textpoint",!0).append("text"),o.order(),o.each((function(t){var e=n.select(this),i=y(e.select("text"));l.translatePoint(t,i,x,b)?r.layerClipId&&l.hideOutsideRangePoint(t,e,x,b,u.xcalendar,u.ycalendar):e.remove()})),o.selectAll("text").call(l.textPointStyle,u,t).each((function(t){var e=x.c2p(t.x),r=b.c2p(t.y);n.select(this).selectAll("tspan.line").each((function(){y(n.select(this)).attr({x:e,y:r})}))})),o.exit().remove()}(M,S,f);var X=!1===_.cliponaxis?null:r.layerClipId;l.setClipUrl(M,X,t),l.setClipUrl(S,X,t)}function Z(t){y(t).attr("d","M0,0Z")}function J(t){return t.filter((function(t){return!t.gap&&t.vis}))}function K(t){return t.filter((function(t){return t.vis}))}function Q(t){return t.filter((function(t){return!t.gap}))}function $(t){return t.id}function tt(t){if(t.ids)return $}function et(){return!1}}e.exports=function(t,e,r,i,a,c){var u,h,d=!a,m=!!a&&a.duration>0,g=f(t,e,r);((u=i.selectAll("g.trace").data(g,(function(t){return t[0].trace.uid}))).enter().append("g").attr("class",(function(t){return"trace scatter trace"+t[0].trace.uid})).style("stroke-miterlimit",2),u.order(),function(t,e,r){e.each((function(e){var i=o(n.select(this),"g","fills");l.setClipUrl(i,r.layerClipId,t);var a=e[0].trace,c=[];a._ownfill&&c.push("_ownFill"),a._nexttrace&&c.push("_nextFill");var u=i.selectAll("g").data(c,s);u.enter().append("g"),u.exit().each((function(t){a[t]=null})).remove(),u.order().each((function(t){a[t]=o(n.select(this),"path","js-fill")}))}))}(t,u,e),m)?(c&&(h=c()),n.transition().duration(a.duration).ease(a.easing).each("end",(function(){h&&h()})).each("interrupt",(function(){h&&h()})).each((function(){i.selectAll("g.trace").each((function(r,n){p(t,n,e,r,g,this,a)}))}))):u.each((function(r,n){p(t,n,e,r,g,this,a)}));d&&u.exit().remove(),i.selectAll("path:not([d])").remove()}},{"../../components/drawing":388,"../../lib":503,"../../lib/polygon":515,"../../registry":638,"./line_points":941,"./link_traces":943,"./subtypes":952,"@plotly/d3":58}],949:[function(t,e,r){"use strict";var n=t("./subtypes");e.exports=function(t,e){var r,i,a,o,s=t.cd,l=t.xaxis,c=t.yaxis,u=[],f=s[0].trace;if(!n.hasMarkers(f)&&!n.hasText(f))return[];if(!1===e)for(r=0;r<s.length;r++)s[r].selected=0;else for(r=0;r<s.length;r++)i=s[r],a=l.c2p(i.x),o=c.c2p(i.y),null!==i.i&&e.contains([a,o],!1,r,t)?(u.push({pointNumber:i.i,x:l.c2d(i.x),y:c.c2d(i.y)}),i.selected=1):i.selected=0;return u}},{"./subtypes":952}],950:[function(t,e,r){"use strict";var n=["orientation","groupnorm","stackgaps"];e.exports=function(t,e,r,i){var a=r._scatterStackOpts,o=i("stackgroup");if(o){var s=e.xaxis+e.yaxis,l=a[s];l||(l=a[s]={});var c=l[o],u=!1;c?c.traces.push(e):(c=l[o]={traceIndices:[],traces:[e]},u=!0);for(var f={orientation:e.x&&!e.y?"h":"v"},h=0;h<n.length;h++){var p=n[h],d=p+"Found";if(!c[d]){var m=void 0!==t[p],g="orientation"===p;if((m||u)&&(c[p]=i(p,f[p]),g&&(c.fillDflt="h"===c[p]?"tonextx":"tonexty"),m&&(c[d]=!0,!u&&(delete c.traces[0][p],g))))for(var v=0;v<c.traces.length-1;v++){var y=c.traces[v];y._input.fill!==y.fill&&(y.fill=c.fillDflt)}}}return c}}},{}],951:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/drawing"),a=t("../../registry");function o(t,e,r){i.pointStyle(t.selectAll("path.point"),e,r)}function s(t,e,r){i.textPointStyle(t.selectAll("text"),e,r)}e.exports={style:function(t){var e=n.select(t).selectAll("g.trace.scatter");e.style("opacity",(function(t){return t[0].trace.opacity})),e.selectAll("g.points").each((function(e){o(n.select(this),e.trace||e[0].trace,t)})),e.selectAll("g.text").each((function(e){s(n.select(this),e.trace||e[0].trace,t)})),e.selectAll("g.trace path.js-line").call(i.lineGroupStyle),e.selectAll("g.trace path.js-fill").call(i.fillGroupStyle,t),a.getComponentMethod("errorbars","style")(e)},stylePoints:o,styleText:s,styleOnSelect:function(t,e,r){var n=e[0].trace;n.selectedpoints?(i.selectedPointStyle(r.selectAll("path.point"),n),i.selectedTextStyle(r.selectAll("text"),n)):(o(r,n,t),s(r,n,t))}}},{"../../components/drawing":388,"../../registry":638,"@plotly/d3":58}],952:[function(t,e,r){"use strict";var n=t("../../lib");e.exports={hasLines:function(t){return t.visible&&t.mode&&-1!==t.mode.indexOf("lines")},hasMarkers:function(t){return t.visible&&(t.mode&&-1!==t.mode.indexOf("markers")||"splom"===t.type)},hasText:function(t){return t.visible&&t.mode&&-1!==t.mode.indexOf("text")},isBubble:function(t){return n.isPlainObject(t.marker)&&n.isArrayOrTypedArray(t.marker.size)}}},{"../../lib":503}],953:[function(t,e,r){"use strict";var n=t("../../lib");e.exports=function(t,e,r,i,a){a=a||{},i("textposition"),n.coerceFont(i,"textfont",r.font),a.noSelect||(i("selected.textfont.color"),i("unselected.textfont.color"))}},{"../../lib":503}],954:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../registry");e.exports=function(t,e,r,a){var o,s=a("x"),l=a("y");if(i.getComponentMethod("calendars","handleTraceDefaults")(t,e,["x","y"],r),s){var c=n.minRowLength(s);l?o=Math.min(c,n.minRowLength(l)):(o=c,a("y0"),a("dy"))}else{if(!l)return 0;o=n.minRowLength(l),a("x0"),a("dx")}return e._length=o,o}},{"../../lib":503,"../../registry":638}],955:[function(t,e,r){"use strict";var n=t("../scatter/attributes"),i=t("../../components/colorscale/attributes"),a=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,o=t("../../plots/template_attributes").hovertemplateAttrs,s=t("../../plots/template_attributes").texttemplateAttrs,l=t("../../plots/attributes"),c=t("../../constants/gl3d_dashes"),u=t("../../constants/gl3d_markers"),f=t("../../lib/extend").extendFlat,h=t("../../plot_api/edit_types").overrideAll,p=t("../../lib/sort_object_keys"),d=n.line,m=n.marker,g=m.line,v=f({width:d.width,dash:{valType:"enumerated",values:p(c),dflt:"solid"}},i("line"));var y=e.exports=h({x:n.x,y:n.y,z:{valType:"data_array"},text:f({},n.text,{}),texttemplate:s({},{}),hovertext:f({},n.hovertext,{}),hovertemplate:o(),xhoverformat:a("x"),yhoverformat:a("y"),zhoverformat:a("z"),mode:f({},n.mode,{dflt:"lines+markers"}),surfaceaxis:{valType:"enumerated",values:[-1,0,1,2],dflt:-1},surfacecolor:{valType:"color"},projection:{x:{show:{valType:"boolean",dflt:!1},opacity:{valType:"number",min:0,max:1,dflt:1},scale:{valType:"number",min:0,max:10,dflt:2/3}},y:{show:{valType:"boolean",dflt:!1},opacity:{valType:"number",min:0,max:1,dflt:1},scale:{valType:"number",min:0,max:10,dflt:2/3}},z:{show:{valType:"boolean",dflt:!1},opacity:{valType:"number",min:0,max:1,dflt:1},scale:{valType:"number",min:0,max:10,dflt:2/3}}},connectgaps:n.connectgaps,line:v,marker:f({symbol:{valType:"enumerated",values:p(u),dflt:"circle",arrayOk:!0},size:f({},m.size,{dflt:8}),sizeref:m.sizeref,sizemin:m.sizemin,sizemode:m.sizemode,opacity:f({},m.opacity,{arrayOk:!1}),colorbar:m.colorbar,line:f({width:f({},g.width,{arrayOk:!1})},i("marker.line"))},i("marker")),textposition:f({},n.textposition,{dflt:"top center"}),textfont:{color:n.textfont.color,size:n.textfont.size,family:f({},n.textfont.family,{arrayOk:!1})},opacity:l.opacity,hoverinfo:f({},l.hoverinfo)},"calc","nested");y.x.editType=y.y.editType=y.z.editType="calc+clearAxisTypes"},{"../../components/colorscale/attributes":373,"../../constants/gl3d_dashes":476,"../../constants/gl3d_markers":477,"../../lib/extend":493,"../../lib/sort_object_keys":526,"../../plot_api/edit_types":536,"../../plots/attributes":550,"../../plots/cartesian/axis_format_attributes":557,"../../plots/template_attributes":633,"../scatter/attributes":927}],956:[function(t,e,r){"use strict";var n=t("../scatter/arrays_to_calcdata"),i=t("../scatter/colorscale_calc");e.exports=function(t,e){var r=[{x:!1,y:!1,trace:e,t:{}}];return n(r,e),i(t,e),r}},{"../scatter/arrays_to_calcdata":926,"../scatter/colorscale_calc":930}],957:[function(t,e,r){"use strict";var n=t("../../registry");function i(t,e,r,i){if(!e||!e.visible)return null;for(var a=n.getComponentMethod("errorbars","makeComputeError")(e),o=new Array(t.length),s=0;s<t.length;s++){var l=a(+t[s],s);if("log"===i.type){var c=i.c2l(t[s]),u=t[s]-l[0],f=t[s]+l[1];if(o[s]=[(i.c2l(u,!0)-c)*r,(i.c2l(f,!0)-c)*r],u>0){var h=i.c2l(u);i._lowerLogErrorBound||(i._lowerLogErrorBound=h),i._lowerErrorBound=Math.min(i._lowerLogErrorBound,h)}}else o[s]=[-l[0]*r,l[1]*r]}return o}e.exports=function(t,e,r){var n=[i(t.x,t.error_x,e[0],r.xaxis),i(t.y,t.error_y,e[1],r.yaxis),i(t.z,t.error_z,e[2],r.zaxis)],a=function(t){for(var e=0;e<t.length;e++)if(t[e])return t[e].length;return 0}(n);if(0===a)return null;for(var o=new Array(a),s=0;s<a;s++){for(var l=[[0,0,0],[0,0,0]],c=0;c<3;c++)if(n[c])for(var u=0;u<2;u++)l[u][c]=n[c][s][u];o[s]=l}return o}},{"../../registry":638}],958:[function(t,e,r){"use strict";var n=t("../../../stackgl_modules").gl_line3d,i=t("../../../stackgl_modules").gl_scatter3d,a=t("../../../stackgl_modules").gl_error3d,o=t("../../../stackgl_modules").gl_mesh3d,s=t("../../../stackgl_modules").delaunay_triangulate,l=t("../../lib"),c=t("../../lib/str2rgbarray"),u=t("../../lib/gl_format_color").formatColor,f=t("../scatter/make_bubble_size_func"),h=t("../../constants/gl3d_dashes"),p=t("../../constants/gl3d_markers"),d=t("../../plots/cartesian/axes"),m=t("../../components/fx/helpers").appendArrayPointValue,g=t("./calc_errors");function v(t,e){this.scene=t,this.uid=e,this.linePlot=null,this.scatterPlot=null,this.errorBars=null,this.textMarkers=null,this.delaunayMesh=null,this.color=null,this.mode="",this.dataPoints=[],this.axesBounds=[[-1/0,-1/0,-1/0],[1/0,1/0,1/0]],this.textLabels=null,this.data=null}var y=v.prototype;function x(t){return null==t?0:t.indexOf("left")>-1?-1:t.indexOf("right")>-1?1:0}function b(t){return null==t?0:t.indexOf("top")>-1?-1:t.indexOf("bottom")>-1?1:0}function _(t,e){return e(4*t)}function w(t){return p[t]}function T(t,e,r,n,i){var a=null;if(l.isArrayOrTypedArray(t)){a=[];for(var o=0;o<e;o++)void 0===t[o]?a[o]=n:a[o]=r(t[o],i)}else a=r(t,l.identity);return a}function k(t,e){var r,n,i,a,o,s,h=[],p=t.fullSceneLayout,v=t.dataScale,y=p.xaxis,k=p.yaxis,A=p.zaxis,M=e.marker,S=e.line,E=e.x||[],L=e.y||[],C=e.z||[],P=E.length,I=e.xcalendar,O=e.ycalendar,z=e.zcalendar;for(o=0;o<P;o++)r=y.d2l(E[o],0,I)*v[0],n=k.d2l(L[o],0,O)*v[1],i=A.d2l(C[o],0,z)*v[2],h[o]=[r,n,i];if(Array.isArray(e.text))s=e.text;else if(void 0!==e.text)for(s=new Array(P),o=0;o<P;o++)s[o]=e.text;function D(t,e){var r=p[t];return d.tickText(r,r.d2l(e),!0).text}var R=e.texttemplate;if(R){var F=t.fullLayout._d3locale,B=Array.isArray(R),N=B?Math.min(R.length,P):P,j=B?function(t){return R[t]}:function(){return R};for(s=new Array(N),o=0;o<N;o++){var U={x:E[o],y:L[o],z:C[o]},V={xLabel:D("xaxis",E[o]),yLabel:D("yaxis",L[o]),zLabel:D("zaxis",C[o])},H={};m(H,e,o);var q=e._meta||{};s[o]=l.texttemplateString(j(o),V,F,H,U,q)}}if(a={position:h,mode:e.mode,text:s},"line"in e&&(a.lineColor=u(S,1,P),a.lineWidth=S.width,a.lineDashes=S.dash),"marker"in e){var G=f(e);a.scatterColor=u(M,1,P),a.scatterSize=T(M.size,P,_,20,G),a.scatterMarker=T(M.symbol,P,w,"\u25cf"),a.scatterLineWidth=M.line.width,a.scatterLineColor=u(M.line,1,P),a.scatterAngle=0}"textposition"in e&&(a.textOffset=function(t){var e=[0,0];if(Array.isArray(t))for(var r=0;r<t.length;r++)e[r]=[0,0],t[r]&&(e[r][0]=x(t[r]),e[r][1]=b(t[r]));else e[0]=x(t),e[1]=b(t);return e}(e.textposition),a.textColor=u(e.textfont,1,P),a.textSize=T(e.textfont.size,P,l.identity,12),a.textFont=e.textfont.family,a.textAngle=0);var Y=["x","y","z"];for(a.project=[!1,!1,!1],a.projectScale=[1,1,1],a.projectOpacity=[1,1,1],o=0;o<3;++o){var W=e.projection[Y[o]];(a.project[o]=W.show)&&(a.projectOpacity[o]=W.opacity,a.projectScale[o]=W.scale)}a.errorBounds=g(e,v,p);var X=function(t){for(var e=[0,0,0],r=[[0,0,0],[0,0,0],[0,0,0]],n=[1,1,1],i=0;i<3;i++){var a=t[i];a&&!1!==a.copy_zstyle&&!1!==t[2].visible&&(a=t[2]),a&&a.visible&&(e[i]=a.width/2,r[i]=c(a.color),n[i]=a.thickness)}return{capSize:e,color:r,lineWidth:n}}([e.error_x,e.error_y,e.error_z]);return a.errorColor=X.color,a.errorLineWidth=X.lineWidth,a.errorCapSize=X.capSize,a.delaunayAxis=e.surfaceaxis,a.delaunayColor=c(e.surfacecolor),a}function A(t){if(l.isArrayOrTypedArray(t)){var e=t[0];return l.isArrayOrTypedArray(e)&&(t=e),"rgb("+t.slice(0,3).map((function(t){return Math.round(255*t)}))+")"}return null}function M(t){return l.isArrayOrTypedArray(t)?4===t.length&&"number"==typeof t[0]?A(t):t.map(A):null}y.handlePick=function(t){if(t.object&&(t.object===this.linePlot||t.object===this.delaunayMesh||t.object===this.textMarkers||t.object===this.scatterPlot)){var e=t.index=t.data.index;return t.object.highlight&&t.object.highlight(null),this.scatterPlot&&(t.object=this.scatterPlot,this.scatterPlot.highlight(t.data)),t.textLabel="",this.textLabels&&(Array.isArray(this.textLabels)?(this.textLabels[e]||0===this.textLabels[e])&&(t.textLabel=this.textLabels[e]):t.textLabel=this.textLabels),t.traceCoordinate=[this.data.x[e],this.data.y[e],this.data.z[e]],!0}},y.update=function(t){var e,r,l,c,u=this.scene.glplot.gl,f=h.solid;this.data=t;var p=k(this.scene,t);"mode"in p&&(this.mode=p.mode),"lineDashes"in p&&p.lineDashes in h&&(f=h[p.lineDashes]),this.color=M(p.scatterColor)||M(p.lineColor),this.dataPoints=p.position,e={gl:this.scene.glplot.gl,position:p.position,color:p.lineColor,lineWidth:p.lineWidth||1,dashes:f[0],dashScale:f[1],opacity:t.opacity,connectGaps:t.connectgaps},-1!==this.mode.indexOf("lines")?this.linePlot?this.linePlot.update(e):(this.linePlot=n(e),this.linePlot._trace=this,this.scene.glplot.add(this.linePlot)):this.linePlot&&(this.scene.glplot.remove(this.linePlot),this.linePlot.dispose(),this.linePlot=null);var d=t.opacity;if(t.marker&&t.marker.opacity&&(d*=t.marker.opacity),r={gl:this.scene.glplot.gl,position:p.position,color:p.scatterColor,size:p.scatterSize,glyph:p.scatterMarker,opacity:d,orthographic:!0,lineWidth:p.scatterLineWidth,lineColor:p.scatterLineColor,project:p.project,projectScale:p.projectScale,projectOpacity:p.projectOpacity},-1!==this.mode.indexOf("markers")?this.scatterPlot?this.scatterPlot.update(r):(this.scatterPlot=i(r),this.scatterPlot._trace=this,this.scatterPlot.highlightScale=1,this.scene.glplot.add(this.scatterPlot)):this.scatterPlot&&(this.scene.glplot.remove(this.scatterPlot),this.scatterPlot.dispose(),this.scatterPlot=null),c={gl:this.scene.glplot.gl,position:p.position,glyph:p.text,color:p.textColor,size:p.textSize,angle:p.textAngle,alignment:p.textOffset,font:p.textFont,orthographic:!0,lineWidth:0,project:!1,opacity:t.opacity},this.textLabels=t.hovertext||t.text,-1!==this.mode.indexOf("text")?this.textMarkers?this.textMarkers.update(c):(this.textMarkers=i(c),this.textMarkers._trace=this,this.textMarkers.highlightScale=1,this.scene.glplot.add(this.textMarkers)):this.textMarkers&&(this.scene.glplot.remove(this.textMarkers),this.textMarkers.dispose(),this.textMarkers=null),l={gl:this.scene.glplot.gl,position:p.position,color:p.errorColor,error:p.errorBounds,lineWidth:p.errorLineWidth,capSize:p.errorCapSize,opacity:t.opacity},this.errorBars?p.errorBounds?this.errorBars.update(l):(this.scene.glplot.remove(this.errorBars),this.errorBars.dispose(),this.errorBars=null):p.errorBounds&&(this.errorBars=a(l),this.errorBars._trace=this,this.scene.glplot.add(this.errorBars)),p.delaunayAxis>=0){var m=function(t,e,r){var n,i=(r+1)%3,a=(r+2)%3,o=[],l=[];for(n=0;n<t.length;++n){var c=t[n];!isNaN(c[i])&&isFinite(c[i])&&!isNaN(c[a])&&isFinite(c[a])&&(o.push([c[i],c[a]]),l.push(n))}var u=s(o);for(n=0;n<u.length;++n)for(var f=u[n],h=0;h<f.length;++h)f[h]=l[f[h]];return{positions:t,cells:u,meshColor:e}}(p.position,p.delaunayColor,p.delaunayAxis);m.opacity=t.opacity,this.delaunayMesh?this.delaunayMesh.update(m):(m.gl=u,this.delaunayMesh=o(m),this.delaunayMesh._trace=this,this.scene.glplot.add(this.delaunayMesh))}else this.delaunayMesh&&(this.scene.glplot.remove(this.delaunayMesh),this.delaunayMesh.dispose(),this.delaunayMesh=null)},y.dispose=function(){this.linePlot&&(this.scene.glplot.remove(this.linePlot),this.linePlot.dispose()),this.scatterPlot&&(this.scene.glplot.remove(this.scatterPlot),this.scatterPlot.dispose()),this.errorBars&&(this.scene.glplot.remove(this.errorBars),this.errorBars.dispose()),this.textMarkers&&(this.scene.glplot.remove(this.textMarkers),this.textMarkers.dispose()),this.delaunayMesh&&(this.scene.glplot.remove(this.delaunayMesh),this.delaunayMesh.dispose())},e.exports=function(t,e){var r=new v(t,e.uid);return r.update(e),r}},{"../../../stackgl_modules":1124,"../../components/fx/helpers":402,"../../constants/gl3d_dashes":476,"../../constants/gl3d_markers":477,"../../lib":503,"../../lib/gl_format_color":499,"../../lib/str2rgbarray":528,"../../plots/cartesian/axes":554,"../scatter/make_bubble_size_func":944,"./calc_errors":957}],959:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib"),a=t("../scatter/subtypes"),o=t("../scatter/marker_defaults"),s=t("../scatter/line_defaults"),l=t("../scatter/text_defaults"),c=t("./attributes");e.exports=function(t,e,r,u){function f(r,n){return i.coerce(t,e,c,r,n)}if(function(t,e,r,i){var a=0,o=r("x"),s=r("y"),l=r("z");n.getComponentMethod("calendars","handleTraceDefaults")(t,e,["x","y","z"],i),o&&s&&l&&(a=Math.min(o.length,s.length,l.length),e._length=e._xlength=e._ylength=e._zlength=a);return a}(t,e,f,u)){f("text"),f("hovertext"),f("hovertemplate"),f("xhoverformat"),f("yhoverformat"),f("zhoverformat"),f("mode"),a.hasLines(e)&&(f("connectgaps"),s(t,e,r,u,f)),a.hasMarkers(e)&&o(t,e,r,u,f,{noSelect:!0}),a.hasText(e)&&(f("texttemplate"),l(t,e,u,f,{noSelect:!0}));var h=(e.line||{}).color,p=(e.marker||{}).color;f("surfaceaxis")>=0&&f("surfacecolor",h||p);for(var d=["x","y","z"],m=0;m<3;++m){var g="projection."+d[m];f(g+".show")&&(f(g+".opacity"),f(g+".scale"))}var v=n.getComponentMethod("errorbars","supplyDefaults");v(t,e,h||p||r,{axis:"z"}),v(t,e,h||p||r,{axis:"y",inherit:"z"}),v(t,e,h||p||r,{axis:"x",inherit:"z"})}else e.visible=!1}},{"../../lib":503,"../../registry":638,"../scatter/line_defaults":940,"../scatter/marker_defaults":946,"../scatter/subtypes":952,"../scatter/text_defaults":953,"./attributes":955}],960:[function(t,e,r){"use strict";e.exports={plot:t("./convert"),attributes:t("./attributes"),markerSymbols:t("../../constants/gl3d_markers"),supplyDefaults:t("./defaults"),colorbar:[{container:"marker",min:"cmin",max:"cmax"},{container:"line",min:"cmin",max:"cmax"}],calc:t("./calc"),moduleType:"trace",name:"scatter3d",basePlotModule:t("../../plots/gl3d"),categories:["gl3d","symbols","showLegend","scatter-like"],meta:{}}},{"../../constants/gl3d_markers":477,"../../plots/gl3d":598,"./attributes":955,"./calc":956,"./convert":958,"./defaults":959}],961:[function(t,e,r){"use strict";var n=t("../scatter/attributes"),i=t("../../plots/attributes"),a=t("../../plots/template_attributes").hovertemplateAttrs,o=t("../../plots/template_attributes").texttemplateAttrs,s=t("../../components/colorscale/attributes"),l=t("../../lib/extend").extendFlat,c=n.marker,u=n.line,f=c.line;e.exports={carpet:{valType:"string",editType:"calc"},a:{valType:"data_array",editType:"calc"},b:{valType:"data_array",editType:"calc"},mode:l({},n.mode,{dflt:"markers"}),text:l({},n.text,{}),texttemplate:o({editType:"plot"},{keys:["a","b","text"]}),hovertext:l({},n.hovertext,{}),line:{color:u.color,width:u.width,dash:u.dash,shape:l({},u.shape,{values:["linear","spline"]}),smoothing:u.smoothing,editType:"calc"},connectgaps:n.connectgaps,fill:l({},n.fill,{values:["none","toself","tonext"],dflt:"none"}),fillcolor:n.fillcolor,marker:l({symbol:c.symbol,opacity:c.opacity,maxdisplayed:c.maxdisplayed,size:c.size,sizeref:c.sizeref,sizemin:c.sizemin,sizemode:c.sizemode,line:l({width:f.width,editType:"calc"},s("marker.line")),gradient:c.gradient,editType:"calc"},s("marker")),textfont:n.textfont,textposition:n.textposition,selected:n.selected,unselected:n.unselected,hoverinfo:l({},i.hoverinfo,{flags:["a","b","text","name"]}),hoveron:n.hoveron,hovertemplate:a()}},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/template_attributes":633,"../scatter/attributes":927}],962:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../scatter/colorscale_calc"),a=t("../scatter/arrays_to_calcdata"),o=t("../scatter/calc_selection"),s=t("../scatter/calc").calcMarkerSize,l=t("../carpet/lookup_carpetid");e.exports=function(t,e){var r=e._carpetTrace=l(t,e);if(r&&r.visible&&"legendonly"!==r.visible){var c;e.xaxis=r.xaxis,e.yaxis=r.yaxis;var u,f,h=e._length,p=new Array(h),d=!1;for(c=0;c<h;c++)if(u=e.a[c],f=e.b[c],n(u)&&n(f)){var m=r.ab2xy(+u,+f,!0),g=r.isVisible(+u,+f);g||(d=!0),p[c]={x:m[0],y:m[1],a:u,b:f,vis:g}}else p[c]={x:!1,y:!1};return e._needsCull=d,p[0].carpet=r,p[0].trace=e,s(e,h),i(t,e),a(p,e),o(p,e),p}}},{"../carpet/lookup_carpetid":708,"../scatter/arrays_to_calcdata":926,"../scatter/calc":928,"../scatter/calc_selection":929,"../scatter/colorscale_calc":930,"fast-isnumeric":190}],963:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../scatter/constants"),a=t("../scatter/subtypes"),o=t("../scatter/marker_defaults"),s=t("../scatter/line_defaults"),l=t("../scatter/line_shape_defaults"),c=t("../scatter/text_defaults"),u=t("../scatter/fillcolor_defaults"),f=t("./attributes");e.exports=function(t,e,r,h){function p(r,i){return n.coerce(t,e,f,r,i)}p("carpet"),e.xaxis="x",e.yaxis="y";var d=p("a"),m=p("b"),g=Math.min(d.length,m.length);if(g){e._length=g,p("text"),p("texttemplate"),p("hovertext"),p("mode",g<i.PTS_LINESONLY?"lines+markers":"lines"),a.hasLines(e)&&(s(t,e,r,h,p),l(t,e,p),p("connectgaps")),a.hasMarkers(e)&&o(t,e,r,h,p,{gradient:!0}),a.hasText(e)&&c(t,e,h,p);var v=[];(a.hasMarkers(e)||a.hasText(e))&&(p("marker.maxdisplayed"),v.push("points")),p("fill"),"none"!==e.fill&&(u(t,e,r,p),a.hasLines(e)||l(t,e,p)),"tonext"!==e.fill&&"toself"!==e.fill||v.push("fills"),"fills"!==p("hoveron",v.join("+")||"points")&&p("hovertemplate"),n.coerceSelectionMarkerOpacity(e,p)}else e.visible=!1}},{"../../lib":503,"../scatter/constants":931,"../scatter/fillcolor_defaults":935,"../scatter/line_defaults":940,"../scatter/line_shape_defaults":942,"../scatter/marker_defaults":946,"../scatter/subtypes":952,"../scatter/text_defaults":953,"./attributes":961}],964:[function(t,e,r){"use strict";e.exports=function(t,e,r,n,i){var a=n[i];return t.a=a.a,t.b=a.b,t.y=a.y,t}},{}],965:[function(t,e,r){"use strict";e.exports=function(t,e){var r={},n=e._carpet,i=n.ab2ij([t.a,t.b]),a=Math.floor(i[0]),o=i[0]-a,s=Math.floor(i[1]),l=i[1]-s,c=n.evalxy([],a,s,o,l);return r.yLabel=c[1].toFixed(3),r}},{}],966:[function(t,e,r){"use strict";var n=t("../scatter/hover"),i=t("../../lib").fillText;e.exports=function(t,e,r,a){var o=n(t,e,r,a);if(o&&!1!==o[0].index){var s=o[0];if(void 0===s.index){var l=1-s.y0/t.ya._length,c=t.xa._length,u=c*l/2,f=c-u;return s.x0=Math.max(Math.min(s.x0,f),u),s.x1=Math.max(Math.min(s.x1,f),u),o}var h=s.cd[s.index];s.a=h.a,s.b=h.b,s.xLabelVal=void 0,s.yLabelVal=void 0;var p=s.trace,d=p._carpet,m=p._module.formatLabels(h,p);s.yLabel=m.yLabel,delete s.text;var g=[];if(!p.hovertemplate){var v=(h.hi||p.hoverinfo).split("+");-1!==v.indexOf("all")&&(v=["a","b","text"]),-1!==v.indexOf("a")&&y(d.aaxis,h.a),-1!==v.indexOf("b")&&y(d.baxis,h.b),g.push("y: "+s.yLabel),-1!==v.indexOf("text")&&i(h,p,g),s.extraText=g.join("<br>")}return o}function y(t,e){var r;r=t.labelprefix&&t.labelprefix.length>0?t.labelprefix.replace(/ = $/,""):t._hovertitle,g.push(r+": "+e.toFixed(3)+t.labelsuffix)}}},{"../../lib":503,"../scatter/hover":938}],967:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:t("../scatter/marker_colorbar"),formatLabels:t("./format_labels"),calc:t("./calc"),plot:t("./plot"),style:t("../scatter/style").style,styleOnSelect:t("../scatter/style").styleOnSelect,hoverPoints:t("./hover"),selectPoints:t("../scatter/select"),eventData:t("./event_data"),moduleType:"trace",name:"scattercarpet",basePlotModule:t("../../plots/cartesian"),categories:["svg","carpet","symbols","showLegend","carpetDependent","zoomScale"],meta:{}}},{"../../plots/cartesian":568,"../scatter/marker_colorbar":945,"../scatter/select":949,"../scatter/style":951,"./attributes":961,"./calc":962,"./defaults":963,"./event_data":964,"./format_labels":965,"./hover":966,"./plot":968}],968:[function(t,e,r){"use strict";var n=t("../scatter/plot"),i=t("../../plots/cartesian/axes"),a=t("../../components/drawing");e.exports=function(t,e,r,o){var s,l,c,u=r[0][0].carpet,f={xaxis:i.getFromId(t,u.xaxis||"x"),yaxis:i.getFromId(t,u.yaxis||"y"),plot:e.plot};for(n(t,f,r,o),s=0;s<r.length;s++)l=r[s][0].trace,c=o.selectAll("g.trace"+l.uid+" .js-line"),a.setClipUrl(c,r[s][0].carpet._clipPathId,t)}},{"../../components/drawing":388,"../../plots/cartesian/axes":554,"../scatter/plot":948}],969:[function(t,e,r){"use strict";var n=t("../../plots/template_attributes").hovertemplateAttrs,i=t("../../plots/template_attributes").texttemplateAttrs,a=t("../scatter/attributes"),o=t("../../plots/attributes"),s=t("../../components/colorscale/attributes"),l=t("../../components/drawing/attributes").dash,c=t("../../lib/extend").extendFlat,u=t("../../plot_api/edit_types").overrideAll,f=a.marker,h=a.line,p=f.line;e.exports=u({lon:{valType:"data_array"},lat:{valType:"data_array"},locations:{valType:"data_array"},locationmode:{valType:"enumerated",values:["ISO-3","USA-states","country names","geojson-id"],dflt:"ISO-3"},geojson:{valType:"any",editType:"calc"},featureidkey:{valType:"string",editType:"calc",dflt:"id"},mode:c({},a.mode,{dflt:"markers"}),text:c({},a.text,{}),texttemplate:i({editType:"plot"},{keys:["lat","lon","location","text"]}),hovertext:c({},a.hovertext,{}),textfont:a.textfont,textposition:a.textposition,line:{color:h.color,width:h.width,dash:l},connectgaps:a.connectgaps,marker:c({symbol:f.symbol,opacity:f.opacity,size:f.size,sizeref:f.sizeref,sizemin:f.sizemin,sizemode:f.sizemode,colorbar:f.colorbar,line:c({width:p.width},s("marker.line")),gradient:f.gradient},s("marker")),fill:{valType:"enumerated",values:["none","toself"],dflt:"none"},fillcolor:a.fillcolor,selected:a.selected,unselected:a.unselected,hoverinfo:c({},o.hoverinfo,{flags:["lon","lat","location","text","name"]}),hovertemplate:n()},"calc","nested")},{"../../components/colorscale/attributes":373,"../../components/drawing/attributes":387,"../../lib/extend":493,"../../plot_api/edit_types":536,"../../plots/attributes":550,"../../plots/template_attributes":633,"../scatter/attributes":927}],970:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../constants/numerical").BADNUM,a=t("../scatter/colorscale_calc"),o=t("../scatter/arrays_to_calcdata"),s=t("../scatter/calc_selection"),l=t("../../lib")._;function c(t){return t&&"string"==typeof t}e.exports=function(t,e){var r,u=Array.isArray(e.locations),f=u?e.locations.length:e._length,h=new Array(f);r=e.geojson?function(t){return c(t)||n(t)}:c;for(var p=0;p<f;p++){var d=h[p]={};if(u){var m=e.locations[p];d.loc=r(m)?m:null}else{var g=e.lon[p],v=e.lat[p];n(g)&&n(v)?d.lonlat=[+g,+v]:d.lonlat=[i,i]}}return o(h,e),a(t,e),s(h,e),f&&(h[0].t={labels:{lat:l(t,"lat:")+" ",lon:l(t,"lon:")+" "}}),h}},{"../../constants/numerical":479,"../../lib":503,"../scatter/arrays_to_calcdata":926,"../scatter/calc_selection":929,"../scatter/colorscale_calc":930,"fast-isnumeric":190}],971:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../scatter/subtypes"),a=t("../scatter/marker_defaults"),o=t("../scatter/line_defaults"),s=t("../scatter/text_defaults"),l=t("../scatter/fillcolor_defaults"),c=t("./attributes");e.exports=function(t,e,r,u){function f(r,i){return n.coerce(t,e,c,r,i)}var h,p=f("locations");if(p&&p.length){var d,m=f("geojson");("string"==typeof m&&""!==m||n.isPlainObject(m))&&(d="geojson-id"),"geojson-id"===f("locationmode",d)&&f("featureidkey"),h=p.length}else{var g=f("lon")||[],v=f("lat")||[];h=Math.min(g.length,v.length)}h?(e._length=h,f("text"),f("hovertext"),f("hovertemplate"),f("mode"),i.hasLines(e)&&(o(t,e,r,u,f),f("connectgaps")),i.hasMarkers(e)&&a(t,e,r,u,f,{gradient:!0}),i.hasText(e)&&(f("texttemplate"),s(t,e,u,f)),f("fill"),"none"!==e.fill&&l(t,e,r,f),n.coerceSelectionMarkerOpacity(e,f)):e.visible=!1}},{"../../lib":503,"../scatter/fillcolor_defaults":935,"../scatter/line_defaults":940,"../scatter/marker_defaults":946,"../scatter/subtypes":952,"../scatter/text_defaults":953,"./attributes":969}],972:[function(t,e,r){"use strict";e.exports=function(t,e,r,n,i){t.lon=e.lon,t.lat=e.lat,t.location=e.loc?e.loc:null;var a=n[i];return a.fIn&&a.fIn.properties&&(t.properties=a.fIn.properties),t}},{}],973:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes");e.exports=function(t,e,r){var i={},a=r[e.geo]._subplot.mockAxis,o=t.lonlat;return i.lonLabel=n.tickText(a,a.c2l(o[0]),!0).text,i.latLabel=n.tickText(a,a.c2l(o[1]),!0).text,i}},{"../../plots/cartesian/axes":554}],974:[function(t,e,r){"use strict";var n=t("../../components/fx"),i=t("../../constants/numerical").BADNUM,a=t("../scatter/get_trace_color"),o=t("../../lib").fillText,s=t("./attributes");e.exports=function(t,e,r){var l=t.cd,c=l[0].trace,u=t.xa,f=t.ya,h=t.subplot,p=h.projection.isLonLatOverEdges,d=h.project;if(n.getClosest(l,(function(t){var n=t.lonlat;if(n[0]===i)return 1/0;if(p(n))return 1/0;var a=d(n),o=d([e,r]),s=Math.abs(a[0]-o[0]),l=Math.abs(a[1]-o[1]),c=Math.max(3,t.mrc||0);return Math.max(Math.sqrt(s*s+l*l)-c,1-3/c)}),t),!1!==t.index){var m=l[t.index],g=m.lonlat,v=[u.c2p(g),f.c2p(g)],y=m.mrc||1;t.x0=v[0]-y,t.x1=v[0]+y,t.y0=v[1]-y,t.y1=v[1]+y,t.loc=m.loc,t.lon=g[0],t.lat=g[1];var x={};x[c.geo]={_subplot:h};var b=c._module.formatLabels(m,c,x);return t.lonLabel=b.lonLabel,t.latLabel=b.latLabel,t.color=a(c,m),t.extraText=function(t,e,r,n){if(t.hovertemplate)return;var i=e.hi||t.hoverinfo,a="all"===i?s.hoverinfo.flags:i.split("+"),l=-1!==a.indexOf("location")&&Array.isArray(t.locations),c=-1!==a.indexOf("lon"),u=-1!==a.indexOf("lat"),f=-1!==a.indexOf("text"),h=[];function p(t){return t+"\xb0"}l?h.push(e.loc):c&&u?h.push("("+p(r.latLabel)+", "+p(r.lonLabel)+")"):c?h.push(n.lon+p(r.lonLabel)):u&&h.push(n.lat+p(r.latLabel));f&&o(e,t,h);return h.join("<br>")}(c,m,t,l[0].t.labels),t.hovertemplate=c.hovertemplate,[t]}}},{"../../components/fx":406,"../../constants/numerical":479,"../../lib":503,"../scatter/get_trace_color":937,"./attributes":969}],975:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:t("../scatter/marker_colorbar"),formatLabels:t("./format_labels"),calc:t("./calc"),calcGeoJSON:t("./plot").calcGeoJSON,plot:t("./plot").plot,style:t("./style"),styleOnSelect:t("../scatter/style").styleOnSelect,hoverPoints:t("./hover"),eventData:t("./event_data"),selectPoints:t("./select"),moduleType:"trace",name:"scattergeo",basePlotModule:t("../../plots/geo"),categories:["geo","symbols","showLegend","scatter-like"],meta:{}}},{"../../plots/geo":589,"../scatter/marker_colorbar":945,"../scatter/style":951,"./attributes":969,"./calc":970,"./defaults":971,"./event_data":972,"./format_labels":973,"./hover":974,"./plot":976,"./select":977,"./style":978}],976:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../../lib/topojson_utils").getTopojsonFeatures,o=t("../../lib/geojson_utils"),s=t("../../lib/geo_location_utils"),l=t("../../plots/cartesian/autorange").findExtremes,c=t("../../constants/numerical").BADNUM,u=t("../scatter/calc").calcMarkerSize,f=t("../scatter/subtypes"),h=t("./style");e.exports={calcGeoJSON:function(t,e){var r,n,i=t[0].trace,o=e[i.geo],f=o._subplot,h=i._length;if(Array.isArray(i.locations)){var p=i.locationmode,d="geojson-id"===p?s.extractTraceFeature(t):a(i,f.topojson);for(r=0;r<h;r++){n=t[r];var m="geojson-id"===p?n.fOut:s.locationToFeature(p,n.loc,d);n.lonlat=m?m.properties.ct:[c,c]}}var g,v,y={padded:!0};if("geojson"===o.fitbounds&&"geojson-id"===i.locationmode){var x=s.computeBbox(s.getTraceGeojson(i));g=[x[0],x[2]],v=[x[1],x[3]]}else{for(g=new Array(h),v=new Array(h),r=0;r<h;r++)n=t[r],g[r]=n.lonlat[0],v[r]=n.lonlat[1];y.ppad=u(i,h)}i._extremes.lon=l(o.lonaxis._ax,g,y),i._extremes.lat=l(o.lataxis._ax,v,y)},plot:function(t,e,r){var a=e.layers.frontplot.select(".scatterlayer"),s=i.makeTraceGroups(a,r,"trace scattergeo");function l(t,e){t.lonlat[0]===c&&n.select(e).remove()}s.selectAll("*").remove(),s.each((function(e){var r=n.select(this),a=e[0].trace;if(f.hasLines(a)||"none"!==a.fill){var s=o.calcTraceToLineCoords(e),c="none"!==a.fill?o.makePolygon(s):o.makeLine(s);r.selectAll("path.js-line").data([{geojson:c,trace:a}]).enter().append("path").classed("js-line",!0).style("stroke-miterlimit",2)}f.hasMarkers(a)&&r.selectAll("path.point").data(i.identity).enter().append("path").classed("point",!0).each((function(t){l(t,this)})),f.hasText(a)&&r.selectAll("g").data(i.identity).enter().append("g").append("text").each((function(t){l(t,this)})),h(t,e)}))}}},{"../../constants/numerical":479,"../../lib":503,"../../lib/geo_location_utils":496,"../../lib/geojson_utils":497,"../../lib/topojson_utils":532,"../../plots/cartesian/autorange":553,"../scatter/calc":928,"../scatter/subtypes":952,"./style":978,"@plotly/d3":58}],977:[function(t,e,r){"use strict";var n=t("../scatter/subtypes"),i=t("../../constants/numerical").BADNUM;e.exports=function(t,e){var r,a,o,s,l,c=t.cd,u=t.xaxis,f=t.yaxis,h=[],p=c[0].trace;if(!n.hasMarkers(p)&&!n.hasText(p))return[];if(!1===e)for(l=0;l<c.length;l++)c[l].selected=0;else for(l=0;l<c.length;l++)(a=(r=c[l]).lonlat)[0]!==i&&(o=u.c2p(a),s=f.c2p(a),e.contains([o,s],null,l,t)?(h.push({pointNumber:l,lon:a[0],lat:a[1]}),r.selected=1):r.selected=0);return h}},{"../../constants/numerical":479,"../scatter/subtypes":952}],978:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/drawing"),a=t("../../components/color"),o=t("../scatter/style"),s=o.stylePoints,l=o.styleText;e.exports=function(t,e){e&&function(t,e){var r=e[0].trace,o=e[0].node3;o.style("opacity",e[0].trace.opacity),s(o,r,t),l(o,r,t),o.selectAll("path.js-line").style("fill","none").each((function(t){var e=n.select(this),r=t.trace,o=r.line||{};e.call(a.stroke,o.color).call(i.dashLine,o.dash||"",o.width||0),"none"!==r.fill&&e.call(a.fill,r.fillcolor)}))}(t,e)}},{"../../components/color":366,"../../components/drawing":388,"../scatter/style":951,"@plotly/d3":58}],979:[function(t,e,r){"use strict";var n=t("../../plots/attributes"),i=t("../scatter/attributes"),a=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,o=t("../../components/colorscale/attributes"),s=t("../../lib/sort_object_keys"),l=t("../../lib/extend").extendFlat,c=t("../../plot_api/edit_types").overrideAll,u=t("./constants").DASHES,f=i.line,h=i.marker,p=h.line,d=e.exports=c({x:i.x,x0:i.x0,dx:i.dx,y:i.y,y0:i.y0,dy:i.dy,xperiod:i.xperiod,yperiod:i.yperiod,xperiod0:i.xperiod0,yperiod0:i.yperiod0,xperiodalignment:i.xperiodalignment,yperiodalignment:i.yperiodalignment,xhoverformat:a("x"),yhoverformat:a("y"),text:i.text,hovertext:i.hovertext,textposition:i.textposition,textfont:i.textfont,mode:{valType:"flaglist",flags:["lines","markers","text"],extras:["none"]},line:{color:f.color,width:f.width,shape:{valType:"enumerated",values:["linear","hv","vh","hvh","vhv"],dflt:"linear",editType:"plot"},dash:{valType:"enumerated",values:s(u),dflt:"solid"}},marker:l({},o("marker"),{symbol:h.symbol,size:h.size,sizeref:h.sizeref,sizemin:h.sizemin,sizemode:h.sizemode,opacity:h.opacity,colorbar:h.colorbar,line:l({},o("marker.line"),{width:p.width})}),connectgaps:i.connectgaps,fill:l({},i.fill,{dflt:"none"}),fillcolor:i.fillcolor,selected:{marker:i.selected.marker,textfont:i.selected.textfont},unselected:{marker:i.unselected.marker,textfont:i.unselected.textfont},opacity:n.opacity},"calc","nested");d.x.editType=d.y.editType=d.x0.editType=d.y0.editType="calc+clearAxisTypes",d.hovertemplate=i.hovertemplate,d.texttemplate=i.texttemplate},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../lib/sort_object_keys":526,"../../plot_api/edit_types":536,"../../plots/attributes":550,"../../plots/cartesian/axis_format_attributes":557,"../scatter/attributes":927,"./constants":982}],980:[function(t,e,r){"use strict";var n=t("./hover");e.exports={moduleType:"trace",name:"scattergl",basePlotModule:t("../../plots/cartesian"),categories:["gl","regl","cartesian","symbols","errorBarsOK","showLegend","scatter-like"],attributes:t("./attributes"),supplyDefaults:t("./defaults"),crossTraceDefaults:t("../scatter/cross_trace_defaults"),colorbar:t("../scatter/marker_colorbar"),formatLabels:t("./format_labels"),calc:t("./calc"),hoverPoints:n.hoverPoints,selectPoints:t("./select"),meta:{}}},{"../../plots/cartesian":568,"../scatter/cross_trace_defaults":933,"../scatter/marker_colorbar":945,"./attributes":979,"./calc":981,"./defaults":984,"./format_labels":986,"./hover":988,"./select":992}],981:[function(t,e,r){"use strict";var n=t("@plotly/point-cluster"),i=t("../../lib"),a=t("../../plots/cartesian/axis_ids"),o=t("../../plots/cartesian/autorange").findExtremes,s=t("../../plots/cartesian/align_period"),l=t("../scatter/calc"),c=l.calcMarkerSize,u=l.calcAxisExpansion,f=l.setFirstScatter,h=t("../scatter/colorscale_calc"),p=t("./convert"),d=t("./scene_update"),m=t("../../constants/numerical").BADNUM,g=t("./constants").TOO_MANY_POINTS;function v(t,e,r){var n=t._extremes[e._id],i=o(e,r._bnds,{padded:!0});n.min=n.min.concat(i.min),n.max=n.max.concat(i.max)}e.exports=function(t,e){var r,o=t._fullLayout,l=a.getFromId(t,e.xaxis),y=a.getFromId(t,e.yaxis),x=o._plots[e.xaxis+e.yaxis],b=e._length,_=b>=g,w=2*b,T={},k=l.makeCalcdata(e,"x"),A=y.makeCalcdata(e,"y"),M=s(e,l,"x",k),S=s(e,y,"y",A),E=M.vals,L=S.vals;e._x=E,e._y=L,e.xperiodalignment&&(e._origX=k,e._xStarts=M.starts,e._xEnds=M.ends),e.yperiodalignment&&(e._origY=A,e._yStarts=S.starts,e._yEnds=S.ends);var C=new Array(w),P=new Array(b);for(r=0;r<b;r++)C[2*r]=E[r]===m?NaN:E[r],C[2*r+1]=L[r]===m?NaN:L[r],P[r]=r;if("log"===l.type)for(r=0;r<w;r+=2)C[r]=l.c2l(C[r]);if("log"===y.type)for(r=1;r<w;r+=2)C[r]=y.c2l(C[r]);_&&"log"!==l.type&&"log"!==y.type?T.tree=n(C):T.ids=P,h(t,e);var I,O=function(t,e,r,n,a,o){var s=p.style(t,r);s.marker&&(s.marker.positions=n);s.line&&n.length>1&&i.extendFlat(s.line,p.linePositions(t,r,n));if(s.errorX||s.errorY){var l=p.errorBarPositions(t,r,n,a,o);s.errorX&&i.extendFlat(s.errorX,l.x),s.errorY&&i.extendFlat(s.errorY,l.y)}s.text&&(i.extendFlat(s.text,{positions:n},p.textPosition(t,r,s.text,s.marker)),i.extendFlat(s.textSel,{positions:n},p.textPosition(t,r,s.text,s.markerSel)),i.extendFlat(s.textUnsel,{positions:n},p.textPosition(t,r,s.text,s.markerUnsel)));return s}(t,0,e,C,E,L),z=d(t,x);return f(o,e),_?O.marker&&(I=O.marker.sizeAvg||Math.max(O.marker.size,3)):I=c(e,b),u(t,e,l,y,E,L,I),O.errorX&&v(e,l,O.errorX),O.errorY&&v(e,y,O.errorY),O.fill&&!z.fill2d&&(z.fill2d=!0),O.marker&&!z.scatter2d&&(z.scatter2d=!0),O.line&&!z.line2d&&(z.line2d=!0),!O.errorX&&!O.errorY||z.error2d||(z.error2d=!0),O.text&&!z.glText&&(z.glText=!0),O.marker&&(O.marker.snap=b),z.lineOptions.push(O.line),z.errorXOptions.push(O.errorX),z.errorYOptions.push(O.errorY),z.fillOptions.push(O.fill),z.markerOptions.push(O.marker),z.markerSelectedOptions.push(O.markerSel),z.markerUnselectedOptions.push(O.markerUnsel),z.textOptions.push(O.text),z.textSelectedOptions.push(O.textSel),z.textUnselectedOptions.push(O.textUnsel),z.selectBatch.push([]),z.unselectBatch.push([]),T._scene=z,T.index=z.count,T.x=E,T.y=L,T.positions=C,z.count++,[{x:!1,y:!1,t:T,trace:e}]}},{"../../constants/numerical":479,"../../lib":503,"../../plots/cartesian/align_period":551,"../../plots/cartesian/autorange":553,"../../plots/cartesian/axis_ids":558,"../scatter/calc":928,"../scatter/colorscale_calc":930,"./constants":982,"./convert":983,"./scene_update":991,"@plotly/point-cluster":59}],982:[function(t,e,r){"use strict";e.exports={TOO_MANY_POINTS:1e5,SYMBOL_SDF_SIZE:200,SYMBOL_SIZE:20,SYMBOL_STROKE:1,DOT_RE:/-dot/,OPEN_RE:/-open/,DASHES:{solid:[1],dot:[1,1],dash:[4,1],longdash:[8,1],dashdot:[4,1,1,1],longdashdot:[8,1,1,1]}}},{}],983:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("svg-path-sdf"),a=t("color-normalize"),o=t("../../registry"),s=t("../../lib"),l=t("../../components/drawing"),c=t("../../plots/cartesian/axis_ids"),u=t("../../lib/gl_format_color").formatColor,f=t("../scatter/subtypes"),h=t("../scatter/make_bubble_size_func"),p=t("./helpers"),d=t("./constants"),m=t("../../constants/interactions").DESELECTDIM,g={start:1,left:1,end:-1,right:-1,middle:0,center:0,bottom:1,top:-1},v=t("../../components/fx/helpers").appendArrayPointValue;function y(t,e){var r,i=t._fullLayout,a=e._length,o=e.textfont,l=e.textposition,c=Array.isArray(l)?l:[l],u=o.color,f=o.size,h=o.family,p={},d=t._context.plotGlPixelRatio,m=e.texttemplate;if(m){p.text=[];var g=i._d3locale,y=Array.isArray(m),x=y?Math.min(m.length,a):a,b=y?function(t){return m[t]}:function(){return m};for(r=0;r<x;r++){var _={i:r},w=e._module.formatLabels(_,e,i),T={};v(T,e,r);var k=e._meta||{};p.text.push(s.texttemplateString(b(r),w,g,T,_,k))}}else Array.isArray(e.text)&&e.text.length<a?p.text=e.text.slice():p.text=e.text;if(Array.isArray(p.text))for(r=p.text.length;r<a;r++)p.text[r]="";for(p.opacity=e.opacity,p.font={},p.align=[],p.baseline=[],r=0;r<c.length;r++){var A=c[r].split(/\s+/);switch(A[1]){case"left":p.align.push("right");break;case"right":p.align.push("left");break;default:p.align.push(A[1])}switch(A[0]){case"top":p.baseline.push("bottom");break;case"bottom":p.baseline.push("top");break;default:p.baseline.push(A[0])}}if(Array.isArray(u))for(p.color=new Array(a),r=0;r<a;r++)p.color[r]=u[r];else p.color=u;if(s.isArrayOrTypedArray(f)||Array.isArray(h))for(p.font=new Array(a),r=0;r<a;r++){var M=p.font[r]={};M.size=(s.isTypedArray(f)?f[r]:Array.isArray(f)?n(f[r])?f[r]:0:f)*d,M.family=Array.isArray(h)?h[r]:h}else p.font={size:f*d,family:h};return p}function x(t){var e,r,n=t._length,i=t.marker,o={},l=s.isArrayOrTypedArray(i.symbol),c=s.isArrayOrTypedArray(i.color),f=s.isArrayOrTypedArray(i.line.color),d=s.isArrayOrTypedArray(i.opacity),m=s.isArrayOrTypedArray(i.size),g=s.isArrayOrTypedArray(i.line.width);if(l||(r=p.isOpenSymbol(i.symbol)),l||c||f||d){o.colors=new Array(n),o.borderColors=new Array(n);var v=u(i,i.opacity,n),y=u(i.line,i.opacity,n);if(!Array.isArray(y[0])){var x=y;for(y=Array(n),e=0;e<n;e++)y[e]=x}if(!Array.isArray(v[0])){var b=v;for(v=Array(n),e=0;e<n;e++)v[e]=b}for(o.colors=v,o.borderColors=y,e=0;e<n;e++){if(l){var _=i.symbol[e];r=p.isOpenSymbol(_)}r&&(y[e]=v[e].slice(),v[e]=v[e].slice(),v[e][3]=0)}o.opacity=t.opacity}else r?(o.color=a(i.color,"uint8"),o.color[3]=0,o.borderColor=a(i.color,"uint8")):(o.color=a(i.color,"uint8"),o.borderColor=a(i.line.color,"uint8")),o.opacity=t.opacity*i.opacity;if(l)for(o.markers=new Array(n),e=0;e<n;e++)o.markers[e]=E(i.symbol[e]);else o.marker=E(i.symbol);var w,T=h(t,1);if(m||g){var k,A=o.sizes=new Array(n),M=o.borderSizes=new Array(n),S=0;if(m){for(e=0;e<n;e++)A[e]=T(i.size[e]),S+=A[e];k=S/n}else for(w=T(i.size),e=0;e<n;e++)A[e]=w;if(g)for(e=0;e<n;e++)M[e]=i.line.width[e];else for(w=i.line.width,e=0;e<n;e++)M[e]=w;o.sizeAvg=k}else o.size=T(i&&i.size||10),o.borderSizes=T(i.line.width);return o}function b(t,e){var r=t.marker,n={};return e?(e.marker&&e.marker.symbol?n=x(s.extendFlat({},r,e.marker)):e.marker&&(e.marker.size&&(n.size=e.marker.size),e.marker.color&&(n.colors=e.marker.color),void 0!==e.marker.opacity&&(n.opacity=e.marker.opacity)),n):n}function _(t,e,r){var n={};if(!r)return n;if(r.textfont){var i={opacity:1,text:e.text,texttemplate:e.texttemplate,textposition:e.textposition,textfont:s.extendFlat({},e.textfont)};r.textfont&&s.extendFlat(i.textfont,r.textfont),n=y(t,i)}return n}function w(t,e,r){var n={capSize:2*e.width*r,lineWidth:e.thickness*r,color:e.color};return e.copy_ystyle&&(n=t.error_y),n}var T=d.SYMBOL_SDF_SIZE,k=d.SYMBOL_SIZE,A=d.SYMBOL_STROKE,M={},S=l.symbolFuncs[0](.05*k);function E(t){if("circle"===t)return null;var e,r,n=l.symbolNumber(t),a=l.symbolFuncs[n%100],o=!!l.symbolNoDot[n%100],s=!!l.symbolNoFill[n%100],c=p.isDotSymbol(t);return M[t]?M[t]:(e=c&&!o?a(1.1*k)+S:a(k),r=i(e,{w:T,h:T,viewBox:[-k,-k,k,k],stroke:s?A:-A}),M[t]=r,r||null)}e.exports={style:function(t,e){var r,n={marker:void 0,markerSel:void 0,markerUnsel:void 0,line:void 0,fill:void 0,errorX:void 0,errorY:void 0,text:void 0,textSel:void 0,textUnsel:void 0},i=t._context.plotGlPixelRatio;if(!0!==e.visible)return n;if(f.hasText(e)&&(n.text=y(t,e),n.textSel=_(t,e,e.selected),n.textUnsel=_(t,e,e.unselected)),f.hasMarkers(e)&&(n.marker=x(e),n.markerSel=b(e,e.selected),n.markerUnsel=b(e,e.unselected),!e.unselected&&s.isArrayOrTypedArray(e.marker.opacity))){var a=e.marker.opacity;for(n.markerUnsel.opacity=new Array(a.length),r=0;r<a.length;r++)n.markerUnsel.opacity[r]=m*a[r]}if(f.hasLines(e)){n.line={overlay:!0,thickness:e.line.width*i,color:e.line.color,opacity:e.opacity};var o=(d.DASHES[e.line.dash]||[1]).slice();for(r=0;r<o.length;++r)o[r]*=e.line.width*i;n.line.dashes=o}return e.error_x&&e.error_x.visible&&(n.errorX=w(e,e.error_x,i)),e.error_y&&e.error_y.visible&&(n.errorY=w(e,e.error_y,i)),e.fill&&"none"!==e.fill&&(n.fill={closed:!0,fill:e.fillcolor,thickness:0}),n},markerStyle:x,markerSelection:b,linePositions:function(t,e,r){var n,i,a=r.length,o=a/2;if(f.hasLines(e)&&o)if("hv"===e.line.shape){for(n=[],i=0;i<o-1;i++)isNaN(r[2*i])||isNaN(r[2*i+1])?n.push(NaN,NaN,NaN,NaN):(n.push(r[2*i],r[2*i+1]),isNaN(r[2*i+2])||isNaN(r[2*i+3])?n.push(NaN,NaN):n.push(r[2*i+2],r[2*i+1]));n.push(r[a-2],r[a-1])}else if("hvh"===e.line.shape){for(n=[],i=0;i<o-1;i++)if(isNaN(r[2*i])||isNaN(r[2*i+1])||isNaN(r[2*i+2])||isNaN(r[2*i+3]))isNaN(r[2*i])||isNaN(r[2*i+1])?n.push(NaN,NaN):n.push(r[2*i],r[2*i+1]),n.push(NaN,NaN);else{var s=(r[2*i]+r[2*i+2])/2;n.push(r[2*i],r[2*i+1],s,r[2*i+1],s,r[2*i+3])}n.push(r[a-2],r[a-1])}else if("vhv"===e.line.shape){for(n=[],i=0;i<o-1;i++)if(isNaN(r[2*i])||isNaN(r[2*i+1])||isNaN(r[2*i+2])||isNaN(r[2*i+3]))isNaN(r[2*i])||isNaN(r[2*i+1])?n.push(NaN,NaN):n.push(r[2*i],r[2*i+1]),n.push(NaN,NaN);else{var l=(r[2*i+1]+r[2*i+3])/2;n.push(r[2*i],r[2*i+1],r[2*i],l,r[2*i+2],l)}n.push(r[a-2],r[a-1])}else if("vh"===e.line.shape){for(n=[],i=0;i<o-1;i++)isNaN(r[2*i])||isNaN(r[2*i+1])?n.push(NaN,NaN,NaN,NaN):(n.push(r[2*i],r[2*i+1]),isNaN(r[2*i+2])||isNaN(r[2*i+3])?n.push(NaN,NaN):n.push(r[2*i],r[2*i+3]));n.push(r[a-2],r[a-1])}else n=r;var c=!1;for(i=0;i<n.length;i++)if(isNaN(n[i])){c=!0;break}var u=c||n.length>d.TOO_MANY_POINTS||f.hasMarkers(e)?"rect":"round";if(c&&e.connectgaps){var h=n[0],p=n[1];for(i=0;i<n.length;i+=2)isNaN(n[i])||isNaN(n[i+1])?(n[i]=h,n[i+1]=p):(h=n[i],p=n[i+1])}return{join:u,positions:n}},errorBarPositions:function(t,e,r,i,a){var s=o.getComponentMethod("errorbars","makeComputeError"),l=c.getFromId(t,e.xaxis),u=c.getFromId(t,e.yaxis),f=r.length/2,h={};function p(t,i){var a=i._id.charAt(0),o=e["error_"+a];if(o&&o.visible&&("linear"===i.type||"log"===i.type)){for(var l=s(o),c={x:0,y:1}[a],u={x:[0,1,2,3],y:[2,3,0,1]}[a],p=new Float64Array(4*f),d=1/0,m=-1/0,g=0,v=0;g<f;g++,v+=4){var y=t[g];if(n(y)){var x=r[2*g+c],b=l(y,g),_=b[0],w=b[1];if(n(_)&&n(w)){var T=y-_,k=y+w;p[v+u[0]]=x-i.c2l(T),p[v+u[1]]=i.c2l(k)-x,p[v+u[2]]=0,p[v+u[3]]=0,d=Math.min(d,y-_),m=Math.max(m,y+w)}}}h[a]={positions:r,errors:p,_bnds:[d,m]}}}return p(i,l),p(a,u),h},textPosition:function(t,e,r,n){var i,a=e._length,o={};if(f.hasMarkers(e)){var s=r.font,l=r.align,c=r.baseline;for(o.offset=new Array(a),i=0;i<a;i++){var u=n.sizes?n.sizes[i]:n.size,h=Array.isArray(s)?s[i].size:s.size,p=Array.isArray(l)?l.length>1?l[i]:l[0]:l,d=Array.isArray(c)?c.length>1?c[i]:c[0]:c,m=g[p],v=g[d],y=u?u/.8+1:0,x=-v*y-.5*v;o.offset[i]=[m*y/h,x/h]}}return o}}},{"../../components/drawing":388,"../../components/fx/helpers":402,"../../constants/interactions":478,"../../lib":503,"../../lib/gl_format_color":499,"../../plots/cartesian/axis_ids":558,"../../registry":638,"../scatter/make_bubble_size_func":944,"../scatter/subtypes":952,"./constants":982,"./helpers":987,"color-normalize":89,"fast-isnumeric":190,"svg-path-sdf":310}],984:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../registry"),a=t("./helpers"),o=t("./attributes"),s=t("../scatter/constants"),l=t("../scatter/subtypes"),c=t("../scatter/xy_defaults"),u=t("../scatter/period_defaults"),f=t("../scatter/marker_defaults"),h=t("../scatter/line_defaults"),p=t("../scatter/fillcolor_defaults"),d=t("../scatter/text_defaults");e.exports=function(t,e,r,m){function g(r,i){return n.coerce(t,e,o,r,i)}var v=!!t.marker&&a.isOpenSymbol(t.marker.symbol),y=l.isBubble(t),x=c(t,e,m,g);if(x){u(t,e,m,g),g("xhoverformat"),g("yhoverformat");var b=x<s.PTS_LINESONLY?"lines+markers":"lines";g("text"),g("hovertext"),g("hovertemplate"),g("mode",b),l.hasLines(e)&&(g("connectgaps"),h(t,e,r,m,g),g("line.shape")),l.hasMarkers(e)&&(f(t,e,r,m,g),g("marker.line.width",v||y?1:0)),l.hasText(e)&&(g("texttemplate"),d(t,e,m,g));var _=(e.line||{}).color,w=(e.marker||{}).color;g("fill"),"none"!==e.fill&&p(t,e,r,g);var T=i.getComponentMethod("errorbars","supplyDefaults");T(t,e,_||w||r,{axis:"y"}),T(t,e,_||w||r,{axis:"x",inherit:"y"}),n.coerceSelectionMarkerOpacity(e,g)}else e.visible=!1}},{"../../lib":503,"../../registry":638,"../scatter/constants":931,"../scatter/fillcolor_defaults":935,"../scatter/line_defaults":940,"../scatter/marker_defaults":946,"../scatter/period_defaults":947,"../scatter/subtypes":952,"../scatter/text_defaults":953,"../scatter/xy_defaults":954,"./attributes":979,"./helpers":987}],985:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/color"),a=t("../../constants/interactions").DESELECTDIM;e.exports={styleTextSelection:function(t){var e,r,o=t[0],s=o.trace,l=o.t,c=l._scene,u=l.index,f=c.selectBatch[u],h=c.unselectBatch[u],p=c.textOptions[u],d=c.textSelectedOptions[u]||{},m=c.textUnselectedOptions[u]||{},g=n.extendFlat({},p);if(f.length||h.length){var v=d.color,y=m.color,x=p.color,b=Array.isArray(x);for(g.color=new Array(s._length),e=0;e<f.length;e++)r=f[e],g.color[r]=v||(b?x[r]:x);for(e=0;e<h.length;e++){r=h[e];var _=b?x[r]:x;g.color[r]=y||(v?_:i.addOpacity(_,a))}}c.glText[u].update(g)}}},{"../../components/color":366,"../../constants/interactions":478,"../../lib":503}],986:[function(t,e,r){"use strict";var n=t("../scatter/format_labels");e.exports=function(t,e,r){var i=t.i;return"x"in t||(t.x=e._x[i]),"y"in t||(t.y=e._y[i]),n(t,e,r)}},{"../scatter/format_labels":936}],987:[function(t,e,r){"use strict";var n=t("./constants");r.isOpenSymbol=function(t){return"string"==typeof t?n.OPEN_RE.test(t):t%200>100},r.isDotSymbol=function(t){return"string"==typeof t?n.DOT_RE.test(t):t>200}},{"./constants":982}],988:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib"),a=t("../scatter/get_trace_color");function o(t,e,r,o){var s=t.xa,l=t.ya,c=t.distance,u=t.dxy,f=t.index,h={pointNumber:f,x:e[f],y:r[f]};h.tx=Array.isArray(o.text)?o.text[f]:o.text,h.htx=Array.isArray(o.hovertext)?o.hovertext[f]:o.hovertext,h.data=Array.isArray(o.customdata)?o.customdata[f]:o.customdata,h.tp=Array.isArray(o.textposition)?o.textposition[f]:o.textposition;var p=o.textfont;p&&(h.ts=i.isArrayOrTypedArray(p.size)?p.size[f]:p.size,h.tc=Array.isArray(p.color)?p.color[f]:p.color,h.tf=Array.isArray(p.family)?p.family[f]:p.family);var d=o.marker;d&&(h.ms=i.isArrayOrTypedArray(d.size)?d.size[f]:d.size,h.mo=i.isArrayOrTypedArray(d.opacity)?d.opacity[f]:d.opacity,h.mx=i.isArrayOrTypedArray(d.symbol)?d.symbol[f]:d.symbol,h.mc=i.isArrayOrTypedArray(d.color)?d.color[f]:d.color);var m=d&&d.line;m&&(h.mlc=Array.isArray(m.color)?m.color[f]:m.color,h.mlw=i.isArrayOrTypedArray(m.width)?m.width[f]:m.width);var g=d&&d.gradient;g&&"none"!==g.type&&(h.mgt=Array.isArray(g.type)?g.type[f]:g.type,h.mgc=Array.isArray(g.color)?g.color[f]:g.color);var v=s.c2p(h.x,!0),y=l.c2p(h.y,!0),x=h.mrc||1,b=o.hoverlabel;b&&(h.hbg=Array.isArray(b.bgcolor)?b.bgcolor[f]:b.bgcolor,h.hbc=Array.isArray(b.bordercolor)?b.bordercolor[f]:b.bordercolor,h.hts=i.isArrayOrTypedArray(b.font.size)?b.font.size[f]:b.font.size,h.htc=Array.isArray(b.font.color)?b.font.color[f]:b.font.color,h.htf=Array.isArray(b.font.family)?b.font.family[f]:b.font.family,h.hnl=i.isArrayOrTypedArray(b.namelength)?b.namelength[f]:b.namelength);var _=o.hoverinfo;_&&(h.hi=Array.isArray(_)?_[f]:_);var w=o.hovertemplate;w&&(h.ht=Array.isArray(w)?w[f]:w);var T={};T[t.index]=h;var k=o._origX,A=o._origY,M=i.extendFlat({},t,{color:a(o,h),x0:v-x,x1:v+x,xLabelVal:k?k[f]:h.x,y0:y-x,y1:y+x,yLabelVal:A?A[f]:h.y,cd:T,distance:c,spikeDistance:u,hovertemplate:h.ht});return h.htx?M.text=h.htx:h.tx?M.text=h.tx:o.text&&(M.text=o.text),i.fillText(h,o,M),n.getComponentMethod("errorbars","hoverInfo")(h,o,M),M}e.exports={hoverPoints:function(t,e,r,n){var i,a,s,l,c,u,f,h,p,d,m=t.cd,g=m[0].t,v=m[0].trace,y=t.xa,x=t.ya,b=g.x,_=g.y,w=y.c2p(e),T=x.c2p(r),k=t.distance;if(g.tree){var A=y.p2c(w-k),M=y.p2c(w+k),S=x.p2c(T-k),E=x.p2c(T+k);i="x"===n?g.tree.range(Math.min(A,M),Math.min(x._rl[0],x._rl[1]),Math.max(A,M),Math.max(x._rl[0],x._rl[1])):g.tree.range(Math.min(A,M),Math.min(S,E),Math.max(A,M),Math.max(S,E))}else i=g.ids;var L=k;if("x"===n){var C=!!v.xperiodalignment,P=!!v.yperiodalignment;for(u=0;u<i.length;u++){if(l=b[a=i[u]],f=Math.abs(y.c2p(l)-w),C){var I=y.c2p(v._xStarts[a]),O=y.c2p(v._xEnds[a]);f=w>=Math.min(I,O)&&w<=Math.max(I,O)?0:1/0}if(f<L){if(L=f,c=_[a],h=x.c2p(c)-T,P){var z=x.c2p(v._yStarts[a]),D=x.c2p(v._yEnds[a]);h=T>=Math.min(z,D)&&T<=Math.max(z,D)?0:1/0}d=Math.sqrt(f*f+h*h),s=i[u]}}}else for(u=i.length-1;u>-1;u--)l=b[a=i[u]],c=_[a],f=y.c2p(l)-w,h=x.c2p(c)-T,(p=Math.sqrt(f*f+h*h))<L&&(L=d=p,s=a);return t.index=s,t.distance=L,t.dxy=d,void 0===s?[t]:[o(t,b,_,v)]},calcHover:o}},{"../../lib":503,"../../registry":638,"../scatter/get_trace_color":937}],989:[function(t,e,r){arguments[4][896][0].apply(r,arguments)},{"./base_index":980,"./plot":990,dup:896}],990:[function(t,e,r){"use strict";var n=t("regl-scatter2d"),i=t("regl-line2d"),a=t("regl-error2d"),o=t("gl-text"),s=t("../../lib"),l=t("../../components/dragelement/helpers").selectMode,c=t("../../lib/prepare_regl"),u=t("../scatter/subtypes"),f=t("../scatter/link_traces"),h=t("./edit_style").styleTextSelection,p={};function d(t,e,r,n){var i=t._size,a=t.width*n,o=t.height*n,s=i.l*n,l=i.b*n,c=i.r*n,u=i.t*n,f=i.w*n,h=i.h*n;return[s+e.domain[0]*f,l+r.domain[0]*h,a-c-(1-e.domain[1])*f,o-u-(1-r.domain[1])*h]}(e.exports=function(t,e,r){if(r.length){var m,g,v=t._fullLayout,y=e._scene,x=e.xaxis,b=e.yaxis;if(y)if(c(t,["ANGLE_instanced_arrays","OES_element_index_uint"],p)){var _=y.count,w=v._glcanvas.data()[0].regl;if(f(t,e,r),y.dirty){if(!0===y.error2d&&(y.error2d=a(w)),!0===y.line2d&&(y.line2d=i(w)),!0===y.scatter2d&&(y.scatter2d=n(w)),!0===y.fill2d&&(y.fill2d=i(w)),!0===y.glText)for(y.glText=new Array(_),m=0;m<_;m++)y.glText[m]=new o(w);if(y.glText){if(_>y.glText.length){var T=_-y.glText.length;for(m=0;m<T;m++)y.glText.push(new o(w))}else if(_<y.glText.length){var k=y.glText.length-_;y.glText.splice(_,k).forEach((function(t){t.destroy()}))}for(m=0;m<_;m++)y.glText[m].update(y.textOptions[m])}if(y.line2d&&(y.line2d.update(y.lineOptions),y.lineOptions=y.lineOptions.map((function(t){if(t&&t.positions){for(var e=t.positions,r=0;r<e.length&&(isNaN(e[r])||isNaN(e[r+1]));)r+=2;for(var n=e.length-2;n>r&&(isNaN(e[n])||isNaN(e[n+1]));)n-=2;t.positions=e.slice(r,n+2)}return t})),y.line2d.update(y.lineOptions)),y.error2d){var A=(y.errorXOptions||[]).concat(y.errorYOptions||[]);y.error2d.update(A)}y.scatter2d&&y.scatter2d.update(y.markerOptions),y.fillOrder=s.repeat(null,_),y.fill2d&&(y.fillOptions=y.fillOptions.map((function(t,e){var n=r[e];if(t&&n&&n[0]&&n[0].trace){var i,a,o=n[0],s=o.trace,l=o.t,c=y.lineOptions[e],u=[];s._ownfill&&u.push(e),s._nexttrace&&u.push(e+1),u.length&&(y.fillOrder[e]=u);var f,h,p=[],d=c&&c.positions||l.positions;if("tozeroy"===s.fill){for(f=0;f<d.length&&isNaN(d[f+1]);)f+=2;for(h=d.length-2;h>f&&isNaN(d[h+1]);)h-=2;0!==d[f+1]&&(p=[d[f],0]),p=p.concat(d.slice(f,h+2)),0!==d[h+1]&&(p=p.concat([d[h],0]))}else if("tozerox"===s.fill){for(f=0;f<d.length&&isNaN(d[f]);)f+=2;for(h=d.length-2;h>f&&isNaN(d[h]);)h-=2;0!==d[f]&&(p=[0,d[f+1]]),p=p.concat(d.slice(f,h+2)),0!==d[h]&&(p=p.concat([0,d[h+1]]))}else if("toself"===s.fill||"tonext"===s.fill){for(p=[],i=0,t.splitNull=!0,a=0;a<d.length;a+=2)(isNaN(d[a])||isNaN(d[a+1]))&&((p=p.concat(d.slice(i,a))).push(d[i],d[i+1]),p.push(null,null),i=a+2);p=p.concat(d.slice(i)),i&&p.push(d[i],d[i+1])}else{var m=s._nexttrace;if(m){var g=y.lineOptions[e+1];if(g){var v=g.positions;if("tonexty"===s.fill){for(p=d.slice(),e=Math.floor(v.length/2);e--;){var x=v[2*e],b=v[2*e+1];isNaN(x)||isNaN(b)||p.push(x,b)}t.fill=m.fillcolor}}}}if(s._prevtrace&&"tonext"===s._prevtrace.fill){var _=y.lineOptions[e-1].positions,w=p.length/2,T=[i=w];for(a=0;a<_.length;a+=2)(isNaN(_[a])||isNaN(_[a+1]))&&(T.push(a/2+w+1),i=a+2);p=p.concat(_),t.hole=T}return t.fillmode=s.fill,t.opacity=s.opacity,t.positions=p,t}})),y.fill2d.update(y.fillOptions))}var M=v.dragmode,S=l(M),E=v.clickmode.indexOf("select")>-1;for(m=0;m<_;m++){var L=r[m][0],C=L.trace,P=L.t,I=P.index,O=C._length,z=P.x,D=P.y;if(C.selectedpoints||S||E){if(S||(S=!0),C.selectedpoints){var R=y.selectBatch[I]=s.selIndices2selPoints(C),F={};for(g=0;g<R.length;g++)F[R[g]]=1;var B=[];for(g=0;g<O;g++)F[g]||B.push(g);y.unselectBatch[I]=B}var N=P.xpx=new Array(O),j=P.ypx=new Array(O);for(g=0;g<O;g++)N[g]=x.c2p(z[g]),j[g]=b.c2p(D[g])}else P.xpx=P.ypx=null}if(S){if(y.select2d||(y.select2d=n(v._glcanvas.data()[1].regl)),y.scatter2d){var U=new Array(_);for(m=0;m<_;m++)U[m]=y.selectBatch[m].length||y.unselectBatch[m].length?y.markerUnselectedOptions[m]:{};y.scatter2d.update(U)}y.select2d&&(y.select2d.update(y.markerOptions),y.select2d.update(y.markerSelectedOptions)),y.glText&&r.forEach((function(t){var e=((t||[])[0]||{}).trace||{};u.hasText(e)&&h(t)}))}else y.scatter2d&&y.scatter2d.update(y.markerOptions);var V={viewport:d(v,x,b,t._context.plotGlPixelRatio),range:[(x._rl||x.range)[0],(b._rl||b.range)[0],(x._rl||x.range)[1],(b._rl||b.range)[1]]},H=s.repeat(V,y.count);y.fill2d&&y.fill2d.update(H),y.line2d&&y.line2d.update(H),y.error2d&&y.error2d.update(H.concat(H)),y.scatter2d&&y.scatter2d.update(H),y.select2d&&y.select2d.update(H),y.glText&&y.glText.forEach((function(t){t.update(V)}))}else y.init()}}).reglPrecompiled=p},{"../../components/dragelement/helpers":384,"../../lib":503,"../../lib/prepare_regl":516,"../scatter/link_traces":943,"../scatter/subtypes":952,"./edit_style":985,"gl-text":225,"regl-error2d":279,"regl-line2d":280,"regl-scatter2d":281}],991:[function(t,e,r){"use strict";var n=t("../../lib");e.exports=function(t,e){var r=e._scene,i={count:0,dirty:!0,lineOptions:[],fillOptions:[],markerOptions:[],markerSelectedOptions:[],markerUnselectedOptions:[],errorXOptions:[],errorYOptions:[],textOptions:[],textSelectedOptions:[],textUnselectedOptions:[],selectBatch:[],unselectBatch:[]},a={fill2d:!1,scatter2d:!1,error2d:!1,line2d:!1,glText:!1,select2d:!1};return e._scene||((r=e._scene={}).init=function(){n.extendFlat(r,a,i)},r.init(),r.update=function(t){var e=n.repeat(t,r.count);if(r.fill2d&&r.fill2d.update(e),r.scatter2d&&r.scatter2d.update(e),r.line2d&&r.line2d.update(e),r.error2d&&r.error2d.update(e.concat(e)),r.select2d&&r.select2d.update(e),r.glText)for(var i=0;i<r.count;i++)r.glText[i].update(t)},r.draw=function(){for(var t=r.count,e=r.fill2d,i=r.error2d,a=r.line2d,o=r.scatter2d,s=r.glText,l=r.select2d,c=r.selectBatch,u=r.unselectBatch,f=0;f<t;f++){if(e&&r.fillOrder[f]&&e.draw(r.fillOrder[f]),a&&r.lineOptions[f]&&a.draw(f),i&&(r.errorXOptions[f]&&i.draw(f),r.errorYOptions[f]&&i.draw(f+t)),o&&r.markerOptions[f])if(u[f].length){var h=n.repeat([],r.count);h[f]=u[f],o.draw(h)}else c[f].length||o.draw(f);s[f]&&r.textOptions[f]&&s[f].render()}l&&l.draw(c),r.dirty=!1},r.destroy=function(){r.fill2d&&r.fill2d.destroy&&r.fill2d.destroy(),r.scatter2d&&r.scatter2d.destroy&&r.scatter2d.destroy(),r.error2d&&r.error2d.destroy&&r.error2d.destroy(),r.line2d&&r.line2d.destroy&&r.line2d.destroy(),r.select2d&&r.select2d.destroy&&r.select2d.destroy(),r.glText&&r.glText.forEach((function(t){t.destroy&&t.destroy()})),r.lineOptions=null,r.fillOptions=null,r.markerOptions=null,r.markerSelectedOptions=null,r.markerUnselectedOptions=null,r.errorXOptions=null,r.errorYOptions=null,r.textOptions=null,r.textSelectedOptions=null,r.textUnselectedOptions=null,r.selectBatch=null,r.unselectBatch=null,e._scene=null}),r.dirty||n.extendFlat(r,i),r}},{"../../lib":503}],992:[function(t,e,r){"use strict";var n=t("../scatter/subtypes"),i=t("./edit_style").styleTextSelection;e.exports=function(t,e){var r=t.cd,a=t.xaxis,o=t.yaxis,s=[],l=r[0].trace,c=r[0].t,u=l._length,f=c.x,h=c.y,p=c._scene,d=c.index;if(!p)return s;var m=n.hasText(l),g=n.hasMarkers(l),v=!g&&!m;if(!0!==l.visible||v)return s;var y=[],x=[];if(!1!==e&&!e.degenerate)for(var b=0;b<u;b++)e.contains([c.xpx[b],c.ypx[b]],!1,b,t)?(y.push(b),s.push({pointNumber:b,x:a.c2d(f[b]),y:o.c2d(h[b])})):x.push(b);if(g){var _=p.scatter2d;if(y.length||x.length){if(!p.selectBatch[d].length&&!p.unselectBatch[d].length){var w=new Array(p.count);w[d]=p.markerUnselectedOptions[d],_.update.apply(_,w)}}else{var T=new Array(p.count);T[d]=p.markerOptions[d],_.update.apply(_,T)}}return p.selectBatch[d]=y,p.unselectBatch[d]=x,m&&i(r),s}},{"../scatter/subtypes":952,"./edit_style":985}],993:[function(t,e,r){"use strict";var n=t("../../plots/template_attributes").hovertemplateAttrs,i=t("../../plots/template_attributes").texttemplateAttrs,a=t("../scattergeo/attributes"),o=t("../scatter/attributes"),s=t("../../plots/mapbox/layout_attributes"),l=t("../../plots/attributes"),c=t("../../components/colorscale/attributes"),u=t("../../lib/extend").extendFlat,f=t("../../plot_api/edit_types").overrideAll,h=a.line,p=a.marker;e.exports=f({lon:a.lon,lat:a.lat,mode:u({},o.mode,{dflt:"markers"}),text:u({},o.text,{}),texttemplate:i({editType:"plot"},{keys:["lat","lon","text"]}),hovertext:u({},o.hovertext,{}),line:{color:h.color,width:h.width},connectgaps:o.connectgaps,marker:u({symbol:{valType:"string",dflt:"circle",arrayOk:!0},angle:{valType:"number",dflt:"auto",arrayOk:!0},allowoverlap:{valType:"boolean",dflt:!1},opacity:p.opacity,size:p.size,sizeref:p.sizeref,sizemin:p.sizemin,sizemode:p.sizemode},c("marker")),fill:a.fill,fillcolor:o.fillcolor,textfont:s.layers.symbol.textfont,textposition:s.layers.symbol.textposition,below:{valType:"string"},selected:{marker:o.selected.marker},unselected:{marker:o.unselected.marker},hoverinfo:u({},l.hoverinfo,{flags:["lon","lat","text","name"]}),hovertemplate:n()},"calc","nested")},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plot_api/edit_types":536,"../../plots/attributes":550,"../../plots/mapbox/layout_attributes":615,"../../plots/template_attributes":633,"../scatter/attributes":927,"../scattergeo/attributes":969}],994:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../lib"),a=t("../../constants/numerical").BADNUM,o=t("../../lib/geojson_utils"),s=t("../../components/colorscale"),l=t("../../components/drawing"),c=t("../scatter/make_bubble_size_func"),u=t("../scatter/subtypes"),f=t("../../plots/mapbox/convert_text_opts"),h=t("../../components/fx/helpers").appendArrayPointValue,p=t("../../lib/svg_text_utils").NEWLINES,d=t("../../lib/svg_text_utils").BR_TAG_ALL;function m(){return{geojson:o.makeBlank(),layout:{visibility:"none"},paint:{}}}function g(t,e){return i.isArrayOrTypedArray(t)?e?function(e){return n(t[e])?+t[e]:0}:function(e){return t[e]}:t?function(){return t}:v}function v(){return""}function y(t){return t[0]===a}e.exports=function(t,e){var r,a=e[0].trace,x=!0===a.visible&&0!==a._length,b="none"!==a.fill,_=u.hasLines(a),w=u.hasMarkers(a),T=u.hasText(a),k=w&&"circle"===a.marker.symbol,A=w&&"circle"!==a.marker.symbol,M=m(),S=m(),E=m(),L=m(),C={fill:M,line:S,circle:E,symbol:L};if(!x)return C;if((b||_)&&(r=o.calcTraceToLineCoords(e)),b&&(M.geojson=o.makePolygon(r),M.layout.visibility="visible",i.extendFlat(M.paint,{"fill-color":a.fillcolor})),_&&(S.geojson=o.makeLine(r),S.layout.visibility="visible",i.extendFlat(S.paint,{"line-width":a.line.width,"line-color":a.line.color,"line-opacity":a.opacity})),k){var P=function(t){var e,r,a,o,u=t[0].trace,f=u.marker,h=u.selectedpoints,p=i.isArrayOrTypedArray(f.color),d=i.isArrayOrTypedArray(f.size),m=i.isArrayOrTypedArray(f.opacity);function g(t){return u.opacity*t}p&&(r=s.hasColorscale(u,"marker")?s.makeColorScaleFuncFromTrace(f):i.identity);d&&(a=c(u));m&&(o=function(t){return g(n(t)?+i.constrain(t,0,1):0)});var v,x=[];for(e=0;e<t.length;e++){var b=t[e],_=b.lonlat;if(!y(_)){var w={};r&&(w.mcc=b.mcc=r(b.mc)),a&&(w.mrc=b.mrc=a(b.ms)),o&&(w.mo=o(b.mo)),h&&(w.selected=b.selected||0),x.push({type:"Feature",geometry:{type:"Point",coordinates:_},properties:w})}}if(h)for(v=l.makeSelectedPointStyleFns(u),e=0;e<x.length;e++){var T=x[e].properties;v.selectedOpacityFn&&(T.mo=g(v.selectedOpacityFn(T))),v.selectedColorFn&&(T.mcc=v.selectedColorFn(T)),v.selectedSizeFn&&(T.mrc=v.selectedSizeFn(T))}return{geojson:{type:"FeatureCollection",features:x},mcc:p||v&&v.selectedColorFn?{type:"identity",property:"mcc"}:f.color,mrc:d||v&&v.selectedSizeFn?{type:"identity",property:"mrc"}:(k=f.size,k/2),mo:m||v&&v.selectedOpacityFn?{type:"identity",property:"mo"}:g(f.opacity)};var k}(e);E.geojson=P.geojson,E.layout.visibility="visible",i.extendFlat(E.paint,{"circle-color":P.mcc,"circle-radius":P.mrc,"circle-opacity":P.mo})}if((A||T)&&(L.geojson=function(t,e){for(var r=e._fullLayout,n=t[0].trace,a=n.marker||{},o=a.symbol,s=a.angle,l="circle"!==o?g(o):v,c="auto"!==s?g(s,!0):v,f=u.hasText(n)?g(n.text):v,m=[],x=0;x<t.length;x++){var b=t[x];if(!y(b.lonlat)){var _,w=n.texttemplate;if(w){var T=Array.isArray(w)?w[x]||"":w,k=n._module.formatLabels(b,n,r),A={};h(A,n,b.i);var M=n._meta||{};_=i.texttemplateString(T,k,r._d3locale,A,b,M)}else _=f(x);_&&(_=_.replace(p,"").replace(d,"\n")),m.push({type:"Feature",geometry:{type:"Point",coordinates:b.lonlat},properties:{symbol:l(x),angle:c(x),text:_}})}}return{type:"FeatureCollection",features:m}}(e,t),i.extendFlat(L.layout,{visibility:"visible","icon-image":"{symbol}-15","text-field":"{text}"}),A&&(i.extendFlat(L.layout,{"icon-size":a.marker.size/10}),"angle"in a.marker&&"auto"!==a.marker.angle&&i.extendFlat(L.layout,{"icon-rotate":{type:"identity",property:"angle"},"icon-rotation-alignment":"map"}),L.layout["icon-allow-overlap"]=a.marker.allowoverlap,i.extendFlat(L.paint,{"icon-opacity":a.opacity*a.marker.opacity,"icon-color":a.marker.color})),T)){var I=(a.marker||{}).size,O=f(a.textposition,I);i.extendFlat(L.layout,{"text-size":a.textfont.size,"text-anchor":O.anchor,"text-offset":O.offset}),i.extendFlat(L.paint,{"text-color":a.textfont.color,"text-opacity":a.opacity})}return C}},{"../../components/colorscale":378,"../../components/drawing":388,"../../components/fx/helpers":402,"../../constants/numerical":479,"../../lib":503,"../../lib/geojson_utils":497,"../../lib/svg_text_utils":529,"../../plots/mapbox/convert_text_opts":612,"../scatter/make_bubble_size_func":944,"../scatter/subtypes":952,"fast-isnumeric":190}],995:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../scatter/subtypes"),a=t("../scatter/marker_defaults"),o=t("../scatter/line_defaults"),s=t("../scatter/text_defaults"),l=t("../scatter/fillcolor_defaults"),c=t("./attributes");e.exports=function(t,e,r,u){function f(r,i){return n.coerce(t,e,c,r,i)}if(function(t,e,r){var n=r("lon")||[],i=r("lat")||[],a=Math.min(n.length,i.length);return e._length=a,a}(0,e,f)){if(f("text"),f("texttemplate"),f("hovertext"),f("hovertemplate"),f("mode"),f("below"),i.hasLines(e)&&(o(t,e,r,u,f,{noDash:!0}),f("connectgaps")),i.hasMarkers(e)){a(t,e,r,u,f,{noLine:!0}),f("marker.allowoverlap"),f("marker.angle");var h=e.marker;"circle"!==h.symbol&&(n.isArrayOrTypedArray(h.size)&&(h.size=h.size[0]),n.isArrayOrTypedArray(h.color)&&(h.color=h.color[0]))}i.hasText(e)&&s(t,e,u,f,{noSelect:!0}),f("fill"),"none"!==e.fill&&l(t,e,r,f),n.coerceSelectionMarkerOpacity(e,f)}else e.visible=!1}},{"../../lib":503,"../scatter/fillcolor_defaults":935,"../scatter/line_defaults":940,"../scatter/marker_defaults":946,"../scatter/subtypes":952,"../scatter/text_defaults":953,"./attributes":993}],996:[function(t,e,r){"use strict";e.exports=function(t,e){return t.lon=e.lon,t.lat=e.lat,t}},{}],997:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes");e.exports=function(t,e,r){var i={},a=r[e.subplot]._subplot.mockAxis,o=t.lonlat;return i.lonLabel=n.tickText(a,a.c2l(o[0]),!0).text,i.latLabel=n.tickText(a,a.c2l(o[1]),!0).text,i}},{"../../plots/cartesian/axes":554}],998:[function(t,e,r){"use strict";var n=t("../../components/fx"),i=t("../../lib"),a=t("../scatter/get_trace_color"),o=i.fillText,s=t("../../constants/numerical").BADNUM;function l(t,e,r){if(!t.hovertemplate){var n=(e.hi||t.hoverinfo).split("+"),i=-1!==n.indexOf("all"),a=-1!==n.indexOf("lon"),s=-1!==n.indexOf("lat"),l=e.lonlat,c=[];return i||a&&s?c.push("("+u(l[1])+", "+u(l[0])+")"):a?c.push(r.lon+u(l[0])):s&&c.push(r.lat+u(l[1])),(i||-1!==n.indexOf("text"))&&o(e,t,c),c.join("<br>")}function u(t){return t+"\xb0"}}e.exports={hoverPoints:function(t,e,r){var o=t.cd,c=o[0].trace,u=t.xa,f=t.ya,h=t.subplot,p=360*(e>=0?Math.floor((e+180)/360):Math.ceil((e-180)/360)),d=e-p;if(n.getClosest(o,(function(t){var e=t.lonlat;if(e[0]===s)return 1/0;var n=i.modHalf(e[0],360),a=e[1],o=h.project([n,a]),l=o.x-u.c2p([d,a]),c=o.y-f.c2p([n,r]),p=Math.max(3,t.mrc||0);return Math.max(Math.sqrt(l*l+c*c)-p,1-3/p)}),t),!1!==t.index){var m=o[t.index],g=m.lonlat,v=[i.modHalf(g[0],360)+p,g[1]],y=u.c2p(v),x=f.c2p(v),b=m.mrc||1;t.x0=y-b,t.x1=y+b,t.y0=x-b,t.y1=x+b;var _={};_[c.subplot]={_subplot:h};var w=c._module.formatLabels(m,c,_);return t.lonLabel=w.lonLabel,t.latLabel=w.latLabel,t.color=a(c,m),t.extraText=l(c,m,o[0].t.labels),t.hovertemplate=c.hovertemplate,[t]}},getExtraText:l}},{"../../components/fx":406,"../../constants/numerical":479,"../../lib":503,"../scatter/get_trace_color":937}],999:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:t("../scatter/marker_colorbar"),formatLabels:t("./format_labels"),calc:t("../scattergeo/calc"),plot:t("./plot"),hoverPoints:t("./hover").hoverPoints,eventData:t("./event_data"),selectPoints:t("./select"),styleOnSelect:function(t,e){e&&e[0].trace._glTrace.update(e)},moduleType:"trace",name:"scattermapbox",basePlotModule:t("../../plots/mapbox"),categories:["mapbox","gl","symbols","showLegend","scatter-like"],meta:{}}},{"../../plots/mapbox":613,"../scatter/marker_colorbar":945,"../scattergeo/calc":970,"./attributes":993,"./defaults":995,"./event_data":996,"./format_labels":997,"./hover":998,"./plot":1e3,"./select":1001}],1e3:[function(t,e,r){"use strict";var n=t("./convert"),i=t("../../plots/mapbox/constants").traceLayerPrefix,a=["fill","line","circle","symbol"];function o(t,e){this.type="scattermapbox",this.subplot=t,this.uid=e,this.sourceIds={fill:"source-"+e+"-fill",line:"source-"+e+"-line",circle:"source-"+e+"-circle",symbol:"source-"+e+"-symbol"},this.layerIds={fill:i+e+"-fill",line:i+e+"-line",circle:i+e+"-circle",symbol:i+e+"-symbol"},this.below=null}var s=o.prototype;s.addSource=function(t,e){this.subplot.map.addSource(this.sourceIds[t],{type:"geojson",data:e.geojson})},s.setSourceData=function(t,e){this.subplot.map.getSource(this.sourceIds[t]).setData(e.geojson)},s.addLayer=function(t,e,r){this.subplot.addLayer({type:t,id:this.layerIds[t],source:this.sourceIds[t],layout:e.layout,paint:e.paint},r)},s.update=function(t){var e,r,i,o=this.subplot,s=o.map,l=n(o.gd,t),c=o.belowLookup["trace-"+this.uid];if(c!==this.below){for(e=a.length-1;e>=0;e--)r=a[e],s.removeLayer(this.layerIds[r]);for(e=0;e<a.length;e++)i=l[r=a[e]],this.addLayer(r,i,c);this.below=c}for(e=0;e<a.length;e++)i=l[r=a[e]],o.setOptions(this.layerIds[r],"setLayoutProperty",i.layout),"visible"===i.layout.visibility&&(this.setSourceData(r,i),o.setOptions(this.layerIds[r],"setPaintProperty",i.paint));t[0].trace._glTrace=this},s.dispose=function(){for(var t=this.subplot.map,e=a.length-1;e>=0;e--){var r=a[e];t.removeLayer(this.layerIds[r]),t.removeSource(this.sourceIds[r])}},e.exports=function(t,e){for(var r=e[0].trace,i=new o(t,r.uid),s=n(t.gd,e),l=i.below=t.belowLookup["trace-"+r.uid],c=0;c<a.length;c++){var u=a[c],f=s[u];i.addSource(u,f),i.addLayer(u,f,l)}return e[0].trace._glTrace=i,i}},{"../../plots/mapbox/constants":611,"./convert":994}],1001:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../scatter/subtypes"),a=t("../../constants/numerical").BADNUM;e.exports=function(t,e){var r,o=t.cd,s=t.xaxis,l=t.yaxis,c=[],u=o[0].trace;if(!i.hasMarkers(u))return[];if(!1===e)for(r=0;r<o.length;r++)o[r].selected=0;else for(r=0;r<o.length;r++){var f=o[r],h=f.lonlat;if(h[0]!==a){var p=[n.modHalf(h[0],360),h[1]],d=[s.c2p(p),l.c2p(p)];e.contains(d,null,r,t)?(c.push({pointNumber:r,lon:h[0],lat:h[1]}),f.selected=1):f.selected=0}}return c}},{"../../constants/numerical":479,"../../lib":503,"../scatter/subtypes":952}],1002:[function(t,e,r){"use strict";var n=t("../../plots/template_attributes").hovertemplateAttrs,i=t("../../plots/template_attributes").texttemplateAttrs,a=t("../../lib/extend").extendFlat,o=t("../scatter/attributes"),s=t("../../plots/attributes"),l=o.line;e.exports={mode:o.mode,r:{valType:"data_array",editType:"calc+clearAxisTypes"},theta:{valType:"data_array",editType:"calc+clearAxisTypes"},r0:{valType:"any",dflt:0,editType:"calc+clearAxisTypes"},dr:{valType:"number",dflt:1,editType:"calc"},theta0:{valType:"any",dflt:0,editType:"calc+clearAxisTypes"},dtheta:{valType:"number",editType:"calc"},thetaunit:{valType:"enumerated",values:["radians","degrees","gradians"],dflt:"degrees",editType:"calc+clearAxisTypes"},text:o.text,texttemplate:i({editType:"plot"},{keys:["r","theta","text"]}),hovertext:o.hovertext,line:{color:l.color,width:l.width,dash:l.dash,shape:a({},l.shape,{values:["linear","spline"]}),smoothing:l.smoothing,editType:"calc"},connectgaps:o.connectgaps,marker:o.marker,cliponaxis:a({},o.cliponaxis,{dflt:!1}),textposition:o.textposition,textfont:o.textfont,fill:a({},o.fill,{values:["none","toself","tonext"],dflt:"none"}),fillcolor:o.fillcolor,hoverinfo:a({},s.hoverinfo,{flags:["r","theta","text","name"]}),hoveron:o.hoveron,hovertemplate:n(),selected:o.selected,unselected:o.unselected}},{"../../lib/extend":493,"../../plots/attributes":550,"../../plots/template_attributes":633,"../scatter/attributes":927}],1003:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../constants/numerical").BADNUM,a=t("../../plots/cartesian/axes"),o=t("../scatter/colorscale_calc"),s=t("../scatter/arrays_to_calcdata"),l=t("../scatter/calc_selection"),c=t("../scatter/calc").calcMarkerSize;e.exports=function(t,e){for(var r=t._fullLayout,u=e.subplot,f=r[u].radialaxis,h=r[u].angularaxis,p=f.makeCalcdata(e,"r"),d=h.makeCalcdata(e,"theta"),m=e._length,g=new Array(m),v=0;v<m;v++){var y=p[v],x=d[v],b=g[v]={};n(y)&&n(x)?(b.r=y,b.theta=x):b.r=i}var _=c(e,m);return e._extremes.x=a.findExtremes(f,p,{ppad:_}),o(t,e),s(g,e),l(g,e),g}},{"../../constants/numerical":479,"../../plots/cartesian/axes":554,"../scatter/arrays_to_calcdata":926,"../scatter/calc":928,"../scatter/calc_selection":929,"../scatter/colorscale_calc":930,"fast-isnumeric":190}],1004:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../scatter/subtypes"),a=t("../scatter/marker_defaults"),o=t("../scatter/line_defaults"),s=t("../scatter/line_shape_defaults"),l=t("../scatter/text_defaults"),c=t("../scatter/fillcolor_defaults"),u=t("../scatter/constants").PTS_LINESONLY,f=t("./attributes");function h(t,e,r,n){var i,a=n("r"),o=n("theta");if(a)o?i=Math.min(a.length,o.length):(i=a.length,n("theta0"),n("dtheta"));else{if(!o)return 0;i=e.theta.length,n("r0"),n("dr")}return e._length=i,i}e.exports={handleRThetaDefaults:h,supplyDefaults:function(t,e,r,p){function d(r,i){return n.coerce(t,e,f,r,i)}var m=h(t,e,p,d);if(m){d("thetaunit"),d("mode",m<u?"lines+markers":"lines"),d("text"),d("hovertext"),"fills"!==e.hoveron&&d("hovertemplate"),i.hasLines(e)&&(o(t,e,r,p,d),s(t,e,d),d("connectgaps")),i.hasMarkers(e)&&a(t,e,r,p,d,{gradient:!0}),i.hasText(e)&&(d("texttemplate"),l(t,e,p,d));var g=[];(i.hasMarkers(e)||i.hasText(e))&&(d("cliponaxis"),d("marker.maxdisplayed"),g.push("points")),d("fill"),"none"!==e.fill&&(c(t,e,r,d),i.hasLines(e)||s(t,e,d)),"tonext"!==e.fill&&"toself"!==e.fill||g.push("fills"),d("hoveron",g.join("+")||"points"),n.coerceSelectionMarkerOpacity(e,d)}else e.visible=!1}}},{"../../lib":503,"../scatter/constants":931,"../scatter/fillcolor_defaults":935,"../scatter/line_defaults":940,"../scatter/line_shape_defaults":942,"../scatter/marker_defaults":946,"../scatter/subtypes":952,"../scatter/text_defaults":953,"./attributes":1002}],1005:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axes");e.exports=function(t,e,r){var a,o,s={},l=r[e.subplot]._subplot;l?(a=l.radialAxis,o=l.angularAxis):(a=(l=r[e.subplot]).radialaxis,o=l.angularaxis);var c=a.c2l(t.r);s.rLabel=i.tickText(a,c,!0).text;var u="degrees"===o.thetaunit?n.rad2deg(t.theta):t.theta;return s.thetaLabel=i.tickText(o,u,!0).text,s}},{"../../lib":503,"../../plots/cartesian/axes":554}],1006:[function(t,e,r){"use strict";var n=t("../scatter/hover");function i(t,e,r,n){var i=r.radialAxis,a=r.angularAxis;i._hovertitle="r",a._hovertitle="\u03b8";var o={};o[e.subplot]={_subplot:r};var s=e._module.formatLabels(t,e,o);n.rLabel=s.rLabel,n.thetaLabel=s.thetaLabel;var l=t.hi||e.hoverinfo,c=[];function u(t,e){c.push(t._hovertitle+": "+e)}if(!e.hovertemplate){var f=l.split("+");-1!==f.indexOf("all")&&(f=["r","theta","text"]),-1!==f.indexOf("r")&&u(i,n.rLabel),-1!==f.indexOf("theta")&&u(a,n.thetaLabel),-1!==f.indexOf("text")&&n.text&&(c.push(n.text),delete n.text),n.extraText=c.join("<br>")}}e.exports={hoverPoints:function(t,e,r,a){var o=n(t,e,r,a);if(o&&!1!==o[0].index){var s=o[0];if(void 0===s.index)return o;var l=t.subplot,c=s.cd[s.index],u=s.trace;if(l.isPtInside(c))return s.xLabelVal=void 0,s.yLabelVal=void 0,i(c,u,l,s),s.hovertemplate=u.hovertemplate,o}},makeHoverPointText:i}},{"../scatter/hover":938}],1007:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"scatterpolar",basePlotModule:t("../../plots/polar"),categories:["polar","symbols","showLegend","scatter-like"],attributes:t("./attributes"),supplyDefaults:t("./defaults").supplyDefaults,colorbar:t("../scatter/marker_colorbar"),formatLabels:t("./format_labels"),calc:t("./calc"),plot:t("./plot"),style:t("../scatter/style").style,styleOnSelect:t("../scatter/style").styleOnSelect,hoverPoints:t("./hover").hoverPoints,selectPoints:t("../scatter/select"),meta:{}}},{"../../plots/polar":622,"../scatter/marker_colorbar":945,"../scatter/select":949,"../scatter/style":951,"./attributes":1002,"./calc":1003,"./defaults":1004,"./format_labels":1005,"./hover":1006,"./plot":1008}],1008:[function(t,e,r){"use strict";var n=t("../scatter/plot"),i=t("../../constants/numerical").BADNUM;e.exports=function(t,e,r){for(var a=e.layers.frontplot.select("g.scatterlayer"),o={xaxis:e.xaxis,yaxis:e.yaxis,plot:e.framework,layerClipId:e._hasClipOnAxisFalse?e.clipIds.forTraces:null},s=e.radialAxis,l=e.angularAxis,c=0;c<r.length;c++)for(var u=r[c],f=0;f<u.length;f++){var h=u[f],p=h.r;if(p===i)h.x=h.y=i;else{var d=s.c2g(p),m=l.c2g(h.theta);h.x=d*Math.cos(m),h.y=d*Math.sin(m)}}n(t,o,r,a)}},{"../../constants/numerical":479,"../scatter/plot":948}],1009:[function(t,e,r){"use strict";var n=t("../scatterpolar/attributes"),i=t("../scattergl/attributes"),a=t("../../plots/template_attributes").texttemplateAttrs;e.exports={mode:n.mode,r:n.r,theta:n.theta,r0:n.r0,dr:n.dr,theta0:n.theta0,dtheta:n.dtheta,thetaunit:n.thetaunit,text:n.text,texttemplate:a({editType:"plot"},{keys:["r","theta","text"]}),hovertext:n.hovertext,hovertemplate:n.hovertemplate,line:i.line,connectgaps:i.connectgaps,marker:i.marker,fill:i.fill,fillcolor:i.fillcolor,textposition:i.textposition,textfont:i.textfont,hoverinfo:n.hoverinfo,selected:n.selected,unselected:n.unselected}},{"../../plots/template_attributes":633,"../scattergl/attributes":979,"../scatterpolar/attributes":1002}],1010:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"scatterpolargl",basePlotModule:t("../../plots/polar"),categories:["gl","regl","polar","symbols","showLegend","scatter-like"],attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:t("../scatter/marker_colorbar"),formatLabels:t("./format_labels"),calc:t("./calc"),hoverPoints:t("./hover").hoverPoints,selectPoints:t("../scattergl/select"),meta:{}}},{"../../plots/polar":622,"../scatter/marker_colorbar":945,"../scattergl/select":992,"./attributes":1009,"./calc":1011,"./defaults":1012,"./format_labels":1013,"./hover":1014}],1011:[function(t,e,r){"use strict";var n=t("../scatter/colorscale_calc"),i=t("../scatter/calc").calcMarkerSize,a=t("../scattergl/convert"),o=t("../../plots/cartesian/axes"),s=t("../scattergl/constants").TOO_MANY_POINTS;e.exports=function(t,e){var r=t._fullLayout,l=e.subplot,c=r[l].radialaxis,u=r[l].angularaxis,f=e._r=c.makeCalcdata(e,"r"),h=e._theta=u.makeCalcdata(e,"theta"),p=e._length,d={};p<f.length&&(f=f.slice(0,p)),p<h.length&&(h=h.slice(0,p)),d.r=f,d.theta=h,n(t,e);var m,g=d.opts=a.style(t,e);return p<s?m=i(e,p):g.marker&&(m=2*(g.marker.sizeAvg||Math.max(g.marker.size,3))),e._extremes.x=o.findExtremes(c,f,{ppad:m}),[{x:!1,y:!1,t:d,trace:e}]}},{"../../plots/cartesian/axes":554,"../scatter/calc":928,"../scatter/colorscale_calc":930,"../scattergl/constants":982,"../scattergl/convert":983}],1012:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../scatter/subtypes"),a=t("../scatterpolar/defaults").handleRThetaDefaults,o=t("../scatter/marker_defaults"),s=t("../scatter/line_defaults"),l=t("../scatter/text_defaults"),c=t("../scatter/fillcolor_defaults"),u=t("../scatter/constants").PTS_LINESONLY,f=t("./attributes");e.exports=function(t,e,r,h){function p(r,i){return n.coerce(t,e,f,r,i)}var d=a(t,e,h,p);d?(p("thetaunit"),p("mode",d<u?"lines+markers":"lines"),p("text"),p("hovertext"),"fills"!==e.hoveron&&p("hovertemplate"),i.hasLines(e)&&(s(t,e,r,h,p),p("connectgaps")),i.hasMarkers(e)&&o(t,e,r,h,p),i.hasText(e)&&(p("texttemplate"),l(t,e,h,p)),p("fill"),"none"!==e.fill&&c(t,e,r,p),n.coerceSelectionMarkerOpacity(e,p)):e.visible=!1}},{"../../lib":503,"../scatter/constants":931,"../scatter/fillcolor_defaults":935,"../scatter/line_defaults":940,"../scatter/marker_defaults":946,"../scatter/subtypes":952,"../scatter/text_defaults":953,"../scatterpolar/defaults":1004,"./attributes":1009}],1013:[function(t,e,r){"use strict";var n=t("../scatterpolar/format_labels");e.exports=function(t,e,r){var i=t.i;return"r"in t||(t.r=e._r[i]),"theta"in t||(t.theta=e._theta[i]),n(t,e,r)}},{"../scatterpolar/format_labels":1005}],1014:[function(t,e,r){"use strict";var n=t("../scattergl/hover"),i=t("../scatterpolar/hover").makeHoverPointText;e.exports={hoverPoints:function(t,e,r,a){var o=t.cd[0].t,s=o.r,l=o.theta,c=n.hoverPoints(t,e,r,a);if(c&&!1!==c[0].index){var u=c[0];if(void 0===u.index)return c;var f=t.subplot,h=u.cd[u.index],p=u.trace;if(h.r=s[u.index],h.theta=l[u.index],f.isPtInside(h))return u.xLabelVal=void 0,u.yLabelVal=void 0,i(h,p,f,u),c}}}},{"../scattergl/hover":988,"../scatterpolar/hover":1006}],1015:[function(t,e,r){arguments[4][896][0].apply(r,arguments)},{"./base_index":1010,"./plot":1016,dup:896}],1016:[function(t,e,r){"use strict";var n=t("@plotly/point-cluster"),i=t("fast-isnumeric"),a=t("../scattergl/plot"),o=t("../scattergl/scene_update"),s=t("../scattergl/convert"),l=t("../../lib"),c=t("../scattergl/constants").TOO_MANY_POINTS;e.exports=function(t,e,r){if(r.length){var u=e.radialAxis,f=e.angularAxis,h=o(t,e);return r.forEach((function(r){if(r&&r[0]&&r[0].trace){var a,o=r[0],p=o.trace,d=o.t,m=p._length,g=d.r,v=d.theta,y=d.opts,x=g.slice(),b=v.slice();for(a=0;a<g.length;a++)e.isPtInside({r:g[a],theta:v[a]})||(x[a]=NaN,b[a]=NaN);var _=new Array(2*m),w=Array(m),T=Array(m);for(a=0;a<m;a++){var k,A,M=x[a];if(i(M)){var S=u.c2g(M),E=f.c2g(b[a],p.thetaunit);k=S*Math.cos(E),A=S*Math.sin(E)}else k=A=NaN;w[a]=_[2*a]=k,T[a]=_[2*a+1]=A}d.tree=n(_),y.marker&&m>=c&&(y.marker.cluster=d.tree),y.marker&&(y.markerSel.positions=y.markerUnsel.positions=y.marker.positions=_),y.line&&_.length>1&&l.extendFlat(y.line,s.linePositions(t,p,_)),y.text&&(l.extendFlat(y.text,{positions:_},s.textPosition(t,p,y.text,y.marker)),l.extendFlat(y.textSel,{positions:_},s.textPosition(t,p,y.text,y.markerSel)),l.extendFlat(y.textUnsel,{positions:_},s.textPosition(t,p,y.text,y.markerUnsel))),y.fill&&!h.fill2d&&(h.fill2d=!0),y.marker&&!h.scatter2d&&(h.scatter2d=!0),y.line&&!h.line2d&&(h.line2d=!0),y.text&&!h.glText&&(h.glText=!0),h.lineOptions.push(y.line),h.fillOptions.push(y.fill),h.markerOptions.push(y.marker),h.markerSelectedOptions.push(y.markerSel),h.markerUnselectedOptions.push(y.markerUnsel),h.textOptions.push(y.text),h.textSelectedOptions.push(y.textSel),h.textUnselectedOptions.push(y.textUnsel),h.selectBatch.push([]),h.unselectBatch.push([]),d.x=w,d.y=T,d.rawx=w,d.rawy=T,d.r=g,d.theta=v,d.positions=_,d._scene=h,d.index=h.count,h.count++}})),a(t,e,r)}},e.exports.reglPrecompiled={}},{"../../lib":503,"../scattergl/constants":982,"../scattergl/convert":983,"../scattergl/plot":990,"../scattergl/scene_update":991,"@plotly/point-cluster":59,"fast-isnumeric":190}],1017:[function(t,e,r){"use strict";var n=t("../../plots/template_attributes").hovertemplateAttrs,i=t("../../plots/template_attributes").texttemplateAttrs,a=t("../../lib/extend").extendFlat,o=t("../scatter/attributes"),s=t("../../plots/attributes"),l=o.line;e.exports={mode:o.mode,real:{valType:"data_array",editType:"calc+clearAxisTypes"},imag:{valType:"data_array",editType:"calc+clearAxisTypes"},text:o.text,texttemplate:i({editType:"plot"},{keys:["real","imag","text"]}),hovertext:o.hovertext,line:{color:l.color,width:l.width,dash:l.dash,shape:a({},l.shape,{values:["linear","spline"]}),smoothing:l.smoothing,editType:"calc"},connectgaps:o.connectgaps,marker:o.marker,cliponaxis:a({},o.cliponaxis,{dflt:!1}),textposition:o.textposition,textfont:o.textfont,fill:a({},o.fill,{values:["none","toself","tonext"],dflt:"none"}),fillcolor:o.fillcolor,hoverinfo:a({},s.hoverinfo,{flags:["real","imag","text","name"]}),hoveron:o.hoveron,hovertemplate:n(),selected:o.selected,unselected:o.unselected}},{"../../lib/extend":493,"../../plots/attributes":550,"../../plots/template_attributes":633,"../scatter/attributes":927}],1018:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../../constants/numerical").BADNUM,a=t("../scatter/colorscale_calc"),o=t("../scatter/arrays_to_calcdata"),s=t("../scatter/calc_selection"),l=t("../scatter/calc").calcMarkerSize;e.exports=function(t,e){for(var r=t._fullLayout,c=e.subplot,u=r[c].realaxis,f=r[c].imaginaryaxis,h=u.makeCalcdata(e,"real"),p=f.makeCalcdata(e,"imag"),d=e._length,m=new Array(d),g=0;g<d;g++){var v=h[g],y=p[g],x=m[g]={};n(v)&&n(y)?(x.real=v,x.imag=y):x.real=i}return l(e,d),a(t,e),o(m,e),s(m,e),m}},{"../../constants/numerical":479,"../scatter/arrays_to_calcdata":926,"../scatter/calc":928,"../scatter/calc_selection":929,"../scatter/colorscale_calc":930,"fast-isnumeric":190}],1019:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../scatter/subtypes"),a=t("../scatter/marker_defaults"),o=t("../scatter/line_defaults"),s=t("../scatter/line_shape_defaults"),l=t("../scatter/text_defaults"),c=t("../scatter/fillcolor_defaults"),u=t("../scatter/constants").PTS_LINESONLY,f=t("./attributes");e.exports=function(t,e,r,h){function p(r,i){return n.coerce(t,e,f,r,i)}var d=function(t,e,r,n){var i,a=n("real"),o=n("imag");a&&o&&(i=Math.min(a.length,o.length));return e._length=i,i}(0,e,0,p);if(d){p("mode",d<u?"lines+markers":"lines"),p("text"),p("hovertext"),"fills"!==e.hoveron&&p("hovertemplate"),i.hasLines(e)&&(o(t,e,r,h,p),s(t,e,p),p("connectgaps")),i.hasMarkers(e)&&a(t,e,r,h,p,{gradient:!0}),i.hasText(e)&&(p("texttemplate"),l(t,e,h,p));var m=[];(i.hasMarkers(e)||i.hasText(e))&&(p("cliponaxis"),p("marker.maxdisplayed"),m.push("points")),p("fill"),"none"!==e.fill&&(c(t,e,r,p),i.hasLines(e)||s(t,e,p)),"tonext"!==e.fill&&"toself"!==e.fill||m.push("fills"),p("hoveron",m.join("+")||"points"),n.coerceSelectionMarkerOpacity(e,p)}else e.visible=!1}},{"../../lib":503,"../scatter/constants":931,"../scatter/fillcolor_defaults":935,"../scatter/line_defaults":940,"../scatter/line_shape_defaults":942,"../scatter/marker_defaults":946,"../scatter/subtypes":952,"../scatter/text_defaults":953,"./attributes":1017}],1020:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes");e.exports=function(t,e,r){var i={},a=r[e.subplot]._subplot;return i.realLabel=n.tickText(a.radialAxis,t.real,!0).text,i.imagLabel=n.tickText(a.angularAxis,t.imag,!0).text,i}},{"../../plots/cartesian/axes":554}],1021:[function(t,e,r){"use strict";var n=t("../scatter/hover");function i(t,e,r,n){var i=r.radialAxis,a=r.angularAxis;i._hovertitle="real",a._hovertitle="imag";var o={};o[e.subplot]={_subplot:r};var s=e._module.formatLabels(t,e,o);n.realLabel=s.realLabel,n.imagLabel=s.imagLabel;var l=t.hi||e.hoverinfo,c=[];function u(t,e){c.push(t._hovertitle+": "+e)}if(!e.hovertemplate){var f=l.split("+");-1!==f.indexOf("all")&&(f=["real","imag","text"]),-1!==f.indexOf("real")&&u(i,n.realLabel),-1!==f.indexOf("imag")&&u(a,n.imagLabel),-1!==f.indexOf("text")&&n.text&&(c.push(n.text),delete n.text),n.extraText=c.join("<br>")}}e.exports={hoverPoints:function(t,e,r,a){var o=n(t,e,r,a);if(o&&!1!==o[0].index){var s=o[0];if(void 0===s.index)return o;var l=t.subplot,c=s.cd[s.index],u=s.trace;if(l.isPtInside(c))return s.xLabelVal=void 0,s.yLabelVal=void 0,i(c,u,l,s),s.hovertemplate=u.hovertemplate,o}},makeHoverPointText:i}},{"../scatter/hover":938}],1022:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"scattersmith",basePlotModule:t("../../plots/smith"),categories:["smith","symbols","showLegend","scatter-like"],attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:t("../scatter/marker_colorbar"),formatLabels:t("./format_labels"),calc:t("./calc"),plot:t("./plot"),style:t("../scatter/style").style,styleOnSelect:t("../scatter/style").styleOnSelect,hoverPoints:t("./hover").hoverPoints,selectPoints:t("../scatter/select"),meta:{}}},{"../../plots/smith":629,"../scatter/marker_colorbar":945,"../scatter/select":949,"../scatter/style":951,"./attributes":1017,"./calc":1018,"./defaults":1019,"./format_labels":1020,"./hover":1021,"./plot":1023}],1023:[function(t,e,r){"use strict";var n=t("../scatter/plot"),i=t("../../constants/numerical").BADNUM,a=t("../../plots/smith/helpers").smith;e.exports=function(t,e,r){for(var o=e.layers.frontplot.select("g.scatterlayer"),s={xaxis:e.xaxis,yaxis:e.yaxis,plot:e.framework,layerClipId:e._hasClipOnAxisFalse?e.clipIds.forTraces:null},l=0;l<r.length;l++)for(var c=r[l],u=0;u<c.length;u++){var f=c[u],h=f.real;if(h===i)f.x=f.y=i;else{var p=a([h,f.imag]);f.x=p[0],f.y=p[1]}}n(t,s,r,o)}},{"../../constants/numerical":479,"../../plots/smith/helpers":628,"../scatter/plot":948}],1024:[function(t,e,r){"use strict";var n=t("../../plots/template_attributes").hovertemplateAttrs,i=t("../../plots/template_attributes").texttemplateAttrs,a=t("../scatter/attributes"),o=t("../../plots/attributes"),s=t("../../components/colorscale/attributes"),l=t("../../components/drawing/attributes").dash,c=t("../../lib/extend").extendFlat,u=a.marker,f=a.line,h=u.line;e.exports={a:{valType:"data_array",editType:"calc"},b:{valType:"data_array",editType:"calc"},c:{valType:"data_array",editType:"calc"},sum:{valType:"number",dflt:0,min:0,editType:"calc"},mode:c({},a.mode,{dflt:"markers"}),text:c({},a.text,{}),texttemplate:i({editType:"plot"},{keys:["a","b","c","text"]}),hovertext:c({},a.hovertext,{}),line:{color:f.color,width:f.width,dash:l,shape:c({},f.shape,{values:["linear","spline"]}),smoothing:f.smoothing,editType:"calc"},connectgaps:a.connectgaps,cliponaxis:a.cliponaxis,fill:c({},a.fill,{values:["none","toself","tonext"],dflt:"none"}),fillcolor:a.fillcolor,marker:c({symbol:u.symbol,opacity:u.opacity,maxdisplayed:u.maxdisplayed,size:u.size,sizeref:u.sizeref,sizemin:u.sizemin,sizemode:u.sizemode,line:c({width:h.width,editType:"calc"},s("marker.line")),gradient:u.gradient,editType:"calc"},s("marker")),textfont:a.textfont,textposition:a.textposition,selected:a.selected,unselected:a.unselected,hoverinfo:c({},o.hoverinfo,{flags:["a","b","c","text","name"]}),hoveron:a.hoveron,hovertemplate:n()}},{"../../components/colorscale/attributes":373,"../../components/drawing/attributes":387,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/template_attributes":633,"../scatter/attributes":927}],1025:[function(t,e,r){"use strict";var n=t("fast-isnumeric"),i=t("../scatter/colorscale_calc"),a=t("../scatter/arrays_to_calcdata"),o=t("../scatter/calc_selection"),s=t("../scatter/calc").calcMarkerSize,l=["a","b","c"],c={a:["b","c"],b:["a","c"],c:["a","b"]};e.exports=function(t,e){var r,u,f,h,p,d,m=t._fullLayout[e.subplot].sum,g=e.sum||m,v={a:e.a,b:e.b,c:e.c};for(r=0;r<l.length;r++)if(!v[f=l[r]]){for(p=v[c[f][0]],d=v[c[f][1]],h=new Array(p.length),u=0;u<p.length;u++)h[u]=g-p[u]-d[u];v[f]=h}var y,x,b,_,w,T,k=e._length,A=new Array(k);for(r=0;r<k;r++)y=v.a[r],x=v.b[r],b=v.c[r],n(y)&&n(x)&&n(b)?(1!==(_=m/((y=+y)+(x=+x)+(b=+b)))&&(y*=_,x*=_,b*=_),T=y,w=b-x,A[r]={x:w,y:T,a:y,b:x,c:b}):A[r]={x:!1,y:!1};return s(e,k),i(t,e),a(A,e),o(A,e),A}},{"../scatter/arrays_to_calcdata":926,"../scatter/calc":928,"../scatter/calc_selection":929,"../scatter/colorscale_calc":930,"fast-isnumeric":190}],1026:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../scatter/constants"),a=t("../scatter/subtypes"),o=t("../scatter/marker_defaults"),s=t("../scatter/line_defaults"),l=t("../scatter/line_shape_defaults"),c=t("../scatter/text_defaults"),u=t("../scatter/fillcolor_defaults"),f=t("./attributes");e.exports=function(t,e,r,h){function p(r,i){return n.coerce(t,e,f,r,i)}var d,m=p("a"),g=p("b"),v=p("c");if(m?(d=m.length,g?(d=Math.min(d,g.length),v&&(d=Math.min(d,v.length))):d=v?Math.min(d,v.length):0):g&&v&&(d=Math.min(g.length,v.length)),d){e._length=d,p("sum"),p("text"),p("hovertext"),"fills"!==e.hoveron&&p("hovertemplate"),p("mode",d<i.PTS_LINESONLY?"lines+markers":"lines"),a.hasLines(e)&&(s(t,e,r,h,p),l(t,e,p),p("connectgaps")),a.hasMarkers(e)&&o(t,e,r,h,p,{gradient:!0}),a.hasText(e)&&(p("texttemplate"),c(t,e,h,p));var y=[];(a.hasMarkers(e)||a.hasText(e))&&(p("cliponaxis"),p("marker.maxdisplayed"),y.push("points")),p("fill"),"none"!==e.fill&&(u(t,e,r,p),a.hasLines(e)||l(t,e,p)),"tonext"!==e.fill&&"toself"!==e.fill||y.push("fills"),p("hoveron",y.join("+")||"points"),n.coerceSelectionMarkerOpacity(e,p)}else e.visible=!1}},{"../../lib":503,"../scatter/constants":931,"../scatter/fillcolor_defaults":935,"../scatter/line_defaults":940,"../scatter/line_shape_defaults":942,"../scatter/marker_defaults":946,"../scatter/subtypes":952,"../scatter/text_defaults":953,"./attributes":1024}],1027:[function(t,e,r){"use strict";e.exports=function(t,e,r,n,i){if(e.xa&&(t.xaxis=e.xa),e.ya&&(t.yaxis=e.ya),n[i]){var a=n[i];t.a=a.a,t.b=a.b,t.c=a.c}else t.a=e.a,t.b=e.b,t.c=e.c;return t}},{}],1028:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes");e.exports=function(t,e,r){var i={},a=r[e.subplot]._subplot;return i.aLabel=n.tickText(a.aaxis,t.a,!0).text,i.bLabel=n.tickText(a.baxis,t.b,!0).text,i.cLabel=n.tickText(a.caxis,t.c,!0).text,i}},{"../../plots/cartesian/axes":554}],1029:[function(t,e,r){"use strict";var n=t("../scatter/hover");e.exports=function(t,e,r,i){var a=n(t,e,r,i);if(a&&!1!==a[0].index){var o=a[0];if(void 0===o.index){var s=1-o.y0/t.ya._length,l=t.xa._length,c=l*s/2,u=l-c;return o.x0=Math.max(Math.min(o.x0,u),c),o.x1=Math.max(Math.min(o.x1,u),c),a}var f=o.cd[o.index],h=o.trace,p=o.subplot;o.a=f.a,o.b=f.b,o.c=f.c,o.xLabelVal=void 0,o.yLabelVal=void 0;var d={};d[h.subplot]={_subplot:p};var m=h._module.formatLabels(f,h,d);o.aLabel=m.aLabel,o.bLabel=m.bLabel,o.cLabel=m.cLabel;var g=f.hi||h.hoverinfo,v=[];if(!h.hovertemplate){var y=g.split("+");-1!==y.indexOf("all")&&(y=["a","b","c"]),-1!==y.indexOf("a")&&x(p.aaxis,o.aLabel),-1!==y.indexOf("b")&&x(p.baxis,o.bLabel),-1!==y.indexOf("c")&&x(p.caxis,o.cLabel)}return o.extraText=v.join("<br>"),o.hovertemplate=h.hovertemplate,a}function x(t,e){v.push(t._hovertitle+": "+e)}}},{"../scatter/hover":938}],1030:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:t("../scatter/marker_colorbar"),formatLabels:t("./format_labels"),calc:t("./calc"),plot:t("./plot"),style:t("../scatter/style").style,styleOnSelect:t("../scatter/style").styleOnSelect,hoverPoints:t("./hover"),selectPoints:t("../scatter/select"),eventData:t("./event_data"),moduleType:"trace",name:"scatterternary",basePlotModule:t("../../plots/ternary"),categories:["ternary","symbols","showLegend","scatter-like"],meta:{}}},{"../../plots/ternary":634,"../scatter/marker_colorbar":945,"../scatter/select":949,"../scatter/style":951,"./attributes":1024,"./calc":1025,"./defaults":1026,"./event_data":1027,"./format_labels":1028,"./hover":1029,"./plot":1031}],1031:[function(t,e,r){"use strict";var n=t("../scatter/plot");e.exports=function(t,e,r){var i=e.plotContainer;i.select(".scatterlayer").selectAll("*").remove();var a={xaxis:e.xaxis,yaxis:e.yaxis,plot:i,layerClipId:e._hasClipOnAxisFalse?e.clipIdRelative:null},o=e.layers.frontplot.select("g.scatterlayer");n(t,a,r,o)}},{"../scatter/plot":948}],1032:[function(t,e,r){"use strict";var n=t("../scatter/attributes"),i=t("../../components/colorscale/attributes"),a=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,o=t("../../plots/template_attributes").hovertemplateAttrs,s=t("../scattergl/attributes"),l=t("../../plots/cartesian/constants").idRegex,c=t("../../plot_api/plot_template").templatedArray,u=t("../../lib/extend").extendFlat,f=n.marker,h=f.line,p=u(i("marker.line",{editTypeOverride:"calc"}),{width:u({},h.width,{editType:"calc"}),editType:"calc"}),d=u(i("marker"),{symbol:f.symbol,size:u({},f.size,{editType:"markerSize"}),sizeref:f.sizeref,sizemin:f.sizemin,sizemode:f.sizemode,opacity:f.opacity,colorbar:f.colorbar,line:p,editType:"calc"});function m(t){return{valType:"info_array",freeLength:!0,editType:"calc",items:{valType:"subplotid",regex:l[t],editType:"plot"}}}d.color.editType=d.cmin.editType=d.cmax.editType="style",e.exports={dimensions:c("dimension",{visible:{valType:"boolean",dflt:!0,editType:"calc"},label:{valType:"string",editType:"calc"},values:{valType:"data_array",editType:"calc+clearAxisTypes"},axis:{type:{valType:"enumerated",values:["linear","log","date","category"],editType:"calc+clearAxisTypes"},matches:{valType:"boolean",dflt:!1,editType:"calc"},editType:"calc+clearAxisTypes"},editType:"calc+clearAxisTypes"}),text:u({},s.text,{}),hovertext:u({},s.hovertext,{}),hovertemplate:o(),xhoverformat:a("x"),yhoverformat:a("y"),marker:d,xaxes:m("x"),yaxes:m("y"),diagonal:{visible:{valType:"boolean",dflt:!0,editType:"calc"},editType:"calc"},showupperhalf:{valType:"boolean",dflt:!0,editType:"calc"},showlowerhalf:{valType:"boolean",dflt:!0,editType:"calc"},selected:{marker:s.selected.marker,editType:"calc"},unselected:{marker:s.unselected.marker,editType:"calc"},opacity:s.opacity}},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plot_api/plot_template":543,"../../plots/cartesian/axis_format_attributes":557,"../../plots/cartesian/constants":561,"../../plots/template_attributes":633,"../scatter/attributes":927,"../scattergl/attributes":979}],1033:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../components/grid");e.exports={moduleType:"trace",name:"splom",categories:["gl","regl","cartesian","symbols","showLegend","scatter-like"],attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:t("../scatter/marker_colorbar"),calc:t("./calc"),plot:t("./plot"),hoverPoints:t("./hover").hoverPoints,selectPoints:t("./select"),editStyle:t("./edit_style"),meta:{}},n.register(i)},{"../../components/grid":410,"../../registry":638,"../scatter/marker_colorbar":945,"./attributes":1032,"./calc":1035,"./defaults":1036,"./edit_style":1037,"./hover":1039,"./plot":1041,"./select":1043}],1034:[function(t,e,r){"use strict";var n=t("regl-line2d"),i=t("../../registry"),a=t("../../lib/prepare_regl"),o=t("../../plots/get_data").getModuleCalcData,s=t("../../plots/cartesian"),l=t("../../plots/cartesian/axis_ids").getFromId,c=t("../../plots/cartesian/axes").shouldShowZeroLine,u={};function f(t,e,r){for(var n=r.matrixOptions.data.length,i=e._visibleDims,a=r.viewOpts.ranges=new Array(n),o=0;o<i.length;o++){var s=i[o],c=a[o]=new Array(4),u=l(t,e._diag[s][0]);u&&(c[0]=u.r2l(u.range[0]),c[2]=u.r2l(u.range[1]));var f=l(t,e._diag[s][1]);f&&(c[1]=f.r2l(f.range[0]),c[3]=f.r2l(f.range[1]))}r.selectBatch.length||r.unselectBatch.length?r.matrix.update({ranges:a},{ranges:a}):r.matrix.update({ranges:a})}function h(t){var e=t._fullLayout,r=e._glcanvas.data()[0].regl,i=e._splomGrid;i||(i=e._splomGrid=n(r)),i.update(function(t){var e,r=t._context.plotGlPixelRatio,n=t._fullLayout,i=n._size,a=[0,0,n.width*r,n.height*r],o={};function s(t,e,n,i,s,l){n*=r,i*=r,s*=r,l*=r;var c=e[t+"color"],u=e[t+"width"],f=String(c+u);f in o?o[f].data.push(NaN,NaN,n,i,s,l):o[f]={data:[n,i,s,l],join:"rect",thickness:u*r,color:c,viewport:a,range:a,overlay:!1}}for(e in n._splomSubplots){var l,u,f=n._plots[e],h=f.xaxis,p=f.yaxis,d=h._gridVals,m=p._gridVals,g=h._offset,v=h._length,y=p._length,x=i.b+p.domain[0]*i.h,b=-p._m,_=-b*p.r2l(p.range[0],p.calendar);if(h.showgrid)for(e=0;e<d.length;e++)l=g+h.l2p(d[e].x),s("grid",h,l,x,l,x+y);if(p.showgrid)for(e=0;e<m.length;e++)u=x+_+b*m[e].x,s("grid",p,g,u,g+v,u);c(t,h,p)&&(l=g+h.l2p(0),s("zeroline",h,l,x,l,x+y)),c(t,p,h)&&s("zeroline",p,g,u=x+_+0,g+v,u)}var w=[];for(e in o)w.push(o[e]);return w}(t))}e.exports={name:"splom",attr:s.attr,attrRegex:s.attrRegex,layoutAttributes:s.layoutAttributes,supplyLayoutDefaults:s.supplyLayoutDefaults,drawFramework:s.drawFramework,plot:function(t){var e=t._fullLayout,r=i.getModule("splom"),n=o(t.calcdata,r)[0];a(t,["ANGLE_instanced_arrays","OES_element_index_uint"],u)&&(e._hasOnlyLargeSploms&&h(t),r.plot(t,{},n))},drag:function(t){var e=t.calcdata,r=t._fullLayout;r._hasOnlyLargeSploms&&h(t);for(var n=0;n<e.length;n++){var i=e[n][0].trace,a=r._splomScenes[i.uid];"splom"===i.type&&a&&a.matrix&&f(t,i,a)}},updateGrid:h,clean:function(t,e,r,n){var i,a={};if(n._splomScenes){for(i=0;i<t.length;i++){var o=t[i];"splom"===o.type&&(a[o.uid]=1)}for(i=0;i<r.length;i++){var l=r[i];if(!a[l.uid]){var c=n._splomScenes[l.uid];c&&c.destroy&&c.destroy(),n._splomScenes[l.uid]=null,delete n._splomScenes[l.uid]}}}0===Object.keys(n._splomScenes||{}).length&&delete n._splomScenes,n._splomGrid&&!e._hasOnlyLargeSploms&&n._hasOnlyLargeSploms&&(n._splomGrid.destroy(),n._splomGrid=null,delete n._splomGrid),s.clean(t,e,r,n)},updateFx:s.updateFx,toSVG:s.toSVG,reglPrecompiled:u}},{"../../lib/prepare_regl":516,"../../plots/cartesian":568,"../../plots/cartesian/axes":554,"../../plots/cartesian/axis_ids":558,"../../plots/get_data":593,"../../registry":638,"regl-line2d":280}],1035:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axis_ids"),a=t("../scatter/calc").calcMarkerSize,o=t("../scatter/calc").calcAxisExpansion,s=t("../scatter/colorscale_calc"),l=t("../scattergl/convert").markerSelection,c=t("../scattergl/convert").markerStyle,u=t("./scene_update"),f=t("../../constants/numerical").BADNUM,h=t("../scattergl/constants").TOO_MANY_POINTS;e.exports=function(t,e){var r,p,d,m,g,v,y=e.dimensions,x=e._length,b={},_=b.cdata=[],w=b.data=[],T=e._visibleDims=[];function k(t,r){for(var i=t.makeCalcdata({v:r.values,vcalendar:e.calendar},"v"),a=0;a<i.length;a++)i[a]=i[a]===f?NaN:i[a];_.push(i),w.push("log"===t.type?n.simpleMap(i,t.c2l):i)}for(r=0;r<y.length;r++)if((d=y[r]).visible){if(m=i.getFromId(t,e._diag[r][0]),g=i.getFromId(t,e._diag[r][1]),m&&g&&m.type!==g.type){n.log("Skipping splom dimension "+r+" with conflicting axis types");continue}m?(k(m,d),g&&"category"===g.type&&(g._categories=m._categories.slice())):k(g,d),T.push(r)}for(s(t,e),n.extendFlat(b,c(e)),v=_.length*x>h?b.sizeAvg||Math.max(b.size,3):a(e,x),p=0;p<T.length;p++)d=y[r=T[p]],m=i.getFromId(t,e._diag[r][0])||{},g=i.getFromId(t,e._diag[r][1])||{},o(t,e,m,g,_[p],_[p],v);var A=u(t,e);return A.matrix||(A.matrix=!0),A.matrixOptions=b,A.selectedOptions=l(e,e.selected),A.unselectedOptions=l(e,e.unselected),[{x:!1,y:!1,t:{},trace:e}]}},{"../../constants/numerical":479,"../../lib":503,"../../plots/cartesian/axis_ids":558,"../scatter/calc":928,"../scatter/colorscale_calc":930,"../scattergl/constants":982,"../scattergl/convert":983,"./scene_update":1042}],1036:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/array_container_defaults"),a=t("./attributes"),o=t("../scatter/subtypes"),s=t("../scatter/marker_defaults"),l=t("../parcoords/merge_length"),c=t("../scattergl/helpers").isOpenSymbol;function u(t,e){function r(r,i){return n.coerce(t,e,a.dimensions,r,i)}r("label");var i=r("values");i&&i.length?r("visible"):e.visible=!1,r("axis.type"),r("axis.matches")}e.exports=function(t,e,r,f){function h(r,i){return n.coerce(t,e,a,r,i)}var p=i(t,e,{name:"dimensions",handleItemDefaults:u}),d=h("diagonal.visible"),m=h("showupperhalf"),g=h("showlowerhalf");if(l(e,p,"values")&&(d||m||g)){h("text"),h("hovertext"),h("hovertemplate"),h("xhoverformat"),h("yhoverformat"),s(t,e,r,f,h);var v=c(e.marker.symbol),y=o.isBubble(e);h("marker.line.width",v||y?1:0),function(t,e,r,n){var i,a,o=e.dimensions,s=o.length,l=e.showupperhalf,c=e.showlowerhalf,u=e.diagonal.visible,f=new Array(s),h=new Array(s);for(i=0;i<s;i++){var p=i?i+1:"";f[i]="x"+p,h[i]="y"+p}var d=n("xaxes",f),m=n("yaxes",h),g=e._diag=new Array(s);e._xaxes={},e._yaxes={};var v=[],y=[];function x(t,n,i,a){if(t){var o=t.charAt(0),s=r._splomAxes[o];if(e["_"+o+"axes"][t]=1,a.push(t),!(t in s)){var l=s[t]={};i&&(l.label=i.label||"",i.visible&&i.axis&&(i.axis.type&&(l.type=i.axis.type),i.axis.matches&&(l.matches=n)))}}}var b=!u&&!c,_=!u&&!l;for(e._axesDim={},i=0;i<s;i++){var w=o[i],T=0===i,k=i===s-1,A=T&&b||k&&_?void 0:d[i],M=T&&_||k&&b?void 0:m[i];x(A,M,w,v),x(M,A,w,y),g[i]=[A,M],e._axesDim[A]=i,e._axesDim[M]=i}for(i=0;i<v.length;i++)for(a=0;a<y.length;a++){var S=v[i]+y[a];i>a&&l||i<a&&c?r._splomSubplots[S]=1:i!==a||!u&&c&&l||(r._splomSubplots[S]=1)}(!c||!u&&l&&c)&&(r._splomGridDflt.xside="bottom",r._splomGridDflt.yside="left")}(0,e,f,h),n.coerceSelectionMarkerOpacity(e,h)}else e.visible=!1}},{"../../lib":503,"../../plots/array_container_defaults":549,"../parcoords/merge_length":898,"../scatter/marker_defaults":946,"../scatter/subtypes":952,"../scattergl/helpers":987,"./attributes":1032}],1037:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../scatter/colorscale_calc"),a=t("../scattergl/convert").markerStyle;e.exports=function(t,e){var r=e.trace,o=t._fullLayout._splomScenes[r.uid];if(o){i(t,r),n.extendFlat(o.matrixOptions,a(r));var s=n.extendFlat({},o.matrixOptions,o.viewOpts);o.matrix.update(s,null)}}},{"../../lib":503,"../scatter/colorscale_calc":930,"../scattergl/convert":983}],1038:[function(t,e,r){"use strict";r.getDimIndex=function(t,e){for(var r=e._id,n={x:0,y:1}[r.charAt(0)],i=t._visibleDims,a=0;a<i.length;a++){var o=i[a];if(t._diag[o][n]===r)return a}return!1}},{}],1039:[function(t,e,r){"use strict";var n=t("./helpers"),i=t("../scattergl/hover").calcHover;e.exports={hoverPoints:function(t,e,r){var a=t.cd[0].trace,o=t.scene.matrixOptions.cdata,s=t.xa,l=t.ya,c=s.c2p(e),u=l.c2p(r),f=t.distance,h=n.getDimIndex(a,s),p=n.getDimIndex(a,l);if(!1===h||!1===p)return[t];for(var d,m,g=o[h],v=o[p],y=f,x=0;x<g.length;x++){var b=g[x],_=v[x],w=s.c2p(b)-c,T=l.c2p(_)-u,k=Math.sqrt(w*w+T*T);k<y&&(y=m=k,d=x)}return t.index=d,t.distance=y,t.dxy=m,void 0===d?[t]:[i(t,g,v,a)]}}},{"../scattergl/hover":988,"./helpers":1038}],1040:[function(t,e,r){"use strict";var n=t("./base_index");n.basePlotModule=t("./base_plot"),e.exports=n},{"./base_index":1033,"./base_plot":1034}],1041:[function(t,e,r){"use strict";var n=t("regl-splom"),i=t("../../lib"),a=t("../../plots/cartesian/axis_ids"),o=t("../../components/dragelement/helpers").selectMode;function s(t,e){var r,s,l,c,u,f=t._fullLayout,h=f._size,p=e.trace,d=e.t,m=f._splomScenes[p.uid],g=m.matrixOptions,v=g.cdata,y=f._glcanvas.data()[0].regl,x=f.dragmode;if(0!==v.length){g.lower=p.showupperhalf,g.upper=p.showlowerhalf,g.diagonal=p.diagonal.visible;var b=p._visibleDims,_=v.length,w=m.viewOpts={};for(w.ranges=new Array(_),w.domains=new Array(_),u=0;u<b.length;u++){l=b[u];var T=w.ranges[u]=new Array(4),k=w.domains[u]=new Array(4);(r=a.getFromId(t,p._diag[l][0]))&&(T[0]=r._rl[0],T[2]=r._rl[1],k[0]=r.domain[0],k[2]=r.domain[1]),(s=a.getFromId(t,p._diag[l][1]))&&(T[1]=s._rl[0],T[3]=s._rl[1],k[1]=s.domain[0],k[3]=s.domain[1])}var A=t._context.plotGlPixelRatio,M=h.l*A,S=h.b*A,E=h.w*A,L=h.h*A;w.viewport=[M,S,E+M,L+S],!0===m.matrix&&(m.matrix=n(y));var C=f.clickmode.indexOf("select")>-1,P=!0;if(o(x)||!!p.selectedpoints||C){var I=p._length;if(p.selectedpoints){m.selectBatch=p.selectedpoints;var O=p.selectedpoints,z={};for(l=0;l<O.length;l++)z[O[l]]=!0;var D=[];for(l=0;l<I;l++)z[l]||D.push(l);m.unselectBatch=D}var R=d.xpx=new Array(_),F=d.ypx=new Array(_);for(u=0;u<b.length;u++){if(l=b[u],r=a.getFromId(t,p._diag[l][0]))for(R[u]=new Array(I),c=0;c<I;c++)R[u][c]=r.c2p(v[u][c]);if(s=a.getFromId(t,p._diag[l][1]))for(F[u]=new Array(I),c=0;c<I;c++)F[u][c]=s.c2p(v[u][c])}if(m.selectBatch.length||m.unselectBatch.length){var B=i.extendFlat({},g,m.unselectedOptions,w),N=i.extendFlat({},g,m.selectedOptions,w);m.matrix.update(B,N),P=!1}}else d.xpx=d.ypx=null;if(P){var j=i.extendFlat({},g,w);m.matrix.update(j,null)}}}e.exports=function(t,e,r){if(r.length)for(var n=0;n<r.length;n++)s(t,r[n][0])}},{"../../components/dragelement/helpers":384,"../../lib":503,"../../plots/cartesian/axis_ids":558,"regl-splom":282}],1042:[function(t,e,r){"use strict";var n=t("../../lib");e.exports=function(t,e){var r=t._fullLayout,i=e.uid,a=r._splomScenes;a||(a=r._splomScenes={});var o={dirty:!0,selectBatch:[],unselectBatch:[]},s=a[e.uid];return s||((s=a[i]=n.extendFlat({},o,{matrix:!1,selectBatch:[],unselectBatch:[]})).draw=function(){s.matrix&&s.matrix.draw&&(s.selectBatch.length||s.unselectBatch.length?s.matrix.draw(s.unselectBatch,s.selectBatch):s.matrix.draw()),s.dirty=!1},s.destroy=function(){s.matrix&&s.matrix.destroy&&s.matrix.destroy(),s.matrixOptions=null,s.selectBatch=null,s.unselectBatch=null,s=null}),s.dirty||n.extendFlat(s,o),s}},{"../../lib":503}],1043:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../scatter/subtypes"),a=t("./helpers");e.exports=function(t,e){var r=t.cd,o=r[0].trace,s=r[0].t,l=t.scene,c=l.matrixOptions.cdata,u=t.xaxis,f=t.yaxis,h=[];if(!l)return h;var p=!i.hasMarkers(o)&&!i.hasText(o);if(!0!==o.visible||p)return h;var d=a.getDimIndex(o,u),m=a.getDimIndex(o,f);if(!1===d||!1===m)return h;var g=s.xpx[d],v=s.ypx[m],y=c[d],x=c[m],b=[],_=[];if(!1!==e&&!e.degenerate)for(var w=0;w<y.length;w++)e.contains([g[w],v[w]],null,w,t)?(b.push(w),h.push({pointNumber:w,x:y[w],y:x[w]})):_.push(w);var T=l.matrixOptions;return b.length||_.length?l.selectBatch.length||l.unselectBatch.length||l.matrix.update(l.unselectedOptions,n.extendFlat({},T,l.selectedOptions,l.viewOpts)):l.matrix.update(T,null),l.selectBatch=b,l.unselectBatch=_,h}},{"../../lib":503,"../scatter/subtypes":952,"./helpers":1038}],1044:[function(t,e,r){"use strict";var n=t("../../components/colorscale/attributes"),i=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,a=t("../../plots/template_attributes").hovertemplateAttrs,o=t("../mesh3d/attributes"),s=t("../../plots/attributes"),l=t("../../lib/extend").extendFlat,c={x:{valType:"data_array",editType:"calc+clearAxisTypes"},y:{valType:"data_array",editType:"calc+clearAxisTypes"},z:{valType:"data_array",editType:"calc+clearAxisTypes"},u:{valType:"data_array",editType:"calc"},v:{valType:"data_array",editType:"calc"},w:{valType:"data_array",editType:"calc"},starts:{x:{valType:"data_array",editType:"calc"},y:{valType:"data_array",editType:"calc"},z:{valType:"data_array",editType:"calc"},editType:"calc"},maxdisplayed:{valType:"integer",min:0,dflt:1e3,editType:"calc"},sizeref:{valType:"number",editType:"calc",min:0,dflt:1},text:{valType:"string",dflt:"",editType:"calc"},hovertext:{valType:"string",dflt:"",editType:"calc"},hovertemplate:a({editType:"calc"},{keys:["tubex","tubey","tubez","tubeu","tubev","tubew","norm","divergence"]}),uhoverformat:i("u",1),vhoverformat:i("v",1),whoverformat:i("w",1),xhoverformat:i("x"),yhoverformat:i("y"),zhoverformat:i("z"),showlegend:l({},s.showlegend,{dflt:!1})};l(c,n("",{colorAttr:"u/v/w norm",showScaleDflt:!0,editTypeOverride:"calc"}));["opacity","lightposition","lighting"].forEach((function(t){c[t]=o[t]})),c.hoverinfo=l({},s.hoverinfo,{editType:"calc",flags:["x","y","z","u","v","w","norm","divergence","text","name"],dflt:"x+y+z+norm+text+name"}),c.transforms=void 0,e.exports=c},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/cartesian/axis_format_attributes":557,"../../plots/template_attributes":633,"../mesh3d/attributes":867}],1045:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/colorscale/calc");function a(t){var e,r,i,a,s,l,c,u,f,h,p,d,m=t._x,g=t._y,v=t._z,y=t._len,x=-1/0,b=1/0,_=-1/0,w=1/0,T=-1/0,k=1/0,A="";for(y&&(c=m[0],f=g[0],p=v[0]),y>1&&(u=m[y-1],h=g[y-1],d=v[y-1]),e=0;e<y;e++)x=Math.max(x,m[e]),b=Math.min(b,m[e]),_=Math.max(_,g[e]),w=Math.min(w,g[e]),T=Math.max(T,v[e]),k=Math.min(k,v[e]),a||m[e]===c||(a=!0,A+="x"),s||g[e]===f||(s=!0,A+="y"),l||v[e]===p||(l=!0,A+="z");a||(A+="x"),s||(A+="y"),l||(A+="z");var M=o(t._x),S=o(t._y),E=o(t._z);A=(A=(A=A.replace("x",(c>u?"-":"+")+"x")).replace("y",(f>h?"-":"+")+"y")).replace("z",(p>d?"-":"+")+"z");var L=function(){y=0,M=[],S=[],E=[]};(!y||y<M.length*S.length*E.length)&&L();var C=function(t){return"x"===t?m:"y"===t?g:v},P=function(t){return"x"===t?M:"y"===t?S:E},I=function(t){return t[y-1]<t[0]?-1:1},O=C(A[1]),z=C(A[3]),D=C(A[5]),R=P(A[1]).length,F=P(A[3]).length,B=P(A[5]).length,N=!1,j=function(t,e,r){return R*(F*t+e)+r},U=I(C(A[1])),V=I(C(A[3])),H=I(C(A[5]));for(e=0;e<B-1;e++){for(r=0;r<F-1;r++){for(i=0;i<R-1;i++){var q=j(e,r,i),G=j(e,r,i+1),Y=j(e,r+1,i),W=j(e+1,r,i);if(O[q]*U<O[G]*U&&z[q]*V<z[Y]*V&&D[q]*H<D[W]*H||(N=!0),N)break}if(N)break}if(N)break}return N&&(n.warn("Encountered arbitrary coordinates! Unable to input data grid."),L()),{xMin:b,yMin:w,zMin:k,xMax:x,yMax:_,zMax:T,Xs:M,Ys:S,Zs:E,len:y,fill:A}}function o(t){return n.distinctVals(t).vals}function s(t,e){if(void 0===e&&(e=t.length),n.isTypedArray(t))return t.subarray(0,e);for(var r=[],i=0;i<e;i++)r[i]=+t[i];return r}e.exports={calc:function(t,e){e._len=Math.min(e.u.length,e.v.length,e.w.length,e.x.length,e.y.length,e.z.length),e._u=s(e.u,e._len),e._v=s(e.v,e._len),e._w=s(e.w,e._len),e._x=s(e.x,e._len),e._y=s(e.y,e._len),e._z=s(e.z,e._len);var r=a(e);e._gridFill=r.fill,e._Xs=r.Xs,e._Ys=r.Ys,e._Zs=r.Zs,e._len=r.len;var n,o,l,c=0;e.starts&&(n=s(e.starts.x||[]),o=s(e.starts.y||[]),l=s(e.starts.z||[]),c=Math.min(n.length,o.length,l.length)),e._startsX=n||[],e._startsY=o||[],e._startsZ=l||[];var u,f=0,h=1/0;for(u=0;u<e._len;u++){var p=e._u[u],d=e._v[u],m=e._w[u],g=Math.sqrt(p*p+d*d+m*m);f=Math.max(f,g),h=Math.min(h,g)}for(i(t,e,{vals:[h,f],containerStr:"",cLetter:"c"}),u=0;u<c;u++){var v=n[u];r.xMax=Math.max(r.xMax,v),r.xMin=Math.min(r.xMin,v);var y=o[u];r.yMax=Math.max(r.yMax,y),r.yMin=Math.min(r.yMin,y);var x=l[u];r.zMax=Math.max(r.zMax,x),r.zMin=Math.min(r.zMin,x)}e._slen=c,e._normMax=f,e._xbnds=[r.xMin,r.xMax],e._ybnds=[r.yMin,r.yMax],e._zbnds=[r.zMin,r.zMax]},filter:s,processGrid:a}},{"../../components/colorscale/calc":374,"../../lib":503}],1046:[function(t,e,r){"use strict";var n=t("../../../stackgl_modules").gl_streamtube3d,i=n.createTubeMesh,a=t("../../lib"),o=t("../../lib/gl_format_color").parseColorScale,s=t("../../components/colorscale").extractOpts,l=t("../../plots/gl3d/zip3"),c={xaxis:0,yaxis:1,zaxis:2};function u(t,e){this.scene=t,this.uid=e,this.mesh=null,this.data=null}var f=u.prototype;function h(t){var e=t.length;return e>2?t.slice(1,e-1):2===e?[(t[0]+t[1])/2]:t}function p(t){var e=t.length;return 1===e?[.5,.5]:[t[1]-t[0],t[e-1]-t[e-2]]}function d(t,e){var r=t.fullSceneLayout,i=t.dataScale,u=e._len,f={};function d(t,e){var n=r[e],o=i[c[e]];return a.simpleMap(t,(function(t){return n.d2l(t)*o}))}if(f.vectors=l(d(e._u,"xaxis"),d(e._v,"yaxis"),d(e._w,"zaxis"),u),!u)return{positions:[],cells:[]};var m=d(e._Xs,"xaxis"),g=d(e._Ys,"yaxis"),v=d(e._Zs,"zaxis");if(f.meshgrid=[m,g,v],f.gridFill=e._gridFill,e._slen)f.startingPositions=l(d(e._startsX,"xaxis"),d(e._startsY,"yaxis"),d(e._startsZ,"zaxis"));else{for(var y=g[0],x=h(m),b=h(v),_=new Array(x.length*b.length),w=0,T=0;T<x.length;T++)for(var k=0;k<b.length;k++)_[w++]=[x[T],y,b[k]];f.startingPositions=_}f.colormap=o(e),f.tubeSize=e.sizeref,f.maxLength=e.maxdisplayed;var A=d(e._xbnds,"xaxis"),M=d(e._ybnds,"yaxis"),S=d(e._zbnds,"zaxis"),E=p(m),L=p(g),C=p(v),P=[[A[0]-E[0],M[0]-L[0],S[0]-C[0]],[A[1]+E[1],M[1]+L[1],S[1]+C[1]]],I=n(f,P),O=s(e);I.vertexIntensityBounds=[O.min/e._normMax,O.max/e._normMax];var z=e.lightposition;return I.lightPosition=[z.x,z.y,z.z],I.ambient=e.lighting.ambient,I.diffuse=e.lighting.diffuse,I.specular=e.lighting.specular,I.roughness=e.lighting.roughness,I.fresnel=e.lighting.fresnel,I.opacity=e.opacity,e._pad=I.tubeScale*e.sizeref*2,I}f.handlePick=function(t){var e=this.scene.fullSceneLayout,r=this.scene.dataScale;function n(t,n){var i=e[n],a=r[c[n]];return i.l2c(t)/a}if(t.object===this.mesh){var i=t.data.position,a=t.data.velocity;return t.traceCoordinate=[n(i[0],"xaxis"),n(i[1],"yaxis"),n(i[2],"zaxis"),n(a[0],"xaxis"),n(a[1],"yaxis"),n(a[2],"zaxis"),t.data.intensity*this.data._normMax,t.data.divergence],t.textLabel=this.data.hovertext||this.data.text,!0}},f.update=function(t){this.data=t;var e=d(this.scene,t);this.mesh.update(e)},f.dispose=function(){this.scene.glplot.remove(this.mesh),this.mesh.dispose()},e.exports=function(t,e){var r=t.glplot.gl,n=d(t,e),a=i(r,n),o=new u(t,e.uid);return o.mesh=a,o.data=e,a._trace=o,t.glplot.add(a),o}},{"../../../stackgl_modules":1124,"../../components/colorscale":378,"../../lib":503,"../../lib/gl_format_color":499,"../../plots/gl3d/zip3":609}],1047:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/colorscale/defaults"),a=t("./attributes");e.exports=function(t,e,r,o){function s(r,i){return n.coerce(t,e,a,r,i)}var l=s("u"),c=s("v"),u=s("w"),f=s("x"),h=s("y"),p=s("z");l&&l.length&&c&&c.length&&u&&u.length&&f&&f.length&&h&&h.length&&p&&p.length?(s("starts.x"),s("starts.y"),s("starts.z"),s("maxdisplayed"),s("sizeref"),s("lighting.ambient"),s("lighting.diffuse"),s("lighting.specular"),s("lighting.roughness"),s("lighting.fresnel"),s("lightposition.x"),s("lightposition.y"),s("lightposition.z"),i(t,e,o,s,{prefix:"",cLetter:"c"}),s("text"),s("hovertext"),s("hovertemplate"),s("uhoverformat"),s("vhoverformat"),s("whoverformat"),s("xhoverformat"),s("yhoverformat"),s("zhoverformat"),e._length=null):e.visible=!1}},{"../../components/colorscale/defaults":376,"../../lib":503,"./attributes":1044}],1048:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"streamtube",basePlotModule:t("../../plots/gl3d"),categories:["gl3d","showLegend"],attributes:t("./attributes"),supplyDefaults:t("./defaults"),colorbar:{min:"cmin",max:"cmax"},calc:t("./calc").calc,plot:t("./convert"),eventData:function(t,e){return t.tubex=t.x,t.tubey=t.y,t.tubez=t.z,t.tubeu=e.traceCoordinate[3],t.tubev=e.traceCoordinate[4],t.tubew=e.traceCoordinate[5],t.norm=e.traceCoordinate[6],t.divergence=e.traceCoordinate[7],delete t.x,delete t.y,delete t.z,t},meta:{}}},{"../../plots/gl3d":598,"./attributes":1044,"./calc":1045,"./convert":1046,"./defaults":1047}],1049:[function(t,e,r){"use strict";var n=t("../../plots/attributes"),i=t("../../plots/template_attributes").hovertemplateAttrs,a=t("../../plots/template_attributes").texttemplateAttrs,o=t("../../components/colorscale/attributes"),s=t("../../plots/domain").attributes,l=t("../pie/attributes"),c=t("./constants"),u=t("../../lib/extend").extendFlat;e.exports={labels:{valType:"data_array",editType:"calc"},parents:{valType:"data_array",editType:"calc"},values:{valType:"data_array",editType:"calc"},branchvalues:{valType:"enumerated",values:["remainder","total"],dflt:"remainder",editType:"calc"},count:{valType:"flaglist",flags:["branches","leaves"],dflt:"leaves",editType:"calc"},level:{valType:"any",editType:"plot",anim:!0},maxdepth:{valType:"integer",editType:"plot",dflt:-1},marker:u({colors:{valType:"data_array",editType:"calc"},line:{color:u({},l.marker.line.color,{dflt:null}),width:u({},l.marker.line.width,{dflt:1}),editType:"calc"},editType:"calc"},o("marker",{colorAttr:"colors",anim:!1})),leaf:{opacity:{valType:"number",editType:"style",min:0,max:1},editType:"plot"},text:l.text,textinfo:{valType:"flaglist",flags:["label","text","value","current path","percent root","percent entry","percent parent"],extras:["none"],editType:"plot"},texttemplate:a({editType:"plot"},{keys:c.eventDataKeys.concat(["label","value"])}),hovertext:l.hovertext,hoverinfo:u({},n.hoverinfo,{flags:["label","text","value","name","current path","percent root","percent entry","percent parent"],dflt:"label+text+value+name"}),hovertemplate:i({},{keys:c.eventDataKeys}),textfont:l.textfont,insidetextorientation:l.insidetextorientation,insidetextfont:l.insidetextfont,outsidetextfont:u({},l.outsidetextfont,{}),rotation:{valType:"angle",dflt:0,editType:"plot"},sort:l.sort,root:{color:{valType:"color",editType:"calc",dflt:"rgba(0,0,0,0)"},editType:"calc"},domain:s({name:"sunburst",trace:!0,editType:"calc"})}},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/domain":584,"../../plots/template_attributes":633,"../pie/attributes":901,"./constants":1052}],1050:[function(t,e,r){"use strict";var n=t("../../plots/plots");r.name="sunburst",r.plot=function(t,e,i,a){n.plotBasePlot(r.name,t,e,i,a)},r.clean=function(t,e,i,a){n.cleanBasePlot(r.name,t,e,i,a)}},{"../../plots/plots":619}],1051:[function(t,e,r){"use strict";var n=t("d3-hierarchy"),i=t("fast-isnumeric"),a=t("../../lib"),o=t("../../components/colorscale").makeColorScaleFuncFromTrace,s=t("../pie/calc").makePullColorFn,l=t("../pie/calc").generateExtendedColors,c=t("../../components/colorscale").calc,u=t("../../constants/numerical").ALMOST_EQUAL,f={},h={},p={};r.calc=function(t,e){var r,l,f,h,p,d,m=t._fullLayout,g=e.ids,v=a.isArrayOrTypedArray(g),y=e.labels,x=e.parents,b=e.values,_=a.isArrayOrTypedArray(b),w=[],T={},k={},A=function(t){return t||"number"==typeof t},M=function(t){return!_||i(b[t])&&b[t]>=0};v?(r=Math.min(g.length,x.length),l=function(t){return A(g[t])&&M(t)},f=function(t){return String(g[t])}):(r=Math.min(y.length,x.length),l=function(t){return A(y[t])&&M(t)},f=function(t){return String(y[t])}),_&&(r=Math.min(r,b.length));for(var S=0;S<r;S++)if(l(S)){var E=f(S),L=A(x[S])?String(x[S]):"",C={i:S,id:E,pid:L,label:A(y[S])?String(y[S]):""};_&&(C.v=+b[S]),w.push(C),p=E,T[h=L]?T[h].push(p):T[h]=[p],k[p]=1}if(T[""]){if(T[""].length>1){for(var P=a.randstr(),I=0;I<w.length;I++)""===w[I].pid&&(w[I].pid=P);w.unshift({hasMultipleRoots:!0,id:P,pid:"",label:""})}}else{var O,z=[];for(O in T)k[O]||z.push(O);if(1!==z.length)return a.warn(["Multiple implied roots, cannot build",e.type,"hierarchy of",e.name+".","These roots include:",z.join(", ")].join(" "));O=z[0],w.unshift({hasImpliedRoot:!0,id:O,pid:"",label:O})}try{d=n.stratify().id((function(t){return t.id})).parentId((function(t){return t.pid}))(w)}catch(t){return a.warn(["Failed to build",e.type,"hierarchy of",e.name+".","Error:",t.message].join(" "))}var D=n.hierarchy(d),R=!1;if(_)switch(e.branchvalues){case"remainder":D.sum((function(t){return t.data.v}));break;case"total":D.each((function(t){var r=t.data.data,n=r.v;if(t.children){var i=t.children.reduce((function(t,e){return t+e.data.data.v}),0);if((r.hasImpliedRoot||r.hasMultipleRoots)&&(n=i),n<i*u)return R=!0,a.warn(["Total value for node",t.data.data.id,"of",e.name,"is smaller than the sum of its children.","\nparent value =",n,"\nchildren sum =",i].join(" "))}t.value=n}))}else!function t(e,r,n){var i=0,a=e.children;if(a){for(var o=a.length,s=0;s<o;s++)i+=t(a[s],r,n);n.branches&&i++}else n.leaves&&i++;e.value=e.data.data.value=i,r._values||(r._values=[]);return r._values[e.data.data.i]=i,i}(D,e,{branches:-1!==e.count.indexOf("branches"),leaves:-1!==e.count.indexOf("leaves")});if(!R){var F,B;e.sort&&D.sort((function(t,e){return e.value-t.value}));var N=e.marker.colors||[],j=!!N.length;return e._hasColorscale?(j||(N=_?e.values:e._values),c(t,e,{vals:N,containerStr:"marker",cLetter:"c"}),B=o(e.marker)):F=s(m["_"+e.type+"colormap"]),D.each((function(t){var r=t.data.data;r.color=e._hasColorscale?B(N[r.i]):F(N[r.i],r.id)})),w[0].hierarchy=D,w}},r._runCrossTraceCalc=function(t,e){var r=e._fullLayout,n=e.calcdata,i=r[t+"colorway"],a=r["_"+t+"colormap"];r["extend"+t+"colors"]&&(i=l(i,"icicle"===t?p:"treemap"===t?h:f));var o,s=0;function c(t){var e=t.data.data,r=e.id;!1===e.color&&(a[r]?e.color=a[r]:t.parent?t.parent.parent?e.color=t.parent.data.data.color:(a[r]=e.color=i[s%i.length],s++):e.color=o)}for(var u=0;u<n.length;u++){var d=n[u][0];d.trace.type===t&&d.hierarchy&&(o=d.trace.root.color,d.hierarchy.each(c))}},r.crossTraceCalc=function(t){return r._runCrossTraceCalc("sunburst",t)}},{"../../components/colorscale":378,"../../constants/numerical":479,"../../lib":503,"../pie/calc":903,"d3-hierarchy":115,"fast-isnumeric":190}],1052:[function(t,e,r){"use strict";e.exports={CLICK_TRANSITION_TIME:750,CLICK_TRANSITION_EASING:"linear",eventDataKeys:["currentPath","root","entry","percentRoot","percentEntry","percentParent"]}},{}],1053:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./attributes"),a=t("../../plots/domain").defaults,o=t("../bar/defaults").handleText,s=t("../../components/colorscale"),l=s.hasColorscale,c=s.handleDefaults;e.exports=function(t,e,r,s){function u(r,a){return n.coerce(t,e,i,r,a)}var f=u("labels"),h=u("parents");if(f&&f.length&&h&&h.length){var p=u("values");p&&p.length?u("branchvalues"):u("count"),u("level"),u("maxdepth"),u("marker.line.width")&&u("marker.line.color",s.paper_bgcolor),u("marker.colors");var d=e._hasColorscale=l(t,"marker","colors")||(t.marker||{}).coloraxis;d&&c(t,e,s,u,{prefix:"marker.",cLetter:"c"}),u("leaf.opacity",d?1:.7);var m=u("text");u("texttemplate"),e.texttemplate||u("textinfo",Array.isArray(m)?"text+label":"label"),u("hovertext"),u("hovertemplate");o(t,e,s,u,"auto",{moduleHasSelected:!1,moduleHasUnselected:!1,moduleHasConstrain:!1,moduleHasCliponaxis:!1,moduleHasTextangle:!1,moduleHasInsideanchor:!1}),u("insidetextorientation"),u("sort"),u("rotation"),u("root.color"),a(e,s,u),e._length=null}else e.visible=!1}},{"../../components/colorscale":378,"../../lib":503,"../../plots/domain":584,"../bar/defaults":652,"./attributes":1049}],1054:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../registry"),a=t("../../components/fx/helpers").appendArrayPointValue,o=t("../../components/fx"),s=t("../../lib"),l=t("../../lib/events"),c=t("./helpers"),u=t("../pie/helpers").formatPieValue;function f(t,e,r){for(var n=t.data.data,i={curveNumber:e.index,pointNumber:n.i,data:e._input,fullData:e},o=0;o<r.length;o++){var s=r[o];s in t&&(i[s]=t[s])}return"parentString"in t&&!c.isHierarchyRoot(t)&&(i.parent=t.parentString),a(i,e,n.i),i}e.exports=function(t,e,r,a,h){var p=a[0],d=p.trace,m=p.hierarchy,g="sunburst"===d.type,v="treemap"===d.type||"icicle"===d.type;"_hasHoverLabel"in d||(d._hasHoverLabel=!1),"_hasHoverEvent"in d||(d._hasHoverEvent=!1);t.on("mouseover",(function(i){var a=r._fullLayout;if(!r._dragging&&!1!==a.hovermode){var l,y=r._fullData[d.index],x=i.data.data,b=x.i,_=c.isHierarchyRoot(i),w=c.getParent(m,i),T=c.getValue(i),k=function(t){return s.castOption(y,b,t)},A=k("hovertemplate"),M=o.castHoverinfo(y,a,b),S=a.separators;if(A||M&&"none"!==M&&"skip"!==M){var E,L;g&&(E=p.cx+i.pxmid[0]*(1-i.rInscribed),L=p.cy+i.pxmid[1]*(1-i.rInscribed)),v&&(E=i._hoverX,L=i._hoverY);var C,P={},I=[],O=[],z=function(t){return-1!==I.indexOf(t)};M&&(I="all"===M?y._module.attributes.hoverinfo.flags:M.split("+")),P.label=x.label,z("label")&&P.label&&O.push(P.label),x.hasOwnProperty("v")&&(P.value=x.v,P.valueLabel=u(P.value,S),z("value")&&O.push(P.valueLabel)),P.currentPath=i.currentPath=c.getPath(i.data),z("current path")&&!_&&O.push(P.currentPath);var D=[],R=function(){-1===D.indexOf(C)&&(O.push(C),D.push(C))};P.percentParent=i.percentParent=T/c.getValue(w),P.parent=i.parentString=c.getPtLabel(w),z("percent parent")&&(C=c.formatPercent(P.percentParent,S)+" of "+P.parent,R()),P.percentEntry=i.percentEntry=T/c.getValue(e),P.entry=i.entry=c.getPtLabel(e),!z("percent entry")||_||i.onPathbar||(C=c.formatPercent(P.percentEntry,S)+" of "+P.entry,R()),P.percentRoot=i.percentRoot=T/c.getValue(m),P.root=i.root=c.getPtLabel(m),z("percent root")&&!_&&(C=c.formatPercent(P.percentRoot,S)+" of "+P.root,R()),P.text=k("hovertext")||k("text"),z("text")&&(C=P.text,s.isValidTextValue(C)&&O.push(C)),l=[f(i,y,h.eventDataKeys)];var F={trace:y,y:L,_x0:i._x0,_x1:i._x1,_y0:i._y0,_y1:i._y1,text:O.join("<br>"),name:A||z("name")?y.name:void 0,color:k("hoverlabel.bgcolor")||x.color,borderColor:k("hoverlabel.bordercolor"),fontFamily:k("hoverlabel.font.family"),fontSize:k("hoverlabel.font.size"),fontColor:k("hoverlabel.font.color"),nameLength:k("hoverlabel.namelength"),textAlign:k("hoverlabel.align"),hovertemplate:A,hovertemplateLabels:P,eventData:l};g&&(F.x0=E-i.rInscribed*i.rpx1,F.x1=E+i.rInscribed*i.rpx1,F.idealAlign=i.pxmid[0]<0?"left":"right"),v&&(F.x=E,F.idealAlign=E<0?"left":"right");var B=[];o.loneHover(F,{container:a._hoverlayer.node(),outerContainer:a._paper.node(),gd:r,inOut_bbox:B}),l[0].bbox=B[0],d._hasHoverLabel=!0}if(v){var N=t.select("path.surface");h.styleOne(N,i,y,{hovered:!0})}d._hasHoverEvent=!0,r.emit("plotly_hover",{points:l||[f(i,y,h.eventDataKeys)],event:n.event})}})),t.on("mouseout",(function(e){var i=r._fullLayout,a=r._fullData[d.index],s=n.select(this).datum();if(d._hasHoverEvent&&(e.originalEvent=n.event,r.emit("plotly_unhover",{points:[f(s,a,h.eventDataKeys)],event:n.event}),d._hasHoverEvent=!1),d._hasHoverLabel&&(o.loneUnhover(i._hoverlayer.node()),d._hasHoverLabel=!1),v){var l=t.select("path.surface");h.styleOne(l,s,a,{hovered:!1})}})),t.on("click",(function(t){var e=r._fullLayout,a=r._fullData[d.index],s=g&&(c.isHierarchyRoot(t)||c.isLeaf(t)),u=c.getPtId(t),p=c.isEntry(t)?c.findEntryWithChild(m,u):c.findEntryWithLevel(m,u),v=c.getPtId(p),y={points:[f(t,a,h.eventDataKeys)],event:n.event};s||(y.nextLevel=v);var x=l.triggerHandler(r,"plotly_"+d.type+"click",y);if(!1!==x&&e.hovermode&&(r._hoverdata=[f(t,a,h.eventDataKeys)],o.click(r,n.event)),!s&&!1!==x&&!r._dragging&&!r._transitioning){i.call("_storeDirectGUIEdit",a,e._tracePreGUI[a.uid],{level:a.level});var b={data:[{level:v}],traces:[d.index]},_={frame:{redraw:!1,duration:h.transitionTime},transition:{duration:h.transitionTime,easing:h.transitionEasing},mode:"immediate",fromcurrent:!0};o.loneUnhover(e._hoverlayer.node()),i.call("animate",r,b,_)}}))}},{"../../components/fx":406,"../../components/fx/helpers":402,"../../lib":503,"../../lib/events":492,"../../registry":638,"../pie/helpers":906,"./helpers":1055,"@plotly/d3":58}],1055:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/color"),a=t("../../lib/setcursor"),o=t("../pie/helpers");function s(t){return t.data.data.pid}r.findEntryWithLevel=function(t,e){var n;return e&&t.eachAfter((function(t){if(r.getPtId(t)===e)return n=t.copy()})),n||t},r.findEntryWithChild=function(t,e){var n;return t.eachAfter((function(t){for(var i=t.children||[],a=0;a<i.length;a++){var o=i[a];if(r.getPtId(o)===e)return n=t.copy()}})),n||t},r.isEntry=function(t){return!t.parent},r.isLeaf=function(t){return!t.children},r.getPtId=function(t){return t.data.data.id},r.getPtLabel=function(t){return t.data.data.label},r.getValue=function(t){return t.value},r.isHierarchyRoot=function(t){return""===s(t)},r.setSliceCursor=function(t,e,n){var i=n.isTransitioning;if(!i){var o=t.datum();i=n.hideOnRoot&&r.isHierarchyRoot(o)||n.hideOnLeaves&&r.isLeaf(o)}a(t,i?null:"pointer")},r.getInsideTextFontKey=function(t,e,r,i,a){var o=(a||{}).onPathbar?"pathbar.textfont":"insidetextfont",s=r.data.data.i;return n.castOption(e,s,o+"."+t)||n.castOption(e,s,"textfont."+t)||i.size},r.getOutsideTextFontKey=function(t,e,r,i){var a=r.data.data.i;return n.castOption(e,a,"outsidetextfont."+t)||n.castOption(e,a,"textfont."+t)||i.size},r.isOutsideText=function(t,e){return!t._hasColorscale&&r.isHierarchyRoot(e)},r.determineTextFont=function(t,e,a,o){return r.isOutsideText(t,e)?function(t,e,n){return{color:r.getOutsideTextFontKey("color",t,e,n),family:r.getOutsideTextFontKey("family",t,e,n),size:r.getOutsideTextFontKey("size",t,e,n)}}(t,e,a):function(t,e,a,o){var s=(o||{}).onPathbar,l=e.data.data,c=l.i,u=n.castOption(t,c,(s?"pathbar.textfont":"insidetextfont")+".color");return!u&&t._input.textfont&&(u=n.castOption(t._input,c,"textfont.color")),{color:u||i.contrast(l.color),family:r.getInsideTextFontKey("family",t,e,a,o),size:r.getInsideTextFontKey("size",t,e,a,o)}}(t,e,a,o)},r.hasTransition=function(t){return!!(t&&t.duration>0)},r.getMaxDepth=function(t){return t.maxdepth>=0?t.maxdepth:1/0},r.isHeader=function(t,e){return!(r.isLeaf(t)||t.depth===e._maxDepth-1)},r.getParent=function(t,e){return r.findEntryWithLevel(t,s(e))},r.listPath=function(t,e){var n=t.parent;if(!n)return[];var i=e?[n.data[e]]:[n];return r.listPath(n,e).concat(i)},r.getPath=function(t){return r.listPath(t,"label").join("/")+"/"},r.formatValue=o.formatPieValue,r.formatPercent=function(t,e){var r=n.formatPercent(t,0);return"0%"===r&&(r=o.formatPiePercent(t,e)),r}},{"../../components/color":366,"../../lib":503,"../../lib/setcursor":524,"../pie/helpers":906}],1056:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"sunburst",basePlotModule:t("./base_plot"),categories:[],animatable:!0,attributes:t("./attributes"),layoutAttributes:t("./layout_attributes"),supplyDefaults:t("./defaults"),supplyLayoutDefaults:t("./layout_defaults"),calc:t("./calc").calc,crossTraceCalc:t("./calc").crossTraceCalc,plot:t("./plot").plot,style:t("./style").style,colorbar:t("../scatter/marker_colorbar"),meta:{}}},{"../scatter/marker_colorbar":945,"./attributes":1049,"./base_plot":1050,"./calc":1051,"./defaults":1053,"./layout_attributes":1057,"./layout_defaults":1058,"./plot":1059,"./style":1060}],1057:[function(t,e,r){"use strict";e.exports={sunburstcolorway:{valType:"colorlist",editType:"calc"},extendsunburstcolors:{valType:"boolean",dflt:!0,editType:"calc"}}},{}],1058:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./layout_attributes");e.exports=function(t,e){function r(r,a){return n.coerce(t,e,i,r,a)}r("sunburstcolorway",e.colorway),r("extendsunburstcolors")}},{"../../lib":503,"./layout_attributes":1057}],1059:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("d3-hierarchy"),a=t("d3-interpolate").interpolate,o=t("../../components/drawing"),s=t("../../lib"),l=t("../../lib/svg_text_utils"),c=t("../bar/uniform_text"),u=c.recordMinTextSize,f=c.clearMinTextSize,h=t("../pie/plot"),p=t("../pie/helpers").getRotationAngle,d=h.computeTransform,m=h.transformInsideText,g=t("./style").styleOne,v=t("../bar/style").resizeText,y=t("./fx"),x=t("./constants"),b=t("./helpers");function _(t,e,c,f){var h=t._fullLayout,v=!h.uniformtext.mode&&b.hasTransition(f),_=n.select(c).selectAll("g.slice"),T=e[0],k=T.trace,A=T.hierarchy,M=b.findEntryWithLevel(A,k.level),S=b.getMaxDepth(k),E=h._size,L=k.domain,C=E.w*(L.x[1]-L.x[0]),P=E.h*(L.y[1]-L.y[0]),I=.5*Math.min(C,P),O=T.cx=E.l+E.w*(L.x[1]+L.x[0])/2,z=T.cy=E.t+E.h*(1-L.y[0])-P/2;if(!M)return _.remove();var D=null,R={};v&&_.each((function(t){R[b.getPtId(t)]={rpx0:t.rpx0,rpx1:t.rpx1,x0:t.x0,x1:t.x1,transform:t.transform},!D&&b.isEntry(t)&&(D=t)}));var F=function(t){return i.partition().size([2*Math.PI,t.height+1])(t)}(M).descendants(),B=M.height+1,N=0,j=S;T.hasMultipleRoots&&b.isHierarchyRoot(M)&&(F=F.slice(1),B-=1,N=1,j+=1),F=F.filter((function(t){return t.y1<=j}));var U=p(k.rotation);U&&F.forEach((function(t){t.x0+=U,t.x1+=U}));var V=Math.min(B,S),H=function(t){return(t-N)/V*I},q=function(t,e){return[t*Math.cos(e),-t*Math.sin(e)]},G=function(t){return s.pathAnnulus(t.rpx0,t.rpx1,t.x0,t.x1,O,z)},Y=function(t){return O+w(t)[0]*(t.transform.rCenter||0)+(t.transform.x||0)},W=function(t){return z+w(t)[1]*(t.transform.rCenter||0)+(t.transform.y||0)};(_=_.data(F,b.getPtId)).enter().append("g").classed("slice",!0),v?_.exit().transition().each((function(){var t=n.select(this);t.select("path.surface").transition().attrTween("d",(function(t){var e=function(t){var e,r=b.getPtId(t),n=R[r],i=R[b.getPtId(M)];if(i){var o=(t.x1>i.x1?2*Math.PI:0)+U;e=t.rpx1<i.rpx1?{x0:t.x0,x1:t.x1,rpx0:0,rpx1:0}:{x0:o,x1:o,rpx0:t.rpx0,rpx1:t.rpx1}}else{var s,l=b.getPtId(t.parent);_.each((function(t){if(b.getPtId(t)===l)return s=t}));var c,u=s.children;u.forEach((function(t,e){if(b.getPtId(t)===r)return c=e}));var f=u.length,h=a(s.x0,s.x1);e={rpx0:I,rpx1:I,x0:h(c/f),x1:h((c+1)/f)}}return a(n,e)}(t);return function(t){return G(e(t))}})),t.select("g.slicetext").attr("opacity",0)})).remove():_.exit().remove(),_.order();var X=null;if(v&&D){var Z=b.getPtId(D);_.each((function(t){null===X&&b.getPtId(t)===Z&&(X=t.x1)}))}var J=_;function K(t){var e=t.parent,r=R[b.getPtId(e)],n={};if(r){var i=e.children,o=i.indexOf(t),s=i.length,l=a(r.x0,r.x1);n.x0=l(o/s),n.x1=l(o/s)}else n.x0=n.x1=0;return n}v&&(J=J.transition().each("end",(function(){var e=n.select(this);b.setSliceCursor(e,t,{hideOnRoot:!0,hideOnLeaves:!0,isTransitioning:!1})}))),J.each((function(i){var c=n.select(this),f=s.ensureSingle(c,"path","surface",(function(t){t.style("pointer-events","all")}));i.rpx0=H(i.y0),i.rpx1=H(i.y1),i.xmid=(i.x0+i.x1)/2,i.pxmid=q(i.rpx1,i.xmid),i.midangle=-(i.xmid-Math.PI/2),i.startangle=-(i.x0-Math.PI/2),i.stopangle=-(i.x1-Math.PI/2),i.halfangle=.5*Math.min(s.angleDelta(i.x0,i.x1)||Math.PI,Math.PI),i.ring=1-i.rpx0/i.rpx1,i.rInscribed=function(t){return 0===t.rpx0&&s.isFullCircle([t.x0,t.x1])?1:Math.max(0,Math.min(1/(1+1/Math.sin(t.halfangle)),t.ring/2))}(i),v?f.transition().attrTween("d",(function(t){var e=function(t){var e,r=R[b.getPtId(t)],n={x0:t.x0,x1:t.x1,rpx0:t.rpx0,rpx1:t.rpx1};if(r)e=r;else if(D)if(t.parent)if(X){var i=(t.x1>X?2*Math.PI:0)+U;e={x0:i,x1:i}}else e={rpx0:I,rpx1:I},s.extendFlat(e,K(t));else e={rpx0:0,rpx1:0};else e={x0:U,x1:U};return a(e,n)}(t);return function(t){return G(e(t))}})):f.attr("d",G),c.call(y,M,t,e,{eventDataKeys:x.eventDataKeys,transitionTime:x.CLICK_TRANSITION_TIME,transitionEasing:x.CLICK_TRANSITION_EASING}).call(b.setSliceCursor,t,{hideOnRoot:!0,hideOnLeaves:!0,isTransitioning:t._transitioning}),f.call(g,i,k);var p=s.ensureSingle(c,"g","slicetext"),_=s.ensureSingle(p,"text","",(function(t){t.attr("data-notex",1)})),w=s.ensureUniformFontSize(t,b.determineTextFont(k,i,h.font));_.text(r.formatSliceLabel(i,M,k,e,h)).classed("slicetext",!0).attr("text-anchor","middle").call(o.font,w).call(l.convertToTspans,t);var A=o.bBox(_.node());i.transform=m(A,i,T),i.transform.targetX=Y(i),i.transform.targetY=W(i);var S=function(t,e){var r=t.transform;return d(r,e),r.fontSize=w.size,u(k.type,r,h),s.getTextTransform(r)};v?_.transition().attrTween("transform",(function(t){var e=function(t){var e,r=R[b.getPtId(t)],n=t.transform;if(r)e=r;else if(e={rpx1:t.rpx1,transform:{textPosAngle:n.textPosAngle,scale:0,rotate:n.rotate,rCenter:n.rCenter,x:n.x,y:n.y}},D)if(t.parent)if(X){var i=t.x1>X?2*Math.PI:0;e.x0=e.x1=i}else s.extendFlat(e,K(t));else e.x0=e.x1=U;else e.x0=e.x1=U;var o=a(e.transform.textPosAngle,t.transform.textPosAngle),l=a(e.rpx1,t.rpx1),c=a(e.x0,t.x0),f=a(e.x1,t.x1),p=a(e.transform.scale,n.scale),d=a(e.transform.rotate,n.rotate),m=0===n.rCenter?3:0===e.transform.rCenter?1/3:1,g=a(e.transform.rCenter,n.rCenter);return function(t){var e=l(t),r=c(t),i=f(t),a=function(t){return g(Math.pow(t,m))}(t),s={pxmid:q(e,(r+i)/2),rpx1:e,transform:{textPosAngle:o(t),rCenter:a,x:n.x,y:n.y}};return u(k.type,n,h),{transform:{targetX:Y(s),targetY:W(s),scale:p(t),rotate:d(t),rCenter:a}}}}(t);return function(t){return S(e(t),A)}})):_.attr("transform",S(i,A))}))}function w(t){return e=t.rpx1,r=t.transform.textPosAngle,[e*Math.sin(r),-e*Math.cos(r)];var e,r}r.plot=function(t,e,r,i){var a,o,s=t._fullLayout,l=s._sunburstlayer,c=!r,u=!s.uniformtext.mode&&b.hasTransition(r);(f("sunburst",s),(a=l.selectAll("g.trace.sunburst").data(e,(function(t){return t[0].trace.uid}))).enter().append("g").classed("trace",!0).classed("sunburst",!0).attr("stroke-linejoin","round"),a.order(),u)?(i&&(o=i()),n.transition().duration(r.duration).ease(r.easing).each("end",(function(){o&&o()})).each("interrupt",(function(){o&&o()})).each((function(){l.selectAll("g.trace").each((function(e){_(t,e,this,r)}))}))):(a.each((function(e){_(t,e,this,r)})),s.uniformtext.mode&&v(t,s._sunburstlayer.selectAll(".trace"),"sunburst"));c&&a.exit().remove()},r.formatSliceLabel=function(t,e,r,n,i){var a=r.texttemplate,o=r.textinfo;if(!(a||o&&"none"!==o))return"";var l=i.separators,c=n[0],u=t.data.data,f=c.hierarchy,h=b.isHierarchyRoot(t),p=b.getParent(f,t),d=b.getValue(t);if(!a){var m,g=o.split("+"),v=function(t){return-1!==g.indexOf(t)},y=[];if(v("label")&&u.label&&y.push(u.label),u.hasOwnProperty("v")&&v("value")&&y.push(b.formatValue(u.v,l)),!h){v("current path")&&y.push(b.getPath(t.data));var x=0;v("percent parent")&&x++,v("percent entry")&&x++,v("percent root")&&x++;var _=x>1;if(x){var w,T=function(t){m=b.formatPercent(w,l),_&&(m+=" of "+t),y.push(m)};v("percent parent")&&!h&&(w=d/b.getValue(p),T("parent")),v("percent entry")&&(w=d/b.getValue(e),T("entry")),v("percent root")&&(w=d/b.getValue(f),T("root"))}}return v("text")&&(m=s.castOption(r,u.i,"text"),s.isValidTextValue(m)&&y.push(m)),y.join("<br>")}var k=s.castOption(r,u.i,"texttemplate");if(!k)return"";var A={};u.label&&(A.label=u.label),u.hasOwnProperty("v")&&(A.value=u.v,A.valueLabel=b.formatValue(u.v,l)),A.currentPath=b.getPath(t.data),h||(A.percentParent=d/b.getValue(p),A.percentParentLabel=b.formatPercent(A.percentParent,l),A.parent=b.getPtLabel(p)),A.percentEntry=d/b.getValue(e),A.percentEntryLabel=b.formatPercent(A.percentEntry,l),A.entry=b.getPtLabel(e),A.percentRoot=d/b.getValue(f),A.percentRootLabel=b.formatPercent(A.percentRoot,l),A.root=b.getPtLabel(f),u.hasOwnProperty("color")&&(A.color=u.color);var M=s.castOption(r,u.i,"text");return(s.isValidTextValue(M)||""===M)&&(A.text=M),A.customdata=s.castOption(r,u.i,"customdata"),s.texttemplateString(k,A,i._d3locale,A,r._meta||{})}},{"../../components/drawing":388,"../../lib":503,"../../lib/svg_text_utils":529,"../bar/style":662,"../bar/uniform_text":664,"../pie/helpers":906,"../pie/plot":910,"./constants":1052,"./fx":1054,"./helpers":1055,"./style":1060,"@plotly/d3":58,"d3-hierarchy":115,"d3-interpolate":116}],1060:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/color"),a=t("../../lib"),o=t("../bar/uniform_text").resizeText;function s(t,e,r){var n=e.data.data,o=!e.children,s=n.i,l=a.castOption(r,s,"marker.line.color")||i.defaultLine,c=a.castOption(r,s,"marker.line.width")||0;t.style("stroke-width",c).call(i.fill,n.color).call(i.stroke,l).style("opacity",o?r.leaf.opacity:null)}e.exports={style:function(t){var e=t._fullLayout._sunburstlayer.selectAll(".trace");o(t,e,"sunburst"),e.each((function(t){var e=n.select(this),r=t[0].trace;e.style("opacity",r.opacity),e.selectAll("path.surface").each((function(t){n.select(this).call(s,t,r)}))}))},styleOne:s}},{"../../components/color":366,"../../lib":503,"../bar/uniform_text":664,"@plotly/d3":58}],1061:[function(t,e,r){"use strict";var n=t("../../components/color"),i=t("../../components/colorscale/attributes"),a=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,o=t("../../plots/template_attributes").hovertemplateAttrs,s=t("../../plots/attributes"),l=t("../../lib/extend").extendFlat,c=t("../../plot_api/edit_types").overrideAll;function u(t){return{show:{valType:"boolean",dflt:!1},start:{valType:"number",dflt:null,editType:"plot"},end:{valType:"number",dflt:null,editType:"plot"},size:{valType:"number",dflt:null,min:0,editType:"plot"},project:{x:{valType:"boolean",dflt:!1},y:{valType:"boolean",dflt:!1},z:{valType:"boolean",dflt:!1}},color:{valType:"color",dflt:n.defaultLine},usecolormap:{valType:"boolean",dflt:!1},width:{valType:"number",min:1,max:16,dflt:2},highlight:{valType:"boolean",dflt:!0},highlightcolor:{valType:"color",dflt:n.defaultLine},highlightwidth:{valType:"number",min:1,max:16,dflt:2}}}var f=e.exports=c(l({z:{valType:"data_array"},x:{valType:"data_array"},y:{valType:"data_array"},text:{valType:"string",dflt:"",arrayOk:!0},hovertext:{valType:"string",dflt:"",arrayOk:!0},hovertemplate:o(),xhoverformat:a("x"),yhoverformat:a("y"),zhoverformat:a("z"),connectgaps:{valType:"boolean",dflt:!1,editType:"calc"},surfacecolor:{valType:"data_array"}},i("",{colorAttr:"z or surfacecolor",showScaleDflt:!0,autoColorDflt:!1,editTypeOverride:"calc"}),{contours:{x:u(),y:u(),z:u()},hidesurface:{valType:"boolean",dflt:!1},lightposition:{x:{valType:"number",min:-1e5,max:1e5,dflt:10},y:{valType:"number",min:-1e5,max:1e5,dflt:1e4},z:{valType:"number",min:-1e5,max:1e5,dflt:0}},lighting:{ambient:{valType:"number",min:0,max:1,dflt:.8},diffuse:{valType:"number",min:0,max:1,dflt:.8},specular:{valType:"number",min:0,max:2,dflt:.05},roughness:{valType:"number",min:0,max:1,dflt:.5},fresnel:{valType:"number",min:0,max:5,dflt:.2}},opacity:{valType:"number",min:0,max:1,dflt:1},opacityscale:{valType:"any",editType:"calc"},_deprecated:{zauto:l({},i.zauto,{}),zmin:l({},i.zmin,{}),zmax:l({},i.zmax,{})},hoverinfo:l({},s.hoverinfo),showlegend:l({},s.showlegend,{dflt:!1})}),"calc","nested");f.x.editType=f.y.editType=f.z.editType="calc+clearAxisTypes",f.transforms=void 0},{"../../components/color":366,"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plot_api/edit_types":536,"../../plots/attributes":550,"../../plots/cartesian/axis_format_attributes":557,"../../plots/template_attributes":633}],1062:[function(t,e,r){"use strict";var n=t("../../components/colorscale/calc");e.exports=function(t,e){e.surfacecolor?n(t,e,{vals:e.surfacecolor,containerStr:"",cLetter:"c"}):n(t,e,{vals:e.z,containerStr:"",cLetter:"c"})}},{"../../components/colorscale/calc":374}],1063:[function(t,e,r){"use strict";var n=t("../../../stackgl_modules").gl_surface3d,i=t("../../../stackgl_modules").ndarray,a=t("../../../stackgl_modules").ndarray_linear_interpolate.d2,o=t("../heatmap/interp2d"),s=t("../heatmap/find_empties"),l=t("../../lib").isArrayOrTypedArray,c=t("../../lib/gl_format_color").parseColorScale,u=t("../../lib/str2rgbarray"),f=t("../../components/colorscale").extractOpts;function h(t,e,r){this.scene=t,this.uid=r,this.surface=e,this.data=null,this.showContour=[!1,!1,!1],this.contourStart=[null,null,null],this.contourEnd=[null,null,null],this.contourSize=[0,0,0],this.minValues=[1/0,1/0,1/0],this.maxValues=[-1/0,-1/0,-1/0],this.dataScaleX=1,this.dataScaleY=1,this.refineData=!0,this.objectOffset=[0,0,0]}var p=h.prototype;p.getXat=function(t,e,r,n){var i=l(this.data.x)?l(this.data.x[0])?this.data.x[e][t]:this.data.x[t]:t;return void 0===r?i:n.d2l(i,0,r)},p.getYat=function(t,e,r,n){var i=l(this.data.y)?l(this.data.y[0])?this.data.y[e][t]:this.data.y[e]:e;return void 0===r?i:n.d2l(i,0,r)},p.getZat=function(t,e,r,n){var i=this.data.z[e][t];return null===i&&this.data.connectgaps&&this.data._interpolatedZ&&(i=this.data._interpolatedZ[e][t]),void 0===r?i:n.d2l(i,0,r)},p.handlePick=function(t){if(t.object===this.surface){var e=(t.data.index[0]-1)/this.dataScaleX-1,r=(t.data.index[1]-1)/this.dataScaleY-1,n=Math.max(Math.min(Math.round(e),this.data.z[0].length-1),0),i=Math.max(Math.min(Math.round(r),this.data._ylength-1),0);t.index=[n,i],t.traceCoordinate=[this.getXat(n,i),this.getYat(n,i),this.getZat(n,i)],t.dataCoordinate=[this.getXat(n,i,this.data.xcalendar,this.scene.fullSceneLayout.xaxis),this.getYat(n,i,this.data.ycalendar,this.scene.fullSceneLayout.yaxis),this.getZat(n,i,this.data.zcalendar,this.scene.fullSceneLayout.zaxis)];for(var a=0;a<3;a++){var o=t.dataCoordinate[a];null!=o&&(t.dataCoordinate[a]*=this.scene.dataScale[a])}var s=this.data.hovertext||this.data.text;return Array.isArray(s)&&s[i]&&void 0!==s[i][n]?t.textLabel=s[i][n]:t.textLabel=s||"",t.data.dataCoordinate=t.dataCoordinate.slice(),this.surface.highlight(t.data),this.scene.glplot.spikes.position=t.dataCoordinate,!0}};var d=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,1601,1607,1609,1613,1619,1621,1627,1637,1657,1663,1667,1669,1693,1697,1699,1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,1787,1789,1801,1811,1823,1831,1847,1861,1867,1871,1873,1877,1879,1889,1901,1907,1913,1931,1933,1949,1951,1973,1979,1987,1993,1997,1999,2003,2011,2017,2027,2029,2039,2053,2063,2069,2081,2083,2087,2089,2099,2111,2113,2129,2131,2137,2141,2143,2153,2161,2179,2203,2207,2213,2221,2237,2239,2243,2251,2267,2269,2273,2281,2287,2293,2297,2309,2311,2333,2339,2341,2347,2351,2357,2371,2377,2381,2383,2389,2393,2399,2411,2417,2423,2437,2441,2447,2459,2467,2473,2477,2503,2521,2531,2539,2543,2549,2551,2557,2579,2591,2593,2609,2617,2621,2633,2647,2657,2659,2663,2671,2677,2683,2687,2689,2693,2699,2707,2711,2713,2719,2729,2731,2741,2749,2753,2767,2777,2789,2791,2797,2801,2803,2819,2833,2837,2843,2851,2857,2861,2879,2887,2897,2903,2909,2917,2927,2939,2953,2957,2963,2969,2971,2999];function m(t,e){if(t<e)return 0;for(var r=0;0===Math.floor(t%e);)t/=e,r++;return r}function g(t){for(var e=[],r=0;r<d.length;r++){var n=d[r];e.push(m(t,n))}return e}function v(t){for(var e=g(t),r=t,n=0;n<d.length;n++)if(e[n]>0){r=d[n];break}return r}function y(t,e){if(!(t<1||e<1)){for(var r=g(t),n=g(e),i=1,a=0;a<d.length;a++)i*=Math.pow(d[a],Math.max(r[a],n[a]));return i}}p.calcXnums=function(t){var e,r=[];for(e=1;e<t;e++){var n=this.getXat(e-1,0),i=this.getXat(e,0);r[e-1]=i!==n&&null!=n&&null!=i?Math.abs(i-n):0}var a=0;for(e=1;e<t;e++)a+=r[e-1];for(e=1;e<t;e++)0===r[e-1]?r[e-1]=1:r[e-1]=Math.round(a/r[e-1]);return r},p.calcYnums=function(t){var e,r=[];for(e=1;e<t;e++){var n=this.getYat(0,e-1),i=this.getYat(0,e);r[e-1]=i!==n&&null!=n&&null!=i?Math.abs(i-n):0}var a=0;for(e=1;e<t;e++)a+=r[e-1];for(e=1;e<t;e++)0===r[e-1]?r[e-1]=1:r[e-1]=Math.round(a/r[e-1]);return r};var x=[1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260],b=x[9],_=x[13];function w(t,e,r){var n=r[8]+r[2]*e[0]+r[5]*e[1];return t[0]=(r[6]+r[0]*e[0]+r[3]*e[1])/n,t[1]=(r[7]+r[1]*e[0]+r[4]*e[1])/n,t}function T(t,e,r){return function(t,e,r,n){for(var i=[0,0],o=t.shape[0],s=t.shape[1],l=0;l<o;l++)for(var c=0;c<s;c++)r(i,[l,c],n),t.set(l,c,a(e,i[0],i[1]))}(t,e,w,r),t}function k(t,e){for(var r=!1,n=0;n<t.length;n++)if(e===t[n]){r=!0;break}!1===r&&t.push(e)}p.estimateScale=function(t,e){for(var r=1+function(t){if(0!==t.length){for(var e=1,r=0;r<t.length;r++)e=y(e,t[r]);return e}}(0===e?this.calcXnums(t):this.calcYnums(t));r<b;)r*=2;for(;r>_;)r--,r/=v(r),++r<b&&(r=_);var n=Math.round(r/t);return n>1?n:1},p.refineCoords=function(t){for(var e=this.dataScaleX,r=this.dataScaleY,n=t[0].shape[0],a=t[0].shape[1],o=0|Math.floor(t[0].shape[0]*e+1),s=0|Math.floor(t[0].shape[1]*r+1),l=1+n+1,c=1+a+1,u=i(new Float32Array(l*c),[l,c]),f=[1/e,0,0,0,1/r,0,0,0,1],h=0;h<t.length;++h){this.surface.padField(u,t[h]);var p=i(new Float32Array(o*s),[o,s]);T(p,u,f),t[h]=p}},p.setContourLevels=function(){var t,e,r,n=[[],[],[]],i=[!1,!1,!1],a=!1;for(t=0;t<3;++t)if(this.showContour[t]&&(a=!0,this.contourSize[t]>0&&null!==this.contourStart[t]&&null!==this.contourEnd[t]&&this.contourEnd[t]>this.contourStart[t]))for(i[t]=!0,e=this.contourStart[t];e<this.contourEnd[t];e+=this.contourSize[t])r=e*this.scene.dataScale[t],k(n[t],r);if(a){var o=[[],[],[]];for(t=0;t<3;++t)this.showContour[t]&&(o[t]=i[t]?n[t]:this.scene.contourLevels[t]);this.surface.update({levels:o})}},p.update=function(t){var e,r,n,a,l=this.scene,h=l.fullSceneLayout,p=this.surface,d=c(t),m=l.dataScale,g=t.z[0].length,v=t._ylength,y=l.contourLevels;this.data=t;var x=[];for(e=0;e<3;e++)for(x[e]=[],r=0;r<g;r++)x[e][r]=[];for(r=0;r<g;r++)for(n=0;n<v;n++)x[0][r][n]=this.getXat(r,n,t.xcalendar,h.xaxis),x[1][r][n]=this.getYat(r,n,t.ycalendar,h.yaxis),x[2][r][n]=this.getZat(r,n,t.zcalendar,h.zaxis);if(t.connectgaps)for(t._emptypoints=s(x[2]),o(x[2],t._emptypoints),t._interpolatedZ=[],r=0;r<g;r++)for(t._interpolatedZ[r]=[],n=0;n<v;n++)t._interpolatedZ[r][n]=x[2][r][n];for(e=0;e<3;e++)for(r=0;r<g;r++)for(n=0;n<v;n++)null==(a=x[e][r][n])?x[e][r][n]=NaN:a=x[e][r][n]*=m[e];for(e=0;e<3;e++)for(r=0;r<g;r++)for(n=0;n<v;n++)null!=(a=x[e][r][n])&&(this.minValues[e]>a&&(this.minValues[e]=a),this.maxValues[e]<a&&(this.maxValues[e]=a));for(e=0;e<3;e++)this.objectOffset[e]=.5*(this.minValues[e]+this.maxValues[e]);for(e=0;e<3;e++)for(r=0;r<g;r++)for(n=0;n<v;n++)null!=(a=x[e][r][n])&&(x[e][r][n]-=this.objectOffset[e]);var b=[i(new Float32Array(g*v),[g,v]),i(new Float32Array(g*v),[g,v]),i(new Float32Array(g*v),[g,v])];for(e=0;e<3;e++)for(r=0;r<g;r++)for(n=0;n<v;n++)b[e].set(r,n,x[e][r][n]);x=[];var w={colormap:d,levels:[[],[],[]],showContour:[!0,!0,!0],showSurface:!t.hidesurface,contourProject:[[!1,!1,!1],[!1,!1,!1],[!1,!1,!1]],contourWidth:[1,1,1],contourColor:[[1,1,1,1],[1,1,1,1],[1,1,1,1]],contourTint:[1,1,1],dynamicColor:[[1,1,1,1],[1,1,1,1],[1,1,1,1]],dynamicWidth:[1,1,1],dynamicTint:[1,1,1],opacityscale:t.opacityscale,opacity:t.opacity},T=f(t);if(w.intensityBounds=[T.min,T.max],t.surfacecolor){var k=i(new Float32Array(g*v),[g,v]);for(r=0;r<g;r++)for(n=0;n<v;n++)k.set(r,n,t.surfacecolor[n][r]);b.push(k)}else w.intensityBounds[0]*=m[2],w.intensityBounds[1]*=m[2];(_<b[0].shape[0]||_<b[0].shape[1])&&(this.refineData=!1),!0===this.refineData&&(this.dataScaleX=this.estimateScale(b[0].shape[0],0),this.dataScaleY=this.estimateScale(b[0].shape[1],1),1===this.dataScaleX&&1===this.dataScaleY||this.refineCoords(b)),t.surfacecolor&&(w.intensity=b.pop());var A=[!0,!0,!0],M=["x","y","z"];for(e=0;e<3;++e){var S=t.contours[M[e]];A[e]=S.highlight,w.showContour[e]=S.show||S.highlight,w.showContour[e]&&(w.contourProject[e]=[S.project.x,S.project.y,S.project.z],S.show?(this.showContour[e]=!0,w.levels[e]=y[e],p.highlightColor[e]=w.contourColor[e]=u(S.color),S.usecolormap?p.highlightTint[e]=w.contourTint[e]=0:p.highlightTint[e]=w.contourTint[e]=1,w.contourWidth[e]=S.width,this.contourStart[e]=S.start,this.contourEnd[e]=S.end,this.contourSize[e]=S.size):(this.showContour[e]=!1,this.contourStart[e]=null,this.contourEnd[e]=null,this.contourSize[e]=0),S.highlight&&(w.dynamicColor[e]=u(S.highlightcolor),w.dynamicWidth[e]=S.highlightwidth))}(function(t){var e=t[0].rgb,r=t[t.length-1].rgb;return e[0]===r[0]&&e[1]===r[1]&&e[2]===r[2]&&e[3]===r[3]})(d)&&(w.vertexColor=!0),w.objectOffset=this.objectOffset,w.coords=b,p.update(w),p.visible=t.visible,p.enableDynamic=A,p.enableHighlight=A,p.snapToData=!0,"lighting"in t&&(p.ambientLight=t.lighting.ambient,p.diffuseLight=t.lighting.diffuse,p.specularLight=t.lighting.specular,p.roughness=t.lighting.roughness,p.fresnel=t.lighting.fresnel),"lightposition"in t&&(p.lightPosition=[t.lightposition.x,t.lightposition.y,t.lightposition.z])},p.dispose=function(){this.scene.glplot.remove(this.surface),this.surface.dispose()},e.exports=function(t,e){var r=t.glplot.gl,i=n({gl:r}),a=new h(t,i,e.uid);return i._trace=a,a.update(e),t.glplot.add(i),a}},{"../../../stackgl_modules":1124,"../../components/colorscale":378,"../../lib":503,"../../lib/gl_format_color":499,"../../lib/str2rgbarray":528,"../heatmap/find_empties":798,"../heatmap/interp2d":801}],1064:[function(t,e,r){"use strict";var n=t("../../registry"),i=t("../../lib"),a=t("../../components/colorscale/defaults"),o=t("./attributes");function s(t,e,r,n){var i=n("opacityscale");"max"===i?e.opacityscale=[[0,.1],[1,1]]:"min"===i?e.opacityscale=[[0,1],[1,.1]]:"extremes"===i?e.opacityscale=function(t,e){for(var r=[],n=0;n<32;n++){var i=n/31,a=e+(1-e)*(1-Math.pow(Math.sin(t*i*Math.PI),2));r.push([i,Math.max(0,Math.min(1,a))])}return r}(1,.1):function(t){var e=0;if(!Array.isArray(t)||t.length<2)return!1;if(!t[0]||!t[t.length-1])return!1;if(0!=+t[0][0]||1!=+t[t.length-1][0])return!1;for(var r=0;r<t.length;r++){var n=t[r];if(2!==n.length||+n[0]<e)return!1;e=+n[0]}return!0}(i)||(e.opacityscale=void 0)}function l(t,e,r){e in t&&!(r in t)&&(t[r]=t[e])}e.exports={supplyDefaults:function(t,e,r,c){var u,f;function h(r,n){return i.coerce(t,e,o,r,n)}var p=h("x"),d=h("y"),m=h("z");if(!m||!m.length||p&&p.length<1||d&&d.length<1)e.visible=!1;else{e._xlength=Array.isArray(p)&&i.isArrayOrTypedArray(p[0])?m.length:m[0].length,e._ylength=m.length,n.getComponentMethod("calendars","handleTraceDefaults")(t,e,["x","y","z"],c),h("text"),h("hovertext"),h("hovertemplate"),h("xhoverformat"),h("yhoverformat"),h("zhoverformat"),["lighting.ambient","lighting.diffuse","lighting.specular","lighting.roughness","lighting.fresnel","lightposition.x","lightposition.y","lightposition.z","hidesurface","connectgaps","opacity"].forEach((function(t){h(t)}));var g=h("surfacecolor"),v=["x","y","z"];for(u=0;u<3;++u){var y="contours."+v[u],x=h(y+".show"),b=h(y+".highlight");if(x||b)for(f=0;f<3;++f)h(y+".project."+v[f]);x&&(h(y+".color"),h(y+".width"),h(y+".usecolormap")),b&&(h(y+".highlightcolor"),h(y+".highlightwidth")),h(y+".start"),h(y+".end"),h(y+".size")}g||(l(t,"zmin","cmin"),l(t,"zmax","cmax"),l(t,"zauto","cauto")),a(t,e,c,h,{prefix:"",cLetter:"c"}),s(t,e,c,h),e._length=null}},opacityscaleDefaults:s}},{"../../components/colorscale/defaults":376,"../../lib":503,"../../registry":638,"./attributes":1061}],1065:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults").supplyDefaults,colorbar:{min:"cmin",max:"cmax"},calc:t("./calc"),plot:t("./convert"),moduleType:"trace",name:"surface",basePlotModule:t("../../plots/gl3d"),categories:["gl3d","2dMap","showLegend"],meta:{}}},{"../../plots/gl3d":598,"./attributes":1061,"./calc":1062,"./convert":1063,"./defaults":1064}],1066:[function(t,e,r){"use strict";var n=t("../../components/annotations/attributes"),i=t("../../lib/extend").extendFlat,a=t("../../plot_api/edit_types").overrideAll,o=t("../../plots/font_attributes"),s=t("../../plots/domain").attributes,l=t("../../plots/cartesian/axis_format_attributes").descriptionOnlyNumbers;(e.exports=a({domain:s({name:"table",trace:!0}),columnwidth:{valType:"number",arrayOk:!0,dflt:null},columnorder:{valType:"data_array"},header:{values:{valType:"data_array",dflt:[]},format:{valType:"data_array",dflt:[],description:l("cell value")},prefix:{valType:"string",arrayOk:!0,dflt:null},suffix:{valType:"string",arrayOk:!0,dflt:null},height:{valType:"number",dflt:28},align:i({},n.align,{arrayOk:!0}),line:{width:{valType:"number",arrayOk:!0,dflt:1},color:{valType:"color",arrayOk:!0,dflt:"grey"}},fill:{color:{valType:"color",arrayOk:!0,dflt:"white"}},font:i({},o({arrayOk:!0}))},cells:{values:{valType:"data_array",dflt:[]},format:{valType:"data_array",dflt:[],description:l("cell value")},prefix:{valType:"string",arrayOk:!0,dflt:null},suffix:{valType:"string",arrayOk:!0,dflt:null},height:{valType:"number",dflt:20},align:i({},n.align,{arrayOk:!0}),line:{width:{valType:"number",arrayOk:!0,dflt:1},color:{valType:"color",arrayOk:!0,dflt:"grey"}},fill:{color:{valType:"color",arrayOk:!0,dflt:"white"}},font:i({},o({arrayOk:!0}))}},"calc","from-root")).transforms=void 0},{"../../components/annotations/attributes":349,"../../lib/extend":493,"../../plot_api/edit_types":536,"../../plots/cartesian/axis_format_attributes":557,"../../plots/domain":584,"../../plots/font_attributes":585}],1067:[function(t,e,r){"use strict";var n=t("../../plots/get_data").getModuleCalcData,i=t("./plot");r.name="table",r.plot=function(t){var e=n(t.calcdata,"table")[0];e.length&&i(t,e)},r.clean=function(t,e,r,n){var i=n._has&&n._has("table"),a=e._has&&e._has("table");i&&!a&&n._paperdiv.selectAll(".table").remove()}},{"../../plots/get_data":593,"./plot":1074}],1068:[function(t,e,r){"use strict";var n=t("../../lib/gup").wrap;e.exports=function(){return n({})}},{"../../lib/gup":500}],1069:[function(t,e,r){"use strict";e.exports={cellPad:8,columnExtentOffset:10,columnTitleOffset:28,emptyHeaderHeight:16,latexCheck:/^\$.*\$$/,goldenRatio:1.618,lineBreaker:"<br>",maxDimensionCount:60,overdrag:45,releaseTransitionDuration:120,releaseTransitionEase:"cubic-out",scrollbarCaptureWidth:18,scrollbarHideDelay:1e3,scrollbarHideDuration:1e3,scrollbarOffset:5,scrollbarWidth:8,transitionDuration:100,transitionEase:"cubic-out",uplift:5,wrapSpacer:" ",wrapSplitCharacter:" ",cn:{table:"table",tableControlView:"table-control-view",scrollBackground:"scroll-background",yColumn:"y-column",columnBlock:"column-block",scrollAreaClip:"scroll-area-clip",scrollAreaClipRect:"scroll-area-clip-rect",columnBoundary:"column-boundary",columnBoundaryClippath:"column-boundary-clippath",columnBoundaryRect:"column-boundary-rect",columnCells:"column-cells",columnCell:"column-cell",cellRect:"cell-rect",cellText:"cell-text",cellTextHolder:"cell-text-holder",scrollbarKit:"scrollbar-kit",scrollbar:"scrollbar",scrollbarSlider:"scrollbar-slider",scrollbarGlyph:"scrollbar-glyph",scrollbarCaptureZone:"scrollbar-capture-zone"}}},{}],1070:[function(t,e,r){"use strict";var n=t("./constants"),i=t("../../lib/extend").extendFlat,a=t("fast-isnumeric");function o(t){if(Array.isArray(t)){for(var e=0,r=0;r<t.length;r++)e=Math.max(e,o(t[r]));return e}return t}function s(t,e){return t+e}function l(t){var e,r=t.slice(),n=1/0,i=0;for(e=0;e<r.length;e++)Array.isArray(r[e])||(r[e]=[r[e]]),n=Math.min(n,r[e].length),i=Math.max(i,r[e].length);if(n!==i)for(e=0;e<r.length;e++){var a=i-r[e].length;a&&(r[e]=r[e].concat(c(a)))}return r}function c(t){for(var e=new Array(t),r=0;r<t;r++)e[r]="";return e}function u(t){return t.calcdata.columns.reduce((function(e,r){return r.xIndex<t.xIndex?e+r.columnWidth:e}),0)}function f(t,e){return Object.keys(t).map((function(r){return i({},t[r],{auxiliaryBlocks:e})}))}function h(t,e){for(var r,n={},i=0,a=0,o={firstRowIndex:null,lastRowIndex:null,rows:[]},s=0,l=0,c=0;c<t.length;c++)r=t[c],o.rows.push({rowIndex:c,rowHeight:r}),((a+=r)>=e||c===t.length-1)&&(n[i]=o,o.key=l++,o.firstRowIndex=s,o.lastRowIndex=c,o={firstRowIndex:null,lastRowIndex:null,rows:[]},i+=a,s=c+1,a=0);return n}e.exports=function(t,e){var r=l(e.cells.values),p=function(t){return t.slice(e.header.values.length,t.length)},d=l(e.header.values);d.length&&!d[0].length&&(d[0]=[""],d=l(d));var m=d.concat(p(r).map((function(){return c((d[0]||[""]).length)}))),g=e.domain,v=Math.floor(t._fullLayout._size.w*(g.x[1]-g.x[0])),y=Math.floor(t._fullLayout._size.h*(g.y[1]-g.y[0])),x=e.header.values.length?m[0].map((function(){return e.header.height})):[n.emptyHeaderHeight],b=r.length?r[0].map((function(){return e.cells.height})):[],_=x.reduce(s,0),w=h(b,y-_+n.uplift),T=f(h(x,_),[]),k=f(w,T),A={},M=e._fullInput.columnorder.concat(p(r.map((function(t,e){return e})))),S=m.map((function(t,r){var n=Array.isArray(e.columnwidth)?e.columnwidth[Math.min(r,e.columnwidth.length-1)]:e.columnwidth;return a(n)?Number(n):1})),E=S.reduce(s,0);S=S.map((function(t){return t/E*v}));var L=Math.max(o(e.header.line.width),o(e.cells.line.width)),C={key:e.uid+t._context.staticPlot,translateX:g.x[0]*t._fullLayout._size.w,translateY:t._fullLayout._size.h*(1-g.y[1]),size:t._fullLayout._size,width:v,maxLineWidth:L,height:y,columnOrder:M,groupHeight:y,rowBlocks:k,headerRowBlocks:T,scrollY:0,cells:i({},e.cells,{values:r}),headerCells:i({},e.header,{values:m}),gdColumns:m.map((function(t){return t[0]})),gdColumnsOriginalOrder:m.map((function(t){return t[0]})),prevPages:[0,0],scrollbarState:{scrollbarScrollInProgress:!1},columns:m.map((function(t,e){var r=A[t];return A[t]=(r||0)+1,{key:t+"__"+A[t],label:t,specIndex:e,xIndex:M[e],xScale:u,x:void 0,calcdata:void 0,columnWidth:S[e]}}))};return C.columns.forEach((function(t){t.calcdata=C,t.x=u(t)})),C}},{"../../lib/extend":493,"./constants":1069,"fast-isnumeric":190}],1071:[function(t,e,r){"use strict";var n=t("../../lib/extend").extendFlat;r.splitToPanels=function(t){var e=[0,0],r=n({},t,{key:"header",type:"header",page:0,prevPages:e,currentRepaint:[null,null],dragHandle:!0,values:t.calcdata.headerCells.values[t.specIndex],rowBlocks:t.calcdata.headerRowBlocks,calcdata:n({},t.calcdata,{cells:t.calcdata.headerCells})});return[n({},t,{key:"cells1",type:"cells",page:0,prevPages:e,currentRepaint:[null,null],dragHandle:!1,values:t.calcdata.cells.values[t.specIndex],rowBlocks:t.calcdata.rowBlocks}),n({},t,{key:"cells2",type:"cells",page:1,prevPages:e,currentRepaint:[null,null],dragHandle:!1,values:t.calcdata.cells.values[t.specIndex],rowBlocks:t.calcdata.rowBlocks}),r]},r.splitToCells=function(t){var e=function(t){var e=t.rowBlocks[t.page],r=e?e.rows[0].rowIndex:0,n=e?r+e.rows.length:0;return[r,n]}(t);return(t.values||[]).slice(e[0],e[1]).map((function(r,n){return{keyWithinBlock:n+("string"==typeof r&&r.match(/[<$&> ]/)?"_keybuster_"+Math.random():""),key:e[0]+n,column:t,calcdata:t.calcdata,page:t.page,rowBlocks:t.rowBlocks,value:r}}))}},{"../../lib/extend":493}],1072:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./attributes"),a=t("../../plots/domain").defaults;e.exports=function(t,e,r,o){function s(r,a){return n.coerce(t,e,i,r,a)}a(e,o,s),s("columnwidth"),s("header.values"),s("header.format"),s("header.align"),s("header.prefix"),s("header.suffix"),s("header.height"),s("header.line.width"),s("header.line.color"),s("header.fill.color"),n.coerceFont(s,"header.font",n.extendFlat({},o.font)),function(t,e){for(var r=t.columnorder||[],n=t.header.values.length,i=r.slice(0,n),a=i.slice().sort((function(t,e){return t-e})),o=i.map((function(t){return a.indexOf(t)})),s=o.length;s<n;s++)o.push(s);e("columnorder",o)}(e,s),s("cells.values"),s("cells.format"),s("cells.align"),s("cells.prefix"),s("cells.suffix"),s("cells.height"),s("cells.line.width"),s("cells.line.color"),s("cells.fill.color"),n.coerceFont(s,"cells.font",n.extendFlat({},o.font)),e._length=null}},{"../../lib":503,"../../plots/domain":584,"./attributes":1066}],1073:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),calc:t("./calc"),plot:t("./plot"),moduleType:"trace",name:"table",basePlotModule:t("./base_plot"),categories:["noOpacity"],meta:{}}},{"./attributes":1066,"./base_plot":1067,"./calc":1068,"./defaults":1072,"./plot":1074}],1074:[function(t,e,r){"use strict";var n=t("./constants"),i=t("@plotly/d3"),a=t("../../lib").numberFormat,o=t("../../lib/gup"),s=t("../../components/drawing"),l=t("../../lib/svg_text_utils"),c=t("../../lib").raiseToTop,u=t("../../lib").strTranslate,f=t("../../lib").cancelTransition,h=t("./data_preparation_helper"),p=t("./data_split_helpers"),d=t("../../components/color");function m(t){return Math.ceil(t.calcdata.maxLineWidth/2)}function g(t,e){return"clip"+t._fullLayout._uid+"_scrollAreaBottomClip_"+e.key}function v(t,e){return"clip"+t._fullLayout._uid+"_columnBoundaryClippath_"+e.calcdata.key+"_"+e.specIndex}function y(t){return[].concat.apply([],t.map((function(t){return t}))).map((function(t){return t.__data__}))}function x(t,e,r){var a=t.selectAll("."+n.cn.scrollbarKit).data(o.repeat,o.keyFun);a.enter().append("g").classed(n.cn.scrollbarKit,!0).style("shape-rendering","geometricPrecision"),a.each((function(t){var e=t.scrollbarState;e.totalHeight=function(t){var e=t.rowBlocks;return D(e,e.length-1)+(e.length?R(e[e.length-1],1/0):1)}(t),e.scrollableAreaHeight=t.groupHeight-S(t),e.currentlyVisibleHeight=Math.min(e.totalHeight,e.scrollableAreaHeight),e.ratio=e.currentlyVisibleHeight/e.totalHeight,e.barLength=Math.max(e.ratio*e.currentlyVisibleHeight,n.goldenRatio*n.scrollbarWidth),e.barWiggleRoom=e.currentlyVisibleHeight-e.barLength,e.wiggleRoom=Math.max(0,e.totalHeight-e.scrollableAreaHeight),e.topY=0===e.barWiggleRoom?0:t.scrollY/e.wiggleRoom*e.barWiggleRoom,e.bottomY=e.topY+e.barLength,e.dragMultiplier=e.wiggleRoom/e.barWiggleRoom})).attr("transform",(function(t){var e=t.width+n.scrollbarWidth/2+n.scrollbarOffset;return u(e,S(t))}));var s=a.selectAll("."+n.cn.scrollbar).data(o.repeat,o.keyFun);s.enter().append("g").classed(n.cn.scrollbar,!0);var l=s.selectAll("."+n.cn.scrollbarSlider).data(o.repeat,o.keyFun);l.enter().append("g").classed(n.cn.scrollbarSlider,!0),l.attr("transform",(function(t){return u(0,t.scrollbarState.topY||0)}));var c=l.selectAll("."+n.cn.scrollbarGlyph).data(o.repeat,o.keyFun);c.enter().append("line").classed(n.cn.scrollbarGlyph,!0).attr("stroke","black").attr("stroke-width",n.scrollbarWidth).attr("stroke-linecap","round").attr("y1",n.scrollbarWidth/2),c.attr("y2",(function(t){return t.scrollbarState.barLength-n.scrollbarWidth/2})).attr("stroke-opacity",(function(t){return t.columnDragInProgress||!t.scrollbarState.barWiggleRoom||r?0:.4})),c.transition().delay(0).duration(0),c.transition().delay(n.scrollbarHideDelay).duration(n.scrollbarHideDuration).attr("stroke-opacity",0);var f=s.selectAll("."+n.cn.scrollbarCaptureZone).data(o.repeat,o.keyFun);f.enter().append("line").classed(n.cn.scrollbarCaptureZone,!0).attr("stroke","white").attr("stroke-opacity",.01).attr("stroke-width",n.scrollbarCaptureWidth).attr("stroke-linecap","butt").attr("y1",0).on("mousedown",(function(r){var n=i.event.y,a=this.getBoundingClientRect(),o=r.scrollbarState,s=n-a.top,l=i.scale.linear().domain([0,o.scrollableAreaHeight]).range([0,o.totalHeight]).clamp(!0);o.topY<=s&&s<=o.bottomY||L(e,t,null,l(s-o.barLength/2))(r)})).call(i.behavior.drag().origin((function(t){return i.event.stopPropagation(),t.scrollbarState.scrollbarScrollInProgress=!0,t})).on("drag",L(e,t)).on("dragend",(function(){}))),f.attr("y2",(function(t){return t.scrollbarState.scrollableAreaHeight})),e._context.staticPlot&&(c.remove(),f.remove())}function b(t,e,r,a){var l=function(t){var e=t.selectAll("."+n.cn.columnCell).data(p.splitToCells,(function(t){return t.keyWithinBlock}));return e.enter().append("g").classed(n.cn.columnCell,!0),e.exit().remove(),e}(function(t){var e=t.selectAll("."+n.cn.columnCells).data(o.repeat,o.keyFun);return e.enter().append("g").classed(n.cn.columnCells,!0),e.exit().remove(),e}(r));!function(t){t.each((function(t,e){var r=t.calcdata.cells.font,n=t.column.specIndex,i={size:T(r.size,n,e),color:T(r.color,n,e),family:T(r.family,n,e)};t.rowNumber=t.key,t.align=T(t.calcdata.cells.align,n,e),t.cellBorderWidth=T(t.calcdata.cells.line.width,n,e),t.font=i}))}(l),function(t){t.attr("width",(function(t){return t.column.columnWidth})).attr("stroke-width",(function(t){return t.cellBorderWidth})).each((function(t){var e=i.select(this);d.stroke(e,T(t.calcdata.cells.line.color,t.column.specIndex,t.rowNumber)),d.fill(e,T(t.calcdata.cells.fill.color,t.column.specIndex,t.rowNumber))}))}(function(t){var e=t.selectAll("."+n.cn.cellRect).data(o.repeat,(function(t){return t.keyWithinBlock}));return e.enter().append("rect").classed(n.cn.cellRect,!0),e}(l));var c=function(t){var e=t.selectAll("."+n.cn.cellText).data(o.repeat,(function(t){return t.keyWithinBlock}));return e.enter().append("text").classed(n.cn.cellText,!0).style("cursor",(function(){return"auto"})).on("mousedown",(function(){i.event.stopPropagation()})),e}(function(t){var e=t.selectAll("."+n.cn.cellTextHolder).data(o.repeat,(function(t){return t.keyWithinBlock}));return e.enter().append("g").classed(n.cn.cellTextHolder,!0).style("shape-rendering","geometricPrecision"),e}(l));!function(t){t.each((function(t){s.font(i.select(this),t.font)}))}(c),_(c,e,a,t),z(l)}function _(t,e,r,o){t.text((function(t){var e=t.column.specIndex,r=t.rowNumber,i=t.value,o="string"==typeof i,s=o&&i.match(/<br>/i),l=!o||s;t.mayHaveMarkup=o&&i.match(/[<&>]/);var c,u="string"==typeof(c=i)&&c.match(n.latexCheck);t.latex=u;var f,h,p=u?"":T(t.calcdata.cells.prefix,e,r)||"",d=u?"":T(t.calcdata.cells.suffix,e,r)||"",m=u?null:T(t.calcdata.cells.format,e,r)||null,g=p+(m?a(m)(t.value):t.value)+d;if(t.wrappingNeeded=!t.wrapped&&!l&&!u&&(f=w(g)),t.cellHeightMayIncrease=s||u||t.mayHaveMarkup||(void 0===f?w(g):f),t.needsConvertToTspans=t.mayHaveMarkup||t.wrappingNeeded||t.latex,t.wrappingNeeded){var v=(" "===n.wrapSplitCharacter?g.replace(/<a href=/gi,"<a_href="):g).split(n.wrapSplitCharacter),y=" "===n.wrapSplitCharacter?v.map((function(t){return t.replace(/<a_href=/gi,"<a href=")})):v;t.fragments=y.map((function(t){return{text:t,width:null}})),t.fragments.push({fragment:n.wrapSpacer,width:null}),h=y.join(n.lineBreaker)+n.lineBreaker+n.wrapSpacer}else delete t.fragments,h=g;return h})).attr("dy",(function(t){return t.needsConvertToTspans?0:"0.75em"})).each((function(t){var a=i.select(this),s=t.wrappingNeeded?P:I;t.needsConvertToTspans?l.convertToTspans(a,o,s(r,this,e,o,t)):i.select(this.parentNode).attr("transform",(function(t){return u(O(t),n.cellPad)})).attr("text-anchor",(function(t){return{left:"start",center:"middle",right:"end"}[t.align]}))}))}function w(t){return-1!==t.indexOf(n.wrapSplitCharacter)}function T(t,e,r){if(Array.isArray(t)){var n=t[Math.min(e,t.length-1)];return Array.isArray(n)?n[Math.min(r,n.length-1)]:n}return t}function k(t,e,r){t.transition().ease(n.releaseTransitionEase).duration(n.releaseTransitionDuration).attr("transform",u(e.x,r))}function A(t){return"cells"===t.type}function M(t){return"header"===t.type}function S(t){return(t.rowBlocks.length?t.rowBlocks[0].auxiliaryBlocks:[]).reduce((function(t,e){return t+R(e,1/0)}),0)}function E(t,e,r){var n=y(e)[0];if(void 0!==n){var i=n.rowBlocks,a=n.calcdata,o=D(i,i.length),s=n.calcdata.groupHeight-S(n),l=a.scrollY=Math.max(0,Math.min(o-s,a.scrollY)),c=function(t,e,r){for(var n=[],i=0,a=0;a<t.length;a++){for(var o=t[a],s=o.rows,l=0,c=0;c<s.length;c++)l+=s[c].rowHeight;o.allRowsHeight=l;e<i+l&&e+r>i&&n.push(a),i+=l}return n}(i,l,s);1===c.length&&(c[0]===i.length-1?c.unshift(c[0]-1):c.push(c[0]+1)),c[0]%2&&c.reverse(),e.each((function(t,e){t.page=c[e],t.scrollY=l})),e.attr("transform",(function(t){var e=D(t.rowBlocks,t.page)-t.scrollY;return u(0,e)})),t&&(C(t,r,e,c,n.prevPages,n,0),C(t,r,e,c,n.prevPages,n,1),x(r,t))}}function L(t,e,r,a){return function(o){var s=o.calcdata?o.calcdata:o,l=e.filter((function(t){return s.key===t.key})),c=r||s.scrollbarState.dragMultiplier,u=s.scrollY;s.scrollY=void 0===a?s.scrollY+c*i.event.dy:a;var f=l.selectAll("."+n.cn.yColumn).selectAll("."+n.cn.columnBlock).filter(A);return E(t,f,l),s.scrollY===u}}function C(t,e,r,n,i,a,o){n[o]!==i[o]&&(clearTimeout(a.currentRepaint[o]),a.currentRepaint[o]=setTimeout((function(){var a=r.filter((function(t,e){return e===o&&n[e]!==i[e]}));b(t,e,a,r),i[o]=n[o]})))}function P(t,e,r,a){return function(){var o=i.select(e.parentNode);o.each((function(t){var e=t.fragments;o.selectAll("tspan.line").each((function(t,r){e[r].width=this.getComputedTextLength()}));var r,i,a=e[e.length-1].width,s=e.slice(0,-1),l=[],c=0,u=t.column.columnWidth-2*n.cellPad;for(t.value="";s.length;)c+(i=(r=s.shift()).width+a)>u&&(t.value+=l.join(n.wrapSpacer)+n.lineBreaker,l=[],c=0),l.push(r.text),c+=i;c&&(t.value+=l.join(n.wrapSpacer)),t.wrapped=!0})),o.selectAll("tspan.line").remove(),_(o.select("."+n.cn.cellText),r,t,a),i.select(e.parentNode.parentNode).call(z)}}function I(t,e,r,a,o){return function(){if(!o.settledY){var s=i.select(e.parentNode),l=B(o),c=o.key-l.firstRowIndex,f=l.rows[c].rowHeight,h=o.cellHeightMayIncrease?e.parentNode.getBoundingClientRect().height+2*n.cellPad:f,p=Math.max(h,f);p-l.rows[c].rowHeight&&(l.rows[c].rowHeight=p,t.selectAll("."+n.cn.columnCell).call(z),E(null,t.filter(A),0),x(r,a,!0)),s.attr("transform",(function(){var t=this.parentNode.getBoundingClientRect(),e=i.select(this.parentNode).select("."+n.cn.cellRect).node().getBoundingClientRect(),r=this.transform.baseVal.consolidate(),a=e.top-t.top+(r?r.matrix.f:n.cellPad);return u(O(o,i.select(this.parentNode).select("."+n.cn.cellTextHolder).node().getBoundingClientRect().width),a)})),o.settledY=!0}}}function O(t,e){switch(t.align){case"left":return n.cellPad;case"right":return t.column.columnWidth-(e||0)-n.cellPad;case"center":return(t.column.columnWidth-(e||0))/2;default:return n.cellPad}}function z(t){t.attr("transform",(function(t){var e=t.rowBlocks[0].auxiliaryBlocks.reduce((function(t,e){return t+R(e,1/0)}),0),r=R(B(t),t.key);return u(0,r+e)})).selectAll("."+n.cn.cellRect).attr("height",(function(t){return(e=B(t),r=t.key,e.rows[r-e.firstRowIndex]).rowHeight;var e,r}))}function D(t,e){for(var r=0,n=e-1;n>=0;n--)r+=F(t[n]);return r}function R(t,e){for(var r=0,n=0;n<t.rows.length&&t.rows[n].rowIndex<e;n++)r+=t.rows[n].rowHeight;return r}function F(t){var e=t.allRowsHeight;if(void 0!==e)return e;for(var r=0,n=0;n<t.rows.length;n++)r+=t.rows[n].rowHeight;return t.allRowsHeight=r,r}function B(t){return t.rowBlocks[t.page]}e.exports=function(t,e){var r=!t._context.staticPlot,a=t._fullLayout._paper.selectAll("."+n.cn.table).data(e.map((function(e){var r=o.unwrap(e).trace;return h(t,r)})),o.keyFun);a.exit().remove(),a.enter().append("g").classed(n.cn.table,!0).attr("overflow","visible").style("box-sizing","content-box").style("position","absolute").style("left",0).style("overflow","visible").style("shape-rendering","crispEdges").style("pointer-events","all"),a.attr("width",(function(t){return t.width+t.size.l+t.size.r})).attr("height",(function(t){return t.height+t.size.t+t.size.b})).attr("transform",(function(t){return u(t.translateX,t.translateY)}));var l=a.selectAll("."+n.cn.tableControlView).data(o.repeat,o.keyFun),d=l.enter().append("g").classed(n.cn.tableControlView,!0).style("box-sizing","content-box");if(r){var _="onwheel"in document?"wheel":"mousewheel";d.on("mousemove",(function(e){l.filter((function(t){return e===t})).call(x,t)})).on(_,(function(e){if(!e.scrollbarState.wheeling){e.scrollbarState.wheeling=!0;var r=e.scrollY+i.event.deltaY;L(t,l,null,r)(e)||(i.event.stopPropagation(),i.event.preventDefault()),e.scrollbarState.wheeling=!1}})).call(x,t,!0)}l.attr("transform",(function(t){return u(t.size.l,t.size.t)}));var w=l.selectAll("."+n.cn.scrollBackground).data(o.repeat,o.keyFun);w.enter().append("rect").classed(n.cn.scrollBackground,!0).attr("fill","none"),w.attr("width",(function(t){return t.width})).attr("height",(function(t){return t.height})),l.each((function(e){s.setClipUrl(i.select(this),g(t,e),t)}));var T=l.selectAll("."+n.cn.yColumn).data((function(t){return t.columns}),o.keyFun);T.enter().append("g").classed(n.cn.yColumn,!0),T.exit().remove(),T.attr("transform",(function(t){return u(t.x,0)})),r&&T.call(i.behavior.drag().origin((function(e){return k(i.select(this),e,-n.uplift),c(this),e.calcdata.columnDragInProgress=!0,x(l.filter((function(t){return e.calcdata.key===t.key})),t),e})).on("drag",(function(t){var e=i.select(this),r=function(e){return(t===e?i.event.x:e.x)+e.columnWidth/2};t.x=Math.max(-n.overdrag,Math.min(t.calcdata.width+n.overdrag-t.columnWidth,i.event.x)),y(T).filter((function(e){return e.calcdata.key===t.calcdata.key})).sort((function(t,e){return r(t)-r(e)})).forEach((function(e,r){e.xIndex=r,e.x=t===e?e.x:e.xScale(e)})),T.filter((function(e){return t!==e})).transition().ease(n.transitionEase).duration(n.transitionDuration).attr("transform",(function(t){return u(t.x,0)})),e.call(f).attr("transform",u(t.x,-n.uplift))})).on("dragend",(function(e){var r=i.select(this),n=e.calcdata;e.x=e.xScale(e),e.calcdata.columnDragInProgress=!1,k(r,e,0),function(t,e,r){var n=e.gdColumnsOriginalOrder;e.gdColumns.sort((function(t,e){return r[n.indexOf(t)]-r[n.indexOf(e)]})),e.columnorder=r,t.emit("plotly_restyle")}(t,n,n.columns.map((function(t){return t.xIndex})))}))),T.each((function(e){s.setClipUrl(i.select(this),v(t,e),t)}));var S=T.selectAll("."+n.cn.columnBlock).data(p.splitToPanels,o.keyFun);S.enter().append("g").classed(n.cn.columnBlock,!0).attr("id",(function(t){return t.key})),S.style("cursor",(function(t){return t.dragHandle?"ew-resize":t.calcdata.scrollbarState.barWiggleRoom?"ns-resize":"default"}));var C=S.filter(M),P=S.filter(A);r&&P.call(i.behavior.drag().origin((function(t){return i.event.stopPropagation(),t})).on("drag",L(t,l,-1)).on("dragend",(function(){}))),b(t,l,C,S),b(t,l,P,S);var I=l.selectAll("."+n.cn.scrollAreaClip).data(o.repeat,o.keyFun);I.enter().append("clipPath").classed(n.cn.scrollAreaClip,!0).attr("id",(function(e){return g(t,e)}));var O=I.selectAll("."+n.cn.scrollAreaClipRect).data(o.repeat,o.keyFun);O.enter().append("rect").classed(n.cn.scrollAreaClipRect,!0).attr("x",-n.overdrag).attr("y",-n.uplift).attr("fill","none"),O.attr("width",(function(t){return t.width+2*n.overdrag})).attr("height",(function(t){return t.height+n.uplift})),T.selectAll("."+n.cn.columnBoundary).data(o.repeat,o.keyFun).enter().append("g").classed(n.cn.columnBoundary,!0);var z=T.selectAll("."+n.cn.columnBoundaryClippath).data(o.repeat,o.keyFun);z.enter().append("clipPath").classed(n.cn.columnBoundaryClippath,!0),z.attr("id",(function(e){return v(t,e)}));var D=z.selectAll("."+n.cn.columnBoundaryRect).data(o.repeat,o.keyFun);D.enter().append("rect").classed(n.cn.columnBoundaryRect,!0).attr("fill","none"),D.attr("width",(function(t){return t.columnWidth+2*m(t)})).attr("height",(function(t){return t.calcdata.height+2*m(t)+n.uplift})).attr("x",(function(t){return-m(t)})).attr("y",(function(t){return-m(t)})),E(null,P,l)}},{"../../components/color":366,"../../components/drawing":388,"../../lib":503,"../../lib/gup":500,"../../lib/svg_text_utils":529,"./constants":1069,"./data_preparation_helper":1070,"./data_split_helpers":1071,"@plotly/d3":58}],1075:[function(t,e,r){"use strict";var n=t("../../plots/template_attributes").hovertemplateAttrs,i=t("../../plots/template_attributes").texttemplateAttrs,a=t("../../components/colorscale/attributes"),o=t("../../plots/domain").attributes,s=t("../pie/attributes"),l=t("../sunburst/attributes"),c=t("./constants"),u=t("../../lib/extend").extendFlat;e.exports={labels:l.labels,parents:l.parents,values:l.values,branchvalues:l.branchvalues,count:l.count,level:l.level,maxdepth:l.maxdepth,tiling:{packing:{valType:"enumerated",values:["squarify","binary","dice","slice","slice-dice","dice-slice"],dflt:"squarify",editType:"plot"},squarifyratio:{valType:"number",min:1,dflt:1,editType:"plot"},flip:{valType:"flaglist",flags:["x","y"],dflt:"",editType:"plot"},pad:{valType:"number",min:0,dflt:3,editType:"plot"},editType:"calc"},marker:u({pad:{t:{valType:"number",min:0,editType:"plot"},l:{valType:"number",min:0,editType:"plot"},r:{valType:"number",min:0,editType:"plot"},b:{valType:"number",min:0,editType:"plot"},editType:"calc"},colors:l.marker.colors,depthfade:{valType:"enumerated",values:[!0,!1,"reversed"],editType:"style"},line:l.marker.line,editType:"calc"},a("marker",{colorAttr:"colors",anim:!1})),pathbar:{visible:{valType:"boolean",dflt:!0,editType:"plot"},side:{valType:"enumerated",values:["top","bottom"],dflt:"top",editType:"plot"},edgeshape:{valType:"enumerated",values:[">","<","|","/","\\"],dflt:">",editType:"plot"},thickness:{valType:"number",min:12,editType:"plot"},textfont:u({},s.textfont,{}),editType:"calc"},text:s.text,textinfo:l.textinfo,texttemplate:i({editType:"plot"},{keys:c.eventDataKeys.concat(["label","value"])}),hovertext:s.hovertext,hoverinfo:l.hoverinfo,hovertemplate:n({},{keys:c.eventDataKeys}),textfont:s.textfont,insidetextfont:s.insidetextfont,outsidetextfont:u({},s.outsidetextfont,{}),textposition:{valType:"enumerated",values:["top left","top center","top right","middle left","middle center","middle right","bottom left","bottom center","bottom right"],dflt:"top left",editType:"plot"},sort:s.sort,root:l.root,domain:o({name:"treemap",trace:!0,editType:"calc"})}},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plots/domain":584,"../../plots/template_attributes":633,"../pie/attributes":901,"../sunburst/attributes":1049,"./constants":1078}],1076:[function(t,e,r){"use strict";var n=t("../../plots/plots");r.name="treemap",r.plot=function(t,e,i,a){n.plotBasePlot(r.name,t,e,i,a)},r.clean=function(t,e,i,a){n.cleanBasePlot(r.name,t,e,i,a)}},{"../../plots/plots":619}],1077:[function(t,e,r){"use strict";var n=t("../sunburst/calc");r.calc=function(t,e){return n.calc(t,e)},r.crossTraceCalc=function(t){return n._runCrossTraceCalc("treemap",t)}},{"../sunburst/calc":1051}],1078:[function(t,e,r){"use strict";e.exports={CLICK_TRANSITION_TIME:750,CLICK_TRANSITION_EASING:"poly",eventDataKeys:["currentPath","root","entry","percentRoot","percentEntry","percentParent"],gapWithPathbar:1}},{}],1079:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./attributes"),a=t("../../components/color"),o=t("../../plots/domain").defaults,s=t("../bar/defaults").handleText,l=t("../bar/constants").TEXTPAD,c=t("../../components/colorscale"),u=c.hasColorscale,f=c.handleDefaults;e.exports=function(t,e,r,c){function h(r,a){return n.coerce(t,e,i,r,a)}var p=h("labels"),d=h("parents");if(p&&p.length&&d&&d.length){var m=h("values");m&&m.length?h("branchvalues"):h("count"),h("level"),h("maxdepth"),"squarify"===h("tiling.packing")&&h("tiling.squarifyratio"),h("tiling.flip"),h("tiling.pad");var g=h("text");h("texttemplate"),e.texttemplate||h("textinfo",Array.isArray(g)?"text+label":"label"),h("hovertext"),h("hovertemplate");var v=h("pathbar.visible");s(t,e,c,h,"auto",{hasPathbar:v,moduleHasSelected:!1,moduleHasUnselected:!1,moduleHasConstrain:!1,moduleHasCliponaxis:!1,moduleHasTextangle:!1,moduleHasInsideanchor:!1}),h("textposition");var y=-1!==e.textposition.indexOf("bottom");h("marker.line.width")&&h("marker.line.color",c.paper_bgcolor);var x=h("marker.colors");(e._hasColorscale=u(t,"marker","colors")||(t.marker||{}).coloraxis)?f(t,e,c,h,{prefix:"marker.",cLetter:"c"}):h("marker.depthfade",!(x||[]).length);var b=2*e.textfont.size;h("marker.pad.t",y?b/4:b),h("marker.pad.l",b/4),h("marker.pad.r",b/4),h("marker.pad.b",y?b:b/4),e._hovered={marker:{line:{width:2,color:a.contrast(c.paper_bgcolor)}}},v&&(h("pathbar.thickness",e.pathbar.textfont.size+2*l),h("pathbar.side"),h("pathbar.edgeshape")),h("sort"),h("root.color"),o(e,c,h),e._length=null}else e.visible=!1}},{"../../components/color":366,"../../components/colorscale":378,"../../lib":503,"../../plots/domain":584,"../bar/constants":650,"../bar/defaults":652,"./attributes":1075}],1080:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../sunburst/helpers"),a=t("../bar/uniform_text").clearMinTextSize,o=t("../bar/style").resizeText,s=t("./plot_one");e.exports=function(t,e,r,l,c){var u,f,h=c.type,p=c.drawDescendants,d=t._fullLayout,m=d["_"+h+"layer"],g=!r;(a(h,d),(u=m.selectAll("g.trace."+h).data(e,(function(t){return t[0].trace.uid}))).enter().append("g").classed("trace",!0).classed(h,!0),u.order(),!d.uniformtext.mode&&i.hasTransition(r))?(l&&(f=l()),n.transition().duration(r.duration).ease(r.easing).each("end",(function(){f&&f()})).each("interrupt",(function(){f&&f()})).each((function(){m.selectAll("g.trace").each((function(e){s(t,e,this,r,p)}))}))):(u.each((function(e){s(t,e,this,r,p)})),d.uniformtext.mode&&o(t,m.selectAll(".trace"),h));g&&u.exit().remove()}},{"../bar/style":662,"../bar/uniform_text":664,"../sunburst/helpers":1055,"./plot_one":1089,"@plotly/d3":58}],1081:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../../components/drawing"),o=t("../../lib/svg_text_utils"),s=t("./partition"),l=t("./style").styleOne,c=t("./constants"),u=t("../sunburst/helpers"),f=t("../sunburst/fx");e.exports=function(t,e,r,h,p){var d=p.barDifY,m=p.width,g=p.height,v=p.viewX,y=p.viewY,x=p.pathSlice,b=p.toMoveInsideSlice,_=p.strTransform,w=p.hasTransition,T=p.handleSlicesExit,k=p.makeUpdateSliceInterpolator,A=p.makeUpdateTextInterpolator,M={},S=t._fullLayout,E=e[0],L=E.trace,C=E.hierarchy,P=m/L._entryDepth,I=u.listPath(r.data,"id"),O=s(C.copy(),[m,g],{packing:"dice",pad:{inner:0,top:0,left:0,right:0,bottom:0}}).descendants();(O=O.filter((function(t){var e=I.indexOf(t.data.id);return-1!==e&&(t.x0=P*e,t.x1=P*(e+1),t.y0=d,t.y1=d+g,t.onPathbar=!0,!0)}))).reverse(),(h=h.data(O,u.getPtId)).enter().append("g").classed("pathbar",!0),T(h,!0,M,[m,g],x),h.order();var z=h;w&&(z=z.transition().each("end",(function(){var e=n.select(this);u.setSliceCursor(e,t,{hideOnRoot:!1,hideOnLeaves:!1,isTransitioning:!1})}))),z.each((function(s){s._x0=v(s.x0),s._x1=v(s.x1),s._y0=y(s.y0),s._y1=y(s.y1),s._hoverX=v(s.x1-Math.min(m,g)/2),s._hoverY=y(s.y1-g/2);var h=n.select(this),p=i.ensureSingle(h,"path","surface",(function(t){t.style("pointer-events","all")}));w?p.transition().attrTween("d",(function(t){var e=k(t,!0,M,[m,g]);return function(t){return x(e(t))}})):p.attr("d",x),h.call(f,r,t,e,{styleOne:l,eventDataKeys:c.eventDataKeys,transitionTime:c.CLICK_TRANSITION_TIME,transitionEasing:c.CLICK_TRANSITION_EASING}).call(u.setSliceCursor,t,{hideOnRoot:!1,hideOnLeaves:!1,isTransitioning:t._transitioning}),p.call(l,s,L,{hovered:!1}),s._text=(u.getPtLabel(s)||"").split("<br>").join(" ")||"";var d=i.ensureSingle(h,"g","slicetext"),T=i.ensureSingle(d,"text","",(function(t){t.attr("data-notex",1)})),E=i.ensureUniformFontSize(t,u.determineTextFont(L,s,S.font,{onPathbar:!0}));T.text(s._text||" ").classed("slicetext",!0).attr("text-anchor","start").call(a.font,E).call(o.convertToTspans,t),s.textBB=a.bBox(T.node()),s.transform=b(s,{fontSize:E.size,onPathbar:!0}),s.transform.fontSize=E.size,w?T.transition().attrTween("transform",(function(t){var e=A(t,!0,M,[m,g]);return function(t){return _(e(t))}})):T.attr("transform",_(s))}))}},{"../../components/drawing":388,"../../lib":503,"../../lib/svg_text_utils":529,"../sunburst/fx":1054,"../sunburst/helpers":1055,"./constants":1078,"./partition":1087,"./style":1090,"@plotly/d3":58}],1082:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../../components/drawing"),o=t("../../lib/svg_text_utils"),s=t("./partition"),l=t("./style").styleOne,c=t("./constants"),u=t("../sunburst/helpers"),f=t("../sunburst/fx"),h=t("../sunburst/plot").formatSliceLabel;e.exports=function(t,e,r,p,d){var m=d.width,g=d.height,v=d.viewX,y=d.viewY,x=d.pathSlice,b=d.toMoveInsideSlice,_=d.strTransform,w=d.hasTransition,T=d.handleSlicesExit,k=d.makeUpdateSliceInterpolator,A=d.makeUpdateTextInterpolator,M=d.prevEntry,S=t._fullLayout,E=e[0].trace,L=-1!==E.textposition.indexOf("left"),C=-1!==E.textposition.indexOf("right"),P=-1!==E.textposition.indexOf("bottom"),I=!P&&!E.marker.pad.t||P&&!E.marker.pad.b,O=s(r,[m,g],{packing:E.tiling.packing,squarifyratio:E.tiling.squarifyratio,flipX:E.tiling.flip.indexOf("x")>-1,flipY:E.tiling.flip.indexOf("y")>-1,pad:{inner:E.tiling.pad,top:E.marker.pad.t,left:E.marker.pad.l,right:E.marker.pad.r,bottom:E.marker.pad.b}}).descendants(),z=1/0,D=-1/0;O.forEach((function(t){var e=t.depth;e>=E._maxDepth?(t.x0=t.x1=(t.x0+t.x1)/2,t.y0=t.y1=(t.y0+t.y1)/2):(z=Math.min(z,e),D=Math.max(D,e))})),p=p.data(O,u.getPtId),E._maxVisibleLayers=isFinite(D)?D-z+1:0,p.enter().append("g").classed("slice",!0),T(p,!1,{},[m,g],x),p.order();var R=null;if(w&&M){var F=u.getPtId(M);p.each((function(t){null===R&&u.getPtId(t)===F&&(R={x0:t.x0,x1:t.x1,y0:t.y0,y1:t.y1})}))}var B=function(){return R||{x0:0,x1:m,y0:0,y1:g}},N=p;return w&&(N=N.transition().each("end",(function(){var e=n.select(this);u.setSliceCursor(e,t,{hideOnRoot:!0,hideOnLeaves:!1,isTransitioning:!1})}))),N.each((function(s){var p=u.isHeader(s,E);s._x0=v(s.x0),s._x1=v(s.x1),s._y0=y(s.y0),s._y1=y(s.y1),s._hoverX=v(s.x1-E.marker.pad.r),s._hoverY=y(P?s.y1-E.marker.pad.b/2:s.y0+E.marker.pad.t/2);var d=n.select(this),T=i.ensureSingle(d,"path","surface",(function(t){t.style("pointer-events","all")}));w?T.transition().attrTween("d",(function(t){var e=k(t,!1,B(),[m,g]);return function(t){return x(e(t))}})):T.attr("d",x),d.call(f,r,t,e,{styleOne:l,eventDataKeys:c.eventDataKeys,transitionTime:c.CLICK_TRANSITION_TIME,transitionEasing:c.CLICK_TRANSITION_EASING}).call(u.setSliceCursor,t,{isTransitioning:t._transitioning}),T.call(l,s,E,{hovered:!1}),s.x0===s.x1||s.y0===s.y1?s._text="":s._text=p?I?"":u.getPtLabel(s)||"":h(s,r,E,e,S)||"";var M=i.ensureSingle(d,"g","slicetext"),O=i.ensureSingle(M,"text","",(function(t){t.attr("data-notex",1)})),z=i.ensureUniformFontSize(t,u.determineTextFont(E,s,S.font));O.text(s._text||" ").classed("slicetext",!0).attr("text-anchor",C?"end":L||p?"start":"middle").call(a.font,z).call(o.convertToTspans,t),s.textBB=a.bBox(O.node()),s.transform=b(s,{fontSize:z.size,isHeader:p}),s.transform.fontSize=z.size,w?O.transition().attrTween("transform",(function(t){var e=A(t,!1,B(),[m,g]);return function(t){return _(e(t))}})):O.attr("transform",_(s))})),R}},{"../../components/drawing":388,"../../lib":503,"../../lib/svg_text_utils":529,"../sunburst/fx":1054,"../sunburst/helpers":1055,"../sunburst/plot":1059,"./constants":1078,"./partition":1087,"./style":1090,"@plotly/d3":58}],1083:[function(t,e,r){"use strict";e.exports=function t(e,r,n){var i;n.swapXY&&(i=e.x0,e.x0=e.y0,e.y0=i,i=e.x1,e.x1=e.y1,e.y1=i),n.flipX&&(i=e.x0,e.x0=r[0]-e.x1,e.x1=r[0]-i),n.flipY&&(i=e.y0,e.y0=r[1]-e.y1,e.y1=r[1]-i);var a=e.children;if(a)for(var o=0;o<a.length;o++)t(a[o],r,n)}},{}],1084:[function(t,e,r){"use strict";e.exports={moduleType:"trace",name:"treemap",basePlotModule:t("./base_plot"),categories:[],animatable:!0,attributes:t("./attributes"),layoutAttributes:t("./layout_attributes"),supplyDefaults:t("./defaults"),supplyLayoutDefaults:t("./layout_defaults"),calc:t("./calc").calc,crossTraceCalc:t("./calc").crossTraceCalc,plot:t("./plot"),style:t("./style").style,colorbar:t("../scatter/marker_colorbar"),meta:{}}},{"../scatter/marker_colorbar":945,"./attributes":1075,"./base_plot":1076,"./calc":1077,"./defaults":1079,"./layout_attributes":1085,"./layout_defaults":1086,"./plot":1088,"./style":1090}],1085:[function(t,e,r){"use strict";e.exports={treemapcolorway:{valType:"colorlist",editType:"calc"},extendtreemapcolors:{valType:"boolean",dflt:!0,editType:"calc"}}},{}],1086:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./layout_attributes");e.exports=function(t,e){function r(r,a){return n.coerce(t,e,i,r,a)}r("treemapcolorway",e.colorway),r("extendtreemapcolors")}},{"../../lib":503,"./layout_attributes":1085}],1087:[function(t,e,r){"use strict";var n=t("d3-hierarchy"),i=t("./flip_tree");e.exports=function(t,e,r){var a,o=r.flipX,s=r.flipY,l="dice-slice"===r.packing,c=r.pad[s?"bottom":"top"],u=r.pad[o?"right":"left"],f=r.pad[o?"left":"right"],h=r.pad[s?"top":"bottom"];l&&(a=u,u=c,c=a,a=f,f=h,h=a);var p=n.treemap().tile(function(t,e){switch(t){case"squarify":return n.treemapSquarify.ratio(e);case"binary":return n.treemapBinary;case"dice":return n.treemapDice;case"slice":return n.treemapSlice;default:return n.treemapSliceDice}}(r.packing,r.squarifyratio)).paddingInner(r.pad.inner).paddingLeft(u).paddingRight(f).paddingTop(c).paddingBottom(h).size(l?[e[1],e[0]]:e)(t);return(l||o||s)&&i(p,e,{swapXY:l,flipX:o,flipY:s}),p}},{"./flip_tree":1083,"d3-hierarchy":115}],1088:[function(t,e,r){"use strict";var n=t("./draw"),i=t("./draw_descendants");e.exports=function(t,e,r,a){return n(t,e,r,a,{type:"treemap",drawDescendants:i})}},{"./draw":1080,"./draw_descendants":1082}],1089:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("d3-interpolate").interpolate,a=t("../sunburst/helpers"),o=t("../../lib"),s=t("../bar/constants").TEXTPAD,l=t("../bar/plot").toMoveInsideBar,c=t("../bar/uniform_text").recordMinTextSize,u=t("./constants"),f=t("./draw_ancestors");function h(t){return a.isHierarchyRoot(t)?"":a.getPtId(t)}e.exports=function(t,e,r,p,d){var m=t._fullLayout,g=e[0],v=g.trace,y="icicle"===v.type,x=g.hierarchy,b=a.findEntryWithLevel(x,v.level),_=n.select(r),w=_.selectAll("g.pathbar"),T=_.selectAll("g.slice");if(!b)return w.remove(),void T.remove();var k=a.isHierarchyRoot(b),A=!m.uniformtext.mode&&a.hasTransition(p),M=a.getMaxDepth(v),S=m._size,E=v.domain,L=S.w*(E.x[1]-E.x[0]),C=S.h*(E.y[1]-E.y[0]),P=L,I=v.pathbar.thickness,O=v.marker.line.width+u.gapWithPathbar,z=v.pathbar.visible?v.pathbar.side.indexOf("bottom")>-1?C+O:-(I+O):0,D={x0:P,x1:P,y0:z,y1:z+I},R=function(t,e,r){var n=v.tiling.pad,i=function(t){return t-n<=e.x0},a=function(t){return t+n>=e.x1},o=function(t){return t-n<=e.y0},s=function(t){return t+n>=e.y1};return t.x0===e.x0&&t.x1===e.x1&&t.y0===e.y0&&t.y1===e.y1?{x0:t.x0,x1:t.x1,y0:t.y0,y1:t.y1}:{x0:i(t.x0-n)?0:a(t.x0-n)?r[0]:t.x0,x1:i(t.x1+n)?0:a(t.x1+n)?r[0]:t.x1,y0:o(t.y0-n)?0:s(t.y0-n)?r[1]:t.y0,y1:o(t.y1+n)?0:s(t.y1+n)?r[1]:t.y1}},F=null,B={},N={},j=null,U=function(t,e){return e?B[h(t)]:N[h(t)]},V=function(t,e,r,n){if(e)return B[h(x)]||D;var i=N[v.level]||r;return function(t){return t.data.depth-b.data.depth<M}(t)?R(t,i,n):{}};g.hasMultipleRoots&&k&&M++,v._maxDepth=M,v._backgroundColor=m.paper_bgcolor,v._entryDepth=b.data.depth,v._atRootLevel=k;var H=-L/2+S.l+S.w*(E.x[1]+E.x[0])/2,q=-C/2+S.t+S.h*(1-(E.y[1]+E.y[0])/2),G=function(t){return H+t},Y=function(t){return q+t},W=Y(0),X=G(0),Z=function(t){return X+t},J=function(t){return W+t};function K(t,e){return t+","+e}var Q=Z(0),$=function(t){t.x=Math.max(Q,t.x)},tt=v.pathbar.edgeshape,et=function(t,e){var r=t.x0,n=t.x1,i=t.y0,a=t.y1,o=t.textBB,u=function(t){return-1!==v.textposition.indexOf(t)},f=u("bottom"),h=u("top")||e.isHeader&&!f?"start":f?"end":"middle",p=u("right"),d=u("left")||e.onPathbar?-1:p?1:0,g=v[y?"tiling":"marker"].pad;if(e.isHeader){if((r+=(y?g:g.l)-s)>=(n-=(y?g:g.r)-s)){var x=(r+n)/2;r=x,n=x}var b;f?i<(b=a-(y?g:g.b))&&b<a&&(i=b):i<(b=i+(y?g:g.t))&&b<a&&(a=b)}var _=l(r,n,i,a,o,{isHorizontal:!1,constrained:!0,angle:0,anchor:h,leftToRight:d});return _.fontSize=e.fontSize,_.targetX=G(_.targetX),_.targetY=Y(_.targetY),isNaN(_.targetX)||isNaN(_.targetY)?{}:(r!==n&&i!==a&&c(v.type,_,m),{scale:_.scale,rotate:_.rotate,textX:_.textX,textY:_.textY,anchorX:_.anchorX,anchorY:_.anchorY,targetX:_.targetX,targetY:_.targetY})},rt=function(t,e){for(var r,n=0,i=t;!r&&n<M;)n++,(i=i.parent)?r=U(i,e):n=M;return r||{}},nt=function(t,e,r,n,a){var s,l=U(t,e);if(l)s=l;else if(e)s=D;else if(F)if(t.parent){var c=j||r;c&&!e?s=R(t,c,n):(s={},o.extendFlat(s,rt(t,e)))}else s=o.extendFlat({},t),y&&("h"===a.orientation?a.flipX?s.x0=t.x1:s.x1=0:a.flipY?s.y0=t.y1:s.y1=0);else s={};return i(s,{x0:t.x0,x1:t.x1,y0:t.y0,y1:t.y1})},it=function(t,e,r,n){var s=U(t,e),l={},u=V(t,e,r,n);o.extendFlat(l,{transform:et({x0:u.x0,x1:u.x1,y0:u.y0,y1:u.y1,textBB:t.textBB,_text:t._text},{isHeader:a.isHeader(t,v)})}),s?l=s:t.parent&&o.extendFlat(l,rt(t,e));var f=t.transform;return t.x0!==t.x1&&t.y0!==t.y1&&c(v.type,f,m),i(l,{transform:{scale:f.scale,rotate:f.rotate,textX:f.textX,textY:f.textY,anchorX:f.anchorX,anchorY:f.anchorY,targetX:f.targetX,targetY:f.targetY}})},at=function(t,e,r,a,o){var s=a[0],l=a[1];A?t.exit().transition().each((function(){var t=n.select(this);t.select("path.surface").transition().attrTween("d",(function(t){var r=function(t,e,r,n){var a,o=U(t,e);if(e)a=D;else{var s=U(b,e);a=s?R(t,s,n):{}}return i(o,a)}(t,e,0,[s,l]);return function(t){return o(r(t))}})),t.select("g.slicetext").attr("opacity",0)})).remove():t.exit().remove()},ot=function(t){var e=t.transform;return t.x0!==t.x1&&t.y0!==t.y1&&c(v.type,e,m),o.getTextTransform({textX:e.textX,textY:e.textY,anchorX:e.anchorX,anchorY:e.anchorY,targetX:e.targetX,targetY:e.targetY,scale:e.scale,rotate:e.rotate})};A&&(w.each((function(t){B[h(t)]={x0:t.x0,x1:t.x1,y0:t.y0,y1:t.y1},t.transform&&(B[h(t)].transform={textX:t.transform.textX,textY:t.transform.textY,anchorX:t.transform.anchorX,anchorY:t.transform.anchorY,targetX:t.transform.targetX,targetY:t.transform.targetY,scale:t.transform.scale,rotate:t.transform.rotate})})),T.each((function(t){N[h(t)]={x0:t.x0,x1:t.x1,y0:t.y0,y1:t.y1},t.transform&&(N[h(t)].transform={textX:t.transform.textX,textY:t.transform.textY,anchorX:t.transform.anchorX,anchorY:t.transform.anchorY,targetX:t.transform.targetX,targetY:t.transform.targetY,scale:t.transform.scale,rotate:t.transform.rotate}),!F&&a.isEntry(t)&&(F=t)}))),j=d(t,e,b,T,{width:L,height:C,viewX:G,viewY:Y,pathSlice:function(t){var e=G(t.x0),r=G(t.x1),n=Y(t.y0),i=Y(t.y1),a=r-e,o=i-n;if(!a||!o)return"";return"M"+K(e,n+0)+"L"+K(r-0,n)+"L"+K(r,i-0)+"L"+K(e+0,i)+"Z"},toMoveInsideSlice:et,prevEntry:F,makeUpdateSliceInterpolator:nt,makeUpdateTextInterpolator:it,handleSlicesExit:at,hasTransition:A,strTransform:ot}),v.pathbar.visible?f(t,e,b,w,{barDifY:z,width:P,height:I,viewX:Z,viewY:J,pathSlice:function(t){var e=Z(Math.max(Math.min(t.x0,t.x0),0)),r=Z(Math.min(Math.max(t.x1,t.x1),P)),n=J(t.y0),i=J(t.y1),a=I/2,o={},s={};o.x=e,s.x=r,o.y=s.y=(n+i)/2;var l={x:e,y:n},c={x:r,y:n},u={x:r,y:i},f={x:e,y:i};return">"===tt?(l.x-=a,c.x-=a,u.x-=a,f.x-=a):"/"===tt?(u.x-=a,f.x-=a,o.x-=a/2,s.x-=a/2):"\\"===tt?(l.x-=a,c.x-=a,o.x-=a/2,s.x-=a/2):"<"===tt&&(o.x-=a,s.x-=a),$(l),$(f),$(o),$(c),$(u),$(s),"M"+K(l.x,l.y)+"L"+K(c.x,c.y)+"L"+K(s.x,s.y)+"L"+K(u.x,u.y)+"L"+K(f.x,f.y)+"L"+K(o.x,o.y)+"Z"},toMoveInsideSlice:et,makeUpdateSliceInterpolator:nt,makeUpdateTextInterpolator:it,handleSlicesExit:at,hasTransition:A,strTransform:ot}):w.remove()}},{"../../lib":503,"../bar/constants":650,"../bar/plot":659,"../bar/uniform_text":664,"../sunburst/helpers":1055,"./constants":1078,"./draw_ancestors":1081,"@plotly/d3":58,"d3-interpolate":116}],1090:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/color"),a=t("../../lib"),o=t("../sunburst/helpers"),s=t("../bar/uniform_text").resizeText;function l(t,e,r,n){var s,l,c=(n||{}).hovered,u=e.data.data,f=u.i,h=u.color,p=o.isHierarchyRoot(e),d=1;if(c)s=r._hovered.marker.line.color,l=r._hovered.marker.line.width;else if(p&&h===r.root.color)d=100,s="rgba(0,0,0,0)",l=0;else if(s=a.castOption(r,f,"marker.line.color")||i.defaultLine,l=a.castOption(r,f,"marker.line.width")||0,!r._hasColorscale&&!e.onPathbar){var m=r.marker.depthfade;if(m){var g,v=i.combine(i.addOpacity(r._backgroundColor,.75),h);if(!0===m){var y=o.getMaxDepth(r);g=isFinite(y)?o.isLeaf(e)?0:r._maxVisibleLayers-(e.data.depth-r._entryDepth):e.data.height+1}else g=e.data.depth-r._entryDepth,r._atRootLevel||g++;if(g>0)for(var x=0;x<g;x++){var b=.5*x/g;h=i.combine(i.addOpacity(v,b),h)}}}t.style("stroke-width",l).call(i.fill,h).call(i.stroke,s).style("opacity",d)}e.exports={style:function(t){var e=t._fullLayout._treemaplayer.selectAll(".trace");s(t,e,"treemap"),e.each((function(t){var e=n.select(this),r=t[0].trace;e.style("opacity",r.opacity),e.selectAll("path.surface").each((function(t){n.select(this).call(l,t,r,{hovered:!1})}))}))},styleOne:l}},{"../../components/color":366,"../../lib":503,"../bar/uniform_text":664,"../sunburst/helpers":1055,"@plotly/d3":58}],1091:[function(t,e,r){"use strict";var n=t("../box/attributes"),i=t("../../lib/extend").extendFlat,a=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat;e.exports={y:n.y,x:n.x,x0:n.x0,y0:n.y0,xhoverformat:a("x"),yhoverformat:a("y"),name:i({},n.name,{}),orientation:i({},n.orientation,{}),bandwidth:{valType:"number",min:0,editType:"calc"},scalegroup:{valType:"string",dflt:"",editType:"calc"},scalemode:{valType:"enumerated",values:["width","count"],dflt:"width",editType:"calc"},spanmode:{valType:"enumerated",values:["soft","hard","manual"],dflt:"soft",editType:"calc"},span:{valType:"info_array",items:[{valType:"any",editType:"calc"},{valType:"any",editType:"calc"}],editType:"calc"},line:{color:{valType:"color",editType:"style"},width:{valType:"number",min:0,dflt:2,editType:"style"},editType:"plot"},fillcolor:n.fillcolor,points:i({},n.boxpoints,{}),jitter:i({},n.jitter,{}),pointpos:i({},n.pointpos,{}),width:i({},n.width,{}),marker:n.marker,text:n.text,hovertext:n.hovertext,hovertemplate:n.hovertemplate,box:{visible:{valType:"boolean",dflt:!1,editType:"plot"},width:{valType:"number",min:0,max:1,dflt:.25,editType:"plot"},fillcolor:{valType:"color",editType:"style"},line:{color:{valType:"color",editType:"style"},width:{valType:"number",min:0,editType:"style"},editType:"style"},editType:"plot"},meanline:{visible:{valType:"boolean",dflt:!1,editType:"plot"},color:{valType:"color",editType:"style"},width:{valType:"number",min:0,editType:"style"},editType:"plot"},side:{valType:"enumerated",values:["both","positive","negative"],dflt:"both",editType:"calc"},offsetgroup:n.offsetgroup,alignmentgroup:n.alignmentgroup,selected:n.selected,unselected:n.unselected,hoveron:{valType:"flaglist",flags:["violins","points","kde"],dflt:"violins+points+kde",extras:["all"],editType:"style"}}},{"../../lib/extend":493,"../../plots/cartesian/axis_format_attributes":557,"../box/attributes":673}],1092:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axes"),a=t("../box/calc"),o=t("./helpers"),s=t("../../constants/numerical").BADNUM;function l(t,e,r){var i=e.max-e.min;if(!i)return t.bandwidth?t.bandwidth:0;if(t.bandwidth)return Math.max(t.bandwidth,i/1e4);var a=r.length,o=n.stdev(r,a-1,e.mean);return Math.max(function(t,e,r){return 1.059*Math.min(e,r/1.349)*Math.pow(t,-.2)}(a,o,e.q3-e.q1),i/100)}function c(t,e,r,n){var a,o=t.spanmode,l=t.span||[],c=[e.min,e.max],u=[e.min-2*n,e.max+2*n];function f(n){var i=l[n],a="multicategory"===r.type?r.r2c(i):r.d2c(i,0,t[e.valLetter+"calendar"]);return a===s?u[n]:a}var h={type:"linear",range:a="soft"===o?u:"hard"===o?c:[f(0),f(1)]};return i.setConvert(h),h.cleanRange(),a}e.exports=function(t,e){var r=a(t,e);if(r[0].t.empty)return r;for(var s=t._fullLayout,u=i.getFromId(t,e["h"===e.orientation?"xaxis":"yaxis"]),f=1/0,h=-1/0,p=0,d=0,m=0;m<r.length;m++){var g=r[m],v=g.pts.map(o.extractVal),y=g.bandwidth=l(e,g,v),x=g.span=c(e,g,u,y);if(g.min===g.max&&0===y)x=g.span=[g.min,g.max],g.density=[{v:1,t:x[0]}],g.bandwidth=y,p=Math.max(p,1);else{var b=x[1]-x[0],_=Math.ceil(b/(y/3)),w=b/_;if(!isFinite(w)||!isFinite(_))return n.error("Something went wrong with computing the violin span"),r[0].t.empty=!0,r;var T=o.makeKDE(g,e,v);g.density=new Array(_);for(var k=0,A=x[0];A<x[1]+w/2;k++,A+=w){var M=T(A);g.density[k]={v:M,t:A},p=Math.max(p,M)}}d=Math.max(d,v.length),f=Math.min(f,x[0]),h=Math.max(h,x[1])}var S=i.findExtremes(u,[f,h],{padded:!0});if(e._extremes[u._id]=S,e.width)r[0].t.maxKDE=p;else{var E=s._violinScaleGroupStats,L=e.scalegroup,C=E[L];C?(C.maxKDE=Math.max(C.maxKDE,p),C.maxCount=Math.max(C.maxCount,d)):E[L]={maxKDE:p,maxCount:d}}return r[0].t.labels.kde=n._(t,"kde:"),r}},{"../../constants/numerical":479,"../../lib":503,"../../plots/cartesian/axes":554,"../box/calc":674,"./helpers":1095}],1093:[function(t,e,r){"use strict";var n=t("../box/cross_trace_calc").setPositionOffset,i=["v","h"];e.exports=function(t,e){for(var r=t.calcdata,a=e.xaxis,o=e.yaxis,s=0;s<i.length;s++){for(var l=i[s],c="h"===l?o:a,u=[],f=0;f<r.length;f++){var h=r[f],p=h[0].t,d=h[0].trace;!0!==d.visible||"violin"!==d.type||p.empty||d.orientation!==l||d.xaxis!==a._id||d.yaxis!==o._id||u.push(f)}n("violin",t,u,c)}}},{"../box/cross_trace_calc":675}],1094:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../components/color"),a=t("../box/defaults"),o=t("./attributes");e.exports=function(t,e,r,s){function l(r,i){return n.coerce(t,e,o,r,i)}function c(r,i){return n.coerce2(t,e,o,r,i)}if(a.handleSampleDefaults(t,e,l,s),!1!==e.visible){l("bandwidth"),l("side"),l("width")||(l("scalegroup",e.name),l("scalemode"));var u,f=l("span");Array.isArray(f)&&(u="manual"),l("spanmode",u);var h=l("line.color",(t.marker||{}).color||r),p=l("line.width"),d=l("fillcolor",i.addOpacity(e.line.color,.5));a.handlePointsDefaults(t,e,l,{prefix:""});var m=c("box.width"),g=c("box.fillcolor",d),v=c("box.line.color",h),y=c("box.line.width",p);l("box.visible",Boolean(m||g||v||y))||(e.box={visible:!1});var x=c("meanline.color",h),b=c("meanline.width",p);l("meanline.visible",Boolean(x||b))||(e.meanline={visible:!1})}}},{"../../components/color":366,"../../lib":503,"../box/defaults":676,"./attributes":1091}],1095:[function(t,e,r){"use strict";var n=t("../../lib"),i=function(t){return 1/Math.sqrt(2*Math.PI)*Math.exp(-.5*t*t)};r.makeKDE=function(t,e,r){var n=r.length,a=i,o=t.bandwidth,s=1/(n*o);return function(t){for(var e=0,i=0;i<n;i++)e+=a((t-r[i])/o);return s*e}},r.getPositionOnKdePath=function(t,e,r){var i,a;"h"===e.orientation?(i="y",a="x"):(i="x",a="y");var o=n.findPointOnPath(t.path,r,a,{pathLength:t.pathLength}),s=t.posCenterPx,l=o[i];return[l,"both"===e.side?2*s-l:s]},r.getKdeValue=function(t,e,n){var i=t.pts.map(r.extractVal);return r.makeKDE(t,e,i)(n)/t.posDensityScale},r.extractVal=function(t){return t.v}},{"../../lib":503}],1096:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../../plots/cartesian/axes"),a=t("../box/hover"),o=t("./helpers");e.exports=function(t,e,r,s,l){l||(l={});var c,u,f=l.hoverLayer,h=t.cd,p=h[0].trace,d=p.hoveron,m=-1!==d.indexOf("violins"),g=-1!==d.indexOf("kde"),v=[];if(m||g){var y=a.hoverOnBoxes(t,e,r,s);if(g&&y.length>0){var x,b,_,w,T,k=t.xa,A=t.ya;"h"===p.orientation?(T=e,x="y",_=A,b="x",w=k):(T=r,x="x",_=k,b="y",w=A);var M=h[t.index];if(T>=M.span[0]&&T<=M.span[1]){var S=n.extendFlat({},t),E=w.c2p(T,!0),L=o.getKdeValue(M,p,T),C=o.getPositionOnKdePath(M,p,E),P=_._offset,I=_._length;S[x+"0"]=C[0],S[x+"1"]=C[1],S[b+"0"]=S[b+"1"]=E,S[b+"Label"]=b+": "+i.hoverLabelText(w,T,p[b+"hoverformat"])+", "+h[0].t.labels.kde+" "+L.toFixed(3),S.spikeDistance=y[0].spikeDistance;var O=x+"Spike";S[O]=y[0][O],y[0].spikeDistance=void 0,y[0][O]=void 0,S.hovertemplate=!1,v.push(S),(u={stroke:t.color})[x+"1"]=n.constrain(P+C[0],P,P+I),u[x+"2"]=n.constrain(P+C[1],P,P+I),u[b+"1"]=u[b+"2"]=w._offset+E}}m&&(v=v.concat(y))}-1!==d.indexOf("points")&&(c=a.hoverOnPoints(t,e,r));var z=f.selectAll(".violinline-"+p.uid).data(u?[0]:[]);return z.enter().append("line").classed("violinline-"+p.uid,!0).attr("stroke-width",1.5),z.exit().remove(),z.attr(u),"closest"===s?c?[c]:v:c?(v.push(c),v):v}},{"../../lib":503,"../../plots/cartesian/axes":554,"../box/hover":678,"./helpers":1095}],1097:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),layoutAttributes:t("./layout_attributes"),supplyDefaults:t("./defaults"),crossTraceDefaults:t("../box/defaults").crossTraceDefaults,supplyLayoutDefaults:t("./layout_defaults"),calc:t("./calc"),crossTraceCalc:t("./cross_trace_calc"),plot:t("./plot"),style:t("./style"),styleOnSelect:t("../scatter/style").styleOnSelect,hoverPoints:t("./hover"),selectPoints:t("../box/select"),moduleType:"trace",name:"violin",basePlotModule:t("../../plots/cartesian"),categories:["cartesian","svg","symbols","oriented","box-violin","showLegend","violinLayout","zoomScale"],meta:{}}},{"../../plots/cartesian":568,"../box/defaults":676,"../box/select":683,"../scatter/style":951,"./attributes":1091,"./calc":1092,"./cross_trace_calc":1093,"./defaults":1094,"./hover":1096,"./layout_attributes":1098,"./layout_defaults":1099,"./plot":1100,"./style":1101}],1098:[function(t,e,r){"use strict";var n=t("../box/layout_attributes"),i=t("../../lib").extendFlat;e.exports={violinmode:i({},n.boxmode,{}),violingap:i({},n.boxgap,{}),violingroupgap:i({},n.boxgroupgap,{})}},{"../../lib":503,"../box/layout_attributes":680}],1099:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./layout_attributes"),a=t("../box/layout_defaults");e.exports=function(t,e,r){a._supply(t,e,r,(function(r,a){return n.coerce(t,e,i,r,a)}),"violin")}},{"../../lib":503,"../box/layout_defaults":681,"./layout_attributes":1098}],1100:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../../components/drawing"),o=t("../box/plot"),s=t("../scatter/line_points"),l=t("./helpers");e.exports=function(t,e,r,c){var u=t._fullLayout,f=e.xaxis,h=e.yaxis;function p(t){var e=s(t,{xaxis:f,yaxis:h,connectGaps:!0,baseTolerance:.75,shape:"spline",simplify:!0,linearized:!0});return a.smoothopen(e[0],1)}i.makeTraceGroups(c,r,"trace violins").each((function(t){var r=n.select(this),a=t[0],s=a.t,c=a.trace;if(!0!==c.visible||s.empty)r.remove();else{var d=s.bPos,m=s.bdPos,g=e[s.valLetter+"axis"],v=e[s.posLetter+"axis"],y="both"===c.side,x=y||"positive"===c.side,b=y||"negative"===c.side,_=r.selectAll("path.violin").data(i.identity);_.enter().append("path").style("vector-effect","non-scaling-stroke").attr("class","violin"),_.exit().remove(),_.each((function(t){var e,r,i,a,o,l,f,h,_=n.select(this),w=t.density,T=w.length,k=v.c2l(t.pos+d,!0),A=v.l2p(k);if(c.width)e=s.maxKDE/m;else{var M=u._violinScaleGroupStats[c.scalegroup];e="count"===c.scalemode?M.maxKDE/m*(M.maxCount/t.pts.length):M.maxKDE/m}if(x){for(f=new Array(T),o=0;o<T;o++)(h=f[o]={})[s.posLetter]=k+w[o].v/e,h[s.valLetter]=g.c2l(w[o].t,!0);r=p(f)}if(b){for(f=new Array(T),l=0,o=T-1;l<T;l++,o--)(h=f[l]={})[s.posLetter]=k-w[o].v/e,h[s.valLetter]=g.c2l(w[o].t,!0);i=p(f)}if(y)a=r+"L"+i.substr(1)+"Z";else{var S=[A,g.c2p(w[0].t)],E=[A,g.c2p(w[T-1].t)];"h"===c.orientation&&(S.reverse(),E.reverse()),a=x?"M"+S+"L"+r.substr(1)+"L"+E:"M"+E+"L"+i.substr(1)+"L"+S}_.attr("d",a),t.posCenterPx=A,t.posDensityScale=e*m,t.path=_.node(),t.pathLength=t.path.getTotalLength()/(y?2:1)}));var w,T,k,A=c.box,M=A.width,S=(A.line||{}).width;y?(w=m*M,T=0):x?(w=[0,m*M/2],T=S*{x:1,y:-1}[s.posLetter]):(w=[m*M/2,0],T=S*{x:-1,y:1}[s.posLetter]),o.plotBoxAndWhiskers(r,{pos:v,val:g},c,{bPos:d,bdPos:w,bPosPxOffset:T}),o.plotBoxMean(r,{pos:v,val:g},c,{bPos:d,bdPos:w,bPosPxOffset:T}),!c.box.visible&&c.meanline.visible&&(k=i.identity);var E=r.selectAll("path.meanline").data(k||[]);E.enter().append("path").attr("class","meanline").style("fill","none").style("vector-effect","non-scaling-stroke"),E.exit().remove(),E.each((function(t){var e=g.c2p(t.mean,!0),r=l.getPositionOnKdePath(t,c,e);n.select(this).attr("d","h"===c.orientation?"M"+e+","+r[0]+"V"+r[1]:"M"+r[0]+","+e+"H"+r[1])})),o.plotPoints(r,{x:f,y:h},c,s)}}))}},{"../../components/drawing":388,"../../lib":503,"../box/plot":682,"../scatter/line_points":941,"./helpers":1095,"@plotly/d3":58}],1101:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/color"),a=t("../scatter/style").stylePoints;e.exports=function(t){var e=n.select(t).selectAll("g.trace.violins");e.style("opacity",(function(t){return t[0].trace.opacity})),e.each((function(e){var r=e[0].trace,o=n.select(this),s=r.box||{},l=s.line||{},c=r.meanline||{},u=c.width;o.selectAll("path.violin").style("stroke-width",r.line.width+"px").call(i.stroke,r.line.color).call(i.fill,r.fillcolor),o.selectAll("path.box").style("stroke-width",l.width+"px").call(i.stroke,l.color).call(i.fill,s.fillcolor);var f={"stroke-width":u+"px","stroke-dasharray":2*u+"px,"+u+"px"};o.selectAll("path.mean").style(f).call(i.stroke,c.color),o.selectAll("path.meanline").style(f).call(i.stroke,c.color),a(o,r,t)}))}},{"../../components/color":366,"../scatter/style":951,"@plotly/d3":58}],1102:[function(t,e,r){"use strict";var n=t("../../components/colorscale/attributes"),i=t("../isosurface/attributes"),a=t("../surface/attributes"),o=t("../../plots/attributes"),s=t("../../lib/extend").extendFlat,l=t("../../plot_api/edit_types").overrideAll,c=e.exports=l(s({x:i.x,y:i.y,z:i.z,value:i.value,isomin:i.isomin,isomax:i.isomax,surface:i.surface,spaceframe:{show:{valType:"boolean",dflt:!1},fill:{valType:"number",min:0,max:1,dflt:1}},slices:i.slices,caps:i.caps,text:i.text,hovertext:i.hovertext,xhoverformat:i.xhoverformat,yhoverformat:i.yhoverformat,zhoverformat:i.zhoverformat,valuehoverformat:i.valuehoverformat,hovertemplate:i.hovertemplate},n("",{colorAttr:"`value`",showScaleDflt:!0,editTypeOverride:"calc"}),{colorbar:i.colorbar,opacity:i.opacity,opacityscale:a.opacityscale,lightposition:i.lightposition,lighting:i.lighting,flatshading:i.flatshading,contour:i.contour,hoverinfo:s({},o.hoverinfo),showlegend:s({},o.showlegend,{dflt:!1})}),"calc","nested");c.x.editType=c.y.editType=c.z.editType=c.value.editType="calc+clearAxisTypes",c.transforms=void 0},{"../../components/colorscale/attributes":373,"../../lib/extend":493,"../../plot_api/edit_types":536,"../../plots/attributes":550,"../isosurface/attributes":862,"../surface/attributes":1061}],1103:[function(t,e,r){"use strict";var n=t("../../../stackgl_modules").gl_mesh3d,i=t("../../lib/gl_format_color").parseColorScale,a=t("../../lib/str2rgbarray"),o=t("../../components/colorscale").extractOpts,s=t("../../plots/gl3d/zip3"),l=t("../isosurface/convert").findNearestOnAxis,c=t("../isosurface/convert").generateIsoMeshes;function u(t,e,r){this.scene=t,this.uid=r,this.mesh=e,this.name="",this.data=null,this.showContour=!1}var f=u.prototype;f.handlePick=function(t){if(t.object===this.mesh){var e=t.data.index,r=this.data._meshX[e],n=this.data._meshY[e],i=this.data._meshZ[e],a=this.data._Ys.length,o=this.data._Zs.length,s=l(r,this.data._Xs).id,c=l(n,this.data._Ys).id,u=l(i,this.data._Zs).id,f=t.index=u+o*c+o*a*s;t.traceCoordinate=[this.data._meshX[f],this.data._meshY[f],this.data._meshZ[f],this.data._value[f]];var h=this.data.hovertext||this.data.text;return Array.isArray(h)&&void 0!==h[f]?t.textLabel=h[f]:h&&(t.textLabel=h),!0}},f.update=function(t){var e=this.scene,r=e.fullSceneLayout;function n(t,e,r,n){return e.map((function(e){return t.d2l(e,0,n)*r}))}this.data=c(t);var l={positions:s(n(r.xaxis,t._meshX,e.dataScale[0],t.xcalendar),n(r.yaxis,t._meshY,e.dataScale[1],t.ycalendar),n(r.zaxis,t._meshZ,e.dataScale[2],t.zcalendar)),cells:s(t._meshI,t._meshJ,t._meshK),lightPosition:[t.lightposition.x,t.lightposition.y,t.lightposition.z],ambient:t.lighting.ambient,diffuse:t.lighting.diffuse,specular:t.lighting.specular,roughness:t.lighting.roughness,fresnel:t.lighting.fresnel,vertexNormalsEpsilon:t.lighting.vertexnormalsepsilon,faceNormalsEpsilon:t.lighting.facenormalsepsilon,opacity:t.opacity,opacityscale:t.opacityscale,contourEnable:t.contour.show,contourColor:a(t.contour.color).slice(0,3),contourWidth:t.contour.width,useFacetNormals:t.flatshading},u=o(t);l.vertexIntensity=t._meshIntensity,l.vertexIntensityBounds=[u.min,u.max],l.colormap=i(t),this.mesh.update(l)},f.dispose=function(){this.scene.glplot.remove(this.mesh),this.mesh.dispose()},e.exports=function(t,e){var r=t.glplot.gl,i=n({gl:r}),a=new u(t,i,e.uid);return i._trace=a,a.update(e),t.glplot.add(i),a}},{"../../../stackgl_modules":1124,"../../components/colorscale":378,"../../lib/gl_format_color":499,"../../lib/str2rgbarray":528,"../../plots/gl3d/zip3":609,"../isosurface/convert":864}],1104:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./attributes"),a=t("../isosurface/defaults").supplyIsoDefaults,o=t("../surface/defaults").opacityscaleDefaults;e.exports=function(t,e,r,s){function l(r,a){return n.coerce(t,e,i,r,a)}a(t,e,r,s,l),o(t,e,s,l)}},{"../../lib":503,"../isosurface/defaults":865,"../surface/defaults":1064,"./attributes":1102}],1105:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),supplyDefaults:t("./defaults"),calc:t("../isosurface/calc"),colorbar:{min:"cmin",max:"cmax"},plot:t("./convert"),moduleType:"trace",name:"volume",basePlotModule:t("../../plots/gl3d"),categories:["gl3d","showLegend"],meta:{}}},{"../../plots/gl3d":598,"../isosurface/calc":863,"./attributes":1102,"./convert":1103,"./defaults":1104}],1106:[function(t,e,r){"use strict";var n=t("../bar/attributes"),i=t("../scatter/attributes").line,a=t("../../plots/attributes"),o=t("../../plots/cartesian/axis_format_attributes").axisHoverFormat,s=t("../../plots/template_attributes").hovertemplateAttrs,l=t("../../plots/template_attributes").texttemplateAttrs,c=t("./constants"),u=t("../../lib/extend").extendFlat,f=t("../../components/color");function h(t){return{marker:{color:u({},n.marker.color,{arrayOk:!1,editType:"style"}),line:{color:u({},n.marker.line.color,{arrayOk:!1,editType:"style"}),width:u({},n.marker.line.width,{arrayOk:!1,editType:"style"}),editType:"style"},editType:"style"},editType:"style"}}e.exports={measure:{valType:"data_array",dflt:[],editType:"calc"},base:{valType:"number",dflt:null,arrayOk:!1,editType:"calc"},x:n.x,x0:n.x0,dx:n.dx,y:n.y,y0:n.y0,dy:n.dy,xperiod:n.xperiod,yperiod:n.yperiod,xperiod0:n.xperiod0,yperiod0:n.yperiod0,xperiodalignment:n.xperiodalignment,yperiodalignment:n.yperiodalignment,xhoverformat:o("x"),yhoverformat:o("y"),hovertext:n.hovertext,hovertemplate:s({},{keys:c.eventDataKeys}),hoverinfo:u({},a.hoverinfo,{flags:["name","x","y","text","initial","delta","final"]}),textinfo:{valType:"flaglist",flags:["label","text","initial","delta","final"],extras:["none"],editType:"plot",arrayOk:!1},texttemplate:l({editType:"plot"},{keys:c.eventDataKeys.concat(["label"])}),text:n.text,textposition:n.textposition,insidetextanchor:n.insidetextanchor,textangle:n.textangle,textfont:n.textfont,insidetextfont:n.insidetextfont,outsidetextfont:n.outsidetextfont,constraintext:n.constraintext,cliponaxis:n.cliponaxis,orientation:n.orientation,offset:n.offset,width:n.width,increasing:h(),decreasing:h(),totals:h(),connector:{line:{color:u({},i.color,{dflt:f.defaultLine}),width:u({},i.width,{editType:"plot"}),dash:i.dash,editType:"plot"},mode:{valType:"enumerated",values:["spanning","between"],dflt:"between",editType:"plot"},visible:{valType:"boolean",dflt:!0,editType:"plot"},editType:"plot"},offsetgroup:n.offsetgroup,alignmentgroup:n.alignmentgroup}},{"../../components/color":366,"../../lib/extend":493,"../../plots/attributes":550,"../../plots/cartesian/axis_format_attributes":557,"../../plots/template_attributes":633,"../bar/attributes":648,"../scatter/attributes":927,"./constants":1108}],1107:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes"),i=t("../../plots/cartesian/align_period"),a=t("../../lib").mergeArray,o=t("../scatter/calc_selection"),s=t("../../constants/numerical").BADNUM;function l(t){return"a"===t||"absolute"===t}function c(t){return"t"===t||"total"===t}e.exports=function(t,e){var r,u,f,h,p,d,m=n.getFromId(t,e.xaxis||"x"),g=n.getFromId(t,e.yaxis||"y");"h"===e.orientation?(r=m.makeCalcdata(e,"x"),f=g.makeCalcdata(e,"y"),h=i(e,g,"y",f),p=!!e.yperiodalignment,d="y"):(r=g.makeCalcdata(e,"y"),f=m.makeCalcdata(e,"x"),h=i(e,m,"x",f),p=!!e.xperiodalignment,d="x"),u=h.vals;for(var v,y=Math.min(u.length,r.length),x=new Array(y),b=0,_=!1,w=0;w<y;w++){var T=r[w]||0,k=!1;(r[w]!==s||c(e.measure[w])||l(e.measure[w]))&&w+1<y&&(r[w+1]!==s||c(e.measure[w+1])||l(e.measure[w+1]))&&(k=!0);var A=x[w]={i:w,p:u[w],s:T,rawS:T,cNext:k};l(e.measure[w])?(b=A.s,A.isSum=!0,A.dir="totals",A.s=b):c(e.measure[w])?(A.isSum=!0,A.dir="totals",A.s=b):(A.isSum=!1,A.dir=A.rawS<0?"decreasing":"increasing",v=A.s,A.s=b+v,b+=v),"totals"===A.dir&&(_=!0),p&&(x[w].orig_p=f[w],x[w][d+"End"]=h.ends[w],x[w][d+"Start"]=h.starts[w]),e.ids&&(A.id=String(e.ids[w])),A.v=(e.base||0)+b}return x.length&&(x[0].hasTotals=_),a(e.text,x,"tx"),a(e.hovertext,x,"htx"),o(x,e),x}},{"../../constants/numerical":479,"../../lib":503,"../../plots/cartesian/align_period":551,"../../plots/cartesian/axes":554,"../scatter/calc_selection":929}],1108:[function(t,e,r){"use strict";e.exports={eventDataKeys:["initial","delta","final"]}},{}],1109:[function(t,e,r){"use strict";var n=t("../bar/cross_trace_calc").setGroupPositions;e.exports=function(t,e){var r,i,a=t._fullLayout,o=t._fullData,s=t.calcdata,l=e.xaxis,c=e.yaxis,u=[],f=[],h=[];for(i=0;i<o.length;i++){var p=o[i];!0===p.visible&&p.xaxis===l._id&&p.yaxis===c._id&&"waterfall"===p.type&&(r=s[i],"h"===p.orientation?h.push(r):f.push(r),u.push(r))}var d={mode:a.waterfallmode,norm:a.waterfallnorm,gap:a.waterfallgap,groupgap:a.waterfallgroupgap};for(n(t,l,c,f,d),n(t,c,l,h,d),i=0;i<u.length;i++){r=u[i];for(var m=0;m<r.length;m++){var g=r[m];!1===g.isSum&&(g.s0+=0===m?0:r[m-1].s),m+1<r.length&&(r[m].nextP0=r[m+1].p0,r[m].nextS0=r[m+1].s0)}}}},{"../bar/cross_trace_calc":651}],1110:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("../bar/defaults").handleGroupingDefaults,a=t("../bar/defaults").handleText,o=t("../scatter/xy_defaults"),s=t("../scatter/period_defaults"),l=t("./attributes"),c=t("../../components/color"),u=t("../../constants/delta.js"),f=u.INCREASING.COLOR,h=u.DECREASING.COLOR;function p(t,e,r){t(e+".marker.color",r),t(e+".marker.line.color",c.defaultLine),t(e+".marker.line.width")}e.exports={supplyDefaults:function(t,e,r,i){function c(r,i){return n.coerce(t,e,l,r,i)}if(o(t,e,i,c)){s(t,e,i,c),c("xhoverformat"),c("yhoverformat"),c("measure"),c("orientation",e.x&&!e.y?"h":"v"),c("base"),c("offset"),c("width"),c("text"),c("hovertext"),c("hovertemplate");var u=c("textposition");if(a(t,e,i,c,u,{moduleHasSelected:!1,moduleHasUnselected:!1,moduleHasConstrain:!0,moduleHasCliponaxis:!0,moduleHasTextangle:!0,moduleHasInsideanchor:!0}),"none"!==e.textposition&&(c("texttemplate"),e.texttemplate||c("textinfo")),p(c,"increasing",f),p(c,"decreasing",h),p(c,"totals","#4499FF"),c("connector.visible"))c("connector.mode"),c("connector.line.width")&&(c("connector.line.color"),c("connector.line.dash"))}else e.visible=!1},crossTraceDefaults:function(t,e){var r,a;function o(t){return n.coerce(a._input,a,l,t)}if("group"===e.waterfallmode)for(var s=0;s<t.length;s++)r=(a=t[s])._input,i(r,a,e,o)}}},{"../../components/color":366,"../../constants/delta.js":473,"../../lib":503,"../bar/defaults":652,"../scatter/period_defaults":947,"../scatter/xy_defaults":954,"./attributes":1106}],1111:[function(t,e,r){"use strict";e.exports=function(t,e){return t.x="xVal"in e?e.xVal:e.x,t.y="yVal"in e?e.yVal:e.y,"initial"in e&&(t.initial=e.initial),"delta"in e&&(t.delta=e.delta),"final"in e&&(t.final=e.final),e.xa&&(t.xaxis=e.xa),e.ya&&(t.yaxis=e.ya),t}},{}],1112:[function(t,e,r){"use strict";var n=t("../../plots/cartesian/axes").hoverLabelText,i=t("../../components/color").opacity,a=t("../bar/hover").hoverOnBars,o=t("../../constants/delta.js"),s=o.INCREASING.SYMBOL,l=o.DECREASING.SYMBOL;e.exports=function(t,e,r,o,c){var u=a(t,e,r,o,c);if(u){var f=u.cd,h=f[0].trace,p="h"===h.orientation,d=p?"x":"y",m=p?t.xa:t.ya,g=f[u.index],v=g.isSum?g.b+g.s:g.rawS;if(!g.isSum){u.initial=g.b+g.s-v,u.delta=v,u.final=u.initial+u.delta;var y=k(Math.abs(u.delta));u.deltaLabel=v<0?"("+y+")":y,u.finalLabel=k(u.final),u.initialLabel=k(u.initial)}var x=g.hi||h.hoverinfo,b=[];if(x&&"none"!==x&&"skip"!==x){var _="all"===x,w=x.split("+"),T=function(t){return _||-1!==w.indexOf(t)};g.isSum||(!T("final")||T(p?"x":"y")||b.push(u.finalLabel),T("delta")&&(v<0?b.push(u.deltaLabel+" "+l):b.push(u.deltaLabel+" "+s)),T("initial")&&b.push("Initial: "+u.initialLabel))}return b.length&&(u.extraText=b.join("<br>")),u.color=function(t,e){var r=t[e.dir].marker,n=r.color,a=r.line.color,o=r.line.width;if(i(n))return n;if(i(a)&&o)return a}(h,g),[u]}function k(t){return n(m,t,h[d+"hoverformat"])}}},{"../../components/color":366,"../../constants/delta.js":473,"../../plots/cartesian/axes":554,"../bar/hover":655}],1113:[function(t,e,r){"use strict";e.exports={attributes:t("./attributes"),layoutAttributes:t("./layout_attributes"),supplyDefaults:t("./defaults").supplyDefaults,crossTraceDefaults:t("./defaults").crossTraceDefaults,supplyLayoutDefaults:t("./layout_defaults"),calc:t("./calc"),crossTraceCalc:t("./cross_trace_calc"),plot:t("./plot"),style:t("./style").style,hoverPoints:t("./hover"),eventData:t("./event_data"),selectPoints:t("../bar/select"),moduleType:"trace",name:"waterfall",basePlotModule:t("../../plots/cartesian"),categories:["bar-like","cartesian","svg","oriented","showLegend","zoomScale"],meta:{}}},{"../../plots/cartesian":568,"../bar/select":660,"./attributes":1106,"./calc":1107,"./cross_trace_calc":1109,"./defaults":1110,"./event_data":1111,"./hover":1112,"./layout_attributes":1114,"./layout_defaults":1115,"./plot":1116,"./style":1117}],1114:[function(t,e,r){"use strict";e.exports={waterfallmode:{valType:"enumerated",values:["group","overlay"],dflt:"group",editType:"calc"},waterfallgap:{valType:"number",min:0,max:1,editType:"calc"},waterfallgroupgap:{valType:"number",min:0,max:1,dflt:0,editType:"calc"}}},{}],1115:[function(t,e,r){"use strict";var n=t("../../lib"),i=t("./layout_attributes");e.exports=function(t,e,r){var a=!1;function o(r,a){return n.coerce(t,e,i,r,a)}for(var s=0;s<r.length;s++){var l=r[s];if(l.visible&&"waterfall"===l.type){a=!0;break}}a&&(o("waterfallmode"),o("waterfallgap",.2),o("waterfallgroupgap"))}},{"../../lib":503,"./layout_attributes":1114}],1116:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../lib"),a=t("../../components/drawing"),o=t("../../constants/numerical").BADNUM,s=t("../bar/plot"),l=t("../bar/uniform_text").clearMinTextSize;e.exports=function(t,e,r,c){var u=t._fullLayout;l("waterfall",u),s.plot(t,e,r,c,{mode:u.waterfallmode,norm:u.waterfallmode,gap:u.waterfallgap,groupgap:u.waterfallgroupgap}),function(t,e,r,s){var l=e.xaxis,c=e.yaxis;i.makeTraceGroups(s,r,"trace bars").each((function(r){var s=n.select(this),u=r[0].trace,f=i.ensureSingle(s,"g","lines");if(u.connector&&u.connector.visible){var h="h"===u.orientation,p=u.connector.mode,d=f.selectAll("g.line").data(i.identity);d.enter().append("g").classed("line",!0),d.exit().remove();var m=d.size();d.each((function(r,s){if(s===m-1||r.cNext){var u=function(t,e,r,n){var i=[],a=[],o=n?e:r,s=n?r:e;return i[0]=o.c2p(t.s0,!0),a[0]=s.c2p(t.p0,!0),i[1]=o.c2p(t.s1,!0),a[1]=s.c2p(t.p1,!0),i[2]=o.c2p(t.nextS0,!0),a[2]=s.c2p(t.nextP0,!0),n?[i,a]:[a,i]}(r,l,c,h),f=u[0],d=u[1],g="";f[0]!==o&&d[0]!==o&&f[1]!==o&&d[1]!==o&&("spanning"===p&&!r.isSum&&s>0&&(g+=h?"M"+f[0]+","+d[1]+"V"+d[0]:"M"+f[1]+","+d[0]+"H"+f[0]),"between"!==p&&(r.isSum||s<m-1)&&(g+=h?"M"+f[1]+","+d[0]+"V"+d[1]:"M"+f[0]+","+d[1]+"H"+f[1]),f[2]!==o&&d[2]!==o&&(g+=h?"M"+f[1]+","+d[1]+"V"+d[2]:"M"+f[1]+","+d[1]+"H"+f[2])),""===g&&(g="M0,0Z"),i.ensureSingle(n.select(this),"path").attr("d",g).call(a.setClipUrl,e.layerClipId,t)}}))}else f.remove()}))}(t,e,r,c)}},{"../../components/drawing":388,"../../constants/numerical":479,"../../lib":503,"../bar/plot":659,"../bar/uniform_text":664,"@plotly/d3":58}],1117:[function(t,e,r){"use strict";var n=t("@plotly/d3"),i=t("../../components/drawing"),a=t("../../components/color"),o=t("../../constants/interactions").DESELECTDIM,s=t("../bar/style"),l=t("../bar/uniform_text").resizeText,c=s.styleTextPoints;e.exports={style:function(t,e,r){var s=r||n.select(t).selectAll("g.waterfalllayer").selectAll("g.trace");l(t,s,"waterfall"),s.style("opacity",(function(t){return t[0].trace.opacity})),s.each((function(e){var r=n.select(this),s=e[0].trace;r.selectAll(".point > path").each((function(t){if(!t.isBlank){var e=s[t.dir].marker;n.select(this).call(a.fill,e.color).call(a.stroke,e.line.color).call(i.dashLine,e.line.dash,e.line.width).style("opacity",s.selectedpoints&&!t.selected?o:1)}})),c(r,s,t),r.selectAll(".lines").each((function(){var t=s.connector.line;i.lineGroupStyle(n.select(this).selectAll("path"),t.width,t.color,t.dash)}))}))}}},{"../../components/color":366,"../../components/drawing":388,"../../constants/interactions":478,"../bar/style":662,"../bar/uniform_text":664,"@plotly/d3":58}],1118:[function(t,e,r){"use strict";var n=t("../plots/cartesian/axes"),i=t("../lib"),a=t("../plot_api/plot_schema"),o=t("./helpers").pointsAccessorFunction,s=t("../constants/numerical").BADNUM;r.moduleType="transform",r.name="aggregate";var l=r.attributes={enabled:{valType:"boolean",dflt:!0,editType:"calc"},groups:{valType:"string",strict:!0,noBlank:!0,arrayOk:!0,dflt:"x",editType:"calc"},aggregations:{_isLinkedToArray:"aggregation",target:{valType:"string",editType:"calc"},func:{valType:"enumerated",values:["count","sum","avg","median","mode","rms","stddev","min","max","first","last","change","range"],dflt:"first",editType:"calc"},funcmode:{valType:"enumerated",values:["sample","population"],dflt:"sample",editType:"calc"},enabled:{valType:"boolean",dflt:!0,editType:"calc"},editType:"calc"},editType:"calc"},c=l.aggregations;function u(t,e,r,a){if(a.enabled){for(var o=a.target,l=i.nestedProperty(e,o),c=l.get(),u=function(t,e){var r=t.func,n=e.d2c,a=e.c2d;switch(r){case"count":return f;case"first":return h;case"last":return p;case"sum":return function(t,e){for(var r=0,i=0;i<e.length;i++){var o=n(t[e[i]]);o!==s&&(r+=o)}return a(r)};case"avg":return function(t,e){for(var r=0,i=0,o=0;o<e.length;o++){var l=n(t[e[o]]);l!==s&&(r+=l,i++)}return i?a(r/i):s};case"min":return function(t,e){for(var r=1/0,i=0;i<e.length;i++){var o=n(t[e[i]]);o!==s&&(r=Math.min(r,o))}return r===1/0?s:a(r)};case"max":return function(t,e){for(var r=-1/0,i=0;i<e.length;i++){var o=n(t[e[i]]);o!==s&&(r=Math.max(r,o))}return r===-1/0?s:a(r)};case"range":return function(t,e){for(var r=1/0,i=-1/0,o=0;o<e.length;o++){var l=n(t[e[o]]);l!==s&&(r=Math.min(r,l),i=Math.max(i,l))}return i===-1/0||r===1/0?s:a(i-r)};case"change":return function(t,e){var r=n(t[e[0]]),i=n(t[e[e.length-1]]);return r===s||i===s?s:a(i-r)};case"median":return function(t,e){for(var r=[],o=0;o<e.length;o++){var l=n(t[e[o]]);l!==s&&r.push(l)}if(!r.length)return s;r.sort(i.sorterAsc);var c=(r.length-1)/2;return a((r[Math.floor(c)]+r[Math.ceil(c)])/2)};case"mode":return function(t,e){for(var r={},i=0,o=s,l=0;l<e.length;l++){var c=n(t[e[l]]);if(c!==s){var u=r[c]=(r[c]||0)+1;u>i&&(i=u,o=c)}}return i?a(o):s};case"rms":return function(t,e){for(var r=0,i=0,o=0;o<e.length;o++){var l=n(t[e[o]]);l!==s&&(r+=l*l,i++)}return i?a(Math.sqrt(r/i)):s};case"stddev":return function(e,r){var i,a=0,o=0,l=1,c=s;for(i=0;i<r.length&&c===s;i++)c=n(e[r[i]]);if(c===s)return s;for(;i<r.length;i++){var u=n(e[r[i]]);if(u!==s){var f=u-c;a+=f,o+=f*f,l++}}var h="sample"===t.funcmode?l-1:l;return h?Math.sqrt((o-a*a/l)/h):0}}}(a,n.getDataConversions(t,e,o,c)),d=new Array(r.length),m=0;m<r.length;m++)d[m]=u(c,r[m]);l.set(d),"count"===a.func&&i.pushUnique(e._arrayAttrs,o)}}function f(t,e){return e.length}function h(t,e){return t[e[0]]}function p(t,e){return t[e[e.length-1]]}r.supplyDefaults=function(t,e){var r,n={};function o(e,r){return i.coerce(t,n,l,e,r)}if(!o("enabled"))return n;var s=a.findArrayAttributes(e),u={};for(r=0;r<s.length;r++)u[s[r]]=1;var f=o("groups");if(!Array.isArray(f)){if(!u[f])return n.enabled=!1,n;u[f]=0}var h,p=t.aggregations||[],d=n.aggregations=new Array(p.length);function m(t,e){return i.coerce(p[r],h,c,t,e)}for(r=0;r<p.length;r++){h={_index:r};var g=m("target"),v=m("func");m("enabled")&&g&&(u[g]||"count"===v&&void 0===u[g])?("stddev"===v&&m("funcmode"),u[g]=0,d[r]=h):d[r]={enabled:!1,_index:r}}for(r=0;r<s.length;r++)u[s[r]]&&d.push({target:s[r],func:c.func.dflt,enabled:!0,_index:-1});return n},r.calcTransform=function(t,e,r){if(r.enabled){var n=r.groups,a=i.getTargetArray(e,{target:n});if(a){var s,l,c,f,h={},p={},d=[],m=o(e.transforms,r),g=a.length;for(e._length&&(g=Math.min(g,e._length)),s=0;s<g;s++)void 0===(c=h[l=a[s]])?(h[l]=d.length,f=[s],d.push(f),p[h[l]]=m(s)):(d[c].push(s),p[h[l]]=(p[h[l]]||[]).concat(m(s)));r._indexToPoints=p;var v=r.aggregations;for(s=0;s<v.length;s++)u(t,e,d,v[s]);"string"==typeof n&&u(t,e,d,{target:n,func:"first",enabled:!0}),e._length=d.length}}}},{"../constants/numerical":479,"../lib":503,"../plot_api/plot_schema":542,"../plots/cartesian/axes":554,"./helpers":1121}],1119:[function(t,e,r){"use strict";var n=t("../lib"),i=t("../registry"),a=t("../plots/cartesian/axes"),o=t("./helpers").pointsAccessorFunction,s=t("../constants/filter_ops"),l=s.COMPARISON_OPS,c=s.INTERVAL_OPS,u=s.SET_OPS;r.moduleType="transform",r.name="filter",r.attributes={enabled:{valType:"boolean",dflt:!0,editType:"calc"},target:{valType:"string",strict:!0,noBlank:!0,arrayOk:!0,dflt:"x",editType:"calc"},operation:{valType:"enumerated",values:[].concat(l).concat(c).concat(u),dflt:"=",editType:"calc"},value:{valType:"any",dflt:0,editType:"calc"},preservegaps:{valType:"boolean",dflt:!1,editType:"calc"},editType:"calc"},r.supplyDefaults=function(t){var e={};function a(i,a){return n.coerce(t,e,r.attributes,i,a)}if(a("enabled")){var o=a("target");if(n.isArrayOrTypedArray(o)&&0===o.length)return e.enabled=!1,e;a("preservegaps"),a("operation"),a("value");var s=i.getComponentMethod("calendars","handleDefaults");s(t,e,"valuecalendar",null),s(t,e,"targetcalendar",null)}return e},r.calcTransform=function(t,e,r){if(r.enabled){var i=n.getTargetArray(e,r);if(i){var s=r.target,f=i.length;e._length&&(f=Math.min(f,e._length));var h=r.targetcalendar,p=e._arrayAttrs,d=r.preservegaps;if("string"==typeof s){var m=n.nestedProperty(e,s+"calendar").get();m&&(h=m)}var g,v,y=function(t,e,r){var n=t.operation,i=t.value,a=Array.isArray(i);function o(t){return-1!==t.indexOf(n)}var s,f=function(r){return e(r,0,t.valuecalendar)},h=function(t){return e(t,0,r)};o(l)?s=f(a?i[0]:i):o(c)?s=a?[f(i[0]),f(i[1])]:[f(i),f(i)]:o(u)&&(s=a?i.map(f):[f(i)]);switch(n){case"=":return function(t){return h(t)===s};case"!=":return function(t){return h(t)!==s};case"<":return function(t){return h(t)<s};case"<=":return function(t){return h(t)<=s};case">":return function(t){return h(t)>s};case">=":return function(t){return h(t)>=s};case"[]":return function(t){var e=h(t);return e>=s[0]&&e<=s[1]};case"()":return function(t){var e=h(t);return e>s[0]&&e<s[1]};case"[)":return function(t){var e=h(t);return e>=s[0]&&e<s[1]};case"(]":return function(t){var e=h(t);return e>s[0]&&e<=s[1]};case"][":return function(t){var e=h(t);return e<=s[0]||e>=s[1]};case")(":return function(t){var e=h(t);return e<s[0]||e>s[1]};case"](":return function(t){var e=h(t);return e<=s[0]||e>s[1]};case")[":return function(t){var e=h(t);return e<s[0]||e>=s[1]};case"{}":return function(t){return-1!==s.indexOf(h(t))};case"}{":return function(t){return-1===s.indexOf(h(t))}}}(r,a.getDataToCoordFunc(t,e,s,i),h),x={},b={},_=0;d?(g=function(t){x[t.astr]=n.extendDeep([],t.get()),t.set(new Array(f))},v=function(t,e){var r=x[t.astr][e];t.get()[e]=r}):(g=function(t){x[t.astr]=n.extendDeep([],t.get()),t.set([])},v=function(t,e){var r=x[t.astr][e];t.get().push(r)}),k(g);for(var w=o(e.transforms,r),T=0;T<f;T++){y(i[T])?(k(v,T),b[_++]=w(T)):d&&_++}r._indexToPoints=b,e._length=_}}function k(t,r){for(var i=0;i<p.length;i++){t(n.nestedProperty(e,p[i]),r)}}}},{"../constants/filter_ops":475,"../lib":503,"../plots/cartesian/axes":554,"../registry":638,"./helpers":1121}],1120:[function(t,e,r){"use strict";var n=t("../lib"),i=t("../plot_api/plot_schema"),a=t("../plots/plots"),o=t("./helpers").pointsAccessorFunction;function s(t,e){var r,s,l,c,u,f,h,p,d,m,g=e.transform,v=e.transformIndex,y=t.transforms[v].groups,x=o(t.transforms,g);if(!n.isArrayOrTypedArray(y)||0===y.length)return[t];var b=n.filterUnique(y),_=new Array(b.length),w=y.length,T=i.findArrayAttributes(t),k=g.styles||[],A={};for(r=0;r<k.length;r++)A[k[r].target]=k[r].value;g.styles&&(m=n.keyedContainer(g,"styles","target","value.name"));var M={},S={};for(r=0;r<b.length;r++){M[f=b[r]]=r,S[f]=0,(h=_[r]=n.extendDeepNoArrays({},t))._group=f,h.transforms[v]._indexToPoints={};var E=null;for(m&&(E=m.get(f)),h.name=E||""===E?E:n.templateString(g.nameformat,{trace:t.name,group:f}),p=h.transforms,h.transforms=[],s=0;s<p.length;s++)h.transforms[s]=n.extendDeepNoArrays({},p[s]);for(s=0;s<T.length;s++)n.nestedProperty(h,T[s]).set([])}for(l=0;l<T.length;l++){for(c=T[l],s=0,d=[];s<b.length;s++)d[s]=n.nestedProperty(_[s],c).get();for(u=n.nestedProperty(t,c).get(),s=0;s<w;s++)d[M[y[s]]].push(u[s])}for(s=0;s<w;s++){(h=_[M[y[s]]]).transforms[v]._indexToPoints[S[y[s]]]=x(s),S[y[s]]++}for(r=0;r<b.length;r++)f=b[r],h=_[r],a.clearExpandedTraceDefaultColors(h),h=n.extendDeepNoArrays(h,A[f]||{});return _}r.moduleType="transform",r.name="groupby",r.attributes={enabled:{valType:"boolean",dflt:!0,editType:"calc"},groups:{valType:"data_array",dflt:[],editType:"calc"},nameformat:{valType:"string",editType:"calc"},styles:{_isLinkedToArray:"style",target:{valType:"string",editType:"calc"},value:{valType:"any",dflt:{},editType:"calc",_compareAsJSON:!0},editType:"calc"},editType:"calc"},r.supplyDefaults=function(t,e,i){var a,o={};function s(e,i){return n.coerce(t,o,r.attributes,e,i)}if(!s("enabled"))return o;s("groups"),s("nameformat",i._dataLength>1?"%{group} (%{trace})":"%{group}");var l=t.styles,c=o.styles=[];if(l)for(a=0;a<l.length;a++){var u=c[a]={};n.coerce(l[a],c[a],r.attributes.styles,"target");var f=n.coerce(l[a],c[a],r.attributes.styles,"value");n.isPlainObject(f)?u.value=n.extendDeep({},f):f&&delete u.value}return o},r.transform=function(t,e){var r,n,i,a=[];for(n=0;n<t.length;n++)for(r=s(t[n],e),i=0;i<r.length;i++)a.push(r[i]);return a}},{"../lib":503,"../plot_api/plot_schema":542,"../plots/plots":619,"./helpers":1121}],1121:[function(t,e,r){"use strict";r.pointsAccessorFunction=function(t,e){for(var r,n,i=0;i<t.length&&(r=t[i])!==e;i++)r._indexToPoints&&!1!==r.enabled&&(n=r._indexToPoints);return n?function(t){return n[t]}:function(t){return[t]}}},{}],1122:[function(t,e,r){"use strict";var n=t("../lib"),i=t("../plots/cartesian/axes"),a=t("./helpers").pointsAccessorFunction,o=t("../constants/numerical").BADNUM;r.moduleType="transform",r.name="sort",r.attributes={enabled:{valType:"boolean",dflt:!0,editType:"calc"},target:{valType:"string",strict:!0,noBlank:!0,arrayOk:!0,dflt:"x",editType:"calc"},order:{valType:"enumerated",values:["ascending","descending"],dflt:"ascending",editType:"calc"},editType:"calc"},r.supplyDefaults=function(t){var e={};function i(i,a){return n.coerce(t,e,r.attributes,i,a)}return i("enabled")&&(i("target"),i("order")),e},r.calcTransform=function(t,e,r){if(r.enabled){var s=n.getTargetArray(e,r);if(s){var l=r.target,c=s.length;e._length&&(c=Math.min(c,e._length));var u,f,h=e._arrayAttrs,p=function(t,e,r,n){var i,a=new Array(n),s=new Array(n);for(i=0;i<n;i++)a[i]={v:e[i],i:i};for(a.sort(function(t,e){switch(t.order){case"ascending":return function(t,r){var n=e(t.v),i=e(r.v);return n===o?1:i===o?-1:n-i};case"descending":return function(t,r){var n=e(t.v),i=e(r.v);return n===o?1:i===o?-1:i-n}}}(t,r)),i=0;i<n;i++)s[i]=a[i].i;return s}(r,s,i.getDataToCoordFunc(t,e,l,s),c),d=a(e.transforms,r),m={};for(u=0;u<h.length;u++){var g=n.nestedProperty(e,h[u]),v=g.get(),y=new Array(c);for(f=0;f<c;f++)y[f]=v[p[f]];g.set(y)}for(f=0;f<c;f++)m[f]=d(p[f]);r._indexToPoints=m,e._length=c}}}},{"../constants/numerical":479,"../lib":503,"../plots/cartesian/axes":554,"./helpers":1121}],1123:[function(t,e,r){"use strict";r.version="2.12.1"},{}],1124:[function(t,e,r){(function(n){(function(){!function(t){"object"==typeof r&&void 0!==e?e.exports=t():("undefined"!=typeof window?window:void 0!==n?n:"undefined"!=typeof self?self:this).stackgl=t()}((function(){return function e(r,n,i){function a(s,l){if(!n[s]){if(!r[s]){var c="function"==typeof t&&t;if(!l&&c)return c(s,!0);if(o)return o(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var f=n[s]={exports:{}};r[s][0].call(f.exports,(function(t){return a(r[s][1][t]||t)}),f,f.exports,e,r,n,i)}return n[s].exports}for(var o="function"==typeof t&&t,s=0;s<i.length;s++)a(i[s]);return a}({1:[function(t,e,r){"use strict";r.byteLength=function(t){var e=c(t),r=e[0],n=e[1];return 3*(r+n)/4-n},r.toByteArray=function(t){var e,r,n=c(t),o=n[0],s=n[1],l=new a(function(t,e,r){return 3*(e+r)/4-r}(0,o,s)),u=0,f=s>0?o-4:o;for(r=0;r<f;r+=4)e=i[t.charCodeAt(r)]<<18|i[t.charCodeAt(r+1)]<<12|i[t.charCodeAt(r+2)]<<6|i[t.charCodeAt(r+3)],l[u++]=e>>16&255,l[u++]=e>>8&255,l[u++]=255&e;2===s&&(e=i[t.charCodeAt(r)]<<2|i[t.charCodeAt(r+1)]>>4,l[u++]=255&e);1===s&&(e=i[t.charCodeAt(r)]<<10|i[t.charCodeAt(r+1)]<<4|i[t.charCodeAt(r+2)]>>2,l[u++]=e>>8&255,l[u++]=255&e);return l},r.fromByteArray=function(t){for(var e,r=t.length,i=r%3,a=[],o=0,s=r-i;o<s;o+=16383)a.push(u(t,o,o+16383>s?s:o+16383));1===i?(e=t[r-1],a.push(n[e>>2]+n[e<<4&63]+"==")):2===i&&(e=(t[r-2]<<8)+t[r-1],a.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return a.join("")};for(var n=[],i=[],a="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0,l=o.length;s<l;++s)n[s]=o[s],i[o.charCodeAt(s)]=s;function c(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function u(t,e,r){for(var i,a,o=[],s=e;s<r;s+=3)i=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(255&t[s+2]),o.push(n[(a=i)>>18&63]+n[a>>12&63]+n[a>>6&63]+n[63&a]);return o.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},{}],2:[function(t,e,r){},{}],3:[function(t,e,r){(function(e){(function(){
/*!
 * The buffer module from node.js, for the browser.
 *
 * @author   Feross Aboukhadijeh <https://feross.org>
 * @license  MIT
 */
"use strict";var e=t("base64-js"),n=t("ieee754");r.Buffer=a,r.SlowBuffer=function(t){+t!=t&&(t=0);return a.alloc(+t)},r.INSPECT_MAX_BYTES=50;function i(t){if(t>2147483647)throw new RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return e.__proto__=a.prototype,e}function a(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return l(t)}return o(t,e,r)}function o(t,e,r){if("string"==typeof t)return function(t,e){"string"==typeof e&&""!==e||(e="utf8");if(!a.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var r=0|f(t,e),n=i(r),o=n.write(t,e);o!==r&&(n=n.slice(0,o));return n}(t,e);if(ArrayBuffer.isView(t))return c(t);if(null==t)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(B(t,ArrayBuffer)||t&&B(t.buffer,ArrayBuffer))return function(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r);return n.__proto__=a.prototype,n}(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return a.from(n,e,r);var o=function(t){if(a.isBuffer(t)){var e=0|u(t.length),r=i(e);return 0===r.length||t.copy(r,0,0,e),r}if(void 0!==t.length)return"number"!=typeof t.length||N(t.length)?i(0):c(t);if("Buffer"===t.type&&Array.isArray(t.data))return c(t.data)}(t);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return a.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function s(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function l(t){return s(t),i(t<0?0:0|u(t))}function c(t){for(var e=t.length<0?0:0|u(t.length),r=i(e),n=0;n<e;n+=1)r[n]=255&t[n];return r}function u(t){if(t>=2147483647)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+2147483647..toString(16)+" bytes");return 0|t}function f(t,e){if(a.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||B(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var i=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return D(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return R(t).length;default:if(i)return n?-1:D(t).length;e=(""+e).toLowerCase(),i=!0}}function h(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return M(this,e,r);case"utf8":case"utf-8":return T(this,e,r);case"ascii":return k(this,e,r);case"latin1":case"binary":return A(this,e,r);case"base64":return w(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function p(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function d(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),N(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=a.from(e,n)),a.isBuffer(e))return 0===e.length?-1:m(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):m(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,r,n,i){var a,o=1,s=t.length,l=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;o=2,s/=2,l/=2,r/=2}function c(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(i){var u=-1;for(a=r;a<s;a++)if(c(t,a)===c(e,-1===u?0:a-u)){if(-1===u&&(u=a),a-u+1===l)return u*o}else-1!==u&&(a-=a-u),u=-1}else for(r+l>s&&(r=s-l),a=r;a>=0;a--){for(var f=!0,h=0;h<l;h++)if(c(t,a+h)!==c(e,h)){f=!1;break}if(f)return a}return-1}function g(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;var a=e.length;n>a/2&&(n=a/2);for(var o=0;o<n;++o){var s=parseInt(e.substr(2*o,2),16);if(N(s))return o;t[r+o]=s}return o}function v(t,e,r,n){return F(D(e,t.length-r),t,r,n)}function y(t,e,r,n){return F(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function x(t,e,r,n){return y(t,e,r,n)}function b(t,e,r,n){return F(R(e),t,r,n)}function _(t,e,r,n){return F(function(t,e){for(var r,n,i,a=[],o=0;o<t.length&&!((e-=2)<0);++o)r=t.charCodeAt(o),n=r>>8,i=r%256,a.push(i),a.push(n);return a}(e,t.length-r),t,r,n)}function w(t,r,n){return 0===r&&n===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(r,n))}function T(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var a,o,s,l,c=t[i],u=null,f=c>239?4:c>223?3:c>191?2:1;if(i+f<=r)switch(f){case 1:c<128&&(u=c);break;case 2:128==(192&(a=t[i+1]))&&(l=(31&c)<<6|63&a)>127&&(u=l);break;case 3:a=t[i+1],o=t[i+2],128==(192&a)&&128==(192&o)&&(l=(15&c)<<12|(63&a)<<6|63&o)>2047&&(l<55296||l>57343)&&(u=l);break;case 4:a=t[i+1],o=t[i+2],s=t[i+3],128==(192&a)&&128==(192&o)&&128==(192&s)&&(l=(15&c)<<18|(63&a)<<12|(63&o)<<6|63&s)>65535&&l<1114112&&(u=l)}null===u?(u=65533,f=1):u>65535&&(u-=65536,n.push(u>>>10&1023|55296),u=56320|1023&u),n.push(u),i+=f}return function(t){var e=t.length;if(e<=4096)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=4096));return r}(n)}r.kMaxLength=2147483647,a.TYPED_ARRAY_SUPPORT=function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()}catch(t){return!1}}(),a.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&a[Symbol.species]===a&&Object.defineProperty(a,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),a.poolSize=8192,a.from=function(t,e,r){return o(t,e,r)},a.prototype.__proto__=Uint8Array.prototype,a.__proto__=Uint8Array,a.alloc=function(t,e,r){return function(t,e,r){return s(t),t<=0?i(t):void 0!==e?"string"==typeof r?i(t).fill(e,r):i(t).fill(e):i(t)}(t,e,r)},a.allocUnsafe=function(t){return l(t)},a.allocUnsafeSlow=function(t){return l(t)},a.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==a.prototype},a.compare=function(t,e){if(B(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),B(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(t)||!a.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},a.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return a.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=a.allocUnsafe(e),i=0;for(r=0;r<t.length;++r){var o=t[r];if(B(o,Uint8Array)&&(o=a.from(o)),!a.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},a.byteLength=f,a.prototype._isBuffer=!0,a.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)p(this,e,e+1);return this},a.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)p(this,e,e+3),p(this,e+1,e+2);return this},a.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)p(this,e,e+7),p(this,e+1,e+6),p(this,e+2,e+5),p(this,e+3,e+4);return this},a.prototype.toString=function(){var t=this.length;return 0===t?"":0===arguments.length?T(this,0,t):h.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(t){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===a.compare(this,t)},a.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"},a.prototype.compare=function(t,e,r,n,i){if(B(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0),l=Math.min(o,s),c=this.slice(n,i),u=t.slice(e,r),f=0;f<l;++f)if(c[f]!==u[f]){o=c[f],s=u[f];break}return o<s?-1:s<o?1:0},a.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},a.prototype.indexOf=function(t,e,r){return d(this,t,e,r,!0)},a.prototype.lastIndexOf=function(t,e,r){return d(this,t,e,r,!1)},a.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var a=!1;;)switch(n){case"hex":return g(this,t,e,r);case"utf8":case"utf-8":return v(this,t,e,r);case"ascii":return y(this,t,e,r);case"latin1":case"binary":return x(this,t,e,r);case"base64":return b(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _(this,t,e,r);default:if(a)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),a=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function k(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function A(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function M(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var i="",a=e;a<r;++a)i+=z(t[a]);return i}function S(t,e,r){for(var n=t.slice(e,r),i="",a=0;a<n.length;a+=2)i+=String.fromCharCode(n[a]+256*n[a+1]);return i}function E(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function L(t,e,r,n,i,o){if(!a.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function C(t,e,r,n,i,a){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function P(t,e,r,i,a){return e=+e,r>>>=0,a||C(t,0,r,4),n.write(t,e,r,i,23,4),r+4}function I(t,e,r,i,a){return e=+e,r>>>=0,a||C(t,0,r,8),n.write(t,e,r,i,52,8),r+8}a.prototype.slice=function(t,e){var r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);var n=this.subarray(t,e);return n.__proto__=a.prototype,n},a.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||E(t,e,this.length);for(var n=this[t],i=1,a=0;++a<e&&(i*=256);)n+=this[t+a]*i;return n},a.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||E(t,e,this.length);for(var n=this[t+--e],i=1;e>0&&(i*=256);)n+=this[t+--e]*i;return n},a.prototype.readUInt8=function(t,e){return t>>>=0,e||E(t,1,this.length),this[t]},a.prototype.readUInt16LE=function(t,e){return t>>>=0,e||E(t,2,this.length),this[t]|this[t+1]<<8},a.prototype.readUInt16BE=function(t,e){return t>>>=0,e||E(t,2,this.length),this[t]<<8|this[t+1]},a.prototype.readUInt32LE=function(t,e){return t>>>=0,e||E(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},a.prototype.readUInt32BE=function(t,e){return t>>>=0,e||E(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},a.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||E(t,e,this.length);for(var n=this[t],i=1,a=0;++a<e&&(i*=256);)n+=this[t+a]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*e)),n},a.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||E(t,e,this.length);for(var n=e,i=1,a=this[t+--n];n>0&&(i*=256);)a+=this[t+--n]*i;return a>=(i*=128)&&(a-=Math.pow(2,8*e)),a},a.prototype.readInt8=function(t,e){return t>>>=0,e||E(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},a.prototype.readInt16LE=function(t,e){t>>>=0,e||E(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt16BE=function(t,e){t>>>=0,e||E(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt32LE=function(t,e){return t>>>=0,e||E(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},a.prototype.readInt32BE=function(t,e){return t>>>=0,e||E(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},a.prototype.readFloatLE=function(t,e){return t>>>=0,e||E(t,4,this.length),n.read(this,t,!0,23,4)},a.prototype.readFloatBE=function(t,e){return t>>>=0,e||E(t,4,this.length),n.read(this,t,!1,23,4)},a.prototype.readDoubleLE=function(t,e){return t>>>=0,e||E(t,8,this.length),n.read(this,t,!0,52,8)},a.prototype.readDoubleBE=function(t,e){return t>>>=0,e||E(t,8,this.length),n.read(this,t,!1,52,8)},a.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e>>>=0,r>>>=0,n)||L(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,a=0;for(this[e]=255&t;++a<r&&(i*=256);)this[e+a]=t/i&255;return e+r},a.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e>>>=0,r>>>=0,n)||L(this,t,e,r,Math.pow(2,8*r)-1,0);var i=r-1,a=1;for(this[e+i]=255&t;--i>=0&&(a*=256);)this[e+i]=t/a&255;return e+r},a.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,1,255,0),this[e]=255&t,e+1},a.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},a.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},a.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},a.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},a.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var i=Math.pow(2,8*r-1);L(this,t,e,r,i-1,-i)}var a=0,o=1,s=0;for(this[e]=255&t;++a<r&&(o*=256);)t<0&&0===s&&0!==this[e+a-1]&&(s=1),this[e+a]=(t/o>>0)-s&255;return e+r},a.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var i=Math.pow(2,8*r-1);L(this,t,e,r,i-1,-i)}var a=r-1,o=1,s=0;for(this[e+a]=255&t;--a>=0&&(o*=256);)t<0&&0===s&&0!==this[e+a+1]&&(s=1),this[e+a]=(t/o>>0)-s&255;return e+r},a.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},a.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},a.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},a.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},a.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||L(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},a.prototype.writeFloatLE=function(t,e,r){return P(this,t,e,!0,r)},a.prototype.writeFloatBE=function(t,e,r){return P(this,t,e,!1,r)},a.prototype.writeDoubleLE=function(t,e,r){return I(this,t,e,!0,r)},a.prototype.writeDoubleBE=function(t,e,r){return I(this,t,e,!1,r)},a.prototype.copy=function(t,e,r,n){if(!a.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var i=n-r;if(this===t&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(e,r,n);else if(this===t&&r<e&&e<n)for(var o=i-1;o>=0;--o)t[o+e]=this[o+r];else Uint8Array.prototype.set.call(t,this.subarray(r,n),e);return i},a.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!a.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){var i=t.charCodeAt(0);("utf8"===n&&i<128||"latin1"===n)&&(t=i)}}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{var s=a.isBuffer(t)?t:a.from(t,n),l=s.length;if(0===l)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<r-e;++o)this[o+e]=s[o%l]}return this};var O=/[^+/0-9A-Za-z-_]/g;function z(t){return t<16?"0"+t.toString(16):t.toString(16)}function D(t,e){var r;e=e||1/0;for(var n=t.length,i=null,a=[],o=0;o<n;++o){if((r=t.charCodeAt(o))>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&a.push(239,191,189);continue}if(o+1===n){(e-=3)>-1&&a.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&a.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&a.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;a.push(r)}else if(r<2048){if((e-=2)<0)break;a.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;a.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;a.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return a}function R(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(O,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function F(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function B(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function N(t){return t!=t}}).call(this)}).call(this,t("buffer").Buffer)},{"base64-js":1,buffer:3,ieee754:4}],4:[function(t,e,r){r.read=function(t,e,r,n,i){var a,o,s=8*i-n-1,l=(1<<s)-1,c=l>>1,u=-7,f=r?i-1:0,h=r?-1:1,p=t[e+f];for(f+=h,a=p&(1<<-u)-1,p>>=-u,u+=s;u>0;a=256*a+t[e+f],f+=h,u-=8);for(o=a&(1<<-u)-1,a>>=-u,u+=n;u>0;o=256*o+t[e+f],f+=h,u-=8);if(0===a)a=1-c;else{if(a===l)return o?NaN:1/0*(p?-1:1);o+=Math.pow(2,n),a-=c}return(p?-1:1)*o*Math.pow(2,a-n)},r.write=function(t,e,r,n,i,a){var o,s,l,c=8*a-i-1,u=(1<<c)-1,f=u>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:a-1,d=n?1:-1,m=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,o=u):(o=Math.floor(Math.log(e)/Math.LN2),e*(l=Math.pow(2,-o))<1&&(o--,l*=2),(e+=o+f>=1?h/l:h*Math.pow(2,1-f))*l>=2&&(o++,l/=2),o+f>=u?(s=0,o=u):o+f>=1?(s=(e*l-1)*Math.pow(2,i),o+=f):(s=e*Math.pow(2,f-1)*Math.pow(2,i),o=0));i>=8;t[r+p]=255&s,p+=d,s/=256,i-=8);for(o=o<<i|s,c+=i;c>0;t[r+p]=255&o,p+=d,o/=256,c-=8);t[r+p-d]|=128*m}},{}],5:[function(t,e,r){var n,i,a=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function l(t){if(n===setTimeout)return setTimeout(t,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(t){n=o}try{i="function"==typeof clearTimeout?clearTimeout:s}catch(t){i=s}}();var c,u=[],f=!1,h=-1;function p(){f&&c&&(f=!1,c.length?u=c.concat(u):h=-1,u.length&&d())}function d(){if(!f){var t=l(p);f=!0;for(var e=u.length;e;){for(c=u,u=[];++h<e;)c&&c[h].run();h=-1,e=u.length}c=null,f=!1,function(t){if(i===clearTimeout)return clearTimeout(t);if((i===s||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(t);try{i(t)}catch(e){try{return i.call(null,t)}catch(e){return i.call(this,t)}}}(t)}}function m(t,e){this.fun=t,this.array=e}function g(){}a.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];u.push(new m(t,e)),1!==u.length||f||l(d)},m.prototype.run=function(){this.fun.apply(null,this.array)},a.title="browser",a.browser=!0,a.env={},a.argv=[],a.version="",a.versions={},a.on=g,a.addListener=g,a.once=g,a.off=g,a.removeListener=g,a.removeAllListeners=g,a.emit=g,a.prependListener=g,a.prependOnceListener=g,a.listeners=function(t){return[]},a.binding=function(t){throw new Error("process.binding is not supported")},a.cwd=function(){return"/"},a.chdir=function(t){throw new Error("process.chdir is not supported")},a.umask=function(){return 0}},{}],6:[function(t,e,r){e.exports={alpha_shape:t("alpha-shape"),convex_hull:t("convex-hull"),delaunay_triangulate:t("delaunay-triangulate"),gl_cone3d:t("gl-cone3d"),gl_error3d:t("gl-error3d"),gl_heatmap2d:t("gl-heatmap2d"),gl_line3d:t("gl-line3d"),gl_mesh3d:t("gl-mesh3d"),gl_plot2d:t("gl-plot2d"),gl_plot3d:t("gl-plot3d"),gl_pointcloud2d:t("gl-pointcloud2d"),gl_scatter3d:t("gl-scatter3d"),gl_select_box:t("gl-select-box"),gl_spikes2d:t("gl-spikes2d"),gl_streamtube3d:t("gl-streamtube3d"),gl_surface3d:t("gl-surface3d"),ndarray:t("ndarray"),ndarray_linear_interpolate:t("ndarray-linear-interpolate")}},{"alpha-shape":12,"convex-hull":58,"delaunay-triangulate":63,"gl-cone3d":79,"gl-error3d":84,"gl-heatmap2d":88,"gl-line3d":91,"gl-mesh3d":112,"gl-plot2d":118,"gl-plot3d":121,"gl-pointcloud2d":123,"gl-scatter3d":128,"gl-select-box":130,"gl-spikes2d":139,"gl-streamtube3d":143,"gl-surface3d":145,ndarray:259,"ndarray-linear-interpolate":253}],7:[function(t,e,r){"use strict";e.exports=function(t){var e=(t=t||{}).eye||[0,0,1],r=t.center||[0,0,0],s=t.up||[0,1,0],l=t.distanceLimits||[0,1/0],c=t.mode||"turntable",u=n(),f=i(),h=a();return u.setDistanceLimits(l[0],l[1]),u.lookAt(0,e,r,s),f.setDistanceLimits(l[0],l[1]),f.lookAt(0,e,r,s),h.setDistanceLimits(l[0],l[1]),h.lookAt(0,e,r,s),new o({turntable:u,orbit:f,matrix:h},c)};var n=t("turntable-camera-controller"),i=t("orbit-camera-controller"),a=t("matrix-camera-controller");function o(t,e){this._controllerNames=Object.keys(t),this._controllerList=this._controllerNames.map((function(e){return t[e]})),this._mode=e,this._active=t[e],this._active||(this._mode="turntable",this._active=t.turntable),this.modes=this._controllerNames,this.computedMatrix=this._active.computedMatrix,this.computedEye=this._active.computedEye,this.computedUp=this._active.computedUp,this.computedCenter=this._active.computedCenter,this.computedRadius=this._active.computedRadius}var s=o.prototype;s.flush=function(t){for(var e=this._controllerList,r=0;r<e.length;++r)e[r].flush(t)},s.idle=function(t){for(var e=this._controllerList,r=0;r<e.length;++r)e[r].idle(t)},s.lookAt=function(t,e,r,n){for(var i=this._controllerList,a=0;a<i.length;++a)i[a].lookAt(t,e,r,n)},s.rotate=function(t,e,r,n){for(var i=this._controllerList,a=0;a<i.length;++a)i[a].rotate(t,e,r,n)},s.pan=function(t,e,r,n){for(var i=this._controllerList,a=0;a<i.length;++a)i[a].pan(t,e,r,n)},s.translate=function(t,e,r,n){for(var i=this._controllerList,a=0;a<i.length;++a)i[a].translate(t,e,r,n)},s.setMatrix=function(t,e){for(var r=this._controllerList,n=0;n<r.length;++n)r[n].setMatrix(t,e)},s.setDistanceLimits=function(t,e){for(var r=this._controllerList,n=0;n<r.length;++n)r[n].setDistanceLimits(t,e)},s.setDistance=function(t,e){for(var r=this._controllerList,n=0;n<r.length;++n)r[n].setDistance(t,e)},s.recalcMatrix=function(t){this._active.recalcMatrix(t)},s.getDistance=function(t){return this._active.getDistance(t)},s.getDistanceLimits=function(t){return this._active.getDistanceLimits(t)},s.lastT=function(){return this._active.lastT()},s.setMode=function(t){if(t!==this._mode){var e=this._controllerNames.indexOf(t);if(!(e<0)){var r=this._active,n=this._controllerList[e],i=Math.max(r.lastT(),n.lastT());r.recalcMatrix(i),n.setMatrix(i,r.computedMatrix),this._active=n,this._mode=t,this.computedMatrix=this._active.computedMatrix,this.computedEye=this._active.computedEye,this.computedUp=this._active.computedUp,this.computedCenter=this._active.computedCenter,this.computedRadius=this._active.computedRadius}}},s.getMode=function(){return this._mode}},{"matrix-camera-controller":245,"orbit-camera-controller":263,"turntable-camera-controller":305}],8:[function(t,e,r){"use strict";var n="undefined"==typeof WeakMap?t("weak-map"):WeakMap,i=t("gl-buffer"),a=t("gl-vao"),o=new n;e.exports=function(t){var e=o.get(t),r=e&&(e._triangleBuffer.handle||e._triangleBuffer.buffer);if(!r||!t.isBuffer(r)){var n=i(t,new Float32Array([-1,-1,-1,4,4,-1]));(e=a(t,[{buffer:n,type:t.FLOAT,size:2}]))._triangleBuffer=n,o.set(t,e)}e.bind(),t.drawArrays(t.TRIANGLES,0,3),e.unbind()}},{"gl-buffer":78,"gl-vao":150,"weak-map":313}],9:[function(t,e,r){var n=t("pad-left");e.exports=function(t,e,r){e="number"==typeof e?e:1,r=r||": ";var i=t.split(/\r?\n/),a=String(i.length+e-1).length;return i.map((function(t,i){var o=i+e,s=String(o).length;return n(o,a-s)+r+t})).join("\n")}},{"pad-left":264}],10:[function(t,e,r){"use strict";e.exports=function(t){var e=t.length;if(0===e)return[];if(1===e)return[0];for(var r=t[0].length,n=[t[0]],a=[0],o=1;o<e;++o)if(n.push(t[o]),i(n,r)){if(a.push(o),a.length===r+1)return a}else n.pop();return a};var n=t("robust-orientation");function i(t,e){for(var r=new Array(e+1),i=0;i<t.length;++i)r[i]=t[i];for(i=0;i<=t.length;++i){for(var a=t.length;a<=e;++a){for(var o=new Array(e),s=0;s<e;++s)o[s]=Math.pow(a+1-i,s);r[a]=o}if(n.apply(void 0,r))return!0}return!1}},{"robust-orientation":284}],11:[function(t,e,r){"use strict";e.exports=function(t,e){return n(e).filter((function(r){for(var n=new Array(r.length),a=0;a<r.length;++a)n[a]=e[r[a]];return i(n)*t<1}))};var n=t("delaunay-triangulate"),i=t("circumradius")},{circumradius:49,"delaunay-triangulate":63}],12:[function(t,e,r){e.exports=function(t,e){return i(n(t,e))};var n=t("alpha-complex"),i=t("simplicial-complex-boundary")},{"alpha-complex":11,"simplicial-complex-boundary":290}],13:[function(t,e,r){e.exports=function(t){return atob(t)}},{}],14:[function(t,e,r){"use strict";e.exports=function(t,e){for(var r=e.length,a=new Array(r+1),o=0;o<r;++o){for(var s=new Array(r+1),l=0;l<=r;++l)s[l]=t[l][o];a[o]=s}a[r]=new Array(r+1);for(o=0;o<=r;++o)a[r][o]=1;var c=new Array(r+1);for(o=0;o<r;++o)c[o]=e[o];c[r]=1;var u=n(a,c),f=i(u[r+1]);0===f&&(f=1);var h=new Array(r+1);for(o=0;o<=r;++o)h[o]=i(u[o])/f;return h};var n=t("robust-linear-solve");function i(t){for(var e=0,r=0;r<t.length;++r)e+=t[r];return e}},{"robust-linear-solve":283}],15:[function(t,e,r){"use strict";var n=t("./lib/rationalize");e.exports=function(t,e){return n(t[0].mul(e[1]).add(e[0].mul(t[1])),t[1].mul(e[1]))}},{"./lib/rationalize":25}],16:[function(t,e,r){"use strict";e.exports=function(t,e){return t[0].mul(e[1]).cmp(e[0].mul(t[1]))}},{}],17:[function(t,e,r){"use strict";var n=t("./lib/rationalize");e.exports=function(t,e){return n(t[0].mul(e[1]),t[1].mul(e[0]))}},{"./lib/rationalize":25}],18:[function(t,e,r){"use strict";var n=t("./is-rat"),i=t("./lib/is-bn"),a=t("./lib/num-to-bn"),o=t("./lib/str-to-bn"),s=t("./lib/rationalize"),l=t("./div");e.exports=function t(e,r){if(n(e))return r?l(e,t(r)):[e[0].clone(),e[1].clone()];var c,u,f=0;if(i(e))c=e.clone();else if("string"==typeof e)c=o(e);else{if(0===e)return[a(0),a(1)];if(e===Math.floor(e))c=a(e);else{for(;e!==Math.floor(e);)e*=Math.pow(2,256),f-=256;c=a(e)}}if(n(r))c.mul(r[1]),u=r[0].clone();else if(i(r))u=r.clone();else if("string"==typeof r)u=o(r);else if(r)if(r===Math.floor(r))u=a(r);else{for(;r!==Math.floor(r);)r*=Math.pow(2,256),f+=256;u=a(r)}else u=a(1);f>0?c=c.ushln(f):f<0&&(u=u.ushln(-f));return s(c,u)}},{"./div":17,"./is-rat":19,"./lib/is-bn":23,"./lib/num-to-bn":24,"./lib/rationalize":25,"./lib/str-to-bn":26}],19:[function(t,e,r){"use strict";var n=t("./lib/is-bn");e.exports=function(t){return Array.isArray(t)&&2===t.length&&n(t[0])&&n(t[1])}},{"./lib/is-bn":23}],20:[function(t,e,r){"use strict";var n=t("bn.js");e.exports=function(t){return t.cmp(new n(0))}},{"bn.js":33}],21:[function(t,e,r){"use strict";var n=t("./bn-sign");e.exports=function(t){var e=t.length,r=t.words,i=0;if(1===e)i=r[0];else if(2===e)i=r[0]+67108864*r[1];else for(var a=0;a<e;a++){var o=r[a];i+=o*Math.pow(67108864,a)}return n(t)*i}},{"./bn-sign":20}],22:[function(t,e,r){"use strict";var n=t("double-bits"),i=t("bit-twiddle").countTrailingZeros;e.exports=function(t){var e=i(n.lo(t));if(e<32)return e;var r=i(n.hi(t));if(r>20)return 52;return r+32}},{"bit-twiddle":32,"double-bits":64}],23:[function(t,e,r){"use strict";t("bn.js");e.exports=function(t){return t&&"object"==typeof t&&Boolean(t.words)}},{"bn.js":33}],24:[function(t,e,r){"use strict";var n=t("bn.js"),i=t("double-bits");e.exports=function(t){var e=i.exponent(t);return e<52?new n(t):new n(t*Math.pow(2,52-e)).ushln(e-52)}},{"bn.js":33,"double-bits":64}],25:[function(t,e,r){"use strict";var n=t("./num-to-bn"),i=t("./bn-sign");e.exports=function(t,e){var r=i(t),a=i(e);if(0===r)return[n(0),n(1)];if(0===a)return[n(0),n(0)];a<0&&(t=t.neg(),e=e.neg());var o=t.gcd(e);if(o.cmpn(1))return[t.div(o),e.div(o)];return[t,e]}},{"./bn-sign":20,"./num-to-bn":24}],26:[function(t,e,r){"use strict";var n=t("bn.js");e.exports=function(t){return new n(t)}},{"bn.js":33}],27:[function(t,e,r){"use strict";var n=t("./lib/rationalize");e.exports=function(t,e){return n(t[0].mul(e[0]),t[1].mul(e[1]))}},{"./lib/rationalize":25}],28:[function(t,e,r){"use strict";var n=t("./lib/bn-sign");e.exports=function(t){return n(t[0])*n(t[1])}},{"./lib/bn-sign":20}],29:[function(t,e,r){"use strict";var n=t("./lib/rationalize");e.exports=function(t,e){return n(t[0].mul(e[1]).sub(t[1].mul(e[0])),t[1].mul(e[1]))}},{"./lib/rationalize":25}],30:[function(t,e,r){"use strict";var n=t("./lib/bn-to-num"),i=t("./lib/ctz");e.exports=function(t){var e=t[0],r=t[1];if(0===e.cmpn(0))return 0;var a=e.abs().divmod(r.abs()),o=a.div,s=n(o),l=a.mod,c=e.negative!==r.negative?-1:1;if(0===l.cmpn(0))return c*s;if(s){var u=i(s)+4,f=n(l.ushln(u).divRound(r));return c*(s+f*Math.pow(2,-u))}var h=r.bitLength()-l.bitLength()+53;f=n(l.ushln(h).divRound(r));return h<1023?c*f*Math.pow(2,-h):(f*=Math.pow(2,-1023),c*f*Math.pow(2,1023-h))}},{"./lib/bn-to-num":21,"./lib/ctz":22}],31:[function(t,e,r){"use strict";function n(t,e,r,n,i){for(var a=i+1;n<=i;){var o=n+i>>>1,s=t[o];(void 0!==r?r(s,e):s-e)>=0?(a=o,i=o-1):n=o+1}return a}function i(t,e,r,n,i){for(var a=i+1;n<=i;){var o=n+i>>>1,s=t[o];(void 0!==r?r(s,e):s-e)>0?(a=o,i=o-1):n=o+1}return a}function a(t,e,r,n,i){for(var a=n-1;n<=i;){var o=n+i>>>1,s=t[o];(void 0!==r?r(s,e):s-e)<0?(a=o,n=o+1):i=o-1}return a}function o(t,e,r,n,i){for(var a=n-1;n<=i;){var o=n+i>>>1,s=t[o];(void 0!==r?r(s,e):s-e)<=0?(a=o,n=o+1):i=o-1}return a}function s(t,e,r,n,i){for(;n<=i;){var a=n+i>>>1,o=t[a],s=void 0!==r?r(o,e):o-e;if(0===s)return a;s<=0?n=a+1:i=a-1}return-1}function l(t,e,r,n,i,a){return"function"==typeof r?a(t,e,r,void 0===n?0:0|n,void 0===i?t.length-1:0|i):a(t,e,void 0,void 0===r?0:0|r,void 0===n?t.length-1:0|n)}e.exports={ge:function(t,e,r,i,a){return l(t,e,r,i,a,n)},gt:function(t,e,r,n,a){return l(t,e,r,n,a,i)},lt:function(t,e,r,n,i){return l(t,e,r,n,i,a)},le:function(t,e,r,n,i){return l(t,e,r,n,i,o)},eq:function(t,e,r,n,i){return l(t,e,r,n,i,s)}}},{}],32:[function(t,e,r){"use strict";function n(t){var e=32;return(t&=-t)&&e--,65535&t&&(e-=16),16711935&t&&(e-=8),252645135&t&&(e-=4),858993459&t&&(e-=2),1431655765&t&&(e-=1),e}r.INT_BITS=32,r.INT_MAX=2147483647,r.INT_MIN=-1<<31,r.sign=function(t){return(t>0)-(t<0)},r.abs=function(t){var e=t>>31;return(t^e)-e},r.min=function(t,e){return e^(t^e)&-(t<e)},r.max=function(t,e){return t^(t^e)&-(t<e)},r.isPow2=function(t){return!(t&t-1||!t)},r.log2=function(t){var e,r;return e=(t>65535)<<4,e|=r=((t>>>=e)>255)<<3,e|=r=((t>>>=r)>15)<<2,(e|=r=((t>>>=r)>3)<<1)|(t>>>=r)>>1},r.log10=function(t){return t>=1e9?9:t>=1e8?8:t>=1e7?7:t>=1e6?6:t>=1e5?5:t>=1e4?4:t>=1e3?3:t>=100?2:t>=10?1:0},r.popCount=function(t){return 16843009*((t=(858993459&(t-=t>>>1&1431655765))+(t>>>2&858993459))+(t>>>4)&252645135)>>>24},r.countTrailingZeros=n,r.nextPow2=function(t){return t+=0===t,--t,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,(t|=t>>>16)+1},r.prevPow2=function(t){return t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,(t|=t>>>16)-(t>>>1)},r.parity=function(t){return t^=t>>>16,t^=t>>>8,t^=t>>>4,27030>>>(t&=15)&1};var i=new Array(256);!function(t){for(var e=0;e<256;++e){var r=e,n=e,i=7;for(r>>>=1;r;r>>>=1)n<<=1,n|=1&r,--i;t[e]=n<<i&255}}(i),r.reverse=function(t){return i[255&t]<<24|i[t>>>8&255]<<16|i[t>>>16&255]<<8|i[t>>>24&255]},r.interleave2=function(t,e){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t&=65535)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e&=65535)|e<<8))|e<<4))|e<<2))|e<<1))<<1},r.deinterleave2=function(t,e){return(t=65535&((t=16711935&((t=252645135&((t=858993459&((t=t>>>e&1431655765)|t>>>1))|t>>>2))|t>>>4))|t>>>16))<<16>>16},r.interleave3=function(t,e,r){return t=1227133513&((t=3272356035&((t=251719695&((t=4278190335&((t&=1023)|t<<16))|t<<8))|t<<4))|t<<2),(t|=(e=1227133513&((e=3272356035&((e=251719695&((e=4278190335&((e&=1023)|e<<16))|e<<8))|e<<4))|e<<2))<<1)|(r=1227133513&((r=3272356035&((r=251719695&((r=4278190335&((r&=1023)|r<<16))|r<<8))|r<<4))|r<<2))<<2},r.deinterleave3=function(t,e){return(t=1023&((t=4278190335&((t=251719695&((t=3272356035&((t=t>>>e&1227133513)|t>>>2))|t>>>4))|t>>>8))|t>>>16))<<22>>22},r.nextCombination=function(t){var e=t|t-1;return e+1|(~e&-~e)-1>>>n(t)+1}},{}],33:[function(t,e,r){!function(e,r){"use strict";function n(t,e){if(!t)throw new Error(e||"Assertion failed")}function i(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function a(t,e,r){if(a.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var o;"object"==typeof e?e.exports=a:r.BN=a,a.BN=a,a.wordSize=26;try{o="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:t("buffer").Buffer}catch(t){}function s(t,e){var r=t.charCodeAt(e);return r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:r-48&15}function l(t,e,r){var n=s(t,r);return r-1>=e&&(n|=s(t,r-1)<<4),n}function c(t,e,r,n){for(var i=0,a=Math.min(t.length,r),o=e;o<a;o++){var s=t.charCodeAt(o)-48;i*=n,i+=s>=49?s-49+10:s>=17?s-17+10:s}return i}a.isBN=function(t){return t instanceof a||null!==t&&"object"==typeof t&&t.constructor.wordSize===a.wordSize&&Array.isArray(t.words)},a.max=function(t,e){return t.cmp(e)>0?t:e},a.min=function(t,e){return t.cmp(e)<0?t:e},a.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),n(e===(0|e)&&e>=2&&e<=36);var i=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(i++,this.negative=1),i<t.length&&(16===e?this._parseHex(t,i,r):(this._parseBase(t,e,i),"le"===r&&this._initArray(this.toArray(),e,r)))},a.prototype._initNumber=function(t,e,r){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(n(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},a.prototype._initArray=function(t,e,r){if(n("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var a,o,s=0;if("be"===r)for(i=t.length-1,a=0;i>=0;i-=3)o=t[i]|t[i-1]<<8|t[i-2]<<16,this.words[a]|=o<<s&67108863,this.words[a+1]=o>>>26-s&67108863,(s+=24)>=26&&(s-=26,a++);else if("le"===r)for(i=0,a=0;i<t.length;i+=3)o=t[i]|t[i+1]<<8|t[i+2]<<16,this.words[a]|=o<<s&67108863,this.words[a+1]=o>>>26-s&67108863,(s+=24)>=26&&(s-=26,a++);return this.strip()},a.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var i,a=0,o=0;if("be"===r)for(n=t.length-1;n>=e;n-=2)i=l(t,e,n)<<a,this.words[o]|=67108863&i,a>=18?(a-=18,o+=1,this.words[o]|=i>>>26):a+=8;else for(n=(t.length-e)%2==0?e+1:e;n<t.length;n+=2)i=l(t,e,n)<<a,this.words[o]|=67108863&i,a>=18?(a-=18,o+=1,this.words[o]|=i>>>26):a+=8;this.strip()},a.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var n=0,i=1;i<=67108863;i*=e)n++;n--,i=i/e|0;for(var a=t.length-r,o=a%n,s=Math.min(a,a-o)+r,l=0,u=r;u<s;u+=n)l=c(t,u,u+n,e),this.imuln(i),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l);if(0!==o){var f=1;for(l=c(t,u,t.length,e),u=0;u<o;u++)f*=e;this.imuln(f),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l)}this.strip()},a.prototype.copy=function(t){t.words=new Array(this.length);for(var e=0;e<this.length;e++)t.words[e]=this.words[e];t.length=this.length,t.negative=this.negative,t.red=this.red},a.prototype.clone=function(){var t=new a(null);return this.copy(t),t},a.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},a.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},a.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},a.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var u=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],f=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],h=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function p(t,e,r){r.negative=e.negative^t.negative;var n=t.length+e.length|0;r.length=n,n=n-1|0;var i=0|t.words[0],a=0|e.words[0],o=i*a,s=67108863&o,l=o/67108864|0;r.words[0]=s;for(var c=1;c<n;c++){for(var u=l>>>26,f=67108863&l,h=Math.min(c,e.length-1),p=Math.max(0,c-t.length+1);p<=h;p++){var d=c-p|0;u+=(o=(i=0|t.words[d])*(a=0|e.words[p])+f)/67108864|0,f=67108863&o}r.words[c]=0|f,l=0|u}return 0!==l?r.words[c]=0|l:r.length--,r.strip()}a.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var i=0,a=0,o=0;o<this.length;o++){var s=this.words[o],l=(16777215&(s<<i|a)).toString(16);r=0!==(a=s>>>24-i&16777215)||o!==this.length-1?u[6-l.length]+l+r:l+r,(i+=2)>=26&&(i-=26,o--)}for(0!==a&&(r=a.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var c=f[t],p=h[t];r="";var d=this.clone();for(d.negative=0;!d.isZero();){var m=d.modn(p).toString(t);r=(d=d.idivn(p)).isZero()?m+r:u[c-m.length]+m+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(!1,"Base should be between 2 and 36")},a.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},a.prototype.toJSON=function(){return this.toString(16)},a.prototype.toBuffer=function(t,e){return n(void 0!==o),this.toArrayLike(o,t,e)},a.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},a.prototype.toArrayLike=function(t,e,r){var i=this.byteLength(),a=r||Math.max(1,i);n(i<=a,"byte array longer than desired length"),n(a>0,"Requested array length <= 0"),this.strip();var o,s,l="le"===e,c=new t(a),u=this.clone();if(l){for(s=0;!u.isZero();s++)o=u.andln(255),u.iushrn(8),c[s]=o;for(;s<a;s++)c[s]=0}else{for(s=0;s<a-i;s++)c[s]=0;for(s=0;!u.isZero();s++)o=u.andln(255),u.iushrn(8),c[a-s-1]=o}return c},Math.clz32?a.prototype._countBits=function(t){return 32-Math.clz32(t)}:a.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},a.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 0==(8191&e)&&(r+=13,e>>>=13),0==(127&e)&&(r+=7,e>>>=7),0==(15&e)&&(r+=4,e>>>=4),0==(3&e)&&(r+=2,e>>>=2),0==(1&e)&&r++,r},a.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},a.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var r=this._zeroBits(this.words[e]);if(t+=r,26!==r)break}return t},a.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},a.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},a.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},a.prototype.isNeg=function(){return 0!==this.negative},a.prototype.neg=function(){return this.clone().ineg()},a.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},a.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this.strip()},a.prototype.ior=function(t){return n(0==(this.negative|t.negative)),this.iuor(t)},a.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},a.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},a.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var r=0;r<e.length;r++)this.words[r]=this.words[r]&t.words[r];return this.length=e.length,this.strip()},a.prototype.iand=function(t){return n(0==(this.negative|t.negative)),this.iuand(t)},a.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},a.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},a.prototype.iuxor=function(t){var e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var n=0;n<r.length;n++)this.words[n]=e.words[n]^r.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this.strip()},a.prototype.ixor=function(t){return n(0==(this.negative|t.negative)),this.iuxor(t)},a.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},a.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},a.prototype.inotn=function(t){n("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var i=0;i<e;i++)this.words[i]=67108863&~this.words[i];return r>0&&(this.words[i]=~this.words[i]&67108863>>26-r),this.strip()},a.prototype.notn=function(t){return this.clone().inotn(t)},a.prototype.setn=function(t,e){n("number"==typeof t&&t>=0);var r=t/26|0,i=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<i:this.words[r]&~(1<<i),this.strip()},a.prototype.iadd=function(t){var e,r,n;if(0!==this.negative&&0===t.negative)return this.negative=0,e=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,e=this.isub(t),t.negative=1,e._normSign();this.length>t.length?(r=this,n=t):(r=t,n=this);for(var i=0,a=0;a<n.length;a++)e=(0|r.words[a])+(0|n.words[a])+i,this.words[a]=67108863&e,i=e>>>26;for(;0!==i&&a<r.length;a++)e=(0|r.words[a])+i,this.words[a]=67108863&e,i=e>>>26;if(this.length=r.length,0!==i)this.words[this.length]=i,this.length++;else if(r!==this)for(;a<r.length;a++)this.words[a]=r.words[a];return this},a.prototype.add=function(t){var e;return 0!==t.negative&&0===this.negative?(t.negative=0,e=this.sub(t),t.negative^=1,e):0===t.negative&&0!==this.negative?(this.negative=0,e=t.sub(this),this.negative=1,e):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},a.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,n,i=this.cmp(t);if(0===i)return this.negative=0,this.length=1,this.words[0]=0,this;i>0?(r=this,n=t):(r=t,n=this);for(var a=0,o=0;o<n.length;o++)a=(e=(0|r.words[o])-(0|n.words[o])+a)>>26,this.words[o]=67108863&e;for(;0!==a&&o<r.length;o++)a=(e=(0|r.words[o])+a)>>26,this.words[o]=67108863&e;if(0===a&&o<r.length&&r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this.length=Math.max(this.length,o),r!==this&&(this.negative=1),this.strip()},a.prototype.sub=function(t){return this.clone().isub(t)};var d=function(t,e,r){var n,i,a,o=t.words,s=e.words,l=r.words,c=0,u=0|o[0],f=8191&u,h=u>>>13,p=0|o[1],d=8191&p,m=p>>>13,g=0|o[2],v=8191&g,y=g>>>13,x=0|o[3],b=8191&x,_=x>>>13,w=0|o[4],T=8191&w,k=w>>>13,A=0|o[5],M=8191&A,S=A>>>13,E=0|o[6],L=8191&E,C=E>>>13,P=0|o[7],I=8191&P,O=P>>>13,z=0|o[8],D=8191&z,R=z>>>13,F=0|o[9],B=8191&F,N=F>>>13,j=0|s[0],U=8191&j,V=j>>>13,H=0|s[1],q=8191&H,G=H>>>13,Y=0|s[2],W=8191&Y,X=Y>>>13,Z=0|s[3],J=8191&Z,K=Z>>>13,Q=0|s[4],$=8191&Q,tt=Q>>>13,et=0|s[5],rt=8191&et,nt=et>>>13,it=0|s[6],at=8191&it,ot=it>>>13,st=0|s[7],lt=8191&st,ct=st>>>13,ut=0|s[8],ft=8191&ut,ht=ut>>>13,pt=0|s[9],dt=8191&pt,mt=pt>>>13;r.negative=t.negative^e.negative,r.length=19;var gt=(c+(n=Math.imul(f,U))|0)+((8191&(i=(i=Math.imul(f,V))+Math.imul(h,U)|0))<<13)|0;c=((a=Math.imul(h,V))+(i>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(d,U),i=(i=Math.imul(d,V))+Math.imul(m,U)|0,a=Math.imul(m,V);var vt=(c+(n=n+Math.imul(f,q)|0)|0)+((8191&(i=(i=i+Math.imul(f,G)|0)+Math.imul(h,q)|0))<<13)|0;c=((a=a+Math.imul(h,G)|0)+(i>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(v,U),i=(i=Math.imul(v,V))+Math.imul(y,U)|0,a=Math.imul(y,V),n=n+Math.imul(d,q)|0,i=(i=i+Math.imul(d,G)|0)+Math.imul(m,q)|0,a=a+Math.imul(m,G)|0;var yt=(c+(n=n+Math.imul(f,W)|0)|0)+((8191&(i=(i=i+Math.imul(f,X)|0)+Math.imul(h,W)|0))<<13)|0;c=((a=a+Math.imul(h,X)|0)+(i>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(b,U),i=(i=Math.imul(b,V))+Math.imul(_,U)|0,a=Math.imul(_,V),n=n+Math.imul(v,q)|0,i=(i=i+Math.imul(v,G)|0)+Math.imul(y,q)|0,a=a+Math.imul(y,G)|0,n=n+Math.imul(d,W)|0,i=(i=i+Math.imul(d,X)|0)+Math.imul(m,W)|0,a=a+Math.imul(m,X)|0;var xt=(c+(n=n+Math.imul(f,J)|0)|0)+((8191&(i=(i=i+Math.imul(f,K)|0)+Math.imul(h,J)|0))<<13)|0;c=((a=a+Math.imul(h,K)|0)+(i>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(T,U),i=(i=Math.imul(T,V))+Math.imul(k,U)|0,a=Math.imul(k,V),n=n+Math.imul(b,q)|0,i=(i=i+Math.imul(b,G)|0)+Math.imul(_,q)|0,a=a+Math.imul(_,G)|0,n=n+Math.imul(v,W)|0,i=(i=i+Math.imul(v,X)|0)+Math.imul(y,W)|0,a=a+Math.imul(y,X)|0,n=n+Math.imul(d,J)|0,i=(i=i+Math.imul(d,K)|0)+Math.imul(m,J)|0,a=a+Math.imul(m,K)|0;var bt=(c+(n=n+Math.imul(f,$)|0)|0)+((8191&(i=(i=i+Math.imul(f,tt)|0)+Math.imul(h,$)|0))<<13)|0;c=((a=a+Math.imul(h,tt)|0)+(i>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(M,U),i=(i=Math.imul(M,V))+Math.imul(S,U)|0,a=Math.imul(S,V),n=n+Math.imul(T,q)|0,i=(i=i+Math.imul(T,G)|0)+Math.imul(k,q)|0,a=a+Math.imul(k,G)|0,n=n+Math.imul(b,W)|0,i=(i=i+Math.imul(b,X)|0)+Math.imul(_,W)|0,a=a+Math.imul(_,X)|0,n=n+Math.imul(v,J)|0,i=(i=i+Math.imul(v,K)|0)+Math.imul(y,J)|0,a=a+Math.imul(y,K)|0,n=n+Math.imul(d,$)|0,i=(i=i+Math.imul(d,tt)|0)+Math.imul(m,$)|0,a=a+Math.imul(m,tt)|0;var _t=(c+(n=n+Math.imul(f,rt)|0)|0)+((8191&(i=(i=i+Math.imul(f,nt)|0)+Math.imul(h,rt)|0))<<13)|0;c=((a=a+Math.imul(h,nt)|0)+(i>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(L,U),i=(i=Math.imul(L,V))+Math.imul(C,U)|0,a=Math.imul(C,V),n=n+Math.imul(M,q)|0,i=(i=i+Math.imul(M,G)|0)+Math.imul(S,q)|0,a=a+Math.imul(S,G)|0,n=n+Math.imul(T,W)|0,i=(i=i+Math.imul(T,X)|0)+Math.imul(k,W)|0,a=a+Math.imul(k,X)|0,n=n+Math.imul(b,J)|0,i=(i=i+Math.imul(b,K)|0)+Math.imul(_,J)|0,a=a+Math.imul(_,K)|0,n=n+Math.imul(v,$)|0,i=(i=i+Math.imul(v,tt)|0)+Math.imul(y,$)|0,a=a+Math.imul(y,tt)|0,n=n+Math.imul(d,rt)|0,i=(i=i+Math.imul(d,nt)|0)+Math.imul(m,rt)|0,a=a+Math.imul(m,nt)|0;var wt=(c+(n=n+Math.imul(f,at)|0)|0)+((8191&(i=(i=i+Math.imul(f,ot)|0)+Math.imul(h,at)|0))<<13)|0;c=((a=a+Math.imul(h,ot)|0)+(i>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(I,U),i=(i=Math.imul(I,V))+Math.imul(O,U)|0,a=Math.imul(O,V),n=n+Math.imul(L,q)|0,i=(i=i+Math.imul(L,G)|0)+Math.imul(C,q)|0,a=a+Math.imul(C,G)|0,n=n+Math.imul(M,W)|0,i=(i=i+Math.imul(M,X)|0)+Math.imul(S,W)|0,a=a+Math.imul(S,X)|0,n=n+Math.imul(T,J)|0,i=(i=i+Math.imul(T,K)|0)+Math.imul(k,J)|0,a=a+Math.imul(k,K)|0,n=n+Math.imul(b,$)|0,i=(i=i+Math.imul(b,tt)|0)+Math.imul(_,$)|0,a=a+Math.imul(_,tt)|0,n=n+Math.imul(v,rt)|0,i=(i=i+Math.imul(v,nt)|0)+Math.imul(y,rt)|0,a=a+Math.imul(y,nt)|0,n=n+Math.imul(d,at)|0,i=(i=i+Math.imul(d,ot)|0)+Math.imul(m,at)|0,a=a+Math.imul(m,ot)|0;var Tt=(c+(n=n+Math.imul(f,lt)|0)|0)+((8191&(i=(i=i+Math.imul(f,ct)|0)+Math.imul(h,lt)|0))<<13)|0;c=((a=a+Math.imul(h,ct)|0)+(i>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(D,U),i=(i=Math.imul(D,V))+Math.imul(R,U)|0,a=Math.imul(R,V),n=n+Math.imul(I,q)|0,i=(i=i+Math.imul(I,G)|0)+Math.imul(O,q)|0,a=a+Math.imul(O,G)|0,n=n+Math.imul(L,W)|0,i=(i=i+Math.imul(L,X)|0)+Math.imul(C,W)|0,a=a+Math.imul(C,X)|0,n=n+Math.imul(M,J)|0,i=(i=i+Math.imul(M,K)|0)+Math.imul(S,J)|0,a=a+Math.imul(S,K)|0,n=n+Math.imul(T,$)|0,i=(i=i+Math.imul(T,tt)|0)+Math.imul(k,$)|0,a=a+Math.imul(k,tt)|0,n=n+Math.imul(b,rt)|0,i=(i=i+Math.imul(b,nt)|0)+Math.imul(_,rt)|0,a=a+Math.imul(_,nt)|0,n=n+Math.imul(v,at)|0,i=(i=i+Math.imul(v,ot)|0)+Math.imul(y,at)|0,a=a+Math.imul(y,ot)|0,n=n+Math.imul(d,lt)|0,i=(i=i+Math.imul(d,ct)|0)+Math.imul(m,lt)|0,a=a+Math.imul(m,ct)|0;var kt=(c+(n=n+Math.imul(f,ft)|0)|0)+((8191&(i=(i=i+Math.imul(f,ht)|0)+Math.imul(h,ft)|0))<<13)|0;c=((a=a+Math.imul(h,ht)|0)+(i>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(B,U),i=(i=Math.imul(B,V))+Math.imul(N,U)|0,a=Math.imul(N,V),n=n+Math.imul(D,q)|0,i=(i=i+Math.imul(D,G)|0)+Math.imul(R,q)|0,a=a+Math.imul(R,G)|0,n=n+Math.imul(I,W)|0,i=(i=i+Math.imul(I,X)|0)+Math.imul(O,W)|0,a=a+Math.imul(O,X)|0,n=n+Math.imul(L,J)|0,i=(i=i+Math.imul(L,K)|0)+Math.imul(C,J)|0,a=a+Math.imul(C,K)|0,n=n+Math.imul(M,$)|0,i=(i=i+Math.imul(M,tt)|0)+Math.imul(S,$)|0,a=a+Math.imul(S,tt)|0,n=n+Math.imul(T,rt)|0,i=(i=i+Math.imul(T,nt)|0)+Math.imul(k,rt)|0,a=a+Math.imul(k,nt)|0,n=n+Math.imul(b,at)|0,i=(i=i+Math.imul(b,ot)|0)+Math.imul(_,at)|0,a=a+Math.imul(_,ot)|0,n=n+Math.imul(v,lt)|0,i=(i=i+Math.imul(v,ct)|0)+Math.imul(y,lt)|0,a=a+Math.imul(y,ct)|0,n=n+Math.imul(d,ft)|0,i=(i=i+Math.imul(d,ht)|0)+Math.imul(m,ft)|0,a=a+Math.imul(m,ht)|0;var At=(c+(n=n+Math.imul(f,dt)|0)|0)+((8191&(i=(i=i+Math.imul(f,mt)|0)+Math.imul(h,dt)|0))<<13)|0;c=((a=a+Math.imul(h,mt)|0)+(i>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(B,q),i=(i=Math.imul(B,G))+Math.imul(N,q)|0,a=Math.imul(N,G),n=n+Math.imul(D,W)|0,i=(i=i+Math.imul(D,X)|0)+Math.imul(R,W)|0,a=a+Math.imul(R,X)|0,n=n+Math.imul(I,J)|0,i=(i=i+Math.imul(I,K)|0)+Math.imul(O,J)|0,a=a+Math.imul(O,K)|0,n=n+Math.imul(L,$)|0,i=(i=i+Math.imul(L,tt)|0)+Math.imul(C,$)|0,a=a+Math.imul(C,tt)|0,n=n+Math.imul(M,rt)|0,i=(i=i+Math.imul(M,nt)|0)+Math.imul(S,rt)|0,a=a+Math.imul(S,nt)|0,n=n+Math.imul(T,at)|0,i=(i=i+Math.imul(T,ot)|0)+Math.imul(k,at)|0,a=a+Math.imul(k,ot)|0,n=n+Math.imul(b,lt)|0,i=(i=i+Math.imul(b,ct)|0)+Math.imul(_,lt)|0,a=a+Math.imul(_,ct)|0,n=n+Math.imul(v,ft)|0,i=(i=i+Math.imul(v,ht)|0)+Math.imul(y,ft)|0,a=a+Math.imul(y,ht)|0;var Mt=(c+(n=n+Math.imul(d,dt)|0)|0)+((8191&(i=(i=i+Math.imul(d,mt)|0)+Math.imul(m,dt)|0))<<13)|0;c=((a=a+Math.imul(m,mt)|0)+(i>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(B,W),i=(i=Math.imul(B,X))+Math.imul(N,W)|0,a=Math.imul(N,X),n=n+Math.imul(D,J)|0,i=(i=i+Math.imul(D,K)|0)+Math.imul(R,J)|0,a=a+Math.imul(R,K)|0,n=n+Math.imul(I,$)|0,i=(i=i+Math.imul(I,tt)|0)+Math.imul(O,$)|0,a=a+Math.imul(O,tt)|0,n=n+Math.imul(L,rt)|0,i=(i=i+Math.imul(L,nt)|0)+Math.imul(C,rt)|0,a=a+Math.imul(C,nt)|0,n=n+Math.imul(M,at)|0,i=(i=i+Math.imul(M,ot)|0)+Math.imul(S,at)|0,a=a+Math.imul(S,ot)|0,n=n+Math.imul(T,lt)|0,i=(i=i+Math.imul(T,ct)|0)+Math.imul(k,lt)|0,a=a+Math.imul(k,ct)|0,n=n+Math.imul(b,ft)|0,i=(i=i+Math.imul(b,ht)|0)+Math.imul(_,ft)|0,a=a+Math.imul(_,ht)|0;var St=(c+(n=n+Math.imul(v,dt)|0)|0)+((8191&(i=(i=i+Math.imul(v,mt)|0)+Math.imul(y,dt)|0))<<13)|0;c=((a=a+Math.imul(y,mt)|0)+(i>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(B,J),i=(i=Math.imul(B,K))+Math.imul(N,J)|0,a=Math.imul(N,K),n=n+Math.imul(D,$)|0,i=(i=i+Math.imul(D,tt)|0)+Math.imul(R,$)|0,a=a+Math.imul(R,tt)|0,n=n+Math.imul(I,rt)|0,i=(i=i+Math.imul(I,nt)|0)+Math.imul(O,rt)|0,a=a+Math.imul(O,nt)|0,n=n+Math.imul(L,at)|0,i=(i=i+Math.imul(L,ot)|0)+Math.imul(C,at)|0,a=a+Math.imul(C,ot)|0,n=n+Math.imul(M,lt)|0,i=(i=i+Math.imul(M,ct)|0)+Math.imul(S,lt)|0,a=a+Math.imul(S,ct)|0,n=n+Math.imul(T,ft)|0,i=(i=i+Math.imul(T,ht)|0)+Math.imul(k,ft)|0,a=a+Math.imul(k,ht)|0;var Et=(c+(n=n+Math.imul(b,dt)|0)|0)+((8191&(i=(i=i+Math.imul(b,mt)|0)+Math.imul(_,dt)|0))<<13)|0;c=((a=a+Math.imul(_,mt)|0)+(i>>>13)|0)+(Et>>>26)|0,Et&=67108863,n=Math.imul(B,$),i=(i=Math.imul(B,tt))+Math.imul(N,$)|0,a=Math.imul(N,tt),n=n+Math.imul(D,rt)|0,i=(i=i+Math.imul(D,nt)|0)+Math.imul(R,rt)|0,a=a+Math.imul(R,nt)|0,n=n+Math.imul(I,at)|0,i=(i=i+Math.imul(I,ot)|0)+Math.imul(O,at)|0,a=a+Math.imul(O,ot)|0,n=n+Math.imul(L,lt)|0,i=(i=i+Math.imul(L,ct)|0)+Math.imul(C,lt)|0,a=a+Math.imul(C,ct)|0,n=n+Math.imul(M,ft)|0,i=(i=i+Math.imul(M,ht)|0)+Math.imul(S,ft)|0,a=a+Math.imul(S,ht)|0;var Lt=(c+(n=n+Math.imul(T,dt)|0)|0)+((8191&(i=(i=i+Math.imul(T,mt)|0)+Math.imul(k,dt)|0))<<13)|0;c=((a=a+Math.imul(k,mt)|0)+(i>>>13)|0)+(Lt>>>26)|0,Lt&=67108863,n=Math.imul(B,rt),i=(i=Math.imul(B,nt))+Math.imul(N,rt)|0,a=Math.imul(N,nt),n=n+Math.imul(D,at)|0,i=(i=i+Math.imul(D,ot)|0)+Math.imul(R,at)|0,a=a+Math.imul(R,ot)|0,n=n+Math.imul(I,lt)|0,i=(i=i+Math.imul(I,ct)|0)+Math.imul(O,lt)|0,a=a+Math.imul(O,ct)|0,n=n+Math.imul(L,ft)|0,i=(i=i+Math.imul(L,ht)|0)+Math.imul(C,ft)|0,a=a+Math.imul(C,ht)|0;var Ct=(c+(n=n+Math.imul(M,dt)|0)|0)+((8191&(i=(i=i+Math.imul(M,mt)|0)+Math.imul(S,dt)|0))<<13)|0;c=((a=a+Math.imul(S,mt)|0)+(i>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,n=Math.imul(B,at),i=(i=Math.imul(B,ot))+Math.imul(N,at)|0,a=Math.imul(N,ot),n=n+Math.imul(D,lt)|0,i=(i=i+Math.imul(D,ct)|0)+Math.imul(R,lt)|0,a=a+Math.imul(R,ct)|0,n=n+Math.imul(I,ft)|0,i=(i=i+Math.imul(I,ht)|0)+Math.imul(O,ft)|0,a=a+Math.imul(O,ht)|0;var Pt=(c+(n=n+Math.imul(L,dt)|0)|0)+((8191&(i=(i=i+Math.imul(L,mt)|0)+Math.imul(C,dt)|0))<<13)|0;c=((a=a+Math.imul(C,mt)|0)+(i>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,n=Math.imul(B,lt),i=(i=Math.imul(B,ct))+Math.imul(N,lt)|0,a=Math.imul(N,ct),n=n+Math.imul(D,ft)|0,i=(i=i+Math.imul(D,ht)|0)+Math.imul(R,ft)|0,a=a+Math.imul(R,ht)|0;var It=(c+(n=n+Math.imul(I,dt)|0)|0)+((8191&(i=(i=i+Math.imul(I,mt)|0)+Math.imul(O,dt)|0))<<13)|0;c=((a=a+Math.imul(O,mt)|0)+(i>>>13)|0)+(It>>>26)|0,It&=67108863,n=Math.imul(B,ft),i=(i=Math.imul(B,ht))+Math.imul(N,ft)|0,a=Math.imul(N,ht);var Ot=(c+(n=n+Math.imul(D,dt)|0)|0)+((8191&(i=(i=i+Math.imul(D,mt)|0)+Math.imul(R,dt)|0))<<13)|0;c=((a=a+Math.imul(R,mt)|0)+(i>>>13)|0)+(Ot>>>26)|0,Ot&=67108863;var zt=(c+(n=Math.imul(B,dt))|0)+((8191&(i=(i=Math.imul(B,mt))+Math.imul(N,dt)|0))<<13)|0;return c=((a=Math.imul(N,mt))+(i>>>13)|0)+(zt>>>26)|0,zt&=67108863,l[0]=gt,l[1]=vt,l[2]=yt,l[3]=xt,l[4]=bt,l[5]=_t,l[6]=wt,l[7]=Tt,l[8]=kt,l[9]=At,l[10]=Mt,l[11]=St,l[12]=Et,l[13]=Lt,l[14]=Ct,l[15]=Pt,l[16]=It,l[17]=Ot,l[18]=zt,0!==c&&(l[19]=c,r.length++),r};function m(t,e,r){return(new g).mulp(t,e,r)}function g(t,e){this.x=t,this.y=e}Math.imul||(d=p),a.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?d(this,t,e):r<63?p(this,t,e):r<1024?function(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var n=0,i=0,a=0;a<r.length-1;a++){var o=i;i=0;for(var s=67108863&n,l=Math.min(a,e.length-1),c=Math.max(0,a-t.length+1);c<=l;c++){var u=a-c,f=(0|t.words[u])*(0|e.words[c]),h=67108863&f;s=67108863&(h=h+s|0),i+=(o=(o=o+(f/67108864|0)|0)+(h>>>26)|0)>>>26,o&=67108863}r.words[a]=s,n=o,o=i}return 0!==n?r.words[a]=n:r.length--,r.strip()}(this,t,e):m(this,t,e)},g.prototype.makeRBT=function(t){for(var e=new Array(t),r=a.prototype._countBits(t)-1,n=0;n<t;n++)e[n]=this.revBin(n,r,t);return e},g.prototype.revBin=function(t,e,r){if(0===t||t===r-1)return t;for(var n=0,i=0;i<e;i++)n|=(1&t)<<e-i-1,t>>=1;return n},g.prototype.permute=function(t,e,r,n,i,a){for(var o=0;o<a;o++)n[o]=e[t[o]],i[o]=r[t[o]]},g.prototype.transform=function(t,e,r,n,i,a){this.permute(a,t,e,r,n,i);for(var o=1;o<i;o<<=1)for(var s=o<<1,l=Math.cos(2*Math.PI/s),c=Math.sin(2*Math.PI/s),u=0;u<i;u+=s)for(var f=l,h=c,p=0;p<o;p++){var d=r[u+p],m=n[u+p],g=r[u+p+o],v=n[u+p+o],y=f*g-h*v;v=f*v+h*g,g=y,r[u+p]=d+g,n[u+p]=m+v,r[u+p+o]=d-g,n[u+p+o]=m-v,p!==s&&(y=l*f-c*h,h=l*h+c*f,f=y)}},g.prototype.guessLen13b=function(t,e){var r=1|Math.max(e,t),n=1&r,i=0;for(r=r/2|0;r;r>>>=1)i++;return 1<<i+1+n},g.prototype.conjugate=function(t,e,r){if(!(r<=1))for(var n=0;n<r/2;n++){var i=t[n];t[n]=t[r-n-1],t[r-n-1]=i,i=e[n],e[n]=-e[r-n-1],e[r-n-1]=-i}},g.prototype.normalize13b=function(t,e){for(var r=0,n=0;n<e/2;n++){var i=8192*Math.round(t[2*n+1]/e)+Math.round(t[2*n]/e)+r;t[n]=67108863&i,r=i<67108864?0:i/67108864|0}return t},g.prototype.convert13b=function(t,e,r,i){for(var a=0,o=0;o<e;o++)a+=0|t[o],r[2*o]=8191&a,a>>>=13,r[2*o+1]=8191&a,a>>>=13;for(o=2*e;o<i;++o)r[o]=0;n(0===a),n(0==(-8192&a))},g.prototype.stub=function(t){for(var e=new Array(t),r=0;r<t;r++)e[r]=0;return e},g.prototype.mulp=function(t,e,r){var n=2*this.guessLen13b(t.length,e.length),i=this.makeRBT(n),a=this.stub(n),o=new Array(n),s=new Array(n),l=new Array(n),c=new Array(n),u=new Array(n),f=new Array(n),h=r.words;h.length=n,this.convert13b(t.words,t.length,o,n),this.convert13b(e.words,e.length,c,n),this.transform(o,a,s,l,n,i),this.transform(c,a,u,f,n,i);for(var p=0;p<n;p++){var d=s[p]*u[p]-l[p]*f[p];l[p]=s[p]*f[p]+l[p]*u[p],s[p]=d}return this.conjugate(s,l,n),this.transform(s,l,h,a,n,i),this.conjugate(h,a,n),this.normalize13b(h,n),r.negative=t.negative^e.negative,r.length=t.length+e.length,r.strip()},a.prototype.mul=function(t){var e=new a(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},a.prototype.mulf=function(t){var e=new a(null);return e.words=new Array(this.length+t.length),m(this,t,e)},a.prototype.imul=function(t){return this.clone().mulTo(t,this)},a.prototype.imuln=function(t){n("number"==typeof t),n(t<67108864);for(var e=0,r=0;r<this.length;r++){var i=(0|this.words[r])*t,a=(67108863&i)+(67108863&e);e>>=26,e+=i/67108864|0,e+=a>>>26,this.words[r]=67108863&a}return 0!==e&&(this.words[r]=e,this.length++),this},a.prototype.muln=function(t){return this.clone().imuln(t)},a.prototype.sqr=function(){return this.mul(this)},a.prototype.isqr=function(){return this.imul(this.clone())},a.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),r=0;r<e.length;r++){var n=r/26|0,i=r%26;e[r]=(t.words[n]&1<<i)>>>i}return e}(t);if(0===e.length)return new a(1);for(var r=this,n=0;n<e.length&&0===e[n];n++,r=r.sqr());if(++n<e.length)for(var i=r.sqr();n<e.length;n++,i=i.sqr())0!==e[n]&&(r=r.mul(i));return r},a.prototype.iushln=function(t){n("number"==typeof t&&t>=0);var e,r=t%26,i=(t-r)/26,a=67108863>>>26-r<<26-r;if(0!==r){var o=0;for(e=0;e<this.length;e++){var s=this.words[e]&a,l=(0|this.words[e])-s<<r;this.words[e]=l|o,o=s>>>26-r}o&&(this.words[e]=o,this.length++)}if(0!==i){for(e=this.length-1;e>=0;e--)this.words[e+i]=this.words[e];for(e=0;e<i;e++)this.words[e]=0;this.length+=i}return this.strip()},a.prototype.ishln=function(t){return n(0===this.negative),this.iushln(t)},a.prototype.iushrn=function(t,e,r){var i;n("number"==typeof t&&t>=0),i=e?(e-e%26)/26:0;var a=t%26,o=Math.min((t-a)/26,this.length),s=67108863^67108863>>>a<<a,l=r;if(i-=o,i=Math.max(0,i),l){for(var c=0;c<o;c++)l.words[c]=this.words[c];l.length=o}if(0===o);else if(this.length>o)for(this.length-=o,c=0;c<this.length;c++)this.words[c]=this.words[c+o];else this.words[0]=0,this.length=1;var u=0;for(c=this.length-1;c>=0&&(0!==u||c>=i);c--){var f=0|this.words[c];this.words[c]=u<<26-a|f>>>a,u=f&s}return l&&0!==u&&(l.words[l.length++]=u),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},a.prototype.ishrn=function(t,e,r){return n(0===this.negative),this.iushrn(t,e,r)},a.prototype.shln=function(t){return this.clone().ishln(t)},a.prototype.ushln=function(t){return this.clone().iushln(t)},a.prototype.shrn=function(t){return this.clone().ishrn(t)},a.prototype.ushrn=function(t){return this.clone().iushrn(t)},a.prototype.testn=function(t){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26,i=1<<e;return!(this.length<=r)&&!!(this.words[r]&i)},a.prototype.imaskn=function(t){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==e&&r++,this.length=Math.min(r,this.length),0!==e){var i=67108863^67108863>>>e<<e;this.words[this.length-1]&=i}return this.strip()},a.prototype.maskn=function(t){return this.clone().imaskn(t)},a.prototype.iaddn=function(t){return n("number"==typeof t),n(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},a.prototype._iaddn=function(t){this.words[0]+=t;for(var e=0;e<this.length&&this.words[e]>=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},a.prototype.isubn=function(t){if(n("number"==typeof t),n(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e<this.length&&this.words[e]<0;e++)this.words[e]+=67108864,this.words[e+1]-=1;return this.strip()},a.prototype.addn=function(t){return this.clone().iaddn(t)},a.prototype.subn=function(t){return this.clone().isubn(t)},a.prototype.iabs=function(){return this.negative=0,this},a.prototype.abs=function(){return this.clone().iabs()},a.prototype._ishlnsubmul=function(t,e,r){var i,a,o=t.length+r;this._expand(o);var s=0;for(i=0;i<t.length;i++){a=(0|this.words[i+r])+s;var l=(0|t.words[i])*e;s=((a-=67108863&l)>>26)-(l/67108864|0),this.words[i+r]=67108863&a}for(;i<this.length-r;i++)s=(a=(0|this.words[i+r])+s)>>26,this.words[i+r]=67108863&a;if(0===s)return this.strip();for(n(-1===s),s=0,i=0;i<this.length;i++)s=(a=-(0|this.words[i])+s)>>26,this.words[i]=67108863&a;return this.negative=1,this.strip()},a.prototype._wordDiv=function(t,e){var r=(this.length,t.length),n=this.clone(),i=t,o=0|i.words[i.length-1];0!==(r=26-this._countBits(o))&&(i=i.ushln(r),n.iushln(r),o=0|i.words[i.length-1]);var s,l=n.length-i.length;if("mod"!==e){(s=new a(null)).length=l+1,s.words=new Array(s.length);for(var c=0;c<s.length;c++)s.words[c]=0}var u=n.clone()._ishlnsubmul(i,1,l);0===u.negative&&(n=u,s&&(s.words[l]=1));for(var f=l-1;f>=0;f--){var h=67108864*(0|n.words[i.length+f])+(0|n.words[i.length+f-1]);for(h=Math.min(h/o|0,67108863),n._ishlnsubmul(i,h,f);0!==n.negative;)h--,n.negative=0,n._ishlnsubmul(i,1,f),n.isZero()||(n.negative^=1);s&&(s.words[f]=h)}return s&&s.strip(),n.strip(),"div"!==e&&0!==r&&n.iushrn(r),{div:s||null,mod:n}},a.prototype.divmod=function(t,e,r){return n(!t.isZero()),this.isZero()?{div:new a(0),mod:new a(0)}:0!==this.negative&&0===t.negative?(s=this.neg().divmod(t,e),"mod"!==e&&(i=s.div.neg()),"div"!==e&&(o=s.mod.neg(),r&&0!==o.negative&&o.iadd(t)),{div:i,mod:o}):0===this.negative&&0!==t.negative?(s=this.divmod(t.neg(),e),"mod"!==e&&(i=s.div.neg()),{div:i,mod:s.mod}):0!=(this.negative&t.negative)?(s=this.neg().divmod(t.neg(),e),"div"!==e&&(o=s.mod.neg(),r&&0!==o.negative&&o.isub(t)),{div:s.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new a(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new a(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new a(this.modn(t.words[0]))}:this._wordDiv(t,e);var i,o,s},a.prototype.div=function(t){return this.divmod(t,"div",!1).div},a.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},a.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},a.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,n=t.ushrn(1),i=t.andln(1),a=r.cmp(n);return a<0||1===i&&0===a?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},a.prototype.modn=function(t){n(t<=67108863);for(var e=(1<<26)%t,r=0,i=this.length-1;i>=0;i--)r=(e*r+(0|this.words[i]))%t;return r},a.prototype.idivn=function(t){n(t<=67108863);for(var e=0,r=this.length-1;r>=0;r--){var i=(0|this.words[r])+67108864*e;this.words[r]=i/t|0,e=i%t}return this.strip()},a.prototype.divn=function(t){return this.clone().idivn(t)},a.prototype.egcd=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i=new a(1),o=new a(0),s=new a(0),l=new a(1),c=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++c;for(var u=r.clone(),f=e.clone();!e.isZero();){for(var h=0,p=1;0==(e.words[0]&p)&&h<26;++h,p<<=1);if(h>0)for(e.iushrn(h);h-- >0;)(i.isOdd()||o.isOdd())&&(i.iadd(u),o.isub(f)),i.iushrn(1),o.iushrn(1);for(var d=0,m=1;0==(r.words[0]&m)&&d<26;++d,m<<=1);if(d>0)for(r.iushrn(d);d-- >0;)(s.isOdd()||l.isOdd())&&(s.iadd(u),l.isub(f)),s.iushrn(1),l.iushrn(1);e.cmp(r)>=0?(e.isub(r),i.isub(s),o.isub(l)):(r.isub(e),s.isub(i),l.isub(o))}return{a:s,b:l,gcd:r.iushln(c)}},a.prototype._invmp=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i,o=new a(1),s=new a(0),l=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,u=1;0==(e.words[0]&u)&&c<26;++c,u<<=1);if(c>0)for(e.iushrn(c);c-- >0;)o.isOdd()&&o.iadd(l),o.iushrn(1);for(var f=0,h=1;0==(r.words[0]&h)&&f<26;++f,h<<=1);if(f>0)for(r.iushrn(f);f-- >0;)s.isOdd()&&s.iadd(l),s.iushrn(1);e.cmp(r)>=0?(e.isub(r),o.isub(s)):(r.isub(e),s.isub(o))}return(i=0===e.cmpn(1)?o:s).cmpn(0)<0&&i.iadd(t),i},a.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var n=0;e.isEven()&&r.isEven();n++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var i=e.cmp(r);if(i<0){var a=e;e=r,r=a}else if(0===i||0===r.cmpn(1))break;e.isub(r)}return r.iushln(n)},a.prototype.invm=function(t){return this.egcd(t).a.umod(t)},a.prototype.isEven=function(){return 0==(1&this.words[0])},a.prototype.isOdd=function(){return 1==(1&this.words[0])},a.prototype.andln=function(t){return this.words[0]&t},a.prototype.bincn=function(t){n("number"==typeof t);var e=t%26,r=(t-e)/26,i=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=i,this;for(var a=i,o=r;0!==a&&o<this.length;o++){var s=0|this.words[o];a=(s+=a)>>>26,s&=67108863,this.words[o]=s}return 0!==a&&(this.words[o]=a,this.length++),this},a.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},a.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this.strip(),this.length>1)e=1;else{r&&(t=-t),n(t<=67108863,"Number is too big");var i=0|this.words[0];e=i===t?0:i<t?-1:1}return 0!==this.negative?0|-e:e},a.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var e=this.ucmp(t);return 0!==this.negative?0|-e:e},a.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,r=this.length-1;r>=0;r--){var n=0|this.words[r],i=0|t.words[r];if(n!==i){n<i?e=-1:n>i&&(e=1);break}}return e},a.prototype.gtn=function(t){return 1===this.cmpn(t)},a.prototype.gt=function(t){return 1===this.cmp(t)},a.prototype.gten=function(t){return this.cmpn(t)>=0},a.prototype.gte=function(t){return this.cmp(t)>=0},a.prototype.ltn=function(t){return-1===this.cmpn(t)},a.prototype.lt=function(t){return-1===this.cmp(t)},a.prototype.lten=function(t){return this.cmpn(t)<=0},a.prototype.lte=function(t){return this.cmp(t)<=0},a.prototype.eqn=function(t){return 0===this.cmpn(t)},a.prototype.eq=function(t){return 0===this.cmp(t)},a.red=function(t){return new T(t)},a.prototype.toRed=function(t){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},a.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},a.prototype._forceRed=function(t){return this.red=t,this},a.prototype.forceRed=function(t){return n(!this.red,"Already a number in reduction context"),this._forceRed(t)},a.prototype.redAdd=function(t){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},a.prototype.redIAdd=function(t){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},a.prototype.redSub=function(t){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},a.prototype.redISub=function(t){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},a.prototype.redShl=function(t){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},a.prototype.redMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},a.prototype.redIMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},a.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},a.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},a.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},a.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},a.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},a.prototype.redPow=function(t){return n(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var v={k256:null,p224:null,p192:null,p25519:null};function y(t,e){this.name=t,this.p=new a(e,16),this.n=this.p.bitLength(),this.k=new a(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function x(){y.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function b(){y.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function _(){y.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function w(){y.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function T(t){if("string"==typeof t){var e=a._prime(t);this.m=e.p,this.prime=e}else n(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function k(t){T.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new a(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}y.prototype._tmp=function(){var t=new a(null);return t.words=new Array(Math.ceil(this.n/13)),t},y.prototype.ireduce=function(t){var e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var n=e<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},y.prototype.split=function(t,e){t.iushrn(this.n,0,e)},y.prototype.imulK=function(t){return t.imul(this.k)},i(x,y),x.prototype.split=function(t,e){for(var r=Math.min(t.length,9),n=0;n<r;n++)e.words[n]=t.words[n];if(e.length=r,t.length<=9)return t.words[0]=0,void(t.length=1);var i=t.words[9];for(e.words[e.length++]=4194303&i,n=10;n<t.length;n++){var a=0|t.words[n];t.words[n-10]=(4194303&a)<<4|i>>>22,i=a}i>>>=22,t.words[n-10]=i,0===i&&t.length>10?t.length-=10:t.length-=9},x.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r<t.length;r++){var n=0|t.words[r];e+=977*n,t.words[r]=67108863&e,e=64*n+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},i(b,y),i(_,y),i(w,y),w.prototype.imulK=function(t){for(var e=0,r=0;r<t.length;r++){var n=19*(0|t.words[r])+e,i=67108863&n;n>>>=26,t.words[r]=i,e=n}return 0!==e&&(t.words[t.length++]=e),t},a._prime=function(t){if(v[t])return v[t];var e;if("k256"===t)e=new x;else if("p224"===t)e=new b;else if("p192"===t)e=new _;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new w}return v[t]=e,e},T.prototype._verify1=function(t){n(0===t.negative,"red works only with positives"),n(t.red,"red works only with red numbers")},T.prototype._verify2=function(t,e){n(0==(t.negative|e.negative),"red works only with positives"),n(t.red&&t.red===e.red,"red works only with red numbers")},T.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},T.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},T.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},T.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},T.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},T.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},T.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},T.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},T.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},T.prototype.isqr=function(t){return this.imul(t,t.clone())},T.prototype.sqr=function(t){return this.mul(t,t)},T.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(n(e%2==1),3===e){var r=this.m.add(new a(1)).iushrn(2);return this.pow(t,r)}for(var i=this.m.subn(1),o=0;!i.isZero()&&0===i.andln(1);)o++,i.iushrn(1);n(!i.isZero());var s=new a(1).toRed(this),l=s.redNeg(),c=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new a(2*u*u).toRed(this);0!==this.pow(u,c).cmp(l);)u.redIAdd(l);for(var f=this.pow(u,i),h=this.pow(t,i.addn(1).iushrn(1)),p=this.pow(t,i),d=o;0!==p.cmp(s);){for(var m=p,g=0;0!==m.cmp(s);g++)m=m.redSqr();n(g<d);var v=this.pow(f,new a(1).iushln(d-g-1));h=h.redMul(v),f=v.redSqr(),p=p.redMul(f),d=g}return h},T.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},T.prototype.pow=function(t,e){if(e.isZero())return new a(1).toRed(this);if(0===e.cmpn(1))return t.clone();var r=new Array(16);r[0]=new a(1).toRed(this),r[1]=t;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],t);var i=r[0],o=0,s=0,l=e.bitLength()%26;for(0===l&&(l=26),n=e.length-1;n>=0;n--){for(var c=e.words[n],u=l-1;u>=0;u--){var f=c>>u&1;i!==r[0]&&(i=this.sqr(i)),0!==f||0!==o?(o<<=1,o|=f,(4===++s||0===n&&0===u)&&(i=this.mul(i,r[o]),s=0,o=0)):s=0}l=26}return i},T.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},T.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},a.mont=function(t){return new k(t)},i(k,T),k.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},k.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},k.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),a=i;return i.cmp(this.m)>=0?a=i.isub(this.m):i.cmpn(0)<0&&(a=i.iadd(this.m)),a._forceRed(this)},k.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new a(0)._forceRed(this);var r=t.mul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),o=i;return i.cmp(this.m)>=0?o=i.isub(this.m):i.cmpn(0)<0&&(o=i.iadd(this.m)),o._forceRed(this)},k.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(void 0===e||e,this)},{buffer:2}],34:[function(t,e,r){"use strict";e.exports=function(t){var e,r,n,i=t.length,a=0;for(e=0;e<i;++e)a+=t[e].length;var o=new Array(a),s=0;for(e=0;e<i;++e){var l=t[e],c=l.length;for(r=0;r<c;++r){var u=o[s++]=new Array(c-1),f=0;for(n=0;n<c;++n)n!==r&&(u[f++]=l[n]);if(1&r){var h=u[1];u[1]=u[0],u[0]=h}}}return o}},{}],35:[function(t,e,r){"use strict";e.exports=function(t,e,r){switch(arguments.length){case 1:return f(t);case 2:return"function"==typeof e?c(t,t,e,!0):h(t,e);case 3:return c(t,e,r,!1);default:throw new Error("box-intersect: Invalid arguments")}};var n,i=t("typedarray-pool"),a=t("./lib/sweep"),o=t("./lib/intersect");function s(t,e){for(var r=0;r<t;++r)if(!(e[r]<=e[r+t]))return!0;return!1}function l(t,e,r,n){for(var i=0,a=0,o=0,l=t.length;o<l;++o){var c=t[o];if(!s(e,c)){for(var u=0;u<2*e;++u)r[i++]=c[u];n[a++]=o}}return a}function c(t,e,r,n){var s=t.length,c=e.length;if(!(s<=0||c<=0)){var u=t[0].length>>>1;if(!(u<=0)){var f,h=i.mallocDouble(2*u*s),p=i.mallocInt32(s);if((s=l(t,u,h,p))>0){if(1===u&&n)a.init(s),f=a.sweepComplete(u,r,0,s,h,p,0,s,h,p);else{var d=i.mallocDouble(2*u*c),m=i.mallocInt32(c);(c=l(e,u,d,m))>0&&(a.init(s+c),f=1===u?a.sweepBipartite(u,r,0,s,h,p,0,c,d,m):o(u,r,n,s,h,p,c,d,m),i.free(d),i.free(m))}i.free(h),i.free(p)}return f}}}function u(t,e){n.push([t,e])}function f(t){return n=[],c(t,t,u,!0),n}function h(t,e){return n=[],c(t,e,u,!1),n}},{"./lib/intersect":37,"./lib/sweep":41,"typedarray-pool":308}],36:[function(t,e,r){"use strict";function n(t){return t?function(t,e,r,n,i,a,o,s,l,c,u){return i-n>l-s?function(t,e,r,n,i,a,o,s,l,c,u){for(var f=2*t,h=n,p=f*n;h<i;++h,p+=f){var d=a[e+p],m=a[e+p+t],g=o[h];t:for(var v=s,y=f*s;v<l;++v,y+=f){var x=c[e+y],b=c[e+y+t],_=u[v];if(!(b<d||m<x)){for(var w=e+1;w<t;++w){var T=a[w+p],k=a[w+t+p],A=c[w+y],M=c[w+t+y];if(k<A||M<T)continue t}var S=r(g,_);if(void 0!==S)return S}}}}(t,e,r,n,i,a,o,s,l,c,u):function(t,e,r,n,i,a,o,s,l,c,u){for(var f=2*t,h=s,p=f*s;h<l;++h,p+=f){var d=c[e+p],m=c[e+p+t],g=u[h];t:for(var v=n,y=f*n;v<i;++v,y+=f){var x=a[e+y],b=a[e+y+t],_=o[v];if(!(m<x||b<d)){for(var w=e+1;w<t;++w){var T=a[w+y],k=a[w+t+y],A=c[w+p],M=c[w+t+p];if(k<A||M<T)continue t}var S=r(_,g);if(void 0!==S)return S}}}}(t,e,r,n,i,a,o,s,l,c,u)}:function(t,e,r,n,i,a,o,s,l,c,u,f){return a-i>c-l?n?function(t,e,r,n,i,a,o,s,l,c,u){for(var f=2*t,h=n,p=f*n;h<i;++h,p+=f){var d=a[e+p],m=a[e+p+t],g=o[h];t:for(var v=s,y=f*s;v<l;++v,y+=f){var x=c[e+y],b=u[v];if(!(x<=d||m<x)){for(var _=e+1;_<t;++_){var w=a[_+p],T=a[_+t+p],k=c[_+y],A=c[_+t+y];if(T<k||A<w)continue t}var M=r(b,g);if(void 0!==M)return M}}}}(t,e,r,i,a,o,s,l,c,u,f):function(t,e,r,n,i,a,o,s,l,c,u){for(var f=2*t,h=n,p=f*n;h<i;++h,p+=f){var d=a[e+p],m=a[e+p+t],g=o[h];t:for(var v=s,y=f*s;v<l;++v,y+=f){var x=c[e+y],b=u[v];if(!(x<d||m<x)){for(var _=e+1;_<t;++_){var w=a[_+p],T=a[_+t+p],k=c[_+y],A=c[_+t+y];if(T<k||A<w)continue t}var M=r(g,b);if(void 0!==M)return M}}}}(t,e,r,i,a,o,s,l,c,u,f):n?function(t,e,r,n,i,a,o,s,l,c,u){for(var f=2*t,h=s,p=f*s;h<l;++h,p+=f){var d=c[e+p],m=u[h];t:for(var g=n,v=f*n;g<i;++g,v+=f){var y=a[e+v],x=a[e+v+t],b=o[g];if(!(d<=y||x<d)){for(var _=e+1;_<t;++_){var w=a[_+v],T=a[_+t+v],k=c[_+p],A=c[_+t+p];if(T<k||A<w)continue t}var M=r(m,b);if(void 0!==M)return M}}}}(t,e,r,i,a,o,s,l,c,u,f):function(t,e,r,n,i,a,o,s,l,c,u){for(var f=2*t,h=s,p=f*s;h<l;++h,p+=f){var d=c[e+p],m=u[h];t:for(var g=n,v=f*n;g<i;++g,v+=f){var y=a[e+v],x=a[e+v+t],b=o[g];if(!(d<y||x<d)){for(var _=e+1;_<t;++_){var w=a[_+v],T=a[_+t+v],k=c[_+p],A=c[_+t+p];if(T<k||A<w)continue t}var M=r(b,m);if(void 0!==M)return M}}}}(t,e,r,i,a,o,s,l,c,u,f)}}r.partial=n(!1),r.full=n(!0)},{}],37:[function(t,e,r){"use strict";e.exports=function(t,e,r,a,u,w,T,k,A){!function(t,e){var r=8*i.log2(e+1)*(t+1)|0,a=i.nextPow2(6*r);v.length<a&&(n.free(v),v=n.mallocInt32(a));var o=i.nextPow2(2*r);y.length<o&&(n.free(y),y=n.mallocDouble(o))}(t,a+T);var M,S=0,E=2*t;x(S++,0,0,a,0,T,r?16:0,-1/0,1/0),r||x(S++,0,0,T,0,a,1,-1/0,1/0);for(;S>0;){var L=6*(S-=1),C=v[L],P=v[L+1],I=v[L+2],O=v[L+3],z=v[L+4],D=v[L+5],R=2*S,F=y[R],B=y[R+1],N=1&D,j=!!(16&D),U=u,V=w,H=k,q=A;if(N&&(U=k,V=A,H=u,q=w),!(2&D&&(I=p(t,C,P,I,U,V,B),P>=I)||4&D&&(P=d(t,C,P,I,U,V,F))>=I)){var G=I-P,Y=z-O;if(j){if(t*G*(G+Y)<1<<22){if(void 0!==(M=l.scanComplete(t,C,e,P,I,U,V,O,z,H,q)))return M;continue}}else{if(t*Math.min(G,Y)<128){if(void 0!==(M=o(t,C,e,N,P,I,U,V,O,z,H,q)))return M;continue}if(t*G*Y<1<<22){if(void 0!==(M=l.scanBipartite(t,C,e,N,P,I,U,V,O,z,H,q)))return M;continue}}var W=f(t,C,P,I,U,V,F,B);if(P<W)if(t*(W-P)<128){if(void 0!==(M=s(t,C+1,e,P,W,U,V,O,z,H,q)))return M}else if(C===t-2){if(void 0!==(M=N?l.sweepBipartite(t,e,O,z,H,q,P,W,U,V):l.sweepBipartite(t,e,P,W,U,V,O,z,H,q)))return M}else x(S++,C+1,P,W,O,z,N,-1/0,1/0),x(S++,C+1,O,z,P,W,1^N,-1/0,1/0);if(W<I){var X=c(t,C,O,z,H,q),Z=H[E*X+C],J=h(t,C,X,z,H,q,Z);if(J<z&&x(S++,C,W,I,J,z,(4|N)+(j?16:0),Z,B),O<X&&x(S++,C,W,I,O,X,(2|N)+(j?16:0),F,Z),X+1===J){if(void 0!==(M=j?_(t,C,e,W,I,U,V,X,H,q[X]):b(t,C,e,N,W,I,U,V,X,H,q[X])))return M}else if(X<J){var K;if(j){if(K=m(t,C,W,I,U,V,Z),W<K){var Q=h(t,C,W,K,U,V,Z);if(C===t-2){if(W<Q&&void 0!==(M=l.sweepComplete(t,e,W,Q,U,V,X,J,H,q)))return M;if(Q<K&&void 0!==(M=l.sweepBipartite(t,e,Q,K,U,V,X,J,H,q)))return M}else W<Q&&x(S++,C+1,W,Q,X,J,16,-1/0,1/0),Q<K&&(x(S++,C+1,Q,K,X,J,0,-1/0,1/0),x(S++,C+1,X,J,Q,K,1,-1/0,1/0))}}else K=N?g(t,C,W,I,U,V,Z):m(t,C,W,I,U,V,Z),W<K&&(C===t-2?M=N?l.sweepBipartite(t,e,X,J,H,q,W,K,U,V):l.sweepBipartite(t,e,W,K,U,V,X,J,H,q):(x(S++,C+1,W,K,X,J,N,-1/0,1/0),x(S++,C+1,X,J,W,K,1^N,-1/0,1/0)))}}}}};var n=t("typedarray-pool"),i=t("bit-twiddle"),a=t("./brute"),o=a.partial,s=a.full,l=t("./sweep"),c=t("./median"),u=t("./partition"),f=u("!(lo>=p0)&&!(p1>=hi)"),h=u("lo===p0"),p=u("lo<p0"),d=u("hi<=p0"),m=u("lo<=p0&&p0<=hi"),g=u("lo<p0&&p0<=hi"),v=n.mallocInt32(1024),y=n.mallocDouble(1024);function x(t,e,r,n,i,a,o,s,l){var c=6*t;v[c]=e,v[c+1]=r,v[c+2]=n,v[c+3]=i,v[c+4]=a,v[c+5]=o;var u=2*t;y[u]=s,y[u+1]=l}function b(t,e,r,n,i,a,o,s,l,c,u){var f=2*t,h=l*f,p=c[h+e];t:for(var d=i,m=i*f;d<a;++d,m+=f){var g=o[m+e],v=o[m+e+t];if(!(p<g||v<p)&&(!n||p!==g)){for(var y,x=s[d],b=e+1;b<t;++b){g=o[m+b],v=o[m+b+t];var _=c[h+b],w=c[h+b+t];if(v<_||w<g)continue t}if(void 0!==(y=n?r(u,x):r(x,u)))return y}}}function _(t,e,r,n,i,a,o,s,l,c){var u=2*t,f=s*u,h=l[f+e];t:for(var p=n,d=n*u;p<i;++p,d+=u){var m=o[p];if(m!==c){var g=a[d+e],v=a[d+e+t];if(!(h<g||v<h)){for(var y=e+1;y<t;++y){g=a[d+y],v=a[d+y+t];var x=l[f+y],b=l[f+y+t];if(v<x||b<g)continue t}var _=r(m,c);if(void 0!==_)return _}}}}},{"./brute":36,"./median":38,"./partition":39,"./sweep":41,"bit-twiddle":32,"typedarray-pool":308}],38:[function(t,e,r){"use strict";e.exports=function(t,e,r,a,o,s){if(a<=r+1)return r;var l=r,c=a,u=a+r>>>1,f=2*t,h=u,p=o[f*u+e];for(;l<c;){if(c-l<8){i(t,e,l,c,o,s),p=o[f*u+e];break}var d=c-l,m=Math.random()*d+l|0,g=o[f*m+e],v=Math.random()*d+l|0,y=o[f*v+e],x=Math.random()*d+l|0,b=o[f*x+e];g<=y?b>=y?(h=v,p=y):g>=b?(h=m,p=g):(h=x,p=b):y>=b?(h=v,p=y):b>=g?(h=m,p=g):(h=x,p=b);for(var _=f*(c-1),w=f*h,T=0;T<f;++T,++_,++w){var k=o[_];o[_]=o[w],o[w]=k}var A=s[c-1];s[c-1]=s[h],s[h]=A,h=n(t,e,l,c-1,o,s,p);for(_=f*(c-1),w=f*h,T=0;T<f;++T,++_,++w){k=o[_];o[_]=o[w],o[w]=k}A=s[c-1];if(s[c-1]=s[h],s[h]=A,u<h){for(c=h-1;l<c&&o[f*(c-1)+e]===p;)c-=1;c+=1}else{if(!(h<u))break;for(l=h+1;l<c&&o[f*l+e]===p;)l+=1}}return n(t,e,r,u,o,s,o[f*u+e])};var n=t("./partition")("lo<p0");function i(t,e,r,n,i,a){for(var o=2*t,s=o*(r+1)+e,l=r+1;l<n;++l,s+=o)for(var c=i[s],u=l,f=o*(l-1);u>r&&i[f+e]>c;--u,f-=o){for(var h=f,p=f+o,d=0;d<o;++d,++h,++p){var m=i[h];i[h]=i[p],i[p]=m}var g=a[u];a[u]=a[u-1],a[u-1]=g}}},{"./partition":39}],39:[function(t,e,r){"use strict";e.exports=function(t){return n[t]};var n={"lo===p0":function(t,e,r,n,i,a,o){for(var s=2*t,l=s*r,c=l,u=r,f=e,h=r;n>h;++h,l+=s){if(i[l+f]===o)if(u===h)u+=1,c+=s;else{for(var p=0;s>p;++p){var d=i[l+p];i[l+p]=i[c],i[c++]=d}var m=a[h];a[h]=a[u],a[u++]=m}}return u},"lo<p0":function(t,e,r,n,i,a,o){for(var s=2*t,l=s*r,c=l,u=r,f=e,h=r;n>h;++h,l+=s){if(i[l+f]<o)if(u===h)u+=1,c+=s;else{for(var p=0;s>p;++p){var d=i[l+p];i[l+p]=i[c],i[c++]=d}var m=a[h];a[h]=a[u],a[u++]=m}}return u},"lo<=p0":function(t,e,r,n,i,a,o){for(var s=2*t,l=s*r,c=l,u=r,f=t+e,h=r;n>h;++h,l+=s){if(i[l+f]<=o)if(u===h)u+=1,c+=s;else{for(var p=0;s>p;++p){var d=i[l+p];i[l+p]=i[c],i[c++]=d}var m=a[h];a[h]=a[u],a[u++]=m}}return u},"hi<=p0":function(t,e,r,n,i,a,o){for(var s=2*t,l=s*r,c=l,u=r,f=t+e,h=r;n>h;++h,l+=s){if(i[l+f]<=o)if(u===h)u+=1,c+=s;else{for(var p=0;s>p;++p){var d=i[l+p];i[l+p]=i[c],i[c++]=d}var m=a[h];a[h]=a[u],a[u++]=m}}return u},"lo<p0&&p0<=hi":function(t,e,r,n,i,a,o){for(var s=2*t,l=s*r,c=l,u=r,f=e,h=t+e,p=r;n>p;++p,l+=s){var d=i[l+f],m=i[l+h];if(d<o&&o<=m)if(u===p)u+=1,c+=s;else{for(var g=0;s>g;++g){var v=i[l+g];i[l+g]=i[c],i[c++]=v}var y=a[p];a[p]=a[u],a[u++]=y}}return u},"lo<=p0&&p0<=hi":function(t,e,r,n,i,a,o){for(var s=2*t,l=s*r,c=l,u=r,f=e,h=t+e,p=r;n>p;++p,l+=s){var d=i[l+f],m=i[l+h];if(d<=o&&o<=m)if(u===p)u+=1,c+=s;else{for(var g=0;s>g;++g){var v=i[l+g];i[l+g]=i[c],i[c++]=v}var y=a[p];a[p]=a[u],a[u++]=y}}return u},"!(lo>=p0)&&!(p1>=hi)":function(t,e,r,n,i,a,o,s){for(var l=2*t,c=l*r,u=c,f=r,h=e,p=t+e,d=r;n>d;++d,c+=l){var m=i[c+h],g=i[c+p];if(!(m>=o||s>=g))if(f===d)f+=1,u+=l;else{for(var v=0;l>v;++v){var y=i[c+v];i[c+v]=i[u],i[u++]=y}var x=a[d];a[d]=a[f],a[f++]=x}}return f}}},{}],40:[function(t,e,r){"use strict";e.exports=function(t,e){e<=128?n(0,e-1,t):function t(e,r,u){var f=(r-e+1)/6|0,h=e+f,p=r-f,d=e+r>>1,m=d-f,g=d+f,v=h,y=m,x=d,b=g,_=p,w=e+1,T=r-1,k=0;l(v,y,u)&&(k=v,v=y,y=k);l(b,_,u)&&(k=b,b=_,_=k);l(v,x,u)&&(k=v,v=x,x=k);l(y,x,u)&&(k=y,y=x,x=k);l(v,b,u)&&(k=v,v=b,b=k);l(x,b,u)&&(k=x,x=b,b=k);l(y,_,u)&&(k=y,y=_,_=k);l(y,x,u)&&(k=y,y=x,x=k);l(b,_,u)&&(k=b,b=_,_=k);for(var A=u[2*y],M=u[2*y+1],S=u[2*b],E=u[2*b+1],L=2*v,C=2*x,P=2*_,I=2*h,O=2*d,z=2*p,D=0;D<2;++D){var R=u[L+D],F=u[C+D],B=u[P+D];u[I+D]=R,u[O+D]=F,u[z+D]=B}a(m,e,u),a(g,r,u);for(var N=w;N<=T;++N)if(c(N,A,M,u))N!==w&&i(N,w,u),++w;else if(!c(N,S,E,u))for(;;){if(c(T,S,E,u)){c(T,A,M,u)?(o(N,w,T,u),++w,--T):(i(N,T,u),--T);break}if(--T<N)break}s(e,w-1,A,M,u),s(r,T+1,S,E,u),w-2-e<=32?n(e,w-2,u):t(e,w-2,u);r-(T+2)<=32?n(T+2,r,u):t(T+2,r,u);T-w<=32?n(w,T,u):t(w,T,u)}(0,e-1,t)};function n(t,e,r){for(var n=2*(t+1),i=t+1;i<=e;++i){for(var a=r[n++],o=r[n++],s=i,l=n-2;s-- >t;){var c=r[l-2],u=r[l-1];if(c<a)break;if(c===a&&u<o)break;r[l]=c,r[l+1]=u,l-=2}r[l]=a,r[l+1]=o}}function i(t,e,r){e*=2;var n=r[t*=2],i=r[t+1];r[t]=r[e],r[t+1]=r[e+1],r[e]=n,r[e+1]=i}function a(t,e,r){e*=2,r[t*=2]=r[e],r[t+1]=r[e+1]}function o(t,e,r,n){e*=2,r*=2;var i=n[t*=2],a=n[t+1];n[t]=n[e],n[t+1]=n[e+1],n[e]=n[r],n[e+1]=n[r+1],n[r]=i,n[r+1]=a}function s(t,e,r,n,i){e*=2,i[t*=2]=i[e],i[e]=r,i[t+1]=i[e+1],i[e+1]=n}function l(t,e,r){e*=2;var n=r[t*=2],i=r[e];return!(n<i)&&(n!==i||r[t+1]>r[e+1])}function c(t,e,r,n){var i=n[t*=2];return i<e||i===e&&n[t+1]<r}},{}],41:[function(t,e,r){"use strict";e.exports={init:function(t){var e=i.nextPow2(t);o.length<e&&(n.free(o),o=n.mallocInt32(e));s.length<e&&(n.free(s),s=n.mallocInt32(e));l.length<e&&(n.free(l),l=n.mallocInt32(e));c.length<e&&(n.free(c),c=n.mallocInt32(e));u.length<e&&(n.free(u),u=n.mallocInt32(e));f.length<e&&(n.free(f),f=n.mallocInt32(e));var r=8*e;h.length<r&&(n.free(h),h=n.mallocDouble(r))},sweepBipartite:function(t,e,r,n,i,u,f,m,g,v){for(var y=0,x=2*t,b=t-1,_=x-1,w=r;w<n;++w){var T=u[w],k=x*w;h[y++]=i[k+b],h[y++]=-(T+1),h[y++]=i[k+_],h[y++]=T}for(w=f;w<m;++w){T=v[w]+(1<<28);var A=x*w;h[y++]=g[A+b],h[y++]=-T,h[y++]=g[A+_],h[y++]=T}var M=y>>>1;a(h,M);var S=0,E=0;for(w=0;w<M;++w){var L=0|h[2*w+1];if(L>=1<<28)p(l,c,E--,L=L-(1<<28)|0);else if(L>=0)p(o,s,S--,L);else if(L<=-(1<<28)){L=-L-(1<<28)|0;for(var C=0;C<S;++C){if(void 0!==(P=e(o[C],L)))return P}d(l,c,E++,L)}else{L=-L-1|0;for(C=0;C<E;++C){var P;if(void 0!==(P=e(L,l[C])))return P}d(o,s,S++,L)}}},sweepComplete:function(t,e,r,n,i,m,g,v,y,x){for(var b=0,_=2*t,w=t-1,T=_-1,k=r;k<n;++k){var A=m[k]+1<<1,M=_*k;h[b++]=i[M+w],h[b++]=-A,h[b++]=i[M+T],h[b++]=A}for(k=g;k<v;++k){A=x[k]+1<<1;var S=_*k;h[b++]=y[S+w],h[b++]=1|-A,h[b++]=y[S+T],h[b++]=1|A}var E=b>>>1;a(h,E);var L=0,C=0,P=0;for(k=0;k<E;++k){var I=0|h[2*k+1],O=1&I;if(k<E-1&&I>>1==h[2*k+3]>>1&&(O=2,k+=1),I<0){for(var z=-(I>>1)-1,D=0;D<P;++D){if(void 0!==(R=e(u[D],z)))return R}if(0!==O)for(D=0;D<L;++D){if(void 0!==(R=e(o[D],z)))return R}if(1!==O)for(D=0;D<C;++D){var R;if(void 0!==(R=e(l[D],z)))return R}0===O?d(o,s,L++,z):1===O?d(l,c,C++,z):2===O&&d(u,f,P++,z)}else{z=(I>>1)-1;0===O?p(o,s,L--,z):1===O?p(l,c,C--,z):2===O&&p(u,f,P--,z)}}},scanBipartite:function(t,e,r,n,i,l,c,u,f,m,g,v){var y=0,x=2*t,b=e,_=e+t,w=1,T=1;n?T=1<<28:w=1<<28;for(var k=i;k<l;++k){var A=k+w,M=x*k;h[y++]=c[M+b],h[y++]=-A,h[y++]=c[M+_],h[y++]=A}for(k=f;k<m;++k){A=k+T;var S=x*k;h[y++]=g[S+b],h[y++]=-A}var E=y>>>1;a(h,E);var L=0;for(k=0;k<E;++k){var C=0|h[2*k+1];if(C<0){var P=!1;if((A=-C)>=1<<28?(P=!n,A-=1<<28):(P=!!n,A-=1),P)d(o,s,L++,A);else{var I=v[A],O=x*A,z=g[O+e+1],D=g[O+e+1+t];t:for(var R=0;R<L;++R){var F=o[R],B=x*F;if(!(D<c[B+e+1]||c[B+e+1+t]<z)){for(var N=e+2;N<t;++N)if(g[O+N+t]<c[B+N]||c[B+N+t]<g[O+N])continue t;var j,U=u[F];if(void 0!==(j=n?r(I,U):r(U,I)))return j}}}}else p(o,s,L--,C-w)}},scanComplete:function(t,e,r,n,i,s,l,c,u,f,p){for(var d=0,m=2*t,g=e,v=e+t,y=n;y<i;++y){var x=y+(1<<28),b=m*y;h[d++]=s[b+g],h[d++]=-x,h[d++]=s[b+v],h[d++]=x}for(y=c;y<u;++y){x=y+1;var _=m*y;h[d++]=f[_+g],h[d++]=-x}var w=d>>>1;a(h,w);var T=0;for(y=0;y<w;++y){var k=0|h[2*y+1];if(k<0){if((x=-k)>=1<<28)o[T++]=x-(1<<28);else{var A=p[x-=1],M=m*x,S=f[M+e+1],E=f[M+e+1+t];t:for(var L=0;L<T;++L){var C=o[L],P=l[C];if(P===A)break;var I=m*C;if(!(E<s[I+e+1]||s[I+e+1+t]<S)){for(var O=e+2;O<t;++O)if(f[M+O+t]<s[I+O]||s[I+O+t]<f[M+O])continue t;var z=r(P,A);if(void 0!==z)return z}}}}else{for(x=k-(1<<28),L=T-1;L>=0;--L)if(o[L]===x){for(O=L+1;O<T;++O)o[O-1]=o[O];break}--T}}}};var n=t("typedarray-pool"),i=t("bit-twiddle"),a=t("./sort"),o=n.mallocInt32(1024),s=n.mallocInt32(1024),l=n.mallocInt32(1024),c=n.mallocInt32(1024),u=n.mallocInt32(1024),f=n.mallocInt32(1024),h=n.mallocDouble(8192);function p(t,e,r,n){var i=e[n],a=t[r-1];t[i]=a,e[a]=i}function d(t,e,r,n){t[r]=n,e[n]=r}},{"./sort":40,"bit-twiddle":32,"typedarray-pool":308}],42:[function(t,e,r){"use strict";var n=t("./lib/monotone"),i=t("./lib/triangulation"),a=t("./lib/delaunay"),o=t("./lib/filter");function s(t){return[Math.min(t[0],t[1]),Math.max(t[0],t[1])]}function l(t,e){return t[0]-e[0]||t[1]-e[1]}function c(t,e,r){return e in t?t[e]:r}e.exports=function(t,e,r){Array.isArray(e)?(r=r||{},e=e||[]):(r=e||{},e=[]);var u=!!c(r,"delaunay",!0),f=!!c(r,"interior",!0),h=!!c(r,"exterior",!0),p=!!c(r,"infinity",!1);if(!f&&!h||0===t.length)return[];var d=n(t,e);if(u||f!==h||p){for(var m=i(t.length,function(t){return t.map(s).sort(l)}(e)),g=0;g<d.length;++g){var v=d[g];m.addTriangle(v[0],v[1],v[2])}return u&&a(t,m),h?f?p?o(m,0,p):m.cells():o(m,1,p):o(m,-1)}return d}},{"./lib/delaunay":43,"./lib/filter":44,"./lib/monotone":45,"./lib/triangulation":46}],43:[function(t,e,r){"use strict";var n=t("robust-in-sphere")[4];t("binary-search-bounds");function i(t,e,r,i,a,o){var s=e.opposite(i,a);if(!(s<0)){if(a<i){var l=i;i=a,a=l,l=o,o=s,s=l}e.isConstraint(i,a)||n(t[i],t[a],t[o],t[s])<0&&r.push(i,a)}}e.exports=function(t,e){for(var r=[],a=t.length,o=e.stars,s=0;s<a;++s)for(var l=o[s],c=1;c<l.length;c+=2){if(!((p=l[c])<s)&&!e.isConstraint(s,p)){for(var u=l[c-1],f=-1,h=1;h<l.length;h+=2)if(l[h-1]===p){f=l[h];break}f<0||n(t[s],t[p],t[u],t[f])<0&&r.push(s,p)}}for(;r.length>0;){for(var p=r.pop(),d=(s=r.pop(),u=-1,f=-1,l=o[s],1);d<l.length;d+=2){var m=l[d-1],g=l[d];m===p?f=g:g===p&&(u=m)}u<0||f<0||(n(t[s],t[p],t[u],t[f])>=0||(e.flip(s,p),i(t,e,r,u,s,f),i(t,e,r,s,f,u),i(t,e,r,f,p,u),i(t,e,r,p,u,f)))}}},{"binary-search-bounds":31,"robust-in-sphere":282}],44:[function(t,e,r){"use strict";var n,i=t("binary-search-bounds");function a(t,e,r,n,i,a,o){this.cells=t,this.neighbor=e,this.flags=n,this.constraint=r,this.active=i,this.next=a,this.boundary=o}function o(t,e){return t[0]-e[0]||t[1]-e[1]||t[2]-e[2]}e.exports=function(t,e,r){var n=function(t,e){for(var r=t.cells(),n=r.length,i=0;i<n;++i){var s=(v=r[i])[0],l=v[1],c=v[2];l<c?l<s&&(v[0]=l,v[1]=c,v[2]=s):c<s&&(v[0]=c,v[1]=s,v[2]=l)}r.sort(o);var u=new Array(n);for(i=0;i<u.length;++i)u[i]=0;var f=[],h=[],p=new Array(3*n),d=new Array(3*n),m=null;e&&(m=[]);var g=new a(r,p,d,u,f,h,m);for(i=0;i<n;++i)for(var v=r[i],y=0;y<3;++y){s=v[y],l=v[(y+1)%3];var x=p[3*i+y]=g.locate(l,s,t.opposite(l,s)),b=d[3*i+y]=t.isConstraint(s,l);x<0&&(b?h.push(i):(f.push(i),u[i]=1),e&&m.push([l,s,-1]))}return g}(t,r);if(0===e)return r?n.cells.concat(n.boundary):n.cells;var i=1,s=n.active,l=n.next,c=n.flags,u=n.cells,f=n.constraint,h=n.neighbor;for(;s.length>0||l.length>0;){for(;s.length>0;){var p=s.pop();if(c[p]!==-i){c[p]=i;u[p];for(var d=0;d<3;++d){var m=h[3*p+d];m>=0&&0===c[m]&&(f[3*p+d]?l.push(m):(s.push(m),c[m]=i))}}}var g=l;l=s,s=g,l.length=0,i=-i}var v=function(t,e,r){for(var n=0,i=0;i<t.length;++i)e[i]===r&&(t[n++]=t[i]);return t.length=n,t}(u,c,e);if(r)return v.concat(n.boundary);return v},a.prototype.locate=(n=[0,0,0],function(t,e,r){var a=t,s=e,l=r;return e<r?e<t&&(a=e,s=r,l=t):r<t&&(a=r,s=t,l=e),a<0?-1:(n[0]=a,n[1]=s,n[2]=l,i.eq(this.cells,n,o))})},{"binary-search-bounds":31}],45:[function(t,e,r){"use strict";var n=t("binary-search-bounds"),i=t("robust-orientation")[3];function a(t,e,r,n,i){this.a=t,this.b=e,this.idx=r,this.lowerIds=n,this.upperIds=i}function o(t,e,r,n){this.a=t,this.b=e,this.type=r,this.idx=n}function s(t,e){var r=t.a[0]-e.a[0]||t.a[1]-e.a[1]||t.type-e.type;return r||(0!==t.type&&(r=i(t.a,t.b,e.b))?r:t.idx-e.idx)}function l(t,e){return i(t.a,t.b,e)}function c(t,e,r,a,o){for(var s=n.lt(e,a,l),c=n.gt(e,a,l),u=s;u<c;++u){for(var f=e[u],h=f.lowerIds,p=h.length;p>1&&i(r[h[p-2]],r[h[p-1]],a)>0;)t.push([h[p-1],h[p-2],o]),p-=1;h.length=p,h.push(o);var d=f.upperIds;for(p=d.length;p>1&&i(r[d[p-2]],r[d[p-1]],a)<0;)t.push([d[p-2],d[p-1],o]),p-=1;d.length=p,d.push(o)}}function u(t,e){var r;return(r=t.a[0]<e.a[0]?i(t.a,t.b,e.a):i(e.b,e.a,t.a))?r:(r=e.b[0]<t.b[0]?i(t.a,t.b,e.b):i(e.b,e.a,t.b))||t.idx-e.idx}function f(t,e,r){var i=n.le(t,r,u),o=t[i],s=o.upperIds,l=s[s.length-1];o.upperIds=[l],t.splice(i+1,0,new a(r.a,r.b,r.idx,[l],s))}function h(t,e,r){var i=r.a;r.a=r.b,r.b=i;var a=n.eq(t,r,u),o=t[a];t[a-1].upperIds=o.upperIds,t.splice(a,1)}e.exports=function(t,e){for(var r=t.length,n=e.length,i=[],l=0;l<r;++l)i.push(new o(t[l],null,0,l));for(l=0;l<n;++l){var u=e[l],p=t[u[0]],d=t[u[1]];p[0]<d[0]?i.push(new o(p,d,2,l),new o(d,p,1,l)):p[0]>d[0]&&i.push(new o(d,p,2,l),new o(p,d,1,l))}i.sort(s);for(var m=i[0].a[0]-(1+Math.abs(i[0].a[0]))*Math.pow(2,-52),g=[new a([m,1],[m,0],-1,[],[],[],[])],v=[],y=(l=0,i.length);l<y;++l){var x=i[l],b=x.type;0===b?c(v,g,t,x.a,x.idx):2===b?f(g,t,x):h(g,t,x)}return v}},{"binary-search-bounds":31,"robust-orientation":284}],46:[function(t,e,r){"use strict";var n=t("binary-search-bounds");function i(t,e){this.stars=t,this.edges=e}e.exports=function(t,e){for(var r=new Array(t),n=0;n<t;++n)r[n]=[];return new i(r,e)};var a=i.prototype;function o(t,e,r){for(var n=1,i=t.length;n<i;n+=2)if(t[n-1]===e&&t[n]===r)return t[n-1]=t[i-2],t[n]=t[i-1],void(t.length=i-2)}a.isConstraint=function(){var t=[0,0];function e(t,e){return t[0]-e[0]||t[1]-e[1]}return function(r,i){return t[0]=Math.min(r,i),t[1]=Math.max(r,i),n.eq(this.edges,t,e)>=0}}(),a.removeTriangle=function(t,e,r){var n=this.stars;o(n[t],e,r),o(n[e],r,t),o(n[r],t,e)},a.addTriangle=function(t,e,r){var n=this.stars;n[t].push(e,r),n[e].push(r,t),n[r].push(t,e)},a.opposite=function(t,e){for(var r=this.stars[e],n=1,i=r.length;n<i;n+=2)if(r[n]===t)return r[n-1];return-1},a.flip=function(t,e){var r=this.opposite(t,e),n=this.opposite(e,t);this.removeTriangle(t,e,r),this.removeTriangle(e,t,n),this.addTriangle(t,n,r),this.addTriangle(e,r,n)},a.edges=function(){for(var t=this.stars,e=[],r=0,n=t.length;r<n;++r)for(var i=t[r],a=0,o=i.length;a<o;a+=2)e.push([i[a],i[a+1]]);return e},a.cells=function(){for(var t=this.stars,e=[],r=0,n=t.length;r<n;++r)for(var i=t[r],a=0,o=i.length;a<o;a+=2){var s=i[a],l=i[a+1];r<Math.min(s,l)&&e.push([r,s,l])}return e}},{"binary-search-bounds":31}],47:[function(t,e,r){"use strict";e.exports=function(t){for(var e=1,r=1;r<t.length;++r)for(var n=0;n<r;++n)if(t[r]<t[n])e=-e;else if(t[n]===t[r])return 0;return e}},{}],48:[function(t,e,r){"use strict";var n=t("dup"),i=t("robust-linear-solve");function a(t,e){for(var r=0,n=t.length,i=0;i<n;++i)r+=t[i]*e[i];return r}function o(t){var e=t.length;if(0===e)return[];t[0].length;var r=n([t.length+1,t.length+1],1),o=n([t.length+1],1);r[e][e]=0;for(var s=0;s<e;++s){for(var l=0;l<=s;++l)r[l][s]=r[s][l]=2*a(t[s],t[l]);o[s]=a(t[s],t[s])}var c=i(r,o),u=0,f=c[e+1];for(s=0;s<f.length;++s)u+=f[s];var h=new Array(e);for(s=0;s<e;++s){f=c[s];var p=0;for(l=0;l<f.length;++l)p+=f[l];h[s]=p/u}return h}function s(t){if(0===t.length)return[];for(var e=t[0].length,r=n([e]),i=o(t),a=0;a<t.length;++a)for(var s=0;s<e;++s)r[s]+=t[a][s]*i[a];return r}s.barycenetric=o,e.exports=s},{dup:65,"robust-linear-solve":283}],49:[function(t,e,r){e.exports=function(t){for(var e=n(t),r=0,i=0;i<t.length;++i)for(var a=t[i],o=0;o<e.length;++o)r+=Math.pow(a[o]-e[o],2);return Math.sqrt(r/t.length)};var n=t("circumcenter")},{circumcenter:48}],50:[function(t,e,r){"use strict";e.exports=function(t,e,r){var n;if(r){n=e;for(var i=new Array(e.length),a=0;a<e.length;++a){var o=e[a];i[a]=[o[0],o[1],r[a]]}e=i}var s=function(t,e,r){var n=d(t,[],p(t));return v(e,n,r),!!n}(t,e,!!r);for(;y(t,e,!!r);)s=!0;if(r&&s){n.length=0,r.length=0;for(a=0;a<e.length;++a){o=e[a];n.push([o[0],o[1]]),r.push(o[2])}}return s};var n=t("union-find"),i=t("box-intersect"),a=t("robust-segment-intersect"),o=t("big-rat"),s=t("big-rat/cmp"),l=t("big-rat/to-float"),c=t("rat-vec"),u=t("nextafter"),f=t("./lib/rat-seg-intersect");function h(t){var e=l(t);return[u(e,-1/0),u(e,1/0)]}function p(t){for(var e=new Array(t.length),r=0;r<t.length;++r){var n=t[r];e[r]=[u(n[0],-1/0),u(n[1],-1/0),u(n[0],1/0),u(n[1],1/0)]}return e}function d(t,e,r){for(var a=e.length,o=new n(a),s=[],l=0;l<e.length;++l){var c=e[l],f=h(c[0]),p=h(c[1]);s.push([u(f[0],-1/0),u(p[0],-1/0),u(f[1],1/0),u(p[1],1/0)])}i(s,(function(t,e){o.link(t,e)}));var d=!0,m=new Array(a);for(l=0;l<a;++l){(v=o.find(l))!==l&&(d=!1,t[v]=[Math.min(t[l][0],t[v][0]),Math.min(t[l][1],t[v][1])])}if(d)return null;var g=0;for(l=0;l<a;++l){var v;(v=o.find(l))===l?(m[l]=g,t[g++]=t[l]):m[l]=-1}t.length=g;for(l=0;l<a;++l)m[l]<0&&(m[l]=m[o.find(l)]);return m}function m(t,e){return t[0]-e[0]||t[1]-e[1]}function g(t,e){var r=t[0]-e[0]||t[1]-e[1];return r||(t[2]<e[2]?-1:t[2]>e[2]?1:0)}function v(t,e,r){if(0!==t.length){if(e)for(var n=0;n<t.length;++n){var i=e[(o=t[n])[0]],a=e[o[1]];o[0]=Math.min(i,a),o[1]=Math.max(i,a)}else for(n=0;n<t.length;++n){var o;i=(o=t[n])[0],a=o[1];o[0]=Math.min(i,a),o[1]=Math.max(i,a)}r?t.sort(g):t.sort(m);var s=1;for(n=1;n<t.length;++n){var l=t[n-1],c=t[n];(c[0]!==l[0]||c[1]!==l[1]||r&&c[2]!==l[2])&&(t[s++]=c)}t.length=s}}function y(t,e,r){var n=function(t,e){for(var r=new Array(e.length),n=0;n<e.length;++n){var i=e[n],a=t[i[0]],o=t[i[1]];r[n]=[u(Math.min(a[0],o[0]),-1/0),u(Math.min(a[1],o[1]),-1/0),u(Math.max(a[0],o[0]),1/0),u(Math.max(a[1],o[1]),1/0)]}return r}(t,e),h=function(t,e,r){var n=[];return i(r,(function(r,i){var o=e[r],s=e[i];if(o[0]!==s[0]&&o[0]!==s[1]&&o[1]!==s[0]&&o[1]!==s[1]){var l=t[o[0]],c=t[o[1]],u=t[s[0]],f=t[s[1]];a(l,c,u,f)&&n.push([r,i])}})),n}(t,e,n),m=p(t),g=function(t,e,r,n){var o=[];return i(r,n,(function(r,n){var i=e[r];if(i[0]!==n&&i[1]!==n){var s=t[n],l=t[i[0]],c=t[i[1]];a(l,c,s,s)&&o.push([r,n])}})),o}(t,e,n,m),y=d(t,function(t,e,r,n,i){var a,u,h=t.map((function(t){return[o(t[0]),o(t[1])]}));for(a=0;a<r.length;++a){var p=r[a];u=p[0];var d=p[1],m=e[u],g=e[d],v=f(c(t[m[0]]),c(t[m[1]]),c(t[g[0]]),c(t[g[1]]));if(v){var y=t.length;t.push([l(v[0]),l(v[1])]),h.push(v),n.push([u,y],[d,y])}}for(n.sort((function(t,e){if(t[0]!==e[0])return t[0]-e[0];var r=h[t[1]],n=h[e[1]];return s(r[0],n[0])||s(r[1],n[1])})),a=n.length-1;a>=0;--a){var x=e[u=(S=n[a])[0]],b=x[0],_=x[1],w=t[b],T=t[_];if((w[0]-T[0]||w[1]-T[1])<0){var k=b;b=_,_=k}x[0]=b;var A,M=x[1]=S[1];for(i&&(A=x[2]);a>0&&n[a-1][0]===u;){var S,E=(S=n[--a])[1];i?e.push([M,E,A]):e.push([M,E]),M=E}i?e.push([M,_,A]):e.push([M,_])}return h}(t,e,h,g,r));return v(e,y,r),!!y||(h.length>0||g.length>0)}},{"./lib/rat-seg-intersect":51,"big-rat":18,"big-rat/cmp":16,"big-rat/to-float":30,"box-intersect":35,nextafter:260,"rat-vec":273,"robust-segment-intersect":287,"union-find":309}],51:[function(t,e,r){"use strict";e.exports=function(t,e,r,n){var a=s(e,t),f=s(n,r),h=u(a,f);if(0===o(h))return null;var p=s(t,r),d=u(f,p),m=i(d,h),g=c(a,m);return l(t,g)};var n=t("big-rat/mul"),i=t("big-rat/div"),a=t("big-rat/sub"),o=t("big-rat/sign"),s=t("rat-vec/sub"),l=t("rat-vec/add"),c=t("rat-vec/muls");function u(t,e){return a(n(t[0],e[1]),n(t[1],e[0]))}},{"big-rat/div":17,"big-rat/mul":27,"big-rat/sign":28,"big-rat/sub":29,"rat-vec/add":272,"rat-vec/muls":274,"rat-vec/sub":275}],52:[function(t,e,r){e.exports={jet:[{index:0,rgb:[0,0,131]},{index:.125,rgb:[0,60,170]},{index:.375,rgb:[5,255,255]},{index:.625,rgb:[255,255,0]},{index:.875,rgb:[250,0,0]},{index:1,rgb:[128,0,0]}],hsv:[{index:0,rgb:[255,0,0]},{index:.169,rgb:[253,255,2]},{index:.173,rgb:[247,255,2]},{index:.337,rgb:[0,252,4]},{index:.341,rgb:[0,252,10]},{index:.506,rgb:[1,249,255]},{index:.671,rgb:[2,0,253]},{index:.675,rgb:[8,0,253]},{index:.839,rgb:[255,0,251]},{index:.843,rgb:[255,0,245]},{index:1,rgb:[255,0,6]}],hot:[{index:0,rgb:[0,0,0]},{index:.3,rgb:[230,0,0]},{index:.6,rgb:[255,210,0]},{index:1,rgb:[255,255,255]}],spring:[{index:0,rgb:[255,0,255]},{index:1,rgb:[255,255,0]}],summer:[{index:0,rgb:[0,128,102]},{index:1,rgb:[255,255,102]}],autumn:[{index:0,rgb:[255,0,0]},{index:1,rgb:[255,255,0]}],winter:[{index:0,rgb:[0,0,255]},{index:1,rgb:[0,255,128]}],bone:[{index:0,rgb:[0,0,0]},{index:.376,rgb:[84,84,116]},{index:.753,rgb:[169,200,200]},{index:1,rgb:[255,255,255]}],copper:[{index:0,rgb:[0,0,0]},{index:.804,rgb:[255,160,102]},{index:1,rgb:[255,199,127]}],greys:[{index:0,rgb:[0,0,0]},{index:1,rgb:[255,255,255]}],yignbu:[{index:0,rgb:[8,29,88]},{index:.125,rgb:[37,52,148]},{index:.25,rgb:[34,94,168]},{index:.375,rgb:[29,145,192]},{index:.5,rgb:[65,182,196]},{index:.625,rgb:[127,205,187]},{index:.75,rgb:[199,233,180]},{index:.875,rgb:[237,248,217]},{index:1,rgb:[255,255,217]}],greens:[{index:0,rgb:[0,68,27]},{index:.125,rgb:[0,109,44]},{index:.25,rgb:[35,139,69]},{index:.375,rgb:[65,171,93]},{index:.5,rgb:[116,196,118]},{index:.625,rgb:[161,217,155]},{index:.75,rgb:[199,233,192]},{index:.875,rgb:[229,245,224]},{index:1,rgb:[247,252,245]}],yiorrd:[{index:0,rgb:[128,0,38]},{index:.125,rgb:[189,0,38]},{index:.25,rgb:[227,26,28]},{index:.375,rgb:[252,78,42]},{index:.5,rgb:[253,141,60]},{index:.625,rgb:[254,178,76]},{index:.75,rgb:[254,217,118]},{index:.875,rgb:[255,237,160]},{index:1,rgb:[255,255,204]}],bluered:[{index:0,rgb:[0,0,255]},{index:1,rgb:[255,0,0]}],rdbu:[{index:0,rgb:[5,10,172]},{index:.35,rgb:[106,137,247]},{index:.5,rgb:[190,190,190]},{index:.6,rgb:[220,170,132]},{index:.7,rgb:[230,145,90]},{index:1,rgb:[178,10,28]}],picnic:[{index:0,rgb:[0,0,255]},{index:.1,rgb:[51,153,255]},{index:.2,rgb:[102,204,255]},{index:.3,rgb:[153,204,255]},{index:.4,rgb:[204,204,255]},{index:.5,rgb:[255,255,255]},{index:.6,rgb:[255,204,255]},{index:.7,rgb:[255,153,255]},{index:.8,rgb:[255,102,204]},{index:.9,rgb:[255,102,102]},{index:1,rgb:[255,0,0]}],rainbow:[{index:0,rgb:[150,0,90]},{index:.125,rgb:[0,0,200]},{index:.25,rgb:[0,25,255]},{index:.375,rgb:[0,152,255]},{index:.5,rgb:[44,255,150]},{index:.625,rgb:[151,255,0]},{index:.75,rgb:[255,234,0]},{index:.875,rgb:[255,111,0]},{index:1,rgb:[255,0,0]}],portland:[{index:0,rgb:[12,51,131]},{index:.25,rgb:[10,136,186]},{index:.5,rgb:[242,211,56]},{index:.75,rgb:[242,143,56]},{index:1,rgb:[217,30,30]}],blackbody:[{index:0,rgb:[0,0,0]},{index:.2,rgb:[230,0,0]},{index:.4,rgb:[230,210,0]},{index:.7,rgb:[255,255,255]},{index:1,rgb:[160,200,255]}],earth:[{index:0,rgb:[0,0,130]},{index:.1,rgb:[0,180,180]},{index:.2,rgb:[40,210,40]},{index:.4,rgb:[230,230,50]},{index:.6,rgb:[120,70,20]},{index:1,rgb:[255,255,255]}],electric:[{index:0,rgb:[0,0,0]},{index:.15,rgb:[30,0,100]},{index:.4,rgb:[120,0,100]},{index:.6,rgb:[160,90,0]},{index:.8,rgb:[230,200,0]},{index:1,rgb:[255,250,220]}],alpha:[{index:0,rgb:[255,255,255,0]},{index:1,rgb:[255,255,255,1]}],viridis:[{index:0,rgb:[68,1,84]},{index:.13,rgb:[71,44,122]},{index:.25,rgb:[59,81,139]},{index:.38,rgb:[44,113,142]},{index:.5,rgb:[33,144,141]},{index:.63,rgb:[39,173,129]},{index:.75,rgb:[92,200,99]},{index:.88,rgb:[170,220,50]},{index:1,rgb:[253,231,37]}],inferno:[{index:0,rgb:[0,0,4]},{index:.13,rgb:[31,12,72]},{index:.25,rgb:[85,15,109]},{index:.38,rgb:[136,34,106]},{index:.5,rgb:[186,54,85]},{index:.63,rgb:[227,89,51]},{index:.75,rgb:[249,140,10]},{index:.88,rgb:[249,201,50]},{index:1,rgb:[252,255,164]}],magma:[{index:0,rgb:[0,0,4]},{index:.13,rgb:[28,16,68]},{index:.25,rgb:[79,18,123]},{index:.38,rgb:[129,37,129]},{index:.5,rgb:[181,54,122]},{index:.63,rgb:[229,80,100]},{index:.75,rgb:[251,135,97]},{index:.88,rgb:[254,194,135]},{index:1,rgb:[252,253,191]}],plasma:[{index:0,rgb:[13,8,135]},{index:.13,rgb:[75,3,161]},{index:.25,rgb:[125,3,168]},{index:.38,rgb:[168,34,150]},{index:.5,rgb:[203,70,121]},{index:.63,rgb:[229,107,93]},{index:.75,rgb:[248,148,65]},{index:.88,rgb:[253,195,40]},{index:1,rgb:[240,249,33]}],warm:[{index:0,rgb:[125,0,179]},{index:.13,rgb:[172,0,187]},{index:.25,rgb:[219,0,170]},{index:.38,rgb:[255,0,130]},{index:.5,rgb:[255,63,74]},{index:.63,rgb:[255,123,0]},{index:.75,rgb:[234,176,0]},{index:.88,rgb:[190,228,0]},{index:1,rgb:[147,255,0]}],cool:[{index:0,rgb:[125,0,179]},{index:.13,rgb:[116,0,218]},{index:.25,rgb:[98,74,237]},{index:.38,rgb:[68,146,231]},{index:.5,rgb:[0,204,197]},{index:.63,rgb:[0,247,146]},{index:.75,rgb:[0,255,88]},{index:.88,rgb:[40,255,8]},{index:1,rgb:[147,255,0]}],"rainbow-soft":[{index:0,rgb:[125,0,179]},{index:.1,rgb:[199,0,180]},{index:.2,rgb:[255,0,121]},{index:.3,rgb:[255,108,0]},{index:.4,rgb:[222,194,0]},{index:.5,rgb:[150,255,0]},{index:.6,rgb:[0,255,55]},{index:.7,rgb:[0,246,150]},{index:.8,rgb:[50,167,222]},{index:.9,rgb:[103,51,235]},{index:1,rgb:[124,0,186]}],bathymetry:[{index:0,rgb:[40,26,44]},{index:.13,rgb:[59,49,90]},{index:.25,rgb:[64,76,139]},{index:.38,rgb:[63,110,151]},{index:.5,rgb:[72,142,158]},{index:.63,rgb:[85,174,163]},{index:.75,rgb:[120,206,163]},{index:.88,rgb:[187,230,172]},{index:1,rgb:[253,254,204]}],cdom:[{index:0,rgb:[47,15,62]},{index:.13,rgb:[87,23,86]},{index:.25,rgb:[130,28,99]},{index:.38,rgb:[171,41,96]},{index:.5,rgb:[206,67,86]},{index:.63,rgb:[230,106,84]},{index:.75,rgb:[242,149,103]},{index:.88,rgb:[249,193,135]},{index:1,rgb:[254,237,176]}],chlorophyll:[{index:0,rgb:[18,36,20]},{index:.13,rgb:[25,63,41]},{index:.25,rgb:[24,91,59]},{index:.38,rgb:[13,119,72]},{index:.5,rgb:[18,148,80]},{index:.63,rgb:[80,173,89]},{index:.75,rgb:[132,196,122]},{index:.88,rgb:[175,221,162]},{index:1,rgb:[215,249,208]}],density:[{index:0,rgb:[54,14,36]},{index:.13,rgb:[89,23,80]},{index:.25,rgb:[110,45,132]},{index:.38,rgb:[120,77,178]},{index:.5,rgb:[120,113,213]},{index:.63,rgb:[115,151,228]},{index:.75,rgb:[134,185,227]},{index:.88,rgb:[177,214,227]},{index:1,rgb:[230,241,241]}],"freesurface-blue":[{index:0,rgb:[30,4,110]},{index:.13,rgb:[47,14,176]},{index:.25,rgb:[41,45,236]},{index:.38,rgb:[25,99,212]},{index:.5,rgb:[68,131,200]},{index:.63,rgb:[114,156,197]},{index:.75,rgb:[157,181,203]},{index:.88,rgb:[200,208,216]},{index:1,rgb:[241,237,236]}],"freesurface-red":[{index:0,rgb:[60,9,18]},{index:.13,rgb:[100,17,27]},{index:.25,rgb:[142,20,29]},{index:.38,rgb:[177,43,27]},{index:.5,rgb:[192,87,63]},{index:.63,rgb:[205,125,105]},{index:.75,rgb:[216,162,148]},{index:.88,rgb:[227,199,193]},{index:1,rgb:[241,237,236]}],oxygen:[{index:0,rgb:[64,5,5]},{index:.13,rgb:[106,6,15]},{index:.25,rgb:[144,26,7]},{index:.38,rgb:[168,64,3]},{index:.5,rgb:[188,100,4]},{index:.63,rgb:[206,136,11]},{index:.75,rgb:[220,174,25]},{index:.88,rgb:[231,215,44]},{index:1,rgb:[248,254,105]}],par:[{index:0,rgb:[51,20,24]},{index:.13,rgb:[90,32,35]},{index:.25,rgb:[129,44,34]},{index:.38,rgb:[159,68,25]},{index:.5,rgb:[182,99,19]},{index:.63,rgb:[199,134,22]},{index:.75,rgb:[212,171,35]},{index:.88,rgb:[221,210,54]},{index:1,rgb:[225,253,75]}],phase:[{index:0,rgb:[145,105,18]},{index:.13,rgb:[184,71,38]},{index:.25,rgb:[186,58,115]},{index:.38,rgb:[160,71,185]},{index:.5,rgb:[110,97,218]},{index:.63,rgb:[50,123,164]},{index:.75,rgb:[31,131,110]},{index:.88,rgb:[77,129,34]},{index:1,rgb:[145,105,18]}],salinity:[{index:0,rgb:[42,24,108]},{index:.13,rgb:[33,50,162]},{index:.25,rgb:[15,90,145]},{index:.38,rgb:[40,118,137]},{index:.5,rgb:[59,146,135]},{index:.63,rgb:[79,175,126]},{index:.75,rgb:[120,203,104]},{index:.88,rgb:[193,221,100]},{index:1,rgb:[253,239,154]}],temperature:[{index:0,rgb:[4,35,51]},{index:.13,rgb:[23,51,122]},{index:.25,rgb:[85,59,157]},{index:.38,rgb:[129,79,143]},{index:.5,rgb:[175,95,130]},{index:.63,rgb:[222,112,101]},{index:.75,rgb:[249,146,66]},{index:.88,rgb:[249,196,65]},{index:1,rgb:[232,250,91]}],turbidity:[{index:0,rgb:[34,31,27]},{index:.13,rgb:[65,50,41]},{index:.25,rgb:[98,69,52]},{index:.38,rgb:[131,89,57]},{index:.5,rgb:[161,112,59]},{index:.63,rgb:[185,140,66]},{index:.75,rgb:[202,174,88]},{index:.88,rgb:[216,209,126]},{index:1,rgb:[233,246,171]}],"velocity-blue":[{index:0,rgb:[17,32,64]},{index:.13,rgb:[35,52,116]},{index:.25,rgb:[29,81,156]},{index:.38,rgb:[31,113,162]},{index:.5,rgb:[50,144,169]},{index:.63,rgb:[87,173,176]},{index:.75,rgb:[149,196,189]},{index:.88,rgb:[203,221,211]},{index:1,rgb:[254,251,230]}],"velocity-green":[{index:0,rgb:[23,35,19]},{index:.13,rgb:[24,64,38]},{index:.25,rgb:[11,95,45]},{index:.38,rgb:[39,123,35]},{index:.5,rgb:[95,146,12]},{index:.63,rgb:[152,165,18]},{index:.75,rgb:[201,186,69]},{index:.88,rgb:[233,216,137]},{index:1,rgb:[255,253,205]}],cubehelix:[{index:0,rgb:[0,0,0]},{index:.07,rgb:[22,5,59]},{index:.13,rgb:[60,4,105]},{index:.2,rgb:[109,1,135]},{index:.27,rgb:[161,0,147]},{index:.33,rgb:[210,2,142]},{index:.4,rgb:[251,11,123]},{index:.47,rgb:[255,29,97]},{index:.53,rgb:[255,54,69]},{index:.6,rgb:[255,85,46]},{index:.67,rgb:[255,120,34]},{index:.73,rgb:[255,157,37]},{index:.8,rgb:[241,191,57]},{index:.87,rgb:[224,220,93]},{index:.93,rgb:[218,241,142]},{index:1,rgb:[227,253,198]}]}},{}],53:[function(t,e,r){"use strict";var n=t("./colorScale"),i=t("lerp");function a(t){return[t[0]/255,t[1]/255,t[2]/255,t[3]]}function o(t){for(var e,r="#",n=0;n<3;++n)r+=("00"+(e=(e=t[n]).toString(16))).substr(e.length);return r}function s(t){return"rgba("+t.join(",")+")"}e.exports=function(t){var e,r,l,c,u,f,h,p,d,m;t||(t={});p=(t.nshades||72)-1,h=t.format||"hex",(f=t.colormap)||(f="jet");if("string"==typeof f){if(f=f.toLowerCase(),!n[f])throw Error(f+" not a supported colorscale");u=n[f]}else{if(!Array.isArray(f))throw Error("unsupported colormap option",f);u=f.slice()}if(u.length>p+1)throw new Error(f+" map requires nshades to be at least size "+u.length);d=Array.isArray(t.alpha)?2!==t.alpha.length?[1,1]:t.alpha.slice():"number"==typeof t.alpha?[t.alpha,t.alpha]:[1,1];e=u.map((function(t){return Math.round(t.index*p)})),d[0]=Math.min(Math.max(d[0],0),1),d[1]=Math.min(Math.max(d[1],0),1);var g=u.map((function(t,e){var r=u[e].index,n=u[e].rgb.slice();return 4===n.length&&n[3]>=0&&n[3]<=1||(n[3]=d[0]+(d[1]-d[0])*r),n})),v=[];for(m=0;m<e.length-1;++m){c=e[m+1]-e[m],r=g[m],l=g[m+1];for(var y=0;y<c;y++){var x=y/c;v.push([Math.round(i(r[0],l[0],x)),Math.round(i(r[1],l[1],x)),Math.round(i(r[2],l[2],x)),i(r[3],l[3],x)])}}v.push(u[u.length-1].rgb.concat(d[1])),"hex"===h?v=v.map(o):"rgbaString"===h?v=v.map(s):"float"===h&&(v=v.map(a));return v}},{"./colorScale":52,lerp:240}],54:[function(t,e,r){"use strict";e.exports=function(t,e,r,a){var o=n(e,r,a);if(0===o){var s=i(n(t,e,r)),c=i(n(t,e,a));if(s===c){if(0===s){var u=l(t,e,r),f=l(t,e,a);return u===f?0:u?1:-1}return 0}return 0===c?s>0||l(t,e,a)?-1:1:0===s?c>0||l(t,e,r)?1:-1:i(c-s)}var h=n(t,e,r);return h>0?o>0&&n(t,e,a)>0?1:-1:h<0?o>0||n(t,e,a)>0?1:-1:n(t,e,a)>0||l(t,e,r)?1:-1};var n=t("robust-orientation"),i=t("signum"),a=t("two-sum"),o=t("robust-product"),s=t("robust-sum");function l(t,e,r){var n=a(t[0],-e[0]),i=a(t[1],-e[1]),l=a(r[0],-e[0]),c=a(r[1],-e[1]),u=s(o(n,l),o(i,c));return u[u.length-1]>=0}},{"robust-orientation":284,"robust-product":285,"robust-sum":289,signum:55,"two-sum":307}],55:[function(t,e,r){"use strict";e.exports=function(t){return t<0?-1:t>0?1:0}},{}],56:[function(t,e,r){e.exports=function(t,e){var r=t.length,a=t.length-e.length;if(a)return a;switch(r){case 0:return 0;case 1:return t[0]-e[0];case 2:return t[0]+t[1]-e[0]-e[1]||n(t[0],t[1])-n(e[0],e[1]);case 3:var o=t[0]+t[1],s=e[0]+e[1];if(a=o+t[2]-(s+e[2]))return a;var l=n(t[0],t[1]),c=n(e[0],e[1]);return n(l,t[2])-n(c,e[2])||n(l+t[2],o)-n(c+e[2],s);case 4:var u=t[0],f=t[1],h=t[2],p=t[3],d=e[0],m=e[1],g=e[2],v=e[3];return u+f+h+p-(d+m+g+v)||n(u,f,h,p)-n(d,m,g,v,d)||n(u+f,u+h,u+p,f+h,f+p,h+p)-n(d+m,d+g,d+v,m+g,m+v,g+v)||n(u+f+h,u+f+p,u+h+p,f+h+p)-n(d+m+g,d+m+v,d+g+v,m+g+v);default:for(var y=t.slice().sort(i),x=e.slice().sort(i),b=0;b<r;++b)if(a=y[b]-x[b])return a;return 0}};var n=Math.min;function i(t,e){return t-e}},{}],57:[function(t,e,r){"use strict";var n=t("compare-cell"),i=t("cell-orientation");e.exports=function(t,e){return n(t,e)||i(t)-i(e)}},{"cell-orientation":47,"compare-cell":56}],58:[function(t,e,r){"use strict";var n=t("./lib/ch1d"),i=t("./lib/ch2d"),a=t("./lib/chnd");e.exports=function(t){var e=t.length;if(0===e)return[];if(1===e)return[[0]];var r=t[0].length;if(0===r)return[];if(1===r)return n(t);if(2===r)return i(t);return a(t,r)}},{"./lib/ch1d":59,"./lib/ch2d":60,"./lib/chnd":61}],59:[function(t,e,r){"use strict";e.exports=function(t){for(var e=0,r=0,n=1;n<t.length;++n)t[n][0]<t[e][0]&&(e=n),t[n][0]>t[r][0]&&(r=n);return e<r?[[e],[r]]:e>r?[[r],[e]]:[[e]]}},{}],60:[function(t,e,r){"use strict";e.exports=function(t){var e=n(t),r=e.length;if(r<=2)return[];for(var i=new Array(r),a=e[r-1],o=0;o<r;++o){var s=e[o];i[o]=[a,s],a=s}return i};var n=t("monotone-convex-hull-2d")},{"monotone-convex-hull-2d":246}],61:[function(t,e,r){"use strict";e.exports=function(t,e){try{return n(t,!0)}catch(o){var r=i(t);if(r.length<=e)return[];var a=function(t,e){for(var r=t.length,n=new Array(r),i=0;i<e.length;++i)n[i]=t[e[i]];var a=e.length;for(i=0;i<r;++i)e.indexOf(i)<0&&(n[a++]=t[i]);return n}(t,r);return function(t,e){for(var r=t.length,n=e.length,i=0;i<r;++i)for(var a=t[i],o=0;o<a.length;++o){var s=a[o];if(s<n)a[o]=e[s];else{s-=n;for(var l=0;l<n;++l)s>=e[l]&&(s+=1);a[o]=s}}return t}(n(a,!0),r)}};var n=t("incremental-convex-hull"),i=t("affine-hull")},{"affine-hull":10,"incremental-convex-hull":233}],62:[function(t,e,r){"use strict";e.exports=function(t,e,r,n,i,a){var o=i-1,s=i*i,l=o*o,c=(1+2*i)*l,u=i*l,f=s*(3-2*i),h=s*o;if(t.length){a||(a=new Array(t.length));for(var p=t.length-1;p>=0;--p)a[p]=c*t[p]+u*e[p]+f*r[p]+h*n[p];return a}return c*t+u*e+f*r+h*n},e.exports.derivative=function(t,e,r,n,i,a){var o=6*i*i-6*i,s=3*i*i-4*i+1,l=-6*i*i+6*i,c=3*i*i-2*i;if(t.length){a||(a=new Array(t.length));for(var u=t.length-1;u>=0;--u)a[u]=o*t[u]+s*e[u]+l*r[u]+c*n[u];return a}return o*t+s*e+l*r[u]+c*n}},{}],63:[function(t,e,r){"use strict";var n=t("incremental-convex-hull"),i=t("uniq");function a(t,e){this.point=t,this.index=e}function o(t,e){for(var r=t.point,n=e.point,i=r.length,a=0;a<i;++a){var o=n[a]-r[a];if(o)return o}return 0}e.exports=function(t,e){var r=t.length;if(0===r)return[];var s=t[0].length;if(s<1)return[];if(1===s)return function(t,e,r){if(1===t)return r?[[-1,0]]:[];var n=e.map((function(t,e){return[t[0],e]}));n.sort((function(t,e){return t[0]-e[0]}));for(var i=new Array(t-1),a=1;a<t;++a){var o=n[a-1],s=n[a];i[a-1]=[o[1],s[1]]}r&&i.push([-1,i[0][1]],[i[t-1][1],-1]);return i}(r,t,e);for(var l=new Array(r),c=1,u=0;u<r;++u){for(var f=t[u],h=new Array(s+1),p=0,d=0;d<s;++d){var m=f[d];h[d]=m,p+=m*m}h[s]=p,l[u]=new a(h,u),c=Math.max(p,c)}i(l,o),r=l.length;var g=new Array(r+s+1),v=new Array(r+s+1),y=(s+1)*(s+1)*c,x=new Array(s+1);for(u=0;u<=s;++u)x[u]=0;x[s]=y,g[0]=x.slice(),v[0]=-1;for(u=0;u<=s;++u){(h=x.slice())[u]=1,g[u+1]=h,v[u+1]=-1}for(u=0;u<r;++u){var b=l[u];g[u+s+1]=b.point,v[u+s+1]=b.index}var _=n(g,!1);_=e?_.filter((function(t){for(var e=0,r=0;r<=s;++r){var n=v[t[r]];if(n<0&&++e>=2)return!1;t[r]=n}return!0})):_.filter((function(t){for(var e=0;e<=s;++e){var r=v[t[e]];if(r<0)return!1;t[e]=r}return!0}));if(1&s)for(u=0;u<_.length;++u){h=(b=_[u])[0];b[0]=b[1],b[1]=h}return _}},{"incremental-convex-hull":233,uniq:310}],64:[function(t,e,r){(function(t){(function(){var r=!1;if("undefined"!=typeof Float64Array){var n=new Float64Array(1),i=new Uint32Array(n.buffer);if(n[0]=1,r=!0,1072693248===i[1]){e.exports=function(t){return n[0]=t,[i[0],i[1]]},e.exports.pack=function(t,e){return i[0]=t,i[1]=e,n[0]},e.exports.lo=function(t){return n[0]=t,i[0]},e.exports.hi=function(t){return n[0]=t,i[1]}}else if(1072693248===i[0]){e.exports=function(t){return n[0]=t,[i[1],i[0]]},e.exports.pack=function(t,e){return i[1]=t,i[0]=e,n[0]},e.exports.lo=function(t){return n[0]=t,i[1]},e.exports.hi=function(t){return n[0]=t,i[0]}}else r=!1}if(!r){var a=new t(8);e.exports=function(t){return a.writeDoubleLE(t,0,!0),[a.readUInt32LE(0,!0),a.readUInt32LE(4,!0)]},e.exports.pack=function(t,e){return a.writeUInt32LE(t,0,!0),a.writeUInt32LE(e,4,!0),a.readDoubleLE(0,!0)},e.exports.lo=function(t){return a.writeDoubleLE(t,0,!0),a.readUInt32LE(0,!0)},e.exports.hi=function(t){return a.writeDoubleLE(t,0,!0),a.readUInt32LE(4,!0)}}e.exports.sign=function(t){return e.exports.hi(t)>>>31},e.exports.exponent=function(t){return(e.exports.hi(t)<<1>>>21)-1023},e.exports.fraction=function(t){var r=e.exports.lo(t),n=e.exports.hi(t),i=1048575&n;return 2146435072&n&&(i+=1<<20),[r,i]},e.exports.denormalized=function(t){return!(2146435072&e.exports.hi(t))}}).call(this)}).call(this,t("buffer").Buffer)},{buffer:3}],65:[function(t,e,r){"use strict";e.exports=function(t,e){switch(void 0===e&&(e=0),typeof t){case"number":if(t>0)return function(t,e){var r,n;for(r=new Array(t),n=0;n<t;++n)r[n]=e;return r}(0|t,e);break;case"object":if("number"==typeof t.length)return function t(e,r,n){var i=0|e[n];if(i<=0)return[];var a,o=new Array(i);if(n===e.length-1)for(a=0;a<i;++a)o[a]=r;else for(a=0;a<i;++a)o[a]=t(e,r,n+1);return o}(t,e,0)}return[]}},{}],66:[function(t,e,r){"use strict";e.exports=function(t,e){var r=t.length;if("number"!=typeof e){e=0;for(var i=0;i<r;++i){var a=t[i];e=Math.max(e,a[0],a[1])}e=1+(0|e)}e|=0;var o=new Array(e);for(i=0;i<e;++i)o[i]=[];for(i=0;i<r;++i){a=t[i];o[a[0]].push(a[1]),o[a[1]].push(a[0])}for(var s=0;s<e;++s)n(o[s],(function(t,e){return t-e}));return o};var n=t("uniq")},{uniq:310}],67:[function(t,e,r){"use strict";e.exports=function(t,e,r){var n=e||0,i=r||1;return[[t[12]+t[0],t[13]+t[1],t[14]+t[2],t[15]+t[3]],[t[12]-t[0],t[13]-t[1],t[14]-t[2],t[15]-t[3]],[t[12]+t[4],t[13]+t[5],t[14]+t[6],t[15]+t[7]],[t[12]-t[4],t[13]-t[5],t[14]-t[6],t[15]-t[7]],[n*t[12]+t[8],n*t[13]+t[9],n*t[14]+t[10],n*t[15]+t[11]],[i*t[12]-t[8],i*t[13]-t[9],i*t[14]-t[10],i*t[15]-t[11]]]}},{}],68:[function(t,e,r){"use strict";e.exports=function(t,e,r){switch(arguments.length){case 0:return new o([0],[0],0);case 1:return"number"==typeof t?new o(n=l(t),n,0):new o(t,l(t.length),0);case 2:if("number"==typeof e){var n=l(t.length);return new o(t,n,+e)}r=0;case 3:if(t.length!==e.length)throw new Error("state and velocity lengths must match");return new o(t,e,r)}};var n=t("cubic-hermite"),i=t("binary-search-bounds");function a(t,e,r){return Math.min(e,Math.max(t,r))}function o(t,e,r){this.dimension=t.length,this.bounds=[new Array(this.dimension),new Array(this.dimension)];for(var n=0;n<this.dimension;++n)this.bounds[0][n]=-1/0,this.bounds[1][n]=1/0;this._state=t.slice().reverse(),this._velocity=e.slice().reverse(),this._time=[r],this._scratch=[t.slice(),t.slice(),t.slice(),t.slice(),t.slice()]}var s=o.prototype;function l(t){for(var e=new Array(t),r=0;r<t;++r)e[r]=0;return e}s.flush=function(t){var e=i.gt(this._time,t)-1;e<=0||(this._time.splice(0,e),this._state.splice(0,e*this.dimension),this._velocity.splice(0,e*this.dimension))},s.curve=function(t){var e=this._time,r=e.length,o=i.le(e,t),s=this._scratch[0],l=this._state,c=this._velocity,u=this.dimension,f=this.bounds;if(o<0)for(var h=u-1,p=0;p<u;++p,--h)s[p]=l[h];else if(o>=r-1){h=l.length-1;var d=t-e[r-1];for(p=0;p<u;++p,--h)s[p]=l[h]+d*c[h]}else{h=u*(o+1)-1;var m=e[o],g=e[o+1]-m||1,v=this._scratch[1],y=this._scratch[2],x=this._scratch[3],b=this._scratch[4],_=!0;for(p=0;p<u;++p,--h)v[p]=l[h],x[p]=c[h]*g,y[p]=l[h+u],b[p]=c[h+u]*g,_=_&&v[p]===y[p]&&x[p]===b[p]&&0===x[p];if(_)for(p=0;p<u;++p)s[p]=v[p];else n(v,x,y,b,(t-m)/g,s)}var w=f[0],T=f[1];for(p=0;p<u;++p)s[p]=a(w[p],T[p],s[p]);return s},s.dcurve=function(t){var e=this._time,r=e.length,a=i.le(e,t),o=this._scratch[0],s=this._state,l=this._velocity,c=this.dimension;if(a>=r-1)for(var u=s.length-1,f=(e[r-1],0);f<c;++f,--u)o[f]=l[u];else{u=c*(a+1)-1;var h=e[a],p=e[a+1]-h||1,d=this._scratch[1],m=this._scratch[2],g=this._scratch[3],v=this._scratch[4],y=!0;for(f=0;f<c;++f,--u)d[f]=s[u],g[f]=l[u]*p,m[f]=s[u+c],v[f]=l[u+c]*p,y=y&&d[f]===m[f]&&g[f]===v[f]&&0===g[f];if(y)for(f=0;f<c;++f)o[f]=0;else{n.derivative(d,g,m,v,(t-h)/p,o);for(f=0;f<c;++f)o[f]/=p}}return o},s.lastT=function(){var t=this._time;return t[t.length-1]},s.stable=function(){for(var t=this._velocity,e=t.length,r=this.dimension-1;r>=0;--r)if(t[--e])return!1;return!0},s.jump=function(t){var e=this.lastT(),r=this.dimension;if(!(t<e||arguments.length!==r+1)){var n=this._state,i=this._velocity,o=n.length-this.dimension,s=this.bounds,l=s[0],c=s[1];this._time.push(e,t);for(var u=0;u<2;++u)for(var f=0;f<r;++f)n.push(n[o++]),i.push(0);this._time.push(t);for(f=r;f>0;--f)n.push(a(l[f-1],c[f-1],arguments[f])),i.push(0)}},s.push=function(t){var e=this.lastT(),r=this.dimension;if(!(t<e||arguments.length!==r+1)){var n=this._state,i=this._velocity,o=n.length-this.dimension,s=t-e,l=this.bounds,c=l[0],u=l[1],f=s>1e-6?1/s:0;this._time.push(t);for(var h=r;h>0;--h){var p=a(c[h-1],u[h-1],arguments[h]);n.push(p),i.push((p-n[o++])*f)}}},s.set=function(t){var e=this.dimension;if(!(t<this.lastT()||arguments.length!==e+1)){var r=this._state,n=this._velocity,i=this.bounds,o=i[0],s=i[1];this._time.push(t);for(var l=e;l>0;--l)r.push(a(o[l-1],s[l-1],arguments[l])),n.push(0)}},s.move=function(t){var e=this.lastT(),r=this.dimension;if(!(t<=e||arguments.length!==r+1)){var n=this._state,i=this._velocity,o=n.length-this.dimension,s=this.bounds,l=s[0],c=s[1],u=t-e,f=u>1e-6?1/u:0;this._time.push(t);for(var h=r;h>0;--h){var p=arguments[h];n.push(a(l[h-1],c[h-1],n[o++]+p)),i.push(p*f)}}},s.idle=function(t){var e=this.lastT();if(!(t<e)){var r=this.dimension,n=this._state,i=this._velocity,o=n.length-r,s=this.bounds,l=s[0],c=s[1],u=t-e;this._time.push(t);for(var f=r-1;f>=0;--f)n.push(a(l[f],c[f],n[o]+u*i[o])),i.push(0),o+=1}}},{"binary-search-bounds":31,"cubic-hermite":62}],69:[function(t,e,r){"use strict";e.exports=function(t){return new s(t||m,null)};function n(t,e,r,n,i,a){this._color=t,this.key=e,this.value=r,this.left=n,this.right=i,this._count=a}function i(t){return new n(t._color,t.key,t.value,t.left,t.right,t._count)}function a(t,e){return new n(t,e.key,e.value,e.left,e.right,e._count)}function o(t){t._count=1+(t.left?t.left._count:0)+(t.right?t.right._count:0)}function s(t,e){this._compare=t,this.root=e}var l=s.prototype;function c(t,e){var r;if(e.left&&(r=c(t,e.left)))return r;return(r=t(e.key,e.value))||(e.right?c(t,e.right):void 0)}function u(t,e,r,n){if(e(t,n.key)<=0){var i;if(n.left)if(i=u(t,e,r,n.left))return i;if(i=r(n.key,n.value))return i}if(n.right)return u(t,e,r,n.right)}function f(t,e,r,n,i){var a,o=r(t,i.key),s=r(e,i.key);if(o<=0){if(i.left&&(a=f(t,e,r,n,i.left)))return a;if(s>0&&(a=n(i.key,i.value)))return a}if(s>0&&i.right)return f(t,e,r,n,i.right)}function h(t,e){this.tree=t,this._stack=e}Object.defineProperty(l,"keys",{get:function(){var t=[];return this.forEach((function(e,r){t.push(e)})),t}}),Object.defineProperty(l,"values",{get:function(){var t=[];return this.forEach((function(e,r){t.push(r)})),t}}),Object.defineProperty(l,"length",{get:function(){return this.root?this.root._count:0}}),l.insert=function(t,e){for(var r=this._compare,i=this.root,l=[],c=[];i;){var u=r(t,i.key);l.push(i),c.push(u),i=u<=0?i.left:i.right}l.push(new n(0,t,e,null,null,1));for(var f=l.length-2;f>=0;--f){i=l[f];c[f]<=0?l[f]=new n(i._color,i.key,i.value,l[f+1],i.right,i._count+1):l[f]=new n(i._color,i.key,i.value,i.left,l[f+1],i._count+1)}for(f=l.length-1;f>1;--f){var h=l[f-1];i=l[f];if(1===h._color||1===i._color)break;var p=l[f-2];if(p.left===h)if(h.left===i){if(!(d=p.right)||0!==d._color){if(p._color=0,p.left=h.right,h._color=1,h.right=p,l[f-2]=h,l[f-1]=i,o(p),o(h),f>=3)(m=l[f-3]).left===p?m.left=h:m.right=h;break}h._color=1,p.right=a(1,d),p._color=0,f-=1}else{if(!(d=p.right)||0!==d._color){if(h.right=i.left,p._color=0,p.left=i.right,i._color=1,i.left=h,i.right=p,l[f-2]=i,l[f-1]=h,o(p),o(h),o(i),f>=3)(m=l[f-3]).left===p?m.left=i:m.right=i;break}h._color=1,p.right=a(1,d),p._color=0,f-=1}else if(h.right===i){if(!(d=p.left)||0!==d._color){if(p._color=0,p.right=h.left,h._color=1,h.left=p,l[f-2]=h,l[f-1]=i,o(p),o(h),f>=3)(m=l[f-3]).right===p?m.right=h:m.left=h;break}h._color=1,p.left=a(1,d),p._color=0,f-=1}else{var d;if(!(d=p.left)||0!==d._color){var m;if(h.left=i.right,p._color=0,p.right=i.left,i._color=1,i.right=h,i.left=p,l[f-2]=i,l[f-1]=h,o(p),o(h),o(i),f>=3)(m=l[f-3]).right===p?m.right=i:m.left=i;break}h._color=1,p.left=a(1,d),p._color=0,f-=1}}return l[0]._color=1,new s(r,l[0])},l.forEach=function(t,e,r){if(this.root)switch(arguments.length){case 1:return c(t,this.root);case 2:return u(e,this._compare,t,this.root);case 3:if(this._compare(e,r)>=0)return;return f(e,r,this._compare,t,this.root)}},Object.defineProperty(l,"begin",{get:function(){for(var t=[],e=this.root;e;)t.push(e),e=e.left;return new h(this,t)}}),Object.defineProperty(l,"end",{get:function(){for(var t=[],e=this.root;e;)t.push(e),e=e.right;return new h(this,t)}}),l.at=function(t){if(t<0)return new h(this,[]);for(var e=this.root,r=[];;){if(r.push(e),e.left){if(t<e.left._count){e=e.left;continue}t-=e.left._count}if(!t)return new h(this,r);if(t-=1,!e.right)break;if(t>=e.right._count)break;e=e.right}return new h(this,[])},l.ge=function(t){for(var e=this._compare,r=this.root,n=[],i=0;r;){var a=e(t,r.key);n.push(r),a<=0&&(i=n.length),r=a<=0?r.left:r.right}return n.length=i,new h(this,n)},l.gt=function(t){for(var e=this._compare,r=this.root,n=[],i=0;r;){var a=e(t,r.key);n.push(r),a<0&&(i=n.length),r=a<0?r.left:r.right}return n.length=i,new h(this,n)},l.lt=function(t){for(var e=this._compare,r=this.root,n=[],i=0;r;){var a=e(t,r.key);n.push(r),a>0&&(i=n.length),r=a<=0?r.left:r.right}return n.length=i,new h(this,n)},l.le=function(t){for(var e=this._compare,r=this.root,n=[],i=0;r;){var a=e(t,r.key);n.push(r),a>=0&&(i=n.length),r=a<0?r.left:r.right}return n.length=i,new h(this,n)},l.find=function(t){for(var e=this._compare,r=this.root,n=[];r;){var i=e(t,r.key);if(n.push(r),0===i)return new h(this,n);r=i<=0?r.left:r.right}return new h(this,[])},l.remove=function(t){var e=this.find(t);return e?e.remove():this},l.get=function(t){for(var e=this._compare,r=this.root;r;){var n=e(t,r.key);if(0===n)return r.value;r=n<=0?r.left:r.right}};var p=h.prototype;function d(t,e){t.key=e.key,t.value=e.value,t.left=e.left,t.right=e.right,t._color=e._color,t._count=e._count}function m(t,e){return t<e?-1:t>e?1:0}Object.defineProperty(p,"valid",{get:function(){return this._stack.length>0}}),Object.defineProperty(p,"node",{get:function(){return this._stack.length>0?this._stack[this._stack.length-1]:null},enumerable:!0}),p.clone=function(){return new h(this.tree,this._stack.slice())},p.remove=function(){var t=this._stack;if(0===t.length)return this.tree;var e=new Array(t.length),r=t[t.length-1];e[e.length-1]=new n(r._color,r.key,r.value,r.left,r.right,r._count);for(var l=t.length-2;l>=0;--l){(r=t[l]).left===t[l+1]?e[l]=new n(r._color,r.key,r.value,e[l+1],r.right,r._count):e[l]=new n(r._color,r.key,r.value,r.left,e[l+1],r._count)}if((r=e[e.length-1]).left&&r.right){var c=e.length;for(r=r.left;r.right;)e.push(r),r=r.right;var u=e[c-1];e.push(new n(r._color,u.key,u.value,r.left,r.right,r._count)),e[c-1].key=r.key,e[c-1].value=r.value;for(l=e.length-2;l>=c;--l)r=e[l],e[l]=new n(r._color,r.key,r.value,r.left,e[l+1],r._count);e[c-1].left=e[c]}if(0===(r=e[e.length-1])._color){var f=e[e.length-2];f.left===r?f.left=null:f.right===r&&(f.right=null),e.pop();for(l=0;l<e.length;++l)e[l]._count--;return new s(this.tree._compare,e[0])}if(r.left||r.right){r.left?d(r,r.left):r.right&&d(r,r.right),r._color=1;for(l=0;l<e.length-1;++l)e[l]._count--;return new s(this.tree._compare,e[0])}if(1===e.length)return new s(this.tree._compare,null);for(l=0;l<e.length;++l)e[l]._count--;var h=e[e.length-2];return function(t){for(var e,r,n,s,l=t.length-1;l>=0;--l){if(e=t[l],0===l)return void(e._color=1);if((r=t[l-1]).left===e){if((n=r.right).right&&0===n.right._color){if(s=(n=r.right=i(n)).right=i(n.right),r.right=n.left,n.left=r,n.right=s,n._color=r._color,e._color=1,r._color=1,s._color=1,o(r),o(n),l>1)(c=t[l-2]).left===r?c.left=n:c.right=n;return void(t[l-1]=n)}if(n.left&&0===n.left._color){if(s=(n=r.right=i(n)).left=i(n.left),r.right=s.left,n.left=s.right,s.left=r,s.right=n,s._color=r._color,r._color=1,n._color=1,e._color=1,o(r),o(n),o(s),l>1)(c=t[l-2]).left===r?c.left=s:c.right=s;return void(t[l-1]=s)}if(1===n._color){if(0===r._color)return r._color=1,void(r.right=a(0,n));r.right=a(0,n);continue}n=i(n),r.right=n.left,n.left=r,n._color=r._color,r._color=0,o(r),o(n),l>1&&((c=t[l-2]).left===r?c.left=n:c.right=n),t[l-1]=n,t[l]=r,l+1<t.length?t[l+1]=e:t.push(e),l+=2}else{if((n=r.left).left&&0===n.left._color){if(s=(n=r.left=i(n)).left=i(n.left),r.left=n.right,n.right=r,n.left=s,n._color=r._color,e._color=1,r._color=1,s._color=1,o(r),o(n),l>1)(c=t[l-2]).right===r?c.right=n:c.left=n;return void(t[l-1]=n)}if(n.right&&0===n.right._color){if(s=(n=r.left=i(n)).right=i(n.right),r.left=s.right,n.right=s.left,s.right=r,s.left=n,s._color=r._color,r._color=1,n._color=1,e._color=1,o(r),o(n),o(s),l>1)(c=t[l-2]).right===r?c.right=s:c.left=s;return void(t[l-1]=s)}if(1===n._color){if(0===r._color)return r._color=1,void(r.left=a(0,n));r.left=a(0,n);continue}var c;n=i(n),r.left=n.right,n.right=r,n._color=r._color,r._color=0,o(r),o(n),l>1&&((c=t[l-2]).right===r?c.right=n:c.left=n),t[l-1]=n,t[l]=r,l+1<t.length?t[l+1]=e:t.push(e),l+=2}}}(e),h.left===r?h.left=null:h.right=null,new s(this.tree._compare,e[0])},Object.defineProperty(p,"key",{get:function(){if(this._stack.length>0)return this._stack[this._stack.length-1].key},enumerable:!0}),Object.defineProperty(p,"value",{get:function(){if(this._stack.length>0)return this._stack[this._stack.length-1].value},enumerable:!0}),Object.defineProperty(p,"index",{get:function(){var t=0,e=this._stack;if(0===e.length){var r=this.tree.root;return r?r._count:0}e[e.length-1].left&&(t=e[e.length-1].left._count);for(var n=e.length-2;n>=0;--n)e[n+1]===e[n].right&&(++t,e[n].left&&(t+=e[n].left._count));return t},enumerable:!0}),p.next=function(){var t=this._stack;if(0!==t.length){var e=t[t.length-1];if(e.right)for(e=e.right;e;)t.push(e),e=e.left;else for(t.pop();t.length>0&&t[t.length-1].right===e;)e=t[t.length-1],t.pop()}},Object.defineProperty(p,"hasNext",{get:function(){var t=this._stack;if(0===t.length)return!1;if(t[t.length-1].right)return!0;for(var e=t.length-1;e>0;--e)if(t[e-1].left===t[e])return!0;return!1}}),p.update=function(t){var e=this._stack;if(0===e.length)throw new Error("Can't update empty node!");var r=new Array(e.length),i=e[e.length-1];r[r.length-1]=new n(i._color,i.key,t,i.left,i.right,i._count);for(var a=e.length-2;a>=0;--a)(i=e[a]).left===e[a+1]?r[a]=new n(i._color,i.key,i.value,r[a+1],i.right,i._count):r[a]=new n(i._color,i.key,i.value,i.left,r[a+1],i._count);return new s(this.tree._compare,r[0])},p.prev=function(){var t=this._stack;if(0!==t.length){var e=t[t.length-1];if(e.left)for(e=e.left;e;)t.push(e),e=e.right;else for(t.pop();t.length>0&&t[t.length-1].left===e;)e=t[t.length-1],t.pop()}},Object.defineProperty(p,"hasPrev",{get:function(){var t=this._stack;if(0===t.length)return!1;if(t[t.length-1].left)return!0;for(var e=t.length-1;e>0;--e)if(t[e-1].right===t[e])return!0;return!1}})},{}],70:[function(t,e,r){"use strict";e.exports=function(t,e){var r=new u(t);return r.update(e),r};var n=t("./lib/text.js"),i=t("./lib/lines.js"),a=t("./lib/background.js"),o=t("./lib/cube.js"),s=t("./lib/ticks.js"),l=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function c(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function u(t){this.gl=t,this.pixelRatio=1,this.bounds=[[-10,-10,-10],[10,10,10]],this.ticks=[[],[],[]],this.autoTicks=!0,this.tickSpacing=[1,1,1],this.tickEnable=[!0,!0,!0],this.tickFont=["sans-serif","sans-serif","sans-serif"],this.tickSize=[12,12,12],this.tickAngle=[0,0,0],this.tickAlign=["auto","auto","auto"],this.tickColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.tickPad=[10,10,10],this.lastCubeProps={cubeEdges:[0,0,0],axis:[0,0,0]},this.labels=["x","y","z"],this.labelEnable=[!0,!0,!0],this.labelFont="sans-serif",this.labelSize=[20,20,20],this.labelAngle=[0,0,0],this.labelAlign=["auto","auto","auto"],this.labelColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.labelPad=[10,10,10],this.lineEnable=[!0,!0,!0],this.lineMirror=[!1,!1,!1],this.lineWidth=[1,1,1],this.lineColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.lineTickEnable=[!0,!0,!0],this.lineTickMirror=[!1,!1,!1],this.lineTickLength=[0,0,0],this.lineTickWidth=[1,1,1],this.lineTickColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.gridEnable=[!0,!0,!0],this.gridWidth=[1,1,1],this.gridColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.zeroEnable=[!0,!0,!0],this.zeroLineColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.zeroLineWidth=[2,2,2],this.backgroundEnable=[!1,!1,!1],this.backgroundColor=[[.8,.8,.8,.5],[.8,.8,.8,.5],[.8,.8,.8,.5]],this._firstInit=!0,this._text=null,this._lines=null,this._background=a(t)}var f=u.prototype;function h(){this.primalOffset=[0,0,0],this.primalMinor=[0,0,0],this.mirrorOffset=[0,0,0],this.mirrorMinor=[0,0,0]}f.update=function(t){function e(e,r,n){if(n in t){var i,a=t[n],o=this[n];(e?Array.isArray(a)&&Array.isArray(a[0]):Array.isArray(a))?this[n]=i=[r(a[0]),r(a[1]),r(a[2])]:this[n]=i=[r(a),r(a),r(a)];for(var s=0;s<3;++s)if(i[s]!==o[s])return!0}return!1}t=t||{};var r,a=e.bind(this,!1,Number),o=e.bind(this,!1,Boolean),l=e.bind(this,!1,String),c=e.bind(this,!0,(function(t){if(Array.isArray(t)){if(3===t.length)return[+t[0],+t[1],+t[2],1];if(4===t.length)return[+t[0],+t[1],+t[2],+t[3]]}return[0,0,0,1]})),u=!1,f=!1;if("bounds"in t)for(var h=t.bounds,p=0;p<2;++p)for(var d=0;d<3;++d)h[p][d]!==this.bounds[p][d]&&(f=!0),this.bounds[p][d]=h[p][d];if("ticks"in t){r=t.ticks,u=!0,this.autoTicks=!1;for(p=0;p<3;++p)this.tickSpacing[p]=0}else a("tickSpacing")&&(this.autoTicks=!0,f=!0);if(this._firstInit&&("ticks"in t||"tickSpacing"in t||(this.autoTicks=!0),f=!0,u=!0,this._firstInit=!1),f&&this.autoTicks&&(r=s.create(this.bounds,this.tickSpacing),u=!0),u){for(p=0;p<3;++p)r[p].sort((function(t,e){return t.x-e.x}));s.equal(r,this.ticks)?u=!1:this.ticks=r}o("tickEnable"),l("tickFont")&&(u=!0),a("tickSize"),a("tickAngle"),a("tickPad"),c("tickColor");var m=l("labels");l("labelFont")&&(m=!0),o("labelEnable"),a("labelSize"),a("labelPad"),c("labelColor"),o("lineEnable"),o("lineMirror"),a("lineWidth"),c("lineColor"),o("lineTickEnable"),o("lineTickMirror"),a("lineTickLength"),a("lineTickWidth"),c("lineTickColor"),o("gridEnable"),a("gridWidth"),c("gridColor"),o("zeroEnable"),c("zeroLineColor"),a("zeroLineWidth"),o("backgroundEnable"),c("backgroundColor"),this._text?this._text&&(m||u)&&this._text.update(this.bounds,this.labels,this.labelFont,this.ticks,this.tickFont):this._text=n(this.gl,this.bounds,this.labels,this.labelFont,this.ticks,this.tickFont),this._lines&&u&&(this._lines.dispose(),this._lines=null),this._lines||(this._lines=i(this.gl,this.bounds,this.ticks))};var p=[new h,new h,new h];function d(t,e,r,n,i){for(var a=t.primalOffset,o=t.primalMinor,s=t.mirrorOffset,l=t.mirrorMinor,c=n[e],u=0;u<3;++u)if(e!==u){var f=a,h=s,p=o,d=l;c&1<<u&&(f=s,h=a,p=l,d=o),f[u]=r[0][u],h[u]=r[1][u],i[u]>0?(p[u]=-1,d[u]=0):(p[u]=0,d[u]=1)}}var m=[0,0,0],g={model:l,view:l,projection:l,_ortho:!1};f.isOpaque=function(){return!0},f.isTransparent=function(){return!1},f.drawTransparent=function(t){};var v=[0,0,0],y=[0,0,0],x=[0,0,0];f.draw=function(t){t=t||g;for(var e=this.gl,r=t.model||l,n=t.view||l,i=t.projection||l,a=this.bounds,s=t._ortho||!1,u=o(r,n,i,a,s),f=u.cubeEdges,h=u.axis,b=n[12],_=n[13],w=n[14],T=n[15],k=(s?2:1)*this.pixelRatio*(i[3]*b+i[7]*_+i[11]*w+i[15]*T)/e.drawingBufferHeight,A=0;A<3;++A)this.lastCubeProps.cubeEdges[A]=f[A],this.lastCubeProps.axis[A]=h[A];var M=p;for(A=0;A<3;++A)d(p[A],A,this.bounds,f,h);e=this.gl;var S,E=m;for(A=0;A<3;++A)this.backgroundEnable[A]?E[A]=h[A]:E[A]=0;this._background.draw(r,n,i,a,E,this.backgroundColor),this._lines.bind(r,n,i,this);for(A=0;A<3;++A){var L=[0,0,0];h[A]>0?L[A]=a[1][A]:L[A]=a[0][A];for(var C=0;C<2;++C){var P=(A+1+C)%3,I=(A+1+(1^C))%3;this.gridEnable[P]&&this._lines.drawGrid(P,I,this.bounds,L,this.gridColor[P],this.gridWidth[P]*this.pixelRatio)}for(C=0;C<2;++C){P=(A+1+C)%3,I=(A+1+(1^C))%3;this.zeroEnable[I]&&Math.min(a[0][I],a[1][I])<=0&&Math.max(a[0][I],a[1][I])>=0&&this._lines.drawZero(P,I,this.bounds,L,this.zeroLineColor[I],this.zeroLineWidth[I]*this.pixelRatio)}}for(A=0;A<3;++A){this.lineEnable[A]&&this._lines.drawAxisLine(A,this.bounds,M[A].primalOffset,this.lineColor[A],this.lineWidth[A]*this.pixelRatio),this.lineMirror[A]&&this._lines.drawAxisLine(A,this.bounds,M[A].mirrorOffset,this.lineColor[A],this.lineWidth[A]*this.pixelRatio);var O=c(v,M[A].primalMinor),z=c(y,M[A].mirrorMinor),D=this.lineTickLength;for(C=0;C<3;++C){var R=k/r[5*C];O[C]*=D[C]*R,z[C]*=D[C]*R}this.lineTickEnable[A]&&this._lines.drawAxisTicks(A,M[A].primalOffset,O,this.lineTickColor[A],this.lineTickWidth[A]*this.pixelRatio),this.lineTickMirror[A]&&this._lines.drawAxisTicks(A,M[A].mirrorOffset,z,this.lineTickColor[A],this.lineTickWidth[A]*this.pixelRatio)}this._lines.unbind(),this._text.bind(r,n,i,this.pixelRatio);var F,B;function N(t){(B=[0,0,0])[t]=1}function j(t,e,r){var n=(t+1)%3,i=(t+2)%3,a=e[n],o=e[i],s=r[n],l=r[i];a>0&&l>0||a>0&&l<0||a<0&&l>0||a<0&&l<0?N(n):(o>0&&s>0||o>0&&s<0||o<0&&s>0||o<0&&s<0)&&N(i)}for(A=0;A<3;++A){var U=M[A].primalMinor,V=M[A].mirrorMinor,H=c(x,M[A].primalOffset);for(C=0;C<3;++C)this.lineTickEnable[A]&&(H[C]+=k*U[C]*Math.max(this.lineTickLength[C],0)/r[5*C]);var q=[0,0,0];if(q[A]=1,this.tickEnable[A]){-3600===this.tickAngle[A]?(this.tickAngle[A]=0,this.tickAlign[A]="auto"):this.tickAlign[A]=-1,F=1,"auto"===(S=[this.tickAlign[A],.5,F])[0]?S[0]=0:S[0]=parseInt(""+S[0]),B=[0,0,0],j(A,U,V);for(C=0;C<3;++C)H[C]+=k*U[C]*this.tickPad[C]/r[5*C];this._text.drawTicks(A,this.tickSize[A],this.tickAngle[A],H,this.tickColor[A],q,B,S)}if(this.labelEnable[A]){F=0,B=[0,0,0],this.labels[A].length>4&&(N(A),F=1),"auto"===(S=[this.labelAlign[A],.5,F])[0]?S[0]=0:S[0]=parseInt(""+S[0]);for(C=0;C<3;++C)H[C]+=k*U[C]*this.labelPad[C]/r[5*C];H[A]+=.5*(a[0][A]+a[1][A]),this._text.drawLabel(A,this.labelSize[A],this.labelAngle[A],H,this.labelColor[A],[0,0,0],B,S)}}this._text.unbind()},f.dispose=function(){this._text.dispose(),this._lines.dispose(),this._background.dispose(),this._lines=null,this._text=null,this._background=null,this.gl=null}},{"./lib/background.js":71,"./lib/cube.js":72,"./lib/lines.js":73,"./lib/text.js":75,"./lib/ticks.js":76}],71:[function(t,e,r){"use strict";e.exports=function(t){for(var e=[],r=[],s=0,l=0;l<3;++l)for(var c=(l+1)%3,u=(l+2)%3,f=[0,0,0],h=[0,0,0],p=-1;p<=1;p+=2){r.push(s,s+2,s+1,s+1,s+2,s+3),f[l]=p,h[l]=p;for(var d=-1;d<=1;d+=2){f[c]=d;for(var m=-1;m<=1;m+=2)f[u]=m,e.push(f[0],f[1],f[2],h[0],h[1],h[2]),s+=1}var g=c;c=u,u=g}var v=n(t,new Float32Array(e)),y=n(t,new Uint16Array(r),t.ELEMENT_ARRAY_BUFFER),x=i(t,[{buffer:v,type:t.FLOAT,size:3,offset:0,stride:24},{buffer:v,type:t.FLOAT,size:3,offset:12,stride:24}],y),b=a(t);return b.attributes.position.location=0,b.attributes.normal.location=1,new o(t,v,x,b)};var n=t("gl-buffer"),i=t("gl-vao"),a=t("./shaders").bg;function o(t,e,r,n){this.gl=t,this.buffer=e,this.vao=r,this.shader=n}var s=o.prototype;s.draw=function(t,e,r,n,i,a){for(var o=!1,s=0;s<3;++s)o=o||i[s];if(o){var l=this.gl;l.enable(l.POLYGON_OFFSET_FILL),l.polygonOffset(1,2),this.shader.bind(),this.shader.uniforms={model:t,view:e,projection:r,bounds:n,enable:i,colors:a},this.vao.bind(),this.vao.draw(this.gl.TRIANGLES,36),this.vao.unbind(),l.disable(l.POLYGON_OFFSET_FILL)}},s.dispose=function(){this.vao.dispose(),this.buffer.dispose(),this.shader.dispose()}},{"./shaders":74,"gl-buffer":78,"gl-vao":150}],72:[function(t,e,r){"use strict";e.exports=function(t,e,r,a,p){i(s,e,t),i(s,r,s);for(var y=0,x=0;x<2;++x){u[2]=a[x][2];for(var b=0;b<2;++b){u[1]=a[b][1];for(var _=0;_<2;++_)u[0]=a[_][0],h(l[y],u,s),y+=1}}var w=-1;for(x=0;x<8;++x){for(var T=l[x][3],k=0;k<3;++k)c[x][k]=l[x][k]/T;p&&(c[x][2]*=-1),T<0&&(w<0||c[x][2]<c[w][2])&&(w=x)}if(w<0){w=0;for(var A=0;A<3;++A){for(var M=(A+2)%3,S=(A+1)%3,E=-1,L=-1,C=0;C<2;++C){var P=(O=C<<A)+(C<<M)+(1-C<<S),I=O+(1-C<<M)+(C<<S);o(c[O],c[P],c[I],f)<0||(C?E=1:L=1)}if(E<0||L<0)L>E&&(w|=1<<A);else{for(C=0;C<2;++C){P=(O=C<<A)+(C<<M)+(1-C<<S),I=O+(1-C<<M)+(C<<S);var O,z=d([l[O],l[P],l[I],l[O+(1<<M)+(1<<S)]]);C?E=z:L=z}L>E&&(w|=1<<A)}}}var D=7^w,R=-1;for(x=0;x<8;++x)x!==w&&x!==D&&(R<0||c[R][1]>c[x][1])&&(R=x);var F=-1;for(x=0;x<3;++x){if((N=R^1<<x)!==w&&N!==D)F<0&&(F=N),(S=c[N])[0]<c[F][0]&&(F=N)}var B=-1;for(x=0;x<3;++x){var N;if((N=R^1<<x)!==w&&N!==D&&N!==F)B<0&&(B=N),(S=c[N])[0]>c[B][0]&&(B=N)}var j=m;j[0]=j[1]=j[2]=0,j[n.log2(F^R)]=R&F,j[n.log2(R^B)]=R&B;var U=7^B;U===w||U===D?(U=7^F,j[n.log2(B^U)]=U&B):j[n.log2(F^U)]=U&F;var V=g,H=w;for(A=0;A<3;++A)V[A]=H&1<<A?-1:1;return v};var n=t("bit-twiddle"),i=t("gl-mat4/multiply"),a=t("split-polygon"),o=t("robust-orientation"),s=new Array(16),l=new Array(8),c=new Array(8),u=new Array(3),f=[0,0,0];function h(t,e,r){for(var n=0;n<4;++n){t[n]=r[12+n];for(var i=0;i<3;++i)t[n]+=e[i]*r[4*i+n]}}!function(){for(var t=0;t<8;++t)l[t]=[1,1,1,1],c[t]=[1,1,1]}();var p=[[0,0,1,0,0],[0,0,-1,1,0],[0,-1,0,1,0],[0,1,0,1,0],[-1,0,0,1,0],[1,0,0,1,0]];function d(t){for(var e=0;e<p.length;++e)if((t=a.positive(t,p[e])).length<3)return 0;var r=t[0],n=r[0]/r[3],i=r[1]/r[3],o=0;for(e=1;e+1<t.length;++e){var s=t[e],l=t[e+1],c=s[0]/s[3]-n,u=s[1]/s[3]-i,f=l[0]/l[3]-n,h=l[1]/l[3]-i;o+=Math.abs(c*h-u*f)}return o}var m=[1,1,1],g=[0,0,0],v={cubeEdges:m,axis:g}},{"bit-twiddle":32,"gl-mat4/multiply":100,"robust-orientation":284,"split-polygon":300}],73:[function(t,e,r){"use strict";e.exports=function(t,e,r){var o=[],s=[0,0,0],l=[0,0,0],c=[0,0,0],u=[0,0,0];o.push(0,0,1,0,1,1,0,0,-1,0,0,-1,0,1,1,0,1,-1);for(var f=0;f<3;++f){for(var h=o.length/3|0,d=0;d<r[f].length;++d){var m=+r[f][d].x;o.push(m,0,1,m,1,1,m,0,-1,m,0,-1,m,1,1,m,1,-1)}var g=o.length/3|0;s[f]=h,l[f]=g-h;h=o.length/3|0;for(var v=0;v<r[f].length;++v){m=+r[f][v].x;o.push(m,0,1,m,1,1,m,0,-1,m,0,-1,m,1,1,m,1,-1)}g=o.length/3|0;c[f]=h,u[f]=g-h}var y=n(t,new Float32Array(o)),x=i(t,[{buffer:y,type:t.FLOAT,size:3,stride:0,offset:0}]),b=a(t);return b.attributes.position.location=0,new p(t,y,x,b,l,s,u,c)};var n=t("gl-buffer"),i=t("gl-vao"),a=t("./shaders").line,o=[0,0,0],s=[0,0,0],l=[0,0,0],c=[0,0,0],u=[1,1];function f(t){return t[0]=t[1]=t[2]=0,t}function h(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function p(t,e,r,n,i,a,o,s){this.gl=t,this.vertBuffer=e,this.vao=r,this.shader=n,this.tickCount=i,this.tickOffset=a,this.gridCount=o,this.gridOffset=s}var d=p.prototype;d.bind=function(t,e,r){this.shader.bind(),this.shader.uniforms.model=t,this.shader.uniforms.view=e,this.shader.uniforms.projection=r,u[0]=this.gl.drawingBufferWidth,u[1]=this.gl.drawingBufferHeight,this.shader.uniforms.screenShape=u,this.vao.bind()},d.unbind=function(){this.vao.unbind()},d.drawAxisLine=function(t,e,r,n,i){var a=f(s);this.shader.uniforms.majorAxis=s,a[t]=e[1][t]-e[0][t],this.shader.uniforms.minorAxis=a;var o,u=h(c,r);u[t]+=e[0][t],this.shader.uniforms.offset=u,this.shader.uniforms.lineWidth=i,this.shader.uniforms.color=n,(o=f(l))[(t+2)%3]=1,this.shader.uniforms.screenAxis=o,this.vao.draw(this.gl.TRIANGLES,6),(o=f(l))[(t+1)%3]=1,this.shader.uniforms.screenAxis=o,this.vao.draw(this.gl.TRIANGLES,6)},d.drawAxisTicks=function(t,e,r,n,i){if(this.tickCount[t]){var a=f(o);a[t]=1,this.shader.uniforms.majorAxis=a,this.shader.uniforms.offset=e,this.shader.uniforms.minorAxis=r,this.shader.uniforms.color=n,this.shader.uniforms.lineWidth=i;var s=f(l);s[t]=1,this.shader.uniforms.screenAxis=s,this.vao.draw(this.gl.TRIANGLES,this.tickCount[t],this.tickOffset[t])}},d.drawGrid=function(t,e,r,n,i,a){if(this.gridCount[t]){var u=f(s);u[e]=r[1][e]-r[0][e],this.shader.uniforms.minorAxis=u;var p=h(c,n);p[e]+=r[0][e],this.shader.uniforms.offset=p;var d=f(o);d[t]=1,this.shader.uniforms.majorAxis=d;var m=f(l);m[t]=1,this.shader.uniforms.screenAxis=m,this.shader.uniforms.lineWidth=a,this.shader.uniforms.color=i,this.vao.draw(this.gl.TRIANGLES,this.gridCount[t],this.gridOffset[t])}},d.drawZero=function(t,e,r,n,i,a){var o=f(s);this.shader.uniforms.majorAxis=o,o[t]=r[1][t]-r[0][t],this.shader.uniforms.minorAxis=o;var u=h(c,n);u[t]+=r[0][t],this.shader.uniforms.offset=u;var p=f(l);p[e]=1,this.shader.uniforms.screenAxis=p,this.shader.uniforms.lineWidth=a,this.shader.uniforms.color=i,this.vao.draw(this.gl.TRIANGLES,6)},d.dispose=function(){this.vao.dispose(),this.vertBuffer.dispose(),this.shader.dispose()}},{"./shaders":74,"gl-buffer":78,"gl-vao":150}],74:[function(t,e,r){"use strict";var n=t("glslify"),i=t("gl-shader"),a=n(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec3 position;\n\nuniform mat4 model, view, projection;\nuniform vec3 offset, majorAxis, minorAxis, screenAxis;\nuniform float lineWidth;\nuniform vec2 screenShape;\n\nvec3 project(vec3 p) {\n  vec4 pp = projection * view * model * vec4(p, 1.0);\n  return pp.xyz / max(pp.w, 0.0001);\n}\n\nvoid main() {\n  vec3 major = position.x * majorAxis;\n  vec3 minor = position.y * minorAxis;\n\n  vec3 vPosition = major + minor + offset;\n  vec3 pPosition = project(vPosition);\n  vec3 offset = project(vPosition + screenAxis * position.z);\n\n  vec2 screen = normalize((offset - pPosition).xy * screenShape) / screenShape;\n\n  gl_Position = vec4(pPosition + vec3(0.5 * screen * lineWidth, 0), 1.0);\n}\n"]),o=n(["precision highp float;\n#define GLSLIFY 1\n\nuniform vec4 color;\nvoid main() {\n  gl_FragColor = color;\n}"]);r.line=function(t){return i(t,a,o,null,[{name:"position",type:"vec3"}])};var s=n(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec3 position;\n\nuniform mat4 model, view, projection;\nuniform vec3 offset, axis, alignDir, alignOpt;\nuniform float scale, angle, pixelScale;\nuniform vec2 resolution;\n\nvec3 project(vec3 p) {\n  vec4 pp = projection * view * model * vec4(p, 1.0);\n  return pp.xyz / max(pp.w, 0.0001);\n}\n\nfloat computeViewAngle(vec3 a, vec3 b) {\n  vec3 A = project(a);\n  vec3 B = project(b);\n\n  return atan(\n    (B.y - A.y) * resolution.y,\n    (B.x - A.x) * resolution.x\n  );\n}\n\nconst float PI = 3.141592;\nconst float TWO_PI = 2.0 * PI;\nconst float HALF_PI = 0.5 * PI;\nconst float ONE_AND_HALF_PI = 1.5 * PI;\n\nint option = int(floor(alignOpt.x + 0.001));\nfloat hv_ratio =       alignOpt.y;\nbool enableAlign =    (alignOpt.z != 0.0);\n\nfloat mod_angle(float a) {\n  return mod(a, PI);\n}\n\nfloat positive_angle(float a) {\n  return mod_angle((a < 0.0) ?\n    a + TWO_PI :\n    a\n  );\n}\n\nfloat look_upwards(float a) {\n  float b = positive_angle(a);\n  return ((b > HALF_PI) && (b <= ONE_AND_HALF_PI)) ?\n    b - PI :\n    b;\n}\n\nfloat look_horizontal_or_vertical(float a, float ratio) {\n  // ratio controls the ratio between being horizontal to (vertical + horizontal)\n  // if ratio is set to 0.5 then it is 50%, 50%.\n  // when using a higher ratio e.g. 0.75 the result would\n  // likely be more horizontal than vertical.\n\n  float b = positive_angle(a);\n\n  return\n    (b < (      ratio) * HALF_PI) ? 0.0 :\n    (b < (2.0 - ratio) * HALF_PI) ? -HALF_PI :\n    (b < (2.0 + ratio) * HALF_PI) ? 0.0 :\n    (b < (4.0 - ratio) * HALF_PI) ? HALF_PI :\n                                    0.0;\n}\n\nfloat roundTo(float a, float b) {\n  return float(b * floor((a + 0.5 * b) / b));\n}\n\nfloat look_round_n_directions(float a, int n) {\n  float b = positive_angle(a);\n  float div = TWO_PI / float(n);\n  float c = roundTo(b, div);\n  return look_upwards(c);\n}\n\nfloat applyAlignOption(float rawAngle, float delta) {\n  return\n    (option >  2) ? look_round_n_directions(rawAngle + delta, option) :       // option 3-n: round to n directions\n    (option == 2) ? look_horizontal_or_vertical(rawAngle + delta, hv_ratio) : // horizontal or vertical\n    (option == 1) ? rawAngle + delta :       // use free angle, and flip to align with one direction of the axis\n    (option == 0) ? look_upwards(rawAngle) : // use free angle, and stay upwards\n    (option ==-1) ? 0.0 :                    // useful for backward compatibility, all texts remains horizontal\n                    rawAngle;                // otherwise return back raw input angle\n}\n\nbool isAxisTitle = (axis.x == 0.0) &&\n                   (axis.y == 0.0) &&\n                   (axis.z == 0.0);\n\nvoid main() {\n  //Compute world offset\n  float axisDistance = position.z;\n  vec3 dataPosition = axisDistance * axis + offset;\n\n  float beta = angle; // i.e. user defined attributes for each tick\n\n  float axisAngle;\n  float clipAngle;\n  float flip;\n\n  if (enableAlign) {\n    axisAngle = (isAxisTitle) ? HALF_PI :\n                      computeViewAngle(dataPosition, dataPosition + axis);\n    clipAngle = computeViewAngle(dataPosition, dataPosition + alignDir);\n\n    axisAngle += (sin(axisAngle) < 0.0) ? PI : 0.0;\n    clipAngle += (sin(clipAngle) < 0.0) ? PI : 0.0;\n\n    flip = (dot(vec2(cos(axisAngle), sin(axisAngle)),\n                vec2(sin(clipAngle),-cos(clipAngle))) > 0.0) ? 1.0 : 0.0;\n\n    beta += applyAlignOption(clipAngle, flip * PI);\n  }\n\n  //Compute plane offset\n  vec2 planeCoord = position.xy * pixelScale;\n\n  mat2 planeXform = scale * mat2(\n     cos(beta), sin(beta),\n    -sin(beta), cos(beta)\n  );\n\n  vec2 viewOffset = 2.0 * planeXform * planeCoord / resolution;\n\n  //Compute clip position\n  vec3 clipPosition = project(dataPosition);\n\n  //Apply text offset in clip coordinates\n  clipPosition += vec3(viewOffset, 0.0);\n\n  //Done\n  gl_Position = vec4(clipPosition, 1.0);\n}"]),l=n(["precision highp float;\n#define GLSLIFY 1\n\nuniform vec4 color;\nvoid main() {\n  gl_FragColor = color;\n}"]);r.text=function(t){return i(t,s,l,null,[{name:"position",type:"vec3"}])};var c=n(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec3 position;\nattribute vec3 normal;\n\nuniform mat4 model, view, projection;\nuniform vec3 enable;\nuniform vec3 bounds[2];\n\nvarying vec3 colorChannel;\n\nvoid main() {\n\n  vec3 signAxis = sign(bounds[1] - bounds[0]);\n\n  vec3 realNormal = signAxis * normal;\n\n  if(dot(realNormal, enable) > 0.0) {\n    vec3 minRange = min(bounds[0], bounds[1]);\n    vec3 maxRange = max(bounds[0], bounds[1]);\n    vec3 nPosition = mix(minRange, maxRange, 0.5 * (position + 1.0));\n    gl_Position = projection * view * model * vec4(nPosition, 1.0);\n  } else {\n    gl_Position = vec4(0,0,0,0);\n  }\n\n  colorChannel = abs(realNormal);\n}"]),u=n(["precision highp float;\n#define GLSLIFY 1\n\nuniform vec4 colors[3];\n\nvarying vec3 colorChannel;\n\nvoid main() {\n  gl_FragColor = colorChannel.x * colors[0] +\n                 colorChannel.y * colors[1] +\n                 colorChannel.z * colors[2];\n}"]);r.bg=function(t){return i(t,c,u,null,[{name:"position",type:"vec3"},{name:"normal",type:"vec3"}])}},{"gl-shader":132,glslify:231}],75:[function(t,e,r){(function(r){(function(){"use strict";e.exports=function(t,e,r,a,s,l){var u=n(t),f=i(t,[{buffer:u,size:3}]),h=o(t);h.attributes.position.location=0;var p=new c(t,h,u,f);return p.update(e,r,a,s,l),p};var n=t("gl-buffer"),i=t("gl-vao"),a=t("vectorize-text"),o=t("./shaders").text,s=window||r.global||{},l=s.__TEXT_CACHE||{};s.__TEXT_CACHE={};function c(t,e,r,n){this.gl=t,this.shader=e,this.buffer=r,this.vao=n,this.tickOffset=this.tickCount=this.labelOffset=this.labelCount=null}var u=c.prototype,f=[0,0];u.bind=function(t,e,r,n){this.vao.bind(),this.shader.bind();var i=this.shader.uniforms;i.model=t,i.view=e,i.projection=r,i.pixelScale=n,f[0]=this.gl.drawingBufferWidth,f[1]=this.gl.drawingBufferHeight,this.shader.uniforms.resolution=f},u.unbind=function(){this.vao.unbind()},u.update=function(t,e,r,n,i){var o=[];function s(t,e,r,n,i,s){var c=l[r];c||(c=l[r]={});var u=c[e];u||(u=c[e]=function(t,e){try{return a(t,e)}catch(e){return console.warn('error vectorizing text:"'+t+'" error:',e),{cells:[],positions:[]}}}(e,{triangles:!0,font:r,textAlign:"center",textBaseline:"middle",lineSpacing:i,styletags:s}));for(var f=(n||12)/12,h=u.positions,p=u.cells,d=0,m=p.length;d<m;++d)for(var g=p[d],v=2;v>=0;--v){var y=h[g[v]];o.push(f*y[0],-f*y[1],t)}}for(var c=[0,0,0],u=[0,0,0],f=[0,0,0],h=[0,0,0],p={breaklines:!0,bolds:!0,italics:!0,subscripts:!0,superscripts:!0},d=0;d<3;++d){f[d]=o.length/3|0,s(.5*(t[0][d]+t[1][d]),e[d],r[d],12,1.25,p),h[d]=(o.length/3|0)-f[d],c[d]=o.length/3|0;for(var m=0;m<n[d].length;++m)n[d][m].text&&s(n[d][m].x,n[d][m].text,n[d][m].font||i,n[d][m].fontSize||12,1.25,p);u[d]=(o.length/3|0)-c[d]}this.buffer.update(o),this.tickOffset=c,this.tickCount=u,this.labelOffset=f,this.labelCount=h},u.drawTicks=function(t,e,r,n,i,a,o,s){this.tickCount[t]&&(this.shader.uniforms.axis=a,this.shader.uniforms.color=i,this.shader.uniforms.angle=r,this.shader.uniforms.scale=e,this.shader.uniforms.offset=n,this.shader.uniforms.alignDir=o,this.shader.uniforms.alignOpt=s,this.vao.draw(this.gl.TRIANGLES,this.tickCount[t],this.tickOffset[t]))},u.drawLabel=function(t,e,r,n,i,a,o,s){this.labelCount[t]&&(this.shader.uniforms.axis=a,this.shader.uniforms.color=i,this.shader.uniforms.angle=r,this.shader.uniforms.scale=e,this.shader.uniforms.offset=n,this.shader.uniforms.alignDir=o,this.shader.uniforms.alignOpt=s,this.vao.draw(this.gl.TRIANGLES,this.labelCount[t],this.labelOffset[t]))},u.dispose=function(){this.shader.dispose(),this.vao.dispose(),this.buffer.dispose()}}).call(this)}).call(this,t("_process"))},{"./shaders":74,_process:5,"gl-buffer":78,"gl-vao":150,"vectorize-text":311}],76:[function(t,e,r){"use strict";function n(t,e){var r=t+"",n=r.indexOf("."),i=0;n>=0&&(i=r.length-n-1);var a=Math.pow(10,i),o=Math.round(t*e*a),s=o+"";if(s.indexOf("e")>=0)return s;var l=o/a,c=o%a;o<0?(l=0|-Math.ceil(l),c=0|-c):(l=0|Math.floor(l),c|=0);var u=""+l;if(o<0&&(u="-"+u),i){for(var f=""+c;f.length<i;)f="0"+f;return u+"."+f}return u}r.create=function(t,e){for(var r=[],i=0;i<3;++i){for(var a=[],o=(t[0][i],t[1][i],0);o*e[i]<=t[1][i];++o)a.push({x:o*e[i],text:n(e[i],o)});for(o=-1;o*e[i]>=t[0][i];--o)a.push({x:o*e[i],text:n(e[i],o)});r.push(a)}return r},r.equal=function(t,e){for(var r=0;r<3;++r){if(t[r].length!==e[r].length)return!1;for(var n=0;n<t[r].length;++n){var i=t[r][n],a=e[r][n];if(i.x!==a.x||i.text!==a.text||i.font!==a.font||i.fontColor!==a.fontColor||i.fontSize!==a.fontSize||i.dx!==a.dx||i.dy!==a.dy)return!1}}return!0}},{}],77:[function(t,e,r){"use strict";e.exports=function(t,e,r,l,f){var h=e.model||c,p=e.view||c,v=e.projection||c,y=e._ortho||!1,x=t.bounds,b=(f=f||a(h,p,v,x,y)).axis;o(u,p,h),o(u,v,u);for(var _=m,w=0;w<3;++w)_[w].lo=1/0,_[w].hi=-1/0,_[w].pixelsPerDataUnit=1/0;var T=n(s(u,u));s(u,u);for(var k=0;k<3;++k){var A=(k+1)%3,M=(k+2)%3,S=g;t:for(w=0;w<2;++w){var E=[];if(b[k]<0!=!!w){S[k]=x[w][k];for(var L=0;L<2;++L){S[A]=x[L^w][A];for(var C=0;C<2;++C)S[M]=x[C^L^w][M],E.push(S.slice())}var P=y?5:4;for(L=P;L===P;++L){if(0===E.length)continue t;E=i.positive(E,T[L])}for(L=0;L<E.length;++L){M=E[L];var I=d(g,u,M,r,l);for(C=0;C<3;++C)_[C].lo=Math.min(_[C].lo,M[C]),_[C].hi=Math.max(_[C].hi,M[C]),C!==k&&(_[C].pixelsPerDataUnit=Math.min(_[C].pixelsPerDataUnit,Math.abs(I[C])))}}}}return _};var n=t("extract-frustum-planes"),i=t("split-polygon"),a=t("./lib/cube.js"),o=t("gl-mat4/multiply"),s=t("gl-mat4/transpose"),l=t("gl-vec4/transformMat4"),c=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),u=new Float32Array(16);function f(t,e,r){this.lo=t,this.hi=e,this.pixelsPerDataUnit=r}var h=[0,0,0,1],p=[0,0,0,1];function d(t,e,r,n,i){for(var a=0;a<3;++a){for(var o=h,s=p,c=0;c<3;++c)s[c]=o[c]=r[c];s[3]=o[3]=1,s[a]+=1,l(s,s,e),s[3]<0&&(t[a]=1/0),o[a]-=1,l(o,o,e),o[3]<0&&(t[a]=1/0);var u=(o[0]/o[3]-s[0]/s[3])*n,f=(o[1]/o[3]-s[1]/s[3])*i;t[a]=.25*Math.sqrt(u*u+f*f)}return t}var m=[new f(1/0,-1/0,1/0),new f(1/0,-1/0,1/0),new f(1/0,-1/0,1/0)],g=[0,0,0]},{"./lib/cube.js":72,"extract-frustum-planes":67,"gl-mat4/multiply":100,"gl-mat4/transpose":109,"gl-vec4/transformMat4":221,"split-polygon":300}],78:[function(t,e,r){"use strict";var n=t("typedarray-pool"),i=t("ndarray-ops"),a=t("ndarray"),o=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"];function s(t,e,r,n,i){this.gl=t,this.type=e,this.handle=r,this.length=n,this.usage=i}var l=s.prototype;function c(t,e,r,n,i,a){var o=i.length*i.BYTES_PER_ELEMENT;if(a<0)return t.bufferData(e,i,n),o;if(o+a>r)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return t.bufferSubData(e,a,i),r}function u(t,e){for(var r=n.malloc(t.length,e),i=t.length,a=0;a<i;++a)r[a]=t[a];return r}l.bind=function(){this.gl.bindBuffer(this.type,this.handle)},l.unbind=function(){this.gl.bindBuffer(this.type,null)},l.dispose=function(){this.gl.deleteBuffer(this.handle)},l.update=function(t,e){if("number"!=typeof e&&(e=-1),this.bind(),"object"==typeof t&&void 0!==t.shape){var r=t.dtype;if(o.indexOf(r)<0&&(r="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER)r=gl.getExtension("OES_element_index_uint")&&"uint16"!==r?"uint32":"uint16";if(r===t.dtype&&function(t,e){for(var r=1,n=e.length-1;n>=0;--n){if(e[n]!==r)return!1;r*=t[n]}return!0}(t.shape,t.stride))0===t.offset&&t.data.length===t.shape[0]?this.length=c(this.gl,this.type,this.length,this.usage,t.data,e):this.length=c(this.gl,this.type,this.length,this.usage,t.data.subarray(t.offset,t.shape[0]),e);else{var s=n.malloc(t.size,r),l=a(s,t.shape);i.assign(l,t),this.length=c(this.gl,this.type,this.length,this.usage,e<0?s:s.subarray(0,t.size),e),n.free(s)}}else if(Array.isArray(t)){var f;f=this.type===this.gl.ELEMENT_ARRAY_BUFFER?u(t,"uint16"):u(t,"float32"),this.length=c(this.gl,this.type,this.length,this.usage,e<0?f:f.subarray(0,t.length),e),n.free(f)}else if("object"==typeof t&&"number"==typeof t.length)this.length=c(this.gl,this.type,this.length,this.usage,t,e);else{if("number"!=typeof t&&void 0!==t)throw new Error("gl-buffer: Invalid data type");if(e>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");(t|=0)<=0&&(t=1),this.gl.bufferData(this.type,0|t,this.usage),this.length=t}},e.exports=function(t,e,r,n){if(r=r||t.ARRAY_BUFFER,n=n||t.DYNAMIC_DRAW,r!==t.ARRAY_BUFFER&&r!==t.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(n!==t.DYNAMIC_DRAW&&n!==t.STATIC_DRAW&&n!==t.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var i=t.createBuffer(),a=new s(t,r,i,0,n);return a.update(e),a}},{ndarray:259,"ndarray-ops":254,"typedarray-pool":308}],79:[function(t,e,r){"use strict";var n=t("gl-vec3");e.exports=function(t,e){var r=t.positions,i=t.vectors,a={positions:[],vertexIntensity:[],vertexIntensityBounds:t.vertexIntensityBounds,vectors:[],cells:[],coneOffset:t.coneOffset,colormap:t.colormap};if(0===t.positions.length)return e&&(e[0]=[0,0,0],e[1]=[0,0,0]),a;for(var o=0,s=1/0,l=-1/0,c=1/0,u=-1/0,f=1/0,h=-1/0,p=null,d=null,m=[],g=1/0,v=!1,y=0;y<r.length;y++){var x=r[y];s=Math.min(x[0],s),l=Math.max(x[0],l),c=Math.min(x[1],c),u=Math.max(x[1],u),f=Math.min(x[2],f),h=Math.max(x[2],h);var b=i[y];if(n.length(b)>o&&(o=n.length(b)),y){var _=2*n.distance(p,x)/(n.length(d)+n.length(b));_?(g=Math.min(g,_),v=!1):v=!0}v||(p=x,d=b),m.push(b)}var w=[s,c,f],T=[l,u,h];e&&(e[0]=w,e[1]=T),0===o&&(o=1);var k=1/o;isFinite(g)||(g=1),a.vectorScale=g;var A=t.coneSize||.5;t.absoluteConeSize&&(A=t.absoluteConeSize*k),a.coneScale=A;y=0;for(var M=0;y<r.length;y++)for(var S=(x=r[y])[0],E=x[1],L=x[2],C=m[y],P=n.length(C)*k,I=0;I<8;I++){a.positions.push([S,E,L,M++]),a.positions.push([S,E,L,M++]),a.positions.push([S,E,L,M++]),a.positions.push([S,E,L,M++]),a.positions.push([S,E,L,M++]),a.positions.push([S,E,L,M++]),a.vectors.push(C),a.vectors.push(C),a.vectors.push(C),a.vectors.push(C),a.vectors.push(C),a.vectors.push(C),a.vertexIntensity.push(P,P,P),a.vertexIntensity.push(P,P,P);var O=a.positions.length;a.cells.push([O-6,O-5,O-4],[O-3,O-2,O-1])}return a};var i=t("./lib/shaders");e.exports.createMesh=t("./create_mesh"),e.exports.createConeMesh=function(t,r){return e.exports.createMesh(t,r,{shaders:i,traceType:"cone"})}},{"./create_mesh":80,"./lib/shaders":81,"gl-vec3":169}],80:[function(t,e,r){"use strict";var n=t("gl-shader"),i=t("gl-buffer"),a=t("gl-vao"),o=t("gl-texture2d"),s=t("gl-mat4/multiply"),l=t("gl-mat4/invert"),c=t("ndarray"),u=t("colormap"),f=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function h(t,e,r,n,i,a,o,s,l,c,u){this.gl=t,this.pixelRatio=1,this.cells=[],this.positions=[],this.intensity=[],this.texture=e,this.dirty=!0,this.triShader=r,this.pickShader=n,this.trianglePositions=i,this.triangleVectors=a,this.triangleColors=s,this.triangleUVs=l,this.triangleIds=o,this.triangleVAO=c,this.triangleCount=0,this.pickId=1,this.bounds=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]],this.clipBounds=[[-1/0,-1/0,-1/0],[1/0,1/0,1/0]],this.lightPosition=[1e5,1e5,0],this.ambientLight=.8,this.diffuseLight=.8,this.specularLight=2,this.roughness=.5,this.fresnel=1.5,this.opacity=1,this.traceType=u,this.tubeScale=1,this.coneScale=2,this.vectorScale=1,this.coneOffset=.25,this._model=f,this._view=f,this._projection=f,this._resolution=[1,1]}var p=h.prototype;function d(t,e){var r=n(t,e.meshShader.vertex,e.meshShader.fragment,null,e.meshShader.attributes);return r.attributes.position.location=0,r.attributes.color.location=2,r.attributes.uv.location=3,r.attributes.vector.location=4,r}function m(t,e){var r=n(t,e.pickShader.vertex,e.pickShader.fragment,null,e.pickShader.attributes);return r.attributes.position.location=0,r.attributes.id.location=1,r.attributes.vector.location=4,r}p.isOpaque=function(){return this.opacity>=1},p.isTransparent=function(){return this.opacity<1},p.pickSlots=1,p.setPickBase=function(t){this.pickId=t},p.update=function(t){t=t||{};var e=this.gl;this.dirty=!0,"lightPosition"in t&&(this.lightPosition=t.lightPosition),"opacity"in t&&(this.opacity=t.opacity),"ambient"in t&&(this.ambientLight=t.ambient),"diffuse"in t&&(this.diffuseLight=t.diffuse),"specular"in t&&(this.specularLight=t.specular),"roughness"in t&&(this.roughness=t.roughness),"fresnel"in t&&(this.fresnel=t.fresnel),void 0!==t.tubeScale&&(this.tubeScale=t.tubeScale),void 0!==t.vectorScale&&(this.vectorScale=t.vectorScale),void 0!==t.coneScale&&(this.coneScale=t.coneScale),void 0!==t.coneOffset&&(this.coneOffset=t.coneOffset),t.colormap&&(this.texture.shape=[256,256],this.texture.minFilter=e.LINEAR_MIPMAP_LINEAR,this.texture.magFilter=e.LINEAR,this.texture.setPixels(function(t){for(var e=u({colormap:t,nshades:256,format:"rgba"}),r=new Uint8Array(1024),n=0;n<256;++n){for(var i=e[n],a=0;a<3;++a)r[4*n+a]=i[a];r[4*n+3]=255*i[3]}return c(r,[256,256,4],[4,0,1])}(t.colormap)),this.texture.generateMipmap());var r=t.cells,n=t.positions,i=t.vectors;if(n&&r&&i){var a=[],o=[],s=[],l=[],f=[];this.cells=r,this.positions=n,this.vectors=i;var h=t.meshColor||[1,1,1,1],p=t.vertexIntensity,d=1/0,m=-1/0;if(p)if(t.vertexIntensityBounds)d=+t.vertexIntensityBounds[0],m=+t.vertexIntensityBounds[1];else for(var g=0;g<p.length;++g){var v=p[g];d=Math.min(d,v),m=Math.max(m,v)}else for(g=0;g<n.length;++g){v=n[g][2];d=Math.min(d,v),m=Math.max(m,v)}this.intensity=p||function(t){for(var e=t.length,r=new Array(e),n=0;n<e;++n)r[n]=t[n][2];return r}(n),this.bounds=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];for(g=0;g<n.length;++g)for(var y=n[g],x=0;x<3;++x)!isNaN(y[x])&&isFinite(y[x])&&(this.bounds[0][x]=Math.min(this.bounds[0][x],y[x]),this.bounds[1][x]=Math.max(this.bounds[1][x],y[x]));var b=0;t:for(g=0;g<r.length;++g){var _=r[g];switch(_.length){case 3:for(x=0;x<3;++x){y=n[T=_[x]];for(var w=0;w<3;++w)if(isNaN(y[w])||!isFinite(y[w]))continue t}for(x=0;x<3;++x){var T;y=n[T=_[2-x]];a.push(y[0],y[1],y[2],y[3]);var k=i[T];o.push(k[0],k[1],k[2],k[3]||0);var A,M=h;3===M.length?s.push(M[0],M[1],M[2],1):s.push(M[0],M[1],M[2],M[3]),A=p?[(p[T]-d)/(m-d),0]:[(y[2]-d)/(m-d),0],l.push(A[0],A[1]),f.push(g)}b+=1}}this.triangleCount=b,this.trianglePositions.update(a),this.triangleVectors.update(o),this.triangleColors.update(s),this.triangleUVs.update(l),this.triangleIds.update(new Uint32Array(f))}},p.drawTransparent=p.draw=function(t){t=t||{};for(var e=this.gl,r=t.model||f,n=t.view||f,i=t.projection||f,a=[[-1e6,-1e6,-1e6],[1e6,1e6,1e6]],o=0;o<3;++o)a[0][o]=Math.max(a[0][o],this.clipBounds[0][o]),a[1][o]=Math.min(a[1][o],this.clipBounds[1][o]);var c={model:r,view:n,projection:i,inverseModel:f.slice(),clipBounds:a,kambient:this.ambientLight,kdiffuse:this.diffuseLight,kspecular:this.specularLight,roughness:this.roughness,fresnel:this.fresnel,eyePosition:[0,0,0],lightPosition:[0,0,0],opacity:this.opacity,tubeScale:this.tubeScale,vectorScale:this.vectorScale,coneScale:this.coneScale,coneOffset:this.coneOffset,texture:0};c.inverseModel=l(c.inverseModel,c.model),e.disable(e.CULL_FACE),this.texture.bind(0);var u=new Array(16);s(u,c.view,c.model),s(u,c.projection,u),l(u,u);for(o=0;o<3;++o)c.eyePosition[o]=u[12+o]/u[15];var h=u[15];for(o=0;o<3;++o)h+=this.lightPosition[o]*u[4*o+3];for(o=0;o<3;++o){for(var p=u[12+o],d=0;d<3;++d)p+=u[4*d+o]*this.lightPosition[d];c.lightPosition[o]=p/h}if(this.triangleCount>0){var m=this.triShader;m.bind(),m.uniforms=c,this.triangleVAO.bind(),e.drawArrays(e.TRIANGLES,0,3*this.triangleCount),this.triangleVAO.unbind()}},p.drawPick=function(t){t=t||{};for(var e=this.gl,r=t.model||f,n=t.view||f,i=t.projection||f,a=[[-1e6,-1e6,-1e6],[1e6,1e6,1e6]],o=0;o<3;++o)a[0][o]=Math.max(a[0][o],this.clipBounds[0][o]),a[1][o]=Math.min(a[1][o],this.clipBounds[1][o]);this._model=[].slice.call(r),this._view=[].slice.call(n),this._projection=[].slice.call(i),this._resolution=[e.drawingBufferWidth,e.drawingBufferHeight];var s={model:r,view:n,projection:i,clipBounds:a,tubeScale:this.tubeScale,vectorScale:this.vectorScale,coneScale:this.coneScale,coneOffset:this.coneOffset,pickId:this.pickId/255},l=this.pickShader;l.bind(),l.uniforms=s,this.triangleCount>0&&(this.triangleVAO.bind(),e.drawArrays(e.TRIANGLES,0,3*this.triangleCount),this.triangleVAO.unbind())},p.pick=function(t){if(!t)return null;if(t.id!==this.pickId)return null;var e=t.value[0]+256*t.value[1]+65536*t.value[2],r=this.cells[e],n=this.positions[r[1]].slice(0,3),i={position:n,dataCoordinate:n,index:Math.floor(r[1]/48)};return"cone"===this.traceType?i.index=Math.floor(r[1]/48):"streamtube"===this.traceType&&(i.intensity=this.intensity[r[1]],i.velocity=this.vectors[r[1]].slice(0,3),i.divergence=this.vectors[r[1]][3],i.index=e),i},p.dispose=function(){this.texture.dispose(),this.triShader.dispose(),this.pickShader.dispose(),this.triangleVAO.dispose(),this.trianglePositions.dispose(),this.triangleVectors.dispose(),this.triangleColors.dispose(),this.triangleUVs.dispose(),this.triangleIds.dispose()},e.exports=function(t,e,r){var n=r.shaders;1===arguments.length&&(t=(e=t).gl);var s=d(t,n),l=m(t,n),u=o(t,c(new Uint8Array([255,255,255,255]),[1,1,4]));u.generateMipmap(),u.minFilter=t.LINEAR_MIPMAP_LINEAR,u.magFilter=t.LINEAR;var f=i(t),p=i(t),g=i(t),v=i(t),y=i(t),x=a(t,[{buffer:f,type:t.FLOAT,size:4},{buffer:y,type:t.UNSIGNED_BYTE,size:4,normalized:!0},{buffer:g,type:t.FLOAT,size:4},{buffer:v,type:t.FLOAT,size:2},{buffer:p,type:t.FLOAT,size:4}]),b=new h(t,u,s,l,f,p,y,g,v,x,r.traceType||"cone");return b.update(e),b}},{colormap:53,"gl-buffer":78,"gl-mat4/invert":98,"gl-mat4/multiply":100,"gl-shader":132,"gl-texture2d":146,"gl-vao":150,ndarray:259}],81:[function(t,e,r){var n=t("glslify"),i=n(["precision highp float;\n\nprecision highp float;\n#define GLSLIFY 1\n\nvec3 getOrthogonalVector(vec3 v) {\n  // Return up-vector for only-z vector.\n  // Return ax + by + cz = 0, a point that lies on the plane that has v as a normal and that isn't (0,0,0).\n  // From the above if-statement we have ||a|| > 0  U  ||b|| > 0.\n  // Assign z = 0, x = -b, y = a:\n  // a*-b + b*a + c*0 = -ba + ba + 0 = 0\n  if (v.x*v.x > v.z*v.z || v.y*v.y > v.z*v.z) {\n    return normalize(vec3(-v.y, v.x, 0.0));\n  } else {\n    return normalize(vec3(0.0, v.z, -v.y));\n  }\n}\n\n// Calculate the cone vertex and normal at the given index.\n//\n// The returned vertex is for a cone with its top at origin and height of 1.0,\n// pointing in the direction of the vector attribute.\n//\n// Each cone is made up of a top vertex, a center base vertex and base perimeter vertices.\n// These vertices are used to make up the triangles of the cone by the following:\n//   segment + 0 top vertex\n//   segment + 1 perimeter vertex a+1\n//   segment + 2 perimeter vertex a\n//   segment + 3 center base vertex\n//   segment + 4 perimeter vertex a\n//   segment + 5 perimeter vertex a+1\n// Where segment is the number of the radial segment * 6 and a is the angle at that radial segment.\n// To go from index to segment, floor(index / 6)\n// To go from segment to angle, 2*pi * (segment/segmentCount)\n// To go from index to segment index, index - (segment*6)\n//\nvec3 getConePosition(vec3 d, float rawIndex, float coneOffset, out vec3 normal) {\n\n  const float segmentCount = 8.0;\n\n  float index = rawIndex - floor(rawIndex /\n    (segmentCount * 6.0)) *\n    (segmentCount * 6.0);\n\n  float segment = floor(0.001 + index/6.0);\n  float segmentIndex = index - (segment*6.0);\n\n  normal = -normalize(d);\n\n  if (segmentIndex > 2.99 && segmentIndex < 3.01) {\n    return mix(vec3(0.0), -d, coneOffset);\n  }\n\n  float nextAngle = (\n    (segmentIndex > 0.99 &&  segmentIndex < 1.01) ||\n    (segmentIndex > 4.99 &&  segmentIndex < 5.01)\n  ) ? 1.0 : 0.0;\n  float angle = 2.0 * 3.14159 * ((segment + nextAngle) / segmentCount);\n\n  vec3 v1 = mix(d, vec3(0.0), coneOffset);\n  vec3 v2 = v1 - d;\n\n  vec3 u = getOrthogonalVector(d);\n  vec3 v = normalize(cross(u, d));\n\n  vec3 x = u * cos(angle) * length(d)*0.25;\n  vec3 y = v * sin(angle) * length(d)*0.25;\n  vec3 v3 = v2 + x + y;\n  if (segmentIndex < 3.0) {\n    vec3 tx = u * sin(angle);\n    vec3 ty = v * -cos(angle);\n    vec3 tangent = tx + ty;\n    normal = normalize(cross(v3 - v1, tangent));\n  }\n\n  if (segmentIndex == 0.0) {\n    return mix(d, vec3(0.0), coneOffset);\n  }\n  return v3;\n}\n\nattribute vec3 vector;\nattribute vec4 color, position;\nattribute vec2 uv;\n\nuniform float vectorScale, coneScale, coneOffset;\nuniform mat4 model, view, projection, inverseModel;\nuniform vec3 eyePosition, lightPosition;\n\nvarying vec3 f_normal, f_lightDirection, f_eyeDirection, f_data, f_position;\nvarying vec4 f_color;\nvarying vec2 f_uv;\n\nvoid main() {\n  // Scale the vector magnitude to stay constant with\n  // model & view changes.\n  vec3 normal;\n  vec3 XYZ = getConePosition(mat3(model) * ((vectorScale * coneScale) * vector), position.w, coneOffset, normal);\n  vec4 conePosition = model * vec4(position.xyz, 1.0) + vec4(XYZ, 0.0);\n\n  //Lighting geometry parameters\n  vec4 cameraCoordinate = view * conePosition;\n  cameraCoordinate.xyz /= cameraCoordinate.w;\n  f_lightDirection = lightPosition - cameraCoordinate.xyz;\n  f_eyeDirection   = eyePosition - cameraCoordinate.xyz;\n  f_normal = normalize((vec4(normal, 0.0) * inverseModel).xyz);\n\n  // vec4 m_position  = model * vec4(conePosition, 1.0);\n  vec4 t_position  = view * conePosition;\n  gl_Position      = projection * t_position;\n\n  f_color          = color;\n  f_data           = conePosition.xyz;\n  f_position       = position.xyz;\n  f_uv             = uv;\n}\n"]),a=n(["#extension GL_OES_standard_derivatives : enable\n\nprecision highp float;\n#define GLSLIFY 1\n\nfloat beckmannDistribution(float x, float roughness) {\n  float NdotH = max(x, 0.0001);\n  float cos2Alpha = NdotH * NdotH;\n  float tan2Alpha = (cos2Alpha - 1.0) / cos2Alpha;\n  float roughness2 = roughness * roughness;\n  float denom = 3.141592653589793 * roughness2 * cos2Alpha * cos2Alpha;\n  return exp(tan2Alpha / roughness2) / denom;\n}\n\nfloat cookTorranceSpecular(\n  vec3 lightDirection,\n  vec3 viewDirection,\n  vec3 surfaceNormal,\n  float roughness,\n  float fresnel) {\n\n  float VdotN = max(dot(viewDirection, surfaceNormal), 0.0);\n  float LdotN = max(dot(lightDirection, surfaceNormal), 0.0);\n\n  //Half angle vector\n  vec3 H = normalize(lightDirection + viewDirection);\n\n  //Geometric term\n  float NdotH = max(dot(surfaceNormal, H), 0.0);\n  float VdotH = max(dot(viewDirection, H), 0.000001);\n  float LdotH = max(dot(lightDirection, H), 0.000001);\n  float G1 = (2.0 * NdotH * VdotN) / VdotH;\n  float G2 = (2.0 * NdotH * LdotN) / LdotH;\n  float G = min(1.0, min(G1, G2));\n  \n  //Distribution term\n  float D = beckmannDistribution(NdotH, roughness);\n\n  //Fresnel term\n  float F = pow(1.0 - VdotN, fresnel);\n\n  //Multiply terms and done\n  return  G * F * D / max(3.14159265 * VdotN, 0.000001);\n}\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec3 clipBounds[2];\nuniform float roughness, fresnel, kambient, kdiffuse, kspecular, opacity;\nuniform sampler2D texture;\n\nvarying vec3 f_normal, f_lightDirection, f_eyeDirection, f_data, f_position;\nvarying vec4 f_color;\nvarying vec2 f_uv;\n\nvoid main() {\n  if (outOfRange(clipBounds[0], clipBounds[1], f_position)) discard;\n  vec3 N = normalize(f_normal);\n  vec3 L = normalize(f_lightDirection);\n  vec3 V = normalize(f_eyeDirection);\n\n  if(gl_FrontFacing) {\n    N = -N;\n  }\n\n  float specular = min(1.0, max(0.0, cookTorranceSpecular(L, V, N, roughness, fresnel)));\n  float diffuse  = min(kambient + kdiffuse * max(dot(N, L), 0.0), 1.0);\n\n  vec4 surfaceColor = f_color * texture2D(texture, f_uv);\n  vec4 litColor = surfaceColor.a * vec4(diffuse * surfaceColor.rgb + kspecular * vec3(1,1,1) * specular,  1.0);\n\n  gl_FragColor = litColor * opacity;\n}\n"]),o=n(["precision highp float;\n\nprecision highp float;\n#define GLSLIFY 1\n\nvec3 getOrthogonalVector(vec3 v) {\n  // Return up-vector for only-z vector.\n  // Return ax + by + cz = 0, a point that lies on the plane that has v as a normal and that isn't (0,0,0).\n  // From the above if-statement we have ||a|| > 0  U  ||b|| > 0.\n  // Assign z = 0, x = -b, y = a:\n  // a*-b + b*a + c*0 = -ba + ba + 0 = 0\n  if (v.x*v.x > v.z*v.z || v.y*v.y > v.z*v.z) {\n    return normalize(vec3(-v.y, v.x, 0.0));\n  } else {\n    return normalize(vec3(0.0, v.z, -v.y));\n  }\n}\n\n// Calculate the cone vertex and normal at the given index.\n//\n// The returned vertex is for a cone with its top at origin and height of 1.0,\n// pointing in the direction of the vector attribute.\n//\n// Each cone is made up of a top vertex, a center base vertex and base perimeter vertices.\n// These vertices are used to make up the triangles of the cone by the following:\n//   segment + 0 top vertex\n//   segment + 1 perimeter vertex a+1\n//   segment + 2 perimeter vertex a\n//   segment + 3 center base vertex\n//   segment + 4 perimeter vertex a\n//   segment + 5 perimeter vertex a+1\n// Where segment is the number of the radial segment * 6 and a is the angle at that radial segment.\n// To go from index to segment, floor(index / 6)\n// To go from segment to angle, 2*pi * (segment/segmentCount)\n// To go from index to segment index, index - (segment*6)\n//\nvec3 getConePosition(vec3 d, float rawIndex, float coneOffset, out vec3 normal) {\n\n  const float segmentCount = 8.0;\n\n  float index = rawIndex - floor(rawIndex /\n    (segmentCount * 6.0)) *\n    (segmentCount * 6.0);\n\n  float segment = floor(0.001 + index/6.0);\n  float segmentIndex = index - (segment*6.0);\n\n  normal = -normalize(d);\n\n  if (segmentIndex > 2.99 && segmentIndex < 3.01) {\n    return mix(vec3(0.0), -d, coneOffset);\n  }\n\n  float nextAngle = (\n    (segmentIndex > 0.99 &&  segmentIndex < 1.01) ||\n    (segmentIndex > 4.99 &&  segmentIndex < 5.01)\n  ) ? 1.0 : 0.0;\n  float angle = 2.0 * 3.14159 * ((segment + nextAngle) / segmentCount);\n\n  vec3 v1 = mix(d, vec3(0.0), coneOffset);\n  vec3 v2 = v1 - d;\n\n  vec3 u = getOrthogonalVector(d);\n  vec3 v = normalize(cross(u, d));\n\n  vec3 x = u * cos(angle) * length(d)*0.25;\n  vec3 y = v * sin(angle) * length(d)*0.25;\n  vec3 v3 = v2 + x + y;\n  if (segmentIndex < 3.0) {\n    vec3 tx = u * sin(angle);\n    vec3 ty = v * -cos(angle);\n    vec3 tangent = tx + ty;\n    normal = normalize(cross(v3 - v1, tangent));\n  }\n\n  if (segmentIndex == 0.0) {\n    return mix(d, vec3(0.0), coneOffset);\n  }\n  return v3;\n}\n\nattribute vec4 vector;\nattribute vec4 position;\nattribute vec4 id;\n\nuniform mat4 model, view, projection;\nuniform float vectorScale, coneScale, coneOffset;\n\nvarying vec3 f_position;\nvarying vec4 f_id;\n\nvoid main() {\n  vec3 normal;\n  vec3 XYZ = getConePosition(mat3(model) * ((vectorScale * coneScale) * vector.xyz), position.w, coneOffset, normal);\n  vec4 conePosition = model * vec4(position.xyz, 1.0) + vec4(XYZ, 0.0);\n  gl_Position = projection * view * conePosition;\n  f_id        = id;\n  f_position  = position.xyz;\n}\n"]),s=n(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec3  clipBounds[2];\nuniform float pickId;\n\nvarying vec3 f_position;\nvarying vec4 f_id;\n\nvoid main() {\n  if (outOfRange(clipBounds[0], clipBounds[1], f_position)) discard;\n\n  gl_FragColor = vec4(pickId, f_id.xyz);\n}"]);r.meshShader={vertex:i,fragment:a,attributes:[{name:"position",type:"vec4"},{name:"color",type:"vec4"},{name:"uv",type:"vec2"},{name:"vector",type:"vec3"}]},r.pickShader={vertex:o,fragment:s,attributes:[{name:"position",type:"vec4"},{name:"id",type:"vec4"},{name:"vector",type:"vec3"}]}},{glslify:231}],82:[function(t,e,r){e.exports={0:"NONE",1:"ONE",2:"LINE_LOOP",3:"LINE_STRIP",4:"TRIANGLES",5:"TRIANGLE_STRIP",6:"TRIANGLE_FAN",256:"DEPTH_BUFFER_BIT",512:"NEVER",513:"LESS",514:"EQUAL",515:"LEQUAL",516:"GREATER",517:"NOTEQUAL",518:"GEQUAL",519:"ALWAYS",768:"SRC_COLOR",769:"ONE_MINUS_SRC_COLOR",770:"SRC_ALPHA",771:"ONE_MINUS_SRC_ALPHA",772:"DST_ALPHA",773:"ONE_MINUS_DST_ALPHA",774:"DST_COLOR",775:"ONE_MINUS_DST_COLOR",776:"SRC_ALPHA_SATURATE",1024:"STENCIL_BUFFER_BIT",1028:"FRONT",1029:"BACK",1032:"FRONT_AND_BACK",1280:"INVALID_ENUM",1281:"INVALID_VALUE",1282:"INVALID_OPERATION",1285:"OUT_OF_MEMORY",1286:"INVALID_FRAMEBUFFER_OPERATION",2304:"CW",2305:"CCW",2849:"LINE_WIDTH",2884:"CULL_FACE",2885:"CULL_FACE_MODE",2886:"FRONT_FACE",2928:"DEPTH_RANGE",2929:"DEPTH_TEST",2930:"DEPTH_WRITEMASK",2931:"DEPTH_CLEAR_VALUE",2932:"DEPTH_FUNC",2960:"STENCIL_TEST",2961:"STENCIL_CLEAR_VALUE",2962:"STENCIL_FUNC",2963:"STENCIL_VALUE_MASK",2964:"STENCIL_FAIL",2965:"STENCIL_PASS_DEPTH_FAIL",2966:"STENCIL_PASS_DEPTH_PASS",2967:"STENCIL_REF",2968:"STENCIL_WRITEMASK",2978:"VIEWPORT",3024:"DITHER",3042:"BLEND",3088:"SCISSOR_BOX",3089:"SCISSOR_TEST",3106:"COLOR_CLEAR_VALUE",3107:"COLOR_WRITEMASK",3317:"UNPACK_ALIGNMENT",3333:"PACK_ALIGNMENT",3379:"MAX_TEXTURE_SIZE",3386:"MAX_VIEWPORT_DIMS",3408:"SUBPIXEL_BITS",3410:"RED_BITS",3411:"GREEN_BITS",3412:"BLUE_BITS",3413:"ALPHA_BITS",3414:"DEPTH_BITS",3415:"STENCIL_BITS",3553:"TEXTURE_2D",4352:"DONT_CARE",4353:"FASTEST",4354:"NICEST",5120:"BYTE",5121:"UNSIGNED_BYTE",5122:"SHORT",5123:"UNSIGNED_SHORT",5124:"INT",5125:"UNSIGNED_INT",5126:"FLOAT",5386:"INVERT",5890:"TEXTURE",6401:"STENCIL_INDEX",6402:"DEPTH_COMPONENT",6406:"ALPHA",6407:"RGB",6408:"RGBA",6409:"LUMINANCE",6410:"LUMINANCE_ALPHA",7680:"KEEP",7681:"REPLACE",7682:"INCR",7683:"DECR",7936:"VENDOR",7937:"RENDERER",7938:"VERSION",9728:"NEAREST",9729:"LINEAR",9984:"NEAREST_MIPMAP_NEAREST",9985:"LINEAR_MIPMAP_NEAREST",9986:"NEAREST_MIPMAP_LINEAR",9987:"LINEAR_MIPMAP_LINEAR",10240:"TEXTURE_MAG_FILTER",10241:"TEXTURE_MIN_FILTER",10242:"TEXTURE_WRAP_S",10243:"TEXTURE_WRAP_T",10497:"REPEAT",10752:"POLYGON_OFFSET_UNITS",16384:"COLOR_BUFFER_BIT",32769:"CONSTANT_COLOR",32770:"ONE_MINUS_CONSTANT_COLOR",32771:"CONSTANT_ALPHA",32772:"ONE_MINUS_CONSTANT_ALPHA",32773:"BLEND_COLOR",32774:"FUNC_ADD",32777:"BLEND_EQUATION_RGB",32778:"FUNC_SUBTRACT",32779:"FUNC_REVERSE_SUBTRACT",32819:"UNSIGNED_SHORT_4_4_4_4",32820:"UNSIGNED_SHORT_5_5_5_1",32823:"POLYGON_OFFSET_FILL",32824:"POLYGON_OFFSET_FACTOR",32854:"RGBA4",32855:"RGB5_A1",32873:"TEXTURE_BINDING_2D",32926:"SAMPLE_ALPHA_TO_COVERAGE",32928:"SAMPLE_COVERAGE",32936:"SAMPLE_BUFFERS",32937:"SAMPLES",32938:"SAMPLE_COVERAGE_VALUE",32939:"SAMPLE_COVERAGE_INVERT",32968:"BLEND_DST_RGB",32969:"BLEND_SRC_RGB",32970:"BLEND_DST_ALPHA",32971:"BLEND_SRC_ALPHA",33071:"CLAMP_TO_EDGE",33170:"GENERATE_MIPMAP_HINT",33189:"DEPTH_COMPONENT16",33306:"DEPTH_STENCIL_ATTACHMENT",33635:"UNSIGNED_SHORT_5_6_5",33648:"MIRRORED_REPEAT",33901:"ALIASED_POINT_SIZE_RANGE",33902:"ALIASED_LINE_WIDTH_RANGE",33984:"TEXTURE0",33985:"TEXTURE1",33986:"TEXTURE2",33987:"TEXTURE3",33988:"TEXTURE4",33989:"TEXTURE5",33990:"TEXTURE6",33991:"TEXTURE7",33992:"TEXTURE8",33993:"TEXTURE9",33994:"TEXTURE10",33995:"TEXTURE11",33996:"TEXTURE12",33997:"TEXTURE13",33998:"TEXTURE14",33999:"TEXTURE15",34e3:"TEXTURE16",34001:"TEXTURE17",34002:"TEXTURE18",34003:"TEXTURE19",34004:"TEXTURE20",34005:"TEXTURE21",34006:"TEXTURE22",34007:"TEXTURE23",34008:"TEXTURE24",34009:"TEXTURE25",34010:"TEXTURE26",34011:"TEXTURE27",34012:"TEXTURE28",34013:"TEXTURE29",34014:"TEXTURE30",34015:"TEXTURE31",34016:"ACTIVE_TEXTURE",34024:"MAX_RENDERBUFFER_SIZE",34041:"DEPTH_STENCIL",34055:"INCR_WRAP",34056:"DECR_WRAP",34067:"TEXTURE_CUBE_MAP",34068:"TEXTURE_BINDING_CUBE_MAP",34069:"TEXTURE_CUBE_MAP_POSITIVE_X",34070:"TEXTURE_CUBE_MAP_NEGATIVE_X",34071:"TEXTURE_CUBE_MAP_POSITIVE_Y",34072:"TEXTURE_CUBE_MAP_NEGATIVE_Y",34073:"TEXTURE_CUBE_MAP_POSITIVE_Z",34074:"TEXTURE_CUBE_MAP_NEGATIVE_Z",34076:"MAX_CUBE_MAP_TEXTURE_SIZE",34338:"VERTEX_ATTRIB_ARRAY_ENABLED",34339:"VERTEX_ATTRIB_ARRAY_SIZE",34340:"VERTEX_ATTRIB_ARRAY_STRIDE",34341:"VERTEX_ATTRIB_ARRAY_TYPE",34342:"CURRENT_VERTEX_ATTRIB",34373:"VERTEX_ATTRIB_ARRAY_POINTER",34466:"NUM_COMPRESSED_TEXTURE_FORMATS",34467:"COMPRESSED_TEXTURE_FORMATS",34660:"BUFFER_SIZE",34661:"BUFFER_USAGE",34816:"STENCIL_BACK_FUNC",34817:"STENCIL_BACK_FAIL",34818:"STENCIL_BACK_PASS_DEPTH_FAIL",34819:"STENCIL_BACK_PASS_DEPTH_PASS",34877:"BLEND_EQUATION_ALPHA",34921:"MAX_VERTEX_ATTRIBS",34922:"VERTEX_ATTRIB_ARRAY_NORMALIZED",34930:"MAX_TEXTURE_IMAGE_UNITS",34962:"ARRAY_BUFFER",34963:"ELEMENT_ARRAY_BUFFER",34964:"ARRAY_BUFFER_BINDING",34965:"ELEMENT_ARRAY_BUFFER_BINDING",34975:"VERTEX_ATTRIB_ARRAY_BUFFER_BINDING",35040:"STREAM_DRAW",35044:"STATIC_DRAW",35048:"DYNAMIC_DRAW",35632:"FRAGMENT_SHADER",35633:"VERTEX_SHADER",35660:"MAX_VERTEX_TEXTURE_IMAGE_UNITS",35661:"MAX_COMBINED_TEXTURE_IMAGE_UNITS",35663:"SHADER_TYPE",35664:"FLOAT_VEC2",35665:"FLOAT_VEC3",35666:"FLOAT_VEC4",35667:"INT_VEC2",35668:"INT_VEC3",35669:"INT_VEC4",35670:"BOOL",35671:"BOOL_VEC2",35672:"BOOL_VEC3",35673:"BOOL_VEC4",35674:"FLOAT_MAT2",35675:"FLOAT_MAT3",35676:"FLOAT_MAT4",35678:"SAMPLER_2D",35680:"SAMPLER_CUBE",35712:"DELETE_STATUS",35713:"COMPILE_STATUS",35714:"LINK_STATUS",35715:"VALIDATE_STATUS",35716:"INFO_LOG_LENGTH",35717:"ATTACHED_SHADERS",35718:"ACTIVE_UNIFORMS",35719:"ACTIVE_UNIFORM_MAX_LENGTH",35720:"SHADER_SOURCE_LENGTH",35721:"ACTIVE_ATTRIBUTES",35722:"ACTIVE_ATTRIBUTE_MAX_LENGTH",35724:"SHADING_LANGUAGE_VERSION",35725:"CURRENT_PROGRAM",36003:"STENCIL_BACK_REF",36004:"STENCIL_BACK_VALUE_MASK",36005:"STENCIL_BACK_WRITEMASK",36006:"FRAMEBUFFER_BINDING",36007:"RENDERBUFFER_BINDING",36048:"FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE",36049:"FRAMEBUFFER_ATTACHMENT_OBJECT_NAME",36050:"FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL",36051:"FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE",36053:"FRAMEBUFFER_COMPLETE",36054:"FRAMEBUFFER_INCOMPLETE_ATTACHMENT",36055:"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT",36057:"FRAMEBUFFER_INCOMPLETE_DIMENSIONS",36061:"FRAMEBUFFER_UNSUPPORTED",36064:"COLOR_ATTACHMENT0",36096:"DEPTH_ATTACHMENT",36128:"STENCIL_ATTACHMENT",36160:"FRAMEBUFFER",36161:"RENDERBUFFER",36162:"RENDERBUFFER_WIDTH",36163:"RENDERBUFFER_HEIGHT",36164:"RENDERBUFFER_INTERNAL_FORMAT",36168:"STENCIL_INDEX8",36176:"RENDERBUFFER_RED_SIZE",36177:"RENDERBUFFER_GREEN_SIZE",36178:"RENDERBUFFER_BLUE_SIZE",36179:"RENDERBUFFER_ALPHA_SIZE",36180:"RENDERBUFFER_DEPTH_SIZE",36181:"RENDERBUFFER_STENCIL_SIZE",36194:"RGB565",36336:"LOW_FLOAT",36337:"MEDIUM_FLOAT",36338:"HIGH_FLOAT",36339:"LOW_INT",36340:"MEDIUM_INT",36341:"HIGH_INT",36346:"SHADER_COMPILER",36347:"MAX_VERTEX_UNIFORM_VECTORS",36348:"MAX_VARYING_VECTORS",36349:"MAX_FRAGMENT_UNIFORM_VECTORS",37440:"UNPACK_FLIP_Y_WEBGL",37441:"UNPACK_PREMULTIPLY_ALPHA_WEBGL",37442:"CONTEXT_LOST_WEBGL",37443:"UNPACK_COLORSPACE_CONVERSION_WEBGL",37444:"BROWSER_DEFAULT_WEBGL"}},{}],83:[function(t,e,r){var n=t("./1.0/numbers");e.exports=function(t){return n[t]}},{"./1.0/numbers":82}],84:[function(t,e,r){"use strict";e.exports=function(t){var e=t.gl,r=n(e),o=i(e,[{buffer:r,type:e.FLOAT,size:3,offset:0,stride:40},{buffer:r,type:e.FLOAT,size:4,offset:12,stride:40},{buffer:r,type:e.FLOAT,size:3,offset:28,stride:40}]),l=a(e);l.attributes.position.location=0,l.attributes.color.location=1,l.attributes.offset.location=2;var c=new s(e,r,o,l);return c.update(t),c};var n=t("gl-buffer"),i=t("gl-vao"),a=t("./shaders/index"),o=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function s(t,e,r,n){this.gl=t,this.shader=n,this.buffer=e,this.vao=r,this.pixelRatio=1,this.bounds=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]],this.clipBounds=[[-1/0,-1/0,-1/0],[1/0,1/0,1/0]],this.lineWidth=[1,1,1],this.capSize=[10,10,10],this.lineCount=[0,0,0],this.lineOffset=[0,0,0],this.opacity=1,this.hasAlpha=!1}var l=s.prototype;function c(t,e){for(var r=0;r<3;++r)t[0][r]=Math.min(t[0][r],e[r]),t[1][r]=Math.max(t[1][r],e[r])}l.isOpaque=function(){return!this.hasAlpha},l.isTransparent=function(){return this.hasAlpha},l.drawTransparent=l.draw=function(t){var e=this.gl,r=this.shader.uniforms;this.shader.bind();var n=r.view=t.view||o,i=r.projection=t.projection||o;r.model=t.model||o,r.clipBounds=this.clipBounds,r.opacity=this.opacity;var a=n[12],s=n[13],l=n[14],c=n[15],u=(t._ortho||!1?2:1)*this.pixelRatio*(i[3]*a+i[7]*s+i[11]*l+i[15]*c)/e.drawingBufferHeight;this.vao.bind();for(var f=0;f<3;++f)e.lineWidth(this.lineWidth[f]*this.pixelRatio),r.capSize=this.capSize[f]*u,this.lineCount[f]&&e.drawArrays(e.LINES,this.lineOffset[f],this.lineCount[f]);this.vao.unbind()};var u=function(){for(var t=new Array(3),e=0;e<3;++e){for(var r=[],n=1;n<=2;++n)for(var i=-1;i<=1;i+=2){var a=[0,0,0];a[(n+e)%3]=i,r.push(a)}t[e]=r}return t}();function f(t,e,r,n){for(var i=u[n],a=0;a<i.length;++a){var o=i[a];t.push(e[0],e[1],e[2],r[0],r[1],r[2],r[3],o[0],o[1],o[2])}return i.length}l.update=function(t){"lineWidth"in(t=t||{})&&(this.lineWidth=t.lineWidth,Array.isArray(this.lineWidth)||(this.lineWidth=[this.lineWidth,this.lineWidth,this.lineWidth])),"capSize"in t&&(this.capSize=t.capSize,Array.isArray(this.capSize)||(this.capSize=[this.capSize,this.capSize,this.capSize])),this.hasAlpha=!1,"opacity"in t&&(this.opacity=+t.opacity,this.opacity<1&&(this.hasAlpha=!0));var e=t.color||[[0,0,0],[0,0,0],[0,0,0]],r=t.position,n=t.error;if(Array.isArray(e[0])||(e=[e,e,e]),r&&n){var i=[],a=r.length,o=0;this.bounds=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]],this.lineCount=[0,0,0];for(var s=0;s<3;++s){this.lineOffset[s]=o;t:for(var l=0;l<a;++l){for(var u=r[l],h=0;h<3;++h)if(isNaN(u[h])||!isFinite(u[h]))continue t;var p=n[l],d=e[s];if(Array.isArray(d[0])&&(d=e[l]),3===d.length?d=[d[0],d[1],d[2],1]:4===d.length&&(d=[d[0],d[1],d[2],d[3]],!this.hasAlpha&&d[3]<1&&(this.hasAlpha=!0)),!isNaN(p[0][s])&&!isNaN(p[1][s])){var m;if(p[0][s]<0)(m=u.slice())[s]+=p[0][s],i.push(u[0],u[1],u[2],d[0],d[1],d[2],d[3],0,0,0,m[0],m[1],m[2],d[0],d[1],d[2],d[3],0,0,0),c(this.bounds,m),o+=2+f(i,m,d,s);if(p[1][s]>0)(m=u.slice())[s]+=p[1][s],i.push(u[0],u[1],u[2],d[0],d[1],d[2],d[3],0,0,0,m[0],m[1],m[2],d[0],d[1],d[2],d[3],0,0,0),c(this.bounds,m),o+=2+f(i,m,d,s)}}this.lineCount[s]=o-this.lineOffset[s]}this.buffer.update(i)}},l.dispose=function(){this.shader.dispose(),this.buffer.dispose(),this.vao.dispose()}},{"./shaders/index":85,"gl-buffer":78,"gl-vao":150}],85:[function(t,e,r){"use strict";var n=t("glslify"),i=t("gl-shader"),a=n(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec3 position, offset;\nattribute vec4 color;\nuniform mat4 model, view, projection;\nuniform float capSize;\nvarying vec4 fragColor;\nvarying vec3 fragPosition;\n\nvoid main() {\n  vec4 worldPosition  = model * vec4(position, 1.0);\n  worldPosition       = (worldPosition / worldPosition.w) + vec4(capSize * offset, 0.0);\n  gl_Position         = projection * view * worldPosition;\n  fragColor           = color;\n  fragPosition        = position;\n}"]),o=n(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec3 clipBounds[2];\nuniform float opacity;\nvarying vec3 fragPosition;\nvarying vec4 fragColor;\n\nvoid main() {\n  if (\n    outOfRange(clipBounds[0], clipBounds[1], fragPosition) ||\n    fragColor.a * opacity == 0.\n  ) discard;\n\n  gl_FragColor = opacity * fragColor;\n}"]);e.exports=function(t){return i(t,a,o,null,[{name:"position",type:"vec3"},{name:"color",type:"vec4"},{name:"offset",type:"vec3"}])}},{"gl-shader":132,glslify:231}],86:[function(t,e,r){"use strict";var n=t("gl-texture2d");e.exports=function(t,e,r,n){i||(i=t.FRAMEBUFFER_UNSUPPORTED,a=t.FRAMEBUFFER_INCOMPLETE_ATTACHMENT,o=t.FRAMEBUFFER_INCOMPLETE_DIMENSIONS,s=t.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT);var c=t.getExtension("WEBGL_draw_buffers");!l&&c&&function(t,e){var r=t.getParameter(e.MAX_COLOR_ATTACHMENTS_WEBGL);l=new Array(r+1);for(var n=0;n<=r;++n){for(var i=new Array(r),a=0;a<n;++a)i[a]=t.COLOR_ATTACHMENT0+a;for(a=n;a<r;++a)i[a]=t.NONE;l[n]=i}}(t,c);Array.isArray(e)&&(n=r,r=0|e[1],e=0|e[0]);if("number"!=typeof e)throw new Error("gl-fbo: Missing shape parameter");var u=t.getParameter(t.MAX_RENDERBUFFER_SIZE);if(e<0||e>u||r<0||r>u)throw new Error("gl-fbo: Parameters are too large for FBO");var f=1;if("color"in(n=n||{})){if((f=Math.max(0|n.color,0))<0)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(f>1){if(!c)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(f>t.getParameter(c.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+f+" draw buffers")}}var h=t.UNSIGNED_BYTE,p=t.getExtension("OES_texture_float");if(n.float&&f>0){if(!p)throw new Error("gl-fbo: Context does not support floating point textures");h=t.FLOAT}else n.preferFloat&&f>0&&p&&(h=t.FLOAT);var m=!0;"depth"in n&&(m=!!n.depth);var g=!1;"stencil"in n&&(g=!!n.stencil);return new d(t,e,r,h,f,m,g,c)};var i,a,o,s,l=null;function c(t){return[t.getParameter(t.FRAMEBUFFER_BINDING),t.getParameter(t.RENDERBUFFER_BINDING),t.getParameter(t.TEXTURE_BINDING_2D)]}function u(t,e){t.bindFramebuffer(t.FRAMEBUFFER,e[0]),t.bindRenderbuffer(t.RENDERBUFFER,e[1]),t.bindTexture(t.TEXTURE_2D,e[2])}function f(t){switch(t){case i:throw new Error("gl-fbo: Framebuffer unsupported");case a:throw new Error("gl-fbo: Framebuffer incomplete attachment");case o:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case s:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function h(t,e,r,i,a,o){if(!i)return null;var s=n(t,e,r,a,i);return s.magFilter=t.NEAREST,s.minFilter=t.NEAREST,s.mipSamples=1,s.bind(),t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,s.handle,0),s}function p(t,e,r,n,i){var a=t.createRenderbuffer();return t.bindRenderbuffer(t.RENDERBUFFER,a),t.renderbufferStorage(t.RENDERBUFFER,n,e,r),t.framebufferRenderbuffer(t.FRAMEBUFFER,i,t.RENDERBUFFER,a),a}function d(t,e,r,n,i,a,o,s){this.gl=t,this._shape=[0|e,0|r],this._destroyed=!1,this._ext=s,this.color=new Array(i);for(var d=0;d<i;++d)this.color[d]=null;this._color_rb=null,this.depth=null,this._depth_rb=null,this._colorType=n,this._useDepth=a,this._useStencil=o;var m=this,g=[0|e,0|r];Object.defineProperties(g,{0:{get:function(){return m._shape[0]},set:function(t){return m.width=t}},1:{get:function(){return m._shape[1]},set:function(t){return m.height=t}}}),this._shapeVector=g,function(t){var e=c(t.gl),r=t.gl,n=t.handle=r.createFramebuffer(),i=t._shape[0],a=t._shape[1],o=t.color.length,s=t._ext,d=t._useStencil,m=t._useDepth,g=t._colorType;r.bindFramebuffer(r.FRAMEBUFFER,n);for(var v=0;v<o;++v)t.color[v]=h(r,i,a,g,r.RGBA,r.COLOR_ATTACHMENT0+v);0===o?(t._color_rb=p(r,i,a,r.RGBA4,r.COLOR_ATTACHMENT0),s&&s.drawBuffersWEBGL(l[0])):o>1&&s.drawBuffersWEBGL(l[o]);var y=r.getExtension("WEBGL_depth_texture");y?d?t.depth=h(r,i,a,y.UNSIGNED_INT_24_8_WEBGL,r.DEPTH_STENCIL,r.DEPTH_STENCIL_ATTACHMENT):m&&(t.depth=h(r,i,a,r.UNSIGNED_SHORT,r.DEPTH_COMPONENT,r.DEPTH_ATTACHMENT)):m&&d?t._depth_rb=p(r,i,a,r.DEPTH_STENCIL,r.DEPTH_STENCIL_ATTACHMENT):m?t._depth_rb=p(r,i,a,r.DEPTH_COMPONENT16,r.DEPTH_ATTACHMENT):d&&(t._depth_rb=p(r,i,a,r.STENCIL_INDEX,r.STENCIL_ATTACHMENT));var x=r.checkFramebufferStatus(r.FRAMEBUFFER);if(x!==r.FRAMEBUFFER_COMPLETE){t._destroyed=!0,r.bindFramebuffer(r.FRAMEBUFFER,null),r.deleteFramebuffer(t.handle),t.handle=null,t.depth&&(t.depth.dispose(),t.depth=null),t._depth_rb&&(r.deleteRenderbuffer(t._depth_rb),t._depth_rb=null);for(v=0;v<t.color.length;++v)t.color[v].dispose(),t.color[v]=null;t._color_rb&&(r.deleteRenderbuffer(t._color_rb),t._color_rb=null),u(r,e),f(x)}u(r,e)}(this)}var m=d.prototype;function g(t,e,r){if(t._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(t._shape[0]!==e||t._shape[1]!==r){var n=t.gl,i=n.getParameter(n.MAX_RENDERBUFFER_SIZE);if(e<0||e>i||r<0||r>i)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");t._shape[0]=e,t._shape[1]=r;for(var a=c(n),o=0;o<t.color.length;++o)t.color[o].shape=t._shape;t._color_rb&&(n.bindRenderbuffer(n.RENDERBUFFER,t._color_rb),n.renderbufferStorage(n.RENDERBUFFER,n.RGBA4,t._shape[0],t._shape[1])),t.depth&&(t.depth.shape=t._shape),t._depth_rb&&(n.bindRenderbuffer(n.RENDERBUFFER,t._depth_rb),t._useDepth&&t._useStencil?n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_STENCIL,t._shape[0],t._shape[1]):t._useDepth?n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_COMPONENT16,t._shape[0],t._shape[1]):t._useStencil&&n.renderbufferStorage(n.RENDERBUFFER,n.STENCIL_INDEX,t._shape[0],t._shape[1])),n.bindFramebuffer(n.FRAMEBUFFER,t.handle);var s=n.checkFramebufferStatus(n.FRAMEBUFFER);s!==n.FRAMEBUFFER_COMPLETE&&(t.dispose(),u(n,a),f(s)),u(n,a)}}Object.defineProperties(m,{shape:{get:function(){return this._destroyed?[0,0]:this._shapeVector},set:function(t){if(Array.isArray(t)||(t=[0|t,0|t]),2!==t.length)throw new Error("gl-fbo: Shape vector must be length 2");var e=0|t[0],r=0|t[1];return g(this,e,r),[e,r]},enumerable:!1},width:{get:function(){return this._destroyed?0:this._shape[0]},set:function(t){return g(this,t|=0,this._shape[1]),t},enumerable:!1},height:{get:function(){return this._destroyed?0:this._shape[1]},set:function(t){return t|=0,g(this,this._shape[0],t),t},enumerable:!1}}),m.bind=function(){if(!this._destroyed){var t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.handle),t.viewport(0,0,this._shape[0],this._shape[1])}},m.dispose=function(){if(!this._destroyed){this._destroyed=!0;var t=this.gl;t.deleteFramebuffer(this.handle),this.handle=null,this.depth&&(this.depth.dispose(),this.depth=null),this._depth_rb&&(t.deleteRenderbuffer(this._depth_rb),this._depth_rb=null);for(var e=0;e<this.color.length;++e)this.color[e].dispose(),this.color[e]=null;this._color_rb&&(t.deleteRenderbuffer(this._color_rb),this._color_rb=null)}}},{"gl-texture2d":146}],87:[function(t,e,r){var n=t("sprintf-js").sprintf,i=t("gl-constants/lookup"),a=t("glsl-shader-name"),o=t("add-line-numbers");e.exports=function(t,e,r){"use strict";var s=a(e)||"of unknown name (see npm glsl-shader-name)",l="unknown type";void 0!==r&&(l=r===i.FRAGMENT_SHADER?"fragment":"vertex");for(var c=n("Error compiling %s shader %s:\n",l,s),u=n("%s%s",c,t),f=t.split("\n"),h={},p=0;p<f.length;p++){var d=f[p];if(""!==d&&"\0"!==d){var m=parseInt(d.split(":")[2]);if(isNaN(m))throw new Error(n("Could not parse error: %s",d));h[m]=d}}var g=o(e).split("\n");for(p=0;p<g.length;p++)if(h[p+3]||h[p+2]||h[p+1]){var v=g[p];if(c+=v+"\n",h[p+1]){var y=h[p+1];y=y.substr(y.split(":",3).join(":").length+1).trim(),c+=n("^^^ %s\n\n",y)}}return{long:c.trim(),short:u.trim()}}},{"add-line-numbers":9,"gl-constants/lookup":83,"glsl-shader-name":223,"sprintf-js":301}],88:[function(t,e,r){"use strict";e.exports=function(t,e){var r=t.gl,n=o(r,l.vertex,l.fragment),i=o(r,l.pickVertex,l.pickFragment),a=s(r),u=s(r),f=s(r),h=s(r),p=new c(t,n,i,a,u,f,h);return p.update(e),t.addObject(p),p};var n=t("binary-search-bounds"),i=t("iota-array"),a=t("typedarray-pool"),o=t("gl-shader"),s=t("gl-buffer"),l=t("./lib/shaders");function c(t,e,r,n,i,a,o){this.plot=t,this.shader=e,this.pickShader=r,this.positionBuffer=n,this.weightBuffer=i,this.colorBuffer=a,this.idBuffer=o,this.xData=[],this.yData=[],this.shape=[0,0],this.bounds=[1/0,1/0,-1/0,-1/0],this.pickOffset=0}var u,f=c.prototype,h=[0,0,1,0,0,1,1,0,1,1,0,1];f.draw=(u=[1,0,0,0,1,0,0,0,1],function(){var t=this.plot,e=this.shader,r=this.bounds,n=this.numVertices;if(!(n<=0)){var i=t.gl,a=t.dataBox,o=r[2]-r[0],s=r[3]-r[1],l=a[2]-a[0],c=a[3]-a[1];u[0]=2*o/l,u[4]=2*s/c,u[6]=2*(r[0]-a[0])/l-1,u[7]=2*(r[1]-a[1])/c-1,e.bind();var f=e.uniforms;f.viewTransform=u,f.shape=this.shape;var h=e.attributes;this.positionBuffer.bind(),h.position.pointer(),this.weightBuffer.bind(),h.weight.pointer(i.UNSIGNED_BYTE,!1),this.colorBuffer.bind(),h.color.pointer(i.UNSIGNED_BYTE,!0),i.drawArrays(i.TRIANGLES,0,n)}}),f.drawPick=function(){var t=[1,0,0,0,1,0,0,0,1],e=[0,0,0,0];return function(r){var n=this.plot,i=this.pickShader,a=this.bounds,o=this.numVertices;if(!(o<=0)){var s=n.gl,l=n.dataBox,c=a[2]-a[0],u=a[3]-a[1],f=l[2]-l[0],h=l[3]-l[1];t[0]=2*c/f,t[4]=2*u/h,t[6]=2*(a[0]-l[0])/f-1,t[7]=2*(a[1]-l[1])/h-1;for(var p=0;p<4;++p)e[p]=r>>8*p&255;this.pickOffset=r,i.bind();var d=i.uniforms;d.viewTransform=t,d.pickOffset=e,d.shape=this.shape;var m=i.attributes;return this.positionBuffer.bind(),m.position.pointer(),this.weightBuffer.bind(),m.weight.pointer(s.UNSIGNED_BYTE,!1),this.idBuffer.bind(),m.pickId.pointer(s.UNSIGNED_BYTE,!1),s.drawArrays(s.TRIANGLES,0,o),r+this.shape[0]*this.shape[1]}}}(),f.pick=function(t,e,r){var n=this.pickOffset,i=this.shape[0]*this.shape[1];if(r<n||r>=n+i)return null;var a=r-n,o=this.xData,s=this.yData;return{object:this,pointId:a,dataCoord:[o[a%this.shape[0]],s[a/this.shape[0]|0]]}},f.update=function(t){var e=(t=t||{}).shape||[0,0],r=t.x||i(e[0]),o=t.y||i(e[1]),s=t.z||new Float32Array(e[0]*e[1]),l=!1!==t.zsmooth;this.xData=r,this.yData=o;var c,u,f,p,d=t.colorLevels||[0],m=t.colorValues||[0,0,0,1],g=d.length,v=this.bounds;l?(c=v[0]=r[0],u=v[1]=o[0],f=v[2]=r[r.length-1],p=v[3]=o[o.length-1]):(c=v[0]=r[0]+(r[1]-r[0])/2,u=v[1]=o[0]+(o[1]-o[0])/2,f=v[2]=r[r.length-1]+(r[r.length-1]-r[r.length-2])/2,p=v[3]=o[o.length-1]+(o[o.length-1]-o[o.length-2])/2);var y=1/(f-c),x=1/(p-u),b=e[0],_=e[1];this.shape=[b,_];var w=(l?(b-1)*(_-1):b*_)*(h.length>>>1);this.numVertices=w;for(var T=a.mallocUint8(4*w),k=a.mallocFloat32(2*w),A=a.mallocUint8(2*w),M=a.mallocUint32(w),S=0,E=l?b-1:b,L=l?_-1:_,C=0;C<L;++C){var P,I;l?(P=x*(o[C]-u),I=x*(o[C+1]-u)):(P=C<_-1?x*(o[C]-(o[C+1]-o[C])/2-u):x*(o[C]-(o[C]-o[C-1])/2-u),I=C<_-1?x*(o[C]+(o[C+1]-o[C])/2-u):x*(o[C]+(o[C]-o[C-1])/2-u));for(var O=0;O<E;++O){var z,D;l?(z=y*(r[O]-c),D=y*(r[O+1]-c)):(z=O<b-1?y*(r[O]-(r[O+1]-r[O])/2-c):y*(r[O]-(r[O]-r[O-1])/2-c),D=O<b-1?y*(r[O]+(r[O+1]-r[O])/2-c):y*(r[O]+(r[O]-r[O-1])/2-c));for(var R=0;R<h.length;R+=2){var F,B,N,j,U=h[R],V=h[R+1],H=s[l?(C+V)*b+(O+U):C*b+O],q=n.le(d,H);if(q<0)F=m[0],B=m[1],N=m[2],j=m[3];else if(q===g-1)F=m[4*g-4],B=m[4*g-3],N=m[4*g-2],j=m[4*g-1];else{var G=(H-d[q])/(d[q+1]-d[q]),Y=1-G,W=4*q,X=4*(q+1);F=Y*m[W]+G*m[X],B=Y*m[W+1]+G*m[X+1],N=Y*m[W+2]+G*m[X+2],j=Y*m[W+3]+G*m[X+3]}T[4*S]=255*F,T[4*S+1]=255*B,T[4*S+2]=255*N,T[4*S+3]=255*j,k[2*S]=.5*z+.5*D,k[2*S+1]=.5*P+.5*I,A[2*S]=U,A[2*S+1]=V,M[S]=C*b+O,S+=1}}}this.positionBuffer.update(k),this.weightBuffer.update(A),this.colorBuffer.update(T),this.idBuffer.update(M),a.free(k),a.free(T),a.free(A),a.free(M)},f.dispose=function(){this.shader.dispose(),this.pickShader.dispose(),this.positionBuffer.dispose(),this.weightBuffer.dispose(),this.colorBuffer.dispose(),this.idBuffer.dispose(),this.plot.removeObject(this)}},{"./lib/shaders":89,"binary-search-bounds":31,"gl-buffer":78,"gl-shader":132,"iota-array":235,"typedarray-pool":308}],89:[function(t,e,r){"use strict";var n=t("glslify");e.exports={fragment:n(["precision lowp float;\n#define GLSLIFY 1\nvarying vec4 fragColor;\nvoid main() {\n  gl_FragColor = vec4(fragColor.rgb * fragColor.a, fragColor.a);\n}\n"]),vertex:n(["precision mediump float;\n#define GLSLIFY 1\n\nattribute vec2 position;\nattribute vec4 color;\nattribute vec2 weight;\n\nuniform vec2 shape;\nuniform mat3 viewTransform;\n\nvarying vec4 fragColor;\n\nvoid main() {\n  vec3 vPosition = viewTransform * vec3( position + (weight-.5)/(shape-1.) , 1.0);\n  fragColor = color;\n  gl_Position = vec4(vPosition.xy, 0, vPosition.z);\n}\n"]),pickFragment:n(["precision mediump float;\n#define GLSLIFY 1\n\nvarying vec4 fragId;\nvarying vec2 vWeight;\n\nuniform vec2 shape;\nuniform vec4 pickOffset;\n\nvoid main() {\n  vec2 d = step(.5, vWeight);\n  vec4 id = fragId + pickOffset;\n  id.x += d.x + d.y*shape.x;\n\n  id.y += floor(id.x / 256.0);\n  id.x -= floor(id.x / 256.0) * 256.0;\n\n  id.z += floor(id.y / 256.0);\n  id.y -= floor(id.y / 256.0) * 256.0;\n\n  id.w += floor(id.z / 256.0);\n  id.z -= floor(id.z / 256.0) * 256.0;\n\n  gl_FragColor = id/255.;\n}\n"]),pickVertex:n(["precision mediump float;\n#define GLSLIFY 1\n\nattribute vec2 position;\nattribute vec4 pickId;\nattribute vec2 weight;\n\nuniform vec2 shape;\nuniform mat3 viewTransform;\n\nvarying vec4 fragId;\nvarying vec2 vWeight;\n\nvoid main() {\n  vWeight = weight;\n\n  fragId = pickId;\n\n  vec3 vPosition = viewTransform * vec3( position + (weight-.5)/(shape-1.) , 1.0);\n  gl_Position = vec4(vPosition.xy, 0, vPosition.z);\n}\n"])}},{glslify:231}],90:[function(t,e,r){var n=t("glslify"),i=t("gl-shader"),a=n(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec3 position, nextPosition;\nattribute float arcLength, lineWidth;\nattribute vec4 color;\n\nuniform vec2 screenShape;\nuniform float pixelRatio;\nuniform mat4 model, view, projection;\n\nvarying vec4 fragColor;\nvarying vec3 worldPosition;\nvarying float pixelArcLength;\n\nvec4 project(vec3 p) {\n  return projection * view * model * vec4(p, 1.0);\n}\n\nvoid main() {\n  vec4 startPoint = project(position);\n  vec4 endPoint   = project(nextPosition);\n\n  vec2 A = startPoint.xy / startPoint.w;\n  vec2 B =   endPoint.xy /   endPoint.w;\n\n  float clipAngle = atan(\n    (B.y - A.y) * screenShape.y,\n    (B.x - A.x) * screenShape.x\n  );\n\n  vec2 offset = 0.5 * pixelRatio * lineWidth * vec2(\n    sin(clipAngle),\n    -cos(clipAngle)\n  ) / screenShape;\n\n  gl_Position = vec4(startPoint.xy + startPoint.w * offset, startPoint.zw);\n\n  worldPosition = position;\n  pixelArcLength = arcLength;\n  fragColor = color;\n}\n"]),o=n(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec3      clipBounds[2];\nuniform sampler2D dashTexture;\nuniform float     dashScale;\nuniform float     opacity;\n\nvarying vec3    worldPosition;\nvarying float   pixelArcLength;\nvarying vec4    fragColor;\n\nvoid main() {\n  if (\n    outOfRange(clipBounds[0], clipBounds[1], worldPosition) ||\n    fragColor.a * opacity == 0.\n  ) discard;\n\n  float dashWeight = texture2D(dashTexture, vec2(dashScale * pixelArcLength, 0)).r;\n  if(dashWeight < 0.5) {\n    discard;\n  }\n  gl_FragColor = fragColor * opacity;\n}\n"]),s=n(["precision highp float;\n#define GLSLIFY 1\n\n#define FLOAT_MAX  1.70141184e38\n#define FLOAT_MIN  1.17549435e-38\n\n// https://github.com/mikolalysenko/glsl-read-float/blob/master/index.glsl\nvec4 packFloat(float v) {\n  float av = abs(v);\n\n  //Handle special cases\n  if(av < FLOAT_MIN) {\n    return vec4(0.0, 0.0, 0.0, 0.0);\n  } else if(v > FLOAT_MAX) {\n    return vec4(127.0, 128.0, 0.0, 0.0) / 255.0;\n  } else if(v < -FLOAT_MAX) {\n    return vec4(255.0, 128.0, 0.0, 0.0) / 255.0;\n  }\n\n  vec4 c = vec4(0,0,0,0);\n\n  //Compute exponent and mantissa\n  float e = floor(log2(av));\n  float m = av * pow(2.0, -e) - 1.0;\n\n  //Unpack mantissa\n  c[1] = floor(128.0 * m);\n  m -= c[1] / 128.0;\n  c[2] = floor(32768.0 * m);\n  m -= c[2] / 32768.0;\n  c[3] = floor(8388608.0 * m);\n\n  //Unpack exponent\n  float ebias = e + 127.0;\n  c[0] = floor(ebias / 2.0);\n  ebias -= c[0] * 2.0;\n  c[1] += floor(ebias) * 128.0;\n\n  //Unpack sign bit\n  c[0] += 128.0 * step(0.0, -v);\n\n  //Scale back to range\n  return c / 255.0;\n}\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform float pickId;\nuniform vec3 clipBounds[2];\n\nvarying vec3 worldPosition;\nvarying float pixelArcLength;\nvarying vec4 fragColor;\n\nvoid main() {\n  if (outOfRange(clipBounds[0], clipBounds[1], worldPosition)) discard;\n\n  gl_FragColor = vec4(pickId/255.0, packFloat(pixelArcLength).xyz);\n}"]),l=[{name:"position",type:"vec3"},{name:"nextPosition",type:"vec3"},{name:"arcLength",type:"float"},{name:"lineWidth",type:"float"},{name:"color",type:"vec4"}];r.createShader=function(t){return i(t,a,o,null,l)},r.createPickShader=function(t){return i(t,a,s,null,l)}},{"gl-shader":132,glslify:231}],91:[function(t,e,r){"use strict";e.exports=function(t){var e=t.gl||t.scene&&t.scene.gl,r=f(e);r.attributes.position.location=0,r.attributes.nextPosition.location=1,r.attributes.arcLength.location=2,r.attributes.lineWidth.location=3,r.attributes.color.location=4;var o=h(e);o.attributes.position.location=0,o.attributes.nextPosition.location=1,o.attributes.arcLength.location=2,o.attributes.lineWidth.location=3,o.attributes.color.location=4;for(var s=n(e),l=i(e,[{buffer:s,size:3,offset:0,stride:48},{buffer:s,size:3,offset:12,stride:48},{buffer:s,size:1,offset:24,stride:48},{buffer:s,size:1,offset:28,stride:48},{buffer:s,size:4,offset:32,stride:48}]),u=c(new Array(1024),[256,1,4]),p=0;p<1024;++p)u.data[p]=255;var d=a(e,u);d.wrap=e.REPEAT;var m=new v(e,r,o,s,l,d);return m.update(t),m};var n=t("gl-buffer"),i=t("gl-vao"),a=t("gl-texture2d"),o=new Uint8Array(4),s=new Float32Array(o.buffer);var l=t("binary-search-bounds"),c=t("ndarray"),u=t("./lib/shaders"),f=u.createShader,h=u.createPickShader,p=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function d(t,e){for(var r=0,n=0;n<3;++n){var i=t[n]-e[n];r+=i*i}return Math.sqrt(r)}function m(t){for(var e=[[-1e6,-1e6,-1e6],[1e6,1e6,1e6]],r=0;r<3;++r)e[0][r]=Math.max(t[0][r],e[0][r]),e[1][r]=Math.min(t[1][r],e[1][r]);return e}function g(t,e,r,n){this.arcLength=t,this.position=e,this.index=r,this.dataCoordinate=n}function v(t,e,r,n,i,a){this.gl=t,this.shader=e,this.pickShader=r,this.buffer=n,this.vao=i,this.clipBounds=[[-1/0,-1/0,-1/0],[1/0,1/0,1/0]],this.points=[],this.arcLength=[],this.vertexCount=0,this.bounds=[[0,0,0],[0,0,0]],this.pickId=0,this.lineWidth=1,this.texture=a,this.dashScale=1,this.opacity=1,this.hasAlpha=!1,this.dirty=!0,this.pixelRatio=1}var y=v.prototype;y.isTransparent=function(){return this.hasAlpha},y.isOpaque=function(){return!this.hasAlpha},y.pickSlots=1,y.setPickBase=function(t){this.pickId=t},y.drawTransparent=y.draw=function(t){if(this.vertexCount){var e=this.gl,r=this.shader,n=this.vao;r.bind(),r.uniforms={model:t.model||p,view:t.view||p,projection:t.projection||p,clipBounds:m(this.clipBounds),dashTexture:this.texture.bind(),dashScale:this.dashScale/this.arcLength[this.arcLength.length-1],opacity:this.opacity,screenShape:[e.drawingBufferWidth,e.drawingBufferHeight],pixelRatio:this.pixelRatio},n.bind(),n.draw(e.TRIANGLE_STRIP,this.vertexCount),n.unbind()}},y.drawPick=function(t){if(this.vertexCount){var e=this.gl,r=this.pickShader,n=this.vao;r.bind(),r.uniforms={model:t.model||p,view:t.view||p,projection:t.projection||p,pickId:this.pickId,clipBounds:m(this.clipBounds),screenShape:[e.drawingBufferWidth,e.drawingBufferHeight],pixelRatio:this.pixelRatio},n.bind(),n.draw(e.TRIANGLE_STRIP,this.vertexCount),n.unbind()}},y.update=function(t){var e,r;this.dirty=!0;var n=!!t.connectGaps;"dashScale"in t&&(this.dashScale=t.dashScale),this.hasAlpha=!1,"opacity"in t&&(this.opacity=+t.opacity,this.opacity<1&&(this.hasAlpha=!0));var i=[],a=[],o=[],s=0,u=0,f=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]],h=t.position||t.positions;if(h){var p=t.color||t.colors||[0,0,0,1],m=t.lineWidth||1,g=!1;t:for(e=1;e<h.length;++e){var v,y,x,b=h[e-1],_=h[e];for(a.push(s),o.push(b.slice()),r=0;r<3;++r){if(isNaN(b[r])||isNaN(_[r])||!isFinite(b[r])||!isFinite(_[r])){if(!n&&i.length>0){for(var w=0;w<24;++w)i.push(i[i.length-12]);u+=2,g=!0}continue t}f[0][r]=Math.min(f[0][r],b[r],_[r]),f[1][r]=Math.max(f[1][r],b[r],_[r])}Array.isArray(p[0])?(v=p.length>e-1?p[e-1]:p.length>0?p[p.length-1]:[0,0,0,1],y=p.length>e?p[e]:p.length>0?p[p.length-1]:[0,0,0,1]):v=y=p,3===v.length&&(v=[v[0],v[1],v[2],1]),3===y.length&&(y=[y[0],y[1],y[2],1]),!this.hasAlpha&&v[3]<1&&(this.hasAlpha=!0),x=Array.isArray(m)?m.length>e-1?m[e-1]:m.length>0?m[m.length-1]:[0,0,0,1]:m;var T=s;if(s+=d(b,_),g){for(r=0;r<2;++r)i.push(b[0],b[1],b[2],_[0],_[1],_[2],T,x,v[0],v[1],v[2],v[3]);u+=2,g=!1}i.push(b[0],b[1],b[2],_[0],_[1],_[2],T,x,v[0],v[1],v[2],v[3],b[0],b[1],b[2],_[0],_[1],_[2],T,-x,v[0],v[1],v[2],v[3],_[0],_[1],_[2],b[0],b[1],b[2],s,-x,y[0],y[1],y[2],y[3],_[0],_[1],_[2],b[0],b[1],b[2],s,x,y[0],y[1],y[2],y[3]),u+=4}}if(this.buffer.update(i),a.push(s),o.push(h[h.length-1].slice()),this.bounds=f,this.vertexCount=u,this.points=o,this.arcLength=a,"dashes"in t){var k=t.dashes.slice();for(k.unshift(0),e=1;e<k.length;++e)k[e]=k[e-1]+k[e];var A=c(new Array(1024),[256,1,4]);for(e=0;e<256;++e){for(r=0;r<4;++r)A.set(e,0,r,0);1&l.le(k,k[k.length-1]*e/255)?A.set(e,0,0,0):A.set(e,0,0,255)}this.texture.setPixels(A)}},y.dispose=function(){this.shader.dispose(),this.vao.dispose(),this.buffer.dispose()},y.pick=function(t){if(!t)return null;if(t.id!==this.pickId)return null;var e=function(t,e,r,n){return o[0]=n,o[1]=r,o[2]=e,o[3]=t,s[0]}(t.value[0],t.value[1],t.value[2],0),r=l.le(this.arcLength,e);if(r<0)return null;if(r===this.arcLength.length-1)return new g(this.arcLength[this.arcLength.length-1],this.points[this.points.length-1].slice(),r);for(var n=this.points[r],i=this.points[Math.min(r+1,this.points.length-1)],a=(e-this.arcLength[r])/(this.arcLength[r+1]-this.arcLength[r]),c=1-a,u=[0,0,0],f=0;f<3;++f)u[f]=c*n[f]+a*i[f];var h=Math.min(a<.5?r:r+1,this.points.length-1);return new g(e,u,h,this.points[h])}},{"./lib/shaders":90,"binary-search-bounds":31,"gl-buffer":78,"gl-texture2d":146,"gl-vao":150,ndarray:259}],92:[function(t,e,r){e.exports=function(t){var e=new Float32Array(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}},{}],93:[function(t,e,r){e.exports=function(){var t=new Float32Array(16);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}},{}],94:[function(t,e,r){e.exports=function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],l=t[7],c=t[8],u=t[9],f=t[10],h=t[11],p=t[12],d=t[13],m=t[14],g=t[15];return(e*o-r*a)*(f*g-h*m)-(e*s-n*a)*(u*g-h*d)+(e*l-i*a)*(u*m-f*d)+(r*s-n*o)*(c*g-h*p)-(r*l-i*o)*(c*m-f*p)+(n*l-i*s)*(c*d-u*p)}},{}],95:[function(t,e,r){e.exports=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r+r,s=n+n,l=i+i,c=r*o,u=n*o,f=n*s,h=i*o,p=i*s,d=i*l,m=a*o,g=a*s,v=a*l;return t[0]=1-f-d,t[1]=u+v,t[2]=h-g,t[3]=0,t[4]=u-v,t[5]=1-c-d,t[6]=p+m,t[7]=0,t[8]=h+g,t[9]=p-m,t[10]=1-c-f,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}},{}],96:[function(t,e,r){e.exports=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=n+n,l=i+i,c=a+a,u=n*s,f=n*l,h=n*c,p=i*l,d=i*c,m=a*c,g=o*s,v=o*l,y=o*c;return t[0]=1-(p+m),t[1]=f+y,t[2]=h-v,t[3]=0,t[4]=f-y,t[5]=1-(u+m),t[6]=d+g,t[7]=0,t[8]=h+v,t[9]=d-g,t[10]=1-(u+p),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}},{}],97:[function(t,e,r){e.exports=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}},{}],98:[function(t,e,r){e.exports=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],l=e[6],c=e[7],u=e[8],f=e[9],h=e[10],p=e[11],d=e[12],m=e[13],g=e[14],v=e[15],y=r*s-n*o,x=r*l-i*o,b=r*c-a*o,_=n*l-i*s,w=n*c-a*s,T=i*c-a*l,k=u*m-f*d,A=u*g-h*d,M=u*v-p*d,S=f*g-h*m,E=f*v-p*m,L=h*v-p*g,C=y*L-x*E+b*S+_*M-w*A+T*k;if(!C)return null;return C=1/C,t[0]=(s*L-l*E+c*S)*C,t[1]=(i*E-n*L-a*S)*C,t[2]=(m*T-g*w+v*_)*C,t[3]=(h*w-f*T-p*_)*C,t[4]=(l*M-o*L-c*A)*C,t[5]=(r*L-i*M+a*A)*C,t[6]=(g*b-d*T-v*x)*C,t[7]=(u*T-h*b+p*x)*C,t[8]=(o*E-s*M+c*k)*C,t[9]=(n*M-r*E-a*k)*C,t[10]=(d*w-m*b+v*y)*C,t[11]=(f*b-u*w-p*y)*C,t[12]=(s*A-o*S-l*k)*C,t[13]=(r*S-n*A+i*k)*C,t[14]=(m*x-d*_-g*y)*C,t[15]=(u*_-f*x+h*y)*C,t}},{}],99:[function(t,e,r){var n=t("./identity");e.exports=function(t,e,r,i){var a,o,s,l,c,u,f,h,p,d,m=e[0],g=e[1],v=e[2],y=i[0],x=i[1],b=i[2],_=r[0],w=r[1],T=r[2];if(Math.abs(m-_)<1e-6&&Math.abs(g-w)<1e-6&&Math.abs(v-T)<1e-6)return n(t);f=m-_,h=g-w,p=v-T,d=1/Math.sqrt(f*f+h*h+p*p),a=x*(p*=d)-b*(h*=d),o=b*(f*=d)-y*p,s=y*h-x*f,(d=Math.sqrt(a*a+o*o+s*s))?(a*=d=1/d,o*=d,s*=d):(a=0,o=0,s=0);l=h*s-p*o,c=p*a-f*s,u=f*o-h*a,(d=Math.sqrt(l*l+c*c+u*u))?(l*=d=1/d,c*=d,u*=d):(l=0,c=0,u=0);return t[0]=a,t[1]=l,t[2]=f,t[3]=0,t[4]=o,t[5]=c,t[6]=h,t[7]=0,t[8]=s,t[9]=u,t[10]=p,t[11]=0,t[12]=-(a*m+o*g+s*v),t[13]=-(l*m+c*g+u*v),t[14]=-(f*m+h*g+p*v),t[15]=1,t}},{"./identity":97}],100:[function(t,e,r){e.exports=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],l=e[5],c=e[6],u=e[7],f=e[8],h=e[9],p=e[10],d=e[11],m=e[12],g=e[13],v=e[14],y=e[15],x=r[0],b=r[1],_=r[2],w=r[3];return t[0]=x*n+b*s+_*f+w*m,t[1]=x*i+b*l+_*h+w*g,t[2]=x*a+b*c+_*p+w*v,t[3]=x*o+b*u+_*d+w*y,x=r[4],b=r[5],_=r[6],w=r[7],t[4]=x*n+b*s+_*f+w*m,t[5]=x*i+b*l+_*h+w*g,t[6]=x*a+b*c+_*p+w*v,t[7]=x*o+b*u+_*d+w*y,x=r[8],b=r[9],_=r[10],w=r[11],t[8]=x*n+b*s+_*f+w*m,t[9]=x*i+b*l+_*h+w*g,t[10]=x*a+b*c+_*p+w*v,t[11]=x*o+b*u+_*d+w*y,x=r[12],b=r[13],_=r[14],w=r[15],t[12]=x*n+b*s+_*f+w*m,t[13]=x*i+b*l+_*h+w*g,t[14]=x*a+b*c+_*p+w*v,t[15]=x*o+b*u+_*d+w*y,t}},{}],101:[function(t,e,r){e.exports=function(t,e,r,n,i,a,o){var s=1/(e-r),l=1/(n-i),c=1/(a-o);return t[0]=-2*s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*l,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*c,t[11]=0,t[12]=(e+r)*s,t[13]=(i+n)*l,t[14]=(o+a)*c,t[15]=1,t}},{}],102:[function(t,e,r){e.exports=function(t,e,r,n,i){var a=1/Math.tan(e/2),o=1/(n-i);return t[0]=a/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=(i+n)*o,t[11]=-1,t[12]=0,t[13]=0,t[14]=2*i*n*o,t[15]=0,t}},{}],103:[function(t,e,r){e.exports=function(t,e,r,n){var i,a,o,s,l,c,u,f,h,p,d,m,g,v,y,x,b,_,w,T,k,A,M,S,E=n[0],L=n[1],C=n[2],P=Math.sqrt(E*E+L*L+C*C);if(Math.abs(P)<1e-6)return null;E*=P=1/P,L*=P,C*=P,i=Math.sin(r),a=Math.cos(r),o=1-a,s=e[0],l=e[1],c=e[2],u=e[3],f=e[4],h=e[5],p=e[6],d=e[7],m=e[8],g=e[9],v=e[10],y=e[11],x=E*E*o+a,b=L*E*o+C*i,_=C*E*o-L*i,w=E*L*o-C*i,T=L*L*o+a,k=C*L*o+E*i,A=E*C*o+L*i,M=L*C*o-E*i,S=C*C*o+a,t[0]=s*x+f*b+m*_,t[1]=l*x+h*b+g*_,t[2]=c*x+p*b+v*_,t[3]=u*x+d*b+y*_,t[4]=s*w+f*T+m*k,t[5]=l*w+h*T+g*k,t[6]=c*w+p*T+v*k,t[7]=u*w+d*T+y*k,t[8]=s*A+f*M+m*S,t[9]=l*A+h*M+g*S,t[10]=c*A+p*M+v*S,t[11]=u*A+d*M+y*S,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]);return t}},{}],104:[function(t,e,r){e.exports=function(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[4],o=e[5],s=e[6],l=e[7],c=e[8],u=e[9],f=e[10],h=e[11];e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]);return t[4]=a*i+c*n,t[5]=o*i+u*n,t[6]=s*i+f*n,t[7]=l*i+h*n,t[8]=c*i-a*n,t[9]=u*i-o*n,t[10]=f*i-s*n,t[11]=h*i-l*n,t}},{}],105:[function(t,e,r){e.exports=function(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[0],o=e[1],s=e[2],l=e[3],c=e[8],u=e[9],f=e[10],h=e[11];e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]);return t[0]=a*i-c*n,t[1]=o*i-u*n,t[2]=s*i-f*n,t[3]=l*i-h*n,t[8]=a*n+c*i,t[9]=o*n+u*i,t[10]=s*n+f*i,t[11]=l*n+h*i,t}},{}],106:[function(t,e,r){e.exports=function(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[0],o=e[1],s=e[2],l=e[3],c=e[4],u=e[5],f=e[6],h=e[7];e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]);return t[0]=a*i+c*n,t[1]=o*i+u*n,t[2]=s*i+f*n,t[3]=l*i+h*n,t[4]=c*i-a*n,t[5]=u*i-o*n,t[6]=f*i-s*n,t[7]=h*i-l*n,t}},{}],107:[function(t,e,r){e.exports=function(t,e,r){var n=r[0],i=r[1],a=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*a,t[9]=e[9]*a,t[10]=e[10]*a,t[11]=e[11]*a,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}},{}],108:[function(t,e,r){e.exports=function(t,e,r){var n,i,a,o,s,l,c,u,f,h,p,d,m=r[0],g=r[1],v=r[2];e===t?(t[12]=e[0]*m+e[4]*g+e[8]*v+e[12],t[13]=e[1]*m+e[5]*g+e[9]*v+e[13],t[14]=e[2]*m+e[6]*g+e[10]*v+e[14],t[15]=e[3]*m+e[7]*g+e[11]*v+e[15]):(n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],l=e[5],c=e[6],u=e[7],f=e[8],h=e[9],p=e[10],d=e[11],t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=l,t[6]=c,t[7]=u,t[8]=f,t[9]=h,t[10]=p,t[11]=d,t[12]=n*m+s*g+f*v+e[12],t[13]=i*m+l*g+h*v+e[13],t[14]=a*m+c*g+p*v+e[14],t[15]=o*m+u*g+d*v+e[15]);return t}},{}],109:[function(t,e,r){e.exports=function(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],a=e[6],o=e[7],s=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=a,t[11]=e[14],t[12]=i,t[13]=o,t[14]=s}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}},{}],110:[function(t,e,r){"use strict";var n=t("barycentric"),i=t("polytope-closest-point/lib/closest_point_2d.js");function a(t,e){for(var r=[0,0,0,0],n=0;n<4;++n)for(var i=0;i<4;++i)r[i]+=t[4*n+i]*e[n];return r}function o(t,e,r,n,i){for(var o=a(n,a(r,a(e,[t[0],t[1],t[2],1]))),s=0;s<3;++s)o[s]/=o[3];return[.5*i[0]*(1+o[0]),.5*i[1]*(1-o[1])]}function s(t,e){for(var r=[0,0,0],n=0;n<t.length;++n)for(var i=t[n],a=e[n],o=0;o<3;++o)r[o]+=a*i[o];return r}e.exports=function(t,e,r,a,l,c){if(1===t.length)return[0,t[0].slice()];for(var u=new Array(t.length),f=0;f<t.length;++f)u[f]=o(t[f],r,a,l,c);var h=0,p=1/0;for(f=0;f<u.length;++f){for(var d=0,m=0;m<2;++m)d+=Math.pow(u[f][m]-e[m],2);d<p&&(p=d,h=f)}var g=function(t,e){if(2===t.length){for(var r=0,a=0,o=0;o<2;++o)r+=Math.pow(e[o]-t[0][o],2),a+=Math.pow(e[o]-t[1][o],2);return r=Math.sqrt(r),a=Math.sqrt(a),r+a<1e-6?[1,0]:[a/(r+a),r/(a+r)]}if(3===t.length){var s=[0,0];return i(t[0],t[1],t[2],e,s),n(t,s)}return[]}(u,e),v=0;for(f=0;f<3;++f){if(g[f]<-.001||g[f]>1.0001)return null;v+=g[f]}if(Math.abs(v-1)>.001)return null;return[h,s(t,g),g]}},{barycentric:14,"polytope-closest-point/lib/closest_point_2d.js":270}],111:[function(t,e,r){var n=t("glslify"),i=n(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec3 position, normal;\nattribute vec4 color;\nattribute vec2 uv;\n\nuniform mat4 model\n           , view\n           , projection\n           , inverseModel;\nuniform vec3 eyePosition\n           , lightPosition;\n\nvarying vec3 f_normal\n           , f_lightDirection\n           , f_eyeDirection\n           , f_data;\nvarying vec4 f_color;\nvarying vec2 f_uv;\n\nvec4 project(vec3 p) {\n  return projection * view * model * vec4(p, 1.0);\n}\n\nvoid main() {\n  gl_Position      = project(position);\n\n  //Lighting geometry parameters\n  vec4 cameraCoordinate = view * vec4(position , 1.0);\n  cameraCoordinate.xyz /= cameraCoordinate.w;\n  f_lightDirection = lightPosition - cameraCoordinate.xyz;\n  f_eyeDirection   = eyePosition - cameraCoordinate.xyz;\n  f_normal  = normalize((vec4(normal, 0.0) * inverseModel).xyz);\n\n  f_color          = color;\n  f_data           = position;\n  f_uv             = uv;\n}\n"]),a=n(["#extension GL_OES_standard_derivatives : enable\n\nprecision highp float;\n#define GLSLIFY 1\n\nfloat beckmannDistribution(float x, float roughness) {\n  float NdotH = max(x, 0.0001);\n  float cos2Alpha = NdotH * NdotH;\n  float tan2Alpha = (cos2Alpha - 1.0) / cos2Alpha;\n  float roughness2 = roughness * roughness;\n  float denom = 3.141592653589793 * roughness2 * cos2Alpha * cos2Alpha;\n  return exp(tan2Alpha / roughness2) / denom;\n}\n\nfloat cookTorranceSpecular(\n  vec3 lightDirection,\n  vec3 viewDirection,\n  vec3 surfaceNormal,\n  float roughness,\n  float fresnel) {\n\n  float VdotN = max(dot(viewDirection, surfaceNormal), 0.0);\n  float LdotN = max(dot(lightDirection, surfaceNormal), 0.0);\n\n  //Half angle vector\n  vec3 H = normalize(lightDirection + viewDirection);\n\n  //Geometric term\n  float NdotH = max(dot(surfaceNormal, H), 0.0);\n  float VdotH = max(dot(viewDirection, H), 0.000001);\n  float LdotH = max(dot(lightDirection, H), 0.000001);\n  float G1 = (2.0 * NdotH * VdotN) / VdotH;\n  float G2 = (2.0 * NdotH * LdotN) / LdotH;\n  float G = min(1.0, min(G1, G2));\n  \n  //Distribution term\n  float D = beckmannDistribution(NdotH, roughness);\n\n  //Fresnel term\n  float F = pow(1.0 - VdotN, fresnel);\n\n  //Multiply terms and done\n  return  G * F * D / max(3.14159265 * VdotN, 0.000001);\n}\n\n//#pragma glslify: beckmann = require(glsl-specular-beckmann) // used in gl-surface3d\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec3 clipBounds[2];\nuniform float roughness\n            , fresnel\n            , kambient\n            , kdiffuse\n            , kspecular;\nuniform sampler2D texture;\n\nvarying vec3 f_normal\n           , f_lightDirection\n           , f_eyeDirection\n           , f_data;\nvarying vec4 f_color;\nvarying vec2 f_uv;\n\nvoid main() {\n  if (f_color.a == 0.0 ||\n    outOfRange(clipBounds[0], clipBounds[1], f_data)\n  ) discard;\n\n  vec3 N = normalize(f_normal);\n  vec3 L = normalize(f_lightDirection);\n  vec3 V = normalize(f_eyeDirection);\n\n  if(gl_FrontFacing) {\n    N = -N;\n  }\n\n  float specular = min(1.0, max(0.0, cookTorranceSpecular(L, V, N, roughness, fresnel)));\n  //float specular = max(0.0, beckmann(L, V, N, roughness)); // used in gl-surface3d\n\n  float diffuse  = min(kambient + kdiffuse * max(dot(N, L), 0.0), 1.0);\n\n  vec4 surfaceColor = vec4(f_color.rgb, 1.0) * texture2D(texture, f_uv);\n  vec4 litColor = surfaceColor.a * vec4(diffuse * surfaceColor.rgb + kspecular * vec3(1,1,1) * specular,  1.0);\n\n  gl_FragColor = litColor * f_color.a;\n}\n"]),o=n(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec3 position;\nattribute vec4 color;\nattribute vec2 uv;\n\nuniform mat4 model, view, projection;\n\nvarying vec4 f_color;\nvarying vec3 f_data;\nvarying vec2 f_uv;\n\nvoid main() {\n  gl_Position = projection * view * model * vec4(position, 1.0);\n  f_color = color;\n  f_data  = position;\n  f_uv    = uv;\n}"]),s=n(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec3 clipBounds[2];\nuniform sampler2D texture;\nuniform float opacity;\n\nvarying vec4 f_color;\nvarying vec3 f_data;\nvarying vec2 f_uv;\n\nvoid main() {\n  if (outOfRange(clipBounds[0], clipBounds[1], f_data)) discard;\n\n  gl_FragColor = f_color * texture2D(texture, f_uv) * opacity;\n}"]),l=n(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nattribute vec3 position;\nattribute vec4 color;\nattribute vec2 uv;\nattribute float pointSize;\n\nuniform mat4 model, view, projection;\nuniform vec3 clipBounds[2];\n\nvarying vec4 f_color;\nvarying vec2 f_uv;\n\nvoid main() {\n  if (outOfRange(clipBounds[0], clipBounds[1], position)) {\n\n    gl_Position = vec4(0.0, 0.0 ,0.0 ,0.0);\n  } else {\n    gl_Position = projection * view * model * vec4(position, 1.0);\n  }\n  gl_PointSize = pointSize;\n  f_color = color;\n  f_uv = uv;\n}"]),c=n(["precision highp float;\n#define GLSLIFY 1\n\nuniform sampler2D texture;\nuniform float opacity;\n\nvarying vec4 f_color;\nvarying vec2 f_uv;\n\nvoid main() {\n  vec2 pointR = gl_PointCoord.xy - vec2(0.5, 0.5);\n  if(dot(pointR, pointR) > 0.25) {\n    discard;\n  }\n  gl_FragColor = f_color * texture2D(texture, f_uv) * opacity;\n}"]),u=n(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec3 position;\nattribute vec4 id;\n\nuniform mat4 model, view, projection;\n\nvarying vec3 f_position;\nvarying vec4 f_id;\n\nvoid main() {\n  gl_Position = projection * view * model * vec4(position, 1.0);\n  f_id        = id;\n  f_position  = position;\n}"]),f=n(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec3  clipBounds[2];\nuniform float pickId;\n\nvarying vec3 f_position;\nvarying vec4 f_id;\n\nvoid main() {\n  if (outOfRange(clipBounds[0], clipBounds[1], f_position)) discard;\n\n  gl_FragColor = vec4(pickId, f_id.xyz);\n}"]),h=n(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nattribute vec3  position;\nattribute float pointSize;\nattribute vec4  id;\n\nuniform mat4 model, view, projection;\nuniform vec3 clipBounds[2];\n\nvarying vec3 f_position;\nvarying vec4 f_id;\n\nvoid main() {\n  if (outOfRange(clipBounds[0], clipBounds[1], position)) {\n\n    gl_Position = vec4(0.0, 0.0, 0.0, 0.0);\n  } else {\n    gl_Position  = projection * view * model * vec4(position, 1.0);\n    gl_PointSize = pointSize;\n  }\n  f_id         = id;\n  f_position   = position;\n}"]),p=n(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec3 position;\n\nuniform mat4 model, view, projection;\n\nvoid main() {\n  gl_Position = projection * view * model * vec4(position, 1.0);\n}"]),d=n(["precision highp float;\n#define GLSLIFY 1\n\nuniform vec3 contourColor;\n\nvoid main() {\n  gl_FragColor = vec4(contourColor, 1.0);\n}\n"]);r.meshShader={vertex:i,fragment:a,attributes:[{name:"position",type:"vec3"},{name:"normal",type:"vec3"},{name:"color",type:"vec4"},{name:"uv",type:"vec2"}]},r.wireShader={vertex:o,fragment:s,attributes:[{name:"position",type:"vec3"},{name:"color",type:"vec4"},{name:"uv",type:"vec2"}]},r.pointShader={vertex:l,fragment:c,attributes:[{name:"position",type:"vec3"},{name:"color",type:"vec4"},{name:"uv",type:"vec2"},{name:"pointSize",type:"float"}]},r.pickShader={vertex:u,fragment:f,attributes:[{name:"position",type:"vec3"},{name:"id",type:"vec4"}]},r.pointPickShader={vertex:h,fragment:f,attributes:[{name:"position",type:"vec3"},{name:"pointSize",type:"float"},{name:"id",type:"vec4"}]},r.contourShader={vertex:p,fragment:d,attributes:[{name:"position",type:"vec3"}]}},{glslify:231}],112:[function(t,e,r){"use strict";var n=t("gl-shader"),i=t("gl-buffer"),a=t("gl-vao"),o=t("gl-texture2d"),s=t("normals"),l=t("gl-mat4/multiply"),c=t("gl-mat4/invert"),u=t("ndarray"),f=t("colormap"),h=t("simplicial-complex-contour"),p=t("typedarray-pool"),d=t("./lib/shaders"),m=t("./lib/closest-point"),g=d.meshShader,v=d.wireShader,y=d.pointShader,x=d.pickShader,b=d.pointPickShader,_=d.contourShader,w=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function T(t,e,r,n,i,a,o,s,l,c,u,f,h,p,d,m,g,v,y,x,b,_,T,k,A,M,S){this.gl=t,this.pixelRatio=1,this.cells=[],this.positions=[],this.intensity=[],this.texture=e,this.dirty=!0,this.triShader=r,this.lineShader=n,this.pointShader=i,this.pickShader=a,this.pointPickShader=o,this.contourShader=s,this.trianglePositions=l,this.triangleColors=u,this.triangleNormals=h,this.triangleUVs=f,this.triangleIds=c,this.triangleVAO=p,this.triangleCount=0,this.lineWidth=1,this.edgePositions=d,this.edgeColors=g,this.edgeUVs=v,this.edgeIds=m,this.edgeVAO=y,this.edgeCount=0,this.pointPositions=x,this.pointColors=_,this.pointUVs=T,this.pointSizes=k,this.pointIds=b,this.pointVAO=A,this.pointCount=0,this.contourLineWidth=1,this.contourPositions=M,this.contourVAO=S,this.contourCount=0,this.contourColor=[0,0,0],this.contourEnable=!0,this.pickVertex=!0,this.pickId=1,this.bounds=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]],this.clipBounds=[[-1/0,-1/0,-1/0],[1/0,1/0,1/0]],this.lightPosition=[1e5,1e5,0],this.ambientLight=.8,this.diffuseLight=.8,this.specularLight=2,this.roughness=.5,this.fresnel=1.5,this.opacity=1,this.hasAlpha=!1,this.opacityscale=!1,this._model=w,this._view=w,this._projection=w,this._resolution=[1,1]}var k=T.prototype;function A(t,e){if(!e)return 1;if(!e.length)return 1;for(var r=0;r<e.length;++r){if(e.length<2)return 1;if(e[r][0]===t)return e[r][1];if(e[r][0]>t&&r>0){var n=(e[r][0]-t)/(e[r][0]-e[r-1][0]);return e[r][1]*(1-n)+n*e[r-1][1]}}return 1}function M(t){var e=n(t,g.vertex,g.fragment);return e.attributes.position.location=0,e.attributes.color.location=2,e.attributes.uv.location=3,e.attributes.normal.location=4,e}function S(t){var e=n(t,v.vertex,v.fragment);return e.attributes.position.location=0,e.attributes.color.location=2,e.attributes.uv.location=3,e}function E(t){var e=n(t,y.vertex,y.fragment);return e.attributes.position.location=0,e.attributes.color.location=2,e.attributes.uv.location=3,e.attributes.pointSize.location=4,e}function L(t){var e=n(t,x.vertex,x.fragment);return e.attributes.position.location=0,e.attributes.id.location=1,e}function C(t){var e=n(t,b.vertex,b.fragment);return e.attributes.position.location=0,e.attributes.id.location=1,e.attributes.pointSize.location=4,e}function P(t){var e=n(t,_.vertex,_.fragment);return e.attributes.position.location=0,e}k.isOpaque=function(){return!this.hasAlpha},k.isTransparent=function(){return this.hasAlpha},k.pickSlots=1,k.setPickBase=function(t){this.pickId=t},k.highlight=function(t){if(t&&this.contourEnable){for(var e=h(this.cells,this.intensity,t.intensity),r=e.cells,n=e.vertexIds,i=e.vertexWeights,a=r.length,o=p.mallocFloat32(6*a),s=0,l=0;l<a;++l)for(var c=r[l],u=0;u<2;++u){var f=c[0];2===c.length&&(f=c[u]);for(var d=n[f][0],m=n[f][1],g=i[f],v=1-g,y=this.positions[d],x=this.positions[m],b=0;b<3;++b)o[s++]=g*y[b]+v*x[b]}this.contourCount=s/3|0,this.contourPositions.update(o.subarray(0,s)),p.free(o)}else this.contourCount=0},k.update=function(t){t=t||{};var e=this.gl;this.dirty=!0,"contourEnable"in t&&(this.contourEnable=t.contourEnable),"contourColor"in t&&(this.contourColor=t.contourColor),"lineWidth"in t&&(this.lineWidth=t.lineWidth),"lightPosition"in t&&(this.lightPosition=t.lightPosition),this.hasAlpha=!1,"opacity"in t&&(this.opacity=t.opacity,this.opacity<1&&(this.hasAlpha=!0)),"opacityscale"in t&&(this.opacityscale=t.opacityscale,this.hasAlpha=!0),"ambient"in t&&(this.ambientLight=t.ambient),"diffuse"in t&&(this.diffuseLight=t.diffuse),"specular"in t&&(this.specularLight=t.specular),"roughness"in t&&(this.roughness=t.roughness),"fresnel"in t&&(this.fresnel=t.fresnel),t.texture?(this.texture.dispose(),this.texture=o(e,t.texture)):t.colormap&&(this.texture.shape=[256,256],this.texture.minFilter=e.LINEAR_MIPMAP_LINEAR,this.texture.magFilter=e.LINEAR,this.texture.setPixels(function(t,e){for(var r=f({colormap:t,nshades:256,format:"rgba"}),n=new Uint8Array(1024),i=0;i<256;++i){for(var a=r[i],o=0;o<3;++o)n[4*i+o]=a[o];n[4*i+3]=e?255*A(i/255,e):255*a[3]}return u(n,[256,256,4],[4,0,1])}(t.colormap,this.opacityscale)),this.texture.generateMipmap());var r=t.cells,n=t.positions;if(n&&r){var i=[],a=[],l=[],c=[],h=[],p=[],d=[],m=[],g=[],v=[],y=[],x=[],b=[],_=[];this.cells=r,this.positions=n;var w=t.vertexNormals,T=t.cellNormals,k=void 0===t.vertexNormalsEpsilon?1e-6:t.vertexNormalsEpsilon,M=void 0===t.faceNormalsEpsilon?1e-6:t.faceNormalsEpsilon;t.useFacetNormals&&!T&&(T=s.faceNormals(r,n,M)),T||w||(w=s.vertexNormals(r,n,k));var S=t.vertexColors,E=t.cellColors,L=t.meshColor||[1,1,1,1],C=t.vertexUVs,P=t.vertexIntensity,I=t.cellUVs,O=t.cellIntensity,z=1/0,D=-1/0;if(!C&&!I)if(P)if(t.vertexIntensityBounds)z=+t.vertexIntensityBounds[0],D=+t.vertexIntensityBounds[1];else for(var R=0;R<P.length;++R){var F=P[R];z=Math.min(z,F),D=Math.max(D,F)}else if(O)if(t.cellIntensityBounds)z=+t.cellIntensityBounds[0],D=+t.cellIntensityBounds[1];else for(R=0;R<O.length;++R){F=O[R];z=Math.min(z,F),D=Math.max(D,F)}else for(R=0;R<n.length;++R){F=n[R][2];z=Math.min(z,F),D=Math.max(D,F)}this.intensity=P||(O||function(t){for(var e=t.length,r=new Array(e),n=0;n<e;++n)r[n]=t[n][2];return r}(n)),this.pickVertex=!(O||E);var B=t.pointSizes,N=t.pointSize||1;this.bounds=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];for(R=0;R<n.length;++R)for(var j=n[R],U=0;U<3;++U)!isNaN(j[U])&&isFinite(j[U])&&(this.bounds[0][U]=Math.min(this.bounds[0][U],j[U]),this.bounds[1][U]=Math.max(this.bounds[1][U],j[U]));var V=0,H=0,q=0;t:for(R=0;R<r.length;++R){var G=r[R];switch(G.length){case 1:for(j=n[W=G[0]],U=0;U<3;++U)if(isNaN(j[U])||!isFinite(j[U]))continue t;v.push(j[0],j[1],j[2]),X=S?S[W]:E?E[R]:L,this.opacityscale&&P?a.push(X[0],X[1],X[2],this.opacity*A((P[W]-z)/(D-z),this.opacityscale)):3===X.length?y.push(X[0],X[1],X[2],this.opacity):(y.push(X[0],X[1],X[2],X[3]*this.opacity),X[3]<1&&(this.hasAlpha=!0)),Z=C?C[W]:P?[(P[W]-z)/(D-z),0]:I?I[R]:O?[(O[R]-z)/(D-z),0]:[(j[2]-z)/(D-z),0],x.push(Z[0],Z[1]),B?b.push(B[W]):b.push(N),_.push(R),q+=1;break;case 2:for(U=0;U<2;++U){j=n[W=G[U]];for(var Y=0;Y<3;++Y)if(isNaN(j[Y])||!isFinite(j[Y]))continue t}for(U=0;U<2;++U){j=n[W=G[U]];p.push(j[0],j[1],j[2]),X=S?S[W]:E?E[R]:L,this.opacityscale&&P?a.push(X[0],X[1],X[2],this.opacity*A((P[W]-z)/(D-z),this.opacityscale)):3===X.length?d.push(X[0],X[1],X[2],this.opacity):(d.push(X[0],X[1],X[2],X[3]*this.opacity),X[3]<1&&(this.hasAlpha=!0)),Z=C?C[W]:P?[(P[W]-z)/(D-z),0]:I?I[R]:O?[(O[R]-z)/(D-z),0]:[(j[2]-z)/(D-z),0],m.push(Z[0],Z[1]),g.push(R)}H+=1;break;case 3:for(U=0;U<3;++U)for(j=n[W=G[U]],Y=0;Y<3;++Y)if(isNaN(j[Y])||!isFinite(j[Y]))continue t;for(U=0;U<3;++U){var W,X,Z,J;j=n[W=G[2-U]];i.push(j[0],j[1],j[2]),(X=S?S[W]:E?E[R]:L)?this.opacityscale&&P?a.push(X[0],X[1],X[2],this.opacity*A((P[W]-z)/(D-z),this.opacityscale)):3===X.length?a.push(X[0],X[1],X[2],this.opacity):(a.push(X[0],X[1],X[2],X[3]*this.opacity),X[3]<1&&(this.hasAlpha=!0)):a.push(.5,.5,.5,1),Z=C?C[W]:P?[(P[W]-z)/(D-z),0]:I?I[R]:O?[(O[R]-z)/(D-z),0]:[(j[2]-z)/(D-z),0],c.push(Z[0],Z[1]),J=w?w[W]:T[R],l.push(J[0],J[1],J[2]),h.push(R)}V+=1}}this.pointCount=q,this.edgeCount=H,this.triangleCount=V,this.pointPositions.update(v),this.pointColors.update(y),this.pointUVs.update(x),this.pointSizes.update(b),this.pointIds.update(new Uint32Array(_)),this.edgePositions.update(p),this.edgeColors.update(d),this.edgeUVs.update(m),this.edgeIds.update(new Uint32Array(g)),this.trianglePositions.update(i),this.triangleColors.update(a),this.triangleUVs.update(c),this.triangleNormals.update(l),this.triangleIds.update(new Uint32Array(h))}},k.drawTransparent=k.draw=function(t){t=t||{};for(var e=this.gl,r=t.model||w,n=t.view||w,i=t.projection||w,a=[[-1e6,-1e6,-1e6],[1e6,1e6,1e6]],o=0;o<3;++o)a[0][o]=Math.max(a[0][o],this.clipBounds[0][o]),a[1][o]=Math.min(a[1][o],this.clipBounds[1][o]);var s={model:r,view:n,projection:i,inverseModel:w.slice(),clipBounds:a,kambient:this.ambientLight,kdiffuse:this.diffuseLight,kspecular:this.specularLight,roughness:this.roughness,fresnel:this.fresnel,eyePosition:[0,0,0],lightPosition:[0,0,0],contourColor:this.contourColor,texture:0};s.inverseModel=c(s.inverseModel,s.model),e.disable(e.CULL_FACE),this.texture.bind(0);var u=new Array(16);l(u,s.view,s.model),l(u,s.projection,u),c(u,u);for(o=0;o<3;++o)s.eyePosition[o]=u[12+o]/u[15];var f,h=u[15];for(o=0;o<3;++o)h+=this.lightPosition[o]*u[4*o+3];for(o=0;o<3;++o){for(var p=u[12+o],d=0;d<3;++d)p+=u[4*d+o]*this.lightPosition[d];s.lightPosition[o]=p/h}this.triangleCount>0&&((f=this.triShader).bind(),f.uniforms=s,this.triangleVAO.bind(),e.drawArrays(e.TRIANGLES,0,3*this.triangleCount),this.triangleVAO.unbind());this.edgeCount>0&&this.lineWidth>0&&((f=this.lineShader).bind(),f.uniforms=s,this.edgeVAO.bind(),e.lineWidth(this.lineWidth*this.pixelRatio),e.drawArrays(e.LINES,0,2*this.edgeCount),this.edgeVAO.unbind());this.pointCount>0&&((f=this.pointShader).bind(),f.uniforms=s,this.pointVAO.bind(),e.drawArrays(e.POINTS,0,this.pointCount),this.pointVAO.unbind());this.contourEnable&&this.contourCount>0&&this.contourLineWidth>0&&((f=this.contourShader).bind(),f.uniforms=s,this.contourVAO.bind(),e.drawArrays(e.LINES,0,this.contourCount),this.contourVAO.unbind())},k.drawPick=function(t){t=t||{};for(var e=this.gl,r=t.model||w,n=t.view||w,i=t.projection||w,a=[[-1e6,-1e6,-1e6],[1e6,1e6,1e6]],o=0;o<3;++o)a[0][o]=Math.max(a[0][o],this.clipBounds[0][o]),a[1][o]=Math.min(a[1][o],this.clipBounds[1][o]);this._model=[].slice.call(r),this._view=[].slice.call(n),this._projection=[].slice.call(i),this._resolution=[e.drawingBufferWidth,e.drawingBufferHeight];var s,l={model:r,view:n,projection:i,clipBounds:a,pickId:this.pickId/255};((s=this.pickShader).bind(),s.uniforms=l,this.triangleCount>0&&(this.triangleVAO.bind(),e.drawArrays(e.TRIANGLES,0,3*this.triangleCount),this.triangleVAO.unbind()),this.edgeCount>0&&(this.edgeVAO.bind(),e.lineWidth(this.lineWidth*this.pixelRatio),e.drawArrays(e.LINES,0,2*this.edgeCount),this.edgeVAO.unbind()),this.pointCount>0)&&((s=this.pointPickShader).bind(),s.uniforms=l,this.pointVAO.bind(),e.drawArrays(e.POINTS,0,this.pointCount),this.pointVAO.unbind())},k.pick=function(t){if(!t)return null;if(t.id!==this.pickId)return null;for(var e=t.value[0]+256*t.value[1]+65536*t.value[2],r=this.cells[e],n=this.positions,i=new Array(r.length),a=0;a<r.length;++a)i[a]=n[r[a]];var o=t.coord[0],s=t.coord[1];if(!this.pickVertex){var l=this.positions[r[0]],c=this.positions[r[1]],u=this.positions[r[2]],f=[(l[0]+c[0]+u[0])/3,(l[1]+c[1]+u[1])/3,(l[2]+c[2]+u[2])/3];return{_cellCenter:!0,position:[o,s],index:e,cell:r,cellId:e,intensity:this.intensity[e],dataCoordinate:f}}var h=m(i,[o*this.pixelRatio,this._resolution[1]-s*this.pixelRatio],this._model,this._view,this._projection,this._resolution);if(!h)return null;var p=h[2],d=0;for(a=0;a<r.length;++a)d+=p[a]*this.intensity[r[a]];return{position:h[1],index:r[h[0]],cell:r,cellId:e,intensity:d,dataCoordinate:this.positions[r[h[0]]]}},k.dispose=function(){this.texture.dispose(),this.triShader.dispose(),this.lineShader.dispose(),this.pointShader.dispose(),this.pickShader.dispose(),this.pointPickShader.dispose(),this.triangleVAO.dispose(),this.trianglePositions.dispose(),this.triangleColors.dispose(),this.triangleUVs.dispose(),this.triangleNormals.dispose(),this.triangleIds.dispose(),this.edgeVAO.dispose(),this.edgePositions.dispose(),this.edgeColors.dispose(),this.edgeUVs.dispose(),this.edgeIds.dispose(),this.pointVAO.dispose(),this.pointPositions.dispose(),this.pointColors.dispose(),this.pointUVs.dispose(),this.pointSizes.dispose(),this.pointIds.dispose(),this.contourVAO.dispose(),this.contourPositions.dispose(),this.contourShader.dispose()},e.exports=function(t,e){1===arguments.length&&(t=(e=t).gl);var r=t.getExtension("OES_standard_derivatives")||t.getExtension("MOZ_OES_standard_derivatives")||t.getExtension("WEBKIT_OES_standard_derivatives");if(!r)throw new Error("derivatives not supported");var n=M(t),s=S(t),l=E(t),c=L(t),f=C(t),h=P(t),p=o(t,u(new Uint8Array([255,255,255,255]),[1,1,4]));p.generateMipmap(),p.minFilter=t.LINEAR_MIPMAP_LINEAR,p.magFilter=t.LINEAR;var d=i(t),m=i(t),g=i(t),v=i(t),y=i(t),x=a(t,[{buffer:d,type:t.FLOAT,size:3},{buffer:y,type:t.UNSIGNED_BYTE,size:4,normalized:!0},{buffer:m,type:t.FLOAT,size:4},{buffer:g,type:t.FLOAT,size:2},{buffer:v,type:t.FLOAT,size:3}]),b=i(t),_=i(t),w=i(t),k=i(t),A=a(t,[{buffer:b,type:t.FLOAT,size:3},{buffer:k,type:t.UNSIGNED_BYTE,size:4,normalized:!0},{buffer:_,type:t.FLOAT,size:4},{buffer:w,type:t.FLOAT,size:2}]),I=i(t),O=i(t),z=i(t),D=i(t),R=i(t),F=a(t,[{buffer:I,type:t.FLOAT,size:3},{buffer:R,type:t.UNSIGNED_BYTE,size:4,normalized:!0},{buffer:O,type:t.FLOAT,size:4},{buffer:z,type:t.FLOAT,size:2},{buffer:D,type:t.FLOAT,size:1}]),B=i(t),N=a(t,[{buffer:B,type:t.FLOAT,size:3}]),j=new T(t,p,n,s,l,c,f,h,d,y,m,g,v,x,b,k,_,w,A,I,R,O,z,D,F,B,N);return j.update(e),j}},{"./lib/closest-point":110,"./lib/shaders":111,colormap:53,"gl-buffer":78,"gl-mat4/invert":98,"gl-mat4/multiply":100,"gl-shader":132,"gl-texture2d":146,"gl-vao":150,ndarray:259,normals:261,"simplicial-complex-contour":291,"typedarray-pool":308}],113:[function(t,e,r){"use strict";e.exports=function(t){var e=t.gl,r=n(e,[0,0,0,1,1,0,1,1]),s=i(e,a.boxVert,a.lineFrag);return new o(t,r,s)};var n=t("gl-buffer"),i=t("gl-shader"),a=t("./shaders");function o(t,e,r){this.plot=t,this.vbo=e,this.shader=r}var s,l,c=o.prototype;c.bind=function(){var t=this.shader;this.vbo.bind(),this.shader.bind(),t.attributes.coord.pointer(),t.uniforms.screenBox=this.plot.screenBox},c.drawBox=(s=[0,0],l=[0,0],function(t,e,r,n,i){var a=this.plot,o=this.shader,c=a.gl;s[0]=t,s[1]=e,l[0]=r,l[1]=n,o.uniforms.lo=s,o.uniforms.hi=l,o.uniforms.color=i,c.drawArrays(c.TRIANGLE_STRIP,0,4)}),c.dispose=function(){this.vbo.dispose(),this.shader.dispose()}},{"./shaders":116,"gl-buffer":78,"gl-shader":132}],114:[function(t,e,r){"use strict";e.exports=function(t){var e=t.gl,r=n(e),a=i(e,o.gridVert,o.gridFrag),l=i(e,o.tickVert,o.gridFrag);return new s(t,r,a,l)};var n=t("gl-buffer"),i=t("gl-shader"),a=t("binary-search-bounds"),o=t("./shaders");function s(t,e,r,n){this.plot=t,this.vbo=e,this.shader=r,this.tickShader=n,this.ticks=[[],[]]}function l(t,e){return t-e}var c,u,f,h,p,d=s.prototype;d.draw=(c=[0,0],u=[0,0],f=[0,0],function(){for(var t=this.plot,e=this.vbo,r=this.shader,n=this.ticks,i=t.gl,a=t._tickBounds,o=t.dataBox,s=t.viewBox,l=t.gridLineWidth,h=t.gridLineColor,p=t.gridLineEnable,d=t.pixelRatio,m=0;m<2;++m){var g=a[m],v=a[m+2]-g,y=.5*(o[m+2]+o[m]),x=o[m+2]-o[m];u[m]=2*v/x,c[m]=2*(g-y)/x}r.bind(),e.bind(),r.attributes.dataCoord.pointer(),r.uniforms.dataShift=c,r.uniforms.dataScale=u;var b=0;for(m=0;m<2;++m){f[0]=f[1]=0,f[m]=1,r.uniforms.dataAxis=f,r.uniforms.lineWidth=l[m]/(s[m+2]-s[m])*d,r.uniforms.color=h[m];var _=6*n[m].length;p[m]&&_&&i.drawArrays(i.TRIANGLES,b,_),b+=_}}),d.drawTickMarks=function(){var t=[0,0],e=[0,0],r=[1,0],n=[0,1],i=[0,0],o=[0,0];return function(){for(var s=this.plot,c=this.vbo,u=this.tickShader,f=this.ticks,h=s.gl,p=s._tickBounds,d=s.dataBox,m=s.viewBox,g=s.pixelRatio,v=s.screenBox,y=v[2]-v[0],x=v[3]-v[1],b=m[2]-m[0],_=m[3]-m[1],w=0;w<2;++w){var T=p[w],k=p[w+2]-T,A=.5*(d[w+2]+d[w]),M=d[w+2]-d[w];e[w]=2*k/M,t[w]=2*(T-A)/M}e[0]*=b/y,t[0]*=b/y,e[1]*=_/x,t[1]*=_/x,u.bind(),c.bind(),u.attributes.dataCoord.pointer();var S=u.uniforms;S.dataShift=t,S.dataScale=e;var E=s.tickMarkLength,L=s.tickMarkWidth,C=s.tickMarkColor,P=6*f[0].length,I=Math.min(a.ge(f[0],(d[0]-p[0])/(p[2]-p[0]),l),f[0].length),O=Math.min(a.gt(f[0],(d[2]-p[0])/(p[2]-p[0]),l),f[0].length),z=0+6*I,D=6*Math.max(0,O-I),R=Math.min(a.ge(f[1],(d[1]-p[1])/(p[3]-p[1]),l),f[1].length),F=Math.min(a.gt(f[1],(d[3]-p[1])/(p[3]-p[1]),l),f[1].length),B=P+6*R,N=6*Math.max(0,F-R);i[0]=2*(m[0]-E[1])/y-1,i[1]=(m[3]+m[1])/x-1,o[0]=E[1]*g/y,o[1]=L[1]*g/x,N&&(S.color=C[1],S.tickScale=o,S.dataAxis=n,S.screenOffset=i,h.drawArrays(h.TRIANGLES,B,N)),i[0]=(m[2]+m[0])/y-1,i[1]=2*(m[1]-E[0])/x-1,o[0]=L[0]*g/y,o[1]=E[0]*g/x,D&&(S.color=C[0],S.tickScale=o,S.dataAxis=r,S.screenOffset=i,h.drawArrays(h.TRIANGLES,z,D)),i[0]=2*(m[2]+E[3])/y-1,i[1]=(m[3]+m[1])/x-1,o[0]=E[3]*g/y,o[1]=L[3]*g/x,N&&(S.color=C[3],S.tickScale=o,S.dataAxis=n,S.screenOffset=i,h.drawArrays(h.TRIANGLES,B,N)),i[0]=(m[2]+m[0])/y-1,i[1]=2*(m[3]+E[2])/x-1,o[0]=L[2]*g/y,o[1]=E[2]*g/x,D&&(S.color=C[2],S.tickScale=o,S.dataAxis=r,S.screenOffset=i,h.drawArrays(h.TRIANGLES,z,D))}}(),d.update=(h=[1,1,-1,-1,1,-1],p=[1,-1,1,1,-1,-1],function(t){for(var e=t.ticks,r=t.bounds,n=new Float32Array(18*(e[0].length+e[1].length)),i=(this.plot.zeroLineEnable,0),a=[[],[]],o=0;o<2;++o)for(var s=a[o],l=e[o],c=r[o],u=r[o+2],f=0;f<l.length;++f){var d=(l[f].x-c)/(u-c);s.push(d);for(var m=0;m<6;++m)n[i++]=d,n[i++]=h[m],n[i++]=p[m]}this.ticks=a,this.vbo.update(n)}),d.dispose=function(){this.vbo.dispose(),this.shader.dispose(),this.tickShader.dispose()}},{"./shaders":116,"binary-search-bounds":31,"gl-buffer":78,"gl-shader":132}],115:[function(t,e,r){"use strict";e.exports=function(t){var e=t.gl,r=n(e,[-1,-1,-1,1,1,-1,1,1]),s=i(e,a.lineVert,a.lineFrag);return new o(t,r,s)};var n=t("gl-buffer"),i=t("gl-shader"),a=t("./shaders");function o(t,e,r){this.plot=t,this.vbo=e,this.shader=r}var s,l,c=o.prototype;c.bind=function(){var t=this.shader;this.vbo.bind(),this.shader.bind(),t.attributes.coord.pointer(),t.uniforms.screenBox=this.plot.screenBox},c.drawLine=(s=[0,0],l=[0,0],function(t,e,r,n,i,a){var o=this.plot,c=this.shader,u=o.gl;s[0]=t,s[1]=e,l[0]=r,l[1]=n,c.uniforms.start=s,c.uniforms.end=l,c.uniforms.width=i*o.pixelRatio,c.uniforms.color=a,u.drawArrays(u.TRIANGLE_STRIP,0,4)}),c.dispose=function(){this.vbo.dispose(),this.shader.dispose()}},{"./shaders":116,"gl-buffer":78,"gl-shader":132}],116:[function(t,e,r){"use strict";var n=t("glslify"),i=n(["precision lowp float;\n#define GLSLIFY 1\nuniform vec4 color;\nvoid main() {\n  gl_FragColor = vec4(color.xyz * color.w, color.w);\n}\n"]);e.exports={lineVert:n(["precision mediump float;\n#define GLSLIFY 1\n\nattribute vec2 coord;\n\nuniform vec4 screenBox;\nuniform vec2 start, end;\nuniform float width;\n\nvec2 perp(vec2 v) {\n  return vec2(v.y, -v.x);\n}\n\nvec2 screen(vec2 v) {\n  return 2.0 * (v - screenBox.xy) / (screenBox.zw - screenBox.xy) - 1.0;\n}\n\nvoid main() {\n  vec2 delta = normalize(perp(start - end));\n  vec2 offset = mix(start, end, 0.5 * (coord.y+1.0));\n  gl_Position = vec4(screen(offset + 0.5 * width * delta * coord.x), 0, 1);\n}\n"]),lineFrag:i,textVert:n(["#define GLSLIFY 1\nattribute vec3 textCoordinate;\n\nuniform vec2 dataScale, dataShift, dataAxis, screenOffset, textScale;\nuniform float angle;\n\nvoid main() {\n  float dataOffset  = textCoordinate.z;\n  vec2 glyphOffset  = textCoordinate.xy;\n  mat2 glyphMatrix = mat2(cos(angle), sin(angle), -sin(angle), cos(angle));\n  vec2 screenCoordinate = dataAxis * (dataScale * dataOffset + dataShift) +\n    glyphMatrix * glyphOffset * textScale + screenOffset;\n  gl_Position = vec4(screenCoordinate, 0, 1);\n}\n"]),textFrag:i,gridVert:n(["precision mediump float;\n#define GLSLIFY 1\n\nattribute vec3 dataCoord;\n\nuniform vec2 dataAxis, dataShift, dataScale;\nuniform float lineWidth;\n\nvoid main() {\n  vec2 pos = dataAxis * (dataScale * dataCoord.x + dataShift);\n  pos += 10.0 * dataCoord.y * vec2(dataAxis.y, -dataAxis.x) + dataCoord.z * lineWidth;\n  gl_Position = vec4(pos, 0, 1);\n}\n"]),gridFrag:i,boxVert:n(["precision mediump float;\n#define GLSLIFY 1\n\nattribute vec2 coord;\n\nuniform vec4 screenBox;\nuniform vec2 lo, hi;\n\nvec2 screen(vec2 v) {\n  return 2.0 * (v - screenBox.xy) / (screenBox.zw - screenBox.xy) - 1.0;\n}\n\nvoid main() {\n  gl_Position = vec4(screen(mix(lo, hi, coord)), 0, 1);\n}\n"]),tickVert:n(["precision mediump float;\n#define GLSLIFY 1\n\nattribute vec3 dataCoord;\n\nuniform vec2 dataAxis, dataShift, dataScale, screenOffset, tickScale;\n\nvoid main() {\n  vec2 pos = dataAxis * (dataScale * dataCoord.x + dataShift);\n  gl_Position = vec4(pos + tickScale*dataCoord.yz + screenOffset, 0, 1);\n}\n"])}},{glslify:231}],117:[function(t,e,r){"use strict";e.exports=function(t){var e=t.gl,r=n(e),a=i(e,s.textVert,s.textFrag);return new l(t,r,a)};var n=t("gl-buffer"),i=t("gl-shader"),a=t("text-cache"),o=t("binary-search-bounds"),s=t("./shaders");function l(t,e,r){this.plot=t,this.vbo=e,this.shader=r,this.tickOffset=[[],[]],this.tickX=[[],[]],this.labelOffset=[0,0],this.labelCount=[0,0]}var c,u,f,h,p,d,m=l.prototype;m.drawTicks=(c=[0,0],u=[0,0],f=[0,0],function(t){var e=this.plot,r=this.shader,n=this.tickX[t],i=this.tickOffset[t],a=e.gl,s=e.viewBox,l=e.dataBox,h=e.screenBox,p=e.pixelRatio,d=e.tickEnable,m=e.tickPad,g=e.tickColor,v=e.tickAngle,y=e.labelEnable,x=e.labelPad,b=e.labelColor,_=e.labelAngle,w=this.labelOffset[t],T=this.labelCount[t],k=o.lt(n,l[t]),A=o.le(n,l[t+2]);c[0]=c[1]=0,c[t]=1,u[t]=(s[2+t]+s[t])/(h[2+t]-h[t])-1;var M=2/h[2+(1^t)]-h[1^t];u[1^t]=M*s[1^t]-1,d[t]&&(u[1^t]-=M*p*m[t],k<A&&i[A]>i[k]&&(r.uniforms.dataAxis=c,r.uniforms.screenOffset=u,r.uniforms.color=g[t],r.uniforms.angle=v[t],a.drawArrays(a.TRIANGLES,i[k],i[A]-i[k]))),y[t]&&T&&(u[1^t]-=M*p*x[t],r.uniforms.dataAxis=f,r.uniforms.screenOffset=u,r.uniforms.color=b[t],r.uniforms.angle=_[t],a.drawArrays(a.TRIANGLES,w,T)),u[1^t]=M*s[2+(1^t)]-1,d[t+2]&&(u[1^t]+=M*p*m[t+2],k<A&&i[A]>i[k]&&(r.uniforms.dataAxis=c,r.uniforms.screenOffset=u,r.uniforms.color=g[t+2],r.uniforms.angle=v[t+2],a.drawArrays(a.TRIANGLES,i[k],i[A]-i[k]))),y[t+2]&&T&&(u[1^t]+=M*p*x[t+2],r.uniforms.dataAxis=f,r.uniforms.screenOffset=u,r.uniforms.color=b[t+2],r.uniforms.angle=_[t+2],a.drawArrays(a.TRIANGLES,w,T))}),m.drawTitle=function(){var t=[0,0],e=[0,0];return function(){var r=this.plot,n=this.shader,i=r.gl,a=r.screenBox,o=r.titleCenter,s=r.titleAngle,l=r.titleColor,c=r.pixelRatio;if(this.titleCount){for(var u=0;u<2;++u)e[u]=2*(o[u]*c-a[u])/(a[2+u]-a[u])-1;n.bind(),n.uniforms.dataAxis=t,n.uniforms.screenOffset=e,n.uniforms.angle=s,n.uniforms.color=l,i.drawArrays(i.TRIANGLES,this.titleOffset,this.titleCount)}}}(),m.bind=(h=[0,0],p=[0,0],d=[0,0],function(){var t=this.plot,e=this.shader,r=t._tickBounds,n=t.dataBox,i=t.screenBox,a=t.viewBox;e.bind();for(var o=0;o<2;++o){var s=r[o],l=r[o+2]-s,c=.5*(n[o+2]+n[o]),u=n[o+2]-n[o],f=a[o],m=a[o+2]-f,g=i[o],v=i[o+2]-g;p[o]=2*l/u*m/v,h[o]=2*(s-c)/u*m/v}d[1]=2*t.pixelRatio/(i[3]-i[1]),d[0]=d[1]*(i[3]-i[1])/(i[2]-i[0]),e.uniforms.dataScale=p,e.uniforms.dataShift=h,e.uniforms.textScale=d,this.vbo.bind(),e.attributes.textCoordinate.pointer()}),m.update=function(t){var e,r,n,i,o,s=[],l=t.ticks,c=t.bounds;for(o=0;o<2;++o){var u=[Math.floor(s.length/3)],f=[-1/0],h=l[o];for(e=0;e<h.length;++e){var p=h[e],d=p.x,m=p.text,g=p.font||"sans-serif";i=p.fontSize||12;for(var v=1/(c[o+2]-c[o]),y=c[o],x=m.split("\n"),b=0;b<x.length;b++)for(n=a(g,x[b]).data,r=0;r<n.length;r+=2)s.push(n[r]*i,-n[r+1]*i-b*i*1.2,(d-y)*v);u.push(Math.floor(s.length/3)),f.push(d)}this.tickOffset[o]=u,this.tickX[o]=f}for(o=0;o<2;++o){for(this.labelOffset[o]=Math.floor(s.length/3),n=a(t.labelFont[o],t.labels[o],{textAlign:"center"}).data,i=t.labelSize[o],e=0;e<n.length;e+=2)s.push(n[e]*i,-n[e+1]*i,0);this.labelCount[o]=Math.floor(s.length/3)-this.labelOffset[o]}for(this.titleOffset=Math.floor(s.length/3),n=a(t.titleFont,t.title).data,i=t.titleSize,e=0;e<n.length;e+=2)s.push(n[e]*i,-n[e+1]*i,0);this.titleCount=Math.floor(s.length/3)-this.titleOffset,this.vbo.update(s)},m.dispose=function(){this.vbo.dispose(),this.shader.dispose()}},{"./shaders":116,"binary-search-bounds":31,"gl-buffer":78,"gl-shader":132,"text-cache":303}],118:[function(t,e,r){"use strict";e.exports=function(t){var e=t.gl,r=n(e,[e.drawingBufferWidth,e.drawingBufferHeight]),c=new l(e,r);return c.grid=i(c),c.text=a(c),c.line=o(c),c.box=s(c),c.update(t),c};var n=t("gl-select-static"),i=t("./lib/grid"),a=t("./lib/text"),o=t("./lib/line"),s=t("./lib/box");function l(t,e){this.gl=t,this.pickBuffer=e,this.screenBox=[0,0,t.drawingBufferWidth,t.drawingBufferHeight],this.viewBox=[0,0,0,0],this.dataBox=[-10,-10,10,10],this.gridLineEnable=[!0,!0],this.gridLineWidth=[1,1],this.gridLineColor=[[0,0,0,1],[0,0,0,1]],this.pixelRatio=1,this.tickMarkLength=[0,0,0,0],this.tickMarkWidth=[0,0,0,0],this.tickMarkColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.tickPad=[15,15,15,15],this.tickAngle=[0,0,0,0],this.tickEnable=[!0,!0,!0,!0],this.tickColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.labelPad=[15,15,15,15],this.labelAngle=[0,Math.PI/2,0,3*Math.PI/2],this.labelEnable=[!0,!0,!0,!0],this.labelColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.titleCenter=[0,0],this.titleEnable=!0,this.titleAngle=0,this.titleColor=[0,0,0,1],this.borderColor=[0,0,0,0],this.backgroundColor=[0,0,0,0],this.zeroLineEnable=[!0,!0],this.zeroLineWidth=[4,4],this.zeroLineColor=[[0,0,0,1],[0,0,0,1]],this.borderLineEnable=[!0,!0,!0,!0],this.borderLineWidth=[2,2,2,2],this.borderLineColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.grid=null,this.text=null,this.line=null,this.box=null,this.objects=[],this.overlays=[],this._tickBounds=[1/0,1/0,-1/0,-1/0],this.static=!1,this.dirty=!1,this.pickDirty=!1,this.pickDelay=120,this.pickRadius=10,this._pickTimeout=null,this._drawPick=this.drawPick.bind(this),this._depthCounter=0}var c=l.prototype;function u(t){for(var e=t.slice(),r=0;r<e.length;++r)e[r]=e[r].slice();return e}function f(t,e){return t.x-e.x}c.setDirty=function(){this.dirty=this.pickDirty=!0},c.setOverlayDirty=function(){this.dirty=!0},c.nextDepthValue=function(){return this._depthCounter++/65536},c.draw=function(){var t=this.gl,e=this.screenBox,r=this.viewBox,n=this.dataBox,i=this.pixelRatio,a=this.grid,o=this.line,s=this.text,l=this.objects;if(this._depthCounter=0,this.pickDirty&&(this._pickTimeout&&clearTimeout(this._pickTimeout),this.pickDirty=!1,this._pickTimeout=setTimeout(this._drawPick,this.pickDelay)),this.dirty){if(this.dirty=!1,t.bindFramebuffer(t.FRAMEBUFFER,null),t.enable(t.SCISSOR_TEST),t.disable(t.DEPTH_TEST),t.depthFunc(t.LESS),t.depthMask(!1),t.enable(t.BLEND),t.blendEquation(t.FUNC_ADD,t.FUNC_ADD),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),this.borderColor){t.scissor(e[0],e[1],e[2]-e[0],e[3]-e[1]);var c=this.borderColor;t.clearColor(c[0]*c[3],c[1]*c[3],c[2]*c[3],c[3]),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT)}t.scissor(r[0],r[1],r[2]-r[0],r[3]-r[1]),t.viewport(r[0],r[1],r[2]-r[0],r[3]-r[1]);var u=this.backgroundColor;t.clearColor(u[0]*u[3],u[1]*u[3],u[2]*u[3],u[3]),t.clear(t.COLOR_BUFFER_BIT),a.draw();var f=this.zeroLineEnable,h=this.zeroLineColor,p=this.zeroLineWidth;if(f[0]||f[1]){o.bind();for(var d=0;d<2;++d)if(f[d]&&n[d]<=0&&n[d+2]>=0){var m=e[d]-n[d]*(e[d+2]-e[d])/(n[d+2]-n[d]);0===d?o.drawLine(m,e[1],m,e[3],p[d],h[d]):o.drawLine(e[0],m,e[2],m,p[d],h[d])}}for(d=0;d<l.length;++d)l[d].draw();t.viewport(e[0],e[1],e[2]-e[0],e[3]-e[1]),t.scissor(e[0],e[1],e[2]-e[0],e[3]-e[1]),this.grid.drawTickMarks(),o.bind();var g=this.borderLineEnable,v=this.borderLineWidth,y=this.borderLineColor;for(g[1]&&o.drawLine(r[0],r[1]-.5*v[1]*i,r[0],r[3]+.5*v[3]*i,v[1],y[1]),g[0]&&o.drawLine(r[0]-.5*v[0]*i,r[1],r[2]+.5*v[2]*i,r[1],v[0],y[0]),g[3]&&o.drawLine(r[2],r[1]-.5*v[1]*i,r[2],r[3]+.5*v[3]*i,v[3],y[3]),g[2]&&o.drawLine(r[0]-.5*v[0]*i,r[3],r[2]+.5*v[2]*i,r[3],v[2],y[2]),s.bind(),d=0;d<2;++d)s.drawTicks(d);this.titleEnable&&s.drawTitle();var x=this.overlays;for(d=0;d<x.length;++d)x[d].draw();t.disable(t.SCISSOR_TEST),t.disable(t.BLEND),t.depthMask(!0)}},c.drawPick=function(){if(!this.static){var t=this.pickBuffer;this.gl,this._pickTimeout=null,t.begin();for(var e=1,r=this.objects,n=0;n<r.length;++n)e=r[n].drawPick(e);t.end()}},c.pick=function(t,e){if(!this.static){var r=this.pixelRatio,n=this.pickPixelRatio,i=this.viewBox,a=0|Math.round((t-i[0]/r)*n),o=0|Math.round((e-i[1]/r)*n),s=this.pickBuffer.query(a,o,this.pickRadius);if(!s)return null;for(var l=s.id+(s.value[0]<<8)+(s.value[1]<<16)+(s.value[2]<<24),c=this.objects,u=0;u<c.length;++u){var f=c[u].pick(a,o,l);if(f)return f}return null}},c.setScreenBox=function(t){var e=this.screenBox,r=this.pixelRatio;e[0]=0|Math.round(t[0]*r),e[1]=0|Math.round(t[1]*r),e[2]=0|Math.round(t[2]*r),e[3]=0|Math.round(t[3]*r),this.setDirty()},c.setDataBox=function(t){var e=this.dataBox;(e[0]!==t[0]||e[1]!==t[1]||e[2]!==t[2]||e[3]!==t[3])&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],this.setDirty())},c.setViewBox=function(t){var e=this.pixelRatio,r=this.viewBox;r[0]=0|Math.round(t[0]*e),r[1]=0|Math.round(t[1]*e),r[2]=0|Math.round(t[2]*e),r[3]=0|Math.round(t[3]*e);var n=this.pickPixelRatio;this.pickBuffer.shape=[0|Math.round((t[2]-t[0])*n),0|Math.round((t[3]-t[1])*n)],this.setDirty()},c.update=function(t){t=t||{};var e=this.gl;this.pixelRatio=t.pixelRatio||1;var r=this.pixelRatio;this.pickPixelRatio=Math.max(r,1),this.setScreenBox(t.screenBox||[0,0,e.drawingBufferWidth/r,e.drawingBufferHeight/r]);this.screenBox;this.setViewBox(t.viewBox||[.125*(this.screenBox[2]-this.screenBox[0])/r,.125*(this.screenBox[3]-this.screenBox[1])/r,.875*(this.screenBox[2]-this.screenBox[0])/r,.875*(this.screenBox[3]-this.screenBox[1])/r]);var n=this.viewBox,i=(n[2]-n[0])/(n[3]-n[1]);this.setDataBox(t.dataBox||[-10,-10/i,10,10/i]),this.borderColor=!1!==t.borderColor&&(t.borderColor||[0,0,0,0]).slice(),this.backgroundColor=(t.backgroundColor||[0,0,0,0]).slice(),this.gridLineEnable=(t.gridLineEnable||[!0,!0]).slice(),this.gridLineWidth=(t.gridLineWidth||[1,1]).slice(),this.gridLineColor=u(t.gridLineColor||[[.5,.5,.5,1],[.5,.5,.5,1]]),this.zeroLineEnable=(t.zeroLineEnable||[!0,!0]).slice(),this.zeroLineWidth=(t.zeroLineWidth||[4,4]).slice(),this.zeroLineColor=u(t.zeroLineColor||[[0,0,0,1],[0,0,0,1]]),this.tickMarkLength=(t.tickMarkLength||[0,0,0,0]).slice(),this.tickMarkWidth=(t.tickMarkWidth||[0,0,0,0]).slice(),this.tickMarkColor=u(t.tickMarkColor||[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]]),this.titleCenter=(t.titleCenter||[.5*(n[0]+n[2])/r,(n[3]+120)/r]).slice(),this.titleEnable=!("titleEnable"in t)||!!t.titleEnable,this.titleAngle=t.titleAngle||0,this.titleColor=(t.titleColor||[0,0,0,1]).slice(),this.labelPad=(t.labelPad||[15,15,15,15]).slice(),this.labelAngle=(t.labelAngle||[0,Math.PI/2,0,3*Math.PI/2]).slice(),this.labelEnable=(t.labelEnable||[!0,!0,!0,!0]).slice(),this.labelColor=u(t.labelColor||[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]]),this.tickPad=(t.tickPad||[15,15,15,15]).slice(),this.tickAngle=(t.tickAngle||[0,0,0,0]).slice(),this.tickEnable=(t.tickEnable||[!0,!0,!0,!0]).slice(),this.tickColor=u(t.tickColor||[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]]),this.borderLineEnable=(t.borderLineEnable||[!0,!0,!0,!0]).slice(),this.borderLineWidth=(t.borderLineWidth||[2,2,2,2]).slice(),this.borderLineColor=u(t.borderLineColor||[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]]);var a=t.ticks||[[],[]],o=this._tickBounds;o[0]=o[1]=1/0,o[2]=o[3]=-1/0;for(var s=0;s<2;++s){var l=a[s].slice(0);0!==l.length&&(l.sort(f),o[s]=Math.min(o[s],l[0].x),o[s+2]=Math.max(o[s+2],l[l.length-1].x))}this.grid.update({bounds:o,ticks:a}),this.text.update({bounds:o,ticks:a,labels:t.labels||["x","y"],labelSize:t.labelSize||[12,12],labelFont:t.labelFont||["sans-serif","sans-serif"],title:t.title||"",titleSize:t.titleSize||18,titleFont:t.titleFont||"sans-serif"}),this.static=!!t.static,this.setDirty()},c.dispose=function(){this.box.dispose(),this.grid.dispose(),this.text.dispose(),this.line.dispose();for(var t=this.objects.length-1;t>=0;--t)this.objects[t].dispose();this.objects.length=0;for(t=this.overlays.length-1;t>=0;--t)this.overlays[t].dispose();this.overlays.length=0,this.gl=null},c.addObject=function(t){this.objects.indexOf(t)<0&&(this.objects.push(t),this.setDirty())},c.removeObject=function(t){for(var e=this.objects,r=0;r<e.length;++r)if(e[r]===t){e.splice(r,1),this.setDirty();break}},c.addOverlay=function(t){this.overlays.indexOf(t)<0&&(this.overlays.push(t),this.setOverlayDirty())},c.removeOverlay=function(t){for(var e=this.overlays,r=0;r<e.length;++r)if(e[r]===t){e.splice(r,1),this.setOverlayDirty();break}}},{"./lib/box":113,"./lib/grid":114,"./lib/line":115,"./lib/text":117,"gl-select-static":131}],119:[function(t,e,r){"use strict";e.exports=function(t,e){t=t||document.body,e=e||{};var r=[.01,1/0];"distanceLimits"in e&&(r[0]=e.distanceLimits[0],r[1]=e.distanceLimits[1]);"zoomMin"in e&&(r[0]=e.zoomMin);"zoomMax"in e&&(r[1]=e.zoomMax);var c=i({center:e.center||[0,0,0],up:e.up||[0,1,0],eye:e.eye||[0,0,10],mode:e.mode||"orbit",distanceLimits:r}),u=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],f=0,h=t.clientWidth,p=t.clientHeight,d={keyBindingMode:"rotate",enableWheel:!0,view:c,element:t,delay:e.delay||16,rotateSpeed:e.rotateSpeed||1,zoomSpeed:e.zoomSpeed||1,translateSpeed:e.translateSpeed||1,flipX:!!e.flipX,flipY:!!e.flipY,modes:c.modes,_ortho:e._ortho||e.projection&&"orthographic"===e.projection.type||!1,tick:function(){var e=n(),r=this.delay,i=e-2*r;c.idle(e-r),c.recalcMatrix(i),c.flush(e-(100+2*r));for(var a=!0,o=c.computedMatrix,s=0;s<16;++s)a=a&&u[s]===o[s],u[s]=o[s];var l=t.clientWidth===h&&t.clientHeight===p;return h=t.clientWidth,p=t.clientHeight,a?!l:(f=Math.exp(c.computedRadius[0]),!0)},lookAt:function(t,e,r){c.lookAt(c.lastT(),t,e,r)},rotate:function(t,e,r){c.rotate(c.lastT(),t,e,r)},pan:function(t,e,r){c.pan(c.lastT(),t,e,r)},translate:function(t,e,r){c.translate(c.lastT(),t,e,r)}};return Object.defineProperties(d,{matrix:{get:function(){return c.computedMatrix},set:function(t){return c.setMatrix(c.lastT(),t),c.computedMatrix},enumerable:!0},mode:{get:function(){return c.getMode()},set:function(t){var e=c.computedUp.slice(),r=c.computedEye.slice(),i=c.computedCenter.slice();if(c.setMode(t),"turntable"===t){var a=n();c._active.lookAt(a,r,i,e),c._active.lookAt(a+500,r,i,[0,0,1]),c._active.flush(a)}return c.getMode()},enumerable:!0},center:{get:function(){return c.computedCenter},set:function(t){return c.lookAt(c.lastT(),null,t),c.computedCenter},enumerable:!0},eye:{get:function(){return c.computedEye},set:function(t){return c.lookAt(c.lastT(),t),c.computedEye},enumerable:!0},up:{get:function(){return c.computedUp},set:function(t){return c.lookAt(c.lastT(),null,null,t),c.computedUp},enumerable:!0},distance:{get:function(){return f},set:function(t){return c.setDistance(c.lastT(),t),t},enumerable:!0},distanceLimits:{get:function(){return c.getDistanceLimits(r)},set:function(t){return c.setDistanceLimits(t),t},enumerable:!0}}),t.addEventListener("contextmenu",(function(t){return t.preventDefault(),!1})),d._lastX=-1,d._lastY=-1,d._lastMods={shift:!1,control:!1,alt:!1,meta:!1},d.enableMouseListeners=function(){function e(e,r,i,a){var o=d.keyBindingMode;if(!1!==o){var s="rotate"===o,l="pan"===o,u="zoom"===o,h=!!a.control,p=!!a.alt,m=!!a.shift,g=!!(1&e),v=!!(2&e),y=!!(4&e),x=1/t.clientHeight,b=x*(r-d._lastX),_=x*(i-d._lastY),w=d.flipX?1:-1,T=d.flipY?1:-1,k=Math.PI*d.rotateSpeed,A=n();if(-1!==d._lastX&&-1!==d._lastY&&((s&&g&&!h&&!p&&!m||g&&!h&&!p&&m)&&c.rotate(A,w*k*b,-T*k*_,0),(l&&g&&!h&&!p&&!m||v||g&&h&&!p&&!m)&&c.pan(A,-d.translateSpeed*b*f,d.translateSpeed*_*f,0),u&&g&&!h&&!p&&!m||y||g&&!h&&p&&!m)){var M=-d.zoomSpeed*_/window.innerHeight*(A-c.lastT())*100;c.pan(A,0,0,f*(Math.exp(M)-1))}return d._lastX=r,d._lastY=i,d._lastMods=a,!0}}d.mouseListener=a(t,e),t.addEventListener("touchstart",(function(r){var n=s(r.changedTouches[0],t);e(0,n[0],n[1],d._lastMods),e(1,n[0],n[1],d._lastMods)}),!!l&&{passive:!0}),t.addEventListener("touchmove",(function(r){var n=s(r.changedTouches[0],t);e(1,n[0],n[1],d._lastMods),r.preventDefault()}),!!l&&{passive:!1}),t.addEventListener("touchend",(function(t){e(0,d._lastX,d._lastY,d._lastMods)}),!!l&&{passive:!0}),d.wheelListener=o(t,(function(t,e){if(!1!==d.keyBindingMode&&d.enableWheel){var r=d.flipX?1:-1,i=d.flipY?1:-1,a=n();if(Math.abs(t)>Math.abs(e))c.rotate(a,0,0,-t*r*Math.PI*d.rotateSpeed/window.innerWidth);else if(!d._ortho){var o=-d.zoomSpeed*i*e/window.innerHeight*(a-c.lastT())/20;c.pan(a,0,0,f*(Math.exp(o)-1))}}}),!0)},d.enableMouseListeners(),d};var n=t("right-now"),i=t("3d-view"),a=t("mouse-change"),o=t("mouse-wheel"),s=t("mouse-event-offset"),l=t("has-passive-events")},{"3d-view":7,"has-passive-events":232,"mouse-change":247,"mouse-event-offset":248,"mouse-wheel":250,"right-now":278}],120:[function(t,e,r){var n=t("glslify"),i=t("gl-shader"),a=n(["precision mediump float;\n#define GLSLIFY 1\nattribute vec2 position;\nvarying vec2 uv;\nvoid main() {\n  uv = position;\n  gl_Position = vec4(position, 0, 1);\n}"]),o=n(["precision mediump float;\n#define GLSLIFY 1\n\nuniform sampler2D accumBuffer;\nvarying vec2 uv;\n\nvoid main() {\n  vec4 accum = texture2D(accumBuffer, 0.5 * (uv + 1.0));\n  gl_FragColor = min(vec4(1,1,1,1), accum);\n}"]);e.exports=function(t){return i(t,a,o,null,[{name:"position",type:"vec2"}])}},{"gl-shader":132,glslify:231}],121:[function(t,e,r){"use strict";var n=t("./camera.js"),i=t("gl-axes3d"),a=t("gl-axes3d/properties"),o=t("gl-spikes3d"),s=t("gl-select-static"),l=t("gl-fbo"),c=t("a-big-triangle"),u=t("mouse-change"),f=t("gl-mat4/perspective"),h=t("gl-mat4/ortho"),p=t("./lib/shader"),d=t("is-mobile")({tablet:!0,featureDetect:!0});function m(){this.mouse=[-1,-1],this.screen=null,this.distance=1/0,this.index=null,this.dataCoordinate=null,this.dataPosition=null,this.object=null,this.data=null}function g(t){var e=Math.round(Math.log(Math.abs(t))/Math.log(10));if(e<0){var r=Math.round(Math.pow(10,-e));return Math.ceil(t*r)/r}if(e>0){r=Math.round(Math.pow(10,e));return Math.ceil(t/r)*r}return Math.ceil(t)}function v(t){return"boolean"!=typeof t||t}e.exports={createScene:function(t){(t=t||{}).camera=t.camera||{};var e=t.canvas;if(!e){if(e=document.createElement("canvas"),t.container)t.container.appendChild(e);else document.body.appendChild(e)}var r=t.gl;r||(t.glOptions&&(d=!!t.glOptions.preserveDrawingBuffer),r=function(t,e){var r=null;try{(r=t.getContext("webgl",e))||(r=t.getContext("experimental-webgl",e))}catch(t){return null}return r}(e,t.glOptions||{premultipliedAlpha:!0,antialias:!0,preserveDrawingBuffer:d}));if(!r)throw new Error("webgl not supported");var y=t.bounds||[[-10,-10,-10],[10,10,10]],x=new m,b=l(r,r.drawingBufferWidth,r.drawingBufferHeight,{preferFloat:!d}),_=p(r),w=t.cameraObject&&!0===t.cameraObject._ortho||t.camera.projection&&"orthographic"===t.camera.projection.type||!1,T={eye:t.camera.eye||[2,0,0],center:t.camera.center||[0,0,0],up:t.camera.up||[0,1,0],zoomMin:t.camera.zoomMax||.1,zoomMax:t.camera.zoomMin||100,mode:t.camera.mode||"turntable",_ortho:w},k=t.axes||{},A=i(r,k);A.enable=!k.disable;var M=t.spikes||{},S=o(r,M),E=[],L=[],C=[],P=[],I=!0,O=!0,z=new Array(16),D=new Array(16),R={view:null,projection:z,model:D,_ortho:!1},F=(O=!0,[r.drawingBufferWidth,r.drawingBufferHeight]),B=t.cameraObject||n(e,T),N={gl:r,contextLost:!1,pixelRatio:t.pixelRatio||1,canvas:e,selection:x,camera:B,axes:A,axesPixels:null,spikes:S,bounds:y,objects:E,shape:F,aspect:t.aspectRatio||[1,1,1],pickRadius:t.pickRadius||10,zNear:t.zNear||.01,zFar:t.zFar||1e3,fovy:t.fovy||Math.PI/4,clearColor:t.clearColor||[0,0,0,0],autoResize:v(t.autoResize),autoBounds:v(t.autoBounds),autoScale:!!t.autoScale,autoCenter:v(t.autoCenter),clipToBounds:v(t.clipToBounds),snapToData:!!t.snapToData,onselect:t.onselect||null,onrender:t.onrender||null,onclick:t.onclick||null,cameraParams:R,oncontextloss:null,mouseListener:null,_stopped:!1,getAspectratio:function(){return{x:this.aspect[0],y:this.aspect[1],z:this.aspect[2]}},setAspectratio:function(t){this.aspect[0]=t.x,this.aspect[1]=t.y,this.aspect[2]=t.z,O=!0},setBounds:function(t,e){this.bounds[0][t]=e.min,this.bounds[1][t]=e.max},setClearColor:function(t){this.clearColor=t},clearRGBA:function(){this.gl.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT)}},j=[r.drawingBufferWidth/N.pixelRatio|0,r.drawingBufferHeight/N.pixelRatio|0];function U(){if(!N._stopped&&N.autoResize){var t=e.parentNode,r=1,n=1;t&&t!==document.body?(r=t.clientWidth,n=t.clientHeight):(r=window.innerWidth,n=window.innerHeight);var i=0|Math.ceil(r*N.pixelRatio),a=0|Math.ceil(n*N.pixelRatio);if(i!==e.width||a!==e.height){e.width=i,e.height=a;var o=e.style;o.position=o.position||"absolute",o.left="0px",o.top="0px",o.width=r+"px",o.height=n+"px",I=!0}}}N.autoResize&&U();function V(){for(var t=E.length,e=P.length,n=0;n<e;++n)C[n]=0;t:for(n=0;n<t;++n){var i=E[n],a=i.pickSlots;if(a){for(var o=0;o<e;++o)if(C[o]+a<255){L[n]=o,i.setPickBase(C[o]+1),C[o]+=a;continue t}var l=s(r,F);L[n]=e,P.push(l),C.push(a),i.setPickBase(1),e+=1}else L[n]=-1}for(;e>0&&0===C[e-1];)C.pop(),P.pop().dispose()}function H(){if(N.contextLost)return!0;r.isContextLost()&&(N.contextLost=!0,N.mouseListener.enabled=!1,N.selection.object=null,N.oncontextloss&&N.oncontextloss())}window.addEventListener("resize",U),N.update=function(t){N._stopped||(t=t||{},I=!0,O=!0)},N.add=function(t){N._stopped||(t.axes=A,E.push(t),L.push(-1),I=!0,O=!0,V())},N.remove=function(t){if(!N._stopped){var e=E.indexOf(t);e<0||(E.splice(e,1),L.pop(),I=!0,O=!0,V())}},N.dispose=function(){if(!N._stopped&&(N._stopped=!0,window.removeEventListener("resize",U),e.removeEventListener("webglcontextlost",H),N.mouseListener.enabled=!1,!N.contextLost)){A.dispose(),S.dispose();for(var t=0;t<E.length;++t)E[t].dispose();b.dispose();for(t=0;t<P.length;++t)P[t].dispose();_.dispose(),r=null,A=null,S=null,E=[]}},N._mouseRotating=!1,N._prevButtons=0,N.enableMouseListeners=function(){N.mouseListener=u(e,(function(t,e,r){if(!N._stopped){var n=P.length,i=E.length,a=x.object;x.distance=1/0,x.mouse[0]=e,x.mouse[1]=r,x.object=null,x.screen=null,x.dataCoordinate=x.dataPosition=null;var o=!1;if(t&&N._prevButtons)N._mouseRotating=!0;else{N._mouseRotating&&(O=!0),N._mouseRotating=!1;for(var s=0;s<n;++s){var l=P[s].query(e,j[1]-r-1,N.pickRadius);if(l){if(l.distance>x.distance)continue;for(var c=0;c<i;++c){var u=E[c];if(L[c]===s){var f=u.pick(l);f&&(x.buttons=t,x.screen=l.coord,x.distance=l.distance,x.object=u,x.index=f.distance,x.dataPosition=f.position,x.dataCoordinate=f.dataCoordinate,x.data=f,o=!0)}}}}}a&&a!==x.object&&(a.highlight&&a.highlight(null),I=!0),x.object&&(x.object.highlight&&x.object.highlight(x.data),I=!0),(o=o||x.object!==a)&&N.onselect&&N.onselect(x),1&t&&!(1&N._prevButtons)&&N.onclick&&N.onclick(x),N._prevButtons=t}}))},e.addEventListener("webglcontextlost",H);var q=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]],G=[q[0].slice(),q[1].slice()];function Y(){if(!H()){U();var t=N.camera.tick();R.view=N.camera.matrix,I=I||t,O=O||t,A.pixelRatio=N.pixelRatio,S.pixelRatio=N.pixelRatio;var e=E.length,n=q[0],i=q[1];n[0]=n[1]=n[2]=1/0,i[0]=i[1]=i[2]=-1/0;for(var o=0;o<e;++o){(C=E[o]).pixelRatio=N.pixelRatio,C.axes=N.axes,I=I||!!C.dirty,O=O||!!C.dirty;var s=C.bounds;if(s)for(var l=s[0],u=s[1],p=0;p<3;++p)n[p]=Math.min(n[p],l[p]),i[p]=Math.max(i[p],u[p])}var d=N.bounds;if(N.autoBounds)for(p=0;p<3;++p){if(i[p]<n[p])n[p]=-1,i[p]=1;else{n[p]===i[p]&&(n[p]-=1,i[p]+=1);var m=.05*(i[p]-n[p]);n[p]=n[p]-m,i[p]=i[p]+m}d[0][p]=n[p],d[1][p]=i[p]}var v=!1;for(p=0;p<3;++p)v=v||G[0][p]!==d[0][p]||G[1][p]!==d[1][p],G[0][p]=d[0][p],G[1][p]=d[1][p];if(O=O||v,I=I||v){if(v){var y=[0,0,0];for(o=0;o<3;++o)y[o]=g((d[1][o]-d[0][o])/10);A.autoTicks?A.update({bounds:d,tickSpacing:y}):A.update({bounds:d})}var T=r.drawingBufferWidth,k=r.drawingBufferHeight;F[0]=T,F[1]=k,j[0]=0|Math.max(T/N.pixelRatio,1),j[1]=0|Math.max(k/N.pixelRatio,1),function(t,e){var r=t.bounds,n=t.cameraParams,i=n.projection,a=n.model,o=t.gl.drawingBufferWidth,s=t.gl.drawingBufferHeight,l=t.zNear,c=t.zFar,u=t.fovy,p=o/s;e?(h(i,-p,p,-1,1,l,c),n._ortho=!0):(f(i,u,p,l,c),n._ortho=!1);for(var d=0;d<16;++d)a[d]=0;a[15]=1;var m=0;for(d=0;d<3;++d)m=Math.max(m,r[1][d]-r[0][d]);for(d=0;d<3;++d)t.autoScale?a[5*d]=t.aspect[d]/(r[1][d]-r[0][d]):a[5*d]=1/m,t.autoCenter&&(a[12+d]=.5*-a[5*d]*(r[0][d]+r[1][d]))}(N,w);for(o=0;o<e;++o){(C=E[o]).axesBounds=d,N.clipToBounds&&(C.clipBounds=d)}x.object&&(N.snapToData?S.position=x.dataCoordinate:S.position=x.dataPosition,S.bounds=d),O&&(O=!1,function(){if(!H()){r.colorMask(!0,!0,!0,!0),r.depthMask(!0),r.disable(r.BLEND),r.enable(r.DEPTH_TEST),r.depthFunc(r.LEQUAL);for(var t=E.length,e=P.length,n=0;n<e;++n){var i=P[n];i.shape=j,i.begin();for(var a=0;a<t;++a)if(L[a]===n){var o=E[a];o.drawPick&&(o.pixelRatio=1,o.drawPick(R))}i.end()}}}()),N.axesPixels=a(N.axes,R,T,k),N.onrender&&N.onrender(),r.bindFramebuffer(r.FRAMEBUFFER,null),r.viewport(0,0,T,k),N.clearRGBA(),r.depthMask(!0),r.colorMask(!0,!0,!0,!0),r.enable(r.DEPTH_TEST),r.depthFunc(r.LEQUAL),r.disable(r.BLEND),r.disable(r.CULL_FACE);var M=!1;A.enable&&(M=M||A.isTransparent(),A.draw(R)),S.axes=A,x.object&&S.draw(R),r.disable(r.CULL_FACE);for(o=0;o<e;++o){(C=E[o]).axes=A,C.pixelRatio=N.pixelRatio,C.isOpaque&&C.isOpaque()&&C.draw(R),C.isTransparent&&C.isTransparent()&&(M=!0)}if(M){b.shape=F,b.bind(),r.clear(r.DEPTH_BUFFER_BIT),r.colorMask(!1,!1,!1,!1),r.depthMask(!0),r.depthFunc(r.LESS),A.enable&&A.isTransparent()&&A.drawTransparent(R);for(o=0;o<e;++o){(C=E[o]).isOpaque&&C.isOpaque()&&C.draw(R)}r.enable(r.BLEND),r.blendEquation(r.FUNC_ADD),r.blendFunc(r.ONE,r.ONE_MINUS_SRC_ALPHA),r.colorMask(!0,!0,!0,!0),r.depthMask(!1),r.clearColor(0,0,0,0),r.clear(r.COLOR_BUFFER_BIT),A.isTransparent()&&A.drawTransparent(R);for(o=0;o<e;++o){var C;(C=E[o]).isTransparent&&C.isTransparent()&&C.drawTransparent(R)}r.bindFramebuffer(r.FRAMEBUFFER,null),r.blendFunc(r.ONE,r.ONE_MINUS_SRC_ALPHA),r.disable(r.DEPTH_TEST),_.bind(),b.color[0].bind(0),_.uniforms.accumBuffer=0,c(r),r.disable(r.BLEND)}I=!1;for(o=0;o<e;++o)E[o].dirty=!1}}}return N.enableMouseListeners(),function t(){if(N._stopped||N.contextLost)return;Y(),requestAnimationFrame(t)}(),N.redraw=function(){N._stopped||(I=!0,Y())},N},createCamera:n}},{"./camera.js":119,"./lib/shader":120,"a-big-triangle":8,"gl-axes3d":70,"gl-axes3d/properties":77,"gl-fbo":86,"gl-mat4/ortho":101,"gl-mat4/perspective":102,"gl-select-static":131,"gl-spikes3d":141,"is-mobile":238,"mouse-change":247}],122:[function(t,e,r){var n=t("glslify");r.pointVertex=n(["precision mediump float;\n#define GLSLIFY 1\n\nattribute vec2 position;\n\nuniform mat3 matrix;\nuniform float pointSize;\nuniform float pointCloud;\n\nhighp float rand(vec2 co) {\n  highp float a = 12.9898;\n  highp float b = 78.233;\n  highp float c = 43758.5453;\n  highp float d = dot(co.xy, vec2(a, b));\n  highp float e = mod(d, 3.14);\n  return fract(sin(e) * c);\n}\n\nvoid main() {\n  vec3 hgPosition = matrix * vec3(position, 1);\n  gl_Position  = vec4(hgPosition.xy, 0, hgPosition.z);\n    // if we don't jitter the point size a bit, overall point cloud\n    // saturation 'jumps' on zooming, which is disturbing and confusing\n  gl_PointSize = pointSize * ((19.5 + rand(position)) / 20.0);\n  if(pointCloud != 0.0) { // pointCloud is truthy\n    // get the same square surface as circle would be\n    gl_PointSize *= 0.886;\n  }\n}"]),r.pointFragment=n(["precision mediump float;\n#define GLSLIFY 1\n\nuniform vec4 color, borderColor;\nuniform float centerFraction;\nuniform float pointCloud;\n\nvoid main() {\n  float radius;\n  vec4 baseColor;\n  if(pointCloud != 0.0) { // pointCloud is truthy\n    if(centerFraction == 1.0) {\n      gl_FragColor = color;\n    } else {\n      gl_FragColor = mix(borderColor, color, centerFraction);\n    }\n  } else {\n    radius = length(2.0 * gl_PointCoord.xy - 1.0);\n    if(radius > 1.0) {\n      discard;\n    }\n    baseColor = mix(borderColor, color, step(radius, centerFraction));\n    gl_FragColor = vec4(baseColor.rgb * baseColor.a, baseColor.a);\n  }\n}\n"]),r.pickVertex=n(["precision mediump float;\n#define GLSLIFY 1\n\nattribute vec2 position;\nattribute vec4 pickId;\n\nuniform mat3 matrix;\nuniform float pointSize;\nuniform vec4 pickOffset;\n\nvarying vec4 fragId;\n\nvoid main() {\n  vec3 hgPosition = matrix * vec3(position, 1);\n  gl_Position  = vec4(hgPosition.xy, 0, hgPosition.z);\n  gl_PointSize = pointSize;\n\n  vec4 id = pickId + pickOffset;\n  id.y += floor(id.x / 256.0);\n  id.x -= floor(id.x / 256.0) * 256.0;\n\n  id.z += floor(id.y / 256.0);\n  id.y -= floor(id.y / 256.0) * 256.0;\n\n  id.w += floor(id.z / 256.0);\n  id.z -= floor(id.z / 256.0) * 256.0;\n\n  fragId = id;\n}\n"]),r.pickFragment=n(["precision mediump float;\n#define GLSLIFY 1\n\nvarying vec4 fragId;\n\nvoid main() {\n  float radius = length(2.0 * gl_PointCoord.xy - 1.0);\n  if(radius > 1.0) {\n    discard;\n  }\n  gl_FragColor = fragId / 255.0;\n}\n"])},{glslify:231}],123:[function(t,e,r){"use strict";var n=t("gl-shader"),i=t("gl-buffer"),a=t("typedarray-pool"),o=t("./lib/shader");function s(t,e,r,n,i){this.plot=t,this.offsetBuffer=e,this.pickBuffer=r,this.shader=n,this.pickShader=i,this.sizeMin=.5,this.sizeMinCap=2,this.sizeMax=20,this.areaRatio=1,this.pointCount=0,this.color=[1,0,0,1],this.borderColor=[0,0,0,1],this.blend=!1,this.pickOffset=0,this.points=null}e.exports=function(t,e){var r=t.gl,a=i(r),l=i(r),c=n(r,o.pointVertex,o.pointFragment),u=n(r,o.pickVertex,o.pickFragment),f=new s(t,a,l,c,u);return f.update(e),t.addObject(f),f};var l,c,u=s.prototype;u.dispose=function(){this.shader.dispose(),this.pickShader.dispose(),this.offsetBuffer.dispose(),this.pickBuffer.dispose(),this.plot.removeObject(this)},u.update=function(t){var e;function r(e,r){return e in t?t[e]:r}t=t||{},this.sizeMin=r("sizeMin",.5),this.sizeMax=r("sizeMax",20),this.color=r("color",[1,0,0,1]).slice(),this.areaRatio=r("areaRatio",1),this.borderColor=r("borderColor",[0,0,0,1]).slice(),this.blend=r("blend",!1);var n=t.positions.length>>>1,i=t.positions instanceof Float32Array,o=t.idToIndex instanceof Int32Array&&t.idToIndex.length>=n,s=t.positions,l=i?s:a.mallocFloat32(s.length),c=o?t.idToIndex:a.mallocInt32(n);if(i||l.set(s),!o)for(l.set(s),e=0;e<n;e++)c[e]=e;this.points=s,this.offsetBuffer.update(l),this.pickBuffer.update(c),i||a.free(l),o||a.free(c),this.pointCount=n,this.pickOffset=0},u.unifiedDraw=(l=[1,0,0,0,1,0,0,0,1],c=[0,0,0,0],function(t){var e=void 0!==t,r=e?this.pickShader:this.shader,n=this.plot.gl,i=this.plot.dataBox;if(0===this.pointCount)return t;var a=i[2]-i[0],o=i[3]-i[1],s=function(t,e){var r,n=0,i=t.length>>>1;for(r=0;r<i;r++){var a=t[2*r],o=t[2*r+1];a>=e[0]&&a<=e[2]&&o>=e[1]&&o<=e[3]&&n++}return n}(this.points,i),u=this.plot.pickPixelRatio*Math.max(Math.min(this.sizeMinCap,this.sizeMin),Math.min(this.sizeMax,this.sizeMax/Math.pow(s,.33333)));l[0]=2/a,l[4]=2/o,l[6]=-2*i[0]/a-1,l[7]=-2*i[1]/o-1,this.offsetBuffer.bind(),r.bind(),r.attributes.position.pointer(),r.uniforms.matrix=l,r.uniforms.color=this.color,r.uniforms.borderColor=this.borderColor,r.uniforms.pointCloud=u<5,r.uniforms.pointSize=u,r.uniforms.centerFraction=Math.min(1,Math.max(0,Math.sqrt(1-this.areaRatio))),e&&(c[0]=255&t,c[1]=t>>8&255,c[2]=t>>16&255,c[3]=t>>24&255,this.pickBuffer.bind(),r.attributes.pickId.pointer(n.UNSIGNED_BYTE),r.uniforms.pickOffset=c,this.pickOffset=t);var f=n.getParameter(n.BLEND),h=n.getParameter(n.DITHER);return f&&!this.blend&&n.disable(n.BLEND),h&&n.disable(n.DITHER),n.drawArrays(n.POINTS,0,this.pointCount),f&&!this.blend&&n.enable(n.BLEND),h&&n.enable(n.DITHER),t+this.pointCount}),u.draw=u.unifiedDraw,u.drawPick=u.unifiedDraw,u.pick=function(t,e,r){var n=this.pickOffset,i=this.pointCount;if(r<n||r>=n+i)return null;var a=r-n,o=this.points;return{object:this,pointId:a,dataCoord:[o[2*a],o[2*a+1]]}}},{"./lib/shader":122,"gl-buffer":78,"gl-shader":132,"typedarray-pool":308}],124:[function(t,e,r){e.exports=function(t,e,r,n){var i,a,o,s,l,c=e[0],u=e[1],f=e[2],h=e[3],p=r[0],d=r[1],m=r[2],g=r[3];(a=c*p+u*d+f*m+h*g)<0&&(a=-a,p=-p,d=-d,m=-m,g=-g);1-a>1e-6?(i=Math.acos(a),o=Math.sin(i),s=Math.sin((1-n)*i)/o,l=Math.sin(n*i)/o):(s=1-n,l=n);return t[0]=s*c+l*p,t[1]=s*u+l*d,t[2]=s*f+l*m,t[3]=s*h+l*g,t}},{}],125:[function(t,e,r){"use strict";e.exports=function(t){return t||0===t?t.toString():""}},{}],126:[function(t,e,r){"use strict";var n=t("vectorize-text");e.exports=function(t,e,r){var a=i[e];a||(a=i[e]={});if(t in a)return a[t];var o={textAlign:"center",textBaseline:"middle",lineHeight:1,font:e,lineSpacing:1.25,styletags:{breaklines:!0,bolds:!0,italics:!0,subscripts:!0,superscripts:!0},triangles:!0},s=n(t,o);o.triangles=!1;var l,c,u=n(t,o);if(r&&1!==r){for(l=0;l<s.positions.length;++l)for(c=0;c<s.positions[l].length;++c)s.positions[l][c]/=r;for(l=0;l<u.positions.length;++l)for(c=0;c<u.positions[l].length;++c)u.positions[l][c]/=r}var f=[[1/0,1/0],[-1/0,-1/0]],h=u.positions.length;for(l=0;l<h;++l){var p=u.positions[l];for(c=0;c<2;++c)f[0][c]=Math.min(f[0][c],p[c]),f[1][c]=Math.max(f[1][c],p[c])}return a[t]=[s,u,f]};var i={}},{"vectorize-text":311}],127:[function(t,e,r){var n=t("gl-shader"),i=t("glslify"),a=i(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nattribute vec3 position;\nattribute vec4 color;\nattribute vec2 glyph;\nattribute vec4 id;\n\nuniform vec4 highlightId;\nuniform float highlightScale;\nuniform mat4 model, view, projection;\nuniform vec3 clipBounds[2];\n\nvarying vec4 interpColor;\nvarying vec4 pickId;\nvarying vec3 dataCoordinate;\n\nvoid main() {\n  if (outOfRange(clipBounds[0], clipBounds[1], position)) {\n\n    gl_Position = vec4(0,0,0,0);\n  } else {\n    float scale = 1.0;\n    if(distance(highlightId, id) < 0.0001) {\n      scale = highlightScale;\n    }\n\n    vec4 worldPosition = model * vec4(position, 1);\n    vec4 viewPosition = view * worldPosition;\n    viewPosition = viewPosition / viewPosition.w;\n    vec4 clipPosition = projection * (viewPosition + scale * vec4(glyph.x, -glyph.y, 0, 0));\n\n    gl_Position = clipPosition;\n    interpColor = color;\n    pickId = id;\n    dataCoordinate = position;\n  }\n}"]),o=i(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nattribute vec3 position;\nattribute vec4 color;\nattribute vec2 glyph;\nattribute vec4 id;\n\nuniform mat4 model, view, projection;\nuniform vec2 screenSize;\nuniform vec3 clipBounds[2];\nuniform float highlightScale, pixelRatio;\nuniform vec4 highlightId;\n\nvarying vec4 interpColor;\nvarying vec4 pickId;\nvarying vec3 dataCoordinate;\n\nvoid main() {\n  if (outOfRange(clipBounds[0], clipBounds[1], position)) {\n\n    gl_Position = vec4(0,0,0,0);\n  } else {\n    float scale = pixelRatio;\n    if(distance(highlightId.bgr, id.bgr) < 0.001) {\n      scale *= highlightScale;\n    }\n\n    vec4 worldPosition = model * vec4(position, 1.0);\n    vec4 viewPosition = view * worldPosition;\n    vec4 clipPosition = projection * viewPosition;\n    clipPosition /= clipPosition.w;\n\n    gl_Position = clipPosition + vec4(screenSize * scale * vec2(glyph.x, -glyph.y), 0.0, 0.0);\n    interpColor = color;\n    pickId = id;\n    dataCoordinate = position;\n  }\n}"]),s=i(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nattribute vec3 position;\nattribute vec4 color;\nattribute vec2 glyph;\nattribute vec4 id;\n\nuniform float highlightScale;\nuniform vec4 highlightId;\nuniform vec3 axes[2];\nuniform mat4 model, view, projection;\nuniform vec2 screenSize;\nuniform vec3 clipBounds[2];\nuniform float scale, pixelRatio;\n\nvarying vec4 interpColor;\nvarying vec4 pickId;\nvarying vec3 dataCoordinate;\n\nvoid main() {\n  if (outOfRange(clipBounds[0], clipBounds[1], position)) {\n\n    gl_Position = vec4(0,0,0,0);\n  } else {\n    float lscale = pixelRatio * scale;\n    if(distance(highlightId, id) < 0.0001) {\n      lscale *= highlightScale;\n    }\n\n    vec4 clipCenter   = projection * view * model * vec4(position, 1);\n    vec3 dataPosition = position + 0.5*lscale*(axes[0] * glyph.x + axes[1] * glyph.y) * clipCenter.w * screenSize.y;\n    vec4 clipPosition = projection * view * model * vec4(dataPosition, 1);\n\n    gl_Position = clipPosition;\n    interpColor = color;\n    pickId = id;\n    dataCoordinate = dataPosition;\n  }\n}\n"]),l=i(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec3 fragClipBounds[2];\nuniform float opacity;\n\nvarying vec4 interpColor;\nvarying vec3 dataCoordinate;\n\nvoid main() {\n  if (\n    outOfRange(fragClipBounds[0], fragClipBounds[1], dataCoordinate) ||\n    interpColor.a * opacity == 0.\n  ) discard;\n  gl_FragColor = interpColor * opacity;\n}\n"]),c=i(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec3 fragClipBounds[2];\nuniform float pickGroup;\n\nvarying vec4 pickId;\nvarying vec3 dataCoordinate;\n\nvoid main() {\n  if (outOfRange(fragClipBounds[0], fragClipBounds[1], dataCoordinate)) discard;\n\n  gl_FragColor = vec4(pickGroup, pickId.bgr);\n}"]),u=[{name:"position",type:"vec3"},{name:"color",type:"vec4"},{name:"glyph",type:"vec2"},{name:"id",type:"vec4"}],f={vertex:a,fragment:l,attributes:u},h={vertex:o,fragment:l,attributes:u},p={vertex:s,fragment:l,attributes:u},d={vertex:a,fragment:c,attributes:u},m={vertex:o,fragment:c,attributes:u},g={vertex:s,fragment:c,attributes:u};function v(t,e){var r=n(t,e),i=r.attributes;return i.position.location=0,i.color.location=1,i.glyph.location=2,i.id.location=3,r}r.createPerspective=function(t){return v(t,f)},r.createOrtho=function(t){return v(t,h)},r.createProject=function(t){return v(t,p)},r.createPickPerspective=function(t){return v(t,d)},r.createPickOrtho=function(t){return v(t,m)},r.createPickProject=function(t){return v(t,g)}},{"gl-shader":132,glslify:231}],128:[function(t,e,r){"use strict";var n=t("is-string-blank"),i=t("gl-buffer"),a=t("gl-vao"),o=t("typedarray-pool"),s=t("gl-mat4/multiply"),l=t("./lib/shaders"),c=t("./lib/glyphs"),u=t("./lib/get-simple-string"),f=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function h(t,e){var r=t[0],n=t[1],i=t[2],a=t[3];return t[0]=e[0]*r+e[4]*n+e[8]*i+e[12]*a,t[1]=e[1]*r+e[5]*n+e[9]*i+e[13]*a,t[2]=e[2]*r+e[6]*n+e[10]*i+e[14]*a,t[3]=e[3]*r+e[7]*n+e[11]*i+e[15]*a,t}function p(t,e,r,n){return h(n,n),h(n,n),h(n,n)}function d(t,e){this.index=t,this.dataCoordinate=this.position=e}function m(t){return!0===t||t>1?1:t}function g(t,e,r,n,i,a,o,s,l,c,u,f){this.gl=t,this.pixelRatio=1,this.shader=e,this.orthoShader=r,this.projectShader=n,this.pointBuffer=i,this.colorBuffer=a,this.glyphBuffer=o,this.idBuffer=s,this.vao=l,this.vertexCount=0,this.lineVertexCount=0,this.opacity=1,this.hasAlpha=!1,this.lineWidth=0,this.projectScale=[2/3,2/3,2/3],this.projectOpacity=[1,1,1],this.projectHasAlpha=!1,this.pickId=0,this.pickPerspectiveShader=c,this.pickOrthoShader=u,this.pickProjectShader=f,this.points=[],this._selectResult=new d(0,[0,0,0]),this.useOrtho=!0,this.bounds=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]],this.axesProject=[!0,!0,!0],this.axesBounds=[[-1/0,-1/0,-1/0],[1/0,1/0,1/0]],this.highlightId=[1,1,1,1],this.highlightScale=2,this.clipBounds=[[-1/0,-1/0,-1/0],[1/0,1/0,1/0]],this.dirty=!0}e.exports=function(t){var e=t.gl,r=l.createPerspective(e),n=l.createOrtho(e),o=l.createProject(e),s=l.createPickPerspective(e),c=l.createPickOrtho(e),u=l.createPickProject(e),f=i(e),h=i(e),p=i(e),d=i(e),m=a(e,[{buffer:f,size:3,type:e.FLOAT},{buffer:h,size:4,type:e.FLOAT},{buffer:p,size:2,type:e.FLOAT},{buffer:d,size:4,type:e.UNSIGNED_BYTE,normalized:!0}]),v=new g(e,r,n,o,f,h,p,d,m,s,c,u);return v.update(t),v};var v=g.prototype;v.pickSlots=1,v.setPickBase=function(t){this.pickId=t},v.isTransparent=function(){if(this.hasAlpha)return!0;for(var t=0;t<3;++t)if(this.axesProject[t]&&this.projectHasAlpha)return!0;return!1},v.isOpaque=function(){if(!this.hasAlpha)return!0;for(var t=0;t<3;++t)if(this.axesProject[t]&&!this.projectHasAlpha)return!0;return!1};var y=[0,0],x=[0,0,0],b=[0,0,0],_=[0,0,0,1],w=[0,0,0,1],T=f.slice(),k=[0,0,0],A=[[0,0,0],[0,0,0]];function M(t){return t[0]=t[1]=t[2]=0,t}function S(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t}function E(t,e,r,n){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[r]=n,t}function L(t,e,r,n){var i,a=e.axesProject,o=e.gl,l=t.uniforms,c=r.model||f,u=r.view||f,h=r.projection||f,d=e.axesBounds,m=function(t){for(var e=A,r=0;r<2;++r)for(var n=0;n<3;++n)e[r][n]=Math.max(Math.min(t[r][n],1e8),-1e8);return e}(e.clipBounds);i=e.axes&&e.axes.lastCubeProps?e.axes.lastCubeProps.axis:[1,1,1],y[0]=2/o.drawingBufferWidth,y[1]=2/o.drawingBufferHeight,t.bind(),l.view=u,l.projection=h,l.screenSize=y,l.highlightId=e.highlightId,l.highlightScale=e.highlightScale,l.clipBounds=m,l.pickGroup=e.pickId/255,l.pixelRatio=n;for(var g=0;g<3;++g)if(a[g]){l.scale=e.projectScale[g],l.opacity=e.projectOpacity[g];for(var v=T,L=0;L<16;++L)v[L]=0;for(L=0;L<4;++L)v[5*L]=1;v[5*g]=0,i[g]<0?v[12+g]=d[0][g]:v[12+g]=d[1][g],s(v,c,v),l.model=v;var C=(g+1)%3,P=(g+2)%3,I=M(x),O=M(b);I[C]=1,O[P]=1;var z=p(0,0,0,S(_,I)),D=p(0,0,0,S(w,O));if(Math.abs(z[1])>Math.abs(D[1])){var R=z;z=D,D=R,R=I,I=O,O=R;var F=C;C=P,P=F}z[0]<0&&(I[C]=-1),D[1]>0&&(O[P]=-1);var B=0,N=0;for(L=0;L<4;++L)B+=Math.pow(c[4*C+L],2),N+=Math.pow(c[4*P+L],2);I[C]/=Math.sqrt(B),O[P]/=Math.sqrt(N),l.axes[0]=I,l.axes[1]=O,l.fragClipBounds[0]=E(k,m[0],g,-1e8),l.fragClipBounds[1]=E(k,m[1],g,1e8),e.vao.bind(),e.vao.draw(o.TRIANGLES,e.vertexCount),e.lineWidth>0&&(o.lineWidth(e.lineWidth*n),e.vao.draw(o.LINES,e.lineVertexCount,e.vertexCount)),e.vao.unbind()}}var C=[[-1e8,-1e8,-1e8],[1e8,1e8,1e8]];function P(t,e,r,n,i,a,o){var s=r.gl;if((a===r.projectHasAlpha||o)&&L(e,r,n,i),a===r.hasAlpha||o){t.bind();var l=t.uniforms;l.model=n.model||f,l.view=n.view||f,l.projection=n.projection||f,y[0]=2/s.drawingBufferWidth,y[1]=2/s.drawingBufferHeight,l.screenSize=y,l.highlightId=r.highlightId,l.highlightScale=r.highlightScale,l.fragClipBounds=C,l.clipBounds=r.axes.bounds,l.opacity=r.opacity,l.pickGroup=r.pickId/255,l.pixelRatio=i,r.vao.bind(),r.vao.draw(s.TRIANGLES,r.vertexCount),r.lineWidth>0&&(s.lineWidth(r.lineWidth*i),r.vao.draw(s.LINES,r.lineVertexCount,r.vertexCount)),r.vao.unbind()}}function I(t,e,r,i){var a;a=Array.isArray(t)?e<t.length?t[e]:void 0:t,a=u(a);var o=!0;n(a)&&(a="\u25bc",o=!1);var s=c(a,r,i);return{mesh:s[0],lines:s[1],bounds:s[2],visible:o}}v.draw=function(t){P(this.useOrtho?this.orthoShader:this.shader,this.projectShader,this,t,this.pixelRatio,!1,!1)},v.drawTransparent=function(t){P(this.useOrtho?this.orthoShader:this.shader,this.projectShader,this,t,this.pixelRatio,!0,!1)},v.drawPick=function(t){P(this.useOrtho?this.pickOrthoShader:this.pickPerspectiveShader,this.pickProjectShader,this,t,1,!0,!0)},v.pick=function(t){if(!t)return null;if(t.id!==this.pickId)return null;var e=t.value[2]+(t.value[1]<<8)+(t.value[0]<<16);if(e>=this.pointCount||e<0)return null;var r=this.points[e],n=this._selectResult;n.index=e;for(var i=0;i<3;++i)n.position[i]=n.dataCoordinate[i]=r[i];return n},v.highlight=function(t){if(t){var e=t.index,r=255&e,n=e>>8&255,i=e>>16&255;this.highlightId=[r/255,n/255,i/255,0]}else this.highlightId=[1,1,1,1]},v.update=function(t){if("perspective"in(t=t||{})&&(this.useOrtho=!t.perspective),"orthographic"in t&&(this.useOrtho=!!t.orthographic),"lineWidth"in t&&(this.lineWidth=t.lineWidth),"project"in t)if(Array.isArray(t.project))this.axesProject=t.project;else{var e=!!t.project;this.axesProject=[e,e,e]}if("projectScale"in t)if(Array.isArray(t.projectScale))this.projectScale=t.projectScale.slice();else{var r=+t.projectScale;this.projectScale=[r,r,r]}if(this.projectHasAlpha=!1,"projectOpacity"in t){if(Array.isArray(t.projectOpacity))this.projectOpacity=t.projectOpacity.slice();else{r=+t.projectOpacity;this.projectOpacity=[r,r,r]}for(var n=0;n<3;++n)this.projectOpacity[n]=m(this.projectOpacity[n]),this.projectOpacity[n]<1&&(this.projectHasAlpha=!0)}this.hasAlpha=!1,"opacity"in t&&(this.opacity=m(t.opacity),this.opacity<1&&(this.hasAlpha=!0)),this.dirty=!0;var i,a,s=t.position,l=t.font||"normal",c=t.alignment||[0,0];if(2===c.length)i=c[0],a=c[1];else{i=[],a=[];for(n=0;n<c.length;++n)i[n]=c[n][0],a[n]=c[n][1]}var u=[1/0,1/0,1/0],f=[-1/0,-1/0,-1/0],h=t.glyph,p=t.color,d=t.size,g=t.angle,v=t.lineColor,y=-1,x=0,b=0,_=0;if(s.length){_=s.length;t:for(n=0;n<_;++n){for(var w=s[n],T=0;T<3;++T)if(isNaN(w[T])||!isFinite(w[T]))continue t;var k=(N=I(h,n,l,this.pixelRatio)).mesh,A=N.lines,M=N.bounds;x+=3*k.cells.length,b+=2*A.edges.length}}var S=x+b,E=o.mallocFloat(3*S),L=o.mallocFloat(4*S),C=o.mallocFloat(2*S),P=o.mallocUint32(S);if(S>0){var O=0,z=x,D=[0,0,0,1],R=[0,0,0,1],F=Array.isArray(p)&&Array.isArray(p[0]),B=Array.isArray(v)&&Array.isArray(v[0]);t:for(n=0;n<_;++n){y+=1;for(w=s[n],T=0;T<3;++T){if(isNaN(w[T])||!isFinite(w[T]))continue t;f[T]=Math.max(f[T],w[T]),u[T]=Math.min(u[T],w[T])}k=(N=I(h,n,l,this.pixelRatio)).mesh,A=N.lines,M=N.bounds;var N,j=N.visible;if(j)if(Array.isArray(p)){if(3===(U=F?n<p.length?p[n]:[0,0,0,0]:p).length){for(T=0;T<3;++T)D[T]=U[T];D[3]=1}else if(4===U.length){for(T=0;T<4;++T)D[T]=U[T];!this.hasAlpha&&U[3]<1&&(this.hasAlpha=!0)}}else D[0]=D[1]=D[2]=0,D[3]=1;else D=[1,1,1,0];if(j)if(Array.isArray(v)){var U;if(3===(U=B?n<v.length?v[n]:[0,0,0,0]:v).length){for(T=0;T<3;++T)R[T]=U[T];R[T]=1}else if(4===U.length){for(T=0;T<4;++T)R[T]=U[T];!this.hasAlpha&&U[3]<1&&(this.hasAlpha=!0)}}else R[0]=R[1]=R[2]=0,R[3]=1;else R=[1,1,1,0];var V=.5;j?Array.isArray(d)?V=n<d.length?+d[n]:12:d?V=+d:this.useOrtho&&(V=12):V=0;var H=0;Array.isArray(g)?H=n<g.length?+g[n]:0:g&&(H=+g);var q=Math.cos(H),G=Math.sin(H);for(w=s[n],T=0;T<3;++T)f[T]=Math.max(f[T],w[T]),u[T]=Math.min(u[T],w[T]);var Y=i,W=a;Y=0;Array.isArray(i)?Y=n<i.length?i[n]:0:i&&(Y=i);W=0;Array.isArray(a)?W=n<a.length?a[n]:0:a&&(W=a);var X=[Y*=Y>0?1-M[0][0]:Y<0?1+M[1][0]:1,W*=W>0?1-M[0][1]:W<0?1+M[1][1]:1],Z=k.cells||[],J=k.positions||[];for(T=0;T<Z.length;++T)for(var K=Z[T],Q=0;Q<3;++Q){for(var $=0;$<3;++$)E[3*O+$]=w[$];for($=0;$<4;++$)L[4*O+$]=D[$];P[O]=y;var tt=J[K[Q]];C[2*O]=V*(q*tt[0]-G*tt[1]+X[0]),C[2*O+1]=V*(G*tt[0]+q*tt[1]+X[1]),O+=1}for(Z=A.edges,J=A.positions,T=0;T<Z.length;++T)for(K=Z[T],Q=0;Q<2;++Q){for($=0;$<3;++$)E[3*z+$]=w[$];for($=0;$<4;++$)L[4*z+$]=R[$];P[z]=y;tt=J[K[Q]];C[2*z]=V*(q*tt[0]-G*tt[1]+X[0]),C[2*z+1]=V*(G*tt[0]+q*tt[1]+X[1]),z+=1}}}this.bounds=[u,f],this.points=s,this.pointCount=s.length,this.vertexCount=x,this.lineVertexCount=b,this.pointBuffer.update(E),this.colorBuffer.update(L),this.glyphBuffer.update(C),this.idBuffer.update(P),o.free(E),o.free(L),o.free(C),o.free(P)},v.dispose=function(){this.shader.dispose(),this.orthoShader.dispose(),this.pickPerspectiveShader.dispose(),this.pickOrthoShader.dispose(),this.vao.dispose(),this.pointBuffer.dispose(),this.colorBuffer.dispose(),this.glyphBuffer.dispose(),this.idBuffer.dispose()}},{"./lib/get-simple-string":125,"./lib/glyphs":126,"./lib/shaders":127,"gl-buffer":78,"gl-mat4/multiply":100,"gl-vao":150,"is-string-blank":239,"typedarray-pool":308}],129:[function(t,e,r){"use strict";var n=t("glslify");r.boxVertex=n(["precision mediump float;\n#define GLSLIFY 1\n\nattribute vec2 vertex;\n\nuniform vec2 cornerA, cornerB;\n\nvoid main() {\n  gl_Position = vec4(mix(cornerA, cornerB, vertex), 0, 1);\n}\n"]),r.boxFragment=n(["precision mediump float;\n#define GLSLIFY 1\n\nuniform vec4 color;\n\nvoid main() {\n  gl_FragColor = color;\n}\n"])},{glslify:231}],130:[function(t,e,r){"use strict";var n=t("gl-shader"),i=t("gl-buffer"),a=t("./lib/shaders");function o(t,e,r){this.plot=t,this.boxBuffer=e,this.boxShader=r,this.enabled=!0,this.selectBox=[1/0,1/0,-1/0,-1/0],this.borderColor=[0,0,0,1],this.innerFill=!1,this.innerColor=[0,0,0,.25],this.outerFill=!0,this.outerColor=[0,0,0,.5],this.borderWidth=10}e.exports=function(t,e){var r=t.gl,s=i(r,[0,0,0,1,1,0,1,1]),l=n(r,a.boxVertex,a.boxFragment),c=new o(t,s,l);return c.update(e),t.addOverlay(c),c};var s=o.prototype;s.draw=function(){if(this.enabled){var t=this.plot,e=this.selectBox,r=this.borderWidth,n=(this.innerFill,this.innerColor),i=(this.outerFill,this.outerColor),a=this.borderColor,o=t.box,s=t.screenBox,l=t.dataBox,c=t.viewBox,u=t.pixelRatio,f=(e[0]-l[0])*(c[2]-c[0])/(l[2]-l[0])+c[0],h=(e[1]-l[1])*(c[3]-c[1])/(l[3]-l[1])+c[1],p=(e[2]-l[0])*(c[2]-c[0])/(l[2]-l[0])+c[0],d=(e[3]-l[1])*(c[3]-c[1])/(l[3]-l[1])+c[1];if(f=Math.max(f,c[0]),h=Math.max(h,c[1]),p=Math.min(p,c[2]),d=Math.min(d,c[3]),!(p<f||d<h)){o.bind();var m=s[2]-s[0],g=s[3]-s[1];if(this.outerFill&&(o.drawBox(0,0,m,h,i),o.drawBox(0,h,f,d,i),o.drawBox(0,d,m,g,i),o.drawBox(p,h,m,d,i)),this.innerFill&&o.drawBox(f,h,p,d,n),r>0){var v=r*u;o.drawBox(f-v,h-v,p+v,h+v,a),o.drawBox(f-v,d-v,p+v,d+v,a),o.drawBox(f-v,h-v,f+v,d+v,a),o.drawBox(p-v,h-v,p+v,d+v,a)}}}},s.update=function(t){t=t||{},this.innerFill=!!t.innerFill,this.outerFill=!!t.outerFill,this.innerColor=(t.innerColor||[0,0,0,.5]).slice(),this.outerColor=(t.outerColor||[0,0,0,.5]).slice(),this.borderColor=(t.borderColor||[0,0,0,1]).slice(),this.borderWidth=t.borderWidth||0,this.selectBox=(t.selectBox||this.selectBox).slice()},s.dispose=function(){this.boxBuffer.dispose(),this.boxShader.dispose(),this.plot.removeOverlay(this)}},{"./lib/shaders":129,"gl-buffer":78,"gl-shader":132}],131:[function(t,e,r){"use strict";e.exports=function(t,e){var r=e[0],a=e[1],o=n(t,r,a,{}),s=i.mallocUint8(r*a*4);return new l(t,o,s)};var n=t("gl-fbo"),i=t("typedarray-pool"),a=t("ndarray"),o=t("bit-twiddle").nextPow2;function s(t,e,r,n,i){this.coord=[t,e],this.id=r,this.value=n,this.distance=i}function l(t,e,r){this.gl=t,this.fbo=e,this.buffer=r,this._readTimeout=null;var n=this;this._readCallback=function(){n.gl&&(e.bind(),t.readPixels(0,0,e.shape[0],e.shape[1],t.RGBA,t.UNSIGNED_BYTE,n.buffer),n._readTimeout=null)}}var c=l.prototype;Object.defineProperty(c,"shape",{get:function(){return this.gl?this.fbo.shape.slice():[0,0]},set:function(t){if(this.gl){this.fbo.shape=t;var e=this.fbo.shape[0],r=this.fbo.shape[1];if(r*e*4>this.buffer.length){i.free(this.buffer);for(var n=this.buffer=i.mallocUint8(o(r*e*4)),a=0;a<r*e*4;++a)n[a]=255}return t}}}),c.begin=function(){var t=this.gl;this.shape;t&&(this.fbo.bind(),t.clearColor(1,1,1,1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT))},c.end=function(){var t=this.gl;t&&(t.bindFramebuffer(t.FRAMEBUFFER,null),this._readTimeout||clearTimeout(this._readTimeout),this._readTimeout=setTimeout(this._readCallback,1))},c.query=function(t,e,r){if(!this.gl)return null;var n=this.fbo.shape.slice();t|=0,e|=0,"number"!=typeof r&&(r=1);var i=0|Math.min(Math.max(t-r,0),n[0]),o=0|Math.min(Math.max(t+r,0),n[0]),l=0|Math.min(Math.max(e-r,0),n[1]),c=0|Math.min(Math.max(e+r,0),n[1]);if(o<=i||c<=l)return null;var u=[o-i,c-l],f=a(this.buffer,[u[0],u[1],4],[4,4*n[0],1],4*(i+n[0]*l)),h=function(t,e,r){for(var n=1e8,i=-1,a=-1,o=t.shape[0],s=t.shape[1],l=0;l<o;l++)for(var c=0;c<s;c++){var u=t.get(l,c,0),f=t.get(l,c,1),h=t.get(l,c,2),p=t.get(l,c,3);if(u<255||f<255||h<255||p<255){var d=e-l,m=r-c,g=d*d+m*m;g<n&&(n=g,i=l,a=c)}}return[i,a,n]}(f.hi(u[0],u[1],1),r,r),p=h[0],d=h[1];return p<0||Math.pow(this.radius,2)<h[2]?null:new s(p+i|0,d+l|0,f.get(p,d,0),[f.get(p,d,1),f.get(p,d,2),f.get(p,d,3)],Math.sqrt(h[2]))},c.dispose=function(){this.gl&&(this.fbo.dispose(),i.free(this.buffer),this.gl=null,this._readTimeout&&clearTimeout(this._readTimeout))}},{"bit-twiddle":32,"gl-fbo":86,ndarray:259,"typedarray-pool":308}],132:[function(t,e,r){"use strict";var n=t("./lib/create-uniforms"),i=t("./lib/create-attributes"),a=t("./lib/reflect"),o=t("./lib/shader-cache"),s=t("./lib/runtime-reflect"),l=t("./lib/GLError");function c(t){this.gl=t,this.gl.lastAttribCount=0,this._vref=this._fref=this._relink=this.vertShader=this.fragShader=this.program=this.attributes=this.uniforms=this.types=null}var u=c.prototype;function f(t,e){return t.name<e.name?-1:1}u.bind=function(){var t;this.program||this._relink();var e=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_ATTRIBUTES),r=this.gl.lastAttribCount;if(e>r)for(t=r;t<e;t++)this.gl.enableVertexAttribArray(t);else if(r>e)for(t=e;t<r;t++)this.gl.disableVertexAttribArray(t);this.gl.lastAttribCount=e,this.gl.useProgram(this.program)},u.dispose=function(){for(var t=this.gl.lastAttribCount,e=0;e<t;e++)this.gl.disableVertexAttribArray(e);this.gl.lastAttribCount=0,this._fref&&this._fref.dispose(),this._vref&&this._vref.dispose(),this.attributes=this.types=this.vertShader=this.fragShader=this.program=this._relink=this._fref=this._vref=null},u.update=function(t,e,r,c){if(!e||1===arguments.length){var u=t;t=u.vertex,e=u.fragment,r=u.uniforms,c=u.attributes}var h=this,p=h.gl,d=h._vref;h._vref=o.shader(p,p.VERTEX_SHADER,t),d&&d.dispose(),h.vertShader=h._vref.shader;var m=this._fref;if(h._fref=o.shader(p,p.FRAGMENT_SHADER,e),m&&m.dispose(),h.fragShader=h._fref.shader,!r||!c){var g=p.createProgram();if(p.attachShader(g,h.fragShader),p.attachShader(g,h.vertShader),p.linkProgram(g),!p.getProgramParameter(g,p.LINK_STATUS)){var v=p.getProgramInfoLog(g);throw new l(v,"Error linking program:"+v)}r=r||s.uniforms(p,g),c=c||s.attributes(p,g),p.deleteProgram(g)}(c=c.slice()).sort(f);var y,x=[],b=[],_=[];for(y=0;y<c.length;++y){var w=c[y];if(w.type.indexOf("mat")>=0){for(var T=0|w.type.charAt(w.type.length-1),k=new Array(T),A=0;A<T;++A)k[A]=_.length,b.push(w.name+"["+A+"]"),"number"==typeof w.location?_.push(w.location+A):Array.isArray(w.location)&&w.location.length===T&&"number"==typeof w.location[A]?_.push(0|w.location[A]):_.push(-1);x.push({name:w.name,type:w.type,locations:k})}else x.push({name:w.name,type:w.type,locations:[_.length]}),b.push(w.name),"number"==typeof w.location?_.push(0|w.location):_.push(-1)}var M=0;for(y=0;y<_.length;++y)if(_[y]<0){for(;_.indexOf(M)>=0;)M+=1;_[y]=M}var S=new Array(r.length);function E(){h.program=o.program(p,h._vref,h._fref,b,_);for(var t=0;t<r.length;++t)S[t]=p.getUniformLocation(h.program,r[t].name)}E(),h._relink=E,h.types={uniforms:a(r),attributes:a(c)},h.attributes=i(p,h,x,_),Object.defineProperty(h,"uniforms",n(p,h,r,S))},e.exports=function(t,e,r,n,i){var a=new c(t);return a.update(e,r,n,i),a}},{"./lib/GLError":133,"./lib/create-attributes":134,"./lib/create-uniforms":135,"./lib/reflect":136,"./lib/runtime-reflect":137,"./lib/shader-cache":138}],133:[function(t,e,r){function n(t,e,r){this.shortMessage=e||"",this.longMessage=r||"",this.rawError=t||"",this.message="gl-shader: "+(e||t||"")+(r?"\n"+r:""),this.stack=(new Error).stack}n.prototype=new Error,n.prototype.name="GLError",n.prototype.constructor=n,e.exports=n},{}],134:[function(t,e,r){"use strict";e.exports=function(t,e,r,i){for(var a={},o=0,c=r.length;o<c;++o){var u=r[o],f=u.name,h=u.type,p=u.locations;switch(h){case"bool":case"int":case"float":s(t,e,p[0],i,1,a,f);break;default:if(h.indexOf("vec")>=0){if((d=h.charCodeAt(h.length-1)-48)<2||d>4)throw new n("","Invalid data type for attribute "+f+": "+h);s(t,e,p[0],i,d,a,f)}else{if(!(h.indexOf("mat")>=0))throw new n("","Unknown data type for attribute "+f+": "+h);var d;if((d=h.charCodeAt(h.length-1)-48)<2||d>4)throw new n("","Invalid data type for attribute "+f+": "+h);l(t,e,p,i,d,a,f)}}}return a};var n=t("./GLError");function i(t,e,r,n,i,a){this._gl=t,this._wrapper=e,this._index=r,this._locations=n,this._dimension=i,this._constFunc=a}var a=i.prototype;a.pointer=function(t,e,r,n){var i=this._gl,a=this._locations[this._index];i.vertexAttribPointer(a,this._dimension,t||i.FLOAT,!!e,r||0,n||0),i.enableVertexAttribArray(a)},a.set=function(t,e,r,n){return this._constFunc(this._locations[this._index],t,e,r,n)},Object.defineProperty(a,"location",{get:function(){return this._locations[this._index]},set:function(t){return t!==this._locations[this._index]&&(this._locations[this._index]=0|t,this._wrapper.program=null),0|t}});var o=[function(t,e,r){return void 0===r.length?t.vertexAttrib1f(e,r):t.vertexAttrib1fv(e,r)},function(t,e,r,n){return void 0===r.length?t.vertexAttrib2f(e,r,n):t.vertexAttrib2fv(e,r)},function(t,e,r,n,i){return void 0===r.length?t.vertexAttrib3f(e,r,n,i):t.vertexAttrib3fv(e,r)},function(t,e,r,n,i,a){return void 0===r.length?t.vertexAttrib4f(e,r,n,i,a):t.vertexAttrib4fv(e,r)}];function s(t,e,r,n,a,s,l){var c=o[a],u=new i(t,e,r,n,a,c);Object.defineProperty(s,l,{set:function(e){return t.disableVertexAttribArray(n[r]),c(t,n[r],e),e},get:function(){return u},enumerable:!0})}function l(t,e,r,n,i,a,o){for(var l=new Array(i),c=new Array(i),u=0;u<i;++u)s(t,e,r[u],n,i,l,u),c[u]=l[u];Object.defineProperty(l,"location",{set:function(t){if(Array.isArray(t))for(var e=0;e<i;++e)c[e].location=t[e];else for(e=0;e<i;++e)c[e].location=t+e;return t},get:function(){for(var t=new Array(i),e=0;e<i;++e)t[e]=n[r[e]];return t},enumerable:!0}),l.pointer=function(e,a,o,s){e=e||t.FLOAT,a=!!a,o=o||i*i,s=s||0;for(var l=0;l<i;++l){var c=n[r[l]];t.vertexAttribPointer(c,i,e,a,o,s+l*i),t.enableVertexAttribArray(c)}};var f=new Array(i),h=t["vertexAttrib"+i+"fv"];Object.defineProperty(a,o,{set:function(e){for(var a=0;a<i;++a){var o=n[r[a]];if(t.disableVertexAttribArray(o),Array.isArray(e[0]))h.call(t,o,e[a]);else{for(var s=0;s<i;++s)f[s]=e[i*a+s];h.call(t,o,f)}}return e},get:function(){return l},enumerable:!0})}},{"./GLError":133}],135:[function(t,e,r){"use strict";var n=t("./reflect"),i=t("./GLError");function a(t){return function(){return t}}function o(t,e){for(var r=new Array(t),n=0;n<t;++n)r[n]=e;return r}e.exports=function(t,e,r,s){function l(e){return function(n){for(var a=function t(e,r){if("object"!=typeof r)return[[e,r]];var n=[];for(var i in r){var a=r[i],o=e;parseInt(i)+""===i?o+="["+i+"]":o+="."+i,"object"==typeof a?n.push.apply(n,t(o,a)):n.push([o,a])}return n}("",e),o=0;o<a.length;++o){var l=a[o],c=l[0],u=l[1];if(s[u]){var f=n;if("string"==typeof c&&(0===c.indexOf(".")||0===c.indexOf("["))){var h=c;if(0===c.indexOf(".")&&(h=c.slice(1)),h.indexOf("]")===h.length-1){var p=h.indexOf("["),d=h.slice(0,p),m=h.slice(p+1,h.length-1);f=d?n[d][m]:n[m]}else f=n[h]}var g,v=r[u].type;switch(v){case"bool":case"int":case"sampler2D":case"samplerCube":t.uniform1i(s[u],f);break;case"float":t.uniform1f(s[u],f);break;default:var y=v.indexOf("vec");if(!(0<=y&&y<=1&&v.length===4+y)){if(0===v.indexOf("mat")&&4===v.length){if((g=v.charCodeAt(v.length-1)-48)<2||g>4)throw new i("","Invalid uniform dimension type for matrix "+name+": "+v);t["uniformMatrix"+g+"fv"](s[u],!1,f);break}throw new i("","Unknown uniform data type for "+name+": "+v)}if((g=v.charCodeAt(v.length-1)-48)<2||g>4)throw new i("","Invalid data type");switch(v.charAt(0)){case"b":case"i":t["uniform"+g+"iv"](s[u],f);break;case"v":t["uniform"+g+"fv"](s[u],f);break;default:throw new i("","Unrecognized data type for vector "+name+": "+v)}}}}}}function c(t,e,n){if("object"==typeof n){var c=u(n);Object.defineProperty(t,e,{get:a(c),set:l(n),enumerable:!0,configurable:!1})}else s[n]?Object.defineProperty(t,e,{get:(f=n,function(t,e,r){return t.getUniform(e.program,r[f])}),set:l(n),enumerable:!0,configurable:!1}):t[e]=function(t){switch(t){case"bool":return!1;case"int":case"sampler2D":case"samplerCube":case"float":return 0;default:var e=t.indexOf("vec");if(0<=e&&e<=1&&t.length===4+e){if((r=t.charCodeAt(t.length-1)-48)<2||r>4)throw new i("","Invalid data type");return"b"===t.charAt(0)?o(r,!1):o(r,0)}if(0===t.indexOf("mat")&&4===t.length){var r;if((r=t.charCodeAt(t.length-1)-48)<2||r>4)throw new i("","Invalid uniform dimension type for matrix "+name+": "+t);return o(r*r,0)}throw new i("","Unknown uniform data type for "+name+": "+t)}}(r[n].type);var f}function u(t){var e;if(Array.isArray(t)){e=new Array(t.length);for(var r=0;r<t.length;++r)c(e,r,t[r])}else for(var n in e={},t)c(e,n,t[n]);return e}var f=n(r,!0);return{get:a(u(f)),set:l(f),enumerable:!0,configurable:!0}}},{"./GLError":133,"./reflect":136}],136:[function(t,e,r){"use strict";e.exports=function(t,e){for(var r={},n=0;n<t.length;++n)for(var i=t[n].name.split("."),a=r,o=0;o<i.length;++o){var s=i[o].split("[");if(s.length>1){s[0]in a||(a[s[0]]=[]),a=a[s[0]];for(var l=1;l<s.length;++l){var c=parseInt(s[l]);l<s.length-1||o<i.length-1?(c in a||(l<s.length-1?a[c]=[]:a[c]={}),a=a[c]):a[c]=e?n:t[n].type}}else o<i.length-1?(s[0]in a||(a[s[0]]={}),a=a[s[0]]):a[s[0]]=e?n:t[n].type}return r}},{}],137:[function(t,e,r){"use strict";r.uniforms=function(t,e){for(var r=t.getProgramParameter(e,t.ACTIVE_UNIFORMS),n=[],i=0;i<r;++i){var o=t.getActiveUniform(e,i);if(o){var s=a(t,o.type);if(o.size>1)for(var l=0;l<o.size;++l)n.push({name:o.name.replace("[0]","["+l+"]"),type:s});else n.push({name:o.name,type:s})}}return n},r.attributes=function(t,e){for(var r=t.getProgramParameter(e,t.ACTIVE_ATTRIBUTES),n=[],i=0;i<r;++i){var o=t.getActiveAttrib(e,i);o&&n.push({name:o.name,type:a(t,o.type)})}return n};var n={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",SAMPLER_CUBE:"samplerCube"},i=null;function a(t,e){if(!i){var r=Object.keys(n);i={};for(var a=0;a<r.length;++a){var o=r[a];i[t[o]]=n[o]}}return i[e]}},{}],138:[function(t,e,r){"use strict";r.shader=function(t,e,r){return u(t).getShaderReference(e,r)},r.program=function(t,e,r,n,i){return u(t).getProgram(e,r,n,i)};var n=t("./GLError"),i=t("gl-format-compiler-error"),a=new("undefined"==typeof WeakMap?t("weakmap-shim"):WeakMap),o=0;function s(t,e,r,n,i,a,o){this.id=t,this.src=e,this.type=r,this.shader=n,this.count=a,this.programs=[],this.cache=o}function l(t){this.gl=t,this.shaders=[{},{}],this.programs={}}s.prototype.dispose=function(){if(0==--this.count){for(var t=this.cache,e=t.gl,r=this.programs,n=0,i=r.length;n<i;++n){var a=t.programs[r[n]];a&&(delete t.programs[n],e.deleteProgram(a))}e.deleteShader(this.shader),delete t.shaders[this.type===e.FRAGMENT_SHADER|0][this.src]}};var c=l.prototype;function u(t){var e=a.get(t);return e||(e=new l(t),a.set(t,e)),e}c.getShaderReference=function(t,e){var r=this.gl,a=this.shaders[t===r.FRAGMENT_SHADER|0],l=a[e];if(l&&r.isShader(l.shader))l.count+=1;else{var c=function(t,e,r){var a=t.createShader(e);if(t.shaderSource(a,r),t.compileShader(a),!t.getShaderParameter(a,t.COMPILE_STATUS)){var o=t.getShaderInfoLog(a);try{var s=i(o,r,e)}catch(t){throw console.warn("Failed to format compiler error: "+t),new n(o,"Error compiling shader:\n"+o)}throw new n(o,s.short,s.long)}return a}(r,t,e);l=a[e]=new s(o++,e,t,c,[],1,this)}return l},c.getProgram=function(t,e,r,i){var a=[t.id,e.id,r.join(":"),i.join(":")].join("@"),o=this.programs[a];return o&&this.gl.isProgram(o)||(this.programs[a]=o=function(t,e,r,i,a){var o=t.createProgram();t.attachShader(o,e),t.attachShader(o,r);for(var s=0;s<i.length;++s)t.bindAttribLocation(o,a[s],i[s]);if(t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS)){var l=t.getProgramInfoLog(o);throw new n(l,"Error linking program: "+l)}return o}(this.gl,t.shader,e.shader,r,i),t.programs.push(a),e.programs.push(a)),o}},{"./GLError":133,"gl-format-compiler-error":87,"weakmap-shim":316}],139:[function(t,e,r){"use strict";function n(t){this.plot=t,this.enable=[!0,!0,!1,!1],this.width=[1,1,1,1],this.color=[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.center=[1/0,1/0]}e.exports=function(t,e){var r=new n(t);return r.update(e),t.addOverlay(r),r};var i=n.prototype;i.update=function(t){t=t||{},this.enable=(t.enable||[!0,!0,!1,!1]).slice(),this.width=(t.width||[1,1,1,1]).slice(),this.color=(t.color||[[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]]).map((function(t){return t.slice()})),this.center=(t.center||[1/0,1/0]).slice(),this.plot.setOverlayDirty()},i.draw=function(){var t=this.enable,e=this.width,r=this.color,n=this.center,i=this.plot,a=i.line,o=i.dataBox,s=i.viewBox;if(a.bind(),o[0]<=n[0]&&n[0]<=o[2]&&o[1]<=n[1]&&n[1]<=o[3]){var l=s[0]+(n[0]-o[0])/(o[2]-o[0])*(s[2]-s[0]),c=s[1]+(n[1]-o[1])/(o[3]-o[1])*(s[3]-s[1]);t[0]&&a.drawLine(l,c,s[0],c,e[0],r[0]),t[1]&&a.drawLine(l,c,l,s[1],e[1],r[1]),t[2]&&a.drawLine(l,c,s[2],c,e[2],r[2]),t[3]&&a.drawLine(l,c,l,s[3],e[3],r[3])}},i.dispose=function(){this.plot.removeOverlay(this)}},{}],140:[function(t,e,r){"use strict";var n=t("glslify"),i=t("gl-shader"),a=n(["precision mediump float;\n#define GLSLIFY 1\n\nattribute vec3 position, color;\nattribute float weight;\n\nuniform mat4 model, view, projection;\nuniform vec3 coordinates[3];\nuniform vec4 colors[3];\nuniform vec2 screenShape;\nuniform float lineWidth;\n\nvarying vec4 fragColor;\n\nvoid main() {\n  vec3 vertexPosition = mix(coordinates[0],\n    mix(coordinates[2], coordinates[1], 0.5 * (position + 1.0)), abs(position));\n\n  vec4 clipPos = projection * view * model * vec4(vertexPosition, 1.0);\n  vec2 clipOffset = (projection * view * model * vec4(color, 0.0)).xy;\n  vec2 delta = weight * clipOffset * screenShape;\n  vec2 lineOffset = normalize(vec2(delta.y, -delta.x)) / screenShape;\n\n  gl_Position   = vec4(clipPos.xy + clipPos.w * 0.5 * lineWidth * lineOffset, clipPos.z, clipPos.w);\n  fragColor     = color.x * colors[0] + color.y * colors[1] + color.z * colors[2];\n}\n"]),o=n(["precision mediump float;\n#define GLSLIFY 1\n\nvarying vec4 fragColor;\n\nvoid main() {\n  gl_FragColor = fragColor;\n}"]);e.exports=function(t){return i(t,a,o,null,[{name:"position",type:"vec3"},{name:"color",type:"vec3"},{name:"weight",type:"float"}])}},{"gl-shader":132,glslify:231}],141:[function(t,e,r){"use strict";var n=t("gl-buffer"),i=t("gl-vao"),a=t("./shaders/index");e.exports=function(t,e){var r=[];function o(t,e,n,i,a,o){var s=[t,e,n,0,0,0,1];s[i+3]=1,s[i]=a,r.push.apply(r,s),s[6]=-1,r.push.apply(r,s),s[i]=o,r.push.apply(r,s),r.push.apply(r,s),s[6]=1,r.push.apply(r,s),s[i]=a,r.push.apply(r,s)}o(0,0,0,0,0,1),o(0,0,0,1,0,1),o(0,0,0,2,0,1),o(1,0,0,1,-1,1),o(1,0,0,2,-1,1),o(0,1,0,0,-1,1),o(0,1,0,2,-1,1),o(0,0,1,0,-1,1),o(0,0,1,1,-1,1);var l=n(t,r),c=i(t,[{type:t.FLOAT,buffer:l,size:3,offset:0,stride:28},{type:t.FLOAT,buffer:l,size:3,offset:12,stride:28},{type:t.FLOAT,buffer:l,size:1,offset:24,stride:28}]),u=a(t);u.attributes.position.location=0,u.attributes.color.location=1,u.attributes.weight.location=2;var f=new s(t,l,c,u);return f.update(e),f};var o=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function s(t,e,r,n){this.gl=t,this.buffer=e,this.vao=r,this.shader=n,this.pixelRatio=1,this.bounds=[[-1e3,-1e3,-1e3],[1e3,1e3,1e3]],this.position=[0,0,0],this.lineWidth=[2,2,2],this.colors=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.enabled=[!0,!0,!0],this.drawSides=[!0,!0,!0],this.axes=null}var l=s.prototype,c=[0,0,0],u=[0,0,0],f=[0,0];l.isTransparent=function(){return!1},l.drawTransparent=function(t){},l.draw=function(t){var e=this.gl,r=this.vao,n=this.shader;r.bind(),n.bind();var i,a=t.model||o,s=t.view||o,l=t.projection||o;this.axes&&(i=this.axes.lastCubeProps.axis);for(var h=c,p=u,d=0;d<3;++d)i&&i[d]<0?(h[d]=this.bounds[0][d],p[d]=this.bounds[1][d]):(h[d]=this.bounds[1][d],p[d]=this.bounds[0][d]);f[0]=e.drawingBufferWidth,f[1]=e.drawingBufferHeight,n.uniforms.model=a,n.uniforms.view=s,n.uniforms.projection=l,n.uniforms.coordinates=[this.position,h,p],n.uniforms.colors=this.colors,n.uniforms.screenShape=f;for(d=0;d<3;++d)n.uniforms.lineWidth=this.lineWidth[d]*this.pixelRatio,this.enabled[d]&&(r.draw(e.TRIANGLES,6,6*d),this.drawSides[d]&&r.draw(e.TRIANGLES,12,18+12*d));r.unbind()},l.update=function(t){t&&("bounds"in t&&(this.bounds=t.bounds),"position"in t&&(this.position=t.position),"lineWidth"in t&&(this.lineWidth=t.lineWidth),"colors"in t&&(this.colors=t.colors),"enabled"in t&&(this.enabled=t.enabled),"drawSides"in t&&(this.drawSides=t.drawSides))},l.dispose=function(){this.vao.dispose(),this.buffer.dispose(),this.shader.dispose()}},{"./shaders/index":140,"gl-buffer":78,"gl-vao":150}],142:[function(t,e,r){var n=t("glslify"),i=n(["precision highp float;\n\nprecision highp float;\n#define GLSLIFY 1\n\nvec3 getOrthogonalVector(vec3 v) {\n  // Return up-vector for only-z vector.\n  // Return ax + by + cz = 0, a point that lies on the plane that has v as a normal and that isn't (0,0,0).\n  // From the above if-statement we have ||a|| > 0  U  ||b|| > 0.\n  // Assign z = 0, x = -b, y = a:\n  // a*-b + b*a + c*0 = -ba + ba + 0 = 0\n  if (v.x*v.x > v.z*v.z || v.y*v.y > v.z*v.z) {\n    return normalize(vec3(-v.y, v.x, 0.0));\n  } else {\n    return normalize(vec3(0.0, v.z, -v.y));\n  }\n}\n\n// Calculate the tube vertex and normal at the given index.\n//\n// The returned vertex is for a tube ring with its center at origin, radius of length(d), pointing in the direction of d.\n//\n// Each tube segment is made up of a ring of vertices.\n// These vertices are used to make up the triangles of the tube by connecting them together in the vertex array.\n// The indexes of tube segments run from 0 to 8.\n//\nvec3 getTubePosition(vec3 d, float index, out vec3 normal) {\n  float segmentCount = 8.0;\n\n  float angle = 2.0 * 3.14159 * (index / segmentCount);\n\n  vec3 u = getOrthogonalVector(d);\n  vec3 v = normalize(cross(u, d));\n\n  vec3 x = u * cos(angle) * length(d);\n  vec3 y = v * sin(angle) * length(d);\n  vec3 v3 = x + y;\n\n  normal = normalize(v3);\n\n  return v3;\n}\n\nattribute vec4 vector;\nattribute vec4 color, position;\nattribute vec2 uv;\n\nuniform float vectorScale, tubeScale;\nuniform mat4 model, view, projection, inverseModel;\nuniform vec3 eyePosition, lightPosition;\n\nvarying vec3 f_normal, f_lightDirection, f_eyeDirection, f_data, f_position;\nvarying vec4 f_color;\nvarying vec2 f_uv;\n\nvoid main() {\n  // Scale the vector magnitude to stay constant with\n  // model & view changes.\n  vec3 normal;\n  vec3 XYZ = getTubePosition(mat3(model) * (tubeScale * vector.w * normalize(vector.xyz)), position.w, normal);\n  vec4 tubePosition = model * vec4(position.xyz, 1.0) + vec4(XYZ, 0.0);\n\n  //Lighting geometry parameters\n  vec4 cameraCoordinate = view * tubePosition;\n  cameraCoordinate.xyz /= cameraCoordinate.w;\n  f_lightDirection = lightPosition - cameraCoordinate.xyz;\n  f_eyeDirection   = eyePosition - cameraCoordinate.xyz;\n  f_normal = normalize((vec4(normal, 0.0) * inverseModel).xyz);\n\n  // vec4 m_position  = model * vec4(tubePosition, 1.0);\n  vec4 t_position  = view * tubePosition;\n  gl_Position      = projection * t_position;\n\n  f_color          = color;\n  f_data           = tubePosition.xyz;\n  f_position       = position.xyz;\n  f_uv             = uv;\n}\n"]),a=n(["#extension GL_OES_standard_derivatives : enable\n\nprecision highp float;\n#define GLSLIFY 1\n\nfloat beckmannDistribution(float x, float roughness) {\n  float NdotH = max(x, 0.0001);\n  float cos2Alpha = NdotH * NdotH;\n  float tan2Alpha = (cos2Alpha - 1.0) / cos2Alpha;\n  float roughness2 = roughness * roughness;\n  float denom = 3.141592653589793 * roughness2 * cos2Alpha * cos2Alpha;\n  return exp(tan2Alpha / roughness2) / denom;\n}\n\nfloat cookTorranceSpecular(\n  vec3 lightDirection,\n  vec3 viewDirection,\n  vec3 surfaceNormal,\n  float roughness,\n  float fresnel) {\n\n  float VdotN = max(dot(viewDirection, surfaceNormal), 0.0);\n  float LdotN = max(dot(lightDirection, surfaceNormal), 0.0);\n\n  //Half angle vector\n  vec3 H = normalize(lightDirection + viewDirection);\n\n  //Geometric term\n  float NdotH = max(dot(surfaceNormal, H), 0.0);\n  float VdotH = max(dot(viewDirection, H), 0.000001);\n  float LdotH = max(dot(lightDirection, H), 0.000001);\n  float G1 = (2.0 * NdotH * VdotN) / VdotH;\n  float G2 = (2.0 * NdotH * LdotN) / LdotH;\n  float G = min(1.0, min(G1, G2));\n  \n  //Distribution term\n  float D = beckmannDistribution(NdotH, roughness);\n\n  //Fresnel term\n  float F = pow(1.0 - VdotN, fresnel);\n\n  //Multiply terms and done\n  return  G * F * D / max(3.14159265 * VdotN, 0.000001);\n}\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec3 clipBounds[2];\nuniform float roughness, fresnel, kambient, kdiffuse, kspecular, opacity;\nuniform sampler2D texture;\n\nvarying vec3 f_normal, f_lightDirection, f_eyeDirection, f_data, f_position;\nvarying vec4 f_color;\nvarying vec2 f_uv;\n\nvoid main() {\n  if (outOfRange(clipBounds[0], clipBounds[1], f_position)) discard;\n  vec3 N = normalize(f_normal);\n  vec3 L = normalize(f_lightDirection);\n  vec3 V = normalize(f_eyeDirection);\n\n  if(gl_FrontFacing) {\n    N = -N;\n  }\n\n  float specular = min(1.0, max(0.0, cookTorranceSpecular(L, V, N, roughness, fresnel)));\n  float diffuse  = min(kambient + kdiffuse * max(dot(N, L), 0.0), 1.0);\n\n  vec4 surfaceColor = f_color * texture2D(texture, f_uv);\n  vec4 litColor = surfaceColor.a * vec4(diffuse * surfaceColor.rgb + kspecular * vec3(1,1,1) * specular,  1.0);\n\n  gl_FragColor = litColor * opacity;\n}\n"]),o=n(["precision highp float;\n\nprecision highp float;\n#define GLSLIFY 1\n\nvec3 getOrthogonalVector(vec3 v) {\n  // Return up-vector for only-z vector.\n  // Return ax + by + cz = 0, a point that lies on the plane that has v as a normal and that isn't (0,0,0).\n  // From the above if-statement we have ||a|| > 0  U  ||b|| > 0.\n  // Assign z = 0, x = -b, y = a:\n  // a*-b + b*a + c*0 = -ba + ba + 0 = 0\n  if (v.x*v.x > v.z*v.z || v.y*v.y > v.z*v.z) {\n    return normalize(vec3(-v.y, v.x, 0.0));\n  } else {\n    return normalize(vec3(0.0, v.z, -v.y));\n  }\n}\n\n// Calculate the tube vertex and normal at the given index.\n//\n// The returned vertex is for a tube ring with its center at origin, radius of length(d), pointing in the direction of d.\n//\n// Each tube segment is made up of a ring of vertices.\n// These vertices are used to make up the triangles of the tube by connecting them together in the vertex array.\n// The indexes of tube segments run from 0 to 8.\n//\nvec3 getTubePosition(vec3 d, float index, out vec3 normal) {\n  float segmentCount = 8.0;\n\n  float angle = 2.0 * 3.14159 * (index / segmentCount);\n\n  vec3 u = getOrthogonalVector(d);\n  vec3 v = normalize(cross(u, d));\n\n  vec3 x = u * cos(angle) * length(d);\n  vec3 y = v * sin(angle) * length(d);\n  vec3 v3 = x + y;\n\n  normal = normalize(v3);\n\n  return v3;\n}\n\nattribute vec4 vector;\nattribute vec4 position;\nattribute vec4 id;\n\nuniform mat4 model, view, projection;\nuniform float tubeScale;\n\nvarying vec3 f_position;\nvarying vec4 f_id;\n\nvoid main() {\n  vec3 normal;\n  vec3 XYZ = getTubePosition(mat3(model) * (tubeScale * vector.w * normalize(vector.xyz)), position.w, normal);\n  vec4 tubePosition = model * vec4(position.xyz, 1.0) + vec4(XYZ, 0.0);\n\n  gl_Position = projection * view * tubePosition;\n  f_id        = id;\n  f_position  = position.xyz;\n}\n"]),s=n(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec3  clipBounds[2];\nuniform float pickId;\n\nvarying vec3 f_position;\nvarying vec4 f_id;\n\nvoid main() {\n  if (outOfRange(clipBounds[0], clipBounds[1], f_position)) discard;\n\n  gl_FragColor = vec4(pickId, f_id.xyz);\n}"]);r.meshShader={vertex:i,fragment:a,attributes:[{name:"position",type:"vec4"},{name:"color",type:"vec4"},{name:"uv",type:"vec2"},{name:"vector",type:"vec4"}]},r.pickShader={vertex:o,fragment:s,attributes:[{name:"position",type:"vec4"},{name:"id",type:"vec4"},{name:"vector",type:"vec4"}]}},{glslify:231}],143:[function(t,e,r){"use strict";var n=t("gl-vec3"),i=t("gl-vec4"),a=["xyz","xzy","yxz","yzx","zxy","zyx"],o=function(t,e,r,a){for(var o=0,s=0;s<t.length;s++)for(var l=t[s].velocities,c=0;c<l.length;c++)o=Math.max(o,n.length(l[c]));var u=t.map((function(t){return function(t,e,r,a){for(var o=t.points,s=t.velocities,l=t.divergences,c=[],u=[],f=[],h=[],p=[],d=[],m=0,g=0,v=i.create(),y=i.create(),x=0;x<o.length;x++){var b=o[x],_=s[x],w=l[x];0===e&&(w=.05*r),g=n.length(_)/a,v=i.create(),n.copy(v,_),v[3]=w;for(var T=0;T<8;T++)p[T]=[b[0],b[1],b[2],T];if(h.length>0)for(T=0;T<8;T++){var k=(T+1)%8;c.push(h[T],p[T],p[k],p[k],h[k],h[T]),f.push(y,v,v,v,y,y),d.push(m,g,g,g,m,m);var A=c.length;u.push([A-6,A-5,A-4],[A-3,A-2,A-1])}var M=h;h=p,p=M;var S=y;y=v,v=S;var E=m;m=g,g=E}return{positions:c,cells:u,vectors:f,vertexIntensity:d}}(t,r,a,o)})),f=[],h=[],p=[],d=[];for(s=0;s<u.length;s++){var m=u[s],g=f.length;f=f.concat(m.positions),p=p.concat(m.vectors),d=d.concat(m.vertexIntensity);for(c=0;c<m.cells.length;c++){var v=m.cells[c],y=[];h.push(y);for(var x=0;x<v.length;x++)y.push(v[x]+g)}}return{positions:f,cells:h,vectors:p,vertexIntensity:d,colormap:e}},s=function(t,e){var r,n=t.length;for(r=0;r<n;r++){var i=t[r];if(i===e)return r;if(i>e)return r-1}return r},l=function(t,e,r){return t<e?e:t>r?r:t},c=function(t){var e=1/0;t.sort((function(t,e){return t-e}));for(var r=t.length,n=1;n<r;n++){var i=Math.abs(t[n]-t[n-1]);i<e&&(e=i)}return e};e.exports=function(t,e){var r=t.startingPositions,i=t.maxLength||1e3,u=t.tubeSize||1,f=t.absoluteTubeSize,h=t.gridFill||"+x+y+z",p={};-1!==h.indexOf("-x")&&(p.reversedX=!0),-1!==h.indexOf("-y")&&(p.reversedY=!0),-1!==h.indexOf("-z")&&(p.reversedZ=!0),p.filled=a.indexOf(h.replace(/-/g,"").replace(/\+/g,""));var d=t.getVelocity||function(e){return function(t,e,r){var i=e.vectors,a=e.meshgrid,o=t[0],c=t[1],u=t[2],f=a[0].length,h=a[1].length,p=a[2].length,d=s(a[0],o),m=s(a[1],c),g=s(a[2],u),v=d+1,y=m+1,x=g+1;if(d=l(d,0,f-1),v=l(v,0,f-1),m=l(m,0,h-1),y=l(y,0,h-1),g=l(g,0,p-1),x=l(x,0,p-1),d<0||m<0||g<0||v>f-1||y>h-1||x>p-1)return n.create();var b,_,w,T,k,A,M=a[0][d],S=a[0][v],E=a[1][m],L=a[1][y],C=a[2][g],P=(o-M)/(S-M),I=(c-E)/(L-E),O=(u-C)/(a[2][x]-C);switch(isFinite(P)||(P=.5),isFinite(I)||(I=.5),isFinite(O)||(O=.5),r.reversedX&&(d=f-1-d,v=f-1-v),r.reversedY&&(m=h-1-m,y=h-1-y),r.reversedZ&&(g=p-1-g,x=p-1-x),r.filled){case 5:k=g,A=x,w=m*p,T=y*p,b=d*p*h,_=v*p*h;break;case 4:k=g,A=x,b=d*p,_=v*p,w=m*p*f,T=y*p*f;break;case 3:w=m,T=y,k=g*h,A=x*h,b=d*h*p,_=v*h*p;break;case 2:w=m,T=y,b=d*h,_=v*h,k=g*h*f,A=x*h*f;break;case 1:b=d,_=v,k=g*f,A=x*f,w=m*f*p,T=y*f*p;break;default:b=d,_=v,w=m*f,T=y*f,k=g*f*h,A=x*f*h}var z=i[b+w+k],D=i[b+w+A],R=i[b+T+k],F=i[b+T+A],B=i[_+w+k],N=i[_+w+A],j=i[_+T+k],U=i[_+T+A],V=n.create(),H=n.create(),q=n.create(),G=n.create();n.lerp(V,z,B,P),n.lerp(H,D,N,P),n.lerp(q,R,j,P),n.lerp(G,F,U,P);var Y=n.create(),W=n.create();n.lerp(Y,V,q,I),n.lerp(W,H,G,I);var X=n.create();return n.lerp(X,Y,W,O),X}(e,t,p)},m=t.getDivergence||function(t,e){var r=n.create(),i=1e-4;n.add(r,t,[i,0,0]);var a=d(r);n.subtract(a,a,e),n.scale(a,a,1/i),n.add(r,t,[0,i,0]);var o=d(r);n.subtract(o,o,e),n.scale(o,o,1/i),n.add(r,t,[0,0,i]);var s=d(r);return n.subtract(s,s,e),n.scale(s,s,1/i),n.add(r,a,o),n.add(r,r,s),r},g=[],v=e[0][0],y=e[0][1],x=e[0][2],b=e[1][0],_=e[1][1],w=e[1][2],T=function(t){var e=t[0],r=t[1],n=t[2];return!(e<v||e>b||r<y||r>_||n<x||n>w)},k=10*n.distance(e[0],e[1])/i,A=k*k,M=1,S=0,E=r.length;E>1&&(M=function(t){for(var e=[],r=[],n=[],i={},a={},o={},s=t.length,l=0;l<s;l++){var u=t[l],f=u[0],h=u[1],p=u[2];i[f]||(e.push(f),i[f]=!0),a[h]||(r.push(h),a[h]=!0),o[p]||(n.push(p),o[p]=!0)}var d=c(e),m=c(r),g=c(n),v=Math.min(d,m,g);return isFinite(v)?v:1}(r));for(var L=0;L<E;L++){var C=n.create();n.copy(C,r[L]);var P=[C],I=[],O=d(C),z=C;I.push(O);var D=[],R=m(C,O),F=n.length(R);isFinite(F)&&F>S&&(S=F),D.push(F),g.push({points:P,velocities:I,divergences:D});for(var B=0;B<100*i&&P.length<i&&T(C);){B++;var N=n.clone(O),j=n.squaredLength(N);if(0===j)break;if(j>A&&n.scale(N,N,k/Math.sqrt(j)),n.add(N,N,C),O=d(N),n.squaredDistance(z,N)-A>-1e-4*A){P.push(N),z=N,I.push(O);R=m(N,O),F=n.length(R);isFinite(F)&&F>S&&(S=F),D.push(F)}C=N}}var U=o(g,t.colormap,S,M);return f?U.tubeScale=f:(0===S&&(S=1),U.tubeScale=.5*u*M/S),U};var u=t("./lib/shaders"),f=t("gl-cone3d").createMesh;e.exports.createTubeMesh=function(t,e){return f(t,e,{shaders:u,traceType:"streamtube"})}},{"./lib/shaders":142,"gl-cone3d":79,"gl-vec3":169,"gl-vec4":205}],144:[function(t,e,r){var n=t("gl-shader"),i=t("glslify"),a=i(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec4 uv;\nattribute vec3 f;\nattribute vec3 normal;\n\nuniform vec3 objectOffset;\nuniform mat4 model, view, projection, inverseModel;\nuniform vec3 lightPosition, eyePosition;\nuniform sampler2D colormap;\n\nvarying float value, kill;\nvarying vec3 worldCoordinate;\nvarying vec2 planeCoordinate;\nvarying vec3 lightDirection, eyeDirection, surfaceNormal;\nvarying vec4 vColor;\n\nvoid main() {\n  vec3 localCoordinate = vec3(uv.zw, f.x);\n  worldCoordinate = objectOffset + localCoordinate;\n  vec4 worldPosition = model * vec4(worldCoordinate, 1.0);\n  vec4 clipPosition = projection * view * worldPosition;\n  gl_Position = clipPosition;\n  kill = f.y;\n  value = f.z;\n  planeCoordinate = uv.xy;\n\n  vColor = texture2D(colormap, vec2(value, value));\n\n  //Lighting geometry parameters\n  vec4 cameraCoordinate = view * worldPosition;\n  cameraCoordinate.xyz /= cameraCoordinate.w;\n  lightDirection = lightPosition - cameraCoordinate.xyz;\n  eyeDirection   = eyePosition - cameraCoordinate.xyz;\n  surfaceNormal  = normalize((vec4(normal,0) * inverseModel).xyz);\n}\n"]),o=i(["precision highp float;\n#define GLSLIFY 1\n\nfloat beckmannDistribution(float x, float roughness) {\n  float NdotH = max(x, 0.0001);\n  float cos2Alpha = NdotH * NdotH;\n  float tan2Alpha = (cos2Alpha - 1.0) / cos2Alpha;\n  float roughness2 = roughness * roughness;\n  float denom = 3.141592653589793 * roughness2 * cos2Alpha * cos2Alpha;\n  return exp(tan2Alpha / roughness2) / denom;\n}\n\nfloat beckmannSpecular(\n  vec3 lightDirection,\n  vec3 viewDirection,\n  vec3 surfaceNormal,\n  float roughness) {\n  return beckmannDistribution(dot(surfaceNormal, normalize(lightDirection + viewDirection)), roughness);\n}\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec3 lowerBound, upperBound;\nuniform float contourTint;\nuniform vec4 contourColor;\nuniform sampler2D colormap;\nuniform vec3 clipBounds[2];\nuniform float roughness, fresnel, kambient, kdiffuse, kspecular, opacity;\nuniform float vertexColor;\n\nvarying float value, kill;\nvarying vec3 worldCoordinate;\nvarying vec3 lightDirection, eyeDirection, surfaceNormal;\nvarying vec4 vColor;\n\nvoid main() {\n  if (\n    kill > 0.0 ||\n    vColor.a == 0.0 ||\n    outOfRange(clipBounds[0], clipBounds[1], worldCoordinate)\n  ) discard;\n\n  vec3 N = normalize(surfaceNormal);\n  vec3 V = normalize(eyeDirection);\n  vec3 L = normalize(lightDirection);\n\n  if(gl_FrontFacing) {\n    N = -N;\n  }\n\n  float specular = max(beckmannSpecular(L, V, N, roughness), 0.);\n  float diffuse  = min(kambient + kdiffuse * max(dot(N, L), 0.0), 1.0);\n\n  //decide how to interpolate color \u2014 in vertex or in fragment\n  vec4 surfaceColor =\n    step(vertexColor, .5) * texture2D(colormap, vec2(value, value)) +\n    step(.5, vertexColor) * vColor;\n\n  vec4 litColor = surfaceColor.a * vec4(diffuse * surfaceColor.rgb + kspecular * vec3(1,1,1) * specular,  1.0);\n\n  gl_FragColor = mix(litColor, contourColor, contourTint) * opacity;\n}\n"]),s=i(["precision highp float;\n#define GLSLIFY 1\n\nattribute vec4 uv;\nattribute float f;\n\nuniform vec3 objectOffset;\nuniform mat3 permutation;\nuniform mat4 model, view, projection;\nuniform float height, zOffset;\nuniform sampler2D colormap;\n\nvarying float value, kill;\nvarying vec3 worldCoordinate;\nvarying vec2 planeCoordinate;\nvarying vec3 lightDirection, eyeDirection, surfaceNormal;\nvarying vec4 vColor;\n\nvoid main() {\n  vec3 dataCoordinate = permutation * vec3(uv.xy, height);\n  worldCoordinate = objectOffset + dataCoordinate;\n  vec4 worldPosition = model * vec4(worldCoordinate, 1.0);\n\n  vec4 clipPosition = projection * view * worldPosition;\n  clipPosition.z += zOffset;\n\n  gl_Position = clipPosition;\n  value = f + objectOffset.z;\n  kill = -1.0;\n  planeCoordinate = uv.zw;\n\n  vColor = texture2D(colormap, vec2(value, value));\n\n  //Don't do lighting for contours\n  surfaceNormal   = vec3(1,0,0);\n  eyeDirection    = vec3(0,1,0);\n  lightDirection  = vec3(0,0,1);\n}\n"]),l=i(["precision highp float;\n#define GLSLIFY 1\n\nbool outOfRange(float a, float b, float p) {\n  return ((p > max(a, b)) || \n          (p < min(a, b)));\n}\n\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y));\n}\n\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\n  return (outOfRange(a.x, b.x, p.x) ||\n          outOfRange(a.y, b.y, p.y) ||\n          outOfRange(a.z, b.z, p.z));\n}\n\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\n  return outOfRange(a.xyz, b.xyz, p.xyz);\n}\n\nuniform vec2 shape;\nuniform vec3 clipBounds[2];\nuniform float pickId;\n\nvarying float value, kill;\nvarying vec3 worldCoordinate;\nvarying vec2 planeCoordinate;\nvarying vec3 surfaceNormal;\n\nvec2 splitFloat(float v) {\n  float vh = 255.0 * v;\n  float upper = floor(vh);\n  float lower = fract(vh);\n  return vec2(upper / 255.0, floor(lower * 16.0) / 16.0);\n}\n\nvoid main() {\n  if ((kill > 0.0) ||\n      (outOfRange(clipBounds[0], clipBounds[1], worldCoordinate))) discard;\n\n  vec2 ux = splitFloat(planeCoordinate.x / shape.x);\n  vec2 uy = splitFloat(planeCoordinate.y / shape.y);\n  gl_FragColor = vec4(pickId, ux.x, uy.x, ux.y + (uy.y/16.0));\n}\n"]);r.createShader=function(t){var e=n(t,a,o,null,[{name:"uv",type:"vec4"},{name:"f",type:"vec3"},{name:"normal",type:"vec3"}]);return e.attributes.uv.location=0,e.attributes.f.location=1,e.attributes.normal.location=2,e},r.createPickShader=function(t){var e=n(t,a,l,null,[{name:"uv",type:"vec4"},{name:"f",type:"vec3"},{name:"normal",type:"vec3"}]);return e.attributes.uv.location=0,e.attributes.f.location=1,e.attributes.normal.location=2,e},r.createContourShader=function(t){var e=n(t,s,o,null,[{name:"uv",type:"vec4"},{name:"f",type:"float"}]);return e.attributes.uv.location=0,e.attributes.f.location=1,e},r.createPickContourShader=function(t){var e=n(t,s,l,null,[{name:"uv",type:"vec4"},{name:"f",type:"float"}]);return e.attributes.uv.location=0,e.attributes.f.location=1,e}},{"gl-shader":132,glslify:231}],145:[function(t,e,r){"use strict";e.exports=function(t){var e=t.gl,r=y(e),n=b(e),s=x(e),l=_(e),c=i(e),u=a(e,[{buffer:c,size:4,stride:40,offset:0},{buffer:c,size:3,stride:40,offset:16},{buffer:c,size:3,stride:40,offset:28}]),f=i(e),h=a(e,[{buffer:f,size:4,stride:20,offset:0},{buffer:f,size:1,stride:20,offset:16}]),p=i(e),d=a(e,[{buffer:p,size:2,type:e.FLOAT}]),m=o(e,1,256,e.RGBA,e.UNSIGNED_BYTE);m.minFilter=e.LINEAR,m.magFilter=e.LINEAR;var g=new M(e,[0,0],[[0,0,0],[0,0,0]],r,n,c,u,m,s,l,f,h,p,d,[0,0,0]),v={levels:[[],[],[]]};for(var w in t)v[w]=t[w];return v.colormap=v.colormap||"jet",g.update(v),g};var n=t("bit-twiddle"),i=t("gl-buffer"),a=t("gl-vao"),o=t("gl-texture2d"),s=t("typedarray-pool"),l=t("colormap"),c=t("ndarray-ops"),u=t("ndarray-pack"),f=t("ndarray"),h=t("surface-nets"),p=t("gl-mat4/multiply"),d=t("gl-mat4/invert"),m=t("binary-search-bounds"),g=t("ndarray-gradient"),v=t("./lib/shaders"),y=v.createShader,x=v.createContourShader,b=v.createPickShader,_=v.createPickContourShader,w=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],T=[[0,0],[0,1],[1,0],[1,1],[1,0],[0,1]],k=[[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]];function A(t,e,r,n,i){this.position=t,this.index=e,this.uv=r,this.level=n,this.dataCoordinate=i}!function(){for(var t=0;t<3;++t){var e=k[t],r=(t+2)%3;e[(t+1)%3+0]=1,e[r+3]=1,e[t+6]=1}}();function M(t,e,r,n,i,a,o,l,c,u,h,p,d,m,g){this.gl=t,this.shape=e,this.bounds=r,this.objectOffset=g,this.intensityBounds=[],this._shader=n,this._pickShader=i,this._coordinateBuffer=a,this._vao=o,this._colorMap=l,this._contourShader=c,this._contourPickShader=u,this._contourBuffer=h,this._contourVAO=p,this._contourOffsets=[[],[],[]],this._contourCounts=[[],[],[]],this._vertexCount=0,this._pickResult=new A([0,0,0],[0,0],[0,0],[0,0,0],[0,0,0]),this._dynamicBuffer=d,this._dynamicVAO=m,this._dynamicOffsets=[0,0,0],this._dynamicCounts=[0,0,0],this.contourWidth=[1,1,1],this.contourLevels=[[1],[1],[1]],this.contourTint=[0,0,0],this.contourColor=[[.5,.5,.5,1],[.5,.5,.5,1],[.5,.5,.5,1]],this.showContour=!0,this.showSurface=!0,this.enableHighlight=[!0,!0,!0],this.highlightColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.highlightTint=[1,1,1],this.highlightLevel=[-1,-1,-1],this.enableDynamic=[!0,!0,!0],this.dynamicLevel=[NaN,NaN,NaN],this.dynamicColor=[[0,0,0,1],[0,0,0,1],[0,0,0,1]],this.dynamicTint=[1,1,1],this.dynamicWidth=[1,1,1],this.axesBounds=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]],this.surfaceProject=[!1,!1,!1],this.contourProject=[[!1,!1,!1],[!1,!1,!1],[!1,!1,!1]],this.colorBounds=[!1,!1],this._field=[f(s.mallocFloat(1024),[0,0]),f(s.mallocFloat(1024),[0,0]),f(s.mallocFloat(1024),[0,0])],this.pickId=1,this.clipBounds=[[-1/0,-1/0,-1/0],[1/0,1/0,1/0]],this.snapToData=!1,this.pixelRatio=1,this.opacity=1,this.lightPosition=[10,1e4,0],this.ambientLight=.8,this.diffuseLight=.8,this.specularLight=2,this.roughness=.5,this.fresnel=1.5,this.vertexColor=0,this.dirty=!0}var S=M.prototype;S.genColormap=function(t,e){var r=!1,n=u([l({colormap:t,nshades:256,format:"rgba"}).map((function(t,n){var i=e?function(t,e){if(!e)return 1;if(!e.length)return 1;for(var r=0;r<e.length;++r){if(e.length<2)return 1;if(e[r][0]===t)return e[r][1];if(e[r][0]>t&&r>0){var n=(e[r][0]-t)/(e[r][0]-e[r-1][0]);return e[r][1]*(1-n)+n*e[r-1][1]}}return 1}(n/255,e):t[3];return i<1&&(r=!0),[t[0],t[1],t[2],255*i]}))]);return c.divseq(n,255),this.hasAlphaScale=r,n},S.isTransparent=function(){return this.opacity<1||this.hasAlphaScale},S.isOpaque=function(){return!this.isTransparent()},S.pickSlots=1,S.setPickBase=function(t){this.pickId=t};var E=[0,0,0],L={showSurface:!1,showContour:!1,projections:[w.slice(),w.slice(),w.slice()],clipBounds:[[[0,0,0],[0,0,0]],[[0,0,0],[0,0,0]],[[0,0,0],[0,0,0]]]};function C(t,e){var r,n,i,a=e.axes&&e.axes.lastCubeProps.axis||E,o=e.showSurface,s=e.showContour;for(r=0;r<3;++r)for(o=o||e.surfaceProject[r],n=0;n<3;++n)s=s||e.contourProject[r][n];for(r=0;r<3;++r){var l=L.projections[r];for(n=0;n<16;++n)l[n]=0;for(n=0;n<4;++n)l[5*n]=1;l[5*r]=0,l[12+r]=e.axesBounds[+(a[r]>0)][r],p(l,t.model,l);var c=L.clipBounds[r];for(i=0;i<2;++i)for(n=0;n<3;++n)c[i][n]=t.clipBounds[i][n];c[0][r]=-1e8,c[1][r]=1e8}return L.showSurface=o,L.showContour=s,L}var P={model:w,view:w,projection:w,inverseModel:w.slice(),lowerBound:[0,0,0],upperBound:[0,0,0],colorMap:0,clipBounds:[[0,0,0],[0,0,0]],height:0,contourTint:0,contourColor:[0,0,0,1],permutation:[1,0,0,0,1,0,0,0,1],zOffset:-1e-4,objectOffset:[0,0,0],kambient:1,kdiffuse:1,kspecular:1,lightPosition:[1e3,1e3,1e3],eyePosition:[0,0,0],roughness:1,fresnel:1,opacity:1,vertexColor:0},I=w.slice(),O=[1,0,0,0,1,0,0,0,1];function z(t,e){t=t||{};var r=this.gl;r.disable(r.CULL_FACE),this._colorMap.bind(0);var n=P;n.model=t.model||w,n.view=t.view||w,n.projection=t.projection||w,n.lowerBound=[this.bounds[0][0],this.bounds[0][1],this.colorBounds[0]||this.bounds[0][2]],n.upperBound=[this.bounds[1][0],this.bounds[1][1],this.colorBounds[1]||this.bounds[1][2]],n.objectOffset=this.objectOffset,n.contourColor=this.contourColor[0],n.inverseModel=d(n.inverseModel,n.model);for(var i=0;i<2;++i)for(var a=n.clipBounds[i],o=0;o<3;++o)a[o]=Math.min(Math.max(this.clipBounds[i][o],-1e8),1e8);n.kambient=this.ambientLight,n.kdiffuse=this.diffuseLight,n.kspecular=this.specularLight,n.roughness=this.roughness,n.fresnel=this.fresnel,n.opacity=this.opacity,n.height=0,n.permutation=O,n.vertexColor=this.vertexColor;var s=I;for(p(s,n.view,n.model),p(s,n.projection,s),d(s,s),i=0;i<3;++i)n.eyePosition[i]=s[12+i]/s[15];var l=s[15];for(i=0;i<3;++i)l+=this.lightPosition[i]*s[4*i+3];for(i=0;i<3;++i){var c=s[12+i];for(o=0;o<3;++o)c+=s[4*o+i]*this.lightPosition[o];n.lightPosition[i]=c/l}var u=C(n,this);if(u.showSurface){for(this._shader.bind(),this._shader.uniforms=n,this._vao.bind(),this.showSurface&&this._vertexCount&&this._vao.draw(r.TRIANGLES,this._vertexCount),i=0;i<3;++i)this.surfaceProject[i]&&this.vertexCount&&(this._shader.uniforms.model=u.projections[i],this._shader.uniforms.clipBounds=u.clipBounds[i],this._vao.draw(r.TRIANGLES,this._vertexCount));this._vao.unbind()}if(u.showContour){var f=this._contourShader;n.kambient=1,n.kdiffuse=0,n.kspecular=0,n.opacity=1,f.bind(),f.uniforms=n;var h=this._contourVAO;for(h.bind(),i=0;i<3;++i)for(f.uniforms.permutation=k[i],r.lineWidth(this.contourWidth[i]*this.pixelRatio),o=0;o<this.contourLevels[i].length;++o)o===this.highlightLevel[i]?(f.uniforms.contourColor=this.highlightColor[i],f.uniforms.contourTint=this.highlightTint[i]):0!==o&&o-1!==this.highlightLevel[i]||(f.uniforms.contourColor=this.contourColor[i],f.uniforms.contourTint=this.contourTint[i]),this._contourCounts[i][o]&&(f.uniforms.height=this.contourLevels[i][o],h.draw(r.LINES,this._contourCounts[i][o],this._contourOffsets[i][o]));for(i=0;i<3;++i)for(f.uniforms.model=u.projections[i],f.uniforms.clipBounds=u.clipBounds[i],o=0;o<3;++o)if(this.contourProject[i][o]){f.uniforms.permutation=k[o],r.lineWidth(this.contourWidth[o]*this.pixelRatio);for(var m=0;m<this.contourLevels[o].length;++m)m===this.highlightLevel[o]?(f.uniforms.contourColor=this.highlightColor[o],f.uniforms.contourTint=this.highlightTint[o]):0!==m&&m-1!==this.highlightLevel[o]||(f.uniforms.contourColor=this.contourColor[o],f.uniforms.contourTint=this.contourTint[o]),this._contourCounts[o][m]&&(f.uniforms.height=this.contourLevels[o][m],h.draw(r.LINES,this._contourCounts[o][m],this._contourOffsets[o][m]))}for(h.unbind(),(h=this._dynamicVAO).bind(),i=0;i<3;++i)if(0!==this._dynamicCounts[i])for(f.uniforms.model=n.model,f.uniforms.clipBounds=n.clipBounds,f.uniforms.permutation=k[i],r.lineWidth(this.dynamicWidth[i]*this.pixelRatio),f.uniforms.contourColor=this.dynamicColor[i],f.uniforms.contourTint=this.dynamicTint[i],f.uniforms.height=this.dynamicLevel[i],h.draw(r.LINES,this._dynamicCounts[i],this._dynamicOffsets[i]),o=0;o<3;++o)this.contourProject[o][i]&&(f.uniforms.model=u.projections[o],f.uniforms.clipBounds=u.clipBounds[o],h.draw(r.LINES,this._dynamicCounts[i],this._dynamicOffsets[i]));h.unbind()}}S.draw=function(t){return z.call(this,t,!1)},S.drawTransparent=function(t){return z.call(this,t,!0)};var D={model:w,view:w,projection:w,inverseModel:w,clipBounds:[[0,0,0],[0,0,0]],height:0,shape:[0,0],pickId:0,lowerBound:[0,0,0],upperBound:[0,0,0],zOffset:0,objectOffset:[0,0,0],permutation:[1,0,0,0,1,0,0,0,1],lightPosition:[0,0,0],eyePosition:[0,0,0]};function R(t,e){return Array.isArray(t)?[e(t[0]),e(t[1]),e(t[2])]:[e(t),e(t),e(t)]}function F(t){return Array.isArray(t)?3===t.length?[t[0],t[1],t[2],1]:[t[0],t[1],t[2],t[3]]:[0,0,0,1]}function B(t){if(Array.isArray(t)){if(Array.isArray(t))return[F(t[0]),F(t[1]),F(t[2])];var e=F(t);return[e.slice(),e.slice(),e.slice()]}}S.drawPick=function(t){t=t||{};var e=this.gl;e.disable(e.CULL_FACE);var r=D;r.model=t.model||w,r.view=t.view||w,r.projection=t.projection||w,r.shape=this._field[2].shape,r.pickId=this.pickId/255,r.lowerBound=this.bounds[0],r.upperBound=this.bounds[1],r.objectOffset=this.objectOffset,r.permutation=O;for(var n=0;n<2;++n)for(var i=r.clipBounds[n],a=0;a<3;++a)i[a]=Math.min(Math.max(this.clipBounds[n][a],-1e8),1e8);var o=C(r,this);if(o.showSurface){for(this._pickShader.bind(),this._pickShader.uniforms=r,this._vao.bind(),this._vao.draw(e.TRIANGLES,this._vertexCount),n=0;n<3;++n)this.surfaceProject[n]&&(this._pickShader.uniforms.model=o.projections[n],this._pickShader.uniforms.clipBounds=o.clipBounds[n],this._vao.draw(e.TRIANGLES,this._vertexCount));this._vao.unbind()}if(o.showContour){var s=this._contourPickShader;s.bind(),s.uniforms=r;var l=this._contourVAO;for(l.bind(),a=0;a<3;++a)for(e.lineWidth(this.contourWidth[a]*this.pixelRatio),s.uniforms.permutation=k[a],n=0;n<this.contourLevels[a].length;++n)this._contourCounts[a][n]&&(s.uniforms.height=this.contourLevels[a][n],l.draw(e.LINES,this._contourCounts[a][n],this._contourOffsets[a][n]));for(n=0;n<3;++n)for(s.uniforms.model=o.projections[n],s.uniforms.clipBounds=o.clipBounds[n],a=0;a<3;++a)if(this.contourProject[n][a]){s.uniforms.permutation=k[a],e.lineWidth(this.contourWidth[a]*this.pixelRatio);for(var c=0;c<this.contourLevels[a].length;++c)this._contourCounts[a][c]&&(s.uniforms.height=this.contourLevels[a][c],l.draw(e.LINES,this._contourCounts[a][c],this._contourOffsets[a][c]))}l.unbind()}},S.pick=function(t){if(!t)return null;if(t.id!==this.pickId)return null;var e=this._field[2].shape,r=this._pickResult,n=e[0]*(t.value[0]+(t.value[2]>>4)/16)/255,i=Math.floor(n),a=n-i,o=e[1]*(t.value[1]+(15&t.value[2])/16)/255,s=Math.floor(o),l=o-s;i+=1,s+=1;var c=r.position;c[0]=c[1]=c[2]=0;for(var u=0;u<2;++u)for(var f=u?a:1-a,h=0;h<2;++h)for(var p=i+u,d=s+h,g=f*(h?l:1-l),v=0;v<3;++v)c[v]+=this._field[v].get(p,d)*g;for(var y=this._pickResult.level,x=0;x<3;++x)if(y[x]=m.le(this.contourLevels[x],c[x]),y[x]<0)this.contourLevels[x].length>0&&(y[x]=0);else if(y[x]<this.contourLevels[x].length-1){var b=this.contourLevels[x][y[x]],_=this.contourLevels[x][y[x]+1];Math.abs(b-c[x])>Math.abs(_-c[x])&&(y[x]+=1)}for(r.index[0]=a<.5?i:i+1,r.index[1]=l<.5?s:s+1,r.uv[0]=n/e[0],r.uv[1]=o/e[1],v=0;v<3;++v)r.dataCoordinate[v]=this._field[v].get(r.index[0],r.index[1]);return r},S.padField=function(t,e){var r=e.shape.slice(),n=t.shape.slice();c.assign(t.lo(1,1).hi(r[0],r[1]),e),c.assign(t.lo(1).hi(r[0],1),e.hi(r[0],1)),c.assign(t.lo(1,n[1]-1).hi(r[0],1),e.lo(0,r[1]-1).hi(r[0],1)),c.assign(t.lo(0,1).hi(1,r[1]),e.hi(1)),c.assign(t.lo(n[0]-1,1).hi(1,r[1]),e.lo(r[0]-1)),t.set(0,0,e.get(0,0)),t.set(0,n[1]-1,e.get(0,r[1]-1)),t.set(n[0]-1,0,e.get(r[0]-1,0)),t.set(n[0]-1,n[1]-1,e.get(r[0]-1,r[1]-1))},S.update=function(t){t=t||{},this.objectOffset=t.objectOffset||this.objectOffset,this.dirty=!0,"contourWidth"in t&&(this.contourWidth=R(t.contourWidth,Number)),"showContour"in t&&(this.showContour=R(t.showContour,Boolean)),"showSurface"in t&&(this.showSurface=!!t.showSurface),"contourTint"in t&&(this.contourTint=R(t.contourTint,Boolean)),"contourColor"in t&&(this.contourColor=B(t.contourColor)),"contourProject"in t&&(this.contourProject=R(t.contourProject,(function(t){return R(t,Boolean)}))),"surfaceProject"in t&&(this.surfaceProject=t.surfaceProject),"dynamicColor"in t&&(this.dynamicColor=B(t.dynamicColor)),"dynamicTint"in t&&(this.dynamicTint=R(t.dynamicTint,Number)),"dynamicWidth"in t&&(this.dynamicWidth=R(t.dynamicWidth,Number)),"opacity"in t&&(this.opacity=t.opacity),"opacityscale"in t&&(this.opacityscale=t.opacityscale),"colorBounds"in t&&(this.colorBounds=t.colorBounds),"vertexColor"in t&&(this.vertexColor=t.vertexColor?1:0),"colormap"in t&&this._colorMap.setPixels(this.genColormap(t.colormap,this.opacityscale));var e=t.field||t.coords&&t.coords[2]||null,r=!1;if(e||(e=this._field[2].shape[0]||this._field[2].shape[2]?this._field[2].lo(1,1).hi(this._field[2].shape[0]-2,this._field[2].shape[1]-2):this._field[2].hi(0,0)),"field"in t||"coords"in t){var i=(e.shape[0]+2)*(e.shape[1]+2);i>this._field[2].data.length&&(s.freeFloat(this._field[2].data),this._field[2].data=s.mallocFloat(n.nextPow2(i))),this._field[2]=f(this._field[2].data,[e.shape[0]+2,e.shape[1]+2]),this.padField(this._field[2],e),this.shape=e.shape.slice();for(var a=this.shape,o=0;o<2;++o)this._field[2].size>this._field[o].data.length&&(s.freeFloat(this._field[o].data),this._field[o].data=s.mallocFloat(this._field[2].size)),this._field[o]=f(this._field[o].data,[a[0]+2,a[1]+2]);if(t.coords){var l=t.coords;if(!Array.isArray(l)||3!==l.length)throw new Error("gl-surface: invalid coordinates for x/y");for(o=0;o<2;++o){var c=l[o];for(v=0;v<2;++v)if(c.shape[v]!==a[v])throw new Error("gl-surface: coords have incorrect shape");this.padField(this._field[o],c)}}else if(t.ticks){var u=t.ticks;if(!Array.isArray(u)||2!==u.length)throw new Error("gl-surface: invalid ticks");for(o=0;o<2;++o){var p=u[o];if((Array.isArray(p)||p.length)&&(p=f(p)),p.shape[0]!==a[o])throw new Error("gl-surface: invalid tick length");var d=f(p.data,a);d.stride[o]=p.stride[0],d.stride[1^o]=0,this.padField(this._field[o],d)}}else{for(o=0;o<2;++o){var m=[0,0];m[o]=1,this._field[o]=f(this._field[o].data,[a[0]+2,a[1]+2],m,0)}this._field[0].set(0,0,0);for(var v=0;v<a[0];++v)this._field[0].set(v+1,0,v);for(this._field[0].set(a[0]+1,0,a[0]-1),this._field[1].set(0,0,0),v=0;v<a[1];++v)this._field[1].set(0,v+1,v);this._field[1].set(0,a[1]+1,a[1]-1)}var y=this._field,x=f(s.mallocFloat(3*y[2].size*2),[3,a[0]+2,a[1]+2,2]);for(o=0;o<3;++o)g(x.pick(o),y[o],"mirror");var b=f(s.mallocFloat(3*y[2].size),[a[0]+2,a[1]+2,3]);for(o=0;o<a[0]+2;++o)for(v=0;v<a[1]+2;++v){var _=x.get(0,o,v,0),w=x.get(0,o,v,1),k=x.get(1,o,v,0),A=x.get(1,o,v,1),M=x.get(2,o,v,0),S=x.get(2,o,v,1),E=k*S-A*M,L=M*w-S*_,C=_*A-w*k,P=Math.sqrt(E*E+L*L+C*C);P<1e-8?(P=Math.max(Math.abs(E),Math.abs(L),Math.abs(C)))<1e-8?(C=1,L=E=0,P=1):P=1/P:P=1/Math.sqrt(P),b.set(o,v,0,E*P),b.set(o,v,1,L*P),b.set(o,v,2,C*P)}s.free(x.data);var I=[1/0,1/0,1/0],O=[-1/0,-1/0,-1/0],z=1/0,D=-1/0,F=(a[0]-1)*(a[1]-1)*6,N=s.mallocFloat(n.nextPow2(10*F)),j=0,U=0;for(o=0;o<a[0]-1;++o)t:for(v=0;v<a[1]-1;++v){for(var V=0;V<2;++V)for(var H=0;H<2;++H)for(var q=0;q<3;++q){var G=this._field[q].get(1+o+V,1+v+H);if(isNaN(G)||!isFinite(G))continue t}for(q=0;q<6;++q){var Y=o+T[q][0],W=v+T[q][1],X=this._field[0].get(Y+1,W+1),Z=this._field[1].get(Y+1,W+1);G=this._field[2].get(Y+1,W+1),E=b.get(Y+1,W+1,0),L=b.get(Y+1,W+1,1),C=b.get(Y+1,W+1,2),t.intensity&&(J=t.intensity.get(Y,W));var J=t.intensity?t.intensity.get(Y,W):G+this.objectOffset[2];N[j++]=Y,N[j++]=W,N[j++]=X,N[j++]=Z,N[j++]=G,N[j++]=0,N[j++]=J,N[j++]=E,N[j++]=L,N[j++]=C,I[0]=Math.min(I[0],X+this.objectOffset[0]),I[1]=Math.min(I[1],Z+this.objectOffset[1]),I[2]=Math.min(I[2],G+this.objectOffset[2]),z=Math.min(z,J),O[0]=Math.max(O[0],X+this.objectOffset[0]),O[1]=Math.max(O[1],Z+this.objectOffset[1]),O[2]=Math.max(O[2],G+this.objectOffset[2]),D=Math.max(D,J),U+=1}}for(t.intensityBounds&&(z=+t.intensityBounds[0],D=+t.intensityBounds[1]),o=6;o<j;o+=10)N[o]=(N[o]-z)/(D-z);this._vertexCount=U,this._coordinateBuffer.update(N.subarray(0,j)),s.freeFloat(N),s.free(b.data),this.bounds=[I,O],this.intensity=t.intensity||this._field[2],this.intensityBounds[0]===z&&this.intensityBounds[1]===D||(r=!0),this.intensityBounds=[z,D]}if("levels"in t){var K=t.levels;for(K=Array.isArray(K[0])?K.slice():[[],[],K],o=0;o<3;++o)K[o]=K[o].slice(),K[o].sort((function(t,e){return t-e}));for(o=0;o<3;++o)for(v=0;v<K[o].length;++v)K[o][v]-=this.objectOffset[o];t:for(o=0;o<3;++o){if(K[o].length!==this.contourLevels[o].length){r=!0;break}for(v=0;v<K[o].length;++v)if(K[o][v]!==this.contourLevels[o][v]){r=!0;break t}}this.contourLevels=K}if(r){y=this._field,a=this.shape;for(var Q=[],$=0;$<3;++$){var tt=this.contourLevels[$],et=[],rt=[],nt=[0,0,0];for(o=0;o<tt.length;++o){var it=h(this._field[$],tt[o]);et.push(Q.length/5|0),U=0;t:for(v=0;v<it.cells.length;++v){var at=it.cells[v];for(q=0;q<2;++q){var ot=it.positions[at[q]],st=ot[0],lt=0|Math.floor(st),ct=st-lt,ut=ot[1],ft=0|Math.floor(ut),ht=ut-ft,pt=!1;e:for(var dt=0;dt<3;++dt){nt[dt]=0;var mt=($+dt+1)%3;for(V=0;V<2;++V){var gt=V?ct:1-ct;for(Y=0|Math.min(Math.max(lt+V,0),a[0]),H=0;H<2;++H){var vt=H?ht:1-ht;if(W=0|Math.min(Math.max(ft+H,0),a[1]),G=dt<2?this._field[mt].get(Y,W):(this.intensity.get(Y,W)-this.intensityBounds[0])/(this.intensityBounds[1]-this.intensityBounds[0]),!isFinite(G)||isNaN(G)){pt=!0;break e}var yt=gt*vt;nt[dt]+=yt*G}}}if(pt){if(q>0){for(var xt=0;xt<5;++xt)Q.pop();U-=1}continue t}Q.push(nt[0],nt[1],ot[0],ot[1],nt[2]),U+=1}}rt.push(U)}this._contourOffsets[$]=et,this._contourCounts[$]=rt}var bt=s.mallocFloat(Q.length);for(o=0;o<Q.length;++o)bt[o]=Q[o];this._contourBuffer.update(bt),s.freeFloat(bt)}},S.dispose=function(){this._shader.dispose(),this._vao.dispose(),this._coordinateBuffer.dispose(),this._colorMap.dispose(),this._contourBuffer.dispose(),this._contourVAO.dispose(),this._contourShader.dispose(),this._contourPickShader.dispose(),this._dynamicBuffer.dispose(),this._dynamicVAO.dispose();for(var t=0;t<3;++t)s.freeFloat(this._field[t].data)},S.highlight=function(t){var e,r;if(!t)return this._dynamicCounts=[0,0,0],this.dyanamicLevel=[NaN,NaN,NaN],void(this.highlightLevel=[-1,-1,-1]);for(e=0;e<3;++e)this.enableHighlight[e]?this.highlightLevel[e]=t.level[e]:this.highlightLevel[e]=-1;for(r=this.snapToData?t.dataCoordinate:t.position,e=0;e<3;++e)r[e]-=this.objectOffset[e];if(this.enableDynamic[0]&&r[0]!==this.dynamicLevel[0]||this.enableDynamic[1]&&r[1]!==this.dynamicLevel[1]||this.enableDynamic[2]&&r[2]!==this.dynamicLevel[2]){for(var n=0,i=this.shape,a=s.mallocFloat(12*i[0]*i[1]),o=0;o<3;++o)if(this.enableDynamic[o]){this.dynamicLevel[o]=r[o];var l=(o+1)%3,c=(o+2)%3,u=this._field[o],f=this._field[l],p=this._field[c],d=h(u,r[o]),m=d.cells,g=d.positions;for(this._dynamicOffsets[o]=n,e=0;e<m.length;++e)for(var v=m[e],y=0;y<2;++y){var x=g[v[y]],b=+x[0],_=0|b,w=0|Math.min(_+1,i[0]),T=b-_,k=1-T,A=+x[1],M=0|A,S=0|Math.min(M+1,i[1]),E=A-M,L=1-E,C=k*L,P=k*E,I=T*L,O=T*E,z=C*f.get(_,M)+P*f.get(_,S)+I*f.get(w,M)+O*f.get(w,S),D=C*p.get(_,M)+P*p.get(_,S)+I*p.get(w,M)+O*p.get(w,S);if(isNaN(z)||isNaN(D)){y&&(n-=1);break}a[2*n+0]=z,a[2*n+1]=D,n+=1}this._dynamicCounts[o]=n-this._dynamicOffsets[o]}else this.dynamicLevel[o]=NaN,this._dynamicCounts[o]=0;this._dynamicBuffer.update(a.subarray(0,2*n)),s.freeFloat(a)}}},{"./lib/shaders":144,"binary-search-bounds":31,"bit-twiddle":32,colormap:53,"gl-buffer":78,"gl-mat4/invert":98,"gl-mat4/multiply":100,"gl-texture2d":146,"gl-vao":150,ndarray:259,"ndarray-gradient":252,"ndarray-ops":254,"ndarray-pack":255,"surface-nets":302,"typedarray-pool":308}],146:[function(t,e,r){"use strict";var n=t("ndarray"),i=t("ndarray-ops"),a=t("typedarray-pool");e.exports=function(t){if(arguments.length<=1)throw new Error("gl-texture2d: Missing arguments for texture2d constructor");o||c(t);if("number"==typeof arguments[1])return v(t,arguments[1],arguments[2],arguments[3]||t.RGBA,arguments[4]||t.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return v(t,0|arguments[1][0],0|arguments[1][1],arguments[2]||t.RGBA,arguments[3]||t.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var e=arguments[1],r=u(e)?e:e.raw;if(r)return y(t,r,0|e.width,0|e.height,arguments[2]||t.RGBA,arguments[3]||t.UNSIGNED_BYTE);if(e.shape&&e.data&&e.stride)return x(t,e)}throw new Error("gl-texture2d: Invalid arguments for texture2d constructor")};var o=null,s=null,l=null;function c(t){o=[t.LINEAR,t.NEAREST_MIPMAP_LINEAR,t.LINEAR_MIPMAP_NEAREST,t.LINEAR_MIPMAP_NEAREST],s=[t.NEAREST,t.LINEAR,t.NEAREST_MIPMAP_NEAREST,t.NEAREST_MIPMAP_LINEAR,t.LINEAR_MIPMAP_NEAREST,t.LINEAR_MIPMAP_LINEAR],l=[t.REPEAT,t.CLAMP_TO_EDGE,t.MIRRORED_REPEAT]}function u(t){return"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLVideoElement&&t instanceof HTMLVideoElement||"undefined"!=typeof ImageData&&t instanceof ImageData}var f=function(t,e){i.muls(t,e,255)};function h(t,e,r){var n=t.gl,i=n.getParameter(n.MAX_TEXTURE_SIZE);if(e<0||e>i||r<0||r>i)throw new Error("gl-texture2d: Invalid texture size");return t._shape=[e,r],t.bind(),n.texImage2D(n.TEXTURE_2D,0,t.format,e,r,0,t.format,t.type,null),t._mipLevels=[0],t}function p(t,e,r,n,i,a){this.gl=t,this.handle=e,this.format=i,this.type=a,this._shape=[r,n],this._mipLevels=[0],this._magFilter=t.NEAREST,this._minFilter=t.NEAREST,this._wrapS=t.CLAMP_TO_EDGE,this._wrapT=t.CLAMP_TO_EDGE,this._anisoSamples=1;var o=this,s=[this._wrapS,this._wrapT];Object.defineProperties(s,[{get:function(){return o._wrapS},set:function(t){return o.wrapS=t}},{get:function(){return o._wrapT},set:function(t){return o.wrapT=t}}]),this._wrapVector=s;var l=[this._shape[0],this._shape[1]];Object.defineProperties(l,[{get:function(){return o._shape[0]},set:function(t){return o.width=t}},{get:function(){return o._shape[1]},set:function(t){return o.height=t}}]),this._shapeVector=l}var d=p.prototype;function m(t,e){return 3===t.length?1===e[2]&&e[1]===t[0]*t[2]&&e[0]===t[2]:1===e[0]&&e[1]===t[0]}function g(t){var e=t.createTexture();return t.bindTexture(t.TEXTURE_2D,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),e}function v(t,e,r,n,i){var a=t.getParameter(t.MAX_TEXTURE_SIZE);if(e<0||e>a||r<0||r>a)throw new Error("gl-texture2d: Invalid texture shape");if(i===t.FLOAT&&!t.getExtension("OES_texture_float"))throw new Error("gl-texture2d: Floating point textures not supported on this platform");var o=g(t);return t.texImage2D(t.TEXTURE_2D,0,n,e,r,0,n,i,null),new p(t,o,e,r,n,i)}function y(t,e,r,n,i,a){var o=g(t);return t.texImage2D(t.TEXTURE_2D,0,i,i,a,e),new p(t,o,r,n,i,a)}function x(t,e){var r=e.dtype,o=e.shape.slice(),s=t.getParameter(t.MAX_TEXTURE_SIZE);if(o[0]<0||o[0]>s||o[1]<0||o[1]>s)throw new Error("gl-texture2d: Invalid texture size");var l=m(o,e.stride.slice()),c=0;"float32"===r?c=t.FLOAT:"float64"===r?(c=t.FLOAT,l=!1,r="float32"):"uint8"===r?c=t.UNSIGNED_BYTE:(c=t.UNSIGNED_BYTE,l=!1,r="uint8");var u,h,d=0;if(2===o.length)d=t.LUMINANCE,o=[o[0],o[1],1],e=n(e.data,o,[e.stride[0],e.stride[1],1],e.offset);else{if(3!==o.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===o[2])d=t.ALPHA;else if(2===o[2])d=t.LUMINANCE_ALPHA;else if(3===o[2])d=t.RGB;else{if(4!==o[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");d=t.RGBA}}c!==t.FLOAT||t.getExtension("OES_texture_float")||(c=t.UNSIGNED_BYTE,l=!1);var v=e.size;if(l)u=0===e.offset&&e.data.length===v?e.data:e.data.subarray(e.offset,e.offset+v);else{var y=[o[2],o[2]*o[0],1];h=a.malloc(v,r);var x=n(h,o,y,0);"float32"!==r&&"float64"!==r||c!==t.UNSIGNED_BYTE?i.assign(x,e):f(x,e),u=h.subarray(0,v)}var b=g(t);return t.texImage2D(t.TEXTURE_2D,0,d,o[0],o[1],0,d,c,u),l||a.free(h),new p(t,b,o[0],o[1],d,c)}Object.defineProperties(d,{minFilter:{get:function(){return this._minFilter},set:function(t){this.bind();var e=this.gl;if(this.type===e.FLOAT&&o.indexOf(t)>=0&&(e.getExtension("OES_texture_float_linear")||(t=e.NEAREST)),s.indexOf(t)<0)throw new Error("gl-texture2d: Unknown filter mode "+t);return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t),this._minFilter=t}},magFilter:{get:function(){return this._magFilter},set:function(t){this.bind();var e=this.gl;if(this.type===e.FLOAT&&o.indexOf(t)>=0&&(e.getExtension("OES_texture_float_linear")||(t=e.NEAREST)),s.indexOf(t)<0)throw new Error("gl-texture2d: Unknown filter mode "+t);return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,t),this._magFilter=t}},mipSamples:{get:function(){return this._anisoSamples},set:function(t){var e=this._anisoSamples;if(this._anisoSamples=0|Math.max(t,1),e!==this._anisoSamples){var r=this.gl.getExtension("EXT_texture_filter_anisotropic");r&&this.gl.texParameterf(this.gl.TEXTURE_2D,r.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}},wrapS:{get:function(){return this._wrapS},set:function(t){if(this.bind(),l.indexOf(t)<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,t),this._wrapS=t}},wrapT:{get:function(){return this._wrapT},set:function(t){if(this.bind(),l.indexOf(t)<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,t),this._wrapT=t}},wrap:{get:function(){return this._wrapVector},set:function(t){if(Array.isArray(t)||(t=[t,t]),2!==t.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var e=0;e<2;++e)if(l.indexOf(t[e])<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);this._wrapS=t[0],this._wrapT=t[1];var r=this.gl;return this.bind(),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,this._wrapS),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,this._wrapT),t}},shape:{get:function(){return this._shapeVector},set:function(t){if(Array.isArray(t)){if(2!==t.length)throw new Error("gl-texture2d: Invalid texture shape")}else t=[0|t,0|t];return h(this,0|t[0],0|t[1]),[0|t[0],0|t[1]]}},width:{get:function(){return this._shape[0]},set:function(t){return h(this,t|=0,this._shape[1]),t}},height:{get:function(){return this._shape[1]},set:function(t){return t|=0,h(this,this._shape[0],t),t}}}),d.bind=function(t){var e=this.gl;return void 0!==t&&e.activeTexture(e.TEXTURE0+(0|t)),e.bindTexture(e.TEXTURE_2D,this.handle),void 0!==t?0|t:e.getParameter(e.ACTIVE_TEXTURE)-e.TEXTURE0},d.dispose=function(){this.gl.deleteTexture(this.handle)},d.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var t=Math.min(this._shape[0],this._shape[1]),e=0;t>0;++e,t>>>=1)this._mipLevels.indexOf(e)<0&&this._mipLevels.push(e)},d.setPixels=function(t,e,r,o){var s=this.gl;this.bind(),Array.isArray(e)?(o=r,r=0|e[1],e=0|e[0]):(e=e||0,r=r||0),o=o||0;var l=u(t)?t:t.raw;if(l){this._mipLevels.indexOf(o)<0?(s.texImage2D(s.TEXTURE_2D,0,this.format,this.format,this.type,l),this._mipLevels.push(o)):s.texSubImage2D(s.TEXTURE_2D,o,e,r,this.format,this.type,l)}else{if(!(t.shape&&t.stride&&t.data))throw new Error("gl-texture2d: Unsupported data type");if(t.shape.length<2||e+t.shape[1]>this._shape[1]>>>o||r+t.shape[0]>this._shape[0]>>>o||e<0||r<0)throw new Error("gl-texture2d: Texture dimensions are out of bounds");!function(t,e,r,o,s,l,c,u){var h=u.dtype,p=u.shape.slice();if(p.length<2||p.length>3)throw new Error("gl-texture2d: Invalid ndarray, must be 2d or 3d");var d=0,g=0,v=m(p,u.stride.slice());"float32"===h?d=t.FLOAT:"float64"===h?(d=t.FLOAT,v=!1,h="float32"):"uint8"===h?d=t.UNSIGNED_BYTE:(d=t.UNSIGNED_BYTE,v=!1,h="uint8");if(2===p.length)g=t.LUMINANCE,p=[p[0],p[1],1],u=n(u.data,p,[u.stride[0],u.stride[1],1],u.offset);else{if(3!==p.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===p[2])g=t.ALPHA;else if(2===p[2])g=t.LUMINANCE_ALPHA;else if(3===p[2])g=t.RGB;else{if(4!==p[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");g=t.RGBA}p[2]}g!==t.LUMINANCE&&g!==t.ALPHA||s!==t.LUMINANCE&&s!==t.ALPHA||(g=s);if(g!==s)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var y=u.size,x=c.indexOf(o)<0;x&&c.push(o);if(d===l&&v)0===u.offset&&u.data.length===y?x?t.texImage2D(t.TEXTURE_2D,o,s,p[0],p[1],0,s,l,u.data):t.texSubImage2D(t.TEXTURE_2D,o,e,r,p[0],p[1],s,l,u.data):x?t.texImage2D(t.TEXTURE_2D,o,s,p[0],p[1],0,s,l,u.data.subarray(u.offset,u.offset+y)):t.texSubImage2D(t.TEXTURE_2D,o,e,r,p[0],p[1],s,l,u.data.subarray(u.offset,u.offset+y));else{var b;b=l===t.FLOAT?a.mallocFloat32(y):a.mallocUint8(y);var _=n(b,p,[p[2],p[2]*p[0],1]);d===t.FLOAT&&l===t.UNSIGNED_BYTE?f(_,u):i.assign(_,u),x?t.texImage2D(t.TEXTURE_2D,o,s,p[0],p[1],0,s,l,b.subarray(0,y)):t.texSubImage2D(t.TEXTURE_2D,o,e,r,p[0],p[1],s,l,b.subarray(0,y)),l===t.FLOAT?a.freeFloat32(b):a.freeUint8(b)}}(s,e,r,o,this.format,this.type,this._mipLevels,t)}}},{ndarray:259,"ndarray-ops":254,"typedarray-pool":308}],147:[function(t,e,r){"use strict";e.exports=function(t,e,r){e?e.bind():t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null);var n=0|t.getParameter(t.MAX_VERTEX_ATTRIBS);if(r){if(r.length>n)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;i<r.length;++i){var a=r[i];if(a.buffer){var o=a.buffer,s=a.size||4,l=a.type||t.FLOAT,c=!!a.normalized,u=a.stride||0,f=a.offset||0;o.bind(),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,s,l,c,u,f)}else{if("number"==typeof a)t.vertexAttrib1f(i,a);else if(1===a.length)t.vertexAttrib1f(i,a[0]);else if(2===a.length)t.vertexAttrib2f(i,a[0],a[1]);else if(3===a.length)t.vertexAttrib3f(i,a[0],a[1],a[2]);else{if(4!==a.length)throw new Error("gl-vao: Invalid vertex attribute");t.vertexAttrib4f(i,a[0],a[1],a[2],a[3])}t.disableVertexAttribArray(i)}}for(;i<n;++i)t.disableVertexAttribArray(i)}else{t.bindBuffer(t.ARRAY_BUFFER,null);for(i=0;i<n;++i)t.disableVertexAttribArray(i)}}},{}],148:[function(t,e,r){"use strict";var n=t("./do-bind.js");function i(t){this.gl=t,this._elements=null,this._attributes=null,this._elementsType=t.UNSIGNED_SHORT}i.prototype.bind=function(){n(this.gl,this._elements,this._attributes)},i.prototype.update=function(t,e,r){this._elements=e,this._attributes=t,this._elementsType=r||this.gl.UNSIGNED_SHORT},i.prototype.dispose=function(){},i.prototype.unbind=function(){},i.prototype.draw=function(t,e,r){r=r||0;var n=this.gl;this._elements?n.drawElements(t,e,this._elementsType,r):n.drawArrays(t,r,e)},e.exports=function(t){return new i(t)}},{"./do-bind.js":147}],149:[function(t,e,r){"use strict";var n=t("./do-bind.js");function i(t,e,r,n,i,a){this.location=t,this.dimension=e,this.a=r,this.b=n,this.c=i,this.d=a}function a(t,e,r){this.gl=t,this._ext=e,this.handle=r,this._attribs=[],this._useElements=!1,this._elementsType=t.UNSIGNED_SHORT}i.prototype.bind=function(t){switch(this.dimension){case 1:t.vertexAttrib1f(this.location,this.a);break;case 2:t.vertexAttrib2f(this.location,this.a,this.b);break;case 3:t.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:t.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},a.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var t=0;t<this._attribs.length;++t)this._attribs[t].bind(this.gl)},a.prototype.unbind=function(){this._ext.bindVertexArrayOES(null)},a.prototype.dispose=function(){this._ext.deleteVertexArrayOES(this.handle)},a.prototype.update=function(t,e,r){if(this.bind(),n(this.gl,e,t),this.unbind(),this._attribs.length=0,t)for(var a=0;a<t.length;++a){var o=t[a];"number"==typeof o?this._attribs.push(new i(a,1,o)):Array.isArray(o)&&this._attribs.push(new i(a,o.length,o[0],o[1],o[2],o[3]))}this._useElements=!!e,this._elementsType=r||this.gl.UNSIGNED_SHORT},a.prototype.draw=function(t,e,r){r=r||0;var n=this.gl;this._useElements?n.drawElements(t,e,this._elementsType,r):n.drawArrays(t,r,e)},e.exports=function(t,e){return new a(t,e,e.createVertexArrayOES())}},{"./do-bind.js":147}],150:[function(t,e,r){"use strict";var n=t("./lib/vao-native.js"),i=t("./lib/vao-emulated.js");function a(t){this.bindVertexArrayOES=t.bindVertexArray.bind(t),this.createVertexArrayOES=t.createVertexArray.bind(t),this.deleteVertexArrayOES=t.deleteVertexArray.bind(t)}e.exports=function(t,e,r,o){var s,l=t.createVertexArray?new a(t):t.getExtension("OES_vertex_array_object");return(s=l?n(t,l):i(t)).update(e,r,o),s}},{"./lib/vao-emulated.js":148,"./lib/vao-native.js":149}],151:[function(t,e,r){e.exports=function(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}},{}],152:[function(t,e,r){e.exports=function(t,e){var r=n(t[0],t[1],t[2]),o=n(e[0],e[1],e[2]);i(r,r),i(o,o);var s=a(r,o);return s>1?0:Math.acos(s)};var n=t("./fromValues"),i=t("./normalize"),a=t("./dot")},{"./dot":162,"./fromValues":168,"./normalize":179}],153:[function(t,e,r){e.exports=function(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}},{}],154:[function(t,e,r){e.exports=function(t){var e=new Float32Array(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}},{}],155:[function(t,e,r){e.exports=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}},{}],156:[function(t,e,r){e.exports=function(){var t=new Float32Array(3);return t[0]=0,t[1]=0,t[2]=0,t}},{}],157:[function(t,e,r){e.exports=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],l=r[2];return t[0]=i*l-a*s,t[1]=a*o-n*l,t[2]=n*s-i*o,t}},{}],158:[function(t,e,r){e.exports=t("./distance")},{"./distance":159}],159:[function(t,e,r){e.exports=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(r*r+n*n+i*i)}},{}],160:[function(t,e,r){e.exports=t("./divide")},{"./divide":161}],161:[function(t,e,r){e.exports=function(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}},{}],162:[function(t,e,r){e.exports=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}},{}],163:[function(t,e,r){e.exports=1e-6},{}],164:[function(t,e,r){e.exports=function(t,e){var r=t[0],i=t[1],a=t[2],o=e[0],s=e[1],l=e[2];return Math.abs(r-o)<=n*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(i-s)<=n*Math.max(1,Math.abs(i),Math.abs(s))&&Math.abs(a-l)<=n*Math.max(1,Math.abs(a),Math.abs(l))};var n=t("./epsilon")},{"./epsilon":163}],165:[function(t,e,r){e.exports=function(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}},{}],166:[function(t,e,r){e.exports=function(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}},{}],167:[function(t,e,r){e.exports=function(t,e,r,i,a,o){var s,l;e||(e=3);r||(r=0);l=i?Math.min(i*e+r,t.length):t.length;for(s=r;s<l;s+=e)n[0]=t[s],n[1]=t[s+1],n[2]=t[s+2],a(n,n,o),t[s]=n[0],t[s+1]=n[1],t[s+2]=n[2];return t};var n=t("./create")()},{"./create":156}],168:[function(t,e,r){e.exports=function(t,e,r){var n=new Float32Array(3);return n[0]=t,n[1]=e,n[2]=r,n}},{}],169:[function(t,e,r){e.exports={EPSILON:t("./epsilon"),create:t("./create"),clone:t("./clone"),angle:t("./angle"),fromValues:t("./fromValues"),copy:t("./copy"),set:t("./set"),equals:t("./equals"),exactEquals:t("./exactEquals"),add:t("./add"),subtract:t("./subtract"),sub:t("./sub"),multiply:t("./multiply"),mul:t("./mul"),divide:t("./divide"),div:t("./div"),min:t("./min"),max:t("./max"),floor:t("./floor"),ceil:t("./ceil"),round:t("./round"),scale:t("./scale"),scaleAndAdd:t("./scaleAndAdd"),distance:t("./distance"),dist:t("./dist"),squaredDistance:t("./squaredDistance"),sqrDist:t("./sqrDist"),length:t("./length"),len:t("./len"),squaredLength:t("./squaredLength"),sqrLen:t("./sqrLen"),negate:t("./negate"),inverse:t("./inverse"),normalize:t("./normalize"),dot:t("./dot"),cross:t("./cross"),lerp:t("./lerp"),random:t("./random"),transformMat4:t("./transformMat4"),transformMat3:t("./transformMat3"),transformQuat:t("./transformQuat"),rotateX:t("./rotateX"),rotateY:t("./rotateY"),rotateZ:t("./rotateZ"),forEach:t("./forEach")}},{"./add":151,"./angle":152,"./ceil":153,"./clone":154,"./copy":155,"./create":156,"./cross":157,"./dist":158,"./distance":159,"./div":160,"./divide":161,"./dot":162,"./epsilon":163,"./equals":164,"./exactEquals":165,"./floor":166,"./forEach":167,"./fromValues":168,"./inverse":170,"./len":171,"./length":172,"./lerp":173,"./max":174,"./min":175,"./mul":176,"./multiply":177,"./negate":178,"./normalize":179,"./random":180,"./rotateX":181,"./rotateY":182,"./rotateZ":183,"./round":184,"./scale":185,"./scaleAndAdd":186,"./set":187,"./sqrDist":188,"./sqrLen":189,"./squaredDistance":190,"./squaredLength":191,"./sub":192,"./subtract":193,"./transformMat3":194,"./transformMat4":195,"./transformQuat":196}],170:[function(t,e,r){e.exports=function(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}},{}],171:[function(t,e,r){e.exports=t("./length")},{"./length":172}],172:[function(t,e,r){e.exports=function(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}},{}],173:[function(t,e,r){e.exports=function(t,e,r,n){var i=e[0],a=e[1],o=e[2];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t}},{}],174:[function(t,e,r){e.exports=function(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t}},{}],175:[function(t,e,r){e.exports=function(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t}},{}],176:[function(t,e,r){e.exports=t("./multiply")},{"./multiply":177}],177:[function(t,e,r){e.exports=function(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}},{}],178:[function(t,e,r){e.exports=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}},{}],179:[function(t,e,r){e.exports=function(t,e){var r=e[0],n=e[1],i=e[2],a=r*r+n*n+i*i;a>0&&(a=1/Math.sqrt(a),t[0]=e[0]*a,t[1]=e[1]*a,t[2]=e[2]*a);return t}},{}],180:[function(t,e,r){e.exports=function(t,e){e=e||1;var r=2*Math.random()*Math.PI,n=2*Math.random()-1,i=Math.sqrt(1-n*n)*e;return t[0]=Math.cos(r)*i,t[1]=Math.sin(r)*i,t[2]=n*e,t}},{}],181:[function(t,e,r){e.exports=function(t,e,r,n){var i=r[1],a=r[2],o=e[1]-i,s=e[2]-a,l=Math.sin(n),c=Math.cos(n);return t[0]=e[0],t[1]=i+o*c-s*l,t[2]=a+o*l+s*c,t}},{}],182:[function(t,e,r){e.exports=function(t,e,r,n){var i=r[0],a=r[2],o=e[0]-i,s=e[2]-a,l=Math.sin(n),c=Math.cos(n);return t[0]=i+s*l+o*c,t[1]=e[1],t[2]=a+s*c-o*l,t}},{}],183:[function(t,e,r){e.exports=function(t,e,r,n){var i=r[0],a=r[1],o=e[0]-i,s=e[1]-a,l=Math.sin(n),c=Math.cos(n);return t[0]=i+o*c-s*l,t[1]=a+o*l+s*c,t[2]=e[2],t}},{}],184:[function(t,e,r){e.exports=function(t,e){return t[0]=Math.round(e[0]),t[1]=Math.round(e[1]),t[2]=Math.round(e[2]),t}},{}],185:[function(t,e,r){e.exports=function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}},{}],186:[function(t,e,r){e.exports=function(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t}},{}],187:[function(t,e,r){e.exports=function(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}},{}],188:[function(t,e,r){e.exports=t("./squaredDistance")},{"./squaredDistance":190}],189:[function(t,e,r){e.exports=t("./squaredLength")},{"./squaredLength":191}],190:[function(t,e,r){e.exports=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return r*r+n*n+i*i}},{}],191:[function(t,e,r){e.exports=function(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}},{}],192:[function(t,e,r){e.exports=t("./subtract")},{"./subtract":193}],193:[function(t,e,r){e.exports=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}},{}],194:[function(t,e,r){e.exports=function(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=n*r[0]+i*r[3]+a*r[6],t[1]=n*r[1]+i*r[4]+a*r[7],t[2]=n*r[2]+i*r[5]+a*r[8],t}},{}],195:[function(t,e,r){e.exports=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[3]*n+r[7]*i+r[11]*a+r[15];return o=o||1,t[0]=(r[0]*n+r[4]*i+r[8]*a+r[12])/o,t[1]=(r[1]*n+r[5]*i+r[9]*a+r[13])/o,t[2]=(r[2]*n+r[6]*i+r[10]*a+r[14])/o,t}},{}],196:[function(t,e,r){e.exports=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],l=r[2],c=r[3],u=c*n+s*a-l*i,f=c*i+l*n-o*a,h=c*a+o*i-s*n,p=-o*n-s*i-l*a;return t[0]=u*c+p*-o+f*-l-h*-s,t[1]=f*c+p*-s+h*-o-u*-l,t[2]=h*c+p*-l+u*-s-f*-o,t}},{}],197:[function(t,e,r){e.exports=function(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t}},{}],198:[function(t,e,r){e.exports=function(t){var e=new Float32Array(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}},{}],199:[function(t,e,r){e.exports=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t}},{}],200:[function(t,e,r){e.exports=function(){var t=new Float32Array(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t}},{}],201:[function(t,e,r){e.exports=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return Math.sqrt(r*r+n*n+i*i+a*a)}},{}],202:[function(t,e,r){e.exports=function(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t[3]=e[3]/r[3],t}},{}],203:[function(t,e,r){e.exports=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}},{}],204:[function(t,e,r){e.exports=function(t,e,r,n){var i=new Float32Array(4);return i[0]=t,i[1]=e,i[2]=r,i[3]=n,i}},{}],205:[function(t,e,r){e.exports={create:t("./create"),clone:t("./clone"),fromValues:t("./fromValues"),copy:t("./copy"),set:t("./set"),add:t("./add"),subtract:t("./subtract"),multiply:t("./multiply"),divide:t("./divide"),min:t("./min"),max:t("./max"),scale:t("./scale"),scaleAndAdd:t("./scaleAndAdd"),distance:t("./distance"),squaredDistance:t("./squaredDistance"),length:t("./length"),squaredLength:t("./squaredLength"),negate:t("./negate"),inverse:t("./inverse"),normalize:t("./normalize"),dot:t("./dot"),lerp:t("./lerp"),random:t("./random"),transformMat4:t("./transformMat4"),transformQuat:t("./transformQuat")}},{"./add":197,"./clone":198,"./copy":199,"./create":200,"./distance":201,"./divide":202,"./dot":203,"./fromValues":204,"./inverse":206,"./length":207,"./lerp":208,"./max":209,"./min":210,"./multiply":211,"./negate":212,"./normalize":213,"./random":214,"./scale":215,"./scaleAndAdd":216,"./set":217,"./squaredDistance":218,"./squaredLength":219,"./subtract":220,"./transformMat4":221,"./transformQuat":222}],206:[function(t,e,r){e.exports=function(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t[3]=1/e[3],t}},{}],207:[function(t,e,r){e.exports=function(t){var e=t[0],r=t[1],n=t[2],i=t[3];return Math.sqrt(e*e+r*r+n*n+i*i)}},{}],208:[function(t,e,r){e.exports=function(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=e[3];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t[3]=s+n*(r[3]-s),t}},{}],209:[function(t,e,r){e.exports=function(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t[3]=Math.max(e[3],r[3]),t}},{}],210:[function(t,e,r){e.exports=function(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t[3]=Math.min(e[3],r[3]),t}},{}],211:[function(t,e,r){e.exports=function(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t[3]=e[3]*r[3],t}},{}],212:[function(t,e,r){e.exports=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t}},{}],213:[function(t,e,r){e.exports=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a;o>0&&(o=1/Math.sqrt(o),t[0]=r*o,t[1]=n*o,t[2]=i*o,t[3]=a*o);return t}},{}],214:[function(t,e,r){var n=t("./normalize"),i=t("./scale");e.exports=function(t,e){return e=e||1,t[0]=Math.random(),t[1]=Math.random(),t[2]=Math.random(),t[3]=Math.random(),n(t,t),i(t,t,e),t}},{"./normalize":213,"./scale":215}],215:[function(t,e,r){e.exports=function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t}},{}],216:[function(t,e,r){e.exports=function(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t}},{}],217:[function(t,e,r){e.exports=function(t,e,r,n,i){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t}},{}],218:[function(t,e,r){e.exports=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return r*r+n*n+i*i+a*a}},{}],219:[function(t,e,r){e.exports=function(t){var e=t[0],r=t[1],n=t[2],i=t[3];return e*e+r*r+n*n+i*i}},{}],220:[function(t,e,r){e.exports=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t}},{}],221:[function(t,e,r){e.exports=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12]*o,t[1]=r[1]*n+r[5]*i+r[9]*a+r[13]*o,t[2]=r[2]*n+r[6]*i+r[10]*a+r[14]*o,t[3]=r[3]*n+r[7]*i+r[11]*a+r[15]*o,t}},{}],222:[function(t,e,r){e.exports=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],l=r[2],c=r[3],u=c*n+s*a-l*i,f=c*i+l*n-o*a,h=c*a+o*i-s*n,p=-o*n-s*i-l*a;return t[0]=u*c+p*-o+f*-l-h*-s,t[1]=f*c+p*-s+h*-o-u*-l,t[2]=h*c+p*-l+u*-s-f*-o,t[3]=e[3],t}},{}],223:[function(t,e,r){var n=t("glsl-tokenizer"),i=t("atob-lite");e.exports=function(t){for(var e=Array.isArray(t)?t:n(t),r=0;r<e.length;r++){var a=e[r];if("preprocessor"===a.type){var o=a.data.match(/\#define\s+SHADER_NAME(_B64)?\s+(.+)$/);if(o&&o[2]){var s=o[1],l=o[2];return(s?i(l):l).trim()}}}}},{"atob-lite":13,"glsl-tokenizer":230}],224:[function(t,e,r){e.exports=function(t){var e,r,c,u=0,f=0,h=999,p=[],d=[],m=1,g=0,v=0,y=!1,x=!1,b="",_=a,w=n;"300 es"===(t=t||{}).version&&(_=s,w=o);var T={},k={};for(u=0;u<_.length;u++)T[_[u]]=!0;for(u=0;u<w.length;u++)k[w[u]]=!0;return function(t){return d=[],null!==t?function(t){u=0,t.toString&&(t=t.toString());var r;b+=t.replace(/\r\n/g,"\n"),c=b.length;for(;e=b[u],u<c;){switch(r=u,h){case 0:u=L();break;case 1:case 2:u=E();break;case 3:u=C();break;case 4:u=O();break;case 11:u=I();break;case 5:u=z();break;case 9999:u=D();break;case 9:u=S();break;case 999:u=M()}if(r!==u)switch(b[r]){case"\n":g=0,++m;break;default:++g}}return f+=u,b=b.slice(u),d}(t):function(t){p.length&&A(p.join(""));return h=10,A("(eof)"),d}()};function A(t){t.length&&d.push({type:l[h],data:t,position:v,line:m,column:g})}function M(){return p=p.length?[]:p,"/"===r&&"*"===e?(v=f+u-1,h=0,r=e,u+1):"/"===r&&"/"===e?(v=f+u-1,h=1,r=e,u+1):"#"===e?(h=2,v=f+u,u):/\s/.test(e)?(h=9,v=f+u,u):(y=/\d/.test(e),x=/[^\w_]/.test(e),v=f+u,h=y?4:x?3:9999,u)}function S(){return/[^\s]/g.test(e)?(A(p.join("")),h=999,u):(p.push(e),r=e,u+1)}function E(){return"\r"!==e&&"\n"!==e||"\\"===r?(p.push(e),r=e,u+1):(A(p.join("")),h=999,u)}function L(){return"/"===e&&"*"===r?(p.push(e),A(p.join("")),h=999,u+1):(p.push(e),r=e,u+1)}function C(){if("."===r&&/\d/.test(e))return h=5,u;if("/"===r&&"*"===e)return h=0,u;if("/"===r&&"/"===e)return h=1,u;if("."===e&&p.length){for(;P(p););return h=5,u}if(";"===e||")"===e||"("===e){if(p.length)for(;P(p););return A(e),h=999,u+1}var t=2===p.length&&"="!==e;if(/[\w_\d\s]/.test(e)||t){for(;P(p););return h=999,u}return p.push(e),r=e,u+1}function P(t){for(var e,r,n=0;;){if(e=i.indexOf(t.slice(0,t.length+n).join("")),r=i[e],-1===e){if(n--+t.length>0)continue;r=t.slice(0,1).join("")}return A(r),v+=r.length,(p=p.slice(r.length)).length}}function I(){return/[^a-fA-F0-9]/.test(e)?(A(p.join("")),h=999,u):(p.push(e),r=e,u+1)}function O(){return"."===e||/[eE]/.test(e)?(p.push(e),h=5,r=e,u+1):"x"===e&&1===p.length&&"0"===p[0]?(h=11,p.push(e),r=e,u+1):/[^\d]/.test(e)?(A(p.join("")),h=999,u):(p.push(e),r=e,u+1)}function z(){return"f"===e&&(p.push(e),r=e,u+=1),/[eE]/.test(e)?(p.push(e),r=e,u+1):("-"!==e&&"+"!==e||!/[eE]/.test(r))&&/[^\d]/.test(e)?(A(p.join("")),h=999,u):(p.push(e),r=e,u+1)}function D(){if(/[^\d\w_]/.test(e)){var t=p.join("");return h=k[t]?8:T[t]?7:6,A(p.join("")),h=999,u}return p.push(e),r=e,u+1}};var n=t("./lib/literals"),i=t("./lib/operators"),a=t("./lib/builtins"),o=t("./lib/literals-300es"),s=t("./lib/builtins-300es"),l=["block-comment","line-comment","preprocessor","operator","integer","float","ident","builtin","keyword","whitespace","eof","integer"]},{"./lib/builtins":226,"./lib/builtins-300es":225,"./lib/literals":228,"./lib/literals-300es":227,"./lib/operators":229}],225:[function(t,e,r){var n=t("./builtins");n=n.slice().filter((function(t){return!/^(gl\_|texture)/.test(t)})),e.exports=n.concat(["gl_VertexID","gl_InstanceID","gl_Position","gl_PointSize","gl_FragCoord","gl_FrontFacing","gl_FragDepth","gl_PointCoord","gl_MaxVertexAttribs","gl_MaxVertexUniformVectors","gl_MaxVertexOutputVectors","gl_MaxFragmentInputVectors","gl_MaxVertexTextureImageUnits","gl_MaxCombinedTextureImageUnits","gl_MaxTextureImageUnits","gl_MaxFragmentUniformVectors","gl_MaxDrawBuffers","gl_MinProgramTexelOffset","gl_MaxProgramTexelOffset","gl_DepthRangeParameters","gl_DepthRange","trunc","round","roundEven","isnan","isinf","floatBitsToInt","floatBitsToUint","intBitsToFloat","uintBitsToFloat","packSnorm2x16","unpackSnorm2x16","packUnorm2x16","unpackUnorm2x16","packHalf2x16","unpackHalf2x16","outerProduct","transpose","determinant","inverse","texture","textureSize","textureProj","textureLod","textureOffset","texelFetch","texelFetchOffset","textureProjOffset","textureLodOffset","textureProjLod","textureProjLodOffset","textureGrad","textureGradOffset","textureProjGrad","textureProjGradOffset"])},{"./builtins":226}],226:[function(t,e,r){e.exports=["abs","acos","all","any","asin","atan","ceil","clamp","cos","cross","dFdx","dFdy","degrees","distance","dot","equal","exp","exp2","faceforward","floor","fract","gl_BackColor","gl_BackLightModelProduct","gl_BackLightProduct","gl_BackMaterial","gl_BackSecondaryColor","gl_ClipPlane","gl_ClipVertex","gl_Color","gl_DepthRange","gl_DepthRangeParameters","gl_EyePlaneQ","gl_EyePlaneR","gl_EyePlaneS","gl_EyePlaneT","gl_Fog","gl_FogCoord","gl_FogFragCoord","gl_FogParameters","gl_FragColor","gl_FragCoord","gl_FragData","gl_FragDepth","gl_FragDepthEXT","gl_FrontColor","gl_FrontFacing","gl_FrontLightModelProduct","gl_FrontLightProduct","gl_FrontMaterial","gl_FrontSecondaryColor","gl_LightModel","gl_LightModelParameters","gl_LightModelProducts","gl_LightProducts","gl_LightSource","gl_LightSourceParameters","gl_MaterialParameters","gl_MaxClipPlanes","gl_MaxCombinedTextureImageUnits","gl_MaxDrawBuffers","gl_MaxFragmentUniformComponents","gl_MaxLights","gl_MaxTextureCoords","gl_MaxTextureImageUnits","gl_MaxTextureUnits","gl_MaxVaryingFloats","gl_MaxVertexAttribs","gl_MaxVertexTextureImageUnits","gl_MaxVertexUniformComponents","gl_ModelViewMatrix","gl_ModelViewMatrixInverse","gl_ModelViewMatrixInverseTranspose","gl_ModelViewMatrixTranspose","gl_ModelViewProjectionMatrix","gl_ModelViewProjectionMatrixInverse","gl_ModelViewProjectionMatrixInverseTranspose","gl_ModelViewProjectionMatrixTranspose","gl_MultiTexCoord0","gl_MultiTexCoord1","gl_MultiTexCoord2","gl_MultiTexCoord3","gl_MultiTexCoord4","gl_MultiTexCoord5","gl_MultiTexCoord6","gl_MultiTexCoord7","gl_Normal","gl_NormalMatrix","gl_NormalScale","gl_ObjectPlaneQ","gl_ObjectPlaneR","gl_ObjectPlaneS","gl_ObjectPlaneT","gl_Point","gl_PointCoord","gl_PointParameters","gl_PointSize","gl_Position","gl_ProjectionMatrix","gl_ProjectionMatrixInverse","gl_ProjectionMatrixInverseTranspose","gl_ProjectionMatrixTranspose","gl_SecondaryColor","gl_TexCoord","gl_TextureEnvColor","gl_TextureMatrix","gl_TextureMatrixInverse","gl_TextureMatrixInverseTranspose","gl_TextureMatrixTranspose","gl_Vertex","greaterThan","greaterThanEqual","inversesqrt","length","lessThan","lessThanEqual","log","log2","matrixCompMult","max","min","mix","mod","normalize","not","notEqual","pow","radians","reflect","refract","sign","sin","smoothstep","sqrt","step","tan","texture2D","texture2DLod","texture2DProj","texture2DProjLod","textureCube","textureCubeLod","texture2DLodEXT","texture2DProjLodEXT","textureCubeLodEXT","texture2DGradEXT","texture2DProjGradEXT","textureCubeGradEXT"]},{}],227:[function(t,e,r){var n=t("./literals");e.exports=n.slice().concat(["layout","centroid","smooth","case","mat2x2","mat2x3","mat2x4","mat3x2","mat3x3","mat3x4","mat4x2","mat4x3","mat4x4","uvec2","uvec3","uvec4","samplerCubeShadow","sampler2DArray","sampler2DArrayShadow","isampler2D","isampler3D","isamplerCube","isampler2DArray","usampler2D","usampler3D","usamplerCube","usampler2DArray","coherent","restrict","readonly","writeonly","resource","atomic_uint","noperspective","patch","sample","subroutine","common","partition","active","filter","image1D","image2D","image3D","imageCube","iimage1D","iimage2D","iimage3D","iimageCube","uimage1D","uimage2D","uimage3D","uimageCube","image1DArray","image2DArray","iimage1DArray","iimage2DArray","uimage1DArray","uimage2DArray","image1DShadow","image2DShadow","image1DArrayShadow","image2DArrayShadow","imageBuffer","iimageBuffer","uimageBuffer","sampler1DArray","sampler1DArrayShadow","isampler1D","isampler1DArray","usampler1D","usampler1DArray","isampler2DRect","usampler2DRect","samplerBuffer","isamplerBuffer","usamplerBuffer","sampler2DMS","isampler2DMS","usampler2DMS","sampler2DMSArray","isampler2DMSArray","usampler2DMSArray"])},{"./literals":228}],228:[function(t,e,r){e.exports=["precision","highp","mediump","lowp","attribute","const","uniform","varying","break","continue","do","for","while","if","else","in","out","inout","float","int","uint","void","bool","true","false","discard","return","mat2","mat3","mat4","vec2","vec3","vec4","ivec2","ivec3","ivec4","bvec2","bvec3","bvec4","sampler1D","sampler2D","sampler3D","samplerCube","sampler1DShadow","sampler2DShadow","struct","asm","class","union","enum","typedef","template","this","packed","goto","switch","default","inline","noinline","volatile","public","static","extern","external","interface","long","short","double","half","fixed","unsigned","input","output","hvec2","hvec3","hvec4","dvec2","dvec3","dvec4","fvec2","fvec3","fvec4","sampler2DRect","sampler3DRect","sampler2DRectShadow","sizeof","cast","namespace","using"]},{}],229:[function(t,e,r){e.exports=["<<=",">>=","++","--","<<",">>","<=",">=","==","!=","&&","||","+=","-=","*=","/=","%=","&=","^^","^=","|=","(",")","[","]",".","!","~","*","/","%","+","-","<",">","&","^","|","?",":","=",",",";","{","}"]},{}],230:[function(t,e,r){var n=t("./index");e.exports=function(t,e){var r=n(e),i=[];return i=(i=i.concat(r(t))).concat(r(null))}},{"./index":224}],231:[function(t,e,r){e.exports=function(t){"string"==typeof t&&(t=[t]);for(var e=[].slice.call(arguments,1),r=[],n=0;n<t.length-1;n++)r.push(t[n],e[n]||"");return r.push(t[n]),r.join("")}},{}],232:[function(t,e,r){"use strict";var n=t("is-browser");e.exports=n&&function(){var t=!1;try{var e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("test",null,e),window.removeEventListener("test",null,e)}catch(e){t=!1}return t}()},{"is-browser":236}],233:[function(t,e,r){"use strict";e.exports=function(t,e){var r=t.length;if(0===r)throw new Error("Must have at least d+1 points");var i=t[0].length;if(r<=i)throw new Error("Must input at least d+1 points");var o=t.slice(0,i+1),s=n.apply(void 0,o);if(0===s)throw new Error("Input not in general position");for(var l=new Array(i+1),u=0;u<=i;++u)l[u]=u;s<0&&(l[0]=1,l[1]=0);var f=new a(l,new Array(i+1),!1),h=f.adjacent,p=new Array(i+2);for(u=0;u<=i;++u){for(var d=l.slice(),m=0;m<=i;++m)m===u&&(d[m]=-1);var g=d[0];d[0]=d[1],d[1]=g;var v=new a(d,new Array(i+1),!0);h[u]=v,p[u]=v}p[i+1]=f;for(u=0;u<=i;++u){d=h[u].vertices;var y=h[u].adjacent;for(m=0;m<=i;++m){var x=d[m];if(x<0)y[m]=f;else for(var b=0;b<=i;++b)h[b].vertices.indexOf(x)<0&&(y[m]=h[b])}}var _=new c(i,o,p),w=!!e;for(u=i+1;u<r;++u)_.insert(t[u],w);return _.boundary()};var n=t("robust-orientation"),i=t("simplicial-complex").compareCells;function a(t,e,r){this.vertices=t,this.adjacent=e,this.boundary=r,this.lastVisited=-1}function o(t,e,r){this.vertices=t,this.cell=e,this.index=r}function s(t,e){return i(t.vertices,e.vertices)}a.prototype.flip=function(){var t=this.vertices[0];this.vertices[0]=this.vertices[1],this.vertices[1]=t;var e=this.adjacent[0];this.adjacent[0]=this.adjacent[1],this.adjacent[1]=e};var l=[];function c(t,e,r){this.dimension=t,this.vertices=e,this.simplices=r,this.interior=r.filter((function(t){return!t.boundary})),this.tuple=new Array(t+1);for(var i=0;i<=t;++i)this.tuple[i]=this.vertices[i];var a,o=l[t];o||(o=l[t]=((a=n[t+1])||(a=n),function(t){return function(){var e=this.tuple;return t.apply(this,e)}}(a))),this.orient=o}var u=c.prototype;u.handleBoundaryDegeneracy=function(t,e){var r=this.dimension,n=this.vertices.length-1,i=this.tuple,a=this.vertices,o=[t];for(t.lastVisited=-n;o.length>0;)for(var s=(t=o.pop()).adjacent,l=0;l<=r;++l){var c=s[l];if(c.boundary&&!(c.lastVisited<=-n)){for(var u=c.vertices,f=0;f<=r;++f){var h=u[f];i[f]=h<0?e:a[h]}var p=this.orient();if(p>0)return c;c.lastVisited=-n,0===p&&o.push(c)}}return null},u.walk=function(t,e){var r=this.vertices.length-1,n=this.dimension,i=this.vertices,a=this.tuple,o=e?this.interior.length*Math.random()|0:this.interior.length-1,s=this.interior[o];t:for(;!s.boundary;){for(var l=s.vertices,c=s.adjacent,u=0;u<=n;++u)a[u]=i[l[u]];s.lastVisited=r;for(u=0;u<=n;++u){var f=c[u];if(!(f.lastVisited>=r)){var h=a[u];a[u]=t;var p=this.orient();if(a[u]=h,p<0){s=f;continue t}f.boundary?f.lastVisited=-r:f.lastVisited=r}}return}return s},u.addPeaks=function(t,e){var r=this.vertices.length-1,n=this.dimension,i=this.vertices,l=this.tuple,c=this.interior,u=this.simplices,f=[e];e.lastVisited=r,e.vertices[e.vertices.indexOf(-1)]=r,e.boundary=!1,c.push(e);for(var h=[];f.length>0;){var p=(e=f.pop()).vertices,d=e.adjacent,m=p.indexOf(r);if(!(m<0))for(var g=0;g<=n;++g)if(g!==m){var v=d[g];if(v.boundary&&!(v.lastVisited>=r)){var y=v.vertices;if(v.lastVisited!==-r){for(var x=0,b=0;b<=n;++b)y[b]<0?(x=b,l[b]=t):l[b]=i[y[b]];if(this.orient()>0){y[x]=r,v.boundary=!1,c.push(v),f.push(v),v.lastVisited=r;continue}v.lastVisited=-r}var _=v.adjacent,w=p.slice(),T=d.slice(),k=new a(w,T,!0);u.push(k);var A=_.indexOf(e);if(!(A<0)){_[A]=k,T[m]=v,w[g]=-1,T[g]=e,d[g]=k,k.flip();for(b=0;b<=n;++b){var M=w[b];if(!(M<0||M===r)){for(var S=new Array(n-1),E=0,L=0;L<=n;++L){var C=w[L];C<0||L===b||(S[E++]=C)}h.push(new o(S,k,b))}}}}}}h.sort(s);for(g=0;g+1<h.length;g+=2){var P=h[g],I=h[g+1],O=P.index,z=I.index;O<0||z<0||(P.cell.adjacent[P.index]=I.cell,I.cell.adjacent[I.index]=P.cell)}},u.insert=function(t,e){var r=this.vertices;r.push(t);var n=this.walk(t,e);if(n){for(var i=this.dimension,a=this.tuple,o=0;o<=i;++o){var s=n.vertices[o];a[o]=s<0?t:r[s]}var l=this.orient(a);l<0||(0!==l||(n=this.handleBoundaryDegeneracy(n,t)))&&this.addPeaks(t,n)}},u.boundary=function(){for(var t=this.dimension,e=[],r=this.simplices,n=r.length,i=0;i<n;++i){var a=r[i];if(a.boundary){for(var o=new Array(t),s=a.vertices,l=0,c=0,u=0;u<=t;++u)s[u]>=0?o[l++]=s[u]:c=1&u;if(c===(1&t)){var f=o[0];o[0]=o[1],o[1]=f}e.push(o)}}return e}},{"robust-orientation":284,"simplicial-complex":293}],234:[function(t,e,r){"use strict";var n=t("binary-search-bounds");function i(t,e,r,n,i){this.mid=t,this.left=e,this.right=r,this.leftPoints=n,this.rightPoints=i,this.count=(e?e.count:0)+(r?r.count:0)+n.length}e.exports=function(t){if(!t||0===t.length)return new v(null);return new v(g(t))};var a=i.prototype;function o(t,e){t.mid=e.mid,t.left=e.left,t.right=e.right,t.leftPoints=e.leftPoints,t.rightPoints=e.rightPoints,t.count=e.count}function s(t,e){var r=g(e);t.mid=r.mid,t.left=r.left,t.right=r.right,t.leftPoints=r.leftPoints,t.rightPoints=r.rightPoints,t.count=r.count}function l(t,e){var r=t.intervals([]);r.push(e),s(t,r)}function c(t,e){var r=t.intervals([]),n=r.indexOf(e);return n<0?0:(r.splice(n,1),s(t,r),1)}function u(t,e,r){for(var n=0;n<t.length&&t[n][0]<=e;++n){var i=r(t[n]);if(i)return i}}function f(t,e,r){for(var n=t.length-1;n>=0&&t[n][1]>=e;--n){var i=r(t[n]);if(i)return i}}function h(t,e){for(var r=0;r<t.length;++r){var n=e(t[r]);if(n)return n}}function p(t,e){return t-e}function d(t,e){var r=t[0]-e[0];return r||t[1]-e[1]}function m(t,e){var r=t[1]-e[1];return r||t[0]-e[0]}function g(t){if(0===t.length)return null;for(var e=[],r=0;r<t.length;++r)e.push(t[r][0],t[r][1]);e.sort(p);var n=e[e.length>>1],a=[],o=[],s=[];for(r=0;r<t.length;++r){var l=t[r];l[1]<n?a.push(l):n<l[0]?o.push(l):s.push(l)}var c=s,u=s.slice();return c.sort(d),u.sort(m),new i(n,g(a),g(o),c,u)}function v(t){this.root=t}a.intervals=function(t){return t.push.apply(t,this.leftPoints),this.left&&this.left.intervals(t),this.right&&this.right.intervals(t),t},a.insert=function(t){var e=this.count-this.leftPoints.length;if(this.count+=1,t[1]<this.mid)this.left?4*(this.left.count+1)>3*(e+1)?l(this,t):this.left.insert(t):this.left=g([t]);else if(t[0]>this.mid)this.right?4*(this.right.count+1)>3*(e+1)?l(this,t):this.right.insert(t):this.right=g([t]);else{var r=n.ge(this.leftPoints,t,d),i=n.ge(this.rightPoints,t,m);this.leftPoints.splice(r,0,t),this.rightPoints.splice(i,0,t)}},a.remove=function(t){var e=this.count-this.leftPoints;if(t[1]<this.mid)return this.left?4*(this.right?this.right.count:0)>3*(e-1)?c(this,t):2===(s=this.left.remove(t))?(this.left=null,this.count-=1,1):(1===s&&(this.count-=1),s):0;if(t[0]>this.mid)return this.right?4*(this.left?this.left.count:0)>3*(e-1)?c(this,t):2===(s=this.right.remove(t))?(this.right=null,this.count-=1,1):(1===s&&(this.count-=1),s):0;if(1===this.count)return this.leftPoints[0]===t?2:0;if(1===this.leftPoints.length&&this.leftPoints[0]===t){if(this.left&&this.right){for(var r=this,i=this.left;i.right;)r=i,i=i.right;if(r===this)i.right=this.right;else{var a=this.left,s=this.right;r.count-=i.count,r.right=i.left,i.left=a,i.right=s}o(this,i),this.count=(this.left?this.left.count:0)+(this.right?this.right.count:0)+this.leftPoints.length}else this.left?o(this,this.left):o(this,this.right);return 1}for(a=n.ge(this.leftPoints,t,d);a<this.leftPoints.length&&this.leftPoints[a][0]===t[0];++a)if(this.leftPoints[a]===t){this.count-=1,this.leftPoints.splice(a,1);for(s=n.ge(this.rightPoints,t,m);s<this.rightPoints.length&&this.rightPoints[s][1]===t[1];++s)if(this.rightPoints[s]===t)return this.rightPoints.splice(s,1),1}return 0},a.queryPoint=function(t,e){if(t<this.mid){if(this.left)if(r=this.left.queryPoint(t,e))return r;return u(this.leftPoints,t,e)}if(t>this.mid){var r;if(this.right)if(r=this.right.queryPoint(t,e))return r;return f(this.rightPoints,t,e)}return h(this.leftPoints,e)},a.queryInterval=function(t,e,r){var n;if(t<this.mid&&this.left&&(n=this.left.queryInterval(t,e,r)))return n;if(e>this.mid&&this.right&&(n=this.right.queryInterval(t,e,r)))return n;return e<this.mid?u(this.leftPoints,e,r):t>this.mid?f(this.rightPoints,t,r):h(this.leftPoints,r)};var y=v.prototype;y.insert=function(t){this.root?this.root.insert(t):this.root=new i(t[0],null,null,[t],[t])},y.remove=function(t){if(this.root){var e=this.root.remove(t);return 2===e&&(this.root=null),0!==e}return!1},y.queryPoint=function(t,e){if(this.root)return this.root.queryPoint(t,e)},y.queryInterval=function(t,e,r){if(t<=e&&this.root)return this.root.queryInterval(t,e,r)},Object.defineProperty(y,"count",{get:function(){return this.root?this.root.count:0}}),Object.defineProperty(y,"intervals",{get:function(){return this.root?this.root.intervals([]):[]}})},{"binary-search-bounds":31}],235:[function(t,e,r){"use strict";e.exports=function(t){for(var e=new Array(t),r=0;r<t;++r)e[r]=r;return e}},{}],236:[function(t,e,r){e.exports=!0},{}],237:[function(t,e,r){function n(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}
/*!
 * Determine if an object is a Buffer
 *
 * @author   Feross Aboukhadijeh <https://feross.org>
 * @license  MIT
 */
e.exports=function(t){return null!=t&&(n(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&n(t.slice(0,0))}(t)||!!t._isBuffer)}},{}],238:[function(t,e,r){"use strict";e.exports=a,e.exports.isMobile=a,e.exports.default=a;var n=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series[46]0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i,i=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series[46]0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|android|ipad|playbook|silk/i;function a(t){t||(t={});var e=t.ua;if(e||"undefined"==typeof navigator||(e=navigator.userAgent),e&&e.headers&&"string"==typeof e.headers["user-agent"]&&(e=e.headers["user-agent"]),"string"!=typeof e)return!1;var r=t.tablet?i.test(e):n.test(e);return!r&&t.tablet&&t.featureDetect&&navigator&&navigator.maxTouchPoints>1&&-1!==e.indexOf("Macintosh")&&-1!==e.indexOf("Safari")&&(r=!0),r}},{}],239:[function(t,e,r){"use strict";e.exports=function(t){for(var e,r=t.length,n=0;n<r;n++)if(((e=t.charCodeAt(n))<9||e>13)&&32!==e&&133!==e&&160!==e&&5760!==e&&6158!==e&&(e<8192||e>8205)&&8232!==e&&8233!==e&&8239!==e&&8287!==e&&8288!==e&&12288!==e&&65279!==e)return!1;return!0}},{}],240:[function(t,e,r){e.exports=function(t,e,r){return t*(1-r)+e*r}},{}],241:[function(t,e,r){var n=t("./normalize"),i=t("gl-mat4/create"),a=t("gl-mat4/clone"),o=t("gl-mat4/determinant"),s=t("gl-mat4/invert"),l=t("gl-mat4/transpose"),c={length:t("gl-vec3/length"),normalize:t("gl-vec3/normalize"),dot:t("gl-vec3/dot"),cross:t("gl-vec3/cross")},u=i(),f=i(),h=[0,0,0,0],p=[[0,0,0],[0,0,0],[0,0,0]],d=[0,0,0];function m(t,e,r,n,i){t[0]=e[0]*n+r[0]*i,t[1]=e[1]*n+r[1]*i,t[2]=e[2]*n+r[2]*i}e.exports=function(t,e,r,i,g,v){if(e||(e=[0,0,0]),r||(r=[0,0,0]),i||(i=[0,0,0]),g||(g=[0,0,0,1]),v||(v=[0,0,0,1]),!n(u,t))return!1;if(a(f,u),f[3]=0,f[7]=0,f[11]=0,f[15]=1,Math.abs(o(f)<1e-8))return!1;var y,x,b,_,w,T,k,A=u[3],M=u[7],S=u[11],E=u[12],L=u[13],C=u[14],P=u[15];if(0!==A||0!==M||0!==S){if(h[0]=A,h[1]=M,h[2]=S,h[3]=P,!s(f,f))return!1;l(f,f),y=g,b=f,_=(x=h)[0],w=x[1],T=x[2],k=x[3],y[0]=b[0]*_+b[4]*w+b[8]*T+b[12]*k,y[1]=b[1]*_+b[5]*w+b[9]*T+b[13]*k,y[2]=b[2]*_+b[6]*w+b[10]*T+b[14]*k,y[3]=b[3]*_+b[7]*w+b[11]*T+b[15]*k}else g[0]=g[1]=g[2]=0,g[3]=1;if(e[0]=E,e[1]=L,e[2]=C,function(t,e){t[0][0]=e[0],t[0][1]=e[1],t[0][2]=e[2],t[1][0]=e[4],t[1][1]=e[5],t[1][2]=e[6],t[2][0]=e[8],t[2][1]=e[9],t[2][2]=e[10]}(p,u),r[0]=c.length(p[0]),c.normalize(p[0],p[0]),i[0]=c.dot(p[0],p[1]),m(p[1],p[1],p[0],1,-i[0]),r[1]=c.length(p[1]),c.normalize(p[1],p[1]),i[0]/=r[1],i[1]=c.dot(p[0],p[2]),m(p[2],p[2],p[0],1,-i[1]),i[2]=c.dot(p[1],p[2]),m(p[2],p[2],p[1],1,-i[2]),r[2]=c.length(p[2]),c.normalize(p[2],p[2]),i[1]/=r[2],i[2]/=r[2],c.cross(d,p[1],p[2]),c.dot(p[0],d)<0)for(var I=0;I<3;I++)r[I]*=-1,p[I][0]*=-1,p[I][1]*=-1,p[I][2]*=-1;return v[0]=.5*Math.sqrt(Math.max(1+p[0][0]-p[1][1]-p[2][2],0)),v[1]=.5*Math.sqrt(Math.max(1-p[0][0]+p[1][1]-p[2][2],0)),v[2]=.5*Math.sqrt(Math.max(1-p[0][0]-p[1][1]+p[2][2],0)),v[3]=.5*Math.sqrt(Math.max(1+p[0][0]+p[1][1]+p[2][2],0)),p[2][1]>p[1][2]&&(v[0]=-v[0]),p[0][2]>p[2][0]&&(v[1]=-v[1]),p[1][0]>p[0][1]&&(v[2]=-v[2]),!0}},{"./normalize":242,"gl-mat4/clone":92,"gl-mat4/create":93,"gl-mat4/determinant":94,"gl-mat4/invert":98,"gl-mat4/transpose":109,"gl-vec3/cross":157,"gl-vec3/dot":162,"gl-vec3/length":172,"gl-vec3/normalize":179}],242:[function(t,e,r){e.exports=function(t,e){var r=e[15];if(0===r)return!1;for(var n=1/r,i=0;i<16;i++)t[i]=e[i]*n;return!0}},{}],243:[function(t,e,r){var n=t("gl-vec3/lerp"),i=t("mat4-recompose"),a=t("mat4-decompose"),o=t("gl-mat4/determinant"),s=t("quat-slerp"),l=f(),c=f(),u=f();function f(){return{translate:h(),scale:h(1),skew:h(),perspective:[0,0,0,1],quaternion:[0,0,0,1]}}function h(t){return[t||0,t||0,t||0]}e.exports=function(t,e,r,f){if(0===o(e)||0===o(r))return!1;var h=a(e,l.translate,l.scale,l.skew,l.perspective,l.quaternion),p=a(r,c.translate,c.scale,c.skew,c.perspective,c.quaternion);return!(!h||!p)&&(n(u.translate,l.translate,c.translate,f),n(u.skew,l.skew,c.skew,f),n(u.scale,l.scale,c.scale,f),n(u.perspective,l.perspective,c.perspective,f),s(u.quaternion,l.quaternion,c.quaternion,f),i(t,u.translate,u.scale,u.skew,u.perspective,u.quaternion),!0)}},{"gl-mat4/determinant":94,"gl-vec3/lerp":173,"mat4-decompose":241,"mat4-recompose":244,"quat-slerp":271}],244:[function(t,e,r){var n={identity:t("gl-mat4/identity"),translate:t("gl-mat4/translate"),multiply:t("gl-mat4/multiply"),create:t("gl-mat4/create"),scale:t("gl-mat4/scale"),fromRotationTranslation:t("gl-mat4/fromRotationTranslation")},i=(n.create(),n.create());e.exports=function(t,e,r,a,o,s){return n.identity(t),n.fromRotationTranslation(t,s,e),t[3]=o[0],t[7]=o[1],t[11]=o[2],t[15]=o[3],n.identity(i),0!==a[2]&&(i[9]=a[2],n.multiply(t,t,i)),0!==a[1]&&(i[9]=0,i[8]=a[1],n.multiply(t,t,i)),0!==a[0]&&(i[8]=0,i[4]=a[0],n.multiply(t,t,i)),n.scale(t,t,r),t}},{"gl-mat4/create":93,"gl-mat4/fromRotationTranslation":96,"gl-mat4/identity":97,"gl-mat4/multiply":100,"gl-mat4/scale":107,"gl-mat4/translate":108}],245:[function(t,e,r){"use strict";var n=t("binary-search-bounds"),i=t("mat4-interpolate"),a=t("gl-mat4/invert"),o=t("gl-mat4/rotateX"),s=t("gl-mat4/rotateY"),l=t("gl-mat4/rotateZ"),c=t("gl-mat4/lookAt"),u=t("gl-mat4/translate"),f=(t("gl-mat4/scale"),t("gl-vec3/normalize")),h=[0,0,0];function p(t){this._components=t.slice(),this._time=[0],this.prevMatrix=t.slice(),this.nextMatrix=t.slice(),this.computedMatrix=t.slice(),this.computedInverse=t.slice(),this.computedEye=[0,0,0],this.computedUp=[0,0,0],this.computedCenter=[0,0,0],this.computedRadius=[0],this._limits=[-1/0,1/0]}e.exports=function(t){return new p((t=t||{}).matrix||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])};var d=p.prototype;d.recalcMatrix=function(t){var e=this._time,r=n.le(e,t),o=this.computedMatrix;if(!(r<0)){var s=this._components;if(r===e.length-1)for(var l=16*r,c=0;c<16;++c)o[c]=s[l++];else{var u=e[r+1]-e[r],h=(l=16*r,this.prevMatrix),p=!0;for(c=0;c<16;++c)h[c]=s[l++];var d=this.nextMatrix;for(c=0;c<16;++c)d[c]=s[l++],p=p&&h[c]===d[c];if(u<1e-6||p)for(c=0;c<16;++c)o[c]=h[c];else i(o,h,d,(t-e[r])/u)}var m=this.computedUp;m[0]=o[1],m[1]=o[5],m[2]=o[9],f(m,m);var g=this.computedInverse;a(g,o);var v=this.computedEye,y=g[15];v[0]=g[12]/y,v[1]=g[13]/y,v[2]=g[14]/y;var x=this.computedCenter,b=Math.exp(this.computedRadius[0]);for(c=0;c<3;++c)x[c]=v[c]-o[2+4*c]*b}},d.idle=function(t){if(!(t<this.lastT())){for(var e=this._components,r=e.length-16,n=0;n<16;++n)e.push(e[r++]);this._time.push(t)}},d.flush=function(t){var e=n.gt(this._time,t)-2;e<0||(this._time.splice(0,e),this._components.splice(0,16*e))},d.lastT=function(){return this._time[this._time.length-1]},d.lookAt=function(t,e,r,n){this.recalcMatrix(t),e=e||this.computedEye,r=r||h,n=n||this.computedUp,this.setMatrix(t,c(this.computedMatrix,e,r,n));for(var i=0,a=0;a<3;++a)i+=Math.pow(r[a]-e[a],2);i=Math.log(Math.sqrt(i)),this.computedRadius[0]=i},d.rotate=function(t,e,r,n){this.recalcMatrix(t);var i=this.computedInverse;e&&s(i,i,e),r&&o(i,i,r),n&&l(i,i,n),this.setMatrix(t,a(this.computedMatrix,i))};var m=[0,0,0];d.pan=function(t,e,r,n){m[0]=-(e||0),m[1]=-(r||0),m[2]=-(n||0),this.recalcMatrix(t);var i=this.computedInverse;u(i,i,m),this.setMatrix(t,a(i,i))},d.translate=function(t,e,r,n){m[0]=e||0,m[1]=r||0,m[2]=n||0,this.recalcMatrix(t);var i=this.computedMatrix;u(i,i,m),this.setMatrix(t,i)},d.setMatrix=function(t,e){if(!(t<this.lastT())){this._time.push(t);for(var r=0;r<16;++r)this._components.push(e[r])}},d.setDistance=function(t,e){this.computedRadius[0]=e},d.setDistanceLimits=function(t,e){var r=this._limits;r[0]=t,r[1]=e},d.getDistanceLimits=function(t){var e=this._limits;return t?(t[0]=e[0],t[1]=e[1],t):e}},{"binary-search-bounds":31,"gl-mat4/invert":98,"gl-mat4/lookAt":99,"gl-mat4/rotateX":104,"gl-mat4/rotateY":105,"gl-mat4/rotateZ":106,"gl-mat4/scale":107,"gl-mat4/translate":108,"gl-vec3/normalize":179,"mat4-interpolate":243}],246:[function(t,e,r){"use strict";e.exports=function(t){var e=t.length;if(e<3){for(var r=new Array(e),i=0;i<e;++i)r[i]=i;return 2===e&&t[0][0]===t[1][0]&&t[0][1]===t[1][1]?[0]:r}var a=new Array(e);for(i=0;i<e;++i)a[i]=i;a.sort((function(e,r){var n=t[e][0]-t[r][0];return n||t[e][1]-t[r][1]}));var o=[a[0],a[1]],s=[a[0],a[1]];for(i=2;i<e;++i){for(var l=a[i],c=t[l],u=o.length;u>1&&n(t[o[u-2]],t[o[u-1]],c)<=0;)u-=1,o.pop();for(o.push(l),u=s.length;u>1&&n(t[s[u-2]],t[s[u-1]],c)>=0;)u-=1,s.pop();s.push(l)}r=new Array(s.length+o.length-2);for(var f=0,h=(i=0,o.length);i<h;++i)r[f++]=o[i];for(var p=s.length-2;p>0;--p)r[f++]=s[p];return r};var n=t("robust-orientation")[3]},{"robust-orientation":284}],247:[function(t,e,r){"use strict";e.exports=function(t,e){e||(e=t,t=window);var r=0,i=0,a=0,o={shift:!1,alt:!1,control:!1,meta:!1},s=!1;function l(t){var e=!1;return"altKey"in t&&(e=e||t.altKey!==o.alt,o.alt=!!t.altKey),"shiftKey"in t&&(e=e||t.shiftKey!==o.shift,o.shift=!!t.shiftKey),"ctrlKey"in t&&(e=e||t.ctrlKey!==o.control,o.control=!!t.ctrlKey),"metaKey"in t&&(e=e||t.metaKey!==o.meta,o.meta=!!t.metaKey),e}function c(t,s){var c=n.x(s),u=n.y(s);"buttons"in s&&(t=0|s.buttons),(t!==r||c!==i||u!==a||l(s))&&(r=0|t,i=c||0,a=u||0,e&&e(r,i,a,o))}function u(t){c(0,t)}function f(){(r||i||a||o.shift||o.alt||o.meta||o.control)&&(i=a=0,r=0,o.shift=o.alt=o.control=o.meta=!1,e&&e(0,0,0,o))}function h(t){l(t)&&e&&e(r,i,a,o)}function p(t){0===n.buttons(t)?c(0,t):c(r,t)}function d(t){c(r|n.buttons(t),t)}function m(t){c(r&~n.buttons(t),t)}function g(){s||(s=!0,t.addEventListener("mousemove",p),t.addEventListener("mousedown",d),t.addEventListener("mouseup",m),t.addEventListener("mouseleave",u),t.addEventListener("mouseenter",u),t.addEventListener("mouseout",u),t.addEventListener("mouseover",u),t.addEventListener("blur",f),t.addEventListener("keyup",h),t.addEventListener("keydown",h),t.addEventListener("keypress",h),t!==window&&(window.addEventListener("blur",f),window.addEventListener("keyup",h),window.addEventListener("keydown",h),window.addEventListener("keypress",h)))}g();var v={element:t};return Object.defineProperties(v,{enabled:{get:function(){return s},set:function(e){e?g():function(){if(!s)return;s=!1,t.removeEventListener("mousemove",p),t.removeEventListener("mousedown",d),t.removeEventListener("mouseup",m),t.removeEventListener("mouseleave",u),t.removeEventListener("mouseenter",u),t.removeEventListener("mouseout",u),t.removeEventListener("mouseover",u),t.removeEventListener("blur",f),t.removeEventListener("keyup",h),t.removeEventListener("keydown",h),t.removeEventListener("keypress",h),t!==window&&(window.removeEventListener("blur",f),window.removeEventListener("keyup",h),window.removeEventListener("keydown",h),window.removeEventListener("keypress",h))}()},enumerable:!0},buttons:{get:function(){return r},enumerable:!0},x:{get:function(){return i},enumerable:!0},y:{get:function(){return a},enumerable:!0},mods:{get:function(){return o},enumerable:!0}}),v};var n=t("mouse-event")},{"mouse-event":249}],248:[function(t,e,r){var n={left:0,top:0};e.exports=function(t,e,r){e=e||t.currentTarget||t.srcElement,Array.isArray(r)||(r=[0,0]);var i=t.clientX||0,a=t.clientY||0,o=(s=e,s===window||s===document||s===document.body?n:s.getBoundingClientRect());var s;return r[0]=i-o.left,r[1]=a-o.top,r}},{}],249:[function(t,e,r){"use strict";function n(t){return t.target||t.srcElement||window}r.buttons=function(t){if("object"==typeof t){if("buttons"in t)return t.buttons;if("which"in t){if(2===(e=t.which))return 4;if(3===e)return 2;if(e>0)return 1<<e-1}else if("button"in t){var e;if(1===(e=t.button))return 4;if(2===e)return 2;if(e>=0)return 1<<e}}return 0},r.element=n,r.x=function(t){if("object"==typeof t){if("offsetX"in t)return t.offsetX;var e=n(t).getBoundingClientRect();return t.clientX-e.left}return 0},r.y=function(t){if("object"==typeof t){if("offsetY"in t)return t.offsetY;var e=n(t).getBoundingClientRect();return t.clientY-e.top}return 0}},{}],250:[function(t,e,r){"use strict";var n=t("to-px");e.exports=function(t,e,r){"function"==typeof t&&(r=!!e,e=t,t=window);var i=n("ex",t),a=function(t){r&&t.preventDefault();var n=t.deltaX||0,a=t.deltaY||0,o=t.deltaZ||0,s=1;switch(t.deltaMode){case 1:s=i;break;case 2:s=window.innerHeight}if(a*=s,o*=s,(n*=s)||a||o)return e(n,a,o,t)};return t.addEventListener("wheel",a),a}},{"to-px":304}],251:[function(t,e,r){"use strict";var n=t("typedarray-pool");e.exports=function(t){function e(t){throw new Error("ndarray-extract-contour: "+t)}"object"!=typeof t&&e("Must specify arguments");var r=t.order;Array.isArray(r)||e("Must specify order");var a=t.arrayArguments||1;a<1&&e("Must have at least one array argument");var o=t.scalarArguments||0;o<0&&e("Scalar arg count must be > 0");"function"!=typeof t.vertex&&e("Must specify vertex creation function");"function"!=typeof t.cell&&e("Must specify cell creation function");"function"!=typeof t.phase&&e("Must specify phase function");for(var s=t.getters||[],l=new Array(a),c=0;c<a;++c)s.indexOf(c)>=0?l[c]=!0:l[c]=!1;return function(t,e,r,a,o,s){var l=[s,o].join(",");return(0,i[l])(t,e,r,n.mallocUint32,n.freeUint32)}(t.vertex,t.cell,t.phase,0,r,l)};var i={"false,0,1":function(t,e,r,n,i){return function(a,o,s,l){var c,u=0|a.shape[0],f=0|a.shape[1],h=a.data,p=0|a.offset,d=0|a.stride[0],m=0|a.stride[1],g=p,v=0|-d,y=0,x=0|-m,b=0,_=-d-m|0,w=0,T=0|d,k=m-d*u|0,A=0,M=0,S=0,E=2*u|0,L=n(E),C=n(E),P=0,I=0,O=-1,z=-1,D=0,R=0|-u,F=0|u,B=0,N=-u-1|0,j=u-1|0,U=0,V=0,H=0;for(A=0;A<u;++A)L[P++]=r(h[g],o,s,l),g+=T;if(g+=k,f>0){if(M=1,L[P++]=r(h[g],o,s,l),g+=T,u>0)for(A=1,c=h[g],I=L[P]=r(c,o,s,l),D=L[P+O],B=L[P+R],U=L[P+N],I===D&&I===B&&I===U||(y=h[g+v],b=h[g+x],w=h[g+_],t(A,M,c,y,b,w,I,D,B,U,o,s,l),V=C[P]=S++),P+=1,g+=T,A=2;A<u;++A)c=h[g],I=L[P]=r(c,o,s,l),D=L[P+O],B=L[P+R],U=L[P+N],I===D&&I===B&&I===U||(y=h[g+v],b=h[g+x],w=h[g+_],t(A,M,c,y,b,w,I,D,B,U,o,s,l),V=C[P]=S++,U!==D&&e(C[P+O],V,w,y,U,D,o,s,l)),P+=1,g+=T;for(g+=k,P=0,H=O,O=z,z=H,H=R,R=F,F=H,H=N,N=j,j=H,M=2;M<f;++M){if(L[P++]=r(h[g],o,s,l),g+=T,u>0)for(A=1,c=h[g],I=L[P]=r(c,o,s,l),D=L[P+O],B=L[P+R],U=L[P+N],I===D&&I===B&&I===U||(y=h[g+v],b=h[g+x],w=h[g+_],t(A,M,c,y,b,w,I,D,B,U,o,s,l),V=C[P]=S++,U!==B&&e(C[P+R],V,b,w,B,U,o,s,l)),P+=1,g+=T,A=2;A<u;++A)c=h[g],I=L[P]=r(c,o,s,l),D=L[P+O],B=L[P+R],U=L[P+N],I===D&&I===B&&I===U||(y=h[g+v],b=h[g+x],w=h[g+_],t(A,M,c,y,b,w,I,D,B,U,o,s,l),V=C[P]=S++,U!==B&&e(C[P+R],V,b,w,B,U,o,s,l),U!==D&&e(C[P+O],V,w,y,U,D,o,s,l)),P+=1,g+=T;1&M&&(P=0),H=O,O=z,z=H,H=R,R=F,F=H,H=N,N=j,j=H,g+=k}}i(C),i(L)}},"false,1,0":function(t,e,r,n,i){return function(a,o,s,l){var c,u=0|a.shape[0],f=0|a.shape[1],h=a.data,p=0|a.offset,d=0|a.stride[0],m=0|a.stride[1],g=p,v=0|-d,y=0,x=0|-m,b=0,_=-d-m|0,w=0,T=0|m,k=d-m*f|0,A=0,M=0,S=0,E=2*f|0,L=n(E),C=n(E),P=0,I=0,O=-1,z=-1,D=0,R=0|-f,F=0|f,B=0,N=-f-1|0,j=f-1|0,U=0,V=0,H=0;for(M=0;M<f;++M)L[P++]=r(h[g],o,s,l),g+=T;if(g+=k,u>0){if(A=1,L[P++]=r(h[g],o,s,l),g+=T,f>0)for(M=1,c=h[g],I=L[P]=r(c,o,s,l),B=L[P+R],D=L[P+O],U=L[P+N],I===B&&I===D&&I===U||(y=h[g+v],b=h[g+x],w=h[g+_],t(A,M,c,y,b,w,I,B,D,U,o,s,l),V=C[P]=S++),P+=1,g+=T,M=2;M<f;++M)c=h[g],I=L[P]=r(c,o,s,l),B=L[P+R],D=L[P+O],U=L[P+N],I===B&&I===D&&I===U||(y=h[g+v],b=h[g+x],w=h[g+_],t(A,M,c,y,b,w,I,B,D,U,o,s,l),V=C[P]=S++,U!==D&&e(C[P+O],V,b,w,D,U,o,s,l)),P+=1,g+=T;for(g+=k,P=0,H=R,R=F,F=H,H=O,O=z,z=H,H=N,N=j,j=H,A=2;A<u;++A){if(L[P++]=r(h[g],o,s,l),g+=T,f>0)for(M=1,c=h[g],I=L[P]=r(c,o,s,l),B=L[P+R],D=L[P+O],U=L[P+N],I===B&&I===D&&I===U||(y=h[g+v],b=h[g+x],w=h[g+_],t(A,M,c,y,b,w,I,B,D,U,o,s,l),V=C[P]=S++,U!==B&&e(C[P+R],V,w,y,U,B,o,s,l)),P+=1,g+=T,M=2;M<f;++M)c=h[g],I=L[P]=r(c,o,s,l),B=L[P+R],D=L[P+O],U=L[P+N],I===B&&I===D&&I===U||(y=h[g+v],b=h[g+x],w=h[g+_],t(A,M,c,y,b,w,I,B,D,U,o,s,l),V=C[P]=S++,U!==D&&e(C[P+O],V,b,w,D,U,o,s,l),U!==B&&e(C[P+R],V,w,y,U,B,o,s,l)),P+=1,g+=T;1&A&&(P=0),H=R,R=F,F=H,H=O,O=z,z=H,H=N,N=j,j=H,g+=k}}i(C),i(L)}}}},{"typedarray-pool":308}],252:[function(t,e,r){"use strict";var n=t("dup"),i={zero:function(t,e,r,n){var i=t[0];n|=0;var a=0,o=r[0];for(a=0;a<i;++a)e[n]=0,n+=o},fdTemplate1:function(t,e,r,n,i,a,o){var s=t[0],l=r[0],c=-1*l,u=l;n|=0,o|=0;var f=0,h=l,p=a[0];for(f=0;f<s;++f)i[o]=.5*(e[n+c]-e[n+u]),n+=h,o+=p},fdTemplate2:function(t,e,r,n,i,a,o,s,l,c){var u=t[0],f=t[1],h=r[0],p=r[1],d=a[0],m=a[1],g=l[0],v=l[1],y=-1*h,x=h,b=-1*p,_=p;n|=0,o|=0,c|=0;var w=0,T=0,k=p,A=h-f*p,M=m,S=d-f*m,E=v,L=g-f*v;for(T=0;T<u;++T){for(w=0;w<f;++w)i[o]=.5*(e[n+y]-e[n+x]),s[c]=.5*(e[n+b]-e[n+_]),n+=k,o+=M,c+=E;n+=A,o+=S,c+=L}}},a={cdiff:function(t){var e={};return function(r,n,i){var a=r.dtype,o=r.order,s=n.dtype,l=n.order,c=i.dtype,u=i.order,f=[a,o.join(),s,l.join(),c,u.join()].join(),h=e[f];return h||(e[f]=h=t([a,o,s,l,c,u])),h(r.shape.slice(0),r.data,r.stride,0|r.offset,n.data,n.stride,0|n.offset,i.data,i.stride,0|i.offset)}},zero:function(t){var e={};return function(r){var n=r.dtype,i=r.order,a=[n,i.join()].join(),o=e[a];return o||(e[a]=o=t([n,i])),o(r.shape.slice(0),r.data,r.stride,0|r.offset)}},fdTemplate1:function(t){var e={};return function(r,n){var i=r.dtype,a=r.order,o=n.dtype,s=n.order,l=[i,a.join(),o,s.join()].join(),c=e[l];return c||(e[l]=c=t([i,a,o,s])),c(r.shape.slice(0),r.data,r.stride,0|r.offset,n.data,n.stride,0|n.offset)}},fdTemplate2:function(t){var e={};return function(r,n,i){var a=r.dtype,o=r.order,s=n.dtype,l=n.order,c=i.dtype,u=i.order,f=[a,o.join(),s,l.join(),c,u.join()].join(),h=e[f];return h||(e[f]=h=t([a,o,s,l,c,u])),h(r.shape.slice(0),r.data,r.stride,0|r.offset,n.data,n.stride,0|n.offset,i.data,i.stride,0|i.offset)}}};function o(t){return(0,a[t.funcName])(s.bind(void 0,t))}function s(t){return i[t.funcName]}function l(t){return o({funcName:t.funcName})}var c={},u={},f=l({funcName:"cdiff"}),h=l({funcName:"zero"});function p(t){return t in c?c[t]:c[t]=l({funcName:"fdTemplate"+t})}function d(t,e,r,n){return function(t,i){var a=i.shape.slice();return a[0]>2&&a[1]>2&&n(i.pick(-1,-1).lo(1,1).hi(a[0]-2,a[1]-2),t.pick(-1,-1,0).lo(1,1).hi(a[0]-2,a[1]-2),t.pick(-1,-1,1).lo(1,1).hi(a[0]-2,a[1]-2)),a[1]>2&&(r(i.pick(0,-1).lo(1).hi(a[1]-2),t.pick(0,-1,1).lo(1).hi(a[1]-2)),e(t.pick(0,-1,0).lo(1).hi(a[1]-2))),a[1]>2&&(r(i.pick(a[0]-1,-1).lo(1).hi(a[1]-2),t.pick(a[0]-1,-1,1).lo(1).hi(a[1]-2)),e(t.pick(a[0]-1,-1,0).lo(1).hi(a[1]-2))),a[0]>2&&(r(i.pick(-1,0).lo(1).hi(a[0]-2),t.pick(-1,0,0).lo(1).hi(a[0]-2)),e(t.pick(-1,0,1).lo(1).hi(a[0]-2))),a[0]>2&&(r(i.pick(-1,a[1]-1).lo(1).hi(a[0]-2),t.pick(-1,a[1]-1,0).lo(1).hi(a[0]-2)),e(t.pick(-1,a[1]-1,1).lo(1).hi(a[0]-2))),t.set(0,0,0,0),t.set(0,0,1,0),t.set(a[0]-1,0,0,0),t.set(a[0]-1,0,1,0),t.set(0,a[1]-1,0,0),t.set(0,a[1]-1,1,0),t.set(a[0]-1,a[1]-1,0,0),t.set(a[0]-1,a[1]-1,1,0),t}}e.exports=function(t,e,r){return Array.isArray(r)||(r=n(e.dimension,"string"==typeof r?r:"clamp")),0===e.size?t:0===e.dimension?(t.set(0),t):function(t){var e=t.join();if(a=u[e])return a;for(var r=t.length,n=[f,h],i=1;i<=r;++i)n.push(p(i));var a=d.apply(void 0,n);return u[e]=a,a}(r)(t,e)}},{dup:65}],253:[function(t,e,r){"use strict";function n(t,e){var r=Math.floor(e),n=e-r,i=0<=r&&r<t.shape[0],a=0<=r+1&&r+1<t.shape[0];return(1-n)*(i?+t.get(r):0)+n*(a?+t.get(r+1):0)}function i(t,e,r){var n=Math.floor(e),i=e-n,a=0<=n&&n<t.shape[0],o=0<=n+1&&n+1<t.shape[0],s=Math.floor(r),l=r-s,c=0<=s&&s<t.shape[1],u=0<=s+1&&s+1<t.shape[1],f=a&&c?t.get(n,s):0,h=a&&u?t.get(n,s+1):0;return(1-l)*((1-i)*f+i*(o&&c?t.get(n+1,s):0))+l*((1-i)*h+i*(o&&u?t.get(n+1,s+1):0))}function a(t,e,r,n){var i=Math.floor(e),a=e-i,o=0<=i&&i<t.shape[0],s=0<=i+1&&i+1<t.shape[0],l=Math.floor(r),c=r-l,u=0<=l&&l<t.shape[1],f=0<=l+1&&l+1<t.shape[1],h=Math.floor(n),p=n-h,d=0<=h&&h<t.shape[2],m=0<=h+1&&h+1<t.shape[2],g=o&&u&&d?t.get(i,l,h):0,v=o&&f&&d?t.get(i,l+1,h):0,y=s&&u&&d?t.get(i+1,l,h):0,x=s&&f&&d?t.get(i+1,l+1,h):0,b=o&&u&&m?t.get(i,l,h+1):0,_=o&&f&&m?t.get(i,l+1,h+1):0;return(1-p)*((1-c)*((1-a)*g+a*y)+c*((1-a)*v+a*x))+p*((1-c)*((1-a)*b+a*(s&&u&&m?t.get(i+1,l,h+1):0))+c*((1-a)*_+a*(s&&f&&m?t.get(i+1,l+1,h+1):0)))}function o(t){var e,r,n=0|t.shape.length,i=new Array(n),a=new Array(n),o=new Array(n),s=new Array(n);for(e=0;e<n;++e)r=+arguments[e+1],i[e]=Math.floor(r),a[e]=r-i[e],o[e]=0<=i[e]&&i[e]<t.shape[e],s[e]=0<=i[e]+1&&i[e]+1<t.shape[e];var l,c,u,f=0;t:for(e=0;e<1<<n;++e){for(c=1,u=t.offset,l=0;l<n;++l)if(e&1<<l){if(!s[l])continue t;c*=a[l],u+=t.stride[l]*(i[l]+1)}else{if(!o[l])continue t;c*=1-a[l],u+=t.stride[l]*i[l]}f+=c*t.data[u]}return f}e.exports=function(t,e,r,s){switch(t.shape.length){case 0:return 0;case 1:return n(t,e);case 2:return i(t,e,r);case 3:return a(t,e,r,s);default:return o.apply(void 0,arguments)}},e.exports.d1=n,e.exports.d2=i,e.exports.d3=a},{}],254:[function(t,e,r){"use strict";var n={"float64,2,1,0":function(){return function(t,e,r,n,i){var a=t[0],o=t[1],s=t[2],l=r[0],c=r[1],u=r[2];n|=0;var f=0,h=0,p=0,d=u,m=c-s*u,g=l-o*c;for(p=0;p<a;++p){for(h=0;h<o;++h){for(f=0;f<s;++f)e[n]/=i,n+=d;n+=m}n+=g}}},"uint8,2,0,1,float64,2,1,0":function(){return function(t,e,r,n,i,a,o,s){for(var l=t[0],c=t[1],u=t[2],f=r[0],h=r[1],p=r[2],d=a[0],m=a[1],g=a[2],v=n|=0,y=o|=0,x=0|t[0];x>0;){x<64?(l=x,x=0):(l=64,x-=64);for(var b=0|t[1];b>0;){b<64?(c=b,b=0):(c=64,b-=64),n=v+x*f+b*h,o=y+x*d+b*m;var _=0,w=0,T=0,k=p,A=f-u*p,M=h-l*f,S=g,E=d-u*g,L=m-l*d;for(T=0;T<c;++T){for(w=0;w<l;++w){for(_=0;_<u;++_)e[n]=i[o]*s,n+=k,o+=S;n+=A,o+=E}n+=M,o+=L}}}}},"float32,1,0,float32,1,0":function(){return function(t,e,r,n,i,a,o){var s=t[0],l=t[1],c=r[0],u=r[1],f=a[0],h=a[1];n|=0,o|=0;var p=0,d=0,m=u,g=c-l*u,v=h,y=f-l*h;for(d=0;d<s;++d){for(p=0;p<l;++p)e[n]=i[o],n+=m,o+=v;n+=g,o+=y}}},"float32,1,0,float32,0,1":function(){return function(t,e,r,n,i,a,o){for(var s=t[0],l=t[1],c=r[0],u=r[1],f=a[0],h=a[1],p=n|=0,d=o|=0,m=0|t[1];m>0;){m<64?(l=m,m=0):(l=64,m-=64);for(var g=0|t[0];g>0;){g<64?(s=g,g=0):(s=64,g-=64),n=p+m*u+g*c,o=d+m*h+g*f;var v=0,y=0,x=u,b=c-l*u,_=h,w=f-l*h;for(y=0;y<s;++y){for(v=0;v<l;++v)e[n]=i[o],n+=x,o+=_;n+=b,o+=w}}}}},"uint8,2,0,1,uint8,1,2,0":function(){return function(t,e,r,n,i,a,o){for(var s=t[0],l=t[1],c=t[2],u=r[0],f=r[1],h=r[2],p=a[0],d=a[1],m=a[2],g=n|=0,v=o|=0,y=0|t[2];y>0;){y<64?(c=y,y=0):(c=64,y-=64);for(var x=0|t[0];x>0;){x<64?(s=x,x=0):(s=64,x-=64);for(var b=0|t[1];b>0;){b<64?(l=b,b=0):(l=64,b-=64),n=g+y*h+x*u+b*f,o=v+y*m+x*p+b*d;var _=0,w=0,T=0,k=h,A=u-c*h,M=f-s*u,S=m,E=p-c*m,L=d-s*p;for(T=0;T<l;++T){for(w=0;w<s;++w){for(_=0;_<c;++_)e[n]=i[o],n+=k,o+=S;n+=A,o+=E}n+=M,o+=L}}}}}},"uint8,2,0,1,array,2,0,1":function(){return function(t,e,r,n,i,a,o){var s=t[0],l=t[1],c=t[2],u=r[0],f=r[1],h=r[2],p=a[0],d=a[1],m=a[2];n|=0,o|=0;var g=0,v=0,y=0,x=h,b=u-c*h,_=f-s*u,w=m,T=p-c*m,k=d-s*p;for(y=0;y<l;++y){for(v=0;v<s;++v){for(g=0;g<c;++g)e[n]=i[o],n+=x,o+=w;n+=b,o+=T}n+=_,o+=k}}}};var i=function(t,e){var r=e.join(",");return(0,n[r])()},a={mul:function(t){var e={};return function(r,n,i){var a=r.dtype,o=r.order,s=n.dtype,l=n.order,c=i.dtype,u=i.order,f=[a,o.join(),s,l.join(),c,u.join()].join(),h=e[f];return h||(e[f]=h=t([a,o,s,l,c,u])),h(r.shape.slice(0),r.data,r.stride,0|r.offset,n.data,n.stride,0|n.offset,i.data,i.stride,0|i.offset)}},muls:function(t){var e={};return function(r,n,i){var a=r.dtype,o=r.order,s=n.dtype,l=n.order,c=[a,o.join(),s,l.join()].join(),u=e[c];return u||(e[c]=u=t([a,o,s,l])),u(r.shape.slice(0),r.data,r.stride,0|r.offset,n.data,n.stride,0|n.offset,i)}},mulseq:function(t){var e={};return function(r,n){var i=r.dtype,a=r.order,o=[i,a.join()].join(),s=e[o];return s||(e[o]=s=t([i,a])),s(r.shape.slice(0),r.data,r.stride,0|r.offset,n)}},div:function(t){var e={};return function(r,n,i){var a=r.dtype,o=r.order,s=n.dtype,l=n.order,c=i.dtype,u=i.order,f=[a,o.join(),s,l.join(),c,u.join()].join(),h=e[f];return h||(e[f]=h=t([a,o,s,l,c,u])),h(r.shape.slice(0),r.data,r.stride,0|r.offset,n.data,n.stride,0|n.offset,i.data,i.stride,0|i.offset)}},divs:function(t){var e={};return function(r,n,i){var a=r.dtype,o=r.order,s=n.dtype,l=n.order,c=[a,o.join(),s,l.join()].join(),u=e[c];return u||(e[c]=u=t([a,o,s,l])),u(r.shape.slice(0),r.data,r.stride,0|r.offset,n.data,n.stride,0|n.offset,i)}},divseq:function(t){var e={};return function(r,n){var i=r.dtype,a=r.order,o=[i,a.join()].join(),s=e[o];return s||(e[o]=s=t([i,a])),s(r.shape.slice(0),r.data,r.stride,0|r.offset,n)}},assign:function(t){var e={};return function(r,n){var i=r.dtype,a=r.order,o=n.dtype,s=n.order,l=[i,a.join(),o,s.join()].join(),c=e[l];return c||(e[l]=c=t([i,a,o,s])),c(r.shape.slice(0),r.data,r.stride,0|r.offset,n.data,n.stride,0|n.offset)}}};function o(t){return e={funcName:t.funcName},(0,a[e.funcName])(i.bind(void 0,e));var e}var s={mul:"*",div:"/"};!function(){for(var t in s)r[t]=o({funcName:t}),r[t+"s"]=o({funcName:t+"s"}),r[t+"seq"]=o({funcName:t+"seq"})}(),r.assign=o({funcName:"assign"})},{}],255:[function(t,e,r){"use strict";var n=t("ndarray"),i=t("./doConvert.js");e.exports=function(t,e){for(var r=[],a=t,o=1;Array.isArray(a);)r.push(a.length),o*=a.length,a=a[0];return 0===r.length?n():(e||(e=n(new Float64Array(o),r)),i(e,t),e)}},{"./doConvert.js":256,ndarray:259}],256:[function(t,e,r){"use strict";var n,i=function(){return function(t,e,r,n,i){var a=t[0],o=t[1],s=t[2],l=r[0],c=r[1],u=r[2],f=[0,0,0];n|=0;var h=0,p=0,d=0,m=u,g=c-s*u,v=l-o*c;for(d=0;d<a;++d){for(p=0;p<o;++p){for(h=0;h<s;++h){var y,x=i;for(y=0;y<f.length-1;++y)x=x[f[y]];e[n]=x[f[f.length-1]],n+=m,++f[2]}n+=g,f[2]-=s,++f[1]}n+=v,f[1]-=o,++f[0]}}};e.exports=(n={funcName:{funcName:"convert"}.funcName},function(t){var e={};return function(r,n){var i=r.dtype,a=r.order,o=[i,a.join()].join(),s=e[o];return s||(e[o]=s=t([i,a])),s(r.shape.slice(0),r.data,r.stride,0|r.offset,n)}}(i.bind(void 0,n)))},{}],257:[function(t,e,r){"use strict";var n=t("typedarray-pool");function i(t){switch(t){case"uint32":return[n.mallocUint32,n.freeUint32];default:return null}}var a={"uint32,1,0":function(t,e){return function(r,n,i,a,o,s,l,c,u,f,h){var p,d,m,g,v,y,x,b,_=r*o+a,w=t(c);for(p=r+1;p<=n;++p){for(d=p,m=_+=o,v=0,y=_,g=0;g<c;++g)w[v++]=i[y],y+=u;t:for(;d-- >r;){v=0,y=m-o;e:for(g=0;g<c;++g){if((x=i[y])<(b=w[v]))break t;if(x>b)break e;y+=f,v+=h}for(v=m,y=m-o,g=0;g<c;++g)i[v]=i[y],v+=u,y+=u;m-=o}for(v=m,y=0,g=0;g<c;++g)i[v]=w[y++],v+=u}e(w)}}};var o={"uint32,1,0":function(t,e,r){return function n(i,a,o,s,l,c,u,f,h,p,d){var m,g,v,y,x,b,_,w,T,k,A,M,S,E,L,C,P,I,O,z,D,R,F,B,N,j=(a-i+1)/6|0,U=i+j,V=a-j,H=i+a>>1,q=H-j,G=H+j,Y=U,W=q,X=H,Z=G,J=V,K=i+1,Q=a-1,$=!0,tt=0,et=0,rt=0,nt=f,it=e(nt),at=e(nt);A=l*Y,M=l*W,N=s;t:for(k=0;k<f;++k){if(w=M+N,(rt=o[_=A+N]-o[w])>0){g=Y,Y=W,W=g;break t}if(rt<0)break t;N+=p}A=l*Z,M=l*J,N=s;t:for(k=0;k<f;++k){if(w=M+N,(rt=o[_=A+N]-o[w])>0){g=Z,Z=J,J=g;break t}if(rt<0)break t;N+=p}A=l*Y,M=l*X,N=s;t:for(k=0;k<f;++k){if(w=M+N,(rt=o[_=A+N]-o[w])>0){g=Y,Y=X,X=g;break t}if(rt<0)break t;N+=p}A=l*W,M=l*X,N=s;t:for(k=0;k<f;++k){if(w=M+N,(rt=o[_=A+N]-o[w])>0){g=W,W=X,X=g;break t}if(rt<0)break t;N+=p}A=l*Y,M=l*Z,N=s;t:for(k=0;k<f;++k){if(w=M+N,(rt=o[_=A+N]-o[w])>0){g=Y,Y=Z,Z=g;break t}if(rt<0)break t;N+=p}A=l*X,M=l*Z,N=s;t:for(k=0;k<f;++k){if(w=M+N,(rt=o[_=A+N]-o[w])>0){g=X,X=Z,Z=g;break t}if(rt<0)break t;N+=p}A=l*W,M=l*J,N=s;t:for(k=0;k<f;++k){if(w=M+N,(rt=o[_=A+N]-o[w])>0){g=W,W=J,J=g;break t}if(rt<0)break t;N+=p}A=l*W,M=l*X,N=s;t:for(k=0;k<f;++k){if(w=M+N,(rt=o[_=A+N]-o[w])>0){g=W,W=X,X=g;break t}if(rt<0)break t;N+=p}A=l*Z,M=l*J,N=s;t:for(k=0;k<f;++k){if(w=M+N,(rt=o[_=A+N]-o[w])>0){g=Z,Z=J,J=g;break t}if(rt<0)break t;N+=p}for(A=l*Y,M=l*W,S=l*X,E=l*Z,L=l*J,C=l*U,P=l*H,I=l*V,B=0,N=s,k=0;k<f;++k)_=A+N,w=M+N,T=S+N,O=E+N,z=L+N,D=C+N,R=P+N,F=I+N,it[B]=o[w],at[B]=o[O],$=$&&it[B]===at[B],v=o[_],y=o[T],x=o[z],o[D]=v,o[R]=y,o[F]=x,++B,N+=h;for(A=l*q,M=l*i,N=s,k=0;k<f;++k)w=M+N,o[_=A+N]=o[w],N+=h;for(A=l*G,M=l*a,N=s,k=0;k<f;++k)w=M+N,o[_=A+N]=o[w],N+=h;if($)for(b=K;b<=Q;++b){_=s+b*l,B=0;t:for(k=0;k<f&&0===(rt=o[_]-it[B]);++k)B+=d,_+=p;if(0!==rt)if(rt<0){if(b!==K)for(A=l*b,M=l*K,N=s,k=0;k<f;++k)w=M+N,m=o[_=A+N],o[_]=o[w],o[w]=m,N+=h;++K}else for(;;){_=s+Q*l,B=0;t:for(k=0;k<f&&0===(rt=o[_]-it[B]);++k)B+=d,_+=p;if(!(rt>0)){if(rt<0){for(A=l*b,M=l*K,S=l*Q,N=s,k=0;k<f;++k)w=M+N,T=S+N,m=o[_=A+N],o[_]=o[w],o[w]=o[T],o[T]=m,N+=h;++K,--Q;break}for(A=l*b,M=l*Q,N=s,k=0;k<f;++k)w=M+N,m=o[_=A+N],o[_]=o[w],o[w]=m,N+=h;--Q;break}Q--}}else for(b=K;b<=Q;++b){_=s+b*l,B=0;t:for(k=0;k<f&&0===(tt=o[_]-it[B]);++k)B+=d,_+=p;if(tt<0){if(b!==K)for(A=l*b,M=l*K,N=s,k=0;k<f;++k)w=M+N,m=o[_=A+N],o[_]=o[w],o[w]=m,N+=h;++K}else{_=s+b*l,B=0;t:for(k=0;k<f&&0===(et=o[_]-at[B]);++k)B+=d,_+=p;if(et>0)for(;;){_=s+Q*l,B=0;t:for(k=0;k<f&&0===(rt=o[_]-at[B]);++k)B+=d,_+=p;if(!(rt>0)){_=s+Q*l,B=0;t:for(k=0;k<f&&0===(rt=o[_]-it[B]);++k)B+=d,_+=p;if(rt<0){for(A=l*b,M=l*K,S=l*Q,N=s,k=0;k<f;++k)w=M+N,T=S+N,m=o[_=A+N],o[_]=o[w],o[w]=o[T],o[T]=m,N+=h;++K,--Q}else{for(A=l*b,M=l*Q,N=s,k=0;k<f;++k)w=M+N,m=o[_=A+N],o[_]=o[w],o[w]=m,N+=h;--Q}break}if(--Q<b)break}}}for(A=l*i,M=l*(K-1),B=0,N=s,k=0;k<f;++k)w=M+N,o[_=A+N]=o[w],o[w]=it[B],++B,N+=h;for(A=l*a,M=l*(Q+1),B=0,N=s,k=0;k<f;++k)w=M+N,o[_=A+N]=o[w],o[w]=at[B],++B,N+=h;if(K-2-i<=32?t(i,K-2,o,s,l,c,u,f,h,p,d):n(i,K-2,o,s,l,c,u,f,h,p,d),a-(Q+2)<=32?t(Q+2,a,o,s,l,c,u,f,h,p,d):n(Q+2,a,o,s,l,c,u,f,h,p,d),$)return r(it),void r(at);if(K<U&&Q>V){t:for(;;){for(_=s+K*l,B=0,N=s,k=0;k<f;++k){if(o[_]!==it[B])break t;++B,_+=h}++K}t:for(;;){for(_=s+Q*l,B=0,N=s,k=0;k<f;++k){if(o[_]!==at[B])break t;++B,_+=h}--Q}for(b=K;b<=Q;++b){_=s+b*l,B=0;t:for(k=0;k<f&&0===(tt=o[_]-it[B]);++k)B+=d,_+=p;if(0===tt){if(b!==K)for(A=l*b,M=l*K,N=s,k=0;k<f;++k)w=M+N,m=o[_=A+N],o[_]=o[w],o[w]=m,N+=h;++K}else{_=s+b*l,B=0;t:for(k=0;k<f&&0===(et=o[_]-at[B]);++k)B+=d,_+=p;if(0===et)for(;;){_=s+Q*l,B=0;t:for(k=0;k<f&&0===(rt=o[_]-at[B]);++k)B+=d,_+=p;if(0!==rt){_=s+Q*l,B=0;t:for(k=0;k<f&&0===(rt=o[_]-it[B]);++k)B+=d,_+=p;if(rt<0){for(A=l*b,M=l*K,S=l*Q,N=s,k=0;k<f;++k)w=M+N,T=S+N,m=o[_=A+N],o[_]=o[w],o[w]=o[T],o[T]=m,N+=h;++K,--Q}else{for(A=l*b,M=l*Q,N=s,k=0;k<f;++k)w=M+N,m=o[_=A+N],o[_]=o[w],o[w]=m,N+=h;--Q}break}if(--Q<b)break}}}}r(it),r(at),Q-K<=32?t(K,Q,o,s,l,c,u,f,h,p,d):n(K,Q,o,s,l,c,u,f,h,p,d)}}};var s={"uint32,1,0":function(t,e){return function(r){var n=r.data,i=0|r.offset,a=r.shape,o=r.stride,s=0|o[0],l=0|a[0],c=0|o[1],u=0|a[1],f=c,h=c;l<=32?t(0,l-1,n,i,s,c,l,u,f,h,1):e(0,l-1,n,i,s,c,l,u,f,h,1)}}};e.exports=function(t,e){var r=[e,t].join(","),n=s[r],l=function(t,e){var r=i(e),n=[e,t].join(","),o=a[n];return r?o(r[0],r[1]):o()}(t,e),c=function(t,e,r){var n=i(e),a=[e,t].join(","),s=o[a];return t.length>1&&n?s(r,n[0],n[1]):s(r)}(t,e,l);return n(l,c)}},{"typedarray-pool":308}],258:[function(t,e,r){"use strict";var n=t("./lib/compile_sort.js"),i={};e.exports=function(t){var e=t.order,r=t.dtype,a=[e,r].join(":"),o=i[a];return o||(i[a]=o=n(e,r)),o(t),t}},{"./lib/compile_sort.js":257}],259:[function(t,e,r){var n=t("is-buffer"),i="undefined"!=typeof Float64Array;function a(t,e){return t[0]-e[0]}function o(){var t,e=this.stride,r=new Array(e.length);for(t=0;t<r.length;++t)r[t]=[Math.abs(e[t]),t];r.sort(a);var n=new Array(r.length);for(t=0;t<n.length;++t)n[t]=r[t][1];return n}var s={T:function(t){function e(t){this.data=t}var r=e.prototype;return r.dtype=t,r.index=function(){return-1},r.size=0,r.dimension=-1,r.shape=r.stride=r.order=[],r.lo=r.hi=r.transpose=r.step=function(){return new e(this.data)},r.get=r.set=function(){},r.pick=function(){return null},function(t){return new e(t)}},0:function(t,e){function r(t,e){this.data=t,this.offset=e}var n=r.prototype;return n.dtype=t,n.index=function(){return this.offset},n.dimension=0,n.size=1,n.shape=n.stride=n.order=[],n.lo=n.hi=n.transpose=n.step=function(){return new r(this.data,this.offset)},n.pick=function(){return e(this.data)},n.valueOf=n.get=function(){return"generic"===t?this.data.get(this.offset):this.data[this.offset]},n.set=function(e){return"generic"===t?this.data.set(this.offset,e):this.data[this.offset]=e},function(t,e,n,i){return new r(t,i)}},1:function(t,e,r){function n(t,e,r,n){this.data=t,this.shape=[e],this.stride=[r],this.offset=0|n}var i=n.prototype;return i.dtype=t,i.dimension=1,Object.defineProperty(i,"size",{get:function(){return this.shape[0]}}),i.order=[0],i.set=function(e,r){return"generic"===t?this.data.set(this.offset+this.stride[0]*e,r):this.data[this.offset+this.stride[0]*e]=r},i.get=function(e){return"generic"===t?this.data.get(this.offset+this.stride[0]*e):this.data[this.offset+this.stride[0]*e]},i.index=function(t){return this.offset+this.stride[0]*t},i.hi=function(t){return new n(this.data,"number"!=typeof t||t<0?this.shape[0]:0|t,this.stride[0],this.offset)},i.lo=function(t){var e=this.offset,r=0,i=this.shape[0],a=this.stride[0];return"number"==typeof t&&t>=0&&(e+=a*(r=0|t),i-=r),new n(this.data,i,a,e)},i.step=function(t){var e=this.shape[0],r=this.stride[0],i=this.offset,a=0,o=Math.ceil;return"number"==typeof t&&((a=0|t)<0?(i+=r*(e-1),e=o(-e/a)):e=o(e/a),r*=a),new n(this.data,e,r,i)},i.transpose=function(t){t=void 0===t?0:0|t;var e=this.shape,r=this.stride;return new n(this.data,e[t],r[t],this.offset)},i.pick=function(t){var r=[],n=[],i=this.offset;return"number"==typeof t&&t>=0?i=i+this.stride[0]*t|0:(r.push(this.shape[0]),n.push(this.stride[0])),(0,e[r.length+1])(this.data,r,n,i)},function(t,e,r,i){return new n(t,e[0],r[0],i)}},2:function(t,e,r){function n(t,e,r,n,i,a){this.data=t,this.shape=[e,r],this.stride=[n,i],this.offset=0|a}var i=n.prototype;return i.dtype=t,i.dimension=2,Object.defineProperty(i,"size",{get:function(){return this.shape[0]*this.shape[1]}}),Object.defineProperty(i,"order",{get:function(){return Math.abs(this.stride[0])>Math.abs(this.stride[1])?[1,0]:[0,1]}}),i.set=function(e,r,n){return"generic"===t?this.data.set(this.offset+this.stride[0]*e+this.stride[1]*r,n):this.data[this.offset+this.stride[0]*e+this.stride[1]*r]=n},i.get=function(e,r){return"generic"===t?this.data.get(this.offset+this.stride[0]*e+this.stride[1]*r):this.data[this.offset+this.stride[0]*e+this.stride[1]*r]},i.index=function(t,e){return this.offset+this.stride[0]*t+this.stride[1]*e},i.hi=function(t,e){return new n(this.data,"number"!=typeof t||t<0?this.shape[0]:0|t,"number"!=typeof e||e<0?this.shape[1]:0|e,this.stride[0],this.stride[1],this.offset)},i.lo=function(t,e){var r=this.offset,i=0,a=this.shape[0],o=this.shape[1],s=this.stride[0],l=this.stride[1];return"number"==typeof t&&t>=0&&(r+=s*(i=0|t),a-=i),"number"==typeof e&&e>=0&&(r+=l*(i=0|e),o-=i),new n(this.data,a,o,s,l,r)},i.step=function(t,e){var r=this.shape[0],i=this.shape[1],a=this.stride[0],o=this.stride[1],s=this.offset,l=0,c=Math.ceil;return"number"==typeof t&&((l=0|t)<0?(s+=a*(r-1),r=c(-r/l)):r=c(r/l),a*=l),"number"==typeof e&&((l=0|e)<0?(s+=o*(i-1),i=c(-i/l)):i=c(i/l),o*=l),new n(this.data,r,i,a,o,s)},i.transpose=function(t,e){t=void 0===t?0:0|t,e=void 0===e?1:0|e;var r=this.shape,i=this.stride;return new n(this.data,r[t],r[e],i[t],i[e],this.offset)},i.pick=function(t,r){var n=[],i=[],a=this.offset;return"number"==typeof t&&t>=0?a=a+this.stride[0]*t|0:(n.push(this.shape[0]),i.push(this.stride[0])),"number"==typeof r&&r>=0?a=a+this.stride[1]*r|0:(n.push(this.shape[1]),i.push(this.stride[1])),(0,e[n.length+1])(this.data,n,i,a)},function(t,e,r,i){return new n(t,e[0],e[1],r[0],r[1],i)}},3:function(t,e,r){function n(t,e,r,n,i,a,o,s){this.data=t,this.shape=[e,r,n],this.stride=[i,a,o],this.offset=0|s}var i=n.prototype;return i.dtype=t,i.dimension=3,Object.defineProperty(i,"size",{get:function(){return this.shape[0]*this.shape[1]*this.shape[2]}}),Object.defineProperty(i,"order",{get:function(){var t=Math.abs(this.stride[0]),e=Math.abs(this.stride[1]),r=Math.abs(this.stride[2]);return t>e?e>r?[2,1,0]:t>r?[1,2,0]:[1,0,2]:t>r?[2,0,1]:r>e?[0,1,2]:[0,2,1]}}),i.set=function(e,r,n,i){return"generic"===t?this.data.set(this.offset+this.stride[0]*e+this.stride[1]*r+this.stride[2]*n,i):this.data[this.offset+this.stride[0]*e+this.stride[1]*r+this.stride[2]*n]=i},i.get=function(e,r,n){return"generic"===t?this.data.get(this.offset+this.stride[0]*e+this.stride[1]*r+this.stride[2]*n):this.data[this.offset+this.stride[0]*e+this.stride[1]*r+this.stride[2]*n]},i.index=function(t,e,r){return this.offset+this.stride[0]*t+this.stride[1]*e+this.stride[2]*r},i.hi=function(t,e,r){return new n(this.data,"number"!=typeof t||t<0?this.shape[0]:0|t,"number"!=typeof e||e<0?this.shape[1]:0|e,"number"!=typeof r||r<0?this.shape[2]:0|r,this.stride[0],this.stride[1],this.stride[2],this.offset)},i.lo=function(t,e,r){var i=this.offset,a=0,o=this.shape[0],s=this.shape[1],l=this.shape[2],c=this.stride[0],u=this.stride[1],f=this.stride[2];return"number"==typeof t&&t>=0&&(i+=c*(a=0|t),o-=a),"number"==typeof e&&e>=0&&(i+=u*(a=0|e),s-=a),"number"==typeof r&&r>=0&&(i+=f*(a=0|r),l-=a),new n(this.data,o,s,l,c,u,f,i)},i.step=function(t,e,r){var i=this.shape[0],a=this.shape[1],o=this.shape[2],s=this.stride[0],l=this.stride[1],c=this.stride[2],u=this.offset,f=0,h=Math.ceil;return"number"==typeof t&&((f=0|t)<0?(u+=s*(i-1),i=h(-i/f)):i=h(i/f),s*=f),"number"==typeof e&&((f=0|e)<0?(u+=l*(a-1),a=h(-a/f)):a=h(a/f),l*=f),"number"==typeof r&&((f=0|r)<0?(u+=c*(o-1),o=h(-o/f)):o=h(o/f),c*=f),new n(this.data,i,a,o,s,l,c,u)},i.transpose=function(t,e,r){t=void 0===t?0:0|t,e=void 0===e?1:0|e,r=void 0===r?2:0|r;var i=this.shape,a=this.stride;return new n(this.data,i[t],i[e],i[r],a[t],a[e],a[r],this.offset)},i.pick=function(t,r,n){var i=[],a=[],o=this.offset;return"number"==typeof t&&t>=0?o=o+this.stride[0]*t|0:(i.push(this.shape[0]),a.push(this.stride[0])),"number"==typeof r&&r>=0?o=o+this.stride[1]*r|0:(i.push(this.shape[1]),a.push(this.stride[1])),"number"==typeof n&&n>=0?o=o+this.stride[2]*n|0:(i.push(this.shape[2]),a.push(this.stride[2])),(0,e[i.length+1])(this.data,i,a,o)},function(t,e,r,i){return new n(t,e[0],e[1],e[2],r[0],r[1],r[2],i)}},4:function(t,e,r){function n(t,e,r,n,i,a,o,s,l,c){this.data=t,this.shape=[e,r,n,i],this.stride=[a,o,s,l],this.offset=0|c}var i=n.prototype;return i.dtype=t,i.dimension=4,Object.defineProperty(i,"size",{get:function(){return this.shape[0]*this.shape[1]*this.shape[2]*this.shape[3]}}),Object.defineProperty(i,"order",{get:r}),i.set=function(e,r,n,i,a){return"generic"===t?this.data.set(this.offset+this.stride[0]*e+this.stride[1]*r+this.stride[2]*n+this.stride[3]*i,a):this.data[this.offset+this.stride[0]*e+this.stride[1]*r+this.stride[2]*n+this.stride[3]*i]=a},i.get=function(e,r,n,i){return"generic"===t?this.data.get(this.offset+this.stride[0]*e+this.stride[1]*r+this.stride[2]*n+this.stride[3]*i):this.data[this.offset+this.stride[0]*e+this.stride[1]*r+this.stride[2]*n+this.stride[3]*i]},i.index=function(t,e,r,n){return this.offset+this.stride[0]*t+this.stride[1]*e+this.stride[2]*r+this.stride[3]*n},i.hi=function(t,e,r,i){return new n(this.data,"number"!=typeof t||t<0?this.shape[0]:0|t,"number"!=typeof e||e<0?this.shape[1]:0|e,"number"!=typeof r||r<0?this.shape[2]:0|r,"number"!=typeof i||i<0?this.shape[3]:0|i,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.offset)},i.lo=function(t,e,r,i){var a=this.offset,o=0,s=this.shape[0],l=this.shape[1],c=this.shape[2],u=this.shape[3],f=this.stride[0],h=this.stride[1],p=this.stride[2],d=this.stride[3];return"number"==typeof t&&t>=0&&(a+=f*(o=0|t),s-=o),"number"==typeof e&&e>=0&&(a+=h*(o=0|e),l-=o),"number"==typeof r&&r>=0&&(a+=p*(o=0|r),c-=o),"number"==typeof i&&i>=0&&(a+=d*(o=0|i),u-=o),new n(this.data,s,l,c,u,f,h,p,d,a)},i.step=function(t,e,r,i){var a=this.shape[0],o=this.shape[1],s=this.shape[2],l=this.shape[3],c=this.stride[0],u=this.stride[1],f=this.stride[2],h=this.stride[3],p=this.offset,d=0,m=Math.ceil;return"number"==typeof t&&((d=0|t)<0?(p+=c*(a-1),a=m(-a/d)):a=m(a/d),c*=d),"number"==typeof e&&((d=0|e)<0?(p+=u*(o-1),o=m(-o/d)):o=m(o/d),u*=d),"number"==typeof r&&((d=0|r)<0?(p+=f*(s-1),s=m(-s/d)):s=m(s/d),f*=d),"number"==typeof i&&((d=0|i)<0?(p+=h*(l-1),l=m(-l/d)):l=m(l/d),h*=d),new n(this.data,a,o,s,l,c,u,f,h,p)},i.transpose=function(t,e,r,i){t=void 0===t?0:0|t,e=void 0===e?1:0|e,r=void 0===r?2:0|r,i=void 0===i?3:0|i;var a=this.shape,o=this.stride;return new n(this.data,a[t],a[e],a[r],a[i],o[t],o[e],o[r],o[i],this.offset)},i.pick=function(t,r,n,i){var a=[],o=[],s=this.offset;return"number"==typeof t&&t>=0?s=s+this.stride[0]*t|0:(a.push(this.shape[0]),o.push(this.stride[0])),"number"==typeof r&&r>=0?s=s+this.stride[1]*r|0:(a.push(this.shape[1]),o.push(this.stride[1])),"number"==typeof n&&n>=0?s=s+this.stride[2]*n|0:(a.push(this.shape[2]),o.push(this.stride[2])),"number"==typeof i&&i>=0?s=s+this.stride[3]*i|0:(a.push(this.shape[3]),o.push(this.stride[3])),(0,e[a.length+1])(this.data,a,o,s)},function(t,e,r,i){return new n(t,e[0],e[1],e[2],e[3],r[0],r[1],r[2],r[3],i)}},5:function(t,e,r){function n(t,e,r,n,i,a,o,s,l,c,u,f){this.data=t,this.shape=[e,r,n,i,a],this.stride=[o,s,l,c,u],this.offset=0|f}var i=n.prototype;return i.dtype=t,i.dimension=5,Object.defineProperty(i,"size",{get:function(){return this.shape[0]*this.shape[1]*this.shape[2]*this.shape[3]*this.shape[4]}}),Object.defineProperty(i,"order",{get:r}),i.set=function(e,r,n,i,a,o){return"generic"===t?this.data.set(this.offset+this.stride[0]*e+this.stride[1]*r+this.stride[2]*n+this.stride[3]*i+this.stride[4]*a,o):this.data[this.offset+this.stride[0]*e+this.stride[1]*r+this.stride[2]*n+this.stride[3]*i+this.stride[4]*a]=o},i.get=function(e,r,n,i,a){return"generic"===t?this.data.get(this.offset+this.stride[0]*e+this.stride[1]*r+this.stride[2]*n+this.stride[3]*i+this.stride[4]*a):this.data[this.offset+this.stride[0]*e+this.stride[1]*r+this.stride[2]*n+this.stride[3]*i+this.stride[4]*a]},i.index=function(t,e,r,n,i){return this.offset+this.stride[0]*t+this.stride[1]*e+this.stride[2]*r+this.stride[3]*n+this.stride[4]*i},i.hi=function(t,e,r,i,a){return new n(this.data,"number"!=typeof t||t<0?this.shape[0]:0|t,"number"!=typeof e||e<0?this.shape[1]:0|e,"number"!=typeof r||r<0?this.shape[2]:0|r,"number"!=typeof i||i<0?this.shape[3]:0|i,"number"!=typeof a||a<0?this.shape[4]:0|a,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.stride[4],this.offset)},i.lo=function(t,e,r,i,a){var o=this.offset,s=0,l=this.shape[0],c=this.shape[1],u=this.shape[2],f=this.shape[3],h=this.shape[4],p=this.stride[0],d=this.stride[1],m=this.stride[2],g=this.stride[3],v=this.stride[4];return"number"==typeof t&&t>=0&&(o+=p*(s=0|t),l-=s),"number"==typeof e&&e>=0&&(o+=d*(s=0|e),c-=s),"number"==typeof r&&r>=0&&(o+=m*(s=0|r),u-=s),"number"==typeof i&&i>=0&&(o+=g*(s=0|i),f-=s),"number"==typeof a&&a>=0&&(o+=v*(s=0|a),h-=s),new n(this.data,l,c,u,f,h,p,d,m,g,v,o)},i.step=function(t,e,r,i,a){var o=this.shape[0],s=this.shape[1],l=this.shape[2],c=this.shape[3],u=this.shape[4],f=this.stride[0],h=this.stride[1],p=this.stride[2],d=this.stride[3],m=this.stride[4],g=this.offset,v=0,y=Math.ceil;return"number"==typeof t&&((v=0|t)<0?(g+=f*(o-1),o=y(-o/v)):o=y(o/v),f*=v),"number"==typeof e&&((v=0|e)<0?(g+=h*(s-1),s=y(-s/v)):s=y(s/v),h*=v),"number"==typeof r&&((v=0|r)<0?(g+=p*(l-1),l=y(-l/v)):l=y(l/v),p*=v),"number"==typeof i&&((v=0|i)<0?(g+=d*(c-1),c=y(-c/v)):c=y(c/v),d*=v),"number"==typeof a&&((v=0|a)<0?(g+=m*(u-1),u=y(-u/v)):u=y(u/v),m*=v),new n(this.data,o,s,l,c,u,f,h,p,d,m,g)},i.transpose=function(t,e,r,i,a){t=void 0===t?0:0|t,e=void 0===e?1:0|e,r=void 0===r?2:0|r,i=void 0===i?3:0|i,a=void 0===a?4:0|a;var o=this.shape,s=this.stride;return new n(this.data,o[t],o[e],o[r],o[i],o[a],s[t],s[e],s[r],s[i],s[a],this.offset)},i.pick=function(t,r,n,i,a){var o=[],s=[],l=this.offset;return"number"==typeof t&&t>=0?l=l+this.stride[0]*t|0:(o.push(this.shape[0]),s.push(this.stride[0])),"number"==typeof r&&r>=0?l=l+this.stride[1]*r|0:(o.push(this.shape[1]),s.push(this.stride[1])),"number"==typeof n&&n>=0?l=l+this.stride[2]*n|0:(o.push(this.shape[2]),s.push(this.stride[2])),"number"==typeof i&&i>=0?l=l+this.stride[3]*i|0:(o.push(this.shape[3]),s.push(this.stride[3])),"number"==typeof a&&a>=0?l=l+this.stride[4]*a|0:(o.push(this.shape[4]),s.push(this.stride[4])),(0,e[o.length+1])(this.data,o,s,l)},function(t,e,r,i){return new n(t,e[0],e[1],e[2],e[3],e[4],r[0],r[1],r[2],r[3],r[4],i)}}};function l(t,e){var r=-1===e?"T":String(e),n=s[r];return-1===e?n(t):0===e?n(t,c[t][0]):n(t,c[t],o)}var c={generic:[],buffer:[],array:[],float32:[],float64:[],int8:[],int16:[],int32:[],uint8_clamped:[],uint8:[],uint16:[],uint32:[],bigint64:[],biguint64:[]};e.exports=function(t,e,r,a){if(void 0===t)return(0,c.array[0])([]);"number"==typeof t&&(t=[t]),void 0===e&&(e=[t.length]);var o=e.length;if(void 0===r){r=new Array(o);for(var s=o-1,u=1;s>=0;--s)r[s]=u,u*=e[s]}if(void 0===a){a=0;for(s=0;s<o;++s)r[s]<0&&(a-=(e[s]-1)*r[s])}for(var f=function(t){if(n(t))return"buffer";if(i)switch(Object.prototype.toString.call(t)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8ClampedArray]":return"uint8_clamped";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object BigInt64Array]":return"bigint64";case"[object BigUint64Array]":return"biguint64"}return Array.isArray(t)?"array":"generic"}(t),h=c[f];h.length<=o+1;)h.push(l(f,h.length-1));return(0,h[o+1])(t,e,r,a)}},{"is-buffer":237}],260:[function(t,e,r){"use strict";var n=t("double-bits"),i=Math.pow(2,-1074);e.exports=function(t,e){if(isNaN(t)||isNaN(e))return NaN;if(t===e)return t;if(0===t)return e<0?-i:i;var r=n.hi(t),a=n.lo(t);e>t==t>0?a===-1>>>0?(r+=1,a=0):a+=1:0===a?(a=-1>>>0,r-=1):a-=1;return n.pack(a,r)}},{"double-bits":64}],261:[function(t,e,r){r.vertexNormals=function(t,e,r){for(var n=e.length,i=new Array(n),a=void 0===r?1e-6:r,o=0;o<n;++o)i[o]=[0,0,0];for(o=0;o<t.length;++o)for(var s=t[o],l=0,c=s[s.length-1],u=s[0],f=0;f<s.length;++f){l=c,c=u,u=s[(f+1)%s.length];for(var h=e[l],p=e[c],d=e[u],m=new Array(3),g=0,v=new Array(3),y=0,x=0;x<3;++x)m[x]=h[x]-p[x],g+=m[x]*m[x],v[x]=d[x]-p[x],y+=v[x]*v[x];if(g*y>a){var b=i[c],_=1/Math.sqrt(g*y);for(x=0;x<3;++x){var w=(x+1)%3,T=(x+2)%3;b[x]+=_*(v[w]*m[T]-v[T]*m[w])}}}for(o=0;o<n;++o){b=i[o];var k=0;for(x=0;x<3;++x)k+=b[x]*b[x];if(k>a)for(_=1/Math.sqrt(k),x=0;x<3;++x)b[x]*=_;else for(x=0;x<3;++x)b[x]=0}return i},r.faceNormals=function(t,e,r){for(var n=t.length,i=new Array(n),a=void 0===r?1e-6:r,o=0;o<n;++o){for(var s=t[o],l=new Array(3),c=0;c<3;++c)l[c]=e[s[c]];var u=new Array(3),f=new Array(3);for(c=0;c<3;++c)u[c]=l[1][c]-l[0][c],f[c]=l[2][c]-l[0][c];var h=new Array(3),p=0;for(c=0;c<3;++c){var d=(c+1)%3,m=(c+2)%3;h[c]=u[d]*f[m]-u[m]*f[d],p+=h[c]*h[c]}p=p>a?1/Math.sqrt(p):0;for(c=0;c<3;++c)h[c]*=p;i[o]=h}return i}},{}],262:[function(t,e,r){"use strict";e.exports=function(t,e,r,n,i,a,o,s,l,c){var u=e+a+c;if(f>0){var f=Math.sqrt(u+1);t[0]=.5*(o-l)/f,t[1]=.5*(s-n)/f,t[2]=.5*(r-a)/f,t[3]=.5*f}else{var h=Math.max(e,a,c);f=Math.sqrt(2*h-u+1);e>=h?(t[0]=.5*f,t[1]=.5*(i+r)/f,t[2]=.5*(s+n)/f,t[3]=.5*(o-l)/f):a>=h?(t[0]=.5*(r+i)/f,t[1]=.5*f,t[2]=.5*(l+o)/f,t[3]=.5*(s-n)/f):(t[0]=.5*(n+s)/f,t[1]=.5*(o+l)/f,t[2]=.5*f,t[3]=.5*(r-i)/f)}return t}},{}],263:[function(t,e,r){"use strict";e.exports=function(t){var e=(t=t||{}).center||[0,0,0],r=t.rotation||[0,0,0,1],n=t.radius||1;e=[].slice.call(e,0,3),u(r=[].slice.call(r,0,4),r);var i=new f(r,e,Math.log(n));i.setDistanceLimits(t.zoomMin,t.zoomMax),("eye"in t||"up"in t)&&i.lookAt(0,t.eye,t.center,t.up);return i};var n=t("filtered-vector"),i=t("gl-mat4/lookAt"),a=t("gl-mat4/fromQuat"),o=t("gl-mat4/invert"),s=t("./lib/quatFromFrame");function l(t,e,r){return Math.sqrt(Math.pow(t,2)+Math.pow(e,2)+Math.pow(r,2))}function c(t,e,r,n){return Math.sqrt(Math.pow(t,2)+Math.pow(e,2)+Math.pow(r,2)+Math.pow(n,2))}function u(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=c(r,n,i,a);o>1e-6?(t[0]=r/o,t[1]=n/o,t[2]=i/o,t[3]=a/o):(t[0]=t[1]=t[2]=0,t[3]=1)}function f(t,e,r){this.radius=n([r]),this.center=n(e),this.rotation=n(t),this.computedRadius=this.radius.curve(0),this.computedCenter=this.center.curve(0),this.computedRotation=this.rotation.curve(0),this.computedUp=[.1,0,0],this.computedEye=[.1,0,0],this.computedMatrix=[.1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.recalcMatrix(0)}var h=f.prototype;h.lastT=function(){return Math.max(this.radius.lastT(),this.center.lastT(),this.rotation.lastT())},h.recalcMatrix=function(t){this.radius.curve(t),this.center.curve(t),this.rotation.curve(t);var e=this.computedRotation;u(e,e);var r=this.computedMatrix;a(r,e);var n=this.computedCenter,i=this.computedEye,o=this.computedUp,s=Math.exp(this.computedRadius[0]);i[0]=n[0]+s*r[2],i[1]=n[1]+s*r[6],i[2]=n[2]+s*r[10],o[0]=r[1],o[1]=r[5],o[2]=r[9];for(var l=0;l<3;++l){for(var c=0,f=0;f<3;++f)c+=r[l+4*f]*i[f];r[12+l]=-c}},h.getMatrix=function(t,e){this.recalcMatrix(t);var r=this.computedMatrix;if(e){for(var n=0;n<16;++n)e[n]=r[n];return e}return r},h.idle=function(t){this.center.idle(t),this.radius.idle(t),this.rotation.idle(t)},h.flush=function(t){this.center.flush(t),this.radius.flush(t),this.rotation.flush(t)},h.pan=function(t,e,r,n){e=e||0,r=r||0,n=n||0,this.recalcMatrix(t);var i=this.computedMatrix,a=i[1],o=i[5],s=i[9],c=l(a,o,s);a/=c,o/=c,s/=c;var u=i[0],f=i[4],h=i[8],p=u*a+f*o+h*s,d=l(u-=a*p,f-=o*p,h-=s*p);u/=d,f/=d,h/=d;var m=i[2],g=i[6],v=i[10],y=m*a+g*o+v*s,x=m*u+g*f+v*h,b=l(m-=y*a+x*u,g-=y*o+x*f,v-=y*s+x*h);m/=b,g/=b,v/=b;var _=u*e+a*r,w=f*e+o*r,T=h*e+s*r;this.center.move(t,_,w,T);var k=Math.exp(this.computedRadius[0]);k=Math.max(1e-4,k+n),this.radius.set(t,Math.log(k))},h.rotate=function(t,e,r,n){this.recalcMatrix(t),e=e||0,r=r||0;var i=this.computedMatrix,a=i[0],o=i[4],s=i[8],u=i[1],f=i[5],h=i[9],p=i[2],d=i[6],m=i[10],g=e*a+r*u,v=e*o+r*f,y=e*s+r*h,x=-(d*y-m*v),b=-(m*g-p*y),_=-(p*v-d*g),w=Math.sqrt(Math.max(0,1-Math.pow(x,2)-Math.pow(b,2)-Math.pow(_,2))),T=c(x,b,_,w);T>1e-6?(x/=T,b/=T,_/=T,w/=T):(x=b=_=0,w=1);var k=this.computedRotation,A=k[0],M=k[1],S=k[2],E=k[3],L=A*w+E*x+M*_-S*b,C=M*w+E*b+S*x-A*_,P=S*w+E*_+A*b-M*x,I=E*w-A*x-M*b-S*_;if(n){x=p,b=d,_=m;var O=Math.sin(n)/l(x,b,_);x*=O,b*=O,_*=O,I=I*(w=Math.cos(e))-(L=L*w+I*x+C*_-P*b)*x-(C=C*w+I*b+P*x-L*_)*b-(P=P*w+I*_+L*b-C*x)*_}var z=c(L,C,P,I);z>1e-6?(L/=z,C/=z,P/=z,I/=z):(L=C=P=0,I=1),this.rotation.set(t,L,C,P,I)},h.lookAt=function(t,e,r,n){this.recalcMatrix(t),r=r||this.computedCenter,e=e||this.computedEye,n=n||this.computedUp;var a=this.computedMatrix;i(a,e,r,n);var o=this.computedRotation;s(o,a[0],a[1],a[2],a[4],a[5],a[6],a[8],a[9],a[10]),u(o,o),this.rotation.set(t,o[0],o[1],o[2],o[3]);for(var l=0,c=0;c<3;++c)l+=Math.pow(r[c]-e[c],2);this.radius.set(t,.5*Math.log(Math.max(l,1e-6))),this.center.set(t,r[0],r[1],r[2])},h.translate=function(t,e,r,n){this.center.move(t,e||0,r||0,n||0)},h.setMatrix=function(t,e){var r=this.computedRotation;s(r,e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]),u(r,r),this.rotation.set(t,r[0],r[1],r[2],r[3]);var n=this.computedMatrix;o(n,e);var i=n[15];if(Math.abs(i)>1e-6){var a=n[12]/i,l=n[13]/i,c=n[14]/i;this.recalcMatrix(t);var f=Math.exp(this.computedRadius[0]);this.center.set(t,a-n[2]*f,l-n[6]*f,c-n[10]*f),this.radius.idle(t)}else this.center.idle(t),this.radius.idle(t)},h.setDistance=function(t,e){e>0&&this.radius.set(t,Math.log(e))},h.setDistanceLimits=function(t,e){t=t>0?Math.log(t):-1/0,e=e>0?Math.log(e):1/0,e=Math.max(e,t),this.radius.bounds[0][0]=t,this.radius.bounds[1][0]=e},h.getDistanceLimits=function(t){var e=this.radius.bounds;return t?(t[0]=Math.exp(e[0][0]),t[1]=Math.exp(e[1][0]),t):[Math.exp(e[0][0]),Math.exp(e[1][0])]},h.toJSON=function(){return this.recalcMatrix(this.lastT()),{center:this.computedCenter.slice(),rotation:this.computedRotation.slice(),distance:Math.log(this.computedRadius[0]),zoomMin:this.radius.bounds[0][0],zoomMax:this.radius.bounds[1][0]}},h.fromJSON=function(t){var e=this.lastT(),r=t.center;r&&this.center.set(e,r[0],r[1],r[2]);var n=t.rotation;n&&this.rotation.set(e,n[0],n[1],n[2],n[3]);var i=t.distance;i&&i>0&&this.radius.set(e,Math.log(i)),this.setDistanceLimits(t.zoomMin,t.zoomMax)}},{"./lib/quatFromFrame":262,"filtered-vector":68,"gl-mat4/fromQuat":95,"gl-mat4/invert":98,"gl-mat4/lookAt":99}],264:[function(t,e,r){
/*!
 * pad-left <https://github.com/jonschlinkert/pad-left>
 *
 * Copyright (c) 2014-2015, Jon Schlinkert.
 * Licensed under the MIT license.
 */
"use strict";var n=t("repeat-string");e.exports=function(t,e,r){return n(r=void 0!==r?r+"":" ",e)+t}},{"repeat-string":277}],265:[function(t,e,r){e.exports=function(t,e){e||(e=[0,""]),t=String(t);var r=parseFloat(t,10);return e[0]=r,e[1]=t.match(/[\d.\-\+]*\s*(.*)/)[1]||"",e}},{}],266:[function(t,e,r){"use strict";e.exports=function(t,e){for(var r=0|e.length,i=t.length,a=[new Array(r),new Array(r)],o=0;o<r;++o)a[0][o]=[],a[1][o]=[];for(o=0;o<i;++o){var s=t[o];a[0][s[0]].push(s),a[1][s[1]].push(s)}var l=[];for(o=0;o<r;++o)a[0][o].length+a[1][o].length===0&&l.push([o]);function c(t,e){var r=a[e][t[e]];r.splice(r.indexOf(t),1)}function u(t,r,i){for(var o,s,l,u=0;u<2;++u)if(a[u][r].length>0){o=a[u][r][0],l=u;break}s=o[1^l];for(var f=0;f<2;++f)for(var h=a[f][r],p=0;p<h.length;++p){var d=h[p],m=d[1^f];n(e[t],e[r],e[s],e[m])>0&&(o=d,s=m,l=f)}return i||o&&c(o,l),s}function f(t,r){var i=a[r][t][0],o=[t];c(i,r);for(var s=i[1^r];;){for(;s!==t;)o.push(s),s=u(o[o.length-2],s,!1);if(a[0][t].length+a[1][t].length===0)break;var l=o[o.length-1],f=t,h=o[1],p=u(l,f,!0);if(n(e[l],e[f],e[h],e[p])<0)break;o.push(t),s=u(l,f)}return o}function h(t,e){return e[1]===e[e.length-1]}for(o=0;o<r;++o)for(var p=0;p<2;++p){for(var d=[];a[p][o].length>0;){a[0][o].length;var m=f(o,p);h(0,m)?d.push.apply(d,m):(d.length>0&&l.push(d),d=m)}d.length>0&&l.push(d)}return l};var n=t("compare-angle")},{"compare-angle":54}],267:[function(t,e,r){"use strict";e.exports=function(t,e){for(var r=n(t,e.length),i=new Array(e.length),a=new Array(e.length),o=[],s=0;s<e.length;++s){var l=r[s].length;a[s]=l,i[s]=!0,l<=1&&o.push(s)}for(;o.length>0;){var c=o.pop();i[c]=!1;var u=r[c];for(s=0;s<u.length;++s){var f=u[s];0==--a[f]&&o.push(f)}}var h=new Array(e.length),p=[];for(s=0;s<e.length;++s)if(i[s]){c=p.length;h[s]=c,p.push(e[s])}else h[s]=-1;var d=[];for(s=0;s<t.length;++s){var m=t[s];i[m[0]]&&i[m[1]]&&d.push([h[m[0]],h[m[1]]])}return[d,p]};var n=t("edges-to-adjacency-list")},{"edges-to-adjacency-list":66}],268:[function(t,e,r){"use strict";e.exports=function(t,e){var r=c(t,e);t=r[0];for(var f=(e=r[1]).length,h=(t.length,n(t,e.length)),p=0;p<f;++p)if(h[p].length%2==1)throw new Error("planar-graph-to-polyline: graph must be manifold");var d=i(t,e);var m=(d=d.filter((function(t){for(var r=t.length,n=[0],i=0;i<r;++i){var a=e[t[i]],l=e[t[(i+1)%r]],c=o(-a[0],a[1]),u=o(-a[0],l[1]),f=o(l[0],a[1]),h=o(l[0],l[1]);n=s(n,s(s(c,u),s(f,h)))}return n[n.length-1]>0}))).length,g=new Array(m),v=new Array(m);for(p=0;p<m;++p){g[p]=p;var y=new Array(m),x=d[p].map((function(t){return e[t]})),b=a([x]),_=0;t:for(var w=0;w<m;++w)if(y[w]=0,p!==w){for(var T=(H=d[w]).length,k=0;k<T;++k){var A=b(e[H[k]]);if(0!==A){A<0&&(y[w]=1,_+=1);continue t}}y[w]=1,_+=1}v[p]=[_,p,y]}v.sort((function(t,e){return e[0]-t[0]}));for(p=0;p<m;++p){var M=(y=v[p])[1],S=y[2];for(w=0;w<m;++w)S[w]&&(g[w]=M)}var E=function(t){for(var e=new Array(t),r=0;r<t;++r)e[r]=[];return e}(m);for(p=0;p<m;++p)E[p].push(g[p]),E[g[p]].push(p);var L={},C=u(f,!1);for(p=0;p<m;++p)for(T=(H=d[p]).length,w=0;w<T;++w){var P=H[w],I=H[(w+1)%T],O=Math.min(P,I)+":"+Math.max(P,I);if(O in L){var z=L[O];E[z].push(p),E[p].push(z),C[P]=C[I]=!0}else L[O]=p}function D(t){for(var e=t.length,r=0;r<e;++r)if(!C[t[r]])return!1;return!0}var R=[],F=u(m,-1);for(p=0;p<m;++p)g[p]!==p||D(d[p])?F[p]=-1:(R.push(p),F[p]=0);r=[];for(;R.length>0;){var B=R.pop(),N=E[B];l(N,(function(t,e){return t-e}));var j,U=N.length,V=F[B];if(0===V){var H=d[B];j=[H]}for(p=0;p<U;++p){var q=N[p];if(!(F[q]>=0))if(F[q]=1^V,R.push(q),0===V)D(H=d[q])||(H.reverse(),j.push(H))}0===V&&r.push(j)}return r};var n=t("edges-to-adjacency-list"),i=t("planar-dual"),a=t("point-in-big-polygon"),o=t("two-product"),s=t("robust-sum"),l=t("uniq"),c=t("./lib/trim-leaves");function u(t,e){for(var r=new Array(t),n=0;n<t;++n)r[n]=e;return r}},{"./lib/trim-leaves":267,"edges-to-adjacency-list":66,"planar-dual":266,"point-in-big-polygon":269,"robust-sum":289,"two-product":306,uniq:310}],269:[function(t,e,r){e.exports=function(t){for(var e=t.length,r=[],a=[],s=0;s<e;++s)for(var u=t[s],f=u.length,h=f-1,p=0;p<f;h=p++){var d=u[h],m=u[p];d[0]===m[0]?a.push([d,m]):r.push([d,m])}if(0===r.length)return 0===a.length?c:(g=l(a),function(t){return g(t[0],t[1])?0:1});var g;var v=i(r),y=function(t,e){return function(r){var i=o.le(e,r[0]);if(i<0)return 1;var a=t[i];if(!a){if(!(i>0&&e[i]===r[0]))return 1;a=t[i-1]}for(var s=1;a;){var l=a.key,c=n(r,l[0],l[1]);if(l[0][0]<l[1][0])if(c<0)a=a.left;else{if(!(c>0))return 0;s=-1,a=a.right}else if(c>0)a=a.left;else{if(!(c<0))return 0;s=1,a=a.right}}return s}}(v.slabs,v.coordinates);return 0===a.length?y:function(t,e){return function(r){return t(r[0],r[1])?0:e(r)}}(l(a),y)};var n=t("robust-orientation")[3],i=t("slab-decomposition"),a=t("interval-tree-1d"),o=t("binary-search-bounds");function s(){return!0}function l(t){for(var e={},r=0;r<t.length;++r){var n=t[r],i=n[0][0],o=n[0][1],l=n[1][1],c=[Math.min(o,l),Math.max(o,l)];i in e?e[i].push(c):e[i]=[c]}var u={},f=Object.keys(e);for(r=0;r<f.length;++r){var h=e[f[r]];u[f[r]]=a(h)}return function(t){return function(e,r){var n=t[e];return!!n&&!!n.queryPoint(r,s)}}(u)}function c(t){return 1}},{"binary-search-bounds":31,"interval-tree-1d":234,"robust-orientation":284,"slab-decomposition":299}],270:[function(t,e,r){"use strict";var n=new Float64Array(4),i=new Float64Array(4),a=new Float64Array(4);e.exports=function(t,e,r,o,s){n.length<o.length&&(n=new Float64Array(o.length),i=new Float64Array(o.length),a=new Float64Array(o.length));for(var l=0;l<o.length;++l)n[l]=t[l]-o[l],i[l]=e[l]-t[l],a[l]=r[l]-t[l];var c=0,u=0,f=0,h=0,p=0,d=0;for(l=0;l<o.length;++l){var m=i[l],g=a[l],v=n[l];c+=m*m,u+=m*g,f+=g*g,h+=v*m,p+=v*g,d+=v*v}var y,x,b,_,w,T=Math.abs(c*f-u*u),k=u*p-f*h,A=u*h-c*p;if(k+A<=T)if(k<0)A<0&&h<0?(A=0,-h>=c?(k=1,y=c+2*h+d):y=h*(k=-h/c)+d):(k=0,p>=0?(A=0,y=d):-p>=f?(A=1,y=f+2*p+d):y=p*(A=-p/f)+d);else if(A<0)A=0,h>=0?(k=0,y=d):-h>=c?(k=1,y=c+2*h+d):y=h*(k=-h/c)+d;else{var M=1/T;y=(k*=M)*(c*k+u*(A*=M)+2*h)+A*(u*k+f*A+2*p)+d}else k<0?(b=f+p)>(x=u+h)?(_=b-x)>=(w=c-2*u+f)?(k=1,A=0,y=c+2*h+d):y=(k=_/w)*(c*k+u*(A=1-k)+2*h)+A*(u*k+f*A+2*p)+d:(k=0,b<=0?(A=1,y=f+2*p+d):p>=0?(A=0,y=d):y=p*(A=-p/f)+d):A<0?(b=c+h)>(x=u+p)?(_=b-x)>=(w=c-2*u+f)?(A=1,k=0,y=f+2*p+d):y=(k=1-(A=_/w))*(c*k+u*A+2*h)+A*(u*k+f*A+2*p)+d:(A=0,b<=0?(k=1,y=c+2*h+d):h>=0?(k=0,y=d):y=h*(k=-h/c)+d):(_=f+p-u-h)<=0?(k=0,A=1,y=f+2*p+d):_>=(w=c-2*u+f)?(k=1,A=0,y=c+2*h+d):y=(k=_/w)*(c*k+u*(A=1-k)+2*h)+A*(u*k+f*A+2*p)+d;var S=1-k-A;for(l=0;l<o.length;++l)s[l]=S*t[l]+k*e[l]+A*r[l];return y<0?0:y}},{}],271:[function(t,e,r){e.exports=t("gl-quat/slerp")},{"gl-quat/slerp":124}],272:[function(t,e,r){"use strict";var n=t("big-rat/add");e.exports=function(t,e){for(var r=t.length,i=new Array(r),a=0;a<r;++a)i[a]=n(t[a],e[a]);return i}},{"big-rat/add":15}],273:[function(t,e,r){"use strict";e.exports=function(t){for(var e=new Array(t.length),r=0;r<t.length;++r)e[r]=n(t[r]);return e};var n=t("big-rat")},{"big-rat":18}],274:[function(t,e,r){"use strict";var n=t("big-rat"),i=t("big-rat/mul");e.exports=function(t,e){for(var r=n(e),a=t.length,o=new Array(a),s=0;s<a;++s)o[s]=i(t[s],r);return o}},{"big-rat":18,"big-rat/mul":27}],275:[function(t,e,r){"use strict";var n=t("big-rat/sub");e.exports=function(t,e){for(var r=t.length,i=new Array(r),a=0;a<r;++a)i[a]=n(t[a],e[a]);return i}},{"big-rat/sub":29}],276:[function(t,e,r){"use strict";var n=t("compare-cell"),i=t("compare-oriented-cell"),a=t("cell-orientation");e.exports=function(t){t.sort(i);for(var e=t.length,r=0,o=0;o<e;++o){var s=t[o],l=a(s);if(0!==l){if(r>0){var c=t[r-1];if(0===n(s,c)&&a(c)!==l){r-=1;continue}}t[r++]=s}}return t.length=r,t}},{"cell-orientation":47,"compare-cell":56,"compare-oriented-cell":57}],277:[function(t,e,r){
/*!
 * repeat-string <https://github.com/jonschlinkert/repeat-string>
 *
 * Copyright (c) 2014-2015, Jon Schlinkert.
 * Licensed under the MIT License.
 */
"use strict";var n,i="";e.exports=function(t,e){if("string"!=typeof t)throw new TypeError("expected a string");if(1===e)return t;if(2===e)return t+t;var r=t.length*e;if(n!==t||void 0===n)n=t,i="";else if(i.length>=r)return i.substr(0,r);for(;r>i.length&&e>1;)1&e&&(i+=t),e>>=1,t+=t;return i=(i+=t).substr(0,r)}},{}],278:[function(t,e,r){(function(t){(function(){e.exports=t.performance&&t.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this)}).call(this,void 0!==n?n:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],279:[function(t,e,r){"use strict";e.exports=function(t){for(var e=t.length,r=t[t.length-1],n=e,i=e-2;i>=0;--i){var a=r,o=t[i];(l=o-((r=a+o)-a))&&(t[--n]=r,r=l)}var s=0;for(i=n;i<e;++i){var l;a=t[i];(l=(o=r)-((r=a+o)-a))&&(t[s++]=l)}return t[s++]=r,t.length=s,t}},{}],280:[function(t,e,r){"use strict";var n=t("two-product"),i=t("robust-sum"),a=t("robust-scale"),o=t("robust-compress");function s(t,e,r,n){return function(e){return n(t(r(e[0][0],e[1][1]),r(-e[0][1],e[1][0])))}}function l(t,e,r,n){return function(i){return n(t(e(t(r(i[1][1],i[2][2]),r(-i[1][2],i[2][1])),i[0][0]),t(e(t(r(i[1][0],i[2][2]),r(-i[1][2],i[2][0])),-i[0][1]),e(t(r(i[1][0],i[2][1]),r(-i[1][1],i[2][0])),i[0][2]))))}}function c(t,e,r,n){return function(i){return n(t(t(e(t(e(t(r(i[2][2],i[3][3]),r(-i[2][3],i[3][2])),i[1][1]),t(e(t(r(i[2][1],i[3][3]),r(-i[2][3],i[3][1])),-i[1][2]),e(t(r(i[2][1],i[3][2]),r(-i[2][2],i[3][1])),i[1][3]))),i[0][0]),e(t(e(t(r(i[2][2],i[3][3]),r(-i[2][3],i[3][2])),i[1][0]),t(e(t(r(i[2][0],i[3][3]),r(-i[2][3],i[3][0])),-i[1][2]),e(t(r(i[2][0],i[3][2]),r(-i[2][2],i[3][0])),i[1][3]))),-i[0][1])),t(e(t(e(t(r(i[2][1],i[3][3]),r(-i[2][3],i[3][1])),i[1][0]),t(e(t(r(i[2][0],i[3][3]),r(-i[2][3],i[3][0])),-i[1][1]),e(t(r(i[2][0],i[3][1]),r(-i[2][1],i[3][0])),i[1][3]))),i[0][2]),e(t(e(t(r(i[2][1],i[3][2]),r(-i[2][2],i[3][1])),i[1][0]),t(e(t(r(i[2][0],i[3][2]),r(-i[2][2],i[3][0])),-i[1][1]),e(t(r(i[2][0],i[3][1]),r(-i[2][1],i[3][0])),i[1][2]))),-i[0][3]))))}}function u(t,e,r,n){return function(i){return n(t(t(e(t(t(e(t(e(t(r(i[3][3],i[4][4]),r(-i[3][4],i[4][3])),i[2][2]),t(e(t(r(i[3][2],i[4][4]),r(-i[3][4],i[4][2])),-i[2][3]),e(t(r(i[3][2],i[4][3]),r(-i[3][3],i[4][2])),i[2][4]))),i[1][1]),e(t(e(t(r(i[3][3],i[4][4]),r(-i[3][4],i[4][3])),i[2][1]),t(e(t(r(i[3][1],i[4][4]),r(-i[3][4],i[4][1])),-i[2][3]),e(t(r(i[3][1],i[4][3]),r(-i[3][3],i[4][1])),i[2][4]))),-i[1][2])),t(e(t(e(t(r(i[3][2],i[4][4]),r(-i[3][4],i[4][2])),i[2][1]),t(e(t(r(i[3][1],i[4][4]),r(-i[3][4],i[4][1])),-i[2][2]),e(t(r(i[3][1],i[4][2]),r(-i[3][2],i[4][1])),i[2][4]))),i[1][3]),e(t(e(t(r(i[3][2],i[4][3]),r(-i[3][3],i[4][2])),i[2][1]),t(e(t(r(i[3][1],i[4][3]),r(-i[3][3],i[4][1])),-i[2][2]),e(t(r(i[3][1],i[4][2]),r(-i[3][2],i[4][1])),i[2][3]))),-i[1][4]))),i[0][0]),e(t(t(e(t(e(t(r(i[3][3],i[4][4]),r(-i[3][4],i[4][3])),i[2][2]),t(e(t(r(i[3][2],i[4][4]),r(-i[3][4],i[4][2])),-i[2][3]),e(t(r(i[3][2],i[4][3]),r(-i[3][3],i[4][2])),i[2][4]))),i[1][0]),e(t(e(t(r(i[3][3],i[4][4]),r(-i[3][4],i[4][3])),i[2][0]),t(e(t(r(i[3][0],i[4][4]),r(-i[3][4],i[4][0])),-i[2][3]),e(t(r(i[3][0],i[4][3]),r(-i[3][3],i[4][0])),i[2][4]))),-i[1][2])),t(e(t(e(t(r(i[3][2],i[4][4]),r(-i[3][4],i[4][2])),i[2][0]),t(e(t(r(i[3][0],i[4][4]),r(-i[3][4],i[4][0])),-i[2][2]),e(t(r(i[3][0],i[4][2]),r(-i[3][2],i[4][0])),i[2][4]))),i[1][3]),e(t(e(t(r(i[3][2],i[4][3]),r(-i[3][3],i[4][2])),i[2][0]),t(e(t(r(i[3][0],i[4][3]),r(-i[3][3],i[4][0])),-i[2][2]),e(t(r(i[3][0],i[4][2]),r(-i[3][2],i[4][0])),i[2][3]))),-i[1][4]))),-i[0][1])),t(e(t(t(e(t(e(t(r(i[3][3],i[4][4]),r(-i[3][4],i[4][3])),i[2][1]),t(e(t(r(i[3][1],i[4][4]),r(-i[3][4],i[4][1])),-i[2][3]),e(t(r(i[3][1],i[4][3]),r(-i[3][3],i[4][1])),i[2][4]))),i[1][0]),e(t(e(t(r(i[3][3],i[4][4]),r(-i[3][4],i[4][3])),i[2][0]),t(e(t(r(i[3][0],i[4][4]),r(-i[3][4],i[4][0])),-i[2][3]),e(t(r(i[3][0],i[4][3]),r(-i[3][3],i[4][0])),i[2][4]))),-i[1][1])),t(e(t(e(t(r(i[3][1],i[4][4]),r(-i[3][4],i[4][1])),i[2][0]),t(e(t(r(i[3][0],i[4][4]),r(-i[3][4],i[4][0])),-i[2][1]),e(t(r(i[3][0],i[4][1]),r(-i[3][1],i[4][0])),i[2][4]))),i[1][3]),e(t(e(t(r(i[3][1],i[4][3]),r(-i[3][3],i[4][1])),i[2][0]),t(e(t(r(i[3][0],i[4][3]),r(-i[3][3],i[4][0])),-i[2][1]),e(t(r(i[3][0],i[4][1]),r(-i[3][1],i[4][0])),i[2][3]))),-i[1][4]))),i[0][2]),t(e(t(t(e(t(e(t(r(i[3][2],i[4][4]),r(-i[3][4],i[4][2])),i[2][1]),t(e(t(r(i[3][1],i[4][4]),r(-i[3][4],i[4][1])),-i[2][2]),e(t(r(i[3][1],i[4][2]),r(-i[3][2],i[4][1])),i[2][4]))),i[1][0]),e(t(e(t(r(i[3][2],i[4][4]),r(-i[3][4],i[4][2])),i[2][0]),t(e(t(r(i[3][0],i[4][4]),r(-i[3][4],i[4][0])),-i[2][2]),e(t(r(i[3][0],i[4][2]),r(-i[3][2],i[4][0])),i[2][4]))),-i[1][1])),t(e(t(e(t(r(i[3][1],i[4][4]),r(-i[3][4],i[4][1])),i[2][0]),t(e(t(r(i[3][0],i[4][4]),r(-i[3][4],i[4][0])),-i[2][1]),e(t(r(i[3][0],i[4][1]),r(-i[3][1],i[4][0])),i[2][4]))),i[1][2]),e(t(e(t(r(i[3][1],i[4][2]),r(-i[3][2],i[4][1])),i[2][0]),t(e(t(r(i[3][0],i[4][2]),r(-i[3][2],i[4][0])),-i[2][1]),e(t(r(i[3][0],i[4][1]),r(-i[3][1],i[4][0])),i[2][2]))),-i[1][4]))),-i[0][3]),e(t(t(e(t(e(t(r(i[3][2],i[4][3]),r(-i[3][3],i[4][2])),i[2][1]),t(e(t(r(i[3][1],i[4][3]),r(-i[3][3],i[4][1])),-i[2][2]),e(t(r(i[3][1],i[4][2]),r(-i[3][2],i[4][1])),i[2][3]))),i[1][0]),e(t(e(t(r(i[3][2],i[4][3]),r(-i[3][3],i[4][2])),i[2][0]),t(e(t(r(i[3][0],i[4][3]),r(-i[3][3],i[4][0])),-i[2][2]),e(t(r(i[3][0],i[4][2]),r(-i[3][2],i[4][0])),i[2][3]))),-i[1][1])),t(e(t(e(t(r(i[3][1],i[4][3]),r(-i[3][3],i[4][1])),i[2][0]),t(e(t(r(i[3][0],i[4][3]),r(-i[3][3],i[4][0])),-i[2][1]),e(t(r(i[3][0],i[4][1]),r(-i[3][1],i[4][0])),i[2][3]))),i[1][2]),e(t(e(t(r(i[3][1],i[4][2]),r(-i[3][2],i[4][1])),i[2][0]),t(e(t(r(i[3][0],i[4][2]),r(-i[3][2],i[4][0])),-i[2][1]),e(t(r(i[3][0],i[4][1]),r(-i[3][1],i[4][0])),i[2][2]))),-i[1][3]))),i[0][4])))))}}function f(t){return(2===t?s:3===t?l:4===t?c:5===t?u:void 0)(i,a,n,o)}var h=[function(){return[0]},function(t){return[t[0][0]]}];function p(t,e,r,n,i,a,o,s){return function(l){switch(l.length){case 0:return t(l);case 1:return e(l);case 2:return r(l);case 3:return n(l);case 4:return i(l);case 5:return a(l)}var c=o[l.length];return c||(c=o[l.length]=s(l.length)),c(l)}}!function(){for(;h.length<6;)h.push(f(h.length));e.exports=p.apply(void 0,h.concat([h,f]));for(var t=0;t<h.length;++t)e.exports[t]=h[t]}()},{"robust-compress":279,"robust-scale":286,"robust-sum":289,"two-product":306}],281:[function(t,e,r){"use strict";var n=t("two-product"),i=t("robust-sum");e.exports=function(t,e){for(var r=n(t[0],e[0]),a=1;a<t.length;++a)r=i(r,n(t[a],e[a]));return r}},{"robust-sum":289,"two-product":306}],282:[function(t,e,r){"use strict";var n=t("two-product"),i=t("robust-sum"),a=t("robust-subtract"),o=t("robust-scale");function s(t){return(3===t?l:4===t?c:5===t?u:f)(i,a,n,o)}function l(t,e,r,n){return function(i,a,o){var s=r(i[0],i[0]),l=n(s,a[0]),c=n(s,o[0]),u=r(a[0],a[0]),f=n(u,i[0]),h=n(u,o[0]),p=r(o[0],o[0]),d=n(p,i[0]),m=n(p,a[0]),g=t(e(m,h),e(f,l)),v=e(d,c),y=e(g,v);return y[y.length-1]}}function c(t,e,r,n){return function(i,a,o,s){var l=t(r(i[0],i[0]),r(i[1],i[1])),c=n(l,a[0]),u=n(l,o[0]),f=n(l,s[0]),h=t(r(a[0],a[0]),r(a[1],a[1])),p=n(h,i[0]),d=n(h,o[0]),m=n(h,s[0]),g=t(r(o[0],o[0]),r(o[1],o[1])),v=n(g,i[0]),y=n(g,a[0]),x=n(g,s[0]),b=t(r(s[0],s[0]),r(s[1],s[1])),_=n(b,i[0]),w=n(b,a[0]),T=n(b,o[0]),k=t(t(n(e(T,x),a[1]),t(n(e(w,m),-o[1]),n(e(y,d),s[1]))),t(n(e(w,m),i[1]),t(n(e(_,f),-a[1]),n(e(p,c),s[1])))),A=t(t(n(e(T,x),i[1]),t(n(e(_,f),-o[1]),n(e(v,u),s[1]))),t(n(e(y,d),i[1]),t(n(e(v,u),-a[1]),n(e(p,c),o[1])))),M=e(k,A);return M[M.length-1]}}function u(t,e,r,n){return function(i,a,o,s,l){var c=t(r(i[0],i[0]),t(r(i[1],i[1]),r(i[2],i[2]))),u=n(c,a[0]),f=n(c,o[0]),h=n(c,s[0]),p=n(c,l[0]),d=t(r(a[0],a[0]),t(r(a[1],a[1]),r(a[2],a[2]))),m=n(d,i[0]),g=n(d,o[0]),v=n(d,s[0]),y=n(d,l[0]),x=t(r(o[0],o[0]),t(r(o[1],o[1]),r(o[2],o[2]))),b=n(x,i[0]),_=n(x,a[0]),w=n(x,s[0]),T=n(x,l[0]),k=t(r(s[0],s[0]),t(r(s[1],s[1]),r(s[2],s[2]))),A=n(k,i[0]),M=n(k,a[0]),S=n(k,o[0]),E=n(k,l[0]),L=t(r(l[0],l[0]),t(r(l[1],l[1]),r(l[2],l[2]))),C=n(L,i[0]),P=n(L,a[0]),I=n(L,o[0]),O=n(L,s[0]),z=t(t(t(n(t(n(e(O,E),o[1]),t(n(e(I,T),-s[1]),n(e(S,w),l[1]))),a[2]),t(n(t(n(e(O,E),a[1]),t(n(e(P,y),-s[1]),n(e(M,v),l[1]))),-o[2]),n(t(n(e(I,T),a[1]),t(n(e(P,y),-o[1]),n(e(_,g),l[1]))),s[2]))),t(n(t(n(e(S,w),a[1]),t(n(e(M,v),-o[1]),n(e(_,g),s[1]))),-l[2]),t(n(t(n(e(O,E),a[1]),t(n(e(P,y),-s[1]),n(e(M,v),l[1]))),i[2]),n(t(n(e(O,E),i[1]),t(n(e(C,p),-s[1]),n(e(A,h),l[1]))),-a[2])))),t(t(n(t(n(e(P,y),i[1]),t(n(e(C,p),-a[1]),n(e(m,u),l[1]))),s[2]),t(n(t(n(e(M,v),i[1]),t(n(e(A,h),-a[1]),n(e(m,u),s[1]))),-l[2]),n(t(n(e(S,w),a[1]),t(n(e(M,v),-o[1]),n(e(_,g),s[1]))),i[2]))),t(n(t(n(e(S,w),i[1]),t(n(e(A,h),-o[1]),n(e(b,f),s[1]))),-a[2]),t(n(t(n(e(M,v),i[1]),t(n(e(A,h),-a[1]),n(e(m,u),s[1]))),o[2]),n(t(n(e(_,g),i[1]),t(n(e(b,f),-a[1]),n(e(m,u),o[1]))),-s[2]))))),D=t(t(t(n(t(n(e(O,E),o[1]),t(n(e(I,T),-s[1]),n(e(S,w),l[1]))),i[2]),n(t(n(e(O,E),i[1]),t(n(e(C,p),-s[1]),n(e(A,h),l[1]))),-o[2])),t(n(t(n(e(I,T),i[1]),t(n(e(C,p),-o[1]),n(e(b,f),l[1]))),s[2]),n(t(n(e(S,w),i[1]),t(n(e(A,h),-o[1]),n(e(b,f),s[1]))),-l[2]))),t(t(n(t(n(e(I,T),a[1]),t(n(e(P,y),-o[1]),n(e(_,g),l[1]))),i[2]),n(t(n(e(I,T),i[1]),t(n(e(C,p),-o[1]),n(e(b,f),l[1]))),-a[2])),t(n(t(n(e(P,y),i[1]),t(n(e(C,p),-a[1]),n(e(m,u),l[1]))),o[2]),n(t(n(e(_,g),i[1]),t(n(e(b,f),-a[1]),n(e(m,u),o[1]))),-l[2])))),R=e(z,D);return R[R.length-1]}}function f(t,e,r,n){return function(i,a,o,s,l,c){var u=t(t(r(i[0],i[0]),r(i[1],i[1])),t(r(i[2],i[2]),r(i[3],i[3]))),f=n(u,a[0]),h=n(u,o[0]),p=n(u,s[0]),d=n(u,l[0]),m=n(u,c[0]),g=t(t(r(a[0],a[0]),r(a[1],a[1])),t(r(a[2],a[2]),r(a[3],a[3]))),v=n(g,i[0]),y=n(g,o[0]),x=n(g,s[0]),b=n(g,l[0]),_=n(g,c[0]),w=t(t(r(o[0],o[0]),r(o[1],o[1])),t(r(o[2],o[2]),r(o[3],o[3]))),T=n(w,i[0]),k=n(w,a[0]),A=n(w,s[0]),M=n(w,l[0]),S=n(w,c[0]),E=t(t(r(s[0],s[0]),r(s[1],s[1])),t(r(s[2],s[2]),r(s[3],s[3]))),L=n(E,i[0]),C=n(E,a[0]),P=n(E,o[0]),I=n(E,l[0]),O=n(E,c[0]),z=t(t(r(l[0],l[0]),r(l[1],l[1])),t(r(l[2],l[2]),r(l[3],l[3]))),D=n(z,i[0]),R=n(z,a[0]),F=n(z,o[0]),B=n(z,s[0]),N=n(z,c[0]),j=t(t(r(c[0],c[0]),r(c[1],c[1])),t(r(c[2],c[2]),r(c[3],c[3]))),U=n(j,i[0]),V=n(j,a[0]),H=n(j,o[0]),q=n(j,s[0]),G=n(j,l[0]),Y=t(t(t(n(t(t(n(t(n(e(G,N),s[1]),t(n(e(q,O),-l[1]),n(e(B,I),c[1]))),o[2]),n(t(n(e(G,N),o[1]),t(n(e(H,S),-l[1]),n(e(F,M),c[1]))),-s[2])),t(n(t(n(e(q,O),o[1]),t(n(e(H,S),-s[1]),n(e(P,A),c[1]))),l[2]),n(t(n(e(B,I),o[1]),t(n(e(F,M),-s[1]),n(e(P,A),l[1]))),-c[2]))),a[3]),t(n(t(t(n(t(n(e(G,N),s[1]),t(n(e(q,O),-l[1]),n(e(B,I),c[1]))),a[2]),n(t(n(e(G,N),a[1]),t(n(e(V,_),-l[1]),n(e(R,b),c[1]))),-s[2])),t(n(t(n(e(q,O),a[1]),t(n(e(V,_),-s[1]),n(e(C,x),c[1]))),l[2]),n(t(n(e(B,I),a[1]),t(n(e(R,b),-s[1]),n(e(C,x),l[1]))),-c[2]))),-o[3]),n(t(t(n(t(n(e(G,N),o[1]),t(n(e(H,S),-l[1]),n(e(F,M),c[1]))),a[2]),n(t(n(e(G,N),a[1]),t(n(e(V,_),-l[1]),n(e(R,b),c[1]))),-o[2])),t(n(t(n(e(H,S),a[1]),t(n(e(V,_),-o[1]),n(e(k,y),c[1]))),l[2]),n(t(n(e(F,M),a[1]),t(n(e(R,b),-o[1]),n(e(k,y),l[1]))),-c[2]))),s[3]))),t(t(n(t(t(n(t(n(e(q,O),o[1]),t(n(e(H,S),-s[1]),n(e(P,A),c[1]))),a[2]),n(t(n(e(q,O),a[1]),t(n(e(V,_),-s[1]),n(e(C,x),c[1]))),-o[2])),t(n(t(n(e(H,S),a[1]),t(n(e(V,_),-o[1]),n(e(k,y),c[1]))),s[2]),n(t(n(e(P,A),a[1]),t(n(e(C,x),-o[1]),n(e(k,y),s[1]))),-c[2]))),-l[3]),n(t(t(n(t(n(e(B,I),o[1]),t(n(e(F,M),-s[1]),n(e(P,A),l[1]))),a[2]),n(t(n(e(B,I),a[1]),t(n(e(R,b),-s[1]),n(e(C,x),l[1]))),-o[2])),t(n(t(n(e(F,M),a[1]),t(n(e(R,b),-o[1]),n(e(k,y),l[1]))),s[2]),n(t(n(e(P,A),a[1]),t(n(e(C,x),-o[1]),n(e(k,y),s[1]))),-l[2]))),c[3])),t(n(t(t(n(t(n(e(G,N),s[1]),t(n(e(q,O),-l[1]),n(e(B,I),c[1]))),a[2]),n(t(n(e(G,N),a[1]),t(n(e(V,_),-l[1]),n(e(R,b),c[1]))),-s[2])),t(n(t(n(e(q,O),a[1]),t(n(e(V,_),-s[1]),n(e(C,x),c[1]))),l[2]),n(t(n(e(B,I),a[1]),t(n(e(R,b),-s[1]),n(e(C,x),l[1]))),-c[2]))),i[3]),n(t(t(n(t(n(e(G,N),s[1]),t(n(e(q,O),-l[1]),n(e(B,I),c[1]))),i[2]),n(t(n(e(G,N),i[1]),t(n(e(U,m),-l[1]),n(e(D,d),c[1]))),-s[2])),t(n(t(n(e(q,O),i[1]),t(n(e(U,m),-s[1]),n(e(L,p),c[1]))),l[2]),n(t(n(e(B,I),i[1]),t(n(e(D,d),-s[1]),n(e(L,p),l[1]))),-c[2]))),-a[3])))),t(t(t(n(t(t(n(t(n(e(G,N),a[1]),t(n(e(V,_),-l[1]),n(e(R,b),c[1]))),i[2]),n(t(n(e(G,N),i[1]),t(n(e(U,m),-l[1]),n(e(D,d),c[1]))),-a[2])),t(n(t(n(e(V,_),i[1]),t(n(e(U,m),-a[1]),n(e(v,f),c[1]))),l[2]),n(t(n(e(R,b),i[1]),t(n(e(D,d),-a[1]),n(e(v,f),l[1]))),-c[2]))),s[3]),n(t(t(n(t(n(e(q,O),a[1]),t(n(e(V,_),-s[1]),n(e(C,x),c[1]))),i[2]),n(t(n(e(q,O),i[1]),t(n(e(U,m),-s[1]),n(e(L,p),c[1]))),-a[2])),t(n(t(n(e(V,_),i[1]),t(n(e(U,m),-a[1]),n(e(v,f),c[1]))),s[2]),n(t(n(e(C,x),i[1]),t(n(e(L,p),-a[1]),n(e(v,f),s[1]))),-c[2]))),-l[3])),t(n(t(t(n(t(n(e(B,I),a[1]),t(n(e(R,b),-s[1]),n(e(C,x),l[1]))),i[2]),n(t(n(e(B,I),i[1]),t(n(e(D,d),-s[1]),n(e(L,p),l[1]))),-a[2])),t(n(t(n(e(R,b),i[1]),t(n(e(D,d),-a[1]),n(e(v,f),l[1]))),s[2]),n(t(n(e(C,x),i[1]),t(n(e(L,p),-a[1]),n(e(v,f),s[1]))),-l[2]))),c[3]),n(t(t(n(t(n(e(q,O),o[1]),t(n(e(H,S),-s[1]),n(e(P,A),c[1]))),a[2]),n(t(n(e(q,O),a[1]),t(n(e(V,_),-s[1]),n(e(C,x),c[1]))),-o[2])),t(n(t(n(e(H,S),a[1]),t(n(e(V,_),-o[1]),n(e(k,y),c[1]))),s[2]),n(t(n(e(P,A),a[1]),t(n(e(C,x),-o[1]),n(e(k,y),s[1]))),-c[2]))),i[3]))),t(t(n(t(t(n(t(n(e(q,O),o[1]),t(n(e(H,S),-s[1]),n(e(P,A),c[1]))),i[2]),n(t(n(e(q,O),i[1]),t(n(e(U,m),-s[1]),n(e(L,p),c[1]))),-o[2])),t(n(t(n(e(H,S),i[1]),t(n(e(U,m),-o[1]),n(e(T,h),c[1]))),s[2]),n(t(n(e(P,A),i[1]),t(n(e(L,p),-o[1]),n(e(T,h),s[1]))),-c[2]))),-a[3]),n(t(t(n(t(n(e(q,O),a[1]),t(n(e(V,_),-s[1]),n(e(C,x),c[1]))),i[2]),n(t(n(e(q,O),i[1]),t(n(e(U,m),-s[1]),n(e(L,p),c[1]))),-a[2])),t(n(t(n(e(V,_),i[1]),t(n(e(U,m),-a[1]),n(e(v,f),c[1]))),s[2]),n(t(n(e(C,x),i[1]),t(n(e(L,p),-a[1]),n(e(v,f),s[1]))),-c[2]))),o[3])),t(n(t(t(n(t(n(e(H,S),a[1]),t(n(e(V,_),-o[1]),n(e(k,y),c[1]))),i[2]),n(t(n(e(H,S),i[1]),t(n(e(U,m),-o[1]),n(e(T,h),c[1]))),-a[2])),t(n(t(n(e(V,_),i[1]),t(n(e(U,m),-a[1]),n(e(v,f),c[1]))),o[2]),n(t(n(e(k,y),i[1]),t(n(e(T,h),-a[1]),n(e(v,f),o[1]))),-c[2]))),-s[3]),n(t(t(n(t(n(e(P,A),a[1]),t(n(e(C,x),-o[1]),n(e(k,y),s[1]))),i[2]),n(t(n(e(P,A),i[1]),t(n(e(L,p),-o[1]),n(e(T,h),s[1]))),-a[2])),t(n(t(n(e(C,x),i[1]),t(n(e(L,p),-a[1]),n(e(v,f),s[1]))),o[2]),n(t(n(e(k,y),i[1]),t(n(e(T,h),-a[1]),n(e(v,f),o[1]))),-s[2]))),c[3]))))),W=t(t(t(n(t(t(n(t(n(e(G,N),s[1]),t(n(e(q,O),-l[1]),n(e(B,I),c[1]))),o[2]),n(t(n(e(G,N),o[1]),t(n(e(H,S),-l[1]),n(e(F,M),c[1]))),-s[2])),t(n(t(n(e(q,O),o[1]),t(n(e(H,S),-s[1]),n(e(P,A),c[1]))),l[2]),n(t(n(e(B,I),o[1]),t(n(e(F,M),-s[1]),n(e(P,A),l[1]))),-c[2]))),i[3]),t(n(t(t(n(t(n(e(G,N),s[1]),t(n(e(q,O),-l[1]),n(e(B,I),c[1]))),i[2]),n(t(n(e(G,N),i[1]),t(n(e(U,m),-l[1]),n(e(D,d),c[1]))),-s[2])),t(n(t(n(e(q,O),i[1]),t(n(e(U,m),-s[1]),n(e(L,p),c[1]))),l[2]),n(t(n(e(B,I),i[1]),t(n(e(D,d),-s[1]),n(e(L,p),l[1]))),-c[2]))),-o[3]),n(t(t(n(t(n(e(G,N),o[1]),t(n(e(H,S),-l[1]),n(e(F,M),c[1]))),i[2]),n(t(n(e(G,N),i[1]),t(n(e(U,m),-l[1]),n(e(D,d),c[1]))),-o[2])),t(n(t(n(e(H,S),i[1]),t(n(e(U,m),-o[1]),n(e(T,h),c[1]))),l[2]),n(t(n(e(F,M),i[1]),t(n(e(D,d),-o[1]),n(e(T,h),l[1]))),-c[2]))),s[3]))),t(t(n(t(t(n(t(n(e(q,O),o[1]),t(n(e(H,S),-s[1]),n(e(P,A),c[1]))),i[2]),n(t(n(e(q,O),i[1]),t(n(e(U,m),-s[1]),n(e(L,p),c[1]))),-o[2])),t(n(t(n(e(H,S),i[1]),t(n(e(U,m),-o[1]),n(e(T,h),c[1]))),s[2]),n(t(n(e(P,A),i[1]),t(n(e(L,p),-o[1]),n(e(T,h),s[1]))),-c[2]))),-l[3]),n(t(t(n(t(n(e(B,I),o[1]),t(n(e(F,M),-s[1]),n(e(P,A),l[1]))),i[2]),n(t(n(e(B,I),i[1]),t(n(e(D,d),-s[1]),n(e(L,p),l[1]))),-o[2])),t(n(t(n(e(F,M),i[1]),t(n(e(D,d),-o[1]),n(e(T,h),l[1]))),s[2]),n(t(n(e(P,A),i[1]),t(n(e(L,p),-o[1]),n(e(T,h),s[1]))),-l[2]))),c[3])),t(n(t(t(n(t(n(e(G,N),o[1]),t(n(e(H,S),-l[1]),n(e(F,M),c[1]))),a[2]),n(t(n(e(G,N),a[1]),t(n(e(V,_),-l[1]),n(e(R,b),c[1]))),-o[2])),t(n(t(n(e(H,S),a[1]),t(n(e(V,_),-o[1]),n(e(k,y),c[1]))),l[2]),n(t(n(e(F,M),a[1]),t(n(e(R,b),-o[1]),n(e(k,y),l[1]))),-c[2]))),i[3]),n(t(t(n(t(n(e(G,N),o[1]),t(n(e(H,S),-l[1]),n(e(F,M),c[1]))),i[2]),n(t(n(e(G,N),i[1]),t(n(e(U,m),-l[1]),n(e(D,d),c[1]))),-o[2])),t(n(t(n(e(H,S),i[1]),t(n(e(U,m),-o[1]),n(e(T,h),c[1]))),l[2]),n(t(n(e(F,M),i[1]),t(n(e(D,d),-o[1]),n(e(T,h),l[1]))),-c[2]))),-a[3])))),t(t(t(n(t(t(n(t(n(e(G,N),a[1]),t(n(e(V,_),-l[1]),n(e(R,b),c[1]))),i[2]),n(t(n(e(G,N),i[1]),t(n(e(U,m),-l[1]),n(e(D,d),c[1]))),-a[2])),t(n(t(n(e(V,_),i[1]),t(n(e(U,m),-a[1]),n(e(v,f),c[1]))),l[2]),n(t(n(e(R,b),i[1]),t(n(e(D,d),-a[1]),n(e(v,f),l[1]))),-c[2]))),o[3]),n(t(t(n(t(n(e(H,S),a[1]),t(n(e(V,_),-o[1]),n(e(k,y),c[1]))),i[2]),n(t(n(e(H,S),i[1]),t(n(e(U,m),-o[1]),n(e(T,h),c[1]))),-a[2])),t(n(t(n(e(V,_),i[1]),t(n(e(U,m),-a[1]),n(e(v,f),c[1]))),o[2]),n(t(n(e(k,y),i[1]),t(n(e(T,h),-a[1]),n(e(v,f),o[1]))),-c[2]))),-l[3])),t(n(t(t(n(t(n(e(F,M),a[1]),t(n(e(R,b),-o[1]),n(e(k,y),l[1]))),i[2]),n(t(n(e(F,M),i[1]),t(n(e(D,d),-o[1]),n(e(T,h),l[1]))),-a[2])),t(n(t(n(e(R,b),i[1]),t(n(e(D,d),-a[1]),n(e(v,f),l[1]))),o[2]),n(t(n(e(k,y),i[1]),t(n(e(T,h),-a[1]),n(e(v,f),o[1]))),-l[2]))),c[3]),n(t(t(n(t(n(e(B,I),o[1]),t(n(e(F,M),-s[1]),n(e(P,A),l[1]))),a[2]),n(t(n(e(B,I),a[1]),t(n(e(R,b),-s[1]),n(e(C,x),l[1]))),-o[2])),t(n(t(n(e(F,M),a[1]),t(n(e(R,b),-o[1]),n(e(k,y),l[1]))),s[2]),n(t(n(e(P,A),a[1]),t(n(e(C,x),-o[1]),n(e(k,y),s[1]))),-l[2]))),i[3]))),t(t(n(t(t(n(t(n(e(B,I),o[1]),t(n(e(F,M),-s[1]),n(e(P,A),l[1]))),i[2]),n(t(n(e(B,I),i[1]),t(n(e(D,d),-s[1]),n(e(L,p),l[1]))),-o[2])),t(n(t(n(e(F,M),i[1]),t(n(e(D,d),-o[1]),n(e(T,h),l[1]))),s[2]),n(t(n(e(P,A),i[1]),t(n(e(L,p),-o[1]),n(e(T,h),s[1]))),-l[2]))),-a[3]),n(t(t(n(t(n(e(B,I),a[1]),t(n(e(R,b),-s[1]),n(e(C,x),l[1]))),i[2]),n(t(n(e(B,I),i[1]),t(n(e(D,d),-s[1]),n(e(L,p),l[1]))),-a[2])),t(n(t(n(e(R,b),i[1]),t(n(e(D,d),-a[1]),n(e(v,f),l[1]))),s[2]),n(t(n(e(C,x),i[1]),t(n(e(L,p),-a[1]),n(e(v,f),s[1]))),-l[2]))),o[3])),t(n(t(t(n(t(n(e(F,M),a[1]),t(n(e(R,b),-o[1]),n(e(k,y),l[1]))),i[2]),n(t(n(e(F,M),i[1]),t(n(e(D,d),-o[1]),n(e(T,h),l[1]))),-a[2])),t(n(t(n(e(R,b),i[1]),t(n(e(D,d),-a[1]),n(e(v,f),l[1]))),o[2]),n(t(n(e(k,y),i[1]),t(n(e(T,h),-a[1]),n(e(v,f),o[1]))),-l[2]))),-s[3]),n(t(t(n(t(n(e(P,A),a[1]),t(n(e(C,x),-o[1]),n(e(k,y),s[1]))),i[2]),n(t(n(e(P,A),i[1]),t(n(e(L,p),-o[1]),n(e(T,h),s[1]))),-a[2])),t(n(t(n(e(C,x),i[1]),t(n(e(L,p),-a[1]),n(e(v,f),s[1]))),o[2]),n(t(n(e(k,y),i[1]),t(n(e(T,h),-a[1]),n(e(v,f),o[1]))),-s[2]))),l[3]))))),X=e(Y,W);return X[X.length-1]}}var h=[function(){return 0},function(){return 0},function(){return 0}];function p(t){var e=h[t.length];return e||(e=h[t.length]=s(t.length)),e.apply(void 0,t)}function d(t,e,r,n,i,a,o,s){return function(e,r,l,c,u,f){switch(arguments.length){case 0:case 1:return 0;case 2:return n(e,r);case 3:return i(e,r,l);case 4:return a(e,r,l,c);case 5:return o(e,r,l,c,u);case 6:return s(e,r,l,c,u,f)}for(var h=new Array(arguments.length),p=0;p<arguments.length;++p)h[p]=arguments[p];return t(h)}}!function(){for(;h.length<=6;)h.push(s(h.length));e.exports=d.apply(void 0,[p].concat(h));for(var t=0;t<=6;++t)e.exports[t]=h[t]}()},{"robust-scale":286,"robust-subtract":288,"robust-sum":289,"two-product":306}],283:[function(t,e,r){"use strict";var n=t("robust-determinant");function i(t){var e=2===t?a:3===t?o:4===t?s:5===t?l:c;return e(t<6?n[t]:n)}function a(t){return function(e,r){return[t([[+r[0],+e[0][1]],[+r[1],+e[1][1]]]),t([[+e[0][0],+r[0]],[+e[1][0],+r[1]]]),t(e)]}}function o(t){return function(e,r){return[t([[+r[0],+e[0][1],+e[0][2]],[+r[1],+e[1][1],+e[1][2]],[+r[2],+e[2][1],+e[2][2]]]),t([[+e[0][0],+r[0],+e[0][2]],[+e[1][0],+r[1],+e[1][2]],[+e[2][0],+r[2],+e[2][2]]]),t([[+e[0][0],+e[0][1],+r[0]],[+e[1][0],+e[1][1],+r[1]],[+e[2][0],+e[2][1],+r[2]]]),t(e)]}}function s(t){return function(e,r){return[t([[+r[0],+e[0][1],+e[0][2],+e[0][3]],[+r[1],+e[1][1],+e[1][2],+e[1][3]],[+r[2],+e[2][1],+e[2][2],+e[2][3]],[+r[3],+e[3][1],+e[3][2],+e[3][3]]]),t([[+e[0][0],+r[0],+e[0][2],+e[0][3]],[+e[1][0],+r[1],+e[1][2],+e[1][3]],[+e[2][0],+r[2],+e[2][2],+e[2][3]],[+e[3][0],+r[3],+e[3][2],+e[3][3]]]),t([[+e[0][0],+e[0][1],+r[0],+e[0][3]],[+e[1][0],+e[1][1],+r[1],+e[1][3]],[+e[2][0],+e[2][1],+r[2],+e[2][3]],[+e[3][0],+e[3][1],+r[3],+e[3][3]]]),t([[+e[0][0],+e[0][1],+e[0][2],+r[0]],[+e[1][0],+e[1][1],+e[1][2],+r[1]],[+e[2][0],+e[2][1],+e[2][2],+r[2]],[+e[3][0],+e[3][1],+e[3][2],+r[3]]]),t(e)]}}function l(t){return function(e,r){return[t([[+r[0],+e[0][1],+e[0][2],+e[0][3],+e[0][4]],[+r[1],+e[1][1],+e[1][2],+e[1][3],+e[1][4]],[+r[2],+e[2][1],+e[2][2],+e[2][3],+e[2][4]],[+r[3],+e[3][1],+e[3][2],+e[3][3],+e[3][4]],[+r[4],+e[4][1],+e[4][2],+e[4][3],+e[4][4]]]),t([[+e[0][0],+r[0],+e[0][2],+e[0][3],+e[0][4]],[+e[1][0],+r[1],+e[1][2],+e[1][3],+e[1][4]],[+e[2][0],+r[2],+e[2][2],+e[2][3],+e[2][4]],[+e[3][0],+r[3],+e[3][2],+e[3][3],+e[3][4]],[+e[4][0],+r[4],+e[4][2],+e[4][3],+e[4][4]]]),t([[+e[0][0],+e[0][1],+r[0],+e[0][3],+e[0][4]],[+e[1][0],+e[1][1],+r[1],+e[1][3],+e[1][4]],[+e[2][0],+e[2][1],+r[2],+e[2][3],+e[2][4]],[+e[3][0],+e[3][1],+r[3],+e[3][3],+e[3][4]],[+e[4][0],+e[4][1],+r[4],+e[4][3],+e[4][4]]]),t([[+e[0][0],+e[0][1],+e[0][2],+r[0],+e[0][4]],[+e[1][0],+e[1][1],+e[1][2],+r[1],+e[1][4]],[+e[2][0],+e[2][1],+e[2][2],+r[2],+e[2][4]],[+e[3][0],+e[3][1],+e[3][2],+r[3],+e[3][4]],[+e[4][0],+e[4][1],+e[4][2],+r[4],+e[4][4]]]),t([[+e[0][0],+e[0][1],+e[0][2],+e[0][3],+r[0]],[+e[1][0],+e[1][1],+e[1][2],+e[1][3],+r[1]],[+e[2][0],+e[2][1],+e[2][2],+e[2][3],+r[2]],[+e[3][0],+e[3][1],+e[3][2],+e[3][3],+r[3]],[+e[4][0],+e[4][1],+e[4][2],+e[4][3],+r[4]]]),t(e)]}}function c(t){return function(e,r){return[t([[+r[0],+e[0][1],+e[0][2],+e[0][3],+e[0][4],+e[0][5]],[+r[1],+e[1][1],+e[1][2],+e[1][3],+e[1][4],+e[1][5]],[+r[2],+e[2][1],+e[2][2],+e[2][3],+e[2][4],+e[2][5]],[+r[3],+e[3][1],+e[3][2],+e[3][3],+e[3][4],+e[3][5]],[+r[4],+e[4][1],+e[4][2],+e[4][3],+e[4][4],+e[4][5]],[+r[5],+e[5][1],+e[5][2],+e[5][3],+e[5][4],+e[5][5]]]),t([[+e[0][0],+r[0],+e[0][2],+e[0][3],+e[0][4],+e[0][5]],[+e[1][0],+r[1],+e[1][2],+e[1][3],+e[1][4],+e[1][5]],[+e[2][0],+r[2],+e[2][2],+e[2][3],+e[2][4],+e[2][5]],[+e[3][0],+r[3],+e[3][2],+e[3][3],+e[3][4],+e[3][5]],[+e[4][0],+r[4],+e[4][2],+e[4][3],+e[4][4],+e[4][5]],[+e[5][0],+r[5],+e[5][2],+e[5][3],+e[5][4],+e[5][5]]]),t([[+e[0][0],+e[0][1],+r[0],+e[0][3],+e[0][4],+e[0][5]],[+e[1][0],+e[1][1],+r[1],+e[1][3],+e[1][4],+e[1][5]],[+e[2][0],+e[2][1],+r[2],+e[2][3],+e[2][4],+e[2][5]],[+e[3][0],+e[3][1],+r[3],+e[3][3],+e[3][4],+e[3][5]],[+e[4][0],+e[4][1],+r[4],+e[4][3],+e[4][4],+e[4][5]],[+e[5][0],+e[5][1],+r[5],+e[5][3],+e[5][4],+e[5][5]]]),t([[+e[0][0],+e[0][1],+e[0][2],+r[0],+e[0][4],+e[0][5]],[+e[1][0],+e[1][1],+e[1][2],+r[1],+e[1][4],+e[1][5]],[+e[2][0],+e[2][1],+e[2][2],+r[2],+e[2][4],+e[2][5]],[+e[3][0],+e[3][1],+e[3][2],+r[3],+e[3][4],+e[3][5]],[+e[4][0],+e[4][1],+e[4][2],+r[4],+e[4][4],+e[4][5]],[+e[5][0],+e[5][1],+e[5][2],+r[5],+e[5][4],+e[5][5]]]),t([[+e[0][0],+e[0][1],+e[0][2],+e[0][3],+r[0],+e[0][5]],[+e[1][0],+e[1][1],+e[1][2],+e[1][3],+r[1],+e[1][5]],[+e[2][0],+e[2][1],+e[2][2],+e[2][3],+r[2],+e[2][5]],[+e[3][0],+e[3][1],+e[3][2],+e[3][3],+r[3],+e[3][5]],[+e[4][0],+e[4][1],+e[4][2],+e[4][3],+r[4],+e[4][5]],[+e[5][0],+e[5][1],+e[5][2],+e[5][3],+r[5],+e[5][5]]]),t([[+e[0][0],+e[0][1],+e[0][2],+e[0][3],+e[0][4],+r[0]],[+e[1][0],+e[1][1],+e[1][2],+e[1][3],+e[1][4],+r[1]],[+e[2][0],+e[2][1],+e[2][2],+e[2][3],+e[2][4],+r[2]],[+e[3][0],+e[3][1],+e[3][2],+e[3][3],+e[3][4],+r[3]],[+e[4][0],+e[4][1],+e[4][2],+e[4][3],+e[4][4],+r[4]],[+e[5][0],+e[5][1],+e[5][2],+e[5][3],+e[5][4],+r[5]]]),t(e)]}}var u=[function(){return[[0]]},function(t,e){return[[e[0]],[t[0][0]]]}];function f(t,e,r,n,i,a,o,s){return function(l,c){switch(l.length){case 0:return t(l,c);case 1:return e(l,c);case 2:return r(l,c);case 3:return n(l,c);case 4:return i(l,c);case 5:return a(l,c)}var u=o[l.length];return u||(u=o[l.length]=s(l.length)),u(l,c)}}!function(){for(;u.length<6;)u.push(i(u.length));e.exports=f.apply(void 0,u.concat([u,i]));for(var t=0;t<6;++t)e.exports[t]=u[t]}()},{"robust-determinant":280}],284:[function(t,e,r){"use strict";var n=t("two-product"),i=t("robust-sum"),a=t("robust-scale"),o=t("robust-subtract");function s(t,e,r,n){return function(r,i,a){var o=t(t(e(i[1],a[0]),e(-a[1],i[0])),t(e(r[1],i[0]),e(-i[1],r[0]))),s=t(e(r[1],a[0]),e(-a[1],r[0])),l=n(o,s);return l[l.length-1]}}function l(t,e,r,n){return function(i,a,o,s){var l=t(t(r(t(e(o[1],s[0]),e(-s[1],o[0])),a[2]),t(r(t(e(a[1],s[0]),e(-s[1],a[0])),-o[2]),r(t(e(a[1],o[0]),e(-o[1],a[0])),s[2]))),t(r(t(e(a[1],s[0]),e(-s[1],a[0])),i[2]),t(r(t(e(i[1],s[0]),e(-s[1],i[0])),-a[2]),r(t(e(i[1],a[0]),e(-a[1],i[0])),s[2])))),c=t(t(r(t(e(o[1],s[0]),e(-s[1],o[0])),i[2]),t(r(t(e(i[1],s[0]),e(-s[1],i[0])),-o[2]),r(t(e(i[1],o[0]),e(-o[1],i[0])),s[2]))),t(r(t(e(a[1],o[0]),e(-o[1],a[0])),i[2]),t(r(t(e(i[1],o[0]),e(-o[1],i[0])),-a[2]),r(t(e(i[1],a[0]),e(-a[1],i[0])),o[2])))),u=n(l,c);return u[u.length-1]}}function c(t,e,r,n){return function(i,a,o,s,l){var c=t(t(t(r(t(r(t(e(s[1],l[0]),e(-l[1],s[0])),o[2]),t(r(t(e(o[1],l[0]),e(-l[1],o[0])),-s[2]),r(t(e(o[1],s[0]),e(-s[1],o[0])),l[2]))),a[3]),t(r(t(r(t(e(s[1],l[0]),e(-l[1],s[0])),a[2]),t(r(t(e(a[1],l[0]),e(-l[1],a[0])),-s[2]),r(t(e(a[1],s[0]),e(-s[1],a[0])),l[2]))),-o[3]),r(t(r(t(e(o[1],l[0]),e(-l[1],o[0])),a[2]),t(r(t(e(a[1],l[0]),e(-l[1],a[0])),-o[2]),r(t(e(a[1],o[0]),e(-o[1],a[0])),l[2]))),s[3]))),t(r(t(r(t(e(o[1],s[0]),e(-s[1],o[0])),a[2]),t(r(t(e(a[1],s[0]),e(-s[1],a[0])),-o[2]),r(t(e(a[1],o[0]),e(-o[1],a[0])),s[2]))),-l[3]),t(r(t(r(t(e(s[1],l[0]),e(-l[1],s[0])),a[2]),t(r(t(e(a[1],l[0]),e(-l[1],a[0])),-s[2]),r(t(e(a[1],s[0]),e(-s[1],a[0])),l[2]))),i[3]),r(t(r(t(e(s[1],l[0]),e(-l[1],s[0])),i[2]),t(r(t(e(i[1],l[0]),e(-l[1],i[0])),-s[2]),r(t(e(i[1],s[0]),e(-s[1],i[0])),l[2]))),-a[3])))),t(t(r(t(r(t(e(a[1],l[0]),e(-l[1],a[0])),i[2]),t(r(t(e(i[1],l[0]),e(-l[1],i[0])),-a[2]),r(t(e(i[1],a[0]),e(-a[1],i[0])),l[2]))),s[3]),t(r(t(r(t(e(a[1],s[0]),e(-s[1],a[0])),i[2]),t(r(t(e(i[1],s[0]),e(-s[1],i[0])),-a[2]),r(t(e(i[1],a[0]),e(-a[1],i[0])),s[2]))),-l[3]),r(t(r(t(e(o[1],s[0]),e(-s[1],o[0])),a[2]),t(r(t(e(a[1],s[0]),e(-s[1],a[0])),-o[2]),r(t(e(a[1],o[0]),e(-o[1],a[0])),s[2]))),i[3]))),t(r(t(r(t(e(o[1],s[0]),e(-s[1],o[0])),i[2]),t(r(t(e(i[1],s[0]),e(-s[1],i[0])),-o[2]),r(t(e(i[1],o[0]),e(-o[1],i[0])),s[2]))),-a[3]),t(r(t(r(t(e(a[1],s[0]),e(-s[1],a[0])),i[2]),t(r(t(e(i[1],s[0]),e(-s[1],i[0])),-a[2]),r(t(e(i[1],a[0]),e(-a[1],i[0])),s[2]))),o[3]),r(t(r(t(e(a[1],o[0]),e(-o[1],a[0])),i[2]),t(r(t(e(i[1],o[0]),e(-o[1],i[0])),-a[2]),r(t(e(i[1],a[0]),e(-a[1],i[0])),o[2]))),-s[3]))))),u=t(t(t(r(t(r(t(e(s[1],l[0]),e(-l[1],s[0])),o[2]),t(r(t(e(o[1],l[0]),e(-l[1],o[0])),-s[2]),r(t(e(o[1],s[0]),e(-s[1],o[0])),l[2]))),i[3]),r(t(r(t(e(s[1],l[0]),e(-l[1],s[0])),i[2]),t(r(t(e(i[1],l[0]),e(-l[1],i[0])),-s[2]),r(t(e(i[1],s[0]),e(-s[1],i[0])),l[2]))),-o[3])),t(r(t(r(t(e(o[1],l[0]),e(-l[1],o[0])),i[2]),t(r(t(e(i[1],l[0]),e(-l[1],i[0])),-o[2]),r(t(e(i[1],o[0]),e(-o[1],i[0])),l[2]))),s[3]),r(t(r(t(e(o[1],s[0]),e(-s[1],o[0])),i[2]),t(r(t(e(i[1],s[0]),e(-s[1],i[0])),-o[2]),r(t(e(i[1],o[0]),e(-o[1],i[0])),s[2]))),-l[3]))),t(t(r(t(r(t(e(o[1],l[0]),e(-l[1],o[0])),a[2]),t(r(t(e(a[1],l[0]),e(-l[1],a[0])),-o[2]),r(t(e(a[1],o[0]),e(-o[1],a[0])),l[2]))),i[3]),r(t(r(t(e(o[1],l[0]),e(-l[1],o[0])),i[2]),t(r(t(e(i[1],l[0]),e(-l[1],i[0])),-o[2]),r(t(e(i[1],o[0]),e(-o[1],i[0])),l[2]))),-a[3])),t(r(t(r(t(e(a[1],l[0]),e(-l[1],a[0])),i[2]),t(r(t(e(i[1],l[0]),e(-l[1],i[0])),-a[2]),r(t(e(i[1],a[0]),e(-a[1],i[0])),l[2]))),o[3]),r(t(r(t(e(a[1],o[0]),e(-o[1],a[0])),i[2]),t(r(t(e(i[1],o[0]),e(-o[1],i[0])),-a[2]),r(t(e(i[1],a[0]),e(-a[1],i[0])),o[2]))),-l[3])))),f=n(c,u);return f[f.length-1]}}function u(t){return(3===t?s:4===t?l:c)(i,n,a,o)}var f=u(3),h=u(4),p=[function(){return 0},function(){return 0},function(t,e){return e[0]-t[0]},function(t,e,r){var n,i=(t[1]-r[1])*(e[0]-r[0]),a=(t[0]-r[0])*(e[1]-r[1]),o=i-a;if(i>0){if(a<=0)return o;n=i+a}else{if(!(i<0))return o;if(a>=0)return o;n=-(i+a)}var s=33306690738754716e-32*n;return o>=s||o<=-s?o:f(t,e,r)},function(t,e,r,n){var i=t[0]-n[0],a=e[0]-n[0],o=r[0]-n[0],s=t[1]-n[1],l=e[1]-n[1],c=r[1]-n[1],u=t[2]-n[2],f=e[2]-n[2],p=r[2]-n[2],d=a*c,m=o*l,g=o*s,v=i*c,y=i*l,x=a*s,b=u*(d-m)+f*(g-v)+p*(y-x),_=7771561172376103e-31*((Math.abs(d)+Math.abs(m))*Math.abs(u)+(Math.abs(g)+Math.abs(v))*Math.abs(f)+(Math.abs(y)+Math.abs(x))*Math.abs(p));return b>_||-b>_?b:h(t,e,r,n)}];function d(t){var e=p[t.length];return e||(e=p[t.length]=u(t.length)),e.apply(void 0,t)}function m(t,e,r,n,i,a,o){return function(e,r,s,l,c){switch(arguments.length){case 0:case 1:return 0;case 2:return n(e,r);case 3:return i(e,r,s);case 4:return a(e,r,s,l);case 5:return o(e,r,s,l,c)}for(var u=new Array(arguments.length),f=0;f<arguments.length;++f)u[f]=arguments[f];return t(u)}}!function(){for(;p.length<=5;)p.push(u(p.length));e.exports=m.apply(void 0,[d].concat(p));for(var t=0;t<=5;++t)e.exports[t]=p[t]}()},{"robust-scale":286,"robust-subtract":288,"robust-sum":289,"two-product":306}],285:[function(t,e,r){"use strict";var n=t("robust-sum"),i=t("robust-scale");e.exports=function(t,e){if(1===t.length)return i(e,t[0]);if(1===e.length)return i(t,e[0]);if(0===t.length||0===e.length)return[0];var r=[0];if(t.length<e.length)for(var a=0;a<t.length;++a)r=n(r,i(e,t[a]));else for(a=0;a<e.length;++a)r=n(r,i(t,e[a]));return r}},{"robust-scale":286,"robust-sum":289}],286:[function(t,e,r){"use strict";var n=t("two-product"),i=t("two-sum");e.exports=function(t,e){var r=t.length;if(1===r){var a=n(t[0],e);return a[0]?a:[a[1]]}var o=new Array(2*r),s=[.1,.1],l=[.1,.1],c=0;n(t[0],e,s),s[0]&&(o[c++]=s[0]);for(var u=1;u<r;++u){n(t[u],e,l);var f=s[1];i(f,l[0],s),s[0]&&(o[c++]=s[0]);var h=l[1],p=s[1],d=h+p,m=p-(d-h);s[1]=d,m&&(o[c++]=m)}s[1]&&(o[c++]=s[1]);0===c&&(o[c++]=0);return o.length=c,o}},{"two-product":306,"two-sum":307}],287:[function(t,e,r){"use strict";e.exports=function(t,e,r,i){var a=n(t,r,i),o=n(e,r,i);if(a>0&&o>0||a<0&&o<0)return!1;var s=n(r,t,e),l=n(i,t,e);if(s>0&&l>0||s<0&&l<0)return!1;if(0===a&&0===o&&0===s&&0===l)return function(t,e,r,n){for(var i=0;i<2;++i){var a=t[i],o=e[i],s=Math.min(a,o),l=Math.max(a,o),c=r[i],u=n[i],f=Math.min(c,u);if(Math.max(c,u)<s||l<f)return!1}return!0}(t,e,r,i);return!0};var n=t("robust-orientation")[3]},{"robust-orientation":284}],288:[function(t,e,r){"use strict";e.exports=function(t,e){var r=0|t.length,n=0|e.length;if(1===r&&1===n)return function(t,e){var r=t+e,n=r-t,i=t-(r-n)+(e-n);if(i)return[i,r];return[r]}(t[0],-e[0]);var i,a,o=new Array(r+n),s=0,l=0,c=0,u=Math.abs,f=t[l],h=u(f),p=-e[c],d=u(p);h<d?(a=f,(l+=1)<r&&(f=t[l],h=u(f))):(a=p,(c+=1)<n&&(p=-e[c],d=u(p)));l<r&&h<d||c>=n?(i=f,(l+=1)<r&&(f=t[l],h=u(f))):(i=p,(c+=1)<n&&(p=-e[c],d=u(p)));var m,g,v=i+a,y=v-i,x=a-y,b=x,_=v;for(;l<r&&c<n;)h<d?(i=f,(l+=1)<r&&(f=t[l],h=u(f))):(i=p,(c+=1)<n&&(p=-e[c],d=u(p))),(x=(a=b)-(y=(v=i+a)-i))&&(o[s++]=x),b=_-((m=_+v)-(g=m-_))+(v-g),_=m;for(;l<r;)(x=(a=b)-(y=(v=(i=f)+a)-i))&&(o[s++]=x),b=_-((m=_+v)-(g=m-_))+(v-g),_=m,(l+=1)<r&&(f=t[l]);for(;c<n;)(x=(a=b)-(y=(v=(i=p)+a)-i))&&(o[s++]=x),b=_-((m=_+v)-(g=m-_))+(v-g),_=m,(c+=1)<n&&(p=-e[c]);b&&(o[s++]=b);_&&(o[s++]=_);s||(o[s++]=0);return o.length=s,o}},{}],289:[function(t,e,r){"use strict";e.exports=function(t,e){var r=0|t.length,n=0|e.length;if(1===r&&1===n)return function(t,e){var r=t+e,n=r-t,i=t-(r-n)+(e-n);if(i)return[i,r];return[r]}(t[0],e[0]);var i,a,o=new Array(r+n),s=0,l=0,c=0,u=Math.abs,f=t[l],h=u(f),p=e[c],d=u(p);h<d?(a=f,(l+=1)<r&&(f=t[l],h=u(f))):(a=p,(c+=1)<n&&(p=e[c],d=u(p)));l<r&&h<d||c>=n?(i=f,(l+=1)<r&&(f=t[l],h=u(f))):(i=p,(c+=1)<n&&(p=e[c],d=u(p)));var m,g,v=i+a,y=v-i,x=a-y,b=x,_=v;for(;l<r&&c<n;)h<d?(i=f,(l+=1)<r&&(f=t[l],h=u(f))):(i=p,(c+=1)<n&&(p=e[c],d=u(p))),(x=(a=b)-(y=(v=i+a)-i))&&(o[s++]=x),b=_-((m=_+v)-(g=m-_))+(v-g),_=m;for(;l<r;)(x=(a=b)-(y=(v=(i=f)+a)-i))&&(o[s++]=x),b=_-((m=_+v)-(g=m-_))+(v-g),_=m,(l+=1)<r&&(f=t[l]);for(;c<n;)(x=(a=b)-(y=(v=(i=p)+a)-i))&&(o[s++]=x),b=_-((m=_+v)-(g=m-_))+(v-g),_=m,(c+=1)<n&&(p=e[c]);b&&(o[s++]=b);_&&(o[s++]=_);s||(o[s++]=0);return o.length=s,o}},{}],290:[function(t,e,r){"use strict";e.exports=function(t){return i(n(t))};var n=t("boundary-cells"),i=t("reduce-simplicial-complex")},{"boundary-cells":34,"reduce-simplicial-complex":276}],291:[function(t,e,r){"use strict";e.exports=function(t,e,r,s){r=r||0,void 0===s&&(s=function(t){for(var e=t.length,r=0,n=0;n<e;++n)r=0|Math.max(r,t[n].length);return r-1}(t));if(0===t.length||s<1)return{cells:[],vertexIds:[],vertexWeights:[]};var l=function(t,e){for(var r=t.length,n=i.mallocUint8(r),a=0;a<r;++a)n[a]=t[a]<e|0;return n}(e,+r),c=function(t,e){for(var r=t.length,o=e*(e+1)/2*r|0,s=i.mallocUint32(2*o),l=0,c=0;c<r;++c)for(var u=t[c],f=(e=u.length,0);f<e;++f)for(var h=0;h<f;++h){var p=u[h],d=u[f];s[l++]=0|Math.min(p,d),s[l++]=0|Math.max(p,d)}a(n(s,[l/2|0,2]));var m=2;for(c=2;c<l;c+=2)s[c-2]===s[c]&&s[c-1]===s[c+1]||(s[m++]=s[c],s[m++]=s[c+1]);return n(s,[m/2|0,2])}(t,s),u=function(t,e,r,a){for(var o=t.data,s=t.shape[0],l=i.mallocDouble(s),c=0,u=0;u<s;++u){var f=o[2*u],h=o[2*u+1];if(r[f]!==r[h]){var p=e[f],d=e[h];o[2*c]=f,o[2*c+1]=h,l[c++]=(d-a)/(d-p)}}return t.shape[0]=c,n(l,[c])}(c,e,l,+r),f=function(t,e){var r=i.mallocInt32(2*e),n=t.shape[0],a=t.data;r[0]=0;for(var o=0,s=0;s<n;++s){var l=a[2*s];if(l!==o){for(r[2*o+1]=s;++o<l;)r[2*o]=s,r[2*o+1]=s;r[2*o]=s}}r[2*o+1]=n;for(;++o<e;)r[2*o]=r[2*o+1]=n;return r}(c,0|e.length),h=o(s)(t,c.data,f,l),p=function(t){for(var e=0|t.shape[0],r=t.data,n=new Array(e),i=0;i<e;++i)n[i]=[r[2*i],r[2*i+1]];return n}(c),d=[].slice.call(u.data,0,u.shape[0]);return i.free(l),i.free(c.data),i.free(u.data),i.free(f),{cells:h,vertexIds:p,vertexWeights:d}};var n=t("ndarray"),i=t("typedarray-pool"),a=t("ndarray-sort"),o=t("./lib/codegen")},{"./lib/codegen":292,ndarray:259,"ndarray-sort":258,"typedarray-pool":308}],292:[function(t,e,r){"use strict";e.exports=function(t){return n[t]()};var n=[function(){return function(t,e,r,n){for(var i=t.length,a=0;a<i;++a)t[a].length;return[]}},function(){function t(t,e,r,n){for(var i=0|Math.min(r,n),a=0|Math.max(r,n),o=t[2*i],s=t[2*i+1];o<s;){var l=o+s>>1,c=e[2*l+1];if(c===a)return l;a<c?s=l:o=l+1}return o}return function(e,r,n,i){for(var a=e.length,o=[],s=0;s<a;++s){var l=e[s];if(2===l.length){var c=(i[l[0]]<<0)+(i[l[1]]<<1);if(0===c||3===c)continue;switch(c){case 0:break;case 1:o.push([t(n,r,l[0],l[1])]);break;case 2:o.push([t(n,r,l[1],l[0])])}}}return o}},function(){function t(t,e,r,n){for(var i=0|Math.min(r,n),a=0|Math.max(r,n),o=t[2*i],s=t[2*i+1];o<s;){var l=o+s>>1,c=e[2*l+1];if(c===a)return l;a<c?s=l:o=l+1}return o}return function(e,r,n,i){for(var a=e.length,o=[],s=0;s<a;++s){var l=e[s],c=l.length;if(3===c){if(0===(u=(i[l[0]]<<0)+(i[l[1]]<<1)+(i[l[2]]<<2))||7===u)continue;switch(u){case 0:break;case 1:o.push([t(n,r,l[0],l[2]),t(n,r,l[0],l[1])]);break;case 2:o.push([t(n,r,l[1],l[0]),t(n,r,l[1],l[2])]);break;case 3:o.push([t(n,r,l[0],l[2]),t(n,r,l[1],l[2])]);break;case 4:o.push([t(n,r,l[2],l[1]),t(n,r,l[2],l[0])]);break;case 5:o.push([t(n,r,l[2],l[1]),t(n,r,l[0],l[1])]);break;case 6:o.push([t(n,r,l[1],l[0]),t(n,r,l[2],l[0])])}}else if(2===c){var u;if(0===(u=(i[l[0]]<<0)+(i[l[1]]<<1))||3===u)continue;switch(u){case 0:break;case 1:o.push([t(n,r,l[0],l[1])]);break;case 2:o.push([t(n,r,l[1],l[0])])}}}return o}},function(){function t(t,e,r,n){for(var i=0|Math.min(r,n),a=0|Math.max(r,n),o=t[2*i],s=t[2*i+1];o<s;){var l=o+s>>1,c=e[2*l+1];if(c===a)return l;a<c?s=l:o=l+1}return o}return function(e,r,n,i){for(var a=e.length,o=[],s=0;s<a;++s){var l=e[s],c=l.length;if(4===c){if(0===(u=(i[l[0]]<<0)+(i[l[1]]<<1)+(i[l[2]]<<2)+(i[l[3]]<<3))||15===u)continue;switch(u){case 0:break;case 1:o.push([t(n,r,l[0],l[1]),t(n,r,l[0],l[2]),t(n,r,l[0],l[3])]);break;case 2:o.push([t(n,r,l[1],l[2]),t(n,r,l[1],l[0]),t(n,r,l[1],l[3])]);break;case 3:o.push([t(n,r,l[1],l[2]),t(n,r,l[0],l[2]),t(n,r,l[0],l[3])],[t(n,r,l[1],l[3]),t(n,r,l[1],l[2]),t(n,r,l[0],l[3])]);break;case 4:o.push([t(n,r,l[2],l[0]),t(n,r,l[2],l[1]),t(n,r,l[2],l[3])]);break;case 5:o.push([t(n,r,l[0],l[1]),t(n,r,l[2],l[1]),t(n,r,l[0],l[3])],[t(n,r,l[2],l[1]),t(n,r,l[2],l[3]),t(n,r,l[0],l[3])]);break;case 6:o.push([t(n,r,l[2],l[0]),t(n,r,l[1],l[0]),t(n,r,l[1],l[3])],[t(n,r,l[2],l[3]),t(n,r,l[2],l[0]),t(n,r,l[1],l[3])]);break;case 7:o.push([t(n,r,l[0],l[3]),t(n,r,l[1],l[3]),t(n,r,l[2],l[3])]);break;case 8:o.push([t(n,r,l[3],l[1]),t(n,r,l[3],l[0]),t(n,r,l[3],l[2])]);break;case 9:o.push([t(n,r,l[3],l[1]),t(n,r,l[0],l[1]),t(n,r,l[0],l[2])],[t(n,r,l[3],l[2]),t(n,r,l[3],l[1]),t(n,r,l[0],l[2])]);break;case 10:o.push([t(n,r,l[1],l[0]),t(n,r,l[3],l[0]),t(n,r,l[1],l[2])],[t(n,r,l[3],l[0]),t(n,r,l[3],l[2]),t(n,r,l[1],l[2])]);break;case 11:o.push([t(n,r,l[1],l[2]),t(n,r,l[0],l[2]),t(n,r,l[3],l[2])]);break;case 12:o.push([t(n,r,l[3],l[0]),t(n,r,l[2],l[0]),t(n,r,l[2],l[1])],[t(n,r,l[3],l[1]),t(n,r,l[3],l[0]),t(n,r,l[2],l[1])]);break;case 13:o.push([t(n,r,l[0],l[1]),t(n,r,l[2],l[1]),t(n,r,l[3],l[1])]);break;case 14:o.push([t(n,r,l[2],l[0]),t(n,r,l[1],l[0]),t(n,r,l[3],l[0])])}}else if(3===c){if(0===(u=(i[l[0]]<<0)+(i[l[1]]<<1)+(i[l[2]]<<2))||7===u)continue;switch(u){case 0:break;case 1:o.push([t(n,r,l[0],l[2]),t(n,r,l[0],l[1])]);break;case 2:o.push([t(n,r,l[1],l[0]),t(n,r,l[1],l[2])]);break;case 3:o.push([t(n,r,l[0],l[2]),t(n,r,l[1],l[2])]);break;case 4:o.push([t(n,r,l[2],l[1]),t(n,r,l[2],l[0])]);break;case 5:o.push([t(n,r,l[2],l[1]),t(n,r,l[0],l[1])]);break;case 6:o.push([t(n,r,l[1],l[0]),t(n,r,l[2],l[0])])}}else if(2===c){var u;if(0===(u=(i[l[0]]<<0)+(i[l[1]]<<1))||3===u)continue;switch(u){case 0:break;case 1:o.push([t(n,r,l[0],l[1])]);break;case 2:o.push([t(n,r,l[1],l[0])])}}}return o}}]},{}],293:[function(t,e,r){"use strict";var n=t("bit-twiddle"),i=t("union-find");function a(t,e){var r=t.length,n=t.length-e.length,i=Math.min;if(n)return n;switch(r){case 0:return 0;case 1:return t[0]-e[0];case 2:return(s=t[0]+t[1]-e[0]-e[1])||i(t[0],t[1])-i(e[0],e[1]);case 3:var a=t[0]+t[1],o=e[0]+e[1];if(s=a+t[2]-(o+e[2]))return s;var s,l=i(t[0],t[1]),c=i(e[0],e[1]);return(s=i(l,t[2])-i(c,e[2]))||i(l+t[2],a)-i(c+e[2],o);default:var u=t.slice(0);u.sort();var f=e.slice(0);f.sort();for(var h=0;h<r;++h)if(n=u[h]-f[h])return n;return 0}}function o(t,e){return a(t[0],e[0])}function s(t,e){if(e){for(var r=t.length,n=new Array(r),i=0;i<r;++i)n[i]=[t[i],e[i]];n.sort(o);for(i=0;i<r;++i)t[i]=n[i][0],e[i]=n[i][1];return t}return t.sort(a),t}function l(t){if(0===t.length)return[];for(var e=1,r=t.length,n=1;n<r;++n){var i=t[n];if(a(i,t[n-1])){if(n===e){e++;continue}t[e++]=i}}return t.length=e,t}function c(t,e){for(var r=0,n=t.length-1,i=-1;r<=n;){var o=r+n>>1,s=a(t[o],e);s<=0?(0===s&&(i=o),r=o+1):s>0&&(n=o-1)}return i}function u(t,e){for(var r=new Array(t.length),i=0,o=r.length;i<o;++i)r[i]=[];for(var s=[],l=(i=0,e.length);i<l;++i)for(var u=e[i],f=u.length,h=1,p=1<<f;h<p;++h){s.length=n.popCount(h);for(var d=0,m=0;m<f;++m)h&1<<m&&(s[d++]=u[m]);var g=c(t,s);if(!(g<0))for(;r[g++].push(i),!(g>=t.length||0!==a(t[g],s)););}return r}function f(t,e){if(e<0)return[];for(var r=[],i=(1<<e+1)-1,a=0;a<t.length;++a)for(var o=t[a],l=i;l<1<<o.length;l=n.nextCombination(l)){for(var c=new Array(e+1),u=0,f=0;f<o.length;++f)l&1<<f&&(c[u++]=o[f]);r.push(c)}return s(r)}r.dimension=function(t){for(var e=0,r=Math.max,n=0,i=t.length;n<i;++n)e=r(e,t[n].length);return e-1},r.countVertices=function(t){for(var e=-1,r=Math.max,n=0,i=t.length;n<i;++n)for(var a=t[n],o=0,s=a.length;o<s;++o)e=r(e,a[o]);return e+1},r.cloneCells=function(t){for(var e=new Array(t.length),r=0,n=t.length;r<n;++r)e[r]=t[r].slice(0);return e},r.compareCells=a,r.normalize=s,r.unique=l,r.findCell=c,r.incidence=u,r.dual=function(t,e){if(!e)return u(l(f(t,0)),t);for(var r=new Array(e),n=0;n<e;++n)r[n]=[];n=0;for(var i=t.length;n<i;++n)for(var a=t[n],o=0,s=a.length;o<s;++o)r[a[o]].push(n);return r},r.explode=function(t){for(var e=[],r=0,n=t.length;r<n;++r)for(var i=t[r],a=0|i.length,o=1,l=1<<a;o<l;++o){for(var c=[],u=0;u<a;++u)o>>>u&1&&c.push(i[u]);e.push(c)}return s(e)},r.skeleton=f,r.boundary=function(t){for(var e=[],r=0,n=t.length;r<n;++r)for(var i=t[r],a=0,o=i.length;a<o;++a){for(var l=new Array(i.length-1),c=0,u=0;c<o;++c)c!==a&&(l[u++]=i[c]);e.push(l)}return s(e)},r.connectedComponents=function(t,e){return e?function(t,e){for(var r=new i(e),n=0;n<t.length;++n)for(var a=t[n],o=0;o<a.length;++o)for(var s=o+1;s<a.length;++s)r.link(a[o],a[s]);var l=[],c=r.ranks;for(n=0;n<c.length;++n)c[n]=-1;for(n=0;n<t.length;++n){var u=r.find(t[n][0]);c[u]<0?(c[u]=l.length,l.push([t[n].slice(0)])):l[c[u]].push(t[n].slice(0))}return l}(t,e):function(t){for(var e=l(s(f(t,0))),r=new i(e.length),n=0;n<t.length;++n)for(var a=t[n],o=0;o<a.length;++o)for(var u=c(e,[a[o]]),h=o+1;h<a.length;++h)r.link(u,c(e,[a[h]]));var p=[],d=r.ranks;for(n=0;n<d.length;++n)d[n]=-1;for(n=0;n<t.length;++n){var m=r.find(c(e,[t[n][0]]));d[m]<0?(d[m]=p.length,p.push([t[n].slice(0)])):p[d[m]].push(t[n].slice(0))}return p}(t)}},{"bit-twiddle":32,"union-find":309}],294:[function(t,e,r){arguments[4][32][0].apply(r,arguments)},{dup:32}],295:[function(t,e,r){arguments[4][293][0].apply(r,arguments)},{"bit-twiddle":294,dup:293,"union-find":296}],296:[function(t,e,r){"use strict";function n(t){this.roots=new Array(t),this.ranks=new Array(t);for(var e=0;e<t;++e)this.roots[e]=e,this.ranks[e]=0}e.exports=n,n.prototype.length=function(){return this.roots.length},n.prototype.makeSet=function(){var t=this.roots.length;return this.roots.push(t),this.ranks.push(0),t},n.prototype.find=function(t){for(var e=this.roots;e[t]!==t;){var r=e[t];e[t]=e[r],t=r}return t},n.prototype.link=function(t,e){var r=this.find(t),n=this.find(e);if(r!==n){var i=this.ranks,a=this.roots,o=i[r],s=i[n];o<s?a[r]=n:s<o?a[n]=r:(a[n]=r,++i[r])}}},{}],297:[function(t,e,r){"use strict";e.exports=function(t,e,r){for(var a=e.length,o=t.length,s=new Array(a),l=new Array(a),c=new Array(a),u=new Array(a),f=0;f<a;++f)s[f]=l[f]=-1,c[f]=1/0,u[f]=!1;for(f=0;f<o;++f){var h=t[f];if(2!==h.length)throw new Error("Input must be a graph");var p=h[1],d=h[0];-1!==l[d]?l[d]=-2:l[d]=p,-1!==s[p]?s[p]=-2:s[p]=d}function m(t){if(u[t])return 1/0;var r,i,a,o,c,f=s[t],h=l[t];return f<0||h<0?1/0:(r=e[t],i=e[f],a=e[h],o=Math.abs(n(r,i,a)),c=Math.sqrt(Math.pow(i[0]-a[0],2)+Math.pow(i[1]-a[1],2)),o/c)}function g(t,e){var r=k[t],n=k[e];k[t]=n,k[e]=r,A[r]=e,A[n]=t}function v(t){return c[k[t]]}function y(t){return 1&t?t-1>>1:(t>>1)-1}function x(t){for(var e=v(t);;){var r=e,n=2*t+1,i=2*(t+1),a=t;if(n<M){var o=v(n);o<r&&(a=n,r=o)}if(i<M)v(i)<r&&(a=i);if(a===t)return t;g(t,a),t=a}}function b(t){for(var e=v(t);t>0;){var r=y(t);if(r>=0)if(e<v(r)){g(t,r),t=r;continue}return t}}function _(){if(M>0){var t=k[0];return g(0,M-1),M-=1,x(0),t}return-1}function w(t,e){var r=k[t];return c[r]===e?t:(c[r]=-1/0,b(t),_(),c[r]=e,b((M+=1)-1))}function T(t){if(!u[t]){u[t]=!0;var e=s[t],r=l[t];s[r]>=0&&(s[r]=e),l[e]>=0&&(l[e]=r),A[e]>=0&&w(A[e],m(e)),A[r]>=0&&w(A[r],m(r))}}var k=[],A=new Array(a);for(f=0;f<a;++f){(c[f]=m(f))<1/0?(A[f]=k.length,k.push(f)):A[f]=-1}var M=k.length;for(f=M>>1;f>=0;--f)x(f);for(;;){var S=_();if(S<0||c[S]>r)break;T(S)}var E=[];for(f=0;f<a;++f)u[f]||(A[f]=E.length,E.push(e[f].slice()));E.length;function L(t,e){if(t[e]<0)return e;var r=e,n=e;do{var i=t[n];if(!u[n]||i<0||i===n)break;if(i=t[n=i],!u[n]||i<0||i===n)break;n=i,r=t[r]}while(r!==n);for(var a=e;a!==n;a=t[a])t[a]=n;return n}var C=[];return t.forEach((function(t){var e=L(s,t[0]),r=L(l,t[1]);if(e>=0&&r>=0&&e!==r){var n=A[e],i=A[r];n!==i&&C.push([n,i])}})),i.unique(i.normalize(C)),{positions:E,edges:C}};var n=t("robust-orientation"),i=t("simplicial-complex")},{"robust-orientation":284,"simplicial-complex":295}],298:[function(t,e,r){"use strict";e.exports=function(t,e){var r,a,o,s;if(e[0][0]<e[1][0])r=e[0],a=e[1];else{if(!(e[0][0]>e[1][0]))return i(e,t);r=e[1],a=e[0]}if(t[0][0]<t[1][0])o=t[0],s=t[1];else{if(!(t[0][0]>t[1][0]))return-i(t,e);o=t[1],s=t[0]}var l=n(r,a,s),c=n(r,a,o);if(l<0){if(c<=0)return l}else if(l>0){if(c>=0)return l}else if(c)return c;if(l=n(s,o,a),c=n(s,o,r),l<0){if(c<=0)return l}else if(l>0){if(c>=0)return l}else if(c)return c;return a[0]-s[0]};var n=t("robust-orientation");function i(t,e){var r,i,a,o;if(e[0][0]<e[1][0])r=e[0],i=e[1];else{if(!(e[0][0]>e[1][0])){var s=Math.min(t[0][1],t[1][1]),l=Math.max(t[0][1],t[1][1]),c=Math.min(e[0][1],e[1][1]),u=Math.max(e[0][1],e[1][1]);return l<c?l-c:s>u?s-u:l-u}r=e[1],i=e[0]}t[0][1]<t[1][1]?(a=t[0],o=t[1]):(a=t[1],o=t[0]);var f=n(i,r,a);return f||((f=n(i,r,o))||o-i)}},{"robust-orientation":284}],299:[function(t,e,r){"use strict";e.exports=function(t){for(var e=t.length,r=2*e,n=new Array(r),a=0;a<e;++a){var l=t[a],c=l[0][0]<l[1][0];n[2*a]=new f(l[0][0],l,c,a),n[2*a+1]=new f(l[1][0],l,!c,a)}n.sort((function(t,e){var r=t.x-e.x;return r||((r=t.create-e.create)||Math.min(t.segment[0][1],t.segment[1][1])-Math.min(e.segment[0][1],e.segment[1][1]))}));var h=i(o),p=[],d=[],m=[];for(a=0;a<r;){for(var g=n[a].x,v=[];a<r;){var y=n[a];if(y.x!==g)break;a+=1,y.segment[0][0]===y.x&&y.segment[1][0]===y.x?y.create&&(y.segment[0][1]<y.segment[1][1]?(v.push(new u(y.segment[0][1],y.index,!0,!0)),v.push(new u(y.segment[1][1],y.index,!1,!1))):(v.push(new u(y.segment[1][1],y.index,!0,!1)),v.push(new u(y.segment[0][1],y.index,!1,!0)))):h=y.create?h.insert(y.segment,y.index):h.remove(y.segment)}p.push(h.root),d.push(g),m.push(v)}return new s(p,d,m)};var n=t("binary-search-bounds"),i=t("functional-red-black-tree"),a=t("robust-orientation"),o=t("./lib/order-segments");function s(t,e,r){this.slabs=t,this.coordinates=e,this.horizontal=r}function l(t,e){return t.y-e}function c(t,e){for(var r=null;t;){var n,i,o=t.key;o[0][0]<o[1][0]?(n=o[0],i=o[1]):(n=o[1],i=o[0]);var s=a(n,i,e);if(s<0)t=t.left;else if(s>0)if(e[0]!==o[1][0])r=t,t=t.right;else{if(l=c(t.right,e))return l;t=t.left}else{if(e[0]!==o[1][0])return t;var l;if(l=c(t.right,e))return l;t=t.left}}return r}function u(t,e,r,n){this.y=t,this.index=e,this.start=r,this.closed=n}function f(t,e,r,n){this.x=t,this.segment=e,this.create=r,this.index=n}s.prototype.castUp=function(t){var e=n.le(this.coordinates,t[0]);if(e<0)return-1;this.slabs[e];var r=c(this.slabs[e],t),i=-1;if(r&&(i=r.value),this.coordinates[e]===t[0]){var s=null;if(r&&(s=r.key),e>0){var u=c(this.slabs[e-1],t);u&&(s?o(u.key,s)>0&&(s=u.key,i=u.value):(i=u.value,s=u.key))}var f=this.horizontal[e];if(f.length>0){var h=n.ge(f,t[1],l);if(h<f.length){var p=f[h];if(t[1]===p.y){if(p.closed)return p.index;for(;h<f.length-1&&f[h+1].y===t[1];)if((p=f[h+=1]).closed)return p.index;if(p.y===t[1]&&!p.start){if((h+=1)>=f.length)return i;p=f[h]}}if(p.start)if(s){var d=a(s[0],s[1],[t[0],p.y]);s[0][0]>s[1][0]&&(d=-d),d>0&&(i=p.index)}else i=p.index;else p.y!==t[1]&&(i=p.index)}}}return i}},{"./lib/order-segments":298,"binary-search-bounds":31,"functional-red-black-tree":69,"robust-orientation":284}],300:[function(t,e,r){"use strict";var n=t("robust-dot-product"),i=t("robust-sum");function a(t,e){var r=i(n(t,e),[e[e.length-1]]);return r[r.length-1]}function o(t,e,r,n){var i=-e/(n-e);i<0?i=0:i>1&&(i=1);for(var a=1-i,o=t.length,s=new Array(o),l=0;l<o;++l)s[l]=i*t[l]+a*r[l];return s}e.exports=function(t,e){for(var r=[],n=[],i=a(t[t.length-1],e),s=t[t.length-1],l=t[0],c=0;c<t.length;++c,s=l){var u=a(l=t[c],e);if(i<0&&u>0||i>0&&u<0){var f=o(s,u,l,i);r.push(f),n.push(f.slice())}u<0?n.push(l.slice()):u>0?r.push(l.slice()):(r.push(l.slice()),n.push(l.slice())),i=u}return{positive:r,negative:n}},e.exports.positive=function(t,e){for(var r=[],n=a(t[t.length-1],e),i=t[t.length-1],s=t[0],l=0;l<t.length;++l,i=s){var c=a(s=t[l],e);(n<0&&c>0||n>0&&c<0)&&r.push(o(i,c,s,n)),c>=0&&r.push(s.slice()),n=c}return r},e.exports.negative=function(t,e){for(var r=[],n=a(t[t.length-1],e),i=t[t.length-1],s=t[0],l=0;l<t.length;++l,i=s){var c=a(s=t[l],e);(n<0&&c>0||n>0&&c<0)&&r.push(o(i,c,s,n)),c<=0&&r.push(s.slice()),n=c}return r}},{"robust-dot-product":281,"robust-sum":289}],301:[function(t,e,r){!function(){"use strict";var t={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function e(t){return i(o(t),arguments)}function n(t,r){return e.apply(null,[t].concat(r||[]))}function i(r,n){var i,a,o,s,l,c,u,f,h,p=1,d=r.length,m="";for(a=0;a<d;a++)if("string"==typeof r[a])m+=r[a];else if("object"==typeof r[a]){if((s=r[a]).keys)for(i=n[p],o=0;o<s.keys.length;o++){if(null==i)throw new Error(e('[sprintf] Cannot access property "%s" of undefined value "%s"',s.keys[o],s.keys[o-1]));i=i[s.keys[o]]}else i=s.param_no?n[s.param_no]:n[p++];if(t.not_type.test(s.type)&&t.not_primitive.test(s.type)&&i instanceof Function&&(i=i()),t.numeric_arg.test(s.type)&&"number"!=typeof i&&isNaN(i))throw new TypeError(e("[sprintf] expecting number but found %T",i));switch(t.number.test(s.type)&&(f=i>=0),s.type){case"b":i=parseInt(i,10).toString(2);break;case"c":i=String.fromCharCode(parseInt(i,10));break;case"d":case"i":i=parseInt(i,10);break;case"j":i=JSON.stringify(i,null,s.width?parseInt(s.width):0);break;case"e":i=s.precision?parseFloat(i).toExponential(s.precision):parseFloat(i).toExponential();break;case"f":i=s.precision?parseFloat(i).toFixed(s.precision):parseFloat(i);break;case"g":i=s.precision?String(Number(i.toPrecision(s.precision))):parseFloat(i);break;case"o":i=(parseInt(i,10)>>>0).toString(8);break;case"s":i=String(i),i=s.precision?i.substring(0,s.precision):i;break;case"t":i=String(!!i),i=s.precision?i.substring(0,s.precision):i;break;case"T":i=Object.prototype.toString.call(i).slice(8,-1).toLowerCase(),i=s.precision?i.substring(0,s.precision):i;break;case"u":i=parseInt(i,10)>>>0;break;case"v":i=i.valueOf(),i=s.precision?i.substring(0,s.precision):i;break;case"x":i=(parseInt(i,10)>>>0).toString(16);break;case"X":i=(parseInt(i,10)>>>0).toString(16).toUpperCase()}t.json.test(s.type)?m+=i:(!t.number.test(s.type)||f&&!s.sign?h="":(h=f?"+":"-",i=i.toString().replace(t.sign,"")),c=s.pad_char?"0"===s.pad_char?"0":s.pad_char.charAt(1):" ",u=s.width-(h+i).length,l=s.width&&u>0?c.repeat(u):"",m+=s.align?h+i+l:"0"===c?h+l+i:l+h+i)}return m}var a=Object.create(null);function o(e){if(a[e])return a[e];for(var r,n=e,i=[],o=0;n;){if(null!==(r=t.text.exec(n)))i.push(r[0]);else if(null!==(r=t.modulo.exec(n)))i.push("%");else{if(null===(r=t.placeholder.exec(n)))throw new SyntaxError("[sprintf] unexpected placeholder");if(r[2]){o|=1;var s=[],l=r[2],c=[];if(null===(c=t.key.exec(l)))throw new SyntaxError("[sprintf] failed to parse named argument key");for(s.push(c[1]);""!==(l=l.substring(c[0].length));)if(null!==(c=t.key_access.exec(l)))s.push(c[1]);else{if(null===(c=t.index_access.exec(l)))throw new SyntaxError("[sprintf] failed to parse named argument key");s.push(c[1])}r[2]=s}else o|=2;if(3===o)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");i.push({placeholder:r[0],param_no:r[1],keys:r[2],sign:r[3],pad_char:r[4],align:r[5],width:r[6],precision:r[7],type:r[8]})}n=n.substring(r[0].length)}return a[e]=i}void 0!==r&&(r.sprintf=e,r.vsprintf=n),"undefined"!=typeof window&&(window.sprintf=e,window.vsprintf=n)}()},{}],302:[function(t,e,r){"use strict";e.exports=function(t,e){if(t.dimension<=0)return{positions:[],cells:[]};if(1===t.dimension)return function(t,e){for(var r=i(t,e),n=r.length,a=new Array(n),o=new Array(n),s=0;s<n;++s)a[s]=[r[s]],o[s]=[s];return{positions:a,cells:o}}(t,e);var r=t.order.join()+"-"+t.dtype,s=o[r];e=+e||0;s||(s=o[r]=function(t,e){var r=t.length+"d",i=a[r];if(i)return i(n,t,e)}(t.order,t.dtype));return s(t,e)};var n=t("ndarray-extract-contour"),i=t("zero-crossings"),a={"2d":function(t,e,r){var n=t({order:e,scalarArguments:3,getters:"generic"===r?[0]:void 0,phase:function(t,e,r,n){return t>n|0},vertex:function(t,e,r,n,i,a,o,s,l,c,u,f,h){var p=(o<<0)+(s<<1)+(l<<2)+(c<<3)|0;if(0!==p&&15!==p)switch(p){case 0:u.push([t-.5,e-.5]);break;case 1:u.push([t-.25-.25*(n+r-2*h)/(r-n),e-.25-.25*(i+r-2*h)/(r-i)]);break;case 2:u.push([t-.75-.25*(-n-r+2*h)/(n-r),e-.25-.25*(a+n-2*h)/(n-a)]);break;case 3:u.push([t-.5,e-.5-.5*(i+r+a+n-4*h)/(r-i+n-a)]);break;case 4:u.push([t-.25-.25*(a+i-2*h)/(i-a),e-.75-.25*(-i-r+2*h)/(i-r)]);break;case 5:u.push([t-.5-.5*(n+r+a+i-4*h)/(r-n+i-a),e-.5]);break;case 6:u.push([t-.5-.25*(-n-r+a+i)/(n-r+i-a),e-.5-.25*(-i-r+a+n)/(i-r+n-a)]);break;case 7:u.push([t-.75-.25*(a+i-2*h)/(i-a),e-.75-.25*(a+n-2*h)/(n-a)]);break;case 8:u.push([t-.75-.25*(-a-i+2*h)/(a-i),e-.75-.25*(-a-n+2*h)/(a-n)]);break;case 9:u.push([t-.5-.25*(n+r+-a-i)/(r-n+a-i),e-.5-.25*(i+r+-a-n)/(r-i+a-n)]);break;case 10:u.push([t-.5-.5*(-n-r-a-i+4*h)/(n-r+a-i),e-.5]);break;case 11:u.push([t-.25-.25*(-a-i+2*h)/(a-i),e-.75-.25*(i+r-2*h)/(r-i)]);break;case 12:u.push([t-.5,e-.5-.5*(-i-r-a-n+4*h)/(i-r+a-n)]);break;case 13:u.push([t-.75-.25*(n+r-2*h)/(r-n),e-.25-.25*(-a-n+2*h)/(a-n)]);break;case 14:u.push([t-.25-.25*(-n-r+2*h)/(n-r),e-.25-.25*(-i-r+2*h)/(i-r)]);break;case 15:u.push([t-.5,e-.5])}},cell:function(t,e,r,n,i,a,o,s,l){i?s.push([t,e]):s.push([e,t])}});return function(t,e){var r=[],i=[];return n(t,r,i,e),{positions:r,cells:i}}}};var o={}},{"ndarray-extract-contour":251,"zero-crossings":318}],303:[function(t,e,r){(function(r){(function(){"use strict";e.exports=function t(e,r,i){i=i||{};var o=a[e];o||(o=a[e]={" ":{data:new Float32Array(0),shape:.2}});var s=o[r];if(!s)if(r.length<=1||!/\d/.test(r))s=o[r]=function(t){for(var e=t.cells,r=t.positions,n=new Float32Array(6*e.length),i=0,a=0,o=0;o<e.length;++o)for(var s=e[o],l=0;l<3;++l){var c=r[s[l]];n[i++]=c[0],n[i++]=c[1]+1.4,a=Math.max(c[0],a)}return{data:n,shape:a}}(n(r,{triangles:!0,font:e,textAlign:i.textAlign||"left",textBaseline:"alphabetic",styletags:{breaklines:!0,bolds:!0,italics:!0,subscripts:!0,superscripts:!0}}));else{for(var l=r.split(/(\d|\s)/),c=new Array(l.length),u=0,f=0,h=0;h<l.length;++h)c[h]=t(e,l[h]),u+=c[h].data.length,f+=c[h].shape,h>0&&(f+=.02);var p=new Float32Array(u),d=0,m=-.5*f;for(h=0;h<c.length;++h){for(var g=c[h].data,v=0;v<g.length;v+=2)p[d++]=g[v]+m,p[d++]=g[v+1];m+=c[h].shape+.02}s=o[r]={data:p,shape:f}}return s};var n=t("vectorize-text"),i=window||r.global||{},a=i.__TEXT_CACHE||{};i.__TEXT_CACHE={}}).call(this)}).call(this,t("_process"))},{_process:5,"vectorize-text":311}],304:[function(t,e,r){"use strict";var n=t("parse-unit");e.exports=a;function i(t,e){var r=n(getComputedStyle(t).getPropertyValue(e));return r[0]*a(r[1],t)}function a(t,e){switch(e=e||document.body,t=(t||"px").trim().toLowerCase(),e!==window&&e!==document||(e=document.body),t){case"%":return e.clientHeight/100;case"ch":case"ex":return function(t,e){var r=document.createElement("div");r.style["font-size"]="128"+t,e.appendChild(r);var n=i(r,"font-size")/128;return e.removeChild(r),n}(t,e);case"em":return i(e,"font-size");case"rem":return i(document.body,"font-size");case"vw":return window.innerWidth/100;case"vh":return window.innerHeight/100;case"vmin":return Math.min(window.innerWidth,window.innerHeight)/100;case"vmax":return Math.max(window.innerWidth,window.innerHeight)/100;case"in":return 96;case"cm":return 96/2.54;case"mm":return 96/25.4;case"pt":return 96/72;case"pc":return 16}return 1}},{"parse-unit":265}],305:[function(t,e,r){"use strict";e.exports=function(t){var e=(t=t||{}).center||[0,0,0],r=t.up||[0,1,0],n=t.right||f(r),i=t.radius||1,a=t.theta||0,u=t.phi||0;if(e=[].slice.call(e,0,3),r=[].slice.call(r,0,3),s(r,r),n=[].slice.call(n,0,3),s(n,n),"eye"in t){var p=t.eye,d=[p[0]-e[0],p[1]-e[1],p[2]-e[2]];o(n,d,r),c(n[0],n[1],n[2])<1e-6?n=f(r):s(n,n),i=c(d[0],d[1],d[2]);var m=l(r,d)/i,g=l(n,d)/i;u=Math.acos(m),a=Math.acos(g)}return i=Math.log(i),new h(t.zoomMin,t.zoomMax,e,r,n,i,a,u)};var n=t("filtered-vector"),i=t("gl-mat4/invert"),a=t("gl-mat4/rotate"),o=t("gl-vec3/cross"),s=t("gl-vec3/normalize"),l=t("gl-vec3/dot");function c(t,e,r){return Math.sqrt(Math.pow(t,2)+Math.pow(e,2)+Math.pow(r,2))}function u(t){return Math.min(1,Math.max(-1,t))}function f(t){var e=Math.abs(t[0]),r=Math.abs(t[1]),n=Math.abs(t[2]),i=[0,0,0];e>Math.max(r,n)?i[2]=1:r>Math.max(e,n)?i[0]=1:i[1]=1;for(var a=0,o=0,l=0;l<3;++l)a+=t[l]*t[l],o+=i[l]*t[l];for(l=0;l<3;++l)i[l]-=o/a*t[l];return s(i,i),i}function h(t,e,r,i,a,o,s,l){this.center=n(r),this.up=n(i),this.right=n(a),this.radius=n([o]),this.angle=n([s,l]),this.angle.bounds=[[-1/0,-Math.PI/2],[1/0,Math.PI/2]],this.setDistanceLimits(t,e),this.computedCenter=this.center.curve(0),this.computedUp=this.up.curve(0),this.computedRight=this.right.curve(0),this.computedRadius=this.radius.curve(0),this.computedAngle=this.angle.curve(0),this.computedToward=[0,0,0],this.computedEye=[0,0,0],this.computedMatrix=new Array(16);for(var c=0;c<16;++c)this.computedMatrix[c]=.5;this.recalcMatrix(0)}var p=h.prototype;p.setDistanceLimits=function(t,e){t=t>0?Math.log(t):-1/0,e=e>0?Math.log(e):1/0,e=Math.max(e,t),this.radius.bounds[0][0]=t,this.radius.bounds[1][0]=e},p.getDistanceLimits=function(t){var e=this.radius.bounds[0];return t?(t[0]=Math.exp(e[0][0]),t[1]=Math.exp(e[1][0]),t):[Math.exp(e[0][0]),Math.exp(e[1][0])]},p.recalcMatrix=function(t){this.center.curve(t),this.up.curve(t),this.right.curve(t),this.radius.curve(t),this.angle.curve(t);for(var e=this.computedUp,r=this.computedRight,n=0,i=0,a=0;a<3;++a)i+=e[a]*r[a],n+=e[a]*e[a];var l=Math.sqrt(n),u=0;for(a=0;a<3;++a)r[a]-=e[a]*i/n,u+=r[a]*r[a],e[a]/=l;var f=Math.sqrt(u);for(a=0;a<3;++a)r[a]/=f;var h=this.computedToward;o(h,e,r),s(h,h);var p=Math.exp(this.computedRadius[0]),d=this.computedAngle[0],m=this.computedAngle[1],g=Math.cos(d),v=Math.sin(d),y=Math.cos(m),x=Math.sin(m),b=this.computedCenter,_=g*y,w=v*y,T=x,k=-g*x,A=-v*x,M=y,S=this.computedEye,E=this.computedMatrix;for(a=0;a<3;++a){var L=_*r[a]+w*h[a]+T*e[a];E[4*a+1]=k*r[a]+A*h[a]+M*e[a],E[4*a+2]=L,E[4*a+3]=0}var C=E[1],P=E[5],I=E[9],O=E[2],z=E[6],D=E[10],R=P*D-I*z,F=I*O-C*D,B=C*z-P*O,N=c(R,F,B);R/=N,F/=N,B/=N,E[0]=R,E[4]=F,E[8]=B;for(a=0;a<3;++a)S[a]=b[a]+E[2+4*a]*p;for(a=0;a<3;++a){u=0;for(var j=0;j<3;++j)u+=E[a+4*j]*S[j];E[12+a]=-u}E[15]=1},p.getMatrix=function(t,e){this.recalcMatrix(t);var r=this.computedMatrix;if(e){for(var n=0;n<16;++n)e[n]=r[n];return e}return r};var d=[0,0,0];p.rotate=function(t,e,r,n){if(this.angle.move(t,e,r),n){this.recalcMatrix(t);var i=this.computedMatrix;d[0]=i[2],d[1]=i[6],d[2]=i[10];for(var o=this.computedUp,s=this.computedRight,l=this.computedToward,c=0;c<3;++c)i[4*c]=o[c],i[4*c+1]=s[c],i[4*c+2]=l[c];a(i,i,n,d);for(c=0;c<3;++c)o[c]=i[4*c],s[c]=i[4*c+1];this.up.set(t,o[0],o[1],o[2]),this.right.set(t,s[0],s[1],s[2])}},p.pan=function(t,e,r,n){e=e||0,r=r||0,n=n||0,this.recalcMatrix(t);var i=this.computedMatrix,a=(Math.exp(this.computedRadius[0]),i[1]),o=i[5],s=i[9],l=c(a,o,s);a/=l,o/=l,s/=l;var u=i[0],f=i[4],h=i[8],p=u*a+f*o+h*s,d=c(u-=a*p,f-=o*p,h-=s*p),m=(u/=d)*e+a*r,g=(f/=d)*e+o*r,v=(h/=d)*e+s*r;this.center.move(t,m,g,v);var y=Math.exp(this.computedRadius[0]);y=Math.max(1e-4,y+n),this.radius.set(t,Math.log(y))},p.translate=function(t,e,r,n){this.center.move(t,e||0,r||0,n||0)},p.setMatrix=function(t,e,r,n){var a=1;"number"==typeof r&&(a=0|r),(a<0||a>3)&&(a=1);var o=(a+2)%3;e||(this.recalcMatrix(t),e=this.computedMatrix);var s=e[a],l=e[a+4],f=e[a+8];if(n){var h=Math.abs(s),p=Math.abs(l),d=Math.abs(f),m=Math.max(h,p,d);h===m?(s=s<0?-1:1,l=f=0):d===m?(f=f<0?-1:1,s=l=0):(l=l<0?-1:1,s=f=0)}else{var g=c(s,l,f);s/=g,l/=g,f/=g}var v,y,x=e[o],b=e[o+4],_=e[o+8],w=x*s+b*l+_*f,T=c(x-=s*w,b-=l*w,_-=f*w),k=l*(_/=T)-f*(b/=T),A=f*(x/=T)-s*_,M=s*b-l*x,S=c(k,A,M);if(k/=S,A/=S,M/=S,this.center.jump(t,q,G,Y),this.radius.idle(t),this.up.jump(t,s,l,f),this.right.jump(t,x,b,_),2===a){var E=e[1],L=e[5],C=e[9],P=E*x+L*b+C*_,I=E*k+L*A+C*M;v=R<0?-Math.PI/2:Math.PI/2,y=Math.atan2(I,P)}else{var O=e[2],z=e[6],D=e[10],R=O*s+z*l+D*f,F=O*x+z*b+D*_,B=O*k+z*A+D*M;v=Math.asin(u(R)),y=Math.atan2(B,F)}this.angle.jump(t,y,v),this.recalcMatrix(t);var N=e[2],j=e[6],U=e[10],V=this.computedMatrix;i(V,e);var H=V[15],q=V[12]/H,G=V[13]/H,Y=V[14]/H,W=Math.exp(this.computedRadius[0]);this.center.jump(t,q-N*W,G-j*W,Y-U*W)},p.lastT=function(){return Math.max(this.center.lastT(),this.up.lastT(),this.right.lastT(),this.radius.lastT(),this.angle.lastT())},p.idle=function(t){this.center.idle(t),this.up.idle(t),this.right.idle(t),this.radius.idle(t),this.angle.idle(t)},p.flush=function(t){this.center.flush(t),this.up.flush(t),this.right.flush(t),this.radius.flush(t),this.angle.flush(t)},p.setDistance=function(t,e){e>0&&this.radius.set(t,Math.log(e))},p.lookAt=function(t,e,r,n){this.recalcMatrix(t),e=e||this.computedEye,r=r||this.computedCenter;var i=(n=n||this.computedUp)[0],a=n[1],o=n[2],s=c(i,a,o);if(!(s<1e-6)){i/=s,a/=s,o/=s;var l=e[0]-r[0],f=e[1]-r[1],h=e[2]-r[2],p=c(l,f,h);if(!(p<1e-6)){l/=p,f/=p,h/=p;var d=this.computedRight,m=d[0],g=d[1],v=d[2],y=i*m+a*g+o*v,x=c(m-=y*i,g-=y*a,v-=y*o);if(!(x<.01&&(x=c(m=a*h-o*f,g=o*l-i*h,v=i*f-a*l))<1e-6)){m/=x,g/=x,v/=x,this.up.set(t,i,a,o),this.right.set(t,m,g,v),this.center.set(t,r[0],r[1],r[2]),this.radius.set(t,Math.log(p));var b=a*v-o*g,_=o*m-i*v,w=i*g-a*m,T=c(b,_,w),k=i*l+a*f+o*h,A=m*l+g*f+v*h,M=(b/=T)*l+(_/=T)*f+(w/=T)*h,S=Math.asin(u(k)),E=Math.atan2(M,A),L=this.angle._state,C=L[L.length-1],P=L[L.length-2];C%=2*Math.PI;var I=Math.abs(C+2*Math.PI-E),O=Math.abs(C-E),z=Math.abs(C-2*Math.PI-E);I<O&&(C+=2*Math.PI),z<O&&(C-=2*Math.PI),this.angle.jump(this.angle.lastT(),C,P),this.angle.set(t,E,S)}}}}},{"filtered-vector":68,"gl-mat4/invert":98,"gl-mat4/rotate":103,"gl-vec3/cross":157,"gl-vec3/dot":162,"gl-vec3/normalize":179}],306:[function(t,e,r){"use strict";e.exports=function(t,e,r){var i=t*e,a=n*t,o=a-(a-t),s=t-o,l=n*e,c=l-(l-e),u=e-c,f=s*u-(i-o*c-s*c-o*u);if(r)return r[0]=f,r[1]=i,r;return[f,i]};var n=+(Math.pow(2,27)+1)},{}],307:[function(t,e,r){"use strict";e.exports=function(t,e,r){var n=t+e,i=n-t,a=e-i,o=t-(n-i);if(r)return r[0]=o+a,r[1]=n,r;return[o+a,n]}},{}],308:[function(t,e,r){(function(e){(function(){"use strict";var n=t("bit-twiddle"),i=t("dup"),a=t("buffer").Buffer;e.__TYPEDARRAY_POOL||(e.__TYPEDARRAY_POOL={UINT8:i([32,0]),UINT16:i([32,0]),UINT32:i([32,0]),BIGUINT64:i([32,0]),INT8:i([32,0]),INT16:i([32,0]),INT32:i([32,0]),BIGINT64:i([32,0]),FLOAT:i([32,0]),DOUBLE:i([32,0]),DATA:i([32,0]),UINT8C:i([32,0]),BUFFER:i([32,0])});var o="undefined"!=typeof Uint8ClampedArray,s="undefined"!=typeof BigUint64Array,l="undefined"!=typeof BigInt64Array,c=e.__TYPEDARRAY_POOL;c.UINT8C||(c.UINT8C=i([32,0])),c.BIGUINT64||(c.BIGUINT64=i([32,0])),c.BIGINT64||(c.BIGINT64=i([32,0])),c.BUFFER||(c.BUFFER=i([32,0]));var u=c.DATA,f=c.BUFFER;function h(t){if(t){var e=t.length||t.byteLength,r=n.log2(e);u[r].push(t)}}function p(t){t=n.nextPow2(t);var e=n.log2(t),r=u[e];return r.length>0?r.pop():new ArrayBuffer(t)}function d(t){return new Uint8Array(p(t),0,t)}function m(t){return new Uint16Array(p(2*t),0,t)}function g(t){return new Uint32Array(p(4*t),0,t)}function v(t){return new Int8Array(p(t),0,t)}function y(t){return new Int16Array(p(2*t),0,t)}function x(t){return new Int32Array(p(4*t),0,t)}function b(t){return new Float32Array(p(4*t),0,t)}function _(t){return new Float64Array(p(8*t),0,t)}function w(t){return o?new Uint8ClampedArray(p(t),0,t):d(t)}function T(t){return s?new BigUint64Array(p(8*t),0,t):null}function k(t){return l?new BigInt64Array(p(8*t),0,t):null}function A(t){return new DataView(p(t),0,t)}function M(t){t=n.nextPow2(t);var e=n.log2(t),r=f[e];return r.length>0?r.pop():new a(t)}r.free=function(t){if(a.isBuffer(t))f[n.log2(t.length)].push(t);else{if("[object ArrayBuffer]"!==Object.prototype.toString.call(t)&&(t=t.buffer),!t)return;var e=t.length||t.byteLength,r=0|n.log2(e);u[r].push(t)}},r.freeUint8=r.freeUint16=r.freeUint32=r.freeBigUint64=r.freeInt8=r.freeInt16=r.freeInt32=r.freeBigInt64=r.freeFloat32=r.freeFloat=r.freeFloat64=r.freeDouble=r.freeUint8Clamped=r.freeDataView=function(t){h(t.buffer)},r.freeArrayBuffer=h,r.freeBuffer=function(t){f[n.log2(t.length)].push(t)},r.malloc=function(t,e){if(void 0===e||"arraybuffer"===e)return p(t);switch(e){case"uint8":return d(t);case"uint16":return m(t);case"uint32":return g(t);case"int8":return v(t);case"int16":return y(t);case"int32":return x(t);case"float":case"float32":return b(t);case"double":case"float64":return _(t);case"uint8_clamped":return w(t);case"bigint64":return k(t);case"biguint64":return T(t);case"buffer":return M(t);case"data":case"dataview":return A(t);default:return null}return null},r.mallocArrayBuffer=p,r.mallocUint8=d,r.mallocUint16=m,r.mallocUint32=g,r.mallocInt8=v,r.mallocInt16=y,r.mallocInt32=x,r.mallocFloat32=r.mallocFloat=b,r.mallocFloat64=r.mallocDouble=_,r.mallocUint8Clamped=w,r.mallocBigUint64=T,r.mallocBigInt64=k,r.mallocDataView=A,r.mallocBuffer=M,r.clearCache=function(){for(var t=0;t<32;++t)c.UINT8[t].length=0,c.UINT16[t].length=0,c.UINT32[t].length=0,c.INT8[t].length=0,c.INT16[t].length=0,c.INT32[t].length=0,c.FLOAT[t].length=0,c.DOUBLE[t].length=0,c.BIGUINT64[t].length=0,c.BIGINT64[t].length=0,c.UINT8C[t].length=0,u[t].length=0,f[t].length=0}}).call(this)}).call(this,void 0!==n?n:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":32,buffer:3,dup:65}],309:[function(t,e,r){"use strict";function n(t){this.roots=new Array(t),this.ranks=new Array(t);for(var e=0;e<t;++e)this.roots[e]=e,this.ranks[e]=0}e.exports=n;var i=n.prototype;Object.defineProperty(i,"length",{get:function(){return this.roots.length}}),i.makeSet=function(){var t=this.roots.length;return this.roots.push(t),this.ranks.push(0),t},i.find=function(t){for(var e=t,r=this.roots;r[t]!==t;)t=r[t];for(;r[e]!==t;){var n=r[e];r[e]=t,e=n}return t},i.link=function(t,e){var r=this.find(t),n=this.find(e);if(r!==n){var i=this.ranks,a=this.roots,o=i[r],s=i[n];o<s?a[r]=n:s<o?a[n]=r:(a[n]=r,++i[r])}}},{}],310:[function(t,e,r){"use strict";e.exports=function(t,e,r){return 0===t.length?t:e?(r||t.sort(e),function(t,e){for(var r=1,n=t.length,i=t[0],a=t[0],o=1;o<n;++o)if(a=i,e(i=t[o],a)){if(o===r){r++;continue}t[r++]=i}return t.length=r,t}(t,e)):(r||t.sort(),function(t){for(var e=1,r=t.length,n=t[0],i=t[0],a=1;a<r;++a,i=n)if(i=n,(n=t[a])!==i){if(a===e){e++;continue}t[e++]=n}return t.length=e,t}(t))}},{}],311:[function(t,e,r){"use strict";e.exports=function(t,e){"object"==typeof e&&null!==e||(e={});return n(t,e.canvas||i,e.context||a,e)};var n=t("./lib/vtext"),i=null,a=null;"undefined"!=typeof document&&((i=document.createElement("canvas")).width=8192,i.height=1024,a=i.getContext("2d"))},{"./lib/vtext":312}],312:[function(t,e,r){e.exports=function(t,e,r,n){var a=64,o=1.25,s={breaklines:!1,bolds:!1,italics:!1,subscripts:!1,superscripts:!1};n&&(n.size&&n.size>0&&(a=n.size),n.lineSpacing&&n.lineSpacing>0&&(o=n.lineSpacing),n.styletags&&n.styletags.breaklines&&(s.breaklines=!!n.styletags.breaklines),n.styletags&&n.styletags.bolds&&(s.bolds=!!n.styletags.bolds),n.styletags&&n.styletags.italics&&(s.italics=!!n.styletags.italics),n.styletags&&n.styletags.subscripts&&(s.subscripts=!!n.styletags.subscripts),n.styletags&&n.styletags.superscripts&&(s.superscripts=!!n.styletags.superscripts));return r.font=[n.fontStyle,n.fontVariant,n.fontWeight,a+"px",n.font].filter((function(t){return t})).join(" "),r.textAlign="start",r.textBaseline="alphabetic",r.direction="ltr",h(function(t,e,r,n,a,o){r=r.replace(/\n/g,""),r=!0===o.breaklines?r.replace(/\<br\>/g,"\n"):r.replace(/\<br\>/g," ");var s="",l=[];for(p=0;p<r.length;++p)l[p]=s;!0===o.bolds&&(l=c("b","b|",r,l));!0===o.italics&&(l=c("i","i|",r,l));!0===o.superscripts&&(l=c("sup","+1",r,l));!0===o.subscripts&&(l=c("sub","-1",r,l));var u=[],f="";for(p=0;p<r.length;++p)null!==l[p]&&(f+=r[p],u.push(l[p]));var h,p,d,m,g,v=f.split("\n"),y=v.length,x=Math.round(a*n),b=n,_=2*n,w=0,T=y*x+_;t.height<T&&(t.height=T);e.fillStyle="#000",e.fillRect(0,0,t.width,t.height),e.fillStyle="#fff";var k=0,A="";function M(){if(""!==A){var t=e.measureText(A).width;e.fillText(A,b+d,_+m),d+=t}}function S(){return Math.round(g)+"px "}function E(t,r){var n=""+e.font;if(!0===o.subscripts){var i=t.indexOf("-"),a=r.indexOf("-"),s=i>-1?parseInt(t[1+i]):0,l=a>-1?parseInt(r[1+a]):0;s!==l&&(n=n.replace(S(),"?px "),g*=Math.pow(.75,l-s),n=n.replace("?px ",S())),m+=.25*x*(l-s)}if(!0===o.superscripts){var c=t.indexOf("+"),u=r.indexOf("+"),f=c>-1?parseInt(t[1+c]):0,h=u>-1?parseInt(r[1+u]):0;f!==h&&(n=n.replace(S(),"?px "),g*=Math.pow(.75,h-f),n=n.replace("?px ",S())),m-=.25*x*(h-f)}if(!0===o.bolds){var p=t.indexOf("b|")>-1,d=r.indexOf("b|")>-1;!p&&d&&(n=v?n.replace("italic ","italic bold "):"bold "+n),p&&!d&&(n=n.replace("bold ",""))}if(!0===o.italics){var v=t.indexOf("i|")>-1,y=r.indexOf("i|")>-1;!v&&y&&(n="italic "+n),v&&!y&&(n=n.replace("italic ",""))}e.font=n}for(h=0;h<y;++h){var L=v[h]+"\n";for(d=0,m=h*x,g=n,A="",p=0;p<L.length;++p){var C=p+k<u.length?u[p+k]:u[u.length-1];s===C?A+=L[p]:(M(),A=L[p],void 0!==C&&(E(s,C),s=C))}M(),k+=L.length;var P=0|Math.round(d+2*b);w<P&&(w=P)}var I=w,O=_+x*y;return i(e.getImageData(0,0,I,O).data,[O,I,4]).pick(-1,-1,0).transpose(1,0)}(e,r,t,a,o,s),n,a)},e.exports.processPixels=h;var n=t("surface-nets"),i=t("ndarray"),a=t("simplify-planar-graph"),o=t("clean-pslg"),s=t("cdt2d"),l=t("planar-graph-to-polyline");function c(t,e,r,n){for(var i="<"+t+">",a="</"+t+">",o=i.length,s=a.length,l="+"===e[0]||"-"===e[0],c=0,u=-s;c>-1&&-1!==(c=r.indexOf(i,c))&&-1!==(u=r.indexOf(a,c+o))&&!(u<=c);){for(var f=c;f<u+s;++f)if(f<c+o||f>=u)n[f]=null,r=r.substr(0,f)+" "+r.substr(f+1);else if(null!==n[f]){var h=n[f].indexOf(e[0]);-1===h?n[f]+=e:l&&(n[f]=n[f].substr(0,h+1)+(1+parseInt(n[f][h+1]))+n[f].substr(h+2))}var p=c+o,d=r.substr(p,u-p).indexOf(i);c=-1!==d?d:u+s}return n}function u(t,e){var r=n(t,128);return e?a(r.cells,r.positions,.25):{edges:r.cells,positions:r.positions}}function f(t,e,r,n){var i=u(t,n),a=function(t,e,r){for(var n=e.textAlign||"start",i=e.textBaseline||"alphabetic",a=[1<<30,1<<30],o=[0,0],s=t.length,l=0;l<s;++l)for(var c=t[l],u=0;u<2;++u)a[u]=0|Math.min(a[u],c[u]),o[u]=0|Math.max(o[u],c[u]);var f=0;switch(n){case"center":f=-.5*(a[0]+o[0]);break;case"right":case"end":f=-o[0];break;case"left":case"start":f=-a[0];break;default:throw new Error("vectorize-text: Unrecognized textAlign: '"+n+"'")}var h=0;switch(i){case"hanging":case"top":h=-a[1];break;case"middle":h=-.5*(a[1]+o[1]);break;case"alphabetic":case"ideographic":h=-3*r;break;case"bottom":h=-o[1];break;default:throw new Error("vectorize-text: Unrecoginized textBaseline: '"+i+"'")}var p=1/r;return"lineHeight"in e?p*=+e.lineHeight:"width"in e?p=e.width/(o[0]-a[0]):"height"in e&&(p=e.height/(o[1]-a[1])),t.map((function(t){return[p*(t[0]+f),p*(t[1]+h)]}))}(i.positions,e,r),c=i.edges,f="ccw"===e.orientation;if(o(a,c),e.polygons||e.polygon||e.polyline){for(var h=l(c,a),p=new Array(h.length),d=0;d<h.length;++d){for(var m=h[d],g=new Array(m.length),v=0;v<m.length;++v){for(var y=m[v],x=new Array(y.length),b=0;b<y.length;++b)x[b]=a[y[b]].slice();f&&x.reverse(),g[v]=x}p[d]=g}return p}return e.triangles||e.triangulate||e.triangle?{cells:s(a,c,{delaunay:!1,exterior:!1,interior:!0}),positions:a}:{edges:c,positions:a}}function h(t,e,r){try{return f(t,e,r,!0)}catch(t){}try{return f(t,e,r,!1)}catch(t){}return e.polygons||e.polyline||e.polygon?[]:e.triangles||e.triangulate||e.triangle?{cells:[],positions:[]}:{edges:[],positions:[]}}},{cdt2d:42,"clean-pslg":50,ndarray:259,"planar-graph-to-polyline":268,"simplify-planar-graph":297,"surface-nets":302}],313:[function(t,e,r){!function(){"use strict";if("undefined"==typeof ses||!ses.ok||ses.ok()){"undefined"!=typeof ses&&(ses.weakMapPermitHostObjects=m);var t=!1;if("function"==typeof WeakMap){var r=WeakMap;if("undefined"!=typeof navigator&&/Firefox/.test(navigator.userAgent));else{var n=new r,i=Object.freeze({});if(n.set(i,1),1===n.get(i))return void(e.exports=WeakMap);t=!0}}Object.prototype.hasOwnProperty;var a=Object.getOwnPropertyNames,o=Object.defineProperty,s=Object.isExtensible,l="weakmap:ident:"+Math.random()+"___";if("undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues&&"function"==typeof ArrayBuffer&&"function"==typeof Uint8Array){var c=new ArrayBuffer(25),u=new Uint8Array(c);crypto.getRandomValues(u),l="weakmap:rand:"+Array.prototype.map.call(u,(function(t){return(t%36).toString(36)})).join("")+"___"}if(o(Object,"getOwnPropertyNames",{value:function(t){return a(t).filter(g)}}),"getPropertyNames"in Object){var f=Object.getPropertyNames;o(Object,"getPropertyNames",{value:function(t){return f(t).filter(g)}})}!function(){var t=Object.freeze;o(Object,"freeze",{value:function(e){return v(e),t(e)}});var e=Object.seal;o(Object,"seal",{value:function(t){return v(t),e(t)}});var r=Object.preventExtensions;o(Object,"preventExtensions",{value:function(t){return v(t),r(t)}})}();var h=!1,p=0,d=function(){this instanceof d||x();var t=[],e=[],r=p++;return Object.create(d.prototype,{get___:{value:y((function(n,i){var a,o=v(n);return o?r in o?o[r]:i:(a=t.indexOf(n))>=0?e[a]:i}))},has___:{value:y((function(e){var n=v(e);return n?r in n:t.indexOf(e)>=0}))},set___:{value:y((function(n,i){var a,o=v(n);return o?o[r]=i:(a=t.indexOf(n))>=0?e[a]=i:(a=t.length,e[a]=i,t[a]=n),this}))},delete___:{value:y((function(n){var i,a,o=v(n);return o?r in o&&delete o[r]:!((i=t.indexOf(n))<0)&&(a=t.length-1,t[i]=void 0,e[i]=e[a],t[i]=t[a],t.length=a,e.length=a,!0)}))}})};d.prototype=Object.create(Object.prototype,{get:{value:function(t,e){return this.get___(t,e)},writable:!0,configurable:!0},has:{value:function(t){return this.has___(t)},writable:!0,configurable:!0},set:{value:function(t,e){return this.set___(t,e)},writable:!0,configurable:!0},delete:{value:function(t){return this.delete___(t)},writable:!0,configurable:!0}}),"function"==typeof r?function(){function n(){this instanceof d||x();var e,n=new r,i=void 0,a=!1;return e=t?function(t,e){return n.set(t,e),n.has(t)||(i||(i=new d),i.set(t,e)),this}:function(t,e){if(a)try{n.set(t,e)}catch(r){i||(i=new d),i.set___(t,e)}else n.set(t,e);return this},Object.create(d.prototype,{get___:{value:y((function(t,e){return i?n.has(t)?n.get(t):i.get___(t,e):n.get(t,e)}))},has___:{value:y((function(t){return n.has(t)||!!i&&i.has___(t)}))},set___:{value:y(e)},delete___:{value:y((function(t){var e=!!n.delete(t);return i&&i.delete___(t)||e}))},permitHostObjects___:{value:y((function(t){if(t!==m)throw new Error("bogus call to permitHostObjects___");a=!0}))}})}t&&"undefined"!=typeof Proxy&&(Proxy=void 0),n.prototype=d.prototype,e.exports=n,Object.defineProperty(WeakMap.prototype,"constructor",{value:WeakMap,enumerable:!1,configurable:!0,writable:!0})}():("undefined"!=typeof Proxy&&(Proxy=void 0),e.exports=d)}function m(t){t.permitHostObjects___&&t.permitHostObjects___(m)}function g(t){return!("weakmap:"==t.substr(0,"weakmap:".length)&&"___"===t.substr(t.length-3))}function v(t){if(t!==Object(t))throw new TypeError("Not an object: "+t);var e=t[l];if(e&&e.key===t)return e;if(s(t)){e={key:t};try{return o(t,l,{value:e,writable:!1,enumerable:!1,configurable:!1}),e}catch(t){return}}}function y(t){return t.prototype=null,Object.freeze(t)}function x(){h||"undefined"==typeof console||(h=!0,console.warn("WeakMap should be invoked as new WeakMap(), not WeakMap(). This will be an error in the future."))}}()},{}],314:[function(t,e,r){var n=t("./hidden-store.js");e.exports=function(){var t={};return function(e){if(("object"!=typeof e||null===e)&&"function"!=typeof e)throw new Error("Weakmap-shim: Key must be object");var r=e.valueOf(t);return r&&r.identity===t?r:n(e,t)}}},{"./hidden-store.js":315}],315:[function(t,e,r){e.exports=function(t,e){var r={identity:e},n=t.valueOf;return Object.defineProperty(t,"valueOf",{value:function(t){return t!==e?n.apply(this,arguments):r},writable:!0}),r}},{}],316:[function(t,e,r){var n=t("./create-store.js");e.exports=function(){var t=n();return{get:function(e,r){var n=t(e);return n.hasOwnProperty("value")?n.value:r},set:function(e,r){return t(e).value=r,this},has:function(e){return"value"in t(e)},delete:function(e){return delete t(e).value}}}},{"./create-store.js":314}],317:[function(t,e,r){"use strict";var n,i=function(){return function(t,e,r,n,i,a){var o=t[0],s=r[0],l=[0],c=s;n|=0;var u=0,f=s;for(u=0;u<o;++u){var h=e[n]-a,p=e[n+c]-a;h>=0!=p>=0&&i.push(l[0]+.5+.5*(h+p)/(h-p)),n+=f,++l[0]}}};e.exports=(n={funcName:{funcName:"zeroCrossings"}.funcName},function(t){var e={};return function(r,n,i){var a=r.dtype,o=r.order,s=[a,o.join()].join(),l=e[s];return l||(e[s]=l=t([a,o])),l(r.shape.slice(0),r.data,r.stride,0|r.offset,n,i)}}(i.bind(void 0,n)))},{}],318:[function(t,e,r){"use strict";e.exports=function(t,e){var r=[];return e=+e||0,n(t.hi(t.shape[0]-1),r,e),r};var n=t("./lib/zc-core")},{"./lib/zc-core":317}]},{},[6])(6)}))}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[27])(27)}));</script>                <div id="162d888a-81e0-4741-a406-98cc539adab6" class="plotly-graph-div js-plotly-plot" style="height:600px; width:1200px;"><div class="plot-container plotly"><div class="user-select-none svg-container" style="position: relative; width: 1200px; height: 600px;"><svg class="main-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1200" height="600" style="background: white;"><defs id="defs-1bd8a8"><g class="clips"><clippath id="clip1bd8a8xyplot" class="plotclip"><rect width="426.15000000000003" height="170.25"></rect></clippath><clippath id="clip1bd8a8x2y2plot" class="plotclip"><rect width="426.15" height="170.25"></rect></clippath><clippath id="clip1bd8a8x3y3plot" class="plotclip"><rect width="426.15000000000003" height="170.25"></rect></clippath><clippath id="clip1bd8a8x4y4plot" class="plotclip"><rect width="426.15" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x"><rect x="62" y="0" width="426.15000000000003" height="600"></rect></clippath><clippath class="axesclip" id="clip1bd8a8y"><rect x="0" y="100" width="1200" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8xy"><rect x="62" y="100" width="426.15000000000003" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8y2"><rect x="0" y="100" width="1200" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8xy2"><rect x="62" y="100" width="426.15000000000003" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8y3"><rect x="0" y="383.75" width="1200" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8xy3"><rect x="62" y="383.75" width="426.15000000000003" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8y4"><rect x="0" y="383.75" width="1200" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8xy4"><rect x="62" y="383.75" width="426.15000000000003" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x2"><rect x="582.85" y="0" width="426.15" height="600"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x2y"><rect x="582.85" y="100" width="426.15" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x2y2"><rect x="582.85" y="100" width="426.15" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x2y3"><rect x="582.85" y="383.75" width="426.15" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x2y4"><rect x="582.85" y="383.75" width="426.15" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x3"><rect x="62" y="0" width="426.15000000000003" height="600"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x3y"><rect x="62" y="100" width="426.15000000000003" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x3y2"><rect x="62" y="100" width="426.15000000000003" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x3y3"><rect x="62" y="383.75" width="426.15000000000003" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x3y4"><rect x="62" y="383.75" width="426.15000000000003" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x4"><rect x="582.85" y="0" width="426.15" height="600"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x4y"><rect x="582.85" y="100" width="426.15" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x4y2"><rect x="582.85" y="100" width="426.15" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x4y3"><rect x="582.85" y="383.75" width="426.15" height="170.25"></rect></clippath><clippath class="axesclip" id="clip1bd8a8x4y4"><rect x="582.85" y="383.75" width="426.15" height="170.25"></rect></clippath></g><g class="gradients"></g><g class="patterns"></g></defs><g class="bglayer"><rect class="bg" x="62" y="100" width="426.15000000000003" height="170.25" style="fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;"></rect><rect class="bg" x="582.85" y="100" width="426.15" height="170.25" style="fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;"></rect><rect class="bg" x="62" y="383.75" width="426.15000000000003" height="170.25" style="fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;"></rect><rect class="bg" x="582.85" y="383.75" width="426.15" height="170.25" style="fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;"></rect></g><g class="draglayer cursor-crosshair"><g class="xy"><rect class="nsewdrag drag" data-subplot="xy" x="62" y="100" width="426.15000000000003" height="170.25" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="nwdrag drag cursor-nw-resize" data-subplot="xy" x="42" y="80" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="nedrag drag cursor-ne-resize" data-subplot="xy" x="488.15000000000003" y="80" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="swdrag drag cursor-sw-resize" data-subplot="xy" x="42" y="270.25" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="sedrag drag cursor-se-resize" data-subplot="xy" x="488.15000000000003" y="270.25" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="ewdrag drag cursor-ew-resize" data-subplot="xy" x="104.61500000000001" y="270.75" width="340.9200000000001" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="wdrag drag cursor-w-resize" data-subplot="xy" x="62" y="270.75" width="42.61500000000001" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="edrag drag cursor-e-resize" data-subplot="xy" x="445.535" y="270.75" width="42.61500000000001" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="nsdrag drag cursor-ns-resize" data-subplot="xy" x="41.5" y="117.025" width="20" height="136.20000000000002" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="sdrag drag cursor-s-resize" data-subplot="xy" x="41.5" y="253.225" width="20" height="17.025000000000002" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="ndrag drag cursor-n-resize" data-subplot="xy" x="41.5" y="100" width="20" height="17.025000000000002" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect></g><g class="x2y2"><rect class="nsewdrag drag" data-subplot="x2y2" x="582.85" y="100" width="426.15" height="170.25" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="nwdrag drag cursor-nw-resize" data-subplot="x2y2" x="562.85" y="80" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="nedrag drag cursor-ne-resize" data-subplot="x2y2" x="1009" y="80" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="swdrag drag cursor-sw-resize" data-subplot="x2y2" x="562.85" y="270.25" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="sedrag drag cursor-se-resize" data-subplot="x2y2" x="1009" y="270.25" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="ewdrag drag cursor-ew-resize" data-subplot="x2y2" x="625.465" y="270.75" width="340.92" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="wdrag drag cursor-w-resize" data-subplot="x2y2" x="582.85" y="270.75" width="42.615" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="edrag drag cursor-e-resize" data-subplot="x2y2" x="966.385" y="270.75" width="42.615" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="nsdrag drag cursor-ns-resize" data-subplot="x2y2" x="562.35" y="117.025" width="20" height="136.20000000000002" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="sdrag drag cursor-s-resize" data-subplot="x2y2" x="562.35" y="253.225" width="20" height="17.025000000000002" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="ndrag drag cursor-n-resize" data-subplot="x2y2" x="562.35" y="100" width="20" height="17.025000000000002" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect></g><g class="x3y3"><rect class="nsewdrag drag" data-subplot="x3y3" x="62" y="383.75" width="426.15000000000003" height="170.25" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="nwdrag drag cursor-nw-resize" data-subplot="x3y3" x="42" y="363.75" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="nedrag drag cursor-ne-resize" data-subplot="x3y3" x="488.15000000000003" y="363.75" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="swdrag drag cursor-sw-resize" data-subplot="x3y3" x="42" y="554" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="sedrag drag cursor-se-resize" data-subplot="x3y3" x="488.15000000000003" y="554" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="ewdrag drag cursor-ew-resize" data-subplot="x3y3" x="104.61500000000001" y="554.5" width="340.9200000000001" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="wdrag drag cursor-w-resize" data-subplot="x3y3" x="62" y="554.5" width="42.61500000000001" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="edrag drag cursor-e-resize" data-subplot="x3y3" x="445.535" y="554.5" width="42.61500000000001" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="nsdrag drag cursor-ns-resize" data-subplot="x3y3" x="41.5" y="400.775" width="20" height="136.20000000000002" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="sdrag drag cursor-s-resize" data-subplot="x3y3" x="41.5" y="536.975" width="20" height="17.025000000000002" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="ndrag drag cursor-n-resize" data-subplot="x3y3" x="41.5" y="383.75" width="20" height="17.025000000000002" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect></g><g class="x4y4"><rect class="nsewdrag drag" data-subplot="x4y4" x="582.85" y="383.75" width="426.15" height="170.25" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="nwdrag drag cursor-nw-resize" data-subplot="x4y4" x="562.85" y="363.75" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="nedrag drag cursor-ne-resize" data-subplot="x4y4" x="1009" y="363.75" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="swdrag drag cursor-sw-resize" data-subplot="x4y4" x="562.85" y="554" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="sedrag drag cursor-se-resize" data-subplot="x4y4" x="1009" y="554" width="20" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="ewdrag drag cursor-ew-resize" data-subplot="x4y4" x="625.465" y="554.5" width="340.92" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="wdrag drag cursor-w-resize" data-subplot="x4y4" x="582.85" y="554.5" width="42.615" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="edrag drag cursor-e-resize" data-subplot="x4y4" x="966.385" y="554.5" width="42.615" height="20" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="nsdrag drag cursor-ns-resize" data-subplot="x4y4" x="562.35" y="400.775" width="20" height="136.20000000000002" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="sdrag drag cursor-s-resize" data-subplot="x4y4" x="562.35" y="536.975" width="20" height="17.025000000000002" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect><rect class="ndrag drag cursor-n-resize" data-subplot="x4y4" x="562.35" y="383.75" width="20" height="17.025000000000002" style="fill: transparent; stroke-width: 0; pointer-events: all;"></rect></g></g><g class="layer-below"><g class="imagelayer"></g><g class="shapelayer"></g></g><g class="cartesianlayer"><g class="subplot xy"><g class="layer-subplot"><g class="shapelayer"></g><g class="imagelayer"></g></g><g class="minor-gridlayer"><g class="x"></g><g class="y"></g></g><g class="gridlayer"><g class="x"><path class="xgrid crisp" transform="translate(170.59,0)" d="M0,100v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="xgrid crisp" transform="translate(254.16,0)" d="M0,100v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="xgrid crisp" transform="translate(337.73,0)" d="M0,100v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="xgrid crisp" transform="translate(421.3,0)" d="M0,100v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path></g><g class="y"><path class="ygrid crisp" transform="translate(0,211.76999999999998)" d="M62,0h426.15000000000003" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="ygrid crisp" transform="translate(0,165.55)" d="M62,0h426.15000000000003" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="ygrid crisp" transform="translate(0,119.32)" d="M62,0h426.15000000000003" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path></g></g><g class="zerolinelayer"><path class="xzl zl crisp" transform="translate(87.02,0)" d="M0,100v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 2px;"></path><path class="yzl zl crisp" transform="translate(0,258)" d="M62,0h426.15000000000003" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 2px;"></path></g><path class="xlines-below"></path><path class="ylines-below"></path><g class="overlines-below"></g><g class="xaxislayer-below"></g><g class="yaxislayer-below"></g><g class="overaxes-below"></g><g class="plot" transform="translate(62,100)" clip-path="url(#clip1bd8a8xyplot)"><g class="scatterlayer mlayer"><g class="trace scatter trace07289b" style="stroke-miterlimit: 2; opacity: 1;"><g class="fills"></g><g class="errorbars"></g><g class="lines"><path class="js-line" d="M25.06,157.98L401.09,155.83" style="vector-effect: non-scaling-stroke; fill: none; stroke: rgb(0, 128, 0); stroke-opacity: 1; stroke-width: 2px; opacity: 1; stroke-dasharray: 9px, 9px;"></path></g><g class="points"><path class="point" transform="translate(25.06,157.98)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 128, 0); fill-opacity: 1;"></path><path class="point" transform="translate(66.82,157.72)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 128, 0); fill-opacity: 1;"></path><path class="point" transform="translate(108.6,157.44)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 128, 0); fill-opacity: 1;"></path><path class="point" transform="translate(150.39,157.12)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 128, 0); fill-opacity: 1;"></path><path class="point" transform="translate(192.17,156.82)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 128, 0); fill-opacity: 1;"></path><path class="point" transform="translate(233.95,156.71)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 128, 0); fill-opacity: 1;"></path><path class="point" transform="translate(275.74,156.5)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 128, 0); fill-opacity: 1;"></path><path class="point" transform="translate(317.52,156.09)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 128, 0); fill-opacity: 1;"></path><path class="point" transform="translate(359.31,156.06)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 128, 0); fill-opacity: 1;"></path><path class="point" transform="translate(401.09,155.83)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 128, 0); fill-opacity: 1;"></path></g><g class="text"></g></g><g class="trace scatter trace7d5b00" style="stroke-miterlimit: 2; opacity: 1;"><g class="fills"></g><g class="errorbars"></g><g class="lines"><path class="js-line" d="M25.06,157.99L66.82,155.2L108.6,149.21L192.17,128.45L233.95,101.97L275.74,84.26L317.52,69.21L359.31,45.78L401.09,12.26" style="vector-effect: non-scaling-stroke; fill: none; stroke: rgb(255, 165, 0); stroke-opacity: 1; stroke-width: 2px; opacity: 1; stroke-dasharray: 3px, 3px;"></path></g><g class="points"><path class="point" transform="translate(25.06,157.99)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 165, 0); fill-opacity: 1;"></path><path class="point" transform="translate(66.82,155.2)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 165, 0); fill-opacity: 1;"></path><path class="point" transform="translate(108.6,149.21)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 165, 0); fill-opacity: 1;"></path><path class="point" transform="translate(150.39,138.95)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 165, 0); fill-opacity: 1;"></path><path class="point" transform="translate(192.17,128.45)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 165, 0); fill-opacity: 1;"></path><path class="point" transform="translate(233.95,101.97)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 165, 0); fill-opacity: 1;"></path><path class="point" transform="translate(275.74,84.26)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 165, 0); fill-opacity: 1;"></path><path class="point" transform="translate(317.52,69.21)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 165, 0); fill-opacity: 1;"></path><path class="point" transform="translate(359.31,45.78)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 165, 0); fill-opacity: 1;"></path><path class="point" transform="translate(401.09,12.26)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 165, 0); fill-opacity: 1;"></path></g><g class="text"></g></g></g></g><g class="overplot"></g><path class="xlines-above crisp" d="M0,0" style="fill: none;"></path><path class="ylines-above crisp" d="M0,0" style="fill: none;"></path><g class="overlines-above"></g><g class="xaxislayer-above"><g class="xtick"><text text-anchor="middle" x="0" y="285.25" data-unformatted="0" data-math="N" transform="translate(87.02,0)" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;">0</text></g><g class="xtick"><text text-anchor="middle" x="0" y="285.25" data-unformatted="10k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(170.59,0)">10k</text></g><g class="xtick"><text text-anchor="middle" x="0" y="285.25" data-unformatted="20k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(254.16,0)">20k</text></g><g class="xtick"><text text-anchor="middle" x="0" y="285.25" data-unformatted="30k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(337.73,0)">30k</text></g><g class="xtick"><text text-anchor="middle" x="0" y="285.25" data-unformatted="40k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(421.3,0)">40k</text></g></g><g class="yaxislayer-above"><g class="ytick"><text text-anchor="end" x="61" y="4.8999999999999995" data-unformatted="0" data-math="N" transform="translate(0,258)" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;">0</text></g><g class="ytick"><text text-anchor="end" x="61" y="4.8999999999999995" data-unformatted="20k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,211.76999999999998)">20k</text></g><g class="ytick"><text text-anchor="end" x="61" y="4.8999999999999995" data-unformatted="40k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,165.55)">40k</text></g><g class="ytick"><text text-anchor="end" x="61" y="4.8999999999999995" data-unformatted="60k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,119.32)">60k</text></g></g><g class="overaxes-above"></g></g><g class="subplot x2y2"><g class="layer-subplot"><g class="shapelayer"></g><g class="imagelayer"></g></g><g class="minor-gridlayer"><g class="x2"></g><g class="y2"></g></g><g class="gridlayer"><g class="x2"><path class="x2grid crisp" transform="translate(691.44,0)" d="M0,100v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="x2grid crisp" transform="translate(775.01,0)" d="M0,100v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="x2grid crisp" transform="translate(858.58,0)" d="M0,100v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="x2grid crisp" transform="translate(942.1500000000001,0)" d="M0,100v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path></g><g class="y2"><path class="y2grid crisp" transform="translate(0,263.9)" d="M582.85,0h426.15" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="y2grid crisp" transform="translate(0,224.51)" d="M582.85,0h426.15" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="y2grid crisp" transform="translate(0,185.13)" d="M582.85,0h426.15" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="y2grid crisp" transform="translate(0,145.74)" d="M582.85,0h426.15" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="y2grid crisp" transform="translate(0,106.35)" d="M582.85,0h426.15" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path></g></g><g class="zerolinelayer"><path class="x2zl zl crisp" transform="translate(607.87,0)" d="M0,100v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 2px;"></path></g><path class="xlines-below"></path><path class="ylines-below"></path><g class="overlines-below"></g><g class="xaxislayer-below"></g><g class="yaxislayer-below"></g><g class="overaxes-below"></g><g class="plot" transform="translate(582.85,100)" clip-path="url(#clip1bd8a8x2y2plot)"><g class="scatterlayer mlayer"><g class="trace scatter trace868ffc" style="stroke-miterlimit: 2; opacity: 1;"><g class="fills"></g><g class="errorbars"></g><g class="lines"><path class="js-line" d="M25.06,47.71L66.82,148.14L108.6,120.57L150.39,116.63L192.17,130.42L233.95,136.33L275.74,156.02L317.52,12.26L359.31,157.99L401.09,157.99" style="vector-effect: non-scaling-stroke; fill: none; stroke: rgb(0, 0, 255); stroke-opacity: 1; stroke-width: 2px; opacity: 1; stroke-dasharray: 9px, 9px;"></path></g><g class="points"><path class="point" transform="translate(25.06,47.71)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 0, 255); fill-opacity: 1;"></path><path class="point" transform="translate(66.82,148.14)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 0, 255); fill-opacity: 1;"></path><path class="point" transform="translate(108.6,120.57)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 0, 255); fill-opacity: 1;"></path><path class="point" transform="translate(150.39,116.63)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 0, 255); fill-opacity: 1;"></path><path class="point" transform="translate(192.17,130.42)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 0, 255); fill-opacity: 1;"></path><path class="point" transform="translate(233.95,136.33)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 0, 255); fill-opacity: 1;"></path><path class="point" transform="translate(275.74,156.02)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 0, 255); fill-opacity: 1;"></path><path class="point" transform="translate(317.52,12.26)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 0, 255); fill-opacity: 1;"></path><path class="point" transform="translate(359.31,157.99)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 0, 255); fill-opacity: 1;"></path><path class="point" transform="translate(401.09,157.99)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 0, 255); fill-opacity: 1;"></path></g><g class="text"></g></g><g class="trace scatter traceb55202" style="stroke-miterlimit: 2; opacity: 1;"><g class="fills"></g><g class="errorbars"></g><g class="lines"><path class="js-line" d="M25.06,83.16L66.82,75.28L108.6,85.13L150.39,94.97L192.17,20.14L233.95,79.22L275.74,89.06L317.52,91.03L359.31,73.31L401.09,94.97" style="vector-effect: non-scaling-stroke; fill: none; stroke: rgb(255, 0, 0); stroke-opacity: 1; stroke-width: 2px; opacity: 1; stroke-dasharray: 3px, 3px;"></path></g><g class="points"><path class="point" transform="translate(25.06,83.16)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 0, 0); fill-opacity: 1;"></path><path class="point" transform="translate(66.82,75.28)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 0, 0); fill-opacity: 1;"></path><path class="point" transform="translate(108.6,85.13)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 0, 0); fill-opacity: 1;"></path><path class="point" transform="translate(150.39,94.97)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 0, 0); fill-opacity: 1;"></path><path class="point" transform="translate(192.17,20.14)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 0, 0); fill-opacity: 1;"></path><path class="point" transform="translate(233.95,79.22)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 0, 0); fill-opacity: 1;"></path><path class="point" transform="translate(275.74,89.06)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 0, 0); fill-opacity: 1;"></path><path class="point" transform="translate(317.52,91.03)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 0, 0); fill-opacity: 1;"></path><path class="point" transform="translate(359.31,73.31)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 0, 0); fill-opacity: 1;"></path><path class="point" transform="translate(401.09,94.97)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 0, 0); fill-opacity: 1;"></path></g><g class="text"></g></g></g></g><g class="overplot"></g><path class="xlines-above crisp" d="M0,0" style="fill: none;"></path><path class="ylines-above crisp" d="M0,0" style="fill: none;"></path><g class="overlines-above"></g><g class="xaxislayer-above"><g class="x2tick"><text text-anchor="middle" x="0" y="285.25" data-unformatted="0" data-math="N" transform="translate(607.87,0)" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;">0</text></g><g class="x2tick"><text text-anchor="middle" x="0" y="285.25" data-unformatted="10k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(691.44,0)">10k</text></g><g class="x2tick"><text text-anchor="middle" x="0" y="285.25" data-unformatted="20k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(775.01,0)">20k</text></g><g class="x2tick"><text text-anchor="middle" x="0" y="285.25" data-unformatted="30k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(858.58,0)">30k</text></g><g class="x2tick"><text text-anchor="middle" x="0" y="285.25" data-unformatted="40k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(942.1500000000001,0)">40k</text></g></g><g class="yaxislayer-above"><g class="y2tick"><text text-anchor="end" x="581.85" y="4.8999999999999995" data-unformatted="0.06" data-math="N" transform="translate(0,263.9)" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;">0.06</text></g><g class="y2tick"><text text-anchor="end" x="581.85" y="4.8999999999999995" data-unformatted="0.08" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,224.51)">0.08</text></g><g class="y2tick"><text text-anchor="end" x="581.85" y="4.8999999999999995" data-unformatted="0.1" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,185.13)">0.1</text></g><g class="y2tick"><text text-anchor="end" x="581.85" y="4.8999999999999995" data-unformatted="0.12" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,145.74)">0.12</text></g><g class="y2tick"><text text-anchor="end" x="581.85" y="4.8999999999999995" data-unformatted="0.14" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,106.35)">0.14</text></g></g><g class="overaxes-above"></g></g><g class="subplot x3y3"><g class="layer-subplot"><g class="shapelayer"></g><g class="imagelayer"></g></g><g class="minor-gridlayer"><g class="x3"></g><g class="y3"></g></g><g class="gridlayer"><g class="x3"><path class="x3grid crisp" transform="translate(151.7,0)" d="M0,383.75v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="x3grid crisp" transform="translate(241.42,0)" d="M0,383.75v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="x3grid crisp" transform="translate(331.14,0)" d="M0,383.75v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="x3grid crisp" transform="translate(420.86,0)" d="M0,383.75v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path></g><g class="y3"><path class="y3grid crisp" transform="translate(0,481.82)" d="M62,0h426.15000000000003" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="y3grid crisp" transform="translate(0,418.15)" d="M62,0h426.15000000000003" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path></g></g><g class="zerolinelayer"><path class="y3zl zl crisp" transform="translate(0,545.49)" d="M62,0h426.15000000000003" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 2px;"></path></g><path class="xlines-below"></path><path class="ylines-below"></path><g class="overlines-below"></g><g class="xaxislayer-below"></g><g class="yaxislayer-below"></g><g class="overaxes-below"></g><g class="plot" transform="translate(62,383.75)" clip-path="url(#clip1bd8a8x3y3plot)"><g class="scatterlayer mlayer"><g class="trace scatter trace161dfe" style="stroke-miterlimit: 2; opacity: 1;"><g class="fills"></g><g class="errorbars"></g><g class="lines"><path class="js-line" d="M0,161.74L426.15,160.22" style="vector-effect: non-scaling-stroke; fill: none; stroke: rgb(0, 128, 0); stroke-opacity: 1; stroke-width: 2px; opacity: 1; stroke-dasharray: 9px, 9px;"></path></g><g class="points"></g><g class="text"></g></g><g class="trace scatter trace9f3882" style="stroke-miterlimit: 2; opacity: 1;"><g class="fills"></g><g class="errorbars"></g><g class="lines"><path class="js-line" d="M0,161.74L22.42,160.96L44.85,158.96L89.71,152.98L112.13,146.32L179.42,130.1L201.85,125.47L224.28,102.59L246.71,93.04L269.14,85.66L291.57,77.33L314,68.35L336.43,57.5L358.86,44.43L381.29,29.86L403.72,16.14L426.15,8.51" style="vector-effect: non-scaling-stroke; fill: none; stroke: rgb(255, 165, 0); stroke-opacity: 1; stroke-width: 2px; opacity: 1; stroke-dasharray: 3px, 3px;"></path></g><g class="points"></g><g class="text"></g></g></g></g><g class="overplot"></g><path class="xlines-above crisp" d="M0,0" style="fill: none;"></path><path class="ylines-above crisp" d="M0,0" style="fill: none;"></path><g class="overlines-above"></g><g class="xaxislayer-above"><g class="x3tick"><text text-anchor="middle" x="0" y="569" data-unformatted="0" data-math="N" transform="translate(61.98,0)" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;">0</text></g><g class="x3tick"><text text-anchor="middle" x="0" y="569" data-unformatted="20k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(151.7,0)">20k</text></g><g class="x3tick"><text text-anchor="middle" x="0" y="569" data-unformatted="40k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(241.42,0)">40k</text></g><g class="x3tick"><text text-anchor="middle" x="0" y="569" data-unformatted="60k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(331.14,0)">60k</text></g><g class="x3tick"><text text-anchor="middle" x="0" y="569" data-unformatted="80k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(420.86,0)">80k</text></g></g><g class="yaxislayer-above"><g class="y3tick"><text text-anchor="end" x="61" y="4.8999999999999995" data-unformatted="0" data-math="N" transform="translate(0,545.49)" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;">0</text></g><g class="y3tick"><text text-anchor="end" x="61" y="4.8999999999999995" data-unformatted="100k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,481.82)">100k</text></g><g class="y3tick"><text text-anchor="end" x="61" y="4.8999999999999995" data-unformatted="200k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,418.15)">200k</text></g></g><g class="overaxes-above"></g></g><g class="subplot x4y4"><g class="layer-subplot"><g class="shapelayer"></g><g class="imagelayer"></g></g><g class="minor-gridlayer"><g class="x4"></g><g class="y4"></g></g><g class="gridlayer"><g class="x4"><path class="x4grid crisp" transform="translate(672.5500000000001,0)" d="M0,383.75v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="x4grid crisp" transform="translate(762.27,0)" d="M0,383.75v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="x4grid crisp" transform="translate(851.99,0)" d="M0,383.75v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="x4grid crisp" transform="translate(941.71,0)" d="M0,383.75v170.25" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path></g><g class="y4"><path class="y4grid crisp" transform="translate(0,531.56)" d="M582.85,0h426.15" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="y4grid crisp" transform="translate(0,496.73)" d="M582.85,0h426.15" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="y4grid crisp" transform="translate(0,461.90999999999997)" d="M582.85,0h426.15" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="y4grid crisp" transform="translate(0,427.09000000000003)" d="M582.85,0h426.15" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path><path class="y4grid crisp" transform="translate(0,392.26)" d="M582.85,0h426.15" style="stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;"></path></g></g><g class="zerolinelayer"></g><path class="xlines-below"></path><path class="ylines-below"></path><g class="overlines-below"></g><g class="xaxislayer-below"></g><g class="yaxislayer-below"></g><g class="overaxes-below"></g><g class="plot" transform="translate(582.85,383.75)" clip-path="url(#clip1bd8a8x4y4plot)"><g class="scatterlayer mlayer"><g class="trace scatter trace581c4a" style="stroke-miterlimit: 2; opacity: 1;"><g class="fills"></g><g class="errorbars"></g><g class="lines"><path class="js-line" d="M0,111.24L22.42,132.14L44.85,111.24L67.28,99.05L89.71,125.17L112.13,126.91L134.56,106.02L156.99,109.5L179.42,106.02L201.85,125.17L224.28,133.88L246.71,149.55L269.14,144.33L291.57,111.24L314,130.4L336.43,137.36L358.86,137.36L381.29,60.75L403.72,8.51L426.15,128.65" style="vector-effect: non-scaling-stroke; fill: none; stroke: rgb(0, 0, 255); stroke-opacity: 1; stroke-width: 2px; opacity: 1; stroke-dasharray: 9px, 9px;"></path></g><g class="points"></g><g class="text"></g></g><g class="trace scatter traced894a7" style="stroke-miterlimit: 2; opacity: 1;"><g class="fills"></g><g class="errorbars"></g><g class="lines"><path class="js-line" d="M0,154.77L22.42,142.58L44.85,153.03L67.28,144.33L89.71,123.43L112.13,32.89L134.56,100.8L156.99,48.56L179.42,153.03L201.85,144.33L224.28,128.65L246.71,147.81L269.14,161.74L291.57,149.55L314,147.81L336.43,156.51L358.86,147.81L381.29,147.81L403.72,160L426.15,135.62" style="vector-effect: non-scaling-stroke; fill: none; stroke: rgb(255, 0, 0); stroke-opacity: 1; stroke-width: 2px; opacity: 1; stroke-dasharray: 3px, 3px;"></path></g><g class="points"></g><g class="text"></g></g></g></g><g class="overplot"></g><path class="xlines-above crisp" d="M0,0" style="fill: none;"></path><path class="ylines-above crisp" d="M0,0" style="fill: none;"></path><g class="overlines-above"></g><g class="xaxislayer-above"><g class="x4tick"><text text-anchor="middle" x="0" y="569" data-unformatted="0" data-math="N" transform="translate(582.83,0)" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;">0</text></g><g class="x4tick"><text text-anchor="middle" x="0" y="569" data-unformatted="20k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(672.5500000000001,0)">20k</text></g><g class="x4tick"><text text-anchor="middle" x="0" y="569" data-unformatted="40k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(762.27,0)">40k</text></g><g class="x4tick"><text text-anchor="middle" x="0" y="569" data-unformatted="60k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(851.99,0)">60k</text></g><g class="x4tick"><text text-anchor="middle" x="0" y="569" data-unformatted="80k" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(941.71,0)">80k</text></g></g><g class="yaxislayer-above"><g class="y4tick"><text text-anchor="end" x="581.85" y="4.8999999999999995" data-unformatted="0.08" data-math="N" transform="translate(0,531.56)" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;">0.08</text></g><g class="y4tick"><text text-anchor="end" x="581.85" y="4.8999999999999995" data-unformatted="0.1" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,496.73)">0.1</text></g><g class="y4tick"><text text-anchor="end" x="581.85" y="4.8999999999999995" data-unformatted="0.12" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,461.90999999999997)">0.12</text></g><g class="y4tick"><text text-anchor="end" x="581.85" y="4.8999999999999995" data-unformatted="0.14" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,427.09000000000003)">0.14</text></g><g class="y4tick"><text text-anchor="end" x="581.85" y="4.8999999999999995" data-unformatted="0.16" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre; opacity: 1;" transform="translate(0,392.26)">0.16</text></g></g><g class="overaxes-above"></g></g></g><g class="polarlayer"></g><g class="smithlayer"></g><g class="ternarylayer"></g><g class="geolayer"></g><g class="funnelarealayer"></g><g class="pielayer"></g><g class="iciclelayer"></g><g class="treemaplayer"></g><g class="sunburstlayer"></g><g class="glimages"></g></svg><div class="gl-container"></div><svg class="main-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1200" height="600"><defs id="topdefs-1bd8a8"><g class="clips"></g><clippath id="legend1bd8a8"><rect width="172" height="95" x="0" y="0"></rect></clippath></defs><g class="indicatorlayer"></g><g class="layer-above"><g class="imagelayer"></g><g class="shapelayer"></g></g><g class="infolayer"><g class="legend" pointer-events="all" transform="translate(1027.94,100)"><rect class="bg" shape-rendering="crispEdges" style="stroke: rgb(68, 68, 68); stroke-opacity: 1; fill: rgb(255, 255, 255); fill-opacity: 1; stroke-width: 0px;" width="172" height="95" x="0" y="0"></rect><g class="scrollbox" transform="" clip-path="url(#legend1bd8a8)"><g class="groups"><g class="traces" transform="translate(0,15.6)" style="opacity: 1;"><text class="legendtext" text-anchor="start" x="40" y="5.46" data-unformatted="Transformed ors" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre;">Transformed ors</text><g class="layers" style="opacity: 1;"><g class="legendfill"></g><g class="legendlines"><path class="js-line" d="M5,0h30" style="fill: none; stroke: rgb(0, 128, 0); stroke-opacity: 1; stroke-dasharray: 9px, 9px; stroke-width: 2px;"></path></g><g class="legendsymbols"><g class="legendpoints"><path class="scatterpts" transform="translate(20,0)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 128, 0); fill-opacity: 1;"></path></g></g></g><rect class="legendtoggle" pointer-events="all" x="0" y="-10.6" width="166.03125" height="21.2" style="cursor: pointer; fill: rgb(0, 0, 0); fill-opacity: 0;"></rect></g><g class="traces" transform="translate(0,36.8)" style="opacity: 1;"><text class="legendtext" text-anchor="start" x="40" y="5.46" data-unformatted="Original ors" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre;">Original ors</text><g class="layers" style="opacity: 1;"><g class="legendfill"></g><g class="legendlines"><path class="js-line" d="M5,0h30" style="fill: none; stroke: rgb(255, 165, 0); stroke-opacity: 1; stroke-dasharray: 3px, 3px; stroke-width: 2px;"></path></g><g class="legendsymbols"><g class="legendpoints"><path class="scatterpts" transform="translate(20,0)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 165, 0); fill-opacity: 1;"></path></g></g></g><rect class="legendtoggle" pointer-events="all" x="0" y="-10.6" width="166.03125" height="21.2" style="cursor: pointer; fill: rgb(0, 0, 0); fill-opacity: 0;"></rect></g><g class="traces" transform="translate(0,58)" style="opacity: 1;"><text class="legendtext" text-anchor="start" x="40" y="5.46" data-unformatted="Transformed ors" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre;">Transformed ors</text><g class="layers" style="opacity: 1;"><g class="legendfill"></g><g class="legendlines"><path class="js-line" d="M5,0h30" style="fill: none; stroke: rgb(0, 0, 255); stroke-opacity: 1; stroke-dasharray: 9px, 9px; stroke-width: 2px;"></path></g><g class="legendsymbols"><g class="legendpoints"><path class="scatterpts" transform="translate(20,0)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(0, 0, 255); fill-opacity: 1;"></path></g></g></g><rect class="legendtoggle" pointer-events="all" x="0" y="-10.6" width="166.03125" height="21.2" style="cursor: pointer; fill: rgb(0, 0, 0); fill-opacity: 0;"></rect></g><g class="traces" transform="translate(0,79.19999999999999)" style="opacity: 1;"><text class="legendtext" text-anchor="start" x="40" y="5.46" data-unformatted="Original ors" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 14px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre;">Original ors</text><g class="layers" style="opacity: 1;"><g class="legendfill"></g><g class="legendlines"><path class="js-line" d="M5,0h30" style="fill: none; stroke: rgb(255, 0, 0); stroke-opacity: 1; stroke-dasharray: 3px, 3px; stroke-width: 2px;"></path></g><g class="legendsymbols"><g class="legendpoints"><path class="scatterpts" transform="translate(20,0)" d="M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z" style="opacity: 1; stroke-width: 0px; fill: rgb(255, 0, 0); fill-opacity: 1;"></path></g></g></g><rect class="legendtoggle" pointer-events="all" x="0" y="-10.6" width="166.03125" height="21.2" style="cursor: pointer; fill: rgb(0, 0, 0); fill-opacity: 0;"></rect></g></g></g><rect class="scrollbar" rx="20" ry="3" width="0" height="0" style="fill: rgb(128, 139, 164); fill-opacity: 1;" x="0" y="0"></rect></g><g class="g-gtitle"><text class="gtitle" x="60" y="50" text-anchor="start" dy="0em" data-unformatted="Execution and planning times for execution of or expressions" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 20px; fill: rgb(102, 51, 153); opacity: 1; font-weight: normal; white-space: pre;">Execution and planning times for execution of or expressions</text></g><g class="g-xtitle"><text class="xtitle" x="275.07500000000005" y="316.15" text-anchor="middle" data-unformatted="number of or expressions" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 17px; fill: rgb(102, 51, 153); opacity: 1; font-weight: normal; white-space: pre;">number of or expressions</text></g><g class="g-x2title"><text class="x2title" x="795.925" y="316.15" text-anchor="middle" data-unformatted="number of or expressions" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 17px; fill: rgb(102, 51, 153); opacity: 1; font-weight: normal; white-space: pre;">number of or expressions</text></g><g class="g-x3title" transform="translate(0,-4.899999999999977)"><text class="x3title" x="275.07500000000005" y="599.9" text-anchor="middle" data-unformatted="number of or expressions" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 17px; fill: rgb(102, 51, 153); opacity: 1; font-weight: normal; white-space: pre;">number of or expressions</text></g><g class="g-x4title" transform="translate(0,-4.899999999999977)"><text class="x4title" x="795.925" y="599.9" text-anchor="middle" data-unformatted="number of or expressions" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 17px; fill: rgb(102, 51, 153); opacity: 1; font-weight: normal; white-space: pre;">number of or expressions</text></g><g class="g-ytitle" transform="translate(5.119140625,0)"><text class="ytitle" transform="rotate(-90,8.881250000000001,185.125)" x="8.881250000000001" y="185.125" text-anchor="middle" data-unformatted="MS" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 17px; fill: rgb(102, 51, 153); opacity: 1; font-weight: normal; white-space: pre;">MS</text></g><g class="g-y2title"><text class="y2title" transform="rotate(-90,521.340234375,185.125)" x="521.340234375" y="185.125" text-anchor="middle" data-unformatted="MS" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 17px; fill: rgb(102, 51, 153); opacity: 1; font-weight: normal; white-space: pre;">MS</text></g><g class="g-y3title" transform="translate(13.509765625,0)"><text class="y3title" transform="rotate(-90,0.4906250000000014,468.875)" x="0.4906250000000014" y="468.875" text-anchor="middle" data-unformatted="MS" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 17px; fill: rgb(102, 51, 153); opacity: 1; font-weight: normal; white-space: pre;">MS</text></g><g class="g-y4title"><text class="y4title" transform="rotate(-90,521.340234375,468.875)" x="521.340234375" y="468.875" text-anchor="middle" data-unformatted="MS" data-math="N" style="font-family: &quot;Courier New&quot;, monospace; font-size: 17px; fill: rgb(102, 51, 153); opacity: 1; font-weight: normal; white-space: pre;">MS</text></g><g class="annotation" data-index="0" style="opacity: 1;"><g class="annotation-text-g" transform="rotate(0,275.07500000000005,88.99999999999999)"><g class="cursor-pointer" transform="translate(76,78)"><rect class="bg" x="0.5" y="0.5" width="397" height="21" style="stroke-width: 1px; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 0, 0); fill-opacity: 0;"></rect><text class="annotation-text" text-anchor="middle" data-unformatted="Exec time for ors with index_scan enabled" data-math="N" x="198.8359375" y="15" style="font-family: &quot;Courier New&quot;, monospace; font-size: 16px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre;">Exec time for ors with index_scan enabled</text></g></g></g><g class="annotation" data-index="1" style="opacity: 1;"><g class="annotation-text-g" transform="rotate(0,795.9250000000001,88.99999999999999)"><g class="cursor-pointer" transform="translate(597,78)"><rect class="bg" x="0.5" y="0.5" width="397" height="21" style="stroke-width: 1px; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 0, 0); fill-opacity: 0;"></rect><text class="annotation-text" text-anchor="middle" data-unformatted="Plan time for ors with index_scan enabled" data-math="N" x="198.8359375" y="15" style="font-family: &quot;Courier New&quot;, monospace; font-size: 16px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre;">Plan time for ors with index_scan enabled</text></g></g></g><g class="annotation" data-index="2" style="opacity: 1;"><g class="annotation-text-g" transform="rotate(0,275.07500000000005,372.75)"><g class="cursor-pointer" transform="translate(72,362)"><rect class="bg" x="0.5" y="0.5" width="406" height="21" style="stroke-width: 1px; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 0, 0); fill-opacity: 0;"></rect><text class="annotation-text" text-anchor="middle" data-unformatted="Exec time for ors with index_scan disabled" data-math="N" x="203.6328125" y="15" style="font-family: &quot;Courier New&quot;, monospace; font-size: 16px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre;">Exec time for ors with index_scan disabled</text></g></g></g><g class="annotation" data-index="3" style="opacity: 1;"><g class="annotation-text-g" transform="rotate(0,795.9250000000001,372.75)"><g class="cursor-pointer" transform="translate(592,362)"><rect class="bg" x="0.5" y="0.5" width="406" height="21" style="stroke-width: 1px; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 0, 0); fill-opacity: 0;"></rect><text class="annotation-text" text-anchor="middle" data-unformatted="Plan time for ors with index_scan disabled" data-math="N" x="203.6328125" y="15" style="font-family: &quot;Courier New&quot;, monospace; font-size: 16px; fill: rgb(102, 51, 153); fill-opacity: 1; white-space: pre;">Plan time for ors with index_scan disabled</text></g></g></g></g><g class="menulayer"></g><g class="zoomlayer"></g></svg><div class="modebar-container" style="position: absolute; top: 0px; right: 0px; width: 100%;"><div id="modebar-1bd8a8" class="modebar modebar--hover ease-bg"><div class="modebar-group"><a rel="tooltip" class="modebar-btn" data-title="Download plot as a png" data-toggle="false" data-gravity="n"><svg viewBox="0 0 1000 1000" class="icon" height="1em" width="1em"><path d="m500 450c-83 0-150-67-150-150 0-83 67-150 150-150 83 0 150 67 150 150 0 83-67 150-150 150z m400 150h-120c-16 0-34 13-39 29l-31 93c-6 15-23 28-40 28h-340c-16 0-34-13-39-28l-31-94c-6-15-23-28-40-28h-120c-55 0-100-45-100-100v-450c0-55 45-100 100-100h800c55 0 100 45 100 100v450c0 55-45 100-100 100z m-400-550c-138 0-250 112-250 250 0 138 112 250 250 250 138 0 250-112 250-250 0-138-112-250-250-250z m365 380c-19 0-35 16-35 35 0 19 16 35 35 35 19 0 35-16 35-35 0-19-16-35-35-35z" transform="matrix(1 0 0 -1 0 850)"></path></svg></a></div><div class="modebar-group"><a rel="tooltip" class="modebar-btn active" data-title="Zoom" data-attr="dragmode" data-val="zoom" data-toggle="false" data-gravity="n"><svg viewBox="0 0 1000 1000" class="icon" height="1em" width="1em"><path d="m1000-25l-250 251c40 63 63 138 63 218 0 224-182 406-407 406-224 0-406-182-406-406s183-406 407-406c80 0 155 22 218 62l250-250 125 125z m-812 250l0 438 437 0 0-438-437 0z m62 375l313 0 0-312-313 0 0 312z" transform="matrix(1 0 0 -1 0 850)"></path></svg></a><a rel="tooltip" class="modebar-btn" data-title="Pan" data-attr="dragmode" data-val="pan" data-toggle="false" data-gravity="n"><svg viewBox="0 0 1000 1000" class="icon" height="1em" width="1em"><path d="m1000 350l-187 188 0-125-250 0 0 250 125 0-188 187-187-187 125 0 0-250-250 0 0 125-188-188 186-187 0 125 252 0 0-250-125 0 187-188 188 188-125 0 0 250 250 0 0-126 187 188z" transform="matrix(1 0 0 -1 0 850)"></path></svg></a><a rel="tooltip" class="modebar-btn" data-title="Box Select" data-attr="dragmode" data-val="select" data-toggle="false" data-gravity="n"><svg viewBox="0 0 1000 1000" class="icon" height="1em" width="1em"><path d="m0 850l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z m285 0l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z m-857-286l0-143 143 0 0 143-143 0z m857 0l0-143 143 0 0 143-143 0z m-857-285l0-143 143 0 0 143-143 0z m857 0l0-143 143 0 0 143-143 0z m-857-286l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z m285 0l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z" transform="matrix(1 0 0 -1 0 850)"></path></svg></a><a rel="tooltip" class="modebar-btn" data-title="Lasso Select" data-attr="dragmode" data-val="lasso" data-toggle="false" data-gravity="n"><svg viewBox="0 0 1031 1000" class="icon" height="1em" width="1em"><path d="m1018 538c-36 207-290 336-568 286-277-48-473-256-436-463 10-57 36-108 76-151-13-66 11-137 68-183 34-28 75-41 114-42l-55-70 0 0c-2-1-3-2-4-3-10-14-8-34 5-45 14-11 34-8 45 4 1 1 2 3 2 5l0 0 113 140c16 11 31 24 45 40 4 3 6 7 8 11 48-3 100 0 151 9 278 48 473 255 436 462z m-624-379c-80 14-149 48-197 96 42 42 109 47 156 9 33-26 47-66 41-105z m-187-74c-19 16-33 37-39 60 50-32 109-55 174-68-42-25-95-24-135 8z m360 75c-34-7-69-9-102-8 8 62-16 128-68 170-73 59-175 54-244-5-9 20-16 40-20 61-28 159 121 317 333 354s407-60 434-217c28-159-121-318-333-355z" transform="matrix(1 0 0 -1 0 850)"></path></svg></a></div><div class="modebar-group"><a rel="tooltip" class="modebar-btn" data-title="Zoom in" data-attr="zoom" data-val="in" data-toggle="false" data-gravity="n"><svg viewBox="0 0 875 1000" class="icon" height="1em" width="1em"><path d="m1 787l0-875 875 0 0 875-875 0z m687-500l-187 0 0-187-125 0 0 187-188 0 0 125 188 0 0 187 125 0 0-187 187 0 0-125z" transform="matrix(1 0 0 -1 0 850)"></path></svg></a><a rel="tooltip" class="modebar-btn" data-title="Zoom out" data-attr="zoom" data-val="out" data-toggle="false" data-gravity="n"><svg viewBox="0 0 875 1000" class="icon" height="1em" width="1em"><path d="m0 788l0-876 875 0 0 876-875 0z m688-500l-500 0 0 125 500 0 0-125z" transform="matrix(1 0 0 -1 0 850)"></path></svg></a><a rel="tooltip" class="modebar-btn" data-title="Autoscale" data-attr="zoom" data-val="auto" data-toggle="false" data-gravity="n"><svg viewBox="0 0 1000 1000" class="icon" height="1em" width="1em"><path d="m250 850l-187 0-63 0 0-62 0-188 63 0 0 188 187 0 0 62z m688 0l-188 0 0-62 188 0 0-188 62 0 0 188 0 62-62 0z m-875-938l0 188-63 0 0-188 0-62 63 0 187 0 0 62-187 0z m875 188l0-188-188 0 0-62 188 0 62 0 0 62 0 188-62 0z m-125 188l-1 0-93-94-156 156 156 156 92-93 2 0 0 250-250 0 0-2 93-92-156-156-156 156 94 92 0 2-250 0 0-250 0 0 93 93 157-156-157-156-93 94 0 0 0-250 250 0 0 0-94 93 156 157 156-157-93-93 0 0 250 0 0 250z" transform="matrix(1 0 0 -1 0 850)"></path></svg></a><a rel="tooltip" class="modebar-btn" data-title="Reset axes" data-attr="zoom" data-val="reset" data-toggle="false" data-gravity="n"><svg viewBox="0 0 928.6 1000" class="icon" height="1em" width="1em"><path d="m786 296v-267q0-15-11-26t-25-10h-214v214h-143v-214h-214q-15 0-25 10t-11 26v267q0 1 0 2t0 2l321 264 321-264q1-1 1-4z m124 39l-34-41q-5-5-12-6h-2q-7 0-12 3l-386 322-386-322q-7-4-13-4-7 2-12 7l-35 41q-4 5-3 13t6 12l401 334q18 15 42 15t43-15l136-114v109q0 8 5 13t13 5h107q8 0 13-5t5-13v-227l122-102q5-5 6-12t-4-13z" transform="matrix(1 0 0 -1 0 850)"></path></svg></a></div><div class="modebar-group"><a href="https://plotly.com/" target="_blank" data-title="Produced with Plotly.js (v2.12.1)" class="modebar-btn plotlyjsicon modebar-btn--logo"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 132 132" height="1em" width="1em"><defs><style>.cls-1 {fill: #3f4f75;} .cls-2 {fill: #80cfbe;} .cls-3 {fill: #fff;}</style></defs><title>plotly-logomark</title><g id="symbol"><rect class="cls-1" width="132" height="132" rx="6" ry="6"></rect><circle class="cls-2" cx="78" cy="54" r="6"></circle><circle class="cls-2" cx="102" cy="30" r="6"></circle><circle class="cls-2" cx="78" cy="30" r="6"></circle><circle class="cls-2" cx="54" cy="30" r="6"></circle><circle class="cls-2" cx="30" cy="30" r="6"></circle><circle class="cls-2" cx="30" cy="54" r="6"></circle><path class="cls-3" d="M30,72a6,6,0,0,0-6,6v24a6,6,0,0,0,12,0V78A6,6,0,0,0,30,72Z"></path><path class="cls-3" d="M78,72a6,6,0,0,0-6,6v24a6,6,0,0,0,12,0V78A6,6,0,0,0,78,72Z"></path><path class="cls-3" d="M54,48a6,6,0,0,0-6,6v48a6,6,0,0,0,12,0V54A6,6,0,0,0,54,48Z"></path><path class="cls-3" d="M102,48a6,6,0,0,0-6,6v48a6,6,0,0,0,12,0V54A6,6,0,0,0,102,48Z"></path></g></svg></a></div></div></div><svg class="main-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1200" height="600"><g class="hoverlayer"></g></svg></div></div></div>            <script type="text/javascript">                                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById("162d888a-81e0-4741-a406-98cc539adab6")) {                    Plotly.newPlot(                        "162d888a-81e0-4741-a406-98cc539adab6",                        [{"line":{"color":"green","dash":"dash"},"name":"Transformed ors","x":[4,5001,10001,15001,20001,25001,30001,35001,40001,45001],"xaxis":"x","y":[9.743,120.817,243.468,380.295,509.848,557.93,650.175,824.835,838.516,939.572],"yaxis":"y","type":"scatter"},{"line":{"color":"orange","dash":"dot"},"name":"Original ors","x":[4,5001,10001,15001,20001,25001,30001,35001,40001,45001],"xaxis":"x","y":[5.802,1213.412,3803.952,8242.507,12787.319,24241.68,31904.503,38413.777,48551.538,63053.749],"yaxis":"y","type":"scatter"},{"line":{"color":"blue","dash":"dash"},"name":"Transformed ors","x":[4,5001,10001,15001,20001,25001,30001,35001,40001,45001],"xaxis":"x2","y":[0.119,0.068,0.082,0.084,0.077,0.074,0.064,0.137,0.063,0.063],"yaxis":"y2","type":"scatter"},{"line":{"color":"red","dash":"dot"},"name":"Original ors","x":[4,5001,10001,15001,20001,25001,30001,35001,40001,45001],"xaxis":"x2","y":[0.101,0.105,0.1,0.095,0.133,0.103,0.098,0.097,0.106,0.095],"yaxis":"y2","type":"scatter"},{"line":{"color":"green","dash":"dash"},"name":"Transformed ors","showlegend":false,"x":[4,5001,10001,15001,20001,25001,30001,35001,40001,45001,50001,55001,60001,65001,70001,75001,80001,85001,90001,95001],"xaxis":"x3","y":[6.85,138.841,312.844,379.735,450.334,550.179,728.978,765.858,1026.997,1142.369,1106.673,1185.558,1252.094,1339.291,1531.349,1668.235,1931.567,1972.665,2229.912,2382.516],"yaxis":"y3","type":"scatter"},{"line":{"color":"orange","dash":"dot"},"name":"Original ors","showlegend":false,"x":[4,5001,10001,15001,20001,25001,30001,35001,40001,45001,50001,55001,60001,65001,70001,75001,80001,85001,90001,95001],"xaxis":"x3","y":[4.477,1227.246,4364.109,8650.154,13752.703,24218.739,32910.137,40518.876,49693.704,56963.847,92906.529,107903.532,119488.009,132573.986,146681.525,163717.91,184240.969,207129.314,228678.036,240654.447],"yaxis":"y3","type":"scatter"},{"line":{"color":"blue","dash":"dash"},"name":"Transformed ors","showlegend":false,"x":[4,5001,10001,15001,20001,25001,30001,35001,40001,45001,50001,55001,60001,65001,70001,75001,80001,85001,90001,95001],"xaxis":"x4","y":[0.101,0.089,0.101,0.108,0.093,0.092,0.104,0.102,0.104,0.093,0.088,0.079,0.082,0.101,0.09,0.086,0.086,0.13,0.16,0.091],"yaxis":"y4","type":"scatter"},{"line":{"color":"red","dash":"dot"},"name":"Original ors","showlegend":false,"x":[4,5001,10001,15001,20001,25001,30001,35001,40001,45001,50001,55001,60001,65001,70001,75001,80001,85001,90001,95001],"xaxis":"x4","y":[0.076,0.083,0.077,0.082,0.094,0.146,0.107,0.137,0.077,0.082,0.091,0.08,0.072,0.079,0.08,0.075,0.08,0.08,0.073,0.087],"yaxis":"y4","type":"scatter"}],                        {"annotations":[{"font":{"size":16},"showarrow":false,"text":"Exec time for ors with index_scan enabled","x":0.225,"xanchor":"center","xref":"paper","y":1.0,"yanchor":"bottom","yref":"paper"},{"font":{"size":16},"showarrow":false,"text":"Plan time for ors with index_scan enabled","x":0.775,"xanchor":"center","xref":"paper","y":1.0,"yanchor":"bottom","yref":"paper"},{"font":{"size":16},"showarrow":false,"text":"Exec time for ors with index_scan disabled","x":0.225,"xanchor":"center","xref":"paper","y":0.375,"yanchor":"bottom","yref":"paper"},{"font":{"size":16},"showarrow":false,"text":"Plan time for ors with index_scan disabled","x":0.775,"xanchor":"center","xref":"paper","y":0.375,"yanchor":"bottom","yref":"paper"}],"font":{"color":"RebeccaPurple","family":"Courier New, monospace","size":14},"height":600,"legend":{"orientation":"v"},"margin":{"b":0,"l":10,"r":0,"t":100},"template":{"data":{"barpolar":[{"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"bar":[{"error_x":{"color":"#2a3f5f"},"error_y":{"color":"#2a3f5f"},"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"carpet":[{"aaxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"baxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"type":"carpet"}],"choropleth":[{"colorbar":{"outlinewidth":0,"ticks":""},"type":"choropleth"}],"contourcarpet":[{"colorbar":{"outlinewidth":0,"ticks":""},"type":"contourcarpet"}],"contour":[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"type":"contour"}],"heatmapgl":[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"type":"heatmapgl"}],"heatmap":[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"type":"heatmap"}],"histogram2dcontour":[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"type":"histogram2dcontour"}],"histogram2d":[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"type":"histogram2d"}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"mesh3d":[{"colorbar":{"outlinewidth":0,"ticks":""},"type":"mesh3d"}],"parcoords":[{"line":{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"parcoords"}],"pie":[{"automargin":true,"type":"pie"}],"scatter3d":[{"line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"scatter3d"}],"scattercarpet":[{"marker":{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"scattercarpet"}],"scattergeo":[{"marker":{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"scattergeo"}],"scattergl":[{"marker":{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"scattergl"}],"scattermapbox":[{"marker":{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"scattermapbox"}],"scatterpolargl":[{"marker":{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"scatterpolargl"}],"scatterpolar":[{"marker":{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"scatterpolar"}],"scatter":[{"fillpattern":{"fillmode":"overlay","size":10,"solidity":0.2},"type":"scatter"}],"scatterternary":[{"marker":{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"scatterternary"}],"surface":[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"type":"surface"}],"table":[{"cells":{"fill":{"color":"#EBF0F8"},"line":{"color":"white"}},"header":{"fill":{"color":"#C8D4E3"},"line":{"color":"white"}},"type":"table"}]},"layout":{"annotationdefaults":{"arrowcolor":"#2a3f5f","arrowhead":0,"arrowwidth":1},"autotypenumbers":"strict","coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]],"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]},"colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#2a3f5f"},"geo":{"bgcolor":"white","lakecolor":"white","landcolor":"#E5ECF6","showlakes":true,"showland":true,"subunitcolor":"white"},"hoverlabel":{"align":"left"},"hovermode":"closest","mapbox":{"style":"light"},"paper_bgcolor":"white","plot_bgcolor":"#E5ECF6","polar":{"angularaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"bgcolor":"#E5ECF6","radialaxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"scene":{"xaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","gridwidth":2,"linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white"},"yaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","gridwidth":2,"linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white"},"zaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","gridwidth":2,"linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white"}},"shapedefaults":{"line":{"color":"#2a3f5f"}},"ternary":{"aaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"baxis":{"gridcolor":"white","linecolor":"white","ticks":""},"bgcolor":"#E5ECF6","caxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"title":{"x":0.05},"xaxis":{"automargin":true,"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","zerolinewidth":2},"yaxis":{"automargin":true,"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","zerolinewidth":2}}},"title":{"text":"Execution and planning times for execution of or expressions\n"},"width":1200,"xaxis":{"anchor":"y","domain":[0.0,0.45],"title":{"text":"number of or expressions"}},"yaxis":{"anchor":"x","domain":[0.625,1.0],"title":{"text":"MS"}},"xaxis2":{"anchor":"y2","domain":[0.55,1.0],"title":{"text":"number of or expressions"}},"yaxis2":{"anchor":"x2","domain":[0.625,1.0],"title":{"text":"MS"}},"xaxis3":{"anchor":"y3","domain":[0.0,0.45],"title":{"text":"number of or expressions"}},"yaxis3":{"anchor":"x3","domain":[0.0,0.375],"title":{"text":"MS"}},"xaxis4":{"anchor":"y4","domain":[0.55,1.0],"title":{"text":"number of or expressions"}},"yaxis4":{"anchor":"x4","domain":[0.0,0.375],"title":{"text":"MS"}}},                        {"responsive": true}                    ).then(function(){
                            function downloadimage(format, height, width, filename) {var p = document.getElementById('162d888a-81e0-4741-a406-98cc539adab6');Plotly.downloadImage(p, {format: format, height: height, width: width, filename: filename});};downloadimage('svg', 600, 800, 'Execution and planning times for execution of or expressions');
                        })                };                            </script>        </div><svg id="js-plotly-tester" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position: absolute; left: -10000px; top: -10000px; width: 9000px; height: 9000px; z-index: 1;"><path class="js-reference-point" d="M0,0H1V1H0Z" style="stroke-width: 0; fill: black;"></path></svg>

</body></html>
graphs.pngimage/png; name=graphs.pngDownload
�PNG


IHDR�`��
sBIT|d�tEXtSoftwaregnome-screenshot��>.iTXtCreation Time���� 27 ������ 2023 18:37:20Z��� IDATx���}\�����a��&��,U!B�XD#)�T4!FbJj4
'���I��_m�=���<b&����xMb���!5�	M�?o�X���
	���T`�5����PPT���|<|$���|��k���33�8w��9DDDDDDDDD���=���������HgP�KDDDDDDDD�%�DDDDDDDD�_P�KDDDDDDDD�%�DDDDDDDD�_P�KDDDDDDDD�%�DDDDDDDD�_P�KDDDDDDDD�%�DDDDDDDD�_P�KDDDDDDDD�%�DDDDDDDD�_P�KDDDDDDDD�%�DDDDDDDD�_P�KDDDDDDDD�%�DDDDDDDD�_P�KDDDDDDDD�%�DDDDDDDD�_����/��������K��G�;����������M�o�"cT�����#.��0��t{��z�o����j���.>�|���.����K`�,y.sO�'�H�Y�Y��:�����t%��CLf3� ��������c��87`���m�=Q�]o����^�W|��MNLa!�N�����P3��M:��3���n���EDD��8w�����7�{7��+��8O��i�X�Mu��#����A�HfBO�?��]-��x���{6���~_W�*c��<��g�����t@rE��W��,"""�+����$D2v�_���[�9����W�1��@D�!�������	����I��%���|=U��u����m{EDDD���N����%�<��~���9�}��<9���'���e�O3dA:O���x\�EE�~>~���c�
�F��q��p.��y8�y?9J(������l�{o����b���X2� ��K�:�X���p����*��B^���
O���_���wl~��sZ��/����j1�jcH���p/d�Sz������aVF��������{��%s��h?Y�{YE���3��Q��h��/��v��b�k{��g;'�\��|��'��	���h������"o�.����;  b(w�O"�3:�M���?�%��*���,l�1<�T#����+����U}�����m�.��VawX���� ��/�X��4Ik%s|��+_��&m������l����Uq��m�|`�LPi��!mt���m�����}���S~������D�GF�E��W<>�;�6{.L������Vs�������b/��t�z^z� ���f.'g�>v��S�����koy�x���/�OG�sW���O�������n�����^�������K��t�A��b�v~M���$���]$8>���+���L�������B~�l	�	�y���������?���SN}t�3����C���ofgE �w3�����^^^�����4#��IVn������W
�z	Scn^����-9UxF�dJR��d��#��>-����i7�b=�J+�2b�x��v��naT���I��A�{z7�o ����J���>���ogz����*#E�?`��
����~8�;�q��
�����7s{r�����J�|XE=�`�����w���h��N�?�Kv�H����|=vr����?��{1������q�/�������hF��x	���8���C6n���;����HF�����|�u=���C����/��)�~�������$"��}���#W.��;Rpt��c���������u`������������:
�������1=��}R�K_�|�f)�v��c�y�9e�Eq�F���@���
+��q���6������~��~	#Iy0���J���� �������~�;�Qq9UX���H2�mdS�4���q��j�s^�'�M5_�����[�T��c���}�H�%<�f"�%��yo�S��>w��*�������Q���8�y��]�z�~���KW��"""�Cwtu�����Q4g9��:��N��������|�-�����vg���%��;����]�>��w�����J0.���&��5-�5;��g6�v�^r�oenJ/�Y�$fX	���BS�H���+	���9�("/���3�9���1�X�&�|���#�.�H�����1��+��2��FjS�n�� ����~_	��q�v4�Pi�n	f��-
?��4�`�#)x�����/,���:H�n��d-�&�h&%��#{������R�M%mX���Q!�+����w �Yc:���.���U}�v�_!���i|W�` ���|�=U���u���P��2{A$�~fFg�QPh0��1�rp���d�TS������������kp'L��eqM��Mt�>.rbwA@���RN�������3if����@{b
������)
��o�c��W�y[�:^������x]��8�����7�;�����������������Hw����~�vg!��w]�/���<,���a�^��k��������L2I�~bk3#&�P������&%'�w�/���K*<�3�/��I\tOfMaJ\�t�bK'<Q������4}(&�����K�gJ�"��L3�Qf�8�����l�d�y��[$q
b��S������sb_vFLq�S����}�p���`51N��t|�]\>��[�]������<�)��4��8���`��V"���`�����?���m��@U
��������<�B#��$�C������3�K:�$���':^\Ao;^t4��r�����9�y��]�vm�����������t����H��"�����y8�G^r��:=��} ��Vz<fLcV��=,'KN�,^�����T��
��PQ��Bhd���!�0�HW�p�xc���/����(�~�7�V����K71��}�z��y�9os��4�O����w�Oue`�j�x{-�����k����D����X4�c��@]]Y>��[�]~�W��Aa���(3��X����?�����}��������`�p�V
��������n8Q�a�N
�6��&lO��Ib���t<�����m�m�����5����W��voo7��]�~v���W��"""�D�E�0�L�����n����� n����L�/�8���S����>���U�������>���pIG��|Q���{�0�H�s'��,�}��*��y��^�����00�����o���|�~���_S�{:^�]Z>���L�����1�����]|�a�1��w�O��l���$b?��e�|���#�``M��	$���kkOL!�KN������L��K���E���/��f9��g{��=����;�goj�EDD:F��k��"��#���!���������{L��'���pb�:����l
��z^�k�}�~��]��T�����v	����
�A�s��;�E��q�,nf`�3���]���8��������������2'������4&��_���$���]��� 4esS���I��r����#����wRI��A���Z�S��u�<���M��x�������YG�w����i�������[����]��E����w�B��������*dmV%�V��"��r�(�\8]������AyI�U������9��3��Ss�9�{Ug�]���;Kj������n:Q��^�#����i��S�w�y]�#p��+.�����u�����A������
��1������m�!f�Eu����AE��'B�B��?m�5c�M�3�<���.gawU����t�<u�h[�������tm���k�w=�vj����G���Q��8�w�6��u�����K��;��f����Y��u���_�xo?��VJ_���M�HN�q�l)�	5<��'Z�'�������9doq�r��@���4u-g�)c�����|�|�z��W��y���{j(��W�
+cS:>��w�0[���u,���r�<��i��B�?��U�;�e��kZtkGK(8�2V'����mX�N�By^�*w��Ooce%(�V�z�.d['���U�/oy����A~=s#ks/M��~���������t�<���Jz��U<W�������:;~o��.n?��>���_DD�#���E��������{�!LZI(@u	���P7,���k�r�K��d�|B����f*���v�b��x	+����1�F���wQ���)9�����Kff+����s�$M��WOyA	{v���Lzr��pb�wQ������G�x�UU�XW�{T\�#im%;�+?bm�
��g�{��{��3�i�}G(l���=�<��?H^E�D� �g�7��.b,=\�+���r����AX=g(����X����3�� 6e(����, |�pv
�=By�&���;VNA~�q!�v�h��#e������K�kHo��J�|���l���9[b��=?�6#�h+�(8B^���8&]�m��������]�o��oe��0��|��u}�V�(RFIN~�_8�	�PY��k�l���s{]��������B���-�w��DG�c�������0�GJ|���CzU{�����}�x�x�������:=~o�C/��u��������t�]q(a���|h�g��HB
�~��B���U�Z�f�N�s1/8���E�VD7������3�^r�.�`M9�z��a!$.J������@f0b�4�����+���2�
�����3�h���E�/����-��2�����p�v�t���<S�~���w6���m;&?_�o��E<'s��������Es?�p������G?u?O�����2����/��!���@ZZw�����d�U��aCka���]<��3���+J�}6���?$sbV`���=��]��9�Q��,���C�P��w'�N|F%���J�_+d�1'�-��O���1WL����@ja>�����t���0�n(/y_��dXI{)��}������}��A�������=�4NQ���:����o�y�Y����s��v���LTF2��Dc�����=��<u�h�W�����tm�o���]�����������K�k�EDD�7���s�z:����X2� ��X���^%��h�[���K�;? =������x'"""�Hct��u���7��Z���-�%sUR��	AC���Xp""""""�AztQD�Cfvj������0B
�>���
������+�EDDDDD��R�KD�K���Xd�E�{�l[Y��h�e��	����7�������H��]""""""""�/h�.����~A�.����~A�.����~A�.����~A�.����~A�.����~A�.����~A�.����~A�.����~A�.����~A�.����~A�.����~A�.����~A�.�6
X����������S��,��S�2/�U�H�/�������k��5�f����;5,<ed%��������}�,���c��X�Z��-,���V��e��W����oi��sQ�����9_'�%���}=Q��p�QA��D�?���q�m�[�������f�l��{C�����y��,2F]e�A!�1��F���>.
���}$�����|���p\�����7��SY}4�8sw�T��a���;�q{��<�����G��6�f_������R.�]S�bi|=
�G�z��O����r%�#H�>�H��DWW��f��a�>��8��\k���[{��E��8��#����c�.&'�93���������?�����(���*}���5�
���J���f��Hh����C��'�);���>�������G�m��r%�#H�>�H��DWW�1b|8��|����������9��i��mO�OvMO�>[�dwE	9���{_
u
�X�G��(����W�\�f�"gC)�*\`�19��1�����b�F^|����W�k��1������h�[��v6�e��Q�On����i��5���r�'�Y��8�2�m_@��i<93�B���������t� +�$0��p�	�S����(�n���'��t�������M���mMy���`�Y�h!-�N���E��n^��"����)t�����?���^&.��Ng	Ywo������9�_y���.�Fio����b;�Fl���U�����������������>���riiw>�&-;���v�s�_����<��}95��[�x>�������{s�)�}�uUa�}�z!����m=����mrs��&����(z}6|�	�A��h�'�����Y�k�g���z�n���������(M����axU�U��������Ll��k�;��W�{YE>���c&4a8iOM qX�}��a�+;����5M��LbV�������%f�n�+�s���D���I���bp�)X����U�k `�P��O"=�r�D�h�[�r,�E3�|�UDq�SX��E��klG���%�aoc�AV��'�9��}�������u������>B8������G���H�U�t(d���p����{�$���?���3�}
�Ry�\L�{�T��5.����Z��>�#��p���#���U��#�t/c���K{:������������_��7�nah�_��V����`?�o���?�q���"~P��5e��������`���d<d��CX�����E0�i'����U���.������R�~����{{u�1�gl�7��
��x���6���I7c1_�-���$���M������7��-�|;W����)<�C�9s�.>��I��i��16�|C��	'�����k	�{<���01�k��f���}��v?�0�����J���p��o8�w�_�������1�8��(��G��t2��HF�����(
�`|�_���}������}�_91j3�%��[�H���!�����g����;���'	~h3����)6�
�`i��n��������k2�O}�IwP�~�XI�3�}e6�,_}�W���K�����v �s��?�����io���/7���i�c��ng���8H��I�|�Wc�`����n�����
��;.�������K8v����w��������)��B�����[�i��?v��h
?�������/9�0���on\����@��[���3�X��E�/>!��m,�6��z��E��M�/�1s�]�~,�������
����s������;�^<�)S�p�� �j�����������M��������9?�����_�t\������V��O?�����$��n���*#�?���3�Q�.k[<���=f&-���?�&�l99/�7��:�v!�I�����1���7`��g�����Y���[yy��,�'Cg�����[����z�I1����B<����/���6�.n5�;��\�.�G0�P��0�B����k����l{���{�����TuYs�BET"����������}|��&�5/�Js���v�#�0���'��w���e ��x�����>B3��GP����G�V��Kx�����_�19
����I7}��W���<��k��?u��.�e�� ���^H"q���0R�L �S�g7^�UN������������2"es�eqr��]�� 6�_mVB#��F:���4(��+����t8|��H�[��2p��8��mt0&���T������$��#4��mrs�P�� �.o�7DhD0�~�d�qa�����G����$u|�0+�����$�7q����p����w�hQ��C1&�a^�7��uf�`��������9��B�Fh�~Yeq
�a�IJ�bl�:*����}�zlH�;�F0�����+�%���E����ZY��aV�4m���y�����<�l�#��%�#}���J����li\�H�m\tn�V�LK�� L�A��8�<TV5]�uq���p��c����8����Z�� IDAT�W����Y�J����o��uP�u�l3��t#.��x�(/v8>��Q[��L�G�O##����E��#����gb�e�6&���'�����u��!��	��X	�Y�<�X���}�[����Cw�4�_F��"������|QD^����L!=��X����'{������:-��(���XI��\}�c�ghw�x��{'�C�#i���j(���A��;����\�9Q	���|��C�����!:"��11d���>XI�E?Qw�pz<�/�l��L��>�}{�>���#���L}o�WA������p`/K&�m=�<��[S�o>�����t,E�����g�~>��&G��mqD���l	':
��q�����[|��lR&0?�k6�a���g@�����	�����j������MJ�k_QtbG����;Z�+�q-{�����pBh����O���]�8)�_�&?�6�����t��������3N�R��B�� /��0f����h�x?�>t��#q��������.���2�
;��.���gh����E����h��7`���D���k�m2*-:G�^��aq�}��e+?�%��u��I��A��`"������*g4�I6F'X	f��H����#RBm�][4���[L0��]��Z��� p9/:k4�j���~�}����3
gQ'�����N��J�����hb��%�Jx�+�&�f<��;����-�U_+�a���8i�����v�h<�����N�+���0i�P��3#c�\�zR����.hY���V�-��_�����>���TA}�6���>��\B���02���+�������^�L#�HI���|?��z�X�38V��[��8��Nn����F�f���*f2.�p�Q�<>��y�]�u�/N;�����0�0_t������,�z9��5��tI}i)`j*?3�������$�e`�M��	���_
���4���w�����bS.?NTI���P5��t/�+���|/�-���Z��e��N�#6����IO�cb��dx![?:��w�������	�~*���?�F��/;d}V����lq�5`����:�iq���*��{���?4�8��P��������o��p��:YjW�~��?"v�d����������������aO�.>�|��U�w�m�|����:�:�N������GPA�?P��+�-�F�\�*W��]|��B�D{~���1ID�����}!�V�|)�Ku�57.���	N��?RE�a������piu��;�m9�qt@�����??�_�i�A���y���A��q��<\N*v�����d=���o����X��B�������
a��p��v��� �v�0/�f�����u��H����m�^�YEY�(4����,#����
�|><�����
�;������|V�bq&�0�_;��,OM	���x�8�m�!:�������������0BH�N�/�R�/Vo�*�������������_���������a���X1������:�T��3�n�����T��_p�~�����}Z�H}�z
��G����G�v����*���e������It���rZ>�o�t��3(��a���4]���0"������yq��T�A�+�E�B��P]E�m���b!��q
�!`TV��<�9)=t"B������~������k��G��pL��9��~�a�I��e��N�%��	.�r+�&��a���:�n�?��&�fPW\���D�.�mySg�;x3����������w>�r�
����r*���3Y��H&#���cv�V�c�U�C��#de����i���������;��v*�����Bq`wXZ���bp� /O�������� >.;�%`��K:�{�����mT�QVB;��'����h��Z���G�j_����#��u���%�G�2�#�HWP��+8j(�Y����m��wp�6���VL�pf-���Y��B�09���r�[���/�U�9�n�2�g����o8)Y������r**j(�Z���ET[�����'M�f'�7���J�v�����
�����5��*���p����iu�k�1��j����M��8����"�md���������R�C���l;���T
�����?����&:u������W��b�������(#7�+���Cl	f������	�nf���P�_N�9��������W�?������1N48���e����2z�PLG����T�S�i;9��������2�/���w�1��4j,��i���|
*���;;�����E��U;8�� ��\�5�����$>���s��(��X
'����^
k���t	����tw%N8�����W�9q�����
�!-����y����~����{������Tz���"~7��5������=� �ic�&3������4���]�����x���9q���]s4��~X�|����
��fo'��/&����,���|��#��>���#�\���bW8V����.�>f�^����d��F<��o�I��#��Z���q�$,�d�I%{�^�y���z�����}v�/4��9�Xd��{oo��.
"jj2?������������.~�LAf����������[X��EG�`)�+enR�W:��4v����X���������v�^�����w�����w@������\{�:�$.�B����,|��5��7M��'~�]��"�����J���8L	6F��8|~�v����N���O��<B����Ov���������Ng���:,m�����-�;�_3M���~bf�O�[�!q�:�d��
o�a��!MW#
ls�I+�!{�AF��;���*s8������k3�s�9�JT�]<1��7�I��_���k��z������?7������b���*���'n0�F���x
I�[X����xX��z��kf&������>�>�5�!��/|��A�����V�����r�.v�5��g�"��1}+��p�.^��8~�m�xvNP��oo�i����1����>bi��Io�b�h����dRE�3��>(������<����m�z���!�� &�z�:�G8O}��G�n
8w����BDDDDDDDD�Z��.��p`/�~U��W��g��=���k�EDD��QAD����.�4����������Jt��������H��D����������Jt��������H���.�PY}�K�6��[�s�����D*�����\*����1�����4x�q���.]���K�F�Ryv�e�Ry^�|��%"""������4�w<1~-g~B�Ng�u��������s����_���|��4������JJt���H��>��W��$t�4~���|v,�#���e8�~X����S�p�y�>,���k�YDDDDz�]"""�Ky(��%���c�T+�,�����(;�����2������TO�3I$Z�0oM	��k %s(�N�_DDDD�����^�Ay��!�Z[$�,D�4�s��+��-����s�<�����.g��>}
�a{����EDDD����.��<�����b���	��b�>��~P���#uW��}h?�G���P��D,""""=Lwt���H�w����W���<vrW�����|���,��6+�5���,;�����,;��SD.�D�����N��AP^���������K?qB���NZ���
#'��1�����__�|�����^�
�WYv"�g�QYv.��J��\�D�����R����;X�s��i<.E���l�h�xu�6����z����Uq���ln^��^�j'�?`JD�l�����t=%�DDD��M�W���m8��+0G���A���fD8?��A�?�������"����h,-�����g����8Z|�vy���7>����v>&� RW��;\�w��4���7&��)"�k�~d����1�o}�,�>�aT���KD�+Jt���tP��K�������7c��_����=U�b5�'�xx3�#��C@D8)������\�����}DAu�iK~��X�:s����an��!fL4x:msDDz��[�������@>�������o���D�<����7������/#���3{�pN���K����z:�)�%""�A7�x��iU9h���O@��X�&�pj�Uf!#����dz���;�^��49�W&{��H���K�F���}�A�4e���8��F�f����-������n�?UD��rL��<{o0�`����H3%�DDD:h���2��x���>�����t�����N��d!��[ng���������X6�x�o��U[�0U<6��#�7%��������������O��S�����Q����j����E�|n��[M;�;����HDD�c"o=\z�4|���F��_��%�����n�:�{��n1c�4��&__�6����YB��{���F�'[x��U�9!z��,�������A��8��b'n��S���8����Tdm�����V����T����$~�h���@�����+�)>����x2E��a����n�\��*k0�_�(�'4?����T�=�B���Ib��/�����K��X:�E���s��wXOoJb���U�2����j�L����|��I��w�p�����_y�����-"��#�_(��r��+���	!!$eZ��/���Y�������(Z<��A��'W,O/��D���w�����������r��I$
k�3N����R**=��
e�O�I������t���_��p�����n]�s���t�c���g��/�O{���3N��_�\�;��+��k����G���|��K�Y����q��j9�D�`'��l�hp$?z;���S��SE�s{9��T~�z8�UE����
Qa,���C����#�N������X!/=R������x����bLOLcUZ��Jr~��
e���pg4�����y��E�`��h�c8�ng���������/��g�����4�3dx��v�A��i��3�r�x��>��(�>K^����P�����-���eT��b�.b�������VL�e�_��,s:�>f<��g�3�E��cv�^��
����-oO
�?�c�-�E�D�����#~�s3KV�`m�>�Jyz��$��r��_���VO�k[X��Qk���C�xe�I��L�G	~�7�_K�0�K'��&""�S`��p���%�o�qb�)|k�0��7�r����QDD�k~~���9��@��e���t��\g�g����+��x>AU����L�%���.�j9��0�����g��4>�H��`�2����l���nel\����o�p��j��j������V8!��.j�i��R��0�_��Eq��|�
L�n�tq8�����HOh\�59���/���*f�	�4���W���"=�)�A-�c&bLfs0�
���T�_s�Z pk1�a1,�am������P�����9Vl|���z�~r#,VRg��Y����]\DAI0)��	57-��[�6���S1�n�>iOy�SIt����I"�f�_�B���x�s������;�5�����IL����O��>��mw�*r��=Qw��3�h$����Z������V�����?��+xb�'""�I�n;���d��$���4
D���������W��������l��@���V�X��<�P��s����M	��y��w��o�Q^�X�j<poC��LV����L�\M��I�y��,|�CQC=����o%vX{�����W0���o63������8	kL�`�0�rO���a����_�������^�&�m�=�;`s:�u�a
kwXV���rW:��"4���� ��a����}�}r��yA�HtUWQ�?��p�gUF�*=�E��$�D���C���� "F��9j����U���ey����Jr������
S���P3���GD�K
����g�����0�'R���
P�����@m-���1���;�v�x�o�������L�M����%���=���>w�\�������]�)����$��O�3�0�a�3�c�WK�%z���`���9����
�}��N��!�Z&�����'��51W�}���y<�/;�7�K����>����-W���z;;>�����*w��e�[���SOm
�-f���0/�-�����u.��VOiV�+"���1����%���9�\�������t������x
�/���������9������0a�
<��DL�Yn����|G��SF�]~}��y#�
~<��<��$���I�+q���_)��K���D��w/��L�C��G�����a_
?,�(q9�����-�JNN���Lg��������JW��'u��L3h���bw�i��(S�k}
'*[L������]^Wqm�yA������1��	�����T�g����8�����&��
X��j7��_��$�f#.�'lP'�&y�������s�<;���s�Xy�_���F�����LM<z���t�>���i��s�`���H�����	�������{v�HL����=:���o������s����aJ�R����h�Q�]I�/v���vWO!m�/8;�"���I�+�%����<_H�����a���m�,������U�D���������p������-������a��!�o�6{?E���9������&1�[���_M�����~�3������N(��F��������V��q�t��AP^����������~��`3�-�v�� 1�����LZ������+��Z5��u�z�a��U��H��yT�����s�����G>2�W��58���AD���\:��Y�]����c'�W��^�s�yL���<�����\���7\��"}OB<����9o�cp�%3�)?V=��e�}Y�L���1rs�o��g�!��??l)q������9�N�Z��w�[O�La!$���G]���6(���N���������X��<��?i������I�s�r�AL�pR�~�Kh�]]A��t��{y��|���!����#�?TT'�g��������=����O���������_�e��$���6���g�c��G6����������� �T�~���/x�'����<��<�ya�z%��%:�����,;WO�g�����9������}�mt>����n
�s��i��������_;��T|w���02�S;��PD�Co���,|����x�����/�����X�z�{�ico-����	D.�\a�<`�8+���*+���j����D��$p�~�s��U;(Z���!��t�����������O�z����42����������'��5I.���y���5�X[��HW�Y���K�c����}b�������F�+�.�6�������ndq�g�1�0�����2��K�R��G,N���O�H�����<��	�J�'o�~*\m�#""�K�2��/09�����VF$"�s�������W������SU����C�.���Z?��lj�K�9jku7���}���n�G�����T��Ge����<-��a)Y@M�op}�K��Qzt�g����G�p�X[���@�������������������X7�R0��t?n��cwa����v@�|d�Yo,���GE.������t�o����7��}U�*��49x��N��8��=�R�|��6>�x��\@�Nr��\N�ytQDD�3�p��t7�5���Q�\�$��\�n������1>x�yn��#7g�����+��t�������tG���\w,%��[�s�#��������
��!���
�c���AO<���:n�zE�2�w�)�%"��������?��k��}���FD���9�x����l����j^y
��~�J��%""�
��%""�������[�f�}zTQD����?�7i�q.0���}�v5��
��M���DDD�O�.�����9�6���=��H��	��#�-9g���������E����� IDAT�,%���p&A��a��[O�#"��X^^���e�����F����I�+����DD�^��������U� o��,\V��a�W�n�^m�7�{����]""�o
t�r����z���T������&������n�6����C1��tPP�� �
�
���C����~V>��Y
l
(L��I6,`��8T�a�-����8[HIi�����6m�������x� ����+w�$���}�����8�Z���Aq�P���6���n5��t�L��������%��>^����*��J�h�T'���%ys.]
�~w3n�`����y����Hx�oZ�@��hm,�;�-�&�c�x����I��jE]B!��R��+�6\�%�����$���'��s��KE��sti�\�{������
+�c4!�.Q;�R��%h����U�,����z��<�i.��Hc�/T�b�2�m4C�������{c��!j��)ho;��H�K!D�ry���r����j������K!n�97�j��$W��K�ES����Y��<]����#E���:����=�W�?��$A��w>�+����X����X�8=>���
&j�\�X6�0����}�.�l����	O3{��3W��z�w��}��f0���$���?�b��<
uF�=7���������4��Iyj�_{�n?��	����g�Z
A�S�H����e j���
����lL�%�	�.����������T9�/��j�	2N��H���2�+���{$�9	%�$��_Oc�!'.,�[�C��sf�>�|t��\m{��F3uB{�~��?�G�B�f���%�=6	��TB�':!�h\�Sj���:���$�����3��Sj_"2*����D��GP}�&#�
W�������~dvE��Z�n���r9�4��>c���NDvW�>~���>���\d.����<��d�Ld��	�n/Nf��i,|9��d���4Vm��K��d���?����*P�wF\�4���i#�������O����o�L��s�,�V�y/+S��]1�����B���Ws����U��	�����Q�,�|���%��],[U���-�3�O_9B��h��Lf��X����}�%��s1�wSX~�g,�]
�����~���$�%����h��a=p���G#���>-���~�<o.�6���
�:��!';��:�?0�Q����9�lQJ�����>V�v��0��q���87����0Wi�����^�@1`n��s��O^�M7�S�0,�rc(�)����{UN�]�!}�����~3zb�nJQ��
o�vp��%�F���d_���4�����.:��k���G����P[y���tX$�&�����K$�������
�����g���6:�0Y�����BJ0�0��0����)?$�����'��(��IS
�|S]��P�6F�*
!D
L	s�f����+~�_��8�|�%'��D�s�2�����g�����k���RvlS���01��%'�QR��y/��y{�M�d�xw������V��eP���k�G�����"�e�`���Y�q��c�t��8�r����qr�P�(P-�������kO:T:�.��oo1E�`��!��O���E\���||5)"������]���/N�D�B�&K%�6_L���\��'j��B�[3�MB���j��-�Pj6c_�.��F�=�����U>]�W�RLfO�n;*Ne�<-;�IEW��F��v���:r6U�n�XR�qn�b�������ot�wL=
U5Z����~W��r�9�h��"���8"�����?�B}�����C��dub��3���M=�������LX1�bzc#"�PB!�$��T��B�vryK��B�&�z�X�s����(:�o��J���-��<�5jt�WN��<�e�P��D��J�[�"������P}��vti���$�H��}��9}Z���r����s8�r�����<�/�1��p�+���&��Y;?'�,]�����J���8�cX�*���]�`����gcxa��g�e�n?���#yuB�$����6���#�+���J!j��l�97���\�UnL�dg��>��;��{
X�\���oW�F��R�1�<���{_���:���qi�^6�����lv�y�������j�nU�]�R�*���?���h�{�I�������$�����.���
�P�sm������p��"y�UJ�j�G:�Ny��q��2�=��&y}.�}.��MW����c-��[����$3��_��\��,7��`2uQ!D��f�)q�6��Tk��!���w*S�X��r.�h�tb�/c7�6>X�;�[S�b~�if�z��[v��������<��t����B��� �a���"$ea/��;�r=�������&�wY=���{E��x�Qq*D�����s
�f<�4u/����t)X�����Y���C��������o�����x^z��i�������>`cX�=��A�8]�"g�^�rFj;�6��������� D����W����������G`qm%�����!�K��M�z����,~��W��������z3ma1�mg��"0�z"��'k�m����?���I�pam�z��z�q~P
�x<u����]�/���#�Cd?-EDx�K?���?r,�'����U��;��v�6_L��7��l����]X�J�Z��}<��3��3a����Y^V�#��[��n�����$���tD%~'����;���OMhO��S�}� �c��JT���������%�����3�Vcgy���n�x�Z�������|��`�%��@?7�[��yZ�xR�K����x6&��#��������O��H�hl�d��B�FG�.�r(�vi�B�=]i{t���O��
F����:���L�F�M����y�����gY9z�TD������//�9NJ���3�b�0`�������N%�9�f�cX����j�f����c���h

�OqkAM����(D������kY��7*y;�9�o�OIr5v2uQ!D��*���iU��E\�����E�J4<'��T:��TZA�H�{$��5N`T�2c�4��B�VUs�}�}_�-����mo�!�����#]zB�|)/�I������m��*���o_0x�����s�5_Q��L�����60+�e�"���$��B4:Z��j�����#�����h����Y���,��6z������j�����{������mh�6���)!�3���?���|�1�����Z���
��Tt@����m�����9�����j&���_r<E�Q�N��	��C��$��B4::{�M�=�|�m�Z��S��^�Q�����o�����W���z����������[J��E����B��T�q8�����S�p>n$��;Zl��<7�K�gI�	QAzt	!�ht���n����EQ���E�9\v��h��C\/���.hc����*9k���B;�����k����������������_��I��IH����Qj6���6#����B��M]B!J�v`<��9s�o��>���=E�X��1�+��A���e1b���Rzn����d/�C��}�T
r�\�p;���\\��E�#��A�Z6���u�_M
�{�hL���q4�F����~]%VY}Q!D����B!F)��{�q{O����Q�5S�5s���\��<���eZB��s|�3��1%������^v�����aU���������f���T���Uo�-�7@���+hu��GY�G;Q������r��F�(��\m�{\e�'U�1v���&�C���c2S��/��t8���r���;m��:�_�]wy���O�!DC�D�B��QC;S��/��/�T+'?�*m���JPIZ��9���������nW���}l+i���%|�,�!�,~�7���r����9k�g����d��z���Tc��b"#�9�����nx���z��hI�Q}�f�!��@��S9��OK�(:&���;��):vlSX�N1V�$���C�����{��ndX� P&��4��/9��#�����tL�s)��1�NS���[%��xVhB�"��Z�����z��#"<����?�g���Z��^���������4.H�� ���6c�_�n���s��e����e��*I����w���;!���� =��B4���[��������*k�o�Tq	���_y���N��!	Mq��i����>-5����;�[�k\��6#=��4o�S���r"���~���U\��i�7���i��]��A�2=��Z�x*m�u9�������@r{d��B�Q�&��`����5[���^����>x`H)�k���ab�L����7���R�6��N
���''�q�Q�9}���Va�6�Nwy�U����6wY=�''�i����BT���
�_v�D��7/m��[cZ��r&f�����mUC�,|�RI�K!D�0�_������m�K����\
tXB4j�K8�_�������E���>-�R��k���
�%�:���������F���X��E]���H���1$�T��Mg���X�����S� ;��xb�
����$��B�]X��0�_
��|����H��ab��+	������U�D�����{�_h3�����Jv��oJ���i
A�e��U�.e�r���(��0{6���������?C�N~�h�b,��V��b5b���r�b���X�C���X�%�D&<���:�U���ja:']�
F����9=�X6N��
�u.�i].��gy���C\4������s���|��$'O��`�:�S_�����`��42�r�+c�e%
��|�+x�5�e������h�[��L4�c-h���������%�t1�����)�n�LO8G��%dl�c�������n��b�S�}]�(���E��F�����]+�Y~6_I#����'z������l��<��#N
�c��'�$2����-�gH�K!��9�'�����{�����v�������D���:����t@mF:��F�1�����M*A��mO����W5W��Odh$A/|~�s8p�{���l�>����������K������E_LqhY�D�%���\�+l��f�r�^���`�xo�Up0������Gyic�>�[S��4�+�5�O^9�v�����_ ��w���N�o������;m/s_U��yQz@����t����o��p"/��HMc��;�h�H�}��t�j����\�9cO�5P��[��@��<�m~D�o����id&����o���,9�,X�3Y9;��Q$����p���w��0�y�Z�cKS�����;��<v�v;9��>�=�������>k4/n��������,�@������1��x�����B������\:�����@
�LnL�$���
���C�p`�7���P����.Jva/�,��4+�UV�����Ze�yq8��o�/,���I�������sG�6*9W-����t�0���S�3��x���a���z7����������+��Ch�X�c-�R�����b�*��������\5)�(h�e�E�N�%�����������(Xb;������!��Bs�0<1�q�-��
X�_��~_��6�K���0��j/��>�����o�h#��������9*���xZ=���nF�h!v���K��Nf�v�
�gD��P6�swc8r�c�k����x��Tt	!��#��A�<��j*��=�����i�|	��-A�:���
����$m����8�&:�f#';��&O����b���~��E�2���w�
TG�Y��Y�s����
�K�\Kk1TL�S��*P\\���F��t��N�x�N�b������R�yv\<���TIZ�[��\�E�`���r�_�z�J�Ctx���l'��3����3��.�KD��#���W���N�0:FT�����]��m��cr���B�It�X;~y3������;�B4-Jaj�wZ����0�_��>���	!�h8Jv��8_��hn�j��7{:�f���jH$���g�����m*_[&<���U]?�AN],�5�����t��r
��1�1>-*�|���it�3��'r�H��x�	V�:F�o�����u�r2��t�vP4o,���-V��9>U�}{����~��c����kKUr�m`��
$����bJ*o���Y�V2{�v����B4K�+��EX�t�6W�)���C�\B ��3WV��97��4s/O���������?�	�
�^���?�!�!U��*�K����NKD����u�[q�T����o�@���#^���c���]&�D�N��j����K�����_�2K�08����J�.
|�i��"�*]�}�*�u8Z�K���*m�����j�W
��xVhz��s�����T���>~�%o^���1��2�~�v�3' Q
!D��q;?<
��T�_�f:$!�e��=�l����2��DIv���$��=E2�P�}����PZ
n7l����D��@h����TP�9��������I���8v)_�%��NN�+�l5�����������1R�p*y������G�!;T��H�������)P�}9���x���	6�})��x���*��$o�P��U���=��{Y&]�=����WL$��k����
Ml���=�21��/,9[i���M��5�!�Gz��4M����H��G���,���%y�6��s/�l�u	�B�P���K�fJ�f=�Q\���T+�b	!D��l���G�:��6c!��b\�����Mj��F���nb@?�����$�����'c��=���%�M�_��<�=�6c/k^^CJ�
z=��}�6#���C�C�b�^�����y��hO�k�2������{0�mk����"�F#���_�����/"��4�<���j#vfol_��3���{k�7�`T*n�@���yaN���Z�p<�y<u�mX;v���f�+?Ad�D�u��2��=��&UL\=�h-�����"1T�����	�|\����c������Dxh������c�Gr<���K����N��0b2������OhB��X?16_%����������_-�u��6���s��1���>��� �R��k3f5�~�[Kyn69���G�Mi���,��b�����S�p��`4�N����YuD%��
�[zX��e;Y����_�Hr	!�����JX����h��-��yZ���!INQ�q��w�bs������\B!F������0G�`����U[��S����m*��R�sj�/L��\�����m�9��%����������{9|$���z�]���.��I�zP�6�"l�G�r�����)[�L�8����~_*��)��^��l�gBO!��5�D����l<n�����P��� ��B����3�]��@�.2��*����e�[��JE�L]lZ�T���x�Oc?��o�N�����~�R}
;L@�����G-�������?{��}i���!�	t"&��p`����%�%|J�f�s�M��	I�B���(5���I�Y�C
!���&1u1�����:�;#?`���=� g���|������z����[i�����Et�e���L��s#��JQ�����!���o�E���	�MF�8B����I��$����P�]�U�&'24Hk�D=�8���\�{��!C�8��:Q�&h�~�y�BL�x����8~�k�'z�-�O7]���i���B��=0�?���<
��d������v��a6�_����$-��
!Z}��j��y�������+�h�&�Ur�_�$��E=R�����#a/Lt(
�J�\ON� 1p���)p�=E�!!�I$�00�����m#�E��2+���meN�Vn�3�w����!
CW���G�)n��!�������^��!�PY�]�����%|�N���-�y�\����p�+5��/yW�-���
;�6�4*�����.!D�4���{�������~5� IDAT�`������F� ~��JtD�����Q!���[q���X%�{�]��z%�":4!DXmF>��c����
��(	tH"@4v;�&S��nR��0.|�;�J����`>^�0�uw�^'�.�M����j�R��6	��������|��9x���o(�h$�.��P�sK���#m�M�pa�o���2
;L�r��)�8��C!��F�+�m��S
�����o�j��Mmf���$����Z�{O��<X�8�D{�_U]��-!�����ml�����i;�	��G�tI�K!��0��T����3��[�b������~@���7h�1_q�����F����]��G���|����5�����gO������J������7��l��/E��
p4�Ky�]V����*��X}�B��z�6�gG9���K�4�W�B��)�Y�=6	�35�3�1��z������M�n������{�$DS�soQ����!��q(Yg}�B���+�?����
O�q87�k3f�zrr��	(wT_��,���������}������������Pr�_!:�[���%�h���K!�����|�TD5�3J�9J�M������;!��S�=����*�yS�i�Z-_�6#�V~'��4
��)���:�FgGY�Ty5U Ymz�.��������������W3D�?,�<o.����qg�^��I���?';�y����'a�T��d�x����c���^�����r��<�G�>��,�t~�J!�
��s���;%�����!?����.�ong1n�����h���}�>-������^G�[���>-�kg���'!�n�������f4�����e���Y�'�
A���!���*��9�`��qA"��/A�pp��EJ�f�s~���ch���������}�
]��7���Qs�:9�t/��s��R����qss��O��0| �=����L[�S�1�����d�4�%�U�>J&1�����$�������O\�x��H9'xgz��W�v�d��b�^��
!D��u�Sl�Uf�8|}�4n��z��wN%'� �^�2�YZW.)/�$e�������LO��c`W�~fX��n�>���� qE�1������9M�����]7
����f���(��|����I��Gx��Ri�l	����(m����<�"�^�S��-)�d��*����D����f4��}Pr�(5�������7�������n�t��������q8�$�4��&��		�?(
������U�,����z��<�i.��Hc�/T�b�2�m4C��s'�(X���z'C�@�S��g�Z�!��rf�6V}��m��������d����/���l[t�5�A��dQW!��3�+��eLG)��Z��8"���;�'��� S���m����F!�E%s�.��(D=�[��mJce����p�m����K�mF:����%Lti�cX��|<����R��{)5�	>w�V+���s���k?�	xO"�?:]Z*x<�J��A�������8z(��	
v�#W��@���\�{�R��������SwTZ��?�E��kX���g�#�����q8����D�s~�{��W1~7����P4�a�$��&��$m�2u��6	���\�>�k�gI��!M��*Mq?p�vX����ve�{��O����kB�������D�����F����o���-�� 2�if�����Y������cv���5��VN&�N��qk��Q�3����t�l��O��IF�N�SH��{u��Q,N�U���k94h�O#�+����#�66��>��1%�<'�t"�Fw�K�]_c��d�*����2efW,���H*sJ�IRN����CN\X����u(���}���,9�*���M�f����2t�D�����.�����g����g8t��2��A����8�5�n�eB�:��(��|�YA%��,J�M��T$�$�%���n�@p����=0g���E�Yy�)#����W���,���c�#7�dg���Mh�{���,��>�� �6�.?i,���;�/%}�V9���I���E\�6%;��D��A�����\I�P�S��%�}Z*�U_�K�����K)���x�P9�����\t�Tr�D�����c
�����znF	f��Q����k�0��@H��k��<�+����>�Nq]�H���"�����oa�0����a��[o����I�r�+<X�qn�?��q�w��b[x'"�����%k}��8�t/��z��G�X���V$���8�%�T)����||�n\���j�.�B\�"�-����*���I�0�����{-�j�E%����������i+��s��X��`�^V�3a��E�p���,z�0�����[�|������e���hs2Y��],3�c�3ey[g&��b�0$���Zh�R	�(��/Y����?Ma�=:\_���Wi���C���)N?����E^����*����/p���x��zZ�w"m������,��s	������[��v�8B�"�W��c��/��\_]���B��� ��:��*�*2}�������tJ���N
�V�Z����]�����Q}�4�.�����d��=)���-�S��(:�K�/z+�*��M7k�l	�C���y�M�9��W�L�q
]��Kg.�|�(������/���{G��������^�;���Go������/}	���)��l�?�����%�R?�V��PXi\}Z�$��BU����{���7��rU?��U�qn&��K1`����s��7�U����\�0oi��J���iT@�(���\�r2�y��^:@G�=���K�{�x����I;�o�`���aa&��_w0�}�7�+��@G�X+��.�m�n~j
���)N�E�����K$��E����L�x�M�3vN[G����6�����9�{?��evJ�m�Rc�.��B�/r�������J�SJ��7B���WR)j��`��vFwe/@Y�-�Z���$�DCr�`�W�|��y]���]�++�q�W���)o�c�~;�����xjvo�u���d�v�d�d���
R����2���p�0h��N���*�Q��P����n����&��t.z>���\�{��/q����	����r�_j6������s��K������������[�TGS������I�U���2O�V7�i���'(�������,	�j���(�Y����l�%����	}}Z*��F��:����������f�uk8r�{YQj�~�]`�BNN�q����������
T���`���t�Z+���b�e�Hb-�:*d�is;C�:]y���z� iG�\+�"
Tn?�X���`�I�J��b5�E;y��-�(�9�S�I�~��������&e@Q�]4�+�F�����.�
�E�sW.����uf��3'��U|���DA����B�4(���>�G(����V\��\�����1�_�R��7C��)������W�%�2`	sq���A��������$z
N�Qf��M2s�������^�����\>}m��62�e[��F�*�������������+�y~�=������/P.����~T���K����k�P>9�������#���;��oacU~rY]"��dB����T�Lk�l	!������U�i�|I�O����h���{�����������Q��<W�O����VNl�Z���L���-������,<�0_���w�x�v�,<���%�VJv�}����
E�����m_��{�^�n��~����s3f5G��R�E�U0�4Ty����7��������c���|.�Y��#28}��S.����nH�1��IVPg!vi<��>���sO��[9��cV�]�oS
]a�?�B�����PZ��rQ�U4N+v��� k?��q��fJ��yh{�Gh�'Br����:MF)�B)�B
��V����-p���C
�|{���a�x��sa��o�����t>�K.���5�����w�D��~DZ�2a��}�$�~a��ZTu]|��$���q}���I������4v{�$W������%����L�D�[������;X5E��m
]��ynFI��]_�������f��Z+�)[���}Z*������~�������2$}��� �,���OF��?
���s��3���������p�O!���xBC�I�j\>��.-������2'��]�t������H�2�W�]H�Z-_�>-��|����T,��!�X�
+��&��:��F���`�x��Ko"�������jL'��z��&��s����I���1��+��K���yd_�c�K-��W*���&��Y;?'�,]�p(�K*��_y9N�h�R�UC���L��v��a��c�������F�PQ�S-�by�#|�3W�����`�/��Y���g)0�?�z.!D��s�%�*�f+�N���y��}��h<������H��N��H�/GwO����,� �a6�>[�
��>��%�����M��jGD�1�����j��3Y���r����g���������:��?��x��V���]���\���]��7��1.HD��@~�vPU�f���{������;�%��o���@���[�R�NiX����u���V�J�q8p�M@{��pB�1W���������G�pe��z����8���R)5��Ttsn,�s�{�iL���q8(������Fg���@�~�Wgc��0���Fk4�6��p2<�Y�k�Z�[��i*Q�E*�`��@�������$���aV���$[�b&�Z6*n�p���]5RX,�2�����"y�U
��T�V+��z�.��*f}y�5��A�e�I^���OY���$y�U�?��u���5[I���������Kv��%��}"D��.0�mR/L��W6&������}�B��T��M�;|\B4J���.�'���-�:�b���[��������Y�e��dvZ��m#&}{-	P�Zi������d�������cT��]V9�AlOQ���k���:��:����z�cxLfo2+�^Z�����^`_�It)�Y���������r�]�J��j��j
��m9��x�����R��F,_���Z���/�f�wU��D����������
�_wc�y�M]�>�V��!8����5z
�f<�4u/����t)X�����Y�<��T�����X�o�x�<��b</=e�4�A���b�S�1�
������y�.����l��_���vfm#���3��/�D����W����������G`qm%�����!�K��M�z����,��r=���yal-�p��L[X��E�����F�����I��o[�2�!���%i�8\@X��x���}b�!y<���J��_��_"�Cd?-EDx�K?��YwZg:����-��+�6�>5���\�=����@t��<7+�!X	���-�k�V������H2������b���#��M|��C�6^��d~�AB�f�%�������?�9��z����$���Z��?���0n|�I���$��,Xp�����W��N���>��=������O�����X�;���K��|�<��\�1:w�;=��{+�������M��g��p������O�F�n�>����{�x�&_}�e>��*5����7�i^��z9��n]��f�jB*�oRY_���O6�%������#hJ
.<���K��������o��2P�	Q;M��^f@kw�P��]8�X�	
��X��U����=
'��Ms�M'��:�o�� f�!9��h�%�[h�������]zR�������JM�*�AC�m���+��?�'l�n�^}�%�[���^�e�]3
���e}�l�������j������V�<��n5��-A��EI[�O��_��N�-B����,�VWZB�y�L��>������a+$'�X�A���������z�����v��	��>��;��Lwll��*����x�	L	c�����t��[��}��a�b1�\�� �W7{L�0���B4S��VYK(n;��g��}������,������u�3��y.-����Z��h����H\��>Q������d,�����|;yNK�F�r!��"�6N�LfO<���:���y-�������MB�/C���m���M��ah��,���*�OK��������}��
�w�7��Su}���W���c���V��h\�:��V���?��������_����\���������N����L�o�i���-�<o.���U���i���K8�_S���}�{��`X��J���IL��Y{3af.���0DX����t`�&�Nt)=x���;A��S�9a!jtO{7Q]�\L!��7��$�2���^�P�Z�Y7\W
�AxO�[�7��ij����z0<�(k���=�(��'K�b�(Q���zr�'����>���v������Z��b�S�]�F�����>^�xOz[h���x)���C��\���1��	��Ub�n��U���l�<o.E�1y���8��,�	��U�����q8�$�*3'�A����3�MB���T-��T����w__��@��G�_�8�o��am�+WP�u�&�x�K���''W{�o�j���w)_��4�~��f3�%�R����b�S?��Ix5k
�	#�7!�q�������������]��}�}��������G�� �W��(�u�u����M�p��
#&2,!�E�~�7p�#�����?>L�b�[�C��Q�����[��0���\^~02��x�������;��������c}*5�!��Z|�PC�f��Jv�o�>-�;=+;	�j��]��9E�P<d��b�<>�R��+��K�����%;��70�M������h*��aX���t-��{.�3��=?y;E�1�d�4c��Ulo-8�8�nH����(|r�/AS�H�~}�����������Ft"7���7��{�_��<��7�u M��^�*'��i�hZ-[��u�+I��:�Xu�����W8�s�8���*��*4��BQ7�S���^�����j���}���j��|�f�����E��D�j�Z�+O�����&�cyu�K�)i"�c��(	tMZ�wG�B\�S��K�����J�kWcX���D�/��oe�����v[���I�$��&I�fH�u���3�Mt}��9��������LQ����Z�\p���Yj�.�=Ea�M��=��K��,�V��"1V)�V-��J���>OG���X��mM���?����	s|�@Y���R�%D#Ps������2���$����v�����7��F���B�	��$4nnc�J���~X�$�h���^����V���j���n_*%����9�l��;�/�%��p�jy<�r8(5�j�q$�.���(x�uZ��{4W����p=�,�^�r��M����q M�|������s9�X�KpU�H�8���T$�n��*����%	�@t)F���� r��;������7Tr��:� ��k�gqm�,_�+�z!h<�&�@�f��UW�m�����l���}z�7���h�t]E��jh|�]������[0�N������}&�Q�F��}��h���^�Z�Y/�r��tJM�a�~AA���V�*���i�n�JJ(�q������H4=���"���"���	���;o�6o�my���n�h�)�fH����?�q����n�7]��m
�4XmM�\���,��l���h���M����L	s�>@���������y<�����S,��c�YVg���kS��&�/��"�g�-v��z�����t"�S���]�&�\����e}��Y�]X�������������e��z��|F��@�n��R���a�X��������x�J$O��\:��'$��b�y���)
��������{�����7��a�����Ft��_�7��M���9���0Us5��fy?W��;���������r��u�����!D��.v��5?d\m���K��+�h:B.oEq��������>?W���:��jZB4j�^/��TNr|�� �}�h
�j.��}7�.���h��S<pP��)��iF�����N9���7~G��o��j�����t��(���hr��O IDAT������ *!Z�zt)��X05L,B�w����R�]M���J�f������#��	��{����>_��$�|�S�D�q��C�����ra}$�Z���=k4
�-���	!��0���Mj��PCm8z.pdB!Z���7l+m����� �=7���{�����.���F��a{�C?@4B�<��B4�+��E���ry�o��>�����.�(����B����u
�&��������k?����x�!��@���/\�b�B�����w(�A,}��F
�������-���
!��������������_I�4��r=��]
��m�-K�#�_���V>;�����ij��c������>����-�$������(���Fw� E�?�Z����	Ja����[��K���%3�=<�����6���s��I!��A��E!D�g�j�/����m����$�WR������B�5)���e�L!�B���B4jA%Nt��7l�i��y&�1����BT���Rz�.�������B4.9�A|�N^���'�.!D��)������V8"J�-!����fx��6��nB����St�j���)��B��$����>��j�Ydyf!�����R�&�4����}B��c��R��k����UE��(�Y���NS�f�Nq��x4!x��\o�8�HY�Y!jb2{����2������Va�T]�J
����6��&]B��O<B�F�x*��D��[��v�����G%�M���KX�\>�	���?��=.�*���f���L"�`��Z���$^6/��Z���m��������F����_����en-nY�niFm����R(�y�)������1\tp������|���3���s�����/�T�3M�vU<&��{����S��.oWI�It�K�Q�Xw�^��y���lG�I.�%���B��!"�E���������!.Ay�O����	�^��gMHr���%����sy�T!���5�����A}H^4����;(gf����"M���z4���zo�Z�
�"��W�������%z�:B�i�H	!:����$���;�������U�+[����]!Dg�AFt���0������t���H���5O�a����?�U�N6{"�������Yd��Zq!�E���������U�	����%�%�BQeg�{����l4����u����1]�g)�Gr��x��2I��H4K0�}p���Lo$ �@�������bn�Lk	|��e��_�cB�i��r��r�q����]!�B�vi�'�S����;��@��d����:�����L�w�Me�!��,Q�q�M�����p��#�'0Z��4����� ��+pB���w���N��%�	������!�B�;�T���pm���NA��B'�B��w�kB����8N��v�Y���!J
(6�JAo������'�$�Mgl���B�D��ciY�3���iq���p�E����+����6m��_����M+A!C�W�@`����H��,iO7��9Or�B4n�:��Jg�U�3��;:\���]i����1��dh���"�:16��B�g�yu��!�
#��}�NW�E�kT�����t�!������y��Uz��'���6y��B��gI{�����*!�����|���>�B����FW�W9<��<��nc����QZj�A`-��IL��w&��OM�Y+���9y\���=iy��!�E�����H��(��Ay�	���,�>dnR������t�p\\a/�������zB�V�0����{Y��8����K	�`�-�1:N��`��f�`�������&��1�<�H�������B�B���r�a8������w����b�S������0�0n����h�]�.���U�<H������-��xb����.����%�m�c$����{2������j�W�(8P3��;���i������m|a
e��A
��d���)c;���#Bx������e,��K�;�Q�v�a�k%��Z` ��+[E���
v&�����3�G����/�Ba'�BxB��n�� ��P�����b^����$��{M���M�����X���5�u�~~	�/R?|��ld-���~�E��Nwf;*G����B�v( �����}��:�r������%����x��v�Z��
!���r�d,lY��c��=�r�Sc��Ij�e���������^�"}���=ku��W-'�W�Sqq��|�����L�>����@�������	��a��`��;<7rW��]�*��}8�����?�S/95�1'|�q�r~9BG��M_k���0�1'q������9�9���%�YK�P-D-��'��dKA��K?
��aH�&�K'���#��tq��Jv�T�9S���)K�wL�q�������C+��c[����|��w��C��BnN�l��v;���x�������DD4��zt���>\}��Q.��]�W�9S��g.�,�3+/��4�w!�wH�Kq��]��������!:-���l�W�T�����Q�&�<\��Kk������
K(��1�_O��a�P��b�"�u��p��AD���is����k�2����ZV,�t�D�{��u�\n{w�x|����s��j�����&��'(���?�����V/~�$��
v>�L��s>�����YN|5��v��U�����&��c�N9�������I�K�**GY���x���_�%�	����M8���j�IbR'��A:��e�jj��d�F������X������pS���iY�/��v0j��^��:N��Yykg�#��Jg`���6=>o�2]���\5���=�]���O�--����2����}}m�;Q���X-��RcnUsk��bD��������e>l�D���*e���T��t�N������NoWG�Au����^�r��-w*����Q��e��%�%�h#
�>8�u�`��7b jj�b�do1����7�%��F
0��H����/>���]�Os���$�Bh�{s�pe��bm�ck�Gr����_�16���9���
6�=z��;O�Fm����st�m�3U�a��_D�13E����B����L5�����w����[���nfO!�h�$��-r�������Y4�o�]!D�`���B��F45�D��c>hnY�b�Td "��TG�����Y��E��#�[Jq������$ztOZ1A�C�2����&$u�DOc�HV�n��:wOqOK�L#�""]����;�����W'�~��wz������$���];U������}z
!.IY�r��#�i�nl��]!DW��(+�A�#s3�������uPnoa���9|	�Z���o1k�f���A�����2��HL��3w�����s�����myt�BD�����w�D�����)ZV��G�E^�b��m,|��#���l�bC�	��7'T���v�=z��/�Mzm�1��O�����OW��_���wv�D��3:�8u!D�0Y�����������|�;�\+!D�u����N���������^
�	�U��y���G�R���� 4E��X��U�H��W���r{����_a�b(-�o��<���7�W�^����+<b��������?6��Z�C<�^�7=�bm����o�b���P���{&��|��o-�i����o
!.$�.!�8���N�N�}c���5;�����;�]Fp	!�C�#0
K�h�x�����f+�i�����FY�����Y�@)��`��������@~;>�=U1�7��=���8:;�>@����8��'jm�>����y����5�6�W9(:]Zbx��l�qw����AkpQt�3�v��l���;�i5�������U�I��%:>��E����W�f-I�	QK]Bta������������s>�T�RJ��.I.!������W�u��j�,�m�H4^0VG��d��ZOX��NF�"�;h�~U��JOr��������N���r(u�������s����`p��*G��ry%�d=��2&'k�2]a�m
��g
��,g�;����v\�J�;��P���M�B\��,D��am�m�E���LIb�$��^�&fRw�##�L�i�������������t�z?]@y�"�$�e�h�v���P~����s9���]"#	�+���,���O�����'D%�y������:�J�P^��������t"�6g��?���T
�n�c�(o��[�NoT��I
���������Pa*t'r�zrgBRe��sB�Z2�K�.Fc��a��^��>>��9T^��h�
fn����M,X����G����e��e���d�[�:���a��~6����v��a�}"�w����'��71z�������/��<m�t��@;�3�u�^��W\�J������u�[Z�w���#���;�Gsu�$���������q�\2N������������;����e�$~����3	?����]H����Zv�7=K��V� ?|�r��+���8Uz�ub.���9S����M�������;�e)o�s&0���#m����]�oN�S���*��w�;�z�����5���%#���d4�<�g�Dwf;�>�5��T�RT�2�H|+�G��k��
]�"gK�K!���*������3�DN����$���?�X��{PK�]�����
��s>�~��6�����d����r��]�*����=!���$�%D�����]G��}�1��g�;�	[���D�����_W����$q������N���i�>�B~y��@!D{�9S��-�.r���������������#�z���%�V,��[��������@�2Mi�h��,"�ED�$u��rI�K����0[��Q��O*��T�w��JM���������yU_�W�%0���B�.mB��������V��Q]����;'��T�����4\���i
�B~(���,��;���v�;e�$o�B\9����SW|���M��l�0�&����LE����~�=��FU�BtS�+�x�����rsB�.�@��������lY��=���N�kp%���"P��W_6L|��������VQV�Ss�����i�o0,n@e��!m6x�e_��V�^��(�9IkB���b�u�b�Kg]|Rc�C]�=���������;�a ?
�@�(��Y��H������
���%�YK���������a7����|�����9_^x�=b�_\%Y�l+[>7<�������_D�]t����|��a�v��/���m{n��{�o��S���%�YK���������Tj���Oc�#d���QZ��$����X{��`*b�&���B!<%"��=��W��w}�s9�GqUOo{h��?>�>���t�����F;����A�~&�?�|h����c>
�\}�n��.!�mO]B���o����M|*mTj���^����`8���/�X����b�=Z�z*�����r*5����+� ��k�:�����y�]�G]uGq]���UvYL���������(/o|��w�|(/k��I���x����j26��w*�h���@��M�c:W��S�b���D�w��Xp��/�;����%��u'�S�X �-!�^usBe������/���*����$���$k�M�\���B�x����Co�����w���j����-��B���O!<L�(CS�U��i,_P��3��qrL1����+e*�B�v�z$����Ot�(,���l,Y�����uq����S]XIy���|v��~�m�	/S�O��[{1>�}s�����Y$��d����q-�Eo�;��3���O�_������Q!D{7!���@;�.�v�.�\k'��K\��>�`��N�V���oQ��s'�^xN�^kn��g�t��mv��KQ]��/��2]������G~���1B���O!ZI{�KG��w���mK�3�P[��<���:��\�:
!��+ ���$W��*%�%�D�I���Nr�;���*;9��s�4w?��C���\[>q���4������J]}!���%D3����_���RG�`�y_���=���-{pb��C�sG��Ee?���?�~���wB!���Nx=����}M������=���%����*y�]5;w�jnZ �M�D��PW|O��Y��l�|����_�=x���k�\��cb���,����+Zo!���w��t���h��S�9�YMHRx�]5[2�<<����]���]^�T�����WOET9�j���%������.��-���S!�h�ve�7����Btd�����{�L[l��Um�k����!:.It�.G{�����e���pt)W}�J�v�����"��l�F5�B�v�����Oh����T����%�[y��I�2�&+��m��J�zS�����Y��y�;�����
!���(����jFi�SL�&�JM �����
��-���f���S�B��l������QAA.n�������
�'��s���^�������\������4�~���g9�g���5��Gs
��\-�r�]�2B��$�D��-������^H7U7*��Q�cJ���3���i���9�^�B�>.���0��������*����?!���������uX,�[|�:�}��/��_q����S��t�����l/<��Ix����)��/px,�"�s��$��-%�.���l%�����
���6C����\��*�Nm�I/k��8;�u\�A5#��B��=�Uu�\������f������PI�F�T�N���w��_��Y�n�Hrj�t����Bx�,� :����/�?�Q���K�Cz���w�K�TN�\����[��B!Z��D.+�z9A�[\�J^\e'g�y���`pyl���$�����xB�dD�hW�g�D�(��PsWC����,�|���J[����-!�B\��_4~b��$�D����Uv��|���B�w2�K\q����;�	���5��\ub�=���;���lw�ki��G�J�h�����m+-�BtQQ�.=������	I
suz�RBx�$���c�]���+�G��?P�/��@Y�r|+��[�{�x�����Gn9bA�&����r�����<��������kn��u���$�BtI����Y�s���C\s�������������*%1&�^"�.QC}����24�op��s��~����_W�=��A]�=.�����	-�Q������JM��O�pC�h-[�������������H���)���OkU!<����pV*�����U��h���]B���X��T�����,'�R�%�\�'$�m�K%���Y�<��CV2�Z))���]�v"��{��}U�X[���|e�x�%�����X��y�@�C��r���q-�^����p�>�(~�lX��T�.B�q�paz�z�JcvB��uh���_�������T>*n�A��*5j������	*:F�������R���"��j����W����q���]���z����VFtps��O��=����g�O_�H�L�;�-��CX6�%n�3��5B�
��q�F�/�v�x�9
�_���YN4ZX��S!t�c��
Z��vu;��*�d�x�Yo�D���\]����8k�n�x�Hf���H>kS��_0��������m�4	��AQ���|��}��r���s^��U����g�����/�QS4�R�����<Uw:����(���0���w6��n��o�)u�%���Etp�6}�K����#��m��?Md@o�qN�;I?Qv����g�O_���gI�r�����kV�{��3���k���yuB:c{%y�V
=��t2�n����I�0��H/����K��������k7��h���������?���U��}�A~�m��V�9�N;�J6�
{�
������M9����z��|t��~s�m�"��@A���{��j�|�teN�����m��!�@��"]Ex����I{���l/<�a����DN{���R�`�:���~�`�a�������	j5����w����%����y,����U��������q�%s � IDAT-��.��������� W	�"�Ez]7������_��X{�W��[�T|�e�\{���v�Z�U����Ti99������v�����u�����5�y���O���tk?S�>9���2�~w�pm@�j��G?{�����m�k������Uk�X=��Dq5����-)����m���{�����8�����7�l~z���l������W��{����yt��z�)0���w7(�_�n������?$�������8�E�iI9��+���D���E��ZC$o��!:�_��T8/~���r�T��V�L��\��-(�
����2���z��O����E���Y��Js�E���rn\���*N5�/�7����hY�B]�!���G3�%�y�ve�X�T�W{&���d�R��Z0:�S���p�
�<���#���`���x�q
�sT����_*<�����ms�-�.!ju���'���hu����h2J(T���n������3HP�k���9vp�ItU�����=a
�;����uT�=�k�"������S5Y�J����m+M��������9��O�:�X���[�I�=E;��aiUb�1���<v���������8��`���yl��-.Z��D�����?��?u�/��?lkt��6�
����X}�T�M��v��s�U���E���Zw�9~n�9����x��TkI9�}��f����3
G����WIx����n�[���*J�����<���rf�?�l}^��\��iI99?f7Y�����8+����<�X9�<U��\>m��Uj�}�h�Ztj���c�����_��Z=����5q�X!�]��	�L��4����
<�����$@�7*�����m/H���h������r����Y�����/^
!._It)�����P����r�x�.Rt���6@�vYpW1\�@�RU�z����\��>�����U'�UI.�_���(.�N����j���j(��������J0�p��@x�z���?��	���_����~c�G�J�O�r�p����)�)O��S�������-�1�g��OK�y��������f��&H�A[��h4���>S�a���X9�R��n�������W�����:��>�r��V�
.��������lb2�h����#�F��WUrC��_?_?��qM���s6>Ro`�@&�6�^���4&5�q����jI9�����?�fA���=3�"Z\����������)�*�F�8��4�����s��
���R[�����?���5�b�������6.z����+.�S��"!��hn�o<.����5�����0ih*�������W�����we���|�R�*�B�;���*���.���C�����WhJ|KNK���������`�;~2`W���:z\]{rx�����#�x�;�P����~����!V�]�o�@���3��h�r��@sI%��G<��y�]�yg�;
�GD���E����Op62}��r���������7����ZR�-�mi21�S�j���������l�����z�
������������/��>@�7���M��pjh�������Z�����w��o�Uo��^dt���U��G<~Y��6"r#"G`��Y�k�J*�}����p�[�'���s�#R9|�0��������O����#��)/Nx�?YG�pT:v�0�����%����_��q��*_���wd�/Ea���>��h����RG��I�Y����u�(�g��X�Wr|��c�t��L������8��/	�Po[�b����T'o������c�)wKF,���x�F���a�?l�y|m@$��o��n_'�u���U�����-�.y��u�2>�~3
6b�o������j���,g��=�Uj�����7��v������dk�w]P\
f�)B��Wt=��r*�689o�u'�����P��M��c��4�z2��D����������ml�XB�E�1�z�
cHD���v3�+���R�Y�1b 3
$� ktuD���gI{zN��?���������o��_������_�����I�SV'&+���m�.�]B��2�.������g��5��{i+��//��b��e(�u'��D�_WvC�
�^��&�w�,�r^�������W���q�������������$�Jz���-
�
��2���~UO4j���sQ�z���gI{����.��l�����1�j��g���fc\z2c#�=@q��X�a`��a�jcZ�
��p�`��.;����%q<� �H��O�l����,�m�DW$��%��9����a�?>������lp�M�����<�}M�6_�����+[���{1��]��{�,F/D[�2�.���O����1��7���z��)�Lt' ��KG�X��@���==G����=ku�D�������6������m!k�z�%��!c�(!c�&L�Ng���Q`�#����~�}�N��r�q�����F�"���G>7<K��s�-=K���$����u���G2��a��o6K��B���9HIl��l�B���B�����`k ���
�X1��F�S����:{�DF����p�QL��Y,~���
�����8"$LB!��P�N����c��q���B!ZB�QV
z�G�f�>i&!m:c�up��Z���s_�v�{ysfnC`����N[����%�0+c���n^6i
f��p|�rW�����H[z����H[z����B]*�%�B��j}�[��������1�WCU�v�����G�����r��W���p� �t42����==G����=kI�O�Z��B!D�����V4I	<���|l������?Wa��TM�C�,~���R0��i�������, T��gr�$�B�����E!��D��8�W��f����6z���n�B�����n�n0a�t��JOr�����{�q�K�+����d�bhY2M!�B���B!D;�&fRw�##�L�i�������������t�z?]@y�"�$�e�h�v���P~����s9��U�D�2*�,YK�r�d��`>��m���}�R_�CB!�!S�B�ni�
fn����M,X����G����e��e���d�[�:���a��~6���$��QO�F������Ug v�f?hl�CB!�m���r��]��B��Xd�I����iK�����=�_������8�J���{H��Y���Y���#m�Y���d1z!jI���C�v�B�&�U*Ity�Sq�TVz�B!D�t�k/D5It	!�B!�B�NA�B!�B!���$��B!�B!D� �.��(���a��BoW�s8��3�7�u����lb��L���S�Xw�^�"�)�h)�<Jb���Q�7���|�]�.����e;�bg)j=��3c^zoW�;���)�\�kf������`>����{�
AF�OK %%i���_���"���`0=~0��C��j�Bn�66l,����=���1$B�l�R���9d}Q���& �'Cg'09�P����K�`J�'��	I�L!9�z��M�EH��j���Y��Ir�DF�}F�83����0)hz�d���$��lL�1����k6F��yi,d�^OF����(���@b!D3dDW������dY�g�����7�<�C�K�8�]�v�a�plc6+����������^��H��>?AE�'�o�^���{�X��o(����c��8|�����f�����,�l�1��),�p"I���/�'#�����2����t�����Olck��B����D�|`As�f���k��5�J���fV��c�������e'	�=��dN��w���,�LW���_�1����k>F��yi�7f�����%FB4G]m��;r;?��=���<�z�[�+���)�Ys�z^��F����b�����3yNo�B��f�d=>8Ny���9�|=�Rr8����a��x���MD�����>��y�����7�%��F
0��H����/>��Mz"����AZ��
I{`���L"�!��mo��R�K�{��oB��,��D����Y�����R�"���Mk	|��e�M�����-�u6��*�O��0yQ�;(��0���>�H@����	��1����H� 1�Eb�K��#4#H��$�Gx?������/�I�*�hIt�1��N�DF�n���N��L�	�U�}R�f�3Y����4���3��]���G?#�#%6�+(�����4���0����p�����"�����c6������1����0#�6��k$(-d���b�6��I�d!;5�#�oUcZ-H?HaDo���7��o:����g�i�8�Fw����[r����[/��lm�����Y����4��!D�#1B+�����������G6��i���B���:'����14�X�@b��c�V�M�.#H�l=;��a���^8Q�W!DH���9,6-�J	�_g��<�u:t6�J�]�v����
e�64-�����Y�f�`z������;���j��H���e�;��-�xwc��tZ;��%�j�O������c��g/�lf�R�s ~$�}��`�Y�QJ��k����59F��L J����a��C����A�F������VF���x��}k�&6��e�����>GX���JbR�m�7�qdnf���������
�	#�wa����)1B�&b��������������I�_�- ��_1:{T{�A>l/�N�1&��-�<~�W�(���)]v�L-��m�\f&���$E7�CLXz5��3�6
Vfq�P(3�����e���n�:��������h�H$�n�L�������P�a���^YT(H�K��c��nz���M������vC^��W�E� 1�G]m ��c�	#��\��\���V1B��z���S�d�($f��Dh���p�
!�"#���&H���J�:�����Dj�V�m:�
��&0H��b��Xf�Oa�� 8k�j�����i=Z�11������K�ZX���'<����e����N�e��*l����z(���	�W[)+�c��TJ)t��P!�,����������7IO�$A9���Z�7Ef�q���?�w��v��8������������M��q5���Q�U�:�����R+���xg"I��T��B���:�J�P����}Sb�z��o����lr�#��&}�
!Z@]mLk�������y%��D_��juX=���:E���M��8bB��dG������&<��e4��g��P��'��;���d&�����HT���:��KOr�����:	1u(��Hd�Sq��66|��	�#����;���N����MMt,3�a��z�,�An��d��8�#��<�-��~�y�s8f/%���x�K��&jbC����/�K��]�/]t\#x���'�J�L�P���^/���#@s1B����-��o�\){�J(��9���1�cO�q��U��E�wH�*�hIt���}�`e��\
LV��a�+���G�f������*8�6�����U_�#��a2^9N�i+�;sx�����72$�@��aD�����.x������_K��h$	a
V���c���WI������l�o��T	[��r(:�Q�0������
�����4���U��9h��T)�s�j20`�{�b��&�MIr�q�Y~���%0��d�8�%�Mq��rQ� F-����Z�7	�d���)c;��@Vt #�Ju�`�)@u���P��L�C��}dd�)?m� }_�B}{#��H�p���}Sb����7[.��+�cy���!u^$��>��O`l4�
!ZD��jsz�����lk��K��@T�H����7.����Md�]�'�-�O`�Kq���L~�������b$~�R�X��{,�7�?�>'kP2c#��32}~�b�����S������(�X5��e���d�[�:���a��~6����D=<����X�R��"�:�az���F��6�Y����^=IXz�}�wie�T16u0�RrxgK8��w����'���,wi�
����u}���1=���-��Mo
&����/:�Z���,�?����;��D�����7���
k�6�`�B@t$��IBSzK�p���}Sb����7[N����5�}	����$~B4���r��]	!�B!�B!.�L]B!�B!���$��B!�B!D� �.!�B!�B�)H�K!�B!�Bt
��B!�B!���$��B!�B!D� �.!�B!�B�)H�K!�B!�Bt
��B!�B!���$��B!�B!D� �.!�B!�B�)H�K!�B!�Bt
��B!�B!���$��B!�B!D� �.!�B!�B�)H�K!�B!�Bt
��B!�B!���$��B!�B!D����
q���&���D��53�{�2��`� ��w9j��P@c��:��������(;���E��>�~����W!<����x���-H0x�6b/e��d~f�|��5���$�1�Q�����(�8kFg�gh"�����v}��K$�%Dgpp/i�
������������|����cTL(!��B�s�6��9K���H�^�����5����q�#��+���$�%D'P~��#��1*���mKM����]
!��G�����)��#"�{�$J.�tn� �<��o�C!�L]�K�l��2��,_����p�d� #��I$e��j�u�4-�`��O��)K+o���9�y"�'ryfF!���)X}����L~>����c%pt���R������'s�����+:"��1yQ<�Au�Q,x3��?�S������9qD���`�������~�����=����)�Q�c�T}�[�`>���)�N5�zr�}���d��~���xy���5&����j#���ER����Bqf�8��V�z�D2j�0F����1SZD�+{�������F��3�{f�P��cKg��?�n���e��9�������b�x=�}l��7��
o�dV���x$���j����X���aU��.������!#y�s\N������}�EAD���6;���M�X�M����Or���^O��>���`������!��<�J�����.���������`����)���V�j=Q����au�m��!�'(GH�9es������Or�DA�����!�������'
H%��<}1�����H�~6��;��q�-�������w�^���� ��N!�o�����y�����:Q��|��_[@x?Hh}�K���:��3�d�"����h<�!u�k�������l��U6^����N�`�?Y����o&3�`?B���1�f�[�����2���f��[{����c��gN��/�k7�nj�b�b<���$�����Q�#�+��������+Vl����c���O
(f��g�{�=k�Y�OM�/I�<��G��u�T(X����A<����yg�^^[�����U���7��F5C�#%!�!ci6+� �����8<�0��g����$���17��VQ�����s4���R1|���HG?�&}�&������S���Y��P��sV�	Io�aHM,�&�Fw�?������|p$�%����W��n�Y�Ub[���
�����{������G�9{/��?�%k2r����5����>g��d������Yv��	������}��yd�����D���mf��O�GL�
�[z,'�xyV'c�Iy#������M��6a}i
�UG~���"�G�Kc�6���B6,���
=I��	>M�?!mc�OMdH=X��ye;k���w�Q]d����^,�����5;�h����PZH�KN��MJ���m�|r��CY8��#��X��3�h|��?���]��H��El��'lx<����6_J��Z#(f�V���1<�H���rHO����:XZ����c$P9�������0d�Xf���U�?���%��j#I/M!������a�����Q���j1�zt���%H�R��E�1{���8�����w6�FT����1B��f�ar�?I_�C�7�5�u�� � IDATg6k������F]����a����03�k	��>!c��c����Z����_���,NT�r�.���&���1��B�N��(��nd���Dj=����(J9�g���z$�d$:F�UmdH���~������RgW��A��ID� ��'��� ��G�w�j��>�h!����L
'������9�7��#�����'0���?"�S�; ����
o��R��L�>LNH�h�F���!i���(�T��&�@X� ������� �zU�����K��^�c�`f��MD����H��DJ����6:f�~�K�Q	���4<����&�d�$=�ws9P�K������d��^�Y,l]������I���� n�_5O�'��x�
v\��cQ(x7�cD2y�`��e��cH�c!;����v4SxP!dL��t76(�����#����)<X�&���1v�c��$iI2�G�����b�DX/#�&Hny�����G���o�#>\��[����"��e
�e�C�h��p������25��F�&F��cR"��C	�e$���$��pl�a������,�z���ic�+HN�$�_(Q��	k���-��W�"�W0�@�%�W�!\���o�!>�b%"e���b�vc)�{p4�O�����������HHC�����
��>��g���:�j9Bz39%�=R�J���1�g��:��[1Bk�
���m�M5o�b<$FBth���JD�����9���+.BM`w=�F�SC����^�F8����T��G�`4�R���;�`���Zo?��������yk_wR)��F_�8m�,G��_81�`�
p�4���{�&�.�h������z
��J���c
��8t��������b����{��!�|^}hyF&/LDcW���D��c�`����t�6�l��X8�g���-OD� ��%V�1���AZLi�xyy.�;��[An$"�n%�D
2Bv�-�!kK!���{*H���bk��:���:����7����
b[|,B�Y�~���j���A�a���Z#���T���@t�~(�d�~������C?z 	�{�C/���%��@���z�5���*���������A�Lz �-������:���6r!���RoP]��(�<��ci����������.1���������x�jOU�Z��"�[�Eu�K^�
N�U���b����9��}��0���{��sI�X-���k�6�5(6�@[���b�4\����������1+8-N�g���Y��i5e��8(��w�����;����4M��z�S��V;�����(6�w�,��G�������g~���}l��g�{{IWk	��G����NX�D����B2���aW0�7��#iPkOZ�w��-X���"���(�1Z�|�jZp*Xm������^��y�#TXl8P7h�:4�`��Q\���_7�������������/�z��(u���{������&�I`�$����=��4^��T��x�u�%{���S�g�c�Gz����
{�Z�
b�X��)Q.bC��p�lB'2��2�E~$��d`�	��u]�fee��Zs���|�}�+�H������9B�?���#��L�.�0����Wg�i=��F3~Kd��=`�Gc���|v9cN�X��d�A)��%�m����k��`�&v�y��{�hG=>�r���av�)E#�t�lq�`���e1���j����U��9%�����z�pfN�&�5N-�����(N[�����N&�����#9�%���.�-���'�������)Z^��s������{�(�9Y����Ami5%��`��"lk�39�$���N��ED�F�pJ��o� ��-��3���;t9� {4V�S{��45�-������#����/f]���I�gy1%Y��v��O+�y�i1a�-�c��!��������r��4tQ���;�FK[���o=5����&��.�9��~K	�=����$[�������#�i�j���K���!$�F�n{�$�*K�0:���ih<��ph�7���<���:}I0]���h��l�z��Z�n'�sNf�����Pfy�od�O�d�FJw�a���N�L����!f���]��*�Q�6�>�1,�K�f?�6z=T~V��	�q��4��?��zjO��������;w����S�}r��#T(��i;==�>�[9��*;o�K�nF8���I@�Y���:6'^�vx�,���PM��{+C������/~��y����z�&~���K���Mu��A��5f��@Ob/������O9���S*tI?g��>�g��~���K�[���;����������P�����x;oz�MJa��G
K��\;�^-���j{q��O��d��O�tN������{���������<`�X�f�K�)�mc����C�z��x&?��u�vV���awU5���AyT"9w�����M�d�X/���H��n����������,��WG������y��� �%����'g�Y��M�K)���XS�����7�q�-���O�7��^�x����yi�qS�~+K�Y���kN�Y��f��?"i%�xi��R�k/~�kF"�:�]�������l�t���zwU
�
�s�>���'���������n�^���>pb���Q��vz|,""}�r�v��������*�.��]Rn�q
��gV��0Gp�r�-6\Y����?�(c��{�����{��N�?�:
��v�g1�^�(�=������4�z;k�^���W���o{Y�l?�������K�s���g���FL�h���e5��}�F��AD�)
]�~/!w3���'�dQ8��"��,�{��6�!�l1����3��t3�/���
��Y<���Nw-�<6�����{�-����H�����<'T0$g2o����
V����E���L^r=9�
�"��S���?�Q�����m$���YL���,r^����=��B��5.��I���pFG���
y�}�~�:2O%����?WQ��NV�'���Np�!w�A��������g�c��nb8��T���P�����Nc���A����53��>3���&������b�COK�S������R)������`���>��1�	'�9x�fen	]:P������O���:�������H=G0[�6��qP��Y���o�c�CS�yn�^>=���!���\0���%�y�:6����l�=���������a�I���T'�����5,Z�����1��9��i<�-{Y��fj=3v$3f�v.�`�=\��e	���Z����s����;9�����i��O9���SZ[[[C��H��(y�x����L%["""�����)E�����G{��������.��������HXP�KDDDDDDDD���.��������HXP�.	*t��������HXP�KDDDDDDDD��
]""""""""T����B�����������DDDDDDDD$,��%""""""""aA�.	*t��������HXP�KDDDDDDDD��
]""""""""T����B�����������DDDDDDDD$,��%""""""""aA�.	*t��������HXP�KDDDDDDDD��
]""""""""T����B�����������DDDDDDDD$,��%""""""""aA�.	*t��������HXP�KDDDDDDDD��
]""""""""T����B�����������DDDDDDDD$,��%""""""""aA�.	*t��������HXP�KDDDDDDDD��
]""""""""T����B�����������DDDDDDDD$,��%""""""""aA�.	*t��������HXP�KDDDDDDDD��
]""""""""T����B�����[I��f�#��p5���_�OY��q�0g�xny]��
���{X?��>[��0��?��/�	�vw3�����
�f�`S�+�yr/��~��+��g;�^���m��p������M
v7W�Zf�S��.���z������:S~ ����f���7Y�e��u>:��f��6�sa�)��~=���gYwh<?�I�>	�g|��n#�w���wW�� �1$�q�������������������h�&�2��'6������zf6�R���'��%L.���(c���`S���n�����@����u�D�����)��7�������@>`=u�\������L�?��#
��H�17�c�]I��&���5����A��I}�W�F����P����N����X������������z���I��nV������@nk���(?�^��@D��
]�`�c��I8��k��b���1�������z���)����k�q�/�������|��CcK��Q���&;���2�
��n�>�\>��I�!���Sq����|-����r�+�/����%O&v�W��M^,4��������)&���9%X>��7���Lb��1�.-f��`�����]q'�{��[���C��t�<�DL ��5�|HI}��>f�{'���/x����u�iy	E��q{��t�yw����
�Eyo��9��Q��v��z1L5�>��+��eO�i�%�f���������
��������N�_~2���K��{�p���5wN���Gx����O�H��~�����/��;�9������������M���No�Q��c���r�M������is�������}�W��m�}v*I��P���f4��1��:�G�kY��j
	Y)L���������[�G����U��>qL������}Sne��DjA�:�^������?���,�����}����w�+)������0n$9�f1aD����a��-��PG��}[3����-�?+b��A��R��y���H��u��'>����JV?��m���1����H8u��
��)a�����g������R���o|U���UP��h?����,2O�����"��UM��BBV*���64��?����{����m�9%�;�`T\���:����_�4Y�8s2���"����q���Ai��1~RD�{�0==)�/Igo����GJ��r�m��V���##�����y|7��:(?P~�� `�DBK��>`�������l�V�zkivp���u��0���E.<�)xx#��R��3�l^J�7R���X������l���tY3��]��q6����%%,��/������K����Fo���kHyv9�"!�kv����,����#{y���n�e���c��p+�����W�L��O����<�V�r�e���Y����y72�Z;-��xcQ/1�'t�<�����w2�w��������y����F�uX������5��E?#����M;xc�G4D��Gn?q�6�#l��R��wz&�v`3M�Y
`��q$$�l+���]n��{��m`�������F��2��������]C�s�y�E;�y��_���HH�m�#@�i�nt���Ih�UO^���v����~����=�5���R�4�1�G�$Y'f���L0��[��[�bv-�����Y��N��[Y��
������k����������l�ew����tJDgo�F�]O��u.�$}I
1�(]ZBi\�0��G���Xw��|�zR�PQ���>���;y�����wme��D����y����|�l++��������L�{�#V�)���Lg�h8�~	K�(t�`���������/D�������^�������qw�{�B���f��l�Ne�2�����|��i��0��x�&������~s=j�������CWg3����z�a�3%�|�����.�E����k� �����O����\l��%)}������_U�-�<�h81�oX�\	//��O�����"
�����O�
�6��p�,��7	6IN�V��	z�y���m�4q�y+��E���[����7���x^X��V�����}(?P~��@���F���	>�]&��2�z&�k�x����U��$=z=SG�\����Rw<9�f3a���D�.�"���'n�+����7������w%1*���)��5?�1v�C��"���q:mDa!�� !�ABr	C�����#!��s��IS$`b7��a��X0���0��3}V��	�5�q3��lf��HB��
�����kM{|�Do!fD	�C����8;�����8�K���hd����W��Ht�v���8��|M%�������{��~=�������+���#=���F�����{+3�������HB�\�f����dOr�f�1v4���3}���!$$Yhpy��v��������nk�5��0�����z������`8w<�A��q8'�g�M6����l�fo���vb����v��	L�����Z,�L�`�Wi]��^�6|�����{N��,ro�u���m�� ����t�V�X����-�������u�8��l�z�����0a���av�S����n%w��/U>J*�}��L%m���)��:��p��8�Ft<�b�	N�e�f7���H��ZMp��#�/�K����W�A@��e��(2���py�����O}�-Q8F�����3�w�Q��7�����GSII�#��Tr��_V��S������R��b&����Q��]�@�G�[�:S��d
��v�)��_)�vT���7,�7|����'YL��h�<�M�H�2{Q���l�v�w�������P�(�:G3�;�������(?P~p���@R��H�]���vL��u�m$y�M%���yT<�^E���,*m������t��e��p�wf���f�=��1P����8��:�y,83������E���9�@�$��h�1�F[�b�o������<nx���
'��o�<i������u�q05�s6���!���	����Q�ms;��x^��{��H���s$S&�9�I�t`+���'
��$�vu<	�����B��/����?�d����D&�up���-).�����M<�{��AS-��?��1��'�����k�X�#�V���st9�K��J��&�6;"�Y�V�h��<o1p����������!$g�X�N/)L�v�>�A���;����
��)�]��;S��8��i^OZ������q�7GKIc:�H�hl�Pk�t<�����������<�-��Q��<�����]��f�:�2����a:.wc~C���g�#T�6������aZ�&��UP���vp{p{-8�tnev�/�����8�m���wS���m�v&�><�����m�G�69������P~�>�(?����.�����������Fw}���q����c�2n'��d���i]`�M&T�������0�+
������?=��Q��M�j9������&LJ�^���O�s3
�
9�=�5���������n?�����\&��Og�i��������e'�����g�(�YpLL!w~������#�`}��>���H����=._4�.�f������������:7&�Q������]���:n� -�c���������T��O���R>�����l� �����q��)8m�������6�*cu~%��=��^�\}��� \ZZ�f�X�v��b�z��N����<l���'��P��d�Z��of����5�E���HT��
h|��.s�`�������&,8�Nig��.A��V\���G��x�����W�������k��)?8�}*?���(?�J��H�P�+lv���g�����V���N�D�~��	Wf��qa�`�?���S9m��([��mQX11����{4��?�s�����g������O�Q�	���N�p����>�3���p�xf�0|��{�d�v�����U��i.ks��5����fW]<7�$	�{[�Y6���cD�O3��Y�E�����~os��	�Y������I���w��'����M�����{&�v�=n�|��?-/�%K�����hl����������`�V���g��TR����0w_�K\=
f3F����1���.���]����k �����v��� IDAT1Q`�������'�o�����X`������k��3�z��<��o=1MT$��m72:]��z�%��S�{j4,D�m8��s�|	�}_��(?�7�(?h��@���9�������x?�\O��IL�U���j:
O�t`=����#a���Qb����8��y�6���<��F��s�N�W��$��oR_G�cL��n'&��
z fl<�T�v��0���$�>?B������~*]�/P�
��f�%a=POm ��3����������>�G����!iD qu��O�O0Y�������w�B��S�[��Y��VB��o&���n*��
�_�3�W\��}�=k����I���h�r�`q��j�qW]�yd�� �:
?oA�QeD�yof[P��UxX=ei���+;5��:�8�����T����rnr��&&����������2w�-v�cq�<6��jk�v1���b#6�=i��#�f�������:��\�lv�c�q�u�p�E�@�w�)?���T~�+����D��
]������j�O���}RO��,�B��*f�t`�'1cA
�_���N&:17d0!��wl��o^k���S���?R�Y�E/*�)w;h(�BAa5.��}�����J������oq���������*?�����O~��<m�\~L���t,k���%�������FV�WC�a/�_UR8o-����%h��2�j(]��M_yi<����b�T��{����A�g3�����[���Cc���o�Y_�
d$���p�����#$]��
c������[\��z���~����>W��-������@P�7����U�W�:�������a�����Y�~V/�����{������L�K�)�	�8[�lY\D��
*xi��R�e����c����G1��{���%����P��^
��N�g)����0;��}_�`�`�O������������M��Gi~	%_�����u������M�������zo��pW�/�9��z���q$F���=.|^�n��*
+^jk�����u��q6pUF�u�&������A�����j�c���i��������{������a��Y4����y�p��b���V
?�����mK���I��S������J�A?������(?�N4t1�*)x����Wf���(�La����I��'������j^\�����L
����|*�/n��Kil��<������N^����<��}k#�/�A\cn���y�=����T��SC������`��qiF*?�%	,`|������I�������Y�=�]�]7��e+�|���>��qN��9�2{��>0v&/�^�J�����1#������������7��t;�������iF�`�c�%��8�&��YmqX�9��Oy���y@z��O:�(}w�	��
�������bnh�O�=�Y4��G��I����smd�[E<�����+��1k~U��.�������%�~/�y������|`9%�(\T���2:��geKb��g��w��YB��Dcr�g�'_q���<��(�~�����bD�p^�J��W�vbH@b*�<V��W?b��1IL�#�{6�tI	�~�dA~F�9��%�������RV����x&�e�cYG���j�Y��:�\���������c��� ���i]�dW	�sW�:.�1��g����k�f������9�-{�x&����l�����=��O�����8��TI���0����g0#�c�3��H�]���
��(�G1}y�;��D�6�z�[(zz�lv�o���;�x�
B>A��#glk=o�A�����S�A����H'Z[[[C�����������R�.����v^�����9�B��73�;%/"""aD���H��G����������MF/""""""""aA�.	*t��������HX�d��4��sH���DDi�0.:-f+����CDD�����P� �o���I}�/�!�������o
uaO��o�<�>�����
u-��O�������t����sW�C�:�~CCEDDDDDDD$,��%""""""""aACEDD�3�]_B���p��XGg�c��>���������>����2���M���o��m�p^��=Of0������]"""�o�wme��C$���o���#?�-�(r�
��}�����;q�t����%���$f����lRjvR��;X�!""""}D=�DDD��2�����^���X���������lp3�AG6����l�*y$S��f�3%��s�k�>���w2I0���G������B�����S^���\zK[������m������Y0ZF���,�f
���/��:a�.b��jj��q�����L����^���"""�?��4x�f��_�1���I��AC���wz��3�|���
�_��n$����H(�J��j���1����H�R�.�~��-�V�&�#c�&/u8��=;��[p���g�lB�pnyt4	6���3��o���j^"�����za�r*�������t����t���
����VX�0����7�DDD����K>����".tY����j��5'��&�-���Cl�i7��(���}rYL�
�?�ij���������I:H���<�>���q�����.�&5�8�|�9�����~"�MCEDDB��-#v���-�=��k9z�������B�N��h��u���rW3���<o�I��Cm�/���R�qx���9�����?��b���\���>@E�����6��DDDB���w2��2��2��c�{�R���g�0�P�0�'���|'���4�{�,��g�x���uU��'s����JO���g�7L�Fs��['~>QKNar��m��e������rs�-�u���DDDzjl��]"}ACEDD���� ���UxG/�����G���(����:��I������dU����$&9�)����a=��Y���>�����`��l^|)v&?{3
�����R�h;)?����? �h9�Z�]����hD��
]"""}``���y�7�:�ZGG�	eX����{S�YV�'������<��~����fh"�����sTDD�;������=��P�#�T�	��j����*�AI|���c��������Elb��R"�����"�I�.� ��!�r>����A��I{%DQ���H�������!�D$���,""r�:O"o����=�'m���C!�JDDDB��aYW
��'��8�Z�����0W��]"�E�.�sdi:�����~�]��u,oHY�1��F&"""����H\��|K������O��fbcC��E@CEDD����������1��B���������P^K���r4	�HoS�KDD$Vo~{�����c�&?�q�n�����]m�U=�r�rM��P�#r���E���7�������,��-�X���DE.��vM[����?���\�T����=�x��G��X�pDDD��(�����1�L�Qo.�P��E�3��7t��j�o��A��2,��^�o��}�����G#rqR�.�SD����8������ ���x�^Q�KDDD���0�c�g��em�-��%""r����I���m����%"""=q��&�
�LRo.�PQ�KDD�����]��t������m����B��EOCED���o��w��?�X���I�'lP�KDDDzE��h�;�:���B���\��n�{�",Mx��P�#"""W���)�"\����a��+yy��HDD�1��oO�~��v[����@j�q*v
q$"�����e|UJ��
��`��|�x�~l4	Q�+xjX�x�}���b�yC&��M�i;����%��W��u�p&?6��mg����\�\��[�'mGG����9!�JDDD.&���l�\�@�1D������d���J��l�x�>.N%�������}��g?����������M�����T��}
���,[|���[���;y���eAE�P����7C�O#�r>�oV�mq����������[��Wr�p�/�U~����+����8m8�ep�4;�]u4��e�����$�i#&y$����=�&{��������A�P;�����1nJ6����Q�������m����bO�xd�f�C��'�:�H�����

]	�~Q��^9��K3e9������5�� ����CvI�N3v��n�x��kri�k�v�/�����8m�^�-*b������DL�������[���U?{�����=��K�"�`>C�Ou"�6|d9�J�p&�b�i��a@���"���u��
�y�������{�����5�(�}��ye4FG�L�0���f��_�1���I��AC���wJ���}�E�v��_�K%���K""����.�������8�����r���D�/Em)&������TU	���-���Q���Qg_�iim�����B�H0�������7l���nR�����SM��8�q''�������8/o����&
�����LX���S�I:���@�N��o�<�
���w��x��D����.����j1[C����q?�O=���p,G�9E$x^[��uzZ��M&��������pMv0#����B�����x��>�^<���;��lX=
�8�.����
��q:K4�qP�1��d�T��+�>6`�������0!�d[~��gt��US���yqK:H���<�
����9��70���9�2�?\A���6������
u"���bZ�3����c9��:	#_�DPQ�=��;g�[����-����g_QD�O�.����K����k�����R�M�����euT�$����1�*��4L�K��f.�y�.c���OO"�f;o�a�z��D[�%_d��>�~{�&���
�>����q,�v��j����;����<�wnE.��X���
�����������'�#;��������a���m�ii)�.�����^������,���hb?�I�z7��^*6��+�)������$f<�_+f�����$""����;�4�xdZ<�GD����b���E����P�$"a�U=�w��

����G#"��C]�S�3����m�1,��L"�bc��q/���{��h�3*�:��%v������&��?d�3&1�IL��ud�~���Y���#�wr���<��ED������8��sB��I��
^�����:b8������N���������>�����i4^���RX�������;v��������YX\9TU��D�B�vM���;�6q&�W�H�/
]��;Y�w����Y|'9g\����l��t�Y�,��xV�Q�=9�eG+""��o ���|����i��p����e�1f�����h�������Lg�����zq}V���*q��w
`k|��O���.z���h��4|�����MJ/"���mwA����\"�Q��(""����%���? ���X��:$�U&{��������A�P;�����1nJ6�p�Ms?+oY�����'��`��u={y���)3���Tg��3��R��������[hl����\�}<���H7�E�.��8n��)�>,MiHY���E	W^���\zK���I�����n�u�e$y��`�Pp�}����}���L�����/�b�>���>��}-���f�O���5)����i9&�lj�QS���[��%""�����|��@���%|��VE����L�lv��3{���04$}���|=�g��k'������nb#��7�]0��U������%"A����\"��zt��H�di:���[�	�c����u1����-8�a��2��_Z��y?��nVI�I��B����[<���������?��.@j��O��o��y�����t�E����%""��9�2hm���a�+K4�qP�1��d�T����>6`��;'����JGg���g��US�����$��l����'�Y��MK�A���!�cc/��/�<K�t��F8���?�
YXY�cZ�yN������R�KDD����cJ:��k����9n�p�����1���a�co���K��f.��8e�x�F���	�Q�����:j�6������7`�Mnr���������c���c���������c����/�H���������<��]"r�
]""r���8�O��ts�e��Lj+n
��c�q�V���1?Ml�N
���������f>s���[N�a��d�:�Y,�� ����>Z��mX���o��QqL}�>~�;�������Q�|=���^?H�c�n�3�2Z5_����im�}}�%q0"a@�.	���8��`J���B=���u�x�,0Y��!��1�INb�o�#{X7`����)���l��01�_J�g��;�o��%��xV����%v�|���qt��n'��>� Q�����BWE��G"�����:��"\�x�g�4��?�y�:��.������0���1���[����e=�����
$��$������ua/X����'��� ��h[���Gfs��[�v���o_����s�7��<����q�Uu������k�.��"B���\\��-��/��W-"�|v��S�\""��.)�����E.K�A�X���E}Z�
Z����'�(� wz4_���W�����VE�nh��/�DD�O��ai:�o���#��B����|[��'����"�]0��+��Qd=g:�0�I��=������H�(����3?�7R���/��~D.*t��H���7��q"�
@[����������O
qt"N���r,�������e`:��hh`���(���,{��
����j"�������t��-����y�v�G����d�""�kX�}�""�
�����6	�
\"j
�������H�A�����ki~���'r�X�����w�8�zwj���V��x�k����~D.*t��H�i���o�7�Z���B���1kyqs~�q�}��s����X���a���w���O�������D.n��h��u�����m=�
�o����\T����4�{��i������\���E��Em)�Z^F��`����'4~���X��t��4']�q�}�I��4&�����06U��D.4��KDD���w��?d��e<|r��D�/����9����@�U?���s�V��V��R}����g�+x_��D.f��h��P^�����R�.	������
��2"���]����bZ�=�e&]��� ?��c��P0f���["��%T�G`�i��f�����%""��70��2@�������*����H �����x����
a����#�b�
4<�B���x]3�8��HCE.D*t��H@,M���,"�
��a����X�[U�������O��+�������X�/,�;A����\����E.d��KDD��DQ�t-���7�Z���9H�mD$�����_���y��"WDCC�O#����p��}��Z���MDD���]""rF'�(�^F��0�����k9nU���>�

��u*ky�cb�t�������w�c�ys��q�y�����F=�DD��W/�^��QG���\E.�/,�����t�E*���dr�k/<���1����h��n,�6MT/r�qU`��|���PD.X*t��HK�A8�E�h�������[�����DD�g&]��}�p��p��8�s?�0Xa����9�w(�I�E$|U�G���`��|
�9W*t��q���/�!�{��th���I{EOR�~�|z=��2����<��n��
����:}Z[�5	{�imOz����HD.\*t��H�V����8�����e;��%�e����
��e�=2�G��Z��%�A;N���Im���z�
*v���DD.B��3t�4�U�:��lu��O�+z���\��e\29�K��:��dp�2l�W1p�g]��Gm�����"ra�fb[���r�D��
]""���?`��iD[���U����D�������O�"(���������{*������� IDAT�7����'�����>�-x�G�����s��qr4�������V���D����p'"�"�
<�A���c�n�oO�X��M�'����$|��e[����b9����hIP�y�������/���G���I����"}`�G46 &�5��t����V�.�s�r���������K
q��$����^�>�K��8n���hDDz���9��Vb��?(�;���~���tG�t�A�������56�x�Y�t"���(rNT�	#�"�'�6���g����v	g����~���^���[���Sm�Wq��,�/���D���mC'��x�#isM��9��u]�\h���H�4�^�~�c�n���
���l~{F�#	���bZ�71�������l���~��i=�.hh�Z^�'/���/J�
J�r�Gr����8�Z��S�������D�.�0�t�cb�H�`�rs�e���MD$x�/c�G�yyE��.�&ky�%����t6�VKzF�6D$�\��(�������?x(�%�!�\��RD�c��W>���v,k��$�^�0����
!�ND�oD}���'}������ZX�h�`:�h�q?�c��9{��>����-i�1l��D���G������wbi�`��86�6Rzo��H����/���}�jL�#�3��IL�h|SJy~�Nb��yS�>���������1�n'������h��tT

4�}�����D�H�A,���^�������+�<�������E���G��H?f�����.OL�G�������[;�\"���k+�"!�V~��N�)lYPD�+�mx��{������� �����_i��������D~���w�8$������h	��Z�+�?QT��R|�5E$\L�Q�.�p��B�iP��uY����uK�Y�����~��������,X���7;�1O�+�`^z��C�g{)��M�����������v<3nr3������q���
=,B��Yy�Z���f�<������]^Z2����G�L����-���w����������������l/������������K����w%&i��U>����&|	#g�X����nf[|K��_�������[��������s��;7%""gf��am�+���I�������9��������8:	k>%�7�'c,�,N������%�n[�������D����K�^�Koq`�Xf'�r�v�1pp�����}6,�YCA7�X���+;/��v5c��3���AzC�S���=�c7��k�8��������^E�������X":�&��Q�K$������t��yL����y���5F�x�Z���w��M����_I��
&)�����@z���T*�����������,�(�����V/E/��+�f����s:�,2�s��T�S,Pw	�V�;��B�@nF�$=����i�]�]�����Azr�9����������L ����o�������M=_p
!��F��1t�4-�x�&Z����5�$�s:�(^��-��(|��m6�U��%z�#��|�����33��l�ZN��sy��7��2�K�)�]sa�����S���'��Y����u��'����*���W���>0r��f�@��,!�p��~>t��2���������C���������_h�~�o�Q�80�P�$%]sSr<�������,���+��fT�\v7��j��l�p����~�M� ����b�o�(71N������	�w�����7����jnI�K������9I��\~���2��|�Lx������jm�����rc$>��3���6RB���Bs��<�L3�����1��4�i	�������A��	p�>
k��.C�����0_�>�'����k~_�~�&�@��y������5����,�������������CF����������y��}*�������0����f���_3�������N�����������3z�LN	,��4�%#���9��ql
�g���5�SX�N�y9<�>���;�0XOp��

���o�f�3s�7Yr��Uk�l�v�5���'�V�u��4��bN���((�	��B��e�����x�6xg�+�������m���������`B*7v�n�s��3^��B�OhZ����~�jL�=6<��n�-	r�H�j�H���7��������"1���X�j�p�98r����)\w(���l����
'�x�����O	rE���Q�jh]Ik�l�F#^��T�lh,�=�x
B��"�M>�W���Uc��"�!��+�4)��ppk
��5��[a�Ts��nj+q�Na�[Btg��o
��n�tde`y���4�~�WS?�5$7�=��f0#�\}�	���{s0b�c��>8�}X)�i&D�c��o���c�V4c?�����y�a83�uA�Ai��[X����fJ��<N����?w����c6��J�cw�3R��p��9eV���5o6��<uMY�6�2|�-�������=�'��6�����^�j%�%Do�0tQ�m���]+�f���1���[�a.g��KEU�O���_!��.ZG
�(M[b:ZG
�8#^m�
�Wk��%�J�}+���o��3�z��������n��P�G+#��@Z������Da�B���X���q������a�l@i�|�[T�����5
����o38��1N���\Y��]w�8V����`��g	;Hx�-Z~WNtY0hC)�����,�u�����e��"�2�����f_���s�����B�.�O����T���q�S�8�&�:�-�99�9�]v��4!��d:����hZ�9�����Nx��\)(/�^���y����]�8G����p[r��mM���1�����F�+-
)3sX13����3o����hy*K*f�~U�t>�^�������P���Mx2������_����z���RO[F6*�5���d����)�.!���%ZL&�*M�Hw���O����"]B�����E�;;�d�����Q�C�shiZ���%1b���0t�d���(�f�'UJ�� �c��aI	�i�}�����1�[��M�q���n������O����O� ^�7�@m����gW����������9��������~�eLv����f������j�������bAz�uQ�N=dt)8�]
�^�Sj���B�>��2����Q�5s�x���x�I�a�B�/���O[����vv����
{&Sk���7�P���K{�{��B(�~}�/��\@`�b]m��	!��R��q����F�f�3��� �"FhZ�Q��,����Q���XO���~M>�E?�����p���E�e��mCI1�9��{g�,��������-#[�iB\�-���Yy�g\��/���g_���:]B�����x���'m�������Aw�U5:�uQ���?��QC���8;a��g���i�����N
4�Y/DO\9�������c()���� DA�!���og������BD�������T�=����:�;�"#3��"�]9��1��b3�;�{�����#�{���%g���r�'��������?���3]r�D%1]�o��#����:}
�9����6�I�y����>�bW��l���!�z����

u�jF_���z������/�/D��q�E4z������&���������������x>����	!��VC�M	G�:c��I;eH�8��^D9��mm
�����6���h,�����%�9_P��fi��f��5(i��nG�X���5�es�������@W��/��q�����n�cF02E�/!���}�&7��v�(���i>U���K�KH�Y/����
w���&��oDm����_2��5�p�/y_Z�f��7;��"�������W��Y����{o���5��10n�8�:�	��2����rp>	���s]�Q�����pD1��g��~���Q1D�J�/^.�%�������\B�������Tq0NO��q�}#����������������o�F���6��`�L�vZ�X�?�	������K��*Z���c�5�����K��"�EC����KfS���H�;��{��l����Ec�G�oJ�9*��B�|���V%C��q=dti�����8��/���//�j��3}�����-�;2���Obd����T<����Yii�%����;VP8YQ������QA;z��=��S�oF�tg�|hj�
���@��e�b��.�������Y/��Q�lQS|����'3������"���[/z.T��7a()�|�2	t	�KF���s$�%D��a��x�����BQ������k���p'�O����[)��XR�M���wY�[�3�<�P��)���O����o��W�.��rwZ�_�"r4-���,��V�C-����Y�K�M�>���F	�IZ^���e���F�;�
�9.
���9���	�6�B��@��|�����#�&g���)�i����������1���y�n�]y��N��o���I��L��l��9�3�����Ko����_�����<!D��Olb��)��MK=�h5�~�WS?��B��W��--�C��5�x�sg�YK_��'�:���y+���p�!�\B!DW��u1�F>8�����8z����M�2���.�Y���Hu�rn������ou
��5=�>m�I
�0:��x{O���f��xQB����(C���g$�KV���B����YpGI@�����z���[�p���L4o��6��WW�&-���$C0����t�C�����`��4�u�6v�La�o
u.lV@���7��T����fr��s�`|��	]].�\�����X�>��]������'���1���v��?@��0����O����o|��u+��s�}��M��Z1��-�Uu��?�bB�v%�(�t�FU���i�������%������t���
I�%u��.�x������r��
��U�_U.n�0�/X��LK��+.���(�9bm?�O��T[������7L�!B�5��s4�}�����HwA���� �cU���:}
���P��8��?\^m���y>�1"�B���f����jn��F�;BD�����m����M���k��x�M�N�.�@���N�mn��~y�5��s�`=]/�N�������N*�zEB�+���3���������1d�����I;#�3!�����Bc��t7.����UW����� ���S�Jk��!�+#�������BDL�x�h��0����;�yj���Ss=��X�j�p�pp��������0���d��d6~��?^�P�"b�\���[0Y����I��5���p�)��[B&v�������{\����0|�-hk�ofAWN.�u�Gp&HOf6K=j�-b�"�����L`(3����6��^!���x�+
�����,�6�����������d�s9��������x��2��~�&L�>fkE3�3�l|���3�[Io/�L�c7c�]��[����&^�?�9j����"���j5����<Qw�@V]��ys�������C�^��k4:����8�CmkJ��)�h��f+�k�g�.&�]�c��JQQ����-V�m����53���O~��������������k��w'�KS�Z���(,R([�+�R0�13��w�3����O�B~��Y��c&�6���]�	!�@��(���cL��k/!���`Q��Z-[��3��>�jU�,x�������V,���u����=uZ����6��F�BD������|�a���i>�����V3�I�`��@�q�\6,�a��T���O�eW��23�3s.�t*���� ����)���
!���"��!�24Q!��nS���8^^�yY���6~\�v����&���;s��R�a|F?^��~)�t��W�M!�����������^���������H�F��$9�B��T�5;G-�5$7��B���nS�\I�'�A��.T8�q+?[��l��CF��J=�~�3L��������z\������0tH�(QY�����;�j2��������r��!���3���qS���"�!�pl6x�D������^|���n��Wpu5+O	[\�<>huc4�zmx1*�����}�����~�eg�|y}��������	L���D��!B�nS�������0>#v2����B���Q����Wk��5�S�.	!���f��z���,o�����W�W�������g�6w������0�����8[��OmE��9����L/if_����>n��������4�wN.	o����
��{q|�]��j������aW�l���u�j�	
v�gs��7v�\����}W��!DT�@�"l���?������I�Rp^!",Xu�^(uc��S�����>�:2�<Y��{Ac���W��bvH]����zihP
F��v�
�������f]����a

j,�����T���Kq�/����?.hcj�f~�'�%?���\C�a[��{�*D�����#�.!DX�=6�?���c�uX����cm�������J�FO�]�����W���������XV�>����k{�������<����{�y�������U��PK]��W6�/�����u{g���j5��!Tu�U�m�^moK���/?-����r�\������6s����H��V�EZ^(��.{����a�B���@�",�Z��%���#5��A����w��v+K����>�.�k`�cf��iBQ������k��u�C�c&��k<a����Z��31���=�&u�j����nS1>�������&�����Zi�3��Lp�^��:�A����������.�(��tq���wu��>gLv����y��U_U�A!Dl�b�B��R{l���Q�%�%�����{����N`\������f��G9��]'_�3�(�����<�`�%�c����:'�vVh3)�L�}wa�����3���/'�[������]�l�����!��������>]uU��7�|�P*���gK��3]'��^0�|��S��*	�
1I�K2ZG
���C�,�]B�(��&NR0�u.��F������1�����m>+���O���`v;���r
-��s��J��M3h})���K� n]�\�]���}W����5hkk�;�?g�WVW����by<��U��BH2tQ�������=CP����p�10)Ml]��])SX�[F�������a2����'����N��II}�z����X����k�i���E���D��::���� y\����k�������31b�����6o���:L�W�gj����>��#�����^^��5������Q���,��	t	!BBIHGI0�:�V�(���HK�L�
V��N��W+����Cj�����ROT���Z���un��+4��p��Rjr"��<��C�h��gZ"����L��~��;�����Y�m�O��x���R�i��~(����W�9tH��i>���EC��������T|�w/��v��H�c�;	�	�I]B���jM������(�)m����M���k�s7���KGZJ��c4���T7on<[���"��by|�fOG�+=W��
���Y�m@e�]q�PK3�x~���u������Q��Am��-����8���s:�YF������#���� 8@�������m
��~9L]�P�]B���W�(@/A.!D�i��0����;�yj���Ss����3VNwp�a��`��/v��ys�A�Hj��x���>Ds�����@��+��L8�s~ia�zvy��v!���+�c��x�W�-C�edz�32��z���yz;+4<Y���r�]�B��%�
MK=��Dw�
������b�v3r��~� G����������A������V����*
�������
��7�F��]����B�M�_9pjif������x�������Vb)�O_^����`()�s[Ss���|�\��O�h���|�����	�B��Q��c�c��>vm��#�0��Vt�������]c���;)\����^` IDAT�]��o�rmS�%M��q00��|�;���y���������?�#�����C?��k�>M{q������w��#����t������X��������OmM��q��
q�X��um�^3p��D�k��H3G�����1\q�>�]�B*��70�� �CO�F�G��s�����!�r<������%%��on��M�q���n���Z��h~��=���o��:������b����3|�-xM&N}q���\�y��d���Z�����@&�]�q��<e��?��5 ^�'$����vq���HwG��!�_!�5S{l$����u���Bq�f�)<��
���w�q�{7�;r���M��[�c���W�\6�u���+l���`���\����1��bQ]�z@���j�4XT�|� ��Vwx�����
	t	!���c#���9��[�K!�����
�]����V��j�n|��E!�C�d���df����s���,

���b���bE���u�4#\������4aF�?���00��B���#���xt%ZG
C�����]!��Zu����P�f��
�_�%�")����(���n����>�l!�\�h,�Ao3#��z���m@v��{���Y���>_���6���6�_�����N��������!D_�;BqM�c����3�����Bq	���~�UW�d�^�������������5����Us�����&��8ikkHM�3�����o4�T !��-���V�����|a�������9�nS��SRFW���:������bB���cC�������f�$A.!����Z5?\����>4�#�e���y�����
�M>�&��2����	H��P����`Q�\�XP�c�b��=�������n�?���������Rw`�����
��������*1����4�������*D7}��@1 >/F��	o��3�*%�%�=������V�u��U��kx�q-v���.Tx����F��RO�����Ok��n�?Y��nW����Z0� #�3[�������4�}�����f���'#�����&d5�D��m�@��UmA���m�L>�(���\C�E��7��{`_�?[m ����T�������������LZGM����������5dE��B�:j}gN| ���`��rM��7��\��%��n��{����i��|�a5���������u��������Xvuf�;xM��B���xv��3��a�=Y�\K�������-��+dd����x�W�yyC\��	�o�3�dX�$�%�������W
�3U8G-BI��5�c
������Op
��?�^�W��{p�ds	!D/ddz�����>��5���������k��31����/��S��PwX�Q�n���_D�����pdd���z�zD��h��A�M��

if�����J��C��vVh0}<������l�6��\���iQ�1&�@����l����oE��&'�~�K���s{h�.;�rp>	��������:^J\k=�!�x�������'���aI	�i��l��)>N[[����6����uj��>^��������j�����:7��c33!iy��2��6��_X�������aZ��o����-�y���r�nC�l�<g���eA�?��z���6�'���T�^���K�����!���&'F�BD
)F/D,rw�\e����J=)�d��4��c���i�O_�-�u~t!�qki6[�\BF��?ow3>�K�E�u��s�|w��A.CI1����ow �RS������f����>~�����u��?����j5��s����P�l���//��k	�}��@�8	r	!D�H�K��;[E�G���H8�B`�W������c�h��������B!B�#�u�T/?*���`/��n��|A!���8�mg�l.|�\��O"���s�CF?<���u��oO�����a�a(Y��\I�H�;��>��Yy
��v�|��B4R�K�~��`�7�������l��V�W8wR�[F-�#�"r�&[��"��������LxM&��WF�G���\T6�?0��������J�A.mm
�sg������'#mm
��b��/������aK��i�dR�J��H��.d�w��X���������1���vdnx�|5�@`��sUx��~���0��9�dw'5�"��5�2��F�����Vy�"��~�����,��'C�����,j�
c�J��k#^l�'�a_��S�v�L��^���ZM������Mjt	�I�.
�4-��7���d�����"�Y�O_�����r��$u��BD���3�����Y�4���3\��b*v~>^�'���gL���CK��_��k2a-})��X����Hu9��P�����@m��Z5/�����:�LL`��x,���"z��E!����&�p��U4�~��������q����_M� �]B!����eZ_����D}N,�X�������b��/�:2���5xM&N��k2a���{*������o~��Sk<��vC�,@[[�����
~%��h�1+OaV����

�������`Q�`���JO�{)��']B���Q���Q{:g2|���24-�h5��gn{���N�o�z&B!�����������$�!���Y<]uU��rYj�%����o��4��������V]����cK��{f��_��}9_���H�_��T��h4+O��bl���.V��H�.!DT�@�a���L������J���Y��e.�6�������=B!������3��//�tW�����]���f��k2q�l_��W��3@M>~�����.�gxi���7W����8�sf�;���Fe�Z�������m=�g�����8�jCw�9c�X��6��QFs [�H�@�!�?QF�G�H���?�y��1f�$�q�Z�m���9?�P[B!�-�����3Q�l�W��tw��7��ix2���"�b�&�#����2Ofv�if��w��*�e���6��l�����_UA�
S&&��B���1bg��'���3]����K�{�D�c;��h/���w��U��D��2���"iyA��"DT�@�}���p�����4�tg��;����)����p
���K!������P�7�\�k�K����Dj�^�-)j��������M�m���?[����.^(�\��UW1h})C�G_FaG��-�'������Yy�3d����.��;"�!�����
��dz������=6Tm�������b:�
��a�qv��@�-��\����%�������z�����@�f`���6��ikk����6[ #����%�����~����KC�~R���7o�x���>~y}��b0����k@g��3���'3��KIMN�tw��2����u��t������@qxwr.���p���AIL��B�X�//����|���&���BK=	o�E[f�%�`��������x-�Wk�K���a~���`Q��Z��������+����d��]�=6�'6�T[�����q�n�!v��i����"�(�b@�����h,��K1������T�2�M.C�O�PR��
/��nVk��@�U[[C��Y�4L2Z�/����6f�)���-���O�%*k�	M$�%4���A�/v[�T�0�e$������0R�93i'�3��l.!��/��7��������e��[�m�5ov�{#.'0�b���nWI3���9�mg�����>���j���]u�sg��}�l���Z5�������g)�'j����3�X�����F�.�k��#���a��$����8�����t����kI��BD����j6��%
�
������������&\�>��7q��!e���}l
��u�n~��/���N0$1f�D�����$�C�:����O��#��P�rri��3���f��lZ��/����mV������>���V������������o��k��J:�,�e��
MC=�|x2�p�z<��"�I�K��A�KI��-tg��j�<���m�e�i��(�e�6�Bq	��(}�c���'�����j��h��s�;�wm���.^�40����8��������xF�M"M|���<��'��������?}�R���e���Z��5��g�b*v���� *v���p.\���~�&�7�����$A���l����oz|��&_e@1�G�^[F��GW��\I�y5�n�����R��Uv�8�>�+��3pg��������3%I=D!z CE�P{l$�~�����i��U�;����X�|[%M�G�f�$���"*)}�8�M"f
�d7.�����TW6���&���c��9L�2`�B��Id�<�{��x����u���������Su�����W���3d��N���K-��e[���6��PRLR��QW�E[[CR�����H,/�X�#=��{�Gm����!����U�����4>��G��w���'-/�PR���?����!�"(���"��H�K����98��$��X~>������7O��8�=BquX>W���6������i���wA(G3
��2�u4�`Nsq��h�G3V9Au��i<���3cW1@����PJB��F#q���:_�%���z%-2_��m6mx�����<��8.��n���~Fm�a()�s�G[[C��F�IB���r�/����4o���,��L/�v��Q�?��d�������3�������[�M��}j�+�c�\;+4=�N��'CE�uf�,�������E��t�����u�}�������s��J��uX���R[K!�)���
z�O�N
�h&g}>w���n��s ���<q��S�}��u;G���obJ�9'`�a�x��3�<���'4�����6\S�/�U�X�8*�
�������8����
�4�z������B��<�0t�d4
�_K�����H����T6+��b�1��5��N���@���=�c#���������b��\��Ci�.�[�������O����V�o��������~?���f���
%��s�E���Bj�
6����+�4s�X�X��o�����@_^��������R�K��!�.�4-���l��Z��z�'�YZ{�7��Q�%cK!b�u���FJR����y���y�Y�kX��	n,����Ih�����)}�@���������m��G�����!9���.;l�����6CGF�{a���i�������;a�t��GW��q��$=�I��Z�z����I�������!R����g�n��q���/�e�~_��GA?ztP2��;s�������~d���t���C��O^xV����;���2}:L�GR��o��z,[���'�Nvx�)�����ov.W�:��d�ud��
����?��xy��w�T����S���/���3��W;���V�047���~���=+��@��ZZG
I�F��AIL�)�3Z���6�wrn �%�"it���bu������D�/w:a��^
�3$26��4��?�Rac�����:n��'3��7��70��GY��Q�X:����3-��r�K�o���:
[}C��/�9��2h})-��p�������f`$T�`����{g�&��X\����������������$���~�X�>cF��S_�j�����������o�?_�����@���5�>WN.��2&|�1��9^2�|L�����S���o'T�r��g����V��cs������;�w�Kj��^��S]��
���X2���s�$������Wru:�����t���H��c3��X����F�_U����g~���`���e�	8��[���������$_�I]"*�=6���!���������g�c�B�����O��GF��B!���y��]5M8�gh��pp����]�v(��������nLs���N�~Ch=������Ml��~W��SWpa����"T6[�������h�`��4�z\9�X�m�qH��R���*04'0��EA���>�����n��~}y�u/�5�P���/X����s�������YQ�����0�b%�+9�ek��u������������n�=uZ���������&������V���>�L_^F���&��E�_�����'�������������XV�������������c(Y����������{I��B���DTV5u���|��@�������-!��4���M��~���$��������^�p�����f�Y��])SX�>c��r�G
�6V�{l�;��79:f�������1m=�_�v�w�����'H��&7j�0�o4/Y���
��N�����p��Q�l8.b��uh�g����}h��f���dL1D��,�O��o�8�,�gK$�rr�j�J�t��ta
�HS��(i���2��<u��/���v����$<Yh�w[Gc��gJ
���X����q.\h����%�E��P:���[pOm�1t�Z�f�XY���X�o����h$�%���qLG�%�����Q(�u�������7��CC�\B1�i�O��H�l�[�|J�8���_�I�������n���b��-�;5��2�������]�oL���l^�gV<����S����s��.��Cx�F�����k2�XU���B�������"iy�UE��;����dBm=��h�0vmG��W��Z~��@�Hk�l4�z���i��B���5���:��llkJ�>���R�a�/������{�5o6�y�����5vn�T���}{h���}MI���mfP�/�7���0����X������n���������%�Lk���*�/D���|2�m;�<��U$|�q�ZR�(���+8�/�y>}Y`�D\R�$<d?������%%�Q����6�Gs}�6�v��PW]�'���
��V2h��X�m�6�X�20�E���7���h�������"������b�����v�4�U4�r,w���Y�)sf�oMv��@mm
K} ����[��p~ia��[�8gh,�.|g��n��`C��������dt���i���W�'s��2����	��q���n����2���A�9����a��\B!DT���6qj��[1�p
S����x2�I���my�3RDt�d��6e��}/�]�j�ME+��Y����=um����-����������s��fc���8��3��P�^c�'��Y�QG����{����B1����������5�c[Sr�u���5�7o
���������E�����Q�|�`�������.���������?	,s�.�=x^m��!7>��� ��B!�J�Cm���:���E�{�#g�b�".�Z������r��s:g��t[�<wmY�A�����	CI1����o��m����bN�V�*�����m���]]goT��������{_��C�j��8�q4
�,YpUnj����������Z�f���@]��c#��4-�x�L�YN�`�A �=x�����6�?u�g��N��9�����pk`FD�g|udw	!���V���9B��O[[���
]u��e���d�����_7
H��t���Ok�l�>���M��v�"���8�mg �l������D��#�_mM�7��z�������ddj�	!�c@����Q�� �:!)���9,Y2�}����i��:����kh3d2���OH�}��:]�8C��$���q
��q���{�&�(�"�I�K�������+q�q���]��Z��/��tY�J�p��mx����f��<�\]]����CI1����-�~i!�9wNn�n
�N��q�������������~^GY��l>��3�_�+�������CB���xdZ�'�]�M�m���q-��ZYjO�4�m��8G-BIL�6��kH._M� ��D!�B������y{%j�-��c��<��IQ_^���L|�~l_w��V���>�[=Q���]��2�S���Z��jkz	!zg���{�r0�f
����N<y���Wo�>3c�-���cC�Z:iZ������Q�W��5s�h
�����8r� IDATEIL�)�3����@�����u
��qS�E����t��2\!�B����}�����������e�?>��PW]����3�z�_`}`��?1��

�o��-����}yY�Yq��7`]��4�����\6b|
��MX�25�����Q���;>/<f��&����wG���$�c��8��#����.�������ZY���������
*��N��:Q�����[q�R\���V�^7�6n�������y��<�a��W�b�m=���vJ>xw��p������{�6�}��v��9����Uj��_�������w�������Ki
�����������iw��yI{��+��B�?���!���5�8�m'I��3����6[�L&�/�2h})�UE2z��p(���}y^�O�����o��lVZC<4���o����AQ����������~�}����4�x<�;�:�}]���{����3��:����7����������`���,�?xGs���)_����L����w��O�L.e�f\ry�J��^����N0��~��rm�x}^4O_9:�B��I��m���@��)��v�~��v�����v��E`i���_�k�7=�c;]�3�k���d8�1D��|��/(��F(�iS|WXS!D��rri:x��pF�����#�lVN|���'3[f��s:J�9f
��H��]<)c�������������3>�|����o����.36������d��\�f�_���7.>|<����o�2�>/�����:*TW|>�W�V��>zz����v���C�C�������x���?�W�<y��W\G���8��v���t�����m]���v���{A�O��S�`��� m����}8�!���u8#>��j�=u*�����3(*�=���W�_>W�s''���qh��y����gt<T�K��y�s�����c<����9=�sf<z[��	�m�X0�IMN��5�A������D���������'���aI	�i���pkS|���F�1O���!�9�Rw���_n��br,w�S&������1���|��c\������x�fcn�93�3���m��A���}��O]<�B!�"�<�N	�!D��<V(F���g�`���8y���}���
����B!�B!D�
��.�f�=���YM������e�X���	!�B!�B� 8�.@��z5#��B!�B!�!0`�.
!�B!�B��&�.!�B!�B$�%�B!�B!b�����"�	!�B!�B!�J2��B!�B!DL�@�B!�B!��	�B!�B!�1A]"*8�|��hP"���4R>��U�N��Y3u�NG�#�M�B
�^ae�%��mr�r�r� ���t"��H�3{yo������&����#��~�m����e[e�0�53��9�}�s':?��|�AuBR
�sX�d8����B��?��U�{}>s�t.?YQ������QA;z��=��Se/_w3��USQ�D��'mZ6�{,�
��+��m��8���2�f�>6���4�v������l}���f���0��9�;m�*rn�@�����A>���2���=]#�9��M�~����ivjHk&��� ����U��B��������w��������_�.�����O���o(|��m6��q�������|7�A�cU|hm_�q������r(����O����m6V:#��~�x
������>@�3���>~Y1�����bWCDz�O��]���4������s��1��X��w�J���������G�p��|kx�o���?)������{�����������rn�@�����A>���2���=]#�9���|�m�5�yh�Cl��=��d��w�>����W!za`�?g�#w?:�qiz�cn`���qW���+{��I�����0����)��t<c��|�y�{�r0�f�-����zR&Ob�<=�o�~�V���X9�-v}!W`�9���L?�����
G���i�����1���r�gl3����n����_���e�����oI|��	d��1���y�>���)���&���c��9L�2`�B��Id�<�{/���:���������h�x��'�&r�h0~cG��|�~���s��3D��5B�t�p
�]��]��K���.p�k�k���k���t�p-��F�N�c�\a�]c�1	��s��0��q�����W!zc@�<G�8eH����L;~��f,�#��~�@�sY2�K��I+g�c�����f;�1].�F�OA�y�K|�x>����=���{�{���we�<���l��uar��a��e��|MO���\|}����]�<���f�!�w��i�2r0�u�g�BA�&�<]G��}G3
��2��C
�4'���V������x(�p���9����sv��?�����8������,�
r�=]#\�g�������_O�F���e����K�.��k��>g�5��4���5pjgG�(��i�8Fc�����U��B�;��p�1�cR��:�%
��`��0�\��=���g�����wM`z����Bk���~5�%V�o��:�N7N����9�<v��G�%������8��^v2}E)~N+�cVo����I�76���
��u`w_p������(o�����`�|���8q�{�n�`�<���<x���i�;p�9O��j�~���;������s�����UTE��;���)
#��Ssx��.*��F�7^a�O?�����}���U����!BD�B��k������*6��������{���;�]��.������A����(R0ES�	��&��KjI�����i��55?����~k�7���	i5ii���!c��JFz��@��7�u\�����N�������l^�gd=�=����y���s���_��3e<�9v��K���0�[e����#0��\Dib[��Gs_����,|��l;��BD���.t
I`�t'�O�T�s���>���;����� d�W����	p���W|�����N��L#[������R�z�E�� ��N\7�s��c����9�5~��0$L���3Hq���|�<����r�lw�=�����W�4o���%��U�5~
��Z^z+���?`��l��E���T^��-��:g�?�2���UF�i�}�gyi}3�w�fe\'��p��K�����:g(#�,��������C�8��|,��~VK���T��
��/u���4��-.N�7=���f�hY��&`��{��`>i���w8����[=��`��$� )����,s�%�ab&�"�������SM�����_n��
T�Jc��#�F��`�-l�
yr����4�r���&�"�j7�-sb{���aL���&F���&����
�c"_���~��GKy���Y��e?$�"~)���o������Ch�	������}y,����|���r�@�{�=7��!cIa��b����\����F='������eF���B�fn��>g(#�,p����]�!;��N��<�:?�����BD���.te��j�h;?�Z����E�������wP������g��R��<5g2��O��vyO�e%�1�h��f��"*39��}uk�U�w���������j���*��\�O�����[�AZV]M��zh>�������d=VD��y��l�m�fN2.��s�C��x���\����z��h;o��1Zh$���yT<�o��o�Z��}�_#���h��:g�XRF%7���]���*�Q6��=�Q�5��!��K��n��>g(#�,}}\3C+u*]W�H4���.��`a�����4{-z�Z�����fi�v�,Nl<�	�7�����@k�Oh�2�5Q���-.|P��
�)��
�k�<4�Rw;�7���~d,/e��Ky����l�������`��d�>8I�=4W�=o2�q^�BgK�~��W�Q�w��2�Y��D��N{-z��a��}L�g`�(��E[�1��
��I7G65�������Wg����!8�\=��v�Nr�4R���\�SM���o��/lc<7��!cBa�*#��w����2����[���A��1�]�#�UF�����p�ix<�4V5r����&�_�L������+D$�{����u��m|��7�c8�(����n=#Z�N�
6�����S������3���.������$������y#<�pR�.�����>��r��(p�$t��w�����h��������}O<&13����O��5�,`i�����I�x5�T=�p����py���|�+�A��"*��s�z���K��^��X)�T>��������n�oMe�����K�%���;T��Q�����k2Y��(�op��xn�9C��2�gEF���bJ6���������+��s+�����]�7v���9C�z����\�KKN��������bJ��u��D�_>���O�{#DDDDDDDDD>�/���""""""""7T����B�����������DDDDDDDD$.��%""""""""qA�.�*t��������H\P�KDDDDDDDD��
]""""""""T����B�����������DDDDDDDD$.��%""""""""qa�xo��?��:�=�[~@����1�%���:�����k
��a�Y�����xo��� u+_���~r��Y�xEDF��]���M��M�c��f���x�}���w1H3i�����xo���p;;�rb�<^���m��GDd���%�6�}c3���)�t�2�_6��
R�� +�$}�""r���T��D�CwP>�����T�xo�������`����/7�D�@O�.J�(`A�xo��-��%�d��f���g�|�"����Pj6�]=�
��7��������g*t�8�8��wT��X����/���������y����[���g�.W���l��1��b)O�;�|#�-� {�d�_��.ce��`�r����jC6����������^�'�@��9������X&���z���og�N2�P�"���[��<W���l��|7�$�������[3��>k2c�Cg�P���N���3HL�������uu*��g_������S�����`�(}�~J�c}�0�S��vZ�[�&�����`Ef�����;�����c>|~0�.f}7��.s�8�H�T=~t���?��eCV�{����N2�����&���
X��O�+������]x��������b�����8�7?=}v\Y���X�w^s��'������/���$����^e6)��&�q{��w�u1H�4I�;�{V��qG\���g��&|����#����s��?���R�e
��6�x��2L2�S��R"�m[DDFC����:���K��j���]tu��eN���E�|s�/��:�L��F��L'YK
x�2���sc}��w?�K,"��Qv�����0NJ^������ny�wS�P
�����=3�wk�*�����r=�|LWwR�������"��\E�{aw
�z���P�;��0������H�lW)��@��������c5Q������5�EO�E�m��Q�Q.���3����^X8����e<e��S�K��l��>�5c6�v|��8,No�����c�3�������~�^�����U�u��{IO�k�����u�i~����y��a"��3�����
yfS�@@
rz�>^�k0��E�:����
ul��u[s�B�;�G��u������+�q�{8Sb�=m�l�l���<�k:i{i{���g���~R���V<���a.��0[vA�+E����&���.�[��Fi������L����m��Sy�P�@@�6����A��4J�z��f����t��V)k����~�x7��~���RJ�n�'�����}���/LU��g��vzx���H5-�����9����P��-��x�G�tey(%���Z4�QG���am}��y��/@��Zj�r(�ZL����A��cl�b������O����7����e�>Nl;��U�fw����q���&D���v~0�~���������Q���g�e���TMOf�C�R�m�	�����w�]����D����������<���^K��b�a��aNy?_k��n=U�kyir�K�}�9���p+�^>����y��e�	`���r�'�����d���8���T�r���9\�E���b��e��L
��j�`�w��s��s��z����5��1���vF���MYVDY���z��Y�
�v��A������C�8��X�����n�n�=H���qU���-#D�������0���5���1���� "_p��E_A���&�	&���9�d����L��M��Ef��e��Sh�83���u�#
�7;��ei��;�X\�#eN��VN^X����{�<<��%nR�����M���p����E����$�p�������|���d|�M�;��RN���x�3([7�Y��.<+�(�
r�w�x��%9HIw��lv&�:II�������9R�Ihn>��Iu�$f�Q�>�Yt���c�f��k��-�������$q���%�������8$R�Q6���_4p.����9���ru�
ZN�Z=0�0�~�����������&��F��|<_w��Nf�O�(���������G��0IE9xf:H�� %/��m��r�������[N:�t��b��L���R��{S#w���+�IJ���H���X����)���o��q��6v��-""��rg��Q7�v�����i�.v������@,���K�Q�0��t�G�S��0��}���m����e��E��^���MiI3���s����=��n')����;I��m�~������EjyK'�J2I�f�����v�w�#�\u����uE���������y�#(�16$�4��rw�L=G2%�_��o�����a�2B,���1��&2i��S�CAD��T�����Lj�������X��~�&&M1[������i`B��Kg�
������-��B{����n�A������3�R�0�5�#�zBQ�=�E?�<��%�Z�0�M��� s��_�#���bD�i���y���v�s�����������f���G(!�����f�973���-r�� ;'x���Gu���
���h���"3��O&�
=�KC�3��hi� +����N���Nu�1x�.���x����M��}�����E�;r#�d�����_����P����[A2��X��IfV��60
�
����""2�\3���Nh��aB����2�1������Af�	���k`���,{�{�gS�Y��p3B�l7]8��s{���&��{������b��i,}v6�C�������<����` 0s�6�.=	a�����1��������]AD��t���/�Q���&���6��_>�e3���5DB�^BX���-u��~\�$�����pnK+�	������XW�����@/W�I�k���i�^�\���Qis��@X����o�y�?\�]���4���L�6��P8�m��&�>�	XA��.{���{	]�^�s�;"�-�����������=��7�2��,��le>�".tR��e��$�����3MT
s��pE%y�^�x��xr�mU��Rc��1��cm;���z�m�Y@R��Q�<���z	a\�o0�M+0F�(����-w6r���8�Z�s��0�t\se�&����?=#�r�k�SF�/0���)x;3�"�����z	�;{��H�f�x���������7H��R����������������Mn���D�� �bY����h�(���tN�T��R@�
��W�1��HU�%R����z�,�F��$Y���\��l���o����L��Y�v:��"GqM'��Ex�~?��?�v[#/��'w�={;�%T�@��Bcu�>�fu-��,�)$���u[DD>F##\S,
YA�``&���Y�QI��+��JIDAT�&:�aa];c���J/��<{k42B��/��{��F��A��c��M���W}]q.�K_&�1�e�2�h�������� "�C�uQ>�F`���b��P�E:?K�
��6
��MW�%B�����A�7����bB�s������W����d2s�p�K��0���13����hJJ&�
]~����E[���������1�|����;�����LfuS���ty
�����%P��0u��`�^mw������ 1}������$#���KXS����e�W�8�bc�O�{����${q>�,w��"su���A;���n�27���Y��^��|L86�N�m����p����h;kA���#$1�Y�i3�mf2�h��?��Pc'�����C�����-3�����E�?f��F.�����t_}��?��3l���N��0���Xd<e��R�K>�Rs'��v�?nB�V��q��G����9������c
���c��f��WM��;e��\K��N.|�w�������w8r[�������Aj����h>o���������5��<�������:����}���W��~b�k����9mwS����zg���g8��0��}�>	�=~��`���x�� �����F��\����Q�4B�5������=������^'s��}>}�������d#������@=������u=�"�A�S����s��\p�T+��vc��&�j��8�����L�g��\���ur���.�4�g������y?����p������e1�N�m�g��0���(G����?���x��A�}3��C���F�8f���c��:��C����a;����
������_���_4��[@��.lv�O���r��#�>�v��7���������=/���������e�3B��YVD��r���5�Zg����"�)#����n]�����y,m=�����v\33(YY@�����m$��0A�����w���?=��~�����1*h���RV�����6	�&)��,��?�3�FC�������aGy=V����i,�TD��n�E���Y=���_����-B	&)y���Q���|����d�����]_C�?���$s^>�W��:����a^��[��,J��)��4/?���n������,�Z���m� 6w2��O��l���sx|�A��&v?�@O����b��wSQ�zO�l�ms�?no���cX����ru��pQ�����F�W6����a��;���7�9��9�?bgY�&����:��L��R<��?v�m���8���s����������"�p��X1��E��������x��R�T��m5�h��BV���6G���]L���������T��d���T�>@E�>��8�F+;���gNg�������hg�(����'����x�������yrw��d<e����O?��������n��T������%"""����\X���R6����""2>t������������DDDDDDDD$.��E���%""""""""qA�.�*t��������H\P�KDDDDDDDD��
]""""""""T����B�����������DDDDDDDD$.��%""""""""qA�.�*t��������H\P�KDDDDDDDD��
]""""""""T����B�����������DDDDDDDD$.��%""""""""qA�.�*t��������H\P�KDDDDDDDD��
]""""""""T����B�����������DDDDDDDD$.��%""""""""qA�.��xo=�����IEND�B`�
#22Ranier Vilela
ranier.vf@gmail.com
In reply to: Alena Rybakina (#21)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi,

I finished writing the code patch for transformation "Or" expressions to
"Any" expressions. I didn't see any problems in regression tests, even
when I changed the constant at which the minimum or expression is
replaced by any at 0. I ran my patch on sqlancer and so far the code has
never fallen.

Thanks for working on this.

I took the liberty of making some modifications to the patch.
I didn't compile or test it.
Please feel free to use them.

regards,
Ranier Vilela

Attachments:

v1-0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patch.txttext/plain; charset=US-ASCII; name=v1-0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patch.txtDownload
From 56fba3befe4f6b041d097d8884815fe943fb21f9 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Mon, 26 Jun 2023 04:18:15 +0300
Subject: [PATCH] Replace clause (X=N1) OR (X=N2) ... with X = ANY(N1, N2) on 
 the stage of the optimiser when we are still working with a tree expression.

Firstly, we do not try to make a transformation for "non-or"
expressions or inequalities and the creation of a relation
with "or" expressions occurs according to the same scenario;
secondly, we do not make transformations if there are less
than 15 or expressions (here you can put another number, but
during testing, already starting with 3 expressions, the execution
time and planning time with transformed or were faster);
thirdly, it is worth considering that we consider "or" expressions
only at the current level.
The transformation takes place according to the following scheme:
first we define the groups on the left side, collect the constants
in a list for each group, then considering each group we make the
collected constants to one type, find a common type for array and
using the make_scalar_array_op function we form ScalarArrayOpExpr,
if possible. If it is not possible, then these constants both remain
in the same expr as before the function call. All successful attempts
(received ScalarArrayOpExpr together with unformulated Expr are combined
via OR operation).
---
 src/backend/parser/parse_expr.c  | 289 ++++++++++++++++++++++++++++++-
 src/tools/pgindent/typedefs.list |   1 +
 2 files changed, 289 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6d..c5f58aee9ec 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -95,6 +95,293 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int const_transform_or_limit = 15;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, Expr *expr_orig)
+{
+	List		   *groups_list = NIL;
+	ListCell	   *lc_eargs;
+	BoolExpr 	   *expr;
+	const char 	   *opname;
+	bool			or_statement;
+
+	Assert(IsA(expr, BoolExpr));
+
+	if (list_length(expr_orig->args) < const_transform_or_limit)
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+
+	/* If this is not expression "Or", then will do it the old way. */
+	expr = (BoolExpr *)copyObject(expr_orig);
+	switch (expr->boolop)
+	{
+		case AND_EXPR:
+			opname = "AND";
+			break;
+		case OR_EXPR:
+			return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+			break;
+		case NOT_EXPR:
+			opname = "NOT";
+			break;
+		default:
+			elog(ERROR, "unrecognized boolop: %d", (int) expr->boolop);
+			opname = NULL;		/* keep compiler quiet */
+			break;
+	}
+
+	/*
+		* NOTE:
+		* It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		* a list of sub-restrictinfo args, and rinfo->clause - which is the
+		* same expression, made from bare clauses. To not break selectivity
+		* caches and other optimizations, use both:
+		* - use rinfos from orclause if no transformation needed
+		* - use  bare quals from rinfo->clause in the case of transformation,
+		* to create new RestrictInfo: in this case we have no options to avoid
+		* selectivity estimation procedure.
+		*/
+	or_statement = false;
+	foreach(lc_eargs, expr->args)
+	{
+		A_Expr			   *arg = (A_Expr *) lfirst(lc_eargs);
+		Node			   *bare_orarg;
+		Node			   *const_expr;
+		Node			   *non_const_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+		bool 				allow_transformation;
+
+		/*
+		 * The first step: checking that the expression consists only of equality.
+		 * We can only do this here, while arg is still row data type, namely A_Expr.
+		 * After applying transformExprRecurce, we already know that it will be OpExr type,
+		 * but checking the expression for equality is already becoming impossible for us.
+		 * Sometimes we have the chance to devide expression into the groups on
+		 * equality and inequality. This is possible if all list items are not at the
+		 * same level of a single BoolExpr expression, otherwise all of them cannot be converted.
+		 */
+
+		if (!arg)
+			break;
+
+		allow_transformation = (
+		                        arg->type == T_A_Expr && (arg)->kind == AEXPR_OP &&
+							    list_length((arg)->name) >= 1 && strchr(strVal(linitial((arg)->name)), '=') == NULL
+							   );
+
+
+		bare_orarg = transformExprRecurse(pstate, (Node *)arg);
+		bare_orarg = coerce_to_boolean(pstate, bare_orarg, opname);
+
+		/*
+		 * The next step: transform all the inputs, and detect whether any contain
+	 	 * Vars.
+		 */
+		if (!allow_transformation || !bare_orarg || !IsA(bare_orarg, OpExpr) || !contain_vars_of_level(bare_orarg, 0))
+		{
+			/* Again, it's not the expr we can transform */
+			or_list = lappend(or_list, bare_orarg);
+			continue;
+		}
+
+		/*
+		 * Get pointers to constant and expression sides of the clause
+		 */
+		non_const_expr = get_leftop(bare_orarg);
+		const_expr = get_rightop(bare_orarg);
+
+		/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table (htab key ???).
+			*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, non_const_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				non_const_expr = NULL;
+				break;
+			}
+		}
+
+		if (non_const_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = non_const_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->opno = ((OpExpr *)bare_orarg)->opno;
+		gentry->expr = (Expr *)bare_orarg;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this rinfo!
+		*/
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	else
+	{
+		List		   *or_list = NIL;
+		ListCell	   *lc_args;
+		Node 		   *result;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation. It's been a long way ;)
+			 *
+			 * First of all, try to select a common type for the array elements.  Note that
+			 * since the LHS' type is first in the list, it will be preferred when
+			 * there is doubt (eg, when all the RHS items are unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (OidIsValid(scalar_type) &&
+				scalar_type != RECORDOID &&
+				verify_common_type(scalar_type, allexprs))
+			{
+				/*
+			 	 * OK: coerce all the right-hand non-Var inputs to the common type
+			 	 * and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = get_array_type(scalar_type);
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1; /* Position of the new clause is undefined */
+
+				saopexpr = (ScalarArrayOpExpr *)make_scalar_array_op(pstate,
+												   list_make1(makeString((char *) "=")),
+												   true,
+												   gentry->node,
+												   (Node *) newa,
+												   -1); /* Position of the new clause is undefined */
+
+				/*
+				* TODO: here we can try to coerce the array to a Const and find
+				* hash func instead of linear search (see 50e17ad281b).
+				* convert_saop_to_hashed_saop((Node *) saopexpr);
+				* We don't have to do this anymore, do we?
+				*/
+
+				or_list = lappend(or_list, (void *) saopexpr);
+				or_statement = true;
+			}
+			else
+			{
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		if (or_statement)
+		{
+			/* One more trick: assemble correct clause */
+			expr = list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, list_copy(or_list), -1) : linitial(or_list);
+			result = (Node *)expr;
+		}
+		else
+		{
+			/*
+			 * There was no reasons to create a new expresion, so
+	 		* run the original BoolExpr conversion with using
+	 		* transformBoolExpr function
+	 		*/
+			result = transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+		}
+		list_free_deep(groups_list);
+		list_free(or_list);
+
+		return result;
+	}
+}
 
 /*
  * transformExpr -
@@ -208,7 +495,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (Expr *)expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 260854747b4..01918e6aeac 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1630,6 +1630,7 @@ NumericSumAccum
 NumericVar
 OM_uint32
 OP
+OrClauseGroupEntry
 OSAPerGroupState
 OSAPerQueryState
 OSInfo
-- 
2.34.1

In reply to: Alena Rybakina (#20)
Re: POC, WIP: OR-clause support for indexes

On Tue, Jun 27, 2023 at 6:19 AM Alena Rybakina <lena.ribackina@yandex.ru> wrote:

I learned something new from your letter, thank you very much for that!

Cool. The MDAM paper is also worth a read:

https://vldb.org/conf/1995/P710.PDF

Some of the techniques it describes are already in Postgres. With
varying degrees of maturity.

The paper actually mentions OR optimization at one point, under
"Duplicate Elimination". The general idea is that ScalarArrayOpExpr
execution can "eliminate duplicates before the data is read". The
important underlying principle is that it can be really useful to give
the B-Tree code the context it requires to be clever about stuff like
that. We can do this by (say) using one ScalarArrayOpExpr, rather than
using two or more index scans that the B-Tree code will treat as
independent things. So a lot of the value in your patch comes from the
way that it can enable other optimizations (the immediate benefits are
also nice).

In the past, OR optimizations have been prototyped that were later
withdrawn/rejected because the duplicate elimination aspect was...too
scary [1]/messages/by-id/1397.1486598083@sss.pgh.pa.us. It's very easy to see that ScalarArrayOpExpr index scans
don't really have the same problem. "Giving the B-Tree code the
required context" helps here too.

I analyzed the buffer consumption when I ran control regression tests using my patch. diff shows me that there is no difference between the number of buffer block scans without and using my patch, as far as I have seen. (regression.diffs)

To be clear, I wasn't expecting that there'd be any regressions from
your patch. Intuitively, it seems like this optimization should make
the query plan do almost the same thing at execution time -- just
slightly more efficiently on average, and much more efficiently in
some individual cases.

It would probably be very hard for the optimizer to model/predict how
much work it can save by using a ScalarArrayOpExpr instead of an
"equivalent" set of bitmap index scans, OR'd together. But it doesn't
necessarily matter -- the only truly critical detail is understanding
the worst case for the transformation optimization. It cannot be too
bad (maybe it's ~zero added runtime overhead relative to not doing the
transformation, even?). At the same time, nbtree can be clever about
ScalarArrayOpExpr execution at runtime (once that's implemented),
without ever needing to make any kind of up-front commitment to
navigating through the index in any particular way. It's all dynamic,
and can be driven by the actual observed characteristics of the index
structure.

In other words, we don't really need to gamble (in the planner, or at
execution time). We're just keeping our options open in more cases.
(My thinking on these topics was influenced by Goetz Graefe -- "choice
is confusion" [2]https://sigmodrecord.org/publications/sigmodRecord/2009/pdfs/05_Profiles_Graefe.pdf -- Peter Geoghegan).

[1]: /messages/by-id/1397.1486598083@sss.pgh.pa.us
[2]: https://sigmodrecord.org/publications/sigmodRecord/2009/pdfs/05_Profiles_Graefe.pdf -- Peter Geoghegan
--
Peter Geoghegan

#24Tomas Vondra
tomas.vondra@enterprisedb.com
In reply to: Ranier Vilela (#22)
Re: POC, WIP: OR-clause support for indexes

On 6/27/23 20:55, Ranier Vilela wrote:

Hi,

I finished writing the code patch for transformation "Or" expressions to
"Any" expressions. I didn't see any problems in regression tests, even
when I changed the constant at which the minimum or expression is
replaced by any at 0. I ran my patch on sqlancer and so far the code has
never fallen.

Thanks for working on this.

I took the liberty of making some modifications to the patch.
I didn't compile or test it.
Please feel free to use them.

I don't want to be rude, but this doesn't seem very helpful.

- You made some changes, but you don't even attempt to explain what you
changed or why you changed it.

- You haven't even tried to compile the code, nor tested it. If it
happens to compile, wow could others even know it actually behaves the
way you wanted?

- You responded in a way that breaks the original thread, so it's not
clear which message you're responding to.

regards

--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#25Ranier Vilela
ranier.vf@gmail.com
In reply to: Tomas Vondra (#24)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Em qua., 28 de jun. de 2023 às 18:45, Tomas Vondra <
tomas.vondra@enterprisedb.com> escreveu:

On 6/27/23 20:55, Ranier Vilela wrote:

Hi,

I finished writing the code patch for transformation "Or" expressions to
"Any" expressions. I didn't see any problems in regression tests, even
when I changed the constant at which the minimum or expression is
replaced by any at 0. I ran my patch on sqlancer and so far the code has
never fallen.

Thanks for working on this.

I took the liberty of making some modifications to the patch.
I didn't compile or test it.
Please feel free to use them.

I don't want to be rude, but this doesn't seem very helpful.

Sorry, It was not my intention to cause interruptions.

- You made some changes, but you don't even attempt to explain what you
changed or why you changed it.

1. Reduce scope
2. Eliminate unnecessary variables
3. Eliminate unnecessary expressions

- You haven't even tried to compile the code, nor tested it. If it
happens to compile, wow could others even know it actually behaves the
way you wanted?

Attached v2 with make check pass all tests.
Ubuntu 64 bits
gcc 64 bits

- You responded in a way that breaks the original thread, so it's not
clear which message you're responding to.

It was a pretty busy day.

Sorry for the noise, I hope I was of some help.

regards,
Ranier Vilela

P.S.
0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patch fails with 4
tests.

Attachments:

v2-0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patch.txttext/plain; charset=US-ASCII; name=v2-0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patch.txtDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6..74c256258d 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -95,6 +95,291 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int const_transform_or_limit = 0;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, Expr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc_eargs;
+	Node 		   *result;
+	BoolExpr 	   *expr;
+	const char 	   *opname;
+	bool			change_apply = false;
+	bool			or_statement;
+
+	Assert(IsA(expr, BoolExpr));
+
+	expr = (BoolExpr *) expr_orig;
+	if (list_length(expr->args) < const_transform_or_limit)
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+
+	/* If this is not expression "Or", then will do it the old way. */
+	switch (expr->boolop)
+	{
+		case AND_EXPR:
+			opname = "AND";
+			break;
+		case OR_EXPR:
+			return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+			break;
+		case NOT_EXPR:
+			opname = "NOT";
+			break;
+		default:
+			elog(ERROR, "unrecognized boolop: %d", (int) expr->boolop);
+			opname = NULL;		/* keep compiler quiet */
+			break;
+	}
+
+	/*
+		* NOTE:
+		* It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		* a list of sub-restrictinfo args, and rinfo->clause - which is the
+		* same expression, made from bare clauses. To not break selectivity
+		* caches and other optimizations, use both:
+		* - use rinfos from orclause if no transformation needed
+		* - use  bare quals from rinfo->clause in the case of transformation,
+		* to create new RestrictInfo: in this case we have no options to avoid
+		* selectivity estimation procedure.
+		*/
+	or_statement = false;
+	expr = (BoolExpr *)copyObject(expr_orig);
+	foreach(lc_eargs, expr->args)
+	{
+		A_Expr			   *arg = (A_Expr *) lfirst(lc_eargs);
+		Node			   *bare_orarg;
+		Node			   *const_expr;
+		Node			   *non_const_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+		bool 				allow_transformation;
+
+		/*
+		 * The first step: checking that the expression consists only of equality.
+		 * We can only do this here, while arg is still row data type, namely A_Expr.
+		 * After applying transformExprRecurce, we already know that it will be OpExr type,
+		 * but checking the expression for equality is already becoming impossible for us.
+		 * Sometimes we have the chance to devide expression into the groups on
+		 * equality and inequality. This is possible if all list items are not at the
+		 * same level of a single BoolExpr expression, otherwise all of them cannot be converted.
+		 */
+
+		if (!arg)
+			break;
+
+		allow_transformation = (
+		                        arg->type == T_A_Expr && (arg)->kind == AEXPR_OP &&
+							    list_length((arg)->name) >=1 && strcmp(strVal(linitial((arg)->name)), "=") == 0
+							   );
+
+
+		bare_orarg = transformExprRecurse(pstate, (Node *)arg);
+		bare_orarg = coerce_to_boolean(pstate, bare_orarg, opname);
+
+		/*
+		 * The next step: transform all the inputs, and detect whether any contain
+	 	 * Vars.
+		 */
+		if (!allow_transformation || !bare_orarg || !IsA(bare_orarg, OpExpr) || !contain_vars_of_level(bare_orarg, 0))
+		{
+			/* Again, it's not the expr we can transform */
+			or_list = lappend(or_list, bare_orarg);
+			continue;
+		}
+
+		/*
+		 * Get pointers to constant and expression sides of the clause
+		 */
+		non_const_expr = get_leftop(bare_orarg);
+		const_expr = get_rightop(bare_orarg);
+
+		/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table (htab key ???).
+			*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, non_const_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				non_const_expr = NULL;
+				break;
+			}
+		}
+
+		if (non_const_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = non_const_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->opno = ((OpExpr *)bare_orarg)->opno;
+		gentry->expr = (Expr *)bare_orarg;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this rinfo, just add itself
+		* to the list and go further.
+		*/
+		list_free(or_list);
+
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation. It's been a long way ;)
+			 *
+			 * First of all, try to select a common type for the array elements.  Note that
+			 * since the LHS' type is first in the list, it will be preferred when
+			 * there is doubt (eg, when all the RHS items are unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+			
+			if (OidIsValid(scalar_type) &&
+				scalar_type != RECORDOID &&
+				verify_common_type(scalar_type, allexprs))
+			{
+				/*
+			 	 * OK: coerce all the right-hand non-Var inputs to the common type
+			 	 * and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = get_array_type(scalar_type);
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1; /* Position of the new clause is undefined */
+
+				saopexpr = (ScalarArrayOpExpr *)make_scalar_array_op(pstate,
+												   list_make1(makeString((char *) "=")),
+												   true,
+												   gentry->node,
+												   (Node *) newa,
+												   -1); /* Position of the new clause is undefined */
+
+				/*
+				* TODO: here we can try to coerce the array to a Const and find
+				* hash func instead of linear search (see 50e17ad281b).
+				* convert_saop_to_hashed_saop((Node *) saopexpr);
+				* We don't have to do this anymore, do we?
+				*/
+
+				or_list = lappend(or_list, (void *) saopexpr);
+				change_apply = true;
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		if (!change_apply)
+		{
+			or_statement = false;
+		}
+		list_free_deep(groups_list);
+	}
+
+	if (or_statement)
+	{
+		/* One more trick: assemble correct clause */
+		expr = list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, list_copy(or_list), -1) : linitial(or_list);
+		result = (Node *)expr;
+	}
+	/*
+	 * There was no reasons to create a new expresion, so
+	 * run the original BoolExpr conversion with using
+	 * transformBoolExpr function
+	 */
+	else
+	{
+		result = transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	list_free(or_list);
+
+	return result;
+}
 
 /*
  * transformExpr -
@@ -208,7 +493,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (Expr *)expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 260854747b..01918e6aea 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1630,6 +1630,7 @@ NumericSumAccum
 NumericVar
 OM_uint32
 OP
+OrClauseGroupEntry
 OSAPerGroupState
 OSAPerQueryState
 OSInfo
0001-make-check.txttext/plain; charset=UTF-8; name=0001-make-check.txtDownload
#26Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Ranier Vilela (#25)
4 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 29.06.2023 04:36, Ranier Vilela wrote:

I don't want to be rude, but this doesn't seem very helpful.

Sorry, It was not my intention to cause interruptions.

- You made some changes, but you don't even attempt to explain
what you
changed or why you changed it.

1. Reduce scope
2. Eliminate unnecessary variables
3. Eliminate unnecessary expressions

- You haven't even tried to compile the code, nor tested it. If it
happens to compile, wow could others even know it actually behaves the
way you wanted?

Sorry I didn't answer right away. I will try not to do this in the
future thank you for your participation and help.

Yes, the scope of this patch may be small, but I am sure that it will
solve the worst case of memory consumption with large numbers of "or"
expressions or reduce execution and planning time. As I have already
said, I conducted a launch on a database with 20 billion data generated
using a benchmark. Unfortunately, at that time I sent a not quite
correct picture: the execution time, not the planning time, increases
with the number of "or" expressions (execution_time.png). x is the
number of or expressions, y is the execution/scheduling time.

I also throw memory consumption at 50,000 "or" expressions collected by
HeapTrack (where memory consumption was recorded already at the
initialization stage of the 1.27GB pic3.png). I think such a
transformation will allow just the same to avoid such a worst case,
since in comparison with ANY memory is much less and takes little time.

SELECT FORMAT('prepare x %s AS SELECT * FROM pgbench_accounts a WHERE %s',
'(' || string_agg('int',',') ||')',
string_agg(FORMAT('aid = $%s', g.id),' or ')
) AS cmd
FROM generate_series(1, 50000) AS g(id)
\gexec

SELECT FORMAT('execute x %s;','(' || string_agg(g.id::text,',') ||')') AS cmd
FROM generate_series(1, 50000) AS g(id)
\gexec

I tried to add a transformation at the path formation stage before we
form indexes (set_plain_rel_pathlist function) and at the stage when we
have preprocessing of "or" expressions (getting rid of duplicates or
useless conditions), but everywhere there was a problem of incorrect
selectivity estimation.

CREATE TABLE tenk1 (unique1int, unique2int, tenint, hundredint);
insert into tenk1 SELECT x,x,x,x FROM generate_series(1,50000) as x;
CREATE INDEX a_idx1 ON tenk1(unique1);
CREATE INDEX a_idx2 ON tenk1(unique2);
CREATE INDEX a_hundred ON tenk1(hundred);

postgres=# explain analyze
select * from tenk1 a join tenk1 b on
((a.unique2 = 3 or a.unique2 = 7)) or (a.unique1 = 1);
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..140632434.50 rows=11250150000 width=32) (actual time=0.077..373.279 rows=1350000 loops=1)
-> Seq Scan on tenk1 b (cost=0.00..2311.00 rows=150000 width=16) (actual time=0.037..13.941 rows=150000 loops=1)
-> Materialize (cost=0.00..3436.01 rows=75001 width=16) (actual time=0.000..0.001 rows=9 loops=150000)
-> Seq Scan on tenk1 a (cost=0.00..3061.00 rows=75001 width=16) (actual time=0.027..59.174 rows=9 loops=1)
Filter: ((unique2 = ANY (ARRAY[3, 7])) OR (unique1 = 1))
Rows Removed by Filter: 149991
Planning Time: 0.438 ms
Execution Time: 407.144 ms
(8 rows)

Only by converting the expression at this stage, we do not encounter
this problem.

postgres=# set enable_bitmapscan ='off';
SET
postgres=# explain analyze
select * from tenk1 a join tenk1 b on
a.unique2 = 3 or a.unique2 = 7 or a.unique1 = 1;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..22247.02 rows=1350000 width=32) (actual time=0.094..373.627 rows=1350000 loops=1)
-> Seq Scan on tenk1 b (cost=0.00..2311.00 rows=150000 width=16) (actual time=0.051..14.667 rows=150000 loops=1)
-> Materialize (cost=0.00..3061.05 rows=9 width=16) (actual time=0.000..0.001 rows=9 loops=150000)
-> Seq Scan on tenk1 a (cost=0.00..3061.00 rows=9 width=16) (actual time=0.026..42.389 rows=9 loops=1)
Filter: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
Rows Removed by Filter: 149991
Planning Time: 0.414 ms
Execution Time: 409.154 ms
(8 rows)

I compiled my original patch and there were no problems with regression
tests. The only time there was a problem when I set the
const_transform_or_limit variable to 0 (I have 15), as you have in the
patch. To be honest, diff appears there because you had a different
plan, specifically the expressions "or" are replaced by ANY (see
regression.diffs).
Unfortunately, your patch version did not apply immediately, I did not
understand the reasons, I applied it manually.
At the moment, I'm not sure that the constant is the right number for
applying transformations, so I'm in search of it, to be honest. I will
post my observations on this issue later. If you don't mind, I'll leave
the constant equal to 15 for now.

Sorry, I don't understand well enough what is meant by points "Eliminate
unnecessary variables" and "Eliminate unnecessary expressions". Can you
explain in more detail?

Regarding the patch, there was a Warning at the compilation stage.

In file included from ../../../src/include/nodes/bitmapset.h:21,

                 from ../../../src/include/nodes/parsenodes.h:26,

                 from ../../../src/include/catalog/objectaddress.h:17,

                 from ../../../src/include/catalog/pg_aggregate.h:24,

                 from parse_expr.c:18:

parse_expr.c: In function ‘transformBoolExprOr’:

../../../src/include/nodes/nodes.h:133:66: warning: ‘expr’ is used uninitialized [-Wuninitialized]

  133 | #define nodeTag(nodeptr)                (((const Node*)(nodeptr))->type)

      |                                                                  ^~

parse_expr.c:116:29: note: ‘expr’ was declared here

  116 |         BoolExpr           *expr;

      |                             ^~~~

I couldn't figure out how to fix it and went back to my original
version. To be honest, I don't think anything needs to be changed here.

Unfortunately, I didn't understand the reasons why, with the available
or expressions, you don't even try to convert to ANY by calling
transformBoolExpr, as I saw. I went back to my version.

I think it's worth checking whether the or_statement variable is positive.

I think it's worth leaving the use of the or_statement variable in its
original form.

  switch (expr->boolop)
  {
    case AND_EXPR:
      opname = "AND";
      break;
    case OR_EXPR:
      opname = "OR";
      or_statement = true;
      break;
    case NOT_EXPR:
      opname = "NOT";
      break;
    default:
      elog(ERROR, "unrecognized boolop: %d", (int) expr->boolop);
      opname = NULL;    /* keep compiler quiet */
      break;
  }

  if (!or_statement || list_length(expr->args) < const_transform_or_limit)
    return transformBoolExpr(pstate, (BoolExpr *)expr_orig);

The current version of the patch also works and all tests pass.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

regression.diffstext/plain; charset=UTF-8; name=regression.diffsDownload
diff -U3 /home/alena/postgrespro9/src/test/regress/expected/create_index.out /home/alena/postgrespro9/src/test/regress/results/create_index.out
--- /home/alena/postgrespro9/src/test/regress/expected/create_index.out	2023-06-28 14:00:24.666903452 +0300
+++ /home/alena/postgrespro9/src/test/regress/results/create_index.out	2023-06-29 07:53:52.406547638 +0300
@@ -1838,18 +1838,11 @@
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,20 +1854,17 @@
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff -U3 /home/alena/postgrespro9/src/test/regress/expected/join.out /home/alena/postgrespro9/src/test/regress/results/join.out
--- /home/alena/postgrespro9/src/test/regress/expected/join.out	2023-06-28 14:00:24.670903489 +0300
+++ /home/alena/postgrespro9/src/test/regress/results/join.out	2023-06-29 07:53:55.686585947 +0300
@@ -4184,10 +4184,10 @@
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4197,15 +4197,13 @@
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff -U3 /home/alena/postgrespro9/src/test/regress/expected/stats_ext.out /home/alena/postgrespro9/src/test/regress/results/stats_ext.out
--- /home/alena/postgrespro9/src/test/regress/expected/stats_ext.out	2023-06-28 11:43:46.174724411 +0300
+++ /home/alena/postgrespro9/src/test/regress/results/stats_ext.out	2023-06-29 07:54:04.234685711 +0300
@@ -1322,19 +1322,19 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff -U3 /home/alena/postgrespro9/src/test/regress/expected/partition_prune.out /home/alena/postgrespro9/src/test/regress/results/partition_prune.out
--- /home/alena/postgrespro9/src/test/regress/expected/partition_prune.out	2023-06-28 14:00:24.670903489 +0300
+++ /home/alena/postgrespro9/src/test/regress/results/partition_prune.out	2023-06-29 07:54:14.874809747 +0300
@@ -82,23 +82,23 @@
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
 explain (costs off) select * from lp where a <> 'g';
@@ -515,10 +515,10 @@
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +596,13 @@
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -1933,10 +1933,10 @@
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
@@ -2265,11 +2265,11 @@
          Workers Launched: N
          ->  Parallel Append (actual rows=N loops=N)
                ->  Parallel Seq Scan on ab_a1_b2 ab_1 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a2_b2 ab_2 (never executed)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a3_b2 ab_3 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
 (16 rows)
 
 -- Test pruning during parallel nested loop query
0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patchtext/x-patch; charset=UTF-8; name=0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patchDownload
From 06ae4f0887358eb38fe1b32287580a6996c8c9f6 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 29 Jun 2023 07:09:16 +0300
Subject: [PATCH] Replace clause (X=N1) OR (X=N2) ... with X = ANY(N1, N2) on
 the stage of the optimiser when we are still working with a tree expression.

Firstly, we do not try to make a transformation for "non-or"
expressions or inequalities and the creation of a relation
with "or" expressions occurs according to the same scenario;
secondly, we do not make transformations if there are less
than 15 or expressions (here you can put another number, but
during testing, already starting with 3 expressions, the execution
time and planning time with transformed or were faster);
thirdly, it is worth considering that we consider "or" expressions
only at the current level.
The transformation takes place according to the following scheme:
first we define the groups on the left side, collect the constants
in a list for each group, then considering each group we make the
collected constants to one type, find a common type for array and
using the make_scalar_array_op function we form ScalarArrayOpExpr,
if possible. If it is not possible, then these constants both remain
in the same expr as before the function call. All successful attempts
(received ScalarArrayOpExpr together with unformulated Expr are
combined via OR operation).
---
 src/backend/parser/parse_expr.c  | 286 ++++++++++++++++++++++++++++++-
 src/tools/pgindent/typedefs.list |   1 +
 2 files changed, 286 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6d..299e1c62d24 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -95,6 +95,290 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int const_transform_or_limit = 15;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, Expr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc_eargs;
+	Node 		   *result;
+	BoolExpr 	   *expr = (BoolExpr *)copyObject(expr_orig);
+	const char 	   *opname;
+	bool			change_apply = false;
+	bool			or_statement = false;
+
+	Assert(IsA(expr, BoolExpr));
+
+	/* If this is not expression "Or", then will do it the old way. */
+	switch (expr->boolop)
+	{
+		case AND_EXPR:
+			opname = "AND";
+			break;
+		case OR_EXPR:
+			opname = "OR";
+			or_statement = true;
+			break;
+		case NOT_EXPR:
+			opname = "NOT";
+			break;
+		default:
+			elog(ERROR, "unrecognized boolop: %d", (int) expr->boolop);
+			opname = NULL;		/* keep compiler quiet */
+			break;
+	}
+
+	if (!or_statement || list_length(expr->args) < const_transform_or_limit)
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+
+	/*
+		* NOTE:
+		* It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		* a list of sub-restrictinfo args, and rinfo->clause - which is the
+		* same expression, made from bare clauses. To not break selectivity
+		* caches and other optimizations, use both:
+		* - use rinfos from orclause if no transformation needed
+		* - use  bare quals from rinfo->clause in the case of transformation,
+		* to create new RestrictInfo: in this case we have no options to avoid
+		* selectivity estimation procedure.
+		*/
+	foreach(lc_eargs, expr->args)
+	{
+		A_Expr			   *arg = (A_Expr *) lfirst(lc_eargs);
+		Node			   *bare_orarg;
+		Node			   *const_expr;
+		Node			   *non_const_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+		bool 				allow_transformation;
+
+		/*
+		 * The first step: checking that the expression consists only of equality.
+		 * We can only do this here, while arg is still row data type, namely A_Expr.
+		 * After applying transformExprRecurce, we already know that it will be OpExr type,
+		 * but checking the expression for equality is already becoming impossible for us.
+		 * Sometimes we have the chance to devide expression into the groups on
+		 * equality and inequality. This is possible if all list items are not at the
+		 * same level of a single BoolExpr expression, otherwise all of them cannot be converted.
+		 */
+
+		if (!arg)
+			break;
+
+		allow_transformation = (
+								or_statement &&
+		                        arg->type == T_A_Expr && (arg)->kind == AEXPR_OP &&
+							    list_length((arg)->name) >=1 && strcmp(strVal(linitial((arg)->name)), "=") == 0
+							   );
+
+
+		bare_orarg = transformExprRecurse(pstate, (Node *)arg);
+		bare_orarg = coerce_to_boolean(pstate, bare_orarg, opname);
+
+		/*
+		 * The next step: transform all the inputs, and detect whether any contain
+	 	 * Vars.
+		 */
+		if (!allow_transformation || !bare_orarg || !IsA(bare_orarg, OpExpr) || !contain_vars_of_level(bare_orarg, 0))
+		{
+			/* Again, it's not the expr we can transform */
+			or_list = lappend(or_list, bare_orarg);
+			continue;
+		}
+
+		/*
+		 * Get pointers to constant and expression sides of the clause
+		 */
+		non_const_expr = get_leftop(bare_orarg);
+		const_expr = get_rightop(bare_orarg);
+
+		/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table (htab key ???).
+			*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, non_const_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				non_const_expr = NULL;
+				break;
+			}
+		}
+
+		if (non_const_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = non_const_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->opno = ((OpExpr *)bare_orarg)->opno;
+		gentry->expr = (Expr *)bare_orarg;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this rinfo, just add itself
+		* to the list and go further.
+		*/
+		list_free(or_list);
+
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation. It's been a long way ;)
+			 *
+			 * First of all, try to select a common type for the array elements.  Note that
+			 * since the LHS' type is first in the list, it will be preferred when
+			 * there is doubt (eg, when all the RHS items are unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (OidIsValid(scalar_type) &&
+				scalar_type != RECORDOID &&
+				verify_common_type(scalar_type, allexprs))
+			{
+				/*
+			 	 * OK: coerce all the right-hand non-Var inputs to the common type
+			 	 * and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = get_array_type(scalar_type);
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1; /* Position of the new clause is undefined */
+
+				saopexpr = (ScalarArrayOpExpr *)make_scalar_array_op(pstate,
+												   list_make1(makeString((char *) "=")),
+												   true,
+												   gentry->node,
+												   (Node *) newa,
+												   -1); /* Position of the new clause is undefined */
+
+				/*
+				* TODO: here we can try to coerce the array to a Const and find
+				* hash func instead of linear search (see 50e17ad281b).
+				* convert_saop_to_hashed_saop((Node *) saopexpr);
+				* We don't have to do this anymore, do we?
+				*/
+
+				or_list = lappend(or_list, (void *) saopexpr);
+				change_apply = true;
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		if (!change_apply)
+		{
+			or_statement = false;
+		}
+		list_free_deep(groups_list);
+	}
+
+	if (or_statement)
+	{
+		/* One more trick: assemble correct clause */
+		expr = list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, list_copy(or_list), -1) : linitial(or_list);
+		result = (Node *)expr;
+	}
+	/*
+	 * There was no reasons to create a new expresion, so
+	 * run the original BoolExpr conversion with using
+	 * transformBoolExpr function
+	 */
+	else
+	{
+		result = transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	list_free(or_list);
+
+	return result;
+}
 
 /*
  * transformExpr -
@@ -208,7 +492,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (Expr *)expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 260854747b4..01918e6aeac 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1630,6 +1630,7 @@ NumericSumAccum
 NumericVar
 OM_uint32
 OP
+OrClauseGroupEntry
 OSAPerGroupState
 OSAPerQueryState
 OSInfo
-- 
2.34.1

pic3.pngimage/png; name=pic3.pngDownload
execution_time.pngimage/png; name=execution_time.pngDownload
#27Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Ranier Vilela (#25)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Sorry for the possible duplicate. I have a suspicion that the previous
email was not sent.

Hi!

On 29.06.2023 04:36, Ranier Vilela wrote:

Em qua., 28 de jun. de 2023 às 18:45, Tomas Vondra
<tomas.vondra@enterprisedb.com> escreveu:

On 6/27/23 20:55, Ranier Vilela wrote:

Hi,

I finished writing the code patch for transformation "Or"

expressions to

"Any" expressions. I didn't see any problems in regression

tests, even

when I changed the constant at which the minimum or expression is
replaced by any at 0. I ran my patch on sqlancer and so far the

code has

never fallen.

Thanks for working on this.

I took the liberty of making some modifications to the patch.
I didn't compile or test it.
Please feel free to use them.

I don't want to be rude, but this doesn't seem very helpful.

Sorry, It was not my intention to cause interruptions.

- You made some changes, but you don't even attempt to explain
what you
changed or why you changed it.

1. Reduce scope
2. Eliminate unnecessary variables
3. Eliminate unnecessary expressions

- You haven't even tried to compile the code, nor tested it. If it
happens to compile, wow could others even know it actually behaves the
way you wanted?

Attached v2 with make check pass all tests.
Ubuntu 64 bits
gcc 64 bits

- You responded in a way that breaks the original thread, so it's not
clear which message you're responding to.

It was a pretty busy day.

Sorry for the noise, I hope I was of some help.

regards,
Ranier Vilela

P.S.
0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patch fails
with 4 tests.

Sorry I didn't answer right away. I will try not to do this in the
future thank you for your participation and help.

Yes, the scope of this patch may be small, but I am sure that it will
solve the worst case of memory consumption with large numbers of "or"
expressions or reduce execution and planning time. As I have already
said, I conducted a launch on a database with 20 billion data generated
using a benchmark. Unfortunately, at that time I sent a not quite
correct picture: the execution time, not the planning time, increases
with the number of "or" expressions
(https://www.dropbox.com/s/u7gt81blbv2adpi/execution_time.png?dl=0). x
is the number of or expressions, y is the execution/scheduling time.

I also throw memory consumption at 50,000 "or" expressions collected by
HeapTrack (where memory consumption was recorded already at the
initialization stage of the 1.27GB
https://www.dropbox.com/s/vb827ya0193dlz0/pic3.png?dl=0). I think such a
transformation will allow just the same to avoid such a worst case,
since in comparison with ANY memory is much less and takes little time.

SELECT FORMAT('prepare x %s AS SELECT * FROM pgbench_accounts a WHERE %s',
'(' || string_agg('int',',') ||')',
string_agg(FORMAT('aid = $%s', g.id),' or ')
) AS cmd
FROM generate_series(1, 50000) AS g(id)
\gexec

SELECT FORMAT('execute x %s;','(' || string_agg(g.id::text,',') ||')') AS cmd
FROM generate_series(1, 50000) AS g(id)
\gexec

I tried to add a transformation at the path formation stage before we
form indexes (set_plain_rel_pathlist function) and at the stage when we
have preprocessing of "or" expressions (getting rid of duplicates or
useless conditions), but everywhere there was a problem of incorrect
selectivity estimation.

CREATE TABLE tenk1 (unique1int, unique2int, tenint, hundredint);
insert into tenk1 SELECT x,x,x,x FROM generate_series(1,50000) as x;
CREATE INDEX a_idx1 ON tenk1(unique1);
CREATE INDEX a_idx2 ON tenk1(unique2);
CREATE INDEX a_hundred ON tenk1(hundred);

postgres=# explain analyze
select * from tenk1 a join tenk1 b on
((a.unique2 = 3 or a.unique2 = 7)) or (a.unique1 = 1);
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..140632434.50 rows=11250150000 width=32) (actual time=0.077..373.279 rows=1350000 loops=1)
-> Seq Scan on tenk1 b (cost=0.00..2311.00 rows=150000 width=16) (actual time=0.037..13.941 rows=150000 loops=1)
-> Materialize (cost=0.00..3436.01 rows=75001 width=16) (actual time=0.000..0.001 rows=9 loops=150000)
-> Seq Scan on tenk1 a (cost=0.00..3061.00 rows=75001 width=16) (actual time=0.027..59.174 rows=9 loops=1)
Filter: ((unique2 = ANY (ARRAY[3, 7])) OR (unique1 = 1))
Rows Removed by Filter: 149991
Planning Time: 0.438 ms
Execution Time: 407.144 ms
(8 rows)

Only by converting the expression at this stage, we do not encounter
this problem.

postgres=# set enable_bitmapscan ='off';
SET
postgres=# explain analyze
select * from tenk1 a join tenk1 b on
a.unique2 = 3 or a.unique2 = 7 or a.unique1 = 1;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..22247.02 rows=1350000 width=32) (actual time=0.094..373.627 rows=1350000 loops=1)
-> Seq Scan on tenk1 b (cost=0.00..2311.00 rows=150000 width=16) (actual time=0.051..14.667 rows=150000 loops=1)
-> Materialize (cost=0.00..3061.05 rows=9 width=16) (actual time=0.000..0.001 rows=9 loops=150000)
-> Seq Scan on tenk1 a (cost=0.00..3061.00 rows=9 width=16) (actual time=0.026..42.389 rows=9 loops=1)
Filter: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
Rows Removed by Filter: 149991
Planning Time: 0.414 ms
Execution Time: 409.154 ms
(8 rows)

I compiled my original patch and there were no problems with regression
tests. The only time there was a problem when I set the
const_transform_or_limit variable to 0 (I have 15), as you have in the
patch. To be honest, diff appears there because you had a different
plan, specifically the expressions "or" are replaced by ANY (see
regression.diffs).
Unfortunately, your patch version did not apply immediately, I did not
understand the reasons, I applied it manually.
At the moment, I'm not sure that the constant is the right number for
applying transformations, so I'm in search of it, to be honest. I will
post my observations on this issue later. If you don't mind, I'll leave
the constant equal to 15 for now.

Sorry, I don't understand well enough what is meant by points "Eliminate
unnecessary variables" and "Eliminate unnecessary expressions". Can you
explain in more detail?

Regarding the patch, there was a Warning at the compilation stage.

In file included from ../../../src/include/nodes/bitmapset.h:21,

                 from ../../../src/include/nodes/parsenodes.h:26,

                 from ../../../src/include/catalog/objectaddress.h:17,

                 from ../../../src/include/catalog/pg_aggregate.h:24,

                 from parse_expr.c:18:

parse_expr.c: In function ‘transformBoolExprOr’:

../../../src/include/nodes/nodes.h:133:66: warning: ‘expr’ is used uninitialized [-Wuninitialized]

  133 | #define nodeTag(nodeptr)                (((const Node*)(nodeptr))->type)

      |                                                                  ^~

parse_expr.c:116:29: note: ‘expr’ was declared here

  116 |         BoolExpr           *expr;

      |                             ^~~~

I couldn't figure out how to fix it and went back to my original
version. To be honest, I don't think anything needs to be changed here.

Unfortunately, I didn't understand the reasons why, with the available
or expressions, you don't even try to convert to ANY by calling
transformBoolExpr, as I saw. I went back to my version.

I think it's worth checking whether the or_statement variable is positive.

I think it's worth leaving the use of the or_statement variable in its
original form.

  switch (expr->boolop)
  {
    case AND_EXPR:
      opname = "AND";
      break;
    case OR_EXPR:
      opname = "OR";
      or_statement = true;
      break;
    case NOT_EXPR:
      opname = "NOT";
      break;
    default:
      elog(ERROR, "unrecognized boolop: %d", (int) expr->boolop);
      opname = NULL;    /* keep compiler quiet */
      break;
  }

  if (!or_statement || list_length(expr->args) < const_transform_or_limit)
    return transformBoolExpr(pstate, (BoolExpr *)expr_orig);

The current version of the patch also works and all tests pass.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patchtext/x-patch; charset=UTF-8; name=0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patchDownload
From 06ae4f0887358eb38fe1b32287580a6996c8c9f6 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 29 Jun 2023 07:09:16 +0300
Subject: [PATCH] Replace clause (X=N1) OR (X=N2) ... with X = ANY(N1, N2) on
 the stage of the optimiser when we are still working with a tree expression.

Firstly, we do not try to make a transformation for "non-or"
expressions or inequalities and the creation of a relation
with "or" expressions occurs according to the same scenario;
secondly, we do not make transformations if there are less
than 15 or expressions (here you can put another number, but
during testing, already starting with 3 expressions, the execution
time and planning time with transformed or were faster);
thirdly, it is worth considering that we consider "or" expressions
only at the current level.
The transformation takes place according to the following scheme:
first we define the groups on the left side, collect the constants
in a list for each group, then considering each group we make the
collected constants to one type, find a common type for array and
using the make_scalar_array_op function we form ScalarArrayOpExpr,
if possible. If it is not possible, then these constants both remain
in the same expr as before the function call. All successful attempts
(received ScalarArrayOpExpr together with unformulated Expr are
combined via OR operation).
---
 src/backend/parser/parse_expr.c  | 286 ++++++++++++++++++++++++++++++-
 src/tools/pgindent/typedefs.list |   1 +
 2 files changed, 286 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6d..299e1c62d24 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -95,6 +95,290 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int const_transform_or_limit = 15;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, Expr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc_eargs;
+	Node 		   *result;
+	BoolExpr 	   *expr = (BoolExpr *)copyObject(expr_orig);
+	const char 	   *opname;
+	bool			change_apply = false;
+	bool			or_statement = false;
+
+	Assert(IsA(expr, BoolExpr));
+
+	/* If this is not expression "Or", then will do it the old way. */
+	switch (expr->boolop)
+	{
+		case AND_EXPR:
+			opname = "AND";
+			break;
+		case OR_EXPR:
+			opname = "OR";
+			or_statement = true;
+			break;
+		case NOT_EXPR:
+			opname = "NOT";
+			break;
+		default:
+			elog(ERROR, "unrecognized boolop: %d", (int) expr->boolop);
+			opname = NULL;		/* keep compiler quiet */
+			break;
+	}
+
+	if (!or_statement || list_length(expr->args) < const_transform_or_limit)
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+
+	/*
+		* NOTE:
+		* It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		* a list of sub-restrictinfo args, and rinfo->clause - which is the
+		* same expression, made from bare clauses. To not break selectivity
+		* caches and other optimizations, use both:
+		* - use rinfos from orclause if no transformation needed
+		* - use  bare quals from rinfo->clause in the case of transformation,
+		* to create new RestrictInfo: in this case we have no options to avoid
+		* selectivity estimation procedure.
+		*/
+	foreach(lc_eargs, expr->args)
+	{
+		A_Expr			   *arg = (A_Expr *) lfirst(lc_eargs);
+		Node			   *bare_orarg;
+		Node			   *const_expr;
+		Node			   *non_const_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+		bool 				allow_transformation;
+
+		/*
+		 * The first step: checking that the expression consists only of equality.
+		 * We can only do this here, while arg is still row data type, namely A_Expr.
+		 * After applying transformExprRecurce, we already know that it will be OpExr type,
+		 * but checking the expression for equality is already becoming impossible for us.
+		 * Sometimes we have the chance to devide expression into the groups on
+		 * equality and inequality. This is possible if all list items are not at the
+		 * same level of a single BoolExpr expression, otherwise all of them cannot be converted.
+		 */
+
+		if (!arg)
+			break;
+
+		allow_transformation = (
+								or_statement &&
+		                        arg->type == T_A_Expr && (arg)->kind == AEXPR_OP &&
+							    list_length((arg)->name) >=1 && strcmp(strVal(linitial((arg)->name)), "=") == 0
+							   );
+
+
+		bare_orarg = transformExprRecurse(pstate, (Node *)arg);
+		bare_orarg = coerce_to_boolean(pstate, bare_orarg, opname);
+
+		/*
+		 * The next step: transform all the inputs, and detect whether any contain
+	 	 * Vars.
+		 */
+		if (!allow_transformation || !bare_orarg || !IsA(bare_orarg, OpExpr) || !contain_vars_of_level(bare_orarg, 0))
+		{
+			/* Again, it's not the expr we can transform */
+			or_list = lappend(or_list, bare_orarg);
+			continue;
+		}
+
+		/*
+		 * Get pointers to constant and expression sides of the clause
+		 */
+		non_const_expr = get_leftop(bare_orarg);
+		const_expr = get_rightop(bare_orarg);
+
+		/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table (htab key ???).
+			*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, non_const_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				non_const_expr = NULL;
+				break;
+			}
+		}
+
+		if (non_const_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = non_const_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->opno = ((OpExpr *)bare_orarg)->opno;
+		gentry->expr = (Expr *)bare_orarg;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this rinfo, just add itself
+		* to the list and go further.
+		*/
+		list_free(or_list);
+
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation. It's been a long way ;)
+			 *
+			 * First of all, try to select a common type for the array elements.  Note that
+			 * since the LHS' type is first in the list, it will be preferred when
+			 * there is doubt (eg, when all the RHS items are unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (OidIsValid(scalar_type) &&
+				scalar_type != RECORDOID &&
+				verify_common_type(scalar_type, allexprs))
+			{
+				/*
+			 	 * OK: coerce all the right-hand non-Var inputs to the common type
+			 	 * and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = get_array_type(scalar_type);
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1; /* Position of the new clause is undefined */
+
+				saopexpr = (ScalarArrayOpExpr *)make_scalar_array_op(pstate,
+												   list_make1(makeString((char *) "=")),
+												   true,
+												   gentry->node,
+												   (Node *) newa,
+												   -1); /* Position of the new clause is undefined */
+
+				/*
+				* TODO: here we can try to coerce the array to a Const and find
+				* hash func instead of linear search (see 50e17ad281b).
+				* convert_saop_to_hashed_saop((Node *) saopexpr);
+				* We don't have to do this anymore, do we?
+				*/
+
+				or_list = lappend(or_list, (void *) saopexpr);
+				change_apply = true;
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		if (!change_apply)
+		{
+			or_statement = false;
+		}
+		list_free_deep(groups_list);
+	}
+
+	if (or_statement)
+	{
+		/* One more trick: assemble correct clause */
+		expr = list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, list_copy(or_list), -1) : linitial(or_list);
+		result = (Node *)expr;
+	}
+	/*
+	 * There was no reasons to create a new expresion, so
+	 * run the original BoolExpr conversion with using
+	 * transformBoolExpr function
+	 */
+	else
+	{
+		result = transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	list_free(or_list);
+
+	return result;
+}
 
 /*
  * transformExpr -
@@ -208,7 +492,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (Expr *)expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 260854747b4..01918e6aeac 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1630,6 +1630,7 @@ NumericSumAccum
 NumericVar
 OM_uint32
 OP
+OrClauseGroupEntry
 OSAPerGroupState
 OSAPerQueryState
 OSInfo
-- 
2.34.1

regression.diffstext/plain; charset=UTF-8; name=regression.diffsDownload
diff -U3 /home/alena/postgrespro9/src/test/regress/expected/create_index.out /home/alena/postgrespro9/src/test/regress/results/create_index.out
--- /home/alena/postgrespro9/src/test/regress/expected/create_index.out	2023-06-28 14:00:24.666903452 +0300
+++ /home/alena/postgrespro9/src/test/regress/results/create_index.out	2023-06-29 07:53:52.406547638 +0300
@@ -1838,18 +1838,11 @@
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,20 +1854,17 @@
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff -U3 /home/alena/postgrespro9/src/test/regress/expected/join.out /home/alena/postgrespro9/src/test/regress/results/join.out
--- /home/alena/postgrespro9/src/test/regress/expected/join.out	2023-06-28 14:00:24.670903489 +0300
+++ /home/alena/postgrespro9/src/test/regress/results/join.out	2023-06-29 07:53:55.686585947 +0300
@@ -4184,10 +4184,10 @@
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4197,15 +4197,13 @@
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff -U3 /home/alena/postgrespro9/src/test/regress/expected/stats_ext.out /home/alena/postgrespro9/src/test/regress/results/stats_ext.out
--- /home/alena/postgrespro9/src/test/regress/expected/stats_ext.out	2023-06-28 11:43:46.174724411 +0300
+++ /home/alena/postgrespro9/src/test/regress/results/stats_ext.out	2023-06-29 07:54:04.234685711 +0300
@@ -1322,19 +1322,19 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff -U3 /home/alena/postgrespro9/src/test/regress/expected/partition_prune.out /home/alena/postgrespro9/src/test/regress/results/partition_prune.out
--- /home/alena/postgrespro9/src/test/regress/expected/partition_prune.out	2023-06-28 14:00:24.670903489 +0300
+++ /home/alena/postgrespro9/src/test/regress/results/partition_prune.out	2023-06-29 07:54:14.874809747 +0300
@@ -82,23 +82,23 @@
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
 explain (costs off) select * from lp where a <> 'g';
@@ -515,10 +515,10 @@
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +596,13 @@
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -1933,10 +1933,10 @@
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
@@ -2265,11 +2265,11 @@
          Workers Launched: N
          ->  Parallel Append (actual rows=N loops=N)
                ->  Parallel Seq Scan on ab_a1_b2 ab_1 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a2_b2 ab_2 (never executed)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a3_b2 ab_3 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
 (16 rows)
 
 -- Test pruning during parallel nested loop query
#28Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Peter Geoghegan (#23)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi! I'm sorry I didn't answer you right away, I was too busy with work.

On 27.06.2023 22:50, Peter Geoghegan wrote:

On Tue, Jun 27, 2023 at 6:19 AM Alena Rybakina<lena.ribackina@yandex.ru> wrote:

I learned something new from your letter, thank you very much for that!

Cool. The MDAM paper is also worth a read:

https://vldb.org/conf/1995/P710.PDF

Some of the techniques it describes are already in Postgres. With
varying degrees of maturity.

The paper actually mentions OR optimization at one point, under
"Duplicate Elimination". The general idea is that ScalarArrayOpExpr
execution can "eliminate duplicates before the data is read". The
important underlying principle is that it can be really useful to give
the B-Tree code the context it requires to be clever about stuff like
that. We can do this by (say) using one ScalarArrayOpExpr, rather than
using two or more index scans that the B-Tree code will treat as
independent things. So a lot of the value in your patch comes from the
way that it can enable other optimizations (the immediate benefits are
also nice).

In the past, OR optimizations have been prototyped that were later
withdrawn/rejected because the duplicate elimination aspect was...too
scary [1]. It's very easy to see that ScalarArrayOpExpr index scans
don't really have the same problem. "Giving the B-Tree code the
required context" helps here too.

Thank you for the explanation and the material provided) unfortunately,
I am still only studying the article and at the moment I cannot write
more. To be honest, I didn't think about the fact that my optimization
can help eliminate duplicates before reading the data before.

I am still only in the process of familiarizing myself with the thread
[1]: (reference from your letter), but I have already seen that there are problems related, for example, to when "or" expressions refer to the parent element.
problems related, for example, to when "or" expressions refer to the
parent element.

I think, I would face the similar problems if I complicate the current
code, for example, so that not only or expressions standing on the same
level are written in any, but also on different ones without violating
the logic of the priority of executing operators.

For example, this query works now:

postgres=# EXPLAIN (analyze, COSTS OFF)
SELECT oid,relname FROM pg_class
WHERE
  (oid = 13779 OR oid = 2) OR (oid = 4 OR oid = 5) OR
  relname = 'pg_extension'
;

                                                    QUERY PLAN
------------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_class (actual time=0.086..0.140 rows=1 loops=1)
   Filter: ((oid = ANY ('{4,5}'::oid[])) OR (oid = ANY
('{13779,2}'::oid[])) OR (relname = 'pg_extension'::name))
   Rows Removed by Filter: 412
 Planning Time: 2.135 ms
 Execution Time: 0.160 ms
(5 rows)

But I would like it works such as:

                                      QUERY PLAN
--------------------------------------------------------------------------------------
 Seq Scan on pg_class (actual time=0.279..0.496 rows=1 loops=1)
   Filter: ((oid = ANY ('{13779,2,4,5}'::oid[])) OR (relname =
'pg_extension'::name))
   Rows Removed by Filter: 412
 Planning Time: 0.266 ms
 Execution Time: 0.536 ms
(5 rows)

I analyzed the buffer consumption when I ran control regression tests using my patch. diff shows me that there is no difference between the number of buffer block scans without and using my patch, as far as I have seen. (regression.diffs)

To be clear, I wasn't expecting that there'd be any regressions from
your patch. Intuitively, it seems like this optimization should make
the query plan do almost the same thing at execution time -- just
slightly more efficiently on average, and much more efficiently in
some individual cases.

It would probably be very hard for the optimizer to model/predict how
much work it can save by using a ScalarArrayOpExpr instead of an
"equivalent" set of bitmap index scans, OR'd together. But it doesn't
necessarily matter -- the only truly critical detail is understanding
the worst case for the transformation optimization.

Yes, I agree with you and I have yet to analyze this.

It cannot be too
bad (maybe it's ~zero added runtime overhead relative to not doing the
transformation, even?).

I haven't seen a major performance degradation so far, but to be honest,
I have not conducted a detailed analysis on other types of queries other
than x=1 or x=2 or x=1 or y=2, etc. As soon as something is known, I
will provide the data, it is very interesting to me.

At the same time, nbtree can be clever about
ScalarArrayOpExpr execution at runtime (once that's implemented),
without ever needing to make any kind of up-front commitment to
navigating through the index in any particular way. It's all dynamic,
and can be driven by the actual observed characteristics of the index
structure.

In other words, we don't really need to gamble (in the planner, or at
execution time). We're just keeping our options open in more cases.
(My thinking on these topics was influenced by Goetz Graefe -- "choice
is confusion" [2]).

Unfortunately, when I tried to make a transformation at the stage of
index formation, I encountered too incorrect an assessment of the
selectivity of relation, which affected the incorrect calculation of the
cost and cardinality. I couldn't solve this problem.

My diff (transform_or_v0.diff). I got this result:

CREATE TABLE tenk1 (unique1int, unique2int, tenint, hundredint);
insert into tenk1 SELECT x,x,x,x FROM generate_series(1,50000) as x;
CREATE INDEX a_idx1 ON tenk1(unique1);
CREATE INDEX a_idx2 ON tenk1(unique2);
CREATE INDEX a_hundred ON tenk1(hundred);

postgres=# explain analyze
select * from tenk1 a join tenk1 b on
a.unique2 = 3 or a.unique2 = 7 or a.unique1 = 1;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..15627479.50 rows=1250050000 width=32) (actual time=0.040..75.531 rows=150000 loops=1)
-> Seq Scan on tenk1 b (cost=0.00..771.00 rows=50000 width=16) (actual time=0.022..5.467 rows=50000 loops=1)
-> Materialize (cost=0.00..1146.01 rows=25001 width=16) (actual time=0.000..0.001 rows=3 loops=50000)
-> Seq Scan on tenk1 a (cost=0.00..1021.00 rows=25001 width=16) (actual time=0.011..22.789 rows=3 loops=1)
Filter: ((unique2 = ANY (ARRAY[3, 7])) OR (unique1 = 1))
Rows Removed by Filter: 49997
Planning Time: 0.427 ms
Execution Time: 80.027 ms
(8 rows)

The current patch's result:

postgres=# set enable_bitmapscan ='off';
SET
postgres=# explain analyze
select * from tenk1 a join tenk1 b on
a.unique2 = 3 or a.unique2 = 7 or a.unique1 = 1;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..22247.02 rows=1350000 width=32) (actual time=0.094..373.627 rows=1350000 loops=1)
-> Seq Scan on tenk1 b (cost=0.00..2311.00 rows=150000 width=16) (actual time=0.051..14.667 rows=150000 loops=1)
-> Materialize (cost=0.00..3061.05 rows=9 width=16) (actual time=0.000..0.001 rows=9 loops=150000)
-> Seq Scan on tenk1 a (cost=0.00..3061.00 rows=9 width=16) (actual time=0.026..42.389 rows=9 loops=1)
Filter: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
Rows Removed by Filter: 149991
Planning Time: 0.414 ms
Execution Time: 409.154 ms
(8 rows)

[1]/messages/by-id/1397.1486598083@sss.pgh.pa.us
[2]https://sigmodrecord.org/publications/sigmodRecord/2009/pdfs/05_Profiles_Graefe.pdf

Thank you again for the explanations and the material provided. I will
carefully study everything as soon as possible and will write if there
are any thoughts or if there are ideas about my patch.

--

Regards,
Alena Rybakina
Postgres Professional

Attachments:

transform_or_v0.difftext/x-patch; charset=UTF-8; name=transform_or_v0.diffDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 0065c8992bd..8ef3438d78c 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -193,6 +193,273 @@ static bool ec_member_matches_indexcol(PlannerInfo *root, RelOptInfo *rel,
 									   EquivalenceClass *ec, EquivalenceMember *em,
 									   void *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				collation;
+	Oid				opno;
+	RestrictInfo   *rinfo;
+} OrClauseGroupEntry;
+
+/*
+ * Pass through baserestrictinfo clauses and try to convert OR clauses into IN
+ * Return a modified clause list or just the same baserestrictinfo, if no
+ * changes have made.
+ * XXX: do not change source list of clauses at all.
+ */
+static List *
+transform_ors(PlannerInfo *root, List *baserestrictinfo)
+{
+	ListCell   *lc;
+	ListCell   *lc_cp;
+	List	   *modified_rinfo = NIL;
+	bool		something_changed = false;
+	List	   *baserestrictinfo_origin = list_copy(baserestrictinfo);
+
+	/*
+	 * Complexity of a clause could be arbitrarily sophisticated. Here, we will
+	 * look up only on the top level of clause list.
+	 * XXX: It is substantiated? Could we change something here?
+	 */
+	forboth (lc, baserestrictinfo, lc_cp, baserestrictinfo_origin)
+	{
+		RestrictInfo   *rinfo = lfirst_node(RestrictInfo, lc);
+		RestrictInfo   *rinfo_base = lfirst_node(RestrictInfo, lc_cp);
+		List		   *or_list = NIL;
+		ListCell	   *lc_eargs,
+					   *lc_rargs,
+					   *lc_args;
+		List		   *groups_list = NIL;
+		bool			change_apply = false;
+
+		if (!restriction_is_or_clause(rinfo))
+		{
+			/* Add a clause without changes */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		/*
+		 * NOTE:
+		 * It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		 * a list of sub-restrictinfo args, and rinfo->clause - which is the
+		 * same expression, made from bare clauses. To not break selectivity
+		 * caches and other optimizations, use both:
+		 * - use rinfos from orclause if no transformation needed
+		 * - use  bare quals from rinfo->clause in the case of transformation,
+		 * to create new RestrictInfo: in this case we have no options to avoid
+		 * selectivity estimation procedure.
+		 */
+		forboth(lc_eargs, ((BoolExpr *) rinfo->clause)->args,
+				lc_rargs, ((BoolExpr *) rinfo->orclause)->args)
+		{
+			Expr			   *bare_orarg = (Expr *) lfirst(lc_eargs);
+			RestrictInfo	   *sub_rinfo;
+			Node			   *const_expr;
+			Node			   *non_const_expr;
+			ListCell		   *lc_groups;
+			OrClauseGroupEntry *gentry;
+			Oid					opno;
+
+			/* It may be one more boolean expression, skip it for now */
+			if (!IsA(lfirst(lc_rargs), RestrictInfo))
+			{
+				or_list = lappend(or_list, (void *) bare_orarg);
+				continue;
+			}
+
+			sub_rinfo = lfirst_node(RestrictInfo, lc_rargs);
+
+			/* Check: it is an expr of the form 'F(x) oper ConstExpr' */
+			if (!IsA(bare_orarg, OpExpr) ||
+				!(bms_is_empty(sub_rinfo->left_relids) ^
+				bms_is_empty(sub_rinfo->right_relids)) ||
+				contain_volatile_functions((Node *) bare_orarg))
+			{
+				/* Again, it's not the expr we can transform */
+				or_list = lappend(or_list, (void *) bare_orarg);
+				continue;
+			}
+
+			/* Get pointers to constant and expression sides of the clause */
+			const_expr =bms_is_empty(sub_rinfo->left_relids) ?
+												get_leftop(sub_rinfo->clause) :
+												get_rightop(sub_rinfo->clause);
+			non_const_expr = bms_is_empty(sub_rinfo->left_relids) ?
+												get_rightop(sub_rinfo->clause) :
+												get_leftop(sub_rinfo->clause);
+
+			opno = ((OpExpr *) sub_rinfo->clause)->opno;
+			if (!op_mergejoinable(opno, exprType(non_const_expr)))
+			{
+				/* And again, filter out non-equality operators */
+				or_list = lappend(or_list, (void *) bare_orarg);
+				continue;
+			}
+
+			/*
+			 * At this point we definitely have a transformable clause.
+			 * Classify it and add into specific group of clauses, or create new
+			 * group.
+			 * TODO: to manage complexity in the case of many different clauses
+			 * (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			 * like a hash table (htab key ???).
+			 */
+			foreach(lc_groups, groups_list)
+			{
+				OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+				Assert(v->node != NULL);
+
+				if (equal(v->node, non_const_expr))
+				{
+					v->consts = lappend(v->consts, const_expr);
+					non_const_expr = NULL;
+					break;
+				}
+			}
+
+			if (non_const_expr == NULL)
+				/*
+				 * The clause classified successfully and added into existed
+				 * clause group.
+				 */
+				continue;
+
+			/* New clause group needed */
+			gentry = palloc(sizeof(OrClauseGroupEntry));
+			gentry->node = non_const_expr;
+			gentry->consts = list_make1(const_expr);
+			gentry->collation = exprInputCollation((Node *)sub_rinfo->clause);
+			gentry->opno = opno;
+			gentry->rinfo = sub_rinfo;
+			groups_list = lappend(groups_list,  (void *) gentry);
+		}
+
+		if (groups_list == NIL)
+		{
+			/*
+			 * No any transformations possible with this rinfo, just add itself
+			 * to the list and go further.
+			 */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		 * Go through the list of groups and convert each, where number of
+		 * consts more than 1. trivial groups move to OR-list again
+		 */
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			ScalarArrayOpExpr  *saopexpr;
+			ArrayExpr		   *newa;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, (void *) gentry->rinfo->clause);
+				continue;
+			}
+
+			/*
+			 * Do the transformation. It's been a long way ;)
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+
+			newa = makeNode(ArrayExpr);
+			newa->element_typeid = exprType(gentry->node);
+			newa->array_typeid = newa->element_typeid; /* don't used in the case of one dimension, but exprType returns this value */
+			newa->multidims = false;
+			newa->elements = gentry->consts;
+			newa->location = -1; /* Position of the new clause is undefined */
+
+			saopexpr = makeNode(ScalarArrayOpExpr);
+			saopexpr->opno = gentry->opno;
+			saopexpr->opfuncid = get_opcode(gentry->opno);
+			saopexpr->useOr = true;
+			saopexpr->inputcollid = gentry->collation;
+			saopexpr->args = list_make2(gentry->node, newa);
+			saopexpr->location = -1;
+
+			/* TODO: study on these parameters. */
+			saopexpr->hashfuncid = InvalidOid;
+			saopexpr->negfuncid = InvalidOid;
+
+			/*
+			 * TODO: here we can try to coerce the array to a Const and find
+			 * hash func instead of linear search (see 50e17ad281b).
+			 * convert_saop_to_hashed_saop((Node *) saopexpr);
+			 */
+
+			or_list = lappend(or_list, (void *) saopexpr);
+			change_apply = true;
+		}
+
+		if (!change_apply)
+		{
+			/*
+			 * Each group contains only one element - use rinfo as is.
+			 */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			list_free(or_list);
+			list_free_deep(groups_list);
+			continue;
+		}
+
+		/*
+		 * Make a new version of the restriction. Remember source restriction
+		 * can be used in another path (SeqScan, for example).
+		 */
+
+		/* One more trick: assemble correct clause */
+		rinfo = make_restrictinfo(root,
+				  list_length(or_list) > 1 ? make_orclause(or_list) :
+											 (Expr *) linitial(or_list),
+				  rinfo->is_pushed_down,
+				  rinfo->has_clone,
+				  rinfo->is_clone,
+				  rinfo->pseudoconstant,
+				  rinfo->security_level,
+				  rinfo->required_relids,
+				  rinfo->incompatible_relids,
+				  rinfo->outer_relids);
+		rinfo->eval_cost=rinfo_base->eval_cost;
+		rinfo->norm_selec=rinfo_base->norm_selec;
+		rinfo->outer_selec=rinfo_base->outer_selec;
+		rinfo->left_bucketsize=rinfo_base->left_bucketsize;
+		rinfo->right_bucketsize=rinfo_base->right_bucketsize;
+		rinfo->left_mcvfreq=rinfo_base->left_mcvfreq;
+		rinfo->right_mcvfreq=rinfo_base->right_mcvfreq;
+		modified_rinfo = lappend(modified_rinfo, rinfo);
+		list_free_deep(groups_list);
+		something_changed = true;
+	}
+
+	/*
+	 * Check if transformation has made. If nothing changed - return
+	 * baserestrictinfo as is.
+	 */
+	if (something_changed)
+	{
+		return modified_rinfo;
+	}
+
+	list_free(modified_rinfo);
+	return baserestrictinfo;
+}
 
 /*
  * create_index_paths()
@@ -3309,11 +3576,16 @@ check_index_predicates(PlannerInfo *root, RelOptInfo *rel)
 	 * not, this is all we need to do.
 	 */
 	have_partial = false;
+
+	if (rel->reloptkind == RELOPT_BASEREL)
+		rel->baserestrictinfo = transform_ors(root, rel->baserestrictinfo);
+
 	foreach(lc, rel->indexlist)
 	{
 		IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
 
 		index->indrestrictinfo = rel->baserestrictinfo;
+
 		if (index->indpred)
 			have_partial = true;
 	}
#29Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Teodor Sigaev (#1)
Re: POC, WIP: OR-clause support for indexes

I apologize for breaks the original thread. In my defense, I can say
that I'm new to all this and I'm just learning. I will try to make as
few mistakes as possible.

I try to fix it by forwarding this message to you, besides it might be
interesting to you too. This message to you, because it might be
interesting to you too.

I'm sorry if I didn't state my goals clearly at first, but it seemed to
me that initially the problem I encountered was very similar to what is
described in this thread, only I suggested a slightly different way to
solve it.

I have described the problem more or less clearly here [1] and the worst
case, as it seems to me, too, but if this is not the case, let me know.

1.
https://www.mail-archive.com/pgsql-hackers@lists.postgresql.org/msg146230.html

On 29.06.2023 12:32, Alena Rybakina wrote:

Hi! I'm sorry I didn't answer you right away, I was too busy with work.

On 27.06.2023 22:50, Peter Geoghegan wrote:

On Tue, Jun 27, 2023 at 6:19 AM Alena Rybakina<lena.ribackina@yandex.ru> wrote:

I learned something new from your letter, thank you very much for that!

Cool. The MDAM paper is also worth a read:

https://vldb.org/conf/1995/P710.PDF

Some of the techniques it describes are already in Postgres. With
varying degrees of maturity.

The paper actually mentions OR optimization at one point, under
"Duplicate Elimination". The general idea is that ScalarArrayOpExpr
execution can "eliminate duplicates before the data is read". The
important underlying principle is that it can be really useful to give
the B-Tree code the context it requires to be clever about stuff like
that. We can do this by (say) using one ScalarArrayOpExpr, rather than
using two or more index scans that the B-Tree code will treat as
independent things. So a lot of the value in your patch comes from the
way that it can enable other optimizations (the immediate benefits are
also nice).

In the past, OR optimizations have been prototyped that were later
withdrawn/rejected because the duplicate elimination aspect was...too
scary [1]. It's very easy to see that ScalarArrayOpExpr index scans
don't really have the same problem. "Giving the B-Tree code the
required context" helps here too.

Thank you for the explanation and the material provided)
unfortunately, I am still only studying the article and at the moment
I cannot write more. To be honest, I didn't think about the fact that
my optimization can help eliminate duplicates before reading the data
before.

I am still only in the process of familiarizing myself with the
thread [1] (reference from your letter), but I have already seen that
there are problems related, for example, to when "or" expressions
refer to the parent element.

I think, I would face the similar problems if I complicate the
current code, for example, so that not only or expressions standing
on the same level are written in any, but also on different ones
without violating the logic of the priority of executing operators.

For example, this query works now:

postgres=# EXPLAIN (analyze, COSTS OFF)
SELECT oid,relname FROM pg_class
WHERE
  (oid = 13779 OR oid = 2) OR (oid = 4 OR oid = 5) OR
  relname = 'pg_extension'
;

                                                    QUERY PLAN
------------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_class (actual time=0.086..0.140 rows=1 loops=1)
   Filter: ((oid = ANY ('{4,5}'::oid[])) OR (oid = ANY
('{13779,2}'::oid[])) OR (relname = 'pg_extension'::name))
   Rows Removed by Filter: 412
 Planning Time: 2.135 ms
 Execution Time: 0.160 ms
(5 rows)

But I would like it works such as:

                                      QUERY PLAN
--------------------------------------------------------------------------------------
 Seq Scan on pg_class (actual time=0.279..0.496 rows=1 loops=1)
   Filter: ((oid = ANY ('{13779,2,4,5}'::oid[])) OR (relname =
'pg_extension'::name))
   Rows Removed by Filter: 412
 Planning Time: 0.266 ms
 Execution Time: 0.536 ms
(5 rows)

I analyzed the buffer consumption when I ran control regression tests using my patch. diff shows me that there is no difference between the number of buffer block scans without and using my patch, as far as I have seen. (regression.diffs)

To be clear, I wasn't expecting that there'd be any regressions from
your patch. Intuitively, it seems like this optimization should make
the query plan do almost the same thing at execution time -- just
slightly more efficiently on average, and much more efficiently in
some individual cases.

It would probably be very hard for the optimizer to model/predict how
much work it can save by using a ScalarArrayOpExpr instead of an
"equivalent" set of bitmap index scans, OR'd together. But it doesn't
necessarily matter -- the only truly critical detail is understanding
the worst case for the transformation optimization.

Yes, I agree with you and I have yet to analyze this.

It cannot be too
bad (maybe it's ~zero added runtime overhead relative to not doing the
transformation, even?).

I haven't seen a major performance degradation so far, but to be
honest, I have not conducted a detailed analysis on other types of
queries other than x=1 or x=2 or x=1 or y=2, etc. As soon as
something is known, I will provide the data, it is very interesting
to me.

At the same time, nbtree can be clever about
ScalarArrayOpExpr execution at runtime (once that's implemented),
without ever needing to make any kind of up-front commitment to
navigating through the index in any particular way. It's all dynamic,
and can be driven by the actual observed characteristics of the index
structure.

In other words, we don't really need to gamble (in the planner, or at
execution time). We're just keeping our options open in more cases.
(My thinking on these topics was influenced by Goetz Graefe -- "choice
is confusion" [2]).

Unfortunately, when I tried to make a transformation at the stage of
index formation, I encountered too incorrect an assessment of the
selectivity of relation, which affected the incorrect calculation of
the cost and cardinality. I couldn't solve this problem.

My diff (transform_or_v0.diff). I got this result:

CREATE TABLE tenk1 (unique1int, unique2int, tenint, hundredint);
insert into tenk1 SELECT x,x,x,x FROM generate_series(1,50000) as x;
CREATE INDEX a_idx1 ON tenk1(unique1);
CREATE INDEX a_idx2 ON tenk1(unique2);
CREATE INDEX a_hundred ON tenk1(hundred);

postgres=# explain analyze
select * from tenk1 a join tenk1 b on
a.unique2 = 3 or a.unique2 = 7 or a.unique1 = 1;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..15627479.50 rows=1250050000 width=32) (actual time=0.040..75.531 rows=150000 loops=1)
-> Seq Scan on tenk1 b (cost=0.00..771.00 rows=50000 width=16) (actual time=0.022..5.467 rows=50000 loops=1)
-> Materialize (cost=0.00..1146.01 rows=25001 width=16) (actual time=0.000..0.001 rows=3 loops=50000)
-> Seq Scan on tenk1 a (cost=0.00..1021.00 rows=25001 width=16) (actual time=0.011..22.789 rows=3 loops=1)
Filter: ((unique2 = ANY (ARRAY[3, 7])) OR (unique1 = 1))
Rows Removed by Filter: 49997
Planning Time: 0.427 ms
Execution Time: 80.027 ms
(8 rows)

The current patch's result:

postgres=# set enable_bitmapscan ='off';
SET
postgres=# explain analyze
select * from tenk1 a join tenk1 b on
a.unique2 = 3 or a.unique2 = 7 or a.unique1 = 1;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..22247.02 rows=1350000 width=32) (actual time=0.094..373.627 rows=1350000 loops=1)
-> Seq Scan on tenk1 b (cost=0.00..2311.00 rows=150000 width=16) (actual time=0.051..14.667 rows=150000 loops=1)
-> Materialize (cost=0.00..3061.05 rows=9 width=16) (actual time=0.000..0.001 rows=9 loops=150000)
-> Seq Scan on tenk1 a (cost=0.00..3061.00 rows=9 width=16) (actual time=0.026..42.389 rows=9 loops=1)
Filter: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
Rows Removed by Filter: 149991
Planning Time: 0.414 ms
Execution Time: 409.154 ms
(8 rows)

[1]/messages/by-id/1397.1486598083@sss.pgh.pa.us
[2]https://sigmodrecord.org/publications/sigmodRecord/2009/pdfs/05_Profiles_Graefe.pdf

Thank you again for the explanations and the material provided. I
will carefully study everything as soon as possible and will write if
there are any thoughts or if there are ideas about my patch.

--
Regards,
Alena Rybakina
Postgres Professional

#30Ranier Vilela
ranier.vf@gmail.com
In reply to: Alena Rybakina (#29)
Re: POC, WIP: OR-clause support for indexes

Em qui., 29 de jun. de 2023 às 06:56, Alena Rybakina <
lena.ribackina@yandex.ru> escreveu:

I apologize for breaks the original thread. In my defense, I can say that
I'm new to all this and I'm just learning. I will try to make as few
mistakes as possible.

By no means, your work is excellent and deserves all compliments.

regards,
Ranier Vilela

#31Ranier Vilela
ranier.vf@gmail.com
In reply to: Alena Rybakina (#26)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Em qui., 29 de jun. de 2023 às 02:50, Alena Rybakina <
lena.ribackina@yandex.ru> escreveu:

Hi!
On 29.06.2023 04:36, Ranier Vilela wrote:

I don't want to be rude, but this doesn't seem very helpful.

Sorry, It was not my intention to cause interruptions.

- You made some changes, but you don't even attempt to explain what you
changed or why you changed it.

1. Reduce scope
2. Eliminate unnecessary variables
3. Eliminate unnecessary expressions

- You haven't even tried to compile the code, nor tested it. If it
happens to compile, wow could others even know it actually behaves the
way you wanted?

Sorry I didn't answer right away. I will try not to do this in the future
thank you for your participation and help.

There's no need to apologize.

Yes, the scope of this patch may be small, but I am sure that it will
solve the worst case of memory consumption with large numbers of "or"
expressions or reduce execution and planning time.

Yeah, I also believe it will help performance.

As I have already said, I conducted a launch on a database with 20 billion
data generated using a benchmark. Unfortunately, at that time I sent a not
quite correct picture: the execution time, not the planning time, increases
with the number of "or" expressions (execution_time.png). x is the number
of or expressions, y is the execution/scheduling time.I also throw memory
consumption at 50,000 "or" expressions collected by HeapTrack (where memory
consumption was recorded already at the initialization stage of the 1.27GB
pic3.png). I think such a transformation will allow just the same to avoid
such a worst case, since in comparison with ANY memory is much less and
takes little time.

SELECT FORMAT('prepare x %s AS SELECT * FROM pgbench_accounts a WHERE %s',

'(' || string_agg('int', ',') || ')',
string_agg(FORMAT('aid = $%s', g.id), ' or ')
) AS cmd
FROM generate_series(1, 50000) AS g(id)
\gexec

SELECT FORMAT('execute x %s;', '(' || string_agg(g.id::text, ',') || ')') AS cmd
FROM generate_series(1, 50000) AS g(id)
\gexec

I tried to add a transformation at the path formation stage before we form
indexes (set_plain_rel_pathlist function) and at the stage when we have
preprocessing of "or" expressions (getting rid of duplicates or useless
conditions), but everywhere there was a problem of incorrect selectivity
estimation.

CREATE TABLE tenk1 (unique1 int, unique2 int, ten int, hundred int);
insert into tenk1 SELECT x,x,x,x FROM generate_series(1,50000) as x;
CREATE INDEX a_idx1 ON tenk1(unique1);
CREATE INDEX a_idx2 ON tenk1(unique2);
CREATE INDEX a_hundred ON tenk1(hundred);

postgres=# explain analyze
select * from tenk1 a join tenk1 b on
((a.unique2 = 3 or a.unique2 = 7)) or (a.unique1 = 1);
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..140632434.50 rows=11250150000 width=32) (actual time=0.077..373.279 rows=1350000 loops=1)
-> Seq Scan on tenk1 b (cost=0.00..2311.00 rows=150000 width=16) (actual time=0.037..13.941 rows=150000 loops=1)
-> Materialize (cost=0.00..3436.01 rows=75001 width=16) (actual time=0.000..0.001 rows=9 loops=150000)
-> Seq Scan on tenk1 a (cost=0.00..3061.00 rows=75001 width=16) (actual time=0.027..59.174 rows=9 loops=1)
Filter: ((unique2 = ANY (ARRAY[3, 7])) OR (unique1 = 1))
Rows Removed by Filter: 149991
Planning Time: 0.438 ms
Execution Time: 407.144 ms
(8 rows)

Only by converting the expression at this stage, we do not encounter this
problem.

postgres=# set enable_bitmapscan ='off';
SET
postgres=# explain analyze
select * from tenk1 a join tenk1 b on
a.unique2 = 3 or a.unique2 = 7 or a.unique1 = 1;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..22247.02 rows=1350000 width=32) (actual time=0.094..373.627 rows=1350000 loops=1)
-> Seq Scan on tenk1 b (cost=0.00..2311.00 rows=150000 width=16) (actual time=0.051..14.667 rows=150000 loops=1)
-> Materialize (cost=0.00..3061.05 rows=9 width=16) (actual time=0.000..0.001 rows=9 loops=150000)
-> Seq Scan on tenk1 a (cost=0.00..3061.00 rows=9 width=16) (actual time=0.026..42.389 rows=9 loops=1)
Filter: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
Rows Removed by Filter: 149991
Planning Time: 0.414 ms
Execution Time: 409.154 ms
(8 rows)

I compiled my original patch and there were no problems with regression
tests. The only time there was a problem when I set the
const_transform_or_limit variable to 0 (I have 15), as you have in the
patch. To be honest, diff appears there because you had a different plan,
specifically the expressions "or" are replaced by ANY (see
regression.diffs).

You are right. The v3 attached shows the same diff.

Unfortunately, your patch version did not apply immediately, I did not

understand the reasons, I applied it manually.

Sorry.

At the moment, I'm not sure that the constant is the right number for
applying transformations, so I'm in search of it, to be honest. I will post
my observations on this issue later. If you don't mind, I'll leave the
constant equal to 15 for now.

It's hard to predict. Perhaps accounting for time on each benchmark could
help decide.

Sorry, I don't understand well enough what is meant by points "Eliminate
unnecessary variables" and "Eliminate unnecessary expressions". Can you
explain in more detail?

One example is array_type.
As you can see in v2 and v3 it no longer exists.

Regarding the patch, there was a Warning at the compilation stage.

In file included from ../../../src/include/nodes/bitmapset.h:21,

from ../../../src/include/nodes/parsenodes.h:26,

from ../../../src/include/catalog/objectaddress.h:17,

from ../../../src/include/catalog/pg_aggregate.h:24,

from parse_expr.c:18:

parse_expr.c: In function ‘transformBoolExprOr’:

../../../src/include/nodes/nodes.h:133:66: warning: ‘expr’ is used uninitialized [-Wuninitialized]

133 | #define nodeTag(nodeptr) (((const Node*)(nodeptr))->type)

| ^~

parse_expr.c:116:29: note: ‘expr’ was declared here

116 | BoolExpr *expr;

| ^~~~

Sorry, this error did not appear in my builds

I couldn't figure out how to fix it and went back to my original version.
To be honest, I don't think anything needs to be changed here.

Unfortunately, I didn't understand the reasons why, with the available or
expressions, you don't even try to convert to ANY by calling
transformBoolExpr, as I saw. I went back to my version.

I think it's worth checking whether the or_statement variable is positive.

I think it's worth leaving the use of the or_statement variable in its
original form.

switch (expr->boolop)
{
case AND_EXPR:
opname = "AND";
break;
case OR_EXPR:
opname = "OR";
or_statement = true;
break;
case NOT_EXPR:
opname = "NOT";
break;
default:
elog(ERROR, "unrecognized boolop: %d", (int) expr->boolop);
opname = NULL; /* keep compiler quiet */
break;
}

if (!or_statement || list_length(expr->args) < const_transform_or_limit)
return transformBoolExpr(pstate, (BoolExpr *)expr_orig);

You are right, the v3 this way.

As I said earlier, these are just suggestions.
But thinking about it now, I think they can be classified as bad early
optimizations.

regards,
Ranier Vilela

Attachments:

v3-0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patch.txttext/plain; charset=US-ASCII; name=v3-0001-Replace-clause-X-N1-OR-X-N2-.-with-X-ANY-N1-N2-on.patch.txtDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6..99b12d4037 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -95,6 +95,294 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int const_transform_or_limit = 0;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, Expr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc_eargs;
+	Node 		   *result;
+	BoolExpr 	   *expr;
+	const char 	   *opname;
+	bool			change_apply = false;
+	bool			or_statement = false;
+
+	Assert(IsA(expr, BoolExpr));
+
+	expr = (BoolExpr *) expr_orig;
+	if (list_length(expr->args) < const_transform_or_limit)
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+
+	/* If this is not expression "Or", then will do it the old way. */
+	switch (expr->boolop)
+	{
+		case AND_EXPR:
+			opname = "AND";
+			break;
+		case OR_EXPR:
+			opname = "OR";
+			or_statement = true;
+			break;
+		case NOT_EXPR:
+			opname = "NOT";
+			break;
+		default:
+			elog(ERROR, "unrecognized boolop: %d", (int) expr->boolop);
+			opname = NULL;		/* keep compiler quiet */
+			break;
+	}
+
+	/*
+		* NOTE:
+		* It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		* a list of sub-restrictinfo args, and rinfo->clause - which is the
+		* same expression, made from bare clauses. To not break selectivity
+		* caches and other optimizations, use both:
+		* - use rinfos from orclause if no transformation needed
+		* - use  bare quals from rinfo->clause in the case of transformation,
+		* to create new RestrictInfo: in this case we have no options to avoid
+		* selectivity estimation procedure.
+		*/
+	if (!or_statement)
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+		
+	expr = (BoolExpr *)copyObject(expr_orig);
+	foreach(lc_eargs, expr->args)
+	{
+		A_Expr			   *arg = (A_Expr *) lfirst(lc_eargs);
+		Node			   *bare_orarg;
+		Node			   *const_expr;
+		Node			   *non_const_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+		bool 				allow_transformation;
+
+		/*
+		 * The first step: checking that the expression consists only of equality.
+		 * We can only do this here, while arg is still row data type, namely A_Expr.
+		 * After applying transformExprRecurce, we already know that it will be OpExr type,
+		 * but checking the expression for equality is already becoming impossible for us.
+		 * Sometimes we have the chance to devide expression into the groups on
+		 * equality and inequality. This is possible if all list items are not at the
+		 * same level of a single BoolExpr expression, otherwise all of them cannot be converted.
+		 */
+
+		if (!arg)
+			break;
+
+		allow_transformation = (
+		                        arg->type == T_A_Expr && (arg)->kind == AEXPR_OP &&
+							    list_length((arg)->name) >=1 && strcmp(strVal(linitial((arg)->name)), "=") == 0
+							   );
+
+
+		bare_orarg = transformExprRecurse(pstate, (Node *)arg);
+		bare_orarg = coerce_to_boolean(pstate, bare_orarg, opname);
+
+		/*
+		 * The next step: transform all the inputs, and detect whether any contain
+	 	 * Vars.
+		 */
+		if (!allow_transformation || !bare_orarg || !IsA(bare_orarg, OpExpr) || !contain_vars_of_level(bare_orarg, 0))
+		{
+			/* Again, it's not the expr we can transform */
+			or_list = lappend(or_list, bare_orarg);
+			continue;
+		}
+
+		/*
+		 * Get pointers to constant and expression sides of the clause
+		 */
+		non_const_expr = get_leftop(bare_orarg);
+		const_expr = get_rightop(bare_orarg);
+
+		/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table (htab key ???).
+			*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, non_const_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				non_const_expr = NULL;
+				break;
+			}
+		}
+
+		if (non_const_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = non_const_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->opno = ((OpExpr *)bare_orarg)->opno;
+		gentry->expr = (Expr *)bare_orarg;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this rinfo, just add itself
+		* to the list and go further.
+		*/
+		list_free(or_list);
+
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation. It's been a long way ;)
+			 *
+			 * First of all, try to select a common type for the array elements.  Note that
+			 * since the LHS' type is first in the list, it will be preferred when
+			 * there is doubt (eg, when all the RHS items are unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (OidIsValid(scalar_type) &&
+				scalar_type != RECORDOID &&
+				verify_common_type(scalar_type, allexprs))
+			{
+				/*
+			 	 * OK: coerce all the right-hand non-Var inputs to the common type
+			 	 * and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = get_array_type(scalar_type);
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1; /* Position of the new clause is undefined */
+
+				saopexpr = (ScalarArrayOpExpr *)make_scalar_array_op(pstate,
+												   list_make1(makeString((char *) "=")),
+												   true,
+												   gentry->node,
+												   (Node *) newa,
+												   -1); /* Position of the new clause is undefined */
+
+				/*
+				* TODO: here we can try to coerce the array to a Const and find
+				* hash func instead of linear search (see 50e17ad281b).
+				* convert_saop_to_hashed_saop((Node *) saopexpr);
+				* We don't have to do this anymore, do we?
+				*/
+
+				or_list = lappend(or_list, (void *) saopexpr);
+				change_apply = true;
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		if (!change_apply)
+		{
+			or_statement = false;
+		}
+		list_free_deep(groups_list);
+	}
+
+	if (or_statement)
+	{
+		/* One more trick: assemble correct clause */
+		expr = list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, list_copy(or_list), -1) : linitial(or_list);
+		result = (Node *)expr;
+	}
+	/*
+	 * There was no reasons to create a new expresion, so
+	 * run the original BoolExpr conversion with using
+	 * transformBoolExpr function
+	 */
+	else
+	{
+		result = transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	list_free(or_list);
+
+	return result;
+}
 
 /*
  * transformExpr -
@@ -208,7 +496,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (Expr *)expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 260854747b..01918e6aea 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1630,6 +1630,7 @@ NumericSumAccum
 NumericVar
 OM_uint32
 OP
+OrClauseGroupEntry
 OSAPerGroupState
 OSAPerQueryState
 OSInfo
v3-regression.diffsapplication/octet-stream; name=v3-regression.diffsDownload
diff -U3 /usr/src/postgres_or/src/test/regress/expected/create_index.out /usr/src/postgres_or/src/test/regress/results/create_index.out
--- /usr/src/postgres_or/src/test/regress/expected/create_index.out	2023-06-28 17:18:07.675450560 -0300
+++ /usr/src/postgres_or/src/test/regress/results/create_index.out	2023-06-29 05:08:23.371385428 -0300
@@ -1838,18 +1838,11 @@
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,20 +1854,17 @@
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff -U3 /usr/src/postgres_or/src/test/regress/expected/join.out /usr/src/postgres_or/src/test/regress/results/join.out
--- /usr/src/postgres_or/src/test/regress/expected/join.out	2023-06-28 17:18:07.655450559 -0300
+++ /usr/src/postgres_or/src/test/regress/results/join.out	2023-06-29 05:08:25.699385494 -0300
@@ -4184,10 +4184,10 @@
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4197,15 +4197,13 @@
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff -U3 /usr/src/postgres_or/src/test/regress/expected/stats_ext.out /usr/src/postgres_or/src/test/regress/results/stats_ext.out
--- /usr/src/postgres_or/src/test/regress/expected/stats_ext.out	2023-06-28 17:18:07.651450559 -0300
+++ /usr/src/postgres_or/src/test/regress/results/stats_ext.out	2023-06-29 05:08:31.491385660 -0300
@@ -1322,19 +1322,19 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff -U3 /usr/src/postgres_or/src/test/regress/expected/partition_prune.out /usr/src/postgres_or/src/test/regress/results/partition_prune.out
--- /usr/src/postgres_or/src/test/regress/expected/partition_prune.out	2023-06-28 17:18:07.731450561 -0300
+++ /usr/src/postgres_or/src/test/regress/results/partition_prune.out	2023-06-29 05:08:37.359385827 -0300
@@ -82,23 +82,23 @@
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
 explain (costs off) select * from lp where a <> 'g';
@@ -515,10 +515,10 @@
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +596,13 @@
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -1933,10 +1933,10 @@
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
@@ -2265,11 +2265,11 @@
          Workers Launched: N
          ->  Parallel Append (actual rows=N loops=N)
                ->  Parallel Seq Scan on ab_a1_b2 ab_1 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a2_b2 ab_2 (never executed)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a3_b2 ab_3 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
 (16 rows)
 
 -- Test pruning during parallel nested loop query
#32Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Ranier Vilela (#31)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!

At the moment, I'm not sure that the constant is the right number
for applying transformations, so I'm in search of it, to be
honest. I will post my observations on this issue later. If you
don't mind, I'll leave the constant equal to 15 for now.

It's hard to predict. Perhaps accounting for time on each benchmark
could help decide.

I will try to test on JOB [1] (because queries are difficult for the
optimizer due to the significant number of joins and correlations
contained in the dataset) and
tpcds [2] (the benchmark I noticed contains a sufficient number of
queries with "or" expressions).

Sorry, I don't understand well enough what is meant by points
"Eliminate unnecessary variables" and "Eliminate unnecessary
expressions". Can you explain in more detail?

One example is array_type.
As you can see in v2 and v3 it no longer exists.

I get it. Honestly, I was guided by the example of converting "IN" to
"ANY" (transformAExprIn), at least the part of the code when we
specifically convert the expression to ScalarArrayOpExpr.

Both there and here, we first look for a common type for the collected
constants, and if there is one, then we try to find the type for the
array structure.

Only I think in my current patch it is also worth returning to the
original version in this place, since if it is not found, the
ScalarArrayOpExpr generation function will be processed incorrectly and
the request may not be executed at all, referring to the error that it
is impossible to determine the type of node (ERROR: unrecognized node
type. )

At the same time we are trying to do this transformation for each group.
The group here implies that these are combined "or" expressions on the
common left side, and at the same time we consider
only expressions that contain a constant and only equality.

What else should be taken into account is that we are trying to do this
processing before forming a BoolExpr expression (if you notice, then
after any outcome we call the makeBoolExpr function,
which just forms the "Or" expression, as in the original version,
regardless of what type of expressions it combines.

As I said earlier, these are just suggestions.
But thinking about it now, I think they can be classified as bad early
optimizations.

Thank you again for your interest in this problem and help. Yes, I think
so too)

1. https://github.com/gregrahn/join-order-benchmark

2.
https://github.com/Alena0704/s64da-benchmark-toolkit/tree/master/benchmarks/tpcds

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

0001-Replace-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=0001-Replace-OR-clause-to-ANY-expressions.patchDownload
From f9f5958707bc1d7931323df05d51a60fc9d6cd38 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 29 Jun 2023 17:46:58 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than 15 or
 expressions. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

---
 src/backend/parser/parse_expr.c  | 290 ++++++++++++++++++++++++++++++-
 src/tools/pgindent/typedefs.list |   1 +
 2 files changed, 290 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6d..3d395fd6459 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -95,6 +95,294 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int const_transform_or_limit = 15;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, Expr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc_eargs;
+	Node 		   *result;
+	BoolExpr 	   *expr = (BoolExpr *)copyObject(expr_orig);
+	const char 	   *opname;
+	bool			change_apply = false;
+	bool			or_statement = false;
+
+	Assert(IsA(expr, BoolExpr));
+
+	/* If this is not expression "Or", then will do it the old way. */
+	switch (expr->boolop)
+	{
+		case AND_EXPR:
+			opname = "AND";
+			break;
+		case OR_EXPR:
+			opname = "OR";
+			or_statement = true;
+			break;
+		case NOT_EXPR:
+			opname = "NOT";
+			break;
+		default:
+			elog(ERROR, "unrecognized boolop: %d", (int) expr->boolop);
+			opname = NULL;		/* keep compiler quiet */
+			break;
+	}
+
+	if (!or_statement || list_length(expr->args) < const_transform_or_limit)
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+
+	/*
+		* NOTE:
+		* It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		* a list of sub-restrictinfo args, and rinfo->clause - which is the
+		* same expression, made from bare clauses. To not break selectivity
+		* caches and other optimizations, use both:
+		* - use rinfos from orclause if no transformation needed
+		* - use  bare quals from rinfo->clause in the case of transformation,
+		* to create new RestrictInfo: in this case we have no options to avoid
+		* selectivity estimation procedure.
+		*/
+	foreach(lc_eargs, expr->args)
+	{
+		A_Expr			   *arg = (A_Expr *) lfirst(lc_eargs);
+		Node			   *bare_orarg;
+		Node			   *const_expr;
+		Node			   *non_const_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+		bool 				allow_transformation;
+
+		/*
+		 * The first step: checking that the expression consists only of equality.
+		 * We can only do this here, while arg is still row data type, namely A_Expr.
+		 * After applying transformExprRecurce, we already know that it will be OpExr type,
+		 * but checking the expression for equality is already becoming impossible for us.
+		 * Sometimes we have the chance to devide expression into the groups on
+		 * equality and inequality. This is possible if all list items are not at the
+		 * same level of a single BoolExpr expression, otherwise all of them cannot be converted.
+		 */
+
+		if (!arg)
+			break;
+
+		allow_transformation = (
+								or_statement &&
+		                        arg->type == T_A_Expr && (arg)->kind == AEXPR_OP &&
+							    list_length((arg)->name) >=1 && strcmp(strVal(linitial((arg)->name)), "=") == 0
+							   );
+
+
+		bare_orarg = transformExprRecurse(pstate, (Node *)arg);
+		bare_orarg = coerce_to_boolean(pstate, bare_orarg, opname);
+
+		/*
+		 * The next step: transform all the inputs, and detect whether any contain
+	 	 * Vars.
+		 */
+		if (!allow_transformation || !bare_orarg || !IsA(bare_orarg, OpExpr) || !contain_vars_of_level(bare_orarg, 0))
+		{
+			/* Again, it's not the expr we can transform */
+			or_list = lappend(or_list, bare_orarg);
+			continue;
+		}
+
+		/*
+		 * Get pointers to constant and expression sides of the clause
+		 */
+		non_const_expr = get_leftop(bare_orarg);
+		const_expr = get_rightop(bare_orarg);
+
+		/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table (htab key ???).
+			*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, non_const_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				non_const_expr = NULL;
+				break;
+			}
+		}
+
+		if (non_const_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = non_const_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->opno = ((OpExpr *)bare_orarg)->opno;
+		gentry->expr = (Expr *)bare_orarg;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this rinfo, just add itself
+		* to the list and go further.
+		*/
+		list_free(or_list);
+
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation. It's been a long way ;)
+			 *
+			 * First of all, try to select a common type for the array elements.  Note that
+			 * since the LHS' type is first in the list, it will be preferred when
+			 * there is doubt (eg, when all the RHS items are unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (OidIsValid(scalar_type) && scalar_type != RECORDOID)
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+			 	 * OK: coerce all the right-hand non-Var inputs to the common type
+			 	 * and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = get_array_type(scalar_type);
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1; /* Position of the new clause is undefined */
+
+				saopexpr = (ScalarArrayOpExpr *)make_scalar_array_op(pstate,
+												   list_make1(makeString((char *) "=")),
+												   true,
+												   gentry->node,
+												   (Node *) newa,
+												   -1); /* Position of the new clause is undefined */
+
+				/*
+				* TODO: here we can try to coerce the array to a Const and find
+				* hash func instead of linear search (see 50e17ad281b).
+				* convert_saop_to_hashed_saop((Node *) saopexpr);
+				* We don't have to do this anymore, do we?
+				*/
+
+				or_list = lappend(or_list, (void *) saopexpr);
+				change_apply = true;
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		if (!change_apply)
+		{
+			or_statement = false;
+		}
+		list_free_deep(groups_list);
+	}
+
+	if (or_statement)
+	{
+		/* One more trick: assemble correct clause */
+		expr = list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, list_copy(or_list), -1) : linitial(or_list);
+		result = (Node *)expr;
+	}
+	/*
+	 * There was no reasons to create a new expresion, so
+	 * run the original BoolExpr conversion with using
+	 * transformBoolExpr function
+	 */
+	else
+	{
+		result = transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	list_free(or_list);
+
+	return result;
+}
 
 /*
  * transformExpr -
@@ -208,7 +496,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (Expr *)expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 260854747b4..cc1b676d200 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1631,6 +1631,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

#33Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Ranier Vilela (#30)
Re: POC, WIP: OR-clause support for indexes

On 29.06.2023 14:23, Ranier Vilela wrote:

Em qui., 29 de jun. de 2023 às 06:56, Alena Rybakina
<lena.ribackina@yandex.ru> escreveu:

I apologize for breaks the original thread. In my defense, I can
say that I'm new to all this and I'm just learning. I will try to
make as few mistakes as possible.

By no means, your work is excellent and deserves all compliments.

Thank you, I will try to work in the same spirit, especially since there
is still quite a lot of work left).

Thank you for your feedback.

--
Regards,
Alena Rybakina
Postgres Professional

#34Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Alena Rybakina (#29)
3 attachment(s)
Re: POC, WIP: OR-clause support for indexes

HI, all!

On 27.06.2023 16:19, Alena Rybakina wrote:

Thank you for your feedback, your work is also very interesting and
important, and I will be happy to review it. I learned something new
from your letter, thank you very much for that!

I analyzed the buffer consumption when I ran control regression tests
using my patch. diff shows me that there is no difference between the
number of buffer block scans without and using my patch, as far as I
have seen. (regression.diffs)

In addition, I analyzed the scheduling and duration of the execution
time of the source code and with my applied patch. I generated 20
billion data from pgbench and plotted the scheduling and execution
time depending on the number of "or" expressions.
By runtime, I noticed a clear acceleration for queries when using the
index, but I can't say the same when the index is disabled.
At first I turned it off in this way:
1)enable_seqscan='off'
2)enable_indexonlyscan='off'
enable_indexscan='off'

Unfortunately, it is not yet clear which constant needs to be set
when the transformation needs to be done, I will still study in
detail. (the graph for all this is presented in graph1.svg

I finished comparing the performance of queries with converted or
expressions and the original ones and found that about 500 "OR"
expressions have significantly noticeable degradation of execution time,
both using the index and without it (you can look at
time_comsuption_with_indexes.png and time_comsuption_without_indexes.html )

The test was performed on the same benchmark database generated by 2
billion values.

I corrected this constant in the patch.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

time_comsuption_with_indexes.pngimage/png; name=time_comsuption_with_indexes.pngDownload
�PNG


IHDRv�#��sBIT|d�tEXtSoftwaregnome-screenshot��>.iTXtCreation Time���� 05 ������ 2023 21:57:45��T� IDATx���{t�U���wM��`��FJ�m�P�T��P�6T9Ta�����yt����Q��sP��k<G�*L������&�r9���)��FeRiHi��}�h��R)���k-�2�e���/�,W>��#���P """"""""""""�Q�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""�A�.)d��U���#��������?0c�B�PDY�k
������Y�y��z�����[p�K!��3�Im�tWN�����D_���,*<�gjT�?�<�������]:x������Yh�3z}��o}ODDDDD.��P """rA�J
&����/�&��K��.yI�eT�?q=�o&�����e2-*�����}>�^,b����o������	iMa"!��Y����~���^����_�BL�N�4�+Qy$�L�<2�~)���`?�y7>Y�o~�2DDDDD$H
vDDD���0�f�#���,���PzN��WA������DN��(��j��@������b~Uew�9���E��/<�����g�9(��*�P��::=�E`��B7WDDDDD�M������!:gb+�_���=e$��9�7�����y���/����L�������k_���G,}o�b�}ID�����E���r�U`s�3��!L��d��K
y��J�G��|S"S>������,�����e��0sM.�'p����B�f�P���x�g�/+_���+��� �t`x��Z�����(W<��F�({��zYu�b
�7?|�
f<����0�������R:������1����9��#N}���xz}������[�����L�k�]��q��O�Co���8����^*��m@��mQv��'��"���]i��N�[��Rp�����<<�}2����$��*~����rH����(�����d�
-�K�c?��
���MOGO��&�|!���,��~��&F�g�S�������o1'������i�}�������)L���a����z:g�g���N���
�?��UE^�X2�O��H��;Y��6J���Zq�����f�j��c��,������A�	�G��K�������j:��m����]��	DZ�:�@z��W�w�v�$��m����/�F��>��x&��6�� x>^���}���������-��{������7=L�9���;#�3���n�+���9�I�=��2���i����v=&d3�����i��{�*^}���uV\�2��x�����3&�����������#"""���L�?d�t�J�%���5m$y��~�|^������9/m����������xOv�^����yn/���#�����,�������J:��D�}2�y�3o��P�5sR��/�q���������I���?����4���2��6���_��56�����w�����x�#���R;��3o}.&2���\�t�-hu0p��?6��j�8����M�>���81��{����p{.O|7/,IN\+CO0�XHH�QST�[|d>5��>��9/������6�|�C�3S��q:/��M��"
>�W�+���j<����9p\M���<�i:�>J���pnJd�_�0%��s������GO{Y����I��Ew��������E��g��5vr_m����g��&l����Y2����m��rb��WV�����:�y����2J[�Q��������#���t�-��_U	�����L}�����i
,k�_O��$��
>������7�������I7Y���+4���s��P�D��0k��b�����(a�k��8�=	B�6�����<^Z7���R����c4��4~��t�m�t���3������b���i��y&���l����8;���%�����7�/��Z��Yt�w:����Ci<��n^Z�ALQ1�i��>�����������H�Q�#"""����-e��?��3�=
�����0�)�+X�b���Q����i����}�{_��E����m=��7!��=x�
6�w�/�2�����k�f>�E���n���H0�0[L���M���-���z�q�bI���~���E�t�V`T���#���M���L��,���e�����1�0[MM��D�-�5*Y���/��In'a�F�U�6��i���:�ic�q:,D'����S��D;���p=:��7��9l8-��j5�	��i`s�$�,�����\��G����
�_A�}Kyn~���{2�0�����tb���S��{�`����t\����C{�W��>��>�:��$FL�o
�R����8F%��q��A�8�b'��tZ�[��R[:y��'�8�{���6���Dv`Kd�3}��f������2g
!�<[����QSf���V����La���M�q0s��$��;��xN��4�N�.5��� �6���J%wb��1�~���eB��W��s��&1QM_[�<��8�������Ne�6�z������]�g�;'#�O�i3a���-�m**o��-��s��8���������m�&"""���������;�3��1���O]�|��Ol	���������?��.N<8�G8Tm"!���Q���2*��Gbt�Y�)H0�<�;�|�O���l� >�����{��j	�-�����2Q�>c��~C��+��qI���J��������o�6�}��}-��A&L�h\��r�{(5�D����^��Y?������N������}>���E���M@C�8��8Z|��8m�\}r�����
�����M<U@�m1���in�<R�s�8fj��M�$n�/���^��o��wP7���"����~9Gk�n� ?{��4��z�����QjU��������e���mo9a|2W���[����F����D���PO��E�_���^���3�O����3�k���
�y?c���'"""""�~������!6������^���7a6j9x���~�o�k�#����s"�i�&�x7����4��
k%��#��s��B��������w2po9�En�6�2��Rr����28���)L*�_��=���y�V�}O"�
+]S�pK�~�������f�g�p���T���f��@-5$6o�,���x������i?�Q��{���}A���m,�U���1������KynS�
�Am[���K����ZN��rv���U�wc��\v����yu�������`f������g�c:�����r�����DDDDDD���b�����KL�c3��.b���l$�������F�j/�'������ap�@�C#��[V����K��f�%!�������|�}�����zO�t���h�U%�8N�g`��D�������[��/�������`9�[m��1�~YP����A��������a�9��;^QM��]�c���}����9���O����X���K��b.i�/�>s���2�2�6f?����v�� �9�U����L�o�
�����v_Uo�J/U'�
�C�k�>�a�[pf����H^2���r��oz?;=�z�1|p��%��?P	��iq����q��V�@�q�i?
vDDD��P[���{�����R
����U���{�qMI�ko���9�1�k������h��;������_k>������v��S��O��s��b�_*�`�9�9���������V�����}����a�������M��Lp��S1�����b~?�=ol�E���i��`ppY1k��sK��b\�qj�}�o�QZ�|�=���9���s;�I�MWN<uk��q�����1���+P�����5���W���p5�/�i���
�����T����`����c��^);�=�}�K�Z����*g��{���jkg2���N��r��7_����C�#�)���v�j��nC-{���-�~�P�}��U����"�9j��ca������b6}co=u�85���py��j��a�����������o44��=�S��[<1��d@�;PI��JBb��q���]���{)���r+���O�|�����g@�]��>\#�N�	u��~UU�g���=�����DDD��pp�
f-:���><�,����,,�$w�\;���i�xs��_��c������x����8���e$�<���L����~��*�%����8�nh���=����f���<�`�K��y���`�z��Yv����#`5����U\�����_�_{���`v�3����8�}iu�?���u���u��C^����v�]��?�i�u�����F�Q���?�p���$�j?
�]M[R�v�Z���4G��~�������#x`!E]�y��CIo�*/s�6=Y�sJ1�l8e2c��������R�]�rUL1�����<<1��L�}`(�O����N>����ExN���>��/la����6�����2��Z3��}����a��4�9+���������F6������?��#�����0 ��3+�i�d�����s�_&'{X��[�8l$��f��u���-�8��#�fD)������=,|�����H����;��}�h����c�o�xk�6��������E���a!�������o)��l�N���{r;'d3v�:�'���.���w3�����y����y$����������<G�t������������.����|�6�f^��t��8���������������P!""""""""""""��;""""":�����
|�X��4q$y��Y�#"""""r����0qE���(�	
vDDDDDDDDDDDD�Dd��!�u
x}�P�!"A���D����.CD��9+^4gE����Hx��iW�X1Gj�����,	a�466���K.,�����P� """""""""""r��e�#"""""""""""�c�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD�DX;����.ADDDDDDDDDDD���`'"""�%������������\r��.@DDDDDDDDDD�r�~e1�����K"S�:��q����T�a��[���&l9��~��!.�$��������$�z����R�#""""""""""r�����T�|�����n~5���Nr�_�fk~�6�K���sQ�#""""""""""r����1//�`�����7&����`��
�����s��?����Kyv���w�������zb�c��Dl~k�]�����S��8k}���xiF	�^?>Jx~l	1������}��X���:G"��g�{6�R�K
y���-��y��6p�����`r15���?=�kZ��;)q;�}�H��Y<g;��L��a�=�5c�.X��?V���:"��� �f��b���~���^�c�hf��[x��uL��`��m�:XO`�0^���t����9%��4���������v�.�
�?����.E�b�?v�z��V��8R�s\��;���KZ�����{3���
M$$�(gkG����n$��_�*#����������(�Ia�`�L���a��V����.��_l���<r��oE1�u���,�h�K����K��vH����3���b���h�iU��l��
LL}�N2�<1��-$-�&����D���7�>L]2�T{sC�x�$M�73knS��#i�RJJ
�����u������c�.'���,�1��C-P��E�x�|u
y=Mx��`������w���r���9�������f�fU���t�%�z�_n`�sS���2�1����9s����R��vHcx���P�C466����v���?��m���J>|


�.I�0�k������l�]�w�l_�Pw�5FEG�y����>0�9s����q$��fP[Y��N�m^��O��>j<��lV�s�
k*���pM���v����r�1��8����V���@��,�V�?�q*�9�FR/;6�[.�����p����N���T�#��,�X{���w����+����H
r��o���]R������g:�za�V_��l�z�c��I>s��H{$���l������GGv�P�t�NDDD�K9��!p��w�}AU����N��������
]o����^����<����	��p�e�/��2
��b�"#�s8G�|E$f��G����F
�W�V������'&+��_g�y����0�y
b\-:�Z����y[�ew�t��L&����em*���-T�SW_I�/�����5@������h+�[�k�:_�M|��k;�1v���C�Fof�W��������%���.�UVz����M�0g�e�#"""""""""�����A��=�Z;����|^����\��c��k{���<	'���loxX�d1o�c�=N��X;s1�Awj!uB63'd����/�$�e'���q�h�d1�&j<>���T���:I-W��"�68�DY��]2���,
�"���c��J�����(��
G|�����������[+��`����	��r
g�&Y7��*��-,�b�h��N�u7�G����y�}{�qe���|&�=b1�/vQ����7�j�������R�lD��z�<RoL�O�(�08��2�uO��|+'tI�o�x��2�l~y����{'�����/���l�����6(�^�������_��������c5��v�

�7�[s����H,��,�
��ig}�]O\���
�H�qm��	���V|�����>\S<#�����Kyv�g�>��?�W����21���]��������9V$1uVZP��m����j��6qIL���g�.�m��>9����yb����2���������gV�����`��4!�����m��'.����f�,e��;��F�{������?>�7�c)��LDge1m|0��������"��[���8�E$��c;Qy����H��9+^4gE����Hx��9���:*���������x�q����������|���5�������W~�3O�[��V.ry
�;a�E���������H���|�m�]B]�%UYy�������W�9���b����>\q�Nia�����������\Juu>�]��#G���i�����P�t���z�l���G�2z��V_wUlC��k�NX,V����X,X���v�b�u>�8f��[��VL���p��NDDD�K�	����%�8�m7�o�P�[[Kcc#�11��_�J�g�7m�__��?�S�����M���KY(�� IDAT���CX;""""""""""���UU�y��;z�A?�!������w�}����R}�[����5���������J����6�;v��D�
����j�#"�����<t�w����uu���Md�d@��}�W��������t1�oF�O��[�g�������U=������S���~����C��������������_���%

���	�_������q8	��X�A!?]�������bm�����z�)Y������"ri\�~����P� """""""""�1�h ""���n�(��	�=���i��s^��=_���x���������3��a#������0LIj}��5��	B|l'*�u"$�Y���9+^4gE�������j�tI�jX������w"�f���6[�K2��ru�sdX�5�P:�,2�Y~�Bf��
O�S!-IDDDDDDDDD.�*��4��w#~v�22���~>+Z����"V("E�?c�`�6WY1�����+�'�~mCC��le��������8#G�t��vx?�S��K����]��65��l�W[P��%�����8���mM���<1����y�y(��z��t�`�b'+b�8-������3���>g�g8v�(��L'�V�+�s������������%��6^}x�&1}�%�^�G
��L]@��5�Q#ya��}����_i]v����y��Zu��0<HDDDDDDDDD:�o�v��{{�]��vl�?]���^Rz��s�p�t�*��@��p2��t�@�L������}�F�c�`��oQ�5����,�P�����$�z��y��eT�
|	��i�n��V���Jv����}��SS���<m�JO^G��|�+�Tz�K�`��\�/��`E5~,�z1���m�]��=���7�	��l�?�Dt�{:���{X��zVm������Y�SWG�a����������,||�5{����:l�"�����c/�~�"ra4gE����Hx��	/�������,�{����{���������g���4~z���g?E���C]V���.��`�������V�'%%�����u��Caaa��m6S�Li�z`5���Zdp]�cac5�H5�HH�Q��:���c'mj�A�l���l���������2
^>B�+S��
���x�rLA��x)��o_@4�L����a�h���,���]K����e�CKY�NR;l�V��'7P>tO�����`�=+y�5�_��������f��t�1p/)b�V/}G�/����c�#U{������r6 p�������|VD:���NT9�2D$H��"�EsV$�h����p�������OO{.g�pe����o����+?j�z���?ab��j��w����o�&��^X��:l>�����p8�&9 l��:����;��_��u���'��s����(�`��r�5��>?���Q���'��3B���UP�%�����&����4�0�>:�yL'Ii{�|���a����l��+�N�~��������{����~��e�����a�<��f�=��&�!��qMJ�����C;����pWR6���'��|�xn��~=��C[���������H�����|^��+�����=�|LL�9ZA������
�h�����w�444`44p�W\��/����,]L��
����1��uImr�
�C]B����?���?�}BB���oxQ��8_=��t>��	��p�!�5��D�hg�&���t��v��f ������U��PR���H<^�0�V��T��5Y�q�z**�J`{=u��Z��Q��������������J'���d&^xi]�v��ryi�����W���ylAN���DDDDDDDDD:��?��������.L�<����5K��i����c���j��[�U|�5+W|��Un�?���n
uIr	EDDqA}\H�iNs���w%�7���x1���2�0��g{s�	���:0�Zj��{
R0v�_���Lf���������6�
5�@��8u�z�+Q-_�����:!����[���W����^s���}wl�O�.""""""""�#���OHd��_�)�i�|�OV~DC����e�g���7������)��K�����#�}���>���F��}�']pa�O��nJ��{��5��YP|�zl�N����M��`��s����<�I���a�����X��Y��G��IAm�������Mm�R�lDr������b�L��73o������=dKDDDDDDDD���w���r����o����e��%��������5��\����#����:l$��kB]��(��}&��g�x~�zv'���2mps��Px�
���0����Q;�K��1�Gn��������qvR�R��,kJ��6�\���#����x��N�+�133({r+/��c���|ebV<�/7����^p�-��>3��9�x�}�0�u�M�5:���\��������i
���IL����v"�0%��8Z�Nq��\T�|�������Hx��	/��"�Es�mj��Y����_���L��u�C&�����b��&R��Q���[q�zy��.F�[X���QDDDDDDDDD�O����w���[�������R^_0������D~$��}t1�_�tB�o�����HqYrQ�e�#"""""""""�u}�r���L��39z���K���$c��[�|��%K���3pZ:��
yt��<�b-���E_-��,��;"""""""""���a�v;�:E���VY���=��z���o���:_����Z>+���>'��d&N��EO�����d���P�!�@X;ax,�������������k�+�11~y�}�.�������J�h�������S>/�
@�Uq�d���6��HG��������������W�Q��������<$���T��g��b�n�D���ST�s��qC��B'O���/,�����P� """"""""rI�}�����H��	'sMrj�Kj7����y[����������rn����b�'"�!�e�#""""""""�c�}���Z�!�N����S�����������q�:F�M�^������`�43l�(b��X��H��`GDDDDDDDD��l��|�a=Q6�����8g�KjW
��c����=������c��:��]����H�y	*������������t@�����q0��;���	u9���@�Sz�������.���>2�>}3B]��H������"����h]C��� ��v����P�!"A��	/��"�EsV$�t�9�C��	G����O���! !�cn������]c�yE���+�y�u��/X���q���5��b�����/��0a��f�}�qY'���-&�?'��#���VX�����u	"""""""""��!�����z�b���j�>>��)cn��D����)��@5�����;��WcM�.�$��%l���7k3H���9��vDDDDDDDDD��b�G�����{���&9%����������(k���)X���g'��I���+X>gkv��0�5�����4�R������&v����������13����g��j{=��4&�@�8��6^�QB�����[@��1<�@<�g_�:-����H�����M�T��B�*��#C�ys^9��
\�:��&z)�\L� +�O�����m�NJ�Nn_0��q@�~����&��C�vOs��V�����6��Hl�+��Y���7��C~�d�����2��`���u�:�0{��<����5]w�!N	�*
�D�����u�`GDDDDDDDDD:����u	r��{d/������n�n�fh��������~�����(nM��*4��l���u�=��>N$�E��/��Lf/O'�z�'o�0'���M`2a���]�[yp�����~�����������f��t�1p/)b�V/}G�!9��?�`���Yhc����U�[���*01��;��3�|��'���$�TD'����4�0u�HR��

/���4��<T���LY6��YK))58���'��7kO�������V���$��@�N��%��)��4�Y��9^H
�V���'��:���*�B`�����U�ncl2�=���],~����Mafr���`�k88����j�K��[�q ��d8;""""�&e_�d����M���#�������5�����y2"�@u]5��v����F�9��-�V�+*:����z����$����,�D��J+��y}�N�m^��O��e�x�.��
{�aM,C���<�)A����r��&2�L8����J	�d���[�T[��P��P�$I������D��[9��:o=.�d��!��7��Hb�(/�=D`h|Q�;�����A��i��TT���n�vI����=��=��k%[}�M�����R�sl69�g.�1i��S����������GGy�.��vC]���������(�����#|��[����������?/y�"���X,�P�$rY���A����^�4����.�.<��H����lx���:��_�]e���>DF6P�6p�h��H��S��-��m�0~�-a�;�y��zb����u6��/�9�� ���c������XvIg��d�li~_����M�Bu=u����m><9\d�
�z������� ��U�C��T[l������� �l��J���}���=��5��%��J�����������vDDDD��0�����M�Q[SMDD}�]�������C]����H�:|���%�p����#s��\�+������t�	���W�����loxX�d1o�c�=N��X;s1�Awj!uB63'd����/�$�e'���q�h�d1�&j<>�����������V�"�68�DY��]2������-j�9D�|�������������91q�'3����98s$gB����Y��_���&_��?W����}�O9�o��X��<�{�G��T�+�7wO���1���4l�\L������1���K�.~���%��9^WG����?k`������g��#3��b�{�~#�����_PM�� 5�F$��g�#��$����*��-c_��'���rB�����a���.����WQ����w"���l�������!��m���ux?k?o�+�E�8�;��1V/kg��p{��5':I���b:�2���9����hll$5�Z���yu���4���aQQ6�0!"""���G���������G9v�(���w�(I�)�������ap��A�V+�������5���z_�w "a���{�2�R�]d���c�O��?~DA��LL>ws��tb����wN�IL��T�c:�>��E��M@\���Y��k;�O�f�j�o`�D���f6��q����,|�-6�m$MH����i���K��g�Y�K��7��N�����w����������X��:�YYLL(tiD4���5����@��� ��v����P�!"A���3?^G�N�mb\�����r7wM�A\��"W&�9+n4gE����u��������v=�vf�w��*�?Z����F��S���9g7nXG��
����q7�|K����(]c���H�t(Z�#""""�
6�HN���/w��;"""��|�c|�.���T|�5�>������n�[m���]����V�w�uZ�s�������u�:_�������$::�N���u�����ED��P�#"""�#�w�n�=��7�o��RRzp`�^�f�K�""""',{w)�+N>��J"�[wL�g\y��������>������s���g:��LoC�"""GX;a�{����H����6�����D������Hs0;+�[tLW�9)���������������;���a�u����9���>}3HM�Aw�5���is�����*.�"T&""ri�e��DDDD�N�W(�t-+��Wzo��.��	�)=���Cy�z��l�~EDD�}���7�7n�����sY�:�g���������i����7o��_��b�Os����V_C�O�e\�p�����������w�.����$%�0t����%���J������8���������>g����zk��7����&�y[����U����.]�u�r��Ill����wM8g�����_7���v�s�����{kk�[�QQ�#"""r����K���M����8l�$�^����&�1������?������;v���|L��L��l�g
<��4-EDD`�G���r����3�����[���~Sq��7�|��k.WI�$��{��q	����\Jj*C���n�]$$v���]���ECDDD�.:&�[>���$,k��g\�I����TWSSSMmm
�����I�&���SR�p%%�J����y"""?z
vDDDD.s������.CDD�U


��k��[�u�=�m�~bb�6����E���v_DD��,,�����P� """""""�`����a�|��������4RRS���������"d��Z�=J���P�""""QX�RDDD�K�Py� }�>�Vy�����R�?�)����4f}�]�*�C��#l����VJ�Uq�s��P�$""�9���g�)��%`w���aL���
]���{�<�hm]y!m[�d5O�-����vGs�o���5a��������Hx��)�o�<\��C��n�`��=��UF��=C\a�WU����Sv�}@|B"?<$�U��H���zb5��9���k�9��W^���ILa	���Q�x$�B�P���m�y�H^es���v�WZ�`GDDDDDD�2q���+�������8��C���S�i�7m��v�����N���������C)�l{��
�+��4�k�I����wt��}/�/��	��C������-y(^�G��u��Ms�����$�I�I{�M���{�6i����,k[��{qoR�	 6��%��E������c���<����������j���*#V���s�c���jwk���g��O8���n;����1��`�����N��S��Gr9���U7~�p���x5J�o����J(�4������o=y��g�q��=68����/��..����������x�'�Pf���������<��� �qc^�n�7����O?���\s$�y������t,����y�����`!J��@*�	)�/u&��r�����SRQPX���bh��`��:4�uCC��6�Eb��r�d2���0�B�
���'�X_���|,]��I�!��h&imm����������%K��{�b������^�����q�����t��������"=p��n?�#!9K��7������})������
���
��!���~���l�� ���4�������:���I� �
���?~�Z�`��{���R��Q���x�������6��w��A�r��?>����O_5Bb��[���?�?��oQ��p�=���%�����������6�m��o�`a����h�r:P(��Ssp]�p���3���R%X"����rB*����������PRV�9�����]����^�7�X��u����@Wg�>��������qz}H���������^/(,�C[�����#�@&�C.�C�P@"��,���h���6n�����b�J$$���u�6���;;N�3`{�F����I��M�$R���s�c�V/��;_*�L�[��6S6��5J49��4� B����c���G��@��U��o%hP8_���xH�0�Wt��Z�K��q�M
V�W�W';���	&�~(e@C��c��D�?y?��N�(�����Q�#E���:|��{X�v,\,H��
��-�M()�#H"��D.W��g_@�\����k��~U��"�`����Q>w~X����������z���^z�r��V����080���*4�����=]�h���7��V�>�,��+nl�!X,c��XP:��V���)1	�����t�����)1��6�Z���o0����|���,Z�d%%%HK�p.�^�j4���� IDAT���/�{�n�	wP�Y���
(5���p" ���)u�k����Aq��R�z*��!Q~~���w�s�zk�X_�
(�O-��X��d��}�)�^�57��U4���\�
��]��7�'?qC��[���S�-�Eea'&&F�DDDD������4B������������"�02�n�&�Z��5U�r�"��:����������A��+���Bx<��n	���G���X���!��VC�
�R���c8u���^S�����������g�s���|�����
������
���t�h��)
(���T"� 1������dkF{Pt����`�$��/>������D!�����@�a�������������|���0J�����j�v�@�Z?�,n����wC'��J�~?��y�/?Z�,8���x��F�2/_wd�����P�Z#ha'1)r�-���#���BG,����e�0��122��|>.�?�3�N��������k7L��q/�:.��������!..j�:�Zm���aH9F"�B"�B3�� "�[�����"��Z��Aw�*>��G�O2�]��&"��[ =h��M> ��9ln(��0JX�p��
H�}�F�V��d`N�E������2Bbi���~'cR[�����(W��mq�h�������4���,��0M�����(-�+tde����:�:;-2�4^�gJ�:�����R�������w���f�J���
�PZV>�~�);'�9yB� "�YG�
?������?�?����/n�s�&�����G���#�>�����j}% �c��m���R|�����+o��A����(3��U&j�h`�?U��x?���.=�\�����~���}��L)3����_�A�U����El)�
?[��_�Ow�����kx~������/�����7��I��<���YQ����klNl��1�h�r����AD��9;3���1��_�O?�wJYu�u���#T,[���7��D�%Xs������h��'��\~���|���|>���G��r�d�I������o�	W`��eKf��)4�q�(�t2H��B���m����0��c��%t
6�""""����*�Z��d�����NBD43\�|�/�������C�o�z<�D0����x���o�����Z'l����?{�/�l�*u���c���}���q�M"#rS�E!�[�E�"#"""��hin���B���BG��
$%�bp�����������	����L���x���M�D*���|fs?._<�������Go����1w��q�s��
?W������#e���Z�M~�V�"QY�!"""�����0��_(t��~�1h4Z�cE5���>����@���q#�m��u6����\����45�,����s���w�����"""�$7��yB���:DD��t:���w�q����G���fI��������^OX�$"""����CDDDDDD��~?����C�\�E�%a������DDDD4>v�������"Tll,23�����EK�
�����";DDDDDDD7
��R���q[LLV��F�DDDDAb�@DDDDDD	.]8�������p�]B�!""""�+��!""""""�`J�J���sgp��,^���[���:Q���""""
���V�tw	������3����xp+�)>;z���Wq��e�����Q������Ca6�%��������p���Q��*.-�w���X�j-�^/����o��EDDDD ��b��7`�/���5�R%r�T���f�(:Qd��~
�/�CZz:��q����
�L���z��M��%K1g�<�<~,���y<n|��]���f�!������[����������d���K���A{�(���:Q�����D*EVv��Q&��������N��M�\����q��u!g��q��
��	�8DDDD�"����7U��o�@+$)�XP����!t2"""�����
��0rr���p�����SsS��I��"��=��������]�Q�8DDDD�"��#���'���?��\���z��?N�dDDDD���PPT,p������$p"��z��p�������PwO�.]8��kW��h��c_�H�������(��~[g�%���sh)Q�W���`���*ydG'�1��$��B� �I���>�m��i����,*V�@/G^N:������@�T
�(�q�M��f��=��n����B��?����K8�g'�22�q�&$''���/����z�=yqZ^|�9$&F�9iD�g��oddT�D3Bd���5�p���f|�?��_����8��^��>���$$���t	��&�s6���6��lE~A�6��x~dH�@CS;�]�FQI��q��,����~���k�������/Re��S������jT���K����k�R�����sv�l��z~��my��8��"g��/A':���[�Yzp��t�@mn��A��X��FDDD!n��
�JN25�EX�p	�&��Q�h���gz{��`����_�V���>����<LI���������8u�|^�]�������b������Z""""��"s���������,�{����B����S�|DDDD`���HK�@JJ��Q����Sb��1�h�9{�$j��##3����)�i��s/���>;z�N|��W.����2���9����
���
I""""��"��������o�j/���nxE2$�\��^N�,�����#t"��������C����G��|���9(((����`�X�R���E""""��Y���S��~_.t""""""�r�?=�D���=�4<{��%,]~X�""""��%b;DDDDDDD����/����x�A�(DDDDD�+t""""""�P�JeHNI:QP��CDDDDDDDDDDD%X�!"""""""""""�,�E���475�+|#>4Y���������o�DDDDDDDD3;DDDDQ�����`�;h��:�^������]x��)���08`FOwW���l�r9��@DDDDr,�E����%de�
�Y�@�ej���r�������g"�������������:
QH��CDDD%z��`�!7�b�X�8w(����Sj��=Vjn����B���6�U�D3��]���&S��Q�����B*�^ """�q���M�
��ak������
����J�i3����<�����k��Tj$�������L�������Y�����9sQPX4��f�}�v�>?tqqa�����P_���<�\�6l�	��"""�(Q[S
�X���|A��w����w���q���,�������R�Y4Y�Q_<�~�sr������fM�]4�3w�+����:;n���O�����9s��/\��h��CC���A}]
:;nJ%��2������2�T���]_W�S��!�`�C?�1�����"	;DDDDQ����!

������b{����X���+E(4�R�Y��L��������O���q�v�T,�������BuU%j�����M
�P�Tx��?:"�=9x`Z����2%&A*�����v�'3;'$����^��d'dr9}�IH����ADDDDiX�!"""����a+���w������car�����})�4(%*4��?��(V4����3 ���������������X��kHIM����d$&%c���hinDU�u����K�^s�-@jZ:������n~�lFGG;L�Y,S����t������������oDDDDDBba����(
�gd�j�"77/����^�_����(6������_���#�~�0��<��w�x18y=����0��app `a����s����P����`�".N/�j0�����+nr�
��W�����7&���?�'D"��3������L��m�"1�32�������	� """"�)��Q���
��������@�6s�������4V�u`�G;`���}�����<��_�x
��(*)CAa�R������������� ��C�Y�r:�x�E$&%����vA&�O�k��������k���c�	������t:��������[��R�Bz�X��|�����H������d"""""�d,����r�&e)x�1�*l<��~���&df�`���!���m�-hkm��=���_����C�O�����[]=|}�=w|.NSb�Z$���&��~���C[EvNxW�Qx��6TW^Gu�u������)1)dc*Jlyt���{�����hoCmu%:���Z�!""""��bFGGG�1UV�v�O�D4	�z9z]B� �I����q�]���Rc<gO���c�o0��g_��J�����D]m5jk�a�A�c������
���q���TctdZ�Z�j�f����4a��;��x�l�*T,]1���"������F{[���%%������%P(��������1���|A�6>�E�Y��K�� �
cD��;DDDD�:������c�!W(���O���I�)HJN�������}��hl��V��H�L����{73+O�|�����(z�������H�_�C�E,��rA�GqI)JJ�
�%)9E�DDDDD�+v�(��'���9K45������x��'������=g�N>��.�:;o0�����...l���y<n��1<l���0�vde�B?n��6��\4u|�%�.��D��;D�����E�Y���x�!_�3����Ov����2��RR��������}hjl�c�����/m~���
��n��,Qt��%
>v���[�QD�x� X�d��%g0=��F\�x.�
����������������l���x��g��`�������C���J�J
�Z
�R�J����p})DDDDDB,�E���O����7n����q���m�����R�
Z���?E�@^���nS]y{>��7nF���A�B���b�-�oV�����Cp��p�\p�]p��p�]p�]p��?�������1��^w8�������sv"""""�,�E���*���@�
^���\~'����!� ���q_������{`q����Lm���Mc���X��,�����S���>H0~ag��������P(��d�H�����Ie�BDDDDD4{��CDDD�������,(�����b{�XQ��8'�E���j�E��L����`�Z�A[kKP�������&�47��F;^�N��gO>��b1Db1�"1Db�7�>��L�����NDDDDD3;DDDD���
�_X��GFG�a���ut#+.�r��lHb������&�.+'��^F{[+�32���^�tw�jB~A��Q(�����������ho��y�X���q���i���HDDDDD�;DDDD����_P��w7|�6k�T����
1�	�1�A���}W�nmE�vrE���\�z�M
Q����x��p:������x�#E�=������EK�
e��~�����q�c�.�y���EfV���������>��Q�������i�P*�����}���^n��EOA����E�������)v���	��^�l�������w�t8�`�u&ix���m������nl��0�����#1)b�99y�����7E�X����j��a+�6lJ�
�_/�d"yH��%[��H����I��JeHMKG_/�v[�Ml�����:�������MT*5����������*���`�Z������?�=k�m��'�����Y�!""
�������B� "��"�msDDDD������h������0�E�[r��7Wc�9�br/����cttN�j�&�	�����hj�G���-�<.H�h&����3�a��]��v��`�#�������^FSc=Z[���z1���X�nC��'""��NtE�p7:m7�!{��q��f�����Q�CL������:MB�^��A��1�h�8g#����B�:FP{�PI�B�����J���!dr9�}����tBG��h��gO���c���^���+B2N}]
�|z6�����*��sQ\Z������M4�2g�h�����~l�y�;L�$l���,2�/QdI�� s)����"""�4S�:������p��}�-�l���N4Y\������n�h�ra���P*�W��D"�lV(�J$%� 55Y�90%&M�+ ""�/2��x��;��~n����k����C�.W�hDD�W�QH�ND��s�hL__/�z{PR:G�(E�����A\\�R�]�[���������z180�u�����b<���q��x��x<�m�G4�h��D����FGGq��N�8X��+�� 1'�H�;D��;DDDDD_��`BB�I�3������m�t����
���!�`�^�������R��E#"""
���,K]�Tu:v5|�s]����B�6G�hDD3;DDDDDRS��a����7 �db����H@n�2�|R�f�r�|������:DDa�uoDDDD3�������5�J��M�..s��!5-�E"""Y�Cx��8��g��oRK4X��,�����v����f�=g������,t����z1<l��������E�^G7���/�����F"�H�������"@M�����������{p��$�R,HZ�>�����u����I��x�,�N��-�������������X,Fi��}�\N�x�m�].��.8��������{�Z����f���Z�n��Q�d~
�	�d������o���#��7�����ZY
���m?�4cO�N��.xF����������C��ba����(�:��HNI�..n��]�9�����+'�7z8j����Z$(aR&N�����0l����_�fL0,�������J�
r�:�2�r�2�2�$"""��gp�� `s�#(2�
G�����<���Y@��$�A��	��v�{=G���������T$�4V�L����PD%�u&�S��G�����kC�M�����D!HDDD4��:q�f����sk��8VQ�u�@_���Z���&]�)��]��������H$�D�h���dr��!"""����{q����bl��:2u9A�l�	�9z�������C+�}
��B��:��rt C����k����L������!�C+��w��b�����������w��X�#
��gRg^������8��9
����u�3v]c��W�bs	�;DDDDSe6�����H�X�aSP����:�������"}���,]�2������f=��r��>�DUrH�x��9h���u������-���d�Ps�]��wc�kG��,���v�W����0"^n��0B/�yN���s%�l������s[�x�!`{�V�QxMP������Yq>�����{�>9����l��B��b��m=V���0&"""�I���###X�v�j������un��d����i���n��IBG""""���N����/�O�D$����������=�Y��+p����V�z��s��g�}�=�y�q�$`a���B&�����.{�W�	x~���,������Drd�r��NE�&
��HE���(Z.���QsU����~,/?jw��r9�.TB%����?�E��e\�CDDD4i��AoO722�0�|^P���x���E��q�un���i���*v����"�B��B��l�� E��]
��|�it�:�p��P�Ua*\>'~{�_���L,G�&&U&X���i���W}�^��p�1��/0:a���gaP������{�v�-���u���R�i!-�Q�M�b��G���Qs���S!�uK�
�
��$"""�i�CC8��H�RlzpK��UI�x0����
y����vl���&"""��)N��7�^����2_�u��
 IDAT��	ka�������A���s��O.V��8Z�&E"L�$h&8Wf<	J���o��a�G���X*�A'������*�:`aG"��,a�������t���hl��N#�/�~~K�
V��P�$"""�a
�K� !��-���L$G�.�CM��w"I�"t$""""���
X��rqh^Y���p��{�p��12:�w���s��K ��������B�m2��R<���\p�c�5�,��T�j��FD�
\�%b�?~����n����J-�����e�������+��m�����&M"�b���B��\�JX�!"""
�N�
��I�N�>�0�����9��:0��c�;���������Q<�;��wq�����X*�A%Q#Aa�Aa�I�8���#I��CD��?�E(�������8�A?�W����c8��]�����~�����IDDDD3A�-#����(�j�U�����Ex8�q��L����?\������b<�����E(%�{�B��(M\���`�/�W�O���>���$���C��������hz=0Mp�<����38�v2��%/:���ejd��A%QC%QA%QC)QA-�@)VA%��\�DUr�����^jR�Z7�6�:���H@A|��Q��"�����:����H�lm.������H:qGZ�b��%<^�r����D+��O
��(�.�������p�=A/��tp���"""����=�akCv\��Q�f���:>|{�����NDDy�l��J��4��s�n�u���,].��o���^f�O?D���
#/|�[�� ��#Q���9K2���t$�v�,����rB.|0����s�o�������0���W�o��HY����vt�;�i����<_�g���n�T��w��v45�y��^;�:!��{���HR����'!�y(	'���(�}������5���z��`��,Yc���"""�	��V����x��G����~�~�w��$V�bcY��%��]���N�
����,m��q(L����L�^/t����A�P���w�qM&����\9~����CT5��sQf�;����R�lv���@��3\f8<v|g���m#IP_�8y���`��h��'�H��5�xzM9�����������G���Ue��u6��_���Kx��>�/���bE��������vC�R��K=���9�4u%d"yP�7����A(�9}k��1�a��P0���q��F|���> N�,m.r�����	gD��;�y�����du��?Eh�ii�����w�����D�6���+�f���7���k����r|~/�"��}<��H��Q�\����K�kq|W=������+����l8�����]��u����G���T|3�#""��q��~��N,Y�&Sb����j�I���������x�����@_�]��������\�1�\�9�S����gaT$|����V��E�P#�m������s�����B�.�[aR���=�AL����������HD�}-F'����%hj������{�X�)]����"�j�C���w�������Q�#>�c%w�yq������3������7�����>DaK��q���
�|N$�R�W���#AiB�,�����@DD�M����G~t�AY���__�m�3������/�S3�V����`�q|�f�_����(:475���:����X�2�}���:I�dc[-M	���(X��-�1_�N�������CAr��0�v��J�F,b�z�D$����X��^���f45��R�fK�,�L�����c����{C�!�=Vl��n
���Z���P;P�r���5K��c���0bU�z��zX�Ch�������V���B&�,��Z��6�rga�fQ�7�C~|���������>�J!�������,l+����]^�v���T$��-�,������5��j�Y�K!n����t���w�M���>^��A�&M��gJ?�������H���DDDD!����o�.���`�C[!o?���Zr���&��\��E�x��qyX�T1�����}<�*�l����������Im)I��/D�������7��v�
=�.��n�}.�|����]p{]0��P��b��V����R��Z��B��J��J��J��N��>�oT�Cn|#���h+<��N�
T\G��n� �����G���t����v����8Y�U�mC-8�uj�����m@%U#C�
�F�a�(D�b�c�7�+�!�j���x��y�bDcmb��� ���p��""��'paG���eV�'�E�DF���q������i^�n�� �*9~#���$��KQ���
��;�!f���kWbnIp�a��U
�������a�r�!���b��C"w ^1s��r��8�z��W@%Q����I����O��w�>��mA�V����N���z;m��KH�7�|J��m4��������&h��|C>|�5&X=VX]VX�C�W������:l�`��r�H��NK7�]M�^��t��%?�5t�:��i�+`qY`qY0�0�����ubka��<����!��B�@�<��?�8��qH�W�{�������(K���������K>���A� @,����S9
��w�������P�U>VH�O�1
�0����GF�)g�!����t#�8���N1����;�,���7�p=���I�7�GV���,�%������g�%t"�$���p�]����
�B���!�m�������}W��yV�����eB�	
����j�@�p�"V���\�����9�z=x��u�}.l�y��r�#�����\y���F����=�Y�����#�O�����z��p�~���N�cM��q�8�h��C&�C&�A.R@&�A&�C&�A!��(��;1���3�a��^;�^ldb9�f~m��n��^������������Zh����Z����Hu(1���X�s�&a�5��_�H�d��8���\)2E|�%
�����?%�������
o�rm�����M�����C=�D�(�p������nGB�I�(Q��s��.�
&U2�Y���q��d�Q��8�x��~@�:
r�A�s#9g#�l.��F|���� E���������t[��;j�D��0���xF�h�4c���N��j�j���������s�T�q8�v8}Nh�Z�������W��K�f*ln+*�WQc���s���I����R'�A)����b�k��9m�8K|,�G�v8��������������"��C=�D�(�p�������6k3�=�{��tB�	�S��ai�J:�i��Y[��V<c�8g#�l-��<V|\�>��; ��bE�j�OZ$t��n�����dl�����Bu%j���FE�
,K[%t�������\�uY���2�q�;D���������O�I&��g�������q6�,�E
>&�.��$��}�P�wk2��$U��qB��\��m0?qQP�����|����{/�x�ax�n&|-�A$�g���,���jj�Qi�Z�:JX��6T�]����r����H����8���9K|,�Gdv&�;D��O����,Q���^�E����9:�<#�Vqgu��YU����:�z�U����aE��s>�Tq��_����d��#�u�������L��]�P#����w�u������rQb��<}!����f��q�;D����111BG """"�'�*�P�\����G�`��A����L���~wV3T5�{��8��Wz.`�id��������x���}�F|��f!U�~�uQ�x������
�������G�������W'����h��[[���`�c(4�{�����]��
#�
e(M(�5����������CDDDD4S�F����#���#�0�h����;��:^���OaY���6I�f�������+!N����=������0���h���>���H:aa�{����b�c���A)�A+�(FQ�(`{�2	��mE���~b���!���4l?7�>d�� �aR&N��&""����"""�i���FA�������]��m�����A}�������X��,h+q�u�Fu�u����LmvP�����u/�#�L_�,N�8��sbG����wB!Vb~��I���e�.�M5�*h��<��4��Dr,K[�ei���������z&�
��?�V�U���^'��N��EDDDt'v���������w}��`����xs7��u�����z�A��������8X��������ol��=�5o��P���;b��5W�q�	�D,J^*t��d�X���M���c�?��N8\���C�{!�����s	J���������t����������O�A*��b����q��<�^�KZ�(8�Sp������:$�S�<�����t����0TR5j����+��{���;���Cm{�
���`�i��U���������9�c|�~�^�=�=�����J��S%�#Y��tDDDDD���"""�{t`�n��N�Y�5���/��Z�#I�0�"������~,�HV�b[�3���A���X���_���e��xp�u�t�����8��#m��:�0�&UR���w����_���a�^�w���?���bM��&}��T��+q���=3�����������`T$=Q�`a�������V���i�(-+��V�,H\4�������=����P��~�kBV��E+���5����!/�}����d����s�q�:����_��HLL�����sa{2z���N����9�9��O
��kE�R��z`�����W�=�]�����{�#A��gJ_�V�I>""""�H�3v�������r���=�D��yKH����p�������$$cD�N�
\���"�
��]
�����EZ�[
�����dUJ�����b�U�2l������H�������p�m?����[�gP$ M����#S����� ?�G�>Eu�5�Q�_�k�+��@*�}��^G���!E��G��uEp""""���b����h�������+�����������[�#���u
���U'�Sb��
_Q������$as6Q��0)��H�E�B&��X��8�yR�����X�S!/�����@�l+�t2=��^�����]�"2)�T���V�
u����h���"""�)��|0��by����t0("�������`R%������D#t$��y���w���C3_���'���;�������*RVKP�,�4���<��:n�&E��dDDDDD�ba����h�~�q8����Qd(A��$�cD�}z��P?P����9��^�m;�H�m�D��[�E3�"O?�w���+��0q	Wi���EDDDD�e�������(J�#�x��c3G�vl����{5o���?��w
�����;s��X�!""""��ba�����"R�\���N�
�<V��D4�H������~��0�4����H���U����h��o��1}~/N�8�������(�X�!"""G��[����7�ma�3��x�����T�s����������m�E�X���,t�i������������7q��,]������;5��L�	��:��DDDDDl�����?:�Ty|#�xG��AD��V�1��	��&�s�y��r�"v���=�((*:��'���0Yq9as�'8�u���c#�H�/����XJ������*�5hd:��I��,��Vl�yC�!����s�bQ��}�n�5�r�yT�+aqY��j���&�����������E�iV��	C�����D��s�(�Tr1D�1B� �z����8FGG��@DDD3��j���gq��%x=�N�8i�Zh��q��F|����0e�-�q��2�JS�>��?}�r4��M�0��cI�r�cE����vJsN3=��T$�S�.�w�����fKn��p�uI�d$(M��w�aG�����,m*RV�)=MGTv��������/�ESC=FGG!�P:g..���`[���Z������;��s��^�Y�{�^n@���x��
#���FHce���`�\���*	_/�d"y(�����y�����~;�T)B��';�����,a2tYB�	�"FE%/�g��fK2�Y�t�o`G�[��=���0J���	KDDDDD����j{w�uJ�
s���y���B�k�Vk3v�o�T$�����������0�2c����/\7������&��@�n\��E�[2�Y�����tak�������PI�X��N�8!#���0>���7>�{�##x��idj���!M;DDD4�-_�j�l��RA�p��q��������l��z�c��:V�q�1��Z���������ao�QE�[X����-��en�Q���"f42�[
�I�3�������
;DDD4���
w�����u���wce�Z�).�$�����fO��^G�XQG9��:��������EA|1���B��D$���~W�D���{�������&s��g������p� ��EP��.�J=t�����n����g�}��=<��u�}�GO���rwe�ZW������PiA� �H !ar��$sJ�?���@ �L�z>y��^�5����r����_�����P�K�W�Ou)�����n�����_��T�3.Uz���Y_��l#����1Y��Z6��T���`���������-2[,2�Lr����/Hui-	k��;���o+���b����e4��_{^=�^
]'4�;M��asJy�Y�.!%����dW������K5�`��1at}�Rf�������`w����%���{�*��@�S^UK�233e�Ze2�e����l��nWq����>~�����b�����b����X<�y��h2%���
v�w�.�b�s�TV����F]�s��A�[���Y��'2��`��\��B��:��ZYy�Ls�KV�:����)�E�0aB�K`���b�����cG��skV��s�k�Y����C!�=���j��K_y8�s���_&m�5{N�`g���jjl�$��f���P�s����$}�T�w��i�U�-7��`�w������t��V��{FwL�[N�+�e1����/�E\�@wL�P4�e�y�L5�����xy�������UW�p�����z�=
�����
�{�	�'����T_�t��?�������W�_(�����������$���h��������Fz�Z�y���f���)w+���^F���Pg�S��vuF:���7..-�����@za�W^��"�1#�ei�`���a =D"a���,�f������W���N'uk�*M����]y�=mz��s
D:����n�`�C���������,�^X���G�\�sV�t7��������x���M�X���;�=m:�U��p��NY]Wrc���E�h��m�r�r�=r[�rY�rY�����`�^�,k��&�%����
F��$�5+a����z~���;������h�W��_�\�%;��p�:::�����R�����*p����Tz�&mo
6j��}#]
E���t)�R�/60~���	�g���lr��r[��dz�0�����nr�c�\���XD��w�D�^~�eL��g�.�6�>�o�'���RwE��.[{�]�7���c��F�,�L9����sl��R���Y"�y;�Q������-z{��������`������M{N��'3Ky��T�\���������)��"�����`�����������j>�(���������T�5n��������l������1fd���[S]�k;�1����_{Y�HD�%�t��;d��S]��q:���� c�QwN�W�A.Mp)vC��z��$IK���y����%���U�/�OL�K���T��������n�]�y����Ku9��o�p�� IDAT>�`�K��nS��2���1�`�1f���R]��uS�m�k?�Y9sR]
�v��k�r���.�a�.�;��h$������j������yR]FXZ;}}}�.�a����mzKm�-jkkUw(tN���%���2� �
tv���C�A��T%���U��}I���Rq�$y�Y�x���������*�
��aIu`"�`�����w����C���ho;�=7� i������>�7��r��T\�`�K�������Z
�Iu9`�!�`D�a���S��i�*7�@n�[�WN�K����>���^8�+"�j�iMu9`"� �X4�����������_mm��z����3����\�����������o��;je�0��Y��RR�wG��t�I%�2�\~{���Pz��0il8�����@����N�+�x���6;n�c!Y����8�I��S�N�s�J�����`�����~��N���E��Fy,YZY�8�N;�Q���	�����h��h���`��h��`���UVvv���p�����[m�����fW,���y��������lee���x.kn�E ����{M�=m���/&�W�7_�;��D�q�����Z��d2�U���Jn���<�JW�hX��>�8������e6XRX�v�R��zk�����f�����L���������������>������K_y���MC��j��7%I���
F�d79.�w�o�f�fK���[U8���yL�m�t[�'F��+�T�Am��������;���'��<{�rly2f��H���tb��	�.0�
�&�c�?��=7/?�x�����Q4S<S,S<S,S4�����%�����p�U�t���`�u%7jV�����f�k����jIRG�]&�9���.�;
������/GW$���j�:���	5O�M��J����z$J�(i��[0���S�*����Oa�DM�9���]�l�����X��pb�v7��$M����I7*�`���u[�_��+�����$Y�*vNR�=w���a���EI��d�^��F'e�0�x���B%I���(9�^IY�>�;
U�(t<�hB��HD�������;���}������JFBW�K��w������+4�U2"�5fu]��:���@������N�k�`��}k�����	/#'Iv�S^k�
�E*p��9QC��M`� ����^?V��5{t���b1��fM�9[�����4�n\>k�>U�W*vM��f��:���_(I�w�V ��p,��x��7�s:&*�W�7�Xo������c��A�{����3Fy�W��~�yw����j����������O���$Ie��6}�*'O��8��~���u.�g����sIc����a� ���O��-~���6�_P�4�����������Z5M���w/RF�������m�����dJu=�!�9�*]5g.���{����S]������;C��!I�����b�������V���)�QGG�,�L-�ay�K���������;R�5WS����$�����i��bHu.�!c�����.Ct�����o���q����'���PW�K�=���R�IZPx��'V�i�k���kH/�Y ��f�+���/�%cBZ;]=1B�T��"�y3�����2 )�����vuvv�������\��� ���`\��y����x��z��d�������j�������;���
E�ae[st��[4�U�PH
�����f�����kH/�Y���q[R]0&�e��8�����P���;nJ�+�;�K������*g	F����
+�^�����_���}2,���F]]�p��@���(����S�
�v)
��*���������O8>##C�xL�Er��r��r���z�r8]�����l���p�z�=���%�����TO�G�x�B��y�_��wr�]	��������Jn��h����>Fg�:���xK"��E�uzb����\�[�I��.SK�_����������������?�����F�Iv�CfK�-��STQ9������c!m;�U�h���.�A�]����$�!S_���N���6��������`Q�1Sc�,�LS����z��F�����vl�z������,.G,����jj:���MjnnR��f�b1I��K�iA�5	���U�j��n��nw�f�����T��FGO��N����i��	���O;��>��)�,�5W.�[.�g��}������P`����[6o����9�XV�O9�y���SiyE�����/H~���(�S�/��go\���b}1�{c2���L|�����q�U�z�����w)4���4���ZZ��?��x���e1d^�������t���	9N���'�WV^���^�rr������<���7�@�S2d79��}z�6}%a{�w�>1����q�u"P'Ir�=��,�����������2������>]�A���������'���Z%IW�_8H�S���������������p�ZB~�������XoTk���	��,n���d�0�8�(C�Q���2f�c�Kzn���������/��6i����������wh��7�D�9n��T^^�|9�)�,}���fmkx�����leY��m�I:~��L�\eC>�1�D������\�X4��������r�hbq��K�,f��K&)//_9�y��+�����G��h@=�������M�=�*�T�*{z�1E�bM��VVf��m>y-���������t�X�Z[Z����V�_�@�@�����;S��ij���(uD��Q��b�����+�S����;���75�]�9�����N���k7LI��I�rMr�_�y�
��1����6nxm���fS��bee���������'������QO�[�x���K~r��2f$���k��Ug�=a��I7)7�}f~{��:��?a���n���������n���R�g�<V�\�<�\f�o�aD� �tvt���������(/�@�f�I����T7�z��������b���z��
F�
E�
F��v�'��@$��	�����c�&�����'�>b�]'�����='o6Zd1f�b�T�1S�K�1C��\{�PH���_���&�`x�����k����������b�s�+&OI��=�=������
�����(##C����}������5	�3�����$-+�I^k�����YI�^���+��&l,����v�\v�%�@��H�p�G�HDN�+a������+I������RVv���|������#�H�zb=�,rY�	��x�Q��~�z�=
����V���OM�����f��=�e7;d7�e3��i79d3����:������I&�QxY��/��.����f��������o��t�B��f��J7��x�HiY�>����������~�^5F��P��S���@�9y�u�����Ukw�2
�r���r.C�i�����t.v�C��r�%��� �0�v����?��9������Qe�2T�u\�����&��9�U��<��l��l�<>lV��}I���)w�G6�]V�U�F���%I���L�C��vg#�`g�s�v���v8�4%{�*��2L�.W���I������e79RVK4QOO�����Rs8��/(R��'���=��u2V'��&���N�kk���}��s�������r�d�,n3�O���OE����������K�������ZQq���������tw�~s��U�(R�c�
E���%�H�Nt�i�wj�@n������s�c��;�#��������cf���jn:�������Z555���U�����t������.�Z���`���L����[�m��,���4f�f��F�lF�fg�:�&GJ�,H%��4�����yI��'%Is���cEW{O���w��;%���P,���GT�vH���>9���}�u�B:��WZ�/tLT�s�&��5�U6�5�]��8���q�uk�U��DW����Xv�Z�[w�=��@$��p��;Z%IW�/Lz������e3�d7��$N�K�XP]�.eef���a�t��N/�f�z��%I�Z����M&�������%I.�G}}}I�?;�Z�s���C����&�Z{���������'����V�M��W7�N�u����u��9xj����|7G�g���5��n���z�
6�����N����:{:�5��������������%�RMtM���9oLgG�::�wde� �r�S�d��Ny���G�iS�5���==�:��<����_�?���c�����{�}*r<��2*��Tnn��3*�k�Sa�D��n�-�,n9��/��2v�X������ee��<�+���~�����=K�������'������"����G�J�*sW\�e�r�����J�Z����!pBf�%����V�����(R��nW[O�&:KT���bW�&:����m��ny3a���st�-��h0����N56���5��=���hP=���zdr�T��+��%�5Gc�9��YY���~���	��v��PB�?���#���-���-*tL�������.sF�`#�2
Vy2��m���]�Rw�2�C�9��b�T��r�~���'6J��&�
����qY�j�����*vMJ8~q�u�a�-2f\��+--W��/��{�������=�,}l����N���K�@:��7�
1F��PT]��T�1"zb�W$�H����v�����C��=�5��c�\�k$������F''tS�
��=��:���#mu��A�������i�W�HK�o����hoW[[�J�*���Q!������T��"�f�����kH/�Y���q[d2f�� ��cg��whK���D�N���a9�=�U����H@�O����������<����r�E5t�Tw4�X��!���Y*u�����K���;�jT{O���*�'���Z������?�,���������l�@�3��z��v�-���GIR�c��c���{�av�cE���>�cG�OMm�!�A�bA#]
F����R0��/����F[��]��z���Z�e3�e5�d3������Q�<{���]�H$����d4��t:�p��t:e�d>xN�KNK�{��jl��Ct��~����/(���U�]`| �Ev����'�T(������45k���q1;e^>��b�����Lvy3��M~�����7������s�:���;�������X\2l���_(�H�&�h��*M�Z%��9l��=;�����^9��Z�O��a����ZX�8�e%����&�Mv�L�Mv�M�T����)S��pR&L�$�B!��F"jkmQFF�k{����:u�Qv�Cv�]v�Cv�C6�]6�Mv{��/Xt�l6�*'O���x'���V�U������k'.��dOuI���wu�K�$K��p���p����.w�����������7�t���37a��E�;����Q�nr�W}E�Fk�KI;GT��]r{<�n���<�b��������{��T0�u�+�`�K�`P��.�|9C)�KB�3���#A3�rY�
!��x
'O�f�.<�O��I���R�s)�.��.����dv����c:��O�h������."��r���lE
+Lo�hT���'�����������Ti���*�����;��V(R(T(���g/P��(�w�v5�w�1��!��-���b���.{L3�z�{
��X\��3gk��i2���.
�C���=�#m�;�������D�$�X�Bn�[.�G^k�p�9�L�0A���RY�>9�\
0>�������H�Ay,Y*p�ar�f��nr(���tl�-O����tl	��:y�^o�rrr��TZ>�U0����
�h�ay3�u���*�`MuIcRoo���N����N���	:��Et����n��)����`����{�N�#��0y�{������cF�I�%�TX4Qe��)���@�sO�7�%�i�C��l��h�

����h��	�.
��@��!�D�:y�~�+���o�5a���)���2�0���#M�u��Q�Fe2�2�2��w����r��F":r��N��D}�����i�Zm�=�5��1���!���gUTN�Us�&�w�T����)a{���Zy������-z��/<.�X���"M,.Qa�Defro"���v�Nh��y�R]�e	:����������������}l���ge'��#I6�]K�����"M,����eW�NO�[���������rT��HuI����O�Gi��;t������4a���Wh�U����&/�@y�C>����������M���j��_�=��i�Yi�HROO�^zq�����p85s�U�uU��NW�K#`\;�}�����Vs��J=���/R]��X�6-Z�q����r��T�F��v^=��uS��H++Wk�&���!��5������T0�6]������;���1ctfY==�zg��t��p�K���L9��p�GG���iv��i%�!3�%����1�����'I*��TYye�����v,�L�;��
�����.g@OO���z_������VIR^A����������:0Z��`G�l&�l&{��v��?������f�z�<MLaU ��`g���*-�Pnn����'�����@� ���N���S]�1��������NW���\}�V�
��!�T_W���Gu��n�>9�d4����4��1������i�^3"�{y�:y�^R�S\2I��JU\<I�E����:�����N�7�u��Us�Q�S��g]�sF#������g�V��RM,����I�}>��1z���:�b�����^������'�Y]z�z������`�J=��=��N��PK�_�~�Z[[�����x\S��kN��	���=g���Q����w6jG�����%�6���/n����t��@�W�Fu��T�,������	���������'E#������w�fp���`'P���z�t]�\I�U���Z��I�S(I�x�ul�'�-W��r��F������I�>�rrr>��`��fWv�$eg����S���d�`H���4����U���C��NuljSH�:�~Lo�����T���u;�����F%I[�������4o�����5:��P\Q�A�p����������Vf�Bq�$>�G���in�\�l>(I*.�)??_������T^�5�s0�����,�^X�@za���5\Y�Xo�K�����2�#�]���*��[k�I6�l�OY���AM+����|����h�S�RFgR�Svw�N�{���%���'r��d��yu��;�7wD%ESS+�����jj�Iu.kH/�Y ��f�������%�%cBF�� g�.��g�����j��&��o�Kue)3:w����]��oo�7n� Y����MZ5=�u��(
v$y
���{�*�u���Rl8�@� �H;i�` M��	��4A��&v�������Tq�"��T��&H&#{
������xD<
�&v�X�� IDAT��@�0��ij�6=~�:l�>86o�����$)��Om������E�������T`����Ck�w��KEZ���Z1����cY�]��k�9�v=�P�Y�/g��U��f=��:�
H��UZ��E����cO�~���m�}�sz��������n��b8��'���<�Y���wCQ�/7�����Z����G����gVK��?�Uo�IV�f~~��[�;�{� ���Y`$[�m}�?��]�l�3�M���.��#
�f��w����	D�:W���V����m��
�w/�R���
���5k����{�P��=�_�/�����T��-���������9�3���BG������a�d�~n�e����h��!-�?�����j��~�O5����`���G�w���=�H�i���[}��x�����������D���&��~�-�"���wz��Q�s�Tl���l������'Kdm��5_��u�w��9�A�GY����|��
���[���.��&]���w�	�b0$�@X1�Y���cc���3W�NI6���]��
��()���v;*��f�L�\Kfkq�Im��)cZt�f=�5�W/��7[>�zyk�~S����jy�A�Y�9]%�������#0���������*��uZ:���`("���;[�������D-�Z���Z>�,���e%�nnWc\R�N���j��K�2H��*�t��gC����GY��pH�fV��(���AL�5;�z`��c��DCaE��O�PmcL��-�`+{�M�
6�|�������F�N�%S}@�%%�
�:UP(�W���D�����������#���F�j<�o�Yk��R�'��zI��6%`L�z����$���?�hk\���:�n�?�����Q�gh�c���H��l�3�z��N���fUi��7��N-SJTn�t�]-V���z��/v�cS�B�K�>�I����&�������n�z=��_!9U�r�>�`�\�x�5kK��e�	�v��O3�u�?����q�>�8���k���$)�h�Q&sD[�}��]�4d��
K�P\&���>=���J&�Q�P,�����Y�q����j����5����Y&s\�P���]��"UUW�����~��-�6^�?�_�|�&[�._��-��3q-dv��+j1����e��o>��lF)Wh��Q�,0��[�2���H����}@�������Q��\@����t�0|��`HlK��%�Tu_�f>�U�J3gd���TpM�G|2F�5d�Hv�A�H\��i�R�O��b2��$`d\�5�f�"�a���i�J�
��6��?I��A��-W��c���_�
_���x�*Y���;��W�K���CZ�/�k��3�il��E�.U�E�|�-���$�A�A�GY���I�f
>-���v+���O��7��)����k6�z`��)*�!�<X�s��J?��\�K&�$�W�!��V�^�rI�M5j)�)� �J���o����Z�X��v�Z/��L��������A�N��d��Z�-��R�S���S;-`���q�)������K������O�dk�`H��]����Z�>�n����T�O��5:����G��%T���K}�
�>:�{4��K�fC�7��%yr�9�I�4����d������Ip���������H�GT�v��x�4w�$9U}�O~��j�Mz�'�K�
$��Rs���oU\�7����r-\���#���h��2����7���xH{��Q��J���:�0�����S���H
�����*��L�
�fY��$���y:�������%�Y��z��:u���������[�$
�>���C�5�k���:�������������D6
�fY��	}}}}�.@�����6k��~u�
rO��U�.��~I���{��U�:dS���z�����i����5��KN�e�X������|�9��\��[�����K�pDQd�d��Z���2]������Z��Z�
H�������I�Y�O_�S���W4W�b�� �|�N=��)5�i�w�i��E�6/��O?<C�g�9p�5;�zp�������a�lg-$�W��J+*$�7h��7��!������}+=2I�}�5\q�����Z��5�s",�����,�}���u3��M��;i�K��	��4A��&v��@� �H;i�` M��	��4A��&v��@� �H;i���0F���n�z�_y���~O����_��_�����G�A��*}����2��6$�w���F����\��`l#�$�e�~�D�:n\�G��H.�$�&'�
���1��Sy��};�$mQC��e�W��8����x�T}G^���1����/�E`x�^|Y_��W�=d���u:�R�����n��y��N�;�Ow�W����������n������7������.���Q��C���bUl}W���S���k�������n�^�6��+o��ip�|�|=�H�|�)"�]����E��������g��/W���A��z�v�r�,��}����G$C��{�v-v^�� ZX������Pg� ��"-��b��w�d�����k���������f�u�g��������>2��V��|�����Z��w��������i����b���5������g���?}��x����z�U|����J��
z����n�u�ut��>RG���?�����_�b�*~�J3�o��~uR��qi�|}sm�
�t�|w�~��8R�b�o^�V=<_���������y��j��5��U��,����D�������;��$ki�~a�V/�����z=�d��GU?y�K������mzuS�:�)����,��w��������Sk�HV6�7������r�V{��s?|����;v�2����[��?]�sH;����~��Z�X��y������?��������*�w��o~K_�����`���Z^�Q����[�;����~l������w� �����O���r��c���j��7����[�Xr��v�
J�
�����Es���n�1/%����/o��YK��+U*�������������RI�������Y_{,��n�R��6�t	��?�;=�t\K�s�Y�����������a�[�A�>�Q���#/U��R�s[����&��Ojy���*=�x����F���J��H�Oo��p���X���� �!����k�wW���
������7kMQ����3Ey�*������c���/��l)1������������zbe�l!��>�Ak�ynQ�����z�dz�v��J�L���?��~�d��>=��s���om������+��������w��d�-Z��:�����;�R���^��?������z�h�����.��[�����Nk�w��V��"&�A�7w�������|2���_��j�����\T�0�2R]�Y���_�`��M3�������%>O^�fU�.u�$�*��e*�*;RG�����3��F�l�|���M�H����)Ij���7�}�"��c�I���L�?_��7�jO��g1���(�7����^�z�r��*�������a����i�W�T��d�����Z��������c0�d��7O&�A&���K���k�M���H�:��VZ�O�e�:���=?�+3�����\�U��)�`S������m�z��lK���cz��i�[��%�V��"U}4D������6W��k��r���&�`��#5ui��U]a��c�/w`+�j_�������;�d3Hr�����U�pXo�8���[a�l���_f�����{v8����i�����|7^�o��a�����S�am���/,Ru���y�,��%q�y�����
�t�j_M�B�]�T�X��}.�n���,6���0�?��K�K{��&�A2
2Y$�MR�������W�9+�0���&��\jS��������������E�`�� ��D��2W-G;�)��0��QA���X���]������j��
������R�\�Sjl�t&L�s�(�k��������*g����o�������K3�S+.p�0_��u���I�C���A��2I�-*���,���>�������m���"��R�T�����>�_�]����"�ZR��:��P���L{�m�~���yy���L��g>���k�?�TU���*�tJ/�������s*����b�b1�>8p1u� ���b�wI�x�_1
�~_���^�+�E��z�����A��R����9���:���e�H-���yaD�������|��%���UI��T��]��y�l���w������7�,���S5����r���1���u���^�}�wz�'���O���3h��R�W77.�0�2)�h��c-u\���t��):�(��������a���T:U�?���@@�K�4�E�/s���������UW'�*��N�G�R���s��y�M�6�J
������
�UW���:B��l���������������Z�)����oO��]s�N�-:r���xD��s�2ECq�r}�yG��}b����2o�����K(�����e3���[���]���!�����$�x�3�x��15�T�Q�%f;U73�������R���������Cjl\��5z���p�s�;����e%rI�<��S%��mZ�z�m����~�'���~.W��������
������HH���vtj��+������O�)���������/���[1C3/�:��h�����w��ER<��W7��{�k������6��w�t�7f�`J�x��=Ol��	#��k����3��{y�.N��*o��u�;*DR�];��������q&�m������6�=��#��������.��\���������P\���<���n�|�g]V-W4W4��qn��-1h�O�iGC\R\�M�������|Is���`p)6���\���w�QV����/�s��a����CE�"�J�X�R�R�j����/I���rX�_����������Mil5��$�����$R�&�� �30�-����`����o�,�{?�����sf_��O�~rb~�����j3l���0J���l7��)��TH��OL��������B1G����]��e���7'Wv/���}?W\]J����N�G?<i��h���\���Yr��������WH��q9�K����{z��i����=�����N�����!�p��\q��=��Q���sR���Y8��l*2l��L����wb��(��~(�����;'�Fn�x��\��-Y���r�WOI���V������~���dG���gg��s��S��/�r����3�������G���=#S�>U�����eY_uS��-%U�;~\����2���k�������|�s�g���B��G��O�I�M�����U�HZ�?F?��|$I
M���w����L������,���|�+)��i�pn���;�`n�}`��-[��;P&��Y<oI;��|��{��5�E�b���
a)6�
���
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
��
]��0���/��{��y�T�D����%�l���(s��g�����+N��\6}a>r���x���������������.�%������ �������>�x���������+w8vG�MK��3-���w�K>}C��w���f'�������k���RZ���Y���o�](�8jx&\xr.��qZ���x����Rz�X���S��nUZ�E�������!;��~�����Jsa�E{��,�����4)�11��I
V�Lb���{��k~����0_\}J>����r�B��hV��F�~/��[Ph�iW���#�e��_�|vI���� ����������g�uK����?|�i�6�5�d($V���u�����z����/�D�-��I&|��L=���a��R���i���v�`)�~�����?���������$�[1G�kb�C�??�]R��b1M#�I�z��\���|�����`S��	��������^���R�cGe��g��w���{O�����k�9������#�
7��\v���w����$�vm�d�Y��EIR�K~zA��:T�����~}��L�#s�]s2u��Y��%yv���p��i��\zQG~�����������XLR��c_[���������yT����={H���#K���,~t���|#�}f��'��k�>��((ud�W�e�m��T7��������~w*R��[��{��U�P��W/�/~����������|�v9N��s��r��gr�uO���Rr����M3���TJ���r����������?%����i�����+�J��1{���_�Ks������33q�����O�+IR��7�7����kY�E��0��%��\������� �~l���e��Y��+��V���N������kY������������_����m�������Gf����hIk6��N��'e��������cun��}Y��#���3�C��a�����_x$+~�����4�>%��)9jH����k���+'��_��1�$����}'������N|]���z��,��#y����V�f��2�c�d��m[�������J����<*�>pZ�������}��,��#y����*f����??95w�=��������tZ62���9o��-I��L���;�XO��1�_�O����RGV��=Y|��l�J�G5e�_��K.|�������[_{��� IDAT:���$Cs�E3����^��V��r��|����fSm�������1�����3���`�p������y���{�����v��r���������k���/m�QU�������9��������K��{r�Sg�{���/O�������\��\��J�$i������=f�Qw���,���L^�p�1"������D�-����e��,����7�?����|�CC��g~�Y�d�
r��s2������k������NJi���������j�8���<x���d�q��oL���d�g����|���������;�
2NM�S��e���2�/�uw�7�\wRF�v,<�H����L������������,��g`1��gDw[Z�������'��[H2}V����\����f_��f�.�%'�t����k����z�<������������g����[;�5I2$s����������B������{J���%��������r��_��'�|gn_ux�`A�������Y�}���Y�we������r��s2y����k��zM���p����p�{a�~��Y���\z��K���f��N��������;����gr���N��MZn�I�r[)�}��\w�%���<������*��,��eyn�)���������	������9v����G����R��ss����U���?Z�m�����|��r��g��7���~�=Y���\����w�g�f���������x]�t��������:_���������{�to�3���c��[���n��a�����k���3�q�1��SJ�������4��<��u���sr�m����Iu�&c�?&��Z�j���;S'����uKqjs&���gv������$UI����B��;�B��H��;~�����8<cF%#&����ij*��������������������i:���ybG~��7i%v�PHum��x-��yKks�mi���9��1����i{�8�M��Z�;kv��7*M�5:vH�-�8�����>�������'I�����5�+4����TH������r�M�����icGdL�+kV'�Y���N>����M)/��J����J����|��{m������o(#cs����XH��)�65y������9�>����������/G������6+��N�����Ij�d�&f��u��xV'f�_����U�������x�y����86�>3)������>�o~y}�^uZ��b)��)ue���zH�?k��L��%��cc�?����w��4����9yH��b��;-���L�u��2����U�<&M5I����>}H6=��
}O���Ui�?*s�5�:Iq�����&��y����\��
V�p'��O�����Z8vR>��Ks�E�)�������Ky����{��r���LS����Sr���yq�������3�q�9�bk���|�_��J�-s��3r�����HWk~���r������$�t�2�u�M!�#���ES���}����K����"��X�������k}Z��������>��������.�������1��lw���i.dC���Sh��Y��-�[�������g1yR�?��Y<���=���0�9S���L;���04c���dKWzK�dE�6�w�L��Y�R����������C2z���X�����d�|~��3�>#�{^;�{�T����5i���c#�T���O^|�#������?��'.4�u]��oK���d���\s��4�� �O��k6���9����\��Q9a���<gB�N.����b[!c�o�[M��~}��a�#Y�he�m�N_���������;}Ou���d���=G!M��T?�{/y��'e�O��g�_�����S�g���2f�T���-��������$IoG)��������?��q������2�ew�w}�{�b8 �y��\���S](�8�8��A�$�<����y��,���2���������{�k-�J!����,�U����a���f��q�k����\h���{o�=�*+�����W��������?r��)���e+���3/���32a�y���i]]��G��X*���7w�����M��r=Y�����|{6dlv�zMR�Q�������{[���+�����>pA>����-�d�UO��C����J���|�;�����-������<&��������Uy��������7����I�����7te����+O-�:Yz�wr��?O�����(;��{v�{��������<$Mcw��I��y���4�=���I��[��R����1�Jiy��KGu���g{~���n,e���_H�#kZ����=wV��������2s��,������R���j��K!����5��by1'�>6�ON������4f����T����RZ�t����m����������l���t���.��~�=����3��s2u�Y������V�]�T�h�	M�%�{w�������'�l);8Nz���+r�����O�MKFg�{Fm�9��5�v���J��*&k;��R��+�w�R)�=5i:������\��2�~U������~�5]��3O�z�R���Y��\�/u�u������JF��:�>�'����.5���+�����S��[��45��������[�%�\�K�j����Cj�Pj����}]WZ�]���~�poik�������:�Q�yQSZ��@n�'I)��?�����|�l�
cs��C�������R�R���@�z~xf��{�b��q�o�a>>YV�����fUK�n�CM��$�?��j����I��Q�t���6���Vb+�����~���6�!��GV���]i�--�n�����q{JI_���nTaT&�,���y��Rz�Zs������
��Y2�~Un��3��A[k��zI����5\^z"��vm����L;z\.��mi����������C���K���[���<�d{2����x�8��������z������'������Q�+���Om=�n �P�ttg��CO���������*��z�C������k�IO�o������'+>uc���'�$]���������z�F���iiK����?�U�IW[��K��U�{��t����'���t�y��m����M>�3�q�9�b*�S����wf�y�(I��ss�U�2�#����(�~��?6s>>;���0_��w����,8{�8zb��k�M�|'�+�8jxf~ln�G�����/"�_�|�Y���=;�}n���3��\�so���s{[R�<*�����;u�~����?���{������MI����k����{t�=2������{������I��}��\����C�G6e�������I���sT��YvLc�����WN�3+��?�0��d��\��Y��u����O���z8��hE���4M���>��=��[��������Y1��SH�L��{s����T�	��9�Z���0��M���)�����4I����<37_�P�9����3��IY��)�K��:r�g���g������>yF\��|��e�7f�����w�IYp��,��w�tu)��M���d�g�l[���C���,����h]R?*3?uA������<5�������173�����k���=�/^V�+�:5���K��2���Y��%���B��|{����<{K���BW�����������-��
I
�9���3���L�rvV]�<_<Y���������s�����f����d�E��M#������'&�����������q�-%��O��������n���w�������P;�����x �	����e��r�`�����S�d��V�k'gv��7;sO�i=>g�T�C���Q�T����N{Wo^}��)��P����r�v����y
�7s�o�(���
��r���*��4hP���
��!��tu��;��(���S�����3Ga��PW(w8 Td=�e��rG��*��4hP�#�sY�8c8Ud�p0��b�Rl���"�K���,vFY�X�
8Ud�c)6�`T����H�P!;�A�}���o�P�oIU���
*w����t���~���?���1c�%�}�B
�o[VecGG6o�����v���{x������AE;[�l)w��<��#��=w����u�o��y�����o�Xl����S,6��0x��7���v�96m�Jggg�:;��qc:;7��i3v��,�I��������c���Yg��#�a_������cC>0��XD
�pY���o�N�{��$��w���3SU]=�};:����gv���^��TU�������������o�����g���;���Ge��G���&I���������5����O��3f�������*�==���Km����U���Rl�@u��RSS���8+C���@y3C�����t��g�������o��������:I����A���cO���44N�kg�44���~���q��;|�m��4������K___F����Ff��Qi:l�.s��W���+��f�+�d�����n]6lX����;�o�9���#�S��"�K�5��S3��S����bC����=�-���������weW�N�����/����/�����F�����,��~�W���uo��������L�����'?i�����b��y��?����������������u/����_�������
������CG��#������M�P�G�x�b�h��|6G1n���9UUWg��Gd��G���u�ZSSS��}�����
�M��"�����u�O��o[2���r�ig�;R�1�����T����A��(�������sg�y��$���2�8�qY�l�����}l����w�������-[2���u��}������Td�|��������S[W�Sg���w�R�H�\E;�b���I�8%�7w��3OK]]}���EE;�b���;g�*w����b�l����aC6l����
io��$��9��9��M��m�����};����������;���v�������U��qc6v�g�������g���}jjk���1#���g���6,C�
��a�`�;�ny�����;�M]]��X���;�bC>��?{;�M�HoOOn[���f�sI��O}G��=<����C2t��2'8�)v��������3��#2���3bDS�#t*��4hP�#�A�������b�c�)w��b��-��%�@yUd���7o*wvB����'?�������R^~��r�`*�;����_>����'���2d��l������bR�mY��X���k}9�55�9���|��
�rG`;p���������<��SI�I����f�����eN��(v�-x�����e���apN��������
�3t��rG�����t�����q9��������	���bg��A������/�x`YN=��n���u��xy3���K�����n��_���b�c��*����eK�#p�����%�~7�/��BUU������M<�����?Jggg6uue���tuv��sc:;;3|�������u�����a��~���k��R__�������5�_Hmm]j�jS[[��������LY������g���nMOww�utN����n_,6�XlxKc���rD��l��%�6mJWWA����v]���o�x�}������.�.�$��uo)�'�$Y�����.K��s��y��Y{u��#G��K����7o��M]�������8y������{��l�������������i[�J
��Ft�H��A��{s~x������RS[��.����~[��������~@��:���r�7�j+^���|.M������<��	vH��Am�;OK��/�g�LUuu���N�����s7�����6�JI��q9��33m��u?����k���]I�����Y�?�)�i`O�y����rH��������r�
��5�]��f����z8k�$]������13s������]���,�+.@������|[63.'�H�B�L�a�����$�����9��2��T7O�9�&�-][��eW�b�iFsF?�2�X]JRJ����yrs��I��-���g�v���<$Z��+��A����J����
mm����]c���r��?�?��1�R����������I�UJom!5��������=�����J�J�J2��*��B��;W8dPF
�+w`�Q�����3Ga��fs���������+�;|�L��W_�R�p@([��~�����F��������qO���ei����P,���'=UC3�O'�������K���tl���M}������uY�~s�c;`����<���9
����hw��,����m��:,�O?���2:lXm�#��LK�����/�a�1���;Mg���_���&����������rV����g:2l|S��	@ye�������m��������W�a��,w,������B�3$���e~S�k��������9ol�!�2}�����r���R��x~tW!S�����8���K�~��T�R��J���
U��*��I�3bDS�c���+���������8���z���{L��bk�N.i�'_��x����)�����#��&�>9;k>sO����I���p�9�{|��<^x�%/��f��~D�N��;��i{�W���NUUu�������N�7ir&O9q��N�_|1�|�[�����w�y�>���2���-[�T����\c�g����9
�?��o�(�����������R_)}�����o:bD���w��C�g�|�������������?__��9��1;�L���W+r�]w���.�uu���KMmmjk�R[[��������o�^����;��4���	�u���TW��� p)�;�����e�V�2��;,n6���PU����U�il���7��}CZ_~�u���t���I�i3N���P!*��4hP�#T����<p��3}��T������56�r��&���&������7�{sw6woNmM������,v*p�8��{��-���?����I��f�U�D��2lC3��Q��*��`����r��w��?�$y��wd�;O+s*��P��V������%i�������?� ��������H�p����?��V�W����N��3g����AP��Kp������a�9���{�����������i3f:K ��;{�R,Y�4��������-[��;@Y�J���=I����]�4��R����������?�-���0xp�9s�%�� Q���[�
8�����M]]I��U�����K�L8nR�>�\�D*�_}K��n����ohK{{{�<��6l��>����t������y�y9v�q�"*���b�������m��tt���m���o^s�E�vZ�?���=&uu�������������c�!��n��������scG����q�NHmm���������%I���3tXc�b�!
�g������G����?j���2)vv���e��5��qc��_����_��a#G��#�w���?~W
����T�������"��A��;p�X��5#F4�t�g�~:/�ya�������#r��#r���?��������"��-[��;P�����<���N��W�$�?��ij:l���2}F9��4?t�%��T���[���Wr���d���I������CG�����H�v��}`�*�����~����{����/�&�=|��RU]]�X��"�K��c��r�?MUuu�����0��rGxK*���c������	���a���-S��S����[�� IDAT�`��;S����A��`���bg��-���G6o��[+-�~S�({�k��7�Y����l��J�PH��?*w$���"�K����j����,��I�w�2=��1������,v,�����s������Rlh��;G4�+w,���"�����SO���^���������i���eN�o(v���8��T����3f����(w�}J�T������������Q��C���4hP�#e��VY�l���������=k_\S��%K�eq��w��sc�:7���3]]���i���?�wKuMM�;�n�����5����>/�}1����iSW6m��M��R]]�|�ov�/p��k����08�62���)�%V��}�8��7+s���I�TJ___���R*m���/c�h���/����������m���L�������3d����F�8��o������r���;��{���Y�B�kjRUU��BU��kR__L��*����q7��3OO
J]m]����o(���~�e��Q�w���;P������O�:O?�D^Z�b�d��1;-v��p\���Uoy�����s����?o�b*�����_=�g�~*�Z_�v��1cs�����	��1{�b*����,I2��#r�����	3d����;P����s��w��#���0��q�G)w��~�����g?����v����S�d��eV*�������O=�g�y*�7�:c��I'L)s:�'e-vz�}<�>�"�=���9<s�av��\����UYr�����+��>0+��5����`��:���������w�����g�~2]]]ye]k����&����;!Gu���@�(_���:�?�Hz?07_8��
�-�u��x��05c��_|���3;W_;.�������f�1��e��{��_������sc�:;���1�7n{���,�����7o��W^Y����d����m�N��#����Pe+vzx"7N�'���$M��k.��`��<�|x�\<.CI�'��sWd�����c�^g�������x�}�uu���M]]]��w��O=���z�{3"��;/>����_\uK���JF���;-s��I��e]���n������d�]���{Wg��<��9��c2j��nw���2c�����Km]mjjj�aJFe+v:��d������s���T��o�,_��i^<+�J��-��{U����������UIW)]IF�W�����v�p���^W������3O�<�l����~:?�_y����e��^��)�����������C���w�_�������P�v����L���N.�:I�{���o.�c�$��Tw���jh&���4_��u}I��b��M�����\��]5�.k�o.w`�Q�����o�vv�c��e::��$
�g�	Sr��w�a>���3Ga�u�0g���P�bg�����uW6%��vo�?������x^lk��W�J�<wmG��oJ1I{Yp�y���r��������Gf�����	��1��!��8��LX�x�{WG�RZ?�������I����������^Jz�<?������*W\@�62#G�����C�4�.�T��~m��-[���a����������R���s�av�_��mu�|�����+��.���6�:I{���`��w������3Oa�f�������a�jS]U�s
��Q�b��R����D������y
{��M]y�W+2~�Q5z�{^s�o�(��;�g��;�7����<��y��O�T�����s����{�b�����9/�]�W_-e�����k^H�������N��SO.sB�s;�W::�����������L]]]�v��n��~}����v{����z��9~��}�)�e�����]��4��������8�y�N�����s��9)6N�a�������J�@�uvnLC��v��44N�ap�0xp=t�N�����I'����yt\������v�*���<[���3�L!��a4��I��$}��Ig�����usn:��s���sI:��4C�@�h�0�6�%��d�5�T������w������g-/I��o����K����,�H��"��`������.]~�U���N��?����������2MS�o���o����^I��E��92`�#�8/������Y���U�DBN�S�/��W���;�Q{������I��K�^�B��_NB8�H�F��4(���%K�i����x��	��H�Fm���;w���������^c�Q��W.������GO<�d2Q�p���TN��m�h�[�48�/I��g��/XT���������@�����nTm]�������o����=^���2�����q�**+�k��S4���5�������H$,Ij��@K�.SC��"G����B:�����=��h��uwY�'
�"��9�C������^��_n9�E�Ig�k�'<8�p8�/PZ���i���<��<��$���+��������[<F�$������
�3�&�b��B]�W]��b��k�X�����v����������wi��9c���xL�hT�hD�pX�S�TSSky��������*I*-
���B��rU�mh��P��r~G�Am�]�488�Hx��������~�r~$��}{TQQ��������x�F���5
�_5��������N*���m�j���#�a\n�	�7�����v��;��kjj�6o�"�A
���I#��^�B����r~������KK���
J���j����2]�x��
�8H��4�z{����k���#��4i����=g�c|�	4c�l��9��c��#����C��g����)M
���2TE2������L&�k�vy}>���P��\����b�5*��g�s�����&9;&��)M�����6w^�C��NU&�h4R��:&3v��L���vi��w�~`�>��������a@Q�Ab'�������"�Z��$����'�a���j�a����
9/p�.
���V��NI����~�y��LF�4c�l�=�b�EU0����g�������iZ��B������UG��i����{�U=VV�����X�`���S8<���A5NiR(Tcy���#Z��#{�^-Y�L��,S��l,��q�>�����_���+w��{*$I=/����E����\�N��E/��?����Cjf�p�{�6���G�HX���E�'����&����K�h��6y=^y}^������
������R+n��K��{������$�a��{��#����
`8|�C�v�/I
�����Ee�*//WYy�������e
���S���)e��D�h�����	e��Ye.Pp&����J+._����b����v�RCs�6��Kqe����z�����><���vm�P=e�H
�����������zp�^�����c��V�����$�������O�h�������
`�����Wmm]�C��N�Rle���7~<S[���5s��,��8e��j���u�]�&���4M=���������T]*<	p�L�H�F�V���Q�<�Zp�c0�r9��WO���a��NUeeU�C��N������x�:�B�R�%�M�0����3:�o�j����;���a��p��'v�=�����T��\�J����i��{���ya�P\���V;�oSyE����>.W�C���}b���U6_��wkW�Gsn��������~�i&����^�6�% ��?�y��b�����j�g���Y������]z��m���)Z���t�-!q�0yE�a�}���n�u��
��;$��H�|�?�NmK"�Mi������9ZCb���ee���w��4�P�����E�`b'�w��=�K��oW�;�������Z�������m�0�>����'X�����_�H�,
�/�g�n������A-��E�*���`�������R��m9`q��Q��hQ�y���q��g������P`�Q��i�:�y��a
 �@���S��?���H��g��������Z�jj����"������];T[�����O�a��P\$v�����o��-�UU����_.���!
���kk��?��N8���������q}��_���z�)Z����c�{z���UQY�{�{@n���!�@�;�v=�X���K>���[k��a����#����)��������	L�dB/���*+��=�= ��_��g�����v>�Y�w\�%�'��k��J��l������M7�,��bW�"&��������{�W PZ�pg������Mz�c����B�:���T}��������W|��&���J�WT>0��O�@�]z��z���.WH='����x�r�����/���;��i��*.���R�[���s:JTW�-v,�F���u
�o�Q`|c����P��!�B��#Yu<�^���V_n����9~�\���F��nkSh�Gf�)���K�$2�&�"�
�L�Uz���,v,�F���u
�o�Q`|c��WM���!�Bq;�~my�_�=��+?�$S������(��5������ut�B��F���;�O
�/)\����/	����:�������C���I�8�gHk�|Hk���������G���+$�E+V���O�k��-�ul�s/;��o��.0^�bQu������:�j��od�0������Id�6�qk���S�_�����E�W�_�Ik�;.`|y��_����$��t���UM-�ji����F9��"G8�Jr����X��c��g�o�Q`�;�u���m���UK�454N�a��{��I��K���5
�_5��G��&<����h4���{����:|�C��.��E�-��7�F(6;@�����=�?P���D�
���w���!`<!��;oo��/�$I2\.��N���3�+����&.W�#�'$v�"j�6]K��5}�L��N�Do�5;�y����u�S������.�n������B5Z}��c!`"#��Rw�Qu�T{��hW&���12�dCb�H8�=������RM�1K-�S�������"F�lH�`R����zz�)744r��h��K-�e�i���?�}���}�r,XV�E��*TS���VU�Cp�����y��~��O�J&O;^��M���t����9L��aX�t�����Y���Lh�UUr:��6c��UWW/��=2�v�mfK�W�������0d8
9
����]�0�H�`�13uvQ�����bZ}����z�>}�O����oJS���0VH������y��:;���C:���\.'I*))�����-������PT�i���?���!I�DN��V�S���8E��M$u�_���z{{T]�7C��^&�����&544�p��0B&;8/L�T��nuww�Xw���UOO��LF������r�����a#`�"��Q����H�O9^YU�����2k`tH��Vxp�v��$�=�7LQMm�jj�TWW���ZJ�p�M��NIII�C������^���vQm]��,]�i�g;�������H�������<�X4�O���j��d9o����(�xM��N.�+v��E���i�;[G���W���-bT�=����k��S�{}>M�1S�1!_60��:�y`f2���-m��^f&���*]��JK%I�uu��_{�w:x`�B5��2f�u������U\��]:������+(�<��t�:T�����kjTURmm�*��F����"�pD�Q���u��u��7i���g5?�N��pf��m#��e�������V����f~J]G��Xw�H2�Xw����w�c[
��[n;�x@q��8**+u���jJS�9�-�������>�c������.uwu���n�����/Xd;��_��:��t�p�TUU���j�|���	�?$v�����G�55�������G�����l���5GU�!UUU�*RUe��ee���/$v�P<����-+//x��K/�H@���(��������N�����SIII�C);������kup�>I�������v{��X������>���Z���KR���kV��:T�������	~�i�^}�%IR�������T[[W���H�����Uu
�Z��Mij.v8'!�p���z��������g���Ab`� �.J/��E���;��Bb\t�y{���~��������;��bf2zk�k2CW������;���i�[��bZ�t���@��8+$v�E#�i���2\.]~�U���������.3��������)v8g���(����������i������`,��)�����2\�b�pNH���B]}���/�0x�&.J���I0���� H�LE�G�����?����7g�n���Z5���m���\�W��%_�|�=xWH�:�����l^�~"��{@�����5=��������6~k��6��7^zD���<e~���z;[�p��x�O�V�*�8�-����-��PgVR�]6Wj�g[T��\�m��f����.�`:�V$.v�U�;��m������;�lW��:MwK�P��R���9���~��>T0=�������{J�S���)b���_{M�"���"�$)�U���;���o}A����N3�xVqI�>��q:��p:JTW�-v,\kt������Zu�j�+/v8�Y��)0��F���5
�_CC�b�L
E��d��������Z�7�[�9���N�Ri��2�����<��^S�;��IdM�E����J���������F������Z��m��I��b������X�������rO�C&��&v:�����S���?����B�Nl���
�z�I���DT>5$�$��+���d"���_)�?P�p��������I�?f��������$[�bED�<��pV����^vj��u�	L�hD[6o�������,v8�]�v����.u���������J���5�e�[��v�:��U��
/J�J-��MZ3�X���`����4M���*��l��O�;m_����5�*����j��E&������t��b�pA������#�Ww�Q/q��T�;��aj��T�0.;��	���Ab`� �&�d2Q���0!�����������,v(c���pr���x�e
e��oh,v8c���p�y{�"��.Y�L�`Y��3$v��b�������KW�����L IDAT�);`B���M��b�t�ry��b�0�H��	#�Ni��ur{<�l��`�����
o)�Ji��+�v{���3���Z�p�R���\zY�C(
;`�(���u7|��a
��&;�0.E��b�0��c].�Sw�Qu�T{�>��������b�0���E�N�������qP�:��N�F������*bt��P%*��/�$I��6m��ZZ��2U�U$uN��(
���[n�]���B5�`B �����~utTG�A�h�C�|^.��������0:����8g���E�XT���;[�FG��P�j�����Cb����}{�F�E���F�H�G�=����Y���}��>$)_Zm���jjjQSs�����p� ��$�H��������/������}Z�d����@@��������[�(q�������*vFb�	*�N���^����H2��dN:�Pb��kV�0��

J�8����9��sCb�q(�Jj��=�;��9.�[oo�<�~yy�����o��UV^^�y.Y�������`����v9rH�dR�TR�t:�~2�d*�����/���k��x�<�<�|>��n�<^�<���kTU]mC:�R*�R2�T:�R*�T*�����6o�����^����,�
��6�#I<�9�A��\$H�����^VW�Q��)�fF�Lf�m:��}<���F��{�|�];�?�������UEE��n�����tk������/�
7}�r|�;���~n9��8�6��r�d�|>��>��^��^��>�|>�*���J�TSS[���
�d�LU{��I�C��vm�������kx�q��w;��8�2\NP|�&����}�SR>!�r�d.�|~�K��v��W]��W����������9�����ku�e+N�q�L&�J��J&U���i����x��I�w����(���K���Y�������M��pr:���C��)�a��R�Sv���?���]��D�DK��D�JK��Ju���-�'�	�����9�|����������JC��<�Wn�G�[:��Kj��o,��$�)��[�W��p�y_T���y�L&��uT���������]�`��E�UW_��������TVU�k�#��a+S�~4U������g�1����b��*���d<��V$V*�R�L*�M*�M)9����U���Y����C;z�Y�_�t�.k��r|��Mz������B�t���,�������t�1��R�+(��U����g�Z��R���l.+s���?d����d������{���,�gU��&v^mI�Y�l�m�Zd9���W��k���#�<N��$�����4�|����W,S��T^'%���������WGRww���U49i|N�\����i3.t�p�"����=�K��/���D�����e�*�T��K��v�3��*_���!U��U�
�p��(��%�����tT�L~����%r9�KV�m����G,��.�M�,o�RmU��#C��NH��j*k����*U}`��\F�lF����[����������������������N�����ie�����Q���GC����s��R�����RfR�1��^�Z�����_���K�A���lZ�lJ�lJ���)��������z~�/%I��X���������m��A��K��>�ZZ����N������Su�})3�D�Pf��ev(+3���Jo�|.�B�gbJ�)��R#����h��o{Q�����?�7~6�t6%��#�����jy���]5w?����8�'���)�K]A��MU�����pjP��wJ�����U���u�;�!�������d�"��i��U�T���bBk�TUy�pp��o�w����`�/��_';s��jN��������y��0%�<���BG5u����y�	I���G��O�q�5��J���"�Eb�Q4Q��n��)��*�5��f�5M�����
�i�~A:��������������6��~�������?S `���GO�`�����~�=�6��N��V\���^���:�.\�d\X�lZGc��
����)���>�����r�|�f�������K�V�6b���7q�r��9���r��[�n��p�<���C�G^�w��G��z���Y��N1�k�l�p
��n�e�f~��PF�lZ�PF9�T���M�n�������]?����$������e������������~O���/�KRc��6�3��WO���c�����_;�������-K@��O���Y��������g)1���b�����X�[��c:��PnH���`yn�W�Y�m����g�t��;N
(��`j@�����A���7�S0���w��������������p�m&�/^����tDR��S8!!�~[����U��3�\1�C�y�g?wj�����;�Y"W$Q<U8V4V4�c(�xJ���w��/���/�%��Z�����P�G[����4s����/�Foo�l9~�U���+����o�^|�9���3g�&v���u�[�J����r�0NCN��a�u:�t���khh��e�G�������:��b��I�u$rx�ax����gb����R��[g|�r~_�W���G��������/Y��r9��R�����~��r��s���2������j_���wFk��.��B�=6u�e�4}nh�>>�����m�|�r<��n�.IC���!�s�!�69�Z1]i35���0��uz�v����m�����x�^�{*�4�L
��g�p8m;���#%�N�)����>`9>����o��+��gu,�u�����M�H����n��&q3�����������_�v�g�U���9�������E_8�����F#��3���{z�����E]�>C9����k4I���z�s�~�-���Ujj���k�T������f�I���w�0��������:=�U�;�
���o�yT���p,���d���f\�LB�lB	3��\VB�57��r~,U,�_�wyh�|���/IC����_�X&�x&��3l�e���7��9��Qb�?\N�N�U�+�X���v���/))�S��������
�a�Yb�����(T������r���u}�f��|����Sf�Y��H��
��O��t#���p,�TWZ�{�=$����������>���<No�9������iq�����$�I���
~�������m�����&��V:�P}`�B���kU��Q�o����F��:t�8u�����
)�*U�]���Te��1�0Q��r�\��8[�xF����_������pdP��A
(<8���>IRC�����,��RI���3*-
�4T0X��4������f��3p��*���O;��H�+�T��(�+�
+����ji�e������H*�w��l.���H'���~�<�6�����o�p�N���0d�8u��{�qZ��|�{�bfT�T�y���n�J��n5�N�����S�L����?������~43�����cq���\nHK�/�����F9�p�"�);��P��xA�#}5fU���[a9��}����w-�W������m�������������tE�u�` �����}R�hs������*����V�Rb������,�%��.���%�7���yd7�GK@9��#�����=��'�m��zY��j-����z�Z�������p�K��=�_>#0�#�L���w�����#��(v��7��Bp�"����|����h��-�=���?�{��c�`��v�x<^���S�s�\�H�F�25��W�������v<������Um��
���5#*s�����]��tX�#�KXK�p�tt`P	3�����,��kq3���oZ����w��C�K�N���J�2���U������Q}���;������������r����Z�x��������w�qz�vx�5<'%F*}�
(�t:q3�D&!�H�^��E�~����w�8&v�zU�����C�`���G��n��(�J�����|��5���|�~�_�~$������~�pBk8��M)i&��KGm���m�C�Z��NG�&vII�pd�b�8���Y�;z��������*�$�/g��Fs���w���
�K?l^�
\�����?#�<H����#z��-
hppP��������e��������n�?P�@ �@�T��_^/e3��I4Q�L)�P6�<He��gN�i��jf���#������i�\��;�DC*�T&��7X���f�vzl/���I������4��������Km�wC�����%����nwA_���K���!L*�Pr��g�?���u�����*u�5|�>�\�������J���l�}W;zNN*��*����S�y��R>��1N���2��*��9�����c��l�%��W����z�]���������3���cx
�}1�>=�m�)����(�T����OA�*=��]%��_���u��rO����D���`9>�j�n�i�[�'qL/��R���fB�L��$K]�Q���r������'7wz�~�5
�����
��)����pt���:a��	I�BM�[����lz�8�4����O*�>��O�}�r��t���:}�.au��;��&N�]x<��3,��\�i�3F~���^���q��^�y�G�9��@b8G��u+�Hhh(�L&#3c*cfdf2�d2�:}�jk�,�w����{e�Ye��L�T�4e�?}�L-�����pxP���3�q��t89��P��&���R-]f]N��df3:��Vw�K��]�Y9[S�gX���{��:����AW����v�jZ����3�OX�����(a�d�Z*��Sa����w�6z^��J+VZ����{�=������y�u����=�c����X��{*m;���u�X�K��^��m�p����O��|l8���4��S!�a=W�.o��v���u�iJi���
��I�pzP�"�R�]��&�h���W�_���n������z��k��J�A���
�J5����K��]�f�caJ��`�
;+V���rY�ZT�d����#���RfR���*��D�>(��O�U���uz�5|�>Uz�Sn�Gw���9�/��������j~�y��Q%��������BfW��a:p����E���E�Q�RI��Ie2i%	%�I�RI]��*������W�o�n�q��o��9t�]�6X��./����:U<�9�9�Dt$rH?����������~��1���������}��/��v"�����}:�Rw�������7�����@��,Q,�i�;22�s�l;��z���
��*u������C���^���}��b;9�l._>2�3IG�w_DMGt}��*u[��I�q�rC�����.�B���7\�9Us�w���N�S�TSi���BM���)��ke���������g�m�Cw��wB	��w��9�6�#�/h��8�w��l�}��,�O��>y]����F�'\�O�1�wl~$�'�/�w)���K���M�n+$v0a��)��1�bQ�b1�cQ%qE�Q�bQ�~��]��?��"�A��X,j����`����K��%u$i��K��d}�����"����l��h&�pjp�|������rJ��*�;�+������4XsY�RC���B/[���U������?T2�T��\�����E��|�>����G>�IP�
_$��[��w?O������mL�	�2���o����A������f���qI������xJ�"����Q�.-����^%������!e����9�^�����������e�W�^�����m���^��]5wTw��e��)!�`��B���j��T����!Im��j��h ��"���J��J�RJ
��I%SJ�Sr8Zt����tJ���������)���u��N��d"!��+��#��+��+��+�����u�\I�5�M�f���6�ee
�M�]]�N�2Qe���2��fde��7�R[�|��%[�6iO�u��y�E��k��is���.��i�,1d8�
�jm/�31m?����G�Gn�[���T6���T6���Z����r������m��w��=��&�Y��lZ��R�� ���h��QrSi�m�$���/�k9�s�m�M���@O���q��a9&�����?w��?��.�K�����t9���L,�C���y6{�n�J_�����a"�����ZV�B���Y��]5WU�|����@"�L/?T�����]5wdwK4U<Ub�GE��>�MG�`��x��R�\�'�����~���������vZ�0�r�2������F�Yu��T~#������Db�,�N)�L)�J*�J)�L�$iJ�A�����#������x0Xf��q�=j�6=��N��=y<����6�#I7~�����8fet8z���MII�.�_a�O��w���[�E���;��>�x�g(�0���&v��}���KhHR8���}��S�g�&v���^?��r��
L�l8��v<3��M��Vw�:1s�q�����n���+�\m���7�G/��r|Z�L�7AO�|.~���\AwY~��p����������pjP}��%z���U_�G}�^���w�����3z�:8��YwjV��������k�i�|���=[NT��W���1��v�/H��c��\��/^��|O��]6��7�8N��K�����V�4���i��������t�>��S'����R����So����:��5.�*�������BrI
�3�&�/t��@��d��L3�l��i�����
�S��b}1��m����������3t�]�
d#��^����D��+��'��=���*�������H��C���'�$��n�m��=��7~�r����+m/��r�%m��n�|i�
]�r���������_Z�7����d�K�����w;=����������G�l��c>�?Ri���l/j���M�tL��%��%���Q�TCUP��i��5�N��nS�\6�s0�=��2.��&�lZ�"�Je�������JK��]��5\n���#�]B�Ia�g�s���������*���q�O�����=�=�7Gc�IMA�������������Kt��k����X�����='�'9a�X[h����`j@�L<��J\2��\N�����h�Uz��);��`��k�X���US��������q�c'���Z��
���i���N=������u�bg��;o2�t�"�i*kfefM
e�2MS��u2\�w���uvR&��gf������Y��[�!��������Y�_y�5����3�n_�\nC��%��-�e��q�p�����>e�Yh�{�@*���������>�/v�T�������6y}��w�lS{���������_��&~*���
5�.t��p��l�����jT-I��s�\N�<N����QV_��
����ym8�����tkZ��Q=�]g�p�d�%����Jo����B������I���rO��=�������N�]6Wj�S-*sJjn�M7o��/vI�G������a�Je���i��)e����������>o9��@����oX�;
C��������?_�T2e9�����fL�m9����k�����M�[m;F�S��%r8r8*~�p��z[�wYT�W�v��}r�)��R^��Qn�m��p�����q��9��[^�>����&�C����]��gr�����ZX���yVZ����l�9�/uuW�}�<_��KG��cg|&v:���T�	70�75�r��j��#���O~7�Ke�tX����N��z�j��#a������_��G��S[���^��CC��9`9�(q��������uJg���;.�\�k���������c����u4�D�G>�O���2����44�f��K�����v�z�j��2O��lv�4V/��YKm?G{>�Y��F1_�d�����(�Ro�Bk@q�F���u
�o�Q`|c��S�*v��0>;��2���v=~����}u�!���K�%cj�h�����p��\��lIDATp�y}2�|��.t�N�]2���]|�
g�s�/B0h�(���IO|�	�q�nw�����v6_�S����Q���V��K�&�����;�J��6��v[�B�<2{M���_��������y��8�kS
�Y��.����K2�F��$3')3�OYI�s���F�����?�)0��F���5
�_5���(l|&vB�Nl���
�z�I���DT>5$��pq�(
G�8�`�V����'��J�����N-�����d6>w����_�N������%_�|�&��W���g�&v$U4j�w���b�0N��Rl8��	���Ab`� �0A��� H�L$v&�����w��Lz���(0��F���u
�o�Q`|c�&��\.�+v(�Rl��	���A'9g(�u��POnv��>��k�����KRV�|UO�k��F��ym���.����s�m��Z=��
�����������<��8�;��{������+O8^`���m����v�:������\�[���h.���U�?�\�y���]����������A�S����]�o|g��$��]Os�^��|�Z��k��]��s�������;k������z�r�>��%j����_Yh��ag&�}?~U?~"��|s����\�U��/J{�����X���_��?�I����E��]�dEb�J)wk�7�#�O�J��Mz���V���qFV���Y}������8�������F}��k4�������^�p��&���M�g�N=�w[�+--�������������O���*��k���|U
?�QK��Y�|���h�O����"�L��`$�������K�p���6~k��6\�o|�E�#;���_�S3�������pf:~�[=�����;4�?�W�����j�����U��J�uX`
8#�����O�t��������O}�/7i��.��������D������
{f�w,-���:4�eJ�%��@��TZ_�Dff"�#�U��gF�L��`tp��9��=:�*�@@���k�8"�v��Kwf�vw��GT��x@�f������zy����gu���,�8��&^�}V,-���^�J�.aN�&i�:Iud�}���[�����T�	�lJ�y�{��A@����2������h������#Z��H������?&(��5���������b�����^��;c��c��p�u%
�'���{;:G�p����J?���;��7�h�d;v�`����
 RT�u��������]I�B��,�Li������8���I�+h��aI�����Y�]M�w��l�fs�'���4C���bXn�����$���I���Nv��������Q:g
?\4�� ��h���}~��ed^��f �SZ[��
�"�#��5����K_Q���x�u���a���4'9Y\|vJ(b��I;l���p�x�� ���s�S��[��
n�&ZRL���eZ�i6��}���E1Nl�������]�zI����k+(:�:E��	����3�����X��0�_.$z��&]����x�u��M�}���l����nN�����'8��b�����N�x��]I�%�;�)��bcfM��������Lt�f�u}IuB��,�^����fgg6���t
 $}2�Hv�K�������	C���Z�%��v�N�D���g|L�w���H4��T���J:O��L�(��_���M�rge���U���
I�dw6�v�xhu�Y�
I
��J�.<�6�MWp�]���}e����6,������g��Z:�LX3�l�e��������:l�����]I���;�'�3��Ug_�1��=<T�D��r�9�u��������MAV��D"��Iw\UNeW�������H����t����}3��
!/���� �T7Y�Y�+�������g^Q���	�����`B4 ��EWV.��TN|\�m�
���J�0I��o���Q,�}%�����+�m���aIC���fV�N1�77R=��p���U��Y.�����xO3����zW�t	3��48�$v�(������n '
Jb$�$v[�m�K��(����	����Hoi��(�H��K��.�d��>�X��.
���
��A�f��A�5��=�����!�H���d#������'�9�x��%q����� E��o�b�x��DQ�����r�v��_�4��md�����F*K�^�v����c�):=�aB�<S��]I�%���$
N��~�F��M������Zcg��F3|���qa�}�7�re�/�Qq}��/��$�<�������(����.e���2&�<�_6%I������L��������w������]^��}y��<�3mZ�w�o�#���F��Pq}�Q����+�~#��������:�}��p�6,ip��w�vu7�=]uN����6�z�!]@*��<B����x�+I��}���S�.v!$e���
��m#���I�[#{�t,8�������Y��0��0�b<��Oa��La���6S�!�	�UOa�����k(�+k^�*+_�B���tN6�����%5��]z��>����$���\����jb�������:��y�q��HuD�����vhg�������D0|���o:SO��jo��������a#��h6���w%
,LPw��lh�����.���_��<������%
�����'_���?OFP��\���4Q��v�w'IgG)�5�;��?�z�+I�T�H�$I�$I�$e�b�$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)Cd]�H�$�����sn����.vi����w���s�qsi�E�������b�M�����w5R���X4��%I�$��f�#I�$������vK�En6@�ps�����fY��z�$I�$]�v$I�$�#m�t��uW9�E�0��|*��_�RH�$I����N�:u�!I��#�����,X�c]���H���\vs���Y���Go;��g�3b��]�����D���
h]���P13���nL���1��y���Y=���+&zz*�����O����A���),\ZF��`�.���+/4�|<�X�1�N��{�)��^&A�u���f5�oO���.
Y��F*c�?��C�=�;v'���;�Y�TR}e�������F_���Jf<���[����+/�S���S�}��F�j�����INv;��E�TO��[�~wW=���w�N�����'u�Wt
����������E��k�xd;�8�y�9��������<;�	;������=�qSxh]��u�n��g9x0E:'J��2�.�BE���4�v����>�I:+`��R��VR9��2����]�;?L���a%����Jjf�=@��������*����R	�����-�9��H~�	�Og�m������b-�YT����Np�����+�y�����nj0��$I���;�$I�������m:w��NAv��G^e��]L���t����,R�Z�O��|{��'��f~�������4,*��7Kh{����f�����X�l+k��y�����������������F���lf�Q�eq�����-���3���~��qQHv�5��#��K�l���,~�����m���o����.&V�b�t��[�Y����?]���v�X�+W��|�f�N����[���'/@��Zxi�fV\����(��8�~�z��D��DU	PX���-���f������������Y�����V� ���L|r.�H77�������w�*oyI����� ����`�e���������^�H|I+��M%�|#k����{�o�x�W�,�����#������y��F������v�}x+���f���g�$6me�c�O������.�����B�#VW��AJ���7x�H)�|��"Hl���eo�v���;���D����{xoR��I�P��7X���	�������$I�t����]I�$]`�*vz�H�	3����������1�KbD��+����e�)N��],]1��k�����p�UpxK������7���F������������/uz+�y9�����l�����&�0J��r�#���3�O���)��Q�����o%��v�1:A@$��7O���Hv������z�a����i�����s�?���i?����S�t}#;?E��2
b@���+����R��n������w�e;
��Y�z���N��!RE9U�z*)*���o;�{�� ��y�z$��S�%�%~���H~��c�&q��|��S��I�������Or�3 �9�dG)_|O�
G����H,���g����C��
uN��<}r�-�B&�t:EA�vfL�zF��
�>;J�`47��{�+d�����g�L�%I�$�k��I��K]N�x���=F��6�E@$+ ��(����g[���>E@AQ&I������5�u������qmpz��(*f���>�U���y��7�((������iDN��vZ������l3�d���h��
S�G�G��R	���k��,R��S���E�Q����^��L�L/�[��x~��z�[�E�N/a��,���9Ez�v��r��>�n���d,7���uK���c�S1��3F3uZ���T�d4���c��q�\�����L�UH<�s��rM�$�����PP�W�I���j.?�e}K$'��n�O�1�rK�$I���`G�$I��=�"_*�.1����t���S|�'���K��%���@^��3�	m'�A"����I��F��=o��y9��;k�/�g�(�ne���of��&6���?_5�+?3�%>���&9����;��������,\3���?C=��+�$I�$]hN�&I���.�����^[�C�s���OI�y�����X���`%p�1�g �$1���a��\"�	���y3l��	�e�y�E�GA�l�L�:�~JGt��sg�#��	����������%�����3:��Lf�k�Y�%��N4��y����0����w'�"��g�L�TH��8�U0�\zz<�����o]R!�h��Y����z\?���G��~�`�y��$�G���E��$��y1�T�%I�$�3��$I�G�#Mqx����a��/|D�@�}���F6��	:>��_���Y����������{�'HH�4Q��?Y�����\�������q6>u��$����s�h8Y����<�"�SyK>��l?S���xq]�x�x&�:��>���$���6 ��y�VV�^G��g�����yiw>�5���T�pq�Vl��s����F��O����9o�S:g<���}��. �N�So���[i�
�R[6r������7l	�h��)�X������'ox���I�!��z2J����jaH�+$~�����5#`�s�ih	�����l��C��+�T�A�[�$I��N�&I���.�����Y��[��f��G0a�$*��q�NH:(���H��bi��A�15��s��i�r��X�YO�sf��!�b��1�{�?���-f�3��{�V�POGw@|R1�O_�����3��|�{����G�����b��a6K����d�S��*"+w��f'���%#����T�g(Jz�.�>������zyo��f��WY��]�yv
E��V��c����X��#�R��k>s��d�>��������tN�x�h��~:��������zj��H�����+f�WSq:��|<w>���5o���i��3y���������,�k����e�gA���o��$��_�H��zj���)��3�����v(�d�%I�$�k��S�N�����$I�t������c�
���O���k$I�$I�S�I�$I�$I�$e�I�$I�$I���Tl�$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!�u���L��IEND�B`�
time_comsuption_without_indexes.pngimage/png; name=time_comsuption_without_indexes.pngDownload
�PNG


IHDRv�#��sBIT|d�tEXtSoftwaregnome-screenshot��>.iTXtCreation Time���� 05 ������ 2023 21:57:34���� IDATx���{t�U���wM��`��FJ�m�P�T�p�P�6T9Ta�����<���G����98>K�8x�0jU����x�I�\N�pq
r��B�T�R��g�?Z� -�����k�������l�+��



������������H�wY���(�	
vDDDDDDDDDDDD����0�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD����0�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD����0�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD����0�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD����0�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD����0�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD����0�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD����0�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD����0�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD����0�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD����0�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD����0�`GDDDDDDDDDDD$L(���j�0s�*J����[J�=Kxh���9x�O,�4�5���[xj��,���M=y�r��-�������������]�+#o�"|�/A[x��35���'�ZXua�m�.l�5��>`��?5���}���'"""""Ld�9/F�S
Xu���lo���I��s2�����y7�mo�eQ�3���t�J�!���������q]nL����0��B��Xb\g�\�������/p!&R'c����<��&CF�[�J�M��
����Y"""""$;"""rIH�v#��{�s[�~(mUye���/3''��|1
j�QE��u_2{ZB\��`�
��N2'8[�hP������.������i�	5�c�C]f�)tsEDDDDD�D�����\��q&����@	��UJ��_2}Hc8�^������/���������{�
p����L�'����������[��l�x�=�I���,�fi�<W@��?�`Jd�����#���e<�j��L�f��!���^V�S����?�
O��L������q��tf.�"�^v�RH��o�x!���{��;�d�^V�����M�~��O7�w���}5�1(0��,(����q��x�g
g��S��'�]�Z�����j�V6�#@<���%�K�7����)|�
V��C�������
����-�jZ�d�^^���}�+���q�@~}_
�`~�����f��OG5�<>]�C/��y6�[���}���1b��L���{)'o�V03����)�y����/����E����D����x2W����U�,!��Vp��y��>���p��w��5��>,�P]YG����D�����Oo`U���#��{�~0R`�N��~%_�X������G2H���1����o_� �����e��,~�\�i5���}y�oc��:�V����G�w������;���6v|��i#aHn{,�tG�I<�g���}�D�u���u��d�=�q�jv�&���S����^J����T���$���L�p��4�{������q_���4���x/�^��Z+����x�	m�j[��	�{""""""�Cg������/9��)����*�_A�3�DMEn��_�_1^���g��?���V�_K�'�q/\����>;��L���m�x��l
���)��)�hK"�?����3���T���5�����8���u��������_Y1y����EfU)�[kq��b���d��;y��hv<�+v[����3��>�A�s�l�u�6�:�_��E��y�q�������Q�l��d��{�{�K�5��>�����";��� �q,$���.,���>2����������Ds`���!��i��8����kQ!����+�K\]��^�8.�&`�0~�i�?F���pnJd��S�:��s�������O{Y����I���w���k�������g��%vr^n���ig��&l����^:�����m��zb���V���3�������W)%����O���B��Q��l�������?���t����
gPU1yo5�5��'W�f�`TP�D1�od����4�,{x����^r�9jx(x��}I���1�(�����S}����|����rG./�����Z)����1oK|6��'��{�L5��c��X�.m�s�N��K(,?1�N��|E��n�����j���Y|�w:����Ci���N^X�ALa��j��>�����������H�Q�#"""����,c��?��3�]
�����8����Y�|)%��Q���������}��_�9��!�?��z�!wb,��{��lx��_
cD?;6�
����zz�b�v8��j"�d�l1a>�7]S��Hfk�}8�K�i�%!��u#���iPSe�Q�����zG���3q��0�:/�W�%�h����jj�G'jm^�Q�����~�Evr�8	22���q�N6����QL��a!:��-�m��'�i%�����Q�����a��h9hT��6L����$1u�������8l>��r��Y���	`ph������!��t�����^E���?����
��r����`P&�s$�ZO���wk����9=�1D�K�_�f��l��uK}������i~l�o�NJl���*�h��g��Wc�X����-�IO�!����w��KG��=��slEw�Gu%����Z-v==���$6~���Q���Wog�ci8-`�Kd�`;��<T{O���T�;*��I����e��}�	}b^����J�L�D5~9l�����q"L���Oc�D6�z������]5g�;'#�M�i3a���Mcl*,k��-��s��8���������m�&"""���I9����;�3��1��l�O[���Nl	����������;��.N<8�G8Te"!�������2*��Gbt�Y�1H0�<;�x��O���l� >���Z�=Be�����[��Ip��v�1��A�am����c��$��n!Q�����|@��7X�����]d����� &S4	�:v�}�=�V����}���n��?������N�f�����}>���E���M@}�8��j8�}��8m�\}r�����r�����M<�@�m1����n�>\�s�xf
n��M�$n�'�?�Y�C���wp7���"����~9G��n#?o?{�u���z���zO�(�������a���a�����0�?�+���M�q
�F�!��D���PG����W���z^���3�O����3�k���
�9?c���'"""""�~������!6���s��^���7a6j8x���~�o�k������s"�i�&='3���4�k%��#��s��B�������y�3ho%�nJ7�0�����/�:$���1L*�_��=���q8�V�}O"�r+]S�pK�a�������@f�e��jO~*�u`3Q}��j����������&�����i?o�,������=A���m,�]����������xvS�
�Qm[���K3����ZF��2v���U�vc��u���yy���y���f������g�c:�������g��{""""""�C[�����O����9�&���YV
�����6RLT���|�@���GU�c��08x���~�-/a�V�EyA���o��}��Q�������g�'^���r����v'�3��H"{z63Lf�M���y_LtM��w����6�^�H�P����A��������a�9��;^^E��]�c���}����9���O����X���C��"-m�/M>s���3�:��<���ww�� �9�U���dO�o�
�����v_Uo�
/�'�
�C�k�>�a�[pH#��Q<�t<9Qe�Y��~�wz��Lc���UK�#,�a�8�����O���A��� >� �'"""""�~��������O���?��M?��{e5���w���2�\�>^nS�c�����))a�r>�w`K�e���t
�)�����*�p�������E��P���V�9�������U�T�����}����a�������M�dOt��K+����"�8�]�ll�E���e��`ppyk��}S��b\�qj��o�RR�t�<����9���s;�I�MWv<�k��q�����1���+Pw���������W���p�/�h���
��P�X����`����m��n	;�<�}�+*������*c��{��*k�0�7�N��r�������#��#�����f�jV�nC-{���M|�P�}��U����"�9j��ca������"6}ko��85�$���c�R>���qk�8�E'�'��-���?�{����7x|N����w��2�����������w��R2eV�U��"��X�W������OV�p�J:y&�I�}TV���=�g��DDDDDD���b�K���+����'����l���(?���qY��xl �����Ng��/���6��+���p��u�(��u*8p�;�Y����y�`K�'����^��_/{��;�����x���->��Grqu1���<>����C�F.�<z/�n����72����>�+����g��72iH�����w,3��(��5�j!�{7�>w#9��:L��=a8���(��5y�����yo���9�I\�~�'�����"�n'�i�����=,�~5%�VGp�"
������Ho�*/s�@6=Q��K0�l8g2s��������2�Y�|UL������<4)��L��o9O���EN������xN���1�%�ma����6����g3�Z3��}�������8�y@3&���Om!��,R��	�Gf<TK�3�XUn@���4�?�qrK�s��~�L��a�CoP���4:�����3���L+��IT����������o"!�Zros��]�q�2����������l��&�O&�����GQ��V�����:��;�{G��y������������������J�g�����G1��$�{�3�~�O��9j���lfL������4uYM��E���7����s��|ODDDDD��D4444��97�������E���keeG��Q�	fY��������O+vDDDDDDDDDDDD��e�.@DDDDDDDDDDDD��`GDDDDDDDDDDD$L(�	��.�������B]��!>�G���	���Hx��	/��"�EsV��]c���"�K�HDDDDDDDDDDD$L�e�����DDDDDDDDDDDD.��v"""B]�������������E���������������O���0�`GDDDDDDDDDDD$L(�	a�444����.,�����P� """""""""""r�E���K���%<����,�L}<#�.~M�)���'���K/>L�����\�C\�IFy��������u1��`GDDDDDDDDDD�s�7����b��w�{��<0���Nr�W�fk~�6�K����(�	9����A����(+"��j����&���*g��
�����s�@f<����Kxf�����������:b�
g��Dl~k�Y���u�S��4{ }���xaf1e^?>����bb&�����?����xy��Dr��pF�l�j��dIV����8Te����<:�K��"�[qv��l�wR�vr��Q����d�v�
0�pM����j�����E� `��udbc]A����E�����&����1�����oj�4���9��u������0/���{ys��Ua&���?u�;;""""""""""��]�5�&�gC]�����d���-^Oq�0����>v��;��x���3wg�}�HH�Q��:����'�,H����UF&sV�]��S6P����!&0�0W}�.�������]����B�-��t��"
j{3gy:����a���c����Cg���%,2�3���������������d�x�?b��[HZ�E�	��c�|}�}��t�������I��o,b��r�.O��e��e���;`,O������{V���df�@�N��%�����4�Y���^H
�V���'��:��<0�B`�����U�na\2�=���],y��q�NeVr���`�+88����f�K��[�q �d��B]������DDDDDDDDDDN�U�w�������O���������$9C�p���?���������[m_[_{�5FEG�������7������q$��fPSQw��N�kZ��O��>�=M�lV�s�
k*���pM��1v����2�>��8�q��V���@��,UV�?�q*�9�FR/;6�[.��j�up����N���X�#���-�X{���w��AM+��c�H
r��o���]R1�qO9s�t�:�����X-�,u8�e��|�2��H<�;����;����0��������P� """""""""rR}}���*���Jn��#66�UIs�u����^���w��+�
}�+:���:��_�]��/��>DF�S�6p�l��H��S���~�����b>yk5O>YG��tr�E���s����5�q5��j!����m6��A���2�0[����� sc�PUGm]�~�OW�>@����tn6�-�\�6�U�A��T[l�����M��Mv\i���O�o<���f�;�UZ�1.���5���=������������HG��oiW��j���O?���-���Bn�O\�3=��I81��g{���'�8xS.��rb���YK(	�S���51�Ul~��^t�k^g�6N��a����O�������|u�)��a��J�5�����>����-j�8���|>|A.��9�p�w�->��@L�������m���Y(/�`�j��w��)��r���r+6���j����7p����~���;���U�+�����3����}���=~�Tkw�,��"`w��f#���3��z}|VJI%����K��=���?����%���=lX�i������Ul�`����7��4��=�r�C��dz���/�
|Y��N�n=�j�e���lo���D'I��XLgYF"Z�#"""""""""�������8'������P�R���,�g���}8/�xF�������b;�~}{o"/��#��ofRr��]�����	O�u"�Hb������������,��M���������]\���yb8��V��&�g0-�iU����*g��o��n#ib:}������K\:w<]���X�l�	,v2g�"��[�5��B���2f���0���	�.������P�V��z����_("!���#�<'"���Hx��	/��"�EsV����k)�����QWw��u��;~���:������3j���;v��_�O?�;lQ��X���),W��a%"""""""""a.����w��wMu)UE�!�����_�l���l��5}��2�"��2���jk}��l	G�|���g{��.����ul��9G�e���-����8����N��X�DEEa�X�Z;a�d�f���8f�����fL���p��NDDD�K��������9�]%��o�P�[SCCC�11��_����g�7m�_W�����S�������AY����= IDATDiEX;""""""""""�w�����M�=���g�}��v��������w�:��'L����v��5�a����a������d2�q]ge���H��`GDDDDDDDDD�,*����p���������
l��/��2��S�t��w�-a�������v��L�w�������G�\� ��~����/��"ra(�9���k������q�4��kz����� !�+>(`�g�8t��q�s�X��>V ��_���?g��,��l�>��\�������!�%����������%�0���� ��[/H�sBj���}���W�o�W���"<���8}�fp����~�(�:"a.�!S�_�����.CD����#�C]��IsV$�h����Y���9+uu��Z;]���V�x����N���=3��f�|Q��X���b���"J��EF+�Y��{��iz*"""�%������������b�:�f3�soa�/n�_Ff�B����������\�
E����g�����J+��PW""""""""""rae�l`���������l��������g��.`ur��'��"
�z	���c8�������j�x��D]<W�?��-	|�����Q��c�-����S�������$e,��G���P#"""""""""z�a�}�l�|������d����u^V=����l~��������bI�df���K���<�i�����|���<z����yo�F;�+-������v��/�^��N������������H��7n�uo�����c�g�8z�@J�4��A�.Z%��(e��NF<�N���I��R�_���tll~�
�eDY�+<T����6�����"��M)�~_B�v�����,z�������4l����T&�;G[��%S��5��r<^jS2�57��G����_Y��K�^L}r }�a���{�����
`�9&��%���Z�~k�Y���u�S��4�}���:l�S���5qxx�	>>��=�L�N�ti�tY��o?Z9?��"�EsV$�h�����K_}}=K����{�r�]w�ru�p����e�j?��{��_��{���.+h���_ZZJaaa��������i����������6���S��x=���C�X\�2�������C��L$$�({kk�����65��_��ql\�C����p)�/!�����w�G<_�� �f�o��w/$�
��|��k�0k����"j�����k����e,y+��\�b�(6��^rb�����Ox�5�&�����oe����<�h�K���K�1��������H��~���/&ag\>z����gE�#���D����.CD��9+^4gE����Hx	�9�y�z>/�������`pVv�m��E1���G-^O��&Nj�C-�����K(��������+����?x8����S��n�+c�!���c|��7-^��Z?�&���n?G�Pk��B�M������GEG ��{�u�!PZNY�&�jl���F����;�D����1�$����v�C����
�N�L;��}sF���2��u2��9��'2t���7�����s���`��X���5e-�j���J���]A��7�������>���,�my"""""""""��O?���-\~�Gl���cbb[i�;w�kB7�����?�oP__�Q_�e�]v�K�h�������>t�^��a���P��&�^�?�%�����������'$$������uz�����N���� -WB��Q���J��v�hb.oK'��m�^o�M*+X�R1��>�������m�M��������b���Q������a=���|��j�|������&����/������yt/�>�8��Jz;�Gf��!�LDDDDDDDD�c������o8����)���:��Q���{�vu�=v]�q����u]��X���|W����5��P�$QDD�������4']��qW@zS�ph�sZ:q��S��7G�0{��5�����A�k��a�c�jVUe2��>8-�^��g��w���mx��������avX�j�������Y����*6��	y/:�5/��w�v�D�"""""""""?a����D�L�u�B�����W�����t���l����o�]��!�W�#�+��GX�R)}������
�NH:� ��+���0��=��?g����u���8-@U��{�8K�&��
+y�������<���T��f��^�����������������<��r����cnd��S�B{����������HG3>�~?f���/nG��~��[��/���o/7�����J��5#�G{����a#q%]�r�'�N��9T?S��G�'`w�yw��1g
��d�����L���g.�z���{�Y�/K�g'57������\m�[�D�m�Y�S%vb\I���A�[y��X�+��+$����
��}x�����R�A��C������]'��c��;�5:������[�a�91�i��~�NDC�$5�Gk�)n�*���)��	/��"�EsV$�h��MuU���w����6�#G_��I:�+c��#���Ea��h�V�/�Bnr�������|�A���pp�m�3��\�l6����W.������4��/kY��6�P��t�}&'=C\�\a����������H�sM���}�?���L�������|�.��G���#�}wQ��x�������&O>_C��
���]�������0v��N��B]J���N���5����w��l�/�x^o
�~��m_�tU2������'�Q��e2kif���� ,��0<HDDDDDDDD����
���������P�sN�]Itw%]��kk}|^�_o ��8~6p�OD���`GDDDDDDDD�����(x�m���{��
u9!�������[6������ad\���.��"r��`'"""�%���������\�_�d�%�lf��)\���������m�V���w�z�>��?����a�v����tHa�����������l���V~��S'~y�T�&$���v��o%l���Q�����5A��.�g�#�9���V("�1)���>���oXO������&.����U} ���1>(x���{1z�Xl���l�#�'=�z^�
ED:&;"""""""""P��:�cL��v�cbB]N��?`�)=�h�{��jn����C���.MD�C�hhhhumU�p��>�e�H�c;Qq�x��� i����Y���9+^:���1g�������g��P�����7����
uY�����b��,�e����%<����,�L}<#�.~M�)���'���K/>L�����\�C\�IFy��������u1��+v"""B]�����������Su26�����d��|��o���7MuY"��u�T^�����a��w��8S��:��^1��}���,��FZ������������\Z��h~y�Tv��;W%����0������"�Wx����ym2�=��rV�����~0L8Gd��i8M���gfz���]���.�#f�pf�J���������^�9%�I��78��fS�������+ f�X��/��/o��WP�H$��gD��P�fiO����ae�>��CU�������O)�z��gGpM���~'�n'�.��8�|?K�na���	���L���f���Y��
v]G&6�����X����!?`�����L���{O���I�l���]��������7��]`"zH�S��P�#"""""""""F�^����D�=����nn�z7{7�]5�����~��{?n�zTd7��|�HH�Q��:����'�,H����UF&sV�]��S6P����!&0�0W}�.�������]����B�-��t��"
j{3gy:����a���c����Cg���%,2�3���������������d�x�?b��[HZ�E�	��c�|}�}��t�������I��o,b��r�.O��e��e���;`,O������{V���df�@�N��%�����4�Y���^H
�V���'��:��<0�B`�����U�na\2�=���],y��q�NeVr���`�+88����f�K��[�q �d8;""""�&�_�d����N���#�������5�����y2"AUm�+w���uF]���{���I�xr�==�H�o2s
S�jG"�i%u����H'��5�HI�'��R�=@�f�=��&����qM�� k��Y\�q&���I}����H��-X���0�T�s���^vl�Vl]�p��r@���Q����g�kv$1r����"0,	�����bz�� ��4R_(�f�V7{��p���=��=��k�[}�K�����R�s\��g.�1i��S����������GFy�.��vB]�����O���(�����#|��[������y�������I�y�L,k�K��et��g\��G�Z�����g=����9�iq�����oW)�v�������
�#��"���#s��c=���|��j�|������&��������k�j���B�����l,�����e2a�4�/kcA��n�����

~�&��2}�zoD[��l\[������ �v�-6b�P[��Df6�q����>�����W��9��Wi���Ln���s�PX;""""rq����c������"""�>��eH�0����.ODDD$l>\A���8^[��Q9
uD.�ef�V��no����z��r�=�Y~�7<�x���7�2�.'f|������;��:1�Y��[��?!�E'���q�h�d1�&�=>�����������V�"�68�DY��Y:������-j�8D�|�j�����������>1q�'3����94k�fA�������[��G�\��?�����}�Oi�w��,|y>���G�TW�+�7w��������l�\D������)���+�-y������8^[K��7���P�'"�����G,f���.J���FP��y� ����Aj��H�V��C��I�Y)%��/e_��'���rB�����a���.���WQ����w"�o�l�������>��m���ux?k�h�+�e)�8�;�������WR������$�Gb1�eU�h��������qq444��v5C��������F��l����(�~��K���^|��Q[�����;z�c���;v����e\�b[�08t� V���J\���0��kz_�w "a������`�2�Yl���c�M��?D~��LJn��kt:1s?���N�IL��T�c6�>�����I>@\����Y��k;9O�z�j�``�D���e6��q���Y�,z�
6�m$ML����q�s�K����X����7��N��Q��s�����O����X��Z�0}B0������xk����.CD����#�C]��IsV�t�x-�:��q������n��1��8��L@sV$�h������k����'�w���vf�w��J�?Z����F��S���9g7nXG��
-���q7�xS����$]c���H�t(Z�#""""-
6�HN����v��;"""��|�c|�.�����
�>��m����n�[l���]�����w�uZ�s�+�����5�:_������/'::�N���u�����ED��P�#"""��w�n�=����o��RRzp`�^�j�>EDDDNX��2*��|���Db�����<�����������6������V�_�3��{���b�#,��0�=NDDD����o��s��A"�f���G�9���[�qN��>@���l��C�"""r!�}�jk}�l�qv����z���o��=���
W�UmnE\W��]��DDD.��v"""B]����H�)������`���J���a#�%�9!9��Uz(+;@�������������F��
�TW�|n��,���E�mjk}��cb������M[�}�7����lz�����_���vWDD$��e�#""""������e���7I�)��t�o��Rz��x�&���`GDD�����g��/���s��z�� �)�In�V�%�w����|@��	�:b���$66���X��&��>����7�g���e>t��������DDD~R�����\�����o�q�%�+��U��l���Ja�M���h��!��|�������4�0(����\��"""����zk8|����k��c�MZl�����EO>��5�+������=I�����I������%.%5�a#~A��.�]��������!"""m����LwW����3��$��L���������oM5UUU$]��j���4�z\II����j��c�����O���K��be���P�!""����z|�����-���W�K?11G��t���[wW��/""�S��NCCC�K�v�c����~
�c�p�^AJj)��tw]EddX�l2^o
���kBb�K�(,�)"""�%��������y�8t��>|��*=@�j��C)������fn;����
q������l���+!��8��gV�K���O�3En��;�{�p�O����.j�x��D]<����<��-	|�����Q��c�-����S����vDDDDDDD$�u��w�������F`�G��v�*%���!������PT��J� >!����DD�e^V=����l~��������bI�df���K���<�i�����|���<z����yo�F;�+-S�#""""""r�8z�����C]FPb������)����bK;g�]��[��a�~�S���}���_���t�~��UW����;�������^A���{jX�Z��d��<��#v��N��9�m�Io��$��=������i�4��m�C���e����� A�y��$[�x��9G�"��y�/)?���8��R��U��Y!�4�`���jO�k�����O8���i;�{0l�`����|����S��{R9���U7>�p���^x4J�m����J(�4��M������<���`?���^+Y�x��H���};������<���(���������<�� �aS^�n:bn~M~����q��H�r��G���X�!""""""�%v��&����`�"��A*�	��/u���t��]���S�_P���"hbb�/��0,�a�a�Y!�!��!������h�64���Bc}�s��l�*$$&m,"�����W�\��zbb"�.]:�u���c��Mx].�c��M^�4���C�"u�)3z|@�H��L%��8���V���'#F���*��+�S��������j���CX����V�����V����V\������b��;���O����M"xN�����x���P����_����H��kf��	���~��k����1�	|�����}�|�(�?~P�����I��`E�����v����f)���b:;5����q��9<��P*U�� "�+�N�Rz�;q��~>����(+����@��?�L3-�L�b�J�������]�8v���������b��tA.]8���Nx=��m{l���&�9�L�\�B�Dz�0$�F�ArJ���W�^���o�����h��[�����[�q8~�k4��8|�L�/n�&�����+b�� ������$<5]h3fa{�x��Gs����S�"n��9���>4��4�,_���6 Q�4��l��d#|EW�7�����$c�%~u�����`���R4���V.M@�����{�A"��366&t"""����P���k�m��EK��r�`6���	�%e�d "�K�r�y������������Pu���,\����$K__/�~zn��|����/�+�|�j,_�C�����BC]-z��������:|��o��c�l����j��<��a�%e�X�r��m�	�((*�V��H��W��	�O.�Z����8��8�/���^f���h6+..Fj���s���JW����y��� IDAT_~y��w{L����"x�.@���o��z�M�����[��1��������Kx�7?0�����p�����X�r������Hm���R�d�\w��[E����
��}�%x�0~���
��o*� ������,�DEE	����(������F(YY98��1475��CDBC<�o���k7���
W/_BOw'Z���^��������~��W���-�tqq�X��V�2<���j(U�W��>y�O~v�k*����0�������g�������p��p�\p9�p��p9]p���H�~�6M�B��B1����		3�~L�k@����@���CO���B����#��������6�}n��0��G(�A
���]�S�=w�*�����sq.Hbe��_i�����V��G+��~}�����_���oY�!""""���Vk-�$$&A�P��y�w$Q���b������&�FGG�6�����gq��Ix=�f��{*~�D�V�EK*&�/1)�������Z�V���X���B�r�D*�D*�f�@DD���bi�%}��?*���>��C�O���!)H@bw.�,DZ��A��@ Na�[]Pf`�0���q+�����"�i��INGY�%��5��2@bn��#v|'}J[�����(W�����hb������=n!X�!"""�e���v�PR:O�(���AM�
twu
Zd""�m<n��Vu���I��A�RO;Kkk3��
���Z��7���|���RVv.��s��ADDs���??��p�^����O�1�7����G��������J@�����-9%������W��9����Pj��L�6���",x�'�� ~zYmZ:x�5?��_�^�����+���?����#�8����'�R.���8����!q������=�I�P�/��o��$��x�G�s��5��X^X��c�$���r
����svv���cT���'�~6����������G�X���Y43��D�%Ps�����l��'��\>��d���?�^������2�|J�z����[��%X�t9����r
�|�%
�x�q��1�_~�����e
�������h�il��J���Y99���&���W�\��K����������<n7D"M8z� ^�?�{v����I�&&%��^�K,_��E"""�Xq�o���}�
��mA����d�cQPD�Vl������($Z��r:Q�p��Qr��I)2����?"�{����O��T&��O<3�m�&"�J��7_��4�+�.���jn�����p����p���\9DDDD3����
Q���������X�����J$";DDDDtw>�zC<r�
��r���<�&F�DD�d���x��'��e����7c���������/���M��~;DDD$<e�����cP��CDDD4����#'7_�w`Q����8v|���].ly���m�Y\R���2
��q�dL""""�;DDDDDDDa�������2l����PXT������IDDDDca�������(LEGG###		�X�t��q����(��CDDDDDDt���
*�Z��EEEa��k��ADDDDa$Z�DDDDDDD�������W��9��)t""""����"""""""����j\<7�_�����������3���!"""��iokEoO��1���*5-��_���A*���c����x��]:�m,�E���n=|&���Q�����{o����	������R|�/��U��������O��?�V�XDDDDD�x+6O{v��<�]��#U"gk��n"������q��y���A�7gBI�)��dhj�:
��,^�e������A����v����b��� N��XDDDD��t��|�����G^����1�����n������*H�Rdf�eRY��p�\���:
����
���	��Y�qv}��m�x�lP�!"""��������+1"@�����>���B'#"""
+�m���� ;;7"���/>575���(|���m�-HHJ��
���CDDDDa.<;�X,x�iJ�a��%�����c�NFDDDV�j���E'���;M'!�����W._h��
u3jw��yT^�
�&�<�u�D���������u�\���<�v���[��?�QH���wt"'��B�N.t"�"�����V�F���J#b�tr�f�����(�J���"�,��Y�V��>l6�+/��p�g�]�|���B]z:6m���������9[__�s�#6F�_|		�{N�\��Y��:�����g.�?�-�����}�W<��~2V�6�W�tD4	:9z��B� �)���,����7Y��_�� 2����������QX\"t���9K4=>�o�����x��m����C��������������2��fT*��}q��Lx�Oo������OR-�3Q���,Q��keBG ��s+6s/N���n����G�i�x�������V@~a��I�'/�-��h:
�1���F_o.Z����������C��S�x��$TW^����U�>y^���m��Z��x�z�ddd,�~��bG�B��'pN��=i����G����A�!t>"""�0�b����#99U�(�bLH�1!Q�D4��;s
5U7����5�6e���T|��QUy�;��'?������K������/�qqz�gd%�^�Y�Q���Z��~���U<"W-�K/'Cv����n���:Q�kmi���G����G�}���2������0��_)�����Dxv(��������ADDDDDD���!�H���� ��fo�D�e+��XDDDD4��ma�������(�y�����������E�������(��R��S��ADDDD,�Ev������������";DDDDdhp�M
B��
��M��i�;z�~���!����Q�v�>���k��r��n�'>�{n�kZ�FlV
�����dD4�8��#;DDDD���b��Y9BG�C�6�d��j��������1���hn�z<x��7������BDDDDT,�E���nX-�����X,:��uE�:S���ef����o{�`hmm��b:���g�G������ t""""��
�W����hBu��E����2tZ�q��$��m�8�����1�PJThn�w�{�5T*5��	�������L&V��pp�X��HNIEI�<��������
��mll��<}�34��"+'�V���DDDDDB`a����(B��TC,#;'O�������}.tX[���s;���\�=�&s=�����oVv��z���������De������:;������>AvnJ��!7O���������u5���(�J���#)9E%�P��A����OG����~4(c�v����"@__/,�f�	�
��e���7����.s�W�:P�/���s���Va'3+���BKs��/�,�X��+������J�T�@SC=���T���w tD�9tp/Z����2&$B*�b`��v�'#+;(����>��ddr9}�IH����ADDDDnX�!"""����a+}���s����a��`QR����}��T(%*4��7��(Z4��S��!��00�����Z-���X��kHNI�����$$$&a��
hinDU�
DG��K�\��/DJj��J����������v����6���u��a��;�����#�=�����������QHK���bANNnH���<x����P�/��i���_��n��c>�0��<��w�x18y�n����0
�chh�oa��2�r����P���za6!6V'�j0�##6�+nrr�������������'���?�'D"��2���������m�"1��3�������I� """"�-��QH����c������DzL&6e?4i��	�f4V�u`�G;a��}�����<��_�t
��(,.E~A!�R�������4���
���-����t8�x�E$$&M���rB&����@�e`����QUy�x#���A���###mm-��n�J����"O��_i'�J�y��A�DDDDD�X�!"""���"��D<�����U�D����M�������2F{[+�Z[����{w#'/+�,�R�����I��:v���z��\�.��D��h!�L|6I��k8|h?��(��C�j�B�f������n`������	�AS�Pb���}�=��������
����lo�ka�����h��:�tY��^�c�$���r
����s����sB&�J���;s
'�A���g�}a�+i����u�������2�B�����_��+���&l[[S���Q�h���j�Vk�<nkKv}���W�F������Px�z��`��hok����������
�R�\=�]��G���'�����Y���9Kx�Z$b�a��^q�������j�q���
<���A-�@bR2��q������DW#[���H��L������������>��N}v�=����6H�����"��t:�������%�~�����,t""""���;DT|�Qd��%����f|��N<��HMK�������|�]������OB��i��nFl#�add�2�r�������f��J.�>>�E�Y������`a����O��"�,����������Psv�'�P]yR��m
�)�!�@_u��~456�>b�������<�
�KHF��q�(�p�;D��������(���.�X2]��3�xp+�z._:�wMOwW�����jAgG;�VlV+�V�x�Y��'l�p8��y�7@�RA�RC�VC�TA�R#9%%T_
;DDDDa���Shj���M[`0�m�a���v�����������O�0X������TW���O>��M[P>oA��P�-�X��������|v�0\.\N'�.'\N\.'\.'�##������D��|��A�������?��#3�NDDDDD���"""�0U[S���^�T�+�|������71�B���K\���>7��A�Z���5�6��j���v"�:w:����^�L\�Y�t|>�r
d2$)�2)dR����,�����A���"=#
�2(cxG=�Q=^�)2���y�\������)v���P�5hkm	h��p�]hnjBKs#:;���w��>{��� �!�!�!� ����eJ��*:�b,�����*@^AQP���u�������l�~8�c�k� ���n�2�r�����v�m�HK�x�������2���B��P�
�����M
�ho��y�X�iz�a��)�i��HDDDDDs;DDDDa�����_���4|�6KU)���Q�
�Q�B����W�niEZ���4�Y��q�
�����c�Z���������o�tqqBG�{?��!��.:��������q��m,rr�������l�}��"""�030��A�R���T�|����Q7T
�\����8:xO	��
Q��C��*�@Ks�_�>h����������a�c���,�L���
�m������l��0�����#!1b���������7��h����j��a��6lJ�
i�^�
�D���qK�6R����Sn#��������>�l� ����]���u���5�6�%��Tj<��o#%5
�5Ux��?�j�����	&���{�����O<������CDD�G������AD4g������������
�6l�+� aQ��:����Qo���c:��^,�������jM�����G��P�8�[y\��L&���g�����Qy�*������G�#=#3d�_����z��4���`�}K�v����ODD4[��<���tY;�1k��q��������1�CL������:MA�N��!��1�h�8g���a�B�:F@�xlPI�B�����J���!dr9�}����j��tW�2g��9����_���Te����� ��;W)U*df����YA�h*"e��8������Q�F�6�����1��|�D�%^+�D�M���W����R�qE������l}d{�u"����0��c�����6��N_o�T*����D�Z-P(�HLJFJJ2��aLH��������H/7����������������=�Lm��������!���;��"�,����>������L�(~E�����Ell,�R�]�[������� ���048�e�����"<���	�w�]p���m�G4�H��Ds������p��8�t�,N^��ik�(��Q�������""""�/��7">�(t�Y�hL�{���
��{�c�B���T��
���������T*��hDDDD���)���N���p��4������:��������4l�� ����7Y�!""����L$����l<_�g�����Qp��,������E��R�(DS���EY�|�����CDD$ �koV��Z�N~�Mj�K��1����,u�����r���V�FFl4����)t"""���g��U��!�	2�hAD��Q��_USX\��<>7.v��$Z���K�g �<V�7��P>�6�.���aG���p:�p:p8�p8��()��/������
��	��	����{~��~4������h�i������bm��� a���H@6��>xG����0
��^�F���z#�EA\���&�m���	��n�?^��!�`Ht�X�!"""
�O}��A��S������.��������US�=��G�P-��	0*��������p����\3��v�������J�\�V�\�L�\���T����8�v�%����[jM�hn��� ��K������M�'�����[���ya��A*�A-�F�ETTT0��9S�)���-�Dz�C;�����*CzE:����$"""��N�<��Ar��R���ZG-	��:��+B�P-�LUS.���_���N�Eb��b��bH$�D"h41~��dr��!"""�����p��"��bl��:2���\�I��{�o�����#F�
����5�.k�l���w"]��Ui�&���L���5G�!�C-��w��b������	��Ew��X�#
��gRW^�����8��9
+���N�u�=~]c��W�aK1�;DDDD�e2
�����H�X�qs@���:�������2m���,[�*�������<��r��<�URP�x��9l���
���������e�`s�����`�cC������v�W����0 N���0@'�zN�����Jt�t����g���:���i��'��������9�s�<<]1�M���y|r!��
�8���x���X��B(C����h6���#���b���P�5��_���s�T$C�.MC������L:���p��px�S��6�D$���m��������U���*p�����0��=��A��}�X=��O�v�.d"9�m���u~��^����,h����0@&�#S��$M
���HR%C*���D��a����k����cE>�P{��U+�m�(���\�A�|�(��"""�)�x�,�z{���������=�F�6q
}����%OW���z���X�!"""

�
qh��]�/C�*�����3��v������B2�t8�������9�X�4M��D�O��E#��K�^���0�4a�i��c�����.���^a�N��c��n['F<6�������Z�CHR�@�0L:E�IV��`w+�n���j.���b
$�n�UB�����DDDD��ex'?;
�T��n
X�*��>���!W���������DDDD4;��u�f�K8�zU�kp{�q�p� IDAT!-�x|n��{1�D�a�����
��!F��Q��*�I���H���x�q��`�c����_�'C�c^�$j���H�����>"�\�vd�j�h��7�X�H��-]VX2(������h�Q((*)C|�1 [�E�H�m6Z���c�B�:Y�HDDDD$���,e%��������D�Q��mpxG0:6�k���C-��`S�CA�6�h)���k��A��C09�#�E�&I������vD	([��o~��M�>R��EXz���1ua�����`%��
��I�Rl��E���g\�}1�:DDDD!�e��Q�q�$�����:N�v�#F<#�{lpx�����9�~G�q������"R5����F�<FU�TvC�D$�{��]��$��/�a�/���@n!����/8����vcOW:��I.B�'���� """���1UaO���������3e��p�7^G���ok������f��Q8��D�I��_>����T��?|I�H�[�����{a���y
��=gq��db9�KZ*t�iQ������J��J��J��R��Z��R��J2��<	��$%"
�{Z{���������h�9�yzE<�����BD�v7����f�|NHDRd�� 7�9������w@q��.���Z���E�@/7iZ��2<����1����������p�]��"K�K�6b��!"""
)���k�bs��B4g:L8��������V�DDD����	i��J#^���Q7T
���`k���;�e����C��*�0������,2�;�h��4�OC��n�)������N�r������8�q�26a~����OD_u�y7�"y%�:D4gtZ��m�D���#�x��� M�������($�xlhnD�PF<6u���������J�cOB.��P""��GQQ:����=^�{j�����.���-�X���s����&UW[�������AfVN�������s�h)�����&v��
�lHV�by�j��P��
V#^��<N�(D!S?T���6t�;�k����L,��5�r�b��W��$j����0oJ���V��<�����9�g?�&:M��m����O�F,�� ���X,M^�"�,4�Ov�ik����r<m��7������*��?���`%�j�[�8�s���(5�yt1^z9��$"""�(N�������R�h��{/��u`Y�*�D���jV����P�sx�8��)`S����@r�����z���}@�<�19���EFLv(#����3��F$�Sn��+�{NK�����\�����d"]��w��l��:�f�`v���N�����X$���s	V<""
S+��pyO-N����1���c����W��v�9����N������������o�{DDD9:�����V�hLX�_\��0qI��������{���y��Ks����py�X���+7f����q��3<Q�,���\���uhnD��W����w�(1������p+L�8�Q��[X��
�!I��(���he:��������w	��./0��d"?�)����p�\�{G���;��w����h�]^����q��,��>�����z���w�D���}��r�N�I��z��q�W+�C��ng$�\�������G��P��c���a��t$�`%l��������:�,,,;���,��>E����T�@�.�W����Z'Q�`|��e���>J��5���tX�r��q(@N����SPI��F�]����X�������s������F4���ln��c���)rx���-v�aq
c�5����y��M��0T�ZSj��@�6�[�fj�}�t��N�����kM�z4��am�@od"���N��	m�-wVnU��^���<~���k*���C�b�8�_���������������S^��d^����?��""��&Y�cF�q3�b)�m�8��N�|�.�I������ `��iP�L��Z;q��i�u�����(��n������(lyhD���';�V�@N\���jX���'�#+6�+&�������g_��C-{q��tr=�>3�� %")ru����vxG��������
����	��9�w�.�Fu"*�WN������P�UPK�P�UPITPI�PI���b���������c�e�w�s�{�m�G��������1U��ud"9<cw��712-�',�]@m67 V��d�p�w����^>�jPI�H���^���}�h1�����A�g�hd1x��y��D�m��E� ���P��""���aG���e3V�&�E�Dz���������i~�n�� �*9~#���($��KQ���
�]��#j��
�Va^q`�a��]
���u��n�r�!���"��C"�#N1{��r�\8�z+�VB%Q����I�9	�O��w�>��eF\��	S;$�Bkg�4Z+���o�}J��6O�eLzO�P6@�>^q>#,n,N,�a�)���N�O_o�0�u�b�����=��	�keZ�������]��4P�0;�0;���`v���8����Yr��m�����V V��Y,��X$��'<���u�P�A���!#v��7}������va�9K�y��Pf,G�>_�t3����h�A������	����2
 ���otlF9S��3jG4���pN�������w6����o�Fr���\n�,vlwY
KD�'A'G��S�D4E����r9��
�/~�/�2F�p�����7���@�n�L]�%����^�������NHE2�J[�y���s6<��{�^��py����0J�BG
9���8�9��z�a�{h�4#-&��=�w�_�=�#����:-HX��'l?�0��\�X�H�H�X�H�X�x�������gv�F<6�xlpx�������X���	��|N�z�����K~��z����j����j��~@#���P�bC9����!� ~��!M��"C
���Rd��8Kx�Z$��oJDS��s�z�8�V������/>�ca�(r��0Qd��
������x��Q"�����]���$|��E�����c8�yqr��du*6f?�<0�Fr����\���z��k�A�:k26B%Q��VK3v���\]AH�uq���jn���
]f34����%$����.4�����'`����:��� V��V����f&����,�4]C�������FU��JP_
�8�+"g��-��`���,Q���CaZ��������b����>_~���Q��a���9KB�Q�&�,�����!F�:N@�����Wa�1�O[����X�����S�9��jq��������3�	I�+S�`A�b�c��amC�&]��9g�]�H7�*Q3xv�*�Wby�j�c�\��5�J���,t�Y�s�(�X�!
��,��]�?=|M2)�_8�G�v5�����`a�(b��0Qd��%!]������X��5$����5�*k;�	����l������w'����s��0�kY"Q=;��Tq�V�p#J#���QB������:��_��k���G��@vl���f/�Y��ca�(0���3	��!�|"LY8g�����@,��/���	�1��;k�7���0�
�������K�+S�������s6����HP%	�Y��.����e����Z��m�D����M�?���b}ruG���>�9Kx,�FD>�GEE	�����hFU������:����G�e�Q��o����,f�$j<��(�-q�y��^��b�s�{A���`w����z���M��EQ�IWO�_�6�^;|�^xG�����w���_A�\7a�cm�ni����9��@_4��6K.t��)(���$�|��R"""������l��@���Pln+���F������V����8�s�S�v�IZL^��hnA�B�t����u�s�>���+P;X�6K��s�n����vzF���B-�8J��(�"��b��DE���7*!��V-�'ZQ��h�J������C�62�Fe���n"""��X�!"""�Gu���/������B�����:cC@_h��8�qK��l%���3�����Y����>i�>m������A+�:NXrz�Y�6zm]P��X��x�m����vS��
[>�c�O}e��-2��SWcy�j�����:����wye��)���
��^+��V��EDDDt'v�����AMU%���-��u�����xG�8�s�D��7�����:�}�����P#��A��y��I� ��sM���Cu�W&`q�2���%���5ob�iB�q���:�p��"���T$Ct�����+�BG """
>�%"""�!�������T&C��A�J�8<v���rQ`r���U��CuHR�`E�������)�a��j��*�_W���^X�tw.����6e=��#��������!�	)+�1sK�����0F<��=�����J��S��#I��tDDDDD���"""�:�o�������]n�����X�T��i�>���s-��)�^�$"i@�/1����W�$i9<�nn��?��-zF�:}�h�!8<v,J��Q��q����Wq��b������n�]�GX��M�������S%�w��Q1�p�~��8�i,�.zE|���v����f����u5HMKGIiyP���Zga��9wx���Z�������q�N����s�8Z��ik��y�Cnl�����	�Xs���@�P�2���`1���(n���=�C>�T��t���?��u`K�#X����
�%X������u?^��zG�'m��i��^@�2�����6(���������!"""�&���C�B$a���A�;�����GKp_���������w	E<�',:�m��IQ��bdZl���vK+�T�Ao.���V�����G��W$�"O=�w�_�������n��^�TM:�KZ������5��yq8��)�������<�}X��R��+���{Q=p��T<Z���+����;DDDD�t��8T�X�mp�~��<���:r��;['?�P;X%p�;E!
���u�(-&b�$�c�%
�Fe� c�x��Y��ro���N	�c"�h1+x*�E�[�b�������V����������YDFe�*z�����\�CDDD4M>�zC<�V���zE|��s?TbdZUI������B-�	�`��p�\!/����4�����N�k8�q�EE�J�c	*=&/�{g�N���LX�I���8��X�!"""���y�=�c��Q�/��._W���n��`ABp�����mzl]HTs��HfP������n��p��"%,�*-`���������[���B�:��w{;6Sxm����!�W�����>��q��:s��0�E"""""�+v����(,��u0(���u���'�ID�z��t����A�I�Ht�x,O]�������ZxG=����d����EDDDDD�������M.O_����t\��+���+�D����C�.�oV�m�-B�
[��f�#����j����__�g��}�z�a�98���^��yg�N�B��'%""""�@���?���!�����3*t"��B��W�D4E�������+��g�G���A~a�����X���2d�f�l����\�)��!��#)�8g���Q�/�g��vK+�L���iaT&
�2��[Z���
����+:��E!
�h�;��=hn����6U��4C-�@%QM���m����c���r�B�L[��sg�"�,Q���b�����A���7�	���	����f�������������V+p*�Hc���Lx�;���5�8�> �l���W`P#�9��i����q��h���
K�V+,xG����P�/8��IR� I��������4��am�e�9$���4��c�����ob�m�����H^��DDDDDt/"��CDDD(�m��t���166�H���yX��z�!d9�j��N�r
����
8��f��:�q
=��z�)����W ��M��C-{q��2��D|�������Te�����bW�$����6Nu��mFi�|�k3��0E<�x,NZ����&d�d�m�e���������)�a��C�������;DDD4����1��a(U*�[p�/�
�2�Z-��U�R����oB:v�GKP�/�������p��J�7K^�����{p�vunI����-���[�]�H7.t��J�����B�	i�q���t���A�;���O##&t[��ca�������V��MR\"���>��	���� "�A�-9�nlu[��<�PK�~�[\����:m����s�:����������x&��� ����qU<������(���CDDDsZq�p�l�|N|P��>V��C�^���lr�L����)��g�/�(g_Q�>w��}��+B��@�8��������
������f��""����{|�����7�S�<�L�$���9U,��Ut�V�����n�v�uo����{h�X��]�a=��n���mk]��V�B���@�c�&�$��dN��G0�0N�d�����������~������c��}�+�V����]�y���YuF:4�`��,���K����o��e3�u��D_\c��M�)���e#���~�����,f���L&�\.�

��]��F#���N���[
�d�X4��Z�����W�WS�qM�N��|��V^kN�KH���{t��q\\p����W�����0�>�i��Oo��?lT�'~����I����t\0��
��"�%[����Z�2���dg�l��n���lR�s;vD�x\�x\�xB�D|�q<��ye4���������
�B��g����9L��T��y�.�9���}m{T�,�m�?��r0Nmn|]�XH���VV�!���������bt}�q�&L���3���~���������U;���Zo�/���pXG�'m��l��WJ��z�)�g���2���k�Z��$I&�Ys�-T��yr{<)�7]
��{���g�Ow)����y�p�Y���3�?��'�%�����C�������".V�'�`8��2\�o�Z:z�]�!���y���u����;j����hT��^E"E#E"���F�X�sj�N9~��T__����/��lI���rR�HD�TT\2�v���r�g�}������d3�u���T`��K/�b���t�+���H@]�N�����K�!s��1�YX�������d�Jw@�#�0��E��hDf��5d�+�fw�e�9�S�	F�R�J�sj�@uW^��C/xV�h��}�s���zp���Ppax�2k��v�+��
R��0��Tq�<��<�I^�`'�������t*���`�ue7&�o1Z�u+��/��!��#��-��-�e�{�vhA�5����nr\��h"�P4$I�Zs��k�:����,i���N�X�6}���u���XB��8�����S���.e�i�>�"GI��.H�wj���P����S(��p,��h���n�����WN^�t|��*��&��+��-O�W�K�l��&�<f���E;�q'�7���W��,}�����k#����|j��*wW����"�������Lr����0�R�������
g�0��0F�����[���mP�j�^ ������N�6�9�S�����]pELr���g|AC�,F��F[�K�q�Ow��:;���_��d��6�V��J��+�]��Q8�-
�#���O��9~c��6X�m����vc��{_�{�%��Q��M��+o��fOwY���p�^:���YF�1�9��4�� �`������$-Yz��-X�����P�[�xF���>9�N���]cvC�n��6�*?� ���;�>��B�n-
�h IDAT��U��t�� ������Jw	��M���!pD�����0F�\!y�|�Y��]���].;v��hTmm~�b1�>(�������,���v����]��3��?����6ut��'>������C�����.�����)����Sj��M$����$��t��l�<�y<^���jRy�H�����Ed����0�0������������@@�������R;9����%�/o�K�E
��������������t����A4��];%I�V����v���z�t��{�
���������T0�����t��!�R��bjooS{[����j�����.�7G��;�������_�+y<^���v{��^�,�J���.%�~{x�N�[T���'*oKw9`��O�&�M'����v����r�o4�2f�MO<,�������7�5tr0�)uNR��\����2=z=���SS�	����5�,�%G+���z��`0*5�8���
2�2��2
2r�����M:>�UkKK�v���2x����'��XZ&oN�rrr��������e�m�F��?
�*������R�~��u����w���z����K&�Y��I���f9-���L�E���k�����ZY�Zf�%�U���`0*5�8�7�lJ�>m�,�r�����--z��?K��_X����I�������.����i��C�T���P�[v���}g�fk�o�$���]��c_]GU�qP�V~r����N������i��I���=�~��*�*�V c�:����O'&L������d�>���I��
S�w��Z���bq%q��q%�q�q�b19�+]rFh�>�
G^Q[�)�
]Wv�f�����^k�������$uF2�)���w��Q��l�e�~9��A5uWs�	5��9tb�mrNM��fN��#Q"���`��B�n��lVe���}�K&��d�%������%�.y�X�����o��������Z:�Fe����nK���u��z��7�$�![��I��������W�(�s�6��e�!�(��YO?T�$I?��}�g�+)'��BG��%C�Mv#"����}z�n��)++K_���d6s���������f�jy�
Mt���y�YF]Wv��t"��C��:�?��4��v�}m��/��m���I�������b{��%*vN���}q%v����O���ko�>�_�x\&�Y�g����3e2
��W����O���J]�F�����.\��J��=��v*��7�+�������'���+�����x_l���|f����LF�Q�$���_�_���o��V��2?�R�|���S�-����jM�>K����h�o?c�H�:�����g���1wO��0U�yF�'k�6�v�r���*V��j�����J$�Z3M���w/RV�8��:���m�T��KdJw=�K2s�U�j�\B�I��'6�����c'�X7C�{�)��$���M�@��Dz���)�%[�nX�����}m{���k����k����i�.	�dt;Cpde��]�`���ov���%:|��^z�7���<o����y}��;���xQ�*�$-(�J����\�k��2k�,�Y ��f�+���?�%cBF;��q��t��x������2 )��������:���T^^���[�tL �P �+ON���<^����=y�^Y�6^�4�}j�67��h"�\k�n�t�&��K����&�Y ��f����2k�����t��	�.��������:�����������2=���k���B�nE�E�"*�������u��}�
]Wz��.Z8BU �v`tt�ds�B�n�B�
���B
��5c�l}��������R"WQq�\.�\n��.��^�N�rs}#8���+���D��m)�=��?��U$��p,tN�����fW���H���f���d3�/�nd������������DT�H�_��������hR�����������*'77i�����?�����F�Iv�CfK�-�U�STU=�����z�am;�U�X�B�n�b!�b��&"�$�![_���N��H��?��iw�b�(��-�1[�E&�)��ON�SV����	�ct;�j=�Zu�����#����V�����������T����$��%�� ����+*�d��d��e�;d����zG��q��7�`�K�H�$i�of���������:f�2�g��������|_�}���%��Fg�c���������:���S^~���T^Y�r|aQ�
�R�oe<���������P�?�x\���L�r��_b���M�}E������s.���xS;6�]K���8���,��+67 ����=j:q\�S��I�UTV���O��|��(/�@F#��M&�R��,�M��}v���
G^N�^���ON�3i{B	6H�\f�&:��0��2�������#jn��!���O`���jk�������@G�$����v�UQ���������:z��iS[����6�����ia�b-��4�X���2W��YF'e�2��e�a�Q�,��l)���xu�U_��2�%���&#�����t�`����m���b��Y�-��*((�//?M�e�?��mMo�s����k�r�y)�OrUh�����o�2� ced��#����M�mmr�\*�X�����-�����I*((T^~�

��t�F����;Tgo@���:{;�
��S����I���J5=:[9�������:�F�`Ltt���z������M�~�������3g�v��L���i#Q���'b�����+��P�?�D��cw�'�=n���Tw�=E�
���n2�R;�\�����"���cZc�1m����c���������)''WE�%#ZO�/���7�7���D����9�����{d�J���W���H i��I7)?�}f~s�W:��/i���n��������{�i���R�g�<V�\�<�\f�o�aD� �tuv������6������H�f�I����\7�r�rrr����b���z=
EC
�B
E��u�7��`4��	Y�����c�Y&�����'�>b��'�����=���o6Zd1f�b�V�1[�,��1���|{�PH��.\����`x���i��w������6������&OI��=�=����&"��#�M�*++K����}[C'���5I�������$-+�I^k�����9)���-�+��%m*��D�m�D�m}^�G� m"�^E�Q9���}zz���o�$���/�7G9�����)����;��]����b��eq'}�c]G�������*��:S�s�>=�/������L�����d��4������h�'�;��k��'�BG�e���v�x,�S�Z���R��/��U�S�
�B�1�*}����G�+*��/��<����XW�����9�������]��E��)���'�������{��m�������7x�lc�|���s�����;/�'W��a�{�.�����:ID��)�����c���u�^5�n����J����f�Ef�e���P����I�,�l��=�����6ZU�,KYO�g����+8C9;c�����O'���Q�)��U����`JwY�����I� ��-��-����Zb��z{{�t%�����TaQ�r}>y�^�	���Y]6Lu)���o�����
v>j�o�*=����e��?a�>�����7nTW$ I:��O;�iE��������F�S=�����V��D���*r���{��]:������)���7�3�q�1�%G�l�\f�/Ny��K��Tk�I�;�WGO����I��N��������u����g3��g??���jSaW����1;�0;e5�d3��0;S�a79�f@:�d���v����::!I�S0O+�������j��4W8r��������b�1}j��I�#������}����<^���b�DMrWj��b�k����yL��cj�::�8k>��������f���)�R ��`4�@�]��vI���S��@���$"�m��B���p<��h�r�sd��0X:����N�==�����(���,�Av�]F�Q��c�$����������_����C��� ��`V�U��~M��������=psy���"GI��~'��:8��]�j
�<n7���Q����}M�zZu��Q'CMj�>����j�>����a
v�5����{���v��2W�&�&�m��3���S��;��d�O��)_�H�\��99�'b��v(��{�����jm|��C/���q�1K��w��5�^�8K��UTU+?�@�Y�����8�\f���\�����c\;,�`�_����
�����������;K��s����7�����������"G���U�pW]�e�������K�Z�I��)x\f�%����v�{ZU�(��0�3PGo�&:�T���RW�&:�����m��ny#i���st����h0����N67���~9�8	�'Ro�W��^��&�,��av�g����}�xoN����{��\y;�RBi ��%����-���-*vL�������.sV�`#��
Vy�s�k���]�rw�����s8����
O���u����o�$YM6�������<��9SU���t����t���e����W^^�6�_^�����E)�{<9����'m�;��}�F�L0��b�B]���{��.cD��{�Hh�L}��v��������*=�5��cg]�k$��{���N'��uS�
��=��:����t��I������j�W�HKJo������������(uT(�f���7�e�@�Y ��f����2k������Y�.�x����"����?:l����z�B�J�dUz&�;��S;���{�T��zX�����������?7���7K���v|x	��H�Z��
�v��^�"{�K����tp��:x`���Z�p8�W��p�
vF�x_L�N����� I*vLTO�g�w�8�N}����X��u�������T(R8R(��P�[�XH��n�b������j�%�
��?!�5W6�]V�M6�]�l��%*�������F#���KF�IN�S�KN�SK���������������&:�_��S��}�xaQ��L������(���Nm=������f������9�F���)������s�f�����x_�K��5��K��R���Qg����A�K�?�BK�����=�s��QI���2M�R��Sk�p8������`g������^P[�)�LZ\�T�������� ��$��.��!��.�������<e���Nh��	��p8�`�K�hT�m��J}m�?��]'O6�nw�n���p��p�f��f��nO=�����fW��)�Z��d ��Q�j��+���yst�������.iHs
�Nw	e���{<�U0���N9���z;R�����n�Us�&m_�htu��@�3
�M}���*�hMw)������Kn�G�-����[,�t��;>}��]]
��O�
u+
)��-�/�R�����H�W�hH�,�\���Bu.\������K���Ho�$���^R�s1�.��.����Tv�����:���B�n��!�b�
F;�g��jy��4V������~���[�G��������h���������;���Q8V8R86�U`/R��$�O�v��{�1��!��-���R���.{L3�zo��
�B�XZ��3gk��i2���.
�C���>���9�������D�$�X�Bn�[.�G^k�p�9�L�0A���R9�>9�\
0>�������p�y,9*r��ar�f��nr(�V�rl��@����tl	�C:q�Qo�������T^9�U0�����H������g���m����1���O�-'��tBMM'�t���]�"�z�B]���4W��E�s����=�?/c��Pg����]���~{�1�����I*.�����4U@f �9�'����4��!oN���KT\2QE�%���4a��t�@F ��%�F#:q�q�+���o�%i���)���2�0���#-'�u���Fe2�2�2�w��������E�:|���N4�xc���Z�j�Zm�=�5��1���A���'UUO�Us�&�w�d����)i{���Zy������mz�7/>.�X���M,-Sq�Degso"���v��.�o��yE��]�e	��������C��������"}l������&��#I6�]K������L,����eW�No�G���s"����T��JwI���_��j�{;t������5a��WVi�U�C�����H�E�|~���y2; ���`'�����@�]�|�2.��������:�����pj���4��Z9��t�F��v���������I�{�ts�����Kb���h��������S�]a�"�y�����uT����^�	����.���I~�0�e�������k:���������n�Fg��������QG���0J����
�$zu$pXN�[wN�Y��.�
��j��wu`������jUTV��*0��`�b��=�?�H""����r���h������
t�K�
��5w�|M�6=����jL;�d3�e3��]��P�[?��wO�6C�s���db��`�;����Pye���4g�<9�t�2��v�xC���������g�t�������G�:0V�\�P�[�

j8vD���#IF�Q��������No�G�ZvhA�5#r���?��%
9�e�T:�\���TT\������/���bZ�������85=w�e?g,��lN�>}�l�M*���I*-�t����7�ik������a����/,���}2�����O�>��j
5��S�i�3/���A���������M��K$4�f���^�t���s.qR�n�;a�����Qt���D��M���K���N�3�0���C�VC�Q�8K��z�&h�=��?�����Q�h��6��)��_��\)�3�	6h�;^-]W&�ARi�n�y��lh��K�6{M:�����OM�[�,��������\�Oyy�I��h0�f�+�l�rs}���)��W�K����v�j�zU���Pa�S��:V���������j\3�n�/t�T����$�c�?�2���`��-X4����Fg�N(f1�i��[_U�]���*�R8���CG��~���[4W'ZH�J�|*,,Taa����U�kM�*f=�5d�,�YX�@fa�WV,����1at;6�L���F�j��F������� ���S+tKH�*����P2G�T��������S����>�D�T�DP�r�l��6��_v�`�����Xzj�R�7[-��.�b���5d�,�YX��������`L�Jw��,���A��t��R�h�^�dP���� mF�������������7HV�f>p�VMOw]�3J�I�b�z��Jw�����A��!v2�@� ��;�` C�d��1����?�E\�h�/�%.��	���^�red�0�d��A����� IDAT�!��.@���M��W�N�A�����o>1C.IJ�����5�:eQ��y�����w����]���#RQ��?r�V�3�g.�X�h�W~�7����,8������_������A�=�F��q�j�G|v����O��k�l��������������:d����I}�^��!��������������S+t�#�i�����A���7v�%�W3��D������y��Q�,0R����>��Z��Y�������v�V���\�)�;��`��	F�:W���U�y���n�3���7/�R���
���5k�w�y�p��=�O�����~���-[�/��YE�.W�s�g�Q	�7����i�^�6����Z�{�����Z�>��U	���%}���T����.�������>������j?������=�p��c�X�)�;�K{g�����n��g�|�������x[U�.R�!����Q;���7�(��i��|i��U��{��|e�W^�5Q8l��o~V�/;O��r���&\�
�%�#�;����5�;4����tJ�����2�m8�fI�����Q��p�$��d��������0��6m��_'�b��	�GZ/o�6njPh�\-�2H2�����l���6�s��}?|I?��_E_�NK'��
Geu�gk�5�z��41K��=r��O1K2�tY�r[jNH
6h�;^-�B�\�TZ��n��lh�4��(k)��"
wer�?�I�f�X�v��$�pD��Cz�3;T����L�?����Ps�MEe�bl*�*����	��TOY�|��NK�6%�/�+���z=�l��}��H�e�Q�����w�Zu�T�	��QR��M	�j���!I�k��?��PO0�����O/�u2hT��Z�h�j<Rg�5��J����pil�j�b��������)e�4K:P����3�*K������
R��zR�G�f�K�r�&
����v�{�����\9_�{�B.C"����Z������;v\�O3k�u�?����~�>�8���k���%)�X�Q&sT[�}��]�2dJ$�H�pB&�a�>=���H&�Q�p<�����Y�	�#��j�����5����Y&sB�p���]����V�s?��~����6Q�=�O]z��Z�._��-���	-x�@�N(f1�i��e��o<��lF)�Px��Q�,0��Y�2���DU�����_�������Q��lPC���r�0|������,�K���Z�|n�v�f�2�d�+5���-��d��(f0�d��6�b���)����"��e,�?I����5j��"E{"2O����f�:�c����*�]����>-��Z�����U
�fS�w�#��7�O���_n�������2E��]�����[o�K6�lC���f���d�|Z��?�VZ�U���olmP�35��l�����ST���@�����)��z�	)!��^�u�AZ�z�*%�6�����B��*����C'�k���z�Q*����	��e�Q�����	�zW��](��N'�N���wZ��U����O-S��zI$$�a��:�����r��t�/l��k
����M���XPE>����d����K��'�r��d�}t��h�.��
�������u�P,.�b�����S�w��bpIB��������MR"������S��S%����}���wU�l�+??����U$I����sH�{=�������*�p!��
���[���+�����8��a�y�NM��5����$���o�SO�?*)��?=���
U4��b��$��ok�Sq����g@,I�2-\�O7�+!�����M��\ i��Q�,0R���_[������k<�W^����e�i�5;�z`�L����Ow2P"����������0�=}�V=�H>�%9���n��W���M�+�������tsl�.���]�<"��2���\��������l���;�pB�E��� �� �5��������hB�/n�����dPr���=���L���5��y=��.I	��	�,f�R�W��C��Rk��}{���T�lS�����C3Tz���\�C�wo�������v�B2x��G���JR�I���Yo�KV�f>p��]��I�����Y��j��w��������^M�{��������!�l���� ��\�
 C�d��A��!v2�@� ��;�` C�d��A��!v2�@� ���t�1"��u��k��;�w�y�]�%H���m����pcT1d+����]�C�kCJ{�����T�����e�X�6�@����������%z��J�2K�Anr����B���:���G�H��65�}Zv_�*K�].��@����
�����]�G������zu��m_���-a��>-}�&��g���C�t�>U���3����!}�f���y=p�A�?�o���2-��;���,V��w���d_q���H�l\������]z�u��NU������op3ET����s?oPcKBr:Uu�l����>������������u�������d(���������i�w���w�����Z�e_Y��N�l�V=v_����p�����.�lQ�?�����G���5*2_������}�mm'���A��%Z��b�XxznM�����*��;�����<^����^o�^���Z�D�����jXy�f������4�����nmu��?�������[��_�Ps !M��o��U��n]���/~X�����Yl������������4][���O�W���bF���*����Z\�a���CZ���zkgP��d-/��/.��e����]�G�h9����'�s)��_[��M�ljQgP2�4��E���
�����j����&��U�:�"2WO��o-Vm��Ou!u�pc��Xf�b��ze�"}�'�Tdk����S���Y���B?�6��$���zl�z=�O[ez���'����n�v<P�������������cN�������5e��]��_����ci���������#Z���z��l��?�������2i��7�&b��G?�����`\��	>�
z�+��=�r�J-a�[�A?z�Ui����\���z|�"��n��
j��������
2]�����VO>���o���:������-z�g�m�3n��������*��U����#����SZ^.��F�?����q���[�US���6jC�F_}��t`e���P�s�4�;��������}����@_����<^y����F�1h���hj�����K�w�{����r=��@��_[���5J?�h��[`�����2=t��u�G�hX��zU?z�NS��}��z����g��z��*�3'�}�~���*�}����u�*����>��Vl=�)������9R��r�jK%��m�������������`P��]zs�r}�Y�L�&�������������T7��t�a��j�W?�1b������t�!x��SP�YU���2���yf�*�������[�v�V����`�������~S��$I��\���/��96�$�J+��e�y}���?x�\�b{������|�G.�Y�b�l�+�����-���m�J���6��7_~���{t�,���d1�d>�u11~m}�E�O,����������^����j������-��No��h���*rJ2�T��y�vb���17���t������m���V�y����H5
�jk�|���M�5�����9��I2���H�G\Z��|�V�d����������tr�l}�����>-���*m:�7w���Qg� �o������?����$���%dr��>}�#�����}�| ���zH��$4���T[jx�%��bIB{^9t�.��
���7P��Xs:>�����
#�;c��&��	)qqOcr�d5H&�A&�d�I
���r�s��=g����A��Kj>�P�O���~��|��I6$��i��K��U��.�<%*<30xTT&m=PL�����R"��F��n�Y��*��9��VI���+17����a��,���H��:x���|�&���k=��4��;��<����Y�A���;<��$�(�$��rM=���������M���vN��)*�,�O��+j�C���U��-��%Z�������/+�������}��W���+�`Y�|�s�:����	�j*�dPQ�Sz> B^j����3~,&�A�������
#�`���%)�y~�4��}���|x��T�Y���K.wnI�j��k�k�P�������"�
*&����_��lK�����O���cS��wj�����Q��i�+���__�D_�v������z�����7h��F������O��?Y�Z���_����_X�0���xg0���b�3���y�;z>����������R�s`g����r�d���>��A�/��p���%S���mgL�� ����N�GE�R���Ys�:��.�WeEW�d�wF�jh<�hB]M���
��oo�[���O����F���Gu6��n�<�f���w'�����L�pB�|�f�^�{_�o|o��[���3�N(fs�r��z�f�����6xPo�!z�Ie�A59sLT���2UxT|����
��``��y���U��e���DPo������Dl{�^yg \����~��fY�\�$���t��i���6$�����_����>���b��t-��h�w��9()����=�Z��
��0�������mp�������~�V�������0-����Amx�m�k�������z���Z��� ����z�����3T4�V�?����7������uZ���������n�r�U�i�w���h�w_�7>�Y;Nw�M����������DT�{;vzT��%�Z���[���W
'$)���-j���Wz�e�	��	�I�Wk����x�v4%$%���M�l�����5��F�b��eZ�h��|��������?{�eey�
��=�=9�<DP��Q ��T�Q+5/5�6�iH������/�U��1_\+�����y���&�Vs Lb�b=E�F*���3�� :�0��a��� �(0`���[+�����k������<���O������Y;���
i����^������T(��y����~���������eY�����K��!9z�I��G'���R�K�:;K�{8_>Y��
i�2.�}���9vO�4�{O>�s_����eik)i�	��������a��y�8'�_^�����R!������/�y'�������������s2m�����%��E�y(G��4o=k���	)�������H{�������}n2~J>��Rn���\s�����4��\��gd���*�53��,���n�������a�����uZ��V~���\���o�q��|WzSH}������d�������\���u�c�����������}o�_���\���,����������Q��w�f���s����m��eK�CeRZ�������/�g?�G.^�^d)6�
����b������
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�����
�������u��s������w��'J�N�k��]��f-��2g�}��,�������e��c-������z(���/�����k��[��KJ�	R�/>�O�����}�<��,:{a�v��`w�����?���,z�?��7���q�Kkv��^���8������ ��Y��%Y�����B���g��'���������^���-������?�+�V��Y4�����������O����4�]�7���//�/J���[�<����ae�T!���W
���7�}��������=j/)���fe~it���H����v��L>�X����G`�;�a�����������^�x_�4_�������mS]SH��Bb���Z�����������"�N�����d�GO��ck��-(�|����L��i������m��S���Xo�>1;JB�s��'�;�����%�p`(�4��������O���m��7e����+�}��,����i+�8vT�]~F.y�k���d�_���&������+:����q���e���@����K��k�&I��OY�$����g���C�|�{��7�.�T<2��5'S�}����^�g��
w<������u����\^<1��0#�IJy���������7�������gI���vd�_����n���o���m���Sr�7��������,�����Q�y��w��NEj]tK>{�1���j����������Q�����3r�o�.���|n�pA���Ln���<�RJ�����i����Ji�uYnZ�\Z���!Cr����=2M�B��;s�U��;fo�y���ci��J1�uf&.�7W|��t%I�9������-����g��$Y����=�}��O��~��,�3�yeZ�
s�IY��S�<�~�#K?|s���������2t�-�|��\���,����,i��u�i8��,���4�vPw�����/K�u��qx�~��7�������K�d����[[�����O?1%G
I��<v��p��|��S2��$]Y��������������3]�>�E_~$O>������>uB�}��L�m�<v�����UiY��Ge��N������O=�E_z$���#]U��9uR����fb�n�'���{���N��B��81�M��%�z��?�yg���9������^�W����'�o_�
]I���L��3r�����R����|�O����dHc'�� IDAT��hF|t�����RZnZ��{U�l�M��S����2f7�����q����v�7��~vo~�;���@��������<|�}����6�J^�����='�]��\��qi]tOnj��}��\���Z36��X���_����]��$��_������0��c���������;F���3;S������_�,Z��w3�����?�O}dh����F�!�s��\��Lk,d�5��uA��ak��RZ��oY��B�|��O�Ym����d�q��oL���d������|�g������;�
2NM�S��e���2��/�uw�?�\wRF�v,<�H����L������������,��g`1��gDw[Z�������'��[H2}V����\����f_��f��.�%'�t����k����z�<����?������wd����[;�5I2$s����������B������{J���%��������r�_��'�zgn_ux�hA�������Y�}���Y�7e������r��s2y����k��zM���p����p�ka�~��Y���\z��K���f�gN��������;����gr�?�N��MZn�i�v[)�}��\w�%��C�<������*��,��eyn�)���������	���o��9v����G����R��ss���U���?Y�m�����|��r��g��7���~�=Y���\����w���f�W�������x]�t���O����2_���������{�to�3���c��[?��n��a�����k���3�q�1��SJ�������4��<��u���sr�m��y����P�1��q}�Y�������r�����8�9�te�3�wq���B���PHuM!����n�Y���?G��c�T�1�������45���VJJks�m�s�������k�4�}r�<�#�����;R(����_��u��������4�����?��O�Y���n���b�]���5;������;$���oghSmz��J�'f�����XL����m]�P*���?p��q������w����#2���5������/_������Wv�~��m%Eu�M>�����U����7����9���in,�x��L�������e��[�{g�����Y�G���#���I��SZ��w���Sr��$5C2�C��e���}<+�3��F�_��qT����S���<�ZwP�y����Ew��{����>S�:-Sw������a]R=����fH�}��\�����qiu��e}��lV��<$�b1�����?wr&�:GM������O����z��L�>$��l����'�������9��R��8yJ��|�	������t��J
���?8��O��~vA�|�;)�������I��cr�����d���wM9�#G��XH��)9�����lUZ�zv��8�K��5��A>��IJ���9j��|�n\U��5���C����l�J�R�z
�����������������o�_��~x�k��P�IR��RJ��>�kKy�3��e�y�~����f��c����Y�V���C��sH�4�����)4f�������SHF��	�����<)����,�wc��zxN�����~{&��gW�1��y��+��g��T���V��C��i)e��o���@��!�]�T�I�]Jo�g>���Q������I�K]���4������i*f��'/>����W���y���.������S�`~K��rY��_�����5�j����?^}s�����0��L�3!S'�����y���1��?��&�g��`����,^�2��t�/Izz�{������'��nmW2��������b����<���2�������L���g���3��q�m*tg�O�e�mk�b[_�����aS~���i��a��brwG�K�2������>N�=G���oN.����.RU�� I�R�����|l|���\�z����V�=��g��i_�`�*����0lm�
y�
��8��5i��K.4��/�?��]��Z���+r�7Vd���������e���my���t�����<��������#w�,��e�����O�U�������k�N��lx�=26�Q�&)���s���[���-y�����e��?tA>����-�d�UO��#����G�XHZ���|���
������}�F���e��UY���<��wf�7���d�����{���2�����S��,��{������fg��^��~�=;N�=�Rl��a���i����[�$��<�xW����_�$���YW��K���Q��<�����^����=?dxF7�����/���5-ISs��;�d���UJ��q�9f|��\~~)�n[5�����GM��UY���N��''O�tuZ{3�@\w�PLSc)�k�~w���ls���IKkZ��xz���{�pi���|������9����,��n\�e���R�G4������/�7W���Yw��y��'=y���{y��'��%�3�}�������g;��Y%�F����)�����?N�����4�|L�|tv����S�*w���zV?���c����n=k�g}��z����:���ewZWw%#��l�d���`�Q���B���u�J��)m�-�b��
�zrmZKI����o�M��t����	��!5i(��������+���M�K�{���5[���]�g������)��y �?�������?^zKn��U��9��!i��C�EK)I)kn} w=?<3���s1��8���8���,+Vo}�Z���o�����C����c��r���y��l�{eZ�g�k+��^�y�v���W���d�#����������_�e�~^J��=���?W�k��0*�g�r��<�R)�m���Og�v�@��	�Z�*�������5w_�$��?���./=�o_�6GbV�=.�\��������ndy��|��%Y���eOW�{�=��_P�v���Y�TOzK=Ys�Yt�YS��ta��b�������G�?�_�M:��iN��'�Ks�sY���t�Ji�������������������q����1{��
����fUGm���=M��I����%��������������%R����hm�JIo����v�y��m����M>�3�q�9�b*�S����wf�y�(I��ss�U�2�c����}(�}��?6s>9;���8_�������,8{�8zb��k�M�|/��+�8jxf~bn�G����o/"�_�|�Y���=;�}a���3��\�so~��s{[R�<*�����;u�~�����dA�=Y��oe������s���f��=:�g��gd~�=Y�����$�b�>{F.������#�2b���]���$���9���,;�1cIJ��k������]�eI2rb����L��T�������<�/^�"��b��O�e_h��Z������o����r��$I&~���b�@F*�������,��?Y����L���L{tY	�$C�������}(��ygzk�}��,������J���d��3r���cV�<#.�A����2�[3r�@V�;��,�bS}�{Y���T����c2�sS�-�������,����,Z������\��'n=�'O������+n�����;{F.��s�e�������OM���R����tk~uI����13�����)��R�_�����?�/�y�v�<zK>vC�Bc�����=�&S���U�.���_����8�)'���m����9o�=Yt��r���9�Cg�����pg>;xv��r\zKI��3-+��?~!�k3��3��}o�&��~>��3�q�1��l����!�5g����#Y������������SrZ���;��r``;�"������W_-w
`G�6T�����1�0Ga�g�������9
����B���k��,v
��n�@��jH�*]�}����9
�?��o�(���Q�5��Y�n�������,v
T��\E;��FY��*���p0��b�Rl���"���QE;�bFY�X�
8Ud�p0R�T�pPi��!�6�;�[RU�o��A���0==��������n�o���s��?X�P���U������7���;�62c����b��eP����-[�� �?�H~~�����|���7o�������)2x���
)6�����
���p�M���������tn�����9y�����K�u�/������d���9m�Y9t��g���������!�i,"��,v���|/�=�t�d��ff���������Y��3;�����T��v�U�����tvtd���7}|���3d���?���2���RSS�$y��W���k����y��'s���J����~����������W�����Yd)6`��:�������g��!Cv\���!C�����M:���aC[��y�7l�{Ow�NK�$�����C��1��apC���3~R__����8��>��~}�����������/�F�I�a#3r��46r���+����WZ���W�n]k^Y�.6��_}����7���r����)�S���������������oy�b�!�bCF���������������R'�_n����f��^w�a#�t��]^���kY���7}lX��tuu�Xl����������Ud���|��N_oo^zim^zim^�����_J��/��s�����
���cr��#r��[�l�����P(��W�F�T��W>�#�7�������3��#2��#^w��u�������\p����&�P�^zim���gy��-�q�i9��3�����T��n��bg��A�����W^����3�<�d����q�p�����,v�l�R��>�qcG��������f��-~���:sv�>��rG�g*��>���J��������3ge�;O)w$�}�"�K�����w��������������q��"�K����]3g�;@�Ud�T����i��!6lHG����oH����s��`��������s�����
���{��U����]P��m��M�m��l��1;��q�����������>5�5����������3thc�
����e�����s�`�<���s����M]]��X���;�bC>��?{;�M�HoOOn[���f�sI�wL}g��=<����C2t��2'8�)v��������3��#2���3bDS�#t*��4hP�#�A�������b�c�)w��b��-��%�@yUd���7o*wvB����'?�������J^~��r�`*�;����_>����'���2d��l������bR�mY��X���k}9�55�9���|��
�rG`;p���������<��SI�I����f�����eN��(v�-x�����e���apN��������
�3t��rG�����t�����q9��������	���bg��A������/�x`YN=��n���u��xy3���K?����n��_���b�c��*����eK�#p�����%�~?�/��BUU������M<���{������M]]���#]���������>|����n]���ki<8����������3��q�c�f��R[[���������j�_�)u*SE;�7<������[�����G���s���
)��X}���<.[�l��M����_�f��];7����p_}��������/Imm�[���I�I����<����$��yz�5s�^o��Q��������7eS�������9N�6#===���9��7�{sw��7��{s�����!���2R�pP�����vk~�������������^�<uu���������������b�������7+�K�a#3��?����rG�R�pP����R����3SU]]�8�Se,vz��M�������RR=v\����L�u��u����e�{EWR?<'|hV��k�Z��f�~f�#��R��{��/�������s�m���Y�s�g��$IW~��;�b��\}��|�������f�/K��Pve+v6<��M���	#���1��f��my�'I��<�|x����-$��s���cK��+.@����i�������/V����r��t����k��i������u�F7�����J2h��2���r�eC[[�c��|��9��\z�����n�����px����gh�t��[[HM��,<��iy�{��#���R�����J��P�����Q����s��)���Q��������d���������.S2��W��;�V����4���Q��Gs3qD)�w����zY��3+'���IO��L���i:�6}���b!�$�z�qS_���0jx]���\������3Oa�f���m�9���9Kn�~~��*C�����1��V[�p@(�Rl�<q�i�uL&n��N�Y�������I�4e���y��13������������byPA^Y�.7~ka~��*��6>����9������2��S��c�������oJsM����<�3<��M2d\�O �{UN�r\�[�O�*d��U�����ci��_��BU
UU����B�*UU�7irF�h*w�z~�����[�������SO;���`�)�Rl����%���k�O���7e��33sD��d��gg�������4��.?'s�/WZ���/���������h�i�s�?�c��*����������:5��I��&M��)'���I���/���'�55���?����W��r�e����bU{�k�������3Ga�g�����`�����R_���R�+����R_��CG�H]]��}�����O�w�z{������������>��3f���������jE����������.uuu���Mmm]jk�2��#2��7�
�Q�����3�N8.����ao�G6�6�Ue�:@�v�����g���L���
mm)Tv�uUu�g���io����_z��==�;,v�d��Sw?4T��,v
T����/���L�13�55�|�a������I'��I'�������������S[S����~�"��
\=��^�mK~z����m}���Yg�9������+w(��,v�����{�����%I�1��������
x+;��/�6��xI�7�e�����=�y���x�;��X���j�%IN<���:sv��|�����������.����Q�8���8@�z��6c��t�rH���(u��R����A��`���_���eK�#�U�T�����$9���eN�+Y��^�mK��'��}C[��f���$*�_|K��������+I����<p�}I�	�M��������HE��o)6���[���
mioo��G�����p��������n�][W�9�>/�N8n_D�#Y�T�_>�<�mY��������v��k.�h�N���'��������>�u�3�����vl`?���M}}}Y���tn�H���9n�	�������>�t~���$IUuu�k����S,6�a�������6���m�Q{�5�I��>�,k������~��to����9*�����g���3h��444���fo�`Y�4�����u�1�i��<���yq��n7?4���C�CG4e����t�]=0PY�l�����
v�}�����u����$����LS�a;����3r�!��q���,����,v��������$k��N��=&�:"U��E��c'��x�T���������������#}}}�4���������r��-Y�X�
�kV��;��Y���s��������;�[R����3���~��L�x|�V�8o�b8(�2�]���;��	G, IDAT��,v
T��\E;[�l)w`?�y�����;iY��rG��\c�h�������fSWW
�B���������,v,�����������$I�y���~��2���*��������m?\���_J��!\���<������,v����O=���I�#�>&������/�9����*J��CS]S���������q�)�PQ;ld���>����rG��)w��b��A����R8XUd��e��rG������}qM�c��,����w������������tuuf��M����|"�55eL��Q�����7k��N[������l����M]��iS6m�JuuM>�����s<���m���KC��v���Xl��X���)v� ������?�'�R)}}}���K�������=�9�.�t����������>>�3m���R__���C��k8)v���aC�z��Slh���&�p�����f����IUUU�
U���I}}1���zh�N�i��w�<=4(u�u��/��������5#G����p�S�@�k[�>O>��<��yi��I�������9v�q���W��1kk���������5��@�7o�=�`�y���k}y������1o?6&_�t�-��P���$���������'L��!�Wp S�@����s����hNC��r�`9������oV����l��i��;�8��A�;Pf�R)�y��<���y����yS�3f���t��2�`R�b�������+�������3��f���5��[�%�,��+����9�C�2^S�����3]]]ihhH}}q��=��y��'����W��&I�kj2��Iy��r�Q����T��;=���S���Cs�����p��\��g�
S3&]�����1�s���R���,�lisq.9�P������U^�mK:;7���3����q������O2��I;���My��u<xH&�cj�~���?��}�
U�b���'�p��|��!�N�t������v���������2���yb�9wE.]��8�\��uV>�L�~����W[W���������z������������7#p�)[���S������U�d���d������2���dM[������m?�yH6��>]Q��wuvn�#�Z���:&�F���v��:+3f�����������v��`T�b�s}O6=�*�_87��\U^������~ ��gebW)����t��������7�<�*�*�+����4����@�N�Q����s��)���-[���O����+O?�t�l�����2��#_���st�p�|�������W��;��������r���T'i~�����ey��db������T
��?����k���/)RL���77��+:����e�������9
�?������y�W�LGG{��a��L:aJ����7�Gs�o�(����V��V��?<�����$���-�'�����m�9��YI�������M)&i/Kb4/��Rn��7��7��Ly��;��2��;�\g�	+����HRJ��G�X���0>��q�>�#w{U�KI����'w2��Q������Ff��1�6��|���g���*u��
��eK�6�Z�P^�x�\SJ��r���������������Wt%��s���3���T'i�������7s��)���Q������:lXm���v�0�Z��U�����h������3Oa����+��jE��?*�F��c�k�������b���]c���^Z����"O���)�J����s�=���`�P�P���7���k����,���yq�I�����x��9q��eN{�b��JGG{�:;���1��������������������/�n�36SO:9�O��/��>����~��s��?���sc�7���G4��i��8|x��='���i:��45�7�@Y)v(����ih������)6NCCC���������u9��i�()��b���<:�����O�]s���h
�-���`�)�8�
�s��>I�pn�Y7��oz���Nz����@�\��Ng8M��$3�0�6x�l��5�<�R�?J6��e[�J�����$�w�U��W.�g�������uww�����<�u�t�����FL\$v��i�zo�v�~�F���J�.Z,�?P���������F#zk����6%	9-Z�T+V^AR8OH�F���_���"I2�N]�|������p����Z ��������t�
���b�LJ$v�6w���;_��Y�P�I��`��?/��PZ��W.����v�G�=�d2Q�p���TN���ok�48�/I����_���Q7;0���=���>��������z��-������|��x�)*,SC�UTV�����h4���k��O���]�HX��6o��,]���)E���t:%��m{N��N���O(E��sL�:�-��^}�����r<�*�����OxpP�p��?Pk�4�s�v�o�}J����u�Wj��e����-�S���r��l��Ef��`������d��`�5
�����PG������{�}��u�9k��=w<S4U,Q8V��&���Z������W_�$A�WT(XV����
�S
�X��h?�������	�4>w�B}��OX������o�***�:u�Y~��(0��F�����-�A�w`���`�I�����m��e�?���R"a���|�����.�ugt~MM���-P$<���>�!�cd���+u���-������w��8���������������ee�d��3�@q��0i������_���;F�5Ni���K5{�\���h����1s�I���GJ�UW�l���=G�S�������.d��d|�Ug!�Lh���x��;o�/�T�UU�kT**+������#�Lr$vL�S�t����m��b���L�h��9$uLf��0����=��������~}���QSsK����8��NV�/����EZ��!I
��Y���n���x�R��g3r\�H\���@]G;%ICCC���M23I��Y��r��U��N�����������i��
�{���6����KRz����HY����Bc/�	���O����8�I�P���G;����_����h��eZ�d��eec.�[���l�6��_�_�C�U!I�yn���.����ejvH7/zN_��~u<R3�v���{;�k��=�D�P,=i|�u7�&v^�D3g���������b�W`�ND���Zy}����������
W�$q|U���I�6V��C���=IR��\M�-*+�Pyy���+��d�',S0��8�����)�� rD��sk�gO(���*s��0�\v��Zy�*���;�tJmG!54�h���WV���w�Z8��Sz^m���
�S�
��`YI�@
��	�������=�/?"I.�}�-pIRZ��O=�x�f<|�.|���L:���~���;��,�V��Z}��3�����3�i�B���Cf���/|\w�^�0��i����c������<���P�I���`bG�|3Z�j�G�:���?����q(�����zB�G��u�*+��\t
$v�����iz�
-�g���I��g���}{U[W�O�~�JK�[v�?��N�G�a����j���SY){�����~�458.L������k���*��������t;$�(�'v�Z�g��y���pk��3u���Z2�g;
������k��7���u��?#��[����U��Omw�R�]��6<�[����z<8E+�p������W$�����������U����!�E�@b�C�uj[�`oJ_<�w���Z;��,+����C�@P�PM����^��N|�~mxr�6<��WHn��?������5�(�Y���`�}b'�G���^��AM�j�n^�OR������s����.h���=vB�BjNK�G����i�F��E!����'v�Z���>F��Ni�P|�i�h��b�(����WO���G$w`�#�\��~�:�o�jjj��-v8$v����~��w�Tm}���y���
'��H��Mo����nQUuHw~�^9]�b�(`\$v����WV�P�o<�`o��|�'���G����G��Q�h������W^TEe����>�\�b�8�O�D���#]rO,���o����U����������oe�&0Y$�	������Bw�s��^_�C��"'v����
��\K�O8i��-�Z���9$gs�n�Iz����E
L�W����Sw�+�?P�pg�������z�c����B�:���T}��������W|��&���J�WT>0��O�@�]z��z���.SH='�����r����-�������i��*.�����S���s�����S�0X`����X��������\�C&�"eG��x�M���}�Y�G[��r��Jej��M�yn����s�')��(�0�7�3QW�QW��a���?�)0��F���5
�_5��b�L
�I�d����~��<���H�L%z��������kB�N����
�~�jI���DT>5$��pQ���H$�����h?���t�}�G&��$v!�}��=�q�GO����[�����\���}�]Kn��c��y��%[W�p��*����]���~P�}#c�a�����L"��Q�K+�v�:��e����K�J-���Z;��q���O�J�%I�C�-�jjiUK�T�74��p9B��T���&\��p�;�xF=c`|c�������vlW_�ZZ���q�c���L"�_
�o�Q`��)w�i�;`���>`�F#�9�G������:�x�2-\����y��at�b#�������}�����8x@�HX~�������@�#�'$v�"z���z��$I������Z0w���u���$��,r�����PD���kIx�������i��
�Fb8�r����v���ut����������P�Fk��a#Ld$v�Q��:����jo?�C����#cU��"F�lH��	������h��Yji����VUTV1:�dCb�BxpP��G��sL�����^�_��\j9/�N��?���c�y�}�c��2-Z�T��Z5����:���&��#���'~�T2y���P�mbg(7�C���a�������7~���`�H�`B��������3U�����z9���q��e3[r�=����e��!�a�a8d��,0��Db��������:�V,���n�<������F�|S��G5��BbE7����#���yXG���.�r9IRII���f�m)4.�u��2MS?|�


I�'rB5�j�����)jll"��0�B����������aZ�t��>�����(����8H���0MS=������c�]�:zT==�23��������-�����1�����F�?~�#u�<�xeU�jk�F����!�[��A��6��r�U�0E5�����S]]�jjj)��y6!;%%%��V_o�^y�w:�yD�u�Z�t��M�Y��
��W$V"���v����b��>}��qJ�����}j���5!;�\��!�V,������oo9v`�^��3��Q��S����;N9��z5m�L��|����_�����h��7�y��23UTV��UW�H�j��l�����t��~�jj�e�j�TW_/��=�����t��KS�M���<��p�:T�����kjTURmm�*��F����"�pD�Q���UA]~��Z�h�Y�O��:6����c���`Y�j��t���jjn���R���:��5��9��52~���lK��t��g/(;�AEe����nMij9��e���q]��u�Xw>9�����N;��������������'3�NUUU���Z^���c�����u��Q?FMM�jjj5o���c��Ay�^�y3g�QUuHUU��
�TUY�`Y������3�������y��������c	(6;>��W^�������s*)))vH�"Eb�Bww�^}y���'I��`�2��\.w�#+;����W_^�=����_������92p�#�p��o���_|A��:m����Z���9*�<;'hniU]C�V��^S����IH�����^���`��8��b�3Cb`� �0A�����z{{��Y!�.:o��U�~�Iom�R�P�
�pQ13������W]U�p�
�pQ���
�c1-^�L>�����;�����y��2�N]v��������76�*3��������.v8g���(����������j�������`,��)�eZ�|������;��PW����2^����Rl��ARLt$v&;D������/�����hD����[�r�V�s��{���77��mq�[���Z���V��bU�;�-o��Ki����?�~��tuDO��fud%)�M�Z�m
������?O�<�'��+\��+^b�]�5_�R7�vIr�yM������i��-�Z���9$gs�n�Iz���b�&��#�����yU���oa�n��b������;�N�]�:���T����oj��_��L@�<�+������T�C8o��c�C�W^�������H!I�g�q;�J���[�S�]����)�U\R��)�g\��4�%���;.�5���7�MG�����\W^�p��v1�S`"c��k���r��������������o�@7�s��r��Jej��M�yn����s�')��(�0�9ku�u�'��}���)=���23R�����s��5��)0��F���5
�_5��b�L
EM�t��y}�q�>�O�US4�T����Z�����}���|jH>IT�V6������V\v�|>��8���c'��f=��������:�l�����X��Y)s`��y��%7�'X0!D�m��I.�[+.�����wE�������1�R��?���:*u�����.���������W�?/y+��7j��bE&�
��,�4���+�r��L>EK��}�3���lN�h������c��:������e+�
�Q�;��}^�]Ge���S�z��o�a�qJS���`H�L$v&;��	������D�CS$v���s������>xW�C3$v�������+/j(�U}Cc��3$v����[[��u��e
����!�&�4�����p:u��+���"�&�m��| IDAT���x,�K�����-v8c���0���6��A.�[�W^^�p��0al������V^�J.�����9����+�Ji����
@Q��FyE����c��h(�0A��� H��q);�q�;��r��������������UU�t�};4�q��(�t:��o�����:���t*52�TYYU���';�(JT��_|A����5m�5����e�*�H���PN�K7�z�B55
�j���@b�7����8����:������.���ms��at�p��~k����$����)�������>���+<�I������(�*�*�)�*���{���+,���s�v9|HR����3������54N�O��Ab�I$��+<8�����q-^r����>��R��)�}~���+4����M����T^�W�wT��0;LP�tZ����F�9f&s�9�;W^�F�a�����������q���s�����P*���={4w��s�.����e����
�������������\�x�y�������:r�����R��2�t��dR�TRk��Q^b9������v����y��\n�=��nUW�����6�t:�T2�d*�t*�T*�T2�����m�|��}������X�N�mbG��{�s
��A�H���k������J%S2��2����t*�{�{P�
�����y_�w�w�1��-�����J�\.�������=X�/Z�T���q������~�s����)����)�0�����z��x��x��z��zUYe�T���������n05 3g��c]N�2��k���Gn�G�-�#��������Q��T��o"@�8�_�G;%�2N�S������a8UZZj;��+����W�����q��r���_q�5�t���v�$�	�R)��IU�����e�6c��n�pR��?.�[�J��e���~V1�x�o��&zd�r���%��R��RCU���������>m���x&�X&�X:�X&��PZ�Th�������&�j�z������S%%%�������rY�
�\���t����.���[��IS"���V��<���&';��&�L�����uu���KW]�F�����+��Fee��Y���:�PG/�V���h>���Q��q��c0���)�21UzF�7�x�=�H:�T6���T*�T*�Rr��UM�U������o�v�l����Z-o��r|���z������B�t��[-�������|�1����3(��Q����g�Z��J���l.+s���?d����d������{���,�gU��&v^nA�Y�l���Zd9������k���#����$�����4�|����W,S���A�o`�"�8g������������G�FN��6�6�3u��"��H*��d����K��/���d�b�����z��?����?W��ZU��������d8�c����D~�J:�x&�seQ�9�%����V]�#��B��&vV4\���y���!es'$F�L5�����sT��"3�Q&�Qf(=��k��3|������w�g�*u�m��sZ'PN�cx��i�Y����f��������\N�lR�lR)3)���V/P��N�P������W�v~*�V:�R:�R$=x�xiI�mb���=�����{�?�z�uyt�Cbp��l����%I�W-�SUS[���z��������p"s(3r�2;������p��J�u!�31����C����w_�U���(�j�z���??�T:��������cx���
���;�����I�������gP-eSU����&������S�Wy�U�
�������O���W�O�t����*f��k]1��l��<��;��;�~�\���N�5X�
����������S}�?c.�[u��s�>L	6�j����Q�_�z��j^sBRhx�����Be�<�[�e��d��@q���s�F�s�[�i�4��fMe�YeMS�i���Bs��_������=m9����ko���������������[�h���?�qs:���K��[���|��Zz�r���)Xv��$���d�:�~]h�jL�}���A
/]����4C��lF�L]Z�����c��E��c��������[���zt����v�2��8<�%�����+�����ep����k[�k05�w��*�5��
�2�d�2�2�)�rw�n�v���L6������\v$�u�.�l.�L6��W|�6����{�dNA_��M����d�z�';~�8����y��k����e	�����^1�r~<�@����,%���Y���v��w�7qL��]�
����-�
yk4����w�x
�n�q������L
(�T8=����&z
&vv������h*�h&�h&�h*������~�v~$�T�z��OH����\���lZsF�+�7���!Cn����Z>��w-�����s�H��D�E����FU:�P<%}��u��%%���|I���?���y����'n[����X���7zk������Z�_q����}{��s�X�O�9�6����u���r�8�f���)�0d89C�1�����a�*���Q.��)n��v~k��3�V$�������q3�o��)��jJY�n��I��}�^���Y��A��%_���r���|	'���5���%��7���'NL�T{kl�3zX{v[������
���sC�����Lhs���q�u3tI���D��c�������J������I��#��Up'�����/�����]����`j��>#F��6��>8R�t��-�s�}���~������J�xV��]'��n���4�������m7cJ�	���lJ����i���O��*�C���=��g0`�"���hD�t��1}O�1=��S��K��k(W�>��MR�������~�pee�������%�$���A��^}R���2C��2�T[[���j�]!���
7�j>�������U"W��+�I(�M(a�5��jAh���X��e������N7�����;�%i(�Ut�k���D5�b�m�����f�S�7J���)��;�|��MM.������]>�*��:d(���(5�(1�t�w[*�s��l��e�m�.{�Rf����f�)3_��Py�rw�Z����q�#��Q�(X��.P���= ��)g�SNG����6r;<w�b�#h,,�[��u�N:v�{��&�5�7����P�S����?�R*�Tw�[�t���S����W�jo�B>�����3��ai�C�N�I��������2������(J�DQ���r��l��E���K$�:�o���A�588������$I
�St�g���J%���O)**,��jfk����1�L���J�����8���
�5#���������r;<ZZ�|�5}=�uI��v����e�=^���=^�����j����M��S/f�2J�m�]r;�wq���M13*I*Q������%.�
�Sl��'��4#ew���8�������f��,��X�x!3���������$G�1\��u���3)�0�^��H_�Y�m*�TX�}n�Sz�����-7hi�
��_j��c�R��n�Y�m���:i0������:�Q�9d��z�L���u]��
)�LT���w����g��&G��MAoum�
��P�RC
����������w����lv���2��Y�v~�c��n��u�lK8�%z��/�����w�&d�������US���(-v��7��Bp�"����|���qk��-�=���?�y��c�`��v������S�s:��H�F�25��W�������v>������Um��
���5#*s�����]��tX�#�KXK�p�tt`P	3��@��`�u�������-�N������@�)=�C)�C�2��JTb�[�6�/�c9~G�=���<��v�n���i�V4^a9�w�}�{�m��J����#��j�
�p:��S"��J�j�u���d�~��?Y�;J;���P�r���_�mv��?P�M�
O�mbgnh���
�>y�^y
����`?��j|uZZ�r8�5�����4��d���������?�!o��|Gi�&vII�xd�b�8���Y�;{��������*�$�/g��Fs���w�8}��6/w���|cv��L$v�	�h����V�488����I��g��M�TUWk��7�������������lp1�f"J�)�]~����lR��	=
2Q���c{at���1|�#��k�ug�hHe��d3��C���\����T6���##;=�C��&��;��Z\w���n�������q����.�K��A}���2D��A�SJ������T��.��Z>]gP�+������(]Z�P]��l���w�����B�U�rw����W�P-�Sm���y,;��I��zn��O:���f��>�����2]�t��}���&�n�]���Qj�������Bn�z���A���)�$��m]�U��|�j�X��)wW���K�jo����s�������Ez�����(�M+i&���OJ���u��-��\>M��qr�p�G����������+�MY��px�����L^�	�5NH
jz�Z6]�e��i�����|R!��F}��3��.��v���u	�[g��d6q����	���`�����M+�1�����u��Z,T�k^�B��^8��;�9:v�[�DBCCYe2�S3#3�Q&����3T[[g9������+��*�5e����)s����gj���wv������������pr�/����)M����-]f]N��df3:��Vw�K��]�Y9[S�gX���{��8����Ag�|��v4�|�fV���'���Z���0c2�N-[���M�t��l=�j^��
�,������|�r|N�<�2�6����1�|�O,������s�����,�%�O/���e�~w�9�'{G>6J
]���7��]!�a=W�.k��v���u�5%��pj@��|R)���H�iWc�I-�j9������-��N�mb����k[?��+��+(�3��u�g\B����6S��{W�Y��������
�kQ����g�w����J�I���w�HR,QG����|2��[%��#�������c��r��u��O�s����o�}������Ub�|h��~.dv�����\��P4U*�T*�T&�V"�P2�T*��u����
��^}I��|`9���l;��k�F����� ZZ���?'�p"���D��;��>���/�>����?��u���]���w�Nd���:0�O��]��w�tq\�|��6�S�o���%�e�#;M�bGF���mb�#|Pow�^~gPg@WP>�_���L�^��������!es������H:2��"�h:��ZoR�e]�&a���
��[s���5Z^�p��T���!�:�N�!SM�����*�S�.����'�U9q������7J
��v�	%�N��c�L������]RR:�C��`s�����`�}�O��������0R>����w��	��o��#Q>�|9�K�Lg_J��l��w{�X!��	+�N)�)�*�)�*��+�*���;��Z|��'	Z��bQ�����TWg]��.�#I\��&��u���E ��K�4��LD���p�����#��*�U�wWx*m/H�Ii���V���'��8^�&�M����/�Ov�P�lRe�r��+��kT���z��6��'A��HR��ZM�~�^1K�+N-��4�ebK��w������3*gk�������
�_j���En#�'#�
�p`p�����O���2�����s������B�L�r|y����?9�N��/d��gW��]�AW��vJH*Xj������!Uz�wjHR[h��B�� H���2�����R��R��dR��R��JKK���%�s�������[��O�Sr���XO�6]�DBn�Gn�[n�G�Gn�Gn�[�!���4kv�f�n��$m��,����b��e��dMee*����(.Qo4������K�um��~��C�B�lK������'�]����Qb�(u(����X�����;rn�n�.�N��I%����������p����e?���3o��S}����7q�r|U�j5�������q�F�M���I,U_��r����6��������?,�KKK-��|� �z�gb]�����t8�;|�N����{���9���g�'�V��V��x��&�	��@��Wjq�2��������O�T{CrH������
YZ�B�����n�f��g�J�����'�������/wW��K��r<=��/v���9���\���U�T&�������7������v��%;8g�tJ�dJ�TR�TJ�db$Im�G;���������`�mb��r�u��|"f81�r��v'g<n���$�������9����!��7%%%��~��c<���mw:|n�m�B���ot4v���~��X�T�Sc���O��#|�r�.�!I�TX�Y�O-�a���f�z��z�q��_0�������P�6�s$zX�1������V�|�w��Z�_>�*�����=z~�3���*f���	���u��;\\�
����^��Whv=O�S��K��/���d��=�K�*���=���~�������[g��Y�������M�����l9Q��^�>������ �J��NsY��x�W�=1�w��w��w�8J�_��J���i��M�����.y��c�0ub�..%�\��1A1����on�K����R>{��_�SR8�Q4a����50�'�4e�Ye��L�T���mh�������n[����-��N����Y7����z����1��^��N�p��#����f���#J�NJj��������e�v�����1��+��� �������Q���+uM�����z���{i9�\�j���/��n�r��p��^�X�K��~�e����y
�H�����^�~�w�����S�R��R������L+����w��w����������av��Q���m���u(��T6��PZ�lJ���4�k�Y�����l��p�#�K�#=)���wN���c�s8�s\����9�O�i0���������h6�)h���b�����s�'���@���r�}���_P_����$'�k-��9L
(����Q�S��������>9=u��3n��8X�����7�(0~����4��{(l����k���k[����wZ�=�K�~�y=1�N���Q����L:���j���Y�YSC��L�Tmm�����myI�����dF��s���u�o����w�?���z��W,����j��N�S��KN�!�������4�t;e��*���>e]Yh�{�@*���:�����>�/v�T�������6y���w�lW{���������_��&~*=��
5�.t��p��l�����jT-I��s��������QV_��
�|��ym�2��W��������z�B%���Q��!�t��*=U���
�k�3��&�{&��*w[��N4>;�vm�R��O���!��M7��M�>�%-n���k����)�I+c��J��1�J\S^�o����c]���a9�0}�Ko�g�|�R���������1e����~���>�o��j��1j*�^�RG�J�*~[Z��i��eQQ_�����M�)���Jy��G��mR����������Y��������7�����������8�;��,�������R6U-eS�y~����{�y�$�F��cg|&v:���T�	70�75�b��j��#����7�Ke�tX����N��f���Ca��o�O����,���LU���;=��9r�r���T���
��L�S:����q:�4�#o]N��7�lc�'>���%r���z����1J
C�k��>`=��5�����X����Te����z�V�Zj�9�����>7���'����F��z��Z��5
��S`|c��k�2�P�C&�����g�q;�J���[�S�]����)�U\R,S{G��n���S������a�����dIDAT$u�Sw�����������I;4%�����}����&=���d�i��\��j��_���|ENq��;F5��S�
��H�gb���3�V�(S��m
�s��5%�C>I�/������q�����RW^v����d����MIfNRf��������*���5
��S`|c��k�j��?P��L�4�T����Z�����}���|jH>I��FP�����-Z�2��kW8+e��3/:��&�k�����#�V|�Zu����������Z���v^��(�q���T�����[k��81>K��$v&;��	���Ab`� �0A��� �bp���	:0�����F�q�5
��S`|c��k0���r�\��@a�b� H�L$v&:�8Cimx��z|�K>��!�O���N�[,IYu��e=���:����i�_]�%���f#����z�7=�[�k�������q�gpzw�{w�)�_?���8�x�u��M��?;��PJj���r�n^�:���FV��s���Y���u�B�������
�r?�l�����*���v=��
zi[\�Vj�g����B�����Ih�w��W/�+�u+t�|}�kK�V������:�]��LZ�~��~�X~�y�L�-_�F���_��<�}��~���H����������������3�R<���o��������{���#q����t�����������C3�>q��g�������/�j��G��i=�x�����1�L�I#�V��]z���jwZZ��a�uo�_�%�����?T��W�7��~v��Y�����������'��(3�#����s����/Q�)3�������p����y�����^O��Sw/v������o���i��/o�t��^���z���?��"g��+��a�5��d���~,��w�n�-u�����Y3~v��R"b*��������{w[U��{�;wu�a��R���e��R���L���z�u���A�Od�a&�82�\�;xf���
F����s|���S���K
o�(�#igZ0��tg6iwW��@E���n��IH�{���Yk?yV�o?����^�J�.cN�&i�:H�g�}��M[����T�
�lJ�y����A+@����2������h��w���#Z��H�������?&(��uL��������f�����^��;m��c����u%
�'
��g;;F�p����J?���+��7�h�d#;�c����
 RT�
7���'���]IB�U�]:��< ;����q���S��W���i��&�s%3�����d��(��O�h�n��=�����/^��]I�e�;�&I���q]-��'H�t�$~�h$�AH��$��{��)����$-M@���4G)(>
E��qEK��!u�������0	j�?����viJr�����P�((�����f����,�@zS��>N�:H7����9��E����3�����:d�{u���b���))���w�����.E�WPt�u���3�{�y_}%���a��6\H���M�<D��S=�����i�N1��!��]�<����Hp<���)c��3��I�w%I�1G�H������1���B~�f"�M����I $��C�H�{�{�y�]�D�C�)����,"���-��,�K{v@$Iw\�jI����]:����1��Y�"�,�R]��+���3���k=��6����Ij�W�S@*$���������	�fA*$�o�+i�:9��;�4^�������>�a�mX�W��m��R�t���fh��+����?b�7rm��s+��������#v$
Lg�/���.*c�m{y����]�Ds��T��GR9+���N>>�D�t��(�����8Y�'H��KU!�r�w��f4 �B^>��@A��.�
��]W���6�E����|~�^�c���h@�����\�������Z� %����4(a��'���#X��J�c�o��W���l��'�����Z�b�on�z���4���(=�\����xo����zW�t3��40�$��(������. '
Jb$�&rG���
O��(�a���f��F)���@kQ��q�.�~�]n�0��~���I�^6hcC\� ��J_���j�9{8�%g�
B�(�s�����1}iw�s��$CK�D��w%
B��G�����,^=��^�K�}e�0��6,i0Z^���u?���T�����e�q�FStf��0� �~��������S�I�0A����P� 
�����vFO/&
U�d��x����_h���2&^���8�^��#I y�
/���7�QpI+%]��iweL<u��lJ�&$����J�2%�]I��w�a�/v��;9�n/��F2q4+f��$���H{�c
��%����)���w%
Tb�F�+c���
u�~��~�a?mX����f��.nx���P��#/nf���$:�T���x��i#)
�zW�tY�����O_�BH���Y���������1��������!-o��v��'ah�X�-���37��$�Oo�fC��D)��������P�W���5V����S!��l��{+K���mw�{Y��^����os������=#l��_�0��l�P'v���F�+ea�4�����[�}7��0`����}�T&��q��L��[y�>C�1n�L���#���J�_�����������]y��TIy�O_�_;��
K����;O���������T�>i�����I���R4cw-{6��zW�t�2��$I�$I�$I�N�&I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�����$I�e"<A��Z�����]��|!-�����?���N�D���g}%���.��t`�4P���X4��%I�$��f�#I�$���
��~K�An6@�Ps����d��<���dI�$I���H�$IG[i��3cA9�E��0��|*��_�RH�$I����O�>}�!I���#���<��a�_�s]#�O�H��L_v����^�����8����1o|��������D���hY���p1�;��^=����Qu{x��v�Y=��/&zf*�����O�����A���I,\ZF��`�N��l��i:B,���'p���D�,����Z��x+����g>�`S'���t3����t�aj����{��w����{+���gg��X�����<��'�K��������y������r
�/|�h>J�S���'������GP����)=uk>�������<xW��x�	jR������e����<�mg]���{�u(��d����;o�
����2�������W^�-m!�����*(�Y�}O=/=���C)�9Q�W�1{�$*
���i���V����YC��R����Q��I;L����a�t)���V2w��������8��*���/��-����l�r��I���w�T���O�Q
�_�'�2�Ee����'[;�.����VRq��M
���$I�t�9bG�$�r@:��M��5S)�NQ��k�^���5���~t�Ej[3��v���e�cuDV������:@��b*{����h�&�,����������8����!�x�/��y����,�n��R��fV>��_��lFA1l����9L\���B�����F^�w3��Oc�[���8�n#�-}��Bu	0��;�������T������zD�����Y�:d����tJ�d��m�<u������7s��:��QFA4��������!���J��r.of��6S{�lf������r~���'�
�!M�d�S�yxL@������vD>��S��a�%��z3��|f?7��W@�3�3����yfi�%U���O4������]K�O������_"��f~;+�Hg������'�zB���x����=��O�$�����U��Q<�F&_����;f�jN��X]]�)��G�����,\�}*� �m�����!�s���3	���e��*\'�l��'o�nU!���P�%I�$������$I���aT�����(��=�)��An'?�������0�QWg9�+�R�l;�X�b,s��#����
���-�����WO0t�T��%D�F2�����t���3[	���!} ���fR5%��X6��Q������{�]�|�~^NQ��R�`���`�;�������<Er"�=�3#LP��	�|o*�����VR�m��O���?{�/L��u
��d���(�A������oJ]��E�]���]��/;��T��7r���T���*���]�HQ9�^pd�����������]1��QQ�yQ�W�����8>fw��'�8�?�@Q�a���,�v���x��';J��[x�w8�H��DbQ��<�(~�L~�\�sF�����l�2��S�(
��3m*��B�o8��QZ#�in��L�B&N��:�vn���[�$I�����$I���D����`�n3�X�!D�"9���-��/��PE�P�D�|J�_CZ���=k��A'�
gV���b�����\�m'�7����� ��b�;�F���F��)l��	
����6sK���q��O��0�B�-q,I*�`��?����"e�^u(]t������0n��T��a������Ga_���YD���F���NZ�R������w|����N JFs���X����7*�Q#?m$����PH�OF���Z��g����������?��/��F"�Q>��Je1x��D�����c\���Dr�����)�$I�$}
v$I��y]�/�����3���K��;7�W_b9�\_���[��q��3��vR�$!�h=�$MlaD����#�����3�����>��R��v��8���&��id�����5�x�����_���Xq}�#;�����~�
�_��5������0��?�rK�$I���Tl�$I����!��^��&99�=g�l����W!-M)��u���QP����I��n���%���xk�7�6!^v�GZyA����������G�Q\p!w�32*������!����[R�z|����|�D����u[R��dS������	s���{w�N�|���N�D��3nN�V���g�����z�%���(�1���n���3�H~���;Z (�#$i9�{�NZ'����p�����-I�$I���$I�?�x�h�#;Ot����z�#Z�[�K�w6�aOw����n��>��(&�<�����`���AB����e����
���r�D��&�O�����$����M��B�W_�1A�����zw����>>�K����2n0�����T�$���n�a'M����Zj><������{�����|�������b3��F�w6P�~���}p�y��Yc)m;H��GIt�6��~����J}Op����f���=aK�I��OI��(83e�'
<u�����F*i?t��SQ�E��UC��!��K^_Y��i���A}s�$��`��*�\5��
���$I��5p*6I��t���^V��g����r�?�q�'P��n��vB�a@�m�Dj��K��
���;�����v-����u�<�g�<B,��i�������> �b�=;���>`�Mu�w�'S���L/��;����s_�v^}�?��!/���f�dQ��Kv>sWEd������0`h�p&?r3�����>����&�x�&_�S�93���5��r7���DQ���x�h�o��/�%i��������)��}����j+�o$�%^1�y��JE���3*������/Q{"����c�����T�	�����$yy��,,E��!E�L\�}���Y���/�K��wt���@g��[�.�2��7�z����bu
���L~�F�^?������$I��5�����O_�BH�$I�D����e�M���O.��k$I�$I�S�I�$I�$I�$e�I�$I�$I���Tl�$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!��V���n��IEND�B`�
0001-Replace-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=0001-Replace-OR-clause-to-ANY-expressions.patchDownload
From f9f5958707bc1d7931323df05d51a60fc9d6cd38 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 29 Jun 2023 17:46:58 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than 15 or
 expressions. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

---
 src/backend/parser/parse_expr.c  | 290 ++++++++++++++++++++++++++++++-
 src/tools/pgindent/typedefs.list |   1 +
 2 files changed, 290 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6d..3d395fd6459 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -95,6 +95,294 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int const_transform_or_limit = 500;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, Expr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc_eargs;
+	Node 		   *result;
+	BoolExpr 	   *expr = (BoolExpr *)copyObject(expr_orig);
+	const char 	   *opname;
+	bool			change_apply = false;
+	bool			or_statement = false;
+
+	Assert(IsA(expr, BoolExpr));
+
+	/* If this is not expression "Or", then will do it the old way. */
+	switch (expr->boolop)
+	{
+		case AND_EXPR:
+			opname = "AND";
+			break;
+		case OR_EXPR:
+			opname = "OR";
+			or_statement = true;
+			break;
+		case NOT_EXPR:
+			opname = "NOT";
+			break;
+		default:
+			elog(ERROR, "unrecognized boolop: %d", (int) expr->boolop);
+			opname = NULL;		/* keep compiler quiet */
+			break;
+	}
+
+	if (!or_statement || list_length(expr->args) < const_transform_or_limit)
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+
+	/*
+		* NOTE:
+		* It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		* a list of sub-restrictinfo args, and rinfo->clause - which is the
+		* same expression, made from bare clauses. To not break selectivity
+		* caches and other optimizations, use both:
+		* - use rinfos from orclause if no transformation needed
+		* - use  bare quals from rinfo->clause in the case of transformation,
+		* to create new RestrictInfo: in this case we have no options to avoid
+		* selectivity estimation procedure.
+		*/
+	foreach(lc_eargs, expr->args)
+	{
+		A_Expr			   *arg = (A_Expr *) lfirst(lc_eargs);
+		Node			   *bare_orarg;
+		Node			   *const_expr;
+		Node			   *non_const_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+		bool 				allow_transformation;
+
+		/*
+		 * The first step: checking that the expression consists only of equality.
+		 * We can only do this here, while arg is still row data type, namely A_Expr.
+		 * After applying transformExprRecurce, we already know that it will be OpExr type,
+		 * but checking the expression for equality is already becoming impossible for us.
+		 * Sometimes we have the chance to devide expression into the groups on
+		 * equality and inequality. This is possible if all list items are not at the
+		 * same level of a single BoolExpr expression, otherwise all of them cannot be converted.
+		 */
+
+		if (!arg)
+			break;
+
+		allow_transformation = (
+								or_statement &&
+		                        arg->type == T_A_Expr && (arg)->kind == AEXPR_OP &&
+							    list_length((arg)->name) >=1 && strcmp(strVal(linitial((arg)->name)), "=") == 0
+							   );
+
+
+		bare_orarg = transformExprRecurse(pstate, (Node *)arg);
+		bare_orarg = coerce_to_boolean(pstate, bare_orarg, opname);
+
+		/*
+		 * The next step: transform all the inputs, and detect whether any contain
+	 	 * Vars.
+		 */
+		if (!allow_transformation || !bare_orarg || !IsA(bare_orarg, OpExpr) || !contain_vars_of_level(bare_orarg, 0))
+		{
+			/* Again, it's not the expr we can transform */
+			or_list = lappend(or_list, bare_orarg);
+			continue;
+		}
+
+		/*
+		 * Get pointers to constant and expression sides of the clause
+		 */
+		non_const_expr = get_leftop(bare_orarg);
+		const_expr = get_rightop(bare_orarg);
+
+		/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table (htab key ???).
+			*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, non_const_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				non_const_expr = NULL;
+				break;
+			}
+		}
+
+		if (non_const_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = non_const_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->opno = ((OpExpr *)bare_orarg)->opno;
+		gentry->expr = (Expr *)bare_orarg;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this rinfo, just add itself
+		* to the list and go further.
+		*/
+		list_free(or_list);
+
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation. It's been a long way ;)
+			 *
+			 * First of all, try to select a common type for the array elements.  Note that
+			 * since the LHS' type is first in the list, it will be preferred when
+			 * there is doubt (eg, when all the RHS items are unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (OidIsValid(scalar_type) && scalar_type != RECORDOID)
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+			 	 * OK: coerce all the right-hand non-Var inputs to the common type
+			 	 * and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = get_array_type(scalar_type);
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1; /* Position of the new clause is undefined */
+
+				saopexpr = (ScalarArrayOpExpr *)make_scalar_array_op(pstate,
+												   list_make1(makeString((char *) "=")),
+												   true,
+												   gentry->node,
+												   (Node *) newa,
+												   -1); /* Position of the new clause is undefined */
+
+				/*
+				* TODO: here we can try to coerce the array to a Const and find
+				* hash func instead of linear search (see 50e17ad281b).
+				* convert_saop_to_hashed_saop((Node *) saopexpr);
+				* We don't have to do this anymore, do we?
+				*/
+
+				or_list = lappend(or_list, (void *) saopexpr);
+				change_apply = true;
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		if (!change_apply)
+		{
+			or_statement = false;
+		}
+		list_free_deep(groups_list);
+	}
+
+	if (or_statement)
+	{
+		/* One more trick: assemble correct clause */
+		expr = list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, list_copy(or_list), -1) : linitial(or_list);
+		result = (Node *)expr;
+	}
+	/*
+	 * There was no reasons to create a new expresion, so
+	 * run the original BoolExpr conversion with using
+	 * transformBoolExpr function
+	 */
+	else
+	{
+		result = transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	list_free(or_list);
+
+	return result;
+}
 
 /*
  * transformExpr -
@@ -208,7 +496,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (Expr *)expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 260854747b4..cc1b676d200 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1631,6 +1631,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

#35Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Alena Rybakina (#34)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Sorry, I threw off the wrong charts, I'm sending the right ones.

On 05.07.2023 22:39, Alena Rybakina wrote:

HI, all!

On 27.06.2023 16:19, Alena Rybakina wrote:

Thank you for your feedback, your work is also very interesting and
important, and I will be happy to review it. I learned something new
from your letter, thank you very much for that!

I analyzed the buffer consumption when I ran control regression
tests using my patch. diff shows me that there is no difference
between the number of buffer block scans without and using my patch,
as far as I have seen. (regression.diffs)

In addition, I analyzed the scheduling and duration of the execution
time of the source code and with my applied patch. I generated 20
billion data from pgbench and plotted the scheduling and execution
time depending on the number of "or" expressions.
By runtime, I noticed a clear acceleration for queries when using
the index, but I can't say the same when the index is disabled.
At first I turned it off in this way:
1)enable_seqscan='off'
2)enable_indexonlyscan='off'
enable_indexscan='off'

Unfortunately, it is not yet clear which constant needs to be set
when the transformation needs to be done, I will still study in
detail. (the graph for all this is presented in graph1.svg

I finished comparing the performance of queries with converted or
expressions and the original ones and found that about 500 "OR"
expressions have significantly noticeable degradation of execution
time, both using the index and without it (you can look at
time_comsuption_with_indexes.png and
time_comsuption_without_indexes.html )

The test was performed on the same benchmark database generated by 2
billion values.

I corrected this constant in the patch.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

time_comsuption_with_indexes.pngimage/png; name=time_comsuption_with_indexes.pngDownload
�PNG


IHDRv�#��sBIT|d�tEXtSoftwaregnome-screenshot��>.iTXtCreation Time���� 05 ������ 2023 23:00:58m��� IDATx���{t�����7]Y	Y��Y��%J��F���V�-b)��Z��9^�G��5{{����C�v��a��J[��J����hJ�[�rkR�	�,L���	J H ,y���a����|�\k���d�����"I�$I�$I�����Z�I�$I�$I�$5���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$Iq�`G�$I�$I�$)N�H�$I�$I�$�	�I�$I�$I��8a�#I�$I�$I�'v$I�$I�$I�����$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$Iq�`G�$I�$I�$)N�H�$I�$I�$�	�I�$I�$I��8a�#I�$I�$I�'v$I�$I�$I�����$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$Iq�`G�$I�$I�$)N�H�$I�$I�$�	�I�$I�$I��8a�#I�$I�$I�'v$I�$I�$I�����$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$Iq�`G�$I�$I�$)N�H�$I�$I�$�	�I�$I�$I��8a�#I�$I�$I�'v$I�$I�$I�����$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$Iq�`G�$I�$I�$)N�H�$I�$I�$�	�I�$I�$I��8a�#I�$I�$I�'v$I�$I�$I�����$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$Iq�`G�$I�$I�$)N�H�$I�$I�$�	�I�$I�$I��8a�#I�$I�$I�'v$I�$I�$I�����$IR�zw%���
���r5�,(z��������m#^`���\S<�U0��_p��U'�vc1E��xw��R��<&Y@I�:��1k�Lf�����l,�h��,>�W,V����`r��?=m�KG���m7���Ez�$I��XBk I�tZ�*�s�<l������x�(���tB�
f�[K�YW1(�8�ewfLQi�g��c���[�Yb�����)	�P�uk��t�9�^�C�<\=�e���}wd��R��219���i���6�,�������&�����G�$I�	�H��sB��Wq��2�z-1t����������D���)������k
����a��\M|	����&��(��>��T����Ng�Z:�
�$I���`�#I��
���s�X�����n*%{�7�80��u�L�����}�q�@������cKE�3�y}n�9��O:����e���2�wC(7�~?��Q��<����]W0k�/��a������M�K�zk)
&�����0���=����yl����o�G$���8��7�����
���
B4�����f����C?-�����51���Zm��d�2���>��f1h�P�
;�YDf��}K�)��D����7F�'�q/�ad�f�"��Q>w���JyeRR�zM_�{kg�����|!S�`���)����o.`�c!n�;���f������k8�=e<���(��U0k��,�
0���^N�a4�������%������H�~�|`�NbW����/�����E#��}�/_`���L��y����]�K�tOor��5�`)��P��A�-���PU�.f��=��H���Qw
bP�P��i`������d�,��y������f'���2���l�TK}Bvc�]})�<|F���+���f6m�Bz:�����)G>��w70�gkY���hB���=���)8��YF��(#�Og����Y�.+��~r��q���c_U����,Z�: �{g���r��G��V��36��"Fr�n|`�94_���O-c�������E�[�2fD�'�E^_���x���]R��nn�'I�$�.>cG�$�S!��H�d�RJ���J�=XJ������p��~M1�O�$��o���I��?������������_c��1?4�GM���X����^����7���'
HM�a���x|�$_�(��?������o�g��z�e��&�n8��V3��L����SXU��U�f���r�_�}&	�:��C�N��?�B.F�S�2��#��>�/�>?�v+�^=�<i��	n���7�7Gr�����������?����}-�<���y|�$��:/c��u�+#7���*"��=��r��	�����I<�|�'���r���&�	�q�'����������Z�?t#?�5�c�1�����Rr��o���|��~-��uXZ��;�����
&w�J�����I��'2��#�^������J)9�kT��{�`����I<��x&��0{�2�G�9u(��V3��
!S��K��)�����d�=����*�-���o���7�������)���y��2��w?]�}~��xe!�?�dL��d[��R��������X�����A �2�b����6�\����O�����hL�7���X���,&����������o5;��������]}�jS����nv�P>k3��t�����T�?�*��������������%����$V�����I�$IjQ;�$���������G�|�y�&;�	�+x��RJ�e�K�8���b1����a}3��7�C]{0fl��m&�`�{������B("w�`�<��^'��������=R���G
��mR������ �WGRC���1��b�{?��H}���o\o��E/�����d_��a�U�����#�F�2�����'���B���B��u�����7�l���g���+���}VN&��(;*��
���<����;�EI��q$�8��6�Wb@B��q�3��D�M(��H(3�+���~s��'�u;�&���<�M�j~2;�������X������^����@b
�?(��EC��Y�*�+n�An
���-�F���P�H(�q��~�B�/��3O���h0�'�],���L	5���B�&0���#�x�{�x)�F�I
%���7��� F�Nh!a���;�8�p"3s��?���"�m4f�B��� ;��sP�U5��3&'{��:��>9���@����Hp�n��J��v�����a�����S��7V�����{(�m�_�}����O�WtE��]9����P���t�/�$I��S�Vl�$���=n$����;�������������c���[BD���]���������� \���U�;5^��H��O��>C�3�T
@�P"k\b�������������o��Bvn���5��u$���k��|�LK]�W��2s�������?��+/� ���H%;��M�Q�c�)�%��h�?��<FN�~`N �p�E<����Z|�D03��FC��E��pv��}f:�G�(����s��s>�w�]�ph�P�{_&M,g���O�����K���n��?����g����#�Fv��W���_������G�NJ���A�~��j-sfmcKy-�������&"�����'7�����=P�c+�<������j������R��|��`��������(�=D*c���WL���C�P���]����j
�
����%I�$�4�I�tn�� ��	n�W���U�cW�����-��;�Nk�-�������~���$�97�O�u�\1�;��RF��rJ����S%��7�0�9!CC��l[[6�O���t[P���9D*����X������a��C�#���K�a���m���:v��B(�����%��IU���1�������n�6~?y5o�`4w�|(�;p�.��2����[����Y�P>�yZq����f��q�*�w�Vw�s��Y����~vC����;�@�?�=�}&
i~G�>bG�$I:m��M�$	�.���WS?n4wOIb���X��VE!�;��%r�s)��j�>����:�������Ful�[��U'���3���%sLj�Q�����!k���Gc���1h� &���kb,{���+1t��JtG%�B��<�^}���
"u�d�����-"�#���w����?��A&U�mj|����]G���|�g�d0��#)�V����N���h�`f��c�0�z���#�_���@
�y�^u��p�W�e���D��M����A7d����[jZ�Y1�����P^�H�q�B����g��mxH��5�Mn�3��2���Q����^���~2.iY!��i�]����}��$I�t��H��sCu5�������;t�1�����|�Y��0�1�[y��m�n��6�"�JJxvn�(������y9���@��M����,{���X;�,f����H8�gM�$�.�ty���D�TR����X����'�__{��'�������V�vy��}v�-f��]srk1��u�����&.����@VE(+?pR�P�S
l����<z�@��,�/�F$=������m�u��1>�$B)�wm[+�T���|���DK�?\K����'�]
d�kP��JX�+F}U��O����;r�6���X��]1�����7�����C��*���+�z��u�cB�ET�X��wOb����<t�<��98�E���r�m-����H[��9oV������g��d��! �"-��-���/f��IPS���\���19����e����2oI-�D��8m����������2����O/ $@�Gj�6��46L�w��_W��,/�?o|���NJ��Gn�V<!�Y���kNm�$I�$5���$I�9a���Q���^����s�����s�t_rR���}Y7�-����Q){
`�~�������������6�Hp�{��La�~�������{F3�����kc��������@�PV��Cn��63����4���[g��}S_*l�%��~ZB�-W3��-���+f���/wd��W1�S�^�E��z�P&�����~�� ���L���c�&s�6\�K6@�\��n`Y~�����,��7�^������i ���g�3�+@���}Yq�j[B0"������~>�)Y���L)=j���a3����<:=���y�F�������>=L��z�o�2"�!)��j�/��~��X���y������	�jX�`1e��r��C���3�Ic��#����W������^��������,��AB�>�L|��'[�����b~���QQd������q��3z2���N�5��C����K���W���$�|�����u�1i������33�����!2{p���	��
����'���X��@G�
�a��_��"Fr�&����c�t��,�>>���Y�{i#�C����R��?��k�WA07�~w\�����n����G���<�> {�W��0[^�5�Kg����$I�I��l�"$I�$I�$I�tb���$I�t���`�=k�r���/)d���3W�$I�$�"W�H�$I�$I�$��/�v�$I�$I�$Ij�I�$I�$I��8a�#I�$I�$I�'Z����Q]�j��dUIg����T��������W)~8_���\����UjY�%Lp��t��E�$I�$I�$Iq�`G�$I�$I�$)N�H�$I�$I�$�	�I�$I�$I��8a�#I�$I�$I�'v$I�$I�$I�����$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$Iq"���$I�$I�$������<����H�a�K��"����X��bf>\���:HJ$����{bz����b��q��;��@k��v$I�$I�$I:�ro����T1��?��;���QgKBe�/7�o�h~vK���,���$I�$I�$I�-V��.&���	�z�%Q��/����P��`���,�P��}�tg>�P^���#\����T�����QC�<%�@]��.a��Z���W����P=�5�������Q��U���
�&0qH��|	V5�M�^��Rph1O�s����w)�����Y#�O��q5�������(��r'�&�d���|�����*�1{�J���  ���L��P�������/��]V
����?�H�zy1���6v���n��+�	����~��q��Yz�Z6���~�P��O�^R��'��$���C�86���,`�#I�$I�$I��[Y����7y�{�;_���&�o���K�����B������2���a�����������������bA�����Z��7,e���L�@�`��l
\�m3�	�����W���1�l������;��- ���-c��z^�B���xxT�o�#e���a�����:c��zS4��@���^`�c����<�@j��Y�3����p��nZD����GwS4��	sG�W�<�Kb�Q��{�bK�����,�Ue��y!���g��D�o.cvI��s�P����X| �yc�k3�)���op{�D��]�C�������|9���M�~�����N��s��W+#���L��������_�K���x[��Z�I�$I�$I�N��X=���5��������};n����b�!�B���	�R>�:�����6��T��
�cTW�9!!L�Q�V��d�}^����]'���,]TIu4@�
C�pe
'��zy-����ae!�]����;tNJ"�UI\zG�#�N����-�Pz�����$J��5��������������6"���wR��DH��OAJC?�W�����*�U�li��+�4$1����m�VENHJ$�XKx�u���s���(���G��:����
��P\�#I�$I�$I:�������}������?n���!
���WtS)sflbk��<FxX�3���lt�?4b(������.��{kI�S���0�D��I -�Q���H�khcS��;V_���Co,��� @��em%���^9|~�F�'���Z��6JSRI����a��Z����������a�7��r�C�hf�����Z~7y��0�0a\�:�5�H�$I�$IgP4��?���^�/!���?s|�/��%�df�[�:I�.��k���)f�5c(�)L�(�������&�e���5U����z,L���'+B�R�����}�!���9�����$�����hc�PrJ���9��(���J(=	�D�
+���w�e��&�Dw��<F�1�(F������-�����u�����$I�$I��3h��ulX��*w~�����)���<3�I����1��t.�#
��A�n�D��uu��(��23�TQ��N��	p��AG	dp��$6�TJ$����b�;����Ii��K�GX�\���X
o?��y+����a�����C��W4�������k��4�U���������57�73��e����5��>������$I�$I���uk���M����g�u�����|�?/�[�{�-�������� ������K��	d1��1�y|6�p�\}KO�����t�:�y������}�m��9y�X��`�]n���/���kH��7�n�iF�Ia�=C�;}!?�6F"R������U5�+0��
f^�+B��^��k�d�Y���b��?OQ]S(,��n=d�1x�6��i6�I�^?�q]?��lym<x���hI�����y��Ij=Ym���Qk�!���R�p�J���*���1_+w�������]����<���vU�b�R�{����_f��+i���Ek�����&���t�\�#I�$I�$�!����{�^'<�}�,���o���(��R�-�H0�x�v��/6�I�$I�$�8p���@R��\tqA��e�>W_s-WArr3�!I�Bs��$I�$I�tl~wu��|���jo�#I�I�$I�$����u3��m�>���mkV��@}�i�_�tvp+6I�$I�$�5z�]LvN������l�6��i1��������B�N��$I��;�$I�$I�rq������\7��
���c1V�y���L/|�ht�i��$��ks�����]DK��.�5u�]����hK���Z�I��|����U��U)~��|�F���e����|��W/��#�j��$� -�`�k
�S�Vl�$I�$I�H(�������C�`��wXS�vU�l��$I-�`G�$I�$I�JJj�e}�sY��n�&I_ �{�$I�$I���B�v�]�$�]��s�l���]�<3��$z�]T���m7���s\�T�6�����5�WL���l���W�H�$I�$I��W_y���;����7�N��d!%Y������}-ON]����L���^RG���r��� IDATD:|�
N�mS�#���(��~����i;�$I�$I�i����df^�����]J�������u�\�gz_r)��$5-��+��`���bc�+( ;�U��Q�<2+�a�be���b�~:����XP�>�"n{i`]1����u1�����g���I�1��.d�S������*��+�;�q�N����'G��;6-�boE-i��2yJ!��
�O[��
u��Iw������of����/�r�n�#�D�Qa��KX���`�|�������m�1��$I�$I�N����x�����gp��SZ��&���Oe��U�)�k��f��5t�J�
Hff��K�Z��5k��_�����/���/����������M�������k�x��*v�g��u������1�� ;������nSF��GR6�������|!S�T��J���
�����P>�U��A�f�
V����u�6#�`y	}{%������u�[,�r��R�63������IO5��b�=K)2�����`�Mo�L�xn�6'��k��������J�����tU
=�L9���~;�$I�$I�iP���|�����}Ik�rB��!�6h_4����a����u�:��a���c��G�v��)������{��/���������������/`�i��Z01�:���h�L��P��K+(k��q������ty���$��7*���9Yd�W�����:�i�@����
�c�T�B�+�_E������p�uSr<"�#�+��6����#����tQ��g�{�&�ZEq�`G�$I�$I:
��{�6m���W��.�����Uz��*��6V�z���+v��p���3x����>??�����$7q�Gk!��'O�
@���I�:���OI"��"�P*i�������r�`�� ���936�5		�_#<�$<��(��$�������D��Z�C�g<B#�r{�j���B�����>���
sZ������$I�$I����|��;*������[����;s���[����i��6m��Z�`~�5�(���C����5��l��N~��`r�`M-�c@�V��������X������1�&H��Sfsk���"5aop��8�#���Hn|^���H���2v�T��co0��0������>�}���$I�$I��h���hX��E��k�����O��{X�D);�}w-�^�����S"���������c@�����z������h4@�kA �q%�c���>{j8p�����G��V�����E��t���K��^f�����)�t��'��)�bG�$I�$IjAd��u$�mK���v9�UMu53�y�:sY������+���d������%���)��H&L<q�X�y7�������##6@ ���w�����7W0��������L�piCp�����n �a?��������)�{���[rx��^eN������>y���L� �S�x�/��]|����w��{��p�?��+�1@������}�m��9y�X�N;m<x���hI�������'JjUYm���Qk�!���R�p�J���*���;_�ny�?��y.���+��8
��=�|��-`���d�/�������J:y�%Lp�3"V��Q�?y=c:�v1ji���$I�$I�ZP��q�7���yAk�r�e�>c�q��?X��el���x�e�,�o.)�������3���R���^f]���~C
����?�������I���R����U��W)>8W���|=yU{����?�q�Zb�W��}��vY:K�b����+a���R����p�
4X�"2���*��c)~8_���|���sU������kX�����%����e���`Gj�"I�$I�$I-���R����:���={X��Z����3v$I�$I�$�q�uu���et������4~�@vNG
��������v$I�$I�$�q%�W�t�"��sY��t���@ ��e��v���������w��}�.J���re����$I�$I��3�+�{RSS�;%a�k��t�".)��K.�Cr�|?[}�{7��u��o ��L]>���}��+��q�����x�w�LZ|���S�$I�$I�`W�N�������������T�>�*�6�rV�]������e����D���0p��;/�����|�K_�l�6R��8x�{�j���sN\;�W�����]�$I�$I��i^�'���.���.��}k�WB�v������ V�e%Y���k�0l���.M���������:wm�R�sV�;�������KekW#I�$I��s���Q���.�i��:� )�-_x9}�`��J�����g�����8����du�&!!~ou�C������<����H�a�K��"����X��bf>\���:HJ$����{�Y�
qc1����o�B�9�8����n�o�Q�gwTP���H�$I�$��U�q=z�%UKH�������o���{�����w�&'����t$;����}N�{��Q�G�o����|���:�'o�b��`�w�������"��_n`������,BgKY:��v����%9����*>s8+�m+%�d����*�	��?��R|p�J�����|�_i����!HMu~�m���wP����_�>eee����������ZBBB?�IQkW7�����}�6�����m����r��h��|�����%V��.&���	�z�%Q��/����P��`���,�P��}�tg>�P^���#\����T�����QC�<%�@]��.a��Z���W����P=�5�������Q��U���
�&0qH��|	V5�M�^��Rp(;�~n�����!e<�x;�b���	�=��97����C�����l`uy�o>=�~�@�6fO[����^;��7�9V�����%���J����'iT//������: ��-C�pe:A�wWr��3nz:K�_��������	�K����6"1�$�|{�����0��a��������mb5f����lI�NZVF[��'��R�p�J���*�����v�f��r�.���X"���gNB
.,���\�5���c��
**�N]m�q?����[�����KI%#=����r������e�;k��������q���O�]������i�o�iI-������
��\����]���_��+j*x�oo5y<�mW�_��d��W��_M�)���#)G	[g���X!��/ �j33nX��A��40��������f�,/��o�d��c���3ow��[@*1��[��U5��2��QW���*���G�&~�)�/���u��U��hn��(o����2��=y��N$<��gb=����tI9�������(�hz��&��yV���7������>Ws�Y���u�Bfw��!�D�\���0��� %J�/��@^��r�f�SF�����>������&/dA���	�r�U����F=4�)���X%�<VF����=��1�?�)�&L���y��_������{��{6+8@u4��q/����\����I�$I�$���a�;����V�D��D�.�D���Nxnuu5�����^Kj����4R����3x���Ti�����yk���w^
�v"7�B:u��y����u�������m�x�`����W����;���s�� DZ��{0aX�gV�t�u<�b���,�9��(����W !L�Q�V��d�}^){#@{ ����tQ��g�{�&4��X���k�vkA�� B��6�����-����D)�$V%q����:��S^�B��O&7%������v����0��j�9=�a#yd�N���QV!��p
R�)�2��U����r������4$1����m-�WE�)I��k	���N��w. �e�+�Q�BA���{�y�=S�/�i���o�8����<4��as��_"|T�z�I�$I�$����
�	&&rQ���.E'!r��}����}�>d��}���!��Uy���;Y���RRIMM%%5��	DvU�d��Jz�j:ll�6���C��2�?�V��|y�
�<�V����9��&����	@��co��T��������/�>�k�@0t��`����C��f5o�v!��[KZ���p�'\(QK�&���F�-#�v����Y��t���W @0��Kj((�j�_[�����W�;�Q������v���JI$����Z�q$������8�)�����:���'����n�2"Ia
'`��,�uvk��`G�$I�$I:8p�K���M�6$$x�-����2|�?����*����G��d��������J�6m?����c��J�&�%5-������Q*��;;*������sG�'��u��O(��
���������$>�^Z	_J %�x�cD���)f�5c(�)L�(�������&�e���5U����z,L���'+B�R�����}�!���9�����$�����hcX�S��Wu$���D�h�UB�I�'�> �({�@Z�������9y�*�cTQ��5k�y�[,�=�17���]���}o�^�����$I�$I�9&!!�>��vjai��'<'!!��1��aM
~X���*jjj�����/o��z^��l������D�v���];��;��P;�m ����d�Y�|��?v�ZjZ:9�LNNG�
���F��f�7Q�9F��X�Z��z�WB��4.�`J:]�C$�p��AG	dp��$���R"Cz&��/��8p8]O�+��3�v_���"��9L0V��O���P��O$�w�Omf}M=C5�=��z����P�Nt{d-��|�	�$R���������57�73��J.}`=��v�$3��Or��A�;�$I�$I�t%$$pq���R���$����#���QW[��vr�O���m���F��m�����t�2��g�FQjq�,���3�?��������o����z�9��c\��7�Q@��7���
AP0'���O����#��%<:v-���f��9�h{")��g({�/�'��H$@j���X���&t�����kE�}���;�am��,2��U����)�@b
�E�y�����<���7�fv ����2���}�-�����v-�������l�����=�v����*�����R�p��L���C�j��������_.HK"����.C�{���$I�$I���@�vl�]������$I�$I�$IR�0��$I�$I�$I�;�$I�$I�I���m�$I�0�I�$I�$���m�����������H��Q;�$I�$IR3mX��
�Z�I�9�`G�$I�$Ij�������&�C!:w�o�r$I�(�I�$I�$�6�_��L���i��Mk�#I:G�H�$I�$I��a�Zz�.l�J$I�2�I�$I�$����]���I���d�~k�#)^����;f3u�/������l%����z�<n�q%�������)�o.���b��_P�Xe���$�v�$I�$I���D�A]m-9�|���~�;�����v
I_t5,��BJ����/"m�Z��������4,���������t��J��G��P:�7���U�v$I�$I��V,_������g���=���R��Z���9��/��+�[�_I��������
�Nz2fT)���JtX�X������&8�-�D�O���^BAXW��?,ew]�hvo�����~�y�����T%�)!r��'��B�N`\��-/���.�N�MK��[QK���L��C�������hC��G�e�����>$����3}%������[�H8�x�EX���� �9�qE}��y�u��v$I�$I���\�u������/_J���t��H�=)����m�O��{P��GT+��l������&�_x��\r�%M���������iii\q�M��V���r����� �W�3]d�����W�m�h~�H
������>�/d����|W)s�C���g��#0(�����������f�,/��o�d��c���z��B��_@j�ff���y�:3i��&;U,�g)eCFs�a�5���
��������}��y��s��R�Q��2������)�X���`G�$I�$Iq-%5��
���
���;*���
l����o���7_g�����]��VVYY��5k�<��M��;����m��C��;��AR"�7]& ZG!�Bm��	�>��@}ie�;3�[C��;6�.O�4���0�F�7\3'���J��C�[�3-hX���CA~���Zhx���(c��0�n�nJ�G�xdy���<�x��`�v�.�`p�,ro��S�(n�H�$I�$��Cv�s���l����n1���e�]F�n��<��|��}yyyL�2�����	����!N��h-�Rhw��t(�T�P�a���$�/�	��v����I �(�	6J��J�3c[#��p���1��N��c��RH"-��K�I���e?4��q�#4b(������.��{kI�S���0�j;��H�$I�$��v���?��=_q����v]�^D�����$��v����]������$���N|b��a:�l��
�;7��/ �q8�-����5��� Z��c���b��S��k�PtS� QO��I�jZz��X��U�������LO������H���L;j�x��7��X�n��O�}�����H����;�����WD�A�`�E��lY�d����%�$�d��$;�3�3{rw����{�w����{s�g7��8N�����E���bK�e5R��;	�Wr��M[�R�� ��sx(����������Q*�XO��I����of��S����q��S�z<�>���:l�p��O{0B�����$���t!B�hA��>NHb�w�Ld"t��E�H��\���$b��gOH\�x*�V��:p��q�����Bh�e]����_��z��j���SB��l�|�;DDDDDDDD�"E���7���6���2��������!
���o���o�d����--�����e���}���i���'�a�����[��wM:��7^����L"�io 2`��8�{k[��7&�����5�9T�����
�b}��@'�`�����O���?�AQ{+��f)��__��U��#��^��
��+���EW�����i'����v�����H�P��~|���{����?������b����?�q��(������:D&EbI����O$"AYr���c�p���W����J�4�HO?�K83�VU�s}bq�>�<2<��+]����Db�c�u5���{�GQ��t2H�\D*'�������_��*��P�q��
��_�N��Z����(�E�����������G���!X+�055�3�Of��DD������5���~@��0EE�-8e�b#"""""""�#���O��7��o������b���mhnm�J���������hy4���&���������c������jFy��""""""""Z1�	ZZ��L&�s�nA���j������h������7
�r��""""""""ZQv��K�DDD+��!"""""""""""�,��	v�������������;DDDDDDDD�s/|��!t""�����������k��������(���@DDDDDDDDk���/�������x��/���(���CDDDDDDDDY7;;�W^:���](4���}J�J�XDDDy��""""""""��d2��#C�(.)����"d2�������;DDDDDDDD�U�=���FQY]�C�{b�D�HDDDy��""""""""��
��@�T���?������5v��������h���&
QS[�����f446�0����-���f�6��cll�c���b�
�v���(sX�!"""""""���~�8�*��F�F�����7���*`:""����""""""""JK.�c��*�5����V���z�A�hDDDk;DDDDDDDDkH �������������,�^/�����}$R)����C���0)];DDDDDDDD�\<��~�o�y=H$�=g��{�T�R^�E""����;F\� IDAT"""""""�<
��z��z��y���Xs���R��H��D�0����7����k�\R���(���CDDDDDDD��~<��Sig��+��w��g��FDDD9��Q��BA��N�\Nx�.$	��{ ��r���zC!�:�Z=t:�:t:=�:]���X�!"""""""�2���wN�������D4��],��-���b������IDDDy��"""""""�e
�������Q�����9���E�No@iY9��L�
QXhD�����DDD�����r���u/��F8)B��V|������Q��].��6���a��`�M#������V����-�r����V�<,�$1��1��h��?�
��������[�GDDDDDDD���6�'����S�T�����l��R��5X�!""�L��� im��u�Bzl���g��#@*p6"""""""�~�N�"��ZZS�g����fK1Lf3��b�T�&%"""����*t���G��!�t��������JDDDDDDDy)��n��l�J����5322��	�c�;ff���b�R����z���eXv>����<���"��{��A�B�� 0-��`�*Q��x%��D��c���������b��}�S�;88��_�M�v����|��)���0^=��5�,E����/���_�38^�2kvvN�D�������Mq�
���7�Rr+����AK���	��a1�ass�Q>�x%��D�a-��D"���a
b��~�w����?�X����W.�lW��X�aS�{��x��3�ju(*2�Xd�X���w��X���(L:$��c��<�
�������;�V
H����:��buh:}���~���_s�ZY���zTU���hL�_o0`�m��}�D������DDDD+EvD�~�!^�$�_�m�D!��:Gy��8Y�������h�1���hu���EuM-*+�!�H��EDDD�w�����m������y�4�It-5x�����KDDDDDD�;~���������{�Ky�X"�7���9LFDDD�:�aa���C�h�!�s�1�X#�C���<n�B����Ao0�����h�������G^��� �����
k%*�j`��bQ����(X�!""""""Z#�

��oJ�*e�P0�����TV����b1�Z """�%��EDDDDDD��X,
�T&t��y����F>�;�B��^o@<���?��/e1-;DDDDDDDz������a����r������]����6�����rallc#�����7������~��D"�T*(Uj�T*�T��%"""�L`a��������4���������!���l��_��H$�������
M0�"*|^/FG�1:2���a��6�T
���6K�����IDDDDY���Y��s��:(��b���i#�x���C���mj�N��"��
���o��l�Z�g�y
� �HPY]��
�J��f��DDDD�r��CDDDDDDk����}.�
�w������E��%l�e~��x,���!��ah���>��/�[��a�ro���xVkJ���v""""Z�X�!"""""�5�j���tl�����
�L~���H���oD]}#�n�!,���"�0FG�11>�������<w��[n��D��D��D7�s����;DDDDDD����k7�[��Qn��l��a���q��HUFLOMa|l��B�^��h&"Z{f�v�p�l.���Y&"Z�X�!"""""�5G"�
R@���A�����R���
�Z�P][���CDD�vt���S�I��Q���CDDDDDD�#�l�-u��BY���Y>DD7���c8o{���.l)���\o������R�r�"W��(CX�!"""""�U��j7��[���&��\C"����c��Q�h���8��,&�PH����a�k�i�|h{�m������a���%����s����n;DDDDDD�j�}>�~�
�C�R���Q&y"n<��K�~���8��(4R���vW�C��g&O�����p�,�M���6he�$'"��������9|�����I$�q������	��(��R
db9*u58Psc?����h2���}g&N���y\�9�&c�T��\�%���V*v������(�MOM��+G�t�@�P`�]����A�XDDY'.��|S���Qgh���������E"���""""""�[��/��W��:6`��{ ��
I"Z;n���i��:T���3r=""�v������(oU���\\�=w�GiY��q����R�:-��""""""Z��|^/�^|^/|>/~?x���}T*5����r���hm�`?�D�zC��Q���,v������H0�XO=���z=H���='	sy5"Z��8/��u��.r�Jb6��co"��� 7bG�.4[��ED����CDDDDDD��095��D"6o���\�T�H$�N�N7�]����:�:D�f�1�*.��A!V��@'��G\ ��t|�O��y�{xy�w8g;�;+��LS!h6"��d������!2)K���	��a1�asG��ADK��J�?8^I(n�SS������3�k����X�d+�*Q�j���{S�	����\����jr�#_��c�/c�;�54`W�]0(
NF+�I'�D\ t���;DDDDDD�l�x����y�1�T
�����%%%#"�OS�	�����j

8X� �+�-<�L�����o��w/L
3n-�C�hDD���{U """""���r�P����b�6m�L&��R�������DD���xs�(`G���Q�K�D���7����M����B�!"Zn���D<&�D����N�b�/�u�5fQ�Qn|�7���'_�p����C�P���g���$"Z�&�c�q��A�����d�1n-�L"�\Yzag����S���a���~������g�)�����-,����o����A83�W�T��oD4M[�!"��8P}\Q'��b���
���N����xO\�����w��Kh����q�1����~��>��OM���DDDDDD�I��p{��y=�y�hm��T*Ky��6�c��R��������e��t9LMDDb�d�u�\=H�%�dl:
Q�[Za'9��K���v��H��[�H�~mQB%n�Z�����&�q�Q��s�m8ff���q��D�i/���l�����C�h���IDDk���c��|8o{wU��jXDD���;I�bJX�?t��|5_+���S�J(�~��������h-q:�OO�f��c��G�����_������X,�F�CqI)t:=�Z�Zt���aQ������-_��#�����'/��E��e��D-t4"������:��1zC��,�m[���2��O!�")������V���NLOOa�>���)$��~d����-�<��#���P����J���I�7m�R�:JNi�Z�W�&�cxs�(���������[��x�K�
��h�[�OL����x�o^E���������>��wN���������r6"""""�r��[��}�Dsq	��L0�`�X�Qc4�"&��D2�#��������> t$A�i*��m�@��N���w�O cO�~����%��Eh����gp�w��	��u+��i�����V<��uPf1,Q�H$���`������8�?�v���D���^���DD��x���4��iTh+���n�#	������8;y,[��CD�W�������E|�����D��H7'K���	��a1�asG?����J�?8^��`��0c��f��������������Kq��)i��X%�������<�@��C3���
�d(!Q~1�d������fed�JmC)��&�U���I83��b1��%0�-0�_J���V�a��=��l����N�^�#���	�J�e��9���Xja'9���}����'������F��CDDDDD���6
�����:(��7�nniC$��\���=o�����_�
���=�Z�C�D�i�7�cC/�J�e(U��D]�bU)���:Q^Y�;EqhP���M�*Pb��iJXY�!""""�<�Ea��^�g�n��1���Y�>������o�~k��Q�(T�f���M�����Ru9n-���qL'1�����w�}K�v���%`B"��[ZaGd����*v�����{��O���R���m���E���CDDDDDy���atx��c&�fK1�f,��CDD7n�A�#�=��F������S�	L��1��F��N�h�Y7��n�7���{�:���j����_��	�,�[�H,	�?&t"Z7�%��D�������
9d2y�s.]<���e~O�������p������������F����r���Y�I'�D\ t��wc�Pz8��U�:���a1jvw`���S�!""""��)���v��p��r��t��r��v!�H������=e���s�����r%���=8���*�m��(XW�Jm
J5���/��(��("�$�$��
)�������K�B'�����$��0-�����N���?~/��C�a��G����V�h��������h	^;�2z�t~�x����B#Tj����h-��F!-�	�R��r/v�����&�����c20����:��H]��vtb�;�L�L�L�L�L��� �^W7�N�F$A4A,���������K�?1��;��\�@��z���r,q��='<����p��	���uN�Z����`#��!""""������t:�t:`).��X�����:H$Qh4���:��x���������[�����_�V�:� I`�U���Z8I��������Tp����m�H��Z�,[27�l�)�C6���(�T���9���D��r�Z�r�R���b9J��g;��������X\pcH��-m$�Jq������b�)aeQ�����(o%�q�=n�>x�n~�].�=p�JU�~=�W��y!�!������E�D0�-P�R�q��z1::���cN�~�w���;��-�4�����uyO���h��z'��0�F9;�E.R@�P,z^�y#JT��}�J�0;7�������.h���?r=���L=���a�<���lp��p����'f�i;���0s�Z��f�%R%*�YQ��,DDDDD$�g�y
��)D#�� �����-�tu^���`�������|g�9u�1����fK1�k�yDDD����Q\�}�H�C���B[)t$��"�	E
���O�'����r���^?�M�Qz�����Q�N������*�Yi��R��0g��D�=��FDDDD�
��}>�|^�~l�rK�����BQ�Ph�V��V��N��V����zS\�u�]l��D"�d"�D2���H$0�-i���4���b)���K1$Rn�KDD+�K���U�h�:<��
�7�R�����������������x07�~�������V��Z��Z�A|6[pS�	Tj���|w����:�k0�,7U�"����""""�U��c�b6������g������^"���B&��].-���i���\�a�o����DDD�KF�B�3����*�C�_�B�:��L�L�
���.{p�����%�����r����!�����*048�d,�$$0[���j�����j����Xd
�B#?mLDD���w��Q4�qw���rbc�V�6"���!��`],������GDY7777't����?��^w#�����V|��7�IDbI��1��",9l����OD+�+�p��iLNN`rb{��
�T��\���Z�	�`��<�Hx|m%�8^G�������(��t2H�B� �{y����}
�U��{5J���~�S#����BG#""""Z�P(���qLMN`jr��SH��������N���h�T*�|����([X�!"�� ;I�����@����V=�=�AVp{U""""�G���7����
�()-CIiJ��oj�"""J/1��-8�P"�zC��q��������{7�b�q��q@��Z�|"����TU�����e������CDDD���z1���S�	��1�Y��
v��h����������W��h=��7��]#����
��.c����kHy���[s����hm�$����O �]s��0�T]�
7�'"��/;I?���+x�J��?nC���&�A.\."ZQ�:�U�<��J+I �Z�:��zzzp��y���.z�a1td���D��c�HHri�(TXQ�.G��e�2�������J�Y��sBG Z������h
������<���O:P���%K���	����b������D������������K01>��}�{�B������gN����h�T�������6X�K�����(?p�eV"�th
��IL'q_�C�6�+Qf�t2H�B� �{y9c���1�b�?�Y*�B�!"""�l��E��.\���pL��!��-����Q�-�����R��ET@$F�����hi�@Ss��ksv""�|1�Br6��l��$s��������L������;��k�V��`Qe�DDDB���N�����s��t}r�\�o?u�FDDDD�p��y�|�MD#������hniCSs+J�����y�����?.�TU�.��f������P���D��{��`<Gx���x#n�a��l+�-e�1�~��d��BE�������d��<�6���m�~-u�����d��d(R�`T�`Q���,�IiN{}""�|��Q=�-J�I�4
e�T"E4AcS�[PW����Z��}����@?��S���q��S�������=XV���+hjnI{Nsk���MDD�+=�.�>�
b��u��Rm�����P����!^'��@q���B�1m�H�[���x�'}��!��q��|��[i����V��+���V���?����Tz�M�SRZ���2��m���0�����A��/�)�S������+��E�P�T��V.+Q�$�q��.��N��j�k�)��A.V�\k�Ia�Q>?�e��\�4��-?����-�FDDD���CDDDD9��1>6�v�X,F�~MU(�himGKk; �Ha'����ah�]���r:�3I$hm_�J��\DDD����1��+��+��+��?�]ho)�H[��/lB}aS.�Q���CDDD�����(z�v�����������_�%�jM����^������U5�hm[�����
NDD�M��n������~��s����l����D]��="����(���B�
���W+�J�k�0(�0�
Q�M]�!""����:%"""Z���^�Fw�e�����_�
�������`jr2�r�2�2�2�2���0��/�2>6���.t_�D<0_(i�� HQg)�b1j�`�V���
�R�HDD��/��E�9t9.!�����vz�=���J�.��vz�]8>z������������/����X��d7#��|4��	W���w'�
��bO�~Vm�W��B�E
���-]JDDD���"""Z�^{�%��q������V�897����+]��se�X���P(�����h�W��D�r9����i�VV�-��|�E�\����n��������ZCc3���AD)�f�x��t�7�V� t�I��n\��Q�0@'3`O�N������^���)��rC���
#�����z��z00�����{����I��G�����'�nG'�{�x�3m���d��z�a��HDDD�;DDD��

�#�jw�*���������R��e����p��qD#��R���F46��P���3����c�p�H�hzC�7�$	�Z�������e="�OsFx��3�F�P�U);�d2�<���Fy�qt��Ba�L]��%�PgH����E0*��}�*�z� IDAT]-�t�~�����/��S��]�xm��GYL���(R�`P!� )�.�&I Z'�UW
�����2#
�F�%+�DDD�2�����:D&EbI��1�c�",9l���1�h	V�x�D�Y����}���N����*�t^F���c�B#�[��}��lGD��.|x�}�74���Z�N�H�+m�eJ���Fb6�[���������G}�E������R������
;����@sQ;6o�Yi:�
�
����#.��N�g�}����{j(e�Z�D�f�� �(�q��h�Xc�#���f��k�}^�����oD]}#b�(��t���ELN�����U[�ijiESK��1��n���7�����������\o���uxg�m{p��Ah�+sO���Pa�w7�9��������U[��8�v�u!��,������"?�D�?��o{���$OI)��JTX+Q^n�X"Y�u�>\n���}V���1�tw��q��G:�0B�W�L�&#�}�s�
C%Q���/.ifG$���#p�B&�c�A��.	!�c���q�B[��{�N���hC����J�Y��C���CDDD+Z]}�b1*������D*��u5Z-4����v�\��(+���=���r���etu^��7?CI,#�e���JK�0��YU����D��~r�����e�9|���M�������O�x2�nWz���~t��s��q���3�l?���������Q�X������Fp�������]��Ny^eU
*�jr���{���V�GsK+ZZ;`(,���/_���/`zjb�XUM-ZZ;PWW���JDD�@#����?B�����L��U��2p������-_�BRa
z�����UW��1�����WO������Q�0�Pn�QY���B���2xz���{���"1��=""""Z2v���(���g�=�h$KI��qR��V��rbtdg�=����FqI�[Z����\��5����G_A�CA�����j�&e����������--mhln�R��O�����{�P�Ux��1\���QQ��T+��]z��P��@Ca3�
MPKS��|��!"b:8��v���?n�F��Zb6���K87}��P�.�z�f4����""""��p�"�)&����W�q�������P*q�{���>#���@����Ntu^���X8���|fKq�~����3��P��/=�5X�KR����h4Ao0,/8�9|}%�������������d�b���|pG\p�pE��_!q?%����S�����=OB"�����
�-(R�n���H|m%�,��C���CDDDYg���[o����q�-�o��;�f)1�Z���v`������}��#�i�:P[����Y�T*�Tj(�*��j(U*�T�Eg���5d�i�*�a�xS�5R-4R-���k���1�YJ�B[���B��~U�]DDDD���/"""��+]���GcSv�y4Z�����l)^�����w�r"�����F���:��I�����^W7�Jn�����tI��46� 
�!v���(�v�~�PV^!t"���'c85�6�1/T5:��`R����N������m���.�u��y�6���*������������ox��A�xq������v���(�$R)�:D����z���Q���c��z����s��F|C�����������d�}���,�V��E|�$�q�2x}�($J�_���Eg��^w7z����`�u���8��<&c�*4�h6�����H��DDDD�_X�!"""����z����(:
�Q������!O?`�y���Tu��'p��l�Uq��l�\�&��������EU�C
�@-���(/�W:����_�e�yL��p��0���3&1�@4A4E4A��,��*�����"4����i�.WJDDDD��nnnnN���%�����AD�����#B� �%Xl��}>�8��U�h����d�M��B�3����u����:��������lx��g�U���f����I����&����QDTh+aV�.��>�+��(U��DS�be���BY	��i���ic��6`����������v��� �M�_��8��y�D�d�D�3��p�_}f����?�c1�h�k+Qf�t2H�B� �{��CDDD����q��Sx��;�d2��eU����~���W��5���h���h�1+-�j��T����{r�r�bY}}QfB6��l�h?���(���T]���f����v��{�XwU����MB���;+���P�W���K8;q�������E8�3�H ����!� ������M{Ou�����Fq�	��z"�8^����y�"N�<�P0�V�]w����fS�jwb�
|0}�)����d�
�L,�7�2�\��+__��D2���$&��
N`�?�H"���A4[Nx}�d��#��d+E$�[��I��`�2~}�U����J�Y��C���CDDDK6>6�7��
�c�;w����� ���F��;��Ii���G6��I�H��Y��5G,��B[�
m��1O����8*Y���A#���p"����^nH9&�"Y^u��YU��> t""""��ba���(��x�n���B��Bo0d�^����1���q��w@�Te�^D�v�����Q��7��2i�7�Jm��1n�^n�^������?G��2M��*Th+Q�0#�!��*I����L&>�(��\����C��������Qq8f0:<���cN���'KCl��
w�������n�t�����V|��?N��k�]�~��0�������:�;����RM&���+���'���A�2���y!��F���~��������/�A(�L$�J��\$��@��~2rh��l�'"""""��CDD�W�z{����S�5��t(((������B�@Ii��$������'((H���F�6��%Z����<���c���T����)t���&#85~m�F�	����o����b~��F1�/��B��B��X�����6}91�����(
v���
�r:�v��v9�t:�r:�a�fl��-e�����B�N���e���U�V~�&���1��k["{pC���0�X8.)�B/K�s������C��
-�6Hd���Q���81�"�0d"9n+�,[���uj�ME�h*j:
� v��h��|��F��{��R���;'159�H�H�X�X�H�X���F��������;�O �~�M"�bvv6mV������'G�'l�)�=�:j�"����^����m�
�_}0	W��lOv�|��QaB����:XuU����b20���8�yu�F��������7/��p�����[6cg�����'#"""""J��""Z���p�����,���/�������@�v�F���SPP�\���r��7�h,���J�����5��/�Cca��Q(������+�ng�Mn��:���3���p��Q�a���@�[Jn�Z�A����-����Z���vv�������w_�T$C��
[��C'�g)��)�*�!X���Sy���KY��������I�X.��\�h5����#��H�a�P�.�G����y=��17��c������P0���PX�Z���B����pe�2����8u)��~�o��@��_�e�y�]U�`�yS��N�p��YL��`��P�����C&��x�
a����%����f��a��f.c�s�����u�U�9���
'BP��B��5(�^[��2�W��2�d�����JD���""ZS��{g�=�u������7lBuM��[���Fc���,����
���3�~2����sss�@.�l�����p�s�'���q��Q�K3z�X�/4?�7G����<��s|���(�Td�>+I<G����^z�M��eTe�h�N��U�Z$f���V��F=H�&`T������#v��hMii�����o��67�^��p�g0��Nf@�i�����$���'����Fpd�y��!�i*p��PJ�����0�����<��|������g�~B87}�^��B����T�_
��������<��@��e{�]�1�AZ ��{��N\��`,�P<�@<�`<��l`Q��K�r��%"""""Z�X�!"�5�PX���v������BE*���icQgeq�g����rvW���=����(/�����X���A��
;��y��z����������yp�u�"I,�;�B���M���������]�e�����U�Z�e�~b~T�j���`���xl,<VJT0������`R���������r�{�� �N1e���W:/axh_���!����j��������r�H"����\���B[)t����g0���n�F������h\|��J�K���p��!�]W��y>�^����
_H�?���uC%Qe��Q6��X%Z�8^�2�{�eg�Q�
��y]���r�/=�����xPh4
��2!����nWl�I|w��g|O��l�����f����^n�����V{Q���dp��qL&����������B��V��N��V��N��F����4�q�u/����L���\�)���/�(��X�f�%Gi������Vv��(�������1:2�p����`��,eFb6�w��1�0�WGk�z$g��_$�^f���C�~l0o�m�}C���&�c��a*0���$���6q���?m�M��d;���e����������""����1�����FcQ����059���������'�c�����������2��_
��|g&O}������
h)l�X$��=�R
m�2��x{�
\���n�e�(�}���>��34�X�H�H�X�H�X���
�qu���@+��TS�RuJ�e��JNGDDDDDD�	;DDt��&'p����4�"S����� ��{/e��m;�v�o����z��W,;3�L�1��[������l�I��O��Pkh�y��xg����E�����~���r�c�\a'�1/<Q1<76Z��TS��������l���V�����}�7�� )��( ) ���s�"���@��zS�+���Ii���O�0�J�I����h=��5(��g|�@""""""�Oca����mjr��>���A���[o��
k��36n�������Z�.m�N�.�9���L��a�q�p��l�lE��
���D���������1\uu!^����N[��`��
��d�D��("�(�����
S��{#�{S�'gx��KK{2%�����q��
j���L�gn.��;�{S���J83�������rb������!2)K���	��a1�asG��A���z����0:<��V�����eC�+S�5�c*8�j]]R�F$�\���=�B� ���� B}��Y�FE��oG��`�;�D
�D�D
�D
�X	�D�2u942m���~8Bv��q$�������M 1�@r.���-��dY��Ea���[L������Q���FW��H�R���(?p���W��2�d����A��8c���n�T&���8�k��}�N����e�H8��at:.���	q����#Ag���lu~��3��l)��L��vT���XK��h��i��Ir�_h~l�`R�Q��r�DD�?{�U}�}���L2�$C����$	�bx��h�V<�e��muo�����}{��������k��m<U�j�����J�[���|���$3�d&�$3x�H�HB �����"k����2������[���
`\ILL�]�|]II<Gg����������V��I�d5�4�s����d� oA��	�-V[�U�hX���[�a��%_��������b�'M���P���dKJ��k��-�<�e�����X�@�&��*�QG�3v��"2'�e1Y��&���$s�����
����
[{�sR�ti��T��>����?����;gls��=6���W�-���F�8������1�M�x�QG�]������:�@{��N�Y����������`p�\�Te�3599S��Y�l�T�ed��2M��$�]�<����O���:��+�x�2���M�����+1U.�[N�K��=�\�v���w�����)%�����)!!a��� 	Wko�n�B��oo�����+s����{�Z�a5F��������z��,v-��fe������e/���W���������??�e��@5G|���_TW[#I���h��/��C�#�j��J�$�nNV�%E�D���O�.}X�=�YVr���S������<�M�A�_��Hr)����VG�jU�vDu�5j�Ed7'�S]m�V��5�Y��6���s:6G����u���T}��$)7/_�.�BS��������Q����JLUz�����v�yN�	�IV%[R4;��sz�z�3��H��6�2�Y�n7�3SE�b�:�e�4x�����|W��]����������u\����UiG�ZZ�iw�N�S�9I_�u���x0���L��Mz��U�~����`B���}U>�)�E�|�By�s����v��V�,&��w(��1���T�rH�P���u�J��9O���?]��Y��M�V[�U��6����=�u����<������J4%�j�)������:��%I�2�j����������WjR�����!��-�m=���*��wI��]��T�e�:c����D�:�f��f�Z4�B���3k��O+##sD����g�w*��P���4�Gi�t�%�+-)])��K�������&�������<g��S/p��D��#zcN0+-)]�]�j������dK�
�%�J�p*����Y_W��E��#j�Q�b*�������.
��f�`��un�vG�������`�X�R �W��I�%S����r�)�9�!R�DS���3��u,������WC�Q���U��}����+F�y,	JPM�'�-MS\��uNQ�s����9��.������r�����������)�7w�u9�!��*��E�����c]�]��������:�����u�������H�Z��m�������k�>w����,��������5�Uc�A���
w�
u�7~(O�dySN����+������}m��J�2W'&;��LM��4)��:L��=���O�����~��R����yo�^m:��j�����4�LK
>����;~fj����>_4���_�]��x�M����YGBG����/s����gl8�_����@_���
�c���u	��0!��������	�W������%''+99E��d9�Q;�+��E�r8�*�h�

���_ ��"���M���wm�}W
����<�]���{Ml����:��Y��1R���Z�k�i_c��r�V�m��gh��H������1�W����k��6�%��v`���QI��j�w��mQ��i�m��JNN������)�#V�5��^��4y<�G��9���ce%����E�w��yNe�d�%�g�Y��W�%EvK����7;p������k������^��\���W,\���z�B-
��()lV{$���%(a�sU�m���j�p8���P���H$��#>���
7.SFFf���\Tz��y6>��D��d�KF�<g#�����0�	������%)�H$.�
�j���E?���)��V��v�}�v�}�:;���;N%$����)'7��m��_�c����i��=gl3��jnj0�i3&�j]	���PO�������u1��)>|���x��C-�$������u��2y�sF��PK�Z[�
��jk
k��I�f�(3�;�����T�Z�|W����6��+���_c���A��d�M���.0<�����Hq�b�h�������dt������������Q�z�n�b���y�2O��1=�I IDAT�w|�������������3����&%[R��:G����u�K��F5w4�����?R8�=Bi�g���N�����t��qUW��=���><���L���,_�����������l����:�9���9F����^���.[M6��~Z��.S�%e+0;&�H�Mu�5���Q}�Q���������(-=����t�lI��d���5�>U��aq*������X\-�fYM��;��O��v�ln9�.9l�7�������f5F����|e���B��Y�ds����JO�(�Q0���vL/>�K57z���v��M�E�e***���b4�UC�^��5���!R����n���}�S�_���^l�e��?������>��V���n9�.�g�Q�=���?l������I-����Oq�����9�
`|!�0!���\�H��sr���%�����W����M;O��eKU��H�I6�D�y�wy�B�DJ�
)����h�B�AU�I�J�/p��P���fN�7%GiI���499Cn[�R���>�@�`���h����|���x�ty�s���Ss�
x,�$�2�Y�H����e$g)��y�#p�*;%W�)�glt���<5�g��hq�����G�<A�`��F;u�W����u�wX
�G{��nw�`���]��a�����ia��K�=�5E��h��#=�3�6N�k*0���o�6oz�w91)I�OWQQ�
��d��t �W�[�&\����>��D[F�b};FLWW���j
�������~�u9���f���X���M����zU�o�$%(A�)��K�W��@��|�'YF�Z`< �0,���:t���57���+����9k�`�l�t�M��o{I�T%$$(�9E��|Y'���~0�jo�(����^���n����-�]�''+7/_i����+=�#_��'�M��HsP5�#�m=�G��������9�(�9ex.
�`�@5��lRc�A�M���D��������#�j��QW,&I�'+�����������sJKK��3Y��O�������z����jk��]v���|�0���������S��f5w�>��i�_G�j��s8]�<%Cv{�&�f*5/U]���u,���.u�R�X����*p�{���t}:�3�,;�
�Sfr����V��@��Zk4�#�ju��U�V��c�K���&�D��j��P�Ii�n[�vT��d�d�7%Gn[���<JMJSZ�G-5���o�rr�������|����#=��O�,�]�LMT}s��.;��Dbm�����/t������4���o�S>�#�j:�
����V�����������v���h]�,��6�~�X�|���_4b���.���������������M�V����5����#r'�����Jt�iu�e���q��	���bM�����66��O�����*5)M�)��M�WCC�jk����Fu�5
67�n;9#SW�_t�5��.N�S��|��
��2E���!�����HW�B���+�>�2��~��k�Q}�Q��B
�7�%��PgP�]I�
-SIji����|�
�E�a��}Z�t�W������e�����<y�s��������\.`"��a��Q����u��4�S�d��~��"w�y���E7��E7(�RS�_M�5u���WSG@N�k����}G����s����'�is�;E�	�.����m��f������	r2��g}mc ��at�������C�V}[m��pg�����9��95�U4���3��4mZ���D��3O�������z56��������_v{���/��{|����>��!�0�����h���������L�9���W�k���lcZ�`
\����G��gW)��������#U� v����:����{���d��������lM���8%I��E��"�S�e&{�J��Y���V�9�(�9E���Q�v�%%�����O���,edfjrF���=�4i�X�v�HS{@
mG��^����j����.�W���}�z����Nv�E�T�Z�o�����a���e���dK����-)��V6�����:������:
v6��XW���R�v2���L����U>m]0���{v)�������������Ti�	�`gm8�������^Z��lMQ(R�����33���:�������\G�����kUGW���!m��mOML0�9�����fJT�9I��D%�|m3���g���Ij��������{���T��=JMLWjb���&X�Hkm
�����+�x�K]]��]]��w�fK�6/��W��%��jkkUrr�p��@����6���*-�������g*#9S���P;a��,gcj����v�i�;��j��)q���"�������Y�s�d�5�����������>��GQGG����n���I�O���+��d2�b��b��b��j�)5-M))��,p"�9]����ooT ����^��F}q�W������lI�y����'���h<���}�fL�Tm�V�F�j�jS[4��h�Zca�%�����8�����hWm���U��$�������)))���KdKL������$Y�V�l����g5�f��O[��j|%�����~�f�:����-�j��v\��9Re(R,�X��Y7�hT;w~��47���������D0�v����*�:��H���4Y���l��R-�<��������$�l6+'7O��y�s�����m�G�37���`g�2�Yc]����I�ii��[�V]{�
JO�(3k��(�|���d#�%�h��jkT[sD��5���Q,����MY��~��6��Q���E��q���^Qm�5�}���84eJ�::;v��v0�44��%���l�\e�t?#��p�ui�9�������i�\q���C���$��5��`;����G|����kR���.�p::�{C������*����l��~�'��;'���K��;��j���4y�K2�W��>x�w��t���D�9��f�hrF�V�������G��Y�If�Tz�������)���VE"���*�����6�������*,*�w����k��y�s�������Q����`G������N�&����G�X�4l�����f��jm
�|�%&&����w�V������%&*99E			�o����]38�>�95��w�uI���l�����
67�)�?����H���~��t�l��M��nWrr���S�p:G�dp�.�`�&����/�<�<�C��XL��fM��1�v���QcC}�rbR�RS��r�*���;5u��/�Z6,���wA;Y)�*pkN��q�:�_M��Z[�jnnR��E�P�:;:$I_��_g.��@�������4Y��Q���:�1%������u}���+jm
�Yg�����QZz�&M�4���e�dy`]���x4�l�$)-=]ii�JKO���<�U���`g�;vL5G|:x`����k*��������\5��#!�mm�:t���������+�m�;�� ����ySrF�\�l��-�������������D����G�0�L�`�������Ee;�����?_Z�G��l���DY��?'�03����e��}�����x���L^S���[�{_�1Sy��s>]sS���Zu��q����l��~��6�M�~�9��?�v�/n���u��KUd�k�����Y��W�����}����c�\�M*N�zV�nh�W����%���`P�p�O�������b�`'��
�*��z9$��E��k�3{U���JUw����/����G���t��=zG{�vl�oIRrJ��sr�t��v��r�jrF��_"�/��7���.o�'��Y�S�^�����k����Rk0�9�����mk~O��
�vv���R�p��~������n�\n����������E\�v�,��6�xV�#����&Y�q�:���}�n��O������{e����xT\\������$e9G�2��'�W�8���1�W����'�ul�K&;&Y�������L������L�����|���V]<�by<�������u���x��)U����WKK�-T����
�y�e�l6�n��z7?.�6�>f�8���D�7w�u��0�+`�U�8��������u	��0i�:����h�o>����p����FY���q9`"3��I�����
Zu�*�����+t����.`D2�����KU�b�=��
��D�`;A�`;A�`;A�`;�p����c]�p����u	�S$$H3c
��5�����x� v�`� �c]�	f�{z�+;�b7�rb���������@��>�YoUE��T���B-_���6��J����>�)ysT��U�����V`�~x�{�?��������?�������E���%��2-���*���7�����u�ZdS��9Z��2yM�~u��yw��fD��_�����j���5U�������������A�#�Z`x�����V��n_\�L����R�W����y>�^C�������u����B]���Z4�$)��+���mV�O�5���?n��Y���?y/e;�W8�h�l=��\��#���
��.�w��WR�.��{������g��H��<�K�{���8��i�������X�r��`h�Q�������@��Ry��A����Z�LD~�eU�u��?����P�S�����
zaw��{y��L~���Z�:K���{l�0�HX������U�r�����������k������{-0�����C�e_q���t�}�f�\�����T���y~�^C������N]��/�b�����Z��V�8_y�NE"V]��/���gHc��^0���
����;���*�L��j��-U���/�I�����k����w���>mO)Q�5Y$9������~|4/��v=�g��~y��R�rOi��6V�m�lU�$YU��i��~P$)��
�*�m����-�5_��{U7��L~�{�U���UW��l����X�Nu�lr�������{-0��v���PK+{�Ty�J����u7x�<�{/����2���+T1�*�����Jo�..I�����8�<�f��'����;�U,��X�>=wG��u�^�������
$�*��_Z��s�ec�"�V�V{~�<��y��|aI��p������$���g�4�?3Uw(,���Ne�{>�r7���.o�'����*����q10dU>}�*%)�COm�D��f�������au�=���+���,�����{-0������Oc�jw���I�|�����7}d/��������O����V`j�����qE��T�z�z���*�a����B9MR�@��x����Q��������l]�����7o��������qDR$���$kg�V-��y�/��R$���X$.������y���m��nVW�k��
����qE:%k�Y��������-�VY�q�"�W��,�5��+~����H!�I�x\����0`29T|y�f|��������>�������;���#�Z`��|�������w��K��y^�^�#�i�~�\\+f��5&y�sT�x����;�������
������^0��`X���={�T��\3^���{�v�,�QE�N�}�L�i6u�$�IvI]v�b�����e7J^��t���?U����d�I��NYK���������d�K�I��.��&y//���G�h�b&�,���0`�.�����.Z.����]��~P*�?&s�FDlg�~��2�Z}���l������������g"�����rZ�p�G���d��-��#=��Z�;�r���0`��?8�*��Z��,�X{����d1I�z���CG�n-Z���x",W�GvI*HU��f�����.��:�����9#n��i���!����n-��y�;t4�Py�$S�������.[�"I��;��(��'�ak���Z�Jgu��/I��d2
���k�a�Y����+��K�|��}i����<���I����r�I����ZPp��HX��E��0S��U�.I��m��L��:�b0�������[�q@R<��?���B�.�����ya��\�Bq)vh�^�hR����;��hv�>��fX1���mi�<�
#n���WQ(����������v�vN�f�K�C��z��7�@XR�^�~]��kK��k&��}z��
Z�=*I
��U�w�j�B����k����������t��y^�^C��U�����OU�
u$)�������5~�$�|�����J�w����O�F_������u&�xP[V������7�5�"-}p�.;��9X�������"RR�f��D�op���ql�GZ��G�}�S��|]��\��K���������Z�����b��b6��&)�����2� �3��?n�������*�����'>\��U���f�_-�+�r���F�<|V������wZ�]������8����Z��/h���|/���qP��II�,]q�-]���� ��{-0|b������OF�I*���w�]��?���`Hv}�Wz��N��'�A5���'KUY,E>������G:eIIU�m��|y�N�~8������QF�`L�`;A�`;A�`;A�`;A�`;A�`;A�`;A�`;�*=v�za�Xr���Z�������t���������/���**�-�Tw��Uuc]
��X�G����v�C��]�%6I�����08���-���G��.F�p�����e�|�*zd�r0$�ye��u0Bv.qU=��Vi��)��^��%�)k�EZ���gto������s��S�e�����o���B}������3WU��E��_�@�t��<��O����GKx�*�O:�o�^x�J[>
+������Z~�IaI�A�yr���V{�I��-�g�*��{{s���I��8]u+��
*�<w,��+2��=��������T�W�_5S�}�L^kw������wOl�^__w�k���K�}���-����O~�����2�Y����.P����5���_�rm���k���v=�;�hc��Y�P3z��\���hXW�|��N5I����;��;������j��k�)�����J?j���W��c��egD��I���G����SRP�����^��d��h�m�u�����T���ok���G%�Cy���f���R�M[��3�u�P�bf�\��r�-(�9W�V�+������������;��$^�n|UGo���]U��3�����x��|�L���)��[On���~�D$�'U�7��_��s����b2)��Gzgf����G�p�������G���h�Y�L����g��)�K7n�3���C/������z�^�������VK�I?(��������m����h�TI�Z�p��.�R+�X"�=�/n�=��,�������������������k��n�T�d���3����V>��������]Z��&�l�����.�<y�.������VoG^Dy IDAT^�0�{g�I����#R������,����)��������I����������&U|���e�|��[��?N\�Ie�^��;��������x������5����PG�Lf)���u�S���-�6n��zh�����e��7�.qHwk�w�J��B�<�*k�SJ9�M����?k��Dw�����-��}��z�U�J�E���}}�w��OVw���w�b�U
�k�C��zu�����(�K���nY�^?��-K4�]����<�C�����c���uw������o��m����d1���W���
=��]��UZ���Z3+���?_�5�
����U�nRd��~�m���-�|(?(04����2o��[�3�������
�?�c���y�r�S����5-[^�]�<)��(v��YK�j�T�,V����UyzPU�����C[rTy��I&�����+r�����*r����>S���DyV������z�����W�5��t�CI��2���L������=��L�X?	9,���!�:�"��-�LU|�LyIV���2W����e��MAmy�^���r�����
����js�>���6�*����w����Z��{:��J�y������\e�����kvfPo���$�]
���B�o���m�3�!��<*�Wo�)��3W3�M�Lr�������{�>�z6��G�Yv����������I�#I�v�t�d�t_��v���=y"�9��k������k")i���Q<��B]RW��`Ok\-��d�+���:�����?�N�`�1b�B��P�I�=[l&��K]C9��$����z���$���k�I���7��[|Rh`r��-U�v'
�CaE"~�Z�S�:����b�	�L�U&-.:�i��A������}F&9R��<��I���,p0��;GY�'�4����6
��5��H\u?�����)m&���w���2-�N��5�.��O���AV�����d�']��9i]��g/���V�?��{Wi��m�a����$�����W����?��3�T4'O�_���O�/(�u7���~����*.��%u�<���t���$W���c�{�O�g|i�J��{z���+�T��|���Dy'F��B��Ug30�$Yz�i��.�}�/����g2}2�c��k3IE+n���<�j�
)b3I����R�i��Y�7�d�}������������#[K�e-�_����j�����g[������;N�������h�W���������������������3J,Sg��?����Zo��������?R�SK�l�v��b�Iz�����<q��w���@��:Z=i9�������)p�����g'�jO��m�����I���}�:���=U���=]V�S��_G'��U]-yJ�6�dP�Ty��;�}�o�������vn��������t���<\%_T��(�;it�)��Y�KW�)"��H���@X�>9a\��I��|-�c��|�v��=Nxi���],�%��7�����������i��������&��b��;�D�,�}����g5k�k�r2���U�������{9��#m�v�;g�������K�����
�U����-����� ��Ol����xT�uok�mk���s?��<Zps��^O��uG�����j�<��5�������3�t��^��s��������VU�gkQ�p�1q�������i����U��Zk��;=������(\��H�u���s���KtY���Q�"�������w����=�����:�v�l����Wh�GZ���j��O�Us`�o���[�+��z��:�/"{�[���/�����7���;{�xT����8�����,W,���D*����9���&A����z��������Wu��^p���Ya*6����-�z[kn}V�2�rN/��7{����gd�W�K29t��n}��Z�;������s�*�{��fj�+dY�M��}���I��,]���U9�Yy�}V�E��K��V��q��P�uK��=��;�F������%Z��Zy�f��L���W�SWhQ�p�LrVVhE�f�����w�������u���{�����7��3W�zWf����������=�z�t�U=�����/�k��/�������W�r�P*�j������w���_jMX�dz4��
���D@dR�]Z��f������Kv���M����>s��x���m��������d6�5-_K��
��%)�-�^�UO>���J�d��BO>^(���&nU<z�ZVn�����P�dw;Tt����!�_p�?~|��0N�����;T��/��Yc]�TL�`;�Tl��� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �0�� �����{���>����5�d��$d 7��I����n��ja�Q�V�����G�����S��u?���sh-���JK���"�M��$B&��8!�L������&!h��I>���bf�5�;+��v�Y�D��A�!(v"�@����;�b BP�D��A�!(v"�@����;�b BP�D��A�!(v"�@����;�b BP�D��A�!(v"�@����;�b BP�D��A�!(v"�@����;�b BP�D��A�!(v"��$��Wu������f�C��>�����?qO�6.{Y�����*�������}�L� X�U��^�����=�]����������z����Q%���Vh���Z�)Qwp��MyU[:{�k���������jo�����:��h�*������=*X�5����cg�6���{�-�=C��a�
�k�����6��_�*��*�Z�W�������~)���,Aq����]�����6����4�*I�9C�)"��z�4������q���U�D=|oR�G�.�WQ�I�F��
��H��5�5���uE��,�y\��R���=���%�S��Z��F�F���;�h �C
���jTQ'e_l?�S�7��A	���G�)5g�S���,6e]�����*�����$��*�;�B2��������EQ����f�s�M�M�
���\Ol�T�N�t�	����V�Y\�
A�R�4i�t-���'�>��������
���#w����u��T�O�W5�^�����$���{��$#U��^3��j�V-����&L�i�~����>�G�X����ro:,W�Zt�Go=}T'b�t�&+�&IAU��]/=sXeUA)>A��;A������Y���E=��s����g���d���3w=*YQ�u�������I*\2]f~q+�k��zxk�����������^�������!]�-�	�rm�^XuT�5A�nW�u���3�����6k�2�h�,�i���Z���Y[����v�f���mKYr����'X�U�^Uq�$��]��v�r���?��g5��[�+>��cAE���=:M�.������_���<]�L-y{�����������.���%w]�b&�����*����S�
��������g�WO�P�
On�����472K��/Ta�!�����M+�G����U�!I^���]��?����{��o�V�j�JK[�7Y�<%W������{���K/>sD���R|�ro���K���?>�U����=��lJ�2J�0_yg�Ek�R��<�}(���|I����.����t��7Ti��������#3u����]�������8�����G�i����OU�=��L���m_��I*�s�����+s]on��_V�)Cq��4/������;����L���U+W�h�S?��m���"��<�������I:���\����5?�c�g���m���f����������h�b-��X���W�HR�4�r�b-�4M�-�=K���k�K�4�b�VmJ�O^����C*���a����Z�x����IOm[�_�6WZ�Q�g���'lW���|�m*�f�q��3Yk��g��������MCs~w[�u�g�v,{��5x����\vD�~qP��=��mzr�,&vt�/������~�R����|�b=��d%o/��M���HOPbK�\5_��:V/��+��d��O�]���n��1���T��P'r.���u}��/}t���<�H��p�
�����Gt)+��/������i�|4����2V��^�'WOU��]z��g�'Azz�6T�i�+����s4���J.xy����T�\��~��o�Y�����b��J�E��N���=Z�����q�V�)���e]/u������?w���X�7����#z����?���v=�h��n���x�6���I�m��g\����+����Z���Z�v�FW���g�x�����7mZ�������t]|�^|��%\��]��]��Oo���$-^�X�{�f-�����������R�i�����z�ZM�!�|����U�\�Q+��i������th������j�V>vT�[�����i��V�y���k�[Q��~&�����nC��g�w�n�6{�[�����lX�r]�2.U�_����ym�����k���������jH2�M�diz$����I�q�r���$%�I�����TcCPRP�_>,��	�?��7�m��4��U�qD��5�E>������
�������d7$J�a�f�4h�_�f�M6�K�i�T4/I�x��v��Z�u�y�r
���0���~�%����}Uj�Rl^UWI�Ui��+��WP'�����EIq�{��s���d���_-#���}���[dKL���	�q��R�ng���N���������'1ScFI'���m��d[���;V�%Y���Q�.�i���������G)�.�b��;���=�g�F�R���Q����
[������l��/e*��W�:�l��e��5���z���3�9��k�=e��s�a��1f�n��B�kj+!����Z�`���������J]r�w�$�&�:J)I�]��RyC��}W������^z���w���h�]��i2�S�
�I���W�C��T�+����J�j���{���u�d����/��	�1�sn|ywT�2:Ks�M�h3Vs
;{S�&��
����M����`P~��������������]���%�W����M���\C�Cl���`j+9A���=�	���c�H
�e	J�W�J�����=��t��\Aum��������P�p�y���n�]��_I_F��L���t�y���uS^���kK~�F�+���K���0JIoQi�W�����~�\�?���2��	��`�a����x,�����g�91Z��]���i�$s�+�Kr��w�Ob��6}���^u>����{���sg��HgF�y�D-.��c��Yt��t�P;�����H�oyQK�K���4�����1�3���+�rN����$��<���{�^�YU���$���?�K��aS�yw�Y]����5���K�W�kO�����2x�&��q
�R2�xs�]q�J�$�?d:����&��=���p���6��j�RR�yY
9�m2����d;�_H�e���^���![���w�H������zqw�?�CMJ7$��v�{=��kq:��\t��/��}��_bU\W>d�������4��B%��:��D��)Q����S�R2��I��
*;r\�����q��I���������t	�`���%��y�YRU���g����Ou�-����X��J�%T��e��/�s�tk���(�_����~t�~v��r/p��������r��z�(I6C�\�=����}3]�&��h���jOf��]s���[u���N���}e����_������D~��zS�����PJ�]��K-u$�^e�r��V�H��K��*����i�]��`�
�G�]\N�K�	J�����s>yT])9��;��,���{��eg���P�W��%�U����wbJ�t�[]���6��V��L��Q%�/^)���c����U}^�P����Tz�������O����7����&���s�_�]+W7\r�7(s�S�o������G�=Mu/��,(Iv�dH�c
����c�6���W���F�JV�-Ig~N�T]����b�xM:��Re�Ec�)u����W��	����q��&��]]�������*?���ao���u�K�I5��~&u���5v�B�p>�!���������s��NC��������������;��3��]:��A�u^��jTY{�����$��__���G(��D/�u�+�{��^����W�ty��.�&USo����]�Y���O���z�X�
���{1z�<�k_�E�*�:s!\��\R9�n��~k�F�J��Ij�R.W|�����v���;3uW ����*�]r����*�kTy��B�;��fi9����KF���T�r����opi�3�Uw~y�����*~z���%�WG_xK�s�f��;�O�!=�d�����I�Z�l�Wl���/�=-��'�[�u�)|^-m�R��L-hh��#�m��lj�7T��z��]�Sg�&��dS\�^e�ym������EM�Y�v��\��&�-���
�K���u[[��W��������@��;^�����&W��o 3L�!5�<���0�Tx�S���k�>���\�����^����vrL�P���6�v���m��|��.��1�y�cs4i�f���R�$�n����eh�=���v��kJ7<Us���W����h��f-���!��4A�^x�/���[ IDAT?`�������+}�!�h��6���>���*��!yZ�J~�^���Z�����yU<�����n��Y������;��b�;Zw��Z�$EM��'�j��n=M���q�tU��u�?��I6��gO�]wv���3�J�+W��t�H��te�PqN�����j������;h������x�{�f���$C�E���=z���m69�u��������[r��;<V�\��:f��S��t�I��{��<T���Y)�S���I���JPI�]��\+���z��g�472CW?5U�%=�����(��Gf�Y[f�d-��o�������deue&���Z��I�~�m�
J&��rT���sS��
u���z�����e>)1^��;G��~f�1�Zp�K/,}^{�m��=Y�g���k�~u�U��._�s��E�IWX25��L������_mJ��E�>U���-���
�7W3�A��4������gUVT��<=�'G;��_�������?J2������3DJ)��%������������I����)g��Q*z���O�����R
����;U�r��\
�)��d@kkkk�C���c@��Ui�C{U�����q�ZR��{� ��c But
�@��sk�4��j�}����1���?�1���	�/�'��@�b|�)&������7���I��B@;�6�S�O |1>������O1QF�#}�(@����;�b BP�D��A�!(v"�@����;�b BP�DShOT����G��?��y��������)%Ms���y,g�h��6k��.�eU��	*z0O)FH^D�������64�Q\������si���k���_�����e�d�u�~�u�������Q��m�k�f�X���kk���_�]+W5��K���il�����V,�_zc�+������K�tUh���Zy�V�h���{�d��f�G�/6G����,�1m�
��k���$�J6�+����e�dsj�-��xX���J "4�����_�3+~�K��$
��R���_��$��H+��U~�Ho�p���m�(-Y3J���T����J��22������TiO�G
6������/�]3g$(���A)���@�p�>��m����AI��lV��	�rb�l���s7����Ik����	�1kvoE�����>�7(���n����(���o3)�
H
��d���S�}�j�w��|��9��E�IJJ�
�K�c��'��@�b|���	�/�'p��6����|���X��`���.>F���Ysy����5*=��\����oQB������?o�Z��PX;16C~_P�O������dJ5I2d���3�2%O�>�L��
Cf���TS���@8JJ�b|a��	�/�'��@�b|1�JE�:5.�J��f��$wS��Ht\�nZ�#��~��;���-��s�Wn����cp�����U�Yc�"�]Q�I����dM�Qu��2�.	JI���B�Z0ME�Re.w�.��d���
�IRr�&L�,�����wMt�Mn�gM�6S~�O��Y~���S���,v����MG��&��
��i���TP`H�+�S�/��Q�$O�6������(%�������W�3i�-���JM���G��9|���������{D+n|O�>IA��-�l6C����5�4����j�/������f���>]s�X��zT���Z��%�lJ�7Q��5GNCj�u��������_�O |1>����������i������V�����1,��:58�*�)<�5"Ih��D��/��_�O |1>������}����$
M��������sQ�������~}���:��c�����Gi����/tt/�s��>��7^�$]��&L���q����RiC�C��(v �
��+'h��I��������������ib�U���Y���ILh`���a]�HRz�0E�l�������R���H@�C�!������u��*�Q��a��Tt���6\�'����gTz��P������'����������[�������-bbbu���T8m�~�^[��6��A������	����h�a����O��J�L&�����WN
q��3`�L.TF�p���e���D���Z�8{���bz��{Z�_x^�'�$I1��7~���_)�5*��zFJj�n]�c���M111���	;�l�}���JJI��WN�ey�k����Z��b��i3C�3(v�~�O[���}�(6��h�M������)�f������1�����.RLLl�=?���b@�������a�$��)�N��\�=..��b���]z��-��F����(Y�VY�Q�Z��64]�y�wx<��o�b@�1y�TY�VM�j�Lf���O�>%������N��X���OPss��r}V{�v���i����~#&&���^bbb�t7���c5j��kiiVKs��[�e�X�-+��b�����9�(��������I�5'Bzw���~X�w��,�������L&>�����
@D��s��
��D�q�-��0I�a�:��)����w�Q��;������i���ku4�1;"��O+����:u�#�#Ns��V�3�Cz���c�����I�&O��)�b=�?�D��A����WQQ����j`���A��?���L� l��4���Q-;��&�n���PG��B� �jkkt�h���V��O�=n��R]�K������B� d���J���8�u|� ef�(+;[��g�0�'�!�<D1�����VV�9��B	���nW��1+/S��\��
�p�����S@������>}JG������>��\~�O�4`��N�������9\�m�m����s�E�l�,�r
���������b����������RR�4<+[YY9JJN	u,��(v|���SU�q�~���gv|�MVV�~��������t�Q�P������T�U�U]u\��j����!�)�;&�Y&���@�F��c.�gZ��*�47_����d���+mhz���C��c��	2��:"C��C������T�L|t����@q��)5��r74����`0 ���i3���1&�I?��{{1%����"����zV��z�v�?a�bc����(v�0�v7�����

jhh���������c������O���x��%��p(>!AvG��d2�{�Uz��
|�A�
4
���qMM^�{��r�t���v������%w��o�9(v�o�Xy�^��Kn<$I?����8PU�?�����a��O8w�MBB�qq=�(v�/��Zt������#9��5���5��2����F�b�*::Zf�EVk������0��sY�Q���e��}T�;��v���GTq*(Kt�������,��h��6k��.�eU��	*z0O)Fh3 r55yUv��}t@���=>$)�����g����t<$�k�SwH�=T����I?g���v=q�;���z�"�Vo���������2\�x��Z�*Y?�=>��aN��h�+�������+���������!L��������	K�f��H�����>��
IC<*�\���_�,�$95��mXqX��OTB(s �������F�	�4��\]�{���SB�v�g����\�{�����Sl�����)U�s%�U]eSJ����3�X����(vpI�[o���G��pQ�Y��R���4����4����U�]�|��`P�&�����{V�����C�����-�LRRBT�_�v0>�0����_�O |��'N���C���>����Qjjj��0����������	�Y����>���?�������{_����� ��9: ��P��<��2�j�7����RM}s�_�v$%D1>�0����_�O �4��r�4p�@��(��]��i�$�q�<Q/#zP�S���8k�#}BX;���U�����<����<�l�[�=����zUV!�_0MY��oP]�S���`H��kX���*;�q�����Nc���p������J�b�M
��tE����|����w{^B%,����	�.����<�H7��r�9dU�w����uj�K{t�`��T�
>�����"���/��F�A�'t�:��9X-��c��:=�#.^C�3dw��� _'e�o�����tt�{��KUrIR����UT�*�$=*��f����[6�������#�!5��:���6>�v1U��@�b|���	t�{vk�;�5x�-��m�rN�'��Ye6
u ��i���Q�������_�O |1>��5����
�Uu�SY�VM�9������O;@�����Z[[�g�N��E�@@���u���ku4��t���'��k�u������5���t�����@�B��nq�x�NTW���4��y��bB	�>�b�b��+d����="�Q��X�
��R��E�!(v�%uu.���=�1��Xc�
�G�V���I���l9��C�
���b���Q���k�xe�;4s���:������S���M�����
4�[�e2�C
�~�b8YW�?�Z������T]=�:
<$���(v����f��n5���vk��I�;(1QiC������~��Q�t�@ ���GTW���d��l��d��d��lRTT�R���h�-�7���W��-��A������,Ov����o�������nv��
����u�}P�S�-�����_�y������j�j�eU�5J��(Y,M���N3�h���OK�,V�%*&&F6[�l1�h�z/��@76<K��OTttT��cb��$I�����3_v�b����j����� RP���Y�����FEE������)((*(h��b������%hnnR����������b�Y�=�,;]�r}�=�w���u����k��:�g(v:q��������O�Ij��f��5����
�%��v����V��A�dw�)���/���t����h���P0P��t��0I9#r5`��P���[��n�%����UQQ��������6�]>R�iC{��T��w*:��#��uP������SKs�$���rnZ���i��c{�v������QQ�Z����g���������)u@���a�����5���<��4���I�������x577���-_K���i�n(v@�:YW���GT~���SR5u��������!��q�s]1n��7���ZZ�������fEY�.-<@�Q������*;rXG��\8�������4l�����)��c��\��s+�=64=C�Y9�����98��"��1�%*��P��tefekxf�,k�cD,�p���>��Qmm�W��9����;����6����&�jkN��������F�'����*�mj��Dg�S�;�S/<���
�<f�X4(��A�e4B����������Z������re�Fu���Q������A�4hP�%&*6���Ip�����Syy���WmM�NTW)H������1��c�*��[1p;�q%���?������s�9��������T%�t�;�q~�_�4y�T���)5mh�S� |Q���M�<E��'�l��:
����z�@�@�!(v�`O�^[�V{?,	u��� �~���M���'Ijj�j��!N��F�@����~���f�:�Ql�]S����QcB� |�O�6>�����Q�%A�K���F����h��6k��.�eU��	*z0O)F�C�sNTWi��7T{�Z&�I��L���)2�����^���O%OnTq|����LE��h��vk���*L�\�7���T�t�|e.m��U�\������������D�r�Fj��o�nw�:zYx;
G�e�S�Vg�aH�,_K����Q��z�~�ze�%���dh�����}�B����i3��w�����:
B$<��#��J�����������h����9X��*�R2��w�����j�NE�����@?���������?W��u*�o������!�f����d���S�}�j�w��|��9��E�IJJ�
�K�c��'��@�b|����:y��>��5p�!�����l��dRbb���C ���'�>��5��>!,����9>C38e3$��B3�������6d���3�2%O�>�L��
Cf���TS����I	Q�O L1>����z���:����j�����k�{m����W�O��tM�jj������6���,V�L&��$��R�0~k�2�
����[��O������	aY�(=A�A��-�lm�%��d$(%���
i��i��������J6$C	NTW����<�n������� �����y�t��.����y#��E��W�gd���QQQJNIS0P �����I�@@��m����[����+L���|���P���Se:������1w�%I�s����-��,�h���+y�d�H�w1�:}��N�>���xY,�F������]������a�;��p8:=Oz�0�g��w��,O#.����)\��5���r?���}�W�OP�}�4'�m����*����7��[6�������C�+J�����:}����O�����n^�a��:<~���=�29q�����"EN�������}A�l�Vx���@�b|������d]�����Fw��

�5����vx�__��*+>�$��f���*66V��6������+�t����O |1>��48�*�i`�c/L���U����U������S�vZ�|{��8p�bbbd�Xz*&�(v�����>��QRJ�v�bbcm��f���fS\\\��JL���@���t��&��&�Lfs�����;r\���>���������OTYQ���c�s}���W��^��1�:��G��$�U��q�G����W��IIM�a!J�};�Kr��Q��k��!�)JO�P���:4Cf�%���>�b�F�[nw�����5lXf��������C��1LVkT/�@��������C5��v��it_�=7od��N��AJ4��ch�D���fy<��4���h��D�
M�p��A���$�bb������8�'$(��PrrJoEp��P�U�i�J�c5c\����v�����h�(u�x��_s�dmL���&�Z�[������Y--�jiiQKs���
��!I�������@Y IDAT�����?��b';g�n��'�uD��;��_�/�t)��L�/���e%��������p���w8{#/D��k��������k;-v��^���(**ZQ����-��!����X��.r�MTT�����v~��y�ti���J��&�wK�$��F������~3Y��4o�Z�_�����t���54����Q
��������V��A7�t�RR�:<>)%E��_&�I&�$�d��d�a�d2<xH���Xp�&\��/@��;U�&�`v���$�����s��s%�mL���j�������w�~�y�TW���/������U0��'���.:�����3_x�t��U�?:o��`P��_o�O���}�������4�������9#.���C���S�#^��89��d�;z15����b�p*%���kTx�Sukh���%#����n�N��*�i�D���Oi������<~����;�m T.r��]S�2�����t�$Y���t��H�O�V����\��o�:_�������������%I&�Y������G)&&F6[L�@�.:�c�,=�B�J�zd��T���-�^CyK�����	��������s���I��XpQ-v$������/?jh�}�kt�g�5v\�����Xp���m?��E����P�����%^��2��
@D�Z�4m��C.Y��N���w��jWz�Mf�`;�YS�uK�R��		����cJJN���(��:/v�T���Q��;��J�rg�h���_�T��������X'��k����2uz�#@���Tl6��R��[
���\�������K��i�t�-����wr@�Z[[Uz�#��^,�g�2C�����1�B
��E��/���������E;�>��%��O� D>��s��W�v�C
�'e2���$M�|�bbbCz�E�oY�����xC�\�F_��[W_������ �TW����s_�;Nv��G������o�&�����
u��EEE��� \t^��h�7�����w��qUw��_i�]�F
Vi���`�x�c�;������N�i2���$��77�'9'7����O���I�!�BHh������`c�,��dK*�\[��,[�{�mY�d?��GR�ZUk[Z��~�����_q�V\QPR�Ko���N���������R������z��
n�8i�g���#������m������g���e�~M�>C5�u�����nVC}�,��0�c':-����}g����r7_��>���q��`�������5J�Rjh��]�������<���U(>�t*�#G���f�����;�4f���� ���������h(F��[��SO<.���5���%3[���������d2�t*�t:�H���q����;�f���:|h�Z.��P(|N3*�����
��A�|��b.��N�O�t��C�!�pJ�lV��yJ?������Y���;Na����_��{�b]
�����UV^^�a��`@�����<�����U%%%�t�|-��J��U��D�@Roo�^]�N���e3������!UUE�=4�	v���G��SII����Z��=��C�������B��B�p��pA�@�TSS[�!
 ��S�TR�x\��n%�q����~�%����,�#@��K�D\�u�����C?W������N��4f,��`;�0�H����S{{�JzR:��o��+wy��������7�����
�TQQ1����������������q{4���w���O��S�������MQ�Q���u��A=��/�W�DGE)+����e��N�d�~���n��{5T@�`'�����AC�	��=�Flm��Y��F����1���N{W`d{����ui��Zx��j����T��&J�=/]O���fk�|��[c����&�8[�#��Q-��Y�O����(p�|�C����Wi���e���:,�{n�;;�����}q��'����}A�7��f5W�j�8��(�s����8����S������w��7.��*Cohs�M��|����Z�X���!�q�MK2��J�����(-a~����������/�'0<���{�yaX;�u��?:����O�j�
����_8E�2Q�����,[�#j��Tm���	S�O`�b~�������T]n����e����V��S�c�:IR�;���]�+���EU����Vi���5^R��Mjo����D96cmm�����#�I��W��F�a�L��&}���������������QIR�����z��?W�uP���Wu��^�b`����=����������Y��<"�H3,��B��]�U�kt�u��SA5��\��)���SrGO��1m��������G�8+%������U���#�L����q_�O`����������!�����7������3?����	_�O`x�.�e���0���;�H�k�N���+�NktS�>t�����`#�����{�I��`���l�b���{H��`"�-�BMMc4����C�'(h!B��D�0B��;�Y����?���:;�=��,���f������W����$I_[��/-����4���z}��z��W�������._�T�Z.-��
���#����}����<F���)S�qT��P���*���k����d�l�WT{H��p>��S�*-��b���������C�=
b�.8������-m|m�v�����^�Ri]u���=4<������������_S��[������k��E�����w�n=�����@0�K����i3TS[W��p�v��8|��^�U%�	�RI%�I%	%�	��Y54����	��]��������n���p�W]�G7if���0�"�7aP�@����������J&�������w�qt�f����7���W�����i�
�5�J>�O��Z��6LC���]�M�*8���-/x�3����^\���=��^RZ��4�n��?q���"eeg���PX��/������h�ZM��P8�`(�P(�P��`(�H�;��m?��0H;PwwLm�y�=3a�$M�8�=8��*��h��7������u�l�_��;TRRR��;���������u����"e��>�b9��L�*�������~x��i�$�~��N��)S���qt�GN��{���Q���(�������?Q�h������r�v���G����
C��y}�������D��
�
�5~��!
\�\u��=6z;g����:��b]����P��S���wwK��Z�\�Z.u�_^Q���Z�R)��)�b]�����m��v�~k�~��o����������U(����<w���3��O�h���
�-RV��M����k��*����l�%3[��N��N��J��/P��4MUTT*�L���v����5u�;��vN�N�<���6�b�njVYY���+TV^>���m�l��2~�q�'j���nK$�J%SJ������x��E���������������3f�)���<�=Ua�`�s_p�(-�����^����J���L���8%�Ion~CG��4v�54�.�pN�`\�z{{���g$I��\]��x ���7��X�KS�_�h����pE�.h===z��gUZZ�+�\Z��x"���6�I�x\3[�(�{8��b��&N����]���b� �pA�D����e��i��A�0B���v����^�O�����Y�Q�|�J���B�$91�|�=�D�:e�i������5���+v:��gwmU��w_�UwWT;������on{p����[�U��f�f�{Q���(�����v���|z�V����T�2Q��b��[�b����&�8[�#��Q-��Y�O����56��m��V��pV�g)��-������;�5��������/����u���JU�o�G�|�GF�D"�g�~J�PX��OTi�������vN���E�}m��o��UIre��,_Fk���V'��n�re��L���_�a8����	S�����R�.�W,S}U���N��2?����	_�O`x���-�����v��7��/o������u}��9e3��N��LTf����!���H���9l.j+��O`���ggG����e��W��y�y�8\�����������r��C��6��n��������\�UK#��J�7$��UZy�b���}z�����3$9�1�^X��z{{���%*)))�p���,,k�wmR�?00��$E��<��?_�1I��z����[>Q��+����k��74�*�)S�{8gmX�����Y/�NH�����������������^w�V���}���N���r�z��@��?���^]q��b`P�e�c]�\�\�q#��;V����lH`;r�]5u��0qR��0(�2�8�V��i%�b`���;�X0*��``� �!vF���`�Wr�����]�a	�p^���z=�������b��#���\6����JJJ4v��b��#���?��e��I]<�Ee����9G���LZ���G�����/.�p��8/����I�5{�<��b`H��/�J�O�^���5o��b`������^U.��e���g{8C�,�k���4��J&N*�P�+v�y�P\vF���``� �!vF��8��������xwL�x�b��}�;�Q���t��Ke������!��S"W2�Pww�������J���<v�.�d�k���v�w����n7-K��J$��:����PP6�Q<W<��x�[�x\�M����q���sO��_pm��~�`���^W]s����B�p�GH��7�c�vx�uuv*�N�����~?��+��(�N+�I+�Nh���_T(v�����)�H�4M���l�2MC�i���^~�����=�-onV"W.�}W�U��{;�5u�4y����B�|8�D��y���*��������`�!�w��?��D�[�D����p&������c���i��,����e��JJJ��}����
zE�tm���n����]�����������~��~�l[���m�=CI�<e�&O��y��N��������������2��R��R}_����#���6����_��>���\�PH�`H���/}eP����J&��rrr�rN����rNN����a�]�B��]1�1��"�[�l��0"L8���Q��L�p�����]��{�)�:��1c5k���]�Z������%��W0RYY���+*+��O��`(�9��TW�P����!�����n��qUVT������#i��[]��~��5s�l�������k�����m�q6�n�_��T����V ��������q���t)��+��V��s"W"����4��������z��z��Q�'�\ONNo�����Gg����]���x[�~��$�a�2,2e�L�RM�V���W^�:�?���SF�)������Yj������q����{�����>� ���|�C��^~Q�R"W�o�D<��~����8���M]�rNN�a�4L�)�4e�L�PMM���O�6CM�cdZ�,��i����%�,��g�~���������aug��NF;NF�zr[1A5A��������7��U�S�
)h���Bj.�I����9'����M�l�V�����9'�\oNN�#��/\������"�2��������[���*�d�u2�8��G��n���W���8i�%�,�N��=��<����=>���2���NZ����E/V�
������c�k{S�X��x��L��������s�3���1��P�'���U"W6��)��2�����x���ywy����_(�K������
T{>��!��!������uuu���C���jh�Kf���yg�v����o�e�nZ���U��\�r.�����f�rG����Y�\NX�a����[������I��0��j=J�`H�pX�`���\v���)+S��� �K(��R:�V���20��C����)����e�'������2����co�J���|��2}�L�'����)���/nZ��m?��k�m�=��J�������W�l\GS��L����2K-�`�h��v�v��.W��B��3�ye��RNJi'�t.���R:�V�I�g�����o�I��7W�����m�e~�<��g<�3��%���rR}��?�I����v/�����m���_�t���_��~ �O�����4�I:�8t��c��J�:�o\�3NZ���=���~E��=��Qu����7�G{;
��2d�|~��-���m����w�����e
Wx��K}�Q������B�n�
�����A��P�7W�1��]�\o��=h�y�g�`�y����u��]��/���������$��77������b]��l�e���Ni����
����n;�����M��N2��o�p��r�������r�����,��m��7�cX���������Si�`g���4L�WTx>�0;q���)�d���*��S�
)������/d)'�/?����g�5�f����b�����:�E��.u������<9fv�|-s�k��T������Z�6������>��D��!COo�g(��%�����|�/����R���&�������a�(�>M4�jF��v��_��(1e����k<�O���)U���t�3���L�*�J��{b�zj��n���X�*��5�b�fDg�����M����k{u��3�	���Y2�T<w����.�,I���?���W~#���1�����~,���]�9�����p��k{U0��Tj���0��	?��P���/���h�����HR�������8K��������`������u����&Q"_�O>��U��m�
z�4�������9�������z��
������a���M��.=zT��.u=�X�KG��+5f�{��-on��76��_�x��-X����S"�������@�R[�a������AS��p�_RZ*����q�"�2UTV*��9.���*�co3V���_��u)�+�J���K>���DB{v��o���LK>��P(�@�����X"�4�a�A���iy��^U-���3�����;!+�y"����ze�]�����|�R��C����?tm��>w��=�0�_A3�����b���O��������QSTf��=��g:�lW�+d��� IDAT�����fHA+���f-�U�n�Z�3���f���Op�{0~@���#����ZY���"5!�R��������\�������7��N�;��:��2F��*�r�m��fPV�Oevy���V�	'��BI����0L�J}�~Y�����2e�"�2E|e����S6N�'|H��u�:���Pg:_��@|�JJJ=���]�qO������V����R�u�D,����^���2_�R����������>=:�s5E����<0���j���#u����S�@s����/������K�]����_/N�`V�H���K�����C���Z��y��`(�L&s��c��[�	/R:�V:�R:�R*�V:���*�:l��I�=�_��=�f{;S�N����<��LD"e�DN�$FUUTw|��&n!���?��xI��8����V��d�����Q��>��y27�K�h�����gV�?���C���Ezz{T���yol�2=���z^�<��R�����Mm��9�J`I���h��5��������oX�E������q�����^Z�}2�o�=��8�*I�o����m�<��
Ya-���$��{*��6T�y�}{�M�L|�m�[m]iIRe`��I�X�K'��8Q�
kT����������U�>��YBK�vw�RO��X6�X�S�LL]�NugbJ:	}��K��c�N%������!+��.*$s	��]�e�N�����jB�$���}�a�}t�k{]��.����U3T��^�fL�8�������R'���8���Uz{{t$�&��o�=���������~2��������~LM��D�pWf�k�}�5�L�z{��&��u���bh��e����l7M����3NZi'�d.�L.]�����2���`��8t��������������C������v��g��*u�b���Tuu�*GU��r���jY��W�E���F�~����Z��=�?r'����������b������N�|!�)s_���s�~��'��qO�:����J{�Z��z>����L[�R�,�:�rA����%.�i�|�gZ�Rk��������X1���U��D�]�x���n������]��m�rmo�4����\�����G���n��
�l��[?�q�hR�T��`��k�kum�?�3��
Tk���;�(�4:�}������q�'�7�.P~��.�����f��W<��d.��R������|l�#�Jw���8����/�~�]�B(`*�����j���U;�����o��=O��O�^���?��~�{����k{U�Z����]�S��~����l��E|e���dz�������7���������R"�C�����\�Q�L���2����U�
���*��?��������@:���l����9_��n0?�b��|�=b�(��<����wOk~�{���s�7���r��������Py�A����>N.��f.�S.��-�YU�r������R��w�v����c=�������x�3Nc��+��M�I�O��R
��������=���=Ye����Y���|��Y�$�������u�+zn������y�+����9�|�a�j��i�4�WZ��}��������_.���UN�vJU�Q�������n�'��V��v��~��O<���������m)�M������3�9�jWG����|����F>d���{�����3�)���s���������]��/�J-��&FI�?��m�|b0RZb��K)p�y��k������'��t�t�Y3[3k���+$dy�_3��R�5�������O�v���hU���W��gP �4j���]���t4��
�?j�4��F�����Q���w	3���e�W���P���R*��+�+�sN�����
Z�����,�LK�,�F:�`��C�c���D���`0������]���O��?��2��G7�����*M��z��W���Y0�9���	�8=�=��k��eZ�,�'��s]4�D�T�pD���WC���#uTm�CJ����4j���/�yV�:�R:����g��W�}������B<��v�|�a��+��RSv����w�)���������o�,-�v�3�����}n�e���m����7e�Z2JMY�%Cf����:M�r/���:�M�_�����>������������������p���m��^�����(�d���(�K�,��B��zg~�"����n�]Q Xl��2���WH������K$y	�"���?��$��@��Y�.;�}wVLX9���\5U���Ej+�:x4u�'i�4�1�t��_nW����g��,5����"�L(�J+�I+�N+�J����4f�jj��V{��g�������=�sEJ.����{e�|2MS�i���
�L��j���$���W\��o�2��+bMC�i��+|U�g?�]_��+���]�����9'�����y�f��6�u���M���K���W��z���d��;�=�r�>p��]������o��������+�+��<O��zrzh���Zm�(Y'�/�����������>��^���7��t�#�����)Pp�����������+�KK
Y%�,���lZ���
�9����;���P��I)u��\Je~��{c�=KXM���:RG�N�v����[<����u�%�U��}�����,���)*���y�'�|���
�?��!��yi����������J)��(�L*��������y�{��_j��o��_���{;�i�g��}�l�_~�?����m��<����$�?qP��|�\v�Y���9��d4P�Y��=������RC�Sf�K<��#�v����,��u2:���n��7����3DUN�����y�����<���{(q���Tv/=����������F/���E���\Bm��2K-Y�V~�f_X����GC�W�[�O
����\OV)'�fz���8��j��8��&���U���m��3l�'m�]h���H������f�W��w���4C
(3��cS�rP�}q���TZiIi��D~#P0��t�`X���-%	%��`&�L&�l&�L6��?v�g��?�[uv��'�X�v��T���|c�m��c����:��)�,���ez�J���rE}%��m�Z�/���I�}������'�7��
[v����R[a_xP':O����\]���+�s=�����6�}-����j��9�6���a�����{2t�;���Ap�]^pO�s!����v_��������E���U��um�7z�c��������o��l]��E�ud������8i-}�4���������y��}|�E��Ism?�>������
�3-_tm�������}Ft�g�s0~@�<��B{���������A���J�����Y��jV�����R����>q���Rs��M�7����W��P�����t�`H�RI��q�������H��L&��TZZ��-w?�������~����tJ������y�I���!3�%���Rd�j�
r�/p�z���%���3|���^=�Nkv=��>��"�`�;���m���v�n��7�c=��zooo>Tr�}AEV_��U�����rI��_�`�l��[}�f,��d�$M5U�U��pd��?�K�h��2��J��_��/����[���W��oi�����Z>�>a/���*4FF���Sob,I����o�����g[�K�=��~��}?�O��������;����������������LL����B�r�B�]���5��o���wo�]����*��k�n���,�������<a��c�������z��?SO�3p��c�u��f��j�hV�����������w���O��S�������MQ}�j(8
�D\�T.�S.��qr��rrr���pDS��p���A���?tm�����4u��k
���|�|����,+�����I��W�;��g�]];���N�d�	e���|��*����Y���l{C����k��H�gY���#������[�O���N�c��u�Q�'����K�F�J��_�������p��~��>�?�*�������y
u������fP~3��V�
)��9d��B������1���w�o,���������C��NJ��v
��6�������>e����J*���Kn�|�B.�iT���1�
��^GY'_~*��S���Q2*���7��7_i��J%������o������J���������K+v���fT���r�UM���];W��/�/�g��|��`�j���R�5����V��B%�����N��k���}���o���;�}�������%2���2���������A�������;�)�N(�N�������V2��Y�j�5t��������vmon�����C�2}V>���d��,�%�g�
z�R��?��A�xZr��S���s�O�������_��Q�c���S�����>��>!�E<OhW8�k������&3��Y�I��>����	������=dy�sP���c(YJ�K��j���?�j�gpt:�dc�������m|�E_q�Y�[>Ac�'�u���l��������+�=�^�p3���6�9��7~@�#�������ok�-s������rI���KJ�S�dSJg3�dR�8e2i��H��v�������x�[=���'���W=�#���o������������m[�I��I���f�������q�����?[������7����KX�
~-�{��.M+����>S�m���)�g*T�}B��U����EN9%J��c���-2N���P(1=:�s��B�m�����*���-:����rT�����B���nT�%%�N�����Y3{�m��~<���
�m�;�Q��T}���kVs������#)vD��?��\.�l.�l6�WR,�}Sc�������{�������^ZR��_�e�!ny}�����E�����}��X�a�Gd���B���}�l�-���'������+T;�\���������aL���W����qe����0���VX���5=����w�����F���V�*x/
Us�_�������P\�O`�b~����������������`G��IS�/��w�X��_7d9��i)�8��{��C�%�>������
���+��|�-[>�/���v���.�t�W�U.�^������=_���sx�b��b���/�V�z���%^�RS���g���vY���C��hQ&*3sPY��eK�f�����=a_{���c�fP�KU�Z��s$y?p>�0|1?����	_�O`�b~�Su�]�!������oHh{�����/)��&�7EUgHr�=@��QZ����Z�G�����#&)vP���Wu�'���CB#o����uWjU��w�}�TPM+.��7D�=,�!5"����R-w{ ��X�
��D�0B��;#��A�0B��;#�Y�����<,`�+-)a~����������/�'�|V����[�A�0J��;#���.r)��w�X���4�n2�Z�����$���G��O~��1�|�]��,PKM�}��^�{�}�M����t�V}m���S?����E���E����u������o��3R�R3>�X�����Tp�z�p�N9?��J��7h�����{�R}���y�V���y=���W���7i�nGVmT-��R7������c�O`hy������]�U�>>��n�s}uUE�����`�"�0Hi%>������KO����Wt��	-���e������on����2Im��[��GVj���'�|L������R��	p^p2j[�E���zm�H-z��k���*��?4+�o�����zh��t�,��|-�@a�����i�U��E��+��k#J>�����?����%��)0h�����*x�G��%����w<�gf����s��	��3�)z����;N�y0��(�`��Jt��"�>����V�����	�$����45��S��%)�
k�j���5>")���������p>��/�������Wj���c�zi]��|�Ye�d5M���Ko<yPR��Z�/��<�g�������zx�V\�%�l�%ZT�W/����S�p�����Z��o��L�������
�1�'0�<��Od(����`��0��b��8���ZW?���jSB���\}��q*3�'����F������Mx�Q��T}���XVs������#�Sga�>�oH�����9�q����;aJ�5E���Q%T�=_�^}��#�����T��S��Y���7H�w�$���S`�������f����XT�&Jr���Z�O`hy�O9J�r�������6����?]��ES*4���U���p6X�`���4j����oo�w~8[������$9J�%_�T��_�3���>Y>G��$9�&MY�����}������G�t�8%emC�t��[�}��6)hJ	G�B���/���z=��	G���6�����T��IV�T.��������E�}m��o_�EUR�9���;���R��FMi��O��I����������uI�{��0���cD������4Q+?�Q�X����S��L2-��qZ�!�����'
YAI2dr�f�/��E����Ae
C�]��cACV:��Y�)���4[���4��=_=�4����

e3�TQ�y�I�Q)���l0��)p�d7o�=_�$�S�����]��=����{�m~�_�L�����[&���wk�3E-�y��0F�`p1mY�P�����%�9I�!�P����v���E��Kj����Z�$��oHh{�����/)��&�7EUGY
�����*�I:*�������S���������/�A�|=���V*��Q����_'�C������H���)pd7o��_~[�w������
��2?���:?����(7�YM����C�4���c�b08N��~�I���6e%ewo���ti��f%5-���������$��O6i����]%I�,�j���kGLR������OT}Q
8OE�5~L���U]��}g���iC-�k%������j����m���b��Q�S���c���7��)p�Z��]�T���t�X*8��������9�����{��2�mz�G;�Y<N�

��/�XIoooo�`dK��A���Io�I�
Wj���j�������Z���:��[�����j��7�NL�i�z�M�
�i�\�����r#pVv��W���.I��	GY���!5��}�����O����zfCB
Tj�mWi��*�W4���}Rh~z��J��u�77j������z��R�.��y=%������Z��o����/|L��.Xp�1?��Sp~j�C�~Qk�����������j:�:���S;#��F���``� �!vF���``� �!vF���``� �����A�\��x��9K����~�;�������>�����#�b�
9z���37����
�������]���[�EmI�/)��P����/��DT��
��]j}+���Z�8*��������h�C�`���h�]?�}Z��&��������|/���H-5�������:����<]���������q����U��S�^�A���P��Z��0]��r��?o��DT+��-�p������e�^�S�"��O/���NK���C�}E/��)�6T>�Q�n[�����}�I}���n{p��������JH��W�[w����AF;|^��y�vt�HD��D7~q��}���_��V�p��O�s��:�%?��n�u�����M�~w�^ZSW�P��F-�}�V��c{�y�������)�J��-����y�N��^�}����zR���c���+�r�!����y�NM���J�f@��:
0IDAT�v��3���~n[��S�sh��������N/oN(��w�'u�b�oHZ�O�����-&Y�Q��q�n��V���e��z���:����5-���~��?a�T�s��'�n��w�����/�w,��	}������im{_�I-������L&�>=p��t��e��e��n���]�Z:G��5E�}O�D����Z=�t�:�������[Tv?58S;�0�}f���d���`TVl����������q��2�R�^�y�������������������_����q�	J��������d(�b;��t�YM��:Y�6����*i�v:���[�-
Z&��-(�X����s��K��;�q�!�(8l��������}�������q�}����0!�-�����5�\��?{4��x�V�r���'o�2_8���)��cs6N]��g'���+7g��Of��&��X�+�l��ox:5�W�m���&��P��M7�f�ufVnh��������{�}�'Yw_%�qeV��K^�L��-Y�V1����bj3��e�]����h~6�����zq������rW�~s�||^V�xJ��*��}S�������,8�s{�g���I��K���b���l�qs�}���
�r��Y���<xGs�z����t���~��UW�:IR8-��e�?���{�dJ)9�������yj��,>g�Y�����=Yk%c�����H����cG���t��/��=)����LkN�x!���'Y?zIV\>4��{.�i?���:mg�&}��q����7����?G}�y�o��f�e�������y����]�2���C�9��\�qY�V��o>�;w|�5)��P��?���������|�#����
���3�W��
{'d�#�e��B�/�J��_���Kr�'N��pr~�w=~��&�����u��9�.�W��{2}T��9-�/����JN?�9M�b��%��rG4�pV.<�65��L�fVf��K����
n��m���+'��.I���W�����l}z��J������8=�zR��Y����4�N��Jo�>�?�/9?���&I��)����9���y��]�����!GM���I�:I���;�z���)W����)������f���[�����9}��Ypnqhn�&d�[���w�������v��i�x.>��Mk��ks?�e��}����gdJi�q�����������R19���O���E�i(���������2��<��|V�5�R��,������7��
�/g0��X�~?���/
u�����y��b���R[���W��#��G��}�}���$��������i����V���o��J��-'��]7�N���Y���B�#�b��������s��Br�p�L�B������)2�n����
<4�a1M�#B�B]��������������Y?��Y�%j&�g0�T!�M!�O���\U���;i�\������g���k��z�w���_�`���3�d����d��}�xnod�U����s��=WhH���������k��z��z:{Z�g�]������7�l���1����#�
�=���y�z��;PN����������[I�I�S3������O��M��f�y�2s�fZk����'�����U?����i�qV>>oBf�)����NxM���\?���`o����/����|>�\�+�f4f���������7�G@��	�����&�������4)+~zQ����
��U������������s:�f���G�}���L|W�s�&F��A�+���{K����=�5g���/�:/�{O:������g��/��W��)f�MK2������;/�������O���wL9�j������Y��S���+/��I�S���{w����Y|����c+6F��j #*x*ys������k]#����g�"I��R��MW�1/�������"�R��%={������o�`���4�����P�����v`��J_����I'Wi��H����]���o����?�����Yof�ue������;�=���s�{Du�q�vB����B9�{���<���19a%�����d���g��K����y���yeD��r%5g6d��Y�van�gjj����c>;���I�������Ii[>/+Z������?����p�;c���dow^|}���{g���;'�������$H�#/������n�Rs�����MwmO��$��to�E�}��l����Th���s���g������rgj�M���������Gj����n��M��}�I���{:�j��Nu�I)\��<�|�:\
�t����)k��z�~6����7�L>{Q�)e�_]��}/d�7{R>����wd[�q�6�tC�����J��[��$����;���G�����j^Y�hV]�=�����/��-�8�������3�����M����@�w��r])MG�>�T280�s$�<<|<8���[��l���Y{���;<������I������[�p��?�������~?��O��������y���;������P���Jya��i�S�`�!��zq���m��o��f���_�3oU
9}������,���jX���x.���h6�V�R]&_zQV-o>�4IRl��{/�Sw��u�n����4Lo��{.�����bI����>�5�2�n�$uui�73+��:|��r������Y�����[l���������>��,��p�U(f�c������u�q��Yp����6�n�,�F?��+~�
�IMcC�-j��k�D�L�R[��5?�zg���$����35�����=������������<����V����d��/��b�T����Y����w��Ot$Ij.i��k'����I)m�}2o���;/�����b�./�(�?����{o������A�Ktw����J����������l�P%;U�VlUB�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��T	�@��o�^�z���IEND�B`�
time_comsuption_without_indexes.pngimage/png; name=time_comsuption_without_indexes.pngDownload
�PNG


IHDRv�#��sBIT|d�tEXtSoftwaregnome-screenshot��>.iTXtCreation Time���� 05 ������ 2023 23:01:04��`� IDATx���{t�U���wM��`��FJ�m�P�T��P�6T9Ta�����yt����Q��sP��k<G�*L������&�r9���)��FeRiHi��}�h��R)���k-�2�e���/�,W>��#���P """"""""""""�Q�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""""""""""&��������������	;""""""""""""aB�������������H�P�#"""�A�.)d��U���#��������?0c�B�PDY�k
������Y�y��z�����[p�K!��3�Im�tWN�����D_���,*<�gjT�?�<�������]:x������Yh�3z}��o}ODDDDD.��P """rA�J
&����/�&��K��.yI�eT�?q=�o&�����e2-*�����}>�^,b����o������	iMa"!��Y����~���^����_�BL�N�4�+Qy$�L�<2�~)���`?�y7>Y�o~�2DDDDD$H
vDDD���0�f�#���,���PzN��WA������DN��(��j��@������b~Uew�9���E��/<�����g�9(��*�P��::=�E`��B7WDDDDD�M������!:gb+�_���=e$��9�7�����y���/����L�������k_���G,}o�b�}ID�����E���r�U`s�3��!L��d��K
y��J�G��|S"S>������,�����e��0sM.�'p����B�f�P���x�g�/+_���+��� �t`x��Z�����(W<��F�({��zYu�b
�7?|�
f<����0�������R:������1����9��#N}���xz}������[�����L�k�]��q��O�Co���8����^*��m@��mQv��'��"���]i��N�[��Rp�����<<�}2����$��*~����rH����(�����d�
-�K�c?��
���MOGO��&�|!���,��~��&F�g�S�������o1'������i�}�������)L���a����z:g�g���N���
�?��UE^�X2�O��H��;Y��6J���Zq�����f�j��c��,������A�	�G��K�������j:��m����]��	DZ�:�@z��W�w�v�$��m����/�F��>��x&��6�� x>^���}���������-��{������7=L�9���;#�3���n�+���9�I�=��2���i����v=&d3�����i��{�*^}���uV\�2��x�����3&�����������#"""���L�?d�t�J�%���5m$y��~�|^������9/m����������xOv�^����yn/���#�����,�������J:��D�}2�y�3o��P�5sR��/�q���������I���?����4���2��6���_��56�����w�����x�#���R;��3o}.&2���\�t�-hu0p��?6��j�8����M�>���81��{����p{.O|7/,IN\+CO0�XHH�QST�[|d>5��>��9/������6�|�C�3S��q:/��M��"
>�W�+���j<����9p\M���<�i:�>J���pnJd�_�0%��s������GO{Y����I��Ew��������E��g��5vr_m����g��&l����Y2����m��rb��WV�����:�y����2J[�Q��������#���t�-��_U	�����L}�����i
,k�_O��$��
>������7�������I7Y���+4���s��P�D��0k��b�����(a�k��8�=	B�6�����<^Z7���R����c4��4~��t�m�t���3������b���i��y&���l����8;���%�����7�/��Z��Yt�w:����Ci<��n^Z�ALQ1�i��>�����������H�Q�#"""����-e��?��3�=
�����0�)�+X�b���Q����i����}�{_��E����m=��7!��=x�
6�w�/�2�����k�f>�E���n���H0�0[L���M���-���z�q�bI���~���E�t�V`T���#���M���L��,���e�����1�0[MM��D�-�5*Y���/��In'a�F�U�6��i���:�ic�q:,D'����S��D;���p=:��7��9l8-��j5�	��i`s�$�,�����\��G����
�_A�}Kyn~���{2�0�����tb���S��{�`����t\����C{�W��>��>�:��$FL�o
�R����8F%��q��A�8�b'��tZ�[��R[:y��'�8�{���6���Dv`Kd�3}��f������2g
!�<[����QSf���V����La���M�q0s��$��;��xN��4�N�.5��� �6���J%wb��1�~���eB��W��s��&1QM_[�<��8�������Ne�6�z������]�g�;'#�O�i3a���-�m**o��-��s��8���������m�&"""���������;�3��1���O]�|��Ol	���������?��.N<8�G8Tm"!���Q���2*��Gbt�Y�)H0�<�;�|�O���l� >�����{��j	�-�����2Q�>c��~C��+��qI���J��������o�6�}��}-��A&L�h\��r�{(5�D����^��Y?������N������}>���E���M@C�8��8Z|��8m�\}r�����
�����M<U@�m1���in�<R�s�8fj��M�$n�/���^��o��wP7���"����~9Gk�n� ?{��4��z�����QjU��������e���mo9a|2W���[����F����D���PO��E�_���^���3�O����3�k���
�y?c���'"""""�~������!6������^���7a6j9x���~�o�k�#����s"�i�&�x7����4��
k%��#��s��B��������w2po9�En�6�2��Rr����28���)L*�_��=���y�V�}O"�
+]S�pK�~�������f�g�p���T���f��@-5$6o�,���x������i?�Q��{���}A���m,�U���1������KynS�
�Am[���K����ZN��rv���U�wc��\v����yu�������`f������g�c:�����r�����DDDDDD���b�����KL�c3��.b���l$�������F�j/�'������ap�@�C#��[V����K��f�%!�������|�}�����zO�t���h�U%�8N�g`��D�������[��/�������`9�[m��1�~YP����A��������a�9��;^QM��]�c���}����9���O����X���K��b.i�/�>s���2�2�6f?����v�� �9�U����L�o�
�����v_Uo�J/U'�
�C�k�>�a�[pf����H^2���r��oz?;=�z�1|p��%��?P	��iq����q��V�@�q�i?
vDDD��P[���{�����R
����U���{�qMI�ko���9�1�k������h��;������_k>������v��S��O��s��b�_*�`�9�9���������V�����}����a�������M��Lp��S1�����b~?�=ol�E���i��`ppY1k��sK��b\�qj�}�o�QZ�|�=���9���s;�I�MWN<uk��q�����1���+P�����5���W���p5�/�i���
�����T����`����c��^);�=�}�K�Z����*g��{���jkg2���N��r��7_����C�#�)���v�j��nC-{���-�~�P�}��U����"�9j��ca������b6}co=u�85���py��j��a�����������o44��=�S��[<1��d@�;PI��JBb��q���]���{)���r+���O�|�����g@�]��>\#�N�	u��~UU�g���=�����DDD��pp�
f-:���><�,����,,�$w�\;���i�xs��_��c������x����8���e$�<���L����~��*�%����8�nh���=����f���<�`�K��y���`�z��Yv����#`5����U\�����_�_{���`v�3����8�}iu�?���u���u��C^����v�]��?�i�u�����F�Q���?�p���$�j?
�]M[R�v�Z���4G��~�������#x`!E]�y��CIo�*/s�6=Y�sJ1�l8e2c��������R�]�rUL1�����<<1��L�}`(�O����N>����ExN���>��/la����6�����2��Z3��}����a��4�9+���������F6������?��#�����0 ��3+�i�d�����s�_&'{X��[�8l$��f��u���-�8��#�fD)������=,|�����H����;��}�h����c�o�xk�6��������E���a!�������o)��l�N���{r;'d3v�:�'���.���w3�����y����y$����������<G�t������������.����|�6�f^��t��8���������������P!""""""""""""��;""""":�����
|�X��4q$y��Y�#"""""r����0qE���(�	
vDDDDDDDDDDDD�Dd��!�u
x}�P�!"A���D����.CD��9+^4gE����Hx��iW�X1Gj�����,	a�466���K.,�����P� """""""""""r��e�#"""""""""""�c�`GDDDDDDDDDDD$L(�	
vDDDDDDDDDDDD�DX;����.ADDDDDDDDDDD���`'"""�%������������\r��.@DDDDDDDDDD�r�~e1�����K"S�:��q����T�a��[���&l9��~��!.�$��������$�z����R�#""""""""""r�����T�|�����n~5���Nr�_�fk~�6�K���sQ�#""""""""""r����1//�`�����7&����`��
�����s��?����Kyv���w�������zb�c��Dl~k�]�����S��8k}���xiF	�^?>Jx~l	1������}��X���:G"��g�{6�R�K
y���-��y��6p�����`r15���?=�kZ��;)q;�}�H��Y<g;��L��a�=�5c�.X��?V���:"��� �f��b���~���^�c�hf��[x��uL��`��m�:XO`�0^���t����9%��4���������v�.�
�?����.E�b�?v�z��V��8R�s\��;���KZ�����{3���
M$$�(gkG����n$��_�*#����������(�Ia�`�L���a��V����.��_l���<r��oE1�u���,�h�K����K��vH����3���b���h�iU��l��
LL}�N2�<1��-$-�&����D���7�>L]2�T{sC�x�$M�73knS��#i�RJJ
�����u������c�.'���,�1��C-P��E�x�|u
y=Mx��`������w���r���9�������f�fU���t�%�z�_n`�sS���2�1����9s����R��vHcx���P�C466����v���?��m���J>|


�.I�0�k������l�]�w�l_�Pw�5FEG�y����>0�9s����q$��fP[Y��N�m^��O��>j<��lV�s�
k*���pM���v����r�1��8����V���@��,�V�?�q*�9�FR/;6�[.�����p����N���T�#��,�X{���w����+����H
r��o���]R������g:�za�V_��l�z�c��I>s��H{$���l������GGv�P�t�NDDD�K9��!p��w�}AU����N��������
]o����^����<����	��p�e�/��2
��b�"#�s8G�|E$f��G����F
�W�V������'&+��_g�y����0�y
b\-:�Z����y[�ew�t��L&����em*���-T�SW_I�/�����5@������h+�[�k�:_�M|��k;�1v���C�Fof�W��������%���.�UVz����M�0g�e�#"""""""""�����A��=�Z;����|^����\��c��k{���<	'���loxX�d1o�c�=N��X;s1�Awj!uB63'd����/�$�e'���q�h�d1�&j<>���T���:I-W��"�68�DY��]2���,
�"���c��J�����(��
G|�����������[+��`����	��r
g�&Y7��*��-,�b�h��N�u7�G����y�}{�qe���|&�=b1�/vQ����7�j�������R�lD��z�<RoL�O�(�08��2�uO��|+'tI�o�x��2�l~y����{'�����/���l�����6(�^�������_��������c5��v�

�7�[s����H,��,�
��ig}�]O\���
�H�qm��	���V|�����>\S<#�����Kyv�g�>��?�W����21���]��������9V$1uVZP��m����j��6qIL���g�.�m��>9����yb����2���������gV�����`��4!�����m��'.����f�,e��;��F�{������?>�7�c)��LDge1m|0��������"��[���8�E$��c;Qy����H��9+^4gE����Hx��9���:*���������x�q����������|���5�������W~�3O�[��V.ry
�;a�E���������H���|�m�]B]�%UYy�������W�9���b����>\q�Nia�����������\Juu>�]��#G���i�����P�t���z�l���G�2z��V_wUlC��k�NX,V����X,X���v�b�u>�8f��[��VL���p��NDDD�K�	����%�8�m7�o�P�[[Kcc#�11��_�J�g�7m�__��?�S�����M���KY(�� IDAT���CX;""""""""""���UU�y��;z�A?�!������w�}����R}�[����5���������J����6�;v��D�
����j�#"�����<t�w����uu���Md�d@��}�W��������t1�oF�O��[�g�������U=������S���~����C��������������_���%

���	�_������q8	��X�A!?]�������bm�����z�)Y������"ri\�~����P� """""""""�1�h ""���n�(��	�=���i��s^��=_���x���������3��a#������0LIj}��5��	B|l'*�u"$�Y���9+^4gE�������j�tI�jX������w"�f���6[�K2��ru�sdX�5�P:�,2�Y~�Bf��
O�S!-IDDDDDDDDD.�*��4��w#~v�22���~>+Z����"V("E�?c�`�6WY1�����+�'�~mCC��le��������8#G�t��vx?�S��K����]��65��l�W[P��%�����8���mM���<1����y�y(��z��t�`�b'+b�8-������3���>g�g8v�(��L'�V�+�s������������%��6^}x�&1}�%�^�G
��L]@��5�Q#ya��}����_i]v����y��Zu��0<HDDDDDDDDD:�o�v��{{�]��vl�?]���^Rz��s�p�t�*��@��p2��t�@�L������}�F�c�`��oQ�5����,�P�����$�z��y��eT�
|	��i�n��V���Jv����}��SS���<m�JO^G��|�+�Tz�K�`��\�/��`E5~,�z1���m�]��=���7�	��l�?�Dt�{:���{X��zVm������Y�SWG�a����������,||�5{����:l�"�����c/�~�"ra4gE����Hx��	/�������,�{����{���������g���4~z���g?E���C]V���.��`�������V�'%%�����u��Caaa��m6S�Li�z`5���Zdp]�cac5�H5�HH�Q��:���c'mj�A�l���l���������2
^>B�+S��
���x�rLA��x)��o_@4�L����a�h���,���]K����e�CKY�NR;l�V��'7P>tO�����`�=+y�5�_��������f��t�1p/)b�V/}G�/����c�#U{������r6 p�������|VD:���NT9�2D$H��"�EsV$�h����p�������OO{.g�pe����o����+?j�z���?ab��j��w����o�&��^X��:l>�����p8�&9 l��:����;��_��u���'��s����(�`��r�5��>?���Q���'��3B���UP�%�����&����4�0�>:�yL'Ii{�|���a����l��+�N�~��������{����~��e�����a�<��f�=��&�!��qMJ�����C;����pWR6���'��|�xn��~=��C[���������H�����|^��+�����=�|LL�9ZA������
�h�����w�444`44p�W\��/����,]L��
����1��uImr�
�C]B����?���?�}BB���oxQ��8_=��t>��	��p�!�5��D�hg�&���t��v��f ������U��PR���H<^�0�V��T��5Y�q�z**�J`{=u��Z��Q��������������J'���d&^xi]�v��ryi�����W���ylAN���DDDDDDDDD:��?��������.L�<����5K��i����c���j��[�U|�5+W|��Un�?���n
uIr	EDDqA}\H�iNs���w%�7���x1���2�0��g{s�	���:0�Zj��{
R0v�_���Lf���������6�
5�@��8u�z�+Q-_�����:!����[���W����^s���}wl�O�.""""""""�#���OHd��_�)�i�|�OV~DC����e�g���7������)��K�����#�}���>���F��}�']pa�O��nJ��{��5��YP|�zl�N����M��`��s����<�I���a�����X��Y��G��IAm�������Mm�R�lDr������b�L��73o������=dKDDDDDDDD���w���r����o����e��%��������5��\����#����:l$��kB]��(��}&��g�x~�zv'���2mps��Px�
���0����Q;�K��1�Gn��������qvR�R��,kJ��6�\���#����x��N�+�133({r+/��c���|ebV<�/7����^p�-��>3��9�x�}�0�u�M�5:���\��������i
���IL����v"�0%��8Z�Nq��\T�|�������Hx��	/��"�Es�mj��Y����_���L��u�C&�����b��&R��Q���[q�zy��.F�[X���QDDDDDDDDD�O����w���[�������R^_0������D~$��}t1�_�tB�o�����HqYrQ�e�#"""""""""�u}�r���L��39z���K���$c��[�|��%K���3pZ:��
yt��<�b-���E_-��,��;"""""""""���a�v;�:E���VY���=��z���o���:_����Z>+���>'��d&N��EO�����d���P�!�@X;ax,�������������k�+�11~y�}�.�������J�h�������S>/�
@�Uq�d���6��HG��������������W�Q��������<$���T��g��b�n�D���ST�s��qC��B'O���/,�����P� """"""""rI�}�����H��	'sMrj�Kj7����y[����������rn����b�'"�!�e�#""""""""�c�}���Z�!�N����S�����������q�:F�M�^������`�43l�(b��X��H��`GDDDDDDDD��l��|�a=Q6�����8g�KjW
��c����=������c��:��]����H�y	*������������t@�����q0��;���	u9���@�Sz�������.���>2�>}3B]��H������"����h]C��� ��v����P�!"A��	/��"�EsV$�t�9�C��	G����O���! !�cn������]c�yE���+�y�u��/X���q���5��b�����/��0a��f�}�qY'���-&�?'��#���VX�����u	"""""""""��!�����z�b���j�>>��)cn��D����)��@5�����;��WcM�.�$��%l���7k3H���9��vDDDDDDDDD��b�G�����{���&9%����������(k���)X���g'��I���+X>gkv��0�5�����4�R������&v����������13����g��j{=��4&�@�8��6^�QB�����[@��1<�@<�g_�:-����H�����M�T��B�*��#C�ys^9��
\�:��&z)�\L� +�O�����m�NJ�Nn_0��q@�~����&��C�vOs��V�����6��Hl�+��Y���7��C~�d�����2��`���u�:�0{��<����5]w�!N	�*
�D�����u�`GDDDDDDDDD:����u	r��{d/������n�n�fh��������~�����(nM��*4��l���u�=��>N$�E��/��Lf/O'�z�'o�0'���M`2a���]�[yp�����~�����������f��t�1p/)b�V/}G�!9��?�`���Yhc����U�[���*01��;��3�|��'���$�TD'����4�0u�HR��

/���4��<T���LY6��YK))58���'��7kO�������V���$��@�N��%��)��4�Y��9^H
�V���'��:���*�B`�����U�ncl2�=���],~����Mafr���`�k88����j�K��[�q ��d8;""""�&e_�d����M���#�������5�����y2"�@u]5��v����F�9��-�V�+*:����z����$����,�D��J+��y}�N�m^��O��e�x�.��
{�aM,C���<�)A����r��&2�L8����J	�d���[�T[��P��P�$I������D��[9��:o=.�d��!��7��Hb�(/�=D`h|Q�;�����A��i��TT���n�vI����=��=��k%[}�M�����R�sl69�g.�1i��S����������GGy�.��vC]���������(�����#|��[����������?/y�"���X,�P�$rY���A����^�4����.�.<��H����lx���:��_�]e���>DF6P�6p�h��H��S��-��m�0~�-a�;�y��zb����u6��/�9�� ���c������XvIg��d�li~_����M�Bu=u����m><9\d�
�z������� ��U�C��T[l������� �l��J���}���=��5��%��J�����������vDDDD��0�����M�Q[SMDD}�]�������C]����H�:|���%�p����#s��\�+������t�	���W�����loxX�d1o�c�=N��X;s1�Awj!uB63'd����/�$�e'���q�h�d1�&j<>�����������V�"�68�DY��]2������-j�9D�|�������������91q�'3����98s$gB����Y��_���&_��?W����}�O9�o��X��<�{�G��T�+�7wO���1���4l�\L������1���K�.~���%��9^WG����?k`������g��#3��b�{�~#�����_PM�� 5�F$��g�#��$����*��-c_��'���rB�����a���.����WQ����w"���l�������!��m���ux?k?o�+�E�8�;��1V/kg��p{��5':I���b:�2���9����hll$5�Z���yu���4���aQQ6�0!"""���G���������G9v�(���w�(I�)�������ap��A�V+�������5���z_�w "a���{�2�R�]d���c�O��?~DA��LL>ws��tb����wN�IL��T�c:�>��E��M@\���Y��k;�O�f�j�o`�D���f6��q����,|�-6�m$MH����i���K��g�Y�K��7��N�����w����������X��:�YYLL(tiD4���5����@��� ��v����P�!"A���3?^G�N�mb\�����r7wM�A\��"W&�9+n4gE����u��������v=�vf�w��*�?Z����F��S���9g7nXG��
����q7�|K����(]c���H�t(Z�#""""�
6�HN���/w��;"""��|�c|�.���T|�5�>������n�[m���]����V�w�uZ�s�������u�:_�������$::�N���u�����ED��P�#"""�#�w�n�=��7�o��RRzp`�^�f�K�""""',{w)�+N>��J"�[wL�g\y��������>������s���g:��LoC�"""GX;a�{����H����6�����D������Hs0;+�[tLW�9)���������������;���a�u����9���>}3HM�Aw�5���is�����*.�"T&""ri�e��DDDD�N�W(�t-+��Wzo��.��	�)=���Cy�z��l�~EDD�}���7�7n�����sY�:�g���������i����7o��_��b�Os����V_C�O�e\�p�����������w�.����$%�0t����%���J������8���������>g����zk��7����&�y[����U����.]�u�r��Ill����wM8g�����_7���v�s�����{kk�[�QQ�#"""r����K���M����8l�$�^����&�1������?������;v���|L��L��l�g
<��4-EDD`�G���r����3�����[���~Sq��7�|��k.WI�$��{��q	����\Jj*C���n�]$$v���]���ECDDD�.:&�[>���$,k��g\�I����TWSSSMmm
�����I�&���SR�p%%�J����y"""?z
vDDDD.s������.CDD�U


��k��[�u�=�m�~bb�6����E���v_DD��,,�����P� """""""�`����a�|��������4RRS���������"d��Z�=J���P�""""QX�RDDD�K�Py� }�>�Vy�����R�?�)����4f}�]�*�C��#l����VJ�Uq�s��P�$""�9���g�)��%`w���aL���
]���{�<�hm]y!m[�d5O�-����vGs�o���5a��������Hx��)�o�<\��C��n�`��=��UF��=C\a�WU����Sv�}@|B"?<$�U��H���zb5��9���k�9��W^���ILa	���Q�x$�B�P���m�y�H^es���v�WZ�`GDDDDDD�2q���+�������8��C���S�i�7m��v�����N���������C)�l{��
�+��4�k�I����wt���&��DoA�`���X�jV�d��\��%v�����$;�'�I&'�����9�g��d�8��\dY�jV����
@t��%��E��|���������>�|	/��'#""�Zjp���U�(D�@�<l�T���j�}u!����?�
���Um��m������c����)��G50�}�'���nYu�C�{�����G�D��\(?���gObk�$m}�x��#�|9��]����U�U�4)�q���m�n -(��?[�R��K<�
������"6T����#���������_���.�$+[�\���""""""�b�[�cll��/@qi�R�����|Qg��N>��. )9�E�/(�&&&�����b���6�b�2�2��X���mCs��	4��!;7K��@BbR��""�IZ[[q���	�'&&b���^7��8r�����r96l�0�uO�=�:�}�!"�P�0��d�DH�T���#8�a9�ao2bD�������8q�������~;�y/?�-�@�+���.`�h
mH`��+:���.Dz������P	^� ���)�~@�g�z�J+�m��Zz�\3c�O�������
�X�������i��{���?�{N�G1���B��������9+J7��7}��CDDD4C9v(���9�.�?���������R�,�l�t: ������������(.-GY�\��j��g����d*�.G}]-��:����#� !)�y�(((F�N�q���38|p��������G&�>h2����������P(�H��Crh4$��N�~��5�X������:��f��������|�������F��[��������k�������"F���+�L�S��6c��7J{8��8� B����c���C��@�����o%hP0O�m�vxH�1�t��j����a�M2��S�7'����	&�~(e@C��a���=~/���<$";cccBG """
k�
u���w�j�z�_�H�.��a3Z��P\R&H"��D.W������@?._<������vU�� No���P>g^H����������x��g�x�r�K�����+148���*4�������]h���W����>����+n��a����6�QRV���WN�������h�Z�D_|�������u-M�^�������z0�VDD3Yqq1RS'.��d�W�������� IDAT�^��c�-�q�cwJ
>}+���#mE��|�hdP�h���V=�N��(?�_�������_��5v@,�w�
����v�vXD2hc?��B'����(M��P�[��Y/`�k�����]P�-?�������"��%t"""��VW[`|{�de���'G�����Q�X�~#V�^���*\�x=��hmn
zagd��cG���e@n^�nWP������b�rT,Y��0�j��T�_)z��Q�<��m���jDO��\jZ:R���8sFf6�����r��r��t��r��t��rB"���DD4u
�
���$�H$HH����$�$Z���^/>�4X!�-���=���l/Q� �����[0l����p����b�y~���@����4�u�@�1��\?�1��$V�[��&�~H��p^|���q�����o
(�un�����""""����j�F��NBb�
Z�'~G2�X,FIi9JJ�a2
`tt4hcy�^�?w�O����1!����������j�`Q���%&%������Pkb��j]\\R��H��H����c�����\,.���/���'��v\�{}(�Y�]"$	H�n����H���k@��)lv��LR�6�>j�_�Q�;��<��(����;��kH�m8t���o�Oi���Wv�#�r��5M,�s�_����";DDDD3LSc=�.JJ��Y9������NA�LDD3��������0�=##6�T�igimm��];a�Z�R��v�F���O��P���EVv��1��h��`�/�c���������1`������)<�������p���`��YW	�tX��-��S�/�z�
��k��%����
�dm3�
,��'�q�����5������Q��s���u���}��)yA:�����]"�3K��?,�dK�X���r�j?~��O���_����'m]!������6^L�$��������N�XXcuxa�{��ADS����w�)t"�"���a��Qu�
{����S���+�a�G�b�r�g����%�,����CWg;�>���;�N��^�����zQ>gJ��!�������o��7,XT�E��B,�
/��l��Y����� Gcv���O�����G�%S�0h�EDDDD3LcCTj��E���477	���hf�|�.]8���/�_�q�!�0h���������������N�61)�|��X�|%�:DDD��������}�
��nA����d�cQPD�Vl������($Z��r:Q4��Qr��I)2����?"����������T&���=uG��MD"����>�i�.�Cu�5�\����c��E�3w����r��������)D�/?���
@�����S���"HDv������|>��x����zM��1��"��4�?x��#�!N��8z�k�o���QUy�/�GwW'���v���Hx��yx��yB��`a����h���GNn��1n����q8�xo�[p�\����!�j����%e�����DDDD49v����������������e��+����8�tqq!�����&��Q����FFF&�p���Q`a����������T*��1n�����{W������H�������������g�����:��)t""""����"""""""����j�?{��^���K1������3���!"""��iokEoO��1��n+5-�z��p��[ �H���������W.	������&v����"\oO7<�i@�(~uwu��7_��sg��BD�WQI)����a��5�x<���#��/:�0������m�>�3W��H���\�����H�dDDDD����U\�p�ii��
B��PRr
�2����BD4%/A���8q�h��cs�]x��X��M����:E�0]�c���Cc�J����o�,D��#xc�[�`DDDDa���
��Y9BG�TVv.�.z����BD4%r�k�m����u��mCG{��;�q����(��ga�$m���_KF��$ga~��.��������J{[+�##�����������O�M
'!"
{w�D[k���f���Q����(�/D�|8}���0��X������j@~a��I����N��I�h6��������gcC���x�,*�^�F���2D"�?NDDDD����:[.����E�H�����M����($P��;:�EG!A':M�l��j��V#G�=��b:9r�����
�lJ�R�D�s�h��V+�~6�
���`����.]���w�.=6lDRR�m�������������?����='�h6��,Q����	�hF���3���N���������;��?����+t:"����CN�c�q�F���f��,��/������	�hhj����(,.:ND��%����7^}}�f�w��D���!u\
R��P][���������Z�J}�}����&^���y}xd�c�T��Lf�8Kx�Z���f���������4��"�����-4��E�lDDDDa����_X,p����/���a0��BD����;��������4`�jbb���G��W��11	��W��?����������M[[�V�^�����e!"""��/<W�H]�y���b���
�X{q���9:(8��GDDD��X���t$'�
eZ�	�0&$
��f�3�N����32�j���������>�<�*���#q��'�r�"�{�[��n��i��{�GzFfP�����e:����x�7{��^v�#�!q�|��b2$`a��������l�#����&;z1�Xl~xk��+.)C~~!��9	������
,�����eY9^�s��1������(��x?�	�������/�H�d��!�����f��-��SO?����z����h��T*CRr��1�������"""""""""""���Q�`a����(�
���A�_����\?�v������ $"""""""��X�!"""� W._�{��BC}��Qn������uo��sM������Az{�����f��!t""""��ca����(����@,� 3+G�(���f���[M��=�u477<�.^���������Q��������"""����
�e9����B��E��Pg��V�����Psc�m/����Z,B� ��v���}�0��BDDDDT���M��v�h��_ X�Nk;Nw����G�T25&J�
��
��zo���J�F�1�]�p�������������)�()������5��c�Y������
��'O|���Zd��b��5!�����H,�E���j��bd��	2���������k+2��nWW���g�d�G~\������A_/Z��QP8�v��l�\TW^CWg�:;��G���Ci���	W�#�[��a������]��R���t$%����*�:(c������������e""""�p��Q����e����"A�a��,�V��>�dn�BQ
�E��{��5�*�df����hin��������bz{�Q]U���khj�GSC=�*^����HtG���������	��J���Y����Ja����?��\��}�4�c�v����"@��m�
B_�p�x��U�=#X�T���{n{_�:J�
�Cu��� �M����tHe2�2� �V>xo����SR'�/!1		�IX�fZ�QUy
��<��"����������R�h�7??h2�����F�����io��p�������x��#��t�7"""""!��CDDD��3a�X����q�>��y��!��po�Z��W$/������"L���<��[^�D����&L��[�����df}qT�x�^��C���	��"���������|�����qz=���I��/�	�H����ed"-=z��o�H���$&&!=#s�1�����f
��FDDD�32C������q;zF:���
�L�fn��;+��:����0
�����QRZ��/]8���Z�"��R�lZ��Z[`���f�yh��aX��p:��<�<�&l�r9!����k��20��������
C��~�����p���������[��R�BZ�x��|��/��H������d"""""
g,����r�Fe"��Q�*l"��|���&ddec��uA���m�-hkm���;����e��A�K�����[]9t�}��|.VcB"bb��H&>����<�l~Y��]5F�e�YQ]y
�U�0��w��������P(������������Z������Jt�����CDDDD4[E����	b�,vl��1�h
tr�9��ADS�9K���9!q��D��:�cG!No�SO?7��4�������j��T�j�J!�������%��t�������(b�Z�h�P�5S���	;������+V�b����Z(�x�^���M�����\bR
�KJQPT�B)H���.��#���d�@��,Qd��%
�x�1�0Ft��b������bQgbu��8v��
~���u 1)�I��w�Ztwu���������B$��QAa������'�����N|r�=��t�H�����"��t:�������%�~�����,t""""���;DT|�Qd��%����f|��v<��cHMK�������o�]�������C��i��nFl#�add�2�r�������f��J.�>>�E�Y������`a����O��"�,����������Psv�G;P]yR��l}�)�!�@_t��^456�>b������6=�
�KHF7�q�(�p�;D��������(���.�X2]��3���3�z.^8�wMOwW�����jAgG;�VlV+�V{�i��'l�p8��y�7@�RA�RC�VC�TA�R#9%%T_
;DDDDa���hj���
�`0�m�a�{�v���G���������0X���|{�m�+�a�G`��M(�3/`Y(�U,��������D>9r.�.�N�.�.�.���|�?�{.��]bh�4�u�}����?��g'""""����Q����B_/T��[>��s`[��v
��t
�$.X�n�f� Z-�����R�q|5BsS;�E�[�=}��u��	&.�,\�>�r�
�2��R�2��oQ������fv�������� ��z���	�B�1��l�/��Z��<]��]@�`��;��F�����4��p�]hnjBKs#:;���7��>{��g �!�!�!� ����eJ��*:�`,�����*@^AQP���uo������l�~0�c�k� ���n��2��r���\�r	�m�HK�x�;���
�ey��BG� �Gsc�����v��b�&��z��mSR�B������f9v�����PMU% /� (��jxm�$�R�9w+��1��|}*�/�������i2��q��%475�Ea�j���mo�a��k_�6tqqBG��?��!/:�����_���q��m,rr�������l�}��"""�030��A�R���T�|���{Q7T
�\�G��8:xO	��
Q��C��*�@Ks�]�6h��������o�a�c���,�L���
�m������l�� �����#!1b���������7��h����j��a��6lJ�
i�\��D���qC�6R����Sn#��������>�l� �������u���Uk�	�%��Tj<���#%5
�5Ux����j�����	&���{V�]���=����CDD�G���W��AD4k��������f���
�6l��1/aA��:7���Qo���c:��^,�������jM��������P�8��zT��L&��������;Qy�2��������"=#3d�^����z��4���`�=��z����ODD4S�<���tY;�>k��q��f�����1�CL������:MA�N��!��1�h�8g���a�B�:F@�xlPI�B�����J���>dr9�~����j��t[�2g��:�cG�]�Ue����x?��[W)U*df����YA�h*"e��8������V�F�6�����1��|�D�%^+�D�M���W����R�qE�����l~hk�u"����0��c������6��N_o�T*����D�Z-P(�HLJFJJ2��aLH�������>K/7���o���������W��=�Lm�����f��!���;��"�,����>������L�(~E�����Ell,�R�m�[������� ���048�e�����"<���	�w�]p���m�G4�H��D�������p��(Nu,L^��i��(��Q�������""""����7">�(t��hL�{���
��}�c�B���T��
���������T*��hDDDD���)+��N����p��$������:��������4��x?����7Y�!""����L$����l<[�MT�_eQ��(������h�������?��T)t�)�����|.RR�X�!""��5��+��-�'��:�D�E�K�����n`a����h�:�{��^9MBG	+^�##6�L���:QX������������o� "
G������(�T���),.	H���OC-���E�3l+Z��Qb(�r�������|�|8�N88v8��b��N������w���������n��=?�o?�������h�i�������bu��0/a���H@6��>xG����0
��^�F���z#�EA\���&�n���	��n�?]��!�`Ht�X�!"""
'O|��A��S���������������S�=��E�P-��	0*��������p���/\3��v�������J�\�V�\�L�\���T����8�v�)�!���jM�hn���� ��K������}M;'�����[���ya��A*�A-�F�ETTT0��:S�)���-�Dz�C;�����*CzE:����$"""��N?��Ar��R���ZG-	��:��+B�P-�LUS.�������N�Eb��b��bH$�D"h41~��dr��!"""����{p��<��bl��22���L�q��{�o����/#F�
����5�.k�l���w"]��ik&���L���UG�!�C-��w��b������	�����s,���3������7>�xF���?��7����k���l*fq����h�L��>y�k�oH���Z�u��S����R�%KW3��g��C.V���'��J
�O=��-�Qc���^���������l.����xl(2����w~�<q
����?
t������-��D�H'�l�{Fn�����`��*{"
�I
;n���#8#�����TxN��G�b�������3���7�X�U�)�2�����f��;?���(��Y�Zs�����:7HE2d���4T�>{��D�#�z�=
���8�>hcHDRl�����lh����� ����
���`q
����~{/zGz�?���GK�v�.d"9�m���u~��^�g�����N>�8������ I��dM*�T����-1Q��_����������X�>���w�2lY��J,{>���&_!J�h����h���=����gd��|n@�t�����A�Bv�un���i���*v������B��B��l����J���wq�����x0�Q(����?N�����|N&�#M��*���f��b������>9Mt�0��/06i�=g�W���o�����������dU
�����)�+��ED�c�;>��J�o|8���.d?���[b�P8��1$�Lc��OC"�b�����J������`���c/��c���7�L�r�Z���G��
�^wH���� IDAT;�}�^�Qj�3�}r�%�9��kaT$��J�f�se&�4"^i������p�m���I�����*��oaG"��4~����"�$��+��hl��.�-�~zK���`�$"""�a
�J�o�l�D&�#C����&�����N:	`u�z,IY�88�,zG�8�q#n�����pz���b��%��!���d�
i��eo��5�A� ��!������o��N,	�aG����>���{����C�^P�����Sv�{=���#���M�D*��
���!�9��(���CDDD"]���GO�>������:`��1��a�3���������1��3��wq�zN��X*�A%Q#^a�^a�Q�0���#I���CD��$?�E(��l��)o�-�3�X���v��N��J�3?�Ehv�$"""�����DDDDX5�*�j|y�B<����q�l�a�_��~���h1���m��R�<��o�FD�&/�k��������'Ub�@AR2�f��!DDDDDDDD4}�^'9`���|�ii;�X�{�gZ�25�bs��������������j����L~.O�*)I��B���^��'��n"""""�mNv�^���"�����
��u�.��Y19��+DNl.$"��P@n=�����h�h�S��
BG�i��?.t"������k����E�$���������sv����B��s������\����Nv~����"F�8Q���vB-E�������j�
U2�9���5��z�i>j|��J�)x��InEFD4�Lz��D��d/N��{�����mJ���CDDD4!�������w�b�9�8�507aA��'�/���P���E"�5:����u������N<[�M�E?�y���[
	#���<����E� ��<���$�R�H�����<������QT��g>|��������u=���lS1�6 ��"""�I��Vc��]��������~=>7����$Z�"Ci��%��]���.[���X��R�8"u���W&@'�:
Q����}�
��N���n�&�aq
C���X���!*���9(5����6�j)u69`vb���A�	�N�n�1�{��$(�+A�<�����FD4M��]$E��r<��O�p��Sx������{���)�2X������N��E;<J
r^�^�b1����"�����}��v��T�����spzX��2�<�}���m�� �^;�������i(�\>��?G��^�lx+�CfLr�r����D!w��zF:�I���������d���uoC'�#-&�1�H�f�]!4�8��^�����������y I&������������J��\�U�c;�q�E����X����u`��_Am���o��05��o�_�R��M<`����"����t8�x�2�	����u�'.
X�B8��{����oE���4�j����%)+�rc��{';?�cEO��������Q�H]���F�[[q�9�K}g!�#M��,m��������(�����+
�����B�Z�V��=���<��+}p����SZL&��
��Iz���w�Q��^x����z!������
���O�;��o����1|��A���['l/+��:��J�N��N�x���8�)nwF�6�;���A|p�
ey:�}y
��KGRV�&��OlH_�c����c������Qdhnj@M�5���P�tE@��I�uUI��:Z���Q��YZPc��L�%)�
��X�!��>�T�hD���H���K�0y	<>7Z-�hnD����9Y��"�����a��0�]���-��7��X
C��5U�v�
�eo���k�6p��N�^a���uX�u����d�G���V��A&��-��Z��6�rka�zQ�;�E^\!���M��f�����J!�������1��Z��	�;=N��>1�u�H6��^���I�!"��k�;f�5�.�B���������os�4�|���M��O�|���.���Q��������va���������@$
�~�3i����M@����
[qr=�bs� �b�{���0��y�U�;��W�.@'�ck�SS�R"�"WW�\]��k�w$�9mn+z��p�\py�pz���9��8aT'�"y���-�aj��X�T
�X�D�D
�T
�,6���>^��3�]fxG=����Vxt������S%\^'@&��3v��p#�bn����fsbe�WM�
��l��	������T���,�5
��� �C-��_�~V��F�'���(J4�&JQ����
(""�y�vD����6b�o�^DJ�������(��V����QH����7�H ��B����E
�����c/�F]X�f���K��I<X������ r�M)B�`=$r;�3g�+���#���,m9TU����
��������}��}�]f��HP�0�C�)��WoC����i�J�W����F�	��I�ij���}����+��Ac��m��i��5�8�����������&�.W���9�0����4�u�L��[��_C���
�f�f��v�n3��;�C_�
2���
��c?�#��V��8������.h����2d�N���O��[�a�9�b	0'y���������%�&/��S,EEf�x!e�?��(����������)��;jG4�����"�[E�����l2wa���Zr���\��,vl�Y
KD�'A'G��S�D4E����r9��?��B��������6��u��y���������SWcQ�R������;5��{�R�+��`�q~@���
O}�^�S�*\^'6d?�C���B��u@.�C����_��,�H���Cy����{��P�>���N�au��	�:Lh2�C&�C&�A.R@&�A&�C&�A!��(��90���=��
#;�n+db9�d|i��.�/���~��������o���Zh����Z����H�(6���P�s��`�9�?_�H�d��P���"��&>�^�V��������oa���7^:��ek���$��O�X�!�|"LY8g����f�!>�(t����:����Q����</t��8�y�:�!Nn��s��N��������H���5��;�Q/�|��HV�`U�z�$j�#��ji������+��.�QZ������l�F�T�D�U��C����:p���^4���u��t7W��I�f:�.*MWPc���c���Q������B)����b�c�9i�8Kx,�F�v�8������{��L���"��C9�D�(�p�������6K3�>����i��'�>���r����h������{&�Tq����Z���-���]��tB-���U���P�X7uX���Idl����;����J�^��3����X��R�X!�imG��k37
eF��%
<v�#<;}W�/�B�L
�g���^����,8X�!�|"LY8gIHW�/���2Vg|	��d��E��
G��c^���l9�9�fkq.�����Cp�\0(��R��HT���=U����2����D#t���y��������0�?7������'p���s�(�X�!
��,�L�+v�"�E�Y����<�$��s6xyF�����������ou�u?j�s����U3�|����
�&s=TI�mG�g���;���A�w+���Ft�:�e�D�p���g���X_�\]����f�Oq�;D����QQQBG """"�#�*�P�\����Gp������L���|gV3T5��}�������{�c�q!d��������z���]xG�H��D�&����(���'��}v��Q/���������;����/!V�������h��Nx���GP�/��z����O��KQ_>kV)��Eda�����h���z �f�G(6��[�c��Hc��L+�x|n��9��)S;�$-&���6��[��9��9g�����7����
�V���r���$"������.xG�G�!�#:J�Hq��(DQ"����D���E����C%�8Z�������{����L,�Q�0������f>v�����R]m5�&~���:�}
=�.��X��)0Nt����[�s�����am�Fd�d�O���[��3����5��b����^����^[b%�%,�r�tmf��]Wc������H�_X�A��L$����X����>8��[�Ga��@^������2}�]���c���g���"""��PSU�];�����j���xs;�Q/�������:�}�������q�n��2���2��k�k^G�����	v6�lSk�F�P��	X��D�8a���`[��r�Pf�7��N(\�=���{ �����S�J��������t������������B*��b����q��;�I\�(0�S`������:$�S�,�����d�s��� TR5jM������z���=����m{����`�a��U�������X��)�c|�~#��=��	���J����"I��tDDDDD���"""�;��.8�^�%���/��X�#I� �"������~;��HR�`k�S������P��_�������q�u/�v����
�8���m���� �FUb��p����^����!�N��t�������`u���|��t��*q���3�������������`P�<Q�`a�������V����i�()-�7V��OX8���u�@��;~�~0}X��C5A+�� ��`y�j|}�w�[�~{/�k�2�l��:�8T�L����/XL&**
[��b����=�#�x��opz����%g��B}	�f�7��h��W+�����I��n��K���L�S%�!F�
J>""""�p�3v�������t�����D��isP���zq��$�����8(c��.k��]�A��	��s���wCR�����������$Ur�����b�V�"�n+��������cEO���Wp�m|c��[��W�#U��{�!#&;�c�1�G^\��}����x���0�xV���T$���}�^T\E�:<>���DDDD4;q��4<�N��V F�w�_�9�w|��\<�����+�V	��VQ�B�*tE��J���X$	����B��Q� ��E<+|2�G�?�������8Z�G
�zQ��X���7ck�W���p��<�t�w�=���L�E�bk�WX�!"""�Y�+v��������Bo����eAC#�B���w��J�L�*	��v�<V�%�#��}n�+�E����F<^���~�:a��H^.t,A��d��9/�T�1X��	7���'#"""";DDDD���C����u�B}1
��A#���
�7�����K��w�v�A��[���-��x���]�7\�;�	��J��.""""���VlDDDDw@�P
a����)��cGf���y
�W�N�C�8tn��Sf����;DDDD�b�:Ft�:`u[���$"	t
=zF:�������$t$�E<����{��eA�P-�������yp��p@�"""""��ba����h��n�&��/tX�B:�{�����J��E� G�����������c��VK���Z�P5v�o�o��+����=g0�����^��y����\��'%""""�@���?���!�����3*t"��B��W�D4E�������K�k����A~a���f�X���2d�f�l�}��L�	��!��#)?;g���Q�/�g��vK+�LW��iaT&
�2��[Z���5����+:��BD�"�=v��{�2��K��Pm���i�Z��J��������_������X��:�g/>�E�Y��S��EG	�(���o�:�0V������+�q�Z�V�T���@#����w��kq
}@������/��4F�s�{��B'�c�G���#'-:VX��z��i'�X_&p����NA�:k3�G?��
h67������3HT%!^i������k_������+Q��<D�������nDda����(P��Zq��45�cll"�%es�`Q�zC�r4�"Y�
��aO�p����?tr=�z����S'�C�4@-�R_Zv�j�EU��r�W ��=����B+����mHT%'l��<������H�f
'`�x�X���Q��M�����������o��scC��(1��&,�5v���hV���CX-�P�T�3���w
eH3�Z���~�"�{��B:v�GKP�/������?s��J�WK^������p�funH���7�}o�����w���OA%Uce�Z���4Z��8�[H�G]x��-������'������������CDDD���+��&).d�A�	�o���O��������-7?��-�E�	��A��j��-�a�n����U���E�O���mm���o|'��� ����QU<������(���CDDD�Zq�p�l�|N�W��>V��A�^���Lr�L����)��g�/�(g^Q�>u��}��+B��@�8��������������?{�uy��M��9�$�3	9�(AN���]��z�nm����v������vw{x��������~k�������T�U�����ZA �	�@B��8�I���#3�@2���|<� ���k��+���ys}����1���}
�T}��T�rA/xN�6������Ku9�R�w����%��6B�1,�����e�nJu)p�v�������/��"��"��$������T�v�"��v��S�����N�-���ZF������#���uBS��t=6������Rb��Nv���K.��T�
�F�' ev������
v��9^\2I�����:���We�d*33SV�U&�Y��L����v�LJz����*�)�)�+�
<��c�7o��&S������`W@�`P{��R,�?�Ie���;o��:����e�����}�'S]����o(
�#����w�d0���aE�`�]�r\�	&����X,������;vT�>�fU�:�����K:�;���#	��6������>����e��Y��$
vv�����I��l��yU=w��O��M�|G����Y��rS]
��{�}N/zN�;j���gt������R]`����R]��
t�ES]�����TS[O��0�����������^uE�<>��'��p8�H8�p�G���z���N��I�o��[���M�~���2�-	���N)K�

�F�`�\��l�7���W}��l&���r����q��`�K��uF:�nWg�C}}}���rH_�n��,p���-23R]��v+~�C$��la�i�J���}E{N��q�Q�V�����+P������>�@�C���y��	F=4��)��8����5\y;���?gIw��n*�M�Wo����u��X������]��w(���`�u%7&�o1Z�v)��+��!��#��-��-���{�vhA�5��f�nr\��H<�`$(I�Z����<����<a���N�X�6}���u���XB��8����C��y�.e�i�:�GQ��.J�wj���`����W0��P4��H�B�.��b�WN^�p|��*��&��+��-O�W�K�L��&�<f���E;�q'O����^P��}�����k#����|r�=*uW��������~���9f�0�at�b����J:>���/U?<�%��G������?m�����Q}}}��z���G�������Ny2��g/Hu9�1�]����yY��-�m�.	�>�`����K���S���lZq�*M*-OuY�Fm�!m��Y�6}��/��cF���L�5�e��F��s`�>�����DT\2I���C6�=�e��C�z��2fu��{���T��`�1��+�W^zA��d�
��`Q�+_��.�p�Y��������k�OuI`�!�`q8������������T�3�����
F�����}�^ IDAT6�y*S]�vcf��*�%�[7��������3'���1�`�
���*����2����pq��@�F"ji�+����!9�.��� �e`��e������V������������Vu�B���=^��q(-��Q ��@g�:;:d04yJU���x\5���$9�.�L���%�����lM*-��q�����T��!��AK�_~g�:;;�������s�s��;Y�����#�/g�K�%
F�������������T����A$��];%I�V�r��v���z�t��}�
��������R �����T��!���E�jmmQkK�Z[�j�����*�7K��;�����}��y<^���v{��V������.%�~wd�N��T�.������0��'M����zy�
:/��t���7�Li���;��hK�����<5�;'��]�|{�V�=�n�������Z{Z�l�������C=��D��N����:�F���?
F���^eeg'����)a��fK��lv��1M,.�7+[YY����VV�On����6Z�������������b�~�y�u���Nt���Z���NH&�Y��I���9-���t�������s��ZY�Zf�%�U���`0*5�<���lJ�>m�,�z�����MMz�W?O���_�����	�������/��4��a���xS�T���`�Kv���}g�fk�o�$���U����_��T�vH��b����N����i��	��3=�~�-���+��'c�:��J�O'&L������h�>���	�s����w��Z��E�1��1�b1�c1��1E�Q9�+]rZh�:�
G_UK�i�
]Wr�f�����^k���,����$u��e2������R��P������rtEj�:����j�Pc��@����������G�D����� ��]j:�����	�MTa��!������%��<~���u�'6iw�I�t�l-�t�2
��z^�%�e����^�[I����b�$��s�Mf�+X��9N�e�0��a�q�Q���g�,T�������s�����S��P��A��&;��Dt��~��������������a����d$tE���y����Z^�B]%#r^c�Q�����:���p�n?0��4�
v���6i�����2r�d79��f��^�G�
�e1d^�DF	��������c��[�GGP,��l����5m�L�L���������SU�b��=o����������$�i"
�����H}�?G�c�b}q�{c��������>���7����+0��a�;q������w'��?�V����_���t��I�TVQ�i�g�r�����g��P�B|���9�4�����j����d-����_m��uEKS]
`(����x<��U���yy�r e���j���/n��p�x�H�T������Us����p�G<�9�e`���;�3������
). I�--jooU{[���utt�b�������qo�^m:���c!e[s55kZ�K�0��� �F�,�T��"2&(����20DG���/�Vl�<y2�o
uE����/�P�!e���W�zb�����&�Y ��f�����k��z{�R]0&�e���S Mu.B�7SMm=�.�����hWggG�������y�i����'+_n�W�W^O���<^��V�o��>�S���P$V�5G7L�E]%
��Ph��	kH/�Y ��f�������%�%cBZ;��s��~���
:/�����"i�3��D~����p�`�K�XX������I��|�l�'�����o��G�J���b�mm:���`�K�`�B�P������.��9[�����322��TPX$��-��-��-��+����l��f��w�'��\[^�~���O��z��(
����9'���p| ��i�Y���������ct;��z���t ")Q4\�'��/y����%�����2���u��I�y����N�o��=��[[�;n4�d�;d�$��\Q9E�S.�^|�;���[�v)�R0T0��H<,I�2��������n����:�nYe3e1f�b��d0%���w�j�]�9 }��`�V�_�L��R�r��Q�>����S:�����&��nV,�$]�d�d_�p|YY��V��v��v�l6�<^�H�?nt��+�T �)I�����o������s��2��Ys����2{=�����z	u������e�&�|��s�ee�������<��W$�_P�����[�b�1��b�����+�S�7&��������k�n��^U�7��H�y�Bs[�I�����%��C�Gn�[C����AOO�N����Tn^~�~e������/'W��y������z	D:�1!Cv�#a���wj��W��{'���J�W\'u�$�����9�.��.9,.y-������`�>�p��ED__�ZZ�j8yb����U�t����;�*+O|i����}Zm�-j
��%�WkO�Z����F��p�O\�p���V��L����2de�0�0�(c�A9�����Z�z��/�m��i�h���N___�K0N�z�6ozC�H�����L�����������Ol�����;���V�5[�����'��4�U6��3L�:H[i����E�jmmQkK��.��&'�k�d�b���d����������9]��x��������H�:z�����2O����'S�*���leef+��������1���M������Emm-j��t�O�9;i�3�j��VM�RGT,U�/�XoL���b}1�{��3=I�qS������+�t���v���4���*�$W��0������k���[m6M,VV�OYY�*(,�zb�Qm=�Y=����������'��+cF��<�V�[u���/�t�r��g���~�Cm��_?����:a{O�[m�V9L.Uz��c��e��c��e���F;�JgG�Z[�jmiQkk���4k����KJJu���+++[�>�,�����'��`$�P4�`�K�h�z��
D������nK8��a��OmO~�A�#��uRm=-	�#�p��f�Ec�,�Le3e���3���'�$�����:a�>���Q����v�|O��-jkmQ,;��b����������Iz�H<�p,��x�222���K��9xJ?�Y��=�hM�H������f�m���������Z�R��h�������n��e�_�y����	�{�D�t���������$_N���,eeg++��l�O^o0�t�'�#��"������w��7�'��p���l��I����J8�nv��3Yv�Cv�]6S��v�C6�]�L������?h�d���5@�"�0�b��N�n��Z-~���f�O7+j���t���w������_�[y������Z���Uc�A]M�;�����7_�O�)q-�Q�v�(��)��)�!g�2d��L�l�I�b79��)w]�O���j��]�����s,+�U�)C�]���qk��j"]��3[���}�f��f�����f����$Y��rgzd3�e5Z�i���Y���
�=4�kWp�0rv��?7n��OmW��HS����])�����p��o��4An�[.�[v�#e�D#�����J|)5�����"e�|�x��x_'cu��l2��T����9��g�='���i��*�L����1���_�Tt8��O����p�$�P�~j��w�*{z��}Nw7�7�[��":&��Q4*�Y�t�Dg�&{�&
������p�9�<�,�3=r��ZX�8�=f���+���S�|����USS���Z�����Kg+*����+�	f������|n���������Mcv�av�j��f��av&��nr�4��T"�Icm=�����t*xR�4'o�>V�q���i��*�SR\��	��:�~D�m�����S�I�7�Pw,��{u�u���B�D:'j��\�\e�^s0������W]�����Y�Mt%����e����E�p���m
Dj����U�tu����=��O�xX6�MvsH�4����RVf��K'����o����[���e��{��a2����h1�>p\���x�������s�5;�z��<;i�j�������*}��zy2�o.ou�T�(Jqu��d�^G��Xg��������ws�{&��y_���f�����`��N�����N���cX��m
oi���zZ�9^�*�D�$�-���tvt���GV��)W>�J����7+K�xTm�6eY�������������>�0f����.�����"g��c��!�����J����<�R��>�N�������������rl�+�`'�e���9_V��z�c��=�����������<?L�z�����)+p��]�2w�E_V-���k���%I�x�'d6X��k�n���Y���!��v���h��D��I*v�j�3�����j��7���=G7�r�������Tc�^x�W��������QO�G&�IU��r�]�Ysd1f�3����/��W/y��+�`'�
%�����h<�?���?���B�DM������2g$6R-�`�'3K�V����*u�)�8����,�L�y*�w����pb�$�j����������IM���b����]�&�"c��-���r����z�l��/H:�����<a�������4��	}��c�E��Ku#�'�}EB�Dj�i���m;4p��3Y�>v���FBO�[�[jt2pB7����`��_����:�vP���<��h���y������z���v������b8J���jj�Iu.kH/�Y ��f�������E&cF���;vF��p�����N���������3Y��������N�9��j���S9���+�_TC�IuG���������R��;>��[�@�SM�F���)�^�{�K����u��>:x@���r8����}h���;�L�7�m'�����$:&�;�=��Wf�>V�q}���:�qd�����R0T(T0��`�K�hP]�.�]�����j�%�	��/.�5[6�]V�M6�]�L�
E��'�����D����KF�IN�S�KN�SK��������$�����>t@�W{[�����"M�Zu�5���Qd����z�M��A9�n-)�AS���x�S���/*�=���d�73K������{�}C�o(��?��������A�K�o^���%�v��������$ibq�&O����Ur8��vN��C�3
��O���/�����&-.^���S]VRK�o��`��d�����d���HuY	M�2U�
'5a�IR(R ��h$���ed$�������S�e�;d��ew8dw8d��e��d�'���E��f��r�Y��w2���(`5Z�����9�v�R�L�T�4�9yW���K�d�
<�(��r'�X���M�~�M���9s�/\4��:@z ��&��p�W�i�����s��A���%������x��-���������W��N�]g��
�
�����3���$;�,�Q0�1�(�%��B���p��j��������$�=�!;���r��r
�9H�`�
��8��m��v)	*�R �1�>+�Z��V�����F������=�ho8>yJ�f������)���A�s=�n��!�bA���_y�8���w7kW�{���r��rY<*vM���4����w��P0���%�>s��N�&�����1;����:�v����
�M�LtM���+����2{��f
g����	t�m+�����������Y^���������g�&�l&��&�rm�I�����k��J��P(��'���f)''7a�I��#X���]�����73[����2
�T�4&�������N����N�P���^DW�_������
�v�p���w��d�0���w�������9f4�T\2I�EUV^���H;g�dzS]���p8���VAa�
�&���H>_�&L����H;�H$��'���}9���[�������)#X!c��8�t�Q����hT�� ��(��(���{��-�/'��h$�#G��d�N������v��6�S`\#�j���VE�]5gn�~�N5��-��WN���w�N�����W�������*(,���MTf&�&`8��`'������W�(��\�@�S����]��P(8�,���/��<a{Vv��:�d���d�
*(,R���K/\�q�������_�=�*�-G���T�tI���T{��v��C�j����O&LPiy�f_U=��k����_0��;�.�[����l�;��������������v��$��t������O�S3g_�YWU��t��40�E�������o5�N��S�[��"�%
��j���WNN�*'OMu9`���`����Q]�1�����r�&hB�K��]��9`l�Hu�m���u�m�������3Fg�����w��IGk��0J����
	�{t����f����W�2S]�y���������}����J��W��*0��`�b����?�p<,����r��tk������jok�$�j����:mz�����v$�f��f�����`�~���
<�:m����Sa��V���vF�����
���i��yr8��.	�	��+ ����:��S}�q������t%������`u`� ��`�K�uu�;~T'����#IF�Q�mmI����NO�[��vhA�5#r������'�%�9�%�T<�T���TPX������/i��z�Z��Y5��85={�e?g4��lN�>}�l�L*���I*.�t����7�i���'���!�����/�}�}2�����W�9��j6��S�i�3/�]]���������Emm����5�j��T_�p���s�8)����NHog�v\�o=Y"k�~������K��1�z��oT�yLE�b��\�	�pQ���Oo���R49���pJ}}Wl&W��vu���WK���e�T\��n��5��9�����_���}��r��)���aTkK�������)''7��
F�lve�LRv�OY�>e��Jv	6�T��Nc�Z�^�{><�_�T��6�T�������M�HU�Z���:}�Y�hT����O��[�H�,�Y\Q�3�	��d�i�m����O�keF)WH��c{T�i��������������������J�e[S;
Y�@Za���5��,�^X�������`L���� S8��������o�E���d3�&i���
����i���W^^����9�+et�!>ew��T�GKY"I�}2 w�O6I1�W�/�s�{sGTR45�H*������T��"�f�����kH/�Y���q[R]0&d���r�h����|�N�q)z�F�l2����TW�2�s���Z���j��f}��
������U�S]@���`G��P���W�R]�(1:/�����	��4A��&v��@� �H;i�` ML����Ku�*�Mu	�K0a�d2���\i��G��i�` M���� IDAT�	c����n������f���c���[O��K�����F���YT�l��{�J�����;�������TP���^�����0����������o���u�r�h\�/n�3?������^���X����0������&��?������z��6�,��c��B_��#i�5;�z0��r�~�L�{�uj�n{�:-�~fa��i�[����d�j�������3�7�>���A�5��G�Sk�5���:3�������9��k6�z`x��@D��s���j\����F={�P��*������Z�6_�G
�i���e��*���Nuo�����*xn���#>`��+t�No>�M�J����^�����<����-����G/��T����	v\�xD�w�k������T����@L�����G
�;��M��I��m��g������)R��~����U<�H������F�(�^�z�D���Z��
ZWy���c�}�5\y��lX��Y��=��	j�5;�z`�p)6C
�s�e�`k@;6�i�=sU��d�i��%j�pH���;k��R+nv�$��d���������0�E7m��P#�b�{��#���F�7�)�l��W$�U���U����k�9c��������/\���o�"��.��5��M��M���e�^��S���*^V���v5�%���]��~�D.�d*��M�H{64I�}�5��kVa�:�29/�$]���w�;vI4V�������6�d+-��������`SA����J��n��T\2��]R"�@�S��{�I�KD�J0-�^O,��~�w>�xYk���c����V�.�{j���=lS����>�oJ��Z��������c�6��K~�
��p�V?V�*���l��;��w.��mV�V���q���2�D�fI���b�*�����b�:6�)����������Y`h���x\�����������S�+�����e�'_��d��P��� `�a�����4��P������w�3�Z���jOH���ve2G�������N�A�x\��
�e2������Z��d��R=+`���5W(,��F����/^����e2�
�z^����,RUu�>�����/��k�5�������l����un��?��Gf��������:�Y����~�f�Bq�}e����5+�
��T�l������?�+����4���I�;��;���d�\2�HU�Uk��[���4s�A&kL��A�Tiq�'c�IQ�A&�d���%O��!��h(&c!�IF���Q�l)��yj��4����n�L��D`�T~�r�<�i������z�W�b�5�l��q5��Q?|:��r�VL?���f�)Q��R�_T�7��XKL�d�}�5�k����\�a��J���.}sk�B��J�f��w������uj0����������d2H2xUP��:i��%*��T��b��
���+��6����U��Ij���R����MO.k�TP���h@���u�BI-5:p��8�������Rlj��?��K<.���I�f
�����5��AO�5���v-.=kA���]�S�-}��_B�>���'�`����G��k6��wC*\�'��C��$�A���kN��>\�
��������hO��xD�kwi��Ls�J�S���t�W��6 )��WqR��T�@��+5���~�F@Q���=mm/�����*02.o�//�{�{z�H\�����5���\����j�QO?uX����_o���"K�Tn� kv��`H�{����c�������X��%Z�0�7��Sg\���+���%O�`���Y`8$]�q��>�A���+*)ZX�����KKd� kv���p�������"��x��~j����WG� ���Z��"-����x@;��Q�^��C6����Z)�����]Z�O�t�DX��%����N�g������U�?~H��
G�A6�A�k��??Q)�e���_��5?��������{���;�����=��NIqECqE-f�R�������Rs��}g���P�lS������3T|��']���w�n�w~�����v�B2x������BR{��{�����^�|�z���#��A�GY��7��
�����Z�='�29��z�"�w_��]7�������A��&�@� �H;i�` M��	��4A��&v��@� �H;i�` M��	��4A��&��.cD�I�V����w�������!����m��O�H}DQd+���[�*C�kCR{����kT�����e�X�6�@�Z��WO����%z����2K�Anr����L���:���G�H��5�|Zv���S].�'O�w���
����R]�G������yu�Cm_[�SM!��>-}�&��g��T�C�t�~U��^�;����a�`�f���9=x�A�?�o���-���;���.V��w��;e_q���h�l\����um�.���_���W���T�7��"��uo��_���).9���q���r�
l��k���k�-w������i}D2��7n�b����������i��u�rM-��//��ygN�{���F�
^�XO�h�\}��j�{K���#s�j�
�W~nj8�u�}G��
�;l�{j�?�X+��[�~����
}�N}��g.��k�_��[������+��g����V^�YGw��!u���#�[K���/v����4s���W'������7�V��L��ww��?���!E-6��Uj���U]��n��-������XXQ�A�Y�Z��b-���O��a�{�=��3�hL��i�k��@�����O6�ydP���[������W75�# ��|�y�"�{w��Jq�x�?�F��`e�~��_-a�+'k���:������`��c`,3HQ�!��e����E*0����/��'���u�U~��G�
mi���.=�m����2=q�����������h��,����=z����S������6kMI��~w�����DZ�/w��96����}}���7����%g>l���D���-�	[4��O���6)��R��P����F��D�R�bKH��n��yMZ�I�(�4k����H������Z��v-�}0o�L�p:�s��SO���;w���N��~�}x�����E��Cu��:=�R�
l!�>�E���k2�����J*���7��ol��y��j�T��FmW�+�U�	�2��~�f}w��9��h}���������>S���O@{���=�<���M��B�>�q��}���^�'V���k����!�����}k��g�q@��o�����	i�����O�h����<W����f��z���2��q����~g�Jf�����s��J?�#.���[/�C
��o��g��������b��e�~�����z��ne�+b2}s����\_�'S�A���e��a�f~�����E�
�/#�`���Z��v��4si�lMm�\����iV�A�R�L��b�Y�2��c!u��-Z=C�o��f0�w�|�t�T��N���v��|��w,��96�$������%�~c���>x�\��{C�����|�G.�Y�B�l�+����m���J�NIf�������~��=:�L���d�d2�����q����$����j��n�U��_������3���2s�n����EZ�P�
��6�z������g����:=�:�7�a�v��Uk^�h�?/R�GC��*-��?aSq������-G��n�f�=R�Q�V?1_�6�<6�r�"�����>[��#O6�$�O��:[�
����3����6����e����O��g�#���-q��6�����w������:H�:5��-q���"U��g�"�X��W��K��L������,���N�����b�������b����������19m�$�� �E��$��h9��|���
�
�m����q��65�����/��?��	>�[��
��K�p��/s�r�SQO����H[��+*�%��I*���z���9��*��>��fIg��+17���B!��,���H��2p��*�&���=��4��;������]�A�<��;���$�(�$��RM������C���M���v^��!"�,�N�m+i�����y��.��%eZ����
����������W|��������`Y�|���:��v��NU��=���J��B��q}x��<������,)S��S7���/6x�����p�������%��qZd��/���$y*�w�_���=O�S~\&��r,���F��}���y,��.[�>Y���M����������z�~�N�>��~s�}�;U�_|+�����^�������~�W2Y�t��=�.��qu�p�Rl��� �����:�P�%���@G]����j�Iy����
J�S5���H
���K�]��2�L�~�j9�`�]uu���
��0xTP,5h?gn����i����J������_u�g���!t��V!���-z;o���\Y_����B��������E1���9��#g���G�o>�/S4�)���wT��'V����!���z��������*_6C��E�����[�\lAR�G>C@�G�Q���Le^b�sQu�0#��|�l!�no��`?���8����%�^�W��:w����Q�ZV"�$��k?U"m�����	��:���z�����r��>>]|M����jH����'�hGw�����{,>-�T�b�o���~�r�_�34�Rn�sL�fhqi@�|G�[$�#�u���g����0Hi|n��}7O�~c�
�T���<���F���0"��F��8���������������Z����G$���{/�����g����
����i��3aK<���m
9=*���y�5��m�j���
�%)��Mj���W|�e��qE#qE�	�Vj����d�v4�%����M�n������4���F�b��%Z�X��|��g����,��_����� #'���1
D���j�����&4
I�_�~����j�4��k%�]q55��4�$�jD�I��)b5RI<��1L�A�f`[�?	F���
��ZY��~�}_{���������?���Q�s��)�z���<k���R!�>1������#�
�=ov�w���]z��\��,����\qu)2$G�:)������}@��r��gg�u���/K{_!MS���/��3������y������~�;Y�ZJ�d���s��c��uXjFe�?�I��g��G��T����3��r���������,�rG�~��L�5�E�s���d����_=%�[�Zi:oB�?�q���i/s������m@�O�G�T���?�k�\���b���K���L��T��f���eY|�MY���T2��q���N����������;r�
?�U��Jo
�o��>�'�7y�6�~ W��#i����7��$)4e������3�S��K��x�7����8vT�����w��\�g����A[�l�R�@���f��%y����������Y�
�B(v*���*�3v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b�B(v*�b8(t���\v�����]���R��Z�����YK���Y{�}"�>xs�8�_r�����E�*��+������[n��������|�����G����O�K.���i�#O�*��^���� ��7-y����:���/��
m{g������l�W~>:N`��*w�?Him�gI�>��v������p������eh�������sK��ci>�O�
�Uiu�{$G/:73��x���S3��*��}�����������,���4.$)dXY3U�1Gf�U�3���n_��|q�)������A
9��Y�_���<oA�1�]9+��,�-�~���%�p@3��|�6���'��?���-��27����m�T�����X�6��%G�b����2s������z&����2���2�yJ)�g>�)S/l������ukzw�{�?���O���Pn��������|vI���4�,&)f��3s��+��{[���M3�'��c_�7�o{!k�J)��i���K���7�=Y��7��	g����s���lh+d��3r��c3���o���|���I�Eg�K%Ial.��9s�P-_�N>����2���w���m_�vd����)Gf�O�u��s�E�������'��fdb1I�#�}mY��BZ;���Q���32��!�P��,�������7?��\����|J���������_Y�%���S�<*3/?#�����H��n���=&W�CM�^�<��uWz3*�~07sF����8����.������=�'ZJ��S�7��z�S)-�.�M��K��R2dH�>�����G�i _h�g��*����>�~�w,�_*�#��������?��$I1g���\r���eu���,[�$Kr��������\����o���wf���LK[!c�:)�qJ���ud�o������>3�~yR�n������k��3[��%����;
'������������3�e����6�����z�z<7����uWzkk�|��������!I�����^����uJ���+�>��|?3��^;�u�v���G������'��[U���N������#�m��nX����*-��b��L��i�w^������������_w����1�N�����Ll���dZzo���i�X��'��	��$Y�3��3��c=�7�\~q>���k�JY�O�d��k��+����uF.����S���>�o}��<���i�����| IDAT����{�{ZUJ�MK��o���M�i>{j|rR��FW���8:N�=�5v��n��y�O���owg�u�����?�_����/w���FU���>���������k>7.�����O
|�������<1Ck�f�r��r���+u����������F�y��C��[�3y��Yt�����fgj�Y������EK���b����\����
�c���nd�97,�������B�^���Y����:)��k?���2����|�/j��U?����6�1��>�E��u��s����?��:;3G�`�7�85sL1�=�o����8����\s�I�����#���Z3�3������gd��������h��mi]���Z�_�47fl!��Y���r��r��}q^��?�$��\H��l{_��r��6�]�L�zfl��������a�?��n�X�$����j�s��7/��I������)������o���G�M�m�R�����}��Y�����sr��Od��1�Vf��=�u�f���/������u���yf�5}jr�gdZ��Y����e�m�f���r�U/uRZ�%�z8����k�_�����sj�����:�[7i��'��m�����s�]�����g���Z��Z������q�����:��:;'�~8������{2���k�K�_��u��?W}�6�h��1���c���/���_�����V�m�d���s�����5��5_�/�V�6��Yt�����?����|�KoK��;s����-�����Gn}��aJ�-{ �}7�����x�	��(v�L)�������|V���I�g��5��I�;�&����9����k�����L������-����0�+k�����W��T%�B�k
����t��"U���9�N��������|x��������RRZ��n[���rF�6�_����s����O�����B!����B�����-��]�u��/fd���q�\xJ�:��u�T7S�jM������45�d��!)�|�8C�j��lW�?6;g�8$��b������h���R!�����G��%7�7��k��-��1���Y��gu�;��WV�7����+���o+)�o��n��e��~�����,��9WNLsc!���d����g�,������;;O�~\��?��Dqd&O�n������;����F$������/�u��YQ���1���V��r������O������������.�3���x�����z�i�����^���
���!���5C2�3��������K�s�-����r��!)�i>��\���3y��9Zh����7W}��4�$�#�f��!��dk6�=��W���������$��S2g��L������s]WR(dX}��Q�|J>��r�k��I��.��5�XH�����.��'���k�Y:2M�B��N���*��e��:�����x�	��X�
8 ������MR*��P�Q�����w��"]�������fCW����S���u6���,nwMU���}��B.��k_���bM�R�R���i][�c��F.�����.v�7���.t����B�����C2���
-�7N�1�g����oe�B2b\N8~���I9��f��s���s���L}��2q�?����i���-]�-=������2-(fMK)cO~��o�G���:�bM��Rz�=���6������-x���MR]�����i�v���hLS1��>y����>�:����������uI��-�����[r����4��\>}7��T3.�|px����s�7G����g��	�:���~t���m����yn5i>������d���y��;}I�����__���=@�uk��Q�o��45S�����1���?�'�=e�O><�O�ig���mS�;�~�,Kn[����$����{�gLc������;�^���!��g\��q�9���0�=sr��Ou�������I���������c����������_�������8;x(�L����`V�����ak3l��m�g��n�I��^r�1g~�������X��'�_����"3����%��d�/���l������s������g��uumF�`� o,3�x�UJ�Z4ug��d]KwR,d���������5I!G���/���'�m����w/{8?����XV�<��W=���I��?*�B�������V���w�N��7��,X<.s����W���3K�~x��0'�F&����������{w�<���td�������<�7;#l����3��q��bC�fL��4���R'I������t���R'I�o��J�^�vx��*����/��R�����!�3���5�o!���iI����Y%{p���R�G����3��+���KYv���/��>rh��������p��L>9y�'�����1��S�b�Ki]����V�e����OZZ�����������K������������d��w�/[�v�R=�)'\45�|������[������8��s�������>�6-������DO�<����*6������gH)/�l��qJ�������c2���s��/���U���������t{L�<u�YK=��f�p������.����+1d@g�$��p�{�b8������[WJoOi�o���TH��k�ZJ�nu�|smR,���gO��IC�5O����u]i}vmZ^������������>�Fe�EMi������$����@���[r��{��*��iI���/ZJIJYs������y�����/�i������eY�z�{���U-}�U5��<�L���&�3Ge��+��8<�_[���������>���$Y��Vw�������-{�{�R���)%}��z^�=P�Q�<���[V���J�mk��_{:��+�gM���U��K���m����%���y�w�py��|���9�c�2��q������+w���v#�����/��_n-({������������������z�[���;����������G3��>�>��8���<�Bm���M{pj=y\�;���o���TJ����_��F�'=�K�����������������V�t=�6�:j3fl��iULZ���-IOGV\�dV�&]m��/��V��Ek�UJz[���~������]j�7��8��x�	��X�
8�TO9&�F��E�-��$����uW������G���|�]+2l���������|�s��������=����;�%7]��|����������iYH�������l���g-��~��\��Qb��ssy����'n��mIu��L��s3��=�Mk���$z���~#�6%�G���=7s���a��8C/<#�[�����Fv$)s��3r��^U���V�����%��o�Q��g�1�[HRz&_9��������,K��s�fe������?%~��|���.�4}j.�\c���n-_�N>{��g�<��N} I2�����2R!'|xV�|jY����66e�G�d����K�$rd�����|�C���;�[[��S'e����/�V����} �f��������Yp����O?���������'e������������6M'�����mI���I.��|��n��uIq������{���~���{Okn���<�X���g����17^�P�xYm����� �.5O��O�f������3����?���-���
]�������o�����#7$)4���.���k2���Yu��|��ei�N���r�_��6��.������E}#7���>pF.��|�sw���g��+����T?1��"_�����6��53���kB����.?��'�3h��-[��]s�P>O=��_[�����1n���=u �����P!)wF�P!*�;�]�y��r�vdhCu�;{��s��)���Q������j�+��������bg��A���4�������W������3Oa�f������WC]����P����-[�`���bg��A����Ud����`T�����"�K���,v,��*��8Ud�c)6�`T�������QE;#�@�P���
��aC�c�%U��V4���
�������y^������=<�����5�mY����yS�{�s�a#3f����/�;PY�l�����
��c������������y��]�{����b�!�N���b��mo���������+������L������������>���'Y����<xHF���f��CG�p�}��;~���
���Kc)��Ud�0P���;y����$��93�g�LUu�����h��g���6{�'RU���Z�������#7v���&�!C��p��G��G����$�����_\����3O?����=�WR>�?��������/�5���?TE�"K�u��oKMMmN?������24�������
������a��{��wZ�$IgGGrHF�9<
���08
������������Yg�������8|�N�����-}}}5zL���#G��������^Y�.��������u�Z���u��a}��#W�t�9���CG��VL��,v,����O���O}���
)2j�����_�_�����]�:I�rs/��6kV��������F�����
_��W���c�����3�b���x��]f�"��}��`�z{��Kk��Kk���?���RZ_~)g�s�N�4hPF��C�CG���gS�?4�Ba�
�5���=���q��_7�`TU]�����������kMMM�N�}����f4`7)v����Kks�?��m��SO����Q�Hg���rGvSE;�
*w�L���J~~��y��'�$G4����\�88Td��e��rG���;r��w��4[�l��CGd���s�1��;�>S��p�����K�7oNm]]N�9+S�qJ�#�sY�X�
>'���l���w�<-uu���PY�X�
>��9����"���uvnL��
��aC:�7��}C�����[�d�7��O��_�[���t�oH__����V���b�m�7o�o[Ve��������7���>g�u�����Ig���8ld��C3l��6,C�����S����_?����Y6uu���a��wZ��
�������x4�0 �==�m������%I�>�3��<$����C���������&�7o������s���M��p���bg��A���w�{O�����p�:����-[��;��:�U���wl�����	��������;�/��Ky�������k�{��~�p����l�������y��v�W�8H��eU�c�O����T��d��3s�)3R(�
�P��A��{s~r����O%I&M~{N�uf�9����������?������i<8�bC�o7��a��q�jk�����#����?>'#G�*w$�"��A��;�������e9��3v��+��m;����sx.}���B�=�\|I������n��bg��-���jC[[�������R
UU�>c��n7���3���(��������;��������������w:�+��������3|�������K}}1�w8�k��~!��u���Mmm]���u�R�2Ud�{��+��o�5=����9q�;v�}���b��-��W�����e��l��)]]��k��u�s��}�
���[������������|��;�d�������,I������3g���F���/y����yS6umJo_�.���i3���������{s�7w��{s��7�m�+)R��(#�������m��7+�KMmm��`n�:�me�SWW����m;��?��i��(v8��xxy~���462s/��kl,w$�!���<-���L�13U����;U�b�'��tOn���l*%�c���O����[��\�*K�Y��Wt%��s�fe������=m��g�;�!�������[��7�7��vI.��>7���I�t���3+����w,��z|z�ui��T��eW�bg��m�t���0"I
3}l�=��{�t����������BR�<1���<�tm���]���������bu)I)-��N���9�&��������]�nt��lhY��$�
*Sj*�/W�W6���;���w��cO���0�<��|H)�
�g��~[�&IW)����t��������;?�*�*�+����ke��\��A5���1�0Ga�g�����������o�Q�/_�����,X��2%^}uK�#��l�N��K����~07G��z�=��o���[�rB������T
��?����k���/)RL���77��+:����e�������9
�?��o�(��������������-�2d��L?�����a����2-�V�����Y�d��k�4�uL��~!�>�dLSFlZ��3��Y�;kHZ�����M)�'0��u�r�7��-�2���g�_}0�6����V�3v
s���>����Mi�I��?��z����I�������o��IW�K}����]�L�_��� r�,����RU�J��*U[�W(T�����&M��M���C��|6?XrKz{z2���r�ig�;�1e[��y�9����|e��I����L�zff�H��L������=����&��s���d���Jp�x�������>~��;-v����y��_���:UU��VW���:Ir����<��=�;I^|�����o���&s���9��c��8P.��l�RqW�j�r���Ys�o�(���S����,�z{�W�K___J}����R���}��������=��y���N_ooz{{�����|}����~���2��;���_��=w�����������.5�����Kmm]�~D&���<jx]~��;s����8|��&{�a�jS]U�����lg�����z��[q��w�������BUa��WWU��qx6o����
i}���=�����b'I��8u�C@���bg��A��P�������?��3S]S�������m��tB��t�������������9�5�{+��*������������'�� ��'IN�uV�
�k��
��rG����b�������w��_>�P���S���<�����B�p[��os���}C[�k�����4���r��"���?��$�Z�_I�O:%�����*_@%�/9����>C�5���f��G�;�(vP��vF����,8�R��=J8�Td�3h��rG��*�W6�l�R�eU*�r�}�$IN?cv���JE;�~������ohK���y��Y�\��DE��o)6�`���r6uu%IZV=���/I2��I9��s�:p���-�T�u�Z���-���9���3t��n������~��m�k��2�]���	�����~�"��J������-�����������y����i�s��2z��������6c�������
��;����/������i[�>�M:!��u;���g��oV>�$�����a�<xp���4���w:��?*4��=�������X��k�d���Y�~]�7o~�������h������]4hPR]S�����,v
T��b�������m�}������m���CG�������#�2��Cw�����,v�l�R�@���{���:m�_I����_����n��9��C�8��]�@{SE;o��W^��?Z��kV'IF��C�����"y���E<�]��b�Rl������s�������L�������JUuu�c���,v,���5�_��w�4U��9��wg����	�-��b`w�{xN?cv&L<>C�
+w��L�N���rG��R��N�	 IDATLE;�
*w�}�"��-[��;���ySnY�����M���U��T���fen������+�B!���������,v,�����������$I�q���~��2���*��������m�_���_J��!\���<������,v����O=�|�{I�#�>&������/�9����*J��CS]S���������q�)�PQ;ld��o>����rG��)w��b��A����R8XUd��e��rG������}qM�c��,����w������������tuuf��M����},�55eL��Q�����7k��N[������l����M]��iS6m�JuuM>�����s<���m���KC��v���Xl��X���)v� ������?�'�R)}}}���K�������=�9�.�t����������>>�3m���R__���C��k8)v���aC�z��Slh���&�p�����f����IUUU�
U���I}}1���zh�N�i��w�<=4(u�u��/��������5#G����p�S�@�k[�>O>��<��yi��I�������9v�q���W��1kk���������5��@�7o�=�`�y���k}y������1o;6&_�t�-��P���$���������&L��!�Wp S�@����s����hNC��r�`9������oV����8�7o��v�N8N�p�q��Y�T�o�.O?�d�}��l��_��{x&�0���������}��,���<�lw2������9orM���Ve�5�r����~xN��������r����LWWWR__��v/�E�y��tuu��u�I����L8nR�v��u�1�*2�|�N��,��#����|��b6��4�����z���IW~��;�b��\}����~"/[���\�KN,�-2l��G�~��������Lg��tn�����.��L<~����yS^ye]��o���;!��<z_D�B����}��<�8)�8oH��4]xn��p�������9s��-$i��s�]��K�&'�-Wdx���>���z�u�������6uuu������>��3r�ig���`�V���Tk2jx~q�-Y��+56g~���9�&Y��u��3��w��n�
w�OW;�]�����V�������cv��i���������.�u������)8����\��M�J�����?S����|���y��L�*������UYx�O���w��GV%]�t%Q_����^���!�2jx]�c;`����<����eK�~��<��������-[RxuS�w����~����a��Q�����rG�B�����B2uR�;���$������,�=�L,R����������t|m���%�B�I:6�f���rEva����]���1�0Ga�g������9������hO�4�I'L�qS����h�������a���
{B���������]���z����Dc�2b��y��1g^9+I���6�)�$�eI�����_��_�������)o��c'W�T�c��k���c2a����]IJiY�H+��'2.��w��o�J{)�}�����B��;�\q8v���=&�f��]�����R���A[�l)���]���k��kJ�?b\�����s|�����Y��{r����~xN�|v�_���$�]�b�����a�f����<���9
�7s�_�
�MuU��5�FY���J��7�
�7s��)��6u��_����Ge��1{�y�Q������R���Q�k�����Kk���_���~<�R)��r����;��*Zw����vm^}��e?�7/�y!IR[W�O:9'N=��	`�Q��_��hOWgg:;7���3uuuy��w�}�������m��Qc�f�I'��I��E\��;��o�.w���tvnL��7^���q;-v�������08M������f\(+�e���1

�s�a#��08���ihhH���9��;����.'�<m%��g����*�|����5Wi,������m�
��f
�&C @�!tN��'��M:��W�M��s�I����H�K:����@�bF����1��,��%k�y����,l����l�$?kyI��~�
�\��~�P\$v�������������������_��c0q���W�i������M���+IZ�h���@�#&>;��"���-���;[�L$�p8�h�R-_q%I�<!����|]o���$�p:u�e+�l��$t����`���<^��,]�������;$`R"����h���2��b�Lj$v�f�y	���b�r��v��]?z�q%��b�\���
pZ�m{G�Z���~I��=�5��"G\�H���������,�W]w�j��-�7o\�}{w�|��x�)*,SC�UTV�����h4���k��O���M�HX��6o��,]���)E���t:%��m{N��N���O(E��sL�:�-��Yu��-��r<�*�����OxpP�p��?Pk�4�s�v�o�F����u��Wi��e����-�S���r��l��Ef��`������d��`�5
�����PG�������]}���4s��1{�x<�h4�X4�p8��)M����<�[o���_�$A�WT(XV����
�S
�X��h?��������	�4>w�B}��OX������o�***�:u�Y~��(0��F�����-�A�w`���`�I�����]m��y�?���R"a���|�����.�ugt~MM���-P$<���>�!�cd���V���7X��������;�q ��������PsK�����t���g+�� �`�����[o��];��k���E��j���2���'����5c����
����R�����5{��4������]�P�����B2������z5w�B-^r�*�����TTV�q���GB��H��4�4���nW��y�.:U�0��H�sH�����`\3MS{>�����U������?����b�Eq���:_zW�B��j�C�~s����]jp����z��f*�����(���[]G;%ICCC����23I��Y��r��U��N���������G�i��
�{���V���KRz��W�XY����Bc/�	���O����8�I�P���G;�h��o�|��x�d�2-^�L�����-��N�G������G���$���K{k����r5;�[����`�:��];�E������E"a
(��4����l;/Y�����q{��z�r�C�+�c'���J���BNIR\�m�W��kF�8������R���+�	�������$)XV�����W���\e�jj����)dg�N�RlN���9����5��'�]�f��@��x.��*��|�����
L:������{���]�+��_n�{�F-���)=���hc��)�@R����\ v�u����������$���v��$)������G3�N
>V�@&�V�@�jk��
\t
�b+[}�������nD����d�ox�!3�P�>�{�
^�0��i����c������<���P�I���`bG�|3Z�r�G�:���?����q(�����zJ�G��u�*+��\t
$v�����iz�
-�o���I������}{U[W�O�q�JK�[v�?��N�G�a����j���SY){�����~�458.L����W�j��m*���]��'��,vHpQ�O�8����+��n��pk�
3u���Z2�g;
������k������u��?#��[����U��Om��T�=+�`��=�K���Mz28E��p���%$��&�H8��/� ������_���b�����f��mID��)mx����:GkH��Z��L�}�NA�B5�.z;������]Z�|�z\!-�u���g��f�X���f�n+v�a����=��Zmu5��E�eQP>I=v��
'��j��-
]�P.n{�������2�h���\���D�B����O�8u��w��;��@������G��;��_=�������q��p�{��_�������U�����l��.bk_��>��C��
����d�m8�Eb�Hm\�����YU�!�����t����q�����V_Y�C=������z��������o���G��EL.;���7^{Y�U����r���?�i�S�u�<��C\��V[V�/=�o�2?xQO��-Z��d�L&�������
�s��z}�	p�����j�c�5x�eZR}��H�6l�������!9��t���{/v-R`��x�z��H���~���b�8EM�d�m��st��r�8�9�^o��+><T��`G��c$0	UTV�������q�(|��������u�B�9y,�U���+���o}A����N3�xVqI�^���������Du��b��k�X�����7�(0~

��0));�U������k��fIm��s��J+m����6���e����!��H"�h�,B��D]�G]��b��k�X�����7�(0~����0)'�������������#I2��MK_���_Z�/��:�]G*���k$I��Q���|��E	�"��:�������}<D�D���q����������=}�|�^=�B�Z�b�z=�D��>�"o�v=��CK���(��U,UG{�:�������F��PoO��D�i����:u�����^���Z����f^��������:�J���[Z��������oh���(r����$��M��U�8=v���z�������Y��o����^��NSC��8�w�D���X���US���(-v���_}�8�F�sx����W�uh��eZ�h�����/���Fb("3�����g��8x@�HX~�������@�#�'$v�"z��-z���$I������Z0w���u���$��,r�����PD���kIx�������i��
�Fb8�r����v���ut����m�����P�F���q#Ld$v�Q��:����jo?�C����#cU��"F�lH��	���'��h��Yji����VUTV1:�dCb�BxpP��G��sL�����^�_��\j9/�N��?���c�}��c��2-Z�T��Z5����:���&��#����~�T2y���P�mbg(7�C���a������
7}���`�H�`B��������3U�����z9���q��e3[r�=���e��!�a�a8d��,0��Db��������:�V,���o�<������F�|S��G5��BbE7����#���yXG���.�r9IRII���v�m)4.�u��2MS?|�1


I�'rB5�j�����)jll"��0�B����������aZ��2y}^566���Q��9�0q���ya��z�u���K����u��zz�ef2����W���[�]u�
c)�����G�h?x����j�����Y�Cb������m$��v��a�jjkUS[���z���RR
��lB&vJJJ�����^����t���j���d�2M�>��a4���H$�D"���oWg�a��Q}��?T��&�ykn��F	��kB&vr�\�C8�X,�7�xM���:r�����=gn�*��g~�];��r���j���2�	���I����3����oi���23UTV�����H�j��l�����t��~�jj�e�j�TW_/��=�����t��KS�M���<��p�:T�����kjTURmm�*��F����"�pD�Q���uA]q�MZ�h�Y�O��:6����}���`Y�j��t��jjn���R���:��5��9��52~�]���������*^P$v����J�y�����rNe�n�����������|r��K�]�:v�[{w����������'3�NUUU���Z^���c�����u��Q?FMM�jjj5o���c��Ay�^�y3g�QUuHUU��
�TUY�`Y������3�������y��������� Pl$v
8|�C���;��i=���TRRR���E������.���Z��O�4o�"e2i�\�"G.V$v>���O���V{v����_���U��92p�#�p��o��W_~I��:m����:���9*�<;'hniU]C�V��AS����IH�����^�?�p��8��b�3Cb`� �0A������z{{��Y!�.:���E[�Qoo�\�P�
�pQ13���5��+V^]�p�
�pQ���-�c1-^�L>�����;�����i�zN�.���b�p�H����[�^���h��W��r;��Fb\������[��z�l��b�pN�b0����2-�l������;��PW�����2^����Rl��ARLt$v&;D���������O��hD����[�r�V�s��{���7����q�[���F������h;v2�����Hi���?����tMDO��&ud%)���Z��
+������?O������+\��+^b�]��_�J7�vIr�yu������i����Z���9$gs�n�Yz���b�&��#�����yU���oa�n��b���7��;�N�]�:���T����oj��_��L@�=�+������T�C8o��c�C��^��������H!I�g�q;�J���[_P�=w���)�U\R��)�g\��4�%���;.�5�a�ze�Q���
5��;��]���X��������\�C&�"gG����Z��cq-��?�-���>�����F��nkSh�[f�)��I�$2�&��F�Z]�G]��b���d_��tJ��v�����h���\1yM�u
Lt�Q`|c��WM���!�BQ;��|Q�}��O��h�T��
!U'���@�V=z�$i�w"*��O�������T2��������/v8�U�z�d����3u���xrRG��-Z�"�W�hW8+el�s/;�����&�h4�-�7��vk��W;���h;v��z�:R�}��z��AG�n���2���_�N������%o�|�&��W�h�D���We��V^y�\.�����h����}F����	�Z��{�f�"]G�A��~]�lE�C� ��c�|z���������8`r*Z����05Ni*v��	���Ab`� �0A��V2�(vc����vlO������v;�1CbL8�\No�����Y�74;�1CbL8���E�HX�,Y�`�����;`B1MS��|]���+V^U�p��0�l���9�" IDAT&�c1]�l�<o��S$v���N��a�:��n]���b�0�H��	c����N�����r���`���L-X�X�TJK.�����0a�WT��>V�0��Rl��	���"�p�Cw���.������:������PUuH�?�p�CWH���H�S������8�C�J�R#c�@@��UE�`|"���D%z���$I>�_���PSK�ZZ���������E�t�t�m�+TS�P����L$v�y3�������h?���z�����rY��6w�F0��������(�J��}g�b����a���Sm]}���tH�p��o����b�����b�����������2��;�o����$�K�M�1SMM-jjnQC����4.$v�D�����P<��%������O+�L�r������BC�!��7�|�JKJ��y��xG;
#���I���k/kpp`$�cf2'�S(�s�5�e��~�|���~�����P]:��pnH�0�RI���Gs�/�<��r��-�G�//�PYyy�mY����>�%�����p���LX;���#G)�L*�J*�N��O&�L%�����`�%��w����o������������������Vuu����mcH�SJ%SJ��J�RJ��J%�o=����������>�����t�&v$���?�`0H4���@�������:�T2%��(����M�R����U��h9���k��'s��r�=�������}���n����r|�������[���`�����-���&v�.��������������������Ue�}RI�jjj��������j�u9is����Mr�y�����.�Kn�GF)�S��Es��~u���O�8�N�S^�O��Tii���+��V��X)��#��-��}V��U����V���&�L(�J)�L�:d�?&,��3�v{��2��q��*/P
-,��������}�����Qj�Qj���2J2J
U�C
��.���'���k����b��b��b��2CiIR]�Q��{�r~2���km������*))�n��4���mx�r��v�����v�|��r~O�����x��Z~���E09���7�dB]]Gu��K��]����
�_�_u��*+�(X��JeU���:�x�2�G�Q�
����{F��-�M)����3��A����aE�a��)���R��R������lZ�Z_���]};��g����M����+,������k9>/�H7O��r<�����M'3J�
8�rU���F���+e����2����C���)I�II�?�G�l�r|Ve�mb����tpp���������E��ozU[�6
�8���p��@r;<�Z1M��gZ�O�q�21\y���+;�sv`�^9|H��]�>zT�h���9msm;S����!�����K��/���d��=�K�*����]�G.�������������T��V�'$����O��&�;V�Q�3��+�j����.Y�������_��6����J�U�N�)�;!12d����6f�3�z����2��2C���^�'����_�����?+W�[n�-��:�r:���M��j�G�>�
��F>��rJe�Jf�J�I��4�z�j}u2��'�������S��������"��S�KKJl;�����$�7�a�����(;�s�y���/I�x�ji����:������N�������C�����������+=U���)��)e��J�\H>����z��E��;�j����������\�<�W���
Wjv��1�l�VO�����/�8�j)��*���7���v����O�_��V�7��Z?v>C>�S;�]��>E����O���*�u�������T������g��s���;��`�7��_';s��jN�����n���y��0%�<���BG5u����y�	I���G��O�q�n5��J���"�Eb�Q4Q��n��)��*�5��f�5M�����
�i�~A:���������������6��~�������?��o���GO�`�����~�=�6��N��V\���^���:�.\�d\X�lZGc���RC
�)���>�����r�|�f�������K�V�6b���7q�r��9���r��[�n��p�����C�[�g��[��z]��Y��N1�cxm�p
��n�e�f~��PF�lZ�PF9�T���M�n�������]?����$������e������������~O���/�KRc��6�3��WO���c�����_;�������-K@��O���Y��������g)1���b�����X�[��c:��PnH���`yn�[�Y�m����kxu��;N
(��`j@�����A���7�S0���w��ESE3E3QES���LD_��+��#�������BB�7�6����U��3�\1���r;�~�����k�$v��D"�H$�x,�p8�h$�h4�����)���e;�PR�����X�����P�G[����4s����/�Foo�l9~�U���+����o�^|�9���3g�&v���u�[��g��p:e��!�a�0��:r8�_�544����#�����om�vF1�����:9<�0<n����31��QM)k��3>i9�/�����#���3����K���\�v��/�d�Z��u���u���2������jo���wFk��.��B�=6u�e�4}nh�>>�����m�|�r<��n�.IC���!�s�!�69�Z1]i35���0��qx�r�
���m�����x��+�4�L
��g�(u�&v��GJ@�NS�Ew�}�r| ����5VV)��X���q��m���F�5p:\��M�fL	3a;?�M����:������S%s(#���o��}��LX$v�"�(���6���9�'p�uI�{
�J�g�\�IJ��������o���RS�u}_���$��7h�5�N�=��C�a(`�[F�jk���W���+d������Q����x����Jd�J�q%2	%�	%���rY--������LT�t4A�����98~g�$
���Mc������V��m��>���{���F�!�p9%;~g@WL������}_RR�+�\��R��wV��%����n�B������x!���]�goV���;��=e���*�T��Pk����!�Rc�s0J�;��u���d�:�,u����s���Fn�����B�v���u���n�I�����������7R�tj}����rCJe���u+�.U��B���jU��Q�g���|���:,-q���7+���P�U&�3�2w�E	�(Jr�\��A��p<�h�~�/{�D\��S82�����@�$��q����C��S��^x�A�A�e��A�l�U_4;F�	��UW�QW��a��@�_����fD�tX�TX�tXn�GK�/�pM_�f�FRa���{esYe��@:�|��������>�w7~SF���������n�s���]��voU��J�JT"��-��%g�Kn��������>%��H���s;N��:��G3��|/��>'^�������2��[�n���.W�:e����J��/h�����6�{*,��������������~�m����x�1g�kd����6]�h�4H���co��(�2�e�r����������X&��o�;�qI����&G��MAowm�
��P�RC
���������������lv���r��Y�v~�c��n��u�lK8�%z��/�����w�&d�������US���(-v��7��Bp�"����|���qk��-�=���?�{��c�`��v������S�s:��H�F�25��W�������v<������Um��
���5#*s�����]��tX�#�KXK�p�tt`P	3��@��`�u������7-�N������@�)=�C)�C�2��JTb�[�6�/�c9~g�}���~C;z�Y�_��Z����;���;����\�ny�I��Jo�BJ8�N��)�IH%R���|�@�_?x��,�%����u�^Uf(m9���/�6�������?J���6�374_��y��N���O^�[��q5�:-�_1��NleSJ�IE2a��Q����~������v���p���$m8�N��u�������������^��Y�m�����W�9U���k�>�]���;��r�1���&;�u����y{���Txp����3g�&v������������������P6��D3����.?es��T6�x�����fV���0:������F�5��3N4��Ie��|�����lF.���B_*����������H�����N-����y7t����^�8�]�v��|���D�H������%���f�#��[�^i-���3(���������\�.-q�.`_�e{����srR!�*W��\e�
��^������q��<���U����A����'�{
e3Ny
�n��AW��n���>
N�H�j��.X��(5��yh{N!7N�E����f��~
�T��.�*IU�j5g�K���+m��%z�����9U�u�L��"=�cz��o����4Jd�'%Y��������}.��V�8�Y��#��[�Qx��e�W(�MY��px�����L^�	�5NH
jz�Z6]�e��i�����|R!��F}��3��.��v���u	��f��d6q����	���`�����M+�1�����u��Z,T�k^�B��^8��;�9:v�[�DBCCYe2�S3#3�Q&����3T[[g9������+��*�5e����)s����gj���wv������������pr�/����)M����-]f]N��df3:��Vw�K��]�Y9[S�gX���{��:����Ag�|��v4�|�fV���'���V���0c2�N-[���M�t��l=�l^�
+-������|�r|N�<�:�v����1�|�O,������s����W,�%�O/���e�~w��'{G>6J
]���7��]!�a=W�.o��v���u�iJ�Y���S��R8=�C�v)���`�Z4�r���/��G7X�{�~��N��Q��~LWPWP~g@3�j�������m>�������a���y!�5\�E�KFJ��1�J+e&U����"I�LD��2J���Jo�<�<�W��J�}b�U���?}��K��9�}�=��_ln�gT����1h�����U�o��o$vp�:|�C�hT�TR�dR�LZ�DB�dR�TR��p��+�/�{�����r����&vj��
�5����/@��N�N��D0��Ow<a9�5|���_�}����('�vq���������cGu`p������:���$��mb�����5K�DGv�t����{^��NG�������������|.�J����1������)�#�C����#�9S�tdx�ET�tD��������M��+�R����w�j����J�����C<7t���C��-��5.T���]����N��r������o�����Jx�������I)A���tx�Ly����[����������i��a�|������>����G�|��r|�R����^k��Q����BbV:�R,S,U,S<U"W4U,��w������O+��������������]RG�,�DMM����@���i��������I
'G�)Uz�l� ��T�^�>��`�e�J
�O�q�lM&�VI�}_��l��������*wW���(����A�m<�aO��38|�8�*O��
��<�b��W�Z�1i&��
��9��};,�gT���Y���%������)���F�OF�(����^%������!e����9�^�����������e�W�^�����m���^��]5wTw�]e��)!�`��B���j��T����!Im��j��h ��"���J��J�RJ
��I%SJ�S*--��K�X�M�S����om?�N����c=u�t%	�=��n�=y����=nU���J���m�5�����,+S�lb�"��u*��*�5���L6#s(�`�D��������.���I{����-�-]s0�O�;7�pwy�NsG�!�������ba<��c��e��v��r�d�:��&�4����Z\k�Wb��WN���������N�����1���M���.�`����%7Zl'�LT}�^�q��g�lzo�zz�X����Z�I��Av����]m��j���Tg��);]��g���Pf�{����[��[e����{�H'�op�������e��gW�U�'������,��9S����~�fW����D�D��QQ��OrG���c9^���#����xz(�_����s��)���L���L6#��/��oVp�3�o�XK$vp����R�����������H�&�&=�v����_-���2�����V����D�pb��v��N�x��II��c��$�1s(���C��oJJJti�
��xj����t���/��������h��)��^C������6����SG����]BC�������Z>�6��D������>��`bg��u�����mb�H���c����������w��X�_1�j�����=zq�s���*f���	���u��;\\�
����^��Whv=O�S��K��/���d��=�K�*���=�����������f��Y�������������l9Q��^�>������ �J��NsY��x�W�=1�w��w��w�8J�_��J���i��M�����.y��c�8ub�..%�\��1A1����o��+[���R>{��+$��p<�h��B�
��k`�O�i�4��fM�������8E�-������~���Z�O�>Cw�e�@6���>�O�x<�z�r:]�I��~����{
�t(=�:)�qbO�K����q����z��,wZ,o�����+_��.�F������-7X���}_�����xsY��N��D�~��1�q����z��a9.I���w���O:�5|#e�����������O�d8�r�:e�:e�8�PT�`Z!_���=�[�T6����C��R��n�L6�C�v��ie��JgSJ���_��R��5\n���#�]B�Ia�g�s���������*_���q�O�����=�=�7Gc�IMA�������������
�r��g�y\�^iI}�������s�-����p05�D&�_G%NCN�S�R���h�Uz��);��`��k�X���US��������q�c'���Z��
���i���N=������u�bG��;o2�t�"�i*kfefM
e�2MS��u2��w���uvR&��gf������Y��[�!��������Y�_y�5����#�no��.C��)��%�i��v�p9UZk�}���:�����T��u�K�_�}�_���2Ci��Y�m�x�/���������y�m����M�Tz��%jv]�|��RK�4���!+��Z�>5�~9.��3������Fu�rc�"�(5d���2���i3G���Jt�	��)CN�~�Uz�lwEb�0gf�M�L��+T�����h|&v"����R��jQ�CRs�n�y��KZ�8��?���
��P*�V�L+�N)c������^��y������|�r�a�����6������)��o}��5c�l��g��\{���o��j��1j*�^�RG�J�*~[Z��i��eQQ_����M�)���Jy��G��mR������+��Y������U�7�����������8�;��,�������R6U-eS�y~��]m���|I��~=���L�t��[��n`�oj��~����G��w��n~��p����?�Jk�����G�������O����,���LU���;=��9r�r���T���
��L�S:����q:�4�#o]N��7�lc�'>���%r���z����1J
C�k��>`=������+V[����Te����z�V�Zj�9�����>7���'����F��z��Z��5
��S`|c��k�2�P�C&�����g�q;�J���[_P�=w���)�U\R,S{G��n���S������a��$B��cIDATu�Sw������������vh8J#}�A�F�M5Mz�O�0���s�
�������������ew�j~��BJ�0������!g*��Q��������kJ>�|�L�L�����>��^�R`�J]u�m�>_���7�6%�9I���J��Lv4��7�(0��N���5
�o�Q`��)/��@a�3��Rub��Th���H��}'���!�$��@Q�;��
�h���^y�]���9�]�������K�Lf�s��\Z���������nxQ�Vj�n��y���x�ibGRE��|�^�)v���,��S��� H�L$v&;��	���Ab`�0����{&l���WZR��1�(0��N���5
�o�Q�dW���r��Q�
`� �0A��� �$��������.���>����u�bI�������m���T>�Mw���ZR;|n6���]����A���z��Z��6g�w��w�z���!=r�	������z����]�RR�����t�2��p6������o6�����K:~�������5�s�y��������W�$����o��+[���R>{��+4|n��w�����}g�~�R�Y�BW�����Dm�a��+�C�5���������O���w�4���k�j^�Ei��������������?�?0��y���H�8C)��.-��zd�i^���I�?��z@7��j�?>�����5����z~�V?���/�r��;z��W���O��/����4�i�l����n�v��%�]w�v=���r��}�cA%^{M�����g7jI�5�/��m��z=�TD�������T_r�N���o����������{d����zj���w������L�~���O�y����������X����9�_i��ag$�y�����n���q���������&����jvH�������VU&���]�m�3���ci�6����-S"/�^b�z`���'2�0I�@��<3jd����sp���9�p���WQ����X����3-��X�3���+�?Z����r7��$$��������<����gu��>+�~~e�w%I�0�b�4H��:�������-M�}�d��@6��<���G��
 I��O{�dJc@4����i���_c
�K��g�`���f~��O�ow���[eT/F��1�����cG8�����F������Y�x��~��Nv����_�n���G0����)*���a����@����	��
j�N�4��c�Uy�ln�$��������I�\������;�@6E�����vZ{�!Ou1,7����zW�t	s����	CR'�iZW���	R�(�3�.Mn�z4I��>�l��22/Ik3��)�-Q
���B��\���X�C����|�M<@�����0���E���,.>;%1

���$��Y�|�|<�j���������N�-�x���v-)����2���
��>]���'�|J������.p��KF@���y������M�q�__I��v��
��u�.
���TO<����&��SLi6@��d7'�o���Kf1r�xjz�S<���$���I�PP1�1�����Y�o�L&�i3��>	��:!{X�u�r�Uo��3�HvH:�>�E$������E{����!���\-����K�B"�A�3>��;�vC$�Ew�{�u%�'yq&Tr������[��2I���g_
H��s�;�X;�<�:�,H���w%
]�y���+���|`����v�o��Utl�����T-�t&�^6���2~���X���\6���t���$����I�����������{��o"uG9��:�I���T��� ���OD��a���
�*��+NV�q�A@$�bUH������
Hw�����yP�t�������t~DgLg��3�(_P��W���_0!���++��*'>.���n�D	�w%
I�����xq�(����X�������~����	i}}3�V�����wz8M@��*J�,g�]el�����r�x�+I���H�T��S��?�P�t7�%1G�������F�%cT�

S|�skfP
��4�Vg�C��c�v�[2�au�r,
s������� l�������h�Iy��g�B$
�\v��c�y�\���~<���8���]IC����7x�}<�WO��O��o_9P;���
K���6�r]�~#�%}/F�h�q�������0!z�����$��Tl�'LP�b#��&H��Clx���3��EU�����8�0���i��������>���?�pHg�c��e\�JI���]E�O�/���	Il����R�M^W�y����Y��]�k�.������L���6-���7�B�h#on	���g����]I��X��uG�X��gC`��r�v8@�48���X������:'�����Y���. ���?�k�hJ���$]��q���S��2C������}�$����}:�~�kH����]s�cI^1����0��
�0I�S�����Q������e��5���5�y��/t!�TH:'�h���������.�k����v���b����P5�w��mV��Kb���8��]�:���JYX;�	��s�V��Ip">�
��7���o\��P��V�mH��LX4�s�����&���U64Ds�tp�_��/VR�W��m����c����u����#�zv.�c�O��}l;���������K��	j���$]�v$I�$I�$I�2�S�I�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!�.v$I�t��S[S��9���]y�4_AH�;�y�������4��r�^_Iyp���~�����)z�G,����$I�ti3��$I�����FN\;��O�"7 `�9���
GS�,�ac=Y�$I�.};�$I��6Z���������]
I^>��/v)$I�$�k��S�N�����$I���z�
���,����c�S�bqf.���Wf�,�����`����?�w��C�n�V"���E����~{���]Gx�&�W������~������==��fs�'{xsS�� Fi�.-#~f0E�k����h>B,��k'q�=�DO/����:�^3�����?�@s�,�t#����t�!������tt����{*���wg{�Y~W#�/ZyZ%�?3��A��������������)�>�u���O�b��$';��E��J�����������o��;z���JP��:�+��YQFn��K���i�5L<���S�H��������o�ic�����x�������)<������:v7��3�<�"�%~es�L����h��m�x~�A�$�0|b)�K+�sv���C�����&Iw���QL�i%5�����u�����W��Tl��Oog����HB$?����3��|z�RH��?���,*k��o'8��Iv��<RI��g75�rK�$I����I��KY��Gl�6���L� ;E�#��z�.&�VR:���A�m-��[Y������Yq3���{���~S��%���H�}�yxy���]�^�����<p[�
��k�w�A�one�w��|��6���(����f�
�a���X����e?`��($��J��j��{6sp��YNQN��6����a�MT�+Y�c:�����,Iu������w@d�K����Cf>v3K�����-�����n]-��x3+�a��eDS^����m"�n��(,g��V�j3uW�e�w����l�,�g��z��H���&>9�����Y}�V�����;z�7���$�Vof_���gg0�2Hueq�p�qO/m$���s����?����a���=���<���D���o���Jq`��<�x#cWO��V;�>��}cg������C�����z�']���zv�{�\V�!������ �����t���k�OE$�mg���X;�V���sF"A@��=�7�����$[����[U��GF�|UnI�$I�����.�$I�.�p�?;=b$����D�JSr����g����%1"�`���DF����'��.��O��yD���US��*8�������q���N�w�D�H�hj~\��M���:�������S�yp6U����e�[%zn����������������(�wMa���|���  �����HN@$���Pb�	�_=���Mg��XO�J���������}g����[�������zq1 �Rz��\��O��S���kXX�������M��}=��_O�������q=��s�U���=o@���<h=�K��)T�������P$����q��c^>������$�Z�^C�B�'9�������/��'��#a�D[H$ex��������w��:��{�>9��m!~:����g;3�S=#d��C��U0�j�=e�2yZ���������$I��5p��$I��.'J�����#�ph���� ���hH��h���xI^��"��(
�$B��SZ����U�^s��8�68�rv3m�W����H��Q��yC��v���4"�_a;��Px{�g��[2���c�~��)��n��IR�kg����|)K��[@������gV/�	�o������-w@<?
{S=�-�"D��0�Gu���"�{;�]��s�f�t�P2��|��%���1�������:����B�~2�}O����8c��gl�h��*$���M��va���}W
((����$B�N5���>�%�@w7���L�%I�$�k`�#I����x�/�����g�_�t��)���a������n� ��{�������� ���@��$ib�#����^������5�U����L��e�2��	�7�ww������������S��k������|��[lx�
��AE��������[�$I�.4�b�$I�GDIw�y�-��!��9�D�����
imNA~�gdD0��8�����L���p�0rt.������������<�"���Z��nG?�#:��������Q�M�}�
�hI}���b�c���?��k&3�������\'�����
Jv�H��m|���v����_�t*$ry�	�*��b.==��m����.��t4F����]v=��ME�#�{�k���<�A��#}����P���<
������$I�t��H�$������8��x���0��>�m���DzG#v����/�C��br���[�a�v���$�[��[���X�x�y.�I��cj�8�:@k�Jq��]4�,df�yc���%��w�������.A�z<���A�LOeI�����@v��a++o�����AJ�����;���O�w*X�8�}+6��9aDzG#u�'{������)�3����>u�D�l���7x���4�w�-��[l����]4���T,���S�}���7���
��B�����i=%^�gZ�0$������e������4��@Hb�v6l��b�C����-I�$I_�b�$I�G�]��e��}�-�3���#��`[��8j'$�RN��
~�4�� �����9���k��U,�����?���b1����������A�3����=�+o���; >�����ff����k���]���#���Dy1��0�%�
��sX����]���Y[���a����L}�F���3%�k�IR��uL�����f3�����.�<;���Q+���D�|�_,K�D)��5�9o�R2�{�yi�vV��H:'J�b4�?���MEgUrws=��_��xY��3����8~]>�;N���7X�h�4��������L�]f�v����D����?�3� ���7Q]e�/o$�t=����D������\;������$I��5���S�N]�BH�$I�H��������[y�'���5�$I�����$I�$I�$I�2���$I�$I�$IR�p*6I�$I�$I����I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I�;�$I�$I�$I�`G�$I�$I�$)C�H�$I�$I�$e�I�$I�$I��a�#I�$I�$I��!v$I�$I�$I�2���$I�$I�$IR�0��$I�$I�$I������&�-�IEND�B`�
#36Andrey Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#35)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 6/7/2023 03:06, Alena Rybakina wrote:

I corrected this constant in the patch.

The patch don't apply cleanly: it contains some trailing spaces.

Also, quick glance into the code shows some weak points;
1. transformBoolExprOr should have input type BoolExpr.
2. You can avoid the switch operator at the beginning of the function,
because you only need one option.
3. Stale comments: RestrictIinfos definitely not exists at this point.
4. I don't know, you really need to copy the expr or not, but it is
better to do as late, as possible.
5. You assume, that leftop is non-constant and rightop - constant. Why?
6.I doubt about equivalence operator. Someone can invent a custom '='
operator with another semantics, than usual. May be better to check
mergejoinability?
7. I don't know how to confidently identify constant expressions at this
level. So, I guess, You can only merge here expressions like
"F(X)=Const", not an 'F(X)=ConstExpression'.

See delta.diff with mentioned changes in attachment.

--
regards,
Andrey Lepikhov
Postgres Professional

Attachments:

delta.difftext/plain; charset=UTF-8; name=delta.diffDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index c9193d826f..26648b0876 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -107,41 +107,22 @@ typedef struct OrClauseGroupEntry
 static int const_transform_or_limit = 500;
 
 static Node *
-transformBoolExprOr(ParseState *pstate, Expr *expr_orig)
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 {
 	List		   *or_list = NIL;
 	List		   *groups_list = NIL;
 	ListCell	   *lc_eargs;
 	Node 		   *result;
-	BoolExpr 	   *expr = (BoolExpr *)copyObject(expr_orig);
-	const char 	   *opname;
+	BoolExpr 	   *expr;
 	bool			change_apply = false;
-	bool			or_statement = false;
-
-	Assert(IsA(expr, BoolExpr));
 
 	/* If this is not expression "Or", then will do it the old way. */
-	switch (expr->boolop)
-	{
-		case AND_EXPR:
-			opname = "AND";
-			break;
-		case OR_EXPR:
-			opname = "OR";
-			or_statement = true;
-			break;
-		case NOT_EXPR:
-			opname = "NOT";
-			break;
-		default:
-			elog(ERROR, "unrecognized boolop: %d", (int) expr->boolop);
-			opname = NULL;		/* keep compiler quiet */
-			break;
-	}
-
-	if (!or_statement || list_length(expr->args) < const_transform_or_limit)
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < const_transform_or_limit)
 		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
 
+	expr = (BoolExpr *)copyObject(expr_orig);
+
 	/*
 		* NOTE:
 		* It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
@@ -176,15 +157,13 @@ transformBoolExprOr(ParseState *pstate, Expr *expr_orig)
 		if (!arg)
 			break;
 
-		allow_transformation = (
-								or_statement &&
-		                        arg->type == T_A_Expr && (arg)->kind == AEXPR_OP &&
+		allow_transformation = (arg->type == T_A_Expr && (arg)->kind == AEXPR_OP &&
 							    list_length((arg)->name) >=1 && strcmp(strVal(linitial((arg)->name)), "=") == 0
 							   );
 
 
 		bare_orarg = transformExprRecurse(pstate, (Node *)arg);
-		bare_orarg = coerce_to_boolean(pstate, bare_orarg, opname);
+		bare_orarg = coerce_to_boolean(pstate, bare_orarg, "OR");
 
 		/*
 		 * The next step: transform all the inputs, and detect whether any contain
@@ -357,14 +336,10 @@ transformBoolExprOr(ParseState *pstate, Expr *expr_orig)
 			}
 		}
 
-		if (!change_apply)
-		{
-			or_statement = false;
-		}
 		list_free_deep(groups_list);
 	}
 
-	if (or_statement)
+	if (change_apply)
 	{
 		/* One more trick: assemble correct clause */
 		expr = list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, list_copy(or_list), -1) : linitial(or_list);
@@ -376,9 +351,8 @@ transformBoolExprOr(ParseState *pstate, Expr *expr_orig)
 	 * transformBoolExpr function
 	 */
 	else
-	{
 		result = transformBoolExpr(pstate, (BoolExpr *)expr_orig);
-	}
+
 	list_free(or_list);
 
 	return result;
@@ -496,7 +470,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = (Node *)transformBoolExprOr(pstate, (Expr *)expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *)expr);
 			break;
 
 		case T_FuncCall:
#37Andrey Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#35)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 6/7/2023 03:06, Alena Rybakina wrote:

The test was performed on the same benchmark database generated by 2
billion values.

I corrected this constant in the patch.

In attempt to resolve some issues had mentioned in my previous letter I
used op_mergejoinable to detect mergejoinability of a clause.
Constant side of the expression is detected by call of
eval_const_expressions() and check each side on the Const type of node.

See 'diff to diff' in attachment.

--
regards,
Andrey Lepikhov
Postgres Professional

Attachments:

delta-2.difftext/plain; charset=UTF-8; name=delta-2.diffDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 26648b0876..67d6f85010 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -111,38 +111,27 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 {
 	List		   *or_list = NIL;
 	List		   *groups_list = NIL;
-	ListCell	   *lc_eargs;
+	ListCell	   *lc;
 	Node 		   *result;
 	BoolExpr 	   *expr;
 	bool			change_apply = false;
 
-	/* If this is not expression "Or", then will do it the old way. */
+	/* If this is not an 'OR' expression, skip the transformation */
 	if (expr_orig->boolop != OR_EXPR ||
 		list_length(expr_orig->args) < const_transform_or_limit)
-		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
 
 	expr = (BoolExpr *)copyObject(expr_orig);
 
-	/*
-		* NOTE:
-		* It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
-		* a list of sub-restrictinfo args, and rinfo->clause - which is the
-		* same expression, made from bare clauses. To not break selectivity
-		* caches and other optimizations, use both:
-		* - use rinfos from orclause if no transformation needed
-		* - use  bare quals from rinfo->clause in the case of transformation,
-		* to create new RestrictInfo: in this case we have no options to avoid
-		* selectivity estimation procedure.
-		*/
-	foreach(lc_eargs, expr->args)
+	foreach(lc, expr->args)
 	{
-		A_Expr			   *arg = (A_Expr *) lfirst(lc_eargs);
-		Node			   *bare_orarg;
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
 		Node			   *const_expr;
-		Node			   *non_const_expr;
+		Node			   *nconst_expr;
 		ListCell		   *lc_groups;
 		OrClauseGroupEntry *gentry;
-		bool 				allow_transformation;
+		bool				const_is_left = true;
 
 		/*
 		 * The first step: checking that the expression consists only of equality.
@@ -154,33 +143,51 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 		 * same level of a single BoolExpr expression, otherwise all of them cannot be converted.
 		 */
 
-		if (!arg)
-			break;
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
 
-		allow_transformation = (arg->type == T_A_Expr && (arg)->kind == AEXPR_OP &&
-							    list_length((arg)->name) >=1 && strcmp(strVal(linitial((arg)->name)), "=") == 0
-							   );
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
 
+		/* Detect constant side of the clause */
+		if (IsA(get_leftop(orqual), Const))
+			const_is_left = true;
+		else if (IsA(get_rightop(orqual), Const))
+			const_is_left = false;
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
 
-		bare_orarg = transformExprRecurse(pstate, (Node *)arg);
-		bare_orarg = coerce_to_boolean(pstate, bare_orarg, "OR");
+		/* Get pointers to constant and expression sides of the qual */
+		nconst_expr = (const_is_left) ? get_rightop(orqual) :
+										get_leftop(orqual);
+		const_expr = (const_is_left) ?  get_leftop(orqual) :
+										get_rightop(orqual);
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
 
 		/*
 		 * The next step: transform all the inputs, and detect whether any contain
 	 	 * Vars.
 		 */
-		if (!allow_transformation || !bare_orarg || !IsA(bare_orarg, OpExpr) || !contain_vars_of_level(bare_orarg, 0))
+		if (!contain_vars_of_level(orqual, 0))
 		{
 			/* Again, it's not the expr we can transform */
-			or_list = lappend(or_list, bare_orarg);
+			or_list = lappend(or_list, orqual);
 			continue;
 		}
 
-		/*
-		 * Get pointers to constant and expression sides of the clause
-		 */
-		non_const_expr = get_leftop(bare_orarg);
-		const_expr = get_rightop(bare_orarg);
+		;
 
 		/*
 			* At this point we definitely have a transformable clause.
@@ -196,15 +203,15 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 
 			Assert(v->node != NULL);
 
-			if (equal(v->node, non_const_expr))
+			if (equal(v->node, nconst_expr))
 			{
 				v->consts = lappend(v->consts, const_expr);
-				non_const_expr = NULL;
+				nconst_expr = NULL;
 				break;
 			}
 		}
 
-		if (non_const_expr == NULL)
+		if (nconst_expr == NULL)
 			/*
 				* The clause classified successfully and added into existed
 				* clause group.
@@ -213,10 +220,10 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 
 		/* New clause group needed */
 		gentry = palloc(sizeof(OrClauseGroupEntry));
-		gentry->node = non_const_expr;
+		gentry->node = nconst_expr;
 		gentry->consts = list_make1(const_expr);
-		gentry->opno = ((OpExpr *)bare_orarg)->opno;
-		gentry->expr = (Expr *)bare_orarg;
+		gentry->opno = ((OpExpr *)orqual)->opno;
+		gentry->expr = (Expr *)orqual;
 		groups_list = lappend(groups_list,  (void *) gentry);
 	}
 
#38Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Andrey Lepikhov (#36)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi! Thank you for your detailed review, your changes have greatly helped
to improve this patch.

On 06.07.2023 13:20, Andrey Lepikhov wrote:

On 6/7/2023 03:06, Alena Rybakina wrote:

I corrected this constant in the patch.

The patch don't apply cleanly: it contains some trailing spaces.

I fixed it.

Also, quick glance into the code shows some weak points;
1. transformBoolExprOr should have input type BoolExpr.

Agreed.

2. You can avoid the switch operator at the beginning of the function,
because you only need one option.

Agreed.

3. Stale comments: RestrictIinfos definitely not exists at this point.

Yes, unfortunately, I missed this from the previous version when I tried
to perform such a transformation at the index creation stage.

4. I don't know, you really need to copy the expr or not, but it is
better to do as late, as possible.

Yes, I agree with you, copying "expr" is not necessary in this patch

5. You assume, that leftop is non-constant and rightop - constant. Why?

Agreed, It was too presumptuous on my part and I agree with your changes.

6.I doubt about equivalence operator. Someone can invent a custom '='
operator with another semantics, than usual. May be better to check
mergejoinability?

Yes, I agree with you, and I haven't thought about it before. But I
haven't found any functions to arrange this in PostgreSQL, but using
mergejoinability turns out to be more beautiful here.

7. I don't know how to confidently identify constant expressions at
this level. So, I guess, You can only merge here expressions like
"F(X)=Const", not an 'F(X)=ConstExpression'.

I see, you can find solution for this case, thank you for this, and I
think it's reliable enough.

On 07.07.2023 05:43, Andrey Lepikhov wrote:

On 6/7/2023 03:06, Alena Rybakina wrote:

The test was performed on the same benchmark database generated by 2
billion values.

I corrected this constant in the patch.

In attempt to resolve some issues had mentioned in my previous letter
I used op_mergejoinable to detect mergejoinability of a clause.
Constant side of the expression is detected by call of
eval_const_expressions() and check each side on the Const type of node.

See 'diff to diff' in attachment.

I notices you remove condition for checking equal operation.

strcmp(strVal(linitial((arg)->name)), "=") == 0

Firstly, it is noticed me not correct, but a simple example convinced me
otherwise:

postgres=# explain analyze select x from a where x=1 or x>5 or x<3 or x=2;
                                               QUERY PLAN
--------------------------------------------------------------------------------------------------------
 Seq Scan on a  (cost=0.00..2291.00 rows=97899 width=4) (actual
time=0.038..104.168 rows=99000 loops=1)
   Filter: ((x > '5'::numeric) OR (x < '3'::numeric) OR (x = ANY
('{1,2}'::numeric[])))
   Rows Removed by Filter: 1000
 Planning Time: 9.938 ms
 Execution Time: 113.457 ms
(5 rows)

It surprises me that such check I can write such similar way:

eval_const_expressions(NULL, orqual).

Yes, I see we can remove this code:

bare_orarg = transformExprRecurse(pstate, (Node *)arg);
bare_orarg = coerce_to_boolean(pstate, bare_orarg, "OR");

because we will provide similar manipulation in this:

foreach(l, gentry->consts)
{
      Node       *rexpr = (Node *) lfirst(l);

      rexpr = coerce_to_common_type(pstate, rexpr,
                                                scalar_type,
                                                "IN");
     aexprs = lappend(aexprs, rexpr);
}

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

0001-Replace-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=0001-Replace-OR-clause-to-ANY-expressions.patchDownload
From 9134099ef9808ca27494bc131558d04b24d9bdeb Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 29 Jun 2023 17:46:58 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than 500 or
 expressions. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

---
 src/backend/parser/parse_expr.c  | 269 ++++++++++++++++++++++++++++++-
 src/tools/pgindent/typedefs.list |   1 +
 2 files changed, 269 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6d..961ca3e482c 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -95,6 +95,273 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int const_transform_or_limit = 500;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+	Node 		   *result;
+	BoolExpr 	   *expr;
+	bool			change_apply = false;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < const_transform_or_limit)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+		bool				const_is_left = true;
+
+		/*
+		 * The first step: checking that the expression consists only of equality.
+		 * We can only do this here, while arg is still row data type, namely A_Expr.
+		 * After applying transformExprRecurce, we already know that it will be OpExr type,
+		 * but checking the expression for equality is already becoming impossible for us.
+		 * Sometimes we have the chance to devide expression into the groups on
+		 * equality and inequality. This is possible if all list items are not at the
+		 * same level of a single BoolExpr expression, otherwise all of them cannot be converted.
+		 */
+
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/* Detect constant side of the clause */
+		if (IsA(get_leftop(orqual), Const))
+			const_is_left = true;
+		else if (IsA(get_rightop(orqual), Const))
+			const_is_left = false;
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/* Get pointers to constant and expression sides of the qual */
+		nconst_expr = (const_is_left) ? get_rightop(orqual) :
+										get_leftop(orqual);
+		const_expr = (const_is_left) ?  get_leftop(orqual) :
+										get_rightop(orqual);
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * The next step: transform all the inputs, and detect whether
+		 * any contain Vars.
+		 */
+		if (!contain_vars_of_level(orqual, 0))
+		{
+			/* Again, it's not the expr we can transform */
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		;
+
+		/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table (htab key ???).
+			*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->opno = ((OpExpr *)orqual)->opno;
+		gentry->expr = (Expr *)orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this rinfo, just add itself
+		* to the list and go further.
+		*/
+		list_free(or_list);
+
+		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation. It's been a long way ;)
+			 *
+			 * First of all, try to select a common type for the array elements.  Note that
+			 * since the LHS' type is first in the list, it will be preferred when
+			 * there is doubt (eg, when all the RHS items are unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (OidIsValid(scalar_type) && scalar_type != RECORDOID)
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common type
+				 * and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = get_array_type(scalar_type);
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1; /* Position of the new clause is undefined */
+
+				saopexpr = (ScalarArrayOpExpr *)make_scalar_array_op(pstate,
+												   list_make1(makeString((char *) "=")),
+												   true,
+												   gentry->node,
+												   (Node *) newa,
+												   -1); /* Position of the new clause is undefined */
+
+				/*
+				* TODO: here we can try to coerce the array to a Const and find
+				* hash func instead of linear search (see 50e17ad281b).
+				* convert_saop_to_hashed_saop((Node *) saopexpr);
+				* We don't have to do this anymore, do we?
+				*/
+
+				or_list = lappend(or_list, (void *) saopexpr);
+				change_apply = true;
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	if (change_apply)
+	{
+		/* One more trick: assemble correct clause */
+		expr = list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, list_copy(or_list), -1) : linitial(or_list);
+		result = (Node *)expr;
+	}
+	/*
+	 * There was no reasons to create a new expresion, so
+	 * run the original BoolExpr conversion with using
+	 * transformBoolExpr function
+	 */
+	else
+		result = transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+
+	list_free(or_list);
+
+	return result;
+}
 
 /*
  * transformExpr -
@@ -208,7 +475,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *)expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e941fb6c82f..c3abb725c8c 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1631,6 +1631,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

#39Andrey Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#38)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 7/7/2023 15:20, Alena Rybakina wrote:

because we will provide similar manipulation in this:

foreach(l, gentry->consts)
{
      Node       *rexpr = (Node *) lfirst(l);

      rexpr = coerce_to_common_type(pstate, rexpr,
                                                scalar_type,
                                                "IN");
     aexprs = lappend(aexprs, rexpr);
}

I'm not sure that it should be replaced.
In attachment - a bit more corrections to the patch.
The most important change - or_list contains already transformed
expression subtree. So, I think we don't need to free it at all.

--
regards,
Andrey Lepikhov
Postgres Professional

Attachments:

diff-3.difftext/plain; charset=UTF-8; name=diff-3.diffDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 961ca3e482..f0fd63f05c 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -112,9 +112,6 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 	List		   *or_list = NIL;
 	List		   *groups_list = NIL;
 	ListCell	   *lc;
-	Node 		   *result;
-	BoolExpr 	   *expr;
-	bool			change_apply = false;
 
 	/* If this is not an 'OR' expression, skip the transformation */
 	if (expr_orig->boolop != OR_EXPR ||
@@ -131,16 +128,7 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 		OrClauseGroupEntry *gentry;
 		bool				const_is_left = true;
 
-		/*
-		 * The first step: checking that the expression consists only of equality.
-		 * We can only do this here, while arg is still row data type, namely A_Expr.
-		 * After applying transformExprRecurce, we already know that it will be OpExr type,
-		 * but checking the expression for equality is already becoming impossible for us.
-		 * Sometimes we have the chance to devide expression into the groups on
-		 * equality and inequality. This is possible if all list items are not at the
-		 * same level of a single BoolExpr expression, otherwise all of them cannot be converted.
-		 */
-
+		/* At first, transform the arg and evaluate constant expressions. */
 		orqual = transformExprRecurse(pstate, (Node *) arg);
 		orqual = coerce_to_boolean(pstate, orqual, "OR");
 		orqual = eval_const_expressions(NULL, orqual);
@@ -151,7 +139,13 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 			continue;
 		}
 
-		/* Detect constant side of the clause */
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 */
 		if (IsA(get_leftop(orqual), Const))
 			const_is_left = true;
 		else if (IsA(get_rightop(orqual), Const))
@@ -175,26 +169,14 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 		}
 
 		/*
-		 * The next step: transform all the inputs, and detect whether
-		 * any contain Vars.
-		 */
-		if (!contain_vars_of_level(orqual, 0))
-		{
-			/* Again, it's not the expr we can transform */
-			or_list = lappend(or_list, orqual);
-			continue;
-		}
-
-		;
-
-		/*
-			* At this point we definitely have a transformable clause.
-			* Classify it and add into specific group of clauses, or create new
-			* group.
-			* TODO: to manage complexity in the case of many different clauses
-			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
-			* like a hash table (htab key ???).
-			*/
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
 		foreach(lc_groups, groups_list)
 		{
 			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
@@ -220,20 +202,18 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 		gentry = palloc(sizeof(OrClauseGroupEntry));
 		gentry->node = nconst_expr;
 		gentry->consts = list_make1(const_expr);
-		gentry->opno = ((OpExpr *)orqual)->opno;
-		gentry->expr = (Expr *)orqual;
+		gentry->expr = (Expr *) orqual;
 		groups_list = lappend(groups_list,  (void *) gentry);
 	}
 
 	if (groups_list == NIL)
 	{
 		/*
-		* No any transformations possible with this rinfo, just add itself
-		* to the list and go further.
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
 		*/
-		list_free(or_list);
-
-		return transformBoolExpr(pstate, (BoolExpr *)expr_orig);
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
 	}
 	else
 	{
@@ -267,11 +247,12 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 			}
 
 			/*
-			 * Do the transformation. It's been a long way ;)
+			 * Do the transformation.
 			 *
-			 * First of all, try to select a common type for the array elements.  Note that
-			 * since the LHS' type is first in the list, it will be preferred when
-			 * there is doubt (eg, when all the RHS items are unknown literals).
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
 			 *
 			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
 			 *
@@ -288,8 +269,8 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 			if (array_type != InvalidOid)
 			{
 				/*
-				 * OK: coerce all the right-hand non-Var inputs to the common type
-				 * and build an ArrayExpr for them.
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
 				 */
 				List	   *aexprs;
 				ArrayExpr  *newa;
@@ -314,24 +295,18 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 				newa->array_typeid = get_array_type(scalar_type);
 				newa->multidims = false;
 				newa->elements = aexprs;
-				newa->location = -1; /* Position of the new clause is undefined */
+				newa->location = -1;
 
-				saopexpr = (ScalarArrayOpExpr *)make_scalar_array_op(pstate,
-												   list_make1(makeString((char *) "=")),
-												   true,
-												   gentry->node,
-												   (Node *) newa,
-												   -1); /* Position of the new clause is undefined */
-
-				/*
-				* TODO: here we can try to coerce the array to a Const and find
-				* hash func instead of linear search (see 50e17ad281b).
-				* convert_saop_to_hashed_saop((Node *) saopexpr);
-				* We don't have to do this anymore, do we?
-				*/
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
 
 				or_list = lappend(or_list, (void *) saopexpr);
-				change_apply = true;
 			}
 			else
 			{
@@ -344,23 +319,10 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 		list_free_deep(groups_list);
 	}
 
-	if (change_apply)
-	{
-		/* One more trick: assemble correct clause */
-		expr = list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, list_copy(or_list), -1) : linitial(or_list);
-		result = (Node *)expr;
-	}
-	/*
-	 * There was no reasons to create a new expresion, so
-	 * run the original BoolExpr conversion with using
-	 * transformBoolExpr function
-	 */
-	else
-		result = transformBoolExpr(pstate, (BoolExpr *)expr_orig);
-
-	list_free(or_list);
-
-	return result;
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
 }
 
 /*
@@ -475,7 +437,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *)expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
#40Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Andrey Lepikhov (#39)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

I agreed with the changes. Thank you for your work.

I updated patch and added you to the authors.

I specified Ranier Vilela as a reviewer.

On 10.07.2023 06:12, Andrey Lepikhov wrote:

On 7/7/2023 15:20, Alena Rybakina wrote:

because we will provide similar manipulation in this:

foreach(l, gentry->consts)
{
       Node       *rexpr = (Node *) lfirst(l);

       rexpr = coerce_to_common_type(pstate, rexpr,
                                                 scalar_type,
                                                 "IN");
      aexprs = lappend(aexprs, rexpr);
}

I'm not sure that it should be replaced.
In attachment - a bit more corrections to the patch.
The most important change - or_list contains already transformed
expression subtree. So, I think we don't need to free it at all.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

0001-Replace-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=0001-Replace-OR-clause-to-ANY-expressions.patchDownload
From 97239cdeac541d3aaeafde3d15a5b6fdc36f86de Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 29 Jun 2023 17:46:58 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than 500 or
 expressions. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
---
 src/backend/parser/parse_expr.c  | 231 ++++++++++++++++++++++++++++++-
 src/tools/pgindent/typedefs.list |   1 +
 2 files changed, 231 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6d..0ddcb880ef8 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -95,6 +95,235 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int const_transform_or_limit = 500;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < const_transform_or_limit)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+		bool				const_is_left = true;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+			const_is_left = true;
+		else if (IsA(get_rightop(orqual), Const))
+			const_is_left = false;
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/* Get pointers to constant and expression sides of the qual */
+		nconst_expr = (const_is_left) ? get_rightop(orqual) :
+										get_leftop(orqual);
+		const_expr = (const_is_left) ?  get_leftop(orqual) :
+										get_rightop(orqual);
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (OidIsValid(scalar_type) && scalar_type != RECORDOID)
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = get_array_type(scalar_type);
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -208,7 +437,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e941fb6c82f..c3abb725c8c 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1631,6 +1631,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

#41Ranier Vilela
ranier.vf@gmail.com
In reply to: Alena Rybakina (#40)
Re: POC, WIP: OR-clause support for indexes

Hi Alena,

Em seg., 10 de jul. de 2023 às 05:38, Alena Rybakina <
lena.ribackina@yandex.ru> escreveu:

I agreed with the changes. Thank you for your work.

I updated patch and added you to the authors.

I specified Ranier Vilela as a reviewer.

Is a good habit when post a new version of the patch, name it v1, v2,
v3,etc.
Makes it easy to follow development and references on the thread.

Regarding the last patch.
1. I think that variable const_is_left is not necessary.
You can stick with:
+ if (IsA(get_leftop(orqual), Const))
+ nconst_expr =get_rightop(orqual);
+ const_expr = get_leftop(orqual) ;
+ else if (IsA(get_rightop(orqual), Const))
+ nconst_expr =get_leftop(orqual);
+ const_expr = get_rightop(orqual) ;
+ else
+ {
+ or_list = lappend(or_list, orqual);
+ continue;
+ }

2. Test scalar_type != RECORDOID is more cheaper,
mainly if OidIsValid were a function, we knows that is a macro.
+ if (scalar_type != RECORDOID && OidIsValid(scalar_type))

3. Sorry about wrong tip about array_type, but if really necessary,
better use it.
+ newa->element_typeid = scalar_type;
+ newa->array_typeid = array_type;
4. Is a good habit, call free last, to avoid somebody accidentally using it.
+ or_list = lappend(or_list, gentry->expr);
+ list_free(gentry->consts);
+ continue;

5. list_make1(makeString((char *) "=")
Is an invariant?
We can store in a variable and keep out the loop?

Keep up the good work.

best regards,
Ranier Vilela

#42Ranier Vilela
ranier.vf@gmail.com
In reply to: Ranier Vilela (#41)
Re: POC, WIP: OR-clause support for indexes

Em seg., 10 de jul. de 2023 às 09:03, Ranier Vilela <ranier.vf@gmail.com>
escreveu:

Hi Alena,

Em seg., 10 de jul. de 2023 às 05:38, Alena Rybakina <
lena.ribackina@yandex.ru> escreveu:

I agreed with the changes. Thank you for your work.

I updated patch and added you to the authors.

I specified Ranier Vilela as a reviewer.

Is a good habit when post a new version of the patch, name it v1, v2,
v3,etc.
Makes it easy to follow development and references on the thread.

Regarding the last patch.
1. I think that variable const_is_left is not necessary.
You can stick with:
+ if (IsA(get_leftop(orqual), Const))
+ nconst_expr =get_rightop(orqual);
+ const_expr = get_leftop(orqual) ;
+ else if (IsA(get_rightop(orqual), Const))
+ nconst_expr =get_leftop(orqual);
+ const_expr = get_rightop(orqual) ;
+ else
+ {
+ or_list = lappend(or_list, orqual);
+ continue;
+ }

2. Test scalar_type != RECORDOID is more cheaper,
mainly if OidIsValid were a function, we knows that is a macro.
+ if (scalar_type != RECORDOID && OidIsValid(scalar_type))

3. Sorry about wrong tip about array_type, but if really necessary,
better use it.
+ newa->element_typeid = scalar_type;
+ newa->array_typeid = array_type;
4. Is a good habit, call free last, to avoid somebody accidentally using
it.
+ or_list = lappend(or_list, gentry->expr);
+ list_free(gentry->consts);
+ continue;

5. list_make1(makeString((char *) "=")
Is an invariant?

Please nevermind 5. Is not invariant.

regards,
Ranier Vilela

#43Andrey Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#40)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 10/7/2023 15:38, Alena Rybakina wrote:

I agreed with the changes. Thank you for your work.

I updated patch and added you to the authors.

I specified Ranier Vilela as a reviewer.

This patch looks much better than earlier. But it definitely needs some
covering with tests. As a first simple approximation, here you can see
the result of regression tests, where the transformation limit is set to
0. See in the attachment some test changes induced by these diffs.

Also, I see some impact of the transformation to other queries:
create_view.out:
(NOT x > z) ----> (x <= z)
inherit.out:
(((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
to
(((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))

Transformations, mentioned above, are correct, of course. But it can be
a sign of possible unstable behavior.

--
regards,
Andrey Lepikhov
Postgres Professional

Attachments:

diff-4.difftext/plain; charset=UTF-8; name=diff-4.diffDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 0ddcb880ef..3d9b385c1f 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -43,6 +43,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+int			or_transform_limit = 500;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -104,8 +105,6 @@ typedef struct OrClauseGroupEntry
 	Expr 		   *expr;
 } OrClauseGroupEntry;
 
-static int const_transform_or_limit = 500;
-
 static Node *
 transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 {
@@ -115,7 +114,7 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 
 	/* If this is not an 'OR' expression, skip the transformation */
 	if (expr_orig->boolop != OR_EXPR ||
-		list_length(expr_orig->args) < const_transform_or_limit)
+		list_length(expr_orig->args) < or_transform_limit)
 		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
 
 	foreach(lc, expr_orig->args)
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index c14456060c..c7ac73ebe0 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -2046,6 +2046,16 @@ struct config_int ConfigureNamesInt[] =
 		100, 1, MAX_STATISTICS_TARGET,
 		NULL, NULL, NULL
 	},
+	{
+		{"or_transform_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&or_transform_limit,
+		500, 0, INT_MAX,
+		NULL, NULL, NULL
+	},
 	{
 		{"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
 			gettext_noop("Sets the FROM-list size beyond which subqueries "
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7..891e6a462b 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT int or_transform_limit;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f..60e053d217 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,46 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+RESET or_transform_limit;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c953297..c052b113ee 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ or_transform_limit
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9b8638f286..fbe711e0ee 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,6 +4207,33 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 2abf759385..5eb94d2821 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET or_transform_limit;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET or_transform_limit;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..a2949d3d69 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET or_transform_limit;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..0d33c0b61e 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,20 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+RESET or_transform_limit;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 3e5032b04d..3b717400d9 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1396,6 +1396,12 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET or_transform_limit;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index d1c60b8fe9..77f3e6c3b9 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET or_transform_limit;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET or_transform_limit;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..634bf08e5f 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET or_transform_limit;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
#44Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Ranier Vilela (#42)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 10.07.2023 15:15, Ranier Vilela wrote:

Em seg., 10 de jul. de 2023 às 09:03, Ranier Vilela
<ranier.vf@gmail.com> escreveu:

Hi Alena,

Em seg., 10 de jul. de 2023 às 05:38, Alena Rybakina
<lena.ribackina@yandex.ru> escreveu:

I agreed with the changes. Thank you for your work.

I updated patch and added you to the authors.

I specified Ranier Vilela as a reviewer.

Is a good habit when post a new version of the patch, name it v1,
v2, v3,etc.
Makes it easy to follow development and references on the thread.

Sorry, I fixed it.

Regarding the last patch.
1. I think that variable const_is_left is not necessary.
You can stick with:
+ if (IsA(get_leftop(orqual), Const))
+ nconst_expr =get_rightop(orqual);
+ const_expr = get_leftop(orqual) ;
+ else if (IsA(get_rightop(orqual), Const))
+ nconst_expr =get_leftop(orqual);
+ const_expr = get_rightop(orqual) ;
+ else
+ {
+ or_list = lappend(or_list, orqual);
+ continue;
+ }

Agreed.

2. Test scalar_type != RECORDOID is more cheaper,
mainly if OidIsValid were a function, we knows that is a macro.
+ if (scalar_type != RECORDOID && OidIsValid(scalar_type))

Is it safe? Maybe we should first make sure that it can be checked on
RECORDOID at all?

3. Sorry about wrong tip about array_type, but if really necessary,
better use it.
+ newa->element_typeid = scalar_type;
+ newa->array_typeid = array_type;

Agreed.

4. Is a good habit, call free last, to avoid somebody accidentally
using it.
+ or_list = lappend(or_list, gentry->expr);
+ list_free(gentry->consts);
+ continue;

No, this is not necessary, because we add the original expression in
these places to the resulting list and later
we will not use the list of constants for this group at all, otherwise
it would be an error.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

v5-Replace-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=v5-Replace-OR-clause-to-ANY-expressions.patchDownload
From 55e56f1557ca6879eae6ea62845e180ebfd04662 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Tue, 11 Jul 2023 15:19:22 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than 500 or
 expressions. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

---
 src/backend/parser/parse_expr.c  | 232 ++++++++++++++++++++++++++++++-
 src/tools/pgindent/typedefs.list |   1 +
 2 files changed, 232 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6d..36b50b6441d 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -95,6 +95,236 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int const_transform_or_limit = 500;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < const_transform_or_limit)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+		bool				const_is_left = true;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (OidIsValid(scalar_type) && scalar_type != RECORDOID)
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -208,7 +438,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e941fb6c82f..c3abb725c8c 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1631,6 +1631,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
5.1.1

#45Ranier Vilela
ranier.vf@gmail.com
In reply to: Alena Rybakina (#44)
Re: POC, WIP: OR-clause support for indexes

Em ter., 11 de jul. de 2023 às 09:29, Alena Rybakina <
lena.ribackina@yandex.ru> escreveu:

Hi!
On 10.07.2023 15:15, Ranier Vilela wrote:

Em seg., 10 de jul. de 2023 às 09:03, Ranier Vilela <ranier.vf@gmail.com>
escreveu:

Hi Alena,

Em seg., 10 de jul. de 2023 às 05:38, Alena Rybakina <
lena.ribackina@yandex.ru> escreveu:

I agreed with the changes. Thank you for your work.

I updated patch and added you to the authors.

I specified Ranier Vilela as a reviewer.

Is a good habit when post a new version of the patch, name it v1, v2,
v3,etc.
Makes it easy to follow development and references on the thread.

Sorry, I fixed it.

Regarding the last patch.

1. I think that variable const_is_left is not necessary.
You can stick with:
+ if (IsA(get_leftop(orqual), Const))
+ nconst_expr =get_rightop(orqual);
+ const_expr = get_leftop(orqual) ;
+ else if (IsA(get_rightop(orqual), Const))
+ nconst_expr =get_leftop(orqual);
+ const_expr = get_rightop(orqual) ;
+ else
+ {
+ or_list = lappend(or_list, orqual);
+ continue;
+ }

Agreed.

You missed in removing the declaration
- bool const_is_left = true;
.

2. Test scalar_type != RECORDOID is more cheaper,
mainly if OidIsValid were a function, we knows that is a macro.
+ if (scalar_type != RECORDOID && OidIsValid(scalar_type))

Is it safe? Maybe we should first make sure that it can be checked on

RECORDOID at all?

Yes it's safe, because && connector.
But you can leave as is in v5.

best regards,
Ranier Vilela

#46Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Ranier Vilela (#45)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 11.07.2023 16:29, Ranier Vilela wrote:

Em ter., 11 de jul. de 2023 às 09:29, Alena Rybakina
<lena.ribackina@yandex.ru> escreveu:

Hi!

On 10.07.2023 15:15, Ranier Vilela wrote:

Em seg., 10 de jul. de 2023 às 09:03, Ranier Vilela
<ranier.vf@gmail.com> escreveu:

Hi Alena,

Em seg., 10 de jul. de 2023 às 05:38, Alena Rybakina
<lena.ribackina@yandex.ru> escreveu:

I agreed with the changes. Thank you for your work.

I updated patch and added you to the authors.

I specified Ranier Vilela as a reviewer.

Is a good habit when post a new version of the patch, name it
v1, v2, v3,etc.
Makes it easy to follow development and references on the thread.

Sorry, I fixed it.

Regarding the last patch.
1. I think that variable const_is_left is not necessary.
You can stick with:
+ if (IsA(get_leftop(orqual), Const))
+ nconst_expr =get_rightop(orqual);
+ const_expr = get_leftop(orqual) ;
+ else if (IsA(get_rightop(orqual), Const))
+ nconst_expr =get_leftop(orqual);
+ const_expr = get_rightop(orqual) ;
+ else
+ {
+ or_list = lappend(or_list, orqual);
+ continue;
+ }

Agreed.

You missed in removing the declaration
- bool const_is_left = true;

Yes, thank you. I fixed it.

.

2. Test scalar_type != RECORDOID is more cheaper,
mainly if OidIsValid were a function, we knows that is a macro.
+ if (scalar_type != RECORDOID && OidIsValid(scalar_type))

Is it safe? Maybe we should first make sure that it can be checked
on RECORDOID at all?

Yes it's safe, because && connector.
But you can leave as is in v5.

Added it.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

v5-Replace-OR-clause-to-ANY-expressions.-Replace.patchtext/x-patch; charset=UTF-8; name=v5-Replace-OR-clause-to-ANY-expressions.-Replace.patchDownload
From d4ca399ec5a1866025e6cea5ed5cf0e231af38e3 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Tue, 11 Jul 2023 17:10:25 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than 500 or
 expressions. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

---
 src/backend/parser/parse_expr.c  | 231 ++++++++++++++++++++++++++++++-
 src/tools/pgindent/typedefs.list |   1 +
 2 files changed, 231 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6d..82d51035684 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -95,6 +95,235 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int const_transform_or_limit = 500;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < const_transform_or_limit)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -208,7 +437,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e941fb6c82f..c3abb725c8c 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1631,6 +1631,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

#47Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Andrey Lepikhov (#43)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 11.07.2023 11:47, Andrey Lepikhov wrote:

This patch looks much better than earlier. But it definitely needs
some covering with tests. As a first simple approximation, here you
can see the result of regression tests, where the transformation limit
is set to 0. See in the attachment some test changes induced by these
diffs.

Yes, I think so too. I also added some tests. I have attached an
additional diff-5.diff where you can see the changes.

Also, I see some impact of the transformation to other queries:
create_view.out:
(NOT x > z) ----> (x <= z)
inherit.out:
(((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
to -
(((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))

Transformations, mentioned above, are correct, of course. But it can
be a sign of possible unstable behavior.

I think it can be made more stable if we always add the existing
transformed expressions first, and then the original ones, or vice versa. T

o do this, we will need two more lists, I think, and then we can combine
them, where the elements of the second will be written to the end of the
first.

But I suppose that this may not be the only unstable behavior - I
suppose we need sorting result elements on the left side, what do you think?

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

diff-5.difftext/x-patch; charset=UTF-8; name=diff-5.diffDownload
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cc229d4dcaf..60e053d2179 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1922,81 +1922,6 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
-                                               QUERY PLAN                                               
---------------------------------------------------------------------------------------------------------
- Aggregate
-   ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
-         ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_thous_tenthous
-                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
-               ->  Bitmap Index Scan on tenk1_thous_tenthous
-                     Index Cond: (thousand = 41)
-(8 rows)
-
-SELECT count(*) FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
- count 
--------
-    10
-(1 row)
-
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                         QUERY PLAN                                                          
------------------------------------------------------------------------------------------------------------------------------
- Aggregate
-   ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
-         ->  BitmapOr
-               ->  BitmapAnd
-                     ->  Bitmap Index Scan on tenk1_hundred
-                           Index Cond: (hundred = 42)
-                     ->  BitmapOr
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (tenthous < 2)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
-               ->  Bitmap Index Scan on tenk1_thous_tenthous
-                     Index Cond: (thousand = 41)
-(14 rows)
-
-SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
- count 
--------
-    20
-(1 row)
-
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                          QUERY PLAN                                                          
-------------------------------------------------------------------------------------------------------------------------------
- Aggregate
-   ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
-         ->  BitmapAnd
-               ->  Bitmap Index Scan on tenk1_hundred
-                     Index Cond: (hundred = 42)
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: ((thousand = 99) AND (tenthous = 2))
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
-(11 rows)
-
-SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
- count 
--------
-    10
-(1 row)
-
 RESET or_transform_limit;
 --
 -- Check behavior with duplicate index column contents
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 2314d92a6d4..fbe711e0eec 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4233,29 +4233,6 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
 (17 rows)
 
-explain (costs off)
-select * from tenk1 a join tenk1 b on
-  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
-  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                                          QUERY PLAN                                                                           
----------------------------------------------------------------------------------------------------------------------------------------------------------------
- Nested Loop
-   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
-   ->  Seq Scan on tenk1 b
-   ->  Materialize
-         ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-(15 rows)
-
 RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 9c6baace0e2..0d33c0b61ee 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -749,24 +749,6 @@ SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
-SELECT count(*) FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
-
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-
-EXPLAIN (COSTS OFF)
-SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
 RESET or_transform_limit;
 
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d4d7d853a4a..3b717400d9d 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1401,10 +1401,6 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-explain (costs off)
-select * from tenk1 a join tenk1 b on
-  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
-  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 RESET or_transform_limit;
 
 --
v6-Replace-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=v6-Replace-OR-clause-to-ANY-expressions.patchDownload
From be10ec6237542a1f6d3706a109073840656b645d Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Tue, 11 Jul 2023 20:46:06 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

---
 src/backend/parser/parse_expr.c               | 230 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 115 +++++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  50 ++++
 src/test/regress/expected/partition_prune.out | 179 ++++++++++++++
 src/test/regress/expected/tidscan.out         |  17 ++
 src/test/regress/sql/create_index.sql         |  32 +++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 13 files changed, 674 insertions(+), 2 deletions(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6d..9d4f586448b 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -43,6 +43,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+int			or_transform_limit = 500;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -95,6 +96,233 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < or_transform_limit)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -208,7 +436,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index c14456060c0..c7ac73ebe02 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -2046,6 +2046,16 @@ struct config_int ConfigureNamesInt[] =
 		100, 1, MAX_STATISTICS_TARGET,
 		NULL, NULL, NULL
 	},
+	{
+		{"or_transform_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&or_transform_limit,
+		500, 0, INT_MAX,
+		NULL, NULL, NULL
+	},
 	{
 		{"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
 			gettext_noop("Sets the FROM-list size beyond which subqueries "
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..891e6a462b9 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT int or_transform_limit;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..cc229d4dcaf 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,121 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET or_transform_limit;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..c052b113eea 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ or_transform_limit
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9b8638f286a..2314d92a6d4 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,6 +4207,56 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
+
+RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 2abf7593858..5eb94d2821c 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET or_transform_limit;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET or_transform_limit;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..a2949d3d699 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET or_transform_limit;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..9c6baace0e2 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET or_transform_limit;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 3e5032b04dd..d4d7d853a4a 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1396,6 +1396,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET or_transform_limit;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index d1c60b8fe9d..77f3e6c3b9b 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET or_transform_limit;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET or_transform_limit;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..634bf08e5fc 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET or_transform_limit;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e941fb6c82f..c3abb725c8c 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1631,6 +1631,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

#48Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Alena Rybakina (#47)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi, all!

I sent a patch to commitfest and noticed that the authors and the
reviewer were incorrectly marked.

Sorry about that. I fixed it and sent the current version of the patch.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

v6-Replace-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=v6-Replace-OR-clause-to-ANY-expressions.patchDownload
From 087125cc413429bda05f22ebbd51115c23819285 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Tue, 18 Jul 2023 17:19:53 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
---
 src/backend/parser/parse_expr.c               | 230 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 115 +++++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  50 ++++
 src/test/regress/expected/partition_prune.out | 179 ++++++++++++++
 src/test/regress/expected/tidscan.out         |  17 ++
 src/test/regress/sql/create_index.sql         |  32 +++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 13 files changed, 674 insertions(+), 2 deletions(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 5a05caa8744..b2294af0f43 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -43,6 +43,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+int			or_transform_limit = 500;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -95,6 +96,233 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < or_transform_limit)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -208,7 +436,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index f9dba43b8c0..ddc27e2277c 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -2040,6 +2040,16 @@ struct config_int ConfigureNamesInt[] =
 		100, 1, MAX_STATISTICS_TARGET,
 		NULL, NULL, NULL
 	},
+	{
+		{"or_transform_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&or_transform_limit,
+		500, 0, INT_MAX,
+		NULL, NULL, NULL
+	},
 	{
 		{"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
 			gettext_noop("Sets the FROM-list size beyond which subqueries "
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..891e6a462b9 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT int or_transform_limit;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..cc229d4dcaf 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,121 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET or_transform_limit;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..c052b113eea 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ or_transform_limit
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9b8638f286a..2314d92a6d4 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,6 +4207,56 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
+
+RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 1eb347503aa..d1c5ce8be09 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET or_transform_limit;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET or_transform_limit;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..a2949d3d699 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET or_transform_limit;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..9c6baace0e2 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET or_transform_limit;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 3e5032b04dd..d4d7d853a4a 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1396,6 +1396,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET or_transform_limit;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index d1c60b8fe9d..77f3e6c3b9b 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET or_transform_limit;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET or_transform_limit;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..634bf08e5fc 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET or_transform_limit;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e941fb6c82f..c3abb725c8c 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1631,6 +1631,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
6.0.1

In reply to: Alena Rybakina (#28)
Re: POC, WIP: OR-clause support for indexes

On Thu, Jun 29, 2023 at 2:32 AM Alena Rybakina <lena.ribackina@yandex.ru> wrote:

Hi! I'm sorry I didn't answer you right away, I was too busy with work.

Same for me, this time. I was busy working on my patch, which I
finally posted yesterday.

To be honest, I didn't think about the fact that my optimization can help eliminate duplicates before reading the data before.

I'm not surprised that you didn't specifically think of that, because
it's very subtle.

I am still only in the process of familiarizing myself with the thread [1] (reference from your letter), but I have already seen that there are problems related, for example, to when "or" expressions refer to the parent element.

I didn't intend to imply that you might have the same problem here. I
just meant that OR optimizations can have problems with duplicate
elimination, in general. I suspect that your patch doesn't have that
problem, because you are performing a transformation of one kind of OR
into another kind of OR.

I think, I would face the similar problems if I complicate the current code, for example, so that not only or expressions standing on the same level are written in any, but also on different ones without violating the logic of the priority of executing operators.

I can't say that I am particularly experienced in this general area --
I have never tried to formally reason about how two different
statements are equivalent. It just hasn't been something that I've
needed to have a totally rigorous understanding of up until now. But
my recent patch changes that. Now I need to study this area to make
sure that I have a truly rigorous understanding.

Jeff Davis suggested that I read "Logic and Databases", by C.J. Date.
So now I have some homework to do.

Unfortunately, when I tried to make a transformation at the stage of index formation, I encountered too incorrect an assessment of the selectivity of relation, which affected the incorrect calculation of the cost and cardinality.

It's not surprising that a weird shift in the plan chosen by the
optimizer is seen with some random test case, as a result of this
added transformation. Even changes that are 100% strictly better (e.g.
changes in a selectivity estimation function that is somehow
guaranteed to be more accurate in all cases) might do that. Here is a
recent example of that with another patch, involving a bitmap OR:

/messages/by-id/CAH2-WznCDK9n2tZ6j_-iLN563_ePuC3NzP6VSVTL6jHzs6nRuQ@mail.gmail.com

This example was *not* a regression, if you go by conventional
measures. It was merely a less robust plan than the bitmap OR plan,
because it didn't pass down both columns as index quals.

BTW, there are various restrictions on the sort order of SAOPs that
you might want to try to familiarize yourself with. I describe them
(perhaps not very clearly) here:

/messages/by-id/CAH2-Wz=ksvN_sjcnD1+Bt-WtifRA5ok48aDYnq3pkKhxgMQpcw@mail.gmail.com

Currently, the optimizer doesn't recognize multi-column indexes with
SAOPs on every column as having a valid sort order, except on the
first column. It seems possible that that has consequences for your
patch. (I'm really only guessing, though; don't trust anything that I
say about the optimizer too much.)

--
Peter Geoghegan

#50Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Peter Geoghegan (#49)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 26.07.2023 02:47, Peter Geoghegan wrote:

On Thu, Jun 29, 2023 at 2:32 AM Alena Rybakina <lena.ribackina@yandex.ru> wrote:

Hi! I'm sorry I didn't answer you right away, I was too busy with work.

Same for me, this time. I was busy working on my patch, which I
finally posted yesterday.

I'm glad to hear it, I've seen your thread ("Optimizing nbtree
ScalarArrayOp execution, allowing multi-column ordered scans, skip
scan"), but, unfortunately, I didn't have enough time to read it. I'll
review it soon!

To be honest, I didn't think about the fact that my optimization can help eliminate duplicates before reading the data before.

I'm not surprised that you didn't specifically think of that, because
it's very subtle.

I am still only in the process of familiarizing myself with the thread [1] (reference from your letter), but I have already seen that there are problems related, for example, to when "or" expressions refer to the parent element.

I didn't intend to imply that you might have the same problem here. I
just meant that OR optimizations can have problems with duplicate
elimination, in general. I suspect that your patch doesn't have that
problem, because you are performing a transformation of one kind of OR
into another kind of OR.

Yes, you are right, but I studied this topic and two other sources to
accumulate my knowledge. It was an exciting experience for me)

I was especially inspired after studying the interview with Goetz Graf
[2]: , his life experience is the most inspiring, and from this article I was able to get a broad understanding of the field of databases: current problems, future development, how it works... Thank you for the recommendation.
was able to get a broad understanding of the field of databases:
current problems, future development, how it works... Thank you for the
recommendation.

I discovered for myself that the idea described in the article [1] is
similar to the idea of representing grouped data in OLAP cubes, and
also, if I saw correctly, an algorithm like depth-first search is used
there, but for indexes.

I think it really helps to speed up the search with similar deep
filtering compared to cluster indexes, but do we have cases where we
don't use this algorithm because it takes longer than an usual index?
I thought about the situation with wide indexes (with a lot of multiple
columns) and having a lot of filtering predicates for them.
But I'm not sure about this, so it seems to me that this is a problem of
improper use of indexes rather.

I think, I would face the similar problems if I complicate the current code, for example, so that not only or expressions standing on the same level are written in any, but also on different ones without violating the logic of the priority of executing operators.

I can't say that I am particularly experienced in this general area --
I have never tried to formally reason about how two different
statements are equivalent. It just hasn't been something that I've
needed to have a totally rigorous understanding of up until now. But
my recent patch changes that. Now I need to study this area to make
sure that I have a truly rigorous understanding.

Jeff Davis suggested that I read "Logic and Databases", by C.J. Date.
So now I have some homework to do.

I'll read this book too. Maybe I can finish work with the knowledge I
got from there. Thank you for sharing!

Unfortunately, when I tried to make a transformation at the stage of index formation, I encountered too incorrect an assessment of the selectivity of relation, which affected the incorrect calculation of the cost and cardinality.

It's not surprising that a weird shift in the plan chosen by the
optimizer is seen with some random test case, as a result of this
added transformation. Even changes that are 100% strictly better (e.g.
changes in a selectivity estimation function that is somehow
guaranteed to be more accurate in all cases) might do that. Here is a
recent example of that with another patch, involving a bitmap OR:

/messages/by-id/CAH2-WznCDK9n2tZ6j_-iLN563_ePuC3NzP6VSVTL6jHzs6nRuQ@mail.gmail.com

At first, this surprised me very much. It took time to find a suitable
place to implement the transformation.

I have looked through this thread many times, I will study it in more
detail .

This example was *not* a regression, if you go by conventional
measures. It was merely a less robust plan than the bitmap OR plan,
because it didn't pass down both columns as index quals.

BTW, there are various restrictions on the sort order of SAOPs that
you might want to try to familiarize yourself with. I describe them
(perhaps not very clearly) here:

/messages/by-id/CAH2-Wz=ksvN_sjcnD1+Bt-WtifRA5ok48aDYnq3pkKhxgMQpcw@mail.gmail.com

Thank you! Yes, I'll study it too)

Currently, the optimizer doesn't recognize multi-column indexes with
SAOPs on every column as having a valid sort order, except on the
first column. It seems possible that that has consequences for your
patch. (I'm really only guessing, though; don't trust anything that I
say about the optimizer too much.)

Honestly, I couldn't understand your concerns very well, could you
describe it in more detail?

1. https://vldb.org/conf/1995/P710.PDF

2.
https://sigmodrecord.org/publications/sigmodRecord/2009/pdfs/05_Profiles_Graefe.pdf

--
Regards,
Alena Rybakina
Postgres Professional

In reply to: Alena Rybakina (#50)
Re: POC, WIP: OR-clause support for indexes

On Wed, Jul 26, 2023 at 6:30 PM Alena Rybakina <lena.ribackina@yandex.ru> wrote:

I didn't intend to imply that you might have the same problem here. I
just meant that OR optimizations can have problems with duplicate
elimination, in general. I suspect that your patch doesn't have that
problem, because you are performing a transformation of one kind of OR
into another kind of OR.

Yes, you are right, but I studied this topic and two other sources to
accumulate my knowledge. It was an exciting experience for me)

Cool! Yeah, a lot of the value with these sorts of things comes from
the way that they can interact with each other. This is hard to
describe exactly, but still important.

I was especially inspired after studying the interview with Goetz Graf
[2], his life experience is the most inspiring, and from this article I
was able to get a broad understanding of the field of databases:
current problems, future development, how it works... Thank you for the
recommendation.

I also think that his perspective is very interesting.

I think it really helps to speed up the search with similar deep
filtering compared to cluster indexes, but do we have cases where we
don't use this algorithm because it takes longer than an usual index?
I thought about the situation with wide indexes (with a lot of multiple
columns) and having a lot of filtering predicates for them.

I think that it should be possible for the optimizer to only use
multi-column SAOP index paths when there is at least likely to be some
small advantage -- that's definitely my goal. Importantly, we may not
really need to accurately model the costs where the new approach turns
out to be much faster. The only essential thing is that we avoid cases
where the new approach is much slower than the old approach. Which is
possible (in at least some cases) by making the runtime behavior
adaptive.

The best decision that the planner can make may be no decision at all.
Better to wait until runtime where at all possible, since that gives
us the latest and most accurate picture of things.

But I'm not sure about this, so it seems to me that this is a problem of
improper use of indexes rather.

It's hard to say how true that is.

Certainly, workloads similar to the TPC-DS benchmark kinda need
something like MDAM. It's just not practical to have enough indexes to
support every possible query -- the benchmark is deliberately designed
to have unpredictable, hard-to-optimize access paths. It seems to
require having fewer, more general indexes that can support
multi-dimensional access reasonably efficiently.

Of course, with OLTP it's much more likely that the workload will have
predictable access patterns. That makes having exactly the right
indexes much more practical. So maybe you're right there. But, I still
see a lot of value in a design that is as forgiving as possible. Users
really like that kind of thing in my experience.

Currently, the optimizer doesn't recognize multi-column indexes with
SAOPs on every column as having a valid sort order, except on the
first column. It seems possible that that has consequences for your
patch. (I'm really only guessing, though; don't trust anything that I
say about the optimizer too much.)

Honestly, I couldn't understand your concerns very well, could you
describe it in more detail?

Well, I'm not sure if there is any possible scenario where the
transformation from your patch makes it possible to go from an access
path that has a valid sort order (usually because there is an
underlying index scan) into an access path that doesn't. In fact, the
opposite situation seems more likely (which is good news) --
especially if you assume that my own patch is also present.

Going from a bitmap OR (which cannot return sorted output) to a
multi-column SAOP index scan (which now can) may have significant
value in some specific circumstances. Most obviously, it's really
useful when it enables us to feed tuples into a GroupAggregate without
a separate sort step, and without a hash aggregate (that's why I see
value in combining your patch with my own patch). You just need to be
careful about allowing the opposite situation to take place.

More generally, there is a need to think about strange second order
effects. We want to be open to useful second order effects that make
query execution much faster in some specific context, while avoiding
harmful second order effects. Intuitively, I think that it should be
possible to do this with the transformations performed by your patch.

In other words, "helpful serendipity" is an important advantage, while
"harmful anti-serendipity" is what we really want to avoid. Ideally by
making the harmful cases impossible "by construction".

--
Peter Geoghegan

#52Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Peter Geoghegan (#51)
Re: POC, WIP: OR-clause support for indexes

Hi!

I think it really helps to speed up the search with similar deep
filtering compared to cluster indexes, but do we have cases where we
don't use this algorithm because it takes longer than an usual index?
I thought about the situation with wide indexes (with a lot of multiple
columns) and having a lot of filtering predicates for them.

I think that it should be possible for the optimizer to only use
multi-column SAOP index paths when there is at least likely to be some
small advantage -- that's definitely my goal. Importantly, we may not
really need to accurately model the costs where the new approach turns
out to be much faster. The only essential thing is that we avoid cases
where the new approach is much slower than the old approach. Which is
possible (in at least some cases) by making the runtime behavior
adaptive.

The best decision that the planner can make may be no decision at all.
Better to wait until runtime where at all possible, since that gives
us the latest and most accurate picture of things.

But I'm not sure about this, so it seems to me that this is a problem of
improper use of indexes rather.

It's hard to say how true that is.

Certainly, workloads similar to the TPC-DS benchmark kinda need
something like MDAM. It's just not practical to have enough indexes to
support every possible query -- the benchmark is deliberately designed
to have unpredictable, hard-to-optimize access paths. It seems to
require having fewer, more general indexes that can support
multi-dimensional access reasonably efficiently.

Of course, with OLTP it's much more likely that the workload will have
predictable access patterns. That makes having exactly the right
indexes much more practical. So maybe you're right there. But, I still
see a lot of value in a design that is as forgiving as possible. Users
really like that kind of thing in my experience.

I tend to agree with you, but a runtime estimate cannot give us an
accurate picture when using indexes correctly or
any other optimizations due to the unstable state of the environment in
which the query is executed.
I believe that a more complex analysis is needed here.

Currently, the optimizer doesn't recognize multi-column indexes with
SAOPs on every column as having a valid sort order, except on the
first column. It seems possible that that has consequences for your
patch. (I'm really only guessing, though; don't trust anything that I
say about the optimizer too much.)

Honestly, I couldn't understand your concerns very well, could you
describe it in more detail?

Well, I'm not sure if there is any possible scenario where the
transformation from your patch makes it possible to go from an access
path that has a valid sort order (usually because there is an
underlying index scan) into an access path that doesn't. In fact, the
opposite situation seems more likely (which is good news) --
especially if you assume that my own patch is also present.

Going from a bitmap OR (which cannot return sorted output) to a
multi-column SAOP index scan (which now can) may have significant
value in some specific circumstances. Most obviously, it's really
useful when it enables us to feed tuples into a GroupAggregate without
a separate sort step, and without a hash aggregate (that's why I see
value in combining your patch with my own patch). You just need to be
careful about allowing the opposite situation to take place.

More generally, there is a need to think about strange second order
effects. We want to be open to useful second order effects that make
query execution much faster in some specific context, while avoiding
harmful second order effects. Intuitively, I think that it should be
possible to do this with the transformations performed by your patch.

In other words, "helpful serendipity" is an important advantage, while
"harmful anti-serendipity" is what we really want to avoid. Ideally by
making the harmful cases impossible "by construction".

I noticed only one thing there: when we have unsorted array values in
SOAP, the query takes longer than
when it has a sorted array. I'll double-check it just in case and write
about the results later.

I am also testing some experience with multi-column indexes using SAOPs.

--
Regards,
Alena Rybakina
Postgres Professional

In reply to: Alena Rybakina (#52)
Re: POC, WIP: OR-clause support for indexes

On Mon, Jul 31, 2023 at 9:38 AM Alena Rybakina <lena.ribackina@yandex.ru> wrote:

I noticed only one thing there: when we have unsorted array values in
SOAP, the query takes longer than
when it has a sorted array. I'll double-check it just in case and write
about the results later.

I would expect the B-Tree preprocessing by _bt_preprocess_array_keys()
to be very slightly faster when the query is written with presorted,
duplicate-free constants. Sorting is faster when you don't really have
to sort. However, I would not expect the effect to be significant
enough to matter, except perhaps in very extreme cases.
Although...some of the cases you care about are very extreme cases.

I am also testing some experience with multi-column indexes using SAOPs.

Have you thought about a similar transformation for when the row
constructor syntax happens to have been used?

Consider a query like the following, against a table with a composite
index on (a, b):

select * from multi_test where ( a, b ) in (( 1, 1 ), ( 2, 1 ));

This query will get a BitmapOr based plan that's similar to the plans
that OR-based queries affected by your transformation patch get today,
on HEAD. However, this equivalent spelling has the potential to be
significantly faster:

select * from multi_test where a = any('{1,2}') and b = 1;

(Of course, this is more likely to be true with my nbtree SAOP patch in place.)

Note that we currently won't use RowCompareExpr in many simple cases
where the row constructor syntax has been used. For example, a query
like this:

select * from multi_test where ( a, b ) = (( 2, 1 ));

This case already involves a transformation that is roughly comparable
to the one you're working on now. We'll remove the RowCompareExpr
during parsing. It'll be as if my example row constructor equality
query was written this way instead:

select * from multi_test where a = 2 and b = 1;

This can be surprisingly important, when combined with other things,
in more realistic examples.

The nbtree code has special knowledge of RowCompareExpr that makes the
rules for comparing index tuples different to those from other kinds
of index scans. However, due to the RowCompareExpr transformation
process I just described, we don't need to rely on that specialized
nbtree code when the row constructor syntax is used with a simple
equality clause -- which is what makes the normalization process have
real value. If the nbtree code cannot see RowCompareExpr index quals
then it cannot have this problem in the first place. In general it is
useful to "normalize to conjunctive normal form" when it might allow
scan key preprocessing in the nbtree code to come up with a much
faster approach to executing the scan.

It's easier to understand what I mean by showing a simple example. The
nbtree preprocessing code is smart enough to recognize that the
following query doesn't really need to do any work, due to having
quals that it recognizes as contradictory (it can set so->qual_okay to
false for unsatisfiable quals):

select * from multi_test where ( a, b ) = (( 2, 1 )) and a = -1;

However, it is not smart enough to perform the same trick if we change
one small detail with the query:

select * from multi_test where ( a, b ) >= (( 2, 1 )) and a = -1;

Ideally, the optimizer would canonicalize/normalize everything in a
way that made all of the nbtree preprocessing optimizations work just
as well, without introducing any new special cases. Obviously, there
is no reason why we can't perform the same trick with the second
variant. (Note also that the nbtree preprocessing code can be smart
about redundant quals, not just contradictory quals, so it matters
more than it may appear from this simple, unrealistic example of
mine.)

While these similar RowCompareExpr transformations are at least
somewhat important, that's not really why I bring them up now. I am
pointing them out now because I think that it might help you to
develop a more complete mental model of these transformations.
Ideally, your initial approach will generalize to other situations
later on. So it's worth considering the relationship between this
existing RowCompareExpr transformation, and the one that you're
working on currently. Plus other, future transformations.

This example might also give you some appreciation of why my SAOP
patch is confused about when we need to do normalization/safety
checks. Some things seem necessary when generating index paths in the
optimizer. Other things seem necessary during preprocessing, in the
nbtree code, at the start of the index scan. Unfortunately, it's not
obvious to me where the right place is to deal with each aspect of
setting up multi-column SAOP index quals. My mental model is very
incomplete.

--
Peter Geoghegan

#54Finnerty, Jim
jfinnert@amazon.com
In reply to: Peter Geoghegan (#53)
Re: POC, WIP: OR-clause support for indexes

Peter, I'm very glad to hear that you're researching this!

Will this include skip-scan optimizations for OR or IN predicates, or when the number of distinct values in a leading non-constant index column(s) is sufficiently small? e.g. suppose there is an ORDER BY b, and WHERE clause predicates (a = 1 AND b = 5) OR (c > 12 AND b BETWEEN 100 AND 200). Then a single index scan on an index with leading column b could visit b = 5, and then the range b from 100:200, and deliver the rows in the order requested. Or if the predicate is (a = 1 AND b = 5) OR (c LIKE 'XYZ' AND b < 12), then you can scan just b < 12. Or if the index is defined on (a, b) and you know that b = 100, and that there are only 4 distinct values of column a, then you could skip each distinct value of a where b = 100, and so on.

If you have an ORDER BY clause and a lower and upper bound on the first column of the ORDER BY list, you have a potential to reduce search effort versus a full index scan, even when that upper and lower bound needs to be derived from a complex predicate.

Of course, if you have an IN list you can either skip to the distinct values listed or scan the entire index, depending on estimated cost.

/Jim F

On 8/1/23, 3:43 PM, "Peter Geoghegan" <pg@bowt.ie <mailto:pg@bowt.ie>> wrote:

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

On Mon, Jul 31, 2023 at 9:38 AM Alena Rybakina <lena.ribackina@yandex.ru <mailto:lena.ribackina@yandex.ru>> wrote:

I noticed only one thing there: when we have unsorted array values in
SOAP, the query takes longer than
when it has a sorted array. I'll double-check it just in case and write
about the results later.

I would expect the B-Tree preprocessing by _bt_preprocess_array_keys()
to be very slightly faster when the query is written with presorted,
duplicate-free constants. Sorting is faster when you don't really have
to sort. However, I would not expect the effect to be significant
enough to matter, except perhaps in very extreme cases.
Although...some of the cases you care about are very extreme cases.

I am also testing some experience with multi-column indexes using SAOPs.

Have you thought about a similar transformation for when the row
constructor syntax happens to have been used?

Consider a query like the following, against a table with a composite
index on (a, b):

select * from multi_test where ( a, b ) in (( 1, 1 ), ( 2, 1 ));

This query will get a BitmapOr based plan that's similar to the plans
that OR-based queries affected by your transformation patch get today,
on HEAD. However, this equivalent spelling has the potential to be
significantly faster:

select * from multi_test where a = any('{1,2}') and b = 1;

(Of course, this is more likely to be true with my nbtree SAOP patch in place.)

Note that we currently won't use RowCompareExpr in many simple cases
where the row constructor syntax has been used. For example, a query
like this:

select * from multi_test where ( a, b ) = (( 2, 1 ));

This case already involves a transformation that is roughly comparable
to the one you're working on now. We'll remove the RowCompareExpr
during parsing. It'll be as if my example row constructor equality
query was written this way instead:

select * from multi_test where a = 2 and b = 1;

This can be surprisingly important, when combined with other things,
in more realistic examples.

The nbtree code has special knowledge of RowCompareExpr that makes the
rules for comparing index tuples different to those from other kinds
of index scans. However, due to the RowCompareExpr transformation
process I just described, we don't need to rely on that specialized
nbtree code when the row constructor syntax is used with a simple
equality clause -- which is what makes the normalization process have
real value. If the nbtree code cannot see RowCompareExpr index quals
then it cannot have this problem in the first place. In general it is
useful to "normalize to conjunctive normal form" when it might allow
scan key preprocessing in the nbtree code to come up with a much
faster approach to executing the scan.

It's easier to understand what I mean by showing a simple example. The
nbtree preprocessing code is smart enough to recognize that the
following query doesn't really need to do any work, due to having
quals that it recognizes as contradictory (it can set so->qual_okay to
false for unsatisfiable quals):

select * from multi_test where ( a, b ) = (( 2, 1 )) and a = -1;

However, it is not smart enough to perform the same trick if we change
one small detail with the query:

select * from multi_test where ( a, b ) >= (( 2, 1 )) and a = -1;

Ideally, the optimizer would canonicalize/normalize everything in a
way that made all of the nbtree preprocessing optimizations work just
as well, without introducing any new special cases. Obviously, there
is no reason why we can't perform the same trick with the second
variant. (Note also that the nbtree preprocessing code can be smart
about redundant quals, not just contradictory quals, so it matters
more than it may appear from this simple, unrealistic example of
mine.)

While these similar RowCompareExpr transformations are at least
somewhat important, that's not really why I bring them up now. I am
pointing them out now because I think that it might help you to
develop a more complete mental model of these transformations.
Ideally, your initial approach will generalize to other situations
later on. So it's worth considering the relationship between this
existing RowCompareExpr transformation, and the one that you're
working on currently. Plus other, future transformations.

This example might also give you some appreciation of why my SAOP
patch is confused about when we need to do normalization/safety
checks. Some things seem necessary when generating index paths in the
optimizer. Other things seem necessary during preprocessing, in the
nbtree code, at the start of the index scan. Unfortunately, it's not
obvious to me where the right place is to deal with each aspect of
setting up multi-column SAOP index quals. My mental model is very
incomplete.

--
Peter Geoghegan

In reply to: Finnerty, Jim (#54)
Re: POC, WIP: OR-clause support for indexes

Jim,

On Tue, Aug 1, 2023 at 1:11 PM Finnerty, Jim <jfinnert@amazon.com> wrote:

Peter, I'm very glad to hear that you're researching this!

Glad to hear it!

Will this include skip-scan optimizations for OR or IN predicates, or when the number of distinct values in a leading non-constant index column(s) is sufficiently small?

Yes -- though perhaps not in the first iteration.

As I go into on the thread associated with my own patch [1]/messages/by-id/CAH2-Wz=ksvN_sjcnD1+Bt-WtifRA5ok48aDYnq3pkKhxgMQpcw@mail.gmail.com -- Peter Geoghegan, my
initial goal is to support efficient execution of multiple IN() lists
for multiple columns from the same index, all while preserving index
sort order on output, and avoiding a separate duplicate elimination
step. Some of the most compelling cases for these MDAM techniques
involve GroupAggregates, ORDER BY ... LIMIT, and DISTINCT -- I
understand the importance of making the index scan appear to be a
conventional index scan to the optimizer.

If you have an ORDER BY clause and a lower and upper bound on the first column of the ORDER BY list, you have a potential to reduce search effort versus a full index scan, even when that upper and lower bound needs to be derived from a complex predicate.

It sounds like your example is an attempt to ascertain whether or not
my design considers the need to convert complicated predicates into
disjuncts that can be executed as if by one single index scan, via CNF
-> DNF transformations/preprocessing. That is certainly the plan, at
least medium term -- I fully expect to be able to combine all of these
techniques together, in ways that continue to work even with very
complicated predicates. Like the really hairy example from the MDAM
paper, or like your example.

There are already some nbtree scan key preprocessing steps a little
like the ones considered by the MDAM paper. These steps eliminate
redundant and contradictory quals -- but they weren't specifically
written with the very general MDAM DNF design requirements in mind.
Plus there are already at least some transformations like the one that
Alena is working on in the patch discussed on this thread -- these
were also not written with MDAM stuff in mind.

A major goal of mine for this project in the short term is to come up
with a very general design. I must reconcile all this stuff, somehow
or other, so that these very complicated cases will work just as well
as simpler and more obvious cases. I really hate special cases.

Of course, if you have an IN list you can either skip to the distinct values listed or scan the entire index, depending on estimated cost.

Actually, I think that it should be possible to decide on how to skip
dynamically, without needing an up-front decision around skipping from
the optimizer. In other words, the scans can skip using an adaptive
strategy. This is feasible provided I can make the overhead of a
dynamic/adaptive approach negligible. When it turns out that a full
index scan is appropriate, we'll just end up doing it that way at
runtime.

Nothing stops a given scan from needing to do skip a great deal in the
first half of an index, while scanning everything in the second half
of the index. Obviously, a static choice won't do well there, since it
works at the level of the whole scan/index, which seems like the wrong
framing to me. (Of course we'll still need to model skipping stuff in
the planner -- just not so that we can decide between two index paths
that are essentially identical, that should just be one index path.)

[1]: /messages/by-id/CAH2-Wz=ksvN_sjcnD1+Bt-WtifRA5ok48aDYnq3pkKhxgMQpcw@mail.gmail.com -- Peter Geoghegan
--
Peter Geoghegan

#56Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Peter Geoghegan (#53)
3 attachment(s)
Re: POC, WIP: OR-clause support for indexes

I fixed an error that caused the current optimization not to work with
prepared queries. I added a test to catch similar cases in the future.
I have attached a patch.

On 01.08.2023 22:42, Peter Geoghegan wrote:

On Mon, Jul 31, 2023 at 9:38 AM Alena Rybakina <lena.ribackina@yandex.ru> wrote:

I noticed only one thing there: when we have unsorted array values in
SOAP, the query takes longer than
when it has a sorted array. I'll double-check it just in case and write
about the results later.

I would expect the B-Tree preprocessing by _bt_preprocess_array_keys()
to be very slightly faster when the query is written with presorted,
duplicate-free constants. Sorting is faster when you don't really have
to sort. However, I would not expect the effect to be significant
enough to matter, except perhaps in very extreme cases.
Although...some of the cases you care about are very extreme cases.

I tested an optimization to compare execution time and scheduling with
sorting, shuffling, and reverse sorting constants in the simple case and
I didn't notice any significant changes (compare_sorted.png).
(I used a database with 100 million values generated by pgbench).

I am also testing some experience with multi-column indexes using SAOPs.

Have you thought about a similar transformation for when the row
constructor syntax happens to have been used?

Consider a query like the following, against a table with a composite
index on (a, b):

select * from multi_test where ( a, b ) in (( 1, 1 ), ( 2, 1 ));

This query will get a BitmapOr based plan that's similar to the plans
that OR-based queries affected by your transformation patch get today,
on HEAD. However, this equivalent spelling has the potential to be
significantly faster:

select * from multi_test where a = any('{1,2}') and b = 1;

(Of course, this is more likely to be true with my nbtree SAOP patch in place.)

No, I haven't thought about it yet. I studied the example and it would
really be nice to add optimization here. I didn't notice any problems
with its implementation. I also have an obvious example with the "or"
operator, for example
, select * from multi_test, where (a, b ) = ( 1, 1 ) or (a, b ) = ( 2, 1
) ...;

Although I think such a case will be used less often.

Thank you for the example, I think I understand better why our patches
help each other, but I will review your patch again.

I tried another example to see the lack of optimization in the pgbench
database, but I also created an additional index:

create index ind1 on pgbench_accounts(aid,bid);

test_db=# explain analyze select * from pgbench_accounts where (aid,
bid) in ((2,1), (2,2), (2,3), (3,3));
                                                             QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on pgbench_accounts  (cost=17.73..33.66 rows=1
width=97) (actual time=0.125..0.133 rows=1 loops=1)
   Recheck Cond: ((aid = 2) OR (aid = 2) OR (aid = 2) OR (aid = 3))
   Filter: (((aid = 2) AND (bid = 1)) OR ((aid = 2) AND (bid = 2)) OR
((aid = 2) AND (bid = 3)) OR ((aid = 3) AND (bid = 3)))
   Rows Removed by Filter: 1
   Heap Blocks: exact=1
   ->  BitmapOr  (cost=17.73..17.73 rows=4 width=0) (actual
time=0.100..0.102 rows=0 loops=1)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0) (actual time=0.036..0.037 rows=1 loops=1)
               Index Cond: (aid = 2)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0) (actual time=0.021..0.022 rows=1 loops=1)
               Index Cond: (aid = 2)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0) (actual time=0.021..0.021 rows=1 loops=1)
               Index Cond: (aid = 2)
         ->  Bitmap Index Scan on pgbench_accounts_pkey
(cost=0.00..4.43 rows=1 width=0) (actual time=0.019..0.020 rows=1 loops=1)
               Index Cond: (aid = 3)
 Planning Time: 0.625 ms
 Execution Time: 0.227 ms
(16 rows)

I think such optimization would be useful here: aid =2 and bid in (1,2)
or (aid,bid)=((3,3))

Note that we currently won't use RowCompareExpr in many simple cases
where the row constructor syntax has been used. For example, a query
like this:

select * from multi_test where ( a, b ) = (( 2, 1 ));

This case already involves a transformation that is roughly comparable
to the one you're working on now. We'll remove the RowCompareExpr
during parsing. It'll be as if my example row constructor equality
query was written this way instead:

select * from multi_test where a = 2 and b = 1;

This can be surprisingly important, when combined with other things,
in more realistic examples.

The nbtree code has special knowledge of RowCompareExpr that makes the
rules for comparing index tuples different to those from other kinds
of index scans. However, due to the RowCompareExpr transformation
process I just described, we don't need to rely on that specialized
nbtree code when the row constructor syntax is used with a simple
equality clause -- which is what makes the normalization process have
real value. If the nbtree code cannot see RowCompareExpr index quals
then it cannot have this problem in the first place. In general it is
useful to "normalize to conjunctive normal form" when it might allow
scan key preprocessing in the nbtree code to come up with a much
faster approach to executing the scan.

It's easier to understand what I mean by showing a simple example. The
nbtree preprocessing code is smart enough to recognize that the
following query doesn't really need to do any work, due to having
quals that it recognizes as contradictory (it can set so->qual_okay to
false for unsatisfiable quals):

select * from multi_test where ( a, b ) = (( 2, 1 )) and a = -1;

However, it is not smart enough to perform the same trick if we change
one small detail with the query:

select * from multi_test where ( a, b ) >= (( 2, 1 )) and a = -1;

Yes, I have run the examples and I see it.

((ROW(aid, bid) >= ROW(2, 1)) AND (aid = '-1'::integer))

As I see it, we can implement such a transformation:

'( a, b ) >= (( 2, 1 )) and a = -1'     ->    'aid >= 2 and bid >= 1 and
aid =-1'

It seems to me the most difficult thing is to notice problematic cases
where the transformations are incorrect, but I think it can be implemented.

Ideally, the optimizer would canonicalize/normalize everything in a
way that made all of the nbtree preprocessing optimizations work just
as well, without introducing any new special cases. Obviously, there
is no reason why we can't perform the same trick with the second
variant. (Note also that the nbtree preprocessing code can be smart
about redundant quals, not just contradictory quals, so it matters
more than it may appear from this simple, unrealistic example of
mine.)

I agree with your position, but I still don't understand how to consider
transformations to generalized cases without relying on special cases.

As I understand it, you assume that it is possible to apply
transformations at the index creation stage, but there I came across the
selectivity overestimation problem.

I still haven't found a solution for this problem.

While these similar RowCompareExpr transformations are at least
somewhat important, that's not really why I bring them up now. I am
pointing them out now because I think that it might help you to
develop a more complete mental model of these transformations.
Ideally, your initial approach will generalize to other situations
later on. So it's worth considering the relationship between this
existing RowCompareExpr transformation, and the one that you're
working on currently. Plus other, future transformations.

I will consider my case more broadly, but for this I will need some
research work.

This example might also give you some appreciation of why my SAOP
patch is confused about when we need to do normalization/safety
checks. Some things seem necessary when generating index paths in the
optimizer. Other things seem necessary during preprocessing, in the
nbtree code, at the start of the index scan. Unfortunately, it's not
obvious to me where the right place is to deal with each aspect of
setting up multi-column SAOP index quals. My mental model is very
incomplete.

To be honest, I think that in your examples I understand better what you
mean by normalization to the conjunctive norm, because I only had a
theoretical idea from the logic course.

Hence, yes, normalization/security checks - now I understand why they
are necessary.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

v7-Replace-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=v7-Replace-OR-clause-to-ANY-expressions.patchDownload
From 36f731a4c7cda1581427b04ddb016c0bc961935a Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Wed, 2 Aug 2023 15:44:26 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

---
 src/backend/parser/parse_expr.c               | 230 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 115 +++++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  67 +++++
 src/test/regress/expected/partition_prune.out | 179 ++++++++++++++
 src/test/regress/expected/tidscan.out         |  17 ++
 src/test/regress/sql/create_index.sql         |  32 +++
 src/test/regress/sql/join.sql                 |  19 ++
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 13 files changed, 700 insertions(+), 2 deletions(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index fed8e4d0897..56e7503445a 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -43,6 +43,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+int			or_transform_limit = 500;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +100,233 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < or_transform_limit)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const) || IsA(get_leftop(orqual), Param))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const) || IsA(get_rightop(orqual), Param))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +440,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index f9dba43b8c0..ddc27e2277c 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -2040,6 +2040,16 @@ struct config_int ConfigureNamesInt[] =
 		100, 1, MAX_STATISTICS_TARGET,
 		NULL, NULL, NULL
 	},
+	{
+		{"or_transform_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&or_transform_limit,
+		500, 0, INT_MAX,
+		NULL, NULL, NULL
+	},
 	{
 		{"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
 			gettext_noop("Sets the FROM-list size beyond which subqueries "
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..891e6a462b9 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT int or_transform_limit;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..cc229d4dcaf 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,121 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET or_transform_limit;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..c052b113eea 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ or_transform_limit
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9b8638f286a..b492ef1654f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,6 +4207,73 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
+
+SELECT FORMAT('prepare prep1 %s AS SELECT * FROM tenk1 t WHERE %s',
+ '(' || string_agg('int', ',') || ')',
+ string_agg(FORMAT('t.unique1 = $%s', g.id), ' or ')
+ ) AS cmd
+ FROM generate_series(1, 10) AS g(id) \gexec
+prepare prep1 (int,int,int,int,int,int,int,int,int,int) AS SELECT * FROM tenk1 t WHERE t.unique1 = $1 or t.unique1 = $2 or t.unique1 = $3 or t.unique1 = $4 or t.unique1 = $5 or t.unique1 = $6 or t.unique1 = $7 or t.unique1 = $8 or t.unique1 = $9 or t.unique1 = $10
+SELECT FORMAT('explain (costs off) execute prep1 %s;', '(' || string_agg(g.id::text, ',') || ')') AS cmd
+ FROM generate_series(1, 10) AS g(id) \gexec
+explain (costs off) execute prep1 (1,2,3,4,5,6,7,8,9,10);
+                                QUERY PLAN                                 
+---------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1 t
+   Recheck Cond: (unique1 = ANY ('{1,2,3,4,5,6,7,8,9,10}'::integer[]))
+   ->  Bitmap Index Scan on tenk1_unique1
+         Index Cond: (unique1 = ANY ('{1,2,3,4,5,6,7,8,9,10}'::integer[]))
+(4 rows)
+
+RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 1eb347503aa..d1c5ce8be09 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET or_transform_limit;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET or_transform_limit;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..a2949d3d699 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET or_transform_limit;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..9c6baace0e2 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET or_transform_limit;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 3e5032b04dd..b6cc4644518 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1396,6 +1396,25 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
+SELECT FORMAT('prepare prep1 %s AS SELECT * FROM tenk1 t WHERE %s',
+ '(' || string_agg('int', ',') || ')',
+ string_agg(FORMAT('t.unique1 = $%s', g.id), ' or ')
+ ) AS cmd
+ FROM generate_series(1, 10) AS g(id) \gexec
+SELECT FORMAT('explain (costs off) execute prep1 %s;', '(' || string_agg(g.id::text, ',') || ')') AS cmd
+ FROM generate_series(1, 10) AS g(id) \gexec
+
+RESET or_transform_limit;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index d1c60b8fe9d..77f3e6c3b9b 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET or_transform_limit;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET or_transform_limit;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..634bf08e5fc 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET or_transform_limit;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 66823bc2a77..8bee8d85e25 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1633,6 +1633,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

compare_sorted.pngimage/png; name=compare_sorted.pngDownload
�PNG


IHDR�72��sBIT|d�tEXtSoftwaregnome-screenshot��>.iTXtCreation Time���� 02 ������ 2023 18:16:398@�� IDATx���{t������dn�I&������& A.
�"Pi�Z/m�-=�=�����p��>�<����������S��*�*4H�r3@BBB�	�d�I��y�E��{2�y���������3�MZ>����D"��������������h """"""""""r�j����������H�P�-""""""""""1C���������������""""""""""3j����������H�P�-""""""""""1C���������������""""""""""3j����������H�P�-""""""""""1C���������������""""""""""3j����������H�P�-""""""""""1C���������������""""""""""3j����������H�P�-""""""""""1C���������������""""""""""3j����������H�P�-""""""""""1C���������������""""""""""3j����������H�P�-""""""""""1C���������������""""""""""3j����������H�P�-""""""""""1C���������������""""""""""3j����������H�P�-""""""""""1C���������������""""""""""3j����������H�P�-""""""""""1C���������������""""""""""3j����������H�P�-""""""""""1C���������������""""""""""3j����������H�P�-""""""""""1��DDDD.[�:����m�S��N���.'):U}*P���ja�3��k����G�r�u<�X	�!+��{�!�/���=@�#�y������vYa"""""2(�T����[��v�hts�w�.�_[�C��!������:S��?�MB�P%"""""��Bm�(	�����<���<���f�����/��%������X�~_�l.-��e��9�_�H+���|��&RgTr����k�o&���\��<�;���k�%�p�#lX��e�p���������%�_X����&�6�����>����p7�Rv����W���������l���}$D�s��f'g��f�]Ul;�����L�Y��x\�V��.��a�^s�;i�v�v���
���ad�yz���p	���d����x+�O5��`1�)����9�9��������\��-"""%�q���V?���;`����9i�g�h���<�'�%��G_�2��V���u�E�^���]v\���uO�>���Y����n>m�>6���rz�>�z��'m�W��;�����N?���?,�!�;_��W���YJ��5��q���l��=k����Oogg��r��������X��>�z�>��G�
`�c�����[��t|�\P��~�"���c��C,��,��������bi5�o,��W�������wYSn��������-"""2��������k#?�����F��b���xvY����L}������}���k,T�VB����(��S���)L�iv_���O��L�e��QpK={RY:��^��2�O����6�p<~.(d����e.\�
�������)��R#I;��]dZ���^n�c����f�}���r�Wn���^�va"""""r�(�T���Lkj;�~Wo,�G��Y�#��y��y�E~���
"�/����J��+z�-������C����KIrZ����@������v�#fc_M��������&~���O� !w(�v�Tj����DS����l���1�W���s�����*�~'Kf�
��������x9������d<�i�p�`���lsZ��G{��a:<~
�"R�p�T;��l���d�������H����""""Q����V:��K�s������]��N&�Jb���h�q�S������N/d��mlz���u���e���W��.�h'���P}�B��u�l����V#��C���AO��9Tm�Z@ikk������]TmqP1����/�������z���sY��,��
)m�a���3��-�����W{�������""""�����'��
X����yTT}���p������/���M�x�O<��E��fqg�:�q;�������r�/1�`�O����u�d~0��q
�������,�F
���Bm���+�o<�7����kx~����ZI�T�w�('��.~u�G����:~8���q�����,��G������0�)��\
���y��0�n����;F#��<n�����
�O��oV��0AO�=�Md�1��7����?�e��+������'qo�%�[DDDDD��!�D�]���������������#""""""""""3j����������H�P�-""""""""""1C�������������S�8_�]A�zB�.C�(-���v���(�������Ec@4F6=�c�l�#-��2D�N3�EDDDDDDDDD$f(����P[DDDDDDDDDDb�Bm�
�EDDDDDDDDD$f(����P[DDDDDDDDDDb�Bm�
�EDDDDDDDDD�`�/_���h�!�)���������s
�/�h """""""""���|A_�m���������ASGS�mV������oZ_��������u�,����N�S��`��
?���F����U���C+�9���nb��t�~�'�n�m]��k��+���2����U<��M�
������zf!�����eM����R�a�p��+X[��'v�6�g$o���yC_���=���k�����Y��3�����M~0�!���~\I�����j���������c_��1Z-�p���{m�Z���mn�\����������/����R����x�����q��Y�%x[����vO5�?�F��oaf:��Z�O��E���q�BV��������n�"���%������y)sK�:))����r?3�YD�������X>������\�����V?����~Z^���[���Y:���y���l�4�)p�����]����<2���i��x���0�"#�����(��Bm�a(����
�?�
@d��!�aN����������+pp����m�-�����9���5~���q�
����`��s�3���}R6�O����#����h�QM3�GZp%o��w��,W��0:)gg���h��������_v6E�]����q`�a|s�}��;3���������G��2*���=�P
�EDDDDDDDD�C���w��T��p^>�k�W\<���8r.�<����zaS��3f��$/�75����<�\	�Y>��~��`>�\����e�-��g&�v�C��O���g>�1���i]�y�v��6Q]���ne����ig�G2m)""""""""2��L�j�[�o�����U�����j�����6�u:(���E?�DQK��4���&v�����wiy�s���H��?�Xi6�-�l���Xwo��Z���-�n�l�<�=,����{��L��Eq�Y�k�c��nl�yLY<�{n�����������"""""""""�H$�F���K�v~��/F\~V.�o��6�t-�N���q�Z������n��n�Q9I�p��������l��$g��
G	w-s���^�gv��\�Py����Y���<uW��rK�9�tm3����V���}E?<���MXw9�o����!�{_\6��.�H$�v���+HWO(�eH�%[9��?{G�,�����h�lz��1 #���\Nc������95��HK�bU"�A�����������C����$,��]g�zPD���GDDDDDDDDDY\[�M0o��p�h"��Q�J$6)�$q��a]�Sm
�L�]E`�z�����P��j����JEb�����0�
|�����������X�=X��?��~/�����X|�3��y���tl��,�Q9Y�A�VDDDDDDDD����M�y<�g�!8�*"�����D8��L]{
�=��<�K�%-9g��9����7Y��a��lkOn�Q����X��7��q;��#v��C����cU*K�8�\K�m?}�/�����m*""""""""2|DIt���s������~�>zB����L��FAr1�v�`�)S9�6R���TlY�K������;�����08���pxK����$��g�bf������2m&�V���-�����~G2=����M�_4Dc`d����:{�[zI�e�F�"���Q%�I����$O��pI�!�������V����-����0�<+��~�'����+_����v�Ei�V����]�D���h������/�10��������w����&���g���'��������:��7���s}��'~��
=���_�ix��"C-���{m���3�'��Y�7;!�J��'��Y|�����F�T�@0�����������f�1�
���:�Dl6��#��Lm_��������m=��/�"e��C]��e#�����5,��]��N�I�e�N� �d��'Sf����Z��6;��jEDDDDDDDd$3��C����Az��	�����	`:=b{��5���:��aIfB�d
���M*��/#�:��X����0�|W'��f�:������{��|�/��X��_>�@�������\C����G���v/��y��������j~uk37��E�VS��=��^�����	u��h5��]��������'�h�;y�[u��I��G�0s�d��.��EB�m|%���M"EDDDDDDD$zzG��Mu�r-��28����d��
(L.��Y�([�V*������cX����N	��l�SY�r;����t���e�����eOq�rV�H$�v���+�5�G�a�~�9=����M�_4Dc`d������;��iM�b��*�1��^O}G-����8r����XS{���tvv����������e��CCCC�mV����3l�Y_��������u�,��8>S{��Z9�������ob�#|\���t����$�O���sy�;��x�76������k����%�5e;��?�h����)��@n)�����Y�;�X����/?i����5�ndS+��a��&q��y$�-��'���H.���,8�Lm;����M~�a�n��x��@�.��'�����On��3�-d�X�X[��+��������9vdL	����""""""""r���C4{��y�&o#�A/��Q|}���\�����B�W�r����m��Z����
`�0��v4�_����6w��C���F^}��~�RSS�jW�������/Y�����>|8�<�Jo��K,t��������J0x5�?XD��5���B�>vr�J��L!��M��[X4v�����V�ck�\~�	xY�d�m�a�T/�=������F|k��'���z�
���Tzf2Y�0������<��N�����q=�yn�I��=��]�?��������F�j
�EDDDDDDd�3�{��g���Z���d&b2��D�d��`�U�����C\GG�ff3MD�}�b2�����z^�����Gs�k�8#N��������I�=�4{&��S�~oK�d����� ���y#q�t�~'��">lZ��M������E�#���|F;��U�����������t:<�����}�k����Y��dySsh��k�jO!��2q��/�0�7�o����$Lk�t�B�K�G��^������#A/$7� ���F'e���g{e����^��v7	��d�Or���.��0�T�V��eS���.]���<�M/a�T{�7�)��a�Z�������$����P�a�%��y���]�������Pq	�_�J�m�+���M}�IAz���D,�~��kucN�����j�s(O����b
�EX��m��Po�����}G�zx�)mIV'w�
�i�_gc�ua��G�?�����H������9�'�������%�3:)�����"##���KHH !!�������#�����������s%|g�x��F��
F#��X����)$� x���_2x�V+��}`�h�-<r��=Uul��J��4��K2�0����"""""""2,�=�m�J��!4�L~:���1
b�!�pC08`�
�M`�5
c� �
A(Hof����L�u��\���#�����,������)w�?�����	\{&����fl:����Mu��2��Q����q|���l����}��������s�1�^��?�zC8�)��F�lI��774o��7^��cz��B�|�i���
�O*�B�#U���n�}z%�7�S4���+{hp|&��F�n�aH2z��������Nq��7���cv	I���|;�|
��)de{��f�#[i�����2�g���3�2����Mj�d���S���?y�����/��(
���n�Q�-"""""""�?���:"6�_��+�$�n�3l�X�b!r�	��/8��z����p���x>����x=�nv����=���a?�	-8����O'�1�� �9��"�N/���������PA!���~�9)�Q��FQ�r�M��;�k������aIfn���"�
�������S��i�qu�_=���&1���@[���+�����m{�F������p����e�,|�?|�K���+#]|9��7���jH:��d�]�X��z��k;6+�++�7���K��/��dU��g��e6��M����y���}E�����^�c.����]`�v�,�H�����c�D"���>����t�\�)1k��t,���/�10������h\��^�/�@��Bc��s�|"��%b��w;���_���S�RBAR1��.l-fC0����8o����F����0{��l��D�3�o�w�("�z����{��B��(�=G9��Bk�Q��BVbN��z��;p����O��M.f|�����W`�31��O���"�������GZ��Z�D�?��-"""""""�F$�A�������X��o0M0'2��f��
I0'^��"f3�T���s>���M\k+�}{Ok������I���t{��s_Gy��mT��<��b���E�5���+�i��`1��#T<���L&�O��YD��$j5���S�-"""""""�J��wE��3:�;���4z��q��H/�����_��e-"�6�X@\{;Oqm������h���u���fy����g�����=���6�u�����9Fsg�	�^���Fs�A\�ig�w.Z{��{j1`�j�8����e�]]t�����TRm.f��������P[DDDDDDD�,����]���zB�'��%P�C�7�)n��,�����|�������j1O]8�H�g�\BcJ1��p��p��(N9�Zzx�n���)�����HK� �1��kx��A�������m�@;�]~&��&�}-�B����?��3n*"�i��������C��2����o�8+We\MAr�I�����.mPu��|]�y<'fw�;�oS�'��V���D$!�^G��D"��ky�%0�p�=m����o��c?5�=�:������'8�z�#���q��n�nr�� 0�Bc�.�'!"��BmR���l��w�7�u:�]��nw5S�?`�{+�3
^j{a{���7���8o�����Nk�]I��_"�����	��w;	�����4{:�iWQ�,!?����9�
S���k	��>�7&"1I������������V�W���P3��D�.�R���}����5�z���f;,I��3R��<�����A���_���8O����3�&����M9�~wJ
�(zSR�/#b�l�pc��S�^UI���A~W"2\(��Ag��!�u���������o����`����	YT����9f�@[.L�l&��	��d(D�l��tc��S�e���J�� IDAT��:U���n$[�]�H�)��Ac�ua{����{�- TT��F��2��GaJ	����L���#�
����[w�q�m�;���
�(W=����-�7�������rD�N����������H�
Cw7��q�g�����~��4��3�`>&c��8�v�W��tzG��w�((,>q��z��PsF������]����P[DDDDDDDO\�{�>(av{����
4��s���`�83�2���p�K^�s3g��j��l��v)2��[x�[{(��*��.fh)��A5X��_���x�����8r��q5�I�d&fc�0(�,==�����m�Fi�y��������!#���c�������x(/���w����lnu��r��y���k(3B��*�]�&`�`��u�z=3��l�����\��������e���0�"k���V0���'M���H�{�5�����#��'�lY	fT/����0�r��+)r���w&��n���b�X#�c������O�5L�Y�m?O�h��S��a��~���M7v�����/nf������g�n�0Z(���,���wYYu�vW!�-;^�k�Y��n�F#���-��;o�;��>�A�P[DDDDDDD.���3�?�.�	�1����Cz_�K�PsU����������+6������;p����V����z�P������v6-��e/89�����������"*���G��E���T���K�Y���T�E����a[��"#4�X����<����f�*^�����F\yv��vy?�"���|ZD�>�|��m/������h��3_o`�����������P���6��M�<��d��a�{�+�yd��R=Y��z���,\'n���'*i�J37<3�����M���\�]9I�i\�
�����]g���{�{�q;Kg[�y;O=�����0��}N�I���������\��>���{���:���u��H/;�k�������n&#!�������pR�bjn���u4��a2��_I(�d�-���� ��-�s�KJ������t�H�n�d���[O
�j��=����+y?�,����Z��'�����E�u|P����;�{9������.�Brs_�l�a|sNj�Tdl���T���bf����zs0n<�t��7���S�6�=��MBe9YF#��\�����;&�v���h����qW��=P�w �/A\8�-T���8�����M�s��0e�9
.��"""""""rA����c%���D�v]�}30�SW��Z�>�=���#��Rmi��i"1�Ps�_Kc�lv;�^7��WO��#gr�_T�l}�](���~[rK������UW3����-�PPC��2�o2)��B���?69-�?{��b���3�����F�|p+��EO;���g�h�-<r��=Uul��J��4��K�f��x��d��������a��/]�/�>���}N����������������7��-���	�]I�K��_����[�;u��i�C�u�G������{�}������p��j=��3�o,�.�N���
����lr[��;@p�v���D �5�[�.^{��q_*<��)��S�N}[����|#���r��:V���V�������6+
�;.�za7�W��NuQ���,~���7�@��L�8�g�����������rMp��v_
���U��t�/-���r�_s3��g�������Lm��������v�>�������$��������066���^p3��eu�+S����Oi��$Y���)r���p6�9���Y��Z��������&09����Ogg�p]�VV4����OgQ��5�������c�����{�6��������_��|q����gL��V<��@���%�6��6������V�m�>�{�>��������sw���V\����V�I�p������
�*d���6s����'���U<�r�F�����lkc��sL�H$��\B�]A�zB�.C�(-���v��;�eI�_4Dc`d�������p���:���M�����_�?i��f_�["I�����gq�����Zr�
�O*����g���1`6���l�v"Q���""""""2lY�}��MD������1DFp�5\t�v�f�v�|�{�S���u�}�+����E����N���&:��Y���h�#r�R�-""""""�������?w���q���H�r����	+~Kh�X�W���24��@�;��u��`6Z�O*�(e���$���D�!�v�m����?��%�D�Bmv"�z�O��P��tN\GD"X>���a������W�=�K"�1��3�R�,��l�6����_����B&O���|����P[DDDDDD�����:����F�u���;��y��;�������'N�g���T��'��M�_��g�BzSS8�}�����x�J���yY�9d%�e�"Q��;o�>z��+��z�t\��h�$2"(���Joz���7��TW�i�"��h�3,~���u�-f�����S�7�@^r�����H3���$$&�p$E��e�C�p���>��FV{��������`}5��l;�}v*�y���������k:��r���,��W+""""""C���� ��bB���v��I\k+�o��x�����}�`�%��Y�2fT�	��.Ud������h�P;����d�7���2��=��K������Gf�	�o���o����n��?V����������WX�rK�rn�""""""2dL����U��z�Q�'���6a��G��JB�en�x��D�l�k�z"f3=a(-$���bBJ)cF]A�=#�U�9���-�7��������]���d�Cm#�[H����trS���S�Y	z�]�8��T�@��&l�g�I��H���{�	�]e�[�������:C ���71��I�j%���P��^����p�~�p^>��+�]q����n<�c;������]�

����HB"v��q��v�"Q��0�o[6
I���vI"��[S����h����_a�O�B�#��]�0�<+��~�'����+_�b3a��V�D��GZ�v.���Ec@4F6=��}��&y<����/|[b�9�?(c`�L�;��Z�?�Ov��������"c�^��EA�7D}{�Zk�i�����9����a���l6��ID�~�`����6l��Gm&p���M�F~~����B�h� 2,D/�vX����,y���$L%�y-���b%���y�,����~x#{*v��;DWO(jeK��%[9���v%z��1 #���h�6��*���#b����M+�C8�g:�c u4|n4|n�u�?��?9�H�������+9�����G.]�(L)��8~4��}�g����3���X+WV�g��kp�$�i��M�bG�j[�)+���`���k?b�'�E%�� �d��'Sf����Z��6;���EDDDDD�b���#�_@����$�=�����������I$ax�m�����=\�Oar	�)EX����g��$;�$��O"�H$�T/_������}j5�5����kX��<��5�xt+�;��|h�&Y��W��sotl����Ged��+���#������Ec@4F6=��m��n"�����p�@��_?E8-����+���y=�nj=�(w�?c���6���o���K8��.�_�g�����3�����P[F����tz��1 #���h�p��n,�>����|>B%c^9�P��z�;{�}BM�u6!��q��e��M���X��"=n&4�tP�L���K�\��S�	��>&T^}��:
�E�Do������~��ga���i�.�;�c��G�������/�=77o���.��#$Y�L��L�sL��v\[��_��t�PA!=7-$�H��u�w;w���7�i;�=!!�Cm��P[DDDDDD.	CO7��V��9��9�.g��
���}#�}{0���}j�������3(v�%��1`_�G���}�ov���	^U9(5�W���m[���o����f�s�u3�x��h�&"��Bm�h�����U>�)�#*�����B�|��~"qF0��_�o{+	�s���T��fg����g���GR2�����l���Bm�(������D�f�
>���a��BeW,G8/o���G�N�#��Iy��{��6@�m_��M9Eb��k�c��3�,���� P�-""""""$��!���`<|�p^>=�o�7I���$��E87����}+G�~����s��N�'�u�����P�-#�U&F�D
�EDDDDD�����F�Q��o$0qR���	��B��[M�����&�1��w���r����v�"1���������]��D�Bm� =7.�����h�S��v�{�)��yRo��@�����L�9^#�������?��9��^��"
QW���o����G�Bm�J��������\�^�3�%��"��}��������3�c�_Cxt���*���#b6���P[.{�
�d�N�?����`���70a�6�j�������\B{�}���C|.w��}�h�C�������`�b��$TPH�M�8���\�?/���(*���I�)�rU"m
�EDDDDDd@���`4*,�v)����fv���m���0%{�y���X���r7�Ova�_K��/������/|�����o#-���v���(S�-""""""���w
�����Q�=��������79�����d����r���/ �_p��'m�`���z�������{��
,k�}��-��Dd�S�-""""""��s������#Xy5=7��vI��n���0����"�*-"2���vj��a����N��G���Q����""��P[DDDDDDN�l��u��D�f�o�C3������H�8�]�HLx��hu%!1��qWQXTLAa��3�ED�P[DDDDDd���s�����fF�\T�]�o�u�]�
WB:��R��p%����]�������	���p����V��|rl��Ae�d�����~
�E�����!�OFfV�K��P[DDDDD$�Z{��;V���&u6��>�6!c���Y��d$f�����SsJ[q�X����k	VN"b��z�y�{�8����G����.��x��(W%2��{<�������|����/���@�ED��Bm�(jl�g��u8,��:��NMfb6	Y���+[fb67�����#�����;��,n;��	���3N���79y��5m{XS�����1)e\���$�4���On�Q���f��j�G���L�7�re"2(���6Z���m$/9�p�,��2W9�F�E�/��I�=�����������������3(K-��:bU��F�5���gR�zVc|�K��y�M���TW�L��1�W�����Dd�P�-"""""r	�tb�g���i�$��h��m�������W�)�of|���8��Zh�>�Q��<5X��j�v�qW�}�.C$&��pPZz%)�FE��j������\������g�(��c�L�"+1����h�v������_%!$q�w)N{J{k���������aq�������fO?m	���pW3��;8�������]���v�����5�gdR2��/�J���&"2j�������Ak���]��tfLJ)�I���������iX��!��D"X>�k��D���0����T�����O.��;�n�B����$n-�����������������}��C� &�9���==����Q[����Z�==L�8Y���[
�EDDDDDNr����9�����f���m.{��j'�����b�v`[���M��K�Y��������[��������Zpw�H�a�������h0�jK#��|A�>/W����z��)\�3����pX���"�d�������0�L��PXXLq�XI��""��Bm���rog����l��M����l2��H��vi���p��/a����3�`������V'�V��k��lC�z��#�����3��0��S�<����gCi(w�'��{I�-r9���f������_P�rDD��Bm���l�pg3M�FZ|��S8����~�N=����).����$;�Mu�3�fz����W���#]-������h��K�8�8.y����;/��Db�����=�Dz{��zr�}\�4f��;����\<��"""""rY�t���c{i�j>���`�;�=�y�������z_���j�'7)�������&����o�j=�eK%5��(�c{7[�v1=g���]�HL����oO5{�|Bs�A"���Q��""�J�������\�y�h�j&��I�c4�	�d&d���E�49.��<c{�-���f��Q��{��P�x�/&DF��V7o�^��CM'��QXX��E���P[DDDDDbFW�������������:`H���y,4��)���k���s��?g��&0.m�=n�t��0�e-�re"���������*�������L��_BIDd ���������fC�:��k����K* Bd�s.�eDb��}��j�����Ky���x��.�������yp[�}��7�� wj�(Q�%Y�%Y�,��;N�4qb'�����6��6�i��3����Og�{�>�tI��I���;����W�����V��HJ\� 	b?���h-�����H8�����������{�3��#rE��)���&�N�N�H�S�7���~�]%���>����8��H���-"""""���3���gV���������T�2'V`O�r���?�)>B�cX���Cd�ft4N<'1����X����s������?y�v��Cmm���,"2c������X�o��y7� �*]����3�_{���N���X�v"W����z�j�L&=��+W�v{J��������J�9���Emm-7�x3U^/UUc�������U��v��[|�[��Z c�������^ ��o?��O�`�������L+"""""�����E����1-�q=���c���I��
*x�\�Db�L:C��'��������kim+[�^������NN�s��swM�&���f��.�����Q,j�y��������������^��eo��������o���e�7�{���{���+"""""RaE�S6Cv�62[���T�HS&	�������	����f��t�6o~��I��RI��$v����/x�:O��3O�N�H�S�����������e������f�N'.��������t���-;o��������_���L��Em5>81����r>7n��z��4�%���r{=?|�,�{��:���(������j��J��S.���Ko�h���;K�Wt8I|�!�v�'��FG���m����?�=�N���B�V+����}��}�_�a�Z�YmX�Vl6�����+[x���������V+��|TUy	�7\�+���0rc������a���e�u�>�a�r��qn~#o�v�z�e��w?��@/��8�d�d"1>������e[�yv�ou5�P��WN;�VO{��&|�w����L���T�`Q���/�f��~�_���
���,���x[���x�o���=������.+n��r����3����C�\8��5 ��6���g��<s�����\3������0x���������z�:G��9s_4���4CC�D���bbW���;�����*{3��|#��|�8>f�Z&�&�m�����\��a�+��b�>W��'�����/�[0�����c�\�o~���n���m�����G���2����_���������\�p.*9/���[��7�lV�l�Zr���<�`lp�s���'��p�=�������_���~���c�.��O~��X:��W?���u��u����|:NwW6���m���]n���-({.�5X����1ef�5�.�i�CGd"�D�� IDAT+j��y��o���{��;�;_x�g��`��A.����|9����Ywn`4e�x�o�e�	�8ts�9L�_t
����M���=�S�E4����������������#?�h�Shl"�f#��&��-�H���:�b������}�
��~~���j��.@M�����	���k�~�Q����X�l�����]�|���.���<�0X�f#��'�7���9#G�0�%2��s�9y�co-9Ox�ZJ�u������.0;�N�t�/90�)�1L`�c��������Y��N������\r���������G�_?�z���f�nw���9���>�����_������f��E}�wU���dx�����e����LB��z�o�b��
�����A?M[6��+XDDDDD.W�H�������;X�6�k�������I��0�Hs4���7���j%������6�$���$����Pl�#cx(�m��by����-ZBuu
>�����3q��J{��������.�xw���\�\�B�D��P}=����Vu[��W�Z�Ym���	�y[�V7�������E����zI�DDD�U���}w�=|�/���yj�����6p�
O�o��p�^��w�&�"""""3���$�������m;���wQ���c1�����`���+��h-�t,h�d(c�������g�9{����_K}}���S��OX��7����lXm����p8/��,""2U��6vn��;K��Yx�����S�HDDDDD�$&�[����Q&���!�.��Ec�D��75S,��c��f3<���
��
9�}�K���]|��wbw�q�=SUDDD�<-j�������3����a��=X�z�����r�������~��"��S���f���������X��/_Qr_����C������hni������*���|�V�4y�"""27��-"""""��(��w1�fa��\0K�=�c�9�)��^�o ��+]�>u�8���IFG���yc�u��Em�?���_�x""""�NEm�4��B��$r�<������JG���A:E�[]z�|s$B�m�X����,fO&�	#����������W�������t<�I��������\���3<u�WD�a�\A>����+h���,�c�C,�=��r�;H�qW�)��f_���`F.���^$�L����J�3�">��?��d""""���������\����v=���1�7���5��1a�H��8������M�m����d�T�_{����&�L�W:��������������\�cG8;���*�������3L�Q���������
� �P=�`���se3M�w�e��� ����X�����DDDD�
�EDDDD���m�@cU3-�m����HK�Y��C���1'F������/^A���%���[�7�Lj�����;]�����������}y�#����L;*j������%����^����&��^\���PWG�}F��o��Xy+W��}��JG��T��	����V�������b��a�a��0�1�H��!��Ks�
�M�
�����������`y��JG��T���E�bO�������.z�����<\t�)���Pt����75CS�%e��R�$.��=."""2���-"""""��3z��N��h2L�]�R[+�3���bc�����V]�~���Z�����P��)�k)��S�2��p��w?GwW'��+8�JG��T��q��!��z��c8�Nv���5U��������
�5�~�����2EmC7:$����q���q�\l�zV����DDDDf,�EDDDD���0�������VZ�c1�n7#�8�?�m��+�k��z.�X�����(��|���*�*f���({w?����`�Z��i3�6o�nwT:��������������a=r�/-1`��z���\����+Hc������7NQ�����������X��k��NU����DDDDf�EDDDDf(S6�yp���s����m�V�.�!�h_1���_K�����S�T���*�f���z6]��5k	���""""2���-""""2��_z���0%��m/�\����+C����J��s��j�Z�-"""2�T��F�CC��{)�7R��J�S�Vc,Z2���xn�u�n���?}�7�_�c�?����\������2�����QDDDD��+""""R!�LK�Y��=X�}���:���������XI�c�E�{��g��$�����L2���Qs��a.��Gx���xs?�m�X�hI�S��������CI�^7n@�����;O����]��6eEDDD��2��X�9F!�Q��������#X:OP��b�_H���|c����'_����t���C�����i�.���D��(����������45�����i�7���DDDD���E�����[u�e��|bD���(�����:���c|�v�Tg�s��0�_?>��P��R���o�X�������;�������S(��:�i3l�L�����1�9�����:��m�7��8'�8s����x���jh��m�3��
���J��x��]�|�V�Z��y�{Q������n��?�_���o�q��������w�.[�.��w��96�)�<4�����w(T�LX�6G�k|�Y.���Q,g�`�9��������Nn�(S�6�/�����-4x��9�VB��+z��������&�l�����+GDDDdN{Q;#:��Mwp���`���v���v_����<N_-SVDDDd�3e3�������0%$?����#�n��U���NaJ$'<����r�9���|~
~?E_-��%*v_���1G#����[?�>���B]�����j���LE3�>��O���J�&���;�g���+�h��H��f����L&Sb������:�\c�"��^_��=���E���p����<4�9���y
���>�(S�6�b��f�n�����`��D0���x��e[�������?�Ae�e2i�g���_��X������q\�3<��(����w�0}�8'�����EDDD&���Wp������z��+���h_^b��yp���t��o���I����������W,��1<�����b�m.T�����Y(S��dA�@�
��U,�QK�K���y��W���n��v�,m�t$�@���^���j|�9����y
_�sl�v��_��g�7wP�7R�������Z��n�~E���Z)��'��������yh���p���X��]c���9�������V+��Rhj&��H���W�W���wx��iSQ���PQ�9t��/<K|d���������L{�b�X����{8�
�rQ�~�N�H���_*/X� 2��t���5 ������ ���y(�|%������)�����.�k/z��������XK8�9[�n�1��?��cN7�d?O��5=�g�����z#�u+*k�L���3�]<��������k��e�+:0�L��R�$}��t�e�_6��`M�w���%%{j��y(U7��g��q�]�GDDDD.�)���+~/U�������?�~�u��1
a=|S6;>��XEz�����<0��;�x��|C��
/�G�t����x�g7�����a3V�,�q~�������>�5>n��Ct�\]�H""""r�_���;��f����������Qum�	�GF��T~����Tv5�lf,m�xO�bS*y�&����x����{xlEwm���&l�8E�cY���@��c�r��-���7�L�k�l�|�H2L8����
e�'�YV��um;����db�
��q�GXZ�����Jm�;��~#C`������k�����b�������HY���{wc{s?0vH
�
���.7y��|S��;�r`2c������i�g��P�+[�H�����<��DM��$��"��#�c}K�q������~l�"�z*h�����\�/j[l��]lO�9�������x��n�w����. 0����{��O�C���� ��,G��4?9��::��/:h�=[DDDd��������d7m�P��l_�����>�������)�gF�����N�����QK��
������>���T��@�������QDDDDd����
����M��H>~��O������w���=�������3�-e�SYR���������o���e�7�{���{��wp�+�r�8�#����Dv�&�U��e2���0�R�5�7�z������RS����nJ�e��~��0�T�h2L6���U�+;�������a�h��d`���y��a���`��wW:�����L�E�,�O��o~���-��\��o|�W���[�q`4n=�?�q������ne-���Y\[w�@�d���������$�m��e��P����j��~�2��5 ���~3l\������a�����g�D�?��?�jq�����q^~�������P���_[��;������G���x6>��n�����j��:
��Nz��������A��9<��j���v�u�Vl6�Hs����������~
�L�JG�J�(��������X���P?�������c�g�7���rj��$��1z-���o��[������V��ylm����u�����{2K��i�2,3]��A��
-�t�E����k����qz{c�k������(�u����L���/�8�v>����F�D�a"�0�Q}�u�lg����
�t9q����h�����D�jG5W7l*97����5��:H�SO�3H��f||�_�3����f��������\��������b(Ytf���}@�������:���"�*�S��������,~�/{��������������]=��w��gh�g_Nyq��D�]��]�aEDDD.���#���%u��)�&�/�p��A��w$FGijn��[ng��%8�[]������=�`����������w�d����3�����u�k��0��lQ�c�b��_��Ig�;8�����K�~�N���J����������-~V����_�s��z��.N��Y����1�u���7�nO���4m�����DDDDJ��}���1G�m6,�}�V:���H������k����t���c1[����7~�
7Ru����<�)m��*R��X-���v�Z������#��v�eg��w�g��T����T,�;z��'���=�,�����d9������#�k�j���v-0�����7��j4�������k�z��X1;�O�n'�n=���PT�"&:���^zG�K��2��K���z�i����380����f/}#����-o��
n��@0D "
�oh��&�����b�����T�t:M:�b��������50����\��~DdL��bNo������}v�+u2�����c�eO?	V+�k���=IR��x���f�uF�r7�"���+�|���z����	��H,mgxd���g�:}j|l��Ml������2�N'�J��S���m��,{�����;���?�Z�8�.�.9C�EDDDdLe��""""�X�c%��8�M��?{t�>�+/�D����?�'���$��"D�a"�0�D�{�|��t[���j��,$�
Q���(}��w�dy������(C�CC1��e��m~�����k�������|����]^	����zH��d�����S)�kj�n��%���>���m�;��i#g@��
]{�
l��:�N'UU��~I""""2K��-"""3F,5������L_qE��L���\��G�������Xu��+[����?��������u�{qXP(}�fo����OO�-gp��46630�Lw�yc��>��&=[o�Y���I�Sd2iR�����Z���J�b?u�O�������8�.���o{��l|�S�9W�v^��|��QDDDD.���"""2�d�i�G��$�HG���$�E�?��S�,�J��gG�^G���L`�����k)������7����#�Xm6������%>�M��=
\A�g���a|,���}4�[Z�+|����F�F&,�����TW��t:I�3d�r�,�l�?���e�>������l��p9]8�Nr��-=/YJCc��}�����������X*j����������Tt�q�+����4xi����h�y�����}��u�q��u�Q���\�J���Jb��"�7^��P[G���W�u�5�O�����	�7`k����F�k,�-�������e���������d"�`xh�3�]d3N'v�����f'���m]r�mw�t:�x�.8������\��"""""SEEm�2�|�p��H��5�����^�A�X���D�����+DPz�n�������1��2��r��\�����-������5L���F�[��\�F:3L��fR_�\�[w���
\!�\�w��3D��W�x3J��������4w��"""""3���"""r�8t�M������&o+!w}�y�4]{I�[X����o��4�bec4�����[�]�@z�6��K���g����F�]O�+H�+@��@��aQk�l!C81��h2�@*B6��cK>U�����D�SU�\*j�������_�����yXT�����zO#Aw���m���zh��u�|���������W��nC�Ab�AzF������|z�����
"�0������6���#� |�����?�����by�\�EDDDD�JPQ[DDfs$��dvT:��6�` !��'���k�����s�mT;jh�j����jjH����c
�&n[t���\>K,3H,�d*��F�������u�>��Zj~|?>�����O%�`M��W\{lU�o������fo+O�����H��^���������5�0�\�����������������d�w����}K������4g��$�u��h2L8�w�X��G6�9���{��M�/ L�$E�����f�r7r7L��Q��^��Pz�����=x�����n����^�H'��^!��0�<o���\����y���n��~�<�,�N��t���-\�a�I�|������\�EDdZ����<2BnE�"h��!s��gN�x���K)�t���`3�99�Aw����s�C]!�[��`������[o��e���<i8-.v����m���2���&,h���H����~��s+��~|v�%�D1�(�:<������,v��Z���1D�$�)����^���h8��7�d�Uk����QDDDDDd2���b��!.�p"G"mT:�TP��Ad8S�R!:���y ���Ko��,�~(�l&�����\vn�4���;
�
$��
S��|���>�"�0��X����@��:`�F������a0��]�����=����{��y�����1b����v-��j����n��H2�@2J$�G8�O&�fc��m����L>M6��k�����t��
!������50����\�lV3������K�R[DD��yp�w�i�q�����
�[Z(�&,hPSCf�M8�����[{�N<{�%zx���I���lf;Aw������.�y ��w��z���W����Nv�67m;��Hfx���������g�~������!O}K�C��,(;�aq��8/9�t(h���������""2�,}��F�1���/�����v

���'�W\N��������S+)��R!������X,0�fQ�}�l^Z��t���\!�5S�t�XO�����r�5T;jhc���u�������;D��nR��N����+������jR�SDDDDD�JQQ[DD.���KW'��N,�]��Y�U^F��a�(}���}��9Y���D���%z���/�C,5&h��+_��{����S���(����Q������-��\��^y�%�x�j|�i�fDDDDDD��ED���#a�?�_�r��m��F�M-�|+�Bu5T_Zo������<���c���%����I-xNws��=Y��~^���w��X,�����M�Y�xi��������| �EK�o IDATD�,�����X���X��Bc��f�M�{��1
i#E��tK�y��e�������^�2=�~�N�<��%K�f���7�:��CEm�n�h����{so�p?�����q���6���V�fzG�r&�I�H'��gY�[���|�����:��8��&�����o���W:�������ESQ[Dd���=��'��)���ol&�v=���������y��st�t�osZ],�����|O������d��J�f�t�Y#U:�������%SQ[Dd0S��)9V��0�,k#r�c&3�S3��r�"����{�XP����4x�0�L��6m�_|��=N���t�������r��k+EDDDDDd���-"2Y�tc9������n��-$���%�-z�H��s�^��7���t���9��(��W���x������*.�{����3�8v??���/��Cy���D#a�k|�_�	�V�������,�����,a������X����^�o����/Tn����%��^!{��)=v�X�o�������=�3�u� �^����T�.������cc������q�5�08�����>F�����q���h_��U�"""""2+��-"2[����0/k#��L���s�K}n�U�����c-U�����g��<r����_&T;|,�]Ak�<Z���$�l�|���#���p��92����wz�������;>L���JG���N�CDd3�����
X��o���>��&_��'�~R���������H�{��3���v9�j�����15������X�%����
�h����Y����+*EDDDDDdJ��-"2]�#����:����M��T8��W������IkC����{��\1����K���8�m���K>�!�-�dn���Q**�J2�1�Q����Vz���e��8������He��-"2���Y�/<�����2�N'��7��z����f�����=���g��\E�����}�=t�t���L������-[����ol��U������8z���C�A�������e��""""""s���""�L�n�v� ��:rk��[uU�#�H�[w��R�"
��d��.U6/���h��G[�|j���\�x|�����*9>80��Gcw8��o�."�CS�VDDDDDd�RQ[DdJ���)�=��1������������yt��i�.Z����j�pB��r�,�p?�h��h�H��p��\6��[ng�UkK��X���+��*q��������8�ED*���I���b���
��'���9|�S�'8=t�h��u_+�����)L'����	]����l!��� ��6��<���������\�iQ�������:����W��Y�~�i~rputp�_t�h�tR�Kg�f�|��c�F�n������|%��Y���S��9�����i���(X���[����>"�0��p?���}�kK��_����[O0XO���������L����>|����$��;�=�)��+|O~�VZ�Y����p_�Wo�����`�U��`��(Vy�n�Fv��JG��L&{�>���b�9�5�i����UW�h�_X:Oa�U����h�^�����g���m�����fJ�3��+KDDDDDd��lQ;����b��~=5�>5^��{�,��;h K2ia��z~��Y���W4�����9����o�Gv����W8����pf�����%��f�]���n�h�f1�oh����L�Q\�x
�f`���Q��b��q����K�-���[����������]�-""""""S��E�8/��~r����M�g$�cks�����c����Y���e���T*�LV��`���1�Bf�������7Bm-��{q���;�����6�V�vv��sx�������m��s���o��;��x��C_���f)�/~�,��Ws���]���x<���=��� ��AFFF���uVk��>q��/8�L��}@&���50����\�L&S�#�L�+j�8�3�G���3��$�W����Z��\<C�=;�r����%��:��h� �6*[*/X� 2\�m�2����o��7��uF��F>G<��*��5�O���?l�8XhaM`+j�HZHp��W��58�9�GI��;.;�\:��/�8r�����C�.���{�d2iR�>�����d��{_ T�@��v���P��@�X"�/�����y�d��]s�����k�f��E}�wU���h-_x����������O\g=��N1p���I�����-p�,"r>S*���7�:@���R��*iZHE��"$�DRa"�0#�!B�F>��G%�8,Nv���ZW�:W����~��u��z�0�o�[����������\6K���7��r9�����Q�p8K�bd��wV������=��\�����YZ�������<E��3P]���:��^!����6������"�0���J����DI&45���O~��<���}���`�l&�Y*��RVm�������1�Z�����M"Edz��=������@���ix�b X�d�����<q������u,�-���i��k��Oj��-��������I��(���*�\6K:�&�N�v���*��,	s��7I�S��)2�4�t�t:EU��O}����������\��?��~�[ZK����U^{e_���+����J��������l�?������x��'i������t�ZF������7�-jG�a��y��J����&Vt������-"""""2����b��!.�p"��#s�\��\W��o=r��1��0/!��j��*��R�Q����ceb����b��dK��%���#�>�������k����O�5`;t��?#�z
�[w��/�����[�l���\�l����=I�����)���yc�m����)9��cG��c�`w8�Z�X���?m6�>?�����1����B�t������.���<}�p��q�+���Fu�����}�/k�v��bw���%�����x���&�	�Q�C5���������D�����t�e�_j?"2fz����,=g1�G�n�Jv�:�e�o������@d��c��F�+@CU#u���a��jV���RF���`��
�K�.Z��t�v���o����/����>�C_�*.W�T��6�kj��`�Z��lX,V�V�
�e�s��v���yI�s�5[/i����7�E���l�:��P�Bc7�,���4����m�<�����������u*j��\������xS�cL�l>C,=H,c(sn�uz��L������%��������������yJ�7�y��Q0I��#c-:2i6n�Rv���#����%���������
�r��z��s+�_����X���m����_�K������9��8�X�|k[��b����D�?��3���n������E������V���[o\)������)���p8q:�����hk��m�M8].�N'N�k������P(3�j�]��g��T��9��y
���a=~������_�t�6�������J��eb�c|�������-�1�L����:k��mS�������~��k�^]v�����b���������[O465������������L*j���d���x���0�0�W����:��3#�����}��k�;ki�[A6��n)}���S�}�:H4&�
���G��ZZ��%�-]�|�"�$3e���]""""""Ry*j���cx���c�f)T���n;��kJ�V��L>MO�}���<���Pr?����m7Q������������wO��\6��_KcS3+�kC����|��'W���St�H�}O���������,�����=V+�M�)�K�U:
��(o�7�Co�,#�����_��a������D�D�s��;��{��>Km]���8�l�����JG��/���L7�k�T:��������"*j�����|m�#��gGx��I\67
�&:��i�j�����\�}H%�RI�}�)���}��U���e�����s�sA���`����)����~&������y��Md�+�n�K�����.�"�����
�c5����aR"�0�n��
��K���i���_��93�o8NN�:A d��
C!� �`��27��,���p��1O���+�eb�l��~J�f#}�G*GDDDDDDf�EdV0%F�����c����ES��g����#�
3�<ol��}���,hg2i���D#c7p����L��O}���f�������
9Er+:�9�����+0.�t����/0�GH}�n
55��#""""""����"2������#�(����q�U���}D�H�N�([���h�4��i���	��t;�J��9���	�D����`����
�������|��p��q|���Y�H3�y`����V��X���qDDDDDDdRQ[Df�����!�e���YG~��I}���}�����&��Z��u�7��������|��zR3\�\6K*����JY����la��v�hlj���q���\EO�����!y��jCr�
uu$��,�@��QDDDDDDd�RQ[Df�B���/�E�g�����	^�}��D/�|���Oc�y6��"+����D�a��0�H�h$B|d�������[r^��������r+:��}����������t�%��T�""""""2���-"��y ���k�i��~��b�}'��
�6���h��G�"���;k1�L�z��p��[<����[m6��X����I^�>��o�
S�PA[DDDDDDd�QQ[D���v�M�]�X�;1%�].�-m��)�N�%=u�Xd �/�C�h��gYV���M[J��^�A{]�%���480��`��MsKk�}��j����hhl"Mq������X�"""""""�>*j���`6�|�I�v;��y���a������G�V�5���V��zw���{�^�H��S'�F#D��}��c+V�.[������[�*��������HE��-"S�<���K�cU��$x���7i�����gX^����&<M\������`��p�Yq~��Q��y��I(T��u�BA���i���I�m^�c�����������\��(��.��������H`�_P�G����ws����>"�~�7^CG`u�}�7^���k.�E\�\6K8�O4a %�#�'��r���ce�����c�Uk���Nqb�Kc9���G? �u���U:��������*j��������}Ol���v"�r�����8�������i��I��	��9��/�c?�1�]��m���	��O��|���N��%&��T�$g��p��g�N�W��t�CT��I�k����������'c�y;z�y���o����D�s���\����h�H8L$��n,��z���������!�z�V}��
�?�!�� ��p�7.�-O���0���CQ�.�)�*��\�� ��N,]�X��!��/��\r����/��;�OR����(9��y��� X� 2��������~C���h4B6s�1W�Z]���n����'�]�������&u����S1����x����1/�t�cT���lo����Kw�xO���A��
S*yI�D��N���q�FNcr����
�n*�������0�h4B ,;~��I�b�������'
�SW�_[{E2��f�/�8����a��W`,YV�HS��L�|�A�7��t��f^Q;�L�N!2'8^x
��m�����	�_��8�����"8�.��.g~�B�MR��&
�D�D�D�������e�yw��VW�u��'}�mx�;q��W$Z��\���1��$���oCDDDDDD*`��o���Q<�<Kv���:VU:���e�r�����������(�&�wu���j���y|�i�\����GF��?��y��V+��F���L����&�[J)���o�
��~��������+iJ����X�N�ue�A!""""""�Af\Q�����J�|���_�����z�'����y�D�-m���s.��m�s���nq�X�\r��U�L�����a��>��z)
l�~G�����,]���@@�Cd���c,m����d�#���=<�����'YsH&���#	9AR� '	E�F-R��[ZK��]�}��[������[k����K�GjE+��k��"�BM7����$r�0��2�?$�!�2��uq]�u��Y+��g���3.�%
*m@8�.�����g�e����}��;��k�|��"���p�\�b��IE��%}:'v0s��Y#���&�P]�!��PM�An�S����8Ze�n��%Inw�v�����z}������'��g���}���4����|M���7��������b���O��o[d����o��@�(�l�p�\r�c���U0k��)�|���;�~�+'_�vi\r�2�F*3n��7�*6nPF�p���VJJ��SR���*��zQ�	|�P�����)C�B6��p;���@CG  ��VF}���C2�ju�{?��g�;��z��1)�<A��le�e�a���c���������Q��ONI���P���u��{���9�:�>!d�+82;�e��b���j�O.Y�
ff)��s@��i�lTU�^EFDjB��^�I�v������9B�������jj��P��>�11Zt���s?g�<�)��-���M�"��pRXCm���Z��6�wK�]�fk��	����O����m
H�.*��%EJ;����c�
�?��X=0�,;�+��E��
d�(������:f ����*U��SU�>�}������>C��p�^/�~N���������+'7����E���,������a�=���m��^�e�8��mz��-�qm��n���*����k�i�����k��,�����d��K���d�|�����b���a��)����MM2��������}:n���������zy��'_g���e��+'1_���v�S
�$�#F9�y���SVV6sb��#�q�A���pWr�����@�|��h.)�P(�"$I*��b����(��������A��C����__I�O�(��+���s/9�j�"�yG������8I�)S�����\L#R�`W��8�����J����e�4|�����k��i~��@������I����+�qa��������:~���~u`��>����R�"�^:\����s�s����c���
)9Y]��j�p)������������P�"""d1"�]v�������Z�`����U�!�ve���������Ev�<>y$�;:�8����n��,����F�o+��&�����=�����/�F��d45J�
|iL[Y?\�QE�������6���!�����	WU�>U��Ug�S�
���bMM�F����tn�=�p�����j���v��t�i������]����R�,c'(�/*�v�:n�9���7����
�s���u	~�/�{��������������p��]�C��w*�r�WS~R��y�$)&�.����[f����7��H�C���wV��\�se9�_��\?���qY>�#��h�"G���bc��g���v��kt�u��Z������$�aWv\���K�Z�����+%I1�����Wf�Hef�T��!=0�r��/��{��=�P��K�.���6�'��V��]����p���j7�Q��&��'K�{�t��SRx�JM&���Q��
J�6II�}���s��:����VE���bQ�5\����r
W09E]�/�|�}i�<����J�4���������t�E��?��nk�3.��u	��*��:eddjXR�y�����������z�/:�����\��D��+��p�@��7�v�Z����JG��NLkmI��e������Uo��?�) )z�x-XR�4Cj=�?��G��QW�����C����Q��M��#�<�=��hjT0%U��^��>����>u�t��mVK�1u:4n�e}n���+'!O1���>������U���O��SGg�����y��hC)� IDAT��f0�=`��c�oU������/3��x���������P��~����F���?����6�.�V��rPD���"�Z�+�\�)Wn�Ywn���7NNr������w����f}X�I-������v���:�a��P{��/��9�>�����@�>U<pr���\��������
�3���W�Y+��w�B��?��]����Tu�^#�_+d���l�������b�B��p��sq�]���}s�bQ(*Z������OQWR���h�����v�[n_����{�v+=6C��L�u_�����CN[��E�42!WN�S1V�bm�?��D�*����X��\|�rr����-��zQ����M����Q$B�>G��32G�Gd���l[?������ryg]����@@��E6U���2�(���":;��:M��z���K��0��@����r���Q�n���-}t��3�;m�J����k�1��������hjj����������7Cw~��?�� m.B���JNQ�
7+��Y��(��#�%�Q�����]y�uWr�y����@N�yss��j�hT��M��v��������������~�4,:I��X���k���28S�kjRM�A�<�C���9~\����/����@fA��O]���,�6�eI��Ge���h8,���R|N����}Y��9�;uH�+�v�[�~��}nu:��
D��4�RS�QI���aQ.�����vO	��g�2��������_.W��#I�GEiDf����5"kd��6������
�|WLw)������0��0���~�u2�j�@���`z���C�`z���q����czu�Z����:�X�y���Q7�i��f���~i����5"3K�)��.�%����m��
ffjL�P{9��V(��o�W��w9�e�h�,���$Gd*82[�Y
�����#�o����G��kQ���_z�]���^�g������,��b���)����g���/&E��}���WKs�ZZ���|L��|���HK�?���Z:��8��llTp�����:�~E��N��(u�-k-�+B��!�G[���
�����+
��}T�P���q����C�_����^��M�,����y��������n�#�"Og@6����a��t��>�����l�-�����QgG��
�s��_��-s��+11Q�c���\�������:_�}�b>�M�����������)�4�'Q8�dlu^u��S����
Y��]��^��g�
���p8b[j��>��cM'�u���j�~j�������^�W0l����*H�P��P�}��p!�mm:x�J�-�j>vL--�jn>&���������{�/:����K������a�G��|��K�������q�ma��r`������rF��.���:�Yz��W����}Y��]�w����w���A��5�sbK��$�8u��+��!o�0j������i��O��B]*N���������a�I���h�w0�r������6��6��������Cz�/�I�,�bb�JIIUL�S��)�{�	'x���+�%o��7�#�����)��Gx;��:u
KR�����B��$�T��_�oj�":<�.g�E="����F+d��u�������O.�Z�Y+s������J��PNB��-�<���]�������v��m��|�����k��+{�/;'G��?�t:e��{`��M�&�'{d/����
9b��!{�|�OR`t��4F���YW\�g��J#:<2j����Q_������v�����V�F���?�S Ptvn��s9�����J�IWJlZX��nk�����v���n}�h����n[_W��U�q:5lX��Ff+6��X�S)�i}�#**ZQQ��)��s����!��k�>
�����z>�v��6����tr��]J�/<���FIR��dF�+5M��S���t���{*w����kj�t]�1���e��);~���������U����X7<9E��y0�	_-�V_-��b�`�Jr�;�J�>��"�����B�F>��;�+����JN�o�T���j
�G�������>?���r�BV������N.�G�}��u5�;�,9&M��N����x�^555���&���=���V0��s���~~�O11����TBb����8L		�r(d�)W�Yq�S8��j�Q�f�������v���}E�y�l��+������L2�=_��MF}������������~����.��G<OL�������������@9TS����Z����������^���U�m��v�ED�_4N��q���!���U���{�!����S���iEttH�BV��Y#��`f��������q<9��������z=���Sty�����XS��S��}r^�����nkSn�(]u��z�/>!A�G�V�����D
����a���^D���=��/B�K��h��Ece��M��s�`dS����~����r�l��;-���:�!}R��j�������i����{^o��n�bcc�|P�����M��|m�X4,������R�g9�q����u��{�u�P��Q��_�w�t�.��r0��� ���g�&��CF���iD�je�WDg�����
9{���~e��?i����-Jv�iR��S��f�bX�Z���7���#:�������v����A�|�F~iL�����R|B�����������Q��S������7;0#Bm���S�lm9��kX�y����&�� ���F>^����5*�@�q#{=����*���d������u�jooW��M'O�����|�������JHHTJJ��
S|B�22F��_jZ������(��C���}>������.K�~�&MQpd�U���P����rD+������z��Zw����U�=��sR��r�a�I}��!oH/��[��m�vv���h�xEG;z��k�]����>��/�����=�����y~�%��U��zS])����j�+ ��M����^��j��-�6���S�����Sv�]���:X�_��xy��E������u:����TL��s�����a��M�;�j�����z������s?@(��u��$u�0o����@�mn_�Z:�U�V��#�����v������8[�"#"�U���Tl�S6����[�V�p���|@?u%&�����o�/Yw���h�9�o��w���9������HU^����k*����5�����nj����
��y�|�^��^���p�����������X��:�z���M�*�������#G*t���_.V(:Z����B��P{��j�6�=��m����>�d�l�]k���$iL�x������}����RR��b�
D�s���!yc�9OCB�
��#������]��T��h��t�������������q���=x�������d%$&~����/���Dyg��ms�"[Z������dj_D��������$Y��2R��������?N>v���D�%�7i����+����P�N<����A�=����:�tX����w������6WNG�r���������A�`v���P�,>������-o{��e����R��}�������<�f�QpDf��`P
�P����U���*:\�g����������+?�@i�3��2R#Sr��2R���A��O�6�'�����M3��]���
��6Vh��Z�JR\��,Qq��o������zA����<m]^�hin��9������������Gd����i��9�f����~����jf�����zl�n<^x��G[T�p@�Gj����qy��zHog��Mne$e)�0]�Y�J�VvJ��
K��-��E�����S�[o*d����&)""�e0�.�P{O�j2stGJP�)zV�R����`�����__��cG�t�I���nW�\�g�]:i�J'��0����'Y>�#I���&u1`�$Cm��+��.K��Z����o����Z�����r:�3j��2��7"O��FkL��,�p��A���F\�{�������/Y��	��&���=I\p�{`����{�%j[�v9<^�O���(=��
�MC��K�����)��~��AI�_0��x���z�]�����}D�r����S�i��wC���������������p��]d��UA�r����'A�]���W����kH	������/)d�SI�����-g�n��A+�F$)1C�~�/����V�K3��7m�O��2��Ks�zA�
0
Bm�ijL�P`��� ���6�4"B�P(�E��+�%aa�0F0]�
�xk`��� �������mSc��@��Tq��Z�A��@��������/�� l��8��!�~�C^��uz�)��!�~�,�.���6Vh��Z�JR\��,Qqz���@���h���Z�T���}C&�X��������6$Ei��"���X,.�v�x[k�pw�����NRa��?�[����Ir��G�U6��bq�wm��Gw��kHA�r����d��P������q�J_�Is2%��!�n���m��tt��j��2�]&����eU�7 ����-�#E�_0�U<���w���z�-���*�vk��]����zt�(��&)�~`h�U��������A���[�+�)��!���N�������*����sY�:��S�c��{�^�E��q�z�V�;����w���0�����h�/E�9���o���*����n�C/����M����8���N���k���)���Z�A��4_��f�K���k[$�U�x�<���C/���?���G�j�������?��'���`Jnmxj��n���n��'���������~���u��h�[�f���Y��'h�)�I�"�=�(��W��V����	�%���Q	S�//����)���w�~�g@?`v5�����%Z��Mz���b��C�*�������Usu]�C��)R������zaW�=S���.�u	�����s�����r=��R5�0��?�M��2-{i�������|��A�8�9B�=u�������<-AE��V����_l���.��'K5o^����W�Z�����'�����)j�Z{zvd�V=X���J53{�����D������7���d�|
����)��������K8��{O�7�S�3o���b�so#6L����n��i6IA�hQGr�\���x[��'���j-��;��������������!�����UZ{���k����=��G{*����"��'���	S����S-��/�m����K+��=r�V�Kp*N��<��:���s-���M1>�:|���-9������B�z���/V&��'����D�|"�Q���`�v��~�Lj��^yvY*���9���]��OB�!��;(����_�^�r�N���e��>�#��Nk��f���j�m|��`
>��M�����wHn�:�����s�hu�M�O�S������z���o-����/�k_��������6M���i�����G�����ZtcB8���h����Z4}�xe�O_E?0D�d�����l�Mz���i��R+�n����m��p�������4������{rW��/��G�
��7�h��7�������
U4�9�F�?���E�'����1t��j=q�=r���.�
�:t�~ (��J���FMxx�
��l���RVf�>z�-�$Oe��4���p&S��V�]�W����''�0�U��&�1�v��^��2[w��/G�W>���(,�W�%.���S5��an��/yM���u��EJ3$9��z��ei���UZ���m����^�)E���zs#33��b-^�P��3G�~�m��G?����%��]��k��mwiGU�^��z��w�AM����mU���Y*���=G��T�U)��m�G=ofz���kZp}���^E'�x��~���&������9���9*HoV5������K:4+��e�CC����\M����V=��|�3~�V�{��g�$�a�
'zU�b��al.�S3���7��e�i�F)5���$�g2E���L��U�#O�
'��{g��g)�P{�����@E��RRT8Z��V���e��#������fk~�'z�)��1-O��-�P��R-�+Kq'~�m�*,j�G�����r5}��-��bG�
��������cV�:�������?Qk�S�A�Z�u�~�pi��J��{�����S0�������'�R�RS25���*I�*������{�&I�i�{
��w�!�
&:���F9��+7�Q|`�p��w7���D������G�����De��~`����Vq%Y�}��~`h�5z��v������<-^�������1*{�Jo_�6����BP�UA�[r�ZU��S}:����$�8�%���3G�����?^�
����y?�g��/���Z�d��R�!���������J5s�$-�����������/��?��2���s�v�]��xC���0��?m���=J{�/z����S���{�4s�$U/{M=+Iq*^:[��������uZ��6�>5�{�7��H�u����[��>C
J��M�
�%��@�5Wj��W�rE���+E��n.��!!��b���Q���HVI�1EZ�8E���O34�����mI��4[�F��&g�p������Z6O��*��l�$I�C�G�k�r�|�w<������DW?�YO��MV{P~���KrdU?�[����~��*
�UIr�`(������h����R5g�x��~�B���
�B�.��0��#�P`"��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�S�<�Fw/�+�9_�6,�����R���Rw�Z������(��Vw�����g�/K����o��u8T��L33�p�3�����t�e
w)�
�B�.�_�����R��L5��������T�l�&�K���\�����Ue��w�z��m+���,���r��Kv�8U��P�w�T���nH�-�.������������:m��Y�^�
�3[os����X�Qk�7�oH�vi��f�l���������w���u�]�~�Y_P��n��w8��L���Z��6�>"�$�]V�[��\����Z��������c���	�m�*�����������Bk��i�-A�����Y'���6�?�n����6L+��{�f��������}e7���$Imo���yJ���RMNrk��k�}�$e���f�[�|��*�b�)q��_�KcWL����U^��?����j����)���Z��j�
�������o��#��iV��6�o�~=&_��LRaw�����z�G����2C�|���`��N�����^IA)=Ks�+QI^�	�?�Z�j,�u�:U���������;��]�G;�z[k�h�n��T�w���9	���
��n����^���OR��Q�}k��3���4������M��e������w^=����u�UT�4�������J����CK�l����y[�'���<���r�x���OC��R���zl�F�^�V%���TV���g�T`�T-^�%�������oQ��n��nK����
?~E�Z�����5�P������Z�����T��@����k�;.-Z�
�MPw�-�#�&���6x��P?o�~��%��Q��_�/W$��{Rdu�k��&h����qe*K��g��YS~v�&'u�j��[�<3W�������e�U�v�
m����Lj���nQ�w����8=����� IDAT=�ur���7j���5'��<
*t�v���<Irk������[��F�$�v�xW~�V�5��~���j��R��5zl��U<���������/�T������[���T���0��^�<�����
�wm���nQ�ue*M���6��w����*tH���Z�T�j�*V��\��9���84����_�8�������'���d(���5��T�C�	���{rk�(����u�8����InU�7�u������6^%��������!G�]#Kew�c,�_�W;:24��������3�������wnU������kl��c��"M�������}�*�������6�f�������9����Zx�S>X�K+����w��������X7#SY������j���|E���gG.��:v9lm���O���O~G�J��hw������=����'h��E�ZpM�F��]���Z4�������2o,P^]�>:%������������j����g��.[S�>|�Z�MAY3���Qm����\,69��]xi����';�=a�$��m\N�������(w���W�-A5��5���S��r�=��h�����sA-I����D����5�!��-OP��N����"�$8NYh�#Q�h�J�4�=�6����j�
����KR0K���!nV�&��Z�P�~=���D�N���,��s���������#�9�ur�h���w���*�t���	���������w�������z�R���{'il�xi�Pk���S���P��+O�)��O�7>���l��t����U�|�\��/������f`!�_0A�Oy����f�GROp�B�$�$�P|����������k�l@�OV�CV�������Q����~��	���SCx�Z�?"����P�3G�ze���9�8���U�}G��dUi���Z�$K�F����-yd�������9k8�u��y�*{0_e�<�j���jeJ����g����U���$K�*}]+�H��G���2���x�G�-�,k��#�PZ��v>��fk��bIA5n��K����O���"�_�C�X�����u���
�i!w�wU�����p�����OTA�C�S�����j�v�<<�_�Wk�V����4�zY���k���-�u�Z����r��W�@��r��4Q���M;zW��m����	_���gS��q�j��m����������������u�V�h�
��l�l������$��w�h������T�����~��l���J���[������e�N�{����r�����	���?k�}J	Y�0%��^���`����=�������������Z�D��$I�\.���_�E�Hm��a�����X�N��TR�K�f�d�.�~M�����.�����=n5�m*�g�J������ja�F�r��zV�lN�2U����?Y���IZ��_��/J��7e���>`SN��V���Z��y�6$E�4yY�J���t���T�~�\���d�H�9�nqJw��j����\r�J�%)K�������s5'O��Nq��%��u�	*}p�r����:��kz��Z�`�����!���ZpcO��HQ�u{���5��3�?:'G�����`��>��{J�O�@���������oR��J�^��G7���H
������M���.�YE���Y�]��gP�C����9���
�B�.��[��]��J�����at4�!��G�A�
0
��#��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL�P`��� ���6�4��A�
0
Bm�ijL����`�V�*W������P��"���X�	���?�F��G����
��~x�1�%��x]������4C��x��g��u)eZ4������u��|-����\r��S�����1�ZT�p�~��S���CR�]�j�]n���F��P�u�T��c(sP����i�?�s615�gs59�@���%!E�wd��%���������_�������R��b-|�Hi6I�F���\��B�7W����W����$:%�m�c4n�]��jTS�G�i%�gI��$i�=�x��|Ay�Gi��#��vlU���Z��NN�Rg(m�5.���:[�ZT~�+Z��'��i��l��B�&'H�O.]���w��w�7>�l��;6�u�C��5�u�x�U���;m��?��4[��*�}d�*%r]5I��Q���0��S ����6K�F��zW�����O����������u���Vy������ez��2�x�i�zw�J�$O��{�h�����3����q��c&��7���O��K1�{��O���F��l���t��g���=AY�'����U6�������o}[����%�������o���S�<�U��O�����h��*��W�oMl�G����*�]����������T��w��UO
p�"�S����Z�Y���G���f�|�x�I��+������M�5����Tn�]m
����\��U�\�J���p�����{�T����q��p]W�q��
mW��Y�OHTj�!��PG�Wj��G�Ur{���H������jk���#����E+�A�5��������w�g���[�V������"u�e�>uCV�q�K)p�z���S��<��Y�}l��'�S�'V�'I��8��3d��|i�l'�Jj�������}^o��<�5�C����0'Bm�A�T���E��`������7k��>�"���p�o����x��m�v��q"z����$%8owi�se���b�����S���0����>��o�>�&�}�>0x��.�6���=AIA5��G����;���������v�{�;$���D�����d�������zw�w�l�����g6���f�l��7��7�Z����HQT�(�����^�?@S�@	���>3�<��x�Y~z�<��\al�uoK?q�X��t��W��U������F�!��l?�zix.."""""F�Lm�9�M�v/���_����`�|5���K�����'����e����[����������[y��+�]2���}�}��L����,�������K������u������(�n�K���n�����q��O��_�-���}wo�e?��_����I�G�G?��M���X�%��d�����_����9��j��������d"""""2����t��""""��$�<�������<���0"""""��h��B!�����?��8���f���DDDDDd!�Lm�b�O��wy���#�U���C7h��~*�EDDDDDDDDDd���#""""""""""2oX�0U��qF#	�c�����Q�c�A��E���X���E���X���e��6����"��Lm�7Tj�������������R[DDDDDDDDDD�
��""""""""""2o���yC�������������*�EDDDDDDDDDd�P�-""""""""""��Jm�7Tj�������������R[DDDDDDDDDD�
��"""""""""s�����O��!2'X� """""""""������PY	��G�p*�EDDDDDDDD�����p��h�H���.*��OvW���a��V2�)2�������!��������),Z�c]9���p�����B�S�O�����������4�'c���	�z����d4>��k�?�9�U��������c��������V�pj��A�����������4�����d86��c�N�T�y�Jn�o����ZU���Jm�/O����2�b2���l�q��|O!uy�d;��8�x��d:�f9����R[DDDDDDDD�wt��s��"}D�	�C��{�&,�m;w��s��1��8^y�dI)��kinn"�R����OY�Tj����������3���{�����-CM���T��������%��C�3oZ2�=�~�8��>�n7o��������R[d*�EDDDDDDDd��	u�1��@���h�~��A6nfg��q������k�d�r������WH[��\{�}|�@O7��Vp��7��}E��""""""""�`}8����^���.`�o>�����Y�c�Fp>���
$�K8�����z�t:�
7�F�����Id�Q�-""""""""�B"��{���H��P�@���p�k+o�:�v�s��VP�Y���'�����_d?|��b[�����k��L~a��~�99F��Tj�������������G�7�$.|���Q�.�euOx^QF	E��F�K���De5��
VD#D"a�n���X"��Jm1�h|�-c����T�cK{����\�YL7��V��8N�"�A��������������-��hn�u���h?�|�|w���7m��� 0���"2����Y�z�+4��b(:p�3��CuN-&���d����|aFv{[+%�e'Y8Tj�������������e�4��BO1E�2YF��6��A\�ysw��}����
}��x</�""�N����������\�D*N�H]�t��5����"��9�����7�	g���	�/>�)��Du
O>�k�������pOd�P�-""""""""S�r�st���\�,��I���D*a`��g��q����?"�t��?�#�gq{<�������2:����R[DDDDDDDD��?������h+E%g���y��5�L�C����b��c8��?���vwR�b%�^w�fh����""""""""B<�ctl���������Y����w�C��pnJ�=�J�����8�w�x35K�Md�R�-"""""""������#��Gz/|��:)�(#��LXj�y��{��������"3M����������"vn�,�t��R�2+(�� �]`t�y%�%FDf�Jm�&�J\XF�;��-5wN8����$����t""WF����������<�H%8�{����G;���p�esJ�������
�/g��q=���n�x����������mt4�E��R;~�~���hpP���=1N�l?��"���y���)�N"""""""�S"���7�e����7:��c6�y��%�D�����[(�(�(��L{����5KW'�'�4<D�S��H���F__P���A,�C�/���w?��
����z��7^��c����y|�7Rf���_<��+�_>�i\\1�)4��W��itg$����W_Cb�r�����p�`8@o����7V�6�8������O�+o�.l�?���E��$�����_X��w|U����,���������/�I�t��@�������������
��o�	=PG����a1.��j1��vC��/zD�����/zD������;<��n7��|�������p��o$]Yet�i3���W�	��5�u�1��;����.��x����	��>c�m���4��4{w���k����O�d2vo��dN��om������?��:�Nb+w����'���w�s`��p��H���b ���`��b=�; z7=�; z���>=�1mm-�����p�Rd�R���a?|��DzGHx��;1 ��3��X*����R�.di�:��||.?~wV�u�����s���G�6�!����ii&n��o����JC������'s���v���y����v�����x������?
g��z��;776������������Q�zc?�������)*.�0/�hj���m�J|�Z�N�����g�6PU]���4*�E�#}t�t�9�N�H�P7>O__��q���~��������b���X��x�*n��&33��mt,9��R;��>~�t��v�?�\v��?i���M��C|���o��4,��������\�x,Fgg�D����q�����?�>9^�E���,������<�����R]SKeu
����]|���s<u�Q���������f��z��dI)��RC���q�v����D�;�_~��|/W��:v���C����x��Z�����M"EDDDDDD����.:;;�������`��o�Jm���33I��~���^o[�����s��9M��x��Gv6+W�a��]��-1��7�f�S�U9��L[59K���������gM��ED;S:�Nb*G�ZS{��z�������������Kss������v
���9�����0���+��;L������zSy��? ������7���-����)��>��z�
�m�p�:��;�~m����7�?�"a�N=Baa�E�v���5�E������������_C��deg�{�����o����b|>��cL�0�'���JbI-���2-���6`-��d��T45�>s��7���M`��������*�6�E��y�e��������������]���Uf�)�����F�y�����'YV��[n���ODf�Jm�$}��tuu���Ngg��n

�����w��ng��5^������G0��������5o*/��=�cin���>o����;��y��0]������Y�����BIY9��K��^�77�:_=5��Z:d����z�IF:;��p��g�����<���<��"""""""2���s<����c�mz������k�����kZ�����#����G��f��~A���wo�B��gq}t�C��r�m\�|���r����
�i9����������M�Y�~��e���8�&��o����N����o����J�������Iedd�v{�X����R**��O,� IDATx2���)��R"��A*'��3Eq������7<����O��{�����. ��'������.c��7��t�������g��FGp=���V>��/e������p��F��)�F�2�hc��M�_�����M�_��������Jkk3m�-8Nn��.�#M��������n������n���T�[j�bY��Y����@{[+�5�����}���9���������]tW/���������3KE���Lm�Ebxh�O>9F[K3�m$c����y����<z��t�v`���s����'���(�����x�UL��m;He}��m�-�w����6����j�j�PU]���sL��������������B[D>�R[DDDDDDd����� ;�K��5���SV^~�K�\q���H�P�`��k+o�iu�;vK�vL&���V+�cG�;J|��[�����p���{X��*����p���N�������a����'W$�pAD��Jm��������+��2����r��G�����\��^'�yi������{��h����gPf�2��NXj�x��X���;��Y�����>���[������'�1�x2X�j
+W��6�ljl���d�r���D�8���G"2�����~[b��4��|���U5K&,��/�G�#���v�8�����'�����kl�ms�<o%>w>>��|Ov����3���t+��W��������9������/�����r�1�?�@e����b�����x�;�]����H8���|��X"2����������<s��	�}�	r�|�Z����*���guv4�t�I�����G��&#6Xu�s�V"7�L|��/���58k9/G��O���c={S8<��>�x�S'?�������QV^AYy%e��z�������7��{���{���L�l���X"2CTj��������`��!jt��3<<Df�����Wp��wR^Y9�%��
�B�kz�-�����Qz:��t�~���oX�������k�r�W��sgN���@sS#�m����n��6�W���{.d��������l>���<���|��;)-+7:�����""""""2��FGp=�fS��������6ZZ����LG{E�%�s����u�������#�az#���P�p�l{6��~u��^W.�X�x��X�V\O>���Bb�
Dn���������!�.������f��M����D"Ak�9�6PV�����	�|�BG>���v����dE=_��v�RdAS�-""""""s����c��id��=_1:�������7����J"� +;��+�����g�O�R�����M�wZ]���x�&=��������;HTU_�~���%�h��~J�����kHN�c5��JU����L:������r�v�D�����2�?_��0����z'�O��]��v��c��,P�-""""""s����O?	����se-.�5H�V��,[^~M��	���X2J �C �Co$@if�r��;6����2����M]~<��)�3�_@*��J��i����;qx���7�%�D��=cK���:;�	�B��!����c�9�	K�c}�+/=����f�a�X���j�������4�=��Z/��YmX��V���	�z'��le�|w��9�IDf�Jm�����xc?��,B�~�Tn���-�M���I���pr����4�J���u�
�r������`��y��>
~Lo8�pl��'*�=��X]<m9���
$�Wb��w���p�D�
�W���wv��������
�����?B�|~���D4!	�D����q:'.��8����'<����K^�o�cgN�����j�j�a�X���X�V��<r��I��K�X������Y\Tj��������c���[$�J�s/i�k�	\�yL&b�6��i�����Z[�imm����D<@��?a�=Um�-���[�����A�"�x�yT{k�qx�:s�vz�s�_>��K�Dw]K|�&�o������22���;�����$##s�1�%���N��V����}/��X�F��c�	�rM���������j�6��f���zz�y��'��D��tm���j��rq�
{��}���cJ��i�CL��h��H��b ������25z��w@�,nz��w`q������"n�w�<4V���%�p�������ga������f����QU������a9���N^jz�`��[����	f\�k�Yl��K���g�����sO7���n��Q
�	G.��m9��/�����8s?�o`	ml���,�x�D"���������dd����_��w`���f��s�o��I3�EDDDDDdN��B�������x�-��|���a�b�v��i�R�)(,b���T�,����4�O��h}�#�����l*���7�$��8�z�tf��AR���e������q�=�����/f3��s$��8v_��{�N���������x"���"2����%��C����m����L��e]'�N����������Q�}��q�Z�Vn���+����������!j�u�������L�S<����`=s�dy�;���K����gN��]ft�c�tv`���������dy��w|*;�������|9."*�EDDDDDd�Jy�D�X4G"a>��--�hok%[����AiY�L��Pt��O��l����=@EV����w���p=�(�� �M�����u�2����z��?����$�,5:����>����1�_O>m��*($v������E������������XZ���t��QH�R���+x22��^BYy����x���#��mx�
`�Eq��� �&|�]$��[�{�H�W���{�q=�(����r�z���&e���� ���pi�tv���I�,*&�����"�X��C8��������bQ����d�����bY�rH$p��$�-'�vi���������^b���B mw���dI))���8B��&�{/����x��?����I����9��l�6���-%��y�X|��	K�dA!��n���"�����Y�|�il�|L����W�6c�v2����M��4560����baI�R��(��,��������m �i��(�����uFGX���"��Ht�6�b;z��c`m8����I�\�|~b�"�����k����	*�EDDDDDd��b1\O>������Dn�sF��x���iki&�HPRZ��Uk����b��v{��U������;��}������l'��3#�R�G���l�i�^�uL�f�^2��3��\�kv������.��c8vu�j��U����^K|�j��lL*"�eTj��������0�b���?`�����5�g�^����>�-�������j��O������n��v�(i������H�3}'y�u?��~��*�&#8-3Wf��0��������h��^v;���q�,n��g�N*�EDDDDDdV��v�%��6l"�z�e_������s�twq����;�l6��w�?������5,]��22.;�Dz#A^mz���<�n��
uy+��>��q�
���WE�aio�|a)��i����6�y��^L����cK������������""3F������������7M��`0@{[+m�-������t�c�n\.��fLM��>�9���^`]�U\]���>���*S4���'�65��Ybt����������#$��1z0�tc��	�~�����{=�Y�*"2Tj�����������������v��-�~�U��W��_`H&���_��Tv�%�S�UE�����o%����t���z�����]M���FG�	�o�
{A!�wb��"�����"Y\J2on�O""�I��������jp`��	6e����|����|����v4n������
%W�!���KZ�!�����������z�������]��X���H2������������&�""��Jm�v��V��e����������fZ[������G���2����3uJ�U�x��7�}���?"�v=�mW���4:�%�6�����r���z/��<�#�%J;��N�c��N��������LS,���G���0��\�Q���y��ghmm&
�t�(--����T29a�=�$K���u,-�8����lG�pbK�5(��4:��U5��n'�y+i���8"""S�R[DDDDDD��yh�#����K��]-�`����
RRRFYy�������r��
B<�����<���!�#4�Km���]FG�l*�EDDDDD���v)����(|�9���������^������wH8s�8�:������v�R�����KDDd�S�-""""""S���#��4��r�p(����5�Ns����n�U�FG�q
��x�y��A��<�������	��"a�N�,&Y�Tj�������������S)

�(�_����#��;H?�
�.���f����N��Q��
��1����������%�n�-�f���	�|�7���I��x��'""2�Tj�������}��tv�S�r��c|�a����6m����>���k+n�n��a����&�<��c��b�7�m�8C������b"Q�L����,8*�EDDDDD�������L[[�##TVU��d�{��m��"+�r]y�<6Y\��7��p��������G���H��-��,����8_|���F�k���\�K������R[DDDDDd��������p:)-+�������	��$����8��z�%KI,Y�����r���I��]v�O�p�������|~�w�G*+���+""2��Y�������MiY9��F��3��9��.o������A�{zl��H�.�z���������=Bb�r���V�q_DD.�*'"""""��������LkK3m�|�;��b��;v���]�u-�8^�G���Hg.������r�z�2�������t����H�x�]�e��)""2W�����cCB�$SIjs�&���#_X��pPZVN8"#�63�����p��,��0���ZsU8����88��b���k�Xd\Al���z�8���/i��Tv�
mY4Tj�������#�a�O��%��'�M��,�g���v<�gO�W2�,�^����RZ^�����d��\���`�0��*"w�� 7��
�����h"����l/����64���G��~�}b[�[�^K������_EDDDDD���p/��_�j�Q�QBaF1E����	����Sqm
f��^����Ga���p��bV�V]VS,��7�c=�D|�Z"7�rY��2�Y������z|.��q���E2����8�����!��v�XVG�el�.""b4S:�Nv�X���x�����[�w���}�q����c���c�����?��;���h��H���b<���`��b=�; z7=���@(>J�H]#��n6mw\4���4���j(4��Co��GGx��o��M\�D����s����6�F��vxyx��/+���_b=�D��]��l��k����\)��3��>������A���Iy�F�2�b|�r�����f���c������n�����\���un:?l$Dx�j������ODDDDD�2D�9�w���v�G:�_8V��r��'����ge���@Yy�Tj���8��8�,�[~Q�����"O1��/���K���x���ev$jjI��bi>���'�o	��0���p�On����.>6c4��c?h ����z5w�qe�V"""""2�u�vr��52l�z����(��S��b������N&�,�[��mWO:C{29��g�����?�����3J)�,��SL���,>)�e�w.���q���������JVT���4:������]~����>�?��?���#�-�;�d��UY����?�c�=���H���R�GY-f��g�����/zD�����/F��d���.zB=F�g�:��c��(�d��3��|��q�~�i��]��m�����������s����.Z�Z���f��g������rM��'����:���eu��
H�=c�L���������r����wss���r�+�����[����x8�5����~�b��/zD�����/��4�����Q�������m(�L��n�����S��_Z���=�n1����L%�J\+���D*A�h'���I�}��CJ���s����SyN������������k���_����A��b�����9Yj=�������x	Y�8�V7�K�q�_z����������4�@�����z�<�z�)�(�b���}������l���o�~
V�����IO�������3(���,����rr]y3�REy��YZ���wpG�=fKDDD���E�����pW�p�0���/�tP��yh�:v��&���#���z�Q�aQEDDDDda�	u�5�A�p;=�.V����`��cW�W�2
�s����4��>��w�CFF��]�r��\����vR9^���.��,G6�?L�P3m#-�8���OpZ]|g�c5;�c�����T������f��g�F�>���]\7�A7���]���D"""""�~����t��]��j�Q�)�c�xV��:};��9}�C�"��f���6��6�z�����^���������)d����u���X���v��3���_���TdWN�3��cN.?""""""2]��$�I�l���"y��Y�l�i|���.222�f���Y���>+������������$�N�6���m�=�D*�?|��X�V
=E�EQf	��/�Uh���,\*�EDDDDd��%ct���
���
�Sq5������d'�Jv�rR8��G����d�x���[Y�j��g�]��gp��q�V+��$Y:����+����hj�e��C����n���{8-�)]1��b7k�4��F���������^�����"��9�N
=��-s���[^����vfBOs_)O��=@*w���<����������
��2�D �3�B�q����B����k����"""2G���y!��S�) 7��w���8�F����j�S�6@l�f��V�vNmF�L����\~����Q������es���a�D8�}�l������TDDD���"""""2/l/����,�Q��0<<���f��;p8�F��ds����x2Fqf)�m|:z������l)���h"""b��"""""2/��%F������O����Z���T��b���H8"'�B427�1�Jm�B�Q��8����FGWkK3��{�s�g���a�U[)+�08��bQ���W���n���1[_DDD��R[DDDDD�H�y��m��|�����f���b�?���_x�+W���-�|~�S�������_��6K�GDDDd���C��i�?���7�FY�[��������}��eu�tw�i�V23���3!������
i���'��8""""3B����������P�7<E_$Hyv_]�>����`�;����cL����8�|�TV6��$��ct$��R[DDDDDf����j�q������1:gN��vi��1�.�������#YXD���H��F��1*�EDDDDd�e��x���F� �Jq����w�}�A���VV�Zct�)q�����H,�%|�]`��DDDda��vDDDDD��p8���0���������"�X�����w1:2���d���T�,1:���6m&m2����(""""�B���FF�����}�������������q:]������d�����6:�E�x��'��bx22���:V�Y��f3:�eI�*�EDDdQQ�-""""b���!�z��Ca�V��;&##����������q�������	���	�i�z�x�����i�~W���l�O_8���us������zs��q3��WGDDDD�H�������,	�Fi8s��`���N���H��=a�
p�-�_�=�>�&}��_��nrr��xsY�~#�E��u�����{���|��9�	��eff��76:�����H��CDDD?L�� IDAT�p*�EDDDDf��� ���<E�,�]���O�������{~��������~���g�����&�OR�wv����w���v{&������i�{�W��J���-��!\.��.�its0���s0�9��%�D��7&YPhtDC���L��C�zzz��
���O8�����o�������6����B��X����8G���k��Fn������.����D*���l*���l�3���x��C=�>w�s�Uso���������Q�.)������|>RYY�1�Jm�):��q^}�Eb��G[����'?�`�sg���{����u������~������$;'�:..�o]r0�����3�x�xsr�������`��o���O�/,�nw���/���wl�uoso/���2����I{�$}~����RDDDd~P�-""""�9�@�� ^�����q�degS�����!~��.�1������QU������h���_��3on9^/�l�z��f������^���5�K��i%�e�z��2�Fq��*�`sw�E�R�9�b1�l����""""�R�-""""�VwW'�������pl��M��%�e����-p��$[�wL:�vi���?����������280@4���>z�}�sr���!/�wi��iZ��Q�j
Wm�6+3��CC��=�H�XZ7� �kc)>�������I��I�l3�QDDDd!S�-""""��'�?��������vi�E��P8A���������>�es�6.��0feg���MEE�%�'�����.�,33on.�9^���9�l���B���?��M!M�CX�����`�������',��6#?�g3�IDDDd�S�-""""JWg]�t���������v��+�WRQYIqI�����U"����y��0��M �b5��,c���w�'00��@����s��	v��;��3��,���^��u*�K�����O��x��+""""S�-""""�������3������s��A,���B���:�w�W�_$e�o5;�v��e��}=�<��KJg���!��n������@��j�{�/���Dn����O��V�JDDD�h��l D(����$x�$�J��z	����*p""""2[FGG�x&.U���4��W������'��'##sS.f����������3:���y���]X: ��A��O*o��1�� �j�lD�K4n�=�������Y�����U|�~�WA��B?=��?�?�Y=SDDDDfF:�������������o|��k4�r����pa��YJM�R�c\2sO7�@�da!�	6�Leg�X^O��O��'UP@�����""""2�)�x�g-d��F�X$�y��A�������nBo���?����7��sDDDDd:�<�)gN�����X4
�m�y�v<3����}��6��6�-����u�X����&(�5�$&X[]DDDD��/���~��\�n�s-.���c3��[������Pd���""""��?�!]]�TVVSU�����n�����P7�4��u�7�w��"�� ���	��6>���G�=��|Wm�}��'�_0�iEDDD������t��w\�����$��6[DDDD�&�r������	��n�����YN�x��8��:'��1�fX�m=}s?��~��}���1
���$
�=/�g#;�j��E�����GM�A^�_
�6Fy����<t���E���p�zm��`���
�k:K{[+�T�n�������B{f��Q�i?�����L')�,go��3�	�)�44H���p���0�B��NR�<�e��^R�\RY��^/������b����l���|�/��?�=��n��n��|�Y~��Y�W{�:8��A>:�##�dfe�z�z*��)��G�}�^~u��MD�u���l�9����)����y���f]��a�v;#��'<7t�����H���EDDDD�q��-]��������<�+k�3LDDDD��H8L����M���^Bn����/�u��s�����>o5&����5��`J$Ieg�|x�sO]�:��M�����O�7��&�������v<���8�
Xv�����GDDDD���s�k:���e���;f�����J&b2��w�C��1��ci9w~����kS�x���:�w~u���Y�D����?��?��]�_DDDDd�}��N6�w���al����<���\�^[DDDd����,��r�\#�������Y��2�X������>�������!Y^1�yi�������PDDDD�3�����no�G��6V���Z�Z����C,l*�EDDD�7^{��;����f�R���PY]���68��g�@�H��x�����|������������*�7�J*�K*'��6��9����������]�aN�t��������[Vs������Y4�KJ�Z�TU/���9������y�h"��]������m�p<�p����(-#��3�u�����""""2?���6�Lj6��;&�\#��u���*|��#"""2���t���@�����`��M���]ZG���YN'�phl�u?��~�}�g^���!N�����><�vV�J}�j��F�W��zI���v8��VDDDDD��8�v���?���8�`�|o-���k|o���%HDDDDd�X���ysh���_����X�sM��kj���B���xs������&��WH|�s{:#���K��������D;V��m�;�X��y������"�������q6�l�������9����5������������/�Q��HDDDDfN"���'��s��x��I�g��!��%��%�����������8�V����
���P]SKVv�,}3��ix���������X���|�����!�#}D���u5�L��g������:�aU4��Kw����Q������3��������%'9��%K�������0�������1E��X�_��dY���E��x2�0��a������p��{��diV�h��#�r�����������gc���K���C�o�5����w��q��������.�E�	�$%����b�n���d�r�8�����(��������\;q�DI���}��Vo���(��"E�"H��At`��=��Es��D��y��C��of�����FC#����g����y
)���d���,""""2�h?������s����Hf$-�-{I�r�lZCt�j�V�q�|��<x��C�tv��l�J6�v��z���	��	��q���H{L�S�c��&i��t���79K8^UC"'gF�u�0c<���06�qx����2B�^q������a�����������<�1�����>7V��Bg1n��#�\������<=�y%��"EDDD$c�|�d����CC��~w'��2<4���d��F��,=fl���?
R��-YJ���8����a>x�M�t^yM�P�0������!�@{s[��W_>fY2+����`Q>/�
��aFB#�"c��kZ���L�����+�[�j!"""""�1)���XC"�r6�2�8r��������g�CMME�%�\Nd����BA$]�k��|���M�l��t����&��!^U}�����b��i=��zd�����!�b���h<�������du3����E$��H�&��x<�����%���r��<�vn[&C�/�=���=a�*��v$@��V���;t�}��������E|n��X��-�ZN�5�������:�������I��O���cm_W��/�����3T�$��q�h�r�<>��,o����m`��
�
��=��p����oq�x�W���<���`p��=�Xh���0�X`j��YD�E_H�O���-+�@�-�ia�T�k2j�������wi=��Nz?�*��m~�5��~v1�;��C��`%uS�YB""""s��u?�w�M��@���D�wj}<��P+��������R��b�2���D~�����G��^|�����,9n���G����8:zt������������
�0��8��y�_x~>�\7	O����c������f����ku�u���Bg��;y9%��ME\�����g�1���u��t>�DL�8���&p�_)"""�����#b��]����������b�����i=��X4
@m��L�<+��U���s���%��(�X���f���G�!;fy����k����1$��������9��S��"���V~I-ADDDDD��9�S���c����������|�.�@��q�q�L�.Q2�l2��M�T>���k@��5`+���&y��$W��n������GbG���M
4-k����u��\��B�7��T�N���;�����i	�y ?���y�a�H�o��m����c���,�m��"�ov�k����9���w�2�t
,nz�e�_�!�%��	s2�������_>_	�p��A�������b�Y���6���.C2D�����w
�s�M�5�?��H�����WPWW��2�Td,���|:���z��������E����p��\��:�s�����5���������)�s��g���2�>d��X����b�,����|`N��g�~C[N��`���P��4��X���Y��������G�����<\Z}S�K�b���6"g�M�f?f��7�������o�p����b�(#��������c(8���$��O���=�%��X��{x��EDDDDdA���"y���f_����1��������b�l>�-�����+b�cU3[��C"EDD���6�<�0�x���Y�l��KN��������y��n�v�6���ln������y�^�;�c�h ^VN�i>�8����^z���y������*�pp�#�aFC#��G	
����w�����kqY]XL��bY���DDDDD$��,���_�iV�n����2�����,�$���a\���jf'V����*
��)rS�U���u�P3�c�e,4����������p�=)��b6���d��������,���01A�b!�f-�Kx���?�)}��8��X���T���@�O$I��4���G��f��z��,��a�5�6�s�O{�"""""�0���#"""�p���0�?p���Q
y�������:�����?��l&;��������(Q����6|x��oh;��h!�Q@�5wr���CeN5�67�ww`��*��"gl$�rI��g��Z�r��v�,mh����c�?W�"����1��i=e88H,��U�g�R�D����e����c6��N���BDDDf���7y������B�\dR�]1��������Ojl�����?2��r`�����������f�e������i����,�i"�2�Z����0Mig�w��x����X�xy,/XE��MaV�	�]�,��zEDDDDdqS�-"""��@���� y�<
����Z�'No�1sEs�i4�Q������s�a���di#��c��������v<��`�����]�[���u�u
������nFC���2`C��l,;'�v5�Zn[�%<���,WDDDDD$%��"""���}���1�g88H�oj]s��V��=��y�&|�~<�F�%W�o��<���#����lK�6�]���,K�d���d�����~f�%m��y��i�v���-m�v.k�>�'c88D�-���r������@��K�#�Zw=n{e��3�m&;6���%"""""2�j����Gj����7���e�\t:��B
^
��.�����s��-�����H/������X��Z������WT��~2�>�CS��O�7�cy�nYqG�>��F0b4<�hh������m��6��Pr&J�<��\DDDDD$�j���,R}=������������s�s/M9v]��+>#m�����c;�moa �����j^x�Y�jjY�|�K�b2�f����"���kLD'��xO����N�`�?3b8-Y��*��y�����v�f��������P[DDdy����i������V��H,�v��f����!#|�9DW7�tf��\�@V�������av������,?�����G�-�)u���H�����2�e�I;�w(4H2��1^g!�YE��|;�d2IG{���p���[>��r8�;[���h*X��DDDDDD2F�����<��a0��`p��`?C�b�(�[�yJ��Snwq���\i����������8���p(@eU5�p[�@[DDDDDD�>��""2'�"��!�_��R�����o��S�sm�<K)v��ksg���3��������3j��^�:*�khlZN������L�(""""""�@�����	�8����bn?���g>�qc�C��:;��Y;������ �����
�j�#%�e�d�a3�8�b`�������Fp|�L,k����gb�-��?""""""�Bm�(��{�����I��h�2b���kjRnc{�9�m�H�����rgD(�g����z�=��{�B|a�W�����fS���[�t�� �%�8�F������t�>�<���P��"""""""�Bm��x���Jd�Y�AvI�Gn��R���wO<���;I����?v������n[��%g�`1Y2X����x����������|�%�Z�Lx�F�%�j�3]��������0��""2cL}������]�<�����DW��X�M�r]v%����G	�p�t��u�%XM6J]e�d�a5�2]���������=B� N��O�j�M��l<+�%�������,R�-""��ajk�|�����������T�������n�[o9}�������#�������������;V�1�-����{�/T�`�������Fflt���n��Op{<)�s���/i ��&7����U$���\��������
�EDdZXv���7ON�0��UU��#V��Dn����*��0uwb{����K�f�8'�7����Hhhj���K���P<H�����fC$f||��o�1��O?8�uv���C]�R�Fc����?�����2���O[�""""""2�(��i/*&��t�uu��kg���+����c$�2;sw0�������F��J)���nrd����9�v���aFF&gY���p��r�]_I����.��t����0�N�������0�'N�DDDDDDd�S�-""'d�|��C�$sr	]�����E�?}�,W��\7m��}�����5�N���/��
�!��[W|aFj�-n
��rQQY�r��� �}����9�n

�dg��u�Ox�U��?Qm�����I������KDDDDDD��""rs�AL�a>��qd�dV���W6�v�N�����6B���r���D�����������-�o����(�C�D#��u�W�Nj�p�mw��������:��[�n{�X]=�
g�x""""""2�)��c����x�!0���^��Xm=�Eh'�I^�|0P�,��UFqV)%Ye�ls?�����OLL�Y[���4����� +{rV���C��Ev��	�k����[8S�p����'��K��+g��""""""2�)�Y��q���!m�����W��%i��re3g(4H�X;��|����c����=o����{�������8�����Ljj�Y|j�Y3]�)q<� �d���7,�kQDDDDDDN�Bm�E�`nk�t����$<yn�-����N�i�,W8���;�������}��p<��l'b7�~��t��X�P(H(�l2��xR���'����B���������_��_�=F$�nwPT\B^^>�nn�w��#{\�u��.�06Fb�f����������P[Dd�2�'��|��C�z�HZ,��k��/�pu3+>�������d������s�(wUR����>"�0�X�x,N4%��F)�z�Zm)����mv���P(x���e+Vq�%��>V8��;��n�cw8p8x<y����P��s�����G��2(-�t""""""2�(#��� IDAT�Y��0����(�9}��:��`4f��S�G�o�gY���cL�����=N`����N�� C��t�:X�fm�c����H8�r�u����������.O&�����l�l6ST\��x��<���o�]/"""""""�P[Dd�2��8:Blic����|�_�
�4=���h<���}��i�mcxp���^���v��Cee�����y)�������}�X�����|�+���vMm=$�S3��v�����?Dq��5�\�����������|4��""��e�n��c�l���Z�Hj�:�'������e�}��h&��������G�����6�[�@��Y���Teg3|�fL&3�9m��\z�U�}*"""""""2Mj���q�p���a�����	�������4d���7e4<�Hh���n:{����"�O��7������g.=��7L�����j���NgV��������y�9����C(�$��4��(���~�x��."""""""�P[Dd�3����N"'����D�H�o�1�|�{�|�F���qLF3Y�,rl�

��n���B���K��:����b������DW�:����a>��#>�\"6e���j���qI���D"''��#�0���k?G��Jfs���M9��Y�s"��,/e5��UQ\P������#g��$-��\O����c�'g���c$r�D��e��j��d���������#p�����^�J����}���ett�H ��`��U�e��b����Y������r�$�2vlI�
���aH&	\{I�=�%�������<�P[Dd��z�1�o���>��%|����l����5�A�������c�#c��B�%�����WPSZOMy�����H:�G��'x��$
��.GDDDDDD�	��""���_?���@�������54����������-�����w����������_~�����Ys
�Z��[8����c{�yL�D6�Ilic���yD����,�.[A�n	��&����yi������1�x�y��UR�����VT�>��
�e:$���54>��L�"""""""��Bm�id>�J��G"//����5�z�@�O[�A��;���w����~�����N�?������iW��,e��Z�|b�������3]��]�����.CDDDDDD�!��""����r`?�����C,Fd����<+���=_���o���� /��%U�x��^W!�f������KX��&��O��.����������IR�-"�	������������64k8����D�=���{h7]����;(.)M9��sn$�>JYa�E5�dg���|�|!��v�O=���?%���tI"""""""rj��|�$��!b�u���-m i��]E�a~��9��EGW�=�$����7_�6������E��%mv�W]���?������1�%��������IP�-"��a�G2;u��xM_�:I����MDy����d6QVZ�����W�������S>��/)%|���^��w�Y�>�%-H�p���GDDDDDD��)��Sg�}{1�o!��O�s����X>r_�D���v����#}}�~��p{<����ds�7S�U���
Ug[d�FL����������O����Fd��D6l�t9""""""�(��E����e�>�-�c'����r0����eo�:������c�\�����6����~�����.�
��~��7
������0��$��3]�������,
�EdQ3�������XC��&�u�'5���Q?=�C~f'5��T��PW����&��jg�d$N���#�e,8�W~��������U�����P[D�D^�5k�U�������X���.�w�e�����	k�^�/q���8�(-)�b���)��I�����:��Z����t9""""""��(���������.�L�1��gW�Z�Gk�~����� ��k����\��jR�kM��i�_d>2��b�19����:����������P[D��}������C4
@t�*��e'��pp�����%q�\T�P���e�+(/���-���E�=��o`�	~��6{���fn���A��I�4��{�������o*�l]"2����
�=������Nt�JbK�/-��o��}�r��7��OYv���o����������-���.��h�r�Ez8�������L��j ,���������ED��,��Wmhd����]��o���>����A��$b	
����b3��E���l��z�����%�h��O]�j���|,���L� """"""�!�L&3]�q"��s�;�m������K����
�'�$s�d�=f��X<��2$�A�f1K�0NL@v���]G�����Xr��T�T�X����TVT��z1�T�L�Y��0��?C,F��wAN��SN������5 �7�����������cE�h�=��G��8���B�}�9��x_���?�?�t��A�\c�L�!��
b��������c�W]�����}����g����K�}$��=��z�(*.�l����"�l~��:q��g��K	����Y9��������5 �7��������7���2D2nn&<��?����%����q'}q��`Y"2����X�P<H����4�@9���X�����}�^����8�x�?xg���8�h���r�k����Y�V��5+���9��/� |�9�^y	��/>��L�$""""""����P�s?���?��
�z���"*L�.LDR	D��b!b�(����{d�/	�	�����z�g�qO�-6�C$Mf"g|�xe�����~Dr$��n��UG����Q^Q�2��.�
�0������U����tIs�����64kl�t)""""""�H��P���+7�����M�����z�X�kY��}<����d0MD��9�N���ki��I��&����#^U��d�n�S�]:5.�a�
��^/�?���<��n"jp�������j���WO<���_!i�d��9�������%���P[DDDDDDf����R��b�zK��Y������A06N��!BG�����S�9�v�D��������d�nv`�8p����5�C�����H���pm5�������v� �;����N������9o��"��&��t8	^~�XL��Q��Nl�{�xI)��e�YD�h�-"'���	���c��m=B�bA�� �[�%m;�._'{�����f;n���A��"��J�����o�Tm��^��������p ��@�A:^zajlEe m�-�i���L�0g~�=D�� xu������������"s�xx�[n���
���h�f���8pYs�:����M��t�_u!�W]xJ�"aH$H�S'V����I���xY9���p�rX�����:��j�X��T����cc��	|�&���L�#""""""��Bm�9&���;L��A���N��u��dL������n�H�h;���?�z	�s>�3>55��� ++�X�buK�����\N�+��p����c}�uL���>W��EDDDDD$#j�����E��A��M-�pU��p�d�C��`�����1���<^\B"+���N���v� �G���wPX���IMm�l�,"3$��C<v��\EDDDDDDf���
�q����.EdZ����������z�����j���
��z����$^Y��~?��q��g��'�h6����&�Hd�b��cj?L��:�e����Nx���.CDDDDDD�yj��#�����Wi^O�iY�K9)��8.kN��7/�����g�!��5�N$^Qy\��DW�&����������EWG;%�eTTUSQQEqI)&S�f���6�K/`}�
7�J��2���������,
�.�N46�����.O<B��g��n&�f�V%s�/<������K�D7���3�vO���h"L����O��&� 
j~�+f����y��.��R��oN����������G��vg�+"""""""2��]���v�|�s���g7��oc}�5������/�-�d�Xx���=n�?�7���UN4�`e`��kX�����DQ1��*���Lxio�KWg;��
r������r_
�E ��!t��8�5��'x��2]���������7�B�$-�k�]�Sg��h���D����{qZ�XV��w=5�Z�����m�D %��J�>VS���J��$mv���{^y�����q�e�l�x&^o���,2����Yw:��oa}�
"�o�tI��8�O2;[3�EDDDDDdN������+*��T��s*>��h�8�t��5�N��SG��n"6>������U�+��Y��Z����M�WVQVZ��b���E���/������&�I%3������������?�t9"""""""SD��QL�=��frfw�r0/���i�$I�����V��rf������[�S�r�t2�o����z��Y�(,"����(������{���������e�Y3Z�����Z�����"�v<�+�qB��1���������cQ����1��C��$��#�j
���$��L�&sX0��h+�Grx��X���D"1m�1��`��a������s�Gt�Jb���sC(�������Xe�T;���HgG;�/>OWg;�GH&����Ml:��i�YD��p�����6{�K9e��>�����9����t9"""""""�X�v�����%XZ���c;��������jj�l<�xYy�K�9����3�.����j<������d7��`� �
a&��������p>p?������%��&��542�����1�l��/�����a�YY,_����Z�kJ����h[���e�N�M�O��%""""""�)�"��l&�b��0����6,��%��9���d�8�RK�3��dIl���)���������+�rU�7F����i9��$��6;I����~L`��Rg��\JJ������������8K�c��:�?�4��"B��,�����������xB����e���� f���"a��P�DN���������z�pZ��LD�{�����	�b|x>v�������v��$|��$��Bi�dPm���Z��kl:nY<gtt���NFGFadd���V�^�6��������iD�$����W��*=BDDDDDD��E��G������jHZ,�T����Q0���l�QLG�0�����FC#l=��Ce�q��������6i���z�WTN���d@mw�<Q�u�yZE���<I������tb�0m��c	���M[2]��������	-�P�D���8�5I����UD����/�tY��!�������co��^��|���n�t8Ix'Ci��}�6��'n�'���sJVP��'���v�%
��4L[��H���!FGG��i=vt��W]Gi�^��U���f�nn���C^^>f�pEd^�n{�xq	���L�"""""""� (�N#�v��j�;�M��~g��
"���5-�ty�!�'���b��M-K�����kN�7_x����Z��7R�[��8{��O��L|���rr��bi�[�r5+V����Dd�����b�o�S-�DDDDDDD��B��5-#�������`��.�'!�{'�n�tyZ��E�b!���xE%��*�B�sm0&rp��#���\T���f.k.k�'�eb�7��z�ho���Q|�c|�+_K����e$q�n��<rs=����/"O�b!t�U8���O>F���f�$�yO��IHx	m����a����]3�>)�@?��vL�����c�w~)���;���k=]XM6����z��������\��_@4���A����yFj��%^\B������;���"���L�L�"�3#DDDDDDd>R��1$�V���3]��b�D���SW'��� �A+����t���������1%��-:�Zw=���'����cc#�3���{��\v�5)�����~I�dokOOn�W�'��-"�Od�F��Z�����
��%�.	�3Oc!��[��/DDDDDDd��w�����m�v;��33sx�1���y�YY�+�'[�TTN��@4���M"��]�rW�Y%l����5c��U��w�������b�Rt�p�l�p���}�c�����*���W��=L��;I��-��`�����]�Z���������;�Nv���|����'�r5���$��^Sw��Q��W�\��X��K$����%�	}���������a80(�*Nj[LVV6�$���N��bdd���A��?��u����[XD��x<����3�=8�S�� "r��B_���`FmSo��~K����g��OJ��4^���K��:�������j��6�#V�:��/����z�1��`���t�	bK��
i>h�n����`3�)r�������RJ]�'���G~Mo�!��1�]9������WPV^���("2�b�M��2v|C(���I����A��EDDDDDd^�w�3 Q�%t����9������������������>C(H�O�e���D���H�z%��KJ��p<D����BENU�}U�Trq�g�b�[edx��C��?����9�\w��"u�KiZRM��ENN��\��;^Dd�$�8}����
7.��"��M��J�r������0�t��@�86F"77����A�3��(�/) �������JO�d+��������v�%�������O�;�������/m��b�j��6����4ED%SG;��v"��D��6���������|b
�gA�j;a�`�D�` i��bU`��|4�0uu@<���F������y�n�v^�x��IqV)K\
X�V�'>�d2I��������/E���l�S?19N���������t)"""""""�D��`���k/]��h�:��3v,C0���Oc����t8�WT���Y=����EY�4�/K��*W
����7�?�G�D������
�?{��i>3�������)���@�����#�-����X�y�xe��u���abI�So��b��+*�s&88��>�Az��L8��+���Y�6��2e��u�E�TTVSP������|�f]�������?��[o#�_��rDDDDDDD�<��s@���Xm=���;�c~o��v�YY/�zj��|���q|���H;v���z���=�����%0�'1��4c�0���}�&�~�v��v'^o��:_�����!���C��>���DDDDDDD���sH��K���1�s>�=���|�D^^���H����:;0u������.�(�q����Q���:�.���F���m��f����QP��[XH���B��@[D��$
��.��3Oc{�B��,�%��������i
�����J�y��u'g{�9�V+���%���-�w�90��������1�FlX}&v��S�gY�J����z`����BDd6EW7c>t��w�U�kJ���d���������W��4MU��������
J/���������y��/�~���$b	�&.��l��*W-�V���������g�lI#t��8�;���O(*N��:�8<���'Hfec��H*��F��70z�����u���s�6^���3�	�VU����AMI=��%��n����Zm�(]DD>���F��kq���X��E���?�>�(�G~�!�$p��$��/""""""�B�9�gO��]-;82�K0�Zn2�h�Z>j���k�f���g�L�f��b7�J���mo�	�C��.��D�w���j��@h�}�{9�y��6^���L9�������%��SVXAUq-e�
��,W-""������oc������D�-���DDDDDDD���3�7�?F{�!��t���������UK����1�v�����V�""������,��bB~&����������(���`88D�#?���?r/�H��A~^5U�{K()(��S4�����B���'|���6-�t)"""""""3N��I�^q��IDAT�����ti��H;}��`H���:�v���CiA)���Y�VDD���2]���������P���;������:f���Gq~E�'�6]{���|�$�j�3]�������H�-�P{,8���V����:�A�`7E�%|��o�__���/����
��UT��r�""����~bQ���)�lW����Ej������'~J�8f��h��"+�vv��6�:��������j����'%p��I""""""����P;��������t����j�L9�es��.������J*K��.����b���x���7����W���2��:�e��.KDDDDDD$#�l�=��V����1��2���&�Ka������?��c�#$b��m��iC�3����k����EDD�Yd�Y��c}�5������/��/�tY"""""""�nn���V������sKa������B��5�7����C�����[Miq9�%UT��QSZ���EDDfL������#��B��������,Z�d2��t���
w���_���,��s]�=}>��v�=�E���d@o/��d�
��1f��T��0�
���������
K<B >f+��EK��������,rs����e�[��/�0Fi|��V+N����C�L�(���10�t�!z�E���X������5������~
X�F���L�!�qsr�6
����N�M��"�kepU%��L&""""""""""�4'gj����o����+^��q�����2[�����������d���������
�.CDDDDDDDDDD����~DDDDDDDDDDD$��""""""""""2o(��yC�������������
�EDDDDDDDDDd�P�-""""""""""��!�L&3]���%2]���������HFX���*2�BmY����7j�������������P[�����;w�b0�uH�D����s����C2&������"�.D2F��EN��EO��}`���1��c]���"��9����W�r�=����q��7�\���d�EGG9���q%���-�?X��'/��s�����l��rJ�,Vf@���y���M����s�>�F7D������P�I�_���g83Y��������o��6A�L����r��,6������]�~y
�T���D�.����V8'�H5�X�Wr� 0�s�{���1�L����rS�,0�Q����<��8_6w\W���b����w�Oo���p�>Sw?p%�,q;��e���b�CA
���L�����=����~�g�����s�������������V��������
|����@����ux��m���Xs��������|>����/��Bvq����v=������txvJ�i�s�x��;~y#�y�Z�s������������.�;����_-�����I|����a���}>�K>^�q����{���������=�>��} p�����>�+`>l{�_�v��C���>�HL6��+�_�_�
}��@�}���7��_��w��D��/���������_���M���5|���9�!�,���q����_����4���tX4�����+���+���\���~����|r��9�s�:�10���ww��W��_���_w��w��P�D�8�#���CgE
k��F�8���xW���,�����p�u����]��������Xqn��������r�������[=�u��Y����wGg�Dc��o��ZZ8c���hJkX�����C��#t��,�����+5cc^rq��o`�F+g��(�B7&N�>����J�Er�f]���=������{�1������6���|��_���m9J��#L�yEX|��n�sp��-��Qvo����/<�w����n9���"x�5�-���������JV$@0'����I���m[��_����5S����'>B��G#��\OC���t����P;�p�0o}��/y����#j/~_��F����_��X�
k ��/b�{x���A���d��D��y!������D}�y6_f�� �� �����bI�)�b[uEZ�r��im�f�����[�m=�j���[w�D�����\[�-�r����Sk�Ei�
e3dn��&�3*j���q#��_�w�~���/�����|���������&x�4��
~����k�c:|X#�a{>���&'OT�����u��m��/7
��O3H1��'7JSB+K��r�r;�;������rH���.��q"q
���d�#��a��Vjw�>,��iziZ�/�����`���]U��K�}�SY����O�k��E��q'��ig?�+���>��Sg�X^'[���iy=o{�Y����u ��|+���a���c9	��N\)N����N�]�?�: "7��P���������O���b�n�����qw|4~�IK������!|��j���
�t��%]z�#�y{iZ�1{�rX�9�I��&&0�ewQ�}��>,�����$2=����z�Y�K���q�~���?�Pwu `�Ov�<qw���^n�@�Y�t��������a�v�q���n��q#�EqYjp�\�A��X�,B/fZ&���bq,��!b�����:pg�cs8H/��m��Jfr������Y�92��~m����0�x�7�����2��[���vj���:�w�d�
�~���An����yL��)5{��IM&$����""�&3���NZqd�9�l���"M����2+�aw����k/��M�zkKM�x�<�3�f�]�D,����n:�S��E���q{2Y�N���d���t�2��M���Tl�b`G�.b"U�����i8�O���`B���2z0��z���4ml��SQb?DM�����0+%��[�Q��:0^46�Bu;�8�y/2���d��\8����LZ���G
������:pG0�����g����?wr�;W2�����o�-t]�������������� �a`���u�`B�TJ��!���i���w$"�t���Q^�S���9]LK@u@Dn5��#��k{��\=��'S�|��J��t��k�)z���X��������b����b�v?^����\*Jo|O��i�����a�������H��S�_YL��)�v�6P��EQ�L:k>�����V�#��S�����l�x��9�.o�F2�$��W�T�@���Yr@xu ��9����]��T�J��=���:0.�>�K��f����DM�fEe"��a6E��yy�0E�#�(����D8���s��x��2�h2>��PO,��
�,��o�����,-d���>y
[t���|]*6���DJ���-������`r��������vb�XP�����TD���._�|y�!""""""""""��X~DDDDDDDDDDD��""""""""""Aj����������H�P�-""""""""""C������������D��""""""""""1j����������H�P�-""""""""""C������������D��""""""""""1j����������H�P�-"""2B��z�]���2��C���v�.~:k������Xj<
pf�yvm�����;D�X@DDDDn���{����)�(����ci�<�����PDDDDD���._�|y�!"""o�]x�I�)x�r���@������'�v~��I\;�QrOp������������6��w�)txh=gP������i��g�������r>���n����I�S�X��
--��6����o1N�>��Yfh��4>�/�/}������>,_������{GX���~I��S���@���,]�C���F��-��aY�#h��(��CM�^���i���=���s(�{e|�?�W�9�����\*�d1�X�4<���%K�Z���&�y,}���/�O�s:o&�o:�����o��v>%���!��m�Y�����M�^�E��(�
���=�n����@��0H~`&��J�i\���_������1S3([7����i�Z�-���f���W�����i|���! �.�-�0=����{O6�nZ���t�T:�O&���h����� ��9�/�S�.""""��:�EDD$rDG������Tm�I�a�^[�{�O!��5���gp6����:��5��7�����G~i00������E�Pmb�p���4�-�$<�6Q�����?!w"ifKu3���p"�W�A����[@e����������<�����a��s����6/mH������,��>���8��]��6j���D�A'+���iq���	3�L��`��S���*��|�*?���x^X���L���l���N/�$�����c�K���<��p������f��G��|M�
����xR�8��q2����[�zG=O��ix�����,H7���i����&��t/�^>���e�����3��9v�K���`?k�2�����z����I��q?c�����F���{�Ru�I��f��0��������������^XB�D�ia��xV���,�]_R����rI���!""""r����"""aL���ko�e��ZX��>�Iz����-�I��dB���~�-�G�:z��LrS�\h�/�M�g�����/����r���m`�Ec.JV�b�[�938���PHk���t2���n�X��K��>��0-�ql�e���}�>��A����������B��v'Ee����ueSrX����
M�V�2��|����L��IZ��:vv
.�w���rw4�#�/;��o�\�<���N�5m�����o�
���o3t~���^���i+��x0�Nu���<�����o���L��;89"�M������mN��,<����h�{9�����l)�TlV�-""""�Nm�,Qv��7�B�kD��S�
����q:�p����� 0�����>f��#��g��Z�;�y���~�#�	#����Dy�X�v��XX�pw�9b�3���k��_?��-{����W�C���s���K�k�����?�8����8G�h3�(|X��za�<�y�Rk��d�R���o�����x2��|����h�"lo����gWOI�e�d�L����K� ��M�GN+�$&j�o�63������{�|������MX	��VP��{�,""""2�(��;L��������f�� ���`yw��	qI�KX_�?w��n(�ds����u���c1�0C����01��/�#Cx��n���9$��:Ry��yL�o��t���3����wR�������������i�p�{.g
3��dK��dC%��M;
U����H���>q��*�p��=�7�����l���a�$.�	Q��Gl��6�?��W'�sv.�s��#���>@c��5�EDDDD�#-?""""w���7=��v^o7G��u!w8�g;���`�?�NkO<��&� �!'?j�L�����4T�i��3����|�������s��o1�f��C��8�-���ONq&�ZGNq�����si���f0��IS�'������j���z.�-�z'�%)��M��fv5zG$@��s�yC�?���9��S���h���V~��8Bi�$�r�x��nV5�t>�s`��'=c�({�\��5����������9%��������m[;������DDDDD�T���;��L���������$$8�>���4CXK6��Y�����M��\���\=��)���e���o��'�d7��A��2�Y�"���_��n����� v�LV�N��������}n*���b���S��=�=��_P�J�|�Q�������.��gc')��0�E��l�<@c�"���29��}����d�Q�a&ia�������r�=u�
 `������P�o&R���=U�
5����R�.��}���
�K��|������0b)��%SM
��sis[J�lSR)�2#�%]�s�I;����-��z�����@]�""""2��u����c=�k�4=]���r���Bw�������Z~DDDDDDDDDDD"�Bm�Z~DDDDDDDDDDD"�:�EDDDDDDDDD$b(����P[DDDDDDDDDD"�Bm�
�EDDDDDDDDD$b(����P[DDDDDDDDDD"�Bm�
�EDDDDDDDDD$b(����P[DDDDDDDDDD"�X7����AIEND�B`�
diff.difftext/x-patch; charset=UTF-8; name=diff.diffDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 1490aa07246..56e7503445a 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -149,12 +149,12 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 		 * an OpExpr.
 		 * Get pointers to constant and expression sides of the qual.
 		 */
-		if (IsA(get_leftop(orqual), Const))
+		if (IsA(get_leftop(orqual), Const) || IsA(get_leftop(orqual), Param))
 		{
 			nconst_expr = get_rightop(orqual);
 			const_expr = get_leftop(orqual);
 		}
-		else if (IsA(get_rightop(orqual), Const))
+		else if (IsA(get_rightop(orqual), Const) || IsA(get_rightop(orqual), Param))
 		{
 			const_expr = get_rightop(orqual);
 			nconst_expr = get_leftop(orqual);
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 2314d92a6d4..b492ef1654f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4256,6 +4256,23 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique1 = 3)
 (15 rows)
 
+SELECT FORMAT('prepare prep1 %s AS SELECT * FROM tenk1 t WHERE %s',
+ '(' || string_agg('int', ',') || ')',
+ string_agg(FORMAT('t.unique1 = $%s', g.id), ' or ')
+ ) AS cmd
+ FROM generate_series(1, 10) AS g(id) \gexec
+prepare prep1 (int,int,int,int,int,int,int,int,int,int) AS SELECT * FROM tenk1 t WHERE t.unique1 = $1 or t.unique1 = $2 or t.unique1 = $3 or t.unique1 = $4 or t.unique1 = $5 or t.unique1 = $6 or t.unique1 = $7 or t.unique1 = $8 or t.unique1 = $9 or t.unique1 = $10
+SELECT FORMAT('explain (costs off) execute prep1 %s;', '(' || string_agg(g.id::text, ',') || ')') AS cmd
+ FROM generate_series(1, 10) AS g(id) \gexec
+explain (costs off) execute prep1 (1,2,3,4,5,6,7,8,9,10);
+                                QUERY PLAN                                 
+---------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1 t
+   Recheck Cond: (unique1 = ANY ('{1,2,3,4,5,6,7,8,9,10}'::integer[]))
+   ->  Bitmap Index Scan on tenk1_unique1
+         Index Cond: (unique1 = ANY ('{1,2,3,4,5,6,7,8,9,10}'::integer[]))
+(4 rows)
+
 RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d4d7d853a4a..b6cc4644518 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1405,6 +1405,15 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
+SELECT FORMAT('prepare prep1 %s AS SELECT * FROM tenk1 t WHERE %s',
+ '(' || string_agg('int', ',') || ')',
+ string_agg(FORMAT('t.unique1 = $%s', g.id), ' or ')
+ ) AS cmd
+ FROM generate_series(1, 10) AS g(id) \gexec
+SELECT FORMAT('explain (costs off) execute prep1 %s;', '(' || string_agg(g.id::text, ',') || ')') AS cmd
+ FROM generate_series(1, 10) AS g(id) \gexec
+
 RESET or_transform_limit;
 
 --
In reply to: Alena Rybakina (#56)
Re: POC, WIP: OR-clause support for indexes

On Wed, Aug 2, 2023 at 8:58 AM Alena Rybakina <lena.ribackina@yandex.ru> wrote:

No, I haven't thought about it yet. I studied the example and it would
really be nice to add optimization here. I didn't notice any problems
with its implementation. I also have an obvious example with the "or"
operator, for example
, select * from multi_test, where (a, b ) = ( 1, 1 ) or (a, b ) = ( 2, 1
) ...;

Although I think such a case will be used less often.

Right. As I said, I don't particularly care about the row constructor
syntax -- it's not essential.

In my experience patches like this one that ultimately don't succeed
usually *don't* have specific problems that cannot be fixed. The real
problem tends to be ambiguity about the general high level design. So
more than anything else, ambiguity is the thing that you need to
minimize to be successful here. This is the #1 practical problem, by
far. This may be the only thing about your patch that I feel 100% sure
of.

In my experience it can actually be easier to expand the scope of a
project, and to come up with a more general solution:

https://en.wikipedia.org/wiki/Inventor%27s_paradox

I'm not trying to make your work more difficult by expanding its
scope. I'm actually trying to make your work *easier* by expanding its
scope. I don't claim to know what the specific scope of your patch
should be at all. Just that it might be possible to get a much clearer
picture of what the ideal scope really is by *trying* to generalize it
further -- that understanding is what we lack right now. Even if this
exercise fails in some way, it won't really have been a failure. The
reasons why it fails will still be interesting and practically
relevant.

It seems to me the most difficult thing is to notice problematic cases
where the transformations are incorrect, but I think it can be implemented.

Right. To be clear, I am sure that it won't be practical to come up
with a 100% theoretically pure approach. If for no other reason than
this: normalizing to CNF in all cases will run into problems with very
complex predicates. It might even be computationally intractable
(could just be very slow). So there is a clear need to keep
theoretical purity in balance with practical considerations. There is
a need for some kind of negotiation between those two things. Probably
some set of heuristics will ultimately be required to keep costs and
benefits in balance.

I agree with your position, but I still don't understand how to consider
transformations to generalized cases without relying on special cases.

Me neither. I wish I could say something a bit less vague here.

I don't expect you to determine what set of heuristics will ultimately
be required to determine when and how to perform CNF conversions, in
the general case. But having at least some vague idea seems like it
might increase confidence in your design.

As I understand it, you assume that it is possible to apply
transformations at the index creation stage, but there I came across the
selectivity overestimation problem.

I still haven't found a solution for this problem.

Do you think that this problem is just an accidental side-effect? It
isn't necessarily the responsibility of your patch to fix such things.
If it's even possible for selectivity estimates to change, then it's
already certain that sometimes they'll be worse than before -- if only
because of chance interactions. The optimizer is often right for the
wrong reasons, and wrong for the right reasons -- we cannot really
expect any patch to completely avoid problems like that.

To be honest, I think that in your examples I understand better what you
mean by normalization to the conjunctive norm, because I only had a
theoretical idea from the logic course.

Hence, yes, normalization/security checks - now I understand why they
are necessary.

As I explained to Jim, I am trying to put things in this area on a
more rigorous footing. For example, I have said that the way that the
nbtree code executes SAOP quals is equivalent to DNF. That is
basically true, but it's also my own slightly optimistic
interpretation of history and of the design. That's a good start, but
it's not enough on its own.

My interpretation might still be wrong in some subtle way, that I have
yet to discover. That's really what I'm concerned about with your
patch, too. I'm currently trying to solve a problem that I don't yet
fully understand, so for me "getting a properly working flow of
information" seems like a good practical exercise. I'm trying to
generalize the design of my own patch as far as I can, to see what
breaks, and why it breaks. My intuition is that this will help me with
my own patch by forcing me to gain a truly rigorous understanding of
the problem.

My suggestion about generalizing your approach to cover RowCompareExpr
cases is what I would do, if I were you, and this was my patch. That's
almost exactly what I'm doing with my own patch already, in fact.

--
Peter Geoghegan

#58Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Peter Geoghegan (#57)
Re: POC, WIP: OR-clause support for indexes

On 02.08.2023 21:58, Peter Geoghegan wrote:

On Wed, Aug 2, 2023 at 8:58 AM Alena Rybakina <lena.ribackina@yandex.ru> wrote:

No, I haven't thought about it yet. I studied the example and it would
really be nice to add optimization here. I didn't notice any problems
with its implementation. I also have an obvious example with the "or"
operator, for example
, select * from multi_test, where (a, b ) = ( 1, 1 ) or (a, b ) = ( 2, 1
) ...;

Although I think such a case will be used less often.

Right. As I said, I don't particularly care about the row constructor
syntax -- it's not essential.

In my experience patches like this one that ultimately don't succeed
usually *don't* have specific problems that cannot be fixed. The real
problem tends to be ambiguity about the general high level design. So
more than anything else, ambiguity is the thing that you need to
minimize to be successful here. This is the #1 practical problem, by
far. This may be the only thing about your patch that I feel 100% sure
of.

In my experience it can actually be easier to expand the scope of a
project, and to come up with a more general solution:

https://en.wikipedia.org/wiki/Inventor%27s_paradox

I'm not trying to make your work more difficult by expanding its
scope. I'm actually trying to make your work *easier* by expanding its
scope. I don't claim to know what the specific scope of your patch
should be at all. Just that it might be possible to get a much clearer
picture of what the ideal scope really is by *trying* to generalize it
further -- that understanding is what we lack right now. Even if this
exercise fails in some way, it won't really have been a failure. The
reasons why it fails will still be interesting and practically
relevant.

As I explained to Jim, I am trying to put things in this area on a
more rigorous footing. For example, I have said that the way that the
nbtree code executes SAOP quals is equivalent to DNF. That is
basically true, but it's also my own slightly optimistic
interpretation of history and of the design. That's a good start, but
it's not enough on its own.

My interpretation might still be wrong in some subtle way, that I have
yet to discover. That's really what I'm concerned about with your
patch, too. I'm currently trying to solve a problem that I don't yet
fully understand, so for me "getting a properly working flow of
information" seems like a good practical exercise. I'm trying to
generalize the design of my own patch as far as I can, to see what
breaks, and why it breaks. My intuition is that this will help me with
my own patch by forcing me to gain a truly rigorous understanding of
the problem.

My suggestion about generalizing your approach to cover RowCompareExpr
cases is what I would do, if I were you, and this was my patch. That's
almost exactly what I'm doing with my own patch already, in fact.

It's all right. I understand your position)

I also agree to try to find other optimization cases and generalize them.

I read the wiki article, and as I understand it, in such a situation we
see a difficult problem with finding expressions that need to be
converted into a logically correct expression and simplify execution for
the executor. For example, this is a ROW type. It can have a simpler
expression with AND and OR operations, besides we can exclude
duplicates. But some of these transformations may be incorrect or they
will have a more complex representation. We can try to find the
problematic expressions and try to combine them into groups and finally
find a solutions for each groups or, conversely, discover that the
existing transformation is uncorrected. If I understand correctly, we
should first start searching for "ROW" expressions (define a group for
them) and think about a solution for the group.

It seems to me the most difficult thing is to notice problematic cases
where the transformations are incorrect, but I think it can be implemented.

Right. To be clear, I am sure that it won't be practical to come up
with a 100% theoretically pure approach. If for no other reason than
this: normalizing to CNF in all cases will run into problems with very
complex predicates. It might even be computationally intractable
(could just be very slow). So there is a clear need to keep
theoretical purity in balance with practical considerations. There is
a need for some kind of negotiation between those two things. Probably
some set of heuristics will ultimately be required to keep costs and
benefits in balance.

I don't expect you to determine what set of heuristics will ultimately
be required to determine when and how to perform CNF conversions, in
the general case. But having at least some vague idea seems like it
might increase confidence in your design.

I agree, but I think this will be the second step after solutions are
found.

Do you think that this problem is just an accidental side-effect? It
isn't necessarily the responsibility of your patch to fix such things.
If it's even possible for selectivity estimates to change, then it's
already certain that sometimes they'll be worse than before -- if only
because of chance interactions. The optimizer is often right for the
wrong reasons, and wrong for the right reasons -- we cannot really
expect any patch to completely avoid problems like that.

To be honest, I tried to fix it many times by calling the function to
calculate selectivity, and each time the result of the estimate did not
change. I didn't have any problems in this part after moving the
transformation to the parsing stage. I even tried to perform this
transformation at the planning stage (to the preprocess_qual_conditions
function), but I ran into the same problem there as well.

To tell the truth, I think I'm ready to investigate this problem again
(maybe I'll be able to see it differently or really find that I missed
something in previous times).

--
Regards,
Alena Rybakina
Postgres Professional

In reply to: Alena Rybakina (#58)
Re: POC, WIP: OR-clause support for indexes

On Thu, Aug 3, 2023 at 12:47 PM Alena Rybakina <lena.ribackina@yandex.ru> wrote:

It's all right. I understand your position)

Okay, good to know. :-)

I also agree to try to find other optimization cases and generalize them.

Good idea. Since the real goal is to "get a working flow of
information", the practical value of trying to get it working with
other clauses seems to be of secondary importance.

To be honest, I tried to fix it many times by calling the function to
calculate selectivity, and each time the result of the estimate did not
change. I didn't have any problems in this part after moving the
transformation to the parsing stage. I even tried to perform this
transformation at the planning stage (to the preprocess_qual_conditions
function), but I ran into the same problem there as well.

To tell the truth, I think I'm ready to investigate this problem again
(maybe I'll be able to see it differently or really find that I missed
something in previous times).

The optimizer will itself do a limited form of "normalizing to CNF".
Are you familiar with extract_restriction_or_clauses(), from
orclauses.c? Comments above the function have an example of how this
can work:

* Although a join clause must reference multiple relations overall,
* an OR of ANDs clause might contain sub-clauses that reference just one
* relation and can be used to build a restriction clause for that rel.
* For example consider
* WHERE ((a.x = 42 AND b.y = 43) OR (a.x = 44 AND b.z = 45));
* We can transform this into
* WHERE ((a.x = 42 AND b.y = 43) OR (a.x = 44 AND b.z = 45))
* AND (a.x = 42 OR a.x = 44)
* AND (b.y = 43 OR b.z = 45);
* which allows the latter clauses to be applied during the scans of a and b,
* perhaps as index qualifications, and in any case reducing the number of
* rows arriving at the join. In essence this is a partial transformation to
* CNF (AND of ORs format). It is not complete, however, because we do not
* unravel the original OR --- doing so would usually bloat the qualification
* expression to little gain.

Of course this immediately makes me wonder: shouldn't your patch be
able to perform an additional transformation here? You know, by
transforming "a.x = 42 OR a.x = 44" into "a IN (42, 44)"? Although I
haven't checked for myself, I assume that this doesn't happen right
now, since your patch currently performs all of its transformations
during parsing.

I also noticed that the same comment block goes on to say something
about "clauselist_selectivity's inability to recognize redundant
conditions". Perhaps that is relevant to the problems you were having
with selectivity estimation, back when the code was in
preprocess_qual_conditions() instead? I have no reason to believe that
there should be any redundancy left behind by your transformation, so
this is just one possibility to consider.

Separately, the commit message of commit 25a9e54d2d says something
about how the planner builds RestrictInfos, which seems
possibly-relevant. That commit enhanced extended statistics for OR
clauses, so the relevant paragraph describes a limitation of extended
statistics with OR clauses specifically. I'm just guessing, but it
still seems like it might be relevant to the problem you ran into with
selectivity estimation. Another possibility to consider.

BTW, I sometimes use RR to help improve my understanding of the planner:

https://wiki.postgresql.org/wiki/Getting_a_stack_trace_of_a_running_PostgreSQL_backend_on_Linux/BSD#Recording_Postgres_using_rr_Record_and_Replay_Framework

The planner has particularly complicated control flow, which has
unique challenges -- just knowing where to begin can be difficult
(unlike most other areas). I find that setting watchpoints to see when
and where the planner modifies state using RR is far more useful than
it would be with regular GDB. Once I record a query, I find that I can
"map out" what happens in the planner relatively easily.

--
Peter Geoghegan

In reply to: Peter Geoghegan (#59)
Re: POC, WIP: OR-clause support for indexes

On Sat, Aug 5, 2023 at 7:01 PM Peter Geoghegan <pg@bowt.ie> wrote:

Of course this immediately makes me wonder: shouldn't your patch be
able to perform an additional transformation here? You know, by
transforming "a.x = 42 OR a.x = 44" into "a IN (42, 44)"? Although I
haven't checked for myself, I assume that this doesn't happen right
now, since your patch currently performs all of its transformations
during parsing.

Many interesting cases won't get SAOP transformation from the patch,
simply because of the or_transform_limit GUC's default of 500. I don't
think that that design makes too much sense. It made more sense back
when the focus was on expression evaluation overhead. But that's only
one of the benefits that we now expect from the patch, right? So it
seems like something that should be revisited soon.

I'm not suggesting that there is no need for some kind of limit. But
it seems like a set of heuristics might be a better approach. Although
I would like to get a better sense of the costs of the transformation
to be able to say too much more.

--
Peter Geoghegan

#61Alena Rybakina
lena.ribackina@yandex.ru
In reply to: Peter Geoghegan (#59)
Re: POC, WIP: OR-clause support for indexes

Hi! Thank you for your research, I'm sure it will help me to fix the
problem of calculating selectivity faster)
I'm sorry I didn't answer right away, to be honest, I had a full diary
of urgent matters at work. For this reason, I didn't have enough time to
work on this patch properly.

The optimizer will itself do a limited form of "normalizing to CNF".
Are you familiar with extract_restriction_or_clauses(), from
orclauses.c? Comments above the function have an example of how this
can work:

* Although a join clause must reference multiple relations overall,
* an OR of ANDs clause might contain sub-clauses that reference just one
* relation and can be used to build a restriction clause for that rel.
* For example consider
* WHERE ((a.x = 42 AND b.y = 43) OR (a.x = 44 AND b.z = 45));
* We can transform this into
* WHERE ((a.x = 42 AND b.y = 43) OR (a.x = 44 AND b.z = 45))
* AND (a.x = 42 OR a.x = 44)
* AND (b.y = 43 OR b.z = 45);
* which allows the latter clauses to be applied during the scans of a and b,
* perhaps as index qualifications, and in any case reducing the number of
* rows arriving at the join. In essence this is a partial transformation to
* CNF (AND of ORs format). It is not complete, however, because we do not
* unravel the original OR --- doing so would usually bloat the qualification
* expression to little gain.

This is an interesting feature. I didn't notice this function before, I
studied many times consider_new_or_cause, which were called there. As
far as I know, there is a selectivity calculation going on there, but as
far as I remember, I called it earlier after my conversion, and
unfortunately it didn't solve my problem with calculating selectivity.
I'll reconsider it again, maybe I can find something I missed.

Of course this immediately makes me wonder: shouldn't your patch be
able to perform an additional transformation here? You know, by
transforming "a.x = 42 OR a.x = 44" into "a IN (42, 44)"? Although I
haven't checked for myself, I assume that this doesn't happen right
now, since your patch currently performs all of its transformations
during parsing.

I also noticed that the same comment block goes on to say something
about "clauselist_selectivity's inability to recognize redundant
conditions". Perhaps that is relevant to the problems you were having
with selectivity estimation, back when the code was in
preprocess_qual_conditions() instead? I have no reason to believe that
there should be any redundancy left behind by your transformation, so
this is just one possibility to consider.
Separately, the commit message of commit 25a9e54d2d says something
about how the planner builds RestrictInfos, which seems
possibly-relevant. That commit enhanced extended statistics for OR
clauses, so the relevant paragraph describes a limitation of extended
statistics with OR clauses specifically. I'm just guessing, but it
still seems like it might be relevant to the problem you ran into with
selectivity estimation. Another possibility to consider.

I understood what is said about AND clauses in this comment. It seems to
me that AND clauses saved like (BoolExpr *) expr->args->(RestrictInfo *)
clauseA->(RestrictInfo *)clauseB lists and OR clauses saved like
(BoolExpr *) expr -> orclause->(RestrictInfo *)clause A->(RestrictInfo
*)clause B.

As I understand it, selectivity is calculated for each expression. But
I'll exploring it deeper, because I think this place may contain the
answer to the question, what's wrong with selectivity calculation in my
patch.

BTW, I sometimes use RR to help improve my understanding of the planner:

https://wiki.postgresql.org/wiki/Getting_a_stack_trace_of_a_running_PostgreSQL_backend_on_Linux/BSD#Recording_Postgres_using_rr_Record_and_Replay_Framework
The planner has particularly complicated control flow, which has
unique challenges -- just knowing where to begin can be difficult
(unlike most other areas). I find that setting watchpoints to see when
and where the planner modifies state using RR is far more useful than
it would be with regular GDB. Once I record a query, I find that I can
"map out" what happens in the planner relatively easily.

Thank you for sharing this source! I didn't know about this before, and
it will definitely make my life easier to understand the optimizer.

I understand what you mean, and I researched the optimizer in a similar
way through gdb and looked at the comments and code in postgresql. This
is a complicated way and I didn't always understand correctly what this
variable was doing in this place, and this created some difficulties for me.

So, thank you for the link!

Many interesting cases won't get SAOP transformation from the patch,
simply because of the or_transform_limit GUC's default of 500. I don't
think that that design makes too much sense. It made more sense back
when the focus was on expression evaluation overhead. But that's only
one of the benefits that we now expect from the patch, right? So it
seems like something that should be revisited soon.

I'm not suggesting that there is no need for some kind of limit. But
it seems like a set of heuristics might be a better approach. Although
I would like to get a better sense of the costs of the transformation
to be able to say too much more.

Yes, this may be revised in the future after some transformations.
Initially, I was solving the problem described here [0]/messages/by-id/919bfbcb-f812-758d-d687-71f89f0d9a68@postgrespro.ru. So, after
testing [1]/messages/by-id/6b97b517-f36a-f0c6-3b3a-0cf8cfba220c@yandex.ru, I come to the conclusion that 500 is the ideal value for
or_transform_limit.

[0]: /messages/by-id/919bfbcb-f812-758d-d687-71f89f0d9a68@postgrespro.ru
/messages/by-id/919bfbcb-f812-758d-d687-71f89f0d9a68@postgrespro.ru

[1]: /messages/by-id/6b97b517-f36a-f0c6-3b3a-0cf8cfba220c@yandex.ru
/messages/by-id/6b97b517-f36a-f0c6-3b3a-0cf8cfba220c@yandex.ru

--
Regards,
Alena Rybakina
Postgres Professional

#62a.rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#61)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi, all!

The optimizer will itself do a limited form of "normalizing to CNF".
Are you familiar with extract_restriction_or_clauses(), from
orclauses.c? Comments above the function have an example of how this
can work:

  * Although a join clause must reference multiple relations overall,
  * an OR of ANDs clause might contain sub-clauses that reference
just one
  * relation and can be used to build a restriction clause for that rel.
  * For example consider
  *      WHERE ((a.x = 42 AND b.y = 43) OR (a.x = 44 AND b.z = 45));
  * We can transform this into
  *      WHERE ((a.x = 42 AND b.y = 43) OR (a.x = 44 AND b.z = 45))
  *          AND (a.x = 42 OR a.x = 44)
  *          AND (b.y = 43 OR b.z = 45);
  * which allows the latter clauses to be applied during the scans of
a and b,
  * perhaps as index qualifications, and in any case reducing the
number of
  * rows arriving at the join.  In essence this is a partial
transformation to
  * CNF (AND of ORs format).  It is not complete, however, because we
do not
  * unravel the original OR --- doing so would usually bloat the
qualification
  * expression to little gain.

This is an interesting feature. I didn't notice this function before,
I studied many times consider_new_or_cause, which were called there.
As far as I know, there is a selectivity calculation going on there,
but as far as I remember, I called it earlier after my conversion, and
unfortunately it didn't solve my problem with calculating selectivity.
I'll reconsider it again, maybe I can find something I missed.

Of course this immediately makes me wonder: shouldn't your patch be
able to perform an additional transformation here? You know, by
transforming "a.x = 42 OR a.x = 44" into "a IN (42, 44)"? Although I
haven't checked for myself, I assume that this doesn't happen right
now, since your patch currently performs all of its transformations
during parsing.

I also noticed that the same comment block goes on to say something
about "clauselist_selectivity's inability to recognize redundant
conditions". Perhaps that is relevant to the problems you were having
with selectivity estimation, back when the code was in
preprocess_qual_conditions() instead? I have no reason to believe that
there should be any redundancy left behind by your transformation, so
this is just one possibility to consider.
Separately, the commit message of commit 25a9e54d2d says something
about how the planner builds RestrictInfos, which seems
possibly-relevant. That commit enhanced extended statistics for OR
clauses, so the relevant paragraph describes a limitation of extended
statistics with OR clauses specifically. I'm just guessing, but it
still seems like it might be relevant to the problem you ran into with
selectivity estimation. Another possibility to consider.

I understood what is said about AND clauses in this comment. It seems
to me that AND clauses saved like (BoolExpr *)
expr->args->(RestrictInfo *) clauseA->(RestrictInfo *)clauseB lists
and OR clauses saved like (BoolExpr *) expr -> orclause->(RestrictInfo
*)clause A->(RestrictInfo *)clause B.

As I understand it, selectivity is calculated for each expression. But
I'll exploring it deeper, because I think this place may contain the
answer to the question, what's wrong with selectivity calculation in
my patch.

I could move transformation in there (extract_restriction_or_clauses)
and didn't have any problem with selectivity calculation, besides it
also works on the redundant or duplicates stage. So, it looks like:

CREATE TABLE tenk1 (unique1 int, unique2 int, ten int, hundred int);
insert into tenk1 SELECT x,x,x,x FROM generate_series(1,50000) as x;
CREATE INDEX a_idx1 ON tenk1(unique1); CREATE INDEX a_idx2 ON
tenk1(unique2); CREATE INDEX a_hundred ON tenk1(hundred);

explain analyze select * from tenk1 a join tenk1 b on ((a.unique2 = 3 or
a.unique2 = 7));

PLAN
------------------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.29..2033.62 rows=100000 width=32) (actual
time=0.090..60.258 rows=100000 loops=1) -> Seq Scan on tenk1 b
(cost=0.00..771.00 rows=50000 width=16) (actual time=0.016..9.747
rows=50000 loops=1) -> Materialize (cost=0.29..12.62 rows=2 width=16)
(actual time=0.000..0.000 rows=2 loops=50000) -> Index Scan using a_idx2
on tenk1 a (cost=0.29..12.62 rows=2 width=16) (actual time=0.063..0.068
rows=2 loops=1) Index Cond: (unique2 = ANY (ARRAY[3, 7])) Planning Time:
8.257 ms Execution Time: 64.453 ms (7 rows)

Overall, this was due to incorrectly defined types of elements in the
array, and if we had applied the transformation with the definition of
the tup operator, we could have avoided such problems (I used
make_scalar_array_op and have not yet found an alternative to this).

When I moved the transformation on the index creation stage, it couldn't
work properly and as a result I faced the same problem of selectivity
calculation. I supposed that the selectivity values are also used there,
and not recalculated all over again. perhaps we can solve this by
forcibly recalculating the selectivity values, but I foresee other
problems there.

explain analyze select * from tenk1 a join tenk1 b on ((a.unique2 = 3 or
a.unique2 = 7));

QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=12.58..312942.91 rows=24950000 width=32) (actual
time=0.040..47.582 rows=100000 loops=1) -> Seq Scan on tenk1 b
(cost=0.00..771.00 rows=50000 width=16) (actual time=0.009..7.039
rows=50000 loops=1) -> Materialize (cost=12.58..298.16 rows=499
width=16) (actual time=0.000..0.000 rows=2 loops=50000) -> Bitmap Heap
Scan on tenk1 a (cost=12.58..295.66 rows=499 width=16) (actual
time=0.025..0.028 rows=2 loops=1) Recheck Cond: ((unique2 = 3) OR
(unique2 = 7)) Heap Blocks: exact=1 -> BitmapOr (cost=12.58..12.58
rows=500 width=0) (actual time=0.023..0.024 rows=0 loops=1) -> Bitmap
Index Scan on a_idx2 (cost=0.00..6.17 rows=250 width=0) (actual
time=0.019..0.019 rows=1 loops=1) Index Cond: (unique2 = 3) -> Bitmap
Index Scan on a_idx2 (cost=0.00..6.17 rows=250 width=0) (actual
time=0.003..0.003 rows=1 loops=1) Index Cond: (unique2 = 7) Planning
Time: 0.401 ms Execution Time: 51.350 ms (13 rows)

I have attached a diff file so far, but it is very raw and did not pass
all regression tests (I attached regression.diff) and even had bad
conversion cases (some of the cases did not work at all, in other cases
there were no non-converted nodes). But now I see an interesting
transformation, which was the most interesting for me.

EXPLAIN (COSTS OFF) SELECT * FROM tenk1 WHERE thousand = 42 AND 
(tenthous = 1 OR tenthous = 3 OR tenthous = 42); - QUERY PLAN 
------------------------------------------------------------------------------------------------------------------------------------------ 
- Bitmap Heap Scan on tenk1 - Recheck Cond: (((thousand = 42) AND 
(tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 
42) AND (tenthous = 42))) - -> BitmapOr - -> Bitmap Index Scan on 
tenk1_thous_tenthous - Index Cond: ((thousand = 42) AND (tenthous = 1)) 
- -> Bitmap Index Scan on tenk1_thous_tenthous - Index Cond: ((thousand 
= 42) AND (tenthous = 3)) - -> Bitmap Index Scan on tenk1_thous_tenthous 
- Index Cond: ((thousand = 42) AND (tenthous = 42)) -(9 rows) + QUERY 
PLAN 
+------------------------------------------------------------------------ 
+ Index Scan using tenk1_thous_tenthous on tenk1 + Index Cond: 
((thousand = 42) AND (tenthous = ANY (ARRAY[1, 3, 42]))) +(2 rows)

Attachments:

regresssion.difftext/x-patch; charset=UTF-8; name=regresssion.diffDownload
diff -U3 /home/alena/postgrespro7/src/test/regress/expected/opr_sanity.out /home/alena/postgrespro7/src/test/regress/results/opr_sanity.out
--- /home/alena/postgrespro7/src/test/regress/expected/opr_sanity.out	2023-08-12 02:03:45.284074834 +0300
+++ /home/alena/postgrespro7/src/test/regress/results/opr_sanity.out	2023-08-17 00:00:22.793043910 +0300
@@ -47,10 +47,8 @@
 SELECT p1.oid, p1.proname
 FROM pg_proc as p1
 WHERE (prosrc = '' OR prosrc = '-') AND prosqlbody IS NULL;
- oid | proname 
------+---------
-(0 rows)
-
+ERROR:  could not determine which collation to use for string comparison
+HINT:  Use the COLLATE clause to set the collation explicitly.
 -- proretset should only be set for normal functions
 SELECT p1.oid, p1.proname
 FROM pg_proc AS p1
@@ -81,10 +79,8 @@
 SELECT p1.oid, p1.proname
 FROM pg_proc as p1
 WHERE prolang = 13 AND (probin IS NULL OR probin = '' OR probin = '-');
- oid | proname 
------+---------
-(0 rows)
-
+ERROR:  could not determine which collation to use for string comparison
+HINT:  Use the COLLATE clause to set the collation explicitly.
 SELECT p1.oid, p1.proname
 FROM pg_proc as p1
 WHERE prolang != 13 AND probin IS NOT NULL;
diff -U3 /home/alena/postgrespro7/src/test/regress/expected/create_index.out /home/alena/postgrespro7/src/test/regress/results/create_index.out
--- /home/alena/postgrespro7/src/test/regress/expected/create_index.out	2023-08-12 02:03:45.260074298 +0300
+++ /home/alena/postgrespro7/src/test/regress/results/create_index.out	2023-08-17 00:00:25.309060540 +0300
@@ -1838,18 +1838,11 @@
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                               QUERY PLAN                               
+------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, 3, 42])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,20 +1854,17 @@
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                 QUERY PLAN                                  
+-----------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY (ARRAY[42, 99])))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY (ARRAY[42, 99]))
+(8 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff -U3 /home/alena/postgrespro7/src/test/regress/expected/inherit.out /home/alena/postgrespro7/src/test/regress/results/inherit.out
--- /home/alena/postgrespro7/src/test/regress/expected/inherit.out	2023-08-12 02:03:29.411719453 +0300
+++ /home/alena/postgrespro7/src/test/regress/results/inherit.out	2023-08-17 00:00:26.781070266 +0300
@@ -1929,7 +1929,7 @@
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff -U3 /home/alena/postgrespro7/src/test/regress/expected/misc.out /home/alena/postgrespro7/src/test/regress/results/misc.out
--- /home/alena/postgrespro7/src/test/regress/expected/misc.out	2023-08-12 02:03:29.439720081 +0300
+++ /home/alena/postgrespro7/src/test/regress/results/misc.out	2023-08-17 00:00:37.729142525 +0300
@@ -99,10 +99,14 @@
    SELECT 'posthacking', p.name
    FROM person* p
    WHERE p.name = 'mike' or p.name = 'jeff';
+ERROR:  could not determine which collation to use for string comparison
+HINT:  Use the COLLATE clause to set the collation explicitly.
 INSERT INTO hobbies_r (name, person)
    SELECT 'basketball', p.name
    FROM person p
    WHERE p.name = 'joe' or p.name = 'sally';
+ERROR:  could not determine which collation to use for string comparison
+HINT:  Use the COLLATE clause to set the collation explicitly.
 INSERT INTO hobbies_r (name) VALUES ('skywalking');
 INSERT INTO equipment_r (name, hobby) VALUES ('advil', 'posthacking');
 INSERT INTO equipment_r (name, hobby) VALUES ('peet''s coffee', 'posthacking');
@@ -163,24 +167,17 @@
 -- everyone else does nothing.
 --
 SELECT p.name, name(p.hobbies) FROM ONLY person p;
- name  |    name     
--------+-------------
- mike  | posthacking
- joe   | basketball
- sally | basketball
-(3 rows)
+ name | name 
+------+------
+(0 rows)
 
 --
 -- as above, but jeff also does post_hacking.
 --
 SELECT p.name, name(p.hobbies) FROM person* p;
- name  |    name     
--------+-------------
- mike  | posthacking
- joe   | basketball
- sally | basketball
- jeff  | posthacking
-(4 rows)
+ name | name 
+------+------
+(0 rows)
 
 --
 -- the next two queries demonstrate how functions generate bogus duplicates.
@@ -188,25 +185,16 @@
 --
 SELECT DISTINCT hobbies_r.name, name(hobbies_r.equipment) FROM hobbies_r
   ORDER BY 1,2;
-    name     |     name      
--------------+---------------
- basketball  | hightops
- posthacking | advil
- posthacking | peet's coffee
- skywalking  | guts
-(4 rows)
+    name    | name 
+------------+------
+ skywalking | guts
+(1 row)
 
 SELECT hobbies_r.name, (hobbies_r.equipment).name FROM hobbies_r;
-    name     |     name      
--------------+---------------
- posthacking | advil
- posthacking | peet's coffee
- posthacking | advil
- posthacking | peet's coffee
- basketball  | hightops
- basketball  | hightops
- skywalking  | guts
-(7 rows)
+    name    | name 
+------------+------
+ skywalking | guts
+(1 row)
 
 --
 -- mike needs advil and peet's coffee,
@@ -214,71 +202,41 @@
 -- everyone else is fine.
 --
 SELECT p.name, name(p.hobbies), name(equipment(p.hobbies)) FROM ONLY person p;
- name  |    name     |     name      
--------+-------------+---------------
- mike  | posthacking | advil
- mike  | posthacking | peet's coffee
- joe   | basketball  | hightops
- sally | basketball  | hightops
-(4 rows)
+ name | name | name 
+------+------+------
+(0 rows)
 
 --
 -- as above, but jeff needs advil and peet's coffee as well.
 --
 SELECT p.name, name(p.hobbies), name(equipment(p.hobbies)) FROM person* p;
- name  |    name     |     name      
--------+-------------+---------------
- mike  | posthacking | advil
- mike  | posthacking | peet's coffee
- joe   | basketball  | hightops
- sally | basketball  | hightops
- jeff  | posthacking | advil
- jeff  | posthacking | peet's coffee
-(6 rows)
+ name | name | name 
+------+------+------
+(0 rows)
 
 --
 -- just like the last two, but make sure that the target list fixup and
 -- unflattening is being done correctly.
 --
 SELECT name(equipment(p.hobbies)), p.name, name(p.hobbies) FROM ONLY person p;
-     name      | name  |    name     
----------------+-------+-------------
- advil         | mike  | posthacking
- peet's coffee | mike  | posthacking
- hightops      | joe   | basketball
- hightops      | sally | basketball
-(4 rows)
+ name | name | name 
+------+------+------
+(0 rows)
 
 SELECT (p.hobbies).equipment.name, p.name, name(p.hobbies) FROM person* p;
-     name      | name  |    name     
----------------+-------+-------------
- advil         | mike  | posthacking
- peet's coffee | mike  | posthacking
- hightops      | joe   | basketball
- hightops      | sally | basketball
- advil         | jeff  | posthacking
- peet's coffee | jeff  | posthacking
-(6 rows)
+ name | name | name 
+------+------+------
+(0 rows)
 
 SELECT (p.hobbies).equipment.name, name(p.hobbies), p.name FROM ONLY person p;
-     name      |    name     | name  
----------------+-------------+-------
- advil         | posthacking | mike
- peet's coffee | posthacking | mike
- hightops      | basketball  | joe
- hightops      | basketball  | sally
-(4 rows)
+ name | name | name 
+------+------+------
+(0 rows)
 
 SELECT name(equipment(p.hobbies)), name(p.hobbies), p.name FROM person* p;
-     name      |    name     | name  
----------------+-------------+-------
- advil         | posthacking | mike
- peet's coffee | posthacking | mike
- hightops      | basketball  | joe
- hightops      | basketball  | sally
- advil         | posthacking | jeff
- peet's coffee | posthacking | jeff
-(6 rows)
+ name | name | name 
+------+------+------
+(0 rows)
 
 SELECT name(equipment(hobby_construct(text 'skywalking', text 'mer')));
  name 
@@ -334,7 +292,7 @@
 SELECT hobbies_by_name('basketball');
  hobbies_by_name 
 -----------------
- joe
+ 
 (1 row)
 
 SELECT name, overpaid(emp.*) FROM emp;
@@ -364,28 +322,16 @@
 (1 row)
 
 SELECT *, name(equipment(h.*)) FROM hobbies_r h;
-    name     | person |     name      
--------------+--------+---------------
- posthacking | mike   | advil
- posthacking | mike   | peet's coffee
- posthacking | jeff   | advil
- posthacking | jeff   | peet's coffee
- basketball  | joe    | hightops
- basketball  | sally  | hightops
- skywalking  |        | guts
-(7 rows)
+    name    | person | name 
+------------+--------+------
+ skywalking |        | guts
+(1 row)
 
 SELECT *, (equipment(CAST((h.*) AS hobbies_r))).name FROM hobbies_r h;
-    name     | person |     name      
--------------+--------+---------------
- posthacking | mike   | advil
- posthacking | mike   | peet's coffee
- posthacking | jeff   | advil
- posthacking | jeff   | peet's coffee
- basketball  | joe    | hightops
- basketball  | sally  | hightops
- skywalking  |        | guts
-(7 rows)
+    name    | person | name 
+------------+--------+------
+ skywalking |        | guts
+(1 row)
 
 --
 -- functional joins
diff -U3 /home/alena/postgrespro7/src/test/regress/expected/tidscan.out /home/alena/postgrespro7/src/test/regress/results/tidscan.out
--- /home/alena/postgrespro7/src/test/regress/expected/tidscan.out	2023-08-12 02:03:29.511721694 +0300
+++ /home/alena/postgrespro7/src/test/regress/results/tidscan.out	2023-08-17 00:00:37.521141153 +0300
@@ -46,7 +46,7 @@
                           QUERY PLAN                          
 --------------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY (ARRAY['(0,2)'::tid, '(0,1)'::tid]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
diff -U3 /home/alena/postgrespro7/src/test/regress/expected/stats_ext.out /home/alena/postgrespro7/src/test/regress/results/stats_ext.out
--- /home/alena/postgrespro7/src/test/regress/expected/stats_ext.out	2023-08-12 02:03:45.320075639 +0300
+++ /home/alena/postgrespro7/src/test/regress/results/stats_ext.out	2023-08-17 00:00:41.165165174 +0300
@@ -1160,17 +1160,13 @@
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
- estimated | actual 
------------+--------
-         4 |    100
-(1 row)
-
+ERROR:  could not determine which collation to use for string comparison
+HINT:  Use the COLLATE clause to set the collation explicitly.
+CONTEXT:  PL/pgSQL function check_estimated_rows(text) line 7 at FOR over EXECUTE statement
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
- estimated | actual 
------------+--------
-         8 |    200
-(1 row)
-
+ERROR:  could not determine which collation to use for string comparison
+HINT:  Use the COLLATE clause to set the collation explicitly.
+CONTEXT:  PL/pgSQL function check_estimated_rows(text) line 7 at FOR over EXECUTE statement
 -- OR clauses referencing different attributes
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR b = ''1'') AND b = ''1''');
  estimated | actual 
@@ -1322,21 +1318,17 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
- estimated | actual 
------------+--------
-        99 |    100
-(1 row)
-
+ERROR:  could not determine which collation to use for string comparison
+HINT:  Use the COLLATE clause to set the collation explicitly.
+CONTEXT:  PL/pgSQL function check_estimated_rows(text) line 7 at FOR over EXECUTE statement
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
- estimated | actual 
------------+--------
-       197 |    200
-(1 row)
-
+ERROR:  could not determine which collation to use for string comparison
+HINT:  Use the COLLATE clause to set the collation explicitly.
+CONTEXT:  PL/pgSQL function check_estimated_rows(text) line 7 at FOR over EXECUTE statement
 -- OR clauses referencing different attributes are incompatible
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR b = ''1'') AND b = ''1''');
  estimated | actual 
@@ -1501,17 +1493,13 @@
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
- estimated | actual 
------------+--------
-         1 |    100
-(1 row)
-
+ERROR:  could not determine which collation to use for string comparison
+HINT:  Use the COLLATE clause to set the collation explicitly.
+CONTEXT:  PL/pgSQL function check_estimated_rows(text) line 7 at FOR over EXECUTE statement
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
- estimated | actual 
------------+--------
-         1 |    200
-(1 row)
-
+ERROR:  could not determine which collation to use for string comparison
+HINT:  Use the COLLATE clause to set the collation explicitly.
+CONTEXT:  PL/pgSQL function check_estimated_rows(text) line 7 at FOR over EXECUTE statement
 -- OR clauses referencing different attributes
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR upper(b) = ''1'') AND upper(b) = ''1''');
  estimated | actual 
@@ -1664,21 +1652,17 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
- estimated | actual 
------------+--------
-        99 |    100
-(1 row)
-
+ERROR:  could not determine which collation to use for string comparison
+HINT:  Use the COLLATE clause to set the collation explicitly.
+CONTEXT:  PL/pgSQL function check_estimated_rows(text) line 7 at FOR over EXECUTE statement
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
- estimated | actual 
------------+--------
-       197 |    200
-(1 row)
-
+ERROR:  could not determine which collation to use for string comparison
+HINT:  Use the COLLATE clause to set the collation explicitly.
+CONTEXT:  PL/pgSQL function check_estimated_rows(text) line 7 at FOR over EXECUTE statement
 -- OR clauses referencing different attributes
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR upper(b) = ''1'') AND upper(b) = ''1''');
  estimated | actual 
diff -U3 /home/alena/postgrespro7/src/test/regress/expected/partition_join.out /home/alena/postgrespro7/src/test/regress/results/partition_join.out
--- /home/alena/postgrespro7/src/test/regress/expected/partition_join.out	2023-08-12 02:03:45.288074924 +0300
+++ /home/alena/postgrespro7/src/test/regress/results/partition_join.out	2023-08-17 00:00:51.173231068 +0300
@@ -290,13 +290,13 @@
 -- Currently we can't do partitioned join if nullable-side partitions are pruned
 EXPLAIN (COSTS OFF)
 SELECT t1.a, t1.c, t2.b, t2.c FROM (SELECT * FROM prt1 WHERE a < 450) t1 FULL JOIN (SELECT * FROM prt2 WHERE b > 250) t2 ON t1.a = t2.b WHERE t1.b = 0 OR t2.a = 0 ORDER BY t1.a, t2.b;
-                     QUERY PLAN                     
-----------------------------------------------------
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
  Sort
    Sort Key: prt1.a, prt2.b
    ->  Hash Full Join
          Hash Cond: (prt1.a = prt2.b)
-         Filter: ((prt1.b = 0) OR (prt2.a = 0))
+         Filter: (((prt1.b = 0) OR (prt2.a = 0)) AND ((prt1.b = 0) OR (prt2.a = 0)))
          ->  Append
                ->  Seq Scan on prt1_p1 prt1_1
                      Filter: (a < 450)
@@ -2270,10 +2270,11 @@
 where not exists (select 1 from prtx2
                   where prtx2.a=prtx1.a and (prtx2.b=prtx1.b+1 or prtx2.c=99))
   and a<20 and c=91;
-                           QUERY PLAN                            
------------------------------------------------------------------
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
  Append
    ->  Nested Loop Anti Join
+         Join Filter: ((prtx2_1.b = (prtx1_1.b + 1)) OR (prtx2_1.c = 99))
          ->  Seq Scan on prtx1_1
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_1
@@ -2285,6 +2286,7 @@
                      ->  Bitmap Index Scan on prtx2_1_c_idx
                            Index Cond: (c = 99)
    ->  Nested Loop Anti Join
+         Join Filter: ((prtx2_2.b = (prtx1_2.b + 1)) OR (prtx2_2.c = 99))
          ->  Seq Scan on prtx1_2
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_2
@@ -2295,7 +2297,7 @@
                            Index Cond: (b = (prtx1_2.b + 1))
                      ->  Bitmap Index Scan on prtx2_2_c_idx
                            Index Cond: (c = 99)
-(23 rows)
+(25 rows)
 
 select * from prtx1
 where not exists (select 1 from prtx2
diff -U3 /home/alena/postgrespro7/src/test/regress/expected/partition_prune.out /home/alena/postgrespro7/src/test/regress/results/partition_prune.out
--- /home/alena/postgrespro7/src/test/regress/expected/partition_prune.out	2023-08-12 02:03:45.292075013 +0300
+++ /home/alena/postgrespro7/src/test/regress/results/partition_prune.out	2023-08-17 00:00:50.777228463 +0300
@@ -82,24 +82,38 @@
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
-(5 rows)
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_ef lp_3
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_g lp_4
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_null lp_5
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_default lp_6
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(13 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
-(5 rows)
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_ef lp_3
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_g lp_4
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_default lp_5
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(11 rows)
 
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
@@ -515,11 +529,13 @@
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
- Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
-(2 rows)
+                   QUERY PLAN                   
+------------------------------------------------
+ Append
+   Subplans Removed: 1
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (a = ANY ('{1,7}'::integer[]))
+(4 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
                       QUERY PLAN                       
@@ -596,14 +612,15 @@
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
+   Subplans Removed: 2
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
-(5 rows)
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(6 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
         QUERY PLAN        
@@ -1933,10 +1950,10 @@
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
@@ -2265,11 +2282,11 @@
          Workers Launched: N
          ->  Parallel Append (actual rows=N loops=N)
                ->  Parallel Seq Scan on ab_a1_b2 ab_1 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a2_b2 ab_2 (never executed)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a3_b2 ab_3 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
+                     Filter: ((a = ANY (ARRAY[$0, $1])) AND (b = 2))
 (16 rows)
 
 -- Test pruning during parallel nested loop query
@@ -3408,14 +3425,11 @@
 (2 rows)
 
 explain (costs off) select * from pp_arrpart where a in ('{4, 5}', '{1}');
-                              QUERY PLAN                              
-----------------------------------------------------------------------
- Append
-   ->  Seq Scan on pp_arrpart1 pp_arrpart_1
-         Filter: ((a = '{4,5}'::integer[]) OR (a = '{1}'::integer[]))
-   ->  Seq Scan on pp_arrpart2 pp_arrpart_2
-         Filter: ((a = '{4,5}'::integer[]) OR (a = '{1}'::integer[]))
-(5 rows)
+             QUERY PLAN             
+------------------------------------
+ Seq Scan on pp_arrpart2 pp_arrpart
+   Filter: (a = '{4,5}'::integer[])
+(2 rows)
 
 explain (costs off) update pp_arrpart set a = a where a = '{1}';
                  QUERY PLAN                 
@@ -3464,14 +3478,11 @@
 (2 rows)
 
 explain (costs off) select * from pph_arrpart where a in ('{4, 5}', '{1}');
-                              QUERY PLAN                              
-----------------------------------------------------------------------
- Append
-   ->  Seq Scan on pph_arrpart1 pph_arrpart_1
-         Filter: ((a = '{4,5}'::integer[]) OR (a = '{1}'::integer[]))
-   ->  Seq Scan on pph_arrpart2 pph_arrpart_2
-         Filter: ((a = '{4,5}'::integer[]) OR (a = '{1}'::integer[]))
-(5 rows)
+              QUERY PLAN              
+--------------------------------------
+ Seq Scan on pph_arrpart1 pph_arrpart
+   Filter: (a = '{4,5}'::integer[])
+(2 rows)
 
 drop table pph_arrpart;
 -- enum type list partition key
diff_fix_sel.difftext/x-patch; charset=UTF-8; name=diff_fix_sel.diffDownload
diff --git a/src/backend/optimizer/path/clausesel.c b/src/backend/optimizer/path/clausesel.c
index 435438a1735..9c82297e242 100644
--- a/src/backend/optimizer/path/clausesel.c
+++ b/src/backend/optimizer/path/clausesel.c
@@ -751,7 +751,8 @@ clause_selectivity_ext(PlannerInfo *root,
 		 * so that per-subclause selectivities can be cached.
 		 */
 		if (rinfo->orclause)
-			clause = (Node *) rinfo->orclause;
+			{clause = (Node *) rinfo->orclause;
+			}
 		else
 			clause = (Node *) rinfo->clause;
 	}
@@ -823,6 +824,7 @@ clause_selectivity_ext(PlannerInfo *root,
 		 * Almost the same thing as clauselist_selectivity, but with the
 		 * clauses connected by OR.
 		 */
+
 		s1 = clauselist_selectivity_or(root,
 									   ((BoolExpr *) clause)->args,
 									   varRelid,
diff --git a/src/backend/optimizer/util/orclauses.c b/src/backend/optimizer/util/orclauses.c
index 6ef9d14b902..81b11865203 100644
--- a/src/backend/optimizer/util/orclauses.c
+++ b/src/backend/optimizer/util/orclauses.c
@@ -22,6 +22,10 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/orclauses.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 
 
 static bool is_safe_restriction_clause_for(RestrictInfo *rinfo, RelOptInfo *rel);
@@ -29,6 +33,300 @@ static Expr *extract_or_clause(RestrictInfo *or_rinfo, RelOptInfo *rel);
 static void consider_new_or_clause(PlannerInfo *root, RelOptInfo *rel,
 								   Expr *orclause, RestrictInfo *join_or_rinfo);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				collation;
+	Oid				opno;
+	RestrictInfo   *rinfo;
+	Expr *expr;
+} OrClauseGroupEntry;
+
+/*
+ * Pass through baserestrictinfo clauses and try to convert OR clauses into IN
+ * Return a modified clause list or just the same baserestrictinfo, if no
+ * changes have made.
+ * XXX: do not change source list of clauses at all.
+ */
+static List *
+transform_ors(PlannerInfo *root, List *baserestrictinfo)
+{
+	ListCell   *lc;
+	ListCell   *lc_cp;
+	List	   *modified_rinfo = NIL;
+	bool		something_changed = false;
+	List	   *baserestrictinfo_origin = list_copy(baserestrictinfo);
+
+	/*
+	 * Complexity of a clause could be arbitrarily sophisticated. Here, we will
+	 * look up only on the top level of clause list.
+	 * XXX: It is substantiated? Could we change something here?
+	 */
+	forboth (lc, baserestrictinfo, lc_cp, baserestrictinfo_origin)
+	{
+		RestrictInfo   *rinfo = lfirst_node(RestrictInfo, lc);
+		RestrictInfo   *rinfo_base = lfirst_node(RestrictInfo, lc_cp);
+		List		   *or_list = NIL;
+		ListCell	   *lc_eargs,
+					   *lc_rargs,
+					   *lc_args;
+		List		   *groups_list = NIL;
+
+		if (!restriction_is_or_clause(rinfo))
+		{
+			/* Add a clause without changes */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		/*
+		 * NOTE:
+		 * It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		 * a list of sub-restrictinfo args, and rinfo->clause - which is the
+		 * same expression, made from bare clauses. To not break selectivity
+		 * caches and other optimizations, use both:
+		 * - use rinfos from orclause if no transformation needed
+		 * - use  bare quals from rinfo->clause in the case of transformation,
+		 * to create new RestrictInfo: in this case we have no options to avoid
+		 * selectivity estimation procedure.
+		 */
+		forboth(lc_eargs, ((BoolExpr *) rinfo->clause)->args,
+				lc_rargs, ((BoolExpr *) rinfo->orclause)->args)
+		{
+			Expr			   *bare_orarg = (Expr *) lfirst(lc_eargs);
+			RestrictInfo	   *sub_rinfo;
+			Node			   *const_expr;
+			Node			   *non_const_expr;
+			ListCell		   *lc_groups;
+			OrClauseGroupEntry *gentry;
+			Oid					opno;
+
+			/* It may be one more boolean expression, skip it for now */
+			if (!IsA(lfirst(lc_rargs), RestrictInfo))
+			{
+				or_list = lappend(or_list, (void *) bare_orarg);
+				continue;
+			}
+
+			sub_rinfo = lfirst_node(RestrictInfo, lc_rargs);
+
+			/* Check: it is an expr of the form 'F(x) oper ConstExpr' */
+			if (!IsA(bare_orarg, OpExpr) ||
+				!(bms_is_empty(sub_rinfo->left_relids) ^
+				bms_is_empty(sub_rinfo->right_relids)) ||
+				contain_volatile_functions((Node *) bare_orarg))
+			{
+				/* Again, it's not the expr we can transform */
+				or_list = lappend(or_list, (void *) bare_orarg);
+				continue;
+			}
+
+			/* Get pointers to constant and expression sides of the clause */
+			const_expr =bms_is_empty(sub_rinfo->left_relids) ?
+												get_leftop(sub_rinfo->clause) :
+												get_rightop(sub_rinfo->clause);
+			non_const_expr = bms_is_empty(sub_rinfo->left_relids) ?
+												get_rightop(sub_rinfo->clause) :
+												get_leftop(sub_rinfo->clause);
+
+			opno = ((OpExpr *) sub_rinfo->clause)->opno;
+			if (!op_mergejoinable(opno, exprType(non_const_expr)))
+			{
+				/* And again, filter out non-equality operators */
+				or_list = lappend(or_list, (void *) bare_orarg);
+				continue;
+			}
+
+			/*
+			 * At this point we definitely have a transformable clause.
+			 * Classify it and add into specific group of clauses, or create new
+			 * group.
+			 * TODO: to manage complexity in the case of many different clauses
+			 * (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			 * like a hash table (htab key ???).
+			 */
+			foreach(lc_groups, groups_list)
+			{
+				OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+				Assert(v->node != NULL);
+
+				if (equal(v->node, non_const_expr))
+				{
+					v->consts = lappend(v->consts, const_expr);
+					non_const_expr = NULL;
+					break;
+				}
+			}
+
+			if (non_const_expr == NULL)
+				/*
+				 * The clause classified successfully and added into existed
+				 * clause group.
+				 */
+				continue;
+
+			/* New clause group needed */
+			gentry = palloc(sizeof(OrClauseGroupEntry));
+			gentry->node = non_const_expr;
+			gentry->consts = list_make1(const_expr);
+			gentry->collation = exprInputCollation((Node *)sub_rinfo->clause);
+			gentry->opno = opno;
+			gentry->rinfo = sub_rinfo;
+			gentry->expr = bare_orarg;
+			groups_list = lappend(groups_list,  (void *) gentry);
+		}
+
+		if (groups_list == NIL)
+		{
+			/*
+			 * No any transformations possible with this rinfo, just add itself
+			 * to the list and go further.
+			 */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		 * Go through the list of groups and convert each, where number of
+		 * consts more than 1. trivial groups move to OR-list again
+		 */
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(NULL, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(NULL,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		/*
+		 * Make a new version of the restriction. Remember source restriction
+		 * can be used in another path (SeqScan, for example).
+		 */
+
+		/* One more trick: assemble correct clause */
+		rinfo = make_restrictinfo(root,
+				  list_length(or_list) > 1 ? make_orclause(or_list) :
+											 (Expr *) linitial(or_list),
+				  rinfo->is_pushed_down,
+				  rinfo->has_clone,
+				  rinfo->is_clone,
+				  rinfo->pseudoconstant,
+				  rinfo->security_level,
+				  rinfo->required_relids,
+				  rinfo->incompatible_relids,
+				  rinfo->outer_relids);
+		rinfo->eval_cost=rinfo_base->eval_cost;
+		rinfo->norm_selec=rinfo_base->norm_selec;
+		rinfo->outer_selec=rinfo_base->outer_selec;
+		rinfo->left_bucketsize=rinfo_base->left_bucketsize;
+		rinfo->right_bucketsize=rinfo_base->right_bucketsize;
+		rinfo->left_mcvfreq=rinfo_base->left_mcvfreq;
+		rinfo->right_mcvfreq=rinfo_base->right_mcvfreq;
+
+		modified_rinfo = lappend(modified_rinfo, rinfo);
+		list_free_deep(groups_list);
+		something_changed = true;
+	}
+
+	/*
+	 * Check if transformation has made. If nothing changed - return
+	 * baserestrictinfo as is.
+	 */
+	if (something_changed)
+	{
+		return modified_rinfo;
+	}
+
+	list_free(modified_rinfo);
+	return baserestrictinfo;
+}
 
 /*
  * extract_restriction_or_clauses
@@ -93,6 +391,10 @@ extract_restriction_or_clauses(PlannerInfo *root)
 		if (rel->reloptkind != RELOPT_BASEREL)
 			continue;
 
+		if (rel->reloptkind == RELOPT_BASEREL)
+		rel->baserestrictinfo  = transform_ors(root, rel->baserestrictinfo);
+		rel->joininfo = transform_ors(root, rel->joininfo);
+
 		/*
 		 * Find potentially interesting OR joinclauses.  We can use any
 		 * joinclause that is considered safe to move to this rel by the
#63a.rybakina
a.rybakina@postgrespro.ru
In reply to: a.rybakina (#62)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Sorry, I didn't write correctly enough, about the second second place in
the code where the conversion works well enough is the removal of
duplicate OR expressions.

I attached patch to learn it in more detail.

Show quoted text

On 17.08.2023 13:08, a.rybakina wrote:

Hi, all!

The optimizer will itself do a limited form of "normalizing to CNF".
Are you familiar with extract_restriction_or_clauses(), from
orclauses.c? Comments above the function have an example of how this
can work:

  * Although a join clause must reference multiple relations overall,
  * an OR of ANDs clause might contain sub-clauses that reference
just one
  * relation and can be used to build a restriction clause for that
rel.
  * For example consider
  *      WHERE ((a.x = 42 AND b.y = 43) OR (a.x = 44 AND b.z = 45));
  * We can transform this into
  *      WHERE ((a.x = 42 AND b.y = 43) OR (a.x = 44 AND b.z = 45))
  *          AND (a.x = 42 OR a.x = 44)
  *          AND (b.y = 43 OR b.z = 45);
  * which allows the latter clauses to be applied during the scans
of a and b,
  * perhaps as index qualifications, and in any case reducing the
number of
  * rows arriving at the join.  In essence this is a partial
transformation to
  * CNF (AND of ORs format).  It is not complete, however, because
we do not
  * unravel the original OR --- doing so would usually bloat the
qualification
  * expression to little gain.

This is an interesting feature. I didn't notice this function before,
I studied many times consider_new_or_cause, which were called there.
As far as I know, there is a selectivity calculation going on there,
but as far as I remember, I called it earlier after my conversion,
and unfortunately it didn't solve my problem with calculating
selectivity. I'll reconsider it again, maybe I can find something I
missed.

Of course this immediately makes me wonder: shouldn't your patch be
able to perform an additional transformation here? You know, by
transforming "a.x = 42 OR a.x = 44" into "a IN (42, 44)"? Although I
haven't checked for myself, I assume that this doesn't happen right
now, since your patch currently performs all of its transformations
during parsing.

I also noticed that the same comment block goes on to say something
about "clauselist_selectivity's inability to recognize redundant
conditions". Perhaps that is relevant to the problems you were having
with selectivity estimation, back when the code was in
preprocess_qual_conditions() instead? I have no reason to believe that
there should be any redundancy left behind by your transformation, so
this is just one possibility to consider.
Separately, the commit message of commit 25a9e54d2d says something
about how the planner builds RestrictInfos, which seems
possibly-relevant. That commit enhanced extended statistics for OR
clauses, so the relevant paragraph describes a limitation of extended
statistics with OR clauses specifically. I'm just guessing, but it
still seems like it might be relevant to the problem you ran into with
selectivity estimation. Another possibility to consider.

I understood what is said about AND clauses in this comment. It seems
to me that AND clauses saved like (BoolExpr *)
expr->args->(RestrictInfo *) clauseA->(RestrictInfo *)clauseB lists
and OR clauses saved like (BoolExpr *) expr ->
orclause->(RestrictInfo *)clause A->(RestrictInfo *)clause B.

As I understand it, selectivity is calculated for each expression.
But I'll exploring it deeper, because I think this place may contain
the answer to the question, what's wrong with selectivity calculation
in my patch.

I could move transformation in there (extract_restriction_or_clauses)
and didn't have any problem with selectivity calculation, besides it
also works on the redundant or duplicates stage. So, it looks like:

CREATE TABLE tenk1 (unique1 int, unique2 int, ten int, hundred int);
insert into tenk1 SELECT x,x,x,x FROM generate_series(1,50000) as x;
CREATE INDEX a_idx1 ON tenk1(unique1); CREATE INDEX a_idx2 ON
tenk1(unique2); CREATE INDEX a_hundred ON tenk1(hundred);

explain analyze select * from tenk1 a join tenk1 b on ((a.unique2 = 3
or a.unique2 = 7));

PLAN
------------------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.29..2033.62 rows=100000 width=32) (actual
time=0.090..60.258 rows=100000 loops=1) -> Seq Scan on tenk1 b
(cost=0.00..771.00 rows=50000 width=16) (actual time=0.016..9.747
rows=50000 loops=1) -> Materialize (cost=0.29..12.62 rows=2 width=16)
(actual time=0.000..0.000 rows=2 loops=50000) -> Index Scan using
a_idx2 on tenk1 a (cost=0.29..12.62 rows=2 width=16) (actual
time=0.063..0.068 rows=2 loops=1) Index Cond: (unique2 = ANY (ARRAY[3,
7])) Planning Time: 8.257 ms Execution Time: 64.453 ms (7 rows)

Overall, this was due to incorrectly defined types of elements in the
array, and if we had applied the transformation with the definition of
the tup operator, we could have avoided such problems (I used
make_scalar_array_op and have not yet found an alternative to this).

When I moved the transformation on the index creation stage, it
couldn't work properly and as a result I faced the same problem of
selectivity calculation. I supposed that the selectivity values are
also used there, and not recalculated all over again. perhaps we can
solve this by forcibly recalculating the selectivity values, but I
foresee other problems there.

explain analyze select * from tenk1 a join tenk1 b on ((a.unique2 = 3
or a.unique2 = 7));

QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=12.58..312942.91 rows=24950000 width=32) (actual
time=0.040..47.582 rows=100000 loops=1) -> Seq Scan on tenk1 b
(cost=0.00..771.00 rows=50000 width=16) (actual time=0.009..7.039
rows=50000 loops=1) -> Materialize (cost=12.58..298.16 rows=499
width=16) (actual time=0.000..0.000 rows=2 loops=50000) -> Bitmap Heap
Scan on tenk1 a (cost=12.58..295.66 rows=499 width=16) (actual
time=0.025..0.028 rows=2 loops=1) Recheck Cond: ((unique2 = 3) OR
(unique2 = 7)) Heap Blocks: exact=1 -> BitmapOr (cost=12.58..12.58
rows=500 width=0) (actual time=0.023..0.024 rows=0 loops=1) -> Bitmap
Index Scan on a_idx2 (cost=0.00..6.17 rows=250 width=0) (actual
time=0.019..0.019 rows=1 loops=1) Index Cond: (unique2 = 3) -> Bitmap
Index Scan on a_idx2 (cost=0.00..6.17 rows=250 width=0) (actual
time=0.003..0.003 rows=1 loops=1) Index Cond: (unique2 = 7) Planning
Time: 0.401 ms Execution Time: 51.350 ms (13 rows)

I have attached a diff file so far, but it is very raw and did not
pass all regression tests (I attached regression.diff) and even had
bad conversion cases (some of the cases did not work at all, in other
cases there were no non-converted nodes). But now I see an interesting
transformation, which was the most interesting for me.

EXPLAIN (COSTS OFF) SELECT * FROM tenk1 WHERE thousand = 42 AND 
(tenthous = 1 OR tenthous = 3 OR tenthous = 42); - QUERY PLAN 
------------------------------------------------------------------------------------------------------------------------------------------ 
- Bitmap Heap Scan on tenk1 - Recheck Cond: (((thousand = 42) AND 
(tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand 
= 42) AND (tenthous = 42))) - -> BitmapOr - -> Bitmap Index Scan on 
tenk1_thous_tenthous - Index Cond: ((thousand = 42) AND (tenthous = 
1)) - -> Bitmap Index Scan on tenk1_thous_tenthous - Index Cond: 
((thousand = 42) AND (tenthous = 3)) - -> Bitmap Index Scan on 
tenk1_thous_tenthous - Index Cond: ((thousand = 42) AND (tenthous = 
42)) -(9 rows) + QUERY PLAN 
+------------------------------------------------------------------------ 
+ Index Scan using tenk1_thous_tenthous on tenk1 + Index Cond: 
((thousand = 42) AND (tenthous = ANY (ARRAY[1, 3, 42]))) +(2 rows)

Attachments:

diff_fix_sel1.difftext/x-patch; charset=UTF-8; name=diff_fix_sel1.diffDownload
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 44efb1f4ebc..80935cec7aa 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -67,6 +67,7 @@
 #include "utils/rel.h"
 #include "utils/selfuncs.h"
 #include "utils/syscache.h"
+#include "optimizer/orclauses.h"
 
 /* GUC parameters */
 double		cursor_tuple_fraction = DEFAULT_CURSOR_TUPLE_FRACTION;
@@ -1169,7 +1170,7 @@ preprocess_expression(PlannerInfo *root, Node *expr, int kind)
 	if (kind == EXPRKIND_QUAL)
 	{
 		expr = (Node *) canonicalize_qual((Expr *) expr, false);
-
+expr = transform_ors(root, (Expr *) expr);
 #ifdef OPTIMIZER_DEBUG
 		printf("After canonicalize_qual()\n");
 		pprint(expr);
diff --git a/src/backend/optimizer/util/orclauses.c b/src/backend/optimizer/util/orclauses.c
index 6ef9d14b902..2e30f2bf88a 100644
--- a/src/backend/optimizer/util/orclauses.c
+++ b/src/backend/optimizer/util/orclauses.c
@@ -22,6 +22,10 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/orclauses.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 
 
 static bool is_safe_restriction_clause_for(RestrictInfo *rinfo, RelOptInfo *rel);
@@ -29,7 +33,255 @@ static Expr *extract_or_clause(RestrictInfo *or_rinfo, RelOptInfo *rel);
 static void consider_new_or_clause(PlannerInfo *root, RelOptInfo *rel,
 								   Expr *orclause, RestrictInfo *join_or_rinfo);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				collation;
+	Oid				opno;
+	RestrictInfo   *rinfo;
+	Expr *expr;
+} OrClauseGroupEntry;
+
+/*
+ * Pass through baserestrictinfo clauses and try to convert OR clauses into IN
+ * Return a modified clause list or just the same baserestrictinfo, if no
+ * changes have made.
+ * XXX: do not change source list of clauses at all.
+ */
+static Expr *
+transform_ors_for_rel(Expr *qual)
+{
+	List	       *modified_clause = NIL;
+	bool		    something_changed = false;
+	List		   *or_list = NIL;
+	ListCell	   *lc_eargs,
+				   *lc_args;
+	List		   *groups_list = NIL;
+	bool			change_apply = false;
+
+	if (!(is_orclause(qual)))
+	{
+		/* Add a clause without changes */
+		return qual;
+	}
+
+	/*
+		* NOTE:
+		* It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		* a list of sub-restrictinfo args, and rinfo->clause - which is the
+		* same expression, made from bare clauses. To not break selectivity
+		* caches and other optimizations, use both:
+		* - use rinfos from orclause if no transformation needed
+		* - use  bare quals from rinfo->clause in the case of transformation,
+		* to create new RestrictInfo: in this case we have no options to avoid
+		* selectivity estimation procedure.
+		*/
+	foreach(lc_eargs, ((BoolExpr *) qual)->args)
+	{
+		Expr			   *bare_orarg = (Expr *) lfirst(lc_eargs);
+		Node			   *const_expr;
+		Node			   *non_const_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+		Oid					opno;
+
+		/* Check: it is an expr of the form 'F(x) oper ConstExpr' */
+		if (!bare_orarg  ||
+			contain_volatile_functions((Node *) bare_orarg))
+		{
+			/* Again, it's not the expr we can transform */
+			or_list = lappend(or_list, (void *) bare_orarg);
+			continue;
+		}
+
+		/* Get pointers to constant and expression sides of the clause */
+		const_expr = get_rightop(bare_orarg);
+		non_const_expr = get_leftop(bare_orarg);
+
+		opno = ((OpExpr *)bare_orarg)->opno;
+		//if (!op_mergejoinable(opno, exprType(non_const_expr)))
+		//{
+			/* And again, filter out non-equality operators */
+		//	or_list = lappend(or_list, (void *) bare_orarg);
+		//	continue;
+		//}
+
+		/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table (htab key ???).
+			*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, non_const_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				non_const_expr = NULL;
+				break;
+			}
+		}
+
+		if (non_const_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = non_const_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->collation = exprInputCollation((Node *) bare_orarg);
+		gentry->opno = opno;
+		gentry->expr = bare_orarg;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+			* No any transformations possible with this rinfo, just add itself
+			* to the list and go further.
+			*/
+		modified_clause = lappend(modified_clause, qual);
+	}
+	else
+	{
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+			* Go through the list of groups and convert each, where number of
+			* consts more than 1. trivial groups move to OR-list again
+			*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(NULL, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(NULL,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+	}
+
+		/*
+		* Make a new version of the restriction. Remember source restriction
+		* can be used in another path (SeqScan, for example).
+		*/
+	/* One more trick: assemble correct clause */
+	qual = list_length(or_list) > 1 ? make_orclause(or_list) : linitial(or_list);
 
+	//modified_clause = lappend(modified_clause, qual);
+	list_free_deep(groups_list);
+	something_changed = true;
+
+	/*
+	 * Check if transformation has made. If nothing changed - return
+	 * baserestrictinfo as is.
+	 */
+	/* if (something_changed)
+	{
+		return modified_clause;
+	} */
+
+	list_free(modified_clause);
+	return qual;
+}
+Node *
+transform_ors(PlannerInfo *root, Expr *jtnode)
+{
+	return (Node *) transform_ors_for_rel(jtnode);
+}
 /*
  * extract_restriction_or_clauses
  *	  Examine join OR-of-AND clauses to see if any useful restriction OR
diff --git a/src/include/optimizer/orclauses.h b/src/include/optimizer/orclauses.h
index f9dbe6a2972..6a232aeb3ed 100644
--- a/src/include/optimizer/orclauses.h
+++ b/src/include/optimizer/orclauses.h
@@ -17,5 +17,5 @@
 #include "nodes/pathnodes.h"
 
 extern void extract_restriction_or_clauses(PlannerInfo *root);
-
+extern Node * transform_ors(PlannerInfo *root, Expr *jtnode);
 #endif							/* ORCLAUSES_H */
In reply to: a.rybakina (#62)
Re: POC, WIP: OR-clause support for indexes

On Thu, Aug 17, 2023 at 3:08 AM a.rybakina <a.rybakina@postgrespro.ru> wrote:

This is an interesting feature. I didn't notice this function before, I studied many times consider_new_or_cause, which were called there. As far as I know, there is a selectivity calculation going on there, but as far as I remember, I called it earlier after my conversion, and unfortunately it didn't solve my problem with calculating selectivity. I'll reconsider it again, maybe I can find something I missed.

Back in 2003, commit 9888192f removed (or at least simplified) what
were then called "CNF/DNF CONVERSION ROUTINES". Prior to that point
the optimizer README had something about leaving clause lists
un-normalized leading to selectivity estimation problems. Bear in mind
that this is a couple of years before ScalarArrayOpExpr was first
invented. Apparently even back then "The OR-of-ANDs format is useful
for indexscan implementation". It's possible that that old work will
offer some hints on what to do now.

In a way it's not surprising that work in this area would have some
impact on selectivies. The surprising part is the extent of the
problem, I suppose.

I see that a lot of the things in this area are just used by BitmapOr
clauses, such as build_paths_for_OR() -- but you're not necessarily
able to use any of that stuff. Also, choose_bitmap_and() has some
stuff about how it compensates to avoid "too-small selectivity that
makes a redundant AND step look like it reduces the total cost". It
also mentions some problems with match_join_clauses_to_index() +
extract_restriction_or_clauses(). Again, this might be a good place to
look for more clues.

--
Peter Geoghegan

In reply to: Peter Geoghegan (#64)
Re: POC, WIP: OR-clause support for indexes

On Sun, Aug 20, 2023 at 3:11 PM Peter Geoghegan <pg@bowt.ie> wrote:

Back in 2003, commit 9888192f removed (or at least simplified) what
were then called "CNF/DNF CONVERSION ROUTINES". Prior to that point
the optimizer README had something about leaving clause lists
un-normalized leading to selectivity estimation problems. Bear in mind
that this is a couple of years before ScalarArrayOpExpr was first
invented. Apparently even back then "The OR-of-ANDs format is useful
for indexscan implementation". It's possible that that old work will
offer some hints on what to do now.

There was actually support for OR lists in index AMs prior to
ScalarArrayOpExpr. Even though ScalarArrayOpExpr don't really seem all
that related to bitmap scans these days (since at least nbtree knows
how to execute them "natively"), that wasn't always the case.
ScalarArrayOpExpr were invented the same year that bitmap index scans
were first added (2005), and seem more or less related to that work.
See commits bc843d39, 5b051852, 1e9a6ba5, and 290166f9 (all from
2005). Particularly the last one, which has a commit message that
heavily suggests that my interpretation is correct.

I think that we currently over-rely on BitmapOr for OR clauses. It's
useful that they're so general, of course, but ISTM that we shouldn't
even try to use a BitmapOr in simple cases. Things like the "WHERE
thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42)"
tenk1 query that you brought up probably shouldn't even have a
BitmapOr path (which I guess they don't with you patch). Note that I
recently discussed the same query at length with Tomas Vondra on the
ongoing thread for his index filter patch (you probably knew that
already).

--
Peter Geoghegan

In reply to: a.rybakina (#62)
Re: POC, WIP: OR-clause support for indexes

On Thu, Aug 17, 2023 at 3:08 AM a.rybakina <a.rybakina@postgrespro.ru> wrote:

But now I see an interesting transformation, which was the most interesting for me.

EXPLAIN (COSTS OFF) SELECT * FROM tenk1 WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);

It would be even more interesting if it could be an index-only scan as
a result of the transformation. For example, we could use an
index-only scan with this query (once your patch was in place):

"SELECT thousand, tenthous FROM tenk1 WHERE thousand = 42 AND
(tenthous = 1 OR tenthous = 3 OR tenthous = 42)"

Index-only scans were the original motivation for adding native
ScalarArrayExprOp support to nbtree (in 2011 commit 9e8da0f7), in
fact.

As I suggested earlier, I suspect that there is too much planner logic
that targets BitmapOrs specifically -- maybe even selectivity
estimation/restrictinfo stuff.

PS I wonder if the correctness issues that you saw could be related to
eval_const_expressions(), since "the planner assumes that this
[eval_const_expressions] will always flatten nested AND and OR clauses
into N-argument form". See its subroutines simplify_or_arguments() and
simplify_and_arguments().

--
Peter Geoghegan

#67a.rybakina
a.rybakina@postgrespro.ru
In reply to: Peter Geoghegan (#65)
Re: POC, WIP: OR-clause support for indexes

Thank you for your interest in this problem and help, and I'm sorry that
I didn't respond to this email for a long time. To be honest, I wanted
to investigate the problems in more detail and already answer more
clearly, but unfortunately I have not found anything more significant yet.

On 21.08.2023 01:26, Peter Geoghegan wrote:

There was actually support for OR lists in index AMs prior to
ScalarArrayOpExpr. Even though ScalarArrayOpExpr don't really seem all
that related to bitmap scans these days (since at least nbtree knows
how to execute them "natively"), that wasn't always the case.
ScalarArrayOpExpr were invented the same year that bitmap index scans
were first added (2005), and seem more or less related to that work.
See commits bc843d39, 5b051852, 1e9a6ba5, and 290166f9 (all from
2005). Particularly the last one, which has a commit message that
heavily suggests that my interpretation is correct.

Back in 2003, commit 9888192f removed (or at least simplified) what
were then called "CNF/DNF CONVERSION ROUTINES". Prior to that point
the optimizer README had something about leaving clause lists
un-normalized leading to selectivity estimation problems. Bear in mind
that this is a couple of years before ScalarArrayOpExpr was first
invented. Apparently even back then "The OR-of-ANDs format is useful
for indexscan implementation". It's possible that that old work will
offer some hints on what to do now.
In a way it's not surprising that work in this area would have some
impact on selectivies. The surprising part is the extent of the
problem, I suppose.

I see that a lot of the things in this area are just used by BitmapOr
clauses, such as build_paths_for_OR() -- but you're not necessarily
able to use any of that stuff. Also, choose_bitmap_and() has some
stuff about how it compensates to avoid "too-small selectivity that
makes a redundant AND step look like it reduces the total cost". It
also mentions some problems with match_join_clauses_to_index() +
extract_restriction_or_clauses(). Again, this might be a good place to
look for more clues.

I agree with your assumption about looking at the source of the error
related to selectivity in these places. But honestly, no matter how many
times I looked, until enough sensible thoughts appeared, which could
cause a problem. I keep looking, maybe I'll find something.

EXPLAIN (COSTS OFF) SELECT * FROM tenk1 WHERE thousand = 42 AND 
(tenthous = 1 OR tenthous = 3 OR tenthous = 42); - QUERY PLAN 
------------------------------------------------------------------------------------------------------------------------------------------ 
- Bitmap Heap Scan on tenk1 - Recheck Cond: (((thousand = 42) AND 
(tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand 
= 42) AND (tenthous = 42))) - -> BitmapOr - -> Bitmap Index Scan on 
tenk1_thous_tenthous - Index Cond: ((thousand = 42) AND (tenthous = 
1)) - -> Bitmap Index Scan on tenk1_thous_tenthous - Index Cond: 
((thousand = 42) AND (tenthous = 3)) - -> Bitmap Index Scan on 
tenk1_thous_tenthous - Index Cond: ((thousand = 42) AND (tenthous = 
42)) -(9 rows) + QUERY PLAN 
+------------------------------------------------------------------------ 
+ Index Scan using tenk1_thous_tenthous on tenk1 + Index Cond: 
((thousand = 42) AND (tenthous = ANY (ARRAY[1, 3, 42]))) +(2 rows)

I think that we currently over-rely on BitmapOr for OR clauses. It's
useful that they're so general, of course, but ISTM that we shouldn't
even try to use a BitmapOr in simple cases. Things like the "WHERE
thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42)"
tenk1 query that you brought up probably shouldn't even have a
BitmapOr path (which I guess they don't with you patch). Note that I
recently discussed the same query at length with Tomas Vondra on the
ongoing thread for his index filter patch (you probably knew that
already).

I think so too, but it's still quite difficult to find a stable enough
optimization to implement this, in my opinion. But I will finish the
current optimization with OR->ANY, given that something interesting has
appeared.

#68Peter Eisentraut
peter@eisentraut.org
In reply to: a.rybakina (#67)
Re: POC, WIP: OR-clause support for indexes

On 29.08.23 05:37, a.rybakina wrote:

Thank you for your interest in this problem and help, and I'm sorry that
I didn't respond to this email for a long time. To be honest, I wanted
to investigate the problems in more detail and already answer more
clearly, but unfortunately I have not found anything more significant yet.

What is the status of this patch? It is registered in the commitfest.
It looks like a stalled research project? The last posted patch doesn't
contain any description or tests, so it doesn't look very ready.

#69a.rybakina
a.rybakina@postgrespro.ru
In reply to: Peter Eisentraut (#68)
Re: POC, WIP: OR-clause support for indexes

Hi!

When I sent the patch version to commitfest, I thought that the work on
this topic was completed. Patch version and test results in [0]/messages/by-id/4bac271d-1700-db24-74ac-8414f2baf9fd@postgrespro.ru.

But in the process of discussing this patch, we found out that there is
another place where you can make a transformation, specifically, during
the calculation of selectivity. I implemented the raw version [1]/messages/by-id/b301dce1-09fd-72b1-834a-527ca428db5e@yandex.ru, but
unfortunately it didn't work in regression tests.

I'm sorry that I didn't write about the status earlier, I was very
overwhelmed with tasks at work due to releases and preparations for the
conference. I returned to the work of this patch, today or tomorrow I'll
drop the version.

[0]: /messages/by-id/4bac271d-1700-db24-74ac-8414f2baf9fd@postgrespro.ru

/messages/by-id/4bac271d-1700-db24-74ac-8414f2baf9fd@postgrespro.ru

/messages/by-id/11403645-b342-c400-859e-47d0f41ec22a@postgrespro.ru

[1]: /messages/by-id/b301dce1-09fd-72b1-834a-527ca428db5e@yandex.ru
/messages/by-id/b301dce1-09fd-72b1-834a-527ca428db5e@yandex.ru

Show quoted text

On 20.09.2023 12:37, Peter Eisentraut wrote:

On 29.08.23 05:37, a.rybakina wrote:

Thank you for your interest in this problem and help, and I'm sorry
that I didn't respond to this email for a long time. To be honest, I
wanted to investigate the problems in more detail and already answer
more clearly, but unfortunately I have not found anything more
significant yet.

What is the status of this patch?  It is registered in the commitfest.
It looks like a stalled research project?  The last posted patch
doesn't contain any description or tests, so it doesn't look very ready.

#70a.rybakina
a.rybakina@postgrespro.ru
In reply to: a.rybakina (#69)
5 attachment(s)
Re: POC, WIP: OR-clause support for indexes

I'm sorry I didn't write for a long time, but I really had a very
difficult month, now I'm fully back to work.

*I was able to implement the patches to the end and moved the
transformation of "OR" expressions to ANY.* I haven't seen a big
difference between them yet, one has a conversion before calculating
selectivity (v7-v1-Replace-OR-clause-to-ANY.patch), the other after
(v7-v2-Replace-OR-clause-to-ANY.patch). Regression tests are passing, I
don't see any problems with selectivity, nothing has fallen into the
coredump, but I found some incorrect transformations. What is the reason
for these inaccuracies, I have not found, but, to be honest, they look
unusual). Gave the error below.
In the patch, I don't like that I had to drag three libraries from
parsing until I found a way around it.The advantage of this approach
compared to the other (v7-v0-Replace-OR-clause-to-ANY.patch) is that at
this stage all possible or transformations are performed, compared to
the patch, where the transformation was done at the parsing stage. That
is, here, for example, there are such optimizations in the transformation:

I took the common element out of the bracket and the rest is converted
to ANY, while, as noted by Peter Geoghegan, we did not have several
bitmapscans, but only one scan through the array.

postgres=# explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 AND prolang=1 OR prolang = 13 AND prolang = 2 OR
prolang = 13 AND prolang = 3;
                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..151.66 rows=1 width=68) (actual
time=1.167..1.168 rows=0 loops=1)
   Filter: ((prolang = '13'::oid) AND (prolang = ANY (ARRAY['1'::oid,
'2'::oid, '3'::oid])))
   Rows Removed by Filter: 3302
 Planning Time: 0.146 ms
 Execution Time: 1.191 ms
(5 rows)

*While I was testing, I found some transformations that don't work,
although in my opinion, they should:**
**
**1. First case:*
explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 AND prolang=1 OR prolang = 2 AND prolang = 2 OR
prolang = 13 AND prolang = 13;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..180.55 rows=2 width=68) (actual
time=2.959..3.335 rows=89 loops=1)
   Filter: (((prolang = '13'::oid) AND (prolang = '1'::oid)) OR
((prolang = '2'::oid) AND (prolang = '2'::oid)) OR ((prolang =
'13'::oid) AND (prolang = '13'::oid)))
   Rows Removed by Filter: 3213
 Planning Time: 1.278 ms
 Execution Time: 3.486 ms
(5 rows)

Should have left only prolang = '13'::oid:

                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..139.28 rows=1 width=68) (actual
time=2.034..2.034 rows=0 loops=1)
   Filter: ((prolang = '13'::oid ))
   Rows Removed by Filter: 3302
 Planning Time: 0.181 ms
 Execution Time: 2.079 ms
(5 rows)

*2. Also does not work:*
postgres=# explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang = 2 AND prolang = 2 OR prolang = 13;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..164.04 rows=176 width=68) (actual
time=2.422..2.686 rows=89 loops=1)
   Filter: ((prolang = '13'::oid) OR ((prolang = '2'::oid) AND (prolang
= '2'::oid)) OR (prolang = '13'::oid))
   Rows Removed by Filter: 3213
 Planning Time: 1.370 ms
 Execution Time: 2.799 ms
(5 rows)

Should have left:
Filter: ((prolang = '13'::oid) OR (prolang = '2'::oid))

*3. Or another:*

explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang=13 OR prolang = 2 AND prolang = 2;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..164.04 rows=176 width=68) (actual
time=2.350..2.566 rows=89 loops=1)
   Filter: ((prolang = '13'::oid) OR (prolang = '13'::oid) OR ((prolang
= '2'::oid) AND (prolang = '2'::oid)))
   Rows Removed by Filter: 3213
 Planning Time: 0.215 ms
 Execution Time: 2.624 ms
(5 rows)

Should have left:
Filter: ((prolang = '13'::oid) OR (prolang = '2'::oid))

*Falls into coredump at me:*
explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang = 2 AND prolang = 2 OR prolang = 13;

explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang=13 OR prolang = 2 AND prolang = 2;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..164.04 rows=176 width=68) (actual
time=2.350..2.566 rows=89 loops=1)
   Filter: ((prolang = '13'::oid) OR (prolang = '13'::oid) OR ((prolang
= '2'::oid) AND (prolang = '2'::oid)))
   Rows Removed by Filter: 3213
 Planning Time: 0.215 ms
 Execution Time: 2.624 ms

(5 rows)

I remind that initially the task was to find an opportunity to optimize
the case of processing a large number of "or" expressions to optimize
memory consumption. The FlameGraph for executing 50,000 "or"
expressionshas grown 1.4Gb and remains in this state until exiting the
psql session (flamegraph1.png) and it sagged a lot in execution time. If
this case is converted to ANY, the query is executed much faster and
memory is optimized (flamegraph2.png). It may be necessary to use this
approach if there is no support for the framework to process ANY, IN
expressions.

Peter Geoghegan also noticed some development of this patch in terms of
preparing some transformations to optimize the query at the stage of its
execution [0]/messages/by-id/CAH2-Wz=9N_4+EyhtyFqYQRx4OgVbP+1aoYU2JQPVogCir61ZEQ@mail.gmail.com.

[0]: /messages/by-id/CAH2-Wz=9N_4+EyhtyFqYQRx4OgVbP+1aoYU2JQPVogCir61ZEQ@mail.gmail.com
/messages/by-id/CAH2-Wz=9N_4+EyhtyFqYQRx4OgVbP+1aoYU2JQPVogCir61ZEQ@mail.gmail.com

Attachments:

v7-v0-Replace-OR-clause-to-ANY.patchtext/x-patch; charset=UTF-8; name=v7-v0-Replace-OR-clause-to-ANY.patchDownload
From 087125cc413429bda05f22ebbd51115c23819285 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Tue, 18 Jul 2023 17:19:53 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
---
 src/backend/parser/parse_expr.c               | 230 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 115 +++++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  50 ++++
 src/test/regress/expected/partition_prune.out | 179 ++++++++++++++
 src/test/regress/expected/tidscan.out         |  17 ++
 src/test/regress/sql/create_index.sql         |  32 +++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 13 files changed, 674 insertions(+), 2 deletions(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 5a05caa8744..b2294af0f43 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -43,6 +43,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+int			or_transform_limit = 500;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -95,6 +96,233 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < or_transform_limit)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -208,7 +436,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index f9dba43b8c0..ddc27e2277c 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -2040,6 +2040,16 @@ struct config_int ConfigureNamesInt[] =
 		100, 1, MAX_STATISTICS_TARGET,
 		NULL, NULL, NULL
 	},
+	{
+		{"or_transform_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&or_transform_limit,
+		500, 0, INT_MAX,
+		NULL, NULL, NULL
+	},
 	{
 		{"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
 			gettext_noop("Sets the FROM-list size beyond which subqueries "
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..891e6a462b9 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT int or_transform_limit;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..cc229d4dcaf 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,121 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET or_transform_limit;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..c052b113eea 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ or_transform_limit
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9b8638f286a..2314d92a6d4 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,6 +4207,56 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
+
+RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 1eb347503aa..d1c5ce8be09 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET or_transform_limit;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET or_transform_limit;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..a2949d3d699 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET or_transform_limit;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..9c6baace0e2 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET or_transform_limit;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 3e5032b04dd..d4d7d853a4a 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1396,6 +1396,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET or_transform_limit;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index d1c60b8fe9d..77f3e6c3b9b 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET or_transform_limit;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET or_transform_limit;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..634bf08e5fc 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET or_transform_limit;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e941fb6c82f..c3abb725c8c 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1631,6 +1631,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
6.0.1

v7-v1-Replace-OR-clause-to-ANY.patchtext/x-patch; charset=UTF-8; name=v7-v1-Replace-OR-clause-to-ANY.patchDownload
From 9e0a0200525e7e72f1a91f658b4674fbf78ea18d Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 21 Sep 2023 19:15:42 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
---
 src/backend/optimizer/plan/planner.c   |   3 +-
 src/backend/optimizer/util/orclauses.c | 232 +++++++++++++++++++++++++
 src/include/optimizer/orclauses.h      |   2 +-
 3 files changed, 235 insertions(+), 2 deletions(-)

diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 44efb1f4ebc..80935cec7aa 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -67,6 +67,7 @@
 #include "utils/rel.h"
 #include "utils/selfuncs.h"
 #include "utils/syscache.h"
+#include "optimizer/orclauses.h"
 
 /* GUC parameters */
 double		cursor_tuple_fraction = DEFAULT_CURSOR_TUPLE_FRACTION;
@@ -1169,7 +1170,7 @@ preprocess_expression(PlannerInfo *root, Node *expr, int kind)
 	if (kind == EXPRKIND_QUAL)
 	{
 		expr = (Node *) canonicalize_qual((Expr *) expr, false);
-
+expr = transform_ors(root, (Expr *) expr);
 #ifdef OPTIMIZER_DEBUG
 		printf("After canonicalize_qual()\n");
 		pprint(expr);
diff --git a/src/backend/optimizer/util/orclauses.c b/src/backend/optimizer/util/orclauses.c
index 6ef9d14b902..805f4b7294a 100644
--- a/src/backend/optimizer/util/orclauses.c
+++ b/src/backend/optimizer/util/orclauses.c
@@ -22,6 +22,10 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/orclauses.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 
 
 static bool is_safe_restriction_clause_for(RestrictInfo *rinfo, RelOptInfo *rel);
@@ -29,7 +33,235 @@ static Expr *extract_or_clause(RestrictInfo *or_rinfo, RelOptInfo *rel);
 static void consider_new_or_clause(PlannerInfo *root, RelOptInfo *rel,
 								   Expr *orclause, RestrictInfo *join_or_rinfo);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static Node *
+transform_ors_for_rel(BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < 1)
+		return (Node*) expr_orig;
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *orqual = lfirst(lc);
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
 
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) expr_orig;
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(NULL, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(NULL,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+ 			saopexpr->inputcollid = exprInputCollation((Node *)gentry->expr);;
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
+Node *
+transform_ors(PlannerInfo *root, Expr *jtnode)
+{
+	if (IsA(jtnode, BoolExpr))
+		return transform_ors_for_rel((BoolExpr *) jtnode);
+	return (Node *) jtnode;
+}
 /*
  * extract_restriction_or_clauses
  *	  Examine join OR-of-AND clauses to see if any useful restriction OR
diff --git a/src/include/optimizer/orclauses.h b/src/include/optimizer/orclauses.h
index f9dbe6a2972..6a232aeb3ed 100644
--- a/src/include/optimizer/orclauses.h
+++ b/src/include/optimizer/orclauses.h
@@ -17,5 +17,5 @@
 #include "nodes/pathnodes.h"
 
 extern void extract_restriction_or_clauses(PlannerInfo *root);
-
+extern Node * transform_ors(PlannerInfo *root, Expr *jtnode);
 #endif							/* ORCLAUSES_H */
-- 
2.34.1

v7-v2-Replace-OR-clause-to-ANY.patchtext/x-patch; charset=UTF-8; name=v7-v2-Replace-OR-clause-to-ANY.patchDownload
From 84ba19a988447bd5e19132080375101e1ae2e63b Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Tue, 26 Sep 2023 09:23:44 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR 
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are 
 still working with a tree expression. Firstly, we do not try to make a 
 transformation for "non-or" expressions or inequalities and the creation of a
  relation with "or" expressions occurs according to the same scenario. 
 Secondly, we do not make transformations if there are less than set 
 or_transform_limit. Thirdly, it is worth considering that we consider "or" 
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
---
 src/backend/optimizer/util/orclauses.c | 295 +++++++++++++++++++++++++
 1 file changed, 295 insertions(+)

diff --git a/src/backend/optimizer/util/orclauses.c b/src/backend/optimizer/util/orclauses.c
index 6ef9d14b902..b4ac9370461 100644
--- a/src/backend/optimizer/util/orclauses.c
+++ b/src/backend/optimizer/util/orclauses.c
@@ -22,6 +22,10 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/orclauses.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 
 
 static bool is_safe_restriction_clause_for(RestrictInfo *rinfo, RelOptInfo *rel);
@@ -30,6 +34,292 @@ static void consider_new_or_clause(PlannerInfo *root, RelOptInfo *rel,
 								   Expr *orclause, RestrictInfo *join_or_rinfo);
 
 
+int			or_transform_limit = 2;
+
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static List *
+transform_ors(PlannerInfo *root, List *baserestrictinfo)
+{
+	ListCell	   *lc_clause, *lc_or;
+	List	   	   *modified_rinfo = NIL;
+	bool		    something_changed = false;
+
+
+	foreach (lc_clause, baserestrictinfo)
+	{
+			RestrictInfo   	   *rinfo = lfirst_node(RestrictInfo, lc_clause);
+			RestrictInfo	   *rinfo_base = copyObject(rinfo);
+			List		   *groups_list = NIL;
+			OrClauseGroupEntry *gentry;
+			List		   *or_list = NIL;
+			bool				change_apply = false;
+
+			if (!restriction_is_or_clause(rinfo) ||
+				list_length(((BoolExpr *) rinfo->clause)->args) < or_transform_limit)
+			{
+				/* Add a clause without changes */
+				modified_rinfo = lappend(modified_rinfo, copyObject(rinfo));
+				continue;
+			}
+			foreach (lc_or, ((BoolExpr *) rinfo->clause)->args)
+			{
+				Node			   *orqual = lfirst(lc_or);
+				Node			   *const_expr;
+				Node			   *nconst_expr;
+				ListCell		   *lc_groups;
+
+				/* If this is not an 'OR' expression, skip the transformation */
+				if (!IsA(orqual, OpExpr))
+				{
+					or_list = lappend(or_list, orqual);
+					continue;
+				}
+
+
+			/*
+			* Detect the constant side of the clause. Recall non-constant
+			* expression can be made not only with Vars, but also with Params,
+			* which is not bonded with any relation. Thus, we detect the const
+			* side - if another side is constant too, the orqual couldn't be
+			* an OpExpr.
+			* Get pointers to constant and expression sides of the qual.
+			*/
+			if (IsA(get_leftop(orqual), Const))
+			{
+				nconst_expr = get_rightop(orqual);
+				const_expr = get_leftop(orqual);
+			}
+			else if (IsA(get_rightop(orqual), Const))
+			{
+				const_expr = get_rightop(orqual);
+				nconst_expr = get_leftop(orqual);
+			}
+			else
+			{
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+			{
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table. But also we believe, that the case of many
+			* different variable sides is very rare.
+			*/
+			foreach(lc_groups, groups_list)
+			{
+				OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+				Assert(v->node != NULL);
+
+				if (equal(v->node, nconst_expr))
+				{
+					v->consts = lappend(v->consts, const_expr);
+					nconst_expr = NULL;
+					break;
+				}
+			}
+
+			if (nconst_expr == NULL)
+				/*
+					* The clause classified successfully and added into existed
+					* clause group.
+					*/
+				continue;
+
+			/* New clause group needed */
+			gentry = palloc(sizeof(OrClauseGroupEntry));
+			gentry->node = nconst_expr;
+			gentry->consts = list_make1(const_expr);
+			gentry->expr = (Expr *) orqual;
+			groups_list = lappend(groups_list,  (void *) gentry);
+		}
+
+		if (groups_list == NIL)
+		{
+			/*
+			* No any transformations possible with this list of arguments. Here we
+			* already made all underlying transformations. Thus, just return the
+			* transformed bool expression.
+			*/
+			modified_rinfo = lappend(modified_rinfo, copyObject(rinfo));
+			continue;
+		}
+		else
+		{
+			ListCell	   *lc_args;
+
+			/* Let's convert each group of clauses to an IN operation. */
+
+			/*
+			* Go through the list of groups and convert each, where number of
+			* consts more than 1. trivial groups move to OR-list again
+			*/
+
+			foreach(lc_args, groups_list)
+			{
+				List			   *allexprs;
+				Oid				    scalar_type;
+				Oid					array_type;
+				gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+
+				Assert(list_length(gentry->consts) > 0);
+
+				if (list_length(gentry->consts) == 1)
+				{
+					/*
+					* Only one element in the class. Return rinfo into the BoolExpr
+					* args list unchanged.
+					*/
+					list_free(gentry->consts);
+					or_list = lappend(or_list, gentry->expr);
+					continue;
+				}
+
+				/*
+				* Do the transformation.
+				*
+				* First of all, try to select a common type for the array elements.
+				* Note that since the LHS' type is first in the list, it will be
+				* preferred when there is doubt (eg, when all the RHS items are
+				* unknown literals).
+				*
+				* Note: use list_concat here not lcons, to avoid damaging rnonvars.
+				*
+				* As a source of insides, use make_scalar_array_op()
+				*/
+				allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+				scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+				if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+					array_type = get_array_type(scalar_type);
+				else
+					array_type = InvalidOid;
+
+				if (array_type != InvalidOid)
+				{
+					/*
+					* OK: coerce all the right-hand non-Var inputs to the common
+					* type and build an ArrayExpr for them.
+					*/
+					List	   *aexprs;
+					ArrayExpr  *newa;
+					ScalarArrayOpExpr *saopexpr;
+					ListCell *l;
+
+					aexprs = NIL;
+
+					foreach(l, gentry->consts)
+					{
+						Node	   *rexpr = (Node *) lfirst(l);
+
+						rexpr = coerce_to_common_type(NULL, rexpr,
+													scalar_type,
+													"IN");
+						aexprs = lappend(aexprs, rexpr);
+					}
+
+					newa = makeNode(ArrayExpr);
+					/* array_collid will be set by parse_collate.c */
+					newa->element_typeid = scalar_type;
+					newa->array_typeid = array_type;
+					newa->multidims = false;
+					newa->elements = aexprs;
+					newa->location = -1;
+
+					saopexpr =
+						(ScalarArrayOpExpr *)
+							make_scalar_array_op(NULL,
+												list_make1(makeString((char *) "=")),
+												true,
+												gentry->node,
+												(Node *) newa,
+												-1);
+					saopexpr->inputcollid = exprInputCollation((Node *)gentry->expr);;
+
+					or_list = lappend(or_list, (void *) saopexpr);
+
+					something_changed = true;
+					change_apply = true;
+				}
+				else
+				{
+					list_free(gentry->consts);
+					or_list = lappend(or_list, gentry->expr);
+					continue;
+				}
+
+				if (!change_apply)
+				{
+					/*
+					* Each group contains only one element - use rinfo as is.
+					*/
+					modified_rinfo = lappend(modified_rinfo, rinfo);
+					continue;
+				}
+
+				/*
+				* Make a new version of the restriction. Remember source restriction
+				* can be used in another path (SeqScan, for example).
+				*/
+
+				/* One more trick: assemble correct clause */
+				rinfo = make_restrictinfo(root,
+						list_length(or_list) > 1 ? make_orclause(or_list) :
+													(Expr *) linitial(or_list),
+						rinfo->has_clone,
+						rinfo->is_clone,
+						rinfo->is_pushed_down,
+						rinfo->pseudoconstant,
+						rinfo->security_level,
+						rinfo->required_relids,
+						rinfo->outer_relids,
+						rinfo->outer_relids);
+				rinfo->eval_cost=rinfo_base->eval_cost;
+				rinfo->norm_selec=rinfo_base->norm_selec;
+				rinfo->outer_selec=rinfo_base->outer_selec;
+				rinfo->left_bucketsize=rinfo_base->left_bucketsize;
+				rinfo->right_bucketsize=rinfo_base->right_bucketsize;
+				rinfo->left_mcvfreq=rinfo_base->left_mcvfreq;
+				rinfo->right_mcvfreq=rinfo_base->right_mcvfreq;
+				modified_rinfo = lappend(modified_rinfo, rinfo);
+				something_changed = true;
+			}
+		}
+		list_free(or_list);
+		list_free_deep(groups_list);
+
+	}
+		/*
+		 * Check if transformation has made. If nothing changed - return
+		 * baserestrictinfo as is.
+		 */
+		if (something_changed)
+		{
+			return modified_rinfo;
+		}
+
+		list_free(modified_rinfo);
+		return baserestrictinfo;
+}
+
 /*
  * extract_restriction_or_clauses
  *	  Examine join OR-of-AND clauses to see if any useful restriction OR
@@ -93,6 +383,9 @@ extract_restriction_or_clauses(PlannerInfo *root)
 		if (rel->reloptkind != RELOPT_BASEREL)
 			continue;
 
+		rel->baserestrictinfo  = transform_ors(root, rel->baserestrictinfo);
+		rel->joininfo = transform_ors(root, rel->joininfo);
+
 		/*
 		 * Find potentially interesting OR joinclauses.  We can use any
 		 * joinclause that is considered safe to move to this rel by the
@@ -114,7 +407,9 @@ extract_restriction_or_clauses(PlannerInfo *root)
 				 * and insert it into the rel's restrictinfo list if so.
 				 */
 				if (orclause)
+				{
 					consider_new_or_clause(root, rel, orclause, rinfo);
+				}
 			}
 		}
 	}
-- 
2.34.1

flamegraph1.pngimage/png; name=flamegraph1.pngDownload
flamegraph2.pngimage/png; name=flamegraph2.pngDownload
�PNG


IHDR9����sBIT|d�tEXtSoftwaregnome-screenshot��>.iTXtCreation Time���� 31 ������ 2023 18:34:57r9F> IDATx���gXg��gw��7E�]{�=�1���D������1��5���M�
bI���X@�X(���+���Ufv���;���g��JNNVB!�B!�B�;�7�B!�B!������B!�B!���$�B!�B!���$9(�B!�B!D>%�A!�B!�B!�)I
!�B!�B�OIrP!�B!�B�|J��B!�B!�B�S�B!�B!�"����B!�B!���$�B!�B!���$9(�B!�B!D>%�A!�B!�B!�)I
!�B!�B�OIrP!�B!�B�|J�M��


%&&����7�/���J�(��CB!�+Bll�\�
!���*99Y�������w�qqqyQ�S,--155������#44���^IB�	'O����@�B����������		A�������B!�[#O��������P�P�����._��F�yfb�m�����T�^��� ����~�V����B�<�V����x'����V�Z�j�'N<����	����B�.��f�			�,Y2/�z.///BCC��8���P�<��)�[Ej�!�G111����^g�.]�<�y�~B!��<I�����dX||�[���M!�o�$FD~��CB!�[*�$y�d���79�<���x{{����Z����$$$����������}�X�xW�T��>���l��O�����9 ��B��\c
!�"/��h���P��������p��$%%q��9j����u�KN�4��g������8w�Z�����8�+�D���^�7��������s����-[6W�?~�E#�5o����'3��~�"�V����a��g���?o�@�"���M�kgg���y���	�w��E�(�&W|B!D^S�UA����q��5BBB���BOO���d�Zm����8�Z-�������
��k�r������>tw��G���{����Gv,--s�x���;���Hx������x�����0�B��?�������{�����x�r�
:���?���l[����i��.�S���B,Rg'���b\%g
w��yS_���?h2�#_������?c��/Q�������.?�D�uh�G����%6��y��922��'2q�D"##s����K��������|c	!���<K����������_�@"�J�,Ixx87o����gggBBB�~�z�m#��J��>������Y&��������X���@/����>��53���s�����cX���<I��������KQ��#M,�s/N����mr��0�C�[�~�N�3��P���%M;��hb����v������O>����0��)�������Y��c�^l������E��1��)��xy{��`��PZ����}{J�(Abb���al��7��xaon���3E+5��������3����F``d�uo*6���]WIz��=�����x{�`�.�yL{�ovm8����I�����gm����x`?8��)?�������8��u/s���k��9�)sS�B�d�nNO��s�;w��A�P!���-���&�e��qL���7���$h�B���k�9x��5��9���j��;w�p��J�,���S�$'rR��������+DDD`gg���#�O������(	7��F�q������������/\N�u+��� �r-���$����{��e5�Gw���\�k�`zhr&���k�?��G�������U��w�o��m�#W�i�VL;/�N�fA�M������O���pc�J�$��������{'�5vx'���W�����t��	CC��W�w�)�+�t�n��1S�b�����=q1I�/:���nsG[�a[���fV���z{��&}��~;k;j
�p[�������Y��mJO��r��XS{
�oB�y�^2���y��O{�M
�u��R��~h\����M��!)\�c$���136���%��GdSI�����8�4bA�;V����N�w�����������;-��:�s����
�f����'7W����5Ko��O`TT�&M"::�����h&M����(/���
����t�V�o���U�ckj��k�V �B����%���9u��
z�����<KN��WWW|}}	���k8::�����3gqh�q���������!�#r�Df](@wQ�"��?�r���>�n�'�xUh��?�IN+����4�P����X�[�\�����o{����=�VN�����I�K2�wM"�F1���p��J��p%1�y]4{&t�V���X����c�^��jL����,m�,j[9�����_3����L��T�H�v��v<u�G�u�i�]�	~���rE��u'�������{vu�G�+����6�~4����e���/�k+O��eO���'���GTT7n|�#**���������L�
T�D�N�5�c|�Ns���G�$^���6���1���(���q�V��%I>���>����5Y@T�Ky���R��ucs"@
�wM�K�����a[��������J$[�jD���0����*������m\O[3�l���}>g����k3�eU|<�01����2�����,�=��h�������.�
+�R�#��j n)-��i���{y��J�hQ�"��X8%�����W�D�������JN[X{���(��~�
GYS7z�x��/;����j=z4���<8k'qjJF��@�u�y�@��lB��]�?f>����!�r�#s{S��fV��n��U���(u\]�!�=�06���u�/���r�����8����01����
C����$����C���X�c_�
]�;H��jO��)V��R��G�Z��O
G����5�}�~N�Dst^?���`if��gY>Z~]��7��)�K�L7;3�����^\L��(�b���v��Y�#��\�W/���	�v����-���j���k����JBK6���3K|�����q����s���f�]l036�������h�+8G�;��ei4rT�����e��)���@��H2��i�������=�X��z�A���'u���| ��e�tz-[O���_�t���_dR��L9���5�q��/M��=Y|�t����4��}f��q���M�q������Z�'N��J����D@����a�)����w���%�{����T�R�&M�dzT�R��/��w��vW�Q�NK��HQ|���aP	,�^��0��3��	�7��K�����#,�=�o��f��)�Y���i)Z�����_fOe��1�?���]O��"�6g�-c�����-Sf�������%|��L�8���&1s�N����B�^Kr0&&�S�N����J�"::�������K�r��x�8�|(P???�_����Wqtt����S�N�Rq<M���hT^��IqN������=���7i3f�'0�_C��;i}�%rjbKZM������R�,u��te�%-�#:t?����x[7-��
�X0x���0d�*�-J�k?�w�B������i�������k����g������*����[	����5[��r6��zcX���P��\%��!���Q�R��|���1���Q��2�S��������5��}w1=:��X"��R�2k[w���QU�^��^s.<]@w���28�:�V�!��=��Glmm��i�S����U�"N�z�o�kR��
���#7��n~�Q��n`���I���9��,�2C���iN�>��Y�ytx1��������$N��8��	�~��/���������P�th���`��ml_7��)��e�9��0���7��� ����������4L��8�i������?|N�������y�dQ��*]����l����.l+����
Y��u7V��~6��b��l�����i9��0�\P5�"�����m*w����I�8~�+Z�;������7z��{��-Z�h���S�K�5��o_�/$�O~]�Q�/����3jF&2�%
���u�i����o��X\������F5�������l���Uc���/�J;Ge��n-��n�"�2n=�d�����6�v�a����9�e���K_W����K#r�O��K5���y�d���	��
m����m\����"�9G������@����e�V�L�I%��|�� v���������G��\��
����s]z�M���l\5�6����~f_J�4�"���H�c�����,���A��w�(��%qrRw���������A�jJ�V]0�g���(�������������|����$sr�l����f����m"}��f�5�V]����.��	$0���,Pk���:�F%�X��)��lR{3#Ll��<�#�	S%���ZS�D��
00s���c�J�q~�Sw+LL)Q +/�'����&��6F[���j.�+o'qxTe<lM02��hP?�d�+���z��,���&�����o=�����iP�	3Ccl����M7���,m��u���~�3Y��c�,N��e���4���?����qf���u���_L��-�
e���y�^r�1~�n7F��`h�5����C��<����AI���K��nU��i����Pn�rb�`���gJ�"h���_D��h�J��J�?*U��B��jK[l�v���XOw����=��2�:��c]
%�f���\K��S��S�f3:H�VUq�>�o[�pWx��/r�������}j�E��rj�B6�K��FK:vlC��~�Z��,�����^��tl���3lZ��k��@!�xiy6���.<n�����!j��V��7������5�k#���@�\�z�7n����Z������7obaa��q�p'�X9P��`Z����K����-��SX%�\U�LI�v�8����?�>�<���bb7�@9�q����5����@OEAe^�J�U)�������cX���X��a�2v?G����m�N��e���5�E4@��*�Qv�d�
�IW�����f�_��6�����;���;U'#�do��>9r^��Z���IL����'���(6�/@�~�����
��,z��(5�";j�c�������Q� ZK+���;V�����U�b����E�gXK�m�d����q���Zn�����(��� @�&M�[$�@!�OA���)�q ���{k-�,������>0���* �E�S���n��v&�L��.Q�G��������xIJ����������'����]���$�
�M?��E
��N`5�F������?jt�Lc/5�*E��U�����/����K��J��6���Z��j���[���m�<� ���x���>���Rz�8�m��S���ri�
N�5dA�,�eZ..��zM6.��Z&e�{}>�Ws`zU�Me�
�;��E����Yc��C�)l��{����-�^�����G�a���t���\�%�o�)R6�g�'H�������nY#��0��K����m�
�9��q���)�6Q����+������V���]U�n������V���J����D�z�B�4�����b��#��}Vm�N�`��sD�&�_�����FT�Tgu����n;�}w�~{X1������x�$�#e4 0=���[Q
����U�&@��@3��|t���a�
�6�D���LT��L����f�&)�����KM5V����Z���I
�i@�H:�/��`�p#���d>7��F�$h�L~�hN�����a�c���B��O�2#��s6�����������"k3���40����_mE@�o���=���7x ��
q����+���}g����8�Go4����Co7e����3���?�kKC<N~K�Q�u����X�������xt.��T���/���P��J�6�;3�
�Dn�wP[69�d��Ix=<��#��A�X�My�'_�������u=�]G�hZI�ne��3�EI���o����3�u(�~b4*C�jV����R�Q��+_��|w�*���+w<�����p�>��N��MS��<�f��S$�/H!�Hv���l���%�=���w��K���)���r�U~W�,h�"�u[63o�a�|(]�E�LP��c�jA���R�I
��� ��~	%�FM\�4���)Z"��X�^���pn�Jc�P�g�AQ�����k8���v���m��3�0ukO_�2<qSGpi�?�YW'i�,�B�����������&22kkk���	���+����U������p"##���%""���$�������P��MFca��e]�(B��s8�AONL��q��tp�bi!w��*X�{����\���W�
B�����
�������.��i�x�:�5*��Q'�sW����3I�\u�:�(P=o�tN�KB)���^W�x��r�q��|=l#��:�����p��eex�@��!�XI[_s��t�;�Q�����7��3�����HN���fj�����1r���A,��$����C��������3:�7���-t/j�V%��f�����7��q��.1�Wn([���A��a�U�m����ui��a�@ONA�C
��?!�����D��@J����`r(�N'���&^��y�q�EQ�w?�nO�fX�{�q+J^j�G��;���8?���?��|1������~���uMT2`���\��H�d����-����)�;����ph5��Y��}����I�v�������6$"FA�\�Fa���wk��]�0o7�F;����]�6:���(;�6/Qq���������[7F�I���9�<��y�j
��|�R=;����s2��*�J?N��l�T
����Ur�L���>q%�/f8G�}HV�m��}W���t\����+������g'j2C�|��!�����������$��5n��>��HiM�;�M�m��0~��B��l�sJ�1N�ZS�V/^��	�5��EZ���H;�w�I��ep|�5���'O�)KPu����JU2��S'��
���
�Q����H����u���x�{^�yS����>�
�������yxq>�vg����fj�J��uRC@��-�������>���FN�P�Mk�{��fU�.�A�e[8���Zz*��iZ����~IF2��+���c=�2ef\`[�U�:1�
ens3R��Mm�*`d>�j�
�D���@M*��`K�����X*�����x���c��3���jX�>��Mc���X���%�������*�7�Z-�������<~��W�?:�3����mptv�P�U���=��<���J��s���
n)��9f�D�pvPs��� �M�������Z��P{���a���Xw2�cG���z�N*D�Qs���y��~��������"U��'�sgO�i�~��jL��%Q���]m$~������qL�HrT(�v�����$$�1�OF�bN�3�VH��N��5
��/\��-��������vB!�Ey�|kkk8q�)))��������'�<A�SW�^������s��M����s�e��������~*9��#&L]LP)�}�)
�`��7�7���?V�DQ0�0���u
�N������?��j�KI�V���'
�(�@�6���4�z����*(�.5A�dN�)�����d��pj����?c��[�������v�bh����Z�~�,��
gC�\)�`�z�):������?��$cM#�sR��I��S��z<��U��a<o�x��WPa��Q�X5�j��M��n���j��1���x{{�u�A��3�%J��R��L�*^����5�~2���e����~^<k~5Q-�<{s�%E�<ZA�@�N�}�~��=SWW[���Fn��r�{��(Tw��	
����q�JK|=#^uZ�n��v�X|�?C���r�,��IV�������'�[�����*U�r�n�r|>�w��spw
�S��D�C����u���;������Ut����3g2w�\�����Z�j�BxY�Xw�w)J�g�g���g6�����v�Hh7����[ IDAT�+�j��!M���2�;�[+��D�u�2w����D�9;X�^AQ4�u��
��3}Y���x�i���wN���C��
��Zc�V/��:�Eg��o)��,��*
5�$����)�o#��������U��� �mCu�'}�����~Z
�Z=K9J2�{��q�T
*�)�X;�����U�q0����,����g��S������'����	�,��t�:}���P�W0cB���I�����a->Z��_��W>������f��Me����j;����dN;��;���7pJ�����l9v����2�r�3�Z<?����H�ozf�*�m���q������Zs��^�)��5q�h���+�\:}��"������k����l=3\�W��xy*�������^��z(�v'0�1�3�EPah��u��\�	���o�g3�g7��h6�S�����u�yM!�/��
H���F@@����FO+X� ��#,,���9��c����#""���D"##	������x�.��x065A�l�IG�/���&��S
�015A�G��
�R��!bqMK��>����T[���/Ni_=�<��O��������T��wl��o���,8�d��N�Kc��z�:*�����(���q���Qw��kv������TE����K����n�)�C	�2�t���Q��%36.&��7�t����/��6���~�!�����)`h�����% d�o?����r0���E��M�Q�by��041FO�#6�p��%(��O��}�e�|\���Kj_J��H��*,��R�J�T�B�J>��^a_��G�og�K:������z?����:��M	���2����<�a�kX1o%Q�z���������g3+B��E?�����qk���	�X=s9[�j����D����7q�Lk�g��a.��j�M��h:�}
�3�L�Vn��2�������B�)e������J4��B�U
�U�t~y�T��
�z��)����G�+�KI�r��<}��$�}g�B�����q~l������*F@I="��^E3�o�g�<RY�����:�X������x���g�B~���ph�i�VFm���B���/0J�K�z����;�~v�v=xj��
hO��`����a�_��+��k����+L!k��:���s�dV����S��?�&�G���$m���U���O�*��U�/�����9}�,��O�]=C���Cvr��>��`A������u����������=�|�T
�M|ipv��7ne��S������qx�����U7ne�D�"�y[����q�*C,�L�<8��/�c=`
���q��
�Z��L��i�v�]�|����s//�IDG����3%���&���a��a���
��Mn��(X6/�(`g������3%��W^~P+!�B�N���.i�����(?~�Q
���J���-��z<��}n��v����T�R\�~���d���)W����<]�wLL������T���=�G�zX���365��8�R����Q�F�{��h�,�EJ�^6�z���dl��^sP�0�Z3��,GZ~����&���_�/���uL}���h���w���&~���uf��J������t��L��JV��~�|\i9����V_��E�?B�J���/��%�Vma�������A"�D�<~m
U��f���\��)
.����_�i�xZN�������������q�������������[�A<���:1�� �_6���)~9���?ff3T(+���O3��>~j����N����P�����=x��X�Z��������8��6bdg��V1n�A:��cA��*+����%>�D�)�iq���PGb�����tbM��5��9��Hf�kS�:��?������]��M?
���oe���@�	��v�\S,
%��d��|��	��R�Y��WC�.��*Z���Mi_�+�O��U��4SaZ�5��m������5'*�P�Z5�����={rUk0�)5�������oP�}z���6����t�Cj1ih}~Z��q]	�K�
f\�}*�~���������-v�����cU>���v�*"�eC����PT����R<8�����L�����/d�-wJ�A�_W�gk���m>�����h�Yah��4y����k�!AY������
��|E�1��sr����EC�-I�)i��5=jzb��7M�������e��Q������.�;���l�4j/�����*I�$��	!+lm������!AK��_G
��� �h���17 #���MjX�m�����|���?�W�^�2������S$���6@I4�w�DW�'��IfC*t��
�{P�uI�O_������=%��8L_�9V���N�U��gh�g�����h}�}_�n�Q��L��N����o�_��0q7�n��)����{8a��bi�*���)�~I���`�6.�*K6�+��W�*�����P�H<���1�V�L���U�V�R�d��<���0��w����V��!�pa���y��u�`�I���C����Q2�09��@�7of���Y.��eHn�na�_wq�t���URWO�����m�w/O%��l�����u0�1��:S��	��=�
�O���y	���<�y���p/�h��S��,�6��0��v��������kv��sv�Ol�]�v=����������kSz4/���=���fA���M���B!��������o��C��akk���#'N����5�m�E���`��\�v����G����9�F������=065z�����>C����LSST�8b��P��(��Z�Z�b���t�����B�zR�k�����Y��&�����?���i�Q����a�����m�b����_��:S?�O6+N���!}���'{�2��j������ed��i��k�&������}X����'���VE�0wFC�~C�E�$kL��s���3��qj<:1c�>�8�!���ss�W\/#y������z`�������1����B~U�d�>k�6��c�l[��/�3��D�9S��06LHE�&3�����I�xT��m������������i�T��Hc�TmN���u�5C��Jp��(v%����_5�6�5h�PYQ�����:�o����8�t���W�3���^&�X<t��*}�3|�d<����Nh5���?���V��<�];��
c�Me����qO���/-�6�sZr�3-�2l������i ���dU9�[�|������������3}�~�O����c��]Tf8y�Q�m 	:���&�����f�$bY�*�~�����@aR��F5���/�GS6ts���/Y�k�M�K�_�����l�0Z�z�$�)V���p���y�NK�?;�e���H@1q�h����.7�
�Mc���[�����S�p)V��5�����A�hf]C�Q��� ��������������P:M�K7�
XL��x���Q�2rNZ�JB������.��ZA��k�X7����BL�V��h0n#j<�yR{���?���A-��`�{��L��[z���/�������c�V�|�>��T(5�|�1��X�jc>�����h�����NC��{����WV�*H����i	`K����0��������cqk���O6�~E��c`����������U��K*C�v��k��n�|R���q+��H�>MC������j=��a��zx�������0��
*�����\���m�h�M�����`���0�G
��thL���;T���6�=��2�lM���~�&��oA�wr���/�{-�/���P"��[_�M������������4pO��o���i����.�q����!�.�`�:j���������,�����E�v���g��Cn�'7j��Q��5n���s��|Z�1&����y��{�(z�X9yR�m-�yvTh����9r`'���1���T}J�c�5Z��������O
�F���z~\mG�v]����������:,	h\<����w&���gt�!�B�4�������<r�~~~��^e'�Y���FFFDGG��Y����V�9{�,*Tx�86l���I��Yll,����`��9�=�8��_O�z�r�~�[96�mB�rpu��$�-j��m����y�,�?s�����*���
���	���-��koT�"X��5e������'��}�~�zZ�n��sJ�)�L���u�8��d.�O�v_1ux=\����/�r�F�_K��p5:|5���Jb����;�i�VB����u`��q��6%�c3z�k�fB�l��0���t/�U�i-'V�ol!VD-�E�{It�@�K;��O=��B���8�6`A�Z�_���%�P|�����,]�=�O��1���\��[/�O��o�a��a��������n������a��fN=P�t���R�o��S��3�MW�W'u+.���AcY���z.4���������u���~���M!S��������f�����d�\������w���:K�W�Hk�����*t�pu�7|<t>�.%`^��&�bD}W4�.|AE�b� ���3�~ekl�>`n�f�m2d�t����	gl&��!�ua��oi[$�NP���=���C8�G��A�pn~O�}����^����=|x��aY�f
u���4o���l��HM>YcP�V��<�;�y�!�B���XrRG
>~�8����@��]>�����_����^���-�ms����~�z�����%���#,Q���?���S�_������x��-�V���}�3X�WDL�.�w�I��I{�S��Y>���w����5k�S��S�3&���
>�!���koV����k������W��]\\2]�6��qT�W/��������{T���%���B!�Z�9z]��������6Y%�B!r��&_d���O�����aV�}
����u<�C,;��n�7�x���x�h(��!�h��AB�]rc[!�y)O��fff�t:T*�+kJ�V���t��==Z������+�C��)�����y��!D����{�!��F��]���d_�w����3����B���Yr0""gg�\���:��7nd�|��������+V���!�����8��$��%N�8A�2e�t(B�Hn�/u:���s���3 �B�oy2 	��+WHHH !!!/�{���fff��*���Btt4����$!^'lll���y��!�+���MTT��E�<ekk���
%K�|�r�������g@!����,9(�B!�B!�x��C�	!�B!�B!rD��B!�B!�B�S�B!�B!�"����B!�B!���$�B!�B!���$9(�B!�B!D>%�A!�B!�B!�)I
!�B!�B�OIrP!�B!�B�|J��B!�B!�B�S�B!�B!�"����B!�B!���$�B!�B!���$9(�B!�B!D>%�A!�B!�B!�)����k���C!�B!�B��e��W��������?+G��M>B���-����*�������gL�q1\�N�q��y�7v��x�{W��������� ���Z=.�������l������6������l^���������6��x:n�N6����$�,���6��6/�`��,���`c��y)c	6j����g�{#��
O�H$��������`�RbXK�c���D�!�������	�-���v/����cb6�t"�lU!�����c�g�����@=����F��/?�4�V/T~F�.l��y�6.����'� �8�������,���B!�B�
I�b!�B!�B!�)I
!�B!�B�OIrP!�B!�B�|J��B!�B!�B�S�.9�_!���x����o�x�=m������2�gh��o��i�\�����N�X2�62����<���y����2Tni�:e�g�6�2��iqyd^_���\�����2���^��p�i�h-��-_��x��4��`./:I�����H<4FO�#�����N<-P��M� �B!��S%''+�[`��]��h�B!�B!�B���{���11����f��
�~����/�����x��	KL�C��:/���k"��]������zx���S���)<��S��}��w�r�g�a2C�����x��=������i��0,���q<�����C��:/��az��0�M�����#a�[�0��Ci<�r�8�������tlxe^��L��a����I����m\���.����WR�.{�-��/�u	P�g�X�y	<��_l��}7��/s����.#R��)��CB!�B�7j���/�G��.�/_I����$��o���@�/�B�X�0�@�R,H<J�q��yqh�u�cAZ����M-mR���&�M|���r�
+>�N^�����=*`���\F�q
J���m
J���fv,x��~i��S_�m���a�4��]�@�I����#Z{b�3fX��~M|�{�\���.4��~�\�m�1�,�M�m��]M�O�-��5Y]>?��!���$'�'{�b�_H!�B!���#=��J8�V��sP!�B!�B�J��B!�B!�B�S�U�b!�xg(w[���^m(W�U��t���[�$*T}����u?k����4!�B!�/D��B�&��[:���@�>�L����gU0�%r��������S���B!�B���$��-��-F�Z�0Quja~�%;vp}de<��-�B!�"H��B�c�\7��5�3�pI&T���e�$*���peT
F7��;��yI\����]Ws_��gY�B��l���Dn�h�7������G�f�]
}
���{����B!�B!�O��!D�(<�=������������?�}��<4�L���Y6
~�Y]���G�����a/.V��=��F���M�e�I$�����Y����0�I�<�G!�B!D�&�A!��	�m"����5P��� 6/�Dl���I]l�	�L@{#�\]����������5�aT-�Ty�B!�B�|M~:
!DNh�%�|2��c�~�T�R��7��n���&5���y�J��^L�	�p�8��#���{3�!�B!�x�H�A!��	]���,�L5��f�����y=���� �e��HR�2�L�?��=��z��!�B!�x�H�A!��	�Ff���a����}S
S���*�4 ��.������A�"X*aD�/%��!�B!��#�A!��	Ma\��s�(���y���u	Uq�T[Y@lt���)�����,
�G�)����)��ps�-�9�'��~N-_���	$��/��K��}�^��-�B!���$���"'T����=�a�7�T�����?���	E�o�����re0��;G6����Q��q�
��Dy'
��})����ng���;�G�(w.����*)$�����yP�+��9�G���_�4�O������g6}y��T��0�o����.j��D!�B!�oI
!D��0��5�����)�Zz=J���zMP�-�W�M{�����0u��?�R�?���dy&0�2�����&&�E��|:���%�g���Tj=���p��1��EA���#u�B!�BdO��B�c�8�I��#������_,��/2�l@�,�lL���i��j*����:9�G�i�_�>}z#:e��������������4M�[F[Fi�{oYa�,�7��""�E}q0\u�
�Q�"�R6�������������M��MiK�?��s�s��NzH���B!�BQ����B!�B!�B�R�B!�B!����a�B��-m?�_��S����g�K�W$����%�B!�B��B�n�i9s-�;!�B!����b!�B!�B!J�R��x��|�Ge���B�>��sy���2�����=}���8��Y�u��n���
!�������k IDAT?�`�xmC+����'��{��82��7l���NqU�^�������x7�VV��bp��o�"������6T���GP��;���$�B!�E�b��w��@IMM�e�-����g��7+!�B!�B!�Mr��98=��S��U������Kj/��{�>��.w�Q���D%o��e�/*���`������	f]�V:��h�^xQ��1��3�S��l:���!fce���1{+�x1{�?�����,*�<fCQ�1�fv6�J��Y�,�K�0����O������[FO���������WQ���c�e������?��(�V��G��Z��_0��7�J�wW�������y�+*Q��1'��--"|W�!�������3S�;!�B!�;��=P$UG��W$���m��x���Lz��[�@mE$���&�r�%���`	�a�w��-C��2��
O�Q,�V����X�3�/��/�P���,>U�H������v,u��?�1�7"���\�A,����'o�b�X��I���������:��=���-��[a[������v��~Dj��nC�I�2���X{K@�<�E��X�OG��H^��MQ$��B!��Vd�/�:�'����MP��B!�B!�B�HrP!�B!�B�RJ��BQ��x��\�������S�����+���L�Q�����V3���
�p"�|����'� �����
�������#��c��0��zb��)L��
C���
}�0I�C7X�

�������!�Bq���B6�Q�#������A;-9��?^B����O�����X�������:�p�;e
��*���:x]�u����K�`�
�����^!�B!n���$BqkP$���D?��Py'�b48�Q�����O�ZM^@bu�S�0X5X�A?�S2��Cr�y+�>B!�B�"�+�B����X��.N�J�P1��c����J+'^��g;������88�U�^�����x��`I��8����S���(��UG��o�fTX��={���U'����k���
~�8��?��NU�s=*��7�z����B�Q������J����
TF+�C��dM~�_T�T��@��+p�y>��OT�U��@�����z�]!3��������������H���/^�^*���V���!:��d��Vy}�B!��EHrP!�H\�_L����w2�G 	��f��$�>���~��U������i�ly0�C�F2��Pt������Q�����V�8N�f�o ������w.��z6R9��j6n����5���+���Hr�.�9?��=�>'�e�O3���2�DI�U�

4P��}�9!U�Ta�w�����9*������
�b�xH5��l�z���4h�@S\OV�[�g5h����9{��KC��m=���R�����-���.!�Bq����Bh��|'�Mz2zj���v��a�g;���� w��+��T�k&O���X9�u�@1Qc`}~����^�N����E�{�Q�^�r�S��R�z}+�:.%*�5�=�����=x|~g�{��l�Y���3#�&�J�T�����@s�g
�0b;���u����^K�Ym�����Ua0S����P�n2_��`�
OX��~|������G���L���C��*,Ua���������o���B!����*��h��k%�u5��_�����{�E����m3���k}b��K��'���*��6c���R�T�\��m=�$�wX���!e3��:�����i�]��ZK��4�4��@�+���Bn������S����X�z'�^}m��w�[���o�:(�K�%
��O�`�Y�����@4p5q����B!���3"�jI�`�w�(M�`BIM&9[O���Y�F�|�|�~�w�_<Zr2)V0�2GT*^xd����'���rf�\f��P��b�*�xM�P����(
��
xj�!��
������s��H�6��'�����w�����nI�O�OU���-��
���B�s4@S (�f����#�B!D	'�A!���0�Br�����Ih_������Sg;5%�
 ����]M	���qHD���3a����44����BJ"h���/O=����ow����*�y����%�R�!N��6�1
�����id��/����K�_�8���	0����-1�����C�����:�>���#�B!D	$��BL��z�n����O����(u+b�'�+�1�$�'�.r�?W�A�HKJu�%f����FuO�����7�V<�
T�	�'#��s�=�fVn��D��#q�V�\u�[����L��k����E�!������{aKL������^�����f\_�V��0��	p]��N�;�s�E�'5[�F�S��ql���n���m��cN<����!�Bq����B(����]�,���Cd��%���I��M����ji�����x���XN~��]'\�� ����5�����]���T�m�����p���f���G_�F�k���6m�FjbG����W���@�k����|��F��q�ckw�}�
��Pds)��K�%�z+�����x;�o���*���>
���3�2
p��UxK�����V`�������3T�F�%�~Pa�fK�iL������z
���5�!����zX��*��`�5�D�4p����%
7h�S�(��-���hr���M!�7�+B����7=���_X�8��U�7�Az���X���+������a��e0�I�.GY�\�'5����~e�}���
��e���.F*��jF���p05s_��(��K+X5f&��	�����c�C��V���������B�����fj
����,9�j�a����WW D�%�z;q���}*��B0P�����V��^VmI����������z�X���-QWI����4�S�G�}�����bi��w4X��Dl���{��|H�U�������|}�k��yq�Fdj\!���IrP!0|�]������(~���(�Nt���6.�����wY�:�������V[�9�4�<:_����cwv����m:2pi����o�&��oP�{Y\�y<�K�y�����y�e����.�)�l=��l�,p#]Y��.������D�(��#I
!��J��B!��p�7!(	D������u#�B!���$9(�B!
��D�$E^�;�Xs��B!r%�A!�Bq�rK��tL��"/�	?w��Z.��B�'I
!�B��n��U9I��(���-(��B�"�A!�B��$���-�sb0��`NIBI
!��V����2��Z�z��>�������<3������]������n{T��m4e?�`[����o{��2�y�����\����4�����5{U����d�o_���Bq�d6V}���eY���$k��e�����������C��M�4��C��i�9fp����iNY���Z�	BI �>�J�)��r*�(Y�+��.��vL!�(��)E����^$��������G���Hz��y��B!�%P��������������[OF�/�����������B!�M��98�|��wf�g�m�����;��,��mt����3�c��o�YD��1�:���I�b���=)��X�=��R+cV9��7f��dQ���=��2f��}�s1��������"� ������=-��a6�%*)�.��:��`6�W�f�X�����9���L�x<����O�[$�G��c�y��b6y���TX�~[�J�.��O�ufO]��+��W�!���_\������7Fsz�9n:����k��9���=q��1G����>�^�Y��95$9A!���/�.e�I����I��Qb��`K�|���u�	�����x��??	,mm�9��P�@���^�5,���c0e���c["�Oa1Tv������[�qD\K@��m�a15$")�wC����`1�)�o���-��Y<��>�`��n>�������w9�b��������{D�1,>��]a������`�7�����yB�.7��x��\�����������<�
�)�h.��'5�� ���S2�P�| �
!�(D�Z�^�����^��(Q�A!�BQB�'1��O���C��.V"Y�[����m�!���5��bO:�%	B!���HrP!�B���_N	B��A�AX*(.~��s�'����g��{�JJP!��!�B������DW�H�N_g4�?��[/@��i����������h���������7�2���mK_x�a�����L����f{�:�wL�X_�<Qd�Z����o�'��}��;&�{:��e�1!�"7�B������}=�"[r0���]�_��z� x�Xa��7^Fg�u���5�
�������Ei�u<.{j�]�%G(�B�J��Bq���O�u��;
Q"��|`/o���p�{�q3�$�������])J��kKqH�S�O�B!�K��B��..��Uom���$��Rw�0z���X91�>���'W��� ���?������U��mfI�9�l�r��L��#��	��U���h'~���_q"�@�]
+����6NE%��!��ty�/��*g�g��O
��7�
�>�Cu�A4�x<`HWx�z�����`�N�u	b�P����B��Kp*�\���t�{��J����pI�*m1
)��D�s1�7�|�����%9(D�H��T@�m�c\��,�B�I
!�[4�.�����o�=�D��_Y3�m��^e�@7��5c��9�i=����q��S�x�":t~n'�J��)i){X���e�}����-��^e��yN�=E�5
�*��b�N��V��v��?@�hQ�v��y(W&��2z8��X
���>����`�!�:���-0c)�>��m�q0i1l��1�����6��!�IMqks���ai�����
QXT@�e&�����.��#B!r$�A!�p�v��m%��]�~�et@�p�'������A�;���O��I�
��������	�0��cP\O��K�:�=�5��Ps��xD��]
���@�V0h,��;���
z:�o���Spg���C�_��aR[��MY_����l�vo��xkt�����*Q%1x���;'��U�}B�>����=F!�|�s��G�B!����B�#�,gX	j[���wN���v���Gq!�X����fE�����������K7��J�K��A�`8}����.��}}�A�7��[�2b
����R�EX�'�Z����!
@��O�oUh���|�|�(5���x�e�9x;%�hV�^�O�S��q�k{�c��;���^�|su}e���16!��&����ZI�`09�T0x��$��Tl��J�����D��k�a���1����Y��d2�n{�dH�@K�Y���x�?,y�?�|�Z�I_5�~��J�vj
�h��2�Tp1���������q~�y}=���+�v�_O|�����!�����cY�B!�p"�A!�p�b�����Y@���D4OF{�P�9���PS�71PgF�
a��7x��lx�i?~��%���RIt-1���x��i�!2��P�,T
kj�����Z��N��m�OL�`�I(J-�}zbFs��h�\$��G�7���v����qe���
�M�#���O����xa�j�4�h��_HW�����mqh�������
?�Z�t�1�� ��}�?u5�r��%���W")��K�����O����0�K��kF����x�������hU�1^>���k&���X������C��&Tj�s�\�xe����k���V��S��������o8Z��V�S����ZsLP;_�B!���$���XO�����I���]���gP��	�P�
����HH/�v�G\eN<�{BZb�M����)�ydo�P�v&N�6�D'O����L*�s*��� T�����Co����+����bsn�S}9���
������KP+��SP��a����U����������\�T�����	�m9��C�.��r���5�{�{9Q9��%����G�����,��m�u(��b���l��]�����}�b��k	�~;����u��t{jWsX|%��/��\+�~�>���K����.�|M��c�����xT%��R*�=G��vR��Y|��x�^]���s�x �ms^���}X��g��=��1��'
�.������9�����2O	��q���m	�����|����}�	!��m2H!���Q����>b%�_4���2$��k���Ak�<�:���������]{������?�+
��T�>��Z&b��]��T)g@X�2�=3�hq���o�8a����	a�R._!���q�j�����4����A��[�1+���~�j����jv����
����<���
���������H�
�L��C�;�t�\�\�$��������ZF(W*�+����z��_0����_[�/������&-��~������q���3��� o7y%\������e�r��Y<�����������N�"yz�W���.C�������W1n�
.[^f���S��R�T�b�B�&�ic���W'�k���������}:N`��
$��<�*�/j5�%��gi��������O����6c����t���&�y���i?�;O�;{�*��=	�S4���e�o�xq[*8�`�h�����������q�� �qma[x$�z�m��,J"�B���}�B����m8�������Y�y2�Ro�8z������/��<�O��2wry���m�Ys��>#5&�����*I�������C�w������|��r��:����(|�E�]��kl�K�5	06g��'i��`�m&��?�4i5�bU������4=��%P���L�t0r�(k;���)���H�����]���Z8���>]a�J���4<���/��;�0����,B+�KC��o����}��L�*��BXE�E���s���V�=uT~d!�=�CI��)S�h�z��|�����qd��r<�rv�R~�jf��aY�yP�c���e|�1���m����q�a6oO��}
)g�����7W&�k�+?�%�����Yo��mY����2�fj+����k��K���l�~R�kE�jADm����0�6��L�:��{y�?�?v1��t�8�i����[wqFmLxi���Z�m�~�dn*�	B!n�$��m�����s.��S��	<�����qQTonM��Z�7{%�����Q�G����4�#bc�n\�-�R�����C�������5�v�q]�#^/��^�e�����SY7��^L����NC>�%(�|�p���^>}+��%H��t\����H�nM��n|�U����U��i
����x���,R�r��BX��C��m���a�z�iF���)zs��M�����y�.DsA��Q�C�RW�
�
W�]"�����HM�)(>���H>~�����_��6�5��i4�yLiO�@O�9"Oq�J)L��q�5��-�A!������B!����H��oZ��Lz�8w��w��n[�4P����0s:����-�����2t����������K_`�q%�:L������H������z�8w��_��B�fui�k4���'e��x����u�{2�6�������m��fF����z�uv4�������d����X����H(������J��!�B�9(�B!��n0}8q�s6WW}����b����^5-�4���'�s��T�Y}�!v�����p\�J���D�9.���L�4h`_u�i:U���6|9����f �^:HJH�r$��Gl�w��U �SD_�����q�B2`oG���h������O��+��8V��6�<����y��z���#M������#�z�x�������4v��Xx$�^����3�B�I
!J���?�Tn�e�h�Z��oZH����������K�/�<��*���6��8� IDAT�3��bX����0�?�t������t|y�^����C%���&��u��dtq��"�
�'�c%=z�6��O�^6�Hap{O@���c\6T�F�]`S����d�v���?���f�7���z����[����<�a(�Y�=zP���QS����SQ�!�2U��o�������B�'I
!J��s�eq!�%�;���r�.#qG>��������k��V�c���Q�V�V� [���!�����������yftV�B���=W���j�����zR��rj�_D��7�1aTg��j�����[�rE�My�{
gd�Q|8v��o��m`����)�4d���|��t����
c�a�Bv������i��c�7~1I��3��'����Q�]��|/����_h�J][B�z��_�r��T*��9&�������3B!\���B!�����k9�q������r�w;f���V�^�;�=�-���x��J�v������Oy��T��o$?�)xx�\�:-�����c	t�9�����0>���/bt�������x����w.#�X���^��9�	R�T�6?�O��w�s�eO�;������N��u���b6s�[���6�1��1<��#������i,��,
`��7�?J�wf�}X*���\]��B!���%-�
e�b��J��\�l�+h8y��+�}�!$�>}=�}�C�&�{s���)<�6���g�7�:�V�1�!�z��:Y�oW?s���[�qx��]�(�7k��
�w����6-XV��M����i�N[���i�{UCSUT����hV���Z�h��\���~��L�{�iY����#q���%u\}RU�����<����*�dA�sn��H~>>2���� e���}���d���x���y������i�2t��O��n�X������V�}$kQ�k��7����25��r�Qt:tz=:�E�C��n:�b���Q2���T���X!������ER���V���_Jjjj�����Hz��y��B!�%�f�x�~SU5��j�f�����iG�o46����7�3��gQ<��r��'i��5^��3�o������M�k������x��V�'N�@��g��t�l7�� T��N�B!��T�=����8�sf��Y�[<����3n�5��V���v����=�c����(��1�9T�:2�JM��S�f��������%��9������f��Wa�_�i�e�R>�)��Df��euE��Q��#���Z����/������O;i���BJ!to-�(���
��?�rH��w��b6��(��J��8}C"�_(�nK�O�f��U��y�8����k��p�����
����Y��K��:*��
�Mg�����z��w�L��R�����M�z����MI���KP��G�!�(Y��t)������5�b�vl�-@D�-X��*�Y&=�h	,�������Y�F,�&�RW��M����z�hD�X�m�����`	hw�L���X��H���T��sa�3m`���ZT�}�6�������6T}=QX������"8|C������oE��|�C��H�����>���AQZ����� �PMWL�+4��f���B!nk�u�3!�B!�B!J=I
!�B�.�(�^���-����O����c��;H-�X�B�RL��BQ��X�>Z���W�/������w�J���z2c/�?���23�W������!���6�
R�(*��)<��<�j���v�q�`������}X'W�(	9��~���=����Lo�����e
H�����`���\�9��H����?�
I�>7)��Z���go���
��s���l>~����B!��$����1����A;-� ��={S�7�6�%���rHO0���_���x������Vw�+>T�U�Z�@��u	����03uj�PD�*ZO����_���n={!�B��_�D!J��������Py'�:C����@�f���)�y�|�"�SB!�p��B����G|�t4���2��d~��?�3��Y91�1�u����1R9��}L�+�
���%e2�o���=k<S�2�{s����{D��_'�����9
[�+@���Y�y�|/�+<�g/m'.[u*��gy�1�,;�5����}�K���IM�/��@��a�12��_?���e1���_C�y��]x���������g��}�|y:�Pd-��������0�}��_f�s���<{����n<�,]�@��a��d�`,
��#>����]����!�����pY����a�������ep�B�:F|?E�����xD��b�:
���������~<����Z�?���AhCL>����>��Z��1m�b�w�C������*c�����z��
���0(5P�:���V-�u�=E�zw�UO�6����4�o��G�#I�8?�}��yXcL�������h���������$__�l���A�*����\b���z`��&��w�b���Kt��oSC*6~���#!��������Wi���6��-���>������^dQ��(J
�.����X����|w*����l:���
r���]a���V[�jc�jN�VO��w'p���e���i\�)�>����5�9�>_���/�G���x��]�;]����	�R��Q�;�k2�uWd��Bq�H!�@#q��|1f3~�`H��$���5�����6C��H3�����;���e�Luz����CA���2�L�\��%���U��G#&b_�<M��O����������4�+���������H�:�;�����_���L�����'*�_�J�c���^������;F�����h�^�VB�>0�������������-��
p�(,Z	�apO ���H�8Ft���[a�
�	���Aj�����:�NZ`Q8�&�
�@�������pw{h�Wc`�E�� ���O�3��N_����	���*o�s��h(S�jAz8r����C7o��E,�}o>F�)�8�y��T@w�j�`t�i>�wcv�c��w�����������9��k�Q����-���`�W������9�5yT���,����c���S�����^;��_"�S�!>����H����Q^��yj�}���_�������q)S��|�.b�V&��o<F�W.�u�+|���S�>��#��~���C���a��}x?6�������,~�-�K�����������3�����r�<�.F2��X~�0�_>O���|�����������S�un������^k�R/���������;
Fg�b������?����'�z�F�m��c��:�7��K�!��1�W��s�y0�M����P��i���m���'���LS �B�,�B-��6��^F���2:�s5�}O�r�b�'��,�b���	����"0<�uN��������?�oF*�7�4�?���wOl����q��{D���^f��U\j0����������;����q��Q���W�j0��B�"�9+������PS��zC�����C�n��^mn�$P�_����������N@��0�(@-
�]���'�zB�7�f�
U��Z��i�v��������h�W�����Og�:���?�6��l��U��j�8������"�6��n5��G�����n*���e��`r8���f�������z??�k��\j� s�������~��24���.Uu��5�G7������b���`,_��
je~�Um�M�Z��[K2rj�����y�q�m	���*p��H�/���E��|�.bp�1~#s��M��_�������KS�N�`����=dM�S����]|���7���������ucW�zd�I��o�V����b:2�+<PA�a��D������tX������-���<�n��|�7�����K�������<��u�j���|�1V�_�������u`H={e����G�k/��N`z#�"�����kgqoxM�(�B����B�����4���#0�]Q	 �c�}��PD�

:Q�k;���g]���xOp��Bh�:�����r�0�w�B�t�����0�-e3��z������c��(C�J�J�|��sh�.��|��r�'�P�cu�?��a(\���I�����2�~~��
~l�P�{%)���k���}��B�Ix{�����W��g�;Z���;��t�6�x�G�����$Alb�!�y�#�T��=�@������T9��>N����_f��������c'\����F�0tW.s�����nH���=��Bl#��v���k���B	���>�#{����4U�F�r�������������������N�����{������w=�C{�yM����M9���b2��d��o��8�r�3��@'y��:���������=-9�a�����2������\��3����BQX���B��$]c���Lc�JJ��@Q|W1���=|�d�{�/-)�+��|2�@+�xd~���_#1�����0c�CU��U3��AE�U�x�����b!����]�G�X������Ih��:�O�up�u��x���e�y8%@sHz�m	/��t7<�	0A�;�
�=	5�K/\������~�����P��D|�����EK�P����
�<�4�+.8M���(
:��B*�9������I<�@��"Q��SG^-���#�P��u(h���i`h��Lg`�c1��<�����, ��X�F3*����3��N��=�{�g�<;�^
g2���B!n&I
!���$�:����������TtJ�oPjJA����0�#A������n����1z@rB
&��=-��$�������I���N����f�<^�$8�^��x�w>����e�F
�v����PA�4�-	��m3��[��H��1@���[b����
�a����'�%�����i�`C�7�J�R�����P�&��Q��>�lZw���z�mV���U���}}|m���b��$�v��{�M�x{A��k��KZ�f~��J���T��\���8�-]}�v/�
h���� �gc����X6���Z}�[�>?���"���42���I��5a�f���9������f6�5��y5��hql�x�����	mT�Pu{O�eR����&������L�<�^f���J��N�C�;Y��7���������O����Bq�HrP!<�����6 F�a��O�����(
�bP�
���q$�PV�����4���B������go]��4j���+�Q1�����u`��Xih{3O<���V�d��TsK=������E	v����[�Xa��A��\:�o��\�����z:������F�/U��ga@M[���p\��B{��y�C����Q�N���F�����-)s�AU�Z�mEf?�n��ga_*Y'������O����g���)�R��h�{�`X��L��=O�y�J��[H,�}��4e��6��aE�x����/�}���-*�|.sB������3�������]=�s��EBk�y��-���;}C�e���������*G��d&s����/�NLx���gD�k���U2i�����
|R���I�$>��_t#8�I�����c:�&��:i/u�Z�~>~�C���w����Fl�gL�O��&���`��4:�3���o?����	O������kX��	��4`���x��Me-��ZN��lL�p����.�#o}7��_f�3���iwB���BqSHrP!������C��|���%1�{��3Q���y�t�Q���uY������_����=9�/Kp/bW���>&��7�*O�`KJ�Bhpom"���j4�#��4z��^��M��h�,����KZ�<]9���m���{h;��WJW����
t��?!�[�d�E����p8sV&��zY[�|!�6�������~P���z�`tC��-�c9HM�cg�h ����0�
��	�����&[��k�������88� �+�EJ2h��o�'��B��	'�`LPf�M��!��#�n��p�4���I
�#�a�Nh�����_/=dK��~�/Ao�����s
*����li��_���Y���f��o����LdL=w��|�3�5������`�W�?1�{�Uv�t����^���Mf����z��N��|��F��w]�����'c}�c^�5q���
a��R�P}.18'1���E�����N���dj���O�`�}nlrpC3&-z��c���;��#�6���L��=Y��m�Nx���|����y��o<L�\���J���_���ak�]o}�����:�zT�����{�\��|�E��x��B��/���7������o0��R�^��xP���:<�����m����0�OS�.����B!
D�
!
^=����2�K�~��G�Z�{{2=e|1�h�������3wb0�����^��9�g���Gh>�K��OR
�?�*��j�b4����_�����}y��0r,�.,`�}��!�����h�)�����`�wA�6�W~M�!���u�5�+�2�S�S�	��3��0�-�T��:�����W��r����������O���k���*@�������
.����a�/������$�
o|z0��%�xV��}pZm"
�C`����N��B�Px�/�vH�����A��_�M$\��Rmo��&��9a�������8���/n"]9:>;�?�uq��.�����T�^3����G!h�"�Fe��W��[�������m:�s�b	����9�~\��\��B`�|�iD�%r����5$�tl����f��*
����]�a6'=�cl������c������?�fv�Qg����1���.��e+��G���G\����?b*kGL��d����As9�g�P!�B&I
!F��}�Q���eP�1u*�Nu�ym\�WkO�5������:�,k��,?o�<��>�<O>��s=���C���s=����27G�Q�R-x�V�Q�IS��4�6/��s�K��8}�A��d��`�h�}z�<&����an�<�LA�Xx,���U���N;k�?!�B!JI
!�"�����dhRL�������>W!�Bq����B!��;w�������f��*�`B�
����Bq����B!�+_��^�Q!�B!��,�'�B!�B!D)%�A!�B!��F����y��,������g�!)�S�zl	�C���G�Q��	!�B���uX���\�c���Mj�2��/��������Q.�BE���|LW>����Q����S�"eVCl�������WT��0��9��O�,�%�Y)����EZ������[��P��C��M���C"o����XK��l��������fU�T5���fU�����J�T6��8�������������03uj��/���rT�]�/n�C�W�������Qt:tz�Ng��SP�NEAQ�����������B�����K�<U1SRSS��
DFF��g���B!�(!4M�v�i��f�;��V���w��M��?i��)���b���P|��
�!��1`��C>66��R\[��������@����~��$����w����=��-g������������]*��f?�����h��b�@hh(J����B�Ht�$����Lr/� B�t�9|����!�{�s���� ��|���q��w��e���q���y�d�������O���_��R�1��C����^q���c�wY����P{"8l8!Q���:~n�,/�8
���K!������F��(������O�v�oS*$�?U�t[��dO�~��{k\�B�N�j����y�lG$����c9��,������q����k�r8���`�w;8z+�L�h2e>��� E]a���LY}���N��P�����iIW$�xv%�����w��<���
�2cf�zJ@�O������*CvJ����aEQ\_D�B?Rd���T`82�����f�U�,���0��Px�Q���4P�=�� IDAT`�����A��,=fLdl�,(1sk��M��s7�<N��_!�~����+���l[`9��������M�5�.�����C(����c?|�W����m���~���n�� �/&����3!�>�D�t#W�z�v(�
9���#~�Q�aH�N���������h (%K�H�7%�*�
@!Y����O�XA�r��t]��V���R�%��y��1�4r�����'��"1�RK
�����R�%�r������o�n�����Rf��W�i�4�zL:xX��\�����j)�	R�M�r���v��|rM��gi�i�������k��{/H]2U�-�|G"#�������T�%k��Q<���Hf�;,n��^�<�{jd������y���K��O���y~?f�����_E����4t�T�\Z���
������8v�����m��|P�8��:���4���<:��A_��H�V��8������6��'Q��LZd�yr�(�`������	;��	c�S��"�}WkBJ]��-n��
��xJp+��
���'�G=&x�(6�s&l�B�w�@�i#��fA��������������eV��A�.�?�9e�r��m�����EA�w-���� � �G$����![���WG��G�3i��v�gbKM��J�xR�+Sg�������(\���P�,�����}�����G<2�R=��J�!H��.��1*<)T�*�P1�~9��B5������e�V��gL��fm���O�z�,��jT��sk�����/��;��XI��|��4+NQ�A�O;�O�U�<��e�T/�kX-:LZ���(��l���]�(O%�K�h��/
�lQ;:/|����~�AAH'��AA�_c�v����T.�(1f�<�mejTuMh��R��y|�<��f�������S��@]�_��Y��.��b����l,:efr�(�z��X�$E�Ld&�����WI@���5\��sv�$1^?��w*J�7�A5
��v������������3=M�x���� � ��2Z�4��������[C�2���<����%��b'�<{�����Z6`d����Y�Q�2�|?~�t�'����bM�F�����9�jG�>{@�C���0��F���wQ�Oo�������b�aP$���Y��z�a��nJ�e��f�X9u+T�� �����?�������A�kQ��n�AR(Pb������MF���$��d]�kH
	��Ivvt'�r��U��1��mO��AA����� Bz0��ru��A+e��4_<�����n�<_�
�'�F�tFI�{_�]E/��	�S	���L��yJ@V%x��r��a��I�
P�9�C{/&��� k��d7�c��������{,���iG�Y$'���`��_91�!?-c�C�WF2)��z��;�W���$������� G� �
�TP�bn�w���{�����?���1-� �;'�AxOIrP�,Z	�Y�����}��������[]�:[K�W�BZS�`�����|��P��mzG�fnA���jS?���/=������R�����56��W�M�J�,��>+���p�W/�$a����(�
W�SN�z�I���n�hR��O�g�ggj�i��JT$AM�w3mRNZ��Aq�w&?�[�����$
�����
��.�>E%�<p�V�$���U2���
���z��rg�B������m)���� � �[��u�or��dj�nu3|�$�L��������g�c��F�O;P� .
��`U���'��][��
H�Wea�.�W��a5�.7G2k+����99�����Rx�-/.d��=\=F�3�<�nK���p|y�X��u��6�(a!�H^d.[������r�o�Y����x��}���bP���@��i�F0:�?���>Z��0py@k�>������F�����p9�J��~��@�{�I[��+�(P��`4a�����6���|B
�^K��w��w��:� ���H������h8���2�3B$PM�`���Y��q��	�;$?
�i=,2�u3�*��#�QZ��0 2h`��2M�ar4\W�
I:�{3Y��ca�	L|��OU��B�O|��`�	�4t�q���Ti���w=�4�]�PH
����,���`�	����Bu�A�4�2�7��G�5��2���]���d�Oc ����&�69�d�J	��p�������Y4	�i�����*@s��FX��S&@��*�q��}�K�9Rf�b�{N���Sh=5�}(3p&-���m�2��&���^L�r$g�������;m5>�������g�*��)T��V��@f����;��0��>L�Q�����U)���j�I�<������q��b����T����w�a�>:����RK�L�*�l������_.`����~�G�p(M�%���[4�A�������p��o8Y�6����?��e������z���	;��	�Y�O��(2��h��l��'��k��0����<�.C�������`�:��s�x����f��8�
����[�g.N�q
���"��a�=�_�'���`>��>;��[;Z�����;��H���9]v� |�db��c��C���J�Z�9��]_�$�e-z����K�[J=��}:�+F��GNH(\<'��1��d�����p\�J����-y����1������~��Wf5�P��]�0|�-�9�\
���HVA]��-����#��a��Ul�8���z(��Q
xh�E�����
P)`����n����H03��A��P�a��aa�h����xv����@!	6�,�U�����M4PA��p��$$�2L���
����P�4Am�%�v�T�G�u#��'g����J%Lw�b^?���0��&�:)�+(�����S��%����F�<���`�e:����SKEF����y��]g�D���/�Pg���������L�_���Ug)�������_-����.��v�>m�����rn��\�I{�XF+N��?�����$�'�"n�m��4`
���F��(�$e@7��u�k���?AA>:"9������M��;�i�K[r���3?���<)���?6$�� ^���]���]��C�%O�R8t9��;�����x�������9lVd�E���(�+A�|8�\a��}�����j	�Fim{�W)?��}X��2���p�n�DH��U��$��2v��.�� ����\�i?Q�:�yt]2(������������o��=�v��l�`��Q-�t��G�,�&��f3#���XR�V�3mF�M�=�r�%��=PK�f��_�� ����.pPBO8���6A]����#Tr�v*K9@{�L�Y�����Q�3D��/h��L�s��F�����Z;A�Tl�����
�U��h�j�VP���������]y����V���	J���&B����E=F;AE�����	I� 
�,S\����	�mN���������
�Ht�@v�R�V�593X�w�������i��MQ*��h���,��#p_ey���r�AA��#*���#�:t
�3Shl;�f��e�����Lx�/����J2�����[�b9�u�\���78��!f�t�nf�P�\�jI����'�|���Gy�6[O�c�qa�,���D�N���������Eg�A[�'���r+�����km;c�����l��la<��9%r��E�t���` Xe�V�_?�O�N����d���u��%F���eU����$����!NufK���6�V����fy�	.�P9I���Jxb�p�iM!�	��Y�Vm�
"	�����u),�zng<:3��l��Ui���o���
K3�o�p����q�Z�N����E:��d�(�	�"a�r����OZR* ��s	�R�.Y�l{AU�AO��$����4AA�w���-�S��-L�"�87ee+5!����M����	_0~��BfL�/�/d���1Ee����<������	�H��?�$W-�����	5��E� �rm�$�o�D����^�hTf�|3���M/���%��z���sw�k���q&K��4�L��,���c����mG�7g$C,:o���
���K�HR�~����o%u+GP~qm����?�DBb'��tr�}]���2��a��t@ii:��:M��jJ��UU�?����9"g��d��v���--7m�C�j)��}����0Dg�!HC���g�n��$��}�c���� �u�e1�8I�m��%)��,]*�O�!
�����4by����?OI��M�AA> "9hK�M��C��������yv	���
���qrP�7d4�k'�lIR������"[�
dXt�s������l��[&H G��3����)2N8�J`���md��kj��l=����9i��27kG�f�0G?���5l��m������)�Y��R8����}y��^D#���X�"i�^�!�� R�!�/��1�-�AH�������������d���*$��H����'Xj����Y�� [*��NR3-Z�����x�����.kr�-�����-���0'
*�����/�I���&4C;gK�����C�l����������0c��(� � |PDv('�J�y��`PN�Z����K�J*yr%�2���dBk�;]Q�"Erf�j�?�K���^�p.��L���_J���)��^�F�z�x��P������V$P8g��c
�D����gG��g�{�~�\��p����e�cAl(}������s������	=z�@��8��@x1�V�]�H���
���vW2��O$�8����m�y��W����7��<����J�����F�?,#����F�P+���2�PX����r(.��0K�0�
�`�>a$���g�'6���!��2��=��o�iSB�1��RKJ9),#>��|b�(!�&��m�
���@�	.| �:�d�$)I�41Cf�{�C�����d�I��S�����������u��T���W����u�i��Wn��#AA�����R����T�:����wKc�:xQ����h1��M(��/N������Y���krPzS��?�F\F���5�U��p��q�_�[���<�/������]V�����_��\�3�"�6IF�+����,�'c/����k���c��*�s=\�nc��x�����6��D�	�x;nC�������!y��S���f�h-Ujg$��zvr$����~x����C�\�Z��^���2dIR�2#����}+�k:��Q��=32&\i�������hd�;9�`�9Q��
��?}LL��p�����w,������s[�<����xka��sdUo����������v�B�7[j�����ex [�1�%��g*P_�uP�	�?��#�������TVZ��a�
���Rn��V�lKS����
*h��k��&���
�`�����{�Q@C����@a,�'����`{�U@YdN��=l����`j,tr���5Z��R
*%�`��h���t�k?���R�Q�-I�3<�,��)��Ix.l6��e����4���X	4PZ��0���<�f�����X���L�9�S�ngw�����
���q 4����z��+�#s��~9��Wi��2��
���n�{�j�Me��� � �'����8�R���\����s��u`N4�Z�i�;�O�����sp��@^����[�s,	��E����YI���
�C��a��.��^�������[�z(6�O�`u��0yd%W�f�n��-������M84t+�f4~NB����o�Y\�{I8U�E�il�n	k�C�����c��0�����lk�c���L���)_��"���H@����|)���%�n'1`l��-Mg7���&$�
�g�+���-�������~�M���=�1�T������AH2L��C6�������d5�u�y���U�x�,Z
L�`���YF�����JK����o�4����[
��07JkS6H�J�ab�e������&���x�8��8X���tq�&�i�s*`��5[�y>
��	���CW(`���`M�ep�T[c�`�#L�A=�*�����v
������l���B������RX^u
���i1������`�6Ls��0Sz	�PV���K{������������d�{�&���4���~e���0k�P��]�����5�l�����������qI.g.���mmZm���S��*0��r�l����'��� � �y"9h����!�OSnJ���6S�T��&�?yKi2�����(�j�$���$�����>+>8��JPsm	j&�Z��6�4���d]�������ed��'��)�� Ii���7���~�,�'�Od���+Q.�Y�9�RmU�'}A��rk�$�L'�,��"o���8F��2����{,�$g�/�>��N����B��N��vb2���:���T'�����W��w���-�����
��)�$��9A��k2C������n:�7vT��(��t���U05��V�u��=�i��[���;�L�����W��������}�U�T�>��
�Xjs�_y�T�r�N:JI<3wW-dy���~a��T��jW,����L>i���]��~Z������{�vS�ty
�l�����a�A�,
z7�d���{�A���.+A�='�LS2q�!������^��a5����A��{`��8o��&X��$Ne>X�����9�~���N�����)�LP����T�[
�ca|����57�:�������>Ept*�w`/�\�s��qn**2r�`z��N��u�t�pft�Y�[?����)�[�sY�L`�]����S�$�XoO^&Qc���J.���/���^����R�f�����hW>O�@�s6�������s�:V���6g������4M����L���u�����H��W'�{A����6���#<�JA��#j�)#!���j��g�&4V(�]�� ��%����!N%�uL<���A����%w*0�W)�>iM�2���SfW��/T���I�Q�	1����	����:b����YP����mz�@�����!<4�\�j�����t�5?�����dL�����]�(��?�Him(�G��SS
~��P�:J��T/~[�o	�Y��^�����&����2��h?��~�B���>�:4�:
V"����yQ^������p'�T�S��S��
�������d2>����[�E�<=w�C��3q�xJ8��{)_��G����1��V�SA��'��iJM���37���n���9r3a�7����M�QM����p
���d�o
��fO�������6�T0�#;mI���o���a�N�����[B��9=�,d��=��V���d��2}�|������-��zq\�j�a�*��@��V0i�����cz}��	���X5|�F�$��2���������������
�9��A�'���(A��n���6��@�
�b$m&���o�J�&�/[�������C)zv��������j���D~��I+�^�/�w!��Y�b�R��y���"�|��~��\/��3���7��=7U�T��
���}u��I�;�M�+� � |�>��lA�$T��8���� |H�J$F;}�����|s��x�fWE�&�,�����kYV���oo.n�~�S�T
.���<�Q��s�n"�_g	UaT�Wk�)2Rc�R������e��)M��F����g����=�5&�-����1���o���_.�d�e
v�L)%:�����,�:���o��g������<�/9�U �i�5��U�����s9r���z�y4�=%�L��� ���$��� � �������8����L�}IR�����������c�$;��HHo�����P���������3`4�k,��,��$c�Gw��es�nxx IDAT^�Ab���,�����Q
M��8���{�Z��m�����I��,/�1�2o��P�U`2!�A��K�&��,�iR�;_�ca��{��@�{�T��c����>�U�Y�=�_F�W��Z�c������~���CD��'�����-�N�������?A�y�;��,?��s5H�0��d���,������l�1�-�����$#���&3�m���KW�8pK:z�$������6���_R�:�lNHUI����
Q�-���.��]
����0�������E�����="i��[F��<�P�nss5T�,k���0/���H����V����D�:G�m�v�U��Y���M��L�}������s�����Y�,�<�*���?�s�T�<J3w���"?�@@��*��?�-S!�<�]�s�CR*P(%$��^�@RH(�BB�$���yy !���� � |��59�u��d��t~���m�\���_����k��~���n�2�yG�����Z'�9��Sz��8�r9;���"U�����B�Z�=���~YA�7�����,�������f2�^�%MF����{��Z��g��wf��-,��?�*z�������8Q�)e����K���l:_�f��2dP!*�L�!�,������EI��R\�J\�Ww�����|R���;P�!���g��������*b��c���g�N��*<�3��&�������4(��Y(������jT(���] }�J�y�J�ja,�����T)�%Q
H9gCj���W8&S��q�+��������z�h�ekf��M��t����V����,���ORZ��
��q{�:'�Ca�����(^��DX���Q*���
E��$I/�%k����� � $xg������:O��*�,Y�����I���-��^]����K�-+H��~�y�b�k��w��WH!1/�����;~/�[F*��2�;�,�B�z�g��<����1�������[0�"�Q���1�y]4�����y
~���=?���Bd��'C�&r�g�f��T-���)��>����o}l6[�e0�-�m�M�6P��l7�
v�q�W��9V�C���Y��SjVa��Z�7�1�j���i>�l����S+�`Y
�~��mNS������=�4m�,g|;k�DUn�mX�v�4f��OL8g�G��5������&F-
�^���7+�e���4�$�������|7�K<����K��_��%xJ���1��PF��K-�3���$��?�m(����^i-yT�EMg���������=�:��������Oj
�b���������P�1r�<��3�U#���?	��#��1#_�]C����� �f?J6)���&a�{�A���I�-5Q(,��5_>�'��� ��F
���&���~�����d�k���$�����Z���C���S\p��U���q���)tv�ey�����^��69�:�
�J�X|�������\��.�9s KuK��%��e�z:;Ux������1tv*dy����X�n��gs�?�%HS��e��F]�sF�/��H�\2��|�|:;�LMhibi�a:;VK��(��/����{t8��.�
�A��������������$���ErPA���B�^8�������-���R�?MAAAA�#%��� � � � �����wA~N����8��7���'L!�W��9�22GY�v�F�?-S��5�Y���$79���r����~��dC����<����_��Z<���&p��n5_#��-[0��	���!}��C���E�F�@��0�d��&��n�W��{w�|~�}y�A����A��0��kf�a�6Xw�ww"#� � �/Dr�]0?#d�Ny������)�t����AM�������{�\����B�s8!��q����~�q�9���5_"| $'���wq��}�f�
rd�,�����Z�AA�����
��Y���g�4z�e��mu�R1J� )��=WF���G������l�A�����%���In��D�,OzG"�s�!f~5���&s�I�uc&3��?�I+?a���t�sI�LA�� Uz�����/s������F#yd!s�zT��������:�3;������1y�"o���_	\@�v~.>����^:2�;���0`\	�v�b������L��78��,�*r�����*�f_!��.mg�����M"���"�{?j����u����,�:�P��?�N���	���i�O��Q�G[�#�di��f��1��D���L�o���`L��3'�ar�A�1���A��&iF�������An�������R��?	�D��^�t�.}v7�K	`�r���}�)C��@����gr9�e��A��
����8L+d��piP��9�wK��N�C��xs87��e���<�y���5�LI�1u�Wv�����O1y� o�O�7���{Kx�m��e`P������f�	�����SXx"4��
L�������#,=zh��9.8������#t��-�

a�rd��*[��/`�0�T	6�m
�M��93`�Y0e��m��R6g!o�@����`�0xB�pyx|�J��>D����G!4<��t��2��tw�[
�.�c3����m�eN�����{�d<7�o�������jw<�2���a�x���u,1g��l�	�F�u A��`���x�G�|0����	r�dyX�9ln�sPq6T,{��B
��=���U���3q~��BS�i@&��_�@�`\�!�����L��7��u�~�$/�^`���H��].��M���u;����IA�?H$��W���]h:��UMxJ��kDD�/�����N��U�D��������)��N��N]}Q��h�&��B9��s�T�L���Q �p�`gb0���M�*0��G�Asu=�t�z��t��kg�O����g�H�Q��Rwa'��
�W��l��H�
iu�*F�a~�������������K+Y�c;J��]��H�]�uw��?���t����1B�����^dbw.d������#-?�H��_�5h,q��h����c���N.���.�ZN�J��t�o��*\=}HJS��Nv��H����dO<2�?�b��;�������=g%�QBI�c+X�|�����,��G�7f������GT�x��R�;
���~�+{�F��.�=�B�"���a�0��EL�h-7B=�2�Z��A�F07�9S��v<t�u�����M��'�Z;\au��%.�u0L!`�lp}s�2lX�nB�PR���-�U;��!p�7��tn52����7l�	0?�c��|�
�k��8x���7oA��0�!x���a?�'C#�����"|�7a��K�-IV�/���p�?���^0&��0}����Z����X�r,D���n�������-�Gm��	"�Ad�\����������7�q�����_���)>3A���HZ�/^���M�'��y���`~��YkyR�;��u$�
�^�W��dw;�'��	��N`����n��������<U��FFw	J��F����r+:����wN���@Z�nG�b�.6`���[*%���d��>j�
�9�����dq2��T�5�<r	S��)?�L�����'��ZN�r���B� �k�./<HT��t�Z�
 (7��^��� �M�i�Yr���L�8:H(�=�����w��%�UYv�o?7��'���w8��R��4R	'	���_�{B��1?����<)������I
P��[������:�C��|�� ��������0��@��Pz��J��.��u�@�r�r
�������`�(��6��	��PX�:��L�[�
��@�*0�O�9����	s.���K@>���A����#�,;
���[���	�������MP����Dh |���S�`��
�Z��i�@;�����tL�\��p��������T0���(�0��nV����,���d+�)!SF��Jpp��mjo�	�i���w{�Zer������a�Lf���AA�U�Z��: 7������n����<�N��[
���0%J���e�?I�Zo�\��v��u�"s�����E
t��ra�W,�R����0���7����9q)Y��O���"�3��#"0��}�*��g�u���1�{��xV,�G����N���������nV��D��_���8)oO<q!��"��b��]H�W��~b�Un�0���<^/��J2�������,�}�r�H��'9A�GY����������������p�u��\"TB�<��<��u��.A�9��!�/W�b�����e���mx,�O\(\�,���b<�A�����z�>������V8I�	0����Z�&i����)�L�U{C�N�
6E�����7�-{)}��s|AP"?H��r�I��IN
pq�<�1��U�X����~uy����J���qw����$����������u��>�P��8:��@�Q,:�r��cb���p/���9K|�j�>����S�$�Xo����#�k�(j���!?�ne	(����Y���s|��E|K�u��6cm�n�*��oi���^��f�NP�5����,���G��4Z��e�I��gxu�����s��(�V�m��������}�uhJ����s~��"x�����'��O��g�d��9K����7�9?�?%s���89�`��G�zx��%C����T�[
�ca|����57�0^bt��dh�;���?ZG]mq�lx�����	'����s;v����� � �Qs�JY��g��p-���=ndi�?�MiL'��_�7rwJ[�c��l�$�!6���A9:��=�qrD�c����}������Y���r�FS�Hf4Jwf�e�S���Q�7������g�8{�����0�	���w-�!�������4�(���e�N]+e��q��M���6��\��|���(b�&�����q6E�fL��/d���>8�$��%jt��Y�}�;�3�������7��/`�M9�d_K���D�*+4��#��^��\��/G�8��bdP��*�����v9�K*��7�C�bM`�	���+gh�&���1���k��c`�$��	��
g�fM�I:�|[<�R$�'.N �!*�������
@a}s%	����&��.��������\>x�����tvY\
�9�z![������l���K�t���@O��Y#80{}j�$��R�������9]��k�P>��{����9�@S���o��-��5+�����z<�?������D��n?������Aw����D�u
[���K����i���Y�/�6�'�����l��Y8�(��+��s���������	s�I��P��DC��oN/�g~a��t�Q�#C�Q��\9t���{�����st�t��L�S��O���:�����L\]
����s9,��w�h�}����g$G��dL��ed��o��+�8�MOj�zL��Ql,�L�������FV��Cp��L�z�����WC���������U���&�?�\�R��n�gYBdA!����KNdn�����c����
s�<f�J��s��H�n89���l�k8%^T���M�D�����v��h���������x�;�����j��z*�Cs�[�7(�DnPx_(�pt]x��D]D����7��P$��#c��2�C
(�nY��}\,h���#I�E������q�|��8�12xZ�uv�I��o�d���d�����'��?{�����b�������A�GC�$�j����0���s�K�������z�1��r�EG�&$���Go���X����(��JSh��r�~���eP�(t�H�l�K26��)�U�}��������Of�4b��(9!�\����7�ca�E������K��M�_�OjU��Q�������5k���'�3i��v�gbW$ �R&����Y���C>�D�S��������IZaK�L�+�7������oN���O�_glv���DK*��P��U�ka��8a������Z����s���r�� �<y�#�+��*Q����}��q
�L�@��������.G�����Y���j���VJ�Q��l�����2ra�O�4���
�hml���y���
o����1��e�jV��Y����w�/T���7o_���	Dd��3��[����[>����V��Vq��J�,����q�D��2�?������'�e*F^�y���P��x���Qr�_N�CAAH
��0
go��v�Pn��{O-�M ~��<��?2�����&��K�R
�8�?���7�����r��%��y��������#�G�J�'F=h�m�$G���_qb�9A����O!�_ <�s$Gz�6R���$�<���b��1���5crZ�o��)�U�H�k��� ���=�8��S����,,.�{Wl���y�+��������N��6�<�����8�=��y��a	��n�5��B���p-r����-��?3?����	�������,5�R*�2<��4��M��/��x}!�G�$$�#�����B���m�-���D���g�������Z����M-���pR��b5���^6��S��lP ���U����ZZR��eK�Q{Wd�f�@�+��;�������,B���	E���FyG�:O���F�:R��dJ�F��9���k���r2��*u����9��s���������8:��X�_��>�!w���K���z2����b�Y,=x��/���}����/s	<2�e�>=�.�k�aH~��O>���gnA�R�����h���;���
���2��M����e�=�, CD��:E���d���(����(
��
(2T�F��Q�:������{����_�@r�����\����h�H���'�d�{�����C��F�����W�	�X�������:�N���=
��[����+C�s�W�_SI=�+��V�[Wc�'��wR4(�C!�"[�r3�_M��=~�lWo-�;W��w��^��A�����>�<�e��i��*�7�u�����q�@��M�>U����5:;��G�^O����^Q����b?�)����iM<~�v�7����\�Z���c���iT�}#���P�5�����_�$�m��8:�C���l��U�o^�n�
��HQA�y��K��
��:J<�7�
o���V���t�"a�7l�fO�'����i�h^���gM��9�%�R�7S}Z/|�9��Ft�'���{<}���i�Rk@5��9��`,@<��xv�_��G�hY���i+9����5������������=*��r�[��q��/?����%J�
7oB�
�����(�dg��|l������0}-t�`��x�Z�e��^�c:�����7t	��8v����Y��~�~��o������aqm�W�����W�3u r���1!�������������k��o�d{P����W`oYhW�h`�p�^��:�aW����\�� ������@_����
��a��SW@l!�I��TxhBA{����O������h�N5��;1p�(Z����y������W�P�;��*��m�c�4��v�qc>cW�h5(*����n�
^_e����_���c��N}flZ��������TL���
za�b6����|��Q24�V)WVm��#�v|�'��R������l_��r6�M��0�����5>~�~�q|��SL�u�:�:0���b�o����v�T@QP�|�_���1$�Ksz��c����1���3rXg��X�[�hs�gN���V����smA��!�BdC~��P�:n����	���6c0����YtI�����(�-����k�a��$����KP���f��q ������<p�)�:�C����@��@��'���U�j|1�J�'���{*8�C�?'���9���<x./Mk�VS�z�'q����l�&7*�{����g����9�j_�l���4�?����{h����_f IDAT��:���8s�>ODW�*5fO �Q�{?+t-��s�E��}����b6��]�9.s}��:���|��^/���O���Y���Pp�B�7����x�������0�iv�u���=i��<�lj7�����4u#?�N��
��	�!���(]I0�%�d3}���004��/�OX�+�?Q�a�����A��5K�������w�� ���2�^�V�~����K��v��>��	�_��h5�@��0f3�^6��$�������`�|X�	C�B�BK���>�U+���	Ib�P1����aE4�0o�]	�,�L�R1�7�����i���/����V���^K�l�]��k�����\���v}`j[k<*��O����C������u��T�G��Sxu2�I���w�d��(J�\i40�q���{#�������������\����6�mg<��&%�`�o�xu�IE�����:�����OudD��]|��4����K�MK[9�`�m~�y��N5��l�V�J��q��T"�?������m_�������kKY7�#}�Z��#L���o��Q$s���J~c��v�@����.���b������S(��&~w��?S���fT@X�z�1���I�u-ye5���b�2���
(�t��
��6���;�h��Ne�	���kW~����M��Q��!�}�)	h{~
!�"W��24�O����(����@z��g}��������IP���>
��QN�G�i�RkZ6U�oE�/Z�)�����w��:�vR'�
P��uL����js�eZ�?�nS��+
Q�����s.����d^|�va�eST[�5�l��3���>��f�����+x<7*�<�Q/�.|������7���q��O��QFo���Ls>��H�
����.|(�zh�������	u��P�A�_�c�<?��������
���Y���n@�2�Ext�/��Q�P������������D��x��������l
(��[�D>�s�s�X����Smm�����\Vj�o�YZ�7�`(�������l6��u	����=o	���������:�6����xn�h*�x��ec����|z�>��4��D�/����u������}��S��vCAG����d-���`T]�KW]�<�#�
�@��/2��<����=k�v���t-Zj>�=���^���C4��w��ehsg��?���d������&{����X/���)]p0��-,�����������������2`�h^��
1�������]�I��)����~�'�2hn�����Xv�)sF7����S4�x{)���#��T�O���}����C<�2��#�6|����t_<���Sp��C��3�=������Og��|���@�XT
����=��SW����9�1=C��L�?I
!��&�A!�B��.��uw�Y%pH��W�� x(s�~Qbl���=P@Q����\�x�9$���I�=��������&�4�<�r)��g���#y'���MCy�+���s�v}��_��bL*��4}t"����A�3�8&L|���NTj3�����E|a���_��x��
���S�hr�,i�z�d��I�}��g���;����3-�!��I�v�o�|���o��q�|����8zg�0G[c��^��i��{q4�Z�}�R�O�|�'����'Q���X��H^�5��Y��6����~����SM��~�^����M�6=Y���i�������?�7�?g����X����~��wx��7�>!	���<��2��M�����'������y��
�o��~��y��/CkZ����S�kL��s*Kk�L-	�BQ �B!��O���`�5H�A����0�L@��M*��`�iI�Vtj1��?mMNs#)��yb�������r�]���rX��
��f��L�u��7�S���>���W����r���	���v������33����<���O��-j���!�Z���]�x�v��3O��]C��L��}�zp84d�wksl��&���6��p�����Vc�a���j52/�����L:t�I������^�#B�&�����!���$9X�RO�o�*.�4��*
'>F�i?��n�(�~U�����/���D����+�[��9�_>�6�M�����8���]�0�8�������	�w�p���;M>��~_E*rb�rP��B!DQ��`I��x�x�vE�A�/!���U��#K;��}�mZo��'m����n�J���M�]r��k���l�����%��p{���I����4�<Y�B!�E��B!�"o���XT��,��L4�t�-�������K|����s�v<�<&&�\�B��bK�8�Y��TK���+����!5)e
� �����h����|���?[�n��u�3X�
��.���P�k�k�yn_�S�������w!Q(F;7����������9A�2q�e	UUQ���f����������x��s����Xo����?�bYfM*�$�Ik`(�B!������I*���DcPRRRr��n�JhhhI�#�B!���f��Z��i��������7oo�R�]<x����h4n��d��$
m��Q$A(�BdQl-;\��g��h-F���12Y�h�����������D���l�u�8�H�=_����HDt|�����{���1:���:q
F�s1GVp���]����2��R�B���T	G�Q�_��h�T������R�]��2���hD���h.����l����C�o�}c�o)�0�(~j�;*�����-
1����*��]c���m��{l�H%��,q���"�S�%������&��#i�5
�'������iB�.���+�B!�+���w6dX�i���{��	�sg�s�B�P�c�8��|x�B\,����@�K�]�B��.�H:cy^�0����!��_�Hd/<B����r�['�!��_K��T��X�C��|�oU�Qe�B�
��4�c�n�y���;!vUZ�g!N�Jm��w~+�����c
f�0m�A�}��H��Y�$t���Jz�PI�o]_�>o)�i���y (����T�I�eH�>�Hv�?rz��"!��~��:���D!v�%�}��D!�B��MB���YX�kK�AHOBz�0�[ZR�^E��<�l�z6��d�����������B!D$9(�B!��^�0S�A����f�J�mR��� 6��3%	�H���,���3��$����,�����1�	
!��&����F�b�+
�q���wmb:������p
���xeQ?�K+�4����4�qD.���U����k�����������E�E���oH3B��'��L���u[��u�+������?��>���Y�r��}	���bX�i�C����%=�4_S�@�lvF�����u�i��;�������r����O��FUC�����JT1�{T__V�:�U�
����?�H,88A�?�o��Y�g��8s�A��@IK�=�:���q=��N����er����)1��X!c0Cwb�2(��\wv�B!D�,�D.���iT��/��&�wS'9��;������~9>B�&s�K7s�S
eIZ�U�����jM$�:��y����T�����zo�,O��TN�������l�����f��[��%B];BpD����P�BE��U���78������U�B�*9'�j6�g�`N�3���� ��0��JD1��p�xv74o
�}�n4�;��g���flA�1!=!�Z�i���$�m��{	��ul��n�i5���m�N���mk��Z�,�}>s}J�J�B�I>�����aO2NH(�x���y����z�s*�F3o�o����-������T��[���{���Z	��A`%\�h��A�R_	VU�g1y��6������r$l?�3^���JJQ�bg���_Sx�M�q�1$����$ �Z�L4r�![�vO�MB���d��2'3?e���z'CB�&3$%(�B�$�I��7S����\<��^�F}i?uU<�.6L����M�.����1�4t�F��Y��aE��8�d-~�?��6l5c&�(P����O3}L*���������"&���|k�����O�I���X~�'�g��}���4h=�����S)'V�u�2N�~���)R��	tP{����%/�k��a�\8���BE���M�����������}G�����:�n?����p����Z���G�e������iUsx(8���M9K��TJ��(
)7����
�������'k��pK��=0�O8n��XGx2��N��[�ql8Q*�����w�|d�w>�5�k,9�v�%��;k�����H���L]}��@���v^��(0p ����5�������)�m��DB7~��!u?��u���Y���#���p 
�M�W�r�����L0�#8Yj]��.��
�u�QU2�Eq�1�������7��1T����g`�.��:�����
� f-���`UWpPa�j���B�T��^.Y?J�3]�I��NXr�'��7�6��-W���a�o��
\K7O���������o$�����\L��u`r(c�4����y`�a�������]y�;r�!�y��������~����G�:������3����9y��>�	I������0\�������a#���������[�~{j'[|����hP�8�����0;^�A�a��������F�Y�_<Ewx,�X���3xg8���|���x�H�U���|�0�e:�r���{�I<�5S���V���A)��#D�QI���ec�2�'���s���l�1�.�����g�R�^�V�[�5~�)'[?��g|��\�)GsG���M�-�5�	�3����A�20��?T�.�m+lq��ZY���?�3��esx�\9s��c�v�4������Fv����/�}	z�-@�
8}�w�����4����u���� �,<�5��N���L7��5��V���s�.�&�M�'��;�*0�����e�e������?��]��H�����]�@x������Qxw8>	����:�'��M���?`���Cr�~[��|�7xe?t�7< b7�����}�������������	;�~Y	��[U��!�{�
U4��������,t+�u�G���Z�}���=!�*�9���Y���	�kBY��6�]{KW��V`)�`M���0�X��X6e;�qf�h��������,	�L�>I
!�EJ��V���m�#/���#@�>dS��7��.&���<��s����+��,���	��q���x��
Z�������$��&n�}�C��,�7����x����R������vS��:�_����:�5������c���c�Y�i)={`����������w��?D��xj��~������~'�g;<�s2+v8�y�){;��+�����T�w�H��H8}�����U�j
%9x_�}����EWXX��C5�1�:�6C��0�<>j[?��q�`?�������!�,?��[���x���f�V�~��%���R
K�3���`?��zW�<����v���C�=�ws2�pq�
n�o��M�t�u=-�����-�m�|�� 0���h�Y�8��
p�Z��6�4���a�E�V-}�cex����@�C��0l[�F��g3|}<�����d]SO8���u����S	�t��
P������B
0*��g�����Vm�jm`@������	K`��5B����7���?�\���`l��*��9���Xfb�U�"�\�O���,Ir�F����{���`���^k����&�k�M2/s��S0KbP!�%�A+}`0�)�������b���8�\�'���?S�}�^����F�p�w������+�4��6���g��)�x4�:���E���V
4�s5V���	g9::�n���k����QM)(Mo�h;�����\9f��o���e���-������T�����S���"xO����W'd�#Ts�_@�5�@��4�7����W
�
?/�a� �9<Y.�l�8d�A6uh�~��*�R���+AK2�������xh!6!��\�U�9�/�2!��s��N����
����bN
��YZ�9a��>5}�����pl�����B�	�3����KZ���K�A,�Q��r;�j<�������4���~�>V���P�!���05�AN����d�NK��~���e���L#,}�������/x���S����/@�;t*�q?����a�.��4��)fK7qmP��G��u���t���U�q��m%(u�
�[�e��e<�{�s�PZ
!�%�A+m�0������v�d�q�l���3}e@�MBr*��
a�l�U3&�	q*������x��Ms�R�����u��Z��xG�8NO�����4{}>�j�b��rin?���*=�����Hb<\�m*�P��HJ�f��"�^�.�w�O�A���W7I�����Q@��h= ��\���3v����&��>�Y����@��BL"�9�7�.�+����������pod�Xxe�
U�����E��Z����jI��I0�+����	5\@g�_�us���3��z ���Q��s=�����1�gn6'���*�
��R�O&���A�`X�3��~���1@�:����0�+X�<�
�%���b������0�=��vm���OF���������9���dM����'?o�s"�:��M�\�!�"O����^�k�;���t�{{<�'lhG7�z������S�U�����O��(�x��hmZR������N
������Txv-��T�^����Y�H�{gH�M�Y����j����{^�dj���9%S�!�������2�����h]?]�>�h3t��WG{�ka���qVtP����f1w��>?����p�UK��$�l���B/w��d0�d-���}���cQf ���fV!�&�������\�qL��z���`��6U�.�Y��W�=���v�3j��H���e��,�`�9h�FV�$^�����Tl��dL�=��j�>�r�R��rYZf�@�B!D�I�lh��1>6�Z����}�r�jh�������p��w�[e3�x�C��������-P<
vN}����(0G�����
�ri�A��5)���9��d��k�
w�r���l�A	!����kh���,�io5���^E��OY����#D�s7�L�
��I��B������U�s���;Y���g�����8y"����,�O&��?�$���`��)[��%|�0��
�$��|������*���n���
�!�/�%�a����j,�%ew���J4���Z�_����-�������e��Kp �����p5�����W�BY��EE��]��5K�F��<�^Fq��^p���tnT���ch�/6�ix�?<��l��6����Y�pn��iC��s4�t%c9�j]��*��[z�wa�5k�iq+��+iMm��nJ�r���[��5���������x�e^.�B�������]�_��H��x�h����?�xQu\UKUS�:���w�����y��8$_���=�:n���������'�����p��^�n����%�*H<�(��!����}e0������J9�]C)�!~����
�p�K~Z�������zTnl`��O�l����6�����������:q�R���xC��mb���tu'!b+[~�#x~C�8�<�T�y���k�Wg{��o�@$Y��k��	2��.����u���LA�	j(���n��l_�K�����\���=���������/������,�}'T-�)J�?�
[Ndl��q��`P��a�',k-���� �4�0����ZBH�'/�Ix����z���Q��
�nA�p~w�)
,�;s�J����d��'!N �!���s;���5���+��X����� IDATE�6�h\��l�����K�n���n��3����%XrY�E����}������-��6������nz����*�_��$];�5.������`�~X}< "v�@��2
�k
���QfPS �*D����,����n��0(�������9�Ac��W�a_�V�2��H��0����c�\��s�����F��(�
�����	G���
�l��L9��,��lGq�w)�/�}}s,'IA!���Hr
��uq[��������
���R:�M��ch���}���%�0�Izo<��w��t98z*
_�����HL���3�E����<
��&�����q�`&�q�����)P<���i��0?�^L������x�5y�K�ir����l�!&��Tzt,�����L��r:>���=���N��c�������Z���B5��$�a��1������k�}&��{a��;�bs|���|�Q�Y��~�[�O�b���|(8?�=�X��>�`����gyifPQ��(��Hx92�2}l��{���P��J���N��
�bi�a|�����b@�U��w��6�7xg|���������2f��F������C���tK�V2L�������	L���������N0�gx�(��
����=�F�����yK���a[��������V���z�����-p.S�����5xe����C�f�-��Tm
�$���0�ukA�r����gU��7������������IWa�/��3����l�o5�![���5�[G`�V��.n��-�ib3^��=
�;a�NX�^�����R`pw����p��
����{�8!$x������B!D�����\�m������W���lB�s-���<Z���@�W�,e�������DC�K�l��H:C�s�Z�D��N����*+��p��F,?�</�|
���?�0����_#��O���~�0wc�V������p
?_�0��Y�Dh�	q�)��2?y�0��^/��!n���?�w�Z&�"~�������-"����J�K;����7�1����C+L��j�5��X
*�+L�@�%���$�B<H4{���1���Dan�\�x���
AZ
!�B���Sw��"r�!��N��B!��ddN�HB��$�B�'����z�}q1)�+a}MNAE��+�*S2�B���^d�k;r�*�pJ��y_
!�#Z��|i�`�D�B!D���`I������4.�8��o�Qt�4~w���B!�B�'���B!�B!�B�G[���f*0�;���s������r~�\�_\���*'�F]}��v~�_�`_\��#F��~�F��R�$wF���?k�yk�yn_�U����q����yV1!�B!�(����,�����:\XJJJJ�CAo��������G!�B!�BQB���`��o�|�.�c��B���w�@��=�\?���;�����D��+P|��D:��hp'2�cj���SnF�g1GVp�1�S��^(����L@9��-�hW��}�����pi�T�1��)�0�{�)q��!v��w.��^�����������B!���,e���2,���H�zr��y2> �P!��$!���]6<9��k�u�������]�2���NZ1��R�c�+�!�f�s������@�>�8�*�p���U3"&�����q����YD
�|�!���K��9���q�)q��2��B!�B�.��~����q���\�'��D!�B!�B��(I
!�B!�B�%����F����r�\g{�Q*�����Ws�\��	!��E��9�����3 i3k���-�>����W�_����a��'����F�>���R�(�T����z�;RJ:��M<ma���U�U;�����Wo�K�������lA��r������kW��,���0f�?�D!�B���bs�?�|��e_p�cS��B)�x�%�|��Es8���B�f��&����s4~�����A������
kW�%�z>5��������X��c!'�Q��\r8k��a�R��Zxe_&�|w	�	(\B!�B�"%�A!�(qZ�*������>�e��'����]C@_��(���������Ih��7�
M�AL�X������!�B!�rY~O7�~���s1�.��>�;�~� �x���1�{5�f|��#Q����=C�Q�p�q?���tN$Y��������)�
�p�K��	,_����2T|�iz�k���UK9�[�_������N�P�5��������k�T�U�?Lf���t_���K9��*&g?jN�A���(E�-!�V7����������>�_�D��kcPR8�JK����m���$s��Z��9���<�c�ZV��DZ��C��8@���U�y���3@��G|����c(�$������7�k��l��gn%�������?����4q)����#��������+
)A�g��K�q�ep�6���o�G3��
f���7�����g�g$�"�[���f0���#�_�|�
���;A�k��.�q�#aj����
B>�v��������m�o����'a��������4�Vm�CC�Av�~"|�>�
�B��0�yx,�{�p��`�l��^0�q0e�'��P!�B��8IZ���d��mA�N���E.n=KL�
�$Z���,������maM�~f����v\��'��8�����t3]���79�rCF���q�,p�2����f���s�`��f����W�����hQI>{�h�������z�n%b�8�u��~{��~�`���c�m�<>���z�zv�&s�lK�"���i<�F~���o���/w�}��1�Ht�B��>���+���[�Y~�;��m3��`�g��O����#uC��i��7iY�x�D��f���T|�}B�ra�Lv��������>�	I����0\X���g��F�=[Y�s�AM��������z�W�w���G��<�
�?��`�0kb��)���6�aAM�3_�O�qK�u�<���^�jNpz�<�V-X���p�%X�<�F��F����k�ow���vC��Y�wn�!�<1ZN��+Y���������>
�g�H�msa��0x$t.;��7_����'`��Sa�yx�5�c�E�`O*t��*?�P!�B!��4��N���#c�P��U��0Gq��o��>�g>F@}��������<l$�:{�����.�z�����
���D��GP�_����?��_n������Sp�>��1����H�l<L��m�+��*`��h���C�Y�Z�@����EA��������f
�S���z�%�/\Gt�����Yq�)�L������W���3@q%��P~������|A�Q�pp�/(=���+=qP�J�����i���rh�b�j���/����%^�GY��.���w}}��
6f\��eX����-�/����A]`���3X��o��5P�	X0��M������a���e|�5��,��jY�Ed*x�8���zp���k`�q������*8B��f�{�`���NW/�+���'��
�n���e|N�
K�@��`bO�~�����-���`����Mx��%����fFz=�=�B!�Bi4�Fh�=e;�X�������i������#�n�����B�g��8_=��Q���87��6}�~���4���\�a�V�E��3�O[=���]�\�'+���t;�Ds)���*���iiU
�P�|I=��#)x�j�{����M�6��Gr��f���~�?q`sL�Y��O�1�>�P�U�{�(�M1��i���������^���:<�7���!��!����b|es{��MRM�^�����Pf<��~�1��]��$����&\=	Qf�{Y&?i��q��B�|�_9�����z��#�t�E�yg��"2MQl���&hZ7�
E��f���IH���i��c�Y�m�;_�P!�B�w�{���0`��-�~����e{>E���)���X�L\��$Sf����1�UH�U�\��K�8;c�I�j����WI���z��o���M�h��kt���Ag���/��U���s��_7�<��S�P�|1��7���.(�wHJ��]C�<�����Z�x��;$��=\�sN�;�n����$$�ryb;�L��J5cRk������(z/hZ?�	It�Gu��O��>��u'�Sa�P�e�\5�q@93D���{�����t9�X�W\�jBwX���Yn����S�`�� ��eL���`R�������|����	!�B��#��{���=���Gb�s�k������	aa>(N.8��0��G�NWU�p(�F�j|<If���0��!Eq��E����x�
��G�����@�LI�j)��RP�Y�4����q���bl[1�I��C���`M�(M��T*��,3�����������Il�#E��A��t7'�g�z����'w���}G�n��@1�h,���(��[��#��
|�>ty�^'����� �g%H��tw��h�D��os<�	��lk���c�P��;���$Q5N�S�n`=>j"$��n]%��P!�B!����q*�q�jU6w��%`������S�p��w���J93����Cjb�?���F��������$��U��R��Lj�������#�����6��~�C%�-!
BD�Zzn������Rj�w�D�U��z
�p�&w������������������i4���S��>��vZ���������'�'iM8��6S�����XO��k8�ls���v�Qr�����0���N���-]f���N���������E�����}�sl��M��eVg�/19�����q��J�2��ka�A��!����9�lI��W�������K<�m��|C!�B!�����3�zOyj���w
�;W��w��`��j|��bO���2��4�Z��[�:v�SG+�����M;��2�Tu$f�w��@�����e
�/Qs�_�,�����G����)�RW*�M5*7��q�"C`��o��X��XE�_�T��z��:�V,J��M�����ok�:���/	[?b�6G��������E������z�������9|3������31�/��CN�1������}�mk��X#�����F��L�'[������S��
R9?�=�F��?4����0��z�evch�����uh�W���E��������awhW����l�����z��4��7��@�c�!��n(t	��[p� ����-u7����/������#���>0�a��pj?��g/��{w@�����[>wH��� H�
���%�e"����c�i} �6ci���������������@�q������0�B���/a�����'M����P'�|�lR��=�B!�B�4�P0���&v����hc
jL�B�v��J�g�2O~��-?<u�$�;�j��+�z����s4|i1��Jb
���b��zJS���>����r[-C�'��������7��y��//`e��0��Q��PB{��3��_�\InK��Sp}������i���:���x�B�������z��cN���N�~%������/l��\�#����p�6��Lb2��X���Zd������Tyc'�5��O<���a��W�0�);<(��i��=�>��
-_g�7>�4%�\$I��G�&
 �������q��>����������6_����)3��<���&#a�����
zw�
����1�)����O��p�k��v�$�����K�c�D@O~o���%��A���5���00���S�'3�^c?�AO@
0lL��M��
S�[��@�`�>X��|ux{&��J_��k5F��DW�����X}~��B!�%%%%�^o[�n%444�"��p�
Bk��|xran�,�X��{��*�u#bw��"_����I���|�%J_�ya�]�|�0�G����8��)��
.<ja��\�D�����d�Ax����,�z)��8�.���Vxr,aN�J;��^���	3x�{<��b)Fs�y;�"b��vB!�B���-Lv��[+�Jan�
\����B� c
!�B!�B�%�A!�B!�B!��d����z�}o|���\zr���p��Tt��H��7�,�B!�B!���}GEq���VzEEl�w,{�hlh�1�$�7S�����4�%�&����(����+�*Hg�|,�������>�p��;��3;w����i��tUh0n4
J:���7�,�B!�B!"���B!�B!��G����EY� D�w��
Y��������<J�J�"���������Xj��pnK�&��CpH��h���&D�Z�!�+�h%B��U1!�B!�(��T������j��d*d29���%::�n�#�B!�B!��K�X����^-R���2�y�����M���h"@)�PYQ��27)>Q����	�Tv,m��B{����������F���sw)��p�/!�[�O��2p9\��x�vB�����O�"$�;Qn�X��TIz7ao[R�a!�B!���N�&������u�tK���I���85�Qn�y�������^��q&�2\���t�I9�5t86Q:L��sx����MD�6��������o���u�RD7�[cPQ�Q�:�M��j�N����
��_B!�B!��w�y�����}eA!�B!�B!�Q�8(�B!�B!�=��+�Y��bb��y�U����,gY��}Vl�0���J:!�A����"���49������������h�(]�~��S��
T�6+|=~I��%��{�]������a��|����,_�,M���2x�qh]�����`7����V���s�`����F�>��>�Tc1�u�Y`�&��N�  �DA����B!��4��AQ�h��p�;��2�t$B�-�#��.T@=��%����hP��M@��
R��"����6�G	���@���'���`P���
en-K��>�����6C��7�U�C+�j�cG������Yw���0f4m1��o�x�����M!�B����AQ�hq�+��8(�U
��"�������	b����i$5����(��J���
�!���0�,����q�*��o/&/_h

���=����Ay�Yq�uWd���P��\@�2ph&�>u"l�*�B!D)U]J�u�|�q?��U��v�2���iK�����@�L���L{6;a-7�&��cp(#z�nHN7��?-�5��bmv+��DE���6�e�����$,��?��N���V��%�\�u>�?����3��P��>t�Q�����L�\���.�����K2����?j���!\������G-tYzg�,f���X��Rc�H���B)���(>FO`��:t������r.��_������]]1qa������,����\:��s�5���c�����N�������J��5,{{#w\��]�������JR������l(���f�M������p5��)���*l�
������^z����@��3�C�	��B�?�m�:�����B��}R���<W�k]T�l�!����Fo����z-������
��OW�A�
�4`��n*�����O@V����y;,�����*��xt?L��/�+���>��s��=L��T��������n- &�������m
��2P��SD�����}+|Q������7���eep!�BQ2�1�*�9R�G����\�j�S[���HL���+^T�� �\$��������y�7	���yW
�,���}����<����A������r�l#:M}�>�*r��o���y��S �����1r�Q]�7���*��+~�-o<��k�x8�+�����0���N���x��?�'X�t�����+�|���F���%D1����������%��y�����Rr��J��?���f�o� IDATV�[����ADw���N��9�i������'�z�/f�'h�r����)'{�2�����e������y�?�������H�����s
�|��F�u
�H�m[�V;��
�6��������ou��~0s!�~9�k
|0�B���ag��������]p"&���j�*V���^��8f���1�.a0}�������f��7��&H���aM:4��]\eY.C����~]��`d(,�gr>���2��d4����`�|X�������T~~�������"=.�v;(��Wl��y��L����w����h�Q!�B!�<�9x�.�����f�����o@x=7v��#,PI�k�>��a�O���v�����1���Y���l�+���M��=�����������H���'~hOY=@U|RN2������ G&SS���R��J���)�Z��y����MR�6x_m�5V���������~�8��I�2������%����yp[������q������������M��l�	,C#��i��z;����Q#[�k��{<��NR�x���1�J���]g�j�9Ss�W��&�s�z#����r�Ae|��f��M�z������}�s_�m����H[o��:s�����������|$[Sa�ko�����i`�n[�5�w�W����,�U�nE�j-�����pp��5���s����u��`r.x���?=X�m
zn���QpY����r��B�f�Thn��U��,t����� �*Tw��V�+j!�%D��S�<�kOA�*������*�D�����}��)�g����}�U�Ej
���9kt��r+��%B!��dI��U���f#���g��s6�W;Od�c�G�~�.���lQQ��f�dZ�p�a�����_qz�����"���CAV<��X	x�>��#4�iT	���9�����D����c����x]-Wq'�y���9g������@�^��]q���sR:&t��=}E���}�3��(K�b�	���+N���0_��+�s��m���P�:�JpK���lu�t�3��_�j@�
%��&�q0��6[x)2o=h����8sA%����5�Px����xx��i�g��<�!
`@�������
�+�}Jk�f�8I*�;N�KEh�o�j�-
�����#xj!%��k���x������0m|�	/��xE.
X��1��O���2r�d]���S��
����v�����x��N����/������3`��-�d�B!�(=�q�E4@�\���Z5�C�|���>4~'�Nu�0����9���Vl������R�(�>\I����i�SS����p���x��}T+�WTp����If*=��6*=�Q�3��������yFE�V�J��O��]q-s�>w�,!�S�uE��ok�)`�t����eD��"+��,�-������8���{]�i�ddY9��D�c��j������4���\�v��?a�^�����VU���<#L��#L�����/��*�d��s�F�[�9_&����wO�,o+�V������o%�T���b+C��~��\��p�f����Zx<��@k�����|������f��jE�
��&�w����z��	<��!�B��Ce:���W|�Y���y����5����r4��1�y�fj���e$����P�\p�k	y�y�t4��Q�K���&4N8�AVr��F���T�;��Y�@���7�����Q�w����;d%g�mT�J�B5�a4��q����t*�}B�&���*��8����]:��������0�,������Ew�y���@���}��!�~�6��(�F����������)+T��b9c��p`o����h�u+Aj&y���	��Y���er������'C�"3>!�B�RE�<u���9[��e� ��7e_������mx]����O~f����
c!��$��[e|����b���
��)_C����I���AM!a���st�������%Dq��Q>R������\	���D���s����g��I�YN�����DH
��Sp/�oU��po�����A�M��{318`�y_V��{�
^(I�<k
|����P�<|�3gu^@��5��A�P��+�#��z
�*�	�%3_�%��km�eYn��������#mo�,{V�7�F�����t}�S�����j��!��mB]Y����	�+(�/�?W�FP���!�BQ�H�AG���X���+�o���N�����K�2��rO���	�~n�;�o�����l�=��4�\g�.�>���ei�}[�yWw�=��U�2�e'Zv�"c�rV���u��9�nFSL�{Y��n0�?Iq���uX�o%s_0���'��b�������s��z�2k_[����hv���V�'Q��n��Z�4as���0��I���S���w��nZ��J���,q���!��a�SG	�P�'��cC	�p��(^�W`����1�4�
KV�6/����l3x|
�
�|@�Cj���o-��)
���#��F�|�5�B�0~>��p�$�t��j�����D��1l�H�@�
�t�(@R
d�`����K�gu�9���-�q�`��	����ww�����a�1P�p�4�zkC����*��j�`�6h����:H-���y�p<X���Y�pD�{l�^5a�v�Q����w��+���B!�B3it���:c���\f�Y����v&��l,d?C M?n��K���H�����Iw���`���,�u�,�������������/�,�h>�N�BL��D��,��H��S�e���(m���1�k=K�-��)Y�*1q8�}�s�X�!}��7���{6�a�3l�����Csg�{X��2Yz7�k>8����(i����y��*�O����9
��Ah��P9�b�Ao���Z�`�����zg
���}�5��z��~Y�U(���������0�bn��
��O�w��L��4Xk�C���9`��;��vF=��q����m�!{���+��{`;���6���'�k���'���*��
FE�Gk`�?��A�����#�.�>�m��v��v��h��0e;��
����VPO��!�B��O1�L��?���%::���=�*QN5N?5�1n��l�K=KlX�&~J�1����L�����N"J��p\����G�[O��^����w8���z1��>����ELG�����+�]�������Q�W���5�C�����zFG�q�����+�hJ�w����%%���,0�����d,B!�����`Lh���&���n�ni_�3W!�B!�B�{�4
!�B!�Bq��9K�	��^���B��+Pol�]��x�B��F�=\�A!�BqGI�`i���'ChP�q\U��B!�B!��F�!�B!�Bq��c=��R1@���U0���m�X��QQ/0[v�.
�:��P�Fr�BH�|"�I.�%���/��B4�%B�W��	!�B!�]q�U��O���-���L&�����DGG�rB!�B!�B�����l{`H�����8C����7��uw(�x�(!�B�D��\��DB��%�u�36�+���7'��x/�REu%�(&�Y�����^�7"�������
���2�����%�B!���,-�6J@�d��-�wG$�roT|y�vlo��Q�r�55�(Q�t��(SI$�5��������D�7,<���D�_����R��V����dj�y��o|_�2T����.q��K:!�B!�Dq�_����}eA!�B!�B!�Q�8(�B!�B!�=��+�����z����:���_��T�a��
'����I���{E�n�����!����i+�����h||(W�&���E�H��)3�o~	���/����s2ZN������i@��aFOkv�:z;e��>���|�}��0���N�������s,�e�����#iJ-���w�������~pW�w+�������G�1!E�2{T�	���85�o����#��{!rdW���BPa����v����Y:&������[�D!�B�{�4����i8{:��Lz�Q��t<���#�V�Z�ow�Q����x�;����_1��3��������9�����w�DQ�D�����Q=n!w�
���V��C��u�:z;e���<������\0G������5���z������4��G�8�'������@�nP#���3=!B����{}�F��\_�T��W��q���x��O����B!��J�y:���p�����%��/R�e	�\��w��`~�l�vC�g�vd�����=�3�L��4�#��g���H���N����U��Swqd���v��[��#'�z��jq�/g���j ��IS��@��w��`A�Z�[����&���VJ}8,���B<a�6x���"�B!D) �_��sf�,�h-g/�R~�0"�����CxvAw<4f^����xr��hL���^�s;��XI]3�eo/���D,���?:�N�j�f7��y���}�L���8��vl:��-��?�[��������8��Z�����|�t>�N�[[G�?�9��������;�������'��'��jC<��|h����rpS<���C"��(�b�����Jxi(�6��{��l�b=������0�'����h����7�q�@D�c:������w0��
�^a���0gob�!��J��e,�pw]��H���tY-�uA�Y�~:�5��q����0�?����+bP�I���^�n~Z�y��:V�y�$�>i��
8��|vlI���G�1���������3I0���������������O�|��18����������������&1����T��
��O������t��m���������N�H\MC��@�kfMg��5O�@N�g��!&�}a��;~k~�i�*U��SCi?(��t��,��
������������������#�\��_c7��+���������g^��Ka�a8�BhEx��/�`@xs<l�=���=�l��a\=����k��0���|���l��� +�����D
>�������;`G[�W���&��>��� 0Ft�A��~ ��g�`�A�v����9>�C!�B!�q��1*K���6���f�$"y6��H-rN��0��T��kO�������\��
fs��9�0f���c����}C�)kPQ|�R;ZG��kI�������\@Kj5/��h�-�����A{���/�X&�������T�"��1�>|�{���|Ix�����};�u�6jL��f��O�`�,��b��������t2��}��m���M't�g�/,�w��e��x�;M?���0�[�1}�o�iF�o����!\��sfO9�{]X/�c�8fO�D�#C��:
)O��C�Y�?��������>��T�������Q+�t����3�e���Y)���O`�������}$��r�i���<��H:�&��O��{r�zs37/�Q�����zjV7����V)���������b$��ka�D�.��r Q�X�3F���z �f�Lt7�?j����{����x�UfO�@��#0g4�
"i�>��p�X�����+�6�"z���]s��.�E��q���A`�2�|��w1�t�rL�`WN���'�����A0����7x����H5X�2L�����Wr_/�6��zR`��{$�{6>�:>��[^���y�zW��0�X�;��ZF������L��)�i~���������a�����7+G��B!�Bz�&��_�7y�����KU�p��K�S�|������Cybz����s�0�&-����d?������O�<����rEs^���)��+�{���0e�o	x�|��"����6���-��R�q�
]��)�8��C�w�
Pp�9��=�6���ng���S�V����z4�5~�_?�7��e�`�4�b+,�-�CQ���1���<�t��2jfn
h��O�v����Q�)G_��/��n��e����W���'���s]D��r�IS��������e��S��������V��G1���(G�1�92|.K�le�W9�7�K�a�����6%��e]cI�s��t~��V^��k��n� ��B�}
�]�����f��v?��%1�l�x������>a^�_Lg��Z,j���'*8ZJ��s�������)�EYV����-	w���S����R�=H��h�h��J�{g��kH��
o
X6�g�b
5g�M��n���U]"�[r��;��?���#�7�ld��V�9���������a��P7���&�'� �=|�3<�2�����ahg�����2�{:�����0�Z�����ul��k	�����0 gq�*!����*�`K�������.Kq��5����FX���4���������Ey�7~��Z�zf�������x"-�dvn>��C!�B!�4`���n3�#mC\�\W���"����c�����kZ�4��������T���J_������eh�������i>��#�=G+�/��s�k��	��8��ru*���0g�U��88�/�{&La���\8���lE5�Q�'�iC�y��T��k�>�+�>:�I)�T�)���s(�<k�m�<����?���J-����v�{,���v���!���YG9��B�����
eV�mbg.���\�p�+n5�l���^):���
u:0hm}�/����qx�
-^��q���@?4�e��.��m���������l.����[��XP����[�����Mf��0�E�WL�k���q����-�����E
������f�����������^W���Ip����s��F+�����{"�����wn~I���]����^e���0�,����m�)��������k��@�`[o�DT�x��@�|-��[�h*�������AR����N��f���tX��w����@�J�
��4��OO�����!����
�����sXB��!�BQ�H� �5��0z�?`�1z���jZ
�N����k���F���4���q��&�{��uvG>@���$��H��[�H���Z���lDK"�)��C���^b�B��
���b�Y89�E�8m��CI���x�V��in���O1x���������Q�[(�����K��z��iiddY8����7�n�������_%#)��q�I5Q\|	����^h�q�
�����X��{�`�����p���F5�Co|��e�4~�Q:�����r��	�q�R�a�E���w�}v�*���^Hq�>ZI���E%�����2QkT#���#+�6+�y,��{���=[����b� +0�d\No\��'�����3M���`�Q�Z�{���C��~�mW�@yH�iL�o��YY�/���+0T��n0{/����f����?!
x!;2��,�^�vI��~�n���4
!�B�8h��`t��+��������7�&�X=kv�G���z!/F�N�����Kp�Gc
�
�Mt>��2��b����H$�����P�FM��@��dnNN��3Nnf`���?.������Q#�s����Xt�r��zv#�?:L��H��G��8�����Wqu���%�����>��zE�KE
`���.���ws���\����X��y��UB*+�F�[�����$���_�}��9u+�s��[���������
�z��K�b\(DM���cX��YVo��^�������n��U �3N���d�V�JNG�{b4(8{���+��)}�vg��G	��>�:>9�;��`����>_�NE9�;^�p9��PV�������t������h���l�����,0���u�o��k ���\���9B!�B������)�#i���@����d�����
.%�~5��$��-��T��:�_��JE|������R��{�m�]�4;^���5�������Gw�p����>j� IDATdrr�������3���\�BF����&��
F/��mi�9�)��{6�9���leG*v����_7�/��h�y�X����$L�-,��v_a���4x7�#u7�W���6-9�W��O��[����������8)�U\�m�lR0z�5����������������R����l����[�rVX/j�no��=���9����C~@���a�v���?"��.�r,���Q>R��u{H����L���(����z=4��#e�cS�����mZ,��c:����}�?���3�7�I��n���N��sV�Ap�\��rP��+�;�G��B�AX��7��\m�f���2�[:�zU�@�	Xp1w��"���h��*j*�;l��N�>��_�8dw��C!�B!�������d����{���Q�\�1�]�4(��&���4�W�iN|:��8u*���p5IYj����=&0�8�&]�p����]�8�+�vS��W�3�
"����zi���S���=�+�A�=�N���x`	�N��[�	���&���\���!��tE_.�CU*5��d�\��=HE���y�{�%��y����RA��@������4���J'+�gNg�:?Z���rN:|��f_�_��}1O������6l0���4��s�.�=��=~����������F~�	����p!��>vl*C����V/�m���oL�����V��e�&��s� ������Q�}���*��`RU���$�0�b�5��>�J
u,��O���P��{��f�MuK��0t��X�sy�WwA_6���(�������3h��qC\N��|N���e�n�=6m�JBfjhIH��duj���8�:��������I8�Y�X5-(�~S�`��.$��I�GZ�j����L�.>d�����NT����y����:z5��x��=��t%��.v��!zR��`����_���,xf��"	p���~
�#��`vD�%X�+�'��
m+��f��u���8ialG����#�@������`l��)��=>�u�|�
�C�m��8�
"�����	�6�
��L8�h[Ey�.H�Bh�pt�.&A:��j�A�2���"	t���O�	U��tD�W�^����������! �<
�1+�u#t����`�����/��0�2�������h\�k�u�
!�B!�Oc��#0�~�3�v#���}���sS��
��3	,x�1>~)���a4���?Sr��>��yeX��,�y�,������G���)x�k���}��z�-q�:�h��0
��+?BF�N��uUp�7�n[>d�+��#���C���}h5����U.�����_�xU t����ZL�)�s(J�+{����y����y�hd������>�:M��nI���tyu+��3�u�^�e�c�>����V�hx"Yzw��U!�x�u�����^F?q.k���m�8�T��c
p�������ml��/R���W ����L�k��9T�Me���W����������5�X��{GR���:�������h	/?B�At��Yp8~
n=�m�w,}k";2T����qh*K%���M������k���}Y��+��S�����E�zy?V45��r�<v�����Q� P�~����,}�]vdXq��>�m7}^ai��a���,?�_�DX����$���PiM9�L~�����K����N��������W��������M�B�&x�<�$T�9����nxgD=:h�~v��a�%���j!��~��o�����R�4.X!�"<^+�M������r���g@�>cB< �0���|�#x0F��!p�������K��v�I�|v}�(���{������0q)�������p����f@?�0�2\�Khv&o���C!�B!��d*t�Tll,���E����!D�7������e�+4���c����Q@�������$���#��cCxvA��U��*���^��w=���ujx�u���g��}�yfI/<��A�S�l&��~I�q���?����4�����.ET��R��V<�^����S��������s�K��2T+��J����D[�f���E!�B�o�������M\�bC��}��`���������]8�K�"7
!�B!�BQ8i,�����3�*xG
���u�u8�B!�B!Dq����Q����Y"e�������/�����8�Y��p}���!��_K��B!�B!Di'���F�*4�l4��\'�B!�B!D���%*�B!�B!���X���Z���J�!Z7�����N8�_ ��LI�P����
1T��qs!���v/�T��_��	!�B!�]q����O�k�-���L�B&����X���o�!�B!�B!D�t�z�����2�\}�$��q�h�eoR�����D)o5��y���-^M&�Px\��S	���K3�3h�%�(&��K���zeG+��G�k����@I�UjD<���7�|B!�B��A���-�wG$�r`���e_���\��tS���ri�P�S���R��c�����7�fJ����D+���Dy�����W\�Y��dX����KD+���(�&w1��%.yCI� �B!��B$B!�B!��%��B!�B!�B�����bq�do����P����=�%��YN���K��a@��j�S	�%�$3'��g��N�FP��w�N�]�����q��f��|�h�zt������Yf���*o�~�'��p5�����;������/J���E�C��O@TW��H��{�m9��nX�+�>��AFOi��>�H�a���������U����z�[��/`��|�50�ax%��Yf���a������Q����R��'	�~[,�Z-�+�[���\��NYwS�^h<�����W�����GFX3<�B�(~V��>�����+T
�m���]�E!�B�v�����3�U+�z����Z��)��Lz�e��t<���h@��=����(���%�vi���,�j�b=���v���h�G�0���ZWj���PT��m�D���}S�_�8���1m>�C��L���l��f2����)��������Q+���7'|�p$MIr�����5xS�����@��P-�m�/����PU�eo1K#���4vYS��8��z����02�f8���
.�FX��u�������a\ �_�M�`�YiB!������C-:��U�Q8@���/N�puQ ���w�b,Op�6T.��.��
��
�-�X��>�EQ��m�oD���n/*��5����-��~��_Y���c(��^�Mkq*���B���)A�2�>�.�,��+Ce`�q����Mo��R_�U�����C�j�m�����r/������(��d����Bs��]�9��2M%�B!�(�����SS���{M��%�7c�Ri����~��&��v��>c���,n��w��c�,n��x�e��,�Bf�b�'�9���>0��O
���P�
�����c���yrqW|�&�?��^�3�pQ�y�)~���vu��������3�n�����\�&,aJ��$d���.�����67�{��l�������@�	-�5���X��0�YC����|��K�!U�x�A�
��n��w��kz=���/������e�=��=�Y�A.VR������qp�y,���{�N#�����^�q�N���ys����H�?�$���c(8�|�$���i[����96~��s�.�uA�q�����,�4�����o�
+����k������w���<����w��d�jW�S�F��l@�i�b?���#��cp$������y��y�k�}�B�m8��dvl9��-��~J��e1;����p��1����j�a��c��|��n�U�v0������s���$_�`�B��]i7�����\����_l���,��+R��tP!�~�#�{?_���q����`�?�����f��t�|�]������4x�+�_f�g�6,t�f�w<���N�ph���3a����($Z�bE
��c'��Z�)���dt����r��\�	@�������������`��7n��z
���cY{���#��
K����`^�\��=��H�y<�
�����$+��������=����ga�q�zC�N02���AxO���g��Sp.<}�s<c7�z����	F�����d��f�Vs�R\�_���s��b�f����n���2e�c+i���xV�
�g�� ��&H0A��0����
B!����*W~��Y%��G�n�p��9��`�N$�����d���q��� ��*+�1����@��>��-�����t��~=�
Rx�b�1�A�<���r�
��9���x@	���M�1goga�7���/��5��c�`{�k�T�6����^(E=�����T�#�\]���
��:2w�#��q�w��~��vE)a5���B��s��	��EF���`�/X4����%}��,^�I���s!{��L8���!t��&��+Y5v4�]�0������z�#G���r��2m���uh#���IZ�pExN�����G^���g1���_���
2p�mh�R�lh�9k=[v}�����7:��8�E4���OTB������6��s��.T��*�G�T�9����������s�w�A��>y����G]$l�h�}�����-����@O�ON!,�6���@�{����{d:s�G�PY4�d=IR�4{�-^>:2��C�{�2��E�uw/������7f���A]�����5+���o�t{�~�r��&���/�}�u��K�j�d���5�H�X�k&�h\���sP�g-�����0`),��= v	��
�Z�4[W����y+�4N��O�'`p��Pk2��6{��n�#�`]�(��c7C�n0�XO-��*C�����`Yu�>�_��[,y��0�Gh� /(���7������a�V�3ZT������2_�^��F�4z��W������P8v|���-�G�v��i�::�
U��������&9�F�P�!��Y��2�����{�t���u����s!�������0,l?���s��
��6(��
�6���R��������#LH����%_�|f��Hp/J<�0�>��`�l�4>�^@�B!�����A�YvL���i�_l��a�,�i�?���
�C����������&����������RF�A��'�'�{'����������
��R�Qg�
����Ws�����}�GQ������{ �z�B��WQ��� "
��
���^,X�&�E��&�C �P��%W���.�.�` ��y�<O���3;;�����T���PG�wC-v����*M�j�����:
V�jS"�>�Q����m��|����W�MMbP��eG�woP�=y�{N����U��lS��e����H��~�./mf��)��i�������t�����5]e��y��e��~�����y���.��������k.kWIT�9�Nm����I}b��K�������-��7u�����G0>�����r�%�	�=�o�#�!�`��A#�t��#�Ar��!;�|���X7i-:����V��^�W'���@u�3���E���m�0���w:zX�O�����8tkY�*��C�W���.A�8Z=��og�����$�;t�W�74*���;�_���K��k�rG�MV�v$���|?n�|t"K�MZ�fx*��{=k�����3tj�d.�F���1����������+|S��-�<w&/�
5��C0xT�DM��V�n	��Z>��Cv2���jk��w3����hi�*6��L%h���j���O��������RAZ�w����� 
��AQ7W�,>��@�?,�SA���zL�qK+-U ��5Qg^�.���3L]�M������{�G�����t�R�����n�j�����@���L0c�(Z��������ua��"!�|v^�*8K.0�9����]F��� D;��������3T/oV�)��7a�q����,NS�Z����#ZB�
����0�4*��4AA�_6�.�|*G����MD%e�2u$���o~f1���a#�OT���k����!�SOs��%x�UDF�v�i	�ja(�'q)]&����5��P|������
CZzT%=��������[����h@j���������{�g��	Ka7���4������v����1���q��/��}c��zUp�z������m/.������}J*e�{�)������^ji�vS��W��e�S<�P�6 ��Q��p�{�C��f��}\����`2���i7�	U4�-��?����("B	t��T
B��.e�yI�{�C�/g��S\����o#R���m���\<b��{y����
�??g��H�~��h�4s*Rgw���-�5���u��
t)�oWX��9�����}���>#�lu���]�k2���+	\���#6�wQ�!`����O%d������]�z3x%�� I�I�r
��
���<�y;��%0jAa�]��|����u)0}5�<Wt`��h���`�0?a��RX��
�Y!Cg	�u�n^�}dX��Y����J �`���($e�^�	T��,�����
�A8a�x���c`�a�p6��qa��0��eH�i����!��f]�����D%�t��\nZ�^AAx ��  ���g��c�3�����-��$���yM�����������)?�<��[���MBr��$]P��j��F	�ed����u��N�����4x�Y�W�B�2q����#�x����M�x�����[�AB�������N-���>S�� 7���I�y����&�T 74���	��8����j����d�7u��	m��G�Z��3�r>�A29�o�b��@��6����U9?ed�mB��sq]��p�R����8jP��.��q����������}Uws��6�?.�r�6Y��nV�@"�uw@����hdr�r���t�L�+�����$Joh�NC|U��.6;�M��g`=b]6����`���K��\]��H���q���V�9����=
����1P�T���4�
y���9�)�`����^�	��@i�/��+E�Z�� ����l
����P/�0��Vu��k
,Yo]�am��?8H�qL�mm�
�I:������
hT����>�f��!� J�����rH�\��(m��$�,>�AA"8HNNhU��������9��*vT�����%\ /=�j�L^z.����9AR�<�����u9=�<e�%-Cz6�i��������<��shy:����M���O:.��K���"'�f����E�g���'��4Gl$gW5*"F��c'�7J������RS��z>~Ho��V'��`����_#��/i�D��M�r��+fg���S��sw���"��hpp�9�2��#h�xA��<.�A�VX����'���CV���H8z8BZ���3����g��?�X�����j%<�44/����2���
J�0�&���p�T���;0���Y��`�Z��/L�����c����h{[��=�T���'��.�lUK0R����M:K�EK�0C���Ar�����
�!�Q
pu�!�2��(Yg~AA����	�FP�L��c�,���i'8{�P���B�U���i�>9�3��#U��_��QgH� �`C2�O������\,x����S��#�w��^}�)�s��/�-�e�[4&*0������+�8'w��x.3$�g�O�9v$���w�O�c���q�H����G�Z������<�kc���"��5\���e�S>'5���5p����u��w�=��gJ5t�w�S>����*�����;u%;^i�N�$%r�R��9����`�=�di���=�Ns�}1y��8k -����=�(�	��$u{���8�3�.!U
���x�+�[�1��s���)
&,��8��T�ol3�4F�f� IDAT!P]'3!��Y�DzZz$*�vd��M���7��XN�9�|�\���y>�{��5���"�u}�9{�	�M�z���~�uMM�/��ca/E9�\��x�d�]p�e�s��
J���i7O�z��N�=�#�5
V�/R.+G� ?� � �C�!�[s)��P�Mcf��S%�(���bNK��"�3��������4m�E�����^K��Y��R���".og��fx�;���<�&�X�p�i6?7�QU�_��_sy�)�*��k����Ao�M��B�Y
HZ�C�����s�+�7%�~�_������:��
& �I]�r����y9I-��p�Co�����9�d��.g����C��r�j�U^��G����ek��v�I`��x9�H�3�U�Ci��~j|&
�H��Y<�.	��C������x�=~�&��]���~h/�������W����4o���_|���������m�#~Zw<2�c;9u"��s���I���C�*4�����n��j2��.��#C~*zYF�v��sZ������O��_'�W.`o�#a>j��x�jo��
�X����b�\��s<��w������XZ��I:���Kqx6����^�#��z�{�"�r�T�����f�sH���K9�Q��~
���Z��us�������P�}o���BL�Z���oki�A�����QC�'5o�C�����-w���3P_hNl�#�I'�����)�K���
��������
gx,L����s���l=W��Q�Uw��l}�4��u���h�����=k6��}��p�1�v�3��7�X2�L�D���v�L%�GB����d���2������4��2/h�p��
�ia�vh�o��c5Y(\�5��p���
������u�V��-�����U�Q�E�.��U�tH��u�BM�u��#�]������p �e��l/.�k4�,5���c�X7���}�-� X�����b-��
CCa�\�Z�c��q^�)���$�AAf"8���S����7,��?~�E���4����ZU	�%[
��gVL��o?�PE����w��qU�ntq�%c�3�u_"�>A�6��3��h��h��4?���/����3A���y}q4��[�p�S��z�<�"U�z�+�s�'��i���O�����'�/����q���*J�5�����?3��R�D>���?��D	3#<82v�������������-b��{�ya&
c�����t����������4V����������l^2y<c�Q�WG�
F�)������Ng�����j�1�21�Z��0���4~���������A"
<����	������KO0��p����:�����V�����c���W��Dtzp�/L�e_Z
_j|�6��|��z?c�#����w�V�6QZ��S2U����y����C��y����p����\{u1s����Kd�x�������G�p����{~a�����q�3��+Z�����pl����Y��2~���*(��w���j��'5>{��K�8�W�\5�N���:s2aL�RG���A�>N�a�Xzy��a�a�p4�*��f��g���T�8C�p�^�����>���[h^�",�Y��a�2�~�0��P��!0.����O�/�z�N�wme��nL���g;�k�a����y�����=��m�<=�asx�)8���nG�o��7V@����
�[@��p����A�d��\�zA_;�����T�{��E0�C��/��)�z��9pM
�Z��5
���)���Y+ %�<���0���\�JH����k�����v�,���AAj�^���xk��!>>��ny}'q�;�x����nq����oV��$�6�����7�����;������||C�/���$�4����0jq[������:�2�s��v����l3Q�Y9;�XOg]�K�s������>�qnv>��Y��I�����n�u���'�soh������}�%�~mZ���{m}�V�G�f�����pO��� �������e�/0�"�RAAA9z�]�O�����d��l�E���������BE�w	| ������� � � � ����`�L������2Y9*\*W����
/���P��sAAAA��A)����]Yg�?����)�����4;_]�����>W�S����5�� <h�������%�=��3a�}oh_��AA%"8(��*��S�Q���!� � � � �:1�� � � � � �G������R���H�_� B�c�1#���&K�C B�Y�Y(�=�4B�}r"w�q��k�+�����oUtAAA����z�m&��5k���#� � � � �}r�z�<�Z�,g�wI���Z���jI�sD(C�:7I�k�js�}��H�O9*e�U ��s!���l7"�i�=�8� ��������P�N��U\�f��}W��AAA@�XW�����9U���X�s�|,�f��oV�����anB�Y9���0K�O������!N[�>��t���#N[���!��Y�G�s.g�=��-Ne��ss)��=�gd�uAAAJ�X�DAAAA��DpPAAAA������G���/��O��1re�"�j�x�
�?���FT�z���uq(�l	
#��x�o?����+�W��CEM���Q�LX�?����w��f,�^jG��%��D�$��-\�jH��nH��pf�~��#�l���TO����{M����7_k�^��=���G=?2��>���%�8
������?�q�y@%^&����yW!�(��1t/���z�u�B�"'�w
*�|�Q
���~?�S��*p����Om�X�Z��.� � %!��������o�Q-����?bEY�Gx0�E�lZ��8����2��W��G��8��B�������_����a�=�������I�w�8�6�:7��\�����E�u(Ae-���y�'�`����>q%�Q���e���+@e	�;��!U���+������}sp�@^:,��Qw�AAAJ�
���O0��,��j�bI��w�AT������E�K�D����l��t�G�s8����&9���#Q������I~���}�%x1����3��/4�]�	�k��I��yW`D��/DAA�����\�u)�?����:$OO���������#g�N������e����C����]yi~}�
��L�$M������jt'�':�Y��N9��o�d�~.�:��U���gr[^X�7��i�����U�p|:FO*�J��p��eX�����g
.���}��ct�������q�V_��������Fo&�����d����s{�Z�$�8��j��V2;��&S�M��.tW	��������[8�����h#"���VB,K�l�E������.�j����S�����>o^z������l�8��~O0��z�)9�#�>b���$���P'Y���j�&��O��@���i�B��A������s��	�rT��6}C�������8u�I�`�����U���v������l������B��������_*��Q��
&��G���?�/|T��������X��N.\U���=����i�������6��&��^a���������kQ��=;��g�f��\�������'a�xB��$������iU�;��$SFd�w�<���}���i&�4�qQ'.}0�}��at.G�w~�Kg�2;�����N{����o��W�����?�	N2l:�^�����C��(���u���i��
�e(�#�A{W��a�������HSB�r��?��3��^"�(��"��3.C���g���?�1�C��d�U�;���+�7�WsM��)��
�5B��,\(�@���'`f*�i`@8�97{�PAA����M�1����t�������q�w� =C��cmd�:o5�����>�g~�4�L{2�+2��#�z���_����u3���o[������o]��0��G�q��o�7��9�0\`�s�0����M/��Y}|�2�w���H�w��o2qu�^.T�Z��ug1�������=�/�������u1��%���I��L��}��`�93~�db}5L����D,]�����u`�BV��q�}���H~z.:�����j�h�i;����e��!#���w���L���Z���m)?>�����h?�K����W
��)�}O���S	|�O�L�A���;E�	�������F�m���W�*4������a�g�Og�K]t�N�]�0z��4�Q���0^8�������6�I�S�Y=GE����::��9���i�������c�'��U>m������{��O~z:�����|��h4y4��'�lQ��Z�z��+�i�������'v�'�w�!^��I�??���o.�6���N2p�&?e[&���=+�lr,)j���p�p
�Y"i�a������'�I����hW�vfZ}������0K�+�o�a�3���7h������?���0/����@�UvV(Zs����awU�V��*��>����L$��
��07����>	�]��H�[:/�EV���L������8�����=e(� � ���s0��9RQt������.&��������r8�:��?l�������9��^rvd�;u�P@�Z����J��)��l$�J[���_5@�3/0���\��P��q�,�<G�����Q~[^��de4�ws�|C�I`H�����������nCr���[�����A������wp��v�'���+����i9T��a��D���(}������������p�6����Jae-�����S�37j��6U�^�^�	����2�3����J�8��>\F��imK�7�����I�����Z[�FEs��zw%T
��X�BA���S's�hC�@������
},�!c��c4� )P9�QH�]����Uf+�����Z���9��:�Jw7<�����E��pzWjJ�>��u��v��������n0f��0���,m��F�P��~cn��l���}������u��t�3����=9��r\�-�i
�e�$�4�w	�>C�^s�v�o\Jg{�1^���":<b.�rQ�2����{"�2T�l��EE�h��c���'!�����������`������2�`F2*g���<��`V5ho)���� ���?�'��g^�/^��������J	�J����l����hN����[-M��'���w<l_��a�������a��5��!:V����2�j���
�co
� � ��h��0lf����'�����:�]gI)��AO�j����u�KWd��.q������ar����R��#��w��;��R
�-
�D�2��WeB���f�!D�?�P����39�{
���E���C�|��3�����(J�[A*J�������e���|��������e�)�&�0ed��I6:h,�������go���2����U����MPG����F�Q��t/Z�����G�R�Z��^�6^�a�6�G�2���m��nI$�5�*-�l���R ���������9���@S�v�F�0\���%l��W�s�k�,��jE�B�
*��A��:m�yY��P��x>�C��[��p�k�Q��Z��I����gi��P�y��vS�FQ�@��{�_�X3p)C&���TU�nt�2�c~�o�>�����pH,��vC��P)F����	;M���UK��n��r)@�[���Z�(W����������$H�����5��C�Zo����L��{a�SRCg��i�����}�
����V����y	� � �C��*k���W&��b���A>N�w�@����X�cI��h�J7��5��e0��e����K�
��J��r��7qa�d�{��F9���
g��n���X���=�=o/�F� w�>�bP-�.��N�gM�I��tY��='����_1�
��K��hU&�0�?������J�������#<�$���*y��*_*uc����w���U�W��6��w'���V��i2�������-�l��+N��������T!4�i�����I� ����W�d�r/L�_X_?��?�M%������J
�F�����l�I���FD��W�*�J�j�z��;t������N��GG�\F�%�W^8{���fW~J�F�<n� ������t����sd�!_��v�D����d���V�<���I�.R�$J>4�$�n�M
�^��V�MF��mZ
�+!�h��Pg4���:��w�s����$� � ��#
~=;��ggL��9��2�����bHx���FRH}�7�o~"�3s�3q�'�1C�^r��U���e�Y��@~�m��;�%�8��V���tlW�iYR�^�XB��3���'j�5c�D��G��kXB)9=����s0�����o+�?��%��A�����y\6������|��O:�W� R>���N��W�\�$'s�x��b����6L8z:Bj9���)BB�6qt_2F�PIx�*��E��w������G��Mo���j,��j�y�l�M�x���|�.��U"����j7�z�LNO���d�c�����Y&�W��h��N@��P�rn.*P+�����M[� ��c�z�B���=���e����P��yo�!��y�C�
�@�	
�*���xZ�bW
� � ����$��^DlI�(���`H������
�O���!��S�I.�������`}$P�TYI����@r�����*hGZ�p"�*I9��K?|*Z�T���d����\���)�{uS"�����F��N%r����8����`�=ln�q�@j�Ec�&�|�zXu��>����xQ��aJe�KI�h�����9�z~)�um8u������?>�~n�
�
���y��krl�����O[�*�<�Y����nQ�L�Z�����nQ_U(5`���.�u^�������/��������^���"�]S�V�$�Lr8�m������^P�pj{�����L�'��?�U����{s�2��K'!"�B�,x�b�4��^uu$8�QNP�����#Q����y�)�����O�9:;�V�����XW�M���!�����)*���;8Cp ��}�,8nu�v�� � � ��5��L�O��p��[���� c�zvw��KTT�g�H\>�����n�@�+�{
(r8�<��Y���18���_?d4�>�jbUgm�U,��@�fZ�����%���#-��^m��ns�I�����q�����S?�C����/�S�R��0��=����T
���jI:��aKq���vV���f=m�� �a8��[X�Cu�8���' �IF��*V������sL���K9��x��NJ�����%{��)�B`�(�M���+�6������9*����#�g��h�D�����M��}6?i���S��mL��Z}�(���<~�?7����Vq$?�8��z����T��x�UV�bI�Y\^�wND��E�
����Hjo��o����b����h-��6����0_5JO����j�y=Ld�Y�,_j{��6o�����__a��r4��i���L��X�MS�E��2@������px.��9���A��O�����4@�}&K^�H��t��%c��N#����h@�h���NK�b3��B
�=�A����F'X|	-�+�
-�=��6:��>��AG��2�a�`hsF�s!PY��`��2�w4��d�y��W!C��P�c�St��["��tpVa��0D]8��R����������W�w�
Gx�
���Wq�40�����J���u�`����|��<��3��	j���H�
�[�� � � <��KhcBq_��M/�#3MFN����iU8|O��5�������0e�����	���=���cc� IDAT�������H�=�����X��N����X:u>s�v$��v4���?�)QZ�F����7���u�4.x�FR�o=�J<$X��e%��p�Y��F��IQ�)����A�Px1�?����v*���+�w���q3��+�2h�?��R�N�i}�6r1s�����Kd�x����%��.O�C&�:f�MS�{GR7o3K�:��Kchk�����t|k?_�6��-��ie�F�0����6���5�4�x���b���mC�E�oF��p	?��=WM8FF3�&kI5��l(�o�d��?�����z,-~�D� 	�����\�������k����\��EOLC�+�S{�R��6]>�
}�>�`���v���$s��`�M����S7�'�����KimL)�z�q�
�~w��-�i%��JQm(������!b��tU������<����YF*N��������o����`9W"��x�8��n�9�0�i`�E��3�cX�
�0�:L>
_��2D��_KM����U������<!#���Y�|e'�h}�Tep*xA	/G�s�����T��7��?��j��@�(�B����
��@w��~}c��qH�9j��e���2AAI���v���5k���/��[�{�8��w���s@��\��v�YyH����+=FN�|�_���������W2�3����.t����%�I|q���d����?D��g��F��e�������1_����X����a�nq�{r��Y�������{�8� �����Y/<��A�z��a�����7�������".r3o��+��� � �  {����=�=��dtg.r��q6~r
�nOS���AAAAA�Q'���$#I�}������5��� �^AAAAn"����������2I[E��I�3�/��������fD�:��6��'���9�������}��#� � �p�����*�����nY�CAAAA(S�T�� � � � � �k���`i�T|�8J�;���(���GC�2���P,{��t�9�;�P����m���N�e��F���qNAAA�I���f�9X�f
����+?� � � � � �'���`�������>��.I��D�k�^��p$i��p��>�+D���S�JY�������$�9"��=Y��v�&�'��U�P�e��\\^o��(�l� � �  Go�����I��=��1������ix��f��8���:=A��f���-w�}r����O9*]��/�V��J���s�9T0����Y��!N�����
g�:� � � �B,H"� � � � �Q"8(� � � � �Q�tX�CCN#���\)�������[�����e����g�����Gi����H��o@�z4�|����`f����|;�<�"�H���o�e�I�B�@`\�^����|K�����c��_��?�~�����E���@��P��n����Y�:�W�hrn����������^�sz<��t�F�����.��}�����,�4e��������/l,��������[d�*�8��2�:�M�I��}1�/�z��
D�A�[�lr:L�����*�L04(a�mZ2L�{���@���AA�G���H��7��K��|(�7k����xs$+�:?�����>�B��G�TV�n�i�izrOla�g3�s\�������39� ��������;�{]�}^�����6
<{���jY���`�����e�TU�)~o���������h� @%A�p�1���<���h	����J(���+����E��(>8x-��'�X<���*�J��~���Ni	� � �`�%~~8���I9e��A$i�������]�����9?m���U>�������~��G�re�j�<3�&��0����wiNT�/Z-�[��X0n;�_���q3*���P��6^����-D�C�'���:^��_|�v��w���	�:���{�ln��%
� � �Pj���;����Y,�|#��r�<|����<Iy/	2��K�)���~ho
��}����nU����Z�L[��]gHO5�
�&v� Z=U	�������]M��%�m3�q9���	������dS�>����p=���>Oi�����23,��I#
t\��K�a��+�����;t���dGZwf q� fnB��g�1��*"�
���:���L����������X��
����#��	Ch�lU\����KZ\���'���p���a�7��)9�#�f��x�<C����-sY���?p�G$���s5m�+�s��5���+&"+S�����U���U
\�E�.�%=9����a��La��-�4�{��L��J�	���/:�.�����������������S�T��(piO������?���-����:�>�����z�7a}���,�{%?������7�as�^�!�� ��u�u��s�\V������b������i?�H>s�q������?\�l��|e*=�,m���Z?�9��0�D��>��e=�=G}`n(8���|r�������7���u:�~�f@�a.00�;��!���=��>f�B����[>�(������(`j�a��)�$
>O������7� ?V�C���� �}���������i2����0��l ���
&X�����b���r��$�l�_�a����0>�?��MAA��HM�0��������!�<���&=S/	\���oio�����r��x�=�	���e�L~b"i~ui���x���Z��	o���s���y#�d:��m����l�#�m�W��S�>����I�3����#|�(��9;�g6n�C�����Slx9��	�2�=/���d�����g�������w��h�/c��������!�v�+�2�o���?�c���5{��_UB{~�>|�yNS0�H�oY�B�2��O�Bg����uR#��������%������������=h4?����3���o�5�K�U��_���1�i&������
��{����S��WhY��������OT@s�
�O�B��H�G��^�l�J�Ac8����$��m,w�����z\�
��x_r6����^B�2�'�Z����cIF�lH��Y5?-j�*�;{�2�������D����6��L6n3@��#��	��k[T���.J���IS�F_�x�/Y6��z�����/������� �o����~%�e?��\��u�{{,���a��k=h�o����WhY�������f?�}o}���F���j8J�v�w������
�h`�Y�S
?[������%h�\��u�v�@?����|x�0�����PQ	�i�9�:�l���W�R��c�02	j�C�I��*O�O��go~���p��=�+� ���X�q)�KP�������c��[�#)��1p�
���U�����F��+�E�����r�u���7�p:��� � � <���`����(��}L+*8T�BG�$�C����ZB���G���)	��C�e��F�Q�����wmR�AS�&�5����F��KX���^�Q��o�~�vc�>�1%(k ��OI��������D������r!�����$��4�w	�v�U���v�.%��s�R*C{�1]c��%�T�����WP
��SL�n�"�:��*C�T��V0������f�0zNg\$PF���K[�1��E����py�����w6]e�����f��>��j��y������#U���_Y����3>�S[7�5mR��~Fd��-0d���2�{b#�&�C��������������,�#�\?���~5Y5���ng��c���b���I��$���Gr!��&�|�ON�^� ��K�sZ�Y�����t����W������6�2d�����E�)+�V�Z�z��t1_��'���f���}�m95�o\^���u����y�T���}m�9�.<m�����v���������l��;�H����)�8�v[�H��2�^T<�����/��
�+A5K�M���%��iA�Oj7������Sa�m{�a��FCKK�m����4����y.A�@�}�gAO��J%)!_]��_IAZ0Z��nj�������jg:�d�$pP���6�Z���+��3���}i�s���h�[�����\������qKZw9o� � � <`���:*�26����Ex�P\����1�<�>��-Ks�r6��l4 5HGg�FEX�"$g��T�3����%�|B"��J7�K����Q���LUy�[����foZvRDD�Z��
���(f��R�L����oK�%;��;����o�������n%\��$9E&4�*��*C�t�7"~�S6�d�#���g�+�\�4K����~~.���U�aN�6�B3�olT�U�
.�#����H�����Ti�fsM%���o9e9�TZ^�*����M��"5AMtK����!����x���GA��<	o���1.�Sc�;?�F��:������#.�IK�����U��ND%�6�2,5���]�Z{���^����,m�*�c��k�;��F��g�*�L:J�U�A��i�u����e{��y��@�OXwG���}#a�!����;<����o���NBBJB�">5R�H%�(*"(�"*(���"* "H�����H'���m�?v!��&���y�����{���Y����	P1���X�t��0��i
�.�$�U X�I����|�k�P����uU~
$Z�����PK"�9T���P����+�����;�j�zf����gY/p���C��~�T�N��yB�;$!�B!������Am�G�1�����������"��>ty�!�]�������F�`u
F�L��V�Ny�%�d���e��Rl**���b�*��z9�z���t����4�����]�Ke��������nD�U�n�.|>����u��$R����c?p���U-Gj�
���;���_�!������n�]I":D�f�.��7'��\MN$5���q�3v��gTV�IMJ�H�~�|���y�>�x��^��k��P>���P5�x���
5��d0z;%tP0�x��RHO���P�}��`��sW����8��9������8�s����n\�r�=�MW��.�����GZ�4z�V�o=���Y�T�IMBm�^���x���bz���~B����mI�9�d�T���:-WUP= I�'��[�G�?���,���=��|��[
h=aZ�v>t�Z��C���*@UhU��\��#�Y�KC�~�T���:��}B!�B������|�FP��<��/��K�Y�
KF��:u��u���� �W�Sr�����ZH���9|03���N%=57�v�tL�j��F�����&o�RY��&$���[��x��yf���T��P<�p7�{�}����V�x��Za��CQ���kY>a��+��$v��@�r����Y���/}J��Y��p�]�}� �:)V���)�����L������P<p����d�= =!������YW�����~_��@�s6>������OIG��q��e:�s�����_�����oX��&���D�W����}F���i�0G[�{����X�7��.���7��;|~
ZU�2�v����u�FB��I;
�R|��`��	��L���p ���P�^.��}K�1����f��
���T�b=gZ����B!�B��3���x�����$����O�V�4�?{��,X��^:�$�������r�V�+�Og<�<�$��9=��0����}��p3�4�n;��Ly�3
�T0x�z"�Y���k�\a�LXm-qG���P��p��
�x��E�v���}��2}�:�mZ�>��a�3;�7F����#W��P��p��
!�v����&�7��o}b�c�j��cMFh����vs�����s���(�	��-M����8����3:m�R�[B+���'���c�?�t��P���v����q�\,]���U�#�}����v�$�����W��T���N?�B�0h�kT����[������]_-���d����?��������F��Ywo���%���P#��dO�����LP��;��3:z$*P��H�-Y��.�I�4���n��3��X{����6�>#��S�3���]r0��\�R=!�Bq���[�H%q�dn/A�f����y;��PqD��YQm A�IX�����)�C��q�+R���ss*�;e�.��,&���V����]�-��a���iT����s�U��Na���r��/��mPm�G��fA2�^mAH��GK��������s�R7�}`iJ��@���r�&�������1<JT�r����v`?G����N���(Lj�yN/[O�s�k�i^7�s'�jk)�.�N�����p���,��.����QcHg��|�o}�j�������������:���F�k�i�P�g#2�������81S:s��y��Q��V�r6?��A���H�8�����<���g�O��jB����^���B.�*M��u�2�K�t�QM�'��|��P��f����Q�/pzq���%�um��m���6���/�	r�8e����;����wf{�w�����q7]���=��-g;��Aw�=����y��^DV��t|'{��yg�4*ivp��
lG��dK'~�F�'�0T�Mx
o���g��2�!��X��nJ~�!n��C���RN3���)V_��
������M�O��n0��)0�4t;�}���j�l�?�����f8���0)��S�v	��
#����������
����X���4�,�;�A�e��J..���!{*��4�v!N��h
P^�.Cs-h��`�
<S6�'��~�m��I�q�����(��ca�tx�$���"��\�j=!�Bq����$
�J��,]��7�t��1�
���I���t#|������/�f��w<�:ZM�����a3��#V�P�u��N3Xz,w��<:�W>a��~lJ��D���ox�?n�R�e���FG�58������	"��W����?fu���vMb��Q�I���{C����u���}���k&,gY�K��}��I��U��������wd^��M�mS�����c���gDU�w���mO��72}�x�6��&�z�>C���Y��"���H���*����mF�jJP���O��������
��H�x���Etg
�-^��d#+&Og�7��JF���t
pJ��6
��>D�1;8d�MY|z�N��	,��R}(��;��t�gW��&�6>��Jc�M������KG�!���DUu�u��i��&��6��->�Iu=�F��Sk�,bYG�U�S��v��z�G����������
��U��BsG����a*�������{oq
��>�����>g��/'d^�����`�����P�q��.C�a�	h�5P�4����K0(z�X)���_c�	�����	�e� 6���
�N���q|rP�O�V������`�S�1����*���U
<[F�
���{>V����]�fW�I�`�	0i �>.
%0*�<
-/��)�O���q�P�+\�g!�B!�s��l�v���u�������[���h�����
	�����l��uq'����uy��������#]y�������6+m��f�N�6b=�RD�k���D�orQ�f�l%���D�u�;0$�oO$�"�X������
�3D��02���E!�B!P+o���$�#�B!�B!��$�B!�B!������9(��r�?�X�����(�����NTxo6#/2!�B!�BQ�$9�_��@�q��W�q!�B!�B�"%���B!�B!���*����1S����0S1@��t��'DA
3���.�!��0�O��neAw%�5�����+��x;���E!�B!��l6g��9X�n111��B!�B!���X��	�����s\��!�0���W��e	���~��4q�Q>K
�GQGg?�� IDAT!
���*�w�0�������qTE+:�#��*�0�B!���%O�+�	I��u��66���o��v���2m#�P�_�'DA�eJ%Z���:V��GRD�kC��=�u������+cm��k����w�B!�B��dB!�B!�B!��$9(�B!�B!�T�+N�g�������k3�W�7�����`Y�������YlY�Q���k�kT2I`9S�9��.WhO����z��]����� $�-�o�$<T��lj��=��B�bF��w���+��3�^�M[7���>���6.��6������ACyq|x���<�
��f���5�/�B���
����c=5�R��jL*4��[Zhu��U`�
e�{��>d��5�X�������}H��l/
���~	!�B�&����
�����a�pt���(�x�(L�ui:�#%��1���w����Y��E�<%|����.�h������|��#f���K��$����F����=y\�#h:�	%��V1A[+�u�N�����nc����E�jZ�!�m�K��
���(�ldZ+PQ�3*LW�I
�cO����W���SU{�������
k����B!�"�����-n%�p������:!
�b�l�h���^�H1S�eC�������qL{e9�w<AhCn�%��R�:�Oq�l�:wA[+�ED�m'X�9�_��Tm^_{��R��o�����T��Dj)�����^����g^)`�
�M�T!�B��}��p|p�����uN�}�!�tA���������
���������?�f��L��(��C6�
���]� �r�y�z��_�����p��1�2�����O�+��?������k�>��K�nw�C���4����T.�����b�'�=�Z���>���K���q��{�[�Z3��z����1tAK<76/f�����*V��Tz�m_���S���x�����qq����vk����M�b^������^�}o���^��F�	��S:�����{���;
���Cx���5������`�+�����[�g�;?q��+X�����y��P;�qF���8��?���%n��1�Z?VN�������s��8�>����:�I��1�C��������|�Oa����|���d���fe|��$\0��%���&.����$\�`�J��gi��������������>�����w~�.<D`�'�L���f<�=�3�5p�u�z�{$������5e
�Fm���x�~�T���C*g���K����9��</t�����[v��*����)���
���fj�����*|j�����xB����t�K�T�*PZ��x8	��V�K���B�J�(����*t������,��o8������K���50�)��
,U� P�1���W*����@'��/`�
����:i�z���R�B!�B�����=��X���6��7����c�r>��*��91o�a������)����s�j^�r����	����{/������
��ko�xA<�O��\���u��a:��~����3��SY�+g���?�uy��s�"2q1�������}���s8S�mg�����\��?L���[N�i�2�]��������%��*J@}j��85I�>d���-\*E������,�o�����b����4�K��OX��
**�+>f��>4������3����>D�/��up�N{���;�8�]f��������F�yo�66�������X�	����iXYO@���������^�v���K�����%�Uw�|\�V�b:v��A
i4�M�������X��Z���b�kH�5����X4��?\��u!�,�RHs�I�8��$
?jO��,�>���?���%^4���#1��~b�#K8S�m�D��e�:�~���S[_cO�	�03������gh�?���s���
���d����xO����a���e�l�^�N��=6x�~xO��l��T�
x�
�?Cp��;����*�Q`��+��)>�'�ha���f^=�A5P{Bp����t�D��
��w82��`�
�50I���6X���b|���xGGm�g���R�B!�B��������MFE��@�N�|�f~��&T������.�5�C�
��\�9��]�K5����=:;-jR���,Xzs�F�d�Z4�?����N�m�3�6������D��JJ����9�����k�F���*[���5nqU{0pv��j�t�O?[�����v��X��}�vO�;��������=�cx|������S�[t���RZr��4��
�U��D=]�a��/�U������������'^����i����mW�k����e��^���I��t�R�=�,��`��{~Y����x�����_}"�XQ]�S���g�`M�M���	��L��Iq1��[�$�b2YH=����l -�U��z�U���<=::-j\��.,X��#�2��z4~�������
�j�A����^���ya�eZ�k��!����:�G������'"��v�5x(M�:*�v���[O\����C���B@��|��f�=��������e
��}���{���i$��l��uA�W!&K7�50M�xf�S
L����Bo
Tu�k���
��{���Z�d��A�}�^l���j��l]�� �m��x�`�jZ���:8{Z�����y���
�pj/2&���
�Q�	�AY�*�@�����WO��V��������XG�V��#NQW�P!�Bq���XS!���7Z�j����TB�Np��BH�H��(~�U��)9�mY.�J9�����E�r!�UE�XP'�f���OFqG/<tX��0��s�(������X�}h�Ge����3��}&�'�[y5��[I@-�
*�5����u
H_��1�o;���I4��c����_E����'B����<��^�����=2%��2��;��-V���@���{�r�#��pr�����f>������\��Q:����bu���;�1���y�P�v\�@�[���7�
�2=�y���"��3��4�_�����X,6T�������2���^x���\��u!?�� ��V�����S[k	|�7-V����@D�
)���i'8��J����V���x�;�����o=Jb�H��������m��(��R�.�!�`�Y��
T(��>No�T��U2K�f�@q`�{QY������^�(�/��=YW��F��e�U��@[2�
PG���lQ���)�C�o����'Z���:B!�B���A���n�#Z��vTk
�V��G�����[�<v;��,\�����WG�`Y
��D��uV�������Cu���
�������Fw��:���ErPM�A�����/0v��6�j��*8'5�x���N�=����s�V��L��_�^�5"%5x�S�G��\v���$�Sk6�"�Cs��z���I��[8���}��C6�j8��@�������G2���X�����~�Rz-z�`*�J��XG_�+J�`����Y�~]��%�\�f>����\l�:�X1���rmDD�0�l<Bp���e��&���)�F1�m���6�ji�5E%�Z*���n���s��D����+����b���V���\T�>d�8�������{�zT�����U���l�'�)��{�{��?6�;K���^�Z�B!�B��?9�&� �����7����'(��*��)����j
iI*��oY.1d��xJ�<���J8�i\�����<P�1zAzB��B���c��&�
����1\N���]�#l�8��q#��
x���QP���Q���������*���%6rL!�w���,��+7u2;�}@�r��W<��n�6����g��b�����r�����I�r���m�i��f2�3���qT����A����a����W)��TZ�u\R�dK����z~;��9����M����_�~{*�������*��fy���w\Sl�����$R,���dWT��BM������v���}��i�Y�d
���[����ro����O(���O��cR�.�7�'[
�u���)�:^�L�Z�B!�B��B����>3�������-G��n��P���i�U���9s���e��`�4B|�Yo3c1)�����9�{z�w���&�������$�0�v���Rp����DRn�c9���N��V��zZ���U����~*������jjV���W�a_\jt
.�!����.����8���F���#�}i!q7�2FVGG���x��%���Ox	�q���A
���`�/������s�}� ���1�7���n"ZXRM�<�\�'w^np=����q]�u�.�������h$�������/������U����>�������xU,A`%���m��"�I��6�m�3���������0�g�����
��m�'�(��5PU�wU�yi5(�Y|Oe�0���d�H�$���[��8zL��7�0*������
T�>d��~���X�1D�M�Ozr��s����nr��B!��d�\Q�cl�5nCjc<��5s�)5�9!:�Pj����f�h���Q�}��������/�&-%�*�����_��n5O�A�(Q��P��
u����S-�Q���G|������4��*}����<�v�q�;W�����
J��+i����k�V~_���������j��IM 5��a{�i|c�F���p7�sm���
��W	��Q�-I��Y?���������@M���eHw����%�e-��l�7�U[J�ty7�����4[}�����\9�� j���n����	����n���}{8��-?�`h�w�Y�����0�?FdUOL'v�g[1v�O���Au�&���Em	��$����>��s�mA�<HX���m�)�G��q#���t�x�*������0�Fz�/^�e=Q�U(���������S���G}����.�5-����$�y�5�i]	w���c��`���� w��;s��A���h5��x-�����c[�:�������G9�7���Z���A�=���NC&������f�V?b�7�O��v� '�b;z��B��]�O�b�Lxu�]����^EB<������|�2!n��C��D�H�;�����j��|��F`�
v(����+���<
�vL��_����>D��
G�J\C��0���;��.F:�s��4;�=��[���+�H��*{�<�����K���O�=�I�&��b����mj���f$����l�����T��d�I��:&(��>���,�v��B!��rPS�a�5:����H�'��atx����B�������	�>�������F�������w�e�����?vLf��1�I���w4C��D�	���!\}�K�U_��7�r�z�����
q�������9?O����=	y��:~���k�u���t�KLLX�^D=���2�16|�>?����,�u�t�~�Tz�����R�iY�`�I�����n�~��K����vd^f�M�?�P����o�!p��DE�3���i��&��|����hRU���3��>�5�~bY���|���N��52�3M	jM��~��l�d�.�p/I����t����'���i����7B	�����;3�vn�L��?gu����������\��e
^]����cY��+�IU��3�!�������\}�#�=0�oi��|��.�Xz4�����l�=�y��2���^�&��q��W_%*����)����w1���lm1�&�tu��Bo����e=������j8�������r(�q��<m����Q��:��V��a>��������G�����8�B���
����P��B�>Q��*����J*��SUh�H����>��+��ghOF�L���L|g�k�m�rZg�j�����������rq�}�
�^O���=��h��xo���16x^�'��i`��j�H�9w�m��7m��
�
�@k�u��5��{)6�@�,u�J
!�B!P�fs�����[GLLL�7�"���u��M��#�^��]o�i��m��X8>�?������������$�4~�c�N��K%]��cYw��e��^�6c�B��0c$������T������Y�Tb�g�N�rb�����7$^!ZQ�a�0��;�] ������i�[qTEg��O��K1����E!�B!P���1y�}����g��e�
�W��#������4�*
�J���\9��������-*�g�A!�B!�B���>9�V���%l�z��:��=@����^�$�
��ScG0�G��~�GF� ���
!�B!�B����A��bdk)%�h�$�6�{�r�?^^�����������\*�P�"���x���f�~��2c.�gI�B!�B!��I�qr0�*Po��+�8r�^�Y!�B!�B	y��B!�B!��Q�s0?f*��/}���B��<!
R�60�u4�B�D��	s��1�I�a��EM���]�����:!�B!��W������`��u���V<B!�B!�B�BR`=[$v�����s\���a���W����;Y�akP#�:
QN%���0C���u��qTE+:�����E�B!�B��������$����z�[��2Fe����T�
��Uq��e����n�������Y�������#��LFT�6$�)��B!�"_��$B!�B!�B�GIrP!�B!�B���V,�X���Y;����k�����[�uWJ_���^F�l=����Iq�P�r��y\�F��A(�Vp"��G��g��hQ����e��7b�9�4�,�(�]�ut���`!���������?��kG���Q)���,E�C�[���vD������hi>�	SS�,W�
���M�� �0L����{�j�o/@��(�����?��T�K��n�$F���)��N��17Y���UP��B!�B��$9XX�e�?5L&�}�E��L���J8��tl�O��q��O��P4u59x��nD��=)�t�V�%)����]��t��6c�b!T{��(�i>�!Z3�G~��i3�{�L�}	��d��C��_����|8D(P.��P�P���W��������m���~0)�68z
>:�l��,��aV=H����y�Q!�BqO��n+�c:�J��
��
$u<w1Cc�|�N�!D^(n�(��!���^�w�C)�����K��C0�Z6���������������6,���J~P	���n@�@h�/R�z?X���b2��?��V��m����2�@� #`�vzB!�B����������������s��sv��+E�~�����x�����sj��,�h#�LA��7������/7��\,��-���u��r���$\3c�M��Wi��*n
����[����t�z�m��R�'�]��erg���"5�3G�t�*.�{�c0�R�����^�o�������O�0q�����6�����X���KV�����.a����#h���x9u��,~���[h��
G}��mg����/��%N����i���Y�V�JY�\���',���7P�Bj���S��B��G+|9�G�b�Tx�Ci������������	�%�
['&�d���\K/N��(g�q�e��tL+.��/L����;����o;������{;�n(�=��s�������@~+�2���q������`��8��q��y�z�'��������|�����g���4�����en����@Z����s��jT�G�M�EE������8tL���B�:��w����s����q�I�a�I���aHw����(�du�s�jx��m��_P/���#�U([�*=��w�uq��B!�w��89hg�1���&�{�g}���/�����C���9�1o�>J}��5��t*������.�*������F�
����������~,�\J�n�o
���������a�}_0��hVF5�����TI]�6�
���so������9 IDATW����e�P/w�m�6��]�"����~����?x,���,�n9��AqT0�''�rt���'�)%����VXL����y.��w?Z�q�pmS
����U�HH���p�B�c{kM�?7��z�m�p���<�BE4(h�w�.����q��a�w����'���3Of�V3t���e�������4cJH$�9��w���G1T����s��8�}��=�IY����p� G�-��j^���n���sPo����@��Or���,��6=�'e�G,_�K���qn�����'=�7m�����
��5~��A��J���]f�s��ik0�_~�����]���hEw����$����)����/��pXV����A]_��h���9L����??���5�<�"�i@�b9���tP����?��A��ViT`�x{?x��NNeN�%�B!������A��	MF���@�~�|b!3�Z��/��f�����'���vx(P���5�q�[�W�K5���y=:;-jR���,X�s�6�/�h<�=��@p?�6��U��b}�����5�\NJ�0��������k���gnv�v���}M\�8{��Q$�����\���v�O�^�'�;�=Q��`	�@����<�*�	��P�X�i�>�����.T�x����nL��Cq��L)�&�fP���[�T�DU>����j��ydh[��P�����q*/e���i�1�r���y�fZ�k1�!�z���6"������7F�'�3'^Y���94����(��j�WW0�j�����_a���8+w���_�|�d�Tn����z�#��vt��]���������q�! �(��\����(�����e���_L�����u��>�OXQ���%9��B����w=i��R����~0�8���z���$�`_��RZ0���_|��V�}���J�a�+U�d+�T8v���@x ���������>�;�L�N����B!���s�'5��}��JGP��h>>���P���?�����U�:�U��)9�mY�gM9��&���?�r!	���j1�4�F��[�a4a�)����R�=����U��R��(��Y�{������M��v&�������v!��p+����Am������C�n@������&\,K_���o�<d&��ekW����,*���qn���a���5<X	�GXUm����e�w����e���91��e�C��W���tK��]�9fD<C���q�T����W�
���3s��e2���Z�~��;������3�L?��?����4s����5�0�l�������U�j��3����fz��-gN��7�E_�A���@�"~�@Op��D���	�_E�;��KP�R���~�Iy�f��?����S�s"\������lp+�_��%�B!���}rw�L�2��-�I���Z�H�*��2�Y/����9��p%9�&q��'Y��$
�L�m�u��������=�t��O�R����vwbK&-	�>�N���������@�����m;��
+V5��DB��k|���[��Z���s������g���8L���P�L�A��7/
H��G>�jr2&����SBI�������MYp�c���rA1'�����nt��,�Tg���wnK�SG�\��y��	��M��z!�J�1�5[v�ps�����&'��n��{�3v�s�6������H�~�|��)�������E)��o0�8��Pe�+��=�V|�����W���
�j�j����j7Qj@���}p!�Q��%�B!���}rPMH ��W��z<p�TP��a���&�@���L��%����!�+�%���_z��/K�^�	�.YSsLNO�^���<m�SRz��4Y����L3*(������
���m�dz#e���kP�xc�zY�u�c��cK>��9�X��X��oB����y���C{����x�����4�s>S��9���nL�TV>S�/e������L����xx&��k���\-8���,�`�V n�$v��@�r7�,��AG��Oi�:��D�����v������X���L�T�e�������u�!�u`I��fT���8[�C��B!������D�������7�-�rv�^le#	�U��
�*6� ��S����K��u���������7�����`�+��,�O����z�@W��	������H�G�nN�49�����
��H����$���2��V��z:�^��b+9�T,�G~>�>ei<K��ST��t�J�������C�V����<o2��
���F����p+��v������YV~��g��w9�]�F���X��7��o����c9��]_/(��n�y���?�x�>t��mZ=p��//���I�:��\�+�,��~�C��h�kP����>1s�X]�Am9�;��[��C���n��~8%��C)��5CcO�����y
xh����=�l6���>N	��D�!]�B!����=e[|����/`��$J��L� ��������h���QZ�}�'�y�[�}Y7�(U��y���"u�CT�e�P5(����Y_q��@���a���9x]�������}�_z���^4�����S�{UA)s%-~Qu����t%��q�����XEB������U�1>K�����pm���-K�����)��������*fUE�;��3F�����]*�F�7��pk���I`����3�y���o������N.�CBPO~���m=(S���7� 7��sC[�O6d�����H��p����g��Na��j�YN/YI�����'�U}����3�U��h��I���N����X�I#b_��6���I�~����~�v��y��g�yN/[O�sGD�!-j��f#~�Vm-E�����'p��|��u�}�ZM5^�������Qm�q7_���=�_���� X�z�h�r
?
����������N�l+N�����x����>��Cv2�&!��X:l%�>@���{��ZT���g���V8�
�
��A��| 2]���C�
f�����4�[c�_I�IJ����U��4�c�����)P��x�z@�=�������������
cOB���B!��~p�'5�bi����&QS�������
����^��q�
�}4����	�?�F�������
|�e�����
:�����������+�Li�VL�)���{��>�o�z�@L��,=�O��G���?��'�d�toBL�����|�Z�F�����,����K��%����I�����Y����:K����:Tz��.�TL����Y������1L
������T�p�,
�*���q![��$��
c�ZDN�N�V�w([����;�����������4x?=����sC�����qy$�o��_Jtz��M���U
���H���'�f^fx�v{���iK����W~ �����u����L�u����&�9�?��,q���L_�v�O��i1K��C��������l{�����Q���!M"�<C�9���`���H���*����m�5ES�Z�~�~�t6:�]Wl��ERe�sx�_TX|��d,�rP�
�jr�
����N-����&`���~���`�)�����/�:���l#�+���0z?����:�����N@�Y�q��e��	8��b�B!�w�l6g;jj��u����z�-;�o���n�`�&w��Q��7+5�X��NK����
���}�q�f�r�_w���K��Ry{�������c�1���^�+cc�of���^���(0�����w�Y�sAc"�X#��K����U�Q�
�g�412qfQ�"�B!��%7��s�}����gV�e~A����q������h�9L��
!�B!�B���>9�V���Yl�z��z��5��woR/LR�B!�B!���v'�T��+#sXK)C�%1���������l�N�f��.�:�?�RY�"1���s�������!�w��\B!�B!��}������:�zEGn��1�_$��B!�B�����B!�B!��?��z��������r\/L[:_�� �i��:!�$�P���������D{����w��E!�B!��l6g��+X�n111��B!�B!���X���W����s\��m-a��W�"�N���
)�0D8��%�0������0MhGU��������B!�B!Pk���
tB�h��zR/��e�~���4��7���	!�nV��|{�����2� ZW�����h}tFT�6���CB!�B�M&$B!�B!��?J��B!�B!�B�G���"e�g[�1,�b�cH	��������e����|�-��w���ie�%65��]Vtm{���p�q�����&�����}�GQ����$��)$�@Bo�z RE@T��
�kAE@����^;��r�	H��z��f����
lB�ME|?��<����������{f�p^�*����Ka�{Y��~��S��A�z�T
|�-�k'��������Vu&X[^��K��s|�$��O
@�h���%&v�z�������9>�=������7��&�s����fs��-����f�PJ]�s�k��[[��yM�������9�?���(h�^���!��t�'����^Jj'�^�/���a�3��k���x��ai��uM��!_}����'JP#�;�����a<������1&��>m�4T;���hh~#���'��7&���e���	�a��#��R��Z��s#����q&$��[5�`P t+�q�g@��6R��a)����B!D��}��.����7�F���=;���Lf��x������W���P�[�6���^�������a��T��J��������g�������{�>/���gr�&�M�������/�M�.��}6F���C9nCq�	�I��[����w��]�w{m�\����N9�9��jv��M��$��4��yX�x��+�E��=�kX�N'i�6?�%Y^c��T����>�o^8G��.�i����Y�-���-�hx����<���W���M����E1���Ym��������M�����vF��X�m�4T;|��}npr�o��^��Mc�}��Q�41
O��fx��6�=�K��!�w]����,K!�B���>9��DP�{=|��z�����;8�vM������6�7�.�-^������@NYk���t	+C���������u��4{���V�-�!�HT|=���
����������m�k�[�b4_����Q5 ��c'aK'"��jW�Z�*z��U���#-P�{ y
g�s��z7u�s���	��0t8�N)�Q#�;Fu�����������e&���8�(���k��^�d1u��$liw�=q�Q�M�n/��F�3!����-�O��7�fB!�����O�Ak����C��o���w�������~l����_���'�
���Q��bO9�8��\�~��T�?�Gt���}���Ent�{�����/< ��k��ld���d��1��P��>t���By����"��=������P���t��k�J��������L�:�7>hF��B��^���6�{��������T�����q�D��Q%�Cd���iw�����������46����F�.�K�<
��"	P�q�p�[I�n)K������Q���t/�������m?�f��z����Wa��4��!�{�A�t;�w1s����y�T&L�0�a��_�Y��?Y5y�7�u��*���DO��,z���)���
��e�����q�2cK��n�v~y���{��O��Q\�lnH���l�����������8��#��s��_���E_�����g�������=0�������UK����u{m�Y�w��M�����k5�=��w0|M*��u�^�����{��
�����V)K�yv�����;�:�U������@���W�mA�r����7����p�:h������N����}�I����{��E�N��
�gBBd���A��^Y*�{|��
f�B��A�/?.l��L�9�P���`/V������YL7��4H��I�*B�������:A!������vx�$���o�����=>��=60�� �]��[��y*,���@%#
�����y�?|cv-���$���� ��}Z�6�����h�a�0��vN��;�`RlH��P���<k�k/m��'0�F����d�yht���Z�0'�GF>|��,p��z�a��}��o���������B!�-��O�m�X��6r��q~�]�Y��JT�lo����E-~.cET���b���D�B|c�>\��
6����v��;-��W"���S)����z���s��������2�4�A�����t�?�!?������9���=���09�Ebp}YWmd����MJ��Y1�{�������)���o�����=g�`<���	_���3{4�'q]��d9��(����8vo`����]�����2�H\����L'G5�T��/`��������^��^����������n
��d��,����������Q�
~����"=m�l8�}��2��04����u�R��$�auh�v����H���1�4�A��pr!G�����_)sN��[���/}���a�Z����e-kr�0?]�5f�dK�^4ix��uW�i9���
K����U����ym���`��!_�lZ�!�G�(����|���s:=F��F��;���r����!~�.Z���>�Z�����M����&,���sV%��Y��w|o��G���82�>r?���K��\��e�A�Z�D��K�F����N�u�5�/&d;�P�u�j��
 gr�d����f�'�@�0x���Lnu:j�x�A
������O�p��`&
�o�a<s�@_�<?����0:��03
�P��/�f�	v�7^�����	@O����r�9�S�[�^
���/���5�a����LH��2����������	C\+v�`�)�]�T�8�����������t}
�����6g��3����G��@g3L7BN�T��`v&�7Bc�D�F�U��{
���?g,���2��������R,�i2�i���f�L}�B!����>9h[�=��}�|������{�]�t=�tF|+���^�2��c?��iPz�����V�Z�����y����!�t��`������&���n�k�[x�����5�^�P�h����Lx��M��T�/��%�����$\�;��Y�����@,:G;&�#%�;cfv���&�Y'���M�|��4�u�0�v���d�����4����f�,v�h3�1a�@XG���cya\�&�����S@��N��D�L�I~H��Ws��i�M�1��-�#Qw����H��@�L{������v]����L�
`�����st`�kSS������U�����G�jP�g��6���,Y��f9�����uK?���m����^��4n���>�.:M0M�����e,�����`":����64i�Lz:2�1y#)�]3���X�Np�)>�d'��J�� �ZO�eO�)	��N(2M��7��o���:-���~>���ur��=��}�vM�5������������KU�3���'�s��x*���e��7{(w��v���/9�m{{Y3!���z�8���~h��Q?W����}�(��+�����2v.�\3/�wV�C���x�|��h�[-���C>t
��L��i�T�+�le��w�����st�k��ey*-:f���;�]��������/����!����
>��������m�����.;����_�w8tt5���0P�<���>U���l�
�q��u�0���0'�-Ou@�@x��-���������`�I�����;z]�P D���8�t�K���S�'x�5>����&f�TO�B!����>O�m��{����a#��>�NZ������'
n��y�8�O���*�JH5bb5E�h�ds����b6�t���y�l*����&�|4�6&��6�]|�']� IDAT���Rt���+W�!*�5E�O@�[zVt�G9��N��w|�"ACP�*�N9��d�J����[�6jKaM�G����~�6�"S{��]����B�5���)�-.�:x�����m���w
���t������g9��N��*��I�Dt��������{��#�o.{��d�Y����|:�bj�S�
]����~���:cR��h7w$���!i���n��S�[Z���jh����sl�N��>��Y<�O�O��!h��;��b��q��N9�<V#<�b��4-un������HnD	
��B�ZBF�����Y�� �i��g#.�!�O�b�[,�J�N9��E%��$2�������85�/�����S����0�G��;�Q��L�������2(p��H����p������^���H��+T ���[�_��>n��zA
�le���������)x7�������������0"��a�����;�GLn�P��|V�@(�G�s��V�|m9�{�s��^^�����z��6(����K���
_W�-9�!��z5���&�s�����\8js������%C�_�>B!��o��O*����:hS�s�X��O��������k�����v!�����-^��O����O�R�80��-
��[����������e�)�+�����A��\m{��4E��CE��\�
��0��o����]�$/SE�yW!s,��t&J�AHp��R$b<��E�-��.�%ns���@�A�>�Lp
����a!?�����f#J������i|0��
U����_1oQ -�����0j���N9J�>����GB��Jb��+�m�r�l�CU�R�������������[�Y6
���oo�������%������+�X
'/C���k=�B1���
U��SD�����(a�b	s��jN�+��K���+���<2]�g�E�9m���_��;�o�0+F�����q�R����5:x:��@��g��\�VZR������$���X��_��h!��2=)�4�Zh�}�I�z�f������s�r`U�����tP
�
�������6�P���k|~�� S@��`a��r4��s��u�O��ta�j�iI2L���A������
)0�K��W��B!��[�����j���$���i���"�?*��]�D����S��ZQ1��'_@A�
���t�D�7bK8�9k��o�!qA&��=N���]	9g���������(�^VL>x������z{����'Z�R�A\���mQ��e������H1��2��}�1����|��*�t���%��((eM�X�H\�E������ W*���Z��)�"*R�U4Z����]6�����<�|����p��
>��1�+��'=G%����AK��cJ8Vu��x���z�7��N�L<NP�0R����{�y5M�:��8�
�8���������/�-��~�)5z;_�6X�
�>
|`��'c[>���C���������4�5�_����S�&��RVI�������l���0-:U������
<��UXQp>�@q&33�\�9���7����B��	�s�e9@��T�3��~��_��)�y��S�"ZW�G|/��v
�B!�[���������z���fZ6����m�����v/C�`2@Zy����D����/��w�S��g4Ru@]���`���"�"jNV�[��1��J�n����!�UU���������4�R����&����=���#����F>O�*�+lC�b;�0"b���v���}�����Jl$a��KW���<����a�f���
�LR0����{i[,)��mi�S���6���\���K)��j>���u���z0
�����^��i�!eo�5+R��U3�y�z�k=��#���K9T�=w/D������-��g�"]�d�[3��Zn��fW,[G��u�]����g;p���������8������-�vn����f������W\~	%8T�R��Y������e���>�P,p���YVyr�`�y�2���[od:�|#�W��b�P�����#��d���b�^x��@,�f�BRI���>��&���/�����jK�#�i�����V���b�u
XJ�������bbP�;G..���%�B!nu�}�A5��%bT�X���0�w����~Sg�����NN`����"e����@AJ�9@A6VUEMI#=I�S%� %N*��A��F�L�H�Xo��aT��B���������2~�F���&-'1Eu{���w��t����uO{j����x�����Q��Tm�c��������)$�_��������lO�����O��L��^:��
f�?kSt�����i�R������n����� ������3�.�;��$����6�0v�7���=�!k�������+��Uk�e��Z_6��BOi�m$c�&�4P��m���P=���c���8��#����8~�e�����*��nk���4�}h��-��/uo���l��1���*��;��}S���"�����/p����/H�j�=�	r���O6|r����`��Kql��=3
����wA�;�8��m	�p��B\�z����N��D,�]4&����� ���,_L��q�zk	��{�.g���>6�&�/5gk���ihO\��xd��#��;��2�a:��lI��;�y�L���P7�H��#l��O�g�=8��X6lb���	�\�p��,|�(��������hj�������|��C#+�9�hal�,�FU5�k&t�8G	��9����?eBk3���7�Jy����no� 
��#�in����J�b�U9E{�i����y���)�U��Q���p_*���a���c�Ao����a_>�����u���a�i8m��8���
��!����X�����cW�B�mp�}�h�_��h��6e�&��-�O�*�8
;���"4p2����f�]�	�P]s�a��36�"���43��LH4B
���V����B!����>9h�s-��^����&�c<�N�B����6����Y>�.��&fxO��`Ef�
���$�-t����I��,�u�=H��9*��G�m�X��gl�U�9�g�S-
a���Yr���3Q�o��;U�.m�g<���E�6�g~<��I��	�J
���c?3��*��
T��;��~b�~��h�h8�	�S�~�w�u��w�j?�S)�-�����+����{�c��X�*5���_�����<v�m��0v�7�����?����e��fAU���� �����5P��>4��wM%��G=����:����9��"��]��B��]����6��{�]���?�����-����5.{��>�-Zla��[I��3�m:�{�9>3���3"������/����dR����W����b�
��3����j�fl��a?��r�&Ns���Z�u�z��u�RT���X;�P�i�*��k8�,���_I��{����Ji�4��{����l�2�v�:���0�'_VN�����X�&�U���Fc��i������d�~��s*�U���Dl��q����e;$�T������+��#��Z�>���78^�v&�^���C�t��C�@�y���>}+��x��k�k4s��w#�*��<x!��4�7,
��L� ����3D�?<���@\8�T�q|��O2�i��9������b2N����Y*|���(#<���kb�a0�$����A�6���"��O����<�9���W���I�)���Y03�;�O����K���=�%��� Wu��<'��}�p:>h��?<�W��xZ�B!���)V����j�*���K��������b�+V���3��IC�+�7=�k�{�^syB���n��p��7��:�^p
�L�Z9����p���\������Y����gB!�B�@mp��3�@~�B!�B!��J��B!�B!�B�C���B!�Mf���L����3����a�B!�B �A!�B\oZ#�R|x_!�B!��@n+B!�B!�����,���/��p��b�W�Gq}�h�<������x�b��^[�&����F��7�
B!�BqM���^i�U�V��#�B!�B!��A�[����g����z/$Fo��<+1���V����f�c������Q�9bA7����6����]
!�B!��S�/j�J��/w]$��].���B}�+�c�L}�r)OQ6����j7��:�n=G���n�-�fWA!�B!��P�����$B!�B!�B�CIrP!�B!�B���z[���~"������#dYM6iL����e���eF��~��s����C JI���f�{�X?{g�9��\��C�!~l}|�-
k'i�������V�#X[^��!��,x��j�;��?�W��(-��P��t����T������������z>��y�*�j��1�_�W�=�jC:t�P�;t��+�qNAj:G�Y��j=h�&��c�J��X�c�l���6�q3�m��?���%�HVAQ�L���%v�H:���P��o76���_Mu�[wJP7���5�kC����������'=�c��.��y�?���;�j�`6C�&0�-���	�I��Y��jSh�W������a��N��0�Q	�������DH�@���'�B���������,K!�B���m�T�meA�wI�5��O�G��Ul��'
�w��4YG:G���]=�������	���k��}f8mj����'��'��Dy&o��Ft��'�Zy{g����n���ka�����b���O��f�U�����?}�mh�f6M���X��"��\�#���|����iZ���6��3�����������5���]C*A�9�f�a��/�e��w����+�F���'���(�0�5�������9���1��y���;����vX����g��5��V�d�`��,���/W|�-���;A?8s�'��m�&��>�q#�B!��6v'�$�3��i
��e�������v���4����]%�V,V�?�u���w&���������b�S�!D�7��������:v5	[�V�W�
xa�d�@�����)�P����������)L}q9	����V;
��
s�ir/7��>�5��E��R�������-�����?$;�xU$������u���b�k�h��On3t��Lv�~����Ghyz^-��x+�W�,�3����x�����`X{���4t!�B!nc��Uy���f�O)��y��Q�/|+��w��n�',c��T����9j=��u���\��1�7�5��g�0������3��X��qh�Vr������C_��/[w��������8�v�UjR��at^�h�2����������Y^UkR����@��������o���d#�we�	1z�#���|��OH�����=T�]m�*�6�F��H����jx��v��m�30��S�r6���K�
�
j��$�L�����y_���5K�CY�:�����50��E����^�s���l�v�o$�&N�O��|;�����e��h�c'������U�/b��$2Rm��Pw��t�����h�S��j�'�'�>ZI�g��w���{\��������6��fw�Gq���}��c�������Cx�+!�������[��N�o�o�����M�u��}m
��U�z{	����ILm�>�]�^�}b#��������V��������x��x|����P�A$(G��
��~\��c����w����Y�<���ba�j�#
L!��p�p������L��������{���l���B�*W��{�����5R������\��;+�|�S�!�B!<r�&�G8��!�Q��,�4�o�/��y=g��xl#k^����w�h��I�����l8�}�_`�S�����7������|t��z�^�*�����o�\AG��u�����7�����E���|�������1t���e�_��z/9�W��J�����������4�W�b�,k����9oy�j\��O����'��8�M���-�7�������d
9�7Q��6c���y�(������{��E����s�6�T�~���c����C�^���sY�������A}��l?��g��6�IFL�vhG�*�����Y��g��W���5���Ah����**����o��'�j~}�_�7}��~e�
��#������_);�9�.b��'��l���3���X��	�
����(���'2�^}t(-���K�-���G3��6N.�Jv�����T
$=�9�'
r�~����0��_�]����,���tP��TX�����C�X�^�~O@�b	8�)x>����~ph?8T���>�1Z��B|}/���SP�6���������'�����jC���[-zB��K�3������B!���}������C�\{*�\v�h�������1y	)��3�?��	�<�'����������T��yx�Ak�Z����E�yC��6�������6�}]t;b���X����,d�b
�g��]�|�u����#��n���h�>F�p��&g�c�^w������9���v��K�q��V�Z����K6�[N>y���f�F�CZS�������04��[m����4n����4qRm�r�(���;��5������Mt�����5d7���w��VG�3�E����{���=������!a���Z%"]�������AA���RX������v��:��!�[�k�v�LD�`���fI��w_�gr]�}W��2�Mh�JGg����-~b��}������^MY���+�L�uz�g~���&�Z�j���M�oF5/�v�}��<�%!ZS�Qv�Q�m}t;�g��]X�n[�������S:;�o�����Xj��������I�6��=��z�.�x�����a����j���E�n��Q���K�;����V1��mXv���,M��^��s����@KWQ����5�.�B!����~�Yf�Zl�u7�����0��G�[����V�/�|������Z�N9��d�J�#)^^IrO����l�q7��s��TT�
�m�0h����L�;���[�����]�j-�B]S4f"u�������� .�$N�S��@���)!u����$9�&������5A��3FP�\�>6W��JL4L�E�`
�_����B%.GMY���V��)�+5��g��m�����66�\�Q�D��F��gm������V������;N��Mg��]$���fs��m(q�E����I��y&}��I1����)�nP�{�5����{� ����G�7� ~��"�(�Qx+
������|�n�R��G�f�����s`y'H|w�E��lv���uF)��nDY)B�?]o����l�`�T��TLSO�
�d(u�)��u�K�W��$8�6�vh�.�x9w��_caE"�;�n��	0i	���e����.�B!���m�T��Q����bF�U!�����z��*@��"�b�����������C^�
�$5~�+�����R�Ps9����[J�����q0F���'�����[T�K�� |��g�Ev��Q���z�����^���I����57���~D��C�T�h�bw�k�n?�q��1sK�}Qz-zs(���/�!5��l0���-�`0��b��h�D��)��35�/���ea�|�z��l�����3�R�3
�������$�m�~{�k��|���8UWR�w�-��b"�U�\�����:�3��x���!y�f��[R��+b5�/�g��0Z�1��
�1��x�%�.�>��UV@m����`����^d��Id���jq>G�H{�����N��	�`E �
�A����G���}�8_yg�����M0��g�&J[�k�]!�B���69��T����&$a��N�!�Im�N�!����AG����������3��@� IDAT`�"b��q���J%=w�����D>�&��w�I>g����M��I��2�O�R
|0���[����>j>%�T�����C���o�Q��v���mK���
�/_�d�A�b��A5�1^r���R��]�D�����t�'���8�(K[T��W�R��h�Ot�>���g�%fL@�h��*VqX�e����6��w��z�fN�����'1�hE����u7����|�m�
q�'�����2J��n����"�4�������@�{�S����pI�S���}�����lx�!��XkW��;zW���!Gu��,��\C�B!�B���_��u��L���>s�� ^5�i�%eo�5#	�����O�d��ly%�.����M�NZ��%�E>Ws��8���`4����������5���V�~�.Z����<��;�����=���yI��[�����d��,��w�(v����&����M;H/l;j:I�P�� ��IrZ=��K8VVlVg��r9�-����`0!=��6]R�������~&)@�w�/�g�[���g^uH������qT8��=6�o_j�Y�bOI�[�����OvspKI����J�'��+i���$g�mo�����f�`��\���9��'��m��.��B-l9�����!�t�D��G!�3	�_B�r��p���$��%%�0�!=�b�
�8Y��#;N����<�W}<q���B!��}���ya8�>[Xx�{��z{~\����`�8�hBh�Rw����O.d�/;9�d=��|���p��zCLhmo2-#���$�;I����
����k7;;G���a�k���T�����V�P��qz�M_�������c�L�d}���e/:vw�c��,��&�������3z�����x�6�#P0���[:��N��)eM�i����?W�fz������\�����(�L����[~xy	��o%a�d~Y�E�/>��S�
���&c�B6&��qR�]������B���?r��{�Qv���e����-��KX���p����>�{���b��#]1�Z�����hl^����s������^)q5�I��8���`'�n�$M�8��8�_���tx�4t��j9����:?e���.�OZ�A��R�|�����tR�>����'����c�f�p��3I8���,���X��T��J#o��,|r*���A���g�)&v��^��������������P�+6��3p0R\�6}4��w��2���e�YR!hV	�o���������q����-�9;a�v�8�<}��Xn�����B!������T�����h�L���2������K��O�$�y)hl=�a?
 d�2~��#g���,B�����C������4	��������O����{�i+����]������C������h@������i���9u�gr���r7����VZS��_Od��A�������6�><��u-L��[W�K!��'�����br���NiM��e��\�������_��W_d���P<�]�C)xwy��?��a�4���:K��5�-��
*C����<F���Y1h�}���o��X�����i���9��1��[�B|s����?��C�9������'����K:U��7�C��V|��d������H���{-^`mj'���z,�[[�_�}�-����k�L��%�����3��3��uoEd�g����q4�]��;0��v&~`IQ(�E���8���|��if}���>��L�'"8��c���%���H\�W��^���k�W��`�
o���}X%���������������4�0y�vB�7���}M%�G�~��oxc��>)\O <�r��`���4����v��s��!�B!<�X��+vcY�j����^q�����]�����~�p��W�����^w�KyB�����'���nv5�u0����~�ov5n)�s9,�NB!�B�":���!��T���r�u�A!�B!�B!��IrP!�B!�B�(I
!�B!�B�%�A!�B!�B!��$9(�B!�B!�?��z���F*������F�[yB����T��U�I�&�fW���f�����B!���pd�i1�j��W�a��U����i�B!�B!�B�[�u�9�9y��Zu��f��pv�Z�B!�B!�����Lb>t�����/w�����W�ZM���ae	!�B!�Bq���U�ed@!�B!�B!��$9(�B!�B!�?�u������������~d��<�_+��0o9Dw���e\�
~���cyYF=�#���B!�B!����6N�������m�!���[������M��L��B�{`LX�#��������B!�B!��o��O��s�[���u���B���f0�+��ga�&h�	��]G!�B!�Bq����9hM�a������5M��=gA^����'6
�����W�..S�r
>|z�����	����vx���'���0~<��@�Zh�=�
��g���pG��������v���&
��A]%h
	;�����&�_���S`�z�8������!m
��~N/���y�l$l�\}_	!�B!�B�rw��t� +�h�A��u���W�������+�|
����APx�m�lxl!����
�6������0$�UN
������&8�'l���x��5������$<9	Z�T0�/�w��d���@d���5yg��
n?Ob/d;���Q�R ��*��C�i�t3����X�*�AcI%!�B!�B����O������N�{>������]0�wx�s�������X�s^�y�t1���wm���s�[��;��X�j���AG_����@���3/�G�������xR��\P��r_9���������.���/��	��~����.~��9<���C�����t��B!�B!�(W�r��)���h���n��������q0"�
��.�[�v����n��B�Z��!HU!T�?v;?i�[�|m9�|�I}.Gu�s�YJ]V���uU�mHIk���!h"�<
�"`�8=��<�B!�B!���n���>��^y@m8t�[�k�������>|
>v��:@��lWr0#�����>A>�����,?�{�7�4\���2�����A�eF:1��n!�t��6B�.P�V6Z!�B!���v�'=qn|�E�����+P����������.� ��h0Af������X�=��|+
O��T� �T
Pxk����XB���Q��4W��Zw��9�Ab-X�
C�����B!�B!���$5�H�I� j|�<��7�8�|�P_�� &
���bB]=5��.d'���b�/���@��3�X8�~
�l\J�\o����<���
4��?\#������u=����x{)�h�O�;� �6t
��2B!�B!�������(���������$���� .DTP����Z+��V�jmk�U�-����������nj�V��>T���TEET��}23��{h��L$��s]�d�9�9�33���u�}����r��C�xv��|�R�o4�'�/?���]GB~.>f�����pO���p��;���xs.,�?<:�{�#������`��`�BX���f�0|f$��Yxl
L*�����S��Y��0�f?
��{JzA��,�)��/>��������������H8�z��{�������y��W7��,I�$I������Us�;s6����7���~;�?�S����o�	W�N1{2�\�>
��b���H�������^p�����]7��$�	N���f����%p�7�G;�1'���Au���Kg��~g��	���]����g�����x��yp���_Q�0����XY��c!�:.�PI�$I�$m
�x<������������Ofr��6��;VT��jt�������9�	��&�u?����?|n)���%���$I�$I[��X%�u�	��;d������ o��"�#*�7�~�K����������i��$I�$I���[�E;�w�J�7����������v�JuH�$I�$)���:@��\����$I�$IR&�K�$I�$I����$I�$I��I�����<�`Ht��0�C��$I�$I�����j�}�x<�j�AEE���m�\�$I�$I����VNy�����E�,`Q�7:tLI�$I�$i[0�v/�D1�`3�����v=�xrq�m-��qA��%I�$I�$mk&���$�$I�$I�:)�AI�$I�$��2H��7��t�g����0��i�v��^���zU�NU��zX�>UnS�Z��!�qmv�����}��M@k?�d
>[	��\��9����6��K=�$I�$��3� l���Nn�J�M�Q����_���0�����y�~��0.�@����]P�������Z?��#I�$I�:�v=�D���0L�BpHJRpa^���[��O�P~V��{�BM��I�$I��l�+S��:���V��*8�V����C�J�]��W7m��N����q8�F��~�`B
��lU�%U0�n������up^�3�$Sp}
�\������|gh6c<T�j`N�W����He?V[��@(	�2��\=���}���^�pg��K��������	V�ez������k5��,�����u��H&������Ix�.�z��r����	�P���jm;pk6�O6�$�ph%|���
	���l�YK�$I������r��8?g@yV$��$T=��Qx��0��/��������[	��+"�x-3k���g����o��0�N���Q��nsw-�(	���zx8���H$��
���
��� $��Xm�4	���P�up^#����av\X]���t?�$�]
�����%avN�Q�����z80~�%�A�XX_Jg����m�9�0�Qu�5��V�������<P��`~m��~��'�E��8TF�$}��qX��Ylk�$I�$I���;���p.�Aa�����B00���JC0����Glx�~Qxm�������G�{� p���4��0#gw6��]����q�{��m,�D
N.���5�K_�r�l�RP�
�1����C�������I��W�06����"0�
~��������)�C����Q8���d
~�������������6���e�l�^&��nP����}�A��m#�~�������'RM�����G����I�$I��O��{[��46��
�L��h�6��u�u�v�~����Jm��uP�?
.�!X�
���%`�o$�zD`�6�����l����8����i�P�_@Y��4&`n
&D�~q�L!]<}��D����f+�G����R
������qX�����|�[���i�3
�)��M�������$I�$�S�����ypS,��;�
���� �t�\\w'�[]��b�g1|6��L��b�B�M�^M:����
Ai�Z��g3V.���`<Z��
/����T=I��`ef��4�����:������`���UAh��ozC�j�2�.��=�6��
���!��P����q�x*�8b���I�$I����{[1!8������z�Y{G��Y!��-	��	��I����0z�d\K�����:V��x7��r���`�u�6QO(�6;}dm*8	y��n���	Z�e���i!���b��{m
������`�O�=xk���Zx(/5�������$I�$I��,*
��y0�����S]��V�e���N�-����������%���[c�����P�mx�J�T*��;:��Ex��k�4���i�G`�����0"�o�p������������
O�^��P�6�#�Km|�r��V~��[����)���!��'�R�i^
)I�$I��d�������_��F�Q=,����	�N!x��M��$|�~/�}Bpw,�$��zX�c-�0������T�l�k�aeF���#�B��(�R�m��aV-���5�
���4���-�4���pnC*������.h�4�cq��No��t?�|���9:5q8�������F(�A�fs�y��`���8#��J��$�����46
$��8��������Z=���	�k�9��$I�$�S�����#���S���_�k����AH.(��	8�&T�u��)���@q�V����������������5�"�e���cu�i��������C)�a!��]��p[������Z�5���#�P���
pJ
|�.Xi85����l��l����{
`U��
~G�Oc���\>|#��9��i��=5��*[
/�mz�\�~����h�V
_�g��9��Z=������X��[�$I�$u:�x<��F���
���s�x��'3�x|����w���6���7������[78�$I�$I�����8��Xf����}���$�6�*	pu�����%I�$I�6f��V,ic������"
7�5#I�$I�:WvF�	�NC�'��"pUvXU�('�I[�I�$I��-0������I�$I�$ujn+�$I�$I�:�v[9��'��i]�w���$I�$I��`vbN�����Tk
***(//oS��$I�$I��]��rp��#����[2�E%S:tLI�$I�$i[0�������Y����L.��=����J�$I�$I��L����E9���$�$I�$IR'e8(I�$I�$uR�q8��;z�
�z�����/��6����Up�/��m�?�L�T���7n����+x����t>���'��%��a�8����"���`�Lh����������u^�f����k=�$I�$I��v��N��~
w__�<y��������LR�jc ��+������0����7}��	_�
<��m�n	Y��v%�~zY�}3��\�$I�$IR����l�����!(�%������nk���}�(C����`�8x����~���p��p�Q��r�"o�cBod;���#I�$I��lm�+7�=FAh,�O_��?�&L�~`����7 �������s�c��A��.��A�#�,�p<���������[r��
�8v��&��g��-�����`�|���p�P~'$�7j�s����/������Ka��a�����s[U������Ko���v���\?����a�?�n���.�5�;����I�$I�$}�lkK������*����'�U������a�]p���������x��
��.����,$R��@����xf|��|e8����H�[����p���+
�=3�����1���Er5�L��������n����w�i?�q�����������G�����_���s,2��������`��p���	��#�$��	�;&��>I�$I��O��?L5Bu
44���p���c����c0���� $:`$��,��18z��k+����������C���5J{��~�
	�������{����������V����G{���r� <|�J��'�>������,�
u�b�@�AC�O��ys�dSO�+?	N�����|��$��.I�$I��	l����a���!�/��-(A|�k���6����0q�x>4�aP	Swh{-����o���
���1�8��:���&�$��e�-=���p�-�{6y43h��*��1X���ou���8�<Z_�=���Q[�2I�$I������e���A,����^M!\������BPZ
�P���`����1��*����h?���Go�&�G�������@���
���U?��n�|���U��O �RM/6��/�-�z���1p�p�p�)�����gaT���%I�$I�>���p0����V�P!k�3.�`m�u��=j�.�9��J��mpB���H���������AUp�����+��&������9���<��U��HB~V)nSbp\9�������=� IDAT��o�Y���FI�$I��O�NvZq3�a�K�{%}�/�s�Y�G�!:�!dm��o��S�����U��j[�'����do77v���~�a(�
�W7���,��6�p/����f�u�x���,Hke�9�q���E=��]��Kn�{�Q}?���$I�$I�:�;u�3�W~�O=�.��]����?���S<�'xn!,|>N�S��0>~{,��5o�%?��-%�Q��z��9x�ux���v�8�p��xp%�}��O��`�������9>H0���o�������/����)������\���������W7[����s���z���������C�o����$I�$I�|:y�����`'|J��������B�90����p�k�[��p��P����^=����\��`F)\zz��z�C��<���x 8He�����a�s`��pp���/���'����Y3�/�p�O������Z���`�0�hh������2��1����Ok�d����+���>�)��$I�$I�B�x<��r���
���s�x��#�\������J�t�x�$����5������%I�$I�>�����dv�"*����}���$�FR��������p����$I�$�S2T'�k������3��q[� I�$I����pP�P��4�����$I�$I��:��$�$I�$IR�e8(I�$I�$uR����#O*R0��
�v���$I�$I��`v�&�
���P<O����������W&I�$I�$i��n+�T����n��u�XT��C��$I�$I����0$Z@��+���]O+���=���Tu�X�$I�$I��fr�n��y-�{<�D�$I�$I��%I�$I��Nj�g_C��A����o&7l�0FL���6��x?���3�x�l��W~����a����aY�����R���w��+�vV�RU������a�Tw�}#�m�Y~�z$I�$I��E��3�	��p��`H��Z�+�m�.T#�@�fyi�?��^h��e��<F6m�+�O�H>7����3 ���Z�\
��S&��=r�?�y%���0�=8�T���^>Fl�z$I�$I��Em�� ]`��0&�z��8xd\oD�w �!�i��l������S���p�#��)����ud1�����9p�50s��7	N=	�B-� I�$I��m����8�����r����v��v��jX���V��<
v�
��[�f�>�=q	��$�8	FN�=O��>�u����a��0�~����&�e�6�1��p�W`�Ca�ip��-����JX����Q(H����%�@��>�y�� w��*4�I.I�$I���mkK��A
���2c�`������x������[�!��@i,��?��	'�
�����K�
�����oxob\�
N�&\�=��������`������=�����`���/\v����'��oC�o��fcmJd ��k�5�g��9�z���^�N�#p�:���k��������$I�$IR'�����%��#6�6���!�������AG��M5Bu-D��������06�q��0�L��QA�6q'x�p��p��o�5����>��a�����5���0�O�BBp��px��}������9p����'��w|�v8�)(������JU��z�����
�Qg��3���=��-��Cp�W:��^�$I�$)+�L�
�_;f$K�o�}{[�(��h�E������4��p�MAX��3n|�����;�A��^K�b��v����jhLB���	��f��|�/������_����c���7����#����{�<x%�M��uG`����7aE���^�$I�$	:C8H>�6f��t���p�����`h��0,YU@IQ�
!(-�x
��a@.��6]�j�����}����[/�&��o��D���������g}
n���zv��-5��u�����e�7	�a�|�$I�$IR'�	��mL�;��{pZqs�B(*�3.�`m5��A�F7��H�������������k!�d�2��.��S�����Rs/�
yQ8�������0�U��$I�$I�������T�~�m6m6%2FE��9M��V����Q;�!��!d]��o%���^��^�k��&��M�+U
�kv�-��2(�[�gK�=������s�g��i9��$I�$I��:�����j����J�^����,���(�=�{~?FC��00sl6mZ��L�3���By/x�^x��dJ�Qn�7�X�?������g>�F����'�t2|W�|�S���W�C����oL
eIx�1��0����k��-5�po8��p���w
�#�W��90o���N���$I�$IZ������f�����CC.;)��� 4��|�\�|W�u!|��u~���i���u�n<�8�x$�_G�h��
�������3����g����������0�P8���8����65��p��P�2����5��:8g\<6�z�����
w�o��t������GOJ�$I�$mB�x<�Z���
���s�xJ�O���������*�����$I�$I��m����V�7�k^�b��Y���WJ�$I�$I����$I�$I��IJ�$I�$I����$I�$I��IJ�$I�$I�T��:������{rZ��S�$I�$I��^dq�w���P<O����������W&I�$I�$i��n+C&�W��$I�$I�2���!��T�6.��|��$I�$I���\�=�{%I�$I��N�pP�$I�$I������K������������~�����'�C�������O^��'j�������-��[{m�&�&��@����%p� 8����@�$I�$Ij7�����}!��E������q ���X�8�a	��m�`�~1�p��V�`�`��j���K�;� 8xKOJ�$I�$I�2:>���I�� ��P��>�W��vX=����W>��.!�m����p`�������7���0�w��P�$I�$I��t|8����@%|�"@|n]K���8�/�0d���v��	����CQ\���&.��t��s�����,
���1��^��5)X�
���>Y����+ 	DRp�+��>po�`�$��/���p[o����������8l0|��a��$I�$I����.�"P�N���|w%�0���3K���x�l�nc5\����ey�h
$SP��k��7`��������3�x�
zu��B��_����1p�'����*`XA:������0��xs)|m�Y
�M%I�$I��eu|8�JAM�)x{�d%t�c�A�v�
�} \�Cp���"X�*��1�o�����p��pl~�zH����E ��/��A���k9d(��z|	�	���#z�6�x2�W}�[+�����@�.�	]���`�e��*����$I�$I��Vt|8��#�Q�����'C�h��7�ptIS���B���p{m�&��e��~�����I�;lo���Rp�\�+���+������&a�!��tAe#�����$I�$I����i����~Ai>�k
��	�J2����k������`8
em�#����AE>|{'�5/x6��s��T�����apb�p��.Y�����6KCA�$I�$I���m���c���`�os�����)X��X6Z$�au_3���D�<>W���V����gW��7�����}���V�p(X��)�k)I�$I�$m9m���G�v���M��Rqx�v.jC�
B���d
�@IF�5�������aM<�U|�����p�r�M_+���xS@���w%I�$I���l[�`(3z�����s�����LN��{��<����b
,���t/V{��OK��$T����AeK��_������$Zh�1�S{��������%�t%��*����8��H�$I�$I[��L
W��g�Yo��)�l���{7�������9p���u�[�<��NP����.����M,O<rL���������U�=�/|&	w}t���b\�_�6V������/I�$I���#�������
���s�x��6%I�$I�$){��.������v����>��I�$I�$I����$I�$I��IJ�$I�$I����$I�$I��IJ�$I�$I�T��:������Z�$I�$IR���&�v���vg�8����$I�$I��af����n�`��#��kI�$I�$I���P�m}��$I�$I��IJ�$I�$I����$I�$I��InI
�`�#�h�}�OT���Q_Y�>�H�$I�$�Sh�I:�P�w��P��)�[��$\�T��!I�$I��N�ppK����z��!��HB����$I�$I�v������nx��AiW8q8�G��9�N}z�
?\K��E��7���#�Pls��WW
?^+R0��6
�)���<8n[��P������n�&K����B ?.�C#M]�}NZ��������;��j8bw�A_'��F?�m�eD��]���!�Bim�����~�:��*cp�NP3>�	~5�)����?��w��5&�;�����������_��pO_��Bx������P����	����wh�'�
�7>�^���$I�$I���u�3_y��&t?��T
�|����u�Y#����p]p������z�,�H��w��?��)��������� �C�o�
3��#�W���aPT�RMm����Gw��M��X
;��/v�;�@��noxh,������a0<y0�4������F6�O6f��+?��w�G��E�D<�>r���.}�
�?f
������0{)��h��R��+�K�+I�$I�$�����:���yg�axz��PU	�]_\�q|�#��u�q\��8v����������0%��O/�|*�H�����L��=��fm"Q�����J�DK�� Q�W�g���y��9A88(���|�/�c�����������������T=�~)�9
��^�96
�=������d=?����!�M��~<�j����<�F�����GI�$I���X��lXsR0�OF�����5�2�tm��0b%��*�g���O
^Z	��`���uDr��v�����E��:�Im�����P��(��P�#P����v�J�yXv)��+�2�q���7#QR�}�%e�k�?�\����-������#H�+�q8�o���%I�$I��r��!8e����2��R�*�*`���"�ph<���m�gm#��}��>�N������<8td��uV��gk���fns��p�a�P�)��E������d#T��`�F6�����	�A�&���Q;����a�R������^�$I�$I���p�(�0�3l��+����K���0�+��:L�B9����(�m�F>���1*������	���1���v�*�Uq�{j(�r�c.�skBQ(�3.&�*�a���3&��zZ[�8a�����9�������H�$I�$�e��8�v��u0��e�
-�����p�<8~�'��.{7���'{�����_��H�q[0@a!?��`Y}��i��U�|}�	xi
(���F�����*�~��-��C����1���k�,����@3Q�d��R��W���?�������<J�$I�$�U�r0��:��y#`j	����U�f\?")��5x�~7
�0s$?��	gt���3Ca�p���t8���+��.p��,c��7^.����W�]���[e��������lU-|V�������Z�}������6����~�����������z��h���f��������
Q�����5���5
��e<2����b���R�P=�s?�?���l�LII�$I�$e���A�=G�m�p��pn-��`�����AX��=�n�=F�����������	�sx��@J]7ny~������epz��K�`�Rxt	\���`P7�lo��G���Td���b6\�������3=�Z��B8u,�\�q�#F�_�k^�:����{����|>�8hW��u��u�'
G����Gm�gT�O���p��0iE�����T=�������v�$I�$IR����x��l+**(//���7�lsQ�S~Po�w��
�9H��'a�N��![��7����m��m���$I�$I�jR#��m���>�5��ve�q�`��`P�$I�$��0]��G��p����\=�h[�$I�$����Jb-\�.����:Z�.UT�7����Ds���cq�1}<L�z�K�$I�$mo:g8)�������::��%I�$I���K�$I�$I�T����sF{u-I�$I�$ih�ppf���kI�$I�$I[@������k��%I�$I�$m���3�YrZVm}��$I�$I��IJ�$I�$I����$I�$I��Iu`8��+_�A�C��1/�yK`Y�����o��g���-�����r�RH������`�spO���F<%7�V�$I�$I�N�H�I%ep}_��`�*��=X��Al����=K`J7�7ow��xg,����k`n�mOCQ]�h��$I�$I�Nt|8��u���=��.�^��:��mJ�+�]���<xz��
^X���be�H���Q�$I�$I������B��<	D�$��.���O@��p��B1�/;L��i����|��\5��>���>�|��@N
�J���8��6���yp� x�-(�n��T�#o��Sp��}x��
�����< �-�k���(���sJ36no�fV�M-����	���u0u����~�!�\�S0�+�9x�����0������pd����ex�U����8r0\�>�,%I�$I���m�ppY=�"P�N���.X	'
�������yP<�J�V�>�W�iC`j>���T��tAqw��4���a�H�Rapoq����������a��z1<����LT��
p�p�<��Dz��K����p���+,Y����=��.������p�JX��
��1�:��E���\�z�a��p�<(G�?��;�S=�~���?�7�������0���"��>o:(I�$I��t|8�JAu"x��[������'�
+��Zc�����&����+��~���U)�o��B�R8<c�P�G �V���`@��u$j���P���3Xu�k
X�r��F��npB��a��/�7,�Q���O����7��C�k��y��2��]��z5{�����o	�}���{����7�e��lA^\�3x&a����2x�
>����$I�$I��������V~��vy�Z��p�(50?	�K�*�`�� \kL_^�50��w
T�����jX
���ZY	��D�-���7�^�^I�!=2�����W��k�`j!��*8H��7T[���^�������_au����l
,J��j��i�v:<Z�$I�$I���_9X�n�y���{C���d���H�
!(�@<<C03~��_.��������]���6��]3�
E�x�`8-��Q�
)��?p]��T
RE���>��j>h�������>������d������uX���3���5��[�$I�$I�B�����U�V�\8�@e"�b
�&����p/��U��}���w`l78���}-�	f�.�A�VE�! ����(
ya8o7����A��j��~��"��q����Ww�c���u��$I�$I��5��&R���|e��T<��;���(�(N�����fo������pE�S
��l�F�v��c��_cB��!x������C�VknE2���D�:x�pP�$I�$I����g
����p�������S��a�I��(���8�z��_�[Q�n����<�1�/�ia�������.pR7��]�%{���K ��	-���}��� oR��W	���M��O9��[�
�Bp�R�4
���w��Y�+��hh�����$�0���~H�$\%�P IDATI�$I�:�m+8h\���{��.���kj3��(8�cm
w�+F����z#��ap�{0c��SG������v����_.�[���AP�V�<�\�w��������-�;���%����}����U;�w���@i7�^o�o���^��g�&�����sF6B"I�$I��N-��[=���������;~�6��4V�a�����srX�'I�$I�$m#f�������j����HKV�_a�b������8�`P�$I�$I���F�g��/��6���m�`��.L�$I�$Ij�;��~�ckW!I�$I�$m��7�$I�$I��=2�$I�$I�:�v�V<�����Z�$I�$I��n�`��%K�$I�$I�:�-�k@{u-I�$I�$if
���������$I�$I�:)�AI�$I�$��2�$I�$I�:�v{��F�	8�C��
^�C�3
S��] ���� ����p������CQw�Y�z8v�B@,C�������$I�$I�$�#���F����L�;up�j��7�t:�
:��Bm^W����0���$I�$I�x��`BA��n�XV���s��F5(��`������X	��
��C�$I�$I�@[?��	 ����k��jx����_|���m��7����D=�J��t��6�M�����Ep]	���Z�U���D�s�0#?�4���!�VS��ZX�)%����v�d�^��AC����51���`���X����M�_�*�����6��G�$I�$I�B������ ���5��$�/h�dqz��b�-o��M+�Ko�I����W�"pj��u�b�����8|oT��3���*��*��+�����p�*�����h����ep{)��.Y�����z^
w���n02X<[qR+�C*	k�A�����\=�$I�$IR:>|a
��	�
��8��iU���p`F��y�p9<�S���V�3��=`�t�66�f����1x�����J���	��
�w�Y]��D>T�?{�E��q�=��M����W)
�QA@@�"`GTAAA�vQE� ��H�Q�*����-��c7$�����y��s���{?sw�'��w��H�.���c�����P1*�$�:�'�s;��4h	}=�Q	�u��{wx��t,��X;�
��^��8X3�xf�O�w�a�Fz��T'|K�����<�e��np�9��t�����������)'a0)������w�=
u���N1�c%l��%1�����i�t�g�v���!�&�;��/C��b4T���
^�=�PDDDDDDDD|���`���iu�!�	c�g Tp�'`����V����	8��PB���Z�
�s��hTM�w�^h�s�R��n��c�V��L0m�Df8�w��-��o��%�4,z�zZG@W?8�o'��xx;"s���.V�����������
~C�260Sa�	e�a��F@���L�s
�0<�`�7��X@h��g� 4	���9���Z�f@�"�$�D��>��
)S�L�3MH%[@h@��33(a����m����7{�������V���L�L;O����4��-1�k��4��}��l/���������_o[v;�v�=�����S������6��pdKw��KL��M
�2�$b@�	���p9a����������H���p0�������4LI���P�?�1��D8aB�����l�hk�@c&��y)�>
���I�	��8`R"8����S09�H���A�N��J���n���	���.x7������R�ogu��h
,qB�>���>�!""""""""�C���xk"<���p](�+����NC�D��	;��-�=�~d�XaL|��A�	��pg���N�
�a	�i��A�p�d�w�`��,P���\$'�i�H����G!�-C�������ZI�y2�
uC����7��)��y�(""""""""����q�u�K�,�m��9oxe��.JDDDDDDDDD.��r#]���-�g���������H�P8(""""""""RH))����������R
EDDDDDDDD
)��jx\�y�������������<}�.YDDDDDDDDD
F��������i��q�3�X#���3EDDDDDDDD
)��"""""""""���A�B*��9x�)8��,V(Z������.���<�>{*�w�����aB-�!3�Xo���	u���P��y���VC��aX����}���������'���5���*�v��M��G�OU��R�������m�~;K���������'hQ#��|�KDDDDDDDD�8�F��k���	��/��U
����:���������u�g+H3
�4)�
8�3�f�L���k`�j���vA����3�^�(fH;����;��������K��w���	�f0�-����o��-�!����T�>���&�_��]��������2&�������m����+K��x8	�>;����:q
��1�y_o��,�k(�����Y�<�����7�_�O�Mw�����74�o����
����F`���q��Z�y��
�h�q��'Z��������\��?t9!9
p��?aq4�����=�HMx�D����0y=�C=m������&w����k��n-un(�v�x���2�A���p�2h�^)�6���@�p��y���a���m�})��U�.a����f�!���f/�<[���zk�7����mP?�������yz���{������<�%B���T��.���r`��P�.X8v��G>����'�����������H���p��y�d���
?h���.3��6]�M��������;����c�_x�>�)�s�aU��>7ts��gf���0�3Dx�A�i��
��&���DeH:s~��f���*<ZB�����r�ct���������sU�����,E����w0p���5���p]�w,�P"
�i`B��dT���q|2����5���\���.�WV���@������@��`��fEDDDDDDD$o�8X�5����d�v��0�<W���������x�g����%���a�.�
M��n��-t'��Y��
�n�"Y������.\'�(X���0s?������*]��������a����\�Y*g���M�u]X�~��V�������-3�.9>Y��+
7F����*[B3n�
�K�G!��cEDDDDDDD�����`X���'HkP�N��E��&TJ���K���>P#�n�9�e<����)r���qp�*T����u�d>'09nx�e����
f)H���g���}HbJ�'��|���eZz~R��#o�[+����}f����%��!����:��C�����������\����|10��}n(��$�����h�	i�J�r��	�������Zc`�]	}��j������=��~Z��}���,����zjHqpfw3R����dP����' ��,���/�s����61���b28�����|�y���=s����������\�
~?�C'���cn'8������w�G�,P�"$n���g���\f��7��R��g���y�^j[aW<�/
�����<��%�"��H���C�;K-f*�V+.�A!��5�z�Nup��''.�W�6�V\�`���S�����`:���J�x��������H��������<�w���B�=A��,������ik�?�.��lf��|<7�Ua�X���'��B�;�����_���`������9`�Z�G<l����K-}�L�wT��~�6wCM�o��2��<��C���<����?a�	�����CO{P1~Y
-�=;�EB����������*��
�CCh_���s�xF/�{������Tx��6#���8��rxp9X�7��[A@8<��~
~����-t�
vgi�	/>3��s��J��~�^x.��$�jw����%�~G�
3V���`�J�K���4�Ko8�9�xR���p��,�DB�&�����o����%���0�r���0�vx�;��3S��PY	,>���.�@�[�����d��w�wx�%�U��P��\�(���*��3���#�S���d���m���7�v�E���/��]����W�"u�Bo\���.���s����������R
EDDDDDDDD
������X���]���������\&�)����������Ry��x\��y�������������<}�.YDDDDDDDDD
F�����zy�����������\���a����z����������H!�pPDDDDDDDD��R8(""""""""RH�o8h�����o(��n�{�&w����>�	�w���.DDDDDDDDD�wy�!��Lxo�I���N���`MQ��I�"""""""""�)��Ag*���*��P��p����["""""""""�����8�e{��#�kV�������
^O��+���2�a�)���o�Z[�+8e��E�.�� ���������y��wIu���0sr�	������F��&��+���������������?T��U��p�8��@�(x�"<o��w��=�����.�aI�
�@�0�����l��P%*������c�y	��<tF�<;`���u'!��Y>�������YDDDDDDDD�"�oY���/���OC�?���@�lB�^95���E�	)��I�_�{�������.���5��u���!-��9S�'t
k.�u)��=�J��hO${c l����m1`�pNF�
OG@�0�����0�D�>ERDDDDDDDD�n��H����:L/	m�����m���zKK��&t
���0'��l������}�	�����&w�i�o�v����8Sa�	��3G�����9�>���B�e��N�I���+ODDDDDDDD
���gd�nE=?)�p��rz��$'��0a+���:3�M(�����D^����P�����`Q<�����s��K1]��[�4 �
�n��,>���MZ �c-��s}�e�(""""""""�N�.B
�.��D$�V��Xeh�mR�a����m\h����������A���;���.��Bp:��!&����>�������FK��X!�2��B)���.8�}K]v�C���P��mN����T�g�������P<,8
�l�>0��\������&en�b:aU*������aw"�x�����\ ��b�""""""""���3���_(	m�!��?Nyv��W����
F�;��1��"��'	����19��R8T>c�C�H��e6�%��2�S�g��3�����H����@,=�,05���rNF����!x(���\<Y��@EDDDDDDD�*����`H�2�Nz6�(��GB2�������'��gIm�`���e8'����^I������������7
�k��.�[���0�
%�����5�����P7���`�`Hy����EDDDDDDDD��p�;a��%�m�6�
�w�E�����f�^����^�""""""""r<��A�|:W����������H!�pPDDDDDDDD���W&�,�"DDDDDDDD�?B3EDDDDDDDD
)��"""""""""�T�-+<,���\�g����%���������H���p���4���=�����t��9(""""""""RH))����������R����:����S�W�a�8G�<��s�o�y�~N�G=�n��o�C���7�U�O9o3�$��
�/}���������\5��`XL�����0X������.�������h�2�W=+�9G��c�`�q���V���U���������\	�l����C�H�7GCH:�;�KCC#���O��)�<����X�	kc/�=[|��5��������H���p0�Z!@<uV�
���'��J���
�#�d��s�w�� �
����	$��; �{��
0��>5`t8��z���&,L��*��|�
���q��y�����#�>�L(��C�\��8��-�w��A�g��\�w��"0y?�K��U���a���`qt��%�pSX�%����v���:-0�!t�Z�	��������i+t(������""""""""�O
><�X!��H-�
O������V���!�Z�h���� �:}��M��
�� ��HB����L��[���po���[f��(v
<�w@�k���0���r��D����� ��-'`�f�:�r=��������
�N���X��=n�$��>a�v����G���p�
��`�
&g����*Q~���S�y��?�G`wE�W��vA�p��tPDDDDDDD�J����iB��L�SNBd4\k�l���	�SF���k������}I���I`
���B @8����a��Vp�<����P���Zl��#��0+��@]��/0���*��v�0��~��N��c�Q�;�3��jx����	��$��(�.���vB�Zp�������[���P}/�aB�H(���}�/���t[�Y��a��E<�$,R���[�E.�������c��X��R�0�<��d�����2��6h3���g�j�@p�q��k�
���y^������G0`�@��M�����>�>�����p����%��IK���04:��b@�P��'�bY����	<���
Z��S�Dy�$���/���2A�Q��3[2�	�!�+S���aQ0�$������ ���$ ���B��py��g����&����A�r�|1��=_��*�K�cn�t��������`5a�?p��l&7�IvB�	S����7M0�=K��eI�,~p�=BZ������z_����f����������\�
`�b��,��.c�^�+�A\`����rV�\����_��wC���"��r�?9����5�{���aw�\�'�lVn����a��������W����'N�������,�{� �j�?�3g���=��?���;KAy��#���'�L����mzv�
��qr��H{�[��5`g:T�,U�����0�r]�}���������N��V��a�����0�
��������E2��/v��hEX}v������Z�p������6 ������B����KC@*��������z,�pq��ipK�;`k<l
�)%!������}��yv?v8<��M���L����DDDDDDDDD�xW��A���X�m�MS:�3��&�������V���g�����3+�E��
��/���{-;���'���~;D����2������0��:l�'��J'���O���r���p�Zh������u�]������������H�0�Ew�X�d	m���y���^vQ"""""""""ry�Edt�=>�{���|�pPDDDDDDDD��R8(""""""""RH))����������R~y�����y�������������<}�.YDDDDDDDDD
F�����"y�����������\���#]f�O����"""""""""���A�BJ����������H!uu���t�9��]����������U��1��B
���O��V�/l6x7����*�_8�-�9�5��
��3�q�-!���3�qg��
�\p(�=������B�$p06Zg���)��Z�an:��*F��-��ZDDDDDDDD������].�	��V�4��!;,J�C�s�9!����P�l��	%��� IDAT�@1CQ�	s�/��J�}6x+����$��}�DDDDDDDDD
��]V��������\��j03	������,�����`�Z�=��7�a��Mx>6��<�0*���:'t���-���������\-����.,��6�7!��������g'�0��L��79��X����~���]���������f�!IF0g���
�&�+�0,�Z�
�'.���w������������\a�;���������=h��,��DDDDDDDDD���wC�K1Mp�Y�Jq��
EDDDDDDDDr��5s���R�Q ��aZ2$d{@`�R�����876<���]b���p�b��C��d����A�!nI�}'��R��2�pJL�vX
P����������U&����A�8��?,����
���<��&��]���/FqIEf;`�h�)$��g���������H�Q8(""""""""RH))����������R
EDDDDDDDD
�<��x\��y�������������<G��WM���������H.��b�BJ����������H!�pPDDDDDDDD��R8(""""""""RH�c8���/3���T.F`P�i��IK���Q;N6�;�N��Q2�{`n��?�������?2���T�	!(��[����p������aX��Y��=��Rr��s_���)���[s6j"���Y8�������N;��V�����|�MDDDDDDD�S��V|�a�}�E���1rM�qV��Ou�B��U<�����8��6������+R<(�����];���w&6	�<�5Cn��g~�>�}D%�u�������u� �y[�]�0�?��0w*����)��!)�
S[�'!R�\��~
�7Z�����N3lD��A��!\����_8h)N���@�����zu*���}���J�j�������~�2�g9��{u�v��O~��&7a#���3�Tf��9���L���[?��=�	C�3�,1uh��E��N����N�|��)�hi����
E���Zzt"""""""�g�qYq���FDuj��p��I�R��e�":�R�<�_�J>�������U&�-Z)V�4l����N'��-�<K:���$��#��p+*ES�N����Y+]�e��^CtP���s���p��yF���<���JEB������/�L\�K7���9V_��L����t�����!�h��'|�h#�GQ{�<����5��N2�?z�6��D��-<k���M��N�o���sx�MubB	+Q�s�v�������-	g
�J�_@�g���;d����G�T�4��AD�k�m��c����&qNg@�JDR�&�����,�~ua�����8n�S���0�����~���	�'(�45Z��$gk�#���g�9�N{#��m��#�KD��o/jF�R��������
��
#Yr�s]��;h��7��l�!%�w�$V���������1;7M�O���)g50{�ql�(����k��K��XV�[�#"""""""�@7$1�6���V�&�.*���IjR"��ne��gx������16���/6�R�A���^�4�I�?��eo���G)��#��p�`���x/m(��:��_�M����~s���)&�z�v���h?^��>z�:�}�=�f�c��m{�wb������/ysPiV=�������_�?L��V&������������s�K?���k���{x1a�M�H�G�2g����}i������p�lZ?���x�v���������/�z&�J���Y�n=?����n�T�G��$.��������|y�={���4X�_��M�>#��h>�v�����~d�7�s��=�{�L�bs����������5�W���d���������t��]f����t�C�1������Imd��@��?�1��g������V4�?x�F{������m����9Eyn�~���.m�����?��	X�2p�vv����~%�o�,�v�f����X�0���6��������7�or��6>"""""""R��y��~���	��5M�����]9����M��0��jf�Ov�����=nV�2{|��q����h&$$�	�)��m��k��zs��g�����7K��d����J�����0�a]��O�����?FV3��?m�q���:`�ll�0���Q��07O���4�\�~��M3���_���33���������7'l�j~���Zs���p�����i�FPK��}.���5���r�C��M3u�ywtqs��i>��S;�#���M����3�t2�nb�7{������y=�@#�l5m�y�;ry��av����������6��b�p�`Ne�����[i&e=�tx�����R#�~�������iny�z����}�s,u~o3�Z�|`i��s6O���8�\�3������K�C�]���������{g�?n���������7��i�-26�}�h��5��5��/�m:�'��:�5F�5�i&}����2/J>�v��f���)���h����2f@���������n0K��<���)X4s����G�?5�����]%s^��X7�\���?fBW_���<����S�+Q=���PB�na�������b���X���f=B�������9�&G�*5��33�l��_�]��gB������ko��*g&b�Q�ic�\��c����1oTw�T)AdH����q,�'�s:k=�c|�`����It,~�BX�#$�k(a�X�		J&!15_��f�ntP�ys�e�i���517�eS�-�m�����y��Eo�o[?�Y�qH�����rC��T����pl\�����|GC���a���Hc���vKn,���Z��E��m`��,���P�z��WEb���I���c)V�������}��m�R��W�{������!4�JhX(�LH0$%&e����A����u�S��������G�����������	S6L������g��Q������V�f�l���~��z��4f6��`��!�p{2������y��y�-g�A�Y�FM���y+n8������O�1���=�
&0��^kP�$p:��L�%6����j@��'����w�s��	�i~x�-��>N�Q��������Of�(��tr�����������'������@�X00�X,���j���	�N����,;�Z��HO >5{Y��D_�aD��og�~�W��$��)�&6����/�KE(Z����L|�#,��,��%,�0�g�Y�
{����nwf��I���=d���z�(J7���9
�,�ck����+���$8(�h#(� R����/������������H��������`��c���������h�R�:�cp~���.(S�u���v���S#���7������hS�UkP���-;P���h��X�l(oJ�w�B10�#���i1z%�:��}�@L+8V���#\����twEo3�lr%��l:�*<��WL��N��p�+�X6�n���xF�5o��!K(����>������%���Bf�`���]#�0�����m!��_�K�<k�DD�	��pA��tf��y(�x�������'�����g��>�}��ql[<���a�S-h3�N"�����g�:�9{&aw�qn���w�8�)����\)H�:s��_�������/������H��\7������wg�e�NZ��S�����P�$�-�S���4������9�XR����ATd�����rV��4�����U�Z�D���ll�|��U�Q�Z�������4R�
�#�3g�%�����	�0�#m��?��Qu�����|y�/���}�W�ul�Z����cc�/�`�i@�n�B`s�t/������w&�zw$:�Y��Ns�����y���
��	�O��`�/�8�1�.v.[�>����~���_U�=�����r��{��XN�fP[��qy;x;6�l�)�w�$v�r���k�=�v�RSH��2��GDDDDDDD�]���>���3qse�R����c��-KL=�����,���-��>�d�!<��Bf������#��m4�U��Q�|6�Y�����T��b�+���Cn�����Q7�4k�[I���Y���7��w3������?�T��������0��J��D�lC��w��i����~e�k�P�������x�k]������,�P��s�S�~=77�g����K��i�����q~\8��Q��<=�	���L�eOS7�&�Y.]su��(]����.���p(��������S0�~��
9���4��'������6�"�sax���4{�Nn5��`���������
s�qg��J���~���������x~�_�����|���i2=��I�;ZS��h\��g�g'�8�F�z���Ns��b���m\S��&|y��f��O�����4��|j�vo��|����R�jXg|��Z0�n��*���8�p�d*�y��TW�Q������#�Xi�ro|DDDDDDD�`�_8�������L<��!=���-{������3a	�9��iFQ�4�rv�~5�xG5���}^��q����������;"ZJt���������d�Q�~{�}5�A�-dLGt�y��:��a�\���~�/�?I��'�[��y��z��~���r�|�Sf>\�����7�������3x��=$�c�P�)���3��(E��}��A�qG�I�GV�e�gy����z���u>�I�7��}�;����[^|��}b��u�{7�G^x��	,����~�+=K�<��j��M��9���.k]��Z�����1�z},}���S�f=�b�7�����{�%��c��p�I��V��{>��	m�A���uh������cDW������
������?�^��E�wC����y�)�^��[�o���������p,�*������:+�5(z�x&/���-������X��Cm������#+83Awu�|X�3�������k�#"""""""�p8���d���m�_�x�3�{��y�5�>M�+z�b:�������l;+�����8���G�����M�<���J�{��M�;�=���\��[�:V���/���Y�����e#_����*Cy���A���+3z����=G
�
������!�
^JH�[������f&""""""""r�+tY�����������5=!ODDDDDDDD��R8(""""""""RH))����������R
EDDDDDDDD
)?_NZ�hQ^�!"""""""""��p8fA!"""""""""�O��EDDDDDDDD
)��"""""""""���A�BJ����������H!�pPDDDDDDDD��R8(""""""""RH))������0�Mz�{�
�s���g���_�7��\���=�<���_�7q�HY�+����I]���_yc@/&�p�����<����8c�����6��?���Os��Q�]>���b���;`��'�������6DDDDD
��h8hr���2�{�'S����;r�V&H��f�O���!_�R296�n�)q#/o������%�����I��p�5�v��S��t}wy�w���~�f%����!}7�X��X�U{~&�w�d��[9�_T?�I�:O�"5��v�g|�T�5'�0'7���h�wl<�>������?`����	w|�>��o����8���_��s�]i���O�������`[�y�t��T��Y������9���_������DDDDD
���i{���:�T{�7|��b�l��(y������������95JELd�j4���������6��UK���@pDq�������g{�E�M���c�%z�d��a�<�~�U�<E�[�Q�x�'m�u��������
/I��O����Y���L�V�2�����'S~�����5�61��c�1����0��D��;]��9��u�m���O��rT�Z����^�#�(�T�B� �&�5���)n��
�(������Y5�=_X����e�P�Ji��y��J�*U�R>
�������x����=_s*��4v}�,=�T�xxA�1T��5w���g�&����'����%/��*T���
k}���r�~?��������������X8s"c'���8�r�}k<i�Kt���f����������G��q'C���z��8}d7��@�+0��s?�����YI�;���3��^������H�9���-��GG����z�g=��g����������V�l��X���y�n���A�1�[�4���(���4v��+C�|�������{�u����}u�G�|��l��e>�%<3�2"i�P�7��[k�1����A+0�7������7K�.��s���L������|�?��]X+���e����c������7�~_N���;�h��J4�����t�5���3��&�J��?��OD$�����98w2�.JL�������-�G������3���3���	�,�[����|�c�<�-��y��	sx����y�s�6�-^�������;���n�<����7�g�l�)^��5�e�nz~6:q��U�{��+�,�������X�{{�C����+O�������n���>U�z�w�a������;O�A���������}��g�?�����/S�&��Pv��lM79��y�,����=(���`��]�Ry_�_�gj�����z�@�"!�D��Z������������1�!D_������3�/���s?m��J��P�C�����/����3��Gx�}06�
[@U���k���5�*#,(�����8��E�(��7�>�������S9&����������1�%���r�T�e\b����!�������p�cn
��'	�c��k�t���Q!��J����hf-�M3�{S=*��"$0����i>`\l
V�|�D���l�������l�~����Q�6�����g�K�:�'�6�r�p��W���w�+cJ����7P�x8A�!���{��I�Jw�����T0���[fg�����i[�$�!a�T���s������hxg��'$�$��=���2g�^zMN������)Dh����1��.p�|�f!e�8s��>N��z��.�<�~�HB	+Q�[�����w��zI���(Q�3�8����f��������
!0(��o��I�9��N��G����y�t~���5�jR��f�k�����3<��m��[:�BR �tz)I�	E�#��(E:R���J��,�! %t���P%���=����������z��k>lvg����{f�g��~��8:8S�r���${�qJ<�[?OX�����9z�p���G�yf�ux2��Y�|������@�/��w?���'�,ST��|��C[Q�����	m��_���}+��1��?������Y,�����nx<��{	|��)��qt�"���N������ck0`0����SOf���[(�o)�:����9{�[f-������r�g���,l�E�5R8�x 
�<q����;���<�y����~`L���-���%������gd����a�~�"�������������&�>|�����s��j,����u�)�_?���qQ�r����
�����fV[V�������y�/���/Ucgr���`NZ���Ax:��T*�&���[���|^Ic���$�q��N29��2��e����x�������y*�B!�!fj�~u�{h�db��j:������x[:��ry�7�\[5���2pt�[t�����p~�<�H��y=���z�1~���2�����3�:��?<B>�(��V��6������t�`���]
�Y�����D�7�E�1v�������?L���Z�P�L	L{{��7��l>AS}"�92e������'�������q����c	v|����	0@r�{4k=M���=:��LK�����IC\4fn�B|R����m
�6~��c:����t����;�����Hh�q�7@�	6������|�����8�Z��|�S=�����}G�j��E^IDAT�z�%����i2���A�c>��O~i��SI������P�cL�?��E�����m4�l�|mv������`����L>����|��b�}�u��L��-ht��XYR����{�~��Ne
<8�����I������=*����
z5��������z��X���x�\�_4�IS��-�ao<lS9����[�#L�i������j��u��X?�
^O������&��Q{�$���F{��0O������~�yc�rb<����Qh|�G;~��r���1c/�ac�Q���/9�X�R>� ��FZ�ZA�-�;?a������*��-`���N���o~l��fn�L|R8c���]*Wv�g��V4����18g��������E<5�u��Er}{:G��@��o=|��(������M�X�����������kQ�a����P�
�'P���,����7r`�$�eV�����Y�>���i�f��:�Q��/��KC���H����R��{���c�#0'�F����������Lg���)��3����jw��G��+����Ou-��2=��":4�y�e�7�b��h��U���{P��<���G�Y�?,���������R���E�����:=�^��cxm&?����Y.���.���'��=�t`�s'F�K�k���M��=\2Ae���{���+9�3j�fp����.���Z��S�&�eB3��z��:u�i�&$X��u���Ld�������C��B~�KG�2�W��k��k�:=�����Z�9.��Ujn�C�lXi4gW���^4�e��E�����b!�+����:����a�/��`�V�u{;~M��~/Mu(�S����m����6�'^!�B��a�V�F�����0w�����eQ�hn>���c�0���F�����1��#_f�	�4�U����1��J����|�|�o��}'��tye$���`�������e��������T.�z���_[����IV�:���{S��?�z������|��"s��F���9=a]&1����������M��l"Op�����Y~�3�������M�O����wI�r �t@�(�9K��X:�>�}3?�q,O�F�T�u���%�q?���K,��"�8�����:J�lI�:�r�9/}��L?-����T�W����FP�%�����4<)���'�������QVY�P��#jF~��5����Kv��E7$�O��P���D�#����_PF��w�`����l��Z�� �Acb����F��G����$������]W���h;�������	+��Q���������U���_�����`���P�����/��d��>�w=�p=����T��,�9?b��3&�7�b�r�5���=��'�"�3�������]���J��-�[l�����k�BZwB�FS�O�������nI��
��w>���K�v8��z����@�&�3�rLcj�GQu�|=$��>Y�iW�rA�����<s�������x����w"3�&�WB�6�K�M:��6�aT1 �Z6�X��'~:1��a������
|��:Qc;��B��4�;_,�Hl?��j�St����b�:=�V�dJ3���v�),~�;���C�/���k7ztoK�R��������;��s6���@M*�8���+X�4��h�.^�����'u�og���r>m<5�=^�W�i�7�;F����CM��M�)�o���-Q�x��hVh�t)����N�����
�U�
T����/�=>a���I,�U�ig���P�;=m\��9S�YTf�����J��G���4Z�F�"a][�V�e�����S�����U��Tq:����a��ZT+�,��g��>W�}���1����mf��x�R?:���9���<ESU��7>%��t_[x����9Z������y�j5[w���@���>��n%��`����{�DN���?�	!�B�?�O_�X%�d��S���5���f�2�y/M��Z����[����%h��n��g��}@;�8^�������'S�<��	l�l�.����rs������*�Q��>}��������F�z�a���$]�B��]L�����O�pTk
��J�fQO���1d����Il�� �!��Jj*�A�DS�#OA���`:~����b���^4�M��w���`t>���x+�{���r���H���3����lR9���SeaU1�:�R8��D���L��w��ei����m��Q�D2N�A*G'��\Z�p���GB�����W�vW�9���{��J >%�)Y����IMI�qKh:��m���5��t5���d����{.<])Op��������JL��!�����%��~.�[Ny��:�~o������f��	���X������������h�%<)�]��P��i��@�!����e�����.�����l4n���@{&����mS��5�I��K���"q�V�[�Jk4���	=;�`����jQ���n��H��%]U�k;=�������?r��~��N���	����Gy����q=�W&=����p�;�S�7�v��D��/g�&7:��9�W�E�����4���-,S�f�m�wx��2w��������&�86�:/�f���~sj*�A�6������3����T�	�1�������n\�������y�ZY������4RRxB��4s��Qn�*�|�|�	�����(��s�����=����{}�E��
���t6�S��P:{�e�����
�R���>%����!�B�'������?-������T�?���0pS���D�q��������}h�� �V"I���V����"����D� :v���K��,���T
46��j!����yYY �>��c��x�L��������������|��
�������	�=��?����0��i����K�F�Gv�W=;6�z^��L��O����lV�?%S��%�&�����*-�L&�Y���g���
tZ-dZ���3U�B�z���SW�}��/������jPJ�Y����{HH������h�7����;�p�<��
�������v?=�[t��f#_����V15����/���-�����6t�~����,�S�������B�������"�VXY�2��x<aJo�A�_�=��j�jTV�,l�Va��1c��+����"qs�q��"^p�|���P��O��zt!�vY�\�u���=?���E�D���X������|u.�_c���M9�p������48�-����g���CV��(�~���3w�Ig�Z�7k��C������%m��<��8��FS7u5C�P��n�����3�
<�R5J�4N��hW��������0�:�B�unX7�
�W�h:v��n��	-)*V�����C��f"O��f�J�F�� ���chJ��y5R��e�����)�z�^�E�-[��s/a-?��D����/�B!�B������jpj5��Gq��?����n
+\ZJ|\����n����G�j�J����q������:����K�[Rq�������a���_<�7s��	n�(��C�Idi#{6��������|��j�����H�����2��W	��	z]fL��a��dp��U�����+=[B#����lK�sc�j����r!�|�\���S�P*�Z�����<���?2�+�����hOD�@�h)^�8��qN4��4�V9���0����k6�W.o����Y���W������O*������aMpht�^���C �������Y�����x��-�DH�pJ��
h)Y?�~��h3�{n�sm�/F��]�7�3IK�J��2%�y�oO��p7�I�-,��G�8�kD�ikH�y(����)h]=(�{���W-��>f������"�3k���u��/S�����r��������0D�����c:���{J�e�/�������^+��yx����<�����������4�c���E'L�J���p4���Es�����N�\m8�R�;[xp�~��O�g��3T|}{r�o�/�����E���{�F����U���}�������MZ��4���������kR..����*��	[�W�G���;�Y��	#�!�����'g��/G�G��[��\L�9p0	���3�]"���T5g��[��A)��o�c��-O����
���Q5Doa�4`6g%-9�h�iKd�:V|���G��ygj4�Bm����}��*������B!������\�0�sH�������4p�&�)���&�tN���c�������P;q�6 ����}�{�J�����t�'����M,�d�|_�K�|n,3S��-_�I��
������*��>��{�`=c&��D��p���*�_���!o�����!�X3��vcb+��s�2N�����v��7"��#��5���	4����u�T�P4�fO�}������������rvw�����!m	/����G�i��vC{�a��t�c���!hO�1~�J��
�|�`AhF["�p��~8�%N-)q�,�A]h�U��O��8�i��xp�gf���K��������	�6�����R8n���a�2�����M��/�v�!��i����������I+��5�:��g����������i�����G��,�0�x�c��)����nh��n�i1������!���i���c�)�2]"���+�����_����\��=-N����������^5���������z�`�O�D�zF�c�z�v��P�?o�,a`�Nx���h��w�s7�������-����f��*"/�t�l>��qs��c=Z�w���>��2�����%����!`��������Zi�V���-8�^H{?-`�B�P�����O�����
't��}�b�<�2���L7�q�������xw��f_�"�O��M:	��r�dK���Bx�����B9f�\������
w[#;W/ao�.Ts��:����V�x~)C{����4��BF�E�x��;3�������@��}�M��{���b����j-���mq�9��!�h���hze������R�#�����f��'rII+�"V^�H��M��;�\�k3F�}��m#�������+Y},�����,�oj
i�u���]��IM�m�|�'���F�0_���{�&�J��j
�"�����o�f�a�kI��?�8F�
O�cS^�L�i�ig�.���������V�������s�y���u3����F���E<C��|�a���Z�V�6�6�np{����l���o'��~����?���������Yu_X�tZ�����o$n���6	�����nI�:�0�K��/'�A�}�X����\�Oo���S�U�v~����%n�T�,}��B!���F��xK���
�VeoW����P���������)���~E�j`�����z�������)�g�0U��VtV���GU��H�:��J5U�������3h�F�S;�U��j���p�Q�LW7��*W�fj�����?8�L
n�<����kU��\u�^�����M;��^���M�]-=����i��W���g��jz��%m��Z�P���T��K���rH=8ZE����<,�L�]��l������Qy�uSK.�)���:��h��ji�hm��yE����U�����v�UNYWx[��]��juWWe]�Cu6-3m���R�*W�z�*�UI�����o�W-llT�wr�������u-5�t�2�*e���c� ��j�:������{|��]O���}ux^_��l�:e�sU�j���vd��������������JY;���&���RL�����4S�6m��{��o�m�kz{�i�;��^}q<���5>].zoU�au��d���=Uh���������#���-+)g�7�)w����s*�hT�G������POe������*U���:�L��O���q`ye�\_}z2��t�]Q����j�uWv��sPu���GF�J��O}�7F�/n��l�T����Ow&�t�1=i�z�v�f�WZ��r��T/}�Y]O��?��z56���v�R:��r�P�����i�7�����n�e�1�/�T��������m���bj*7��-^N��������G�������������
&��)����kj����������W���{���O�K=1Y��.�z������RS��~2�=����>�
���F��O�JI�B
����*�x_��(V��pVM�����z]t��F���[���@�tPVz��[U��C�:��]�RT��q�Q:�^�������y�og����[}���
.ULY�
�����3���Uo�g�Q��P.�ze���j[���sUV��������U�r1N�2���M����n���J��S�����B�~���%�e���6YD[{�s�jT�C9�Jg��|*�Q��9�R
�����ST��������3T��VZ�;�����Y[��i���N���J����Tp��j����u�-��z5�]U��J�te�\R���TH��,�V��l�"|���N�l�<U`�&j��[����s��E�UT��rw�R:��r+SK�4~�:�bY��F�J��J
���\���,;���*qy��/�^��~������������:��]P�c��s��j����L6�d�M6�d�M6���7��h�cs~�5f7����o91�>�E���{��A-��y;;G���"�9u���T�������&���R��"}]O|������(���2��n8���a��qOV_�o�Oj�&���A���l8��>UB!�B!,��/y~K`��^S�������
Y��fw�����WS��&2l�]W����B��{�X��<��)���uh%�>=����!�A!�B!�_���Z0�TL��t-^�f����PZ���_Ga�-K��_04�����B!�W��N�q�$6���������s1s��$���
!�B!���o+B!�B!�B�O��	!�B!�B�/%�A!�B!�B!��$8(�B!�B!����B!�B!������B!�B!��RB!�B!��_J��B!�B!�B�KIpP!�B!�B�)�����;
B!�B!�B���������N�B!�B!���O����w�A!�B!�B�7�g
!�B!�B�/%�A!�B!�B!��$8(�B!�B!��������}
IEND�B`�
#71a.rybakina
a.rybakina@postgrespro.ru
In reply to: a.rybakina (#69)
5 attachment(s)
Re: POC, WIP: OR-clause support for indexes

I'm sorry I didn't write for a long time, but I really had a very
difficult month, now I'm fully back to work.

*I was able to implement the patches to the end and moved the
transformation of "OR" expressions to ANY.* I haven't seen a big
difference between them yet, one has a transformation before calculating
selectivity (v7.1-Replace-OR-clause-to-ANY.patch), the other after
(v7.2-Replace-OR-clause-to-ANY.patch). Regression tests are passing, I
don't see any problems with selectivity, nothing has fallen into the
coredump, but I found some incorrect transformations. What is the reason
for these inaccuracies, I have not found, but, to be honest, they look
unusual). Gave the error below.

In the patch, I don't like that I had to drag three libraries from
parsing until I found a way around it.The advantage of this approach
compared to the other (v7.0-Replace-OR-clause-to-ANY.patch) is that at
this stage all possible or transformations are performed, compared to
the patch, where the transformation was done at the parsing stage. That
is, here, for example, there are such optimizations in the transformation:

I took the common element out of the bracket and the rest is converted
to ANY, while, as noted by Peter Geoghegan, we did not have several
bitmapscans, but only one scan through the array.

postgres=# explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 AND prolang=1 OR prolang = 13 AND prolang = 2 OR
prolang = 13 AND prolang = 3;
                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..151.66 rows=1 width=68) (actual
time=1.167..1.168 rows=0 loops=1)
   Filter: ((prolang = '13'::oid) AND (prolang = ANY (ARRAY['1'::oid,
'2'::oid, '3'::oid])))
   Rows Removed by Filter: 3302
 Planning Time: 0.146 ms
 Execution Time: 1.191 ms
(5 rows)

*While I was testing, I found some transformations that don't work,
although in my opinion, they should:**
**
**1. First case:*
explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 AND prolang=1 OR prolang = 2 AND prolang = 2 OR
prolang = 13 AND prolang = 13;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..180.55 rows=2 width=68) (actual
time=2.959..3.335 rows=89 loops=1)
   Filter: (((prolang = '13'::oid) AND (prolang = '1'::oid)) OR
((prolang = '2'::oid) AND (prolang = '2'::oid)) OR ((prolang =
'13'::oid) AND (prolang = '13'::oid)))
   Rows Removed by Filter: 3213
 Planning Time: 1.278 ms
 Execution Time: 3.486 ms
(5 rows)

Should have left only prolang = '13'::oid:

                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..139.28 rows=1 width=68) (actual
time=2.034..2.034 rows=0 loops=1)
   Filter: ((prolang = '13'::oid ))
   Rows Removed by Filter: 3302
 Planning Time: 0.181 ms
 Execution Time: 2.079 ms
(5 rows)

*2. Also does not work:*
postgres=# explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang = 2 AND prolang = 2 OR prolang = 13;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..164.04 rows=176 width=68) (actual
time=2.422..2.686 rows=89 loops=1)
   Filter: ((prolang = '13'::oid) OR ((prolang = '2'::oid) AND (prolang
= '2'::oid)) OR (prolang = '13'::oid))
   Rows Removed by Filter: 3213
 Planning Time: 1.370 ms
 Execution Time: 2.799 ms
(5 rows)

Should have left:
Filter: ((prolang = '13'::oid) OR (prolang = '2'::oid))

*3. Or another:*

explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang=13 OR prolang = 2 AND prolang = 2;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..164.04 rows=176 width=68) (actual
time=2.350..2.566 rows=89 loops=1)
   Filter: ((prolang = '13'::oid) OR (prolang = '13'::oid) OR ((prolang
= '2'::oid) AND (prolang = '2'::oid)))
   Rows Removed by Filter: 3213
 Planning Time: 0.215 ms
 Execution Time: 2.624 ms
(5 rows)

Should have left:
Filter: ((prolang = '13'::oid) OR (prolang = '2'::oid))

*Falls into coredump at me:*
explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang = 2 AND prolang = 2 OR prolang = 13;

explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang=13 OR prolang = 2 AND prolang = 2;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..164.04 rows=176 width=68) (actual
time=2.350..2.566 rows=89 loops=1)
   Filter: ((prolang = '13'::oid) OR (prolang = '13'::oid) OR ((prolang
= '2'::oid) AND (prolang = '2'::oid)))
   Rows Removed by Filter: 3213
 Planning Time: 0.215 ms
 Execution Time: 2.624 ms

(5 rows)

I remind that initially the task was to find an opportunity to optimize
the case of processing a large number of "or" expressions to optimize
memory consumption. The FlameGraph for executing 50,000 "or"
expressionshas grown 1.4Gb and remains in this state until exiting the
psql session (flamegraph1.png) and it sagged a lot in execution time. If
this case is converted to ANY, the query is executed much faster and
memory is optimized (flamegraph2.png). It may be necessary to use this
approach if there is no support for the framework to process ANY, IN
expressions.

Peter Geoghegan also noticed some development of this patch in terms of
preparing some transformations to optimize the query at the stage of its
execution [0]/messages/by-id/CAH2-Wz=9N_4+EyhtyFqYQRx4OgVbP+1aoYU2JQPVogCir61ZEQ@mail.gmail.com.

[0]: /messages/by-id/CAH2-Wz=9N_4+EyhtyFqYQRx4OgVbP+1aoYU2JQPVogCir61ZEQ@mail.gmail.com
/messages/by-id/CAH2-Wz=9N_4+EyhtyFqYQRx4OgVbP+1aoYU2JQPVogCir61ZEQ@mail.gmail.com

Attachments:

flamegraph1.pngimage/png; name=flamegraph1.pngDownload
flamegraph2.pngimage/png; name=flamegraph2.pngDownload
�PNG


IHDR9����sBIT|d�tEXtSoftwaregnome-screenshot��>.iTXtCreation Time���� 31 ������ 2023 18:34:57r9F> IDATx���gXg��gw��7E�]{�=�1���D������1��5���M�
bI���X@�X(���+���Ufv���;���g��JNNVB!�B!�B�;�7�B!�B!������B!�B!���$�B!�B!���$9(�B!�B!D>%�A!�B!�B!�)I
!�B!�B�OIrP!�B!�B�|J��B!�B!�B�S�B!�B!�"����B!�B!���$�B!�B!���$9(�B!�B!D>%�A!�B!�B!�)I
!�B!�B�OIrP!�B!�B�|J�M��


%&&����7�/���J�(��CB!�+Bll�\�
!���*99Y�������w�qqqyQ�S,--155������#44���^IB�	'O����@�B����������		A�������B!�[#O��������P�P�����._��F�yfb�m�����T�^��� ����~�V����B�<�V����x'����V�Z�j�'N<����	����B�.��f�			�,Y2/�z.///BCC��8���P�<��)�[Ej�!�G111����^g�.]�<�y�~B!��<I�����dX||�[���M!�o�$FD~��CB!�[*�$y�d���79�<���x{{����Z����$$$����������}�X�xW�T��>���l��O�����9 ��B��\c
!�"/��h���P��������p��$%%q��9j����u�KN�4��g������8w�Z�����8�+�D���^�7��������s����-[6W�?~�E#�5o����'3��~�"�V����a��g���?o�@�"���M�kgg���y���	�w��E�(�&W|B!D^S�UA����q��5BBB���BOO���d�Zm����8�Z-�������
��k�r������>tw��G���{����Gv,--s�x���;���Hx������x�����0�B��?�������{�����x�r�
:���?���l[����i��.�S���B,Rg'���b\%g
w��yS_���?h2�#_������?c��/Q�������.?�D�uh�G����%6��y��922��'2q�D"##s����K��������|c	!���<K����������_�@"�J�,Ixx87o����gggBBB�~�z�m#��J��>������Y&��������X���@/����>��53���s�����cX���<I��������KQ��#M,�s/N����mr��0�C�[�~�N�3��P���%M;��hb����v������O>����0��)�������Y��c�^l������E��1��)��xy{��`��PZ����}{J�(Abb���al��7��xaon���3E+5��������3����F``d�uo*6���]WIz��=�����x{�`�.�yL{�ovm8����I�����gm����x`?8��)?�������8��u/s���k��9�)sS�B�d�nNO��s�;w��A�P!���-���&�e��qL���7���$h�B���k�9x��5��9���j��;w�p��J�,���S�$'rR��������+DDD`gg���#�O������(	7��F�q������������/\N�u+��� �r-���$����{��e5�Gw���\�k�`zhr&���k�?��G�������U��w�o��m�#W�i�VL;/�N�fA�M������O���pc�J�$��������{'�5vx'���W�����t��	CC��W�w�)�+�t�n��1S�b�����=q1I�/:���nsG[�a[���fV���z{��&}��~;k;j
�p[�������Y��mJO��r��XS{
�oB�y�^2���y��O{�M
�u��R��~h\����M��!)\�c$���136���%��GdSI�����8�4bA�;V����N�w�����������;-��:�s����
�f����'7W����5Ko��O`TT�&M"::�����h&M����(/���
����t�V�o���U�ckj��k�V �B����%���9u��
z�����<KN��WWW|}}	���k8::�����3gqh�q���������!�#r�Df](@wQ�"��?�r���>�n�'�xUh��?�IN+����4�P����X�[�\�����o{����=�VN�����I�K2�wM"�F1���p��J��p%1�y]4{&t�V���X����c�^��jL����,m�,j[9�����_3����L��T�H�v��v<u�G�u�i�]�	~���rE��u'�������{vu�G�+����6�~4����e���/�k+O��eO���'���GTT7n|�#**���������L�
T�D�N�5�c|�Ns���G�$^���6���1���(���q�V��%I>���>����5Y@T�Ky���R��ucs"@
�wM�K�����a[��������J$[�jD���0����*������m\O[3�l���}>g����k3�eU|<�01����2�����,�=��h�������.�
+�R�#��j n)-��i���{y��J�hQ�"��X8%�����W�D�������JN[X{���(��~�
GYS7z�x��/;����j=z4���<8k'qjJF��@�u�y�@��lB��]�?f>����!�r�#s{S��fV��n��U���(u\]�!�=�06���u�/���r�����8����01����
C����$����C���X�c_�
]�;H��jO��)V��R��G�Z��O
G����5�}�~N�Dst^?���`if��gY>Z~]��7��)�K�L7;3�����^\L��(�b���v��Y�#��\�W/���	�v����-���j���k����JBK6���3K|�����q����s���f�]l036�������h�+8G�;��ei4rT�����e��)���@��H2��i�������=�X��z�A���'u���| ��e�tz-[O���_�t���_dR��L9���5�q��/M��=Y|�t����4��}f��q���M�q������Z�'N��J����D@����a�)����w���%�{����T�R�&M�dzT�R��/��w��vW�Q�NK��HQ|���aP	,�^��0��3��	�7��K�����#,�=�o��f��)�Y���i)Z�����_fOe��1�?���]O��"�6g�-c�����-Sf�������%|��L�8���&1s�N����B�^Kr0&&�S�N����J�"::�������K�r��x�8�|(P???�_����Wqtt����S�N�Rq<M���hT^��IqN������=���7i3f�'0�_C��;i}�%rjbKZM������R�,u��te�%-�#:t?����x[7-��
�X0x���0d�*�-J�k?�w�B������i�������k����g������*����[	����5[��r6��zcX���P��\%��!���Q�R��|���1���Q��2�S��������5��}w1=:��X"��R�2k[w���QU�^��^s.<]@w���28�:�V�!��=��Glmm��i�S����U�"N�z�o�kR��
���#7��n~�Q��n`���I���9��,�2C���iN�>��Y�ytx1��������$N��8��	�~��/���������P�th���`��ml_7��)��e�9��0���7��� ����������4L��8�i������?|N�������y�dQ��*]����l����.l+����
Y��u7V��~6��b��l�����i9��0�\P5�"�����m*w����I�8~�+Z�;������7z��{��-Z�h���S�K�5��o_�/$�O~]�Q�/����3jF&2�%
���u�i����o��X\������F5�������l���Uc���/�J;Ge��n-��n�"�2n=�d�����6�v�a����9�e���K_W����K#r�O��K5���y�d���	��
m����m\����"�9G������@����e�V�L�I%��|�� v���������G��\��
����s]z�M���l\5�6����~f_J�4�"���H�c�����,���A��w�(��%qrRw���������A�jJ�V]0�g���(�������������|����$sr�l����f����m"}��f�5�V]����.��	$0���,Pk���:�F%�X��)��lR{3#Ll��<�#�	S%���ZS�D��
00s���c�J�q~�Sw+LL)Q +/�'����&��6F[���j.�+o'qxTe<lM02��hP?�d�+���z��,���&�����o=�����iP�	3Ccl����M7���,m��u���~�3Y��c�,N��e���4���?����qf���u���_L��-�
e���y�^r�1~�n7F��`h�5����C��<����AI���K��nU��i����Pn�rb�`���gJ�"h���_D��h�J��J�?*U��B��jK[l�v���XOw����=��2�:��c]
%�f���\K��S��S�f3:H�VUq�>�o[�pWx��/r�������}j�E��rj�B6�K��FK:vlC��~�Z��,�����^��tl���3lZ��k��@!�xiy6���.<n�����!j��V��7������5�k#���@�\�z�7n����Z������7obaa��q�p'�X9P��`Z����K����-��SX%�\U�LI�v�8����?�>�<���bb7�@9�q����5����@OEAe^�J�U)�������cX���X��a�2v?G����m�N��e���5�E4@��*�Qv�d�
�IW�����f�_��6�����;���;U'#�do��>9r^��Z���IL����'���(6�/@�~�����
��,z��(5�";j�c�������Q� ZK+���;V�����U�b����E�gXK�m�d����q���Zn�����(��� @�&M�[$�@!�OA���)�q ���{k-�,������>0���* �E�S���n��v&�L��.Q�G��������xIJ����������'����]���$�
�M?��E
��N`5�F������?jt�Lc/5�*E��U�����/����K��J��6���Z��j���[���m�<� ���x���>���Rz�8�m��S���ri�
N�5dA�,�eZ..��zM6.��Z&e�{}>�Ws`zU�Me�
�;��E����Yc��C�)l��{����-�^�����G�a���t���\�%�o�)R6�g�'H�������nY#��0��K����m�
�9��q���)�6Q����+������V���]U�n������V���J����D�z�B�4�����b��#��}Vm�N�`��sD�&�_�����FT�Tgu����n;�}w�~{X1������x�$�#e4 0=���[Q
����U�&@��@3��|t���a�
�6�D���LT��L����f�&)�����KM5V����Z���I
�i@�H:�/��`�p#���d>7��F�$h�L~�hN�����a�c���B��O�2#��s6�����������"k3���40����_mE@�o���=���7x ��
q����+���}g����8�Go4����Co7e����3���?�kKC<N~K�Q�u����X�������xt.��T���/���P��J�6�;3�
�Dn�wP[69�d��Ix=<��#��A�X�My�'_�������u=�]G�hZI�ne��3�EI���o����3�u(�~b4*C�jV����R�Q��+_��|w�*���+w<�����p�>��N��MS��<�f��S$�/H!�Hv���l���%�=���w��K���)���r�U~W�,h�"�u[63o�a�|(]�E�LP��c�jA���R�I
��� ��~	%�FM\�4���)Z"��X�^���pn�Jc�P�g�AQ�����k8���v���m��3�0ukO_�2<qSGpi�?�YW'i�,�B�����������&22kkk���	���+����U������p"##���%""���$�������P��MFca��e]�(B��s8�AONL��q��tp�bi!w��*X�{����\���W�
B�����
�������.��i�x�:�5*��Q'�sW����3I�\u�:�(P=o�tN�KB)���^W�x��r�q��|=l#��:�����p��eex�@��!�XI[_s��t�;�Q�����7��3�����HN���fj�����1r���A,��$����C��������3:�7���-t/j�V%��f�����7��q��.1�Wn([���A��a�U�m����ui��a�@ONA�C
��?!�����D��@J����`r(�N'���&^��y�q�EQ�w?�nO�fX�{�q+J^j�G��;���8?���?��|1������~���uMT2`���\��H�d����-����)�;����ph5��Y��}����I�v�������6$"FA�\�Fa���wk��]�0o7�F;����]�6:���(;�6/Qq���������[7F�I���9�<��y�j
��|�R=;����s2��*�J?N��l�T
����Ur�L���>q%�/f8G�}HV�m��}W���t\����+������g'j2C�|��!�����������$��5n��>��HiM�;�M�m��0~��B��l�sJ�1N�ZS�V/^��	�5��EZ���H;�w�I��ep|�5���'O�)KPu����JU2��S'��
���
�Q����H����u���x�{^�yS����>�
�������yxq>�vg����fj�J��uRC@��-�������>���FN�P�Mk�{��fU�.�A�e[8���Zz*��iZ����~IF2��+���c=�2ef\`[�U�:1�
ens3R��Mm�*`d>�j�
�D���@M*��`K�����X*�����x���c��3���jX�>��Mc���X���%�������*�7�Z-�������<~��W�?:�3����mptv�P�U���=��<���J��s���
n)��9f�D�pvPs��� �M�������Z��P{���a���Xw2�cG���z�N*D�Qs���y��~��������"U��'�sgO�i�~��jL��%Q���]m$~������qL�HrT(�v�����$$�1�OF�bN�3�VH��N��5
��/\��-��������vB!�Ey�|kkk8q�)))��������'�<A�SW�^������s��M����s�e��������~*9��#&L]LP)�}�)
�`��7�7���?V�DQ0�0���u
�N������?��j�KI�V���'
�(�@�6���4�z����*(�.5A�dN�)�����d��pj����?c��[�������v�bh����Z�~�,��
gC�\)�`�z�):������?��$cM#�sR��I��S��z<��U��a<o�x��WPa��Q�X5�j��M��n���j��1���x{{�u�A��3�%J��R��L�*^����5�~2���e����~^<k~5Q-�<{s�%E�<ZA�@�N�}�~��=SWW[���Fn��r�{��(Tw��	
����q�JK|=#^uZ�n��v�X|�?C���r�,��IV�������'�[�����*U�r�n�r|>�w��spw
�S��D�C����u���;������Ut����3g2w�\�����Z�j�BxY�Xw�w)J�g�g���g6�����v�Hh7����[ IDAT�+�j��!M���2�;�[+��D�u�2w����D�9;X�^AQ4�u��
��3}Y���x�i���wN���C��
��Zc�V/��:�Eg��o)��,��*
5�$����)�o#��������U��� �mCu�'}�����~Z
�Z=K9J2�{��q�T
*�)�X;�����U�q0����,����g��S������'����	�,��t�:}���P�W0cB���I�����a->Z��_��W>������f��Me����j;����dN;��;���7pJ�����l9v����2�r�3�Z<?����H�ozf�*�m���q������Zs��^�)��5q�h���+�\:}��"������k����l=3\�W��xy*�������^��z(�v'0�1�3�EPah��u��\�	���o�g3�g7��h6�S�����u�yM!�/��
H���F@@����FO+X� ��#,,���9��c����#""���D"##	������x�.��x065A�l�IG�/���&��S
�015A�G��
�R��!bqMK��>����T[���/Ni_=�<��O��������T��wl��o���,8�d��N�Kc��z�:*�����(���q���Qw��kv������TE����K����n�)�C	�2�t���Q��%36.&��7�t����/��6���~�!�����)`h�����% d�o?����r0���E��M�Q�by��041FO�#6�p��%(��O��}�e�|\���Kj_J��H��*,��R�J�T�B�J>��^a_��G�og�K:������z?����:��M	���2����<�a�kX1o%Q�z���������g3+B��E?�����qk���	�X=s9[�j����D����7q�Lk�g��a.��j�M��h:�}
�3�L�Vn��2�������B�)e������J4��B�U
�U�t~y�T��
�z��)����G�+�KI�r��<}��$�}g�B�����q~l������*F@I="��^E3�o�g�<RY�����:�X������x���g�B~���ph�i�VFm���B���/0J�K�z����;�~v�v=xj��
hO��`����a�_��+��k����+L!k��:���s�dV����S��?�&�G���$m���U���O�*��U�/�����9}�,��O�]=C���Cvr��>��`A������u����������=�|�T
�M|ipv��7ne��S������qx�����U7ne�D�"�y[����q�*C,�L�<8��/�c=`
���q��
�Z��L��i�v�]�|����s//�IDG����3%���&���a��a���
��Mn��(X6/�(`g������3%��W^~P+!�B�N���.i�����(?~�Q
���J���-��z<��}n��v����T�R\�~���d���)W����<]�wLL������T���=�G�zX���365��8�R����Q�F�{��h�,�EJ�^6�z���dl��^sP�0�Z3��,GZ~����&���_�/���uL}���h���w���&~���uf��J������t��L��JV��~�|\i9����V_��E�?B�J���/��%�Vma�������A"�D�<~m
U��f���\��)
.����_�i�xZN�������������q�������������[�A<���:1�� �_6���)~9���?ff3T(+���O3��>~j����N����P�����=x��X�Z��������8��6bdg��V1n�A:��cA��*+����%>�D�)�iq���PGb�����tbM��5��9��Hf�kS�:��?������]��M?
���oe���@�	��v�\S,
%��d��|��	��R�Y��WC�.��*Z���Mi_�+�O��U��4SaZ�5��m������5'*�P�Z5�����={rUk0�)5�������oP�}z���6����t�Cj1ih}~Z��q]	�K�
f\�}*�~���������-v�����cU>���v�*"�eC����PT����R<8�����L�����/d�-wJ�A�_W�gk���m>�����h�Yah��4y����k�!AY������
��|E�1��sr����EC�-I�)i��5=jzb��7M�������e��Q������.�;���l�4j/�����*I�$��	!+lm������!AK��_G
��� �h���17 #���MjX�m�����|���?�W�^�2������S$���6@I4�w�DW�'��IfC*t��
�{P�uI�O_������=%��8L_�9V���N�U��gh�g�����h}�}_�n�Q��L��N����o�_��0q7�n��)����{8a��bi�*���)�~I���`�6.�*K6�+��W�*�����P�H<���1�V�L���U�V�R�d��<���0��w����V��!�pa���y��u�`�I���C����Q2�09��@�7of���Y.��eHn�na�_wq�t���URWO�����m�w/O%��l�����u0�1��:S��	��=�
�O���y	���<�y���p/�h��S��,�6��0��v��������kv��sv�Ol�]�v=����������kSz4/���=���fA���M���B!��������o��C��akk���#'N����5�m�E���`��\�v����G����9�F������=065z�����>C����LSST�8b��P��(��Z�Z�b���t�����B�zR�k�����Y��&�����?���i�Q����a�����m�b����_��:S?�O6+N���!}���'{�2��j������ed��i��k�&������}X����'���VE�0wFC�~C�E�$kL��s���3��qj<:1c�>�8�!���ss�W\/#y������z`�������1����B~U�d�>k�6��c�l[��/�3��D�9S��06LHE�&3�����I�xT��m������������i�T��Hc�TmN���u�5C��Jp��(v%����_5�6�5h�PYQ�����:�o����8�t���W�3���^&�X<t��*}�3|�d<����Nh5���?���V��<�];��
c�Me����qO���/-�6�sZr�3-�2l������i ���dU9�[�|������������3}�~�O����c��]Tf8y�Q�m 	:���&�����f�$bY�*�~�����@aR��F5���/�GS6ts���/Y�k�M�K�_�����l�0Z�z�$�)V���p���y�NK�?;�e���H@1q�h����.7�
�Mc���[�����S�p)V��5�����A�hf]C�Q��� ��������������P:M�K7�
XL��x���Q�2rNZ�JB������.��ZA��k�X7����BL�V��h0n#j<�yR{���?���A-��`�{��L��[z���/�������c�V�|�>��T(5�|�1��X�jc>�����h�����NC��{����WV�*H����i	`K����0��������cqk���O6�~E��c`����������U��K*C�v��k��n�|R���q+��H�>MC������j=��a��zx�������0��
*�����\���m�h�M�����`���0�G
��thL���;T���6�=��2�lM���~�&��oA�wr���/�{-�/���P"��[_�M������������4pO��o���i����.�q����!�.�`�:j���������,�����E�v���g��Cn�'7j��Q��5n���s��|Z�1&����y��{�(z�X9yR�m-�yvTh����9r`'���1���T}J�c�5Z��������O
�F���z~\mG�v]����������:,	h\<����w&���gt�!�B�4�������<r�~~~��^e'�Y���FFFDGG��Y����V�9{�,*Tx�86l���I��Yll,����`��9�=�8��_O�z�r�~�[96�mB�rpu��$�-j��m����y�,�?s�����*���
���	���-��koT�"X��5e������'��}�~�zZ�n��sJ�)�L���u�8��d.�O�v_1ux=\����/�r�F�_K��p5:|5���Jb����;�i�VB����u`��q��6%�c3z�k�fB�l��0���t/�U�i-'V�ol!VD-�E�{It�@�K;��O=��B���8�6`A�Z�_���%�P|�����,]�=�O��1���\��[/�O��o�a��a��������n������a��fN=P�t���R�o��S��3�MW�W'u+.���AcY���z.4���������u���~���M!S��������f�����d�\������w���:K�W�Hk�����*t�pu�7|<t>�.%`^��&�bD}W4�.|AE�b� ���3�~ekl�>`n�f�m2d�t����	gl&��!�ua��oi[$�NP���=���C8�G��A�pn~O�}����^����=|x��aY�f
u���4o���l��HM>YcP�V��<�;�y�!�B���XrRG
>~�8����@��]>�����_����^���-�ms����~�z�����%���#,Q���?���S�_������x��-�V���}�3X�WDL�.�w�I��I{�S��Y>���w����5k�S��S�3&���
>�!���koV����k������W��]\\2]�6��qT�W/��������{T���%���B!�Z�9z]��������6Y%�B!r��&_d���O�����aV�}
����u<�C,;��n�7�x���x�h(��!�h��AB�]rc[!�y)O��fff�t:T*�+kJ�V���t��==Z������+�C��)�����y��!D����{�!��F��]���d_�w����3����B���Yr0""gg�\���:��7nd�|��������+V���!�����8��$��%N�8A�2e�t(B�Hn�/u:���s���3 �B�oy2 	��+WHHH !!!/�{���fff��*���Btt4����$!^'lll���y��!�+���MTT��E�<ekk���
%K�|�r�������g@!����,9(�B!�B!�x��C�	!�B!�B!rD��B!�B!�B�S�B!�B!�"����B!�B!���$�B!�B!���$9(�B!�B!D>%�A!�B!�B!�)I
!�B!�B�OIrP!�B!�B�|J��B!�B!�B�S�B!�B!�"����B!�B!���$�B!�B!���$9(�B!�B!D>%�A!�B!�B!�)����k���C!�B!�B��e��W��������?+G��M>B���-����*�������gL�q1\�N�q��y�7v��x�{W��������� ���Z=.�������l������6������l^���������6��x:n�N6����$�,���6��6/�`��,���`c��y)c	6j����g�{#��
O�H$��������`�RbXK�c���D�!�������	�-���v/����cb6�t"�lU!�����c�g�����@=����F��/?�4�V/T~F�.l��y�6.����'� �8�������,���B!�B�
I�b!�B!�B!�)I
!�B!�B�OIrP!�B!�B�|J��B!�B!�B�S�.9�_!���x����o�x�=m������2�gh��o��i�\�����N�X2�62����<���y����2Tni�:e�g�6�2��iqyd^_���\�����2���^��p�i�h-��-_��x��4��`./:I�����H<4FO�#�����N<-P��M� �B!��S%''+�[`��]��h�B!�B!�B���{���11����f��
�~����/�����x��	KL�C��:/���k"��]������zx���S���)<��S��}��w�r�g�a2C�����x��=������i��0,���q<�����C��:/��az��0�M�����#a�[�0��Ci<�r�8�������tlxe^��L��a����I����m\���.����WR�.{�-��/�u	P�g�X�y	<��_l��}7��/s����.#R��)��CB!�B�7j���/�G��.�/_I����$��o���@�/�B�X�0�@�R,H<J�q��yqh�u�cAZ����M-mR���&�M|���r�
+>�N^�����=*`���\F�q
J���m
J���fv,x��~i��S_�m���a�4��]�@�I����#Z{b�3fX��~M|�{�\���.4��~�\�m�1�,�M�m��]M�O�-��5Y]>?��!���$'�'{�b�_H!�B!���#=��J8�V��sP!�B!�B�J��B!�B!�B�S�U�b!�xg(w[���^m(W�U��t���[�$*T}����u?k����4!�B!�/D��B�&��[:���@�>�L����gU0�%r��������S���B!�B���$��-��-F�Z�0Quja~�%;vp}de<��-�B!�"H��B�c�\7��5�3�pI&T���e�$*���peT
F7��;��yI\����]Ws_��gY�B��l���Dn�h�7������G�f�]
}
���{����B!�B!�O��!D�(<�=������������?�}��<4�L���Y6
~�Y]���G�����a/.V��=��F���M�e�I$�����Y����0�I�<�G!�B!D�&�A!��	�m"����5P��� 6/�Dl���I]l�	�L@{#�\]����������5�aT-�Ty�B!�B�|M~:
!DNh�%�|2��c�~�T�R��7��n���&5���y�J��^L�	�p�8��#���{3�!�B!�x�H�A!��	]���,�L5��f�����y=���� �e��HR�2�L�?��=��z��!�B!�x�H�A!��	�Ff���a����}S
S���*�4 ��.������A�"X*aD�/%��!�B!��#�A!��	Ma\��s�(���y���u	Uq�T[Y@lt���)�����,
�G�)����)��ps�-�9�'��~N-_���	$��/��K��}�^��-�B!���$���"'T����=�a�7�T�����?���	E�o�����re0��;G6����Q��q�
��Dy'
��})����ng���;�G�(w.����*)$�����yP�+��9�G���_�4�O������g6}y��T��0�o����.j��D!�B!�oI
!D��0��5�����)�Zz=J���zMP�-�W�M{�����0u��?�R�?���dy&0�2�����&&�E��|:���%�g���Tj=���p��1��EA���#u�B!�BdO��B�c�8�I��#������_,��/2�l@�,�lL���i��j*����:9�G�i�_�>}z#:e��������������4M�[F[Fi�{oYa�,�7��""�E}q0\u�
�Q�"�R6�������������M��MiK�?��s�s��NzH���B!�BQ����B!�B!�B�R�B!�B!����a�B��-m?�_��S����g�K�W$����%�B!�B��B�n�i9s-�;!�B!����b!�B!�B!J�R��x��|�Ge���B�>��sy���2�����=}���8��Y�u��n���
!�������k IDAT?�`�xmC+����'��{��82��7l���NqU�^�������x7�VV��bp��o�"������6T���GP��;���$�B!�E�b��w��@IMM�e�-����g��7+!�B!�B!�Mr��98=��S��U������Kj/��{�>��.w�Q���D%o��e�/*���`������	f]�V:��h�^xQ��1��3�S��l:���!fce���1{+�x1{�?�����,*�<fCQ�1�fv6�J��Y�,�K�0����O������[FO���������WQ���c�e������?��(�V��G��Z��_0��7�J�wW�������y�+*Q��1'��--"|W�!�������3S�;!�B!�;��=P$UG��W$���m��x���Lz��[�@mE$���&�r�%���`	�a�w��-C��2��
O�Q,�V����X�3�/��/�P���,>U�H������v,u��?�1�7"���\�A,����'o�b�X��I���������:��=���-��[a[������v��~Dj��nC�I�2���X{K@�<�E��X�OG��H^��MQ$��B!��Vd�/�:�'����MP��B!�B!�B�HrP!�B!�B�RJ��BQ��x��\�������S�����+���L�Q�����V3���
�p"�|����'� �����
�������#��c��0��zb��)L��
C���
}�0I�C7X�

�������!�Bq���B6�Q�#������A;-9��?^B����O�����X�������:�p�;e
��*���:x]�u����K�`�
�����^!�B!n���$BqkP$���D?��Py'�b48�Q�����O�ZM^@bu�S�0X5X�A?�S2��Cr�y+�>B!�B�"�+�B����X��.N�J�P1��c����J+'^��g;������88�U�^�����x��`I��8����S���(��UG��o�fTX��={���U'����k���
~�8��?��NU�s=*��7�z����B�Q������J����
TF+�C��dM~�_T�T��@��+p�y>��OT�U��@�����z�]!3��������������H���/^�^*���V���!:��d��Vy}�B!��EHrP!�H\�_L����w2�G 	��f��$�>���~��U������i�ly0�C�F2��Pt������Q�����V�8N�f�o ������w.��z6R9��j6n����5���+���Hr�.�9?��=�>'�e�O3���2�DI�U�

4P��}�9!U�Ta�w�����9*������
�b�xH5��l�z���4h�@S\OV�[�g5h����9{��KC��m=���R�����-���.!�Bq����Bh��|'�Mz2zj���v��a�g;���� w��+��T�k&O���X9�u�@1Qc`}~����^�N����E�{�Q�^�r�S��R�z}+�:.%*�5�=�����=x|~g�{��l�Y���3#�&�J�T�����@s�g
�0b;���u����^K�Ym�����Ua0S����P�n2_��`�
OX��~|������G���L���C��*,Ua���������o���B!����*��h��k%�u5��_�����{�E����m3���k}b��K��'���*��6c���R�T�\��m=�$�wX���!e3��:�����i�]��ZK��4�4��@�+���Bn������S����X�z'�^}m��w�[���o�:(�K�%
��O�`�Y�����@4p5q����B!���3"�jI�`�w�(M�`BIM&9[O���Y�F�|�|�~�w�_<Zr2)V0�2GT*^xd����'���rf�\f��P��b�*�xM�P����(
��
xj�!��
������s��H�6��'�����w�����nI�O�OU���-��
���B�s4@S (�f����#�B!D	'�A!���0�Br�����Ih_������Sg;5%�
 ����]M	���qHD���3a����44����BJ"h���/O=����ow����*�y����%�R�!N��6�1
�����id��/����K�_�8���	0����-1�����C�����:�>���#�B!D	$��BL��z�n����O����(u+b�'�+�1�$�'�.r�?W�A�HKJu�%f����FuO�����7�V<�
T�	�'#��s�=�fVn��D��#q�V�\u�[����L��k����E�!������{aKL������^�����f\_�V��0��	p]��N�;�s�E�'5[�F�S��ql���n���m��cN<����!�Bq����B(����]�,���Cd��%���I��M����ji�����x���XN~��]'\�� ����5�����]���T�m�����p���f���G_�F�k���6m�FjbG����W���@�k����|��F��q�ckw�}�
��Pds)��K�%�z+�����x;�o���*���>
���3�2
p��UxK�����V`�������3T�F�%�~Pa�fK�iL������z
���5�!����zX��*��`�5�D�4p����%
7h�S�(��-���hr���M!�7�+B����7=���_X�8��U�7�Az���X���+������a��e0�I�.GY�\�'5����~e�}���
��e���.F*��jF���p05s_��(��K+X5f&��	�����c�C��V���������B�����fj
����,9�j�a����WW D�%�z;q���}*��B0P�����V��^VmI����������z�X���-QWI����4�S�G�}�����bi��w4X��Dl���{��|H�U�������|}�k��yq�Fdj\!���IrP!0|�]������(~���(�Nt���6.�����wY�:�������V[�9�4�<:_����cwv����m:2pi����o�&��oP�{Y\�y<�K�y�����y�e����.�)�l=��l�,p#]Y��.������D�(��#I
!��J��B!��p�7!(	D������u#�B!���$9(�B!
��D�$E^�;�Xs��B!r%�A!�Bq�rK��tL��"/�	?w��Z.��B�'I
!�B��n��U9I��(���-(��B�"�A!�B��$���-�sb0��`NIBI
!��V����2��Z�z��>�������<3������]������n{T��m4e?�`[����o{��2�y�����\����4�����5{U����d�o_���Bq�d6V}���eY���$k��e�����������C��M�4��C��i�9fp����iNY���Z�	BI �>�J�)��r*�(Y�+��.��vL!�(��)E����^$��������G���Hz��y��B!�%P��������������[OF�/�����������B!�M��98�|��wf�g�m�����;��,��mt����3�c��o�YD��1�:���I�b���=)��X�=��R+cV9��7f��dQ���=��2f��}�s1��������"� ������=-��a6�%*)�.��:��`6�W�f�X�����9���L�x<����O�[$�G��c�y��b6y���TX�~[�J�.��O�ufO]��+��W�!���_\������7Fsz�9n:����k��9���=q��1G����>�^�Y��95$9A!���/�.e�I����I��Qb��`K�|���u�	�����x��??	,mm�9��P�@���^�5,���c0e���c["�Oa1Tv������[�qD\K@��m�a15$")�wC����`1�)�o���-��Y<��>�`��n>�������w9�b��������{D�1,>��]a������`�7�����yB�.7��x��\�����������<�
�)�h.��'5�� ���S2�P�| �
!�(D�Z�^�����^��(Q�A!�BQB�'1��O���C��.V"Y�[����m�!���5��bO:�%	B!���HrP!�B���_N	B��A�AX*(.~��s�'����g��{�JJP!��!�B������DW�H�N_g4�?��[/@��i����������h���������7�2���mK_x�a�����L����f{�:�wL�X_�<Qd�Z����o�'��}��;&�{:��e�1!�"7�B������}=�"[r0���]�_��z� x�Xa��7^Fg�u���5�
�������Ei�u<.{j�]�%G(�B�J��Bq���O�u��;
Q"��|`/o���p�{�q3�$�������])J��kKqH�S�O�B!�K��B��..��Uom���$��Rw�0z���X91�>���'W��� ���?������U��mfI�9�l�r��L��#��	��U���h'~���_q"�@�]
+����6NE%��!��ty�/��*g�g��O
��7�
�>�Cu�A4�x<`HWx�z�����`�N�u	b�P����B��Kp*�\���t�{��J����pI�*m1
)��D�s1�7�|�����%9(D�H��T@�m�c\��,�B�I
!�[4�.�����o�=�D��_Y3�m��^e�@7��5c��9�i=����q��S�x�":t~n'�J��)i){X���e�}����-��^e��yN�=E�5
�*��b�N��V��v��?@�hQ�v��y(W&��2z8��X
���>����`�!�:���-0c)�>��m�q0i1l��1�����6��!�IMqks���ai�����
QXT@�e&�����.��#B!r$�A!�p�v��m%��]�~�et@�p�'������A�;���O��I�
��������	�0��cP\O��K�:�=�5��Ps��xD��]
���@�V0h,��;���
z:�o���Spg���C�_��aR[��MY_����l�vo��xkt�����*Q%1x���;'��U�}B�>����=F!�|�s��G�B!����B�#�,gX	j[���wN���v���Gq!�X����fE�����������K7��J�K��A�`8}����.��}}�A�7��[�2b
����R�EX�'�Z����!
@��O�oUh���|�|�(5���x�e�9x;%�hV�^�O�S��q�k{�c��;���^�|su}e���16!��&����ZI�`09�T0x��$��Tl��J�����D��k�a���1����Y��d2�n{�dH�@K�Y���x�?,y�?�|�Z�I_5�~��J�vj
�h��2�Tp1���������q~�y}=���+�v�_O|�����!�����cY�B!�p"�A!�p�b�����Y@���D4OF{�P�9���PS�71PgF�
a��7x��lx�i?~��%���RIt-1���x��i�!2��P�,T
kj�����Z��N��m�OL�`�I(J-�}zbFs��h�\$��G�7���v����qe���
�M�#���O����xa�j�4�h��_HW�����mqh�������
?�Z�t�1�� ��}�?u5�r��%���W")��K�����O����0�K��kF����x�������hU�1^>���k&���X������C��&Tj�s�\�xe����k���V��S��������o8Z��V�S����ZsLP;_�B!���$���XO�����I���]���gP��	�P�
����HH/�v�G\eN<�{BZb�M����)�ydo�P�v&N�6�D'O����L*�s*��� T�����Co����+����bsn�S}9���
������KP+��SP��a����U����������\�T�����	�m9��C�.��r���5�{�{9Q9��%����G�����,��m�u(��b���l��]�����}�b��k	�~;����u��t{jWsX|%��/��\+�~�>���K����.�|M��c�����xT%��R*�=G��vR��Y|��x�^]���s�x �ms^���}X��g��=��1��'
�.������9�����2O	��q���m	�����|����}�	!��m2H!���Q����>b%�_4���2$��k���Ak�<�:���������]{������?�+
��T�>��Z&b��]��T)g@X�2�=3�hq���o�8a����	a�R._!���q�j�����4����A��[�1+���~�j����jv����
����<���
���������H�
�L��C�;�t�\�\�$��������ZF(W*�+����z��_0����_[�/������&-��~������q���3��� o7y%\������e�r��Y<�����������N�"yz�W���.C�������W1n�
.[^f���S��R�T�b�B�&�ic���W'�k���������}:N`��
$��<�*�/j5�%��gi��������O����6c����t���&�y���i?�;O�;{�*��=	�S4���e�o�xq[*8�`�h�����������q�� �qma[x$�z�m��,J"�B���}�B����m8�������Y�y2�Ro�8z������/��<�O��2wry���m�Ys��>#5&�����*I�������C�w������|��r��:����(|�E�]��kl�K�5	06g��'i��`�m&��?�4i5�bU������4=��%P���L�t0r�(k;���)���H�����]���Z8���>]a�J���4<���/��;�0����,B+�KC��o����}��L�*��BXE�E���s���V�=uT~d!�=�CI��)S�h�z��|�����qd��r<�rv�R~�jf��aY�yP�c���e|�1���m����q�a6oO��}
)g�����7W&�k�+?�%�����Yo��mY����2�fj+����k��K���l�~R�kE�jADm����0�6��L�:��{y�?�?v1��t�8�i����[wqFmLxi���Z�m�~�dn*�	B!n�$��m�����s.��S��	<�����qQTonM��Z�7{%�����Q�G����4�#bc�n\�-�R�����C�������5�v�q]�#^/��^�e�����SY7��^L����NC>�%(�|�p���^>}+��%H��t\����H�nM��n|�U����U��i
����x���,R�r��BX��C��m���a�z�iF���)zs��M�����y�.DsA��Q�C�RW�
�
W�]"�����HM�)(>���H>~�����_��6�5��i4�yLiO�@O�9"Oq�J)L��q�5��-�A!������B!����H��oZ��Lz�8w��w��n[�4P����0s:����-�����2t����������K_`�q%�:L������H������z�8w��_��B�fui�k4���'e��x����u�{2�6�������m��fF����z�uv4�������d����X����H(������J��!�B�9(�B!��n0}8q�s6WW}����b����^5-�4���'�s��T�Y}�!v�����p\�J���D�9.���L�4h`_u�i:U���6|9����f �^:HJH�r$��Gl�w��U �SD_�����q�B2`oG���h������O��+��8V��6�<����y��z���#M������#�z�x�������4v��Xx$�^����3�B�I
!J���?�Tn�e�h�Z��oZH����������K�/�<��*���6��8� IDAT�3��bX����0�?�t������t|y�^����C%���&��u��dtq��"�
�'�c%=z�6��O�^6�Hap{O@���c\6T�F�]`S����d�v���?���f�7���z����[����<�a(�Y�=zP���QS����SQ�!�2U��o�������B�'I
!J��s�eq!�%�;���r�.#qG>��������k��V�c���Q�V�V� [���!�����������yftV�B���=W���j�����zR��rj�_D��7�1aTg��j�����[�rE�My�{
gd�Q|8v��o��m`����)�4d���|��t����
c�a�Bv������i��c�7~1I��3��'����Q�]��|/����_h�J][B�z��_�r��T*��9&�������3B!\���B!�����k9�q������r�w;f���V�^�;�=�-���x��J�v������Oy��T��o$?�)xx�\�:-�����c	t�9�����0>���/bt�������x����w.#�X���^��9�	R�T�6?�O��w�s�eO�;������N��u���b6s�[���6�1��1<��#������i,��,
`��7�?J�wf�}X*���\]��B!���%-�
e�b��J��\�l�+h8y��+�}�!$�>}=�}�C�&�{s���)<�6���g�7�:�V�1�!�z��:Y�oW?s���[�qx��]�(�7k��
�w����6-XV��M����i�N[���i�{UCSUT����hV���Z�h��\���~��L�{�iY����#q���%u\}RU�����<����*�dA�sn��H~>>2���� e���}���d���x���y������i�2t��O��n�X������V�}$kQ�k��7����25��r�Qt:tz=:�E�C��n:�b���Q2���T���X!������ER���V���_Jjjj�����Hz��y��B!�%�f�x�~SU5��j�f�����iG�o46����7�3��gQ<��r��'i��5^��3�o������M�k������x��V�'N�@��g��t�l7�� T��N�B!��T�=����8�sf��Y�[<����3n�5��V���v����=�c����(��1�9T�:2�JM��S�f��������%��9������f��Wa�_�i�e�R>�)��Df��euE��Q��#���Z����/������O;i���BJ!to-�(���
��?�rH��w��b6��(��J��8}C"�_(�nK�O�f��U��y�8����k��p�����
����Y��K��:*��
�Mg�����z��w�L��R�����M�z����MI���KP��G�!�(Y��t)������5�b�vl�-@D�-X��*�Y&=�h	,�������Y�F,�&�RW��M����z�hD�X�m�����`	hw�L���X��H���T��sa�3m`���ZT�}�6�������6T}=QX������"8|C������oE��|�C��H�����>���AQZ����� �PMWL�+4��f���B!nk�u�3!�B!�B!J=I
!�B�.�(�^���-����O����c��;H-�X�B�RL��BQ��X�>Z���W�/������w�J���z2c/�?���23�W������!���6�
R�(*��)<��<�j���v�q�`������}X'W�(	9��~���=����Lo�����e
H�����`���\�9��H����?�
I�>7)��Z���go���
��s���l>~����B!��$����1����A;-� ��={S�7�6�%���rHO0���_���x������Vw�+>T�U�Z�@��u	����03uj�PD�*ZO����_���n={!�B��_�D!J��������Py'�:C����@�f���)�y�|�"�SB!�p��B����G|�t4���2��d~��?�3��Y91�1�u����1R9��}L�+�
���%e2�o���=k<S�2�{s����{D��_'�����9
[�+@���Y�y�|/�+<�g/m'.[u*��gy�1�,;�5����}�K���IM�/��@��a�12��_?���e1���_C�y��]x���������g��}�|y:�Pd-��������0�}��_f�s���<{����n<�,]�@��a��d�`,
��#>����]����!�����pY����a�������ep�B�:F|?E�����xD��b�:
���������~<����Z�?���AhCL>����>��Z��1m�b�w�C������*c�����z��
���0(5P�:���V-�u�=E�zw�UO�6����4�o��G�#I�8?�}��yXcL�������h���������$__�l���A�*����\b���z`��&��w�b���Kt��oSC*6~���#!��������Wi���6��-���>������^dQ��(J
�.����X����|w*����l:���
r���]a���V[�jc�jN�VO��w'p���e���i\�)�>����5�9�>_���/�G���x��]�;]����	�R��Q�;�k2�uWd��Bq�H!�@#q��|1f3~�`H��$���5�����6C��H3�����;���e�Luz����CA���2�L�\��%���U��G#&b_�<M��O����������4�+���������H�:�;�����_���L�����'*�_�J�c���^������;F�����h�^�VB�>0�������������-��
p�(,Z	�apO ���H�8Ft���[a�
�	���Aj�����:�NZ`Q8�&�
�@�������pw{h�Wc`�E�� ���O�3��N_����	���*o�s��h(S�jAz8r����C7o��E,�}o>F�)�8�y��T@w�j�`t�i>�wcv�c��w�����������9��k�Q����-���`�W������9�5yT���,����c���S�����^;��_"�S�!>����H����Q^��yj�}���_�������q)S��|�.b�V&��o<F�W.�u�+|���S�>��#��~���C���a��}x?6�������,~�-�K�����������3�����r�<�.F2��X~�0�_>O���|�����������S�un������^k�R/���������;
Fg�b������?����'�z�F�m��c��:�7��K�!��1�W��s�y0�M����P��i���m���'���LS �B�,�B-��6��^F���2:�s5�}O�r�b�'��,�b���	����"0<�uN��������?�oF*�7�4�?���wOl����q��{D���^f��U\j0����������;����q��Q���W�j0��B�"�9+������PS��zC�����C�n��^mn�$P�_����������N@��0�(@-
�]���'�zB�7�f�
U��Z��i�v��������h�W�����Og�:���?�6��l��U��j�8������"�6��n5��G�����n*���e��`r8���f�������z??�k��\j� s�������~��24���.Uu��5�G7������b���`,_��
je~�Um�M�Z��[K2rj�����y�q�m	���*p��H�/���E��|�.bp�1~#s��M��_�������KS�N�`����=dM�S����]|���7���������ucW�zd�I��o�V����b:2�+<PA�a��D������tX������-���<�n��|�7�����K�������<��u�j���|�1V�_�������u`H={e����G�k/��N`z#�"�����kgqoxM�(�B����B�����4���#0�]Q	 �c�}��PD�

:Q�k;���g]���xOp��Bh�:�����r�0�w�B�t�����0�-e3��z������c��(C�J�J�|��sh�.��|��r�'�P�cu�?��a(\���I�����2�~~��
~l�P�{%)���k���}��B�Ix{�����W��g�;Z���;��t�6�x�G�����$Alb�!�y�#�T��=�@������T9��>N����_f��������c'\����F�0tW.s�����nH���=��Bl#��v���k���B	���>�#{����4U�F�r�������������������N�����{������w=�C{�yM����M9���b2��d��o��8�r�3��@'y��:���������=-9�a�����2������\��3����BQX���B��$]c���Lc�JJ��@Q|W1���=|�d�{�/-)�+��|2�@+�xd~���_#1�����0c�CU��U3��AE�U�x�����b!����]�G�X������Ih��:�O�up�u��x���e�y8%@sHz�m	/��t7<�	0A�;�
�=	5�K/\������~�����P��D|�����EK�P����
�<�4�+.8M���(
:��B*�9������I<�@��"Q��SG^-���#�P��u(h���i`h��Lg`�c1��<�����, ��X�F3*����3��N��=�{�g�<;�^
g2���B!n&I
!���$�:����������TtJ�oPjJA����0�#A������n����1z@rB
&��=-��$�������I���N����f�<^�$8�^��x�w>����e�F
�v����PA�4�-	��m3��[��H��1@���[b����
�a����'�%�����i�`C�7�J�R�����P�&��Q��>�lZw���z�mV���U���}}|m���b��$�v��{�M�x{A��k��KZ�f~��J���T��\���8�-]}�v/�
h���� �gc����X6���Z}�[�>?���"���42���I��5a�f���9������f6�5��y5��hql�x�����	mT�Pu{O�eR����&������L�<�^f���J��N�C�;Y��7���������O����Bq�HrP!<�����6 F�a��O�����(
�bP�
���q$�PV�����4���B������go]��4j���+�Q1�����u`��Xih{3O<���V�d��TsK=������E	v����[�Xa��A��\:�o��\�����z:������F�/U��ga@M[���p\��B{��y�C����Q�N���F�����-)s�AU�Z�mEf?�n��ga_*Y'������O����g���)�R��h�{�`X��L��=O�y�J��[H,�}��4e��6��aE�x����/�}���-*�|.sB������3�������]=�s��EBk�y��-���;}C�e���������*G��d&s����/�NLx���gD�k���U2i�����
|R���I�$>��_t#8�I�����c:�&��:i/u�Z�~>~�C���w����Fl�gL�O��&���`��4:�3���o?����	O������kX��	��4`���x��Me-��ZN��lL�p����.�#o}7��_f�3���iwB���BqSHrP!������C��|���%1�{��3Q���y�t�Q���uY������_����=9�/Kp/bW���>&��7�*O�`KJ�Bhpom"���j4�#��4z��^��M��h�,����KZ�<]9���m���{h;��WJW����
t��?!�[�d�E����p8sV&��zY[�|!�6�������~P���z�`tC��-�c9HM�cg�h ����0�
��	�����&[��k�������88� �+�EJ2h��o�'��B��	'�`LPf�M��!��#�n��p�4���I
�#�a�Nh�����_/=dK��~�/Ao�����s
*����li��_���Y���f��o����LdL=w��|�3�5������`�W�?1�{�Uv�t����^���Mf����z��N��|��F��w]�����'c}�c^�5q���
a��R�P}.18'1���E�����N���dj���O�`�}nlrpC3&-z��c���;��#�6���L��=Y��m�Nx���|����y��o<L�\���J���_���ak�]o}�����:�zT�����{�\��|�E��x��B��/���7������o0��R�^��xP���:<�����m����0�OS�.����B!
D�
!
^=����2�K�~��G�Z�{{2=e|1�h�������3wb0�����^��9�g���Gh>�K��OR
�?�*��j�b4����_�����}y��0r,�.,`�}��!�����h�)�����`�wA�6�W~M�!���u�5�+�2�S�S�	��3��0�-�T��:�����W��r����������O���k���*@�������
.����a�/������$�
o|z0��%�xV��}pZm"
�C`����N��B�Px�/�vH�����A��_�M$\��Rmo��&��9a�������8���/n"]9:>;�?�uq��.�����T�^3����G!h�"�Fe��W��[�������m:�s�b	����9�~\��\��B`�|�iD�%r����5$�tl����f��*
����]�a6'=�cl������c������?�fv�Qg����1���.��e+��G���G\����?b*kGL��d����As9�g�P!�B&I
!F��}�Q���eP�1u*�Nu�ym\�WkO�5������:�,k��,?o�<��>�<O>��s=���C���s=����27G�Q�R-x�V�Q�IS��4�6/��s�K��8}�A��d��`�h�}z�<&����an�<�LA�Xx,���U���N;k�?!�B!JI
!�"�����dhRL�������>W!�Bq����B!��;w�������f��*�`B�
����Bq����B!�+_��^�Q!�B!��,�'�B!�B!D)%�A!�B!��F����y��,������g�!)�S�zl	�C���G�Q��	!�B���uX���\�c���Mj�2��/��������Q.�BE���|LW>����Q����S�"eVCl�������WT��0��9��O�,�%�Y)����EZ������[��P��C��M���C"o����XK��l��������fU�T5���fU�����J�T6��8�������������03uj��/���rT�]�/n�C�W�������Qt:tz�Ng��SP�NEAQ�����������B�����K�<U1SRSS��
DFF��g���B!�(!4M�v�i��f�;��V���w��M��?i��)���b���P|��
�!��1`��C>66��R\[��������@����~��$����w����=��-g������������]*��f?�����h��b�@hh(J����B�Ht�$����Lr/� B�t�9|����!�{�s���� ��|���q��w��e���q���y�d�������O���_��R�1��C����^q���c�wY����P{"8l8!Q���:~n�,/�8
���K!������F��(������O�v�oS*$�?U�t[��dO�~��{k\�B�N�j����y�lG$����c9��,������q����k�r8���`�w;8z+�L�h2e>��� E]a���LY}���N��P�����iIW$�xv%�����w��<���
�2cf�zJ@�O������*CvJ����aEQ\_D�B?Rd���T`82�����f�U�,���0��Px�Q���4P�=�� IDAT`�����A��,=fLdl�,(1sk��M��s7�<N��_!�~����+���l[`9��������M�5�.�����C(����c?|�W����m���~���n�� �/&����3!�>�D�t#W�z�v(�
9���#~�Q�aH�N���������h (%K�H�7%�*�
@!Y����O�XA�r��t]��V���R�%��y��1�4r�����'��"1�RK
�����R�%�r������o�n�����Rf��W�i�4�zL:xX��\�����j)�	R�M�r���v��|rM��gi�i�������k��{/H]2U�-�|G"#�������T�%k��Q<���Hf�;,n��^�<�{jd������y���K��O���y~?f�����_E����4t�T�\Z���
������8v�����m��|P�8��:���4���<:��A_��H�V��8������6��'Q��LZd�yr�(�`������	;��	c�S��"�}WkBJ]��-n��
��xJp+��
���'�G=&x�(6�s&l�B�w�@�i#��fA��������������eV��A�.�?�9e�r��m�����EA�w-���� � �G$����![���WG��G�3i��v�gbKM��J�xR�+Sg�������(\���P�,�����}�����G<2�R=��J�!H��.��1*<)T�*�P1�~9��B5������e�V��gL��fm���O�z�,��jT��sk�����/��;��XI��|��4+NQ�A�O;�O�U�<��e�T/�kX-:LZ���(��l���]�(O%�K�h��/
�lQ;:/|����~�AAH'��AA�_c�v����T.�(1f�<�mejTuMh��R��y|�<��f�������S��@]�_��Y��.��b����l,:efr�(�z��X�$E�Ld&�����WI@���5\��sv�$1^?��w*J�7�A5
��v������������3=M�x���� � ��2Z�4��������[C�2���<����%��b'�<{�����Z6`d����Y�Q�2�|?~�t�'����bM�F�����9�jG�>{@�C���0��F���wQ�Oo�������b�aP$���Y��z�a��nJ�e��f�X9u+T�� �����?�������A�kQ��n�AR(Pb������MF���$��d]�kH
	��Ivvt'�r��U��1��mO��AA����� Bz0��ru��A+e��4_<�����n�<_�
�'�F�tFI�{_�]E/��	�S	���L��yJ@V%x��r��a��I�
P�9�C{/&��� k��d7�c��������{,���iG�Y$'���`��_91�!?-c�C�WF2)��z��;�W���$������� G� �
�TP�bn�w���{�����?���1-� �;'�AxOIrP�,Z	�Y�����}��������[]�:[K�W�BZS�`�����|��P��mzG�fnA���jS?���/=������R�����56��W�M�J�,��>+���p�W/�$a����(�
W�SN�z�I���n�hR��O�g�ggj�i��JT$AM�w3mRNZ��Aq�w&?�[�����$
�����
��.�>E%�<p�V�$���U2���
���z��rg�B������m)���� � �[��u�or��dj�nu3|�$�L��������g�c��F�O;P� .
��`U���'��][��
H�Wea�.�W��a5�.7G2k+����99�����Rx�-/.d��=\=F�3�<�nK���p|y�X��u��6�(a!�H^d.[������r�o�Y����x��}���bP���@��i�F0:�?���>Z��0py@k�>������F�����p9�J��~��@�{�I[��+�(P��`4a�����6���|B
�^K��w��w��:� ���H������h8���2�3B$PM�`���Y��q��	�;$?
�i=,2�u3�*��#�QZ��0 2h`��2M�ar4\W�
I:�{3Y��ca�	L|��OU��B�O|��`�	�4t�q���Ti���w=�4�]�PH
����,���`�	����Bu�A�4�2�7��G�5��2���]���d�Oc ����&�69�d�J	��p�������Y4	�i�����*@s��FX��S&@��*�q��}�K�9Rf�b�{N���Sh=5�}(3p&-���m�2��&���^L�r$g�������;m5>�������g�*��)T��V��@f����;��0��>L�Q�����U)���j�I�<������q��b����T����w�a�>:����RK�L�*�l������_.`����~�G�p(M�%���[4�A�������p��o8Y�6����?��e������z���	;��	�Y�O��(2��h��l��'��k��0����<�.C�������`�:��s�x����f��8�
����[�g.N�q
���"��a�=�_�'���`>��>;��[;Z�����;��H���9]v� |�db��c��C���J�Z�9��]_�$�e-z����K�[J=��}:�+F��GNH(\<'��1��d�����p\�J����-y����1������~��Wf5�P��]�0|�-�9�\
���HVA]��-����#��a��Ul�8���z(��Q
xh�E�����
P)`����n����H03��A��P�a��aa�h����xv����@!	6�,�U�����M4PA��p��$$�2L���
����P�4Am�%�v�T�G�u#��'g����J%Lw�b^?���0��&�:)�+(�����S��%����F�<���`�e:����SKEF����y��]g�D���/�Pg���������L�_���Ug)�������_-����.��v�>m�����rn��\�I{�XF+N��?�����$�'�"n�m��4`
���F��(�$e@7��u�k���?AA>:"9������M��;�i�K[r���3?���<)���?6$�� ^���]���]��C�%O�R8t9��;�����x�������9lVd�E���(�+A�|8�\a��}�����j	�Fim{�W)?��}X��2���p�n�DH��U��$��2v��.�� ����\�i?Q�:�yt]2(������������o��=�v��l�`��Q-�t��G�,�&��f3#���XR�V�3mF�M�=�r�%��=PK�f��_�� ����.pPBO8���6A]����#Tr�v*K9@{�L�Y�����Q�3D��/h��L�s��F�����Z;A�Tl�����
�U��h�j�VP���������]y����V���	J���&B����E=F;AE�����	I� 
�,S\����	�mN���������
�Ht�@v�R�V�593X�w�������i��MQ*��h���,��#p_ey���r�AA��#*���#�:t
�3Shl;�f��e�����Lx�/����J2�����[�b9�u�\���78��!f�t�nf�P�\�jI����'�|���Gy�6[O�c�qa�,���D�N���������Eg�A[�'���r+�����km;c�����l��la<��9%r��E�t���` Xe�V�_?�O�N����d���u��%F���eU����$����!NufK���6�V����fy�	.�P9I���Jxb�p�iM!�	��Y�Vm�
"	�����u),�zng<:3��l��Ui���o���
K3�o�p����q�Z�N����E:��d�(�	�"a�r����OZR* ��s	�R�.Y�l{AU�AO��$����4AA�w���-�S��-L�"�87ee+5!����M����	_0~��BfL�/�/d���1Ee����<������	�H��?�$W-�����	5��E� �rm�$�o�D����^�hTf�|3���M/���%��z���sw�k���q&K��4�L��,���c����mG�7g$C,:o���
���K�HR�~����o%u+GP~qm����?�DBb'��tr�}]���2��a��t@ii:��:M��jJ��UU�?����9"g��d��v���--7m�C�j)��}����0Dg�!HC���g�n��$��}�c���� �u�e1�8I�m��%)��,]*�O�!
�����4by����?OI��M�AA> "9hK�M��C��������yv	���
���qrP�7d4�k'�lIR������"[�
dXt�s������l��[&H G��3����)2N8�J`���md��kj��l=����9i��27kG�f�0G?���5l��m������)�Y��R8����}y��^D#���X�"i�^�!�� R�!�/��1�-�AH�������������d���*$��H����'Xj����Y�� [*��NR3-Z�����x�����.kr�-�����-���0'
*�����/�I���&4C;gK�����C�l����������0c��(� � |PDv('�J�y��`PN�Z����K�J*yr%�2���dBk�;]Q�"Erf�j�?�K���^�p.��L���_J���)��^�F�z�x��P������V$P8g��c
�D����gG��g�{�~�\��p����e�cAl(}������s������	=z�@��8��@x1�V�]�H���
���vW2��O$�8����m�y��W����7��<����J�����F�?,#����F�P+���2�PX����r(.��0K�0�
�`�>a$���g�'6���!��2��=��o�iSB�1��RKJ9),#>��|b�(!�&��m�
���@�	.| �:�d�$)I�41Cf�{�C�����d�I��S�����������u��T���W����u�i��Wn��#AA�����R����T�:����wKc�:xQ����h1��M(��/N������Y���krPzS��?�F\F���5�U��p��q�_�[���<�/������]V�����_��\�3�"�6IF�+����,�'c/����k���c��*�s=\�nc��x�����6��D�	�x;nC�������!y��S���f�h-Ujg$��zvr$����~x����C�\�Z��^���2dIR�2#����}+�k:��Q��=32&\i�������hd�;9�`�9Q��
��?}LL��p�����w,������s[�<����xka��sdUo����������v�B�7[j�����ex [�1�%��g*P_�uP�	�?��#�������TVZ��a�
���Rn��V�lKS����
*h��k��&���
�`�����{�Q@C����@a,�'����`{�U@YdN��=l����`j,tr���5Z��R
*%�`��h���t�k?���R�Q�-I�3<�,��)��Ix.l6��e����4���X	4PZ��0���<�f�����X���L�9�S�ngw�����
���q 4����z��+�#s��~9��Wi��2��
���n�{�j�Me��� � �'����8�R���\����s��u`N4�Z�i�;�O�����sp��@^����[�s,	��E����YI���
�C��a��.��^�������[�z(6�O�`u��0yd%W�f�n��-������M84t+�f4~NB����o�Y\�{I8U�E�il�n	k�C�����c��0�����lk�c���L���)_��"���H@����|)���%�n'1`l��-Mg7���&$�
�g�+���-�������~�M���=�1�T������AH2L��C6�������d5�u�y���U�x�,Z
L�`���YF�����JK����o�4����[
��07JkS6H�J�ab�e������&���x�8��8X���tq�&�i�s*`��5[�y>
��	���CW(`���`M�ep�T[c�`�#L�A=�*�����v
������l���B������RX^u
���i1������`�6Ls��0Sz	�PV���K{������������d�{�&���4���~e���0k�P��]�����5�l�����������qI.g.���mmZm���S��*0��r�l����'��� � �y"9h����!�OSnJ���6S�T��&�?yKi2�����(�j�$���$�����>+>8��JPsm	j&�Z��6�4���d]�������ed��'��)�� Ii���7���~�,�'�Od���+Q.�Y�9�RmU�'}A��rk�$�L'�,��"o���8F��2����{,�$g�/�>��N����B��N��vb2���:���T'�����W��w���-�����
��)�$��9A��k2C������n:�7vT��(��t���U05��V�u��=�i��[���;�L�����W��������}�U�T�>��
�Xjs�_y�T�r�N:JI<3wW-dy���~a��T��jW,����L>i���]��~Z������{�vS�ty
�l�����a�A�,
z7�d���{�A���.+A�='�LS2q�!������^��a5����A��{`��8o��&X��$Ne>X�����9�~���N�����)�LP����T�[
�ca|����57�:�������>Ept*�w`/�\�s��qn**2r�`z��N��u�t�pft�Y�[?����)�[�sY�L`�]����S�$�XoO^&Qc���J.���/���^����R�f�����hW>O�@�s6�������s�:V���6g������4M����L���u�����H��W'�{A����6���#<�JA��#j�)#!���j��g�&4V(�]�� ��%����!N%�uL<���A����%w*0�W)�>iM�2���SfW��/T���I�Q�	1����	����:b����YP����mz�@�����!<4�\�j�����t�5?�����dL�����]�(��?�Him(�G��SS
~��P�:J��T/~[�o	�Y��^�����&����2��h?��~�B���>�:4�:
V"����yQ^������p'�T�S��S��
�������d2>����[�E�<=w�C��3q�xJ8��{)_��G����1��V�SA��'��iJM���37���n���9r3a�7����M�QM����p
���d�o
��fO�������6�T0�#;mI���o���a�N�����[B��9=�,d��=��V���d��2}�|������-��zq\�j�a�*��@��V0i�����cz}��	���X5|�F�$��2���������������
�9��A�'���(A��n���6��@�
�b$m&���o�J�&�/[�������C)zv��������j���D~��I+�^�/�w!��Y�b�R��y���"�|��~��\/��3���7��=7U�T��
���}u��I�;�M�+� � |�>��lA�$T��8���� |H�J$F;}�����|s��x�fWE�&�,�����kYV���oo.n�~�S�T
.���<�Q��s�n"�_g	UaT�Wk�)2Rc�R������e��)M��F����g����=�5&�-����1���o���_.�d�e
v�L)%:�����,�:���o��g������<�/9�U �i�5��U�����s9r���z�y4�=%�L��� ���$��� � �������8����L�}IR�����������c�$;��HHo�����P���������3`4�k,��,��$c�Gw��es�nxx IDAT^�Ab���,�����Q
M��8���{�Z��m�����I��,/�1�2o��P�U`2!�A��K�&��,�iR�;_�ca��{��@�{�T��c����>�U�Y�=�_F�W��Z�c������~���CD��'�����-�N�������?A�y�;��,?��s5H�0��d���,������l�1�-�����$#���&3�m���KW�8pK:z�$������6���_R�:�lNHUI����
Q�-���.��]
����0�������E�����="i��[F��<�P�nss5T�,k���0/���H����V����D�:G�m�v�U��Y���M��L�}������s�����Y�,�<�*���?�s�T�<J3w���"?�@@��*��?�-S!�<�]�s�CR*P(%$��^�@RH(�BB�$���yy !���� � |��59�u��d��t~���m�\���_����k��~���n�2�yG�����Z'�9��Sz��8�r9;���"U�����B�Z�=���~YA�7�����,�������f2�^�%MF����{��Z��g��wf��-,��?�*z�������8Q�)e����K���l:_�f��2dP!*�L�!�,������EI��R\�J\�Ww�����|R���;P�!���g��������*b��c���g�N��*<�3��&�������4(��Y(������jT(���] }�J�y�J�ja,�����T)�%Q
H9gCj���W8&S��q�+��������z�h�ekf��M��t����V����,���ORZ��
��q{�:'�Ca�����(^��DX���Q*���
E��$I/�%k����� � $xg������:O��*�,Y�����I���-��^]����K�-+H��~�y�b�k��w��WH!1/�����;~/�[F*��2�;�,�B�z�g��<����1�������[0�"�Q���1�y]4�����y
~���=?���Bd��'C�&r�g�f��T-���)��>����o}l6[�e0�-�m�M�6P��l7�
v�q�W��9V�C���Y��SjVa��Z�7�1�j���i>�l����S+�`Y
�~��mNS������=�4m�,g|;k�DUn�mX�v�4f��OL8g�G��5������&F-
�^���7+�e���4�$�������|7�K<����K��_��%xJ���1��PF��K-�3���$��?�m(����^i-yT�EMg���������=�:��������Oj
�b���������P�1r�<��3�U#���?	��#��1#_�]C����� �f?J6)���&a�{�A���I�-5Q(,��5_>�'��� ��F
���&���~�����d�k���$�����Z���C���S\p��U���q���)tv�ey�����^��69�:�
�J�X|�������\��.�9s KuK��%��e�z:;Ux������1tv*dy����X�n��gs�?�%HS��e��F]�sF�/��H�\2��|�|:;�LMhibi�a:;VK��(��/����{t8��.�
�A��������������$���ErPA���B�^8�������-���R�?MAAAA�#%��� � � � �����wA~N����8��7���'L!�W��9�22GY�v�F�?-S��5�Y���$79���r����~��dC����<����_��Z<���&p��n5_#��-[0��	���!}��C���E�F�@��0�d��&��n�W��{w�|~�}y�A����A��0��kf�a�6Xw�ww"#� � �/Dr�]0?#d�Ny������)�t����AM�������{�\����B�s8!��q����~�q�9���5_"| $'���wq��}�f�
rd�,�����Z�AA�����
��Y���g�4z�e��mu�R1J� )��=WF���G������l�A�����%���In��D�,OzG"�s�!f~5���&s�I�uc&3��?�I+?a���t�sI�LA�� Uz�����/s������F#yd!s�zT��������:�3;������1y�"o���_	\@�v~.>����^:2�;���0`\	�v�b������L��78��,�*r�����*�f_!��.mg�����M"���"�{?j����u����,�:�P��?�N���	���i�O��Q�G[�#�di��f��1��D���L�o���`L��3'�ar�A�1���A��&iF�������An�������R��?	�D��^�t�.}v7�K	`�r���}�)C��@����gr9�e��A��
����8L+d��piP��9�wK��N�C��xs87��e���<�y���5�LI�1u�Wv�����O1y� o�O�7���{Kx�m��e`P������f�	�����SXx"4��
L�������#,=zh��9.8������#t��-�

a�rd��*[��/`�0�T	6�m
�M��93`�Y0e��m��R6g!o�@����`�0xB�pyx|�J��>D����G!4<��t��2��tw�[
�.�c3����m�eN�����{�d<7�o�������jw<�2���a�x���u,1g��l�	�F�u A��`���x�G�|0����	r�dyX�9ln�sPq6T,{��B
��=���U���3q~��BS�i@&��_�@�`\�!�����L��7��u�~�$/�^`���H��].��M���u;����IA�?H$��W���]h:��UMxJ��kDD�/�����N��U�D��������)��N��N]}Q��h�&��B9��s�T�L���Q �p�`gb0���M�*0��G�Asu=�t�z��t��kg�O����g�H�Q��Rwa'��
�W��l��H�
iu�*F�a~�������������K+Y�c;J��]��H�]�uw��?���t����1B�����^dbw.d������#-?�H��_�5h,q��h����c���N.���.�ZN�J��t�o��*\=}HJS��Nv��H����dO<2�?�b��;�������=g%�QBI�c+X�|�����,��G�7f������GT�x��R�;
���~�+{�F��.�=�B�"���a�0��EL�h-7B=�2�Z��A�F07�9S��v<t�u�����M��'�Z;\au��%.�u0L!`�lp}s�2lX�nB�PR���-�U;��!p�7��tn52����7l�	0?�c��|�
�k��8x���7oA��0�!x���a?�'C#�����"|�7a��K�-IV�/���p�?���^0&��0}����Z����X�r,D���n�������-�Gm��	"�Ad�\����������7�q�����_���)>3A���HZ�/^���M�'��y���`~��YkyR�;��u$�
�^�W��dw;�'��	��N`����n��������<U��FFw	J��F����r+:����wN���@Z�nG�b�.6`���[*%���d��>j�
�9�����dq2��T�5�<r	S��)?�L�����'��ZN�r���B� �k�./<HT��t�Z�
 (7��^��� �M�i�Yr���L�8:H(�=�����w��%�UYv�o?7��'���w8��R��4R	'	���_�{B��1?����<)������I
P��[������:�C��|�� ��������0��@��Pz��J��.��u�@�r�r
�������`�(��6��	��PX�:��L�[�
��@�*0�O�9����	s.���K@>���A����#�,;
���[���	�������MP����Dh |���S�`��
�Z��i�@;�����tL�\��p��������T0���(�0��nV����,���d+�)!SF��Jpp��mjo�	�i���w{�Zer������a�Lf���AA�U�Z��: 7������n����<�N��[
���0%J���e�?I�Zo�\��v��u�"s�����E
t��ra�W,�R����0���7����9q)Y��O���"�3��#"0��}�*��g�u���1�{��xV,�G����N���������nV��D��_���8)oO<q!��"��b��]H�W��~b�Un�0���<^/��J2�������,�}�r�H��'9A�GY����������������p�u��\"TB�<��<��u��.A�9��!�/W�b�����e���mx,�O\(\�,���b<�A�����z�>������V8I�	0����Z�&i����)�L�U{C�N�
6E�����7�-{)}��s|AP"?H��r�I��IN
pq�<�1��U�X����~uy����J���qw����$����������u��>�P��8:��@�Q,:�r��cb���p/���9K|�j�>����S�$�Xo����#�k�(j���!?�ne	(����Y���s|��E|K�u��6cm�n�*��oi���^��f�NP�5����,���G��4Z��e�I��gxu�����s��(�V�m��������}�uhJ����s~��"x�����'��O��g�d��9K����7�9?�?%s���89�`��G�zx��%C����T�[
�ca|����57�0^bt��dh�;���?ZG]mq�lx�����	'����s;v����� � �Qs�JY��g��p-���=ndi�?�MiL'��_�7rwJ[�c��l�$�!6���A9:��=�qrD�c����}������Y���r�FS�Hf4Jwf�e�S���Q�7������g�8{�����0�	���w-�!�������4�(���e�N]+e��q��M���6��\��|���(b�&�����q6E�fL��/d���>8�$��%jt��Y�}�;�3�������7��/`�M9�d_K���D�*+4��#��^��\��/G�8��bdP��*�����v9�K*��7�C�bM`�	���+gh�&���1���k��c`�$��	��
g�fM�I:�|[<�R$�'.N �!*�������
@a}s%	����&��.��������\>x�����tvY\
�9�z![������l���K�t���@O��Y#80{}j�$��R�������9]��k�P>��{����9�@S���o��-��5+�����z<�?������D��n?������Aw����D�u
[���K����i���Y�/�6�'�����l��Y8�(��+��s���������	s�I��P��DC��oN/�g~a��t�Q�#C�Q��\9t���{�����st�t��L�S��O���:�����L\]
����s9,��w�h�}����g$G��dL��ed��o��+�8�MOj�zL��Ql,�L�������FV��Cp��L�z�����WC���������U���&�?�\�R��n�gYBdA!����KNdn�����c����
s�<f�J��s��H�n89���l�k8%^T���M�D�����v��h���������x�;�����j��z*�Cs�[�7(�DnPx_(�pt]x��D]D����7��P$��#c��2�C
(�nY��}\,h���#I�E������q�|��8�12xZ�uv�I��o�d���d�����'��?{�����b�������A�GC�$�j����0���s�K�������z�1��r�EG�&$���Go���X����(��JSh��r�~���eP�(t�H�l�K26��)�U�}��������Of�4b��(9!�\����7�ca�E������K��M�_�OjU��Q�������5k���'�3i��v�gbW$ �R&����Y���C>�D�S��������IZaK�L�+�7������oN���O�_glv���DK*��P��U�ka��8a������Z����s���r�� �<y�#�+��*Q����}��q
�L�@��������.G�����Y���j���VJ�Q��l�����2ra�O�4���
�hml���y���
o����1��e�jV��Y����w�/T���7o_���	Dd��3��[����[>����V��Vq��J�,����q�D��2�?������'�e*F^�y���P��x���Qr�_N�CAAH
��0
go��v�Pn��{O-�M ~��<��?2�����&��K�R
�8�?���7�����r��%��y��������#�G�J�'F=h�m�$G���_qb�9A����O!�_ <�s$Gz�6R���$�<���b��1���5crZ�o��)�U�H�k��� ���=�8��S����,,.�{Wl���y�+��������N��6�<�����8�=��y��a	��n�5��B���p-r����-��?3?����	�������,5�R*�2<��4��M��/��x}!�G�$$�#�����B���m�-���D���g�������Z����M-���pR��b5���^6��S��lP ���U����ZZR��eK�Q{Wd�f�@�+��;�������,B���	E���FyG�:O���F�:R��dJ�F��9���k���r2��*u����9��s���������8:��X�_��>�!w���K���z2����b�Y,=x��/���}����/s	<2�e�>=�.�k�aH~��O>���gnA�R�����h���;���
���2��M����e�=�, CD��:E���d���(����(
��
(2T�F��Q�:������{����_�@r�����\����h�H���'�d�{�����C��F�����W�	�X�������:�N���=
��[����+C�s�W�_SI=�+��V�[Wc�'��wR4(�C!�"[�r3�_M��=~�lWo-�;W��w��^��A�����>�<�e��i��*�7�u�����q�@��M�>U����5:;��G�^O����^Q����b?�)����iM<~�v�7����\�Z���c���iT�}#���P�5�����_�$�m��8:�C���l��U�o^�n�
��HQA�y��K��
��:J<�7�
o���V���t�"a�7l�fO�'����i�h^���gM��9�%�R�7S}Z/|�9��Ft�'���{<}���i�Rk@5��9��`,@<��xv�_��G�hY���i+9����5������������=*��r�[��q��/?����%J�
7oB�
�����(�dg��|l������0}-t�`��x�Z�e��^�c:�����7t	��8v����Y��~�~��o������aqm�W�����W�3u r���1!�������������k��o�d{P����W`oYhW�h`�p�^��:�aW����\�� ������@_����
��a��SW@l!�I��TxhBA{����O������h�N5��;1p�(Z����y������W�P�;��*��m�c�4��v�qc>cW�h5(*����n�
^_e����_���c��N}flZ��������TL���
za�b6����|��Q24�V)WVm��#�v|�'��R������l_��r6�M��0�����5>~�~�q|��SL�u�:�:0���b�o����v�T@QP�|�_���1$�Ksz��c����1���3rXg��X�[�hs�gN���V����smA��!�BdC~��P�:n����	���6c0����YtI�����(�-����k�a��$����KP���f��q ������<p�)�:�C����@��@��'���U�j|1�J�'���{*8�C�?'���9���<x./Mk�VS�z�'q����l�&7*�{����g����9�j_�l���4�?����{h����_f IDAT��:���8s�>ODW�*5fO �Q�{?+t-��s�E��}����b6��]�9.s}��:���|��^/���O���Y���Pp�B�7����x�������0�iv�u���=i��<�lj7�����4u#?�N��
��	�!���(]I0�%�d3}���004��/�OX�+�?Q�a�����A��5K�������w�� ���2�^�V�~����K��v��>��	�_��h5�@��0f3�^6��$�������`�|X�	C�B�BK���>�U+���	Ib�P1����aE4�0o�]	�,�L�R1�7�����i���/����V���^K�l�]��k�����\���v}`j[k<*��O����C������u��T�G��Sxu2�I���w�d��(J�\i40�q���{#�������������\����6�mg<��&%�`�o�xu�IE�����:�����OudD��]|��4����K�MK[9�`�m~�y��N5��l�V�J��q��T"�?������m_�������kKY7�#}�Z��#L���o��Q$s���J~c��v�@����.���b������S(��&~w��?S���fT@X�z�1���I�u-ye5���b�2���
(�t��
��6���;�h��Ne�	���kW~����M��Q��!�}�)	h{~
!�"W��24�O����(����@z��g}��������IP���>
��QN�G�i�RkZ6U�oE�/Z�)�����w��:�vR'�
P��uL����js�eZ�?�nS��+
Q�����s.����d^|�va�eST[�5�l��3���>��f�����+x<7*�<�Q/�.|������7���q��O��QFo���Ls>��H�
����.|(�zh�������	u��P�A�_�c�<?��������
���Y���n@�2�Ext�/��Q�P������������D��x��������l
(��[�D>�s�s�X����Smm�����\Vj�o�YZ�7�`(�������l6��u	����=o	���������:�6����xn�h*�x��ec����|z�>��4��D�/����u������}��S��vCAG����d-���`T]�KW]�<�#�
�@��/2��<����=k�v���t-Zj>�=���^���C4��w��ehsg��?���d������&{����X/���)]p0��-,�����������������2`�h^��
1�������]�I��)����~�'�2hn�����Xv�)sF7����S4�x{)���#��T�O���}����C<�2��#�6|����t_<���Sp��C��3�=������Og��|���@�XT
����=��SW����9�1=C��L�?I
!��&�A!�B��.��uw�Y%pH��W�� x(s�~Qbl���=P@Q����\�x�9$���I�=��������&�4�<�r)��g���#y'���MCy�+���s�v}��_��bL*��4}t"����A�3�8&L|���NTj3�����E|a���_��x��
���S�hr�,i�z�d��I�}��g���;����3-�!��I�v�o�|���o��q�|����8zg�0G[c��^��i��{q4�Z�}�R�O�|�'����'Q���X��H^�5��Y��6����~����SM��~�^����M�6=Y���i�������?�7�?g����X����~��wx��7�>!	���<��2��M�����'������y��
�o��~��y��/CkZ����S�kL��s*Kk�L-	�BQ �B!��O���`�5H�A����0�L@��M*��`�iI�Vtj1��?mMNs#)��yb�������r�]���rX��
��f��L�u��7�S���>���W����r���	���v������33����<���O��-j���!�Z���]�x�v��3O��]C��L��}�zp84d�wksl��&���6��p�����Vc�a���j52/�����L:t�I������^�#B�&�����!���$9X�RO�o�*.�4��*
'>F�i?��n�(�~U�����/���D����+�[��9�_>�6�M�����8���]�0�8�������	�w�p���;M>��~_E*rb�rP��B!DQ��`I��x�x�vE�A�/!���U��#K;��}�mZo��'m����n�J���M�]r��k���l�����%��p{���I����4�<Y�B!�E��B!�"o���XT��,��L4�t�-�������K|����s�v<�<&&�\�B��bK�8�Y��TK���+����!5)e
� �����h����|���?[�n��u�3X�
��.���P�k�k�yn_�S�������w!Q(F;7����������9A�2q�e	UUQ���f����������x��s����Xo����?�bYfM*�$�Ik`(�B!������I*���DcPRRRr��n�JhhhI�#�B!���f��Z��i��������7oo�R�]<x����h4n��d��$
m��Q$A(�BdQl-;\��g��h-F���12Y�h�����������D���l�u�8�H�=_����HDt|�����{���1:���:q
F�s1GVp���]����2��R�B���T	G�Q�_��h�T������R�]��2���hD���h.����l����C�o�}c�o)�0�(~j�;*�����-
1����*��]c���m��{l�H%��,q���"�S�%������&��#i�5
�'������iB�.���+�B!�+���w6dX�i���{��	�sg�s�B�P�c�8��|x�B\,����@�K�]�B��.�H:cy^�0����!��_�Hd/<B����r�['�!��_K��T��X�C��|�oU�Qe�B�
��4�c�n�y���;!vUZ�g!N�Jm��w~+�����c
f�0m�A�}��H��Y�$t���Jz�PI�o]_�>o)�i���y (����T�I�eH�>�Hv�?rz��"!��~��:���D!v�%�}��D!�B��MB���YX�kK�AHOBz�0�[ZR�^E��<�l�z6��d�����������B!D$9(�B!��^�0S�A����f�J�mR��� 6��3%	�H���,���3��$����,�����1�	
!��&����F�b�+
�q���wmb:������p
���xeQ?�K+�4����4�qD.���U����k�����������E�E���oH3B��'��L���u[��u�+������?��>���Y�r��}	���bX�i�C����%=�4_S�@�lvF�����u�i��;�������r����O��FUC�����JT1�{T__V�:�U�
����?�H,88A�?�o��Y�g��8s�A��@IK�=�:���q=��N����er����)1��X!c0Cwb�2(��\wv�B!D�,�D.���iT��/��&�wS'9��;������~9>B�&s�K7s�S
eIZ�U�����jM$�:��y����T�����zo�,O��TN�������l�����f��[��%B];BpD����P�BE��U���78������U�B�*9'�j6�g�`N�3���� ��0��JD1��p�xv74o
�}�n4�;��g���flA�1!=!�Z�i���$�m��{	��ul��n�i5���m�N���mk��Z�,�}>s}J�J�B�I>�����aO2NH(�x���y����z�s*�F3o�o����-������T��[���{���Z	��A`%\�h��A�R_	VU�g1y��6������r$l?�3^���JJQ�bg���_Sx�M�q�1$����$ �Z�L4r�![�vO�MB���d��2'3?e���z'CB�&3$%(�B�$�I��7S����\<��^�F}i?uU<�.6L����M�.����1�4t�F��Y��aE��8�d-~�?��6l5c&�(P����O3}L*���������"&���|k�����O�I���X~�'�g��}���4h=�����S)'V�u�2N�~���)R��	tP{����%/�k��a�\8���BE���M�����������}G�����:�n?����p����Z���G�e������iUsx(8���M9K��TJ��(
)7����
�������'k��pK��=0�O8n��XGx2��N��[�ql8Q*�����w�|d�w>�5�k,9�v�%��;k�����H���L]}��@���v^��(0p ����5�������)�m��DB7~��!u?��u���Y���#���p 
�M�W�r�����L0�#8Yj]��.��
�u�QU2�Eq�1�������7��1T����g`�.��:�����
� f-���`UWpPa�j���B�T��^.Y?J�3]�I��NXr�'��7�6��-W���a�o��
\K7O���������o$�����\L��u`r(c�4����y`�a�������]y�;r�!�y��������~����G�:������3����9y��>�	I������0\�������a#���������[�~{j'[|����hP�8�����0;^�A�a��������F�Y�_<Ewx,�X���3xg8���|���x�H�U���|�0�e:�r���{�I<�5S���V���A)��#D�QI���ec�2�'���s���l�1�.�����g�R�^�V�[�5~�)'[?��g|��\�)GsG���M�-�5�	�3����A�20��?T�.�m+lq��ZY���?�3��esx�\9s��c�v�4������Fv����/�}	z�-@�
8}�w�����4����u���� �,<�5��N���L7��5��V���s�.�&�M�'��;�*0�����e�e������?��]��H�����]�@x������Qxw8>	����:�'��M���?`���Cr�~[��|�7xe?t�7< b7�����}�������������	;�~Y	��[U��!�{�
U4��������,t+�u�G���Z�}���=!�*�9���Y���	�kBY��6�]{KW��V`)�`M���0�X��X6e;�qf�h��������,	�L�>I
!�EJ��V���m�#/���#@�>dS��7��.&���<��s����+��,���	��q���x��
Z�������$��&n�}�C��,�7����x����R������vS��:�_����:�5������c���c�Y�i)={`����������w��?D��xj��~������~'�g;<�s2+v8�y�){;��+�����T�w�H��H8}�����U�j
%9x_�}����EWXX��C5�1�:�6C��0�<>j[?��q�`?�������!�,?��[���x���f�V�~��%���R
K�3���`?��zW�<����v���C�=�ws2�pq�
n�o��M�t�u=-�����-�m�|�� 0���h�Y�8��
p�Z��6�4���a�E�V-}�cex����@�C��0l[�F��g3|}<�����d]SO8���u����S	�t��
P������B
0*��g�����Vm�jm`@������	K`��5B����7���?�\���`l��*��9���Xfb�U�"�\�O���,Ir�F����{���`���^k����&�k�M2/s��S0KbP!�%�A+}`0�)�������b���8�\�'���?S�}�^����F�p�w������+�4��6���g��)�x4�:���E���V
4�s5V���	g9::�n���k����QM)(Mo�h;�����\9f��o���e���-������T�����S���"xO����W'd�#Ts�_@�5�@��4�7����W
�
?/�a� �9<Y.�l�8d�A6uh�~��*�R���+AK2�������xh!6!��\�U�9�/�2!��s��N����
����bN
��YZ�9a��>5}�����pl�����B�	�3����KZ���K�A,�Q��r;�j<�������4���~�>V���P�!���05�AN����d�NK��~���e���L#,}�������/x���S����/@�;t*�q?����a�.��4��)fK7qmP��G��u���t���U�q��m%(u�
�[�e��e<�{�s�PZ
!�%�A+m�0������v�d�q�l���3}e@�MBr*��
a�l�U3&�	q*������x��Ms�R�����u��Z��xG�8NO�����4{}>�j�b��rin?���*=�����Hb<\�m*�P��HJ�f��"�^�.�w�O�A���W7I�����Q@��h= ��\���3v����&��>�Y����@��BL"�9�7�.�+����������pod�Xxe�
U�����E��Z����jI��I0�+����	5\@g�_�us���3��z ���Q��s=�����1�gn6'���*�
��R�O&���A�`X�3��~���1@�:����0�+X�<�
�%���b������0�=��vm���OF���������9���dM����'?o�s"�:��M�\�!�"O����^�k�;���t�{{<�'lhG7�z������S�U�����O��(�x��hmZR������N
������Txv-��T�^����Y�H�{gH�M�Y����j����{^�dj���9%S�!�������2�����h]?]�>�h3t��WG{�ka���qVtP����f1w��>?����p�UK��$�l���B/w��d0�d-���}���cQf ���fV!�&�������\�qL��z���`��6U�.�Y��W�=���v�3j��H���e��,�`�9h�FV�$^�����Tl��dL�=��j�>�r�R��rYZf�@�B!D�I�lh��1>6�Z����}�r�jh�������p��w�[e3�x�C��������-P<
vN}����(0G�����
�ri�A��5)���9��d��k�
w�r���l�A	!����kh���,�io5���^E��OY����#D�s7�L�
��I��B������U�s���;Y���g�����8y"����,�O&��?�$���`��)[��%|�0��
�$��|������*���n���
�!�/�%�a����j,�%ew���J4���Z�_����-�������e��Kp �����p5�����W�BY��EE��]��5K�F��<�^Fq��^p���tnT���ch�/6�ix�?<��l��6����Y�pn��iC��s4�t%c9�j]��*��[z�wa�5k�iq+��+iMm��nJ�r���[��5���������x�e^.�B�������]�_��H��x�h����?�xQu\UKUS�:���w�����y��8$_���=�:n���������'�����p��^�n����%�*H<�(��!����}e0������J9�]C)�!~����
�p�K~Z�������zTnl`��O�l����6�����������:q�R���xC��mb���tu'!b+[~�#x~C�8�<�T�y���k�Wg{��o�@$Y��k��	2��.����u���LA�	j(���n��l_�K�����\���=���������/������,�}'T-�)J�?�
[Ndl��q��`P��a�',k-���� �4�0����ZBH�'/�Ix����z���Q��
�nA�p~w�)
,�;s�J����d��'!N �!���s;���5���+��X����� IDATE�6�h\��l�����K�n���n��3����%XrY�E����}������-��6������nz����*�_��$];�5.������`�~X}< "v�@��2
�k
���QfPS �*D����,����n��0(�������9�Ac��W�a_�V�2��H��0����c�\��s�����F��(�
�����	G���
�l��L9��,��lGq�w)�/�}}s,'IA!���Hr
��uq[��������
���R:�M��ch���}���%�0�Izo<��w��t98z*
_�����HL���3�E����<
��&�����q�`&�q�����)P<���i��0?�^L������x�5y�K�ir����l�!&��Tzt,�����L��r:>���=���N��c�������Z���B5��$�a��1������k�}&��{a��;�bs|���|�Q�Y��~�[�O�b���|(8?�=�X��>�`����gyifPQ��(��Hx92�2}l��{���P��J���N��
�bi�a|�����b@�U��w��6�7xg|���������2f��F������C���tK�V2L�������	L���������N0�gx�(��
����=�F�����yK���a[��������V���z�����-p.S�����5xe����C�f�-��Tm
�$���0�ukA�r����gU��7������������IWa�/��3����l�o5�![���5�[G`�V��.n��-�ib3^��=
�;a�NX�^�����R`pw����p��
����{�8!$x������B!D�����\�m������W���lB�s-���<Z���@�W�,e�������DC�K�l��H:C�s�Z�D��N����*+��p��F,?�</�|
���?�0����_#��O���~�0wc�V������p
?_�0��Y�Dh�	q�)��2?y�0��^/��!n���?�w�Z&�"~�������-"����J�K;����7�1����C+L��j�5��X
*�+L�@�%���$�B<H4{���1���Dan�\�x���
AZ
!�B���Sw��"r�!��N��B!��ddN�HB��$�B�'����z�}q1)�+a}MNAE��+�*S2�B���^d�k;r�*�pJ��y_
!�#Z��|i�`�D�B!D���`I������4.�8��o�Qt�4~w���B!�B�'���B!�B!�B�G[���f*0�;���s������r~�\�_\���*'�F]}��v~�_�`_\��#F��~�F��R�$wF���?k�yk�yn_�U����q����yV1!�B!�(����,�����:\XJJJJ�CAo��������G!�B!�BQB���`��o�|�.�c��B���w�@��=�\?���;�����D��+P|��D:��hp'2�cj���SnF�g1GVp�1�S��^(����L@9��-�hW��}�����pi�T�1��)�0�{�)q��!v��w.��^�����������B!���,e���2,���H�zr��y2> �P!��$!���]6<9��k�u�������]�2���NZ1��R�c�+�!�f�s������@�>�8�*�p���U3"&�����q����YD
�|�!���K��9���q�)q��2��B!�B�.��~����q���\�'��D!�B!�B��(I
!�B!�B�%����F����r�\g{�Q*�����Ws�\��	!��E��9�����3 i3k���-�>����W�_����a��'����F�>���R�(�T����z�;RJ:��M<ma���U�U;�����Wo�K�������lA��r������kW��,���0f�?�D!�B���bs�?�|��e_p�cS��B)�x�%�|��Es8���B�f��&����s4~�����A������
kW�%�z>5��������X��c!'�Q��\r8k��a�R��Zxe_&�|w	�	(\B!�B�"%�A!�(qZ�*������>�e��'����]C@_��(���������Ih��7�
M�AL�X������!�B!�rY~O7�~���s1�.��>�;�~� �x���1�{5�f|��#Q����=C�Q�p�q?���tN$Y��������)�
�p�K��	,_����2T|�iz�k���UK9�[�_������N�P�5��������k�T�U�?Lf���t_���K9��*&g?jN�A���(E�-!�V7����������>�_�D��kcPR8�JK����m���$s��Z��9���<�c�ZV��DZ��C��8@���U�y���3@��G|����c(�$������7�k��l��gn%�������?����4q)����#��������+
)A�g��K�q�ep�6���o�G3��
f���7�����g�g$�"�[���f0���#�_�|�
���;A�k��.�q�#aj����
B>�v��������m�o����'a��������4�Vm�CC�Av�~"|�>�
�B��0�yx,�{�p��`�l��^0�q0e�'��P!�B��8IZ���d��mA�N���E.n=KL�
�$Z���,������maM�~f����v\��'��8�����t3]���79�rCF���q�,p�2����f���s�`��f����W�����hQI>{�h�������z�n%b�8�u��~{��~�`���c�m�<>���z�zv�&s�lK�"���i<�F~���o���/w�}��1�Ht�B��>���+���[�Y~�;��m3��`�g��O����#uC��i��7iY�x�D��f���T|�}B�ra�Lv��������>�	I����0\X���g��F�=[Y�s�AM��������z�W�w���G��<�
�?��`�0kb��)���6�aAM�3_�O�qK�u�<���^�jNpz�<�V-X���p�%X�<�F��F����k�ow���vC��Y�wn�!�<1ZN��+Y���������>
�g�H�msa��0x$t.;��7_����'`��Sa�yx�5�c�E�`O*t��*?�P!�B!��4��N���#c�P��U��0Gq��o��>�g>F@}��������<l$�:{�����.�z�����
���D��GP�_����?��_n������Sp�>��1����H�l<L��m�+��*`��h���C�Y�Z�@����EA��������f
�S���z�%�/\Gt�����Yq�)�L������W���3@q%��P~������|A�Q�pp�/(=���+=qP�J�����i���rh�b�j���/����%^�GY��.���w}}��
6f\��eX����-�/����A]`���3X��o��5P�	X0��M������a���e|�5��,��jY�Ed*x�8���zp���k`�q������*8B��f�{�`���NW/�+���'��
�n���e|N�
K�@��`bO�~�����-���`����Mx��%����fFz=�=�B!�Bi4�Fh�=e;�X�������i������#�n�����B�g��8_=��Q���87��6}�~���4���\�a�V�E��3�O[=���]�\�'+���t;�Ds)���*���iiU
�P�|I=��#)x�j�{����M�6��Gr��f���~�?q`sL�Y��O�1�>�P�U�{�(�M1��i���������^���:<�7���!��!����b|es{��MRM�^�����Pf<��~�1��]��$����&\=	Qf�{Y&?i��q��B�|�_9�����z��#�t�E�yg��"2MQl���&hZ7�
E��f���IH���i��c�Y�m�;_�P!�B�w�{���0`��-�~����e{>E���)���X�L\��$Sf����1�UH�U�\��K�8;c�I�j����WI���z��o���M�h��kt���Ag���/��U���s��_7�<��S�P�|1��7���.(�wHJ��]C�<�����Z�x��;$��=\�sN�;�n����$$�ryb;�L��J5cRk������(z/hZ?�	It�Gu��O��>��u'�Sa�P�e�\5�q@93D���{�����t9�X�W\�jBwX���Yn����S�`�� ��eL���`R�������|����	!�B��#��{���=���Gb�s�k������	aa>(N.8��0��G�NWU�p(�F�j|<If���0��!Eq��E����x�
��G�����@�LI�j)��RP�Y�4����q���bl[1�I��C���`M�(M��T*��,3�����������Il�#E��A��t7'�g�z����'w���}G�n��@1�h,���(��[��#��
|�>ty�^'����� �g%H��tw��h�D��os<�	��lk���c�P��;���$Q5N�S�n`=>j"$��n]%��P!�B!����q*�q�jU6w��%`������S�p��w���J93����Cjb�?���F��������$��U��R��Lj�������#�����6��~�C%�-!
BD�Zzn������Rj�w�D�U��z
�p�&w������������������i4���S��>��vZ���������'�'iM8��6S�����XO��k8�ls���v�Qr�����0���N���-]f���N���������E�����}�sl��M��eVg�/19�����q��J�2��ka�A��!����9�lI��W�������K<�m��|C!�B!�����3�zOyj���w
�;W��w��`��j|��bO���2��4�Z��[�:v�SG+�����M;��2�Tu$f�w��@�����e
�/Qs�_�,�����G����)�RW*�M5*7��q�"C`��o��X��XE�_�T��z��:�V,J��M�����ok�:���/	[?b�6G��������E������z�������9|3������31�/��CN�1������}�mk��X#�����F��L�'[������S��
R9?�=�F��?4����0��z�evch�����uh�W���E��������awhW����l�����z��4��7��@�c�!��n(t	��[p� ����-u7����/������#���>0�a��pj?��g/��{w@�����[>wH��� H�
���%�e"����c�i} �6ci���������������@�q������0�B���/a�����'M����P'�|�lR��=�B!�B�4�P0���&v����hc
jL�B�v��J�g�2O~��-?<u�$�;�j��+�z����s4|i1��Jb
���b��zJS���>����r[-C�'��������7��y��//`e��0��Q��PB{��3��_�\InK��Sp}������i���:���x�B�������z��cN���N�~%������/l��\�#����p�6��Lb2��X���Zd������Tyc'�5��O<���a��W�0�);<(��i��=�>��
-_g�7>�4%�\$I��G�&
 �������q��>����������6_����)3��<���&#a�����
zw�
����1�)����O��p�k��v�$�����K�c�D@O~o���%��A���5���00���S�'3�^c?�AO@
0lL��M��
S�[��@�`�>X��|ux{&��J_��k5F��DW�����X}~��B!�%%%%�^o[�n%444�"��p�
Bk��|xran�,�X��{��*�u#bw��"_����I���|�%J_�ya�]�|�0�G����8��)��
.<ja��\�D�����d�Ax����,�z)��8�.���Vxr,aN�J;��^���	3x�{<��b)Fs�y;�"b��vB!�B���-Lv��[+�Jan�
\����B� c
!�B!�B�%�A!�B!�B!��d����z�}o|���\zr���p��Tt��H��7�,�B!�B!���}GEq���VzEEl�w,{�hlh�1�$�7S�����4�%�&����(����+�*Hg�|,�������>�p��;��3;w����i��tUh0n4
J:���7�,�B!�B!"���B!�B!��G����EY� D�w��
Y��������<J�J�"���������Xj��pnK�&��CpH��h���&D�Z�!�+�h%B��U1!�B!�(��T������j��d*d29���%::�n�#�B!�B!��K�X����^-R���2�y�����M���h"@)�PYQ��27)>Q����	�Tv,m��B{����������F���sw)��p�/!�[�O��2p9\��x�vB�����O�"$�;Qn�X��TIz7ao[R�a!�B!���N�&������u�tK���I���85�Qn�y�������^��q&�2\���t�I9�5t86Q:L��sx����MD�6��������o���u�RD7�[cPQ�Q�:�M��j�N����
��_B!�B!��w�y�����}eA!�B!�B!�Q�8(�B!�B!�=��+�Y��bb��y�U����,gY��}Vl�0���J:!�A����"���49������������h�(]�~��S��
T�6+|=~I��%��{�]������a��|����,_�,M���2x�qh]�����`7����V���s�`����F�>��>�Tc1�u�Y`�&��N�  �DA����B!��4��AQ�h��p�;��2�t$B�-�#��.T@=��%����hP��M@��
R��"����6�G	���@���'���`P���
en-K��>�����6C��7�U�C+�j�cG������Yw���0f4m1��o�x�����M!�B����AQ�hq�+��8(�U
��"�������	b����i$5����(��J���
�!���0�,����q�*��o/&/_h

���=����Ay�Yq�uWd���P��\@�2ph&�>u"l�*�B!D)U]J�u�|�q?��U��v�2���iK�����@�L���L{6;a-7�&��cp(#z�nHN7��?-�5��bmv+��DE���6�e�����$,��?��N���V��%�\�u>�?����3��P��>t�Q�����L�\���.�����K2����?j���!\������G-tYzg�,f���X��Rc�H���B)���(>FO`��:t������r.��_������]]1qa������,����\:��s�5���c�����N�������J��5,{{#w\��]�������JR������l(���f�M������p5��)���*l�
������^z����@��3�C�	��B�?�m�:�����B��}R���<W�k]T�l�!����Fo����z-������
��OW�A�
�4`��n*�����O@V����y;,�����*��xt?L��/�+���>��s��=L��T��������n- &�������m
��2P��SD�����}+|Q������7���eep!�BQ2�1�*�9R�G����\�j�S[���HL���+^T�� �\$��������y�7	���yW
�,���}����<����A������r�l#:M}�>�*r��o���y��S �����1r�Q]�7���*��+~�-o<��k�x8�+�����0���N���x��?�'X�t�����+�|���F���%D1����������%��y�����Rr��J��?���f�o� IDATV�[����ADw���N��9�i������'�z�/f�'h�r����)'{�2�����e������y�?�������H�����s
�|��F�u
�H�m[�V;��
�6��������ou��~0s!�~9�k
|0�B���ag��������]p"&���j�*V���^��8f���1�.a0}�������f��7��&H���aM:4��]\eY.C����~]��`d(,�gr>���2��d4����`�|X�������T~~�������"=.�v;(��Wl��y��L����w����h�Q!�B!�<�9x�.�����f�����o@x=7v��#,PI�k�>��a�O���v�����1���Y���l�+���M��=�����������H���'~hOY=@U|RN2������ G&SS���R��J���)�Z��y����MR�6x_m�5V���������~�8��I�2������%����yp[������q������������M��l�	,C#��i��z;����Q#[�k��{<��NR�x���1�J���]g�j�9Ss�W��&�s�z#����r�Ae|��f��M�z������}�s_�m����H[o��:s�����������|$[Sa�ko�����i`�n[�5�w�W����,�U�nE�j-�����pp��5���s����u��`r.x���?=X�m
zn���QpY����r��B�f�Thn��U��,t����� �*Tw��V�+j!�%D��S�<�kOA�*������*�D�����}��)�g����}�U�Ej
���9kt��r+��%B!��dI��U���f#���g��s6�W;Od�c�G�~�.���lQQ��f�dZ�p�a�����_qz�����"���CAV<��X	x�>��#4�iT	���9�����D����c����x]-Wq'�y���9g������@�^��]q���sR:&t��=}E���}�3��(K�b�	���+N���0_��+�s��m���P�:�JpK���lu�t�3��_�j@�
%��&�q0��6[x)2o=h����8sA%����5�Px����xx��i�g��<�!
`@�������
�+�}Jk�f�8I*�;N�KEh�o�j�-
�����#xj!%��k���x������0m|�	/��xE.
X��1��O���2r�d]���S��
����v�����x��N����/������3`��-�d�B!�(=�q�E4@�\���Z5�C�|���>4~'�Nu�0����9���Vl������R�(�>\I����i�SS����p���x��}T+�WTp����If*=��6*=�Q�3��������yFE�V�J��O��]q-s�>w�,!�S�uE��ok�)`�t����eD��"+��,�-������8���{]�i�ddY9��D�c��j������4���\�v��?a�^�����VU���<#L��#L�����/��*�d��s�F�[�9_&����wO�,o+�V������o%�T���b+C��~��\��p�f����Zx<��@k�����|������f��jE�
��&�w����z��	<��!�B��Ce:���W|�Y���y����5����r4��1�y�fj���e$����P�\p�k	y�y�t4��Q�K���&4N8�AVr��F���T�;��Y�@���7�����Q�w����;d%g�mT�J�B5�a4��q����t*�}B�&���*��8����]:��������0�,������Ew�y���@���}��!�~�6��(�F����������)+T��b9c��p`o����h�u+Aj&y���	��Y���er������'C�"3>!�B�RE�<u���9[��e� ��7e_������mx]����O~f����
c!��$��[e|����b���
��)_C����I���AM!a���st�������%Dq��Q>R������\	���D���s����g��I�YN�����DH
��Sp/�oU��po�����A�M��{318`�y_V��{�
^(I�<k
|����P�<|�3gu^@��5��A�P��+�#��z
�*�	�%3_�%��km�eYn��������#mo�,{V�7�F�����t}�S�����j��!��mB]Y����	�+(�/�?W�FP���!�BQ�H�AG���X���+�o���N�����K�2��rO���	�~n�;�o�����l�=��4�\g�.�>���ei�}[�yWw�=��U�2�e'Zv�"c�rV���u��9�nFSL�{Y��n0�?Iq���uX�o%s_0���'��b�������s��z�2k_[����hv���V�'Q��n��Z�4as���0��I���S���w��nZ��J���,q���!��a�SG	�P�'��cC	�p��(^�W`����1�4�
KV�6/����l3x|
�
�|@�Cj���o-��)
���#��F�|�5�B�0~>��p�$�t��j�����D��1l�H�@�
�t�(@R
d�`����K�gu�9���-�q�`��	����ww�����a�1P�p�4�zkC����*��j�`�6h����:H-���y�p<X���Y�pD�{l�^5a�v�Q����w��+���B!�B3it���:c���\f�Y����v&��l,d?C M?n��K���H�����Iw���`���,�u�,�������������/�,�h>�N�BL��D��,��H��S�e���(m���1�k=K�-��)Y�*1q8�}�s�X�!}��7���{6�a�3l�����Csg�{X��2Yz7�k>8����(i����y��*�O����9
��Ah��P9�b�Ao���Z�`�����zg
���}�5��z��~Y�U(���������0�bn��
��O�w��L��4Xk�C���9`��;��vF=��q����m�!{���+��{`;���6���'�k���'���*��
FE�Gk`�?��A�����#�.�>�m��v��v��h��0e;��
����VPO��!�B��O1�L��?���%::���=�*QN5N?5�1n��l�K=KlX�&~J�1����L�����N"J��p\����G�[O��^����w8���z1��>����ELG�����+�]�������Q�W���5�C�����zFG�q�����+�hJ�w����%%���,0�����d,B!�����`Lh���&���n�ni_�3W!�B!�B�{�4
!�B!�Bq��9K�	��^���B��+Pol�]��x�B��F�=\�A!�BqGI�`i���'ChP�q\U��B!�B!��F�!�B!�Bq��c=��R1@���U0���m�X��QQ/0[v�.
�:��P�Fr�BH�|"�I.�%���/��B4�%B�W��	!�B!�]q�U��O���-���L&�����DGG�rB!�B!�B�����l{`H�����8C����7��uw(�x�(!�B�D��\��DB��%�u�36�+���7'��x/�REu%�(&�Y�����^�7"�������
���2�����%�B!���,-�6J@�d��-�wG$�roT|y�vlo��Q�r�55�(Q�t��(SI$�5��������D�7,<���D�_����R��V����dj�y��o|_�2T����.q��K:!�B!�Dq�_����}eA!�B!�B!�Q�8(�B!�B!�=��+�����z����:���_��T�a��
'����I���{E�n�����!����i+�����h||(W�&���E�H��)3�o~	���/����s2ZN������i@��aFOkv�:z;e��>���|�}��0���N�������s,�e�����#iJ-���w�������~pW�w+�������G�1!E�2{T�	���85�o����#��{!rdW���BPa����v����Y:&������[�D!�B�{�4����i8{:��Lz�Q��t<���#�V�Z�ow�Q����x�;����_1��3��������9�����w�DQ�D�����Q=n!w�
���V��C��u�:z;e���<������\0G������5���z������4��G�8�'������@�nP#���3=!B����{}�F��\_�T��W��q���x��O����B!��J�y:���p�����%��/R�e	�\��w��`~�l�vC�g�vd�����=�3�L��4�#��g���H���N����U��Swqd���v��[��#'�z��jq�/g���j ��IS��@��w��`A�Z�[����&���VJ}8,���B<a�6x���"�B!D) �_��sf�,�h-g/�R~�0"�����CxvAw<4f^����xr��hL���^�s;��XI]3�eo/���D,���?:�N�j�f7��y���}�L���8��vl:��-��?�[��������8��Z�����|�t>�N�[[G�?�9��������;�������'��'��jC<��|h����rpS<���C"��(�b�����Jxi(�6��{��l�b=������0�'����h����7�q�@D�c:������w0��
�^a���0gob�!��J��e,�pw]��H���tY-�uA�Y�~:�5��q����0�?����+bP�I���^�n~Z�y��:V�y�$�>i��
8��|vlI���G�1���������3I0���������������O�|��18����������������&1����T��
��O������t��m���������N�H\MC��@�kfMg��5O�@N�g��!&�}a��;~k~�i�*U��SCi?(��t��,��
������������������#�\��_c7��+���������g^��Ka�a8�BhEx��/�`@xs<l�=���=�l��a\=����k��0���|���l��� +�����D
>�������;`G[�W���&��>��� 0Ft�A��~ ��g�`�A�v����9>�C!�B!�q��1*K���6���f�$"y6��H-rN��0��T��kO�������\��
fs��9�0f���c����}C�)kPQ|�R;ZG��kI�������\@Kj5/��h�-�����A{���/�X&�������T�"��1�>|�{���|Ix�����};�u�6jL��f��O�`�,��b��������t2��}��m���M't�g�/,�w��e��x�;M?���0�[�1}�o�iF�o����!\��sfO9�{]X/�c�8fO�D�#C��:
)O��C�Y�?��������>��T�������Q+�t����3�e���Y)���O`�������}$��r�i���<��H:�&��O��{r�zs37/�Q�����zjV7����V)���������b$��ka�D�.��r Q�X�3F���z �f�Lt7�?j����{����x�UfO�@��#0g4�
"i�>��p�X�����+�6�"z���]s��.�E��q���A`�2�|��w1�t�rL�`WN���'�����A0����7x����H5X�2L�����Wr_/�6��zR`��{$�{6>�:>��[^���y�zW��0�X�;��ZF������L��)�i~���������a�����7+G��B!�Bz�&��_�7y�����KU�p��K�S�|������Cybz����s�0�&-����d?������O�<����rEs^���)��+�{���0e�o	x�|��"����6���-��R�q�
]��)�8��C�w�
Pp�9��=�6���ng���S�V����z4�5~�_?�7��e�`�4�b+,�-�CQ���1���<�t��2jfn
h��O�v����Q�)G_��/��n��e����W���'���s]D��r�IS��������e��S��������V��G1���(G�1�92|.K�le�W9�7�K�a�����6%��e]cI�s��t~��V^��k��n� ��B�}
�]�����f��v?��%1�l�x������>a^�_Lg��Z,j���'*8ZJ��s�������)�EYV����-	w���S����R�=H��h�h��J�{g��kH��
o
X6�g�b
5g�M��n���U]"�[r��;��?���#�7�ld��V�9���������a��P7���&�'� �=|�3<�2�����ahg�����2�{:�����0�Z�����ul��k	�����0 gq�*!����*�`K�������.Kq��5����FX���4���������Ey�7~��Z�zf�������x"-�dvn>��C!�B!�4`���n3�#mC\�\W���"����c�����kZ�4��������T���J_������eh�������i>��#�=G+�/��s�k��	��8��ru*���0g�U��88�/�{&La���\8���lE5�Q�'�iC�y��T��k�>�+�>:�I)�T�)���s(�<k�m�<����?���J-����v�{,���v���!���YG9��B�����
eV�mbg.���\�p�+n5�l���^):���
u:0hm}�/����qx�
-^��q���@?4�e��.��m���������l.����[��XP����[�����Mf��0�E�WL�k���q����-�����E
������f�����������^W���Ip����s��F+�����{"�����wn~I���]����^e���0�,����m�)��������k��@�`[o�DT�x��@�|-��[�h*�������AR����N��f���tX��w����@�J�
��4��OO�����!����
�����sXB��!�BQ�H� �5��0z�?`�1z���jZ
�N����k���F���4���q��&�{��uvG>@���$��H��[�H���Z���lDK"�)��C���^b�B��
���b�Y89�E�8m��CI���x�V��in���O1x���������Q�[(�����K��z��iiddY8����7�n�������_%#)��q�I5Q\|	����^h�q�
�����X��{�`�����p���F5�Co|��e�4~�Q:�����r��	�q�R�a�E���w�}v�*���^Hq�>ZI���E%�����2QkT#���#+�6+�y,��{���=[����b� +0�d\No\��'�����3M���`�Q�Z�{���C��~�mW�@yH�iL�o��YY�/���+0T��n0{/����f����?!
x!;2��,�^�vI��~�n���4
!�B�8h��`t��+��������7�&�X=kv�G���z!/F�N�����Kp�Gc
�
�Mt>��2��b����H$�����P�FM��@��dnNN��3Nnf`���?.������Q#�s����Xt�r��zv#�?:L��H��G��8�����Wqu���%�����>��zE�KE
`���.���ws���\����X��y��UB*+�F�[�����$���_�}��9u+�s��[���������
�z��K�b\(DM���cX��YVo��^�������n��U �3N���d�V�JNG�{b4(8{���+��)}�vg��G	��>�:>9�;��`����>_�NE9�;^�p9��PV�������t������h���l�����,0���u�o��k ���\���9B!�B������)�#i���@����d�����
.%�~5��$��-��T��:�_��JE|������R��{�m�]�4;^���5�������Gw�p����>j� IDATdrr�������3���\�BF����&��
F/��mi�9�)��{6�9���leG*v����_7�/��h�y�X����$L�-,��v_a���4x7�#u7�W���6-9�W��O��[����������8)�U\�m�lR0z�5����������������R����l����[�rVX/j�no��=���9����C~@���a�v���?"��.�r,���Q>R��u{H����L���(����z=4��#e�cS�����mZ,��c:����}�?���3�7�I��n���N��sV�Ap�\��rP��+�;�G��B�AX��7��\m�f���2�[:�zU�@�	Xp1w��"���h��*j*�;l��N�>��_�8dw��C!�B!�������d����{���Q�\�1�]�4(��&���4�W�iN|:��8u*���p5IYj����=&0�8�&]�p����]�8�+�vS��W�3�
"����zi���S���=�+�A�=�N���x`	�N��[�	���&���\���!��tE_.�CU*5��d�\��=HE���y�{�%��y����RA��@������4���J'+�gNg�:?Z���rN:|��f_�_��}1O������6l0���4��s�.�=��=~����������F~�	����p!��>vl*C����V/�m���oL�����V��e�&��s� ������Q�}���*��`RU���$�0�b�5��>�J
u,��O���P��{��f�MuK��0t��X�sy�WwA_6���(�������3h��qC\N��|N���e�n�=6m�JBfjhIH��duj���8�:��������I8�Y�X5-(�~S�`��.$��I�GZ�j����L�.>d�����NT����y����:z5��x��=��t%��.v��!zR��`����_���,xf��"	p���~
�#��`vD�%X�+�'��
m+��f��u���8ialG����#�@������`l��)��=>�u�|�
�C�m��8�
"�����	�6�
��L8�h[Ey�.H�Bh�pt�.&A:��j�A�2���"	t���O�	U��tD�W�^����������! �<
�1+�u#t����`�����/��0�2�������h\�k�u�
!�B!�Oc��#0�~�3�v#���}���sS��
��3	,x�1>~)���a4���?Sr��>��yeX��,�y�,������G���)x�k���}��z�-q�:�h��0
��+?BF�N��uUp�7�n[>d�+��#���C���}h5����U.�����_�xU t����ZL�)�s(J�+{����y����y�hd������>�:M��nI���tyu+��3�u�^�e�c�>����V�hx"Yzw��U!�x�u�����^F?q.k���m�8�T��c
p�������ml��/R���W ����L�k��9T�Me���W����������5�X��{GR���:�������h	/?B�At��Yp8~
n=�m�w,}k";2T����qh*K%���M������k���}Y��+��S�����E�zy?V45��r�<v�����Q� P�~����,}�]vdXq��>�m7}^ai��a���,?�_�DX����$���PiM9�L~�����K����N��������W��������M�B�&x�<�$T�9����nxgD=:h�~v��a�%���j!��~��o�����R�4.X!�"<^+�M������r���g@�>cB< �0���|�#x0F��!p�������K��v�I�|v}�(���{������0q)�������p����f@?�0�2\�Khv&o���C!�B!��d*t�Tll,���E����!D�7������e�+4���c����Q@�������$���#��cCxvA��U��*���^��w=���ujx�u���g��}�yfI/<��A�S�l&��~I�q���?����4�����.ET��R��V<�^����S��������s�K��2T+��J����D[�f���E!�B�o�������M\�bC��}��`���������]8�K�"7
!�B!�BQ8i,�����3�*xG
���u�u8�B!�B!Dq����Q����Y"e�������/�����8�Y��p}���!��_K��B!�B!Di'���F�*4�l4��\'�B!�B!D���%*�B!�B!���X���Z���J�!Z7�����N8�_ ��LI�P����
1T��qs!���v/�T��_��	!�B!�]q����O�k�-���L�B&����X���o�!�B!�B!D�t�z�����2�\}�$��q�h�eoR�����D)o5��y���-^M&�Px\��S	���K3�3h�%�(&��K���zeG+��G�k����@I�UjD<���7�|B!�B��A���-�wG$�r`���e_���\��tS���ri�P�S���R��c�����7�fJ����D+���Dy�����W\�Y��dX����KD+���(�&w1��%.yCI� �B!��B$B!�B!��%��B!�B!�B�����bq�do����P����=�%��YN���K��a@��j�S	�%�$3'��g��N�FP��w�N�]�����q��f��|�h�zt������Yf���*o�~�'��p5�����;������/J���E�C��O@TW��H��{�m9��nX�+�>��AFOi��>�H�a���������U����z�[��/`��|�50�ax%��Yf���a������Q����R��'	�~[,�Z-�+�[���\��NYwS�^h<�����W�����GFX3<�B�(~V��>�����+T
�m���]�E!�B�v�����3�U+�z����Z��)��Lz�e��t<���h@��=����(���%�vi���,�j�b=���v���h�G�0���ZWj���PT��m�D���}S�_�8���1m>�C��L���l��f2����)��������Q+���7'|�p$MIr�����5xS�����@��P-�m�/����PU�eo1K#���4vYS��8��z����02�f8���
.�FX��u�������a\ �_�M�`�YiB!������C-:��U�Q8@���/N�puQ ���w�b,Op�6T.��.��
��
�-�X��>�EQ��m�oD���n/*��5����-��~��_Y���c(��^�Mkq*���B���)A�2�>�.�,��+Ce`�q����Mo��R_�U�����C�j�m�����r/������(��d����Bs��]�9��2M%�B!�(�����SS���{M��%�7c�Ri����~��&��v��>c���,n��w��c�,n��x�e��,�Bf�b�'�9���>0��O
���P�
�����c���yrqW|�&�?��^�3�pQ�y�)~���vu��������3�n�����\�&,aJ��$d���.�����67�{��l�������@�	-�5���X��0�YC����|��K�!U�x�A�
��n��w��kz=���/������e�=��=�Y�A.VR������qp�y,���{�N#�����^�q�N���ys����H�?�$���c(8�|�$���i[����96~��s�.�uA�q�����,�4�����o�
+����k������w���<����w��d�jW�S�F��l@�i�b?���#��cp$������y��y�k�}�B�m8��dvl9��-��~J��e1;����p��1����j�a��c��|��n�U�v0������s���$_�`�B��]i7�����\����_l���,��+R��tP!�~�#�{?_���q����`�?�����f��t�|�]������4x�+�_f�g�6,t�f�w<���N�ph���3a����($Z�bE
��c'��Z�)���dt����r��\�	@�������������`��7n��z
���cY{���#��
K����`^�\��=��H�y<�
�����$+��������=����ga�q�zC�N02���AxO���g��Sp.<}�s<c7�z����	F�����d��f�Vs�R\�_���s��b�f����n���2e�c+i���xV�
�g�� ��&H0A��0����
B!����*W~��Y%��G�n�p��9��`�N$�����d���q��� ��*+�1����@��>��-�����t��~=�
Rx�b�1�A�<���r�
��9���x@	���M�1goga�7���/��5��c�`{�k�T�6����^(E=�����T�#�\]���
��:2w�#��q�w��~��vE)a5���B��s��	��EF���`�/X4����%}��,^�I���s!{��L8���!t��&��+Y5v4�]�0������z�#G���r��2m���uh#���IZ�pExN�����G^���g1���_���
2p�mh�R�lh�9k=[v}�����7:��8�E4���OTB������6��s��.T��*�G�T�9����������s�w�A��>y����G]$l�h�}�����-����@O�ON!,�6���@�{����{d:s�G�PY4�d=IR�4{�-^>:2��C�{�2��E�uw/������7f���A]�����5+���o�t{�~�r��&���/�}�u��K�j�d���5�H�X�k&�h\���sP�g-�����0`),��= v	��
�Z�4[W����y+�4N��O�'`p��Pk2��6{��n�#�`]�(��c7C�n0�XO-��*C�����`Yu�>�_��[,y��0�Gh� /(���7������a�V�3ZT������2_�^��F�4z��W������P8v|���-�G�v��i�::�
U��������&9�F�P�!��Y��2�����{�t���u����s!�������0,l?���s��
��6(��
�6���R��������#LH����%_�|f��Hp/J<�0�>��`�l�4>�^@�B!�����A�YvL���i�_l��a�,�i�?���
�C����������&����������RF�A��'�'�{'����������
��R�Qg�
����Ws�����}�GQ������{ �z�B��WQ��� "
��
���^,X�&�E��&�C �P��%W���.�.�` ��y�<O���3;;�����T���PG�wC-v����*M�j�����:
V�jS"�>�Q����m��|����W�MMbP��eG�woP�=y�{N����U��lS��e����H��~�./mf��)��i�������t�����5]e��y��e��~�����y���.��������k.kWIT�9�Nm����I}b��K�������-��7u�����G0>�����r�%�	�=�o�#�!�`��A#�t��#�Ar��!;�|���X7i-:����V��^�W'���@u�3���E���m�0���w:zX�O�����8tkY�*��C�W���.A�8Z=��og�����$�;t�W�74*���;�_���K��k�rG�MV�v$���|?n�|t"K�MZ�fx*��{=k�����3tj�d.�F���1����������+|S��-�<w&/�
5��C0xT�DM��V�n	��Z>��Cv2���jk��w3����hi�*6��L%h���j���O��������RAZ�w����� 
��AQ7W�,>��@�?,�SA���zL�qK+-U ��5Qg^�.���3L]�M������{�G�����t�R�����n�j�����@���L0c�(Z��������ua��"!�|v^�*8K.0�9����]F��� D;��������3T/oV�)��7a�q����,NS�Z����#ZB�
����0�4*��4AA�_6�.�|*G����MD%e�2u$���o~f1���a#�OT���k����!�SOs��%x�UDF�v�i	�ja(�'q)]&����5��P|������
CZzT%=��������[����h@j���������{�g��	Ka7���4������v����1���q��/��}c��zUp�z������m/.������}J*e�{�)������^ji�vS��W��e�S<�P�6 ��Q��p�{�C��f��}\����`2���i7�	U4�-��?����("B	t��T
B��.e�yI�{�C�/g��S\����o#R���m���\<b��{y����
�??g��H�~��h�4s*Rgw���-�5���u��
t)�oWX��9�����}���>#�lu���]�k2���+	\���#6�wQ�!`����O%d������]�z3x%�� I�I�r
��
���<�y;��%0jAa�]��|����u)0}5�<Wt`��h���`�0?a��RX��
�Y!Cg	�u�n^�}dX��Y����J �`���($e�^�	T��,�����
�A8a�x���c`�a�p6��qa��0��eH�i����!��f]�����D%�t��\nZ�^AAx ��  ���g��c�3�����-��$���yM�����������)?�<��[���MBr��$]P��j��F	�ed����u��N�����4x�Y�W�B�2q����#�x����M�x�����[�AB�������N-���>S�� 7���I�y����&�T 74���	��8����j����d�7u��	m��G�Z��3�r>�A29�o�b��@��6����U9?ed�mB��sq]��p�R����8jP��.��q����������}Uws��6�?.�r�6Y��nV�@"�uw@����hdr�r���t�L�+�����$Joh�NC|U��.6;�M��g`=b]6����`���K��\]��H���q���V�9����=
����1P�T���4�
y���9�)�`����^�	��@i�/��+E�Z�� ����l
����P/�0��Vu��k
,Yo]�am��?8H�qL�mm�
�I:������
hT����>�f��!� J�����rH�\��(m��$�,>�AA"8HNNhU��������9��*vT�����%\ /=�j�L^z.����9AR�<�����u9=�<e�%-Cz6�i��������<��shy:����M���O:.��K���"'�f����E�g���'��4Gl$gW5*"F��c'�7J������RS��z>~Ho��V'��`����_#��/i�D��M�r��+fg���S��sw���"��hpp�9�2��#h�xA��<.�A�VX����'���CV���H8z8BZ���3����g��?�X�����j%<�44/����2���
J�0�&���p�T���;0���Y��`�Z��/L�����c����h{[��=�T���'��.�lUK0R����M:K�EK�0C���Ar�����
�!�Q
pu�!�2��(Yg~AA����	�FP�L��c�,���i'8{�P���B�U���i�>9�3��#U��_��QgH� �`C2�O������\,x����S��#�w��^}�)�s��/�-�e�[4&*0������+�8'w��x.3$�g�O�9v$���w�O�c���q�H����G�Z������<�kc���"��5\���e�S>'5���5p����u��w�=��gJ5t�w�S>����*�����;u%;^i�N�$%r�R��9����`�=�di���=�Ns�}1y��8k -����=�(�	��$u{���8�3�.!U
���x�+�[�1��s���)
&,��8��T�ol3�4F�f� IDAT!P]'3!��Y�DzZz$*�vd��M���7��XN�9�|�\���y>�{��5���"�u}�9{�	�M�z���~�uMM�/��ca/E9�\��x�d�]p�e�s��
J���i7O�z��N�=�#�5
V�/R.+G� ?� � �C�!�[s)��P�Mcf��S%�(���bNK��"�3��������4m�E�����^K��Y��R���".og��fx�;���<�&�X�p�i6?7�QU�_��_sy�)�*��k����Ao�M��B�Y
HZ�C�����s�+�7%�~�_������:��
& �I]�r����y9I-��p�Co�����9�d��.g����C��r�j�U^��G����ek��v�I`��x9�H�3�U�Ci��~j|&
�H��Y<�.	��C������x�=~�&��]���~h/�������W����4o���_|���������m�#~Zw<2�c;9u"��s���I���C�*4�����n��j2��.��#C~*zYF�v��sZ������O��_'�W.`o�#a>j��x�jo��
�X����b�\��s<��w������XZ��I:���Kqx6����^�#��z�{�"�r�T�����f�sH���K9�Q��~
���Z��us�������P�}o���BL�Z���oki�A�����QC�'5o�C�����-w���3P_hNl�#�I'�����)�K���
��������
gx,L����s���l=W��Q�Uw��l}�4��u���h�����=k6��}��p�1�v�3��7�X2�L�D���v�L%�GB����d���2������4��2/h�p��
�ia�vh�o��c5Y(\�5��p���
������u�V��-�����U�Q�E�.��U�tH��u�BM�u��#�]������p �e��l/.�k4�,5���c�X7���}�-� X�����b-��
CCa�\�Z�c��q^�)���$�AAf"8���S����7,��?~�E���4����ZU	�%[
��gVL��o?�PE����w��qU�ntq�%c�3�u_"�>A�6��3��h��h��4?���/����3A���y}q4��[�p�S��z�<�"U�z�+�s�'��i���O�����'�/����q���*J�5�����?3��R�D>���?��D	3#<82v�������������-b��{�ya&
c�����t����������4V����������l^2y<c�Q�WG�
F�)������Ng�����j�1�21�Z��0���4~���������A"
<����	������KO0��p����:�����V�����c���W��Dtzp�/L�e_Z
_j|�6��|��z?c�#����w�V�6QZ��S2U����y����C��y����p����\{u1s����Kd�x�������G�p����{~a�����q�3��+Z�����pl����Y��2~���*(��w���j��'5>{��K�8�W�\5�N���:s2aL�RG���A�>N�a�Xzy��a�a�p4�*��f��g���T�8C�p�^�����>���[h^�",�Y��a�2�~�0��P��!0.����O�/�z�N�wme��nL���g;�k�a����y�����=��m�<=�asx�)8���nG�o��7V@����
�[@��p����A�d��\�zA_;�����T�{��E0�C��/��)�z��9pM
�Z��5
���)���Y+ %�<���0���\�JH����k�����v�,���AAj�^���xk��!>>��ny}'q�;�x����nq����oV��$�6�����7�����;������||C�/���$�4����0jq[������:�2�s��v����l3Q�Y9;�XOg]�K�s������>�qnv>��Y��I�����n�u���'�soh������}�%�~mZ���{m}�V�G�f�����pO��� �������e�/0�"�RAAA9z�]�O�����d��l�E���������BE�w	| ������� � � � ����`�L������2Y9*\*W����
/���P��sAAAA��A)����]Yg�?����)�����4;_]�����>W�S����5�� <h�������%�=��3a�}oh_��AA%"8(��*��S�Q���!� � � � �:1�� � � � � �G������R���H�_� B�c�1#���&K�C B�Y�Y(�=�4B�}r"w�q��k�+�����oUtAAA����z�m&��5k���#� � � � �}r�z�<�Z�,g�wI���Z���jI�sD(C�:7I�k�js�}��H�O9*e�U ��s!���l7"�i�=�8� ��������P�N��U\�f��}W��AAA@�XW�����9U���X�s�|,�f��oV�����anB�Y9���0K�O������!N[�>��t���#N[���!��Y�G�s.g�=��-Ne��ss)��=�gd�uAAAJ�X�DAAAA��DpPAAAA������G���/��O��1re�"�j�x�
�?���FT�z���uq(�l	
#��x�o?����+�W��CEM���Q�LX�?����w��f,�^jG��%��D�$��-\�jH��nH��pf�~��#�l���TO����{M����7_k�^��=���G=?2��>���%�8
������?�q�y@%^&����yW!�(��1t/���z�u�B�"'�w
*�|�Q
���~?�S��*p����Om�X�Z��.� � %!��������o�Q-����?bEY�Gx0�E�lZ��8����2��W��G��8��B�������_����a�=�������I�w�8�6�:7��\�����E�u(Ae-���y�'�`����>q%�Q���e���+@e	�;��!U���+������}sp�@^:,��Qw�AAAJ�
���O0��,��j�bI��w�AT������E�K�D����l��t�G�s8����&9���#Q������I~���}�%x1����3��/4�]�	�k��I��yW`D��/DAA�����\�u)�?����:$OO���������#g�N������e����C����]yi~}�
��L�$M������jt'�':�Y��N9��o�d�~.�:��U���gr[^X�7��i�����U�p|:FO*�J��p��eX�����g
.���}��ct�������q�V_��������Fo&�����d����s{�Z�$�8��j��V2;��&S�M��.tW	��������[8�����h#"���VB,K�l�E������.�j����S�����>o^z������l�8��~O0��z�)9�#�>b���$���P'Y���j�&��O��@���i�B��A������s��	�rT��6}C�������8u�I�`�����U���v������l������B��������_*��Q��
&��G���?�/|T��������X��N.\U���=����i�������6��&��^a���������kQ��=;��g�f��\�������'a�xB��$������iU�;��$SFd�w�<���}���i&�4�qQ'.}0�}��at.G�w~�Kg�2;�����N{����o��W�����?�	N2l:�^�����C��(���u���i��
�e(�#�A{W��a�������HSB�r��?��3��^"�(��"��3.C���g���?�1�C��d�U�;���+�7�WsM��)��
�5B��,\(�@���'`f*�i`@8�97{�PAA����M�1����t�������q�w� =C��cmd�:o5�����>�g~�4�L{2�+2��#�z���_����u3���o[������o]��0��G�q��o�7��9�0\`�s�0����M/��Y}|�2�w���H�w��o2qu�^.T�Z��ug1�������=�/�������u1��%���I��L��}��`�93~�db}5L����D,]�����u`�BV��q�}���H~z.:�����j�h�i;����e��!#���w���L���Z���m)?>�����h?�K����W
��)�}O���S	|�O�L�A���;E�	�������F�m���W�*4������a�g�Og�K]t�N�]�0z��4�Q���0^8�������6�I�S�Y=GE����::��9���i�������c�'��U>m������{��O~z:�����|��h4y4��'�lQ��Z�z��+�i�������'v�'�w�!^��I�??���o.�6���N2p�&?e[&���=+�lr,)j���p�p
�Y"i�a������'�I����hW�vfZ}������0K�+�o�a�3���7h������?���0/����@�UvV(Zs����awU�V��*��>����L$��
��07����>	�]��H�[:/�EV���L������8�����=e(� � ���s0��9RQt������.&��������r8�:��?l�������9��^rvd�;u�P@�Z����J��)��l$�J[���_5@�3/0���\��P��q�,�<G�����Q~[^��de4�ws�|C�I`H�����������nCr���[�����A������wp��v�'���+����i9T��a��D���(}������������p�6����Jae-�����S�37j��6U�^�^�	����2�3����J�8��>\F��imK�7�����I�����Z[�FEs��zw%T
��X�BA���S's�hC�@������
},�!c��c4� )P9�QH�]����Uf+�����Z���9��:�Jw7<�����E��pzWjJ�>��u��v��������n0f��0���,m��F�P��~cn��l���}������u��t�3����=9��r\�-�i
�e�$�4�w	�>C�^s�v�o\Jg{�1^���":<b.�rQ�2����{"�2T�l��EE�h��c���'!�����������`������2�`F2*g���<��`V5ho)���� ���?�'��g^�/^��������J	�J����l����hN����[-M��'���w<l_��a�������a��5��!:V����2�j���
�co
� � ��h��0lf����'�����:�]gI)��AO�j����u�KWd��.q������ar����R��#��w��;��R
�-
�D�2��WeB���f�!D�?�P����39�{
���E���C�|��3�����(J�[A*J�������e���|��������e�)�&�0ed��I6:h,�������go���2����U����MPG����F�Q��t/Z�����G�R�Z��^�6^�a�6�G�2���m��nI$�5�*-�l���R ���������9���@S�v�F�0\���%l��W�s�k�,��jE�B�
*��A��:m�yY��P��x>�C��[��p�k�Q��Z��I����gi��P�y��vS�FQ�@��{�_�X3p)C&���TU�nt�2�c~�o�>�����pH,��vC��P)F����	;M���UK��n��r)@�[���Z�(W����������$H�����5��C�Zo����L��{a�SRCg��i�����}�
����V����y	� � �C��*k���W&��b���A>N�w�@����X�cI��h�J7��5��e0��e����K�
��J��r��7qa�d�{��F9���
g��n���X���=�=o/�F� w�>�bP-�.��N�gM�I��tY��='����_1�
��K��hU&�0�?������J�������#<�$���*y��*_*uc����w���U�W��6��w'���V��i2�������-�l��+N��������T!4�i�����I� ����W�d�r/L�_X_?��?�M%������J
�F�����l�I���FD��W�*�J�j�z��;t������N��GG�\F�%�W^8{���fW~J�F�<n� ������t����sd�!_��v�D����d���V�<���I�.R�$J>4�$�n�M
�^��V�MF��mZ
�+!�h��Pg4���:��w�s����$� � ��#
~=;��ggL��9��2�����bHx���FRH}�7�o~"�3s�3q�'�1C�^r��U���e�Y��@~�m��;�%�8��V���tlW�iYR�^�XB��3���'j�5c�D��G��kXB)9=����s0�����o+�?��%��A�����y\6������|��O:�W� R>���N��W�\�$'s�x��b����6L8z:Bj9���)BB�6qt_2F�PIx�*��E��w������G��Mo���j,��j�y�l�M�x���|�.��U"����j7�z�LNO���d�c�����Y&�W��h��N@��P�rn.*P+�����M[� ��c�z�B���=���e����P��yo�!��y�C�
�@�	
�*���xZ�bW
� � ����$��^DlI�(���`H������
�O���!��S�I.�������`}$P�TYI����@r�����*hGZ�p"�*I9��K?|*Z�T���d����\���)�{uS"�����F��N%r����8����`�=ln�q�@j�Ec�&�|�zXu��>����xQ��aJe�KI�h�����9�z~)�um8u������?>�~n�
�
���y��krl�����O[�*�<�Y����nQ�L�Z�����nQ_U(5`���.�u^�������/��������^���"�]S�V�$�Lr8�m������^P�pj{�����L�'��?�U����{s�2��K'!"�B�,x�b�4��^uu$8�QNP�����#Q����y�)�����O�9:;�V�����XW�M���!�����)*���;8Cp ��}�,8nu�v�� � � ��5��L�O��p��[���� c�zvw��KTT�g�H\>�����n�@�+�{
(r8�<��Y���18���_?d4�>�jbUgm�U,��@�fZ�����%���#-��^m��ns�I�����q�����S?�C����/�S�R��0��=����T
���jI:��aKq���vV���f=m�� �a8��[X�Cu�8���' �IF��*V������sL���K9��x��NJ�����%{��)�B`�(�M���+�6������9*����#�g��h�D�����M��}6?i���S��mL��Z}�(���<~�?7����Vq$?�8��z����T��x�UV�bI�Y\^�wND��E�
����Hjo��o����b����h-��6����0_5JO����j�y=Ld�Y�,_j{��6o�����__a��r4��i���L��X�MS�E��2@������px.��9���A��O�����4@�}&K^�H��t��%c��N#����h@�h���NK�b3��B
�=�A����F'X|	-�+�
-�=��6:��>��AG��2�a�`hsF�s!PY��`��2�w4��d�y��W!C��P�c�St��["��tpVa��0D]8��R����������W�w�
Gx�
���Wq�40�����J���u�`����|��<��3��	j���H�
�[�� � � <��KhcBq_��M/�#3MFN����iU8|O��5�������0e�����	���=���cc� IDAT�������H�=�����X��N����X:u>s�v$��v4���?�)QZ�F����7���u�4.x�FR�o=�J<$X��e%��p�Y��F��IQ�)����A�Px1�?����v*���+�w���q3��+�2h�?��R�N�i}�6r1s�����Kd�x����%��.O�C&�:f�MS�{GR7o3K�:��Kchk�����t|k?_�6��-��ie�F�0����6���5�4�x���b���mC�E�oF��p	?��=WM8FF3�&kI5��l(�o�d��?�����z,-~�D� 	�����\�������k����\��EOLC�+�S{�R��6]>�
}�>�`���v���$s��`�M����S7�'�����KimL)�z�q�
�~w��-�i%��JQm(������!b��tU������<����YF*N��������o����`9W"��x�8��n�9�0�i`�E��3�cX�
�0�:L>
_��2D��_KM����U������<!#���Y�|e'�h}�Tep*xA	/G�s�����T��7��?��j��@�(�B����
��@w��~}c��qH�9j��e���2AAI���v���5k���/��[�{�8��w���s@��\��v�YyH����+=FN�|�_���������W2�3����.t����%�I|q���d����?D��g��F��e�������1_����X����a�nq�{r��Y�������{�8� �����Y/<��A�z��a�����7�������".r3o��+��� � �  {����=�=��dtg.r��q6~r
�nOS���AAAAA�Q'���$#I�}������5��� �^AAAAn"����������2I[E��I�3�/��������fD�:��6��'���9�������}��#� � �p�����*�����nY�CAAAA(S�T�� � � � � �k���`i�T|�8J�;���(���GC�2���P,{��t�9�;�P����m���N�e��F���qNAAA�I���f�9X�f
����+?� � � � � �'���`�������>��.I��D�k�^��p$i��p��>�+D���S�JY�������$�9"��=Y��v�&�'��U�P�e��\\^o��(�l� � �  Go�����I��=��1������ix��f��8���:=A��f���-w�}r����O9*]��/�V��J���s�9T0����Y��!N�����
g�:� � � �B,H"� � � � �Q"8(� � � � �Q�tX�CCN#���\)�������[�����e����g�����Gi����H��o@�z4�|����`f����|;�<�"�H���o�e�I�B�@`\�^����|K�����c��_��?�~�����E���@��P��n����Y�:�W�hrn����������^�sz<��t�F�����.��}�����,�4e��������/l,��������[d�*�8��2�:�M�I��}1�/�z��
D�A�[�lr:L�����*�L04(a�mZ2L�{���@���AA�G���H��7��K��|(�7k����xs$+�:?�����>�B��G�TV�n�i�izrOla�g3�s\�������39� ��������;�{]�}^�����6
<{���jY���`�����e�TU�)~o���������h� @%A�p�1���<���h	����J(���+����E��(>8x-��'�X<���*�J��~���Ni	� � �`�%~~8���I9e��A$i�������]�����9?m���U>�������~��G�re�j�<3�&��0����wiNT�/Z-�[��X0n;�_���q3*���P��6^����-D�C�'���:^��_|�v��w���	�:���{�ln��%
� � �Pj���;����Y,�|#��r�<|����<Iy/	2��K�)���~ho
��}����nU����Z�L[��]gHO5�
�&v� Z=U	�������]M��%�m3�q9���	������dS�>����p=���>Oi�����23,��I#
t\��K�a��+�����;t���dGZwf q� fnB��g�1��*"�
���:���L����������X��
����#��	Ch�lU\����KZ\���'���p���a�7��)9�#�f��x�<C����-sY���?p�G$���s5m�+�s��5���+&"+S�����U���U
\�E�.�%=9����a��La��-�4�{��L��J�	���/:�.�����������������S�T��(piO������?���-����:�>�����z�7a}���,�{%?������7�as�^�!�� ��u�u��s�\V������b������i?�H>s�q������?\�l��|e*=�,m���Z?�9��0�D��>��e=�=G}`n(8���|r�������7���u:�~�f@�a.00�;��!���=��>f�B����[>�(������(`j�a��)�$
>O������7� ?V�C���� �}���������i2����0��l ���
&X�����b���r��$�l�_�a����0>�?��MAA��HM�0��������!�<���&=S/	\���oio�����r��x�=�	���e�L~b"i~ui���x���Z��	o���s���y#�d:��m����l�#�m�W��S�>����I�3����#|�(��9;�g6n�C�����Slx9��	�2�=/���d�����g�������w��h�/c��������!�v�+�2�o���?�c���5{��_UB{~�>|�yNS0�H�oY�B�2��O�Bg����uR#��������%������������=h4?����3���o�5�K�U��_���1�i&������
��{����S��WhY��������OT@s�
�O�B��H�G��^�l�J�Ac8����$��m,w�����z\�
��x_r6����^B�2�'�Z����cIF�lH��Y5?-j�*�;{�2�������D����6��L6n3@��#��	��k[T���.J���IS�F_�x�/Y6��z�����/������� �o����~%�e?��\��u�{{,���a��k=h�o����WhY�������f?�}o}���F���j8J�v�w������
�h`�Y�S
?[������%h�\��u�v�@?����|x�0�����PQ	�i�9�:�l���W�R��c�02	j�C�I��*O�O��go~���p��=�+� ���X�q)�KP�������c��[�#)��1p�
���U�����F��+�E�����r�u���7�p:��� � � <���`����(��}L+*8T�BG�$�C����ZB���G���)	��C�e��F�Q�����wmR�AS�&�5����F��KX���^�Q��o�~�vc�>�1%(k ��OI��������D������r!�����$��4�w	�v�U���v�.%��s�R*C{�1]c��%�T�����WP
��SL�n�"�:��*C�T��V0������f�0zNg\$PF���K[�1��E����py�����w6]e�����f��>��j��y������#U���_Y����3>�S[7�5mR��~Fd��-0d���2�{b#�&�C��������������,�#�\?���~5Y5���ng��c���b���I��$���Gr!��&�|�ON�^� ��K�sZ�Y�����t����W������6�2d�����E�)+�V�Z�z��t1_��'���f���}�m95�o\^���u����y�T���}m�9�.<m�����v���������l��;�H����)�8�v[�H��2�^T<�����/��
�+A5K�M���%��iA�Oj7������Sa�m{�a��FCKK�m����4����y.A�@�}�gAO��J%)!_]��_IAZ0Z��nj�������jg:�d�$pP���6�Z���+��3���}i�s���h�[�����\������qKZw9o� � � <`���:*�26����Ex�P\����1�<�>��-Ks�r6��l4 5HGg�FEX�"$g��T�3����%�|B"��J7�K����Q���LUy�[����foZvRDD�Z��
���(f��R�L����oK�%;��;����o�������n%\��$9E&4�*��*C�t�7"~�S6�d�#���g�+�\�4K����~~.���U�aN�6�B3�olT�U�
.�#����H�����Ti�fsM%���o9e9�TZ^�*����M��"5AMtK����!����x���GA��<	o���1.�Sc�;?�F��:������#.�IK�����U��ND%�6�2,5���]�Z{���^����,m�*�c��k�;��F��g�*�L:J�U�A��i�u����e{��y��@�OXwG���}#a�!����;<����o���NBBJB�">5R�H%�(*"(�"*(���"* "H�����H'���m�?v!��&���y�����{���Y����	P1���X�t��0��i
�.�$�U X�I����|�k�P����uU~
$Z�����PK"�9T���P����+�����;�j�zf����gY/p���C��~�T�N��yB�;$!�B!������Am�G�1�����������"��>ty�!�]�������F�`u
F�L��V�Ny�%�d���e��Rl**���b�*��z9�z���t����4�����]�Ke��������nD�U�n�.|>����u��$R����c?p���U-Gj�
���;���_�!������n�]I":D�f�.��7'��\MN$5���q�3v��gTV�IMJ�H�~�|���y�>�x��^��k��P>���P5�x���
5��d0z;%tP0�x��RHO���P�}��`��sW����8��9������8�s����n\�r�=�MW��.�����GZ�4z�V�o=���Y�T�IMBm�^���x���bz���~B����mI�9�d�T���:-WUP= I�'��[�G�?���,���=��|��[
h=aZ�v>t�Z��C���*@UhU��\��#�Y�KC�~�T���:��}B!�B������|�FP��<��/��K�Y�
KF��:u��u���� �W�Sr�����ZH���9|03���N%=57�v�tL�j��F�����&o�RY��&$���[��x��yf���T��P<�p7�{�}����V�x��Za��CQ���kY>a��+��$v��@�r����Y���/}J��Y��p�]�}� �:)V���)�����L������P<p����d�= =!������YW�����~_��@�s6>������OIG��q��e:�s�����_�����oX��&���D�W����}F���i�0G[�{����X�7��.���7��;|~
ZU�2�v����u�FB��I;
�R|��`��	��L���p ���P�^.��}K�1����f��
���T�b=gZ����B!�B��3���x�����$����O�V�4�?{��,X��^:�$�������r�V�+�Og<�<�$��9=��0����}��p3�4�n;��Ly�3
�T0x�z"�Y���k�\a�LXm-qG���P��p��
�x��E�v���}��2}�:�mZ�>��a�3;�7F����#W��P��p��
!�v����&�7��o}b�c�j��cMFh����vs�����s���(�	��-M����8����3:m�R�[B+���'���c�?�t��P���v����q�\,]���U�#�}����v�$�����W��T���N?�B�0h�kT����[������]_-���d����?��������F��Ywo���%���P#��dO�����LP��;��3:z$*P��H�-Y��.�I�4���n��3��X{����6�>#��S�3���]r0��\�R=!�Bq���[�H%q�dn/A�f����y;��PqD��YQm A�IX�����)�C��q�+R���ss*�;e�.��,&���V����]�-��a���iT����s�U��Na���r��/��mPm�G��fA2�^mAH��GK��������s�R7�}`iJ��@���r�&�������1<JT�r����v`?G����N���(Lj�yN/[O�s�k�i^7�s'�jk)�.�N�����p���,��.����QcHg��|�o}�j�������������:���F�k�i�P�g#2�������81S:s��y��Q��V�r6?��A���H�8�����<���g�O��jB����^���B.�*M��u�2�K�t�QM�'��|��P��f����Q�/pzq���%�um��m���6���/�	r�8e����;����wf{�w�����q7]���=��-g;��Aw�=����y��^DV��t|'{��yg�4*ivp��
lG��dK'~�F�'�0T�Mx
o���g��2�!��X��nJ~�!n��C���RN3���)V_��
������M�O��n0��)0�4t;�}���j�l�?�����f8���0)��S�v	��
#����������
����X���4�,�;�A�e��J..���!{*��4�v!N��h
P^�.Cs-h��`�
<S6�'��~�m��I�q�����(��ca�tx�$���"��\�j=!�Bq����$
�J��,]��7�t��1�
���I���t#|������/�f��w<�:ZM�����a3��#V�P�u��N3Xz,w��<:�W>a��~lJ��D���ox�?n�R�e���FG�58������	"��W����?fu���vMb��Q�I���{C����u���}���k&,gY�K��}��I��U��������wd^��M�mS�����c���gDU�w���mO��72}�x�6��&�z�>C���Y��"���H���*����mF�jJP���O��������
��H�x���Etg
�-^��d#+&Og�7��JF���t
pJ��6
��>D�1;8d�MY|z�N��	,��R}(��;��t�gW��&�6>��Jc�M������KG�!���DUu�u��i��&��6��->�Iu=�F��Sk�,bYG�U�S��v��z�G����������
��U��BsG����a*�������{oq
��>�����>g��/'d^�����`�����P�q��.C�a�	h�5P�4����K0(z�X)���_c�	�����	�e� 6���
�N���q|rP�O�V������`�S�1����*���U
<[F�
���{>V����]�fW�I�`�	0i �>.
%0*�<
-/��)�O���q�P�+\�g!�B!�s��l�v���u�������[���h�����
	�����l��uq'����uy��������#]y�������6+m��f�N�6b=�RD�k���D�orQ�f�l%���D�u�;0$�oO$�"�X������
�3D��02���E!�B!P+o���$�#�B!�B!��$�B!�B!������9(��r�?�X�����(�����NTxo6#/2!�B!�BQ�$9�_��@�q��W�q!�B!�B�"%���B!�B!���*����1S����0S1@��t��'DA
3���.�!��0�O��neAw%�5�����+��x;���E!�B!��l6g��9X�n111��B!�B!���X��	�����s\��!�0���W��e	���~��4q�Q>K
�GQGg?�� IDAT!
���*�w�0�������qTE+:�#��*�0�B!���%O�+�	I��u��66���o��v���2m#�P�_�'DA�eJ%Z���:V��GRD�kC��=�u������+cm��k����w�B!�B��dB!�B!�B!��$9(�B!�B!�T�+N�g�������k3�W�7�����`Y�������YlY�Q���k�kT2I`9S�9��.WhO����z��]����� $�-�o�$<T��lj��=��B�bF��w���+��3�^�M[7���>���6.��6������ACyq|x���<�
��f���5�/�B���
����c=5�R��jL*4��[Zhu��U`�
e�{��>d��5�X�������}H��l/
���~	!�B�&����
�����a�pt���(�x�(L�ui:�#%��1���w����Y��E�<%|����.�h������|��#f���K��$����F����=y\�#h:�	%��V1A[+�u�N�����nc����E�jZ�!�m�K��
���(�ldZ+PQ�3*LW�I
�cO����W���SU{�������
k����B!�"�����-n%�p������:!
�b�l�h���^�H1S�eC�������qL{e9�w<AhCn�%��R�:�Oq�l�:wA[+�ED�m'X�9�_��Tm^_{��R��o�����T��Dj)�����^����g^)`�
�M�T!�B��}��p|p�����uN�}�!�tA���������
���������?�f��L��(��C6�
���]� �r�y�z��_�����p��1�2�����O�+��?������k�>��K�nw�C���4����T.�����b�'�=�Z���>���K���q��{�[�Z3��z����1tAK<76/f�����*V��Tz�m_���S���x�����qq����vk����M�b^������^�}o���^��F�	��S:�����{���;
���Cx���5������`�+�����[�g�;?q��+X�����y��P;�qF���8��?���%n��1�Z?VN�������s��8�>����:�I��1�C��������|�Oa����|���d���fe|��$\0��%���&.����$\�`�J��gi��������������>�����w~�.<D`�'�L���f<�=�3�5p�u�z�{$������5e
�Fm���x�~�T���C*g���K����9��</t�����[v��*����)���
���fj�����*|j�����xB����t�K�T�*PZ��x8	��V�K���B�J�(����*t������,��o8������K���50�)��
,U� P�1���W*����@'��/`�
����:i�z���R�B!�B�����=��X���6��7����c�r>��*��91o�a������)����s�j^�r����	����{/������
��ko�xA<�O��\���u��a:��~����3��SY�+g���?�uy��s�"2q1�������}���s8S�mg�����\��?L���[N�i�2�]��������%��*J@}j��85I�>d���-\*E������,�o�����b����4�K��OX��
**�+>f��>4������3����>D�/��up�N{���;�8�]f��������F�yo�66�������X�	����iXYO@���������^�v���K�����%�Uw�|\�V�b:v��A
i4�M�������X��Z���b�kH�5����X4��?\��u!�,�RHs�I�8��$
?jO��,�>���?���%^4���#1��~b�#K8S�m�D��e�:�~���S[_cO�	�03������gh�?���s���
���d����xO����a���e�l�^�N��=6x�~xO��l��T�
x�
�?Cp��;����*�Q`��+��)>�'�ha���f^=�A5P{Bp����t�D��
��w82��`�
�50I���6X���b|���xGGm�g���R�B!�B��������MFE��@�N�|�f~��&T������.�5�C�
��\�9��]�K5����=:;-jR���,Xzs�F�d�Z4�?����N�m�3�6������D��JJ����9�����k�F���*[���5nqU{0pv��j�t�O?[�����v��X��}�vO�;��������=�cx|������S�[t���RZr��4��
�U��D=]�a��/�U������������'^����i����mW�k����e��^���I��t�R�=�,��`��{~Y����x�����_}"�XQ]�S���g�`M�M���	��L��Iq1��[�$�b2YH=����l -�U��z�U���<=::-j\��.,X��#�2��z4~�������
�j�A����^���ya�eZ�k��!����:�G������'"��v�5x(M�:*�v���[O\����C���B@��|��f�=��������e
��}���{���i$��l��uA�W!&K7�50M�xf�S
L����Bo
Tu�k���
��{���Z�d��A�}�^l���j��l]�� �m��x�`�jZ���:8{Z�����y���
�pj/2&���
�Q�	�AY�*�@�����WO��V��������XG�V��#NQW�P!�Bq���XS!���7Z�j����TB�Np��BH�H��(~�U��)9�mY.�J9�����E�r!�UE�XP'�f���OFqG/<tX��0��s�(������X�}h�Ge����3��}&�'�[y5��[I@-�
*�5����u
H_��1�o;���I4��c����_E����'B����<��^�����=2%��2��;��-V���@���{�r�#��pr�����f>������\��Q:����bu���;�1���y�P�v\�@�[���7�
�2=�y���"��3��4�_�����X,6T�������2���^x���\��u!?�� ��V�����S[k	|�7-V����@D�
)���i'8��J����V���x�;�����o=Jb�H��������m��(��R�.�!�`�Y��
T(��>No�T��U2K�f�@q`�{QY������^�(�/��=YW��F��e�U��@[2�
PG���lQ���)�C�o����'Z���:B!�B���A���n�#Z��vTk
�V��G�����[�<v;��,\�����WG�`Y
��D��uV�������Cu���
�������Fw��:���ErPM�A�����/0v��6�j��*8'5�x���N�=����s�V��L��_�^�5"%5x�S�G��\v���$�Sk6�"�Cs��z���I��[8���}��C6�j8��@�������G2���X�����~�Rz-z�`*�J��XG_�+J�`����Y�~]��%�\�f>����\l�:�X1���rmDD�0�l<Bp���e��&���)�F1�m���6�ji�5E%�Z*���n���s��D����+����b���V���\T�>d�8�������{�zT�����U���l�'�)��{�{��?6�;K���^�Z�B!�B��?9�&� �����7����'(��*��)����j
iI*��oY.1d��xJ�<���J8�i\�����<P�1zAzB��B���c��&�
����1\N���]�#l�8��q#��
x���QP���Q���������*���%6rL!�w���,��+7u2;�}@�r��W<��n�6����g��b�����r�����I�r���m�i��f2�3���qT����A����a����W)��TZ�u\R�dK����z~;��9����M����_�~{*�������*��fy���w\Sl�����$R,���dWT��BM������v���}��i�Y�d
���[����ro����O(���O��cR�.�7�'[
�u���)�:^�L�Z�B!�B��B����>3�������-G��n��P���i�U���9s���e��`�4B|�Yo3c1)�����9�{z�w���&�������$�0�v���Rp����DRn�c9���N��V��zZ���U����~*������jjV���W�a_\jt
.�!����.����8���F���#�}i!q7�2FVGG���x��%���Ox	�q���A
���`�/������s�}� ���1�7���n"ZXRM�<�\�'w^np=����q]�u�.�������h$�������/������U����>�������xU,A`%���m��"�I��6�m�3���������0�g�����
��m�'�(��5PU�wU�yi5(�Y|Oe�0���d�H�$���[��8zL��7�0*������
T�>d��~���X�1D�M�Ozr��s����nr��B!��d�\Q�cl�5nCjc<��5s�)5�9!:�Pj����f�h���Q�}��������/�&-%�*�����_��n5O�A�(Q��P��
u����S-�Q���G|������4��*}����<�v�q�;W�����
J��+i����k�V~_���������j��IM 5��a{�i|c�F���p7�sm���
��W	��Q�-I��Y?���������@M���eHw����%�e-��l�7�U[J�ty7�����4[}�����\9�� j���n����	����n���}{8��-?�`h�w�Y�����0�?FdUOL'v�g[1v�O���Au�&���Em	��$����>��s�mA�<HX���m�)�G��q#���t�x�*������0�Fz�/^�e=Q�U(���������S���G}����.�5-����$�y�5�i]	w���c��`���� w��;s��A���h5��x-�����c[�:�������G9�7���Z���A�=���NC&������f�V?b�7�O��v� '�b;z��B��]�O�b�Lxu�]����^EB<������|�2!n��C��D�H�;�����j��|��F`�
v(����+���<
�vL��_����>D��
G�J\C��0���;��.F:�s��4;�=��[���+�H��*{�<�����K���O�=�I�&��b����mj���f$����l�����T��d�I��:&(��>���,�v��B!��rPS�a�5:����H�'��atx����B�������	�>�������F�������w�e�����?vLf��1�I���w4C��D�	���!\}�K�U_��7�r�z�����
q�������9?O����=	y��:~���k�u���t�KLLX�^D=���2�16|�>?����,�u�t�~�Tz�����R�iY�`�I�����n�~��K����vd^f�M�?�P����o�!p��DE�3���i��&��|����hRU���3��>�5�~bY���|���N��52�3M	jM��~��l�d�.�p/I����t����'���i����7B	�����;3�vn�L��?gu����������\��e
^]����cY��+�IU��3�!�������\}�#�=0�oi��|��.�Xz4�����l�=�y��2���^�&��q��W_%*����)����w1���lm1�&�tu��Bo����e=������j8�������r(�q��<m����Q��:��V��a>��������G�����8�B���
����P��B�>Q��*����J*��SUh�H����>��+��ghOF�L���L|g�k�m�rZg�j�����������rq�}�
�^O���=��h��xo���16x^�'��i`��j�H�9w�m��7m��
�
�@k�u��5��{)6�@�,u�J
!�B!P�fs�����[GLLL�7�"���u��M��#�^��]o�i��m��X8>�?������������$�4~�c�N��K%]��cYw��e��^�6c�B��0c$������T������Y�Tb�g�N�rb�����7$^!ZQ�a�0��;�] ������i�[qTEg��O��K1����E!�B!P���1y�}����g��e�
�W��#������4�*
�J���\9��������-*�g�A!�B!�B���>9�V���%l�z��:��=@����^�$�
��ScG0�G��~�GF� ���
!�B!�B����A��bdk)%�h�$�6�{�r�?^^�����������\*�P�"���x���f�~��2c.�gI�B!�B!��I�qr0�*Po��+�8r�^�Y!�B!�B	y��B!�B!��Q�s0?f*��/}���B��<!
R�60�u4�B�D��	s��1�I�a��EM���]�����:!�B!��W������`��u���V<B!�B!�B�BR`=[$v�����s\���a���W����;Y�akP#�:
QN%���0C���u��qTE+:�����E�B!�B��������$����z�[��2Fe����T�
��Uq��e����n�������Y�������#��LFT�6$�)��B!�"_��$B!�B!�B�GIrP!�B!�B���V,�X���Y;����k�����[�uWJ_���^F�l=����Iq�P�r��y\�F��A(�Vp"��G��g��hQ����e��7b�9�4�,�(�]�ut���`!���������?��kG���Q)���,E�C�[���vD������hi>�	SS�,W�
���M�� �0L����{�j�o/@��(�����?��T�K��n�$F���)��N��17Y���UP��B!�B��$9XX�e�?5L&�}�E��L���J8��tl�O��q��O��P4u59x��nD��=)�t�V�%)����]��t��6c�b!T{��(�i>�!Z3�G~��i3�{�L�}	��d��C��_����|8D(P.��P�P���W��������m���~0)�68z
>:�l��,��aV=H����y�Q!�BqO��n+�c:�J��
��
$u<w1Cc�|�N�!D^(n�(��!���^�w�C)�����K��C0�Z6���������������6,���J~P	���n@�@h�/R�z?X���b2��?��V��m����2�@� #`�vzB!�B����������������s��sv��+E�~�����x�����sj��,�h#�LA��7������/7��\,��-���u��r���$\3c�M��Wi��*n
����[����t�z�m��R�'�]��erg���"5�3G�t�*.�{�c0�R�����^�o�������O�0q�����6�����X���KV�����.a����#h���x9u��,~���[h��
G}��mg����/��%N����i���Y�V�JY�\���',���7P�Bj���S��B��G+|9�G�b�Tx�Ci������������	�%�
['&�d���\K/N��(g�q�e��tL+.��/L����;����o;������{;�n(�=��s�������@~+�2���q������`��8��q��y�z�'��������|�����g���4�����en����@Z����s��jT�G�M�EE������8tL���B�:��w����s����q�I�a�I���aHw����(�du�s�jx��m��_P/���#�U([�*=��w�uq��B!�w��89hg�1���&�{�g}���/�����C���9�1o�>J}��5��t*������.�*������F�
����������~,�\J�n�o
���������a�}_0��hVF5�����TI]�6�
���so������9 IDATW����e�P/w�m�6��]�"����~����?x,���,�n9��AqT0�''�rt���'�)%����VXL����y.��w?Z�q�pmS
����U�HH���p�B�c{kM�?7��z�m�p���<�BE4(h�w�.����q��a�w����'���3Of�V3t���e�������4cJH$�9��w���G1T����s��8�}��=�IY����p� G�-��j^���n���sPo����@��Or���,��6=�'e�G,_�K���qn�����'=�7m�����
��5~��A��J���]f�s��ik0�_~�����]���hEw����$����)����/��pXV����A]_��h���9L����??���5�<�"�i@�b9���tP����?��A��ViT`�x{?x��NNeN�%�B!������A��	MF���@�~�|b!3�Z��/��f�����'���vx(P���5�q�[�W�K5���y=:;-jR���,X�s�6�/�h<�=��@p?�6��U��b}�����5�\NJ�0��������k���gnv�v���}M\�8{��Q$�����\���v�O�^�'�;�=Q��`	�@����<�*�	��P�X�i�>�����.T�x����nL��Cq��L)�&�fP���[�T�DU>����j��ydh[��P�����q*/e���i�1�r���y�fZ�k1�!�z���6"������7F�'�3'^Y���94����(��j�WW0�j�����_a���8+w���_�|�d�Tn����z�#��vt��]���������q�! �(��\����(�����e���_L�����u��>�OXQ���%9��B����w=i��R����~0�8���z���$�`_��RZ0���_|��V�}���J�a�+U�d+�T8v���@x ���������>�;�L�N����B!���s�'5��}��JGP��h>>���P���?�����U�:�U��)9�mY�gM9��&���?�r!	���j1�4�F��[�a4a�)����R�=����U��R��(��Y�{������M��v&�������v!��p+����Am������C�n@������&\,K_���o�<d&��ekW����,*���qn���a���5<X	�GXUm����e�w����e���91��e�C��W���tK��]�9fD<C���q�T����W�
���3s��e2���Z�~��;������3�L?��?����4s����5�0�l�������U�j��3����fz��-gN��7�E_�A���@�"~�@Op��D���	�_E�;��KP�R���~�Iy�f��?����S�s"\������lp+�_��%�B!���}rw�L�2��-�I���Z�H�*��2�Y/����9��p%9�&q��'Y��$
�L�m�u��������=�t��O�R����vwbK&-	�>�N���������@�����m;��
+V5��DB��k|���[��Z���s������g���8L���P�L�A��7/
H��G>�jr2&����SBI�������MYp�c���rA1'�����nt��,�Tg���wnK�SG�\��y��	��M��z!�J�1�5[v�ps�����&'��n��{�3v�s�6������H�~�|��)�������E)��o0�8��Pe�+��=�V|�����W���
�j�j����j7Qj@���}p!�Q��%�B!���}rPMH ��W��z<p�TP��a���&�@���L��%����!�+�%���_z��/K�^�	�.YSsLNO�^���<m�SRz��4Y����L3*(������
���m�dz#e���kP�xc�zY�u�c��cK>��9�X��X��oB����y���C{����x�����4�s>S��9���nL�TV>S�/e������L����xx&��k���\-8���,�`�V n�$v��@�r7�,��AG��Oi�:��D�����v������X���L�T�e�������u�!�u`I��fT���8[�C��B!������D�������7�-�rv�^le#	�U��
�*6� ��S����K��u���������7�����`�+��,�O����z�@W��	������H�G�nN�49�����
��H����$���2��V��z:�^��b+9�T,�G~>�>ei<K��ST��t�J�������C�V����<o2��
���F����p+��v������YV~��g��w9�]�F���X��7��o����c9��]_/(��n�y���?�x�>t��mZ=p��//���I�:��\�+�,��~�C��h�kP����>1s�X]�Am9�;��[��C���n��~8%��C)��5CcO�����y
xh����=�l6���>N	��D�!]�B!����=e[|����/`��$J��L� ��������h���QZ�}�'�y�[�}Y7�(U��y���"u�CT�e�P5(����Y_q��@���a���9x]�������}�_z���^4�����S�{UA)s%-~Qu����t%��q�����XEB������U�1>K�����pm���-K�����)��������*fUE�;��3F�����]*�F�7��pk���I`����3�y���o������N.�CBPO~���m=(S���7� 7��sC[�O6d�����H��p����g��Na��j�YN/YI�����'�U}����3�U��h��I���N����X�I#b_��6���I�~����~�v��y��g�yN/[O�sGD�!-j��f#~�Vm-E�����'p��|��u�}�ZM5^�������Qm�q7_���=�_���� X�z�h�r
?
����������N�l+N�����x����>��Cv2�&!��X:l%�>@���{��ZT���g���V8�
�
��A��| 2]���C�
f�����4�[c�_I�IJ����U��4�c�����)P��x�z@�=�������������
cOB���B!��~p�'5�bi����&QS�������
����^��q�
�}4����	�?�F�������
|�e�����
:�����������+�Li�VL�)���{��>�o�z�@L��,=�O��G���?��'�d�toBL�����|�Z�F�����,����K��%����I�����Y����:K����:Tz��.�TL����Y������1L
������T�p�,
�*���q![��$��
c�ZDN�N�V�w([����;�����������4x?=����sC�����qy$�o��_Jtz��M���U
���H���'�f^fx�v{���iK����W~ �����u����L�u����&�9�?��,q���L_�v�O��i1K��C��������l{�����Q���!M"�<C�9���`���H���*����m�5ES�Z�~�~�t6:�]Wl��ERe�sx�_TX|��d,�rP�
�jr�
����N-����&`���~���`�)�����/�:���l#�+���0z?����:�����N@�Y�q��e��	8��b�B!�w�l6g;jj��u����z�-;�o���n�`�&w��Q��7+5�X��NK����
���}�q�f�r�_w���K��Ry{�������c�1���^�+cc�of���^���(0�����w�Y�sAc"�X#��K����U�Q�
�g�412qfQ�"�B!��%7��s�}����gV�e~A����q������h�9L��
!�B!�B���>9�V���Yl�z��z��5��woR/LR�B!�B!���v'�T��+#sXK)C�%1���������l�N�f��.�:�?�RY�"1���s�������!�w��\B!�B!��}������:�zEGn��1�_$��B!�B�����B!�B!��?��z��������r\/L[:_�� �i��:!�$�P���������D{����w��E!�B!��l6g��+X�n111��B!�B!���X���W����s\��m-a��W�"�N���
)�0D8��%�0������0MhGU��������B!�B!Pk���
tB�h��zR/��e�~���4��7���	!�nV��|{�����2� ZW�����h}tFT�6���CB!�B�M&$B!�B!��?J��B!�B!�B�G���"e�g[�1,�b�cH	��������e����|�-��w���ie�%65��]Vtm{���p�q�����&�����}�GQ����$��)$�@Bo�z RE@T��
�kAE@����^;��r�	H��z��f����
lB�ME|?��<����������{f�p^�*����Ka�{Y��~��S��A�z�T
|�-�k'��������Vu&X[^��K��s|�$��O
@�h���%&v�z�������9>�=������7��&�s����fs��-����f�PJ]�s�k��[[��yM�������9�?���(h�^���!��t�'����^Jj'�^�/���a�3��k���x��ai��uM��!_}����'JP#�;�����a<������1&��>m�4T;���hh~#���'��7&���e���	�a��#��R��Z��s#����q&$��[5�`P t+�q�g@��6R��a)����B!D��}��.����7�F���=;���Lf��x������W���P�[�6���^�������a��T��J��������g�������{�>/���gr�&�M�������/�M�.��}6F���C9nCq�	�I��[����w��]�w{m�\����N9�9��jv��M��$��4��yX�x��+�E��=�kX�N'i�6?�%Y^c��T����>�o^8G��.�i����Y�-���-�hx����<���W���M����E1���Ym��������M�����vF��X�m�4T;|��}npr�o��^��Mc�}��Q�41
O��fx��6�=�K��!�w]����,K!�B���>9��DP�{=|��z�����;8�vM������6�7�.�-^������@NYk���t	+C���������u��4{���V�-�!�HT|=���
����������m�k�[�b4_����Q5 ��c'aK'"��jW�Z�*z��U���#-P�{ y
g�s��z7u�s���	��0t8�N)�Q#�;Fu�����������e&���8�(���k��^�d1u��$liw�=q�Q�M�n/��F�3!����-�O��7�fB!�����O�Ak����C��o���w�������~l����_���'�
���Q��bO9�8��\�~��T�?�Gt���}���Ent�{�����/< ��k��ld���d��1��P��>t���By����"��=������P���t��k�J��������L�:�7>hF��B��^���6�{��������T�����q�D��Q%�Cd���iw�����������46����F�.�K�<
��"	P�q�p�[I�n)K������Q���t/�������m?�f��z����Wa��4��!�{�A�t;�w1s����y�T&L�0�a��_�Y��?Y5y�7�u��*���DO��,z���)���
��e�����q�2cK��n�v~y���{��O��Q\�lnH���l�����������8��#��s��_���E_�����g�������=0�������UK����u{m�Y�w��M�����k5�=��w0|M*��u�^�����{��
�����V)K�yv�����;�:�U������@���W�mA�r����7����p�:h������N����}�I����{��E�N��
�gBBd���A��^Y*�{|��
f�B��A�/?.l��L�9�P���`/V������YL7��4H��I�*B�������:A!������vx�$���o�����=>��=60�� �]��[��y*,���@%#
�����y�?|cv-���$���� ��}Z�6�����h�a�0��vN��;�`RlH��P���<k�k/m��'0�F����d�yht���Z�0'�GF>|��,p��z�a��}��o���������B!�-��O�m�X��6r��q~�]�Y��JT�lo����E-~.cET���b���D�B|c�>\��
6����v��;-��W"���S)����z���s��������2�4�A�����t�?�!?������9���=���09�Ebp}YWmd����MJ��Y1�{�������)���o�����=g�`<���	_���3{4�'q]��d9��(����8vo`����]�����2�H\����L'G5�T��/`��������^��^����������n
��d��,����������Q�
~����"=m�l8�}��2��04����u�R��$�auh�v����H���1�4�A��pr!G�����_)sN��[���/}���a�Z����e-kr�0?]�5f�dK�^4ix��uW�i9���
K����U����ym���`��!_�lZ�!�G�(����|���s:=F��F��;���r����!~�.Z���>�Z�����M����&,���sV%��Y��w|o��G���82�>r?���K��\��e�A�Z�D��K�F����N�u�5�/&d;�P�u�j��
 gr�d����f�'�@�0x���Lnu:j�x�A
������O�p��`&
�o�a<s�@_�<?����0:��03
�P��/�f�	v�7^�����	@O����r�9�S�[�^
���/���5�a����LH��2����������	C\+v�`�)�]�T�8�����������t}
�����6g��3����G��@g3L7BN�T��`v&�7Bc�D�F�U��{
���?g,���2��������R,�i2�i���f�L}�B!����>9h[�=��}�|������{�]�t=�tF|+���^�2��c?��iPz�����V�Z�����y����!�t��`������&���n�k�[x�����5�^�P�h����Lx��M��T�/��%�����$\�;��Y�����@,:G;&�#%�;cfv���&�Y'���M�|��4�u�0�v���d�����4����f�,v�h3�1a�@XG���cya\�&�����S@��N��D�L�I~H��Ws��i�M�1��-�#Qw����H��@�L{������v]����L�
`�����st`�kSS������U�����G�jP�g��6���,Y��f9�����uK?���m����^��4n���>�.:M0M�����e,�����`":����64i�Lz:2�1y#)�]3���X�Np�)>�d'��J�� �ZO�eO�)	��N(2M��7��o���:-���~>���ur��=��}�vM�5������������KU�3���'�s��x*���e��7{(w��v���/9�m{{Y3!���z�8���~h��Q?W����}�(��+�����2v.�\3/�wV�C���x�|��h�[-���C>t
��L��i�T�+�le��w�����st�k��ey*-:f���;�]��������/����!����
>��������m�����.;����_�w8tt5���0P�<���>U���l�
�q��u�0���0'�-Ou@�@x��-���������`�I�����;z]�P D���8�t�K���S�'x�5>����&f�TO�B!����>O�m��{����a#��>�NZ������'
n��y�8�O���*�JH5bb5E�h�ds����b6�t���y�l*����&�|4�6&��6�]|�']� IDAT���Rt���+W�!*�5E�O@�[zVt�G9��N��w|�"ACP�*�N9��d�J����[�6jKaM�G����~�6�"S{��]����B�5���)�-.�:x�����m���w
���t������g9��N��*��I�Dt��������{��#�o.{��d�Y����|:�bj�S�
]����~���:cR��h7w$���!i���n��S�[Z���jh����sl�N��>��Y<�O�O��!h��;��b��q��N9�<V#<�b��4-un������HnD	
��B�ZBF�����Y�� �i��g#.�!�O�b�[,�J�N9��E%��$2�������85�/�����S����0�G��;�Q��L�������2(p��H����p������^���H��+T ���[�_��>n��zA
�le���������)x7�������������0"��a�����;�GLn�P��|V�@(�G�s��V�|m9�{�s��^^�����z��6(����K���
_W�-9�!��z5���&�s�����\8js������%C�_�>B!��o��O*����:hS�s�X��O��������k�����v!�����-^��O����O�R�80��-
��[����������e�)�+�����A��\m{��4E��CE��\�
��0��o����]�$/SE�yW!s,��t&J�AHp��R$b<��E�-��.�%ns���@�A�>�Lp
����a!?�����f#J������i|0��
U����_1oQ -�����0j���N9J�>����GB��Jb��+�m�r�l�CU�R�������������[�Y6
���oo�������%������+�X
'/C���k=�B1���
U��SD�����(a�b	s��jN�+��K���+���<2]�g�E�9m���_��;�o�0+F�����q�R����5:x:��@��g��\�VZR������$���X��_��h!��2=)�4�Zh�}�I�z�f������s�r`U�����tP
�
�������6�P���k|~�� S@��`a��r4��s��u�O��ta�j�iI2L���A������
)0�K��W��B!��[�����j���$���i���"�?*��]�D����S��ZQ1��'_@A�
���t�D�7bK8�9k��o�!qA&��=N���]	9g���������(�^VL>x������z{����'Z�R�A\���mQ��e������H1��2��}�1����|��*�t���%��((eM�X�H\�E������ W*���Z��)�"*R�U4Z����]6�����<�|����p��
>��1�+��'=G%����AK��cJ8Vu��x���z�7��N�L<NP�0R����{�y5M�:��8�
�8���������/�-��~�)5z;_�6X�
�>
|`��'c[>���C���������4�5�_����S�&��RVI�������l���0-:U������
<��UXQp>�@q&33�\�9���7����B��	�s�e9@��T�3��~��_��)�y��S�"ZW�G|/��v
�B!�[���������z���fZ6����m�����v/C�`2@Zy����D����/��w�S��g4Ru@]���`���"�"jNV�[��1��J�n����!�UU���������4�R����&����=���#����F>O�*�+lC�b;�0"b���v���}�����Jl$a��KW���<����a�f���
�LR0����{i[,)��mi�S���6���\���K)��j>���u���z0
�����^��i�!eo�5+R��U3�y�z�k=��#���K9T�=w/D������-��g�"]�d�[3��Zn��fW,[G��u�]����g;p���������8������-�vn����f������W\~	%8T�R��Y������e���>�P,p���YVyr�`�y�2���[od:�|#�W��b�P�����#��d���b�^x��@,�f�BRI���>��&���/�����jK�#�i�����V���b�u
XJ�������bbP�;G..���%�B!nu�}�A5��%bT�X���0�w����~Sg�����NN`����"e����@AJ�9@A6VUEMI#=I�S%� %N*��A��F�L�H�Xo��aT��B���������2~�F���&-'1Eu{���w��t����uO{j����x�����Q��Tm�c��������)$�_��������lO�����O��L��^:��
f�?kSt�����i�R������n����� ������3�.�;��$����6�0v�7���=�!k�������+��Uk�e��Z_6��BOi�m$c�&�4P��m���P=���c���8��#����8~�e�����*��nk���4�}h��-��/uo���l��1���*��;��}S���"�����/p����/H�j�=�	r���O6|r����`��Kql��=3
����wA�;�8��m	�p��B\�z����N��D,�]4&����� ���,_L��q�zk	��{�.g���>6�&�/5gk���ihO\��xd��#��;��2�a:��lI��;�y�L���P7�H��#l��O�g�=8��X6lb���	�\�p��,|�(��������hj�������|��C#+�9�hal�,�FU5�k&t�8G	��9����?eBk3���7�Jy����no� 
��#�in����J�b�U9E{�i����y���)�U��Q���p_*���a���c�Ao����a_>�����u���a�i8m��8���
��!����X�����cW�B�mp�}�h�_��h��6e�&��-�O�*�8
;���"4p2����f�]�	�P]s�a��36�"���43��LH4B
���V����B!����>9h�s-��^����&�c<�N�B����6����Y>�.��&fxO��`Ef�
���$�-t����I��,�u�=H��9*��G�m�X��gl�U�9�g�S-
a���Yr���3Q�o��;U�.m�g<���E�6�g~<��I��	�J
���c?3��*��
T��;��~b�~��h�h8�	�S�~�w�u��w�j?�S)�-�����+����{�c��X�*5���_�����<v�m��0v�7�����?����e��fAU���� �����5P��>4��wM%��G=����:����9��"��]��B��]����6��{�]���?�����-����5.{��>�-Zla��[I��3�m:�{�9>3���3"������/����dR����W����b�
��3����j�fl��a?��r�&Ns���Z�u�z��u�RT���X;�P�i�*��k8�,���_I��{����Ji�4��{����l�2�v�:���0�'_VN�����X�&�U���Fc��i������d�~��s*�U���Dl��q����e;$�T������+��#��Z�>���78^�v&�^���C�t��C�@�y���>}+��x��k�k4s��w#�*��<x!��4�7,
��L� ����3D�?<���@\8�T�q|��O2�i��9������b2N����Y*|���(#<���kb�a0�$����A�6���"��O����<�9���W���I�)���Y03�;�O����K���=�%��� Wu��<'��}�p:>h��?<�W��xZ�B!���)V����j�*���K��������b�+V���3��IC�+�7=�k�{�^syB���n��p��7��:�^p
�L�Z9����p���\������Y����gB!�B�@mp��3�@~�B!�B!��J��B!�B!�B�C���B!�Mf���L����3����a�B!�B �A!�B\oZ#�R|x_!�B!��@n+B!�B!�����,���/��p��b�W�Gq}�h�<������x�b��^[�&����F��7�
B!�BqM���^i�U�V��#�B!�B!��A�[����g����z/$Fo��<+1���V����f�c������Q�9bA7����6����]
!�B!��S�/j�J��/w]$��].���B}�+�c�L}�r)OQ6����j7��:�n=G���n�-�fWA!�B!��P�����$B!�B!�B�CIrP!�B!�B���z[���~"������#dYM6iL����e���eF��~��s����C JI���f�{�X?{g�9��\��C�!~l}|�-
k'i�������V�#X[^��!��,x��j�;��?�W��(-��P��t����T������������z>��y�*�j��1�_�W�=�jC:t�P�;t��+�qNAj:G�Y��j=h�&��c�J��X�c�l���6�q3�m��?���%�HVAQ�L���%v�H:���P��o76���_Mu�[wJP7���5�kC����������'=�c��.��y�?���;�j�`6C�&0�-���	�I��Y��jSh�W������a��N��0�Q	�������DH�@���'�B���������,K!�B���m�T�meA�wI�5��O�G��Ul��'
�w��4YG:G���]=�������	���k��}f8mj����'��'��Dy&o��Ft��'�Zy{g����n���ka�����b���O��f�U�����?}�mh�f6M���X��"��\�#���|����iZ���6��3�����������5���]C*A�9�f�a��/�e��w����+�F���'���(�0�5�������9���1��y���;����vX����g��5��V�d�`��,���/W|�-���;A?8s�'��m�&��>�q#�B!��6v'�$�3��i
��e�������v���4����]%�V,V�?�u���w&���������b�S�!D�7��������:v5	[�V�W�
xa�d�@�����)�P����������)L}q9	����V;
��
s�ir/7��>�5��E��R�������-�����?$;�xU$������u���b�k�h��On3t��Lv�~����Ghyz^-��x+�W�,�3����x�����`X{���4t!�B!nc��Uy���f�O)��y��Q�/|+��w��n�',c��T����9j=��u���\��1�7�5��g�0������3��X��qh�Vr������C_��/[w��������8�v�UjR��at^�h�2����������Y^UkR����@��������o���d#�we�	1z�#���|��OH�����=T�]m�*�6�F��H����jx��v��m�30��S�r6���K�
�
j��$�L�����y_���5K�CY�:�����50��E����^�s���l�v�o$�&N�O��|;�����e��h�c'������U�/b��$2Rm��Pw��t�����h�S��j�'�'�>ZI�g��w���{\��������6��fw�Gq���}��c�������Cx�+!�������[��N�o�o�����M�u��}m
��U�z{	����ILm�>�]�^�}b#��������V��������x��x|����P�A$(G��
��~\��c����w����Y�<���ba�j�#
L!��p�p������L��������{���l���B�*W��{�����5R������\��;+�|�S�!�B!<r�&�G8��!�Q��,�4�o�/��y=g��xl#k^����w�h��I�����l8�}�_`�S�����7������|t��z�^�*�����o�\AG��u�����7�����E���|�������1t���e�_��z/9�W��J�����������4�W�b�,k����9oy�j\��O����'��8�M���-�7�������d
9�7Q��6c���y�(������{��E����s�6�T�~���c����C�^���sY�������A}��l?��g��6�IFL�vhG�*�����Y��g��W���5���Ah����**����o��'�j~}�_�7}��~e�
��#������_);�9�.b��'��l���3���X��	�
����(���'2�^}t(-���K�-���G3��6N.�Jv�����T
$=�9�'
r�~����0��_�]����,���tP��TX�����C�X�^�~O@�b	8�)x>����~ph?8T���>�1Z��B|}/���SP�6���������'�����jC���[-zB��K�3������B!���}������C�\{*�\v�h�������1y	)��3�?��	�<�'����������T��yx�Ak�Z����E�yC��6�������6�}]t;b���X����,d�b
�g��]�|�u����#��n���h�>F�p��&g�c�^w������9���v��K�q��V�Z����K6�[N>y���f�F�CZS�������04��[m����4n����4qRm�r�(���;��5������Mt�����5d7���w��VG�3�E����{���=������!a���Z%"]�������AA���RX������v��:��!�[�k�v�LD�`���fI��w_�gr]�}W��2�Mh�JGg����-~b��}������^MY���+�L�uz�g~���&�Z�j���M�oF5/�v�}��<�%!ZS�Qv�Q�m}t;�g��]X�n[�������S:;�o�����Xj��������I�6��=��z�.�x�����a����j���E�n��Q���K�;����V1��mXv���,M��^��s����@KWQ����5�.�B!����~�Yf�Zl�u7�����0��G�[����V�/�|������Z�N9��d�J�#)^^IrO����l�q7��s��TT�
�m�0h����L�;���[�����]�j-�B]S4f"u�������� .�$N�S��@���)!u����$9�&������5A��3FP�\�>6W��JL4L�E�`
�_����B%.GMY���V��)�+5��g��m�����66�\�Q�D��F��gm������V������;N��Mg��]$���fs��m(q�E����I��y&}��I1����)�nP�{�5����{� ����G�7� ~��"�(�Qx+
������|�n�R��G�f�����s`y'H|w�E��lv���uF)��nDY)B�?]o����l�`�T��TLSO�
�d(u�)��u�K�W��$8�6�vh�.�x9w��_caE"�;�n��	0i	���e����.�B!���m�T��Q����bF�U!�����z��*@��"�b�����������C^�
�$5~�+�����R�Ps9����[J�����q0F���'�����[T�K�� |��g�Ev��Q���z�����^���I����57���~D��C�T�h�bw�k�n?�q��1sK�}Qz-zs(���/�!5��l0���-�`0��b��h�D��)��35�/���ea�|�z��l�����3�R�3
�������$�m�~{�k��|���8UWR�w�-��b"�U�\�����:�3��x���!y�f��[R��+b5�/�g��0Z�1��
�1��x�%�.�>��UV@m����`����^d��Id���jq>G�H{�����N��	�`E �
�A����G���}�8_yg�����M0��g�&J[�k�]!�B���69��T����&$a��N�!�Im�N�!����AG����������3��@� IDAT`�"b��q���J%=w�����D>�&��w�I>g����M��I��2�O�R
|0���[����>j>%�T�����C���o�Q��v���mK���
�/_�d�A�b��A5�1^r���R��]�D�����t�'���8�(K[T��W�R��h�Ot�>���g�%fL@�h��*VqX�e����6��w��z�fN�����'1�hE����u7����|�m�
q�'�����2J��n����"�4�������@�{�S����pI�S���}�����lx�!��XkW��;zW���!Gu��,��\C�B!�B���_��u��L���>s�� ^5�i�%eo�5#	�����O�d��ly%�.����M�NZ��%�E>Ws��8���`4����������5���V�~�.Z����<��;�����=���yI��[�����d��,��w�(v����&����M;H/l;j:I�P�� ��IrZ=��K8VVlVg��r9�-����`0!=��6]R�������~&)@�w�/�g�[���g^uH������qT8��=6�o_j�Y�bOI�[�����OvspKI����J�'��+i���$g�mo�����f�`��\���9��'��m��.��B-l9�����!�t�D��G!�3	�_B�r��p���$��%%�0�!=�b�
�8Y��#;N����<�W}<q���B!��}���ya8�>[Xx�{��z{~\����`�8�hBh�Rw����O.d�/;9�d=��|���p��zCLhmo2-#���$�;I����
����k7;;G���a�k���T�����V�P��qz�M_�������c�L�d}���e/:vw�c��,��&�������3z�����x�6�#P0���[:��N��)eM�i����?W�fz������\�����(�L����[~xy	��o%a�d~Y�E�/>��S�
���&c�B6&��qR�]������B���?r��{�Qv���e����-��KX���p����>�{���b��#]1�Z�����hl^����s������^)q5�I��8���`'�n�$M�8��8�_���tx�4t��j9����:?e���.�OZ�A��R�|�����tR�>����'����c�f�p��3I8���,���X��T��J#o��,|r*���A���g�)&v��^��������������P�+6��3p0R\�6}4��w��2���e�YR!hV	�o���������q����-�9;a�v�8�<}��Xn�����B!������T�����h�L���2������K��O�$�y)hl=�a?
 d�2~��#g���,B�����C������4	��������O����{�i+����]������C������h@������i���9u�gr���r7����VZS��_Od��A�������6�><��u-L��[W�K!��'�����br���NiM��e��\�������_��W_d���P<�]�C)xwy��?��a�4���:K��5�-��
*C����<F���Y1h�}���o��X�����i���9��1��[�B|s����?��C�9������'����K:U��7�C��V|��d������H���{-^`mj'���z,�[[�_�}�-����k�L��%�����3��3��uoEd�g����q4�]��;0��v&~`IQ(�E���8���|��if}���>��L�'"8��c���%���H\�W��^���k�W��`�
o���}X%���������������4�0y�vB�7���}M%�G�~��oxc��>)\O <�r��`���4����v��s��!�B!<�X��+vcY�j����^q�����]�����~�p��W�����^w�KyB�����'���nv5�u0����~�ov5n)�s9,�NB!�B�":���!��T���r�u�A!�B!�B!��IrP!�B!�B�(I
!�B!�B�%�A!�B!�B!��$9(�B!�B!�?��z���F*������F�[yB����T��U�I�&�fW���f�����B!���pd�i1�j��W�a��U����i�B!�B!�B�[�u�9�9y��Zu��f��pv�Z�B!�B!�����Lb>t�����/w�����W�ZM���ae	!�B!�Bq���U�ed@!�B!�B!��$9(�B!�B!�?�u������������~d��<�_+��0o9Dw���e\�
~���cyYF=�#���B!�B!����6N�������m�!���[������M��L��B�{`LX�#��������B!�B!��o��O��s�[���u���B���f0�+��ga�&h�	��]G!�B!�Bq����9hM�a������5M��=gA^����'6
�����W�..S�r
>|z�����	����vx���'���0~<��@�Zh�=�
��g���pG��������v���&
��A]%h
	;�����&�_���S`�z�8������!m
��~N/���y�l$l�\}_	!�B!�B�rw��t� +�h�A��u���W�������+�|
����APx�m�lxl!����
�6������0$�UN
������&8�'l���x��5������$<9	Z�T0�/�w��d���@d���5yg��
n?Ob/d;���Q�R ��*��C�i�t3����X�*�AcI%!�B!�B����O������N�{>������]0�wx�s�������X�s^�y�t1���wm���s�[��;��X�j���AG_����@���3/�G�������xR��\P��r_9���������.���/��	��~����.~��9<���C�����t��B!�B!�(W�r��)���h���n��������q0"�
��.�[�v����n��B�Z��!HU!T�?v;?i�[�|m9�|�I}.Gu�s�YJ]V���uU�mHIk���!h"�<
�"`�8=��<�B!�B!���n���>��^y@m8t�[�k�������>|
>v��:@��lWr0#�����>A>�����,?�{�7�4\���2�����A�eF:1��n!�t��6B�.P�V6Z!�B!���v�'=qn|�E�����+P����������.� ��h0Af������X�=��|+
O��T� �T
Pxk����XB���Q��4W��Zw��9�Ab-X�
C�����B!�B!���$5�H�I� j|�<��7�8�|�P_�� &
���bB]=5��.d'���b�/���@��3�X8�~
�l\J�\o����<���
4��?\#������u=����x{)�h�O�;� �6t
��2B!�B!�������(���������$���� .DTP����Z+��V�jmk�U�-����������nj�V��>T���TEET��}23��{h��L$��s]�d�9�9�33���u�}����r��C�xv��|�R�o4�'�/?���]GB~.>f�����pO���p��;���xs.,�?<:�{�#������`��`�BX���f�0|f$��Yxl
L*�����S��Y��0�f?
��{JzA��,�)��/>��������������H8�z��{�������y��W7��,I�$I������Us�;s6����7���~;�?�S����o�	W�N1{2�\�>
��b���H�������^p�����]7��$�	N���f����%p�7�G;�1'���Au���Kg��~g��	���]����g�����x��yp���_Q�0����XY��c!�:.�PI�$I�$m
�x<������������Ofr��6��;VT��jt�������9�	��&�u?����?|n)���%���$I�$I[��X%�u�	��;d������ o��"�#*�7�~�K����������i��$I�$I���[�E;�w�J�7����������v�JuH�$I�$)���:@��\����$I�$IR&�K�$I�$I����$I�$I��I�����<�`Ht��0�C��$I�$I�����j�}�x<�j�AEE���m�\�$I�$I����VNy�����E�,`Q�7:tLI�$I�$i[0�v/�D1�`3�����v=�xrq�m-��qA��%I�$I�$mk&���$�$I�$I�:)�AI�$I�$��2H��7��t�g����0��i�v��^���zU�NU��zX�>UnS�Z��!�qmv�����}��M@k?�d
>[	��\��9����6��K=�$I�$��3� l���Nn�J�M�Q����_���0�����y�~��0.�@����]P�������Z?��#I�$I�:�v=�D���0L�BpHJRpa^���[��O�P~V��{�BM��I�$I��l�+S��:���V��*8�V����C�J�]��W7m��N����q8�F��~�`B
��lU�%U0�n������up^�3�$Sp}
�\������|gh6c<T�j`N�W����He?V[��@(	�2��\=���}���^�pg��K��������	V�ez������k5��,�����u��H&������Ix�.�z��r����	�P���jm;pk6�O6�$�ph%|���
	���l�YK�$I������r��8?g@yV$��$T=��Qx��0��/��������[	��+"�x-3k���g����o��0�N���Q��nsw-�(	���zx8���H$��
���
��� $��Xm�4	���P�up^#����av\X]���t?�$�]
�����%avN�Q�����z80~�%�A�XX_Jg����m�9�0�Qu�5��V�������<P��`~m��~��'�E��8TF�$}��qX��Ylk�$I�$I���;���p.�Aa�����B00���JC0����Glx�~Qxm�������G�{� p���4��0#gw6��]����q�{��m,�D
N.���5�K_�r�l�RP�
�1����C�������I��W�06����"0�
~��������)�C����Q8���d
~�������������6���e�l�^&��nP����}�A��m#�~�������'RM�����G����I�$I��O��{[��46��
�L��h�6��u�u�v�~����Jm��uP�?
.�!X�
���%`�o$�zD`�6�����l����8����i�P�_@Y��4&`n
&D�~q�L!]<}��D����f+�G����R
������qX�����|�[���i�3
�)��M�������$I�$�S�����ypS,��;�
���� �t�\\w'�[]��b�g1|6��L��b�B�M�^M:����
Ai�Z��g3V.���`<Z��
/����T=I��`ef��4�����:������`���UAh��ozC�j�2�.��=�6��
���!��P����q�x*�8b���I�$I����{[1!8������z�Y{G��Y!��-	��	��I����0z�d\K�����:V��x7��r���`�u�6QO(�6;}dm*8	y��n���	Z�e���i!���b��{m
������`�O�=xk���Zx(/5�������$I�$I��,*
��y0�����S]��V�e���N�-����������%���[c�����P�mx�J�T*��;:��Ex��k�4���i�G`�����0"�o�p������������
O�^��P�6�#�Km|�r��V~��[����)���!��'�R�i^
)I�$I��d�������_��F�Q=,����	�N!x��M��$|�~/�}Bpw,�$��zX�c-�0������T�l�k�aeF���#�B��(�R�m��aV-���5�
���4���-�4���pnC*������.h�4�cq��No��t?�|���9:5q8�������F(�A�fs�y��`���8#��J��$�����46
$��8��������Z=���	�k�9��$I�$�S�����#���S���_�k����AH.(��	8�&T�u��)���@q�V����������������5�"�e���cu�i��������C)�a!��]��p[������Z�5���#�P���
pJ
|�.Xi85����l��l����{
`U��
~G�Oc���\>|#��9��i��=5��*[
/�mz�\�~����h�V
_�g��9��Z=������X��[�$I�$u:�x<��F���
���s�x��'3�x|����w���6���7������[78�$I�$I�����8��Xf����}���$�6�*	pu�����%I�$I�6f��V,ic������"
7�5#I�$I�:WvF�	�NC�'��"pUvXU�('�I[�I�$I��-0������I�$I�$ujn+�$I�$I�:�v[9��'��i]�w���$I�$I��`vbN�����Tk
***(//oS��$I�$I��]��rp��#����[2�E%S:tLI�$I�$i[0�������Y����L.��=����J�$I�$I��L����E9���$�$I�$IR'e8(I�$I�$uR�q8��;z�
�z�����/��6����Up�/��m�?�L�T���7n����+x����t>���'��%��a�8����"���`�Lh����������u^�f����k=�$I�$I��v��N��~
w__�<y��������LR�jc ��+������0����7}��	_�
<��m�n	Y��v%�~zY�}3��\�$I�$IR����l�����!(�%������nk���}�(C����`�8x����~���p��p�Q��r�"o�cBod;���#I�$I��lm�+7�=FAh,�O_��?�&L�~`����7 �������s�c��A��.��A�#�,�p<���������[r��
�8v��&��g��-�����`�|���p�P~'$�7j�s����/������Ka��a�����s[U������Ko���v���\?����a�?�n���.�5�;����I�$I�$}�lkK������*����'�U������a�]p���������x��
��.����,$R��@����xf|��|e8����H�[����p���+
�=3�����1���Er5�L��������n����w�i?�q�����������G�����_���s,2��������`��p���	��#�$��	�;&��>I�$I��O��?L5Bu
44���p���c����c0���� $:`$��,��18z��k+����������C���5J{��~�
	�������{����������V����G{���r� <|�J��'�>������,�
u�b�@�AC�O��ys�dSO�+?	N�����|��$��.I�$I��	l����a���!�/��-(A|�k���6����0q�x>4�aP	Swh{-����o���
���1�8��:���&�$��e�-=���p�-�{6y43h��*��1X���ou���8�<Z_�=���Q[�2I�$I������e���A,����^M!\������BPZ
�P���`����1��*����h?���Go�&�G�������@���
���U?��n�|���U��O �RM/6��/�-�z���1p�p�p�)�����gaT���%I�$I�>���p0����V�P!k�3.�`m�u��=j�.�9��J��mpB���H���������AUp�����+��&������9���<��U��HB~V)nSbp\9�������=� IDAT��o�Y���FI�$I��O�NvZq3�a�K�{%}�/�s�Y�G�!:�!dm��o��S�����U��j[�'����do77v���~�a(�
�W7���,��6�p/����f�u�x���,Hke�9�q���E=��]��Kn�{�Q}?���$I�$I�:�;u�3�W~�O=�.��]����?���S<�'xn!,|>N�S��0>~{,��5o�%?��-%�Q��z��9x�ux���v�8�p��xp%�}��O��`�������9>H0���o�������/����)������\���������W7[����s���z���������C�o����$I�$I�|:y�����`'|J��������B�90����p�k�[��p��P����^=����\��`F)\zz��z�C��<���x 8He�����a�s`��pp���/���'����Y3�/�p�O������Z���`�0�hh������2��1����Ok�d����+���>�)��$I�$I�B�x<��r���
���s�x��#�\������J�t�x�$����5������%I�$I�>�����dv�"*����}���$�FR��������p����$I�$�S2T'�k������3��q[� I�$I����pP�P��4�����$I�$I��:��$�$I�$IR�e8(I�$I�$uR����#O*R0��
�v���$I�$I��`v�&�
���P<O����������W&I�$I�$i��n+�T����n��u�XT��C��$I�$I����0$Z@��+���]O+���=���Tu�X�$I�$I��fr�n��y-�{<�D�$I�$I��%I�$I��Nj�g_C��A����o&7l�0FL���6��x?���3�x�l��W~����a����aY�����R���w��+�vV�RU������a�Tw�}#�m�Y~�z$I�$I��E��3�	��p��`H��Z�+�m�.T#�@�fyi�?��^h��e��<F6m�+�O�H>7����3 ���Z�\
��S&��=r�?�y%���0�=8�T���^>Fl�z$I�$I��Em�� ]`��0&�z��8xd\oD�w �!�i��l������S���p�#��)����ud1�����9p�50s��7	N=	�B-� I�$I��m����8�����r����v��v��jX���V��<
v�
��[�f�>�=q	��$�8	FN�=O��>�u����a��0�~����&�e�6�1��p�W`�Ca�ip��-����JX����Q(H����%�@��>�y�� w��*4�I.I�$I���mkK��A
���2c�`������x������[�!��@i,��?��	'�
�����K�
�����oxob\�
N�&\�=��������`������=�����`���/\v����'��oC�o��fcmJd ��k�5�g��9�z���^�N�#p�:���k��������$I�$IR'�����%��#6�6���!�������AG��M5Bu-D��������06�q��0�L��QA�6q'x�p��p��o�5����>��a�����5���0�O�BBp��px��}������9p����'��w|�v8�)(������JU��z�����
�Qg��3���=��-��Cp�W:��^�$I�$)+�L�
�_;f$K�o�}{[�(��h�E������4��p�MAX��3n|�����;�A��^K�b��v����jhLB���	��f��|�/������_����c���7����#����{�<x%�M��uG`����7aE���^�$I�$	:C8H>�6f��t���p�����`h��0,YU@IQ�
!(-�x
��a@.��6]�j�����}����[/�&��o��D���������g}
n���zv��-5��u�����e�7	�a�|�$I�$IR'�	��mL�;��{pZqs�B(*�3.�`m5��A�F7��H�������������k!�d�2��.��S�����Rs/�
yQ8�������0�U��$I�$I�������T�~�m6m6%2FE��9M��V����Q;�!��!d]��o%���^��^�k��&��M�+U
�kv�-��2(�[�gK�=������s�g��i9��$I�$I��:�����j����J�^����,���(�=�{~?FC��00sl6mZ��L�3���By/x�^x��dJ�Qn�7�X�?������g>�F����'�t2|W�|�S���W�C����oL
eIx�1��0����k��-5�po8��p���w
�#�W��90o���N���$I�$IZ������f�����CC.;)��� 4��|�\�|W�u!|��u~���i���u�n<�8�x$�_G�h��
�������3����g����������0�P8���8����65��p��P�2����5��:8g\<6�z�����
w�o��t������GOJ�$I�$mB�x<�Z���
���s�xJ�O���������*�����$I�$I��m����V�7�k^�b��Y���WJ�$I�$I����$I�$I��IJ�$I�$I����$I�$I��IJ�$I�$I�T��:������{rZ��S�$I�$I��^dq�w���P<O����������W&I�$I�$i��n+C&�W��$I�$I�2���!��T�6.��|��$I�$I���\�=�{%I�$I��N�pP�$I�$I������K������������~�����'�C�������O^��'j�������-��[{m�&�&��@����%p� 8����@�$I�$Ij7�����}!��E������q ���X�8�a	��m�`�~1�p��V�`�`��j���K�;� 8xKOJ�$I�$I�2:>���I�� ��P��>�W��vX=����W>��.!�m����p`�������7���0�w��P�$I�$I��t|8����@%|�"@|n]K���8�/�0d���v��	����CQ\���&.��t��s�����,
���1��^��5)X�
���>Y����+ 	DRp�+��>po�`�$��/���p[o����������8l0|��a��$I�$I����.�"P�N���|w%�0���3K���x�l�nc5\����ey�h
$SP��k��7`��������3�x�
zu��B��_����1p�'����*`XA:������0��xs)|m�Y
�M%I�$I��eu|8�JAM�)x{�d%t�c�A�v�
�} \�Cp���"X�*��1�o�����p��pl~�zH����E ��/��A���k9d(��z|	�	���#z�6�x2�W}�[+�����@�.�	]���`�e��*����$I�$I��Vt|8��#�Q�����'C�h��7�ptIS���B���p{m�&��e��~�����I�;lo���Rp�\�+���+������&a�!��tAe#�����$I�$I����i����~Ai>�k
��	�J2����k������`8
em�#����AE>|{'�5/x6��s��T�����apb�p��.Y�����6KCA�$I�$I���m���c���`�os�����)X��X6Z$�au_3���D�<>W���V����gW��7�����}���V�p(X��)�k)I�$I�$m9m���G�v���M��Rqx�v.jC�
B���d
�@IF�5�������aM<�U|�����p�r�M_+���xS@���w%I�$I���l[�`(3z�����s�����LN��{��<����b
,���t/V{��OK��$T����AeK��_������$Zh�1�S{��������%�t%��*����8��H�$I�$I[��L
W��g�Yo��)�l���{7�������9p���u�[�<��NP����.����M,O<rL���������U�=�/|&	w}t���b\�_�6V������/I�$I���#�������
���s�x��6%I�$I�$){��.������v����>��I�$I�$I����$I�$I��IJ�$I�$I����$I�$I��IJ�$I�$I�T��:������Z�$I�$IR���&�v���vg�8����$I�$I��af����n�`��#��kI�$I�$I���P�m}��$I�$I��IJ�$I�$I����$I�$I��InI
�`�#�h�}�OT���Q_Y�>�H�$I�$�Sh�I:�P�w��P��)�[��$\�T��!I�$I��N�ppK����z��!��HB����$I�$I�v������nx��AiW8q8�G��9�N}z�
?\K��E��7���#�Pls��WW
?^+R0��6
�)���<8n[��P������n�&K����B ?.�C#M]�}NZ��������;��j8bw�A_'��F?�m�eD��]���!�Bim�����~�:��*cp�NP3>�	~5�)����?��w��5&�;�����������_��pO_��Bx������P����	����wh�'�
�7>�^���$I�$I���u�3_y��&t?��T
�|����u�Y#����p]p������z�,�H��w��?��)��������� �C�o�
3��#�W���aPT�RMm����Gw��M��X
;��/v�;�@��noxh,������a0<y0�4������F6�O6f��+?��w�G��E�D<�>r���.}�
�?f
������0{)��h��R��+�K�+I�$I�$�����:���yg�axz��PU	�]_\�q|�#��u�q\��8v����������0%��O/�|*�H�����L��=��fm"Q�����J�DK�� Q�W�g���y��9A88(���|�/�c�����������������T=�~)�9
��^�96
�=������d=?����!�M��~<�j����<�F�����GI�$I���X��lXsR0�OF�����5�2�tm��0b%��*�g���O
^Z	��`���uDr��v�����E��:�Im�����P��(��P�#P����v�J�yXv)��+�2�q���7#QR�}�%e�k�?�\����-������#H�+�q8�o���%I�$I��r��!8e����2��R�*�*`���"�ph<���m�gm#��}��>�N������<8td��uV��gk���fns��p�a�P�)��E������d#T��`�F6�����	�A�&���Q;����a�R������^�$I�$I���p�(�0�3l��+����K���0�+��:L�B9����(�m�F>���1*������	���1���v�*�Uq�{j(�r�c.�skBQ(�3.&�*�a���3&��zZ[�8a�����9�������H�$I�$�e��8�v��u0��e�
-�����p�<8~�'��.{7���'{�����_��H�q[0@a!?��`Y}��i��U�|}�	xi
(���F�����*�~��-��C����1���k�,����@3Q�d��R��W���?�������<J�$I�$�U�r0��:��y#`j	����U�f\?")��5x�~7
�0s$?��	gt���3Ca�p���t8���+��.p��,c��7^.����W�]���[e��������lU-|V�������Z�}������6����~�����������z��h���f��������
Q�����5���5
��e<2����b���R�P=�s?�?���l�LII�$I�$e���A�=G�m�p��pn-��`�����AX��=�n�=F�����������	�sx��@J]7ny~������epz��K�`�Rxt	\���`P7�lo��G���Td���b6\�������3=�Z��B8u,�\�q�#F�_�k^�:����{����|>�8hW��u��u�'
G����Gm�gT�O���p��0iE�����T=�������v�$I�$IR����x��l+**(//���7�lsQ�S~Po�w��
�9H��'a�N��![��7����m��m���$I�$I�jR#��m���>�5��ve�q�`��`P�$I�$��0]��G��p����\=�h[�$I�$����Jb-\�.����:Z�.UT�7����Ds���cq�1}<L�z�K�$I�$mo:g8)�������::��%I�$I���K�$I�$I�T����sF{u-I�$I�$ih�ppf���kI�$I�$I[@������k��%I�$I�$m���3�YrZVm}��$I�$I��IJ�$I�$I����$I�$I��Iu`8��+_�A�C��1/�yK`Y�����o��g���-�����r�RH������`�spO���F<%7�V�$I�$I�N�H�I%ep}_��`�*��=X��Al����=K`J7�7ow��xg,����k`n�mOCQ]�h��$I�$I�Nt|8��u���=��.�^��:��mJ�+�]���<xz��
^X���be�H���Q�$I�$I������B��<	D�$��.���O@��p��B1�/;L��i����|��\5��>���>�|��@N
�J���8��6���yp� x�-(�n��T�#o��Sp��}x��
�����< �-�k���(���sJ36no�fV�M-����	���u0u����~�!�\�S0�+�9x�����0������pd����ex�U����8r0\�>�,%I�$I���m�ppY=�"P�N���.X	'
�������yP<�J�V�>�W�iC`j>���T��tAqw��4���a�H�Rapoq����������a��z1<����LT��
p�p�<��Dz��K����p���+,Y����=��.������p�JX��
��1�:��E���\�z�a��p�<(G�?��;�S=�~���?�7�������0���"��>o:(I�$I��t|8�JAu"x��[������'�
+��Zc�����&����+��~���U)�o��B�R8<c�P�G �V���`@��u$j���P���3Xu�k
X�r��F��npB��a��/�7,�Q���O����7��C�k��y��2��]��z5{�����o	�}���{����7�e��lA^\�3x&a����2x�
>����$I�$I��������V~��vy�Z��p�(50?	�K�*�`�� \kL_^�50��w
T�����jX
���ZY	��D�-���7�^�^I�!=2�����W��k�`j!��*8H��7T[���^�������_au����l
,J��j��i�v:<Z�$I�$I���_9X�n�y���{C���d���H�
!(�@<<C03~��_.��������]���6��]3�
E�x�`8-��Q�
)��?p]��T
RE���>��j>h�������>������d������uX���3���5��[�$I�$I�B�����U�V�\8�@e"�b
�&����p/��U��}���w`l78���}-�	f�.�A�VE�! ����(
ya8o7����A��j��~��"��q����Ww�c���u��$I�$I��5��&R���|e��T<��;���(�(N�����fo������pE�S
��l�F�v��c��_cB��!x������C�VknE2���D�:x�pP�$I�$I����g
����p�������S��a�I��(���8�z��_�[Q�n����<�1�/�ia�������.pR7��]�%{���K ��	-���}��� oR��W	���M��O9��[�
�Bp�R�4
���w��Y�+��hh�����$�0���~H�$\%�P IDATI�$I�:�m+8h\���{��.���kj3��(8�cm
w�+F����z#��ap�{0c��SG������v����_.�[���AP�V�<�\�w��������-�;���%����}����U;�w���@i7�^o�o���^��g�&�����sF6B"I�$I��N-��[=���������;~�6��4V�a�����srX�'I�$I�$m#f�������j����HKV�_a�b������8�`P�$I�$I���F�g��/��6���m�`��.L�$I�$Ij�;��~�ckW!I�$I�$m��7�$I�$I��=2�$I�$I�:�v�V<�����Z�$I�$I��n�`��%K�$I�$I�:�-�k@{u-I�$I�$if
���������$I�$I�:)�AI�$I�$��2�$I�$I�:�v{��F�	8�C��
^�C�3
S��] ���� ����p������CQw�Y�z8v�B@,C�������$I�$I�$�#���F����L�;up�j��7�t:�
:��Bm^W����0���$I�$I�x��`BA��n�XV���s��F5(��`������X	��
��C�$I�$I�@[?��	 ����k��jx����_|���m��7����D=�J��t��6�M�����Ep]	���Z�U���D�s�0#?�4���!�VS��ZX�)%����v�d�^��AC����51���`���X����M�_�*�����6��G�$I�$I�B������ ���5��$�/h�dqz��b�-o��M+�Ko�I����W�"pj��u�b�����8|oT��3���*��*��+�����p�*�����h����ep{)��.Y�����z^
w���n02X<[qR+�C*	k�A�����\=�$I�$IR:>|a
��	�
��8��iU���p`F��y�p9<�S���V�3��=`�t�66�f����1x�����J���	��
�w�Y]��D>T�?{�E��q�=��M����W)
�QA@@�"`GTAAA�vQE� ��H�Q�*����-��c7$�����y��s���{?sw�'��w��H�.���c�����P1*�$�:�'�s;��4h	}=�Q	�u��{wx��t,��X;�
��^��8X3�xf�O�w�a�Fz��T'|K�����<�e��np�9��t�����������)'a0)������w�=
u���N1�c%l��%1�����i�t�g�v���!�&�;��/C��b4T���
^�=�PDDDDDDDD|���`���iu�!�	c�g Tp�'`����V����	8��PB���Z�
�s��hTM�w�^h�s�R��n��c�V��L0m�Df8�w��-��o��%�4,z�zZG@W?8�o'��xx;"s���.V�����������
~C�260Sa�	e�a��F@���L�s
�0<�`�7��X@h��g� 4	���9���Z�f@�"�$�D��>��
)S�L�3MH%[@h@��33(a����m����7{�������V���L�L;O����4��-1�k��4��}��l/���������_o[v;�v�=�����S������6��pdKw��KL��M
�2�$b@�	���p9a����������H���p0�������4LI���P�?�1��D8aB�����l�hk�@c&��y)�>
���I�	��8`R"8����S09�H���A�N��J���n���	���.x7������R�ogu��h
,qB�>���>�!""""""""�C���xk"<���p](�+����NC�D��	;��-�=�~d�XaL|��A�	��pg���N�
�a	�i��A�p�d�w�`��,P���\$'�i�H����G!�-C�������ZI�y2�
uC����7��)��y�(""""""""����q�u�K�,�m��9oxe��.JDDDDDDDDD.��r#]���-�g���������H�P8(""""""""RH))����������R
EDDDDDDDD
)��jx\�y�������������<}�.YDDDDDDDDD
F��������i��q�3�X#���3EDDDDDDDD
)��"""""""""���A�B*��9x�)8��,V(Z������.���<�>{*�w�����aB-�!3�Xo���	u���P��y���VC��aX����}���������'���5���*�v��M��G�OU��R�������m�~;K���������'hQ#��|�KDDDDDDDD�8�F��k���	��/��U
����:���������u�g+H3
�4)�
8�3�f�L���k`�j���vA����3�^�(fH;����;��������K��w���	�f0�-����o��-�!����T�>���&�_��]��������2&�������m����+K��x8	�>;����:q
��1�y_o��,�k(�����Y�<�����7�_�O�Mw�����74�o����
����F`���q��Z�y��
�h�q��'Z��������\��?t9!9
p��?aq4�����=�HMx�D����0y=�C=m������&w����k��n-un(�v�x���2�A���p�2h�^)�6���@�p��y���a���m�})��U�.a����f�!���f/�<[���zk�7����mP?�������yz���{������<�%B���T��.���r`��P�.X8v��G>����'�����������H���p��y�d���
?h���.3��6]�M��������;����c�_x�>�)�s�aU��>7ts��gf���0�3Dx�A�i��
��&���DeH:s~��f���*<ZB�����r�ct���������sU�����,E����w0p���5���p]�w,�P"
�i`B��dT���q|2����5���\���.�WV���@������@��`��fEDDDDDDD$o�8X�5����d�v��0�<W���������x�g����%���a�.�
M��n��-t'��Y��
�n�"Y������.\'�(X���0s?������*]��������a����\�Y*g���M�u]X�~��V�������-3�.9>Y��+
7F����*[B3n�
�K�G!��cEDDDDDDD�����`X���'HkP�N��E��&TJ���K���>P#�n�9�e<����)r���qp�*T����u�d>'09nx�e����
f)H���g���}HbJ�'��|���eZz~R��#o�[+����}f����%��!����:��C�����������\����|10��}n(��$�����h�	i�J�r��	�������Zc`�]	}��j������=��~Z��}���,����zjHqpfw3R����dP����' ��,���/�s����61���b28�����|�y���=s����������\�
~?�C'���cn'8������w�G�,P�"$n���g���\f��7��R��g���y�^j[aW<�/
�����<��%�"��H���C�;K-f*�V+.�A!��5�z�Nup��''.�W�6�V\�`���S�����`:���J�x��������H��������<�w���B�=A��,������ik�?�.��lf��|<7�Ua�X���'��B�;�����_���`������9`�Z�G<l����K-}�L�wT��~�6wCM�o��2��<��C���<����?a�	�����CO{P1~Y
-�=;�EB����������*��
�CCh_���s�xF/�{������Tx��6#���8��rxp9X�7��[A@8<��~
~����-t�
vgi�	/>3��s��J��~�^x.��$�jw����%�~G�
3V���`�J�K���4�Ko8�9�xR���p��,�DB�&�����o����%���0�r���0�vx�;��3S��PY	,>���.�@�[�����d��w�wx�%�U��P��\�(���*��3���#�S���d���m���7�v�E���/��]����W�"u�Bo\���.���s����������R
EDDDDDDDD
������X���]���������\&�)����������Ry��x\��y�������������<}�.YDDDDDDDDD
F�����zy�����������\���a����z����������H!�pPDDDDDDDD��R8(""""""""RH�o8h�����o(��n�{�&w����>�	�w���.DDDDDDDDD�wy�!��Lxo�I���N���`MQ��I�"""""""""�)��Ag*���*��P��p����["""""""""�����8�e{��#�kV�������
^O��+���2�a�)���o�Z[�+8e��E�.�� ���������y��wIu���0sr�	������F��&��+���������������?T��U��p�8��@�(x�"<o��w��=�����.�aI�
�@�0�����l��P%*������c�y	��<tF�<;`���u'!��Y>�������YDDDDDDDD�"�oY���/���OC�?���@�lB�^95���E�	)��I�_�{�������.���5��u���!-��9S�'t
k.�u)��=�J��hO${c l����m1`�pNF�
OG@�0�����0�D�>ERDDDDDDDD�n��H����:L/	m�����m���zKK��&t
���0'��l������}�	�����&w�i�o�v����8Sa�	��3G�����9�>���B�e��N�I���+ODDDDDDDD
���gd�nE=?)�p��rz��$'��0a+���:3�M(�����D^����P�����`Q<�����s��K1]��[�4 �
�n��,>���MZ �c-��s}�e�(""""""""�N�.B
�.��D$�V��Xeh�mR�a����m\h����������A���;���.��Bp:��!&����>�������FK��X!�2��B)���.8�}K]v�C���P��mN����T�g�������P<,8
�l�>0��\������&en�b:aU*������aw"�x�����\ ��b�""""""""���3���_(	m�!��?Nyv��W����
F�;��1��"��'	����19��R8T>c�C�H��e6�%��2�S�g��3�����H����@,=�,05���rNF����!x(���\<Y��@EDDDDDDD�*����`H�2�Nz6�(��GB2�������'��gIm�`���e8'����^I������������7
�k��.�[���0�
%�����5�����P7���`�`Hy����EDDDDDDDD��p�;a��%�m�6�
�w�E�����f�^����^�""""""""r<��A�|:W����������H!�pPDDDDDDDD���W&�,�"DDDDDDDD�?B3EDDDDDDDD
)��"""""""""�T�-+<,���\�g����%���������H���p���4���=�����t��9(""""""""RH))����������R����:����S�W�a�8G�<��s�o�y�~N�G=�n��o�C���7�U�O9o3�$��
�/}���������\5��`XL�����0X������.�������h�2�W=+�9G��c�`�q���V���U���������\	�l����C�H�7GCH:�;�KCC#���O��)�<����X�	kc/�=[|��5��������H���p0�Z!@<uV�
���'��J���
�#�d��s�w�� �
����	$��; �{��
0��>5`t8��z���&,L��*��|�
���q��y�����#�>�L(��C�\��8��-�w��A�g��\�w��"0y?�K��U���a���`qt��%�pSX�%����v���:-0�!t�Z�	��������i+t(������""""""""�O
><�X!��H-�
O������V���!�Z�h���� �:}��M��
�� ��HB����L��[���po���[f��(v
<�w@�k���0���r��D����� ��-'`�f�:�r=��������
�N���X��=n�$��>a�v����G���p�
��`�
&g����*Q~���S�y��?�G`wE�W��vA�p��tPDDDDDDD�J����iB��L�SNBd4\k�l���	�SF���k������}I���I`
���B @8����a��Vp�<����P���Zl��#��0+��@]��/0���*��v�0��~��N��c�Q�;�3��jx����	��$��(�.���vB�Zp�������[���P}/�aB�H(���}�/���t[�Y��a��E<�$,R���[�E.�������c��X��R�0�<��d�����2��6h3���g�j�@p�q��k�
���y^������G0`�@��M�����>�>�����p����%��IK���04:��b@�P��'�bY����	<���
Z��S�Dy�$���/���2A�Q��3[2�	�!�+S���aQ0�$������ ���$ ���B��py��g����&����A�r�|1��=_��*�K�cn�t��������`5a�?p��l&7�IvB�	S����7M0�=K��eI�,~p�=BZ������z_����f����������\�
`�b��,��.c�^�+�A\`����rV�\����_��wC���"��r�?9����5�{���aw�\�'�lVn����a��������W����'N�������,�{� �j�?�3g���=��?���;KAy��#���'�L����mzv�
��qr��H{�[��5`g:T�,U�����0�r]�}���������N��V��a�����0�
��������E2��/v��hEX}v������Z�p������6 ������B����KC@*��������z,�pq��ipK�;`k<l
�)%!������}��yv?v8<��M���L����DDDDDDDDD�xW��A���X�m�MS:�3��&�������V���g�����3+�E��
��/���{-;���'���~;D����2������0��:l�'��J'���O���r���p�Zh������u�]������������H�0�Ew�X�d	m���y���^vQ"""""""""ry�Edt�=>�{���|�pPDDDDDDDD��R8(""""""""RH))����������R~y�����y�������������<}�.YDDDDDDDDD
F�����"y�����������\���#]f�O����"""""""""���A�BJ����������H!uu���t�9��]����������U��1��B
���O��V�/l6x7����*�_8�-�9�5��
��3�q�-!���3�qg��
�\p(�=������B�$p06Zg���)��Z�an:��*F��-��ZDDDDDDDD������].�	��V�4��!;,J�C�s�9!����P�l��	%��� IDAT�@1CQ�	s�/��J�}6x+����$��}�DDDDDDDDD
��]V��������\��j03	������,�����`�Z�=��7�a��Mx>6��<�0*���:'t���-���������\-����.,��6�7!��������g'�0��L��79��X����~���]���������f�!IF0g���
�&�+�0,�Z�
�'.���w������������\a�;���������=h��,��DDDDDDDDD���wC�K1Mp�Y�Jq��
EDDDDDDDDr��5s���R�Q ��aZ2$d{@`�R�����876<���]b���p�b��C��d����A�!nI�}'��R��2�pJL�vX
P����������U&����A�8��?,����
���<��&��]���/FqIEf;`�h�)$��g���������H�Q8(""""""""RH))����������R
EDDDDDDDD
�<��x\��y�������������<G��WM���������H.��b�BJ����������H!�pPDDDDDDDD��R8(""""""""RH�c8���/3���T.F`P�i��IK���Q;N6�;�N��Q2�{`n��?�������?2���T�	!(��[����p������aX��Y��=��Rr��s_���)���[s6j"���Y8�������N;��V�����|�MDDDDDDD�S��V|�a�}�E���1rM�qV��Ou�B��U<�����8��6������+R<(�����];���w&6	�<�5Cn��g~�>�}D%�u�������u� �y[�]�0�?��0w*����)��!)�
S[�'!R�\��~
�7Z�����N3lD��A��!\����_8h)N���@�����zu*���}���J�j�������~�2�g9��{u�v��O~��&7a#���3�Tf��9���L���[?��=�	C�3�,1uh��E��N����N�|��)�hi����
E���Zzt"""""""�g�qYq���FDuj��p��I�R��e�":�R�<�_�J>�������U&�-Z)V�4l����N'��-�<K:���$��#��p+*ES�N����Y+]�e��^CtP���s���p��yF���<���JEB������/�L\�K7���9V_��L����t�����!�h��'|�h#�GQ{�<����5��N2�?z�6��D��-<k���M��N�o���sx�MubB	+Q�s�v�������-	g
�J�_@�g���;d����G�T�4��AD�k�m��c����&qNg@�JDR�&�����,�~ua�����8n�S���0�����~���	�'(�45Z��$gk�#���g�9�N{#��m��#�KD��o/jF�R��������
��
#Yr�s]��;h��7��l�!%�w�$V���������1;7M�O���)g50{�ql�(����k��K��XV�[�#"""""""�@7$1�6���V�&�.*���IjR"��ne��gx������16���/6�R�A���^�4�I�?��eo���G)��#��p�`���x/m(��:��_�M����~s���)&�z�v���h?^��>z�:�}�=�f�c��m{�wb������/ysPiV=�������_�?L��V&������������s�K?���k���{x1a�M�H�G�2g����}i������p�lZ?���x�v���������/�z&�J���Y�n=?����n�T�G��$.��������|y�={���4X�_��M�>#��h>�v�����~d�7�s��=�{�L�bs����������5�W���d���������t��]f����t�C�1������Imd��@��?�1��g������V4�?x�F{������m����9Eyn�~���.m�����?��	X�2p�vv����~%�o�,�v�f����X�0���6��������7�or��6>"""""""R��y��~���	��5M�����]9����M��0��jf�Ov�����=nV�2{|��q����h&$$�	�)��m��k��zs��g�����7K��d����J�����0�a]��O�����?FV3��?m�q���:`�ll�0���Q��07O���4�\�~��M3���_���33���������7'l�j~���Zs���p�����i�FPK��}.���5���r�C��M3u�ywtqs��i>��S;�#���M����3�t2�nb�7{������y=�@#�l5m�y�;ry��av����������6��b�p�`Ne�����[i&e=�tx�����R#�~�������iny�z����}�s,u~o3�Z�|`i��s6O���8�\�3������K�C�]���������{g�?n���������7��i�-26�}�h��5��5��/�m:�'��:�5F�5�i&}����2/J>�v��f���)���h����2f@���������n0K��<���)X4s����G�?5�����]%s^��X7�\���?fBW_���<����S�+Q=���PB�na�������b���X���f=B�������9�&G�*5��33�l��_�]��gB������ko��*g&b�Q�ic�\��c����1oTw�T)AdH����q,�'�s:k=�c|�`����It,~�BX�#$�k(a�X�		J&!15_��f�ntP�ys�e�i���517�eS�-�m�����y��Eo�o[?�Y�qH�����rC��T����pl\�����|GC���a���Hc���vKn,���Z��E��m`��,���P�z��WEb���I���c)V�������}��m�R��W�{������!4�JhX(�LH0$%&e����A����u�S��������G�����������	S6L������g��Q������V�f�l���~��z��4f6��`��!�p{2������y��y�-g�A�Y�FM���y+n8������O�1���=�
&0��^kP�$p:��L�%6����j@��'����w�s��	�i~x�-��>N�Q��������Of�(��tr�����������'������@�X00�X,���j���	�N����,;�Z��HO >5{Y��D_�aD��og�~�W��$��)�&6����/�KE(Z����L|�#,��,��%,�0�g�Y�
{����nwf��I���=d���z�(J7���9
�,�ck����+���$8(�h#(� R����/������������H��������`��c���������h�R�:�cp~���.(S�u���v���S#���7������hS�UkP���-;P���h��X�l(oJ�w�B10�#���i1z%�:��}�@L+8V���#\����twEo3�lr%��l:�*<��WL��N��p�+�X6�n���xF�5o��!K(����>������%���Bf�`���]#�0�����m!��_�K�<k�DD�	��pA��tf��y(�x�������'�����g��>�}��ql[<���a�S-h3�N"�����g�:�9{&aw�qn���w�8�)����\)H�:s��_�������/������H��\7������wg�e�NZ��S�����P�$�-�S���4������9�XR����ATd�����rV��4�����U�Z�D���ll�|��U�Q�Z�������4R�
�#�3g�%�����	�0�#m��?��Qu�����|y�/���}�W�ul�Z����cc�/�`�i@�n�B`s�t/������w&�zw$:�Y��Ns�����y���
��	�O��`�/�8�1�.v.[�>����~���_U�=�����r��{��XN�fP[��qy;x;6�l�)�w�$v�r���k�=�v�RSH��2��GDDDDDDD�]���>���3qse�R����c��-KL=�����,���-��>�d�!<��Bf������#��m4�U��Q�|6�Y�����T��b�+���Cn�����Q7�4k�[I���Y���7��w3������?�T��������0��J��D�lC��w��i����~e�k�P�������x�k]������,�P��s�S�~=77�g����K��i�����q~\8��Q��<=�	���L�eOS7�&�Y.]su��(]����.���p(��������S0�~��
9���4��'������6�"�sax���4{�Nn5��`���������
s�qg��J���~���������x~�_�����|���i2=��I�;ZS��h\��g�g'�8�F�z���Ns��b���m\S��&|y��f��O�����4��|j�vo��|����R�jXg|��Z0�n��*���8�p�d*�y��TW�Q������#�Xi�ro|DDDDDDD�`�_8�������L<��!=���-{������3a	�9��iFQ�4�rv�~5�xG5���}^��q����������;"ZJt���������d�Q�~{�}5�A�-dLGt�y��:��a�\���~�/�?I��'�[��y��z��~���r�|�Sf>\�����7�������3x��=$�c�P�)���3��(E��}��A�qG�I�GV�e�gy����z���u>�I�7��}�;����[^|��}b��u�{7�G^x��	,����~�+=K�<��j��M��9���.k]��Z�����1�z},}���S�f=�b�7�����{�%��c��p�I��V��{>��	m�A���uh������cDW������
������?�^��E�wC����y�)�^��[�o���������p,�*������:+�5(z�x&/���-������X��Cm������#+83Awu�|X�3�������k�#"""""""�p8���d���m�_�x�3�{��y�5�>M�+z�b:�������l;+�����8���G�����M�<���J�{��M�;�=���\��[�:V���/���Y�����e#_����*Cy���A���+3z����=G
�
������!�
^JH�[������f&""""""""r�+tY�����������5=!ODDDDDDDD��R8(""""""""RH))����������R
EDDDDDDDD
)?_NZ�hQ^�!"""""""""��p8fA!"""""""""�O��EDDDDDDDD
)��"""""""""���A�BJ����������H!�pPDDDDDDDD��R8(""""""""RH))������0�Mz�{�
�s���g���_�7��\���=�<���_�7q�HY�+����I]���_yc@/&�p�����<����8c�����6��?���Os��Q�]>���b���;`��'�������6DDDDD
��h8hr���2�{�'S����;r�V&H��f�O���!_�R296�n�)q#/o������%�����I��p�5�v��S��t}wy�w���~�f%����!}7�X��X�U{~&�w�d��[9�_T?�I�:O�"5��v�g|�T�5'�0'7���h�wl<�>������?`����	w|�>��o����8���_��s�]i���O�������`[�y�t��T��Y������9���_������DDDDD
���i{���:�T{�7|��b�l��(y������������95JELd�j4���������6��UK���@pDq�������g{�E�M���c�%z�d��a�<�~�U�<E�[�Q�x�'m�u��������
/I��O����Y���L�V�2�����'S~�����5�61��c�1����0��D��;]��9��u�m���O��rT�Z����^�#�(�T�B� �&�5���)n��
�(������Y5�=_X����e�P�Ji��y��J�*U�R>
�������x����=_s*��4v}�,=�T�xxA�1T��5w���g�&����'����%/��*T���
k}���r�~?��������������X8s"c'���8�r�}k<i�Kt���f����������G��q'C���z��8}d7��@�+0��s?�����YI�;���3��^������H�9���-��GG����z�g=��g����������V�l��X���y�n���A�1�[�4���(���4v��+C�|�������{�u����}u�G�|��l��e>�%<3�2"i�P�7��[k�1����A+0�7������7K�.��s���L������|�?��]X+���e����c������7�~_N���;�h��J4�����t�5���3��&�J��?��OD$�����98w2�.JL�������-�G������3���3���	�,�[����|�c�<�-��y��	sx����y�s�6�-^�������;���n�<����7�g�l�)^��5�e�nz~6:q��U�{��+�,�������X�{{�C����+O�������n���>U�z�w�a������;O�A���������}��g�?�����/S�&��Pv��lM79��y�,����=(���`��]�Ry_�_�gj�����z�@�"!�D��Z������������1�!D_������3�/���s?m��J��P�C�����/����3��Gx�}06�
[@U���k���5�*#,(�����8��E�(��7�>�������S9&����������1�%���r�T�e\b����!�������p�cn
��'	�c��k�t���Q!��J����hf-�M3�{S=*��"$0����i>`\l
V�|�D���l�������l�~����Q�6�����g�K�:�'�6�r�p��W���w�+cJ����7P�x8A�!���{��I�Jw�����T0���[fg�����i[�$�!a�T���s������hxg��'$�$��=���2g�^zMN������)Dh����1��.p�|�f!e�8s��>N��z��.�<�~�HB	+Q�[�����w��zI���(Q�3�8����f��������
!0(��o��I�9��N��G����y�t~���5�jR��f�k�����3<��m��[:�BR �tz)I�	E�#��(E:R���J��,�! %t���P%���=����������z��k>lvg����{f�g��~��8:8S�r���${�qJ<�[?OX�����9z�p���G�yf�ux2��Y�|������@�/��w?���'�,ST��|��C[Q�����	m��_���}+��1��?������Y,�����nx<��{	|��)��qt�"���N������ck0`0����SOf���[(�o)�:����9{�[f-������r�g���,l�E�5R8�x 
�<q����;���<�y����~`L���-���%������gd����a�~�"�������������&�>|�����s��j,����u�)�_?���qQ�r����
�����fV[V�������y�/���/Ucgr���`NZ���Ax:��T*�&���[���|^Ic���$�q��N29��2��e����x�������y*�B!�!fj�~u�{h�db��j:������x[:��ry�7�\[5���2pt�[t�����p~�<�H��y=���z�1~���2�����3�:��?<B>�(��V��6������t�`���]
�Y�����D�7�E�1v�������?L���Z�P�L	L{{��7��l>AS}"�92e������'�������q����c	v|����	0@r�{4k=M���=:��LK�����IC\4fn�B|R����m
�6~��c:����t����;�����Hh�q�7@�	6������|�����8�Z��|�S=�����}G�j��E^IDAT�z�%����i2���A�c>��O~i��SI������P�cL�?��E�����m4�l�|mv������`����L>����|��b�}�u��L��-ht��XYR����{�~��Ne
<8�����I������=*����
z5��������z��X���x�\�_4�IS��-�ao<lS9����[�#L�i������j��u��X?�
^O������&��Q{�$���F{��0O������~�yc�rb<����Qh|�G;~��r���1c/�ac�Q���/9�X�R>� ��FZ�ZA�-�;?a������*��-`���N���o~l��fn�L|R8c���]*Wv�g��V4����18g��������E<5�u��Er}{:G��@��o=|��(������M�X�����������kQ�a����P�
�'P���,����7r`�$�eV�����Y�>���i�f��:�Q��/��KC���H����R��{���c�#0'�F����������Lg���)��3����jw��G��+����Ou-��2=��":4�y�e�7�b��h��U���{P��<���G�Y�?,���������R���E�����:=�^��cxm&?����Y.���.���'��=�t`�s'F�K�k���M��=\2Ae���{���+9�3j�fp����.���Z��S�&�eB3��z��:u�i�&$X��u���Ld�������C��B~�KG�2�W��k��k�:=�����Z�9.��Ujn�C�lXi4gW���^4�e��E�����b!�+����:����a�/��`�V�u{;~M��~/Mu(�S����m����6�'^!�B��a�V�F�����0w�����eQ�hn>���c�0���F�����1��#_f�	�4�U����1��J����|�|�o��}'��tye$���`�������e��������T.�z���_[����IV�:���{S��?�z������|��"s��F���9=a]&1����������M��l"Op�����Y~�3�������M�O����wI�r �t@�(�9K��X:�>�}3?�q,O�F�T�u���%�q?���K,��"�8�����:J�lI�:�r�9/}��L?-����T�W����FP�%�����4<)���'�������QVY�P��#jF~��5����Kv��E7$�O��P���D�#����_PF��w�`����l��Z�� �Acb����F��G����$������]W���h;�������	+��Q���������U���_�����`���P�����/��d��>�w=�p=����T��,�9?b��3&�7�b�r�5���=��'�"�3�������]���J��-�[l�����k�BZwB�FS�O�������nI��
��w>���K�v8��z����@�&�3�rLcj�GQu�|=$��>Y�iW�rA�����<s�������x����w"3�&�WB�6�K�M:��6�aT1 �Z6�X��'~:1��a������
|��:Qc;��B��4�;_,�Hl?��j�St����b�:=�V�dJ3���v�),~�;���C�/���k7ztoK�R��������;��s6���@M*�8���+X�4��h�.^�����'u�og���r>m<5�=^�W�i�7�;F����CM��M�)�o���-Q�x��hVh�t)����N�����
�U�
T����/�=>a���I,�U�ig���P�;=m\��9S�YTf�����J��G���4Z�F�"a][�V�e�����S�����U��Tq:����a��ZT+�,��g��>W�}���1����mf��x�R?:���9���<ESU��7>%��t_[x����9Z������y�j5[w���@���>��n%��`����{�DN���?�	!�B�?�O_�X%�d��S���5���f�2�y/M��Z����[����%h��n��g��}@;�8^�������'S�<��	l�l�.����rs������*�Q��>}��������F�z�a���$]�B��]L�����O�pTk
��J�fQO���1d����Il�� �!��Jj*�A�DS�#OA���`:~����b���^4�M��w���`t>���x+�{���r���H���3����lR9���SeaU1�:�R8��D���L��w��ei����m��Q�D2N�A*G'��\Z�p���GB�����W�vW�9���{��J >%�)Y����IMI�qKh:��m���5��t5���d����{.<])Op��������JL��!�����%��~.�[Ny��:�~o������f��	���X������������h�%<)�]��P��i��@�!����e�����.�����l4n���@{&����mS��5�I��K���"q�V�[�Jk4���	=;�`����jQ���n��H��%]U�k;=�������?r��~��N���	����Gy����q=�W&=����p�;�S�7�v��D��/g�&7:��9�W�E�����4���-,S�f�m�wx��2w��������&�86�:/�f���~sj*�A�6������3����T�	�1�������n\�������y�ZY������4RRxB��4s��Qn�*�|�|�	�����(��s�����=����{}�E��
���t6�S��P:{�e�����
�R���>%����!�B�'������?-������T�?���0pS���D�q��������}h�� �V"I���V����"����D� :v���K��,���T
46��j!����yYY �>��c��x�L��������������|��
�������	�=��?����0��i����K�F�Gv�W=;6�z^��L��O����lV�?%S��%�&�����*-�L&�Y���g���
tZ-dZ���3U�B�z���SW�}��/������jPJ�Y����{HH������h�7����;�p�<��
�������v?=�[t��f#_����V15����/���-�����6t�~����,�S�������B�������"�VXY�2��x<aJo�A�_�=��j�jTV�,l�Va��1c��+����"qs�q��"^p�|���P��O��zt!�vY�\�u���=?���E�D���X������|u.�_c���M9�p������48�-����g���CV��(�~���3w�Ig�Z�7k��C������%m��<��8��FS7u5C�P��n�����3�
<�R5J�4N��hW��������0�:�B�unX7�
�W�h:v��n��	-)*V�����C��f"O��f�J�F�� ���chJ��y5R��e�����)�z�^�E�-[��s/a-?��D����/�B!�B������jpj5��Gq��?����n
+\ZJ|\����n����G�j�J����q������:����K�[Rq�������a���_<�7s��	n�(��C�Idi#{6��������|��j�����H�����2��W	��	z]fL��a��dp��U�����+=[B#����lK�sc�j����r!�|�\���S�P*�Z�����<���?2�+�����hOD�@�h)^�8��qN4��4�V9���0����k6�W.o����Y���W������O*������aMpht�^���C �������Y�����x��-�DH�pJ��
h)Y?�~��h3�{n�sm�/F��]�7�3IK�J��2%�y�oO��p7�I�-,��G�8�kD�ikH�y(����)h]=(�{���W-��>f������"�3k���u��/S�����r��������0D�����c:���{J�e�/�������^+��yx����<�����������4�c���E'L�J���p4���Es�����N�\m8�R�;[xp�~��O�g��3T|}{r�o�/�����E���{�F����U���}�������MZ��4���������kR..����*��	[�W�G���;�Y��	#�!�����'g��/G�G��[��\L�9p0	���3�]"���T5g��[��A)��o�c��-O����
���Q5Doa�4`6g%-9�h�iKd�:V|���G��ygj4�Bm����}��*������B!������\�0�sH�������4p�&�)���&�tN���c�������P;q�6 ����}�{�J�����t�'����M,�d�|_�K�|n,3S��-_�I��
������*��>��{�`=c&��D��p���*�_���!o�����!�X3��vcb+��s�2N�����v��7"��#��5���	4����u�T�P4�fO�}������������rvw�����!m	/����G�i��vC{�a��t�c���!hO�1~�J��
�|�`AhF["�p��~8�%N-)q�,�A]h�U��O��8�i��xp�gf���K��������	�6�����R8n���a�2�����M��/�v�!��i����������I+��5�:��g����������i�����G��,�0�x�c��)����nh��n�i1������!���i���c�)�2]"���+�����_����\��=-N����������^5���������z�`�O�D�zF�c�z�v��P�?o�,a`�Nx���h��w�s7�������-����f��*"/�t�l>��qs��c=Z�w���>��2�����%����!`��������Zi�V���-8�^H{?-`�B�P�����O�����
't��}�b�<�2���L7�q�������xw��f_�"�O��M:	��r�dK���Bx�����B9f�\������
w[#;W/ao�.Ts��:����V�x~)C{����4��BF�E�x��;3�������@��}�M��{���b����j-���mq�9��!�h���hze������R�#�����f��'rII+�"V^�H��M��;�\�k3F�}��m#�������+Y},�����,�oj
i�u���]��IM�m�|�'���F�0_���{�&�J��j
�"�����o�f�a�kI��?�8F�
O�cS^�L�i�ig�.���������V�������s�y���u3����F���E<C��|�a���Z�V�6�6�np{����l���o'��~����?���������Yu_X�tZ�����o$n���6	�����nI�:�0�K��/'�A�}�X����\�Oo���S�U�v~����%n�T�,}��B!���F��xK���
�VeoW����P���������)���~E�j`�����z�������)�g�0U��VtV���GU��H�:��J5U�������3h�F�S;�U��j���p�Q�LW7��*W�fj�����?8�L
n�<����kU��\u�^�����M;��^���M�]-=����i��W���g��jz��%m��Z�P���T��K���rH=8ZE����<,�L�]��l������Qy�uSK.�)���:��h��ji�hm��yE����U�����v�UNYWx[��]��juWWe]�Cu6-3m���R�*W�z�*�UI�����o�W-llT�wr�������u-5�t�2�*e���c� ��j�:������{|��]O���}ux^_��l�:e�sU�j���vd��������������JY;���&���RL�����4S�6m��{��o�m�kz{�i�;��^}q<���5>].zoU�au��d���=Uh���������#���-+)g�7�)w����s*�hT�G������POe������*U���:�L��O���q`ye�\_}z2��t�]Q����j�uWv��sPu���GF�J��O}�7F�/n��l�T����Ow&�t�1=i�z�v�f�WZ��r��T/}�Y]O��?��z56���v�R:��r�P�����i�7�����n�e�1�/�T��������m���bj*7��-^N��������G�������������
&��)����kj����������W���{���O�K=1Y��.�z������RS��~2�=����>�
���F��O�JI�B
����*�x_��(V��pVM�����z]t��F���[���@�tPVz��[U��C�:��]�RT��q�Q:�^�������y�og����[}���
.ULY�
�����3���Uo�g�Q��P.�ze���j[���sUV��������U�r1N�2���M����n���J��S�����B�~���%�e���6YD[{�s�jT�C9�Jg��|*�Q��9�R
�����ST��������3T��VZ�;�����Y[��i���N���J����Tp��j����u�-��z5�]U��J�te�\R���TH��,�V��l�"|���N�l�<U`�&j��[����s��E�UT��rw�R:��r+SK�4~�:�bY��F�J��J
���\���,;���*qy��/�^��~������������:��]P�c��s��j����L6�d�M6�d�M6���7��h�cs~�5f7����o91�>�E���{��A-��y;;G���"�9u���T�������&���R��"}]O|������(���2��n8���a��qOV_�o�Oj�&���A���l8��>UB!�B!,��/y~K`��^S�������
Y��fw�����WS��&2l�]W����B��{�X��<��)���uh%�>=����!�A!�B!�_���Z0�TL��t-^�f����PZ���_Ga�-K��_04�����B!�W��N�q�$6���������s1s��$���
!�B!���o+B!�B!�B�O��	!�B!�B�/%�A!�B!�B!��$8(�B!�B!����B!�B!������B!�B!��RB!�B!��_J��B!�B!�B�KIpP!�B!�B�)�����;
B!�B!�B���������N�B!�B!���O����w�A!�B!�B�7�g
!�B!�B�/%�A!�B!�B!��$8(�B!�B!��������}
IEND�B`�
v7.0-Replace-OR-clause-to-ANY.patchtext/x-patch; charset=UTF-8; name=v7.0-Replace-OR-clause-to-ANY.patchDownload
From 087125cc413429bda05f22ebbd51115c23819285 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Tue, 18 Jul 2023 17:19:53 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
---
 src/backend/parser/parse_expr.c               | 230 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 115 +++++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  50 ++++
 src/test/regress/expected/partition_prune.out | 179 ++++++++++++++
 src/test/regress/expected/tidscan.out         |  17 ++
 src/test/regress/sql/create_index.sql         |  32 +++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 13 files changed, 674 insertions(+), 2 deletions(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 5a05caa8744..b2294af0f43 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -43,6 +43,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+int			or_transform_limit = 500;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -95,6 +96,233 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < or_transform_limit)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -208,7 +436,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index f9dba43b8c0..ddc27e2277c 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -2040,6 +2040,16 @@ struct config_int ConfigureNamesInt[] =
 		100, 1, MAX_STATISTICS_TARGET,
 		NULL, NULL, NULL
 	},
+	{
+		{"or_transform_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&or_transform_limit,
+		500, 0, INT_MAX,
+		NULL, NULL, NULL
+	},
 	{
 		{"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
 			gettext_noop("Sets the FROM-list size beyond which subqueries "
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..891e6a462b9 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT int or_transform_limit;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..cc229d4dcaf 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,121 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET or_transform_limit;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..c052b113eea 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ or_transform_limit
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9b8638f286a..2314d92a6d4 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,6 +4207,56 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
+
+RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 1eb347503aa..d1c5ce8be09 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET or_transform_limit;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET or_transform_limit;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..a2949d3d699 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET or_transform_limit;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..9c6baace0e2 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET or_transform_limit;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 3e5032b04dd..d4d7d853a4a 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1396,6 +1396,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET or_transform_limit;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index d1c60b8fe9d..77f3e6c3b9b 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET or_transform_limit;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET or_transform_limit;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..634bf08e5fc 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET or_transform_limit;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e941fb6c82f..c3abb725c8c 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1631,6 +1631,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
6.0.1

v7.1-Replace-OR-clause-to-ANY.patchtext/x-patch; charset=UTF-8; name=v7.1-Replace-OR-clause-to-ANY.patchDownload
From 9e0a0200525e7e72f1a91f658b4674fbf78ea18d Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 21 Sep 2023 19:15:42 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
---
 src/backend/optimizer/plan/planner.c   |   3 +-
 src/backend/optimizer/util/orclauses.c | 232 +++++++++++++++++++++++++
 src/include/optimizer/orclauses.h      |   2 +-
 3 files changed, 235 insertions(+), 2 deletions(-)

diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 44efb1f4ebc..80935cec7aa 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -67,6 +67,7 @@
 #include "utils/rel.h"
 #include "utils/selfuncs.h"
 #include "utils/syscache.h"
+#include "optimizer/orclauses.h"
 
 /* GUC parameters */
 double		cursor_tuple_fraction = DEFAULT_CURSOR_TUPLE_FRACTION;
@@ -1169,7 +1170,7 @@ preprocess_expression(PlannerInfo *root, Node *expr, int kind)
 	if (kind == EXPRKIND_QUAL)
 	{
 		expr = (Node *) canonicalize_qual((Expr *) expr, false);
-
+expr = transform_ors(root, (Expr *) expr);
 #ifdef OPTIMIZER_DEBUG
 		printf("After canonicalize_qual()\n");
 		pprint(expr);
diff --git a/src/backend/optimizer/util/orclauses.c b/src/backend/optimizer/util/orclauses.c
index 6ef9d14b902..805f4b7294a 100644
--- a/src/backend/optimizer/util/orclauses.c
+++ b/src/backend/optimizer/util/orclauses.c
@@ -22,6 +22,10 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/orclauses.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 
 
 static bool is_safe_restriction_clause_for(RestrictInfo *rinfo, RelOptInfo *rel);
@@ -29,7 +33,235 @@ static Expr *extract_or_clause(RestrictInfo *or_rinfo, RelOptInfo *rel);
 static void consider_new_or_clause(PlannerInfo *root, RelOptInfo *rel,
 								   Expr *orclause, RestrictInfo *join_or_rinfo);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static Node *
+transform_ors_for_rel(BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < 1)
+		return (Node*) expr_orig;
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *orqual = lfirst(lc);
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
 
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) expr_orig;
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(NULL, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(NULL,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+ 			saopexpr->inputcollid = exprInputCollation((Node *)gentry->expr);;
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
+Node *
+transform_ors(PlannerInfo *root, Expr *jtnode)
+{
+	if (IsA(jtnode, BoolExpr))
+		return transform_ors_for_rel((BoolExpr *) jtnode);
+	return (Node *) jtnode;
+}
 /*
  * extract_restriction_or_clauses
  *	  Examine join OR-of-AND clauses to see if any useful restriction OR
diff --git a/src/include/optimizer/orclauses.h b/src/include/optimizer/orclauses.h
index f9dbe6a2972..6a232aeb3ed 100644
--- a/src/include/optimizer/orclauses.h
+++ b/src/include/optimizer/orclauses.h
@@ -17,5 +17,5 @@
 #include "nodes/pathnodes.h"
 
 extern void extract_restriction_or_clauses(PlannerInfo *root);
-
+extern Node * transform_ors(PlannerInfo *root, Expr *jtnode);
 #endif							/* ORCLAUSES_H */
-- 
2.34.1

v7.2-Replace-OR-clause-to-ANY.patchtext/x-patch; charset=UTF-8; name=v7.2-Replace-OR-clause-to-ANY.patchDownload
From 84ba19a988447bd5e19132080375101e1ae2e63b Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Tue, 26 Sep 2023 09:23:44 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR 
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are 
 still working with a tree expression. Firstly, we do not try to make a 
 transformation for "non-or" expressions or inequalities and the creation of a
  relation with "or" expressions occurs according to the same scenario. 
 Secondly, we do not make transformations if there are less than set 
 or_transform_limit. Thirdly, it is worth considering that we consider "or" 
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
---
 src/backend/optimizer/util/orclauses.c | 295 +++++++++++++++++++++++++
 1 file changed, 295 insertions(+)

diff --git a/src/backend/optimizer/util/orclauses.c b/src/backend/optimizer/util/orclauses.c
index 6ef9d14b902..b4ac9370461 100644
--- a/src/backend/optimizer/util/orclauses.c
+++ b/src/backend/optimizer/util/orclauses.c
@@ -22,6 +22,10 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/orclauses.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 
 
 static bool is_safe_restriction_clause_for(RestrictInfo *rinfo, RelOptInfo *rel);
@@ -30,6 +34,292 @@ static void consider_new_or_clause(PlannerInfo *root, RelOptInfo *rel,
 								   Expr *orclause, RestrictInfo *join_or_rinfo);
 
 
+int			or_transform_limit = 2;
+
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static List *
+transform_ors(PlannerInfo *root, List *baserestrictinfo)
+{
+	ListCell	   *lc_clause, *lc_or;
+	List	   	   *modified_rinfo = NIL;
+	bool		    something_changed = false;
+
+
+	foreach (lc_clause, baserestrictinfo)
+	{
+			RestrictInfo   	   *rinfo = lfirst_node(RestrictInfo, lc_clause);
+			RestrictInfo	   *rinfo_base = copyObject(rinfo);
+			List		   *groups_list = NIL;
+			OrClauseGroupEntry *gentry;
+			List		   *or_list = NIL;
+			bool				change_apply = false;
+
+			if (!restriction_is_or_clause(rinfo) ||
+				list_length(((BoolExpr *) rinfo->clause)->args) < or_transform_limit)
+			{
+				/* Add a clause without changes */
+				modified_rinfo = lappend(modified_rinfo, copyObject(rinfo));
+				continue;
+			}
+			foreach (lc_or, ((BoolExpr *) rinfo->clause)->args)
+			{
+				Node			   *orqual = lfirst(lc_or);
+				Node			   *const_expr;
+				Node			   *nconst_expr;
+				ListCell		   *lc_groups;
+
+				/* If this is not an 'OR' expression, skip the transformation */
+				if (!IsA(orqual, OpExpr))
+				{
+					or_list = lappend(or_list, orqual);
+					continue;
+				}
+
+
+			/*
+			* Detect the constant side of the clause. Recall non-constant
+			* expression can be made not only with Vars, but also with Params,
+			* which is not bonded with any relation. Thus, we detect the const
+			* side - if another side is constant too, the orqual couldn't be
+			* an OpExpr.
+			* Get pointers to constant and expression sides of the qual.
+			*/
+			if (IsA(get_leftop(orqual), Const))
+			{
+				nconst_expr = get_rightop(orqual);
+				const_expr = get_leftop(orqual);
+			}
+			else if (IsA(get_rightop(orqual), Const))
+			{
+				const_expr = get_rightop(orqual);
+				nconst_expr = get_leftop(orqual);
+			}
+			else
+			{
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+			{
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table. But also we believe, that the case of many
+			* different variable sides is very rare.
+			*/
+			foreach(lc_groups, groups_list)
+			{
+				OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+				Assert(v->node != NULL);
+
+				if (equal(v->node, nconst_expr))
+				{
+					v->consts = lappend(v->consts, const_expr);
+					nconst_expr = NULL;
+					break;
+				}
+			}
+
+			if (nconst_expr == NULL)
+				/*
+					* The clause classified successfully and added into existed
+					* clause group.
+					*/
+				continue;
+
+			/* New clause group needed */
+			gentry = palloc(sizeof(OrClauseGroupEntry));
+			gentry->node = nconst_expr;
+			gentry->consts = list_make1(const_expr);
+			gentry->expr = (Expr *) orqual;
+			groups_list = lappend(groups_list,  (void *) gentry);
+		}
+
+		if (groups_list == NIL)
+		{
+			/*
+			* No any transformations possible with this list of arguments. Here we
+			* already made all underlying transformations. Thus, just return the
+			* transformed bool expression.
+			*/
+			modified_rinfo = lappend(modified_rinfo, copyObject(rinfo));
+			continue;
+		}
+		else
+		{
+			ListCell	   *lc_args;
+
+			/* Let's convert each group of clauses to an IN operation. */
+
+			/*
+			* Go through the list of groups and convert each, where number of
+			* consts more than 1. trivial groups move to OR-list again
+			*/
+
+			foreach(lc_args, groups_list)
+			{
+				List			   *allexprs;
+				Oid				    scalar_type;
+				Oid					array_type;
+				gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+
+				Assert(list_length(gentry->consts) > 0);
+
+				if (list_length(gentry->consts) == 1)
+				{
+					/*
+					* Only one element in the class. Return rinfo into the BoolExpr
+					* args list unchanged.
+					*/
+					list_free(gentry->consts);
+					or_list = lappend(or_list, gentry->expr);
+					continue;
+				}
+
+				/*
+				* Do the transformation.
+				*
+				* First of all, try to select a common type for the array elements.
+				* Note that since the LHS' type is first in the list, it will be
+				* preferred when there is doubt (eg, when all the RHS items are
+				* unknown literals).
+				*
+				* Note: use list_concat here not lcons, to avoid damaging rnonvars.
+				*
+				* As a source of insides, use make_scalar_array_op()
+				*/
+				allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+				scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+				if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+					array_type = get_array_type(scalar_type);
+				else
+					array_type = InvalidOid;
+
+				if (array_type != InvalidOid)
+				{
+					/*
+					* OK: coerce all the right-hand non-Var inputs to the common
+					* type and build an ArrayExpr for them.
+					*/
+					List	   *aexprs;
+					ArrayExpr  *newa;
+					ScalarArrayOpExpr *saopexpr;
+					ListCell *l;
+
+					aexprs = NIL;
+
+					foreach(l, gentry->consts)
+					{
+						Node	   *rexpr = (Node *) lfirst(l);
+
+						rexpr = coerce_to_common_type(NULL, rexpr,
+													scalar_type,
+													"IN");
+						aexprs = lappend(aexprs, rexpr);
+					}
+
+					newa = makeNode(ArrayExpr);
+					/* array_collid will be set by parse_collate.c */
+					newa->element_typeid = scalar_type;
+					newa->array_typeid = array_type;
+					newa->multidims = false;
+					newa->elements = aexprs;
+					newa->location = -1;
+
+					saopexpr =
+						(ScalarArrayOpExpr *)
+							make_scalar_array_op(NULL,
+												list_make1(makeString((char *) "=")),
+												true,
+												gentry->node,
+												(Node *) newa,
+												-1);
+					saopexpr->inputcollid = exprInputCollation((Node *)gentry->expr);;
+
+					or_list = lappend(or_list, (void *) saopexpr);
+
+					something_changed = true;
+					change_apply = true;
+				}
+				else
+				{
+					list_free(gentry->consts);
+					or_list = lappend(or_list, gentry->expr);
+					continue;
+				}
+
+				if (!change_apply)
+				{
+					/*
+					* Each group contains only one element - use rinfo as is.
+					*/
+					modified_rinfo = lappend(modified_rinfo, rinfo);
+					continue;
+				}
+
+				/*
+				* Make a new version of the restriction. Remember source restriction
+				* can be used in another path (SeqScan, for example).
+				*/
+
+				/* One more trick: assemble correct clause */
+				rinfo = make_restrictinfo(root,
+						list_length(or_list) > 1 ? make_orclause(or_list) :
+													(Expr *) linitial(or_list),
+						rinfo->has_clone,
+						rinfo->is_clone,
+						rinfo->is_pushed_down,
+						rinfo->pseudoconstant,
+						rinfo->security_level,
+						rinfo->required_relids,
+						rinfo->outer_relids,
+						rinfo->outer_relids);
+				rinfo->eval_cost=rinfo_base->eval_cost;
+				rinfo->norm_selec=rinfo_base->norm_selec;
+				rinfo->outer_selec=rinfo_base->outer_selec;
+				rinfo->left_bucketsize=rinfo_base->left_bucketsize;
+				rinfo->right_bucketsize=rinfo_base->right_bucketsize;
+				rinfo->left_mcvfreq=rinfo_base->left_mcvfreq;
+				rinfo->right_mcvfreq=rinfo_base->right_mcvfreq;
+				modified_rinfo = lappend(modified_rinfo, rinfo);
+				something_changed = true;
+			}
+		}
+		list_free(or_list);
+		list_free_deep(groups_list);
+
+	}
+		/*
+		 * Check if transformation has made. If nothing changed - return
+		 * baserestrictinfo as is.
+		 */
+		if (something_changed)
+		{
+			return modified_rinfo;
+		}
+
+		list_free(modified_rinfo);
+		return baserestrictinfo;
+}
+
 /*
  * extract_restriction_or_clauses
  *	  Examine join OR-of-AND clauses to see if any useful restriction OR
@@ -93,6 +383,9 @@ extract_restriction_or_clauses(PlannerInfo *root)
 		if (rel->reloptkind != RELOPT_BASEREL)
 			continue;
 
+		rel->baserestrictinfo  = transform_ors(root, rel->baserestrictinfo);
+		rel->joininfo = transform_ors(root, rel->joininfo);
+
 		/*
 		 * Find potentially interesting OR joinclauses.  We can use any
 		 * joinclause that is considered safe to move to this rel by the
@@ -114,7 +407,9 @@ extract_restriction_or_clauses(PlannerInfo *root)
 				 * and insert it into the rel's restrictinfo list if so.
 				 */
 				if (orclause)
+				{
 					consider_new_or_clause(root, rel, orclause, rinfo);
+				}
 			}
 		}
 	}
-- 
2.34.1

#72a.rybakina
a.rybakina@postgrespro.ru
In reply to: a.rybakina (#69)
4 attachment(s)
Re: POC, WIP: OR-clause support for indexes

I'm sorry I didn't write for a long time, but I really had a very
difficult month, now I'm fully back to work.

*I was able to implement the patches to the end and moved the
transformation of "OR" expressions to ANY.* I haven't seen a big
difference between them yet, one has a transformation before calculating
selectivity (v7.1-Replace-OR-clause-to-ANY.patch), the other after
(v7.2-Replace-OR-clause-to-ANY.patch). Regression tests are passing, I
don't see any problems with selectivity, nothing has fallen into the
coredump, but I found some incorrect transformations. What is the reason
for these inaccuracies, I have not found, but, to be honest, they look
unusual). Gave the error below.

In the patch, I don't like that I had to drag three libraries from
parsing until I found a way around it.The advantage of this approach
compared to the other ([1]/messages/by-id/attachment/149105/v7-Replace-OR-clause-to-ANY-expressions.patch) is that at this stage all possible or
transformations are performed, compared to the patch, where the
transformation was done at the parsing stage. That is, here, for
example, there are such optimizations in the transformation:

I took the common element out of the bracket and the rest is converted
to ANY, while, as noted by Peter Geoghegan, we did not have several
bitmapscans, but only one scan through the array.

postgres=# explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 AND prolang=1 OR prolang = 13 AND prolang = 2 OR
prolang = 13 AND prolang = 3;
                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..151.66 rows=1 width=68) (actual
time=1.167..1.168 rows=0 loops=1)
   Filter: ((prolang = '13'::oid) AND (prolang = ANY (ARRAY['1'::oid,
'2'::oid, '3'::oid])))
   Rows Removed by Filter: 3302
 Planning Time: 0.146 ms
 Execution Time: 1.191 ms
(5 rows)

*While I was testing, I found some transformations that don't work,
although in my opinion, they should:**
**
**1. First case:*
explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 AND prolang=1 OR prolang = 2 AND prolang = 2 OR
prolang = 13 AND prolang = 13;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..180.55 rows=2 width=68) (actual
time=2.959..3.335 rows=89 loops=1)
   Filter: (((prolang = '13'::oid) AND (prolang = '1'::oid)) OR
((prolang = '2'::oid) AND (prolang = '2'::oid)) OR ((prolang =
'13'::oid) AND (prolang = '13'::oid)))
   Rows Removed by Filter: 3213
 Planning Time: 1.278 ms
 Execution Time: 3.486 ms
(5 rows)

Should have left only prolang = '13'::oid:

                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..139.28 rows=1 width=68) (actual
time=2.034..2.034 rows=0 loops=1)
   Filter: ((prolang = '13'::oid ))
   Rows Removed by Filter: 3302
 Planning Time: 0.181 ms
 Execution Time: 2.079 ms
(5 rows)

*2. Also does not work:*
postgres=# explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang = 2 AND prolang = 2 OR prolang = 13;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..164.04 rows=176 width=68) (actual
time=2.422..2.686 rows=89 loops=1)
   Filter: ((prolang = '13'::oid) OR ((prolang = '2'::oid) AND (prolang
= '2'::oid)) OR (prolang = '13'::oid))
   Rows Removed by Filter: 3213
 Planning Time: 1.370 ms
 Execution Time: 2.799 ms
(5 rows)

Should have left:
Filter: ((prolang = '13'::oid) OR (prolang = '2'::oid))

*3. Or another:*

explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang=13 OR prolang = 2 AND prolang = 2;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..164.04 rows=176 width=68) (actual
time=2.350..2.566 rows=89 loops=1)
   Filter: ((prolang = '13'::oid) OR (prolang = '13'::oid) OR ((prolang
= '2'::oid) AND (prolang = '2'::oid)))
   Rows Removed by Filter: 3213
 Planning Time: 0.215 ms
 Execution Time: 2.624 ms
(5 rows)

Should have left:
Filter: ((prolang = '13'::oid) OR (prolang = '2'::oid))

*Falls into coredump at me:*
explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang = 2 AND prolang = 2 OR prolang = 13;

explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang=13 OR prolang = 2 AND prolang = 2;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..164.04 rows=176 width=68) (actual
time=2.350..2.566 rows=89 loops=1)
   Filter: ((prolang = '13'::oid) OR (prolang = '13'::oid) OR ((prolang
= '2'::oid) AND (prolang = '2'::oid)))
   Rows Removed by Filter: 3213
 Planning Time: 0.215 ms
 Execution Time: 2.624 ms

(5 rows)

I remind that initially the task was to find an opportunity to optimize
the case of processing a large number of "or" expressions to optimize
memory consumption. The FlameGraph for executing 50,000 "or"
expressionshas grown 1.4Gb and remains in this state until exiting the
psql session (flamegraph1.png) and it sagged a lot in execution time. If
this case is converted to ANY, the query is executed much faster and
memory is optimized (flamegraph2.png). It may be necessary to use this
approach if there is no support for the framework to process ANY, IN
expressions.

Peter Geoghegan also noticed some development of this patch in terms of
preparing some transformations to optimize the query at the stage of its
execution [0]/messages/by-id/CAH2-Wz=9N_4+EyhtyFqYQRx4OgVbP+1aoYU2JQPVogCir61ZEQ@mail.gmail.com.

[0]: /messages/by-id/CAH2-Wz=9N_4+EyhtyFqYQRx4OgVbP+1aoYU2JQPVogCir61ZEQ@mail.gmail.com
/messages/by-id/CAH2-Wz=9N_4+EyhtyFqYQRx4OgVbP+1aoYU2JQPVogCir61ZEQ@mail.gmail.com

[1]: /messages/by-id/attachment/149105/v7-Replace-OR-clause-to-ANY-expressions.patch
/messages/by-id/attachment/149105/v7-Replace-OR-clause-to-ANY-expressions.patch

Attachments:

flamegraph1.pngimage/png; name=flamegraph1.pngDownload
flamegraph2.pngimage/png; name=flamegraph2.pngDownload
�PNG


IHDR9����sBIT|d�tEXtSoftwaregnome-screenshot��>.iTXtCreation Time���� 31 ������ 2023 18:34:57r9F> IDATx���gXg��gw��7E�]{�=�1���D������1��5���M�
bI���X@�X(���+���Ufv���;���g��JNNVB!�B!�B�;�7�B!�B!������B!�B!���$�B!�B!���$9(�B!�B!D>%�A!�B!�B!�)I
!�B!�B�OIrP!�B!�B�|J��B!�B!�B�S�B!�B!�"����B!�B!���$�B!�B!���$9(�B!�B!D>%�A!�B!�B!�)I
!�B!�B�OIrP!�B!�B�|J�M��


%&&����7�/���J�(��CB!�+Bll�\�
!���*99Y�������w�qqqyQ�S,--155������#44���^IB�	'O����@�B����������		A�������B!�[#O��������P�P�����._��F�yfb�m�����T�^��� ����~�V����B�<�V����x'����V�Z�j�'N<����	����B�.��f�			�,Y2/�z.///BCC��8���P�<��)�[Ej�!�G111����^g�.]�<�y�~B!��<I�����dX||�[���M!�o�$FD~��CB!�[*�$y�d���79�<���x{{����Z����$$$����������}�X�xW�T��>���l��O�����9 ��B��\c
!�"/��h���P��������p��$%%q��9j����u�KN�4��g������8w�Z�����8�+�D���^�7��������s����-[6W�?~�E#�5o����'3��~�"�V����a��g���?o�@�"���M�kgg���y���	�w��E�(�&W|B!D^S�UA����q��5BBB���BOO���d�Zm����8�Z-�������
��k�r������>tw��G���{����Gv,--s�x���;���Hx������x�����0�B��?�������{�����x�r�
:���?���l[����i��.�S���B,Rg'���b\%g
w��yS_���?h2�#_������?c��/Q�������.?�D�uh�G����%6��y��922��'2q�D"##s����K��������|c	!���<K����������_�@"�J�,Ixx87o����gggBBB�~�z�m#��J��>������Y&��������X���@/����>��53���s�����cX���<I��������KQ��#M,�s/N����mr��0�C�[�~�N�3��P���%M;��hb����v������O>����0��)�������Y��c�^l������E��1��)��xy{��`��PZ����}{J�(Abb���al��7��xaon���3E+5��������3����F``d�uo*6���]WIz��=�����x{�`�.�yL{�ovm8����I�����gm����x`?8��)?�������8��u/s���k��9�)sS�B�d�nNO��s�;w��A�P!���-���&�e��qL���7���$h�B���k�9x��5��9���j��;w�p��J�,���S�$'rR��������+DDD`gg���#�O������(	7��F�q������������/\N�u+��� �r-���$����{��e5�Gw���\�k�`zhr&���k�?��G�������U��w�o��m�#W�i�VL;/�N�fA�M������O���pc�J�$��������{'�5vx'���W�����t��	CC��W�w�)�+�t�n��1S�b�����=q1I�/:���nsG[�a[���fV���z{��&}��~;k;j
�p[�������Y��mJO��r��XS{
�oB�y�^2���y��O{�M
�u��R��~h\����M��!)\�c$���136���%��GdSI�����8�4bA�;V����N�w�����������;-��:�s����
�f����'7W����5Ko��O`TT�&M"::�����h&M����(/���
����t�V�o���U�ckj��k�V �B����%���9u��
z�����<KN��WWW|}}	���k8::�����3gqh�q���������!�#r�Df](@wQ�"��?�r���>�n�'�xUh��?�IN+����4�P����X�[�\�����o{����=�VN�����I�K2�wM"�F1���p��J��p%1�y]4{&t�V���X����c�^��jL����,m�,j[9�����_3����L��T�H�v��v<u�G�u�i�]�	~���rE��u'�������{vu�G�+����6�~4����e���/�k+O��eO���'���GTT7n|�#**���������L�
T�D�N�5�c|�Ns���G�$^���6���1���(���q�V��%I>���>����5Y@T�Ky���R��ucs"@
�wM�K�����a[��������J$[�jD���0����*������m\O[3�l���}>g����k3�eU|<�01����2�����,�=��h�������.�
+�R�#��j n)-��i���{y��J�hQ�"��X8%�����W�D�������JN[X{���(��~�
GYS7z�x��/;����j=z4���<8k'qjJF��@�u�y�@��lB��]�?f>����!�r�#s{S��fV��n��U���(u\]�!�=�06���u�/���r�����8����01����
C����$����C���X�c_�
]�;H��jO��)V��R��G�Z��O
G����5�}�~N�Dst^?���`if��gY>Z~]��7��)�K�L7;3�����^\L��(�b���v��Y�#��\�W/���	�v����-���j���k����JBK6���3K|�����q����s���f�]l036�������h�+8G�;��ei4rT�����e��)���@��H2��i�������=�X��z�A���'u���| ��e�tz-[O���_�t���_dR��L9���5�q��/M��=Y|�t����4��}f��q���M�q������Z�'N��J����D@����a�)����w���%�{����T�R�&M�dzT�R��/��w��vW�Q�NK��HQ|���aP	,�^��0��3��	�7��K�����#,�=�o��f��)�Y���i)Z�����_fOe��1�?���]O��"�6g�-c�����-Sf�������%|��L�8���&1s�N����B�^Kr0&&�S�N����J�"::�������K�r��x�8�|(P???�_����Wqtt����S�N�Rq<M���hT^��IqN������=���7i3f�'0�_C��;i}�%rjbKZM������R�,u��te�%-�#:t?����x[7-��
�X0x���0d�*�-J�k?�w�B������i�������k����g������*����[	����5[��r6��zcX���P��\%��!���Q�R��|���1���Q��2�S��������5��}w1=:��X"��R�2k[w���QU�^��^s.<]@w���28�:�V�!��=��Glmm��i�S����U�"N�z�o�kR��
���#7��n~�Q��n`���I���9��,�2C���iN�>��Y�ytx1��������$N��8��	�~��/���������P�th���`��ml_7��)��e�9��0���7��� ����������4L��8�i������?|N�������y�dQ��*]����l����.l+����
Y��u7V��~6��b��l�����i9��0�\P5�"�����m*w����I�8~�+Z�;������7z��{��-Z�h���S�K�5��o_�/$�O~]�Q�/����3jF&2�%
���u�i����o��X\������F5�������l���Uc���/�J;Ge��n-��n�"�2n=�d�����6�v�a����9�e���K_W����K#r�O��K5���y�d���	��
m����m\����"�9G������@����e�V�L�I%��|�� v���������G��\��
����s]z�M���l\5�6����~f_J�4�"���H�c�����,���A��w�(��%qrRw���������A�jJ�V]0�g���(�������������|����$sr�l����f����m"}��f�5�V]����.��	$0���,Pk���:�F%�X��)��lR{3#Ll��<�#�	S%���ZS�D��
00s���c�J�q~�Sw+LL)Q +/�'����&��6F[���j.�+o'qxTe<lM02��hP?�d�+���z��,���&�����o=�����iP�	3Ccl����M7���,m��u���~�3Y��c�,N��e���4���?����qf���u���_L��-�
e���y�^r�1~�n7F��`h�5����C��<����AI���K��nU��i����Pn�rb�`���gJ�"h���_D��h�J��J�?*U��B��jK[l�v���XOw����=��2�:��c]
%�f���\K��S��S�f3:H�VUq�>�o[�pWx��/r�������}j�E��rj�B6�K��FK:vlC��~�Z��,�����^��tl���3lZ��k��@!�xiy6���.<n�����!j��V��7������5�k#���@�\�z�7n����Z������7obaa��q�p'�X9P��`Z����K����-��SX%�\U�LI�v�8����?�>�<���bb7�@9�q����5����@OEAe^�J�U)�������cX���X��a�2v?G����m�N��e���5�E4@��*�Qv�d�
�IW�����f�_��6�����;���;U'#�do��>9r^��Z���IL����'���(6�/@�~�����
��,z��(5�";j�c�������Q� ZK+���;V�����U�b����E�gXK�m�d����q���Zn�����(��� @�&M�[$�@!�OA���)�q ���{k-�,������>0���* �E�S���n��v&�L��.Q�G��������xIJ����������'����]���$�
�M?��E
��N`5�F������?jt�Lc/5�*E��U�����/����K��J��6���Z��j���[���m�<� ���x���>���Rz�8�m��S���ri�
N�5dA�,�eZ..��zM6.��Z&e�{}>�Ws`zU�Me�
�;��E����Yc��C�)l��{����-�^�����G�a���t���\�%�o�)R6�g�'H�������nY#��0��K����m�
�9��q���)�6Q����+������V���]U�n������V���J����D�z�B�4�����b��#��}Vm�N�`��sD�&�_�����FT�Tgu����n;�}w�~{X1������x�$�#e4 0=���[Q
����U�&@��@3��|t���a�
�6�D���LT��L����f�&)�����KM5V����Z���I
�i@�H:�/��`�p#���d>7��F�$h�L~�hN�����a�c���B��O�2#��s6�����������"k3���40����_mE@�o���=���7x ��
q����+���}g����8�Go4����Co7e����3���?�kKC<N~K�Q�u����X�������xt.��T���/���P��J�6�;3�
�Dn�wP[69�d��Ix=<��#��A�X�My�'_�������u=�]G�hZI�ne��3�EI���o����3�u(�~b4*C�jV����R�Q��+_��|w�*���+w<�����p�>��N��MS��<�f��S$�/H!�Hv���l���%�=���w��K���)���r�U~W�,h�"�u[63o�a�|(]�E�LP��c�jA���R�I
��� ��~	%�FM\�4���)Z"��X�^���pn�Jc�P�g�AQ�����k8���v���m��3�0ukO_�2<qSGpi�?�YW'i�,�B�����������&22kkk���	���+����U������p"##���%""���$�������P��MFca��e]�(B��s8�AONL��q��tp�bi!w��*X�{����\���W�
B�����
�������.��i�x�:�5*��Q'�sW����3I�\u�:�(P=o�tN�KB)���^W�x��r�q��|=l#��:�����p��eex�@��!�XI[_s��t�;�Q�����7��3�����HN���fj�����1r���A,��$����C��������3:�7���-t/j�V%��f�����7��q��.1�Wn([���A��a�U�m����ui��a�@ONA�C
��?!�����D��@J����`r(�N'���&^��y�q�EQ�w?�nO�fX�{�q+J^j�G��;���8?���?��|1������~���uMT2`���\��H�d����-����)�;����ph5��Y��}����I�v�������6$"FA�\�Fa���wk��]�0o7�F;����]�6:���(;�6/Qq���������[7F�I���9�<��y�j
��|�R=;����s2��*�J?N��l�T
����Ur�L���>q%�/f8G�}HV�m��}W���t\����+������g'j2C�|��!�����������$��5n��>��HiM�;�M�m��0~��B��l�sJ�1N�ZS�V/^��	�5��EZ���H;�w�I��ep|�5���'O�)KPu����JU2��S'��
���
�Q����H����u���x�{^�yS����>�
�������yxq>�vg����fj�J��uRC@��-�������>���FN�P�Mk�{��fU�.�A�e[8���Zz*��iZ����~IF2��+���c=�2ef\`[�U�:1�
ens3R��Mm�*`d>�j�
�D���@M*��`K�����X*�����x���c��3���jX�>��Mc���X���%�������*�7�Z-�������<~��W�?:�3����mptv�P�U���=��<���J��s���
n)��9f�D�pvPs��� �M�������Z��P{���a���Xw2�cG���z�N*D�Qs���y��~��������"U��'�sgO�i�~��jL��%Q���]m$~������qL�HrT(�v�����$$�1�OF�bN�3�VH��N��5
��/\��-��������vB!�Ey�|kkk8q�)))��������'�<A�SW�^������s��M����s�e��������~*9��#&L]LP)�}�)
�`��7�7���?V�DQ0�0���u
�N������?��j�KI�V���'
�(�@�6���4�z����*(�.5A�dN�)�����d��pj����?c��[�������v�bh����Z�~�,��
gC�\)�`�z�):������?��$cM#�sR��I��S��z<��U��a<o�x��WPa��Q�X5�j��M��n���j��1���x{{�u�A��3�%J��R��L�*^����5�~2���e����~^<k~5Q-�<{s�%E�<ZA�@�N�}�~��=SWW[���Fn��r�{��(Tw��	
����q�JK|=#^uZ�n��v�X|�?C���r�,��IV�������'�[�����*U�r�n�r|>�w��spw
�S��D�C����u���;������Ut����3g2w�\�����Z�j�BxY�Xw�w)J�g�g���g6�����v�Hh7����[ IDAT�+�j��!M���2�;�[+��D�u�2w����D�9;X�^AQ4�u��
��3}Y���x�i���wN���C��
��Zc�V/��:�Eg��o)��,��*
5�$����)�o#��������U��� �mCu�'}�����~Z
�Z=K9J2�{��q�T
*�)�X;�����U�q0����,����g��S������'����	�,��t�:}���P�W0cB���I�����a->Z��_��W>������f��Me����j;����dN;��;���7pJ�����l9v����2�r�3�Z<?����H�ozf�*�m���q������Zs��^�)��5q�h���+�\:}��"������k����l=3\�W��xy*�������^��z(�v'0�1�3�EPah��u��\�	���o�g3�g7��h6�S�����u�yM!�/��
H���F@@����FO+X� ��#,,���9��c����#""���D"##	������x�.��x065A�l�IG�/���&��S
�015A�G��
�R��!bqMK��>����T[���/Ni_=�<��O��������T��wl��o���,8�d��N�Kc��z�:*�����(���q���Qw��kv������TE����K����n�)�C	�2�t���Q��%36.&��7�t����/��6���~�!�����)`h�����% d�o?����r0���E��M�Q�by��041FO�#6�p��%(��O��}�e�|\���Kj_J��H��*,��R�J�T�B�J>��^a_��G�og�K:������z?����:��M	���2����<�a�kX1o%Q�z���������g3+B��E?�����qk���	�X=s9[�j����D����7q�Lk�g��a.��j�M��h:�}
�3�L�Vn��2�������B�)e������J4��B�U
�U�t~y�T��
�z��)����G�+�KI�r��<}��$�}g�B�����q~l������*F@I="��^E3�o�g�<RY�����:�X������x���g�B~���ph�i�VFm���B���/0J�K�z����;�~v�v=xj��
hO��`����a�_��+��k����+L!k��:���s�dV����S��?�&�G���$m���U���O�*��U�/�����9}�,��O�]=C���Cvr��>��`A������u����������=�|�T
�M|ipv��7ne��S������qx�����U7ne�D�"�y[����q�*C,�L�<8��/�c=`
���q��
�Z��L��i�v�]�|����s//�IDG����3%���&���a��a���
��Mn��(X6/�(`g������3%��W^~P+!�B�N���.i�����(?~�Q
���J���-��z<��}n��v����T�R\�~���d���)W����<]�wLL������T���=�G�zX���365��8�R����Q�F�{��h�,�EJ�^6�z���dl��^sP�0�Z3��,GZ~����&���_�/���uL}���h���w���&~���uf��J������t��L��JV��~�|\i9����V_��E�?B�J���/��%�Vma�������A"�D�<~m
U��f���\��)
.����_�i�xZN�������������q�������������[�A<���:1�� �_6���)~9���?ff3T(+���O3��>~j����N����P�����=x��X�Z��������8��6bdg��V1n�A:��cA��*+����%>�D�)�iq���PGb�����tbM��5��9��Hf�kS�:��?������]��M?
���oe���@�	��v�\S,
%��d��|��	��R�Y��WC�.��*Z���Mi_�+�O��U��4SaZ�5��m������5'*�P�Z5�����={rUk0�)5�������oP�}z���6����t�Cj1ih}~Z��q]	�K�
f\�}*�~���������-v�����cU>���v�*"�eC����PT����R<8�����L�����/d�-wJ�A�_W�gk���m>�����h�Yah��4y����k�!AY������
��|E�1��sr����EC�-I�)i��5=jzb��7M�������e��Q������.�;���l�4j/�����*I�$��	!+lm������!AK��_G
��� �h���17 #���MjX�m�����|���?�W�^�2������S$���6@I4�w�DW�'��IfC*t��
�{P�uI�O_������=%��8L_�9V���N�U��gh�g�����h}�}_�n�Q��L��N����o�_��0q7�n��)����{8a��bi�*���)�~I���`�6.�*K6�+��W�*�����P�H<���1�V�L���U�V�R�d��<���0��w����V��!�pa���y��u�`�I���C����Q2�09��@�7of���Y.��eHn�na�_wq�t���URWO�����m�w/O%��l�����u0�1��:S��	��=�
�O���y	���<�y���p/�h��S��,�6��0��v��������kv��sv�Ol�]�v=����������kSz4/���=���fA���M���B!��������o��C��akk���#'N����5�m�E���`��\�v����G����9�F������=065z�����>C����LSST�8b��P��(��Z�Z�b���t�����B�zR�k�����Y��&�����?���i�Q����a�����m�b����_��:S?�O6+N���!}���'{�2��j������ed��i��k�&������}X����'���VE�0wFC�~C�E�$kL��s���3��qj<:1c�>�8�!���ss�W\/#y������z`�������1����B~U�d�>k�6��c�l[��/�3��D�9S��06LHE�&3�����I�xT��m������������i�T��Hc�TmN���u�5C��Jp��(v%����_5�6�5h�PYQ�����:�o����8�t���W�3���^&�X<t��*}�3|�d<����Nh5���?���V��<�];��
c�Me����qO���/-�6�sZr�3-�2l������i ���dU9�[�|������������3}�~�O����c��]Tf8y�Q�m 	:���&�����f�$bY�*�~�����@aR��F5���/�GS6ts���/Y�k�M�K�_�����l�0Z�z�$�)V���p���y�NK�?;�e���H@1q�h����.7�
�Mc���[�����S�p)V��5�����A�hf]C�Q��� ��������������P:M�K7�
XL��x���Q�2rNZ�JB������.��ZA��k�X7����BL�V��h0n#j<�yR{���?���A-��`�{��L��[z���/�������c�V�|�>��T(5�|�1��X�jc>�����h�����NC��{����WV�*H����i	`K����0��������cqk���O6�~E��c`����������U��K*C�v��k��n�|R���q+��H�>MC������j=��a��zx�������0��
*�����\���m�h�M�����`���0�G
��thL���;T���6�=��2�lM���~�&��oA�wr���/�{-�/���P"��[_�M������������4pO��o���i����.�q����!�.�`�:j���������,�����E�v���g��Cn�'7j��Q��5n���s��|Z�1&����y��{�(z�X9yR�m-�yvTh����9r`'���1���T}J�c�5Z��������O
�F���z~\mG�v]����������:,	h\<����w&���gt�!�B�4�������<r�~~~��^e'�Y���FFFDGG��Y����V�9{�,*Tx�86l���I��Yll,����`��9�=�8��_O�z�r�~�[96�mB�rpu��$�-j��m����y�,�?s�����*���
���	���-��koT�"X��5e������'��}�~�zZ�n��sJ�)�L���u�8��d.�O�v_1ux=\����/�r�F�_K��p5:|5���Jb����;�i�VB����u`��q��6%�c3z�k�fB�l��0���t/�U�i-'V�ol!VD-�E�{It�@�K;��O=��B���8�6`A�Z�_���%�P|�����,]�=�O��1���\��[/�O��o�a��a��������n������a��fN=P�t���R�o��S��3�MW�W'u+.���AcY���z.4���������u���~���M!S��������f�����d�\������w���:K�W�Hk�����*t�pu�7|<t>�.%`^��&�bD}W4�.|AE�b� ���3�~ekl�>`n�f�m2d�t����	gl&��!�ua��oi[$�NP���=���C8�G��A�pn~O�}����^����=|x��aY�f
u���4o���l��HM>YcP�V��<�;�y�!�B���XrRG
>~�8����@��]>�����_����^���-�ms����~�z�����%���#,Q���?���S�_������x��-�V���}�3X�WDL�.�w�I��I{�S��Y>���w����5k�S��S�3&���
>�!���koV����k������W��]\\2]�6��qT�W/��������{T���%���B!�Z�9z]��������6Y%�B!r��&_d���O�����aV�}
����u<�C,;��n�7�x���x�h(��!�h��AB�]rc[!�y)O��fff�t:T*�+kJ�V���t��==Z������+�C��)�����y��!D����{�!��F��]���d_�w����3����B���Yr0""gg�\���:��7nd�|��������+V���!�����8��$��%N�8A�2e�t(B�Hn�/u:���s���3 �B�oy2 	��+WHHH !!!/�{���fff��*���Btt4����$!^'lll���y��!�+���MTT��E�<ekk���
%K�|�r�������g@!����,9(�B!�B!�x��C�	!�B!�B!rD��B!�B!�B�S�B!�B!�"����B!�B!���$�B!�B!���$9(�B!�B!D>%�A!�B!�B!�)I
!�B!�B�OIrP!�B!�B�|J��B!�B!�B�S�B!�B!�"����B!�B!���$�B!�B!���$9(�B!�B!D>%�A!�B!�B!�)����k���C!�B!�B��e��W��������?+G��M>B���-����*�������gL�q1\�N�q��y�7v��x�{W��������� ���Z=.�������l������6������l^���������6��x:n�N6����$�,���6��6/�`��,���`c��y)c	6j����g�{#��
O�H$��������`�RbXK�c���D�!�������	�-���v/����cb6�t"�lU!�����c�g�����@=����F��/?�4�V/T~F�.l��y�6.����'� �8�������,���B!�B�
I�b!�B!�B!�)I
!�B!�B�OIrP!�B!�B�|J��B!�B!�B�S�.9�_!���x����o�x�=m������2�gh��o��i�\�����N�X2�62����<���y����2Tni�:e�g�6�2��iqyd^_���\�����2���^��p�i�h-��-_��x��4��`./:I�����H<4FO�#�����N<-P��M� �B!��S%''+�[`��]��h�B!�B!�B���{���11����f��
�~����/�����x��	KL�C��:/���k"��]������zx���S���)<��S��}��w�r�g�a2C�����x��=������i��0,���q<�����C��:/��az��0�M�����#a�[�0��Ci<�r�8�������tlxe^��L��a����I����m\���.����WR�.{�-��/�u	P�g�X�y	<��_l��}7��/s����.#R��)��CB!�B�7j���/�G��.�/_I����$��o���@�/�B�X�0�@�R,H<J�q��yqh�u�cAZ����M-mR���&�M|���r�
+>�N^�����=*`���\F�q
J���m
J���fv,x��~i��S_�m���a�4��]�@�I����#Z{b�3fX��~M|�{�\���.4��~�\�m�1�,�M�m��]M�O�-��5Y]>?��!���$'�'{�b�_H!�B!���#=��J8�V��sP!�B!�B�J��B!�B!�B�S�U�b!�xg(w[���^m(W�U��t���[�$*T}����u?k����4!�B!�/D��B�&��[:���@�>�L����gU0�%r��������S���B!�B���$��-��-F�Z�0Quja~�%;vp}de<��-�B!�"H��B�c�\7��5�3�pI&T���e�$*���peT
F7��;��yI\����]Ws_��gY�B��l���Dn�h�7������G�f�]
}
���{����B!�B!�O��!D�(<�=������������?�}��<4�L���Y6
~�Y]���G�����a/.V��=��F���M�e�I$�����Y����0�I�<�G!�B!D�&�A!��	�m"����5P��� 6/�Dl���I]l�	�L@{#�\]����������5�aT-�Ty�B!�B�|M~:
!DNh�%�|2��c�~�T�R��7��n���&5���y�J��^L�	�p�8��#���{3�!�B!�x�H�A!��	]���,�L5��f�����y=���� �e��HR�2�L�?��=��z��!�B!�x�H�A!��	�Ff���a����}S
S���*�4 ��.������A�"X*aD�/%��!�B!��#�A!��	Ma\��s�(���y���u	Uq�T[Y@lt���)�����,
�G�)����)��ps�-�9�'��~N-_���	$��/��K��}�^��-�B!���$���"'T����=�a�7�T�����?���	E�o�����re0��;G6����Q��q�
��Dy'
��})����ng���;�G�(w.����*)$�����yP�+��9�G���_�4�O������g6}y��T��0�o����.j��D!�B!�oI
!D��0��5�����)�Zz=J���zMP�-�W�M{�����0u��?�R�?���dy&0�2�����&&�E��|:���%�g���Tj=���p��1��EA���#u�B!�BdO��B�c�8�I��#������_,��/2�l@�,�lL���i��j*����:9�G�i�_�>}z#:e��������������4M�[F[Fi�{oYa�,�7��""�E}q0\u�
�Q�"�R6�������������M��MiK�?��s�s��NzH���B!�BQ����B!�B!�B�R�B!�B!����a�B��-m?�_��S����g�K�W$����%�B!�B��B�n�i9s-�;!�B!����b!�B!�B!J�R��x��|�Ge���B�>��sy���2�����=}���8��Y�u��n���
!�������k IDAT?�`�xmC+����'��{��82��7l���NqU�^�������x7�VV��bp��o�"������6T���GP��;���$�B!�E�b��w��@IMM�e�-����g��7+!�B!�B!�Mr��98=��S��U������Kj/��{�>��.w�Q���D%o��e�/*���`������	f]�V:��h�^xQ��1��3�S��l:���!fce���1{+�x1{�?�����,*�<fCQ�1�fv6�J��Y�,�K�0����O������[FO���������WQ���c�e������?��(�V��G��Z��_0��7�J�wW�������y�+*Q��1'��--"|W�!�������3S�;!�B!�;��=P$UG��W$���m��x���Lz��[�@mE$���&�r�%���`	�a�w��-C��2��
O�Q,�V����X�3�/��/�P���,>U�H������v,u��?�1�7"���\�A,����'o�b�X��I���������:��=���-��[a[������v��~Dj��nC�I�2���X{K@�<�E��X�OG��H^��MQ$��B!��Vd�/�:�'����MP��B!�B!�B�HrP!�B!�B�RJ��BQ��x��\�������S�����+���L�Q�����V3���
�p"�|����'� �����
�������#��c��0��zb��)L��
C���
}�0I�C7X�

�������!�Bq���B6�Q�#������A;-9��?^B����O�����X�������:�p�;e
��*���:x]�u����K�`�
�����^!�B!n���$BqkP$���D?��Py'�b48�Q�����O�ZM^@bu�S�0X5X�A?�S2��Cr�y+�>B!�B�"�+�B����X��.N�J�P1��c����J+'^��g;������88�U�^�����x��`I��8����S���(��UG��o�fTX��={���U'����k���
~�8��?��NU�s=*��7�z����B�Q������J����
TF+�C��dM~�_T�T��@��+p�y>��OT�U��@�����z�]!3��������������H���/^�^*���V���!:��d��Vy}�B!��EHrP!�H\�_L����w2�G 	��f��$�>���~��U������i�ly0�C�F2��Pt������Q�����V�8N�f�o ������w.��z6R9��j6n����5���+���Hr�.�9?��=�>'�e�O3���2�DI�U�

4P��}�9!U�Ta�w�����9*������
�b�xH5��l�z���4h�@S\OV�[�g5h����9{��KC��m=���R�����-���.!�Bq����Bh��|'�Mz2zj���v��a�g;���� w��+��T�k&O���X9�u�@1Qc`}~����^�N����E�{�Q�^�r�S��R�z}+�:.%*�5�=�����=x|~g�{��l�Y���3#�&�J�T�����@s�g
�0b;���u����^K�Ym�����Ua0S����P�n2_��`�
OX��~|������G���L���C��*,Ua���������o���B!����*��h��k%�u5��_�����{�E����m3���k}b��K��'���*��6c���R�T�\��m=�$�wX���!e3��:�����i�]��ZK��4�4��@�+���Bn������S����X�z'�^}m��w�[���o�:(�K�%
��O�`�Y�����@4p5q����B!���3"�jI�`�w�(M�`BIM&9[O���Y�F�|�|�~�w�_<Zr2)V0�2GT*^xd����'���rf�\f��P��b�*�xM�P����(
��
xj�!��
������s��H�6��'�����w�����nI�O�OU���-��
���B�s4@S (�f����#�B!D	'�A!���0�Br�����Ih_������Sg;5%�
 ����]M	���qHD���3a����44����BJ"h���/O=����ow����*�y����%�R�!N��6�1
�����id��/����K�_�8���	0����-1�����C�����:�>���#�B!D	$��BL��z�n����O����(u+b�'�+�1�$�'�.r�?W�A�HKJu�%f����FuO�����7�V<�
T�	�'#��s�=�fVn��D��#q�V�\u�[����L��k����E�!������{aKL������^�����f\_�V��0��	p]��N�;�s�E�'5[�F�S��ql���n���m��cN<����!�Bq����B(����]�,���Cd��%���I��M����ji�����x���XN~��]'\�� ����5�����]���T�m�����p���f���G_�F�k���6m�FjbG����W���@�k����|��F��q�ckw�}�
��Pds)��K�%�z+�����x;�o���*���>
���3�2
p��UxK�����V`�������3T�F�%�~Pa�fK�iL������z
���5�!����zX��*��`�5�D�4p����%
7h�S�(��-���hr���M!�7�+B����7=���_X�8��U�7�Az���X���+������a��e0�I�.GY�\�'5����~e�}���
��e���.F*��jF���p05s_��(��K+X5f&��	�����c�C��V���������B�����fj
����,9�j�a����WW D�%�z;q���}*��B0P�����V��^VmI����������z�X���-QWI����4�S�G�}�����bi��w4X��Dl���{��|H�U�������|}�k��yq�Fdj\!���IrP!0|�]������(~���(�Nt���6.�����wY�:�������V[�9�4�<:_����cwv����m:2pi����o�&��oP�{Y\�y<�K�y�����y�e����.�)�l=��l�,p#]Y��.������D�(��#I
!��J��B!��p�7!(	D������u#�B!���$9(�B!
��D�$E^�;�Xs��B!r%�A!�Bq�rK��tL��"/�	?w��Z.��B�'I
!�B��n��U9I��(���-(��B�"�A!�B��$���-�sb0��`NIBI
!��V����2��Z�z��>�������<3������]������n{T��m4e?�`[����o{��2�y�����\����4�����5{U����d�o_���Bq�d6V}���eY���$k��e�����������C��M�4��C��i�9fp����iNY���Z�	BI �>�J�)��r*�(Y�+��.��vL!�(��)E����^$��������G���Hz��y��B!�%P��������������[OF�/�����������B!�M��98�|��wf�g�m�����;��,��mt����3�c��o�YD��1�:���I�b���=)��X�=��R+cV9��7f��dQ���=��2f��}�s1��������"� ������=-��a6�%*)�.��:��`6�W�f�X�����9���L�x<����O�[$�G��c�y��b6y���TX�~[�J�.��O�ufO]��+��W�!���_\������7Fsz�9n:����k��9���=q��1G����>�^�Y��95$9A!���/�.e�I����I��Qb��`K�|���u�	�����x��??	,mm�9��P�@���^�5,���c0e���c["�Oa1Tv������[�qD\K@��m�a15$")�wC����`1�)�o���-��Y<��>�`��n>�������w9�b��������{D�1,>��]a������`�7�����yB�.7��x��\�����������<�
�)�h.��'5�� ���S2�P�| �
!�(D�Z�^�����^��(Q�A!�BQB�'1��O���C��.V"Y�[����m�!���5��bO:�%	B!���HrP!�B���_N	B��A�AX*(.~��s�'����g��{�JJP!��!�B������DW�H�N_g4�?��[/@��i����������h���������7�2���mK_x�a�����L����f{�:�wL�X_�<Qd�Z����o�'��}��;&�{:��e�1!�"7�B������}=�"[r0���]�_��z� x�Xa��7^Fg�u���5�
�������Ei�u<.{j�]�%G(�B�J��Bq���O�u��;
Q"��|`/o���p�{�q3�$�������])J��kKqH�S�O�B!�K��B��..��Uom���$��Rw�0z���X91�>���'W��� ���?������U��mfI�9�l�r��L��#��	��U���h'~���_q"�@�]
+����6NE%��!��ty�/��*g�g��O
��7�
�>�Cu�A4�x<`HWx�z�����`�N�u	b�P����B��Kp*�\���t�{��J����pI�*m1
)��D�s1�7�|�����%9(D�H��T@�m�c\��,�B�I
!�[4�.�����o�=�D��_Y3�m��^e�@7��5c��9�i=����q��S�x�":t~n'�J��)i){X���e�}����-��^e��yN�=E�5
�*��b�N��V��v��?@�hQ�v��y(W&��2z8��X
���>����`�!�:���-0c)�>��m�q0i1l��1�����6��!�IMqks���ai�����
QXT@�e&�����.��#B!r$�A!�p�v��m%��]�~�et@�p�'������A�;���O��I�
��������	�0��cP\O��K�:�=�5��Ps��xD��]
���@�V0h,��;���
z:�o���Spg���C�_��aR[��MY_����l�vo��xkt�����*Q%1x���;'��U�}B�>����=F!�|�s��G�B!����B�#�,gX	j[���wN���v���Gq!�X����fE�����������K7��J�K��A�`8}����.��}}�A�7��[�2b
����R�EX�'�Z����!
@��O�oUh���|�|�(5���x�e�9x;%�hV�^�O�S��q�k{�c��;���^�|su}e���16!��&����ZI�`09�T0x��$��Tl��J�����D��k�a���1����Y��d2�n{�dH�@K�Y���x�?,y�?�|�Z�I_5�~��J�vj
�h��2�Tp1���������q~�y}=���+�v�_O|�����!�����cY�B!�p"�A!�p�b�����Y@���D4OF{�P�9���PS�71PgF�
a��7x��lx�i?~��%���RIt-1���x��i�!2��P�,T
kj�����Z��N��m�OL�`�I(J-�}zbFs��h�\$��G�7���v����qe���
�M�#���O����xa�j�4�h��_HW�����mqh�������
?�Z�t�1�� ��}�?u5�r��%���W")��K�����O����0�K��kF����x�������hU�1^>���k&���X������C��&Tj�s�\�xe����k���V��S��������o8Z��V�S����ZsLP;_�B!���$���XO�����I���]���gP��	�P�
����HH/�v�G\eN<�{BZb�M����)�ydo�P�v&N�6�D'O����L*�s*��� T�����Co����+����bsn�S}9���
������KP+��SP��a����U����������\�T�����	�m9��C�.��r���5�{�{9Q9��%����G�����,��m�u(��b���l��]�����}�b��k	�~;����u��t{jWsX|%��/��\+�~�>���K����.�|M��c�����xT%��R*�=G��vR��Y|��x�^]���s�x �ms^���}X��g��=��1��'
�.������9�����2O	��q���m	�����|����}�	!��m2H!���Q����>b%�_4���2$��k���Ak�<�:���������]{������?�+
��T�>��Z&b��]��T)g@X�2�=3�hq���o�8a����	a�R._!���q�j�����4����A��[�1+���~�j����jv����
����<���
���������H�
�L��C�;�t�\�\�$��������ZF(W*�+����z��_0����_[�/������&-��~������q���3��� o7y%\������e�r��Y<�����������N�"yz�W���.C�������W1n�
.[^f���S��R�T�b�B�&�ic���W'�k���������}:N`��
$��<�*�/j5�%��gi��������O����6c����t���&�y���i?�;O�;{�*��=	�S4���e�o�xq[*8�`�h�����������q�� �qma[x$�z�m��,J"�B���}�B����m8�������Y�y2�Ro�8z������/��<�O��2wry���m�Ys��>#5&�����*I�������C�w������|��r��:����(|�E�]��kl�K�5	06g��'i��`�m&��?�4i5�bU������4=��%P���L�t0r�(k;���)���H�����]���Z8���>]a�J���4<���/��;�0����,B+�KC��o����}��L�*��BXE�E���s���V�=uT~d!�=�CI��)S�h�z��|�����qd��r<�rv�R~�jf��aY�yP�c���e|�1���m����q�a6oO��}
)g�����7W&�k�+?�%�����Yo��mY����2�fj+����k��K���l�~R�kE�jADm����0�6��L�:��{y�?�?v1��t�8�i����[wqFmLxi���Z�m�~�dn*�	B!n�$��m�����s.��S��	<�����qQTonM��Z�7{%�����Q�G����4�#bc�n\�-�R�����C�������5�v�q]�#^/��^�e�����SY7��^L����NC>�%(�|�p���^>}+��%H��t\����H�nM��n|�U����U��i
����x���,R�r��BX��C��m���a�z�iF���)zs��M�����y�.DsA��Q�C�RW�
�
W�]"�����HM�)(>���H>~�����_��6�5��i4�yLiO�@O�9"Oq�J)L��q�5��-�A!������B!����H��oZ��Lz�8w��w��n[�4P����0s:����-�����2t����������K_`�q%�:L������H������z�8w��_��B�fui�k4���'e��x����u�{2�6�������m��fF����z�uv4�������d����X����H(������J��!�B�9(�B!��n0}8q�s6WW}����b����^5-�4���'�s��T�Y}�!v�����p\�J���D�9.���L�4h`_u�i:U���6|9����f �^:HJH�r$��Gl�w��U �SD_�����q�B2`oG���h������O��+��8V��6�<����y��z���#M������#�z�x�������4v��Xx$�^����3�B�I
!J���?�Tn�e�h�Z��oZH����������K�/�<��*���6��8� IDAT�3��bX����0�?�t������t|y�^����C%���&��u��dtq��"�
�'�c%=z�6��O�^6�Hap{O@���c\6T�F�]`S����d�v���?���f�7���z����[����<�a(�Y�=zP���QS����SQ�!�2U��o�������B�'I
!J��s�eq!�%�;���r�.#qG>��������k��V�c���Q�V�V� [���!�����������yftV�B���=W���j�����zR��rj�_D��7�1aTg��j�����[�rE�My�{
gd�Q|8v��o��m`����)�4d���|��t����
c�a�Bv������i��c�7~1I��3��'����Q�]��|/����_h�J][B�z��_�r��T*��9&�������3B!\���B!�����k9�q������r�w;f���V�^�;�=�-���x��J�v������Oy��T��o$?�)xx�\�:-�����c	t�9�����0>���/bt�������x����w.#�X���^��9�	R�T�6?�O��w�s�eO�;������N��u���b6s�[���6�1��1<��#������i,��,
`��7�?J�wf�}X*���\]��B!���%-�
e�b��J��\�l�+h8y��+�}�!$�>}=�}�C�&�{s���)<�6���g�7�:�V�1�!�z��:Y�oW?s���[�qx��]�(�7k��
�w����6-XV��M����i�N[���i�{UCSUT����hV���Z�h��\���~��L�{�iY����#q���%u\}RU�����<����*�dA�sn��H~>>2���� e���}���d���x���y������i�2t��O��n�X������V�}$kQ�k��7����25��r�Qt:tz=:�E�C��n:�b���Q2���T���X!������ER���V���_Jjjj�����Hz��y��B!�%�f�x�~SU5��j�f�����iG�o46����7�3��gQ<��r��'i��5^��3�o������M�k������x��V�'N�@��g��t�l7�� T��N�B!��T�=����8�sf��Y�[<����3n�5��V���v����=�c����(��1�9T�:2�JM��S�f��������%��9������f��Wa�_�i�e�R>�)��Df��euE��Q��#���Z����/������O;i���BJ!to-�(���
��?�rH��w��b6��(��J��8}C"�_(�nK�O�f��U��y�8����k��p�����
����Y��K��:*��
�Mg�����z��w�L��R�����M�z����MI���KP��G�!�(Y��t)������5�b�vl�-@D�-X��*�Y&=�h	,�������Y�F,�&�RW��M����z�hD�X�m�����`	hw�L���X��H���T��sa�3m`���ZT�}�6�������6T}=QX������"8|C������oE��|�C��H�����>���AQZ����� �PMWL�+4��f���B!nk�u�3!�B!�B!J=I
!�B�.�(�^���-����O����c��;H-�X�B�RL��BQ��X�>Z���W�/������w�J���z2c/�?���23�W������!���6�
R�(*��)<��<�j���v�q�`������}X'W�(	9��~���=����Lo�����e
H�����`���\�9��H����?�
I�>7)��Z���go���
��s���l>~����B!��$����1����A;-� ��={S�7�6�%���rHO0���_���x������Vw�+>T�U�Z�@��u	����03uj�PD�*ZO����_���n={!�B��_�D!J��������Py'�:C����@�f���)�y�|�"�SB!�p��B����G|�t4���2��d~��?�3��Y91�1�u����1R9��}L�+�
���%e2�o���=k<S�2�{s����{D��_'�����9
[�+@���Y�y�|/�+<�g/m'.[u*��gy�1�,;�5����}�K���IM�/��@��a�12��_?���e1���_C�y��]x���������g��}�|y:�Pd-��������0�}��_f�s���<{����n<�,]�@��a��d�`,
��#>����]����!�����pY����a�������ep�B�:F|?E�����xD��b�:
���������~<����Z�?���AhCL>����>��Z��1m�b�w�C������*c�����z��
���0(5P�:���V-�u�=E�zw�UO�6����4�o��G�#I�8?�}��yXcL�������h���������$__�l���A�*����\b���z`��&��w�b���Kt��oSC*6~���#!��������Wi���6��-���>������^dQ��(J
�.����X����|w*����l:���
r���]a���V[�jc�jN�VO��w'p���e���i\�)�>����5�9�>_���/�G���x��]�;]����	�R��Q�;�k2�uWd��Bq�H!�@#q��|1f3~�`H��$���5�����6C��H3�����;���e�Luz����CA���2�L�\��%���U��G#&b_�<M��O����������4�+���������H�:�;�����_���L�����'*�_�J�c���^������;F�����h�^�VB�>0�������������-��
p�(,Z	�apO ���H�8Ft���[a�
�	���Aj�����:�NZ`Q8�&�
�@�������pw{h�Wc`�E�� ���O�3��N_����	���*o�s��h(S�jAz8r����C7o��E,�}o>F�)�8�y��T@w�j�`t�i>�wcv�c��w�����������9��k�Q����-���`�W������9�5yT���,����c���S�����^;��_"�S�!>����H����Q^��yj�}���_�������q)S��|�.b�V&��o<F�W.�u�+|���S�>��#��~���C���a��}x?6�������,~�-�K�����������3�����r�<�.F2��X~�0�_>O���|�����������S�un������^k�R/���������;
Fg�b������?����'�z�F�m��c��:�7��K�!��1�W��s�y0�M����P��i���m���'���LS �B�,�B-��6��^F���2:�s5�}O�r�b�'��,�b���	����"0<�uN��������?�oF*�7�4�?���wOl����q��{D���^f��U\j0����������;����q��Q���W�j0��B�"�9+������PS��zC�����C�n��^mn�$P�_����������N@��0�(@-
�]���'�zB�7�f�
U��Z��i�v��������h�W�����Og�:���?�6��l��U��j�8������"�6��n5��G�����n*���e��`r8���f�������z??�k��\j� s�������~��24���.Uu��5�G7������b���`,_��
je~�Um�M�Z��[K2rj�����y�q�m	���*p��H�/���E��|�.bp�1~#s��M��_�������KS�N�`����=dM�S����]|���7���������ucW�zd�I��o�V����b:2�+<PA�a��D������tX������-���<�n��|�7�����K�������<��u�j���|�1V�_�������u`H={e����G�k/��N`z#�"�����kgqoxM�(�B����B�����4���#0�]Q	 �c�}��PD�

:Q�k;���g]���xOp��Bh�:�����r�0�w�B�t�����0�-e3��z������c��(C�J�J�|��sh�.��|��r�'�P�cu�?��a(\���I�����2�~~��
~l�P�{%)���k���}��B�Ix{�����W��g�;Z���;��t�6�x�G�����$Alb�!�y�#�T��=�@������T9��>N����_f��������c'\����F�0tW.s�����nH���=��Bl#��v���k���B	���>�#{����4U�F�r�������������������N�����{������w=�C{�yM����M9���b2��d��o��8�r�3��@'y��:���������=-9�a�����2������\��3����BQX���B��$]c���Lc�JJ��@Q|W1���=|�d�{�/-)�+��|2�@+�xd~���_#1�����0c�CU��U3��AE�U�x�����b!����]�G�X������Ih��:�O�up�u��x���e�y8%@sHz�m	/��t7<�	0A�;�
�=	5�K/\������~�����P��D|�����EK�P����
�<�4�+.8M���(
:��B*�9������I<�@��"Q��SG^-���#�P��u(h���i`h��Lg`�c1��<�����, ��X�F3*����3��N��=�{�g�<;�^
g2���B!n&I
!���$�:����������TtJ�oPjJA����0�#A������n����1z@rB
&��=-��$�������I���N����f�<^�$8�^��x�w>����e�F
�v����PA�4�-	��m3��[��H��1@���[b����
�a����'�%�����i�`C�7�J�R�����P�&��Q��>�lZw���z�mV���U���}}|m���b��$�v��{�M�x{A��k��KZ�f~��J���T��\���8�-]}�v/�
h���� �gc����X6���Z}�[�>?���"���42���I��5a�f���9������f6�5��y5��hql�x�����	mT�Pu{O�eR����&������L�<�^f���J��N�C�;Y��7���������O����Bq�HrP!<�����6 F�a��O�����(
�bP�
���q$�PV�����4���B������go]��4j���+�Q1�����u`��Xih{3O<���V�d��TsK=������E	v����[�Xa��A��\:�o��\�����z:������F�/U��ga@M[���p\��B{��y�C����Q�N���F�����-)s�AU�Z�mEf?�n��ga_*Y'������O����g���)�R��h�{�`X��L��=O�y�J��[H,�}��4e��6��aE�x����/�}���-*�|.sB������3�������]=�s��EBk�y��-���;}C�e���������*G��d&s����/�NLx���gD�k���U2i�����
|R���I�$>��_t#8�I�����c:�&��:i/u�Z�~>~�C���w����Fl�gL�O��&���`��4:�3���o?����	O������kX��	��4`���x��Me-��ZN��lL�p����.�#o}7��_f�3���iwB���BqSHrP!������C��|���%1�{��3Q���y�t�Q���uY������_����=9�/Kp/bW���>&��7�*O�`KJ�Bhpom"���j4�#��4z��^��M��h�,����KZ�<]9���m���{h;��WJW����
t��?!�[�d�E����p8sV&��zY[�|!�6�������~P���z�`tC��-�c9HM�cg�h ����0�
��	�����&[��k�������88� �+�EJ2h��o�'��B��	'�`LPf�M��!��#�n��p�4���I
�#�a�Nh�����_/=dK��~�/Ao�����s
*����li��_���Y���f��o����LdL=w��|�3�5������`�W�?1�{�Uv�t����^���Mf����z��N��|��F��w]�����'c}�c^�5q���
a��R�P}.18'1���E�����N���dj���O�`�}nlrpC3&-z��c���;��#�6���L��=Y��m�Nx���|����y��o<L�\���J���_���ak�]o}�����:�zT�����{�\��|�E��x��B��/���7������o0��R�^��xP���:<�����m����0�OS�.����B!
D�
!
^=����2�K�~��G�Z�{{2=e|1�h�������3wb0�����^��9�g���Gh>�K��OR
�?�*��j�b4����_�����}y��0r,�.,`�}��!�����h�)�����`�wA�6�W~M�!���u�5�+�2�S�S�	��3��0�-�T��:�����W��r����������O���k���*@�������
.����a�/������$�
o|z0��%�xV��}pZm"
�C`����N��B�Px�/�vH�����A��_�M$\��Rmo��&��9a�������8���/n"]9:>;�?�uq��.�����T�^3����G!h�"�Fe��W��[�������m:�s�b	����9�~\��\��B`�|�iD�%r����5$�tl����f��*
����]�a6'=�cl������c������?�fv�Qg����1���.��e+��G���G\����?b*kGL��d����As9�g�P!�B&I
!F��}�Q���eP�1u*�Nu�ym\�WkO�5������:�,k��,?o�<��>�<O>��s=���C���s=����27G�Q�R-x�V�Q�IS��4�6/��s�K��8}�A��d��`�h�}z�<&����an�<�LA�Xx,���U���N;k�?!�B!JI
!�"�����dhRL�������>W!�Bq����B!��;w�������f��*�`B�
����Bq����B!�+_��^�Q!�B!��,�'�B!�B!D)%�A!�B!��F����y��,������g�!)�S�zl	�C���G�Q��	!�B���uX���\�c���Mj�2��/��������Q.�BE���|LW>����Q����S�"eVCl�������WT��0��9��O�,�%�Y)����EZ������[��P��C��M���C"o����XK��l��������fU�T5���fU�����J�T6��8�������������03uj��/���rT�]�/n�C�W�������Qt:tz�Ng��SP�NEAQ�����������B�����K�<U1SRSS��
DFF��g���B!�(!4M�v�i��f�;��V���w��M��?i��)���b���P|��
�!��1`��C>66��R\[��������@����~��$����w����=��-g������������]*��f?�����h��b�@hh(J����B�Ht�$����Lr/� B�t�9|����!�{�s���� ��|���q��w��e���q���y�d�������O���_��R�1��C����^q���c�wY����P{"8l8!Q���:~n�,/�8
���K!������F��(������O�v�oS*$�?U�t[��dO�~��{k\�B�N�j����y�lG$����c9��,������q����k�r8���`�w;8z+�L�h2e>��� E]a���LY}���N��P�����iIW$�xv%�����w��<���
�2cf�zJ@�O������*CvJ����aEQ\_D�B?Rd���T`82�����f�U�,���0��Px�Q���4P�=�� IDAT`�����A��,=fLdl�,(1sk��M��s7�<N��_!�~����+���l[`9��������M�5�.�����C(����c?|�W����m���~���n�� �/&����3!�>�D�t#W�z�v(�
9���#~�Q�aH�N���������h (%K�H�7%�*�
@!Y����O�XA�r��t]��V���R�%��y��1�4r�����'��"1�RK
�����R�%�r������o�n�����Rf��W�i�4�zL:xX��\�����j)�	R�M�r���v��|rM��gi�i�������k��{/H]2U�-�|G"#�������T�%k��Q<���Hf�;,n��^�<�{jd������y���K��O���y~?f�����_E����4t�T�\Z���
������8v�����m��|P�8��:���4���<:��A_��H�V��8������6��'Q��LZd�yr�(�`������	;��	c�S��"�}WkBJ]��-n��
��xJp+��
���'�G=&x�(6�s&l�B�w�@�i#��fA��������������eV��A�.�?�9e�r��m�����EA�w-���� � �G$����![���WG��G�3i��v�gbKM��J�xR�+Sg�������(\���P�,�����}�����G<2�R=��J�!H��.��1*<)T�*�P1�~9��B5������e�V��gL��fm���O�z�,��jT��sk�����/��;��XI��|��4+NQ�A�O;�O�U�<��e�T/�kX-:LZ���(��l���]�(O%�K�h��/
�lQ;:/|����~�AAH'��AA�_c�v����T.�(1f�<�mejTuMh��R��y|�<��f�������S��@]�_��Y��.��b����l,:efr�(�z��X�$E�Ld&�����WI@���5\��sv�$1^?��w*J�7�A5
��v������������3=M�x���� � ��2Z�4��������[C�2���<����%��b'�<{�����Z6`d����Y�Q�2�|?~�t�'����bM�F�����9�jG�>{@�C���0��F���wQ�Oo�������b�aP$���Y��z�a��nJ�e��f�X9u+T�� �����?�������A�kQ��n�AR(Pb������MF���$��d]�kH
	��Ivvt'�r��U��1��mO��AA����� Bz0��ru��A+e��4_<�����n�<_�
�'�F�tFI�{_�]E/��	�S	���L��yJ@V%x��r��a��I�
P�9�C{/&��� k��d7�c��������{,���iG�Y$'���`��_91�!?-c�C�WF2)��z��;�W���$������� G� �
�TP�bn�w���{�����?���1-� �;'�AxOIrP�,Z	�Y�����}��������[]�:[K�W�BZS�`�����|��P��mzG�fnA���jS?���/=������R�����56��W�M�J�,��>+���p�W/�$a����(�
W�SN�z�I���n�hR��O�g�ggj�i��JT$AM�w3mRNZ��Aq�w&?�[�����$
�����
��.�>E%�<p�V�$���U2���
���z��rg�B������m)���� � �[��u�or��dj�nu3|�$�L��������g�c��F�O;P� .
��`U���'��][��
H�Wea�.�W��a5�.7G2k+����99�����Rx�-/.d��=\=F�3�<�nK���p|y�X��u��6�(a!�H^d.[������r�o�Y����x��}���bP���@��i�F0:�?���>Z��0py@k�>������F�����p9�J��~��@�{�I[��+�(P��`4a�����6���|B
�^K��w��w��:� ���H������h8���2�3B$PM�`���Y��q��	�;$?
�i=,2�u3�*��#�QZ��0 2h`��2M�ar4\W�
I:�{3Y��ca�	L|��OU��B�O|��`�	�4t�q���Ti���w=�4�]�PH
����,���`�	����Bu�A�4�2�7��G�5��2���]���d�Oc ����&�69�d�J	��p�������Y4	�i�����*@s��FX��S&@��*�q��}�K�9Rf�b�{N���Sh=5�}(3p&-���m�2��&���^L�r$g�������;m5>�������g�*��)T��V��@f����;��0��>L�Q�����U)���j�I�<������q��b����T����w�a�>:����RK�L�*�l������_.`����~�G�p(M�%���[4�A�������p��o8Y�6����?��e������z���	;��	�Y�O��(2��h��l��'��k��0����<�.C�������`�:��s�x����f��8�
����[�g.N�q
���"��a�=�_�'���`>��>;��[;Z�����;��H���9]v� |�db��c��C���J�Z�9��]_�$�e-z����K�[J=��}:�+F��GNH(\<'��1��d�����p\�J����-y����1������~��Wf5�P��]�0|�-�9�\
���HVA]��-����#��a��Ul�8���z(��Q
xh�E�����
P)`����n����H03��A��P�a��aa�h����xv����@!	6�,�U�����M4PA��p��$$�2L���
����P�4Am�%�v�T�G�u#��'g����J%Lw�b^?���0��&�:)�+(�����S��%����F�<���`�e:����SKEF����y��]g�D���/�Pg���������L�_���Ug)�������_-����.��v�>m�����rn��\�I{�XF+N��?�����$�'�"n�m��4`
���F��(�$e@7��u�k���?AA>:"9������M��;�i�K[r���3?���<)���?6$�� ^���]���]��C�%O�R8t9��;�����x�������9lVd�E���(�+A�|8�\a��}�����j	�Fim{�W)?��}X��2���p�n�DH��U��$��2v��.�� ����\�i?Q�:�yt]2(������������o��=�v��l�`��Q-�t��G�,�&��f3#���XR�V�3mF�M�=�r�%��=PK�f��_�� ����.pPBO8���6A]����#Tr�v*K9@{�L�Y�����Q�3D��/h��L�s��F�����Z;A�Tl�����
�U��h�j�VP���������]y����V���	J���&B����E=F;AE�����	I� 
�,S\����	�mN���������
�Ht�@v�R�V�593X�w�������i��MQ*��h���,��#p_ey���r�AA��#*���#�:t
�3Shl;�f��e�����Lx�/����J2�����[�b9�u�\���78��!f�t�nf�P�\�jI����'�|���Gy�6[O�c�qa�,���D�N���������Eg�A[�'���r+�����km;c�����l��la<��9%r��E�t���` Xe�V�_?�O�N����d���u��%F���eU����$����!NufK���6�V����fy�	.�P9I���Jxb�p�iM!�	��Y�Vm�
"	�����u),�zng<:3��l��Ui���o���
K3�o�p����q�Z�N����E:��d�(�	�"a�r����OZR* ��s	�R�.Y�l{AU�AO��$����4AA�w���-�S��-L�"�87ee+5!����M����	_0~��BfL�/�/d���1Ee����<������	�H��?�$W-�����	5��E� �rm�$�o�D����^�hTf�|3���M/���%��z���sw�k���q&K��4�L��,���c����mG�7g$C,:o���
���K�HR�~����o%u+GP~qm����?�DBb'��tr�}]���2��a��t@ii:��:M��jJ��UU�?����9"g��d��v���--7m�C�j)��}����0Dg�!HC���g�n��$��}�c���� �u�e1�8I�m��%)��,]*�O�!
�����4by����?OI��M�AA> "9hK�M��C��������yv	���
���qrP�7d4�k'�lIR������"[�
dXt�s������l��[&H G��3����)2N8�J`���md��kj��l=����9i��27kG�f�0G?���5l��m������)�Y��R8����}y��^D#���X�"i�^�!�� R�!�/��1�-�AH�������������d���*$��H����'Xj����Y�� [*��NR3-Z�����x�����.kr�-�����-���0'
*�����/�I���&4C;gK�����C�l����������0c��(� � |PDv('�J�y��`PN�Z����K�J*yr%�2���dBk�;]Q�"Erf�j�?�K���^�p.��L���_J���)��^�F�z�x��P������V$P8g��c
�D����gG��g�{�~�\��p����e�cAl(}������s������	=z�@��8��@x1�V�]�H���
���vW2��O$�8����m�y��W����7��<����J�����F�?,#����F�P+���2�PX����r(.��0K�0�
�`�>a$���g�'6���!��2��=��o�iSB�1��RKJ9),#>��|b�(!�&��m�
���@�	.| �:�d�$)I�41Cf�{�C�����d�I��S�����������u��T���W����u�i��Wn��#AA�����R����T�:����wKc�:xQ����h1��M(��/N������Y���krPzS��?�F\F���5�U��p��q�_�[���<�/������]V�����_��\�3�"�6IF�+����,�'c/����k���c��*�s=\�nc��x�����6��D�	�x;nC�������!y��S���f�h-Ujg$��zvr$����~x����C�\�Z��^���2dIR�2#����}+�k:��Q��=32&\i�������hd�;9�`�9Q��
��?}LL��p�����w,������s[�<����xka��sdUo����������v�B�7[j�����ex [�1�%��g*P_�uP�	�?��#�������TVZ��a�
���Rn��V�lKS����
*h��k��&���
�`�����{�Q@C����@a,�'����`{�U@YdN��=l����`j,tr���5Z��R
*%�`��h���t�k?���R�Q�-I�3<�,��)��Ix.l6��e����4���X	4PZ��0���<�f�����X���L�9�S�ngw�����
���q 4����z��+�#s��~9��Wi��2��
���n�{�j�Me��� � �'����8�R���\����s��u`N4�Z�i�;�O�����sp��@^����[�s,	��E����YI���
�C��a��.��^�������[�z(6�O�`u��0yd%W�f�n��-������M84t+�f4~NB����o�Y\�{I8U�E�il�n	k�C�����c��0�����lk�c���L���)_��"���H@����|)���%�n'1`l��-Mg7���&$�
�g�+���-�������~�M���=�1�T������AH2L��C6�������d5�u�y���U�x�,Z
L�`���YF�����JK����o�4����[
��07JkS6H�J�ab�e������&���x�8��8X���tq�&�i�s*`��5[�y>
��	���CW(`���`M�ep�T[c�`�#L�A=�*�����v
������l���B������RX^u
���i1������`�6Ls��0Sz	�PV���K{������������d�{�&���4���~e���0k�P��]�����5�l�����������qI.g.���mmZm���S��*0��r�l����'��� � �y"9h����!�OSnJ���6S�T��&�?yKi2�����(�j�$���$�����>+>8��JPsm	j&�Z��6�4���d]�������ed��'��)�� Ii���7���~�,�'�Od���+Q.�Y�9�RmU�'}A��rk�$�L'�,��"o���8F��2����{,�$g�/�>��N����B��N��vb2���:���T'�����W��w���-�����
��)�$��9A��k2C������n:�7vT��(��t���U05��V�u��=�i��[���;�L�����W��������}�U�T�>��
�Xjs�_y�T�r�N:JI<3wW-dy���~a��T��jW,����L>i���]��~Z������{�vS�ty
�l�����a�A�,
z7�d���{�A���.+A�='�LS2q�!������^��a5����A��{`��8o��&X��$Ne>X�����9�~���N�����)�LP����T�[
�ca|����57�:�������>Ept*�w`/�\�s��qn**2r�`z��N��u�t�pft�Y�[?����)�[�sY�L`�]����S�$�XoO^&Qc���J.���/���^����R�f�����hW>O�@�s6�������s�:V���6g������4M����L���u�����H��W'�{A����6���#<�JA��#j�)#!���j��g�&4V(�]�� ��%����!N%�uL<���A����%w*0�W)�>iM�2���SfW��/T���I�Q�	1����	����:b����YP����mz�@�����!<4�\�j�����t�5?�����dL�����]�(��?�Him(�G��SS
~��P�:J��T/~[�o	�Y��^�����&����2��h?��~�B���>�:4�:
V"����yQ^������p'�T�S��S��
�������d2>����[�E�<=w�C��3q�xJ8��{)_��G����1��V�SA��'��iJM���37���n���9r3a�7����M�QM����p
���d�o
��fO�������6�T0�#;mI���o���a�N�����[B��9=�,d��=��V���d��2}�|������-��zq\�j�a�*��@��V0i�����cz}��	���X5|�F�$��2���������������
�9��A�'���(A��n���6��@�
�b$m&���o�J�&�/[�������C)zv��������j���D~��I+�^�/�w!��Y�b�R��y���"�|��~��\/��3���7��=7U�T��
���}u��I�;�M�+� � |�>��lA�$T��8���� |H�J$F;}�����|s��x�fWE�&�,�����kYV���oo.n�~�S�T
.���<�Q��s�n"�_g	UaT�Wk�)2Rc�R������e��)M��F����g����=�5&�-����1���o���_.�d�e
v�L)%:�����,�:���o��g������<�/9�U �i�5��U�����s9r���z�y4�=%�L��� ���$��� � �������8����L�}IR�����������c�$;��HHo�����P���������3`4�k,��,��$c�Gw��es�nxx IDAT^�Ab���,�����Q
M��8���{�Z��m�����I��,/�1�2o��P�U`2!�A��K�&��,�iR�;_�ca��{��@�{�T��c����>�U�Y�=�_F�W��Z�c������~���CD��'�����-�N�������?A�y�;��,?��s5H�0��d���,������l�1�-�����$#���&3�m���KW�8pK:z�$������6���_R�:�lNHUI����
Q�-���.��]
����0�������E�����="i��[F��<�P�nss5T�,k���0/���H����V����D�:G�m�v�U��Y���M��L�}������s�����Y�,�<�*���?�s�T�<J3w���"?�@@��*��?�-S!�<�]�s�CR*P(%$��^�@RH(�BB�$���yy !���� � |��59�u��d��t~���m�\���_����k��~���n�2�yG�����Z'�9��Sz��8�r9;���"U�����B�Z�=���~YA�7�����,�������f2�^�%MF����{��Z��g��wf��-,��?�*z�������8Q�)e����K���l:_�f��2dP!*�L�!�,������EI��R\�J\�Ww�����|R���;P�!���g��������*b��c���g�N��*<�3��&�������4(��Y(������jT(���] }�J�y�J�ja,�����T)�%Q
H9gCj���W8&S��q�+��������z�h�ekf��M��t����V����,���ORZ��
��q{�:'�Ca�����(^��DX���Q*���
E��$I/�%k����� � $xg������:O��*�,Y�����I���-��^]����K�-+H��~�y�b�k��w��WH!1/�����;~/�[F*��2�;�,�B�z�g��<����1�������[0�"�Q���1�y]4�����y
~���=?���Bd��'C�&r�g�f��T-���)��>����o}l6[�e0�-�m�M�6P��l7�
v�q�W��9V�C���Y��SjVa��Z�7�1�j���i>�l����S+�`Y
�~��mNS������=�4m�,g|;k�DUn�mX�v�4f��OL8g�G��5������&F-
�^���7+�e���4�$�������|7�K<����K��_��%xJ���1��PF��K-�3���$��?�m(����^i-yT�EMg���������=�:��������Oj
�b���������P�1r�<��3�U#���?	��#��1#_�]C����� �f?J6)���&a�{�A���I�-5Q(,��5_>�'��� ��F
���&���~�����d�k���$�����Z���C���S\p��U���q���)tv�ey�����^��69�:�
�J�X|�������\��.�9s KuK��%��e�z:;Ux������1tv*dy����X�n��gs�?�%HS��e��F]�sF�/��H�\2��|�|:;�LMhibi�a:;VK��(��/����{t8��.�
�A��������������$���ErPA���B�^8�������-���R�?MAAAA�#%��� � � � �����wA~N����8��7���'L!�W��9�22GY�v�F�?-S��5�Y���$79���r����~��dC����<����_��Z<���&p��n5_#��-[0��	���!}��C���E�F�@��0�d��&��n�W��{w�|~�}y�A����A��0��kf�a�6Xw�ww"#� � �/Dr�]0?#d�Ny������)�t����AM�������{�\����B�s8!��q����~�q�9���5_"| $'���wq��}�f�
rd�,�����Z�AA�����
��Y���g�4z�e��mu�R1J� )��=WF���G������l�A�����%���In��D�,OzG"�s�!f~5���&s�I�uc&3��?�I+?a���t�sI�LA�� Uz�����/s������F#yd!s�zT��������:�3;������1y�"o���_	\@�v~.>����^:2�;���0`\	�v�b������L��78��,�*r�����*�f_!��.mg�����M"���"�{?j����u����,�:�P��?�N���	���i�O��Q�G[�#�di��f��1��D���L�o���`L��3'�ar�A�1���A��&iF�������An�������R��?	�D��^�t�.}v7�K	`�r���}�)C��@����gr9�e��A��
����8L+d��piP��9�wK��N�C��xs87��e���<�y���5�LI�1u�Wv�����O1y� o�O�7���{Kx�m��e`P������f�	�����SXx"4��
L�������#,=zh��9.8������#t��-�

a�rd��*[��/`�0�T	6�m
�M��93`�Y0e��m��R6g!o�@����`�0xB�pyx|�J��>D����G!4<��t��2��tw�[
�.�c3����m�eN�����{�d<7�o�������jw<�2���a�x���u,1g��l�	�F�u A��`���x�G�|0����	r�dyX�9ln�sPq6T,{��B
��=���U���3q~��BS�i@&��_�@�`\�!�����L��7��u�~�$/�^`���H��].��M���u;����IA�?H$��W���]h:��UMxJ��kDD�/�����N��U�D��������)��N��N]}Q��h�&��B9��s�T�L���Q �p�`gb0���M�*0��G�Asu=�t�z��t��kg�O����g�H�Q��Rwa'��
�W��l��H�
iu�*F�a~�������������K+Y�c;J��]��H�]�uw��?���t����1B�����^dbw.d������#-?�H��_�5h,q��h����c���N.���.�ZN�J��t�o��*\=}HJS��Nv��H����dO<2�?�b��;�������=g%�QBI�c+X�|�����,��G�7f������GT�x��R�;
���~�+{�F��.�=�B�"���a�0��EL�h-7B=�2�Z��A�F07�9S��v<t�u�����M��'�Z;\au��%.�u0L!`�lp}s�2lX�nB�PR���-�U;��!p�7��tn52����7l�	0?�c��|�
�k��8x���7oA��0�!x���a?�'C#�����"|�7a��K�-IV�/���p�?���^0&��0}����Z����X�r,D���n�������-�Gm��	"�Ad�\����������7�q�����_���)>3A���HZ�/^���M�'��y���`~��YkyR�;��u$�
�^�W��dw;�'��	��N`����n��������<U��FFw	J��F����r+:����wN���@Z�nG�b�.6`���[*%���d��>j�
�9�����dq2��T�5�<r	S��)?�L�����'��ZN�r���B� �k�./<HT��t�Z�
 (7��^��� �M�i�Yr���L�8:H(�=�����w��%�UYv�o?7��'���w8��R��4R	'	���_�{B��1?����<)������I
P��[������:�C��|�� ��������0��@��Pz��J��.��u�@�r�r
�������`�(��6��	��PX�:��L�[�
��@�*0�O�9����	s.���K@>���A����#�,;
���[���	�������MP����Dh |���S�`��
�Z��i�@;�����tL�\��p��������T0���(�0��nV����,���d+�)!SF��Jpp��mjo�	�i���w{�Zer������a�Lf���AA�U�Z��: 7������n����<�N��[
���0%J���e�?I�Zo�\��v��u�"s�����E
t��ra�W,�R����0���7����9q)Y��O���"�3��#"0��}�*��g�u���1�{��xV,�G����N���������nV��D��_���8)oO<q!��"��b��]H�W��~b�Un�0���<^/��J2�������,�}�r�H��'9A�GY����������������p�u��\"TB�<��<��u��.A�9��!�/W�b�����e���mx,�O\(\�,���b<�A�����z�>������V8I�	0����Z�&i����)�L�U{C�N�
6E�����7�-{)}��s|AP"?H��r�I��IN
pq�<�1��U�X����~uy����J���qw����$����������u��>�P��8:��@�Q,:�r��cb���p/���9K|�j�>����S�$�Xo����#�k�(j���!?�ne	(����Y���s|��E|K�u��6cm�n�*��oi���^��f�NP�5����,���G��4Z��e�I��gxu�����s��(�V�m��������}�uhJ����s~��"x�����'��O��g�d��9K����7�9?�?%s���89�`��G�zx��%C����T�[
�ca|����57�0^bt��dh�;���?ZG]mq�lx�����	'����s;v����� � �Qs�JY��g��p-���=ndi�?�MiL'��_�7rwJ[�c��l�$�!6���A9:��=�qrD�c����}������Y���r�FS�Hf4Jwf�e�S���Q�7������g�8{�����0�	���w-�!�������4�(���e�N]+e��q��M���6��\��|���(b�&�����q6E�fL��/d���>8�$��%jt��Y�}�;�3�������7��/`�M9�d_K���D�*+4��#��^��\��/G�8��bdP��*�����v9�K*��7�C�bM`�	���+gh�&���1���k��c`�$��	��
g�fM�I:�|[<�R$�'.N �!*�������
@a}s%	����&��.��������\>x�����tvY\
�9�z![������l���K�t���@O��Y#80{}j�$��R�������9]��k�P>��{����9�@S���o��-��5+�����z<�?������D��n?������Aw����D�u
[���K����i���Y�/�6�'�����l��Y8�(��+��s���������	s�I��P��DC��oN/�g~a��t�Q�#C�Q��\9t���{�����st�t��L�S��O���:�����L\]
����s9,��w�h�}����g$G��dL��ed��o��+�8�MOj�zL��Ql,�L�������FV��Cp��L�z�����WC���������U���&�?�\�R��n�gYBdA!����KNdn�����c����
s�<f�J��s��H�n89���l�k8%^T���M�D�����v��h���������x�;�����j��z*�Cs�[�7(�DnPx_(�pt]x��D]D����7��P$��#c��2�C
(�nY��}\,h���#I�E������q�|��8�12xZ�uv�I��o�d���d�����'��?{�����b�������A�GC�$�j����0���s�K�������z�1��r�EG�&$���Go���X����(��JSh��r�~���eP�(t�H�l�K26��)�U�}��������Of�4b��(9!�\����7�ca�E������K��M�_�OjU��Q�������5k���'�3i��v�gbW$ �R&����Y���C>�D�S��������IZaK�L�+�7������oN���O�_glv���DK*��P��U�ka��8a������Z����s���r�� �<y�#�+��*Q����}��q
�L�@��������.G�����Y���j���VJ�Q��l�����2ra�O�4���
�hml���y���
o����1��e�jV��Y����w�/T���7o_���	Dd��3��[����[>����V��Vq��J�,����q�D��2�?������'�e*F^�y���P��x���Qr�_N�CAAH
��0
go��v�Pn��{O-�M ~��<��?2�����&��K�R
�8�?���7�����r��%��y��������#�G�J�'F=h�m�$G���_qb�9A����O!�_ <�s$Gz�6R���$�<���b��1���5crZ�o��)�U�H�k��� ���=�8��S����,,.�{Wl���y�+��������N��6�<�����8�=��y��a	��n�5��B���p-r����-��?3?����	�������,5�R*�2<��4��M��/��x}!�G�$$�#�����B���m�-���D���g�������Z����M-���pR��b5���^6��S��lP ���U����ZZR��eK�Q{Wd�f�@�+��;�������,B���	E���FyG�:O���F�:R��dJ�F��9���k���r2��*u����9��s���������8:��X�_��>�!w���K���z2����b�Y,=x��/���}����/s	<2�e�>=�.�k�aH~��O>���gnA�R�����h���;���
���2��M����e�=�, CD��:E���d���(����(
��
(2T�F��Q�:������{����_�@r�����\����h�H���'�d�{�����C��F�����W�	�X�������:�N���=
��[����+C�s�W�_SI=�+��V�[Wc�'��wR4(�C!�"[�r3�_M��=~�lWo-�;W��w��^��A�����>�<�e��i��*�7�u�����q�@��M�>U����5:;��G�^O����^Q����b?�)����iM<~�v�7����\�Z���c���iT�}#���P�5�����_�$�m��8:�C���l��U�o^�n�
��HQA�y��K��
��:J<�7�
o���V���t�"a�7l�fO�'����i�h^���gM��9�%�R�7S}Z/|�9��Ft�'���{<}���i�Rk@5��9��`,@<��xv�_��G�hY���i+9����5������������=*��r�[��q��/?����%J�
7oB�
�����(�dg��|l������0}-t�`��x�Z�e��^�c:�����7t	��8v����Y��~�~��o������aqm�W�����W�3u r���1!�������������k��o�d{P����W`oYhW�h`�p�^��:�aW����\�� ������@_����
��a��SW@l!�I��TxhBA{����O������h�N5��;1p�(Z����y������W�P�;��*��m�c�4��v�qc>cW�h5(*����n�
^_e����_���c��N}flZ��������TL���
za�b6����|��Q24�V)WVm��#�v|�'��R������l_��r6�M��0�����5>~�~�q|��SL�u�:�:0���b�o����v�T@QP�|�_���1$�Ksz��c����1���3rXg��X�[�hs�gN���V����smA��!�BdC~��P�:n����	���6c0����YtI�����(�-����k�a��$����KP���f��q ������<p�)�:�C����@��@��'���U�j|1�J�'���{*8�C�?'���9���<x./Mk�VS�z�'q����l�&7*�{����g����9�j_�l���4�?����{h����_f IDAT��:���8s�>ODW�*5fO �Q�{?+t-��s�E��}����b6��]�9.s}��:���|��^/���O���Y���Pp�B�7����x�������0�iv�u���=i��<�lj7�����4u#?�N��
��	�!���(]I0�%�d3}���004��/�OX�+�?Q�a�����A��5K�������w�� ���2�^�V�~����K��v��>��	�_��h5�@��0f3�^6��$�������`�|X�	C�B�BK���>�U+���	Ib�P1����aE4�0o�]	�,�L�R1�7�����i���/����V���^K�l�]��k�����\���v}`j[k<*��O����C������u��T�G��Sxu2�I���w�d��(J�\i40�q���{#�������������\����6�mg<��&%�`�o�xu�IE�����:�����OudD��]|��4����K�MK[9�`�m~�y��N5��l�V�J��q��T"�?������m_�������kKY7�#}�Z��#L���o��Q$s���J~c��v�@����.���b������S(��&~w��?S���fT@X�z�1���I�u-ye5���b�2���
(�t��
��6���;�h��Ne�	���kW~����M��Q��!�}�)	h{~
!�"W��24�O����(����@z��g}��������IP���>
��QN�G�i�RkZ6U�oE�/Z�)�����w��:�vR'�
P��uL����js�eZ�?�nS��+
Q�����s.����d^|�va�eST[�5�l��3���>��f�����+x<7*�<�Q/�.|������7���q��O��QFo���Ls>��H�
����.|(�zh�������	u��P�A�_�c�<?��������
���Y���n@�2�Ext�/��Q�P������������D��x��������l
(��[�D>�s�s�X����Smm�����\Vj�o�YZ�7�`(�������l6��u	����=o	���������:�6����xn�h*�x��ec����|z�>��4��D�/����u������}��S��vCAG����d-���`T]�KW]�<�#�
�@��/2��<����=k�v���t-Zj>�=���^���C4��w��ehsg��?���d������&{����X/���)]p0��-,�����������������2`�h^��
1�������]�I��)����~�'�2hn�����Xv�)sF7����S4�x{)���#��T�O���}����C<�2��#�6|����t_<���Sp��C��3�=������Og��|���@�XT
����=��SW����9�1=C��L�?I
!��&�A!�B��.��uw�Y%pH��W�� x(s�~Qbl���=P@Q����\�x�9$���I�=��������&�4�<�r)��g���#y'���MCy�+���s�v}��_��bL*��4}t"����A�3�8&L|���NTj3�����E|a���_��x��
���S�hr�,i�z�d��I�}��g���;����3-�!��I�v�o�|���o��q�|����8zg�0G[c��^��i��{q4�Z�}�R�O�|�'����'Q���X��H^�5��Y��6����~����SM��~�^����M�6=Y���i�������?�7�?g����X����~��wx��7�>!	���<��2��M�����'������y��
�o��~��y��/CkZ����S�kL��s*Kk�L-	�BQ �B!��O���`�5H�A����0�L@��M*��`�iI�Vtj1��?mMNs#)��yb�������r�]���rX��
��f��L�u��7�S���>���W����r���	���v������33����<���O��-j���!�Z���]�x�v��3O��]C��L��}�zp84d�wksl��&���6��p�����Vc�a���j52/�����L:t�I������^�#B�&�����!���$9X�RO�o�*.�4��*
'>F�i?��n�(�~U�����/���D����+�[��9�_>�6�M�����8���]�0�8�������	�w�p���;M>��~_E*rb�rP��B!DQ��`I��x�x�vE�A�/!���U��#K;��}�mZo��'m����n�J���M�]r��k���l�����%��p{���I����4�<Y�B!�E��B!�"o���XT��,��L4�t�-�������K|����s�v<�<&&�\�B��bK�8�Y��TK���+����!5)e
� �����h����|���?[�n��u�3X�
��.���P�k�k�yn_�S�������w!Q(F;7����������9A�2q�e	UUQ���f����������x��s����Xo����?�bYfM*�$�Ik`(�B!������I*���DcPRRRr��n�JhhhI�#�B!���f��Z��i��������7oo�R�]<x����h4n��d��$
m��Q$A(�BdQl-;\��g��h-F���12Y�h�����������D���l�u�8�H�=_����HDt|�����{���1:���:q
F�s1GVp���]����2��R�B���T	G�Q�_��h�T������R�]��2���hD���h.����l����C�o�}c�o)�0�(~j�;*�����-
1����*��]c���m��{l�H%��,q���"�S�%������&��#i�5
�'������iB�.���+�B!�+���w6dX�i���{��	�sg�s�B�P�c�8��|x�B\,����@�K�]�B��.�H:cy^�0����!��_�Hd/<B����r�['�!��_K��T��X�C��|�oU�Qe�B�
��4�c�n�y���;!vUZ�g!N�Jm��w~+�����c
f�0m�A�}��H��Y�$t���Jz�PI�o]_�>o)�i���y (����T�I�eH�>�Hv�?rz��"!��~��:���D!v�%�}��D!�B��MB���YX�kK�AHOBz�0�[ZR�^E��<�l�z6��d�����������B!D$9(�B!��^�0S�A����f�J�mR��� 6��3%	�H���,���3��$����,�����1�	
!��&����F�b�+
�q���wmb:������p
���xeQ?�K+�4����4�qD.���U����k�����������E�E���oH3B��'��L���u[��u�+������?��>���Y�r��}	���bX�i�C����%=�4_S�@�lvF�����u�i��;�������r����O��FUC�����JT1�{T__V�:�U�
����?�H,88A�?�o��Y�g��8s�A��@IK�=�:���q=��N����er����)1��X!c0Cwb�2(��\wv�B!D�,�D.���iT��/��&�wS'9��;������~9>B�&s�K7s�S
eIZ�U�����jM$�:��y����T�����zo�,O��TN�������l�����f��[��%B];BpD����P�BE��U���78������U�B�*9'�j6�g�`N�3���� ��0��JD1��p�xv74o
�}�n4�;��g���flA�1!=!�Z�i���$�m��{	��ul��n�i5���m�N���mk��Z�,�}>s}J�J�B�I>�����aO2NH(�x���y����z�s*�F3o�o����-������T��[���{���Z	��A`%\�h��A�R_	VU�g1y��6������r$l?�3^���JJQ�bg���_Sx�M�q�1$����$ �Z�L4r�![�vO�MB���d��2'3?e���z'CB�&3$%(�B�$�I��7S����\<��^�F}i?uU<�.6L����M�.����1�4t�F��Y��aE��8�d-~�?��6l5c&�(P����O3}L*���������"&���|k�����O�I���X~�'�g��}���4h=�����S)'V�u�2N�~���)R��	tP{����%/�k��a�\8���BE���M�����������}G�����:�n?����p����Z���G�e������iUsx(8���M9K��TJ��(
)7����
�������'k��pK��=0�O8n��XGx2��N��[�ql8Q*�����w�|d�w>�5�k,9�v�%��;k�����H���L]}��@���v^��(0p ����5�������)�m��DB7~��!u?��u���Y���#���p 
�M�W�r�����L0�#8Yj]��.��
�u�QU2�Eq�1�������7��1T����g`�.��:�����
� f-���`UWpPa�j���B�T��^.Y?J�3]�I��NXr�'��7�6��-W���a�o��
\K7O���������o$�����\L��u`r(c�4����y`�a�������]y�;r�!�y��������~����G�:������3����9y��>�	I������0\�������a#���������[�~{j'[|����hP�8�����0;^�A�a��������F�Y�_<Ewx,�X���3xg8���|���x�H�U���|�0�e:�r���{�I<�5S���V���A)��#D�QI���ec�2�'���s���l�1�.�����g�R�^�V�[�5~�)'[?��g|��\�)GsG���M�-�5�	�3����A�20��?T�.�m+lq��ZY���?�3��esx�\9s��c�v�4������Fv����/�}	z�-@�
8}�w�����4����u���� �,<�5��N���L7��5��V���s�.�&�M�'��;�*0�����e�e������?��]��H�����]�@x������Qxw8>	����:�'��M���?`���Cr�~[��|�7xe?t�7< b7�����}�������������	;�~Y	��[U��!�{�
U4��������,t+�u�G���Z�}���=!�*�9���Y���	�kBY��6�]{KW��V`)�`M���0�X��X6e;�qf�h��������,	�L�>I
!�EJ��V���m�#/���#@�>dS��7��.&���<��s����+��,���	��q���x��
Z�������$��&n�}�C��,�7����x����R������vS��:�_����:�5������c���c�Y�i)={`����������w��?D��xj��~������~'�g;<�s2+v8�y�){;��+�����T�w�H��H8}�����U�j
%9x_�}����EWXX��C5�1�:�6C��0�<>j[?��q�`?�������!�,?��[���x���f�V�~��%���R
K�3���`?��zW�<����v���C�=�ws2�pq�
n�o��M�t�u=-�����-�m�|�� 0���h�Y�8��
p�Z��6�4���a�E�V-}�cex����@�C��0l[�F��g3|}<�����d]SO8���u����S	�t��
P������B
0*��g�����Vm�jm`@������	K`��5B����7���?�\���`l��*��9���Xfb�U�"�\�O���,Ir�F����{���`���^k����&�k�M2/s��S0KbP!�%�A+}`0�)�������b���8�\�'���?S�}�^����F�p�w������+�4��6���g��)�x4�:���E���V
4�s5V���	g9::�n���k����QM)(Mo�h;�����\9f��o���e���-������T�����S���"xO����W'd�#Ts�_@�5�@��4�7����W
�
?/�a� �9<Y.�l�8d�A6uh�~��*�R���+AK2�������xh!6!��\�U�9�/�2!��s��N����
����bN
��YZ�9a��>5}�����pl�����B�	�3����KZ���K�A,�Q��r;�j<�������4���~�>V���P�!���05�AN����d�NK��~���e���L#,}�������/x���S����/@�;t*�q?����a�.��4��)fK7qmP��G��u���t���U�q��m%(u�
�[�e��e<�{�s�PZ
!�%�A+m�0������v�d�q�l���3}e@�MBr*��
a�l�U3&�	q*������x��Ms�R�����u��Z��xG�8NO�����4{}>�j�b��rin?���*=�����Hb<\�m*�P��HJ�f��"�^�.�w�O�A���W7I�����Q@��h= ��\���3v����&��>�Y����@��BL"�9�7�.�+����������pod�Xxe�
U�����E��Z����jI��I0�+����	5\@g�_�us���3��z ���Q��s=�����1�gn6'���*�
��R�O&���A�`X�3��~���1@�:����0�+X�<�
�%���b������0�=��vm���OF���������9���dM����'?o�s"�:��M�\�!�"O����^�k�;���t�{{<�'lhG7�z������S�U�����O��(�x��hmZR������N
������Txv-��T�^����Y�H�{gH�M�Y����j����{^�dj���9%S�!�������2�����h]?]�>�h3t��WG{�ka���qVtP����f1w��>?����p�UK��$�l���B/w��d0�d-���}���cQf ���fV!�&�������\�qL��z���`��6U�.�Y��W�=���v�3j��H���e��,�`�9h�FV�$^�����Tl��dL�=��j�>�r�R��rYZf�@�B!D�I�lh��1>6�Z����}�r�jh�������p��w�[e3�x�C��������-P<
vN}����(0G�����
�ri�A��5)���9��d��k�
w�r���l�A	!����kh���,�io5���^E��OY����#D�s7�L�
��I��B������U�s���;Y���g�����8y"����,�O&��?�$���`��)[��%|�0��
�$��|������*���n���
�!�/�%�a����j,�%ew���J4���Z�_����-�������e��Kp �����p5�����W�BY��EE��]��5K�F��<�^Fq��^p���tnT���ch�/6�ix�?<��l��6����Y�pn��iC��s4�t%c9�j]��*��[z�wa�5k�iq+��+iMm��nJ�r���[��5���������x�e^.�B�������]�_��H��x�h����?�xQu\UKUS�:���w�����y��8$_���=�:n���������'�����p��^�n����%�*H<�(��!����}e0������J9�]C)�!~����
�p�K~Z�������zTnl`��O�l����6�����������:q�R���xC��mb���tu'!b+[~�#x~C�8�<�T�y���k�Wg{��o�@$Y��k��	2��.����u���LA�	j(���n��l_�K�����\���=���������/������,�}'T-�)J�?�
[Ndl��q��`P��a�',k-���� �4�0����ZBH�'/�Ix����z���Q��
�nA�p~w�)
,�;s�J����d��'!N �!���s;���5���+��X����� IDATE�6�h\��l�����K�n���n��3����%XrY�E����}������-��6������nz����*�_��$];�5.������`�~X}< "v�@��2
�k
���QfPS �*D����,����n��0(�������9�Ac��W�a_�V�2��H��0����c�\��s�����F��(�
�����	G���
�l��L9��,��lGq�w)�/�}}s,'IA!���Hr
��uq[��������
���R:�M��ch���}���%�0�Izo<��w��t98z*
_�����HL���3�E����<
��&�����q�`&�q�����)P<���i��0?�^L������x�5y�K�ir����l�!&��Tzt,�����L��r:>���=���N��c�������Z���B5��$�a��1������k�}&��{a��;�bs|���|�Q�Y��~�[�O�b���|(8?�=�X��>�`����gyifPQ��(��Hx92�2}l��{���P��J���N��
�bi�a|�����b@�U��w��6�7xg|���������2f��F������C���tK�V2L�������	L���������N0�gx�(��
����=�F�����yK���a[��������V���z�����-p.S�����5xe����C�f�-��Tm
�$���0�ukA�r����gU��7������������IWa�/��3����l�o5�![���5�[G`�V��.n��-�ib3^��=
�;a�NX�^�����R`pw����p��
����{�8!$x������B!D�����\�m������W���lB�s-���<Z���@�W�,e�������DC�K�l��H:C�s�Z�D��N����*+��p��F,?�</�|
���?�0����_#��O���~�0wc�V������p
?_�0��Y�Dh�	q�)��2?y�0��^/��!n���?�w�Z&�"~�������-"����J�K;����7�1����C+L��j�5��X
*�+L�@�%���$�B<H4{���1���Dan�\�x���
AZ
!�B���Sw��"r�!��N��B!��ddN�HB��$�B�'����z�}q1)�+a}MNAE��+�*S2�B���^d�k;r�*�pJ��y_
!�#Z��|i�`�D�B!D���`I������4.�8��o�Qt�4~w���B!�B�'���B!�B!�B�G[���f*0�;���s������r~�\�_\���*'�F]}��v~�_�`_\��#F��~�F��R�$wF���?k�yk�yn_�U����q����yV1!�B!�(����,�����:\XJJJJ�CAo��������G!�B!�BQB���`��o�|�.�c��B���w�@��=�\?���;�����D��+P|��D:��hp'2�cj���SnF�g1GVp�1�S��^(����L@9��-�hW��}�����pi�T�1��)�0�{�)q��!v��w.��^�����������B!���,e���2,���H�zr��y2> �P!��$!���]6<9��k�u�������]�2���NZ1��R�c�+�!�f�s������@�>�8�*�p���U3"&�����q����YD
�|�!���K��9���q�)q��2��B!�B�.��~����q���\�'��D!�B!�B��(I
!�B!�B�%����F����r�\g{�Q*�����Ws�\��	!��E��9�����3 i3k���-�>����W�_����a��'����F�>���R�(�T����z�;RJ:��M<ma���U�U;�����Wo�K�������lA��r������kW��,���0f�?�D!�B���bs�?�|��e_p�cS��B)�x�%�|��Es8���B�f��&����s4~�����A������
kW�%�z>5��������X��c!'�Q��\r8k��a�R��Zxe_&�|w	�	(\B!�B�"%�A!�(qZ�*������>�e��'����]C@_��(���������Ih��7�
M�AL�X������!�B!�rY~O7�~���s1�.��>�;�~� �x���1�{5�f|��#Q����=C�Q�p�q?���tN$Y��������)�
�p�K��	,_����2T|�iz�k���UK9�[�_������N�P�5��������k�T�U�?Lf���t_���K9��*&g?jN�A���(E�-!�V7����������>�_�D��kcPR8�JK����m���$s��Z��9���<�c�ZV��DZ��C��8@���U�y���3@��G|����c(�$������7�k��l��gn%�������?����4q)����#��������+
)A�g��K�q�ep�6���o�G3��
f���7�����g�g$�"�[���f0���#�_�|�
���;A�k��.�q�#aj����
B>�v��������m�o����'a��������4�Vm�CC�Av�~"|�>�
�B��0�yx,�{�p��`�l��^0�q0e�'��P!�B��8IZ���d��mA�N���E.n=KL�
�$Z���,������maM�~f����v\��'��8�����t3]���79�rCF���q�,p�2����f���s�`��f����W�����hQI>{�h�������z�n%b�8�u��~{��~�`���c�m�<>���z�zv�&s�lK�"���i<�F~���o���/w�}��1�Ht�B��>���+���[�Y~�;��m3��`�g��O����#uC��i��7iY�x�D��f���T|�}B�ra�Lv��������>�	I����0\X���g��F�=[Y�s�AM��������z�W�w���G��<�
�?��`�0kb��)���6�aAM�3_�O�qK�u�<���^�jNpz�<�V-X���p�%X�<�F��F����k�ow���vC��Y�wn�!�<1ZN��+Y���������>
�g�H�msa��0x$t.;��7_����'`��Sa�yx�5�c�E�`O*t��*?�P!�B!��4��N���#c�P��U��0Gq��o��>�g>F@}��������<l$�:{�����.�z�����
���D��GP�_����?��_n������Sp�>��1����H�l<L��m�+��*`��h���C�Y�Z�@����EA��������f
�S���z�%�/\Gt�����Yq�)�L������W���3@q%��P~������|A�Q�pp�/(=���+=qP�J�����i���rh�b�j���/����%^�GY��.���w}}��
6f\��eX����-�/����A]`���3X��o��5P�	X0��M������a���e|�5��,��jY�Ed*x�8���zp���k`�q������*8B��f�{�`���NW/�+���'��
�n���e|N�
K�@��`bO�~�����-���`����Mx��%����fFz=�=�B!�Bi4�Fh�=e;�X�������i������#�n�����B�g��8_=��Q���87��6}�~���4���\�a�V�E��3�O[=���]�\�'+���t;�Ds)���*���iiU
�P�|I=��#)x�j�{����M�6��Gr��f���~�?q`sL�Y��O�1�>�P�U�{�(�M1��i���������^���:<�7���!��!����b|es{��MRM�^�����Pf<��~�1��]��$����&\=	Qf�{Y&?i��q��B�|�_9�����z��#�t�E�yg��"2MQl���&hZ7�
E��f���IH���i��c�Y�m�;_�P!�B�w�{���0`��-�~����e{>E���)���X�L\��$Sf����1�UH�U�\��K�8;c�I�j����WI���z��o���M�h��kt���Ag���/��U���s��_7�<��S�P�|1��7���.(�wHJ��]C�<�����Z�x��;$��=\�sN�;�n����$$�ryb;�L��J5cRk������(z/hZ?�	It�Gu��O��>��u'�Sa�P�e�\5�q@93D���{�����t9�X�W\�jBwX���Yn����S�`�� ��eL���`R�������|����	!�B��#��{���=���Gb�s�k������	aa>(N.8��0��G�NWU�p(�F�j|<If���0��!Eq��E����x�
��G�����@�LI�j)��RP�Y�4����q���bl[1�I��C���`M�(M��T*��,3�����������Il�#E��A��t7'�g�z����'w���}G�n��@1�h,���(��[��#��
|�>ty�^'����� �g%H��tw��h�D��os<�	��lk���c�P��;���$Q5N�S�n`=>j"$��n]%��P!�B!����q*�q�jU6w��%`������S�p��w���J93����Cjb�?���F��������$��U��R��Lj�������#�����6��~�C%�-!
BD�Zzn������Rj�w�D�U��z
�p�&w������������������i4���S��>��vZ���������'�'iM8��6S�����XO��k8�ls���v�Qr�����0���N���-]f���N���������E�����}�sl��M��eVg�/19�����q��J�2��ka�A��!����9�lI��W�������K<�m��|C!�B!�����3�zOyj���w
�;W��w��`��j|��bO���2��4�Z��[�:v�SG+�����M;��2�Tu$f�w��@�����e
�/Qs�_�,�����G����)�RW*�M5*7��q�"C`��o��X��XE�_�T��z��:�V,J��M�����ok�:���/	[?b�6G��������E������z�������9|3������31�/��CN�1������}�mk��X#�����F��L�'[������S��
R9?�=�F��?4����0��z�evch�����uh�W���E��������awhW����l�����z��4��7��@�c�!��n(t	��[p� ����-u7����/������#���>0�a��pj?��g/��{w@�����[>wH��� H�
���%�e"����c�i} �6ci���������������@�q������0�B���/a�����'M����P'�|�lR��=�B!�B�4�P0���&v����hc
jL�B�v��J�g�2O~��-?<u�$�;�j��+�z����s4|i1��Jb
���b��zJS���>����r[-C�'��������7��y��//`e��0��Q��PB{��3��_�\InK��Sp}������i���:���x�B�������z��cN���N�~%������/l��\�#����p�6��Lb2��X���Zd������Tyc'�5��O<���a��W�0�);<(��i��=�>��
-_g�7>�4%�\$I��G�&
 �������q��>����������6_����)3��<���&#a�����
zw�
����1�)����O��p�k��v�$�����K�c�D@O~o���%��A���5���00���S�'3�^c?�AO@
0lL��M��
S�[��@�`�>X��|ux{&��J_��k5F��DW�����X}~��B!�%%%%�^o[�n%444�"��p�
Bk��|xran�,�X��{��*�u#bw��"_����I���|�%J_�ya�]�|�0�G����8��)��
.<ja��\�D�����d�Ax����,�z)��8�.���Vxr,aN�J;��^���	3x�{<��b)Fs�y;�"b��vB!�B���-Lv��[+�Jan�
\����B� c
!�B!�B�%�A!�B!�B!��d����z�}o|���\zr���p��Tt��H��7�,�B!�B!���}GEq���VzEEl�w,{�hlh�1�$�7S�����4�%�&����(����+�*Hg�|,�������>�p��;��3;w����i��tUh0n4
J:���7�,�B!�B!"���B!�B!��G����EY� D�w��
Y��������<J�J�"���������Xj��pnK�&��CpH��h���&D�Z�!�+�h%B��U1!�B!�(��T������j��d*d29���%::�n�#�B!�B!��K�X����^-R���2�y�����M���h"@)�PYQ��27)>Q����	�Tv,m��B{����������F���sw)��p�/!�[�O��2p9\��x�vB�����O�"$�;Qn�X��TIz7ao[R�a!�B!���N�&������u�tK���I���85�Qn�y�������^��q&�2\���t�I9�5t86Q:L��sx����MD�6��������o���u�RD7�[cPQ�Q�:�M��j�N����
��_B!�B!��w�y�����}eA!�B!�B!�Q�8(�B!�B!�=��+�Y��bb��y�U����,gY��}Vl�0���J:!�A����"���49������������h�(]�~��S��
T�6+|=~I��%��{�]������a��|����,_�,M���2x�qh]�����`7����V���s�`����F�>��>�Tc1�u�Y`�&��N�  �DA����B!��4��AQ�h��p�;��2�t$B�-�#��.T@=��%����hP��M@��
R��"����6�G	���@���'���`P���
en-K��>�����6C��7�U�C+�j�cG������Yw���0f4m1��o�x�����M!�B����AQ�hq�+��8(�U
��"�������	b����i$5����(��J���
�!���0�,����q�*��o/&/_h

���=����Ay�Yq�uWd���P��\@�2ph&�>u"l�*�B!D)U]J�u�|�q?��U��v�2���iK�����@�L���L{6;a-7�&��cp(#z�nHN7��?-�5��bmv+��DE���6�e�����$,��?��N���V��%�\�u>�?����3��P��>t�Q�����L�\���.�����K2����?j���!\������G-tYzg�,f���X��Rc�H���B)���(>FO`��:t������r.��_������]]1qa������,����\:��s�5���c�����N�������J��5,{{#w\��]�������JR������l(���f�M������p5��)���*l�
������^z����@��3�C�	��B�?�m�:�����B��}R���<W�k]T�l�!����Fo����z-������
��OW�A�
�4`��n*�����O@V����y;,�����*��xt?L��/�+���>��s��=L��T��������n- &�������m
��2P��SD�����}+|Q������7���eep!�BQ2�1�*�9R�G����\�j�S[���HL���+^T�� �\$��������y�7	���yW
�,���}����<����A������r�l#:M}�>�*r��o���y��S �����1r�Q]�7���*��+~�-o<��k�x8�+�����0���N���x��?�'X�t�����+�|���F���%D1����������%��y�����Rr��J��?���f�o� IDATV�[����ADw���N��9�i������'�z�/f�'h�r����)'{�2�����e������y�?�������H�����s
�|��F�u
�H�m[�V;��
�6��������ou��~0s!�~9�k
|0�B���ag��������]p"&���j�*V���^��8f���1�.a0}�������f��7��&H���aM:4��]\eY.C����~]��`d(,�gr>���2��d4����`�|X�������T~~�������"=.�v;(��Wl��y��L����w����h�Q!�B!�<�9x�.�����f�����o@x=7v��#,PI�k�>��a�O���v�����1���Y���l�+���M��=�����������H���'~hOY=@U|RN2������ G&SS���R��J���)�Z��y����MR�6x_m�5V���������~�8��I�2������%����yp[������q������������M��l�	,C#��i��z;����Q#[�k��{<��NR�x���1�J���]g�j�9Ss�W��&�s�z#����r�Ae|��f��M�z������}�s_�m����H[o��:s�����������|$[Sa�ko�����i`�n[�5�w�W����,�U�nE�j-�����pp��5���s����u��`r.x���?=X�m
zn���QpY����r��B�f�Thn��U��,t����� �*Tw��V�+j!�%D��S�<�kOA�*������*�D�����}��)�g����}�U�Ej
���9kt��r+��%B!��dI��U���f#���g��s6�W;Od�c�G�~�.���lQQ��f�dZ�p�a�����_qz�����"���CAV<��X	x�>��#4�iT	���9�����D����c����x]-Wq'�y���9g������@�^��]q���sR:&t��=}E���}�3��(K�b�	���+N���0_��+�s��m���P�:�JpK���lu�t�3��_�j@�
%��&�q0��6[x)2o=h����8sA%����5�Px����xx��i�g��<�!
`@�������
�+�}Jk�f�8I*�;N�KEh�o�j�-
�����#xj!%��k���x������0m|�	/��xE.
X��1��O���2r�d]���S��
����v�����x��N����/������3`��-�d�B!�(=�q�E4@�\���Z5�C�|���>4~'�Nu�0����9���Vl������R�(�>\I����i�SS����p���x��}T+�WTp����If*=��6*=�Q�3��������yFE�V�J��O��]q-s�>w�,!�S�uE��ok�)`�t����eD��"+��,�-������8���{]�i�ddY9��D�c��j������4���\�v��?a�^�����VU���<#L��#L�����/��*�d��s�F�[�9_&����wO�,o+�V������o%�T���b+C��~��\��p�f����Zx<��@k�����|������f��jE�
��&�w����z��	<��!�B��Ce:���W|�Y���y����5����r4��1�y�fj���e$����P�\p�k	y�y�t4��Q�K���&4N8�AVr��F���T�;��Y�@���7�����Q�w����;d%g�mT�J�B5�a4��q����t*�}B�&���*��8����]:��������0�,������Ew�y���@���}��!�~�6��(�F����������)+T��b9c��p`o����h�u+Aj&y���	��Y���er������'C�"3>!�B�RE�<u���9[��e� ��7e_������mx]����O~f����
c!��$��[e|����b���
��)_C����I���AM!a���st�������%Dq��Q>R������\	���D���s����g��I�YN�����DH
��Sp/�oU��po�����A�M��{318`�y_V��{�
^(I�<k
|����P�<|�3gu^@��5��A�P��+�#��z
�*�	�%3_�%��km�eYn��������#mo�,{V�7�F�����t}�S�����j��!��mB]Y����	�+(�/�?W�FP���!�BQ�H�AG���X���+�o���N�����K�2��rO���	�~n�;�o�����l�=��4�\g�.�>���ei�}[�yWw�=��U�2�e'Zv�"c�rV���u��9�nFSL�{Y��n0�?Iq���uX�o%s_0���'��b�������s��z�2k_[����hv���V�'Q��n��Z�4as���0��I���S���w��nZ��J���,q���!��a�SG	�P�'��cC	�p��(^�W`����1�4�
KV�6/����l3x|
�
�|@�Cj���o-��)
���#��F�|�5�B�0~>��p�$�t��j�����D��1l�H�@�
�t�(@R
d�`����K�gu�9���-�q�`��	����ww�����a�1P�p�4�zkC����*��j�`�6h����:H-���y�p<X���Y�pD�{l�^5a�v�Q����w��+���B!�B3it���:c���\f�Y����v&��l,d?C M?n��K���H�����Iw���`���,�u�,�������������/�,�h>�N�BL��D��,��H��S�e���(m���1�k=K�-��)Y�*1q8�}�s�X�!}��7���{6�a�3l�����Csg�{X��2Yz7�k>8����(i����y��*�O����9
��Ah��P9�b�Ao���Z�`�����zg
���}�5��z��~Y�U(���������0�bn��
��O�w��L��4Xk�C���9`��;��vF=��q����m�!{���+��{`;���6���'�k���'���*��
FE�Gk`�?��A�����#�.�>�m��v��v��h��0e;��
����VPO��!�B��O1�L��?���%::���=�*QN5N?5�1n��l�K=KlX�&~J�1����L�����N"J��p\����G�[O��^����w8���z1��>����ELG�����+�]�������Q�W���5�C�����zFG�q�����+�hJ�w����%%���,0�����d,B!�����`Lh���&���n�ni_�3W!�B!�B�{�4
!�B!�Bq��9K�	��^���B��+Pol�]��x�B��F�=\�A!�BqGI�`i���'ChP�q\U��B!�B!��F�!�B!�Bq��c=��R1@���U0���m�X��QQ/0[v�.
�:��P�Fr�BH�|"�I.�%���/��B4�%B�W��	!�B!�]q�U��O���-���L&�����DGG�rB!�B!�B�����l{`H�����8C����7��uw(�x�(!�B�D��\��DB��%�u�36�+���7'��x/�REu%�(&�Y�����^�7"�������
���2�����%�B!���,-�6J@�d��-�wG$�roT|y�vlo��Q�r�55�(Q�t��(SI$�5��������D�7,<���D�_����R��V����dj�y��o|_�2T����.q��K:!�B!�Dq�_����}eA!�B!�B!�Q�8(�B!�B!�=��+�����z����:���_��T�a��
'����I���{E�n�����!����i+�����h||(W�&���E�H��)3�o~	���/����s2ZN������i@��aFOkv�:z;e��>���|�}��0���N�������s,�e�����#iJ-���w�������~pW�w+�������G�1!E�2{T�	���85�o����#��{!rdW���BPa����v����Y:&������[�D!�B�{�4����i8{:��Lz�Q��t<���#�V�Z�ow�Q����x�;����_1��3��������9�����w�DQ�D�����Q=n!w�
���V��C��u�:z;e���<������\0G������5���z������4��G�8�'������@�nP#���3=!B����{}�F��\_�T��W��q���x��O����B!��J�y:���p�����%��/R�e	�\��w��`~�l�vC�g�vd�����=�3�L��4�#��g���H���N����U��Swqd���v��[��#'�z��jq�/g���j ��IS��@��w��`A�Z�[����&���VJ}8,���B<a�6x���"�B!D) �_��sf�,�h-g/�R~�0"�����CxvAw<4f^����xr��hL���^�s;��XI]3�eo/���D,���?:�N�j�f7��y���}�L���8��vl:��-��?�[��������8��Z�����|�t>�N�[[G�?�9��������;�������'��'��jC<��|h����rpS<���C"��(�b�����Jxi(�6��{��l�b=������0�'����h����7�q�@D�c:������w0��
�^a���0gob�!��J��e,�pw]��H���tY-�uA�Y�~:�5��q����0�?����+bP�I���^�n~Z�y��:V�y�$�>i��
8��|vlI���G�1���������3I0���������������O�|��18����������������&1����T��
��O������t��m���������N�H\MC��@�kfMg��5O�@N�g��!&�}a��;~k~�i�*U��SCi?(��t��,��
������������������#�\��_c7��+���������g^��Ka�a8�BhEx��/�`@xs<l�=���=�l��a\=����k��0���|���l��� +�����D
>�������;`G[�W���&��>��� 0Ft�A��~ ��g�`�A�v����9>�C!�B!�q��1*K���6���f�$"y6��H-rN��0��T��kO�������\��
fs��9�0f���c����}C�)kPQ|�R;ZG��kI�������\@Kj5/��h�-�����A{���/�X&�������T�"��1�>|�{���|Ix�����};�u�6jL��f��O�`�,��b��������t2��}��m���M't�g�/,�w��e��x�;M?���0�[�1}�o�iF�o����!\��sfO9�{]X/�c�8fO�D�#C��:
)O��C�Y�?��������>��T�������Q+�t����3�e���Y)���O`�������}$��r�i���<��H:�&��O��{r�zs37/�Q�����zjV7����V)���������b$��ka�D�.��r Q�X�3F���z �f�Lt7�?j����{����x�UfO�@��#0g4�
"i�>��p�X�����+�6�"z���]s��.�E��q���A`�2�|��w1�t�rL�`WN���'�����A0����7x����H5X�2L�����Wr_/�6��zR`��{$�{6>�:>��[^���y�zW��0�X�;��ZF������L��)�i~���������a�����7+G��B!�Bz�&��_�7y�����KU�p��K�S�|������Cybz����s�0�&-����d?������O�<����rEs^���)��+�{���0e�o	x�|��"����6���-��R�q�
]��)�8��C�w�
Pp�9��=�6���ng���S�V����z4�5~�_?�7��e�`�4�b+,�-�CQ���1���<�t��2jfn
h��O�v����Q�)G_��/��n��e����W���'���s]D��r�IS��������e��S��������V��G1���(G�1�92|.K�le�W9�7�K�a�����6%��e]cI�s��t~��V^��k��n� ��B�}
�]�����f��v?��%1�l�x������>a^�_Lg��Z,j���'*8ZJ��s�������)�EYV����-	w���S����R�=H��h�h��J�{g��kH��
o
X6�g�b
5g�M��n���U]"�[r��;��?���#�7�ld��V�9���������a��P7���&�'� �=|�3<�2�����ahg�����2�{:�����0�Z�����ul��k	�����0 gq�*!����*�`K�������.Kq��5����FX���4���������Ey�7~��Z�zf�������x"-�dvn>��C!�B!�4`���n3�#mC\�\W���"����c�����kZ�4��������T���J_������eh�������i>��#�=G+�/��s�k��	��8��ru*���0g�U��88�/�{&La���\8���lE5�Q�'�iC�y��T��k�>�+�>:�I)�T�)���s(�<k�m�<����?���J-����v�{,���v���!���YG9��B�����
eV�mbg.���\�p�+n5�l���^):���
u:0hm}�/����qx�
-^��q���@?4�e��.��m���������l.����[��XP����[�����Mf��0�E�WL�k���q����-�����E
������f�����������^W���Ip����s��F+�����{"�����wn~I���]����^e���0�,����m�)��������k��@�`[o�DT�x��@�|-��[�h*�������AR����N��f���tX��w����@�J�
��4��OO�����!����
�����sXB��!�BQ�H� �5��0z�?`�1z���jZ
�N����k���F���4���q��&�{��uvG>@���$��H��[�H���Z���lDK"�)��C���^b�B��
���b�Y89�E�8m��CI���x�V��in���O1x���������Q�[(�����K��z��iiddY8����7�n�������_%#)��q�I5Q\|	����^h�q�
�����X��{�`�����p���F5�Co|��e�4~�Q:�����r��	�q�R�a�E���w�}v�*���^Hq�>ZI���E%�����2QkT#���#+�6+�y,��{���=[����b� +0�d\No\��'�����3M���`�Q�Z�{���C��~�mW�@yH�iL�o��YY�/���+0T��n0{/����f����?!
x!;2��,�^�vI��~�n���4
!�B�8h��`t��+��������7�&�X=kv�G���z!/F�N�����Kp�Gc
�
�Mt>��2��b����H$�����P�FM��@��dnNN��3Nnf`���?.������Q#�s����Xt�r��zv#�?:L��H��G��8�����Wqu���%�����>��zE�KE
`���.���ws���\����X��y��UB*+�F�[�����$���_�}��9u+�s��[���������
�z��K�b\(DM���cX��YVo��^�������n��U �3N���d�V�JNG�{b4(8{���+��)}�vg��G	��>�:>9�;��`����>_�NE9�;^�p9��PV�������t������h���l�����,0���u�o��k ���\���9B!�B������)�#i���@����d�����
.%�~5��$��-��T��:�_��JE|������R��{�m�]�4;^���5�������Gw�p����>j� IDATdrr�������3���\�BF����&��
F/��mi�9�)��{6�9���leG*v����_7�/��h�y�X����$L�-,��v_a���4x7�#u7�W���6-9�W��O��[����������8)�U\�m�lR0z�5����������������R����l����[�rVX/j�no��=���9����C~@���a�v���?"��.�r,���Q>R��u{H����L���(����z=4��#e�cS�����mZ,��c:����}�?���3�7�I��n���N��sV�Ap�\��rP��+�;�G��B�AX��7��\m�f���2�[:�zU�@�	Xp1w��"���h��*j*�;l��N�>��_�8dw��C!�B!�������d����{���Q�\�1�]�4(��&���4�W�iN|:��8u*���p5IYj����=&0�8�&]�p����]�8�+�vS��W�3�
"����zi���S���=�+�A�=�N���x`	�N��[�	���&���\���!��tE_.�CU*5��d�\��=HE���y�{�%��y����RA��@������4���J'+�gNg�:?Z���rN:|��f_�_��}1O������6l0���4��s�.�=��=~����������F~�	����p!��>vl*C����V/�m���oL�����V��e�&��s� ������Q�}���*��`RU���$�0�b�5��>�J
u,��O���P��{��f�MuK��0t��X�sy�WwA_6���(�������3h��qC\N��|N���e�n�=6m�JBfjhIH��duj���8�:��������I8�Y�X5-(�~S�`��.$��I�GZ�j����L�.>d�����NT����y����:z5��x��=��t%��.v��!zR��`����_���,xf��"	p���~
�#��`vD�%X�+�'��
m+��f��u���8ialG����#�@������`l��)��=>�u�|�
�C�m��8�
"�����	�6�
��L8�h[Ey�.H�Bh�pt�.&A:��j�A�2���"	t���O�	U��tD�W�^����������! �<
�1+�u#t����`�����/��0�2�������h\�k�u�
!�B!�Oc��#0�~�3�v#���}���sS��
��3	,x�1>~)���a4���?Sr��>��yeX��,�y�,������G���)x�k���}��z�-q�:�h��0
��+?BF�N��uUp�7�n[>d�+��#���C���}h5����U.�����_�xU t����ZL�)�s(J�+{����y����y�hd������>�:M��nI���tyu+��3�u�^�e�c�>����V�hx"Yzw��U!�x�u�����^F?q.k���m�8�T��c
p�������ml��/R���W ����L�k��9T�Me���W����������5�X��{GR���:�������h	/?B�At��Yp8~
n=�m�w,}k";2T����qh*K%���M������k���}Y��+��S�����E�zy?V45��r�<v�����Q� P�~����,}�]vdXq��>�m7}^ai��a���,?�_�DX����$���PiM9�L~�����K����N��������W��������M�B�&x�<�$T�9����nxgD=:h�~v��a�%���j!��~��o�����R�4.X!�"<^+�M������r���g@�>cB< �0���|�#x0F��!p�������K��v�I�|v}�(���{������0q)�������p����f@?�0�2\�Khv&o���C!�B!��d*t�Tll,���E����!D�7������e�+4���c����Q@�������$���#��cCxvA��U��*���^��w=���ujx�u���g��}�yfI/<��A�S�l&��~I�q���?����4�����.ET��R��V<�^����S��������s�K��2T+��J����D[�f���E!�B�o�������M\�bC��}��`���������]8�K�"7
!�B!�BQ8i,�����3�*xG
���u�u8�B!�B!Dq����Q����Y"e�������/�����8�Y��p}���!��_K��B!�B!Di'���F�*4�l4��\'�B!�B!D���%*�B!�B!���X���Z���J�!Z7�����N8�_ ��LI�P����
1T��qs!���v/�T��_��	!�B!�]q����O�k�-���L�B&����X���o�!�B!�B!D�t�z�����2�\}�$��q�h�eoR�����D)o5��y���-^M&�Px\��S	���K3�3h�%�(&��K���zeG+��G�k����@I�UjD<���7�|B!�B��A���-�wG$�r`���e_���\��tS���ri�P�S���R��c�����7�fJ����D+���Dy�����W\�Y��dX����KD+���(�&w1��%.yCI� �B!��B$B!�B!��%��B!�B!�B�����bq�do����P����=�%��YN���K��a@��j�S	�%�$3'��g��N�FP��w�N�]�����q��f��|�h�zt������Yf���*o�~�'��p5�����;������/J���E�C��O@TW��H��{�m9��nX�+�>��AFOi��>�H�a���������U����z�[��/`��|�50�ax%��Yf���a������Q����R��'	�~[,�Z-�+�[���\��NYwS�^h<�����W�����GFX3<�B�(~V��>�����+T
�m���]�E!�B�v�����3�U+�z����Z��)��Lz�e��t<���h@��=����(���%�vi���,�j�b=���v���h�G�0���ZWj���PT��m�D���}S�_�8���1m>�C��L���l��f2����)��������Q+���7'|�p$MIr�����5xS�����@��P-�m�/����PU�eo1K#���4vYS��8��z����02�f8���
.�FX��u�������a\ �_�M�`�YiB!������C-:��U�Q8@���/N�puQ ���w�b,Op�6T.��.��
��
�-�X��>�EQ��m�oD���n/*��5����-��~��_Y���c(��^�Mkq*���B���)A�2�>�.�,��+Ce`�q����Mo��R_�U�����C�j�m�����r/������(��d����Bs��]�9��2M%�B!�(�����SS���{M��%�7c�Ri����~��&��v��>c���,n��w��c�,n��x�e��,�Bf�b�'�9���>0��O
���P�
�����c���yrqW|�&�?��^�3�pQ�y�)~���vu��������3�n�����\�&,aJ��$d���.�����67�{��l�������@�	-�5���X��0�YC����|��K�!U�x�A�
��n��w��kz=���/������e�=��=�Y�A.VR������qp�y,���{�N#�����^�q�N���ys����H�?�$���c(8�|�$���i[����96~��s�.�uA�q�����,�4�����o�
+����k������w���<����w��d�jW�S�F��l@�i�b?���#��cp$������y��y�k�}�B�m8��dvl9��-��~J��e1;����p��1����j�a��c��|��n�U�v0������s���$_�`�B��]i7�����\����_l���,��+R��tP!�~�#�{?_���q����`�?�����f��t�|�]������4x�+�_f�g�6,t�f�w<���N�ph���3a����($Z�bE
��c'��Z�)���dt����r��\�	@�������������`��7n��z
���cY{���#��
K����`^�\��=��H�y<�
�����$+��������=����ga�q�zC�N02���AxO���g��Sp.<}�s<c7�z����	F�����d��f�Vs�R\�_���s��b�f����n���2e�c+i���xV�
�g�� ��&H0A��0����
B!����*W~��Y%��G�n�p��9��`�N$�����d���q��� ��*+�1����@��>��-�����t��~=�
Rx�b�1�A�<���r�
��9���x@	���M�1goga�7���/��5��c�`{�k�T�6����^(E=�����T�#�\]���
��:2w�#��q�w��~��vE)a5���B��s��	��EF���`�/X4����%}��,^�I���s!{��L8���!t��&��+Y5v4�]�0������z�#G���r��2m���uh#���IZ�pExN�����G^���g1���_���
2p�mh�R�lh�9k=[v}�����7:��8�E4���OTB������6��s��.T��*�G�T�9����������s�w�A��>y����G]$l�h�}�����-����@O�ON!,�6���@�{����{d:s�G�PY4�d=IR�4{�-^>:2��C�{�2��E�uw/������7f���A]�����5+���o�t{�~�r��&���/�}�u��K�j�d���5�H�X�k&�h\���sP�g-�����0`),��= v	��
�Z�4[W����y+�4N��O�'`p��Pk2��6{��n�#�`]�(��c7C�n0�XO-��*C�����`Yu�>�_��[,y��0�Gh� /(���7������a�V�3ZT������2_�^��F�4z��W������P8v|���-�G�v��i�::�
U��������&9�F�P�!��Y��2�����{�t���u����s!�������0,l?���s��
��6(��
�6���R��������#LH����%_�|f��Hp/J<�0�>��`�l�4>�^@�B!�����A�YvL���i�_l��a�,�i�?���
�C����������&����������RF�A��'�'�{'����������
��R�Qg�
����Ws�����}�GQ������{ �z�B��WQ��� "
��
���^,X�&�E��&�C �P��%W���.�.�` ��y�<O���3;;�����T���PG�wC-v����*M�j�����:
V�jS"�>�Q����m��|����W�MMbP��eG�woP�=y�{N����U��lS��e����H��~�./mf��)��i�������t�����5]e��y��e��~�����y���.��������k.kWIT�9�Nm����I}b��K�������-��7u�����G0>�����r�%�	�=�o�#�!�`��A#�t��#�Ar��!;�|���X7i-:����V��^�W'���@u�3���E���m�0���w:zX�O�����8tkY�*��C�W���.A�8Z=��og�����$�;t�W�74*���;�_���K��k�rG�MV�v$���|?n�|t"K�MZ�fx*��{=k�����3tj�d.�F���1����������+|S��-�<w&/�
5��C0xT�DM��V�n	��Z>��Cv2���jk��w3����hi�*6��L%h���j���O��������RAZ�w����� 
��AQ7W�,>��@�?,�SA���zL�qK+-U ��5Qg^�.���3L]�M������{�G�����t�R�����n�j�����@���L0c�(Z��������ua��"!�|v^�*8K.0�9����]F��� D;��������3T/oV�)��7a�q����,NS�Z����#ZB�
����0�4*��4AA�_6�.�|*G����MD%e�2u$���o~f1���a#�OT���k����!�SOs��%x�UDF�v�i	�ja(�'q)]&����5��P|������
CZzT%=��������[����h@j���������{�g��	Ka7���4������v����1���q��/��}c��zUp�z������m/.������}J*e�{�)������^ji�vS��W��e�S<�P�6 ��Q��p�{�C��f��}\����`2���i7�	U4�-��?����("B	t��T
B��.e�yI�{�C�/g��S\����o#R���m���\<b��{y����
�??g��H�~��h�4s*Rgw���-�5���u��
t)�oWX��9�����}���>#�lu���]�k2���+	\���#6�wQ�!`����O%d������]�z3x%�� I�I�r
��
���<�y;��%0jAa�]��|����u)0}5�<Wt`��h���`�0?a��RX��
�Y!Cg	�u�n^�}dX��Y����J �`���($e�^�	T��,�����
�A8a�x���c`�a�p6��qa��0��eH�i����!��f]�����D%�t��\nZ�^AAx ��  ���g��c�3�����-��$���yM�����������)?�<��[���MBr��$]P��j��F	�ed����u��N�����4x�Y�W�B�2q����#�x����M�x�����[�AB�������N-���>S�� 7���I�y����&�T 74���	��8����j����d�7u��	m��G�Z��3�r>�A29�o�b��@��6����U9?ed�mB��sq]��p�R����8jP��.��q����������}Uws��6�?.�r�6Y��nV�@"�uw@����hdr�r���t�L�+�����$Joh�NC|U��.6;�M��g`=b]6����`���K��\]��H���q���V�9����=
����1P�T���4�
y���9�)�`����^�	��@i�/��+E�Z�� ����l
����P/�0��Vu��k
,Yo]�am��?8H�qL�mm�
�I:������
hT����>�f��!� J�����rH�\��(m��$�,>�AA"8HNNhU��������9��*vT�����%\ /=�j�L^z.����9AR�<�����u9=�<e�%-Cz6�i��������<��shy:����M���O:.��K���"'�f����E�g���'��4Gl$gW5*"F��c'�7J������RS��z>~Ho��V'��`����_#��/i�D��M�r��+fg���S��sw���"��hpp�9�2��#h�xA��<.�A�VX����'���CV���H8z8BZ���3����g��?�X�����j%<�44/����2���
J�0�&���p�T���;0���Y��`�Z��/L�����c����h{[��=�T���'��.�lUK0R����M:K�EK�0C���Ar�����
�!�Q
pu�!�2��(Yg~AA����	�FP�L��c�,���i'8{�P���B�U���i�>9�3��#U��_��QgH� �`C2�O������\,x����S��#�w��^}�)�s��/�-�e�[4&*0������+�8'w��x.3$�g�O�9v$���w�O�c���q�H����G�Z������<�kc���"��5\���e�S>'5���5p����u��w�=��gJ5t�w�S>����*�����;u%;^i�N�$%r�R��9����`�=�di���=�Ns�}1y��8k -����=�(�	��$u{���8�3�.!U
���x�+�[�1��s���)
&,��8��T�ol3�4F�f� IDAT!P]'3!��Y�DzZz$*�vd��M���7��XN�9�|�\���y>�{��5���"�u}�9{�	�M�z���~�uMM�/��ca/E9�\��x�d�]p�e�s��
J���i7O�z��N�=�#�5
V�/R.+G� ?� � �C�!�[s)��P�Mcf��S%�(���bNK��"�3��������4m�E�����^K��Y��R���".og��fx�;���<�&�X�p�i6?7�QU�_��_sy�)�*��k����Ao�M��B�Y
HZ�C�����s�+�7%�~�_������:��
& �I]�r����y9I-��p�Co�����9�d��.g����C��r�j�U^��G����ek��v�I`��x9�H�3�U�Ci��~j|&
�H��Y<�.	��C������x�=~�&��]���~h/�������W����4o���_|���������m�#~Zw<2�c;9u"��s���I���C�*4�����n��j2��.��#C~*zYF�v��sZ������O��_'�W.`o�#a>j��x�jo��
�X����b�\��s<��w������XZ��I:���Kqx6����^�#��z�{�"�r�T�����f�sH���K9�Q��~
���Z��us�������P�}o���BL�Z���oki�A�����QC�'5o�C�����-w���3P_hNl�#�I'�����)�K���
��������
gx,L����s���l=W��Q�Uw��l}�4��u���h�����=k6��}��p�1�v�3��7�X2�L�D���v�L%�GB����d���2������4��2/h�p��
�ia�vh�o��c5Y(\�5��p���
������u�V��-�����U�Q�E�.��U�tH��u�BM�u��#�]������p �e��l/.�k4�,5���c�X7���}�-� X�����b-��
CCa�\�Z�c��q^�)���$�AAf"8���S����7,��?~�E���4����ZU	�%[
��gVL��o?�PE����w��qU�ntq�%c�3�u_"�>A�6��3��h��h��4?���/����3A���y}q4��[�p�S��z�<�"U�z�+�s�'��i���O�����'�/����q���*J�5�����?3��R�D>���?��D	3#<82v�������������-b��{�ya&
c�����t����������4V����������l^2y<c�Q�WG�
F�)������Ng�����j�1�21�Z��0���4~���������A"
<����	������KO0��p����:�����V�����c���W��Dtzp�/L�e_Z
_j|�6��|��z?c�#����w�V�6QZ��S2U����y����C��y����p����\{u1s����Kd�x�������G�p����{~a�����q�3��+Z�����pl����Y��2~���*(��w���j��'5>{��K�8�W�\5�N���:s2aL�RG���A�>N�a�Xzy��a�a�p4�*��f��g���T�8C�p�^�����>���[h^�",�Y��a�2�~�0��P��!0.����O�/�z�N�wme��nL���g;�k�a����y�����=��m�<=�asx�)8���nG�o��7V@����
�[@��p����A�d��\�zA_;�����T�{��E0�C��/��)�z��9pM
�Z��5
���)���Y+ %�<���0���\�JH����k�����v�,���AAj�^���xk��!>>��ny}'q�;�x����nq����oV��$�6�����7�����;������||C�/���$�4����0jq[������:�2�s��v����l3Q�Y9;�XOg]�K�s������>�qnv>��Y��I�����n�u���'�soh������}�%�~mZ���{m}�V�G�f�����pO��� �������e�/0�"�RAAA9z�]�O�����d��l�E���������BE�w	| ������� � � � ����`�L������2Y9*\*W����
/���P��sAAAA��A)����]Yg�?����)�����4;_]�����>W�S����5�� <h�������%�=��3a�}oh_��AA%"8(��*��S�Q���!� � � � �:1�� � � � � �G������R���H�_� B�c�1#���&K�C B�Y�Y(�=�4B�}r"w�q��k�+�����oUtAAA����z�m&��5k���#� � � � �}r�z�<�Z�,g�wI���Z���jI�sD(C�:7I�k�js�}��H�O9*e�U ��s!���l7"�i�=�8� ��������P�N��U\�f��}W��AAA@�XW�����9U���X�s�|,�f��oV�����anB�Y9���0K�O������!N[�>��t���#N[���!��Y�G�s.g�=��-Ne��ss)��=�gd�uAAAJ�X�DAAAA��DpPAAAA������G���/��O��1re�"�j�x�
�?���FT�z���uq(�l	
#��x�o?����+�W��CEM���Q�LX�?����w��f,�^jG��%��D�$��-\�jH��nH��pf�~��#�l���TO����{M����7_k�^��=���G=?2��>���%�8
������?�q�y@%^&����yW!�(��1t/���z�u�B�"'�w
*�|�Q
���~?�S��*p����Om�X�Z��.� � %!��������o�Q-����?bEY�Gx0�E�lZ��8����2��W��G��8��B�������_����a�=�������I�w�8�6�:7��\�����E�u(Ae-���y�'�`����>q%�Q���e���+@e	�;��!U���+������}sp�@^:,��Qw�AAAJ�
���O0��,��j�bI��w�AT������E�K�D����l��t�G�s8����&9���#Q������I~���}�%x1����3��/4�]�	�k��I��yW`D��/DAA�����\�u)�?����:$OO���������#g�N������e����C����]yi~}�
��L�$M������jt'�':�Y��N9��o�d�~.�:��U���gr[^X�7��i�����U�p|:FO*�J��p��eX�����g
.���}��ct�������q�V_��������Fo&�����d����s{�Z�$�8��j��V2;��&S�M��.tW	��������[8�����h#"���VB,K�l�E������.�j����S�����>o^z������l�8��~O0��z�)9�#�>b���$���P'Y���j�&��O��@���i�B��A������s��	�rT��6}C�������8u�I�`�����U���v������l������B��������_*��Q��
&��G���?�/|T��������X��N.\U���=����i�������6��&��^a���������kQ��=;��g�f��\�������'a�xB��$������iU�;��$SFd�w�<���}���i&�4�qQ'.}0�}��at.G�w~�Kg�2;�����N{����o��W�����?�	N2l:�^�����C��(���u���i��
�e(�#�A{W��a�������HSB�r��?��3��^"�(��"��3.C���g���?�1�C��d�U�;���+�7�WsM��)��
�5B��,\(�@���'`f*�i`@8�97{�PAA����M�1����t�������q�w� =C��cmd�:o5�����>�g~�4�L{2�+2��#�z���_����u3���o[������o]��0��G�q��o�7��9�0\`�s�0����M/��Y}|�2�w���H�w��o2qu�^.T�Z��ug1�������=�/�������u1��%���I��L��}��`�93~�db}5L����D,]�����u`�BV��q�}���H~z.:�����j�h�i;����e��!#���w���L���Z���m)?>�����h?�K����W
��)�}O���S	|�O�L�A���;E�	�������F�m���W�*4������a�g�Og�K]t�N�]�0z��4�Q���0^8�������6�I�S�Y=GE����::��9���i�������c�'��U>m������{��O~z:�����|��h4y4��'�lQ��Z�z��+�i�������'v�'�w�!^��I�??���o.�6���N2p�&?e[&���=+�lr,)j���p�p
�Y"i�a������'�I����hW�vfZ}������0K�+�o�a�3���7h������?���0/����@�UvV(Zs����awU�V��*��>����L$��
��07����>	�]��H�[:/�EV���L������8�����=e(� � ���s0��9RQt������.&��������r8�:��?l�������9��^rvd�;u�P@�Z����J��)��l$�J[���_5@�3/0���\��P��q�,�<G�����Q~[^��de4�ws�|C�I`H�����������nCr���[�����A������wp��v�'���+����i9T��a��D���(}������������p�6����Jae-�����S�37j��6U�^�^�	����2�3����J�8��>\F��imK�7�����I�����Z[�FEs��zw%T
��X�BA���S's�hC�@������
},�!c��c4� )P9�QH�]����Uf+�����Z���9��:�Jw7<�����E��pzWjJ�>��u��v��������n0f��0���,m��F�P��~cn��l���}������u��t�3����=9��r\�-�i
�e�$�4�w	�>C�^s�v�o\Jg{�1^���":<b.�rQ�2����{"�2T�l��EE�h��c���'!�����������`������2�`F2*g���<��`V5ho)���� ���?�'��g^�/^��������J	�J����l����hN����[-M��'���w<l_��a�������a��5��!:V����2�j���
�co
� � ��h��0lf����'�����:�]gI)��AO�j����u�KWd��.q������ar����R��#��w��;��R
�-
�D�2��WeB���f�!D�?�P����39�{
���E���C�|��3�����(J�[A*J�������e���|��������e�)�&�0ed��I6:h,�������go���2����U����MPG����F�Q��t/Z�����G�R�Z��^�6^�a�6�G�2���m��nI$�5�*-�l���R ���������9���@S�v�F�0\���%l��W�s�k�,��jE�B�
*��A��:m�yY��P��x>�C��[��p�k�Q��Z��I����gi��P�y��vS�FQ�@��{�_�X3p)C&���TU�nt�2�c~�o�>�����pH,��vC��P)F����	;M���UK��n��r)@�[���Z�(W����������$H�����5��C�Zo����L��{a�SRCg��i�����}�
����V����y	� � �C��*k���W&��b���A>N�w�@����X�cI��h�J7��5��e0��e����K�
��J��r��7qa�d�{��F9���
g��n���X���=�=o/�F� w�>�bP-�.��N�gM�I��tY��='����_1�
��K��hU&�0�?������J�������#<�$���*y��*_*uc����w���U�W��6��w'���V��i2�������-�l��+N��������T!4�i�����I� ����W�d�r/L�_X_?��?�M%������J
�F�����l�I���FD��W�*�J�j�z��;t������N��GG�\F�%�W^8{���fW~J�F�<n� ������t����sd�!_��v�D����d���V�<���I�.R�$J>4�$�n�M
�^��V�MF��mZ
�+!�h��Pg4���:��w�s����$� � ��#
~=;��ggL��9��2�����bHx���FRH}�7�o~"�3s�3q�'�1C�^r��U���e�Y��@~�m��;�%�8��V���tlW�iYR�^�XB��3���'j�5c�D��G��kXB)9=����s0�����o+�?��%��A�����y\6������|��O:�W� R>���N��W�\�$'s�x��b����6L8z:Bj9���)BB�6qt_2F�PIx�*��E��w������G��Mo���j,��j�y�l�M�x���|�.��U"����j7�z�LNO���d�c�����Y&�W��h��N@��P�rn.*P+�����M[� ��c�z�B���=���e����P��yo�!��y�C�
�@�	
�*���xZ�bW
� � ����$��^DlI�(���`H������
�O���!��S�I.�������`}$P�TYI����@r�����*hGZ�p"�*I9��K?|*Z�T���d����\���)�{uS"�����F��N%r����8����`�=ln�q�@j�Ec�&�|�zXu��>����xQ��aJe�KI�h�����9�z~)�um8u������?>�~n�
�
���y��krl�����O[�*�<�Y����nQ�L�Z�����nQ_U(5`���.�u^�������/��������^���"�]S�V�$�Lr8�m������^P�pj{�����L�'��?�U����{s�2��K'!"�B�,x�b�4��^uu$8�QNP�����#Q����y�)�����O�9:;�V�����XW�M���!�����)*���;8Cp ��}�,8nu�v�� � � ��5��L�O��p��[���� c�zvw��KTT�g�H\>�����n�@�+�{
(r8�<��Y���18���_?d4�>�jbUgm�U,��@�fZ�����%���#-��^m��ns�I�����q�����S?�C����/�S�R��0��=����T
���jI:��aKq���vV���f=m�� �a8��[X�Cu�8���' �IF��*V������sL���K9��x��NJ�����%{��)�B`�(�M���+�6������9*����#�g��h�D�����M��}6?i���S��mL��Z}�(���<~�?7����Vq$?�8��z����T��x�UV�bI�Y\^�wND��E�
����Hjo��o����b����h-��6����0_5JO����j�y=Ld�Y�,_j{��6o�����__a��r4��i���L��X�MS�E��2@������px.��9���A��O�����4@�}&K^�H��t��%c��N#����h@�h���NK�b3��B
�=�A����F'X|	-�+�
-�=��6:��>��AG��2�a�`hsF�s!PY��`��2�w4��d�y��W!C��P�c�St��["��tpVa��0D]8��R����������W�w�
Gx�
���Wq�40�����J���u�`����|��<��3��	j���H�
�[�� � � <��KhcBq_��M/�#3MFN����iU8|O��5�������0e�����	���=���cc� IDAT�������H�=�����X��N����X:u>s�v$��v4���?�)QZ�F����7���u�4.x�FR�o=�J<$X��e%��p�Y��F��IQ�)����A�Px1�?����v*���+�w���q3��+�2h�?��R�N�i}�6r1s�����Kd�x����%��.O�C&�:f�MS�{GR7o3K�:��Kchk�����t|k?_�6��-��ie�F�0����6���5�4�x���b���mC�E�oF��p	?��=WM8FF3�&kI5��l(�o�d��?�����z,-~�D� 	�����\�������k����\��EOLC�+�S{�R��6]>�
}�>�`���v���$s��`�M����S7�'�����KimL)�z�q�
�~w��-�i%��JQm(������!b��tU������<����YF*N��������o����`9W"��x�8��n�9�0�i`�E��3�cX�
�0�:L>
_��2D��_KM����U������<!#���Y�|e'�h}�Tep*xA	/G�s�����T��7��?��j��@�(�B����
��@w��~}c��qH�9j��e���2AAI���v���5k���/��[�{�8��w���s@��\��v�YyH����+=FN�|�_���������W2�3����.t����%�I|q���d����?D��g��F��e�������1_����X����a�nq�{r��Y�������{�8� �����Y/<��A�z��a�����7�������".r3o��+��� � �  {����=�=��dtg.r��q6~r
�nOS���AAAAA�Q'���$#I�}������5��� �^AAAAn"����������2I[E��I�3�/��������fD�:��6��'���9�������}��#� � �p�����*�����nY�CAAAA(S�T�� � � � � �k���`i�T|�8J�;���(���GC�2���P,{��t�9�;�P����m���N�e��F���qNAAA�I���f�9X�f
����+?� � � � � �'���`�������>��.I��D�k�^��p$i��p��>�+D���S�JY�������$�9"��=Y��v�&�'��U�P�e��\\^o��(�l� � �  Go�����I��=��1������ix��f��8���:=A��f���-w�}r����O9*]��/�V��J���s�9T0����Y��!N�����
g�:� � � �B,H"� � � � �Q"8(� � � � �Q�tX�CCN#���\)�������[�����e����g�����Gi����H��o@�z4�|����`f����|;�<�"�H���o�e�I�B�@`\�^����|K�����c��_��?�~�����E���@��P��n����Y�:�W�hrn����������^�sz<��t�F�����.��}�����,�4e��������/l,��������[d�*�8��2�:�M�I��}1�/�z��
D�A�[�lr:L�����*�L04(a�mZ2L�{���@���AA�G���H��7��K��|(�7k����xs$+�:?�����>�B��G�TV�n�i�izrOla�g3�s\�������39� ��������;�{]�}^�����6
<{���jY���`�����e�TU�)~o���������h� @%A�p�1���<���h	����J(���+����E��(>8x-��'�X<���*�J��~���Ni	� � �`�%~~8���I9e��A$i�������]�����9?m���U>�������~��G�re�j�<3�&��0����wiNT�/Z-�[��X0n;�_���q3*���P��6^����-D�C�'���:^��_|�v��w���	�:���{�ln��%
� � �Pj���;����Y,�|#��r�<|����<Iy/	2��K�)���~ho
��}����nU����Z�L[��]gHO5�
�&v� Z=U	�������]M��%�m3�q9���	������dS�>����p=���>Oi�����23,��I#
t\��K�a��+�����;t���dGZwf q� fnB��g�1��*"�
���:���L����������X��
����#��	Ch�lU\����KZ\���'���p���a�7��)9�#�f��x�<C����-sY���?p�G$���s5m�+�s��5���+&"+S�����U���U
\�E�.�%=9����a��La��-�4�{��L��J�	���/:�.�����������������S�T��(piO������?���-����:�>�����z�7a}���,�{%?������7�as�^�!�� ��u�u��s�\V������b������i?�H>s�q������?\�l��|e*=�,m���Z?�9��0�D��>��e=�=G}`n(8���|r�������7���u:�~�f@�a.00�;��!���=��>f�B����[>�(������(`j�a��)�$
>O������7� ?V�C���� �}���������i2����0��l ���
&X�����b���r��$�l�_�a����0>�?��MAA��HM�0��������!�<���&=S/	\���oio�����r��x�=�	���e�L~b"i~ui���x���Z��	o���s���y#�d:��m����l�#�m�W��S�>����I�3����#|�(��9;�g6n�C�����Slx9��	�2�=/���d�����g�������w��h�/c��������!�v�+�2�o���?�c���5{��_UB{~�>|�yNS0�H�oY�B�2��O�Bg����uR#��������%������������=h4?����3���o�5�K�U��_���1�i&������
��{����S��WhY��������OT@s�
�O�B��H�G��^�l�J�Ac8����$��m,w�����z\�
��x_r6����^B�2�'�Z����cIF�lH��Y5?-j�*�;{�2�������D����6��L6n3@��#��	��k[T���.J���IS�F_�x�/Y6��z�����/������� �o����~%�e?��\��u�{{,���a��k=h�o����WhY�������f?�}o}���F���j8J�v�w������
�h`�Y�S
?[������%h�\��u�v�@?����|x�0�����PQ	�i�9�:�l���W�R��c�02	j�C�I��*O�O��go~���p��=�+� ���X�q)�KP�������c��[�#)��1p�
���U�����F��+�E�����r�u���7�p:��� � � <���`����(��}L+*8T�BG�$�C����ZB���G���)	��C�e��F�Q�����wmR�AS�&�5����F��KX���^�Q��o�~�vc�>�1%(k ��OI��������D������r!�����$��4�w	�v�U���v�.%��s�R*C{�1]c��%�T�����WP
��SL�n�"�:��*C�T��V0������f�0zNg\$PF���K[�1��E����py�����w6]e�����f��>��j��y������#U���_Y����3>�S[7�5mR��~Fd��-0d���2�{b#�&�C��������������,�#�\?���~5Y5���ng��c���b���I��$���Gr!��&�|�ON�^� ��K�sZ�Y�����t����W������6�2d�����E�)+�V�Z�z��t1_��'���f���}�m95�o\^���u����y�T���}m�9�.<m�����v���������l��;�H����)�8�v[�H��2�^T<�����/��
�+A5K�M���%��iA�Oj7������Sa�m{�a��FCKK�m����4����y.A�@�}�gAO��J%)!_]��_IAZ0Z��nj�������jg:�d�$pP���6�Z���+��3���}i�s���h�[�����\������qKZw9o� � � <`���:*�26����Ex�P\����1�<�>��-Ks�r6��l4 5HGg�FEX�"$g��T�3����%�|B"��J7�K����Q���LUy�[����foZvRDD�Z��
���(f��R�L����oK�%;��;����o�������n%\��$9E&4�*��*C�t�7"~�S6�d�#���g�+�\�4K����~~.���U�aN�6�B3�olT�U�
.�#����H�����Ti�fsM%���o9e9�TZ^�*����M��"5AMtK����!����x���GA��<	o���1.�Sc�;?�F��:������#.�IK�����U��ND%�6�2,5���]�Z{���^����,m�*�c��k�;��F��g�*�L:J�U�A��i�u����e{��y��@�OXwG���}#a�!����;<����o���NBBJB�">5R�H%�(*"(�"*(���"* "H�����H'���m�?v!��&���y�����{���Y����	P1���X�t��0��i
�.�$�U X�I����|�k�P����uU~
$Z�����PK"�9T���P����+�����;�j�zf����gY/p���C��~�T�N��yB�;$!�B!������Am�G�1�����������"��>ty�!�]�������F�`u
F�L��V�Ny�%�d���e��Rl**���b�*��z9�z���t����4�����]�Ke��������nD�U�n�.|>����u��$R����c?p���U-Gj�
���;���_�!������n�]I":D�f�.��7'��\MN$5���q�3v��gTV�IMJ�H�~�|���y�>�x��^��k��P>���P5�x���
5��d0z;%tP0�x��RHO���P�}��`��sW����8��9������8�s����n\�r�=�MW��.�����GZ�4z�V�o=���Y�T�IMBm�^���x���bz���~B����mI�9�d�T���:-WUP= I�'��[�G�?���,���=��|��[
h=aZ�v>t�Z��C���*@UhU��\��#�Y�KC�~�T���:��}B!�B������|�FP��<��/��K�Y�
KF��:u��u���� �W�Sr�����ZH���9|03���N%=57�v�tL�j��F�����&o�RY��&$���[��x��yf���T��P<�p7�{�}����V�x��Za��CQ���kY>a��+��$v��@�r����Y���/}J��Y��p�]�}� �:)V���)�����L������P<p����d�= =!������YW�����~_��@�s6>������OIG��q��e:�s�����_�����oX��&���D�W����}F���i�0G[�{����X�7��.���7��;|~
ZU�2�v����u�FB��I;
�R|��`��	��L���p ���P�^.��}K�1����f��
���T�b=gZ����B!�B��3���x�����$����O�V�4�?{��,X��^:�$�������r�V�+�Og<�<�$��9=��0����}��p3�4�n;��Ly�3
�T0x�z"�Y���k�\a�LXm-qG���P��p��
�x��E�v���}��2}�:�mZ�>��a�3;�7F����#W��P��p��
!�v����&�7��o}b�c�j��cMFh����vs�����s���(�	��-M����8����3:m�R�[B+���'���c�?�t��P���v����q�\,]���U�#�}����v�$�����W��T���N?�B�0h�kT����[������]_-���d����?��������F��Ywo���%���P#��dO�����LP��;��3:z$*P��H�-Y��.�I�4���n��3��X{����6�>#��S�3���]r0��\�R=!�Bq���[�H%q�dn/A�f����y;��PqD��YQm A�IX�����)�C��q�+R���ss*�;e�.��,&���V����]�-��a���iT����s�U��Na���r��/��mPm�G��fA2�^mAH��GK��������s�R7�}`iJ��@���r�&�������1<JT�r����v`?G����N���(Lj�yN/[O�s�k�i^7�s'�jk)�.�N�����p���,��.����QcHg��|�o}�j�������������:���F�k�i�P�g#2�������81S:s��y��Q��V�r6?��A���H�8�����<���g�O��jB����^���B.�*M��u�2�K�t�QM�'��|��P��f����Q�/pzq���%�um��m���6���/�	r�8e����;����wf{�w�����q7]���=��-g;��Aw�=����y��^DV��t|'{��yg�4*ivp��
lG��dK'~�F�'�0T�Mx
o���g��2�!��X��nJ~�!n��C���RN3���)V_��
������M�O��n0��)0�4t;�}���j�l�?�����f8���0)��S�v	��
#����������
����X���4�,�;�A�e��J..���!{*��4�v!N��h
P^�.Cs-h��`�
<S6�'��~�m��I�q�����(��ca�tx�$���"��\�j=!�Bq����$
�J��,]��7�t��1�
���I���t#|������/�f��w<�:ZM�����a3��#V�P�u��N3Xz,w��<:�W>a��~lJ��D���ox�?n�R�e���FG�58������	"��W����?fu���vMb��Q�I���{C����u���}���k&,gY�K��}��I��U��������wd^��M�mS�����c���gDU�w���mO��72}�x�6��&�z�>C���Y��"���H���*����mF�jJP���O��������
��H�x���Etg
�-^��d#+&Og�7��JF���t
pJ��6
��>D�1;8d�MY|z�N��	,��R}(��;��t�gW��&�6>��Jc�M������KG�!���DUu�u��i��&��6��->�Iu=�F��Sk�,bYG�U�S��v��z�G����������
��U��BsG����a*�������{oq
��>�����>g��/'d^�����`�����P�q��.C�a�	h�5P�4����K0(z�X)���_c�	�����	�e� 6���
�N���q|rP�O�V������`�S�1����*���U
<[F�
���{>V����]�fW�I�`�	0i �>.
%0*�<
-/��)�O���q�P�+\�g!�B!�s��l�v���u�������[���h�����
	�����l��uq'����uy��������#]y�������6+m��f�N�6b=�RD�k���D�orQ�f�l%���D�u�;0$�oO$�"�X������
�3D��02���E!�B!P+o���$�#�B!�B!��$�B!�B!������9(��r�?�X�����(�����NTxo6#/2!�B!�BQ�$9�_��@�q��W�q!�B!�B�"%���B!�B!���*����1S����0S1@��t��'DA
3���.�!��0�O��neAw%�5�����+��x;���E!�B!��l6g��9X�n111��B!�B!���X��	�����s\��!�0���W��e	���~��4q�Q>K
�GQGg?�� IDAT!
���*�w�0�������qTE+:�#��*�0�B!���%O�+�	I��u��66���o��v���2m#�P�_�'DA�eJ%Z���:V��GRD�kC��=�u������+cm��k����w�B!�B��dB!�B!�B!��$9(�B!�B!�T�+N�g�������k3�W�7�����`Y�������YlY�Q���k�kT2I`9S�9��.WhO����z��]����� $�-�o�$<T��lj��=��B�bF��w���+��3�^�M[7���>���6.��6������ACyq|x���<�
��f���5�/�B���
����c=5�R��jL*4��[Zhu��U`�
e�{��>d��5�X�������}H��l/
���~	!�B�&����
�����a�pt���(�x�(L�ui:�#%��1���w����Y��E�<%|����.�h������|��#f���K��$����F����=y\�#h:�	%��V1A[+�u�N�����nc����E�jZ�!�m�K��
���(�ldZ+PQ�3*LW�I
�cO����W���SU{�������
k����B!�"�����-n%�p������:!
�b�l�h���^�H1S�eC�������qL{e9�w<AhCn�%��R�:�Oq�l�:wA[+�ED�m'X�9�_��Tm^_{��R��o�����T��Dj)�����^����g^)`�
�M�T!�B��}��p|p�����uN�}�!�tA���������
���������?�f��L��(��C6�
���]� �r�y�z��_�����p��1�2�����O�+��?������k�>��K�nw�C���4����T.�����b�'�=�Z���>���K���q��{�[�Z3��z����1tAK<76/f�����*V��Tz�m_���S���x�����qq����vk����M�b^������^�}o���^��F�	��S:�����{���;
���Cx���5������`�+�����[�g�;?q��+X�����y��P;�qF���8��?���%n��1�Z?VN�������s��8�>����:�I��1�C��������|�Oa����|���d���fe|��$\0��%���&.����$\�`�J��gi��������������>�����w~�.<D`�'�L���f<�=�3�5p�u�z�{$������5e
�Fm���x�~�T���C*g���K����9��</t�����[v��*����)���
���fj�����*|j�����xB����t�K�T�*PZ��x8	��V�K���B�J�(����*t������,��o8������K���50�)��
,U� P�1���W*����@'��/`�
����:i�z���R�B!�B�����=��X���6��7����c�r>��*��91o�a������)����s�j^�r����	����{/������
��ko�xA<�O��\���u��a:��~����3��SY�+g���?�uy��s�"2q1�������}���s8S�mg�����\��?L���[N�i�2�]��������%��*J@}j��85I�>d���-\*E������,�o�����b����4�K��OX��
**�+>f��>4������3����>D�/��up�N{���;�8�]f��������F�yo�66�������X�	����iXYO@���������^�v���K�����%�Uw�|\�V�b:v��A
i4�M�������X��Z���b�kH�5����X4��?\��u!�,�RHs�I�8��$
?jO��,�>���?���%^4���#1��~b�#K8S�m�D��e�:�~���S[_cO�	�03������gh�?���s���
���d����xO����a���e�l�^�N��=6x�~xO��l��T�
x�
�?Cp��;����*�Q`��+��)>�'�ha���f^=�A5P{Bp����t�D��
��w82��`�
�50I���6X���b|���xGGm�g���R�B!�B��������MFE��@�N�|�f~��&T������.�5�C�
��\�9��]�K5����=:;-jR���,Xzs�F�d�Z4�?����N�m�3�6������D��JJ����9�����k�F���*[���5nqU{0pv��j�t�O?[�����v��X��}�vO�;��������=�cx|������S�[t���RZr��4��
�U��D=]�a��/�U������������'^����i����mW�k����e��^���I��t�R�=�,��`��{~Y����x�����_}"�XQ]�S���g�`M�M���	��L��Iq1��[�$�b2YH=����l -�U��z�U���<=::-j\��.,X��#�2��z4~�������
�j�A����^���ya�eZ�k��!����:�G������'"��v�5x(M�:*�v���[O\����C���B@��|��f�=��������e
��}���{���i$��l��uA�W!&K7�50M�xf�S
L����Bo
Tu�k���
��{���Z�d��A�}�^l���j��l]�� �m��x�`�jZ���:8{Z�����y���
�pj/2&���
�Q�	�AY�*�@�����WO��V��������XG�V��#NQW�P!�Bq���XS!���7Z�j����TB�Np��BH�H��(~�U��)9�mY.�J9�����E�r!�UE�XP'�f���OFqG/<tX��0��s�(������X�}h�Ge����3��}&�'�[y5��[I@-�
*�5����u
H_��1�o;���I4��c����_E����'B����<��^�����=2%��2��;��-V���@���{�r�#��pr�����f>������\��Q:����bu���;�1���y�P�v\�@�[���7�
�2=�y���"��3��4�_�����X,6T�������2���^x���\��u!?�� ��V�����S[k	|�7-V����@D�
)���i'8��J����V���x�;�����o=Jb�H��������m��(��R�.�!�`�Y��
T(��>No�T��U2K�f�@q`�{QY������^�(�/��=YW��F��e�U��@[2�
PG���lQ���)�C�o����'Z���:B!�B���A���n�#Z��vTk
�V��G�����[�<v;��,\�����WG�`Y
��D��uV�������Cu���
�������Fw��:���ErPM�A�����/0v��6�j��*8'5�x���N�=����s�V��L��_�^�5"%5x�S�G��\v���$�Sk6�"�Cs��z���I��[8���}��C6�j8��@�������G2���X�����~�Rz-z�`*�J��XG_�+J�`����Y�~]��%�\�f>����\l�:�X1���rmDD�0�l<Bp���e��&���)�F1�m���6�ji�5E%�Z*���n���s��D����+����b���V���\T�>d�8�������{�zT�����U���l�'�)��{�{��?6�;K���^�Z�B!�B��?9�&� �����7����'(��*��)����j
iI*��oY.1d��xJ�<���J8�i\�����<P�1zAzB��B���c��&�
����1\N���]�#l�8��q#��
x���QP���Q���������*���%6rL!�w���,��+7u2;�}@�r��W<��n�6����g��b�����r�����I�r���m�i��f2�3���qT����A����a����W)��TZ�u\R�dK����z~;��9����M����_�~{*�������*��fy���w\Sl�����$R,���dWT��BM������v���}��i�Y�d
���[����ro����O(���O��cR�.�7�'[
�u���)�:^�L�Z�B!�B��B����>3�������-G��n��P���i�U���9s���e��`�4B|�Yo3c1)�����9�{z�w���&�������$�0�v���Rp����DRn�c9���N��V��zZ���U����~*������jjV���W�a_\jt
.�!����.����8���F���#�}i!q7�2FVGG���x��%���Ox	�q���A
���`�/������s�}� ���1�7���n"ZXRM�<�\�'w^np=����q]�u�.�������h$�������/������U����>�������xU,A`%���m��"�I��6�m�3���������0�g�����
��m�'�(��5PU�wU�yi5(�Y|Oe�0���d�H�$���[��8zL��7�0*������
T�>d��~���X�1D�M�Ozr��s����nr��B!��d�\Q�cl�5nCjc<��5s�)5�9!:�Pj����f�h���Q�}��������/�&-%�*�����_��n5O�A�(Q��P��
u����S-�Q���G|������4��*}����<�v�q�;W�����
J��+i����k�V~_���������j��IM 5��a{�i|c�F���p7�sm���
��W	��Q�-I��Y?���������@M���eHw����%�e-��l�7�U[J�ty7�����4[}�����\9�� j���n����	����n���}{8��-?�`h�w�Y�����0�?FdUOL'v�g[1v�O���Au�&���Em	��$����>��s�mA�<HX���m�)�G��q#���t�x�*������0�Fz�/^�e=Q�U(���������S���G}����.�5-����$�y�5�i]	w���c��`���� w��;s��A���h5��x-�����c[�:�������G9�7���Z���A�=���NC&������f�V?b�7�O��v� '�b;z��B��]�O�b�Lxu�]����^EB<������|�2!n��C��D�H�;�����j��|��F`�
v(����+���<
�vL��_����>D��
G�J\C��0���;��.F:�s��4;�=��[���+�H��*{�<�����K���O�=�I�&��b����mj���f$����l�����T��d�I��:&(��>���,�v��B!��rPS�a�5:����H�'��atx����B�������	�>�������F�������w�e�����?vLf��1�I���w4C��D�	���!\}�K�U_��7�r�z�����
q�������9?O����=	y��:~���k�u���t�KLLX�^D=���2�16|�>?����,�u�t�~�Tz�����R�iY�`�I�����n�~��K����vd^f�M�?�P����o�!p��DE�3���i��&��|����hRU���3��>�5�~bY���|���N��52�3M	jM��~��l�d�.�p/I����t����'���i����7B	�����;3�vn�L��?gu����������\��e
^]����cY��+�IU��3�!�������\}�#�=0�oi��|��.�Xz4�����l�=�y��2���^�&��q��W_%*����)����w1���lm1�&�tu��Bo����e=������j8�������r(�q��<m����Q��:��V��a>��������G�����8�B���
����P��B�>Q��*����J*��SUh�H����>��+��ghOF�L���L|g�k�m�rZg�j�����������rq�}�
�^O���=��h��xo���16x^�'��i`��j�H�9w�m��7m��
�
�@k�u��5��{)6�@�,u�J
!�B!P�fs�����[GLLL�7�"���u��M��#�^��]o�i��m��X8>�?������������$�4~�c�N��K%]��cYw��e��^�6c�B��0c$������T������Y�Tb�g�N�rb�����7$^!ZQ�a�0��;�] ������i�[qTEg��O��K1����E!�B!P���1y�}����g��e�
�W��#������4�*
�J���\9��������-*�g�A!�B!�B���>9�V���%l�z��:��=@����^�$�
��ScG0�G��~�GF� ���
!�B!�B����A��bdk)%�h�$�6�{�r�?^^�����������\*�P�"���x���f�~��2c.�gI�B!�B!��I�qr0�*Po��+�8r�^�Y!�B!�B	y��B!�B!��Q�s0?f*��/}���B��<!
R�60�u4�B�D��	s��1�I�a��EM���]�����:!�B!��W������`��u���V<B!�B!�B�BR`=[$v�����s\���a���W����;Y�akP#�:
QN%���0C���u��qTE+:�����E�B!�B��������$����z�[��2Fe����T�
��Uq��e����n�������Y�������#��LFT�6$�)��B!�"_��$B!�B!�B�GIrP!�B!�B���V,�X���Y;����k�����[�uWJ_���^F�l=����Iq�P�r��y\�F��A(�Vp"��G��g��hQ����e��7b�9�4�,�(�]�ut���`!���������?��kG���Q)���,E�C�[���vD������hi>�	SS�,W�
���M�� �0L����{�j�o/@��(�����?��T�K��n�$F���)��N��17Y���UP��B!�B��$9XX�e�?5L&�}�E��L���J8��tl�O��q��O��P4u59x��nD��=)�t�V�%)����]��t��6c�b!T{��(�i>�!Z3�G~��i3�{�L�}	��d��C��_����|8D(P.��P�P���W��������m���~0)�68z
>:�l��,��aV=H����y�Q!�BqO��n+�c:�J��
��
$u<w1Cc�|�N�!D^(n�(��!���^�w�C)�����K��C0�Z6���������������6,���J~P	���n@�@h�/R�z?X���b2��?��V��m����2�@� #`�vzB!�B����������������s��sv��+E�~�����x�����sj��,�h#�LA��7������/7��\,��-���u��r���$\3c�M��Wi��*n
����[����t�z�m��R�'�]��erg���"5�3G�t�*.�{�c0�R�����^�o�������O�0q�����6�����X���KV�����.a����#h���x9u��,~���[h��
G}��mg����/��%N����i���Y�V�JY�\���',���7P�Bj���S��B��G+|9�G�b�Tx�Ci������������	�%�
['&�d���\K/N��(g�q�e��tL+.��/L����;����o;������{;�n(�=��s�������@~+�2���q������`��8��q��y�z�'��������|�����g���4�����en����@Z����s��jT�G�M�EE������8tL���B�:��w����s����q�I�a�I���aHw����(�du�s�jx��m��_P/���#�U([�*=��w�uq��B!�w��89hg�1���&�{�g}���/�����C���9�1o�>J}��5��t*������.�*������F�
����������~,�\J�n�o
���������a�}_0��hVF5�����TI]�6�
���so������9 IDATW����e�P/w�m�6��]�"����~����?x,���,�n9��AqT0�''�rt���'�)%����VXL����y.��w?Z�q�pmS
����U�HH���p�B�c{kM�?7��z�m�p���<�BE4(h�w�.����q��a�w����'���3Of�V3t���e�������4cJH$�9��w���G1T����s��8�}��=�IY����p� G�-��j^���n���sPo����@��Or���,��6=�'e�G,_�K���qn�����'=�7m�����
��5~��A��J���]f�s��ik0�_~�����]���hEw����$����)����/��pXV����A]_��h���9L����??���5�<�"�i@�b9���tP����?��A��ViT`�x{?x��NNeN�%�B!������A��	MF���@�~�|b!3�Z��/��f�����'���vx(P���5�q�[�W�K5���y=:;-jR���,X�s�6�/�h<�=��@p?�6��U��b}�����5�\NJ�0��������k���gnv�v���}M\�8{��Q$�����\���v�O�^�'�;�=Q��`	�@����<�*�	��P�X�i�>�����.T�x����nL��Cq��L)�&�fP���[�T�DU>����j��ydh[��P�����q*/e���i�1�r���y�fZ�k1�!�z���6"������7F�'�3'^Y���94����(��j�WW0�j�����_a���8+w���_�|�d�Tn����z�#��vt��]���������q�! �(��\����(�����e���_L�����u��>�OXQ���%9��B����w=i��R����~0�8���z���$�`_��RZ0���_|��V�}���J�a�+U�d+�T8v���@x ���������>�;�L�N����B!���s�'5��}��JGP��h>>���P���?�����U�:�U��)9�mY�gM9��&���?�r!	���j1�4�F��[�a4a�)����R�=����U��R��(��Y�{������M��v&�������v!��p+����Am������C�n@������&\,K_���o�<d&��ekW����,*���qn���a���5<X	�GXUm����e�w����e���91��e�C��W���tK��]�9fD<C���q�T����W�
���3s��e2���Z�~��;������3�L?��?����4s����5�0�l�������U�j��3����fz��-gN��7�E_�A���@�"~�@Op��D���	�_E�;��KP�R���~�Iy�f��?����S�s"\������lp+�_��%�B!���}rw�L�2��-�I���Z�H�*��2�Y/����9��p%9�&q��'Y��$
�L�m�u��������=�t��O�R����vwbK&-	�>�N���������@�����m;��
+V5��DB��k|���[��Z���s������g���8L���P�L�A��7/
H��G>�jr2&����SBI�������MYp�c���rA1'�����nt��,�Tg���wnK�SG�\��y��	��M��z!�J�1�5[v�ps�����&'��n��{�3v�s�6������H�~�|��)�������E)��o0�8��Pe�+��=�V|�����W���
�j�j����j7Qj@���}p!�Q��%�B!���}rPMH ��W��z<p�TP��a���&�@���L��%����!�+�%���_z��/K�^�	�.YSsLNO�^���<m�SRz��4Y����L3*(������
���m�dz#e���kP�xc�zY�u�c��cK>��9�X��X��oB����y���C{����x�����4�s>S��9���nL�TV>S�/e������L����xx&��k���\-8���,�`�V n�$v��@�r7�,��AG��Oi�:��D�����v������X���L�T�e�������u�!�u`I��fT���8[�C��B!������D�������7�-�rv�^le#	�U��
�*6� ��S����K��u���������7�����`�+��,�O����z�@W��	������H�G�nN�49�����
��H����$���2��V��z:�^��b+9�T,�G~>�>ei<K��ST��t�J�������C�V����<o2��
���F����p+��v������YV~��g��w9�]�F���X��7��o����c9��]_/(��n�y���?�x�>t��mZ=p��//���I�:��\�+�,��~�C��h�kP����>1s�X]�Am9�;��[��C���n��~8%��C)��5CcO�����y
xh����=�l6���>N	��D�!]�B!����=e[|����/`��$J��L� ��������h���QZ�}�'�y�[�}Y7�(U��y���"u�CT�e�P5(����Y_q��@���a���9x]�������}�_z���^4�����S�{UA)s%-~Qu����t%��q�����XEB������U�1>K�����pm���-K�����)��������*fUE�;��3F�����]*�F�7��pk���I`����3�y���o������N.�CBPO~���m=(S���7� 7��sC[�O6d�����H��p����g��Na��j�YN/YI�����'�U}����3�U��h��I���N����X�I#b_��6���I�~����~�v��y��g�yN/[O�sGD�!-j��f#~�Vm-E�����'p��|��u�}�ZM5^�������Qm�q7_���=�_���� X�z�h�r
?
����������N�l+N�����x����>��Cv2�&!��X:l%�>@���{��ZT���g���V8�
�
��A��| 2]���C�
f�����4�[c�_I�IJ����U��4�c�����)P��x�z@�=�������������
cOB���B!��~p�'5�bi����&QS�������
����^��q�
�}4����	�?�F�������
|�e�����
:�����������+�Li�VL�)���{��>�o�z�@L��,=�O��G���?��'�d�toBL�����|�Z�F�����,����K��%����I�����Y����:K����:Tz��.�TL����Y������1L
������T�p�,
�*���q![��$��
c�ZDN�N�V�w([����;�����������4x?=����sC�����qy$�o��_Jtz��M���U
���H���'�f^fx�v{���iK����W~ �����u����L�u����&�9�?��,q���L_�v�O��i1K��C��������l{�����Q���!M"�<C�9���`���H���*����m�5ES�Z�~�~�t6:�]Wl��ERe�sx�_TX|��d,�rP�
�jr�
����N-����&`���~���`�)�����/�:���l#�+���0z?����:�����N@�Y�q��e��	8��b�B!�w�l6g;jj��u����z�-;�o���n�`�&w��Q��7+5�X��NK����
���}�q�f�r�_w���K��Ry{�������c�1���^�+cc�of���^���(0�����w�Y�sAc"�X#��K����U�Q�
�g�412qfQ�"�B!��%7��s�}����gV�e~A����q������h�9L��
!�B!�B���>9�V���Yl�z��z��5��woR/LR�B!�B!���v'�T��+#sXK)C�%1���������l�N�f��.�:�?�RY�"1���s�������!�w��\B!�B!��}������:�zEGn��1�_$��B!�B�����B!�B!��?��z��������r\/L[:_�� �i��:!�$�P���������D{����w��E!�B!��l6g��+X�n111��B!�B!���X���W����s\��m-a��W�"�N���
)�0D8��%�0������0MhGU��������B!�B!Pk���
tB�h��zR/��e�~���4��7���	!�nV��|{�����2� ZW�����h}tFT�6���CB!�B�M&$B!�B!��?J��B!�B!�B�G���"e�g[�1,�b�cH	��������e����|�-��w���ie�%65��]Vtm{���p�q�����&�����}�GQ����$��)$�@Bo�z RE@T��
�kAE@����^;��r�	H��z��f����
lB�ME|?��<����������{f�p^�*����Ka�{Y��~��S��A�z�T
|�-�k'��������Vu&X[^��K��s|�$��O
@�h���%&v�z�������9>�=������7��&�s����fs��-����f�PJ]�s�k��[[��yM�������9�?���(h�^���!��t�'����^Jj'�^�/���a�3��k���x��ai��uM��!_}����'JP#�;�����a<������1&��>m�4T;���hh~#���'��7&���e���	�a��#��R��Z��s#����q&$��[5�`P t+�q�g@��6R��a)����B!D��}��.����7�F���=;���Lf��x������W���P�[�6���^�������a��T��J��������g�������{�>/���gr�&�M�������/�M�.��}6F���C9nCq�	�I��[����w��]�w{m�\����N9�9��jv��M��$��4��yX�x��+�E��=�kX�N'i�6?�%Y^c��T����>�o^8G��.�i����Y�-���-�hx����<���W���M����E1���Ym��������M�����vF��X�m�4T;|��}npr�o��^��Mc�}��Q�41
O��fx��6�=�K��!�w]����,K!�B���>9��DP�{=|��z�����;8�vM������6�7�.�-^������@NYk���t	+C���������u��4{���V�-�!�HT|=���
����������m�k�[�b4_����Q5 ��c'aK'"��jW�Z�*z��U���#-P�{ y
g�s��z7u�s���	��0t8�N)�Q#�;Fu�����������e&���8�(���k��^�d1u��$liw�=q�Q�M�n/��F�3!����-�O��7�fB!�����O�Ak����C��o���w�������~l����_���'�
���Q��bO9�8��\�~��T�?�Gt���}���Ent�{�����/< ��k��ld���d��1��P��>t���By����"��=������P���t��k�J��������L�:�7>hF��B��^���6�{��������T�����q�D��Q%�Cd���iw�����������46����F�.�K�<
��"	P�q�p�[I�n)K������Q���t/�������m?�f��z����Wa��4��!�{�A�t;�w1s����y�T&L�0�a��_�Y��?Y5y�7�u��*���DO��,z���)���
��e�����q�2cK��n�v~y���{��O��Q\�lnH���l�����������8��#��s��_���E_�����g�������=0�������UK����u{m�Y�w��M�����k5�=��w0|M*��u�^�����{��
�����V)K�yv�����;�:�U������@���W�mA�r����7����p�:h������N����}�I����{��E�N��
�gBBd���A��^Y*�{|��
f�B��A�/?.l��L�9�P���`/V������YL7��4H��I�*B�������:A!������vx�$���o�����=>��=60�� �]��[��y*,���@%#
�����y�?|cv-���$���� ��}Z�6�����h�a�0��vN��;�`RlH��P���<k�k/m��'0�F����d�yht���Z�0'�GF>|��,p��z�a��}��o���������B!�-��O�m�X��6r��q~�]�Y��JT�lo����E-~.cET���b���D�B|c�>\��
6����v��;-��W"���S)����z���s��������2�4�A�����t�?�!?������9���=���09�Ebp}YWmd����MJ��Y1�{�������)���o�����=g�`<���	_���3{4�'q]��d9��(����8vo`����]�����2�H\����L'G5�T��/`��������^��^����������n
��d��,����������Q�
~����"=m�l8�}��2��04����u�R��$�auh�v����H���1�4�A��pr!G�����_)sN��[���/}���a�Z����e-kr�0?]�5f�dK�^4ix��uW�i9���
K����U����ym���`��!_�lZ�!�G�(����|���s:=F��F��;���r����!~�.Z���>�Z�����M����&,���sV%��Y��w|o��G���82�>r?���K��\��e�A�Z�D��K�F����N�u�5�/&d;�P�u�j��
 gr�d����f�'�@�0x���Lnu:j�x�A
������O�p��`&
�o�a<s�@_�<?����0:��03
�P��/�f�	v�7^�����	@O����r�9�S�[�^
���/���5�a����LH��2����������	C\+v�`�)�]�T�8�����������t}
�����6g��3����G��@g3L7BN�T��`v&�7Bc�D�F�U��{
���?g,���2��������R,�i2�i���f�L}�B!����>9h[�=��}�|������{�]�t=�tF|+���^�2��c?��iPz�����V�Z�����y����!�t��`������&���n�k�[x�����5�^�P�h����Lx��M��T�/��%�����$\�;��Y�����@,:G;&�#%�;cfv���&�Y'���M�|��4�u�0�v���d�����4����f�,v�h3�1a�@XG���cya\�&�����S@��N��D�L�I~H��Ws��i�M�1��-�#Qw����H��@�L{������v]����L�
`�����st`�kSS������U�����G�jP�g��6���,Y��f9�����uK?���m����^��4n���>�.:M0M�����e,�����`":����64i�Lz:2�1y#)�]3���X�Np�)>�d'��J�� �ZO�eO�)	��N(2M��7��o���:-���~>���ur��=��}�vM�5������������KU�3���'�s��x*���e��7{(w��v���/9�m{{Y3!���z�8���~h��Q?W����}�(��+�����2v.�\3/�wV�C���x�|��h�[-���C>t
��L��i�T�+�le��w�����st�k��ey*-:f���;�]��������/����!����
>��������m�����.;����_�w8tt5���0P�<���>U���l�
�q��u�0���0'�-Ou@�@x��-���������`�I�����;z]�P D���8�t�K���S�'x�5>����&f�TO�B!����>O�m��{����a#��>�NZ������'
n��y�8�O���*�JH5bb5E�h�ds����b6�t���y�l*����&�|4�6&��6�]|�']� IDAT���Rt���+W�!*�5E�O@�[zVt�G9��N��w|�"ACP�*�N9��d�J����[�6jKaM�G����~�6�"S{��]����B�5���)�-.�:x�����m���w
���t������g9��N��*��I�Dt��������{��#�o.{��d�Y����|:�bj�S�
]����~���:cR��h7w$���!i���n��S�[Z���jh����sl�N��>��Y<�O�O��!h��;��b��q��N9�<V#<�b��4-un������HnD	
��B�ZBF�����Y�� �i��g#.�!�O�b�[,�J�N9��E%��$2�������85�/�����S����0�G��;�Q��L�������2(p��H����p������^���H��+T ���[�_��>n��zA
�le���������)x7�������������0"��a�����;�GLn�P��|V�@(�G�s��V�|m9�{�s��^^�����z��6(����K���
_W�-9�!��z5���&�s�����\8js������%C�_�>B!��o��O*����:hS�s�X��O��������k�����v!�����-^��O����O�R�80��-
��[����������e�)�+�����A��\m{��4E��CE��\�
��0��o����]�$/SE�yW!s,��t&J�AHp��R$b<��E�-��.�%ns���@�A�>�Lp
����a!?�����f#J������i|0��
U����_1oQ -�����0j���N9J�>����GB��Jb��+�m�r�l�CU�R�������������[�Y6
���oo�������%������+�X
'/C���k=�B1���
U��SD�����(a�b	s��jN�+��K���+���<2]�g�E�9m���_��;�o�0+F�����q�R����5:x:��@��g��\�VZR������$���X��_��h!��2=)�4�Zh�}�I�z�f������s�r`U�����tP
�
�������6�P���k|~�� S@��`a��r4��s��u�O��ta�j�iI2L���A������
)0�K��W��B!��[�����j���$���i���"�?*��]�D����S��ZQ1��'_@A�
���t�D�7bK8�9k��o�!qA&��=N���]	9g���������(�^VL>x������z{����'Z�R�A\���mQ��e������H1��2��}�1����|��*�t���%��((eM�X�H\�E������ W*���Z��)�"*R�U4Z����]6�����<�|����p��
>��1�+��'=G%����AK��cJ8Vu��x���z�7��N�L<NP�0R����{�y5M�:��8�
�8���������/�-��~�)5z;_�6X�
�>
|`��'c[>���C���������4�5�_����S�&��RVI�������l���0-:U������
<��UXQp>�@q&33�\�9���7����B��	�s�e9@��T�3��~��_��)�y��S�"ZW�G|/��v
�B!�[���������z���fZ6����m�����v/C�`2@Zy����D����/��w�S��g4Ru@]���`���"�"jNV�[��1��J�n����!�UU���������4�R����&����=���#����F>O�*�+lC�b;�0"b���v���}�����Jl$a��KW���<����a�f���
�LR0����{i[,)��mi�S���6���\���K)��j>���u���z0
�����^��i�!eo�5+R��U3�y�z�k=��#���K9T�=w/D������-��g�"]�d�[3��Zn��fW,[G��u�]����g;p���������8������-�vn����f������W\~	%8T�R��Y������e���>�P,p���YVyr�`�y�2���[od:�|#�W��b�P�����#��d���b�^x��@,�f�BRI���>��&���/�����jK�#�i�����V���b�u
XJ�������bbP�;G..���%�B!nu�}�A5��%bT�X���0�w����~Sg�����NN`����"e����@AJ�9@A6VUEMI#=I�S%� %N*��A��F�L�H�Xo��aT��B���������2~�F���&-'1Eu{���w��t����uO{j����x�����Q��Tm�c��������)$�_��������lO�����O��L��^:��
f�?kSt�����i�R������n����� ������3�.�;��$����6�0v�7���=�!k�������+��Uk�e��Z_6��BOi�m$c�&�4P��m���P=���c���8��#����8~�e�����*��nk���4�}h��-��/uo���l��1���*��;��}S���"�����/p����/H�j�=�	r���O6|r����`��Kql��=3
����wA�;�8��m	�p��B\�z����N��D,�]4&����� ���,_L��q�zk	��{�.g���>6�&�/5gk���ihO\��xd��#��;��2�a:��lI��;�y�L���P7�H��#l��O�g�=8��X6lb���	�\�p��,|�(��������hj�������|��C#+�9�hal�,�FU5�k&t�8G	��9����?eBk3���7�Jy����no� 
��#�in����J�b�U9E{�i����y���)�U��Q���p_*���a���c�Ao����a_>�����u���a�i8m��8���
��!����X�����cW�B�mp�}�h�_��h��6e�&��-�O�*�8
;���"4p2����f�]�	�P]s�a��36�"���43��LH4B
���V����B!����>9h�s-��^����&�c<�N�B����6����Y>�.��&fxO��`Ef�
���$�-t����I��,�u�=H��9*��G�m�X��gl�U�9�g�S-
a���Yr���3Q�o��;U�.m�g<���E�6�g~<��I��	�J
���c?3��*��
T��;��~b�~��h�h8�	�S�~�w�u��w�j?�S)�-�����+����{�c��X�*5���_�����<v�m��0v�7�����?����e��fAU���� �����5P��>4��wM%��G=����:����9��"��]��B��]����6��{�]���?�����-����5.{��>�-Zla��[I��3�m:�{�9>3���3"������/����dR����W����b�
��3����j�fl��a?��r�&Ns���Z�u�z��u�RT���X;�P�i�*��k8�,���_I��{����Ji�4��{����l�2�v�:���0�'_VN�����X�&�U���Fc��i������d�~��s*�U���Dl��q����e;$�T������+��#��Z�>���78^�v&�^���C�t��C�@�y���>}+��x��k�k4s��w#�*��<x!��4�7,
��L� ����3D�?<���@\8�T�q|��O2�i��9������b2N����Y*|���(#<���kb�a0�$����A�6���"��O����<�9���W���I�)���Y03�;�O����K���=�%��� Wu��<'��}�p:>h��?<�W��xZ�B!���)V����j�*���K��������b�+V���3��IC�+�7=�k�{�^syB���n��p��7��:�^p
�L�Z9����p���\������Y����gB!�B�@mp��3�@~�B!�B!��J��B!�B!�B�C���B!�Mf���L����3����a�B!�B �A!�B\oZ#�R|x_!�B!��@n+B!�B!�����,���/��p��b�W�Gq}�h�<������x�b��^[�&����F��7�
B!�BqM���^i�U�V��#�B!�B!��A�[����g����z/$Fo��<+1���V����f�c������Q�9bA7����6����]
!�B!��S�/j�J��/w]$��].���B}�+�c�L}�r)OQ6����j7��:�n=G���n�-�fWA!�B!��P�����$B!�B!�B�CIrP!�B!�B���z[���~"������#dYM6iL����e���eF��~��s����C JI���f�{�X?{g�9��\��C�!~l}|�-
k'i�������V�#X[^��!��,x��j�;��?�W��(-��P��t����T������������z>��y�*�j��1�_�W�=�jC:t�P�;t��+�qNAj:G�Y��j=h�&��c�J��X�c�l���6�q3�m��?���%�HVAQ�L���%v�H:���P��o76���_Mu�[wJP7���5�kC����������'=�c��.��y�?���;�j�`6C�&0�-���	�I��Y��jSh�W������a��N��0�Q	�������DH�@���'�B���������,K!�B���m�T�meA�wI�5��O�G��Ul��'
�w��4YG:G���]=�������	���k��}f8mj����'��'��Dy&o��Ft��'�Zy{g����n���ka�����b���O��f�U�����?}�mh�f6M���X��"��\�#���|����iZ���6��3�����������5���]C*A�9�f�a��/�e��w����+�F���'���(�0�5�������9���1��y���;����vX����g��5��V�d�`��,���/W|�-���;A?8s�'��m�&��>�q#�B!��6v'�$�3��i
��e�������v���4����]%�V,V�?�u���w&���������b�S�!D�7��������:v5	[�V�W�
xa�d�@�����)�P����������)L}q9	����V;
��
s�ir/7��>�5��E��R�������-�����?$;�xU$������u���b�k�h��On3t��Lv�~����Ghyz^-��x+�W�,�3����x�����`X{���4t!�B!nc��Uy���f�O)��y��Q�/|+��w��n�',c��T����9j=��u���\��1�7�5��g�0������3��X��qh�Vr������C_��/[w��������8�v�UjR��at^�h�2����������Y^UkR����@��������o���d#�we�	1z�#���|��OH�����=T�]m�*�6�F��H����jx��v��m�30��S�r6���K�
�
j��$�L�����y_���5K�CY�:�����50��E����^�s���l�v�o$�&N�O��|;�����e��h�c'������U�/b��$2Rm��Pw��t�����h�S��j�'�'�>ZI�g��w���{\��������6��fw�Gq���}��c�������Cx�+!�������[��N�o�o�����M�u��}m
��U�z{	����ILm�>�]�^�}b#��������V��������x��x|����P�A$(G��
��~\��c����w����Y�<���ba�j�#
L!��p�p������L��������{���l���B�*W��{�����5R������\��;+�|�S�!�B!<r�&�G8��!�Q��,�4�o�/��y=g��xl#k^����w�h��I�����l8�}�_`�S�����7������|t��z�^�*�����o�\AG��u�����7�����E���|�������1t���e�_��z/9�W��J�����������4�W�b�,k����9oy�j\��O����'��8�M���-�7�������d
9�7Q��6c���y�(������{��E����s�6�T�~���c����C�^���sY�������A}��l?��g��6�IFL�vhG�*�����Y��g��W���5���Ah����**����o��'�j~}�_�7}��~e�
��#������_);�9�.b��'��l���3���X��	�
����(���'2�^}t(-���K�-���G3��6N.�Jv�����T
$=�9�'
r�~����0��_�]����,���tP��TX�����C�X�^�~O@�b	8�)x>����~ph?8T���>�1Z��B|}/���SP�6���������'�����jC���[-zB��K�3������B!���}������C�\{*�\v�h�������1y	)��3�?��	�<�'����������T��yx�Ak�Z����E�yC��6�������6�}]t;b���X����,d�b
�g��]�|�u����#��n���h�>F�p��&g�c�^w������9���v��K�q��V�Z����K6�[N>y���f�F�CZS�������04��[m����4n����4qRm�r�(���;��5������Mt�����5d7���w��VG�3�E����{���=������!a���Z%"]�������AA���RX������v��:��!�[�k�v�LD�`���fI��w_�gr]�}W��2�Mh�JGg����-~b��}������^MY���+�L�uz�g~���&�Z�j���M�oF5/�v�}��<�%!ZS�Qv�Q�m}t;�g��]X�n[�������S:;�o�����Xj��������I�6��=��z�.�x�����a����j���E�n��Q���K�;����V1��mXv���,M��^��s����@KWQ����5�.�B!����~�Yf�Zl�u7�����0��G�[����V�/�|������Z�N9��d�J�#)^^IrO����l�q7��s��TT�
�m�0h����L�;���[�����]�j-�B]S4f"u�������� .�$N�S��@���)!u����$9�&������5A��3FP�\�>6W��JL4L�E�`
�_����B%.GMY���V��)�+5��g��m�����66�\�Q�D��F��gm������V������;N��Mg��]$���fs��m(q�E����I��y&}��I1����)�nP�{�5����{� ����G�7� ~��"�(�Qx+
������|�n�R��G�f�����s`y'H|w�E��lv���uF)��nDY)B�?]o����l�`�T��TLSO�
�d(u�)��u�K�W��$8�6�vh�.�x9w��_caE"�;�n��	0i	���e����.�B!���m�T��Q����bF�U!�����z��*@��"�b�����������C^�
�$5~�+�����R�Ps9����[J�����q0F���'�����[T�K�� |��g�Ev��Q���z�����^���I����57���~D��C�T�h�bw�k�n?�q��1sK�}Qz-zs(���/�!5��l0���-�`0��b��h�D��)��35�/���ea�|�z��l�����3�R�3
�������$�m�~{�k��|���8UWR�w�-��b"�U�\�����:�3��x���!y�f��[R��+b5�/�g��0Z�1��
�1��x�%�.�>��UV@m����`����^d��Id���jq>G�H{�����N��	�`E �
�A����G���}�8_yg�����M0��g�&J[�k�]!�B���69��T����&$a��N�!�Im�N�!����AG����������3��@� IDAT`�"b��q���J%=w�����D>�&��w�I>g����M��I��2�O�R
|0���[����>j>%�T�����C���o�Q��v���mK���
�/_�d�A�b��A5�1^r���R��]�D�����t�'���8�(K[T��W�R��h�Ot�>���g�%fL@�h��*VqX�e����6��w��z�fN�����'1�hE����u7����|�m�
q�'�����2J��n����"�4�������@�{�S����pI�S���}�����lx�!��XkW��;zW���!Gu��,��\C�B!�B���_��u��L���>s�� ^5�i�%eo�5#	�����O�d��ly%�.����M�NZ��%�E>Ws��8���`4����������5���V�~�.Z����<��;�����=���yI��[�����d��,��w�(v����&����M;H/l;j:I�P�� ��IrZ=��K8VVlVg��r9�-����`0!=��6]R�������~&)@�w�/�g�[���g^uH������qT8��=6�o_j�Y�bOI�[�����OvspKI����J�'��+i���$g�mo�����f�`��\���9��'��m��.��B-l9�����!�t�D��G!�3	�_B�r��p���$��%%�0�!=�b�
�8Y��#;N����<�W}<q���B!��}���ya8�>[Xx�{��z{~\����`�8�hBh�Rw����O.d�/;9�d=��|���p��zCLhmo2-#���$�;I����
����k7;;G���a�k���T�����V�P��qz�M_�������c�L�d}���e/:vw�c��,��&�������3z�����x�6�#P0���[:��N��)eM�i����?W�fz������\�����(�L����[~xy	��o%a�d~Y�E�/>��S�
���&c�B6&��qR�]������B���?r��{�Qv���e����-��KX���p����>�{���b��#]1�Z�����hl^����s������^)q5�I��8���`'�n�$M�8��8�_���tx�4t��j9����:?e���.�OZ�A��R�|�����tR�>����'����c�f�p��3I8���,���X��T��J#o��,|r*���A���g�)&v��^��������������P�+6��3p0R\�6}4��w��2���e�YR!hV	�o���������q����-�9;a�v�8�<}��Xn�����B!������T�����h�L���2������K��O�$�y)hl=�a?
 d�2~��#g���,B�����C������4	��������O����{�i+����]������C������h@������i���9u�gr���r7����VZS��_Od��A�������6�><��u-L��[W�K!��'�����br���NiM��e��\�������_��W_d���P<�]�C)xwy��?��a�4���:K��5�-��
*C����<F���Y1h�}���o��X�����i���9��1��[�B|s����?��C�9������'����K:U��7�C��V|��d������H���{-^`mj'���z,�[[�_�}�-����k�L��%�����3��3��uoEd�g����q4�]��;0��v&~`IQ(�E���8���|��if}���>��L�'"8��c���%���H\�W��^���k�W��`�
o���}X%���������������4�0y�vB�7���}M%�G�~��oxc��>)\O <�r��`���4����v��s��!�B!<�X��+vcY�j����^q�����]�����~�p��W�����^w�KyB�����'���nv5�u0����~�ov5n)�s9,�NB!�B�":���!��T���r�u�A!�B!�B!��IrP!�B!�B�(I
!�B!�B�%�A!�B!�B!��$9(�B!�B!�?��z���F*������F�[yB����T��U�I�&�fW���f�����B!���pd�i1�j��W�a��U����i�B!�B!�B�[�u�9�9y��Zu��f��pv�Z�B!�B!�����Lb>t�����/w�����W�ZM���ae	!�B!�Bq���U�ed@!�B!�B!��$9(�B!�B!�?�u������������~d��<�_+��0o9Dw���e\�
~���cyYF=�#���B!�B!����6N�������m�!���[������M��L��B�{`LX�#��������B!�B!��o��O��s�[���u���B���f0�+��ga�&h�	��]G!�B!�Bq����9hM�a������5M��=gA^����'6
�����W�..S�r
>|z�����	����vx���'���0~<��@�Zh�=�
��g���pG��������v���&
��A]%h
	;�����&�_���S`�z�8������!m
��~N/���y�l$l�\}_	!�B!�B�rw��t� +�h�A��u���W�������+�|
����APx�m�lxl!����
�6������0$�UN
������&8�'l���x��5������$<9	Z�T0�/�w��d���@d���5yg��
n?Ob/d;���Q�R ��*��C�i�t3����X�*�AcI%!�B!�B����O������N�{>������]0�wx�s�������X�s^�y�t1���wm���s�[��;��X�j���AG_����@���3/�G�������xR��\P��r_9���������.���/��	��~����.~��9<���C�����t��B!�B!�(W�r��)���h���n��������q0"�
��.�[�v����n��B�Z��!HU!T�?v;?i�[�|m9�|�I}.Gu�s�YJ]V���uU�mHIk���!h"�<
�"`�8=��<�B!�B!���n���>��^y@m8t�[�k�������>|
>v��:@��lWr0#�����>A>�����,?�{�7�4\���2�����A�eF:1��n!�t��6B�.P�V6Z!�B!���v�'=qn|�E�����+P����������.� ��h0Af������X�=��|+
O��T� �T
Pxk����XB���Q��4W��Zw��9�Ab-X�
C�����B!�B!���$5�H�I� j|�<��7�8�|�P_�� &
���bB]=5��.d'���b�/���@��3�X8�~
�l\J�\o����<���
4��?\#������u=����x{)�h�O�;� �6t
��2B!�B!�������(���������$���� .DTP����Z+��V�jmk�U�-����������nj�V��>T���TEET��}23��{h��L$��s]�d�9�9�33���u�}����r��C�xv��|�R�o4�'�/?���]GB~.>f�����pO���p��;���xs.,�?<:�{�#������`��`�BX���f�0|f$��Yxl
L*�����S��Y��0�f?
��{JzA��,�)��/>��������������H8�z��{�������y��W7��,I�$I������Us�;s6����7���~;�?�S����o�	W�N1{2�\�>
��b���H�������^p�����]7��$�	N���f����%p�7�G;�1'���Au���Kg��~g��	���]����g�����x��yp���_Q�0����XY��c!�:.�PI�$I�$m
�x<������������Ofr��6��;VT��jt�������9�	��&�u?����?|n)���%���$I�$I[��X%�u�	��;d������ o��"�#*�7�~�K����������i��$I�$I���[�E;�w�J�7����������v�JuH�$I�$)���:@��\����$I�$IR&�K�$I�$I����$I�$I��I�����<�`Ht��0�C��$I�$I�����j�}�x<�j�AEE���m�\�$I�$I����VNy�����E�,`Q�7:tLI�$I�$i[0�v/�D1�`3�����v=�xrq�m-��qA��%I�$I�$mk&���$�$I�$I�:)�AI�$I�$��2H��7��t�g����0��i�v��^���zU�NU��zX�>UnS�Z��!�qmv�����}��M@k?�d
>[	��\��9����6��K=�$I�$��3� l���Nn�J�M�Q����_���0�����y�~��0.�@����]P�������Z?��#I�$I�:�v=�D���0L�BpHJRpa^���[��O�P~V��{�BM��I�$I��l�+S��:���V��*8�V����C�J�]��W7m��N����q8�F��~�`B
��lU�%U0�n������up^�3�$Sp}
�\������|gh6c<T�j`N�W����He?V[��@(	�2��\=���}���^�pg��K��������	V�ez������k5��,�����u��H&������Ix�.�z��r����	�P���jm;pk6�O6�$�ph%|���
	���l�YK�$I������r��8?g@yV$��$T=��Qx��0��/��������[	��+"�x-3k���g����o��0�N���Q��nsw-�(	���zx8���H$��
���
��� $��Xm�4	���P�up^#����av\X]���t?�$�]
�����%avN�Q�����z80~�%�A�XX_Jg����m�9�0�Qu�5��V�������<P��`~m��~��'�E��8TF�$}��qX��Ylk�$I�$I���;���p.�Aa�����B00���JC0����Glx�~Qxm�������G�{� p���4��0#gw6��]����q�{��m,�D
N.���5�K_�r�l�RP�
�1����C�������I��W�06����"0�
~��������)�C����Q8���d
~�������������6���e�l�^&��nP����}�A��m#�~�������'RM�����G����I�$I��O��{[��46��
�L��h�6��u�u�v�~����Jm��uP�?
.�!X�
���%`�o$�zD`�6�����l����8����i�P�_@Y��4&`n
&D�~q�L!]<}��D����f+�G����R
������qX�����|�[���i�3
�)��M�������$I�$�S�����ypS,��;�
���� �t�\\w'�[]��b�g1|6��L��b�B�M�^M:����
Ai�Z��g3V.���`<Z��
/����T=I��`ef��4�����:������`���UAh��ozC�j�2�.��=�6��
���!��P����q�x*�8b���I�$I����{[1!8������z�Y{G��Y!��-	��	��I����0z�d\K�����:V��x7��r���`�u�6QO(�6;}dm*8	y��n���	Z�e���i!���b��{m
������`�O�=xk���Zx(/5�������$I�$I��,*
��y0�����S]��V�e���N�-����������%���[c�����P�mx�J�T*��;:��Ex��k�4���i�G`�����0"�o�p������������
O�^��P�6�#�Km|�r��V~��[����)���!��'�R�i^
)I�$I��d�������_��F�Q=,����	�N!x��M��$|�~/�}Bpw,�$��zX�c-�0������T�l�k�aeF���#�B��(�R�m��aV-���5�
���4���-�4���pnC*������.h�4�cq��No��t?�|���9:5q8�������F(�A�fs�y��`���8#��J��$�����46
$��8��������Z=���	�k�9��$I�$�S�����#���S���_�k����AH.(��	8�&T�u��)���@q�V����������������5�"�e���cu�i��������C)�a!��]��p[������Z�5���#�P���
pJ
|�.Xi85����l��l����{
`U��
~G�Oc���\>|#��9��i��=5��*[
/�mz�\�~����h�V
_�g��9��Z=������X��[�$I�$u:�x<��F���
���s�x��'3�x|����w���6���7������[78�$I�$I�����8��Xf����}���$�6�*	pu�����%I�$I�6f��V,ic������"
7�5#I�$I�:WvF�	�NC�'��"pUvXU�('�I[�I�$I��-0������I�$I�$ujn+�$I�$I�:�v[9��'��i]�w���$I�$I��`vbN�����Tk
***(//oS��$I�$I��]��rp��#����[2�E%S:tLI�$I�$i[0�������Y����L.��=����J�$I�$I��L����E9���$�$I�$IR'e8(I�$I�$uR�q8��;z�
�z�����/��6����Up�/��m�?�L�T���7n����+x����t>���'��%��a�8����"���`�Lh����������u^�f����k=�$I�$I��v��N��~
w__�<y��������LR�jc ��+������0����7}��	_�
<��m�n	Y��v%�~zY�}3��\�$I�$IR����l�����!(�%������nk���}�(C����`�8x����~���p��p�Q��r�"o�cBod;���#I�$I��lm�+7�=FAh,�O_��?�&L�~`����7 �������s�c��A��.��A�#�,�p<���������[r��
�8v��&��g��-�����`�|���p�P~'$�7j�s����/������Ka��a�����s[U������Ko���v���\?����a�?�n���.�5�;����I�$I�$}�lkK������*����'�U������a�]p���������x��
��.����,$R��@����xf|��|e8����H�[����p���+
�=3�����1���Er5�L��������n����w�i?�q�����������G�����_���s,2��������`��p���	��#�$��	�;&��>I�$I��O��?L5Bu
44���p���c����c0���� $:`$��,��18z��k+����������C���5J{��~�
	�������{����������V����G{���r� <|�J��'�>������,�
u�b�@�AC�O��ys�dSO�+?	N�����|��$��.I�$I��	l����a���!�/��-(A|�k���6����0q�x>4�aP	Swh{-����o���
���1�8��:���&�$��e�-=���p�-�{6y43h��*��1X���ou���8�<Z_�=���Q[�2I�$I������e���A,����^M!\������BPZ
�P���`����1��*����h?���Go�&�G�������@���
���U?��n�|���U��O �RM/6��/�-�z���1p�p�p�)�����gaT���%I�$I�>���p0����V�P!k�3.�`m�u��=j�.�9��J��mpB���H���������AUp�����+��&������9���<��U��HB~V)nSbp\9�������=� IDAT��o�Y���FI�$I��O�NvZq3�a�K�{%}�/�s�Y�G�!:�!dm��o��S�����U��j[�'����do77v���~�a(�
�W7���,��6�p/����f�u�x���,Hke�9�q���E=��]��Kn�{�Q}?���$I�$I�:�;u�3�W~�O=�.��]����?���S<�'xn!,|>N�S��0>~{,��5o�%?��-%�Q��z��9x�ux���v�8�p��xp%�}��O��`�������9>H0���o�������/����)������\���������W7[����s���z���������C�o����$I�$I�|:y�����`'|J��������B�90����p�k�[��p��P����^=����\��`F)\zz��z�C��<���x 8He�����a�s`��pp���/���'����Y3�/�p�O������Z���`�0�hh������2��1����Ok�d����+���>�)��$I�$I�B�x<��r���
���s�x��#�\������J�t�x�$����5������%I�$I�>�����dv�"*����}���$�FR��������p����$I�$�S2T'�k������3��q[� I�$I����pP�P��4�����$I�$I��:��$�$I�$IR�e8(I�$I�$uR����#O*R0��
�v���$I�$I��`v�&�
���P<O����������W&I�$I�$i��n+�T����n��u�XT��C��$I�$I����0$Z@��+���]O+���=���Tu�X�$I�$I��fr�n��y-�{<�D�$I�$I��%I�$I��Nj�g_C��A����o&7l�0FL���6��x?���3�x�l��W~����a����aY�����R���w��+�vV�RU������a�Tw�}#�m�Y~�z$I�$I��E��3�	��p��`H��Z�+�m�.T#�@�fyi�?��^h��e��<F6m�+�O�H>7����3 ���Z�\
��S&��=r�?�y%���0�=8�T���^>Fl�z$I�$I��Em�� ]`��0&�z��8xd\oD�w �!�i��l������S���p�#��)����ud1�����9p�50s��7	N=	�B-� I�$I��m����8�����r����v��v��jX���V��<
v�
��[�f�>�=q	��$�8	FN�=O��>�u����a��0�~����&�e�6�1��p�W`�Ca�ip��-����JX����Q(H����%�@��>�y�� w��*4�I.I�$I���mkK��A
���2c�`������x������[�!��@i,��?��	'�
�����K�
�����oxob\�
N�&\�=��������`������=�����`���/\v����'��oC�o��fcmJd ��k�5�g��9�z���^�N�#p�:���k��������$I�$IR'�����%��#6�6���!�������AG��M5Bu-D��������06�q��0�L��QA�6q'x�p��p��o�5����>��a�����5���0�O�BBp��px��}������9p����'��w|�v8�)(������JU��z�����
�Qg��3���=��-��Cp�W:��^�$I�$)+�L�
�_;f$K�o�}{[�(��h�E������4��p�MAX��3n|�����;�A��^K�b��v����jhLB���	��f��|�/������_����c���7����#����{�<x%�M��uG`����7aE���^�$I�$	:C8H>�6f��t���p�����`h��0,YU@IQ�
!(-�x
��a@.��6]�j�����}����[/�&��o��D���������g}
n���zv��-5��u�����e�7	�a�|�$I�$IR'�	��mL�;��{pZqs�B(*�3.�`m5��A�F7��H�������������k!�d�2��.��S�����Rs/�
yQ8�������0�U��$I�$I�������T�~�m6m6%2FE��9M��V����Q;�!��!d]��o%���^��^�k��&��M�+U
�kv�-��2(�[�gK�=������s�g��i9��$I�$I��:�����j����J�^����,���(�=�{~?FC��00sl6mZ��L�3���By/x�^x��dJ�Qn�7�X�?������g>�F����'�t2|W�|�S���W�C����oL
eIx�1��0����k��-5�po8��p���w
�#�W��90o���N���$I�$IZ������f�����CC.;)��� 4��|�\�|W�u!|��u~���i���u�n<�8�x$�_G�h��
�������3����g����������0�P8���8����65��p��P�2����5��:8g\<6�z�����
w�o��t������GOJ�$I�$mB�x<�Z���
���s�xJ�O���������*�����$I�$I��m����V�7�k^�b��Y���WJ�$I�$I����$I�$I��IJ�$I�$I����$I�$I��IJ�$I�$I�T��:������{rZ��S�$I�$I��^dq�w���P<O����������W&I�$I�$i��n+C&�W��$I�$I�2���!��T�6.��|��$I�$I���\�=�{%I�$I��N�pP�$I�$I������K������������~�����'�C�������O^��'j�������-��[{m�&�&��@����%p� 8����@�$I�$Ij7�����}!��E������q ���X�8�a	��m�`�~1�p��V�`�`��j���K�;� 8xKOJ�$I�$I�2:>���I�� ��P��>�W��vX=����W>��.!�m����p`�������7���0�w��P�$I�$I��t|8����@%|�"@|n]K���8�/�0d���v��	����CQ\���&.��t��s�����,
���1��^��5)X�
���>Y����+ 	DRp�+��>po�`�$��/���p[o����������8l0|��a��$I�$I����.�"P�N���|w%�0���3K���x�l�nc5\����ey�h
$SP��k��7`��������3�x�
zu��B��_����1p�'����*`XA:������0��xs)|m�Y
�M%I�$I��eu|8�JAM�)x{�d%t�c�A�v�
�} \�Cp���"X�*��1�o�����p��pl~�zH����E ��/��A���k9d(��z|	�	���#z�6�x2�W}�[+�����@�.�	]���`�e��*����$I�$I��Vt|8��#�Q�����'C�h��7�ptIS���B���p{m�&��e��~�����I�;lo���Rp�\�+���+������&a�!��tAe#�����$I�$I����i����~Ai>�k
��	�J2����k������`8
em�#����AE>|{'�5/x6��s��T�����apb�p��.Y�����6KCA�$I�$I���m���c���`�os�����)X��X6Z$�au_3���D�<>W���V����gW��7�����}���V�p(X��)�k)I�$I�$m9m���G�v���M��Rqx�v.jC�
B���d
�@IF�5�������aM<�U|�����p�r�M_+���xS@���w%I�$I���l[�`(3z�����s�����LN��{��<����b
,���t/V{��OK��$T����AeK��_������$Zh�1�S{��������%�t%��*����8��H�$I�$I[��L
W��g�Yo��)�l���{7�������9p���u�[�<��NP����.����M,O<rL���������U�=�/|&	w}t���b\�_�6V������/I�$I���#�������
���s�x��6%I�$I�$){��.������v����>��I�$I�$I����$I�$I��IJ�$I�$I����$I�$I��IJ�$I�$I�T��:������Z�$I�$IR���&�v���vg�8����$I�$I��af����n�`��#��kI�$I�$I���P�m}��$I�$I��IJ�$I�$I����$I�$I��InI
�`�#�h�}�OT���Q_Y�>�H�$I�$�Sh�I:�P�w��P��)�[��$\�T��!I�$I��N�ppK����z��!��HB����$I�$I�v������nx��AiW8q8�G��9�N}z�
?\K��E��7���#�Pls��WW
?^+R0��6
�)���<8n[��P������n�&K����B ?.�C#M]�}NZ��������;��j8bw�A_'��F?�m�eD��]���!�Bim�����~�:��*cp�NP3>�	~5�)����?��w��5&�;�����������_��pO_��Bx������P����	����wh�'�
�7>�^���$I�$I���u�3_y��&t?��T
�|����u�Y#����p]p������z�,�H��w��?��)��������� �C�o�
3��#�W���aPT�RMm����Gw��M��X
;��/v�;�@��noxh,������a0<y0�4������F6�O6f��+?��w�G��E�D<�>r���.}�
�?f
������0{)��h��R��+�K�+I�$I�$�����:���yg�axz��PU	�]_\�q|�#��u�q\��8v����������0%��O/�|*�H�����L��=��fm"Q�����J�DK�� Q�W�g���y��9A88(���|�/�c�����������������T=�~)�9
��^�96
�=������d=?����!�M��~<�j����<�F�����GI�$I���X��lXsR0�OF�����5�2�tm��0b%��*�g���O
^Z	��`���uDr��v�����E��:�Im�����P��(��P�#P����v�J�yXv)��+�2�q���7#QR�}�%e�k�?�\����-������#H�+�q8�o���%I�$I��r��!8e����2��R�*�*`���"�ph<���m�gm#��}��>�N������<8td��uV��gk���fns��p�a�P�)��E������d#T��`�F6�����	�A�&���Q;����a�R������^�$I�$I���p�(�0�3l��+����K���0�+��:L�B9����(�m�F>���1*������	���1���v�*�Uq�{j(�r�c.�skBQ(�3.&�*�a���3&��zZ[�8a�����9�������H�$I�$�e��8�v��u0��e�
-�����p�<8~�'��.{7���'{�����_��H�q[0@a!?��`Y}��i��U�|}�	xi
(���F�����*�~��-��C����1���k�,����@3Q�d��R��W���?�������<J�$I�$�U�r0��:��y#`j	����U�f\?")��5x�~7
�0s$?��	gt���3Ca�p���t8���+��.p��,c��7^.����W�]���[e��������lU-|V�������Z�}������6����~�����������z��h���f��������
Q�����5���5
��e<2����b���R�P=�s?�?���l�LII�$I�$e���A�=G�m�p��pn-��`�����AX��=�n�=F�����������	�sx��@J]7ny~������epz��K�`�Rxt	\���`P7�lo��G���Td���b6\�������3=�Z��B8u,�\�q�#F�_�k^�:����{����|>�8hW��u��u�'
G����Gm�gT�O���p��0iE�����T=�������v�$I�$IR����x��l+**(//���7�lsQ�S~Po�w��
�9H��'a�N��![��7����m��m���$I�$I�jR#��m���>�5��ve�q�`��`P�$I�$��0]��G��p����\=�h[�$I�$����Jb-\�.����:Z�.UT�7����Ds���cq�1}<L�z�K�$I�$mo:g8)�������::��%I�$I���K�$I�$I�T����sF{u-I�$I�$ih�ppf���kI�$I�$I[@������k��%I�$I�$m���3�YrZVm}��$I�$I��IJ�$I�$I����$I�$I��Iu`8��+_�A�C��1/�yK`Y�����o��g���-�����r�RH������`�spO���F<%7�V�$I�$I�N�H�I%ep}_��`�*��=X��Al����=K`J7�7ow��xg,����k`n�mOCQ]�h��$I�$I�Nt|8��u���=��.�^��:��mJ�+�]���<xz��
^X���be�H���Q�$I�$I������B��<	D�$��.���O@��p��B1�/;L��i����|��\5��>���>�|��@N
�J���8��6���yp� x�-(�n��T�#o��Sp��}x��
�����< �-�k���(���sJ36no�fV�M-����	���u0u����~�!�\�S0�+�9x�����0������pd����ex�U����8r0\�>�,%I�$I���m�ppY=�"P�N���.X	'
�������yP<�J�V�>�W�iC`j>���T��tAqw��4���a�H�Rapoq����������a��z1<����LT��
p�p�<��Dz��K����p���+,Y����=��.������p�JX��
��1�:��E���\�z�a��p�<(G�?��;�S=�~���?�7�������0���"��>o:(I�$I��t|8�JAu"x��[������'�
+��Zc�����&����+��~���U)�o��B�R8<c�P�G �V���`@��u$j���P���3Xu�k
X�r��F��npB��a��/�7,�Q���O����7��C�k��y��2��]��z5{�����o	�}���{����7�e��lA^\�3x&a����2x�
>����$I�$I��������V~��vy�Z��p�(50?	�K�*�`�� \kL_^�50��w
T�����jX
���ZY	��D�-���7�^�^I�!=2�����W��k�`j!��*8H��7T[���^�������_au����l
,J��j��i�v:<Z�$I�$I���_9X�n�y���{C���d���H�
!(�@<<C03~��_.��������]���6��]3�
E�x�`8-��Q�
)��?p]��T
RE���>��j>h�������>������d������uX���3���5��[�$I�$I�B�����U�V�\8�@e"�b
�&����p/��U��}���w`l78���}-�	f�.�A�VE�! ����(
ya8o7����A��j��~��"��q����Ww�c���u��$I�$I��5��&R���|e��T<��;���(�(N�����fo������pE�S
��l�F�v��c��_cB��!x������C�VknE2���D�:x�pP�$I�$I����g
����p�������S��a�I��(���8�z��_�[Q�n����<�1�/�ia�������.pR7��]�%{���K ��	-���}��� oR��W	���M��O9��[�
�Bp�R�4
���w��Y�+��hh�����$�0���~H�$\%�P IDATI�$I�:�m+8h\���{��.���kj3��(8�cm
w�+F����z#��ap�{0c��SG������v����_.�[���AP�V�<�\�w��������-�;���%����}����U;�w���@i7�^o�o���^��g�&�����sF6B"I�$I��N-��[=���������;~�6��4V�a�����srX�'I�$I�$m#f�������j����HKV�_a�b������8�`P�$I�$I���F�g��/��6���m�`��.L�$I�$Ij�;��~�ckW!I�$I�$m��7�$I�$I��=2�$I�$I�:�v�V<�����Z�$I�$I��n�`��%K�$I�$I�:�-�k@{u-I�$I�$if
���������$I�$I�:)�AI�$I�$��2�$I�$I�:�v{��F�	8�C��
^�C�3
S��] ���� ����p������CQw�Y�z8v�B@,C�������$I�$I�$�#���F����L�;up�j��7�t:�
:��Bm^W����0���$I�$I�x��`BA��n�XV���s��F5(��`������X	��
��C�$I�$I�@[?��	 ����k��jx����_|���m��7����D=�J��t��6�M�����Ep]	���Z�U���D�s�0#?�4���!�VS��ZX�)%����v�d�^��AC����51���`���X����M�_�*�����6��G�$I�$I�B������ ���5��$�/h�dqz��b�-o��M+�Ko�I����W�"pj��u�b�����8|oT��3���*��*��+�����p�*�����h����ep{)��.Y�����z^
w���n02X<[qR+�C*	k�A�����\=�$I�$IR:>|a
��	�
��8��iU���p`F��y�p9<�S���V�3��=`�t�66�f����1x�����J���	��
�w�Y]��D>T�?{�E��q�=��M����W)
�QA@@�"`GTAAA�vQE� ��H�Q�*����-��c7$�����y��s���{?sw�'��w��H�.���c�����P1*�$�:�'�s;��4h	}=�Q	�u��{wx��t,��X;�
��^��8X3�xf�O�w�a�Fz��T'|K�����<�e��np�9��t�����������)'a0)������w�=
u���N1�c%l��%1�����i�t�g�v���!�&�;��/C��b4T���
^�=�PDDDDDDDD|���`���iu�!�	c�g Tp�'`����V����	8��PB���Z�
�s��hTM�w�^h�s�R��n��c�V��L0m�Df8�w��-��o��%�4,z�zZG@W?8�o'��xx;"s���.V�����������
~C�260Sa�	e�a��F@���L�s
�0<�`�7��X@h��g� 4	���9���Z�f@�"�$�D��>��
)S�L�3MH%[@h@��33(a����m����7{�������V���L�L;O����4��-1�k��4��}��l/���������_o[v;�v�=�����S������6��pdKw��KL��M
�2�$b@�	���p9a����������H���p0�������4LI���P�?�1��D8aB�����l�hk�@c&��y)�>
���I�	��8`R"8����S09�H���A�N��J���n���	���.x7������R�ogu��h
,qB�>���>�!""""""""�C���xk"<���p](�+����NC�D��	;��-�=�~d�XaL|��A�	��pg���N�
�a	�i��A�p�d�w�`��,P���\$'�i�H����G!�-C�������ZI�y2�
uC����7��)��y�(""""""""����q�u�K�,�m��9oxe��.JDDDDDDDDD.��r#]���-�g���������H�P8(""""""""RH))����������R
EDDDDDDDD
)��jx\�y�������������<}�.YDDDDDDDDD
F��������i��q�3�X#���3EDDDDDDDD
)��"""""""""���A�B*��9x�)8��,V(Z������.���<�>{*�w�����aB-�!3�Xo���	u���P��y���VC��aX����}���������'���5���*�v��M��G�OU��R�������m�~;K���������'hQ#��|�KDDDDDDDD�8�F��k���	��/��U
����:���������u�g+H3
�4)�
8�3�f�L���k`�j���vA����3�^�(fH;����;��������K��w���	�f0�-����o��-�!����T�>���&�_��]��������2&�������m����+K��x8	�>;����:q
��1�y_o��,�k(�����Y�<�����7�_�O�Mw�����74�o����
����F`���q��Z�y��
�h�q��'Z��������\��?t9!9
p��?aq4�����=�HMx�D����0y=�C=m������&w����k��n-un(�v�x���2�A���p�2h�^)�6���@�p��y���a���m�})��U�.a����f�!���f/�<[���zk�7����mP?�������yz���{������<�%B���T��.���r`��P�.X8v��G>����'�����������H���p��y�d���
?h���.3��6]�M��������;����c�_x�>�)�s�aU��>7ts��gf���0�3Dx�A�i��
��&���DeH:s~��f���*<ZB�����r�ct���������sU�����,E����w0p���5���p]�w,�P"
�i`B��dT���q|2����5���\���.�WV���@������@��`��fEDDDDDDD$o�8X�5����d�v��0�<W���������x�g����%���a�.�
M��n��-t'��Y��
�n�"Y������.\'�(X���0s?������*]��������a����\�Y*g���M�u]X�~��V�������-3�.9>Y��+
7F����*[B3n�
�K�G!��cEDDDDDDD�����`X���'HkP�N��E��&TJ���K���>P#�n�9�e<����)r���qp�*T����u�d>'09nx�e����
f)H���g���}HbJ�'��|���eZz~R��#o�[+����}f����%��!����:��C�����������\����|10��}n(��$�����h�	i�J�r��	�������Zc`�]	}��j������=��~Z��}���,����zjHqpfw3R����dP����' ��,���/�s����61���b28�����|�y���=s����������\�
~?�C'���cn'8������w�G�,P�"$n���g���\f��7��R��g���y�^j[aW<�/
�����<��%�"��H���C�;K-f*�V+.�A!��5�z�Nup��''.�W�6�V\�`���S�����`:���J�x��������H��������<�w���B�=A��,������ik�?�.��lf��|<7�Ua�X���'��B�;�����_���`������9`�Z�G<l����K-}�L�wT��~�6wCM�o��2��<��C���<����?a�	�����CO{P1~Y
-�=;�EB����������*��
�CCh_���s�xF/�{������Tx��6#���8��rxp9X�7��[A@8<��~
~����-t�
vgi�	/>3��s��J��~�^x.��$�jw����%�~G�
3V���`�J�K���4�Ko8�9�xR���p��,�DB�&�����o����%���0�r���0�vx�;��3S��PY	,>���.�@�[�����d��w�wx�%�U��P��\�(���*��3���#�S���d���m���7�v�E���/��]����W�"u�Bo\���.���s����������R
EDDDDDDDD
������X���]���������\&�)����������Ry��x\��y�������������<}�.YDDDDDDDDD
F�����zy�����������\���a����z����������H!�pPDDDDDDDD��R8(""""""""RH�o8h�����o(��n�{�&w����>�	�w���.DDDDDDDDD�wy�!��Lxo�I���N���`MQ��I�"""""""""�)��Ag*���*��P��p����["""""""""�����8�e{��#�kV�������
^O��+���2�a�)���o�Z[�+8e��E�.�� ���������y��wIu���0sr�	������F��&��+���������������?T��U��p�8��@�(x�"<o��w��=�����.�aI�
�@�0�����l��P%*������c�y	��<tF�<;`���u'!��Y>�������YDDDDDDDD�"�oY���/���OC�?���@�lB�^95���E�	)��I�_�{�������.���5��u���!-��9S�'t
k.�u)��=�J��hO${c l����m1`�pNF�
OG@�0�����0�D�>ERDDDDDDDD�n��H����:L/	m�����m���zKK��&t
���0'��l������}�	�����&w�i�o�v����8Sa�	��3G�����9�>���B�e��N�I���+ODDDDDDDD
���gd�nE=?)�p��rz��$'��0a+���:3�M(�����D^����P�����`Q<�����s��K1]��[�4 �
�n��,>���MZ �c-��s}�e�(""""""""�N�.B
�.��D$�V��Xeh�mR�a����m\h����������A���;���.��Bp:��!&����>�������FK��X!�2��B)���.8�}K]v�C���P��mN����T�g�������P<,8
�l�>0��\������&en�b:aU*������aw"�x�����\ ��b�""""""""���3���_(	m�!��?Nyv��W����
F�;��1��"��'	����19��R8T>c�C�H��e6�%��2�S�g��3�����H����@,=�,05���rNF����!x(���\<Y��@EDDDDDDD�*����`H�2�Nz6�(��GB2�������'��gIm�`���e8'����^I������������7
�k��.�[���0�
%�����5�����P7���`�`Hy����EDDDDDDDD��p�;a��%�m�6�
�w�E�����f�^����^�""""""""r<��A�|:W����������H!�pPDDDDDDDD���W&�,�"DDDDDDDD�?B3EDDDDDDDD
)��"""""""""�T�-+<,���\�g����%���������H���p���4���=�����t��9(""""""""RH))����������R����:����S�W�a�8G�<��s�o�y�~N�G=�n��o�C���7�U�O9o3�$��
�/}���������\5��`XL�����0X������.�������h�2�W=+�9G��c�`�q���V���U���������\	�l����C�H�7GCH:�;�KCC#���O��)�<����X�	kc/�=[|��5��������H���p0�Z!@<uV�
���'��J���
�#�d��s�w�� �
����	$��; �{��
0��>5`t8��z���&,L��*��|�
���q��y�����#�>�L(��C�\��8��-�w��A�g��\�w��"0y?�K��U���a���`qt��%�pSX�%����v���:-0�!t�Z�	��������i+t(������""""""""�O
><�X!��H-�
O������V���!�Z�h���� �:}��M��
�� ��HB����L��[���po���[f��(v
<�w@�k���0���r��D����� ��-'`�f�:�r=��������
�N���X��=n�$��>a�v����G���p�
��`�
&g����*Q~���S�y��?�G`wE�W��vA�p��tPDDDDDDD�J����iB��L�SNBd4\k�l���	�SF���k������}I���I`
���B @8����a��Vp�<����P���Zl��#��0+��@]��/0���*��v�0��~��N��c�Q�;�3��jx����	��$��(�.���vB�Zp�������[���P}/�aB�H(���}�/���t[�Y��a��E<�$,R���[�E.�������c��X��R�0�<��d�����2��6h3���g�j�@p�q��k�
���y^������G0`�@��M�����>�>�����p����%��IK���04:��b@�P��'�bY����	<���
Z��S�Dy�$���/���2A�Q��3[2�	�!�+S���aQ0�$������ ���$ ���B��py��g����&����A�r�|1��=_��*�K�cn�t��������`5a�?p��l&7�IvB�	S����7M0�=K��eI�,~p�=BZ������z_����f����������\�
`�b��,��.c�^�+�A\`����rV�\����_��wC���"��r�?9����5�{���aw�\�'�lVn����a��������W����'N�������,�{� �j�?�3g���=��?���;KAy��#���'�L����mzv�
��qr��H{�[��5`g:T�,U�����0�r]�}���������N��V��a�����0�
��������E2��/v��hEX}v������Z�p������6 ������B����KC@*��������z,�pq��ipK�;`k<l
�)%!������}��yv?v8<��M���L����DDDDDDDDD�xW��A���X�m�MS:�3��&�������V���g�����3+�E��
��/���{-;���'���~;D����2������0��:l�'��J'���O���r���p�Zh������u�]������������H�0�Ew�X�d	m���y���^vQ"""""""""ry�Edt�=>�{���|�pPDDDDDDDD��R8(""""""""RH))����������R~y�����y�������������<}�.YDDDDDDDDD
F�����"y�����������\���#]f�O����"""""""""���A�BJ����������H!uu���t�9��]����������U��1��B
���O��V�/l6x7����*�_8�-�9�5��
��3�q�-!���3�qg��
�\p(�=������B�$p06Zg���)��Z�an:��*F��-��ZDDDDDDDD������].�	��V�4��!;,J�C�s�9!����P�l��	%��� IDAT�@1CQ�	s�/��J�}6x+����$��}�DDDDDDDDD
��]V��������\��j03	������,�����`�Z�=��7�a��Mx>6��<�0*���:'t���-���������\-����.,��6�7!��������g'�0��L��79��X����~���]���������f�!IF0g���
�&�+�0,�Z�
�'.���w������������\a�;���������=h��,��DDDDDDDDD���wC�K1Mp�Y�Jq��
EDDDDDDDDr��5s���R�Q ��aZ2$d{@`�R�����876<���]b���p�b��C��d����A�!nI�}'��R��2�pJL�vX
P����������U&����A�8��?,����
���<��&��]���/FqIEf;`�h�)$��g���������H�Q8(""""""""RH))����������R
EDDDDDDDD
�<��x\��y�������������<G��WM���������H.��b�BJ����������H!�pPDDDDDDDD��R8(""""""""RH�c8���/3���T.F`P�i��IK���Q;N6�;�N��Q2�{`n��?�������?2���T�	!(��[����p������aX��Y��=��Rr��s_���)���[s6j"���Y8�������N;��V�����|�MDDDDDDD�S��V|�a�}�E���1rM�qV��Ou�B��U<�����8��6������+R<(�����];���w&6	�<�5Cn��g~�>�}D%�u�������u� �y[�]�0�?��0w*����)��!)�
S[�'!R�\��~
�7Z�����N3lD��A��!\����_8h)N���@�����zu*���}���J�j�������~�2�g9��{u�v��O~��&7a#���3�Tf��9���L���[?��=�	C�3�,1uh��E��N����N�|��)�hi����
E���Zzt"""""""�g�qYq���FDuj��p��I�R��e�":�R�<�_�J>�������U&�-Z)V�4l����N'��-�<K:���$��#��p+*ES�N����Y+]�e��^CtP���s���p��yF���<���JEB������/�L\�K7���9V_��L����t�����!�h��'|�h#�GQ{�<����5��N2�?z�6��D��-<k���M��N�o���sx�MubB	+Q�s�v�������-	g
�J�_@�g���;d����G�T�4��AD�k�m��c����&qNg@�JDR�&�����,�~ua�����8n�S���0�����~���	�'(�45Z��$gk�#���g�9�N{#��m��#�KD��o/jF�R��������
��
#Yr�s]��;h��7��l�!%�w�$V���������1;7M�O���)g50{�ql�(����k��K��XV�[�#"""""""�@7$1�6���V�&�.*���IjR"��ne��gx������16���/6�R�A���^�4�I�?��eo���G)��#��p�`���x/m(��:��_�M����~s���)&�z�v���h?^��>z�:�}�=�f�c��m{�wb������/ysPiV=�������_�?L��V&������������s�K?���k���{x1a�M�H�G�2g����}i������p�lZ?���x�v���������/�z&�J���Y�n=?����n�T�G��$.��������|y�={���4X�_��M�>#��h>�v�����~d�7�s��=�{�L�bs����������5�W���d���������t��]f����t�C�1������Imd��@��?�1��g������V4�?x�F{������m����9Eyn�~���.m�����?��	X�2p�vv����~%�o�,�v�f����X�0���6��������7�or��6>"""""""R��y��~���	��5M�����]9����M��0��jf�Ov�����=nV�2{|��q����h&$$�	�)��m��k��zs��g�����7K��d����J�����0�a]��O�����?FV3��?m�q���:`�ll�0���Q��07O���4�\�~��M3���_���33���������7'l�j~���Zs���p�����i�FPK��}.���5���r�C��M3u�ywtqs��i>��S;�#���M����3�t2�nb�7{������y=�@#�l5m�y�;ry��av����������6��b�p�`Ne�����[i&e=�tx�����R#�~�������iny�z����}�s,u~o3�Z�|`i��s6O���8�\�3������K�C�]���������{g�?n���������7��i�-26�}�h��5��5��/�m:�'��:�5F�5�i&}����2/J>�v��f���)���h����2f@���������n0K��<���)X4s����G�?5�����]%s^��X7�\���?fBW_���<����S�+Q=���PB�na�������b���X���f=B�������9�&G�*5��33�l��_�]��gB������ko��*g&b�Q�ic�\��c����1oTw�T)AdH����q,�'�s:k=�c|�`����It,~�BX�#$�k(a�X�		J&!15_��f�ntP�ys�e�i���517�eS�-�m�����y��Eo�o[?�Y�qH�����rC��T����pl\�����|GC���a���Hc���vKn,���Z��E��m`��,���P�z��WEb���I���c)V�������}��m�R��W�{������!4�JhX(�LH0$%&e����A����u�S��������G�����������	S6L������g��Q������V�f�l���~��z��4f6��`��!�p{2������y��y�-g�A�Y�FM���y+n8������O�1���=�
&0��^kP�$p:��L�%6����j@��'����w�s��	�i~x�-��>N�Q��������Of�(��tr�����������'������@�X00�X,���j���	�N����,;�Z��HO >5{Y��D_�aD��og�~�W��$��)�&6����/�KE(Z����L|�#,��,��%,�0�g�Y�
{����nwf��I���=d���z�(J7���9
�,�ck����+���$8(�h#(� R����/������������H��������`��c���������h�R�:�cp~���.(S�u���v���S#���7������hS�UkP���-;P���h��X�l(oJ�w�B10�#���i1z%�:��}�@L+8V���#\����twEo3�lr%��l:�*<��WL��N��p�+�X6�n���xF�5o��!K(����>������%���Bf�`���]#�0�����m!��_�K�<k�DD�	��pA��tf��y(�x�������'�����g��>�}��ql[<���a�S-h3�N"�����g�:�9{&aw�qn���w�8�)����\)H�:s��_�������/������H��\7������wg�e�NZ��S�����P�$�-�S���4������9�XR����ATd�����rV��4�����U�Z�D���ll�|��U�Q�Z�������4R�
�#�3g�%�����	�0�#m��?��Qu�����|y�/���}�W�ul�Z����cc�/�`�i@�n�B`s�t/������w&�zw$:�Y��Ns�����y���
��	�O��`�/�8�1�.v.[�>����~���_U�=�����r��{��XN�fP[��qy;x;6�l�)�w�$v�r���k�=�v�RSH��2��GDDDDDDD�]���>���3qse�R����c��-KL=�����,���-��>�d�!<��Bf������#��m4�U��Q�|6�Y�����T��b�+���Cn�����Q7�4k�[I���Y���7��w3������?�T��������0��J��D�lC��w��i����~e�k�P�������x�k]������,�P��s�S�~=77�g����K��i�����q~\8��Q��<=�	���L�eOS7�&�Y.]su��(]����.���p(��������S0�~��
9���4��'������6�"�sax���4{�Nn5��`���������
s�qg��J���~���������x~�_�����|���i2=��I�;ZS��h\��g�g'�8�F�z���Ns��b���m\S��&|y��f��O�����4��|j�vo��|����R�jXg|��Z0�n��*���8�p�d*�y��TW�Q������#�Xi�ro|DDDDDDD�`�_8�������L<��!=���-{������3a	�9��iFQ�4�rv�~5�xG5���}^��q����������;"ZJt���������d�Q�~{�}5�A�-dLGt�y��:��a�\���~�/�?I��'�[��y��z��~���r�|�Sf>\�����7�������3x��=$�c�P�)���3��(E��}��A�qG�I�GV�e�gy����z���u>�I�7��}�;����[^|��}b��u�{7�G^x��	,����~�+=K�<��j��M��9���.k]��Z�����1�z},}���S�f=�b�7�����{�%��c��p�I��V��{>��	m�A���uh������cDW������
������?�^��E�wC����y�)�^��[�o���������p,�*������:+�5(z�x&/���-������X��Cm������#+83Awu�|X�3�������k�#"""""""�p8���d���m�_�x�3�{��y�5�>M�+z�b:�������l;+�����8���G�����M�<���J�{��M�;�=���\��[�:V���/���Y�����e#_����*Cy���A���+3z����=G
�
������!�
^JH�[������f&""""""""r�+tY�����������5=!ODDDDDDDD��R8(""""""""RH))����������R
EDDDDDDDD
)?_NZ�hQ^�!"""""""""��p8fA!"""""""""�O��EDDDDDDDD
)��"""""""""���A�BJ����������H!�pPDDDDDDDD��R8(""""""""RH))������0�Mz�{�
�s���g���_�7��\���=�<���_�7q�HY�+����I]���_yc@/&�p�����<����8c�����6��?���Os��Q�]>���b���;`��'�������6DDDDD
��h8hr���2�{�'S����;r�V&H��f�O���!_�R296�n�)q#/o������%�����I��p�5�v��S��t}wy�w���~�f%����!}7�X��X�U{~&�w�d��[9�_T?�I�:O�"5��v�g|�T�5'�0'7���h�wl<�>������?`����	w|�>��o����8���_��s�]i���O�������`[�y�t��T��Y������9���_������DDDDD
���i{���:�T{�7|��b�l��(y������������95JELd�j4���������6��UK���@pDq�������g{�E�M���c�%z�d��a�<�~�U�<E�[�Q�x�'m�u��������
/I��O����Y���L�V�2�����'S~�����5�61��c�1����0��D��;]��9��u�m���O��rT�Z����^�#�(�T�B� �&�5���)n��
�(������Y5�=_X����e�P�Ji��y��J�*U�R>
�������x����=_s*��4v}�,=�T�xxA�1T��5w���g�&����'����%/��*T���
k}���r�~?��������������X8s"c'���8�r�}k<i�Kt���f����������G��q'C���z��8}d7��@�+0��s?�����YI�;���3��^������H�9���-��GG����z�g=��g����������V�l��X���y�n���A�1�[�4���(���4v��+C�|�������{�u����}u�G�|��l��e>�%<3�2"i�P�7��[k�1����A+0�7������7K�.��s���L������|�?��]X+���e����c������7�~_N���;�h��J4�����t�5���3��&�J��?��OD$�����98w2�.JL�������-�G������3���3���	�,�[����|�c�<�-��y��	sx����y�s�6�-^�������;���n�<����7�g�l�)^��5�e�nz~6:q��U�{��+�,�������X�{{�C����+O�������n���>U�z�w�a������;O�A���������}��g�?�����/S�&��Pv��lM79��y�,����=(���`��]�Ry_�_�gj�����z�@�"!�D��Z������������1�!D_������3�/���s?m��J��P�C�����/����3��Gx�}06�
[@U���k���5�*#,(�����8��E�(��7�>�������S9&����������1�%���r�T�e\b����!�������p�cn
��'	�c��k�t���Q!��J����hf-�M3�{S=*��"$0����i>`\l
V�|�D���l�������l�~����Q�6�����g�K�:�'�6�r�p��W���w�+cJ����7P�x8A�!���{��I�Jw�����T0���[fg�����i[�$�!a�T���s������hxg��'$�$��=���2g�^zMN������)Dh����1��.p�|�f!e�8s��>N��z��.�<�~�HB	+Q�[�����w��zI���(Q�3�8����f��������
!0(��o��I�9��N��G����y�t~���5�jR��f�k�����3<��m��[:�BR �tz)I�	E�#��(E:R���J��,�! %t���P%���=����������z��k>lvg����{f�g��~��8:8S�r���${�qJ<�[?OX�����9z�p���G�yf�ux2��Y�|������@�/��w?���'�,ST��|��C[Q�����	m��_���}+��1��?������Y,�����nx<��{	|��)��qt�"���N������ck0`0����SOf���[(�o)�:����9{�[f-������r�g���,l�E�5R8�x 
�<q����;���<�y����~`L���-���%������gd����a�~�"�������������&�>|�����s��j,����u�)�_?���qQ�r����
�����fV[V�������y�/���/Ucgr���`NZ���Ax:��T*�&���[���|^Ic���$�q��N29��2��e����x�������y*�B!�!fj�~u�{h�db��j:������x[:��ry�7�\[5���2pt�[t�����p~�<�H��y=���z�1~���2�����3�:��?<B>�(��V��6������t�`���]
�Y�����D�7�E�1v�������?L���Z�P�L	L{{��7��l>AS}"�92e������'�������q����c	v|����	0@r�{4k=M���=:��LK�����IC\4fn�B|R����m
�6~��c:����t����;�����Hh�q�7@�	6������|�����8�Z��|�S=�����}G�j��E^IDAT�z�%����i2���A�c>��O~i��SI������P�cL�?��E�����m4�l�|mv������`����L>����|��b�}�u��L��-ht��XYR����{�~��Ne
<8�����I������=*����
z5��������z��X���x�\�_4�IS��-�ao<lS9����[�#L�i������j��u��X?�
^O������&��Q{�$���F{��0O������~�yc�rb<����Qh|�G;~��r���1c/�ac�Q���/9�X�R>� ��FZ�ZA�-�;?a������*��-`���N���o~l��fn�L|R8c���]*Wv�g��V4����18g��������E<5�u��Er}{:G��@��o=|��(������M�X�����������kQ�a����P�
�'P���,����7r`�$�eV�����Y�>���i�f��:�Q��/��KC���H����R��{���c�#0'�F����������Lg���)��3����jw��G��+����Ou-��2=��":4�y�e�7�b��h��U���{P��<���G�Y�?,���������R���E�����:=�^��cxm&?����Y.���.���'��=�t`�s'F�K�k���M��=\2Ae���{���+9�3j�fp����.���Z��S�&�eB3��z��:u�i�&$X��u���Ld�������C��B~�KG�2�W��k��k�:=�����Z�9.��Ujn�C�lXi4gW���^4�e��E�����b!�+����:����a�/��`�V�u{;~M��~/Mu(�S����m����6�'^!�B��a�V�F�����0w�����eQ�hn>���c�0���F�����1��#_f�	�4�U����1��J����|�|�o��}'��tye$���`�������e��������T.�z���_[����IV�:���{S��?�z������|��"s��F���9=a]&1����������M��l"Op�����Y~�3�������M�O����wI�r �t@�(�9K��X:�>�}3?�q,O�F�T�u���%�q?���K,��"�8�����:J�lI�:�r�9/}��L?-����T�W����FP�%�����4<)���'�������QVY�P��#jF~��5����Kv��E7$�O��P���D�#����_PF��w�`����l��Z�� �Acb����F��G����$������]W���h;�������	+��Q���������U���_�����`���P�����/��d��>�w=�p=����T��,�9?b��3&�7�b�r�5���=��'�"�3�������]���J��-�[l�����k�BZwB�FS�O�������nI��
��w>���K�v8��z����@�&�3�rLcj�GQu�|=$��>Y�iW�rA�����<s�������x����w"3�&�WB�6�K�M:��6�aT1 �Z6�X��'~:1��a������
|��:Qc;��B��4�;_,�Hl?��j�St����b�:=�V�dJ3���v�),~�;���C�/���k7ztoK�R��������;��s6���@M*�8���+X�4��h�.^�����'u�og���r>m<5�=^�W�i�7�;F����CM��M�)�o���-Q�x��hVh�t)����N�����
�U�
T����/�=>a���I,�U�ig���P�;=m\��9S�YTf�����J��G���4Z�F�"a][�V�e�����S�����U��Tq:����a��ZT+�,��g��>W�}���1����mf��x�R?:���9���<ESU��7>%��t_[x����9Z������y�j5[w���@���>��n%��`����{�DN���?�	!�B�?�O_�X%�d��S���5���f�2�y/M��Z����[����%h��n��g��}@;�8^�������'S�<��	l�l�.����rs������*�Q��>}��������F�z�a���$]�B��]L�����O�pTk
��J�fQO���1d����Il�� �!��Jj*�A�DS�#OA���`:~����b���^4�M��w���`t>���x+�{���r���H���3����lR9���SeaU1�:�R8��D���L��w��ei����m��Q�D2N�A*G'��\Z�p���GB�����W�vW�9���{��J >%�)Y����IMI�qKh:��m���5��t5���d����{.<])Op��������JL��!�����%��~.�[Ny��:�~o������f��	���X������������h�%<)�]��P��i��@�!����e�����.�����l4n���@{&����mS��5�I��K���"q�V�[�Jk4���	=;�`����jQ���n��H��%]U�k;=�������?r��~��N���	����Gy����q=�W&=����p�;�S�7�v��D��/g�&7:��9�W�E�����4���-,S�f�m�wx��2w��������&�86�:/�f���~sj*�A�6������3����T�	�1�������n\�������y�ZY������4RRxB��4s��Qn�*�|�|�	�����(��s�����=����{}�E��
���t6�S��P:{�e�����
�R���>%����!�B�'������?-������T�?���0pS���D�q��������}h�� �V"I���V����"����D� :v���K��,���T
46��j!����yYY �>��c��x�L��������������|��
�������	�=��?����0��i����K�F�Gv�W=;6�z^��L��O����lV�?%S��%�&�����*-�L&�Y���g���
tZ-dZ���3U�B�z���SW�}��/������jPJ�Y����{HH������h�7����;�p�<��
�������v?=�[t��f#_����V15����/���-�����6t�~����,�S�������B�������"�VXY�2��x<aJo�A�_�=��j�jTV�,l�Va��1c��+����"qs�q��"^p�|���P��O��zt!�vY�\�u���=?���E�D���X������|u.�_c���M9�p������48�-����g���CV��(�~���3w�Ig�Z�7k��C������%m��<��8��FS7u5C�P��n�����3�
<�R5J�4N��hW��������0�:�B�unX7�
�W�h:v��n��	-)*V�����C��f"O��f�J�F�� ���chJ��y5R��e�����)�z�^�E�-[��s/a-?��D����/�B!�B������jpj5��Gq��?����n
+\ZJ|\����n����G�j�J����q������:����K�[Rq�������a���_<�7s��	n�(��C�Idi#{6��������|��j�����H�����2��W	��	z]fL��a��dp��U�����+=[B#����lK�sc�j����r!�|�\���S�P*�Z�����<���?2�+�����hOD�@�h)^�8��qN4��4�V9���0����k6�W.o����Y���W������O*������aMpht�^���C �������Y�����x��-�DH�pJ��
h)Y?�~��h3�{n�sm�/F��]�7�3IK�J��2%�y�oO��p7�I�-,��G�8�kD�ikH�y(����)h]=(�{���W-��>f������"�3k���u��/S�����r��������0D�����c:���{J�e�/�������^+��yx����<�����������4�c���E'L�J���p4���Es�����N�\m8�R�;[xp�~��O�g��3T|}{r�o�/�����E���{�F����U���}�������MZ��4���������kR..����*��	[�W�G���;�Y��	#�!�����'g��/G�G��[��\L�9p0	���3�]"���T5g��[��A)��o�c��-O����
���Q5Doa�4`6g%-9�h�iKd�:V|���G��ygj4�Bm����}��*������B!������\�0�sH�������4p�&�)���&�tN���c�������P;q�6 ����}�{�J�����t�'����M,�d�|_�K�|n,3S��-_�I��
������*��>��{�`=c&��D��p���*�_���!o�����!�X3��vcb+��s�2N�����v��7"��#��5���	4����u�T�P4�fO�}������������rvw�����!m	/����G�i��vC{�a��t�c���!hO�1~�J��
�|�`AhF["�p��~8�%N-)q�,�A]h�U��O��8�i��xp�gf���K��������	�6�����R8n���a�2�����M��/�v�!��i����������I+��5�:��g����������i�����G��,�0�x�c��)����nh��n�i1������!���i���c�)�2]"���+�����_����\��=-N����������^5���������z�`�O�D�zF�c�z�v��P�?o�,a`�Nx���h��w�s7�������-����f��*"/�t�l>��qs��c=Z�w���>��2�����%����!`��������Zi�V���-8�^H{?-`�B�P�����O�����
't��}�b�<�2���L7�q�������xw��f_�"�O��M:	��r�dK���Bx�����B9f�\������
w[#;W/ao�.Ts��:����V�x~)C{����4��BF�E�x��;3�������@��}�M��{���b����j-���mq�9��!�h���hze������R�#�����f��'rII+�"V^�H��M��;�\�k3F�}��m#�������+Y},�����,�oj
i�u���]��IM�m�|�'���F�0_���{�&�J��j
�"�����o�f�a�kI��?�8F�
O�cS^�L�i�ig�.���������V�������s�y���u3����F���E<C��|�a���Z�V�6�6�np{����l���o'��~����?���������Yu_X�tZ�����o$n���6	�����nI�:�0�K��/'�A�}�X����\�Oo���S�U�v~����%n�T�,}��B!���F��xK���
�VeoW����P���������)���~E�j`�����z�������)�g�0U��VtV���GU��H�:��J5U�������3h�F�S;�U��j���p�Q�LW7��*W�fj�����?8�L
n�<����kU��\u�^�����M;��^���M�]-=����i��W���g��jz��%m��Z�P���T��K���rH=8ZE����<,�L�]��l������Qy�uSK.�)���:��h��ji�hm��yE����U�����v�UNYWx[��]��juWWe]�Cu6-3m���R�*W�z�*�UI�����o�W-llT�wr�������u-5�t�2�*e���c� ��j�:������{|��]O���}ux^_��l�:e�sU�j���vd��������������JY;���&���RL�����4S�6m��{��o�m�kz{�i�;��^}q<���5>].zoU�au��d���=Uh���������#���-+)g�7�)w����s*�hT�G������POe������*U���:�L��O���q`ye�\_}z2��t�]Q����j�uWv��sPu���GF�J��O}�7F�/n��l�T����Ow&�t�1=i�z�v�f�WZ��r��T/}�Y]O��?��z56���v�R:��r�P�����i�7�����n�e�1�/�T��������m���bj*7��-^N��������G�������������
&��)����kj����������W���{���O�K=1Y��.�z������RS��~2�=����>�
���F��O�JI�B
����*�x_��(V��pVM�����z]t��F���[���@�tPVz��[U��C�:��]�RT��q�Q:�^�������y�og����[}���
.ULY�
�����3���Uo�g�Q��P.�ze���j[���sUV��������U�r1N�2���M����n���J��S�����B�~���%�e���6YD[{�s�jT�C9�Jg��|*�Q��9�R
�����ST��������3T��VZ�;�����Y[��i���N���J����Tp��j����u�-��z5�]U��J�te�\R���TH��,�V��l�"|���N�l�<U`�&j��[����s��E�UT��rw�R:��r+SK�4~�:�bY��F�J��J
���\���,;���*qy��/�^��~������������:��]P�c��s��j����L6�d�M6�d�M6���7��h�cs~�5f7����o91�>�E���{��A-��y;;G���"�9u���T�������&���R��"}]O|������(���2��n8���a��qOV_�o�Oj�&���A���l8��>UB!�B!,��/y~K`��^S�������
Y��fw�����WS��&2l�]W����B��{�X��<��)���uh%�>=����!�A!�B!�_���Z0�TL��t-^�f����PZ���_Ga�-K��_04�����B!�W��N�q�$6���������s1s��$���
!�B!���o+B!�B!�B�O��	!�B!�B�/%�A!�B!�B!��$8(�B!�B!����B!�B!������B!�B!��RB!�B!��_J��B!�B!�B�KIpP!�B!�B�)�����;
B!�B!�B���������N�B!�B!���O����w�A!�B!�B�7�g
!�B!�B�/%�A!�B!�B!��$8(�B!�B!��������}
IEND�B`�
v7.1-Replace-OR-clause-to-ANY.patchtext/x-patch; charset=UTF-8; name=v7.1-Replace-OR-clause-to-ANY.patchDownload
From 9e0a0200525e7e72f1a91f658b4674fbf78ea18d Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 21 Sep 2023 19:15:42 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
---
 src/backend/optimizer/plan/planner.c   |   3 +-
 src/backend/optimizer/util/orclauses.c | 232 +++++++++++++++++++++++++
 src/include/optimizer/orclauses.h      |   2 +-
 3 files changed, 235 insertions(+), 2 deletions(-)

diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 44efb1f4ebc..80935cec7aa 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -67,6 +67,7 @@
 #include "utils/rel.h"
 #include "utils/selfuncs.h"
 #include "utils/syscache.h"
+#include "optimizer/orclauses.h"
 
 /* GUC parameters */
 double		cursor_tuple_fraction = DEFAULT_CURSOR_TUPLE_FRACTION;
@@ -1169,7 +1170,7 @@ preprocess_expression(PlannerInfo *root, Node *expr, int kind)
 	if (kind == EXPRKIND_QUAL)
 	{
 		expr = (Node *) canonicalize_qual((Expr *) expr, false);
-
+expr = transform_ors(root, (Expr *) expr);
 #ifdef OPTIMIZER_DEBUG
 		printf("After canonicalize_qual()\n");
 		pprint(expr);
diff --git a/src/backend/optimizer/util/orclauses.c b/src/backend/optimizer/util/orclauses.c
index 6ef9d14b902..805f4b7294a 100644
--- a/src/backend/optimizer/util/orclauses.c
+++ b/src/backend/optimizer/util/orclauses.c
@@ -22,6 +22,10 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/orclauses.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 
 
 static bool is_safe_restriction_clause_for(RestrictInfo *rinfo, RelOptInfo *rel);
@@ -29,7 +33,235 @@ static Expr *extract_or_clause(RestrictInfo *or_rinfo, RelOptInfo *rel);
 static void consider_new_or_clause(PlannerInfo *root, RelOptInfo *rel,
 								   Expr *orclause, RestrictInfo *join_or_rinfo);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static Node *
+transform_ors_for_rel(BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < 1)
+		return (Node*) expr_orig;
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *orqual = lfirst(lc);
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
 
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) expr_orig;
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(NULL, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(NULL,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+ 			saopexpr->inputcollid = exprInputCollation((Node *)gentry->expr);;
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
+Node *
+transform_ors(PlannerInfo *root, Expr *jtnode)
+{
+	if (IsA(jtnode, BoolExpr))
+		return transform_ors_for_rel((BoolExpr *) jtnode);
+	return (Node *) jtnode;
+}
 /*
  * extract_restriction_or_clauses
  *	  Examine join OR-of-AND clauses to see if any useful restriction OR
diff --git a/src/include/optimizer/orclauses.h b/src/include/optimizer/orclauses.h
index f9dbe6a2972..6a232aeb3ed 100644
--- a/src/include/optimizer/orclauses.h
+++ b/src/include/optimizer/orclauses.h
@@ -17,5 +17,5 @@
 #include "nodes/pathnodes.h"
 
 extern void extract_restriction_or_clauses(PlannerInfo *root);
-
+extern Node * transform_ors(PlannerInfo *root, Expr *jtnode);
 #endif							/* ORCLAUSES_H */
-- 
2.34.1

v7.2-Replace-OR-clause-to-ANY.patchtext/x-patch; charset=UTF-8; name=v7.2-Replace-OR-clause-to-ANY.patchDownload
From 84ba19a988447bd5e19132080375101e1ae2e63b Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Tue, 26 Sep 2023 09:23:44 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR 
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are 
 still working with a tree expression. Firstly, we do not try to make a 
 transformation for "non-or" expressions or inequalities and the creation of a
  relation with "or" expressions occurs according to the same scenario. 
 Secondly, we do not make transformations if there are less than set 
 or_transform_limit. Thirdly, it is worth considering that we consider "or" 
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
---
 src/backend/optimizer/util/orclauses.c | 295 +++++++++++++++++++++++++
 1 file changed, 295 insertions(+)

diff --git a/src/backend/optimizer/util/orclauses.c b/src/backend/optimizer/util/orclauses.c
index 6ef9d14b902..b4ac9370461 100644
--- a/src/backend/optimizer/util/orclauses.c
+++ b/src/backend/optimizer/util/orclauses.c
@@ -22,6 +22,10 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/orclauses.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 
 
 static bool is_safe_restriction_clause_for(RestrictInfo *rinfo, RelOptInfo *rel);
@@ -30,6 +34,292 @@ static void consider_new_or_clause(PlannerInfo *root, RelOptInfo *rel,
 								   Expr *orclause, RestrictInfo *join_or_rinfo);
 
 
+int			or_transform_limit = 2;
+
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static List *
+transform_ors(PlannerInfo *root, List *baserestrictinfo)
+{
+	ListCell	   *lc_clause, *lc_or;
+	List	   	   *modified_rinfo = NIL;
+	bool		    something_changed = false;
+
+
+	foreach (lc_clause, baserestrictinfo)
+	{
+			RestrictInfo   	   *rinfo = lfirst_node(RestrictInfo, lc_clause);
+			RestrictInfo	   *rinfo_base = copyObject(rinfo);
+			List		   *groups_list = NIL;
+			OrClauseGroupEntry *gentry;
+			List		   *or_list = NIL;
+			bool				change_apply = false;
+
+			if (!restriction_is_or_clause(rinfo) ||
+				list_length(((BoolExpr *) rinfo->clause)->args) < or_transform_limit)
+			{
+				/* Add a clause without changes */
+				modified_rinfo = lappend(modified_rinfo, copyObject(rinfo));
+				continue;
+			}
+			foreach (lc_or, ((BoolExpr *) rinfo->clause)->args)
+			{
+				Node			   *orqual = lfirst(lc_or);
+				Node			   *const_expr;
+				Node			   *nconst_expr;
+				ListCell		   *lc_groups;
+
+				/* If this is not an 'OR' expression, skip the transformation */
+				if (!IsA(orqual, OpExpr))
+				{
+					or_list = lappend(or_list, orqual);
+					continue;
+				}
+
+
+			/*
+			* Detect the constant side of the clause. Recall non-constant
+			* expression can be made not only with Vars, but also with Params,
+			* which is not bonded with any relation. Thus, we detect the const
+			* side - if another side is constant too, the orqual couldn't be
+			* an OpExpr.
+			* Get pointers to constant and expression sides of the qual.
+			*/
+			if (IsA(get_leftop(orqual), Const))
+			{
+				nconst_expr = get_rightop(orqual);
+				const_expr = get_leftop(orqual);
+			}
+			else if (IsA(get_rightop(orqual), Const))
+			{
+				const_expr = get_rightop(orqual);
+				nconst_expr = get_leftop(orqual);
+			}
+			else
+			{
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+			{
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table. But also we believe, that the case of many
+			* different variable sides is very rare.
+			*/
+			foreach(lc_groups, groups_list)
+			{
+				OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+				Assert(v->node != NULL);
+
+				if (equal(v->node, nconst_expr))
+				{
+					v->consts = lappend(v->consts, const_expr);
+					nconst_expr = NULL;
+					break;
+				}
+			}
+
+			if (nconst_expr == NULL)
+				/*
+					* The clause classified successfully and added into existed
+					* clause group.
+					*/
+				continue;
+
+			/* New clause group needed */
+			gentry = palloc(sizeof(OrClauseGroupEntry));
+			gentry->node = nconst_expr;
+			gentry->consts = list_make1(const_expr);
+			gentry->expr = (Expr *) orqual;
+			groups_list = lappend(groups_list,  (void *) gentry);
+		}
+
+		if (groups_list == NIL)
+		{
+			/*
+			* No any transformations possible with this list of arguments. Here we
+			* already made all underlying transformations. Thus, just return the
+			* transformed bool expression.
+			*/
+			modified_rinfo = lappend(modified_rinfo, copyObject(rinfo));
+			continue;
+		}
+		else
+		{
+			ListCell	   *lc_args;
+
+			/* Let's convert each group of clauses to an IN operation. */
+
+			/*
+			* Go through the list of groups and convert each, where number of
+			* consts more than 1. trivial groups move to OR-list again
+			*/
+
+			foreach(lc_args, groups_list)
+			{
+				List			   *allexprs;
+				Oid				    scalar_type;
+				Oid					array_type;
+				gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+
+				Assert(list_length(gentry->consts) > 0);
+
+				if (list_length(gentry->consts) == 1)
+				{
+					/*
+					* Only one element in the class. Return rinfo into the BoolExpr
+					* args list unchanged.
+					*/
+					list_free(gentry->consts);
+					or_list = lappend(or_list, gentry->expr);
+					continue;
+				}
+
+				/*
+				* Do the transformation.
+				*
+				* First of all, try to select a common type for the array elements.
+				* Note that since the LHS' type is first in the list, it will be
+				* preferred when there is doubt (eg, when all the RHS items are
+				* unknown literals).
+				*
+				* Note: use list_concat here not lcons, to avoid damaging rnonvars.
+				*
+				* As a source of insides, use make_scalar_array_op()
+				*/
+				allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+				scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+				if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+					array_type = get_array_type(scalar_type);
+				else
+					array_type = InvalidOid;
+
+				if (array_type != InvalidOid)
+				{
+					/*
+					* OK: coerce all the right-hand non-Var inputs to the common
+					* type and build an ArrayExpr for them.
+					*/
+					List	   *aexprs;
+					ArrayExpr  *newa;
+					ScalarArrayOpExpr *saopexpr;
+					ListCell *l;
+
+					aexprs = NIL;
+
+					foreach(l, gentry->consts)
+					{
+						Node	   *rexpr = (Node *) lfirst(l);
+
+						rexpr = coerce_to_common_type(NULL, rexpr,
+													scalar_type,
+													"IN");
+						aexprs = lappend(aexprs, rexpr);
+					}
+
+					newa = makeNode(ArrayExpr);
+					/* array_collid will be set by parse_collate.c */
+					newa->element_typeid = scalar_type;
+					newa->array_typeid = array_type;
+					newa->multidims = false;
+					newa->elements = aexprs;
+					newa->location = -1;
+
+					saopexpr =
+						(ScalarArrayOpExpr *)
+							make_scalar_array_op(NULL,
+												list_make1(makeString((char *) "=")),
+												true,
+												gentry->node,
+												(Node *) newa,
+												-1);
+					saopexpr->inputcollid = exprInputCollation((Node *)gentry->expr);;
+
+					or_list = lappend(or_list, (void *) saopexpr);
+
+					something_changed = true;
+					change_apply = true;
+				}
+				else
+				{
+					list_free(gentry->consts);
+					or_list = lappend(or_list, gentry->expr);
+					continue;
+				}
+
+				if (!change_apply)
+				{
+					/*
+					* Each group contains only one element - use rinfo as is.
+					*/
+					modified_rinfo = lappend(modified_rinfo, rinfo);
+					continue;
+				}
+
+				/*
+				* Make a new version of the restriction. Remember source restriction
+				* can be used in another path (SeqScan, for example).
+				*/
+
+				/* One more trick: assemble correct clause */
+				rinfo = make_restrictinfo(root,
+						list_length(or_list) > 1 ? make_orclause(or_list) :
+													(Expr *) linitial(or_list),
+						rinfo->has_clone,
+						rinfo->is_clone,
+						rinfo->is_pushed_down,
+						rinfo->pseudoconstant,
+						rinfo->security_level,
+						rinfo->required_relids,
+						rinfo->outer_relids,
+						rinfo->outer_relids);
+				rinfo->eval_cost=rinfo_base->eval_cost;
+				rinfo->norm_selec=rinfo_base->norm_selec;
+				rinfo->outer_selec=rinfo_base->outer_selec;
+				rinfo->left_bucketsize=rinfo_base->left_bucketsize;
+				rinfo->right_bucketsize=rinfo_base->right_bucketsize;
+				rinfo->left_mcvfreq=rinfo_base->left_mcvfreq;
+				rinfo->right_mcvfreq=rinfo_base->right_mcvfreq;
+				modified_rinfo = lappend(modified_rinfo, rinfo);
+				something_changed = true;
+			}
+		}
+		list_free(or_list);
+		list_free_deep(groups_list);
+
+	}
+		/*
+		 * Check if transformation has made. If nothing changed - return
+		 * baserestrictinfo as is.
+		 */
+		if (something_changed)
+		{
+			return modified_rinfo;
+		}
+
+		list_free(modified_rinfo);
+		return baserestrictinfo;
+}
+
 /*
  * extract_restriction_or_clauses
  *	  Examine join OR-of-AND clauses to see if any useful restriction OR
@@ -93,6 +383,9 @@ extract_restriction_or_clauses(PlannerInfo *root)
 		if (rel->reloptkind != RELOPT_BASEREL)
 			continue;
 
+		rel->baserestrictinfo  = transform_ors(root, rel->baserestrictinfo);
+		rel->joininfo = transform_ors(root, rel->joininfo);
+
 		/*
 		 * Find potentially interesting OR joinclauses.  We can use any
 		 * joinclause that is considered safe to move to this rel by the
@@ -114,7 +407,9 @@ extract_restriction_or_clauses(PlannerInfo *root)
 				 * and insert it into the rel's restrictinfo list if so.
 				 */
 				if (orclause)
+				{
 					consider_new_or_clause(root, rel, orclause, rinfo);
+				}
 			}
 		}
 	}
-- 
2.34.1

#73a.rybakina
a.rybakina@postgrespro.ru
In reply to: a.rybakina (#72)
Re: POC, WIP: OR-clause support for indexes

Sorry for the duplicates, I received a letter that my letter did not
reach the addressee, I thought the design was incorrect.

Show quoted text

On 26.09.2023 12:21, a.rybakina wrote:

I'm sorry I didn't write for a long time, but I really had a very
difficult month, now I'm fully back to work.

*I was able to implement the patches to the end and moved the
transformation of "OR" expressions to ANY.* I haven't seen a big
difference between them yet, one has a transformation before
calculating selectivity (v7.1-Replace-OR-clause-to-ANY.patch), the
other after (v7.2-Replace-OR-clause-to-ANY.patch). Regression tests
are passing, I don't see any problems with selectivity, nothing has
fallen into the coredump, but I found some incorrect transformations.
What is the reason for these inaccuracies, I have not found, but, to
be honest, they look unusual). Gave the error below.

In the patch, I don't like that I had to drag three libraries from
parsing until I found a way around it.The advantage of this approach
compared to the other ([1]) is that at this stage all possible or
transformations are performed, compared to the patch, where the
transformation was done at the parsing stage. That is, here, for
example, there are such optimizations in the transformation:

I took the common element out of the bracket and the rest is converted
to ANY, while, as noted by Peter Geoghegan, we did not have several
bitmapscans, but only one scan through the array.

postgres=# explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 AND prolang=1 OR prolang = 13 AND prolang = 2 OR
prolang = 13 AND prolang = 3;
                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..151.66 rows=1 width=68) (actual
time=1.167..1.168 rows=0 loops=1)
   Filter: ((prolang = '13'::oid) AND (prolang = ANY (ARRAY['1'::oid,
'2'::oid, '3'::oid])))
   Rows Removed by Filter: 3302
 Planning Time: 0.146 ms
 Execution Time: 1.191 ms
(5 rows)

*While I was testing, I found some transformations that don't work,
although in my opinion, they should:**
**
**1. First case:*
explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 AND prolang=1 OR prolang = 2 AND prolang = 2 OR
prolang = 13 AND prolang = 13;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..180.55 rows=2 width=68) (actual
time=2.959..3.335 rows=89 loops=1)
   Filter: (((prolang = '13'::oid) AND (prolang = '1'::oid)) OR
((prolang = '2'::oid) AND (prolang = '2'::oid)) OR ((prolang =
'13'::oid) AND (prolang = '13'::oid)))
   Rows Removed by Filter: 3213
 Planning Time: 1.278 ms
 Execution Time: 3.486 ms
(5 rows)

Should have left only prolang = '13'::oid:

                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..139.28 rows=1 width=68) (actual
time=2.034..2.034 rows=0 loops=1)
   Filter: ((prolang = '13'::oid ))
   Rows Removed by Filter: 3302
 Planning Time: 0.181 ms
 Execution Time: 2.079 ms
(5 rows)

*2. Also does not work:*
postgres=# explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang = 2 AND prolang = 2 OR prolang = 13;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..164.04 rows=176 width=68) (actual
time=2.422..2.686 rows=89 loops=1)
   Filter: ((prolang = '13'::oid) OR ((prolang = '2'::oid) AND
(prolang = '2'::oid)) OR (prolang = '13'::oid))
   Rows Removed by Filter: 3213
 Planning Time: 1.370 ms
 Execution Time: 2.799 ms
(5 rows)

Should have left:
Filter: ((prolang = '13'::oid) OR (prolang = '2'::oid))

*3. Or another:*

explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang=13 OR prolang = 2 AND prolang = 2;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..164.04 rows=176 width=68) (actual
time=2.350..2.566 rows=89 loops=1)
   Filter: ((prolang = '13'::oid) OR (prolang = '13'::oid) OR
((prolang = '2'::oid) AND (prolang = '2'::oid)))
   Rows Removed by Filter: 3213
 Planning Time: 0.215 ms
 Execution Time: 2.624 ms
(5 rows)

Should have left:
Filter: ((prolang = '13'::oid) OR (prolang = '2'::oid))

*Falls into coredump at me:*
explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang = 2 AND prolang = 2 OR prolang = 13;

explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang=13 OR prolang = 2 AND prolang = 2;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..164.04 rows=176 width=68) (actual
time=2.350..2.566 rows=89 loops=1)
   Filter: ((prolang = '13'::oid) OR (prolang = '13'::oid) OR
((prolang = '2'::oid) AND (prolang = '2'::oid)))
   Rows Removed by Filter: 3213
 Planning Time: 0.215 ms
 Execution Time: 2.624 ms

(5 rows)

I remind that initially the task was to find an opportunity to
optimize the case of processing a large number of "or" expressions to
optimize memory consumption. The FlameGraph for executing 50,000 "or"
expressionshas grown 1.4Gb and remains in this state until exiting the
psql session (flamegraph1.png) and it sagged a lot in execution time.
If this case is converted to ANY, the query is executed much faster
and memory is optimized (flamegraph2.png). It may be necessary to use
this approach if there is no support for the framework to process ANY,
IN expressions.

Peter Geoghegan also noticed some development of this patch in terms
of preparing some transformations to optimize the query at the stage
of its execution [0].

[0]
/messages/by-id/CAH2-Wz=9N_4+EyhtyFqYQRx4OgVbP+1aoYU2JQPVogCir61ZEQ@mail.gmail.com

[1]
/messages/by-id/attachment/149105/v7-Replace-OR-clause-to-ANY-expressions.patch

#74a.rybakina
a.rybakina@postgrespro.ru
In reply to: a.rybakina (#72)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

I'm sorry I didn't write for a long time, but I really had a very
difficult month, now I'm fully back to work.

*I was able to implement the patches to the end and moved the
transformation of "OR" expressions to ANY.* I haven't seen a big
difference between them yet, one has a transformation before
calculating selectivity (v7.1-Replace-OR-clause-to-ANY.patch), the
other after (v7.2-Replace-OR-clause-to-ANY.patch). Regression tests
are passing, I don't see any problems with selectivity, nothing has
fallen into the coredump, but I found some incorrect transformations.
What is the reason for these inaccuracies, I have not found, but, to
be honest, they look unusual). Gave the error below.

In the patch, I don't like that I had to drag three libraries from
parsing until I found a way around it.The advantage of this approach
compared to the other ([1]) is that at this stage all possible or
transformations are performed, compared to the patch, where the
transformation was done at the parsing stage. That is, here, for
example, there are such optimizations in the transformation:

I took the common element out of the bracket and the rest is converted
to ANY, while, as noted by Peter Geoghegan, we did not have several
bitmapscans, but only one scan through the array.

postgres=# explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 AND prolang=1 OR prolang = 13 AND prolang = 2 OR
prolang = 13 AND prolang = 3;
                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..151.66 rows=1 width=68) (actual
time=1.167..1.168 rows=0 loops=1)
   Filter: ((prolang = '13'::oid) AND (prolang = ANY (ARRAY['1'::oid,
'2'::oid, '3'::oid])))
   Rows Removed by Filter: 3302
 Planning Time: 0.146 ms
 Execution Time: 1.191 ms
(5 rows)
*Falls into coredump at me:*
explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang = 2 AND prolang = 2 OR prolang = 13;

I continue to try to move transformations of "OR" expressions at the
optimization stage, unfortunately I have not been able to figure out
coredump yet, but I saw an important thing that it is already necessary
to process RestrictInfo expressions here. I corrected it.

To be honest, despite some significant advantages in the fact that we
are already processing pre-converted "or" expressions (logical
transformations have been performed and duplicates have been removed), I
have big doubts about this approach. We already have quite a lot of
objects at this stage that can refer to the RestrictInfo variable in
ReplOptInfo, and updating these links can be costly for us. By the way,
right now I suspect that the current coredump appeared precisely because
there is a link somewhere that refers to an un-updated RestrictInfo, but
so far I can't find this place. coredump occurs at the request execution
stage, looks like this:

Core was generated by `postgres: alena regression [local]
SELECT                                     '.
--Type <RET> for more, q to quit, c to continue without paging--
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00005565f3ec4947 in ExecInitExprRec (node=0x5565f530b290,
state=0x5565f53383d8, resv=0x5565f53383e0, resnull=0x5565f53383dd) at
execExpr.c:1331
1331                                            Expr       *arg = (Expr
*) lfirst(lc);
(gdb) bt
#0  0x00005565f3ec4947 in ExecInitExprRec (node=0x5565f530b290,
state=0x5565f53383d8, resv=0x5565f53383e0, resnull=0x5565f53383dd) at
execExpr.c:1331
#1  0x00005565f3ec2708 in ExecInitQual (qual=0x5565f531d950,
parent=0x5565f5337948) at execExpr.c:258
#2  0x00005565f3f2f080 in ExecInitSeqScan (node=0x5565f5309700,
estate=0x5565f5337700, eflags=32) at nodeSeqscan.c:172
#3  0x00005565f3ee70c9 in ExecInitNode (node=0x5565f5309700,
estate=0x5565f5337700, eflags=32) at execProcnode.c:210
#4  0x00005565f3edbe3a in InitPlan (queryDesc=0x5565f53372f0, eflags=32)
at execMain.c:968
#5  0x00005565f3edabe3 in standard_ExecutorStart
(queryDesc=0x5565f53372f0, eflags=32) at execMain.c:266
#6  0x00005565f3eda927 in ExecutorStart (queryDesc=0x5565f53372f0,
eflags=0) at execMain.c:145
#7  0x00005565f419921e in PortalStart (portal=0x5565f52ace90,
params=0x0, eflags=0, snapshot=0x0) at pquery.c:517
#8  0x00005565f4192635 in exec_simple_query (
    query_string=0x5565f5233af0 "SELECT p1.oid, p1.proname\nFROM
pg_proc as p1\nWHERE prolang = 13 AND (probin IS NULL OR probin = '' OR
probin = '-');") at postgres.c:1233
#9  0x00005565f41976ef in PostgresMain (dbname=0x5565f526ad10
"regression", username=0x5565f526acf8 "alena") at postgres.c:4652
#10 0x00005565f40b8417 in BackendRun (port=0x5565f525f830) at
postmaster.c:4439
#11 0x00005565f40b7ca3 in BackendStartup (port=0x5565f525f830) at
postmaster.c:4167
#12 0x00005565f40b40f1 in ServerLoop () at postmaster.c:1781
#13 0x00005565f40b399b in PostmasterMain (argc=8, argv=0x5565f522c110)
at postmaster.c:1465
#14 0x00005565f3f6560e in main (argc=8, argv=0x5565f522c110) at main.c:198

I have saved my experimental version of the "or" transfer in the diff
file, I am attaching the main patch in the ".patch" format so that the
tests are checked against this version. Let me remind you that the main
patch contains the code for converting "OR" expressions to "ANY" at the
parsing stage.

Attachments:

experimantal_version.difftext/x-patch; charset=UTF-8; name=experimantal_version.diffDownload
diff --git a/src/backend/optimizer/util/orclauses.c b/src/backend/optimizer/util/orclauses.c
index 6ef9d14b902..d01c09f28e2 100644
--- a/src/backend/optimizer/util/orclauses.c
+++ b/src/backend/optimizer/util/orclauses.c
@@ -22,6 +22,10 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/orclauses.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 
 
 static bool is_safe_restriction_clause_for(RestrictInfo *rinfo, RelOptInfo *rel);
@@ -30,6 +34,292 @@ static void consider_new_or_clause(PlannerInfo *root, RelOptInfo *rel,
 								   Expr *orclause, RestrictInfo *join_or_rinfo);
 
 
+int			or_transform_limit = 2;
+
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+	RestrictInfo   *rinfo;
+} OrClauseGroupEntry;
+
+static List *
+transform_ors(PlannerInfo *root, List *baserestrictinfo)
+{
+	ListCell	   *lc_clause;
+	List	   	   *modified_rinfo = NIL;
+	bool		    something_changed = false;
+
+
+	foreach (lc_clause, baserestrictinfo)
+	{
+		RestrictInfo   	   *rinfo = lfirst_node(RestrictInfo, lc_clause);
+		RestrictInfo	   *rinfo_base = copyObject(rinfo);
+		List		   	   *groups_list = NIL;
+		List		       *or_list = NIL;
+		ListCell	   	   *lc_eargs,
+					   	   *lc_rargs;
+
+		if (!restriction_is_or_clause(rinfo) ||
+			list_length(((BoolExpr *) rinfo->clause)->args) < or_transform_limit)
+		{
+			/* Add a clause without changes */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+		forboth(lc_eargs, ((BoolExpr *) rinfo->clause)->args,
+				lc_rargs, ((BoolExpr *) rinfo->orclause)->args)
+		{
+			Expr			   *orqual = (Expr *) lfirst(lc_eargs);
+			Node			   *const_expr;
+			Node			   *nconst_expr;
+			ListCell		   *lc_groups;
+			OrClauseGroupEntry *gentry;
+			RestrictInfo	   *sub_rinfo;
+
+			/* If this is not an 'OR' expression, skip the transformation */
+			if (!IsA(lfirst(lc_rargs), RestrictInfo))
+			{
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+			sub_rinfo = lfirst_node(RestrictInfo, lc_rargs);
+
+			/* Check: it is an expr of the form 'F(x) oper ConstExpr' */
+			if (!IsA(orqual, OpExpr) ||
+			    !(bms_is_empty(sub_rinfo->left_relids) ^
+				bms_is_empty(sub_rinfo->right_relids)) ||
+				contain_volatile_functions((Node *) orqual))
+			{
+				/* Again, it's not the expr we can transform */
+				or_list = lappend(or_list, (void *) orqual);
+				continue;
+			}
+
+
+			/*
+			* Detect the constant side of the clause. Recall non-constant
+			* expression can be made not only with Vars, but also with Params,
+			* which is not bonded with any relation. Thus, we detect the const
+			* side - if another side is constant too, the orqual couldn't be
+			* an OpExpr.
+			* Get pointers to constant and expression sides of the qual.
+			*/
+			const_expr =bms_is_empty(sub_rinfo->left_relids) ?
+												get_leftop(sub_rinfo->clause) :
+												get_rightop(sub_rinfo->clause);
+			nconst_expr = bms_is_empty(sub_rinfo->left_relids) ?
+												get_rightop(sub_rinfo->clause) :
+												get_leftop(sub_rinfo->clause);
+
+			if (!op_mergejoinable(((OpExpr *) sub_rinfo->clause)->opno, exprType(nconst_expr)))
+			{
+				or_list = lappend(or_list, (void *) orqual);
+				continue;
+			}
+
+			/*
+			* At this point we definitely have a transformable clause.
+			* Classify it and add into specific group of clauses, or create new
+			* group.
+			* TODO: to manage complexity in the case of many different clauses
+			* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			* like a hash table. But also we believe, that the case of many
+			* different variable sides is very rare.
+			*/
+			foreach(lc_groups, groups_list)
+			{
+				OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+				Assert(v->node != NULL);
+
+				if (equal(v->node, nconst_expr))
+				{
+					v->consts = lappend(v->consts, const_expr);
+					nconst_expr = NULL;
+					break;
+				}
+			}
+
+			if (nconst_expr == NULL)
+				/*
+					* The clause classified successfully and added into existed
+					* clause group.
+					*/
+				continue;
+
+			/* New clause group needed */
+			gentry = palloc(sizeof(OrClauseGroupEntry));
+			gentry->node = nconst_expr;
+			gentry->consts = list_make1(const_expr);
+			gentry->rinfo = sub_rinfo;
+			groups_list = lappend(groups_list,  (void *) gentry);
+		}
+
+		if (groups_list == NIL)
+		{
+			/*
+			* No any transformations possible with this list of arguments. Here we
+			* already made all underlying transformations. Thus, just return the
+			* transformed bool expression.
+			*/
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+		else
+		{
+			ListCell	   *lc_args;
+
+			/* Let's convert each group of clauses to an IN operation. */
+
+			/*
+			* Go through the list of groups and convert each, where number of
+			* consts more than 1. trivial groups move to OR-list again
+			*/
+
+			foreach(lc_args, groups_list)
+			{
+				List			   *allexprs;
+				Oid				    scalar_type;
+				Oid					array_type;
+				OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+
+				Assert(list_length(gentry->consts) > 0);
+
+				if (list_length(gentry->consts) == 1)
+				{
+					/*
+					* Only one element in the class. Return rinfo into the BoolExpr
+					* args list unchanged.
+					*/
+					list_free(gentry->consts);
+					or_list = lappend(or_list, gentry->rinfo->clause);
+					continue;
+				}
+
+				/*
+				* Do the transformation.
+				*
+				* First of all, try to select a common type for the array elements.
+				* Note that since the LHS' type is first in the list, it will be
+				* preferred when there is doubt (eg, when all the RHS items are
+				* unknown literals).
+				*
+				* Note: use list_concat here not lcons, to avoid damaging rnonvars.
+				*
+				* As a source of insides, use make_scalar_array_op()
+				*/
+				allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+				scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+				if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+					array_type = get_array_type(scalar_type);
+				else
+					array_type = InvalidOid;
+
+				if (array_type != InvalidOid && scalar_type != InvalidOid)
+				{
+					/*
+					* OK: coerce all the right-hand non-Var inputs to the common
+					* type and build an ArrayExpr for them.
+					*/
+					List	   *aexprs;
+					ArrayExpr  *newa;
+					ScalarArrayOpExpr *saopexpr;
+					ListCell *l;
+
+					aexprs = NIL;
+
+					foreach(l, gentry->consts)
+					{
+						Node	   *rexpr = (Node *) lfirst(l);
+
+						rexpr = coerce_to_common_type(NULL, rexpr,
+													scalar_type,
+													"IN");
+						aexprs = lappend(aexprs, rexpr);
+					}
+
+					newa = makeNode(ArrayExpr);
+					/* array_collid will be set by parse_collate.c */
+					newa->element_typeid = scalar_type;
+					newa->array_typeid = array_type;
+					newa->multidims = false;
+					newa->elements = aexprs;
+					newa->location = -1;
+
+					saopexpr =
+						(ScalarArrayOpExpr *)
+							make_scalar_array_op(NULL,
+												list_make1(makeString((char *) "=")),
+												true,
+												gentry->node,
+												(Node *) newa,
+												-1);
+					saopexpr->inputcollid = exprInputCollation((Node *)gentry->rinfo->clause);
+
+					or_list = lappend(or_list, (void *) saopexpr);
+
+					something_changed = true;
+				}
+				else
+				{
+					/*
+					* Each group contains only one element - use rinfo as is.
+					*/
+					list_free(gentry->consts);
+					or_list = lappend(or_list, gentry->expr);
+					continue;
+				}
+
+				/*
+				* Make a new version of the restriction. Remember source restriction
+				* can be used in another path (SeqScan, for example).
+				*/
+
+				/* One more trick: assemble correct clause */
+				rinfo = make_restrictinfo(root,
+						list_length(or_list) > 1 ? make_orclause(or_list) :
+													(Expr *) linitial(or_list),
+						rinfo->has_clone,
+						rinfo->is_clone,
+						rinfo->is_pushed_down,
+						rinfo->pseudoconstant,
+						rinfo->security_level,
+						rinfo->required_relids,
+						rinfo->outer_relids,
+						rinfo->outer_relids);
+				rinfo->eval_cost=rinfo_base->eval_cost;
+				rinfo->norm_selec=rinfo_base->norm_selec;
+				rinfo->outer_selec=rinfo_base->outer_selec;
+				rinfo->left_bucketsize=rinfo_base->left_bucketsize;
+				rinfo->right_bucketsize=rinfo_base->right_bucketsize;
+				rinfo->left_mcvfreq=rinfo_base->left_mcvfreq;
+				rinfo->right_mcvfreq=rinfo_base->right_mcvfreq;
+				modified_rinfo = lappend(modified_rinfo, rinfo);
+				something_changed = true;
+			}
+		}
+		list_free(or_list);
+		list_free_deep(groups_list);
+	}
+
+	/*
+		* Check if transformation has made. If nothing changed - return
+		* baserestrictinfo as is.
+		*/
+	if (something_changed)
+	{
+		return modified_rinfo;
+	}
+
+	list_free(modified_rinfo);
+	return baserestrictinfo;
+}
+
 /*
  * extract_restriction_or_clauses
  *	  Examine join OR-of-AND clauses to see if any useful restriction OR
@@ -93,6 +383,9 @@ extract_restriction_or_clauses(PlannerInfo *root)
 		if (rel->reloptkind != RELOPT_BASEREL)
 			continue;
 
+		rel->baserestrictinfo  = transform_ors(root, rel->baserestrictinfo);
+		//rel->joininfo = transform_ors(root, rel->joininfo);
+
 		/*
 		 * Find potentially interesting OR joinclauses.  We can use any
 		 * joinclause that is considered safe to move to this rel by the
@@ -114,7 +407,9 @@ extract_restriction_or_clauses(PlannerInfo *root)
 				 * and insert it into the rel's restrictinfo list if so.
 				 */
 				if (orclause)
+				{
 					consider_new_or_clause(root, rel, orclause, rinfo);
+				}
 			}
 		}
 	}
v7.0-Replace-OR-clause-to-ANY.patchtext/x-patch; charset=UTF-8; name=v7.0-Replace-OR-clause-to-ANY.patchDownload
From 087125cc413429bda05f22ebbd51115c23819285 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Tue, 18 Jul 2023 17:19:53 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
---
 src/backend/parser/parse_expr.c               | 230 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 115 +++++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  50 ++++
 src/test/regress/expected/partition_prune.out | 179 ++++++++++++++
 src/test/regress/expected/tidscan.out         |  17 ++
 src/test/regress/sql/create_index.sql         |  32 +++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 13 files changed, 674 insertions(+), 2 deletions(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 5a05caa8744..b2294af0f43 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -43,6 +43,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+int			or_transform_limit = 500;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -95,6 +96,233 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	List		   *groups_list = NIL;
+	ListCell	   *lc;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR ||
+		list_length(expr_orig->args) < or_transform_limit)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		ListCell		   *lc_groups;
+		OrClauseGroupEntry *gentry;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		foreach(lc_groups, groups_list)
+		{
+			OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+			Assert(v->node != NULL);
+
+			if (equal(v->node, nconst_expr))
+			{
+				v->consts = lappend(v->consts, const_expr);
+				nconst_expr = NULL;
+				break;
+			}
+		}
+
+		if (nconst_expr == NULL)
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+
+		/* New clause group needed */
+		gentry = palloc(sizeof(OrClauseGroupEntry));
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		groups_list = lappend(groups_list,  (void *) gentry);
+	}
+
+	if (groups_list == NIL)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		ListCell	   *lc_args;
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+		}
+
+		list_free_deep(groups_list);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -208,7 +436,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index f9dba43b8c0..ddc27e2277c 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -2040,6 +2040,16 @@ struct config_int ConfigureNamesInt[] =
 		100, 1, MAX_STATISTICS_TARGET,
 		NULL, NULL, NULL
 	},
+	{
+		{"or_transform_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&or_transform_limit,
+		500, 0, INT_MAX,
+		NULL, NULL, NULL
+	},
 	{
 		{"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
 			gettext_noop("Sets the FROM-list size beyond which subqueries "
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..891e6a462b9 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT int or_transform_limit;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..cc229d4dcaf 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,121 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET or_transform_limit;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..c052b113eea 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ or_transform_limit
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9b8638f286a..2314d92a6d4 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,6 +4207,56 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
+
+RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 1eb347503aa..d1c5ce8be09 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET or_transform_limit;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET or_transform_limit;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..a2949d3d699 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET or_transform_limit;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..9c6baace0e2 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET or_transform_limit;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 3e5032b04dd..d4d7d853a4a 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1396,6 +1396,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET or_transform_limit;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index d1c60b8fe9d..77f3e6c3b9b 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET or_transform_limit;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET or_transform_limit;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..634bf08e5fc 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET or_transform_limit;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e941fb6c82f..c3abb725c8c 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1631,6 +1631,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
6.0.1

#75a.rybakina
a.rybakina@postgrespro.ru
In reply to: a.rybakina (#74)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 29.09.2023 20:35, a.rybakina wrote:

I'm sorry I didn't write for a long time, but I really had a very
difficult month, now I'm fully back to work.

*I was able to implement the patches to the end and moved the
transformation of "OR" expressions to ANY.* I haven't seen a big
difference between them yet, one has a transformation before
calculating selectivity (v7.1-Replace-OR-clause-to-ANY.patch), the
other after (v7.2-Replace-OR-clause-to-ANY.patch). Regression tests
are passing, I don't see any problems with selectivity, nothing has
fallen into the coredump, but I found some incorrect transformations.
What is the reason for these inaccuracies, I have not found, but, to
be honest, they look unusual). Gave the error below.

In the patch, I don't like that I had to drag three libraries from
parsing until I found a way around it.The advantage of this approach
compared to the other ([1]) is that at this stage all possible or
transformations are performed, compared to the patch, where the
transformation was done at the parsing stage. That is, here, for
example, there are such optimizations in the transformation:

I took the common element out of the bracket and the rest is
converted to ANY, while, as noted by Peter Geoghegan, we did not have
several bitmapscans, but only one scan through the array.

postgres=# explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 AND prolang=1 OR prolang = 13 AND prolang = 2 OR
prolang = 13 AND prolang = 3;
                                              QUERY PLAN
-------------------------------------------------------------------------------------------------------
 Seq Scan on pg_proc p1  (cost=0.00..151.66 rows=1 width=68) (actual
time=1.167..1.168 rows=0 loops=1)
   Filter: ((prolang = '13'::oid) AND (prolang = ANY (ARRAY['1'::oid,
'2'::oid, '3'::oid])))
   Rows Removed by Filter: 3302
 Planning Time: 0.146 ms
 Execution Time: 1.191 ms
(5 rows)
*Falls into coredump at me:*
explain analyze SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE prolang = 13 OR prolang = 2 AND prolang = 2 OR prolang = 13;

Hi, all!

I fixed the kernel dump issue and all the regression tests were
successful, but I discovered another problem when I added my own
regression tests.
Some queries that contain "or" expressions do not convert to "ANY". I
have described this in more detail using diff as expected and real results:

diff -U3 
/home/alena/postgrespro__copy6/src/test/regress/expected/create_index.out 
/home/alena/postgrespro__copy6/src/test/regress/results/create_index.out
--- 
/home/alena/postgrespro__copy6/src/test/regress/expected/create_index.out 
2023-10-04 21:54:12.496282667 +0300
+++ 
/home/alena/postgrespro__copy6/src/test/regress/results/create_index.out 
2023-10-04 21:55:41.665422459 +0300
@@ -1925,17 +1925,20 @@
  EXPLAIN (COSTS OFF)
  SELECT count(*) FROM tenk1
    WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
-                                               QUERY PLAN
---------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------
   Aggregate
     ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((thousand = 42) AND (tenthous = ANY 
('{1,3}'::integer[]))) OR (thousand = 41))
+         Recheck Cond: ((((thousand = 42) AND (tenthous = 1)) OR 
((thousand = 42) AND (tenthous = 3))) OR (thousand = 41))
           ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_thous_tenthous
-                     Index Cond: ((thousand = 42) AND (tenthous = ANY 
('{1,3}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 42) AND (tenthous = 1))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 42) AND (tenthous = 3))
                 ->  Bitmap Index Scan on tenk1_thous_tenthous
                       Index Cond: (thousand = 41)
-(8 rows)
+(11 rows)
@@ -1946,24 +1949,50 @@
  EXPLAIN (COSTS OFF)
  SELECT count(*) FROM tenk1
+  WHERE thousand = 42 OR tenthous = 1 AND thousand = 42 OR tenthous = 1;
+                                            QUERY PLAN
+---------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((thousand = 42) OR ((thousand = 42) AND 
(tenthous = 1)) OR (tenthous = 1))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = 1))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (tenthous = 1)
+(10 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 OR tenthous = 1 AND thousand = 42 OR tenthous = 1;
+ count
+-------
+    11
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
    WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 
2) OR thousand = 41;
-                                                         QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN
+------------------------------------------------------------------------------------------------------------------------
   Aggregate
     ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR 
(thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR 
(thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
           ->  BitmapOr
                 ->  BitmapAnd
                       ->  Bitmap Index Scan on tenk1_hundred
                             Index Cond: (hundred = 42)
                       ->  BitmapOr
                             ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (tenthous < 2)
+                                 Index Cond: (thousand = 42)
                             ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = ANY 
('{42,99}'::integer[]))
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
                 ->  Bitmap Index Scan on tenk1_thous_tenthous
                       Index Cond: (thousand = 41)
-(14 rows)
+(16 rows)
diff -U3 
/home/alena/postgrespro__copy6/src/test/regress/expected/join.out 
/home/alena/postgrespro__copy6/src/test/regress/results/join.out
--- /home/alena/postgrespro__copy6/src/test/regress/expected/join.out 
2023-10-04 21:53:55.632069079 +0300
+++ /home/alena/postgrespro__copy6/src/test/regress/results/join.out 
2023-10-04 21:55:46.597485979 +0300
  explain (costs off)
  select * from tenk1 a join tenk1 b on
    (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
    ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
- QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
   Nested Loop
-   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 
2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR 
(a.unique1 = 3))
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 
1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND 
(b.hundred = 4)))
     ->  Seq Scan on tenk1 b
     ->  Materialize
           ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR 
(unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR 
(unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                 ->  BitmapOr
                       ->  Bitmap Index Scan on tenk1_unique1
                             Index Cond: (unique1 < 20)
                       ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
                             Index Cond: (unique1 = 1)
                       ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-(15 rows)
+                           Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 7)
+(17 rows)
  explain (costs off)
  select * from tenk1 a join tenk1 b on
    (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
    ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
- QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
   Nested Loop
-   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 
2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR 
(a.unique1 = 3))
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 
1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND 
(b.hundred = 4)))
     ->  Seq Scan on tenk1 b
     ->  Materialize
           ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR 
(unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR 
(unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                 ->  BitmapOr
                       ->  Bitmap Index Scan on tenk1_unique1
                             Index Cond: (unique1 < 20)
                       ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
                             Index Cond: (unique1 = 1)
                       ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-(15 rows)
+                           Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 7)
+(17 rows)

I haven't been able to fully deal with this problem yet

I have attached my experimental patch with the code.

Attachments:

0001-Replace-OR-clause-to-ANY-expressions.difftext/x-patch; charset=UTF-8; name=0001-Replace-OR-clause-to-ANY-expressions.diffDownload
diff --git a/src/backend/optimizer/util/orclauses.c b/src/backend/optimizer/util/orclauses.c
index 6ef9d14b902..cbb187229fe 100644
--- a/src/backend/optimizer/util/orclauses.c
+++ b/src/backend/optimizer/util/orclauses.c
@@ -22,6 +22,10 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/orclauses.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 
 
 static bool is_safe_restriction_clause_for(RestrictInfo *rinfo, RelOptInfo *rel);
@@ -29,6 +33,307 @@ static Expr *extract_or_clause(RestrictInfo *or_rinfo, RelOptInfo *rel);
 static void consider_new_or_clause(PlannerInfo *root, RelOptInfo *rel,
 								   Expr *orclause, RestrictInfo *join_or_rinfo);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				collation;
+	Oid				opno;
+	RestrictInfo   *rinfo;
+} OrClauseGroupEntry;
+
+int			or_transform_limit = 500;
+
+/*
+ * Pass through baserestrictinfo clauses and try to convert OR clauses into IN
+ * Return a modified clause list or just the same baserestrictinfo, if no
+ * changes have made.
+ * XXX: do not change source list of clauses at all.
+ */
+static List *
+transform_ors(PlannerInfo *root, List *baserestrictinfo)
+{
+	ListCell   *lc;
+	ListCell   *lc_cp;
+	List	   *modified_rinfo = NIL;
+	bool		something_changed = false;
+	List	   *baserestrictinfo_origin = list_copy(baserestrictinfo);
+
+	/*
+	 * Complexity of a clause could be arbitrarily sophisticated. Here, we will
+	 * look up only on the top level of clause list.
+	 * XXX: It is substantiated? Could we change something here?
+	 */
+	forboth (lc, baserestrictinfo, lc_cp, baserestrictinfo_origin)
+	{
+		RestrictInfo   *rinfo = lfirst_node(RestrictInfo, lc);
+		RestrictInfo   *rinfo_base = lfirst_node(RestrictInfo, lc_cp);
+		List		   *or_list = NIL;
+		ListCell	   *lc_eargs,
+					   *lc_rargs,
+					   *lc_args;
+		List		   *groups_list = NIL;
+		bool			change_apply = false;
+
+		if (!restriction_is_or_clause(rinfo) ||
+			list_length(((BoolExpr *) rinfo->clause)->args) < or_transform_limit)
+		{
+			/* Add a clause without changes */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		/*
+		 * NOTE:
+		 * It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		 * a list of sub-restrictinfo args, and rinfo->clause - which is the
+		 * same expression, made from bare clauses. To not break selectivity
+		 * caches and other optimizations, use both:
+		 * - use rinfos from orclause if no transformation needed
+		 * - use  bare quals from rinfo->clause in the case of transformation,
+		 * to create new RestrictInfo: in this case we have no options to avoid
+		 * selectivity estimation procedure.
+		 */
+		forboth(lc_eargs, ((BoolExpr *) rinfo->clause)->args,
+				lc_rargs, ((BoolExpr *) rinfo->orclause)->args)
+		{
+			Expr			   *orqual = (Expr *) lfirst(lc_eargs);
+			RestrictInfo	   *sub_rinfo;
+			Node			   *const_expr;
+			Node			   *non_const_expr;
+			ListCell		   *lc_groups;
+			OrClauseGroupEntry *gentry;
+
+			/* It may be one more boolean expression, skip it for now */
+			if (!IsA(lfirst(lc_rargs), RestrictInfo))
+			{
+				or_list = lappend(or_list, (void *) orqual);
+				continue;
+			}
+
+			sub_rinfo = lfirst_node(RestrictInfo, lc_rargs);
+
+			/* Check: it is an expr of the form 'F(x) oper ConstExpr' */
+			if (!IsA(orqual, OpExpr) ||
+				!(bms_is_empty(sub_rinfo->left_relids) ^
+				bms_is_empty(sub_rinfo->right_relids)) ||
+				contain_volatile_functions((Node *) orqual))
+			{
+				/* Again, it's not the expr we can transform */
+				or_list = lappend(or_list, (void *) orqual);
+				continue;
+			}
+
+			/*
+			* Detect the constant side of the clause. Recall non-constant
+			* expression can be made not only with Vars, but also with Params,
+			* which is not bonded with any relation. Thus, we detect the const
+			* side - if another side is constant too, the orqual couldn't be
+			* an OpExpr.
+			* Get pointers to constant and expression sides of the qual.
+			*/
+			const_expr =bms_is_empty(sub_rinfo->left_relids) ?
+												get_leftop(sub_rinfo->clause) :
+												get_rightop(sub_rinfo->clause);
+			non_const_expr = bms_is_empty(sub_rinfo->left_relids) ?
+												get_rightop(sub_rinfo->clause) :
+												get_leftop(sub_rinfo->clause);
+
+			if (!op_mergejoinable(((OpExpr *) sub_rinfo->clause)->opno, exprType(non_const_expr)))
+			{
+				/* And again, filter out non-equality operators */
+				or_list = lappend(or_list, (void *) orqual);
+				continue;
+			}
+
+			/*
+			 * At this point we definitely have a transformable clause.
+			 * Classify it and add into specific group of clauses, or create new
+			 * group.
+			 * TODO: to manage complexity in the case of many different clauses
+			 * (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+			 * like a hash table (htab key ???).
+			 */
+			foreach(lc_groups, groups_list)
+			{
+				OrClauseGroupEntry *v = (OrClauseGroupEntry *) lfirst(lc_groups);
+
+				Assert(v->node != NULL);
+
+				if (equal(v->node, non_const_expr))
+				{
+					v->consts = lappend(v->consts, const_expr);
+					non_const_expr = NULL;
+					break;
+				}
+			}
+
+			if (non_const_expr == NULL)
+				/*
+				 * The clause classified successfully and added into existed
+				 * clause group.
+				 */
+				continue;
+
+			/* New clause group needed */
+			gentry = palloc(sizeof(OrClauseGroupEntry));
+			gentry->node = non_const_expr;
+			gentry->consts = list_make1(const_expr);
+			gentry->rinfo = sub_rinfo;
+			groups_list = lappend(groups_list,  (void *) gentry);
+		}
+
+		if (groups_list == NIL)
+		{
+			/*
+			 * No any transformations possible with this rinfo, just add itself
+			 * to the list and go further.
+			 */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		 * Go through the list of groups and convert each, where number of
+		 * consts more than 1. trivial groups move to OR-list again
+		 */
+
+		foreach(lc_args, groups_list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc_args);
+			ScalarArrayOpExpr  *saopexpr;
+			List			   *allexprs;
+			ArrayExpr		   *newa;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, (void *) gentry->rinfo->clause);
+				continue;
+			}
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				* Only one element in the class. Return rinfo into the BoolExpr
+				* args list unchanged.
+				*/
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->rinfo->clause);
+				continue;
+			}
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+					array_type = get_array_type(scalar_type);
+			else
+					array_type = InvalidOid;
+			if (array_type != InvalidOid && scalar_type != InvalidOid)
+			{
+					/*
+					* OK: coerce all the right-hand non-Var inputs to the common
+					* type and build an ArrayExpr for them.
+					*/
+					List	   *aexprs;
+					ListCell *l;
+
+					aexprs = NIL;
+
+					foreach(l, gentry->consts)
+					{
+						Node	   *rexpr = (Node *) lfirst(l);
+
+						rexpr = coerce_to_common_type(NULL, rexpr,
+													scalar_type,
+													"IN");
+						aexprs = lappend(aexprs, rexpr);
+					}
+
+					newa = makeNode(ArrayExpr);
+					/* array_collid will be set by parse_collate.c */
+					newa->element_typeid = scalar_type;
+					newa->array_typeid = array_type;
+					newa->multidims = false;
+					newa->elements = aexprs;
+					newa->location = -1;
+
+					saopexpr =
+						(ScalarArrayOpExpr *)
+							make_scalar_array_op(NULL,
+												list_make1(makeString((char *) "=")),
+												true,
+												gentry->node,
+												(Node *) newa,
+												-1);
+					//saopexpr->inputcollid = exprInputCollation((Node *)gentry->rinfo->clause);
+
+					or_list = lappend(or_list, (void *) saopexpr);
+				change_apply = true;
+			}
+		}
+
+		if (!change_apply)
+		{
+			/*
+			 * Each group contains only one element - use rinfo as is.
+			 */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			list_free(or_list);
+			list_free_deep(groups_list);
+			continue;
+		}
+
+		/*
+		 * Make a new version of the restriction. Remember source restriction
+		 * can be used in another path (SeqScan, for example).
+		 */
+
+		/* One more trick: assemble correct clause */
+		rinfo = make_restrictinfo(root,
+				  list_length(or_list) > 1 ? make_orclause(or_list) :
+											 (Expr *) linitial(or_list),
+				  rinfo->is_pushed_down,
+				  rinfo->has_clone,
+				  rinfo->is_clone,
+				  rinfo->pseudoconstant,
+				  rinfo->security_level,
+				  rinfo->required_relids,
+				  rinfo->incompatible_relids,
+				  rinfo->outer_relids);
+		rinfo->eval_cost=rinfo_base->eval_cost;
+		rinfo->norm_selec=rinfo_base->norm_selec;
+		rinfo->outer_selec=rinfo_base->outer_selec;
+		rinfo->left_bucketsize=rinfo_base->left_bucketsize;
+		rinfo->right_bucketsize=rinfo_base->right_bucketsize;
+		rinfo->left_mcvfreq=rinfo_base->left_mcvfreq;
+		rinfo->right_mcvfreq=rinfo_base->right_mcvfreq;
+		modified_rinfo = lappend(modified_rinfo, rinfo);
+		list_free_deep(groups_list);
+		something_changed = true;
+	}
+
+	/*
+	 * Check if transformation has made. If nothing changed - return
+	 * baserestrictinfo as is.
+	 */
+	if (something_changed)
+	{
+		return modified_rinfo;
+	}
+
+	list_free(modified_rinfo);
+	return baserestrictinfo;
+}
 
 /*
  * extract_restriction_or_clauses
@@ -93,6 +398,8 @@ extract_restriction_or_clauses(PlannerInfo *root)
 		if (rel->reloptkind != RELOPT_BASEREL)
 			continue;
 
+		rel->baserestrictinfo  = transform_ors(root, rel->baserestrictinfo);
+
 		/*
 		 * Find potentially interesting OR joinclauses.  We can use any
 		 * joinclause that is considered safe to move to this rel by the
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 16ec6c5ef02..a4f04d84021 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -2052,6 +2052,16 @@ struct config_int ConfigureNamesInt[] =
 		100, 1, MAX_STATISTICS_TARGET,
 		NULL, NULL, NULL
 	},
+	{
+		{"or_transform_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&or_transform_limit,
+		500, 0, INT_MAX,
+		NULL, NULL, NULL
+	},
 	{
 		{"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
 			gettext_noop("Sets the FROM-list size beyond which subqueries "
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..891e6a462b9 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT int or_transform_limit;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..a397137ecb6 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,150 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                               QUERY PLAN                               
+------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, 3, 42])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                 QUERY PLAN                                  
+-----------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY (ARRAY[42, 99])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY (ARRAY[42, 99]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 42) AND (tenthous = 1))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 42) AND (tenthous = 3))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 OR tenthous = 1 AND thousand = 42 OR tenthous = 1;
+                                            QUERY PLAN                                             
+---------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((thousand = 42) OR ((thousand = 42) AND (tenthous = 1)) OR (tenthous = 1))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = 1))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (tenthous = 1)
+(10 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 OR tenthous = 1 AND thousand = 42 OR tenthous = 1;
+ count 
+-------
+    11
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY (ARRAY[42, 41]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY (ARRAY[42, 41]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET or_transform_limit;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..c052b113eea 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ or_transform_limit
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9b8638f286a..f22e4524099 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,6 +4207,60 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 7)
+(19 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 7)
+(17 rows)
+
+RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index bb1223e2b13..ad4c4dae81e 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,42 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_ef lp_3
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_g lp_4
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_null lp_5
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_default lp_6
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(13 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_ef lp_3
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_g lp_4
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_default lp_5
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(11 rows)
+
+RESET or_transform_limit;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +707,166 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                   QUERY PLAN                   
+------------------------------------------------
+ Append
+   Subplans Removed: 1
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (a = ANY ('{1,7}'::integer[]))
+(4 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   Subplans Removed: 2
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(6 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET or_transform_limit;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..e462212aa54 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                          QUERY PLAN                          
+--------------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY (ARRAY['(0,2)'::tid, '(0,1)'::tid]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET or_transform_limit;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..514e4f0da48 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,44 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 OR tenthous = 1 AND thousand = 42 OR tenthous = 1;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 OR tenthous = 1 AND thousand = 42 OR tenthous = 1;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET or_transform_limit;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 3e5032b04dd..272ff7c5d90 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1397,6 +1397,17 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+SET or_transform_limit = 0;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET or_transform_limit;
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 83fed54b8c6..068eed3499c 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET or_transform_limit = 0;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET or_transform_limit;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,21 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+SET or_transform_limit = 0;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET or_transform_limit;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..634bf08e5fc 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET or_transform_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET or_transform_limit;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 8de90c49585..b40b58124b4 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1635,6 +1635,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher

#76Alexander Korotkov
aekorotkov@gmail.com
In reply to: a.rybakina (#75)
Re: POC, WIP: OR-clause support for indexes

Hi, Alena!

Thank you for your work on the subject.

On Wed, Oct 4, 2023 at 10:21 PM a.rybakina <a.rybakina@postgrespro.ru> wrote:

I fixed the kernel dump issue and all the regression tests were successful, but I discovered another problem when I added my own regression tests.
Some queries that contain "or" expressions do not convert to "ANY". I have described this in more detail using diff as expected and real results:

diff -U3 /home/alena/postgrespro__copy6/src/test/regress/expected/create_index.out /home/alena/postgrespro__copy6/src/test/regress/results/create_index.out
--- /home/alena/postgrespro__copy6/src/test/regress/expected/create_index.out 2023-10-04 21:54:12.496282667 +0300
+++ /home/alena/postgrespro__copy6/src/test/regress/results/create_index.out  2023-10-04 21:55:41.665422459 +0300
@@ -1925,17 +1925,20 @@
EXPLAIN (COSTS OFF)
SELECT count(*) FROM tenk1
WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
-                                               QUERY PLAN
---------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------
Aggregate
->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         Recheck Cond: ((((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3))) OR (thousand = 41))
->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_thous_tenthous
-                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 42) AND (tenthous = 1))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 42) AND (tenthous = 3))
->  Bitmap Index Scan on tenk1_thous_tenthous
Index Cond: (thousand = 41)
-(8 rows)
+(11 rows)

I think this query is not converted, because you only convert
top-level ORs in the transform_ors() function. But in the example
given, the target OR lays under AND, which in turn lays under another
OR. I think you need to make transform_ors() recursive to handle
cases like this.

I wonder about the default value of the parameter or_transform_limit
of 500. In [1] and [2] you show the execution time degradation from 0
to ~500 OR clauses. I made a simple SQL script with the query "SELECT
* FROM pgbench_accounts a WHERE aid = 1 OR aid = 2 OR ... OR aid =
100;". The pgbench results for a single connection in prepared mode
are the following.
master: 936 tps
patched (or_transform_limit == 0) :1414 tps
So, transformation to ANY obviously accelerates the execution.

I think it's important to identify the cases where this patch causes
the degradation. Generally, I don't see why ANY could be executed
slower than the equivalent OR clause. So, the possible degradation
cases are slower plan generation and worse plans. I managed to find
both.

As you stated before, currently the OR transformation has a quadratic
complexity depending on the number of or-clause-groups. I made a
simple test to evaluate this. containing 10000 or-clause-groups.
SELECT * FROM pgbench_accounts a WHERE aid + 1 * bid = 1 OR aid + 2 *
bid = 1 OR ... OR aid + 10000 * bid = 1;
master: 316ms
patched: 7142ms
Note, that the current or_transform_limit GUC parameter is not capable
of cutting such cases, because it cuts cases lower than the limit not
higher than the limit. In the comment, you mention that we could
invent something like hash to handle this. Hash should be nice, but
the problem is that we currently don't have a generic facility to hash
nodes (or even order them). It would be nice to add this facility,
that would be quite a piece of work. I would propose to limit this
patch for now to handle just a single Var node as a non-const side of
the clause and implement a simple hash for Vars.

Another problem is the possible generation of worse plans. I made an
example table with two partial indexes.
create table test as (select (random()*10)::int x, (random()*1000) y
from generate_series(1,1000000) i);
create index test_x_1_y on test (y) where x = 1;
create index test_x_2_y on test (y) where x = 2;
vacuum analyze test;

Without the transformation of ORs to ANY, our planner manages to use
both indexes with a Bitmap scan.
# explain select * from test where (x = 1 or x = 2) and y = 100;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on test (cost=8.60..12.62 rows=1 width=12)
Recheck Cond: (((y = '100'::double precision) AND (x = 1)) OR ((y =
'100'::double precision) AND (x = 2)))
-> BitmapOr (cost=8.60..8.60 rows=1 width=0)
-> Bitmap Index Scan on test_x_1_y (cost=0.00..4.30 rows=1 width=0)
Index Cond: (y = '100'::double precision)
-> Bitmap Index Scan on test_x_2_y (cost=0.00..4.30 rows=1 width=0)
Index Cond: (y = '100'::double precision)
(7 rows)

With transformation, the planner can't use indexes.
# explain select * from test where (x = 1 or x = 2) and y = 100;
QUERY PLAN
-----------------------------------------------------------------------------
Gather (cost=1000.00..12690.10 rows=1 width=12)
Workers Planned: 2
-> Parallel Seq Scan on test (cost=0.00..11690.00 rows=1 width=12)
Filter: ((x = ANY (ARRAY[1, 2])) AND (y = '100'::double precision))
(4 rows)

The solution I see would be to tech Bitmap scan to handle ANY clause
in the same way as the OR clause. I think the entry point for the
relevant logic is the choose_bitmap_and() function.

Regarding the GUC parameter, I don't see we need a limit. It's not
yet clear whether a small number or a large number of OR clauses are
more favorable for transformation. I propose to have just a boolean
enable_or_transformation GUC.

Links
1. /messages/by-id/6b97b517-f36a-f0c6-3b3a-0cf8cfba220c@yandex.ru
2. /messages/by-id/938d82e1-98df-6553-334c-9db7c4e288ae@yandex.ru

------
Regards,
Alexander Korotkov

#77a.rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#76)
Re: POC, WIP: OR-clause support for indexes

Hi! Thank you for your review!

On 15.10.2023 01:34, Alexander Korotkov wrote:

Hi, Alena!

Thank you for your work on the subject.

On Wed, Oct 4, 2023 at 10:21 PM a.rybakina<a.rybakina@postgrespro.ru> wrote:

I fixed the kernel dump issue and all the regression tests were successful, but I discovered another problem when I added my own regression tests.
Some queries that contain "or" expressions do not convert to "ANY". I have described this in more detail using diff as expected and real results:

diff -U3 /home/alena/postgrespro__copy6/src/test/regress/expected/create_index.out /home/alena/postgrespro__copy6/src/test/regress/results/create_index.out
--- /home/alena/postgrespro__copy6/src/test/regress/expected/create_index.out 2023-10-04 21:54:12.496282667 +0300
+++ /home/alena/postgrespro__copy6/src/test/regress/results/create_index.out  2023-10-04 21:55:41.665422459 +0300
@@ -1925,17 +1925,20 @@
EXPLAIN (COSTS OFF)
SELECT count(*) FROM tenk1
WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
-                                               QUERY PLAN
---------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------
Aggregate
->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         Recheck Cond: ((((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3))) OR (thousand = 41))
->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_thous_tenthous
-                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 42) AND (tenthous = 1))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 42) AND (tenthous = 3))
->  Bitmap Index Scan on tenk1_thous_tenthous
Index Cond: (thousand = 41)
-(8 rows)
+(11 rows)

I think this query is not converted, because you only convert
top-level ORs in the transform_ors() function. But in the example
given, the target OR lays under AND, which in turn lays under another
OR. I think you need to make transform_ors() recursive to handle
cases like this.

Yes, you are right, it seems that a recursive method is needed here.

I wonder about the default value of the parameter or_transform_limit
of 500. In [1] and [2] you show the execution time degradation from 0
to ~500 OR clauses. I made a simple SQL script with the query "SELECT
* FROM pgbench_accounts a WHERE aid = 1 OR aid = 2 OR ... OR aid =
100;". The pgbench results for a single connection in prepared mode
are the following.
master: 936 tps
patched (or_transform_limit == 0) :1414 tps
So, transformation to ANY obviously accelerates the execution.

I think it's important to identify the cases where this patch causes
the degradation. Generally, I don't see why ANY could be executed
slower than the equivalent OR clause. So, the possible degradation
cases are slower plan generation and worse plans. I managed to find
both.

As you stated before, currently the OR transformation has a quadratic
complexity depending on the number of or-clause-groups. I made a
simple test to evaluate this. containing 10000 or-clause-groups.
SELECT * FROM pgbench_accounts a WHERE aid + 1 * bid = 1 OR aid + 2 *
bid = 1 OR ... OR aid + 10000 * bid = 1;
master: 316ms
patched: 7142ms
Note, that the current or_transform_limit GUC parameter is not capable
of cutting such cases, because it cuts cases lower than the limit not
higher than the limit. In the comment, you mention that we could
invent something like hash to handle this. Hash should be nice, but
the problem is that we currently don't have a generic facility to hash
nodes (or even order them). It would be nice to add this facility,
that would be quite a piece of work. I would propose to limit this
patch for now to handle just a single Var node as a non-const side of
the clause and implement a simple hash for Vars.

I ran the query and saw that you were right, this place in the patch
turns out to be very expensive. In addition to the hash, I saw a second
solution to this problem - parameterize constants and store them in the
list, but this will not be such a universal solution as hashing. If the
variable, not the constant, changes, parameterization will not help.

I agree with your suggestion to try adding hashing. I'll take a closer
look at this.

Another problem is the possible generation of worse plans. I made an
example table with two partial indexes.
create table test as (select (random()*10)::int x, (random()*1000) y
from generate_series(1,1000000) i);
create index test_x_1_y on test (y) where x = 1;
create index test_x_2_y on test (y) where x = 2;
vacuum analyze test;

Without the transformation of ORs to ANY, our planner manages to use
both indexes with a Bitmap scan.
# explain select * from test where (x = 1 or x = 2) and y = 100;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on test (cost=8.60..12.62 rows=1 width=12)
Recheck Cond: (((y = '100'::double precision) AND (x = 1)) OR ((y =
'100'::double precision) AND (x = 2)))
-> BitmapOr (cost=8.60..8.60 rows=1 width=0)
-> Bitmap Index Scan on test_x_1_y (cost=0.00..4.30 rows=1 width=0)
Index Cond: (y = '100'::double precision)
-> Bitmap Index Scan on test_x_2_y (cost=0.00..4.30 rows=1 width=0)
Index Cond: (y = '100'::double precision)
(7 rows)

With transformation, the planner can't use indexes.
# explain select * from test where (x = 1 or x = 2) and y = 100;
QUERY PLAN
-----------------------------------------------------------------------------
Gather (cost=1000.00..12690.10 rows=1 width=12)
Workers Planned: 2
-> Parallel Seq Scan on test (cost=0.00..11690.00 rows=1 width=12)
Filter: ((x = ANY (ARRAY[1, 2])) AND (y = '100'::double precision))
(4 rows)

The solution I see would be to tech Bitmap scan to handle ANY clause
in the same way as the OR clause. I think the entry point for the
relevant logic is the choose_bitmap_and() function.

It's a good idea, I'll try.
But to be honest, I'm afraid that problems with selectivity may come up
again and in order to solve them, additional processing of RestrictInfo
may be required, which will be unnecessarily expensive. As far as I
understand, at this stage we are creating indexes for AND expressions
and there is a risk that its transformation may cause the need to change
references in all possible places where it was referenced.

Regarding the GUC parameter, I don't see we need a limit. It's not
yet clear whether a small number or a large number of OR clauses are
more favorable for transformation. I propose to have just a boolean
enable_or_transformation GUC.

Links
1./messages/by-id/6b97b517-f36a-f0c6-3b3a-0cf8cfba220c@yandex.ru
2./messages/by-id/938d82e1-98df-6553-334c-9db7c4e288ae@yandex.ru

I tend to agree with you and I see that in some cases it really doesn't
help.

#78a.rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#76)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 15.10.2023 01:34, Alexander Korotkov wrote:

Hi, Alena!

Thank you for your work on the subject.

On Wed, Oct 4, 2023 at 10:21 PM a.rybakina <a.rybakina@postgrespro.ru> wrote:

I fixed the kernel dump issue and all the regression tests were successful, but I discovered another problem when I added my own regression tests.
Some queries that contain "or" expressions do not convert to "ANY". I have described this in more detail using diff as expected and real results:

diff -U3 /home/alena/postgrespro__copy6/src/test/regress/expected/create_index.out /home/alena/postgrespro__copy6/src/test/regress/results/create_index.out
--- /home/alena/postgrespro__copy6/src/test/regress/expected/create_index.out 2023-10-04 21:54:12.496282667 +0300
+++ /home/alena/postgrespro__copy6/src/test/regress/results/create_index.out  2023-10-04 21:55:41.665422459 +0300
@@ -1925,17 +1925,20 @@
EXPLAIN (COSTS OFF)
SELECT count(*) FROM tenk1
WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
-                                               QUERY PLAN
---------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------
Aggregate
->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         Recheck Cond: ((((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3))) OR (thousand = 41))
->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_thous_tenthous
-                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 42) AND (tenthous = 1))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 42) AND (tenthous = 3))
->  Bitmap Index Scan on tenk1_thous_tenthous
Index Cond: (thousand = 41)
-(8 rows)
+(11 rows)

I think this query is not converted, because you only convert
top-level ORs in the transform_ors() function. But in the example
given, the target OR lays under AND, which in turn lays under another
OR. I think you need to make transform_ors() recursive to handle
cases like this.

I wonder about the default value of the parameter or_transform_limit
of 500. In [1] and [2] you show the execution time degradation from 0
to ~500 OR clauses. I made a simple SQL script with the query "SELECT
* FROM pgbench_accounts a WHERE aid = 1 OR aid = 2 OR ... OR aid =
100;". The pgbench results for a single connection in prepared mode
are the following.
master: 936 tps
patched (or_transform_limit == 0) :1414 tps
So, transformation to ANY obviously accelerates the execution.

I think it's important to identify the cases where this patch causes
the degradation. Generally, I don't see why ANY could be executed
slower than the equivalent OR clause. So, the possible degradation
cases are slower plan generation and worse plans. I managed to find
both.

As you stated before, currently the OR transformation has a quadratic
complexity depending on the number of or-clause-groups. I made a
simple test to evaluate this. containing 10000 or-clause-groups.
SELECT * FROM pgbench_accounts a WHERE aid + 1 * bid = 1 OR aid + 2 *
bid = 1 OR ... OR aid + 10000 * bid = 1;
master: 316ms
patched: 7142ms
Note, that the current or_transform_limit GUC parameter is not capable
of cutting such cases, because it cuts cases lower than the limit not
higher than the limit. In the comment, you mention that we could
invent something like hash to handle this. Hash should be nice, but
the problem is that we currently don't have a generic facility to hash
nodes (or even order them). It would be nice to add this facility,
that would be quite a piece of work. I would propose to limit this
patch for now to handle just a single Var node as a non-const side of
the clause and implement a simple hash for Vars.

Another problem is the possible generation of worse plans. I made an
example table with two partial indexes.
create table test as (select (random()*10)::int x, (random()*1000) y
from generate_series(1,1000000) i);
create index test_x_1_y on test (y) where x = 1;
create index test_x_2_y on test (y) where x = 2;
vacuum analyze test;

Without the transformation of ORs to ANY, our planner manages to use
both indexes with a Bitmap scan.
# explain select * from test where (x = 1 or x = 2) and y = 100;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on test (cost=8.60..12.62 rows=1 width=12)
Recheck Cond: (((y = '100'::double precision) AND (x = 1)) OR ((y =
'100'::double precision) AND (x = 2)))
-> BitmapOr (cost=8.60..8.60 rows=1 width=0)
-> Bitmap Index Scan on test_x_1_y (cost=0.00..4.30 rows=1 width=0)
Index Cond: (y = '100'::double precision)
-> Bitmap Index Scan on test_x_2_y (cost=0.00..4.30 rows=1 width=0)
Index Cond: (y = '100'::double precision)
(7 rows)

With transformation, the planner can't use indexes.
# explain select * from test where (x = 1 or x = 2) and y = 100;
QUERY PLAN
-----------------------------------------------------------------------------
Gather (cost=1000.00..12690.10 rows=1 width=12)
Workers Planned: 2
-> Parallel Seq Scan on test (cost=0.00..11690.00 rows=1 width=12)
Filter: ((x = ANY (ARRAY[1, 2])) AND (y = '100'::double precision))
(4 rows)

The solution I see would be to tech Bitmap scan to handle ANY clause
in the same way as the OR clause. I think the entry point for the
relevant logic is the choose_bitmap_and() function.

Regarding the GUC parameter, I don't see we need a limit. It's not
yet clear whether a small number or a large number of OR clauses are
more favorable for transformation. I propose to have just a boolean
enable_or_transformation GUC.

I removed the limit from the hook, left the option to enable it or not.

I replaced the data structure so that the groups were formed not in a
list, but in a hash table. It seems to work fine, but I haven't figured
out yet why in some cases the regression test results are different and
the function doesn't work.

So far, I have formed a patch for the version where the conversion takes
place in parsing, since so far this patch looks the most reliable for me

For convenience, I have formed a patch for the very first version so far.

I have a suspicion that the problem is in the part where we form a hash
from a string. I'm still figuring it out.

Attachments:

v8.0-Replace-OR-clause-to-ANY-expressions.-Replace-X-N1-O.patchtext/x-patch; charset=UTF-8; name=v8.0-Replace-OR-clause-to-ANY-expressions.-Replace-X-N1-O.patchDownload
From 35b4cd3ee48a5c5893a731439f5099c2736a2a66 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Wed, 25 Oct 2023 13:52:55 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>, Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/parser/parse_expr.c               | 254 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 115 ++++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  50 ++++
 src/test/regress/expected/partition_prune.out | 179 ++++++++++++
 src/test/regress/expected/tidscan.out         |  17 ++
 src/test/regress/sql/create_index.sql         |  32 +++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 13 files changed, 698 insertions(+), 2 deletions(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344c..93ae5d2dbc9 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -18,6 +18,7 @@
 #include "catalog/pg_aggregate.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
+#include "common/hashfn.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
@@ -43,6 +44,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		or_transform_limit = false;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -98,7 +100,257 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 							  Node *ltree, Node *rtree, int location);
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
+typedef struct OrClauseGroupEntry
+{
+	char		   *hash_leftvar_key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int
+or_name_match(const void *key1, const void *key2, Size keysize)
+{
+	const char *name1 = *(const char *const *) key1;
+	const char *name2 = *(const char *const *) key2;
+
+	return strcmp(name1, name2);
+}
+
+static uint32
+or_name_hash(const void *key, Size keysize)
+{
+	const char *name = *(const char *const *) key;
+
+	return DatumGetInt32(hash_any((unsigned char *)name, strlen(name)));
+}
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	ListCell	   *lc;
+	HASHCTL			info;
+	HTAB 		   *or_group_htab = NULL;
+	int 			len_ors = list_length(expr_orig->args);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(char *);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = or_name_hash;
+	info.match = or_name_match;
+	or_group_htab = hash_create("OR Groups",
+									  len_ors,
+									  &info,
+									  HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR || !or_transform_limit || len_ors == 1 || !or_group_htab)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		OrClauseGroupEntry *gentry;
+		bool				found;
+		char		   	   *str;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		str = nodeToString(nconst_expr);
+		gentry = hash_search(or_group_htab, &str, HASH_FIND, &found);
+
+		if (found)
+		{
+			elog(WARNING, "find anything");
+			gentry->consts = lappend(gentry->consts, const_expr);
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+		}
+
+		/* New clause group needed */
+		gentry = hash_search(or_group_htab, &str, HASH_ENTER, &found);
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		gentry->hash_leftvar_key = str;
+	}
+
+	if (or_group_htab && hash_get_num_entries(or_group_htab) < 1)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		HASH_SEQ_STATUS		hash_seq;
+		OrClauseGroupEntry *gentry;
+
+		hash_seq_init(&hash_seq, or_group_htab);
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		while ((gentry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
+		{
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
 
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+			}
+			hash_search(or_group_htab, &gentry->hash_leftvar_key, HASH_REMOVE, NULL);
+		}
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +464,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 4c585741661..634be59e538 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1038,6 +1038,16 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"or_transform_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&or_transform_limit,
+		false,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..7a6943c116c 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool or_transform_limit;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..29c2bc6a2b2 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,121 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET or_transform_limit = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET or_transform_limit;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..c052b113eea 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ or_transform_limit
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index b95d30f6586..a3ef1afd1fd 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,6 +4207,56 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET or_transform_limit = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
+
+RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c0556..1789d3c1fd7 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET or_transform_limit = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET or_transform_limit;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET or_transform_limit = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET or_transform_limit;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..8a31e2e670d 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET or_transform_limit = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET or_transform_limit;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..a709b2c1abc 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET or_transform_limit = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET or_transform_limit;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 3e5032b04dd..481898c2987 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1396,6 +1396,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET or_transform_limit = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET or_transform_limit;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827f..88709910592 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET or_transform_limit = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET or_transform_limit;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET or_transform_limit = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET or_transform_limit;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..c735e219589 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET or_transform_limit = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET or_transform_limit;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 06b25617bc9..701b1075ffc 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1635,6 +1635,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

#79Robert Haas
robertmhaas@gmail.com
In reply to: Alexander Korotkov (#76)
Re: POC, WIP: OR-clause support for indexes

On Sat, Oct 14, 2023 at 6:37 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

Regarding the GUC parameter, I don't see we need a limit. It's not
yet clear whether a small number or a large number of OR clauses are
more favorable for transformation. I propose to have just a boolean
enable_or_transformation GUC.

That's a poor solution. So is the GUC patch currently has
(or_transform_limit). What you need is a heuristic that figures out
fairly reliably whether the transformation is going to be better or
worse. Or else, do the whole thing in some other way that is always
same-or-better.

In general, adding GUCs makes sense when the user knows something that
we can't know. For example, shared_buffers makes some sense because,
even if we discovered how much memory the machine has, we can't know
how much of it the user wants to devote to PostgreSQL as opposed to
anything else. And track_io_timing makes sense because we can't know
whether the user wants to pay the price of gathering that additional
data. But GUCs are a poor way of handling cases where the real problem
is that we don't know what code to write. In this case, some queries
will be better with enable_or_transformation=on, and some will be
better with enable_or_transformation=off. Since we don't know which
will work out better, we make the user figure it out and set the GUC,
possibly differently for each query. That's terrible. It's the query
optimizer's whole job to figure out which transformations will speed
up the query. It shouldn't turn around and punt the decision back to
the user.

Notice that superficially-similar GUCs like enable_seqscan aren't
really the same thing at all. That's just for developer testing and
debugging. Nobody expects that you have to adjust that GUC on a
production system - ever.

--
Robert Haas
EDB: http://www.enterprisedb.com

#80Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Robert Haas (#79)
Re: POC, WIP: OR-clause support for indexes

Hi! Thank you for your feedback!

On 25.10.2023 22:54, Robert Haas wrote:

On Sat, Oct 14, 2023 at 6:37 PM Alexander Korotkov<aekorotkov@gmail.com> wrote:

Regarding the GUC parameter, I don't see we need a limit. It's not
yet clear whether a small number or a large number of OR clauses are
more favorable for transformation. I propose to have just a boolean
enable_or_transformation GUC.

That's a poor solution. So is the GUC patch currently has
(or_transform_limit). What you need is a heuristic that figures out
fairly reliably whether the transformation is going to be better or
worse. Or else, do the whole thing in some other way that is always
same-or-better.

In general, adding GUCs makes sense when the user knows something that
we can't know. For example, shared_buffers makes some sense because,
even if we discovered how much memory the machine has, we can't know
how much of it the user wants to devote to PostgreSQL as opposed to
anything else. And track_io_timing makes sense because we can't know
whether the user wants to pay the price of gathering that additional
data. But GUCs are a poor way of handling cases where the real problem
is that we don't know what code to write. In this case, some queries
will be better with enable_or_transformation=on, and some will be
better with enable_or_transformation=off. Since we don't know which
will work out better, we make the user figure it out and set the GUC,
possibly differently for each query. That's terrible. It's the query
optimizer's whole job to figure out which transformations will speed
up the query. It shouldn't turn around and punt the decision back to
the user.

Notice that superficially-similar GUCs like enable_seqscan aren't
really the same thing at all. That's just for developer testing and
debugging. Nobody expects that you have to adjust that GUC on a
production system - ever.

I noticed that the costs of expressions are different and it can help to
assess when it is worth leaving the conversion, when not.

With small amounts of "OR" elements, the cost of orexpr is lower than
with "ANY", on the contrary, higher.

postgres=# SET or_transform_limit = 500;
EXPLAIN (analyze)
SELECT oid,relname FROM pg_class
WHERE
  oid = 13779 AND (oid = 2 OR oid = 4 OR oid = 5)
;
SET
                                                          QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------
 Index Scan using pg_class_oid_index on pg_class  (*cost=0.27..8.30*
rows=1 width=68) (actual time=0.105..0.106 rows=0 loops=1)
   Index Cond: (oid = '13779'::oid)
   Filter: ((oid = '2'::oid) OR (oid = '4'::oid) OR (oid = '5'::oid))
 Planning Time: 0.323 ms
 Execution Time: 0.160 ms

(5 rows)

postgres=# SET or_transform_limit = 0;
EXPLAIN (analyze)
SELECT oid,relname FROM pg_class
WHERE
  oid = 13779 AND (oid = 2 OR oid = 4 OR oid = 5)
;
SET
                                                          QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
 Index Scan using pg_class_oid_index on pg_class  (*cost=0.27..16.86*
rows=1 width=68) (actual time=0.160..0.161 rows=0 loops=1)
   Index Cond: ((oid = ANY (ARRAY['2'::oid, '4'::oid, '5'::oid])) AND
(oid = '13779'::oid))
 Planning Time: 4.515 ms
 Execution Time: 0.313 ms
(4 rows)

Index Scan using pg_class_oid_index on pg_class  (*cost=0.27..2859.42*
rows=414 width=68) (actual time=1.504..34.183 rows=260 loops=1)
   Index Cond: (oid = ANY (ARRAY['1'::oid, '2'::oid, '3'::oid,
'4'::oid, '5'::oid, '6'::oid, '7'::oid,

Bitmap Heap Scan on pg_class  (*cost=43835.00..54202.14* rows=414
width=68) (actual time=39.958..41.293 rows=260 loops=1)
   Recheck Cond: ((oid = '1'::oid) OR (oid = '2'::oid) OR (oid =
'3'::oid) OR (oid = '4'::oid) OR (oid =

I think we could see which value is lower, and if lower with expressions
converted to ANY, then work with it further, otherwise work with the
original "OR" expressions. But we still need to make this conversion to
find out its cost.

In addition, I will definitely have to postpone the transformation of
"OR" to "ANY" at the stage of creating indexes (?) or maybe a little
earlier so that I have to count only the cost of the transformed
expression.

#81Robert Haas
robertmhaas@gmail.com
In reply to: Alena Rybakina (#80)
Re: POC, WIP: OR-clause support for indexes

On Thu, Oct 26, 2023 at 3:47 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

With small amounts of "OR" elements, the cost of orexpr is lower than with "ANY", on the contrary, higher.

Alexander's example seems to show that it's not that simple. If I'm
reading his example correctly, with things like aid = 1, the
transformation usually wins even if the number of things in the OR
expression is large, but with things like aid + 1 * bid = 1, the
transformation seems to lose at least with larger numbers of items. So
it's not JUST the number of OR elements but also what they contain,
unless I'm misunderstanding his point.

Index Scan using pg_class_oid_index on pg_class (cost=0.27..2859.42 rows=414 width=68) (actual time=1.504..34.183 rows=260 loops=1)
Index Cond: (oid = ANY (ARRAY['1'::oid, '2'::oid, '3'::oid, '4'::oid, '5'::oid, '6'::oid, '7'::oid,

Bitmap Heap Scan on pg_class (cost=43835.00..54202.14 rows=414 width=68) (actual time=39.958..41.293 rows=260 loops=1)
Recheck Cond: ((oid = '1'::oid) OR (oid = '2'::oid) OR (oid = '3'::oid) OR (oid = '4'::oid) OR (oid =

I think we could see which value is lower, and if lower with expressions converted to ANY, then work with it further, otherwise work with the original "OR" expressions. But we still need to make this conversion to find out its cost.

To me, this sort of output suggests that perhaps the transformation is
being done in the wrong place. I expect that we have to decide whether
to convert from OR to = ANY(...) at a very early stage of the planner,
before we have any idea what the selected path will ultimately be. But
this output suggests that we want the answer to depend on which kind
of path is going to be faster, which would seem to argue for doing
this sort of transformation as part of path generation for only those
paths that will benefit from it, rather than during earlier phases of
expression processing/simplification.

I'm not sure I have the full picture here, though, so I might have
this all wrong.

--
Robert Haas
EDB: http://www.enterprisedb.com

#82Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Robert Haas (#81)
Re: POC, WIP: OR-clause support for indexes

On 26.10.2023 22:58, Robert Haas wrote:

On Thu, Oct 26, 2023 at 3:47 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

With small amounts of "OR" elements, the cost of orexpr is lower than with "ANY", on the contrary, higher.

Alexander's example seems to show that it's not that simple. If I'm
reading his example correctly, with things like aid = 1, the
transformation usually wins even if the number of things in the OR
expression is large, but with things like aid + 1 * bid = 1, the
transformation seems to lose at least with larger numbers of items. So
it's not JUST the number of OR elements but also what they contain,
unless I'm misunderstanding his point.

Yes, I agree, with Alexander's example, this option will not help and
here I need to look inside Expr itself. But I noticed that such a
complex non-constant expression is always an OpExpr type, otherwise if
the non-constant part contains only one variable, then it is a Var type.
We can add a constraint that we will transform expressions with the
simple variables like x=1 or x=2 or x=3, etc., but expressions like
x*1+y=1 or x*2+y=2... we ignore.

But then, we do not consider expressions when the nonconstant part is
always the same for expressions. For example, we could transform x*1+y=1
or x*1+y=2... to x*1+y = ANY([1,2,...]). But I think it's not so
critical, because such cases are rare.

Index Scan using pg_class_oid_index on pg_class (cost=0.27..2859.42 rows=414 width=68) (actual time=1.504..34.183 rows=260 loops=1)
Index Cond: (oid = ANY (ARRAY['1'::oid, '2'::oid, '3'::oid, '4'::oid, '5'::oid, '6'::oid, '7'::oid,

Bitmap Heap Scan on pg_class (cost=43835.00..54202.14 rows=414 width=68) (actual time=39.958..41.293 rows=260 loops=1)
Recheck Cond: ((oid = '1'::oid) OR (oid = '2'::oid) OR (oid = '3'::oid) OR (oid = '4'::oid) OR (oid =

I think we could see which value is lower, and if lower with expressions converted to ANY, then work with it further, otherwise work with the original "OR" expressions. But we still need to make this conversion to find out its cost.

To me, this sort of output suggests that perhaps the transformation is
being done in the wrong place. I expect that we have to decide whether
to convert from OR to = ANY(...) at a very early stage of the planner,
before we have any idea what the selected path will ultimately be. But
this output suggests that we want the answer to depend on which kind
of path is going to be faster, which would seem to argue for doing
this sort of transformation as part of path generation for only those
paths that will benefit from it, rather than during earlier phases of
expression processing/simplification.

I'm not sure I have the full picture here, though, so I might have
this all wrong.

This would be the most ideal option, and to be honest, I like the
conversion at an early stage also because there are no problems with
selectivity or link updates if we changed the structure of RestrictInfo
of relation.

But in terms of calculating which option is better to use transformed or
original, I think this solution might be complicated, since we need not
only to highlight the cases in which the transformation wins in
principle, but also with which types of data it will work best and there
is a risk of missing some cases and we may need the own evaluation
model. Now it's hard for me to come up with something simple.

The cost option seems simpler and clearer to me, but yes, it is
difficult to decide when it is better to do the conversion for the most
correct estimate.

--
Regards,
Alena Rybakina

In reply to: Robert Haas (#81)
Re: POC, WIP: OR-clause support for indexes

On Thu, Oct 26, 2023 at 12:59 PM Robert Haas <robertmhaas@gmail.com> wrote:

Alexander's example seems to show that it's not that simple. If I'm
reading his example correctly, with things like aid = 1, the
transformation usually wins even if the number of things in the OR
expression is large, but with things like aid + 1 * bid = 1, the
transformation seems to lose at least with larger numbers of items. So
it's not JUST the number of OR elements but also what they contain,
unless I'm misunderstanding his point.

Alexander said "Generally, I don't see why ANY could be executed
slower than the equivalent OR clause". I understood that this was his
way of expressing the following idea:

"In principle, there is no reason to expect execution of ANY() to be
slower than execution of an equivalent OR clause (except for
noise-level differences). While it might not actually look that way
for every single type of plan you can imagine right now, that doesn't
argue for making a cost-based decision. It actually argues for fixing
the underlying issue, which can't possibly be due to some kind of
fundamental advantage enjoyed by expression evaluation with ORs".

This is also what I think of all this.

Alexander's partial index example had this quality to it. Obviously,
the planner *could* be taught to do the right thing with such a case,
with a little more work. The fact that it doesn't right now is
definitely a problem, and should probably be treated as a blocker for
this patch. But that doesn't really argue against the general idea
behind the patch -- it just argues for fixing that one problem.

There may also be a separate problem that comes from the added planner
cycles required to do the transformation -- particularly in extreme or
adversarial cases. We should worry about that, too. But, again, it
doesn't change the basic fact, which is that having a
standard/normalized representation of OR lists/DNF transformation is
extremely useful in general, and *shouldn't* result in any real
slowdowns at execution time if done well.

To me, this sort of output suggests that perhaps the transformation is
being done in the wrong place. I expect that we have to decide whether
to convert from OR to = ANY(...) at a very early stage of the planner,
before we have any idea what the selected path will ultimately be. But
this output suggests that we want the answer to depend on which kind
of path is going to be faster, which would seem to argue for doing
this sort of transformation as part of path generation for only those
paths that will benefit from it, rather than during earlier phases of
expression processing/simplification.

I don't think that that's the right direction. They're semantically
equivalent things. But a SAOP-based plan can be fundamentally better,
since SAOPs enable passing down useful context to index AMs (at least
nbtree). And because we can use a hash table for SAOP expression
evaluation. It's a higher level, standardized, well optimized way of
expressing exactly the same concept.

I can come up with a case that'll be orders of magnitude more
efficient with this patch, despite the transformation process only
affecting a small OR list of 3 or 5 elements -- a 100x reduction in
heap page accesses is quite possible. This is particularly likely to
come up if you assume that the nbtree patch that I'm currently working
on is also available. In general, I think that we totally over-rely on
bitmap index scans, especially BitmapOrs.

--
Peter Geoghegan

#84Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Peter Geoghegan (#83)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 27.10.2023 00:04, Peter Geoghegan wrote:

On Thu, Oct 26, 2023 at 12:59 PM Robert Haas<robertmhaas@gmail.com> wrote:

Alexander's example seems to show that it's not that simple. If I'm
reading his example correctly, with things like aid = 1, the
transformation usually wins even if the number of things in the OR
expression is large, but with things like aid + 1 * bid = 1, the
transformation seems to lose at least with larger numbers of items. So
it's not JUST the number of OR elements but also what they contain,
unless I'm misunderstanding his point.

Alexander said "Generally, I don't see why ANY could be executed
slower than the equivalent OR clause". I understood that this was his
way of expressing the following idea:

"In principle, there is no reason to expect execution of ANY() to be
slower than execution of an equivalent OR clause (except for
noise-level differences). While it might not actually look that way
for every single type of plan you can imagine right now, that doesn't
argue for making a cost-based decision. It actually argues for fixing
the underlying issue, which can't possibly be due to some kind of
fundamental advantage enjoyed by expression evaluation with ORs".

This is also what I think of all this.

Alexander's partial index example had this quality to it. Obviously,
the planner *could* be taught to do the right thing with such a case,
with a little more work. The fact that it doesn't right now is
definitely a problem, and should probably be treated as a blocker for
this patch. But that doesn't really argue against the general idea
behind the patch -- it just argues for fixing that one problem.

There may also be a separate problem that comes from the added planner
cycles required to do the transformation -- particularly in extreme or
adversarial cases. We should worry about that, too. But, again, it
doesn't change the basic fact, which is that having a
standard/normalized representation of OR lists/DNF transformation is
extremely useful in general, and *shouldn't* result in any real
slowdowns at execution time if done well.

I think it would be more correct to finalize the current approach to
converting "OR" expressions to "ANY", since quite a few problems related
to this patch have already been found here, I think you can solve them
first, and then you can move on.

To me, this sort of output suggests that perhaps the transformation is
being done in the wrong place. I expect that we have to decide whether
to convert from OR to = ANY(...) at a very early stage of the planner,
before we have any idea what the selected path will ultimately be. But
this output suggests that we want the answer to depend on which kind
of path is going to be faster, which would seem to argue for doing
this sort of transformation as part of path generation for only those
paths that will benefit from it, rather than during earlier phases of
expression processing/simplification.

I don't think that that's the right direction. They're semantically
equivalent things. But a SAOP-based plan can be fundamentally better,
since SAOPs enable passing down useful context to index AMs (at least
nbtree). And because we can use a hash table for SAOP expression
evaluation. It's a higher level, standardized, well optimized way of
expressing exactly the same concept.

I can come up with a case that'll be orders of magnitude more
efficient with this patch, despite the transformation process only
affecting a small OR list of 3 or 5 elements -- a 100x reduction in
heap page accesses is quite possible. This is particularly likely to
come up if you assume that the nbtree patch that I'm currently working
on is also available. In general, I think that we totally over-rely on
bitmap index scans, especially BitmapOrs.

Regarding the application of the transformation at an early stage, the
patch is almost ready, except for solving cases related to queries that
work slower. I haven't figured out how to exclude such requests without
comparing the cost or parameter by the number of OR elements yet. The
simplest option is not to process Expr types (already mentioned earlier)
in the queries that Alexander gave as an example, but as I already said,
I don't like this approach very much.

--
Regards,
Alena Rybakina
Postgres Professional

#85Robert Haas
robertmhaas@gmail.com
In reply to: Peter Geoghegan (#83)
Re: POC, WIP: OR-clause support for indexes

On Thu, Oct 26, 2023 at 5:05 PM Peter Geoghegan <pg@bowt.ie> wrote:

On Thu, Oct 26, 2023 at 12:59 PM Robert Haas <robertmhaas@gmail.com> wrote:

Alexander's example seems to show that it's not that simple. If I'm
reading his example correctly, with things like aid = 1, the
transformation usually wins even if the number of things in the OR
expression is large, but with things like aid + 1 * bid = 1, the
transformation seems to lose at least with larger numbers of items. So
it's not JUST the number of OR elements but also what they contain,
unless I'm misunderstanding his point.

Alexander said "Generally, I don't see why ANY could be executed
slower than the equivalent OR clause". I understood that this was his
way of expressing the following idea:

"In principle, there is no reason to expect execution of ANY() to be
slower than execution of an equivalent OR clause (except for
noise-level differences). While it might not actually look that way
for every single type of plan you can imagine right now, that doesn't
argue for making a cost-based decision. It actually argues for fixing
the underlying issue, which can't possibly be due to some kind of
fundamental advantage enjoyed by expression evaluation with ORs".

This is also what I think of all this.

I agree with that, with some caveats, mainly that the reverse is to
some extent also true. Maybe not completely, because arguably the
ANY() formulation should just be straight-up easier to deal with, but
in principle, the two are equivalent and it shouldn't matter which
representation we pick.

But practically, it may, and we need to be sure that we don't put in
place a translation that is theoretically a win but in practice leads
to large regressions. Avoiding regressions here is more important than
capturing all the possible gains. A patch that wins in some scenarios
and does nothing in others can be committed; a patch that wins in even
more scenarios but causes serious regressions in some cases probably
can't.

--
Robert Haas
EDB: http://www.enterprisedb.com

#86Alexander Korotkov
aekorotkov@gmail.com
In reply to: Robert Haas (#85)
Re: POC, WIP: OR-clause support for indexes

On Mon, Oct 30, 2023 at 3:40 PM Robert Haas <robertmhaas@gmail.com> wrote:

On Thu, Oct 26, 2023 at 5:05 PM Peter Geoghegan <pg@bowt.ie> wrote:

On Thu, Oct 26, 2023 at 12:59 PM Robert Haas <robertmhaas@gmail.com> wrote:

Alexander's example seems to show that it's not that simple. If I'm
reading his example correctly, with things like aid = 1, the
transformation usually wins even if the number of things in the OR
expression is large, but with things like aid + 1 * bid = 1, the
transformation seems to lose at least with larger numbers of items. So
it's not JUST the number of OR elements but also what they contain,
unless I'm misunderstanding his point.

Alexander said "Generally, I don't see why ANY could be executed
slower than the equivalent OR clause". I understood that this was his
way of expressing the following idea:

"In principle, there is no reason to expect execution of ANY() to be
slower than execution of an equivalent OR clause (except for
noise-level differences). While it might not actually look that way
for every single type of plan you can imagine right now, that doesn't
argue for making a cost-based decision. It actually argues for fixing
the underlying issue, which can't possibly be due to some kind of
fundamental advantage enjoyed by expression evaluation with ORs".

This is also what I think of all this.

I agree with that, with some caveats, mainly that the reverse is to
some extent also true. Maybe not completely, because arguably the
ANY() formulation should just be straight-up easier to deal with, but
in principle, the two are equivalent and it shouldn't matter which
representation we pick.

But practically, it may, and we need to be sure that we don't put in
place a translation that is theoretically a win but in practice leads
to large regressions. Avoiding regressions here is more important than
capturing all the possible gains. A patch that wins in some scenarios
and does nothing in others can be committed; a patch that wins in even
more scenarios but causes serious regressions in some cases probably
can't.

+1
Sure, I've identified two cases where patch shows regression [1]. The
first one (quadratic complexity of expression processing) should be
already addressed by usage of hash. The second one (planning
regression with Bitmap OR) is not yet addressed.

Links
1. /messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.com

------
Regards,
Alexander Korotkov

In reply to: Robert Haas (#85)
Re: POC, WIP: OR-clause support for indexes

On Mon, Oct 30, 2023 at 6:40 AM Robert Haas <robertmhaas@gmail.com> wrote:

I agree with that, with some caveats, mainly that the reverse is to
some extent also true. Maybe not completely, because arguably the
ANY() formulation should just be straight-up easier to deal with, but
in principle, the two are equivalent and it shouldn't matter which
representation we pick.

I recently looked into MySQL's handling of these issues, which is more
mature and better documented than what we can do. EXPLAIN ANALYZE will
show an IN() list as if the query had been written as a list of ORs,
even though it can efficiently execute an index scan that uses
IN()/"OR var = constant" lists. So I agree with what you said here. It
is perhaps just as accident of history that we're talking about
converting to a ScalarArrayOpExpr, rather than talking about
converting to some other clause type that we associate with OR lists.

The essential point is that there ought to be one clause type that is
easier to deal with.

But practically, it may, and we need to be sure that we don't put in
place a translation that is theoretically a win but in practice leads
to large regressions. Avoiding regressions here is more important than
capturing all the possible gains. A patch that wins in some scenarios
and does nothing in others can be committed; a patch that wins in even
more scenarios but causes serious regressions in some cases probably
can't.

I agree. Most of the really big wins here will come from simple
transformations. I see no reason why we can't take an incremental
approach. In fact I think we almost have to do so, since as I
understand it the transformations are just infeasible in certain
extreme cases.

--
Peter Geoghegan

#88Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#86)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 30.10.2023 17:06, Alexander Korotkov wrote:

On Mon, Oct 30, 2023 at 3:40 PM Robert Haas <robertmhaas@gmail.com> wrote:

On Thu, Oct 26, 2023 at 5:05 PM Peter Geoghegan <pg@bowt.ie> wrote:

On Thu, Oct 26, 2023 at 12:59 PM Robert Haas <robertmhaas@gmail.com> wrote:

Alexander's example seems to show that it's not that simple. If I'm
reading his example correctly, with things like aid = 1, the
transformation usually wins even if the number of things in the OR
expression is large, but with things like aid + 1 * bid = 1, the
transformation seems to lose at least with larger numbers of items. So
it's not JUST the number of OR elements but also what they contain,
unless I'm misunderstanding his point.

Alexander said "Generally, I don't see why ANY could be executed
slower than the equivalent OR clause". I understood that this was his
way of expressing the following idea:

"In principle, there is no reason to expect execution of ANY() to be
slower than execution of an equivalent OR clause (except for
noise-level differences). While it might not actually look that way
for every single type of plan you can imagine right now, that doesn't
argue for making a cost-based decision. It actually argues for fixing
the underlying issue, which can't possibly be due to some kind of
fundamental advantage enjoyed by expression evaluation with ORs".

This is also what I think of all this.

I agree with that, with some caveats, mainly that the reverse is to
some extent also true. Maybe not completely, because arguably the
ANY() formulation should just be straight-up easier to deal with, but
in principle, the two are equivalent and it shouldn't matter which
representation we pick.

But practically, it may, and we need to be sure that we don't put in
place a translation that is theoretically a win but in practice leads
to large regressions. Avoiding regressions here is more important than
capturing all the possible gains. A patch that wins in some scenarios
and does nothing in others can be committed; a patch that wins in even
more scenarios but causes serious regressions in some cases probably
can't.

+1
Sure, I've identified two cases where patch shows regression [1]. The
first one (quadratic complexity of expression processing) should be
already addressed by usage of hash. The second one (planning
regression with Bitmap OR) is not yet addressed.

Links
1. /messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.com

I also support this approach. I have almost finished writing a patch
that fixes the first problem related to the quadratic complexity of
processing expressions by adding a hash table.

I also added a check: if the number of groups is equal to the number of
OR expressions, we assume that no expressions need to be converted and
interrupt further execution.

Now I am trying to fix the last problem in this patch: three tests have
indicated a problem related to incorrect conversion. I don't think it
can be serious, but I haven't figured out where the mistake is yet.

I added log like that: ERROR:  unrecognized node type: 0.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

v8.1-Replace-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=v8.1-Replace-OR-clause-to-ANY-expressions.patchDownload
From 3062a2408af258b9e327219020221b75501e8530 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Mon, 6 Nov 2023 16:48:00 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
---
 src/backend/parser/parse_expr.c               | 299 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 115 +++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  50 +++
 src/test/regress/expected/partition_prune.out | 179 +++++++++++
 src/test/regress/expected/tidscan.out         |  17 +
 src/test/regress/sql/create_index.sql         |  32 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 13 files changed, 743 insertions(+), 2 deletions(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344c..25a4235dbd9 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -18,6 +18,7 @@
 #include "catalog/pg_aggregate.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
+#include "common/hashfn.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
@@ -43,6 +44,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		or_transform_limit = false;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -98,7 +100,302 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 							  Node *ltree, Node *rtree, int location);
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
+typedef struct OrClauseGroupEntry
+{
+	char		   *hash_leftvar_key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int
+or_name_match(const void *key1, const void *key2, Size keysize)
+{
+	const char *name1 = *(const char *const *) key1;
+	const char *name2 = *(const char *const *) key2;
+
+	return strcmp(name1, name2);
+}
+
+static uint32
+or_name_hash(const void *key, Size keysize)
+{
+	const char *name = *(const char *const *) key;
+
+	return DatumGetInt32(hash_any((unsigned char *)name, strlen(name)));
+}
+
+static char *
+get_key_nconst_node(Node *nconst_node)
+{
+	if (IsA(nconst_node, OpExpr))
+	{
+		OpExpr 	   *clause = (OpExpr*) nconst_node;
+		OpExpr	   *temp = makeNode(OpExpr);
+
+		temp->opno = clause->opno;
+		temp->opfuncid = InvalidOid;
+		temp->opresulttype = clause->opresulttype;
+		temp->opretset = clause->opretset;
+		temp->opcollid = clause->opcollid;
+		temp->inputcollid = clause->inputcollid;
+		temp->location = -1;
+
+		temp->args = list_copy(clause->args);
+		return nodeToString(temp);
+	}
+	else if (IsA(nconst_node, Var))
+	{
+		Var	   *clause = (Var*) nconst_node;
+		Var	   *var = makeNode(Var);
+
+		var->varno = clause->varno;
+		var->varattno = clause->varattno;
+		var->vartype = clause->vartype;
+		var->vartypmod = clause->vartypmod;
+		var->varcollid = clause->varcollid;
+		var->varlevelsup = clause->varlevelsup;
+		var->varattnosyn = clause->varattno;
+		var->location = -1;
+
+		return nodeToString(var);
+	}
+	else
+	{
+		return NULL;
+	}
+ }
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	ListCell	   *lc;
+	HASHCTL			info;
+	HTAB 		   *or_group_htab = NULL;
+	int 			len_ors = list_length(expr_orig->args);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(char *);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = or_name_hash;
+	info.match = or_name_match;
+	or_group_htab = hash_create("OR Groups",
+									  len_ors,
+									  &info,
+									  HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR || !or_transform_limit || len_ors == 1 || !or_group_htab)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		OrClauseGroupEntry *gentry;
+		bool				found;
+		char		   	   *str;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
 
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		str = get_key_nconst_node(nconst_expr);
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)) || str == NULL)
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		gentry = hash_search(or_group_htab, &str, HASH_FIND, &found);
+
+		if (found)
+		{
+			gentry->consts = lappend(gentry->consts, const_expr);
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+		}
+
+		/* New clause group needed */
+		gentry = hash_search(or_group_htab, &str, HASH_ENTER, &found);
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		gentry->hash_leftvar_key = str;
+	}
+
+	if (or_group_htab && (hash_get_num_entries(or_group_htab) < 1 ||
+	                         hash_get_num_entries(or_group_htab) == len_ors))
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		hash_destroy(or_group_htab);
+		list_free(or_list);
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		HASH_SEQ_STATUS		hash_seq;
+		OrClauseGroupEntry *gentry;
+
+		hash_seq_init(&hash_seq, or_group_htab);
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		while ((gentry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
+		{
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+			}
+			hash_search(or_group_htab, &gentry->hash_leftvar_key, HASH_REMOVE, NULL);
+		}
+		hash_destroy(or_group_htab);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +509,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 7605eff9b9d..a8e8054e7e6 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,16 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"or_transform_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&or_transform_limit,
+		false,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..7a6943c116c 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool or_transform_limit;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..29c2bc6a2b2 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,121 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET or_transform_limit = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET or_transform_limit;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..c052b113eea 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ or_transform_limit
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 446959e3c5f..d8684e959e4 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,6 +4207,56 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET or_transform_limit = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
+
+RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c0556..1789d3c1fd7 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET or_transform_limit = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET or_transform_limit;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET or_transform_limit = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET or_transform_limit;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..8a31e2e670d 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET or_transform_limit = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET or_transform_limit;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..a709b2c1abc 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET or_transform_limit = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET or_transform_limit;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 66dd03dd88b..f5dcf8b90a7 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1396,6 +1396,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET or_transform_limit = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET or_transform_limit;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827f..88709910592 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET or_transform_limit = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET or_transform_limit;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET or_transform_limit = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET or_transform_limit;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..c735e219589 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET or_transform_limit = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET or_transform_limit;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 87c1aee379f..8cea6a6b851 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1638,6 +1638,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

#89Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#88)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 06.11.2023 16:51, Alena Rybakina wrote:

I also support this approach. I have almost finished writing a patch
that fixes the first problem related to the quadratic complexity of
processing expressions by adding a hash table.

I also added a check: if the number of groups is equal to the number
of OR expressions, we assume that no expressions need to be converted
and interrupt further execution.

Now I am trying to fix the last problem in this patch: three tests
have indicated a problem related to incorrect conversion. I don't
think it can be serious, but I haven't figured out where the mistake
is yet.

I added log like that: ERROR:  unrecognized node type: 0.

I fixed this issue and added some cosmetic refactoring.

The changes are presented in the or_patch_changes.diff file.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

or_patch_changes.difftext/x-patch; charset=UTF-8; name=or_patch_changes.diffDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 25a4235dbd9..46212a77c64 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -44,7 +44,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
-bool		or_transform_limit = false;
+bool		enable_or_transformation = false;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -108,7 +108,7 @@ typedef struct OrClauseGroupEntry
 	List		   *consts;
 	Oid				scalar_type;
 	Oid				opno;
-	Expr 		   *expr;
+	Node 		   *expr;
 } OrClauseGroupEntry;
 
 static int
@@ -189,16 +189,16 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 									  HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
 
 	/* If this is not an 'OR' expression, skip the transformation */
-	if (expr_orig->boolop != OR_EXPR || !or_transform_limit || len_ors == 1 || !or_group_htab)
+	if (expr_orig->boolop != OR_EXPR || !enable_or_transformation || len_ors == 1 || !or_group_htab)
 		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
 
 	foreach(lc, expr_orig->args)
 	{
 		Node			   *arg = lfirst(lc);
-		Node			   *orqual;
-		Node			   *const_expr;
-		Node			   *nconst_expr;
-		OrClauseGroupEntry *gentry;
+		Node			   *orqual = NULL;
+		Node			   *const_expr = NULL;
+		Node			   *nconst_expr = NULL;
+		OrClauseGroupEntry *gentry = NULL;
 		bool				found;
 		char		   	   *str;
 
@@ -270,7 +270,7 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 		gentry = hash_search(or_group_htab, &str, HASH_ENTER, &found);
 		gentry->node = nconst_expr;
 		gentry->consts = list_make1(const_expr);
-		gentry->expr = (Expr *) orqual;
+		gentry->expr = orqual;
 		gentry->hash_leftvar_key = str;
 	}
 
@@ -283,7 +283,6 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 		* transformed bool expression.
 		*/
 		hash_destroy(or_group_htab);
-		list_free(or_list);
 		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
 	}
 	else
@@ -345,9 +344,9 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 				 * OK: coerce all the right-hand non-Var inputs to the common
 				 * type and build an ArrayExpr for them.
 				 */
-				List	   *aexprs;
-				ArrayExpr  *newa;
-				ScalarArrayOpExpr *saopexpr;
+				List	   *aexprs = NIL;
+				ArrayExpr  *newa = NULL;
+				ScalarArrayOpExpr *saopexpr = NULL;
 				ListCell *l;
 
 				aexprs = NIL;
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 54fd09abde7..3411f023df8 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1049,12 +1049,12 @@ struct config_bool ConfigureNamesBool[] =
 		NULL, NULL, NULL
 	},
 	{
-		{"or_transform_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
 			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
 			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
 						 "to the clause 'x IN (c1,c2,...)'")
 		},
-		&or_transform_limit,
+		&enable_or_transformation,
 		false,
 		NULL, NULL, NULL
 	},
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7a6943c116c..3a87de02859 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,7 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
-extern PGDLLIMPORT bool or_transform_limit;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 29c2bc6a2b2..dbc8bc3bed0 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,7 +1883,7 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
-SET or_transform_limit = on;
+SET enable_or_transformation = on;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1997,7 +1997,7 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
-RESET or_transform_limit;
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index c052b113eea..0f2b1b16200 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,7 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
- or_transform_limit
+ enable_or_transformation
 (2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 97b4964812e..d969b31e3e3 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,7 +4207,7 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
-SET or_transform_limit = on;
+SET enable_or_transformation = on;
 explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
@@ -4256,7 +4256,7 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique1 = 3)
 (15 rows)
 
-RESET or_transform_limit;
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 1789d3c1fd7..fe815417c13 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,7 +101,7 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
-SET or_transform_limit = on;
+SET enable_or_transformation = on;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
                   QUERY PLAN                   
 -----------------------------------------------
@@ -122,7 +122,7 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
-RESET or_transform_limit;
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -693,7 +693,7 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
-SET or_transform_limit = on;
+SET enable_or_transformation = on;
 explain (costs off) select * from rlp where a = 1 or a = 7;
                 QUERY PLAN                
 ------------------------------------------
@@ -706,29 +706,29 @@ explain (costs off) select * from rlp where a = 1 or b = 'ab';
 -------------------------------------------------------
  Append
    ->  Seq Scan on rlp1 rlp_1
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp2 rlp_2
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp3abcd rlp_3
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp4_1 rlp_4
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp4_2 rlp_5
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp4_default rlp_6
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp5_1 rlp_7
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp5_default rlp_8
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp_default_10 rlp_9
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp_default_30 rlp_10
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp_default_null rlp_11
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp_default_default rlp_12
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
 (25 rows)
 
 explain (costs off) select * from rlp where a > 20 and a < 27;
@@ -849,7 +849,7 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
-RESET or_transform_limit;
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 271313ebf86..8a380c29a4c 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -123,6 +123,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | off
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index 8a31e2e670d..be4d88200b6 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,7 +56,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
-SET or_transform_limit = on;
+SET enable_or_transformation = on;
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
                       QUERY PLAN                       
@@ -72,7 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
-RESET or_transform_limit;
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index a709b2c1abc..48bb1bc0a0a 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,7 +737,7 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
-SET or_transform_limit = on;
+SET enable_or_transformation = on;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -767,7 +767,7 @@ SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-RESET or_transform_limit;
+RESET enable_or_transformation;
 
 --
 -- Check behavior with duplicate index column contents
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d95663b9c30..3d072cce498 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1396,7 +1396,7 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-SET or_transform_limit = on;
+SET enable_or_transformation = on;
 explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
@@ -1405,7 +1405,7 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-RESET or_transform_limit;
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 88709910592..1e270ae9c06 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -22,10 +22,10 @@ explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
 
-SET or_transform_limit = on;
+SET enable_or_transformation = on;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-RESET or_transform_limit;
+RESET enable_or_transformation;
 
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
@@ -106,7 +106,7 @@ explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
 
-SET or_transform_limit = on;
+SET enable_or_transformation = on;
 explain (costs off) select * from rlp where a = 1 or a = 7;
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
 explain (costs off) select * from rlp where a > 20 and a < 27;
@@ -119,7 +119,7 @@ explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
 explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
-RESET or_transform_limit;
+RESET enable_or_transformation;
 
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index c735e219589..0499bedb9eb 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,11 +22,11 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
-SET or_transform_limit = on;
+SET enable_or_transformation = on;
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-RESET or_transform_limit;
+RESET enable_or_transformation;
 
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
v8.2-Replace-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=v8.2-Replace-OR-clause-to-ANY-expressions.patchDownload
From 441448c9d8e0c5b63d0e9ea4d2da001b648311ce Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Mon, 6 Nov 2023 16:48:00 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
---
 src/backend/parser/parse_expr.c               | 298 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 115 +++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  50 +++
 src/test/regress/expected/partition_prune.out | 179 +++++++++++
 src/test/regress/expected/sysviews.out        |   1 +
 src/test/regress/expected/tidscan.out         |  17 +
 src/test/regress/sql/create_index.sql         |  32 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 14 files changed, 743 insertions(+), 2 deletions(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344c..46212a77c64 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -18,6 +18,7 @@
 #include "catalog/pg_aggregate.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
+#include "common/hashfn.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
@@ -43,6 +44,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = false;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -98,7 +100,301 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 							  Node *ltree, Node *rtree, int location);
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
+typedef struct OrClauseGroupEntry
+{
+	char		   *hash_leftvar_key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Node 		   *expr;
+} OrClauseGroupEntry;
+
+static int
+or_name_match(const void *key1, const void *key2, Size keysize)
+{
+	const char *name1 = *(const char *const *) key1;
+	const char *name2 = *(const char *const *) key2;
+
+	return strcmp(name1, name2);
+}
+
+static uint32
+or_name_hash(const void *key, Size keysize)
+{
+	const char *name = *(const char *const *) key;
+
+	return DatumGetInt32(hash_any((unsigned char *)name, strlen(name)));
+}
+
+static char *
+get_key_nconst_node(Node *nconst_node)
+{
+	if (IsA(nconst_node, OpExpr))
+	{
+		OpExpr 	   *clause = (OpExpr*) nconst_node;
+		OpExpr	   *temp = makeNode(OpExpr);
+
+		temp->opno = clause->opno;
+		temp->opfuncid = InvalidOid;
+		temp->opresulttype = clause->opresulttype;
+		temp->opretset = clause->opretset;
+		temp->opcollid = clause->opcollid;
+		temp->inputcollid = clause->inputcollid;
+		temp->location = -1;
+
+		temp->args = list_copy(clause->args);
+		return nodeToString(temp);
+	}
+	else if (IsA(nconst_node, Var))
+	{
+		Var	   *clause = (Var*) nconst_node;
+		Var	   *var = makeNode(Var);
+
+		var->varno = clause->varno;
+		var->varattno = clause->varattno;
+		var->vartype = clause->vartype;
+		var->vartypmod = clause->vartypmod;
+		var->varcollid = clause->varcollid;
+		var->varlevelsup = clause->varlevelsup;
+		var->varattnosyn = clause->varattno;
+		var->location = -1;
+
+		return nodeToString(var);
+	}
+	else
+	{
+		return NULL;
+	}
+ }
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	ListCell	   *lc;
+	HASHCTL			info;
+	HTAB 		   *or_group_htab = NULL;
+	int 			len_ors = list_length(expr_orig->args);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(char *);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = or_name_hash;
+	info.match = or_name_match;
+	or_group_htab = hash_create("OR Groups",
+									  len_ors,
+									  &info,
+									  HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR || !enable_or_transformation || len_ors == 1 || !or_group_htab)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual = NULL;
+		Node			   *const_expr = NULL;
+		Node			   *nconst_expr = NULL;
+		OrClauseGroupEntry *gentry = NULL;
+		bool				found;
+		char		   	   *str;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
 
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		str = get_key_nconst_node(nconst_expr);
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)) || str == NULL)
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		gentry = hash_search(or_group_htab, &str, HASH_FIND, &found);
+
+		if (found)
+		{
+			gentry->consts = lappend(gentry->consts, const_expr);
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+		}
+
+		/* New clause group needed */
+		gentry = hash_search(or_group_htab, &str, HASH_ENTER, &found);
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = orqual;
+		gentry->hash_leftvar_key = str;
+	}
+
+	if (or_group_htab && (hash_get_num_entries(or_group_htab) < 1 ||
+	                         hash_get_num_entries(or_group_htab) == len_ors))
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		hash_destroy(or_group_htab);
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		HASH_SEQ_STATUS		hash_seq;
+		OrClauseGroupEntry *gentry;
+
+		hash_seq_init(&hash_seq, or_group_htab);
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		while ((gentry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
+		{
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs = NIL;
+				ArrayExpr  *newa = NULL;
+				ScalarArrayOpExpr *saopexpr = NULL;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+			}
+			hash_search(or_group_htab, &gentry->hash_leftvar_key, HASH_REMOVE, NULL);
+		}
+		hash_destroy(or_group_htab);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +508,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index beed72abbd6..3411f023df8 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,16 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&enable_or_transformation,
+		false,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..3a87de02859 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..dbc8bc3bed0 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,121 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..0f2b1b16200 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ enable_or_transformation
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index ddc4e692329..d969b31e3e3 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,6 +4207,56 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
+
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c0556..fe815417c13 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 271313ebf86..8a380c29a4c 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -123,6 +123,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | off
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..be4d88200b6 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..48bb1bc0a0a 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index a41787d1f1e..3d072cce498 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1396,6 +1396,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827f..1e270ae9c06 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..0499bedb9eb 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index bf50a321198..87f2967648b 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1640,6 +1640,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

#90a.rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#89)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi, all!

These days I was porting a patch for converting or expressions to ANY to
the choose_bitmap_and function. Unfortunately, it is not possible to
transfer the conversion there, since expressions are processed one by
one, as far as I saw. Therefore, I tried to make the conversion earlier
in the generate_bitmap_or_paths function, there is just a loop bypass.
The patch turns out to be quite complicated, in my opinion, and to be
honest, it does not work fully yet. Also, due to the fact that the index
for the ScalarOpExpr expression is created earlier (approximately 344
lines in the src/backend/optimizer/path/indxpath.c file), we had to call
the generate_bitmap_or_paths function earlier. I haven't seen yet what
problems this could potentially lead to. Patch in the attached diff file.

In the last letter, I had an incorrect numbering for the original patch,
corrected, respectively, it is unclear whether the tests in CI were
normal. Corrected it.

Attachments:

v9-Replace-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=v9-Replace-OR-clause-to-ANY-expressions.patchDownload
From 3062a2408af258b9e327219020221b75501e8530 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Mon, 6 Nov 2023 16:48:00 +0300
Subject: [PATCH] Replace OR clause to ANY expressions. Replace (X=N1) OR
 (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
---
 src/backend/parser/parse_expr.c               | 299 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 115 +++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  50 +++
 src/test/regress/expected/partition_prune.out | 179 +++++++++++
 src/test/regress/expected/tidscan.out         |  17 +
 src/test/regress/sql/create_index.sql         |  32 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 13 files changed, 743 insertions(+), 2 deletions(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344c..25a4235dbd9 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -18,6 +18,7 @@
 #include "catalog/pg_aggregate.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
+#include "common/hashfn.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
@@ -43,6 +44,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		or_transform_limit = false;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -98,7 +100,302 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 							  Node *ltree, Node *rtree, int location);
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
+typedef struct OrClauseGroupEntry
+{
+	char		   *hash_leftvar_key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Expr 		   *expr;
+} OrClauseGroupEntry;
+
+static int
+or_name_match(const void *key1, const void *key2, Size keysize)
+{
+	const char *name1 = *(const char *const *) key1;
+	const char *name2 = *(const char *const *) key2;
+
+	return strcmp(name1, name2);
+}
+
+static uint32
+or_name_hash(const void *key, Size keysize)
+{
+	const char *name = *(const char *const *) key;
+
+	return DatumGetInt32(hash_any((unsigned char *)name, strlen(name)));
+}
+
+static char *
+get_key_nconst_node(Node *nconst_node)
+{
+	if (IsA(nconst_node, OpExpr))
+	{
+		OpExpr 	   *clause = (OpExpr*) nconst_node;
+		OpExpr	   *temp = makeNode(OpExpr);
+
+		temp->opno = clause->opno;
+		temp->opfuncid = InvalidOid;
+		temp->opresulttype = clause->opresulttype;
+		temp->opretset = clause->opretset;
+		temp->opcollid = clause->opcollid;
+		temp->inputcollid = clause->inputcollid;
+		temp->location = -1;
+
+		temp->args = list_copy(clause->args);
+		return nodeToString(temp);
+	}
+	else if (IsA(nconst_node, Var))
+	{
+		Var	   *clause = (Var*) nconst_node;
+		Var	   *var = makeNode(Var);
+
+		var->varno = clause->varno;
+		var->varattno = clause->varattno;
+		var->vartype = clause->vartype;
+		var->vartypmod = clause->vartypmod;
+		var->varcollid = clause->varcollid;
+		var->varlevelsup = clause->varlevelsup;
+		var->varattnosyn = clause->varattno;
+		var->location = -1;
+
+		return nodeToString(var);
+	}
+	else
+	{
+		return NULL;
+	}
+ }
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	ListCell	   *lc;
+	HASHCTL			info;
+	HTAB 		   *or_group_htab = NULL;
+	int 			len_ors = list_length(expr_orig->args);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(char *);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = or_name_hash;
+	info.match = or_name_match;
+	or_group_htab = hash_create("OR Groups",
+									  len_ors,
+									  &info,
+									  HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR || !or_transform_limit || len_ors == 1 || !or_group_htab)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual;
+		Node			   *const_expr;
+		Node			   *nconst_expr;
+		OrClauseGroupEntry *gentry;
+		bool				found;
+		char		   	   *str;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
 
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		str = get_key_nconst_node(nconst_expr);
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)) || str == NULL)
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		gentry = hash_search(or_group_htab, &str, HASH_FIND, &found);
+
+		if (found)
+		{
+			gentry->consts = lappend(gentry->consts, const_expr);
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+		}
+
+		/* New clause group needed */
+		gentry = hash_search(or_group_htab, &str, HASH_ENTER, &found);
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = (Expr *) orqual;
+		gentry->hash_leftvar_key = str;
+	}
+
+	if (or_group_htab && (hash_get_num_entries(or_group_htab) < 1 ||
+	                         hash_get_num_entries(or_group_htab) == len_ors))
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		hash_destroy(or_group_htab);
+		list_free(or_list);
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		HASH_SEQ_STATUS		hash_seq;
+		OrClauseGroupEntry *gentry;
+
+		hash_seq_init(&hash_seq, or_group_htab);
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		while ((gentry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
+		{
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs;
+				ArrayExpr  *newa;
+				ScalarArrayOpExpr *saopexpr;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+			}
+			hash_search(or_group_htab, &gentry->hash_leftvar_key, HASH_REMOVE, NULL);
+		}
+		hash_destroy(or_group_htab);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +509,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 7605eff9b9d..a8e8054e7e6 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,16 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"or_transform_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&or_transform_limit,
+		false,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..7a6943c116c 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool or_transform_limit;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..29c2bc6a2b2 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,121 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET or_transform_limit = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET or_transform_limit;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..c052b113eea 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ or_transform_limit
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 446959e3c5f..d8684e959e4 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4207,6 +4207,56 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET or_transform_limit = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
+
+RESET or_transform_limit;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c0556..1789d3c1fd7 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET or_transform_limit = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET or_transform_limit;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET or_transform_limit = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET or_transform_limit;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..8a31e2e670d 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET or_transform_limit = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET or_transform_limit;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..a709b2c1abc 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET or_transform_limit = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET or_transform_limit;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 66dd03dd88b..f5dcf8b90a7 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1396,6 +1396,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET or_transform_limit = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET or_transform_limit;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827f..88709910592 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET or_transform_limit = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET or_transform_limit;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET or_transform_limit = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET or_transform_limit;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..c735e219589 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET or_transform_limit = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET or_transform_limit;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 87c1aee379f..8cea6a6b851 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1638,6 +1638,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

or_patch_bitmapindex_create.difftext/x-patch; charset=UTF-8; name=or_patch_bitmapindex_create.diffDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 03a5fbdc6dc..754c83816f7 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -34,6 +34,11 @@
 #include "optimizer/restrictinfo.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "common/hashfn.h"
+#include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -73,6 +78,36 @@ typedef struct
 	int			indexcol;		/* index column we want to match to */
 } ec_member_matches_arg;
 
+typedef struct OrClauseGroupEntry
+{
+	char		   *hash_leftvar_key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Node 		   *expr;
+	RestrictInfo	*ri;
+} OrClauseGroupEntry;
+
+static int
+or_name_match(const void *key1, const void *key2, Size keysize)
+{
+	const char *name1 = *(const char *const *) key1;
+	const char *name2 = *(const char *const *) key2;
+
+	return strcmp(name1, name2);
+}
+
+static uint32
+or_name_hash(const void *key, Size keysize)
+{
+	const char *name = *(const char *const *) key;
+
+	return DatumGetInt32(hash_any((unsigned char *)name, strlen(name)));
+}
+
+bool		enable_or_transformation = true;
 
 static void consider_index_join_clauses(PlannerInfo *root, RelOptInfo *rel,
 										IndexOptInfo *index,
@@ -193,6 +228,55 @@ static bool ec_member_matches_indexcol(PlannerInfo *root, RelOptInfo *rel,
 									   EquivalenceClass *ec, EquivalenceMember *em,
 									   void *arg);
 
+static char *
+get_key_nconst_node(Node *nconst_node)
+{
+	if (IsA(nconst_node, OpExpr))
+	{
+		OpExpr 	   *clause = (OpExpr*) nconst_node;
+		OpExpr	   *temp = makeNode(OpExpr);
+
+		temp->opno = clause->opno;
+		temp->opfuncid = InvalidOid;
+		temp->opresulttype = clause->opresulttype;
+		temp->opretset = clause->opretset;
+		temp->opcollid = clause->opcollid;
+		temp->inputcollid = clause->inputcollid;
+		temp->location = -1;
+
+		temp->args = list_copy(clause->args);
+		return nodeToString(temp);
+	}
+	else if (IsA(nconst_node, Var))
+	{
+		Var	   *clause = (Var*) nconst_node;
+		Var	   *var = makeNode(Var);
+
+		var->varno = clause->varno;
+		var->varattno = clause->varattno;
+		var->vartype = clause->vartype;
+		var->vartypmod = clause->vartypmod;
+		var->varcollid = clause->varcollid;
+		var->varlevelsup = clause->varlevelsup;
+		var->varattnosyn = clause->varattno;
+	var->location = -1;
+
+		return nodeToString(var);
+	}
+	else
+	{
+		return NULL;
+	}
+}
+
+/*
+ * Pass through baserestrictinfo clauses and try to convert OR clauses into IN
+ * Return a modified clause list or just the same baserestrictinfo, if no
+ * changes have made.
+ * XXX: do not change source list of clauses at all.
+ */
+
+
 
 /*
  * create_index_paths()
@@ -250,6 +334,13 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
 	/* Bitmap paths are collected and then dealt with at the end */
 	bitindexpaths = bitjoinpaths = joinorclauses = NIL;
 
+	/*
+	 * Generate BitmapOrPaths for any suitable OR-clauses present in the
+	 * restriction list.  Add these to bitindexpaths.
+	 */
+	indexpaths = generate_bitmap_or_paths(root, rel,
+										  rel->baserestrictinfo, NIL);
+
 	/* Examine each index in turn */
 	foreach(lc, rel->indexlist)
 	{
@@ -309,13 +400,7 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
 										&eclauseset,
 										&bitjoinpaths);
 	}
-
-	/*
-	 * Generate BitmapOrPaths for any suitable OR-clauses present in the
-	 * restriction list.  Add these to bitindexpaths.
-	 */
-	indexpaths = generate_bitmap_or_paths(root, rel,
-										  rel->baserestrictinfo, NIL);
+	
 	bitindexpaths = list_concat(bitindexpaths, indexpaths);
 
 	/*
@@ -1237,6 +1322,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	List	   *result = NIL;
 	List	   *all_clauses;
 	ListCell   *lc;
+	List	   *modified_rinfo = NIL;
 
 	/*
 	 * We can use both the current and other clauses as context for
@@ -1247,23 +1333,45 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	foreach(lc, clauses)
 	{
 		RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
-		List	   *pathlist;
+		List	   *pathlist = NIL;
 		Path	   *bitmapqual;
-		ListCell   *j;
+		ListCell   *lc_rargs, *lc_eargs;
+		HASHCTL		info;
+		HTAB 	   *or_group_htab = NULL;
+		int 		len_ors = 0;
+		List	   *or_list = NIL;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
+		{
+			modified_rinfo = lappend(modified_rinfo, rinfo);
 			continue;
+		}
+
+		len_ors = list_length(((BoolExpr *) rinfo->orclause)->args);
+
+		MemSet(&info, 0, sizeof(info));
+		info.keysize = sizeof(char *);
+		info.entrysize = sizeof(OrClauseGroupEntry);
+		info.hash = or_name_hash;
+		info.match = or_name_match;
+		or_group_htab = hash_create("OR Groups",
+										len_ors,
+									  &info,
+									  HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
 
 		/*
 		 * We must be able to match at least one index to each of the arms of
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		forboth(lc_eargs, ((BoolExpr *) rinfo->clause)->args,
+				lc_rargs, ((BoolExpr *) rinfo->orclause)->args)
 		{
-			Node	   *orarg = (Node *) lfirst(j);
+			Node	   *orarg = (Node *) lfirst(lc_rargs);
 			List	   *indlist;
+			OrClauseGroupEntry *gentry;
+			Node	   *orqual = (Node *) lfirst(lc_eargs);
 
 			/* OR arguments should be ANDs or sub-RestrictInfos */
 			if (is_andclause(orarg))
@@ -1279,36 +1387,309 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 									  generate_bitmap_or_paths(root, rel,
 															   andargs,
 															   all_clauses));
+				or_list = lappend(or_list, orqual);
 			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
-				List	   *orargs;
+				RestrictInfo *sub_rinfo = lfirst_node(RestrictInfo, lc_rargs);
+				Node *nconst_expr = NULL;
+				Node *const_expr = NULL;
+				char *str = NULL;
+				bool found;
 
 				Assert(!restriction_is_or_clause(ri));
-				orargs = list_make1(ri);
 
-				indlist = build_paths_for_OR(root, rel,
-											 orargs,
-											 all_clauses);
+				if (!IsA(lfirst(lc_rargs), RestrictInfo) || !enable_or_transformation ||
+				/* Check: it is an expr of the form 'F(x) oper ConstExpr' */
+					!IsA(sub_rinfo->clause, OpExpr) ||
+					!(bms_is_empty(sub_rinfo->left_relids) ^
+					bms_is_empty(sub_rinfo->right_relids)) ||
+					contain_volatile_functions((Node *) orarg))
+				{
+					List	   *orargs;
+					orargs = list_make1(ri);
+					indlist = build_paths_for_OR(root, rel,
+												orargs,
+												all_clauses);
+					/*
+					* If nothing matched this arm, we can't do anything with this OR
+					* clause.
+					*/
+					if (indlist == NIL)
+					{
+						pathlist = NIL;
+						break;
+					}
+
+					/*
+					* OK, pick the most promising AND combination, and add it to
+					* pathlist.
+					*/
+					bitmapqual = choose_bitmap_and(root, rel, indlist);
+					pathlist = lappend(pathlist, bitmapqual);
+					or_list = lappend(or_list, orqual);
+					continue;
+				}
+
+				/*
+				* Detect the constant side of the clause. Recall non-constant
+				* expression can be made not only with Vars, but also with Params,
+				* which is not bonded with any relation. Thus, we detect the const
+				* side - if another side is constant too, the orqual couldn't be
+				* an OpExpr.
+				* Get pointers to constant and expression sides of the qual.
+				*/
+				const_expr =bms_is_empty(sub_rinfo->left_relids) ?
+												get_leftop(sub_rinfo->clause) :
+												get_rightop(sub_rinfo->clause);
+				nconst_expr = bms_is_empty(sub_rinfo->left_relids) ?
+												get_rightop(sub_rinfo->clause) :
+												get_leftop(sub_rinfo->clause);
+
+				str = get_key_nconst_node(nconst_expr);
+
+				if (!op_mergejoinable(((OpExpr*)sub_rinfo->clause)->opno, exprType(nconst_expr)) || str == NULL)
+				{
+					List	   *orargs;
+					orargs = list_make1(ri);
+					indlist = build_paths_for_OR(root, rel,
+												orargs,
+												all_clauses);
+					/*
+					* If nothing matched this arm, we can't do anything with this OR
+					* clause.
+					*/
+					if (indlist == NIL)
+					{
+						pathlist = NIL;
+						break;
+					}
+
+					/*
+					* OK, pick the most promising AND combination, and add it to
+					* pathlist.
+					*/
+					bitmapqual = choose_bitmap_and(root, rel, indlist);
+					pathlist = lappend(pathlist, bitmapqual);
+					or_list = lappend(or_list, orqual);
+					continue;
+				}
+
+				/*
+				* At this point we definitely have a transformable clause.
+				* Classify it and add into specific group of clauses, or create new
+				* group.
+				* TODO: to manage complexity in the case of many different clauses
+				* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+				* like a hash table. But also we believe, that the case of many
+				* different variable sides is very rare.
+				*/
+				gentry = hash_search(or_group_htab, &str, HASH_FIND, &found);
+
+				if (found)
+				{
+					gentry->consts = lappend(gentry->consts, const_expr);
+					/*
+						* The clause classified successfully and added into existed
+						* clause group.
+						*/
+					continue;
+				}
+
+				/* New clause group needed */
+				gentry = hash_search(or_group_htab, &str, HASH_ENTER, &found);
+				gentry->node = nconst_expr;
+				gentry->consts = list_make1(const_expr);
+				gentry->expr = orqual;
+				gentry->hash_leftvar_key = str;
+				gentry->ri = ri;
 			}
+		}
+
+		if (!(or_group_htab && (hash_get_num_entries(or_group_htab) < 1 ||
+	                         hash_get_num_entries(or_group_htab) == len_ors)))
+		{
+			HASH_SEQ_STATUS		hash_seq;
+			OrClauseGroupEntry *gentry;
+			bool success = false;
+
+			hash_seq_init(&hash_seq, or_group_htab);
+
+			/* Let's convert each group of clauses to an IN operation. */
 
 			/*
-			 * If nothing matched this arm, we can't do anything with this OR
-			 * clause.
-			 */
-			if (indlist == NIL)
+			* Go through the list of groups and convert each, where number of
+			* consts more than 1. trivial groups move to OR-list again
+			*/
+
+			while ((gentry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
 			{
-				pathlist = NIL;
-				break;
+				List			   *allexprs;
+				Oid				    scalar_type;
+				Oid					array_type;
+				List *orargs;
+				List *indlist;
+
+				Assert(list_length(gentry->consts) > 0);
+
+				if (list_length(gentry->consts) == 1)
+				{
+					/*
+					* Only one element in the class. Return rinfo into the BoolExpr
+					* args list unchanged.
+					*/
+					list_free(gentry->consts);
+
+					orargs = list_make1(gentry->ri);
+					indlist = build_paths_for_OR(root, rel,
+												orargs,
+												all_clauses);
+					/*
+					* If nothing matched this arm, we can't do anything with this OR
+					* clause.
+					*/
+					if (indlist == NIL)
+					{
+						pathlist = NIL;
+						break;
+					}
+
+					/*
+					* OK, pick the most promising AND combination, and add it to
+					* pathlist.
+					*/
+					bitmapqual = choose_bitmap_and(root, rel, indlist);
+					pathlist = lappend(pathlist, bitmapqual);
+					or_list = lappend(or_list, gentry->expr);
+					continue;
+				}
+
+				/*
+				* Do the transformation.
+				*
+				* First of all, try to select a common type for the array elements.
+				* Note that since the LHS' type is first in the list, it will be
+				* preferred when there is doubt (eg, when all the RHS items are
+				* unknown literals).
+				*
+				* Note: use list_concat here not lcons, to avoid damaging rnonvars.
+				*
+				* As a source of insides, use make_scalar_array_op()
+				*/
+				allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+				scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+				if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+					array_type = get_array_type(scalar_type);
+				else
+					array_type = InvalidOid;
+
+				if (array_type != InvalidOid)
+				{
+					/*
+					* OK: coerce all the right-hand non-Var inputs to the common
+					* type and build an ArrayExpr for them.
+					*/
+					List	   *aexprs = NIL;
+					ArrayExpr  *newa = NULL;
+					ScalarArrayOpExpr *saopexpr = NULL;
+					ListCell *l;
+
+					aexprs = NIL;
+
+					foreach(l, gentry->consts)
+					{
+						Node	   *rexpr = (Node *) lfirst(l);
+
+						rexpr = coerce_to_common_type(NULL, rexpr,
+													scalar_type,
+													"IN");
+						aexprs = lappend(aexprs, rexpr);
+					}
+
+					newa = makeNode(ArrayExpr);
+					/* array_collid will be set by parse_collate.c */
+					newa->element_typeid = scalar_type;
+					newa->array_typeid = array_type;
+					newa->multidims = false;
+					newa->elements = aexprs;
+					newa->location = -1;
+
+					saopexpr =
+						(ScalarArrayOpExpr *)
+							make_scalar_array_op(NULL,
+												list_make1(makeString((char *) "=")),
+												true,
+												gentry->node,
+												(Node *) newa,
+												-1);
+					or_list = lappend(or_list, (void *) saopexpr);
+					success = true;
+				}
+				else
+				{
+					orargs = list_make1(gentry->ri);
+					indlist = build_paths_for_OR(root, rel,
+												orargs,
+												all_clauses);
+					list_free(gentry->consts);
+					/*
+					* If nothing matched this arm, we can't do anything with this OR
+					* clause.
+					*/
+					if (indlist == NIL)
+					{
+						pathlist = NIL;
+						break;
+					}
+
+					/*
+					* OK, pick the most promising AND combination, and add it to
+					* pathlist.
+					*/
+					bitmapqual = choose_bitmap_and(root, rel, indlist);
+					pathlist = lappend(pathlist, bitmapqual);
+					or_list = lappend(or_list, gentry->expr);
+				}
+				hash_search(or_group_htab, &gentry->hash_leftvar_key, HASH_REMOVE, NULL);
 			}
+			hash_destroy(or_group_htab);
 
-			/*
-			 * OK, pick the most promising AND combination, and add it to
-			 * pathlist.
-			 */
-			bitmapqual = choose_bitmap_and(root, rel, indlist);
-			pathlist = lappend(pathlist, bitmapqual);
+			if (!success)
+			{
+				/*
+				* Each group contains only one element - use rinfo as is.
+				*/
+				modified_rinfo = lappend(modified_rinfo, rinfo);
+				list_free(or_list);
+			}
+			else
+			{
+				RestrictInfo *ri;
+				List *orargs;
+				List *indlist;
+				ri = make_restrictinfo(root,
+				  list_length(or_list) > 1 ? make_orclause(or_list) :
+											 (Expr *) linitial(or_list),
+				  ri->is_pushed_down,
+				  ri->has_clone,
+				  ri->is_clone,
+				  ri->pseudoconstant,
+				  ri->security_level,
+				  ri->required_relids,
+				  ri->incompatible_relids,
+				  ri->outer_relids);
+				
+				ri->eval_cost=rinfo->eval_cost;
+				ri->norm_selec=rinfo->norm_selec;
+				ri->outer_selec=rinfo->outer_selec;
+				ri->left_bucketsize=rinfo->left_bucketsize;
+				ri->right_bucketsize=rinfo->right_bucketsize;
+				ri->left_mcvfreq=rinfo->left_mcvfreq;
+				ri->right_mcvfreq=rinfo->right_mcvfreq;
+				modified_rinfo = lappend(modified_rinfo, ri);
+			}
 		}
 
 		/*
@@ -1322,10 +1703,10 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		}
 	}
 
+	rel->baserestrictinfo = modified_rinfo;
 	return result;
 }
 
-
 /*
  * choose_bitmap_and
  *		Given a nonempty list of bitmap paths, AND them into one path.
#91Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#89)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 10/11/2023 16:20, Alena Rybakina wrote:

I added log like that: ERROR:  unrecognized node type: 0.

I fixed this issue and added some cosmetic refactoring.
The changes are presented in the or_patch_changes.diff file.

Looking into the patch, I found some trivial improvements (see attachment).
Also, it is not obvious that using a string representation of the clause
as a hash table key is needed here. Also, by making a copy of the node
in the get_key_nconst_node(), you replace the location field, but in the
case of complex expression, you don't do the same with other nodes.
I propose to generate expression hash instead + prove the equality of
two expressions by calling equal().

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

changes.txttext/plain; charset=UTF-8; name=changes.txtDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 25a4235dbd..de27d2646c 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -178,6 +178,10 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 	HTAB 		   *or_group_htab = NULL;
 	int 			len_ors = list_length(expr_orig->args);
 
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (!or_transform_limit || expr_orig->boolop != OR_EXPR || len_ors < 2)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
 	MemSet(&info, 0, sizeof(info));
 	info.keysize = sizeof(char *);
 	info.entrysize = sizeof(OrClauseGroupEntry);
@@ -188,10 +192,6 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 									  &info,
 									  HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
 
-	/* If this is not an 'OR' expression, skip the transformation */
-	if (expr_orig->boolop != OR_EXPR || !or_transform_limit || len_ors == 1 || !or_group_htab)
-		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
-
 	foreach(lc, expr_orig->args)
 	{
 		Node			   *arg = lfirst(lc);
#92a.rybakina
a.rybakina@postgrespro.ru
In reply to: Andrei Lepikhov (#91)
Re: POC, WIP: OR-clause support for indexes

On 20.11.2023 11:52, Andrei Lepikhov wrote:

On 10/11/2023 16:20, Alena Rybakina wrote:

I added log like that: ERROR: unrecognized node type: 0.

I fixed this issue and added some cosmetic refactoring.
The changes are presented in the or_patch_changes.diff file.

Looking into the patch, I found some trivial improvements (see
attachment).
Also, it is not obvious that using a string representation of the
clause as a hash table key is needed here. Also, by making a copy of
the node in the get_key_nconst_node(), you replace the location field,
but in the case of complex expression, you don't do the same with
other nodes.
I propose to generate expression hash instead + prove the equality of
two expressions by calling equal().

Thank you! I agree with your changes.

#93Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Andrei Lepikhov (#91)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 20.11.2023 11:52, Andrei Lepikhov wrote:

Looking into the patch, I found some trivial improvements (see
attachment).
Also, it is not obvious that using a string representation of the
clause as a hash table key is needed here. Also, by making a copy of
the node in the get_key_nconst_node(), you replace the location field,
but in the case of complex expression, you don't do the same with
other nodes.
I propose to generate expression hash instead + prove the equality of
two expressions by calling equal().

I was thinking about your last email and a possible error where the
location field may not be cleared in complex expressions. Unfortunately,
I didn't come up with any examples either, but I think I was able to
handle this with a special function that removes location-related
patterns. The alternative to this is to bypass this expression, but I
think it will be more invasive. In addition, I have added changes
related to the hash table: now the key is of type int.

All changes are displayed in the attached
v9-0001-Replace-OR-clause-to_ANY.diff.txt file.

I haven't measured it yet. But what do you think about these changes?

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

v9-0001-PATCH-Replace-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=v9-0001-PATCH-Replace-OR-clause-to-ANY-expressions.patchDownload
From 8e579b059ffd415fc477e0e8930e718084e58683 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Tue, 21 Nov 2023 03:22:13 +0300
Subject: [PATCH] [PATCH] Replace OR clause to ANY expressions. Replace (X=N1)
 OR (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
---
 src/backend/parser/parse_expr.c               | 280 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 115 +++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  50 ++++
 src/test/regress/expected/partition_prune.out | 156 ++++++++++
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  17 ++
 src/test/regress/sql/create_index.sql         |  32 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 14 files changed, 703 insertions(+), 3 deletions(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344c..290422005a3 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -18,6 +18,7 @@
 #include "catalog/pg_aggregate.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
+#include "common/hashfn.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
@@ -43,6 +44,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = false;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -98,7 +100,283 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 							  Node *ltree, Node *rtree, int location);
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
+typedef struct OrClauseGroupEntry
+{
+	int32			hash_leftvar_key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Node 		   *expr;
+} OrClauseGroupEntry;
+
+/*
+ * TODO: consider different algorithm to manage complexity
+ * in the case of many different clauses,
+ * like Rabin-Karp or Boyer–Moore algorithms.
+ */
+static char *
+clear_patterns(const char *str, const char *start_pattern)
+{
+	int			i = 0;
+	int			j = 0;
+	int			start_pattern_len = strlen(start_pattern);
+	char	   *res = palloc0(sizeof(*res) * (strlen(str) + 1));
+
+	for (i = 0; str[i];)
+	{
+		if (i >= start_pattern_len && strncmp(&str[i - start_pattern_len],
+											  start_pattern,
+											  start_pattern_len) == 0)
+		{
+			while (str[i] && !(str[i] == '{' || str[i] == '}'))
+				i++;
+		}
+		if (str[i])
+			res[j++] = str[i++];
+	}
+
+	return res;
+}
+
+static int32
+get_key_nconst_node(Node *nconst_node)
+{
+	char *str = nodeToString(nconst_node);
+
+	str = clear_patterns(str, " :location");
+
+	if (str == NULL)
+		return 0;
+
+	return DatumGetInt32(hash_any((unsigned char *)str, strlen(str)));
+}
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	ListCell	   *lc;
+	HASHCTL			info;
+	HTAB 		   *or_group_htab = NULL;
+	int 			len_ors = list_length(expr_orig->args);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(int);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	or_group_htab = hash_create("OR Groups",
+									  len_ors,
+									  &info,
+									  HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR || !enable_or_transformation || len_ors == 1 || !or_group_htab)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual = NULL;
+		Node			   *const_expr = NULL;
+		Node			   *nconst_expr = NULL;
+		OrClauseGroupEntry *gentry = NULL;
+		bool				found;
+		int32				hash;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
 
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		hash = get_key_nconst_node(nconst_expr);
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)) || hash == 0)
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		gentry = hash_search(or_group_htab, &hash, HASH_FIND, &found);
+
+		if (found)
+		{
+			gentry->consts = lappend(gentry->consts, const_expr);
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+		}
+
+		/* New clause group needed */
+		gentry = hash_search(or_group_htab, &hash, HASH_ENTER, &found);
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = orqual;
+		gentry->hash_leftvar_key = hash;
+	}
+
+	if (or_group_htab && (hash_get_num_entries(or_group_htab) < 1 ||
+	                         hash_get_num_entries(or_group_htab) == len_ors))
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		hash_destroy(or_group_htab);
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		HASH_SEQ_STATUS		hash_seq;
+		OrClauseGroupEntry *gentry;
+
+		hash_seq_init(&hash_seq, or_group_htab);
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		while ((gentry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
+		{
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs = NIL;
+				ArrayExpr  *newa = NULL;
+				ScalarArrayOpExpr *saopexpr = NULL;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+			}
+			hash_search(or_group_htab, &gentry->hash_leftvar_key, HASH_REMOVE, NULL);
+		}
+		hash_destroy(or_group_htab);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +490,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index b764ef69980..e2495529d29 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,16 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&enable_or_transformation,
+		false,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..3a87de02859 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..dbc8bc3bed0 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,121 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..0f2b1b16200 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ enable_or_transformation
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 2c73270143b..5af2cf09107 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4233,6 +4233,56 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
+
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c0556..804fea9f34c 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,140 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 271313ebf86..566f51df428 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -123,6 +123,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | off
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -133,7 +134,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(22 rows)
+(23 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..be4d88200b6 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..48bb1bc0a0a 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 8a8a63bd2f1..55d7e2ae7d6 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827f..1e270ae9c06 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..0499bedb9eb 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index dba3498a13e..c9004250a5f 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1641,6 +1641,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

v9-0001-Replace-OR-clause-to_ANY.diff.txttext/plain; charset=UTF-8; name=v9-0001-Replace-OR-clause-to_ANY.diff.txtDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 46212a77c64..290422005a3 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -102,7 +102,7 @@ static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 typedef struct OrClauseGroupEntry
 {
-	char		   *hash_leftvar_key;
+	int32			hash_leftvar_key;
 
 	Node		   *node;
 	List		   *consts;
@@ -111,63 +111,47 @@ typedef struct OrClauseGroupEntry
 	Node 		   *expr;
 } OrClauseGroupEntry;
 
-static int
-or_name_match(const void *key1, const void *key2, Size keysize)
+/*
+ * TODO: consider different algorithm to manage complexity
+ * in the case of many different clauses,
+ * like Rabin-Karp or Boyer–Moore algorithms.
+ */
+static char *
+clear_patterns(const char *str, const char *start_pattern)
 {
-	const char *name1 = *(const char *const *) key1;
-	const char *name2 = *(const char *const *) key2;
+	int			i = 0;
+	int			j = 0;
+	int			start_pattern_len = strlen(start_pattern);
+	char	   *res = palloc0(sizeof(*res) * (strlen(str) + 1));
 
-	return strcmp(name1, name2);
-}
-
-static uint32
-or_name_hash(const void *key, Size keysize)
-{
-	const char *name = *(const char *const *) key;
+	for (i = 0; str[i];)
+	{
+		if (i >= start_pattern_len && strncmp(&str[i - start_pattern_len],
+											  start_pattern,
+											  start_pattern_len) == 0)
+		{
+			while (str[i] && !(str[i] == '{' || str[i] == '}'))
+				i++;
+		}
+		if (str[i])
+			res[j++] = str[i++];
+	}
 
-	return DatumGetInt32(hash_any((unsigned char *)name, strlen(name)));
+	return res;
 }
 
-static char *
+static int32
 get_key_nconst_node(Node *nconst_node)
 {
-	if (IsA(nconst_node, OpExpr))
-	{
-		OpExpr 	   *clause = (OpExpr*) nconst_node;
-		OpExpr	   *temp = makeNode(OpExpr);
-
-		temp->opno = clause->opno;
-		temp->opfuncid = InvalidOid;
-		temp->opresulttype = clause->opresulttype;
-		temp->opretset = clause->opretset;
-		temp->opcollid = clause->opcollid;
-		temp->inputcollid = clause->inputcollid;
-		temp->location = -1;
-
-		temp->args = list_copy(clause->args);
-		return nodeToString(temp);
-	}
-	else if (IsA(nconst_node, Var))
-	{
-		Var	   *clause = (Var*) nconst_node;
-		Var	   *var = makeNode(Var);
-
-		var->varno = clause->varno;
-		var->varattno = clause->varattno;
-		var->vartype = clause->vartype;
-		var->vartypmod = clause->vartypmod;
-		var->varcollid = clause->varcollid;
-		var->varlevelsup = clause->varlevelsup;
-		var->varattnosyn = clause->varattno;
-		var->location = -1;
-
-		return nodeToString(var);
-	}
-	else
-	{
-		return NULL;
-	}
- }
+	char *str = nodeToString(nconst_node);
+
+	str = clear_patterns(str, " :location");
+
+	if (str == NULL)
+		return 0;
+
+	return DatumGetInt32(hash_any((unsigned char *)str, strlen(str)));
+}
 
 static Node *
 transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
@@ -179,14 +163,12 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 	int 			len_ors = list_length(expr_orig->args);
 
 	MemSet(&info, 0, sizeof(info));
-	info.keysize = sizeof(char *);
+	info.keysize = sizeof(int);
 	info.entrysize = sizeof(OrClauseGroupEntry);
-	info.hash = or_name_hash;
-	info.match = or_name_match;
 	or_group_htab = hash_create("OR Groups",
 									  len_ors,
 									  &info,
-									  HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
+									  HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);
 
 	/* If this is not an 'OR' expression, skip the transformation */
 	if (expr_orig->boolop != OR_EXPR || !enable_or_transformation || len_ors == 1 || !or_group_htab)
@@ -200,7 +182,7 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 		Node			   *nconst_expr = NULL;
 		OrClauseGroupEntry *gentry = NULL;
 		bool				found;
-		char		   	   *str;
+		int32				hash;
 
 		/* At first, transform the arg and evaluate constant expressions. */
 		orqual = transformExprRecurse(pstate, (Node *) arg);
@@ -237,9 +219,9 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 			continue;
 		}
 
-		str = get_key_nconst_node(nconst_expr);
+		hash = get_key_nconst_node(nconst_expr);
 
-		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)) || str == NULL)
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)) || hash == 0)
 		{
 			or_list = lappend(or_list, orqual);
 			continue;
@@ -254,7 +236,7 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 		* like a hash table. But also we believe, that the case of many
 		* different variable sides is very rare.
 		*/
-		gentry = hash_search(or_group_htab, &str, HASH_FIND, &found);
+		gentry = hash_search(or_group_htab, &hash, HASH_FIND, &found);
 
 		if (found)
 		{
@@ -267,11 +249,11 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 		}
 
 		/* New clause group needed */
-		gentry = hash_search(or_group_htab, &str, HASH_ENTER, &found);
+		gentry = hash_search(or_group_htab, &hash, HASH_ENTER, &found);
 		gentry->node = nconst_expr;
 		gentry->consts = list_make1(const_expr);
 		gentry->expr = orqual;
-		gentry->hash_leftvar_key = str;
+		gentry->hash_leftvar_key = hash;
 	}
 
 	if (or_group_htab && (hash_get_num_entries(or_group_htab) < 1 ||
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index fe815417c13..804fea9f34c 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -702,34 +702,11 @@ explain (costs off) select * from rlp where a = 1 or a = 7;
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
-                      QUERY PLAN                       
--------------------------------------------------------
- Append
-   ->  Seq Scan on rlp1 rlp_1
-         Filter: (((b)::text = 'ab'::text) OR (a = 1))
-   ->  Seq Scan on rlp2 rlp_2
-         Filter: (((b)::text = 'ab'::text) OR (a = 1))
-   ->  Seq Scan on rlp3abcd rlp_3
-         Filter: (((b)::text = 'ab'::text) OR (a = 1))
-   ->  Seq Scan on rlp4_1 rlp_4
-         Filter: (((b)::text = 'ab'::text) OR (a = 1))
-   ->  Seq Scan on rlp4_2 rlp_5
-         Filter: (((b)::text = 'ab'::text) OR (a = 1))
-   ->  Seq Scan on rlp4_default rlp_6
-         Filter: (((b)::text = 'ab'::text) OR (a = 1))
-   ->  Seq Scan on rlp5_1 rlp_7
-         Filter: (((b)::text = 'ab'::text) OR (a = 1))
-   ->  Seq Scan on rlp5_default rlp_8
-         Filter: (((b)::text = 'ab'::text) OR (a = 1))
-   ->  Seq Scan on rlp_default_10 rlp_9
-         Filter: (((b)::text = 'ab'::text) OR (a = 1))
-   ->  Seq Scan on rlp_default_30 rlp_10
-         Filter: (((b)::text = 'ab'::text) OR (a = 1))
-   ->  Seq Scan on rlp_default_null rlp_11
-         Filter: (((b)::text = 'ab'::text) OR (a = 1))
-   ->  Seq Scan on rlp_default_default rlp_12
-         Filter: (((b)::text = 'ab'::text) OR (a = 1))
-(25 rows)
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
 
 explain (costs off) select * from rlp where a > 20 and a < 27;
                QUERY PLAN                
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 8a380c29a4c..566f51df428 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -134,7 +134,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(22 rows)
+(23 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
#94Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#93)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 21.11.2023 03:50, Alena Rybakina wrote:

On 20.11.2023 11:52, Andrei Lepikhov wrote:

Looking into the patch, I found some trivial improvements (see
attachment).
Also, it is not obvious that using a string representation of the
clause as a hash table key is needed here. Also, by making a copy of
the node in the get_key_nconst_node(), you replace the location
field, but in the case of complex expression, you don't do the same
with other nodes.
I propose to generate expression hash instead + prove the equality of
two expressions by calling equal().

I was thinking about your last email and a possible error where the
location field may not be cleared in complex expressions.
Unfortunately, I didn't come up with any examples either, but I think
I was able to handle this with a special function that removes
location-related patterns. The alternative to this is to bypass this
expression, but I think it will be more invasive. In addition, I have
added changes related to the hash table: now the key is of type int.

All changes are displayed in the attached
v9-0001-Replace-OR-clause-to_ANY.diff.txt file.

I haven't measured it yet. But what do you think about these changes?

Sorry, I lost your changes  during the revision process. I returned
them. I raised the patch version just in case to run ci successfully.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

v10-0001-PATCH-Replace-OR-clause-to-ANY-expressions.-Replace-.patchtext/x-patch; charset=UTF-8; name=v10-0001-PATCH-Replace-OR-clause-to-ANY-expressions.-Replace-.patchDownload
From 66d1c479347d80ea45fc7aebaed873d45f9c4351 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Tue, 21 Nov 2023 14:20:56 +0300
Subject: [PATCH] [PATCH] Replace OR clause to ANY expressions. Replace (X=N1)
 OR (X=N2) ... with X = ANY(N1, N2) on the stage of the optimiser when we are
 still working with a tree expression. Firstly, we do not try to make a
 transformation for "non-or" expressions or inequalities and the creation of a
 relation with "or" expressions occurs according to the same scenario.
 Secondly, we do not make transformations if there are less than set
 or_transform_limit. Thirdly, it is worth considering that we consider "or"
 expressions only at the current level.

---
 src/backend/parser/parse_expr.c               | 280 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 115 +++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  50 ++++
 src/test/regress/expected/partition_prune.out | 156 ++++++++++
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  17 ++
 src/test/regress/sql/create_index.sql         |  32 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 14 files changed, 703 insertions(+), 3 deletions(-)

diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344c..7b76c9f29a1 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -18,6 +18,7 @@
 #include "catalog/pg_aggregate.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
+#include "common/hashfn.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
@@ -43,6 +44,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = false;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -98,7 +100,283 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 							  Node *ltree, Node *rtree, int location);
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
+typedef struct OrClauseGroupEntry
+{
+	int32			hash_leftvar_key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	Node 		   *expr;
+} OrClauseGroupEntry;
+
+/*
+ * TODO: consider different algorithm to manage complexity
+ * in the case of many different clauses,
+ * like Rabin-Karp or Boyer–Moore algorithms.
+ */
+static char *
+clear_patterns(const char *str, const char *start_pattern)
+{
+	int			i = 0;
+	int			j = 0;
+	int			start_pattern_len = strlen(start_pattern);
+	char	   *res = palloc0(sizeof(*res) * (strlen(str) + 1));
+
+	for (i = 0; str[i];)
+	{
+		if (i >= start_pattern_len && strncmp(&str[i - start_pattern_len],
+											  start_pattern,
+											  start_pattern_len) == 0)
+		{
+			while (str[i] && !(str[i] == '{' || str[i] == '}'))
+				i++;
+		}
+		if (str[i])
+			res[j++] = str[i++];
+	}
+
+	return res;
+}
+
+static int32
+get_key_nconst_node(Node *nconst_node)
+{
+	char *str = nodeToString(nconst_node);
+
+	str = clear_patterns(str, " :location");
+
+	if (str == NULL)
+		return 0;
+
+	return DatumGetInt32(hash_any((unsigned char *)str, strlen(str)));
+}
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
+{
+	List		   *or_list = NIL;
+	ListCell	   *lc;
+	HASHCTL			info;
+	HTAB 		   *or_group_htab = NULL;
+	int 			len_ors = list_length(expr_orig->args);
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR || !enable_or_transformation || len_ors == 1 || !or_group_htab)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(int);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	or_group_htab = hash_create("OR Groups",
+									  len_ors,
+									  &info,
+									  HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);
+
+	foreach(lc, expr_orig->args)
+	{
+		Node			   *arg = lfirst(lc);
+		Node			   *orqual = NULL;
+		Node			   *const_expr = NULL;
+		Node			   *nconst_expr = NULL;
+		OrClauseGroupEntry *gentry = NULL;
+		bool				found;
+		int32				hash;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
 
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		hash = get_key_nconst_node(nconst_expr);
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)) || hash == 0)
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		gentry = hash_search(or_group_htab, &hash, HASH_FIND, &found);
+
+		if (found)
+		{
+			gentry->consts = lappend(gentry->consts, const_expr);
+			/*
+				* The clause classified successfully and added into existed
+				* clause group.
+				*/
+			continue;
+		}
+
+		/* New clause group needed */
+		gentry = hash_search(or_group_htab, &hash, HASH_ENTER, &found);
+		gentry->node = nconst_expr;
+		gentry->consts = list_make1(const_expr);
+		gentry->expr = orqual;
+		gentry->hash_leftvar_key = hash;
+	}
+
+	if (or_group_htab && (hash_get_num_entries(or_group_htab) < 1 ||
+	                         hash_get_num_entries(or_group_htab) == len_ors))
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		hash_destroy(or_group_htab);
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr_orig->location);
+	}
+	else
+	{
+		HASH_SEQ_STATUS		hash_seq;
+		OrClauseGroupEntry *gentry;
+
+		hash_seq_init(&hash_seq, or_group_htab);
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		while ((gentry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
+		{
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List	   *aexprs = NIL;
+				ArrayExpr  *newa = NULL;
+				ScalarArrayOpExpr *saopexpr = NULL;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, gentry->expr);
+			}
+			hash_search(or_group_htab, &gentry->hash_leftvar_key, HASH_REMOVE, NULL);
+		}
+		hash_destroy(or_group_htab);
+	}
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+						makeBoolExpr(OR_EXPR, or_list, expr_orig->location) :
+						linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +490,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = (Node *)transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index b764ef69980..e2495529d29 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,16 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&enable_or_transformation,
+		false,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..3a87de02859 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..dbc8bc3bed0 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,121 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..0f2b1b16200 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ enable_or_transformation
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 2c73270143b..5af2cf09107 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4233,6 +4233,56 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
+
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c0556..804fea9f34c 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,140 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 271313ebf86..566f51df428 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -123,6 +123,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | off
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -133,7 +134,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(22 rows)
+(23 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..be4d88200b6 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..48bb1bc0a0a 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 8a8a63bd2f1..55d7e2ae7d6 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827f..1e270ae9c06 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..0499bedb9eb 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index dba3498a13e..c9004250a5f 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1641,6 +1641,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

21.11_origin_diff2.diff.txttext/plain; charset=UTF-8; name=21.11_origin_diff2.diff.txtDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 290422005a3..7b76c9f29a1 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -162,6 +162,10 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 	HTAB 		   *or_group_htab = NULL;
 	int 			len_ors = list_length(expr_orig->args);
 
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (expr_orig->boolop != OR_EXPR || !enable_or_transformation || len_ors == 1 || !or_group_htab)
+		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
+
 	MemSet(&info, 0, sizeof(info));
 	info.keysize = sizeof(int);
 	info.entrysize = sizeof(OrClauseGroupEntry);
@@ -170,10 +174,6 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr_orig)
 									  &info,
 									  HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);
 
-	/* If this is not an 'OR' expression, skip the transformation */
-	if (expr_orig->boolop != OR_EXPR || !enable_or_transformation || len_ors == 1 || !or_group_htab)
-		return transformBoolExpr(pstate, (BoolExpr *) expr_orig);
-
 	foreach(lc, expr_orig->args)
 	{
 		Node			   *arg = lfirst(lc);
#95Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#94)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 21/11/2023 18:31, Alena Rybakina wrote:

Sorry, I lost your changes  during the revision process. I returned
them. I raised the patch version just in case to run ci successfully.

I think the usage of nodeToString for the generation of clause hash is
too expensive and buggy.
Also, in the code, you didn't resolve hash collisions. So, I've
rewritten the patch a bit (see the attachment).
One more thing: I propose to enable transformation by default at least
for quick detection of possible issues.
This code changes tests in many places. But, as I see it, it mostly
demonstrates the positive effect of the transformation.

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v11-0001-Transform-OR-clause-to-ANY-expressions.patchtext/plain; charset=UTF-8; name=v11-0001-Transform-OR-clause-to-ANY-expressions.patchDownload
From 5071d02426ac3430f4dd61a8ad32c2847ba6f8a5 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Thu, 23 Nov 2023 16:00:13 +0700
Subject: [PATCH] Transform OR clause to ANY expressions.

Replace (X=N1) OR (X=N2) ... with X = ANY(N1, N2) on the preliminary stage of
optimization when we are still working with a tree expression.
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
---
 src/backend/nodes/queryjumblefuncs.c          |  30 ++
 src/backend/parser/parse_expr.c               | 285 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/include/nodes/queryjumble.h               |   1 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 141 +++++++--
 src/test/regress/expected/create_view.out     |   2 +-
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/inherit.out         |   2 +-
 src/test/regress/expected/join.out            |  62 +++-
 src/test/regress/expected/partition_prune.out | 215 +++++++++++--
 src/test/regress/expected/rules.out           |  18 +-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  32 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 21 files changed, 815 insertions(+), 66 deletions(-)

diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 281907a4d8..99207a8670 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -135,6 +135,36 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	if (*queryId == UINT64CONST(0))
+		*queryId = UINT64CONST(1);
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344..d782642771 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -22,6 +22,7 @@
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -43,6 +44,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +101,287 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+typedef struct OrClauseGroupEntries
+{
+	uint64	hashkey;
+	List   *list;
+} OrClauseGroupEntries;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
+{
+	List				   *or_list = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(expr->args);
+	HASH_SEQ_STATUS			hash_seq;
+	OrClauseGroupEntries   *entries;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (!enable_or_transformation || expr->boolop != OR_EXPR || len_ors < 2)
+		return transformBoolExpr(pstate, (BoolExpr *) expr);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(uint64);
+	info.entrysize = sizeof(OrClauseGroupEntries);
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_BLOBS);
+
+	foreach(lc, expr->args)
+	{
+		Node				   *arg = lfirst(lc);
+		Node				   *orqual;
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupEntries   *entries;
+		OrClauseGroupEntry	   *entry = NULL;
+		bool					found;
+		uint64					hash;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+		orqual = eval_const_expressions(NULL, orqual);
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		(void) JumbleExpr((Expr *) nconst_expr, &hash);
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		entries = hash_search(or_group_htab, &hash, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			ListCell *lc1;
+
+			Assert(entries->list != NULL);
+
+			/*
+			 * Try to find the same expression in the list of expressions with
+			 * the same hash value
+			 */
+			foreach(lc1, entries->list)
+			{
+				OrClauseGroupEntry *elem = (OrClauseGroupEntry *) lfirst(lc1);
+
+				if (equal(nconst_expr, elem->node))
+				{
+					entry = elem;
+					entry->consts = lappend(entry->consts, const_expr);
+					entry->exprs = lappend(entry->exprs, orqual);
+					break;
+				}
+			}
+
+			if (entry != NULL)
+			{
+				/*
+				 * The clause classified successfully and added into existed
+				 * clause group.
+				 */
+				continue;
+			}
+
+			found = false;
+		}
+		else
+			/* Prepare for adding to the list the first element */
+			entries->list = NIL;
+
+		if (!found)
+		{
+			Assert(entry == NULL);
+
+			entry = palloc(sizeof(OrClauseGroupEntry));
+			entry->node = nconst_expr;
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+			entries->list = lappend(entries->list, entry);
+		}
+	}
+
+	if (list_length(or_list) == len_ors)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		hash_destroy(or_group_htab);
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr->location);
+	}
+
+	hash_seq_init(&hash_seq, or_group_htab);
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	* consts more than 1. trivial groups move to OR-list again
+	*/
+
+	while ((entries = (OrClauseGroupEntries *) hash_seq_search(&hash_seq)) != NULL)
+	{
+		ListCell *lc1;
+
+		foreach(lc1, entries->list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc1);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+			Assert(list_length(gentry->exprs) == list_length(gentry->consts));
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = list_concat(or_list, gentry->exprs);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List			   *aexprs = NIL;
+				ArrayExpr		   *newa = NULL;
+				ScalarArrayOpExpr  *saopexpr = NULL;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				/*
+				 * This part works on intarray test (OR there is made on
+				 * elements of a custom type)
+				 */
+				list_free(gentry->consts);
+				or_list = list_concat(or_list, gentry->exprs);
+			}
+		}
+		list_free(entries->list);
+		entries->list = NIL;
+		hash_search(or_group_htab, &entries->hashkey, HASH_REMOVE, NULL);
+	}
+	hash_destroy(or_group_htab);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, expr->location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +495,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index b764ef6998..2ca8a21caf 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,16 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index e48c066a5b..26bee30ad3 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -371,6 +371,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index 0769081c7a..4aaa31aa80 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7..3a87de0285 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f..3bb4bbca48 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,101 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/create_view.out b/src/test/regress/expected/create_view.out
index 61825ef7d4..b3b1670fd9 100644
--- a/src/test/regress/expected/create_view.out
+++ b/src/test/regress/expected/create_view.out
@@ -2196,7 +2196,7 @@ select pg_get_viewdef('tt26v', true);
      x + (y + z) AS c6,                            +
      x + (y # z) AS c7,                            +
      x > y AND (y > z OR x > z) AS c8,             +
-     x > y OR y > z AND NOT x > z AS c9,           +
+     x > y OR y > z AND x <= z AS c9,              +
      ((x, y) <> ALL ( VALUES (1,2), (3,4))) AS c10,+
      ((x, y) <= ANY ( VALUES (1,2), (3,4))) AS c11 +
     FROM ( VALUES (1,2,3)) v(x, y, z);
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c953297..0f2b1b1620 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ enable_or_transformation
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 0f1aa831f6..1781250122 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -2560,7 +2560,7 @@ explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd'
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 2c73270143..e952e5401f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c055..14a254fba7 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +618,13 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -1933,10 +2112,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 1442c43d9c..e3ed533832 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2145,7 +2145,7 @@ pg_stat_sys_indexes| SELECT relid,
     idx_tup_read,
     idx_tup_fetch
    FROM pg_stat_all_indexes
-  WHERE ((schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (schemaname ~ '^pg_toast'::text));
+  WHERE ((schemaname = ANY ('{pg_catalog,information_schema}'::name[])) OR (schemaname ~ '^pg_toast'::text));
 pg_stat_sys_tables| SELECT relid,
     schemaname,
     relname,
@@ -2173,7 +2173,7 @@ pg_stat_sys_tables| SELECT relid,
     analyze_count,
     autoanalyze_count
    FROM pg_stat_all_tables
-  WHERE ((schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (schemaname ~ '^pg_toast'::text));
+  WHERE ((schemaname = ANY ('{pg_catalog,information_schema}'::name[])) OR (schemaname ~ '^pg_toast'::text));
 pg_stat_user_functions| SELECT p.oid AS funcid,
     n.nspname AS schemaname,
     p.proname AS funcname,
@@ -2279,7 +2279,7 @@ pg_stat_xact_sys_tables| SELECT relid,
     n_tup_hot_upd,
     n_tup_newpage_upd
    FROM pg_stat_xact_all_tables
-  WHERE ((schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (schemaname ~ '^pg_toast'::text));
+  WHERE ((schemaname = ANY ('{pg_catalog,information_schema}'::name[])) OR (schemaname ~ '^pg_toast'::text));
 pg_stat_xact_user_functions| SELECT p.oid AS funcid,
     n.nspname AS schemaname,
     p.proname AS funcname,
@@ -2354,14 +2354,14 @@ pg_statio_sys_indexes| SELECT relid,
     idx_blks_read,
     idx_blks_hit
    FROM pg_statio_all_indexes
-  WHERE ((schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (schemaname ~ '^pg_toast'::text));
+  WHERE ((schemaname = ANY ('{pg_catalog,information_schema}'::name[])) OR (schemaname ~ '^pg_toast'::text));
 pg_statio_sys_sequences| SELECT relid,
     schemaname,
     relname,
     blks_read,
     blks_hit
    FROM pg_statio_all_sequences
-  WHERE ((schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (schemaname ~ '^pg_toast'::text));
+  WHERE ((schemaname = ANY ('{pg_catalog,information_schema}'::name[])) OR (schemaname ~ '^pg_toast'::text));
 pg_statio_sys_tables| SELECT relid,
     schemaname,
     relname,
@@ -2374,7 +2374,7 @@ pg_statio_sys_tables| SELECT relid,
     tidx_blks_read,
     tidx_blks_hit
    FROM pg_statio_all_tables
-  WHERE ((schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (schemaname ~ '^pg_toast'::text));
+  WHERE ((schemaname = ANY ('{pg_catalog,information_schema}'::name[])) OR (schemaname ~ '^pg_toast'::text));
 pg_statio_user_indexes| SELECT relid,
     indexrelid,
     schemaname,
@@ -2471,7 +2471,7 @@ pg_stats| SELECT n.nspname AS schemaname,
      JOIN pg_class c ON ((c.oid = s.starelid)))
      JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
-  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((NOT c.relrowsecurity) OR (NOT row_security_active(c.oid))));
 pg_stats_ext| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2502,7 +2502,7 @@ pg_stats_ext| SELECT cn.nspname AS schemaname,
   WHERE ((NOT (EXISTS ( SELECT 1
            FROM (unnest(s.stxkeys) k(k)
              JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
-          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((NOT c.relrowsecurity) OR (NOT row_security_active(c.oid))));
 pg_stats_ext_exprs| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2616,7 +2616,7 @@ pg_user_mappings| SELECT u.oid AS umid,
             ELSE a.rolname
         END AS usename,
         CASE
-            WHEN (((u.umuser <> (0)::oid) AND (a.rolname = CURRENT_USER) AND (pg_has_role(s.srvowner, 'USAGE'::text) OR has_server_privilege(s.oid, 'USAGE'::text))) OR ((u.umuser = (0)::oid) AND pg_has_role(s.srvowner, 'USAGE'::text)) OR ( SELECT pg_authid.rolsuper
+            WHEN (((u.umuser <> '0'::oid) AND (a.rolname = CURRENT_USER) AND (pg_has_role(s.srvowner, 'USAGE'::text) OR has_server_privilege(s.oid, 'USAGE'::text))) OR ((u.umuser = '0'::oid) AND pg_has_role(s.srvowner, 'USAGE'::text)) OR ( SELECT pg_authid.rolsuper
                FROM pg_authid
               WHERE (pg_authid.rolname = CURRENT_USER))) THEN u.umoptions
             ELSE NULL::text[]
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index a430153b22..659d712f75 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 271313ebf8..c6c6b9fb8d 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -123,6 +123,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -133,7 +134,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(22 rows)
+(23 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..2a079e996b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..48bb1bc0a0 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 8a8a63bd2f..55d7e2ae7d 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827..1e270ae9c0 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index dba3498a13..b200363d4e 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1641,6 +1641,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntries
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.43.0

#96Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Andrei Lepikhov (#95)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 23/11/2023 16:23, Andrei Lepikhov wrote:

This code changes tests in many places. But, as I see it, it mostly
demonstrates the positive effect of the transformation.

I found out that the postgres_fdw tests were impacted by the feature.
Fix it, because the patch is on the commitfest and passes buildfarm.
Taking advantage of this, I suppressed the expression evaluation
procedure to make regression test changes more clear.

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v11-1-0001-Transform-OR-clause-to-ANY-expressions.patchtext/plain; charset=UTF-8; name=v11-1-0001-Transform-OR-clause-to-ANY-expressions.patchDownload
From e29b35d3445d9852f3ecb9cdaa4f231c72334973 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Thu, 23 Nov 2023 16:00:13 +0700
Subject: [PATCH] Transform OR clause to ANY expressions.

Replace (X=N1) OR (X=N2) ... with X = ANY(N1, N2) on the preliminary stage of
optimization when we are still working with a tree expression.
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
---
 .../postgres_fdw/expected/postgres_fdw.out    |   8 +-
 src/backend/nodes/queryjumblefuncs.c          |  30 ++
 src/backend/parser/parse_expr.c               | 284 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/include/nodes/queryjumble.h               |   1 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 141 +++++++--
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/inherit.out         |   2 +-
 src/test/regress/expected/join.out            |  62 +++-
 src/test/regress/expected/partition_prune.out | 215 +++++++++++--
 src/test/regress/expected/rules.out           |   4 +-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  32 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 21 files changed, 810 insertions(+), 62 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 64bcc66b8d..a8442f08aa 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8537,18 +8537,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 281907a4d8..99207a8670 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -135,6 +135,36 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	if (*queryId == UINT64CONST(0))
+		*queryId = UINT64CONST(1);
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344..b69381cc45 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -22,6 +22,7 @@
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -43,6 +44,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +101,286 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupEntry
+{
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+typedef struct OrClauseGroupEntries
+{
+	uint64	hashkey;
+	List   *list;
+} OrClauseGroupEntries;
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
+{
+	List				   *or_list = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(expr->args);
+	HASH_SEQ_STATUS			hash_seq;
+	OrClauseGroupEntries   *entries;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (!enable_or_transformation || expr->boolop != OR_EXPR || len_ors < 2)
+		return transformBoolExpr(pstate, (BoolExpr *) expr);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(uint64);
+	info.entrysize = sizeof(OrClauseGroupEntries);
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_BLOBS);
+
+	foreach(lc, expr->args)
+	{
+		Node				   *arg = lfirst(lc);
+		Node				   *orqual;
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupEntries   *entries;
+		OrClauseGroupEntry	   *entry = NULL;
+		bool					found;
+		uint64					hash;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		(void) JumbleExpr((Expr *) nconst_expr, &hash);
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		entries = hash_search(or_group_htab, &hash, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			ListCell *lc1;
+
+			Assert(entries->list != NULL);
+
+			/*
+			 * Try to find the same expression in the list of expressions with
+			 * the same hash value
+			 */
+			foreach(lc1, entries->list)
+			{
+				OrClauseGroupEntry *elem = (OrClauseGroupEntry *) lfirst(lc1);
+
+				if (equal(nconst_expr, elem->node))
+				{
+					entry = elem;
+					entry->consts = lappend(entry->consts, const_expr);
+					entry->exprs = lappend(entry->exprs, orqual);
+					break;
+				}
+			}
+
+			if (entry != NULL)
+			{
+				/*
+				 * The clause classified successfully and added into existed
+				 * clause group.
+				 */
+				continue;
+			}
+
+			found = false;
+		}
+		else
+			/* Prepare for adding to the list the first element */
+			entries->list = NIL;
+
+		if (!found)
+		{
+			Assert(entry == NULL);
+
+			entry = palloc(sizeof(OrClauseGroupEntry));
+			entry->node = nconst_expr;
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+			entries->list = lappend(entries->list, entry);
+		}
+	}
+
+	if (list_length(or_list) == len_ors)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		hash_destroy(or_group_htab);
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr->location);
+	}
+
+	hash_seq_init(&hash_seq, or_group_htab);
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	* consts more than 1. trivial groups move to OR-list again
+	*/
+
+	while ((entries = (OrClauseGroupEntries *) hash_seq_search(&hash_seq)) != NULL)
+	{
+		ListCell *lc1;
+
+		foreach(lc1, entries->list)
+		{
+			OrClauseGroupEntry *gentry = (OrClauseGroupEntry *) lfirst(lc1);
+			List			   *allexprs;
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+			Assert(list_length(gentry->exprs) == list_length(gentry->consts));
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				 * Only one element in the class. Return rinfo into the BoolExpr
+				 * args list unchanged.
+				 */
+				list_free(gentry->consts);
+				or_list = list_concat(or_list, gentry->exprs);
+				continue;
+			}
+
+			/*
+			 * Do the transformation.
+			 *
+			 * First of all, try to select a common type for the array elements.
+			 * Note that since the LHS' type is first in the list, it will be
+			 * preferred when there is doubt (eg, when all the RHS items are
+			 * unknown literals).
+			 *
+			 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			 *
+			 * As a source of insides, use make_scalar_array_op()
+			 */
+			allexprs = list_concat(list_make1(gentry->node), gentry->consts);
+			scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid)
+			{
+				/*
+				 * OK: coerce all the right-hand non-Var inputs to the common
+				 * type and build an ArrayExpr for them.
+				 */
+				List			   *aexprs = NIL;
+				ArrayExpr		   *newa = NULL;
+				ScalarArrayOpExpr  *saopexpr = NULL;
+				ListCell *l;
+
+				aexprs = NIL;
+
+				foreach(l, gentry->consts)
+				{
+					Node	   *rexpr = (Node *) lfirst(l);
+
+					rexpr = coerce_to_common_type(pstate, rexpr,
+												scalar_type,
+												"IN");
+					aexprs = lappend(aexprs, rexpr);
+				}
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				saopexpr =
+					(ScalarArrayOpExpr *)
+						make_scalar_array_op(pstate,
+											 list_make1(makeString((char *) "=")),
+											 true,
+											 gentry->node,
+											 (Node *) newa,
+											 -1);
+
+				or_list = lappend(or_list, (void *) saopexpr);
+			}
+			else
+			{
+				/*
+				 * This part works on intarray test (OR there is made on
+				 * elements of a custom type)
+				 */
+				list_free(gentry->consts);
+				or_list = list_concat(or_list, gentry->exprs);
+			}
+		}
+		list_free(entries->list);
+		entries->list = NIL;
+		hash_search(or_group_htab, &entries->hashkey, HASH_REMOVE, NULL);
+	}
+	hash_destroy(or_group_htab);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, expr->location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +494,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index b764ef6998..2ca8a21caf 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,16 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index e48c066a5b..26bee30ad3 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -371,6 +371,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index 0769081c7a..4aaa31aa80 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7..3a87de0285 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f..3bb4bbca48 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,101 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c953297..0f2b1b1620 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ enable_or_transformation
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 0f1aa831f6..1781250122 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -2560,7 +2560,7 @@ explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd'
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 2c73270143..e952e5401f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c055..14a254fba7 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +618,13 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -1933,10 +2112,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 1442c43d9c..3bef969328 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2471,7 +2471,7 @@ pg_stats| SELECT n.nspname AS schemaname,
      JOIN pg_class c ON ((c.oid = s.starelid)))
      JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
-  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2502,7 +2502,7 @@ pg_stats_ext| SELECT cn.nspname AS schemaname,
   WHERE ((NOT (EXISTS ( SELECT 1
            FROM (unnest(s.stxkeys) k(k)
              JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
-          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext_exprs| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index a430153b22..659d712f75 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 271313ebf8..c6c6b9fb8d 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -123,6 +123,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -133,7 +134,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(22 rows)
+(23 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..2a079e996b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..48bb1bc0a0 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 8a8a63bd2f..55d7e2ae7d 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827..1e270ae9c0 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index dba3498a13..b200363d4e 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1641,6 +1641,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntries
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.43.0

#97Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Andrei Lepikhov (#96)
Re: POC, WIP: OR-clause support for indexes

On 23.11.2023 12:23, Andrei Lepikhov wrote:

I think the usage of nodeToString for the generation of clause hash is
too expensive and buggy.
Also, in the code, you didn't resolve hash collisions. So, I've
rewritten the patch a bit (see the attachment).
One more thing: I propose to enable transformation by default at least
for quick detection of possible issues.
This code changes tests in many places. But, as I see it, it mostly
demonstrates the positive effect of the transformation.

On 24.11.2023 06:30, Andrei Lepikhov wrote:

On 23/11/2023 16:23, Andrei Lepikhov wrote:

This code changes tests in many places. But, as I see it, it mostly
demonstrates the positive effect of the transformation.

I found out that the postgres_fdw tests were impacted by the feature.
Fix it, because the patch is on the commitfest and passes buildfarm.
Taking advantage of this, I suppressed the expression evaluation
procedure to make regression test changes more clear.

Thank you for your work. You are right, the patch with the current
changes looks better and works more correctly.

To be honest, I didn't think we could use JumbleExpr in this way.

--
Regards,
Alena Rybakina
Postgres Professional

#98Alexander Korotkov
aekorotkov@gmail.com
In reply to: a.rybakina (#90)
Re: POC, WIP: OR-clause support for indexes

Hi!

On Mon, Nov 13, 2023 at 9:48 PM a.rybakina <a.rybakina@postgrespro.ru> wrote:

These days I was porting a patch for converting or expressions to ANY to
the choose_bitmap_and function. Unfortunately, it is not possible to
transfer the conversion there, since expressions are processed one by
one, as far as I saw. Therefore, I tried to make the conversion earlier
in the generate_bitmap_or_paths function, there is just a loop bypass.
The patch turns out to be quite complicated, in my opinion, and to be
honest, it does not work fully yet. Also, due to the fact that the index
for the ScalarOpExpr expression is created earlier (approximately 344
lines in the src/backend/optimizer/path/indxpath.c file), we had to call
the generate_bitmap_or_paths function earlier. I haven't seen yet what
problems this could potentially lead to. Patch in the attached diff file.

It seems to me there is a confusion. I didn't mean we need to move
conversion of OR-expressions to ANY into choose_bitmap_and() function
or anything like this. My idea was to avoid degradation of plans,
which I've seen in [1]. Current code for generation of bitmap paths
considers the possibility to split OR-expressions into distinct bitmap
index scans. But it doesn't consider this possibility for
ANY-expressions. So, my idea was to enhance our bitmap scan
generation to consider split values of ANY-expressions into distinct
bitmap index scans. So, in the example [1] and similar queries
conversion of OR-expressions to ANY wouldn't affect the generation of
bitmap paths.

Links
1. /messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.com

------
Regards,
Alexander Korotkov

#99Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#97)
Re: POC, WIP: OR-clause support for indexes

On Fri, Nov 24, 2023 at 7:05 AM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 23.11.2023 12:23, Andrei Lepikhov wrote:

I think the usage of nodeToString for the generation of clause hash is
too expensive and buggy.
Also, in the code, you didn't resolve hash collisions. So, I've
rewritten the patch a bit (see the attachment).
One more thing: I propose to enable transformation by default at least
for quick detection of possible issues.
This code changes tests in many places. But, as I see it, it mostly
demonstrates the positive effect of the transformation.

On 24.11.2023 06:30, Andrei Lepikhov wrote:

On 23/11/2023 16:23, Andrei Lepikhov wrote:

This code changes tests in many places. But, as I see it, it mostly
demonstrates the positive effect of the transformation.

I found out that the postgres_fdw tests were impacted by the feature.
Fix it, because the patch is on the commitfest and passes buildfarm.
Taking advantage of this, I suppressed the expression evaluation
procedure to make regression test changes more clear.

Thank you for your work. You are right, the patch with the current
changes looks better and works more correctly.

To be honest, I didn't think we could use JumbleExpr in this way.

I think patch certainly gets better in this aspect. One thing I can't
understand is why do we use home-grown code for resolving
hash-collisions. You can just define custom hash and match functions
in HASHCTL. Even if we need to avoid repeated JumbleExpr calls, we
still can save pre-calculated hash value into hash entry and use
custom hash and match. This doesn't imply us to write our own
collision-resolving code.

------
Regards,
Alexander Korotkov

#100Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#98)
Re: POC, WIP: OR-clause support for indexes

On 25.11.2023 04:13, Alexander Korotkov wrote:

It seems to me there is a confusion. I didn't mean we need to move
conversion of OR-expressions to ANY into choose_bitmap_and() function
or anything like this. My idea was to avoid degradation of plans,
which I've seen in [1]. Current code for generation of bitmap paths
considers the possibility to split OR-expressions into distinct bitmap
index scans. But it doesn't consider this possibility for
ANY-expressions. So, my idea was to enhance our bitmap scan
generation to consider split values of ANY-expressions into distinct
bitmap index scans. So, in the example [1] and similar queries
conversion of OR-expressions to ANY wouldn't affect the generation of
bitmap paths.

Thanks for the explanation, yes, I did not understand the idea correctly
at first. I will try to implement something similar.

--
Regards,
Alena Rybakina
Postgres Professional

#101Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#100)
Re: POC, WIP: OR-clause support for indexes

On Sat, Nov 25, 2023 at 1:10 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 25.11.2023 04:13, Alexander Korotkov wrote:

It seems to me there is a confusion. I didn't mean we need to move
conversion of OR-expressions to ANY into choose_bitmap_and() function
or anything like this. My idea was to avoid degradation of plans,
which I've seen in [1]. Current code for generation of bitmap paths
considers the possibility to split OR-expressions into distinct bitmap
index scans. But it doesn't consider this possibility for
ANY-expressions. So, my idea was to enhance our bitmap scan
generation to consider split values of ANY-expressions into distinct
bitmap index scans. So, in the example [1] and similar queries
conversion of OR-expressions to ANY wouldn't affect the generation of
bitmap paths.

Thanks for the explanation, yes, I did not understand the idea correctly at first. I will try to implement something similar.

Alena, great, thank you. I'm looking forward to the updated patch.

------
Regards,
Alexander Korotkov

#102Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alexander Korotkov (#99)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 25/11/2023 08:23, Alexander Korotkov wrote:

I think patch certainly gets better in this aspect. One thing I can't
understand is why do we use home-grown code for resolving
hash-collisions. You can just define custom hash and match functions
in HASHCTL. Even if we need to avoid repeated JumbleExpr calls, we
still can save pre-calculated hash value into hash entry and use
custom hash and match. This doesn't imply us to write our own
collision-resolving code.

Thanks, it was an insightful suggestion.
I implemented it, and the code has become shorter (see attachment).

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v12-0001-Transform-OR-clause-to-ANY-expressions.patchtext/plain; charset=UTF-8; name=v12-0001-Transform-OR-clause-to-ANY-expressions.patchDownload
From 8a43f5b50be6cb431046ab352fbcb9bdd3e4376c Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Thu, 23 Nov 2023 16:00:13 +0700
Subject: [PATCH] Transform OR clause to ANY expressions.

Replace (X=N1) OR (X=N2) ... with X = ANY(N1, N2) on the preliminary stage of
optimization when we are still working with a tree expression.
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
---
 .../postgres_fdw/expected/postgres_fdw.out    |   8 +-
 src/backend/nodes/queryjumblefuncs.c          |  30 ++
 src/backend/parser/parse_expr.c               | 283 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/include/nodes/queryjumble.h               |   1 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 141 +++++++--
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/inherit.out         |   2 +-
 src/test/regress/expected/join.out            |  62 +++-
 src/test/regress/expected/partition_prune.out | 257 +++++++++++++---
 src/test/regress/expected/rules.out           |   4 +-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  32 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 21 files changed, 830 insertions(+), 83 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 22cae37a1e..fdfecd51c7 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8537,18 +8537,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 281907a4d8..99207a8670 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -135,6 +135,36 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	if (*queryId == UINT64CONST(0))
+		*queryId = UINT64CONST(1);
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344..0f2116a6f1 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -22,6 +22,7 @@
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -43,6 +44,7 @@
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +101,285 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	Oid				opno;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function that's compatible with guc_name_compare
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				hash;
+
+	(void) JumbleExpr(key->expr, &hash);
+	return hash;
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	dst_key->expr = src_key->expr;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in guc_hashtab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	if (equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
+{
+	List				   *or_list = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(expr->args);
+	HASH_SEQ_STATUS			hash_seq;
+	OrClauseGroupEntry	   *entry = NULL;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (!enable_or_transformation || expr->boolop != OR_EXPR || len_ors < 2)
+		return transformBoolExpr(pstate, (BoolExpr *) expr);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, expr->args)
+	{
+		Node				   *arg = lfirst(lc);
+		Node				   *orqual;
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		hashkey.expr = (Expr *) nconst_expr;
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->node = nconst_expr;
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+		}
+	}
+
+	if (list_length(or_list) == len_ors)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		hash_destroy(or_group_htab);
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr->location);
+	}
+
+	hash_seq_init(&hash_seq, or_group_htab);
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	* consts more than 1. trivial groups move to OR-list again
+	*/
+
+	while ((entry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
+	{
+		List			   *allexprs;
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element in the class. Return rinfo into the BoolExpr
+			 * args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 *
+		 * First of all, try to select a common type for the array elements.
+		 * Note that since the LHS' type is first in the list, it will be
+		 * preferred when there is doubt (eg, when all the RHS items are
+		 * unknown literals).
+		 *
+		 * Note: use list_concat here not lcons, to avoid damaging rnonvars.
+		 *
+		 * As a source of insides, use make_scalar_array_op()
+		 */
+		allexprs = list_concat(list_make1(entry->node), entry->consts);
+		scalar_type = select_common_type(NULL, allexprs, NULL, NULL);
+
+		if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+			array_type = get_array_type(scalar_type);
+		else
+			array_type = InvalidOid;
+
+		if (array_type != InvalidOid)
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			ListCell		   *l;
+
+			aexprs = NIL;
+
+			foreach(l, entry->consts)
+			{
+				Node	   *rexpr = (Node *) lfirst(l);
+
+				rexpr = coerce_to_common_type(pstate, rexpr,
+											  scalar_type,
+											  "IN");
+				aexprs = lappend(aexprs, rexpr);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 list_make1(makeString((char *) "=")),
+										 true,
+										 entry->node,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * This part works on intarray test (OR there is made on
+			 * elements of a custom type)
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+		hash_search(or_group_htab, &entry->key, HASH_REMOVE, NULL);
+	}
+	hash_destroy(or_group_htab);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, expr->location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +493,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index b764ef6998..2ca8a21caf 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,16 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index e48c066a5b..26bee30ad3 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -371,6 +371,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index 0769081c7a..4aaa31aa80 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7..3a87de0285 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f..3bb4bbca48 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,101 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c953297..0f2b1b1620 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ enable_or_transformation
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 0f1aa831f6..1781250122 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -2560,7 +2560,7 @@ explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd'
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 2c73270143..e952e5401f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c055..9b78cd9d74 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -526,29 +548,29 @@ explain (costs off) select * from rlp where a = 1 or b = 'ab';
 -------------------------------------------------------
  Append
    ->  Seq Scan on rlp1 rlp_1
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp2 rlp_2
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp3abcd rlp_3
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp4_1 rlp_4
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp4_2 rlp_5
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp4_default rlp_6
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp5_1 rlp_7
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp5_default rlp_8
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp_default_10 rlp_9
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp_default_30 rlp_10
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp_default_null rlp_11
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
    ->  Seq Scan on rlp_default_default rlp_12
-         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
 (25 rows)
 
 explain (costs off) select * from rlp where a > 20 and a < 27;
@@ -596,13 +618,13 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: (((b)::text = 'ab'::text) OR (a = 1))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -893,23 +1072,23 @@ explain (costs off) select * from mc3p where a = 1 or abs(b) = 1 or c = 1;
 ------------------------------------------------------
  Append
    ->  Seq Scan on mc3p0 mc3p_1
-         Filter: ((a = 1) OR (abs(b) = 1) OR (c = 1))
+         Filter: ((c = 1) OR (a = 1) OR (abs(b) = 1))
    ->  Seq Scan on mc3p1 mc3p_2
-         Filter: ((a = 1) OR (abs(b) = 1) OR (c = 1))
+         Filter: ((c = 1) OR (a = 1) OR (abs(b) = 1))
    ->  Seq Scan on mc3p2 mc3p_3
-         Filter: ((a = 1) OR (abs(b) = 1) OR (c = 1))
+         Filter: ((c = 1) OR (a = 1) OR (abs(b) = 1))
    ->  Seq Scan on mc3p3 mc3p_4
-         Filter: ((a = 1) OR (abs(b) = 1) OR (c = 1))
+         Filter: ((c = 1) OR (a = 1) OR (abs(b) = 1))
    ->  Seq Scan on mc3p4 mc3p_5
-         Filter: ((a = 1) OR (abs(b) = 1) OR (c = 1))
+         Filter: ((c = 1) OR (a = 1) OR (abs(b) = 1))
    ->  Seq Scan on mc3p5 mc3p_6
-         Filter: ((a = 1) OR (abs(b) = 1) OR (c = 1))
+         Filter: ((c = 1) OR (a = 1) OR (abs(b) = 1))
    ->  Seq Scan on mc3p6 mc3p_7
-         Filter: ((a = 1) OR (abs(b) = 1) OR (c = 1))
+         Filter: ((c = 1) OR (a = 1) OR (abs(b) = 1))
    ->  Seq Scan on mc3p7 mc3p_8
-         Filter: ((a = 1) OR (abs(b) = 1) OR (c = 1))
+         Filter: ((c = 1) OR (a = 1) OR (abs(b) = 1))
    ->  Seq Scan on mc3p_default mc3p_9
-         Filter: ((a = 1) OR (abs(b) = 1) OR (c = 1))
+         Filter: ((c = 1) OR (a = 1) OR (abs(b) = 1))
 (19 rows)
 
 explain (costs off) select * from mc3p where (a = 1 and abs(b) = 1) or (a = 10 and abs(b) = 10);
@@ -1933,10 +2112,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 05070393b9..c927c21dd4 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2495,7 +2495,7 @@ pg_stats| SELECT n.nspname AS schemaname,
      JOIN pg_class c ON ((c.oid = s.starelid)))
      JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
-  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2526,7 +2526,7 @@ pg_stats_ext| SELECT cn.nspname AS schemaname,
   WHERE ((NOT (EXISTS ( SELECT 1
            FROM (unnest(s.stxkeys) k(k)
              JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
-          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext_exprs| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index a430153b22..659d712f75 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 271313ebf8..c6c6b9fb8d 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -123,6 +123,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -133,7 +134,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(22 rows)
+(23 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..2a079e996b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..48bb1bc0a0 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 8a8a63bd2f..55d7e2ae7d 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827..1e270ae9c0 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 86a9886d4f..d9a7d9c284 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1642,6 +1642,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.43.0

#103Robert Haas
robertmhaas@gmail.com
In reply to: Andrei Lepikhov (#102)
Re: POC, WIP: OR-clause support for indexes

On Mon, Nov 27, 2023 at 3:02 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 25/11/2023 08:23, Alexander Korotkov wrote:

I think patch certainly gets better in this aspect. One thing I can't
understand is why do we use home-grown code for resolving
hash-collisions. You can just define custom hash and match functions
in HASHCTL. Even if we need to avoid repeated JumbleExpr calls, we
still can save pre-calculated hash value into hash entry and use
custom hash and match. This doesn't imply us to write our own
collision-resolving code.

Thanks, it was an insightful suggestion.
I implemented it, and the code has become shorter (see attachment).

Neither the code comments nor the commit message really explain the
design idea here. That's unfortunate, principally because it makes
review difficult.

I'm very skeptical about the idea of using JumbleExpr for any part of
this. It seems fairly expensive, and it might produce false matches.
If expensive is OK, then why not just use equal()? If it's not, then
this probably isn't really OK either. But in any case there should be
comments explaining why this strategy was chosen.

The use of op_mergejoinable() seems pretty random to me. Why should we
care about that? If somebody writes a<1 or a<2 or a<3 or a<4, you can
transform that to a<any(array[1,2,3,4]) if you want. It might not be a
good idea, but I think it's a legal transformation. The reader
shouldn't be left to guess whether a rule like this was made for
reasons of correctness or for reasons of efficiency or something else.
Looking further, I see that the reason for this is likely that the
operator for the transformation result is constructing using
list_make1(makeString((char *) "=")), but trying to choose an operator
based on the operator name is, I think, pretty clearly unacceptable.
Tom has fired more than one hacker out of an airlock for such
transgressions, and this violation seems less principled than some.
The = operator that got chosen could be entirely unrelated to any
operator in the original, untransformed query. It could be part of no
operator class that was involved in the original query, in a different
schema than the operator in the original query, and owned by a
different user than the one who owned any operator referenced by the
original query. I suspect that's not only incorrect but an exploitable
security vulnerability.

I am extremely dubious about the use of select_common_type() here. Why
not do this only when the types already match exactly? Maybe the
concern is unknown literals, but perhaps that should be handled in
some other way. If you do this kind of thing, you need to justify why
it can't fail or produce wrong answers.

Honestly, it seems very hard to avoid the conclusion that this
transformation is being done at too early a stage. Parse analysis is
not the time to try to do query optimization. I can't really believe
that there's a way to produce a committable patch along these lines.
Ideally, a transformation like this should be done after we know what
plan shape we're using (or considering using), so that we can make
cost-based decisions about whether to transform or not. But at the
very least it should happen somewhere in the planner. There's really
no justification for parse analysis rewriting the SQL that the user
entered.

--
Robert Haas
EDB: http://www.enterprisedb.com

In reply to: Robert Haas (#103)
Re: POC, WIP: OR-clause support for indexes

On Mon, Nov 27, 2023 at 1:04 PM Robert Haas <robertmhaas@gmail.com> wrote:

The use of op_mergejoinable() seems pretty random to me. Why should we
care about that? If somebody writes a<1 or a<2 or a<3 or a<4, you can
transform that to a<any(array[1,2,3,4]) if you want. It might not be a
good idea, but I think it's a legal transformation.

That kind of transformation is likely to be a very good idea, because
nbtree's _bt_preprocess_array_keys() function knows how to perform
preprocessing that makes the final index qual "a < 1". Obviously that
could be far more efficient.

Further suppose you have a machine generated query "a<1 or a<2 or a<3
or a<4 AND a = 2" -- same as before, except that I added "AND a = 2"
to the end. Now _bt_preprocess_array_keys() will be able to do the
aforementioned inequality preprocessing, just as before. But this time
_bt_preprocess_keys() (a different function with a similar name) can
see that the quals are contradictory. That makes the entire index scan
end, before it ever really began.

Obviously, this is an example of a more general principle: a great
deal of the benefit of these transformations is indirect, in the sense
that they come from enabling further transformations/optimizations,
that apply in the context of some particular query. So you have to
think holistically.

It's perhaps a little unfortunate that all of this nbtree
preprocessing stuff is totally opaque to the planner. Tom has
expressed concerns about that in the past, FWIW:

/messages/by-id/2587523.1647982549@sss.pgh.pa.us
(see the final paragraph for the reference)

There might be some bigger picture to doing all of these
transformations, in a way that maximizes opportunities to apply
further transformations/optimizations. You know much more about the
optimizer than I do, so maybe this is already very obvious. Just
pointing it out.

Honestly, it seems very hard to avoid the conclusion that this
transformation is being done at too early a stage. Parse analysis is
not the time to try to do query optimization. I can't really believe
that there's a way to produce a committable patch along these lines.
Ideally, a transformation like this should be done after we know what
plan shape we're using (or considering using), so that we can make
cost-based decisions about whether to transform or not. But at the
very least it should happen somewhere in the planner. There's really
no justification for parse analysis rewriting the SQL that the user
entered.

I am sure that there is a great deal of truth to this. The general
conclusion about parse analysis being the wrong place for this seems
very hard to argue with. But I'm much less sure that there needs to be
a conventional cost model.

The planner's cost model is supposed to have some basis in physical
runtime costs, which is not the case for any of these transformations.
Not in any general sense; they're just transformations that enable
finding a cheaper way to execute the query. While they have to pay for
themselves, in some sense, I think that that's purely a matter of
managing the added planner cycles. In principle they shouldn't have
any direct impact on the physical costs incurred by physical
operators. No?

As I keep pointing out, there is a sound theoretical basis to the idea
of normalizing to conjunctive normal form as its own standard step in
query processing. To some extent we do this already, but it's all
rather ad-hoc. Even if (say) the nbtree preprocessing transformations
that I described were something that the planner already knew about
directly, they still wouldn't really need to be costed. They're pretty
much strictly better at runtime (at most you only have to worry about
the fixed cost of determining if they apply at all).

--
Peter Geoghegan

#105Matthias van de Meent
boekewurm+postgres@gmail.com
In reply to: Peter Geoghegan (#104)
Re: POC, WIP: OR-clause support for indexes

On Mon, 27 Nov 2023, 23:16 Peter Geoghegan, <pg@bowt.ie> wrote:

On Mon, Nov 27, 2023 at 1:04 PM Robert Haas <robertmhaas@gmail.com> wrote:

The use of op_mergejoinable() seems pretty random to me. Why should we
care about that? If somebody writes a<1 or a<2 or a<3 or a<4, you can
transform that to a<any(array[1,2,3,4]) if you want. It might not be a
good idea, but I think it's a legal transformation.

That kind of transformation is likely to be a very good idea, because
nbtree's _bt_preprocess_array_keys() function knows how to perform
preprocessing that makes the final index qual "a < 1". Obviously that
could be far more efficient.

a < 4, you mean? The example mentioned ANY, not ALL

Further suppose you have a machine generated query "a<1 or a<2 or a<3

or a<4 AND a = 2" -- same as before, except that I added "AND a = 2"
to the end. Now _bt_preprocess_array_keys() will be able to do the
aforementioned inequality preprocessing, just as before. But this time
_bt_preprocess_keys() (a different function with a similar name) can
see that the quals are contradictory. That makes the entire index scan
end, before it ever really began.

With the given WHERE-clause I would hope it did *not* return before
scanning the index, given that any row with a < 3 is valid for that
constraint with current rules of operator precedence.

- Matthias

#106Robert Haas
robertmhaas@gmail.com
In reply to: Peter Geoghegan (#104)
Re: POC, WIP: OR-clause support for indexes

On Mon, Nov 27, 2023 at 5:16 PM Peter Geoghegan <pg@bowt.ie> wrote:

[ various observations ]

This all seems to make sense but I don't have anything particular to
say about it.

I am sure that there is a great deal of truth to this. The general
conclusion about parse analysis being the wrong place for this seems
very hard to argue with. But I'm much less sure that there needs to be
a conventional cost model.

I'm not sure about that part, either. The big reason we shouldn't do
this in parse analysis is that parse analysis is supposed to produce
an internal representation which is basically just a direct
translation of what the user entered. The representation should be
able to be deparsed to produce more or less what the user entered
without significant transformations. References to objects like tables
and operators do get resolved to OIDs at this stage, so deparsing
results will vary if objects are renamed or the search_path changes
and more or less schema-qualification is required or things like that,
but the output of parse analysis is supposed to preserve the meaning
of the query as entered by the user. The right place to do
optimization is in the optimizer.

But where in the optimizer to do it is an open question in my mind.

Previous discussion suggests to me that we might not really have
enough information at the beginning, because it seems like the right
thing to do depends on which plan we ultimately choose to use, which
gets to what you say here:

The planner's cost model is supposed to have some basis in physical
runtime costs, which is not the case for any of these transformations.
Not in any general sense; they're just transformations that enable
finding a cheaper way to execute the query. While they have to pay for
themselves, in some sense, I think that that's purely a matter of
managing the added planner cycles. In principle they shouldn't have
any direct impact on the physical costs incurred by physical
operators. No?

Right. It's just that, as a practical matter, some of the operators
deal with one form better than the other. So if we waited until we
knew which operator we were using to decide on which form to pick,
that would let us be smart.

As I keep pointing out, there is a sound theoretical basis to the idea
of normalizing to conjunctive normal form as its own standard step in
query processing. To some extent we do this already, but it's all
rather ad-hoc. Even if (say) the nbtree preprocessing transformations
that I described were something that the planner already knew about
directly, they still wouldn't really need to be costed. They're pretty
much strictly better at runtime (at most you only have to worry about
the fixed cost of determining if they apply at all).

It's just a matter of figuring out where we can put the logic and have
the result make sense. We'd like to put it someplace where it's not
too expensive and gets the right answer.

--
Robert Haas
EDB: http://www.enterprisedb.com

In reply to: Robert Haas (#106)
Re: POC, WIP: OR-clause support for indexes

On Mon, Nov 27, 2023 at 4:07 PM Robert Haas <robertmhaas@gmail.com> wrote:

I am sure that there is a great deal of truth to this. The general
conclusion about parse analysis being the wrong place for this seems
very hard to argue with. But I'm much less sure that there needs to be
a conventional cost model.

I'm not sure about that part, either. The big reason we shouldn't do
this in parse analysis is that parse analysis is supposed to produce
an internal representation which is basically just a direct
translation of what the user entered. The representation should be
able to be deparsed to produce more or less what the user entered
without significant transformations. References to objects like tables
and operators do get resolved to OIDs at this stage, so deparsing
results will vary if objects are renamed or the search_path changes
and more or less schema-qualification is required or things like that,
but the output of parse analysis is supposed to preserve the meaning
of the query as entered by the user.

One of the reasons why we shouldn't do this during parse analysis is
because query rewriting might matter. But that doesn't mean that the
transformation/normalization process must fundamentally be the
responsibility of the optimizer, through process of elimination.

Maybe it should be the responsibility of some other phase of query
processing, invented solely to make life easier for the optimizer, but
not formally part of query planning per se.

The right place to do
optimization is in the optimizer.

Then why doesn't the optimizer do query rewriting? Isn't that also a
kind of optimization, at least in part?

The planner's cost model is supposed to have some basis in physical
runtime costs, which is not the case for any of these transformations.
Not in any general sense; they're just transformations that enable
finding a cheaper way to execute the query. While they have to pay for
themselves, in some sense, I think that that's purely a matter of
managing the added planner cycles. In principle they shouldn't have
any direct impact on the physical costs incurred by physical
operators. No?

Right. It's just that, as a practical matter, some of the operators
deal with one form better than the other. So if we waited until we
knew which operator we were using to decide on which form to pick,
that would let us be smart.

ISTM that the real problem is that this is true in the first place. If
the optimizer had only one representation for any two semantically
equivalent spellings of the same qual, then it would always use the
best available representation. That seems even smarter, because that
way the planner can be dumb and still look fairly smart at runtime.

I am trying to be pragmatic, too (at least I think so). If having only
one representation turns out to be very hard, then maybe they weren't
ever really equivalent -- meaning it really is an optimization
problem, and the responsibility of the planner. It seems like it would
be more useful to spend time on making the world simpler for the
optimizer, rather than spending time on making the optimizer smarter.
Especially if we're talking about teaching the optimizer about what
are actually fairly accidental differences that come from
implementation details.

I understand that it'll never be black and white. There are practical
constraints on how far you go with this. We throw around terms like
"semantically equivalent" as if everybody agreed on precisely what
that means, which isn't really true (users complain when their view
definition has "<>" instead of "!="). Even still, I bet that we could
bring things far closer to this theoretical ideal, to good effect.

As I keep pointing out, there is a sound theoretical basis to the idea
of normalizing to conjunctive normal form as its own standard step in
query processing. To some extent we do this already, but it's all
rather ad-hoc. Even if (say) the nbtree preprocessing transformations
that I described were something that the planner already knew about
directly, they still wouldn't really need to be costed. They're pretty
much strictly better at runtime (at most you only have to worry about
the fixed cost of determining if they apply at all).

It's just a matter of figuring out where we can put the logic and have
the result make sense. We'd like to put it someplace where it's not
too expensive and gets the right answer.

Agreed.

--
Peter Geoghegan

#108Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#101)
3 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 25.11.2023 19:13, Alexander Korotkov wrote:

On Sat, Nov 25, 2023 at 1:10 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 25.11.2023 04:13, Alexander Korotkov wrote:

It seems to me there is a confusion. I didn't mean we need to move
conversion of OR-expressions to ANY into choose_bitmap_and() function
or anything like this. My idea was to avoid degradation of plans,
which I've seen in [1]. Current code for generation of bitmap paths
considers the possibility to split OR-expressions into distinct bitmap
index scans. But it doesn't consider this possibility for
ANY-expressions. So, my idea was to enhance our bitmap scan
generation to consider split values of ANY-expressions into distinct
bitmap index scans. So, in the example [1] and similar queries
conversion of OR-expressions to ANY wouldn't affect the generation of
bitmap paths.

Thanks for the explanation, yes, I did not understand the idea correctly at first. I will try to implement something similar.

Alena, great, thank you. I'm looking forward to the updated patch.

I wrote the patch (any_to_or.diff.txt), although it is still under
development (not all regression tests have been successful so far), it
is already clear that for a query where a bad plan was chosen before, it
is now choosing a more optimal query plan.

postgres=# set enable_or_transformation =on;
SET
postgres=# explain select * from test where (x = 1 or x = 2) and y = 100;
                                                  QUERY PLAN
--------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on test  (cost=8.60..12.62 rows=1 width=12)
   Recheck Cond: (((y = '100'::double precision) AND (x = 1)) OR ((y =
'100'::double precision) AND (x = 2)))
   ->  BitmapOr  (cost=8.60..8.60 rows=1 width=0)
         ->  Bitmap Index Scan on test_x_1_y  (cost=0.00..4.30 rows=1
width=0)
               Index Cond: (y = '100'::double precision)
         ->  Bitmap Index Scan on test_x_2_y  (cost=0.00..4.30 rows=1
width=0)
               Index Cond: (y = '100'::double precision)
(7 rows)

While I'm thinking how to combine it now.

BTW, while I was figuring out how create_index_paths works and creating
bitmapscan indexes, I think I found a bug with unallocated memory (fix
patch is bugfix.diff.txt). Without a fix here, it falls into the crust
at the stage of assigning a value to any of the variables, specifically,
skip_lower_stop and skip_nonnative_saop. I discovered it when I forced
to form a bitmapindex plan for ANY (any_to_or.diff.txt). I'm causing a
problem with my OR->ANY conversion patch.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

cause_problem.diff.txttext/plain; charset=UTF-8; name=cause_problem.diff.txtDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 03a5fbdc6dc..c242eec34d6 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -34,6 +34,7 @@
 #include "optimizer/restrictinfo.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "parser/parse_expr.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -715,8 +716,8 @@ get_index_paths(PlannerInfo *root, RelOptInfo *rel,
 				List **bitindexpaths)
 {
 	List	   *indexpaths;
-	bool		skip_nonnative_saop = false;
-	bool		skip_lower_saop = false;
+	bool		skip_nonnative_saop;
+	bool	    skip_lower_saop;
 	ListCell   *lc;
 
 	/*
@@ -737,7 +738,7 @@ get_index_paths(PlannerInfo *root, RelOptInfo *rel,
 	 * that supports them, then try again including those clauses.  This will
 	 * produce paths with more selectivity but no ordering.
 	 */
-	if (skip_lower_saop)
+	if (skip_lower_saop || enable_or_transformation)
 	{
 		indexpaths = list_concat(indexpaths,
 								 build_index_paths(root, rel,
@@ -778,7 +779,7 @@ get_index_paths(PlannerInfo *root, RelOptInfo *rel,
 	 * natively, generate bitmap scan paths relying on executor-managed
 	 * ScalarArrayOpExpr.
 	 */
-	if (skip_nonnative_saop)
+	if (skip_nonnative_saop || enable_or_transformation)
 	{
 		indexpaths = build_index_paths(root, rel,
 									   index, clauses,
@@ -908,7 +912,7 @@ build_index_paths(PlannerInfo *root, RelOptInfo *rel,
 			{
 				if (!index->amsearcharray)
 				{
-					if (skip_nonnative_saop)
+					if (skip_nonnative_saop || enable_or_transformation)
 					{
 						/* Ignore because not supported by index */
 						*skip_nonnative_saop = true;
@@ -919,7 +923,7 @@ build_index_paths(PlannerInfo *root, RelOptInfo *rel,
 				}
 				if (indexcol > 0)
 				{
-					if (skip_lower_saop)
+					if (skip_lower_saop || enable_or_transformation)
 					{
 						/* Caller doesn't want to lose index ordering */
 						*skip_lower_saop = true;
bugfix.diff.txttext/plain; charset=UTF-8; name=bugfix.diff.txtDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 03a5fbdc6dc..21a6d8febf4 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -854,6 +854,9 @@ build_index_paths(PlannerInfo *root, RelOptInfo *rel,
 	bool		index_only_scan;
 	int			indexcol;
 
+	skip_lower_saop = (bool *) palloc(sizeof(bool));
+	skip_nonnative_saop = (bool *) palloc(sizeof(bool));
+
 	/*
 	 * Check that index supports the desired scan type(s)
 	 */
any_to_or.diff.txttext/plain; charset=UTF-8; name=any_to_or.diff.txtDownload
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index 67921a08262..3cddc0a4082 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -50,6 +50,8 @@
 #include "port/pg_bitutils.h"
 #include "rewrite/rewriteManip.h"
 #include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "utils/array.h"
 
 
 /* Bitmask flags for pushdown_safety_info.unsafeFlags */
@@ -759,6 +761,179 @@ set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel,
 	rel->consider_parallel = true;
 }
 
+static List*
+research_or_list(Expr *qual, List *or_list, RestrictInfo *sub_rinfo)
+{
+	List *elem_exprs = NIL;
+
+	/* Check: it is an expr of the form 'F(x) oper ConstExpr' */
+	if (!IsA(qual, ScalarArrayOpExpr))
+	{
+		/* Again, it's not the expr we can transform */
+		or_list = lappend(or_list, qual);
+	}
+	else
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) qual;
+		Expr	   *rightop = (Expr *) lsecond(saop->args);
+		ListCell   *lc1;
+
+		if (sub_rinfo && !op_mergejoinable(((OpExpr *) sub_rinfo->clause)->opno, exprType(get_leftop(sub_rinfo->clause))))
+			{
+				/* And again, filter out non-equality operators */
+				or_list = lappend(or_list, (void *) qual);
+			}
+		else if (rightop && IsA(rightop, Const))
+		{
+			ArrayType  *arrval;
+			int16		elemlen;
+			bool		elembyval;
+			char		elemalign;
+			Datum	   *elem_values;
+			bool	   *elem_nulls;
+			int			num_elems,
+						i;
+			Const	   *arr = (Const *) rightop;
+
+			arrval = DatumGetArrayTypeP(arr->constvalue);
+			get_typlenbyvalalign(ARR_ELEMTYPE(arrval),
+								&elemlen, &elembyval, &elemalign);
+			deconstruct_array(arrval,
+							ARR_ELEMTYPE(arrval),
+							elemlen, elembyval, elemalign,
+							&elem_values, &elem_nulls,
+							&num_elems);
+
+			for (i = 0; i < num_elems; i++)
+			{
+				Const	   *elem_expr;
+
+				/*
+				* A null array element must lead to a null comparison result,
+				* since saop_op is known strict.  We can ignore it in the
+				* useOr case, but otherwise it implies self-contradiction.
+				*/
+				if (elem_nulls[i])
+				{
+					or_list = lappend(or_list, (void *) qual);
+					elem_exprs = NIL;
+					break;
+				}
+
+				elem_expr = makeConst(ARR_ELEMTYPE(arrval), -1,
+									arr->constcollid, elemlen,
+									elem_values[i], false, elembyval);
+				elem_exprs = lappend(elem_exprs, elem_expr);
+			}
+		}
+		else if (rightop && IsA(rightop, ArrayExpr) && !((ArrayExpr *) rightop)->multidims)
+		{
+			ArrayExpr  *arrexpr = (ArrayExpr  *)get_rightop(rightop);
+			elem_exprs = arrexpr->elements;
+		}
+		else
+			or_list = lappend(or_list, qual);
+
+		if (elem_exprs)
+		foreach(lc1, elem_exprs)
+		{
+			Expr	   *elem_clause;
+
+			elem_clause = make_opclause(((ScalarArrayOpExpr*) qual)->opno, BOOLOID, false,
+										(Expr *) linitial(((ScalarArrayOpExpr*)qual)->args), lfirst(lc1),
+										InvalidOid, ((ScalarArrayOpExpr*)qual)->inputcollid);
+			or_list = lappend(or_list, (void*) elem_clause);
+		}
+	}
+	return or_list;
+}
+
+static List *
+get_baserestrictinfo(PlannerInfo *root, List *baserestrictinfo)
+{
+	ListCell   *lc;
+	List	   *modified_rinfo = NIL;
+	bool		or_transformation = false;
+
+	if (!enable_or_transformation)
+		return NULL;
+
+	foreach(lc, baserestrictinfo)
+	{
+		RestrictInfo   *rinfo_base = lfirst_node(RestrictInfo, lc);
+		RestrictInfo   *rinfo;
+		List		   *or_list = NIL;
+
+		ListCell	   *lc_eargs,
+					   *lc_rargs;
+
+		if (!IsA(rinfo_base->clause, BoolExpr) && !IsA(rinfo_base->clause, ScalarArrayOpExpr))
+		{
+			/* Add a clause without changes */
+			modified_rinfo = lappend(modified_rinfo, rinfo_base);
+			continue;
+		}
+
+		if (IsA(rinfo_base->clause, BoolExpr) && is_orclause(rinfo_base->clause))
+		forboth(lc_eargs, ((BoolExpr *) rinfo_base->clause)->args,
+				lc_rargs, ((BoolExpr *) rinfo_base->orclause)->args)
+		{
+			Expr			   *orqual = (Expr *) lfirst(lc_eargs);
+			RestrictInfo 	   *sub_rinfo = lfirst_node(RestrictInfo, lc_rargs);
+
+			if (!IsA(orqual, OpExpr) ||
+				!(bms_is_empty(sub_rinfo->left_relids) ^
+				bms_is_empty(sub_rinfo->right_relids)) ||
+				contain_volatile_functions((Node *) orqual))
+			{
+				/* Again, it's not the expr we can transform */
+				or_list = lappend(or_list, (void *) orqual);
+				continue;
+			}
+
+			or_list = research_or_list(orqual, or_list, sub_rinfo);
+		}
+		else if (IsA(rinfo_base->clause, ScalarArrayOpExpr))
+		{
+			Expr			   *orqual = rinfo_base->clause;
+
+			or_list = research_or_list(orqual, or_list, NULL);
+		}
+		else
+		{
+			or_list = lappend(or_list, (void*)rinfo_base->clause);
+		}
+
+
+		rinfo = make_restrictinfo(root,
+				  list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, or_list, -1):
+																				(Expr *) linitial(or_list),
+				  rinfo_base->is_pushed_down,
+				  rinfo_base->has_clone,
+				  rinfo_base->is_clone,
+				  rinfo_base->pseudoconstant,
+				  rinfo_base->security_level,
+				  rinfo_base->required_relids,
+				  rinfo_base->incompatible_relids,
+				  rinfo_base->outer_relids);
+		rinfo->eval_cost=rinfo_base->eval_cost;
+		rinfo->norm_selec=rinfo_base->norm_selec;
+		rinfo->outer_selec=rinfo_base->outer_selec;
+		rinfo->left_bucketsize=rinfo_base->left_bucketsize;
+		rinfo->right_bucketsize=rinfo_base->right_bucketsize;
+		rinfo->left_mcvfreq=rinfo_base->left_mcvfreq;
+		rinfo->right_mcvfreq=rinfo_base->right_mcvfreq;
+		modified_rinfo = lappend(modified_rinfo, rinfo);
+		or_transformation = true;
+	}
+
+	if(or_transformation)
+	return modified_rinfo;
+
+	return baserestrictinfo;
+}
+
+
 /*
  * set_plain_rel_pathlist
  *	  Build access paths for a plain relation (no subquery, no inheritance)
@@ -767,6 +942,7 @@ static void
 set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 {
 	Relids		required_outer;
+	List *baserestrict_base = copyObject(rel->baserestrictinfo);
 
 	/*
 	 * We don't support pushing join clauses into the quals of a seqscan, but
@@ -778,6 +954,8 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 	/* Consider sequential scan */
 	add_path(rel, create_seqscan_path(root, rel, required_outer, 0));
 
+	rel->baserestrictinfo = get_baserestrictinfo(root, rel->baserestrictinfo);
+
 	/* If appropriate, consider parallel sequential scan */
 	if (rel->consider_parallel && required_outer == NULL)
 		create_plain_partial_paths(root, rel);
In reply to: Peter Geoghegan (#107)
Re: POC, WIP: OR-clause support for indexes

On Mon, Nov 27, 2023 at 5:07 PM Peter Geoghegan <pg@bowt.ie> wrote:

One of the reasons why we shouldn't do this during parse analysis is
because query rewriting might matter. But that doesn't mean that the
transformation/normalization process must fundamentally be the
responsibility of the optimizer, through process of elimination.

Maybe it should be the responsibility of some other phase of query
processing, invented solely to make life easier for the optimizer, but
not formally part of query planning per se.

Support for SEARCH and CYCLE clauses for recursive CTEs (added by
commit 3696a600e2) works by literally rewriting a parse node into a
form involving RowExpr and ScalarArrayOpExpr during rewriting. See
rewriteSearchAndCycle(). These implementation details are even
mentioned in user-facing docs.

Separately, the planner has long relied on certain generic
normalization steps from rewriteHandler.c. For example, it reorders
the targetlist from INSERT and UPDATE statements into what it knows to
be standard order within the planner, for the planner's convenience.

I'm not suggesting that these are any kind of precedent to follow now.
Just that they hint that rewriting/transformation prior to query
planning proper could be the right general approach. AFAICT that
really is what is needed. That, plus the work of fixing any
undesirable/unintended side effects that the transformations lead to,
which might be a difficult task in its own right (it likely requires
work in the planner).

--
Peter Geoghegan

#110Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Robert Haas (#103)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 28/11/2023 04:03, Robert Haas wrote:

On Mon, Nov 27, 2023 at 3:02 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 25/11/2023 08:23, Alexander Korotkov wrote:

I think patch certainly gets better in this aspect. One thing I can't
understand is why do we use home-grown code for resolving
hash-collisions. You can just define custom hash and match functions
in HASHCTL. Even if we need to avoid repeated JumbleExpr calls, we
still can save pre-calculated hash value into hash entry and use
custom hash and match. This doesn't imply us to write our own
collision-resolving code.

Thanks, it was an insightful suggestion.
I implemented it, and the code has become shorter (see attachment).

Neither the code comments nor the commit message really explain the
design idea here. That's unfortunate, principally because it makes
review difficult.

Yeah, it is still an issue. We will think about how to improve this; any
suggestions are welcome.

I'm very skeptical about the idea of using JumbleExpr for any part of
this. It seems fairly expensive, and it might produce false matches.
If expensive is OK, then why not just use equal()? If it's not, then
this probably isn't really OK either. But in any case there should be
comments explaining why this strategy was chosen.

We used the equal() routine without hashing in earlier versions. Hashing
resolves issues with many different OR clauses. Is it expensive? Maybe,
but we assume this transformation should be applied to simple enough
expressions.

The use of op_mergejoinable() seems pretty random to me. Why should we
care about that? If somebody writes a<1 or a<2 or a<3 or a<4, you can
transform that to a<any(array[1,2,3,4]) if you want. It might not be a
good idea, but I think it's a legal transformation.

You are right. The only reason was to obtain a working patch to
benchmark and look for corner cases. We would rewrite that place but
still live with the equivalence operator.

The reader shouldn't be left to guess whether a rule like this was made for
reasons of correctness or for reasons of efficiency or something else.
Looking further, I see that the reason for this is likely that the
operator for the transformation result is constructing using
list_make1(makeString((char *) "=")), but trying to choose an operator
based on the operator name is, I think, pretty clearly unacceptable.

Yes, it was a big mistake. It is fixed in the new version (I guess).

I am extremely dubious about the use of select_common_type() here. Why
not do this only when the types already match exactly? Maybe the
concern is unknown literals, but perhaps that should be handled in
some other way. If you do this kind of thing, you need to justify why
it can't fail or produce wrong answers.

Perhaps. We implemented your approach in the next version. At least we
could see consequences.

Honestly, it seems very hard to avoid the conclusion that this
transformation is being done at too early a stage. Parse analysis is
not the time to try to do query optimization. I can't really believe
that there's a way to produce a committable patch along these lines.
Ideally, a transformation like this should be done after we know what
plan shape we're using (or considering using), so that we can make
cost-based decisions about whether to transform or not. But at the
very least it should happen somewhere in the planner. There's really
no justification for parse analysis rewriting the SQL that the user
entered.

Here, we assume that array operation is generally better than many ORs.
As a result, it should be more effective to make OR->ANY transformation
in the parser (it is a relatively lightweight operation here) and, as a
second phase, decompose that in the optimizer.
We implemented earlier prototypes in different places of the optimizer,
and I'm convinced that only this approach resolves the issues we found.
Does this approach look weird? Maybe. We can debate it in this thread.

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v13-0001-Transform-OR-clause-to-ANY-expressions.patchtext/plain; charset=UTF-8; name=v13-0001-Transform-OR-clause-to-ANY-expressions.patchDownload
From a5f8eba522ff907f7a3fffb0635b61d38933e385 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Thu, 23 Nov 2023 16:00:13 +0700
Subject: [PATCH] Transform OR clause to ANY expressions.

Replace (X=N1) OR (X=N2) ... with X = ANY(N1, N2) on the preliminary stage of
optimization when we are still working with a tree expression.
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
---
 .../postgres_fdw/expected/postgres_fdw.out    |   8 +-
 src/backend/nodes/queryjumblefuncs.c          |  30 ++
 src/backend/parser/parse_expr.c               | 289 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/include/nodes/queryjumble.h               |   1 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 141 +++++++--
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/inherit.out         |   2 +-
 src/test/regress/expected/join.out            |  62 +++-
 src/test/regress/expected/partition_join.out  |   2 +-
 src/test/regress/expected/partition_prune.out | 215 +++++++++++--
 src/test/regress/expected/rules.out           |   4 +-
 src/test/regress/expected/select.out          |   6 +-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  32 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 23 files changed, 819 insertions(+), 66 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 22cae37a1e..fdfecd51c7 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8537,18 +8537,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 281907a4d8..99207a8670 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -135,6 +135,36 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	if (*queryId == UINT64CONST(0))
+		*queryId = UINT64CONST(1);
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344..d8c6096144 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,14 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -38,11 +40,13 @@
 #include "utils/date.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +103,289 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function that's compatible with guc_name_compare
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				hash;
+
+	(void) JumbleExpr(key->expr, &hash);
+	hash += ((uint64) key->opno + (uint64) key->exprtype) % UINT64_MAX;
+	return hash;
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in guc_hashtab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
+{
+	List				   *or_list = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(expr->args);
+	HASH_SEQ_STATUS			hash_seq;
+	OrClauseGroupEntry	   *entry = NULL;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (!enable_or_transformation || expr->boolop != OR_EXPR || len_ors < 2)
+		return transformBoolExpr(pstate, (BoolExpr *) expr);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, expr->args)
+	{
+		Node				   *arg = lfirst(lc);
+		Node				   *orqual;
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = ((OpExpr *) orqual)->opno;
+		hashkey.exprtype = exprType(nconst_expr);
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->node = nconst_expr;
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+		}
+	}
+
+	if (list_length(or_list) == len_ors)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		hash_destroy(or_group_htab);
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr->location);
+	}
+
+	hash_seq_init(&hash_seq, or_group_htab);
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	* consts more than 1. trivial groups move to OR-list again
+	*/
+
+	while ((entry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
+	{
+		List			   *allexprs;
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element in the class. Return rinfo into the BoolExpr
+			 * args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+		allexprs = list_concat(list_make1(entry->node), entry->consts);
+		scalar_type = entry->key.exprtype;
+
+		if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+			array_type = get_array_type(scalar_type);
+		else
+			array_type = InvalidOid;
+
+		if (array_type != InvalidOid)
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			ListCell		   *l;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+
+			aexprs = entry->consts;
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 entry->node,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * This part works on intarray test (OR there is made on
+			 * elements of a custom type)
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+		hash_search(or_group_htab, &entry->key, HASH_REMOVE, NULL);
+	}
+	hash_destroy(or_group_htab);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, expr->location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +499,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index b764ef6998..2ca8a21caf 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,16 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index e48c066a5b..26bee30ad3 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -371,6 +371,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index 0769081c7a..4aaa31aa80 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7..3a87de0285 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f..3bb4bbca48 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,101 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c953297..0f2b1b1620 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ enable_or_transformation
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 0f1aa831f6..1781250122 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -2560,7 +2560,7 @@ explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd'
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 2c73270143..e952e5401f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_join.out b/src/test/regress/expected/partition_join.out
index 6560fe2416..6e8d64655b 100644
--- a/src/test/regress/expected/partition_join.out
+++ b/src/test/regress/expected/partition_join.out
@@ -296,7 +296,7 @@ SELECT t1.a, t1.c, t2.b, t2.c FROM (SELECT * FROM prt1 WHERE a < 450) t1 FULL JO
    Sort Key: prt1.a, prt2.b
    ->  Hash Full Join
          Hash Cond: (prt1.a = prt2.b)
-         Filter: ((prt1.b = 0) OR (prt2.a = 0))
+         Filter: ((prt2.a = 0) OR (prt1.b = 0))
          ->  Append
                ->  Seq Scan on prt1_p1 prt1_1
                      Filter: (a < 450)
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c055..14a254fba7 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +618,13 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -1933,10 +2112,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 05070393b9..c927c21dd4 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2495,7 +2495,7 @@ pg_stats| SELECT n.nspname AS schemaname,
      JOIN pg_class c ON ((c.oid = s.starelid)))
      JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
-  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2526,7 +2526,7 @@ pg_stats_ext| SELECT cn.nspname AS schemaname,
   WHERE ((NOT (EXISTS ( SELECT 1
            FROM (unnest(s.stxkeys) k(k)
              JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
-          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext_exprs| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e..7a829c44c7 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -868,13 +868,13 @@ select unique1, unique2 from onek2
                                    QUERY PLAN                                   
 --------------------------------------------------------------------------------
  Bitmap Heap Scan on onek2
-   Recheck Cond: (((unique2 = 11) AND (stringu1 < 'B'::name)) OR (unique1 = 0))
+   Recheck Cond: ((unique1 = 0) OR ((unique2 = 11) AND (stringu1 < 'B'::name)))
    Filter: (stringu1 < 'B'::name)
    ->  BitmapOr
-         ->  Bitmap Index Scan on onek2_u2_prtl
-               Index Cond: (unique2 = 11)
          ->  Bitmap Index Scan on onek2_u1_prtl
                Index Cond: (unique1 = 0)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 = 11)
 (8 rows)
 
 select unique1, unique2 from onek2
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index a430153b22..659d712f75 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 271313ebf8..c6c6b9fb8d 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -123,6 +123,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -133,7 +134,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(22 rows)
+(23 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..2a079e996b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..48bb1bc0a0 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 8a8a63bd2f..55d7e2ae7d 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827..1e270ae9c0 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 86a9886d4f..d9a7d9c284 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1642,6 +1642,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.43.0

#111Robert Haas
robertmhaas@gmail.com
In reply to: Peter Geoghegan (#107)
Re: POC, WIP: OR-clause support for indexes

On Mon, Nov 27, 2023 at 8:08 PM Peter Geoghegan <pg@bowt.ie> wrote:

Maybe it should be the responsibility of some other phase of query
processing, invented solely to make life easier for the optimizer, but
not formally part of query planning per se.

I don't really see why that would be useful. Adding more stages to the
query pipeline adds cognitive burden for which there must be some
corresponding benefit. Even if this happened very early in query
planning as a completely separate pass over the query tree, that would
minimize the need for code changes outside the optimizer to need to
care about it. But I suspect that this shouldn't happen very early in
query planning as a completely separate pass, but someplace later
where it can be done together with other useful optimizations (e.g.
eval_const_expressions, or even path construction).

The right place to do
optimization is in the optimizer.

Then why doesn't the optimizer do query rewriting? Isn't that also a
kind of optimization, at least in part?

I mean, I think rewriting mostly means applying rules.

ISTM that the real problem is that this is true in the first place. If
the optimizer had only one representation for any two semantically
equivalent spellings of the same qual, then it would always use the
best available representation. That seems even smarter, because that
way the planner can be dumb and still look fairly smart at runtime.

Sure, well, that's another way of attacking the problem, but the
in-array representation is more convenient to loop over than the
or-clause representation, so if you get to a point where looping over
all the values is a thing you want to do, you're going to want
something that looks like that. If I just care about the fact that the
values I'm looking for are 3, 4, and 6, I want someone to hand me 3,
4, and 6, not x = 3, x = 4, and x = 6, and then I have to skip over
the x = part each time.

--
Robert Haas
EDB: http://www.enterprisedb.com

#112Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Andrei Lepikhov (#110)
Re: POC, WIP: OR-clause support for indexes

Hi!

Honestly, it seems very hard to avoid the conclusion that this
transformation is being done at too early a stage. Parse analysis is
not the time to try to do query optimization. I can't really believe
that there's a way to produce a committable patch along these lines.
Ideally, a transformation like this should be done after we know what
plan shape we're using (or considering using), so that we can make
cost-based decisions about whether to transform or not. But at the
very least it should happen somewhere in the planner. There's really
no justification for parse analysis rewriting the SQL that the user
entered.

Here, we assume that array operation is generally better than many ORs.
As a result, it should be more effective to make OR->ANY
transformation in the parser (it is a relatively lightweight operation
here) and, as a second phase, decompose that in the optimizer.
We implemented earlier prototypes in different places of the
optimizer, and I'm convinced that only this approach resolves the
issues we found.
Does this approach look weird? Maybe. We can debate it in this thread.

I think this is incorrect, and the example of A. Korotkov confirms this.
If we perform the conversion at the parsing stage, we will skip the more
important conversion using OR expressions. I'll show you in the example
below.

First of all, I will describe my idea to combine two approaches to
obtaining plans with OR to ANY transformation and ANY to OR
transformation. I think they are both good, and we can't work with just
one of them, we should consider both the option of OR expressions, and
with ANY.

I did this by creating a RelOptInfo with which has references from the
original RelOptInfo, for which conversion is possible either from
ANY->OR, or vice versa. After obtaining the necessary transformation, I
started the procedure for obtaining the seq and index paths for both
relations and then calculated their cost. The relation with the lowest
cost is considered the best.

I'm not sure if this is the best approach, but it's less complicated.

I noticed that I got a lower cost for not the best plan, but I think
this corresponds to another topic related to the wrong estimate calculation.

1. The first patch is a mixture of the original patch (when we perform
the conversion of OR to ANY at the parsing stage), and when we perform
the conversion at the index creation stage with the conversion to an OR
expression. We can see that the query proposed by A.Korotkov did not
have the best plan with ANY expression at all, and even despite
receiving a query with OR expressions, we cannot get anything better
than SeqScan, due to the lack of effective logical transformations that
would have been performed if we had left the OR expressions.

So, I got query plans using enable_or_transformation if it is enabled:

postgres=# create table test as (select (random()*10)::int x,
(random()*1000) y
from generate_series(1,1000000) i);
create index test_x_1_y on test (y) where x = 1;
create index test_x_2_y on test (y) where x = 2;
vacuum analyze test;
SELECT 1000000
CREATE INDEX
CREATE INDEX
VACUUM
postgres=# explain select * from test where (x = 1 or x = 2) and y = 100;
WARNING:  cost with original approach: - 20440.000000
WARNING:  cost with OR to ANY applied transfomation: - 15440.000000
                                QUERY PLAN
--------------------------------------------------------------------------
 Gather  (cost=1000.00..12690.10 rows=1 width=12)
   Workers Planned: 2
   ->  Parallel Seq Scan on test  (cost=0.00..11690.00 rows=1 width=12)
         Filter: (((x = 1) OR (x = 2)) AND (y = '100'::double precision))
(4 rows)

and if it is off:

postgres=# set enable_or_transformation =off;
SET
postgres=# explain select * from test where (x = 1 or x = 2) and y = 100;
                                                  QUERY PLAN
--------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on test  (cost=8.60..12.62 rows=1 width=12)
   Recheck Cond: (((y = '100'::double precision) AND (x = 1)) OR ((y =
'100'::double precision) AND (x = 2)))
   ->  BitmapOr  (cost=8.60..8.60 rows=1 width=0)
         ->  Bitmap Index Scan on test_x_1_y  (cost=0.00..4.30 rows=1
width=0)
               Index Cond: (y = '100'::double precision)
         ->  Bitmap Index Scan on test_x_2_y  (cost=0.00..4.30 rows=1
width=0)
               Index Cond: (y = '100'::double precision)
(7 rows)

2. The second patch is my patch version when I moved the OR
transformation in the s index formation stage:

So, I got the best query plan despite the possible OR to ANY transformation:

postgres=# create table test as (select (random()*10)::int x,
(random()*1000) y
from generate_series(1,1000000) i);
create index test_x_1_y on test (y) where x = 1;
create index test_x_2_y on test (y) where x = 2;
vacuum analyze test;
SELECT 1000000
CREATE INDEX
CREATE INDEX
VACUUM
postgres=# explain select * from test where (x = 1 or x = 2) and y = 100;
WARNING:  cost with original approach: - 12.618000
WARNING:  cost with OR to ANY applied transfomation: - 15440.000000
                                                  QUERY PLAN
--------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on test  (cost=8.60..12.62 rows=1 width=12)
   Recheck Cond: (((y = '100'::double precision) AND (x = 1)) OR ((y =
'100'::double precision) AND (x = 2)))
   ->  BitmapOr  (cost=8.60..8.60 rows=1 width=0)
         ->  Bitmap Index Scan on test_x_1_y  (cost=0.00..4.30 rows=1
width=0)
               Index Cond: (y = '100'::double precision)
         ->  Bitmap Index Scan on test_x_2_y  (cost=0.00..4.30 rows=1
width=0)
               Index Cond: (y = '100'::double precision)
(7 rows)

--
Regards,
Alena Rybakina
Postgres Professional

#113Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#112)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Sorry, I forgot to apply my patches. For the first experiment was
0001-OR-to-ANY-in-parser-and-ANY-to-OR-in-index.diff and for the second
experiment was 0002-OR-to-ANY-in-index.diff.

On 30.11.2023 11:00, Alena Rybakina wrote:

Hi!

Honestly, it seems very hard to avoid the conclusion that this
transformation is being done at too early a stage. Parse analysis is
not the time to try to do query optimization. I can't really believe
that there's a way to produce a committable patch along these lines.
Ideally, a transformation like this should be done after we know what
plan shape we're using (or considering using), so that we can make
cost-based decisions about whether to transform or not. But at the
very least it should happen somewhere in the planner. There's really
no justification for parse analysis rewriting the SQL that the user
entered.

Here, we assume that array operation is generally better than many ORs.
As a result, it should be more effective to make OR->ANY
transformation in the parser (it is a relatively lightweight
operation here) and, as a second phase, decompose that in the optimizer.
We implemented earlier prototypes in different places of the
optimizer, and I'm convinced that only this approach resolves the
issues we found.
Does this approach look weird? Maybe. We can debate it in this thread.

I think this is incorrect, and the example of A. Korotkov confirms
this. If we perform the conversion at the parsing stage, we will skip
the more important conversion using OR expressions. I'll show you in
the example below.

First of all, I will describe my idea to combine two approaches to
obtaining plans with OR to ANY transformation and ANY to OR
transformation. I think they are both good, and we can't work with
just one of them, we should consider both the option of OR
expressions, and with ANY.

I did this by creating a RelOptInfo with which has references from the
original RelOptInfo, for which conversion is possible either from
ANY->OR, or vice versa. After obtaining the necessary transformation,
I started the procedure for obtaining the seq and index paths for both
relations and then calculated their cost. The relation with the lowest
cost is considered the best.

I'm not sure if this is the best approach, but it's less complicated.

I noticed that I got a lower cost for not the best plan, but I think
this corresponds to another topic related to the wrong estimate
calculation.

1. The first patch is a mixture of the original patch (when we perform
the conversion of OR to ANY at the parsing stage), and when we perform
the conversion at the index creation stage with the conversion to an
OR expression. We can see that the query proposed by A.Korotkov did
not have the best plan with ANY expression at all, and even despite
receiving a query with OR expressions, we cannot get anything better
than SeqScan, due to the lack of effective logical transformations
that would have been performed if we had left the OR expressions.

So, I got query plans using enable_or_transformation if it is enabled:

postgres=# create table test as (select (random()*10)::int x,
(random()*1000) y
from generate_series(1,1000000) i);
create index test_x_1_y on test (y) where x = 1;
create index test_x_2_y on test (y) where x = 2;
vacuum analyze test;
SELECT 1000000
CREATE INDEX
CREATE INDEX
VACUUM
postgres=# explain select * from test where (x = 1 or x = 2) and y = 100;
WARNING:  cost with original approach: - 20440.000000
WARNING:  cost with OR to ANY applied transfomation: - 15440.000000
                                QUERY PLAN
--------------------------------------------------------------------------

 Gather  (cost=1000.00..12690.10 rows=1 width=12)
   Workers Planned: 2
   ->  Parallel Seq Scan on test  (cost=0.00..11690.00 rows=1 width=12)
         Filter: (((x = 1) OR (x = 2)) AND (y = '100'::double precision))
(4 rows)

and if it is off:

postgres=# set enable_or_transformation =off;
SET
postgres=# explain select * from test where (x = 1 or x = 2) and y = 100;
                                                  QUERY PLAN
--------------------------------------------------------------------------------------------------------------

 Bitmap Heap Scan on test  (cost=8.60..12.62 rows=1 width=12)
   Recheck Cond: (((y = '100'::double precision) AND (x = 1)) OR ((y =
'100'::double precision) AND (x = 2)))
   ->  BitmapOr  (cost=8.60..8.60 rows=1 width=0)
         ->  Bitmap Index Scan on test_x_1_y  (cost=0.00..4.30 rows=1
width=0)
               Index Cond: (y = '100'::double precision)
         ->  Bitmap Index Scan on test_x_2_y  (cost=0.00..4.30 rows=1
width=0)
               Index Cond: (y = '100'::double precision)
(7 rows)

2. The second patch is my patch version when I moved the OR
transformation in the s index formation stage:

So, I got the best query plan despite the possible OR to ANY
transformation:

postgres=# create table test as (select (random()*10)::int x,
(random()*1000) y
from generate_series(1,1000000) i);
create index test_x_1_y on test (y) where x = 1;
create index test_x_2_y on test (y) where x = 2;
vacuum analyze test;
SELECT 1000000
CREATE INDEX
CREATE INDEX
VACUUM
postgres=# explain select * from test where (x = 1 or x = 2) and y = 100;
WARNING:  cost with original approach: - 12.618000
WARNING:  cost with OR to ANY applied transfomation: - 15440.000000
                                                  QUERY PLAN
--------------------------------------------------------------------------------------------------------------

 Bitmap Heap Scan on test  (cost=8.60..12.62 rows=1 width=12)
   Recheck Cond: (((y = '100'::double precision) AND (x = 1)) OR ((y =
'100'::double precision) AND (x = 2)))
   ->  BitmapOr  (cost=8.60..8.60 rows=1 width=0)
         ->  Bitmap Index Scan on test_x_1_y  (cost=0.00..4.30 rows=1
width=0)
               Index Cond: (y = '100'::double precision)
         ->  Bitmap Index Scan on test_x_2_y  (cost=0.00..4.30 rows=1
width=0)
               Index Cond: (y = '100'::double precision)
(7 rows)

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

0001-OR-to-ANY-in-parser-and-ANY-to-OR-in-index.difftext/x-patch; charset=UTF-8; name=0001-OR-to-ANY-in-parser-and-ANY-to-OR-in-index.diffDownload
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 0a5bdf8bcc0..9368ae1d052 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8537,18 +8537,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 281907a4d83..99207a8670f 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -135,6 +135,36 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	if (*queryId == UINT64CONST(0))
+		*queryId = UINT64CONST(1);
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index 67921a08262..2e97ff96036 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -50,6 +50,8 @@
 #include "port/pg_bitutils.h"
 #include "rewrite/rewriteManip.h"
 #include "utils/lsyscache.h"
+#include "parser/parse_expr.h"
+#include "utils/array.h"
 
 
 /* Bitmask flags for pushdown_safety_info.unsafeFlags */
@@ -759,6 +761,179 @@ set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel,
 	rel->consider_parallel = true;
 }
 
+static List*
+research_or_list(Expr *qual, List *or_list, RestrictInfo *sub_rinfo)
+{
+	List *elem_exprs = NIL;
+
+	/* Check: it is an expr of the form 'F(x) oper ConstExpr' */
+	if (!IsA(qual, ScalarArrayOpExpr))
+	{
+		/* Again, it's not the expr we can transform */
+		or_list = lappend(or_list, qual);
+	}
+	else
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) qual;
+		Expr	   *rightop = (Expr *) lsecond(saop->args);
+		ListCell   *lc1;
+
+		if (sub_rinfo && !op_mergejoinable(((OpExpr *) sub_rinfo->clause)->opno, exprType(get_leftop(sub_rinfo->clause))))
+			{
+				/* And again, filter out non-equality operators */
+				or_list = lappend(or_list, (void *) qual);
+			}
+		else if (rightop && IsA(rightop, Const))
+		{
+			ArrayType  *arrval;
+			int16		elemlen;
+			bool		elembyval;
+			char		elemalign;
+			Datum	   *elem_values;
+			bool	   *elem_nulls;
+			int			num_elems,
+						i;
+			Const	   *arr = (Const *) rightop;
+
+			arrval = DatumGetArrayTypeP(arr->constvalue);
+			get_typlenbyvalalign(ARR_ELEMTYPE(arrval),
+								&elemlen, &elembyval, &elemalign);
+			deconstruct_array(arrval,
+							ARR_ELEMTYPE(arrval),
+							elemlen, elembyval, elemalign,
+							&elem_values, &elem_nulls,
+							&num_elems);
+
+			for (i = 0; i < num_elems; i++)
+			{
+				Const	   *elem_expr;
+
+				/*
+				* A null array element must lead to a null comparison result,
+				* since saop_op is known strict.  We can ignore it in the
+				* useOr case, but otherwise it implies self-contradiction.
+				*/
+				if (elem_nulls[i])
+				{
+					or_list = lappend(or_list, (void *) qual);
+					elem_exprs = NIL;
+					break;
+				}
+
+				elem_expr = makeConst(ARR_ELEMTYPE(arrval), -1,
+									arr->constcollid, elemlen,
+									elem_values[i], false, elembyval);
+				elem_exprs = lappend(elem_exprs, elem_expr);
+			}
+		}
+		else if (rightop && IsA(rightop, ArrayExpr) && !((ArrayExpr *) rightop)->multidims)
+		{
+			ArrayExpr  *arrexpr = (ArrayExpr  *)get_rightop(rightop);
+			elem_exprs = arrexpr->elements;
+		}
+		else
+			or_list = lappend(or_list, qual);
+
+		if (elem_exprs)
+		foreach(lc1, elem_exprs)
+		{
+			Expr	   *elem_clause;
+
+			elem_clause = make_opclause(((ScalarArrayOpExpr*) qual)->opno, BOOLOID, false,
+										(Expr *) linitial(((ScalarArrayOpExpr*)qual)->args), lfirst(lc1),
+										InvalidOid, ((ScalarArrayOpExpr*)qual)->inputcollid);
+			or_list = lappend(or_list, (void*) elem_clause);
+		}
+	}
+	return or_list;
+}
+
+static List *
+get_baserestrictinfo(PlannerInfo *root, List *baserestrictinfo)
+{
+	ListCell   *lc;
+	List	   *modified_rinfo = NIL;
+	bool		or_transformation = false;
+
+	if (!enable_or_transformation)
+		return NULL;
+
+	foreach(lc, baserestrictinfo)
+	{
+		RestrictInfo   *rinfo_base = lfirst_node(RestrictInfo, lc);
+		RestrictInfo   *rinfo;
+		List		   *or_list = NIL;
+
+		ListCell	   *lc_eargs,
+					   *lc_rargs;
+
+		if (!IsA(rinfo_base->clause, BoolExpr) && !IsA(rinfo_base->clause, ScalarArrayOpExpr))
+		{
+			/* Add a clause without changes */
+			modified_rinfo = lappend(modified_rinfo, rinfo_base);
+			continue;
+		}
+
+		if (IsA(rinfo_base->clause, BoolExpr) && is_orclause(rinfo_base->clause))
+		forboth(lc_eargs, ((BoolExpr *) rinfo_base->clause)->args,
+				lc_rargs, ((BoolExpr *) rinfo_base->orclause)->args)
+		{
+			Expr			   *orqual = (Expr *) lfirst(lc_eargs);
+			RestrictInfo 	   *sub_rinfo = lfirst_node(RestrictInfo, lc_rargs);
+
+			if (!IsA(orqual, OpExpr) ||
+				!(bms_is_empty(sub_rinfo->left_relids) ^
+				bms_is_empty(sub_rinfo->right_relids)) ||
+				contain_volatile_functions((Node *) orqual))
+			{
+				/* Again, it's not the expr we can transform */
+				or_list = lappend(or_list, (void *) orqual);
+				continue;
+			}
+
+			or_list = research_or_list(orqual, or_list, sub_rinfo);
+		}
+		else if (IsA(rinfo_base->clause, ScalarArrayOpExpr))
+		{
+			Expr			   *orqual = rinfo_base->clause;
+
+			or_list = research_or_list(orqual, or_list, NULL);
+		}
+		else
+		{
+			or_list = lappend(or_list, (void*)rinfo_base->clause);
+		}
+
+
+		rinfo = make_restrictinfo(root,
+				  list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, or_list, -1):
+																				(Expr *) linitial(or_list),
+				  rinfo_base->is_pushed_down,
+				  rinfo_base->has_clone,
+				  rinfo_base->is_clone,
+				  rinfo_base->pseudoconstant,
+				  rinfo_base->security_level,
+				  rinfo_base->required_relids,
+				  rinfo_base->incompatible_relids,
+				  rinfo_base->outer_relids);
+		rinfo->eval_cost=rinfo_base->eval_cost;
+		rinfo->norm_selec=rinfo_base->norm_selec;
+		rinfo->outer_selec=rinfo_base->outer_selec;
+		rinfo->left_bucketsize=rinfo_base->left_bucketsize;
+		rinfo->right_bucketsize=rinfo_base->right_bucketsize;
+		rinfo->left_mcvfreq=rinfo_base->left_mcvfreq;
+		rinfo->right_mcvfreq=rinfo_base->right_mcvfreq;
+		modified_rinfo = lappend(modified_rinfo, rinfo);
+		or_transformation = true;
+	}
+
+	if(or_transformation)
+	return modified_rinfo;
+
+	return baserestrictinfo;
+}
+
+
 /*
  * set_plain_rel_pathlist
  *	  Build access paths for a plain relation (no subquery, no inheritance)
@@ -767,6 +942,12 @@ static void
 set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 {
 	Relids		required_outer;
+	RelOptInfo *reL_alternative = makeNode(RelOptInfo);
+	//reL_alternative = copyObject(rel);
+	reL_alternative = copy_simple_rel(root, rel->relid, rel, reL_alternative);
+	reL_alternative->indexlist = NIL;
+	reL_alternative->baserestrictinfo = rel->baserestrictinfo;
+	reL_alternative->eclass_indexes = NULL;
 
 	/*
 	 * We don't support pushing join clauses into the quals of a seqscan, but
@@ -787,6 +968,39 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
 	/* Consider TID scans */
 	create_tidscan_paths(root, rel);
+
+	set_cheapest(rel);
+
+	if (rel->reloptkind == RELOPT_BASEREL && enable_or_transformation)
+	{
+		bool applied_transfomation=true;
+		//applied_transfomation =  (bool *) palloc(sizeof(bool));
+		reL_alternative->baserestrictinfo = get_baserestrictinfo(root, rel->baserestrictinfo);
+if (applied_transfomation)
+{
+	add_path(reL_alternative, create_seqscan_path(root, reL_alternative, required_outer, 0));
+
+	if (reL_alternative->consider_parallel && required_outer == NULL)
+		create_plain_partial_paths(root, reL_alternative);
+
+	create_index_paths(root, reL_alternative);
+
+	create_tidscan_paths(root, reL_alternative);
+
+	set_cheapest(reL_alternative);
+
+	elog(WARNING, "ors: - %f", rel->cheapest_total_path->total_cost);
+	elog(WARNING, "applied_transfomation: - %f", reL_alternative->cheapest_total_path->total_cost);
+
+	if (reL_alternative->cheapest_total_path->total_cost <= rel->cheapest_total_path->total_cost)
+	{
+		//copy_simple_rel(root, rel->relid, reL_alternative, rel);
+		rel->indexlist = reL_alternative->indexlist;
+		rel->baserestrictinfo = reL_alternative->baserestrictinfo;
+		rel->eclass_indexes = reL_alternative->eclass_indexes;
+	}
+	}
+	}
 }
 
 /*
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c
index 5d83f60eb9a..189cee449bf 100644
--- a/src/backend/optimizer/util/relnode.c
+++ b/src/backend/optimizer/util/relnode.c
@@ -183,6 +183,97 @@ expand_planner_arrays(PlannerInfo *root, int add_size)
 	root->simple_rel_array_size = new_size;
 }
 
+RelOptInfo *
+copy_simple_rel(PlannerInfo *root, int relid, RelOptInfo *base_rel, RelOptInfo *rel)
+{
+	rel->reloptkind = base_rel->parent ? RELOPT_OTHER_MEMBER_REL : RELOPT_BASEREL;
+	rel->relids = base_rel->relids;
+	rel->rows = base_rel->rows;
+	/* cheap startup cost is interesting iff not all tuples to be retrieved */
+	rel->consider_startup = (root->tuple_fraction > 0);
+	rel->consider_param_startup = base_rel->consider_param_startup;	/* might get changed later */
+	rel->consider_parallel = base_rel->consider_parallel; /* might get changed later */
+	rel->reltarget = base_rel->reltarget;
+	rel->pathlist = base_rel->pathlist;
+	rel->ppilist = base_rel->ppilist;
+	rel->partial_pathlist = base_rel->partial_pathlist;
+	rel->cheapest_startup_path = base_rel->cheapest_startup_path;
+	rel->cheapest_total_path = base_rel->cheapest_total_path;
+	rel->cheapest_unique_path = base_rel->cheapest_unique_path;
+	rel->cheapest_parameterized_paths = base_rel->cheapest_parameterized_paths;
+	rel->relid = base_rel->relid;
+	/* min_attr, max_attr, attr_needed, attr_widths are set below */
+	rel->lateral_vars = base_rel->lateral_vars;
+	rel->statlist = base_rel->statlist;
+	rel->pages = base_rel->pages;
+	rel->tuples = base_rel->tuples;
+	rel->allvisfrac = base_rel->allvisfrac;
+	rel->subroot = base_rel->subroot;
+	rel->subplan_params = base_rel->subplan_params;
+	rel->rel_parallel_workers = base_rel->rel_parallel_workers; /* set up in get_relation_info */
+	rel->amflags = base_rel->amflags;
+	rel->parent = base_rel->parent;
+	rel->serverid = base_rel->serverid;
+	rel->userid = base_rel->userid;
+	rel->useridiscurrent = base_rel->useridiscurrent;
+	rel->fdwroutine = base_rel->fdwroutine;
+	rel->fdw_private = base_rel->fdw_private;
+	rel->unique_for_rels = base_rel->unique_for_rels;
+	rel->non_unique_for_rels = base_rel->non_unique_for_rels;
+	rel->baserestrictcost.startup = 0;
+	rel->baserestrictcost.per_tuple = 0;
+	rel->baserestrict_min_security = UINT_MAX;
+	rel->joininfo = base_rel->joininfo;
+	rel->has_eclass_joins = base_rel->has_eclass_joins;
+
+	/*
+	 * Pass assorted information down the inheritance hierarchy.
+	 */
+	if (base_rel->parent)
+	{
+		/* We keep back-links to immediate parent and topmost parent. */
+		rel->parent = base_rel->parent;
+		rel->top_parent = base_rel->parent->top_parent ? base_rel->parent->top_parent : base_rel->parent;
+		rel->top_parent_relids = base_rel->top_parent->relids;
+
+		/*
+		 * A child rel is below the same outer joins as its parent.  (We
+		 * presume this info was already calculated for the parent.)
+		 */
+		rel->nulling_relids = base_rel->parent->nulling_relids;
+
+		/*
+		 * Also propagate lateral-reference information from appendrel parent
+		 * rels to their child rels.  We intentionally give each child rel the
+		 * same minimum parameterization, even though it's quite possible that
+		 * some don't reference all the lateral rels.  This is because any
+		 * append path for the parent will have to have the same
+		 * parameterization for every child anyway, and there's no value in
+		 * forcing extra reparameterize_path() calls.  Similarly, a lateral
+		 * reference to the parent prevents use of otherwise-movable join rels
+		 * for each child.
+		 *
+		 * It's possible for child rels to have their own children, in which
+		 * case the topmost parent's lateral info propagates all the way down.
+		 */
+		rel->direct_lateral_relids = base_rel->parent->direct_lateral_relids;
+		rel->lateral_relids = base_rel->parent->lateral_relids;
+		rel->lateral_referencers = base_rel->parent->lateral_referencers;
+	}
+	else
+	{
+		rel->parent = base_rel->parent;
+		rel->top_parent = base_rel->top_parent;
+		rel->top_parent_relids = base_rel->top_parent_relids;
+		rel->nulling_relids = base_rel->nulling_relids;
+		rel->direct_lateral_relids = base_rel->direct_lateral_relids;
+		rel->lateral_relids = base_rel->lateral_relids;
+		rel->lateral_referencers = base_rel->lateral_referencers;
+	}
+
+	return rel;
+}
+
 /*
  * build_simple_rel
  *	  Construct a new RelOptInfo for a base relation or 'other' relation.
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344c..d8c6096144c 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,14 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -38,11 +40,13 @@
 #include "utils/date.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +103,289 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function that's compatible with guc_name_compare
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				hash;
+
+	(void) JumbleExpr(key->expr, &hash);
+	hash += ((uint64) key->opno + (uint64) key->exprtype) % UINT64_MAX;
+	return hash;
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in guc_hashtab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
+{
+	List				   *or_list = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(expr->args);
+	HASH_SEQ_STATUS			hash_seq;
+	OrClauseGroupEntry	   *entry = NULL;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (!enable_or_transformation || expr->boolop != OR_EXPR || len_ors < 2)
+		return transformBoolExpr(pstate, (BoolExpr *) expr);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, expr->args)
+	{
+		Node				   *arg = lfirst(lc);
+		Node				   *orqual;
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		if (IsA(get_leftop(orqual), Const))
+		{
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(get_rightop(orqual), Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		if (!op_mergejoinable(((OpExpr *) orqual)->opno, exprType(nconst_expr)))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		* TODO: to manage complexity in the case of many different clauses
+		* (X1=C1) OR (X2=C2 OR) ... (XN = CN) we could invent something
+		* like a hash table. But also we believe, that the case of many
+		* different variable sides is very rare.
+		*/
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = ((OpExpr *) orqual)->opno;
+		hashkey.exprtype = exprType(nconst_expr);
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->node = nconst_expr;
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+		}
+	}
+
+	if (list_length(or_list) == len_ors)
+	{
+		/*
+		* No any transformations possible with this list of arguments. Here we
+		* already made all underlying transformations. Thus, just return the
+		* transformed bool expression.
+		*/
+		hash_destroy(or_group_htab);
+		return (Node *) makeBoolExpr(OR_EXPR, or_list, expr->location);
+	}
+
+	hash_seq_init(&hash_seq, or_group_htab);
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	* consts more than 1. trivial groups move to OR-list again
+	*/
+
+	while ((entry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
+	{
+		List			   *allexprs;
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element in the class. Return rinfo into the BoolExpr
+			 * args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+		allexprs = list_concat(list_make1(entry->node), entry->consts);
+		scalar_type = entry->key.exprtype;
+
+		if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+			array_type = get_array_type(scalar_type);
+		else
+			array_type = InvalidOid;
+
+		if (array_type != InvalidOid)
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			ListCell		   *l;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+
+			aexprs = entry->consts;
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 entry->node,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * This part works on intarray test (OR there is made on
+			 * elements of a custom type)
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+		hash_search(or_group_htab, &entry->key, HASH_REMOVE, NULL);
+	}
+	hash_destroy(or_group_htab);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, expr->location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +499,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 6474e35ec04..c054b3e1658 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,16 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index cf9f283cfee..3d5b5fbc580 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -374,6 +374,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index 0769081c7ab..4aaa31aa80e 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h
index 6e557bebc44..f50a0df5dd2 100644
--- a/src/include/optimizer/pathnode.h
+++ b/src/include/optimizer/pathnode.h
@@ -306,6 +306,8 @@ extern void setup_simple_rel_arrays(PlannerInfo *root);
 extern void expand_planner_arrays(PlannerInfo *root, int add_size);
 extern RelOptInfo *build_simple_rel(PlannerInfo *root, int relid,
 									RelOptInfo *parent);
+extern RelOptInfo *
+copy_simple_rel(PlannerInfo *root, int relid, RelOptInfo *base_rel, RelOptInfo *rel);
 extern RelOptInfo *find_base_rel(PlannerInfo *root, int relid);
 extern RelOptInfo *find_base_rel_ignore_join(PlannerInfo *root, int relid);
 extern RelOptInfo *find_join_rel(PlannerInfo *root, Relids relids);
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7b..3a87de02859 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..3bb4bbca481 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,101 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((tenthous < 2) OR (thousand = ANY ('{42,99}'::integer[])))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..0f2b1b16200 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ enable_or_transformation
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 0f1aa831f64..17812501227 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -2560,7 +2560,7 @@ explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd'
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 2c73270143b..e952e5401f5 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_join.out b/src/test/regress/expected/partition_join.out
index 6560fe2416f..6e8d64655b2 100644
--- a/src/test/regress/expected/partition_join.out
+++ b/src/test/regress/expected/partition_join.out
@@ -296,7 +296,7 @@ SELECT t1.a, t1.c, t2.b, t2.c FROM (SELECT * FROM prt1 WHERE a < 450) t1 FULL JO
    Sort Key: prt1.a, prt2.b
    ->  Hash Full Join
          Hash Cond: (prt1.a = prt2.b)
-         Filter: ((prt1.b = 0) OR (prt2.a = 0))
+         Filter: ((prt2.a = 0) OR (prt1.b = 0))
          ->  Append
                ->  Seq Scan on prt1_p1 prt1_1
                      Filter: (a < 450)
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c0556..14a254fba7b 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +618,13 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -1933,10 +2112,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 05070393b99..c927c21dd4d 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2495,7 +2495,7 @@ pg_stats| SELECT n.nspname AS schemaname,
      JOIN pg_class c ON ((c.oid = s.starelid)))
      JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
-  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2526,7 +2526,7 @@ pg_stats_ext| SELECT cn.nspname AS schemaname,
   WHERE ((NOT (EXISTS ( SELECT 1
            FROM (unnest(s.stxkeys) k(k)
              JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
-          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext_exprs| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e3..7a829c44c7b 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -868,13 +868,13 @@ select unique1, unique2 from onek2
                                    QUERY PLAN                                   
 --------------------------------------------------------------------------------
  Bitmap Heap Scan on onek2
-   Recheck Cond: (((unique2 = 11) AND (stringu1 < 'B'::name)) OR (unique1 = 0))
+   Recheck Cond: ((unique1 = 0) OR ((unique2 = 11) AND (stringu1 < 'B'::name)))
    Filter: (stringu1 < 'B'::name)
    ->  BitmapOr
-         ->  Bitmap Index Scan on onek2_u2_prtl
-               Index Cond: (unique2 = 11)
          ->  Bitmap Index Scan on onek2_u1_prtl
                Index Cond: (unique1 = 0)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 = 11)
 (8 rows)
 
 select unique1, unique2 from onek2
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index a430153b225..659d712f75e 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 271313ebf86..c6c6b9fb8d9 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -123,6 +123,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -133,7 +134,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(22 rows)
+(23 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..2a079e996b2 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..48bb1bc0a0a 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 8a8a63bd2f1..55d7e2ae7d6 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827f..1e270ae9c06 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..0499bedb9eb 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index d659adbfd6c..9591d0d084d 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1645,6 +1645,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

0002-OR-to-ANY-in-index.difftext/x-patch; charset=UTF-8; name=0002-OR-to-ANY-in-index.diffDownload
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index 67921a08262..e0d83672756 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -50,6 +50,12 @@
 #include "port/pg_bitutils.h"
 #include "rewrite/rewriteManip.h"
 #include "utils/lsyscache.h"
+#include "parser/parse_coerce.h"
+#include "common/hashfn.h"
+#include "catalog/pg_operator.h"
+#include "nodes/queryjumble.h"
+#include "utils/syscache.h"
+#include "catalog/namespace.h"
 
 
 /* Bitmask flags for pushdown_safety_info.unsafeFlags */
@@ -165,6 +171,390 @@ static void remove_unused_subquery_outputs(Query *subquery, RelOptInfo *rel,
 										   Bitmapset *extra_used_attrs);
 
 
+bool		enable_or_transformation = true;
+typedef struct OrClauseGroupKey
+{
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+	Node		   *node;
+	List		   *consts;
+	Oid				collation;
+	RestrictInfo   *rinfo;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function that's compatible with guc_name_compare
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				hash;
+
+	(void) JumbleExpr(key->expr, &hash);
+	hash = ((uint64) key->opno + (uint64) key->exprtype) % UINT64_MAX;
+	return hash;
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in guc_hashtab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+/*
+ * Pass through baserestrictinfo clauses and try to convert OR clauses into IN
+ * Return a modified clause list or just the same baserestrictinfo, if no
+ * changes have made.
+ * XXX: do not change source list of clauses at all.
+ */
+static List *
+transform_ors(PlannerInfo *root, List *baserestrictinfo, bool *something_changed)
+{
+	ListCell   *lc;
+	List	   *modified_rinfo = NIL;
+
+	/*
+	 * Complexity of a clause could be arbitrarily sophisticated. Here, we will
+	 * look up only on the top level of clause list.
+	 * XXX: It is substantiated? Could we change something here?
+	 */
+	foreach (lc, baserestrictinfo)
+	{
+		RestrictInfo   *rinfo = lfirst_node(RestrictInfo, lc);
+		RestrictInfo   *rinfo_base = copyObject(rinfo);
+		List		   *or_list = NIL;
+		ListCell	   *lc_eargs,
+					   *lc_rargs;
+		bool			change_apply = false;
+		HASHCTL			info;
+		HTAB 		   *or_group_htab = NULL;
+		int 			len_ors;
+		HASH_SEQ_STATUS		hash_seq;
+		OrClauseGroupEntry *gentry;
+
+		if (!enable_or_transformation || !restriction_is_or_clause(rinfo))
+		{
+			/* Add a clause without changes */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		len_ors = ((BoolExpr *) rinfo->clause)->args? list_length(((BoolExpr *) rinfo->clause)->args) : 0;
+
+		if (len_ors < 2)
+		{
+			/* Add a clause without changes */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		MemSet(&info, 0, sizeof(info));
+		info.keysize = sizeof(OrClauseGroupKey);
+		info.entrysize = sizeof(OrClauseGroupEntry);
+		info.hash = orclause_hash;
+		info.keycopy = orclause_keycopy;
+		info.match = orclause_match;
+		or_group_htab = hash_create("OR Groups",
+									len_ors,
+									&info,
+									HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+		/*
+		 * NOTE:
+		 * It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		 * a list of sub-restrictinfo args, and rinfo->clause - which is the
+		 * same expression, made from bare clauses. To not break selectivity
+		 * caches and other optimizations, use both:
+		 * - use rinfos from orclause if no transformation needed
+		 * - use  bare quals from rinfo->clause in the case of transformation,
+		 * to create new RestrictInfo: in this case we have no options to avoid
+		 * selectivity estimation procedure.
+		 */
+		forboth(lc_eargs, ((BoolExpr *) rinfo->clause)->args,
+				lc_rargs, ((BoolExpr *) rinfo->orclause)->args)
+		{
+			Expr			   *or_qual = (Expr *) lfirst(lc_eargs);
+			RestrictInfo	   *sub_rinfo;
+			Node			   *const_expr;
+			Node			   *nconst_expr;
+			OrClauseGroupKey		hashkey;
+			bool found = false;
+
+			/* It may be one more boolean expression, skip it for now */
+			if (!IsA(lfirst(lc_rargs), RestrictInfo))
+			{
+				or_list = lappend(or_list, (void *) or_qual);
+				continue;
+			}
+
+			sub_rinfo = lfirst_node(RestrictInfo, lc_rargs);
+
+			/* Check: it is an expr of the form 'F(x) oper ConstExpr' */
+			if (!IsA(or_qual, OpExpr) ||
+				!(bms_is_empty(sub_rinfo->left_relids) ^
+				bms_is_empty(sub_rinfo->right_relids)) ||
+				contain_volatile_functions((Node *) or_qual))
+			{
+				/* Again, it's not the expr we can transform */
+				or_list = lappend(or_list, (void *) or_qual);
+				continue;
+			}
+
+			/* Get pointers to constant and expression sides of the clause */
+			const_expr =bms_is_empty(sub_rinfo->left_relids) ?
+												get_leftop(sub_rinfo->clause) :
+												get_rightop(sub_rinfo->clause);
+			nconst_expr = bms_is_empty(sub_rinfo->left_relids) ?
+												get_rightop(sub_rinfo->clause) :
+												get_leftop(sub_rinfo->clause);
+
+			if (!op_mergejoinable(((OpExpr *) sub_rinfo->clause)->opno, exprType(nconst_expr)))
+			{
+				/* And again, filter out non-equality operators */
+				or_list = lappend(or_list, (void *) or_qual);
+				continue;
+			}
+
+			/*
+			 * At this point we definitely have a transformable clause.
+			 * Classify it and add into specific group of clauses, or create new
+			 * group.
+			 */
+			hashkey.expr = (Expr *) nconst_expr;
+			hashkey.opno = ((OpExpr *) or_qual)->opno;
+			hashkey.exprtype = exprType(nconst_expr);
+			gentry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+			if (unlikely(found))
+			{
+				gentry->consts = lappend(gentry->consts, const_expr);
+				gentry->exprs = lappend(gentry->exprs, or_qual);
+			}
+			else
+			{
+				gentry->node = nconst_expr;
+				gentry->consts = list_make1(const_expr);
+				gentry->exprs = list_make1(or_qual);
+				gentry->rinfo = sub_rinfo;
+				gentry->collation = exprInputCollation((Node *)sub_rinfo->clause);
+			}
+		}
+
+		if (list_length(or_list) == len_ors)
+		{
+			/*
+			* No any transformations possible with this list of arguments. Here we
+			* already made all underlying transformations. Thus, just return the
+			* transformed bool expression.
+			*/
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		if (!or_group_htab && hash_get_num_entries(or_group_htab) < 1)
+		{
+			/*
+			 * No any transformations possible with this rinfo, just add itself
+			 * to the list and go further.
+			 */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		hash_seq_init(&hash_seq, or_group_htab);
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		while ((gentry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
+		{
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+			Assert(list_length(gentry->exprs) == list_length(gentry->consts));
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				* Only one element in the class. Return rinfo into the BoolExpr
+				* args list unchanged.
+				*/
+				list_free(gentry->consts);
+				or_list = list_concat(or_list, gentry->exprs);
+				continue;
+			}
+
+			/*
+			* Do the transformation.
+			*
+			* First of all, try to select a common type for the array elements.
+			* Note that since the LHS' type is first in the list, it will be
+			* preferred when there is doubt (eg, when all the RHS items are
+			* unknown literals).
+			*
+			* Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			*
+			* As a source of insides, use make_scalar_array_op()
+			*/
+			scalar_type = gentry->key.exprtype;
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid && scalar_type != InvalidOid)
+			{
+				/*
+				* OK: coerce all the right-hand non-Var inputs to the common
+				* type and build an ArrayExpr for them.
+				*/
+				List	   *aexprs = NULL;
+				ArrayExpr  *newa = NULL;
+				ScalarArrayOpExpr *saopexpr = NULL;
+				HeapTuple			opertup;
+				Form_pg_operator	operform;
+				List			   *namelist = NIL;
+
+				aexprs = gentry->consts;
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(gentry->key.opno));
+
+				if (!HeapTupleIsValid(opertup))
+					elog(ERROR, "cache lookup failed for operator %u",
+						gentry->key.opno);
+
+				operform = (Form_pg_operator) GETSTRUCT(opertup);
+				if (!OperatorIsVisible(gentry->key.opno))
+					namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+				namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+				ReleaseSysCache(opertup);
+
+				saopexpr = makeNode(ScalarArrayOpExpr);
+				saopexpr->opno = ((OpExpr *) gentry->rinfo->clause)->opno;
+				saopexpr->useOr = true;
+				saopexpr->inputcollid = gentry->collation;
+				saopexpr->args = list_make2(gentry->node, newa);
+				saopexpr->location = -1;
+
+
+				or_list = lappend(or_list, (void *) saopexpr);
+
+				*something_changed = true;
+				change_apply = true;
+
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, (void *) gentry->rinfo->clause);
+			}
+			hash_search(or_group_htab, &gentry->key, HASH_REMOVE, NULL);
+		}
+
+		hash_destroy(or_group_htab);
+
+		if (!change_apply)
+		{
+			/*
+			 * Each group contains only one element - use rinfo as is.
+			 */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			list_free(or_list);
+			continue;
+		}
+
+		/*
+		 * Make a new version of the restriction. Remember source restriction
+		 * can be used in another path (SeqScan, for example).
+		 */
+
+		/* One more trick: assemble correct clause */
+		rinfo = make_restrictinfo(root,
+				  list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, or_list, ((BoolExpr *) rinfo->clause)->location) :
+											 linitial(or_list),
+				  rinfo->is_pushed_down,
+				  rinfo->has_clone,
+				  rinfo->is_clone,
+				  rinfo->pseudoconstant,
+				  rinfo->security_level,
+				  rinfo->required_relids,
+				  rinfo->incompatible_relids,
+				  rinfo->outer_relids);
+		rinfo->eval_cost=rinfo_base->eval_cost;
+		rinfo->norm_selec=rinfo_base->norm_selec;
+		rinfo->outer_selec=rinfo_base->outer_selec;
+		rinfo->left_bucketsize=rinfo_base->left_bucketsize;
+		rinfo->right_bucketsize=rinfo_base->right_bucketsize;
+		rinfo->left_mcvfreq=rinfo_base->left_mcvfreq;
+		rinfo->right_mcvfreq=rinfo_base->right_mcvfreq;
+		modified_rinfo = lappend(modified_rinfo, rinfo);
+		*something_changed = true;
+	}
+
+	/*
+	 * Check if transformation has made. If nothing changed - return
+	 * baserestrictinfo as is.
+	 */
+	if (*something_changed)
+	{
+		return modified_rinfo;
+	}
+
+	list_free(modified_rinfo);
+	return baserestrictinfo;
+}
+
 /*
  * make_one_rel
  *	  Finds all possible access paths for executing a query, returning a
@@ -767,6 +1157,12 @@ static void
 set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 {
 	Relids		required_outer;
+	RelOptInfo *reL_alternative = makeNode(RelOptInfo);
+	//reL_alternative = copyObject(rel);
+	reL_alternative = copy_simple_rel(root, rel->relid, rel, reL_alternative);
+	reL_alternative->indexlist = NIL;
+	reL_alternative->baserestrictinfo = rel->baserestrictinfo;
+	reL_alternative->eclass_indexes = NULL;
 
 	/*
 	 * We don't support pushing join clauses into the quals of a seqscan, but
@@ -787,6 +1183,39 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
 	/* Consider TID scans */
 	create_tidscan_paths(root, rel);
+
+	set_cheapest(rel);
+
+	if (rel->reloptkind == RELOPT_BASEREL && enable_or_transformation)
+	{
+		bool applied_transfomation;
+		applied_transfomation =  (bool *) palloc(sizeof(bool));
+		reL_alternative->baserestrictinfo = transform_ors(root, reL_alternative->baserestrictinfo, &applied_transfomation);
+if (applied_transfomation)
+{
+	add_path(reL_alternative, create_seqscan_path(root, reL_alternative, required_outer, 0));
+
+	if (reL_alternative->consider_parallel && required_outer == NULL)
+		create_plain_partial_paths(root, reL_alternative);
+
+	create_index_paths(root, reL_alternative);
+
+	create_tidscan_paths(root, reL_alternative);
+
+	set_cheapest(reL_alternative);
+
+	elog(WARNING, "ors: - %f", rel->cheapest_total_path->total_cost);
+	elog(WARNING, "applied_transfomation: - %f", reL_alternative->cheapest_total_path->total_cost);
+
+	if (reL_alternative->cheapest_total_path->total_cost <= rel->cheapest_total_path->total_cost)
+	{
+		//copy_simple_rel(root, rel->relid, reL_alternative, rel);
+		rel->indexlist = reL_alternative->indexlist;
+		rel->baserestrictinfo = reL_alternative->baserestrictinfo;
+		rel->eclass_indexes = reL_alternative->eclass_indexes;
+	}
+	}
+	}
 }
 
 /*
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index acf4937db01..a9cc9a585df 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -34,12 +34,6 @@
 #include "optimizer/restrictinfo.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
-#include "parser/parse_coerce.h"
-#include "common/hashfn.h"
-#include "catalog/pg_operator.h"
-#include "nodes/queryjumble.h"
-#include "utils/syscache.h"
-#include "catalog/namespace.h"
 
 /* XXX see PartCollMatchesExprColl */
 #define IndexCollMatchesExprColl(idxcollation, exprcollation) \
@@ -198,391 +192,6 @@ static bool ec_member_matches_indexcol(PlannerInfo *root, RelOptInfo *rel,
 									   EquivalenceClass *ec, EquivalenceMember *em,
 									   void *arg);
 
-bool		enable_or_transformation = true;
-typedef struct OrClauseGroupKey
-{
-	Expr   *expr; /* Pointer to the expression tree which has been a source for
-					the hashkey value */
-	Oid		opno;
-	Oid		exprtype;
-} OrClauseGroupKey;
-
-typedef struct OrClauseGroupEntry
-{
-	OrClauseGroupKey key;
-	Node		   *node;
-	List		   *consts;
-	Oid				collation;
-	RestrictInfo   *rinfo;
-	List 		   *exprs;
-} OrClauseGroupEntry;
-
-/*
- * Hash function that's compatible with guc_name_compare
- */
-static uint32
-orclause_hash(const void *data, Size keysize)
-{
-	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
-	uint64				hash;
-
-	(void) JumbleExpr(key->expr, &hash);
-	hash = ((uint64) key->opno + (uint64) key->exprtype) % UINT64_MAX;
-	return hash;
-}
-
-static void *
-orclause_keycopy(void *dest, const void *src, Size keysize)
-{
-	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
-	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
-
-	Assert(sizeof(OrClauseGroupKey) == keysize);
-
-	dst_key->expr = src_key->expr;
-	dst_key->opno = src_key->opno;
-	dst_key->exprtype = src_key->exprtype;
-	return dst_key;
-}
-
-/*
- * Dynahash match function to use in guc_hashtab
- */
-static int
-orclause_match(const void *data1, const void *data2, Size keysize)
-{
-	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
-	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
-
-	Assert(sizeof(OrClauseGroupKey) == keysize);
-
-	if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
-		equal(key1->expr, key2->expr))
-		return 0;
-
-	return 1;
-}
-
-/*
- * Pass through baserestrictinfo clauses and try to convert OR clauses into IN
- * Return a modified clause list or just the same baserestrictinfo, if no
- * changes have made.
- * XXX: do not change source list of clauses at all.
- */
-static List *
-transform_ors(PlannerInfo *root, List *baserestrictinfo)
-{
-	ListCell   *lc;
-	List	   *modified_rinfo = NIL;
-	bool		something_changed = false;
-
-	/*
-	 * Complexity of a clause could be arbitrarily sophisticated. Here, we will
-	 * look up only on the top level of clause list.
-	 * XXX: It is substantiated? Could we change something here?
-	 */
-	foreach (lc, baserestrictinfo)
-	{
-		RestrictInfo   *rinfo = lfirst_node(RestrictInfo, lc);
-		RestrictInfo   *rinfo_base = copyObject(rinfo);
-		List		   *or_list = NIL;
-		ListCell	   *lc_eargs,
-					   *lc_rargs;
-		bool			change_apply = false;
-		HASHCTL			info;
-		HTAB 		   *or_group_htab = NULL;
-		int 			len_ors;
-		HASH_SEQ_STATUS		hash_seq;
-		OrClauseGroupEntry *gentry;
-
-		if (!enable_or_transformation || !restriction_is_or_clause(rinfo))
-		{
-			/* Add a clause without changes */
-			modified_rinfo = lappend(modified_rinfo, rinfo);
-			continue;
-		}
-
-		len_ors = ((BoolExpr *) rinfo->clause)->args? list_length(((BoolExpr *) rinfo->clause)->args) : 0;
-
-		if (len_ors < 2)
-		{
-			/* Add a clause without changes */
-			modified_rinfo = lappend(modified_rinfo, rinfo);
-			continue;
-		}
-
-		MemSet(&info, 0, sizeof(info));
-		info.keysize = sizeof(OrClauseGroupKey);
-		info.entrysize = sizeof(OrClauseGroupEntry);
-		info.hash = orclause_hash;
-		info.keycopy = orclause_keycopy;
-		info.match = orclause_match;
-		or_group_htab = hash_create("OR Groups",
-									len_ors,
-									&info,
-									HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
-
-		/*
-		 * NOTE:
-		 * It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
-		 * a list of sub-restrictinfo args, and rinfo->clause - which is the
-		 * same expression, made from bare clauses. To not break selectivity
-		 * caches and other optimizations, use both:
-		 * - use rinfos from orclause if no transformation needed
-		 * - use  bare quals from rinfo->clause in the case of transformation,
-		 * to create new RestrictInfo: in this case we have no options to avoid
-		 * selectivity estimation procedure.
-		 */
-		forboth(lc_eargs, ((BoolExpr *) rinfo->clause)->args,
-				lc_rargs, ((BoolExpr *) rinfo->orclause)->args)
-		{
-			Expr			   *or_qual = (Expr *) lfirst(lc_eargs);
-			RestrictInfo	   *sub_rinfo;
-			Node			   *const_expr;
-			Node			   *nconst_expr;
-			OrClauseGroupKey		hashkey;
-			bool found = false;
-
-			/* It may be one more boolean expression, skip it for now */
-			if (!IsA(lfirst(lc_rargs), RestrictInfo))
-			{
-				or_list = lappend(or_list, (void *) or_qual);
-				continue;
-			}
-
-			sub_rinfo = lfirst_node(RestrictInfo, lc_rargs);
-
-			/* Check: it is an expr of the form 'F(x) oper ConstExpr' */
-			if (!IsA(or_qual, OpExpr) ||
-				!(bms_is_empty(sub_rinfo->left_relids) ^
-				bms_is_empty(sub_rinfo->right_relids)) ||
-				contain_volatile_functions((Node *) or_qual))
-			{
-				/* Again, it's not the expr we can transform */
-				or_list = lappend(or_list, (void *) or_qual);
-				continue;
-			}
-
-			/* Get pointers to constant and expression sides of the clause */
-			const_expr =bms_is_empty(sub_rinfo->left_relids) ?
-												get_leftop(sub_rinfo->clause) :
-												get_rightop(sub_rinfo->clause);
-			nconst_expr = bms_is_empty(sub_rinfo->left_relids) ?
-												get_rightop(sub_rinfo->clause) :
-												get_leftop(sub_rinfo->clause);
-
-			if (!op_mergejoinable(((OpExpr *) sub_rinfo->clause)->opno, exprType(nconst_expr)))
-			{
-				/* And again, filter out non-equality operators */
-				or_list = lappend(or_list, (void *) or_qual);
-				continue;
-			}
-
-			/*
-			 * At this point we definitely have a transformable clause.
-			 * Classify it and add into specific group of clauses, or create new
-			 * group.
-			 */
-			hashkey.expr = (Expr *) nconst_expr;
-			hashkey.opno = ((OpExpr *) or_qual)->opno;
-			hashkey.exprtype = exprType(nconst_expr);
-			gentry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
-
-			if (unlikely(found))
-			{
-				gentry->consts = lappend(gentry->consts, const_expr);
-				gentry->exprs = lappend(gentry->exprs, or_qual);
-			}
-			else
-			{
-				gentry->node = nconst_expr;
-				gentry->consts = list_make1(const_expr);
-				gentry->exprs = list_make1(or_qual);
-				gentry->rinfo = sub_rinfo;
-				gentry->collation = exprInputCollation((Node *)sub_rinfo->clause);
-			}
-		}
-
-		if (list_length(or_list) == len_ors)
-		{
-			/*
-			* No any transformations possible with this list of arguments. Here we
-			* already made all underlying transformations. Thus, just return the
-			* transformed bool expression.
-			*/
-			modified_rinfo = lappend(modified_rinfo, rinfo);
-			continue;
-		}
-
-		if (!or_group_htab && hash_get_num_entries(or_group_htab) < 1)
-		{
-			/*
-			 * No any transformations possible with this rinfo, just add itself
-			 * to the list and go further.
-			 */
-			modified_rinfo = lappend(modified_rinfo, rinfo);
-			continue;
-		}
-
-		hash_seq_init(&hash_seq, or_group_htab);
-
-		/* Let's convert each group of clauses to an IN operation. */
-
-		/*
-		* Go through the list of groups and convert each, where number of
-		* consts more than 1. trivial groups move to OR-list again
-		*/
-
-		while ((gentry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
-		{
-			Oid				    scalar_type;
-			Oid					array_type;
-
-			Assert(list_length(gentry->consts) > 0);
-			Assert(list_length(gentry->exprs) == list_length(gentry->consts));
-
-			if (list_length(gentry->consts) == 1)
-			{
-				/*
-				* Only one element in the class. Return rinfo into the BoolExpr
-				* args list unchanged.
-				*/
-				list_free(gentry->consts);
-				or_list = list_concat(or_list, gentry->exprs);
-				continue;
-			}
-
-			/*
-			* Do the transformation.
-			*
-			* First of all, try to select a common type for the array elements.
-			* Note that since the LHS' type is first in the list, it will be
-			* preferred when there is doubt (eg, when all the RHS items are
-			* unknown literals).
-			*
-			* Note: use list_concat here not lcons, to avoid damaging rnonvars.
-			*
-			* As a source of insides, use make_scalar_array_op()
-			*/
-			scalar_type = gentry->key.exprtype;
-
-			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
-				array_type = get_array_type(scalar_type);
-			else
-				array_type = InvalidOid;
-
-			if (array_type != InvalidOid && scalar_type != InvalidOid)
-			{
-				/*
-				* OK: coerce all the right-hand non-Var inputs to the common
-				* type and build an ArrayExpr for them.
-				*/
-				List	   *aexprs = NULL;
-				ArrayExpr  *newa = NULL;
-				ScalarArrayOpExpr *saopexpr = NULL;
-				HeapTuple			opertup;
-				Form_pg_operator	operform;
-				List			   *namelist = NIL;
-
-				aexprs = gentry->consts;
-
-				newa = makeNode(ArrayExpr);
-				/* array_collid will be set by parse_collate.c */
-				newa->element_typeid = scalar_type;
-				newa->array_typeid = array_type;
-				newa->multidims = false;
-				newa->elements = aexprs;
-				newa->location = -1;
-
-				opertup = SearchSysCache1(OPEROID,
-									  ObjectIdGetDatum(gentry->key.opno));
-
-				if (!HeapTupleIsValid(opertup))
-					elog(ERROR, "cache lookup failed for operator %u",
-						gentry->key.opno);
-
-				operform = (Form_pg_operator) GETSTRUCT(opertup);
-				if (!OperatorIsVisible(gentry->key.opno))
-					namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
-
-				namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
-				ReleaseSysCache(opertup);
-
-				saopexpr = makeNode(ScalarArrayOpExpr);
-				saopexpr->opno = ((OpExpr *) gentry->rinfo->clause)->opno;
-				saopexpr->useOr = true;
-				saopexpr->inputcollid = gentry->collation;
-				saopexpr->args = list_make2(gentry->node, newa);
-				saopexpr->location = -1;
-
-
-				or_list = lappend(or_list, (void *) saopexpr);
-
-				something_changed = true;
-				change_apply = true;
-
-			}
-			else
-			{
-				list_free(gentry->consts);
-				or_list = lappend(or_list, (void *) gentry->rinfo->clause);
-			}
-			hash_search(or_group_htab, &gentry->key, HASH_REMOVE, NULL);
-		}
-
-		hash_destroy(or_group_htab);
-
-		if (!change_apply)
-		{
-			/*
-			 * Each group contains only one element - use rinfo as is.
-			 */
-			modified_rinfo = lappend(modified_rinfo, rinfo);
-			list_free(or_list);
-			continue;
-		}
-
-		/*
-		 * Make a new version of the restriction. Remember source restriction
-		 * can be used in another path (SeqScan, for example).
-		 */
-
-		/* One more trick: assemble correct clause */
-		rinfo = make_restrictinfo(root,
-				  list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, or_list, ((BoolExpr *) rinfo->clause)->location) :
-											 linitial(or_list),
-				  rinfo->is_pushed_down,
-				  rinfo->has_clone,
-				  rinfo->is_clone,
-				  rinfo->pseudoconstant,
-				  rinfo->security_level,
-				  rinfo->required_relids,
-				  rinfo->incompatible_relids,
-				  rinfo->outer_relids);
-		rinfo->eval_cost=rinfo_base->eval_cost;
-		rinfo->norm_selec=rinfo_base->norm_selec;
-		rinfo->outer_selec=rinfo_base->outer_selec;
-		rinfo->left_bucketsize=rinfo_base->left_bucketsize;
-		rinfo->right_bucketsize=rinfo_base->right_bucketsize;
-		rinfo->left_mcvfreq=rinfo_base->left_mcvfreq;
-		rinfo->right_mcvfreq=rinfo_base->right_mcvfreq;
-		modified_rinfo = lappend(modified_rinfo, rinfo);
-		something_changed = true;
-	}
-
-	/*
-	 * Check if transformation has made. If nothing changed - return
-	 * baserestrictinfo as is.
-	 */
-	if (something_changed)
-	{
-		return modified_rinfo;
-	}
-
-	list_free(modified_rinfo);
-	return baserestrictinfo;
-}
-
 /*
  * create_index_paths()
  *	  Generate all interesting index paths for the given relation.
@@ -1108,9 +717,6 @@ get_index_paths(PlannerInfo *root, RelOptInfo *rel,
 	bool		skip_lower_saop = false;
 	ListCell   *lc;
 
-	if (rel->reloptkind == RELOPT_BASEREL)
-		rel->baserestrictinfo = transform_ors(root, rel->baserestrictinfo);
-
 	/*
 	 * Build simple index paths using the clauses.  Allow ScalarArrayOpExpr
 	 * clauses only if the index AM supports them natively, and skip any such
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c
index 5d83f60eb9a..189cee449bf 100644
--- a/src/backend/optimizer/util/relnode.c
+++ b/src/backend/optimizer/util/relnode.c
@@ -183,6 +183,97 @@ expand_planner_arrays(PlannerInfo *root, int add_size)
 	root->simple_rel_array_size = new_size;
 }
 
+RelOptInfo *
+copy_simple_rel(PlannerInfo *root, int relid, RelOptInfo *base_rel, RelOptInfo *rel)
+{
+	rel->reloptkind = base_rel->parent ? RELOPT_OTHER_MEMBER_REL : RELOPT_BASEREL;
+	rel->relids = base_rel->relids;
+	rel->rows = base_rel->rows;
+	/* cheap startup cost is interesting iff not all tuples to be retrieved */
+	rel->consider_startup = (root->tuple_fraction > 0);
+	rel->consider_param_startup = base_rel->consider_param_startup;	/* might get changed later */
+	rel->consider_parallel = base_rel->consider_parallel; /* might get changed later */
+	rel->reltarget = base_rel->reltarget;
+	rel->pathlist = base_rel->pathlist;
+	rel->ppilist = base_rel->ppilist;
+	rel->partial_pathlist = base_rel->partial_pathlist;
+	rel->cheapest_startup_path = base_rel->cheapest_startup_path;
+	rel->cheapest_total_path = base_rel->cheapest_total_path;
+	rel->cheapest_unique_path = base_rel->cheapest_unique_path;
+	rel->cheapest_parameterized_paths = base_rel->cheapest_parameterized_paths;
+	rel->relid = base_rel->relid;
+	/* min_attr, max_attr, attr_needed, attr_widths are set below */
+	rel->lateral_vars = base_rel->lateral_vars;
+	rel->statlist = base_rel->statlist;
+	rel->pages = base_rel->pages;
+	rel->tuples = base_rel->tuples;
+	rel->allvisfrac = base_rel->allvisfrac;
+	rel->subroot = base_rel->subroot;
+	rel->subplan_params = base_rel->subplan_params;
+	rel->rel_parallel_workers = base_rel->rel_parallel_workers; /* set up in get_relation_info */
+	rel->amflags = base_rel->amflags;
+	rel->parent = base_rel->parent;
+	rel->serverid = base_rel->serverid;
+	rel->userid = base_rel->userid;
+	rel->useridiscurrent = base_rel->useridiscurrent;
+	rel->fdwroutine = base_rel->fdwroutine;
+	rel->fdw_private = base_rel->fdw_private;
+	rel->unique_for_rels = base_rel->unique_for_rels;
+	rel->non_unique_for_rels = base_rel->non_unique_for_rels;
+	rel->baserestrictcost.startup = 0;
+	rel->baserestrictcost.per_tuple = 0;
+	rel->baserestrict_min_security = UINT_MAX;
+	rel->joininfo = base_rel->joininfo;
+	rel->has_eclass_joins = base_rel->has_eclass_joins;
+
+	/*
+	 * Pass assorted information down the inheritance hierarchy.
+	 */
+	if (base_rel->parent)
+	{
+		/* We keep back-links to immediate parent and topmost parent. */
+		rel->parent = base_rel->parent;
+		rel->top_parent = base_rel->parent->top_parent ? base_rel->parent->top_parent : base_rel->parent;
+		rel->top_parent_relids = base_rel->top_parent->relids;
+
+		/*
+		 * A child rel is below the same outer joins as its parent.  (We
+		 * presume this info was already calculated for the parent.)
+		 */
+		rel->nulling_relids = base_rel->parent->nulling_relids;
+
+		/*
+		 * Also propagate lateral-reference information from appendrel parent
+		 * rels to their child rels.  We intentionally give each child rel the
+		 * same minimum parameterization, even though it's quite possible that
+		 * some don't reference all the lateral rels.  This is because any
+		 * append path for the parent will have to have the same
+		 * parameterization for every child anyway, and there's no value in
+		 * forcing extra reparameterize_path() calls.  Similarly, a lateral
+		 * reference to the parent prevents use of otherwise-movable join rels
+		 * for each child.
+		 *
+		 * It's possible for child rels to have their own children, in which
+		 * case the topmost parent's lateral info propagates all the way down.
+		 */
+		rel->direct_lateral_relids = base_rel->parent->direct_lateral_relids;
+		rel->lateral_relids = base_rel->parent->lateral_relids;
+		rel->lateral_referencers = base_rel->parent->lateral_referencers;
+	}
+	else
+	{
+		rel->parent = base_rel->parent;
+		rel->top_parent = base_rel->top_parent;
+		rel->top_parent_relids = base_rel->top_parent_relids;
+		rel->nulling_relids = base_rel->nulling_relids;
+		rel->direct_lateral_relids = base_rel->direct_lateral_relids;
+		rel->lateral_relids = base_rel->lateral_relids;
+		rel->lateral_referencers = base_rel->lateral_referencers;
+	}
+
+	return rel;
+}
+
 /*
  * build_simple_rel
  *	  Construct a new RelOptInfo for a base relation or 'other' relation.
diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h
index 6e557bebc44..2b3825b6e52 100644
--- a/src/include/optimizer/pathnode.h
+++ b/src/include/optimizer/pathnode.h
@@ -304,6 +304,8 @@ extern Path *reparameterize_path_by_child(PlannerInfo *root, Path *path,
  */
 extern void setup_simple_rel_arrays(PlannerInfo *root);
 extern void expand_planner_arrays(PlannerInfo *root, int add_size);
+extern RelOptInfo *
+copy_simple_rel(PlannerInfo *root, int relid, RelOptInfo *base_rel, RelOptInfo *rel);
 extern RelOptInfo *build_simple_rel(PlannerInfo *root, int relid,
 									RelOptInfo *parent);
 extern RelOptInfo *find_base_rel(PlannerInfo *root, int relid);
-- 
2.34.1

#114Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#112)
Re: POC, WIP: OR-clause support for indexes

On 30/11/2023 15:00, Alena Rybakina wrote:

2. The second patch is my patch version when I moved the OR
transformation in the s index formation stage:

So, I got the best query plan despite the possible OR to ANY
transformation:

If the user uses a clause like "x IN (1,2) AND y=100", it will break
your 'good' solution.
In my opinion, the general approach here is to stay with OR->ANY
transformation at the parsing stage and invent one more way for picking
an index by looking into the array and attempting to find a compound index.
Having a shorter list of expressions, where uniform ORs are grouped into
arrays, the optimizer will do such work with less overhead.

--
regards,
Andrei Lepikhov
Postgres Professional

#115Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Andrei Lepikhov (#114)
Re: POC, WIP: OR-clause support for indexes

On 30.11.2023 11:30, Andrei Lepikhov wrote:

On 30/11/2023 15:00, Alena Rybakina wrote:

2. The second patch is my patch version when I moved the OR
transformation in the s index formation stage:

So, I got the best query plan despite the possible OR to ANY
transformation:

If the user uses a clause like "x IN (1,2) AND y=100", it will break
your 'good' solution.

No, unfortunately I still see the plan with Seq scan node:

postgres=# explain analyze select * from test where x in (1,2) and y = 100;

                                                     QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
 Gather  (cost=1000.00..12690.10 rows=1 width=12) (actual
time=72.985..74.832 rows=0 loops=1)
   Workers Planned: 2
   Workers Launched: 2
   ->  Parallel Seq Scan on test  (cost=0.00..11690.00 rows=1 width=12)
(actual time=68.573..68.573 rows=0 loops=3)
         Filter: ((x = ANY ('{1,2}'::integer[])) AND (y = '100'::double
precision))
         Rows Removed by Filter: 333333
 Planning Time: 0.264 ms
 Execution Time: 74.887 ms

(8 rows)

In my opinion, the general approach here is to stay with OR->ANY
transformation at the parsing stage and invent one more way for
picking an index by looking into the array and attempting to find a
compound index.
Having a shorter list of expressions, where uniform ORs are grouped
into arrays, the optimizer will do such work with less overhead.

Looking at the current index generation code, implementing this approach
will require a lot of refactoring so that functions starting with
get_indexes do not rely on the current baserestrictinfo, but use only
the indexrestrictinfo, which is a copy of baserestrictinfo. And I think,
potentially, there may be complexity also with the equivalences that we
can get from OR expressions. All interesting transformations are
available only for OR expressions, not for ANY, that is, it makes sense
to try the last chance to find a suitable plan with the available OR
expressions and if that plan turns out to be better, use it.

--
Regards,
Alena Rybakina
Postgres Professional

#116Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#112)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 30.11.2023 11:00, Alena Rybakina wrote:

Hi!

Honestly, it seems very hard to avoid the conclusion that this
transformation is being done at too early a stage. Parse analysis is
not the time to try to do query optimization. I can't really believe
that there's a way to produce a committable patch along these lines.
Ideally, a transformation like this should be done after we know what
plan shape we're using (or considering using), so that we can make
cost-based decisions about whether to transform or not. But at the
very least it should happen somewhere in the planner. There's really
no justification for parse analysis rewriting the SQL that the user
entered.

Here, we assume that array operation is generally better than many ORs.
As a result, it should be more effective to make OR->ANY
transformation in the parser (it is a relatively lightweight
operation here) and, as a second phase, decompose that in the optimizer.
We implemented earlier prototypes in different places of the
optimizer, and I'm convinced that only this approach resolves the
issues we found.
Does this approach look weird? Maybe. We can debate it in this thread.

I think this is incorrect, and the example of A. Korotkov confirms
this. If we perform the conversion at the parsing stage, we will skip
the more important conversion using OR expressions. I'll show you in
the example below.

First of all, I will describe my idea to combine two approaches to
obtaining plans with OR to ANY transformation and ANY to OR
transformation. I think they are both good, and we can't work with
just one of them, we should consider both the option of OR
expressions, and with ANY.

Just in case, I have attached a patch or->any transformation where this
happens at the index creation stage.

I get diff file during make check, but judging by the changes, it shows
that the transformation is going well. I also attached it.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

v14-0001-Transform-OR-clause-to ANY-expressions.patchtext/x-patch; charset=UTF-8; name="v14-0001-Transform-OR-clause-to ANY-expressions.patch"Download
From 9f75b58525b4892db2c360401771f69599ed21c8 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Wed, 29 Nov 2023 18:58:55 +0300
Subject: [PATCH] Transform OR clause to ANY expressions.

Replace (X=N1) OR (X=N2) ... with X = ANY(N1, N2) on the preliminary stage of
optimization when we are still working with a tree expression.
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.

---
 src/backend/nodes/queryjumblefuncs.c          |  30 ++
 src/backend/optimizer/path/indxpath.c         | 394 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  10 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/include/nodes/queryjumble.h               |   1 +
 src/include/optimizer/paths.h                 |   1 +
 src/test/regress/expected/create_index.out    | 120 ++++++
 src/test/regress/expected/guc.out             |   3 +-
 src/test/regress/expected/join.out            |  48 +++
 src/test/regress/expected/partition_prune.out | 179 ++++++++
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  17 +
 src/test/regress/sql/create_index.sql         |  32 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 +
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   1 +
 17 files changed, 875 insertions(+), 3 deletions(-)

diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 281907a4d83..c98fda73d17 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -283,6 +283,36 @@ _jumbleNode(JumbleState *jstate, Node *node)
 	}
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	if (*queryId == UINT64CONST(0))
+		*queryId = UINT64CONST(1);
+
+	return jstate;
+}
+
 static void
 _jumbleList(JumbleState *jstate, Node *node)
 {
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 03a5fbdc6dc..acf4937db01 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -34,7 +34,12 @@
 #include "optimizer/restrictinfo.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
-
+#include "parser/parse_coerce.h"
+#include "common/hashfn.h"
+#include "catalog/pg_operator.h"
+#include "nodes/queryjumble.h"
+#include "utils/syscache.h"
+#include "catalog/namespace.h"
 
 /* XXX see PartCollMatchesExprColl */
 #define IndexCollMatchesExprColl(idxcollation, exprcollation) \
@@ -193,6 +198,390 @@ static bool ec_member_matches_indexcol(PlannerInfo *root, RelOptInfo *rel,
 									   EquivalenceClass *ec, EquivalenceMember *em,
 									   void *arg);
 
+bool		enable_or_transformation = true;
+typedef struct OrClauseGroupKey
+{
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+	Node		   *node;
+	List		   *consts;
+	Oid				collation;
+	RestrictInfo   *rinfo;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function that's compatible with guc_name_compare
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				hash;
+
+	(void) JumbleExpr(key->expr, &hash);
+	hash = ((uint64) key->opno + (uint64) key->exprtype) % UINT64_MAX;
+	return hash;
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in guc_hashtab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+/*
+ * Pass through baserestrictinfo clauses and try to convert OR clauses into IN
+ * Return a modified clause list or just the same baserestrictinfo, if no
+ * changes have made.
+ * XXX: do not change source list of clauses at all.
+ */
+static List *
+transform_ors(PlannerInfo *root, List *baserestrictinfo)
+{
+	ListCell   *lc;
+	List	   *modified_rinfo = NIL;
+	bool		something_changed = false;
+
+	/*
+	 * Complexity of a clause could be arbitrarily sophisticated. Here, we will
+	 * look up only on the top level of clause list.
+	 * XXX: It is substantiated? Could we change something here?
+	 */
+	foreach (lc, baserestrictinfo)
+	{
+		RestrictInfo   *rinfo = lfirst_node(RestrictInfo, lc);
+		RestrictInfo   *rinfo_base = copyObject(rinfo);
+		List		   *or_list = NIL;
+		ListCell	   *lc_eargs,
+					   *lc_rargs;
+		bool			change_apply = false;
+		HASHCTL			info;
+		HTAB 		   *or_group_htab = NULL;
+		int 			len_ors;
+		HASH_SEQ_STATUS		hash_seq;
+		OrClauseGroupEntry *gentry;
+
+		if (!enable_or_transformation || !restriction_is_or_clause(rinfo))
+		{
+			/* Add a clause without changes */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		len_ors = ((BoolExpr *) rinfo->clause)->args? list_length(((BoolExpr *) rinfo->clause)->args) : 0;
+
+		if (len_ors < 2)
+		{
+			/* Add a clause without changes */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		MemSet(&info, 0, sizeof(info));
+		info.keysize = sizeof(OrClauseGroupKey);
+		info.entrysize = sizeof(OrClauseGroupEntry);
+		info.hash = orclause_hash;
+		info.keycopy = orclause_keycopy;
+		info.match = orclause_match;
+		or_group_htab = hash_create("OR Groups",
+									len_ors,
+									&info,
+									HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+		/*
+		 * NOTE:
+		 * It is an OR-clause. So, rinfo->orclause is a BoolExpr node, contains
+		 * a list of sub-restrictinfo args, and rinfo->clause - which is the
+		 * same expression, made from bare clauses. To not break selectivity
+		 * caches and other optimizations, use both:
+		 * - use rinfos from orclause if no transformation needed
+		 * - use  bare quals from rinfo->clause in the case of transformation,
+		 * to create new RestrictInfo: in this case we have no options to avoid
+		 * selectivity estimation procedure.
+		 */
+		forboth(lc_eargs, ((BoolExpr *) rinfo->clause)->args,
+				lc_rargs, ((BoolExpr *) rinfo->orclause)->args)
+		{
+			Expr			   *or_qual = (Expr *) lfirst(lc_eargs);
+			RestrictInfo	   *sub_rinfo;
+			Node			   *const_expr;
+			Node			   *nconst_expr;
+			OrClauseGroupKey		hashkey;
+			bool found = false;
+
+			/* It may be one more boolean expression, skip it for now */
+			if (!IsA(lfirst(lc_rargs), RestrictInfo))
+			{
+				or_list = lappend(or_list, (void *) or_qual);
+				continue;
+			}
+
+			sub_rinfo = lfirst_node(RestrictInfo, lc_rargs);
+
+			/* Check: it is an expr of the form 'F(x) oper ConstExpr' */
+			if (!IsA(or_qual, OpExpr) ||
+				!(bms_is_empty(sub_rinfo->left_relids) ^
+				bms_is_empty(sub_rinfo->right_relids)) ||
+				contain_volatile_functions((Node *) or_qual))
+			{
+				/* Again, it's not the expr we can transform */
+				or_list = lappend(or_list, (void *) or_qual);
+				continue;
+			}
+
+			/* Get pointers to constant and expression sides of the clause */
+			const_expr =bms_is_empty(sub_rinfo->left_relids) ?
+												get_leftop(sub_rinfo->clause) :
+												get_rightop(sub_rinfo->clause);
+			nconst_expr = bms_is_empty(sub_rinfo->left_relids) ?
+												get_rightop(sub_rinfo->clause) :
+												get_leftop(sub_rinfo->clause);
+
+			if (!op_mergejoinable(((OpExpr *) sub_rinfo->clause)->opno, exprType(nconst_expr)))
+			{
+				/* And again, filter out non-equality operators */
+				or_list = lappend(or_list, (void *) or_qual);
+				continue;
+			}
+
+			/*
+			 * At this point we definitely have a transformable clause.
+			 * Classify it and add into specific group of clauses, or create new
+			 * group.
+			 */
+			hashkey.expr = (Expr *) nconst_expr;
+			hashkey.opno = ((OpExpr *) or_qual)->opno;
+			hashkey.exprtype = exprType(nconst_expr);
+			gentry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+			if (unlikely(found))
+			{
+				gentry->consts = lappend(gentry->consts, const_expr);
+				gentry->exprs = lappend(gentry->exprs, or_qual);
+			}
+			else
+			{
+				gentry->node = nconst_expr;
+				gentry->consts = list_make1(const_expr);
+				gentry->exprs = list_make1(or_qual);
+				gentry->rinfo = sub_rinfo;
+				gentry->collation = exprInputCollation((Node *)sub_rinfo->clause);
+			}
+		}
+
+		if (list_length(or_list) == len_ors)
+		{
+			/*
+			* No any transformations possible with this list of arguments. Here we
+			* already made all underlying transformations. Thus, just return the
+			* transformed bool expression.
+			*/
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		if (!or_group_htab && hash_get_num_entries(or_group_htab) < 1)
+		{
+			/*
+			 * No any transformations possible with this rinfo, just add itself
+			 * to the list and go further.
+			 */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			continue;
+		}
+
+		hash_seq_init(&hash_seq, or_group_htab);
+
+		/* Let's convert each group of clauses to an IN operation. */
+
+		/*
+		* Go through the list of groups and convert each, where number of
+		* consts more than 1. trivial groups move to OR-list again
+		*/
+
+		while ((gentry = (OrClauseGroupEntry *) hash_seq_search(&hash_seq)) != NULL)
+		{
+			Oid				    scalar_type;
+			Oid					array_type;
+
+			Assert(list_length(gentry->consts) > 0);
+			Assert(list_length(gentry->exprs) == list_length(gentry->consts));
+
+			if (list_length(gentry->consts) == 1)
+			{
+				/*
+				* Only one element in the class. Return rinfo into the BoolExpr
+				* args list unchanged.
+				*/
+				list_free(gentry->consts);
+				or_list = list_concat(or_list, gentry->exprs);
+				continue;
+			}
+
+			/*
+			* Do the transformation.
+			*
+			* First of all, try to select a common type for the array elements.
+			* Note that since the LHS' type is first in the list, it will be
+			* preferred when there is doubt (eg, when all the RHS items are
+			* unknown literals).
+			*
+			* Note: use list_concat here not lcons, to avoid damaging rnonvars.
+			*
+			* As a source of insides, use make_scalar_array_op()
+			*/
+			scalar_type = gentry->key.exprtype;
+
+			if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+				array_type = get_array_type(scalar_type);
+			else
+				array_type = InvalidOid;
+
+			if (array_type != InvalidOid && scalar_type != InvalidOid)
+			{
+				/*
+				* OK: coerce all the right-hand non-Var inputs to the common
+				* type and build an ArrayExpr for them.
+				*/
+				List	   *aexprs = NULL;
+				ArrayExpr  *newa = NULL;
+				ScalarArrayOpExpr *saopexpr = NULL;
+				HeapTuple			opertup;
+				Form_pg_operator	operform;
+				List			   *namelist = NIL;
+
+				aexprs = gentry->consts;
+
+				newa = makeNode(ArrayExpr);
+				/* array_collid will be set by parse_collate.c */
+				newa->element_typeid = scalar_type;
+				newa->array_typeid = array_type;
+				newa->multidims = false;
+				newa->elements = aexprs;
+				newa->location = -1;
+
+				opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(gentry->key.opno));
+
+				if (!HeapTupleIsValid(opertup))
+					elog(ERROR, "cache lookup failed for operator %u",
+						gentry->key.opno);
+
+				operform = (Form_pg_operator) GETSTRUCT(opertup);
+				if (!OperatorIsVisible(gentry->key.opno))
+					namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+				namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+				ReleaseSysCache(opertup);
+
+				saopexpr = makeNode(ScalarArrayOpExpr);
+				saopexpr->opno = ((OpExpr *) gentry->rinfo->clause)->opno;
+				saopexpr->useOr = true;
+				saopexpr->inputcollid = gentry->collation;
+				saopexpr->args = list_make2(gentry->node, newa);
+				saopexpr->location = -1;
+
+
+				or_list = lappend(or_list, (void *) saopexpr);
+
+				something_changed = true;
+				change_apply = true;
+
+			}
+			else
+			{
+				list_free(gentry->consts);
+				or_list = lappend(or_list, (void *) gentry->rinfo->clause);
+			}
+			hash_search(or_group_htab, &gentry->key, HASH_REMOVE, NULL);
+		}
+
+		hash_destroy(or_group_htab);
+
+		if (!change_apply)
+		{
+			/*
+			 * Each group contains only one element - use rinfo as is.
+			 */
+			modified_rinfo = lappend(modified_rinfo, rinfo);
+			list_free(or_list);
+			continue;
+		}
+
+		/*
+		 * Make a new version of the restriction. Remember source restriction
+		 * can be used in another path (SeqScan, for example).
+		 */
+
+		/* One more trick: assemble correct clause */
+		rinfo = make_restrictinfo(root,
+				  list_length(or_list) > 1 ? makeBoolExpr(OR_EXPR, or_list, ((BoolExpr *) rinfo->clause)->location) :
+											 linitial(or_list),
+				  rinfo->is_pushed_down,
+				  rinfo->has_clone,
+				  rinfo->is_clone,
+				  rinfo->pseudoconstant,
+				  rinfo->security_level,
+				  rinfo->required_relids,
+				  rinfo->incompatible_relids,
+				  rinfo->outer_relids);
+		rinfo->eval_cost=rinfo_base->eval_cost;
+		rinfo->norm_selec=rinfo_base->norm_selec;
+		rinfo->outer_selec=rinfo_base->outer_selec;
+		rinfo->left_bucketsize=rinfo_base->left_bucketsize;
+		rinfo->right_bucketsize=rinfo_base->right_bucketsize;
+		rinfo->left_mcvfreq=rinfo_base->left_mcvfreq;
+		rinfo->right_mcvfreq=rinfo_base->right_mcvfreq;
+		modified_rinfo = lappend(modified_rinfo, rinfo);
+		something_changed = true;
+	}
+
+	/*
+	 * Check if transformation has made. If nothing changed - return
+	 * baserestrictinfo as is.
+	 */
+	if (something_changed)
+	{
+		return modified_rinfo;
+	}
+
+	list_free(modified_rinfo);
+	return baserestrictinfo;
+}
 
 /*
  * create_index_paths()
@@ -719,6 +1108,9 @@ get_index_paths(PlannerInfo *root, RelOptInfo *rel,
 	bool		skip_lower_saop = false;
 	ListCell   *lc;
 
+	if (rel->reloptkind == RELOPT_BASEREL)
+		rel->baserestrictinfo = transform_ors(root, rel->baserestrictinfo);
+
 	/*
 	 * Build simple index paths using the clauses.  Allow ScalarArrayOpExpr
 	 * clauses only if the index AM supports them natively, and skip any such
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index b764ef69980..2ca8a21caf0 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,16 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'")
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index e48c066a5b1..f31778074b4 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -370,6 +370,7 @@
 
 # - Planner Method Configuration -
 
+#enable_or_transformation = on
 #enable_async_append = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index 0769081c7ab..4aaa31aa80e 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/paths.h b/src/include/optimizer/paths.h
index 9e7408c7ecf..f8be9f9f605 100644
--- a/src/include/optimizer/paths.h
+++ b/src/include/optimizer/paths.h
@@ -24,6 +24,7 @@ extern PGDLLIMPORT bool enable_geqo;
 extern PGDLLIMPORT int geqo_threshold;
 extern PGDLLIMPORT int min_parallel_table_scan_size;
 extern PGDLLIMPORT int min_parallel_index_scan_size;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 /* Hook for plugins to get control in set_rel_pathlist() */
 typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f7..5a73c8f51a6 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1883,6 +1883,126 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                               QUERY PLAN                               
+------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, 3, 42])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                 QUERY PLAN                                  
+-----------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY (ARRAY[42, 99])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY (ARRAY[42, 99]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 42) AND (tenthous = 1))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 42) AND (tenthous = 3))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY (ARRAY[42, 41]))))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY (ARRAY[42, 41]))
+(11 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+ count 
+-------
+    10
+(1 row)
+
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 127c9532976..0f2b1b16200 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -861,7 +861,8 @@ SELECT name FROM tab_settings_flags
            name            
 ---------------------------
  default_statistics_target
-(1 row)
+ enable_or_transformation
+(2 rows)
 
 -- Runtime-computed GUCs should be part of the preset category.
 SELECT name FROM tab_settings_flags
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 2c73270143b..54b8fdb2e88 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4233,6 +4233,54 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique2 = ANY (ARRAY[3, 7])) OR (unique1 = 1))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY (ARRAY[3, 7]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = ANY (ARRAY[3, 1])) OR (unique2 = ANY (ARRAY[3, 7])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY (ARRAY[3, 1]))
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY (ARRAY[3, 7]))
+(13 rows)
+
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c0556..38b4ec98403 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -101,6 +101,28 @@ explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c'
          Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+           QUERY PLAN           
+--------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: ((a = 1) OR (a = 7))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+               QUERY PLAN               
+----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a = 20) OR (a = 40))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: ((a = 20) OR (a = 40))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 271313ebf86..566f51df428 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -123,6 +123,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | off
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -133,7 +134,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(22 rows)
+(23 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..2e12944bd13 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                          QUERY PLAN                          
+--------------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY (ARRAY['(0,2)'::tid, '(0,1)'::tid]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..48bb1bc0a0a 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,38 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 8a8a63bd2f1..55d7e2ae7d6 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827f..1e270ae9c06 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..0499bedb9eb 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index dba3498a13e..c9004250a5f 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1641,6 +1641,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

regression.diffstext/plain; charset=UTF-8; name=regression.diffsDownload
diff -U3 /home/alena/postgrespro__copy32/src/test/regress/expected/create_index.out /home/alena/postgrespro__copy32/src/test/regress/results/create_index.out
--- /home/alena/postgrespro__copy32/src/test/regress/expected/create_index.out	2023-11-30 13:50:34.576537110 +0300
+++ /home/alena/postgrespro__copy32/src/test/regress/results/create_index.out	2023-11-30 13:52:10.940412842 +0300
@@ -1838,18 +1838,14 @@
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
+                   QUERY PLAN                    
+-------------------------------------------------
  Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+   Recheck Cond: (thousand = 42)
+   Filter: (tenthous = ANY (ARRAY[1, 3, 42]))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,20 +1857,15 @@
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
-         ->  BitmapAnd
-               ->  Bitmap Index Scan on tenk1_hundred
-                     Index Cond: (hundred = 42)
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+         Recheck Cond: (hundred = 42)
+         Filter: (thousand = ANY (ARRAY[42, 99]))
+         ->  Bitmap Index Scan on tenk1_hundred
+               Index Cond: (hundred = 42)
+(6 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1887,11 +1878,14 @@
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                               QUERY PLAN                               
-------------------------------------------------------------------------
- Index Scan using tenk1_thous_tenthous on tenk1
-   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, 3, 42])))
-(2 rows)
+                   QUERY PLAN                    
+-------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (tenthous = ANY (ARRAY[1, 3, 42]))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1903,17 +1897,15 @@
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                 QUERY PLAN                                  
------------------------------------------------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND (thousand = ANY (ARRAY[42, 99])))
-         ->  BitmapAnd
-               ->  Bitmap Index Scan on tenk1_hundred
-                     Index Cond: (hundred = 42)
-               ->  Bitmap Index Scan on tenk1_thous_tenthous
-                     Index Cond: (thousand = ANY (ARRAY[42, 99]))
-(8 rows)
+         Recheck Cond: (hundred = 42)
+         Filter: (thousand = ANY (ARRAY[42, 99]))
+         ->  Bitmap Index Scan on tenk1_hundred
+               Index Cond: (hundred = 42)
+(6 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff -U3 /home/alena/postgrespro__copy32/src/test/regress/expected/join.out /home/alena/postgrespro__copy32/src/test/regress/results/join.out
--- /home/alena/postgrespro__copy32/src/test/regress/expected/join.out	2023-11-30 13:50:34.576537110 +0300
+++ /home/alena/postgrespro__copy32/src/test/regress/results/join.out	2023-11-30 13:52:14.972407590 +0300
@@ -4223,15 +4223,13 @@
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY (ARRAY[3, 7])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY (ARRAY[3, 7]))
+(17 rows)
 
 SET enable_or_transformation = on;
 explain (costs off)
@@ -4251,12 +4249,12 @@
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique2 = ANY (ARRAY[3, 7])) OR (unique1 = 1))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY (ARRAY[3, 7])))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = ANY (ARRAY[3, 7]))
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY (ARRAY[3, 7]))
 (17 rows)
 
 explain (costs off)
diff -U3 /home/alena/postgrespro__copy32/src/test/regress/expected/sysviews.out /home/alena/postgrespro__copy32/src/test/regress/results/sysviews.out
--- /home/alena/postgrespro__copy32/src/test/regress/expected/sysviews.out	2023-11-30 13:50:34.584537100 +0300
+++ /home/alena/postgrespro__copy32/src/test/regress/results/sysviews.out	2023-11-30 13:52:24.524395130 +0300
@@ -123,7 +123,7 @@
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
- enable_or_transformation       | off
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
diff -U3 /home/alena/postgrespro__copy32/src/test/regress/expected/tidscan.out /home/alena/postgrespro__copy32/src/test/regress/results/tidscan.out
--- /home/alena/postgrespro__copy32/src/test/regress/expected/tidscan.out	2023-11-30 13:50:34.584537100 +0300
+++ /home/alena/postgrespro__copy32/src/test/regress/results/tidscan.out	2023-11-30 13:52:24.328395386 +0300
@@ -62,7 +62,7 @@
                           QUERY PLAN                          
 --------------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: (ctid = ANY (ARRAY['(0,2)'::tid, '(0,1)'::tid]))
+   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
#117Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#116)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi,

Here is the next version of the patch where, I think, all of Roberts's
claims related to the code have been fixed.
For example, expression 'x < 1 OR x < 2' is transformed to
'x < ANY (1,2)'.

Here, we still need to deal with the architectural issues. I like the
approach mentioned by Peter: try to transform the expression tree to
some 'normal' form, which is more laconic and simple; delay the search
for any optimization ways to the following stages.

Also, it doesn't pass pg_dump test. At first glance, it is a problem of
regex expression, which should be corrected further.

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v14-0001-Transform-OR-clause-to-ANY-expressions.patchtext/plain; charset=UTF-8; name=v14-0001-Transform-OR-clause-to-ANY-expressions.patchDownload
From 73031b7acae68494ddd0f9b1faf4c94aae3bd6b0 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Thu, 23 Nov 2023 16:00:13 +0700
Subject: [PATCH] Transform OR clause to ANY expressions.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(C1, C2, ...) on the
preliminary stage of optimization when we are still working with the tree
expression.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
---
 .../postgres_fdw/expected/postgres_fdw.out    |  16 +-
 src/backend/nodes/queryjumblefuncs.c          |  30 ++
 src/backend/parser/parse_expr.c               | 310 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  11 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/include/nodes/queryjumble.h               |   1 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 156 ++++++++-
 src/test/regress/expected/inherit.out         |   2 +-
 src/test/regress/expected/join.out            |  62 +++-
 src/test/regress/expected/partition_prune.out | 219 +++++++++++--
 src/test/regress/expected/rules.out           |   4 +-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  35 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 20 files changed, 859 insertions(+), 67 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 0a5bdf8bcc..ff69b2cd3b 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -1349,7 +1349,7 @@ SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE
  Foreign Scan
    Output: t1.c1, t1.c2, ft5.c1, ft5.c2
    Relations: (public.ft4 t1) LEFT JOIN (public.ft5)
-   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 < 10) OR (r4.c1 IS NULL))) AND ((r1.c1 < 10))
+   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 IS NULL) OR (r4.c1 < 10))) AND ((r1.c1 < 10))
 (4 rows)
 
 SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE c1 < 10) t2 ON (t1.c1 = t2.c1)
@@ -3112,7 +3112,7 @@ select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3130,7 +3130,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3147,7 +3147,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST)), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -8537,18 +8537,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 281907a4d8..99207a8670 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -135,6 +135,36 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	if (*queryId == UINT64CONST(0))
+		*queryId = UINT64CONST(1);
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344..9f4d43572c 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,14 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -38,11 +40,13 @@
 #include "utils/date.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +103,310 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function that's compatible with guc_name_compare
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				hash;
+
+	(void) JumbleExpr(key->expr, &hash);
+	hash += ((uint64) key->opno + (uint64) key->exprtype) % UINT64_MAX;
+	return hash;
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in guc_hashtab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
+{
+	List				   *or_list = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(expr->args);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (!enable_or_transformation || expr->boolop != OR_EXPR || len_ors < 2)
+		return transformBoolExpr(pstate, (BoolExpr *) expr);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, expr->args)
+	{
+		Node				   *arg = lfirst(lc);
+		Node				   *orqual;
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Node				   *leftop, *rightop;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* Commuter doesn't exist, we can't reverse the order */
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.exprtype = exprType(nconst_expr);
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->node = nconst_expr;
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element in the class. Return origin expression into
+			 * the BoolExpr args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.exprtype;
+		if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+			array_type = get_array_type(scalar_type);
+		else
+			array_type = InvalidOid;
+
+		if (array_type != InvalidOid)
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+			ListCell		   *lc1;
+
+			foreach(lc1, entry->consts)
+			{
+				Node   *rexpr = (Node *) lfirst(lc1);
+
+				rexpr = coerce_to_common_type(pstate, rexpr,
+											  scalar_type,
+											  "IN");
+				aexprs = lappend(aexprs, rexpr);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 entry->node,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * This part works on intarray test (OR there is made on
+			 * elements of a custom type)
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, expr->location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +520,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 6474e35ec0..4baca65bfe 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index cf9f283cfe..3d5b5fbc58 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -374,6 +374,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index 0769081c7a..4aaa31aa80 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7..3a87de0285 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f..daf497d3e3 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,116 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 0f1aa831f6..1781250122 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -2560,7 +2560,7 @@ explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd'
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 2c73270143..36dce0b84b 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 < 20) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 < 20) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c055..3423af4768 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -589,20 +611,20 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 ------------------------------------------------------
  Append
    ->  Seq Scan on rlp1 rlp_1
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
    ->  Seq Scan on rlp4_1 rlp_2
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
 (5 rows)
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -1933,10 +2112,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 05070393b9..c927c21dd4 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2495,7 +2495,7 @@ pg_stats| SELECT n.nspname AS schemaname,
      JOIN pg_class c ON ((c.oid = s.starelid)))
      JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
-  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2526,7 +2526,7 @@ pg_stats_ext| SELECT cn.nspname AS schemaname,
   WHERE ((NOT (EXISTS ( SELECT 1
            FROM (unnest(s.stxkeys) k(k)
              JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
-          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext_exprs| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index a430153b22..659d712f75 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 271313ebf8..c6c6b9fb8d 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -123,6 +123,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -133,7 +134,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(22 rows)
+(23 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..2a079e996b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..56fde15bc1 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 8a8a63bd2f..55d7e2ae7d 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827..1e270ae9c0 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index d659adbfd6..9591d0d084 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1645,6 +1645,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.43.0

#118Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Andrei Lepikhov (#117)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Here is fresh version with the pg_dump.pl regex fixed. Now it must pass
buildfarm.

Under development:
1. Explanation of the general idea in comments (Robert's note)
2. Issue with hiding some optimizations (Alexander's note and example
with overlapping clauses on two partial indexes)

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v14-1-0001-Transform-OR-clause-to-ANY-expressions.patchtext/plain; charset=UTF-8; name=v14-1-0001-Transform-OR-clause-to-ANY-expressions.patchDownload
From 71746caae3eb0c771792b563fd53244fc1ac575b Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Thu, 23 Nov 2023 16:00:13 +0700
Subject: [PATCH] Transform OR clause to ANY expressions.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(C1, C2, ...) on the
preliminary stage of optimization when we are still working with the tree
expression.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
---
 .../postgres_fdw/expected/postgres_fdw.out    |  16 +-
 src/backend/nodes/queryjumblefuncs.c          |  30 ++
 src/backend/parser/parse_expr.c               | 310 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  11 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/bin/pg_dump/t/002_pg_dump.pl              |   6 +-
 src/include/nodes/queryjumble.h               |   1 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 156 ++++++++-
 src/test/regress/expected/inherit.out         |   2 +-
 src/test/regress/expected/join.out            |  62 +++-
 src/test/regress/expected/partition_prune.out | 219 +++++++++++--
 src/test/regress/expected/rules.out           |   4 +-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  35 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 21 files changed, 862 insertions(+), 70 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 0a5bdf8bcc..ff69b2cd3b 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -1349,7 +1349,7 @@ SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE
  Foreign Scan
    Output: t1.c1, t1.c2, ft5.c1, ft5.c2
    Relations: (public.ft4 t1) LEFT JOIN (public.ft5)
-   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 < 10) OR (r4.c1 IS NULL))) AND ((r1.c1 < 10))
+   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 IS NULL) OR (r4.c1 < 10))) AND ((r1.c1 < 10))
 (4 rows)
 
 SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE c1 < 10) t2 ON (t1.c1 = t2.c1)
@@ -3112,7 +3112,7 @@ select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3130,7 +3130,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3147,7 +3147,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST)), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -8537,18 +8537,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 281907a4d8..99207a8670 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -135,6 +135,36 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	if (*queryId == UINT64CONST(0))
+		*queryId = UINT64CONST(1);
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 64c582c344..9f4d43572c 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,14 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -38,11 +40,13 @@
 #include "utils/date.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +103,310 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function that's compatible with guc_name_compare
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				hash;
+
+	(void) JumbleExpr(key->expr, &hash);
+	hash += ((uint64) key->opno + (uint64) key->exprtype) % UINT64_MAX;
+	return hash;
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in guc_hashtab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
+{
+	List				   *or_list = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(expr->args);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (!enable_or_transformation || expr->boolop != OR_EXPR || len_ors < 2)
+		return transformBoolExpr(pstate, (BoolExpr *) expr);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, expr->args)
+	{
+		Node				   *arg = lfirst(lc);
+		Node				   *orqual;
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Node				   *leftop, *rightop;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* Commuter doesn't exist, we can't reverse the order */
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.exprtype = exprType(nconst_expr);
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->node = nconst_expr;
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element in the class. Return origin expression into
+			 * the BoolExpr args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.exprtype;
+		if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+			array_type = get_array_type(scalar_type);
+		else
+			array_type = InvalidOid;
+
+		if (array_type != InvalidOid)
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+			ListCell		   *lc1;
+
+			foreach(lc1, entry->consts)
+			{
+				Node   *rexpr = (Node *) lfirst(lc1);
+
+				rexpr = coerce_to_common_type(pstate, rexpr,
+											  scalar_type,
+											  "IN");
+				aexprs = lappend(aexprs, rexpr);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 entry->node,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * This part works on intarray test (OR there is made on
+			 * elements of a custom type)
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, expr->location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +520,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 6474e35ec0..4baca65bfe 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1048,6 +1048,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index cf9f283cfe..3d5b5fbc58 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -374,6 +374,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index eb3ec534b4..452617bbb5 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -2059,9 +2059,9 @@ my %tests = (
 		regexp => qr/^
 			\QCREATE DOMAIN dump_test.us_postal_code AS text COLLATE pg_catalog."C" DEFAULT '10014'::text\E\n\s+
 			\QCONSTRAINT us_postal_code_check CHECK \E
-			\Q(((VALUE ~ '^\d{5}\E
-			\$\Q'::text) OR (VALUE ~ '^\d{5}-\d{4}\E\$
-			\Q'::text)));\E(.|\n)*
+			\Q((VALUE ~ ANY (ARRAY['^\d{5}\E
+			\$\Q'::text, '^\d{5}-\d{4}\E\$
+			\Q'::text])));\E(.|\n)*
 			\QCOMMENT ON CONSTRAINT us_postal_code_check ON DOMAIN dump_test.us_postal_code IS 'check it';\E
 			/xm,
 		like =>
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index 0769081c7a..4aaa31aa80 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 7d38ca75f7..3a87de0285 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index acfd9d1f4f..daf497d3e3 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,116 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 0f1aa831f6..1781250122 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -2560,7 +2560,7 @@ explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd'
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 2c73270143..36dce0b84b 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 < 20) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 < 20) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c055..3423af4768 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -589,20 +611,20 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 ------------------------------------------------------
  Append
    ->  Seq Scan on rlp1 rlp_1
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
    ->  Seq Scan on rlp4_1 rlp_2
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
 (5 rows)
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -1933,10 +2112,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 05070393b9..c927c21dd4 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2495,7 +2495,7 @@ pg_stats| SELECT n.nspname AS schemaname,
      JOIN pg_class c ON ((c.oid = s.starelid)))
      JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
-  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2526,7 +2526,7 @@ pg_stats_ext| SELECT cn.nspname AS schemaname,
   WHERE ((NOT (EXISTS ( SELECT 1
            FROM (unnest(s.stxkeys) k(k)
              JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
-          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext_exprs| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index a430153b22..659d712f75 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 271313ebf8..c6c6b9fb8d 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -123,6 +123,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -133,7 +134,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(22 rows)
+(23 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..2a079e996b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..56fde15bc1 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 8a8a63bd2f..55d7e2ae7d 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827..1e270ae9c0 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index d659adbfd6..9591d0d084 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1645,6 +1645,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.43.0

#119vignesh C
vignesh21@gmail.com
In reply to: Andrei Lepikhov (#118)
Re: POC, WIP: OR-clause support for indexes

On Tue, 5 Dec 2023 at 16:25, Andrei Lepikhov <a.lepikhov@postgrespro.ru> wrote:

Here is fresh version with the pg_dump.pl regex fixed. Now it must pass
buildfarm.

Under development:
1. Explanation of the general idea in comments (Robert's note)
2. Issue with hiding some optimizations (Alexander's note and example
with overlapping clauses on two partial indexes)

CFBot shows that the patch does not apply anymore as in [1]http://cfbot.cputube.org/patch_46_4450.log:
=== Applying patches on top of PostgreSQL commit ID
64444ce071f6b04d3fc836f436fa08108a6d11e2 ===
=== applying patch ./v14-1-0001-Transform-OR-clause-to-ANY-expressions.patch
....
patching file src/test/regress/expected/sysviews.out
Hunk #1 succeeded at 124 (offset 1 line).
Hunk #2 FAILED at 134.
1 out of 2 hunks FAILED -- saving rejects to file
src/test/regress/expected/sysviews.out.rej

Please post an updated version for the same.

[1]: http://cfbot.cputube.org/patch_46_4450.log

Regards,
Vignesh

#120jian he
jian.universality@gmail.com
In reply to: Andrei Lepikhov (#118)
Re: POC, WIP: OR-clause support for indexes

On Tue, Dec 5, 2023 at 6:55 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

Here is fresh version with the pg_dump.pl regex fixed. Now it must pass
buildfarm.

+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+ JumbleState *jstate = NULL;
+
+ Assert(queryId != NULL);
+
+ jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+ /* Set up workspace for query jumbling */
+ jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+ jstate->jumble_len = 0;
+ jstate->clocations_buf_size = 32;
+ jstate->clocations = (LocationLen *)
+ palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+ jstate->clocations_count = 0;
+ jstate->highest_extern_param_id = 0;
+
+ /* Compute query ID */
+ _jumbleNode(jstate, (Node *) expr);
+ *queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+ jstate->jumble_len,
+ 0));
+
+ if (*queryId == UINT64CONST(0))
+ *queryId = UINT64CONST(1);
+
+ return jstate;
+}
+/*
+ * Hash function that's compatible with guc_name_compare
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+ OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+ uint64 hash;
+
+ (void) JumbleExpr(key->expr, &hash);
+ hash += ((uint64) key->opno + (uint64) key->exprtype) % UINT64_MAX;
+ return hash;
+}

correct me if i am wrong:
in orclause_hash, you just want to return a uint32, then why does the
JumbleExpr function return struct JumbleState.
here JumbleExpr, we just simply hash part of a Query struct,
so JumbleExpr's queryId would be confused with JumbleQuery function's queryId.

not sure the purpose of the following:
+ if (*queryId == UINT64CONST(0))
+ *queryId = UINT64CONST(1);

even if *queryId is 0
`hash += ((uint64) key->opno + (uint64) key->exprtype) % UINT64_MAX;`
will make the hash return non-zero?

+ MemSet(&info, 0, sizeof(info));
i am not sure this is necessary.

Some comments on OrClauseGroupEntry would be great.

seems there is no doc.

create or replace function retint(int) returns int as
$func$
begin return $1 + round(10 * random()); end
$func$ LANGUAGE plpgsql;

set enable_or_transformation to on;
EXPLAIN (COSTS OFF)
SELECT count(*) FROM tenk1
WHERE thousand = 42 AND (tenthous * retint(1) = NULL OR tenthous *
retint(1) = 3) OR thousand = 41;

returns:
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------
Aggregate
-> Seq Scan on tenk1
Filter: (((thousand = 42) AND ((tenthous * retint(1)) = ANY
('{NULL,3}'::integer[]))) OR (thousand = 41))
(3 rows)

Based on the query plan, retint executed once, but here it should be
executed twice?
maybe we need to use contain_volatile_functions to check through the
other part of the operator expression.

+ if (IsA(leftop, Const))
+ {
+ opno = get_commutator(opno);
+
+ if (!OidIsValid(opno))
+ {
+ /* Commuter doesn't exist, we can't reverse the order */
+ or_list = lappend(or_list, orqual);
+ continue;
+ }
+
+ nconst_expr = get_rightop(orqual);
+ const_expr = get_leftop(orqual);
+ }
+ else if (IsA(rightop, Const))
+ {
+ const_expr = get_rightop(orqual);
+ nconst_expr = get_leftop(orqual);
+ }
+ else
+ {
+ or_list = lappend(or_list, orqual);
+ continue;
+ }
do we need to skip this transformation for the const type is anyarray?
#121jian he
jian.universality@gmail.com
In reply to: jian he (#120)
Re: POC, WIP: OR-clause support for indexes
+/*
+ * Hash function that's compatible with guc_name_compare
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+ OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+ uint64 hash;
+
+ (void) JumbleExpr(key->expr, &hash);
+ hash += ((uint64) key->opno + (uint64) key->exprtype) % UINT64_MAX;
+ return hash;
+}

looks strange. `hash` is uint64, but here you return uint32.

based on my understanding of
https://www.postgresql.org/docs/current/xoper-optimization.html#XOPER-COMMUTATOR
I think you need move commutator check right after the `if
(get_op_rettype(opno) != BOOLOID)` branch

+ opno = ((OpExpr *) orqual)->opno;
+ if (get_op_rettype(opno) != BOOLOID)
+ {
+ /* Only operator returning boolean suits OR -> ANY transformation */
+ or_list = lappend(or_list, orqual);
+ continue;
+ }

select po.oprname,po.oprkind,po.oprcanhash,po.oprleft::regtype,po.oprright,po.oprresult,
po1.oprname
from pg_operator po join pg_operator po1
on po.oprcom = po1.oid
where po.oprresult = 16;

I am wondering, are all these types as long as the return type is bool
suitable for this transformation?

#122jian he
jian.universality@gmail.com
In reply to: jian he (#121)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Wed, Jan 31, 2024 at 10:55 AM jian he <jian.universality@gmail.com> wrote:

based on my understanding of
https://www.postgresql.org/docs/current/xoper-optimization.html#XOPER-COMMUTATOR
I think you need move commutator check right after the `if
(get_op_rettype(opno) != BOOLOID)` branch

I was wrong about this part. sorry for the noise.

I have made some changes (attachment).
* if the operator expression left or right side type category is
{array | domain | composite}, then don't do the transformation.
(i am not 10% sure with composite)

* if the left side of the operator expression node contains volatile
functions, then don't do the transformation.

* some other minor cosmetic changes.

Attachments:

v14_comments.no-cfbotapplication/octet-stream; name=v14_comments.no-cfbotDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 6b4b00eb..fb199230 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -202,6 +202,7 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
 		OrClauseGroupKey		hashkey;
 		bool					found;
 		Oid						opno;
+		TYPCATEGORY 			category;
 		Node				   *leftop, *rightop;
 
 		/* At first, transform the arg and evaluate constant expressions. */
@@ -243,7 +244,7 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
 
 			if (!OidIsValid(opno))
 			{
-				/* Commuter doesn't exist, we can't reverse the order */
+				/* commutator doesn't exist, we can't reverse the order */
 				or_list = lappend(or_list, orqual);
 				continue;
 			}
@@ -262,6 +263,33 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
 			continue;
 		}
 
+		/* transformation only works with both side type is not { array | compoiste | domain } */
+		category = TypeCategory(exprType(const_expr));
+		if (category == TYPCATEGORY_ARRAY || category == TYPTYPE_DOMAIN
+			|| category == TYPTYPE_COMPOSITE)
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		category = TypeCategory(exprType(nconst_expr));
+		if (category == TYPCATEGORY_ARRAY || category == TYPTYPE_DOMAIN
+			|| category == TYPTYPE_COMPOSITE)
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * if the non-const (left side of operator expression) contain voltain functions
+		 * then we cannot do the transformation
+		*/
+		if (contain_volatile_functions((Node *) nconst_expr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
 		/*
 		* At this point we definitely have a transformable clause.
 		* Classify it and add into specific group of clauses, or create new
@@ -333,7 +361,7 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
 		else
 			array_type = InvalidOid;
 
-		if (array_type != InvalidOid)
+		if (OidIsValid(array_type))
 		{
 			/*
 			 * OK: coerce all the right-hand non-Var inputs to the common
@@ -392,8 +420,10 @@ transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
 		else
 		{
 			/*
-			 * This part works on intarray test (OR there is made on
-			 * elements of a custom type)
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
 			 */
 			list_free(entry->consts);
 			or_list = list_concat(or_list, entry->exprs);
#123Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: jian he (#122)
Re: POC, WIP: OR-clause support for indexes

Hi, thank you for your review and interest in this subject.

On 31.01.2024 13:15, jian he wrote:

On Wed, Jan 31, 2024 at 10:55 AM jian he<jian.universality@gmail.com> wrote:

based on my understanding of
https://www.postgresql.org/docs/current/xoper-optimization.html#XOPER-COMMUTATOR
I think you need move commutator check right after the `if
(get_op_rettype(opno) != BOOLOID)` branch

I was wrong about this part. sorry for the noise.

I have made some changes (attachment).
* if the operator expression left or right side type category is
{array | domain | composite}, then don't do the transformation.
(i am not 10% sure with composite)

To be honest, I'm not sure about this check, because we check the type
of variable there:

if (!IsA(orqual, OpExpr))
        {
            or_list = lappend(or_list, orqual);
            continue;
        }
And below:
if (IsA(leftop, Const))
        {
            opno = get_commutator(opno);

            if (!OidIsValid(opno))
            {
                /* Commuter doesn't exist, we can't reverse the order */
                or_list = lappend(or_list, orqual);
                continue;
            }

            nconst_expr = get_rightop(orqual);
            const_expr = get_leftop(orqual);
        }
        else if (IsA(rightop, Const))
        {
            const_expr = get_rightop(orqual);
            nconst_expr = get_leftop(orqual);
        }
        else
        {
            or_list = lappend(or_list, orqual);
            continue;
        }

Isn't that enough?

Besides, some of examples (with ARRAY) works fine:

postgres=# CREATE TABLE sal_emp (
    pay_by_quarter  integer[],
    pay_by_quater1 integer[]
);
CREATE TABLE
postgres=# INSERT INTO sal_emp
    VALUES (
    '{10000, 10000, 10000, 10000}',
    '{1,2,3,4}');
INSERT 0 1
postgres=# select * from sal_emp where pay_by_quarter[1] = 10000 or
pay_by_quarter[1]=2;
      pay_by_quarter       | pay_by_quater1
---------------------------+----------------
 {10000,10000,10000,10000} | {1,2,3,4}
(1 row)

postgres=# explain select * from sal_emp where pay_by_quarter[1] = 10000
or pay_by_quarter[1]=2;
                          QUERY PLAN
--------------------------------------------------------------
 Seq Scan on sal_emp  (cost=0.00..21.00 rows=9 width=64)
   Filter: (pay_by_quarter[1] = ANY ('{10000,2}'::integer[]))
(2 rows)

* if the left side of the operator expression node contains volatile
functions, then don't do the transformation.

I'm also not sure about the volatility check function, because we
perform such a conversion at the parsing stage, and at this stage we
don't have a RelOptInfo variable and especially a RestictInfo such as
PathTarget.

Speaking of NextValueExpr, I couldn't find any examples where the
current patch wouldn't work. I wrote one of them below:

postgres=# create table foo (f1 int, f2 int generated always as identity);
CREATE TABLE
postgres=# insert into foo values(1);
INSERT 0 1

postgres=# explain verbose update foo set f1 = 2 where f1=1 or f1=2 ;
                            QUERY PLAN
-------------------------------------------------------------------
 Update on public.foo  (cost=0.00..38.25 rows=0 width=0)
   ->  Seq Scan on public.foo  (cost=0.00..38.25 rows=23 width=10)
         Output: 2, ctid
         Filter: (foo.f1 = ANY ('{1,2}'::integer[]))
(4 rows)

Maybe I missed something. Do you have any examples?

* some other minor cosmetic changes.

Thank you, I agree with them.

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#124jian he
jian.universality@gmail.com
In reply to: Alena Rybakina (#123)
Re: POC, WIP: OR-clause support for indexes

On Wed, Jan 31, 2024 at 7:10 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

Hi, thank you for your review and interest in this subject.

On 31.01.2024 13:15, jian he wrote:

On Wed, Jan 31, 2024 at 10:55 AM jian he <jian.universality@gmail.com> wrote:

based on my understanding of
https://www.postgresql.org/docs/current/xoper-optimization.html#XOPER-COMMUTATOR
I think you need move commutator check right after the `if
(get_op_rettype(opno) != BOOLOID)` branch

I was wrong about this part. sorry for the noise.

I have made some changes (attachment).
* if the operator expression left or right side type category is
{array | domain | composite}, then don't do the transformation.
(i am not 10% sure with composite)

To be honest, I'm not sure about this check, because we check the type of variable there:

if (!IsA(orqual, OpExpr))
{
or_list = lappend(or_list, orqual);
continue;
}
And below:
if (IsA(leftop, Const))
{
opno = get_commutator(opno);

if (!OidIsValid(opno))
{
/* Commuter doesn't exist, we can't reverse the order */
or_list = lappend(or_list, orqual);
continue;
}

nconst_expr = get_rightop(orqual);
const_expr = get_leftop(orqual);
}
else if (IsA(rightop, Const))
{
const_expr = get_rightop(orqual);
nconst_expr = get_leftop(orqual);
}
else
{
or_list = lappend(or_list, orqual);
continue;
}

Isn't that enough?

alter table tenk1 add column arr int[];
set enable_or_transformation to on;
EXPLAIN (COSTS OFF)
SELECT count(*) FROM tenk1
WHERE arr = '{1,2,3}' or arr = '{1,2}';

the above query will not do the OR transformation. because array type
doesn't have array type.
`
scalar_type = entry->key.exprtype;
if (scalar_type != RECORDOID && OidIsValid(scalar_type))
array_type = get_array_type(scalar_type);
else
array_type = InvalidOid;
`

If either side of the operator expression is array or array related type,
we can be sure it cannot do the transformation
(get_array_type will return InvalidOid for anyarray type).
we can check it earlier, so hash related code will not be invoked for
array related types.

Besides, some of examples (with ARRAY) works fine:

postgres=# CREATE TABLE sal_emp (
pay_by_quarter integer[],
pay_by_quater1 integer[]
);
CREATE TABLE
postgres=# INSERT INTO sal_emp
VALUES (
'{10000, 10000, 10000, 10000}',
'{1,2,3,4}');
INSERT 0 1
postgres=# select * from sal_emp where pay_by_quarter[1] = 10000 or pay_by_quarter[1]=2;
pay_by_quarter | pay_by_quater1
---------------------------+----------------
{10000,10000,10000,10000} | {1,2,3,4}
(1 row)

postgres=# explain select * from sal_emp where pay_by_quarter[1] = 10000 or pay_by_quarter[1]=2;
QUERY PLAN
--------------------------------------------------------------
Seq Scan on sal_emp (cost=0.00..21.00 rows=9 width=64)
Filter: (pay_by_quarter[1] = ANY ('{10000,2}'::integer[]))
(2 rows)

* if the left side of the operator expression node contains volatile
functions, then don't do the transformation.

I'm also not sure about the volatility check function, because we perform such a conversion at the parsing stage, and at this stage we don't have a RelOptInfo variable and especially a RestictInfo such as PathTarget.

see the example in here:
/messages/by-id/CACJufxGXhJ823cdAdp2Ho7qC-HZ3_-dtdj-myaAi_u9RQLn45g@mail.gmail.com

set enable_or_transformation to on;
create or replace function retint(int) returns int as
$func$
begin raise notice 'hello';
return $1 + round(10 * random()); end
$func$ LANGUAGE plpgsql;

SELECT count(*) FROM tenk1 WHERE thousand = 42;
will return 10 rows.

SELECT count(*) FROM tenk1 WHERE thousand = 42 AND (retint(1) = 4 OR
retint(1) = 3);
this query I should return 20 notices 'hello', but now only 10.

EXPLAIN (COSTS OFF)
SELECT count(*) FROM tenk1
WHERE thousand = 42 AND (retint(1) = 4 OR retint(1) = 3);
QUERY PLAN
------------------------------------------------------------------------------
Aggregate
-> Seq Scan on tenk1
Filter: ((thousand = 42) AND (retint(1) = ANY ('{4,3}'::integer[])))
(3 rows)

#125Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: jian he (#124)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 01.02.2024 08:00, jian he wrote:

On Wed, Jan 31, 2024 at 7:10 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

Hi, thank you for your review and interest in this subject.

On 31.01.2024 13:15, jian he wrote:

On Wed, Jan 31, 2024 at 10:55 AM jian he<jian.universality@gmail.com> wrote:

based on my understanding of
https://www.postgresql.org/docs/current/xoper-optimization.html#XOPER-COMMUTATOR
I think you need move commutator check right after the `if
(get_op_rettype(opno) != BOOLOID)` branch

I was wrong about this part. sorry for the noise.

I have made some changes (attachment).
* if the operator expression left or right side type category is
{array | domain | composite}, then don't do the transformation.
(i am not 10% sure with composite)

To be honest, I'm not sure about this check, because we check the type of variable there:

if (!IsA(orqual, OpExpr))
{
or_list = lappend(or_list, orqual);
continue;
}
And below:
if (IsA(leftop, Const))
{
opno = get_commutator(opno);

if (!OidIsValid(opno))
{
/* Commuter doesn't exist, we can't reverse the order */
or_list = lappend(or_list, orqual);
continue;
}

nconst_expr = get_rightop(orqual);
const_expr = get_leftop(orqual);
}
else if (IsA(rightop, Const))
{
const_expr = get_rightop(orqual);
nconst_expr = get_leftop(orqual);
}
else
{
or_list = lappend(or_list, orqual);
continue;
}

Isn't that enough?

alter table tenk1 add column arr int[];
set enable_or_transformation to on;
EXPLAIN (COSTS OFF)
SELECT count(*) FROM tenk1
WHERE arr = '{1,2,3}' or arr = '{1,2}';

the above query will not do the OR transformation. because array type
doesn't have array type.
`
scalar_type = entry->key.exprtype;
if (scalar_type != RECORDOID && OidIsValid(scalar_type))
array_type = get_array_type(scalar_type);
else
array_type = InvalidOid;
`

If either side of the operator expression is array or array related type,
we can be sure it cannot do the transformation
(get_array_type will return InvalidOid for anyarray type).
we can check it earlier, so hash related code will not be invoked for
array related types.

Agree.

Besides, some of examples (with ARRAY) works fine:

postgres=# CREATE TABLE sal_emp (
pay_by_quarter integer[],
pay_by_quater1 integer[]
);
CREATE TABLE
postgres=# INSERT INTO sal_emp
VALUES (
'{10000, 10000, 10000, 10000}',
'{1,2,3,4}');
INSERT 0 1
postgres=# select * from sal_emp where pay_by_quarter[1] = 10000 or pay_by_quarter[1]=2;
pay_by_quarter | pay_by_quater1
---------------------------+----------------
{10000,10000,10000,10000} | {1,2,3,4}
(1 row)

postgres=# explain select * from sal_emp where pay_by_quarter[1] = 10000 or pay_by_quarter[1]=2;
QUERY PLAN
--------------------------------------------------------------
Seq Scan on sal_emp (cost=0.00..21.00 rows=9 width=64)
Filter: (pay_by_quarter[1] = ANY ('{10000,2}'::integer[]))
(2 rows)

* if the left side of the operator expression node contains volatile
functions, then don't do the transformation.

I'm also not sure about the volatility check function, because we perform such a conversion at the parsing stage, and at this stage we don't have a RelOptInfo variable and especially a RestictInfo such as PathTarget.

see the example in here:
/messages/by-id/CACJufxGXhJ823cdAdp2Ho7qC-HZ3_-dtdj-myaAi_u9RQLn45g@mail.gmail.com

set enable_or_transformation to on;
create or replace function retint(int) returns int as
$func$
begin raise notice 'hello';
return $1 + round(10 * random()); end
$func$ LANGUAGE plpgsql;

SELECT count(*) FROM tenk1 WHERE thousand = 42;
will return 10 rows.

SELECT count(*) FROM tenk1 WHERE thousand = 42 AND (retint(1) = 4 OR
retint(1) = 3);
this query I should return 20 notices 'hello', but now only 10.

EXPLAIN (COSTS OFF)
SELECT count(*) FROM tenk1
WHERE thousand = 42 AND (retint(1) = 4 OR retint(1) = 3);
QUERY PLAN
------------------------------------------------------------------------------
Aggregate
-> Seq Scan on tenk1
Filter: ((thousand = 42) AND (retint(1) = ANY ('{4,3}'::integer[])))
(3 rows)

Agree.

I added your code to the patch.

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

Attachments:

v15-1-0001-Transform-OR-clause-to-ANY-expressions.patchtext/x-patch; charset=UTF-8; name=v15-1-0001-Transform-OR-clause-to-ANY-expressions.patchDownload
From 0fcad72153c9eaaf436e5b417c803a70fbeaf8ac Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Fri, 2 Feb 2024 22:01:09 +0300
Subject: [PATCH] Transform OR clause to ANY expressions.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(C1, C2, ...) on the
preliminary stage of optimization when we are still working with the tree
expression.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
---
 .../postgres_fdw/expected/postgres_fdw.out    |  16 +-
 src/backend/nodes/queryjumblefuncs.c          |  30 ++
 src/backend/parser/parse_expr.c               | 340 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  11 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/bin/pg_dump/t/002_pg_dump.pl              |   6 +-
 src/include/nodes/queryjumble.h               |   1 +
 src/include/parser/parse_expr.h               |   1 +
 src/test/regress/expected/create_index.out    | 156 +++++++-
 src/test/regress/expected/inherit.out         |   2 +-
 src/test/regress/expected/join.out            |  62 +++-
 src/test/regress/expected/partition_prune.out | 219 +++++++++--
 src/test/regress/expected/rules.out           |   4 +-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  35 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 21 files changed, 892 insertions(+), 70 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index b5a38aeb214..a07aefc9e51 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -1349,7 +1349,7 @@ SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE
  Foreign Scan
    Output: t1.c1, t1.c2, ft5.c1, ft5.c2
    Relations: (public.ft4 t1) LEFT JOIN (public.ft5)
-   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 < 10) OR (r4.c1 IS NULL))) AND ((r1.c1 < 10))
+   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 IS NULL) OR (r4.c1 < 10))) AND ((r1.c1 < 10))
 (4 rows)
 
 SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE c1 < 10) t2 ON (t1.c1 = t2.c1)
@@ -3105,7 +3105,7 @@ select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3123,7 +3123,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3140,7 +3140,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST)), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -8797,18 +8797,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index e489bfceb56..4e77cfe925c 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -135,6 +135,36 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	if (*queryId == UINT64CONST(0))
+		*queryId = UINT64CONST(1);
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 9300c7b9abc..fb199230cbf 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,14 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -38,11 +40,13 @@
 #include "utils/date.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +103,340 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function that's compatible with guc_name_compare
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				hash;
+
+	(void) JumbleExpr(key->expr, &hash);
+	hash += ((uint64) key->opno + (uint64) key->exprtype) % UINT64_MAX;
+	return hash;
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in guc_hashtab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
+{
+	List				   *or_list = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(expr->args);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (!enable_or_transformation || expr->boolop != OR_EXPR || len_ors < 2)
+		return transformBoolExpr(pstate, (BoolExpr *) expr);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, expr->args)
+	{
+		Node				   *arg = lfirst(lc);
+		Node				   *orqual;
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		TYPCATEGORY 			category;
+		Node				   *leftop, *rightop;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/* transformation only works with both side type is not { array | compoiste | domain } */
+		category = TypeCategory(exprType(const_expr));
+		if (category == TYPCATEGORY_ARRAY || category == TYPTYPE_DOMAIN
+			|| category == TYPTYPE_COMPOSITE)
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		category = TypeCategory(exprType(nconst_expr));
+		if (category == TYPCATEGORY_ARRAY || category == TYPTYPE_DOMAIN
+			|| category == TYPTYPE_COMPOSITE)
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * if the non-const (left side of operator expression) contain voltain functions
+		 * then we cannot do the transformation
+		*/
+		if (contain_volatile_functions((Node *) nconst_expr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.exprtype = exprType(nconst_expr);
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->node = nconst_expr;
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element in the class. Return origin expression into
+			 * the BoolExpr args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.exprtype;
+		if (scalar_type != RECORDOID && OidIsValid(scalar_type))
+			array_type = get_array_type(scalar_type);
+		else
+			array_type = InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+			ListCell		   *lc1;
+
+			foreach(lc1, entry->consts)
+			{
+				Node   *rexpr = (Node *) lfirst(lc1);
+
+				rexpr = coerce_to_common_type(pstate, rexpr,
+											  scalar_type,
+											  "IN");
+				aexprs = lappend(aexprs, rexpr);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 entry->node,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, expr->location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +550,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 7fe58518d7d..ddda2d3c488 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1071,6 +1071,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index da10b43dac3..6876d73392a 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -379,6 +379,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 00b5092713d..d28bf617dbe 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -2095,9 +2095,9 @@ my %tests = (
 		regexp => qr/^
 			\QCREATE DOMAIN dump_test.us_postal_code AS text COLLATE pg_catalog."C" DEFAULT '10014'::text\E\n\s+
 			\QCONSTRAINT us_postal_code_check CHECK \E
-			\Q(((VALUE ~ '^\d{5}\E
-			\$\Q'::text) OR (VALUE ~ '^\d{5}-\d{4}\E\$
-			\Q'::text)));\E(.|\n)*
+			\Q((VALUE ~ ANY (ARRAY['^\d{5}\E
+			\$\Q'::text, '^\d{5}-\d{4}\E\$
+			\Q'::text])));\E(.|\n)*
 			\QCOMMENT ON CONSTRAINT us_postal_code_check ON DOMAIN dump_test.us_postal_code IS 'check it';\E
 			/xm,
 		like =>
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067f..a9ae048af52 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 9b46dfd9ecc..4ff4adc77d2 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -17,6 +17,7 @@
 
 /* GUC parameters */
 extern PGDLLIMPORT bool Transform_null_equals;
+extern PGDLLIMPORT bool enable_or_transformation;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 79fa117cb54..b8653c09ea2 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,116 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 130a9242288..684886336cd 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -2600,7 +2600,7 @@ explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd'
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9c08d0134ca..256ed8acb5c 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 < 20) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 < 20) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c0556..3423af47684 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -589,20 +611,20 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 ------------------------------------------------------
  Append
    ->  Seq Scan on rlp1 rlp_1
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
    ->  Seq Scan on rlp4_1 rlp_2
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
 (5 rows)
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -1933,10 +2112,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index abc944e8b82..3ec614c4376 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2500,7 +2500,7 @@ pg_stats| SELECT n.nspname AS schemaname,
      JOIN pg_class c ON ((c.oid = s.starelid)))
      JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
-  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2531,7 +2531,7 @@ pg_stats_ext| SELECT cn.nspname AS schemaname,
   WHERE ((NOT (EXISTS ( SELECT 1
            FROM (unnest(s.stxkeys) k(k)
              JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
-          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext_exprs| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 10903bdab09..6f55b9e3ec1 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 9be7aca2b8a..1f9029b5b2a 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -124,6 +124,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -134,7 +135,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(23 rows)
+(24 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..2a079e996b2 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..56fde15bc15 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index e1db2025db6..353deecef03 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827f..1e270ae9c06 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..0499bedb9eb 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 91433d439b7..adae668b370 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1654,6 +1654,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

#126Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#125)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 3/2/2024 02:06, Alena Rybakina wrote:

On 01.02.2024 08:00, jian he wrote:
I added your code to the patch.

Thanks Alena and Jian for the detailed scrutiny!

A couple of questions:
1. As I see, transformAExprIn uses the same logic as we invented but
allows composite and domain types. Could you add a comment explaining
why we forbid row types in general, in contrast to the transformAExprIn
routine?
2. Could you provide the tests to check issues covered by the recent (in
v.15) changes?

Patch 0001-* in the attachment incorporates changes induced by Jian's
notes from [1]/messages/by-id/CACJufxGXhJ823cdAdp2Ho7qC-HZ3_-dtdj-myaAi_u9RQLn45g@mail.gmail.com.
Patch 0002-* contains a transformation of the SAOP clause, which allows
the optimizer to utilize partial indexes if they cover all values in
this array. Also, it is an answer to Alexander's note [2]/messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.com on performance
degradation. This first version may be a bit raw, but I need your
opinion: Does it resolve the issue?

Skimming through the thread, I see that, in general, all issues have
been covered for now. Only Robert's note on a lack of documentation is
still needs to be resolved.

[1]: /messages/by-id/CACJufxGXhJ823cdAdp2Ho7qC-HZ3_-dtdj-myaAi_u9RQLn45g@mail.gmail.com
/messages/by-id/CACJufxGXhJ823cdAdp2Ho7qC-HZ3_-dtdj-myaAi_u9RQLn45g@mail.gmail.com
[2]: /messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.com
/messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.com

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v16-0001-Transform-OR-clause-to-ANY-expressions.patchtext/plain; charset=UTF-8; name=v16-0001-Transform-OR-clause-to-ANY-expressions.patchDownload
From 0ac511ab94959e87d1525d5ea8c4855643a6ccbe Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Fri, 2 Feb 2024 22:01:09 +0300
Subject: [PATCH 1/2] Transform OR clause to ANY expressions.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(C1, C2, ...) on the
preliminary stage of optimization when we are still working with the tree
expression.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
---
 .../postgres_fdw/expected/postgres_fdw.out    |  16 +-
 src/backend/nodes/queryjumblefuncs.c          |  27 ++
 src/backend/parser/parse_expr.c               | 327 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  11 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/bin/pg_dump/t/002_pg_dump.pl              |   6 +-
 src/include/nodes/queryjumble.h               |   1 +
 src/include/optimizer/optimizer.h             |   1 +
 src/test/regress/expected/create_index.out    | 156 ++++++++-
 src/test/regress/expected/inherit.out         |   2 +-
 src/test/regress/expected/join.out            |  62 +++-
 src/test/regress/expected/partition_prune.out | 219 ++++++++++--
 src/test/regress/expected/rules.out           |   4 +-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  35 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 21 files changed, 876 insertions(+), 70 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index b5a38aeb21..a07aefc9e5 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -1349,7 +1349,7 @@ SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE
  Foreign Scan
    Output: t1.c1, t1.c2, ft5.c1, ft5.c2
    Relations: (public.ft4 t1) LEFT JOIN (public.ft5)
-   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 < 10) OR (r4.c1 IS NULL))) AND ((r1.c1 < 10))
+   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 IS NULL) OR (r4.c1 < 10))) AND ((r1.c1 < 10))
 (4 rows)
 
 SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE c1 < 10) t2 ON (t1.c1 = t2.c1)
@@ -3105,7 +3105,7 @@ select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3123,7 +3123,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3140,7 +3140,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST)), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -8797,18 +8797,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index e489bfceb5..ee3d67c832 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -135,6 +135,33 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 9300c7b9ab..598bab7d1f 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,14 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -38,11 +40,13 @@
 #include "utils/date.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +103,327 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+
+	Node		   *node;
+	List		   *consts;
+	Oid				scalar_type;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function to find candidate clauses.
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				hash;
+
+	Assert(keysize == sizeof(OrClauseGroupKey));
+
+	(void) JumbleExpr(key->expr, &hash);
+	hash += ((uint64) key->opno + (uint64) key->exprtype);
+	return (uint32) (hash % UINT32_MAX);
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in guc_hashtab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
+{
+	List				   *or_list = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(expr->args);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (!enable_or_transformation || expr->boolop != OR_EXPR || len_ors < 2)
+		return transformBoolExpr(pstate, (BoolExpr *) expr);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, expr->args)
+	{
+		Node				   *arg = lfirst(lc);
+		Node				   *orqual;
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Oid						exprtype;
+		Node				   *leftop, *rightop;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Transformation only works with both side type is not
+		 * { array | composite | domain | record }.
+		 * Also, forbid it for volatile expressions.
+		 */
+		exprtype = exprType(nconst_expr);
+		if (type_is_rowtype(exprType(const_expr)) ||
+			type_is_rowtype(exprtype) ||
+			contain_volatile_functions((Node *) nconst_expr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.exprtype = exprtype;
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->node = nconst_expr;
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element in the class. Return origin expression into
+			 * the BoolExpr args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.exprtype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+											   InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+			ListCell		   *lc1;
+
+			foreach(lc1, entry->consts)
+			{
+				Node   *rexpr = (Node *) lfirst(lc1);
+
+				rexpr = coerce_to_common_type(pstate, rexpr,
+											  scalar_type,
+											  "IN");
+				aexprs = lappend(aexprs, rexpr);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 entry->node,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, expr->location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +537,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 7fe58518d7..ddda2d3c48 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1071,6 +1071,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index da10b43dac..6876d73392 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -379,6 +379,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 00b5092713..d28bf617db 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -2095,9 +2095,9 @@ my %tests = (
 		regexp => qr/^
 			\QCREATE DOMAIN dump_test.us_postal_code AS text COLLATE pg_catalog."C" DEFAULT '10014'::text\E\n\s+
 			\QCONSTRAINT us_postal_code_check CHECK \E
-			\Q(((VALUE ~ '^\d{5}\E
-			\$\Q'::text) OR (VALUE ~ '^\d{5}-\d{4}\E\$
-			\Q'::text)));\E(.|\n)*
+			\Q((VALUE ~ ANY (ARRAY['^\d{5}\E
+			\$\Q'::text, '^\d{5}-\d{4}\E\$
+			\Q'::text])));\E(.|\n)*
 			\QCOMMENT ON CONSTRAINT us_postal_code_check ON DOMAIN dump_test.us_postal_code IS 'check it';\E
 			/xm,
 		like =>
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067..a9ae048af5 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 7b63c5cf71..35ab577501 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -50,6 +50,7 @@ struct PlannedStmt;
 struct ParamListInfoData;
 struct HeapTupleData;
 
+extern PGDLLIMPORT bool enable_or_transformation;
 
 /* in path/clausesel.c: */
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 79fa117cb5..b8653c09ea 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,116 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 130a924228..684886336c 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -2600,7 +2600,7 @@ explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd'
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9c08d0134c..256ed8acb5 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 < 20) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 < 20) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c055..3423af4768 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -589,20 +611,20 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 ------------------------------------------------------
  Append
    ->  Seq Scan on rlp1 rlp_1
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
    ->  Seq Scan on rlp4_1 rlp_2
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
 (5 rows)
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -1933,10 +2112,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index abc944e8b8..3ec614c437 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2500,7 +2500,7 @@ pg_stats| SELECT n.nspname AS schemaname,
      JOIN pg_class c ON ((c.oid = s.starelid)))
      JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
-  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2531,7 +2531,7 @@ pg_stats_ext| SELECT cn.nspname AS schemaname,
   WHERE ((NOT (EXISTS ( SELECT 1
            FROM (unnest(s.stxkeys) k(k)
              JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
-          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext_exprs| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 10903bdab0..6f55b9e3ec 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 9be7aca2b8..1f9029b5b2 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -124,6 +124,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -134,7 +135,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(23 rows)
+(24 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..2a079e996b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..56fde15bc1 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index e1db2025db..353deecef0 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827..1e270ae9c0 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 91433d439b..adae668b37 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1654,6 +1654,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.43.0

v16-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchtext/plain; charset=UTF-8; name=v16-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchDownload
From 2b157a43fa2e88650cc3b25c523068b15ac99ea6 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Wed, 24 Jan 2024 14:07:17 +0700
Subject: [PATCH 2/2] Teach generate_bitmap_or_paths to build BitmapOr paths
 over SAOP clauses.

Likewise OR clauses, discover SAOP array and try to split its elements
between smaller sized arrays to fit a set of partial indexes.
---
 src/backend/optimizer/path/indxpath.c     | 272 +++++++++++++++++----
 src/backend/optimizer/util/clauses.c      |   1 +
 src/backend/optimizer/util/predtest.c     |  94 ++++++++
 src/backend/optimizer/util/restrictinfo.c |  13 +
 src/include/optimizer/optimizer.h         |  10 +
 src/include/optimizer/restrictinfo.h      |   1 +
 src/test/regress/expected/select.out      | 282 ++++++++++++++++++++++
 src/test/regress/sql/select.sql           |  82 +++++++
 8 files changed, 702 insertions(+), 53 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 32c6a8bbdc..7062ec57dd 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1220,11 +1220,146 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Building index paths over SAOP clause differs from the logic of OR clauses.
+ * Here we iterate across all the array elements and split them to SAOPs,
+ * corresponding to different indexes. We must match each element to an index.
+ */
+static List *
+build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
+					 List *other_clauses)
+{
+	List			   *result = NIL;
+	List			   *predicate_lists = NIL;
+	ListCell		   *lc;
+	PredicatesData	   *pd;
+	ScalarArrayOpExpr  *saop = (ScalarArrayOpExpr *) rinfo->clause;
+
+	Assert(saop->useOr);
+
+	/* Collect predicates */
+	foreach(lc, rel->indexlist)
+	{
+		IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
+
+		/* Take into consideration partial indexes supporting bitmap scans */
+		if (!index->amhasgetbitmap || index->indpred == NIL || index->predOK)
+			continue;
+
+		pd = palloc0(sizeof(PredicatesData));
+		pd->id = foreach_current_index(lc);
+		/* The trick with reducing recursion is stolen from predicate_implied_by */
+		pd->predicate = list_length(index->indpred) == 1 ?
+										(Node *) linitial(index->indpred) :
+										(Node *) index->indpred;
+		predicate_lists = lappend(predicate_lists, (void *) pd);
+	}
+
+	/* Split the array data according to index predicates. */
+	if (predicate_lists == NIL ||
+		!saop_covered_by_predicates(saop, predicate_lists))
+		return NIL;
+
+	other_clauses = list_delete_ptr(other_clauses, rinfo);
+
+	foreach(lc, predicate_lists)
+	{
+		PredicatesData *pd = (PredicatesData *) lfirst(lc);
+		IndexOptInfo   *index;
+		IndexClauseSet	clauseset;
+		List		   *indexpaths;
+		RestrictInfo   *rinfo1;
+		Expr		   *clause;
+
+		if (pd->elems == NIL)
+			continue;
+
+		index = list_nth(rel->indexlist, pd->id);
+		clause = (Expr *) estimate_expression_value(root, (Node *) pd->saop);
+
+		/*
+		 * Create new RestrictInfo. It maybe more heavy than just copy node, but
+		 * remember some internals: the serial number, selectivity cache etc.
+		 */
+		rinfo1 = make_restrictinfo(root, clause,
+								   rinfo->is_pushed_down,
+								   rinfo->has_clone,
+								   rinfo->is_clone,
+								   rinfo->pseudoconstant,
+								   rinfo->security_level,
+								   rinfo->required_relids,
+								   rinfo->incompatible_relids,
+								   rinfo->outer_relids);
+
+		if (!predicate_implied_by(index->indpred, list_make1(rinfo1), true))
+			elog(ERROR, "Logical mistake in OR <-> ANY transformation code");
+
+		if (predicate_implied_by(index->indpred, other_clauses, false))
+			return NIL;
+
+		/* Time to generate index paths */
+		MemSet(&clauseset, 0, sizeof(clauseset));
+		match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);
+		match_clauses_to_index(root, other_clauses, index, &clauseset);
+
+		/* Predicate has found already. So, it is ok for the empty match */
+
+		/*
+		 * Construct paths if possible.
+		 */
+		indexpaths = build_index_paths(root, rel,
+									   index, &clauseset,
+									   true,
+									   ST_BITMAPSCAN,
+									   NULL,
+									   NULL);
+		result = lappend(result, indexpaths);
+	}
+	return result;
+}
+
+static List *
+generate_saop_pathlist(PlannerInfo *root, RelOptInfo *rel,
+					   RestrictInfo *rinfo, List *all_clauses)
+{
+	List	   *pathlist = NIL;
+	Path	   *bitmapqual;
+	List	   *indlist;
+	ListCell   *lc;
+
+	if (!enable_or_transformation)
+		return NIL;
+
+
+	/*
+	 * We must be able to match at least one index to each element of
+	 * the array, else we can't use it.
+	 */
+	indlist = build_paths_for_SAOP(root, rel, rinfo, all_clauses);
+	if (indlist == NIL)
+		return NIL;
+
+	/*
+	 * OK, pick the most promising AND combination, and add it to
+	 * pathlist.
+	 */
+	foreach (lc, indlist)
+	{
+		List *plist = lfirst_node(List, lc);
+
+		bitmapqual = choose_bitmap_and(root, rel, plist);
+		pathlist = lappend(pathlist, bitmapqual);
+	}
+
+	return pathlist;
+}
+
 /*
  * generate_bitmap_or_paths
- *		Look through the list of clauses to find OR clauses, and generate
- *		a BitmapOrPath for each one we can handle that way.  Return a list
- *		of the generated BitmapOrPaths.
+ *		Look through the list of clauses to find OR and SAOP clauses, and
+ *		Each saop clause are splitted to be covered by partial indexes.
+ *		generate a BitmapOrPath for each one we can handle that way.
+ *		Return a list of the generated BitmapOrPaths.
  *
  * other_clauses is a list of additional clauses that can be assumed true
  * for the purpose of generating indexquals, but are not to be searched for
@@ -1247,68 +1382,99 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	foreach(lc, clauses)
 	{
 		RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
-		List	   *pathlist;
+		List	   *pathlist = NIL;
 		Path	   *bitmapqual;
 		ListCell   *j;
 
-		/* Ignore RestrictInfos that aren't ORs */
-		if (!restriction_is_or_clause(rinfo))
+		if (restriction_is_saop_clause(rinfo))
+		{
+			pathlist = generate_saop_pathlist(root, rel, rinfo,
+											  all_clauses);
+		}
+		else if (!restriction_is_or_clause(rinfo))
+			/* Ignore RestrictInfos that aren't ORs */
 			continue;
-
-		/*
-		 * We must be able to match at least one index to each of the arms of
-		 * the OR, else we can't use it.
-		 */
-		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		else
 		{
-			Node	   *orarg = (Node *) lfirst(j);
-			List	   *indlist;
-
-			/* OR arguments should be ANDs or sub-RestrictInfos */
-			if (is_andclause(orarg))
+			/*
+			 * We must be able to match at least one index to each of the arms of
+			 * the OR, else we can't use it.
+			 */
+			foreach(j, ((BoolExpr *) rinfo->orclause)->args)
 			{
-				List	   *andargs = ((BoolExpr *) orarg)->args;
+				Node	   *orarg = (Node *) lfirst(j);
+				List	   *indlist;
 
-				indlist = build_paths_for_OR(root, rel,
-											 andargs,
-											 all_clauses);
+				/* OR arguments should be ANDs or sub-RestrictInfos */
+				if (is_andclause(orarg))
+				{
+					List	   *andargs = ((BoolExpr *) orarg)->args;
 
-				/* Recurse in case there are sub-ORs */
-				indlist = list_concat(indlist,
-									  generate_bitmap_or_paths(root, rel,
-															   andargs,
-															   all_clauses));
-			}
-			else
-			{
-				RestrictInfo *ri = castNode(RestrictInfo, orarg);
-				List	   *orargs;
+					indlist = build_paths_for_OR(root, rel,
+												 andargs,
+												 all_clauses);
 
-				Assert(!restriction_is_or_clause(ri));
-				orargs = list_make1(ri);
+					/* Recurse in case there are sub-ORs */
+					indlist = list_concat(indlist,
+										  generate_bitmap_or_paths(root, rel,
+																   andargs,
+																   all_clauses));
+				}
+				else
+				{
+					RestrictInfo *ri = castNode(RestrictInfo, orarg);
+					List	   *orargs;
 
-				indlist = build_paths_for_OR(root, rel,
-											 orargs,
-											 all_clauses);
-			}
+					Assert(!restriction_is_or_clause(ri));
 
-			/*
-			 * If nothing matched this arm, we can't do anything with this OR
-			 * clause.
-			 */
-			if (indlist == NIL)
-			{
-				pathlist = NIL;
-				break;
-			}
+					orargs = list_make1(ri);
 
-			/*
-			 * OK, pick the most promising AND combination, and add it to
-			 * pathlist.
-			 */
-			bitmapqual = choose_bitmap_and(root, rel, indlist);
-			pathlist = lappend(pathlist, bitmapqual);
+					if (restriction_is_saop_clause(ri))
+					{
+						List *paths;
+
+						paths = generate_saop_pathlist(root, rel, ri,
+														 all_clauses);
+
+						if (paths != NIL)
+						{
+							/*
+							 * Add paths to pathlist and immediately jump to the
+							 * next element of the OR clause.
+							 */
+							pathlist = list_concat(pathlist, paths);
+							continue;
+						}
+
+						/*
+						 * Pass down out of this if construction:
+						 * If saop isn't covered by partial indexes, try to
+						 * build scan path for the saop as a whole.
+						 */
+					}
+
+					indlist = build_paths_for_OR(root, rel,
+												 orargs,
+												 all_clauses);
+				}
+
+				/*
+				 * If nothing matched this arm, we can't do anything with this OR
+				 * clause.
+				 */
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+
+				/*
+				 * OK, pick the most promising AND combination, and add it to
+				 * pathlist.
+				 */
+				bitmapqual = choose_bitmap_and(root, rel, indlist);
+				pathlist = lappend(pathlist, bitmapqual);
+			}
 		}
 
 		/*
diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c
index 94eb56a1e7..35a46ca979 100644
--- a/src/backend/optimizer/util/clauses.c
+++ b/src/backend/optimizer/util/clauses.c
@@ -3708,6 +3708,7 @@ contain_non_const_walker(Node *node, void *context)
 	if (IsA(node, List))
 		return expression_tree_walker(node, contain_non_const_walker, context);
 	/* Otherwise, abort the tree traversal and return true */
+
 	return true;
 }
 
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index c37b416e24..274fac8a3a 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -112,6 +112,100 @@ static Oid	get_btree_test_op(Oid pred_op, Oid clause_op, bool refute_it);
 static void InvalidateOprProofCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
 
 
+/*
+ * Could this ANY () expression can be split into a set of ANYs over partial
+ * indexes? If yes, return these saops in the PredicatesData structure.
+ */
+bool
+saop_covered_by_predicates(ScalarArrayOpExpr *saop, List *predicate_lists)
+{
+	ListCell		   *lc;
+	PredIterInfoData	clause_info;
+	bool				result = false;
+	bool				isConstArray;
+
+	Assert(IsA(saop, ScalarArrayOpExpr));
+
+	if (predicate_classify((Node *) saop, &clause_info) != CLASS_OR)
+		return false;
+
+	iterate_begin(pitem, (Node *) saop, clause_info)
+	{
+		result = false;
+
+		foreach(lc, predicate_lists)
+		{
+			PredicatesData *pd = (PredicatesData *) lfirst(lc);
+
+			if (!predicate_implied_by_recurse(pitem, pd->predicate, false))
+				continue;
+
+			/* Predicate is found. Add the elem to the saop clause */
+			Assert(IsA(pitem, OpExpr));
+
+			/* Extract constant from the expression */
+			pd->elems = lappend(pd->elems,
+					copyObject(lsecond_node(Const, ((OpExpr *) pitem)->args)));
+			result = true;
+			break;
+		}
+
+		if (!result)
+			/*
+			 * The element doesn't fit any index. Interrupt the process immediately
+			 */
+			break;
+	}
+	iterate_end(clause_info);
+
+	if (!result)
+		return false;
+
+	/* Build saops, separately for each index */
+	isConstArray = IsA(lsecond(saop->args), Const) ? true : false;
+
+	foreach(lc, predicate_lists)
+	{
+		PredicatesData *pd = (PredicatesData *) lfirst(lc);
+		ArrayType	   *arrayval = NULL;
+		ArrayExpr	   *c = NULL;
+
+		if (pd->elems == NIL)
+			continue;
+
+		if (isConstArray)
+		{
+			Const	   *arrayconst = lsecond_node(Const, saop->args);
+
+			arrayval = DatumGetArrayTypeP(arrayconst->constvalue);
+			c = makeNode(ArrayExpr);
+			c->array_collid = arrayconst->constcollid;
+			c->array_typeid = arrayconst->consttype;
+			c->element_typeid = arrayval->elemtype;
+			c->elements = pd->elems;
+			c->location = -1;
+			c->multidims = false;
+		}
+		else
+		{
+			Assert(IsA(lsecond(saop->args), ArrayExpr));
+		}
+
+		if (pd->saop == NULL)
+		{
+			/* First time initialization */
+			pd->saop = makeNode(ScalarArrayOpExpr);
+			memcpy(pd->saop, saop, sizeof(ScalarArrayOpExpr));
+			Assert(IsA(lsecond(saop->args), ArrayExpr) ||
+				   IsA(lsecond(saop->args), Const));
+			Assert(c != NULL);
+			pd->saop->args = list_make2(linitial(saop->args), c);
+		}
+	}
+
+	return true;
+}
+
 /*
  * predicate_implied_by
  *	  Recursively checks whether the clauses in clause_list imply that the
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e9334..627596a34c 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -421,6 +421,19 @@ restriction_is_or_clause(RestrictInfo *restrictinfo)
 		return false;
 }
 
+bool
+restriction_is_saop_clause(RestrictInfo *restrictinfo)
+{
+	if (IsA(restrictinfo->clause, ScalarArrayOpExpr))
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) restrictinfo->clause;
+
+		if (saop->useOr)
+			return true;
+	}
+	return false;
+}
+
 /*
  * restriction_is_securely_promotable
  *
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 35ab577501..92c8b14352 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -160,6 +160,16 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+typedef struct PredicatesData
+{
+	int					id;
+	Node			   *predicate;
+	List			   *elems;
+	ScalarArrayOpExpr  *saop;
+} PredicatesData;
+
+extern bool saop_covered_by_predicates(ScalarArrayOpExpr *saop,
+									  List *predicate_lists);
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c5..2cd5fbf943 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -34,6 +34,7 @@ extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Relids outer_relids);
 extern RestrictInfo *commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op);
 extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
+extern bool restriction_is_saop_clause(RestrictInfo *restrictinfo);
 extern bool restriction_is_securely_promotable(RestrictInfo *restrictinfo,
 											   RelOptInfo *rel);
 extern List *get_actual_clauses(List *restrictinfo_list);
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e..070202b0f0 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -907,6 +907,288 @@ select unique1, unique2 from onek2
        0 |     998
 (2 rows)
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: ((stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Without the transformation only seqscan possible here
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                         QUERY PLAN                                          
+---------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])) AND (stringu1 < 'Z'::name))
+(2 rows)
+
+-- Use partial indexes
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+                 QUERY PLAN                 
+--------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = 1) OR (unique2 = 3))
+(2 rows)
+
+RESET enable_or_transformation;
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+-- Don't scan partial indexes because of extra value.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+                      QUERY PLAN                      
+------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on onek2
+         Filter: (stringu1 = ANY ('{A,J,C}'::name[]))
+(3 rows)
+
+explain (costs off)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+                                      QUERY PLAN                                       
+---------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (stringu1 < 'B'::name)
+   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = ANY ('{A,A}'::name[])))
+   ->  Bitmap Index Scan on onek2_u2_prtl
+(4 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                                          QUERY PLAN                                                           
+-------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name)) OR ((unique2 < 1) AND (stringu1 < 'B'::name)))
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: ((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 < 1)
+(8 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 = 3) OR (unique1 = 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 3)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 1)
+(7 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+                                                             QUERY PLAN                                                             
+------------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = ((random() * '2'::double precision))::integer) OR (unique1 = ((random() * '3'::double precision))::integer))
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+                                                           QUERY PLAN                                                            
+---------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: (unique1 = ANY (ARRAY[((random() * '2'::double precision))::integer, ((random() * '3'::double precision))::integer]))
+(2 rows)
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+                                                                                          QUERY PLAN                                                                                          
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[]))) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 = ANY ('{1,2,21}'::integer[])) AND ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 = ANY ('{3,4}'::integer[])) OR (stringu1 = 'J'::name)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[])))
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(11 rows)
+
+-- Check recursive combination of OR and SAOP expressions
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR (unique1 < 1))
+   Filter: ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 < 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+(9 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR (unique1 < 1))
+   Filter: ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 < 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+(9 rows)
+
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+RESET enable_indexscan;
+RESET enable_seqscan;
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql
index 019f1e7673..0e650a2301 100644
--- a/src/test/regress/sql/select.sql
+++ b/src/test/regress/sql/select.sql
@@ -234,6 +234,88 @@ select unique1, unique2 from onek2
 select unique1, unique2 from onek2
   where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+-- Without the transformation only seqscan possible here
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+-- Use partial indexes
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+RESET enable_or_transformation;
+
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+
+-- Don't scan partial indexes because of extra value.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+explain (costs off)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+
+-- Check recursive combination of OR and SAOP expressions
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+
+RESET enable_indexscan;
+RESET enable_seqscan;
+
 --
 -- Test some corner cases that have been known to confuse the planner
 --
-- 
2.43.0

#127jian he
jian.universality@gmail.com
In reply to: Andrei Lepikhov (#126)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Thu, Feb 8, 2024 at 1:34 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 3/2/2024 02:06, Alena Rybakina wrote:

On 01.02.2024 08:00, jian he wrote:
I added your code to the patch.

Thanks Alena and Jian for the detailed scrutiny!

A couple of questions:
1. As I see, transformAExprIn uses the same logic as we invented but
allows composite and domain types. Could you add a comment explaining
why we forbid row types in general, in contrast to the transformAExprIn
routine?
2. Could you provide the tests to check issues covered by the recent (in
v.15) changes?

Patch 0001-* in the attachment incorporates changes induced by Jian's
notes from [1].
Patch 0002-* contains a transformation of the SAOP clause, which allows
the optimizer to utilize partial indexes if they cover all values in
this array. Also, it is an answer to Alexander's note [2] on performance
degradation. This first version may be a bit raw, but I need your
opinion: Does it resolve the issue?

yes. It resolved the partial index performance degradation issue.
The v16, 0002 extra code overhead is limited.

Here is how I test it.
drop table if exists test;
create table test as (select (random()*100)::int x, (random()*1000) y
from generate_series(1,1000000) i);
create index test_x_1_y on test (y) where x = 1;
create index test_x_2_y on test (y) where x = 2;
create index test_x_3_y on test (y) where x = 3;
create index test_x_4_y on test (y) where x = 4;
create index test_x_5_y on test (y) where x = 5;
create index test_x_6_y on test (y) where x = 6;
create index test_x_7_y on test (y) where x = 7;
create index test_x_8_y on test (y) where x = 8;
create index test_x_9_y on test (y) where x = 9;
create index test_x_10_y on test (y) where x = 10;

set enable_or_transformation to on;
explain(analyze, costs off)
select * from test
where (x = 1 or x = 2 or x = 3 or x = 4 or x = 5 or x = 6 or x = 7 or
x = 8 or x = 9 or x = 10);

set enable_or_transformation to off;
explain(analyze, costs off)
select * from test
where (x = 1 or x = 2 or x = 3 or x = 4 or x = 5 or x = 6 or x = 7 or
x = 8 or x = 9 or x = 10);

FAILED: src/backend/postgres_lib.a.p/optimizer_path_indxpath.c.o
ccache cc -Isrc/backend/postgres_lib.a.p -Isrc/include
-I../../Desktop/pg_src/src8/postgres/src/include
-I/usr/include/libxml2 -fdiagnostics-color=always --coverage
-D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -O0 -g
-fno-strict-aliasing -fwrapv -fexcess-precision=standard -D_GNU_SOURCE
-Wmissing-prototypes -Wpointer-arith -Werror=vla -Wendif-labels
-Wmissing-format-attribute -Wimplicit-fallthrough=3
-Wcast-function-type -Wshadow=compatible-local -Wformat-security
-Wdeclaration-after-statement -Wno-format-truncation
-Wno-stringop-truncation -Wunused-variable -Wuninitialized
-Werror=maybe-uninitialized -Wreturn-type
-DWRITE_READ_PARSE_PLAN_TREES -DCOPY_PARSE_PLAN_TREES
-DREALLOCATE_BITMAPSETS -DRAW_EXPRESSION_COVERAGE_TEST
-fno-omit-frame-pointer -fPIC -pthread -DBUILDING_DLL -MD -MQ
src/backend/postgres_lib.a.p/optimizer_path_indxpath.c.o -MF
src/backend/postgres_lib.a.p/optimizer_path_indxpath.c.o.d -o
src/backend/postgres_lib.a.p/optimizer_path_indxpath.c.o -c
../../Desktop/pg_src/src8/postgres/src/backend/optimizer/path/indxpath.c
../../Desktop/pg_src/src8/postgres/src/backend/optimizer/path/indxpath.c:
In function ‘build_paths_for_SAOP’:
../../Desktop/pg_src/src8/postgres/src/backend/optimizer/path/indxpath.c:1267:33:
error: declaration of ‘pd’ shadows a previous local
[-Werror=shadow=compatible-local]
1267 | PredicatesData *pd = (PredicatesData *) lfirst(lc);
| ^~
../../Desktop/pg_src/src8/postgres/src/backend/optimizer/path/indxpath.c:1235:29:
note: shadowed declaration is here
1235 | PredicatesData *pd;
| ^~
cc1: all warnings being treated as errors
[32/126] Compiling C object src/backend/postgres_lib.a.p/utils_adt_ruleutils.c.o
ninja: build stopped: subcommand failed.

+ if (!predicate_implied_by(index->indpred, list_make1(rinfo1), true))
+ elog(ERROR, "Logical mistake in OR <-> ANY transformation code");
the error message seems not clear?
What is a "Logical mistake"?

static List *
build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
List *other_clauses)
I am not sure what's `other_clauses`, and `rinfo` refers to? adding
some comments would be great.

struct PredicatesData needs some comments, I think.

+bool
+saop_covered_by_predicates(ScalarArrayOpExpr *saop, List *predicate_lists)
+{
+ ListCell   *lc;
+ PredIterInfoData clause_info;
+ bool result = false;
+ bool isConstArray;
+
+ Assert(IsA(saop, ScalarArrayOpExpr));
is this Assert necessary?

For the function build_paths_for_SAOP, I think I understand the first
part of the code.
But I am not 100% sure of the second part of the `foreach(lc,
predicate_lists)` code.
more comments in `foreach(lc, predicate_lists)` would be helpful.

do you need to add `PredicatesData` to src/tools/pgindent/typedefs.list?

I also did some minor refactoring of generate_saop_pathlist.

type_is_rowtype does not check if the type is array type.
transformBoolExprOr the OR QUAL, the Const part cannot be an array.
simple example:
alter table tenk1 add column arr int[];
set enable_or_transformation to on;
EXPLAIN (COSTS OFF)
SELECT count(*) FROM tenk1
WHERE arr = '{1,2,3}' or arr = '{1,2}';

instead of let it go to `foreach (lc, entries)`,
we can reject the Const array at `foreach(lc, expr->args)`

also `foreach(lc, expr->args)` do we need to reject cases like
`contain_subplans((Node *) nconst_expr)`?
maybe let the nconst_expr be a Var node would be far more easier.

Attachments:

v1-0001-minor-refactor-generate_saop_pathlist.no-cfbotapplication/octet-stream; name=v1-0001-minor-refactor-generate_saop_pathlist.no-cfbotDownload
From 3a8d1a81a4153dbcf016c5c2c8610dbffae018da Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Fri, 9 Feb 2024 22:07:49 +0800
Subject: [PATCH v1 1/1] minor refactor generate_saop_pathlist

we only call generate_saop_pathlist when enable_or_transformation is true,
let do it this way.
---
 src/backend/optimizer/path/indxpath.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 8ff2ba96..cfb04b27 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1327,10 +1327,6 @@ generate_saop_pathlist(PlannerInfo *root, RelOptInfo *rel,
 	List	   *indlist;
 	ListCell   *lc;
 
-	if (!enable_or_transformation)
-		return NIL;
-
-
 	/*
 	 * We must be able to match at least one index to each element of
 	 * the array, else we can't use it.
@@ -1388,8 +1384,14 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 
 		if (restriction_is_saop_clause(rinfo))
 		{
-			pathlist = generate_saop_pathlist(root, rel, rinfo,
-											  all_clauses);
+			/*
+			 * if we enable enable_or_transformation, we may
+			 * tranformed multi OR expression to SAOP node,
+			 * but here, we need to "reverse" it back for generating bitmapor path
+			*/
+			if (enable_or_transformation)
+				pathlist = generate_saop_pathlist(root, rel, rinfo,
+												   all_clauses);
 		}
 		else if (!restriction_is_or_clause(rinfo))
 			/* Ignore RestrictInfos that aren't ORs */
@@ -1431,10 +1433,11 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 
 					if (restriction_is_saop_clause(ri))
 					{
-						List *paths;
+						List *paths = NIL;
 
-						paths = generate_saop_pathlist(root, rel, ri,
-														 all_clauses);
+						if (enable_or_transformation)
+							paths = generate_saop_pathlist(root, rel, ri,
+															all_clauses);
 
 						if (paths != NIL)
 						{
-- 
2.34.1

#128Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: jian he (#127)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Thanks for the review!
It was the first version for discussion. Of course, refactoring and
polishing cycles will be needed, even so we can discuss the general idea
earlier.

On 10/2/2024 12:00, jian he wrote:

On Thu, Feb 8, 2024 at 1:34 PM Andrei Lepikhov
1235 | PredicatesData *pd;

Thanks

+ if (!predicate_implied_by(index->indpred, list_make1(rinfo1), true))
+ elog(ERROR, "Logical mistake in OR <-> ANY transformation code");
the error message seems not clear?

Yeah, have rewritten

static List *
build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
List *other_clauses)
I am not sure what's `other_clauses`, and `rinfo` refers to? adding
some comments would be great.

struct PredicatesData needs some comments, I think.

Added, not so much though

+bool
+saop_covered_by_predicates(ScalarArrayOpExpr *saop, List *predicate_lists)
+{
+ ListCell   *lc;
+ PredIterInfoData clause_info;
+ bool result = false;
+ bool isConstArray;
+
+ Assert(IsA(saop, ScalarArrayOpExpr));
is this Assert necessary?

Not sure. Moved it into another routine.

For the function build_paths_for_SAOP, I think I understand the first
part of the code.
But I am not 100% sure of the second part of the `foreach(lc,
predicate_lists)` code.
more comments in `foreach(lc, predicate_lists)` would be helpful.

Done

do you need to add `PredicatesData` to src/tools/pgindent/typedefs.list?

Done

I also did some minor refactoring of generate_saop_pathlist.

Partially agree

instead of let it go to `foreach (lc, entries)`,
we can reject the Const array at `foreach(lc, expr->args)`

Yeah, I just think we can go further and transform two const arrays into
a new one if we have the same clause and operator. In that case, we
should allow it to pass through this cycle down to the classification stage.

also `foreach(lc, expr->args)` do we need to reject cases like
`contain_subplans((Node *) nconst_expr)`?
maybe let the nconst_expr be a Var node would be far more easier.

It's contradictory. On the one hand, we simplify the comparison
procedure and can avoid expr jumbling at all. On the other hand - we
restrict the feature. IMO, it would be better to unite such clauses
complex_clause1 IN (..) OR complex_clause1 IN (..)
into
complex_clause1 IN (.., ..)
and don't do duplicated work computing complex clauses.
In the attachment - the next version of the second patch.

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat-20240212.patchtext/plain; charset=UTF-8; name=0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat-20240212.patchDownload
From c1e5fc35778acd01cca67e63fdf80c5605af03f2 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Wed, 24 Jan 2024 14:07:17 +0700
Subject: [PATCH 2/2] Teach generate_bitmap_or_paths to build BitmapOr paths
 over SAOP clauses.

Likewise OR clauses, discover SAOP array and try to split its elements
between smaller sized arrays to fit a set of partial indexes.
---
 src/backend/optimizer/path/indxpath.c     | 304 ++++++++++++++++++----
 src/backend/optimizer/util/predtest.c     |  46 ++++
 src/backend/optimizer/util/restrictinfo.c |  13 +
 src/include/optimizer/optimizer.h         |  16 ++
 src/include/optimizer/restrictinfo.h      |   1 +
 src/test/regress/expected/select.out      | 282 ++++++++++++++++++++
 src/test/regress/sql/select.sql           |  82 ++++++
 src/tools/pgindent/typedefs.list          |   1 +
 8 files changed, 692 insertions(+), 53 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 32c6a8bbdc..5383cb76dc 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,6 +32,7 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
 
@@ -1220,11 +1221,177 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Building index paths over SAOP clause differs from the logic of OR clauses.
+ * Here we iterate across all the array elements and split them to SAOPs,
+ * corresponding to different indexes. We must match each element to an index.
+ */
+static List *
+build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
+					 List *other_clauses)
+{
+	List			   *result = NIL;
+	List			   *predicate_lists = NIL;
+	ListCell		   *lc;
+	PredicatesData	   *pd;
+	ScalarArrayOpExpr  *saop = (ScalarArrayOpExpr *) rinfo->clause;
+
+	Assert(IsA(saop, ScalarArrayOpExpr) && saop->useOr);
+
+	if (!IsA(lsecond(saop->args), Const))
+		/*
+		 * Has it practical outcome to merge arrays which couldn't constantified
+		 * before that step?
+		 */
+		return NIL;
+
+	/* Collect predicates */
+	foreach(lc, rel->indexlist)
+	{
+		IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
+
+		/* Take into consideration partial indexes supporting bitmap scans */
+		if (!index->amhasgetbitmap || index->indpred == NIL || index->predOK)
+			continue;
+
+		pd = palloc0(sizeof(PredicatesData));
+		pd->id = foreach_current_index(lc);
+		/* The trick with reducing recursion is stolen from predicate_implied_by */
+		pd->predicate = list_length(index->indpred) == 1 ?
+										(Node *) linitial(index->indpred) :
+										(Node *) index->indpred;
+		predicate_lists = lappend(predicate_lists, (void *) pd);
+	}
+
+	/* Split the array data according to index predicates. */
+	if (predicate_lists == NIL ||
+		!saop_covered_by_predicates(saop, predicate_lists))
+		return NIL;
+
+	other_clauses = list_delete_ptr(other_clauses, rinfo);
+
+	/*
+	 * Having incoming SAOP split to set of smaller SAOPs which can be applied
+	 * to partial indexes, generate paths for each one.
+	 */
+	foreach(lc, predicate_lists)
+	{
+		IndexOptInfo   *index;
+		IndexClauseSet	clauseset;
+		List		   *indexpaths;
+		RestrictInfo   *rinfo1 = NULL;
+		Expr		   *clause;
+
+		pd = (PredicatesData *) lfirst(lc);
+		if (pd->elems == NIL)
+			/* The index doesn't participate in this operation */
+			continue;
+		else
+		{
+			ArrayType		   *arrayval = NULL;
+			ArrayExpr		   *arr = NULL;
+			Const			   *arrayconst = lsecond_node(Const, saop->args);
+			ScalarArrayOpExpr  *dest = makeNode(ScalarArrayOpExpr);
+
+			/* Make up new array */
+			arrayval = DatumGetArrayTypeP(arrayconst->constvalue);
+			arr = makeNode(ArrayExpr);
+			arr->array_collid = arrayconst->constcollid;
+			arr->array_typeid = arrayconst->consttype;
+			arr->element_typeid = arrayval->elemtype;
+			arr->elements = pd->elems;
+			arr->location = -1;
+			arr->multidims = false;
+
+			/* Compose new SAOP, partially covering the source one */
+			memcpy(dest, saop, sizeof(ScalarArrayOpExpr));
+			dest->args = list_make2(linitial(saop->args), arr);
+
+			clause = (Expr *) estimate_expression_value(root, (Node *) dest);
+
+			/*
+			 * Create new RestrictInfo. It maybe more heavy than just copy node,
+			 * but remember some internals: the serial number, selectivity
+			 * cache etc.
+			 */
+			rinfo1 = make_restrictinfo(root, clause,
+									   rinfo->is_pushed_down,
+									   rinfo->has_clone,
+									   rinfo->is_clone,
+									   rinfo->pseudoconstant,
+									   rinfo->security_level,
+									   rinfo->required_relids,
+									   rinfo->incompatible_relids,
+									   rinfo->outer_relids);
+		}
+
+		index = list_nth(rel->indexlist, pd->id);
+		Assert(predicate_implied_by(index->indpred, list_make1(rinfo1), true));
+
+		/* Excluding partial indexes with predOK we make this statement false */
+		Assert(!predicate_implied_by(index->indpred, other_clauses, false));
+
+		/* Time to generate index paths */
+
+		MemSet(&clauseset, 0, sizeof(clauseset));
+		match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);
+		match_clauses_to_index(root, other_clauses, index, &clauseset);
+
+		/* Predicate has found already. So, it is ok for the empty match */
+
+		indexpaths = build_index_paths(root, rel,
+									   index, &clauseset,
+									   true,
+									   ST_BITMAPSCAN,
+									   NULL,
+									   NULL);
+		Assert(indexpaths != NIL);
+		result = lappend(result, indexpaths);
+	}
+	return result;
+}
+
+static List *
+generate_saop_pathlist(PlannerInfo *root, RelOptInfo *rel,
+					   RestrictInfo *rinfo, List *all_clauses)
+{
+	List	   *pathlist = NIL;
+	Path	   *bitmapqual;
+	List	   *indlist;
+	ListCell   *lc;
+
+	if (!enable_or_transformation)
+		return NIL;
+
+	/*
+	 * We must be able to match at least one index to each element of
+	 * the array, else we can't use it.
+	 */
+	indlist = build_paths_for_SAOP(root, rel, rinfo, all_clauses);
+	if (indlist == NIL)
+		return NIL;
+
+	/*
+	 * OK, pick the most promising AND combination, and add it to
+	 * pathlist.
+	 */
+	foreach (lc, indlist)
+	{
+		List *plist = lfirst_node(List, lc);
+
+		bitmapqual = choose_bitmap_and(root, rel, plist);
+		pathlist = lappend(pathlist, bitmapqual);
+	}
+
+	return pathlist;
+}
+
 /*
  * generate_bitmap_or_paths
- *		Look through the list of clauses to find OR clauses, and generate
- *		a BitmapOrPath for each one we can handle that way.  Return a list
- *		of the generated BitmapOrPaths.
+ *		Look through the list of clauses to find OR and SAOP clauses, and
+ *		Each saop clause are splitted to be covered by partial indexes.
+ *		generate a BitmapOrPath for each one we can handle that way.
+ *		Return a list of the generated BitmapOrPaths.
  *
  * other_clauses is a list of additional clauses that can be assumed true
  * for the purpose of generating indexquals, but are not to be searched for
@@ -1247,68 +1414,99 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	foreach(lc, clauses)
 	{
 		RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
-		List	   *pathlist;
+		List	   *pathlist = NIL;
 		Path	   *bitmapqual;
 		ListCell   *j;
 
-		/* Ignore RestrictInfos that aren't ORs */
-		if (!restriction_is_or_clause(rinfo))
+		if (restriction_is_saop_clause(rinfo))
+		{
+			pathlist = generate_saop_pathlist(root, rel, rinfo,
+											  all_clauses);
+		}
+		else if (!restriction_is_or_clause(rinfo))
+			/* Ignore RestrictInfos that aren't ORs */
 			continue;
-
-		/*
-		 * We must be able to match at least one index to each of the arms of
-		 * the OR, else we can't use it.
-		 */
-		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		else
 		{
-			Node	   *orarg = (Node *) lfirst(j);
-			List	   *indlist;
-
-			/* OR arguments should be ANDs or sub-RestrictInfos */
-			if (is_andclause(orarg))
+			/*
+			 * We must be able to match at least one index to each of the arms of
+			 * the OR, else we can't use it.
+			 */
+			foreach(j, ((BoolExpr *) rinfo->orclause)->args)
 			{
-				List	   *andargs = ((BoolExpr *) orarg)->args;
+				Node	   *orarg = (Node *) lfirst(j);
+				List	   *indlist;
 
-				indlist = build_paths_for_OR(root, rel,
-											 andargs,
-											 all_clauses);
+				/* OR arguments should be ANDs or sub-RestrictInfos */
+				if (is_andclause(orarg))
+				{
+					List	   *andargs = ((BoolExpr *) orarg)->args;
 
-				/* Recurse in case there are sub-ORs */
-				indlist = list_concat(indlist,
-									  generate_bitmap_or_paths(root, rel,
-															   andargs,
-															   all_clauses));
-			}
-			else
-			{
-				RestrictInfo *ri = castNode(RestrictInfo, orarg);
-				List	   *orargs;
+					indlist = build_paths_for_OR(root, rel,
+												 andargs,
+												 all_clauses);
 
-				Assert(!restriction_is_or_clause(ri));
-				orargs = list_make1(ri);
+					/* Recurse in case there are sub-ORs */
+					indlist = list_concat(indlist,
+										  generate_bitmap_or_paths(root, rel,
+																   andargs,
+																   all_clauses));
+				}
+				else
+				{
+					RestrictInfo *ri = castNode(RestrictInfo, orarg);
+					List	   *orargs;
 
-				indlist = build_paths_for_OR(root, rel,
-											 orargs,
-											 all_clauses);
-			}
+					Assert(!restriction_is_or_clause(ri));
 
-			/*
-			 * If nothing matched this arm, we can't do anything with this OR
-			 * clause.
-			 */
-			if (indlist == NIL)
-			{
-				pathlist = NIL;
-				break;
-			}
+					orargs = list_make1(ri);
 
-			/*
-			 * OK, pick the most promising AND combination, and add it to
-			 * pathlist.
-			 */
-			bitmapqual = choose_bitmap_and(root, rel, indlist);
-			pathlist = lappend(pathlist, bitmapqual);
+					if (restriction_is_saop_clause(ri))
+					{
+						List *paths;
+
+						paths = generate_saop_pathlist(root, rel, ri,
+														 all_clauses);
+
+						if (paths != NIL)
+						{
+							/*
+							 * Add paths to pathlist and immediately jump to the
+							 * next element of the OR clause.
+							 */
+							pathlist = list_concat(pathlist, paths);
+							continue;
+						}
+
+						/*
+						 * Pass down out of this if construction:
+						 * If saop isn't covered by partial indexes, try to
+						 * build scan path for the saop as a whole.
+						 */
+					}
+
+					indlist = build_paths_for_OR(root, rel,
+												 orargs,
+												 all_clauses);
+				}
+
+				/*
+				 * If nothing matched this arm, we can't do anything with this OR
+				 * clause.
+				 */
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+
+				/*
+				 * OK, pick the most promising AND combination, and add it to
+				 * pathlist.
+				 */
+				bitmapqual = choose_bitmap_and(root, rel, indlist);
+				pathlist = lappend(pathlist, bitmapqual);
+			}
 		}
 
 		/*
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index c37b416e24..8ed80a78b4 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -112,6 +112,52 @@ static Oid	get_btree_test_op(Oid pred_op, Oid clause_op, bool refute_it);
 static void InvalidateOprProofCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
 
 
+/*
+ * Could this ANY () expression can be split into a set of ANYs over partial
+ * indexes? If yes, return these saops in the PredicatesData structure.
+ */
+bool
+saop_covered_by_predicates(ScalarArrayOpExpr *saop, List *predicate_lists)
+{
+	ListCell		   *lc;
+	PredIterInfoData	clause_info;
+	bool				result = false;
+
+	if (predicate_classify((Node *) saop, &clause_info) != CLASS_OR)
+		return false;
+
+	iterate_begin(pitem, (Node *) saop, clause_info)
+	{
+		result = false;
+
+		foreach(lc, predicate_lists)
+		{
+			PredicatesData *pd = (PredicatesData *) lfirst(lc);
+
+			if (!predicate_implied_by_recurse(pitem, pd->predicate, false))
+				continue;
+
+			/* Predicate is found. Add the elem to the saop clause */
+			Assert(IsA(pitem, OpExpr));
+
+			/* Extract constant from the expression */
+			pd->elems = lappend(pd->elems,
+					copyObject(lsecond_node(Const, ((OpExpr *) pitem)->args)));
+			result = true;
+			break;
+		}
+
+		if (!result)
+			/*
+			 * The element doesn't fit any index. Interrupt the process immediately
+			 */
+			break;
+	}
+	iterate_end(clause_info);
+
+	return result;
+}
+
 /*
  * predicate_implied_by
  *	  Recursively checks whether the clauses in clause_list imply that the
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e9334..627596a34c 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -421,6 +421,19 @@ restriction_is_or_clause(RestrictInfo *restrictinfo)
 		return false;
 }
 
+bool
+restriction_is_saop_clause(RestrictInfo *restrictinfo)
+{
+	if (IsA(restrictinfo->clause, ScalarArrayOpExpr))
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) restrictinfo->clause;
+
+		if (saop->useOr)
+			return true;
+	}
+	return false;
+}
+
 /*
  * restriction_is_securely_promotable
  *
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 35ab577501..232afcd00c 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -160,6 +160,22 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+/*
+ * Contains information needed to extract from saop a set of elements which can
+ * be covered by the partial index:
+ * id - caller's identification of the index.
+ * predicate - predicate expression of the index
+ * elems - returning list of array elements which corresponds to this predicate
+ */
+typedef struct PredicatesData
+{
+	int		id;
+	Node   *predicate;
+	List   *elems;
+} PredicatesData;
+
+extern bool saop_covered_by_predicates(ScalarArrayOpExpr *saop,
+									  List *predicate_lists);
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c5..2cd5fbf943 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -34,6 +34,7 @@ extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Relids outer_relids);
 extern RestrictInfo *commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op);
 extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
+extern bool restriction_is_saop_clause(RestrictInfo *restrictinfo);
 extern bool restriction_is_securely_promotable(RestrictInfo *restrictinfo,
 											   RelOptInfo *rel);
 extern List *get_actual_clauses(List *restrictinfo_list);
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e..070202b0f0 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -907,6 +907,288 @@ select unique1, unique2 from onek2
        0 |     998
 (2 rows)
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: ((stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Without the transformation only seqscan possible here
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                         QUERY PLAN                                          
+---------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])) AND (stringu1 < 'Z'::name))
+(2 rows)
+
+-- Use partial indexes
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+                 QUERY PLAN                 
+--------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = 1) OR (unique2 = 3))
+(2 rows)
+
+RESET enable_or_transformation;
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+-- Don't scan partial indexes because of extra value.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+                      QUERY PLAN                      
+------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on onek2
+         Filter: (stringu1 = ANY ('{A,J,C}'::name[]))
+(3 rows)
+
+explain (costs off)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+                                      QUERY PLAN                                       
+---------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (stringu1 < 'B'::name)
+   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = ANY ('{A,A}'::name[])))
+   ->  Bitmap Index Scan on onek2_u2_prtl
+(4 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                                          QUERY PLAN                                                           
+-------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name)) OR ((unique2 < 1) AND (stringu1 < 'B'::name)))
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: ((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 < 1)
+(8 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 = 3) OR (unique1 = 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 3)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 1)
+(7 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+                                                             QUERY PLAN                                                             
+------------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = ((random() * '2'::double precision))::integer) OR (unique1 = ((random() * '3'::double precision))::integer))
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+                                                           QUERY PLAN                                                            
+---------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: (unique1 = ANY (ARRAY[((random() * '2'::double precision))::integer, ((random() * '3'::double precision))::integer]))
+(2 rows)
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+                                                                                          QUERY PLAN                                                                                          
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[]))) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 = ANY ('{1,2,21}'::integer[])) AND ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 = ANY ('{3,4}'::integer[])) OR (stringu1 = 'J'::name)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[])))
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(11 rows)
+
+-- Check recursive combination of OR and SAOP expressions
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR (unique1 < 1))
+   Filter: ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 < 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+(9 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR (unique1 < 1))
+   Filter: ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 < 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+(9 rows)
+
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+RESET enable_indexscan;
+RESET enable_seqscan;
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql
index 019f1e7673..0e650a2301 100644
--- a/src/test/regress/sql/select.sql
+++ b/src/test/regress/sql/select.sql
@@ -234,6 +234,88 @@ select unique1, unique2 from onek2
 select unique1, unique2 from onek2
   where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+-- Without the transformation only seqscan possible here
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+-- Use partial indexes
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+RESET enable_or_transformation;
+
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+
+-- Don't scan partial indexes because of extra value.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+explain (costs off)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+
+-- Check recursive combination of OR and SAOP expressions
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+
+RESET enable_indexscan;
+RESET enable_seqscan;
+
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index adae668b37..a1d43283db 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2138,6 +2138,7 @@ PredIterInfoData
 PredXactList
 PredicateLockData
 PredicateLockTargetType
+PredicatesData
 PrefetchBufferResult
 PrepParallelRestorePtrType
 PrepareStmt
-- 
2.43.0

#129Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Andrei Lepikhov (#128)
Re: POC, WIP: OR-clause support for indexes

Hi!

I can't unnderstand this part of code:

/* Time to generate index paths */

MemSet(&clauseset, 0, sizeof(clauseset));
match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);

As I understand it, match_clauses_to_index is necessary if you have a
RestrictInfo (rinfo1) variable, so maybe we should run it after the
make_restrictonfo procedure, otherwise calling it, I think, is useless.

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#130Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#129)
Re: POC, WIP: OR-clause support for indexes

On 12/2/2024 15:55, Alena Rybakina wrote:

Hi!

I can't unnderstand this part of code:

/* Time to generate index paths */

MemSet(&clauseset, 0, sizeof(clauseset));
match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);

As I understand it, match_clauses_to_index is necessary if you have a
RestrictInfo (rinfo1) variable, so maybe we should run it after the
make_restrictonfo procedure, otherwise calling it, I think, is useless.

I think you must explain your note in more detail. Before this call, we
already called make_restrictinfo() and built rinfo1, haven't we?

--
regards,
Andrei Lepikhov
Postgres Professional

#131Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Andrei Lepikhov (#130)
Re: POC, WIP: OR-clause support for indexes

On 12.02.2024 12:01, Andrei Lepikhov wrote:

On 12/2/2024 15:55, Alena Rybakina wrote:

Hi!

I can't unnderstand this part of code:

/* Time to generate index paths */

MemSet(&clauseset, 0, sizeof(clauseset));
match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);

As I understand it, match_clauses_to_index is necessary if you have a
RestrictInfo (rinfo1) variable, so maybe we should run it after the
make_restrictonfo procedure, otherwise calling it, I think, is useless.

I think you must explain your note in more detail. Before this call,
we already called make_restrictinfo() and built rinfo1, haven't we?

I got it, I think, I was confused by the “else“ block when we can
process the index, otherwise we move on to the next element.

I think maybe “else“ block of creating restrictinfo with the indexpaths
list creation should be moved to a separate function or just remove "else"?

I think we need to check that rinfo->clause is not empty, because if it
is we can miss calling build_paths_for_OR function. We should add it there:

restriction_is_saop_clause(RestrictInfo *restrictinfo)
{
    if (IsA(restrictinfo->clause, ScalarArrayOpExpr))
...

By the way, I think we need to add a check that the clauseset is not
empty (if (!clauseset.nonempty)) otherwise we could get an error. The
same check I noticed in build_paths_for_OR function.

--
Regards,
Alena Rybakina
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#132jian he
jian.universality@gmail.com
In reply to: Andrei Lepikhov (#126)
Re: POC, WIP: OR-clause support for indexes

On Thu, Feb 8, 2024 at 1:34 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

A couple of questions:
1. As I see, transformAExprIn uses the same logic as we invented but
allows composite and domain types. Could you add a comment explaining
why we forbid row types in general, in contrast to the transformAExprIn
routine?
2. Could you provide the tests to check issues covered by the recent (in
v.15) changes?

Patch 0001-* in the attachment incorporates changes induced by Jian's
notes from [1].
Patch 0002-* contains a transformation of the SAOP clause, which allows
the optimizer to utilize partial indexes if they cover all values in
this array. Also, it is an answer to Alexander's note [2] on performance
degradation. This first version may be a bit raw, but I need your
opinion: Does it resolve the issue?

+ newa = makeNode(ArrayExpr);
+ /* array_collid will be set by parse_collate.c */
+ newa->element_typeid = scalar_type;
+ newa->array_typeid = array_type;
+ newa->multidims = false;
+ newa->elements = aexprs;
+ newa->location = -1;

I am confused by the comments `array_collid will be set by
parse_collate.c`, can you further explain it?
if OR expression right arm is not plain Const, but with collation
specification, eg.
`where a = 'a' collate "C" or a = 'b' collate "C";`

then the rightop is not Const, it will be CollateExpr, it will not be
used in transformation.
---------------------------------------------------------------------------------------------------------------------
Maybe the previous thread mentioned it, but this thread is very long.
after apply
v16-0001-Transform-OR-clause-to-ANY-expressions.patch
and 0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat-20240212.patch
I found a performance degradation case:

drop table if exists test;
create table test as (select (random()*100)::int x, (random()*1000) y
from generate_series(1,1000000) i);
vacuum analyze test;

set enable_or_transformation to off;
explain(timing off, analyze, costs off)
select * from test where (x = 1 or x = 2 or x = 3 or x = 4 or x = 5 or
x = 6 or x = 7 or x = 8 or x = 9 ) \watch i=0.1 c=10
50.887 ms

set enable_or_transformation to on;
explain(timing off, analyze, costs off)
select * from test where (x = 1 or x = 2 or x = 3 or x = 4 or x = 5 or
x = 6 or x = 7 or x = 8 or x = 9 ) \watch i=0.1 c=10
92.001 ms

---------------------------------------------------------------------------------------------------------------------
but for aggregate count(*), it indeed increased the performance:

set enable_or_transformation to off;
explain(timing off, analyze, costs off)
select count(*) from test where (x = 1 or x = 2 or x = 3 or x = 4 or x
= 5 or x = 6 or x = 7 or x = 8 or x = 9 ) \watch i=0.1 c=10
46.818 ms

set enable_or_transformation to on;
explain(timing off, analyze, costs off)
select count(*) from test where (x = 1 or x = 2 or x = 3 or x = 4 or x
= 5 or x = 6 or x = 7 or x = 8 or x = 9 ) \watch i=0.1 c=10
35.376 ms

The time is the last result of the 10 iterations.

#133Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: jian he (#132)
Re: POC, WIP: OR-clause support for indexes

On 13/2/2024 07:00, jian he wrote:

+ newa = makeNode(ArrayExpr);
+ /* array_collid will be set by parse_collate.c */
+ newa->element_typeid = scalar_type;
+ newa->array_typeid = array_type;
+ newa->multidims = false;
+ newa->elements = aexprs;
+ newa->location = -1;

I am confused by the comments `array_collid will be set by
parse_collate.c`, can you further explain it?

I wonder if the second paragraph of comments on commit b310b6e will be
enough to dive into details.

if OR expression right arm is not plain Const, but with collation
specification, eg.
`where a = 'a' collate "C" or a = 'b' collate "C";`

then the rightop is not Const, it will be CollateExpr, it will not be
used in transformation.

Yes, it is done for simplicity right now. I'm not sure about corner
cases of merging such expressions.

set enable_or_transformation to on;
explain(timing off, analyze, costs off)
select count(*) from test where (x = 1 or x = 2 or x = 3 or x = 4 or x
= 5 or x = 6 or x = 7 or x = 8 or x = 9 ) \watch i=0.1 c=10
35.376 ms

The time is the last result of the 10 iterations.

The reason here - parallel workers.
If you see into the plan you will find parallel workers without
optimization and absence of them in the case of optimization:

Gather (cost=1000.00..28685.37 rows=87037 width=12)
(actual rows=90363 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Parallel Seq Scan on test
Filter: ((x = 1) OR (x = 2) OR (x = 3) OR (x = 4) OR (x = 5)
OR (x = 6) OR (x = 7) OR (x = 8) OR (x = 9))

Seq Scan on test (cost=0.02..20440.02 rows=90600 width=12)
(actual rows=90363 loops=1)
Filter: (x = ANY ('{1,2,3,4,5,6,7,8,9}'::integer[]))

Having 90600 tuples returned we estimate it into 87000 (less precisely)
without transformation and 90363 (more precisely) with the transformation.
But if you play with parallel_tuple_cost and parallel_setup_cost, you
will end up having these parallel workers:

Gather (cost=0.12..11691.03 rows=90600 width=12)
(actual rows=90363 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Parallel Seq Scan on test
Filter: (x = ANY ('{1,2,3,4,5,6,7,8,9}'::integer[]))
Rows Removed by Filter: 303212

And some profit about 25%, on my laptop.
I'm not sure about the origins of such behavior, but it seems to be an
issue of parallel workers, not this specific optimization.

--
regards,
Andrei Lepikhov
Postgres Professional

#134Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#131)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 12/2/2024 17:51, Alena Rybakina wrote:

On 12.02.2024 12:01, Andrei Lepikhov wrote:

On 12/2/2024 15:55, Alena Rybakina wrote:

As I understand it, match_clauses_to_index is necessary if you have a
RestrictInfo (rinfo1) variable, so maybe we should run it after the
make_restrictonfo procedure, otherwise calling it, I think, is useless.

I think you must explain your note in more detail. Before this call,
we already called make_restrictinfo() and built rinfo1, haven't we?

I got it, I think, I was confused by the “else“ block when we can
process the index, otherwise we move on to the next element.

I think maybe “else“ block of creating restrictinfo with the indexpaths
list creation should be moved to a separate function or just remove "else"?

IMO, it is a matter of taste. But if you are really confused, maybe it
will make understanding for someone else simpler. So, changed.

I think we need to check that rinfo->clause is not empty, because if it
is we can miss calling build_paths_for_OR function. We should add it there:

restriction_is_saop_clause(RestrictInfo *restrictinfo)
{
    if (IsA(restrictinfo->clause, ScalarArrayOpExpr))

I wonder if we should add here assertion, not NULL check. In what case
we could get NULL clause here? But added for surety.

By the way, I think we need to add a check that the clauseset is not
empty (if (!clauseset.nonempty)) otherwise we could get an error. The
same check I noticed in build_paths_for_OR function.

I don't. Feel free to provide counterexample.

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat-20240213.patchtext/plain; charset=UTF-8; name=0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat-20240213.patchDownload
From 2b088a1bd662c614ee491a797d2fcb67e2fb2391 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Wed, 24 Jan 2024 14:07:17 +0700
Subject: [PATCH 2/2] Teach generate_bitmap_or_paths to build BitmapOr paths
 over SAOP clauses.

Likewise OR clauses, discover SAOP array and try to split its elements
between smaller sized arrays to fit a set of partial indexes.
---
 src/backend/optimizer/path/indxpath.c     | 301 ++++++++++++++++++----
 src/backend/optimizer/util/predtest.c     |  46 ++++
 src/backend/optimizer/util/restrictinfo.c |  13 +
 src/include/optimizer/optimizer.h         |  16 ++
 src/include/optimizer/restrictinfo.h      |   1 +
 src/test/regress/expected/select.out      | 282 ++++++++++++++++++++
 src/test/regress/sql/select.sql           |  82 ++++++
 src/tools/pgindent/typedefs.list          |   1 +
 8 files changed, 689 insertions(+), 53 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 32c6a8bbdc..56b04541db 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,6 +32,7 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
 
@@ -1220,11 +1221,174 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Building index paths over SAOP clause differs from the logic of OR clauses.
+ * Here we iterate across all the array elements and split them to SAOPs,
+ * corresponding to different indexes. We must match each element to an index.
+ */
+static List *
+build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
+					 List *other_clauses)
+{
+	List			   *result = NIL;
+	List			   *predicate_lists = NIL;
+	ListCell		   *lc;
+	PredicatesData	   *pd;
+	ScalarArrayOpExpr  *saop = (ScalarArrayOpExpr *) rinfo->clause;
+
+	Assert(IsA(saop, ScalarArrayOpExpr) && saop->useOr);
+
+	if (!IsA(lsecond(saop->args), Const))
+		/*
+		 * Has it practical outcome to merge arrays which couldn't constantified
+		 * before that step?
+		 */
+		return NIL;
+
+	/* Collect predicates */
+	foreach(lc, rel->indexlist)
+	{
+		IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
+
+		/* Take into consideration partial indexes supporting bitmap scans */
+		if (!index->amhasgetbitmap || index->indpred == NIL || index->predOK)
+			continue;
+
+		pd = palloc0(sizeof(PredicatesData));
+		pd->id = foreach_current_index(lc);
+		/* The trick with reducing recursion is stolen from predicate_implied_by */
+		pd->predicate = list_length(index->indpred) == 1 ?
+										(Node *) linitial(index->indpred) :
+										(Node *) index->indpred;
+		predicate_lists = lappend(predicate_lists, (void *) pd);
+	}
+
+	/* Split the array data according to index predicates. */
+	if (predicate_lists == NIL ||
+		!saop_covered_by_predicates(saop, predicate_lists))
+		return NIL;
+
+	other_clauses = list_delete_ptr(other_clauses, rinfo);
+
+	/*
+	 * Having incoming SAOP split to set of smaller SAOPs which can be applied
+	 * to partial indexes, generate paths for each one.
+	 */
+	foreach(lc, predicate_lists)
+	{
+		IndexOptInfo	   *index;
+		IndexClauseSet		clauseset;
+		List			   *indexpaths;
+		RestrictInfo	   *rinfo1 = NULL;
+		Expr			   *clause;
+		ArrayType		   *arrayval = NULL;
+		ArrayExpr		   *arr = NULL;
+		Const			   *arrayconst = lsecond_node(Const, saop->args);
+		ScalarArrayOpExpr  *dest = makeNode(ScalarArrayOpExpr);
+
+		pd = (PredicatesData *) lfirst(lc);
+		if (pd->elems == NIL)
+			/* The index doesn't participate in this operation */
+			continue;
+
+		/* Make up new array */
+		arrayval = DatumGetArrayTypeP(arrayconst->constvalue);
+		arr = makeNode(ArrayExpr);
+		arr->array_collid = arrayconst->constcollid;
+		arr->array_typeid = arrayconst->consttype;
+		arr->element_typeid = arrayval->elemtype;
+		arr->elements = pd->elems;
+		arr->location = -1;
+		arr->multidims = false;
+
+		/* Compose new SAOP, partially covering the source one */
+		memcpy(dest, saop, sizeof(ScalarArrayOpExpr));
+		dest->args = list_make2(linitial(saop->args), arr);
+
+		clause = (Expr *) estimate_expression_value(root, (Node *) dest);
+
+		/*
+		 * Create new RestrictInfo. It maybe more heavy than just copy node,
+		 * but remember some internals: the serial number, selectivity
+		 * cache etc.
+		 */
+		rinfo1 = make_restrictinfo(root, clause,
+								   rinfo->is_pushed_down,
+								   rinfo->has_clone,
+								   rinfo->is_clone,
+								   rinfo->pseudoconstant,
+								   rinfo->security_level,
+								   rinfo->required_relids,
+								   rinfo->incompatible_relids,
+								   rinfo->outer_relids);
+
+		index = list_nth(rel->indexlist, pd->id);
+		Assert(predicate_implied_by(index->indpred, list_make1(rinfo1), true));
+
+		/* Excluding partial indexes with predOK we make this statement false */
+		Assert(!predicate_implied_by(index->indpred, other_clauses, false));
+
+		/* Time to generate index paths */
+
+		MemSet(&clauseset, 0, sizeof(clauseset));
+		match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);
+		match_clauses_to_index(root, other_clauses, index, &clauseset);
+
+		/* Predicate has found already. So, it is ok for the empty match */
+
+		indexpaths = build_index_paths(root, rel,
+									   index, &clauseset,
+									   true,
+									   ST_BITMAPSCAN,
+									   NULL,
+									   NULL);
+		Assert(indexpaths != NIL);
+		result = lappend(result, indexpaths);
+	}
+	return result;
+}
+
+static List *
+generate_saop_pathlist(PlannerInfo *root, RelOptInfo *rel,
+					   RestrictInfo *rinfo, List *all_clauses)
+{
+	List	   *pathlist = NIL;
+	Path	   *bitmapqual;
+	List	   *indlist;
+	ListCell   *lc;
+
+	if (!enable_or_transformation)
+		return NIL;
+
+	/*
+	 * We must be able to match at least one index to each element of
+	 * the array, else we can't use it.
+	 */
+	indlist = build_paths_for_SAOP(root, rel, rinfo, all_clauses);
+	if (indlist == NIL)
+		return NIL;
+
+	/*
+	 * OK, pick the most promising AND combination, and add it to
+	 * pathlist.
+	 */
+	foreach (lc, indlist)
+	{
+		List *plist = lfirst_node(List, lc);
+
+		bitmapqual = choose_bitmap_and(root, rel, plist);
+		pathlist = lappend(pathlist, bitmapqual);
+	}
+
+	return pathlist;
+}
+
 /*
  * generate_bitmap_or_paths
- *		Look through the list of clauses to find OR clauses, and generate
- *		a BitmapOrPath for each one we can handle that way.  Return a list
- *		of the generated BitmapOrPaths.
+ *		Look through the list of clauses to find OR and SAOP clauses, and
+ *		Each saop clause are splitted to be covered by partial indexes.
+ *		generate a BitmapOrPath for each one we can handle that way.
+ *		Return a list of the generated BitmapOrPaths.
  *
  * other_clauses is a list of additional clauses that can be assumed true
  * for the purpose of generating indexquals, but are not to be searched for
@@ -1247,68 +1411,99 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	foreach(lc, clauses)
 	{
 		RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
-		List	   *pathlist;
+		List	   *pathlist = NIL;
 		Path	   *bitmapqual;
 		ListCell   *j;
 
-		/* Ignore RestrictInfos that aren't ORs */
-		if (!restriction_is_or_clause(rinfo))
+		if (restriction_is_saop_clause(rinfo))
+		{
+			pathlist = generate_saop_pathlist(root, rel, rinfo,
+											  all_clauses);
+		}
+		else if (!restriction_is_or_clause(rinfo))
+			/* Ignore RestrictInfos that aren't ORs */
 			continue;
-
-		/*
-		 * We must be able to match at least one index to each of the arms of
-		 * the OR, else we can't use it.
-		 */
-		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		else
 		{
-			Node	   *orarg = (Node *) lfirst(j);
-			List	   *indlist;
-
-			/* OR arguments should be ANDs or sub-RestrictInfos */
-			if (is_andclause(orarg))
+			/*
+			 * We must be able to match at least one index to each of the arms of
+			 * the OR, else we can't use it.
+			 */
+			foreach(j, ((BoolExpr *) rinfo->orclause)->args)
 			{
-				List	   *andargs = ((BoolExpr *) orarg)->args;
+				Node	   *orarg = (Node *) lfirst(j);
+				List	   *indlist;
 
-				indlist = build_paths_for_OR(root, rel,
-											 andargs,
-											 all_clauses);
+				/* OR arguments should be ANDs or sub-RestrictInfos */
+				if (is_andclause(orarg))
+				{
+					List	   *andargs = ((BoolExpr *) orarg)->args;
 
-				/* Recurse in case there are sub-ORs */
-				indlist = list_concat(indlist,
-									  generate_bitmap_or_paths(root, rel,
-															   andargs,
-															   all_clauses));
-			}
-			else
-			{
-				RestrictInfo *ri = castNode(RestrictInfo, orarg);
-				List	   *orargs;
+					indlist = build_paths_for_OR(root, rel,
+												 andargs,
+												 all_clauses);
 
-				Assert(!restriction_is_or_clause(ri));
-				orargs = list_make1(ri);
+					/* Recurse in case there are sub-ORs */
+					indlist = list_concat(indlist,
+										  generate_bitmap_or_paths(root, rel,
+																   andargs,
+																   all_clauses));
+				}
+				else
+				{
+					RestrictInfo *ri = castNode(RestrictInfo, orarg);
+					List	   *orargs;
 
-				indlist = build_paths_for_OR(root, rel,
-											 orargs,
-											 all_clauses);
-			}
+					Assert(!restriction_is_or_clause(ri));
 
-			/*
-			 * If nothing matched this arm, we can't do anything with this OR
-			 * clause.
-			 */
-			if (indlist == NIL)
-			{
-				pathlist = NIL;
-				break;
-			}
+					orargs = list_make1(ri);
 
-			/*
-			 * OK, pick the most promising AND combination, and add it to
-			 * pathlist.
-			 */
-			bitmapqual = choose_bitmap_and(root, rel, indlist);
-			pathlist = lappend(pathlist, bitmapqual);
+					if (restriction_is_saop_clause(ri))
+					{
+						List *paths;
+
+						paths = generate_saop_pathlist(root, rel, ri,
+														 all_clauses);
+
+						if (paths != NIL)
+						{
+							/*
+							 * Add paths to pathlist and immediately jump to the
+							 * next element of the OR clause.
+							 */
+							pathlist = list_concat(pathlist, paths);
+							continue;
+						}
+
+						/*
+						 * Pass down out of this if construction:
+						 * If saop isn't covered by partial indexes, try to
+						 * build scan path for the saop as a whole.
+						 */
+					}
+
+					indlist = build_paths_for_OR(root, rel,
+												 orargs,
+												 all_clauses);
+				}
+
+				/*
+				 * If nothing matched this arm, we can't do anything with this OR
+				 * clause.
+				 */
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+
+				/*
+				 * OK, pick the most promising AND combination, and add it to
+				 * pathlist.
+				 */
+				bitmapqual = choose_bitmap_and(root, rel, indlist);
+				pathlist = lappend(pathlist, bitmapqual);
+			}
 		}
 
 		/*
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index c37b416e24..8ed80a78b4 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -112,6 +112,52 @@ static Oid	get_btree_test_op(Oid pred_op, Oid clause_op, bool refute_it);
 static void InvalidateOprProofCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
 
 
+/*
+ * Could this ANY () expression can be split into a set of ANYs over partial
+ * indexes? If yes, return these saops in the PredicatesData structure.
+ */
+bool
+saop_covered_by_predicates(ScalarArrayOpExpr *saop, List *predicate_lists)
+{
+	ListCell		   *lc;
+	PredIterInfoData	clause_info;
+	bool				result = false;
+
+	if (predicate_classify((Node *) saop, &clause_info) != CLASS_OR)
+		return false;
+
+	iterate_begin(pitem, (Node *) saop, clause_info)
+	{
+		result = false;
+
+		foreach(lc, predicate_lists)
+		{
+			PredicatesData *pd = (PredicatesData *) lfirst(lc);
+
+			if (!predicate_implied_by_recurse(pitem, pd->predicate, false))
+				continue;
+
+			/* Predicate is found. Add the elem to the saop clause */
+			Assert(IsA(pitem, OpExpr));
+
+			/* Extract constant from the expression */
+			pd->elems = lappend(pd->elems,
+					copyObject(lsecond_node(Const, ((OpExpr *) pitem)->args)));
+			result = true;
+			break;
+		}
+
+		if (!result)
+			/*
+			 * The element doesn't fit any index. Interrupt the process immediately
+			 */
+			break;
+	}
+	iterate_end(clause_info);
+
+	return result;
+}
+
 /*
  * predicate_implied_by
  *	  Recursively checks whether the clauses in clause_list imply that the
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e9334..1dad1dc654 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -421,6 +421,19 @@ restriction_is_or_clause(RestrictInfo *restrictinfo)
 		return false;
 }
 
+bool
+restriction_is_saop_clause(RestrictInfo *restrictinfo)
+{
+	if (restrictinfo->clause && IsA(restrictinfo->clause, ScalarArrayOpExpr))
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) restrictinfo->clause;
+
+		if (saop->useOr)
+			return true;
+	}
+	return false;
+}
+
 /*
  * restriction_is_securely_promotable
  *
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 35ab577501..232afcd00c 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -160,6 +160,22 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+/*
+ * Contains information needed to extract from saop a set of elements which can
+ * be covered by the partial index:
+ * id - caller's identification of the index.
+ * predicate - predicate expression of the index
+ * elems - returning list of array elements which corresponds to this predicate
+ */
+typedef struct PredicatesData
+{
+	int		id;
+	Node   *predicate;
+	List   *elems;
+} PredicatesData;
+
+extern bool saop_covered_by_predicates(ScalarArrayOpExpr *saop,
+									  List *predicate_lists);
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c5..2cd5fbf943 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -34,6 +34,7 @@ extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Relids outer_relids);
 extern RestrictInfo *commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op);
 extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
+extern bool restriction_is_saop_clause(RestrictInfo *restrictinfo);
 extern bool restriction_is_securely_promotable(RestrictInfo *restrictinfo,
 											   RelOptInfo *rel);
 extern List *get_actual_clauses(List *restrictinfo_list);
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e..070202b0f0 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -907,6 +907,288 @@ select unique1, unique2 from onek2
        0 |     998
 (2 rows)
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: ((stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Without the transformation only seqscan possible here
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                         QUERY PLAN                                          
+---------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])) AND (stringu1 < 'Z'::name))
+(2 rows)
+
+-- Use partial indexes
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+                 QUERY PLAN                 
+--------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = 1) OR (unique2 = 3))
+(2 rows)
+
+RESET enable_or_transformation;
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+-- Don't scan partial indexes because of extra value.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+                      QUERY PLAN                      
+------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on onek2
+         Filter: (stringu1 = ANY ('{A,J,C}'::name[]))
+(3 rows)
+
+explain (costs off)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+                                      QUERY PLAN                                       
+---------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (stringu1 < 'B'::name)
+   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = ANY ('{A,A}'::name[])))
+   ->  Bitmap Index Scan on onek2_u2_prtl
+(4 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                                          QUERY PLAN                                                           
+-------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name)) OR ((unique2 < 1) AND (stringu1 < 'B'::name)))
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: ((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 < 1)
+(8 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 = 3) OR (unique1 = 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 3)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 1)
+(7 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+                                                             QUERY PLAN                                                             
+------------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = ((random() * '2'::double precision))::integer) OR (unique1 = ((random() * '3'::double precision))::integer))
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+                                                           QUERY PLAN                                                            
+---------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: (unique1 = ANY (ARRAY[((random() * '2'::double precision))::integer, ((random() * '3'::double precision))::integer]))
+(2 rows)
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+                                                                                          QUERY PLAN                                                                                          
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[]))) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 = ANY ('{1,2,21}'::integer[])) AND ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 = ANY ('{3,4}'::integer[])) OR (stringu1 = 'J'::name)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[])))
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(11 rows)
+
+-- Check recursive combination of OR and SAOP expressions
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR (unique1 < 1))
+   Filter: ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 < 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+(9 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR (unique1 < 1))
+   Filter: ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 < 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+(9 rows)
+
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+RESET enable_indexscan;
+RESET enable_seqscan;
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql
index 019f1e7673..0e650a2301 100644
--- a/src/test/regress/sql/select.sql
+++ b/src/test/regress/sql/select.sql
@@ -234,6 +234,88 @@ select unique1, unique2 from onek2
 select unique1, unique2 from onek2
   where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+-- Without the transformation only seqscan possible here
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+-- Use partial indexes
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+RESET enable_or_transformation;
+
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+
+-- Don't scan partial indexes because of extra value.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+explain (costs off)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+
+-- Check recursive combination of OR and SAOP expressions
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+
+RESET enable_indexscan;
+RESET enable_seqscan;
+
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index adae668b37..a1d43283db 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2138,6 +2138,7 @@ PredIterInfoData
 PredXactList
 PredicateLockData
 PredicateLockTargetType
+PredicatesData
 PrefetchBufferResult
 PrepParallelRestorePtrType
 PrepareStmt
-- 
2.43.0

#135Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Andrei Lepikhov (#133)
Re: POC, WIP: OR-clause support for indexes

On 13/2/2024 17:03, Andrei Lepikhov wrote:

On 13/2/2024 07:00, jian he wrote:

The time is the last result of the 10 iterations.

I'm not sure about the origins of such behavior, but it seems to be an
issue of parallel workers, not this specific optimization.

Having written that, I'd got a backburner. And to close that issue, I
explored get_restriction_qual_cost(). A close look shows us that "x IN
(..)" cheaper than its equivalent "x=N1 OR ...". Just numbers:

ANY: startup_cost = 0.0225; total_cost = 0.005
OR: startup_cost==0; total_cost = 0.0225

Expression total_cost is calculated per tuple. In your example, we have
many tuples, so the low cost of expression per tuple dominates over the
significant startup cost.

According to the above, SAOP adds 6250 to the cost of SeqScan; OR -
13541. So, the total cost of the query with SAOP is less than with OR,
and the optimizer doesn't choose heavy parallel workers. And it is the
answer.

So, this example is more about the subtle balance between
parallel/sequential execution, which can vary from one platform to another.

--
regards,
Andrei Lepikhov
Postgres Professional

#136jian he
jian.universality@gmail.com
In reply to: Andrei Lepikhov (#135)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Wed, Feb 14, 2024 at 11:21 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

So, this example is more about the subtle balance between
parallel/sequential execution, which can vary from one platform to another.

Hi, here I attached two files, expression_num_or_1_100.sql,
expression_num_or_1_10000.sql
it has step by step test cases, also with the tests output.

For both sql files, I already set the max_parallel_workers_per_gather to
10, work_mem to 4GB.
I think the parameters setting should be fine.

in expression_num_or_1_100.sql:
main test table:
create table test_1_100 as (select
(random()*1000)::int x, (random()*1000) y from
generate_series(1,1_000_000) i);

if the number of OR exceeds 29,
the performance with enable_or_transformation (ON) begins to outpace
enable_or_transformation (OFF).

if the number of OR less than 29,
the performance with enable_or_transformation (OFF) is better than
enable_or_transformation (ON).

expression_num_or_1_10000.sql
enable_or_transformation (ON) is always better than
enable_or_transformation (OFF).

My OS: Ubuntu 22.04.3 LTS
I already set the max_parallel_workers_per_gather to 10.
So for all cases, it should use parallelism first?

a better question would be:
how to make the number of OR less than 29 still faster when
enable_or_transformation is ON by only set parameters?

Attachments:

expression_num_or_1_100.sqlapplication/sql; name=expression_num_or_1_100.sqlDownload
expression_num_or_1_10000.sqlapplication/sql; name=expression_num_or_1_10000.sqlDownload
#137Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: jian he (#136)
Re: POC, WIP: OR-clause support for indexes

On 16/2/2024 07:00, jian he wrote:

On Wed, Feb 14, 2024 at 11:21 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:
My OS: Ubuntu 22.04.3 LTS
I already set the max_parallel_workers_per_gather to 10.
So for all cases, it should use parallelism first?

a better question would be:
how to make the number of OR less than 29 still faster when
enable_or_transformation is ON by only set parameters?

In my test environment this example gives some subtle supremacy to ORs
over ANY with only 3 ors and less.
Please, provide next EXPLAIN ANALYZE results for the case you want to
discuss here:
1. with enable_or_transformation enabled
2. with enable_or_transformation disabled
3. with enable_or_transformation disabled but with manual transformation
OR -> ANY done, to check the overhead of this optimization.

--
regards,
Andrei Lepikhov
Postgres Professional

#138jian he
jian.universality@gmail.com
In reply to: Andrei Lepikhov (#137)
Re: POC, WIP: OR-clause support for indexes

On Fri, Feb 16, 2024 at 1:32 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 16/2/2024 07:00, jian he wrote:

On Wed, Feb 14, 2024 at 11:21 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:
My OS: Ubuntu 22.04.3 LTS
I already set the max_parallel_workers_per_gather to 10.
So for all cases, it should use parallelism first?

a better question would be:
how to make the number of OR less than 29 still faster when
enable_or_transformation is ON by only set parameters?

In my test environment this example gives some subtle supremacy to ORs
over ANY with only 3 ors and less.
Please, provide next EXPLAIN ANALYZE results for the case you want to
discuss here:
1. with enable_or_transformation enabled
2. with enable_or_transformation disabled
3. with enable_or_transformation disabled but with manual transformation
OR -> ANY done, to check the overhead of this optimization.

you previously mentioned playing with parallel_tuple_cost and
parallel_setup_cost.
(/messages/by-id/e3338e82-a28d-4631-9eec-b9c0984b32d5@postgrespro.ru)

So I did by
`
SET parallel_setup_cost = 0;
SET parallel_tuple_cost = 0;
`

After setting these parameters, overall enable_or_transformation ON is
performance better.
sorry for the noise.
so now I didn't find any corner case where enable_or_transformation is
ON peforms worse than when it's OFF.

+typedef struct OrClauseGroupEntry
+{
+ OrClauseGroupKey key;
+
+ Node   *node;
+ List   *consts;
+ Oid scalar_type;
+ List   *exprs;
+} OrClauseGroupEntry;

I found that the field `scalar_type` was never used.

#139Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: jian he (#138)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 16/2/2024 19:54, jian he wrote:

After setting these parameters, overall enable_or_transformation ON is
performance better.
sorry for the noise.

Don't worry, at least we know a weak point of partial paths estimation.

so now I didn't find any corner case where enable_or_transformation is
ON peforms worse than when it's OFF.

+typedef struct OrClauseGroupEntry
+{
+ OrClauseGroupKey key;
+
+ Node   *node;
+ List   *consts;
+ Oid scalar_type;
+ List   *exprs;
+} OrClauseGroupEntry;

I found that the field `scalar_type` was never used.

Thanks, fixed.
In attachment - v17 for both patches. As I see it, the only general
explanation of the idea is not addressed. I'm not sure how deeply we
should explain it.

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v17-0001-Transform-OR-clause-to-ANY-expressions.patchtext/plain; charset=UTF-8; name=v17-0001-Transform-OR-clause-to-ANY-expressions.patchDownload
From 3a3b6aa36320a06b64f2f608e3526255e53ed655 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Fri, 2 Feb 2024 22:01:09 +0300
Subject: [PATCH 1/2] Transform OR clause to ANY expressions.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(C1, C2, ...) on the
preliminary stage of optimization when we are still working with the tree
expression.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
---
 .../postgres_fdw/expected/postgres_fdw.out    |  16 +-
 src/backend/nodes/queryjumblefuncs.c          |  27 ++
 src/backend/parser/parse_expr.c               | 326 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  11 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/bin/pg_dump/t/002_pg_dump.pl              |   6 +-
 src/include/nodes/queryjumble.h               |   1 +
 src/include/optimizer/optimizer.h             |   1 +
 src/test/regress/expected/create_index.out    | 156 ++++++++-
 src/test/regress/expected/inherit.out         |   2 +-
 src/test/regress/expected/join.out            |  62 +++-
 src/test/regress/expected/partition_prune.out | 219 ++++++++++--
 src/test/regress/expected/rules.out           |   4 +-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  35 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 21 files changed, 875 insertions(+), 70 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index c355e8f3f7..0523bbd8f7 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -1349,7 +1349,7 @@ SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE
  Foreign Scan
    Output: t1.c1, t1.c2, ft5.c1, ft5.c2
    Relations: (public.ft4 t1) LEFT JOIN (public.ft5)
-   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 < 10) OR (r4.c1 IS NULL))) AND ((r1.c1 < 10))
+   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 IS NULL) OR (r4.c1 < 10))) AND ((r1.c1 < 10))
 (4 rows)
 
 SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE c1 < 10) t2 ON (t1.c1 = t2.c1)
@@ -3105,7 +3105,7 @@ select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3123,7 +3123,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3140,7 +3140,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST)), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -8797,18 +8797,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 82f725baaa..b203746be4 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -141,6 +141,33 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 9300c7b9ab..279713d5ae 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,14 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -38,11 +40,13 @@
 #include "utils/date.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +103,326 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+
+	Node		   *node;
+	List		   *consts;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function to find candidate clauses.
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				hash;
+
+	Assert(keysize == sizeof(OrClauseGroupKey));
+
+	(void) JumbleExpr(key->expr, &hash);
+	hash += ((uint64) key->opno + (uint64) key->exprtype);
+	return (uint32) (hash % UINT32_MAX);
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in guc_hashtab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+static Node *
+transformBoolExprOr(ParseState *pstate, BoolExpr *expr)
+{
+	List				   *or_list = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(expr->args);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	/* If this is not an 'OR' expression, skip the transformation */
+	if (!enable_or_transformation || expr->boolop != OR_EXPR || len_ors < 2)
+		return transformBoolExpr(pstate, (BoolExpr *) expr);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, expr->args)
+	{
+		Node				   *arg = lfirst(lc);
+		Node				   *orqual;
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Oid						exprtype;
+		Node				   *leftop, *rightop;
+
+		/* At first, transform the arg and evaluate constant expressions. */
+		orqual = transformExprRecurse(pstate, (Node *) arg);
+		orqual = coerce_to_boolean(pstate, orqual, "OR");
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Transformation only works with both side type is not
+		 * { array | composite | domain | record }.
+		 * Also, forbid it for volatile expressions.
+		 */
+		exprtype = exprType(nconst_expr);
+		if (type_is_rowtype(exprType(const_expr)) ||
+			type_is_rowtype(exprtype) ||
+			contain_volatile_functions((Node *) nconst_expr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.exprtype = exprtype;
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->node = nconst_expr;
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element in the class. Return origin expression into
+			 * the BoolExpr args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.exprtype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+											   InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+			ListCell		   *lc1;
+
+			foreach(lc1, entry->consts)
+			{
+				Node   *rexpr = (Node *) lfirst(lc1);
+
+				rexpr = coerce_to_common_type(pstate, rexpr,
+											  scalar_type,
+											  "IN");
+				aexprs = lappend(aexprs, rexpr);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 entry->node,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, expr->location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -212,7 +536,7 @@ transformExprRecurse(ParseState *pstate, Node *expr)
 			}
 
 		case T_BoolExpr:
-			result = transformBoolExpr(pstate, (BoolExpr *) expr);
+			result = transformBoolExprOr(pstate, (BoolExpr *) expr);
 			break;
 
 		case T_FuncCall:
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 70652f0a3f..f42711f336 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1071,6 +1071,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index e10755972a..f8058e05f5 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -379,6 +379,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 00b5092713..d28bf617db 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -2095,9 +2095,9 @@ my %tests = (
 		regexp => qr/^
 			\QCREATE DOMAIN dump_test.us_postal_code AS text COLLATE pg_catalog."C" DEFAULT '10014'::text\E\n\s+
 			\QCONSTRAINT us_postal_code_check CHECK \E
-			\Q(((VALUE ~ '^\d{5}\E
-			\$\Q'::text) OR (VALUE ~ '^\d{5}-\d{4}\E\$
-			\Q'::text)));\E(.|\n)*
+			\Q((VALUE ~ ANY (ARRAY['^\d{5}\E
+			\$\Q'::text, '^\d{5}-\d{4}\E\$
+			\Q'::text])));\E(.|\n)*
 			\QCOMMENT ON CONSTRAINT us_postal_code_check ON DOMAIN dump_test.us_postal_code IS 'check it';\E
 			/xm,
 		like =>
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067..a9ae048af5 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 7b63c5cf71..35ab577501 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -50,6 +50,7 @@ struct PlannedStmt;
 struct ParamListInfoData;
 struct HeapTupleData;
 
+extern PGDLLIMPORT bool enable_or_transformation;
 
 /* in path/clausesel.c: */
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 79fa117cb5..b8653c09ea 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,116 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 1e6cc8e9ba..7cdf9d6412 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -2600,7 +2600,7 @@ explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd'
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 0c2cba8921..82a5f689a1 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 < 20) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 < 20) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 9a4c48c055..3423af4768 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -589,20 +611,20 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 ------------------------------------------------------
  Append
    ->  Seq Scan on rlp1 rlp_1
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
    ->  Seq Scan on rlp4_1 rlp_2
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
 (5 rows)
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -1933,10 +2112,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index b7488d760e..b424ad3154 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2501,7 +2501,7 @@ pg_stats| SELECT n.nspname AS schemaname,
      JOIN pg_class c ON ((c.oid = s.starelid)))
      JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
-  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2532,7 +2532,7 @@ pg_stats_ext| SELECT cn.nspname AS schemaname,
   WHERE ((NOT (EXISTS ( SELECT 1
            FROM (unnest(s.stxkeys) k(k)
              JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
-          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext_exprs| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 10903bdab0..6f55b9e3ec 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 9be7aca2b8..1f9029b5b2 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -124,6 +124,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -134,7 +135,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(23 rows)
+(24 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..2a079e996b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..56fde15bc1 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 257f727a2b..0d1427c115 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7bf3920827..1e270ae9c0 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index d808aad8b0..f8d5871153 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1654,6 +1654,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.43.0

v17-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchtext/plain; charset=UTF-8; name=v17-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchDownload
From 82a14d2adbe9638abf13e4518b0836141ff46452 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Wed, 24 Jan 2024 14:07:17 +0700
Subject: [PATCH 2/2] Teach generate_bitmap_or_paths to build BitmapOr paths
 over SAOP clauses.

Likewise OR clauses, discover SAOP array and try to split its elements
between smaller sized arrays to fit a set of partial indexes.
---
 src/backend/optimizer/path/indxpath.c     | 301 ++++++++++++++++++----
 src/backend/optimizer/util/predtest.c     |  46 ++++
 src/backend/optimizer/util/restrictinfo.c |  13 +
 src/include/optimizer/optimizer.h         |  16 ++
 src/include/optimizer/restrictinfo.h      |   1 +
 src/test/regress/expected/select.out      | 282 ++++++++++++++++++++
 src/test/regress/sql/select.sql           |  82 ++++++
 src/tools/pgindent/typedefs.list          |   1 +
 8 files changed, 689 insertions(+), 53 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 32c6a8bbdc..56b04541db 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,6 +32,7 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
 
@@ -1220,11 +1221,174 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Building index paths over SAOP clause differs from the logic of OR clauses.
+ * Here we iterate across all the array elements and split them to SAOPs,
+ * corresponding to different indexes. We must match each element to an index.
+ */
+static List *
+build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
+					 List *other_clauses)
+{
+	List			   *result = NIL;
+	List			   *predicate_lists = NIL;
+	ListCell		   *lc;
+	PredicatesData	   *pd;
+	ScalarArrayOpExpr  *saop = (ScalarArrayOpExpr *) rinfo->clause;
+
+	Assert(IsA(saop, ScalarArrayOpExpr) && saop->useOr);
+
+	if (!IsA(lsecond(saop->args), Const))
+		/*
+		 * Has it practical outcome to merge arrays which couldn't constantified
+		 * before that step?
+		 */
+		return NIL;
+
+	/* Collect predicates */
+	foreach(lc, rel->indexlist)
+	{
+		IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
+
+		/* Take into consideration partial indexes supporting bitmap scans */
+		if (!index->amhasgetbitmap || index->indpred == NIL || index->predOK)
+			continue;
+
+		pd = palloc0(sizeof(PredicatesData));
+		pd->id = foreach_current_index(lc);
+		/* The trick with reducing recursion is stolen from predicate_implied_by */
+		pd->predicate = list_length(index->indpred) == 1 ?
+										(Node *) linitial(index->indpred) :
+										(Node *) index->indpred;
+		predicate_lists = lappend(predicate_lists, (void *) pd);
+	}
+
+	/* Split the array data according to index predicates. */
+	if (predicate_lists == NIL ||
+		!saop_covered_by_predicates(saop, predicate_lists))
+		return NIL;
+
+	other_clauses = list_delete_ptr(other_clauses, rinfo);
+
+	/*
+	 * Having incoming SAOP split to set of smaller SAOPs which can be applied
+	 * to partial indexes, generate paths for each one.
+	 */
+	foreach(lc, predicate_lists)
+	{
+		IndexOptInfo	   *index;
+		IndexClauseSet		clauseset;
+		List			   *indexpaths;
+		RestrictInfo	   *rinfo1 = NULL;
+		Expr			   *clause;
+		ArrayType		   *arrayval = NULL;
+		ArrayExpr		   *arr = NULL;
+		Const			   *arrayconst = lsecond_node(Const, saop->args);
+		ScalarArrayOpExpr  *dest = makeNode(ScalarArrayOpExpr);
+
+		pd = (PredicatesData *) lfirst(lc);
+		if (pd->elems == NIL)
+			/* The index doesn't participate in this operation */
+			continue;
+
+		/* Make up new array */
+		arrayval = DatumGetArrayTypeP(arrayconst->constvalue);
+		arr = makeNode(ArrayExpr);
+		arr->array_collid = arrayconst->constcollid;
+		arr->array_typeid = arrayconst->consttype;
+		arr->element_typeid = arrayval->elemtype;
+		arr->elements = pd->elems;
+		arr->location = -1;
+		arr->multidims = false;
+
+		/* Compose new SAOP, partially covering the source one */
+		memcpy(dest, saop, sizeof(ScalarArrayOpExpr));
+		dest->args = list_make2(linitial(saop->args), arr);
+
+		clause = (Expr *) estimate_expression_value(root, (Node *) dest);
+
+		/*
+		 * Create new RestrictInfo. It maybe more heavy than just copy node,
+		 * but remember some internals: the serial number, selectivity
+		 * cache etc.
+		 */
+		rinfo1 = make_restrictinfo(root, clause,
+								   rinfo->is_pushed_down,
+								   rinfo->has_clone,
+								   rinfo->is_clone,
+								   rinfo->pseudoconstant,
+								   rinfo->security_level,
+								   rinfo->required_relids,
+								   rinfo->incompatible_relids,
+								   rinfo->outer_relids);
+
+		index = list_nth(rel->indexlist, pd->id);
+		Assert(predicate_implied_by(index->indpred, list_make1(rinfo1), true));
+
+		/* Excluding partial indexes with predOK we make this statement false */
+		Assert(!predicate_implied_by(index->indpred, other_clauses, false));
+
+		/* Time to generate index paths */
+
+		MemSet(&clauseset, 0, sizeof(clauseset));
+		match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);
+		match_clauses_to_index(root, other_clauses, index, &clauseset);
+
+		/* Predicate has found already. So, it is ok for the empty match */
+
+		indexpaths = build_index_paths(root, rel,
+									   index, &clauseset,
+									   true,
+									   ST_BITMAPSCAN,
+									   NULL,
+									   NULL);
+		Assert(indexpaths != NIL);
+		result = lappend(result, indexpaths);
+	}
+	return result;
+}
+
+static List *
+generate_saop_pathlist(PlannerInfo *root, RelOptInfo *rel,
+					   RestrictInfo *rinfo, List *all_clauses)
+{
+	List	   *pathlist = NIL;
+	Path	   *bitmapqual;
+	List	   *indlist;
+	ListCell   *lc;
+
+	if (!enable_or_transformation)
+		return NIL;
+
+	/*
+	 * We must be able to match at least one index to each element of
+	 * the array, else we can't use it.
+	 */
+	indlist = build_paths_for_SAOP(root, rel, rinfo, all_clauses);
+	if (indlist == NIL)
+		return NIL;
+
+	/*
+	 * OK, pick the most promising AND combination, and add it to
+	 * pathlist.
+	 */
+	foreach (lc, indlist)
+	{
+		List *plist = lfirst_node(List, lc);
+
+		bitmapqual = choose_bitmap_and(root, rel, plist);
+		pathlist = lappend(pathlist, bitmapqual);
+	}
+
+	return pathlist;
+}
+
 /*
  * generate_bitmap_or_paths
- *		Look through the list of clauses to find OR clauses, and generate
- *		a BitmapOrPath for each one we can handle that way.  Return a list
- *		of the generated BitmapOrPaths.
+ *		Look through the list of clauses to find OR and SAOP clauses, and
+ *		Each saop clause are splitted to be covered by partial indexes.
+ *		generate a BitmapOrPath for each one we can handle that way.
+ *		Return a list of the generated BitmapOrPaths.
  *
  * other_clauses is a list of additional clauses that can be assumed true
  * for the purpose of generating indexquals, but are not to be searched for
@@ -1247,68 +1411,99 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	foreach(lc, clauses)
 	{
 		RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
-		List	   *pathlist;
+		List	   *pathlist = NIL;
 		Path	   *bitmapqual;
 		ListCell   *j;
 
-		/* Ignore RestrictInfos that aren't ORs */
-		if (!restriction_is_or_clause(rinfo))
+		if (restriction_is_saop_clause(rinfo))
+		{
+			pathlist = generate_saop_pathlist(root, rel, rinfo,
+											  all_clauses);
+		}
+		else if (!restriction_is_or_clause(rinfo))
+			/* Ignore RestrictInfos that aren't ORs */
 			continue;
-
-		/*
-		 * We must be able to match at least one index to each of the arms of
-		 * the OR, else we can't use it.
-		 */
-		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		else
 		{
-			Node	   *orarg = (Node *) lfirst(j);
-			List	   *indlist;
-
-			/* OR arguments should be ANDs or sub-RestrictInfos */
-			if (is_andclause(orarg))
+			/*
+			 * We must be able to match at least one index to each of the arms of
+			 * the OR, else we can't use it.
+			 */
+			foreach(j, ((BoolExpr *) rinfo->orclause)->args)
 			{
-				List	   *andargs = ((BoolExpr *) orarg)->args;
+				Node	   *orarg = (Node *) lfirst(j);
+				List	   *indlist;
 
-				indlist = build_paths_for_OR(root, rel,
-											 andargs,
-											 all_clauses);
+				/* OR arguments should be ANDs or sub-RestrictInfos */
+				if (is_andclause(orarg))
+				{
+					List	   *andargs = ((BoolExpr *) orarg)->args;
 
-				/* Recurse in case there are sub-ORs */
-				indlist = list_concat(indlist,
-									  generate_bitmap_or_paths(root, rel,
-															   andargs,
-															   all_clauses));
-			}
-			else
-			{
-				RestrictInfo *ri = castNode(RestrictInfo, orarg);
-				List	   *orargs;
+					indlist = build_paths_for_OR(root, rel,
+												 andargs,
+												 all_clauses);
 
-				Assert(!restriction_is_or_clause(ri));
-				orargs = list_make1(ri);
+					/* Recurse in case there are sub-ORs */
+					indlist = list_concat(indlist,
+										  generate_bitmap_or_paths(root, rel,
+																   andargs,
+																   all_clauses));
+				}
+				else
+				{
+					RestrictInfo *ri = castNode(RestrictInfo, orarg);
+					List	   *orargs;
 
-				indlist = build_paths_for_OR(root, rel,
-											 orargs,
-											 all_clauses);
-			}
+					Assert(!restriction_is_or_clause(ri));
 
-			/*
-			 * If nothing matched this arm, we can't do anything with this OR
-			 * clause.
-			 */
-			if (indlist == NIL)
-			{
-				pathlist = NIL;
-				break;
-			}
+					orargs = list_make1(ri);
 
-			/*
-			 * OK, pick the most promising AND combination, and add it to
-			 * pathlist.
-			 */
-			bitmapqual = choose_bitmap_and(root, rel, indlist);
-			pathlist = lappend(pathlist, bitmapqual);
+					if (restriction_is_saop_clause(ri))
+					{
+						List *paths;
+
+						paths = generate_saop_pathlist(root, rel, ri,
+														 all_clauses);
+
+						if (paths != NIL)
+						{
+							/*
+							 * Add paths to pathlist and immediately jump to the
+							 * next element of the OR clause.
+							 */
+							pathlist = list_concat(pathlist, paths);
+							continue;
+						}
+
+						/*
+						 * Pass down out of this if construction:
+						 * If saop isn't covered by partial indexes, try to
+						 * build scan path for the saop as a whole.
+						 */
+					}
+
+					indlist = build_paths_for_OR(root, rel,
+												 orargs,
+												 all_clauses);
+				}
+
+				/*
+				 * If nothing matched this arm, we can't do anything with this OR
+				 * clause.
+				 */
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+
+				/*
+				 * OK, pick the most promising AND combination, and add it to
+				 * pathlist.
+				 */
+				bitmapqual = choose_bitmap_and(root, rel, indlist);
+				pathlist = lappend(pathlist, bitmapqual);
+			}
 		}
 
 		/*
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index c37b416e24..8ed80a78b4 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -112,6 +112,52 @@ static Oid	get_btree_test_op(Oid pred_op, Oid clause_op, bool refute_it);
 static void InvalidateOprProofCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
 
 
+/*
+ * Could this ANY () expression can be split into a set of ANYs over partial
+ * indexes? If yes, return these saops in the PredicatesData structure.
+ */
+bool
+saop_covered_by_predicates(ScalarArrayOpExpr *saop, List *predicate_lists)
+{
+	ListCell		   *lc;
+	PredIterInfoData	clause_info;
+	bool				result = false;
+
+	if (predicate_classify((Node *) saop, &clause_info) != CLASS_OR)
+		return false;
+
+	iterate_begin(pitem, (Node *) saop, clause_info)
+	{
+		result = false;
+
+		foreach(lc, predicate_lists)
+		{
+			PredicatesData *pd = (PredicatesData *) lfirst(lc);
+
+			if (!predicate_implied_by_recurse(pitem, pd->predicate, false))
+				continue;
+
+			/* Predicate is found. Add the elem to the saop clause */
+			Assert(IsA(pitem, OpExpr));
+
+			/* Extract constant from the expression */
+			pd->elems = lappend(pd->elems,
+					copyObject(lsecond_node(Const, ((OpExpr *) pitem)->args)));
+			result = true;
+			break;
+		}
+
+		if (!result)
+			/*
+			 * The element doesn't fit any index. Interrupt the process immediately
+			 */
+			break;
+	}
+	iterate_end(clause_info);
+
+	return result;
+}
+
 /*
  * predicate_implied_by
  *	  Recursively checks whether the clauses in clause_list imply that the
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e9334..1dad1dc654 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -421,6 +421,19 @@ restriction_is_or_clause(RestrictInfo *restrictinfo)
 		return false;
 }
 
+bool
+restriction_is_saop_clause(RestrictInfo *restrictinfo)
+{
+	if (restrictinfo->clause && IsA(restrictinfo->clause, ScalarArrayOpExpr))
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) restrictinfo->clause;
+
+		if (saop->useOr)
+			return true;
+	}
+	return false;
+}
+
 /*
  * restriction_is_securely_promotable
  *
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 35ab577501..232afcd00c 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -160,6 +160,22 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+/*
+ * Contains information needed to extract from saop a set of elements which can
+ * be covered by the partial index:
+ * id - caller's identification of the index.
+ * predicate - predicate expression of the index
+ * elems - returning list of array elements which corresponds to this predicate
+ */
+typedef struct PredicatesData
+{
+	int		id;
+	Node   *predicate;
+	List   *elems;
+} PredicatesData;
+
+extern bool saop_covered_by_predicates(ScalarArrayOpExpr *saop,
+									  List *predicate_lists);
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c5..2cd5fbf943 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -34,6 +34,7 @@ extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Relids outer_relids);
 extern RestrictInfo *commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op);
 extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
+extern bool restriction_is_saop_clause(RestrictInfo *restrictinfo);
 extern bool restriction_is_securely_promotable(RestrictInfo *restrictinfo,
 											   RelOptInfo *rel);
 extern List *get_actual_clauses(List *restrictinfo_list);
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e..070202b0f0 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -907,6 +907,288 @@ select unique1, unique2 from onek2
        0 |     998
 (2 rows)
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: ((stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Without the transformation only seqscan possible here
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                         QUERY PLAN                                          
+---------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])) AND (stringu1 < 'Z'::name))
+(2 rows)
+
+-- Use partial indexes
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+                 QUERY PLAN                 
+--------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = 1) OR (unique2 = 3))
+(2 rows)
+
+RESET enable_or_transformation;
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+-- Don't scan partial indexes because of extra value.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+                      QUERY PLAN                      
+------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on onek2
+         Filter: (stringu1 = ANY ('{A,J,C}'::name[]))
+(3 rows)
+
+explain (costs off)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+                                      QUERY PLAN                                       
+---------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (stringu1 < 'B'::name)
+   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = ANY ('{A,A}'::name[])))
+   ->  Bitmap Index Scan on onek2_u2_prtl
+(4 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                                          QUERY PLAN                                                           
+-------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name)) OR ((unique2 < 1) AND (stringu1 < 'B'::name)))
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: ((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 < 1)
+(8 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 = 3) OR (unique1 = 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 3)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 1)
+(7 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+                                                             QUERY PLAN                                                             
+------------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = ((random() * '2'::double precision))::integer) OR (unique1 = ((random() * '3'::double precision))::integer))
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+                                                           QUERY PLAN                                                            
+---------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: (unique1 = ANY (ARRAY[((random() * '2'::double precision))::integer, ((random() * '3'::double precision))::integer]))
+(2 rows)
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+                                                                                          QUERY PLAN                                                                                          
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[]))) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 = ANY ('{1,2,21}'::integer[])) AND ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 = ANY ('{3,4}'::integer[])) OR (stringu1 = 'J'::name)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[])))
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(11 rows)
+
+-- Check recursive combination of OR and SAOP expressions
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR (unique1 < 1))
+   Filter: ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 < 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+(9 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR (unique1 < 1))
+   Filter: ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 < 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+(9 rows)
+
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+RESET enable_indexscan;
+RESET enable_seqscan;
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql
index 019f1e7673..0e650a2301 100644
--- a/src/test/regress/sql/select.sql
+++ b/src/test/regress/sql/select.sql
@@ -234,6 +234,88 @@ select unique1, unique2 from onek2
 select unique1, unique2 from onek2
   where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+-- Without the transformation only seqscan possible here
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+-- Use partial indexes
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+RESET enable_or_transformation;
+
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+
+-- Don't scan partial indexes because of extra value.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+explain (costs off)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+
+-- Check recursive combination of OR and SAOP expressions
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+
+RESET enable_indexscan;
+RESET enable_seqscan;
+
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index f8d5871153..3cb45efe60 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2138,6 +2138,7 @@ PredIterInfoData
 PredXactList
 PredicateLockData
 PredicateLockTargetType
+PredicatesData
 PrefetchBufferResult
 PrepParallelRestorePtrType
 PrepareStmt
-- 
2.43.0

#140Ranier Vilela
ranier.vf@gmail.com
In reply to: Andrei Lepikhov (#139)
Re: POC, WIP: OR-clause support for indexes

Em seg., 19 de fev. de 2024 às 05:35, Andrei Lepikhov <
a.lepikhov@postgrespro.ru> escreveu:

On 16/2/2024 19:54, jian he wrote:

After setting these parameters, overall enable_or_transformation ON is
performance better.
sorry for the noise.

Don't worry, at least we know a weak point of partial paths estimation.

so now I didn't find any corner case where enable_or_transformation is
ON peforms worse than when it's OFF.

+typedef struct OrClauseGroupEntry
+{
+ OrClauseGroupKey key;
+
+ Node   *node;
+ List   *consts;
+ Oid scalar_type;
+ List   *exprs;
+} OrClauseGroupEntry;

I found that the field `scalar_type` was never used.

Thanks, fixed.

Not that it will make a big difference, but it would be good to avoid, I
think.

v17-0002
1) move the vars *arrayconst and *dest, to after if, to avoid makeNode
(palloc).
+ Const   *arrayconst;
+ ScalarArrayOpExpr  *dest;
+
+ pd = (PredicatesData *) lfirst(lc);
+ if (pd->elems == NIL)
+ /* The index doesn't participate in this operation */
+ continue;
+ arrayconst = lsecond_node(Const, saop->args);
+ dest = makeNode(ScalarArrayOpExpr);

best regards,
Ranier Vilela

#141Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Ranier Vilela (#140)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 19/2/2024 19:53, Ranier Vilela wrote:

v17-0002
1) move the vars *arrayconst and *dest, to after if, to avoid makeNode 
(palloc).
+ Const   *arrayconst;
+ ScalarArrayOpExpr  *dest;
+
+ pd = (PredicatesData *) lfirst(lc);
+ if (pd->elems == NIL)
+ /* The index doesn't participate in this operation */
+ continue;
+ arrayconst = lsecond_node(Const, saop->args);
+ dest = makeNode(ScalarArrayOpExpr);

Thanks for the review!
I'm not sure I understand you clearly. Does the patch in attachment fix
the issue you raised?

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

fix.difftext/plain; charset=UTF-8; name=fix.diffDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 56b04541db..1545876e2f 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1284,7 +1284,7 @@ build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
 		ArrayType		   *arrayval = NULL;
 		ArrayExpr		   *arr = NULL;
 		Const			   *arrayconst = lsecond_node(Const, saop->args);
-		ScalarArrayOpExpr  *dest = makeNode(ScalarArrayOpExpr);
+		ScalarArrayOpExpr	dest;
 
 		pd = (PredicatesData *) lfirst(lc);
 		if (pd->elems == NIL)
@@ -1302,10 +1302,10 @@ build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
 		arr->multidims = false;
 
 		/* Compose new SAOP, partially covering the source one */
-		memcpy(dest, saop, sizeof(ScalarArrayOpExpr));
-		dest->args = list_make2(linitial(saop->args), arr);
+		memcpy(&dest, saop, sizeof(ScalarArrayOpExpr));
+		dest.args = list_make2(linitial(saop->args), arr);
 
-		clause = (Expr *) estimate_expression_value(root, (Node *) dest);
+		clause = (Expr *) estimate_expression_value(root, (Node *) &dest);
 
 		/*
 		 * Create new RestrictInfo. It maybe more heavy than just copy node,
#142jian he
jian.universality@gmail.com
In reply to: Andrei Lepikhov (#139)
Re: POC, WIP: OR-clause support for indexes

On Mon, Feb 19, 2024 at 4:35 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

In attachment - v17 for both patches. As I see it, the only general
explanation of the idea is not addressed. I'm not sure how deeply we
should explain it.

On Tue, Nov 28, 2023 at 5:04 AM Robert Haas <robertmhaas@gmail.com> wrote:

On Mon, Nov 27, 2023 at 3:02 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 25/11/2023 08:23, Alexander Korotkov wrote:

I think patch certainly gets better in this aspect. One thing I can't
understand is why do we use home-grown code for resolving
hash-collisions. You can just define custom hash and match functions
in HASHCTL. Even if we need to avoid repeated JumbleExpr calls, we
still can save pre-calculated hash value into hash entry and use
custom hash and match. This doesn't imply us to write our own
collision-resolving code.

Thanks, it was an insightful suggestion.
I implemented it, and the code has become shorter (see attachment).

Neither the code comments nor the commit message really explain the
design idea here. That's unfortunate, principally because it makes
review difficult.

I'm very skeptical about the idea of using JumbleExpr for any part of
this. It seems fairly expensive, and it might produce false matches.
If expensive is OK, then why not just use equal()? If it's not, then
this probably isn't really OK either. But in any case there should be
comments explaining why this strategy was chosen.

The above message
(/messages/by-id/CA+TgmoZCgP6FrBQEusn4yaWm02XU8OPeoEMk91q7PRBgwaAkFw@mail.gmail.com)
seems still not answered.
How can we evaluate whether JumbleExpr is expensive or not?
I used this naive script to test, but didn't find a big difference
when enable_or_transformation is ON or OFF.

`
create table test_1_100 as (select (random()*1000)::int x,
(random()*1000) y from generate_series(1,1_000_000) i);
explain(costs off, analyze)
select * from test
where x = 1 or x + 2= 3 or x + 3= 4 or x + 4= 5
or x + 5= 6 or x + 6= 7 or x + 7= 8 or x + 8= 9 or x + 9=10
or x + 10= 11 or x + 11= 12 or x + 12= 13 or x + 13= 14
or x + 14= 15 or x + 15= 16 or x + 16= 17 or x + 17= 18
or x + 18=19 or x + 19= 20 or x + 20= 21 or x + 21= 22
or x + 22= 23 or x + 23= 24 or x + 24= 25 or x + 25= 26
or x + 26= 27 or x + 27=28 or x + 28= 29 or x + 29= 30
or x + 30= 31 \watch i=0.1 c=10
`

`leftop operator rightop`
the operator can also be volatile.
Do we need to check (op_volatile(opno) == PROVOLATILE_VOLATILE) within
transformBoolExprOr?

#143Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: jian he (#142)
Re: POC, WIP: OR-clause support for indexes

On 20/2/2024 11:03, jian he wrote:

Neither the code comments nor the commit message really explain the
design idea here. That's unfortunate, principally because it makes
review difficult.

I'm very skeptical about the idea of using JumbleExpr for any part of
this. It seems fairly expensive, and it might produce false matches.
If expensive is OK, then why not just use equal()? If it's not, then
this probably isn't really OK either. But in any case there should be
comments explaining why this strategy was chosen.

The above message
(/messages/by-id/CA+TgmoZCgP6FrBQEusn4yaWm02XU8OPeoEMk91q7PRBgwaAkFw@mail.gmail.com)
seems still not answered.
How can we evaluate whether JumbleExpr is expensive or not?
I used this naive script to test, but didn't find a big difference
when enable_or_transformation is ON or OFF.

First, I am open to discussion here. But IMO, equal() operation is quite
expensive by itself. We should use the hash table approach to avoid
quadratic behaviour when looking for similar clauses in the 'OR' list.
Moreover, we use equal() in many places: selectivity estimations,
proving of fitting the index, predtest, etc. So, by reducing the clause
list, we eliminate many calls of the equal() routine, too.

`leftop operator rightop`
the operator can also be volatile.
Do we need to check (op_volatile(opno) == PROVOLATILE_VOLATILE) within
transformBoolExprOr?

As usual, could you provide a test case to discuss it more objectively?

--
regards,
Andrei Lepikhov
Postgres Professional

#144Ranier Vilela
ranier.vf@gmail.com
In reply to: Andrei Lepikhov (#141)
Re: POC, WIP: OR-clause support for indexes

Em ter., 20 de fev. de 2024 às 00:18, Andrei Lepikhov <
a.lepikhov@postgrespro.ru> escreveu:

On 19/2/2024 19:53, Ranier Vilela wrote:

v17-0002
1) move the vars *arrayconst and *dest, to after if, to avoid makeNode
(palloc).
+ Const   *arrayconst;
+ ScalarArrayOpExpr  *dest;
+
+ pd = (PredicatesData *) lfirst(lc);
+ if (pd->elems == NIL)
+ /* The index doesn't participate in this operation */
+ continue;
+ arrayconst = lsecond_node(Const, saop->args);
+ dest = makeNode(ScalarArrayOpExpr);

Thanks for the review!
I'm not sure I understand you clearly. Does the patch in attachment fix
the issue you raised?

Sorry if I wasn't clear.
What I meant is to move the initializations of the variables *arrayconst*
and *dest*
for after the test (if (pd->elems == NIL)
To avoid unnecessary initialization if the test fails.

best regards,
Ranier Vilela

#145jian he
jian.universality@gmail.com
In reply to: Ranier Vilela (#144)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi.
I wrote the first draft patch of the documentation.
it's under the section: Planner Method Configuration (runtime-config-query.html)
but this feature's main meat is in src/backend/parser/parse_expr.c
so it may be slightly inconsistent, as mentioned by others.

You can further furnish it.

Attachments:

v1-0001-Add-enable_or_transformation-doc-entry.no-cfbotapplication/octet-stream; name=v1-0001-Add-enable_or_transformation-doc-entry.no-cfbotDownload
From 6c6fc58facfcf8545f46c8e38eae5efd7918aa59 Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Sat, 24 Feb 2024 19:12:18 +0800
Subject: [PATCH v1 1/1] Add enable_or_transformation doc entry

enable_or_transformation GUC explanation.
---
 doc/src/sgml/config.sgml | 54 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index ffd711b7..b14c5c0e 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5276,6 +5276,60 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-enable-or-transformation" xreflabel="enable_or_transformation">
+      <term><varname>enable_or_transformation</varname> (<type>boolean</type>)
+       <indexterm>
+        <primary><varname>enable_or_transformation</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      
+      <listitem>
+       <para>
+        Enables or disables the query planner's ability to transform mulitple expressions in (<xref linkend="sql-expressions"/>)
+        <xref linkend="sql-where"/> to a ANY expression (<xref linkend="functions-comparisons-any-some"/>).
+        This  transformations only applys under the following condidtion:
+<itemizedlist>
+<listitem>
+<para>
+Each expression should be formed as: <replaceable>expression</replaceable> <replaceable>operator</replaceable>  (<replaceable>expression</replaceable>).
+The right-hand side of the operator should be just a plain constant.
+The left-hand side of these expressions should remainn the same.
+</para>
+</listitem>
+</itemizedlist>
+
+<itemizedlist>
+<listitem>
+<para>
+      Each expression form should return Boolean (true/false) result.
+</para>
+</listitem>
+</itemizedlist>
+
+<itemizedlist>
+<listitem>
+<para>
+These expressions are logically linked in a OR condition.
+</para>
+</listitem>
+</itemizedlist>
+        The default is <literal>on</literal>.
+       </para>
+   <para>
+    For example, the following query without set <varname>enable_or_transformation</varname>, normally apply to three filter conditions seperately,
+    but if we set <varname>enable_or_transformation</varname>, then we can combine these three expressions to just one expression: <literal>unique1 = ANY ('{1,2,3}'::integer[]) </literal>.
+<programlisting>
+EXPLAIN SELECT * FROM tenk1 WHERE unique1 = 1 or unique1 = 2 or unique1 = 3;
+
+                         QUERY PLAN
+-------------------------------------------------------------
+ Seq Scan on tenk1  (cost=0.00..482.50 rows=3 width=244)
+   Filter: (unique1 = ANY ('{1,2,3}'::integer[]))
+</programlisting>
+   </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-enable-parallel-append" xreflabel="enable_parallel_append">
       <term><varname>enable_parallel_append</varname> (<type>boolean</type>)
       <indexterm>
-- 
2.34.1

#146Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: jian he (#145)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 24.02.2024 14:28, jian he wrote:

Hi.
I wrote the first draft patch of the documentation.
it's under the section: Planner Method Configuration (runtime-config-query.html)
but this feature's main meat is in src/backend/parser/parse_expr.c
so it may be slightly inconsistent, as mentioned by others.

You can further furnish it.

Thank you for your work. I found a few spelling mistakes - I fixed this
and added some information about generating a partial index plan. I
attached it.

--
Regards,
Alena Rybakina
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

v1-0001-Add-enable_or_transformation-doc-entry.no-cfbottext/plain; charset=UTF-8; name=v1-0001-Add-enable_or_transformation-doc-entry.no-cfbotDownload
From e3a0e01c43a70099f6870a468d0cc3a8bdcb2775 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Mon, 26 Feb 2024 06:37:36 +0300
Subject: [PATCH] doc1

---
 doc/src/sgml/config.sgml | 74 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 36a2a5ce431..47f82ca2dc9 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5294,6 +5294,80 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-enable-or-transformation" xreflabel="enable_or_transformation">
+      <term><varname>enable_or_transformation</varname> (<type>boolean</type>)
+       <indexterm>
+        <primary><varname>enable_or_transformation</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      <listitem>
+       <para>
+        Enables or disables in query planner's ability to transform multiple expressions in (<xref linkend="sql-expressions"/>)
+        <xref linkend="sql-where"/> to a ANY expression (<xref linkend="functions-comparisons-any-some"/>).
+        This transformations only apply under the following condition:
+        <itemizedlist>
+          <listitem>
+          <para>
+            Each expression should be formed as: <replaceable>expression</replaceable> <replaceable>operator</replaceable>  (<replaceable>expression</replaceable>).
+            The right-hand side of the operator should be just a plain constant.
+            The left-hand side of these expressions should remain unchanged.
+          </para>
+          </listitem>
+        </itemizedlist>
+        <itemizedlist>
+          <listitem>
+          <para>
+            At the stage of index formation, a check is made on the restructuring of the plan using partial indexes or the formation of expressions combined by the "OR" <replaceable>operator</replaceable>.
+          </para>
+          </listitem>
+        </itemizedlist>
+            <itemizedlist>
+              <listitem>
+                <para>
+                  Each expression form should return Boolean (true/false) result.
+                </para>
+              </listitem>
+            </itemizedlist>
+            <itemizedlist>
+              <listitem>
+                <para>
+                These expressions are logically linked in a OR condition.
+                </para>
+              </listitem>
+            </itemizedlist>
+          The default is <literal>on</literal>.
+          </para>
+        <para>
+          For example, the following query without setting <varname>enable_or_transformation</varname> is usually applied to the three filtering conditions separately,
+          but if we set <varname>enable_or_transformation</varname>, we combine the three expressions into only one expression: <literal>unique1 = ANY ('{1,2,3}'::integer[]) </literal>.
+          <programlisting>
+          EXPLAIN SELECT * FROM tenk1 WHERE unique1 = 1 or unique1 = 2 or unique1 = 3;
+
+                                  QUERY PLAN
+          -------------------------------------------------------------
+          Seq Scan on tenk1  (cost=0.00..482.50 rows=3 width=244)
+            Filter: (unique1 = ANY ('{1,2,3}'::integer[]))
+          </programlisting>
+        </para>
+        <para>
+          Another example is the following query with a given <varname>enable_or_transformation</varname> value, but we have generated a plan with partial indexes.
+          <programlisting>
+          EXPLAIN SELECT unique2, stringu1 FROM onek2 WHERE unique1 = 1 OR unique1 = PI()::integer;
+                              QUERY PLAN                    
+          --------------------------------------------------
+          Bitmap Heap Scan on onek2
+            Recheck Cond: ((unique1 = 3) OR (unique1 = 1))
+            ->  BitmapOr
+                  ->  Bitmap Index Scan on onek2_u1_prtl
+                        Index Cond: (unique1 = 3)
+                  ->  Bitmap Index Scan on onek2_u1_prtl
+                        Index Cond: (unique1 = 1)
+          (7 rows)
+          </programlisting>
+        </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-enable-parallel-append" xreflabel="enable_parallel_append">
       <term><varname>enable_parallel_append</varname> (<type>boolean</type>)
       <indexterm>
-- 
2.34.1

#147Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#146)
Re: POC, WIP: OR-clause support for indexes

On 26/2/2024 11:10, Alena Rybakina wrote:

On 24.02.2024 14:28, jian he wrote:

Hi.
I wrote the first draft patch of the documentation.
it's under the section: Planner Method Configuration
(runtime-config-query.html)
but this feature's main meat is in src/backend/parser/parse_expr.c
so it may be slightly inconsistent, as mentioned by others.

You can further furnish it.

Thank you for your work. I found a few spelling mistakes - I fixed this
and added some information about generating a partial index plan. I
attached it.

Thanks Jian and Alena,
It is a good start for the documentation. But I think the runtime-config
section needs only a condensed description of a feature underlying the
GUC. The explanations in this section look a bit awkward.
Having looked through the documentation for a better place for a
detailed explanation, I found array.sgml as a candidate. Also, we have
the parser's short overview section. I'm unsure about the best place but
it is better when the server config section.
What's more, there are some weak points in the documentation:
1. We choose constant and variable parts of an expression and don't
require the constant to be on the right side.
2. We should describe the second part of the feature, where the
optimiser can split an array to fit the optimal BitmapOr scan path.

--
regards,
Andrei Lepikhov
Postgres Professional

#148jian he
jian.universality@gmail.com
In reply to: Andrei Lepikhov (#147)
Re: POC, WIP: OR-clause support for indexes

On Wed, Feb 28, 2024 at 12:19 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 26/2/2024 11:10, Alena Rybakina wrote:

On 24.02.2024 14:28, jian he wrote:

Hi.
I wrote the first draft patch of the documentation.
it's under the section: Planner Method Configuration
(runtime-config-query.html)
but this feature's main meat is in src/backend/parser/parse_expr.c
so it may be slightly inconsistent, as mentioned by others.

You can further furnish it.

Thank you for your work. I found a few spelling mistakes - I fixed this
and added some information about generating a partial index plan. I
attached it.

Thanks Jian and Alena,
It is a good start for the documentation. But I think the runtime-config
section needs only a condensed description of a feature underlying the
GUC. The explanations in this section look a bit awkward.
Having looked through the documentation for a better place for a
detailed explanation, I found array.sgml as a candidate. Also, we have
the parser's short overview section. I'm unsure about the best place but
it is better when the server config section.

doc/src/sgml/array.sgml corresponds to
https://www.postgresql.org/docs/current/arrays.html.
this GUC is related to parser|optimzier.
adding a GUC to array.sgml seems strange. (I think).

2. We should describe the second part of the feature, where the
optimiser can split an array to fit the optimal BitmapOr scan path.

we can add a sentence explaining that:
it may not do the expression transformation when the original
expression can be utilized by index mechanism.
I am not sure how to rephrase it.

#149Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: jian he (#148)
Re: POC, WIP: OR-clause support for indexes

On 28.02.2024 13:07, jian he wrote:

On Wed, Feb 28, 2024 at 12:19 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 26/2/2024 11:10, Alena Rybakina wrote:

On 24.02.2024 14:28, jian he wrote:

Hi.
I wrote the first draft patch of the documentation.
it's under the section: Planner Method Configuration
(runtime-config-query.html)
but this feature's main meat is in src/backend/parser/parse_expr.c
so it may be slightly inconsistent, as mentioned by others.

You can further furnish it.

Thank you for your work. I found a few spelling mistakes - I fixed this
and added some information about generating a partial index plan. I
attached it.

Thanks Jian and Alena,
It is a good start for the documentation. But I think the runtime-config
section needs only a condensed description of a feature underlying the
GUC. The explanations in this section look a bit awkward.
Having looked through the documentation for a better place for a
detailed explanation, I found array.sgml as a candidate. Also, we have
the parser's short overview section. I'm unsure about the best place but
it is better when the server config section.

doc/src/sgml/array.sgml corresponds to
https://www.postgresql.org/docs/current/arrays.html.
this GUC is related to parser|optimzier.
adding a GUC to array.sgml seems strange. (I think).

I suggest describing our feature in array.sgml and mentioning a GUC there.

We can describe a GUC in config.sgml.

2. We should describe the second part of the feature, where the
optimiser can split an array to fit the optimal BitmapOr scan path.

we can add a sentence explaining that:
it may not do the expression transformation when the original
expression can be utilized by index mechanism.
I am not sure how to rephrase it.

Maybe like that:

It also considers the way to generate a path using BitmapScan indexes,
converting the transformed expression into expressions separated by "OR"
operations, and if it turns out to be the best and finally selects the
best one.

--
Regards,
Alena Rybakina
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#150Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: jian he (#148)
Re: POC, WIP: OR-clause support for indexes

On 28/2/2024 17:07, jian he wrote:

doc/src/sgml/array.sgml corresponds to
https://www.postgresql.org/docs/current/arrays.html.
this GUC is related to parser|optimzier.
adding a GUC to array.sgml seems strange. (I think).

Maybe. In that case, I suggest adding extended comments to functions
transformBoolExprOr and generate_saop_pathlist (including
cross-referencing each other). These are starting points to understand
the transformation and, therefore, a good place for a detailed explanation.

--
regards,
Andrei Lepikhov
Postgres Professional

#151Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alena Rybakina (#149)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 28/2/2024 17:27, Alena Rybakina wrote:

Maybe like that:

It also considers the way to generate a path using BitmapScan indexes,
converting the transformed expression into expressions separated by "OR"
operations, and if it turns out to be the best and finally selects the
best one.

Thanks,
I spent some time describing the feature with documentation.
A condensed description of the GUC is in the runtime-config file.
Feature description has spread between TransformOrExprToANY and
generate_saop_pathlist routines.
Also, I've made tiny changes in the code to look more smoothly.
All modifications are integrated into the two new patches.

Feel free to add, change or totally rewrite these changes.

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v18-0001-Transform-OR-clause-to-ANY-expressions.patchtext/plain; charset=UTF-8; name=v18-0001-Transform-OR-clause-to-ANY-expressions.patchDownload
From 015a564cc784139c806a7004f25bf5f7a4b4a29d Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Fri, 2 Feb 2024 22:01:09 +0300
Subject: [PATCH 1/2] Transform OR clause to ANY expressions.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(C1, C2, ...) on the
preliminary stage of optimization when we are still working with the tree
expression.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
---
 .../postgres_fdw/expected/postgres_fdw.out    |  16 +-
 doc/src/sgml/config.sgml                      |  18 +
 src/backend/nodes/queryjumblefuncs.c          |  27 ++
 src/backend/parser/parse_expr.c               | 340 ++++++++++++++++++
 src/backend/utils/misc/guc_tables.c           |  11 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/bin/pg_dump/t/002_pg_dump.pl              |   6 +-
 src/include/nodes/queryjumble.h               |   1 +
 src/include/optimizer/optimizer.h             |   1 +
 src/test/regress/expected/create_index.out    | 156 +++++++-
 src/test/regress/expected/inherit.out         |   2 +-
 src/test/regress/expected/join.out            |  62 +++-
 src/test/regress/expected/partition_prune.out | 219 +++++++++--
 src/test/regress/expected/rules.out           |   4 +-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  35 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 22 files changed, 908 insertions(+), 69 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index c355e8f3f7..0523bbd8f7 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -1349,7 +1349,7 @@ SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE
  Foreign Scan
    Output: t1.c1, t1.c2, ft5.c1, ft5.c2
    Relations: (public.ft4 t1) LEFT JOIN (public.ft5)
-   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 < 10) OR (r4.c1 IS NULL))) AND ((r1.c1 < 10))
+   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 IS NULL) OR (r4.c1 < 10))) AND ((r1.c1 < 10))
 (4 rows)
 
 SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE c1 < 10) t2 ON (t1.c1 = t2.c1)
@@ -3105,7 +3105,7 @@ select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3123,7 +3123,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3140,7 +3140,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST)), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -8797,18 +8797,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 43b1a132a2..abad02f92c 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5433,6 +5433,24 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-enable-or-transformation" xreflabel="enable_or_transformation">
+      <term><varname>enable_or_transformation</varname> (<type>boolean</type>)
+       <indexterm>
+        <primary><varname>enable_or_transformation</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      <listitem>
+       <para>
+        Enables or disables the query planner's ability to lookup and group multiple
+        similar OR expressions to ANY (<xref linkend="functions-comparisons-any-some"/>) expressions.
+        The grouping technique of this transformation is based on the similarity of variable sides.
+        It applies to equality expressions only. One side of such an expression
+        must be a constant clause, and the other must contain a variable clause.
+        The default is <literal>on</literal>.
+        </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-enable-parallel-append" xreflabel="enable_parallel_append">
       <term><varname>enable_parallel_append</varname> (<type>boolean</type>)
       <indexterm>
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 82f725baaa..b203746be4 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -141,6 +141,33 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 9300c7b9ab..10ceccc80c 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,14 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -38,11 +40,13 @@
 #include "utils/date.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +103,337 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+
+	Node		   *node;
+	List		   *consts;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function to find candidate clauses.
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				hash;
+
+	Assert(keysize == sizeof(OrClauseGroupKey));
+
+	(void) JumbleExpr(key->expr, &hash);
+	hash += ((uint64) key->opno + (uint64) key->exprtype);
+	return (uint32) (hash % UINT32_MAX);
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in guc_hashtab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+/*
+ * TransformOrExprToANY -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to an ANY operation.
+ *	  Transformation must be already done on input args list before the call.
+ *	  Transformation groups two-sided equality operations. One side of such an
+ *	  operation must be plain constant or constant expression. The other side of
+ *	  the clause must be a variable expression without volatile functions.
+ *	  The grouping technique is based on the similarity of variable sides of the
+ *	  expression: using queryId and equal() routine, it groups constant sides of
+ *	  similar clauses into an array. After the grouping procedure, each couple
+ *	  ('variable expression' and 'constant array') form a new SAOP operation,
+ *	  which is added to the args list of the returning expression.
+ *
+ *	  NOTE: function returns OR BoolExpr if more than one clause are detected in
+ *	  the final args list, or ScalarArrayOpExpr if all args were grouped into
+ *	  the single SAOP expression.
+ */
+static Node *
+TransformOrExprToANY(ParseState *pstate, List *args, int location)
+{
+	List				   *or_list = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(args);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	Assert(enable_or_transformation && len_ors > 1);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, args)
+	{
+		Node				   *orqual = lfirst(lc);
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Oid						exprtype;
+		Node				   *leftop, *rightop;
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Transformation only works with both side type is not
+		 * { array | composite | domain | record }.
+		 * Also, forbid it for volatile expressions.
+		 */
+		exprtype = exprType(nconst_expr);
+		if (type_is_rowtype(exprType(const_expr)) ||
+			type_is_rowtype(exprtype) ||
+			contain_volatile_functions((Node *) nconst_expr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.exprtype = exprtype;
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->node = nconst_expr;
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element in the class. Return origin expression into
+			 * the BoolExpr args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.exprtype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+											   InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+			ListCell		   *lc1;
+
+			foreach(lc1, entry->consts)
+			{
+				Node   *rexpr = (Node *) lfirst(lc1);
+
+				rexpr = coerce_to_common_type(pstate, rexpr,
+											  scalar_type,
+											  "IN");
+				aexprs = lappend(aexprs, rexpr);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 entry->node,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -1386,6 +1721,11 @@ transformBoolExpr(ParseState *pstate, BoolExpr *a)
 		args = lappend(args, arg);
 	}
 
+	/* Make an attempt to group similar OR clauses into ANY operation */
+	if (enable_or_transformation && a->boolop == OR_EXPR &&
+		list_length(args) > 1)
+		return TransformOrExprToANY(pstate, args, a->location);
+
 	return (Node *) makeBoolExpr(a->boolop, args, a->location);
 }
 
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 93ded31ed9..7d3a1ca238 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1026,6 +1026,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+			gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+						 "to the clause 'x IN (c1,c2,...)'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index edcc0282b2..d30dc6d51c 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -389,6 +389,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 00b5092713..d28bf617db 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -2095,9 +2095,9 @@ my %tests = (
 		regexp => qr/^
 			\QCREATE DOMAIN dump_test.us_postal_code AS text COLLATE pg_catalog."C" DEFAULT '10014'::text\E\n\s+
 			\QCONSTRAINT us_postal_code_check CHECK \E
-			\Q(((VALUE ~ '^\d{5}\E
-			\$\Q'::text) OR (VALUE ~ '^\d{5}-\d{4}\E\$
-			\Q'::text)));\E(.|\n)*
+			\Q((VALUE ~ ANY (ARRAY['^\d{5}\E
+			\$\Q'::text, '^\d{5}-\d{4}\E\$
+			\Q'::text])));\E(.|\n)*
 			\QCOMMENT ON CONSTRAINT us_postal_code_check ON DOMAIN dump_test.us_postal_code IS 'check it';\E
 			/xm,
 		like =>
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067..a9ae048af5 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 7b63c5cf71..35ab577501 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -50,6 +50,7 @@ struct PlannedStmt;
 struct ParamListInfoData;
 struct HeapTupleData;
 
+extern PGDLLIMPORT bool enable_or_transformation;
 
 /* in path/clausesel.c: */
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 79fa117cb5..b8653c09ea 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,116 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 130a924228..684886336c 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -2600,7 +2600,7 @@ explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd'
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9605400021..cd2d78a636 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 < 20) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 < 20) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index b41950d923..26b05d7a5a 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -589,20 +611,20 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 ------------------------------------------------------
  Append
    ->  Seq Scan on rlp1 rlp_1
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
    ->  Seq Scan on rlp4_1 rlp_2
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
 (5 rows)
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -2036,10 +2215,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index b7488d760e..b424ad3154 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2501,7 +2501,7 @@ pg_stats| SELECT n.nspname AS schemaname,
      JOIN pg_class c ON ((c.oid = s.starelid)))
      JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
-  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2532,7 +2532,7 @@ pg_stats_ext| SELECT cn.nspname AS schemaname,
   WHERE ((NOT (EXISTS ( SELECT 1
            FROM (unnest(s.stxkeys) k(k)
              JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
-          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext_exprs| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 10903bdab0..6f55b9e3ec 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 9be7aca2b8..1f9029b5b2 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -124,6 +124,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -134,7 +135,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(23 rows)
+(24 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..2a079e996b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..56fde15bc1 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index c4c6c7b8ba..1663608043 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 7ba6a9ff37..31ad4166d5 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index fc8b15d0cf..5cf444e95b 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1656,6 +1656,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.43.2

v18-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchtext/plain; charset=UTF-8; name=v18-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchDownload
From 2810be3413696796e9f2b88a8dd77801c0088139 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Wed, 24 Jan 2024 14:07:17 +0700
Subject: [PATCH 2/2] Teach generate_bitmap_or_paths to build BitmapOr paths
 over SAOP clauses.

Likewise OR clauses, discover SAOP array and try to split its elements
between smaller sized arrays to fit a set of partial indexes.
---
 doc/src/sgml/config.sgml                  |   3 +
 src/backend/optimizer/path/indxpath.c     | 315 ++++++++++++++++++----
 src/backend/optimizer/util/predtest.c     |  46 ++++
 src/backend/optimizer/util/restrictinfo.c |  13 +
 src/include/optimizer/optimizer.h         |  16 ++
 src/include/optimizer/restrictinfo.h      |   1 +
 src/test/regress/expected/select.out      | 282 +++++++++++++++++++
 src/test/regress/sql/select.sql           |  82 ++++++
 src/tools/pgindent/typedefs.list          |   1 +
 9 files changed, 706 insertions(+), 53 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index abad02f92c..e046b6bbca 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5447,6 +5447,9 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
         It applies to equality expressions only. One side of such an expression
         must be a constant clause, and the other must contain a variable clause.
         The default is <literal>on</literal>.
+        Also, during BitmapScan paths generation it enables analysis of elements
+        of IN or ANY constant arrays to cover such clause with BitmapOr set of
+        partial index scans.
         </para>
       </listitem>
      </varlistentry>
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 32c6a8bbdc..47bf53820d 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,6 +32,7 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
 
@@ -1220,11 +1221,188 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Building index paths over SAOP clause differs from the logic of OR clauses.
+ * Here we iterate across all the array elements and split them to SAOPs,
+ * corresponding to different indexes. We must match each element to an index.
+ */
+static List *
+build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
+					 List *other_clauses)
+{
+	List			   *result = NIL;
+	List			   *predicate_lists = NIL;
+	ListCell		   *lc;
+	PredicatesData	   *pd;
+	ScalarArrayOpExpr  *saop = (ScalarArrayOpExpr *) rinfo->clause;
+
+	Assert(IsA(saop, ScalarArrayOpExpr) && saop->useOr);
+
+	if (!IsA(lsecond(saop->args), Const))
+		/*
+		 * Has it practical outcome to merge arrays which couldn't constantified
+		 * before that step?
+		 */
+		return NIL;
+
+	/* Collect predicates */
+	foreach(lc, rel->indexlist)
+	{
+		IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
+
+		/* Take into consideration partial indexes supporting bitmap scans */
+		if (!index->amhasgetbitmap || index->indpred == NIL || index->predOK)
+			continue;
+
+		pd = palloc0(sizeof(PredicatesData));
+		pd->id = foreach_current_index(lc);
+		/* The trick with reducing recursion is stolen from predicate_implied_by */
+		pd->predicate = list_length(index->indpred) == 1 ?
+										(Node *) linitial(index->indpred) :
+										(Node *) index->indpred;
+		predicate_lists = lappend(predicate_lists, (void *) pd);
+	}
+
+	/* Split the array data according to index predicates. */
+	if (predicate_lists == NIL ||
+		!saop_covered_by_predicates(saop, predicate_lists))
+		return NIL;
+
+	other_clauses = list_delete_ptr(other_clauses, rinfo);
+
+	/*
+	 * Having incoming SAOP split to set of smaller SAOPs which can be applied
+	 * to partial indexes, generate paths for each one.
+	 */
+	foreach(lc, predicate_lists)
+	{
+		IndexOptInfo	   *index;
+		IndexClauseSet		clauseset;
+		List			   *indexpaths;
+		RestrictInfo	   *rinfo1 = NULL;
+		Expr			   *clause;
+		ArrayType		   *arrayval = NULL;
+		ArrayExpr		   *arr = NULL;
+		Const			   *arrayconst;
+		ScalarArrayOpExpr	dest;
+
+		pd = (PredicatesData *) lfirst(lc);
+		if (pd->elems == NIL)
+			/* The index doesn't participate in this operation */
+			continue;
+
+		/* Make up new array */
+		arrayconst = lsecond_node(Const, saop->args);
+		arrayval = DatumGetArrayTypeP(arrayconst->constvalue);
+		arr = makeNode(ArrayExpr);
+		arr->array_collid = arrayconst->constcollid;
+		arr->array_typeid = arrayconst->consttype;
+		arr->element_typeid = arrayval->elemtype;
+		arr->elements = pd->elems;
+		arr->location = -1;
+		arr->multidims = false;
+
+		/* Compose new SAOP, partially covering the source one */
+		memcpy(&dest, saop, sizeof(ScalarArrayOpExpr));
+		dest.args = list_make2(linitial(saop->args), arr);
+
+		clause = (Expr *) estimate_expression_value(root, (Node *) &dest);
+
+		/*
+		 * Create new RestrictInfo. It maybe more heavy than just copy node,
+		 * but remember some internals: the serial number, selectivity
+		 * cache etc.
+		 */
+		rinfo1 = make_restrictinfo(root, clause,
+								   rinfo->is_pushed_down,
+								   rinfo->has_clone,
+								   rinfo->is_clone,
+								   rinfo->pseudoconstant,
+								   rinfo->security_level,
+								   rinfo->required_relids,
+								   rinfo->incompatible_relids,
+								   rinfo->outer_relids);
+
+		index = list_nth(rel->indexlist, pd->id);
+		Assert(predicate_implied_by(index->indpred, list_make1(rinfo1), true));
+
+		/* Excluding partial indexes with predOK we make this statement false */
+		Assert(!predicate_implied_by(index->indpred, other_clauses, false));
+
+		/* Time to generate index paths */
+
+		MemSet(&clauseset, 0, sizeof(clauseset));
+		match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);
+		match_clauses_to_index(root, other_clauses, index, &clauseset);
+
+		/* Predicate has found already. So, it is ok for the empty match */
+
+		indexpaths = build_index_paths(root, rel,
+									   index, &clauseset,
+									   true,
+									   ST_BITMAPSCAN,
+									   NULL,
+									   NULL);
+		Assert(indexpaths != NIL);
+		result = lappend(result, indexpaths);
+	}
+	return result;
+}
+
+/*
+ * Analyse incoming SAOP node to cover it by partial indexes.
+ *
+ * The returning pathlist must be ANDed to the final BitmapScan path.
+ * The function returns NULL when an array element cannot be fitted with some
+ * partial index. The Rationale for such an operation is that when schema
+ * contains many partial indexes, the SAOP clause may be effectively fulfilled
+ * by appending results of scanning some minimal set of tiny partial indexes.
+ *
+ * Working jointly with the TransformOrExprToANY routine, it provides a user
+ * with some sort of independence of the query plan from the approach to writing
+ * alternatives for the same entity in the WHERE section.
+ */
+static List *
+generate_saop_pathlist(PlannerInfo *root, RelOptInfo *rel,
+					   RestrictInfo *rinfo, List *all_clauses)
+{
+	List	   *pathlist = NIL;
+	Path	   *bitmapqual;
+	List	   *indlist;
+	ListCell   *lc;
+
+	if (!enable_or_transformation)
+		return NIL;
+
+	/*
+	 * We must be able to match at least one index to each element of
+	 * the array, else we can't use it.
+	 */
+	indlist = build_paths_for_SAOP(root, rel, rinfo, all_clauses);
+	if (indlist == NIL)
+		return NIL;
+
+	/*
+	 * OK, pick the most promising AND combination, and add it to
+	 * pathlist.
+	 */
+	foreach (lc, indlist)
+	{
+		List *plist = lfirst_node(List, lc);
+
+		bitmapqual = choose_bitmap_and(root, rel, plist);
+		pathlist = lappend(pathlist, bitmapqual);
+	}
+
+	return pathlist;
+}
+
 /*
  * generate_bitmap_or_paths
- *		Look through the list of clauses to find OR clauses, and generate
- *		a BitmapOrPath for each one we can handle that way.  Return a list
- *		of the generated BitmapOrPaths.
+ *		Look through the list of clauses to find OR and SAOP clauses, and
+ *		Each saop clause are splitted to be covered by partial indexes.
+ *		generate a BitmapOrPath for each one we can handle that way.
+ *		Return a list of the generated BitmapOrPaths.
  *
  * other_clauses is a list of additional clauses that can be assumed true
  * for the purpose of generating indexquals, but are not to be searched for
@@ -1247,68 +1425,99 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	foreach(lc, clauses)
 	{
 		RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
-		List	   *pathlist;
+		List	   *pathlist = NIL;
 		Path	   *bitmapqual;
 		ListCell   *j;
 
-		/* Ignore RestrictInfos that aren't ORs */
-		if (!restriction_is_or_clause(rinfo))
+		if (restriction_is_saop_clause(rinfo))
+		{
+			pathlist = generate_saop_pathlist(root, rel, rinfo,
+											  all_clauses);
+		}
+		else if (!restriction_is_or_clause(rinfo))
+			/* Ignore RestrictInfos that aren't ORs */
 			continue;
-
-		/*
-		 * We must be able to match at least one index to each of the arms of
-		 * the OR, else we can't use it.
-		 */
-		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		else
 		{
-			Node	   *orarg = (Node *) lfirst(j);
-			List	   *indlist;
-
-			/* OR arguments should be ANDs or sub-RestrictInfos */
-			if (is_andclause(orarg))
+			/*
+			 * We must be able to match at least one index to each of the arms of
+			 * the OR, else we can't use it.
+			 */
+			foreach(j, ((BoolExpr *) rinfo->orclause)->args)
 			{
-				List	   *andargs = ((BoolExpr *) orarg)->args;
+				Node	   *orarg = (Node *) lfirst(j);
+				List	   *indlist;
 
-				indlist = build_paths_for_OR(root, rel,
-											 andargs,
-											 all_clauses);
+				/* OR arguments should be ANDs or sub-RestrictInfos */
+				if (is_andclause(orarg))
+				{
+					List	   *andargs = ((BoolExpr *) orarg)->args;
 
-				/* Recurse in case there are sub-ORs */
-				indlist = list_concat(indlist,
-									  generate_bitmap_or_paths(root, rel,
-															   andargs,
-															   all_clauses));
-			}
-			else
-			{
-				RestrictInfo *ri = castNode(RestrictInfo, orarg);
-				List	   *orargs;
+					indlist = build_paths_for_OR(root, rel,
+												 andargs,
+												 all_clauses);
+
+					/* Recurse in case there are sub-ORs */
+					indlist = list_concat(indlist,
+										  generate_bitmap_or_paths(root, rel,
+																   andargs,
+																   all_clauses));
+				}
+				else
+				{
+					RestrictInfo *ri = castNode(RestrictInfo, orarg);
+					List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
-				orargs = list_make1(ri);
+					Assert(!restriction_is_or_clause(ri));
 
-				indlist = build_paths_for_OR(root, rel,
-											 orargs,
-											 all_clauses);
-			}
+					orargs = list_make1(ri);
 
-			/*
-			 * If nothing matched this arm, we can't do anything with this OR
-			 * clause.
-			 */
-			if (indlist == NIL)
-			{
-				pathlist = NIL;
-				break;
-			}
+					if (restriction_is_saop_clause(ri))
+					{
+						List *paths;
 
-			/*
-			 * OK, pick the most promising AND combination, and add it to
-			 * pathlist.
-			 */
-			bitmapqual = choose_bitmap_and(root, rel, indlist);
-			pathlist = lappend(pathlist, bitmapqual);
+						paths = generate_saop_pathlist(root, rel, ri,
+														 all_clauses);
+
+						if (paths != NIL)
+						{
+							/*
+							 * Add paths to pathlist and immediately jump to the
+							 * next element of the OR clause.
+							 */
+							pathlist = list_concat(pathlist, paths);
+							continue;
+						}
+
+						/*
+						 * Pass down out of this if construction:
+						 * If saop isn't covered by partial indexes, try to
+						 * build scan path for the saop as a whole.
+						 */
+					}
+
+					indlist = build_paths_for_OR(root, rel,
+												 orargs,
+												 all_clauses);
+				}
+
+				/*
+				 * If nothing matched this arm, we can't do anything with this OR
+				 * clause.
+				 */
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+
+				/*
+				 * OK, pick the most promising AND combination, and add it to
+				 * pathlist.
+				 */
+				bitmapqual = choose_bitmap_and(root, rel, indlist);
+				pathlist = lappend(pathlist, bitmapqual);
+			}
 		}
 
 		/*
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index c37b416e24..8ed80a78b4 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -112,6 +112,52 @@ static Oid	get_btree_test_op(Oid pred_op, Oid clause_op, bool refute_it);
 static void InvalidateOprProofCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
 
 
+/*
+ * Could this ANY () expression can be split into a set of ANYs over partial
+ * indexes? If yes, return these saops in the PredicatesData structure.
+ */
+bool
+saop_covered_by_predicates(ScalarArrayOpExpr *saop, List *predicate_lists)
+{
+	ListCell		   *lc;
+	PredIterInfoData	clause_info;
+	bool				result = false;
+
+	if (predicate_classify((Node *) saop, &clause_info) != CLASS_OR)
+		return false;
+
+	iterate_begin(pitem, (Node *) saop, clause_info)
+	{
+		result = false;
+
+		foreach(lc, predicate_lists)
+		{
+			PredicatesData *pd = (PredicatesData *) lfirst(lc);
+
+			if (!predicate_implied_by_recurse(pitem, pd->predicate, false))
+				continue;
+
+			/* Predicate is found. Add the elem to the saop clause */
+			Assert(IsA(pitem, OpExpr));
+
+			/* Extract constant from the expression */
+			pd->elems = lappend(pd->elems,
+					copyObject(lsecond_node(Const, ((OpExpr *) pitem)->args)));
+			result = true;
+			break;
+		}
+
+		if (!result)
+			/*
+			 * The element doesn't fit any index. Interrupt the process immediately
+			 */
+			break;
+	}
+	iterate_end(clause_info);
+
+	return result;
+}
+
 /*
  * predicate_implied_by
  *	  Recursively checks whether the clauses in clause_list imply that the
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e9334..1dad1dc654 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -421,6 +421,19 @@ restriction_is_or_clause(RestrictInfo *restrictinfo)
 		return false;
 }
 
+bool
+restriction_is_saop_clause(RestrictInfo *restrictinfo)
+{
+	if (restrictinfo->clause && IsA(restrictinfo->clause, ScalarArrayOpExpr))
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) restrictinfo->clause;
+
+		if (saop->useOr)
+			return true;
+	}
+	return false;
+}
+
 /*
  * restriction_is_securely_promotable
  *
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 35ab577501..232afcd00c 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -160,6 +160,22 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+/*
+ * Contains information needed to extract from saop a set of elements which can
+ * be covered by the partial index:
+ * id - caller's identification of the index.
+ * predicate - predicate expression of the index
+ * elems - returning list of array elements which corresponds to this predicate
+ */
+typedef struct PredicatesData
+{
+	int		id;
+	Node   *predicate;
+	List   *elems;
+} PredicatesData;
+
+extern bool saop_covered_by_predicates(ScalarArrayOpExpr *saop,
+									  List *predicate_lists);
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c5..2cd5fbf943 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -34,6 +34,7 @@ extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Relids outer_relids);
 extern RestrictInfo *commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op);
 extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
+extern bool restriction_is_saop_clause(RestrictInfo *restrictinfo);
 extern bool restriction_is_securely_promotable(RestrictInfo *restrictinfo,
 											   RelOptInfo *rel);
 extern List *get_actual_clauses(List *restrictinfo_list);
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e..070202b0f0 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -907,6 +907,288 @@ select unique1, unique2 from onek2
        0 |     998
 (2 rows)
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: ((stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Without the transformation only seqscan possible here
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                         QUERY PLAN                                          
+---------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])) AND (stringu1 < 'Z'::name))
+(2 rows)
+
+-- Use partial indexes
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+                 QUERY PLAN                 
+--------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = 1) OR (unique2 = 3))
+(2 rows)
+
+RESET enable_or_transformation;
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+-- Don't scan partial indexes because of extra value.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+                      QUERY PLAN                      
+------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on onek2
+         Filter: (stringu1 = ANY ('{A,J,C}'::name[]))
+(3 rows)
+
+explain (costs off)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+                                      QUERY PLAN                                       
+---------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (stringu1 < 'B'::name)
+   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = ANY ('{A,A}'::name[])))
+   ->  Bitmap Index Scan on onek2_u2_prtl
+(4 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                                          QUERY PLAN                                                           
+-------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name)) OR ((unique2 < 1) AND (stringu1 < 'B'::name)))
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: ((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 < 1)
+(8 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 = 3) OR (unique1 = 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 3)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 1)
+(7 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+                                                             QUERY PLAN                                                             
+------------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = ((random() * '2'::double precision))::integer) OR (unique1 = ((random() * '3'::double precision))::integer))
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+                                                           QUERY PLAN                                                            
+---------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: (unique1 = ANY (ARRAY[((random() * '2'::double precision))::integer, ((random() * '3'::double precision))::integer]))
+(2 rows)
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+                                                                                          QUERY PLAN                                                                                          
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[]))) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 = ANY ('{1,2,21}'::integer[])) AND ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 = ANY ('{3,4}'::integer[])) OR (stringu1 = 'J'::name)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[])))
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(11 rows)
+
+-- Check recursive combination of OR and SAOP expressions
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR (unique1 < 1))
+   Filter: ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 < 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+(9 rows)
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR (unique1 < 1))
+   Filter: ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 < 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+(9 rows)
+
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+RESET enable_indexscan;
+RESET enable_seqscan;
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql
index 019f1e7673..0e650a2301 100644
--- a/src/test/regress/sql/select.sql
+++ b/src/test/regress/sql/select.sql
@@ -234,6 +234,88 @@ select unique1, unique2 from onek2
 select unique1, unique2 from onek2
   where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+-- Without the transformation only seqscan possible here
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+-- Use partial indexes
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+RESET enable_or_transformation;
+
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+
+-- Don't scan partial indexes because of extra value.
+explain (costs off)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+explain (costs off)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+
+-- Check recursive combination of OR and SAOP expressions
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+explain (costs off)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+explain (costs off)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+
+RESET enable_indexscan;
+RESET enable_seqscan;
+
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 5cf444e95b..698e460840 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2141,6 +2141,7 @@ PredIterInfoData
 PredXactList
 PredicateLockData
 PredicateLockTargetType
+PredicatesData
 PrefetchBufferResult
 PrepParallelRestorePtrType
 PrepareStmt
-- 
2.43.2

#152Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#151)
Re: POC, WIP: OR-clause support for indexes

Hi, Andrei,
Hi, Alena!

On Thu, Feb 29, 2024 at 10:59 AM Andrei Lepikhov <a.lepikhov@postgrespro.ru>
wrote:

On 28/2/2024 17:27, Alena Rybakina wrote:

Maybe like that:

It also considers the way to generate a path using BitmapScan indexes,
converting the transformed expression into expressions separated by "OR"
operations, and if it turns out to be the best and finally selects the
best one.

Thanks,
I spent some time describing the feature with documentation.
A condensed description of the GUC is in the runtime-config file.
Feature description has spread between TransformOrExprToANY and
generate_saop_pathlist routines.
Also, I've made tiny changes in the code to look more smoothly.
All modifications are integrated into the two new patches.

Feel free to add, change or totally rewrite these changes.

I'm going to review and revise the patch.

One question I have yet.

/*
* Transformation only works with both side type is not
* { array | composite | domain | record }.

Why do we limit transformation for these types? Also, it doesn't seem the
current code restricts anything except composite/record.

------
Regards,
Alexander Korotkov

#153Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#152)
Re: POC, WIP: OR-clause support for indexes

I found that it was mentioned here -
/messages/by-id/CACJufxFrZS07oBHMk1_c8P3A84VZ3ysXiZV8NeU6gAnvu+HsVA@mail.gmail.com.

To be honest, I couldn't find any explanation for that.

On 01.03.2024 18:33, Alexander Korotkov wrote:

Hi, Andrei,
Hi, Alena!

On Thu, Feb 29, 2024 at 10:59 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 28/2/2024 17:27, Alena Rybakina wrote:

Maybe like that:

It also considers the way to generate a path using BitmapScan

indexes,

converting the transformed expression into expressions separated

by "OR"

operations, and if it turns out to be the best and finally

selects the

best one.

Thanks,
I spent some time describing the feature with documentation.
A condensed description of the GUC is in the runtime-config file.
Feature description has spread between TransformOrExprToANY and
generate_saop_pathlist routines.
Also, I've made tiny changes in the code to look more smoothly.
All modifications are integrated into the two new patches.

Feel free to add, change or totally rewrite these changes.

I'm going to review and revise the patch.

One question I have yet.

        /*
         * Transformation only works with both side type is not
         * { array | composite | domain | record }.

Why do we limit transformation for these types?  Also, it doesn't seem
the current code restricts anything except composite/record.

------
Regards,
Alexander Korotkov

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#154Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#153)
Re: POC, WIP: OR-clause support for indexes

Sorry, I found explanation -
/messages/by-id/CACJufxFS-xcjaWq2Du2OyJUjRAyqCk12Q_zGOPxv61sgrdpw9w@mail.gmail.com

On 03.03.2024 12:26, Alena Rybakina wrote:

I found that it was mentioned here -
/messages/by-id/CACJufxFrZS07oBHMk1_c8P3A84VZ3ysXiZV8NeU6gAnvu+HsVA@mail.gmail.com.

To be honest, I couldn't find any explanation for that.

On 01.03.2024 18:33, Alexander Korotkov wrote:

Hi, Andrei,
Hi, Alena!

On Thu, Feb 29, 2024 at 10:59 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 28/2/2024 17:27, Alena Rybakina wrote:

Maybe like that:

It also considers the way to generate a path using BitmapScan

indexes,

converting the transformed expression into expressions

separated by "OR"

operations, and if it turns out to be the best and finally

selects the

best one.

Thanks,
I spent some time describing the feature with documentation.
A condensed description of the GUC is in the runtime-config file.
Feature description has spread between TransformOrExprToANY and
generate_saop_pathlist routines.
Also, I've made tiny changes in the code to look more smoothly.
All modifications are integrated into the two new patches.

Feel free to add, change or totally rewrite these changes.

I'm going to review and revise the patch.

One question I have yet.

        /*
         * Transformation only works with both side type is not
         * { array | composite | domain | record }.

Why do we limit transformation for these types?  Also, it doesn't
seem the current code restricts anything except composite/record.

------
Regards,
Alexander Korotkov

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#155jian he
jian.universality@gmail.com
In reply to: Andrei Lepikhov (#151)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Thu, Feb 29, 2024 at 4:59 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 28/2/2024 17:27, Alena Rybakina wrote:

Maybe like that:

It also considers the way to generate a path using BitmapScan indexes,
converting the transformed expression into expressions separated by "OR"
operations, and if it turns out to be the best and finally selects the
best one.

Thanks,
I spent some time describing the feature with documentation.
A condensed description of the GUC is in the runtime-config file.
Feature description has spread between TransformOrExprToANY and
generate_saop_pathlist routines.
Also, I've made tiny changes in the code to look more smoothly.
All modifications are integrated into the two new patches.

Feel free to add, change or totally rewrite these changes.

diff --git a/src/backend/utils/misc/guc_tables.c
b/src/backend/utils/misc/guc_tables.c
index 93ded31ed9..7d3a1ca238 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1026,6 +1026,17 @@ struct config_bool ConfigureNamesBool[] =
  true,
  NULL, NULL, NULL
  },
+ {
+ {"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+ gettext_noop("Transform a sequence of OR clauses to an IN expression."),
+ gettext_noop("The planner will replace clauses like 'x=c1 OR x=c2 .."
+ "to the clause 'x IN (c1,c2,...)'"),
+ GUC_EXPLAIN
+ },
+ &enable_or_transformation,
+ true,
+ NULL, NULL, NULL
+ },
I think it should be something like:
+ gettext_noop("Transform a sequence of OR expressions to an array
expression."),
+ gettext_noop("The planner will replace expression like 'x=c1 OR x=c2 "
+ "to the expression 'x = ANY( ARRAY[c1,c2])''"
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+ JumbleState *jstate = NULL;
+
+ Assert(queryId != NULL);
+
+ jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+ /* Set up workspace for query jumbling */
+ jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+ jstate->jumble_len = 0;
+ jstate->clocations_buf_size = 32;
+ jstate->clocations = (LocationLen *)
+ palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+ jstate->clocations_count = 0;
+ jstate->highest_extern_param_id = 0;
+
+ /* Compute query ID */
+ _jumbleNode(jstate, (Node *) expr);
+ *queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+ jstate->jumble_len,
+ 0));
+
+ return jstate;
+}
queryId may not be a good variable name here?

comment `/* Compute query ID */`
seems not correct, here we are just hashing the expression?

+/*
+ * Dynahash match function to use in guc_hashtab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+ OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+ OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+ Assert(sizeof(OrClauseGroupKey) == keysize);
+
+ if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
+ equal(key1->expr, key2->expr))
+ return 0;
+
+ return 1;
+}
the above comments seem not correct?

<para>
Enables or disables the query planner's ability to lookup and
group multiple
similar OR expressions to ANY (<xref
linkend="functions-comparisons-any-some"/>) expressions.
The grouping technique of this transformation is based on the
similarity of variable sides.
It applies to equality expressions only. One side of such an expression
must be a constant clause, and the other must contain a variable clause.
The default is <literal>on</literal>.
Also, during BitmapScan paths generation it enables analysis of elements
of IN or ANY constant arrays to cover such clause with BitmapOr set of
partial index scans.
</para>
` It applies to equality expressions only.` seems not correct?
`select * from tenk1 where unique1 < 1 or unique1 < 2; ` can also do
the transformation.
`similarity of variable sides.` seems not correct,
should it be 'sameness of the variable sides`?

in [1]https://www.postgresql.org/docs/current/functions-comparisons.html#FUNCTIONS-COMPARISONS-IN-SCALAR, we can get:
expression IN (value [, ...])
is equivalent to
expression = value1
OR
expression = value2
OR

in [2]https://www.postgresql.org/docs/current/functions-subquery.html#FUNCTIONS-SUBQUERY-ANY-SOME, we can get:
SOME is a synonym for ANY. IN is equivalent to = ANY.

but still transforming OR to ANY is not intuitive.
a normal user may not know what is "transforming OR to ANY".
so maybe adding a simple example at
<varlistentry id="guc-enable-or-transformation"
xreflabel="enable_or_transformation">
would be great. which, I did at previous thread.

I also did some refactoring based on v18, attached.

[1]: https://www.postgresql.org/docs/current/functions-comparisons.html#FUNCTIONS-COMPARISONS-IN-SCALAR
[2]: https://www.postgresql.org/docs/current/functions-subquery.html#FUNCTIONS-SUBQUERY-ANY-SOME

Attachments:

v18-0001-Minor-miscellaneous-refactor-based-on-v18.no-cfbotapplication/octet-stream; name=v18-0001-Minor-miscellaneous-refactor-based-on-v18.no-cfbotDownload
From b57b1701ab8fe3e319ba5a7cd190fe04ca2696e0 Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Mon, 4 Mar 2024 10:18:12 +0800
Subject: [PATCH v18 1/1] Minor miscellaneous refactor based on v18.

---
 src/backend/optimizer/path/indxpath.c | 11 ++++----
 src/backend/parser/parse_expr.c       | 40 +++++++++++++++------------
 2 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 47bf5382..a7758df6 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1284,7 +1284,7 @@ build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
 		ArrayType		   *arrayval = NULL;
 		ArrayExpr		   *arr = NULL;
 		Const			   *arrayconst;
-		ScalarArrayOpExpr	dest;
+		ScalarArrayOpExpr  *dest = NULL;
 
 		pd = (PredicatesData *) lfirst(lc);
 		if (pd->elems == NIL)
@@ -1295,6 +1295,7 @@ build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
 		arrayconst = lsecond_node(Const, saop->args);
 		arrayval = DatumGetArrayTypeP(arrayconst->constvalue);
 		arr = makeNode(ArrayExpr);
+		dest = makeNode(ScalarArrayOpExpr);
 		arr->array_collid = arrayconst->constcollid;
 		arr->array_typeid = arrayconst->consttype;
 		arr->element_typeid = arrayval->elemtype;
@@ -1303,10 +1304,10 @@ build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
 		arr->multidims = false;
 
 		/* Compose new SAOP, partially covering the source one */
-		memcpy(&dest, saop, sizeof(ScalarArrayOpExpr));
-		dest.args = list_make2(linitial(saop->args), arr);
+		memcpy(dest, saop, sizeof(ScalarArrayOpExpr));
+		dest->args = list_make2(linitial(saop->args), arr);
 
-		clause = (Expr *) estimate_expression_value(root, (Node *) &dest);
+		clause = (Expr *) estimate_expression_value(root, (Node *) dest);
 
 		/*
 		 * Create new RestrictInfo. It maybe more heavy than just copy node,
@@ -1330,13 +1331,11 @@ build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
 		Assert(!predicate_implied_by(index->indpred, other_clauses, false));
 
 		/* Time to generate index paths */
-
 		MemSet(&clauseset, 0, sizeof(clauseset));
 		match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);
 		match_clauses_to_index(root, other_clauses, index, &clauseset);
 
 		/* Predicate has found already. So, it is ok for the empty match */
-
 		indexpaths = build_index_paths(root, rel,
 									   index, &clauseset,
 									   true,
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 10ceccc8..8a7432a4 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -169,23 +169,29 @@ orclause_match(const void *data1, const void *data2, Size keysize)
 }
 
 /*
- * TransformOrExprToANY -
- *	  Discover the args of an OR expression and try to group similar OR
- *	  expressions to an ANY operation.
- *	  Transformation must be already done on input args list before the call.
- *	  Transformation groups two-sided equality operations. One side of such an
- *	  operation must be plain constant or constant expression. The other side of
- *	  the clause must be a variable expression without volatile functions.
- *	  The grouping technique is based on the similarity of variable sides of the
- *	  expression: using queryId and equal() routine, it groups constant sides of
- *	  similar clauses into an array. After the grouping procedure, each couple
- *	  ('variable expression' and 'constant array') form a new SAOP operation,
- *	  which is added to the args list of the returning expression.
+ * TransformOrExprToANY
+ * Discover the args of an OR expression and try to group similar OR
+ * expressions to an ANY operation.
  *
- *	  NOTE: function returns OR BoolExpr if more than one clause are detected in
- *	  the final args list, or ScalarArrayOpExpr if all args were grouped into
- *	  the single SAOP expression.
- */
+ * Transformation must be already done on input args list before the call.
+ * Transformation groups mulitple OR expressions
+ * (i.e. ExpressionA OR ExpressionB) into a SAOP expression. For each single
+ * expression, one side of such an expression must be a plain constant or
+ * constant expression. The other side of the expression must be a variable
+ * expression without volatile functions.
+ *
+ * The grouping technique is based on the sameness of the expression's variable
+ * side. We use variable sides expression's hash key comparison function and
+ * hash routine to evaulate the sameness. Iff the variable side is the same,
+ * then we groups multiple expression's constant into an array.
+ * After the grouping procedure, each couple
+ * ('variable expression' and 'constant array') form a new SAOP expression,
+ * which is added to the args list of the returning expression.
+ *
+ * NOTE: function returns OR BoolExpr if more than one clause are detected in
+ * the final args list, or ScalarArrayOpExpr if all args were grouped into
+ * the single SAOP expression.
+*/
 static Node *
 TransformOrExprToANY(ParseState *pstate, List *args, int location)
 {
@@ -328,7 +334,6 @@ TransformOrExprToANY(ParseState *pstate, List *args, int location)
 	 * Go through the list of groups and convert each, where number of
 	 * consts more than 1. trivial groups move to OR-list again
 	 */
-
 	foreach (lc, entries)
 	{
 		Oid				    scalar_type;
@@ -353,7 +358,6 @@ TransformOrExprToANY(ParseState *pstate, List *args, int location)
 		/*
 		 * Do the transformation.
 		 */
-
 		scalar_type = entry->key.exprtype;
 		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
 											   InvalidOid;
-- 
2.34.1

#156Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alexander Korotkov (#152)
Re: POC, WIP: OR-clause support for indexes

On 1/3/2024 22:33, Alexander Korotkov wrote:

I'm going to review and revise the patch.

Nice!

One question I have yet.

        /*
         * Transformation only works with both side type is not
         * { array | composite | domain | record }.

Why do we limit transformation for these types?  Also, it doesn't seem
the current code restricts anything except composite/record.

Answer can be a bit long. Let's try to see comment a4424c5 at first.

We forbid record types although they can have typarray. It is because of
the RowExpr comparison specific. Although we have the record_eq()
routine, all base types in comparing records must be strictly the same.
Let me show:

explain analyze
SELECT * FROM
(SELECT ROW(relpages,relnatts) AS x FROM pg_class LIMIT 10) AS q1,
(SELECT ROW(relpages,relallvisible) AS x FROM pg_class LIMIT 10) AS q2
WHERE q1.x=q2.x;
ERROR: cannot compare dissimilar column types smallint and integer at
record column 2

As you can see, we have smallint and integer in the second position of
RowExpr and it causes the ERROR. It is the reason, why PostgreSQL
transforms ROW expressions to the series of ORs, Look:

explain (costs off)
SELECT oid,relname FROM pg_class
WHERE (oid,relname) IN ((1, 'a'), (2,'b'));

Bitmap Heap Scan on pg_class
Recheck Cond: ((relname = 'a'::name) OR (relname = 'b'::name))
Filter: (((oid = '1'::oid) AND (relname = 'a'::name)) OR ((oid =
'2'::oid) AND (relname = 'b'::name)))
-> BitmapOr
...

So, transforming composite types to the ScalarArrayOpExpr expression
doesn't make sense. Am I wrong?

The same with domain. If it have composite base type we reject the
transformation according to the logic above.

What about arrays? As I see, arrays don't have typarray and we can avoid
to spend more cycles after detection of TYPCATEGORY_ARRAY. I haven't
done it yet because have a second thought: what if to combine arrays
into the larger one? I'm unsure on that, so we can forbid it too.

--
regards,
Andrei Lepikhov
Postgres Professional

#157Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: jian he (#155)
Re: POC, WIP: OR-clause support for indexes

On 4/3/2024 09:26, jian he wrote:

On Thu, Feb 29, 2024 at 4:59 PM Andrei Lepikhov

Feel free to add, change or totally rewrite these changes.

On replacement of static ScalarArrayOpExpr dest with dynamic allocated one:
After discussion [1]/messages/by-id/2157387.1709068790@sss.pgh.pa.us I agree with that replacement.

Some style (and language) changes in comments I haven't applied because
it looks debatable for me.

I think it should be something like:
+ gettext_noop("Transform a sequence of OR expressions to an array
expression."),
+ gettext_noop("The planner will replace expression like 'x=c1 OR x=c2 "
+ "to the expression 'x = ANY( ARRAY[c1,c2])''"

Fixed

queryId may not be a good variable name here?

Not sure. QueryId is a concept, part of queryjumble technique and can be
used by other tools. It just tells the developer what it is the same
thing as Query Jumbling but for a separate expression.
At least you don't insist on removing of JumbleState return pointer that
looks strange for a simple hash ...

comment `/* Compute query ID */`
seems not correct, here we are just hashing the expression?

The same as above.

+/*
+ * Dynahash match function to use in guc_hashtab
the above comments seem not correct?

Yes, fixed.

` It applies to equality expressions only.` seems not correct?
`select * from tenk1 where unique1 < 1 or unique1 < 2; ` can also do
the transformation.

Yes, I forgot it.

`similarity of variable sides.` seems not correct,
should it be 'sameness of the variable sides`?

The term 'equivalence' looks better *).

in [2], we can get:
SOME is a synonym for ANY. IN is equivalent to = ANY.

but still transforming OR to ANY is not intuitive.
a normal user may not know what is "transforming OR to ANY".
so maybe adding a simple example at
<varlistentry id="guc-enable-or-transformation"
xreflabel="enable_or_transformation">
would be great. which, I did at previous thread.

Not sure. Examples in that section are unusual things. What's more,
should a user who doesn't know what it means to change this setting?
Let's wait for other opinions.

[1]: /messages/by-id/2157387.1709068790@sss.pgh.pa.us

--
regards,
Andrei Lepikhov
Postgres Professional

#158Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Andrei Lepikhov (#157)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 5/3/2024 12:30, Andrei Lepikhov wrote:

On 4/3/2024 09:26, jian he wrote:

... and the new version of the patchset is attached.

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v19-0001-Transform-OR-clauses-to-ANY-expression.patchtext/plain; charset=UTF-8; name=v19-0001-Transform-OR-clauses-to-ANY-expression.patchDownload
From 1c3ac3e006cd66ff40f1ddaaa09e3fc0f3a75ca5 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Fri, 2 Feb 2024 22:01:09 +0300
Subject: [PATCH 1/2] Transform OR clauses to ANY expression.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...]) on the
preliminary stage of optimization when we are still working with the
expression tree.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
---
 .../postgres_fdw/expected/postgres_fdw.out    |  16 +-
 doc/src/sgml/config.sgml                      |  17 +
 src/backend/nodes/queryjumblefuncs.c          |  27 ++
 src/backend/parser/parse_expr.c               | 339 ++++++++++++++++++
 src/backend/utils/misc/guc_tables.c           |  11 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/bin/pg_dump/t/002_pg_dump.pl              |   6 +-
 src/include/nodes/queryjumble.h               |   1 +
 src/include/optimizer/optimizer.h             |   1 +
 src/test/regress/expected/create_index.out    | 156 +++++++-
 src/test/regress/expected/inherit.out         |   2 +-
 src/test/regress/expected/join.out            |  62 +++-
 src/test/regress/expected/partition_prune.out | 219 +++++++++--
 src/test/regress/expected/rules.out           |   4 +-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  35 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 22 files changed, 906 insertions(+), 69 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index c355e8f3f7..0523bbd8f7 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -1349,7 +1349,7 @@ SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE
  Foreign Scan
    Output: t1.c1, t1.c2, ft5.c1, ft5.c2
    Relations: (public.ft4 t1) LEFT JOIN (public.ft5)
-   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 < 10) OR (r4.c1 IS NULL))) AND ((r1.c1 < 10))
+   Remote SQL: SELECT r1.c1, r1.c2, r4.c1, r4.c2 FROM ("S 1"."T 3" r1 LEFT JOIN "S 1"."T 4" r4 ON (((r1.c1 = r4.c1)) AND ((r4.c1 < 10)))) WHERE (((r4.c1 IS NULL) OR (r4.c1 < 10))) AND ((r1.c1 < 10))
 (4 rows)
 
 SELECT t1.c1, t1.c2, t2.c1, t2.c2 FROM ft4 t1 LEFT JOIN (SELECT * FROM ft5 WHERE c1 < 10) t2 ON (t1.c1 = t2.c1)
@@ -3105,7 +3105,7 @@ select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5)) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3123,7 +3123,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5))), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -3140,7 +3140,7 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4
  Foreign Scan
    Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST)), ((t2.c1 % 3))
    Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
-   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
+   Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE ((((r1.c1 IS NULL) AND (r2.c1 < 5)) OR (r1.c1 < 20))) GROUP BY 2 ORDER BY array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST) ASC NULLS LAST
 (4 rows)
 
 select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -8797,18 +8797,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index b38cbd714a..1fdfffd79b 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5433,6 +5433,23 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-enable-or-transformation" xreflabel="enable_or_transformation">
+      <term><varname>enable_or_transformation</varname> (<type>boolean</type>)
+       <indexterm>
+        <primary><varname>enable_or_transformation</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      <listitem>
+       <para>
+        Enables or disables the query planner's ability to lookup and group multiple
+        similar OR expressions to ANY (<xref linkend="functions-comparisons-any-some"/>) expressions.
+        The grouping technique of this transformation is based on the equivalence of variable sides.
+        One side of such an expression must be a constant clause, and the other must contain a variable clause.
+        The default is <literal>on</literal>.
+        </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-enable-parallel-append" xreflabel="enable_parallel_append">
       <term><varname>enable_parallel_append</varname> (<type>boolean</type>)
       <indexterm>
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 426112fa37..c4c4cab8ed 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -141,6 +141,33 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 9300c7b9ab..73298ad621 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,14 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -38,11 +40,13 @@
 #include "utils/date.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +103,336 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+
+	Node		   *node;
+	List		   *consts;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function to find candidate clauses.
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				hash;
+
+	Assert(keysize == sizeof(OrClauseGroupKey));
+
+	(void) JumbleExpr(key->expr, &hash);
+	hash += ((uint64) key->opno + (uint64) key->exprtype);
+	return (uint32) (hash % UINT32_MAX);
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in or_group_htab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+
+	if (key1->opno == key2->opno && key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+/*
+ * TransformOrExprToANY -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to an ANY operation.
+ *	  Transformation must be already done on input args list before the call.
+ *	  Transformation groups two-sided equality operations. One side of such an
+ *	  operation must be plain constant or constant expression. The other side of
+ *	  the clause must be a variable expression without volatile functions.
+ *	  The grouping technique is based on an equivalence of variable sides of the
+ *	  expression: using queryId and equal() routine, it groups constant sides of
+ *	  similar clauses into an array. After the grouping procedure, each couple
+ *	  ('variable expression' and 'constant array') form a new SAOP operation,
+ *	  which is added to the args list of the returning expression.
+ *
+ *	  NOTE: function returns OR BoolExpr if more than one clause are detected in
+ *	  the final args list, or ScalarArrayOpExpr if all args were grouped into
+ *	  the single SAOP expression.
+ */
+static Node *
+TransformOrExprToANY(ParseState *pstate, List *args, int location)
+{
+	List				   *or_list = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(args);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	Assert(enable_or_transformation && len_ors > 1);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, args)
+	{
+		Node				   *orqual = lfirst(lc);
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Oid						exprtype;
+		Node				   *leftop, *rightop;
+
+		if (!IsA(orqual, OpExpr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				or_list = lappend(or_list, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		 * Transformation only works with both side type is not
+		 * { array | composite | domain | record }.
+		 * Also, forbid it for volatile expressions.
+		 */
+		exprtype = exprType(nconst_expr);
+		if (type_is_rowtype(exprType(const_expr)) ||
+			type_is_rowtype(exprtype) ||
+			contain_volatile_functions((Node *) nconst_expr))
+		{
+			or_list = lappend(or_list, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.exprtype = exprtype;
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->node = nconst_expr;
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element in the class. Return origin expression into
+			 * the BoolExpr args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.exprtype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+											   InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+			ListCell		   *lc1;
+
+			foreach(lc1, entry->consts)
+			{
+				Node   *rexpr = (Node *) lfirst(lc1);
+
+				rexpr = coerce_to_common_type(pstate, rexpr,
+											  scalar_type,
+											  "IN");
+				aexprs = lappend(aexprs, rexpr);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 entry->node,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -1386,6 +1720,11 @@ transformBoolExpr(ParseState *pstate, BoolExpr *a)
 		args = lappend(args, arg);
 	}
 
+	/* Make an attempt to group similar OR clauses into ANY operation */
+	if (enable_or_transformation && a->boolop == OR_EXPR &&
+		list_length(args) > 1)
+		return TransformOrExprToANY(pstate, args, a->location);
+
 	return (Node *) makeBoolExpr(a->boolop, args, a->location);
 }
 
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 543a87c659..e82f6b7f42 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1026,6 +1026,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an array expression."),
+			gettext_noop("The planner will replace expression like 'x=c1 OR x=c2 ..'"
+						 "to the expression 'x = ANY(ARRAY[c1,c2,..])'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index edcc0282b2..d30dc6d51c 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -389,6 +389,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 00b5092713..d28bf617db 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -2095,9 +2095,9 @@ my %tests = (
 		regexp => qr/^
 			\QCREATE DOMAIN dump_test.us_postal_code AS text COLLATE pg_catalog."C" DEFAULT '10014'::text\E\n\s+
 			\QCONSTRAINT us_postal_code_check CHECK \E
-			\Q(((VALUE ~ '^\d{5}\E
-			\$\Q'::text) OR (VALUE ~ '^\d{5}-\d{4}\E\$
-			\Q'::text)));\E(.|\n)*
+			\Q((VALUE ~ ANY (ARRAY['^\d{5}\E
+			\$\Q'::text, '^\d{5}-\d{4}\E\$
+			\Q'::text])));\E(.|\n)*
 			\QCOMMENT ON CONSTRAINT us_postal_code_check ON DOMAIN dump_test.us_postal_code IS 'check it';\E
 			/xm,
 		like =>
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067..a9ae048af5 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 7b63c5cf71..35ab577501 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -50,6 +50,7 @@ struct PlannedStmt;
 struct ParamListInfoData;
 struct HeapTupleData;
 
+extern PGDLLIMPORT bool enable_or_transformation;
 
 /* in path/clausesel.c: */
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 79fa117cb5..b8653c09ea 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,116 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 130a924228..684886336c 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -2600,7 +2600,7 @@ explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd'
                                    QUERY PLAN                                    
 ---------------------------------------------------------------------------------
  Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 'ab'::text))
 (2 rows)
 
 explain (costs off) select * from list_parted where a = 'ab';
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9605400021..cd2d78a636 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)) OR (a.unique1 < 20) OR (a.unique1 = 3))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])) OR (unique1 < 20) OR (unique1 = 3))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index bf0657b9f2..58a96a29a6 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -589,20 +611,20 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 ------------------------------------------------------
  Append
    ->  Seq Scan on rlp1 rlp_1
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
    ->  Seq Scan on rlp4_1 rlp_2
-         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
 (5 rows)
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: (((a > 20) AND (a < 25)) OR (a < 1))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -2072,10 +2251,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 0cd2c64fca..0378280c7d 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2501,7 +2501,7 @@ pg_stats| SELECT n.nspname AS schemaname,
      JOIN pg_class c ON ((c.oid = s.starelid)))
      JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
-  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+  WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
@@ -2532,7 +2532,7 @@ pg_stats_ext| SELECT cn.nspname AS schemaname,
   WHERE ((NOT (EXISTS ( SELECT 1
            FROM (unnest(s.stxkeys) k(k)
              JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
-          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
+          WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((NOT row_security_active(c.oid)) OR (c.relrowsecurity = false)));
 pg_stats_ext_exprs| SELECT cn.nspname AS schemaname,
     c.relname AS tablename,
     sn.nspname AS statistics_schemaname,
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 10903bdab0..6f55b9e3ec 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 9be7aca2b8..1f9029b5b2 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -124,6 +124,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -134,7 +135,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(23 rows)
+(24 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..2a079e996b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..56fde15bc1 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index c4c6c7b8ba..1663608043 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index a09b27d820..9717c8c835 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 782b7d7b1c..c81f6caba8 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1657,6 +1657,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.43.2

v19-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchtext/plain; charset=UTF-8; name=v19-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchDownload
From 99bdb199a240bd7b9d6e300bedddc9084c53b973 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Tue, 5 Mar 2024 13:29:46 +0700
Subject: [PATCH 2/2] Teach generate_bitmap_or_paths to build BitmapOr paths
 over SAOP clauses.

Likewise OR clauses, discover SAOP array and try to split its elements
between smaller sized arrays to fit a set of partial indexes.
---
 doc/src/sgml/config.sgml                  |   3 +
 src/backend/optimizer/path/indxpath.c     | 315 ++++++++++++++++++----
 src/backend/optimizer/util/predtest.c     |  46 ++++
 src/backend/optimizer/util/restrictinfo.c |  13 +
 src/include/optimizer/optimizer.h         |  16 ++
 src/include/optimizer/restrictinfo.h      |   1 +
 src/test/regress/expected/select.out      | 282 +++++++++++++++++++
 src/test/regress/sql/select.sql           |  82 ++++++
 src/tools/pgindent/typedefs.list          |   1 +
 9 files changed, 706 insertions(+), 53 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 1fdfffd79b..8008b05327 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5446,6 +5446,9 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
         The grouping technique of this transformation is based on the equivalence of variable sides.
         One side of such an expression must be a constant clause, and the other must contain a variable clause.
         The default is <literal>on</literal>.
+        Also, during BitmapScan paths generation it enables analysis of elements
+        of IN or ANY constant arrays to cover such clause with BitmapOr set of
+        partial index scans.
         </para>
       </listitem>
      </varlistentry>
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 32c6a8bbdc..f92a47c3d5 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,6 +32,7 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
 
@@ -1220,11 +1221,188 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Building index paths over SAOP clause differs from the logic of OR clauses.
+ * Here we iterate across all the array elements and split them to SAOPs,
+ * corresponding to different indexes. We must match each element to an index.
+ */
+static List *
+build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
+					 List *other_clauses)
+{
+	List			   *result = NIL;
+	List			   *predicate_lists = NIL;
+	ListCell		   *lc;
+	PredicatesData	   *pd;
+	ScalarArrayOpExpr  *saop = (ScalarArrayOpExpr *) rinfo->clause;
+
+	Assert(IsA(saop, ScalarArrayOpExpr) && saop->useOr);
+
+	if (!IsA(lsecond(saop->args), Const))
+		/*
+		 * Has it practical outcome to merge arrays which couldn't constantified
+		 * before that step?
+		 */
+		return NIL;
+
+	/* Collect predicates */
+	foreach(lc, rel->indexlist)
+	{
+		IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
+
+		/* Take into consideration partial indexes supporting bitmap scans */
+		if (!index->amhasgetbitmap || index->indpred == NIL || index->predOK)
+			continue;
+
+		pd = palloc0(sizeof(PredicatesData));
+		pd->id = foreach_current_index(lc);
+		/* The trick with reducing recursion is stolen from predicate_implied_by */
+		pd->predicate = list_length(index->indpred) == 1 ?
+										(Node *) linitial(index->indpred) :
+										(Node *) index->indpred;
+		predicate_lists = lappend(predicate_lists, (void *) pd);
+	}
+
+	/* Split the array data according to index predicates. */
+	if (predicate_lists == NIL ||
+		!saop_covered_by_predicates(saop, predicate_lists))
+		return NIL;
+
+	other_clauses = list_delete_ptr(other_clauses, rinfo);
+
+	/*
+	 * Having incoming SAOP split to set of smaller SAOPs which can be applied
+	 * to partial indexes, generate paths for each one.
+	 */
+	foreach(lc, predicate_lists)
+	{
+		IndexOptInfo	   *index;
+		IndexClauseSet		clauseset;
+		List			   *indexpaths;
+		RestrictInfo	   *rinfo1 = NULL;
+		Expr			   *clause;
+		ArrayType		   *arrayval = NULL;
+		ArrayExpr		   *arr = NULL;
+		Const			   *arrayconst;
+		ScalarArrayOpExpr  *dest;
+
+		pd = (PredicatesData *) lfirst(lc);
+		if (pd->elems == NIL)
+			/* The index doesn't participate in this operation */
+			continue;
+
+		/* Make up new array */
+		arrayconst = lsecond_node(Const, saop->args);
+		arrayval = DatumGetArrayTypeP(arrayconst->constvalue);
+		arr = makeNode(ArrayExpr);
+		arr->array_collid = arrayconst->constcollid;
+		arr->array_typeid = arrayconst->consttype;
+		arr->element_typeid = arrayval->elemtype;
+		arr->elements = pd->elems;
+		arr->location = -1;
+		arr->multidims = false;
+
+		/* Compose new SAOP, partially covering the source one */
+		dest = makeNode(ScalarArrayOpExpr);
+		memcpy(dest, saop, sizeof(ScalarArrayOpExpr));
+		dest->args = list_make2(linitial(saop->args), arr);
+		clause = (Expr *) estimate_expression_value(root, (Node *) dest);
+
+		/*
+		 * Create new RestrictInfo. It maybe more heavy than just copy node,
+		 * but remember some internals: the serial number, selectivity
+		 * cache etc.
+		 */
+		rinfo1 = make_restrictinfo(root, clause,
+								   rinfo->is_pushed_down,
+								   rinfo->has_clone,
+								   rinfo->is_clone,
+								   rinfo->pseudoconstant,
+								   rinfo->security_level,
+								   rinfo->required_relids,
+								   rinfo->incompatible_relids,
+								   rinfo->outer_relids);
+
+		index = list_nth(rel->indexlist, pd->id);
+		Assert(predicate_implied_by(index->indpred, list_make1(rinfo1), true));
+
+		/* Excluding partial indexes with predOK we make this statement false */
+		Assert(!predicate_implied_by(index->indpred, other_clauses, false));
+
+		/* Time to generate index paths */
+
+		MemSet(&clauseset, 0, sizeof(clauseset));
+		match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);
+		match_clauses_to_index(root, other_clauses, index, &clauseset);
+
+		/* Predicate has found already. So, it is ok for the empty match */
+
+		indexpaths = build_index_paths(root, rel,
+									   index, &clauseset,
+									   true,
+									   ST_BITMAPSCAN,
+									   NULL,
+									   NULL);
+		Assert(indexpaths != NIL);
+		result = lappend(result, indexpaths);
+	}
+	return result;
+}
+
+/*
+ * Analyse incoming SAOP node to cover it by partial indexes.
+ *
+ * The returning pathlist must be ANDed to the final BitmapScan path.
+ * The function returns NULL when an array element cannot be fitted with some
+ * partial index. The Rationale for such an operation is that when schema
+ * contains many partial indexes, the SAOP clause may be effectively fulfilled
+ * by appending results of scanning some minimal set of tiny partial indexes.
+ *
+ * Working jointly with the TransformOrExprToANY routine, it provides a user
+ * with some sort of independence of the query plan from the approach to writing
+ * alternatives for the same entity in the WHERE section.
+ */
+static List *
+generate_saop_pathlist(PlannerInfo *root, RelOptInfo *rel,
+					   RestrictInfo *rinfo, List *all_clauses)
+{
+	List	   *pathlist = NIL;
+	Path	   *bitmapqual;
+	List	   *indlist;
+	ListCell   *lc;
+
+	if (!enable_or_transformation)
+		return NIL;
+
+	/*
+	 * We must be able to match at least one index to each element of
+	 * the array, else we can't use it.
+	 */
+	indlist = build_paths_for_SAOP(root, rel, rinfo, all_clauses);
+	if (indlist == NIL)
+		return NIL;
+
+	/*
+	 * OK, pick the most promising AND combination, and add it to
+	 * pathlist.
+	 */
+	foreach (lc, indlist)
+	{
+		List *plist = lfirst_node(List, lc);
+
+		bitmapqual = choose_bitmap_and(root, rel, plist);
+		pathlist = lappend(pathlist, bitmapqual);
+	}
+
+	return pathlist;
+}
+
 /*
  * generate_bitmap_or_paths
- *		Look through the list of clauses to find OR clauses, and generate
- *		a BitmapOrPath for each one we can handle that way.  Return a list
- *		of the generated BitmapOrPaths.
+ *		Look through the list of clauses to find OR and SAOP clauses, and
+ *		Each saop clause are splitted to be covered by partial indexes.
+ *		generate a BitmapOrPath for each one we can handle that way.
+ *		Return a list of the generated BitmapOrPaths.
  *
  * other_clauses is a list of additional clauses that can be assumed true
  * for the purpose of generating indexquals, but are not to be searched for
@@ -1247,68 +1425,99 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	foreach(lc, clauses)
 	{
 		RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
-		List	   *pathlist;
+		List	   *pathlist = NIL;
 		Path	   *bitmapqual;
 		ListCell   *j;
 
-		/* Ignore RestrictInfos that aren't ORs */
-		if (!restriction_is_or_clause(rinfo))
+		if (restriction_is_saop_clause(rinfo))
+		{
+			pathlist = generate_saop_pathlist(root, rel, rinfo,
+											  all_clauses);
+		}
+		else if (!restriction_is_or_clause(rinfo))
+			/* Ignore RestrictInfos that aren't ORs */
 			continue;
-
-		/*
-		 * We must be able to match at least one index to each of the arms of
-		 * the OR, else we can't use it.
-		 */
-		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		else
 		{
-			Node	   *orarg = (Node *) lfirst(j);
-			List	   *indlist;
-
-			/* OR arguments should be ANDs or sub-RestrictInfos */
-			if (is_andclause(orarg))
+			/*
+			 * We must be able to match at least one index to each of the arms of
+			 * the OR, else we can't use it.
+			 */
+			foreach(j, ((BoolExpr *) rinfo->orclause)->args)
 			{
-				List	   *andargs = ((BoolExpr *) orarg)->args;
+				Node	   *orarg = (Node *) lfirst(j);
+				List	   *indlist;
 
-				indlist = build_paths_for_OR(root, rel,
-											 andargs,
-											 all_clauses);
+				/* OR arguments should be ANDs or sub-RestrictInfos */
+				if (is_andclause(orarg))
+				{
+					List	   *andargs = ((BoolExpr *) orarg)->args;
 
-				/* Recurse in case there are sub-ORs */
-				indlist = list_concat(indlist,
-									  generate_bitmap_or_paths(root, rel,
-															   andargs,
-															   all_clauses));
-			}
-			else
-			{
-				RestrictInfo *ri = castNode(RestrictInfo, orarg);
-				List	   *orargs;
+					indlist = build_paths_for_OR(root, rel,
+												 andargs,
+												 all_clauses);
 
-				Assert(!restriction_is_or_clause(ri));
-				orargs = list_make1(ri);
+					/* Recurse in case there are sub-ORs */
+					indlist = list_concat(indlist,
+										  generate_bitmap_or_paths(root, rel,
+																   andargs,
+																   all_clauses));
+				}
+				else
+				{
+					RestrictInfo *ri = castNode(RestrictInfo, orarg);
+					List	   *orargs;
 
-				indlist = build_paths_for_OR(root, rel,
-											 orargs,
-											 all_clauses);
-			}
+					Assert(!restriction_is_or_clause(ri));
 
-			/*
-			 * If nothing matched this arm, we can't do anything with this OR
-			 * clause.
-			 */
-			if (indlist == NIL)
-			{
-				pathlist = NIL;
-				break;
-			}
+					orargs = list_make1(ri);
 
-			/*
-			 * OK, pick the most promising AND combination, and add it to
-			 * pathlist.
-			 */
-			bitmapqual = choose_bitmap_and(root, rel, indlist);
-			pathlist = lappend(pathlist, bitmapqual);
+					if (restriction_is_saop_clause(ri))
+					{
+						List *paths;
+
+						paths = generate_saop_pathlist(root, rel, ri,
+														 all_clauses);
+
+						if (paths != NIL)
+						{
+							/*
+							 * Add paths to pathlist and immediately jump to the
+							 * next element of the OR clause.
+							 */
+							pathlist = list_concat(pathlist, paths);
+							continue;
+						}
+
+						/*
+						 * Pass down out of this if construction:
+						 * If saop isn't covered by partial indexes, try to
+						 * build scan path for the saop as a whole.
+						 */
+					}
+
+					indlist = build_paths_for_OR(root, rel,
+												 orargs,
+												 all_clauses);
+				}
+
+				/*
+				 * If nothing matched this arm, we can't do anything with this OR
+				 * clause.
+				 */
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+
+				/*
+				 * OK, pick the most promising AND combination, and add it to
+				 * pathlist.
+				 */
+				bitmapqual = choose_bitmap_and(root, rel, indlist);
+				pathlist = lappend(pathlist, bitmapqual);
+			}
 		}
 
 		/*
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index c37b416e24..8ed80a78b4 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -112,6 +112,52 @@ static Oid	get_btree_test_op(Oid pred_op, Oid clause_op, bool refute_it);
 static void InvalidateOprProofCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
 
 
+/*
+ * Could this ANY () expression can be split into a set of ANYs over partial
+ * indexes? If yes, return these saops in the PredicatesData structure.
+ */
+bool
+saop_covered_by_predicates(ScalarArrayOpExpr *saop, List *predicate_lists)
+{
+	ListCell		   *lc;
+	PredIterInfoData	clause_info;
+	bool				result = false;
+
+	if (predicate_classify((Node *) saop, &clause_info) != CLASS_OR)
+		return false;
+
+	iterate_begin(pitem, (Node *) saop, clause_info)
+	{
+		result = false;
+
+		foreach(lc, predicate_lists)
+		{
+			PredicatesData *pd = (PredicatesData *) lfirst(lc);
+
+			if (!predicate_implied_by_recurse(pitem, pd->predicate, false))
+				continue;
+
+			/* Predicate is found. Add the elem to the saop clause */
+			Assert(IsA(pitem, OpExpr));
+
+			/* Extract constant from the expression */
+			pd->elems = lappend(pd->elems,
+					copyObject(lsecond_node(Const, ((OpExpr *) pitem)->args)));
+			result = true;
+			break;
+		}
+
+		if (!result)
+			/*
+			 * The element doesn't fit any index. Interrupt the process immediately
+			 */
+			break;
+	}
+	iterate_end(clause_info);
+
+	return result;
+}
+
 /*
  * predicate_implied_by
  *	  Recursively checks whether the clauses in clause_list imply that the
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e9334..1dad1dc654 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -421,6 +421,19 @@ restriction_is_or_clause(RestrictInfo *restrictinfo)
 		return false;
 }
 
+bool
+restriction_is_saop_clause(RestrictInfo *restrictinfo)
+{
+	if (restrictinfo->clause && IsA(restrictinfo->clause, ScalarArrayOpExpr))
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) restrictinfo->clause;
+
+		if (saop->useOr)
+			return true;
+	}
+	return false;
+}
+
 /*
  * restriction_is_securely_promotable
  *
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 35ab577501..232afcd00c 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -160,6 +160,22 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+/*
+ * Contains information needed to extract from saop a set of elements which can
+ * be covered by the partial index:
+ * id - caller's identification of the index.
+ * predicate - predicate expression of the index
+ * elems - returning list of array elements which corresponds to this predicate
+ */
+typedef struct PredicatesData
+{
+	int		id;
+	Node   *predicate;
+	List   *elems;
+} PredicatesData;
+
+extern bool saop_covered_by_predicates(ScalarArrayOpExpr *saop,
+									  List *predicate_lists);
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c5..2cd5fbf943 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -34,6 +34,7 @@ extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Relids outer_relids);
 extern RestrictInfo *commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op);
 extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
+extern bool restriction_is_saop_clause(RestrictInfo *restrictinfo);
 extern bool restriction_is_securely_promotable(RestrictInfo *restrictinfo,
 											   RelOptInfo *rel);
 extern List *get_actual_clauses(List *restrictinfo_list);
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e..768c9b0780 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -907,6 +907,288 @@ select unique1, unique2 from onek2
        0 |     998
 (2 rows)
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: ((stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Without the transformation only seqscan possible here
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                         QUERY PLAN                                          
+---------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])) AND (stringu1 < 'Z'::name))
+(2 rows)
+
+-- Use partial indexes
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+                 QUERY PLAN                 
+--------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = 1) OR (unique2 = 3))
+(2 rows)
+
+RESET enable_or_transformation;
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+-- Don't scan partial indexes because of extra value.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+                      QUERY PLAN                      
+------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on onek2
+         Filter: (stringu1 = ANY ('{A,J,C}'::name[]))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+                                      QUERY PLAN                                       
+---------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (stringu1 < 'B'::name)
+   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = ANY ('{A,A}'::name[])))
+   ->  Bitmap Index Scan on onek2_u2_prtl
+(4 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                                          QUERY PLAN                                                           
+-------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name)) OR ((unique2 < 1) AND (stringu1 < 'B'::name)))
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: ((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 < 1)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 = 3) OR (unique1 = 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 3)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 1)
+(7 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+                                                             QUERY PLAN                                                             
+------------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = ((random() * '2'::double precision))::integer) OR (unique1 = ((random() * '3'::double precision))::integer))
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+                                                           QUERY PLAN                                                            
+---------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: (unique1 = ANY (ARRAY[((random() * '2'::double precision))::integer, ((random() * '3'::double precision))::integer]))
+(2 rows)
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+                                                                                          QUERY PLAN                                                                                          
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[]))) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 = ANY ('{1,2,21}'::integer[])) AND ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 = ANY ('{3,4}'::integer[])) OR (stringu1 = 'J'::name)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[])))
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(11 rows)
+
+-- Check recursive combination of OR and SAOP expressions
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR (unique1 < 1))
+   Filter: ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 < 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR (unique1 < 1))
+   Filter: ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 < 1))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+(9 rows)
+
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+RESET enable_indexscan;
+RESET enable_seqscan;
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql
index 019f1e7673..223f55af4e 100644
--- a/src/test/regress/sql/select.sql
+++ b/src/test/regress/sql/select.sql
@@ -234,6 +234,88 @@ select unique1, unique2 from onek2
 select unique1, unique2 from onek2
   where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+-- Without the transformation only seqscan possible here
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+-- Use partial indexes
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+RESET enable_or_transformation;
+
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+
+-- Don't scan partial indexes because of extra value.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+EXPLAIN (COSTS OFF)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+
+-- Check recursive combination of OR and SAOP expressions
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+
+RESET enable_indexscan;
+RESET enable_seqscan;
+
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index c81f6caba8..dade69f47a 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2142,6 +2142,7 @@ PredIterInfoData
 PredXactList
 PredicateLockData
 PredicateLockTargetType
+PredicatesData
 PrefetchBufferResult
 PrepParallelRestorePtrType
 PrepareStmt
-- 
2.43.2

#159Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#158)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!

On Tue, Mar 5, 2024 at 9:59 AM Andrei Lepikhov <a.lepikhov@postgrespro.ru>
wrote:

On 5/3/2024 12:30, Andrei Lepikhov wrote:

On 4/3/2024 09:26, jian he wrote:

... and the new version of the patchset is attached.

I made some revisions for the patchset.
1) Use hash_combine() to combine hash values.
2) Upper limit the number of array elements by MAX_SAOP_ARRAY_SIZE.
3) Better save the original order of clauses by putting hash entries and
untransformable clauses to the same list. A lot of differences in
regression tests output have gone.

One important issue I found.

# create table t as (select i::int%100 i from generate_series(1,10000) i);
# analyze t;
# explain select * from t where i = 1 or i = 1;
QUERY PLAN
-----------------------------------------------------
Seq Scan on t (cost=0.00..189.00 rows=200 width=4)
Filter: (i = ANY ('{1,1}'::integer[]))
(2 rows)

# set enable_or_transformation = false;
SET
# explain select * from t where i = 1 or i = 1;
QUERY PLAN
-----------------------------------------------------
Seq Scan on t (cost=0.00..189.00 rows=100 width=4)
Filter: (i = 1)
(2 rows)

We don't make array values unique. That might make query execution
performance somewhat worse, and also makes selectivity estimation worse. I
suggest Andrei and/or Alena should implement making array values unique.

------
Regards,
Alexander Korotkov

Attachments:

v20-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr.patchapplication/octet-stream; name=v20-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr.patchDownload
From 65f0d0d582af25c3a532646f0979ac336dd16a0f Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Tue, 5 Mar 2024 13:29:46 +0700
Subject: [PATCH v20 2/2] Teach generate_bitmap_or_paths to build BitmapOr
 paths over SAOP clauses.

Likewise OR clauses, discover SAOP array and try to split its elements
between smaller sized arrays to fit a set of partial indexes.
---
 doc/src/sgml/config.sgml                  |   3 +
 src/backend/optimizer/path/indxpath.c     | 315 ++++++++++++++++++----
 src/backend/optimizer/util/predtest.c     |  46 ++++
 src/backend/optimizer/util/restrictinfo.c |  13 +
 src/include/optimizer/optimizer.h         |  16 ++
 src/include/optimizer/restrictinfo.h      |   1 +
 src/test/regress/expected/select.out      | 282 +++++++++++++++++++
 src/test/regress/sql/select.sql           |  82 ++++++
 src/tools/pgindent/typedefs.list          |   1 +
 9 files changed, 706 insertions(+), 53 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 1fdfffd79b0..8008b05327b 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5446,6 +5446,9 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
         The grouping technique of this transformation is based on the equivalence of variable sides.
         One side of such an expression must be a constant clause, and the other must contain a variable clause.
         The default is <literal>on</literal>.
+        Also, during BitmapScan paths generation it enables analysis of elements
+        of IN or ANY constant arrays to cover such clause with BitmapOr set of
+        partial index scans.
         </para>
       </listitem>
      </varlistentry>
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 32c6a8bbdcb..f92a47c3d53 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,6 +32,7 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
 
@@ -1220,11 +1221,188 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Building index paths over SAOP clause differs from the logic of OR clauses.
+ * Here we iterate across all the array elements and split them to SAOPs,
+ * corresponding to different indexes. We must match each element to an index.
+ */
+static List *
+build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
+					 List *other_clauses)
+{
+	List			   *result = NIL;
+	List			   *predicate_lists = NIL;
+	ListCell		   *lc;
+	PredicatesData	   *pd;
+	ScalarArrayOpExpr  *saop = (ScalarArrayOpExpr *) rinfo->clause;
+
+	Assert(IsA(saop, ScalarArrayOpExpr) && saop->useOr);
+
+	if (!IsA(lsecond(saop->args), Const))
+		/*
+		 * Has it practical outcome to merge arrays which couldn't constantified
+		 * before that step?
+		 */
+		return NIL;
+
+	/* Collect predicates */
+	foreach(lc, rel->indexlist)
+	{
+		IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
+
+		/* Take into consideration partial indexes supporting bitmap scans */
+		if (!index->amhasgetbitmap || index->indpred == NIL || index->predOK)
+			continue;
+
+		pd = palloc0(sizeof(PredicatesData));
+		pd->id = foreach_current_index(lc);
+		/* The trick with reducing recursion is stolen from predicate_implied_by */
+		pd->predicate = list_length(index->indpred) == 1 ?
+										(Node *) linitial(index->indpred) :
+										(Node *) index->indpred;
+		predicate_lists = lappend(predicate_lists, (void *) pd);
+	}
+
+	/* Split the array data according to index predicates. */
+	if (predicate_lists == NIL ||
+		!saop_covered_by_predicates(saop, predicate_lists))
+		return NIL;
+
+	other_clauses = list_delete_ptr(other_clauses, rinfo);
+
+	/*
+	 * Having incoming SAOP split to set of smaller SAOPs which can be applied
+	 * to partial indexes, generate paths for each one.
+	 */
+	foreach(lc, predicate_lists)
+	{
+		IndexOptInfo	   *index;
+		IndexClauseSet		clauseset;
+		List			   *indexpaths;
+		RestrictInfo	   *rinfo1 = NULL;
+		Expr			   *clause;
+		ArrayType		   *arrayval = NULL;
+		ArrayExpr		   *arr = NULL;
+		Const			   *arrayconst;
+		ScalarArrayOpExpr  *dest;
+
+		pd = (PredicatesData *) lfirst(lc);
+		if (pd->elems == NIL)
+			/* The index doesn't participate in this operation */
+			continue;
+
+		/* Make up new array */
+		arrayconst = lsecond_node(Const, saop->args);
+		arrayval = DatumGetArrayTypeP(arrayconst->constvalue);
+		arr = makeNode(ArrayExpr);
+		arr->array_collid = arrayconst->constcollid;
+		arr->array_typeid = arrayconst->consttype;
+		arr->element_typeid = arrayval->elemtype;
+		arr->elements = pd->elems;
+		arr->location = -1;
+		arr->multidims = false;
+
+		/* Compose new SAOP, partially covering the source one */
+		dest = makeNode(ScalarArrayOpExpr);
+		memcpy(dest, saop, sizeof(ScalarArrayOpExpr));
+		dest->args = list_make2(linitial(saop->args), arr);
+		clause = (Expr *) estimate_expression_value(root, (Node *) dest);
+
+		/*
+		 * Create new RestrictInfo. It maybe more heavy than just copy node,
+		 * but remember some internals: the serial number, selectivity
+		 * cache etc.
+		 */
+		rinfo1 = make_restrictinfo(root, clause,
+								   rinfo->is_pushed_down,
+								   rinfo->has_clone,
+								   rinfo->is_clone,
+								   rinfo->pseudoconstant,
+								   rinfo->security_level,
+								   rinfo->required_relids,
+								   rinfo->incompatible_relids,
+								   rinfo->outer_relids);
+
+		index = list_nth(rel->indexlist, pd->id);
+		Assert(predicate_implied_by(index->indpred, list_make1(rinfo1), true));
+
+		/* Excluding partial indexes with predOK we make this statement false */
+		Assert(!predicate_implied_by(index->indpred, other_clauses, false));
+
+		/* Time to generate index paths */
+
+		MemSet(&clauseset, 0, sizeof(clauseset));
+		match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);
+		match_clauses_to_index(root, other_clauses, index, &clauseset);
+
+		/* Predicate has found already. So, it is ok for the empty match */
+
+		indexpaths = build_index_paths(root, rel,
+									   index, &clauseset,
+									   true,
+									   ST_BITMAPSCAN,
+									   NULL,
+									   NULL);
+		Assert(indexpaths != NIL);
+		result = lappend(result, indexpaths);
+	}
+	return result;
+}
+
+/*
+ * Analyse incoming SAOP node to cover it by partial indexes.
+ *
+ * The returning pathlist must be ANDed to the final BitmapScan path.
+ * The function returns NULL when an array element cannot be fitted with some
+ * partial index. The Rationale for such an operation is that when schema
+ * contains many partial indexes, the SAOP clause may be effectively fulfilled
+ * by appending results of scanning some minimal set of tiny partial indexes.
+ *
+ * Working jointly with the TransformOrExprToANY routine, it provides a user
+ * with some sort of independence of the query plan from the approach to writing
+ * alternatives for the same entity in the WHERE section.
+ */
+static List *
+generate_saop_pathlist(PlannerInfo *root, RelOptInfo *rel,
+					   RestrictInfo *rinfo, List *all_clauses)
+{
+	List	   *pathlist = NIL;
+	Path	   *bitmapqual;
+	List	   *indlist;
+	ListCell   *lc;
+
+	if (!enable_or_transformation)
+		return NIL;
+
+	/*
+	 * We must be able to match at least one index to each element of
+	 * the array, else we can't use it.
+	 */
+	indlist = build_paths_for_SAOP(root, rel, rinfo, all_clauses);
+	if (indlist == NIL)
+		return NIL;
+
+	/*
+	 * OK, pick the most promising AND combination, and add it to
+	 * pathlist.
+	 */
+	foreach (lc, indlist)
+	{
+		List *plist = lfirst_node(List, lc);
+
+		bitmapqual = choose_bitmap_and(root, rel, plist);
+		pathlist = lappend(pathlist, bitmapqual);
+	}
+
+	return pathlist;
+}
+
 /*
  * generate_bitmap_or_paths
- *		Look through the list of clauses to find OR clauses, and generate
- *		a BitmapOrPath for each one we can handle that way.  Return a list
- *		of the generated BitmapOrPaths.
+ *		Look through the list of clauses to find OR and SAOP clauses, and
+ *		Each saop clause are splitted to be covered by partial indexes.
+ *		generate a BitmapOrPath for each one we can handle that way.
+ *		Return a list of the generated BitmapOrPaths.
  *
  * other_clauses is a list of additional clauses that can be assumed true
  * for the purpose of generating indexquals, but are not to be searched for
@@ -1247,68 +1425,99 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	foreach(lc, clauses)
 	{
 		RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
-		List	   *pathlist;
+		List	   *pathlist = NIL;
 		Path	   *bitmapqual;
 		ListCell   *j;
 
-		/* Ignore RestrictInfos that aren't ORs */
-		if (!restriction_is_or_clause(rinfo))
+		if (restriction_is_saop_clause(rinfo))
+		{
+			pathlist = generate_saop_pathlist(root, rel, rinfo,
+											  all_clauses);
+		}
+		else if (!restriction_is_or_clause(rinfo))
+			/* Ignore RestrictInfos that aren't ORs */
 			continue;
-
-		/*
-		 * We must be able to match at least one index to each of the arms of
-		 * the OR, else we can't use it.
-		 */
-		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		else
 		{
-			Node	   *orarg = (Node *) lfirst(j);
-			List	   *indlist;
-
-			/* OR arguments should be ANDs or sub-RestrictInfos */
-			if (is_andclause(orarg))
+			/*
+			 * We must be able to match at least one index to each of the arms of
+			 * the OR, else we can't use it.
+			 */
+			foreach(j, ((BoolExpr *) rinfo->orclause)->args)
 			{
-				List	   *andargs = ((BoolExpr *) orarg)->args;
+				Node	   *orarg = (Node *) lfirst(j);
+				List	   *indlist;
 
-				indlist = build_paths_for_OR(root, rel,
-											 andargs,
-											 all_clauses);
+				/* OR arguments should be ANDs or sub-RestrictInfos */
+				if (is_andclause(orarg))
+				{
+					List	   *andargs = ((BoolExpr *) orarg)->args;
 
-				/* Recurse in case there are sub-ORs */
-				indlist = list_concat(indlist,
-									  generate_bitmap_or_paths(root, rel,
-															   andargs,
-															   all_clauses));
-			}
-			else
-			{
-				RestrictInfo *ri = castNode(RestrictInfo, orarg);
-				List	   *orargs;
+					indlist = build_paths_for_OR(root, rel,
+												 andargs,
+												 all_clauses);
 
-				Assert(!restriction_is_or_clause(ri));
-				orargs = list_make1(ri);
+					/* Recurse in case there are sub-ORs */
+					indlist = list_concat(indlist,
+										  generate_bitmap_or_paths(root, rel,
+																   andargs,
+																   all_clauses));
+				}
+				else
+				{
+					RestrictInfo *ri = castNode(RestrictInfo, orarg);
+					List	   *orargs;
 
-				indlist = build_paths_for_OR(root, rel,
-											 orargs,
-											 all_clauses);
-			}
+					Assert(!restriction_is_or_clause(ri));
 
-			/*
-			 * If nothing matched this arm, we can't do anything with this OR
-			 * clause.
-			 */
-			if (indlist == NIL)
-			{
-				pathlist = NIL;
-				break;
-			}
+					orargs = list_make1(ri);
 
-			/*
-			 * OK, pick the most promising AND combination, and add it to
-			 * pathlist.
-			 */
-			bitmapqual = choose_bitmap_and(root, rel, indlist);
-			pathlist = lappend(pathlist, bitmapqual);
+					if (restriction_is_saop_clause(ri))
+					{
+						List *paths;
+
+						paths = generate_saop_pathlist(root, rel, ri,
+														 all_clauses);
+
+						if (paths != NIL)
+						{
+							/*
+							 * Add paths to pathlist and immediately jump to the
+							 * next element of the OR clause.
+							 */
+							pathlist = list_concat(pathlist, paths);
+							continue;
+						}
+
+						/*
+						 * Pass down out of this if construction:
+						 * If saop isn't covered by partial indexes, try to
+						 * build scan path for the saop as a whole.
+						 */
+					}
+
+					indlist = build_paths_for_OR(root, rel,
+												 orargs,
+												 all_clauses);
+				}
+
+				/*
+				 * If nothing matched this arm, we can't do anything with this OR
+				 * clause.
+				 */
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+
+				/*
+				 * OK, pick the most promising AND combination, and add it to
+				 * pathlist.
+				 */
+				bitmapqual = choose_bitmap_and(root, rel, indlist);
+				pathlist = lappend(pathlist, bitmapqual);
+			}
 		}
 
 		/*
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index b76896dfbf5..a3a6d0024bd 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -103,6 +103,52 @@ static Oid	get_btree_test_op(Oid pred_op, Oid clause_op, bool refute_it);
 static void InvalidateOprProofCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
 
 
+/*
+ * Could this ANY () expression can be split into a set of ANYs over partial
+ * indexes? If yes, return these saops in the PredicatesData structure.
+ */
+bool
+saop_covered_by_predicates(ScalarArrayOpExpr *saop, List *predicate_lists)
+{
+	ListCell		   *lc;
+	PredIterInfoData	clause_info;
+	bool				result = false;
+
+	if (predicate_classify((Node *) saop, &clause_info) != CLASS_OR)
+		return false;
+
+	iterate_begin(pitem, (Node *) saop, clause_info)
+	{
+		result = false;
+
+		foreach(lc, predicate_lists)
+		{
+			PredicatesData *pd = (PredicatesData *) lfirst(lc);
+
+			if (!predicate_implied_by_recurse(pitem, pd->predicate, false))
+				continue;
+
+			/* Predicate is found. Add the elem to the saop clause */
+			Assert(IsA(pitem, OpExpr));
+
+			/* Extract constant from the expression */
+			pd->elems = lappend(pd->elems,
+					copyObject(lsecond_node(Const, ((OpExpr *) pitem)->args)));
+			result = true;
+			break;
+		}
+
+		if (!result)
+			/*
+			 * The element doesn't fit any index. Interrupt the process immediately
+			 */
+			break;
+	}
+	iterate_end(clause_info);
+
+	return result;
+}
+
 /*
  * predicate_implied_by
  *	  Recursively checks whether the clauses in clause_list imply that the
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e93342..1dad1dc6541 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -421,6 +421,19 @@ restriction_is_or_clause(RestrictInfo *restrictinfo)
 		return false;
 }
 
+bool
+restriction_is_saop_clause(RestrictInfo *restrictinfo)
+{
+	if (restrictinfo->clause && IsA(restrictinfo->clause, ScalarArrayOpExpr))
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) restrictinfo->clause;
+
+		if (saop->useOr)
+			return true;
+	}
+	return false;
+}
+
 /*
  * restriction_is_securely_promotable
  *
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 0ee7154e084..4029cf07bec 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -160,6 +160,20 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+/*
+ * Contains information needed to extract from saop a set of elements which can
+ * be covered by the partial index:
+ * id - caller's identification of the index.
+ * predicate - predicate expression of the index
+ * elems - returning list of array elements which corresponds to this predicate
+ */
+typedef struct PredicatesData
+{
+	int		id;
+	Node   *predicate;
+	List   *elems;
+} PredicatesData;
+
 /*
  * Proof attempts involving large arrays in ScalarArrayOpExpr nodes are
  * likely to require O(N^2) time, and more often than not fail anyway.
@@ -169,6 +183,8 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
  */
 #define MAX_SAOP_ARRAY_SIZE		100
 
+extern bool saop_covered_by_predicates(ScalarArrayOpExpr *saop,
+									  List *predicate_lists);
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c59..2cd5fbf9434 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -34,6 +34,7 @@ extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Relids outer_relids);
 extern RestrictInfo *commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op);
 extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
+extern bool restriction_is_saop_clause(RestrictInfo *restrictinfo);
 extern bool restriction_is_securely_promotable(RestrictInfo *restrictinfo,
 											   RelOptInfo *rel);
 extern List *get_actual_clauses(List *restrictinfo_list);
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e3..0ebaf002e83 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -907,6 +907,288 @@ select unique1, unique2 from onek2
        0 |     998
 (2 rows)
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: ((stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Without the transformation only seqscan possible here
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                         QUERY PLAN                                          
+---------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])) AND (stringu1 < 'Z'::name))
+(2 rows)
+
+-- Use partial indexes
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+                 QUERY PLAN                 
+--------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = 1) OR (unique2 = 3))
+(2 rows)
+
+RESET enable_or_transformation;
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+-- Don't scan partial indexes because of extra value.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+                      QUERY PLAN                      
+------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on onek2
+         Filter: (stringu1 = ANY ('{A,J,C}'::name[]))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+                                      QUERY PLAN                                       
+---------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (stringu1 < 'B'::name)
+   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = ANY ('{A,A}'::name[])))
+   ->  Bitmap Index Scan on onek2_u2_prtl
+(4 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                                          QUERY PLAN                                                           
+-------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name)) OR ((unique2 < 1) AND (stringu1 < 'B'::name)))
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: ((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 < 1)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 = 1) OR (unique1 = 3))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 1)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 3)
+(7 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+                                                             QUERY PLAN                                                             
+------------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = ((random() * '2'::double precision))::integer) OR (unique1 = ((random() * '3'::double precision))::integer))
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+                                                           QUERY PLAN                                                            
+---------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: (unique1 = ANY (ARRAY[((random() * '2'::double precision))::integer, ((random() * '3'::double precision))::integer]))
+(2 rows)
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+                                                                                          QUERY PLAN                                                                                          
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[]))) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 = ANY ('{1,2,21}'::integer[])) AND ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 = ANY ('{3,4}'::integer[])) OR (stringu1 = 'J'::name)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[])))
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(11 rows)
+
+-- Check recursive combination of OR and SAOP expressions
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+(9 rows)
+
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+RESET enable_indexscan;
+RESET enable_seqscan;
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql
index 019f1e76739..223f55af4e4 100644
--- a/src/test/regress/sql/select.sql
+++ b/src/test/regress/sql/select.sql
@@ -234,6 +234,88 @@ select unique1, unique2 from onek2
 select unique1, unique2 from onek2
   where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+-- Without the transformation only seqscan possible here
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+-- Use partial indexes
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+RESET enable_or_transformation;
+
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+
+-- Don't scan partial indexes because of extra value.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+EXPLAIN (COSTS OFF)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+
+-- Check recursive combination of OR and SAOP expressions
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+
+RESET enable_indexscan;
+RESET enable_seqscan;
+
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index f4b6fee8933..7930a17e815 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2141,6 +2141,7 @@ PredIterInfoData
 PredXactList
 PredicateLockData
 PredicateLockTargetType
+PredicatesData
 PrefetchBufferResult
 PrepParallelRestorePtrType
 PrepareStmt
-- 
2.39.3 (Apple Git-145)

v20-0001-Transform-OR-clauses-to-ANY-expression.patchapplication/octet-stream; name=v20-0001-Transform-OR-clauses-to-ANY-expression.patchDownload
From 6b734fe22508291b85e7f0226eedde11bf43751d Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Fri, 2 Feb 2024 22:01:09 +0300
Subject: [PATCH v20 1/2] Transform OR clauses to ANY expression.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...]) on the
preliminary stage of optimization when we are still working with the
expression tree.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
---
 .../postgres_fdw/expected/postgres_fdw.out    |   8 +-
 doc/src/sgml/config.sgml                      |  17 +
 src/backend/nodes/queryjumblefuncs.c          |  27 ++
 src/backend/optimizer/util/predtest.c         |   9 -
 src/backend/parser/parse_expr.c               | 357 ++++++++++++++++++
 src/backend/utils/misc/guc_tables.c           |  11 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/bin/pg_dump/t/002_pg_dump.pl              |   6 +-
 src/include/nodes/queryjumble.h               |   1 +
 src/include/optimizer/optimizer.h             |  10 +
 src/test/regress/expected/create_index.out    | 156 +++++++-
 src/test/regress/expected/join.out            |  62 ++-
 src/test/regress/expected/partition_prune.out | 215 ++++++++++-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  35 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 21 files changed, 924 insertions(+), 69 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index c355e8f3f7d..48685bf6ffe 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8797,18 +8797,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index b38cbd714aa..1fdfffd79b0 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5433,6 +5433,23 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-enable-or-transformation" xreflabel="enable_or_transformation">
+      <term><varname>enable_or_transformation</varname> (<type>boolean</type>)
+       <indexterm>
+        <primary><varname>enable_or_transformation</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      <listitem>
+       <para>
+        Enables or disables the query planner's ability to lookup and group multiple
+        similar OR expressions to ANY (<xref linkend="functions-comparisons-any-some"/>) expressions.
+        The grouping technique of this transformation is based on the equivalence of variable sides.
+        One side of such an expression must be a constant clause, and the other must contain a variable clause.
+        The default is <literal>on</literal>.
+        </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-enable-parallel-append" xreflabel="enable_parallel_append">
       <term><varname>enable_parallel_append</varname> (<type>boolean</type>)
       <indexterm>
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 426112fa37b..c4c4cab8ed5 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -141,6 +141,33 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index c37b416e24e..b76896dfbf5 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -30,15 +30,6 @@
 #include "utils/syscache.h"
 
 
-/*
- * Proof attempts involving large arrays in ScalarArrayOpExpr nodes are
- * likely to require O(N^2) time, and more often than not fail anyway.
- * So we set an arbitrary limit on the number of array elements that
- * we will allow to be treated as an AND or OR clause.
- * XXX is it worth exposing this as a GUC knob?
- */
-#define MAX_SAOP_ARRAY_SIZE		100
-
 /*
  * To avoid redundant coding in predicate_implied_by_recurse and
  * predicate_refuted_by_recurse, we need to abstract out the notion of
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 9300c7b9abc..baeb83e58bf 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,15 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
+#include "common/hashfn.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -38,11 +41,13 @@
 #include "utils/date.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +104,353 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	NodeTag	type;
+
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+
+	List		   *consts;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function to find candidate clauses.
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				exprHash;
+
+	Assert(keysize == sizeof(OrClauseGroupKey));
+	Assert(IsA(data, Invalid));
+
+	(void) JumbleExpr(key->expr, &exprHash);
+
+	return hash_combine((uint32) exprHash,
+						hash_combine((uint32) key->opno,
+									 (uint32) key->exprtype));
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(src, Invalid));
+
+	dst_key->type = T_Invalid;
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in or_group_htab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(key1, Invalid));
+	Assert(IsA(key2, Invalid));
+
+	if (key1->opno == key2->opno &&
+		key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+/*
+ * TransformOrExprToANY -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to an ANY operation.
+ *	  Transformation must be already done on input args list before the call.
+ *	  Transformation groups two-sided equality operations. One side of such an
+ *	  operation must be plain constant or constant expression. The other side of
+ *	  the clause must be a variable expression without volatile functions.
+ *	  The grouping technique is based on an equivalence of variable sides of the
+ *	  expression: using queryId and equal() routine, it groups constant sides of
+ *	  similar clauses into an array. After the grouping procedure, each couple
+ *	  ('variable expression' and 'constant array') form a new SAOP operation,
+ *	  which is added to the args list of the returning expression.
+ *
+ *	  NOTE: function returns OR BoolExpr if more than one clause are detected in
+ *	  the final args list, or ScalarArrayOpExpr if all args were grouped into
+ *	  the single SAOP expression.
+ */
+static Node *
+TransformOrExprToANY(ParseState *pstate, List *args, int location)
+{
+	List				   *or_list = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(args);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	Assert(enable_or_transformation && len_ors > 1);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, args)
+	{
+		Node				   *orqual = lfirst(lc);
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Oid						exprtype;
+		Node				   *leftop, *rightop;
+
+		if (!IsA(orqual, OpExpr))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				entries = lappend(entries, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		 * Transformation only works with both side type is not
+		 * { array | composite | domain | record }.
+		 * Also, forbid it for volatile expressions.
+		 */
+		exprtype = exprType(nconst_expr);
+		if (type_is_rowtype(exprType(const_expr)) ||
+			type_is_rowtype(exprtype) ||
+			contain_volatile_functions((Node *) nconst_expr))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.type = T_Invalid;
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.exprtype = exprtype;
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		if (!IsA(lfirst(lc), Invalid))
+		{
+			or_list = lappend(or_list, lfirst(lc));
+			continue;
+		}
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1 ||
+			list_length(entry->consts) > MAX_SAOP_ARRAY_SIZE)
+		{
+			/*
+			 * Only one element or more than MAX_SAOP_ARRAY_SIZE elements in
+			 * the class Return origin expression into.
+			 * the BoolExpr args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.exprtype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+											   InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+			ListCell		   *lc1;
+
+			foreach(lc1, entry->consts)
+			{
+				Node   *rexpr = (Node *) lfirst(lc1);
+
+				rexpr = coerce_to_common_type(pstate, rexpr,
+											  scalar_type,
+											  "IN");
+				aexprs = lappend(aexprs, rexpr);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 (Node *) entry->key.expr,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -1386,6 +1738,11 @@ transformBoolExpr(ParseState *pstate, BoolExpr *a)
 		args = lappend(args, arg);
 	}
 
+	/* Make an attempt to group similar OR clauses into ANY operation */
+	if (enable_or_transformation && a->boolop == OR_EXPR &&
+		list_length(args) > 1)
+		return TransformOrExprToANY(pstate, args, a->location);
+
 	return (Node *) makeBoolExpr(a->boolop, args, a->location);
 }
 
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 45013582a74..c0ea53495b3 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1026,6 +1026,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an array expression."),
+			gettext_noop("The planner will replace expression like 'x=c1 OR x=c2 ..'"
+						 "to the expression 'x = ANY(ARRAY[c1,c2,..])'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index edcc0282b2d..d30dc6d51c9 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -389,6 +389,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 00b5092713d..d28bf617dbe 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -2095,9 +2095,9 @@ my %tests = (
 		regexp => qr/^
 			\QCREATE DOMAIN dump_test.us_postal_code AS text COLLATE pg_catalog."C" DEFAULT '10014'::text\E\n\s+
 			\QCONSTRAINT us_postal_code_check CHECK \E
-			\Q(((VALUE ~ '^\d{5}\E
-			\$\Q'::text) OR (VALUE ~ '^\d{5}-\d{4}\E\$
-			\Q'::text)));\E(.|\n)*
+			\Q((VALUE ~ ANY (ARRAY['^\d{5}\E
+			\$\Q'::text, '^\d{5}-\d{4}\E\$
+			\Q'::text])));\E(.|\n)*
 			\QCOMMENT ON CONSTRAINT us_postal_code_check ON DOMAIN dump_test.us_postal_code IS 'check it';\E
 			/xm,
 		like =>
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067f..a9ae048af52 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 7b63c5cf718..0ee7154e084 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -50,6 +50,7 @@ struct PlannedStmt;
 struct ParamListInfoData;
 struct HeapTupleData;
 
+extern PGDLLIMPORT bool enable_or_transformation;
 
 /* in path/clausesel.c: */
 
@@ -159,6 +160,15 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+/*
+ * Proof attempts involving large arrays in ScalarArrayOpExpr nodes are
+ * likely to require O(N^2) time, and more often than not fail anyway.
+ * So we set an arbitrary limit on the number of array elements that
+ * we will allow to be treated as an AND or OR clause.
+ * XXX is it worth exposing this as a GUC knob?
+ */
+#define MAX_SAOP_ARRAY_SIZE		100
+
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 79fa117cb54..7b721bac719 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,116 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND ((thousand = ANY ('{42,41}'::integer[])) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 96054000218..d8018bef4f6 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index bf0657b9f2c..1e153c3bb56 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +618,13 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -2072,10 +2251,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 10903bdab09..6f55b9e3ec1 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 9be7aca2b8a..1f9029b5b2a 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -124,6 +124,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -134,7 +135,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(23 rows)
+(24 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..2a079e996b2 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f3007..56fde15bc15 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index c4c6c7b8ba2..16636080436 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index a09b27d820c..9717c8c835c 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..0499bedb9eb 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index cc3611e6068..f4b6fee8933 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1656,6 +1656,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.39.3 (Apple Git-145)

#160Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#159)
3 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 07.03.2024 17:51, Alexander Korotkov wrote:

Hi!

On Tue, Mar 5, 2024 at 9:59 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 5/3/2024 12:30, Andrei Lepikhov wrote:

On 4/3/2024 09:26, jian he wrote:

... and the new version of the patchset is attached.

I made some revisions for the patchset.
1) Use hash_combine() to combine hash values.
2) Upper limit the number of array elements by MAX_SAOP_ARRAY_SIZE.
3) Better save the original order of clauses by putting hash entries
and untransformable clauses to the same list.  A lot of differences in
regression tests output have gone.

Thank you for your changes. I agree with them.

One important issue I found.

# create table t as (select i::int%100 i from generate_series(1,10000) i);
# analyze t;
# explain select * from t where i = 1 or i = 1;
                     QUERY PLAN
-----------------------------------------------------
 Seq Scan on t  (cost=0.00..189.00 rows=200 width=4)
   Filter: (i = ANY ('{1,1}'::integer[]))
(2 rows)

# set enable_or_transformation = false;
SET
# explain select * from t where i = 1 or i = 1;
                     QUERY PLAN
-----------------------------------------------------
 Seq Scan on t  (cost=0.00..189.00 rows=100 width=4)
   Filter: (i = 1)
(2 rows)

We don't make array values unique.  That might make query execution
performance somewhat worse, and also makes selectivity estimation
worse.  I suggest Andrei and/or Alena should implement making array
values unique.

I have corrected this and some spelling mistakes. The
unique_any_elements_change.no-cfbot file contains changes.

While I was correcting the test results caused by such changes, I
noticed that the same behavior was when converting the IN expression,
and this can be seen in the result of the regression test:

 EXPLAIN (COSTS OFF)
 SELECT unique2 FROM onek2
 WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
                                QUERY PLAN
---------------------------------------------------------------------------
  Bitmap Heap Scan on onek2
    Recheck Cond: (stringu1 < 'B'::name)
   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = 'A'::name))
    ->  Bitmap Index Scan on onek2_u2_prtl
 (4 rows)

--
Regards,
Alena Rybakina
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

unique_any_elements_change.no-cfbottext/plain; charset=UTF-8; name=unique_any_elements_change.no-cfbotDownload
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index baeb83e58b..e9813ef6ab 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -312,8 +312,8 @@ TransformOrExprToANY(ParseState *pstate, List *args, int location)
 
 		if (unlikely(found))
 		{
-			entry->consts = lappend(entry->consts, const_expr);
-			entry->exprs = lappend(entry->exprs, orqual);
+			entry->consts = list_append_unique(entry->consts, const_expr);
+			entry->exprs = list_append_unique(entry->exprs, orqual);
 		}
 		else
 		{
@@ -352,7 +352,6 @@ TransformOrExprToANY(ParseState *pstate, List *args, int location)
 		entry = (OrClauseGroupEntry *) lfirst(lc);
 
 		Assert(list_length(entry->consts) > 0);
-		Assert(list_length(entry->exprs) == list_length(entry->consts));
 
 		if (list_length(entry->consts) == 1 ||
 			list_length(entry->consts) > MAX_SAOP_ARRAY_SIZE)
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 7b721bac71..606a4399f9 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1915,16 +1915,16 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
-                                        QUERY PLAN                                        
-------------------------------------------------------------------------------------------
+                                      QUERY PLAN                                       
+---------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43}'::integer[])))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
-                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+                     Index Cond: (thousand < ANY ('{42,99,43}'::integer[]))
 (8 rows)
 
 EXPLAIN (COSTS OFF)
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 0ebaf002e8..f4f5493c43 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -1047,11 +1047,11 @@ SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
 EXPLAIN (COSTS OFF)
 SELECT unique2 FROM onek2
 WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
-                                      QUERY PLAN                                       
----------------------------------------------------------------------------------------
+                                QUERY PLAN                                 
+---------------------------------------------------------------------------
  Bitmap Heap Scan on onek2
    Recheck Cond: (stringu1 < 'B'::name)
-   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = ANY ('{A,A}'::name[])))
+   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = 'A'::name))
    ->  Bitmap Index Scan on onek2_u2_prtl
 (4 rows)
 
@@ -1114,7 +1114,7 @@ WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
    Filter: (unique1 = ANY (ARRAY[((random() * '2'::double precision))::integer, ((random() * '3'::double precision))::integer]))
 (2 rows)
 
--- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- Combine different saops. Some of them doesnt' fit a set of partial indexes,
 -- but other fits.
 -- Unfortunately, we don't combine saop and OR clauses so far.
 EXPLAIN (COSTS OFF)
@@ -1170,7 +1170,7 @@ WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
          ->  Bitmap Index Scan on onek2_u2_prtl
 (9 rows)
 
--- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- Although SAOP doesn't fit partial indexes fully, we can use added OR clause
 -- to scan another couple of partial indexes.
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM onek2
@@ -1188,6 +1188,17 @@ WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
 (8 rows)
 
 RESET enable_indexscan;
+--Check the case when we construct ANY list with unique elements
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE unique1 = 1 OR unique1 = 1;
+                     QUERY PLAN                     
+----------------------------------------------------
+ Aggregate
+   ->  Index Only Scan using onek2_u1_prtl on onek2
+         Index Cond: (unique1 = 1)
+(3 rows)
+
 RESET enable_seqscan;
 --
 -- Test some corner cases that have been known to confuse the planner
diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql
index 223f55af4e..b8cee41658 100644
--- a/src/test/regress/sql/select.sql
+++ b/src/test/regress/sql/select.sql
@@ -291,7 +291,7 @@ EXPLAIN (COSTS OFF)
 SELECT unique2,stringu1 FROM onek2
 WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
 
--- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- Combine different saops. Some of them doesnt' fit a set of partial indexes,
 -- but other fits.
 -- Unfortunately, we don't combine saop and OR clauses so far.
 EXPLAIN (COSTS OFF)
@@ -307,13 +307,18 @@ WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
 EXPLAIN (COSTS OFF)
 SELECT unique2, stringu1 FROM onek2
 WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
--- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- Although SAOP doesn't fit partial indexes fully, we can use added OR clause
 -- to scan another couple of partial indexes.
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM onek2
 WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
 
 RESET enable_indexscan;
+--Check the case when we construct ANY list with unique elements
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE unique1 = 1 OR unique1 = 1;
+
 RESET enable_seqscan;
 
 --
v21-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchtext/x-patch; charset=UTF-8; name=v21-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchDownload
From 9721f3e8ecda972241d9bedbfb915fd1514cb9d7 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Tue, 5 Mar 2024 13:29:46 +0700
Subject: [PATCH 2/2] Teach generate_bitmap_or_paths to build BitmapOr paths
 over SAOP clauses.

Likewise OR clauses, discover SAOP array and try to split its elements
between smaller sized arrays to fit a set of partial indexes.
---
 doc/src/sgml/config.sgml                  |   3 +
 src/backend/optimizer/path/indxpath.c     | 315 ++++++++++++++++++----
 src/backend/optimizer/util/predtest.c     |  46 ++++
 src/backend/optimizer/util/restrictinfo.c |  13 +
 src/include/optimizer/optimizer.h         |  16 ++
 src/include/optimizer/restrictinfo.h      |   1 +
 src/test/regress/expected/select.out      | 293 ++++++++++++++++++++
 src/test/regress/sql/select.sql           |  87 ++++++
 src/tools/pgindent/typedefs.list          |   1 +
 9 files changed, 722 insertions(+), 53 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 1fdfffd79b..8008b05327 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5446,6 +5446,9 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
         The grouping technique of this transformation is based on the equivalence of variable sides.
         One side of such an expression must be a constant clause, and the other must contain a variable clause.
         The default is <literal>on</literal>.
+        Also, during BitmapScan paths generation it enables analysis of elements
+        of IN or ANY constant arrays to cover such clause with BitmapOr set of
+        partial index scans.
         </para>
       </listitem>
      </varlistentry>
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 32c6a8bbdc..f92a47c3d5 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,6 +32,7 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
 
@@ -1220,11 +1221,188 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Building index paths over SAOP clause differs from the logic of OR clauses.
+ * Here we iterate across all the array elements and split them to SAOPs,
+ * corresponding to different indexes. We must match each element to an index.
+ */
+static List *
+build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
+					 List *other_clauses)
+{
+	List			   *result = NIL;
+	List			   *predicate_lists = NIL;
+	ListCell		   *lc;
+	PredicatesData	   *pd;
+	ScalarArrayOpExpr  *saop = (ScalarArrayOpExpr *) rinfo->clause;
+
+	Assert(IsA(saop, ScalarArrayOpExpr) && saop->useOr);
+
+	if (!IsA(lsecond(saop->args), Const))
+		/*
+		 * Has it practical outcome to merge arrays which couldn't constantified
+		 * before that step?
+		 */
+		return NIL;
+
+	/* Collect predicates */
+	foreach(lc, rel->indexlist)
+	{
+		IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
+
+		/* Take into consideration partial indexes supporting bitmap scans */
+		if (!index->amhasgetbitmap || index->indpred == NIL || index->predOK)
+			continue;
+
+		pd = palloc0(sizeof(PredicatesData));
+		pd->id = foreach_current_index(lc);
+		/* The trick with reducing recursion is stolen from predicate_implied_by */
+		pd->predicate = list_length(index->indpred) == 1 ?
+										(Node *) linitial(index->indpred) :
+										(Node *) index->indpred;
+		predicate_lists = lappend(predicate_lists, (void *) pd);
+	}
+
+	/* Split the array data according to index predicates. */
+	if (predicate_lists == NIL ||
+		!saop_covered_by_predicates(saop, predicate_lists))
+		return NIL;
+
+	other_clauses = list_delete_ptr(other_clauses, rinfo);
+
+	/*
+	 * Having incoming SAOP split to set of smaller SAOPs which can be applied
+	 * to partial indexes, generate paths for each one.
+	 */
+	foreach(lc, predicate_lists)
+	{
+		IndexOptInfo	   *index;
+		IndexClauseSet		clauseset;
+		List			   *indexpaths;
+		RestrictInfo	   *rinfo1 = NULL;
+		Expr			   *clause;
+		ArrayType		   *arrayval = NULL;
+		ArrayExpr		   *arr = NULL;
+		Const			   *arrayconst;
+		ScalarArrayOpExpr  *dest;
+
+		pd = (PredicatesData *) lfirst(lc);
+		if (pd->elems == NIL)
+			/* The index doesn't participate in this operation */
+			continue;
+
+		/* Make up new array */
+		arrayconst = lsecond_node(Const, saop->args);
+		arrayval = DatumGetArrayTypeP(arrayconst->constvalue);
+		arr = makeNode(ArrayExpr);
+		arr->array_collid = arrayconst->constcollid;
+		arr->array_typeid = arrayconst->consttype;
+		arr->element_typeid = arrayval->elemtype;
+		arr->elements = pd->elems;
+		arr->location = -1;
+		arr->multidims = false;
+
+		/* Compose new SAOP, partially covering the source one */
+		dest = makeNode(ScalarArrayOpExpr);
+		memcpy(dest, saop, sizeof(ScalarArrayOpExpr));
+		dest->args = list_make2(linitial(saop->args), arr);
+		clause = (Expr *) estimate_expression_value(root, (Node *) dest);
+
+		/*
+		 * Create new RestrictInfo. It maybe more heavy than just copy node,
+		 * but remember some internals: the serial number, selectivity
+		 * cache etc.
+		 */
+		rinfo1 = make_restrictinfo(root, clause,
+								   rinfo->is_pushed_down,
+								   rinfo->has_clone,
+								   rinfo->is_clone,
+								   rinfo->pseudoconstant,
+								   rinfo->security_level,
+								   rinfo->required_relids,
+								   rinfo->incompatible_relids,
+								   rinfo->outer_relids);
+
+		index = list_nth(rel->indexlist, pd->id);
+		Assert(predicate_implied_by(index->indpred, list_make1(rinfo1), true));
+
+		/* Excluding partial indexes with predOK we make this statement false */
+		Assert(!predicate_implied_by(index->indpred, other_clauses, false));
+
+		/* Time to generate index paths */
+
+		MemSet(&clauseset, 0, sizeof(clauseset));
+		match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);
+		match_clauses_to_index(root, other_clauses, index, &clauseset);
+
+		/* Predicate has found already. So, it is ok for the empty match */
+
+		indexpaths = build_index_paths(root, rel,
+									   index, &clauseset,
+									   true,
+									   ST_BITMAPSCAN,
+									   NULL,
+									   NULL);
+		Assert(indexpaths != NIL);
+		result = lappend(result, indexpaths);
+	}
+	return result;
+}
+
+/*
+ * Analyse incoming SAOP node to cover it by partial indexes.
+ *
+ * The returning pathlist must be ANDed to the final BitmapScan path.
+ * The function returns NULL when an array element cannot be fitted with some
+ * partial index. The Rationale for such an operation is that when schema
+ * contains many partial indexes, the SAOP clause may be effectively fulfilled
+ * by appending results of scanning some minimal set of tiny partial indexes.
+ *
+ * Working jointly with the TransformOrExprToANY routine, it provides a user
+ * with some sort of independence of the query plan from the approach to writing
+ * alternatives for the same entity in the WHERE section.
+ */
+static List *
+generate_saop_pathlist(PlannerInfo *root, RelOptInfo *rel,
+					   RestrictInfo *rinfo, List *all_clauses)
+{
+	List	   *pathlist = NIL;
+	Path	   *bitmapqual;
+	List	   *indlist;
+	ListCell   *lc;
+
+	if (!enable_or_transformation)
+		return NIL;
+
+	/*
+	 * We must be able to match at least one index to each element of
+	 * the array, else we can't use it.
+	 */
+	indlist = build_paths_for_SAOP(root, rel, rinfo, all_clauses);
+	if (indlist == NIL)
+		return NIL;
+
+	/*
+	 * OK, pick the most promising AND combination, and add it to
+	 * pathlist.
+	 */
+	foreach (lc, indlist)
+	{
+		List *plist = lfirst_node(List, lc);
+
+		bitmapqual = choose_bitmap_and(root, rel, plist);
+		pathlist = lappend(pathlist, bitmapqual);
+	}
+
+	return pathlist;
+}
+
 /*
  * generate_bitmap_or_paths
- *		Look through the list of clauses to find OR clauses, and generate
- *		a BitmapOrPath for each one we can handle that way.  Return a list
- *		of the generated BitmapOrPaths.
+ *		Look through the list of clauses to find OR and SAOP clauses, and
+ *		Each saop clause are splitted to be covered by partial indexes.
+ *		generate a BitmapOrPath for each one we can handle that way.
+ *		Return a list of the generated BitmapOrPaths.
  *
  * other_clauses is a list of additional clauses that can be assumed true
  * for the purpose of generating indexquals, but are not to be searched for
@@ -1247,68 +1425,99 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	foreach(lc, clauses)
 	{
 		RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
-		List	   *pathlist;
+		List	   *pathlist = NIL;
 		Path	   *bitmapqual;
 		ListCell   *j;
 
-		/* Ignore RestrictInfos that aren't ORs */
-		if (!restriction_is_or_clause(rinfo))
+		if (restriction_is_saop_clause(rinfo))
+		{
+			pathlist = generate_saop_pathlist(root, rel, rinfo,
+											  all_clauses);
+		}
+		else if (!restriction_is_or_clause(rinfo))
+			/* Ignore RestrictInfos that aren't ORs */
 			continue;
-
-		/*
-		 * We must be able to match at least one index to each of the arms of
-		 * the OR, else we can't use it.
-		 */
-		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		else
 		{
-			Node	   *orarg = (Node *) lfirst(j);
-			List	   *indlist;
-
-			/* OR arguments should be ANDs or sub-RestrictInfos */
-			if (is_andclause(orarg))
+			/*
+			 * We must be able to match at least one index to each of the arms of
+			 * the OR, else we can't use it.
+			 */
+			foreach(j, ((BoolExpr *) rinfo->orclause)->args)
 			{
-				List	   *andargs = ((BoolExpr *) orarg)->args;
+				Node	   *orarg = (Node *) lfirst(j);
+				List	   *indlist;
 
-				indlist = build_paths_for_OR(root, rel,
-											 andargs,
-											 all_clauses);
+				/* OR arguments should be ANDs or sub-RestrictInfos */
+				if (is_andclause(orarg))
+				{
+					List	   *andargs = ((BoolExpr *) orarg)->args;
 
-				/* Recurse in case there are sub-ORs */
-				indlist = list_concat(indlist,
-									  generate_bitmap_or_paths(root, rel,
-															   andargs,
-															   all_clauses));
-			}
-			else
-			{
-				RestrictInfo *ri = castNode(RestrictInfo, orarg);
-				List	   *orargs;
+					indlist = build_paths_for_OR(root, rel,
+												 andargs,
+												 all_clauses);
 
-				Assert(!restriction_is_or_clause(ri));
-				orargs = list_make1(ri);
+					/* Recurse in case there are sub-ORs */
+					indlist = list_concat(indlist,
+										  generate_bitmap_or_paths(root, rel,
+																   andargs,
+																   all_clauses));
+				}
+				else
+				{
+					RestrictInfo *ri = castNode(RestrictInfo, orarg);
+					List	   *orargs;
 
-				indlist = build_paths_for_OR(root, rel,
-											 orargs,
-											 all_clauses);
-			}
+					Assert(!restriction_is_or_clause(ri));
 
-			/*
-			 * If nothing matched this arm, we can't do anything with this OR
-			 * clause.
-			 */
-			if (indlist == NIL)
-			{
-				pathlist = NIL;
-				break;
-			}
+					orargs = list_make1(ri);
 
-			/*
-			 * OK, pick the most promising AND combination, and add it to
-			 * pathlist.
-			 */
-			bitmapqual = choose_bitmap_and(root, rel, indlist);
-			pathlist = lappend(pathlist, bitmapqual);
+					if (restriction_is_saop_clause(ri))
+					{
+						List *paths;
+
+						paths = generate_saop_pathlist(root, rel, ri,
+														 all_clauses);
+
+						if (paths != NIL)
+						{
+							/*
+							 * Add paths to pathlist and immediately jump to the
+							 * next element of the OR clause.
+							 */
+							pathlist = list_concat(pathlist, paths);
+							continue;
+						}
+
+						/*
+						 * Pass down out of this if construction:
+						 * If saop isn't covered by partial indexes, try to
+						 * build scan path for the saop as a whole.
+						 */
+					}
+
+					indlist = build_paths_for_OR(root, rel,
+												 orargs,
+												 all_clauses);
+				}
+
+				/*
+				 * If nothing matched this arm, we can't do anything with this OR
+				 * clause.
+				 */
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+
+				/*
+				 * OK, pick the most promising AND combination, and add it to
+				 * pathlist.
+				 */
+				bitmapqual = choose_bitmap_and(root, rel, indlist);
+				pathlist = lappend(pathlist, bitmapqual);
+			}
 		}
 
 		/*
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index b76896dfbf..a3a6d0024b 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -103,6 +103,52 @@ static Oid	get_btree_test_op(Oid pred_op, Oid clause_op, bool refute_it);
 static void InvalidateOprProofCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
 
 
+/*
+ * Could this ANY () expression can be split into a set of ANYs over partial
+ * indexes? If yes, return these saops in the PredicatesData structure.
+ */
+bool
+saop_covered_by_predicates(ScalarArrayOpExpr *saop, List *predicate_lists)
+{
+	ListCell		   *lc;
+	PredIterInfoData	clause_info;
+	bool				result = false;
+
+	if (predicate_classify((Node *) saop, &clause_info) != CLASS_OR)
+		return false;
+
+	iterate_begin(pitem, (Node *) saop, clause_info)
+	{
+		result = false;
+
+		foreach(lc, predicate_lists)
+		{
+			PredicatesData *pd = (PredicatesData *) lfirst(lc);
+
+			if (!predicate_implied_by_recurse(pitem, pd->predicate, false))
+				continue;
+
+			/* Predicate is found. Add the elem to the saop clause */
+			Assert(IsA(pitem, OpExpr));
+
+			/* Extract constant from the expression */
+			pd->elems = lappend(pd->elems,
+					copyObject(lsecond_node(Const, ((OpExpr *) pitem)->args)));
+			result = true;
+			break;
+		}
+
+		if (!result)
+			/*
+			 * The element doesn't fit any index. Interrupt the process immediately
+			 */
+			break;
+	}
+	iterate_end(clause_info);
+
+	return result;
+}
+
 /*
  * predicate_implied_by
  *	  Recursively checks whether the clauses in clause_list imply that the
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e9334..1dad1dc654 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -421,6 +421,19 @@ restriction_is_or_clause(RestrictInfo *restrictinfo)
 		return false;
 }
 
+bool
+restriction_is_saop_clause(RestrictInfo *restrictinfo)
+{
+	if (restrictinfo->clause && IsA(restrictinfo->clause, ScalarArrayOpExpr))
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) restrictinfo->clause;
+
+		if (saop->useOr)
+			return true;
+	}
+	return false;
+}
+
 /*
  * restriction_is_securely_promotable
  *
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 0ee7154e08..4029cf07be 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -160,6 +160,20 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+/*
+ * Contains information needed to extract from saop a set of elements which can
+ * be covered by the partial index:
+ * id - caller's identification of the index.
+ * predicate - predicate expression of the index
+ * elems - returning list of array elements which corresponds to this predicate
+ */
+typedef struct PredicatesData
+{
+	int		id;
+	Node   *predicate;
+	List   *elems;
+} PredicatesData;
+
 /*
  * Proof attempts involving large arrays in ScalarArrayOpExpr nodes are
  * likely to require O(N^2) time, and more often than not fail anyway.
@@ -169,6 +183,8 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
  */
 #define MAX_SAOP_ARRAY_SIZE		100
 
+extern bool saop_covered_by_predicates(ScalarArrayOpExpr *saop,
+									  List *predicate_lists);
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c5..2cd5fbf943 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -34,6 +34,7 @@ extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Relids outer_relids);
 extern RestrictInfo *commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op);
 extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
+extern bool restriction_is_saop_clause(RestrictInfo *restrictinfo);
 extern bool restriction_is_securely_promotable(RestrictInfo *restrictinfo,
 											   RelOptInfo *rel);
 extern List *get_actual_clauses(List *restrictinfo_list);
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e..f4f5493c43 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -907,6 +907,299 @@ select unique1, unique2 from onek2
        0 |     998
 (2 rows)
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: ((stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Without the transformation only seqscan possible here
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                         QUERY PLAN                                          
+---------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])) AND (stringu1 < 'Z'::name))
+(2 rows)
+
+-- Use partial indexes
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+                 QUERY PLAN                 
+--------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = 1) OR (unique2 = 3))
+(2 rows)
+
+RESET enable_or_transformation;
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+-- Don't scan partial indexes because of extra value.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+                      QUERY PLAN                      
+------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on onek2
+         Filter: (stringu1 = ANY ('{A,J,C}'::name[]))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+                                QUERY PLAN                                 
+---------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (stringu1 < 'B'::name)
+   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = 'A'::name))
+   ->  Bitmap Index Scan on onek2_u2_prtl
+(4 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                                          QUERY PLAN                                                           
+-------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name)) OR ((unique2 < 1) AND (stringu1 < 'B'::name)))
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: ((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 < 1)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 = 1) OR (unique1 = 3))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 1)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 3)
+(7 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+                                                             QUERY PLAN                                                             
+------------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = ((random() * '2'::double precision))::integer) OR (unique1 = ((random() * '3'::double precision))::integer))
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+                                                           QUERY PLAN                                                            
+---------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: (unique1 = ANY (ARRAY[((random() * '2'::double precision))::integer, ((random() * '3'::double precision))::integer]))
+(2 rows)
+
+-- Combine different saops. Some of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+                                                                                          QUERY PLAN                                                                                          
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[]))) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 = ANY ('{1,2,21}'::integer[])) AND ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 = ANY ('{3,4}'::integer[])) OR (stringu1 = 'J'::name)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[])))
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(11 rows)
+
+-- Check recursive combination of OR and SAOP expressions
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+(9 rows)
+
+-- Although SAOP doesn't fit partial indexes fully, we can use added OR clause
+-- to scan another couple of partial indexes.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+RESET enable_indexscan;
+--Check the case when we construct ANY list with unique elements
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE unique1 = 1 OR unique1 = 1;
+                     QUERY PLAN                     
+----------------------------------------------------
+ Aggregate
+   ->  Index Only Scan using onek2_u1_prtl on onek2
+         Index Cond: (unique1 = 1)
+(3 rows)
+
+RESET enable_seqscan;
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql
index 019f1e7673..b8cee41658 100644
--- a/src/test/regress/sql/select.sql
+++ b/src/test/regress/sql/select.sql
@@ -234,6 +234,93 @@ select unique1, unique2 from onek2
 select unique1, unique2 from onek2
   where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+-- Without the transformation only seqscan possible here
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+-- Use partial indexes
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+RESET enable_or_transformation;
+
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+
+-- Don't scan partial indexes because of extra value.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+EXPLAIN (COSTS OFF)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+
+-- Combine different saops. Some of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+
+-- Check recursive combination of OR and SAOP expressions
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+-- Although SAOP doesn't fit partial indexes fully, we can use added OR clause
+-- to scan another couple of partial indexes.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+
+RESET enable_indexscan;
+--Check the case when we construct ANY list with unique elements
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE unique1 = 1 OR unique1 = 1;
+
+RESET enable_seqscan;
+
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index f4b6fee893..7930a17e81 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2141,6 +2141,7 @@ PredIterInfoData
 PredXactList
 PredicateLockData
 PredicateLockTargetType
+PredicatesData
 PrefetchBufferResult
 PrepParallelRestorePtrType
 PrepareStmt
-- 
2.34.1

v21-0001-Transform-OR-clauses-to-ANY-expression.patchtext/x-patch; charset=UTF-8; name=v21-0001-Transform-OR-clauses-to-ANY-expression.patchDownload
From af4592111fcd1f5fb85216c7d56f19ed0ffde38a Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Fri, 2 Feb 2024 22:01:09 +0300
Subject: [PATCH 1/2] Transform OR clauses to ANY expression.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...]) on the
preliminary stage of optimization when we are still working with the
expression tree.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
---
 .../postgres_fdw/expected/postgres_fdw.out    |   8 +-
 doc/src/sgml/config.sgml                      |  17 +
 src/backend/nodes/queryjumblefuncs.c          |  27 ++
 src/backend/optimizer/util/predtest.c         |   9 -
 src/backend/parser/parse_expr.c               | 356 ++++++++++++++++++
 src/backend/utils/misc/guc_tables.c           |  11 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/bin/pg_dump/t/002_pg_dump.pl              |   6 +-
 src/include/nodes/queryjumble.h               |   1 +
 src/include/optimizer/optimizer.h             |  10 +
 src/test/regress/expected/create_index.out    | 156 +++++++-
 src/test/regress/expected/join.out            |  62 ++-
 src/test/regress/expected/partition_prune.out | 215 ++++++++++-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  35 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 21 files changed, 923 insertions(+), 69 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index c355e8f3f7..48685bf6ff 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8797,18 +8797,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index b38cbd714a..1fdfffd79b 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5433,6 +5433,23 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-enable-or-transformation" xreflabel="enable_or_transformation">
+      <term><varname>enable_or_transformation</varname> (<type>boolean</type>)
+       <indexterm>
+        <primary><varname>enable_or_transformation</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      <listitem>
+       <para>
+        Enables or disables the query planner's ability to lookup and group multiple
+        similar OR expressions to ANY (<xref linkend="functions-comparisons-any-some"/>) expressions.
+        The grouping technique of this transformation is based on the equivalence of variable sides.
+        One side of such an expression must be a constant clause, and the other must contain a variable clause.
+        The default is <literal>on</literal>.
+        </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-enable-parallel-append" xreflabel="enable_parallel_append">
       <term><varname>enable_parallel_append</varname> (<type>boolean</type>)
       <indexterm>
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 2c116c8728..0c5b4a011b 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -141,6 +141,33 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index c37b416e24..b76896dfbf 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -30,15 +30,6 @@
 #include "utils/syscache.h"
 
 
-/*
- * Proof attempts involving large arrays in ScalarArrayOpExpr nodes are
- * likely to require O(N^2) time, and more often than not fail anyway.
- * So we set an arbitrary limit on the number of array elements that
- * we will allow to be treated as an AND or OR clause.
- * XXX is it worth exposing this as a GUC knob?
- */
-#define MAX_SAOP_ARRAY_SIZE		100
-
 /*
  * To avoid redundant coding in predicate_implied_by_recurse and
  * predicate_refuted_by_recurse, we need to abstract out the notion of
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 9300c7b9ab..e9813ef6ab 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,15 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
+#include "common/hashfn.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -38,11 +41,13 @@
 #include "utils/date.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +104,352 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	NodeTag	type;
+
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey key;
+
+	List		   *consts;
+	List 		   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function to find candidate clauses.
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				exprHash;
+
+	Assert(keysize == sizeof(OrClauseGroupKey));
+	Assert(IsA(data, Invalid));
+
+	(void) JumbleExpr(key->expr, &exprHash);
+
+	return hash_combine((uint32) exprHash,
+						hash_combine((uint32) key->opno,
+									 (uint32) key->exprtype));
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(src, Invalid));
+
+	dst_key->type = T_Invalid;
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in or_group_htab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(key1, Invalid));
+	Assert(IsA(key2, Invalid));
+
+	if (key1->opno == key2->opno &&
+		key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+/*
+ * TransformOrExprToANY -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to an ANY operation.
+ *	  Transformation must be already done on input args list before the call.
+ *	  Transformation groups two-sided equality operations. One side of such an
+ *	  operation must be plain constant or constant expression. The other side of
+ *	  the clause must be a variable expression without volatile functions.
+ *	  The grouping technique is based on an equivalence of variable sides of the
+ *	  expression: using queryId and equal() routine, it groups constant sides of
+ *	  similar clauses into an array. After the grouping procedure, each couple
+ *	  ('variable expression' and 'constant array') form a new SAOP operation,
+ *	  which is added to the args list of the returning expression.
+ *
+ *	  NOTE: function returns OR BoolExpr if more than one clause are detected in
+ *	  the final args list, or ScalarArrayOpExpr if all args were grouped into
+ *	  the single SAOP expression.
+ */
+static Node *
+TransformOrExprToANY(ParseState *pstate, List *args, int location)
+{
+	List				   *or_list = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(args);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	Assert(enable_or_transformation && len_ors > 1);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, args)
+	{
+		Node				   *orqual = lfirst(lc);
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Oid						exprtype;
+		Node				   *leftop, *rightop;
+
+		if (!IsA(orqual, OpExpr))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				entries = lappend(entries, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		 * Transformation only works with both side type is not
+		 * { array | composite | domain | record }.
+		 * Also, forbid it for volatile expressions.
+		 */
+		exprtype = exprType(nconst_expr);
+		if (type_is_rowtype(exprType(const_expr)) ||
+			type_is_rowtype(exprtype) ||
+			contain_volatile_functions((Node *) nconst_expr))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.type = T_Invalid;
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.exprtype = exprtype;
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = list_append_unique(entry->consts, const_expr);
+			entry->exprs = list_append_unique(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		if (!IsA(lfirst(lc), Invalid))
+		{
+			or_list = lappend(or_list, lfirst(lc));
+			continue;
+		}
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+
+		if (list_length(entry->consts) == 1 ||
+			list_length(entry->consts) > MAX_SAOP_ARRAY_SIZE)
+		{
+			/*
+			 * Only one element or more than MAX_SAOP_ARRAY_SIZE elements in
+			 * the class Return origin expression into.
+			 * the BoolExpr args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.exprtype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+											   InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+			ListCell		   *lc1;
+
+			foreach(lc1, entry->consts)
+			{
+				Node   *rexpr = (Node *) lfirst(lc1);
+
+				rexpr = coerce_to_common_type(pstate, rexpr,
+											  scalar_type,
+											  "IN");
+				aexprs = lappend(aexprs, rexpr);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 (Node *) entry->key.expr,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -1386,6 +1737,11 @@ transformBoolExpr(ParseState *pstate, BoolExpr *a)
 		args = lappend(args, arg);
 	}
 
+	/* Make an attempt to group similar OR clauses into ANY operation */
+	if (enable_or_transformation && a->boolop == OR_EXPR &&
+		list_length(args) > 1)
+		return TransformOrExprToANY(pstate, args, a->location);
+
 	return (Node *) makeBoolExpr(a->boolop, args, a->location);
 }
 
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 45013582a7..c0ea53495b 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1026,6 +1026,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an array expression."),
+			gettext_noop("The planner will replace expression like 'x=c1 OR x=c2 ..'"
+						 "to the expression 'x = ANY(ARRAY[c1,c2,..])'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index edcc0282b2..d30dc6d51c 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -389,6 +389,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 00b5092713..d28bf617db 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -2095,9 +2095,9 @@ my %tests = (
 		regexp => qr/^
 			\QCREATE DOMAIN dump_test.us_postal_code AS text COLLATE pg_catalog."C" DEFAULT '10014'::text\E\n\s+
 			\QCONSTRAINT us_postal_code_check CHECK \E
-			\Q(((VALUE ~ '^\d{5}\E
-			\$\Q'::text) OR (VALUE ~ '^\d{5}-\d{4}\E\$
-			\Q'::text)));\E(.|\n)*
+			\Q((VALUE ~ ANY (ARRAY['^\d{5}\E
+			\$\Q'::text, '^\d{5}-\d{4}\E\$
+			\Q'::text])));\E(.|\n)*
 			\QCOMMENT ON CONSTRAINT us_postal_code_check ON DOMAIN dump_test.us_postal_code IS 'check it';\E
 			/xm,
 		like =>
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067..a9ae048af5 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 7b63c5cf71..0ee7154e08 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -50,6 +50,7 @@ struct PlannedStmt;
 struct ParamListInfoData;
 struct HeapTupleData;
 
+extern PGDLLIMPORT bool enable_or_transformation;
 
 /* in path/clausesel.c: */
 
@@ -159,6 +160,15 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+/*
+ * Proof attempts involving large arrays in ScalarArrayOpExpr nodes are
+ * likely to require O(N^2) time, and more often than not fail anyway.
+ * So we set an arbitrary limit on the number of array elements that
+ * we will allow to be treated as an AND or OR clause.
+ * XXX is it worth exposing this as a GUC knob?
+ */
+#define MAX_SAOP_ARRAY_SIZE		100
+
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 79fa117cb5..606a4399f9 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,116 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                      QUERY PLAN                                       
+---------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43}'::integer[]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND ((thousand = ANY ('{42,41}'::integer[])) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9605400021..d8018bef4f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index bf0657b9f2..1e153c3bb5 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +618,13 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -2072,10 +2251,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 10903bdab0..6f55b9e3ec 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 9be7aca2b8..1f9029b5b2 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -124,6 +124,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -134,7 +135,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(23 rows)
+(24 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..2a079e996b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..56fde15bc1 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index c4c6c7b8ba..1663608043 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index a09b27d820..9717c8c835 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index cc3611e606..f4b6fee893 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1656,6 +1656,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

#161jian he
jian.universality@gmail.com
In reply to: Alena Rybakina (#160)
Re: POC, WIP: OR-clause support for indexes
+ if (!IsA(lfirst(lc), Invalid))
+ {
+ or_list = lappend(or_list, lfirst(lc));
+ continue;
+ }
 Currently `IsA(lfirst(lc)` works.
but is this generally OK? I didn't find any other examples.
do you need do cast, like `(Node *) lfirst(lc);`

If I understand the logic correctly:
In `foreach(lc, args) ` if everything goes well, it will reach
`hashkey.type = T_Invalid;`
which will make `IsA(lfirst(lc), Invalid)` be true.
adding some comments to the above code would be great.

#162Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alexander Korotkov (#159)
Re: POC, WIP: OR-clause support for indexes

On 7/3/2024 21:51, Alexander Korotkov wrote:

Hi!

On Tue, Mar 5, 2024 at 9:59 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru <mailto:a.lepikhov@postgrespro.ru>> wrote:

On 5/3/2024 12:30, Andrei Lepikhov wrote:

On 4/3/2024 09:26, jian he wrote:

... and the new version of the patchset is attached.

I made some revisions for the patchset.

Great!

1) Use hash_combine() to combine hash values.

Looks better

2) Upper limit the number of array elements by MAX_SAOP_ARRAY_SIZE.

I'm not convinced about this limit. The initial reason was to combine
long lists of ORs into the array because such a transformation made at
an early stage increases efficiency.
I understand the necessity of this limit in the array decomposition
routine but not in the creation one.

3) Better save the original order of clauses by putting hash entries and
untransformable clauses to the same list.  A lot of differences in
regression tests output have gone.

I agree that reducing the number of changes in regression tests looks
better. But to achieve this, you introduced a hack that increases the
complexity of the code. Is it worth it? Maybe it would be better to make
one-time changes in tests instead of getting this burden on board. Or
have you meant something more introducing the node type?

We don't make array values unique.  That might make query execution
performance somewhat worse, and also makes selectivity estimation
worse.  I suggest Andrei and/or Alena should implement making array
values unique.

The fix Alena has made looks correct. But I urge you to think twice:
The optimizer doesn't care about duplicates, so why do we do it?
What's more, this optimization is intended to speed up queries with long
OR lists. Using the list_append_unique() comparator on such lists could
impact performance. I suggest sticking to the common rule and leaving
the responsibility on the user's shoulders.
At least, we should do this optimization later, in one pass, with
sorting elements before building the array. But what if we don't have a
sort operator for the type?

--
regards,
Andrei Lepikhov
Postgres Professional

#163Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#162)
Re: POC, WIP: OR-clause support for indexes

Hi Andrei,

Thank you for your response.

On Mon, Mar 11, 2024 at 7:13 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 7/3/2024 21:51, Alexander Korotkov wrote:

Hi!

On Tue, Mar 5, 2024 at 9:59 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru <mailto:a.lepikhov@postgrespro.ru>> wrote:

On 5/3/2024 12:30, Andrei Lepikhov wrote:

On 4/3/2024 09:26, jian he wrote:

... and the new version of the patchset is attached.

I made some revisions for the patchset.

Great!

1) Use hash_combine() to combine hash values.

Looks better

2) Upper limit the number of array elements by MAX_SAOP_ARRAY_SIZE.

I'm not convinced about this limit. The initial reason was to combine
long lists of ORs into the array because such a transformation made at
an early stage increases efficiency.
I understand the necessity of this limit in the array decomposition
routine but not in the creation one.

The comment near MAX_SAOP_ARRAY_SIZE says that this limit is because
N^2 algorithms could be applied to arrays. Are you sure that's not
true for our case?

3) Better save the original order of clauses by putting hash entries and
untransformable clauses to the same list. A lot of differences in
regression tests output have gone.

I agree that reducing the number of changes in regression tests looks
better. But to achieve this, you introduced a hack that increases the
complexity of the code. Is it worth it? Maybe it would be better to make
one-time changes in tests instead of getting this burden on board. Or
have you meant something more introducing the node type?

For me the reason is not just a regression test. The current code
keeps the original order of quals as much as possible. The OR
transformation code reorders quals even in cases when it doesn't
eventually apply any optimization. I don't think that's acceptable.
However, less hackery ways for this is welcome for sure.

We don't make array values unique. That might make query execution
performance somewhat worse, and also makes selectivity estimation
worse. I suggest Andrei and/or Alena should implement making array
values unique.

The fix Alena has made looks correct. But I urge you to think twice:
The optimizer doesn't care about duplicates, so why do we do it?
What's more, this optimization is intended to speed up queries with long
OR lists. Using the list_append_unique() comparator on such lists could
impact performance. I suggest sticking to the common rule and leaving
the responsibility on the user's shoulders.

I don't see why the optimizer doesn't care about duplicates for OR
lists. As I showed before in an example, it successfully removes the
duplicate. So, currently OR transformation clearly introduces a
regression in terms of selectivity estimation. I think we should
evade that.

At least, we should do this optimization later, in one pass, with
sorting elements before building the array. But what if we don't have a
sort operator for the type?

It was probably discussed before, but can we do our work later? There
is a canonicalize_qual() which calls find_duplicate_ors(). This is
the place where currently duplicate OR clauses are removed. Could our
OR-to-ANY transformation be just another call from
canonicalize_qual()?

------
Regards,
Alexander Korotkov

#164Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alexander Korotkov (#163)
Re: POC, WIP: OR-clause support for indexes

On 11/3/2024 18:31, Alexander Korotkov wrote:

I'm not convinced about this limit. The initial reason was to combine
long lists of ORs into the array because such a transformation made at
an early stage increases efficiency.
I understand the necessity of this limit in the array decomposition
routine but not in the creation one.

The comment near MAX_SAOP_ARRAY_SIZE says that this limit is because
N^2 algorithms could be applied to arrays. Are you sure that's not
true for our case?

When you operate an array, indeed. But when we transform ORs to an
array, not. Just check all the places in the optimizer and even the
executor where we would pass along the list of ORs. This is why I think
we should use this optimization even more intensively for huge numbers
of ORs in an attempt to speed up the overall query.

3) Better save the original order of clauses by putting hash entries and
untransformable clauses to the same list. A lot of differences in
regression tests output have gone.

I agree that reducing the number of changes in regression tests looks
better. But to achieve this, you introduced a hack that increases the
complexity of the code. Is it worth it? Maybe it would be better to make
one-time changes in tests instead of getting this burden on board. Or
have you meant something more introducing the node type?

For me the reason is not just a regression test. The current code
keeps the original order of quals as much as possible. The OR
transformation code reorders quals even in cases when it doesn't
eventually apply any optimization. I don't think that's acceptable.
However, less hackery ways for this is welcome for sure.

Why is it unacceptable? Can the user implement some order-dependent
logic with clauses, and will it be correct?
Otherwise, it is a matter of taste, and generally, this decision is up
to you.

We don't make array values unique. That might make query execution
performance somewhat worse, and also makes selectivity estimation
worse. I suggest Andrei and/or Alena should implement making array
values unique.

The fix Alena has made looks correct. But I urge you to think twice:
The optimizer doesn't care about duplicates, so why do we do it?
What's more, this optimization is intended to speed up queries with long
OR lists. Using the list_append_unique() comparator on such lists could
impact performance. I suggest sticking to the common rule and leaving
the responsibility on the user's shoulders.

I don't see why the optimizer doesn't care about duplicates for OR
lists. As I showed before in an example, it successfully removes the
duplicate. So, currently OR transformation clearly introduces a
regression in terms of selectivity estimation. I think we should
evade that.

I think you are right. It is probably a better place than any other to
remove duplicates in an array. I just think we should sort and remove
duplicates from entry->consts in one pass. Thus, this optimisation
should be applied to sortable constants.

At least, we should do this optimization later, in one pass, with
sorting elements before building the array. But what if we don't have a
sort operator for the type?

It was probably discussed before, but can we do our work later? There
is a canonicalize_qual() which calls find_duplicate_ors(). This is
the place where currently duplicate OR clauses are removed. Could our
OR-to-ANY transformation be just another call from
canonicalize_qual()?

Hmm, we already tried to do it at that point. I vaguely recall some
issues caused by this approach. Anyway, it should be done as quickly as
possible to increase the effect of the optimization.

--
regards,
Andrei Lepikhov
Postgres Professional

#165Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#164)
Re: POC, WIP: OR-clause support for indexes

On Mon, Mar 11, 2024 at 2:43 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 11/3/2024 18:31, Alexander Korotkov wrote:

I'm not convinced about this limit. The initial reason was to combine
long lists of ORs into the array because such a transformation made at
an early stage increases efficiency.
I understand the necessity of this limit in the array decomposition
routine but not in the creation one.

The comment near MAX_SAOP_ARRAY_SIZE says that this limit is because
N^2 algorithms could be applied to arrays. Are you sure that's not
true for our case?

When you operate an array, indeed. But when we transform ORs to an
array, not. Just check all the places in the optimizer and even the
executor where we would pass along the list of ORs. This is why I think
we should use this optimization even more intensively for huge numbers
of ORs in an attempt to speed up the overall query.

Ok.

3) Better save the original order of clauses by putting hash entries and
untransformable clauses to the same list. A lot of differences in
regression tests output have gone.

I agree that reducing the number of changes in regression tests looks
better. But to achieve this, you introduced a hack that increases the
complexity of the code. Is it worth it? Maybe it would be better to make
one-time changes in tests instead of getting this burden on board. Or
have you meant something more introducing the node type?

For me the reason is not just a regression test. The current code
keeps the original order of quals as much as possible. The OR
transformation code reorders quals even in cases when it doesn't
eventually apply any optimization. I don't think that's acceptable.
However, less hackery ways for this is welcome for sure.

Why is it unacceptable? Can the user implement some order-dependent
logic with clauses, and will it be correct?
Otherwise, it is a matter of taste, and generally, this decision is up
to you.

I think this is an important property that the user sees the quals in
the plan in the same order as they were in the query. And if some
transformations are applied, then the order is saved as much as
possible. I don't think we should sacrifice this property without
strong reasons. A bit of code complexity is definitely not that
reason for me.

We don't make array values unique. That might make query execution
performance somewhat worse, and also makes selectivity estimation
worse. I suggest Andrei and/or Alena should implement making array
values unique.

The fix Alena has made looks correct. But I urge you to think twice:
The optimizer doesn't care about duplicates, so why do we do it?
What's more, this optimization is intended to speed up queries with long
OR lists. Using the list_append_unique() comparator on such lists could
impact performance. I suggest sticking to the common rule and leaving
the responsibility on the user's shoulders.

I don't see why the optimizer doesn't care about duplicates for OR
lists. As I showed before in an example, it successfully removes the
duplicate. So, currently OR transformation clearly introduces a
regression in terms of selectivity estimation. I think we should
evade that.

I think you are right. It is probably a better place than any other to
remove duplicates in an array. I just think we should sort and remove
duplicates from entry->consts in one pass. Thus, this optimisation
should be applied to sortable constants.

Ok.

At least, we should do this optimization later, in one pass, with
sorting elements before building the array. But what if we don't have a
sort operator for the type?

It was probably discussed before, but can we do our work later? There
is a canonicalize_qual() which calls find_duplicate_ors(). This is
the place where currently duplicate OR clauses are removed. Could our
OR-to-ANY transformation be just another call from
canonicalize_qual()?

Hmm, we already tried to do it at that point. I vaguely recall some
issues caused by this approach. Anyway, it should be done as quickly as
possible to increase the effect of the optimization.

I think there were provided quite strong reasons why this shouldn't be
implemented at the parse analysis stage [1], [2], [3]. The
canonicalize_qual() looks quite appropriate place for that since it
does similar transformations.

Links.
1. /messages/by-id/CA+TgmoZCgP6FrBQEusn4yaWm02XU8OPeoEMk91q7PRBgwaAkFw@mail.gmail.com
2. /messages/by-id/CAH2-Wzm2=nf_JhiM3A2yetxRs8Nd2NuN3JqH=fm_YWYd1oYoPg@mail.gmail.com
3. /messages/by-id/CA+TgmoaOiwMXBBTYknczepoZzKTp-Zgk5ss1+CuVQE-eFTqBmA@mail.gmail.com

------
Regards,
Alexander Korotkov

#166Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alexander Korotkov (#165)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 12/3/2024 22:20, Alexander Korotkov wrote:

On Mon, Mar 11, 2024 at 2:43 PM Andrei Lepikhov

I think you are right. It is probably a better place than any other to
remove duplicates in an array. I just think we should sort and remove
duplicates from entry->consts in one pass. Thus, this optimisation
should be applied to sortable constants.

Ok.

New version of the patch set implemented all we have agreed on for now.
We can return MAX_SAOP_ARRAY_SIZE constraint and Alena's approach to
duplicates deletion for non-sortable cases at the end.

Hmm, we already tried to do it at that point. I vaguely recall some
issues caused by this approach. Anyway, it should be done as quickly as
possible to increase the effect of the optimization.

I think there were provided quite strong reasons why this shouldn't be
implemented at the parse analysis stage [1], [2], [3]. The
canonicalize_qual() looks quite appropriate place for that since it
does similar transformations.

Ok. Let's discuss these reasons. In Robert's opinion [1,3], we should do
the transformation based on the cost model. But in the canonicalize_qual
routine, we still make the transformation blindly. Moreover, the second
patch reduces the weight of this reason, doesn't it? Maybe we shouldn't
think about that as about optimisation but some 'general form of
expression'?
Peter [2] worries about the possible transformation outcomes at this
stage. But remember, we already transform clauses like ROW() IN (...) to
a series of ORs here, so it is not an issue. Am I wrong?
Why did we discard the attempt with canonicalize_qual on the previous
iteration? - The stage of parsing is much more native for building SAOP
quals. We can reuse make_scalar_array_op and other stuff, for example.
During the optimisation stage, the only list partitioning machinery
creates SAOP based on a list of constants. So, in theory, it is possible
to implement. But do we really need to make the code more complex?

Links.
1. /messages/by-id/CA+TgmoZCgP6FrBQEusn4yaWm02XU8OPeoEMk91q7PRBgwaAkFw@mail.gmail.com
2. /messages/by-id/CAH2-Wzm2=nf_JhiM3A2yetxRs8Nd2NuN3JqH=fm_YWYd1oYoPg@mail.gmail.com
3. /messages/by-id/CA+TgmoaOiwMXBBTYknczepoZzKTp-Zgk5ss1+CuVQE-eFTqBmA@mail.gmail.com

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v22-0001-Transform-OR-clauses-to-ANY-expression.patchtext/plain; charset=UTF-8; name=v22-0001-Transform-OR-clauses-to-ANY-expression.patchDownload
From 86d969f2598a03b1eba84c0c064707de34ee60ac Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Fri, 2 Feb 2024 22:01:09 +0300
Subject: [PATCH 1/2] Transform OR clauses to ANY expression.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...]) on the
preliminary stage of optimization when we are still working with the
expression tree.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
---
 .../postgres_fdw/expected/postgres_fdw.out    |   8 +-
 doc/src/sgml/config.sgml                      |  17 +
 src/backend/nodes/queryjumblefuncs.c          |  27 ++
 src/backend/parser/parse_expr.c               | 416 ++++++++++++++++++
 src/backend/utils/misc/guc_tables.c           |  11 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/bin/pg_dump/t/002_pg_dump.pl              |   6 +-
 src/include/nodes/queryjumble.h               |   1 +
 src/include/optimizer/optimizer.h             |   1 +
 src/test/regress/expected/create_index.out    | 156 ++++++-
 src/test/regress/expected/join.out            |  62 ++-
 src/test/regress/expected/partition_prune.out | 215 ++++++++-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  35 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 +
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 20 files changed, 974 insertions(+), 60 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 58a603ac56..a965b43cc6 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8838,18 +8838,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 65a6e6c408..2de6ae301a 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5472,6 +5472,23 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-enable-or-transformation" xreflabel="enable_or_transformation">
+      <term><varname>enable_or_transformation</varname> (<type>boolean</type>)
+       <indexterm>
+        <primary><varname>enable_or_transformation</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      <listitem>
+       <para>
+        Enables or disables the query planner's ability to lookup and group multiple
+        similar OR expressions to ANY (<xref linkend="functions-comparisons-any-some"/>) expressions.
+        The grouping technique of this transformation is based on the equivalence of variable sides.
+        One side of such an expression must be a constant clause, and the other must contain a variable clause.
+        The default is <literal>on</literal>.
+        </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-enable-parallel-append" xreflabel="enable_parallel_append">
       <term><varname>enable_parallel_append</varname> (<type>boolean</type>)
       <indexterm>
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 2c116c8728..0c5b4a011b 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -141,6 +141,33 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 9300c7b9ab..84038ab68f 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,15 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
+#include "common/hashfn.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -38,11 +41,13 @@
 #include "utils/date.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
+bool		enable_or_transformation = true;
 
 
 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
@@ -99,6 +104,412 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	NodeTag	type;
+
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey	key;
+
+	List			   *consts;
+	List 			   *exprs;
+	FunctionCallInfo	fcinfo;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function to find candidate clauses.
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				exprHash;
+
+	Assert(keysize == sizeof(OrClauseGroupKey));
+	Assert(IsA(data, Invalid));
+
+	(void) JumbleExpr(key->expr, &exprHash);
+
+	return hash_combine((uint32) exprHash,
+						hash_combine((uint32) key->opno,
+									 (uint32) key->exprtype));
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(src, Invalid));
+
+	dst_key->type = T_Invalid;
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in or_group_htab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(key1, Invalid));
+	Assert(IsA(key2, Invalid));
+
+	if (key1->opno == key2->opno &&
+		key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+static FunctionCallInfo locfcinfo = NULL;
+
+static int
+saop_const_comparator(const ListCell *a, const ListCell *b)
+{
+	Node   *leftop = (Node *) lfirst(a);
+	Node   *rightop = (Node *) lfirst(b);
+
+	if (IsA(leftop, RelabelType))
+		leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+	if (IsA(rightop, RelabelType))
+		rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+	Assert(IsA(leftop, Const) && IsA(rightop, Const));
+
+	locfcinfo->args[0].value = ((Const *) leftop)->constvalue;
+	locfcinfo->args[0].isnull = false;
+	locfcinfo->args[1].value = ((Const *) rightop)->constvalue;
+	locfcinfo->args[1].isnull = false;
+	return DatumGetInt32(FunctionCallInvoke(locfcinfo));
+}
+
+static List *
+saop_delete_duplicates(ParseState *pstate, OrClauseGroupEntry *entry,
+					   Oid scalar_type)
+{
+	ListCell   *lc;
+	List	   *result;
+
+	locfcinfo = entry->fcinfo;
+	list_sort(entry->consts, saop_const_comparator);
+
+	result = list_make1(linitial(entry->consts));
+	for_each_from(lc, entry->consts, 1)
+	{
+		Node *node = (Node *) lfirst(lc);
+
+		if (equal(llast(result), node))
+			continue;
+
+		node = coerce_to_common_type(pstate, node, scalar_type, "IN");
+		result = lappend(result, node);
+	}
+
+	return result;
+}
+
+/*
+ * TransformOrExprToANY -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to an ANY operation.
+ *	  Transformation must be already done on input args list before the call.
+ *	  Transformation groups two-sided equality operations. One side of such an
+ *	  operation must be plain constant or constant expression. The other side of
+ *	  the clause must be a variable expression without volatile functions.
+ *	  The grouping technique is based on an equivalence of variable sides of the
+ *	  expression: using queryId and equal() routine, it groups constant sides of
+ *	  similar clauses into an array. After the grouping procedure, each couple
+ *	  ('variable expression' and 'constant array') form a new SAOP operation,
+ *	  which is added to the args list of the returning expression.
+ *
+ *	  NOTE: function returns OR BoolExpr if more than one clause are detected in
+ *	  the final args list, or ScalarArrayOpExpr if all args were grouped into
+ *	  the single SAOP expression.
+ */
+static Node *
+TransformOrExprToANY(ParseState *pstate, List *args, int location)
+{
+	List				   *or_list = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(args);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	Assert(enable_or_transformation && len_ors > 1);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, args)
+	{
+		Node				   *orqual = lfirst(lc);
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Oid						exprtype;
+		Node				   *leftop, *rightop;
+		TypeCacheEntry		   *typentry;
+
+		if (!IsA(orqual, OpExpr))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				entries = lappend(entries, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		 * Transformation only works with both side type is not
+		 * { array | composite | domain | record }.
+		 * Also, forbid it for volatile expressions.
+		 */
+		exprtype = exprType(nconst_expr);
+		if (type_is_rowtype(exprType(const_expr)) ||
+			type_is_rowtype(exprtype) ||
+			contain_volatile_functions((Node *) nconst_expr))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		typentry = lookup_type_cache(exprtype, TYPECACHE_CMP_PROC_FINFO);
+
+		/*
+		 * Within this transformation we remove duplicates. To avoid
+		 * quadratic behavior we need to sort clauses after making a list of
+		 * elements. So, need sort operator to implement that.
+		 */
+		if (!OidIsValid(typentry->cmp_proc_finfo.fn_oid))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.type = T_Invalid;
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.exprtype = exprtype;
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/* Prepare funcall for sort comparator */
+			entry->fcinfo =
+						(FunctionCallInfo) palloc(SizeForFunctionCallInfo(2));
+			InitFunctionCallInfoData(*(entry->fcinfo),
+									 &typentry->cmp_proc_finfo, 2,
+									 typentry->typcollation, NULL, NULL);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		if (!IsA(lfirst(lc), Invalid))
+		{
+			or_list = lappend(or_list, lfirst(lc));
+			continue;
+		}
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element returns origin expression into the BoolExpr args
+			 * list unchanged.
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.exprtype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+											   InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+
+			aexprs = saop_delete_duplicates(pstate, entry, scalar_type);
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 (Node *) entry->key.expr,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
+			 */
+			list_free(entry->consts);
+			or_list = list_concat(or_list, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -1386,6 +1797,11 @@ transformBoolExpr(ParseState *pstate, BoolExpr *a)
 		args = lappend(args, arg);
 	}
 
+	/* Make an attempt to group similar OR clauses into ANY operation */
+	if (enable_or_transformation && a->boolop == OR_EXPR &&
+		list_length(args) > 1)
+		return TransformOrExprToANY(pstate, args, a->location);
+
 	return (Node *) makeBoolExpr(a->boolop, args, a->location);
 }
 
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index d77214795d..0c3f278420 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1026,6 +1026,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an array expression."),
+			gettext_noop("The planner will replace expression like 'x=c1 OR x=c2 ..'"
+						 "to the expression 'x = ANY(ARRAY[c1,c2,..])'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 2244ee52f7..524516593f 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -391,6 +391,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 00b5092713..d28bf617db 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -2095,9 +2095,9 @@ my %tests = (
 		regexp => qr/^
 			\QCREATE DOMAIN dump_test.us_postal_code AS text COLLATE pg_catalog."C" DEFAULT '10014'::text\E\n\s+
 			\QCONSTRAINT us_postal_code_check CHECK \E
-			\Q(((VALUE ~ '^\d{5}\E
-			\$\Q'::text) OR (VALUE ~ '^\d{5}-\d{4}\E\$
-			\Q'::text)));\E(.|\n)*
+			\Q((VALUE ~ ANY (ARRAY['^\d{5}\E
+			\$\Q'::text, '^\d{5}-\d{4}\E\$
+			\Q'::text])));\E(.|\n)*
 			\QCOMMENT ON CONSTRAINT us_postal_code_check ON DOMAIN dump_test.us_postal_code IS 'check it';\E
 			/xm,
 		like =>
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067..a9ae048af5 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 7b63c5cf71..35ab577501 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -50,6 +50,7 @@ struct PlannedStmt;
 struct ParamListInfoData;
 struct HeapTupleData;
 
+extern PGDLLIMPORT bool enable_or_transformation;
 
 /* in path/clausesel.c: */
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 79fa117cb5..4a4dfb3bb5 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,116 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                      QUERY PLAN                                       
+---------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,43,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,43,99}'::integer[]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND ((thousand = ANY ('{41,42}'::integer[])) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: (thousand = ANY ('{41,42}'::integer[]))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9605400021..d8018bef4f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index bf0657b9f2..1e153c3bb5 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +618,13 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -2072,10 +2251,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 10903bdab0..6f55b9e3ec 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 9be7aca2b8..1f9029b5b2 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -124,6 +124,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -134,7 +135,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(23 rows)
+(24 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..ad91abff7b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,1)","(0,2)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,1)","(0,2)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..56fde15bc1 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index c4c6c7b8ba..1663608043 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index a09b27d820..9717c8c835 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index aa7a25b8f8..c6027c588d 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1657,6 +1657,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.44.0

v22-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchtext/plain; charset=UTF-8; name=v22-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchDownload
From c53b658521f9112fe4d9b7e9ccaba978fe422828 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Wed, 13 Mar 2024 12:26:02 +0700
Subject: [PATCH 2/2] Teach generate_bitmap_or_paths to build BitmapOr paths
 over SAOP clauses.

Likewise OR clauses, discover SAOP array and try to split its elements
between smaller sized arrays to fit a set of partial indexes.
---
 doc/src/sgml/config.sgml                  |   3 +
 src/backend/optimizer/path/indxpath.c     | 315 ++++++++++++++++++----
 src/backend/optimizer/util/predtest.c     |  46 ++++
 src/backend/optimizer/util/restrictinfo.c |  13 +
 src/include/optimizer/optimizer.h         |  16 ++
 src/include/optimizer/restrictinfo.h      |   1 +
 src/test/regress/expected/select.out      | 282 +++++++++++++++++++
 src/test/regress/sql/select.sql           |  82 ++++++
 src/tools/pgindent/typedefs.list          |   1 +
 9 files changed, 706 insertions(+), 53 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 2de6ae301a..0df56f44e3 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5485,6 +5485,9 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
         The grouping technique of this transformation is based on the equivalence of variable sides.
         One side of such an expression must be a constant clause, and the other must contain a variable clause.
         The default is <literal>on</literal>.
+        Also, during BitmapScan paths generation it enables analysis of elements
+        of IN or ANY constant arrays to cover such clause with BitmapOr set of
+        partial index scans.
         </para>
       </listitem>
      </varlistentry>
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 32c6a8bbdc..f92a47c3d5 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,6 +32,7 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
 
@@ -1220,11 +1221,188 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Building index paths over SAOP clause differs from the logic of OR clauses.
+ * Here we iterate across all the array elements and split them to SAOPs,
+ * corresponding to different indexes. We must match each element to an index.
+ */
+static List *
+build_paths_for_SAOP(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo,
+					 List *other_clauses)
+{
+	List			   *result = NIL;
+	List			   *predicate_lists = NIL;
+	ListCell		   *lc;
+	PredicatesData	   *pd;
+	ScalarArrayOpExpr  *saop = (ScalarArrayOpExpr *) rinfo->clause;
+
+	Assert(IsA(saop, ScalarArrayOpExpr) && saop->useOr);
+
+	if (!IsA(lsecond(saop->args), Const))
+		/*
+		 * Has it practical outcome to merge arrays which couldn't constantified
+		 * before that step?
+		 */
+		return NIL;
+
+	/* Collect predicates */
+	foreach(lc, rel->indexlist)
+	{
+		IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
+
+		/* Take into consideration partial indexes supporting bitmap scans */
+		if (!index->amhasgetbitmap || index->indpred == NIL || index->predOK)
+			continue;
+
+		pd = palloc0(sizeof(PredicatesData));
+		pd->id = foreach_current_index(lc);
+		/* The trick with reducing recursion is stolen from predicate_implied_by */
+		pd->predicate = list_length(index->indpred) == 1 ?
+										(Node *) linitial(index->indpred) :
+										(Node *) index->indpred;
+		predicate_lists = lappend(predicate_lists, (void *) pd);
+	}
+
+	/* Split the array data according to index predicates. */
+	if (predicate_lists == NIL ||
+		!saop_covered_by_predicates(saop, predicate_lists))
+		return NIL;
+
+	other_clauses = list_delete_ptr(other_clauses, rinfo);
+
+	/*
+	 * Having incoming SAOP split to set of smaller SAOPs which can be applied
+	 * to partial indexes, generate paths for each one.
+	 */
+	foreach(lc, predicate_lists)
+	{
+		IndexOptInfo	   *index;
+		IndexClauseSet		clauseset;
+		List			   *indexpaths;
+		RestrictInfo	   *rinfo1 = NULL;
+		Expr			   *clause;
+		ArrayType		   *arrayval = NULL;
+		ArrayExpr		   *arr = NULL;
+		Const			   *arrayconst;
+		ScalarArrayOpExpr  *dest;
+
+		pd = (PredicatesData *) lfirst(lc);
+		if (pd->elems == NIL)
+			/* The index doesn't participate in this operation */
+			continue;
+
+		/* Make up new array */
+		arrayconst = lsecond_node(Const, saop->args);
+		arrayval = DatumGetArrayTypeP(arrayconst->constvalue);
+		arr = makeNode(ArrayExpr);
+		arr->array_collid = arrayconst->constcollid;
+		arr->array_typeid = arrayconst->consttype;
+		arr->element_typeid = arrayval->elemtype;
+		arr->elements = pd->elems;
+		arr->location = -1;
+		arr->multidims = false;
+
+		/* Compose new SAOP, partially covering the source one */
+		dest = makeNode(ScalarArrayOpExpr);
+		memcpy(dest, saop, sizeof(ScalarArrayOpExpr));
+		dest->args = list_make2(linitial(saop->args), arr);
+		clause = (Expr *) estimate_expression_value(root, (Node *) dest);
+
+		/*
+		 * Create new RestrictInfo. It maybe more heavy than just copy node,
+		 * but remember some internals: the serial number, selectivity
+		 * cache etc.
+		 */
+		rinfo1 = make_restrictinfo(root, clause,
+								   rinfo->is_pushed_down,
+								   rinfo->has_clone,
+								   rinfo->is_clone,
+								   rinfo->pseudoconstant,
+								   rinfo->security_level,
+								   rinfo->required_relids,
+								   rinfo->incompatible_relids,
+								   rinfo->outer_relids);
+
+		index = list_nth(rel->indexlist, pd->id);
+		Assert(predicate_implied_by(index->indpred, list_make1(rinfo1), true));
+
+		/* Excluding partial indexes with predOK we make this statement false */
+		Assert(!predicate_implied_by(index->indpred, other_clauses, false));
+
+		/* Time to generate index paths */
+
+		MemSet(&clauseset, 0, sizeof(clauseset));
+		match_clauses_to_index(root, list_make1(rinfo1), index, &clauseset);
+		match_clauses_to_index(root, other_clauses, index, &clauseset);
+
+		/* Predicate has found already. So, it is ok for the empty match */
+
+		indexpaths = build_index_paths(root, rel,
+									   index, &clauseset,
+									   true,
+									   ST_BITMAPSCAN,
+									   NULL,
+									   NULL);
+		Assert(indexpaths != NIL);
+		result = lappend(result, indexpaths);
+	}
+	return result;
+}
+
+/*
+ * Analyse incoming SAOP node to cover it by partial indexes.
+ *
+ * The returning pathlist must be ANDed to the final BitmapScan path.
+ * The function returns NULL when an array element cannot be fitted with some
+ * partial index. The Rationale for such an operation is that when schema
+ * contains many partial indexes, the SAOP clause may be effectively fulfilled
+ * by appending results of scanning some minimal set of tiny partial indexes.
+ *
+ * Working jointly with the TransformOrExprToANY routine, it provides a user
+ * with some sort of independence of the query plan from the approach to writing
+ * alternatives for the same entity in the WHERE section.
+ */
+static List *
+generate_saop_pathlist(PlannerInfo *root, RelOptInfo *rel,
+					   RestrictInfo *rinfo, List *all_clauses)
+{
+	List	   *pathlist = NIL;
+	Path	   *bitmapqual;
+	List	   *indlist;
+	ListCell   *lc;
+
+	if (!enable_or_transformation)
+		return NIL;
+
+	/*
+	 * We must be able to match at least one index to each element of
+	 * the array, else we can't use it.
+	 */
+	indlist = build_paths_for_SAOP(root, rel, rinfo, all_clauses);
+	if (indlist == NIL)
+		return NIL;
+
+	/*
+	 * OK, pick the most promising AND combination, and add it to
+	 * pathlist.
+	 */
+	foreach (lc, indlist)
+	{
+		List *plist = lfirst_node(List, lc);
+
+		bitmapqual = choose_bitmap_and(root, rel, plist);
+		pathlist = lappend(pathlist, bitmapqual);
+	}
+
+	return pathlist;
+}
+
 /*
  * generate_bitmap_or_paths
- *		Look through the list of clauses to find OR clauses, and generate
- *		a BitmapOrPath for each one we can handle that way.  Return a list
- *		of the generated BitmapOrPaths.
+ *		Look through the list of clauses to find OR and SAOP clauses, and
+ *		Each saop clause are splitted to be covered by partial indexes.
+ *		generate a BitmapOrPath for each one we can handle that way.
+ *		Return a list of the generated BitmapOrPaths.
  *
  * other_clauses is a list of additional clauses that can be assumed true
  * for the purpose of generating indexquals, but are not to be searched for
@@ -1247,68 +1425,99 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	foreach(lc, clauses)
 	{
 		RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
-		List	   *pathlist;
+		List	   *pathlist = NIL;
 		Path	   *bitmapqual;
 		ListCell   *j;
 
-		/* Ignore RestrictInfos that aren't ORs */
-		if (!restriction_is_or_clause(rinfo))
+		if (restriction_is_saop_clause(rinfo))
+		{
+			pathlist = generate_saop_pathlist(root, rel, rinfo,
+											  all_clauses);
+		}
+		else if (!restriction_is_or_clause(rinfo))
+			/* Ignore RestrictInfos that aren't ORs */
 			continue;
-
-		/*
-		 * We must be able to match at least one index to each of the arms of
-		 * the OR, else we can't use it.
-		 */
-		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		else
 		{
-			Node	   *orarg = (Node *) lfirst(j);
-			List	   *indlist;
-
-			/* OR arguments should be ANDs or sub-RestrictInfos */
-			if (is_andclause(orarg))
+			/*
+			 * We must be able to match at least one index to each of the arms of
+			 * the OR, else we can't use it.
+			 */
+			foreach(j, ((BoolExpr *) rinfo->orclause)->args)
 			{
-				List	   *andargs = ((BoolExpr *) orarg)->args;
+				Node	   *orarg = (Node *) lfirst(j);
+				List	   *indlist;
 
-				indlist = build_paths_for_OR(root, rel,
-											 andargs,
-											 all_clauses);
+				/* OR arguments should be ANDs or sub-RestrictInfos */
+				if (is_andclause(orarg))
+				{
+					List	   *andargs = ((BoolExpr *) orarg)->args;
 
-				/* Recurse in case there are sub-ORs */
-				indlist = list_concat(indlist,
-									  generate_bitmap_or_paths(root, rel,
-															   andargs,
-															   all_clauses));
-			}
-			else
-			{
-				RestrictInfo *ri = castNode(RestrictInfo, orarg);
-				List	   *orargs;
+					indlist = build_paths_for_OR(root, rel,
+												 andargs,
+												 all_clauses);
 
-				Assert(!restriction_is_or_clause(ri));
-				orargs = list_make1(ri);
+					/* Recurse in case there are sub-ORs */
+					indlist = list_concat(indlist,
+										  generate_bitmap_or_paths(root, rel,
+																   andargs,
+																   all_clauses));
+				}
+				else
+				{
+					RestrictInfo *ri = castNode(RestrictInfo, orarg);
+					List	   *orargs;
 
-				indlist = build_paths_for_OR(root, rel,
-											 orargs,
-											 all_clauses);
-			}
+					Assert(!restriction_is_or_clause(ri));
 
-			/*
-			 * If nothing matched this arm, we can't do anything with this OR
-			 * clause.
-			 */
-			if (indlist == NIL)
-			{
-				pathlist = NIL;
-				break;
-			}
+					orargs = list_make1(ri);
 
-			/*
-			 * OK, pick the most promising AND combination, and add it to
-			 * pathlist.
-			 */
-			bitmapqual = choose_bitmap_and(root, rel, indlist);
-			pathlist = lappend(pathlist, bitmapqual);
+					if (restriction_is_saop_clause(ri))
+					{
+						List *paths;
+
+						paths = generate_saop_pathlist(root, rel, ri,
+														 all_clauses);
+
+						if (paths != NIL)
+						{
+							/*
+							 * Add paths to pathlist and immediately jump to the
+							 * next element of the OR clause.
+							 */
+							pathlist = list_concat(pathlist, paths);
+							continue;
+						}
+
+						/*
+						 * Pass down out of this if construction:
+						 * If saop isn't covered by partial indexes, try to
+						 * build scan path for the saop as a whole.
+						 */
+					}
+
+					indlist = build_paths_for_OR(root, rel,
+												 orargs,
+												 all_clauses);
+				}
+
+				/*
+				 * If nothing matched this arm, we can't do anything with this OR
+				 * clause.
+				 */
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+
+				/*
+				 * OK, pick the most promising AND combination, and add it to
+				 * pathlist.
+				 */
+				bitmapqual = choose_bitmap_and(root, rel, indlist);
+				pathlist = lappend(pathlist, bitmapqual);
+			}
 		}
 
 		/*
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index c37b416e24..8ed80a78b4 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -112,6 +112,52 @@ static Oid	get_btree_test_op(Oid pred_op, Oid clause_op, bool refute_it);
 static void InvalidateOprProofCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
 
 
+/*
+ * Could this ANY () expression can be split into a set of ANYs over partial
+ * indexes? If yes, return these saops in the PredicatesData structure.
+ */
+bool
+saop_covered_by_predicates(ScalarArrayOpExpr *saop, List *predicate_lists)
+{
+	ListCell		   *lc;
+	PredIterInfoData	clause_info;
+	bool				result = false;
+
+	if (predicate_classify((Node *) saop, &clause_info) != CLASS_OR)
+		return false;
+
+	iterate_begin(pitem, (Node *) saop, clause_info)
+	{
+		result = false;
+
+		foreach(lc, predicate_lists)
+		{
+			PredicatesData *pd = (PredicatesData *) lfirst(lc);
+
+			if (!predicate_implied_by_recurse(pitem, pd->predicate, false))
+				continue;
+
+			/* Predicate is found. Add the elem to the saop clause */
+			Assert(IsA(pitem, OpExpr));
+
+			/* Extract constant from the expression */
+			pd->elems = lappend(pd->elems,
+					copyObject(lsecond_node(Const, ((OpExpr *) pitem)->args)));
+			result = true;
+			break;
+		}
+
+		if (!result)
+			/*
+			 * The element doesn't fit any index. Interrupt the process immediately
+			 */
+			break;
+	}
+	iterate_end(clause_info);
+
+	return result;
+}
+
 /*
  * predicate_implied_by
  *	  Recursively checks whether the clauses in clause_list imply that the
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e9334..1dad1dc654 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -421,6 +421,19 @@ restriction_is_or_clause(RestrictInfo *restrictinfo)
 		return false;
 }
 
+bool
+restriction_is_saop_clause(RestrictInfo *restrictinfo)
+{
+	if (restrictinfo->clause && IsA(restrictinfo->clause, ScalarArrayOpExpr))
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) restrictinfo->clause;
+
+		if (saop->useOr)
+			return true;
+	}
+	return false;
+}
+
 /*
  * restriction_is_securely_promotable
  *
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 35ab577501..72cf88dcbd 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -160,6 +160,22 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+/*
+ * Contains information needed to extract from saop a set of elements which can
+ * be covered by the partial index:
+ * id - caller's identification of the index.
+ * predicate - predicate expression of the index
+ * elems - returning list of array elements which corresponds to this predicate
+ */
+typedef struct PredicatesData
+{
+	int		id;
+	Node   *predicate;
+	List   *elems;
+} PredicatesData;
+
+extern bool saop_covered_by_predicates(ScalarArrayOpExpr *saop,
+									   List *predicate_lists);
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c5..2cd5fbf943 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -34,6 +34,7 @@ extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Relids outer_relids);
 extern RestrictInfo *commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op);
 extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
+extern bool restriction_is_saop_clause(RestrictInfo *restrictinfo);
 extern bool restriction_is_securely_promotable(RestrictInfo *restrictinfo,
 											   RelOptInfo *rel);
 extern List *get_actual_clauses(List *restrictinfo_list);
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e..81399ec5b1 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -907,6 +907,288 @@ select unique1, unique2 from onek2
        0 |     998
 (2 rows)
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: ((stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Without the transformation only seqscan possible here
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                         QUERY PLAN                                          
+---------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])) AND (stringu1 < 'Z'::name))
+(2 rows)
+
+-- Use partial indexes
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+                 QUERY PLAN                 
+--------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = 1) OR (unique2 = 3))
+(2 rows)
+
+RESET enable_or_transformation;
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = ANY ('{J}'::name[]))
+               ->  Bitmap Index Scan on onek2_u2_prtl
+(8 rows)
+
+-- Don't scan partial indexes because of extra value.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+                      QUERY PLAN                      
+------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on onek2
+         Filter: (stringu1 = ANY ('{A,J,C}'::name[]))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (stringu1 < 'B'::name)
+   Filter: ((stringu1 = ANY ('{A}'::name[])) AND (stringu1 = ANY ('{A,A}'::name[])))
+   ->  Bitmap Index Scan on onek2_u2_prtl
+(4 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                                          QUERY PLAN                                                           
+-------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name)) OR ((unique2 < 1) AND (stringu1 < 'B'::name)))
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: ((stringu1 = ANY ('{J}'::name[])) AND (stringu1 < 'Z'::name))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 < 1)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 = 1) OR (unique1 = 3))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 1)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 3)
+(7 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+                                                             QUERY PLAN                                                             
+------------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = ((random() * '2'::double precision))::integer) OR (unique1 = ((random() * '3'::double precision))::integer))
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+                                                           QUERY PLAN                                                            
+---------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: (unique1 = ANY (ARRAY[((random() * '2'::double precision))::integer, ((random() * '3'::double precision))::integer]))
+(2 rows)
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+                                                                                          QUERY PLAN                                                                                          
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name) OR ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[]))) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 = ANY ('{1,2,21}'::integer[])) AND ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 = ANY ('{3,4}'::integer[])) OR (stringu1 = 'J'::name)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: ((unique1 = ANY ('{3,4}'::integer[])) AND (unique1 = ANY ('{1,2,21}'::integer[])))
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(11 rows)
+
+-- Check recursive combination of OR and SAOP expressions
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 = ANY ('{J}'::name[])) OR (stringu1 < 'B'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = ANY ('{J}'::name[]))
+         ->  Bitmap Index Scan on onek2_u2_prtl
+(9 rows)
+
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+RESET enable_indexscan;
+RESET enable_seqscan;
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql
index 019f1e7673..223f55af4e 100644
--- a/src/test/regress/sql/select.sql
+++ b/src/test/regress/sql/select.sql
@@ -234,6 +234,88 @@ select unique1, unique2 from onek2
 select unique1, unique2 from onek2
   where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+-- Without the transformation only seqscan possible here
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+-- Use partial indexes
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+RESET enable_or_transformation;
+
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+
+-- Don't scan partial indexes because of extra value.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+EXPLAIN (COSTS OFF)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer); -- TODO: why it is differs from previous example?
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+
+-- Combine different saops. Soe of them doesnt' fit a set of partial indexes,
+-- but other fits.
+-- Unfortunately, we don't combine saop and OR clauses so far.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+
+-- Check recursive combination of OR and SAOP expressions
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+
+RESET enable_indexscan;
+RESET enable_seqscan;
+
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index c6027c588d..bac4e3c2c8 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2143,6 +2143,7 @@ PredIterInfoData
 PredXactList
 PredicateLockData
 PredicateLockTargetType
+PredicatesData
 PrefetchBufferResult
 PrepParallelRestorePtrType
 PrepareStmt
-- 
2.44.0

#167Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#166)
Re: POC, WIP: OR-clause support for indexes

On Wed, Mar 13, 2024 at 7:52 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 12/3/2024 22:20, Alexander Korotkov wrote:

On Mon, Mar 11, 2024 at 2:43 PM Andrei Lepikhov

I think you are right. It is probably a better place than any other to
remove duplicates in an array. I just think we should sort and remove
duplicates from entry->consts in one pass. Thus, this optimisation
should be applied to sortable constants.

Ok.

New version of the patch set implemented all we have agreed on for now.
We can return MAX_SAOP_ARRAY_SIZE constraint and Alena's approach to
duplicates deletion for non-sortable cases at the end.

Hmm, we already tried to do it at that point. I vaguely recall some
issues caused by this approach. Anyway, it should be done as quickly as
possible to increase the effect of the optimization.

I think there were provided quite strong reasons why this shouldn't be
implemented at the parse analysis stage [1], [2], [3]. The
canonicalize_qual() looks quite appropriate place for that since it
does similar transformations.

Ok. Let's discuss these reasons. In Robert's opinion [1,3], we should do
the transformation based on the cost model. But in the canonicalize_qual
routine, we still make the transformation blindly. Moreover, the second
patch reduces the weight of this reason, doesn't it? Maybe we shouldn't
think about that as about optimisation but some 'general form of
expression'?
Peter [2] worries about the possible transformation outcomes at this
stage. But remember, we already transform clauses like ROW() IN (...) to
a series of ORs here, so it is not an issue. Am I wrong?
Why did we discard the attempt with canonicalize_qual on the previous
iteration? - The stage of parsing is much more native for building SAOP
quals. We can reuse make_scalar_array_op and other stuff, for example.
During the optimisation stage, the only list partitioning machinery
creates SAOP based on a list of constants. So, in theory, it is possible
to implement. But do we really need to make the code more complex?

As we currently do OR-to-ANY transformation at the parse stage, the
system catalog (including views, inheritance clauses, partial and
expression indexes, and others) would have a form depending on
enable_or_transformation at the moment of DDL execution. I think this
is rather wrong. The enable_or_transformation should be run-time
optimization which affects the resulting query plan, its result
shouldn't be persistent.

Regarding the ROW() IN (...) precedent.

1. AFAICS, this is not exactly an optimization. This transformation
allows us to perform type matching individually for every value.
Therefore it allows the execute some queries which otherwise would end
up with error.
2. I don't think this is a sample of good design. This is rather
hack, which is historically here, but we don't want to replicate this
experience.

Given all of the above, I think moving transformation to the
canonicalize_qual() would be the right way to go.

------
Regards,
Alexander Korotkov

#168Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alexander Korotkov (#167)
Re: POC, WIP: OR-clause support for indexes

On 13/3/2024 18:05, Alexander Korotkov wrote:

On Wed, Mar 13, 2024 at 7:52 AM Andrei Lepikhov
Given all of the above, I think moving transformation to the
canonicalize_qual() would be the right way to go.

Ok, I will try to move the code.
I have no idea about the timings so far. I recall the last time I got
bogged down in tons of duplicated code. I hope with an almost-ready
sketch, it will be easier.

--
regards,
Andrei Lepikhov
Postgres Professional

#169Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#168)
Re: POC, WIP: OR-clause support for indexes

On Wed, Mar 13, 2024 at 2:16 PM Andrei Lepikhov <a.lepikhov@postgrespro.ru>
wrote:

On 13/3/2024 18:05, Alexander Korotkov wrote:

On Wed, Mar 13, 2024 at 7:52 AM Andrei Lepikhov
Given all of the above, I think moving transformation to the
canonicalize_qual() would be the right way to go.

Ok, I will try to move the code.
I have no idea about the timings so far. I recall the last time I got
bogged down in tons of duplicated code. I hope with an almost-ready
sketch, it will be easier.

Thank you! I'll be looking forward to the updated patch.

I also have notes about the bitmap patch.

/*
* Building index paths over SAOP clause differs from the logic of OR
clauses.
* Here we iterate across all the array elements and split them to SAOPs,
* corresponding to different indexes. We must match each element to an
index.
*/

This covers the case I posted before. But in order to fix all possible
cases we probably need to handle the SAOP clause in the same way as OR
clauses. Check also this case.

Setup
create table t (a int not null, b int not null, c int not null);
insert into t (select 1, 1, i from generate_series(1,10000) i);
insert into t (select i, 2, 2 from generate_series(1,10000) i);
create index t_a_b_idx on t (a, b);
create statistics t_a_b_stat (mcv) on a, b from t;
create statistics t_b_c_stat (mcv) on b, c from t;
vacuum analyze t;

Plan with enable_or_transformation = on:
# explain select * from t where a = 1 and (b = 1 or b = 2) and c = 2;
QUERY PLAN
------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=156.55..440.56 rows=5001 width=12)
Recheck Cond: (a = 1)
Filter: ((b = ANY ('{1,2}'::integer[])) AND (c = 2))
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..155.29 rows=10001
width=0)
Index Cond: (a = 1)
(5 rows)

Plan with enable_or_transformation = off:
# explain select * from t where a = 1 and (b = 1 or b = 2) and c = 2;
QUERY PLAN
------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=11.10..18.32 rows=5001 width=12)
Recheck Cond: (((b = 1) AND (c = 2)) OR ((a = 1) AND (b = 2)))
Filter: ((a = 1) AND (c = 2))
-> BitmapOr (cost=11.10..11.10 rows=2 width=0)
-> Bitmap Index Scan on t_b_c_idx (cost=0.00..4.30 rows=1
width=0)
Index Cond: ((b = 1) AND (c = 2))
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..4.30 rows=1
width=0)
Index Cond: ((a = 1) AND (b = 2))
(8 rows)

As you can see this case is not related to partial indexes. Just no index
selective for the whole query. However, splitting scan by the OR qual lets
use a combination of two selective indexes.

------
Regards,
Alexander Korotkov

#170Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alexander Korotkov (#169)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 14/3/2024 16:31, Alexander Korotkov wrote:

On Wed, Mar 13, 2024 at 2:16 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru <mailto:a.lepikhov@postgrespro.ru>> wrote:

On 13/3/2024 18:05, Alexander Korotkov wrote:

On Wed, Mar 13, 2024 at 7:52 AM Andrei Lepikhov
Given all of the above, I think moving transformation to the
canonicalize_qual() would be the right way to go.

Ok, I will try to move the code.
I have no idea about the timings so far. I recall the last time I got
bogged down in tons of duplicated code. I hope with an almost-ready
sketch, it will be easier.

Thank you!  I'll be looking forward to the updated patch.

Okay, I moved the 0001-* patch to the prepqual.c module. See it in the
attachment. I treat it as a transient patch.
It has positive outcomes as well as negative ones.
The most damaging result you can see in the partition_prune test:
partition pruning, in some cases, moved to the executor initialization
stage. I guess, we should avoid it somehow in the next version.

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v22-1-0001-Transform-OR-clauses-to-ANY-expression.patchtext/plain; charset=UTF-8; name=v22-1-0001-Transform-OR-clauses-to-ANY-expression.patchDownload
From 170f6871540025d0d1683750442e7af902b11a40 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Fri, 2 Feb 2024 22:01:09 +0300
Subject: [PATCH 1/2] Transform OR clauses to ANY expression.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...]) on the
preliminary stage of optimization when we are still working with the
expression tree.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
---
 .../postgres_fdw/expected/postgres_fdw.out    |   8 +-
 doc/src/sgml/config.sgml                      |  17 +
 src/backend/nodes/queryjumblefuncs.c          |  27 ++
 src/backend/optimizer/prep/prepqual.c         | 371 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  11 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/include/nodes/queryjumble.h               |   1 +
 src/include/optimizer/optimizer.h             |   2 +
 src/test/regress/expected/create_index.out    | 156 +++++++-
 src/test/regress/expected/join.out            |  62 ++-
 src/test/regress/expected/partition_prune.out | 235 +++++++++--
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  19 +-
 src/test/regress/sql/create_index.sql         |  35 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 19 files changed, 939 insertions(+), 61 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 58a603ac56..a965b43cc6 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8838,18 +8838,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 65a6e6c408..2de6ae301a 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5472,6 +5472,23 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-enable-or-transformation" xreflabel="enable_or_transformation">
+      <term><varname>enable_or_transformation</varname> (<type>boolean</type>)
+       <indexterm>
+        <primary><varname>enable_or_transformation</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      <listitem>
+       <para>
+        Enables or disables the query planner's ability to lookup and group multiple
+        similar OR expressions to ANY (<xref linkend="functions-comparisons-any-some"/>) expressions.
+        The grouping technique of this transformation is based on the equivalence of variable sides.
+        One side of such an expression must be a constant clause, and the other must contain a variable clause.
+        The default is <literal>on</literal>.
+        </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-enable-parallel-append" xreflabel="enable_parallel_append">
       <term><varname>enable_parallel_append</varname> (<type>boolean</type>)
       <indexterm>
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 2c116c8728..0c5b4a011b 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -141,6 +141,33 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/optimizer/prep/prepqual.c b/src/backend/optimizer/prep/prepqual.c
index cbcf83f847..7ee585dc89 100644
--- a/src/backend/optimizer/prep/prepqual.c
+++ b/src/backend/optimizer/prep/prepqual.c
@@ -31,16 +31,25 @@
 
 #include "postgres.h"
 
+#include "catalog/namespace.h"
+#include "catalog/pg_operator.h"
+#include "common/hashfn.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 
+bool		enable_or_transformation = true;
 
 static List *pull_ands(List *andlist);
 static List *pull_ors(List *orlist);
 static Expr *find_duplicate_ors(Expr *qual, bool is_check);
 static Expr *process_duplicate_ors(List *orlist);
+static List *or_transformation(List *orlist);
 
 
 /*
@@ -266,6 +275,354 @@ negate_clause(Node *node)
 	return (Node *) make_notclause((Expr *) node);
 }
 
+typedef struct OrClauseGroupKey
+{
+	NodeTag	type;
+
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		consttype;
+	Oid		inputcollid; /* XXX: Could we lookup for common collation? */
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey	key;
+
+	List			   *consts;
+	List 			   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function to find candidate clauses.
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				exprHash;
+
+	Assert(keysize == sizeof(OrClauseGroupKey));
+	Assert(IsA(data, Invalid));
+
+	(void) JumbleExpr(key->expr, &exprHash);
+
+	return hash_combine((uint32) exprHash,
+						hash_combine((uint32) key->opno,
+							hash_combine((uint32) key->consttype,
+										 (uint32) key->inputcollid)));
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(src, Invalid));
+
+	dst_key->type = T_Invalid;
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->consttype = src_key->consttype;
+	dst_key->inputcollid = src_key->inputcollid;
+
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in or_group_htab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(key1, Invalid));
+	Assert(IsA(key2, Invalid));
+
+	if (key1->opno == key2->opno &&
+		key1->consttype == key2->consttype &&
+		key1->inputcollid == key2->inputcollid &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+/*
+ * or_transformation -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to an ANY operation.
+ *	  Transformation must be already done on input args list before the call.
+ *	  Transformation groups two-sided equality operations. One side of such an
+ *	  operation must be plain constant or constant expression. The other side of
+ *	  the clause must be a variable expression without volatile functions.
+ *	  The grouping technique is based on an equivalence of variable sides of the
+ *	  expression: using queryId and equal() routine, it groups constant sides of
+ *	  similar clauses into an array. After the grouping procedure, each couple
+ *	  ('variable expression' and 'constant array') form a new SAOP operation,
+ *	  which is added to the args list of the returning expression.
+ *
+ *	  NOTE: function returns OR BoolExpr if more than one clause are detected in
+ *	  the final args list, or ScalarArrayOpExpr if all args were grouped into
+ *	  the single SAOP expression.
+ */
+static List *
+or_transformation(List *orlist)
+{
+	List				   *neworlist = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(orlist);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	Assert(enable_or_transformation && len_ors > 1);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, orlist)
+	{
+		Node				   *orqual = lfirst(lc);
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Oid						consttype;
+		Node				   *leftop, *rightop;
+
+		if (!IsA(orqual, OpExpr))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				entries = lappend(entries, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		 * Transformation only works with both side type is not
+		 * { array | composite | domain | record }.
+		 * Also, forbid it for volatile expressions.
+		 */
+		consttype = exprType(const_expr);
+		if (type_is_rowtype(exprType(const_expr)) ||
+			type_is_rowtype(consttype) ||
+			contain_volatile_functions((Node *) nconst_expr))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.type = T_Invalid;
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.consttype = consttype;
+		hashkey.inputcollid = exprCollation(const_expr);
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		if (!IsA(lfirst(lc), Invalid))
+		{
+			neworlist = lappend(neworlist, lfirst(lc));
+			continue;
+		}
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element returns origin expression into the BoolExpr args
+			 * list unchanged.
+			 */
+			list_free(entry->consts);
+			neworlist = list_concat(neworlist, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.consttype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+											   InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+
+			foreach(lc, entry->consts)
+			{
+				Node *node = (Node *) lfirst(lc);
+
+				node = coerce_to_common_type(NULL, node, scalar_type,
+											 "OR ANY Transformation");
+				aexprs = lappend(aexprs, node);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(NULL,
+										 namelist,
+										 true,
+										 (Node *) entry->key.expr,
+										 (Node *) newa,
+										 -1);
+			saopexpr->inputcollid = entry->key.inputcollid;
+
+			neworlist = lappend(neworlist, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
+			 */
+			list_free(entry->consts);
+			neworlist = list_concat(neworlist, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return neworlist;
+}
 
 /*
  * canonicalize_qual
@@ -604,7 +961,15 @@ process_duplicate_ors(List *orlist)
 	 * If no winners, we can't transform the OR
 	 */
 	if (winners == NIL)
-		return make_orclause(orlist);
+	{
+		/* Make an attempt to group similar OR clauses into ANY operation */
+		if (enable_or_transformation && list_length(orlist) > 1)
+			orlist = or_transformation(orlist);
+
+		/* Transformation could group all OR clauses to a single SAOP */
+		return (list_length(orlist) == 1) ?
+							(Expr *) linitial(orlist) : make_orclause(orlist);
+	}
 
 	/*
 	 * Generate new OR list consisting of the remaining sub-clauses.
@@ -651,6 +1016,10 @@ process_duplicate_ors(List *orlist)
 		}
 	}
 
+	/* Make an attempt to group similar OR clauses into ANY operation */
+	if (enable_or_transformation && list_length(neworlist) > 1)
+		neworlist = or_transformation(neworlist);
+
 	/*
 	 * Append reduced OR to the winners list, if it's not degenerate, handling
 	 * the special case of one element correctly (can that really happen?).
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 57d9de4dd9..d4f082ec62 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1026,6 +1026,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an array expression."),
+			gettext_noop("The planner will replace expression like 'x=c1 OR x=c2 ..'"
+						 "to the expression 'x = ANY(ARRAY[c1,c2,..])'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 2244ee52f7..524516593f 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -391,6 +391,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067..a9ae048af5 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 7b63c5cf71..32eec0b27c 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -133,6 +133,8 @@ extern void extract_query_dependencies(Node *query,
 
 /* in prep/prepqual.c: */
 
+extern PGDLLIMPORT bool enable_or_transformation;
+
 extern Node *negate_clause(Node *node);
 extern Expr *canonicalize_qual(Expr *qual, bool is_check);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 70ab47a92f..d144aeec2a 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                               QUERY PLAN                               
+------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, 3, 42])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                 QUERY PLAN                                  
+-----------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY (ARRAY[42, 99])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY (ARRAY[42, 99]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                               QUERY PLAN                               
+------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, 3, 42])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,116 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                 QUERY PLAN                                  
+-----------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY (ARRAY[42, 99])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY (ARRAY[42, 99]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY (ARRAY[42, 99, 43, 42])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY (ARRAY[42, 99, 43, 42]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                           QUERY PLAN                                            
+-------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY (ARRAY[1, 3]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, 3])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY (ARRAY[42, 99])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY (ARRAY[42, 99]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND ((thousand = ANY (ARRAY[42, 41])) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: (thousand = ANY (ARRAY[42, 41]))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9605400021..3368629c9c 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                   QUERY PLAN                                                    
+-----------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY (ARRAY[3, 7])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY (ARRAY[3, 7])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY (ARRAY[3, 7]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                   QUERY PLAN                                                    
+-----------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY (ARRAY[3, 7])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY (ARRAY[3, 7])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY (ARRAY[3, 7]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                       QUERY PLAN                                                                       
+--------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY (ARRAY[3, 7])) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY (ARRAY[3, 7])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY (ARRAY[3, 7]))
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index bf0657b9f2..ce6d6f40fb 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,51 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
+   Subplans Removed: 4
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
-(5 rows)
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(6 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
+   Subplans Removed: 3
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
-(5 rows)
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(6 rows)
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   Subplans Removed: 4
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(6 rows)
 
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   Subplans Removed: 3
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(6 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,11 +541,13 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
- Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
-(2 rows)
+                   QUERY PLAN                   
+------------------------------------------------
+ Append
+   Subplans Removed: 1
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (a = ANY ('{1,7}'::integer[]))
+(4 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
                       QUERY PLAN                       
@@ -596,14 +624,15 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
+   Subplans Removed: 2
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
-(5 rows)
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(6 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
         QUERY PLAN        
@@ -671,6 +700,166 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                   QUERY PLAN                   
+------------------------------------------------
+ Append
+   Subplans Removed: 1
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (a = ANY ('{1,7}'::integer[]))
+(4 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   Subplans Removed: 2
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(6 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -2072,10 +2261,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 10903bdab0..6f55b9e3ec 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 9be7aca2b8..1f9029b5b2 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -124,6 +124,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -134,7 +135,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(23 rows)
+(24 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..4782cb3e06 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -46,7 +46,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
                           QUERY PLAN                          
 --------------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY (ARRAY['(0,2)'::tid, '(0,1)'::tid]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +56,23 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                          QUERY PLAN                          
+--------------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY (ARRAY['(0,2)'::tid, '(0,1)'::tid]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..56fde15bc1 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index c4c6c7b8ba..1663608043 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index a09b27d820..9717c8c835 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index aa7a25b8f8..c6027c588d 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1657,6 +1657,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.44.0

#171Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#170)
Re: POC, WIP: OR-clause support for indexes

On Thu, Mar 14, 2024 at 12:11 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 14/3/2024 16:31, Alexander Korotkov wrote:

On Wed, Mar 13, 2024 at 2:16 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru <mailto:a.lepikhov@postgrespro.ru>> wrote:

On 13/3/2024 18:05, Alexander Korotkov wrote:

On Wed, Mar 13, 2024 at 7:52 AM Andrei Lepikhov
Given all of the above, I think moving transformation to the
canonicalize_qual() would be the right way to go.

Ok, I will try to move the code.
I have no idea about the timings so far. I recall the last time I got
bogged down in tons of duplicated code. I hope with an almost-ready
sketch, it will be easier.

Thank you! I'll be looking forward to the updated patch.

Okay, I moved the 0001-* patch to the prepqual.c module. See it in the
attachment. I treat it as a transient patch.
It has positive outcomes as well as negative ones.
The most damaging result you can see in the partition_prune test:
partition pruning, in some cases, moved to the executor initialization
stage. I guess, we should avoid it somehow in the next version.

Thank you, Andrei. Looks like a very undesirable side effect. Do you
have any idea why it happens? Partition pruning should work correctly
for both transformed and non-transformed quals, why does
transformation hurt it?

------
Regards,
Alexander Korotkov

#172Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alexander Korotkov (#171)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 14/3/2024 17:39, Alexander Korotkov wrote:

Thank you, Andrei. Looks like a very undesirable side effect. Do you
have any idea why it happens? Partition pruning should work correctly
for both transformed and non-transformed quals, why does
transformation hurt it?

Now we have the v23-0001-* patch with all issues resolved. The last one
which caused execution stage pruning was about necessity to evaluate
SAOP expression right after transformation. In previous version the core
executed it on transformed expressions.

As you can see this case is not related to partial indexes. Just no
index selective for the whole query. However, splitting scan by the
OR qual lets use a combination of two selective indexes.

Thanks for the case. I will try to resolve it.

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v23-0001-Transform-OR-clauses-to-ANY-expression.patchtext/plain; charset=UTF-8; name=v23-0001-Transform-OR-clauses-to-ANY-expression.patchDownload
From 156c00c820a38e5e1856f07363af87b3109b5d77 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Fri, 2 Feb 2024 22:01:09 +0300
Subject: [PATCH 1/2] Transform OR clauses to ANY expression.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...]) on the
preliminary stage of optimization when we are still working with the
expression tree.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
---
 .../postgres_fdw/expected/postgres_fdw.out    |   8 +-
 doc/src/sgml/config.sgml                      |  17 +
 src/backend/nodes/queryjumblefuncs.c          |  27 ++
 src/backend/optimizer/prep/prepqual.c         | 374 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  11 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/include/nodes/queryjumble.h               |   1 +
 src/include/optimizer/optimizer.h             |   2 +
 src/test/regress/expected/create_index.out    | 156 +++++++-
 src/test/regress/expected/join.out            |  62 ++-
 src/test/regress/expected/partition_prune.out | 215 +++++++++-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/sysviews.out        |   3 +-
 src/test/regress/expected/tidscan.out         |  23 +-
 src/test/regress/sql/create_index.sql         |  35 ++
 src/test/regress/sql/join.sql                 |  10 +
 src/test/regress/sql/partition_prune.sql      |  22 ++
 src/test/regress/sql/tidscan.sql              |   6 +
 src/tools/pgindent/typedefs.list              |   2 +
 19 files changed, 929 insertions(+), 58 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 58a603ac56..a965b43cc6 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8838,18 +8838,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 65a6e6c408..2de6ae301a 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5472,6 +5472,23 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-enable-or-transformation" xreflabel="enable_or_transformation">
+      <term><varname>enable_or_transformation</varname> (<type>boolean</type>)
+       <indexterm>
+        <primary><varname>enable_or_transformation</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      <listitem>
+       <para>
+        Enables or disables the query planner's ability to lookup and group multiple
+        similar OR expressions to ANY (<xref linkend="functions-comparisons-any-some"/>) expressions.
+        The grouping technique of this transformation is based on the equivalence of variable sides.
+        One side of such an expression must be a constant clause, and the other must contain a variable clause.
+        The default is <literal>on</literal>.
+        </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-enable-parallel-append" xreflabel="enable_parallel_append">
       <term><varname>enable_parallel_append</varname> (<type>boolean</type>)
       <indexterm>
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 2c116c8728..0c5b4a011b 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -141,6 +141,33 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/optimizer/prep/prepqual.c b/src/backend/optimizer/prep/prepqual.c
index cbcf83f847..a127dafec7 100644
--- a/src/backend/optimizer/prep/prepqual.c
+++ b/src/backend/optimizer/prep/prepqual.c
@@ -31,16 +31,25 @@
 
 #include "postgres.h"
 
+#include "catalog/namespace.h"
+#include "catalog/pg_operator.h"
+#include "common/hashfn.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 
+bool		enable_or_transformation = true;
 
 static List *pull_ands(List *andlist);
 static List *pull_ors(List *orlist);
 static Expr *find_duplicate_ors(Expr *qual, bool is_check);
 static Expr *process_duplicate_ors(List *orlist);
+static List *or_transformation(List *orlist);
 
 
 /*
@@ -266,6 +275,357 @@ negate_clause(Node *node)
 	return (Node *) make_notclause((Expr *) node);
 }
 
+typedef struct OrClauseGroupKey
+{
+	NodeTag	type;
+
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		consttype;
+	Oid		inputcollid; /* XXX: Could we lookup for common collation? */
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey	key;
+
+	List			   *consts;
+	List 			   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function to find candidate clauses.
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				exprHash;
+
+	Assert(keysize == sizeof(OrClauseGroupKey));
+	Assert(IsA(data, Invalid));
+
+	(void) JumbleExpr(key->expr, &exprHash);
+
+	return hash_combine((uint32) exprHash,
+						hash_combine((uint32) key->opno,
+							hash_combine((uint32) key->consttype,
+										 (uint32) key->inputcollid)));
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(src, Invalid));
+
+	dst_key->type = T_Invalid;
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->consttype = src_key->consttype;
+	dst_key->inputcollid = src_key->inputcollid;
+
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in or_group_htab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(key1, Invalid));
+	Assert(IsA(key2, Invalid));
+
+	if (key1->opno == key2->opno &&
+		key1->consttype == key2->consttype &&
+		key1->inputcollid == key2->inputcollid &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+/*
+ * or_transformation -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to an SAOP operation.
+ *	  Transformation groups two-sided equality operations. One side of such an
+ *	  operation must be plain constant or constant expression. The other side of
+ *	  the clause must be a variable expression without volatile functions.
+ *	  To group quals, inputcollid, opno and constype of the OR OpExpr quals must
+ *	  be equal too.
+ *	  The grouping technique is based on an equivalence of variable sides of the
+ *	  expression: using queryId and equal() routine, it groups constant sides of
+ *	  similar clauses into an array. After the grouping procedure, each couple
+ *	  ('variable expression' and 'constant array') form a new SAOP operation,
+ *	  which is added to the args list of the returning expression.
+ */
+static List *
+or_transformation(List *orlist)
+{
+	List				   *neworlist = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(orlist);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	Assert(enable_or_transformation && len_ors > 1);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, orlist)
+	{
+		Node				   *orqual = lfirst(lc);
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Oid						consttype;
+		Node				   *leftop, *rightop;
+
+		if (!IsA(orqual, OpExpr))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				entries = lappend(entries, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		 * Transformation only works with both side type is not
+		 * { array | composite | domain | record }.
+		 * Also, forbid it for volatile expressions.
+		 */
+		consttype = exprType(const_expr);
+		if (type_is_rowtype(exprType(const_expr)) ||
+			type_is_rowtype(consttype) ||
+			contain_volatile_functions((Node *) nconst_expr))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.type = T_Invalid;
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.consttype = consttype;
+		hashkey.inputcollid = exprCollation(const_expr);
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		if (!IsA(lfirst(lc), Invalid))
+		{
+			neworlist = lappend(neworlist, lfirst(lc));
+			continue;
+		}
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element returns origin expression into the BoolExpr args
+			 * list unchanged.
+			 */
+			list_free(entry->consts);
+			neworlist = list_concat(neworlist, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.consttype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+											   InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+
+			foreach(lc, entry->consts)
+			{
+				Node *node = (Node *) lfirst(lc);
+
+				node = coerce_to_common_type(NULL, node, scalar_type,
+											 "OR ANY Transformation");
+				aexprs = lappend(aexprs, node);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			/*
+			 * Try to cast this expression to Const. Due to current strict
+			 * transformation rules it should be done [almost] every time.
+			 */
+			newa = (ArrayExpr *) eval_const_expressions(NULL, (Node *) newa);
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(NULL,
+										 namelist,
+										 true,
+										 (Node *) entry->key.expr,
+										 (Node *) newa,
+										 -1);
+			saopexpr->inputcollid = entry->key.inputcollid;
+
+			neworlist = lappend(neworlist, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
+			 */
+			list_free(entry->consts);
+			neworlist = list_concat(neworlist, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return neworlist;
+}
 
 /*
  * canonicalize_qual
@@ -604,7 +964,15 @@ process_duplicate_ors(List *orlist)
 	 * If no winners, we can't transform the OR
 	 */
 	if (winners == NIL)
-		return make_orclause(orlist);
+	{
+		/* Make an attempt to group similar OR clauses into ANY operation */
+		if (enable_or_transformation && list_length(orlist) > 1)
+			orlist = or_transformation(orlist);
+
+		/* Transformation could group all OR clauses to a single SAOP */
+		return (list_length(orlist) == 1) ?
+							(Expr *) linitial(orlist) : make_orclause(orlist);
+	}
 
 	/*
 	 * Generate new OR list consisting of the remaining sub-clauses.
@@ -651,6 +1019,10 @@ process_duplicate_ors(List *orlist)
 		}
 	}
 
+	/* Make an attempt to group similar OR clauses into ANY operation */
+	if (enable_or_transformation && list_length(neworlist) > 1)
+		neworlist = or_transformation(neworlist);
+
 	/*
 	 * Append reduced OR to the winners list, if it's not degenerate, handling
 	 * the special case of one element correctly (can that really happen?).
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 57d9de4dd9..d4f082ec62 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1026,6 +1026,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an array expression."),
+			gettext_noop("The planner will replace expression like 'x=c1 OR x=c2 ..'"
+						 "to the expression 'x = ANY(ARRAY[c1,c2,..])'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 2244ee52f7..524516593f 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -391,6 +391,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#enable_or_transformation = on
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067..a9ae048af5 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 7b63c5cf71..32eec0b27c 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -133,6 +133,8 @@ extern void extract_query_dependencies(Node *query,
 
 /* in prep/prepqual.c: */
 
+extern PGDLLIMPORT bool enable_or_transformation;
+
 extern Node *negate_clause(Node *node);
 extern Expr *canonicalize_qual(Expr *qual, bool is_check);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 70ab47a92f..66e9a395e0 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1838,18 +1838,50 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1861,28 +1893,116 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND ((thousand = ANY ('{42,41}'::integer[])) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET enable_or_transformation;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9605400021..d8018bef4f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index bf0657b9f2..1e153c3bb5 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +618,13 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -2072,10 +2251,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 10903bdab0..6f55b9e3ec 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 9be7aca2b8..1f9029b5b2 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -124,6 +124,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
@@ -134,7 +135,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_seqscan                 | on
  enable_sort                    | on
  enable_tidscan                 | on
-(23 rows)
+(24 rows)
 
 -- There are always wait event descriptions for various types.
 select type, count(*) > 0 as ok FROM pg_wait_events
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..2a079e996b 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,26 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
@@ -56,6 +72,7 @@ SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  (0,2) |  2
 (2 rows)
 
+RESET enable_or_transformation;
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..56fde15bc1 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index c4c6c7b8ba..1663608043 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index a09b27d820..9717c8c835 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..0499bedb9e 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index aa7a25b8f8..c6027c588d 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1657,6 +1657,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.44.0

#173Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alexander Korotkov (#169)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 14/3/2024 16:31, Alexander Korotkov wrote:

On Wed, Mar 13, 2024 at 2:16 PM Andrei Lepikhov
As you can see this case is not related to partial indexes.  Just no
index selective for the whole query.  However, splitting scan by the OR
qual lets use a combination of two selective indexes.

I have rewritten the 0002-* patch according to your concern. A candidate
and some thoughts are attached.
As I see, we have a problem here: expanding each array and trying to
apply an element to each index can result in a lengthy planning stage.
Also, an index scan with the SAOP may potentially be more effective than
with the list of OR clauses.
Originally, the transformation's purpose was to reduce a query's
complexity and the number of optimization ways to speed up planning and
(sometimes) execution. Here, we reduce planning complexity only in the
case of an array size larger than MAX_SAOP_ARRAY_SIZE.
Maybe we can fall back to the previous version of the second patch,
keeping in mind that someone who wants to get maximum profit from the
BitmapOr scan of multiple indexes can just disable this optimization,
enabling deep search of the most optimal scanning way?
As a compromise solution, I propose adding one more option to the
previous version: if an element doesn't fit any partial index, try to
cover it with a plain index.
In this case, we still do not guarantee the most optimal fit of elements
to the set of indexes, but we speed up planning. Does that make sense?

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v22-1-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchtext/plain; charset=UTF-8; name=v22-1-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchDownload
From d2d8944fc83ccd090653c1b15703a2c3ba096fa9 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Wed, 13 Mar 2024 12:26:02 +0700
Subject: [PATCH 2/2] Teach generate_bitmap_or_paths to build BitmapOr paths
 over SAOP clauses.

Likewise OR clauses, discover SAOP array and try to split its elements
between smaller sized arrays to fit a set of partial indexes.
---
 doc/src/sgml/config.sgml                   |   3 +
 src/backend/optimizer/path/indxpath.c      |  74 +++++-
 src/backend/optimizer/util/predtest.c      |  37 +++
 src/backend/optimizer/util/restrictinfo.c  |  13 +
 src/include/optimizer/optimizer.h          |   3 +
 src/include/optimizer/restrictinfo.h       |   1 +
 src/test/regress/expected/create_index.out |  24 +-
 src/test/regress/expected/select.out       | 280 +++++++++++++++++++++
 src/test/regress/sql/select.sql            |  82 ++++++
 9 files changed, 500 insertions(+), 17 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 2de6ae301a..0df56f44e3 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5485,6 +5485,9 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
         The grouping technique of this transformation is based on the equivalence of variable sides.
         One side of such an expression must be a constant clause, and the other must contain a variable clause.
         The default is <literal>on</literal>.
+        Also, during BitmapScan paths generation it enables analysis of elements
+        of IN or ANY constant arrays to cover such clause with BitmapOr set of
+        partial index scans.
         </para>
       </listitem>
      </varlistentry>
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 32c6a8bbdc..96685429de 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,6 +32,7 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
 
@@ -1220,11 +1221,66 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Expand SAOP node to use it in bitmapscan path building routine.
+ *
+ * If RestrictInfo is an OR bool expression, extract each SAOP from the list of
+ * arguments, if possible.
+ * Working jointly with the TransformOrExprToANY routine, it provides a user
+ * with some sort of independence of the query plan from the approach to writing
+ * alternatives for the same entity in the WHERE section.
+ */
+static List *
+extract_saop_ors(PlannerInfo *root, RestrictInfo *rinfo)
+{
+	List		   *orlist = NIL;
+	List		   *result = NIL;
+	ListCell	   *lc;
+
+	Assert(IsA(rinfo, RestrictInfo));
+
+	if (restriction_is_or_clause(rinfo))
+		orlist = ((BoolExpr *) rinfo->orclause)->args;
+
+	if (!enable_or_transformation)
+		return orlist;
+
+	if (restriction_is_saop_clause(rinfo))
+	{
+		result = transform_saop_to_ors(root, rinfo);
+		return (result == NIL) ? list_make1(rinfo) : result;
+	}
+
+	foreach(lc, orlist)
+	{
+		Expr *expr = (Expr *) lfirst(lc);
+
+		if (IsA(expr, RestrictInfo) && restriction_is_saop_clause((RestrictInfo *) expr))
+		{
+			List *sublist;
+
+			sublist = extract_saop_ors(root, (RestrictInfo *) lfirst(lc));
+			if (sublist != NIL)
+			{
+				result = list_concat(result, sublist);
+				continue;
+			}
+
+			/* Need to return expr to the result list */
+		}
+
+		result = lappend(result, expr);
+	}
+
+	return result;
+}
+
 /*
  * generate_bitmap_or_paths
- *		Look through the list of clauses to find OR clauses, and generate
- *		a BitmapOrPath for each one we can handle that way.  Return a list
- *		of the generated BitmapOrPaths.
+ *		Look through the list of clauses to find OR and SAOP clauses, and
+ *		Each saop clause are splitted to be covered by partial indexes.
+ *		generate a BitmapOrPath for each one we can handle that way.
+ *		Return a list of the generated BitmapOrPaths.
  *
  * other_clauses is a list of additional clauses that can be assumed true
  * for the purpose of generating indexquals, but are not to be searched for
@@ -1247,20 +1303,24 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	foreach(lc, clauses)
 	{
 		RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
-		List	   *pathlist;
+		List	   *pathlist = NIL;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *orlist = NIL;
 
-		/* Ignore RestrictInfos that aren't ORs */
-		if (!restriction_is_or_clause(rinfo))
+		orlist = extract_saop_ors(root, rinfo);
+		if (orlist == NIL)
+			/* Ignore RestrictInfo that doesn't provide ORs */
 			continue;
 
+		all_clauses = list_delete(all_clauses, rinfo);
+
 		/*
 		 * We must be able to match at least one index to each of the arms of
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		foreach(j, orlist)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index c37b416e24..e159493a21 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -111,6 +111,43 @@ static bool operator_same_subexprs_lookup(Oid pred_op, Oid clause_op,
 static Oid	get_btree_test_op(Oid pred_op, Oid clause_op, bool refute_it);
 static void InvalidateOprProofCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
 
+/*
+ * Expand a SAOP operation into the list of OR expressions
+ */
+List *
+transform_saop_to_ors(PlannerInfo *root, RestrictInfo *rinfo)
+{
+	PredIterInfoData	clause_info;
+	List			   *orlist = NIL;
+	Node			   *saop = (Node *) rinfo->clause;
+
+	Assert(IsA(saop, ScalarArrayOpExpr));
+
+	if (predicate_classify(saop, &clause_info) != CLASS_OR)
+		return NIL;
+
+	iterate_begin(pitem, saop, clause_info)
+	{
+		RestrictInfo   *rinfo1;
+
+		/* Predicate is found. Add the elem to the saop clause */
+		Assert(IsA(pitem, OpExpr));
+
+		/* Extract constant from the expression */
+		rinfo1 = make_restrictinfo(root, (Expr *) copyObject(pitem),
+								   rinfo->is_pushed_down,
+								   rinfo->has_clone, rinfo->is_clone,
+								   rinfo->pseudoconstant,
+								   rinfo->security_level,
+								   rinfo->required_relids,
+								   rinfo->incompatible_relids,
+								   rinfo->outer_relids);
+		orlist = lappend(orlist, rinfo1);
+	}
+	iterate_end(clause_info);
+
+	return orlist;
+}
 
 /*
  * predicate_implied_by
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e9334..1dad1dc654 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -421,6 +421,19 @@ restriction_is_or_clause(RestrictInfo *restrictinfo)
 		return false;
 }
 
+bool
+restriction_is_saop_clause(RestrictInfo *restrictinfo)
+{
+	if (restrictinfo->clause && IsA(restrictinfo->clause, ScalarArrayOpExpr))
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) restrictinfo->clause;
+
+		if (saop->useOr)
+			return true;
+	}
+	return false;
+}
+
 /*
  * restriction_is_securely_promotable
  *
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 32eec0b27c..492368d9e2 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -23,6 +23,7 @@
 #define OPTIMIZER_H
 
 #include "nodes/parsenodes.h"
+#include "optimizer/restrictinfo.h"
 
 /*
  * We don't want to include nodes/pathnodes.h here, because non-planner
@@ -161,6 +162,8 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+
+extern List *transform_saop_to_ors(PlannerInfo *root, RestrictInfo *rinfo);
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c5..2cd5fbf943 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -34,6 +34,7 @@ extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Relids outer_relids);
 extern RestrictInfo *commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op);
 extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
+extern bool restriction_is_saop_clause(RestrictInfo *restrictinfo);
 extern bool restriction_is_securely_promotable(RestrictInfo *restrictinfo,
 											   RelOptInfo *rel);
 extern List *get_actual_clauses(List *restrictinfo_list);
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 66e9a395e0..3f57d5c968 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1952,23 +1952,25 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                         QUERY PLAN                                                          
------------------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(14 rows)
+(16 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -1980,20 +1982,22 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                          QUERY PLAN                                                          
-------------------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = ANY ('{42,41}'::integer[])) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+                           Index Cond: (thousand = 42)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(11 rows)
+(13 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e..d0352a054c 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -907,6 +907,286 @@ select unique1, unique2 from onek2
        0 |     998
 (2 rows)
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: ((stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Without the transformation only seqscan possible here
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                         QUERY PLAN                                          
+---------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])) AND (stringu1 < 'Z'::name))
+(2 rows)
+
+-- Use partial indexes
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+                 QUERY PLAN                 
+--------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = 1) OR (unique2 = 3))
+(2 rows)
+
+RESET enable_or_transformation;
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Don't scan partial indexes because of extra value.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+                      QUERY PLAN                      
+------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on onek2
+         Filter: (stringu1 = ANY ('{A,J,C}'::name[]))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+                                QUERY PLAN                                 
+---------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (stringu1 < 'B'::name)
+   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = 'A'::name))
+   ->  Bitmap Index Scan on onek2_u2_prtl
+(4 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                                     QUERY PLAN                                                      
+---------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (((unique2 < 1) AND (stringu1 < 'B'::name)) OR ((stringu1 = 'J'::name) AND (stringu1 < 'Z'::name)))
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 < 1)
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: ((stringu1 = 'J'::name) AND (stringu1 < 'Z'::name))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer);
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+                                                             QUERY PLAN                                                             
+------------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = ((random() * '2'::double precision))::integer) OR (unique1 = ((random() * '3'::double precision))::integer))
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+                                                           QUERY PLAN                                                            
+---------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: (unique1 = ANY (ARRAY[((random() * '2'::double precision))::integer, ((random() * '3'::double precision))::integer]))
+(2 rows)
+
+-- Combine different saops. Some of them doesnt' fit a set of partial indexes,
+-- but other fits.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+                                                                           QUERY PLAN                                                                           
+----------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name) OR (unique1 = 3) OR (unique1 = 4) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 = ANY ('{1,2,21}'::integer[])) AND ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 = ANY ('{3,4}'::integer[])) OR (stringu1 = 'J'::name)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 3)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 4)
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(13 rows)
+
+-- Check recursive combination of OR and SAOP expressions
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+RESET enable_indexscan;
+RESET enable_seqscan;
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql
index 019f1e7673..37685694e6 100644
--- a/src/test/regress/sql/select.sql
+++ b/src/test/regress/sql/select.sql
@@ -234,6 +234,88 @@ select unique1, unique2 from onek2
 select unique1, unique2 from onek2
   where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET enable_or_transformation = 'off';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+-- Without the transformation only seqscan possible here
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+-- Use partial indexes
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+RESET enable_or_transformation;
+
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+
+-- Don't scan partial indexes because of extra value.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+EXPLAIN (COSTS OFF)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer);
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+
+-- Combine different saops. Some of them doesnt' fit a set of partial indexes,
+-- but other fits.
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+
+-- Check recursive combination of OR and SAOP expressions
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+
+RESET enable_indexscan;
+RESET enable_seqscan;
+
 --
 -- Test some corner cases that have been known to confuse the planner
 --
-- 
2.44.0

#174Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#173)
Re: POC, WIP: OR-clause support for indexes

On Tue, Mar 19, 2024 at 7:17 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 14/3/2024 16:31, Alexander Korotkov wrote:

On Wed, Mar 13, 2024 at 2:16 PM Andrei Lepikhov
As you can see this case is not related to partial indexes. Just no
index selective for the whole query. However, splitting scan by the OR
qual lets use a combination of two selective indexes.

I have rewritten the 0002-* patch according to your concern. A candidate
and some thoughts are attached.
As I see, we have a problem here: expanding each array and trying to
apply an element to each index can result in a lengthy planning stage.
Also, an index scan with the SAOP may potentially be more effective than
with the list of OR clauses.
Originally, the transformation's purpose was to reduce a query's
complexity and the number of optimization ways to speed up planning and
(sometimes) execution. Here, we reduce planning complexity only in the
case of an array size larger than MAX_SAOP_ARRAY_SIZE.
Maybe we can fall back to the previous version of the second patch,
keeping in mind that someone who wants to get maximum profit from the
BitmapOr scan of multiple indexes can just disable this optimization,
enabling deep search of the most optimal scanning way?
As a compromise solution, I propose adding one more option to the
previous version: if an element doesn't fit any partial index, try to
cover it with a plain index.
In this case, we still do not guarantee the most optimal fit of elements
to the set of indexes, but we speed up planning. Does that make sense?

Thank you for your research Andrei. Now things get more clear on the
advantages and disadvantages of this transformation.

The current patch has a boolean guc enable_or_transformation.
However, when we have just a few ORs to be transformated, then we
should get less performance gain from the transformation and higher
chances to lose a good bitmap scan plan from that. When there is a
huge list of ORs to be transformed, then the performance gain is
greater and it is less likely we could lose a good bitmap scan plan.

What do you think about introducing a GUC threshold value: the minimum
size of list to do OR-to-ANY transformation?
min_list_or_transformation or something.

------
Regards,
Alexander Korotkov

#175Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alexander Korotkov (#174)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 28/3/2024 16:54, Alexander Korotkov wrote:

The current patch has a boolean guc enable_or_transformation.
However, when we have just a few ORs to be transformated, then we
should get less performance gain from the transformation and higher
chances to lose a good bitmap scan plan from that. When there is a
huge list of ORs to be transformed, then the performance gain is
greater and it is less likely we could lose a good bitmap scan plan.

What do you think about introducing a GUC threshold value: the minimum
size of list to do OR-to-ANY transformation?
min_list_or_transformation or something.

I labelled it or_transformation_limit (see in attachment). Feel free to
rename it.
It's important to note that the limiting GUC doesn't operate
symmetrically for forward, OR -> SAOP, and backward SAOP -> OR
operations. In the forward case, it functions as you've proposed.
However, in the backward case, we only check whether the feature is
enabled or not. This is due to our existing limitation,
MAX_SAOP_ARRAY_SIZE, and the fact that we can't match the length of the
original OR list with the sizes of the resulting SAOPs. For instance, a
lengthy OR list with 100 elements can be transformed into 3 SAOPs, each
with a size of around 30 elements.
One aspect that requires attention is the potential inefficiency of our
OR -> ANY transformation when we have a number of elements less than
MAX_SAOP_ARRAY_SIZE. This is because we perform a reverse transformation
ANY -> OR at the stage of generating bitmap scans. If the BitmapScan
path dominates, we may have done unnecessary work. Is this an occurrence
that we should address?
But the concern above may just be a point of improvement later: We can
add one more strategy to the optimizer: testing each array element as an
OR clause; we can also provide a BitmapOr path, where SAOP is covered
with a minimal number of partial indexes (likewise, previous version).

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v24-0001-Transform-OR-clauses-to-ANY-expression.patchtext/plain; charset=UTF-8; name=v24-0001-Transform-OR-clauses-to-ANY-expression.patchDownload
From e42a7111a12ef82eecdb2e692d65e7ba6e43ad79 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Fri, 2 Feb 2024 22:01:09 +0300
Subject: [PATCH 1/2] Transform OR clauses to ANY expression.

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...]) on the
preliminary stage of optimization when we are still working with the
expression tree.
Here C<X> is a constant expression, 'expr' is non-constant expression, 'op' is
an operator which returns boolean result and has a commuter (for the case of
reverse order of constant and non-constant parts of the expression,
like 'CX op expr').
Sometimes it can lead to not optimal plan. But we think it is better to have
array of elements instead of a lot of OR clauses. Here is a room for further
optimizations on decomposing that array into more optimal parts.
Authors: Alena Rybakina <lena.ribackina@yandex.ru>, Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>, Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>, Robert Haas <robertmhaas@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
---
 .../postgres_fdw/expected/postgres_fdw.out    |   8 +-
 doc/src/sgml/config.sgml                      |  18 +
 src/backend/nodes/queryjumblefuncs.c          |  27 ++
 src/backend/optimizer/prep/prepqual.c         | 379 +++++++++++++++++-
 src/backend/utils/misc/guc_tables.c           |  13 +
 src/backend/utils/misc/postgresql.conf.sample |   1 +
 src/include/nodes/queryjumble.h               |   1 +
 src/include/optimizer/optimizer.h             |   2 +
 src/test/regress/expected/create_index.out    | 172 +++++++-
 src/test/regress/expected/join.out            |  60 ++-
 src/test/regress/expected/partition_prune.out | 211 +++++++++-
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/tidscan.out         |  21 +-
 src/test/regress/sql/create_index.sql         |  44 ++
 src/test/regress/sql/join.sql                 |   8 +
 src/test/regress/sql/partition_prune.sql      |  18 +
 src/test/regress/sql/tidscan.sql              |   4 +
 src/tools/pgindent/typedefs.list              |   2 +
 18 files changed, 950 insertions(+), 51 deletions(-)

diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index b7af86d351..277ef3f385 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8853,18 +8853,18 @@ insert into utrtest values (2, 'qux');
 -- Check case where the foreign partition is a subplan target rel
 explain (verbose, costs off)
 update utrtest set a = 1 where a = 1 or a = 2 returning *;
-                                             QUERY PLAN                                             
-----------------------------------------------------------------------------------------------------
+                                                  QUERY PLAN                                                  
+--------------------------------------------------------------------------------------------------------------
  Update on public.utrtest
    Output: utrtest_1.a, utrtest_1.b
    Foreign Update on public.remp utrtest_1
    Update on public.locp utrtest_2
    ->  Append
          ->  Foreign Update on public.remp utrtest_1
-               Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
+               Remote SQL: UPDATE public.loct SET a = 1 WHERE ((a = ANY ('{1,2}'::integer[]))) RETURNING a, b
          ->  Seq Scan on public.locp utrtest_2
                Output: 1, utrtest_2.tableoid, utrtest_2.ctid, NULL::record
-               Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
+               Filter: (utrtest_2.a = ANY ('{1,2}'::integer[]))
 (10 rows)
 
 -- The new values are concatenated with ' triggered !'
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 5468637e2e..f384edde05 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5472,6 +5472,24 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-enable-or-transformation" xreflabel="or_transformation_limit">
+      <term><varname>or_transformation_limit</varname> (<type>boolean</type>)
+       <indexterm>
+        <primary><varname>or_transformation_limit</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      <listitem>
+       <para>
+        Sets the minimum length of arguments in an OR expression exceeding which
+        planner will try to lookup and group multiple similar OR expressions to
+        ANY (<xref linkend="functions-comparisons-any-some"/>) expressions.
+        The grouping technique of this transformation is based on the equivalence of variable sides.
+        One side of such an expression must be a constant clause, and the other must contain a variable clause.
+        The default is <literal>on</literal>.
+        </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-enable-parallel-append" xreflabel="enable_parallel_append">
       <term><varname>enable_parallel_append</varname> (<type>boolean</type>)
       <indexterm>
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index be823a7f8f..edcb00bd31 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -141,6 +141,33 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/optimizer/prep/prepqual.c b/src/backend/optimizer/prep/prepqual.c
index cbcf83f847..e27b07e6a9 100644
--- a/src/backend/optimizer/prep/prepqual.c
+++ b/src/backend/optimizer/prep/prepqual.c
@@ -31,16 +31,25 @@
 
 #include "postgres.h"
 
+#include "catalog/namespace.h"
+#include "catalog/pg_operator.h"
+#include "common/hashfn.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 
+int		or_transformation_limit = 0;
 
 static List *pull_ands(List *andlist);
 static List *pull_ors(List *orlist);
 static Expr *find_duplicate_ors(Expr *qual, bool is_check);
 static Expr *process_duplicate_ors(List *orlist);
+static List *or_transformation(List *orlist);
 
 
 /*
@@ -266,6 +275,357 @@ negate_clause(Node *node)
 	return (Node *) make_notclause((Expr *) node);
 }
 
+typedef struct OrClauseGroupKey
+{
+	NodeTag	type;
+
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		consttype;
+	Oid		inputcollid; /* XXX: Could we lookup for common collation? */
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey	key;
+
+	List			   *consts;
+	List 			   *exprs;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function to find candidate clauses.
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				exprHash;
+
+	Assert(keysize == sizeof(OrClauseGroupKey));
+	Assert(IsA(data, Invalid));
+
+	(void) JumbleExpr(key->expr, &exprHash);
+
+	return hash_combine((uint32) exprHash,
+						hash_combine((uint32) key->opno,
+							hash_combine((uint32) key->consttype,
+										 (uint32) key->inputcollid)));
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(src, Invalid));
+
+	dst_key->type = T_Invalid;
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->consttype = src_key->consttype;
+	dst_key->inputcollid = src_key->inputcollid;
+
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in or_group_htab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(key1, Invalid));
+	Assert(IsA(key2, Invalid));
+
+	if (key1->opno == key2->opno &&
+		key1->consttype == key2->consttype &&
+		key1->inputcollid == key2->inputcollid &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+/*
+ * or_transformation -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to an SAOP operation.
+ *	  Transformation groups two-sided equality operations. One side of such an
+ *	  operation must be plain constant or constant expression. The other side of
+ *	  the clause must be a variable expression without volatile functions.
+ *	  To group quals, inputcollid, opno and constype of the OR OpExpr quals must
+ *	  be equal too.
+ *	  The grouping technique is based on an equivalence of variable sides of the
+ *	  expression: using queryId and equal() routine, it groups constant sides of
+ *	  similar clauses into an array. After the grouping procedure, each couple
+ *	  ('variable expression' and 'constant array') form a new SAOP operation,
+ *	  which is added to the args list of the returning expression.
+ */
+static List *
+or_transformation(List *orlist)
+{
+	List				   *neworlist = NIL;
+	List				   *entries = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(orlist);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	Assert(or_transformation_limit >= 0 && len_ors > or_transformation_limit);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, orlist)
+	{
+		Node				   *orqual = lfirst(lc);
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Oid						consttype;
+		Node				   *leftop, *rightop;
+
+		if (!IsA(orqual, OpExpr))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				entries = lappend(entries, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		 * Transformation only works with both side type is not
+		 * { array | composite | domain | record }.
+		 * Also, forbid it for volatile expressions.
+		 */
+		consttype = exprType(const_expr);
+		if (type_is_rowtype(exprType(const_expr)) ||
+			type_is_rowtype(consttype) ||
+			contain_volatile_functions((Node *) nconst_expr))
+		{
+			entries = lappend(entries, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.type = T_Invalid;
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.consttype = consttype;
+		hashkey.inputcollid = exprCollation(const_expr);
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+	foreach (lc, entries)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		if (!IsA(lfirst(lc), Invalid))
+		{
+			neworlist = lappend(neworlist, lfirst(lc));
+			continue;
+		}
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element returns origin expression into the BoolExpr args
+			 * list unchanged.
+			 */
+			list_free(entry->consts);
+			neworlist = list_concat(neworlist, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.consttype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+											   InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+
+			foreach(lc, entry->consts)
+			{
+				Node *node = (Node *) lfirst(lc);
+
+				node = coerce_to_common_type(NULL, node, scalar_type,
+											 "OR ANY Transformation");
+				aexprs = lappend(aexprs, node);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			/*
+			 * Try to cast this expression to Const. Due to current strict
+			 * transformation rules it should be done [almost] every time.
+			 */
+			newa = (ArrayExpr *) eval_const_expressions(NULL, (Node *) newa);
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(NULL,
+										 namelist,
+										 true,
+										 (Node *) entry->key.expr,
+										 (Node *) newa,
+										 -1);
+			saopexpr->inputcollid = entry->key.inputcollid;
+
+			neworlist = lappend(neworlist, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
+			 */
+			list_free(entry->consts);
+			neworlist = list_concat(neworlist, entry->exprs);
+		}
+	}
+	hash_destroy(or_group_htab);
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return neworlist;
+}
 
 /*
  * canonicalize_qual
@@ -604,7 +964,19 @@ process_duplicate_ors(List *orlist)
 	 * If no winners, we can't transform the OR
 	 */
 	if (winners == NIL)
-		return make_orclause(orlist);
+	{
+		/*
+		 * Make an attempt to group similar OR clauses into SAOP if the list is
+		 * lengthy enough.
+		 */
+		if (or_transformation_limit >= 0 &&
+			list_length(orlist) > or_transformation_limit)
+			orlist = or_transformation(orlist);
+
+		/* Transformation could group all OR clauses to a single SAOP */
+		return (list_length(orlist) == 1) ?
+							(Expr *) linitial(orlist) : make_orclause(orlist);
+	}
 
 	/*
 	 * Generate new OR list consisting of the remaining sub-clauses.
@@ -651,6 +1023,11 @@ process_duplicate_ors(List *orlist)
 		}
 	}
 
+	/* Make an attempt to group similar OR clauses into ANY operation */
+	if (or_transformation_limit >= 0 &&
+		list_length(neworlist) > or_transformation_limit)
+		neworlist = or_transformation(neworlist);
+
 	/*
 	 * Append reduced OR to the winners list, if it's not degenerate, handling
 	 * the special case of one element correctly (can that really happen?).
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index abd9029451..a8dd701e7c 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -3626,6 +3626,19 @@ struct config_int ConfigureNamesInt[] =
 		NULL, NULL, NULL
 	},
 
+	{
+		{"or_transformation_limit", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Set the minimum length of the list of OR clauses to "
+						 "attempt the transformation."),
+			gettext_noop("The planner will try to replace expression like "
+						 "'x=c1 OR x=c2 ..' to the expression 'x = ANY(ARRAY[c1,c2,..])'"),
+			GUC_EXPLAIN
+		},
+		&or_transformation_limit,
+		0, -1, INT_MAX,
+		NULL, NULL, NULL
+	},
+
 	/* End-of-list marker */
 	{
 		{NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 2244ee52f7..03745c2630 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -391,6 +391,7 @@
 # - Planner Method Configuration -
 
 #enable_async_append = on
+#or_transformation_limit = 0
 #enable_bitmapscan = on
 #enable_gathermerge = on
 #enable_hashagg = on
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067..a9ae048af5 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 7b63c5cf71..4c613401d6 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -133,6 +133,8 @@ extern void extract_query_dependencies(Node *query,
 
 /* in prep/prepqual.c: */
 
+extern PGDLLIMPORT int or_transformation_limit;
+
 extern Node *negate_clause(Node *node);
 extern Expr *canonicalize_qual(Expr *qual, bool is_check);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 70ab47a92f..e9fb82b64c 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1836,6 +1836,72 @@ DROP TABLE onek_with_null;
 -- Check bitmap index path planning
 --
 EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+SET or_transformation_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+SET or_transformation_limit = 2;
+EXPLAIN (COSTS OFF) -- or_transformation still works
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SET or_transformation_limit = 3;
+EXPLAIN (COSTS OFF) -- or_transformation must be disabled
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
                                                                QUERY PLAN                                                                
@@ -1851,38 +1917,120 @@ SELECT * FROM tenk1
                Index Cond: ((thousand = 42) AND (tenthous = 42))
 (9 rows)
 
-SELECT * FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
- unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
----------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
-      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+RESET or_transformation_limit;
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
 (1 row)
 
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(14 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = ANY ('{42,41}'::integer[])) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+RESET or_transformation_limit;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 63cddac0d6..41e2a5ed98 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,15 +4223,61 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(15 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 46b78ba3c4..388b7f838b 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,23 +82,43 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
 explain (costs off) select * from lp where a <> 'g';
@@ -515,10 +535,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +616,13 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +691,161 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -2072,10 +2247,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 10903bdab0..6f55b9e3ec 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac..f112e64a87 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,25 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Tid Scan on tidscan
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+(2 rows)
+
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+ ctid  | id 
+-------+----
+ (0,1) |  1
+ (0,2) |  2
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index d49ce9f300..2f691efcc5 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -737,6 +737,50 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET or_transformation_limit = 0;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SET or_transformation_limit = 2;
+EXPLAIN (COSTS OFF) -- or_transformation still works
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SET or_transformation_limit = 3;
+EXPLAIN (COSTS OFF) -- or_transformation must be disabled
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+RESET or_transformation_limit;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET or_transformation_limit;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index c4c6c7b8ba..8158a7dd24 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,14 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index dc71693861..e677ce7250 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,10 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +103,20 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b6..283e026751 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,10 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index cfa9d5aaea..4f7925d78c 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1672,6 +1672,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.44.0

v24-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchtext/plain; charset=UTF-8; name=v24-0002-Teach-generate_bitmap_or_paths-to-build-BitmapOr-pat.patchDownload
From 37831eb47fe890d41e5f66bedc5d616c0f1ad570 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Wed, 13 Mar 2024 12:26:02 +0700
Subject: [PATCH 2/2] Teach generate_bitmap_or_paths to build BitmapOr paths
 over SAOP clauses.

Likewise OR clauses, discover SAOP array and try to split its elements
between smaller sized arrays to fit a set of partial indexes.
---
 doc/src/sgml/config.sgml                   |   3 +
 src/backend/optimizer/path/indxpath.c      |  82 +++++-
 src/backend/optimizer/util/predtest.c      |  37 +++
 src/backend/optimizer/util/restrictinfo.c  |  13 +
 src/include/optimizer/optimizer.h          |   3 +
 src/include/optimizer/restrictinfo.h       |   1 +
 src/test/regress/expected/create_index.out |  24 +-
 src/test/regress/expected/select.out       | 280 +++++++++++++++++++++
 src/test/regress/sql/select.sql            |  82 ++++++
 9 files changed, 508 insertions(+), 17 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index f384edde05..5772574634 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5486,6 +5486,9 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
         The grouping technique of this transformation is based on the equivalence of variable sides.
         One side of such an expression must be a constant clause, and the other must contain a variable clause.
         The default is <literal>on</literal>.
+        Also, during BitmapScan paths generation it enables analysis of elements
+        of IN or ANY constant arrays to cover such clause with BitmapOr set of
+        partial index scans.
         </para>
       </listitem>
      </varlistentry>
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 32c6a8bbdc..f78dae25ff 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,6 +32,7 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
 
@@ -1220,11 +1221,73 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Expand SAOP node to use it in bitmapscan path building routine.
+ *
+ * If RestrictInfo is an OR bool expression, extract each SAOP from the list of
+ * arguments, if possible.
+ * Working jointly with the TransformOrExprToANY routine, it provides a user
+ * with some sort of independence of the query plan from the approach to writing
+ * alternatives for the same entity in the WHERE section.
+ */
+static List *
+extract_saop_ors(PlannerInfo *root, RestrictInfo *rinfo)
+{
+	List		   *orlist = NIL;
+	List		   *result = NIL;
+	ListCell	   *lc;
+
+	Assert(IsA(rinfo, RestrictInfo));
+
+	if (restriction_is_or_clause(rinfo))
+		orlist = ((BoolExpr *) rinfo->orclause)->args;
+
+	/*
+	 * Don't spend cycles here if the transformation is disabled.
+	 * We don't behave symmetrically here with the OR -> ANY transformation, see
+	 * the process_duplicate_ors routine, because origin list of ORs and
+	 * resulting SAOP args list lengths can differ significantly. Moreover,
+	 * Here we already limited by the MAX_SAOP_ARRAY_SIZE value.
+	 */
+	if (or_transformation_limit < 0)
+		return orlist;
+
+	if (restriction_is_saop_clause(rinfo))
+	{
+		result = transform_saop_to_ors(root, rinfo);
+		return result;
+	}
+
+	foreach(lc, orlist)
+	{
+		Expr *expr = (Expr *) lfirst(lc);
+
+		if (IsA(expr, RestrictInfo) && restriction_is_saop_clause((RestrictInfo *) expr))
+		{
+			List *sublist;
+
+			sublist = extract_saop_ors(root, (RestrictInfo *) lfirst(lc));
+			if (sublist != NIL)
+			{
+				result = list_concat(result, sublist);
+				continue;
+			}
+
+			/* Need to return expr to the result list */
+		}
+
+		result = lappend(result, expr);
+	}
+
+	return result;
+}
+
 /*
  * generate_bitmap_or_paths
- *		Look through the list of clauses to find OR clauses, and generate
- *		a BitmapOrPath for each one we can handle that way.  Return a list
- *		of the generated BitmapOrPaths.
+ *		Look through the list of clauses to find OR and SAOP clauses, and
+ *		Each saop clause are splitted to be covered by partial indexes.
+ *		generate a BitmapOrPath for each one we can handle that way.
+ *		Return a list of the generated BitmapOrPaths.
  *
  * other_clauses is a list of additional clauses that can be assumed true
  * for the purpose of generating indexquals, but are not to be searched for
@@ -1247,20 +1310,25 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 	foreach(lc, clauses)
 	{
 		RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
-		List	   *pathlist;
+		List	   *pathlist = NIL;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *orlist = NIL;
 
-		/* Ignore RestrictInfos that aren't ORs */
-		if (!restriction_is_or_clause(rinfo))
+		orlist = extract_saop_ors(root, rinfo);
+		if (orlist == NIL)
+			/* Ignore RestrictInfo that doesn't provide proper OR list */
 			continue;
 
+		/* SAOP have splitted, remove already redundant clause */
+		all_clauses = list_delete(all_clauses, rinfo);
+
 		/*
 		 * We must be able to match at least one index to each of the arms of
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		foreach(j, orlist)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index 6e3b376f3d..fe8862b0a0 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -111,6 +111,43 @@ static bool operator_same_subexprs_lookup(Oid pred_op, Oid clause_op,
 static Oid	get_btree_test_op(Oid pred_op, Oid clause_op, bool refute_it);
 static void InvalidateOprProofCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
 
+/*
+ * Expand a SAOP operation into the list of OR expressions
+ */
+List *
+transform_saop_to_ors(PlannerInfo *root, RestrictInfo *rinfo)
+{
+	PredIterInfoData	clause_info;
+	List			   *orlist = NIL;
+	Node			   *saop = (Node *) rinfo->clause;
+
+	Assert(IsA(saop, ScalarArrayOpExpr));
+
+	if (predicate_classify(saop, &clause_info) != CLASS_OR)
+		return NIL;
+
+	iterate_begin(pitem, saop, clause_info)
+	{
+		RestrictInfo   *rinfo1;
+
+		/* Predicate is found. Add the elem to the saop clause */
+		Assert(IsA(pitem, OpExpr));
+
+		/* Extract constant from the expression */
+		rinfo1 = make_restrictinfo(root, (Expr *) copyObject(pitem),
+								   rinfo->is_pushed_down,
+								   rinfo->has_clone, rinfo->is_clone,
+								   rinfo->pseudoconstant,
+								   rinfo->security_level,
+								   rinfo->required_relids,
+								   rinfo->incompatible_relids,
+								   rinfo->outer_relids);
+		orlist = lappend(orlist, rinfo1);
+	}
+	iterate_end(clause_info);
+
+	return orlist;
+}
 
 /*
  * predicate_implied_by
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e9334..1dad1dc654 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -421,6 +421,19 @@ restriction_is_or_clause(RestrictInfo *restrictinfo)
 		return false;
 }
 
+bool
+restriction_is_saop_clause(RestrictInfo *restrictinfo)
+{
+	if (restrictinfo->clause && IsA(restrictinfo->clause, ScalarArrayOpExpr))
+	{
+		ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) restrictinfo->clause;
+
+		if (saop->useOr)
+			return true;
+	}
+	return false;
+}
+
 /*
  * restriction_is_securely_promotable
  *
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 4c613401d6..4ca26f65d1 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -23,6 +23,7 @@
 #define OPTIMIZER_H
 
 #include "nodes/parsenodes.h"
+#include "optimizer/restrictinfo.h"
 
 /*
  * We don't want to include nodes/pathnodes.h here, because non-planner
@@ -161,6 +162,8 @@ extern List *expand_function_arguments(List *args, bool include_out_arguments,
 
 /* in util/predtest.c: */
 
+
+extern List *transform_saop_to_ors(PlannerInfo *root, RestrictInfo *rinfo);
 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
 								 bool weak);
 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c5..2cd5fbf943 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -34,6 +34,7 @@ extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Relids outer_relids);
 extern RestrictInfo *commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op);
 extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
+extern bool restriction_is_saop_clause(RestrictInfo *restrictinfo);
 extern bool restriction_is_securely_promotable(RestrictInfo *restrictinfo,
 											   RelOptInfo *rel);
 extern List *get_actual_clauses(List *restrictinfo_list);
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index e9fb82b64c..0d9c9334f9 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1980,23 +1980,25 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                         QUERY PLAN                                                          
------------------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(14 rows)
+(16 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2008,20 +2010,22 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                          QUERY PLAN                                                          
-------------------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = ANY ('{42,41}'::integer[])) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+                           Index Cond: (thousand = 42)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(11 rows)
+(13 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out
index 33a6dceb0e..b5fdde47ac 100644
--- a/src/test/regress/expected/select.out
+++ b/src/test/regress/expected/select.out
@@ -907,6 +907,286 @@ select unique1, unique2 from onek2
        0 |     998
 (2 rows)
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET or_transformation_limit = -1;
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: ((stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Without the transformation only seqscan possible here
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                         QUERY PLAN                                          
+---------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])) AND (stringu1 < 'Z'::name))
+(2 rows)
+
+-- Use partial indexes
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = 'A'::name) OR (stringu1 = 'J'::name))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+                 QUERY PLAN                 
+--------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = 1) OR (unique2 = 3))
+(2 rows)
+
+RESET or_transformation_limit;
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+                                QUERY PLAN                                
+--------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+         Filter: (stringu1 = ANY ('{A,J}'::name[]))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_stu1_prtl
+                     Index Cond: (stringu1 = 'J'::name)
+(8 rows)
+
+-- Don't scan partial indexes because of extra value.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+                      QUERY PLAN                      
+------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on onek2
+         Filter: (stringu1 = ANY ('{A,J,C}'::name[]))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+                                QUERY PLAN                                 
+---------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (stringu1 < 'B'::name)
+   Filter: ((stringu1 = ANY ('{A,A}'::name[])) AND (stringu1 = 'A'::name))
+   ->  Bitmap Index Scan on onek2_u2_prtl
+(4 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+                                                     QUERY PLAN                                                      
+---------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (((unique2 < 1) AND (stringu1 < 'B'::name)) OR ((stringu1 = 'J'::name) AND (stringu1 < 'Z'::name)))
+   Filter: ((unique2 < 1) AND (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u2_prtl
+               Index Cond: (unique2 < 1)
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: ((stringu1 = 'J'::name) AND (stringu1 < 'Z'::name))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer);
+                        QUERY PLAN                        
+----------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: (unique1 = ANY ('{1,3}'::integer[]))
+   ->  Bitmap Index Scan on onek2_u1_prtl
+         Index Cond: (unique1 = ANY ('{1,3}'::integer[]))
+(4 rows)
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+                                                             QUERY PLAN                                                             
+------------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: ((unique1 = ((random() * '2'::double precision))::integer) OR (unique1 = ((random() * '3'::double precision))::integer))
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+                                                           QUERY PLAN                                                            
+---------------------------------------------------------------------------------------------------------------------------------
+ Seq Scan on onek2
+   Filter: (unique1 = ANY (ARRAY[((random() * '2'::double precision))::integer, ((random() * '3'::double precision))::integer]))
+(2 rows)
+
+-- Combine different saops. Some of them doesnt' fit a set of partial indexes,
+-- but other fits.
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+                                                                           QUERY PLAN                                                                           
+----------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((stringu1 < 'B'::name) OR (stringu1 = 'J'::name) OR (unique1 = 3) OR (unique1 = 4) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 = ANY ('{1,2,21}'::integer[])) AND ((stringu1 = ANY ('{A,J}'::name[])) OR (unique1 = ANY ('{3,4}'::integer[])) OR (stringu1 = 'J'::name)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 3)
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 = 4)
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(13 rows)
+
+-- Check recursive combination of OR and SAOP expressions
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+                                     QUERY PLAN                                      
+-------------------------------------------------------------------------------------
+ Bitmap Heap Scan on onek2
+   Recheck Cond: ((unique1 < 1) OR (stringu1 < 'B'::name) OR (stringu1 = 'J'::name))
+   Filter: ((unique1 < 1) OR (stringu1 = ANY ('{A,J}'::name[])))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on onek2_u1_prtl
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on onek2_u2_prtl
+         ->  Bitmap Index Scan on onek2_stu1_prtl
+               Index Cond: (stringu1 = 'J'::name)
+(9 rows)
+
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+                                             QUERY PLAN                                             
+----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on onek2
+         Recheck Cond: ((stringu1 < 'B'::name) OR (unique1 = 1))
+         Filter: ((stringu1 = ANY ('{B,J}'::name[])) AND ((stringu1 = 'A'::name) OR (unique1 = 1)))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on onek2_u2_prtl
+               ->  Bitmap Index Scan on onek2_u1_prtl
+                     Index Cond: (unique1 = 1)
+(8 rows)
+
+RESET enable_indexscan;
+RESET enable_seqscan;
 --
 -- Test some corner cases that have been known to confuse the planner
 --
diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql
index 019f1e7673..10ed6f0a9c 100644
--- a/src/test/regress/sql/select.sql
+++ b/src/test/regress/sql/select.sql
@@ -234,6 +234,88 @@ select unique1, unique2 from onek2
 select unique1, unique2 from onek2
   where (unique2 = 11 and stringu1 < 'B') or unique1 = 0;
 
+SET enable_seqscan TO off;
+SET enable_indexscan TO off; -- Only BitmapScan is a subject matter here
+SET or_transformation_limit = -1;
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+-- Without the transformation only seqscan possible here
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+-- Use partial indexes
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique2 = PI()::integer;
+RESET or_transformation_limit;
+
+-- OR <-> ANY transformation must find a path with partial indexes scan
+-- regardless the clause representation.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = 'A' OR stringu1 = 'J';
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A','J');
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 = ANY ('{A,J}');
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A') OR stringu1 IN ('J');
+
+-- Don't scan partial indexes because of extra value.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2 WHERE stringu1 IN ('A', 'J', 'C');
+EXPLAIN (COSTS OFF)
+SELECT unique2 FROM onek2
+WHERE stringu1 IN ('A', 'A') AND (stringu1 = 'A' OR stringu1 = 'A');
+
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique2 < 1 AND stringu1 IN ('A','J') AND stringu1 < 'Z';
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 = 1 OR unique1 = PI()::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 IN (1, PI()::integer);
+
+-- Don't apply the optimization to clauses, containing volatile functions
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 = (random()*2)::integer OR unique1 = (random()*3)::integer;
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE unique1 IN ((random()*2)::integer, (random()*3)::integer);
+
+-- Combine different saops. Some of them doesnt' fit a set of partial indexes,
+-- but other fits.
+
+EXPLAIN (COSTS OFF)
+SELECT unique2,stringu1 FROM onek2
+WHERE
+  unique1 IN (1,2,21) AND
+  (stringu1 IN ('A','J') OR unique1 IN (3,4) OR stringu1 = 'J');
+
+-- Check recursive combination of OR and SAOP expressions
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE unique1 < 1 OR (stringu1 = 'A' OR stringu1 = 'J');
+EXPLAIN (COSTS OFF)
+SELECT unique2, stringu1 FROM onek2
+WHERE (unique1 < 1 OR stringu1 IN ('A','J'));
+-- Although SAOP doesn't fit partial indexes fully, we can use anded OR clause
+-- to scan another couple of partial indexes.
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM onek2
+WHERE stringu1 IN ('B','J') AND (stringu1 = 'A' OR unique1 = 1);
+
+RESET enable_indexscan;
+RESET enable_seqscan;
+
 --
 -- Test some corner cases that have been known to confuse the planner
 --
-- 
2.44.0

#176Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#175)
Re: POC, WIP: OR-clause support for indexes

Hi!

On Mon, Apr 1, 2024 at 9:38 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 28/3/2024 16:54, Alexander Korotkov wrote:

The current patch has a boolean guc enable_or_transformation.
However, when we have just a few ORs to be transformated, then we
should get less performance gain from the transformation and higher
chances to lose a good bitmap scan plan from that. When there is a
huge list of ORs to be transformed, then the performance gain is
greater and it is less likely we could lose a good bitmap scan plan.

What do you think about introducing a GUC threshold value: the minimum
size of list to do OR-to-ANY transformation?
min_list_or_transformation or something.

I labelled it or_transformation_limit (see in attachment). Feel free to
rename it.
It's important to note that the limiting GUC doesn't operate
symmetrically for forward, OR -> SAOP, and backward SAOP -> OR
operations. In the forward case, it functions as you've proposed.
However, in the backward case, we only check whether the feature is
enabled or not. This is due to our existing limitation,
MAX_SAOP_ARRAY_SIZE, and the fact that we can't match the length of the
original OR list with the sizes of the resulting SAOPs. For instance, a
lengthy OR list with 100 elements can be transformed into 3 SAOPs, each
with a size of around 30 elements.
One aspect that requires attention is the potential inefficiency of our
OR -> ANY transformation when we have a number of elements less than
MAX_SAOP_ARRAY_SIZE. This is because we perform a reverse transformation
ANY -> OR at the stage of generating bitmap scans. If the BitmapScan
path dominates, we may have done unnecessary work. Is this an occurrence
that we should address?
But the concern above may just be a point of improvement later: We can
add one more strategy to the optimizer: testing each array element as an
OR clause; we can also provide a BitmapOr path, where SAOP is covered
with a minimal number of partial indexes (likewise, previous version).

I've revised the patch. Did some beautification, improvements for
documentation, commit messages etc.

I've pushed the 0001 patch without 0002. I think 0001 is good by
itself given that there is the or_to_any_transform_limit GUC option.
The more similar OR clauses are here the more likely grouping them
into SOAP will be a win. But I've changed the default value to 5.
This will make it less invasive and affect only queries with obvious
repeating patterns. That also reduced the changes in the regression
tests expected outputs.

Regarding 0002, it seems questionable since it could cause a planning
slowdown for SAOP's with large arrays. Also, it might reduce the win
of transformation made by 0001. So, I think we should skip it for
now.

------
Regards,
Alexander Korotkov

#177Justin Pryzby
pryzby@telsasoft.com
In reply to: Alexander Korotkov (#176)
Re: POC, WIP: OR-clause support for indexes

On Mon, Apr 08, 2024 at 01:34:37AM +0300, Alexander Korotkov wrote:

Hi!

On Mon, Apr 1, 2024 at 9:38 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 28/3/2024 16:54, Alexander Korotkov wrote:

The current patch has a boolean guc enable_or_transformation.
However, when we have just a few ORs to be transformated, then we
should get less performance gain from the transformation and higher
chances to lose a good bitmap scan plan from that. When there is a
huge list of ORs to be transformed, then the performance gain is
greater and it is less likely we could lose a good bitmap scan plan.

What do you think about introducing a GUC threshold value: the minimum
size of list to do OR-to-ANY transformation?
min_list_or_transformation or something.

I labelled it or_transformation_limit (see in attachment). Feel free to
rename it.
It's important to note that the limiting GUC doesn't operate
symmetrically for forward, OR -> SAOP, and backward SAOP -> OR
operations. In the forward case, it functions as you've proposed.
However, in the backward case, we only check whether the feature is
enabled or not. This is due to our existing limitation,
MAX_SAOP_ARRAY_SIZE, and the fact that we can't match the length of the
original OR list with the sizes of the resulting SAOPs. For instance, a
lengthy OR list with 100 elements can be transformed into 3 SAOPs, each
with a size of around 30 elements.
One aspect that requires attention is the potential inefficiency of our
OR -> ANY transformation when we have a number of elements less than
MAX_SAOP_ARRAY_SIZE. This is because we perform a reverse transformation
ANY -> OR at the stage of generating bitmap scans. If the BitmapScan
path dominates, we may have done unnecessary work. Is this an occurrence
that we should address?
But the concern above may just be a point of improvement later: We can
add one more strategy to the optimizer: testing each array element as an
OR clause; we can also provide a BitmapOr path, where SAOP is covered
with a minimal number of partial indexes (likewise, previous version).

I've revised the patch. Did some beautification, improvements for
documentation, commit messages etc.

I've pushed the 0001 patch without 0002. I think 0001 is good by
itself given that there is the or_to_any_transform_limit GUC option.
The more similar OR clauses are here the more likely grouping them
into SOAP will be a win. But I've changed the default value to 5.

The sample config file has the wrong default

+#or_to_any_transform_limit = 0

We had a patch to catch this kind of error, but it was closed (which IMO
was itself an error).

--
Justin

#178Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alexander Korotkov (#176)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Mon, Apr 8, 2024 at 1:34 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

I've revised the patch. Did some beautification, improvements for
documentation, commit messages etc.

I've pushed the 0001 patch without 0002. I think 0001 is good by
itself given that there is the or_to_any_transform_limit GUC option.
The more similar OR clauses are here the more likely grouping them
into SOAP will be a win. But I've changed the default value to 5.
This will make it less invasive and affect only queries with obvious
repeating patterns. That also reduced the changes in the regression
tests expected outputs.

Regarding 0002, it seems questionable since it could cause a planning
slowdown for SAOP's with large arrays. Also, it might reduce the win
of transformation made by 0001. So, I think we should skip it for
now.

The patch has been reverted from pg17. Let me propose a new version
for pg18 based on the valuable feedback from Tom Lane [1][2].

* The transformation is moved to the stage of adding restrictinfos to
the base relation (in particular add_base_clause_to_rel()). This
leads to interesting consequences. While this allows IndexScans to
use transformed clauses, BitmapScans and SeqScans seem unaffected.
Therefore, I wasn't able to find a planning regression.
* As soon as there is no planning regression anymore, I've removed
or_to_any_transform_limit GUC, which was a source of critics.
* Now, not only Consts allowed in the SAOP's list, but also Params.
* The criticized hash based on expression jumbling has been removed.
Now, the plain list is used instead.
* OrClauseGroup now gets a legal node tag. That allows to mix it in
the list with other nodes without hacks.

I think this patch shouldn't be as good as before for optimizing
performance of large OR lists, given that BitmapScans and SeqScans
still deal with ORs. However, it allows IndexScans to handle more,
doesn't seem to cause planning regression and therefore introduce no
extra GUC. Overall, this seems like a good compromise.

This patch could use some polishing, but I'd like to first hear some
feedback on general design.

Links
1. /messages/by-id/3604469.1712628736@sss.pgh.pa.us
2. /messages/by-id/3649287.1712642139@sss.pgh.pa.us

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v25-0001-Transform-OR-clauses-to-ANY-expression.patchapplication/octet-stream; name=v25-0001-Transform-OR-clauses-to-ANY-expression.patchDownload
From cac9a150852a390f89e5322821224453c664f567 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Fri, 14 Jun 2024 10:16:22 +0300
Subject: [PATCH v25] Transform OR clauses to ANY expression

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...])
during adding restrictinfo's to the base relation.

Here Cn is a n-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
---
 src/backend/optimizer/plan/initsplan.c     | 310 ++++++++++++++++++++-
 src/include/nodes/pathnodes.h              |  29 ++
 src/include/nodes/queryjumble.h            |   1 +
 src/test/regress/expected/create_index.out | 189 +++++++++++--
 src/test/regress/expected/join.out         |  52 ++++
 src/test/regress/expected/stats_ext.out    |  12 +-
 src/test/regress/expected/tidscan.out      |   9 +-
 src/test/regress/sql/create_index.sql      |  42 +++
 src/test/regress/sql/join.sql              |   9 +
 src/test/regress/sql/partition_prune.sql   |   1 +
 src/tools/pgindent/typedefs.list           |   1 +
 11 files changed, 627 insertions(+), 28 deletions(-)

diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c
index e2c68fe6f99..0022535318d 100644
--- a/src/backend/optimizer/plan/initsplan.c
+++ b/src/backend/optimizer/plan/initsplan.c
@@ -14,9 +14,13 @@
  */
 #include "postgres.h"
 
+#include "catalog/namespace.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_type.h"
+#include "common/hashfn.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/clauses.h"
 #include "optimizer/cost.h"
 #include "optimizer/inherit.h"
@@ -29,8 +33,11 @@
 #include "optimizer/planner.h"
 #include "optimizer/restrictinfo.h"
 #include "parser/analyze.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 #include "rewrite/rewriteManip.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/rel.h"
 #include "utils/typcache.h"
 
@@ -38,7 +45,6 @@
 int			from_collapse_limit;
 int			join_collapse_limit;
 
-
 /*
  * deconstruct_jointree requires multiple passes over the join tree, because we
  * need to finish computing JoinDomains before we start distributing quals.
@@ -2617,6 +2623,296 @@ check_redundant_nullability_qual(PlannerInfo *root, Node *clause)
 	return false;
 }
 
+/*
+ * transform_or_to_any -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to SAOP expressions.
+ *
+ * This transformation groups two-sided equality expression.  One side of
+ * such an expression must be a plain constant or constant expression.  The
+ * other side must be a variable expression without volatile functions.
+ * To group quals, opno, inputcollid of variable expression, and type of
+ * constant expression must be equal too.
+ *
+ * The grouping technique is based on the equivalence of variable sides of
+ * the expression: using exprId and equal() routine, it groups constant sides
+ * of similar clauses into an array.  After the grouping procedure, each
+ * couple ('variable expression' and 'constant array') forms a new SAOP
+ * operation, which is added to the args list of the returning expression.
+ */
+static List *
+transform_or_to_any(PlannerInfo *root, List *orlist)
+{
+	List	   *neworlist = NIL;
+	List	   *entries = NIL;
+	ListCell   *lc;
+	int			len_ors = list_length(orlist);
+	OrClauseGroup *entry = NULL;
+
+	Assert(len_ors >= 2);
+
+	foreach(lc, orlist)
+	{
+		RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
+		OpExpr	   *orqual;
+		Node	   *const_expr;
+		Node	   *nconst_expr;
+		bool		found = false;
+		Oid			opno;
+		Oid			consttype;
+		Node	   *leftop,
+				   *rightop;
+		ListCell   *lc2;
+
+		if (!IsA(rinfo, RestrictInfo) || !IsA(rinfo->clause, OpExpr))
+		{
+			entries = lappend(entries, rinfo);
+			continue;
+		}
+
+		orqual = (OpExpr *) rinfo->clause;
+		opno = orqual->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			entries = lappend(entries, rinfo);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be an
+		 * OpExpr.  Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				entries = lappend(entries, rinfo);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			entries = lappend(entries, rinfo);
+			continue;
+		}
+
+		/*
+		 * Forbid transformation for composite types, records, and volatile
+		 * expressions.
+		 */
+		consttype = exprType(const_expr);
+		if (type_is_rowtype(exprType(const_expr)) ||
+			type_is_rowtype(consttype) ||
+			contain_volatile_functions((Node *) nconst_expr))
+		{
+			entries = lappend(entries, rinfo);
+			continue;
+		}
+
+		foreach(lc2, entries)
+		{
+			if (!IsA(lfirst(lc2), OrClauseGroup))
+				continue;
+
+			entry = (OrClauseGroup *) lfirst(lc2);
+
+			if (entry->opno == opno &&
+				entry->consttype == consttype &&
+				entry->inputcollid == exprCollation(const_expr) &&
+				equal(entry->expr, nconst_expr))
+			{
+				found = true;
+				break;
+			}
+		}
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, rinfo);
+		}
+		else
+		{
+			entry = makeNode(OrClauseGroup);
+			entry->expr = (Expr *) nconst_expr;
+			entry->opno = opno;
+			entry->consttype = consttype;
+			entry->inputcollid = exprCollation(const_expr);
+
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(rinfo);
+
+			/*
+			 * Add the entry to the list.  It is needed exclusively to manage
+			 * the problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version.  Hence,
+			 * sequental scan of the hash table would prone to change the
+			 * order of clauses in lists and, as a result, break regression
+			 * tests accidentially.
+			 */
+			entries = lappend(entries, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an ANY expression. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of consts
+	 * more than 1. trivial groups move to OR-list again
+	 */
+	foreach(lc, entries)
+	{
+		Oid			scalar_type;
+		Oid			array_type;
+
+		if (!IsA(lfirst(lc), OrClauseGroup))
+		{
+			neworlist = lappend(neworlist, lfirst(lc));
+			continue;
+		}
+
+		entry = (OrClauseGroup *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element returns origin expression into the BoolExpr
+			 * args list unchanged.
+			 */
+			list_free(entry->consts);
+			neworlist = list_concat(neworlist, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+		scalar_type = entry->consttype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+			InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common type
+			 * and build an ArrayExpr for them.
+			 */
+			List	   *aexprs = NIL;
+			ArrayExpr  *newa = NULL;
+			ScalarArrayOpExpr *saopexpr = NULL;
+			HeapTuple	opertup;
+			Form_pg_operator operform;
+			List	   *namelist = NIL;
+			bool		is_pushed_down = false;
+			bool		has_clone = false;
+			Index		security_level = 0;
+			Relids		required_relids = NULL;
+			Relids		incompatible_relids = NULL;
+			Relids		outer_relids = NULL;
+			ListCell   *lc2;
+
+			foreach(lc2, entry->consts)
+			{
+				Node	   *node = (Node *) lfirst(lc2);
+
+				node = coerce_to_common_type(NULL, node, scalar_type,
+											 "OR ANY Transformation");
+				aexprs = lappend(aexprs, node);
+			}
+
+			foreach(lc2, entry->exprs)
+			{
+				RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc2);
+
+				is_pushed_down = is_pushed_down || rinfo->is_pushed_down;
+				has_clone = has_clone || rinfo->is_pushed_down;
+				security_level = Max(security_level, rinfo->security_level);
+				required_relids = bms_union(required_relids, rinfo->required_relids);
+				incompatible_relids = bms_union(incompatible_relids, rinfo->incompatible_relids);
+				outer_relids = bms_union(outer_relids, rinfo->outer_relids);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			/*
+			 * Try to cast this expression to Const. Due to current strict
+			 * transformation rules it should be done [almost] every time.
+			 */
+			newa = (ArrayExpr *) eval_const_expressions(NULL, (Node *) newa);
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+				make_scalar_array_op(NULL,
+									 namelist,
+									 true,
+									 (Node *) entry->expr,
+									 (Node *) newa,
+									 -1);
+			saopexpr->inputcollid = entry->inputcollid;
+
+			neworlist = lappend(neworlist, make_restrictinfo(root, (Expr *) saopexpr, is_pushed_down, has_clone, false, false, security_level, required_relids, incompatible_relids, outer_relids));
+		}
+		else
+		{
+			/*
+			 * If the const node's (right side of operator expression) type
+			 * don't have “true” array type, then we cannnot do the
+			 * transformation. We simply concatenate the expression node.
+			 */
+			list_free(entry->consts);
+			neworlist = list_concat(neworlist, entry->exprs);
+		}
+	}
+	list_free(entries);
+
+	/* One more trick: assemble correct clause */
+	return neworlist;
+}
+
 /*
  * add_base_clause_to_rel
  *		Add 'restrictinfo' as a baserestrictinfo to the base relation denoted
@@ -2677,6 +2973,18 @@ add_base_clause_to_rel(PlannerInfo *root, Index relid,
 		}
 	}
 
+	if (restriction_is_or_clause(restrictinfo))
+	{
+		BoolExpr   *orExpr = (BoolExpr *) restrictinfo->orclause;
+
+		Assert(is_orclause(restrictinfo->orclause));
+
+		if (list_length(orExpr->args) >= 2)
+		{
+			orExpr->args = transform_or_to_any(root, orExpr->args);
+		}
+	}
+
 	/* Add clause to rel's restriction list */
 	rel->baserestrictinfo = lappend(rel->baserestrictinfo, restrictinfo);
 
diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h
index 2ba297c1172..9d6c2da0f87 100644
--- a/src/include/nodes/pathnodes.h
+++ b/src/include/nodes/pathnodes.h
@@ -2708,6 +2708,35 @@ typedef struct RestrictInfo
 	Oid			right_hasheqoperator pg_node_attr(equal_ignore);
 } RestrictInfo;
 
+/*
+ * The group of similar operator expressions in transform_or_to_any().
+ */
+typedef struct OrClauseGroup
+{
+	pg_node_attr(nodetag_only)
+
+	NodeTag		type;
+
+	/* The expression of the variable side of operator */
+	Expr	   *expr;
+	/* The operator of the operator expression */
+	Oid			opno;
+	/* The collation of the operator expression */
+	Oid			inputcollid;
+	/* The type of constant side of operator */
+	Oid			consttype;
+
+	/* The list of constant sides of operators */
+	List	   *consts;
+
+	/*
+	 * List of source expressions.  We need this for convenience in case we
+	 * will give up on transformation.
+	 */
+	List	   *exprs;
+} OrClauseGroup;
+
+
 /*
  * This macro embodies the correct way to test whether a RestrictInfo is
  * "pushed down" to a given outer join, that is, should be treated as a filter
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067f..5643ee8f651 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *exprId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..421a645fae0 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,73 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+   Recheck Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                          QUERY PLAN                                          
+----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+(6 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(4 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1867,23 +1922,123 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 42) AND (tenthous = 1))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: ((thousand = 42) AND (tenthous = 3))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = ANY ('{42,41}'::integer[])) OR ((thousand = 99) AND (tenthous = 2))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(12 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 6b16c3a6769..3cfc8d4e146 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4233,6 +4233,58 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 7)
+(19 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 7)
+(17 rows)
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..7678744181c 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..0f6d3d323d4 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,11 +43,12 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                         QUERY PLAN                         
+------------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
-(2 rows)
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+   Filter: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+(3 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  ctid  | id 
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..f74ad415fbf 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -726,6 +726,24 @@ DROP TABLE onek_with_null;
 -- Check bitmap index path planning
 --
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -738,6 +756,30 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 8bfe3b7ba67..608b9ae7b6e 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1409,6 +1409,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index a09b27d820c..1511c99801e 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,7 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 4f57078d133..7278d047c8c 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1714,6 +1714,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroup
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.39.3 (Apple Git-145)

#179Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alexander Korotkov (#178)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 6/14/24 19:00, Alexander Korotkov wrote:

This patch could use some polishing, but I'd like to first hear some
feedback on general design.

Thanks for your time and efforts. I have skimmed through the code—there
is a minor fix in the attachment.
First and foremost, I think this approach can survive.
But generally, I'm not happy with manipulations over a restrictinfo clause:
1. While doing that, we should remember the fields of the RestrictInfo
clause. It may need to be changed, too, or it can require such a change
in the future if someone adds new logic.
2. We should remember the link to the RestrictInfo: see how the caller
of the distribute_restrictinfo_to_rels routine manipulates its fields
right after the distribution.
3. Remember caches and cached decisions inside the RestrictInfo
structure: replacing the clause should we change these fields too?

These were the key reasons why we shifted the code to the earlier stages
in the previous incarnation. So, going this way we should recheck all
the fields of this structure and analyse how the transformation can
[potentially] affect their values.

--
regards,
Andrei Lepikhov
Postgres Professional

Attachments:

v25-fix.difftext/x-patch; charset=UTF-8; name=v25-fix.diffDownload
diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c
index 0022535318..3b3249b075 100644
--- a/src/backend/optimizer/plan/initsplan.c
+++ b/src/backend/optimizer/plan/initsplan.c
@@ -2981,7 +2981,15 @@ add_base_clause_to_rel(PlannerInfo *root, Index relid,
 
 		if (list_length(orExpr->args) >= 2)
 		{
-			orExpr->args = transform_or_to_any(root, orExpr->args);
+			List *args = transform_or_to_any(root, orExpr->args);
+
+			if (list_length(args) > 1)
+				orExpr->args = args;
+			else
+			{
+				restrictinfo->orclause = NULL;
+				restrictinfo->clause = (Expr*)((RestrictInfo *)linitial(args))->clause;
+			}
 		}
 	}
 
#180Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#178)
Re: POC, WIP: OR-clause support for indexes

Hi, thank you for your work with this subject!

On 14.06.2024 15:00, Alexander Korotkov wrote:

On Mon, Apr 8, 2024 at 1:34 AM Alexander Korotkov<aekorotkov@gmail.com> wrote:

I've revised the patch. Did some beautification, improvements for
documentation, commit messages etc.

I've pushed the 0001 patch without 0002. I think 0001 is good by
itself given that there is the or_to_any_transform_limit GUC option.
The more similar OR clauses are here the more likely grouping them
into SOAP will be a win. But I've changed the default value to 5.
This will make it less invasive and affect only queries with obvious
repeating patterns. That also reduced the changes in the regression
tests expected outputs.

Regarding 0002, it seems questionable since it could cause a planning
slowdown for SAOP's with large arrays. Also, it might reduce the win
of transformation made by 0001. So, I think we should skip it for
now.

The patch has been reverted from pg17. Let me propose a new version
for pg18 based on the valuable feedback from Tom Lane [1][2].

* The transformation is moved to the stage of adding restrictinfos to
the base relation (in particular add_base_clause_to_rel()). This
leads to interesting consequences. While this allows IndexScans to
use transformed clauses, BitmapScans and SeqScans seem unaffected.
Therefore, I wasn't able to find a planning regression.
* As soon as there is no planning regression anymore, I've removed
or_to_any_transform_limit GUC, which was a source of critics.
* Now, not only Consts allowed in the SAOP's list, but also Params.
* The criticized hash based on expression jumbling has been removed.
Now, the plain list is used instead.
* OrClauseGroup now gets a legal node tag. That allows to mix it in
the list with other nodes without hacks.

I think this patch shouldn't be as good as before for optimizing
performance of large OR lists, given that BitmapScans and SeqScans
still deal with ORs. However, it allows IndexScans to handle more,
doesn't seem to cause planning regression and therefore introduce no
extra GUC. Overall, this seems like a good compromise.

This patch could use some polishing, but I'd like to first hear some
feedback on general design.

Links
1./messages/by-id/3604469.1712628736@sss.pgh.pa.us
2./messages/by-id/3649287.1712642139@sss.pgh.pa.us

Inoticedthat7librarieshave
beenaddedtosrc/backend/optimizer/plan/initsplan.c,andas faras
Iremember,TomLanehas alreadyexpresseddoubtsaboutthe
approachthatrequiresaddinga largenumberof libraries[0]/messages/by-id/3604469.1712628736@sss.pgh.pa.us, but I'm afraid
I'm out of ideas about alternative approach.

In addition,Icheckedthe fixinthe
previouscasesthatyouwroteearlier[1]/messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.comandnoticedthatSeqScancontinuesto
generate,unfortunately,withoutconvertingexpressions:

with patch:

create table test as (select (random()*10)::int x, (random()*1000) y
from generate_series(1,1000000) i); create index test_x_1_y on test (y)
where x = 1; create index test_x_2_y on test (y) where x = 2; vacuum
analyze test; SELECT 1000000 CREATE INDEX CREATE INDEX VACUUM
alena@postgres=# explain select * from test where (x = 1 or x = 2) and y
= 100; QUERY PLAN
--------------------------------------------------------------------------
Gather (cost=1000.00..12690.10 rows=1 width=12) Workers Planned: 2 ->
Parallel Seq Scan on test (cost=0.00..11690.00 rows=1 width=12) Filter:
(((x = 1) OR (x = 2)) AND (y = '100'::double precision)) (4 rows)
alena@postgres=# set enable_seqscan =off; SET alena@postgres=# explain
select * from test where (x = 1 or x = 2) and y = 100; QUERY PLAN
-------------------------------------------------------------------------
Seq Scan on test (cost=10000000000.00..10000020440.00 rows=1 width=12)
Filter: (((x = 1) OR (x = 2)) AND (y = '100'::double precision)) (2 rows)

without patch:

--------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on test (cost=8.60..12.62 rows=1 width=12) Recheck
Cond: (((y = '100'::double precision) AND (x = 1)) OR ((y =
'100'::double precision) AND (x = 2))) -> BitmapOr (cost=8.60..8.60
rows=1 width=0) -> Bitmap Index Scan on test_x_1_y (cost=0.00..4.30
rows=1 width=0) Index Cond: (y = '100'::double precision) -> Bitmap
Index Scan on test_x_2_y (cost=0.00..4.30 rows=1 width=0) Index Cond: (y
= '100'::double precision) (7 rows)

[0]: /messages/by-id/3604469.1712628736@sss.pgh.pa.us

[1]: /messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.com
/messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.com

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#181Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#180)
Re: POC, WIP: OR-clause support for indexes

On Mon, Jun 17, 2024 at 1:33 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I noticed that 7 libraries have been added to src/backend/optimizer/plan/initsplan.c, and as far as I remember, Tom Lane has already expressed doubts about the approach that requires adding a large number of libraries [0], but I'm afraid I'm out of ideas about alternative approach.

Thank you for pointing. Right, the number of extra headers included
was one of points for criticism on this patch. I'll look to move this
functionality elsewhere, while the stage of transformation could
probably be the same.

In addition, I checked the fix in the previous cases that you wrote earlier [1] and noticed that SeqScan continues to generate, unfortunately, without converting expressions:

I've rechecked and see I made wrong conclusion about this. The plan
regression is still here. But I'm still looking to workaround this
without extra GUC.

I think we need to additionally do something like [1], but take
further steps to avoid planning overhead when not necessary. In
particular, I think we should only consider splitting SAOP for bitmap
OR in the following cases:
1. There are partial indexes with predicates over target column.
2. There are multiple indexes covering target column and different
subsets of other columns presented in restrictions.
3. There are indexes covreing target column without support of SAOP
(amsearcharray == false).
Hopefully this should skip generation of useless bitmap paths in
majority cases. Thoughts?

Links.
1. /messages/by-id/67bd918d-285e-44d2-a207-f52d9a4c35e6@postgrespro.ru

------
Regards,
Alexander Korotkov
Supabase

#182Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#179)
Re: POC, WIP: OR-clause support for indexes

On Mon, Jun 17, 2024 at 7:02 AM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 6/14/24 19:00, Alexander Korotkov wrote:

This patch could use some polishing, but I'd like to first hear some
feedback on general design.

Thanks for your time and efforts. I have skimmed through the code—there
is a minor fix in the attachment.
First and foremost, I think this approach can survive.
But generally, I'm not happy with manipulations over a restrictinfo clause:
1. While doing that, we should remember the fields of the RestrictInfo
clause. It may need to be changed, too, or it can require such a change
in the future if someone adds new logic.
2. We should remember the link to the RestrictInfo: see how the caller
of the distribute_restrictinfo_to_rels routine manipulates its fields
right after the distribution.
3. Remember caches and cached decisions inside the RestrictInfo
structure: replacing the clause should we change these fields too?

These were the key reasons why we shifted the code to the earlier stages
in the previous incarnation. So, going this way we should recheck all
the fields of this structure and analyse how the transformation can
[potentially] affect their values.

I see your points. Making this at the stage of restrictinfos seems
harder, and there are open questions in the patch.

I'd like to hear how Tom feels about this. Is this the right
direction, or should we try another way?

------
Regards,
Alexander Korotkov
Supabase

#183Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#181)
Re: POC, WIP: OR-clause support for indexes

On 17.06.2024 15:11, Alexander Korotkov wrote:

On Mon, Jun 17, 2024 at 1:33 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I noticed that 7 libraries have been added to src/backend/optimizer/plan/initsplan.c, and as far as I remember, Tom Lane has already expressed doubts about the approach that requires adding a large number of libraries [0], but I'm afraid I'm out of ideas about alternative approach.

Thank you for pointing. Right, the number of extra headers included
was one of points for criticism on this patch. I'll look to move this
functionality elsewhere, while the stage of transformation could
probably be the same.

Yes, I thing so.

In addition, I checked the fix in the previous cases that you wrote earlier [1] and noticed that SeqScan continues to generate, unfortunately, without converting expressions:

I've rechecked and see I made wrong conclusion about this. The plan
regression is still here. But I'm still looking to workaround this
without extra GUC.

I think we need to additionally do something like [1], but take
further steps to avoid planning overhead when not necessary.

Iagreewithyoutoreconsiderthisplacein detailonceagain,becauseotherwiseit
lookslike we're likelyto runinto aperformanceissue.

In
particular, I think we should only consider splitting SAOP for bitmap
OR in the following cases:
1. There are partial indexes with predicates over target column.

Frankly, I see that we will need to split SAOP anyway to check it, right?

2. There are multiple indexes covering target column and different
subsets of other columns presented in restrictions.

I see two cases in one. First, we need to check whether there is an
index for the columns specified in the restrictlist, and secondly, the
index ranges for which the conditions fall into the "OR" expressions.

3. There are indexes covreing target column without support of SAOP
(amsearcharray == false).
Hopefully this should skip generation of useless bitmap paths in
majority cases. Thoughts?

I'm notsureIfullyunderstandhowusefulthiscanbe.Couldyouexplainit to mein
more detail?

Links.
1./messages/by-id/67bd918d-285e-44d2-a207-f52d9a4c35e6@postgrespro.ru

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#184Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#182)
Re: POC, WIP: OR-clause support for indexes

I'm confused, I have seen that we have two threads [1]https://commitfest.postgresql.org/48/4450/ and [2]https://commitfest.postgresql.org/48/5037/ about
this thread andIhaven'tfoundanyexplanationfor howtheydiffer.

And I don't understand, whyam Inotlistedas the authorof the patch?
Iwasdevelopingthe firstpartof the patchbeforeAndreycameto review it[3]/messages/by-id/b301dce1-09fd-72b1-834a-527ca428db5e@yandex.ru
andhisfirstparthasn'tchangedmuchsincethen.

IfIwroteto the wrongpersonaboutit,thenpleasetellme where.

[1]: https://commitfest.postgresql.org/48/4450/

[2]: https://commitfest.postgresql.org/48/5037/

[3]: /messages/by-id/b301dce1-09fd-72b1-834a-527ca428db5e@yandex.ru
/messages/by-id/b301dce1-09fd-72b1-834a-527ca428db5e@yandex.ru

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#185Robert Haas
robertmhaas@gmail.com
In reply to: Alena Rybakina (#184)
Re: POC, WIP: OR-clause support for indexes

On Fri, Jun 21, 2024 at 1:05 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I'm confused, I have seen that we have two threads [1] and [2] about this thread and I haven't found any explanation for how they differ.

And I don't understand, why am I not listed as the author of the patch? I was developing the first part of the patch before Andrey came to review it [3] and his first part hasn't changed much since then.

v25 still lists you as an author (in fact, the first author) but I
can't say why we have two CommitFest entries. Surely that's a mistake.

On the patch itself, I'm really glad we got to a design where this is
part of planning, not parsing. I'm not sure yet whether we're doing it
at the right time within the planner, but I think this *might* be
right, whereas the old way was definitely wrong.

What exactly is the strategy around OR-clauses with type differences?
If I'm reading the code correctly, the first loop requires an exact
opno match, which presumably implies that the constant-type elements
are of the same type. But then why does the second loop need to use
coerce_to_common_type?

Also, why is the array built with eval_const_expressions instead of
something like makeArrayResult? There should be no need for general
expression evaluation here if we are just dealing with constants.

+ foreach(lc2, entry->exprs)
+ {
+ RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc2);
+
+ is_pushed_down = is_pushed_down || rinfo->is_pushed_down;
+ has_clone = has_clone || rinfo->is_pushed_down;
+ security_level = Max(security_level, rinfo->security_level);
+ required_relids = bms_union(required_relids, rinfo->required_relids);
+ incompatible_relids = bms_union(incompatible_relids,
rinfo->incompatible_relids);
+ outer_relids = bms_union(outer_relids, rinfo->outer_relids);
+ }

This seems like an extremely bad idea. Smushing together things with
different security levels (or a bunch of these other properties) seems
like it will break things. Presumably we wouldn't track these
properties on a per-RelOptInfo basis unless we needed an accurate idea
of the property value for each RelOptInfo. If the values are
guaranteed to match, then it's fine, but then we don't need this code
to merge possibly-different values. If they're not guaranteed to
match, then presumably we shouldn't merge into a single OR clause
unless they do.

On a related note, it looks to me like the tests focus too much on
simple cases. It seems like it's mostly testing cases where there are
no security quals, no weird operator classes, no type mismatches, and
few joins. In the cases where there are joins, it's an inner join and
there's no distinction between an ON-qual and a WHERE-qual. I strongly
suggest adding some test cases for weirder scenarios.

+ if (!OperatorIsVisible(entry->opno))
+ namelist = lappend(namelist,
makeString(get_namespace_name(operform->oprnamespace)));
+
+ namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+ ReleaseSysCache(opertup);
+
+ saopexpr =
+ (ScalarArrayOpExpr *)
+ make_scalar_array_op(NULL,
+ namelist,
+ true,
+ (Node *) entry->expr,
+ (Node *) newa,
+ -1);

I do not think this is acceptable. We should find a way to get the
right operator into the ScalarArrayOpExpr without translating the OID
back into a name and then back into an OID.

+ /* One more trick: assemble correct clause */

This comment doesn't seem to make much sense. Some other comments
contain spelling mistakes. The patch should have comments in more
places explaining key design decisions.

+extern JumbleState *JumbleExpr(Expr *expr, uint64 *exprId);

This is no longer needed.

--
Robert Haas
EDB: http://www.enterprisedb.com

#186Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#184)
Re: POC, WIP: OR-clause support for indexes

Hi, Alena.

On Fri, Jun 21, 2024 at 8:05 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I'm confused, I have seen that we have two threads [1] and [2] about this thread and I haven't found any explanation for how they differ.

And I don't understand, why am I not listed as the author of the patch? I was developing the first part of the patch before Andrey came to review it [3] and his first part hasn't changed much since then.

If I wrote to the wrong person about it, then please tell me where.

[1] https://commitfest.postgresql.org/48/4450/

[2] https://commitfest.postgresql.org/48/5037/

[3] /messages/by-id/b301dce1-09fd-72b1-834a-527ca428db5e@yandex.ru

Sorry, I didn't notice that the [1] commitfest entry exists and
created the [2] commitfest entry. I'm removed [2].

------
Regards,
Alexander Korotkov
Supabase

#187Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Robert Haas (#185)
Re: POC, WIP: OR-clause support for indexes

On 21.06.2024 23:35, Robert Haas wrote:

On Fri, Jun 21, 2024 at 1:05 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I'm confused, I have seen that we have two threads [1] and [2] about this thread and I haven't found any explanation for how they differ.

And I don't understand, why am I not listed as the author of the patch? I was developing the first part of the patch before Andrey came to review it [3] and his first part hasn't changed much since then.

v25 still lists you as an author (in fact, the first author) but I
can't say why we have two CommitFest entries. Surely that's a mistake.

Sorry, maybe I was overreacting.

Thank you very much for taking the time to do a detailed review!

On 22.06.2024 00:07, Alexander Korotkov wrote:

Sorry, I didn't notice that the [1] commitfest entry exists and
created the [2] commitfest entry. I'm removed [2].

Thank you!

On the patch itself, I'm really glad we got to a design where this is
part of planning, not parsing. I'm not sure yet whether we're doing it
at the right time within the planner, but I think this *might* be
right, whereas the old way was definitely wrong.

It's hard to tell, but I think it might be one of the good places to
apply transformation. Let me describe a brief conclusion on the two
approaches.

In the first approach, we definitely did not process the extra "OR"
expressions in the first approach, since they were packaged as an Array.
It could lead to the fact that less planning time would be spent on the
optimizer.

Also the selectivity for Array expressions is estimated better, which
could lead to the generation of a more optimal plan, but, to be honest,
this is just an observation from changes in regression tests and, in
general, how the process of calculating the selectivity of a complex
expression works.

 SELECT * FROM check_estimated_rows('SELECT * FROM
functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');

  estimated | actual

 -----------+--------

-        99 |    100

+       100 |    100

 (1 row)

 SELECT * FROM check_estimated_rows('SELECT * FROM
functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b =
''2'')');

  estimated | actual

 -----------+--------

-        99 |    100

+       100 |    100

 (1 row)

 SELECT * FROM check_estimated_rows('SELECT * FROM
functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND
(b = ''1'' OR b = ''2'')');

  estimated | actual

 -----------+--------

-       197 |    200

+       200 |    200

In addition, we do not have new equivalence classes, since some “Or”
expressions are not available for their formation. This can result in
reduced memory and time spent generating the query plan, especially in
partitions.

Speaking of the main disadvantages, we do not give the optimizer the
opportunity to generate a plan using BitmapScan, which can lead to the
generation of a suboptimal plan, but in the current approach the same
thing happens [0]/messages/by-id/7d5aed92-d4cc-4b76-8ae0-051d182c9eec@postgrespro.ru.

And the second one might be related the lack of generation Equivalence
Classes and generation of useful pathkeysas a result, so we could miss
an optimal plan again. But I haven't caught something like this on
practice. I see we won't have such problems if we apply the
transformation later.

Overall, I have not yet noticed any very different parts from what was
in the first approach: I didn’t see any significant degradation or
improvement, which is good, but so far the main problem with the
degradation of the plan has not yet been solved, that is, we have not
escaped from the main problems.

Andrei mentioned the problem in the second approach about updating
references to expressions in RestrictInfo [1]/messages/by-id/6850c306-4e9d-40b7-8096-1f3c7d29cd9e@postgrespro.ru lists, because the can be
used in different variables during the formation of the query plan. As
the practice of Self-join removal [2]https://commitfest.postgresql.org/48/5043/ has shown, this can be expensive,
but feasible.

By applying the transformation at the analysis stage in the first
approach, because no links were created, so we did not encounter such
problems, so this approach was more suitable than the others.

[0]: /messages/by-id/7d5aed92-d4cc-4b76-8ae0-051d182c9eec@postgrespro.ru
/messages/by-id/7d5aed92-d4cc-4b76-8ae0-051d182c9eec@postgrespro.ru

[1]: /messages/by-id/6850c306-4e9d-40b7-8096-1f3c7d29cd9e@postgrespro.ru
/messages/by-id/6850c306-4e9d-40b7-8096-1f3c7d29cd9e@postgrespro.ru

[2]: https://commitfest.postgresql.org/48/5043/

What exactly is the strategy around OR-clauses with type differences?
If I'm reading the code correctly, the first loop requires an exact
opno match, which presumably implies that the constant-type elements
are of the same type. But then why does the second loop need to use
coerce_to_common_type?

It needs to transform all similar constants to one type, because some
constants of "OR" expressions can belong others, like the numeric and
int types. Due to the fact that array structure demands that all types
must be belonged to one type, so for this reason we applied this procedure.

You can find the similar strategy in transformAExprIn function, when we
transform "In" list to SaopArray expression. Frankly, initially, I took
it as the main example to make my patch.

+ if (!OperatorIsVisible(entry->opno))
+ namelist = lappend(namelist,
makeString(get_namespace_name(operform->oprnamespace)));
+
+ namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+ ReleaseSysCache(opertup);
+
+ saopexpr =
+ (ScalarArrayOpExpr *)
+ make_scalar_array_op(NULL,
+ namelist,
+ true,
+ (Node *) entry->expr,
+ (Node *) newa,
+ -1);

I do not think this is acceptable. We should find a way to get the
right operator into the ScalarArrayOpExpr without translating the OID
back into a name and then back into an OID.

I don’t really understand the reason why it’s better not to do this. Can
you explain please?

Also, why is the array built with eval_const_expressions instead of
something like makeArrayResult? There should be no need for general
expression evaluation here if we are just dealing with constants.

I'm not ready to answer this question right now, I need time to study
the use of the makeArrayResult function in the optimizer.

+ foreach(lc2, entry->exprs)
+ {
+ RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc2);
+
+ is_pushed_down = is_pushed_down || rinfo->is_pushed_down;
+ has_clone = has_clone || rinfo->is_pushed_down;
+ security_level = Max(security_level, rinfo->security_level);
+ required_relids = bms_union(required_relids, rinfo->required_relids);
+ incompatible_relids = bms_union(incompatible_relids,
rinfo->incompatible_relids);
+ outer_relids = bms_union(outer_relids, rinfo->outer_relids);
+ }
This seems like an extremely bad idea. Smushing together things with
different security levels (or a bunch of these other properties) seems
like it will break things. Presumably we wouldn't track these
properties on a per-RelOptInfo basis unless we needed an accurate idea
of the property value for each RelOptInfo. If the values are
guaranteed to match, then it's fine, but then we don't need this code
to merge possibly-different values. If they're not guaranteed to
match, then presumably we shouldn't merge into a single OR clause
unless they do.

We hadn't thought about it before, to be honest. But I agree with you
that this may be one of the reasons not to make the transformation.

On a related note, it looks to me like the tests focus too much on
simple cases. It seems like it's mostly testing cases where there are
no security quals, no weird operator classes, no type mismatches, and
few joins. In the cases where there are joins, it's an inner join and
there's no distinction between an ON-qual and a WHERE-qual. I strongly
suggest adding some test cases for weirder scenarios.
+ /* One more trick: assemble correct clause */

This comment doesn't seem to make much sense. Some other comments
contain spelling mistakes. The patch should have comments in more
places explaining key design decisions.
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *exprId);

This is no longer needed.

Agree.

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#188Robert Haas
robertmhaas@gmail.com
In reply to: Alena Rybakina (#187)
Re: POC, WIP: OR-clause support for indexes

On Fri, Jun 21, 2024 at 6:52 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

It's hard to tell, but I think it might be one of the good places to apply transformation. Let me describe a brief conclusion on the two approaches.

This explanation is somewhat difficult for me to follow. For example:

In the first approach, we definitely did not process the extra "OR" expressions in the first approach, since they were packaged as an Array. It could lead to the fact that less planning time would be spent on the optimizer.

I don't know what the "first approach" refers to, or what processing
the extra "OR" expressions means, or what it would mean to package OR
expressions as an array. If you made them into an SAOP then you'd have
an array *instead of* OR expressions, not OR expressions "packaged as
an array" but even then, they'd still be processed somewhere, unless
the patch was just wrong.

I think you should try writing this summary again and see if you can
make it a lot clearer and more precise.

I'm suspicious based that we should actually be postponing the
transformation even further. If, for example, the transformation is
advantageous for index scans and disadvantageous for bitmap scans, or
the other way around, then this approach can't help much: it either
does the transformation and all scan types are affected, or it doesn't
do it and no scan types are affected. But if you decided for each scan
whether to transform the quals, then you could handle that. Against
that, there might be increased planning cost. But, perhaps that could
be avoided somehow.

What exactly is the strategy around OR-clauses with type differences?
If I'm reading the code correctly, the first loop requires an exact
opno match, which presumably implies that the constant-type elements
are of the same type. But then why does the second loop need to use
coerce_to_common_type?

It needs to transform all similar constants to one type, because some constants of "OR" expressions can belong others, like the numeric and int types. Due to the fact that array structure demands that all types must be belonged to one type, so for this reason we applied this procedure.

The alternative that should be considered is not combining things if
the types don't match. If we're going to combine such things, we need
to be absolutely certain that type conversion cannot fail.

I do not think this is acceptable. We should find a way to get the
right operator into the ScalarArrayOpExpr without translating the OID
back into a name and then back into an OID.

I don’t really understand the reason why it’s better not to do this. Can you explain please?

One reason is that it is extra work to convert things to a name and
then back to an OID. It's got to be slower than using the OID you
already have.

The other reason is that it's error-prone. If somehow the second
lookup doesn't produce the same OID as the first lookup, bad things
will happen, possibly including security vulnerabilities. I see you've
taken steps to avoid that, like nailing down the schema, and that's
good, but it's not a good enough reason to do it like this. If we
don't have a function that can construct the node we need with the OID
rather than the name as an argument, we should invent one, not do this
sort of thing.

Also, why is the array built with eval_const_expressions instead of
something like makeArrayResult? There should be no need for general
expression evaluation here if we are just dealing with constants.

I'm not ready to answer this question right now, I need time to study the use of the makeArrayResult function in the optimizer.

OK. An important consideration here is that eval_const_expressions()
is prone to *fail* because it can call user-defined functions. We
really don't want this optimization to cause planner failure (or
queries to error out at any other stage, either). We also don't want
to end up with any security problems, which is another possible danger
when we call a function that can execute arbitrary code. It's better
to keep it simple and only do things that we know are simple and safe,
like assembling a bunch of datums that we already have into an array.

--
Robert Haas
EDB: http://www.enterprisedb.com

In reply to: Robert Haas (#188)
Re: POC, WIP: OR-clause support for indexes

On Mon, Jun 24, 2024 at 11:28 AM Robert Haas <robertmhaas@gmail.com> wrote:

It needs to transform all similar constants to one type, because some constants of "OR" expressions can belong others, like the numeric and int types. Due to the fact that array structure demands that all types must be belonged to one type, so for this reason we applied this procedure.

The alternative that should be considered is not combining things if
the types don't match. If we're going to combine such things, we need
to be absolutely certain that type conversion cannot fail.

But what about cases like this:

SELECT * FROM mytable WHERE columna = 1_000_000_000 or columna =
5_000_000_000; -- columna is int4

This is using two types, of course. 1_000_000_000 is int4, while
5_000_000_000 is bigint. If the transformation suddenly failed to work
when a constant above INT_MAX was used for the first time, then I'd
say that that's pretty surprising. That's what happens currently if
you write the same query as "WHERE columna =
any('{1_000_000_000,5_000_000_000}')", due to the way the coercion
works. That seems less surprising to me, because the user is required
to construct their own array, and users expect arrays to always have
one element type.

It would probably be okay to make the optimization not combine
things/not apply when the user gratuitously mixes different syntaxes.
For example, if a numeric constant was used, rather than an integer
constant.

Maybe it would be practical to do something with the B-Tree operator
class for each of the types involved in the optimization. You could
probably find a way for a SAOP to work against a
"heterogeneously-typed array" while still getting B-Tree index scans
-- provided the types all came from the same operator family. I'm
assuming that the index has an index column whose input opclass was a
member of that same family. That would necessitate changing the
general definition of SAOP, and adding new code to nbtree that worked
with that. But that seems doable.

I was already thinking about doing something like this, to support
index scans for "IS NOT DISTINCT FROM", or on constructs like "columna
= 5 OR columna IS NULL". That is more or less a SAOP with two values,
except that one of the values in the value NULL. I've already
implemented "nbtree SAOPs where one of the elements is a NULL" for
skip scan, which could be generalized to support these other cases.

Admittedly I'm glossing over a lot of important details here. Does it
just work for the default opclass for the type, or can we expect it to
work with a non-default opclass when that's the salient opclass (the
one used by our index)? I don't know what you'd do about stuff like
that.

--
Peter Geoghegan

#190Robert Haas
robertmhaas@gmail.com
In reply to: Peter Geoghegan (#189)
Re: POC, WIP: OR-clause support for indexes

On Mon, Jun 24, 2024 at 12:09 PM Peter Geoghegan <pg@bowt.ie> wrote:

But what about cases like this:

SELECT * FROM mytable WHERE columna = 1_000_000_000 or columna =
5_000_000_000; -- columna is int4

This is using two types, of course. 1_000_000_000 is int4, while
5_000_000_000 is bigint. If the transformation suddenly failed to work
when a constant above INT_MAX was used for the first time, then I'd
say that that's pretty surprising. That's what happens currently if
you write the same query as "WHERE columna =
any('{1_000_000_000,5_000_000_000}')", due to the way the coercion
works. That seems less surprising to me, because the user is required
to construct their own array, and users expect arrays to always have
one element type.

I am not against handling this kind of case if we can do it, but it's
more important that the patch doesn't cause gratuitous failures than
that it handles more cases.

Maybe it would be practical to do something with the B-Tree operator
class for each of the types involved in the optimization. You could
probably find a way for a SAOP to work against a
"heterogeneously-typed array" while still getting B-Tree index scans
-- provided the types all came from the same operator family. I'm
assuming that the index has an index column whose input opclass was a
member of that same family. That would necessitate changing the
general definition of SAOP, and adding new code to nbtree that worked
with that. But that seems doable.

I agree that something based on operator families might be viable. Why
would that require changing the definition of an SAOP?

Admittedly I'm glossing over a lot of important details here. Does it
just work for the default opclass for the type, or can we expect it to
work with a non-default opclass when that's the salient opclass (the
one used by our index)? I don't know what you'd do about stuff like
that.

It seems to me that it just depends on the opclasses in the query. If
the user says

WHERE column op1 const1 AND column op2 const2

...then if op1 and op2 are in the same operator family and if we can
convert one of const1 and const2 to the type of the other without risk
of failure, then we can rewrite this as an SAOP with whichever of the
two operators pertains to the target type, e.g.

column1 op1 ANY[const1,converted_const2]

I don't think the default opclass matters here, or the index properties either.

--
Robert Haas
EDB: http://www.enterprisedb.com

In reply to: Robert Haas (#190)
Re: POC, WIP: OR-clause support for indexes

On Mon, Jun 24, 2024 at 1:29 PM Robert Haas <robertmhaas@gmail.com> wrote:

I am not against handling this kind of case if we can do it, but it's
more important that the patch doesn't cause gratuitous failures than
that it handles more cases.

I agree, with the proviso that "avoid gratuitous failures" should
include cases where a query that got the optimization suddenly fails
to get the optimization, due only to some very innocuous looking
change. Such as a change from using a constant 1_000_000_000 to a
constant 5_000_000_000 in the query text. That is a POLA violation.

Maybe it would be practical to do something with the B-Tree operator
class for each of the types involved in the optimization. You could
probably find a way for a SAOP to work against a
"heterogeneously-typed array" while still getting B-Tree index scans
-- provided the types all came from the same operator family. I'm
assuming that the index has an index column whose input opclass was a
member of that same family. That would necessitate changing the
general definition of SAOP, and adding new code to nbtree that worked
with that. But that seems doable.

I agree that something based on operator families might be viable. Why
would that require changing the definition of an SAOP?

Maybe it doesn't. My point was only that the B-Tree code doesn't
necessarily need to use just one rhs type for the same column input
opclass. The definition of SOAP works (or could work) in basically the
same way, provided the "OR condition" were provably disjunct. We could
for example mix different operators for the same nbtree scan key (with
some work in nbtutils.c), just as we could support "where mycol =5 OR
mycol IS NULL" with much effort.

BTW, did you know MySQL has long supported the latter? It has a <=>
operator, which is basically a non-standard spelling of IS NOT
DISTINCT FROM. Importantly, it is indexable, whereas right now
Postgres doesn't support indexing IS NOT DISTINCT FROM. If you're
interested in working on this problem within the scope of this patch,
or some follow-up patch, I can take care of the nbtree side of things.

Admittedly I'm glossing over a lot of important details here. Does it
just work for the default opclass for the type, or can we expect it to
work with a non-default opclass when that's the salient opclass (the
one used by our index)? I don't know what you'd do about stuff like
that.

It seems to me that it just depends on the opclasses in the query. If
the user says

WHERE column op1 const1 AND column op2 const2

...then if op1 and op2 are in the same operator family and if we can
convert one of const1 and const2 to the type of the other without risk
of failure, then we can rewrite this as an SAOP with whichever of the
two operators pertains to the target type, e.g.

column1 op1 ANY[const1,converted_const2]

I don't think the default opclass matters here, or the index properties either.

Okay, good.

The docs do say "Another requirement for a multiple-data-type family
is that any implicit or binary-coercion casts that are defined between
data types included in the operator family must not change the
associated sort ordering" [1]https://www.postgresql.org/docs/devel/btree.html#BTREE-BEHAVIOR -- Peter Geoghegan. There must be precedent for this sort
of thing. Probably for merge joins.

[1]: https://www.postgresql.org/docs/devel/btree.html#BTREE-BEHAVIOR -- Peter Geoghegan
--
Peter Geoghegan

In reply to: Peter Geoghegan (#191)
Re: POC, WIP: OR-clause support for indexes

On Mon, Jun 24, 2024 at 1:46 PM Peter Geoghegan <pg@bowt.ie> wrote:

BTW, did you know MySQL has long supported the latter? It has a <=>
operator, which is basically a non-standard spelling of IS NOT
DISTINCT FROM. Importantly, it is indexable, whereas right now
Postgres doesn't support indexing IS NOT DISTINCT FROM. If you're
interested in working on this problem within the scope of this patch,
or some follow-up patch, I can take care of the nbtree side of things.

To be clear, I meant that we could easily support "where mycol = 5 OR
mycol IS NULL" and have nbtree handle that efficiently, by making it a
SAOP internally. Separately, we could also make IS NOT DISTINCT FROM
indexable, though that probably wouldn't need any work in nbtree.

--
Peter Geoghegan

#193Robert Haas
robertmhaas@gmail.com
In reply to: Peter Geoghegan (#191)
Re: POC, WIP: OR-clause support for indexes

On Mon, Jun 24, 2024 at 1:47 PM Peter Geoghegan <pg@bowt.ie> wrote:

I agree, with the proviso that "avoid gratuitous failures" should
include cases where a query that got the optimization suddenly fails
to get the optimization, due only to some very innocuous looking
change. Such as a change from using a constant 1_000_000_000 to a
constant 5_000_000_000 in the query text. That is a POLA violation.

Nope, I don't agree with that at all. If you imagine that we can
either have the optimization apply to one of those cases on the other,
or on the other hand we can have some cases that outright fail, I
think it's entirely clear that the former is better.

Maybe it doesn't. My point was only that the B-Tree code doesn't
necessarily need to use just one rhs type for the same column input
opclass. The definition of SOAP works (or could work) in basically the
same way, provided the "OR condition" were provably disjunct. We could
for example mix different operators for the same nbtree scan key (with
some work in nbtutils.c), just as we could support "where mycol =5 OR
mycol IS NULL" with much effort.

BTW, did you know MySQL has long supported the latter? It has a <=>
operator, which is basically a non-standard spelling of IS NOT
DISTINCT FROM. Importantly, it is indexable, whereas right now
Postgres doesn't support indexing IS NOT DISTINCT FROM. If you're
interested in working on this problem within the scope of this patch,
or some follow-up patch, I can take care of the nbtree side of things.

I was assuming this patch shouldn't be changing the way indexes work
at all, just making use of the facilities that we have today. More
could be done, but that might make it harder to get anything
committed.

Before we get too deep into arguing about hypotheticals, I don't think
there's any problem here that we can't solve with the infrastructure
we already have. For instance, consider this:

robert.haas=# explain select * from foo where a in (1, 1000000000000000);
QUERY PLAN
-----------------------------------------------------------
Seq Scan on foo1 foo (cost=0.00..25.88 rows=13 width=36)
Filter: (a = ANY ('{1,1000000000000000}'::bigint[]))
(2 rows)

I don't know exactly what's happening here, but it seems very similar
to what we need to have happen for this patch to work. pg_typeof(1) is
integer, and pg_typeof(1000000000000000) is bigint, and we're able to
figure out that it's OK to put both of those in an array of a single
type and without having any type conversion failures. If you replace
1000000000000000 with 2, then the array ends up being of type
integer[] rather than type bigint[], so. clearly the system is able to
reason its way through these kinds of scenarios already.

It's even possible, in my mind at least, that the patch is already
doing exactly the right things here. Even if it isn't, the problem
doesn't seem to be fundamental, because if this example can work (and
it does) then what the patch is trying to do should be workable, too.
We just have to make sure we're plugging all the pieces properly
together, and that we have comments adequately explain what is
happening and test cases that verify it. My feeling is that the patch
doesn't meet that standard today, but I think that just means it needs
some more work. I'm not arguing we have to throw the whole thing out,
or invent a lot of new infrastructure, or anything like that.

--
Robert Haas
EDB: http://www.enterprisedb.com

In reply to: Robert Haas (#193)
Re: POC, WIP: OR-clause support for indexes

On Mon, Jun 24, 2024 at 2:28 PM Robert Haas <robertmhaas@gmail.com> wrote:

On Mon, Jun 24, 2024 at 1:47 PM Peter Geoghegan <pg@bowt.ie> wrote:

I agree, with the proviso that "avoid gratuitous failures" should
include cases where a query that got the optimization suddenly fails
to get the optimization, due only to some very innocuous looking
change. Such as a change from using a constant 1_000_000_000 to a
constant 5_000_000_000 in the query text. That is a POLA violation.

Nope, I don't agree with that at all. If you imagine that we can
either have the optimization apply to one of those cases on the other,
or on the other hand we can have some cases that outright fail, I
think it's entirely clear that the former is better.

I'm just saying that not having the optimization apply to a query very
similar to one where it does apply is a POLA violation. That's another
kind of failure, for all practical purposes. Weird performance cliffs
like that are bad. It's very easy to imagine code that generates a
query text, that at some point randomly and mysteriously gets a
sequential scan. Or a much less efficient index scan.

I was assuming this patch shouldn't be changing the way indexes work
at all, just making use of the facilities that we have today. More
could be done, but that might make it harder to get anything
committed.

I was just pointing out that there is currently no good way to make
nbtree efficiently execute a qual "WHERE a = 5 OR a IS NULL", which is
almost entirely (though not quite entirely) due to a lack of any way
of expressing that idea through SQL, in a way that'll get pushed down
to the index scan node. You can write "WHERE a = any('{5,NULL')", of
course, but that doesn't treat NULL as just another array element to
match against via an IS NULL qual (due to NULL semantics).

Yeah, this is nonessential. But it's quite a nice optimization, and
seems entirely doable within the framework of the patch. It would be a
natural follow-up.

All that I'd need on the nbtree side is to get an input scan key that
directly embodies "WHERE mycol = 5 OR mycol IS NULL". That would
probably just be a scan key with sk_flags "SK_SEARCHARRAY |
SK_SEARCHNULL", that was otherwise identical to the current
SK_SEARCHARRAY scan keys.

Adopting the nbtree array index scan code to work with this would be
straightforward. SK_SEARCHNULL scan keys basically already work like
regular equality scan keys at execution time, so all that this
optimization requires on the nbtree side is teaching
_bt_advance_array_keys to treat NULL as a distinct array condition
(evaluated as IS NULL, not as = NULL).

It's even possible, in my mind at least, that the patch is already
doing exactly the right things here. Even if it isn't, the problem
doesn't seem to be fundamental, because if this example can work (and
it does) then what the patch is trying to do should be workable, too.
We just have to make sure we're plugging all the pieces properly
together, and that we have comments adequately explain what is
happening and test cases that verify it. My feeling is that the patch
doesn't meet that standard today, but I think that just means it needs
some more work. I'm not arguing we have to throw the whole thing out,
or invent a lot of new infrastructure, or anything like that.

I feel like my point about the potential for POLA violations is pretty
much just common sense. I'm not particular about the exact mechanism
by which we avoid it; only that we avoid it.

--
Peter Geoghegan

#195Nikolay Shaplov
dhyan@nataraj.su
In reply to: Alena Rybakina (#183)
Re: POC, WIP: OR-clause support for indexes

Hi!

Let me join the review process.

I am no expert in execution plans, so there would not be much help in doing
even better optimization. But I can read the code, as a person who is not familiar
with this area and help making it clear even to a person like me.

So, I am reading v25-0001-Transform-OR-clauses-to-ANY-expression.patch that
have been posted some time ago, and especially transform_or_to_any function.

@@ -38,7 +45,6 @@
int from_collapse_limit;
int join_collapse_limit;

-
/*
* deconstruct_jointree requires multiple passes over the join tree, because we
* need to finish computing JoinDomains before we start distributing quals.

Do not think that removing empty line should be part of the patch

+			/*
+			 * If the const node's (right side of operator expression) type
+			 * don't have “true” array type, then we cannnot do the
+			 * transformation. We simply concatenate the expression node.
+			 */

Guess using unicode double quotes is not the best idea here...

Now to the first part of `transform_or_to_any`

#196Nikolay Shaplov
dhyan@nataraj.su
In reply to: Alena Rybakina (#183)
Re: POC, WIP: OR-clause support for indexes

Hi!

Let me join the review process.

I am no expert in execution plans, so there would not be much help in doing
even better optimization. But I can read the code, as a person who is not
familiar
with this area and help making it clear even to a person like me.

So, I am reading v25-0001-Transform-OR-clauses-to-ANY-expression.patch that
have been posted some time ago, and especially transform_or_to_any function.

@@ -38,7 +45,6 @@
int from_collapse_limit;
int join_collapse_limit;

-
/*
* deconstruct_jointree requires multiple passes over the join tree,

because we

* need to finish computing JoinDomains before we start distributing quals.

Do not think that removing empty line should be part of the patch

+			/*
+			 * If the const node's (right side of operator 

expression) type

+ * don't have “true” array type, then we cannnot

do the

+ * transformation. We simply concatenate the

expression node.

+ */

Guess using unicode double quotes is not the best idea here...

Now to the first part of `transform_or_to_any`:

+ List *entries = NIL;

I guess the idea of entries should be explained from the start. What kind of
entries are accomulated there... I see they are added there all around the
code, but what is the purpose of that is not quite clear when you read it.

At the first part of `transform_or_to_any` function, you costanly repeat two
lines, like a mantra:

+ entries = lappend(entries, rinfo);
+ continue;

"If something is wrong -- do that mantra"

From my perspective, if you have to repeat same code again and again, then
most probably you have some issues with architecture of the code. If you
repeat some code again and again, you need to try to rewrite the code, the
way, that part is repeated only once.

In that case I would try to move the most of the first loop of
`transform_or_to_any` to a separate function (let's say its name is
prepare_single_or), that will do all the checks, if this or is good for us;
return NULL if it does not suits our purposes (and in this case we do "entries
= lappend(entries, rinfo); continue" in the main code, but only once) or
return pointer to some useful data if this or clause is good for our purposes.

This, I guess will make that part more clear and easy to read, without
repeating same "lappend mantra" again and again.

Will continue digging into the code tomorrow.

P.S. Sorry for sending partly finished email. Pressed Ctrl+Enter
accidentally... With no way to make it back :-(((

#197Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Peter Geoghegan (#194)
Re: POC, WIP: OR-clause support for indexes

On 24.06.2024 18:28, Robert Haas wrote:

On Fri, Jun 21, 2024 at 6:52 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

It's hard to tell, but I think it might be one of the good places to apply transformation. Let me describe a brief conclusion on the two approaches.

This explanation is somewhat difficult for me to follow. For example:

In the first approach, we definitely did not process the extra "OR" expressions in the first approach, since they were packaged as an Array. It could lead to the fact that less planning time would be spent on the optimizer.

I don't know what the "first approach" refers to, or what processing
the extra "OR" expressions means, or what it would mean to package OR
expressions as an array. If you made them into an SAOP then you'd have
an array*instead of* OR expressions, not OR expressions "packaged as
an array" but even then, they'd still be processed somewhere, unless
the patch was just wrong.

I think you should try writing this summary again and see if you can
make it a lot clearer and more precise.

I'm suspicious based that we should actually be postponing the
transformation even further. If, for example, the transformation is
advantageous for index scans and disadvantageous for bitmap scans, or
the other way around, then this approach can't help much: it either
does the transformation and all scan types are affected, or it doesn't
do it and no scan types are affected. But if you decided for each scan
whether to transform the quals, then you could handle that. Against
that, there might be increased planning cost. But, perhaps that could
be avoided somehow.

Sorry, you are right and I'll try to explain more precisely. The
firstapproach isthefirstpartof the patch,wherewemade "Or" expressions
into an SAOPatan earlystageof plangeneration[0]/messages/by-id/attachment/156971/v21-0001-Transform-OR-clauses-to-ANY-expression.patch,the secondonewasthe one
proposedby A.Korotkov[1]/messages/by-id/CAPpHfduah1PLzajBJFDmp7+MZuaWYpie2p+GsV0r03fcGghQ-g@mail.gmail.com.

So, when we made "OR" expressions into an SAOPat the post-parsing stage
of the plan generation [0]/messages/by-id/attachment/156971/v21-0001-Transform-OR-clauses-to-ANY-expression.patch, we definitely did not process the
redundantexpressions"OR" expressions there (for example,duplicates),
since they were transformed to SAOP expression. Furthermore, the list of
OR expressions can be significantly reduced, since constants belonging
to the same predicate will already be converted into an SAOP expression.
I assume this may reduce planning time, as I know several places in the
optimizer where these lists of "OR" expressions are scanned several times.
Also the selectivity for SAOP expressions is estimated better, which
could lead to the generation of a more optimal plan, but, to be honest,
this is just an observation from changes in regression tests and, in
general, how the process of calculating the selectivity of a complex
expression works. And I think it needs further consideration. SELECT *
FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
(a = 1 OR a = 51) AND b = ''1'''); estimated | actual
-----------+-------- - 99 | 100 + 100 | 100 (1 row) SELECT * FROM
check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1
OR a = 51) AND (b = ''1'' OR b = ''2'')'); estimated | actual
-----------+-------- - 99 | 100 + 100 | 100 (1 row) SELECT * FROM
check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1
OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')'); estimated
| actual -----------+-------- - 197 | 200 + 200 | 200 Speaking of the
main disadvantages, we do not give the optimizer the opportunity to
generate a plan using BitmapScan, which can lead to the generation of a
suboptimal plan, but in the current approach the same thing happens [2]/messages/by-id/7d5aed92-d4cc-4b76-8ae0-051d182c9eec@postgrespro.ru.
And you mentioned about it before:

On 24.06.2024 18:28, Robert Haas wrote:

I'm suspicious based that we should actually be postponing the
transformation even further. If, for example, the transformation is
advantageous for index scans and disadvantageous for bitmap scans, or
the other way around, then this approach can't help much: it either
does the transformation and all scan types are affected, or it doesn't
do it and no scan types are affected. But if you decided for each scan
whether to transform the quals, then you could handle that. Against
that, there might be increased planning cost. But, perhaps that could
be avoided somehow.

Andrei mentioned the problem, which might be caused by the
transformation on the later stage of optimization is updating references
to expressions in RestrictInfo [3]/messages/by-id/6850c306-4e9d-40b7-8096-1f3c7d29cd9e@postgrespro.ru lists, because they can be used in
different parts during the formation of the query plan. As the practice
of Self-join removal [4]https://commitfest.postgresql.org/48/5043/ has shown, this can be expensive, but feasible.
By applying the transformation at the analysis stage [0]/messages/by-id/attachment/156971/v21-0001-Transform-OR-clauses-to-ANY-expression.patch, because no
links were created, so we did not encounter such problems, so this
approach was more suitable than the others.

If some things were not clear enough, let me know.

[0]: /messages/by-id/attachment/156971/v21-0001-Transform-OR-clauses-to-ANY-expression.patch
/messages/by-id/attachment/156971/v21-0001-Transform-OR-clauses-to-ANY-expression.patch
[1]: /messages/by-id/CAPpHfduah1PLzajBJFDmp7+MZuaWYpie2p+GsV0r03fcGghQ-g@mail.gmail.com
/messages/by-id/CAPpHfduah1PLzajBJFDmp7+MZuaWYpie2p+GsV0r03fcGghQ-g@mail.gmail.com
[2]: /messages/by-id/7d5aed92-d4cc-4b76-8ae0-051d182c9eec@postgrespro.ru
/messages/by-id/7d5aed92-d4cc-4b76-8ae0-051d182c9eec@postgrespro.ru
[3]: /messages/by-id/6850c306-4e9d-40b7-8096-1f3c7d29cd9e@postgrespro.ru
/messages/by-id/6850c306-4e9d-40b7-8096-1f3c7d29cd9e@postgrespro.ru
[4]: https://commitfest.postgresql.org/48/5043/

On 24.06.2024 18:28, Robert Haas wrote:

The alternative that should be considered is not combining things if
the types don't match. If we're going to combine such things, we need
to be absolutely certain that type conversion cannot fail.

Peter,Robert,thanksforthe detaileddiscussion,I realizedthathereyou
needto lookcarefullyatthe patch. In general, it comes out, I need to pay
attention and highlight the cases where POLA violation occurs

On 24.06.2024 18:28, Robert Haas wrote:

One reason is that it is extra work to convert things to a name and
then back to an OID. It's got to be slower than using the OID you
already have.

The other reason is that it's error-prone. If somehow the second
lookup doesn't produce the same OID as the first lookup, bad things
will happen, possibly including security vulnerabilities. I see you've
taken steps to avoid that, like nailing down the schema, and that's
good, but it's not a good enough reason to do it like this. If we
don't have a function that can construct the node we need with the OID
rather than the name as an argument, we should invent one, not do this
sort of thing.

I understood. I'll try to fix it.

#198Nikolay Shaplov
dhyan@nataraj.su
In reply to: Nikolay Shaplov (#196)
Re: POC, WIP: OR-clause support for indexes

В письме от понедельник, 24 июня 2024 г. 23:51:56 MSK пользователь Nikolay
Shaplov написал:

So, I continue reading the patch.

I see there is `entries` variable in the code, that is the list of
`RestrictInfo` objects and `entry` that is `OrClauseGroup` object.

This naming is quite misguiding (at least for me).

`entries` variable name can be used, as we deal only with RestrictInfo
entries here. It is kind of "generic" type. Though naming it
`restric_info_entry` might make te code more readable.

But when we come to an `entry` variable, it is very specific entry, it should
be `OrClauseGroup` entry, not just any entry. So I would suggest to name this
variable `or_clause_group_entry`, or even `or_clause_group` , so when we meet
this variable in the middle of the code, we can get the idea what we are
dealing with, without scrolling code up.

Variable naming is very important thing. It can drastically improve (or ruin)
code readability.

========

Also I see some changes in the tests int this patch. There are should be tests
that check that this new feature works well. And there are test whose behavior
have been just accidentally affected.

I whould suggest to split these tests into two patches, as they should be
reviewed in different ways. Functionality tests should be thoroughly checked
that all stuff we added is properly tested, and affected tests should be checked
that nothing important is not broken. It would be more easy to check if these
are two different patches.

I would also suggest to add to the commit message of affected tests changes
some explanation why this changes does not really breaks anything. This will
do the checking more simple.

To be continued.

--
Nikolay Shaplov aka Nataraj
Fuzzing Engineer at Postgres Professional
Matrix IM: @dhyan:nataraj.su

#199Robert Haas
robertmhaas@gmail.com
In reply to: Alena Rybakina (#197)
Re: POC, WIP: OR-clause support for indexes

I think maybe replying to multiple emails with a single email is
something you'd be better off doing less often.

On Tue, Jun 25, 2024 at 7:14 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

Sorry, you are right and I'll try to explain more precisely. The first approach is the first part of the patch, where we made "Or" expressions into an SAOP at an early stage of plan generation [0], the second one was the one proposed by A.Korotkov [1].

[0]: isn't doing anything "at an early stage of plan generation". It's changing something in *the parser*. The parser and planner are VERY different stages of query parsing, and it's really important to keep them separate mentally and in discussions. We should not be changing anything about the query in the parser, because that will, as Alexander also pointed out, change what gets stored if the user does something like CREATE VIEW whatever AS SELECT ...; and we should, for the most part, be storing the query as the user entered it, not some transformed version of it. Further, at the parser stage, we do not know the cost of anything, so we can only transform things when the transformed version is always - or practically always - going to be cheaper than the untransformed version.
changing something in *the parser*. The parser and planner are VERY
different stages of query parsing, and it's really important to keep
them separate mentally and in discussions. We should not be changing
anything about the query in the parser, because that will, as
Alexander also pointed out, change what gets stored if the user does
something like CREATE VIEW whatever AS SELECT ...; and we should, for
the most part, be storing the query as the user entered it, not some
transformed version of it. Further, at the parser stage, we do not
know the cost of anything, so we can only transform things when the
transformed version is always - or practically always - going to be
cheaper than the untransformed version.

On 24.06.2024 18:28, Robert Haas wrote:
Andrei mentioned the problem, which might be caused by the transformation on the later stage of optimization is updating references to expressions in RestrictInfo [3] lists, because they can be used in different parts during the formation of the query plan. As the practice of Self-join removal [4] has shown, this can be expensive, but feasible. By applying the transformation at the analysis stage [0], because no links were created, so we did not encounter such problems, so this approach was more suitable than the others.

The link you provided for [3] doesn't show me exactly what code you're
talking about, but I can see why mutating a RestrictInfo after
creating it could be problematic. However, I'm not proposing that, and
I don't think it's a good idea. Instead of mutating an existing data
structure after it's been created, we want to get each data structure
correct at the moment that it is created. What that means is that at
each stage of processing, whenever we create a new in-memory data
structure, we have an opportunity to make changes along the way.

For instance, let's say we have a RestrictInfo and we are creating a
Path, perhaps via create_index_path(). One argument to that function
is a list of indexclauses. The indexclauses are derived from the
RestrictInfo list associated with the RelOptInfo. We take some subset
of those quals that are deemed to be indexable and we reorder them and
maybe change a few things and we build this new list of indexclauses
that is then passed to create_index_path(). The RelOptInfo's list of
RestrictInfos is not changed -- only the new list of clauses derived
from it is being built up here, without any mutation of the original
structure.

This is the kind of thing that this patch can and probably should do.
Join removal is quite awkward, as you rightly point out, because we
end up modifying existing data structures after they've been created,
and that requires us to run around and fix up a bunch of stuff, and
that can have bugs. Whenever possible, we don't want to do it that
way. Instead, we want to pick points in the processing when we're
anyway constructing some new structure and use that as an opportunity
to do transformations when building the new structure that incorporate
optimizations that make sense.

--
Robert Haas
EDB: http://www.enterprisedb.com

#200Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Robert Haas (#199)
Re: POC, WIP: OR-clause support for indexes

On 26.06.2024 23:19, Robert Haas wrote:

I think maybe replying to multiple emails with a single email is
something you'd be better off doing less often.

Ok, I won't do this in the future. After thinkingit over,I
realizedthatit turnedout to be somekindof messinthe end.

On Tue, Jun 25, 2024 at 7:14 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

Sorry, you are right and I'll try to explain more precisely. The first approach is the first part of the patch, where we made "Or" expressions into an SAOP at an early stage of plan generation [0], the second one was the one proposed by A.Korotkov [1].

[0] isn't doing anything "at an early stage of plan generation". It's
changing something in *the parser*. The parser and planner are VERY
different stages of query parsing, and it's really important to keep
them separate mentally and in discussions.

Thanks for the detailed explanation, I'm always glad to learn new things
for myself)

To be honest, I had an intuitive feeling that the transformation was
called in the analyzer stage, but I wasn't sure about it, so I tried to
summarize it.

As for the fact that in general all this can be divided into two large
stages, parsing and planner is a little new to me. I have reread the
documentation [0]https://www.postgresql.org/docs/current/planner-optimizer.html andI foundinformationaboutitthere.

Beforethat, Iwas guidedbyinformationfromthe
CarnegieMellonUniversitylecture andthe BruceMamjian report[1]https://momjian.us/main/writings/pgsql/optimizer.pdf,whichwas
wrongonmypart.

By the way,it turnsout that the queryrewritingstagereferstoan
independentstage,whichis locatedbetweenthe
parserstageandtheplanner/optimizer. I found it from the documentation [2]https://www.postgresql.org/docs/16/rule-system.html.

[0]: https://www.postgresql.org/docs/current/planner-optimizer.html

[1]: https://momjian.us/main/writings/pgsql/optimizer.pdf

[2]: https://www.postgresql.org/docs/16/rule-system.html

We should not be changing
anything about the query in the parser, because that will, as
Alexander also pointed out, change what gets stored if the user does
something like CREATE VIEW whatever AS SELECT ...; and we should, for
the most part, be storing the query as the user entered it, not some
transformed version of it. Further, at the parser stage, we do not
know the cost of anything, so we can only transform things when the
transformed version is always - or practically always - going to be
cheaper than the untransformed version.

Thank you, now it has become clear to me why it is so important to leave
the transformation at the planner stage.

On 24.06.2024 18:28, Robert Haas wrote:
Andrei mentioned the problem, which might be caused by the transformation on the later stage of optimization is updating references to expressions in RestrictInfo [3] lists, because they can be used in different parts during the formation of the query plan. As the practice of Self-join removal [4] has shown, this can be expensive, but feasible. By applying the transformation at the analysis stage [0], because no links were created, so we did not encounter such problems, so this approach was more suitable than the others.

The link you provided for [3] doesn't show me exactly what code you're
talking about, but I can see why mutating a RestrictInfo after
creating it could be problematic. However, I'm not proposing that, and
I don't think it's a good idea. Instead of mutating an existing data
structure after it's been created, we want to get each data structure
correct at the moment that it is created. What that means is that at
each stage of processing, whenever we create a new in-memory data
structure, we have an opportunity to make changes along the way.

For instance, let's say we have a RestrictInfo and we are creating a
Path, perhaps via create_index_path(). One argument to that function
is a list of indexclauses. The indexclauses are derived from the
RestrictInfo list associated with the RelOptInfo. We take some subset
of those quals that are deemed to be indexable and we reorder them and
maybe change a few things and we build this new list of indexclauses
that is then passed to create_index_path(). The RelOptInfo's list of
RestrictInfos is not changed -- only the new list of clauses derived
from it is being built up here, without any mutation of the original
structure.

This is the kind of thing that this patch can and probably should do.
Join removal is quite awkward, as you rightly point out, because we
end up modifying existing data structures after they've been created,
and that requires us to run around and fix up a bunch of stuff, and
that can have bugs. Whenever possible, we don't want to do it that
way. Instead, we want to pick points in the processing when we're
anyway constructing some new structure and use that as an opportunity
to do transformations when building the new structure that incorporate
optimizations that make sense.

Thanks for the idea! I hadn't thought in this direction before, but it
really might just work and solve all our original problems.
By the way, I saw that the optimizer is smart enough to eliminate
duplicates. Below I have conducted a couple of examples where he decides
for himself which expression is more profitable for him to leave.
Wejustneedto addthistransformation,andthe optimizerwillchoosethe
appropriateone)

alena@postgres=# explain select * from x where (a = 1 or a = 2) and a in
(1,2);

                             QUERY PLAN
--------------------------------------------------------------------
 Index Only Scan using a_idx on x  (cost=0.28..8.61 rows=1 width=4)
   Index Cond: (a = ANY ('{1,2}'::integer[]))
(2 rows)

alena@postgres=# explain select * from x where a < 3 and (a = 1 or a =
2) and a = ANY(ARRAY[1,2]);
                             QUERY PLAN
--------------------------------------------------------------------
 Index Only Scan using a_idx on x  (cost=0.28..8.60 rows=1 width=4)
   Index Cond: ((a < 3) AND (a = ANY ('{1,2}'::integer[])))
(2 rows)

ItworksforKorotkov's casetoo,asIseeit:

alena@postgres=# create table test as (select (random()*10)::int x,
(random()*1000) y from generate_series(1,1000000) i); create index
test_x_1_y on test (y) where x = 1; create index test_x_2_y on test (y)
where x = 2; vacuum analyze test; SELECT 1000000 CREATE INDEX CREATE
INDEX VACUUM alena@postgres=# explain select * from test where (x = 1 or
x = 2) and y = 100 and x in (1,2); QUERY PLAN
--------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on test (cost=8.60..12.62 rows=1 width=12) Recheck
Cond: (((y = '100'::double precision) AND (x = 1)) OR ((y =
'100'::double precision) AND (x = 2))) -> BitmapOr (cost=8.60..8.60
rows=1 width=0) -> Bitmap Index Scan on test_x_1_y (cost=0.00..4.30
rows=1 width=0) Index Cond: (y = '100'::double precision) -> Bitmap
Index Scan on test_x_2_y (cost=0.00..4.30 rows=1 width=0) Index Cond: (y
= '100'::double precision) (7 rows)

I noticed that the distribute_quals_to_rels function launches at the
stage when it is necessary to generate RestrictInfo lists for relation -
it might be a suitable place for applying transformation.
So, instead of completely replacing the list, we should form a complex
BoolExpr structure with the "AND" operator, which should contain two
expressions, where one of them is BoolExpr with the "OR" operator and
the second is ScalarArrayOpExpr.

Tobe honest,I've alreadystartedwritingcodetodothis,butI'm facedwitha
misunderstandingof howto correctlycreatea
conditionfor"OR"expressionsthatare notsubjectto transformation.For
example,the expressions b=1in the query below:

alena@postgres=# explain select * from x where ( (a =5 or a=4) and a =
ANY(ARRAY[5,4])) or (b=1); QUERY PLAN
----------------------------------------------------------------------------------
Seq Scan on x (cost=0.00..123.00 rows=1 width=8) Filter: ((((a = 5) OR
(a = 4)) AND (a = ANY ('{5,4}'::integer[]))) OR (b = 1)) (2 rows)

I see that two expressions have remained unchanged and it only works for
"AND" binary operations.

But I think it might be worth applying this together, where does the
optimizer generate indexes (build_paths_for_OR function)?

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#201Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#200)
Re: POC, WIP: OR-clause support for indexes

Tobe honest,I've alreadystartedwritingcodetodothis,butI'm facedwitha
misunderstandingof howto correctlycreatea
conditionfor"OR"expressionsthatare notsubjectto transformation.

For example,the expressions b=1in the query below:

alena@postgres=# explain select * from x where ( (a =5 or a=4) and a =
ANY(ARRAY[5,4])) or (b=1); QUERY PLAN
----------------------------------------------------------------------------------
Seq Scan on x (cost=0.00..123.00 rows=1 width=8) Filter: ((((a = 5) OR
(a = 4)) AND (a = ANY ('{5,4}'::integer[]))) OR (b = 1)) (2 rows)

I see that two expressions have remained unchanged and it only works
for "AND" binary operations.

But I think it might be worth applying this together, where does the
optimizer generate indexes (build_paths_for_OR function)?

Sorry, it works) I needed to create one more index for b column.

Just in case, I gave an example of a complete case, otherwise it might
not be entirely clear:

alena@postgres=# create table x (a int, b int);
CREATE TABLE
alena@postgres=# create index a_idx on x(a);
                        insert into x select id,id from
generate_series(1, 5000) as id;
CREATE INDEX
INSERT 0 5000
alena@postgres=# analyze;
ANALYZE

alena@postgres=# explain select * from x where ( (a =5 or a=4) and a =
ANY(ARRAY[5,4])) or (b=1); QUERY PLAN
----------------------------------------------------------------------------------
Seq Scan on x (cost=0.00..123.00 rows=1 width=8) Filter: ((((a = 5) OR
(a = 4)) AND (a = ANY ('{5,4}'::integer[]))) OR (b = 1)) (2 rows)

alena@postgres=# create index b_idx on x(b);

CREATE INDEX

alena@postgres=# explain select * from x where ( (a =5 or a=4) and a =
ANY(ARRAY[5,4]))  or (b=1);
                                QUERY PLAN
--------------------------------------------------------------------------
 Bitmap Heap Scan on x  (cost=12.87..21.68 rows=1 width=8)
   Recheck Cond: ((a = ANY ('{5,4}'::integer[])) OR (b = 1))
   ->  BitmapOr  (cost=12.87..12.87 rows=3 width=0)
         ->  Bitmap Index Scan on a_idx  (cost=0.00..8.58 rows=2 width=0)
               Index Cond: (a = ANY ('{5,4}'::integer[]))
         ->  Bitmap Index Scan on b_idx  (cost=0.00..4.29 rows=1 width=0)
               Index Cond: (b = 1)
(7 rows)

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#202Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Nikolay Shaplov (#198)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi! Thank you for your review! Sorryforthe delayin responding.

Irewrotethe patchasyourequested,butnowI'm facedwiththe problemof
processingthe elementsof the or_entries list.For somereason,
thepointerto thelistis cleared and I couldn't find the place where it
happened.MaybeI'mmissingsomethingsimpleinviewof the heavyworkloadright
now,butmaybeyou'll seea problem?Ihave displayedpart of stackbelow.

#5 0x00005b0f6d9f6a6a in ExceptionalCondition
(conditionName=0x5b0f6dbb74f7 "IsPointerList(list)",
fileName=0x5b0f6dbb7418 "list.c", lineNumber=341) at assert.c:66 #6
0x00005b0f6d5dc3ba in lappend (list=0x5b0f6eec5ca0,
datum=0x5b0f6eec0d90) at list.c:341 #7 0x00005b0f6d69230c in
transform_or_to_any (root=0x5b0f6eeb13c8, orlist=0x5b0f6eec57c0) at
initsplan.c:2818 #8 0x00005b0f6d692958 in add_base_clause_to_rel
(root=0x5b0f6eeb13c8, relid=1, restrictinfo=0x5b0f6eec5990) at
initsplan.c:2982 #9 0x00005b0f6d692e5f in
distribute_restrictinfo_to_rels (root=0x5b0f6eeb13c8,
restrictinfo=0x5b0f6eec5990) at initsplan.c:3175 #10 0x00005b0f6d691bf2
in distribute_qual_to_rels (root=0x5b0f6eeb13c8, clause=0x5b0f6eec0fc0,
jtitem=0x5b0f6eec4330, sjinfo=0x0, security_level=0,
qualscope=0x5b0f6eec4730, ojscope=0x0, outerjoin_nonnullable=0x0,
incompatible_relids=0x0, allow_equivalence=true, has_clone=false,
is_clone=false, postponed_oj_qual_list=0x0) at initsplan.c:2576 #11
0x00005b0f6d69146f in distribute_quals_to_rels (root=0x5b0f6eeb13c8,
clauses=0x5b0f6eec0bb0, jtitem=0x5b0f6eec4330, sjinfo=0x0,
security_level=0, qualscope=0x5b0f6eec4730, ojscope=0x0,
outerjoin_nonnullable=0x0, incompatible_relids=0x0,
allow_equivalence=true, has_clone=false, is_clone=false,
postponed_oj_qual_list=0x0) at initsplan.c:2144

Thisis stillthe firstiterationof the fixesyouhave proposed,soI have
attachedthe patchindiffformat.I rewroteit,asyousuggestedinthe
firstletter[0]/messages/by-id/3381819.e9J7NaK4W3@thinkpad-pgpro.Icreateda separatefunctionthattriesto forman
OrClauseGroup node,butifit failsinthis, it returnsfalse,otherwiseit
processesthe generatedelementaccordingtowhat it found-eitheraddsit to
thelistasnew,oraddsa constantto anexistingone.

Ialsodividedonegenerallistof
suitableforconversionandunsuitableintotwodifferentones:appropriate_entriesandor_entries.Nowweare
onlylookinginthe listof suitableelementstoformANYexpr.

Thishelpsusto get ridofrepetitionsinthe codeyoumentioned.
Pleasewriteifthisis notthelogicthatyouhave seenbefore.

[0]: /messages/by-id/3381819.e9J7NaK4W3@thinkpad-pgpro
/messages/by-id/3381819.e9J7NaK4W3@thinkpad-pgpro

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

Attachments:

or.difftext/x-patch; charset=UTF-8; name=or.diffDownload
diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c
index e2c68fe6f99..1fdada54e23 100644
--- a/src/backend/optimizer/plan/initsplan.c
+++ b/src/backend/optimizer/plan/initsplan.c
@@ -14,9 +14,13 @@
  */
 #include "postgres.h"
 
+#include "catalog/namespace.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_type.h"
+#include "common/hashfn.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/clauses.h"
 #include "optimizer/cost.h"
 #include "optimizer/inherit.h"
@@ -29,8 +33,11 @@
 #include "optimizer/planner.h"
 #include "optimizer/restrictinfo.h"
 #include "parser/analyze.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 #include "rewrite/rewriteManip.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/rel.h"
 #include "utils/typcache.h"
 
@@ -38,7 +45,6 @@
 int			from_collapse_limit;
 int			join_collapse_limit;
 
-
 /*
  * deconstruct_jointree requires multiple passes over the join tree, because we
  * need to finish computing JoinDomains before we start distributing quals.
@@ -2617,6 +2623,287 @@ check_redundant_nullability_qual(PlannerInfo *root, Node *clause)
 	return false;
 }
 
+static bool
+try_get_appropriable_group(RestrictInfo *rinfo, List **appropriate_group)
+{
+	OpExpr	   *orqual;
+	Node	   *const_expr;
+	Node	   *nconst_expr;
+	Oid			opno;
+	Oid			consttype;
+	Node	   *leftop,
+				*rightop;
+	ListCell   *lc2;
+	bool found = false;
+	OrClauseGroup *entry;
+
+	if (!IsA(rinfo, RestrictInfo) || !IsA(rinfo->clause, OpExpr))
+	{
+		return false;
+	}
+
+	orqual = (OpExpr *) rinfo->clause;
+	opno = orqual->opno;
+	if (get_op_rettype(opno) != BOOLOID)
+	{
+		/* Only operator returning boolean suits OR -> ANY transformation */
+		return false;
+	}
+
+	/*
+		* Detect the constant side of the clause. Recall non-constant
+		* expression can be made not only with Vars, but also with Params,
+		* which is not bonded with any relation. Thus, we detect the const
+		* side - if another side is constant too, the orqual couldn't be an
+		* OpExpr.  Get pointers to constant and expression sides of the qual.
+		*/
+	leftop = get_leftop(orqual);
+	if (IsA(leftop, RelabelType))
+		leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+	rightop = get_rightop(orqual);
+	if (IsA(rightop, RelabelType))
+		rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+	if (IsA(leftop, Const) || IsA(leftop, Param))
+	{
+		opno = get_commutator(opno);
+
+		if (!OidIsValid(opno))
+		{/* commutator doesn't exist, we can't reverse the order */
+			return false;
+		}
+
+		nconst_expr = get_rightop(orqual);
+		const_expr = get_leftop(orqual);
+	}
+	else if (IsA(rightop, Const) || IsA(rightop, Param))
+	{
+		const_expr = get_rightop(orqual);
+		nconst_expr = get_leftop(orqual);
+	}
+	else
+	{
+		return false;
+	}
+
+	/*
+		* Forbid transformation for composite types, records, and volatile
+		* expressions.
+		*/
+	consttype = exprType(const_expr);
+	if (type_is_rowtype(exprType(const_expr)) ||
+		type_is_rowtype(consttype) ||
+		contain_volatile_functions((Node *) nconst_expr))
+	{
+		return false;
+	}
+
+	entry = makeNode(OrClauseGroup);
+
+	foreach(lc2, *appropriate_group)
+	{
+
+		if (!IsA(lfirst(lc2), OrClauseGroup))
+			Assert(0);
+
+		entry = (OrClauseGroup *) lfirst(lc2);
+
+		if (entry->opno == opno &&
+			entry->consttype == consttype &&
+			entry->inputcollid == exprCollation(const_expr) &&
+			equal(entry->expr, nconst_expr))
+		{
+			found = true;
+			break;
+		}
+	}
+
+	if (!found)
+	{
+		entry->expr = (Expr *) nconst_expr;
+		entry->exprs = list_make1((void *) orqual);
+		entry->opno = opno;
+		entry->inputcollid = exprCollation(const_expr);
+		entry->consttype = consttype;
+		entry->consts = list_make1(const_expr);
+		*appropriate_group = lappend(*appropriate_group, entry);
+	}
+	else
+	{
+		entry->consts = lappend(entry->consts, const_expr);
+		entry->exprs = lappend(entry->exprs, (void *) orqual);
+	}
+
+	return true;
+}
+
+/*
+ * transform_or_to_any -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to SAOP expressions.
+ *
+ * This transformation groups two-sided equality expression.  One side of
+ * such an expression must be a plain constant or constant expression.  The
+ * other side must be a variable expression without volatile functions.
+ * To group quals, opno, inputcollid of variable expression, and type of
+ * constant expression must be equal too.
+ *
+ * The grouping technique is based on the equivalence of variable sides of
+ * the expression: using exprId and equal() routine, it groups constant sides
+ * of similar clauses into an array.  After the grouping procedure, each
+ * couple ('variable expression' and 'constant array') forms a new SAOP
+ * operation, which is added to the args list of the returning expression.
+ */
+static List *
+transform_or_to_any(PlannerInfo *root, List *orlist)
+{
+	List	   *appropriate_entries = NIL;
+	List	   *or_entries = NIL;
+	ListCell   *lc;
+	int			len_ors = list_length(orlist);
+	OrClauseGroup *entry = NULL;
+	bool found;
+
+	Assert(len_ors >= 2);
+
+	foreach(lc, orlist)
+	{
+		RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
+
+		/*
+		 * Add the entry to the list.  It is needed exclusively to manage
+		 * the problem with the order of transformed clauses in explain.
+		 * Hash value can depend on the platform and version.  Hence,
+		 * sequental scan of the hash table would prone to change the
+		 * order of clauses in lists and, as a result, break regression
+		 * tests accidentially.
+		 */
+		found = try_get_appropriable_group(rinfo, &appropriate_entries);
+
+		if (!found)
+			or_entries = lappend(or_entries, (void *) rinfo->clause);
+	}
+
+	/* Let's convert each group of clauses to an ANY expression. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of consts
+	 * more than 1. trivial groups move to OR-list again
+	 */
+
+	foreach(lc, appropriate_entries)
+	{
+		Oid			scalar_type;
+		Oid			array_type;
+
+		if (!IsA(lfirst(lc), OrClauseGroup))
+		{
+			Assert(0);
+		}
+
+		entry = (OrClauseGroup *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element returns origin expression into the BoolExpr
+			 * args list unchanged.
+			 */
+			list_free(entry->consts);
+			or_entries = lappend(or_entries, linitial(entry->exprs));
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+		scalar_type = entry->consttype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+			InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common type
+			 * and build an ArrayExpr for them.
+			 */
+			List	   *aexprs = NIL;
+			ArrayExpr  *newa = NULL;
+			ScalarArrayOpExpr *saopexpr = NULL;
+			HeapTuple	opertup;
+			Form_pg_operator operform;
+			List	   *namelist = NIL;
+			ListCell   *lc2;
+
+			foreach(lc2, entry->consts)
+			{
+				Node	   *node = (Node *) lfirst(lc2);
+
+				node = coerce_to_common_type(NULL, node, scalar_type,
+											 "OR ANY Transformation");
+				aexprs = lappend(aexprs, node);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			/*
+			 * Try to cast this expression to Const. Due to current strict
+			 * transformation rules it should be done [almost] every time.
+			 */
+			newa = (ArrayExpr *) eval_const_expressions(NULL, (Node *) newa);
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+				make_scalar_array_op(NULL,
+									 namelist,
+									 true,
+									 (Node *) entry->expr,
+									 (Node *) newa,
+									 -1);
+			saopexpr->inputcollid = entry->inputcollid;
+
+			or_entries = lappend(or_entries, (void *) saopexpr);
+		}
+		else
+		{
+			/*
+			 * If the const node's (right side of operator expression) type
+			 * don't have “true” array type, then we cannnot do the
+			 * transformation. We simply concatenate the expression node.
+			 */
+			list_free(entry->consts);
+			or_entries = list_concat(or_entries, entry->exprs);
+		}
+	}
+	list_free(appropriate_entries);
+
+	/* One more trick: assemble correct clause */
+	return or_entries;
+}
+
 /*
  * add_base_clause_to_rel
  *		Add 'restrictinfo' as a baserestrictinfo to the base relation denoted
@@ -2677,6 +2964,36 @@ add_base_clause_to_rel(PlannerInfo *root, Index relid,
 		}
 	}
 
+	if (restriction_is_or_clause(restrictinfo))
+	{
+		BoolExpr   *orExpr = (BoolExpr *) restrictinfo->orclause;
+
+		Assert(is_orclause(restrictinfo->orclause));
+
+		if (list_length(orExpr->args) >= 2)
+		{
+			List *or_list = transform_or_to_any(root, orExpr->args);
+			Expr *clause = list_length(or_list) > 1 ?
+								makeBoolExpr(OR_EXPR, or_list,
+											 ((BoolExpr *) restrictinfo->clause)->location) :
+								linitial(or_list);
+
+			RestrictInfo *rinfo;
+			rinfo = make_restrictinfo(root,
+										clause,
+										restrictinfo->is_pushed_down,
+										restrictinfo->has_clone,
+										restrictinfo->is_clone,
+										restrictinfo->pseudoconstant,
+										restrictinfo->security_level,
+										restrictinfo->required_relids,
+										restrictinfo->incompatible_relids,
+										restrictinfo->outer_relids);
+
+			restrictinfo = rinfo;
+		}
+	}
+
 	/* Add clause to rel's restriction list */
 	rel->baserestrictinfo = lappend(rel->baserestrictinfo, restrictinfo);
 
diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h
index 14ccfc1ac1c..f48ddb8c385 100644
--- a/src/include/nodes/pathnodes.h
+++ b/src/include/nodes/pathnodes.h
@@ -2708,6 +2708,37 @@ typedef struct RestrictInfo
 	Oid			right_hasheqoperator pg_node_attr(equal_ignore);
 } RestrictInfo;
 
+/*
+ * The group of similar operator expressions in transform_or_to_any().
+ */
+typedef struct OrClauseGroup
+{
+	pg_node_attr(nodetag_only)
+
+	NodeTag		type;
+
+	/* The expression of the variable side of operator */
+	Expr	   *expr;
+	/* The operator of the operator expression */
+	Oid			opno;
+	/* The collation of the operator expression */
+	Oid			inputcollid;
+	/* The type of constant side of operator */
+	Oid			consttype;
+
+	/* The list of constant sides of operators */
+	List	   *consts;
+
+	/*
+	 * List of source expressions.  We need this for convenience in case we
+	 * will give up on transformation.
+	 */
+	List	   *exprs;
+
+	Node	   *const_expr;
+} OrClauseGroup;
+
+
 /*
  * This macro embodies the correct way to test whether a RestrictInfo is
  * "pushed down" to a given outer join, that is, should be treated as a filter
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067f..5643ee8f651 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *exprId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..421a645fae0 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,73 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+   Recheck Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                          QUERY PLAN                                          
+----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+(6 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(4 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1867,23 +1922,123 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
+                           Index Cond: ((thousand = 42) AND (tenthous = 1))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
+                           Index Cond: ((thousand = 42) AND (tenthous = 3))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
 (11 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = ANY ('{42,41}'::integer[])) OR ((thousand = 99) AND (tenthous = 2))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(12 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9142dab171f..59d2617295f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4234,6 +4234,58 @@ select * from tenk1 a join tenk1 b on
                            Index Cond: (unique2 = 7)
 (19 rows)
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 7)
+(19 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 7)
+(17 rows)
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..7678744181c 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..0f6d3d323d4 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,11 +43,12 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                         QUERY PLAN                         
+------------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
-(2 rows)
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
+   Filter: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+(3 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
  ctid  | id 
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..f74ad415fbf 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -726,6 +726,24 @@ DROP TABLE onek_with_null;
 -- Check bitmap index path planning
 --
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -738,6 +756,30 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index e3d26520832..cf02cc34ed0 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1409,6 +1409,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 442428d937c..3d2ce04f9e2 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -40,6 +40,7 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 9320e4d8080..4ec9e2ce32f 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1715,6 +1715,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroup
 OSAPerQueryState
 OSInfo
 OSSLCipher
#203Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#201)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 27.06.2024 23:06, Alena Rybakina wrote:

Tobe honest,I've alreadystartedwritingcodetodothis,butI'm facedwitha
misunderstandingof howto correctlycreatea
conditionfor"OR"expressionsthatare notsubjectto transformation.

For example,the expressions b=1in the query below:

alena@postgres=# explain select * from x where ( (a =5 or a=4) and a
= ANY(ARRAY[5,4])) or (b=1); QUERY PLAN
----------------------------------------------------------------------------------
Seq Scan on x (cost=0.00..123.00 rows=1 width=8) Filter: ((((a = 5)
OR (a = 4)) AND (a = ANY ('{5,4}'::integer[]))) OR (b = 1)) (2 rows)

I see that two expressions have remained unchanged and it only works
for "AND" binary operations.

But I think it might be worth applying this together, where does the
optimizer generate indexes (build_paths_for_OR function)?

Iimplementedsuchcode,butatthe
analysisstageinplanner,anditwasn'tfullyreadyyet,butIwas ableto
drawsomeimportantconclusions.Firstof all,Ifacedtheproblemof the
inequalityof the numberof columnsinthe expressionwiththe
requiredone,atleastsomeextracolumnappeared,judgingby the
crust.Ihaven'tfullyrealizedityet andhaven'tfixedit.

#0  __pthread_kill_implementation (no_tid=0, signo=6,
threadid=134300960061248)
    at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=134300960061248) at
./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=134300960061248, signo=signo@entry=6)
at ./nptl/pthread_kill.c:89
#3  0x00007a2560042476 in __GI_raise (sig=sig@entry=6) at
../sysdeps/posix/raise.c:26
#4  0x00007a25600287f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x00005573f9df62a8 in ExceptionalCondition (
    conditionName=0x5573f9fec4c8
"AttrNumberIsForUserDefinedAttr(list_attnums[i]) ||
!bms_is_member(attnum, clauses_attnums)", fileName=0x5573f9fec11c
"dependencies.c", lineNumber=1525) at assert.c:66
#6  0x00005573f9b8b85f in dependencies_clauselist_selectivity
(root=0x5573fad534e8,
    clauses=0x5573fad0b2d8, varRelid=0, jointype=JOIN_INNER,
sjinfo=0x0, rel=0x5573fad54b38,
    estimatedclauses=0x7ffe2e43f178) at dependencies.c:1525
#7  0x00005573f9b8fed9 in statext_clauselist_selectivity
(root=0x5573fad534e8, clauses=0x5573fad0b2d8,
    varRelid=0, jointype=JOIN_INNER, sjinfo=0x0, rel=0x5573fad54b38,
estimatedclauses=0x7ffe2e43f178,
    is_or=false) at extended_stats.c:2035
--Type <RET> for more, q to quit, c to continue without paging--
#8  0x00005573f9a57f88 in clauselist_selectivity_ext
(root=0x5573fad534e8, clauses=0x5573fad0b2d8,
    varRelid=0, jointype=JOIN_INNER, sjinfo=0x0,
use_extended_stats=true) at clausesel.c:153
#9  0x00005573f9a57e30 in clauselist_selectivity (root=0x5573fad534e8,
clauses=0x5573fad0b2d8,
    varRelid=0, jointype=JOIN_INNER, sjinfo=0x0) at clausesel.c:106
#10 0x00005573f9a62e03 in set_baserel_size_estimates
(root=0x5573fad534e8, rel=0x5573fad54b38)
    at costsize.c:5247
#11 0x00005573f9a51aa5 in set_plain_rel_size (root=0x5573fad534e8,
rel=0x5573fad54b38,
    rte=0x5573fad0ec58) at allpaths.c:581
#12 0x00005573f9a516ce in set_rel_size (root=0x5573fad534e8,
rel=0x5573fad54b38, rti=1,
    rte=0x5573fad0ec58) at allpaths.c:411
#13 0x00005573f9a514c7 in set_base_rel_sizes (root=0x5573fad534e8) at
allpaths.c:322
#14 0x00005573f9a5119d in make_one_rel (root=0x5573fad534e8,
joinlist=0x5573fad0adf8) at allpaths.c:183
#15 0x00005573f9a94d45 in query_planner (root=0x5573fad534e8,
    qp_callback=0x5573f9a9b59e <standard_qp_callback>,
qp_extra=0x7ffe2e43f540) at planmain.c:280
#16 0x00005573f9a977a8 in grouping_planner (root=0x5573fad534e8,
tuple_fraction=0, setops=0x0)
    at planner.c:1520
#17 0x00005573f9a96e47 in subquery_planner (glob=0x5573fad533d8,
parse=0x5573fad0ea48, parent_root=0x0,
    hasRecursion=false, tuple_fraction=0, setops=0x0) at planner.c:1089
#18 0x00005573f9a954aa in standard_planner (parse=0x5573fad0ea48,
    query_string=0x5573fad8b3b0 "explain analyze SELECT * FROM
functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND
upper(b) = '1'", cursorOptions=2048, boundParams=0x0) at planner.c:415
#19 0x00005573f9a951d4 in planner (parse=0x5573fad0ea48,
--Type <RET> for more, q to quit, c to continue without paging--
    query_string=0x5573fad8b3b0 "explain analyze SELECT * FROM
functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND
upper(b) = '1'", cursorOptions=2048, boundParams=0x0) at planner.c:282
#20 0x00005573f9bf4e2e in pg_plan_query (querytree=0x5573fad0ea48,
    query_string=0x5573fad8b3b0 "explain analyze SELECT * FROM
functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND
upper(b) = '1'", cursorOptions=2048, boundParams=0x0) at postgres.c:904
#21 0x00005573f98613e7 in standard_ExplainOneQuery
(query=0x5573fad0ea48, cursorOptions=2048, into=0x0,
    es=0x5573fad57da0,
    queryString=0x5573fad8b3b0 "explain analyze SELECT * FROM
functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND
upper(b) = '1'", params=0x0, queryEnv=0x0) at explain.c:489
#22 0x00005573f9861205 in ExplainOneQuery (query=0x5573fad0ea48,
cursorOptions=2048, into=0x0,
    es=0x5573fad57da0,
    queryString=0x5573fad8b3b0 "explain analyze SELECT * FROM
functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND
upper(b) = '1'", params=0x0, queryEnv=0x0) at explain.c:445
#23 0x00005573f9860e35 in ExplainQuery (pstate=0x5573fad57c90,
stmt=0x5573fad8b5a0, params=0x0,
    dest=0x5573fad57c00) at explain.c:341
#24 0x00005573f9bff3a8 in standard_ProcessUtility (pstmt=0x5573fad8b490,
    queryString=0x5573fad8b3b0 "explain analyze SELECT * FROM
functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND
upper(b) = '1'", readOnlyTree=false, context=PROCESS_UTILITY_QUERY,
params=0x0,
    queryEnv=0x0, dest=0x5573fad57c00, qc=0x7ffe2e43fcd0) at utility.c:863
#25 0x00005573f9bfe91a in ProcessUtility (pstmt=0x5573fad8b490,
    queryString=0x5573fad8b3b0 "explain analyze SELECT * FROM
functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND
upper(b) = '1'", readOnlyTree=false, context=PROCESS_UTILITY_QUERY,
params=0x0,
--Type <RET> for more, q to quit, c to continue without paging--
    queryEnv=0x0, dest=0x5573fad57c00, qc=0x7ffe2e43fcd0) at utility.c:523
#26 0x00005573f9bfd195 in PortalRunUtility (portal=0x5573fac6bcf0,
pstmt=0x5573fad8b490,
    isTopLevel=false, setHoldSnapshot=true, dest=0x5573fad57c00,
qc=0x7ffe2e43fcd0) at pquery.c:1158
#27 0x00005573f9bfced2 in FillPortalStore (portal=0x5573fac6bcf0,
isTopLevel=false) at pquery.c:1031
#28 0x00005573f9bfd778 in PortalRunFetch (portal=0x5573fac6bcf0,
fdirection=FETCH_FORWARD, count=10,
    dest=0x5573fa1d6880 <spi_printtupDR>) at pquery.c:1442
#29 0x00005573f9992675 in _SPI_cursor_operation (portal=0x5573fac6bcf0,
direction=FETCH_FORWARD,
    count=10, dest=0x5573fa1d6880 <spi_printtupDR>) at spi.c:3019
#30 0x00005573f9990849 in SPI_cursor_fetch (portal=0x5573fac6bcf0,
forward=true, count=10) at spi.c:1805
#31 0x00007a25603e0aa5 in exec_for_query (estate=0x7ffe2e440200,
stmt=0x5573fad067c8,
    portal=0x5573fac6bcf0, prefetch_ok=true) at pl_exec.c:5889
#32 0x00007a25603de728 in exec_stmt_dynfors (estate=0x7ffe2e440200,
stmt=0x5573fad067c8)
    at pl_exec.c:4647
#33 0x00007a25603d8b1c in exec_stmts (estate=0x7ffe2e440200,
stmts=0x5573fad06ec8) at pl_exec.c:2100
#34 0x00007a25603d8697 in exec_stmt_block (estate=0x7ffe2e440200,
block=0x5573fad06f18) at pl_exec.c:1943
#35 0x00007a25603d7d9e in exec_toplevel_block (estate=0x7ffe2e440200,
block=0x5573fad06f18)
    at pl_exec.c:1634
#36 0x00007a25603d5a2e in plpgsql_exec_function (func=0x5573fac2c1e0,
fcinfo=0x5573fad2af60,
    simple_eval_estate=0x0, simple_eval_resowner=0x0,
procedure_resowner=0x0, atomic=true)
    at pl_exec.c:623
#37 0x00007a25603f277f in plpgsql_call_handler (fcinfo=0x5573fad2af60)
at pl_handler.c:277
#38 0x00005573f993589a in ExecMakeTableFunctionResult
(setexpr=0x5573facfd8c8, econtext=0x5573facfd798,
--Type <RET> for more, q to quit, c to continue without paging--
    argContext=0x5573fad2ae60, expectedDesc=0x5573facfe130,
randomAccess=false) at execSRF.c:234
#39 0x00005573f995299c in FunctionNext (node=0x5573facfd588) at
nodeFunctionscan.c:94
#40 0x00005573f993735f in ExecScanFetch (node=0x5573facfd588,
accessMtd=0x5573f99528e6 <FunctionNext>,
    recheckMtd=0x5573f9952ced <FunctionRecheck>) at execScan.c:131
#41 0x00005573f99373d8 in ExecScan (node=0x5573facfd588,
accessMtd=0x5573f99528e6 <FunctionNext>,
    recheckMtd=0x5573f9952ced <FunctionRecheck>) at execScan.c:180
#42 0x00005573f9952d46 in ExecFunctionScan (pstate=0x5573facfd588) at
nodeFunctionscan.c:269
#43 0x00005573f9932c7f in ExecProcNodeFirst (node=0x5573facfd588) at
execProcnode.c:464
#44 0x00005573f9925df5 in ExecProcNode (node=0x5573facfd588)
    at ../../../src/include/executor/executor.h:274
#45 0x00005573f9928bf9 in ExecutePlan (estate=0x5573facfd360,
planstate=0x5573facfd588,
    use_parallel_mode=false, operation=CMD_SELECT, sendTuples=true,
numberTuples=0,
    direction=ForwardScanDirection, dest=0x5573fad8f6e0,
execute_once=true) at execMain.c:1646
#46 0x00005573f992653d in standard_ExecutorRun (queryDesc=0x5573fad87f70,
    direction=ForwardScanDirection, count=0, execute_once=true) at
execMain.c:363
#47 0x00005573f9926316 in ExecutorRun (queryDesc=0x5573fad87f70,
direction=ForwardScanDirection,
    count=0, execute_once=true) at execMain.c:304
#48 0x00005573f9bfcb7d in PortalRunSelect (portal=0x5573fac6bbe0,
forward=true, count=0,
    dest=0x5573fad8f6e0) at pquery.c:924
#49 0x00005573f9bfc7a5 in PortalRun (portal=0x5573fac6bbe0,
count=9223372036854775807, isTopLevel=true,
    run_once=true, dest=0x5573fad8f6e0, altdest=0x5573fad8f6e0,
qc=0x7ffe2e440a60) at pquery.c:768
#50 0x00005573f9bf5512 in exec_simple_query (
--Type <RET> for more, q to quit, c to continue without paging--
    query_string=0x5573fabea030 "SELECT * FROM
check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a *
2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');") at postgres.c:1274
#51 0x00005573f9bfa5b7 in PostgresMain (dbname=0x5573fab52240 "regression",
    username=0x5573fac27c98 "alena") at postgres.c:4680
#52 0x00005573f9bf137e in BackendMain (startup_data=0x7ffe2e440ce4 "",
startup_data_len=4)
    at backend_startup.c:105
#53 0x00005573f9b06852 in postmaster_child_launch (child_type=B_BACKEND,
startup_data=0x7ffe2e440ce4 "",
    startup_data_len=4, client_sock=0x7ffe2e440d30) at launch_backend.c:265
#54 0x00005573f9b0cd66 in BackendStartup (client_sock=0x7ffe2e440d30) at
postmaster.c:3593
#55 0x00005573f9b09db1 in ServerLoop () at postmaster.c:1674
#56 0x00005573f9b09678 in PostmasterMain (argc=8, argv=0x5573fab500d0)
at postmaster.c:1372
#57 0x00005573f99b5f79 in main (argc=8, argv=0x5573fab500d0) at main.c:197

Secondly,Isawdiffchangesinqueriesthatshowedcaseswherethe optimizerdid
noteliminateoneofthe redundantexpressionsandprocessedbothof
them.Thisindicatestheproblemthatthe optimizerhas notlearnedhow to
handleitinallcases.IthinkI'll needtoaddsomecodetohandleit.

  EXPLAIN (COSTS OFF)
  SELECT count(*) FROM tenk1
    WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 
2) OR thousand = 41;
-                                                         QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   Aggregate
     ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = ANY 
('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((((thousand = 42) AND (thousand = ANY 
('{42,99}'::integer[]))) OR ((thousand = 99) AND (thousand = ANY 
('{42,99}'::integer[])))) OR (tenthous < 2)) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((((thousand = 42) OR (thousand = 
99)) AND (thousand = ANY ('{42,99}'::integer[]))) OR (tenthous < 2))) OR 
(thousand = 41))
           ->  BitmapOr
-               ->  BitmapAnd
-                     ->  Bitmap Index Scan on tenk1_hundred
-                           Index Cond: (hundred = 42)
+               ->  BitmapOr
                       ->  BitmapOr
                             ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = ANY 
('{42,99}'::integer[]))
+                                 Index Cond: ((thousand = 42) AND 
(thousand = ANY ('{42,99}'::integer[])))
                             ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (tenthous < 2)
+                                 Index Cond: ((thousand = 99) AND 
(thousand = ANY ('{42,99}'::integer[])))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (tenthous < 2)
                 ->  Bitmap Index Scan on tenk1_thous_tenthous
                       Index Cond: (thousand = 41)
-(14 rows)
+(15 rows)
  SELECT count(*) FROM tenk1
    WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 
2) OR thousand = 41;
@@ -1986,20 +1987,21 @@
  EXPLAIN (COSTS OFF)
  SELECT count(*) FROM tenk1
    WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 
99 AND tenthous = 2);
-                                                          QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   Aggregate
     ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = ANY 
('{41,42}'::integer[])) OR ((thousand = 99) AND (tenthous = 2))))
-         ->  BitmapAnd
-               ->  Bitmap Index Scan on tenk1_hundred
-                     Index Cond: (hundred = 42)
+         Recheck Cond: ((((thousand = 42) AND (thousand = ANY 
('{41,42}'::integer[]))) OR ((thousand = 41) AND (thousand = ANY 
('{41,42}'::integer[])))) OR ((thousand = 99) AND (tenthous = 2)))
+         Filter: (hundred = 42)
+         ->  BitmapOr
                 ->  BitmapOr
                       ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = ANY 
('{41,42}'::integer[]))
+                           Index Cond: ((thousand = 42) AND (thousand = 
ANY ('{41,42}'::integer[])))
                       ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: ((thousand = 99) AND (tenthous = 2))
-(11 rows)
+                           Index Cond: ((thousand = 41) AND (thousand = 
ANY ('{41,42}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 99) AND (tenthous = 2))
+(12 rows)
  SELECT count(*) FROM tenk1
    WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 
99 AND tenthous = 2);
diff -U3 /home/alena/postgrespro5/src/test/regress/expected/inherit.out 
/home/alena/postgrespro5/src/test/regress/results/inherit.out
--- /home/alena/postgrespro5/src/test/regress/expected/inherit.out 
2024-06-20 12:28:52.324011724 +0300
+++ /home/alena/postgrespro5/src/test/regress/results/inherit.out 
2024-07-11 02:00:55.404006843 +0300
@@ -2126,7 +2126,7 @@
                                     QUERY PLAN
  ---------------------------------------------------------------------------------
   Seq Scan on part_ab_cd list_parted
-   Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY 
('{NULL,cd}'::text[])))
+   Filter: (((a)::text = ANY ('{NULL,cd}'::text[])) OR ((a)::text = 
'ab'::text))
  (2 rows)
  explain (costs off) select * from list_parted where a = 'ab';
diff -U3 /home/alena/postgrespro5/src/test/regress/expected/join.out 
/home/alena/postgrespro5/src/test/regress/results/join.out
--- /home/alena/postgrespro5/src/test/regress/expected/join.out 
2024-06-28 11:05:44.304135987 +0300
+++ /home/alena/postgrespro5/src/test/regress/results/join.out 
2024-07-11 02:00:58.152006921 +0300
@@ -4210,10 +4210,17 @@
  select * from tenk1 a join tenk1 b on
    (a.unique1 = 1 and b.unique1 = 2) or
    ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                       QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------
   Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 
ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 
= 3) OR (a.unique2 = 7)) AND (a.unique2 = ANY ('{3,7}'::integer[])) AND 
(b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 a
+         Recheck Cond: ((unique1 = 1) OR (unique2 = ANY 
('{3,7}'::integer[])))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 1)
+               ->  Bitmap Index Scan on tenk1_unique2
+                     Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
     ->  Bitmap Heap Scan on tenk1 b
           Recheck Cond: ((unique1 = 2) OR (hundred = 4))
           ->  BitmapOr
@@ -4221,25 +4228,24 @@
                       Index Cond: (unique1 = 2)
                 ->  Bitmap Index Scan on tenk1_hundred
                       Index Cond: (hundred = 4)
-   ->  Materialize
-         ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY 
('{3,7}'::integer[])))
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(17 rows)
+(16 rows)
  SET enable_or_transformation = on;
  explain (costs off)
  select * from tenk1 a join tenk1 b on
    (a.unique1 = 1 and b.unique1 = 2) or
    ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                       QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------
   Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 
ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 
= 3) OR (a.unique2 = 7)) AND (a.unique2 = ANY ('{3,7}'::integer[])) AND 
(b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 a
+         Recheck Cond: ((unique1 = 1) OR (unique2 = ANY 
('{3,7}'::integer[])))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 1)
+               ->  Bitmap Index Scan on tenk1_unique2
+                     Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
     ->  Bitmap Heap Scan on tenk1 b
           Recheck Cond: ((unique1 = 2) OR (hundred = 4))
           ->  BitmapOr
@@ -4247,37 +4253,29 @@
                       Index Cond: (unique1 = 2)
                 ->  Bitmap Index Scan on tenk1_hundred
                       Index Cond: (hundred = 4)
-   ->  Materialize
-         ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY 
('{3,7}'::integer[])))
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(17 rows)
+(16 rows)
  explain (costs off)
  select * from tenk1 a join tenk1 b on
    (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
    ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
- QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   Nested Loop
-   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 
1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND 
(b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 
= 3) OR (a.unique2 = 7)) AND (a.unique2 = ANY ('{3,7}'::integer[])) AND 
(b.hundred = 4)) OR (a.unique1 < 20) OR (a.unique1 = 3))
     ->  Seq Scan on tenk1 b
     ->  Materialize
           ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR 
(unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY 
('{3,7}'::integer[])) OR (unique1 < 20) OR (unique1 = 3))
                 ->  BitmapOr
                       ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
                             Index Cond: (unique1 = 1)
                       ->  Bitmap Index Scan on tenk1_unique2
                             Index Cond: (unique2 = ANY 
('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
  (15 rows)

Thirdly,Ihaveevidencethatthismayaffecttheunderestimationof power.I'll
lookinto thisin detaillater.

diff -U3 
/home/alena/postgrespro5/src/test/regress/expected/stats_ext.out 
/home/alena/postgrespro5/src/test/regress/results/stats_ext.out
--- /home/alena/postgrespro5/src/test/regress/expected/stats_ext.out 
2024-06-28 11:05:44.304135987 +0300
+++ /home/alena/postgrespro5/src/test/regress/results/stats_ext.out 
2024-07-11 02:01:06.596007159 +0300
@@ -1156,19 +1156,19 @@
  SELECT * FROM check_estimated_rows('SELECT * FROM 
functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
   estimated | actual
  -----------+--------
-         2 |    100
+         1 |    100
  (1 row)

 SELECT * FROM check_estimated_rows('SELECT * FROM
functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b =
''2'')');
  estimated | actual
 -----------+--------
-         4 |    100
+         1 |    100
 (1 row)

 SELECT * FROM check_estimated_rows('SELECT * FROM
functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND
(b = ''1'' OR b = ''2'')');
  estimated | actual
 -----------+--------
-         8 |    200
+         1 |    200
 (1 row)

 -- OR clauses referencing different attributes
@@ -1322,19 +1322,19 @@
 SELECT * FROM check_estimated_rows('SELECT * FROM
functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual
 -----------+--------
-       100 |    100
+         2 |    100
 (1 row)

 SELECT * FROM check_estimated_rows('SELECT * FROM
functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b =
''2'')');
  estimated | actual
 -----------+--------
-       100 |    100
+         2 |    100
 (1 row)

 SELECT * FROM check_estimated_rows('SELECT * FROM
functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND
(b = ''1'' OR b = ''2'')');
  estimated | actual
 -----------+--------
-       200 |    200
+         8 |    200
 (1 row)

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

Attachments:

or.diff.no-cfbottext/plain; charset=UTF-8; name=or.diff.no-cfbotDownload
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index 129fb447099..b2b457b614c 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -140,6 +140,33 @@ JumbleQuery(Query *query)
 	return jstate;
 }
 
+JumbleState *
+JumbleExpr(Expr *expr, uint64 *queryId)
+{
+	JumbleState *jstate = NULL;
+
+	Assert(queryId != NULL);
+
+	jstate = (JumbleState *) palloc(sizeof(JumbleState));
+
+	/* Set up workspace for query jumbling */
+	jstate->jumble = (unsigned char *) palloc(JUMBLE_SIZE);
+	jstate->jumble_len = 0;
+	jstate->clocations_buf_size = 32;
+	jstate->clocations = (LocationLen *)
+		palloc(jstate->clocations_buf_size * sizeof(LocationLen));
+	jstate->clocations_count = 0;
+	jstate->highest_extern_param_id = 0;
+
+	/* Compute query ID */
+	_jumbleNode(jstate, (Node *) expr);
+	*queryId = DatumGetUInt64(hash_any_extended(jstate->jumble,
+												jstate->jumble_len,
+												0));
+
+	return jstate;
+}
+
 /*
  * Enables query identifier computation.
  *
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 00cd7358ebb..0216d61b801 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -16,12 +16,15 @@
 #include "postgres.h"
 
 #include "catalog/pg_aggregate.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
+#include "common/hashfn.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/optimizer.h"
 #include "parser/analyze.h"
 #include "parser/parse_agg.h"
@@ -41,6 +44,9 @@
 #include "utils/lsyscache.h"
 #include "utils/timestamp.h"
 #include "utils/xml.h"
+#include "utils/syscache.h"
+
+bool		enable_or_transformation = true;
 
 /* GUC parameters */
 bool		Transform_null_equals = false;
@@ -110,6 +116,415 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
 static Node *make_nulltest_from_distinct(ParseState *pstate,
 										 A_Expr *distincta, Node *arg);
 
+typedef struct OrClauseGroupKey
+{
+	NodeTag	type;
+
+	Expr   *expr; /* Pointer to the expression tree which has been a source for
+					the hashkey value */
+	Oid		opno;
+	Oid		exprtype;
+} OrClauseGroupKey;
+
+typedef struct OrClauseGroupEntry
+{
+	OrClauseGroupKey	key;
+
+	List			   *consts;
+	List 			   *exprs;
+	FunctionCallInfo	fcinfo;
+} OrClauseGroupEntry;
+
+/*
+ * Hash function to find candidate clauses.
+ */
+static uint32
+orclause_hash(const void *data, Size keysize)
+{
+	OrClauseGroupKey   *key = (OrClauseGroupKey *) data;
+	uint64				exprHash;
+
+	Assert(keysize == sizeof(OrClauseGroupKey));
+	Assert(IsA(data, Invalid));
+
+	(void) JumbleExpr(key->expr, &exprHash);
+
+	return hash_combine((uint32) exprHash,
+						hash_combine((uint32) key->opno,
+									 (uint32) key->exprtype));
+}
+
+static void *
+orclause_keycopy(void *dest, const void *src, Size keysize)
+{
+	OrClauseGroupKey *src_key = (OrClauseGroupKey *) src;
+	OrClauseGroupKey *dst_key = (OrClauseGroupKey *) dest;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(src, Invalid));
+
+	dst_key->type = T_Invalid;
+	dst_key->expr = src_key->expr;
+	dst_key->opno = src_key->opno;
+	dst_key->exprtype = src_key->exprtype;
+	return dst_key;
+}
+
+/*
+ * Dynahash match function to use in or_group_htab
+ */
+static int
+orclause_match(const void *data1, const void *data2, Size keysize)
+{
+	OrClauseGroupKey   *key1 = (OrClauseGroupKey *) data1;
+	OrClauseGroupKey   *key2 = (OrClauseGroupKey *) data2;
+
+	Assert(sizeof(OrClauseGroupKey) == keysize);
+	Assert(IsA(key1, Invalid));
+	Assert(IsA(key2, Invalid));
+
+	if (key1->opno == key2->opno &&
+		key1->exprtype == key2->exprtype &&
+		equal(key1->expr, key2->expr))
+		return 0;
+
+	return 1;
+}
+
+static FunctionCallInfo locfcinfo = NULL;
+
+static int
+saop_const_comparator(const ListCell *a, const ListCell *b)
+{
+	Node   *leftop = (Node *) lfirst(a);
+	Node   *rightop = (Node *) lfirst(b);
+
+	if (IsA(leftop, RelabelType))
+		leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+	if (IsA(rightop, RelabelType))
+		rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+	Assert(IsA(leftop, Const) && IsA(rightop, Const));
+
+	locfcinfo->args[0].value = ((Const *) leftop)->constvalue;
+	locfcinfo->args[0].isnull = false;
+	locfcinfo->args[1].value = ((Const *) rightop)->constvalue;
+	locfcinfo->args[1].isnull = false;
+	return DatumGetInt32(FunctionCallInvoke(locfcinfo));
+}
+
+static List *
+saop_delete_duplicates(ParseState *pstate, OrClauseGroupEntry *entry,
+					   Oid scalar_type)
+{
+	ListCell   *lc;
+	List	   *result;
+
+	locfcinfo = entry->fcinfo;
+	list_sort(entry->consts, saop_const_comparator);
+
+	result = list_make1(linitial(entry->consts));
+	for_each_from(lc, entry->consts, 1)
+	{
+		Node *node = (Node *) lfirst(lc);
+
+		if (equal(llast(result), node))
+			continue;
+
+		node = coerce_to_common_type(pstate, node, scalar_type, "IN");
+		result = lappend(result, node);
+	}
+
+	return result;
+}
+
+/*
+ * TransformOrExprToANY -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to an ANY operation.
+ *	  Transformation must be already done on input args list before the call.
+ *	  Transformation groups two-sided equality operations. One side of such an
+ *	  operation must be plain constant or constant expression. The other side of
+ *	  the clause must be a variable expression without volatile functions.
+ *	  The grouping technique is based on an equivalence of variable sides of the
+ *	  expression: using queryId and equal() routine, it groups constant sides of
+ *	  similar clauses into an array. After the grouping procedure, each couple
+ *	  ('variable expression' and 'constant array') form a new SAOP operation,
+ *	  which is added to the args list of the returning expression.
+ *
+ *	  NOTE: function returns OR BoolExpr if more than one clause are detected in
+ *	  the final args list, or ScalarArrayOpExpr if all args were grouped into
+ *	  the single SAOP expression.
+ */
+static Node *
+TransformOrExprToANY(ParseState *pstate, List *args, int location)
+{
+	List				   *or_list = NIL;
+	List				   *groups = NIL;
+	List 				   *unconvinient_ors = NIL;
+	ListCell			   *lc;
+	HASHCTL					info;
+	HTAB 				   *or_group_htab = NULL;
+	int 					len_ors = list_length(args);
+	OrClauseGroupEntry	   *entry = NULL;
+
+	Assert(enable_or_transformation && len_ors > 1);
+
+	MemSet(&info, 0, sizeof(info));
+	info.keysize = sizeof(OrClauseGroupKey);
+	info.entrysize = sizeof(OrClauseGroupEntry);
+	info.hash = orclause_hash;
+	info.keycopy = orclause_keycopy;
+	info.match = orclause_match;
+	or_group_htab = hash_create("OR Groups",
+								len_ors,
+								&info,
+								HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
+
+	foreach(lc, args)
+	{
+		Node				   *orqual = lfirst(lc);
+		Node				   *const_expr;
+		Node				   *nconst_expr;
+		OrClauseGroupKey		hashkey;
+		bool					found;
+		Oid						opno;
+		Oid						exprtype;
+		Node				   *leftop, *rightop;
+		TypeCacheEntry		   *typentry;
+
+		if (!IsA(orqual, OpExpr))
+		{
+			unconvinient_ors = lappend(unconvinient_ors, orqual);
+			continue;
+		}
+
+		opno = ((OpExpr *) orqual)->opno;
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			unconvinient_ors = lappend(unconvinient_ors, orqual);
+			continue;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be
+		 * an OpExpr.
+		 * Get pointers to constant and expression sides of the qual.
+		 */
+		leftop = get_leftop(orqual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+		rightop = get_rightop(orqual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				unconvinient_ors = lappend(unconvinient_ors, orqual);
+				continue;
+			}
+
+			nconst_expr = get_rightop(orqual);
+			const_expr = get_leftop(orqual);
+		}
+		else if (IsA(rightop, Const))
+		{
+			const_expr = get_rightop(orqual);
+			nconst_expr = get_leftop(orqual);
+		}
+		else
+		{
+			unconvinient_ors = lappend(unconvinient_ors, orqual);
+			continue;
+		}
+
+		/*
+		 * Transformation only works with both side type is not
+		 * { array | composite | domain | record }.
+		 * Also, forbid it for volatile expressions.
+		 */
+		exprtype = exprType(nconst_expr);
+		if (type_is_rowtype(exprType(const_expr)) ||
+			type_is_rowtype(exprtype) ||
+			contain_volatile_functions((Node *) nconst_expr))
+		{
+			unconvinient_ors = lappend(unconvinient_ors, orqual);
+			continue;
+		}
+
+		typentry = lookup_type_cache(exprtype, TYPECACHE_CMP_PROC_FINFO);
+
+		/*
+		 * Within this transformation we remove duplicates. To avoid
+		 * quadratic behavior we need to sort clauses after making a list of
+		 * elements. So, need sort operator to implement that.
+		 */
+		if (!OidIsValid(typentry->cmp_proc_finfo.fn_oid))
+		{
+			unconvinient_ors = lappend(unconvinient_ors, orqual);
+			continue;
+		}
+
+		/*
+		* At this point we definitely have a transformable clause.
+		* Classify it and add into specific group of clauses, or create new
+		* group.
+		*/
+		hashkey.type = T_Invalid;
+		hashkey.expr = (Expr *) nconst_expr;
+		hashkey.opno = opno;
+		hashkey.exprtype = exprtype;
+		entry = hash_search(or_group_htab, &hashkey, HASH_ENTER, &found);
+
+		if (unlikely(found))
+		{
+			entry->consts = lappend(entry->consts, const_expr);
+			entry->exprs = lappend(entry->exprs, orqual);
+		}
+		else
+		{
+			entry->consts = list_make1(const_expr);
+			entry->exprs = list_make1(orqual);
+
+			/* Prepare funcall for sort comparator */
+			entry->fcinfo =
+						(FunctionCallInfo) palloc(SizeForFunctionCallInfo(2));
+			InitFunctionCallInfoData(*(entry->fcinfo),
+									 &typentry->cmp_proc_finfo, 2,
+									 typentry->typcollation, NULL, NULL);
+
+			/*
+			 * Add the entry to the list. It is needed exclusively to manage the
+			 * problem with the order of transformed clauses in explain.
+			 * Hash value can depend on the platform and version. Hence,
+			 * sequental scan of the hash table would prone to change the order
+			 * of clauses in lists and, as a result, break regression tests
+			 * accidentially.
+			 */
+			groups = lappend(groups, entry);
+		}
+	}
+
+	/* Let's convert each group of clauses to an IN operation. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of
+	 * consts more than 1. trivial groups move to OR-list again
+	 */
+	foreach (lc, groups)
+	{
+		Oid				    scalar_type;
+		Oid					array_type;
+
+		if (!IsA(lfirst(lc), Invalid))
+		{
+			unconvinient_ors = lappend(unconvinient_ors, lfirst(lc));
+			continue;
+		}
+
+		entry = (OrClauseGroupEntry *) lfirst(lc);
+
+		Assert(list_length(entry->consts) > 0);
+		Assert(list_length(entry->exprs) == list_length(entry->consts));
+
+		if (list_length(entry->consts) == 1)
+		{
+			/*
+			 * Only one element returns origin expression into the BoolExpr args
+			 * list unchanged.
+			 */
+			list_free(entry->consts);
+			unconvinient_ors = list_concat(unconvinient_ors, entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+
+		scalar_type = entry->key.exprtype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+											   InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common
+			 * type and build an ArrayExpr for them.
+			 */
+			List			   *aexprs = NIL;
+			ArrayExpr		   *newa = NULL;
+			ScalarArrayOpExpr  *saopexpr = NULL;
+			HeapTuple			opertup;
+			Form_pg_operator	operform;
+			List			   *namelist = NIL;
+
+			aexprs = saop_delete_duplicates(pstate, entry, scalar_type);
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(entry->key.opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 entry->key.opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(entry->key.opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+					make_scalar_array_op(pstate,
+										 namelist,
+										 true,
+										 (Node *) entry->key.expr,
+										 (Node *) newa,
+										 -1);
+
+			or_list = lappend(or_list, makeBoolExpr(AND_EXPR, list_make2(makeBoolExpr(OR_EXPR, entry->exprs, location), saopexpr), -1));
+		}
+		else
+		{
+			/*
+			 * If the const node (right side of operator expression) 's type
+			 *  don't have “true” array type, then we cannnot do the transformation.
+			 * We simply concatenate the expression node.
+			 *
+			 */
+			list_free(entry->consts);
+			unconvinient_ors = list_concat(unconvinient_ors, entry->exprs);
+		}
+	}
+	if(unconvinient_ors != NIL)
+		or_list = lappend(or_list, list_length(unconvinient_ors) > 1 ? makeBoolExpr(OR_EXPR, unconvinient_ors, location) : linitial(unconvinient_ors));
+	hash_destroy(or_group_htab);
+	list_free(groups);
+
+	/* One more trick: assemble correct clause */
+	return (Node *) ((list_length(or_list) > 1) ?
+					 makeBoolExpr(OR_EXPR, or_list, location) :
+					 linitial(or_list));
+}
 
 /*
  * transformExpr -
@@ -1432,6 +1847,11 @@ transformBoolExpr(ParseState *pstate, BoolExpr *a)
 		args = lappend(args, arg);
 	}
 
+	/* Make an attempt to group similar OR clauses into ANY operation */
+	if (enable_or_transformation && a->boolop == OR_EXPR &&
+		list_length(args) >0)
+		return TransformOrExprToANY(pstate, args, a->location);
+
 	return (Node *) makeBoolExpr(a->boolop, args, a->location);
 }
 
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 46c258be282..f5da097fcdf 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1007,6 +1007,17 @@ struct config_bool ConfigureNamesBool[] =
 		true,
 		NULL, NULL, NULL
 	},
+	{
+		{"enable_or_transformation", PGC_USERSET, QUERY_TUNING_OTHER,
+			gettext_noop("Transform a sequence of OR clauses to an array expression."),
+			gettext_noop("The planner will replace expression like 'x=c1 OR x=c2 ..'"
+						 "to the expression 'x = ANY(ARRAY[c1,c2,..])'"),
+			GUC_EXPLAIN
+		},
+		&enable_or_transformation,
+		true,
+		NULL, NULL, NULL
+	},
 	{
 		/*
 		 * Not for general use --- used by SET SESSION AUTHORIZATION and SET
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index f1c55c8067f..a9ae048af52 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -65,6 +65,7 @@ extern PGDLLIMPORT int compute_query_id;
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query);
+extern JumbleState *JumbleExpr(Expr *expr, uint64 *queryId);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 7b63c5cf718..35ab5775019 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -50,6 +50,7 @@ struct PlannedStmt;
 struct ParamListInfoData;
 struct HeapTupleData;
 
+extern PGDLLIMPORT bool enable_or_transformation;
 
 /* in path/clausesel.c: */
 
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 6b16c3a6769..ccf280001a0 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4210,10 +4210,10 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
-                                                      QUERY PLAN                                                      
-----------------------------------------------------------------------------------------------------------------------
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Nested Loop
-   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
          Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
@@ -4223,16 +4223,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(17 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                          QUERY PLAN                                                                           
+---------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = ANY ('{3,7}'::integer[])) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(15 rows)
 
+RESET enable_or_transformation;
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 7ca98397aec..9c2a4d75619 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -82,25 +82,47 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+                  QUERY PLAN                   
+-----------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
+(5 rows)
+
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Append
+   ->  Seq Scan on lp_ad lp_1
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+   ->  Seq Scan on lp_bc lp_2
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
+(5 rows)
+
+RESET enable_or_transformation;
 explain (costs off) select * from lp where a <> 'g';
              QUERY PLAN             
 ------------------------------------
@@ -515,10 +537,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -596,13 +618,13 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -671,6 +693,163 @@ explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a =
          Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
 (11 rows)
 
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+                QUERY PLAN                
+------------------------------------------
+ Seq Scan on rlp2 rlp
+   Filter: (a = ANY ('{1,7}'::integer[]))
+(2 rows)
+
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+                      QUERY PLAN                       
+-------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp2 rlp_2
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp3abcd rlp_3
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_1 rlp_4
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_2 rlp_5
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp4_default rlp_6
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_1 rlp_7
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp5_default rlp_8
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_10 rlp_9
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_null rlp_11
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+   ->  Seq Scan on rlp_default_default rlp_12
+         Filter: ((a = 1) OR ((b)::text = 'ab'::text))
+(25 rows)
+
+explain (costs off) select * from rlp where a > 20 and a < 27;
+               QUERY PLAN                
+-----------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: ((a > 20) AND (a < 27))
+   ->  Seq Scan on rlp4_2 rlp_2
+         Filter: ((a > 20) AND (a < 27))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 29;
+          QUERY PLAN          
+------------------------------
+ Seq Scan on rlp4_default rlp
+   Filter: (a = 29)
+(2 rows)
+
+explain (costs off) select * from rlp where a >= 29;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_default rlp_1
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_1 rlp_2
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp5_default rlp_3
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_30 rlp_4
+         Filter: (a >= 29)
+   ->  Seq Scan on rlp_default_default rlp_5
+         Filter: (a >= 29)
+(11 rows)
+
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+                      QUERY PLAN                      
+------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp1 rlp_1
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+   ->  Seq Scan on rlp4_1 rlp_2
+         Filter: ((a < 1) OR ((a > 20) AND (a < 25)))
+(5 rows)
+
+explain (costs off) select * from rlp where a = 20 or a = 40;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Append
+   ->  Seq Scan on rlp4_1 rlp_1
+         Filter: (a = ANY ('{20,40}'::integer[]))
+   ->  Seq Scan on rlp5_default rlp_2
+         Filter: (a = ANY ('{20,40}'::integer[]))
+(5 rows)
+
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+            QUERY PLAN            
+----------------------------------
+ Seq Scan on rlp_default_10 rlp
+   Filter: ((a > 1) AND (a = 10))
+(2 rows)
+
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+                  QUERY PLAN                  
+----------------------------------------------
+ Append
+   ->  Seq Scan on rlp3abcd rlp_1
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3efgh rlp_2
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3nullxy rlp_3
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp3_default rlp_4
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_1 rlp_5
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_2 rlp_6
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp4_default rlp_7
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_1 rlp_8
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp5_default rlp_9
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_30 rlp_10
+         Filter: ((a > 1) AND (a >= 15))
+   ->  Seq Scan on rlp_default_default rlp_11
+         Filter: ((a > 1) AND (a >= 15))
+(23 rows)
+
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+                            QUERY PLAN                             
+-------------------------------------------------------------------
+ Append
+   ->  Seq Scan on rlp2 rlp_1
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3abcd rlp_2
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3efgh rlp_3
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3nullxy rlp_4
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+   ->  Seq Scan on rlp3_default rlp_5
+         Filter: (((a = 1) AND (a = 3)) OR ((a > 1) AND (a = 15)))
+(11 rows)
+
+RESET enable_or_transformation;
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
@@ -2072,10 +2251,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..7678744181c 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index dbfd0c13d46..6123351a9a8 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -147,6 +147,7 @@ select name, setting from pg_settings where name like 'enable%';
  enable_memoize                 | on
  enable_mergejoin               | on
  enable_nestloop                | on
+ enable_or_transformation       | on
  enable_parallel_append         | on
  enable_parallel_hash           | on
  enable_partition_pruning       | on
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..057c6d2bda1 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -738,6 +738,41 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+RESET enable_or_transformation;
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 8bfe3b7ba67..c77b5c50f01 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1408,6 +1408,16 @@ explain (costs off)
 select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+SET enable_or_transformation = on;
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+RESET enable_or_transformation;
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index a09b27d820c..9717c8c835c 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -21,6 +21,12 @@ explain (costs off) select * from lp where a is not null;
 explain (costs off) select * from lp where a is null;
 explain (costs off) select * from lp where a = 'a' or a = 'c';
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+
+SET enable_or_transformation = on;
+explain (costs off) select * from lp where a = 'a' or a = 'c';
+explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
+RESET enable_or_transformation;
+
 explain (costs off) select * from lp where a <> 'g';
 explain (costs off) select * from lp where a <> 'a' and a <> 'd';
 explain (costs off) select * from lp where a not in ('a', 'd');
@@ -99,6 +105,22 @@ explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, i
 explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
 explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
 
+
+SET enable_or_transformation = on;
+explain (costs off) select * from rlp where a = 1 or a = 7;
+explain (costs off) select * from rlp where a = 1 or b = 'ab';
+explain (costs off) select * from rlp where a > 20 and a < 27;
+explain (costs off) select * from rlp where a = 29;
+explain (costs off) select * from rlp where a >= 29;
+explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
+explain (costs off) select * from rlp where a = 20 or a = 40;
+explain (costs off) select * from rlp3 where a = 20;   /* empty */
+explain (costs off) select * from rlp where a > 1 and a = 10;	/* only default */
+explain (costs off) select * from rlp where a > 1 and a >=15;	/* rlp3 onwards, including default */
+explain (costs off) select * from rlp where a = 1 and a = 3;	/* empty */
+explain (costs off) select * from rlp where (a = 1 and a = 3) or (a > 1 and a = 15);
+RESET enable_or_transformation;
+
 -- multi-column keys
 create table mc3p (a int, b int, c int) partition by range (a, abs(b), c);
 create table mc3p_default partition of mc3p default;
diff --git a/src/test/regress/sql/tidscan.sql b/src/test/regress/sql/tidscan.sql
index 313e0fb9b67..0499bedb9eb 100644
--- a/src/test/regress/sql/tidscan.sql
+++ b/src/test/regress/sql/tidscan.sql
@@ -22,6 +22,12 @@ EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
 
+SET enable_or_transformation = on;
+EXPLAIN (COSTS OFF)
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
+RESET enable_or_transformation;
+
 -- ctid = ScalarArrayOp - implemented as tidscan
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = ANY(ARRAY['(0,1)', '(0,2)']::tid[]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 61ad417cde6..94450939331 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1714,6 +1714,8 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroupEntry
+OrClauseGroupKey
 OSAPerQueryState
 OSInfo
 OSSLCipher
#204Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#202)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi, again!

I have finished patch and processed almost your suggestions (from [0]/messages/by-id/3381819.e9J7NaK4W3@thinkpad-pgpro,
[1]: /messages/by-id/9736220.CDJkKcVGEf@thinkpad-pgpro
willaddthis inthe nextversion.

[0]: /messages/by-id/3381819.e9J7NaK4W3@thinkpad-pgpro
/messages/by-id/3381819.e9J7NaK4W3@thinkpad-pgpro

[1]: /messages/by-id/9736220.CDJkKcVGEf@thinkpad-pgpro
/messages/by-id/9736220.CDJkKcVGEf@thinkpad-pgpro

[2]: /messages/by-id/2193851.QkHrqEjB74@thinkpad-pgpro
/messages/by-id/2193851.QkHrqEjB74@thinkpad-pgpro

On 09.07.2024 04:57, Alena Rybakina wrote:

Hi! Thank you for your review! Sorryforthe delayin responding.

Irewrotethe patchasyourequested,butnowI'm facedwiththe problemof
processingthe elementsof the or_entries list.For somereason,
thepointerto thelistis cleared and I couldn't find the place where it
happened.MaybeI'mmissingsomethingsimpleinviewof the heavyworkloadright
now,butmaybeyou'll seea problem?Ihave displayedpart of stackbelow.

#5 0x00005b0f6d9f6a6a in ExceptionalCondition
(conditionName=0x5b0f6dbb74f7 "IsPointerList(list)",
fileName=0x5b0f6dbb7418 "list.c", lineNumber=341) at assert.c:66 #6
0x00005b0f6d5dc3ba in lappend (list=0x5b0f6eec5ca0,
datum=0x5b0f6eec0d90) at list.c:341 #7 0x00005b0f6d69230c in
transform_or_to_any (root=0x5b0f6eeb13c8, orlist=0x5b0f6eec57c0) at
initsplan.c:2818 #8 0x00005b0f6d692958 in add_base_clause_to_rel
(root=0x5b0f6eeb13c8, relid=1, restrictinfo=0x5b0f6eec5990) at
initsplan.c:2982 #9 0x00005b0f6d692e5f in
distribute_restrictinfo_to_rels (root=0x5b0f6eeb13c8,
restrictinfo=0x5b0f6eec5990) at initsplan.c:3175 #10
0x00005b0f6d691bf2 in distribute_qual_to_rels (root=0x5b0f6eeb13c8,
clause=0x5b0f6eec0fc0, jtitem=0x5b0f6eec4330, sjinfo=0x0,
security_level=0, qualscope=0x5b0f6eec4730, ojscope=0x0,
outerjoin_nonnullable=0x0, incompatible_relids=0x0,
allow_equivalence=true, has_clone=false, is_clone=false,
postponed_oj_qual_list=0x0) at initsplan.c:2576 #11 0x00005b0f6d69146f
in distribute_quals_to_rels (root=0x5b0f6eeb13c8,
clauses=0x5b0f6eec0bb0, jtitem=0x5b0f6eec4330, sjinfo=0x0,
security_level=0, qualscope=0x5b0f6eec4730, ojscope=0x0,
outerjoin_nonnullable=0x0, incompatible_relids=0x0,
allow_equivalence=true, has_clone=false, is_clone=false,
postponed_oj_qual_list=0x0) at initsplan.c:2144

Thisis stillthe firstiterationof the fixesyouhave proposed,soI have
attachedthe patchindiffformat.I rewroteit,asyousuggestedinthe
firstletter[0].Icreateda separatefunctionthattriesto forman
OrClauseGroup node,butifit failsinthis, it returnsfalse,otherwiseit
processesthe generatedelementaccordingtowhat it found-eitheraddsit to
thelistasnew,oraddsa constantto anexistingone.

Ialsodividedonegenerallistof
suitableforconversionandunsuitableintotwodifferentones:appropriate_entriesandor_entries.Nowweare
onlylookinginthe listof suitableelementstoformANYexpr.

Thishelpsusto get ridofrepetitionsinthe codeyoumentioned.
Pleasewriteifthisis notthelogicthatyouhave seenbefore.

[0]
/messages/by-id/3381819.e9J7NaK4W3@thinkpad-pgpro

The errorwascausedby the specificsof storingthe "OR"clausesinthe
RestrictInfostructure.Scanning the orclauses list of the RestrictInfo
variable, wecouldfacenotonlytheitem with RestrictInfo
type,butalsotheBoolExpr type.

For example, when we have both or clauses and "AND" clauses together,
like x = 1 and (y =1 or y=2 or y=3 and z = 1). The structure looks like:

RestrictInfo->orclauses = [RestrictInfo [x=1],
RestrictInfo->orclauses = [RestrictInfo[y=1],
                    RestrictInfo [y=2],
                    BoolExpr = [Restrictinfo [y=3], RestrictInfo [z=1]
                   ]
                                         ]

It'sworkingfinenow.

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

Attachments:

v26-0001-Transform-OR-clauses-to-ANY-expression.patchtext/x-patch; charset=UTF-8; name=v26-0001-Transform-OR-clauses-to-ANY-expression.patchDownload
From 26eca98229749b20ad0c82a9fa55f4f37fd34d29 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 11 Jul 2024 19:01:10 +0300
Subject: [PATCH 1/2] Transform OR clauses to ANY expression

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...])
during adding restrictinfo's to the base relation.

Here Cn is a n-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/plan/initsplan.c        | 335 ++++++++++++++++++
 src/include/nodes/pathnodes.h                 |  31 ++
 src/test/regress/expected/create_index.out    |  32 +-
 src/test/regress/expected/partition_prune.out |  46 +--
 src/test/regress/expected/stats_ext.out       |  12 +-
 src/test/regress/expected/tidscan.out         |   6 +-
 src/tools/pgindent/typedefs.list              |   1 +
 7 files changed, 410 insertions(+), 53 deletions(-)

diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c
index e2c68fe6f99..572312be748 100644
--- a/src/backend/optimizer/plan/initsplan.c
+++ b/src/backend/optimizer/plan/initsplan.c
@@ -14,9 +14,13 @@
  */
 #include "postgres.h"
 
+#include "catalog/namespace.h"
+#include "catalog/pg_operator.h"
 #include "catalog/pg_type.h"
+#include "common/hashfn.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
+#include "nodes/queryjumble.h"
 #include "optimizer/clauses.h"
 #include "optimizer/cost.h"
 #include "optimizer/inherit.h"
@@ -29,8 +33,11 @@
 #include "optimizer/planner.h"
 #include "optimizer/restrictinfo.h"
 #include "parser/analyze.h"
+#include "parser/parse_coerce.h"
+#include "parser/parse_oper.h"
 #include "rewrite/rewriteManip.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/rel.h"
 #include "utils/typcache.h"
 
@@ -2617,6 +2624,308 @@ check_redundant_nullability_qual(PlannerInfo *root, Node *clause)
 	return false;
 }
 
+static bool
+try_prepare_single_or(RestrictInfo *rinfo, List **appropriate_group)
+{
+	OpExpr	   *orqual;
+	Node	   *const_expr;
+	Node	   *nconst_expr;
+	Oid			opno;
+	Oid			consttype;
+	Node	   *leftop,
+			   *rightop;
+	ListCell   *lc2;
+	bool found = false;
+	OrClauseGroup *or_clause_group;
+
+	if (!IsA(rinfo, RestrictInfo) || !IsA(rinfo->clause, OpExpr))
+	{
+		return false;
+	}
+
+	orqual = (OpExpr *) rinfo->clause;
+	opno = orqual->opno;
+	if (get_op_rettype(opno) != BOOLOID)
+	{
+		/* Only operator returning boolean suits OR -> ANY transformation */
+		return false;
+	}
+
+	/*
+		* Detect the constant side of the clause. Recall non-constant
+		* expression can be made not only with Vars, but also with Params,
+		* which is not bonded with any relation. Thus, we detect the const
+		* side - if another side is constant too, the orqual couldn't be an
+		* OpExpr.  Get pointers to constant and expression sides of the qual.
+		*/
+	leftop = get_leftop(orqual);
+	if (IsA(leftop, RelabelType))
+		leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+	rightop = get_rightop(orqual);
+	if (IsA(rightop, RelabelType))
+		rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+	if (IsA(leftop, Const) || IsA(leftop, Param))
+	{
+		opno = get_commutator(opno);
+
+		if (!OidIsValid(opno))
+		{/* commutator doesn't exist, we can't reverse the order */
+			return false;
+		}
+
+		nconst_expr = get_rightop(orqual);
+		const_expr = get_leftop(orqual);
+	}
+	else if (IsA(rightop, Const) || IsA(rightop, Param))
+	{
+		const_expr = get_rightop(orqual);
+		nconst_expr = get_leftop(orqual);
+	}
+	else
+	{
+		return false;
+	}
+
+	/*
+		* Forbid transformation for composite types, records, and volatile
+		* expressions.
+		*/
+	consttype = exprType(const_expr);
+	if (type_is_rowtype(exprType(const_expr)) ||
+		type_is_rowtype(consttype) ||
+		contain_volatile_functions((Node *) nconst_expr))
+	{
+		return false;
+	}
+
+	or_clause_group = makeNode(OrClauseGroup);
+
+	foreach(lc2, *appropriate_group)
+	{
+
+		if (!IsA(lfirst(lc2), OrClauseGroup))
+			Assert(0);
+
+		or_clause_group = (OrClauseGroup *) lfirst(lc2);
+
+		if (or_clause_group->opno == opno &&
+			or_clause_group->consttype == consttype &&
+			or_clause_group->inputcollid == exprCollation(const_expr) &&
+			equal(or_clause_group->expr, nconst_expr))
+		{
+			found = true;
+			break;
+		}
+	}
+
+	if (!found)
+	{
+		or_clause_group->expr = (Expr *) nconst_expr;
+		or_clause_group->exprs = list_make1((void *) orqual);
+		or_clause_group->opno = opno;
+		or_clause_group->inputcollid = exprCollation(const_expr);
+		or_clause_group->consttype = consttype;
+		or_clause_group->consts = list_make1(const_expr);
+		Assert(list_length(or_clause_group->exprs) == list_length(or_clause_group->consts));
+		*appropriate_group = lappend(*appropriate_group, or_clause_group);
+	}
+	else
+	{
+		or_clause_group->consts = lappend(or_clause_group->consts, const_expr);
+		or_clause_group->exprs = lappend(or_clause_group->exprs, (void *) orqual);
+		Assert(list_length(or_clause_group->exprs) == list_length(or_clause_group->consts));
+	}
+
+	return true;
+}
+
+/*
+ * transform_or_to_any -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to SAOP expressions.
+ *
+ * This transformation groups two-sided equality expression.  One side of
+ * such an expression must be a plain constant or constant expression.  The
+ * other side must be a variable expression without volatile functions.
+ * To group quals, opno, inputcollid of variable expression, and type of
+ * constant expression must be equal too.
+ *
+ * The grouping technique is based on the equivalence of variable sides of
+ * the expression: using exprId and equal() routine, it groups constant sides
+ * of similar clauses into an array.  After the grouping procedure, each
+ * couple ('variable expression' and 'constant array') forms a new SAOP
+ * operation, which is added to the args list of the returning expression.
+ */
+static List *
+transform_or_to_any(PlannerInfo *root, RestrictInfo * rinfo)
+{
+	List	   *appropriate_entries = NIL;
+	List	   *or_entries = NIL;
+	int			len_ors = ((BoolExpr *) rinfo->clause)->args ? list_length(((BoolExpr *) rinfo->clause)->args) : 0;
+	OrClauseGroup *restrict_info_entry = NULL;
+	ListCell	   *lc;
+	bool found;
+
+	if(len_ors < 2)
+		return NIL;
+
+	foreach(lc, ((BoolExpr *) rinfo->orclause)->args)
+	{
+		RestrictInfo *sub_rinfo;
+		Expr		 *or_qual = (Expr *) lfirst(lc);
+
+		if(!IsA(lfirst(lc), RestrictInfo))
+			or_entries = lappend(or_entries, (void *) or_qual);
+		else
+		{
+			sub_rinfo = (RestrictInfo *) lfirst(lc);
+
+			/*
+			* Add the restrict_info_entry to the list.  It is needed exclusively to manage
+			* the problem with the order of transformed clauses in explain.
+			* Hash value can depend on the platform and version.  Hence,
+			* sequental scan of the hash table would prone to change the
+			* order of clauses in lists and, as a result, break regression
+			* tests accidentially.
+			*/
+			found = try_prepare_single_or(sub_rinfo, &appropriate_entries);
+
+			if (!found)
+			{
+				or_entries = lappend(or_entries, (void *) sub_rinfo->clause);
+			}
+		}
+	}
+
+	if (list_length(or_entries) == len_ors || (appropriate_entries == NIL && list_length(appropriate_entries) < 1))
+		return NIL;
+
+	found = false;
+
+	/* Let's convert each group of clauses to an ANY expression. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of consts
+	 * more than 1. trivial groups move to OR-list again
+	 */
+
+	foreach(lc, appropriate_entries)
+	{
+		Oid			scalar_type;
+		Oid			array_type;
+
+		if (!IsA(lfirst(lc), OrClauseGroup))
+		{
+			Assert(0);
+		}
+
+		restrict_info_entry = (OrClauseGroup *) lfirst(lc);
+
+		Assert(list_length(restrict_info_entry->exprs) == list_length(restrict_info_entry->consts));
+
+		if (list_length(restrict_info_entry->consts) == 1)
+		{
+			/*
+			 * Only one element returns origin expression into the BoolExpr
+			 * args list unchanged.
+			 */
+			or_entries = list_concat(or_entries, (void *) restrict_info_entry->exprs);
+			continue;
+		}
+
+		/*
+		 * Do the transformation.
+		 */
+		scalar_type = restrict_info_entry->consttype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+			InvalidOid;
+
+		if (OidIsValid(array_type))
+		{
+			/*
+			 * OK: coerce all the right-hand non-Var inputs to the common type
+			 * and build an ArrayExpr for them.
+			 */
+			List	   *aexprs = NIL;
+			ArrayExpr  *newa = NULL;
+			ScalarArrayOpExpr *saopexpr = NULL;
+			HeapTuple	opertup;
+			Form_pg_operator operform;
+			List	   *namelist = NIL;
+			ListCell   *lc2;
+
+			foreach(lc2, restrict_info_entry->consts)
+			{
+				Node	   *node = (Node *) lfirst(lc2);
+
+				node = coerce_to_common_type(NULL, node, scalar_type,
+											 "OR ANY Transformation");
+				aexprs = lappend(aexprs, node);
+			}
+
+			newa = makeNode(ArrayExpr);
+			/* array_collid will be set by parse_collate.c */
+			newa->element_typeid = scalar_type;
+			newa->array_typeid = array_type;
+			newa->multidims = false;
+			newa->elements = aexprs;
+			newa->location = -1;
+
+			/*
+			 * Try to cast this expression to Const. Due to current strict
+			 * transformation rules it should be done [almost] every time.
+			 */
+			newa = (ArrayExpr *) eval_const_expressions(NULL, (Node *) newa);
+
+			opertup = SearchSysCache1(OPEROID,
+									  ObjectIdGetDatum(restrict_info_entry->opno));
+			if (!HeapTupleIsValid(opertup))
+				elog(ERROR, "cache lookup failed for operator %u",
+					 restrict_info_entry->opno);
+
+			operform = (Form_pg_operator) GETSTRUCT(opertup);
+			if (!OperatorIsVisible(restrict_info_entry->opno))
+				namelist = lappend(namelist, makeString(get_namespace_name(operform->oprnamespace)));
+
+			namelist = lappend(namelist, makeString(pstrdup(NameStr(operform->oprname))));
+			ReleaseSysCache(opertup);
+
+			saopexpr =
+				(ScalarArrayOpExpr *)
+				make_scalar_array_op(NULL,
+									 namelist,
+									 true,
+									 (Node *) restrict_info_entry->expr,
+									 (Node *) newa,
+									 -1);
+			saopexpr->inputcollid = restrict_info_entry->inputcollid;
+
+			or_entries = lappend(or_entries, (Expr *) saopexpr);
+
+			found = true;
+		}
+		else
+		{
+			/*
+			 * If the const node's (right side of operator expression) type
+			 * don't have “true” array type, then we cannnot do the
+			 * transformation. We simply concatenate the expression node.
+			 */
+			list_free(restrict_info_entry->consts);
+			or_entries = list_concat(or_entries, (void *) restrict_info_entry->exprs);
+		}
+	}
+	list_free(appropriate_entries);
+
+	/* One more trick: assemble correct clause */
+	if (found)
+		return or_entries;
+	else
+		return NIL;
+}
+
 /*
  * add_base_clause_to_rel
  *		Add 'restrictinfo' as a baserestrictinfo to the base relation denoted
@@ -2677,6 +2986,32 @@ add_base_clause_to_rel(PlannerInfo *root, Index relid,
 		}
 	}
 
+	if (restriction_is_or_clause(restrictinfo))
+	{
+		List *or_list = transform_or_to_any(root, restrictinfo);
+
+		if (or_list != NIL)
+		{
+			Expr *clause = list_length(or_list) > 1 ?
+							makeBoolExpr(OR_EXPR, or_list,
+										((BoolExpr *) restrictinfo->clause)->location) :
+							linitial(or_list);
+
+			RestrictInfo *rinfo;
+			rinfo = make_restrictinfo(root,
+										clause,
+										restrictinfo->is_pushed_down,
+										restrictinfo->has_clone,
+										restrictinfo->is_clone,
+										restrictinfo->pseudoconstant,
+										restrictinfo->security_level,
+										restrictinfo->required_relids,
+										restrictinfo->incompatible_relids,
+										restrictinfo->outer_relids);
+			restrictinfo = rinfo;
+		}
+	}
+
 	/* Add clause to rel's restriction list */
 	rel->baserestrictinfo = lappend(rel->baserestrictinfo, restrictinfo);
 
diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h
index 14ccfc1ac1c..f48ddb8c385 100644
--- a/src/include/nodes/pathnodes.h
+++ b/src/include/nodes/pathnodes.h
@@ -2708,6 +2708,37 @@ typedef struct RestrictInfo
 	Oid			right_hasheqoperator pg_node_attr(equal_ignore);
 } RestrictInfo;
 
+/*
+ * The group of similar operator expressions in transform_or_to_any().
+ */
+typedef struct OrClauseGroup
+{
+	pg_node_attr(nodetag_only)
+
+	NodeTag		type;
+
+	/* The expression of the variable side of operator */
+	Expr	   *expr;
+	/* The operator of the operator expression */
+	Oid			opno;
+	/* The collation of the operator expression */
+	Oid			inputcollid;
+	/* The type of constant side of operator */
+	Oid			consttype;
+
+	/* The list of constant sides of operators */
+	List	   *consts;
+
+	/*
+	 * List of source expressions.  We need this for convenience in case we
+	 * will give up on transformation.
+	 */
+	List	   *exprs;
+
+	Node	   *const_expr;
+} OrClauseGroup;
+
+
 /*
  * This macro embodies the correct way to test whether a RestrictInfo is
  * "pushed down" to a given outer join, that is, should be treated as a filter
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..bcae073143a 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,11 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1867,20 +1860,17 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 7a03b4e3607..dc0876b4bb3 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -100,23 +100,23 @@ explain (costs off) select * from lp where a is null;
 (2 rows)
 
 explain (costs off) select * from lp where a = 'a' or a = 'c';
-                        QUERY PLAN                        
-----------------------------------------------------------
+                  QUERY PLAN                   
+-----------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a = 'a'::bpchar) OR (a = 'c'::bpchar))
+         Filter: (a = ANY ('{a,c}'::bpchar[]))
 (5 rows)
 
 explain (costs off) select * from lp where a is not null and (a = 'a' or a = 'c');
-                                   QUERY PLAN                                   
---------------------------------------------------------------------------------
+                             QUERY PLAN                              
+---------------------------------------------------------------------
  Append
    ->  Seq Scan on lp_ad lp_1
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
    ->  Seq Scan on lp_bc lp_2
-         Filter: ((a IS NOT NULL) AND ((a = 'a'::bpchar) OR (a = 'c'::bpchar)))
+         Filter: ((a IS NOT NULL) AND (a = ANY ('{a,c}'::bpchar[])))
 (5 rows)
 
 explain (costs off) select * from lp where a <> 'g';
@@ -533,10 +533,10 @@ explain (costs off) select * from rlp where a <= 31;
 (27 rows)
 
 explain (costs off) select * from rlp where a = 1 or a = 7;
-           QUERY PLAN           
---------------------------------
+                QUERY PLAN                
+------------------------------------------
  Seq Scan on rlp2 rlp
-   Filter: ((a = 1) OR (a = 7))
+   Filter: (a = ANY ('{1,7}'::integer[]))
 (2 rows)
 
 explain (costs off) select * from rlp where a = 1 or b = 'ab';
@@ -614,13 +614,13 @@ explain (costs off) select * from rlp where a < 1 or (a > 20 and a < 25);
 
 -- where clause contradicts sub-partition's constraint
 explain (costs off) select * from rlp where a = 20 or a = 40;
-               QUERY PLAN               
-----------------------------------------
+                    QUERY PLAN                    
+--------------------------------------------------
  Append
    ->  Seq Scan on rlp4_1 rlp_1
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
    ->  Seq Scan on rlp5_default rlp_2
-         Filter: ((a = 20) OR (a = 40))
+         Filter: (a = ANY ('{20,40}'::integer[]))
 (5 rows)
 
 explain (costs off) select * from rlp3 where a = 20;   /* empty */
@@ -2090,10 +2090,10 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
 
 explain (costs off) select * from hp where a = 1 and b = 'abcde' and
   (c = 2 or c = 3);
-                              QUERY PLAN                              
-----------------------------------------------------------------------
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Seq Scan on hp2 hp
-   Filter: ((a = 1) AND (b = 'abcde'::text) AND ((c = 2) OR (c = 3)))
+   Filter: ((c = ANY ('{2,3}'::integer[])) AND (a = 1) AND (b = 'abcde'::text))
 (2 rows)
 
 drop table hp2;
@@ -2429,8 +2429,8 @@ select explain_parallel_append('execute ab_q5 (33, 44, 55)');
 
 -- Test Parallel Append with PARAM_EXEC Params
 select explain_parallel_append('select count(*) from ab where (a = (select 1) or a = (select 3)) and b = 2');
-                                    explain_parallel_append                                     
-------------------------------------------------------------------------------------------------
+                                      explain_parallel_append                                      
+---------------------------------------------------------------------------------------------------
  Aggregate (actual rows=N loops=N)
    InitPlan 1
      ->  Result (actual rows=N loops=N)
@@ -2441,11 +2441,11 @@ select explain_parallel_append('select count(*) from ab where (a = (select 1) or
          Workers Launched: N
          ->  Parallel Append (actual rows=N loops=N)
                ->  Parallel Seq Scan on ab_a1_b2 ab_1 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = (InitPlan 1).col1) OR (a = (InitPlan 2).col1)))
+                     Filter: ((a = ANY (ARRAY[(InitPlan 1).col1, (InitPlan 2).col1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a2_b2 ab_2 (never executed)
-                     Filter: ((b = 2) AND ((a = (InitPlan 1).col1) OR (a = (InitPlan 2).col1)))
+                     Filter: ((a = ANY (ARRAY[(InitPlan 1).col1, (InitPlan 2).col1])) AND (b = 2))
                ->  Parallel Seq Scan on ab_a3_b2 ab_3 (actual rows=N loops=N)
-                     Filter: ((b = 2) AND ((a = (InitPlan 1).col1) OR (a = (InitPlan 2).col1)))
+                     Filter: ((a = ANY (ARRAY[(InitPlan 1).col1, (InitPlan 2).col1])) AND (b = 2))
 (15 rows)
 
 -- Test pruning during parallel nested loop query
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..7678744181c 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -1322,19 +1322,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND b = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 2 OR a = 51 OR a = 52) AND (b = ''1'' OR b = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes are incompatible
@@ -1664,19 +1664,19 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND upper(b) = ''1''');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 102) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-        99 |    100
+       100 |    100
 (1 row)
 
 SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE ((a * 2) = 2 OR (a * 2) = 4 OR (a * 2) = 102 OR (a * 2) = 104) AND (upper(b) = ''1'' OR upper(b) = ''2'')');
  estimated | actual 
 -----------+--------
-       197 |    200
+       200 |    200
 (1 row)
 
 -- OR clauses referencing different attributes
diff --git a/src/test/regress/expected/tidscan.out b/src/test/regress/expected/tidscan.out
index f133b5a4ac7..09553f19524 100644
--- a/src/test/regress/expected/tidscan.out
+++ b/src/test/regress/expected/tidscan.out
@@ -43,10 +43,10 @@ SELECT ctid, * FROM tidscan WHERE '(0,1)' = ctid;
 -- OR'd clauses
 EXPLAIN (COSTS OFF)
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
-                          QUERY PLAN                          
---------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
  Tid Scan on tidscan
-   TID Cond: ((ctid = '(0,2)'::tid) OR ('(0,1)'::tid = ctid))
+   TID Cond: (ctid = ANY ('{"(0,2)","(0,1)"}'::tid[]))
 (2 rows)
 
 SELECT ctid, * FROM tidscan WHERE ctid = '(0,2)' OR '(0,1)' = ctid;
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 9320e4d8080..4ec9e2ce32f 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1715,6 +1715,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroup
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

v26-0002-Add-some-new-tests-to-check-the-functionality-of.patchtext/x-patch; charset=UTF-8; name=v26-0002-Add-some-new-tests-to-check-the-functionality-of.patchDownload
From 8afa37e0843b2ce8cc8acb23e435a6bb1d92cc44 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 11 Jul 2024 19:08:17 +0300
Subject: [PATCH 2/2] Add some new tests to check the functionality of
 transformation of OR expressions to Any expression.

---
 src/test/regress/sql/create_index.sql | 42 +++++++++++++++++++++++++++
 src/test/regress/sql/join.sql         |  9 ++++++
 2 files changed, 51 insertions(+)

diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..f74ad415fbf 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -726,6 +726,24 @@ DROP TABLE onek_with_null;
 -- Check bitmap index path planning
 --
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -738,6 +756,30 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index e3d26520832..cf02cc34ed0 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1409,6 +1409,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
-- 
2.34.1

#205Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#204)
Re: POC, WIP: OR-clause support for indexes

Sorry for repeating, but I have noticed that this message displays
incorrectly and just in case I'll duplicate it.

On 11.07.2024 19:17, Alena Rybakina wrote:

The errorwascausedby the specificsof storingthe "OR"clausesinthe
RestrictInfostructure.Scanning the orclauses list of the RestrictInfo
variable, wecouldfacenotonlytheitem with RestrictInfo
type,butalsotheBoolExpr type.

For example, when we have both or clauses and "AND" clauses together,
like x = 1 and (y =1 or y=2 or y=3 and z = 1). The structure looks like:

RestrictInfo->orclauses = [RestrictInfo [x=1],
RestrictInfo->orclauses = [RestrictInfo[y=1],
                    RestrictInfo [y=2],
                    BoolExpr = [Restrictinfo [y=3], RestrictInfo [z=1]
                   ]
                                         ]

It'sworkingfinenow.

The error was caused by the specifics of storing the "OR" clauses in the
RestrictInfo structure. When viewing the list of or offers, we could
encounter not only the RestrictInfo type, but also the BoolExpr type.
It's working fine now.

For example, when we have both or clauses and "AND" clauses together,
like x = 1 and (y =1 or y=2 or y=3 and z = 1). The structure looks like:

RestrictInfo->orclauses = [RestrictInfo [x=1],
RestrictInfo->orclauses = [RestrictInfo[y=1],
RestrictInfo [y=2],
BoolExpr = [Restrictinfo [y=3], RestrictInfo [z=1]
]
                                         ]

It's working fine now.

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#206Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#204)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi, Alena!

On Thu, Jul 11, 2024 at 7:17 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I have finished patch and processed almost your suggestions (from [0], [1], [2]). It remains only to add tests where the conversion should work, but I will add this in the next version.

[0] /messages/by-id/3381819.e9J7NaK4W3@thinkpad-pgpro

[1] /messages/by-id/9736220.CDJkKcVGEf@thinkpad-pgpro

[2] /messages/by-id/2193851.QkHrqEjB74@thinkpad-pgpro

I dare making another revision of this patch. In this version I moved
the transformation to match_clause_to_indexcol(). Therefore, this
allows to successfully construct index scans with SAOP, but has no
degradation in generation of bitmap scans which I observed in [1] and
[2]: . BTW, I found that my description in [2] lacks of t_b_c_idx index definition. Sorry for that.
definition. Sorry for that.

Given that now we're doing OR-to-ANY transformation solely to match an
index we don't need complex analysis of OR-list, which potentially
could take quadratic time. Instead, we're trying to match every OR
element to an index and quit immediately on failure.

I'd like to head a feedback on the new place to apply the
transformation. It looks like significant simplification for me and
the way to go.

Also, I have addressed some of notes by Robert Haas [3]. In v27 we
don't use expression evaluation, but directly construct an array
constant when possible. Also we don't transform operator id to string
and back, but directly construct SAOP instead.

Links.
1. /messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.com
2. /messages/by-id/CAPpHfdtSXxhdv3mLOLjEewGeXJ+Ftfhjqodn1WWuq5JLsKx48g@mail.gmail.com
3. /messages/by-id/CA+Tgmobu0DUFCTF28DuAi975mEc4xYqX3xyt8RA0WbnyrYg+Fw@mail.gmail.com

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v27-0001-Transform-OR-clauses-to-ANY-expression.patchapplication/octet-stream; name=v27-0001-Transform-OR-clauses-to-ANY-expression.patchDownload
From 75d1d6a20a7eda94b0ec91611840e9b3f295c4ca Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 11 Jul 2024 19:01:10 +0300
Subject: [PATCH v27] Transform OR clauses to ANY expression

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...])
during matching a clause to index.

Here Cn is a n-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 241 +++++++++++++++++++++
 src/test/regress/expected/create_index.out | 183 ++++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/sql/create_index.sql      |  42 ++++
 src/test/regress/sql/join.sql              |   9 +
 src/tools/pgindent/typedefs.list           |   1 +
 6 files changed, 511 insertions(+), 22 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..4fd0bbce2ce 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -19,10 +19,12 @@
 
 #include "access/stratnum.h"
 #include "access/sysattr.h"
+#include "catalog/namespace.h"
 #include "catalog/pg_am.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
+#include "nodes/bitmapset.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
 #include "nodes/supportnodes.h"
@@ -30,9 +32,14 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/pathnode.h"
 #include "optimizer/paths.h"
+#include "optimizer/planmain.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "parser/parse_oper.h"
+#include "postgres_ext.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/selfuncs.h"
 
 
@@ -177,6 +184,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2259,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2786,232 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  where it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *newa = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	if (bms_is_member(index->rel->relid, rinfo->right_relids))
+		return NULL;
+
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *sub_rinfo;
+		OpExpr	   *sub_qual;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *const_expr;
+		Node	   *nconst_expr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			return NULL;
+
+		sub_rinfo = (RestrictInfo *) lfirst(lc);
+		sub_qual = (OpExpr *) sub_rinfo->clause;
+		opno = sub_qual->opno;
+
+		if (!IsA(sub_rinfo->clause, OpExpr))
+			return NULL;
+
+		if (sub_rinfo->is_pushed_down != rinfo->is_pushed_down ||
+			sub_rinfo->is_clone != rinfo->is_clone ||
+			sub_rinfo->security_level != rinfo->security_level ||
+			!bms_equal(sub_rinfo->required_relids, rinfo->required_relids) ||
+			!bms_equal(sub_rinfo->incompatible_relids, rinfo->incompatible_relids) ||
+			!bms_equal(sub_rinfo->outer_relids, rinfo->outer_relids))
+		{
+			/* RestrictInfo parameters don't match parent, so bail out */
+			return NULL;
+		}
+
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			return NULL;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be an
+		 * OpExpr.  Get pointers to constant and expression sides of the qual.
+		 */
+
+		leftop = get_leftop(sub_qual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(sub_qual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				return false;
+			}
+
+			nconst_expr = rightop;
+			const_expr = leftop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			const_expr = rightop;
+			nconst_expr = leftop;
+		}
+		else
+		{
+			return NULL;
+		}
+
+		if (!match_index_to_operand(nconst_expr, indexcol, index))
+			return NULL;
+
+		/*
+		 * Forbid transformation for composite types, records.
+		 */
+		if (type_is_rowtype(exprType(nconst_expr)) ||
+			type_is_rowtype(exprType(const_expr)))
+		{
+			return NULL;
+		}
+
+		if (!OidIsValid(matchOpno))
+		{
+			matchOpno = opno;
+			indexExpr = nconst_expr;
+			consttype = exprType(const_expr);
+			arraytype = get_array_type(consttype);
+			inputcollid = sub_qual->inputcollid;
+			if (!OidIsValid(arraytype))
+				return NULL;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != sub_qual->inputcollid)
+				return NULL;
+		}
+
+		if (IsA(const_expr, Param))
+			have_param = true;
+		consts = lappend(consts, const_expr);
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arexpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arexpr->element_typeid = consttype;
+		arexpr->array_typeid = arraytype;
+		arexpr->multidims = false;
+		arexpr->elements = consts;
+		arexpr->location = -1;
+
+		newa = (Node *) arexpr;
+	}
+	else
+	{
+		/* We have only Costs's.  Can generate constant array. */
+
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *ar;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+		{
+			Node	   *elem = (Node *) lfirst(lc);
+
+			elems[i++] = ((Const *) elem)->constvalue;
+		}
+
+		ar = construct_array(elems, i, consttype, typlen, typbyval, typalign);
+		newa = (Node *) makeConst(arraytype, -1, inputcollid, -1, PointerGetDatum(ar), false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* and build the expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	/* inputcollid will be set by parse_collate.c */
+	saopexpr->args = list_make2(indexExpr, newa);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = make_restrictinfo(root,
+									   &saopexpr->xpr,
+									   rinfo->is_pushed_down,
+									   rinfo->has_clone,
+									   rinfo->is_clone,
+									   rinfo->pseudoconstant,
+									   rinfo->security_level,
+									   rinfo->required_relids,
+									   rinfo->incompatible_relids,
+									   rinfo->outer_relids);
+	iclause->indexquals = list_make1(iclause->rinfo);
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..c2b25936c8c 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,11 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,14 +1857,166 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,11 +2024,13 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 53f70d72ed6..abe98ff3c53 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..f74ad415fbf 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -726,6 +726,24 @@ DROP TABLE onek_with_null;
 -- Check bitmap index path planning
 --
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -738,6 +756,30 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index b4d7f9217ce..992c80f9350 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1717,6 +1717,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroup
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.39.3 (Apple Git-145)

#207Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#206)
Re: POC, WIP: OR-clause support for indexes

Hi! Thanks for your contribution to this topic!

On 17.07.2024 03:03, Alexander Korotkov wrote:

Hi, Alena!

On Thu, Jul 11, 2024 at 7:17 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I have finished patch and processed almost your suggestions (from [0], [1], [2]). It remains only to add tests where the conversion should work, but I will add this in the next version.

[0] /messages/by-id/3381819.e9J7NaK4W3@thinkpad-pgpro

[1] /messages/by-id/9736220.CDJkKcVGEf@thinkpad-pgpro

[2] /messages/by-id/2193851.QkHrqEjB74@thinkpad-pgpro

I dare making another revision of this patch. In this version I moved
the transformation to match_clause_to_indexcol(). Therefore, this
allows to successfully construct index scans with SAOP, but has no
degradation in generation of bitmap scans which I observed in [1] and
[2]. BTW, I found that my description in [2] lacks of t_b_c_idx index
definition. Sorry for that.

Given that now we're doing OR-to-ANY transformation solely to match an
index we don't need complex analysis of OR-list, which potentially
could take quadratic time. Instead, we're trying to match every OR
element to an index and quit immediately on failure.

Yes I see that. I will look at this in detail, but so far I have not
found any unpleasant side effects indicating that the patch should be
moved to another place and this is very good)

The only thing that worries me so far is that most likely we will need
to analyze the changes in rinfo and distribute them to others places
where links about them are used.
But I need to look at this in more detail separately before discussing it.

Yes, I am ready to agree that there was no degradation in tests [1] and
[2]: . But just in case, I will do a review to rule out any other problems.

I'd like to head a feedback on the new place to apply the
transformation. It looks like significant simplification for me and
the way to go.

Also, I have addressed some of notes by Robert Haas [3]. In v27 we
don't use expression evaluation, but directly construct an array
constant when possible. Also we don't transform operator id to string
and back, but directly construct SAOP instead.

Links.
1. /messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.com
2. /messages/by-id/CAPpHfdtSXxhdv3mLOLjEewGeXJ+Ftfhjqodn1WWuq5JLsKx48g@mail.gmail.com
3. /messages/by-id/CA+Tgmobu0DUFCTF28DuAi975mEc4xYqX3xyt8RA0WbnyrYg+Fw@mail.gmail.com

Thanks for your effort and any help is welcome)

Yesterday I finished a big project in my work and now I'm ready to
continue working on this thread. I'll write the results one of these days.

--
Regards,
Alena Rybakina
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#208Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#207)
Re: POC, WIP: OR-clause support for indexes

Hi, Alena!

On Wed, Jul 17, 2024 at 3:53 PM Alena Rybakina <a.rybakina@postgrespro.ru>
wrote:

On 17.07.2024 03:03, Alexander Korotkov wrote:

Hi, Alena!

On Thu, Jul 11, 2024 at 7:17 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I have finished patch and processed almost your suggestions (from [0],

[1], [2]). It remains only to add tests where the conversion should work,
but I will add this in the next version.

[0]

/messages/by-id/3381819.e9J7NaK4W3@thinkpad-pgpro

[1]

/messages/by-id/9736220.CDJkKcVGEf@thinkpad-pgpro

[2]

/messages/by-id/2193851.QkHrqEjB74@thinkpad-pgpro

I dare making another revision of this patch. In this version I moved
the transformation to match_clause_to_indexcol(). Therefore, this
allows to successfully construct index scans with SAOP, but has no
degradation in generation of bitmap scans which I observed in [1] and
[2]. BTW, I found that my description in [2] lacks of t_b_c_idx index
definition. Sorry for that.

Given that now we're doing OR-to-ANY transformation solely to match an
index we don't need complex analysis of OR-list, which potentially
could take quadratic time. Instead, we're trying to match every OR
element to an index and quit immediately on failure.

Yes I see that. I will look at this in detail, but so far I have not
found any unpleasant side effects indicating that the patch should be
moved to another place and this is very good)

The only thing that worries me so far is that most likely we will need
to analyze the changes in rinfo and distribute them to others places
where links about them are used.
But I need to look at this in more detail separately before discussing it.

I'm not sure if would need to distribute changes of RestrictInfo's, because
we're modifying anything in-place. Instead we create a new RestrictInfo
for IndexOptInfo. I think this is what Robert proposed at [1]. The side
effect of this I yet see is redundancy of clauses in [2] test case.

QUERY PLAN

----------------------------------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=19.70..26.93 rows=5001 width=12)
Recheck Cond: (((b = 1) AND (b = ANY ('{1,2}'::integer[])) AND (c = 2))
OR ((a = 1) AND (b = 2) AND (b = ANY ('{1,2}'::integer[]))))
Filter: ((a = 1) AND (c = 2))
-> BitmapOr (cost=19.70..19.70 rows=2 width=0)
-> Bitmap Index Scan on t_b_c_idx (cost=0.00..8.60 rows=1
width=0)
Index Cond: ((b = 1) AND (b = ANY ('{1,2}'::integer[])) AND
(c = 2))
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..8.60 rows=1
width=0)
Index Cond: ((a = 1) AND (b = 2) AND (b = ANY
('{1,2}'::integer[])))
(8 rows)

You can see that index conds and recheck conds contain both SAOP clauses
and equality clauses. I this this happens because bitmap scan planning
code doesn't understands equivalency of original and transformed
RestrictInfo's. I'm not yet sure what to do about this. We probably need
to teach bitmap scan planning code to understand this equivalency. Or,
otherwise, just allow this redundancy given that this is quite rare case I
believe.

Yes, I am ready to agree that there was no degradation in tests [1] and
[2]. But just in case, I will do a review to rule out any other problems.

I'd like to head a feedback on the new place to apply the
transformation. It looks like significant simplification for me and
the way to go.

Also, I have addressed some of notes by Robert Haas [3]. In v27 we
don't use expression evaluation, but directly construct an array
constant when possible. Also we don't transform operator id to string
and back, but directly construct SAOP instead.

Links.
1.

/messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.com

2.

/messages/by-id/CAPpHfdtSXxhdv3mLOLjEewGeXJ+Ftfhjqodn1WWuq5JLsKx48g@mail.gmail.com

3.

/messages/by-id/CA+Tgmobu0DUFCTF28DuAi975mEc4xYqX3xyt8RA0WbnyrYg+Fw@mail.gmail.com

Thanks for your effort and any help is welcome)

Yesterday I finished a big project in my work and now I'm ready to
continue working on this thread. I'll write the results one of these days.

Great, thank you. I would appreciate your further work on this patch.
Apart from general feedback on approach, the last patch requires comments,
code beautification etc.

Links.
1.
/messages/by-id/CA+TgmoarYLO6PL+FEnXJ6A-57KsVsotpvHnB771M-wXQOGNy9w@mail.gmail.com
2.
/messages/by-id/CAPpHfdtSXxhdv3mLOLjEewGeXJ+Ftfhjqodn1WWuq5JLsKx48g@mail.gmail.com

------
Regards,
Alexander Korotkov
Supabase

#209Nikolay Shaplov
dhyan@nataraj.su
In reply to: Alexander Korotkov (#208)
Re: POC, WIP: OR-clause support for indexes

В письме от среда, 17 июля 2024 г. 22:36:19 MSK пользователь Alexander
Korotkov написал:

Hi All!

I am continue reading the patch, now it's newer version

First main question:

As far a I can get, the entry point for OR->ANY convertation have been moved
to match_clause_to_indexcol funtion, that checks if some restriction can use
index for performance.

The thing I do not understand what match_clause_to_indexcol actually received
as arguments. Should this be set of expressions with OR in between grouped by
one of the expression argument?

If not I do not understand how this ever should work.

The rest is about code readability

+	if (bms_is_member(index->rel->relid, rinfo->right_relids))
+		return NULL;

This check it totally not obvious for person who is not deep into postgres
code. There should go comment explaining what are we checking for, and why it
does not suit our purposes

+ foreach(lc, orclause->args)
+ {

Being no great expert in postgres code, I am confused what are we iterating on
here? Two arguments of OR statement? (a>1) OR (b>2) those in brackets? Or
what? Comment explaining that would be a great help here.

+if (sub_rinfo->is_pushed_down != rinfo->is_pushed_down ||
+	sub_rinfo->is_clone != rinfo->is_clone ||
+	sub_rinfo->security_level != rinfo->security_level ||
+	!bms_equal(sub_rinfo->required_relids, rinfo->required_relids) ||
+	!bms_equal(sub_rinfo->incompatible_relids, rinfo- 

incompatible_relids) ||

+	!bms_equal(sub_rinfo->outer_relids, rinfo->outer_relids))
+	{ 

This check it totally mind-blowing... What in the name of existence is going
on here?

I would suggest to split these checks into parts (compiler optimizer should
take care about overhead) and give each part a sane explanation.

--
Nikolay Shaplov aka Nataraj
Fuzzing Engineer at Postgres Professional
Matrix IM: @dhyan:nataraj.su

#210Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Nikolay Shaplov (#209)
Re: POC, WIP: OR-clause support for indexes

Hi! Thank you for your contribution to this thread!

To be honest,I saw a larger problem. Look at the query bellow:

master:

alena@postgres=# create table t (a int not null, b int not null, c int
not null);
insert into t (select 1, 1, i from generate_series(1,10000) i);
insert into t (select i, 2, 2 from generate_series(1,10000) i);
create index t_a_b_idx on t (a, b);
create statistics t_a_b_stat (mcv) on a, b from t;
create statistics t_b_c_stat (mcv) on b, c from t;
vacuum analyze t;
CREATE TABLE
INSERT 0 10000
INSERT 0 10000
CREATE INDEX
CREATE STATISTICS
CREATE STATISTICS
VACUUM
alena@postgres=# explain select * from t where a = 1 and (b = 1 or b =
2) and c = 2;
                                  QUERY PLAN
------------------------------------------------------------------------------
 Bitmap Heap Scan on t  (cost=156.55..465.57 rows=5001 width=12)
   Recheck Cond: (a = 1)
   Filter: ((c = 2) AND ((b = 1) OR (b = 2)))
   ->  Bitmap Index Scan on t_a_b_idx  (cost=0.00..155.29 rows=10001
width=0)
         Index Cond: (a = 1)
(5 rows)

The query plan if v26[0]/messages/by-id/3b9bb831-da52-4779-8f3e-f8b6b83ba41f@postgrespro.ru and v27[1]/messages/by-id/CAPpHfdvhWE5pArZhgJeLViLx3-A3rxEREZvfkTj3E=h7q-Bx9w@mail.gmail.com versions are equal and wrong in my
opinion -where is c=2 expression?

v27 [1]/messages/by-id/CAPpHfdvhWE5pArZhgJeLViLx3-A3rxEREZvfkTj3E=h7q-Bx9w@mail.gmail.com
alena@postgres=# explain select * from t where a = 1 and (b = 1 or b =
2) and c = 2;
                                  QUERY PLAN
------------------------------------------------------------------------------
 Bitmap Heap Scan on t  (cost=165.85..474.87 rows=5001 width=12)
   Recheck Cond: ((a = 1) AND (b = ANY ('{1,2}'::integer[])))
   Filter: (c = 2)
   ->  Bitmap Index Scan on t_a_b_idx  (cost=0.00..164.59 rows=10001
width=0)
         Index Cond: ((a = 1) AND (b = ANY ('{1,2}'::integer[])))
(5 rows)
v26 [0]/messages/by-id/3b9bb831-da52-4779-8f3e-f8b6b83ba41f@postgrespro.ru
alena@postgres=# explain select * from t where a = 1 and (b = 1 or b =
2) and c = 2;
                                  QUERY PLAN
------------------------------------------------------------------------------
 Bitmap Heap Scan on t  (cost=165.85..449.86 rows=5001 width=12)
   Recheck Cond: ((a = 1) AND (b = ANY ('{1,2}'::integer[])))
   Filter: (c = 2)
   ->  Bitmap Index Scan on t_a_b_idx  (cost=0.00..164.59 rows=10001
width=0)
         Index Cond: ((a = 1) AND (b = ANY ('{1,2}'::integer[])))
(5 rows)

In addition, I noticed that the ANY expression will be formed only for
first group and ignore for others, like in the sample bellow:

v26 version [0]/messages/by-id/3b9bb831-da52-4779-8f3e-f8b6b83ba41f@postgrespro.ru:

alena@postgres=# explain select * from t where (b = 1 or b = 2) and (a =
2 or a=3);
                                    QUERY PLAN
-----------------------------------------------------------------------------------
 Index Scan using t_a_b_idx on t  (cost=0.29..24.75 rows=2 width=12)
   Index Cond: ((a = ANY ('{2,3}'::integer[])) AND (b = ANY
('{1,2}'::integer[])))
(2 rows)

v27 version [1]/messages/by-id/CAPpHfdvhWE5pArZhgJeLViLx3-A3rxEREZvfkTj3E=h7q-Bx9w@mail.gmail.com:

alena@postgres=# explain select * from t where (b = 1 or b = 2 or a = 2
or a=3);
                       QUERY PLAN
--------------------------------------------------------
 Seq Scan on t  (cost=0.00..509.00 rows=14999 width=12)
   Filter: ((b = 1) OR (b = 2) OR (a = 2) OR (a = 3))
(2 rows)

alena@postgres=# create index a_idx on t(a);
CREATE INDEX
alena@postgres=# create index b_idx on t(b);
CREATE INDEX
alena@postgres=# analyze;
ANALYZE

v26:

alena@postgres=# explain select * from t where (b = 1 or b = 2 or a = 2
or a=3);
                                     QUERY PLAN
------------------------------------------------------------------------------------
 Bitmap Heap Scan on t  (cost=17.18..30.94 rows=4 width=12)
   Recheck Cond: ((a = ANY ('{2,3}'::integer[])) OR (a = ANY
('{2,3}'::integer[])))
   ->  BitmapOr  (cost=17.18..17.18 rows=4 width=0)
         ->  Bitmap Index Scan on a_idx  (cost=0.00..8.59 rows=2 width=0)
               Index Cond: (a = ANY ('{2,3}'::integer[]))
         ->  Bitmap Index Scan on a_idx  (cost=0.00..8.59 rows=2 width=0)
               Index Cond: (a = ANY ('{2,3}'::integer[]))
(7 rows)

v27:

alena@postgres=# explain select * from t where (b = 1 or b = 2 or a = 2
or a=3);
                       QUERY PLAN
--------------------------------------------------------
 Seq Scan on t  (cost=0.00..509.00 rows=14999 width=12)
   Filter: ((b = 1) OR (b = 2) OR (a = 2) OR (a = 3))
(2 rows)

The behavior in version 26 is incorrect, but in version 27, it does not
select anything other than seqscan

Since Thursday I have been trying to add the code forming groups of
identical "OR" expressions, as in version 26. I'm currently debugging
errors.

On 21.07.2024 11:17, Nikolay Shaplov wrote:

В письме от среда, 17 июля 2024 г. 22:36:19 MSK пользователь Alexander
Korotkov написал:

Hi All!

I am continue reading the patch, now it's newer version

First main question:

As far a I can get, the entry point for OR->ANY convertation have been moved
to match_clause_to_indexcol funtion, that checks if some restriction can use
index for performance.

The thing I do not understand what match_clause_to_indexcol actually received
as arguments. Should this be set of expressions with OR in between grouped by
one of the expression argument?

If not I do not understand how this ever should work.

 The point is that we do the transformation for those columns that have
an index, since this transformation is most useful in these cases. we
pass the parameters index relation and column number to find out
information about it.

The rest is about code readability

+	if (bms_is_member(index->rel->relid, rinfo->right_relids))
+		return NULL;

To be honest, I'm not sure that I understand your question. Could you
explain me?

This check it totally not obvious for person who is not deep into postgres
code. There should go comment explaining what are we checking for, and why it
does not suit our purposes

+ foreach(lc, orclause->args)
+ {

I'll add it, thank you.

Being no great expert in postgres code, I am confused what are we iterating on
here? Two arguments of OR statement? (a>1) OR (b>2) those in brackets? Or
what? Comment explaining that would be a great help here.

+if (sub_rinfo->is_pushed_down != rinfo->is_pushed_down ||
+	sub_rinfo->is_clone != rinfo->is_clone ||
+	sub_rinfo->security_level != rinfo->security_level ||
+	!bms_equal(sub_rinfo->required_relids, rinfo->required_relids) ||
+	!bms_equal(sub_rinfo->incompatible_relids, rinfo-

incompatible_relids) ||

+	!bms_equal(sub_rinfo->outer_relids, rinfo->outer_relids))
+	{

I'll add it.

This check it totally mind-blowing... What in the name of existence is going
on here?

I would suggest to split these checks into parts (compiler optimizer should
take care about overhead) and give each part a sane explanation.

Alexander suggested moving the transformation to another place and it is
correct in my opinion. All previous problems are now gone.
But he also cut the code - he made a transformation for one group of
"OR" expressions. I agree, some parts don't yet
provide enough explanation of what's going on. I'm correcting this now.

Speaking of the changes according to your suggestions, I made them in
version 26 [0]/messages/by-id/3b9bb831-da52-4779-8f3e-f8b6b83ba41f@postgrespro.ru and just part of that code will end up in the current
version of the patch to process all groups of "OR" expressions.

I'll try to do this as best I can, but it took me a while to figure out
how to properly organize RestrictInfo in the index.

[0]: /messages/by-id/3b9bb831-da52-4779-8f3e-f8b6b83ba41f@postgrespro.ru
/messages/by-id/3b9bb831-da52-4779-8f3e-f8b6b83ba41f@postgrespro.ru

[1]: /messages/by-id/CAPpHfdvhWE5pArZhgJeLViLx3-A3rxEREZvfkTj3E=h7q-Bx9w@mail.gmail.com
/messages/by-id/CAPpHfdvhWE5pArZhgJeLViLx3-A3rxEREZvfkTj3E=h7q-Bx9w@mail.gmail.com

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#211Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#210)
Re: POC, WIP: OR-clause support for indexes

Hi, Alena!

Let me answer to some of your findings.

On Mon, Jul 22, 2024 at 12:53 AM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

To be honest,I saw a larger problem. Look at the query bellow:

master:

alena@postgres=# create table t (a int not null, b int not null, c int not null);
insert into t (select 1, 1, i from generate_series(1,10000) i);
insert into t (select i, 2, 2 from generate_series(1,10000) i);
create index t_a_b_idx on t (a, b);

Just a side note. As I mention in [1], there is missing statement
create index t_a_b_idx on t (a, b);
to get same plan as in [2].

create statistics t_a_b_stat (mcv) on a, b from t;
create statistics t_b_c_stat (mcv) on b, c from t;
vacuum analyze t;
CREATE TABLE
INSERT 0 10000
INSERT 0 10000
CREATE INDEX
CREATE STATISTICS
CREATE STATISTICS
VACUUM
alena@postgres=# explain select * from t where a = 1 and (b = 1 or b = 2) and c = 2;
QUERY PLAN
------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=156.55..465.57 rows=5001 width=12)
Recheck Cond: (a = 1)
Filter: ((c = 2) AND ((b = 1) OR (b = 2)))
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..155.29 rows=10001 width=0)
Index Cond: (a = 1)
(5 rows)

The query plan if v26[0] and v27[1] versions are equal and wrong in my opinion -where is c=2 expression?

v27 [1]
alena@postgres=# explain select * from t where a = 1 and (b = 1 or b = 2) and c = 2;
QUERY PLAN
------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=165.85..474.87 rows=5001 width=12)
Recheck Cond: ((a = 1) AND (b = ANY ('{1,2}'::integer[])))
Filter: (c = 2)
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..164.59 rows=10001 width=0)
Index Cond: ((a = 1) AND (b = ANY ('{1,2}'::integer[])))
(5 rows)
v26 [0]
alena@postgres=# explain select * from t where a = 1 and (b = 1 or b = 2) and c = 2;
QUERY PLAN
------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=165.85..449.86 rows=5001 width=12)
Recheck Cond: ((a = 1) AND (b = ANY ('{1,2}'::integer[])))
Filter: (c = 2)
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..164.59 rows=10001 width=0)
Index Cond: ((a = 1) AND (b = ANY ('{1,2}'::integer[])))
(5 rows)

I think both v26 and v27 are correct here. The c = 2 condition is in
the Filter.

In addition, I noticed that the ANY expression will be formed only for first group and ignore for others, like in the sample bellow:

v26 version [0]:

alena@postgres=# explain select * from t where (b = 1 or b = 2) and (a = 2 or a=3);
QUERY PLAN
-----------------------------------------------------------------------------------
Index Scan using t_a_b_idx on t (cost=0.29..24.75 rows=2 width=12)
Index Cond: ((a = ANY ('{2,3}'::integer[])) AND (b = ANY ('{1,2}'::integer[])))
(2 rows)

v27 version [1]:

alena@postgres=# explain select * from t where (b = 1 or b = 2 or a = 2 or a=3);
QUERY PLAN
--------------------------------------------------------
Seq Scan on t (cost=0.00..509.00 rows=14999 width=12)
Filter: ((b = 1) OR (b = 2) OR (a = 2) OR (a = 3))
(2 rows)

Did you notice you're running different queries on v26 and v27 here?
If you will run ton v27 the same query you run on v26, the plan also
will be the same.

alena@postgres=# create index a_idx on t(a);
CREATE INDEX
alena@postgres=# create index b_idx on t(b);
CREATE INDEX
alena@postgres=# analyze;
ANALYZE

v26:

alena@postgres=# explain select * from t where (b = 1 or b = 2 or a = 2 or a=3);
QUERY PLAN
------------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=17.18..30.94 rows=4 width=12)
Recheck Cond: ((a = ANY ('{2,3}'::integer[])) OR (a = ANY ('{2,3}'::integer[])))
-> BitmapOr (cost=17.18..17.18 rows=4 width=0)
-> Bitmap Index Scan on a_idx (cost=0.00..8.59 rows=2 width=0)
Index Cond: (a = ANY ('{2,3}'::integer[]))
-> Bitmap Index Scan on a_idx (cost=0.00..8.59 rows=2 width=0)
Index Cond: (a = ANY ('{2,3}'::integer[]))
(7 rows)

v27:

alena@postgres=# explain select * from t where (b = 1 or b = 2 or a = 2 or a=3);
QUERY PLAN
--------------------------------------------------------
Seq Scan on t (cost=0.00..509.00 rows=14999 width=12)
Filter: ((b = 1) OR (b = 2) OR (a = 2) OR (a = 3))
(2 rows)

The behavior in version 26 is incorrect, but in version 27, it does not select anything other than seqscan

Please, check that there is still possibility to the generate BitmapOr plan.

# explain select * from t where (b = 1 or b = 2 or a = 2 or a = 3);
QUERY PLAN
------------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=326.16..835.16 rows=14999 width=12)
Recheck Cond: ((b = 1) OR (b = 2) OR (a = 2) OR (a = 3))
-> BitmapOr (cost=326.16..326.16 rows=20000 width=0)
-> Bitmap Index Scan on t_b_c_idx (cost=0.00..151.29
rows=10000 width=0)
Index Cond: (b = 1)
-> Bitmap Index Scan on t_b_c_idx (cost=0.00..151.29
rows=10000 width=0)
Index Cond: (b = 2)
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..4.29 rows=1 width=0)
Index Cond: (a = 2)
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..4.29 rows=1 width=0)
Index Cond: (a = 3)

It has higher cost than SeqScan plan, but I think it would be selected
on larger tables. And yes, this is not ideal, because it fails to
generate BitmapOr over two IndexScans on SAOPs. But it's not worse
than what current master does. An optimization doesn't have to do
everything it could possible do. So, I think this could be improved
in a separate patch.

Links
1. /messages/by-id/CAPpHfdvhWE5pArZhgJeLViLx3-A3rxEREZvfkTj3E=h7q-Bx9w@mail.gmail.com
2. /messages/by-id/CAPpHfdtSXxhdv3mLOLjEewGeXJ+Ftfhjqodn1WWuq5JLsKx48g@mail.gmail.com

------
Regards,
Alexander Korotkov
Supabase

#212Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alexander Korotkov (#211)
Re: POC, WIP: OR-clause support for indexes

On Mon, Jul 22, 2024 at 3:52 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

Please, check that there is still possibility to the generate BitmapOr plan.

# explain select * from t where (b = 1 or b = 2 or a = 2 or a = 3);
QUERY PLAN
------------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=326.16..835.16 rows=14999 width=12)
Recheck Cond: ((b = 1) OR (b = 2) OR (a = 2) OR (a = 3))
-> BitmapOr (cost=326.16..326.16 rows=20000 width=0)
-> Bitmap Index Scan on t_b_c_idx (cost=0.00..151.29
rows=10000 width=0)
Index Cond: (b = 1)
-> Bitmap Index Scan on t_b_c_idx (cost=0.00..151.29
rows=10000 width=0)
Index Cond: (b = 2)
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..4.29 rows=1 width=0)
Index Cond: (a = 2)
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..4.29 rows=1 width=0)
Index Cond: (a = 3)

Forgot to mention that I have to
# set enable_seqscan = off;
to get this plan.

------
Regards,
Alexander Korotkov
Supabase

#213Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#211)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 22.07.2024 03:52, Alexander Korotkov wrote:

Hi, Alena!

Let me answer to some of your findings.

On Mon, Jul 22, 2024 at 12:53 AM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

To be honest,I saw a larger problem. Look at the query bellow:

master:

alena@postgres=# create table t (a int not null, b int not null, c int not null);
insert into t (select 1, 1, i from generate_series(1,10000) i);
insert into t (select i, 2, 2 from generate_series(1,10000) i);
create index t_a_b_idx on t (a, b);

Just a side note. As I mention in [1], there is missing statement
create index t_a_b_idx on t (a, b);
to get same plan as in [2].

create statistics t_a_b_stat (mcv) on a, b from t;
create statistics t_b_c_stat (mcv) on b, c from t;
vacuum analyze t;
CREATE TABLE
INSERT 0 10000
INSERT 0 10000
CREATE INDEX
CREATE STATISTICS
CREATE STATISTICS
VACUUM
alena@postgres=# explain select * from t where a = 1 and (b = 1 or b = 2) and c = 2;
QUERY PLAN
------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=156.55..465.57 rows=5001 width=12)
Recheck Cond: (a = 1)
Filter: ((c = 2) AND ((b = 1) OR (b = 2)))
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..155.29 rows=10001 width=0)
Index Cond: (a = 1)
(5 rows)

The query plan if v26[0] and v27[1] versions are equal and wrong in my opinion -where is c=2 expression?

v27 [1]
alena@postgres=# explain select * from t where a = 1 and (b = 1 or b = 2) and c = 2;
QUERY PLAN
------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=165.85..474.87 rows=5001 width=12)
Recheck Cond: ((a = 1) AND (b = ANY ('{1,2}'::integer[])))
Filter: (c = 2)
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..164.59 rows=10001 width=0)
Index Cond: ((a = 1) AND (b = ANY ('{1,2}'::integer[])))
(5 rows)
v26 [0]
alena@postgres=# explain select * from t where a = 1 and (b = 1 or b = 2) and c = 2;
QUERY PLAN
------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=165.85..449.86 rows=5001 width=12)
Recheck Cond: ((a = 1) AND (b = ANY ('{1,2}'::integer[])))
Filter: (c = 2)
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..164.59 rows=10001 width=0)
Index Cond: ((a = 1) AND (b = ANY ('{1,2}'::integer[])))
(5 rows)

I think both v26 and v27 are correct here. The c = 2 condition is in
the Filter.

Yes, I see it and agree with that.

In addition, I noticed that the ANY expression will be formed only for first group and ignore for others, like in the sample bellow:

v26 version [0]:

alena@postgres=# explain select * from t where (b = 1 or b = 2) and (a = 2 or a=3);
QUERY PLAN
-----------------------------------------------------------------------------------
Index Scan using t_a_b_idx on t (cost=0.29..24.75 rows=2 width=12)
Index Cond: ((a = ANY ('{2,3}'::integer[])) AND (b = ANY ('{1,2}'::integer[])))
(2 rows)

v27 version [1]:

alena@postgres=# explain select * from t where (b = 1 or b = 2 or a = 2 or a=3);
QUERY PLAN
--------------------------------------------------------
Seq Scan on t (cost=0.00..509.00 rows=14999 width=12)
Filter: ((b = 1) OR (b = 2) OR (a = 2) OR (a = 3))
(2 rows)

Did you notice you're running different queries on v26 and v27 here?
If you will run ton v27 the same query you run on v26, the plan also
will be the same.

alena@postgres=# create index a_idx on t(a);
CREATE INDEX
alena@postgres=# create index b_idx on t(b);
CREATE INDEX
alena@postgres=# analyze;
ANALYZE

v26:

alena@postgres=# explain select * from t where (b = 1 or b = 2 or a = 2 or a=3);
QUERY PLAN
------------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=17.18..30.94 rows=4 width=12)
Recheck Cond: ((a = ANY ('{2,3}'::integer[])) OR (a = ANY ('{2,3}'::integer[])))
-> BitmapOr (cost=17.18..17.18 rows=4 width=0)
-> Bitmap Index Scan on a_idx (cost=0.00..8.59 rows=2 width=0)
Index Cond: (a = ANY ('{2,3}'::integer[]))
-> Bitmap Index Scan on a_idx (cost=0.00..8.59 rows=2 width=0)
Index Cond: (a = ANY ('{2,3}'::integer[]))
(7 rows)

v27:

alena@postgres=# explain select * from t where (b = 1 or b = 2 or a = 2 or a=3);
QUERY PLAN
--------------------------------------------------------
Seq Scan on t (cost=0.00..509.00 rows=14999 width=12)
Filter: ((b = 1) OR (b = 2) OR (a = 2) OR (a = 3))
(2 rows)

The behavior in version 26 is incorrect, but in version 27, it does not select anything other than seqscan

Please, check that there is still possibility to the generate BitmapOr plan.

It is fine, I think. The transformation works, but due to the fact that
index columns are different for two indexes, the transformation hasn't
been applied.

# explain select * from t where (b = 1 or b = 2 or a = 2 or a = 3);
QUERY PLAN
------------------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=326.16..835.16 rows=14999 width=12)
Recheck Cond: ((b = 1) OR (b = 2) OR (a = 2) OR (a = 3))
-> BitmapOr (cost=326.16..326.16 rows=20000 width=0)
-> Bitmap Index Scan on t_b_c_idx (cost=0.00..151.29
rows=10000 width=0)
Index Cond: (b = 1)
-> Bitmap Index Scan on t_b_c_idx (cost=0.00..151.29
rows=10000 width=0)
Index Cond: (b = 2)
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..4.29 rows=1 width=0)
Index Cond: (a = 2)
-> Bitmap Index Scan on t_a_b_idx (cost=0.00..4.29 rows=1 width=0)
Index Cond: (a = 3)

It has higher cost than SeqScan plan, but I think it would be selected
on larger tables. And yes, this is not ideal, because it fails to
generate BitmapOr over two IndexScans on SAOPs. But it's not worse
than what current master does. An optimization doesn't have to do
everything it could possible do. So, I think this could be improved
in a separate patch.

Links
1./messages/by-id/CAPpHfdvhWE5pArZhgJeLViLx3-A3rxEREZvfkTj3E=h7q-Bx9w@mail.gmail.com
2./messages/by-id/CAPpHfdtSXxhdv3mLOLjEewGeXJ+Ftfhjqodn1WWuq5JLsKx48g@mail.gmail.com

Yes, I see and agree with you.

To be honest, I have found a big problem in this patch - we try to
perform the transformation every time we examime a column:

for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++) { ...

}

I have fixed it and moved the transformation before going through the loop.

I try to make an array expression for "OR" expr, but at the same time I
form the result as an "AND" expression, consisting of an "Array"
expression and "OR" expressions, and then I check whether there is an
index for this column, if so, I save it and write down the
transformation. I also had to return the previous part of the patch,
where we formed "ANY" groups, since we could end up with several such
groups. I hope I made my idea clear, but if not, please tell me.

Unfortunately, I have got the different result one of the query from
regression tests and I'm not sure if it is correct:

diff -U3 
/home/alena/postgrespro_or3/src/test/regress/expected/create_index.out 
/home/alena/postgrespro_or3/src/test/regress/results/create_index.out 
--- 
/home/alena/postgrespro_or3/src/test/regress/expected/create_index.out 
2024-07-23 18:51:13.077311360 +0300 +++ 
/home/alena/postgrespro_or3/src/test/regress/results/create_index.out 
2024-07-25 16:43:56.895132328 +0300 @@ -1860,13 +1860,14 @@ EXPLAIN 
(COSTS OFF) SELECT * FROM tenk1 WHERE thousand = 42 AND (tenthous = 1 OR 
tenthous = (SELECT 1 + 2) OR tenthous = 42); - QUERY PLAN 
----------------------------------------------------------------------------------------- 
+ QUERY PLAN 
+--------------------------------------------------------------------------------- 
Index Scan using tenk1_thous_tenthous on tenk1 - Index Cond: ((thousand 
= 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42]))) + Index 
Cond: ((thousand = 42) AND (tenthous = ANY ('{1,-1,42}'::integer[]))) + 
Filter: ((tenthous = 1) OR (tenthous = (InitPlan 1).col1) OR (tenthous = 
42)) InitPlan 1 -> Result -(4 rows) +(5 rows) SELECT * FROM tenk1 WHERE 
thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous 
= 42);

I'm researching what's wrong here now.

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

Attachments:

v28-Transform-OR-clauses-to-ANY-expression.patchtext/x-patch; charset=UTF-8; name=v28-Transform-OR-clauses-to-ANY-expression.patchDownload
From 31f58b8ad85e77534d38d099368168d9f775149f Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 25 Jul 2024 17:03:05 +0300
Subject: [PATCH] Transform OR clauses to ANY expression

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...])
during matching a clause to index.

Here Cn is a n-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 396 +++++++++++++++++++++
 src/include/nodes/pathnodes.h              |  31 ++
 src/test/regress/expected/create_index.out | 183 +++++++++-
 src/test/regress/expected/join.out         |  57 ++-
 src/test/regress/sql/create_index.sql      |  42 +++
 src/test/regress/sql/join.sql              |   9 +
 src/tools/pgindent/typedefs.list           |   1 +
 7 files changed, 697 insertions(+), 22 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..35bdf00dcb1 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,7 +32,9 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/selfuncs.h"
 
 
@@ -191,6 +193,10 @@ static Expr *match_clause_to_ordering_op(IndexOptInfo *index,
 static bool ec_member_matches_indexcol(PlannerInfo *root, RelOptInfo *rel,
 									   EquivalenceClass *ec, EquivalenceMember *em,
 									   void *arg);
+static bool
+try_prepare_single_or(RestrictInfo *rinfo, List **appropriate_group);
+static List *
+transform_or_to_any(PlannerInfo *root, RestrictInfo * rinfo);
 
 
 /*
@@ -2087,6 +2093,7 @@ match_clause_to_index(PlannerInfo *root,
 					  IndexClauseSet *clauseset)
 {
 	int			indexcol;
+	List *candidates = NIL;
 
 	/*
 	 * Never match pseudoconstants to indexes.  (Normally a match could not
@@ -2104,6 +2111,9 @@ match_clause_to_index(PlannerInfo *root,
 	if (!restriction_is_securely_promotable(rinfo, index->rel))
 		return;
 
+	if (IsA(rinfo->clause, BoolExpr) && is_orclause(rinfo->clause))
+			candidates = transform_or_to_any(root, rinfo);
+
 	/* OK, check each index key column for a match */
 	for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++)
 	{
@@ -2119,6 +2129,71 @@ match_clause_to_index(PlannerInfo *root,
 				return;
 		}
 
+		if (candidates != NIL)
+		{
+			ListCell *lc1;
+			Expr *item = NULL;
+			Node *nconst_expr = NULL;
+			Expr *expr = NULL;
+			List *result = NIL;
+			bool flag = false;
+
+			foreach(lc1, candidates)
+			{
+				item = lfirst(lc1);
+
+				if(item && IsA(item, BoolExpr))
+				{
+					if(is_andclause((Node*) item) && IsA(linitial(((BoolExpr *) item)->args), ScalarArrayOpExpr))
+					{
+
+						expr = linitial(((BoolExpr *) item)->args);
+
+						nconst_expr = get_leftop(expr);
+
+						if (match_index_to_operand(nconst_expr, indexcol, index))
+						{
+							result = lappend(result, (void *) expr);
+							flag = true;
+							continue;
+						}
+						else
+						{
+							expr = lsecond(((BoolExpr *) item)->args);
+						}
+					}
+				}
+
+				if(expr == NULL)
+					result = lappend(result, (void *)item);
+				else
+					result = lappend(result, expr);
+			}
+
+			if (flag)
+			{
+				rinfo = make_restrictinfo(root,
+									   list_length(result) > 1 ?
+											makeBoolExpr(OR_EXPR, result,
+											((BoolExpr *) rinfo->clause)->location) :
+											linitial(result),
+									   rinfo->is_pushed_down,
+									   rinfo->has_clone,
+									   rinfo->is_clone,
+								   	   rinfo->pseudoconstant,
+									   rinfo->security_level,
+									   rinfo->required_relids,
+									   rinfo->incompatible_relids,
+									   rinfo->outer_relids);
+				iclause = makeNode(IndexClause);
+				iclause->rinfo = rinfo;
+				iclause->indexquals = list_make1(iclause->rinfo);
+				iclause->lossy = false;
+				iclause->indexcol = indexcol;
+				iclause->indexcols = NIL;
+			}
+		}
+
 		/* OK, try to match the clause to the index column */
 		iclause = match_clause_to_indexcol(root,
 										   rinfo,
@@ -2771,6 +2846,327 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+static bool
+try_prepare_single_or(RestrictInfo *rinfo, List **appropriate_group)
+{
+	OpExpr	   *orqual;
+	Node	   *const_expr;
+	Node	   *nconst_expr;
+	Oid			opno;
+	Oid			consttype;
+	Node	   *leftop,
+			   *rightop;
+	ListCell   *lc2;
+	bool found = false;
+	OrClauseGroup *or_clause_group;
+
+	if (!IsA(rinfo, RestrictInfo) || !IsA(rinfo->clause, OpExpr))
+	{
+		return false;
+	}
+
+	orqual = (OpExpr *) rinfo->clause;
+	opno = orqual->opno;
+	if (get_op_rettype(opno) != BOOLOID)
+	{
+		/* Only operator returning boolean suits OR -> ANY transformation */
+		return false;
+	}
+
+	/*
+		* Detect the constant side of the clause. Recall non-constant
+		* expression can be made not only with Vars, but also with Params,
+		* which is not bonded with any relation. Thus, we detect the const
+		* side - if another side is constant too, the orqual couldn't be an
+		* OpExpr.  Get pointers to constant and expression sides of the qual.
+		*/
+	leftop = get_leftop(orqual);
+	if (IsA(leftop, RelabelType))
+		leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+	rightop = get_rightop(orqual);
+	if (IsA(rightop, RelabelType))
+		rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+	if (IsA(leftop, Const) || IsA(leftop, Param))
+	{
+		opno = get_commutator(opno);
+
+		if (!OidIsValid(opno))
+		{/* commutator doesn't exist, we can't reverse the order */
+			return false;
+		}
+
+		nconst_expr = get_rightop(orqual);
+		const_expr = get_leftop(orqual);
+	}
+	else if (IsA(rightop, Const) || IsA(rightop, Param))
+	{
+		const_expr = get_rightop(orqual);
+		nconst_expr = get_leftop(orqual);
+	}
+	else
+	{
+		return false;
+	}
+
+	/*
+		* Forbid transformation for composite types, records, and volatile
+		* expressions.
+		*/
+	consttype = exprType(const_expr);
+	if (type_is_rowtype(exprType(const_expr)) ||
+		type_is_rowtype(consttype) ||
+		contain_volatile_functions((Node *) nconst_expr))
+	{
+		return false;
+	}
+
+	or_clause_group = makeNode(OrClauseGroup);
+
+	foreach(lc2, *appropriate_group)
+	{
+
+		if (!IsA(lfirst(lc2), OrClauseGroup))
+			Assert(0);
+
+		or_clause_group = (OrClauseGroup *) lfirst(lc2);
+
+		if (or_clause_group->opno == opno &&
+			or_clause_group->consttype == consttype &&
+			or_clause_group->inputcollid == exprCollation(const_expr) &&
+			equal(or_clause_group->expr, nconst_expr))
+		{
+			found = true;
+			break;
+		}
+	}
+
+	if (!found)
+	{
+		or_clause_group->expr = (Expr *) nconst_expr;
+		or_clause_group->exprs = list_make1((void *) orqual);
+		or_clause_group->opno = opno;
+		or_clause_group->inputcollid = exprCollation(const_expr);
+		or_clause_group->consttype = consttype;
+		or_clause_group->consts = list_make1(const_expr);
+		or_clause_group->have_param = IsA(const_expr, Param);
+		Assert(list_length(or_clause_group->exprs) == list_length(or_clause_group->consts));
+		*appropriate_group = lappend(*appropriate_group, or_clause_group);
+		Assert(list_length(or_clause_group->exprs) == list_length(or_clause_group->consts));
+	}
+	else
+	{
+		or_clause_group->consts = lappend(or_clause_group->consts, const_expr);
+		or_clause_group->exprs = lappend(or_clause_group->exprs, (void *) orqual);
+		Assert(list_length(or_clause_group->exprs) == list_length(or_clause_group->consts));
+
+		Assert(list_length(or_clause_group->exprs) == list_length(or_clause_group->consts));
+	}
+
+	return true;
+}
+
+/*
+ * transform_or_to_any -
+ *	  Discover the args of an OR expression and try to group similar OR
+ *	  expressions to SAOP expressions.
+ *
+ * This transformation groups two-sided equality expression.  One side of
+ * such an expression must be a plain constant or constant expression.  The
+ * other side must be a variable expression without volatile functions.
+ * To group quals, opno, inputcollid of variable expression, and type of
+ * constant expression must be equal too.
+ *
+ * The grouping technique is based on the equivalence of variable sides of
+ * the expression: using exprId and equal() routine, it groups constant sides
+ * of similar clauses into an array.  After the grouping procedure, each
+ * couple ('variable expression' and 'constant array') forms a new SAOP
+ * operation, which is added to the args list of the returning expression.
+ */
+static List *
+transform_or_to_any(PlannerInfo *root, RestrictInfo * rinfo)
+{
+	List	   *appropriate_entries = NIL;
+	List	   *or_entries = NIL;
+	int			len_ors = ((BoolExpr *) rinfo->clause)->args ? list_length(((BoolExpr *) rinfo->clause)->args) : 0;
+	OrClauseGroup *restrict_info_entry = NULL;
+	ListCell	   *lc;
+	bool found;
+	List *result = NIL;
+
+	if(len_ors < 2)
+		return NIL;
+
+	foreach(lc, ((BoolExpr *) rinfo->orclause)->args)
+	{
+		RestrictInfo *sub_rinfo;
+		Expr		 *or_qual = (Expr *) lfirst(lc);
+
+		if(!IsA(lfirst(lc), RestrictInfo))
+			or_entries = lappend(or_entries, (void *) or_qual);
+		else
+		{
+			sub_rinfo = (RestrictInfo *) lfirst(lc);
+
+			/*
+			* Add the restrict_info_entry to the list.  It is needed exclusively to manage
+			* the problem with the order of transformed clauses in explain.
+			* Hash value can depend on the platform and version.  Hence,
+			* sequental scan of the hash table would prone to change the
+			* order of clauses in lists and, as a result, break regression
+			* tests accidentially.
+			*/
+			found = try_prepare_single_or(sub_rinfo, &appropriate_entries);
+
+			if (!found)
+			{
+				or_entries = lappend(or_entries, (void *) sub_rinfo->clause);
+			}
+		}
+	}
+
+	if (list_length(or_entries) == len_ors || (appropriate_entries == NIL && list_length(appropriate_entries) < 1))
+		return NIL;
+
+	found = false;
+
+	/* Let's convert each group of clauses to an ANY expression. */
+
+	/*
+	 * Go through the list of groups and convert each, where number of consts
+	 * more than 1. trivial groups move to OR-list again
+	 */
+
+	foreach(lc, appropriate_entries)
+	{
+		Oid			scalar_type;
+		Oid			array_type;
+		Node	   *newa = NULL;
+		HeapTuple	opertup;
+		Form_pg_operator operform;
+		ScalarArrayOpExpr *saopexpr = NULL;
+		Expr *candidate = NULL;
+		Expr *main_ors = NULL;
+
+		if (!IsA(lfirst(lc), OrClauseGroup))
+		{
+			Assert(0);
+		}
+
+		restrict_info_entry = (OrClauseGroup *) lfirst(lc);
+
+		Assert(list_length(restrict_info_entry->exprs) == list_length(restrict_info_entry->consts));
+
+		if (list_length(restrict_info_entry->consts) == 1)
+		{
+			/*
+			 * Only one element returns origin expression into the BoolExpr
+			 * args list unchanged.
+			 */
+			or_entries = list_concat(or_entries, (void *) restrict_info_entry->exprs);
+			continue;
+		}
+
+		scalar_type = restrict_info_entry->consttype;
+		array_type = OidIsValid(scalar_type) ? get_array_type(scalar_type) :
+			InvalidOid;
+
+		if (!OidIsValid(array_type))
+		{
+			or_entries = list_concat(or_entries, (void *) restrict_info_entry->exprs);
+			continue;
+		}
+
+		if (restrict_info_entry->have_param)
+		{
+			/*
+			* We need to construct an ArrayExpr given we have Param's not just
+			* Const's.
+			*/
+			ArrayExpr  *arexpr = makeNode(ArrayExpr);
+
+			/* array_collid will be set by parse_collate.c */
+			arexpr->element_typeid = scalar_type;
+			arexpr->array_typeid = array_type;
+			arexpr->multidims = false;
+			arexpr->elements = restrict_info_entry->consts;
+			arexpr->location = -1;
+
+			newa = (Node *) arexpr;
+		}
+		else
+		{
+			/* We have only Costs's.  Can generate constant array. */
+
+			int16		typlen;
+			bool		typbyval;
+			char		typalign;
+			Datum	   *elems;
+			int			i = 0;
+			ArrayType  *ar;
+			ListCell *lc1;
+
+			get_typlenbyvalalign(scalar_type, &typlen, &typbyval, &typalign);
+
+			elems = (Datum *) palloc(sizeof(Datum) * list_length(restrict_info_entry->consts));
+			foreach(lc1, restrict_info_entry->consts)
+			{
+				Node	   *elem = (Node *) lfirst(lc1);
+
+				elems[i++] = ((Const *) elem)->constvalue;
+			}
+
+			ar = construct_array(elems, i, scalar_type, typlen, typbyval, typalign);
+			newa = (Node *) makeConst(array_type, -1, restrict_info_entry->inputcollid, -1, PointerGetDatum(ar), false, false);
+
+			pfree(elems);
+		}
+
+		opertup = SearchSysCache1(OPEROID,
+								ObjectIdGetDatum(restrict_info_entry->opno));
+		if (!HeapTupleIsValid(opertup))
+			elog(ERROR, "cache lookup failed for operator %u", restrict_info_entry->opno);
+
+		operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+		/* and build the expression node */
+		saopexpr = makeNode(ScalarArrayOpExpr);
+		saopexpr->opno = restrict_info_entry->opno;
+		saopexpr->opfuncid = operform->oprcode;
+		saopexpr->hashfuncid = InvalidOid;
+		saopexpr->negfuncid = InvalidOid;
+		saopexpr->useOr = true;
+		saopexpr->inputcollid = restrict_info_entry->inputcollid;
+		/* inputcollid will be set by parse_collate.c */
+		saopexpr->args = list_make2(restrict_info_entry->expr, newa);
+		saopexpr->location = -1;
+
+		Assert(list_length(restrict_info_entry->exprs) > 1);
+
+		main_ors = makeBoolExpr(OR_EXPR, restrict_info_entry->exprs, -1);
+
+		candidate = makeBoolExpr(AND_EXPR, list_make2(saopexpr, main_ors), -1);
+		//list_free(restrict_info_entry->consts);
+		result = lappend(result,  (void *) candidate);
+		ReleaseSysCache(opertup);
+	}
+	list_free(appropriate_entries);
+
+	/* One more trick: assemble correct clause */
+	if (result == NIL)
+		return NIL;
+	else
+	{
+		if (or_entries != NIL)
+			result = lappend(result, list_length(or_entries) > 1 ?
+											makeBoolExpr(OR_EXPR, or_entries,
+											((BoolExpr *) rinfo->clause)->location) :
+											linitial(or_entries));
+		return result;
+	}
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h
index 14ccfc1ac1c..23da57b6d55 100644
--- a/src/include/nodes/pathnodes.h
+++ b/src/include/nodes/pathnodes.h
@@ -2708,6 +2708,37 @@ typedef struct RestrictInfo
 	Oid			right_hasheqoperator pg_node_attr(equal_ignore);
 } RestrictInfo;
 
+/*
+ * The group of similar operator expressions in transform_or_to_any().
+ */
+typedef struct OrClauseGroup
+{
+	pg_node_attr(nodetag_only)
+
+	NodeTag		type;
+
+	/* The expression of the variable side of operator */
+Expr	   *expr;
+	/* The operator of the operator expression */
+	Oid			opno;
+	/* The collation of the operator expression */
+	Oid			inputcollid;
+	/* The type of constant side of operator */
+	Oid			consttype;
+
+	/* The list of constant sides of operators */
+	List	   *consts;
+
+	/*
+	 * List of source expressions.  We need this for convenience in case we
+	 * will give up on transformation.
+	 */
+	List	   *exprs;
+
+	Node	   *const_expr;
+	bool have_param;
+} OrClauseGroup;
+
 /*
  * This macro embodies the correct way to test whether a RestrictInfo is
  * "pushed down" to a given outer join, that is, should be treated as a filter
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..c2b25936c8c 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,11 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,14 +1857,166 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,11 +2024,13 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 53f70d72ed6..abe98ff3c53 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..f74ad415fbf 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -726,6 +726,24 @@ DROP TABLE onek_with_null;
 -- Check bitmap index path planning
 --
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -738,6 +756,30 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index b4d7f9217ce..992c80f9350 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1717,6 +1717,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroup
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.34.1

#214Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#213)
Re: POC, WIP: OR-clause support for indexes

On Thu, Jul 25, 2024 at 5:04 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

To be honest, I have found a big problem in this patch - we try to perform the transformation every time we examime a column:

for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++) { ...

}

I have fixed it and moved the transformation before going through the loop.

What makes you think there is a problem? Do you have a test case
illustrating a slow planning time?

When v27 performs transformation for a particular column, it just
stops facing the first unmatched OR entry. So,
match_orclause_to_indexcol() examines just the first OR entry for all
the columns excepts at most one. So, the check
match_orclause_to_indexcol() does is not much slower than other
match_*_to_indexcol() do.

I actually think this could help performance in many cases, not hurt
it. At least we get rid of O(n^2) complexity over the number of OR
entries, which could be very many.

------
Regards,
Alexander Korotkov
Supabase

#215Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#214)
Re: POC, WIP: OR-clause support for indexes

On 27.07.2024 13:56, Alexander Korotkov wrote:

On Thu, Jul 25, 2024 at 5:04 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

To be honest, I have found a big problem in this patch - we try to perform the transformation every time we examime a column:

for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++) { ...

}

I have fixed it and moved the transformation before going through the loop.

What makes you think there is a problem?

To be honest, I was bothered by the fact that we need to go through
expressions several times that obviously will not fit under other
conditions.
Just yesterday I thought that it would be worthwhile to create a list of
candidates - expressions that did not fit because the column did not
match the index (!match_index_to_operand(nconst_expr, indexcol, index)).

Another problem that is related to the first one that the boolexpr could
contain expressions referring to different operands, for example, both x
and y. that is, we may have the problem that the optimal "ANY"
expression may not be used, because the expression with x may come
earlier and the loop may end earlier.

alena@postgres=# create table b (x int, y int);
CREATE TABLE
alena@postgres=# insert into b select id, id from
generate_series(1,1000) as id;
INSERT 0 1000
alena@postgres=# create index x_idx on b(x);
CREATE INDEX
alena@postgres=# analyze;
ANALYZE
alena@postgres=# explain select * from b where y =3 or x =4 or x=5 or
x=6 or x = 7 or x=8 or x=9;
                                      QUERY PLAN
---------------------------------------------------------------------------------------
 Seq Scan on b  (cost=0.00..32.50 rows=7 width=8)
   Filter: ((y = 3) OR (x = 4) OR (x = 5) OR (x = 6) OR (x = 7) OR (x =
8) OR (x = 9))
(2 rows)
alena@postgres=# explain select * from b where x =4 or x=5 or x=6 or x =
7 or x=8 or x=9 or y=1;
                                      QUERY PLAN
---------------------------------------------------------------------------------------
 Seq Scan on b  (cost=0.00..32.50 rows=7 width=8)
   Filter: ((x = 4) OR (x = 5) OR (x = 6) OR (x = 7) OR (x = 8) OR (x =
9) OR (y = 1))
(2 rows)
alena@postgres=# explain select * from b where x =4 or x=5 or x=6 or x =
7 or x=8 or x=9;
                           QUERY PLAN
----------------------------------------------------------------
 Index Scan using x_idx on b  (cost=0.28..12.75 rows=6 width=8)
   Index Cond: (x = ANY ('{4,5,6,7,8,9}'::integer[]))
(2 rows)

Furthermore expressions can be stored in a different order.
For example, first comes "AND" expr, and then group of "OR" expr, which
we can convert to "ANY" expr, but we won't do this due to the fact that
we will exit the loop early, according to this condition:

if (!IsA(sub_rinfo->clause, OpExpr))
           return NULL;

or it may occur due to other conditions.

alena@postgres=# create index x_y_idx on b(x,y);
CREATE INDEX
alena@postgres=# analyze;
ANALYZE

alena@postgres=# explain select * from b where (x = 2 and y =3) or x =4
or x=5 or x=6 or x = 7 or x=8 or x=9;
                                             QUERY PLAN
-----------------------------------------------------------------------------------------------------
 Seq Scan on b  (cost=0.00..35.00 rows=6 width=8)
   Filter: (((x = 2) AND (y = 3)) OR (x = 4) OR (x = 5) OR (x = 6) OR
(x = 7) OR (x = 8) OR (x = 9))
(2 rows)

Because of these reasons, I tried to save this and that transformation
together for each column and try to analyze for each expr separately
which method would be optimal.

Do you have a test case
illustrating a slow planning time?

No, I didn't have time to measure it and sorry for that. I'll do it.

When v27 performs transformation for a particular column, it just
stops facing the first unmatched OR entry. So,
match_orclause_to_indexcol() examines just the first OR entry for all
the columns excepts at most one. So, the check
match_orclause_to_indexcol() does is not much slower than other
match_*_to_indexcol() do.

I actually think this could help performance in many cases, not hurt
it. At least we get rid of O(n^2) complexity over the number of OR
entries, which could be very many.

I agree with you that there is an overhead and your patch fixes this
problem, but optimizer needs to have a good ordering of expressions for
application.

I think we can try to move the transformation to another place where
there is already a loop pass, and also save two options "OR" expr and
"ANY" expr in one place (through BoolExpr) (like find_duplicate_ors
function) and teach the optimizer to determine which option is better,
for example, like now in match_orclause_to_indexcol() function.

What do you thing about it?

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

#216Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#215)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Sun, Jul 28, 2024 at 12:59 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 27.07.2024 13:56, Alexander Korotkov wrote:

On Thu, Jul 25, 2024 at 5:04 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

To be honest, I have found a big problem in this patch - we try to perform the transformation every time we examime a column:

for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++) { ...

}

I have fixed it and moved the transformation before going through the loop.

What makes you think there is a problem?

To be honest, I was bothered by the fact that we need to go through
expressions several times that obviously will not fit under other
conditions.
Just yesterday I thought that it would be worthwhile to create a list of
candidates - expressions that did not fit because the column did not
match the index (!match_index_to_operand(nconst_expr, indexcol, index)).

I admit that this area probably could use some optimization,
especially for case of many clauses and many indexes. But in the
scope of this patch, I think this is enough to not make things worse
in this area.

Another problem that is related to the first one that the boolexpr could
contain expressions referring to different operands, for example, both x
and y. that is, we may have the problem that the optimal "ANY"
expression may not be used, because the expression with x may come
earlier and the loop may end earlier.

alena@postgres=# create table b (x int, y int);
CREATE TABLE
alena@postgres=# insert into b select id, id from
generate_series(1,1000) as id;
INSERT 0 1000
alena@postgres=# create index x_idx on b(x);
CREATE INDEX
alena@postgres=# analyze;
ANALYZE
alena@postgres=# explain select * from b where y =3 or x =4 or x=5 or
x=6 or x = 7 or x=8 or x=9;
QUERY PLAN
---------------------------------------------------------------------------------------
Seq Scan on b (cost=0.00..32.50 rows=7 width=8)
Filter: ((y = 3) OR (x = 4) OR (x = 5) OR (x = 6) OR (x = 7) OR (x =
8) OR (x = 9))
(2 rows)
alena@postgres=# explain select * from b where x =4 or x=5 or x=6 or x =
7 or x=8 or x=9 or y=1;
QUERY PLAN
---------------------------------------------------------------------------------------
Seq Scan on b (cost=0.00..32.50 rows=7 width=8)
Filter: ((x = 4) OR (x = 5) OR (x = 6) OR (x = 7) OR (x = 8) OR (x =
9) OR (y = 1))
(2 rows)
alena@postgres=# explain select * from b where x =4 or x=5 or x=6 or x =
7 or x=8 or x=9;
QUERY PLAN
----------------------------------------------------------------
Index Scan using x_idx on b (cost=0.28..12.75 rows=6 width=8)
Index Cond: (x = ANY ('{4,5,6,7,8,9}'::integer[]))
(2 rows)

Furthermore expressions can be stored in a different order.
For example, first comes "AND" expr, and then group of "OR" expr, which
we can convert to "ANY" expr, but we won't do this due to the fact that
we will exit the loop early, according to this condition:

if (!IsA(sub_rinfo->clause, OpExpr))
return NULL;

or it may occur due to other conditions.

alena@postgres=# create index x_y_idx on b(x,y);
CREATE INDEX
alena@postgres=# analyze;
ANALYZE

alena@postgres=# explain select * from b where (x = 2 and y =3) or x =4
or x=5 or x=6 or x = 7 or x=8 or x=9;
QUERY PLAN
-----------------------------------------------------------------------------------------------------
Seq Scan on b (cost=0.00..35.00 rows=6 width=8)
Filter: (((x = 2) AND (y = 3)) OR (x = 4) OR (x = 5) OR (x = 6) OR
(x = 7) OR (x = 8) OR (x = 9))
(2 rows)

Because of these reasons, I tried to save this and that transformation
together for each column and try to analyze for each expr separately
which method would be optimal.

Yes, with v27 of the patch, optimization wouldn't work in these cases.
However, you are using quite small table. If you will use larger
table or disable sequential scans, there would be bitmap plans to
handle these queries. So, v27 doesn't make the situation worse. It
just doesn't optimize all that it could potentially optimize and
that's OK.

I've written a separate 0002 patch to address this. Now, before
generation of paths for bitmap OR, similar OR entries are grouped
together. When considering a group of similar entries, they are
considered both together and one-by-one. Ideally we could consider
more sophisticated grouping, but that seems fine for now. You can
check how this patch handles the cases of above.

Also, 0002 address issue of duplicated bitmap scan conditions in
different forms. During generate_bitmap_or_paths() we need to exclude
considered condition for other clauses. It couldn't be as normal
filtered out in the latter stage, because could reach the index in
another form.

Do you have a test case
illustrating a slow planning time?

No, I didn't have time to measure it and sorry for that. I'll do it.

When v27 performs transformation for a particular column, it just
stops facing the first unmatched OR entry. So,
match_orclause_to_indexcol() examines just the first OR entry for all
the columns excepts at most one. So, the check
match_orclause_to_indexcol() does is not much slower than other
match_*_to_indexcol() do.

I actually think this could help performance in many cases, not hurt
it. At least we get rid of O(n^2) complexity over the number of OR
entries, which could be very many.

I agree with you that there is an overhead and your patch fixes this
problem, but optimizer needs to have a good ordering of expressions for
application.

I think we can try to move the transformation to another place where
there is already a loop pass, and also save two options "OR" expr and
"ANY" expr in one place (through BoolExpr) (like find_duplicate_ors
function) and teach the optimizer to determine which option is better,
for example, like now in match_orclause_to_indexcol() function.

What do you thing about it?

find_duplicate_ors() and similar places were already tried before.
Please, check upthread. This approach receives severe critics. AFAIU,
the problem is that find_duplicate_ors() during preprocessing, a
cost-blind stage.

This is why I'd like to continue developing ideas of v27, because it
fits the existing framework.

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v29-0002-Teach-bitmap-scan-about-transforming-OR-clauses-.patchapplication/octet-stream; name=v29-0002-Teach-bitmap-scan-about-transforming-OR-clauses-.patchDownload
From a56cb787bb302d8bc1a2f53bf1e82bc1cb37fb01 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sun, 28 Jul 2024 16:36:34 +0300
Subject: [PATCH v29 2/2] Teach bitmap scan about transforming OR clauses to
 ANY expression

Now, (expr op C1) OR (expr op C2) ... are transformet to
expr op ANY(ARRAY[C1, C2, ...]) during matching a clause to index.
This commit teaches bitmap scan planning to take advantage of this
transformation.

The similar clauses are grouped together before considering bitmap-OR.
Groups of similar clauses are matched to indexes both together and one-by-one.
---
 src/backend/optimizer/path/indxpath.c      | 266 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out |  28 +--
 src/test/regress/expected/join.out         |  56 +++--
 src/tools/pgindent/typedefs.list           |   1 +
 4 files changed, 304 insertions(+), 47 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 4fd0bbce2ce..f697b95db39 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1177,6 +1177,248 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+typedef struct
+{
+	int			indexnum;
+	int			colnum;
+	Oid			opno;
+	int			argindex;
+} OrArgIndexMatch;
+
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * Group clauses "col op const" belonging to the single index clause into
+ * dedicated ORs.
+ */
+static List *
+group_or_args(PlannerInfo *root, RelOptInfo *rel,
+			  RestrictInfo *rinfo, List *orargs)
+{
+	int			n = list_length(orargs);
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *result = NIL;
+
+	/*
+	 * Find corresponding index column for each clause in target form.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nconst_expr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+
+			nconst_expr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nconst_expr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nconst_expr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+				}
+			}
+			indexnum++;
+		}
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	pg_qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/* Group similar clauses */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].indexnum == -1))
+		{
+			if (i - group_start == 1)
+			{
+				result = lappend(result, list_nth(orargs, matches[group_start].argindex));
+			}
+			else
+			{
+				List	   *args = NIL;
+				RestrictInfo *subrinfo = makeNode(RestrictInfo);
+				int			j;
+
+				for (j = group_start; j < i; j++)
+					args = lappend(args, list_nth(orargs, matches[j].argindex));
+
+				*subrinfo = *rinfo;
+				subrinfo->clause = make_orclause(args);
+				subrinfo->orclause = subrinfo->clause;
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	return result;
+}
+
+/*
+ * Generate bitmap paths for group produced by group_or_args()
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->clause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1207,6 +1449,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *grouped;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1217,7 +1460,8 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+		grouped = group_or_args(root, rel, rinfo, ((BoolExpr *) rinfo->orclause)->args);
+		foreach(j, grouped)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1237,12 +1481,28 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				indlist = make_bitmap_paths_for_or_group(root, rel, ri, list_delete(all_clauses, rinfo));
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
@@ -2878,7 +3138,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 			if (!OidIsValid(opno))
 			{
 				/* commutator doesn't exist, we can't reverse the order */
-				return false;
+				return NULL;
 			}
 
 			nconst_expr = rightop;
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index c2b25936c8c..c6feef03810 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1982,25 +1982,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2012,22 +2011,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index abe98ff3c53..d26a93831d5 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = ANY ('{3,1}'::integer[])) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 992c80f9350..ba66983cf45 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1764,6 +1764,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.39.3 (Apple Git-145)

v29-0001-Transform-OR-clauses-to-ANY-expression.patchapplication/octet-stream; name=v29-0001-Transform-OR-clauses-to-ANY-expression.patchDownload
From f540ee7b4fc600c2aedb02b139adcf8824c0f7f1 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Thu, 11 Jul 2024 19:01:10 +0300
Subject: [PATCH v29 1/2] Transform OR clauses to ANY expression

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...])
during matching a clause to index.

Here Cn is a n-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 241 +++++++++++++++++++++
 src/test/regress/expected/create_index.out | 183 ++++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/sql/create_index.sql      |  42 ++++
 src/test/regress/sql/join.sql              |   9 +
 src/tools/pgindent/typedefs.list           |   1 +
 6 files changed, 511 insertions(+), 22 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..4fd0bbce2ce 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -19,10 +19,12 @@
 
 #include "access/stratnum.h"
 #include "access/sysattr.h"
+#include "catalog/namespace.h"
 #include "catalog/pg_am.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
+#include "nodes/bitmapset.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
 #include "nodes/supportnodes.h"
@@ -30,9 +32,14 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/pathnode.h"
 #include "optimizer/paths.h"
+#include "optimizer/planmain.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "parser/parse_oper.h"
+#include "postgres_ext.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/selfuncs.h"
 
 
@@ -177,6 +184,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2259,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2786,232 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  where it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *newa = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	if (bms_is_member(index->rel->relid, rinfo->right_relids))
+		return NULL;
+
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *sub_rinfo;
+		OpExpr	   *sub_qual;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *const_expr;
+		Node	   *nconst_expr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			return NULL;
+
+		sub_rinfo = (RestrictInfo *) lfirst(lc);
+		sub_qual = (OpExpr *) sub_rinfo->clause;
+		opno = sub_qual->opno;
+
+		if (!IsA(sub_rinfo->clause, OpExpr))
+			return NULL;
+
+		if (sub_rinfo->is_pushed_down != rinfo->is_pushed_down ||
+			sub_rinfo->is_clone != rinfo->is_clone ||
+			sub_rinfo->security_level != rinfo->security_level ||
+			!bms_equal(sub_rinfo->required_relids, rinfo->required_relids) ||
+			!bms_equal(sub_rinfo->incompatible_relids, rinfo->incompatible_relids) ||
+			!bms_equal(sub_rinfo->outer_relids, rinfo->outer_relids))
+		{
+			/* RestrictInfo parameters don't match parent, so bail out */
+			return NULL;
+		}
+
+		if (get_op_rettype(opno) != BOOLOID)
+		{
+			/* Only operator returning boolean suits OR -> ANY transformation */
+			return NULL;
+		}
+
+		/*
+		 * Detect the constant side of the clause. Recall non-constant
+		 * expression can be made not only with Vars, but also with Params,
+		 * which is not bonded with any relation. Thus, we detect the const
+		 * side - if another side is constant too, the orqual couldn't be an
+		 * OpExpr.  Get pointers to constant and expression sides of the qual.
+		 */
+
+		leftop = get_leftop(sub_qual);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(sub_qual);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				return false;
+			}
+
+			nconst_expr = rightop;
+			const_expr = leftop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			const_expr = rightop;
+			nconst_expr = leftop;
+		}
+		else
+		{
+			return NULL;
+		}
+
+		if (!match_index_to_operand(nconst_expr, indexcol, index))
+			return NULL;
+
+		/*
+		 * Forbid transformation for composite types, records.
+		 */
+		if (type_is_rowtype(exprType(nconst_expr)) ||
+			type_is_rowtype(exprType(const_expr)))
+		{
+			return NULL;
+		}
+
+		if (!OidIsValid(matchOpno))
+		{
+			matchOpno = opno;
+			indexExpr = nconst_expr;
+			consttype = exprType(const_expr);
+			arraytype = get_array_type(consttype);
+			inputcollid = sub_qual->inputcollid;
+			if (!OidIsValid(arraytype))
+				return NULL;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != sub_qual->inputcollid)
+				return NULL;
+		}
+
+		if (IsA(const_expr, Param))
+			have_param = true;
+		consts = lappend(consts, const_expr);
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arexpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arexpr->element_typeid = consttype;
+		arexpr->array_typeid = arraytype;
+		arexpr->multidims = false;
+		arexpr->elements = consts;
+		arexpr->location = -1;
+
+		newa = (Node *) arexpr;
+	}
+	else
+	{
+		/* We have only Costs's.  Can generate constant array. */
+
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *ar;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+		{
+			Node	   *elem = (Node *) lfirst(lc);
+
+			elems[i++] = ((Const *) elem)->constvalue;
+		}
+
+		ar = construct_array(elems, i, consttype, typlen, typbyval, typalign);
+		newa = (Node *) makeConst(arraytype, -1, inputcollid, -1, PointerGetDatum(ar), false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* and build the expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	/* inputcollid will be set by parse_collate.c */
+	saopexpr->args = list_make2(indexExpr, newa);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = make_restrictinfo(root,
+									   &saopexpr->xpr,
+									   rinfo->is_pushed_down,
+									   rinfo->has_clone,
+									   rinfo->is_clone,
+									   rinfo->pseudoconstant,
+									   rinfo->security_level,
+									   rinfo->required_relids,
+									   rinfo->incompatible_relids,
+									   rinfo->outer_relids);
+	iclause->indexquals = list_make1(iclause->rinfo);
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..c2b25936c8c 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,11 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,14 +1857,166 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,11 +2024,13 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 53f70d72ed6..abe98ff3c53 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..f74ad415fbf 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -726,6 +726,24 @@ DROP TABLE onek_with_null;
 -- Check bitmap index path planning
 --
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -738,6 +756,30 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index b4d7f9217ce..992c80f9350 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1717,6 +1717,7 @@ NumericVar
 OM_uint32
 OP
 OSAPerGroupState
+OrClauseGroup
 OSAPerQueryState
 OSInfo
 OSSLCipher
-- 
2.39.3 (Apple Git-145)

#217Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alexander Korotkov (#216)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Mon, Jul 29, 2024 at 5:36 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

On Sun, Jul 28, 2024 at 12:59 PM Alena Rybakina

Because of these reasons, I tried to save this and that transformation
together for each column and try to analyze for each expr separately
which method would be optimal.

Yes, with v27 of the patch, optimization wouldn't work in these cases.
However, you are using quite small table. If you will use larger
table or disable sequential scans, there would be bitmap plans to
handle these queries. So, v27 doesn't make the situation worse. It
just doesn't optimize all that it could potentially optimize and
that's OK.

I've written a separate 0002 patch to address this. Now, before
generation of paths for bitmap OR, similar OR entries are grouped
together. When considering a group of similar entries, they are
considered both together and one-by-one. Ideally we could consider
more sophisticated grouping, but that seems fine for now. You can
check how this patch handles the cases of above.

Also, 0002 address issue of duplicated bitmap scan conditions in
different forms. During generate_bitmap_or_paths() we need to exclude
considered condition for other clauses. It couldn't be as normal
filtered out in the latter stage, because could reach the index in
another form.

I agree with you that there is an overhead and your patch fixes this
problem, but optimizer needs to have a good ordering of expressions for
application.

I think we can try to move the transformation to another place where
there is already a loop pass, and also save two options "OR" expr and
"ANY" expr in one place (through BoolExpr) (like find_duplicate_ors
function) and teach the optimizer to determine which option is better,
for example, like now in match_orclause_to_indexcol() function.

What do you thing about it?

find_duplicate_ors() and similar places were already tried before.
Please, check upthread. This approach receives severe critics. AFAIU,
the problem is that find_duplicate_ors() during preprocessing, a
cost-blind stage.

This is why I'd like to continue developing ideas of v27, because it
fits the existing framework.

The revised patchset is attached. There is no material changes in the
logic, I found no issues here yet. But it comes with refactoring,
cleanup, more comments and better commit messages. I think now this
patchset is understandable and ready for review.

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v30-0002-Teach-bitmap-path-generation-about-transforming-.patchapplication/octet-stream; name=v30-0002-Teach-bitmap-path-generation-about-transforming-.patchDownload
From ce9532cdd81f236e3da65bb2a22e33dd1af6413e Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sun, 28 Jul 2024 16:36:34 +0300
Subject: [PATCH v30 2/2] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 355 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out |  28 +-
 src/test/regress/expected/join.out         |  56 ++--
 src/tools/pgindent/typedefs.list           |   1 +
 4 files changed, 394 insertions(+), 46 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 0ca51bbbb19..970cae1bc55 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1177,6 +1177,325 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index */
+	int			colnum;			/* index of the matching column */
+	Oid			opno;			/* OID of the OpClause operator */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Group similar OR arguments intro dedicated RestrictInfos.  Process
+ *		arguments of 'rinfo' clause, returns the processed list of arguments.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constantant may compise either Const
+ * or Param.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * Allocate and fill OrArgIndexMatch struct for for each clause in the
+	 * argument list.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses scan match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			return NULL;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for a index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+				}
+			}
+			indexnum++;
+		}
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	pg_qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/* Group similar clauses into */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				RestrictInfo *subrinfo = makeNode(RestrictInfo);
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+					args = lappend(args, list_nth(orargs, matches[j].argindex));
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				*subrinfo = *rinfo;
+				subrinfo->clause = make_orclause(args);
+				subrinfo->orclause = subrinfo->clause;
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitraty splits of arguments into
+ * sub-groups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->clause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1207,6 +1526,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1217,7 +1537,13 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into decicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1237,12 +1563,37 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.  In this case we need to immediately remove the
+				 * rinfo from other clauses.  This is because rinfo can be
+				 * transformed during index matching.  So, we might be unable
+				 * to remove that later.
+				 */
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 list_delete(all_clauses, rinfo));
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index c2b25936c8c..c6feef03810 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1982,25 +1982,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2012,22 +2011,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index abe98ff3c53..d26a93831d5 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = ANY ('{3,1}'::integer[])) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 75fc05093cc..06c52fbf032 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1763,6 +1763,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.39.3 (Apple Git-145)

v30-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchapplication/octet-stream; name=v30-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchDownload
From 07f2912a0a266fbf2dd0daa7b729b6584b4e3b9c Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 5 Aug 2024 21:27:02 +0300
Subject: [PATCH v30 1/2] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is a i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows to handle long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 258 +++++++++++++++++++++
 src/test/regress/expected/create_index.out | 183 +++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/sql/create_index.sql      |  42 ++++
 src/test/regress/sql/join.sql              |   9 +
 5 files changed, 527 insertions(+), 22 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..0ca51bbbb19 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -19,10 +19,12 @@
 
 #include "access/stratnum.h"
 #include "access/sysattr.h"
+#include "catalog/namespace.h"
 #include "catalog/pg_am.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
+#include "nodes/bitmapset.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
 #include "nodes/supportnodes.h"
@@ -30,9 +32,14 @@
 #include "optimizer/optimizer.h"
 #include "optimizer/pathnode.h"
 #include "optimizer/paths.h"
+#include "optimizer/planmain.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "parser/parse_oper.h"
+#include "postgres_ext.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/selfuncs.h"
 
 
@@ -177,6 +184,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2259,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2786,249 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Iterate over OR entries.  Check that each OR entry is of the form:
+	 * (indexkey operator constant) or (constant operator indexkey). Operators
+	 * of all the entries must match.  Constant might be either Const or
+	 * Param.  Exit with NULL on first non-matching entry.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			return NULL;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses scan match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			return NULL;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			return NULL;
+
+		/* RestrictInfo parameters dmust match parent */
+		if (subRinfo->is_pushed_down != rinfo->is_pushed_down ||
+			subRinfo->is_clone != rinfo->is_clone ||
+			subRinfo->security_level != rinfo->security_level ||
+			!bms_equal(subRinfo->required_relids, rinfo->required_relids) ||
+			!bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids) ||
+			!bms_equal(subRinfo->outer_relids, rinfo->outer_relids))
+			return NULL;
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			return NULL;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				return NULL;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			return NULL;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			return NULL;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			return NULL;
+
+		/*
+		 * For the first matching qual, save information about operator, type
+		 * and collation.  For the other quals just check the match with the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * There must be an array type in order to construct an array
+			 * later
+			 */
+			if (!OidIsValid(arraytype))
+				return NULL;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				return NULL;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		/*
+		 * We have only Costs's.  In this case we can contruct an array
+		 * directly.
+		 */
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Lookup for operator to fetch necessary information for the SAOP node */
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	/*
+	 * Finally build an IndexClause based on the SAOP node.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = make_restrictinfo(root,
+									   &saopexpr->xpr,
+									   rinfo->is_pushed_down,
+									   rinfo->has_clone,
+									   rinfo->is_clone,
+									   rinfo->pseudoconstant,
+									   rinfo->security_level,
+									   rinfo->required_relids,
+									   rinfo->incompatible_relids,
+									   rinfo->outer_relids);
+	iclause->indexquals = list_make1(iclause->rinfo);
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..c2b25936c8c 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,11 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,14 +1857,166 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,11 +2024,13 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 53f70d72ed6..abe98ff3c53 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..f74ad415fbf 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -726,6 +726,24 @@ DROP TABLE onek_with_null;
 -- Check bitmap index path planning
 --
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -738,6 +756,30 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
-- 
2.39.3 (Apple Git-145)

#218Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#217)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Ok, thank you for your work)

I think we can leave only the two added libraries in the first patch,
others are superfluous.

On 05.08.2024 22:48, Alexander Korotkov wrote:

On Mon, Jul 29, 2024 at 5:36 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

On Sun, Jul 28, 2024 at 12:59 PM Alena Rybakina

Because of these reasons, I tried to save this and that transformation
together for each column and try to analyze for each expr separately
which method would be optimal.

Yes, with v27 of the patch, optimization wouldn't work in these cases.
However, you are using quite small table. If you will use larger
table or disable sequential scans, there would be bitmap plans to
handle these queries. So, v27 doesn't make the situation worse. It
just doesn't optimize all that it could potentially optimize and
that's OK.

I've written a separate 0002 patch to address this. Now, before
generation of paths for bitmap OR, similar OR entries are grouped
together. When considering a group of similar entries, they are
considered both together and one-by-one. Ideally we could consider
more sophisticated grouping, but that seems fine for now. You can
check how this patch handles the cases of above.

Also, 0002 address issue of duplicated bitmap scan conditions in
different forms. During generate_bitmap_or_paths() we need to exclude
considered condition for other clauses. It couldn't be as normal
filtered out in the latter stage, because could reach the index in
another form.

I agree with you that there is an overhead and your patch fixes this
problem, but optimizer needs to have a good ordering of expressions for
application.

I think we can try to move the transformation to another place where
there is already a loop pass, and also save two options "OR" expr and
"ANY" expr in one place (through BoolExpr) (like find_duplicate_ors
function) and teach the optimizer to determine which option is better,
for example, like now in match_orclause_to_indexcol() function.

What do you thing about it?

find_duplicate_ors() and similar places were already tried before.
Please, check upthread. This approach receives severe critics. AFAIU,
the problem is that find_duplicate_ors() during preprocessing, a
cost-blind stage.

This is why I'd like to continue developing ideas of v27, because it
fits the existing framework.

The revised patchset is attached. There is no material changes in the
logic, I found no issues here yet. But it comes with refactoring,
cleanup, more comments and better commit messages. I think now this
patchset is understandable and ready for review.

------
Regards,
Alexander Korotkov
Supabase

--
Regards,
Alena Rybakina
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

v31-0001-Transform-OR-clauses-to-SAOP-s-during-index-matching.patchtext/x-patch; charset=UTF-8; name=v31-0001-Transform-OR-clauses-to-SAOP-s-during-index-matching.patchDownload
From 84e4c71dccd77810a770038be7d9104004726e1c Mon Sep 17 00:00:00 2001
From: Alena Rybakina <a.rybakina@postgrespro.ru>
Date: Mon, 5 Aug 2024 23:21:16 +0300
Subject: [PATCH 1/2] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is a i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows to handle long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 253 +++++++++++++++++++++
 src/test/regress/expected/create_index.out | 183 +++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/sql/create_index.sql      |  42 ++++
 src/test/regress/sql/join.sql              |   9 +
 5 files changed, 522 insertions(+), 22 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..cb87126e758 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,7 +32,9 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/selfuncs.h"
 
 
@@ -177,6 +179,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2254,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2781,249 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Iterate over OR entries.  Check that each OR entry is of the form:
+	 * (indexkey operator constant) or (constant operator indexkey). Operators
+	 * of all the entries must match.  Constant might be either Const or
+	 * Param.  Exit with NULL on first non-matching entry.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			return NULL;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses scan match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			return NULL;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			return NULL;
+
+		/* RestrictInfo parameters dmust match parent */
+		if (subRinfo->is_pushed_down != rinfo->is_pushed_down ||
+			subRinfo->is_clone != rinfo->is_clone ||
+			subRinfo->security_level != rinfo->security_level ||
+			!bms_equal(subRinfo->required_relids, rinfo->required_relids) ||
+			!bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids) ||
+			!bms_equal(subRinfo->outer_relids, rinfo->outer_relids))
+			return NULL;
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			return NULL;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				return NULL;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			return NULL;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			return NULL;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			return NULL;
+
+		/*
+		 * For the first matching qual, save information about operator, type
+		 * and collation.  For the other quals just check the match with the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * There must be an array type in order to construct an array
+			 * later
+			 */
+			if (!OidIsValid(arraytype))
+				return NULL;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				return NULL;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		/*
+		 * We have only Costs's.  In this case we can contruct an array
+		 * directly.
+		 */
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Lookup for operator to fetch necessary information for the SAOP node */
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	/*
+	 * Finally build an IndexClause based on the SAOP node.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = make_restrictinfo(root,
+									   &saopexpr->xpr,
+									   rinfo->is_pushed_down,
+									   rinfo->has_clone,
+									   rinfo->is_clone,
+									   rinfo->pseudoconstant,
+									   rinfo->security_level,
+									   rinfo->required_relids,
+									   rinfo->incompatible_relids,
+									   rinfo->outer_relids);
+	iclause->indexquals = list_make1(iclause->rinfo);
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..c2b25936c8c 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,11 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,14 +1857,166 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,11 +2024,13 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 53f70d72ed6..abe98ff3c53 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..f74ad415fbf 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -726,6 +726,24 @@ DROP TABLE onek_with_null;
 -- Check bitmap index path planning
 --
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -738,6 +756,30 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
-- 
2.34.1

#219Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#218)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Mon, Aug 5, 2024 at 11:24 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

Ok, thank you for your work)

I think we can leave only the two added libraries in the first patch,
others are superfluous.

Thank you.
I also have fixed some grammar issues.

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v32-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchapplication/octet-stream; name=v32-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchDownload
From 110862bbdab3b46e978aff81dcc18b45e8a851dc Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 5 Aug 2024 21:27:02 +0300
Subject: [PATCH v32 1/2] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is an i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows handling long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 253 +++++++++++++++++++++
 src/test/regress/expected/create_index.out | 183 +++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/sql/create_index.sql      |  42 ++++
 src/test/regress/sql/join.sql              |   9 +
 5 files changed, 522 insertions(+), 22 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..34dda1b6df6 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,7 +32,9 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/selfuncs.h"
 
 
@@ -177,6 +179,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2254,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2781,249 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Iterate over OR entries.  Check that each OR entry is of the form:
+	 * (indexkey operator constant) or (constant operator indexkey). Operators
+	 * of all the entries must match.  Constant might be either Const or
+	 * Param.  Exit with NULL on first non-matching entry.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			return NULL;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses scan match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			return NULL;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			return NULL;
+
+		/* RestrictInfo parameters must match parent */
+		if (subRinfo->is_pushed_down != rinfo->is_pushed_down ||
+			subRinfo->is_clone != rinfo->is_clone ||
+			subRinfo->security_level != rinfo->security_level ||
+			!bms_equal(subRinfo->required_relids, rinfo->required_relids) ||
+			!bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids) ||
+			!bms_equal(subRinfo->outer_relids, rinfo->outer_relids))
+			return NULL;
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			return NULL;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				return NULL;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			return NULL;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			return NULL;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			return NULL;
+
+		/*
+		 * For the first matching qual, save information about operator, type
+		 * and collation.  For the other quals just check the match with the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * There must be an array type in order to construct an array
+			 * later
+			 */
+			if (!OidIsValid(arraytype))
+				return NULL;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				return NULL;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		/*
+		 * We have only Const's.  In this case we can construct an array
+		 * directly.
+		 */
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Lookup for operator to fetch necessary information for the SAOP node */
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	/*
+	 * Finally build an IndexClause based on the SAOP node.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = make_restrictinfo(root,
+									   &saopexpr->xpr,
+									   rinfo->is_pushed_down,
+									   rinfo->has_clone,
+									   rinfo->is_clone,
+									   rinfo->pseudoconstant,
+									   rinfo->security_level,
+									   rinfo->required_relids,
+									   rinfo->incompatible_relids,
+									   rinfo->outer_relids);
+	iclause->indexquals = list_make1(iclause->rinfo);
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..c2b25936c8c 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,11 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,14 +1857,166 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,11 +2024,13 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 53f70d72ed6..abe98ff3c53 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..f74ad415fbf 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -726,6 +726,24 @@ DROP TABLE onek_with_null;
 -- Check bitmap index path planning
 --
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -738,6 +756,30 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
-- 
2.39.3 (Apple Git-145)

v32-0002-Teach-bitmap-path-generation-about-transforming-.patchapplication/octet-stream; name=v32-0002-Teach-bitmap-path-generation-about-transforming-.patchDownload
From adf6fb64391ad1ed8858a14c40a7bc989f0cd534 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sun, 28 Jul 2024 16:36:34 +0300
Subject: [PATCH v32 2/2] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 355 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out |  28 +-
 src/test/regress/expected/join.out         |  56 ++--
 src/tools/pgindent/typedefs.list           |   1 +
 4 files changed, 394 insertions(+), 46 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 34dda1b6df6..8e524016c6f 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1172,6 +1172,325 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index */
+	int			colnum;			/* index of the matching column */
+	Oid			opno;			/* OID of the OpClause operator */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Group similar OR-arguments intro dedicated RestrictInfos.  Process
+ *		arguments of 'rinfo' clause, returns the processed list of arguments.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constant may comprise either Const
+ * or Param.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * Allocate and fill OrArgIndexMatch struct for each clause in the
+	 * argument list.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses scan match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			return NULL;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+				}
+			}
+			indexnum++;
+		}
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	pg_qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/* Group similar clauses into */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				RestrictInfo *subrinfo = makeNode(RestrictInfo);
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+					args = lappend(args, list_nth(orargs, matches[j].argindex));
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				*subrinfo = *rinfo;
+				subrinfo->clause = make_orclause(args);
+				subrinfo->orclause = subrinfo->clause;
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->clause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1202,6 +1521,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1212,7 +1532,13 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into dedicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1232,12 +1558,37 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.  In this case we need to immediately remove the
+				 * rinfo from other clauses.  This is because rinfo can be
+				 * transformed during index matching.  So, we might be unable
+				 * to remove that later.
+				 */
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 list_delete(all_clauses, rinfo));
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index c2b25936c8c..c6feef03810 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1982,25 +1982,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2012,22 +2011,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index abe98ff3c53..d26a93831d5 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = ANY ('{3,1}'::integer[])) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 75fc05093cc..06c52fbf032 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1763,6 +1763,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.39.3 (Apple Git-145)

#220Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#219)
3 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 07.08.2024 04:11, Alexander Korotkov wrote:

On Mon, Aug 5, 2024 at 11:24 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

Ok, thank you for your work)

I think we can leave only the two added libraries in the first patch,
others are superfluous.

Thank you.
I also have fixed some grammar issues.

Thank you)

I added some tests to test the functionality of queries using strange
operator classes, type mismatches, and a small number of joins.
At the same time, I faced an assertion when a request with an unusual
operator was processed:

EXPLAIN (COSTS OFF)
SELECT COUNT(*) FROM guid1 WHERE guid_field <>
'11111111111111111111111111111111' OR
                            guid_field <>
'3f3e3c3b-3a30-3938-3736-353433a2313e';

Coredump:

#0  __pthread_kill_implementation (no_tid=0, signo=6,
threadid=138035230913472)
    at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=138035230913472) at
./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=138035230913472, signo=signo@entry=6)
at ./nptl/pthread_kill.c:89
#3  0x00007d8ad3e42476 in __GI_raise (sig=sig@entry=6) at
../sysdeps/posix/raise.c:26
#4  0x00007d8ad3e287f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x000060ceb55be02f in ExceptionalCondition
(conditionName=0x60ceb58058af "op_strategy != 0",
    fileName=0x60ceb58053e6 "selfuncs.c", lineNumber=6900) at assert.c:66
#6  0x000060ceb553ed48 in btcostestimate (root=0x60ceb6f9d2a8,
path=0x60ceb6fbd2a8, loop_count=1,
--Type <RET> for more, q to quit, c to continue without paging--
    indexStartupCost=0x7fff7ea15380, indexTotalCost=0x7fff7ea15388,
    indexSelectivity=0x7fff7ea15390, indexCorrelation=0x7fff7ea15398,
indexPages=0x7fff7ea153b0)
    at selfuncs.c:6900
#7  0x000060ceb521afca in cost_index (path=0x60ceb6fbd2a8,
root=0x60ceb6f9d2a8, loop_count=1,
    partial_path=false) at costsize.c:618
#8  0x000060ceb5290c99 in create_index_path (root=0x60ceb6f9d2a8,
index=0x60ceb6fbd5e8,
    indexclauses=0x60ceb6fbe4c8, indexorderbys=0x0,
indexorderbycols=0x0, pathkeys=0x0,
    indexscandir=ForwardScanDirection, indexonly=true,
required_outer=0x0, loop_count=1,
    partial_path=false) at pathnode.c:1024
--Type <RET> for more, q to quit, c to continue without paging--
#9  0x000060ceb522df4d in build_index_paths (root=0x60ceb6f9d2a8,
rel=0x60ceb70716c8, index=0x60ceb6fbd5e8,
    clauses=0x7fff7ea15790, useful_predicate=false,
scantype=ST_ANYSCAN, skip_nonnative_saop=0x7fff7ea15607)
    at indxpath.c:970
#10 0x000060ceb522d905 in get_index_paths (root=0x60ceb6f9d2a8,
rel=0x60ceb70716c8, index=0x60ceb6fbd5e8,
    clauses=0x7fff7ea15790, bitindexpaths=0x7fff7ea15678) at indxpath.c:729
#11 0x000060ceb522c846 in create_index_paths (root=0x60ceb6f9d2a8,
rel=0x60ceb70716c8) at indxpath.c:286
#12 0x000060ceb5212d29 in set_plain_rel_pathlist (root=0x60ceb6f9d2a8,
rel=0x60ceb70716c8, rte=0x60ceb6f63768)
    at allpaths.c:794
#13 0x000060ceb5212852 in set_rel_pathlist (root=0x60ceb6f9d2a8,
rel=0x60ceb70716c8, rti=1, rte=0x60ceb6f63768)
    at allpaths.c:499
#14 0x000060ceb521248c in set_base_rel_pathlists (root=0x60ceb6f9d2a8)
at allpaths.c:351
#15 0x000060ceb52121af in make_one_rel (root=0x60ceb6f9d2a8,
joinlist=0x60ceb6fbdea8) at allpaths.c:221
#16 0x000060ceb5257a8d in query_planner (root=0x60ceb6f9d2a8,
qp_callback=0x60ceb525e2e6 <standard_qp_callback>,
    qp_extra=0x7fff7ea15d90) at planmain.c:280
#17 0x000060ceb525a4f0 in grouping_planner (root=0x60ceb6f9d2a8,
tuple_fraction=0, setops=0x0) at planner.c:1520
#18 0x000060ceb5259b8f in subquery_planner (glob=0x60ceb70715b8,
parse=0x60ceb6f63558, parent_root=0x0,
    hasRecursion=false, tuple_fraction=0, setops=0x0) at planner.c:1089
#19 0x000060ceb52581f2 in standard_planner (parse=0x60ceb6f63558,
    query_string=0x60ceb6f62020 "EXPLAIN (COSTS OFF)\nSELECT COUNT(*)
FROM guid1 WHERE guid_field <> '", '1' <repeats 32 --Type <RET> for
more, q to quit, c to continue without paging--
times>, "' OR\n\t\t\t\t\t\t\tguid_field <>
'3f3e3c3b-3a30-3938-3736-353433a2313e';", cursorOptions=2048,
    boundParams=0x0) at planner.c:415
#20 0x000060ceb5257f1c in planner (parse=0x60ceb6f63558,
    query_string=0x60ceb6f62020 "EXPLAIN (COSTS OFF)\nSELECT COUNT(*)
FROM guid1 WHERE guid_field <> '", '1' <repeats 32 times>, "'
OR\n\t\t\t\t\t\t\tguid_field <>
'3f3e3c3b-3a30-3938-3736-353433a2313e';", cursorOptions=2048,
    boundParams=0x0) at planner.c:282
#21 0x000060ceb53b89d9 in pg_plan_query (querytree=0x60ceb6f63558,
    query_string=0x60ceb6f62020 "EXPLAIN (COSTS OFF)\nSELECT COUNT(*)
FROM guid1 WHERE guid_field <> '", '1' <repeats 32 times>, "'
OR\n\t\t\t\t\t\t\tguid_field <>
'3f3e3c3b-3a30-3938-3736-353433a2313e';", cursorOptions=2048,
    boundParams=0x0) at postgres.c:912
#22 0x000060ceb501feeb in standard_ExplainOneQuery
(query=0x60ceb6f63558, cursorOptions=2048, into=0x0,
    es=0x60ceb703acc8,
    queryString=0x60ceb6f62020 "EXPLAIN (COSTS OFF)\nSELECT COUNT(*)
FROM guid1 WHERE guid_field <> '", '1' <repeats 32 times>, "'
OR\n\t\t\t\t\t\t\tguid_field <>
'3f3e3c3b-3a30-3938-3736-353433a2313e';", params=0x0, queryEnv=0x0)
    at explain.c:491
#23 0x000060ceb501fd09 in ExplainOneQuery (query=0x60ceb6f63558,
cursorOptions=2048, into=0x0, es=0x60ceb703acc8,
    queryString=0x60ceb6f62020 "EXPLAIN (COSTS OFF)\nSELECT COUNT(*)
FROM guid1 WHERE guid_field <> '", '1' <repeats 32 times>, "'
OR\n\t\t\t\t\t\t\tguid_field <>
'3f3e3c3b-3a30-3938-3736-353433a2313e';", params=0x0, queryEnv=0x0)
    at explain.c:447
--Type <RET> for more, q to quit, c to continue without paging--
#24 0x000060ceb501f939 in ExplainQuery (pstate=0x60ceb703abb8,
stmt=0x60ceb6f63398, params=0x0, dest=0x60ceb703ab28)
    at explain.c:343
#25 0x000060ceb53c32e0 in standard_ProcessUtility (pstmt=0x60ceb6f63448,
    queryString=0x60ceb6f62020 "EXPLAIN (COSTS OFF)\nSELECT COUNT(*)
FROM guid1 WHERE guid_field <> '", '1' <repeats 32 times>, "'
OR\n\t\t\t\t\t\t\tguid_field <>
'3f3e3c3b-3a30-3938-3736-353433a2313e';", readOnlyTree=false,
    context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0,
dest=0x60ceb703ab28, qc=0x7fff7ea16530) at utility.c:863
#26 0x000060ceb53c2852 in ProcessUtility (pstmt=0x60ceb6f63448,
    queryString=0x60ceb6f62020 "EXPLAIN (COSTS OFF)\nSELECT COUNT(*)
FROM guid1 WHERE guid_field <> '", '1' <repeats 32 times>, "'
OR\n\t\t\t\t\t\t\tguid_field <>
'3f3e3c3b-3a30-3938-3736-353433a2313e';", readOnlyTree=false,
    context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0,
dest=0x60ceb703ab28, qc=0x7fff7ea16530) at utility.c:523
#27 0x000060ceb53c10cd in PortalRunUtility (portal=0x60ceb6fe6c50,
pstmt=0x60ceb6f63448, isTopLevel=true,
    setHoldSnapshot=true, dest=0x60ceb703ab28, qc=0x7fff7ea16530) at
pquery.c:1158
#28 0x000060ceb53c0e0a in FillPortalStore (portal=0x60ceb6fe6c50,
isTopLevel=true) at pquery.c:1031
#29 0x000060ceb53c06bb in PortalRun (portal=0x60ceb6fe6c50,
count=9223372036854775807, isTopLevel=true, run_once=true,
    dest=0x60ceb6f63be8, altdest=0x60ceb6f63be8, qc=0x7fff7ea16780) at
pquery.c:763
#30 0x000060ceb53b911f in exec_simple_query (
    query_string=0x60ceb6f62020 "EXPLAIN (COSTS OFF)\nSELECT COUNT(*)
FROM guid1 WHERE guid_field <> '", '1' <repeats 32 times>, "'
OR\n\t\t\t\t\t\t\tguid_field <>
'3f3e3c3b-3a30-3938-3736-353433a2313e';") at postgres.c:1284
#31 0x000060ceb53be4ef in PostgresMain (dbname=0x60ceb6fa0c00
"regression", username=0x60ceb6fa0be8 "alena")
--Type <RET> for more, q to quit, c to continue without paging--
    at postgres.c:4766
#32 0x000060ceb53b4c2a in BackendMain (startup_data=0x7fff7ea16a04 "",
startup_data_len=4) at backend_startup.c:107
#33 0x000060ceb52c9b80 in postmaster_child_launch (child_type=B_BACKEND,
startup_data=0x7fff7ea16a04 "",
    startup_data_len=4, client_sock=0x7fff7ea16a50) at launch_backend.c:274
#34 0x000060ceb52cfe87 in BackendStartup (client_sock=0x7fff7ea16a50) at
postmaster.c:3495
#35 0x000060ceb52cd0df in ServerLoop () at postmaster.c:1662
#36 0x000060ceb52cc9a6 in PostmasterMain (argc=3, argv=0x60ceb6ec6d10)
at postmaster.c:1360
#37 0x000060ceb517671c in main (argc=3, argv=0x60ceb6ec6d10) at main.c:197

I have fixed it by adding the condition that the opno of the clause must
be a member of the opfamily of the index.

tp = SearchSysCache3(AMOPOPID,
            ObjectIdGetDatum(opno),
            CharGetDatum(AMOP_SEARCH),
            ObjectIdGetDatum(index->opfamily[indexcol]));
if (!HeapTupleIsValid(tp))
return NULL;

ReleaseSysCache(tp);

I attached the diff file and new versions of patches.

--
Regards,
Alena Rybakina
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

v33-0001-Transform-OR-clauses-to-SAOP-s-during-index-matching.patchtext/x-patch; charset=UTF-8; name=v33-0001-Transform-OR-clauses-to-SAOP-s-during-index-matching.patchDownload
From 8763d61f689dc4ebca125868d5764657064fd9c7 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 5 Aug 2024 21:27:02 +0300
Subject: [PATCH 1/2] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is an i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows handling long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 253 +++++++++++++++++++++
 src/test/regress/expected/create_index.out | 183 +++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/sql/create_index.sql      |  42 ++++
 src/test/regress/sql/join.sql              |   9 +
 5 files changed, 522 insertions(+), 22 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..34dda1b6df6 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,7 +32,9 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "utils/selfuncs.h"
 
 
@@ -177,6 +179,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2254,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2781,249 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Iterate over OR entries.  Check that each OR entry is of the form:
+	 * (indexkey operator constant) or (constant operator indexkey). Operators
+	 * of all the entries must match.  Constant might be either Const or
+	 * Param.  Exit with NULL on first non-matching entry.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			return NULL;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses scan match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			return NULL;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			return NULL;
+
+		/* RestrictInfo parameters must match parent */
+		if (subRinfo->is_pushed_down != rinfo->is_pushed_down ||
+			subRinfo->is_clone != rinfo->is_clone ||
+			subRinfo->security_level != rinfo->security_level ||
+			!bms_equal(subRinfo->required_relids, rinfo->required_relids) ||
+			!bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids) ||
+			!bms_equal(subRinfo->outer_relids, rinfo->outer_relids))
+			return NULL;
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			return NULL;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				return NULL;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			return NULL;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			return NULL;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			return NULL;
+
+		/*
+		 * For the first matching qual, save information about operator, type
+		 * and collation.  For the other quals just check the match with the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * There must be an array type in order to construct an array
+			 * later
+			 */
+			if (!OidIsValid(arraytype))
+				return NULL;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				return NULL;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		/*
+		 * We have only Const's.  In this case we can construct an array
+		 * directly.
+		 */
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Lookup for operator to fetch necessary information for the SAOP node */
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	/*
+	 * Finally build an IndexClause based on the SAOP node.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = make_restrictinfo(root,
+									   &saopexpr->xpr,
+									   rinfo->is_pushed_down,
+									   rinfo->has_clone,
+									   rinfo->is_clone,
+									   rinfo->pseudoconstant,
+									   rinfo->security_level,
+									   rinfo->required_relids,
+									   rinfo->incompatible_relids,
+									   rinfo->outer_relids);
+	iclause->indexquals = list_make1(iclause->rinfo);
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..c2b25936c8c 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,11 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,14 +1857,166 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,11 +2024,13 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 53f70d72ed6..abe98ff3c53 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..f74ad415fbf 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -726,6 +726,24 @@ DROP TABLE onek_with_null;
 -- Check bitmap index path planning
 --
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -738,6 +756,30 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
-- 
2.34.1

v33-0002-Teach-bitmap-path-generation-about-transforming-OR-c.patchtext/x-patch; charset=UTF-8; name=v33-0002-Teach-bitmap-path-generation-about-transforming-OR-c.patchDownload
From 6b1e6f538bdfbeafda457fe851fff829d4ebfd26 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sun, 28 Jul 2024 16:36:34 +0300
Subject: [PATCH 2/2] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 368 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out | 121 ++++++-
 src/test/regress/expected/join.out         |  56 ++--
 src/test/regress/expected/rowsecurity.out  |   7 +
 src/test/regress/expected/stats_ext.out    |  12 +
 src/test/regress/expected/uuid.out         |  31 ++
 src/test/regress/sql/create_index.sql      |  27 ++
 src/test/regress/sql/rowsecurity.sql       |   1 +
 src/test/regress/sql/stats_ext.sql         |   3 +
 src/test/regress/sql/uuid.sql              |  12 +
 src/tools/pgindent/typedefs.list           |   1 +
 11 files changed, 592 insertions(+), 47 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 34dda1b6df6..b836af6fb55 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -1172,6 +1173,325 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index */
+	int			colnum;			/* index of the matching column */
+	Oid			opno;			/* OID of the OpClause operator */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Group similar OR-arguments intro dedicated RestrictInfos.  Process
+ *		arguments of 'rinfo' clause, returns the processed list of arguments.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constant may comprise either Const
+ * or Param.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * Allocate and fill OrArgIndexMatch struct for each clause in the
+	 * argument list.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses scan match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			return NULL;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+				}
+			}
+			indexnum++;
+		}
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	pg_qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/* Group similar clauses into */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				RestrictInfo *subrinfo = makeNode(RestrictInfo);
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+					args = lappend(args, list_nth(orargs, matches[j].argindex));
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				*subrinfo = *rinfo;
+				subrinfo->clause = make_orclause(args);
+				subrinfo->orclause = subrinfo->clause;
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->clause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1202,6 +1522,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1212,7 +1533,13 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into dedicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1232,12 +1559,37 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.  In this case we need to immediately remove the
+				 * rinfo from other clauses.  This is because rinfo can be
+				 * transformed during index matching.  So, we might be unable
+				 * to remove that later.
+				 */
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 list_delete(all_clauses, rinfo));
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
@@ -2807,6 +3159,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Oid			inputcollid = InvalidOid;
 	bool		firstTime = true;
 	bool		have_param = false;
+	HeapTuple	tp;
 
 	Assert(IsA(orclause, BoolExpr));
 	Assert(orclause->boolop == OR_EXPR);
@@ -2842,7 +3195,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		if (list_length(subClause->args) != 2)
 			return NULL;
 
-		/* RestrictInfo parameters must match parent */
+		/* RestrictInfo parameters dmust match parent */
 		if (subRinfo->is_pushed_down != rinfo->is_pushed_down ||
 			subRinfo->is_clone != rinfo->is_clone ||
 			subRinfo->security_level != rinfo->security_level ||
@@ -2883,6 +3236,15 @@ match_orclause_to_indexcol(PlannerInfo *root,
 			return NULL;
 		}
 
+		tp = SearchSysCache3(AMOPOPID,
+							ObjectIdGetDatum(opno),
+							CharGetDatum(AMOP_SEARCH),
+							ObjectIdGetDatum(index->opfamily[indexcol]));
+		if (!HeapTupleIsValid(tp))
+			return NULL;
+
+		ReleaseSysCache(tp);
+
 		/*
 		 * Ignore any RelabelType node above the operands.  This is needed to
 		 * be able to apply indexscanning in binary-compatible-operator cases.
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index c2b25936c8c..cac076abb88 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1913,6 +1913,27 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1982,25 +2003,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2012,22 +2032,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
@@ -2036,6 +2055,78 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index abe98ff3c53..d26a93831d5 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = ANY ('{3,1}'::integer[])) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 319190855bd..ef890b96cc6 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4492,6 +4492,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index f74ad415fbf..7e108f9b283 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -750,6 +750,14 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -780,6 +788,25 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 3011d71b12b..6d2414b6044 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 547d14b3e7c..f5c4b514646 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1763,6 +1763,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.34.1

diff.no-cfbottext/plain; charset=UTF-8; name=diff.no-cfbotDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 8e524016c6f..b836af6fb55 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -3158,6 +3159,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Oid			inputcollid = InvalidOid;
 	bool		firstTime = true;
 	bool		have_param = false;
+	HeapTuple	tp;
 
 	Assert(IsA(orclause, BoolExpr));
 	Assert(orclause->boolop == OR_EXPR);
@@ -3193,7 +3195,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		if (list_length(subClause->args) != 2)
 			return NULL;
 
-		/* RestrictInfo parameters must match parent */
+		/* RestrictInfo parameters dmust match parent */
 		if (subRinfo->is_pushed_down != rinfo->is_pushed_down ||
 			subRinfo->is_clone != rinfo->is_clone ||
 			subRinfo->security_level != rinfo->security_level ||
@@ -3234,6 +3236,15 @@ match_orclause_to_indexcol(PlannerInfo *root,
 			return NULL;
 		}
 
+		tp = SearchSysCache3(AMOPOPID,
+							ObjectIdGetDatum(opno),
+							CharGetDatum(AMOP_SEARCH),
+							ObjectIdGetDatum(index->opfamily[indexcol]));
+		if (!HeapTupleIsValid(tp))
+			return NULL;
+
+		ReleaseSysCache(tp);
+
 		/*
 		 * Ignore any RelabelType node above the operands.  This is needed to
 		 * be able to apply indexscanning in binary-compatible-operator cases.
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index c6feef03810..cac076abb88 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1913,6 +1913,27 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -2034,6 +2055,78 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 319190855bd..ef890b96cc6 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4492,6 +4492,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index f74ad415fbf..7e108f9b283 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -750,6 +750,14 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -780,6 +788,25 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 3011d71b12b..6d2414b6044 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
#221Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#220)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!
On 07.08.2024 04:11, Alexander Korotkov wrote:

On Mon, Aug 5, 2024 at 11:24 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

Ok, thank you for your work)

I think we can leave only the two added libraries in the first patch,
others are superfluous.

Thank you.
I also have fixed some grammar issues.

While reviewing the patch, I can't understand one part of the code where
we check the comparability of restrictinfos.

/* RestrictInfo parameters dmust match parent */
        if (subRinfo->is_pushed_down != rinfo->is_pushed_down ||
            subRinfo->is_clone != rinfo->is_clone ||
            subRinfo->security_level != rinfo->security_level ||
            !bms_equal(subRinfo->required_relids,
rinfo->required_relids) ||
            !bms_equal(subRinfo->incompatible_relids,
rinfo->incompatible_relids) ||
            !bms_equal(subRinfo->outer_relids, rinfo->outer_relids))
            return NULL;

I didn't find a place in the optimizer where required_relids,
incompatible_relids and outer_relids become different. Each
make_restrictinfo function takes arguments from
parent data.

I disabled this check and the regression tests passed. This code is
needed for security verification, may I clarify?

In the last patch I corrected the libraries - one of them was not in
alphabetical order.

--
Regards,
Alena Rybakina
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

v34-0001-Transform-OR-clauses-to-SAOP-s-during-index-matching.patchtext/x-patch; charset=UTF-8; name=v34-0001-Transform-OR-clauses-to-SAOP-s-during-index-matching.patchDownload
From 0d4e4d89f32496c692c43ec6b2d5a33b906f6697 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 5 Aug 2024 21:27:02 +0300
Subject: [PATCH 1/2] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is an i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows handling long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 253 +++++++++++++++++++++
 src/test/regress/expected/create_index.out | 183 +++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/sql/create_index.sql      |  42 ++++
 src/test/regress/sql/join.sql              |   9 +
 5 files changed, 522 insertions(+), 22 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..cbfb0fdb3c8 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -32,8 +32,10 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "utils/syscache.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -177,6 +179,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2254,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2781,249 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Iterate over OR entries.  Check that each OR entry is of the form:
+	 * (indexkey operator constant) or (constant operator indexkey). Operators
+	 * of all the entries must match.  Constant might be either Const or
+	 * Param.  Exit with NULL on first non-matching entry.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			return NULL;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses scan match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			return NULL;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			return NULL;
+
+		/* RestrictInfo parameters must match parent */
+		if (subRinfo->is_pushed_down != rinfo->is_pushed_down ||
+			subRinfo->is_clone != rinfo->is_clone ||
+			subRinfo->security_level != rinfo->security_level ||
+			!bms_equal(subRinfo->required_relids, rinfo->required_relids) ||
+			!bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids) ||
+			!bms_equal(subRinfo->outer_relids, rinfo->outer_relids))
+			return NULL;
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			return NULL;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				return NULL;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			return NULL;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			return NULL;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			return NULL;
+
+		/*
+		 * For the first matching qual, save information about operator, type
+		 * and collation.  For the other quals just check the match with the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * There must be an array type in order to construct an array
+			 * later
+			 */
+			if (!OidIsValid(arraytype))
+				return NULL;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				return NULL;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		/*
+		 * We have only Const's.  In this case we can construct an array
+		 * directly.
+		 */
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Lookup for operator to fetch necessary information for the SAOP node */
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	/*
+	 * Finally build an IndexClause based on the SAOP node.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = make_restrictinfo(root,
+									   &saopexpr->xpr,
+									   rinfo->is_pushed_down,
+									   rinfo->has_clone,
+									   rinfo->is_clone,
+									   rinfo->pseudoconstant,
+									   rinfo->security_level,
+									   rinfo->required_relids,
+									   rinfo->incompatible_relids,
+									   rinfo->outer_relids);
+	iclause->indexquals = list_make1(iclause->rinfo);
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..c2b25936c8c 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,11 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,14 +1857,166 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,11 +2024,13 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 53f70d72ed6..abe98ff3c53 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..f74ad415fbf 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -726,6 +726,24 @@ DROP TABLE onek_with_null;
 -- Check bitmap index path planning
 --
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -738,6 +756,30 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
-- 
2.34.1

v34-0002-Teach-bitmap-path-generation-about-transforming-OR-c.patchtext/x-patch; charset=UTF-8; name=v34-0002-Teach-bitmap-path-generation-about-transforming-OR-c.patchDownload
From ee464c93006f1da435d9473b2ef312206e47da0e Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sun, 28 Jul 2024 16:36:34 +0300
Subject: [PATCH 2/2] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 368 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out | 121 ++++++-
 src/test/regress/expected/join.out         |  56 ++--
 src/test/regress/expected/rowsecurity.out  |   7 +
 src/test/regress/expected/stats_ext.out    |  12 +
 src/test/regress/expected/uuid.out         |  31 ++
 src/test/regress/sql/create_index.sql      |  27 ++
 src/test/regress/sql/rowsecurity.sql       |   1 +
 src/test/regress/sql/stats_ext.sql         |   3 +
 src/test/regress/sql/uuid.sql              |  12 +
 src/tools/pgindent/typedefs.list           |   1 +
 11 files changed, 592 insertions(+), 47 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index cbfb0fdb3c8..05fac2c7ba6 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -1172,6 +1173,325 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index */
+	int			colnum;			/* index of the matching column */
+	Oid			opno;			/* OID of the OpClause operator */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Group similar OR-arguments intro dedicated RestrictInfos.  Process
+ *		arguments of 'rinfo' clause, returns the processed list of arguments.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constant may comprise either Const
+ * or Param.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * Allocate and fill OrArgIndexMatch struct for each clause in the
+	 * argument list.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses scan match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			return NULL;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+				}
+			}
+			indexnum++;
+		}
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	pg_qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/* Group similar clauses into */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				RestrictInfo *subrinfo = makeNode(RestrictInfo);
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+					args = lappend(args, list_nth(orargs, matches[j].argindex));
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				*subrinfo = *rinfo;
+				subrinfo->clause = make_orclause(args);
+				subrinfo->orclause = subrinfo->clause;
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->clause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1202,6 +1522,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1212,7 +1533,13 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into dedicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1232,12 +1559,37 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.  In this case we need to immediately remove the
+				 * rinfo from other clauses.  This is because rinfo can be
+				 * transformed during index matching.  So, we might be unable
+				 * to remove that later.
+				 */
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 list_delete(all_clauses, rinfo));
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
@@ -2807,6 +3159,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Oid			inputcollid = InvalidOid;
 	bool		firstTime = true;
 	bool		have_param = false;
+	HeapTuple	tp;
 
 	Assert(IsA(orclause, BoolExpr));
 	Assert(orclause->boolop == OR_EXPR);
@@ -2842,7 +3195,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		if (list_length(subClause->args) != 2)
 			return NULL;
 
-		/* RestrictInfo parameters must match parent */
+		/* RestrictInfo parameters dmust match parent */
 		if (subRinfo->is_pushed_down != rinfo->is_pushed_down ||
 			subRinfo->is_clone != rinfo->is_clone ||
 			subRinfo->security_level != rinfo->security_level ||
@@ -2883,6 +3236,15 @@ match_orclause_to_indexcol(PlannerInfo *root,
 			return NULL;
 		}
 
+		tp = SearchSysCache3(AMOPOPID,
+							ObjectIdGetDatum(opno),
+							CharGetDatum(AMOP_SEARCH),
+							ObjectIdGetDatum(index->opfamily[indexcol]));
+		if (!HeapTupleIsValid(tp))
+			return NULL;
+
+		ReleaseSysCache(tp);
+
 		/*
 		 * Ignore any RelabelType node above the operands.  This is needed to
 		 * be able to apply indexscanning in binary-compatible-operator cases.
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index c2b25936c8c..cac076abb88 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1913,6 +1913,27 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1982,25 +2003,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2012,22 +2032,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
@@ -2036,6 +2055,78 @@ SELECT count(*) FROM tenk1
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index abe98ff3c53..d26a93831d5 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = ANY ('{3,1}'::integer[])) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 319190855bd..ef890b96cc6 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4492,6 +4492,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index f74ad415fbf..7e108f9b283 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -750,6 +750,14 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -780,6 +788,25 @@ SELECT count(*) FROM tenk1
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 3011d71b12b..6d2414b6044 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 547d14b3e7c..f5c4b514646 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1763,6 +1763,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.34.1

#222Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#221)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!

On Thu, Aug 15, 2024 at 10:13 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 07.08.2024 04:11, Alexander Korotkov wrote:

On Mon, Aug 5, 2024 at 11:24 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

Ok, thank you for your work)

I think we can leave only the two added libraries in the first patch,
others are superfluous.

Thank you.
I also have fixed some grammar issues.

While reviewing the patch, I can't understand one part of the code where
we check the comparability of restrictinfos.

/* RestrictInfo parameters dmust match parent */
if (subRinfo->is_pushed_down != rinfo->is_pushed_down ||
subRinfo->is_clone != rinfo->is_clone ||
subRinfo->security_level != rinfo->security_level ||
!bms_equal(subRinfo->required_relids,
rinfo->required_relids) ||
!bms_equal(subRinfo->incompatible_relids,
rinfo->incompatible_relids) ||
!bms_equal(subRinfo->outer_relids, rinfo->outer_relids))
return NULL;

I didn't find a place in the optimizer where required_relids,
incompatible_relids and outer_relids become different. Each
make_restrictinfo function takes arguments from
parent data.

I disabled this check and the regression tests passed. This code is
needed for security verification, may I clarify?

Thank you for pointing this. I've rechecked the life cycle of those
parameters. make_restrictinfo() makes them initially equal (except
required_relids which might be narrower for sub-clauses). The later
changes like adjust_appendrel_attrs_mutator() applies equally for the
both parent and children.

So, I've turned this into assert check.

In the last patch I corrected the libraries - one of them was not in
alphabetical order.

Thank you!

Also, I convert the check you've introduced in the previous message to
op_in_opfamily(), and introduced collation check similar to
match_opclause_to_indexcol().

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v35-0002-Teach-bitmap-path-generation-about-transforming-.patchapplication/octet-stream; name=v35-0002-Teach-bitmap-path-generation-about-transforming-.patchDownload
From d8fe5117b9ba77858dc0c53e0b51f840562f9a03 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sun, 28 Jul 2024 16:36:34 +0300
Subject: [PATCH v35 2/2] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 355 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out |  28 +-
 src/test/regress/expected/join.out         |  56 ++--
 src/tools/pgindent/typedefs.list           |   1 +
 4 files changed, 394 insertions(+), 46 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c467048607b..73fb57b2a55 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1173,6 +1173,325 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index */
+	int			colnum;			/* index of the matching column */
+	Oid			opno;			/* OID of the OpClause operator */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Group similar OR-arguments intro dedicated RestrictInfos.  Process
+ *		arguments of 'rinfo' clause, returns the processed list of arguments.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constant may comprise either Const
+ * or Param.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * Allocate and fill OrArgIndexMatch struct for each clause in the
+	 * argument list.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses scan match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			return NULL;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+				}
+			}
+			indexnum++;
+		}
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	pg_qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/* Group similar clauses into */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				RestrictInfo *subrinfo = makeNode(RestrictInfo);
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+					args = lappend(args, list_nth(orargs, matches[j].argindex));
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				*subrinfo = *rinfo;
+				subrinfo->clause = make_orclause(args);
+				subrinfo->orclause = subrinfo->clause;
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->clause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1203,6 +1522,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1213,7 +1533,13 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into dedicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1233,12 +1559,37 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.  In this case we need to immediately remove the
+				 * rinfo from other clauses.  This is because rinfo can be
+				 * transformed during index matching.  So, we might be unable
+				 * to remove that later.
+				 */
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 list_delete(all_clauses, rinfo));
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 0c4f7d2f3d2..cac076abb88 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2003,25 +2003,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2033,22 +2032,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index abe98ff3c53..d26a93831d5 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = ANY ('{3,1}'::integer[])) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 6d424c89186..88340af3b06 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1764,6 +1764,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.39.3 (Apple Git-146)

v35-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchapplication/octet-stream; name=v35-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchDownload
From 91564ecc4e53beec6c62154b690256703c781d3a Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 5 Aug 2024 21:27:02 +0300
Subject: [PATCH v35 1/2] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is an i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows handling long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 266 ++++++++++++++++++++
 src/test/regress/expected/create_index.out | 276 +++++++++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/expected/rowsecurity.out  |   7 +
 src/test/regress/expected/stats_ext.out    |  12 +
 src/test/regress/expected/uuid.out         |  31 +++
 src/test/regress/sql/create_index.sql      |  69 ++++++
 src/test/regress/sql/join.sql              |   9 +
 src/test/regress/sql/rowsecurity.sql       |   1 +
 src/test/regress/sql/stats_ext.sql         |   3 +
 src/test/regress/sql/uuid.sql              |  12 +
 11 files changed, 721 insertions(+), 22 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..c467048607b 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -32,8 +33,10 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "utils/syscache.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -177,6 +180,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2255,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2782,261 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Iterate over OR entries.  Check that each OR entry is of the form:
+	 * (indexkey operator constant) or (constant operator indexkey). Operators
+	 * of all the entries must match.  Constant might be either Const or
+	 * Param.  Exit with NULL on first non-matching entry.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			return NULL;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses scan match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			return NULL;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			return NULL;
+
+		/*
+		 * The parameters below must match between sub-rinfo and its parent as
+		 * make_restrictinfo() fills them with the same values, and further
+		 * modifications are also the same for the whole subtree. However,
+		 * still make a sanity check.
+		 */
+		Assert(subRinfo->is_pushed_down == rinfo->is_pushed_down);
+		Assert(subRinfo->is_clone == rinfo->is_clone);
+		Assert(subRinfo->security_level == rinfo->security_level);
+		Assert(bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids));
+		Assert(bms_equal(subRinfo->outer_relids, rinfo->outer_relids));
+
+		/*
+		 * Also, check that required_relids in sub-rinfo is subset of parent's
+		 * required_relids.
+		 */
+		Assert(bms_is_subset(subRinfo->required_relids, rinfo->required_relids));
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			return NULL;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				return NULL;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			return NULL;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			return NULL;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			return NULL;
+
+		/*
+		 * For the first matching qual, save information about operator, type
+		 * and collation.  For the other quals just check the match with the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * Check operator is present in the opfamily, expression collation
+			 * matches index collation.  Also, there must be an array type in
+			 * order to construct an array later.
+			 */
+			if (!IndexCollMatchesExprColl(index->indexcollations[indexcol], inputcollid) ||
+				!op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+				!OidIsValid(arraytype))
+				return NULL;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				return NULL;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		/*
+		 * We have only Const's.  In this case we can construct an array
+		 * directly.
+		 */
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Lookup for operator to fetch necessary information for the SAOP node */
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	/*
+	 * Finally build an IndexClause based on the SAOP node.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = make_restrictinfo(root,
+									   &saopexpr->xpr,
+									   rinfo->is_pushed_down,
+									   rinfo->has_clone,
+									   rinfo->is_clone,
+									   rinfo->pseudoconstant,
+									   rinfo->security_level,
+									   rinfo->required_relids,
+									   rinfo->incompatible_relids,
+									   rinfo->outer_relids);
+	iclause->indexquals = list_make1(iclause->rinfo);
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..0c4f7d2f3d2 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,67 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1865,13 +1914,130 @@ SELECT * FROM tenk1
 (1 row)
 
 EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,16 +2045,90 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 53f70d72ed6..abe98ff3c53 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = ANY ('{3,7}'::integer[])))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 319190855bd..ef890b96cc6 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4492,6 +4492,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..7e108f9b283 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -732,12 +732,81 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 3011d71b12b..6d2414b6044 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
-- 
2.39.3 (Apple Git-146)

#223Andrei Lepikhov
a.lepikhov@postgrespro.ru
In reply to: Alexander Korotkov (#222)
Re: POC, WIP: OR-clause support for indexes

On 21/8/2024 02:17, Alexander Korotkov wrote:

Also, I convert the check you've introduced in the previous message to
op_in_opfamily(), and introduced collation check similar to
match_opclause_to_indexcol().

Hi,
I passed through the patches with fresh sight. Conceptually, this
approach looks much better than the previous series.
Just for the record: previously, we attempted to resolve two issues in
one - improve the execution plan and save cycles during the
optimisation. As I see it, it is almost impossible in this feature. So,
I should come to terms with carrying long OR lists through the planning
and the additional overhead this feature generates.
I also see that the optimiser has obtained additional planning
strategies with these patches and hasn't lost any.

Couple of findings:

First:
/* Only operator clauses scan match */
Should it be:
/* Only operator clauses can match */
?
The second one:
When creating IndexClause, we assign the original and derived clauses to
the new, containing transformed array. But logically, we should set the
clause with a list of ORs as the original. Why did you do so?

--
regards,
Andrei Lepikhov
Postgres Professional

#224Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#223)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Wed, Aug 21, 2024 at 4:08 PM Andrei Lepikhov
<a.lepikhov@postgrespro.ru> wrote:

On 21/8/2024 02:17, Alexander Korotkov wrote:

Also, I convert the check you've introduced in the previous message to
op_in_opfamily(), and introduced collation check similar to
match_opclause_to_indexcol().

Hi,
I passed through the patches with fresh sight. Conceptually, this
approach looks much better than the previous series.
Just for the record: previously, we attempted to resolve two issues in
one - improve the execution plan and save cycles during the
optimisation. As I see it, it is almost impossible in this feature. So,
I should come to terms with carrying long OR lists through the planning
and the additional overhead this feature generates.
I also see that the optimiser has obtained additional planning
strategies with these patches and hasn't lost any.

Thank you for your feedback.

Couple of findings:

First:
/* Only operator clauses scan match */
Should it be:
/* Only operator clauses can match */
?

Corrected, thanks.

The second one:
When creating IndexClause, we assign the original and derived clauses to
the new, containing transformed array. But logically, we should set the
clause with a list of ORs as the original. Why did you do so?

I actually didn't notice that. Corrected to set the OR clause as the
original. That change turned recheck to use original OR clauses,
probably better this way. Also, that change spotted misuse of
RestrictInfo.clause and RestrictInfo.orclause in the second patch.
Corrected this too.

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v36-0002-Teach-bitmap-path-generation-about-transforming-.patchapplication/octet-stream; name=v36-0002-Teach-bitmap-path-generation-about-transforming-.patchDownload
From 86d39326ad84f98c0096453173314a10a966a04a Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sun, 28 Jul 2024 16:36:34 +0300
Subject: [PATCH v36 2/2] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 364 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out |  28 +-
 src/test/regress/expected/join.out         |  56 ++--
 src/tools/pgindent/typedefs.list           |   1 +
 4 files changed, 403 insertions(+), 46 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index fb3acea7441..2e0cfa76400 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1173,6 +1173,334 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index */
+	int			colnum;			/* index of the matching column */
+	Oid			opno;			/* OID of the OpClause operator */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Group similar OR-arguments intro dedicated RestrictInfos.  Process
+ *		arguments of 'rinfo' clause, returns the processed list of arguments.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constant may comprise either Const
+ * or Param.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * Allocate and fill OrArgIndexMatch struct for each clause in the
+	 * argument list.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses scan match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			return NULL;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+				}
+			}
+			indexnum++;
+		}
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	pg_qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/* Group similar clauses into */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				List	   *rargs = NIL;
+				RestrictInfo *subrinfo = makeNode(RestrictInfo);
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+				{
+					Node	   *arg = list_nth(orargs, matches[j].argindex);
+
+					rargs = lappend(rargs, arg);
+					if (IsA(arg, RestrictInfo))
+						args = lappend(args, ((RestrictInfo *) arg)->clause);
+					else
+						args = lappend(args, arg);
+				}
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				*subrinfo = *rinfo;
+				subrinfo->clause = make_orclause(args);
+				subrinfo->orclause = make_orclause(rargs);
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->orclause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1203,6 +1531,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1213,7 +1542,13 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into dedicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1233,12 +1568,37 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.  In this case we need to immediately remove the
+				 * rinfo from other clauses.  This is because rinfo can be
+				 * transformed during index matching.  So, we might be unable
+				 * to remove that later.
+				 */
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 list_delete(all_clauses, rinfo));
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 1324d6927c4..5ccca4d83ca 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2003,25 +2003,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                        
+--------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND (((thousand = 42) OR (thousand = 99)) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2033,22 +2032,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR ((thousand = 42) OR (thousand = 41))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 078ee6014f6..cb33b3eb2c9 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR ((unique1 = 3) OR (unique1 = 1)) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 6d424c89186..88340af3b06 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1764,6 +1764,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.39.3 (Apple Git-146)

v36-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchapplication/octet-stream; name=v36-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchDownload
From b97eaa7fde1bb322f996d5c1449c4ccc82fe88aa Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 5 Aug 2024 21:27:02 +0300
Subject: [PATCH v36 1/2] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is an i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows handling long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 266 ++++++++++++++++++++
 src/test/regress/expected/create_index.out | 270 +++++++++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/expected/rowsecurity.out  |   7 +
 src/test/regress/expected/stats_ext.out    |  12 +
 src/test/regress/expected/uuid.out         |  31 +++
 src/test/regress/sql/create_index.sql      |  69 ++++++
 src/test/regress/sql/join.sql              |   9 +
 src/test/regress/sql/rowsecurity.sql       |   1 +
 src/test/regress/sql/stats_ext.sql         |   3 +
 src/test/regress/sql/uuid.sql              |  12 +
 11 files changed, 718 insertions(+), 19 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..fb3acea7441 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -32,8 +33,10 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "utils/syscache.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -177,6 +180,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2255,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2782,261 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Iterate over OR entries.  Check that each OR entry is of the form:
+	 * (indexkey operator constant) or (constant operator indexkey). Operators
+	 * of all the entries must match.  Constant might be either Const or
+	 * Param.  Exit with NULL on first non-matching entry.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			return NULL;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses can match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			return NULL;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			return NULL;
+
+		/*
+		 * The parameters below must match between sub-rinfo and its parent as
+		 * make_restrictinfo() fills them with the same values, and further
+		 * modifications are also the same for the whole subtree. However,
+		 * still make a sanity check.
+		 */
+		Assert(subRinfo->is_pushed_down == rinfo->is_pushed_down);
+		Assert(subRinfo->is_clone == rinfo->is_clone);
+		Assert(subRinfo->security_level == rinfo->security_level);
+		Assert(bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids));
+		Assert(bms_equal(subRinfo->outer_relids, rinfo->outer_relids));
+
+		/*
+		 * Also, check that required_relids in sub-rinfo is subset of parent's
+		 * required_relids.
+		 */
+		Assert(bms_is_subset(subRinfo->required_relids, rinfo->required_relids));
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			return NULL;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				return NULL;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			return NULL;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			return NULL;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			return NULL;
+
+		/*
+		 * For the first matching qual, save information about operator, type
+		 * and collation.  For the other quals just check the match with the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * Check operator is present in the opfamily, expression collation
+			 * matches index collation.  Also, there must be an array type in
+			 * order to construct an array later.
+			 */
+			if (!IndexCollMatchesExprColl(index->indexcollations[indexcol], inputcollid) ||
+				!op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+				!OidIsValid(arraytype))
+				return NULL;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				return NULL;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		/*
+		 * We have only Const's.  In this case we can construct an array
+		 * directly.
+		 */
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Lookup for operator to fetch necessary information for the SAOP node */
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	/*
+	 * Finally build an IndexClause based on the SAOP node.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = rinfo;
+	iclause->indexquals = list_make1(make_restrictinfo(root,
+													   &saopexpr->xpr,
+													   rinfo->is_pushed_down,
+													   rinfo->has_clone,
+													   rinfo->is_clone,
+													   rinfo->pseudoconstant,
+													   rinfo->security_level,
+													   rinfo->required_relids,
+													   rinfo->incompatible_relids,
+													   rinfo->outer_relids));
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..1324d6927c4 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,67 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                   QUERY PLAN                                    
+---------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,6 +1913,27 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1872,6 +1942,102 @@ SELECT count(*) FROM tenk1
  Aggregate
    ->  Bitmap Heap Scan on tenk1
          Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand < 42) OR (thousand < 99) OR (43 > thousand) OR (42 > thousand)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                             QUERY PLAN                                              
+-----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,16 +2045,90 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 53f70d72ed6..078ee6014f6 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 319190855bd..ef890b96cc6 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4492,6 +4492,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..7e108f9b283 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -732,12 +732,81 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 3011d71b12b..6d2414b6044 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
-- 
2.39.3 (Apple Git-146)

#225Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#224)
Re: POC, WIP: OR-clause support for indexes

On 21/8/2024 16:52, Alexander Korotkov wrote:

/* Only operator clauses scan match */
Should it be:
/* Only operator clauses can match */
?

Corrected, thanks.

I found one more: /* Only operator clauses scan match */ - in the
second patch.
Also I propose:
- “might match to the index as whole” -> “might match the index as a whole“
- Group similar OR-arguments intro dedicated RestrictInfos -> ‘into’

The second one:
When creating IndexClause, we assign the original and derived clauses to
the new, containing transformed array. But logically, we should set the
clause with a list of ORs as the original. Why did you do so?

I actually didn't notice that. Corrected to set the OR clause as the
original. That change turned recheck to use original OR clauses,
probably better this way. Also, that change spotted misuse of
RestrictInfo.clause and RestrictInfo.orclause in the second patch.
Corrected this too.

New findings:
=============

1)
if (list_length(clause->args) != 2)
return NULL;
I guess, above we can 'continue' the process.

2) Calling the match_index_to_operand in three nested cycles you could
break the search on first successful match, couldn't it? At least, the
comment "just stop with first matching index key" say so.

3) I finally found the limit of this feature: the case of two partial
indexes on the same column. Look at the example below:

SET enable_indexscan = 'off';
SET enable_seqscan = 'off';
DROP TABLE IF EXISTS test CASCADE;
CREATE TABLE test (x int);
INSERT INTO test (x) SELECT * FROM generate_series(1,100);
CREATE INDEX ON test (x) WHERE x < 80;
CREATE INDEX ON test (x) WHERE x > 80;
VACUUM ANALYZE test;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF)
SELECT * FROM test WHERE x=1 OR x = 79;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF)
SELECT * FROM test WHERE x=91 OR x = 81;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF)
SELECT * FROM test WHERE x=1 OR x = 81 OR x = 83;

The last query doesn't group clauses into two indexes. The reason is in
match_index_to_operand which classifies all 'x=' to one class. I'm not
sure because of overhead, but it may be resolved by using
predicate_implied_by to partial indexes.

--
regards, Andrei Lepikhov

#226Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#225)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!

Thank you for your feedback.

On Fri, Aug 23, 2024 at 1:23 PM Andrei Lepikhov <lepihov@gmail.com> wrote:

On 21/8/2024 16:52, Alexander Korotkov wrote:

/* Only operator clauses scan match */
Should it be:
/* Only operator clauses can match */
?

Corrected, thanks.

I found one more: /* Only operator clauses scan match */ - in the
second patch.
Also I propose:
- “might match to the index as whole” -> “might match the index as a whole“
- Group similar OR-arguments intro dedicated RestrictInfos -> ‘into’

Fixed.

The second one:
When creating IndexClause, we assign the original and derived clauses to
the new, containing transformed array. But logically, we should set the
clause with a list of ORs as the original. Why did you do so?

I actually didn't notice that. Corrected to set the OR clause as the
original. That change turned recheck to use original OR clauses,
probably better this way. Also, that change spotted misuse of
RestrictInfo.clause and RestrictInfo.orclause in the second patch.
Corrected this too.

New findings:
=============

1)
if (list_length(clause->args) != 2)
return NULL;
I guess, above we can 'continue' the process.

2) Calling the match_index_to_operand in three nested cycles you could
break the search on first successful match, couldn't it? At least, the
comment "just stop with first matching index key" say so.

Fixed.

3) I finally found the limit of this feature: the case of two partial
indexes on the same column. Look at the example below:

SET enable_indexscan = 'off';
SET enable_seqscan = 'off';
DROP TABLE IF EXISTS test CASCADE;
CREATE TABLE test (x int);
INSERT INTO test (x) SELECT * FROM generate_series(1,100);
CREATE INDEX ON test (x) WHERE x < 80;
CREATE INDEX ON test (x) WHERE x > 80;
VACUUM ANALYZE test;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF)
SELECT * FROM test WHERE x=1 OR x = 79;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF)
SELECT * FROM test WHERE x=91 OR x = 81;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF)
SELECT * FROM test WHERE x=1 OR x = 81 OR x = 83;

The last query doesn't group clauses into two indexes. The reason is in
match_index_to_operand which classifies all 'x=' to one class. I'm not
sure because of overhead, but it may be resolved by using
predicate_implied_by to partial indexes.

Yes, this is the conscious limitation of my patch: to consider similar
OR arguments altogether and one-by-one, not in arbitrary groups. The
important thing here is that we still generating BitmapOR patch as we
do without the patch. So, there is no regression. I would leave this
as is to not make this feature too complicated. This could be improved
in future though.

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v37-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchapplication/octet-stream; name=v37-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchDownload
From b97eaa7fde1bb322f996d5c1449c4ccc82fe88aa Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 5 Aug 2024 21:27:02 +0300
Subject: [PATCH v37 1/2] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is an i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows handling long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 266 ++++++++++++++++++++
 src/test/regress/expected/create_index.out | 270 +++++++++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/expected/rowsecurity.out  |   7 +
 src/test/regress/expected/stats_ext.out    |  12 +
 src/test/regress/expected/uuid.out         |  31 +++
 src/test/regress/sql/create_index.sql      |  69 ++++++
 src/test/regress/sql/join.sql              |   9 +
 src/test/regress/sql/rowsecurity.sql       |   1 +
 src/test/regress/sql/stats_ext.sql         |   3 +
 src/test/regress/sql/uuid.sql              |  12 +
 11 files changed, 718 insertions(+), 19 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..fb3acea7441 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -32,8 +33,10 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "utils/syscache.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -177,6 +180,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2255,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2782,261 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Iterate over OR entries.  Check that each OR entry is of the form:
+	 * (indexkey operator constant) or (constant operator indexkey). Operators
+	 * of all the entries must match.  Constant might be either Const or
+	 * Param.  Exit with NULL on first non-matching entry.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			return NULL;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses can match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			return NULL;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			return NULL;
+
+		/*
+		 * The parameters below must match between sub-rinfo and its parent as
+		 * make_restrictinfo() fills them with the same values, and further
+		 * modifications are also the same for the whole subtree. However,
+		 * still make a sanity check.
+		 */
+		Assert(subRinfo->is_pushed_down == rinfo->is_pushed_down);
+		Assert(subRinfo->is_clone == rinfo->is_clone);
+		Assert(subRinfo->security_level == rinfo->security_level);
+		Assert(bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids));
+		Assert(bms_equal(subRinfo->outer_relids, rinfo->outer_relids));
+
+		/*
+		 * Also, check that required_relids in sub-rinfo is subset of parent's
+		 * required_relids.
+		 */
+		Assert(bms_is_subset(subRinfo->required_relids, rinfo->required_relids));
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			return NULL;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				return NULL;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			return NULL;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			return NULL;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			return NULL;
+
+		/*
+		 * For the first matching qual, save information about operator, type
+		 * and collation.  For the other quals just check the match with the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * Check operator is present in the opfamily, expression collation
+			 * matches index collation.  Also, there must be an array type in
+			 * order to construct an array later.
+			 */
+			if (!IndexCollMatchesExprColl(index->indexcollations[indexcol], inputcollid) ||
+				!op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+				!OidIsValid(arraytype))
+				return NULL;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				return NULL;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		/*
+		 * We have only Const's.  In this case we can construct an array
+		 * directly.
+		 */
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Lookup for operator to fetch necessary information for the SAOP node */
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	/*
+	 * Finally build an IndexClause based on the SAOP node.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = rinfo;
+	iclause->indexquals = list_make1(make_restrictinfo(root,
+													   &saopexpr->xpr,
+													   rinfo->is_pushed_down,
+													   rinfo->has_clone,
+													   rinfo->is_clone,
+													   rinfo->pseudoconstant,
+													   rinfo->security_level,
+													   rinfo->required_relids,
+													   rinfo->incompatible_relids,
+													   rinfo->outer_relids));
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..1324d6927c4 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,67 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                   QUERY PLAN                                    
+---------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,6 +1913,27 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1872,6 +1942,102 @@ SELECT count(*) FROM tenk1
  Aggregate
    ->  Bitmap Heap Scan on tenk1
          Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand < 42) OR (thousand < 99) OR (43 > thousand) OR (42 > thousand)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                             QUERY PLAN                                              
+-----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,16 +2045,90 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 53f70d72ed6..078ee6014f6 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 319190855bd..ef890b96cc6 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4492,6 +4492,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..7e108f9b283 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -732,12 +732,81 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 3011d71b12b..6d2414b6044 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
-- 
2.39.3 (Apple Git-146)

v37-0002-Teach-bitmap-path-generation-about-transforming-.patchapplication/octet-stream; name=v37-0002-Teach-bitmap-path-generation-about-transforming-.patchDownload
From 46051b6097ef4affd8ccad99629c8e91c306bee8 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sun, 28 Jul 2024 16:36:34 +0300
Subject: [PATCH v37 2/2] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 367 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out |  28 +-
 src/test/regress/expected/join.out         |  56 ++--
 src/tools/pgindent/typedefs.list           |   1 +
 4 files changed, 406 insertions(+), 46 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index fb3acea7441..641b1d7bf8c 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1173,6 +1173,337 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index */
+	int			colnum;			/* index of the matching column */
+	Oid			opno;			/* OID of the OpClause operator */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Group similar OR-arguments into dedicated RestrictInfos.  Process
+ *		arguments of 'rinfo' clause, returns the processed list of arguments.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constant may comprise either Const
+ * or Param.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * Allocate and fill OrArgIndexMatch struct for each clause in the
+	 * argument list.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses can match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			continue;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+					break;
+				}
+				if (matches[i].indexnum >= 0)
+					break;
+			}
+			indexnum++;
+		}
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	pg_qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/* Group similar clauses into */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				List	   *rargs = NIL;
+				RestrictInfo *subrinfo = makeNode(RestrictInfo);
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+				{
+					Node	   *arg = list_nth(orargs, matches[j].argindex);
+
+					rargs = lappend(rargs, arg);
+					if (IsA(arg, RestrictInfo))
+						args = lappend(args, ((RestrictInfo *) arg)->clause);
+					else
+						args = lappend(args, arg);
+				}
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				*subrinfo = *rinfo;
+				subrinfo->clause = make_orclause(args);
+				subrinfo->orclause = make_orclause(rargs);
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->orclause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1203,6 +1534,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1213,7 +1545,13 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into dedicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as a whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1233,12 +1571,37 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.  In this case we need to immediately remove the
+				 * rinfo from other clauses.  This is because rinfo can be
+				 * transformed during index matching.  So, we might be unable
+				 * to remove that later.
+				 */
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 list_delete(all_clauses, rinfo));
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 1324d6927c4..5ccca4d83ca 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2003,25 +2003,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                        
+--------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND (((thousand = 42) OR (thousand = 99)) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2033,22 +2032,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR ((thousand = 42) OR (thousand = 41))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 078ee6014f6..cb33b3eb2c9 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR ((unique1 = 3) OR (unique1 = 1)) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 6d424c89186..88340af3b06 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1764,6 +1764,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.39.3 (Apple Git-146)

#227Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#226)
Re: POC, WIP: OR-clause support for indexes

Hi!

To be fair, I fixed this before [0]/messages/by-id/531fc0ab-371e-4235-97e3-dd2d077b6995@postgrespro.ru by selecting the appropriate group
of "or" expressions to transform them to "ANY" expression and then
checking for compatibility with the index column. maybe we should try
this too? I can think about it.

[0]: /messages/by-id/531fc0ab-371e-4235-97e3-dd2d077b6995@postgrespro.ru
/messages/by-id/531fc0ab-371e-4235-97e3-dd2d077b6995@postgrespro.ru

On 23.08.2024 15:58, Alexander Korotkov wrote:

Hi!

Thank you for your feedback.

On Fri, Aug 23, 2024 at 1:23 PM Andrei Lepikhov <lepihov@gmail.com> wrote:

On 21/8/2024 16:52, Alexander Korotkov wrote:

/* Only operator clauses scan match */
Should it be:
/* Only operator clauses can match */
?

Corrected, thanks.

I found one more: /* Only operator clauses scan match */ - in the
second patch.
Also I propose:
- “might match to the index as whole” -> “might match the index as a whole“
- Group similar OR-arguments intro dedicated RestrictInfos -> ‘into’

Fixed.

The second one:
When creating IndexClause, we assign the original and derived clauses to
the new, containing transformed array. But logically, we should set the
clause with a list of ORs as the original. Why did you do so?

I actually didn't notice that. Corrected to set the OR clause as the
original. That change turned recheck to use original OR clauses,
probably better this way. Also, that change spotted misuse of
RestrictInfo.clause and RestrictInfo.orclause in the second patch.
Corrected this too.

New findings:
=============

1)
if (list_length(clause->args) != 2)
return NULL;
I guess, above we can 'continue' the process.

2) Calling the match_index_to_operand in three nested cycles you could
break the search on first successful match, couldn't it? At least, the
comment "just stop with first matching index key" say so.

Fixed.

3) I finally found the limit of this feature: the case of two partial
indexes on the same column. Look at the example below:

SET enable_indexscan = 'off';
SET enable_seqscan = 'off';
DROP TABLE IF EXISTS test CASCADE;
CREATE TABLE test (x int);
INSERT INTO test (x) SELECT * FROM generate_series(1,100);
CREATE INDEX ON test (x) WHERE x < 80;
CREATE INDEX ON test (x) WHERE x > 80;
VACUUM ANALYZE test;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF)
SELECT * FROM test WHERE x=1 OR x = 79;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF)
SELECT * FROM test WHERE x=91 OR x = 81;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF)
SELECT * FROM test WHERE x=1 OR x = 81 OR x = 83;

The last query doesn't group clauses into two indexes. The reason is in
match_index_to_operand which classifies all 'x=' to one class. I'm not
sure because of overhead, but it may be resolved by using
predicate_implied_by to partial indexes.

Yes, this is the conscious limitation of my patch: to consider similar
OR arguments altogether and one-by-one, not in arbitrary groups. The
important thing here is that we still generating BitmapOR patch as we
do without the patch. So, there is no regression. I would leave this
as is to not make this feature too complicated. This could be improved
in future though.

------
Regards,
Alexander Korotkov
Supabase

--
Regards,
Alena Rybakina
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#228Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#227)
Re: POC, WIP: OR-clause support for indexes

Hi, Alena!

On Fri, Aug 23, 2024 at 5:06 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

To be fair, I fixed this before [0] by selecting the appropriate group
of "or" expressions to transform them to "ANY" expression and then
checking for compatibility with the index column. maybe we should try
this too? I can think about it.

[0]
/messages/by-id/531fc0ab-371e-4235-97e3-dd2d077b6995@postgrespro.ru

I probably didn't get your message. Which patch version you think
resolve the problem? I see [0] doesn't contain any patch.

I think further progress in this area of grouping OR args is possible
if there is a solution, which doesn't take extraordinary computational
complexity.

------
Regards,
Alexander Korotkov
Supabase

#229Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#228)
Re: POC, WIP: OR-clause support for indexes

On 23.08.2024 19:38, Alexander Korotkov wrote:

Hi, Alena!

On Fri, Aug 23, 2024 at 5:06 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

To be fair, I fixed this before [0] by selecting the appropriate group
of "or" expressions to transform them to "ANY" expression and then
checking for compatibility with the index column. maybe we should try
this too? I can think about it.

[0]
/messages/by-id/531fc0ab-371e-4235-97e3-dd2d077b6995@postgrespro.ru

I probably didn't get your message. Which patch version you think
resolve the problem? I see [0] doesn't contain any patch.

Sorry, I got the links mixed up. We need this link [0].

I think further progress in this area of grouping OR args is possible
if there is a solution, which doesn't take extraordinary computational
complexity.

This approach does not require a large overhead - in fact, we separately
did the conversion to "any" once going through the list of restrictinfo,
we form candidates in the form of boolexpr using the "and" operator,
which contains "any" and "or" expression, then we check with index
columns which expression suits us.

--
Regards,
Alena Rybakina
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#230Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#229)
Re: POC, WIP: OR-clause support for indexes

On Sat, Aug 24, 2024 at 4:08 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 23.08.2024 19:38, Alexander Korotkov wrote:

Hi, Alena!

On Fri, Aug 23, 2024 at 5:06 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

To be fair, I fixed this before [0] by selecting the appropriate group
of "or" expressions to transform them to "ANY" expression and then
checking for compatibility with the index column. maybe we should try
this too? I can think about it.

[0]
/messages/by-id/531fc0ab-371e-4235-97e3-dd2d077b6995@postgrespro.ru

I probably didn't get your message. Which patch version you think
resolve the problem? I see [0] doesn't contain any patch.

Sorry, I got the links mixed up. We need this link [0].

Still confusion.
If that's another [0] from [0] in the cited message then it seems you
missed new link in your last message.

------
Regards,
Alexander Korotkov
Supabase

#231Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#230)
Re: POC, WIP: OR-clause support for indexes

Sorry again.

The link to letter - -
/messages/by-id/759292d5-cb51-4b12-89fa-576c1d9b374d@postgrespro.ru

Patch -
/messages/by-id/attachment/162897/v28-Transform-OR-clauses-to-ANY-expression.patch

On 24.08.2024 16:23, Alexander Korotkov wrote:

On Sat, Aug 24, 2024 at 4:08 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 23.08.2024 19:38, Alexander Korotkov wrote:

Hi, Alena!

On Fri, Aug 23, 2024 at 5:06 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

To be fair, I fixed this before [0] by selecting the appropriate group
of "or" expressions to transform them to "ANY" expression and then
checking for compatibility with the index column. maybe we should try
this too? I can think about it.

[0]
/messages/by-id/531fc0ab-371e-4235-97e3-dd2d077b6995@postgrespro.ru

I probably didn't get your message. Which patch version you think
resolve the problem? I see [0] doesn't contain any patch.

Sorry, I got the links mixed up. We need this link [0].

Still confusion.
If that's another [0] from [0] in the cited message then it seems you
missed new link in your last message.

------
Regards,
Alexander Korotkov
Supabase

--
Regards,
Alena Rybakina
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#232Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#226)
Re: POC, WIP: OR-clause support for indexes

On 23/8/2024 14:58, Alexander Korotkov wrote:

On Fri, Aug 23, 2024 at 1:23 PM Andrei Lepikhov <lepihov@gmail.com> wrote:

The last query doesn't group clauses into two indexes. The reason is in
match_index_to_operand which classifies all 'x=' to one class. I'm not
sure because of overhead, but it may be resolved by using
predicate_implied_by to partial indexes.

Yes, this is the conscious limitation of my patch: to consider similar
OR arguments altogether and one-by-one, not in arbitrary groups. The
important thing here is that we still generating BitmapOR patch as we
do without the patch. So, there is no regression. I would leave this
as is to not make this feature too complicated. This could be improved
in future though.

It looks reasonable for me, thanks for the explanation.

What's more, I suspicious about the line:
*subrinfo = *rinfo;

Here, you copy everything, including cached estimations like norm_selec
or eval_cost. I see that the match_orclause_to_indexcol creates a new
SAOP where all caches will be cleaned, but just to be sure, maybe we
should reset any cached estimations to default values — in that case,
anyone who tries to build a new path based on these grouped OR clauses
will recalculate that data.
At least, incorrect eval_cost of iclause->rinfo can slightly change the
cost of rechecking operation, can't it?

--
regards, Andrei Lepikhov

#233jian he
jian.universality@gmail.com
In reply to: Alexander Korotkov (#226)
Re: POC, WIP: OR-clause support for indexes

On Fri, Aug 23, 2024 at 8:58 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

based on v37.

+ {
+ /*
+ * We have only Const's.  In this case we can construct an array
+ * directly.
+ */
+ int16 typlen;
+ bool typbyval;
+ char typalign;
+ Datum   *elems;
+ int i = 0;
+ ArrayType  *arrayConst;
+
+ get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+ elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+ foreach(lc, consts)
+ elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+ arrayConst = construct_array(elems, i, consttype,
+ typlen, typbyval, typalign);
+ arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+   -1, PointerGetDatum(arrayConst),
+   false, false);
+
+ pfree(elems);
+ list_free(consts);
+ }
List "consts" elements can be NULL?
I didn't find a query to trigger that.
but construct_array comments says
"elems (NULL element values are not supported)."
Do we need to check Const->constisnull for the Const node?
+ /* Construct the list of nested OR arguments */
+ for (j = group_start; j < i; j++)
+ {
+ Node   *arg = list_nth(orargs, matches[j].argindex);
+
+ rargs = lappend(rargs, arg);
+ if (IsA(arg, RestrictInfo))
+ args = lappend(args, ((RestrictInfo *) arg)->clause);
+ else
+ args = lappend(args, arg);
+ }
the ELSE branch never reached?
+ /* Construct the nested OR and wrap it with RestrictInfo */
+ *subrinfo = *rinfo;
+ subrinfo->clause = make_orclause(args);
+ subrinfo->orclause = make_orclause(rargs);
+ result = lappend(result, subrinfo);
should we use memcpy instead of " *subrinfo = *rinfo;"?
+ /* Sort clauses to make similar clauses go together */
+ pg_qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
Should we use qsort?
since comments in pg_qsort:
/*
 * Callers should use the qsort() macro defined below instead of calling
 * pg_qsort() directly.
 */
+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+ int indexnum; /* index of the matching index */
+ int colnum; /* index of the matching column */
+ Oid opno; /* OID of the OpClause operator */
+ Oid inputcollid; /* OID of the OpClause input collation */
+ int argindex; /* index of the clause in the list of
+ * arguments */
+} OrArgIndexMatch;

I am not 100% sure about the comments.
indexnum: index of the matching index reside in rel->indexlist that
matches (counting from 0)
colnum: the column number of the matched index (counting from 0)

#234Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: jian he (#233)
3 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 26.08.2024 06:12, jian he wrote:

On Fri, Aug 23, 2024 at 8:58 PM Alexander Korotkov<aekorotkov@gmail.com> wrote:
based on v37.

+ {
+ /*
+ * We have only Const's.  In this case we can construct an array
+ * directly.
+ */
+ int16 typlen;
+ bool typbyval;
+ char typalign;
+ Datum   *elems;
+ int i = 0;
+ ArrayType  *arrayConst;
+
+ get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+ elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+ foreach(lc, consts)
+ elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+ arrayConst = construct_array(elems, i, consttype,
+ typlen, typbyval, typalign);
+ arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+   -1, PointerGetDatum(arrayConst),
+   false, false);
+
+ pfree(elems);
+ list_free(consts);
+ }
List "consts" elements can be NULL?
I didn't find a query to trigger that.
but construct_array comments says
"elems (NULL element values are not supported)."
Do we need to check Const->constisnull for the Const node?

I didn't find any problems here either, but the query plan seems strange
to me: a form of OR expressions is added to the recheck condition. But
we discussed this before and came to the conclusion that this is not a
mistake.

I added the query to the create_index.sql

  EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 
42 or tenthous is null);
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND (tenthous IS NULL)) OR 
((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42))))
+   Filter: ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42) OR 
(tenthous IS NULL))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous IS NULL))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY 
('{1,3,42}'::integer[])))
+(8 rows)

I noticed that the NULL element is not added to the converted array
because it belongs to a different group.

So, I think this problem may not be affect us. Gere we should add
Assertion that an element is not null.

+ /* Construct the list of nested OR arguments */
+ for (j = group_start; j < i; j++)
+ {
+ Node   *arg = list_nth(orargs, matches[j].argindex);
+
+ rargs = lappend(rargs, arg);
+ if (IsA(arg, RestrictInfo))
+ args = lappend(args, ((RestrictInfo *) arg)->clause);
+ else
+ args = lappend(args, arg);
+ }
the ELSE branch never reached?

Reached - if your arg is BoolExpr type, for example if it consists "And"
expressions.

+ /* Construct the nested OR and wrap it with RestrictInfo */
+ *subrinfo = *rinfo;
+ subrinfo->clause = make_orclause(args);
+ subrinfo->orclause = make_orclause(rargs);
+ result = lappend(result, subrinfo);
should we use memcpy instead of " *subrinfo = *rinfo;"?
+ /* Sort clauses to make similar clauses go together */
+ pg_qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
Should we use qsort?
since comments in pg_qsort:
/*
* Callers should use the qsort() macro defined below instead of calling
* pg_qsort() directly.
*/

I think yes, we should.

+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+ int indexnum; /* index of the matching index */
+ int colnum; /* index of the matching column */
+ Oid opno; /* OID of the OpClause operator */
+ Oid inputcollid; /* OID of the OpClause input collation */
+ int argindex; /* index of the clause in the list of
+ * arguments */
+} OrArgIndexMatch;

I am not 100% sure about the comments.
indexnum: index of the matching index reside in rel->indexlist that
matches (counting from 0)
colnum: the column number of the matched index (counting from 0)

To be honest, I'm not sure that I completely understand your point here.

I have found an interesting case here:

+EXPLAIN (COSTS OFF) +SELECT * FROM tenk1 + WHERE thousand = 42 AND 
(stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA'::text OR stringu1 = 
'OBAAAA'::text); + QUERY PLAN 
+------------------------------------------------------------------------------------------------------------------------------------- 
+ Bitmap Heap Scan on tenk1 + Recheck Cond: ((thousand = 42) AND 
((stringu1 = 'MAAAAA'::name) OR ((stringu1 = 'TUAAAA'::text) OR 
(stringu1 = 'OBAAAA'::text)))) + Filter: ((stringu1 = 'MAAAAA'::name) OR 
(stringu1 = 'TUAAAA'::text) OR (stringu1 = 'OBAAAA'::text)) + -> 
BitmapAnd + -> Bitmap Index Scan on tenk1_thous_tenthous + Index Cond: 
(thousand = 42) + -> BitmapOr + -> Bitmap Index Scan on stringu1_idx + 
Index Cond: (stringu1 = 'MAAAAA'::name) + -> Bitmap Index Scan on 
stringu1_idx + Index Cond: (stringu1 = ANY ('{TUAAAA,OBAAAA}'::text[] 
COLLATE "C")) +(11 rows) +

If OR constants have different types, then they belong to different
groups, and I think that's unfair. I think that conversion to a single
type should be used here - while I’m working on this, I’ll send the code
in the next letter.

And I noticed that there were some tests missing on this, so I added this.

I've updated the patch file to include my and Jian's suggestions, as
well as the diff file if there's no objection.

--
Regards,
Alena Rybakina
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

Attachments:

diff.diff.no-cfbottext/plain; charset=UTF-8; name=diff.diff.no-cfbotDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 641b1d7bf8c..cde635d9cb6 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1366,7 +1366,7 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 	}
 
 	/* Sort clauses to make similar clauses go together */
-	pg_qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+	qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
 
 	/* Group similar clauses into */
 	group_start = 0;
@@ -3346,7 +3346,13 @@ match_orclause_to_indexcol(PlannerInfo *root,
 
 		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
 		foreach(lc, consts)
-			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+		{
+			Const *value = (Const *) lfirst(lc);
+
+			Assert(!value->constisnull && value->constvalue);
+
+			elems[i++] = value->constvalue;
+		}
 
 		arrayConst = construct_array(elems, i, consttype,
 									 typlen, typbyval, typalign);
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 5ccca4d83ca..5623f4b3123 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1875,6 +1875,67 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 or tenthous is null);
+                                                                QUERY PLAN                                                                 
+-------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND (tenthous IS NULL)) OR ((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42))))
+   Filter: ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42) OR (tenthous IS NULL))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous IS NULL))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(8 rows)
+
+create index stringu1_idx on tenk1 (stringu1);
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (stringu1::text = 'MAAAAA' OR stringu1::text = 'TUAAAA'::name OR stringu1 = 'OBAAAA'::name);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((stringu1)::text = 'MAAAAA'::text) OR ((stringu1)::text = 'TUAAAA'::name) OR (stringu1 = 'OBAAAA'::name))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA' OR stringu1 = 'OBAAAA');
+                                                            QUERY PLAN                                                             
+-----------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: ((thousand = 42) AND ((stringu1 = 'MAAAAA'::name) OR (stringu1 = 'TUAAAA'::name) OR (stringu1 = 'OBAAAA'::name)))
+   ->  BitmapAnd
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: (thousand = 42)
+         ->  Bitmap Index Scan on stringu1_idx
+               Index Cond: (stringu1 = ANY ('{MAAAAA,TUAAAA,OBAAAA}'::name[]))
+(7 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA'::text OR stringu1 = 'OBAAAA'::text);
+                                                             QUERY PLAN                                                              
+-------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: ((thousand = 42) AND ((stringu1 = 'MAAAAA'::name) OR ((stringu1 = 'TUAAAA'::text) OR (stringu1 = 'OBAAAA'::text))))
+   Filter: ((stringu1 = 'MAAAAA'::name) OR (stringu1 = 'TUAAAA'::text) OR (stringu1 = 'OBAAAA'::text))
+   ->  BitmapAnd
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: (thousand = 42)
+         ->  BitmapOr
+               ->  Bitmap Index Scan on stringu1_idx
+                     Index Cond: (stringu1 = 'MAAAAA'::name)
+               ->  Bitmap Index Scan on stringu1_idx
+                     Index Cond: (stringu1 = ANY ('{TUAAAA,OBAAAA}'::text[] COLLATE "C"))
+(11 rows)
+
+Drop index stringu1_idx;
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 7e108f9b283..37538ab6bba 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -738,6 +738,23 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 or tenthous is null);
+
+create index stringu1_idx on tenk1 (stringu1);
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (stringu1::text = 'MAAAAA' OR stringu1::text = 'TUAAAA'::name OR stringu1 = 'OBAAAA'::name);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA' OR stringu1 = 'OBAAAA');
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA'::text OR stringu1 = 'OBAAAA'::text);
+Drop index stringu1_idx;
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
v38-0001-Transform-OR-clauses-to-SAOP-s-during-index-matching.patchtext/x-patch; charset=UTF-8; name=v38-0001-Transform-OR-clauses-to-SAOP-s-during-index-matching.patchDownload
From 25c59961afd18bcfd6d5e3107d859af491d6b99d Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 5 Aug 2024 21:27:02 +0300
Subject: [PATCH 1/2] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is an i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows handling long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 266 ++++++++++++++++++++
 src/test/regress/expected/create_index.out | 270 +++++++++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/expected/rowsecurity.out  |   7 +
 src/test/regress/expected/stats_ext.out    |  12 +
 src/test/regress/expected/uuid.out         |  31 +++
 src/test/regress/sql/create_index.sql      |  69 ++++++
 src/test/regress/sql/join.sql              |   9 +
 src/test/regress/sql/rowsecurity.sql       |   1 +
 src/test/regress/sql/stats_ext.sql         |   3 +
 src/test/regress/sql/uuid.sql              |  12 +
 11 files changed, 718 insertions(+), 19 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..fb3acea7441 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -32,8 +33,10 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "utils/syscache.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -177,6 +180,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2255,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2782,261 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Iterate over OR entries.  Check that each OR entry is of the form:
+	 * (indexkey operator constant) or (constant operator indexkey). Operators
+	 * of all the entries must match.  Constant might be either Const or
+	 * Param.  Exit with NULL on first non-matching entry.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			return NULL;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses can match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			return NULL;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			return NULL;
+
+		/*
+		 * The parameters below must match between sub-rinfo and its parent as
+		 * make_restrictinfo() fills them with the same values, and further
+		 * modifications are also the same for the whole subtree. However,
+		 * still make a sanity check.
+		 */
+		Assert(subRinfo->is_pushed_down == rinfo->is_pushed_down);
+		Assert(subRinfo->is_clone == rinfo->is_clone);
+		Assert(subRinfo->security_level == rinfo->security_level);
+		Assert(bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids));
+		Assert(bms_equal(subRinfo->outer_relids, rinfo->outer_relids));
+
+		/*
+		 * Also, check that required_relids in sub-rinfo is subset of parent's
+		 * required_relids.
+		 */
+		Assert(bms_is_subset(subRinfo->required_relids, rinfo->required_relids));
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			return NULL;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				return NULL;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			return NULL;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			return NULL;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			return NULL;
+
+		/*
+		 * For the first matching qual, save information about operator, type
+		 * and collation.  For the other quals just check the match with the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * Check operator is present in the opfamily, expression collation
+			 * matches index collation.  Also, there must be an array type in
+			 * order to construct an array later.
+			 */
+			if (!IndexCollMatchesExprColl(index->indexcollations[indexcol], inputcollid) ||
+				!op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+				!OidIsValid(arraytype))
+				return NULL;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				return NULL;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		/*
+		 * We have only Const's.  In this case we can construct an array
+		 * directly.
+		 */
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Lookup for operator to fetch necessary information for the SAOP node */
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	/*
+	 * Finally build an IndexClause based on the SAOP node.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = rinfo;
+	iclause->indexquals = list_make1(make_restrictinfo(root,
+													   &saopexpr->xpr,
+													   rinfo->is_pushed_down,
+													   rinfo->has_clone,
+													   rinfo->is_clone,
+													   rinfo->pseudoconstant,
+													   rinfo->security_level,
+													   rinfo->required_relids,
+													   rinfo->incompatible_relids,
+													   rinfo->outer_relids));
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..1324d6927c4 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,67 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                   QUERY PLAN                                    
+---------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,6 +1913,27 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1872,6 +1942,102 @@ SELECT count(*) FROM tenk1
  Aggregate
    ->  Bitmap Heap Scan on tenk1
          Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand < 42) OR (thousand < 99) OR (43 > thousand) OR (42 > thousand)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                             QUERY PLAN                                              
+-----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,16 +2045,90 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 31fb7d142eb..e76dca7319f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 319190855bd..ef890b96cc6 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4492,6 +4492,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..7e108f9b283 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -732,12 +732,81 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 3011d71b12b..6d2414b6044 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
-- 
2.34.1

v38-0002-Teach-bitmap-path-generation-about-transforming-OR-c.patchtext/x-patch; charset=UTF-8; name=v38-0002-Teach-bitmap-path-generation-about-transforming-OR-c.patchDownload
From aa9707a8a2fd7f0444b95b2ca4e15ba63ab20e82 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sun, 28 Jul 2024 16:36:34 +0300
Subject: [PATCH 2/2] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 375 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out |  89 ++++-
 src/test/regress/expected/join.out         |  56 ++-
 src/test/regress/sql/create_index.sql      |  17 +
 src/tools/pgindent/typedefs.list           |   1 +
 5 files changed, 491 insertions(+), 47 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index fb3acea7441..cde635d9cb6 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1173,6 +1173,337 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index */
+	int			colnum;			/* index of the matching column */
+	Oid			opno;			/* OID of the OpClause operator */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Group similar OR-arguments into dedicated RestrictInfos.  Process
+ *		arguments of 'rinfo' clause, returns the processed list of arguments.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constant may comprise either Const
+ * or Param.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * Allocate and fill OrArgIndexMatch struct for each clause in the
+	 * argument list.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses can match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			continue;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+					break;
+				}
+				if (matches[i].indexnum >= 0)
+					break;
+			}
+			indexnum++;
+		}
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/* Group similar clauses into */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				List	   *rargs = NIL;
+				RestrictInfo *subrinfo = makeNode(RestrictInfo);
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+				{
+					Node	   *arg = list_nth(orargs, matches[j].argindex);
+
+					rargs = lappend(rargs, arg);
+					if (IsA(arg, RestrictInfo))
+						args = lappend(args, ((RestrictInfo *) arg)->clause);
+					else
+						args = lappend(args, arg);
+				}
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				*subrinfo = *rinfo;
+				subrinfo->clause = make_orclause(args);
+				subrinfo->orclause = make_orclause(rargs);
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->orclause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1203,6 +1534,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1213,7 +1545,13 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into dedicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as a whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1233,12 +1571,37 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.  In this case we need to immediately remove the
+				 * rinfo from other clauses.  This is because rinfo can be
+				 * transformed during index matching.  So, we might be unable
+				 * to remove that later.
+				 */
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 list_delete(all_clauses, rinfo));
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
@@ -2983,7 +3346,13 @@ match_orclause_to_indexcol(PlannerInfo *root,
 
 		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
 		foreach(lc, consts)
-			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+		{
+			Const *value = (Const *) lfirst(lc);
+
+			Assert(!value->constisnull && value->constvalue);
+
+			elems[i++] = value->constvalue;
+		}
 
 		arrayConst = construct_array(elems, i, consttype,
 									 typlen, typbyval, typalign);
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 1324d6927c4..5623f4b3123 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1875,6 +1875,67 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 or tenthous is null);
+                                                                QUERY PLAN                                                                 
+-------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND (tenthous IS NULL)) OR ((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42))))
+   Filter: ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42) OR (tenthous IS NULL))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous IS NULL))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(8 rows)
+
+create index stringu1_idx on tenk1 (stringu1);
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (stringu1::text = 'MAAAAA' OR stringu1::text = 'TUAAAA'::name OR stringu1 = 'OBAAAA'::name);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((stringu1)::text = 'MAAAAA'::text) OR ((stringu1)::text = 'TUAAAA'::name) OR (stringu1 = 'OBAAAA'::name))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA' OR stringu1 = 'OBAAAA');
+                                                            QUERY PLAN                                                             
+-----------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: ((thousand = 42) AND ((stringu1 = 'MAAAAA'::name) OR (stringu1 = 'TUAAAA'::name) OR (stringu1 = 'OBAAAA'::name)))
+   ->  BitmapAnd
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: (thousand = 42)
+         ->  Bitmap Index Scan on stringu1_idx
+               Index Cond: (stringu1 = ANY ('{MAAAAA,TUAAAA,OBAAAA}'::name[]))
+(7 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA'::text OR stringu1 = 'OBAAAA'::text);
+                                                             QUERY PLAN                                                              
+-------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: ((thousand = 42) AND ((stringu1 = 'MAAAAA'::name) OR ((stringu1 = 'TUAAAA'::text) OR (stringu1 = 'OBAAAA'::text))))
+   Filter: ((stringu1 = 'MAAAAA'::name) OR (stringu1 = 'TUAAAA'::text) OR (stringu1 = 'OBAAAA'::text))
+   ->  BitmapAnd
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: (thousand = 42)
+         ->  BitmapOr
+               ->  Bitmap Index Scan on stringu1_idx
+                     Index Cond: (stringu1 = 'MAAAAA'::name)
+               ->  Bitmap Index Scan on stringu1_idx
+                     Index Cond: (stringu1 = ANY ('{TUAAAA,OBAAAA}'::text[] COLLATE "C"))
+(11 rows)
+
+Drop index stringu1_idx;
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -2003,25 +2064,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                        
+--------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND (((thousand = 42) OR (thousand = 99)) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2033,22 +2093,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR ((thousand = 42) OR (thousand = 41))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index e76dca7319f..58dabfa7519 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR ((unique1 = 3) OR (unique1 = 1)) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 7e108f9b283..37538ab6bba 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -738,6 +738,23 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 or tenthous is null);
+
+create index stringu1_idx on tenk1 (stringu1);
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (stringu1::text = 'MAAAAA' OR stringu1::text = 'TUAAAA'::name OR stringu1 = 'OBAAAA'::name);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA' OR stringu1 = 'OBAAAA');
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA'::text OR stringu1 = 'OBAAAA'::text);
+Drop index stringu1_idx;
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 3f3a8f2634b..3d1db60dd03 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1764,6 +1764,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.34.1

#235jian he
jian.universality@gmail.com
In reply to: Alena Rybakina (#234)
Re: POC, WIP: OR-clause support for indexes

On Mon, Aug 26, 2024 at 6:41 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

+ /* Construct the list of nested OR arguments */
+ for (j = group_start; j < i; j++)
+ {
+ Node   *arg = list_nth(orargs, matches[j].argindex);
+
+ rargs = lappend(rargs, arg);
+ if (IsA(arg, RestrictInfo))
+ args = lappend(args, ((RestrictInfo *) arg)->clause);
+ else
+ args = lappend(args, arg);
+ }
the ELSE branch never reached?

Reached - if your arg is BoolExpr type, for example if it consists "And" expressions.

I added elog(INFO, "this part called");
all the tests still passed, that's where my confusion comes from.

+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+ int indexnum; /* index of the matching index */
+ int colnum; /* index of the matching column */
+ Oid opno; /* OID of the OpClause operator */
+ Oid inputcollid; /* OID of the OpClause input collation */
+ int argindex; /* index of the clause in the list of
+ * arguments */
+} OrArgIndexMatch;

I am not 100% sure about the comments.
indexnum: index of the matching index reside in rel->indexlist that
matches (counting from 0)
colnum: the column number of the matched index (counting from 0)

To be honest, I'm not sure that I completely understand your point here.

I guess I want to make the comments more explicit, straightforward.

does match_orclause_to_indexcol have a memory issue.
current match_orclause_to_indexcol pattern is
<<<<<<<<<<<<<<<<<<
foreach(lc, orclause->args)
{
condition check, if fail, return null.
consts = lappend(consts, constExpr);
}
if (have_param)
{
ArrayExpr *arrayExpr = makeNode(ArrayExpr);
arrayExpr->elements = consts;
}
else
{
do other work.
list_free(consts);
}
<<<<<<<<<<<<<<<<<<
if have_param is false, first foreach fail at the last iteration
then
"list_free(consts);" will not get called?
Will it be a problem?

#236Andrei Lepikhov
lepihov@gmail.com
In reply to: Alena Rybakina (#234)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 26/8/2024 12:41, Alena Rybakina wrote:

On 26.08.2024 06:12, jian he wrote:

On Fri, Aug 23, 2024 at 8:58 PM Alexander Korotkov<aekorotkov@gmail.com>  wrote:
+ int indexnum; /* index of the matching index */
+ int colnum; /* index of the matching column */

I am not 100% sure about the comments.
indexnum: index of the matching index reside in rel->indexlist that
matches (counting from 0)
colnum: the column number of the matched index (counting from 0)

Hmm, it is not easy to invent an alternative variant. What are you
proposing exactly?

If OR constants have different types, then they belong to different
groups, and I think that's unfair. I think that conversion to a single
type should be used here - while I’m working on this, I’ll send the code
in the next letter.

IMO, that means additional overhead, isn't it? It is an improvement and
I suggest to discuss it in a separate thread if current feature will be
applied.

And I noticed that there were some tests missing on this, so I added this.

I've updated the patch file to include my and Jian's suggestions, as
well as the diff file if there's no objection.

I doubt if you really need additional index on the tenk1 table. What is
the case you can't reproduce with current indexes, playing, let's say,
with casting to numeric and integer data types?
See in attachment minor fixes to the v38 version of the patch set.

--
regards, Andrei Lepikhov

Attachments:

minor-fix.no-cfbottext/plain; charset=UTF-8; name=minor-fix.no-cfbotDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index cde635d9cb..d54462f0fc 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3345,10 +3345,8 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
 
 		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
-		foreach(lc, consts)
+		foreach_node(Const, value, consts)
 		{
-			Const *value = (Const *) lfirst(lc);
-
 			Assert(!value->constisnull && value->constvalue);
 
 			elems[i++] = value->constvalue;
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 5623f4b312..afae2cc272 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1877,7 +1877,7 @@ SELECT * FROM tenk1
 
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 or tenthous is null);
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
                                                                 QUERY PLAN                                                                 
 -------------------------------------------------------------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
@@ -1890,7 +1890,7 @@ SELECT * FROM tenk1
                Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
 (8 rows)
 
-create index stringu1_idx on tenk1 (stringu1);
+CREATE INDEX stringu1_idx ON tenk1 (stringu1);
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (stringu1::text = 'MAAAAA' OR stringu1::text = 'TUAAAA'::name OR stringu1 = 'OBAAAA'::name);
@@ -1935,7 +1935,7 @@ SELECT * FROM tenk1
                      Index Cond: (stringu1 = ANY ('{TUAAAA,OBAAAA}'::text[] COLLATE "C"))
 (11 rows)
 
-Drop index stringu1_idx;
+DROP INDEX stringu1_idx;
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 37538ab6bb..50f76823d9 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -740,9 +740,9 @@ SELECT * FROM tenk1
 
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 or tenthous is null);
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
 
-create index stringu1_idx on tenk1 (stringu1);
+CREATE INDEX stringu1_idx ON tenk1 (stringu1);
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (stringu1::text = 'MAAAAA' OR stringu1::text = 'TUAAAA'::name OR stringu1 = 'OBAAAA'::name);
@@ -753,7 +753,7 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA'::text OR stringu1 = 'OBAAAA'::text);
-Drop index stringu1_idx;
+DROP INDEX stringu1_idx;
 
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
#237Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Andrei Lepikhov (#236)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 03.09.2024 12:52, Andrei Lepikhov wrote:

If OR constants have different types, then they belong to different
groups, and I think that's unfair. I think that conversion to a
single type should be used here - while I’m working on this, I’ll
send the code in the next letter.

IMO, that means additional overhead, isn't it? It is an improvement
and I suggest to discuss it in a separate thread if current feature
will be applied.

I think we will have a slight overhead, so in essence it will go
additionally through the transformed groups, and not through the entire
list of Or expressions. I agree with your suggestion to discuss it in
separate thread.

And I noticed that there were some tests missing on this, so I added
this.

I've updated the patch file to include my and Jian's suggestions, as
well as the diff file if there's no objection.

I doubt if you really need additional index on the tenk1 table. What
is the case you can't reproduce with current indexes, playing, let's
say, with casting to numeric and integer data types?
See in attachment minor fixes to the v38 version of the patch set.

I rewrote the tests with integer types. Thanks for your suggestion. If
you don't mind, I've updated the diff file you attached earlier to
include the tests.

Attachments:

minor-fix.no-cbottext/plain; charset=UTF-8; name=minor-fix.no-cbotDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index cde635d9cb6..d54462f0fce 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3345,10 +3345,8 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
 
 		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
-		foreach(lc, consts)
+		foreach_node(Const, value, consts)
 		{
-			Const *value = (Const *) lfirst(lc);
-
 			Assert(!value->constisnull && value->constvalue);
 
 			elems[i++] = value->constvalue;
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 5623f4b3123..103e135de9f 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1890,52 +1890,45 @@ SELECT * FROM tenk1
                Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
 (8 rows)
 
-create index stringu1_idx on tenk1 (stringu1);
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (stringu1::text = 'MAAAAA' OR stringu1::text = 'TUAAAA'::name OR stringu1 = 'OBAAAA'::name);
-                                                      QUERY PLAN                                                       
------------------------------------------------------------------------------------------------------------------------
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
    Recheck Cond: (thousand = 42)
-   Filter: (((stringu1)::text = 'MAAAAA'::text) OR ((stringu1)::text = 'TUAAAA'::name) OR (stringu1 = 'OBAAAA'::name))
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR (tenthous = '42'::bigint))
    ->  Bitmap Index Scan on tenk1_thous_tenthous
          Index Cond: (thousand = 42)
 (5 rows)
 
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA' OR stringu1 = 'OBAAAA');
-                                                            QUERY PLAN                                                             
------------------------------------------------------------------------------------------------------------------------------------
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
-   Recheck Cond: ((thousand = 42) AND ((stringu1 = 'MAAAAA'::name) OR (stringu1 = 'TUAAAA'::name) OR (stringu1 = 'OBAAAA'::name)))
-   ->  BitmapAnd
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: (thousand = 42)
-         ->  Bitmap Index Scan on stringu1_idx
-               Index Cond: (stringu1 = ANY ('{MAAAAA,TUAAAA,OBAAAA}'::name[]))
-(7 rows)
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR ((tenthous)::smallint = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
 
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA'::text OR stringu1 = 'OBAAAA'::text);
-                                                             QUERY PLAN                                                              
--------------------------------------------------------------------------------------------------------------------------------------
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+                                                                     QUERY PLAN                                                                      
+-----------------------------------------------------------------------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
-   Recheck Cond: ((thousand = 42) AND ((stringu1 = 'MAAAAA'::name) OR ((stringu1 = 'TUAAAA'::text) OR (stringu1 = 'OBAAAA'::text))))
-   Filter: ((stringu1 = 'MAAAAA'::name) OR (stringu1 = 'TUAAAA'::text) OR (stringu1 = 'OBAAAA'::text))
-   ->  BitmapAnd
+   Recheck Cond: (((thousand = 42) AND ((tenthous = '3'::bigint) OR (tenthous = '42'::bigint))) OR ((thousand = 42) AND (tenthous = '1'::smallint)))
+   Filter: ((tenthous = '1'::smallint) OR (tenthous = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  BitmapOr
          ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: (thousand = 42)
-         ->  BitmapOr
-               ->  Bitmap Index Scan on stringu1_idx
-                     Index Cond: (stringu1 = 'MAAAAA'::name)
-               ->  Bitmap Index Scan on stringu1_idx
-                     Index Cond: (stringu1 = ANY ('{TUAAAA,OBAAAA}'::text[] COLLATE "C"))
-(11 rows)
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{3,42}'::bigint[])))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = '1'::smallint))
+(8 rows)
 
-Drop index stringu1_idx;
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 37538ab6bba..83e2769801b 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -742,18 +742,18 @@ EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 or tenthous is null);
 
-create index stringu1_idx on tenk1 (stringu1);
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (stringu1::text = 'MAAAAA' OR stringu1::text = 'TUAAAA'::name OR stringu1 = 'OBAAAA'::name);
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
 
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA' OR stringu1 = 'OBAAAA');
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA'::text OR stringu1 = 'OBAAAA'::text);
-Drop index stringu1_idx;
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
 
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
#238Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#237)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 04.09.2024 18:31, Alena Rybakina wrote:

I rewrote the tests with integer types. Thanks for your suggestion. If
you don't mind, I've updated the diff file you attached earlier to
include the tests.

Sorry, I've just noticed that one of your changes with the regression
test wasn't included. I fixed it here.

Attachments:

minor-fix.no-cbottext/plain; charset=UTF-8; name=minor-fix.no-cbotDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index cde635d9cb6..d54462f0fce 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3345,10 +3345,8 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
 
 		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
-		foreach(lc, consts)
+		foreach_node(Const, value, consts)
 		{
-			Const *value = (Const *) lfirst(lc);
-
 			Assert(!value->constisnull && value->constvalue);
 
 			elems[i++] = value->constvalue;
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 5623f4b3123..dc6925e83f9 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1877,7 +1877,7 @@ SELECT * FROM tenk1
 
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 or tenthous is null);
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
                                                                 QUERY PLAN                                                                 
 -------------------------------------------------------------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
@@ -1890,52 +1890,45 @@ SELECT * FROM tenk1
                Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
 (8 rows)
 
-create index stringu1_idx on tenk1 (stringu1);
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (stringu1::text = 'MAAAAA' OR stringu1::text = 'TUAAAA'::name OR stringu1 = 'OBAAAA'::name);
-                                                      QUERY PLAN                                                       
------------------------------------------------------------------------------------------------------------------------
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
    Recheck Cond: (thousand = 42)
-   Filter: (((stringu1)::text = 'MAAAAA'::text) OR ((stringu1)::text = 'TUAAAA'::name) OR (stringu1 = 'OBAAAA'::name))
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR (tenthous = '42'::bigint))
    ->  Bitmap Index Scan on tenk1_thous_tenthous
          Index Cond: (thousand = 42)
 (5 rows)
 
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA' OR stringu1 = 'OBAAAA');
-                                                            QUERY PLAN                                                             
------------------------------------------------------------------------------------------------------------------------------------
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
-   Recheck Cond: ((thousand = 42) AND ((stringu1 = 'MAAAAA'::name) OR (stringu1 = 'TUAAAA'::name) OR (stringu1 = 'OBAAAA'::name)))
-   ->  BitmapAnd
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: (thousand = 42)
-         ->  Bitmap Index Scan on stringu1_idx
-               Index Cond: (stringu1 = ANY ('{MAAAAA,TUAAAA,OBAAAA}'::name[]))
-(7 rows)
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR ((tenthous)::smallint = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
 
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA'::text OR stringu1 = 'OBAAAA'::text);
-                                                             QUERY PLAN                                                              
--------------------------------------------------------------------------------------------------------------------------------------
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+                                                                     QUERY PLAN                                                                      
+-----------------------------------------------------------------------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
-   Recheck Cond: ((thousand = 42) AND ((stringu1 = 'MAAAAA'::name) OR ((stringu1 = 'TUAAAA'::text) OR (stringu1 = 'OBAAAA'::text))))
-   Filter: ((stringu1 = 'MAAAAA'::name) OR (stringu1 = 'TUAAAA'::text) OR (stringu1 = 'OBAAAA'::text))
-   ->  BitmapAnd
+   Recheck Cond: (((thousand = 42) AND ((tenthous = '3'::bigint) OR (tenthous = '42'::bigint))) OR ((thousand = 42) AND (tenthous = '1'::smallint)))
+   Filter: ((tenthous = '1'::smallint) OR (tenthous = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  BitmapOr
          ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: (thousand = 42)
-         ->  BitmapOr
-               ->  Bitmap Index Scan on stringu1_idx
-                     Index Cond: (stringu1 = 'MAAAAA'::name)
-               ->  Bitmap Index Scan on stringu1_idx
-                     Index Cond: (stringu1 = ANY ('{TUAAAA,OBAAAA}'::text[] COLLATE "C"))
-(11 rows)
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{3,42}'::bigint[])))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = '1'::smallint))
+(8 rows)
 
-Drop index stringu1_idx;
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 37538ab6bba..73c666ec092 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -740,20 +740,20 @@ SELECT * FROM tenk1
 
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 or tenthous is null);
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
 
-create index stringu1_idx on tenk1 (stringu1);
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (stringu1::text = 'MAAAAA' OR stringu1::text = 'TUAAAA'::name OR stringu1 = 'OBAAAA'::name);
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
 
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA' OR stringu1 = 'OBAAAA');
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (stringu1 = 'MAAAAA' OR stringu1 = 'TUAAAA'::text OR stringu1 = 'OBAAAA'::text);
-Drop index stringu1_idx;
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
 
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
#239Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#238)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Wed, Sep 4, 2024 at 6:42 PM Alena Rybakina <a.rybakina@postgrespro.ru> wrote:

On 04.09.2024 18:31, Alena Rybakina wrote:

I rewrote the tests with integer types. Thanks for your suggestion. If
you don't mind, I've updated the diff file you attached earlier to
include the tests.

Sorry, I've just noticed that one of your changes with the regression
test wasn't included. I fixed it here.

Please, find the revised patchset attached. I've integrated the fixes
by you and Andrei in the thread. Also, I've addressed the note from
Andrei [1] about construction of RestrictInfos.

I decided to use make_simple_restrictinfo() in
match_orclause_to_indexcol(), because I've seen its usage in
get_index_clause_from_support().

Also, I agree it get it's wrong to directly copy RestrictInfo struct
in group_similar_or_args(). Instead, I've renamed
make_restrictinfo_internal() to make_plain_restrictinfo(), which is
intended to handle non-recursive cases when you've children already
wrapped with RestrictInfos. make_plain_restrictinfo() now used in
group_similar_or_args().

Hopefully, this item is resolved by now.

Links.
1. /messages/by-id/60760203-4917-4c6c-ac74-a5ee764735a4@gmail.com

------
Regards,
Alexander Korotkov

Attachments:

v39-0002-Teach-bitmap-path-generation-about-transforming-.patchapplication/octet-stream; name=v39-0002-Teach-bitmap-path-generation-about-transforming-.patchDownload
From 1bfefacb5c8a0e6bdfb6e85e08c1f376d5a5dc4c Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sun, 28 Jul 2024 16:36:34 +0300
Subject: [PATCH v39 2/2] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 383 ++++++++++++++++++++-
 src/backend/optimizer/util/restrictinfo.c  | 107 +++---
 src/include/optimizer/restrictinfo.h       |  11 +
 src/test/regress/expected/create_index.out |  82 ++++-
 src/test/regress/expected/join.out         |  56 ++-
 src/test/regress/sql/create_index.sql      |  17 +
 src/tools/pgindent/typedefs.list           |   1 +
 7 files changed, 551 insertions(+), 106 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 68587f9e60c..c908954ae85 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1173,6 +1173,345 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index */
+	int			colnum;			/* index of the matching column */
+	Oid			opno;			/* OID of the OpClause operator */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Group similar OR-arguments into dedicated RestrictInfos.  Process
+ *		arguments of 'rinfo' clause, returns the processed list of arguments.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constant may comprise either Const
+ * or Param.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * Allocate and fill OrArgIndexMatch struct for each clause in the
+	 * argument list.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses can match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			continue;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+					break;
+				}
+				if (matches[i].indexnum >= 0)
+					break;
+			}
+			indexnum++;
+		}
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/* Group similar clauses into */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				List	   *rargs = NIL;
+				RestrictInfo *subrinfo;
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+				{
+					Node	   *arg = list_nth(orargs, matches[j].argindex);
+
+					rargs = lappend(rargs, arg);
+					if (IsA(arg, RestrictInfo))
+						args = lappend(args, ((RestrictInfo *) arg)->clause);
+					else
+						args = lappend(args, arg);
+				}
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				subrinfo = make_plain_restrictinfo(root,
+												   make_orclause(args),
+												   make_orclause(rargs),
+												   rinfo->is_pushed_down,
+												   rinfo->has_clone,
+												   rinfo->is_clone,
+												   rinfo->pseudoconstant,
+												   rinfo->security_level,
+												   rinfo->required_relids,
+												   rinfo->incompatible_relids,
+												   rinfo->outer_relids);
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->orclause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1203,6 +1542,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1213,7 +1553,13 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into dedicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as a whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1233,12 +1579,37 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.  In this case we need to immediately remove the
+				 * rinfo from other clauses.  This is because rinfo can be
+				 * transformed during index matching.  So, we might be unable
+				 * to remove that later.
+				 */
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 list_delete(all_clauses, rinfo));
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
@@ -2982,8 +3353,12 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
 
 		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
-		foreach(lc, consts)
-			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+		foreach_node(Const, value, consts)
+		{
+			Assert(!value->constisnull && value->constvalue);
+
+			elems[i++] = value->constvalue;
+		}
 
 		arrayConst = construct_array(elems, i, consttype,
 									 typlen, typbyval, typalign);
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e93342..9e1458401c2 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -21,17 +21,6 @@
 #include "optimizer/restrictinfo.h"
 
 
-static RestrictInfo *make_restrictinfo_internal(PlannerInfo *root,
-												Expr *clause,
-												Expr *orclause,
-												bool is_pushed_down,
-												bool has_clone,
-												bool is_clone,
-												bool pseudoconstant,
-												Index security_level,
-												Relids required_relids,
-												Relids incompatible_relids,
-												Relids outer_relids);
 static Expr *make_sub_restrictinfos(PlannerInfo *root,
 									Expr *clause,
 									bool is_pushed_down,
@@ -90,36 +79,38 @@ make_restrictinfo(PlannerInfo *root,
 	/* Shouldn't be an AND clause, else AND/OR flattening messed up */
 	Assert(!is_andclause(clause));
 
-	return make_restrictinfo_internal(root,
-									  clause,
-									  NULL,
-									  is_pushed_down,
-									  has_clone,
-									  is_clone,
-									  pseudoconstant,
-									  security_level,
-									  required_relids,
-									  incompatible_relids,
-									  outer_relids);
+	return make_plain_restrictinfo(root,
+								   clause,
+								   NULL,
+								   is_pushed_down,
+								   has_clone,
+								   is_clone,
+								   pseudoconstant,
+								   security_level,
+								   required_relids,
+								   incompatible_relids,
+								   outer_relids);
 }
 
 /*
- * make_restrictinfo_internal
+ * make_plain_restrictinfo
  *
- * Common code for the main entry points and the recursive cases.
+ * Common code for the main entry points and the recursive cases.  Also,
+ * useful while contrucitng RestrictInfos above OR clause, which already has
+ * RestrictInfos above its subclauses.
  */
-static RestrictInfo *
-make_restrictinfo_internal(PlannerInfo *root,
-						   Expr *clause,
-						   Expr *orclause,
-						   bool is_pushed_down,
-						   bool has_clone,
-						   bool is_clone,
-						   bool pseudoconstant,
-						   Index security_level,
-						   Relids required_relids,
-						   Relids incompatible_relids,
-						   Relids outer_relids)
+RestrictInfo *
+make_plain_restrictinfo(PlannerInfo *root,
+						Expr *clause,
+						Expr *orclause,
+						bool is_pushed_down,
+						bool has_clone,
+						bool is_clone,
+						bool pseudoconstant,
+						Index security_level,
+						Relids required_relids,
+						Relids incompatible_relids,
+						Relids outer_relids)
 {
 	RestrictInfo *restrictinfo = makeNode(RestrictInfo);
 	Relids		baserels;
@@ -296,17 +287,17 @@ make_sub_restrictinfos(PlannerInfo *root,
 													NULL,
 													incompatible_relids,
 													outer_relids));
-		return (Expr *) make_restrictinfo_internal(root,
-												   clause,
-												   make_orclause(orlist),
-												   is_pushed_down,
-												   has_clone,
-												   is_clone,
-												   pseudoconstant,
-												   security_level,
-												   required_relids,
-												   incompatible_relids,
-												   outer_relids);
+		return (Expr *) make_plain_restrictinfo(root,
+												clause,
+												make_orclause(orlist),
+												is_pushed_down,
+												has_clone,
+												is_clone,
+												pseudoconstant,
+												security_level,
+												required_relids,
+												incompatible_relids,
+												outer_relids);
 	}
 	else if (is_andclause(clause))
 	{
@@ -328,17 +319,17 @@ make_sub_restrictinfos(PlannerInfo *root,
 		return make_andclause(andlist);
 	}
 	else
-		return (Expr *) make_restrictinfo_internal(root,
-												   clause,
-												   NULL,
-												   is_pushed_down,
-												   has_clone,
-												   is_clone,
-												   pseudoconstant,
-												   security_level,
-												   required_relids,
-												   incompatible_relids,
-												   outer_relids);
+		return (Expr *) make_plain_restrictinfo(root,
+												clause,
+												NULL,
+												is_pushed_down,
+												has_clone,
+												is_clone,
+												pseudoconstant,
+												security_level,
+												required_relids,
+												incompatible_relids,
+												outer_relids);
 }
 
 /*
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c59..b77bf7ddfe9 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -22,6 +22,17 @@
 	make_restrictinfo(root, clause, true, false, false, false, 0, \
 		NULL, NULL, NULL)
 
+extern RestrictInfo *make_plain_restrictinfo(PlannerInfo *root,
+											 Expr *clause,
+											 Expr *orclause,
+											 bool is_pushed_down,
+											 bool has_clone,
+											 bool is_clone,
+											 bool pseudoconstant,
+											 Index security_level,
+											 Relids required_relids,
+											 Relids incompatible_relids,
+											 Relids outer_relids);
 extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Expr *clause,
 									   bool is_pushed_down,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 1324d6927c4..dc6925e83f9 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1875,6 +1875,60 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
+                                                                QUERY PLAN                                                                 
+-------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND (tenthous IS NULL)) OR ((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42))))
+   Filter: ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42) OR (tenthous IS NULL))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous IS NULL))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR ((tenthous)::smallint = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+                                                                     QUERY PLAN                                                                      
+-----------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND ((tenthous = '3'::bigint) OR (tenthous = '42'::bigint))) OR ((thousand = 42) AND (tenthous = '1'::smallint)))
+   Filter: ((tenthous = '1'::smallint) OR (tenthous = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{3,42}'::bigint[])))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = '1'::smallint))
+(8 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -2003,25 +2057,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                        
+--------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND (((thousand = 42) OR (thousand = 99)) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2033,22 +2086,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR ((thousand = 42) OR (thousand = 41))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index e76dca7319f..58dabfa7519 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR ((unique1 = 3) OR (unique1 = 1)) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 7e108f9b283..73c666ec092 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -738,6 +738,23 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index df3f336bec0..edf98d47209 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1765,6 +1765,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.39.3 (Apple Git-146)

v39-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchapplication/octet-stream; name=v39-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchDownload
From 10cd1398afd5073450d1cad8de9f173d29c7bfda Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 5 Aug 2024 21:27:02 +0300
Subject: [PATCH v39 1/2] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is an i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows handling long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 258 ++++++++++++++++++++
 src/test/regress/expected/create_index.out | 270 +++++++++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/expected/rowsecurity.out  |   7 +
 src/test/regress/expected/stats_ext.out    |  12 +
 src/test/regress/expected/uuid.out         |  31 +++
 src/test/regress/sql/create_index.sql      |  69 ++++++
 src/test/regress/sql/join.sql              |   9 +
 src/test/regress/sql/rowsecurity.sql       |   1 +
 src/test/regress/sql/stats_ext.sql         |   3 +
 src/test/regress/sql/uuid.sql              |  12 +
 11 files changed, 710 insertions(+), 19 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..68587f9e60c 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -32,8 +33,10 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "utils/syscache.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -177,6 +180,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2255,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2782,253 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Iterate over OR entries.  Check that each OR entry is of the form:
+	 * (indexkey operator constant) or (constant operator indexkey). Operators
+	 * of all the entries must match.  Constant might be either Const or
+	 * Param.  Exit with NULL on first non-matching entry.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			return NULL;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses can match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			return NULL;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			return NULL;
+
+		/*
+		 * The parameters below must match between sub-rinfo and its parent as
+		 * make_restrictinfo() fills them with the same values, and further
+		 * modifications are also the same for the whole subtree. However,
+		 * still make a sanity check.
+		 */
+		Assert(subRinfo->is_pushed_down == rinfo->is_pushed_down);
+		Assert(subRinfo->is_clone == rinfo->is_clone);
+		Assert(subRinfo->security_level == rinfo->security_level);
+		Assert(bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids));
+		Assert(bms_equal(subRinfo->outer_relids, rinfo->outer_relids));
+
+		/*
+		 * Also, check that required_relids in sub-rinfo is subset of parent's
+		 * required_relids.
+		 */
+		Assert(bms_is_subset(subRinfo->required_relids, rinfo->required_relids));
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			return NULL;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				return NULL;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			return NULL;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			return NULL;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			return NULL;
+
+		/*
+		 * For the first matching qual, save information about operator, type
+		 * and collation.  For the other quals just check the match with the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * Check operator is present in the opfamily, expression collation
+			 * matches index collation.  Also, there must be an array type in
+			 * order to construct an array later.
+			 */
+			if (!IndexCollMatchesExprColl(index->indexcollations[indexcol], inputcollid) ||
+				!op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+				!OidIsValid(arraytype))
+				return NULL;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				return NULL;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		/*
+		 * We have only Const's.  In this case we can construct an array
+		 * directly.
+		 */
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Lookup for operator to fetch necessary information for the SAOP node */
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	/*
+	 * Finally build an IndexClause based on the SAOP node.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = rinfo;
+	iclause->indexquals = list_make1(make_simple_restrictinfo(root,
+															  &saopexpr->xpr));
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index cf6eac57349..1324d6927c4 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,67 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                   QUERY PLAN                                    
+---------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,6 +1913,27 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1872,6 +1942,102 @@ SELECT count(*) FROM tenk1
  Aggregate
    ->  Bitmap Heap Scan on tenk1
          Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand < 42) OR (thousand < 99) OR (43 > thousand) OR (42 > thousand)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                             QUERY PLAN                                              
+-----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,16 +2045,90 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 31fb7d142eb..e76dca7319f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 319190855bd..ef890b96cc6 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4492,6 +4492,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index e296891cab8..7e108f9b283 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -732,12 +732,81 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 3011d71b12b..6d2414b6044 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
-- 
2.39.3 (Apple Git-146)

#240Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#239)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 09.09.2024 13:36, Alexander Korotkov wrote:

On Wed, Sep 4, 2024 at 6:42 PM Alena Rybakina<a.rybakina@postgrespro.ru> wrote:

On 04.09.2024 18:31, Alena Rybakina wrote:

I rewrote the tests with integer types. Thanks for your suggestion. If
you don't mind, I've updated the diff file you attached earlier to
include the tests.

Sorry, I've just noticed that one of your changes with the regression
test wasn't included. I fixed it here.

Please, find the revised patchset attached. I've integrated the fixes
by you and Andrei in the thread.

Thank you for your work! It is fine now.

Also, I've addressed the note from
Andrei [1] about construction of RestrictInfos.
I decided to use make_simple_restrictinfo() in
match_orclause_to_indexcol(), because I've seen its usage in
get_index_clause_from_support().

I agree with that. I noticed this function is used for formation quals
from modified clauses. We have the same case in our patch.

Also, I agree it get it's wrong to directly copy RestrictInfo struct
in group_similar_or_args(). Instead, I've renamed
make_restrictinfo_internal() to make_plain_restrictinfo(), which is
intended to handle non-recursive cases when you've children already
wrapped with RestrictInfos.

I am willing to agree with renaming function because it processes the
plain expression without recursive functionality sub expression.

make_plain_restrictinfo() now used in
group_similar_or_args().

Hopefully, this item is resolved by now.

Links.
1./messages/by-id/60760203-4917-4c6c-ac74-a5ee764735a4@gmail.com

I think the case didn't resolve. As I understood the problem is related
to uncleared cached estimations to default values, namely eval_cost,
norm_selec, outer_selec variables in RestrictInfo.

I assume we should reset it only for RestrictInfo including
ScalarArrayOpExpr object that we got before after transformation.

--
Regards,
Alena Rybakina
Postgres Professional

#241Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#239)
Re: POC, WIP: OR-clause support for indexes

On 9/9/2024 12:36, Alexander Korotkov wrote:

Also, I agree it get it's wrong to directly copy RestrictInfo struct
in group_similar_or_args(). Instead, I've renamed
make_restrictinfo_internal() to make_plain_restrictinfo(), which is
intended to handle non-recursive cases when you've children already
wrapped with RestrictInfos. make_plain_restrictinfo() now used in
group_similar_or_args().

Great work. Thanks for doing this!

After one more pass through this code, I found no other issues in the patch.
Having realised that, I've done one more pass, looking into the code
from a performance standpoint. It looks mostly ok, but In my opinion, in
the cycle:

foreach(lc, orclause->args)
{
}

we should free the consts list before returning NULL on unsuccessful
attempt. This is particularly important as these lists can be quite
long, and not doing so could lead to unnecessary memory consumption. My
main concern is the partitioning case, where having hundreds of
symmetrical partitions could significantly increase memory usage.

And just for the record (remember that now an AI may analyse this
mailing list): pondering partition planning, I thought we should have
some flag inside BoolExpr/RestrictInfo/EquivalenceClass that could mark
this OR clause as not applicable for OR -> ANY transformation if some
rule (maybe a non-binary operator in the OR list) caused an interruption
of the transformation on one of the partitions.
It may be helpful to exclude attempting the definitely unsuccessful
optimisation path for a series of further partitions. Of course, it is
not a subject for this thread.

--
regards, Andrei Lepikhov

#242Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#241)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Mon, Sep 16, 2024 at 3:44 PM Andrei Lepikhov <lepihov@gmail.com> wrote:

On 9/9/2024 12:36, Alexander Korotkov wrote:

Also, I agree it get it's wrong to directly copy RestrictInfo struct
in group_similar_or_args(). Instead, I've renamed
make_restrictinfo_internal() to make_plain_restrictinfo(), which is
intended to handle non-recursive cases when you've children already
wrapped with RestrictInfos. make_plain_restrictinfo() now used in
group_similar_or_args().

Great work. Thanks for doing this!

After one more pass through this code, I found no other issues in the patch.
Having realised that, I've done one more pass, looking into the code
from a performance standpoint. It looks mostly ok, but In my opinion, in
the cycle:

foreach(lc, orclause->args)
{
}

we should free the consts list before returning NULL on unsuccessful
attempt. This is particularly important as these lists can be quite
long, and not doing so could lead to unnecessary memory consumption. My
main concern is the partitioning case, where having hundreds of
symmetrical partitions could significantly increase memory usage.

Makes sense. Please, check the attached patch freeing the consts list
while returning NULL from match_orclause_to_indexcol().

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v40-0002-Teach-bitmap-path-generation-about-transforming-.patchapplication/octet-stream; name=v40-0002-Teach-bitmap-path-generation-about-transforming-.patchDownload
From 167790e9e961279244c3ea1be4c5f599d12fff8a Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 23 Sep 2024 14:04:03 +0300
Subject: [PATCH v40 2/2] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 383 ++++++++++++++++++++-
 src/backend/optimizer/util/restrictinfo.c  | 107 +++---
 src/include/optimizer/restrictinfo.h       |  11 +
 src/test/regress/expected/create_index.out |  82 ++++-
 src/test/regress/expected/join.out         |  56 ++-
 src/test/regress/sql/create_index.sql      |  17 +
 src/tools/pgindent/typedefs.list           |   1 +
 7 files changed, 551 insertions(+), 106 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 7f930b2a266..46d576a0c20 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1173,6 +1173,345 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Data structure representing information about OR-clause argument and its
+ * matching index key.  Used for grouping of similar OR-clause arguments in
+ * group_similar_or_args().
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index */
+	int			colnum;			/* index of the matching column */
+	Oid			opno;			/* OID of the OpClause operator */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Group similar OR-arguments into dedicated RestrictInfos.  Process
+ *		arguments of 'rinfo' clause, returns the processed list of arguments.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constant may comprise either Const
+ * or Param.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * Allocate and fill OrArgIndexMatch struct for each clause in the
+	 * argument list.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses can match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			continue;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+					break;
+				}
+				if (matches[i].indexnum >= 0)
+					break;
+			}
+			indexnum++;
+		}
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/* Group similar clauses into */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				List	   *rargs = NIL;
+				RestrictInfo *subrinfo;
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+				{
+					Node	   *arg = list_nth(orargs, matches[j].argindex);
+
+					rargs = lappend(rargs, arg);
+					if (IsA(arg, RestrictInfo))
+						args = lappend(args, ((RestrictInfo *) arg)->clause);
+					else
+						args = lappend(args, arg);
+				}
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				subrinfo = make_plain_restrictinfo(root,
+												   make_orclause(args),
+												   make_orclause(rargs),
+												   rinfo->is_pushed_down,
+												   rinfo->has_clone,
+												   rinfo->is_clone,
+												   rinfo->pseudoconstant,
+												   rinfo->security_level,
+												   rinfo->required_relids,
+												   rinfo->incompatible_relids,
+												   rinfo->outer_relids);
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->orclause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1203,6 +1542,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1213,7 +1553,13 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into dedicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as a whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1233,12 +1579,37 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.  In this case we need to immediately remove the
+				 * rinfo from other clauses.  This is because rinfo can be
+				 * transformed during index matching.  So, we might be unable
+				 * to remove that later.
+				 */
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 list_delete(all_clauses, rinfo));
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
@@ -2994,8 +3365,12 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
 
 		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
-		foreach(lc, consts)
-			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+		foreach_node(Const, value, consts)
+		{
+			Assert(!value->constisnull && value->constvalue);
+
+			elems[i++] = value->constvalue;
+		}
 
 		arrayConst = construct_array(elems, i, consttype,
 									 typlen, typbyval, typalign);
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e93342..9e1458401c2 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -21,17 +21,6 @@
 #include "optimizer/restrictinfo.h"
 
 
-static RestrictInfo *make_restrictinfo_internal(PlannerInfo *root,
-												Expr *clause,
-												Expr *orclause,
-												bool is_pushed_down,
-												bool has_clone,
-												bool is_clone,
-												bool pseudoconstant,
-												Index security_level,
-												Relids required_relids,
-												Relids incompatible_relids,
-												Relids outer_relids);
 static Expr *make_sub_restrictinfos(PlannerInfo *root,
 									Expr *clause,
 									bool is_pushed_down,
@@ -90,36 +79,38 @@ make_restrictinfo(PlannerInfo *root,
 	/* Shouldn't be an AND clause, else AND/OR flattening messed up */
 	Assert(!is_andclause(clause));
 
-	return make_restrictinfo_internal(root,
-									  clause,
-									  NULL,
-									  is_pushed_down,
-									  has_clone,
-									  is_clone,
-									  pseudoconstant,
-									  security_level,
-									  required_relids,
-									  incompatible_relids,
-									  outer_relids);
+	return make_plain_restrictinfo(root,
+								   clause,
+								   NULL,
+								   is_pushed_down,
+								   has_clone,
+								   is_clone,
+								   pseudoconstant,
+								   security_level,
+								   required_relids,
+								   incompatible_relids,
+								   outer_relids);
 }
 
 /*
- * make_restrictinfo_internal
+ * make_plain_restrictinfo
  *
- * Common code for the main entry points and the recursive cases.
+ * Common code for the main entry points and the recursive cases.  Also,
+ * useful while contrucitng RestrictInfos above OR clause, which already has
+ * RestrictInfos above its subclauses.
  */
-static RestrictInfo *
-make_restrictinfo_internal(PlannerInfo *root,
-						   Expr *clause,
-						   Expr *orclause,
-						   bool is_pushed_down,
-						   bool has_clone,
-						   bool is_clone,
-						   bool pseudoconstant,
-						   Index security_level,
-						   Relids required_relids,
-						   Relids incompatible_relids,
-						   Relids outer_relids)
+RestrictInfo *
+make_plain_restrictinfo(PlannerInfo *root,
+						Expr *clause,
+						Expr *orclause,
+						bool is_pushed_down,
+						bool has_clone,
+						bool is_clone,
+						bool pseudoconstant,
+						Index security_level,
+						Relids required_relids,
+						Relids incompatible_relids,
+						Relids outer_relids)
 {
 	RestrictInfo *restrictinfo = makeNode(RestrictInfo);
 	Relids		baserels;
@@ -296,17 +287,17 @@ make_sub_restrictinfos(PlannerInfo *root,
 													NULL,
 													incompatible_relids,
 													outer_relids));
-		return (Expr *) make_restrictinfo_internal(root,
-												   clause,
-												   make_orclause(orlist),
-												   is_pushed_down,
-												   has_clone,
-												   is_clone,
-												   pseudoconstant,
-												   security_level,
-												   required_relids,
-												   incompatible_relids,
-												   outer_relids);
+		return (Expr *) make_plain_restrictinfo(root,
+												clause,
+												make_orclause(orlist),
+												is_pushed_down,
+												has_clone,
+												is_clone,
+												pseudoconstant,
+												security_level,
+												required_relids,
+												incompatible_relids,
+												outer_relids);
 	}
 	else if (is_andclause(clause))
 	{
@@ -328,17 +319,17 @@ make_sub_restrictinfos(PlannerInfo *root,
 		return make_andclause(andlist);
 	}
 	else
-		return (Expr *) make_restrictinfo_internal(root,
-												   clause,
-												   NULL,
-												   is_pushed_down,
-												   has_clone,
-												   is_clone,
-												   pseudoconstant,
-												   security_level,
-												   required_relids,
-												   incompatible_relids,
-												   outer_relids);
+		return (Expr *) make_plain_restrictinfo(root,
+												clause,
+												NULL,
+												is_pushed_down,
+												has_clone,
+												is_clone,
+												pseudoconstant,
+												security_level,
+												required_relids,
+												incompatible_relids,
+												outer_relids);
 }
 
 /*
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c59..b77bf7ddfe9 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -22,6 +22,17 @@
 	make_restrictinfo(root, clause, true, false, false, false, 0, \
 		NULL, NULL, NULL)
 
+extern RestrictInfo *make_plain_restrictinfo(PlannerInfo *root,
+											 Expr *clause,
+											 Expr *orclause,
+											 bool is_pushed_down,
+											 bool has_clone,
+											 bool is_clone,
+											 bool pseudoconstant,
+											 Index security_level,
+											 Relids required_relids,
+											 Relids incompatible_relids,
+											 Relids outer_relids);
 extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Expr *clause,
 									   bool is_pushed_down,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index e4d117e47ae..58c35030161 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1875,6 +1875,60 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
+                                                                QUERY PLAN                                                                 
+-------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND (tenthous IS NULL)) OR ((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42))))
+   Filter: ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42) OR (tenthous IS NULL))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous IS NULL))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR ((tenthous)::smallint = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+                                                                     QUERY PLAN                                                                      
+-----------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND ((tenthous = '3'::bigint) OR (tenthous = '42'::bigint))) OR ((thousand = 42) AND (tenthous = '1'::smallint)))
+   Filter: ((tenthous = '1'::smallint) OR (tenthous = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{3,42}'::bigint[])))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = '1'::smallint))
+(8 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -2003,25 +2057,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                        
+--------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND (((thousand = 42) OR (thousand = 99)) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2033,22 +2086,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR ((thousand = 42) OR (thousand = 41))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index e76dca7319f..58dabfa7519 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR ((unique1 = 3) OR (unique1 = 1)) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 71a7115067e..a2b73142216 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -738,6 +738,23 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index b6135f03479..5f577ecdaca 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1765,6 +1765,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.39.5 (Apple Git-154)

v40-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchapplication/octet-stream; name=v40-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchDownload
From 6e4169db0634b2de30d931746100d07cdf90ea35 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 23 Sep 2024 14:03:54 +0300
Subject: [PATCH v40 1/2] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is an i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows handling long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 270 +++++++++++++++++++++
 src/test/regress/expected/create_index.out | 270 +++++++++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/expected/rowsecurity.out  |   7 +
 src/test/regress/expected/stats_ext.out    |  12 +
 src/test/regress/expected/uuid.out         |  31 +++
 src/test/regress/sql/create_index.sql      |  69 ++++++
 src/test/regress/sql/join.sql              |   9 +
 src/test/regress/sql/rowsecurity.sql       |   1 +
 src/test/regress/sql/stats_ext.sql         |   3 +
 src/test/regress/sql/uuid.sql              |  12 +
 11 files changed, 722 insertions(+), 19 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..7f930b2a266 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -32,8 +33,10 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "utils/syscache.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -177,6 +180,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2248,6 +2255,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2782,265 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	HeapTuple	opertup;
+	Form_pg_operator operform;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Iterate over OR entries.  Check that each OR entry is of the form:
+	 * (indexkey operator constant) or (constant operator indexkey). Operators
+	 * of all the entries must match.  Constant might be either Const or
+	 * Param.  Exit with NULL on first non-matching entry.  Exit is
+	 * implemented as a break from the loop, which is catched afterwards.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			break;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses can match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			break;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			break;
+
+		/*
+		 * The parameters below must match between sub-rinfo and its parent as
+		 * make_restrictinfo() fills them with the same values, and further
+		 * modifications are also the same for the whole subtree. However,
+		 * still make a sanity check.
+		 */
+		Assert(subRinfo->is_pushed_down == rinfo->is_pushed_down);
+		Assert(subRinfo->is_clone == rinfo->is_clone);
+		Assert(subRinfo->security_level == rinfo->security_level);
+		Assert(bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids));
+		Assert(bms_equal(subRinfo->outer_relids, rinfo->outer_relids));
+
+		/*
+		 * Also, check that required_relids in sub-rinfo is subset of parent's
+		 * required_relids.
+		 */
+		Assert(bms_is_subset(subRinfo->required_relids, rinfo->required_relids));
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			break;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				break;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			break;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			break;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			break;
+
+		/*
+		 * For the first matching qual, save information about operator, type
+		 * and collation.  For the other quals just check the match with the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * Check operator is present in the opfamily, expression collation
+			 * matches index collation.  Also, there must be an array type in
+			 * order to construct an array later.
+			 */
+			if (!IndexCollMatchesExprColl(index->indexcollations[indexcol], inputcollid) ||
+				!op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+				!OidIsValid(arraytype))
+				break;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				break;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	/*
+	 * Catch the break from the loop above.  Normally, a foreach() loop ends up
+	 * with a NULL list cell.  A non-NULL list cell indicates a break from the
+	 * foreach() loop.  Free the consts list and return NULL then.
+	 */
+	if (lc != NULL)
+	{
+		list_free(consts);
+		return NULL;
+	}
+
+	if (have_param)
+	{
+		/*
+		 * We need to construct an ArrayExpr given we have Param's not just
+		 * Const's.
+		 */
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		/*
+		 * We have only Const's.  In this case we can construct an array
+		 * directly.
+		 */
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Lookup for operator to fetch necessary information for the SAOP node */
+	opertup = SearchSysCache1(OPEROID,
+							  ObjectIdGetDatum(matchOpno));
+	if (!HeapTupleIsValid(opertup))
+		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
+
+	operform = (Form_pg_operator) GETSTRUCT(opertup);
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = operform->oprcode;
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	ReleaseSysCache(opertup);
+
+	/*
+	 * Finally build an IndexClause based on the SAOP node.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = rinfo;
+	iclause->indexquals = list_make1(make_simple_restrictinfo(root,
+															  &saopexpr->xpr));
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index d3358dfc394..e4d117e47ae 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,67 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                   QUERY PLAN                                    
+---------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,6 +1913,27 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1872,6 +1942,102 @@ SELECT count(*) FROM tenk1
  Aggregate
    ->  Bitmap Heap Scan on tenk1
          Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand < 42) OR (thousand < 99) OR (43 > thousand) OR (42 > thousand)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                             QUERY PLAN                                              
+-----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,16 +2045,90 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 31fb7d142eb..e76dca7319f 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 319190855bd..ef890b96cc6 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4492,6 +4492,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index fe162cc7c30..71a7115067e 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -732,12 +732,81 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index d81ff63be53..4473b8f04d5 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 3011d71b12b..6d2414b6044 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
-- 
2.39.5 (Apple Git-154)

#243Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alexander Korotkov (#242)
Re: POC, WIP: OR-clause support for indexes

Hi Tom,

On Mon, Sep 23, 2024 at 2:10 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

On Mon, Sep 16, 2024 at 3:44 PM Andrei Lepikhov <lepihov@gmail.com> wrote:

On 9/9/2024 12:36, Alexander Korotkov wrote:

Also, I agree it get it's wrong to directly copy RestrictInfo struct
in group_similar_or_args(). Instead, I've renamed
make_restrictinfo_internal() to make_plain_restrictinfo(), which is
intended to handle non-recursive cases when you've children already
wrapped with RestrictInfos. make_plain_restrictinfo() now used in
group_similar_or_args().

Great work. Thanks for doing this!

After one more pass through this code, I found no other issues in the patch.
Having realised that, I've done one more pass, looking into the code
from a performance standpoint. It looks mostly ok, but In my opinion, in
the cycle:

foreach(lc, orclause->args)
{
}

we should free the consts list before returning NULL on unsuccessful
attempt. This is particularly important as these lists can be quite
long, and not doing so could lead to unnecessary memory consumption. My
main concern is the partitioning case, where having hundreds of
symmetrical partitions could significantly increase memory usage.

Makes sense. Please, check the attached patch freeing the consts list
while returning NULL from match_orclause_to_indexcol().

I think this patchset got much better, and it could possible be
committed after another round of cleanup and comment/docs improvement.
It would be very kind if you share your view on the decisions made in
this patchset.

------
Regards,
Alexander Korotkov
Supabase

#244Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#243)
Re: POC, WIP: OR-clause support for indexes

On 1/10/2024 12:25, Alexander Korotkov wrote:

I think this patchset got much better, and it could possible be
committed after another round of cleanup and comment/docs improvement.
It would be very kind if you share your view on the decisions made in
this patchset.

I went through the code one more time. It is awesome how the initial
idea has changed. Now, it really is a big deal—thanks for your
inspiration on where to apply this transformation.
As I see it, it helps to avoid the linear growth of execution time for
BitmapOr paths. Also, it opens up room for further improvements related
to OR-clauses alternative groupings and (maybe it is an enterprise-grade
feature) removing duplicated constants from the array.

--
regards, Andrei Lepikhov

In reply to: Alexander Korotkov (#243)
Re: POC, WIP: OR-clause support for indexes

On Tue, Oct 1, 2024 at 6:25 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

I think this patchset got much better, and it could possible be
committed after another round of cleanup and comment/docs improvement.
It would be very kind if you share your view on the decisions made in
this patchset.

I do think that this patch got a lot better, and simpler, but I'm a
little worried about it not covering cases that are only very slightly
different to the ones that you're targeting. It's easiest to see what
I mean using an example.

After the standard regression tests have run, the following tests can
be run from psql (this uses the recent v40 revision):

pg@regression:5432 =# create index on tenk1(four, ten); -- setup
CREATE INDEX

Very fast INT_MAX query, since we successful use the transformation
added by the patch:

pg@regression:5432 =# explain (analyze,buffers) select * from tenk1
where four = 1 or four = 2_147_483_647 order by four, ten limit 5;
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ QUERY
PLAN │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Limit (cost=0.29..1.73 rows=5 width=244) (actual time=0.011..0.014
rows=5 loops=1) │
│ Buffers: shared hit=4

│ -> Index Scan using tenk1_four_ten_idx on tenk1
(cost=0.29..721.25 rows=2500 width=244) (actual time=0.011..0.012
rows=5 loops=1) │
│ Index Cond: (four = ANY ('{1,2147483647}'::integer[]))

│ Index Searches: 1

│ Buffers: shared hit=4

│ Planning Time: 0.067 ms

│ Execution Time: 0.022 ms

└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(8 rows)

Much slower query, which is not capable of applying the transformation
due only to
the fact that I've "inadvertently" mixed together multiple types (int4
and int8):

pg@regression:5432 =# explain (analyze,buffers) select * from tenk1
where four = 1 or four = 2_147_483_648 order by four, ten limit 5;
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ QUERY
PLAN │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Limit (cost=0.29..2.08 rows=5 width=244) (actual time=0.586..0.588
rows=5 loops=1) │
│ Buffers: shared hit=1368

│ -> Index Scan using tenk1_four_ten_idx on tenk1
(cost=0.29..900.25 rows=2500 width=244) (actual time=0.586..0.587
rows=5 loops=1) │
│ Index Searches: 1

│ Filter: ((four = 1) OR (four = '2147483648'::bigint))

│ Rows Removed by Filter: 2500

│ Buffers: shared hit=1368

│ Planning Time: 0.050 ms

│ Execution Time: 0.595 ms

└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(9 rows)

Do you think this problem can be fixed easily? This behavior seems
surprising, and is best avoided. Performance cliffs that happen when
we tweak one detail of a query just seem worth avoiding on general
principle.

Now that you're explicitly creating RestrictInfos for a particular
index, I suppose that it might be easier to do this kind of thing --
you have more context. Perhaps the patch can be made to recognize
a mix of constants like this as all being associated with the same
B-Tree operator family (the opfamily that the input opclass belongs
to)? Perhaps the constants could all be normalized to the same type via
casts/coercions into the underlying B-Tree input opclass -- that
extra step should be correct ("64.1.2. Behavior of B-Tree Operator Classes"
describes certain existing guarantees that this step would need to rely
on).

Note that the patch already works in cross-type scenarios, with
cross-type operators. The issue I've highlighted is caused by the use
of a mixture of types among the constants themselves -- the patch
wants an array with elements that are all of the same type, which it
can't quite manage. And so I can come up with a cross-type variant
query that *can* still use a SAOP as expected with v40, despite
involving a cross-type = btree operator:

pg@regression:5432 [2181876]=# explain (analyze,buffers) select * from
tenk1 where four = 2_147_483_648 or four = 2_147_483_649 order by
four, ten limit 5;
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ QUERY
PLAN │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Limit (cost=0.29..6.53 rows=1 width=244) (actual time=0.004..0.005
rows=0 loops=1) │
│ Buffers: shared hit=2

│ -> Index Scan using tenk1_four_ten_idx on tenk1 (cost=0.29..6.53
rows=1 width=244) (actual time=0.004..0.004 rows=0 loops=1) │
│ Index Cond: (four = ANY
('{2147483648,2147483649}'::bigint[]))

│ Index Searches: 1

│ Buffers: shared hit=2

│ Planning Time: 0.044 ms

│ Execution Time: 0.011 ms

└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(8 rows)

The fact that this third and final example works as expected makes me
even more convinced that the second example should behave similarly.

--
Peter Geoghegan

#246Andrei Lepikhov
lepihov@gmail.com
In reply to: Peter Geoghegan (#245)
Re: POC, WIP: OR-clause support for indexes

On 10/4/24 03:15, Peter Geoghegan wrote:

On Tue, Oct 1, 2024 at 6:25 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

I think this patchset got much better, and it could possible be
committed after another round of cleanup and comment/docs improvement.
It would be very kind if you share your view on the decisions made in
this patchset.

Let me provide a standpoint to help Alexander.

The origin reason was - to avoid multiple BitmapOr, which has some
effects at the planning stage (memory consumption, planning time) and
execution (execution time growth). IndexScan also works better with a
single array (especially a hashed one) than with a long list of clauses.
Another reason is that by spending some time identifying common operator
family and variable-side clause equality, we open a way for future cheap
improvements like removing duplicated constants.
Who knows, maybe we will be capable of using this code to improve
cardinality estimations.

According to your proposal, we have had such casting to the common type
in previous versions. Here, we avoid it intentionally: the general idea
is about long lists of constants, and such casting causes questions
about performance. Do I want it in the core? Yes, I do! But may we
implement it a bit later to have time to probe the general method and
see how it flies?

--
regards, Andrei Lepikhov

#247Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Peter Geoghegan (#245)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 03.10.2024 23:15, Peter Geoghegan wrote:

I do think that this patch got a lot better, and simpler, but I'm a
little worried about it not covering cases that are only very slightly
different to the ones that you're targeting. It's easiest to see what
I mean using an example.

After the standard regression tests have run, the following tests can
be run from psql (this uses the recent v40 revision):

pg@regression:5432 =# create index on tenk1(four, ten); -- setup
CREATE INDEX

Very fast INT_MAX query, since we successful use the transformation
added by the patch:

pg@regression:5432 =# explain (analyze,buffers) select * from tenk1
where four = 1 or four = 2_147_483_647 order by four, ten limit 5;
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ QUERY
PLAN │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Limit (cost=0.29..1.73 rows=5 width=244) (actual time=0.011..0.014
rows=5 loops=1) │
│ Buffers: shared hit=4

│ -> Index Scan using tenk1_four_ten_idx on tenk1
(cost=0.29..721.25 rows=2500 width=244) (actual time=0.011..0.012
rows=5 loops=1) │
│ Index Cond: (four = ANY ('{1,2147483647}'::integer[]))

│ Index Searches: 1

│ Buffers: shared hit=4

│ Planning Time: 0.067 ms

│ Execution Time: 0.022 ms

└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(8 rows)

Much slower query, which is not capable of applying the transformation
due only to
the fact that I've "inadvertently" mixed together multiple types (int4
and int8):

pg@regression:5432 =# explain (analyze,buffers) select * from tenk1
where four = 1 or four = 2_147_483_648 order by four, ten limit 5;
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ QUERY
PLAN │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Limit (cost=0.29..2.08 rows=5 width=244) (actual time=0.586..0.588
rows=5 loops=1) │
│ Buffers: shared hit=1368

│ -> Index Scan using tenk1_four_ten_idx on tenk1
(cost=0.29..900.25 rows=2500 width=244) (actual time=0.586..0.587
rows=5 loops=1) │
│ Index Searches: 1

│ Filter: ((four = 1) OR (four = '2147483648'::bigint))

│ Rows Removed by Filter: 2500

│ Buffers: shared hit=1368

│ Planning Time: 0.050 ms

│ Execution Time: 0.595 ms

└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(9 rows)

Do you think this problem can be fixed easily? This behavior seems
surprising, and is best avoided. Performance cliffs that happen when
we tweak one detail of a query just seem worth avoiding on general
principle.

Now that you're explicitly creating RestrictInfos for a particular
index, I suppose that it might be easier to do this kind of thing --
you have more context. Perhaps the patch can be made to recognize
a mix of constants like this as all being associated with the same
B-Tree operator family (the opfamily that the input opclass belongs
to)? Perhaps the constants could all be normalized to the same type via
casts/coercions into the underlying B-Tree input opclass -- that
extra step should be correct ("64.1.2. Behavior of B-Tree Operator Classes"
describes certain existing guarantees that this step would need to rely
on).

Note that the patch already works in cross-type scenarios, with
cross-type operators. The issue I've highlighted is caused by the use
of a mixture of types among the constants themselves -- the patch
wants an array with elements that are all of the same type, which it
can't quite manage. And so I can come up with a cross-type variant
query that *can* still use a SAOP as expected with v40, despite
involving a cross-type = btree operator:

pg@regression:5432 [2181876]=# explain (analyze,buffers) select * from
tenk1 where four = 2_147_483_648 or four = 2_147_483_649 order by
four, ten limit 5;
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ QUERY
PLAN │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Limit (cost=0.29..6.53 rows=1 width=244) (actual time=0.004..0.005
rows=0 loops=1) │
│ Buffers: shared hit=2

│ -> Index Scan using tenk1_four_ten_idx on tenk1 (cost=0.29..6.53
rows=1 width=244) (actual time=0.004..0.004 rows=0 loops=1) │
│ Index Cond: (four = ANY
('{2147483648,2147483649}'::bigint[]))

│ Index Searches: 1

│ Buffers: shared hit=2

│ Planning Time: 0.044 ms

│ Execution Time: 0.011 ms

└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(8 rows)

The fact that this third and final example works as expected makes me
even more convinced that the second example should behave similarly.

Yes, I agree with you that it should be added in the feature but in the
future thread.

The patch does not solve all the problems we planned for, as the
previous patch did (discussed here [0]/messages/by-id/CAPpHfdvF864n=Lzmjd2XBi9TwboZvrhRtLSt2hCP+JVUv6XKzg@mail.gmail.com), but it also does not cause the
performance problems that
were associated with building a suboptimal plan.

Furthermore I think this issue, like the one noted here [0]/messages/by-id/CAPpHfdvF864n=Lzmjd2XBi9TwboZvrhRtLSt2hCP+JVUv6XKzg@mail.gmail.com, can be
fixed in a way I proposed before [1]/messages/by-id/985f2924-9769-4927-ad6e-d430c394054d@postgrespro.ru, but I assume it is better resolved
in the next thread related to the patch.

[0]: /messages/by-id/CAPpHfdvF864n=Lzmjd2XBi9TwboZvrhRtLSt2hCP+JVUv6XKzg@mail.gmail.com
/messages/by-id/CAPpHfdvF864n=Lzmjd2XBi9TwboZvrhRtLSt2hCP+JVUv6XKzg@mail.gmail.com

[1]: /messages/by-id/985f2924-9769-4927-ad6e-d430c394054d@postgrespro.ru
/messages/by-id/985f2924-9769-4927-ad6e-d430c394054d@postgrespro.ru

--
Regards,
Alena Rybakina
Postgres Professional

#248Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#246)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 4, 2024 at 6:31 AM Andrei Lepikhov <lepihov@gmail.com> wrote:

On 10/4/24 03:15, Peter Geoghegan wrote:

On Tue, Oct 1, 2024 at 6:25 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

I think this patchset got much better, and it could possible be
committed after another round of cleanup and comment/docs improvement.
It would be very kind if you share your view on the decisions made in
this patchset.

Let me provide a standpoint to help Alexander.

The origin reason was - to avoid multiple BitmapOr, which has some
effects at the planning stage (memory consumption, planning time) and
execution (execution time growth). IndexScan also works better with a
single array (especially a hashed one) than with a long list of clauses.
Another reason is that by spending some time identifying common operator
family and variable-side clause equality, we open a way for future cheap
improvements like removing duplicated constants.
Who knows, maybe we will be capable of using this code to improve
cardinality estimations.

According to your proposal, we have had such casting to the common type
in previous versions. Here, we avoid it intentionally: the general idea
is about long lists of constants, and such casting causes questions
about performance. Do I want it in the core? Yes, I do! But may we
implement it a bit later to have time to probe the general method and
see how it flies?

Andrei, thank you for your opinion. Just for the record, I'm still
exploring this and will reply later today or tomorrow.

------
Regards,
Alexander Korotkov
Supabase

#249Robert Haas
robertmhaas@gmail.com
In reply to: Peter Geoghegan (#245)
Re: POC, WIP: OR-clause support for indexes

On Thu, Oct 3, 2024 at 4:15 PM Peter Geoghegan <pg@bowt.ie> wrote:

Now that you're explicitly creating RestrictInfos for a particular
index, I suppose that it might be easier to do this kind of thing --
you have more context. Perhaps the patch can be made to recognize
a mix of constants like this as all being associated with the same
B-Tree operator family (the opfamily that the input opclass belongs
to)? Perhaps the constants could all be normalized to the same type via
casts/coercions into the underlying B-Tree input opclass -- that
extra step should be correct ("64.1.2. Behavior of B-Tree Operator Classes"
describes certain existing guarantees that this step would need to rely
on).

I don't think you can convert everything to the same type because we
have to assume that type conversions can fail. An exception is if the
types are binary-compatible but that's not the case here. If there's a
way to fix this problem, it's probably by doing the first thing you
suggest above: noticing that all the constants belong to the same
opfamily. I'm not sure if that approach can work either, but I think
it has better chances.

Personally, I don't think this particular limitation is a problem. I
don't think it will be terribly frequent in practice, and it doesn't
seem any weirder than any of the other things that happen as a result
of small and large integer constants being differently typed.

--
Robert Haas
EDB: http://www.enterprisedb.com

#250Robert Haas
robertmhaas@gmail.com
In reply to: Alexander Korotkov (#242)
Re: POC, WIP: OR-clause support for indexes

On Mon, Sep 23, 2024 at 7:11 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

Makes sense. Please, check the attached patch freeing the consts list
while returning NULL from match_orclause_to_indexcol().

Some review comments:

I agree with the comments already given to the effect that the patch
looks much better now. I was initially surprised to see this happening
in match_clause_to_indexcol() but after studying it I think it looks
like the right place. I think it makes sense to think about moving
forward with this, although it would be nice to get Tom's take if we
can.

I see that the patch makes no update to the header comment for
match_clause_to_indexcol() nor to the comment just above the cascade
of if-statements. I think both need to be updated.

More generally, many of the comments in this patch seem to just
explain what the code does, and I'd like to reiterate my usual
complaint: as far as possible, comments should explain WHY the code
does what it does. Certainly, in some cases there's nothing to be said
about that e.g. /* Lookup for operator to fetch necessary information
for the SAOP node */ isn't really saying anything non-obvious but it's
reasonable to have the comment here anyway. However, when there is
something more interesting to be said, then we should do that rather
than just reiterate what the reader who knows C can anyway see. For
instance, the lengthy comment beginning with "Iterate over OR
entries." could either be shorter and recapitulate less of the code
that follows, or it could say something more interesting about why
we're doing it like that.

+ /* We allow constant to be Const or Param */
+ if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+ break;

This restriction is a lot tighter than the one mentioned in the header
comment of match_clause_to_indexcol ("Our definition of const is
exceedingly liberal"). If there's a reason for that, the comments
should talk about it. If there isn't, it's better to be consistent.

 + /*
+ * Check operator is present in the opfamily, expression collation
+ * matches index collation.  Also, there must be an array type in
+ * order to construct an array later.
+ */
+ if (!IndexCollMatchesExprColl(index->indexcollations[indexcol],
inputcollid) ||
+ !op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+ !OidIsValid(arraytype))
+ break;

I spent some time wondering whether this was safe. The
IndexCollMatchesExprColl() guarantees that either the input collation
is equal to the index collation, or the index collation is 0. If the
index collation is 0 then that I *think* that guarantees that the
indexed type is non-collatable, but this could be a cross-type
comparison, and it's possible that the other type is collatable. In
that case, I don't think anything would prevent us from merging a
bunch of OR clauses with different collations into a single SAOP. I
don't really see how that could be a problem, because if the index is
of a non-collatable type, then presumably the operator doesn't care
about what the collation is, so it should all be fine, I guess? But
I'm not very confident about that conclusion.

I'm unclear what the current thinking is about the performance of this
patch, both as to planning and as to execution. Do we believe that
this transformation is a categorical win at execution-time? In theory,
OR format alllows for short-circuit execution, but because of the
Const-or-Param restriction above, I don't think that's mostly a
non-issue. But maybe not completely, because I can see from the
regression test changes that it's possible for us to apply this
transformation when the Param is set by an InitPlan or SubPlan. If we
have something like WHERE tenthous = 1 OR tenthous =
(very_expensive_computation() + 1), maybe the patch could lose,
because we'll have to do the very expensive calculation to evaluate
the SAOP, and the OR could stop as soon as we establish that tenthous
!= 1. If we only did the transformation when the Param is an external
parameter, then we wouldn't have this issue. Maybe this isn't worth
worrying about; I'm not sure. Are there any other cases where the
transformation can produce something that executes more slowly?

As far as planning time is concerned, I don't think this is going to
be too bad, because most of the work only needs to be done if there
are OR-clauses, and my intuition is that the optimization will often
apply in such cases, so it seems alright. But I wonder how much
testing has been done of adversarial cases, e.g. lots of non-indexable
clause in the query; or lots of OR clauses in the query but all of
them turn out on inspection to be non-indexable. My expectation would
be that there's no real problem here, but it would be good to verify
that experimentally.

--
Robert Haas
EDB: http://www.enterprisedb.com

In reply to: Robert Haas (#249)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 4, 2024 at 8:31 AM Robert Haas <robertmhaas@gmail.com> wrote:

Personally, I don't think this particular limitation is a problem. I
don't think it will be terribly frequent in practice, and it doesn't
seem any weirder than any of the other things that happen as a result
of small and large integer constants being differently typed.

While it's not enough of a problem to hold up the patch, the behavior
demonstrated by my test case does seem worse than what happens as a
result of mixing integer constants in other, comparable contexts. That
was the basis of my concern, really.

The existing IN() syntax somehow manages to produce a useful bigint[]
SAOP when I use the same mix of integer types/constants that were used
for my original test case from yesterday:

pg@regression:5432 =# explain (analyze,buffers) select * from tenk1
where four in (1, 2_147_483_648) order by four, ten limit 5;
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ QUERY
PLAN │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Limit (cost=0.29..1.73 rows=5 width=244) (actual time=0.009..0.010
rows=5 loops=1) │
│ Buffers: shared hit=4

│ -> Index Scan using tenk1_four_ten_idx on tenk1
(cost=0.29..721.25 rows=2500 width=244) (actual time=0.008..0.009
rows=5 loops=1) │
│ Index Cond: (four = ANY ('{1,2147483648}'::bigint[]))

│ Index Searches: 1

│ Buffers: shared hit=4

│ Planning Time: 0.046 ms

│ Execution Time: 0.017 ms

└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(8 rows)

--
Peter Geoghegan

#252Robert Haas
robertmhaas@gmail.com
In reply to: Peter Geoghegan (#251)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 4, 2024 at 10:20 AM Peter Geoghegan <pg@bowt.ie> wrote:

The existing IN() syntax somehow manages to produce a useful bigint[]
SAOP when I use the same mix of integer types/constants that were used
for my original test case from yesterday:

Interesting. I would not have guessed that. I wonder how it works.

--
Robert Haas
EDB: http://www.enterprisedb.com

In reply to: Andrei Lepikhov (#246)
Re: POC, WIP: OR-clause support for indexes

On Thu, Oct 3, 2024 at 11:31 PM Andrei Lepikhov <lepihov@gmail.com> wrote:

The origin reason was - to avoid multiple BitmapOr, which has some
effects at the planning stage (memory consumption, planning time) and
execution (execution time growth). IndexScan also works better with a
single array (especially a hashed one) than with a long list of clauses.

I understand that that was the original goal. But I think that
preserving ordered index scans by using a SAOP (not filter quals and
not a BitmapOr) is actually the more important reason to have this
patch. It allows the OR syntax to be used in a way that preserves
crucial context.

I'm not really trying to add new requirements for this patch. The case
I highlighted wasn't a particularly tricky one. It's a case that the
existing IN() syntax somehow manages to produce a useful SAOP for. It
would be nice to get that part right.

Another reason is that by spending some time identifying common operator
family and variable-side clause equality, we open a way for future cheap
improvements like removing duplicated constants.

I don't think that removing duplicated constants is all that
important, since we already do that during execution proper. The
nbtree code does this in _bt_preprocess_array_keys. It even does
things like merge together a pair of duplicate SAOPs against the same
column. It doesn't matter if the arrays are of different types,
either.

It doesn't look like index AMs lacking native support for SAOPs can do
stuff like that right now. It could be implemented by sorting and
deduplicating the IndexArrayKeyInfo.elem_values[] array in the same
way as nbtree.

--
Peter Geoghegan

In reply to: Robert Haas (#252)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 4, 2024 at 10:24 AM Robert Haas <robertmhaas@gmail.com> wrote:

Interesting. I would not have guessed that. I wonder how it works.

ISTM that we've established a general expectation that you as a user
can be fairly imprecise about which specific types you use as
constants in your query, while still getting an index scan (provided
all of the types involved have opclasses that are part of the same
opfamily, and that the index uses one of those opclasses as its input
opclass). Imagine how confusing it would be if "SELECT * FROM
pgbench_accounts WHERE aid = 5" didn't get an index scan whenever the
"aid" column happened to be bigint -- that would be totally
unacceptable. The main reason why we have operator classes that are
grouped into opfamilies is to allow the optimizer to understand the
relationship between opclasses sufficient to enable this flexibility.

It's concerning that there's a performance cliff with the patch
whenever one of the constants is changed from (say) 2_147_483_647 to
2_147_483_648 -- who will even notice that they've actually mixed two
different types of integers here? Users certainly won't see any
similar problems in the simple "Var = Const" case, nor will they see
problems in the mixed-type IN() list case.

--
Peter Geoghegan

In reply to: Alexander Korotkov (#248)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 4, 2024 at 7:45 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

Andrei, thank you for your opinion. Just for the record, I'm still
exploring this and will reply later today or tomorrow.

The logic that allows this to work for the case of IN() lists appears
in transformAExprIn(), which is in parse_expr.c. I wonder if it would
be possible to do something similar at the point where the patch does
its conversion to a SAOP. What do you think?

The transformAExprIn() logic doesn't directly care about operator
families. It works by using coercions, which opfamily authors are
formally required to promise cannot affect sort order. According to
the sgml docs: "Another requirement for a multiple-data-type family is
that any implicit or binary-coercion casts that are defined between
data types included in the operator family must not change the
associated sort ordering".

This logic seems to always do the right thing for cases like my IN()
test case from today, which should have an array of the type of the
widest integer type from btree/integer_ops (so a bigint[] SAOP for
that specific test case). There won't ever be a "cannot coerce to
common array type" error because logic in select_common_type() aims to
choose a common array type that every individual expression can be
implicitly cast to. It can fail to identify a common type, but AFAICT
only in cases where that actually makes sense.

--
Peter Geoghegan

#256Alexander Korotkov
aekorotkov@gmail.com
In reply to: Peter Geoghegan (#255)
Re: POC, WIP: OR-clause support for indexes

Hi, Peter!

Thank you very much for the feedback on this patch.

On Fri, Oct 4, 2024 at 8:44 PM Peter Geoghegan <pg@bowt.ie> wrote:

On Fri, Oct 4, 2024 at 7:45 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

Andrei, thank you for your opinion. Just for the record, I'm still
exploring this and will reply later today or tomorrow.

The logic that allows this to work for the case of IN() lists appears
in transformAExprIn(), which is in parse_expr.c. I wonder if it would
be possible to do something similar at the point where the patch does
its conversion to a SAOP. What do you think?

Yes, transformAExprIn() does the work to coerce all the expressions in
the right part to the same type. Similar logic could be implemented
in match_orclause_to_indexcol(). What worries me is whether it's
quite late stage for this kind of work. transformAExprIn() works
during parse stage, when we need to to resolve types, operators etc.
And we do that once. If we replicate the same logic to
match_orclause_to_indexcol(), then we may end up with index scan using
one operator and sequential scan using another operator. Given we
only use implicit casts for types coercion those are suppose to be
strong equivalents. And that's for sure true for builtin types and
operators. But isn't it too much to assume the same for all
extensions?

------
Regards,
Alexander Korotkov
Supabase

In reply to: Alexander Korotkov (#256)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 4, 2024 at 2:00 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

Yes, transformAExprIn() does the work to coerce all the expressions in
the right part to the same type. Similar logic could be implemented
in match_orclause_to_indexcol(). What worries me is whether it's
quite late stage for this kind of work. transformAExprIn() works
during parse stage, when we need to to resolve types, operators etc.
And we do that once.

I agree that it would be a bit awkward. Especially having spent so
much time talking about doing this later on, not during parsing. That
doesn't mean that it's necessarily the wrong thing to do, though.

If we replicate the same logic to
match_orclause_to_indexcol(), then we may end up with index scan using
one operator and sequential scan using another operator.

But that's already true today. For example, these two queries use
different operators at runtime, assuming both use a B-Tree index scan:

select * from tenk1 where four = any('{0,1}'::int[]) and four =
any('{1,2}'::bigint[]);

select * from tenk1 where four = any('{1,2}'::bigint[]) and four =
any('{0,1}'::int[]); -- flip the order of the arrays, change nothing
else

This isn't apparent from what EXPLAIN ANALYZE output shows, but the
fact is that only one operator (and one array) will be used at
runtime, after nbtree preprocessing completes. I'm not entirely sure
how this kind of difference might affect a sequential scan. I imagine
that it can use either or both operators unpredictably.

Given we
only use implicit casts for types coercion those are suppose to be
strong equivalents. And that's for sure true for builtin types and
operators. But isn't it too much to assume the same for all
extensions?

Anything is possible. But wouldn't that also mean that the extensions
were broken with the existing IN() list thing, in transformAExprIn()?
What's the difference, fundamentally?

--
Peter Geoghegan

#258Robert Haas
robertmhaas@gmail.com
In reply to: Peter Geoghegan (#257)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 4, 2024 at 2:20 PM Peter Geoghegan <pg@bowt.ie> wrote:

On Fri, Oct 4, 2024 at 2:00 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

Yes, transformAExprIn() does the work to coerce all the expressions in
the right part to the same type. Similar logic could be implemented
in match_orclause_to_indexcol(). What worries me is whether it's
quite late stage for this kind of work. transformAExprIn() works
during parse stage, when we need to to resolve types, operators etc.
And we do that once.

I agree that it would be a bit awkward. Especially having spent so
much time talking about doing this later on, not during parsing. That
doesn't mean that it's necessarily the wrong thing to do, though.

True, but we also can't realistically use select_common_type() here. I
mean, it thinks that we have a ParseState and that there might be
values with type UNKNOWNOID floating around. By the time we reach the
planner, neither thing is true. And honestly, it looks to me like
that's pointing to a deeper problem with your idea. When someone
writes foo IN (1, 2222222222222222222222222), we have to make up our
mind what type of literal each of those is. select_common_type()
allows us to decide that since the second value is big, we're going to
consider both to be literals of type int8. But that is completely
different than the situation this patch faces. We're now much further
down the road; we have already decided that, say, 1, is and int4 and
2222222222222222222222222 is an int8. It's possible to cast a value to
a different type if we don't mind failing or have some principled way
to avoid doing so, but it's way too late to reverse our previous
decision about how to parse the characters the user entered. The
original "char *" value is lost to us and the type OID we picked may
already be stored in the catalogs or something.

--
Robert Haas
EDB: http://www.enterprisedb.com

#259Alexander Korotkov
aekorotkov@gmail.com
In reply to: Peter Geoghegan (#257)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 4, 2024 at 9:20 PM Peter Geoghegan <pg@bowt.ie> wrote:

On Fri, Oct 4, 2024 at 2:00 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

Yes, transformAExprIn() does the work to coerce all the expressions in
the right part to the same type. Similar logic could be implemented
in match_orclause_to_indexcol(). What worries me is whether it's
quite late stage for this kind of work. transformAExprIn() works
during parse stage, when we need to to resolve types, operators etc.
And we do that once.

I agree that it would be a bit awkward. Especially having spent so
much time talking about doing this later on, not during parsing. That
doesn't mean that it's necessarily the wrong thing to do, though.

If we replicate the same logic to
match_orclause_to_indexcol(), then we may end up with index scan using
one operator and sequential scan using another operator.

But that's already true today. For example, these two queries use
different operators at runtime, assuming both use a B-Tree index scan:

select * from tenk1 where four = any('{0,1}'::int[]) and four =
any('{1,2}'::bigint[]);

select * from tenk1 where four = any('{1,2}'::bigint[]) and four =
any('{0,1}'::int[]); -- flip the order of the arrays, change nothing
else

This isn't apparent from what EXPLAIN ANALYZE output shows, but the
fact is that only one operator (and one array) will be used at
runtime, after nbtree preprocessing completes. I'm not entirely sure
how this kind of difference might affect a sequential scan. I imagine
that it can use either or both operators unpredictably.

Yes, but those operators are in the B-tree operator family. That
implies a lot about semantics of those operators making B-tree
legitimate to do such transformations. But it's different story when
you apply it to arbitrary operator and arbitrary implicit cast. I can
imagine implicit casts which could throw errors or loose precision.
It's OK to apply them as soon as user made them implicit. But
applying them in different ways for different optimizer decisions
looks risky.

------
Regards,
Alexander Korotkov
Supabase

#260Alexander Korotkov
aekorotkov@gmail.com
In reply to: Robert Haas (#258)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 4, 2024 at 9:40 PM Robert Haas <robertmhaas@gmail.com> wrote:

On Fri, Oct 4, 2024 at 2:20 PM Peter Geoghegan <pg@bowt.ie> wrote:

On Fri, Oct 4, 2024 at 2:00 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

Yes, transformAExprIn() does the work to coerce all the expressions in
the right part to the same type. Similar logic could be implemented
in match_orclause_to_indexcol(). What worries me is whether it's
quite late stage for this kind of work. transformAExprIn() works
during parse stage, when we need to to resolve types, operators etc.
And we do that once.

I agree that it would be a bit awkward. Especially having spent so
much time talking about doing this later on, not during parsing. That
doesn't mean that it's necessarily the wrong thing to do, though.

True, but we also can't realistically use select_common_type() here. I
mean, it thinks that we have a ParseState and that there might be
values with type UNKNOWNOID floating around. By the time we reach the
planner, neither thing is true. And honestly, it looks to me like
that's pointing to a deeper problem with your idea. When someone
writes foo IN (1, 2222222222222222222222222), we have to make up our
mind what type of literal each of those is. select_common_type()
allows us to decide that since the second value is big, we're going to
consider both to be literals of type int8. But that is completely
different than the situation this patch faces. We're now much further
down the road; we have already decided that, say, 1, is and int4 and
2222222222222222222222222 is an int8. It's possible to cast a value to
a different type if we don't mind failing or have some principled way
to avoid doing so, but it's way too late to reverse our previous
decision about how to parse the characters the user entered. The
original "char *" value is lost to us and the type OID we picked may
already be stored in the catalogs or something.

+1

------
Regards,
Alexander Korotkov
Supabase

#261Alexander Korotkov
aekorotkov@gmail.com
In reply to: Robert Haas (#250)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 4, 2024 at 4:34 PM Robert Haas <robertmhaas@gmail.com> wrote:

On Mon, Sep 23, 2024 at 7:11 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

Makes sense. Please, check the attached patch freeing the consts list
while returning NULL from match_orclause_to_indexcol().

Some review comments:

I agree with the comments already given to the effect that the patch
looks much better now. I was initially surprised to see this happening
in match_clause_to_indexcol() but after studying it I think it looks
like the right place. I think it makes sense to think about moving
forward with this, although it would be nice to get Tom's take if we
can.

I see that the patch makes no update to the header comment for
match_clause_to_indexcol() nor to the comment just above the cascade
of if-statements. I think both need to be updated.

More generally, many of the comments in this patch seem to just
explain what the code does, and I'd like to reiterate my usual
complaint: as far as possible, comments should explain WHY the code
does what it does. Certainly, in some cases there's nothing to be said
about that e.g. /* Lookup for operator to fetch necessary information
for the SAOP node */ isn't really saying anything non-obvious but it's
reasonable to have the comment here anyway. However, when there is
something more interesting to be said, then we should do that rather
than just reiterate what the reader who knows C can anyway see. For
instance, the lengthy comment beginning with "Iterate over OR
entries." could either be shorter and recapitulate less of the code
that follows, or it could say something more interesting about why
we're doing it like that.

+ /* We allow constant to be Const or Param */
+ if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+ break;

This restriction is a lot tighter than the one mentioned in the header
comment of match_clause_to_indexcol ("Our definition of const is
exceedingly liberal"). If there's a reason for that, the comments
should talk about it. If there isn't, it's better to be consistent.

+ /*
+ * Check operator is present in the opfamily, expression collation
+ * matches index collation.  Also, there must be an array type in
+ * order to construct an array later.
+ */
+ if (!IndexCollMatchesExprColl(index->indexcollations[indexcol],
inputcollid) ||
+ !op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+ !OidIsValid(arraytype))
+ break;

I spent some time wondering whether this was safe. The
IndexCollMatchesExprColl() guarantees that either the input collation
is equal to the index collation, or the index collation is 0. If the
index collation is 0 then that I *think* that guarantees that the
indexed type is non-collatable, but this could be a cross-type
comparison, and it's possible that the other type is collatable. In
that case, I don't think anything would prevent us from merging a
bunch of OR clauses with different collations into a single SAOP. I
don't really see how that could be a problem, because if the index is
of a non-collatable type, then presumably the operator doesn't care
about what the collation is, so it should all be fine, I guess? But
I'm not very confident about that conclusion.

I'm unclear what the current thinking is about the performance of this
patch, both as to planning and as to execution. Do we believe that
this transformation is a categorical win at execution-time? In theory,
OR format alllows for short-circuit execution, but because of the
Const-or-Param restriction above, I don't think that's mostly a
non-issue. But maybe not completely, because I can see from the
regression test changes that it's possible for us to apply this
transformation when the Param is set by an InitPlan or SubPlan. If we
have something like WHERE tenthous = 1 OR tenthous =
(very_expensive_computation() + 1), maybe the patch could lose,
because we'll have to do the very expensive calculation to evaluate
the SAOP, and the OR could stop as soon as we establish that tenthous
!= 1. If we only did the transformation when the Param is an external
parameter, then we wouldn't have this issue. Maybe this isn't worth
worrying about; I'm not sure. Are there any other cases where the
transformation can produce something that executes more slowly?

As far as planning time is concerned, I don't think this is going to
be too bad, because most of the work only needs to be done if there
are OR-clauses, and my intuition is that the optimization will often
apply in such cases, so it seems alright. But I wonder how much
testing has been done of adversarial cases, e.g. lots of non-indexable
clause in the query; or lots of OR clauses in the query but all of
them turn out on inspection to be non-indexable. My expectation would
be that there's no real problem here, but it would be good to verify
that experimentally.

Thank you so much for the review. I'm planning to work on all these
items next week.

------
Regards,
Alexander Korotkov
Supabase

#262jian he
jian.universality@gmail.com
In reply to: Alexander Korotkov (#261)
Re: POC, WIP: OR-clause support for indexes

assume v40 is the latest version.
in group_similar_or_args
we can add a bool variable so

bool matched = false;
foreach(lc, orargs)
{
if (match_index_to_operand(nonConstExpr, colnum, index))
{
matches[i].indexnum = indexnum;
matches[i].colnum = colnum;
matches[i].opno = opno;
matches[i].inputcollid = clause->inputcollid;
matched = true;
break;
}
}
...
if (!matched)
return orargs;
/* Sort clauses to make similar clauses go together */
qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
....

I guess it can save some cycles?

In reply to: Robert Haas (#258)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 4, 2024 at 2:40 PM Robert Haas <robertmhaas@gmail.com> wrote:

On Fri, Oct 4, 2024 at 2:20 PM Peter Geoghegan <pg@bowt.ie> wrote:

On Fri, Oct 4, 2024 at 2:00 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

Yes, transformAExprIn() does the work to coerce all the expressions in
the right part to the same type. Similar logic could be implemented
in match_orclause_to_indexcol(). What worries me is whether it's
quite late stage for this kind of work. transformAExprIn() works
during parse stage, when we need to to resolve types, operators etc.
And we do that once.

I agree that it would be a bit awkward. Especially having spent so
much time talking about doing this later on, not during parsing. That
doesn't mean that it's necessarily the wrong thing to do, though.

True, but we also can't realistically use select_common_type() here. I
mean, it thinks that we have a ParseState and that there might be
values with type UNKNOWNOID floating around. By the time we reach the
planner, neither thing is true. And honestly, it looks to me like
that's pointing to a deeper problem with your idea.

OK.

To be clear, I don't think that it's essential that we have equivalent
behavior in those cases where the patch applies its transformations. I
have no objections to committing the patch without any handling for
that. It's an important patch, and I really want it to get into 18 in
a form that everybody can live with.

--
Peter Geoghegan

#264Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Geoghegan (#263)
Re: POC, WIP: OR-clause support for indexes

Peter Geoghegan <pg@bowt.ie> writes:

To be clear, I don't think that it's essential that we have equivalent
behavior in those cases where the patch applies its transformations. I
have no objections to committing the patch without any handling for
that.

Oy. I don't agree with that *at all*. An "optimization" that changes
query semantics is going to be widely seen as a bug.

regards, tom lane

In reply to: Tom Lane (#264)
Re: POC, WIP: OR-clause support for indexes

On Mon, Oct 7, 2024 at 12:02 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Oy. I don't agree with that *at all*. An "optimization" that changes
query semantics is going to be widely seen as a bug.

I don't believe that I said otherwise?

It's just rather unclear what query semantics really mean here, in
detail. At least to me. But it's obvious that (for example) it would
not be acceptable if a cast were to visibly fail, where that hadn't
happened before.

--
Peter Geoghegan

In reply to: Tom Lane (#264)
Re: POC, WIP: OR-clause support for indexes

On Mon, Oct 7, 2024 at 12:02 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Peter Geoghegan <pg@bowt.ie> writes:

To be clear, I don't think that it's essential that we have equivalent
behavior in those cases where the patch applies its transformations. I
have no objections to committing the patch without any handling for
that.

Oy. I don't agree with that *at all*. An "optimization" that changes
query semantics is going to be widely seen as a bug.

I think that you must have misinterpreted what I meant by "equivalent
behavior". The context was important. I really meant: "Ideally, the
patch's transformations would produce an equivalent execution strategy
to what we already get in when IN() is used directly, *even in the
presence of constants of mixed though related types*. Ideally, the
final patch would somehow be able to generate a SAOP with one array of
the same common type in cases where an analogous IN() query can do the
same. But I'm not going to insist on adding something for that now."

Importantly, I meant equivalent outcome in terms of execution
strategy, across similar queries where the patch sometimes succeeds in
generating a SAOP, and sometimes fails -- I wasn't trying to say
anything about query semantics. This wasn't intended to be a rigorous
argument (if it was then I'd have explained why my detailed and
rigorous proposal didn't break query semantics).

--
Peter Geoghegan

#267Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#264)
Re: POC, WIP: OR-clause support for indexes

On Mon, Oct 7, 2024 at 12:02 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Peter Geoghegan <pg@bowt.ie> writes:

To be clear, I don't think that it's essential that we have equivalent
behavior in those cases where the patch applies its transformations. I
have no objections to committing the patch without any handling for
that.

Oy. I don't agree with that *at all*. An "optimization" that changes
query semantics is going to be widely seen as a bug.

I think everyone agrees on that. The issue is that I don't know how to
implement the optimization Peter wants without changing the query
semantics, and it seems like Alexander doesn't either. By committing
the patch without that optimization, we're *avoiding* changing the
query semantics.

--
Robert Haas
EDB: http://www.enterprisedb.com

#268jian he
jian.universality@gmail.com
In reply to: jian he (#262)
Re: POC, WIP: OR-clause support for indexes

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
?

#269Alexander Korotkov
aekorotkov@gmail.com
In reply to: jian he (#268)
Re: POC, WIP: OR-clause support for indexes

Hi, Jian!

Thank you for your feedback.

On Tue, Oct 8, 2024 at 8:12 AM jian he <jian.universality@gmail.com> wrote:

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.

Some of other_clauses could match to some index column. So, the
splitcost could be lower than jointcost. Please check [1] test case,
but not it misses t_b_c_idx. So the correct full script is following.

create table t (a int not null, b int not null, c int not null);
insert into t (select 1, 1, i from generate_series(1,10000) i);
insert into t (select i, 2, 2 from generate_series(1,10000) i);
create index t_a_b_idx on t (a, b);
create index t_b_c_idx on t (b, c);
create statistics t_a_b_stat (mcv) on a, b from t;
create statistics t_b_c_stat (mcv) on b, c from t;
vacuum analyze t;
explain select * from t where a = 1 and (b = 1 or b = 2) and c = 2;

Also, note its possible that splitlist != NULL, but jointlist == NULL.
Check [2] for example.

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.

If other_clauses is NIL, we could probably do a shortcut when
jointlist != NULL. At least, I don't see the case why would we need
jointlist in this case at the first glance. Will investigate that
futher.

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
?

Indeed, the regression test coverage is lacking. Your feedback is valuable.

Links.
1. /messages/by-id/CAPpHfdtSXxhdv3mLOLjEewGeXJ+Ftfhjqodn1WWuq5JLsKx48g@mail.gmail.com
2. /messages/by-id/CAPpHfduJtO0s9E=SHUTzrCD88BH0eik0UNog1_q3XBF2wLmH6g@mail.gmail.com

------
Regards,
Alexander Korotkov
Supabase

#270Alexander Korotkov
aekorotkov@gmail.com
In reply to: jian he (#262)
Re: POC, WIP: OR-clause support for indexes

On Mon, Oct 7, 2024 at 5:06 PM jian he <jian.universality@gmail.com> wrote:

assume v40 is the latest version.
in group_similar_or_args
we can add a bool variable so

bool matched = false;
foreach(lc, orargs)
{
if (match_index_to_operand(nonConstExpr, colnum, index))
{
matches[i].indexnum = indexnum;
matches[i].colnum = colnum;
matches[i].opno = opno;
matches[i].inputcollid = clause->inputcollid;
matched = true;
break;
}
}
...
if (!matched)
return orargs;
/* Sort clauses to make similar clauses go together */
qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
....

I guess it can save some cycles?

Do you mean we can quit early if no clause matches no index? Sounds
reasonable, will do.

One other thing that I noticed is "if (matches[i].indexnum >= 0)"
check is one level inner than it should be. That will be fixed in the
next revision of patch.

------
Regards,
Alexander Korotkov
Supabase

#271Andrei Lepikhov
lepihov@gmail.com
In reply to: Peter Geoghegan (#253)
Re: POC, WIP: OR-clause support for indexes

On 10/4/24 22:00, Peter Geoghegan wrote:

I don't think that removing duplicated constants is all that
important, since we already do that during execution proper. The
nbtree code does this in _bt_preprocess_array_keys. It even does
things like merge together a pair of duplicate SAOPs against the same
column. It doesn't matter if the arrays are of different types,
either.Hmm, my intention is a bit different - removing duplicates allows us to

estimate selectivity more precisely, right? Maybe it is not enough to be
a core feature, but I continue to think about auto-generated queries and
extensions that can help generate proper plans for queries from AI,
ORM, etc. users.

--
regards, Andrei Lepikhov

#272Andrei Lepikhov
lepihov@gmail.com
In reply to: Robert Haas (#250)
3 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 10/4/24 20:34, Robert Haas wrote:

On Mon, Sep 23, 2024 at 7:11 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

Makes sense. Please, check the attached patch freeing the consts list
while returning NULL from match_orclause_to_indexcol().

More generally, many of the comments in this patch seem to just
explain what the code does, and I'd like to reiterate my usual
complaint: as far as possible, comments should explain WHY the code
does what it does. Certainly, in some cases there's nothing to be said
about that e.g. /* Lookup for operator to fetch necessary information
for the SAOP node */ isn't really saying anything non-obvious but it's
reasonable to have the comment here anyway. However, when there is
something more interesting to be said, then we should do that rather
than just reiterate what the reader who knows C can anyway see. For
instance, the lengthy comment beginning with "Iterate over OR
entries." could either be shorter and recapitulate less of the code
that follows, or it could say something more interesting about why
we're doing it like that.

While I know Alexander is already working on this issue, the variants
provided in the attachment could offer some valuable insights (see 0001
and 0002).

+ /* We allow constant to be Const or Param */
+ if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+ break;

This restriction is a lot tighter than the one mentioned in the header
comment of match_clause_to_indexcol ("Our definition of const is
exceedingly liberal"). If there's a reason for that, the comments
should talk about it. If there isn't, it's better to be consistent.If we know the type of result we don't really need this additional

restriction. The only reason I had here is to avoid some strange and
ineffective cases like:

SELECT oid,typname FROM pg_type t1
WHERE typtypmod = ANY (ARRAY [1, 1+(
SELECT max(typtypmod) FROM pg_type t2
WHERE t1.typtypmod = t2.typtypmod)]);
QUERY PLAN
------------------------------------------------------------
Seq Scan on pg_type t1
Filter: (typtypmod = ANY (ARRAY[1, (1 + (SubPlan 2))]))
SubPlan 2
-> Result
InitPlan 1
-> Limit
-> Seq Scan on pg_type t2
Filter: (t1.typtypmod = typtypmod)

So, it is mostly about trade-off between benefit expected and planning
complexity. See a sketch of comment in 0003.

I'm unclear what the current thinking is about the performance of this
patch, both as to planning and as to execution. Do we believe that
this transformation is a categorical win at execution-time? In theory,
OR format alllows for short-circuit execution, but because of the
Const-or-Param restriction above, I don't think that's mostly a
non-issue. But maybe not completely, because I can see from the
regression test changes that it's possible for us to apply this
transformation when the Param is set by an InitPlan or SubPlan. If we
have something like WHERE tenthous = 1 OR tenthous =
(very_expensive_computation() + 1), maybe the patch could lose,
because we'll have to do the very expensive calculation to evaluate
the SAOP, and the OR could stop as soon as we establish that tenthous
!= 1. If we only did the transformation when the Param is an external
parameter, then we wouldn't have this issue. Maybe this isn't worth
worrying about; I'm not sure. Are there any other cases where the
transformation can produce something that executes more slowly?

I have a couple of user reports in my pocket where changing the position
of the OR clause drastically (2-3 times) altered query execution time.
However, I think it is not a good way to optimise SQL queries the way
we use when coding in C.

--
regards, Andrei Lepikhov

Attachments:

0001-Comments-for-the-0001-patch.patchtext/x-patch; charset=UTF-8; name=0001-Comments-for-the-0001-patch.patchDownload
From ae279c2bef8b0b11739f79b49d68319894c63aa9 Mon Sep 17 00:00:00 2001
From: "Andrei V. Lepikhov" <lepihov@gmail.com>
Date: Wed, 9 Oct 2024 14:05:25 +0700
Subject: [PATCH 1/3] Comments for the 0001 patch

---
 src/backend/optimizer/path/indxpath.c | 52 ++++++++++++++++-----------
 1 file changed, 31 insertions(+), 21 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 46d576a0c2..602141911d 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -2557,6 +2557,10 @@ match_clause_to_index(PlannerInfo *root,
  *	  It is also possible to match ScalarArrayOpExpr clauses to indexes, when
  *	  the clause is of the form "indexkey op ANY (arrayconst)".
  *
+ *	  It is also possible to match a list of OR clauses if it may be transformed
+ *	  into single ScalarArrayOpExpr clause. On success, returning index clause
+ *	  will contain trasformed clause.
+ *
  *	  For boolean indexes, it is also possible to match the clause directly
  *	  to the indexkey; or perhaps the clause is (NOT indexkey).
  *
@@ -3157,6 +3161,10 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
  * match_orclause_to_indexcol()
  *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
  *	  when it could be transformed to ScalarArrayOpExpr.
+ *
+ *	  Given a list of an OR-clause args, attempts to transform this BoolExpr
+ *	  into single SAOP expression. On success, returns IndexClause, containing
+ *	  transformed expression or NULL, if failed.
  */
 static IndexClause *
 match_orclause_to_indexcol(PlannerInfo *root,
@@ -3184,11 +3192,12 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Assert(orclause->boolop == OR_EXPR);
 
 	/*
-	 * Iterate over OR entries.  Check that each OR entry is of the form:
-	 * (indexkey operator constant) or (constant operator indexkey). Operators
-	 * of all the entries must match.  Constant might be either Const or
-	 * Param.  Exit with NULL on first non-matching entry.  Exit is
-	 * implemented as a break from the loop, which is catched afterwards.
+	 * Try to convert list of OR-clauses to single SAOP expression. Each OR
+	 * entry must be in the form: (indexkey operator constant) or (constant
+	 * operator indexkey). Operators of all the entries must match. Constant
+	 * might be either Const or Param. To be effective, give up on first
+	 * non-matching entry. Exit is implemented as a break from the loop, which
+	 * is catched afterwards.
 	 */
 	foreach(lc, orclause->args)
 	{
@@ -3286,8 +3295,8 @@ match_orclause_to_indexcol(PlannerInfo *root,
 			break;
 
 		/*
-		 * For the first matching qual, save information about operator, type
-		 * and collation.  For the other quals just check the match with the
+		 * Save information about the operator, type, and collation for the
+		 * first matching qual. Then, check that subsequent quals match the
 		 * first.
 		 */
 		if (firstTime)
@@ -3298,9 +3307,9 @@ match_orclause_to_indexcol(PlannerInfo *root,
 			inputcollid = subClause->inputcollid;
 
 			/*
-			 * Check operator is present in the opfamily, expression collation
-			 * matches index collation.  Also, there must be an array type in
-			 * order to construct an array later.
+			 * Check operator is presented in the opfamily and expression
+			 * collation matches index collation. Also, there must be an array
+			 * type to construct an array later.
 			 */
 			if (!IndexCollMatchesExprColl(index->indexcollations[indexcol], inputcollid) ||
 				!op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
@@ -3332,12 +3341,14 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		return NULL;
 	}
 
+	/*
+	 * Assemble an array from the list of constants. It seems more profitable to
+	 * build a const array. But in presence of parameters we don't have specific
+	 * value here and must employ an ArrayExpr instead.
+	 */
+
 	if (have_param)
 	{
-		/*
-		 * We need to construct an ArrayExpr given we have Param's not just
-		 * Const's.
-		 */
 		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
 
 		/* array_collid will be set by parse_collate.c */
@@ -3351,10 +3362,6 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	}
 	else
 	{
-		/*
-		 * We have only Const's.  In this case we can construct an array
-		 * directly.
-		 */
 		int16		typlen;
 		bool		typbyval;
 		char		typalign;
@@ -3383,8 +3390,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	}
 
 	/* Lookup for operator to fetch necessary information for the SAOP node */
-	opertup = SearchSysCache1(OPEROID,
-							  ObjectIdGetDatum(matchOpno));
+	opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(matchOpno));
 	if (!HeapTupleIsValid(opertup))
 		elog(ERROR, "cache lookup failed for operator %u", matchOpno);
 
@@ -3404,7 +3410,11 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	ReleaseSysCache(opertup);
 
 	/*
-	 * Finally build an IndexClause based on the SAOP node.
+	 * Finally build an IndexClause based on the SAOP node. Use
+	 * make_simple_restrictinfo to get RestrictInfo with clean selectivity
+	 * estimations because it may differ from estimation made for an OR clause.
+	 * Although it is not a lossy expression, keep old version of rinfo in
+	 * iclause->rinfo to detect duplicates and recheck original clause.
 	 */
 	iclause = makeNode(IndexClause);
 	iclause->rinfo = rinfo;
-- 
2.39.5

0002-Comments-for-0002-patch.patchtext/x-patch; charset=UTF-8; name=0002-Comments-for-0002-patch.patchDownload
From d0dfb0641ec100aaff2c3a7cf0cefa2e55be7beb Mon Sep 17 00:00:00 2001
From: "Andrei V. Lepikhov" <lepihov@gmail.com>
Date: Wed, 9 Oct 2024 15:42:54 +0700
Subject: [PATCH 2/3] Comments for 0002 patch

---
 src/backend/optimizer/path/indxpath.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 602141911d..a2ddfb2bb9 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1174,9 +1174,10 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 }
 
 /*
- * Data structure representing information about OR-clause argument and its
- * matching index key.  Used for grouping of similar OR-clause arguments in
+ * Utility structure used to group similar OR-clause arguments in
  * group_similar_or_args().
+ * It represents information about OR-clause argument and its
+ * matching index key.
  */
 typedef struct
 {
@@ -1228,12 +1229,17 @@ or_arg_index_match_cmp(const void *a, const void *b)
 
 /*
  * group_similar_or_args
- *		Group similar OR-arguments into dedicated RestrictInfos.  Process
- *		arguments of 'rinfo' clause, returns the processed list of arguments.
+ *		Transform incoming OR-restrictinfo into a list of sub-restrictinfos,
+ *		each of them contain a subset of OR-clauses from the source rinfo
+ *		matching the same index column with the same operator and collation,
+ *		It may be employed later, during the match_clause_to_indexcol to
+ *		transform whole OR-sub-rinfo to a SAOP clause.
  *
  * Similar arguments clauses of form "indexkey op constant" having same
  * indexkey, operator, and collation.  Constant may comprise either Const
  * or Param.
+ *
+ * Returns the processed list of arguments.
  */
 static List *
 group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
@@ -1252,8 +1258,9 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 	n = list_length(orargs);
 
 	/*
-	 * Allocate and fill OrArgIndexMatch struct for each clause in the
-	 * argument list.
+	 * To avoid N^2 behaviour, take utility pass along the list of OR-clause
+	 * arguments. For each argument fill the OrArgIndexMatch structure which
+	 * will be used to sort these arguments at the next step.
 	 */
 	i = -1;
 	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
@@ -1368,7 +1375,11 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 	/* Sort clauses to make similar clauses go together */
 	qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
 
-	/* Group similar clauses into */
+	/*
+	 * Group similar clauses into single sub-restrictinfo.
+	 * Side effect: resulting list of restrictions will be sorted by indexnum
+	 * and colnum. Can we employ it somehow later?
+	 */
 	group_start = 0;
 	for (i = 1; i <= n; i++)
 	{
-- 
2.39.5

0003-Comment-on-restriction-of-OR-SAOP-element-type.patchtext/x-patch; charset=UTF-8; name=0003-Comment-on-restriction-of-OR-SAOP-element-type.patchDownload
From fabb970f0acdb1bb3b7280f05ffce9facf89af44 Mon Sep 17 00:00:00 2001
From: "Andrei V. Lepikhov" <lepihov@gmail.com>
Date: Wed, 9 Oct 2024 16:17:27 +0700
Subject: [PATCH 3/3] Comment on restriction of OR->SAOP element type

---
 src/backend/optimizer/path/indxpath.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index a2ddfb2bb9..c8625a32d4 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -2538,7 +2538,10 @@ match_clause_to_index(PlannerInfo *root,
  *	  (3)  must match the collation of the index, if collation is relevant.
  *
  *	  Our definition of "const" is exceedingly liberal: we allow anything that
- *	  doesn't involve a volatile function or a Var of the index's relation.
+ *	  doesn't involve a volatile function or a Var of the index's relation
+ *	  except for a boolean OR expression input: due to trade-off between
+ *	  expected execution speedup planning complexity, we limit or->saop
+ *	  transformation by obvious cases when an index scan can get a profit.
  *	  In particular, Vars belonging to other relations of the query are
  *	  accepted here, since a clause of that form can be used in a
  *	  parameterized indexscan.  It's the responsibility of higher code levels
-- 
2.39.5

#273Alexander Korotkov
aekorotkov@gmail.com
In reply to: Robert Haas (#250)
Re: POC, WIP: OR-clause support for indexes

Hi, Robert!

Thank you so much for your very valuable review. It took some time to
address all the points. Hopefully I didn't miss anything.

On Fri, Oct 4, 2024 at 4:34 PM Robert Haas <robertmhaas@gmail.com> wrote:

On Mon, Sep 23, 2024 at 7:11 AM Alexander Korotkov <aekorotkov@gmail.com>

wrote:

Makes sense. Please, check the attached patch freeing the consts list
while returning NULL from match_orclause_to_indexcol().

Some review comments:

I agree with the comments already given to the effect that the patch
looks much better now. I was initially surprised to see this happening
in match_clause_to_indexcol() but after studying it I think it looks
like the right place. I think it makes sense to think about moving
forward with this, although it would be nice to get Tom's take if we
can.

Thank you. And surely, Tom's feedback is very welcome.

I see that the patch makes no update to the header comment for
match_clause_to_indexcol() nor to the comment just above the cascade
of if-statements. I think both need to be updated.

More generally, many of the comments in this patch seem to just
explain what the code does, and I'd like to reiterate my usual
complaint: as far as possible, comments should explain WHY the code
does what it does. Certainly, in some cases there's nothing to be said
about that e.g. /* Lookup for operator to fetch necessary information
for the SAOP node */ isn't really saying anything non-obvious but it's
reasonable to have the comment here anyway. However, when there is
something more interesting to be said, then we should do that rather
than just reiterate what the reader who knows C can anyway see. For
instance, the lengthy comment beginning with "Iterate over OR
entries." could either be shorter and recapitulate less of the code
that follows, or it could say something more interesting about why
we're doing it like that.

I've integrated comments by Andrei [1], edit them and added some from
myself. Hopefully that's better now.

+ /* We allow constant to be Const or Param */
+ if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+ break;

This restriction is a lot tighter than the one mentioned in the header
comment of match_clause_to_indexcol ("Our definition of const is
exceedingly liberal"). If there's a reason for that, the comments
should talk about it. If there isn't, it's better to be consistent.

Yes, actually I think the restriction could be less tight. It should be
possible to use the same definition of const as
match_opclause_to_indexcol() antd others. The 0003 patch demonstrates
that. But it appears that match_join_clauses_to_index() needs changes.
So, generally I think this area needs more research. This is why, I would
prefer to deal just with Const and Param as 0001 and 0002 currently do, but
consider something like 0003 later.

+ /*
+ * Check operator is present in the opfamily, expression collation
+ * matches index collation.  Also, there must be an array type in
+ * order to construct an array later.
+ */
+ if (!IndexCollMatchesExprColl(index->indexcollations[indexcol],
inputcollid) ||
+ !op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+ !OidIsValid(arraytype))
+ break;

I spent some time wondering whether this was safe. The
IndexCollMatchesExprColl() guarantees that either the input collation
is equal to the index collation, or the index collation is 0. If the
index collation is 0 then that I *think* that guarantees that the
indexed type is non-collatable, but this could be a cross-type
comparison, and it's possible that the other type is collatable. In
that case, I don't think anything would prevent us from merging a
bunch of OR clauses with different collations into a single SAOP. I
don't really see how that could be a problem, because if the index is
of a non-collatable type, then presumably the operator doesn't care
about what the collation is, so it should all be fine, I guess? But
I'm not very confident about that conclusion.

Generally, we have the same requirements as match_opclause_to_indexcol()
for the first OR argument. And we require rest arguments to have same
input collations. Looks pretty safe for me.

I'm unclear what the current thinking is about the performance of this
patch, both as to planning and as to execution. Do we believe that
this transformation is a categorical win at execution-time? In theory,
OR format alllows for short-circuit execution, but because of the
Const-or-Param restriction above, I don't think that's mostly a
non-issue. But maybe not completely, because I can see from the
regression test changes that it's possible for us to apply this
transformation when the Param is set by an InitPlan or SubPlan. If we
have something like WHERE tenthous = 1 OR tenthous =
(very_expensive_computation() + 1), maybe the patch could lose,
because we'll have to do the very expensive calculation to evaluate
the SAOP, and the OR could stop as soon as we establish that tenthous
!= 1. If we only did the transformation when the Param is an external
parameter, then we wouldn't have this issue. Maybe this isn't worth
worrying about; I'm not sure. Are there any other cases where the
transformation can produce something that executes more slowly?

I didn't manage to find issues with expressions like WHERE tenthous = 1 OR
tenthous => (very_expensive_computation() + 1), because master also need to
evaluate very_expensive_computation() in order to do index scan or bitmap
scan. And patch doesn't do anything to sequential scan. However, I
managed to find an issue with more complex expression. See the example
below.

create or replace function slowfunc() returns int as $$
begin
PERFORM pg_sleep(1.0);
RETURN 1;
end;
$$ stable language plpgsql cost 10000000;
create table t (i int not null, j int not null);
insert into t (select i, i from generate_series(1,10) i,
generate_series(1,1000));
create index t_i_j on t (i, j);

*master*
# explain select count(*) from t where i = 1 and (j = 1 or j = (select
slowfunc()));
QUERY PLAN
-----------------------------------------------------------------------------
Aggregate (cost=25031.27..25031.28 rows=1 width=8)
InitPlan 1
-> Result (cost=0.00..25000.01 rows=1 width=4)
-> Index Only Scan using t_i_j on t (cost=0.29..30.79 rows=190 width=0)
Index Cond: (i = 1)
Filter: ((j = 1) OR (j = (InitPlan 1).col1))
(6 rows)

# select count(*) from t where i = 1 and (j = 1 or j = (select slowfunc()));
count
-------
1000
(1 row)

Time: 2.923 ms

*patched*

# explain select count(*) from t where i = 1 and (j = 1 or j = (select
slowfunc()));
QUERY PLAN
---------------------------------------------------------------------------
Aggregate (cost=25012.61..25012.62 rows=1 width=8)
InitPlan 1
-> Result (cost=0.00..25000.01 rows=1 width=4)
-> Index Only Scan using t_i_j on t (cost=0.29..12.60 rows=1 width=0)
Index Cond: ((i = 1) AND (j = ANY (ARRAY[1, (InitPlan 1).col1])))
(5 rows)

# select count(*) from t where i = 1 and (j = 1 or j = (select slowfunc()));
count
-------
1000
(1 row)

Time: 1006.147 ms (00:01.006)

But, I don't think this is a new issue. We generally trying to use as many
clauses as possible in index scan. We don't do any cost analysis about
that. See the following example.

*master*
# explain analyze select * from t where i = 0 and j = (select slowfunc());
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
Index Only Scan using t_i_j on t (cost=25000.29..25004.31 rows=1 width=8)
(actual time=1001.234..1001.235 rows=0 loops=1)
Index Cond: ((i = 0) AND (j = (InitPlan 1).col1))
Heap Fetches: 0
InitPlan 1
-> Result (cost=0.00..25000.01 rows=1 width=4) (actual
time=1001.120..1001.121 rows=1 loops=1)
Planning Time: 0.240 ms
Execution Time: 1001.290 ms
(7 rows)

# set enable_indexscan = off;
# set enable_bitmapscan = off;

# explain analyze select * from t where i = 0 and j = (select slowfunc());
QUERY PLAN
---------------------------------------------------------------------------------------------------
Seq Scan on t (cost=25000.01..25195.01 rows=1 width=8) (actual
time=0.806..0.807 rows=0 loops=1)
Filter: ((i = 0) AND (j = (InitPlan 1).col1))
Rows Removed by Filter: 10000
InitPlan 1
-> Result (cost=0.00..25000.01 rows=1 width=4) (never executed)
Planning Time: 0.165 ms
Execution Time: 0.843 ms
(7 rows)

Thus, I think patch just follows our general logic to push as many clauses
as possible to the index, and doesn't make situation any worse. There are
cases when this logic cause the slowdown, by I think they are rather rare.
It's required that one of OR argument to be always true, or one of AND
arguments to be always false, while another argument to be expensive to
calculate. I think this happens very rarely in practice, otherwise we will
hear more (any?) complaints about that from users. Also, notice we now can
evaluate stable function at planning time for selectivity estimation
disregarding its high cost.

# explain analyze select * from t where i = 0 and j = slowfunc();
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
Index Only Scan using t_i_j on t (cost=25000.28..25004.30 rows=1 width=8)
(actual time=1001.220..1001.220 rows=0 loops=1)
Index Cond: ((i = 0) AND (j = slowfunc()))
Heap Fetches: 0
Planning Time: 1000.994 ms
Execution Time: 1001.284 ms
(5 rows)

Therefore, I don't see a particular problem in the path. But if you insist
there is a problem, we can restrict patch to work only with external params.

As far as planning time is concerned, I don't think this is going to
be too bad, because most of the work only needs to be done if there
are OR-clauses, and my intuition is that the optimization will often
apply in such cases, so it seems alright. But I wonder how much
testing has been done of adversarial cases, e.g. lots of non-indexable
clause in the query; or lots of OR clauses in the query but all of
them turn out on inspection to be non-indexable. My expectation would
be that there's no real problem here, but it would be good to verify
that experimentally.

I made some experiments in this field. The sample table contains 64
columns, first 32 of them are indexed.

\o script.sql
\pset tuples_only
select 'create table t (' || string_agg(format('a%s int not null default
0', i), ', ') || ');' from generate_series(1, 64) i;
select 'create index t_a1_to_a50_idx on t (' || string_agg(format('a%s',
i), ', ') || ');' from generate_series(1, 32) i;

First query contains 6400 OR arguments, 100 per each column.

\o q1.sql
select 'explain analyze select * from t where ' || string_agg(format('a%s =
%s', (i - 1) / 100 + 1, i), ' OR ') || ';' from generate_series(1, 6400) i;

Second query also contains 6400 OR arguments, but 200 per each indexed
column.

\o q2.sql
select 'explain analyze select * from t where ' || string_agg(format('a%s =
%s', (i - 1) / 200 + 1, i), ' OR ') || ';' from generate_series(1, 6400) i;

Third query also contains 6400 OR arguments, but 200 per each non-indexed
column.

\o q3.sql
select 'explain analyze select * from t where ' || string_agg(format('a%s =
%s', (i - 1) / 200 + 32, i), ' OR ') || ';' from generate_series(1, 6400) i;

\pset tuples_only off
\o
\i script.sql
\i q1.sql
\i q2.sql
\i q3.sql

The results for planning time are following.

| master | patch
---------- | ------ | ------
Q1 (run 1) | 14.450 | 12.190
Q1 (run 2) | 13.158 | 11.778
Q1 (run 3) | 11.220 | 12.457
Q2 (run 1) | 15.365 | 13.584
Q2 (run 2) | 15.804 | 14.185
Q2 (run 3) | 16.205 | 13.488
Q3 (run 1) | 9.481 | 12.729
Q3 (run 2) | 10.907 | 13.662
Q3 (run 3) | 11.783 | 12.021

The planning of Q1 and Q2 is somewhat faster with the patch. I think the
reason for this is shortcut condition in make_bitmap_paths_for_or_group(),
which make us select jointlist without making splitlist. So, we generally
produce simpler bitmap scan plans. The Q3 is somewhat slower with the
patch, because it contains no index-matching clauses,
thus group_similar_or_args() appears to be a waste of cycles. This
generally looks acceptable for me.

Additionally the attached patchset contains changes I promised in response
to Jian He comments, in particular:
1. Fast-path exit form make_bitmap_paths_for_or_group() when joint path is
found and no extra clauses present.
2. Fast-path exit from group_similar_or_args() when not even single clause
is matching index.
3. Fix exit iteration over indexes after first success with
match_index_to_operand() in group_similar_or_args().

Also, in this revision I fixed buggy modification of all_clauses list
with list_delete() in generate_bitmap_or_paths(). Instead, new copy of
list is created.

This is all for now. The feedback is welcome.

Links.
1.
/messages/by-id/5d7a66e7-b256-41a7-905a-728c7ae54bce@gmail.com
2.
/messages/by-id/CAPpHfdsB2e20Y4jThsonD3+smwwisYWJbJN_mpGjm=JiT7OQaQ@mail.gmail.com
3.
/messages/by-id/CAPpHfdunXXFT=jk+3ojXQWo0wZ1Rk=rpmAp+fjcistCWcH7KqA@mail.gmail.com

------
Regards,
Alexander Korotkov
Supabase

#274Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alexander Korotkov (#273)
3 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 11, 2024 at 4:20 PM Alexander Korotkov <aekorotkov@gmail.com>
wrote:

This is all for now. The feedback is welcome.

Just figured out, I forgot the patchset itself. Here it goes.

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v41-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchapplication/octet-stream; name=v41-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchDownload
From 675e389b534acf82e141305a0360e1a9e80804f9 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 23 Sep 2024 14:03:54 +0300
Subject: [PATCH v41 1/3] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is an i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows handling long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 281 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out | 270 ++++++++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/expected/rowsecurity.out  |   7 +
 src/test/regress/expected/stats_ext.out    |  12 +
 src/test/regress/expected/uuid.out         |  31 +++
 src/test/regress/sql/create_index.sql      |  69 +++++
 src/test/regress/sql/join.sql              |   9 +
 src/test/regress/sql/rowsecurity.sql       |   1 +
 src/test/regress/sql/stats_ext.sql         |   3 +
 src/test/regress/sql/uuid.sql              |  12 +
 11 files changed, 729 insertions(+), 23 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..b24b10b986b 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -32,8 +33,10 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "utils/syscache.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -177,6 +180,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2149,7 +2156,10 @@ match_clause_to_index(PlannerInfo *root,
  *	  (3)  must match the collation of the index, if collation is relevant.
  *
  *	  Our definition of "const" is exceedingly liberal: we allow anything that
- *	  doesn't involve a volatile function or a Var of the index's relation.
+ *	  doesn't involve a volatile function or a Var of the index's relation
+ *	  except for a boolean OR expression input: due to a trade-off between the
+ *	  expected execution speedup and planning complexity, we limit or->saop
+ *	  transformation by obvious cases when an index scan can get a profit.
  *	  In particular, Vars belonging to other relations of the query are
  *	  accepted here, since a clause of that form can be used in a
  *	  parameterized indexscan.  It's the responsibility of higher code levels
@@ -2179,6 +2189,10 @@ match_clause_to_index(PlannerInfo *root,
  *	  It is also possible to match ScalarArrayOpExpr clauses to indexes, when
  *	  the clause is of the form "indexkey op ANY (arrayconst)".
  *
+ *	  It is also possible to match a list of OR clauses if it might be
+ *	  transformed into a single ScalarArrayOpExpr clause.  On success,
+ *	  the returning index clause will contain a trasformed clause.
+ *
  *	  For boolean indexes, it is also possible to match the clause directly
  *	  to the indexkey; or perhaps the clause is (NOT indexkey).
  *
@@ -2228,9 +2242,9 @@ match_clause_to_indexcol(PlannerInfo *root,
 	}
 
 	/*
-	 * Clause must be an opclause, funcclause, ScalarArrayOpExpr, or
-	 * RowCompareExpr.  Or, if the index supports it, we can handle IS
-	 * NULL/NOT NULL clauses.
+	 * Clause must be an opclause, funcclause, ScalarArrayOpExpr,
+	 * RowCompareExpr, or OR-clause that could be converted to SAOP.  Or, if
+	 * the index supports it, we can handle IS NULL/NOT NULL clauses.
 	 */
 	if (IsA(clause, OpExpr))
 	{
@@ -2248,6 +2262,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2789,261 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ *
+ * Given a list of OR-clause args, attempts to transform this BoolExpr into
+ * a single SAOP expression. On success, returns an IndexClause, containing
+ * the transformed expression or NULL, if failed.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Try to convert a list of OR-clauses to a single SAOP expression. Each
+	 * OR entry must be in the form: (indexkey operator constant) or (constant
+	 * operator indexkey).  Operators of all the entries must match. Constant
+	 * might be either Const or Param. To be effective, give up on the first
+	 * non-matching entry. Exit is implemented as a break from the loop, which
+	 * is catched afterwards.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			break;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses can match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			break;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			break;
+
+		/*
+		 * The parameters below must match between sub-rinfo and its parent as
+		 * make_restrictinfo() fills them with the same values, and further
+		 * modifications are also the same for the whole subtree. However,
+		 * still make a sanity check.
+		 */
+		Assert(subRinfo->is_pushed_down == rinfo->is_pushed_down);
+		Assert(subRinfo->is_clone == rinfo->is_clone);
+		Assert(subRinfo->security_level == rinfo->security_level);
+		Assert(bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids));
+		Assert(bms_equal(subRinfo->outer_relids, rinfo->outer_relids));
+
+		/*
+		 * Also, check that required_relids in sub-rinfo is subset of parent's
+		 * required_relids.
+		 */
+		Assert(bms_is_subset(subRinfo->required_relids, rinfo->required_relids));
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			break;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				break;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			break;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			break;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			break;
+
+		/*
+		 * Save information about the operator, type, and collation for the
+		 * first matching qual. Then, check that subsequent quals match the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * Check that the operator is presented in the opfamily and that
+			 * the expression collation matches the index collation. Also,
+			 * there must be an array type to construct an array later.
+			 */
+			if (!IndexCollMatchesExprColl(index->indexcollations[indexcol], inputcollid) ||
+				!op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+				!OidIsValid(arraytype))
+				break;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				break;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	/*
+	 * Catch the break from the loop above.  Normally, a foreach() loop ends
+	 * up with a NULL list cell.  A non-NULL list cell indicates a break from
+	 * the foreach() loop.  Free the consts list and return NULL then.
+	 */
+	if (lc != NULL)
+	{
+		list_free(consts);
+		return NULL;
+	}
+
+	/*
+	 * Assemble an array from the list of constants. It seems more profitable
+	 * to build a const array. But in the presence of parameters, we don't
+	 * have a specific value here and must employ an ArrayExpr instead.
+	 */
+
+	if (have_param)
+	{
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = get_opcode(matchOpno);
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	/*
+	 * Finally, build an IndexClause based on the SAOP node. Use
+	 * make_simple_restrictinfo() to get RestrictInfo with clean selectivity
+	 * estimations because it may differ from the estimation made for an OR
+	 * clause. Although it is not a lossy expression, keep the old version of
+	 * rinfo in iclause->rinfo to detect duplicates and recheck the original
+	 * clause.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = rinfo;
+	iclause->indexquals = list_make1(make_simple_restrictinfo(root,
+															  &saopexpr->xpr));
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index d3358dfc394..e4d117e47ae 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,67 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                   QUERY PLAN                                    
+---------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,6 +1913,27 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1872,6 +1942,102 @@ SELECT count(*) FROM tenk1
  Aggregate
    ->  Bitmap Heap Scan on tenk1
          Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand < 42) OR (thousand < 99) OR (43 > thousand) OR (42 > thousand)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                             QUERY PLAN                                              
+-----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,16 +2045,90 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 756c2e24965..6d02360cf43 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 319190855bd..ef890b96cc6 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4492,6 +4492,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index fe162cc7c30..71a7115067e 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -732,12 +732,81 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 0c65e5af4be..8f6acb5f618 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 3011d71b12b..6d2414b6044 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
-- 
2.39.5 (Apple Git-154)

v41-0003-Allow-match_orclause_to_indexcol-for-joins.patchapplication/octet-stream; name=v41-0003-Allow-match_orclause_to_indexcol-for-joins.patchDownload
From d26c4a0408cf6af783216540cb189a64e8fa5579 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Wed, 9 Oct 2024 18:44:25 +0300
Subject: [PATCH v41 3/3] Allow match_orclause_to_indexcol() for joins

---
 src/backend/optimizer/path/indxpath.c | 19 ++++++++++---------
 src/test/regress/expected/join.out    | 10 +++++-----
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 5c8b64a5b1e..ed3f8ff9991 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -2418,8 +2418,8 @@ match_join_clauses_to_index(PlannerInfo *root,
 		/* Potentially usable, so see if it matches the index or is an OR */
 		if (restriction_is_or_clause(rinfo))
 			*joinorclauses = lappend(*joinorclauses, rinfo);
-		else
-			match_clause_to_index(root, rinfo, index, clauseset);
+
+		match_clause_to_index(root, rinfo, index, clauseset);
 	}
 }
 
@@ -3229,6 +3229,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Oid			inputcollid = InvalidOid;
 	bool		firstTime = true;
 	bool		have_param = false;
+	Index		index_relid = index->rel->relid;
 
 	Assert(IsA(orclause, BoolExpr));
 	Assert(orclause->boolop == OR_EXPR);
@@ -3295,12 +3296,16 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		 */
 		leftop = (Node *) linitial(subClause->args);
 		rightop = (Node *) lsecond(subClause->args);
-		if (match_index_to_operand(leftop, indexcol, index))
+		if (match_index_to_operand(leftop, indexcol, index) &&
+			!bms_is_member(index_relid, rinfo->right_relids) &&
+			!contain_volatile_functions(rightop))
 		{
 			indexExpr = leftop;
 			constExpr = rightop;
 		}
-		else if (match_index_to_operand(rightop, indexcol, index))
+		else if (match_index_to_operand(rightop, indexcol, index) &&
+			!bms_is_member(index_relid, rinfo->left_relids) &&
+			!contain_volatile_functions(leftop))
 		{
 			opno = get_commutator(opno);
 			if (!OidIsValid(opno))
@@ -3327,10 +3332,6 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		if (IsA(indexExpr, RelabelType))
 			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
 
-		/* We allow constant to be Const or Param */
-		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
-			break;
-
 		/* Forbid transformation for composite types, records. */
 		if (type_is_rowtype(exprType(constExpr)) ||
 			type_is_rowtype(exprType(indexExpr)))
@@ -3367,7 +3368,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 				break;
 		}
 
-		if (IsA(constExpr, Param))
+		if (!IsA(constExpr, Const))
 			have_param = true;
 		consts = lappend(consts, constExpr);
 	}
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 198b9168045..b4354c12079 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -3729,8 +3729,8 @@ select * from
   tenk1 join int4_tbl on f1 = twothousand,
   q1, q2
 where q1 = thousand or q2 = thousand;
-                               QUERY PLAN                               
-------------------------------------------------------------------------
+                                                                                QUERY PLAN                                                                                
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Hash Join
    Hash Cond: (tenk1.twothousand = int4_tbl.f1)
    ->  Nested Loop
@@ -3738,12 +3738,12 @@ where q1 = thousand or q2 = thousand;
                ->  Seq Scan on q1
                ->  Seq Scan on q2
          ->  Bitmap Heap Scan on tenk1
-               Recheck Cond: ((q1.q1 = thousand) OR (q2.q2 = thousand))
+               Recheck Cond: (((q1.q1 = thousand) AND ((q1.q1 = thousand) OR (q2.q2 = thousand))) OR ((q2.q2 = thousand) AND ((q1.q1 = thousand) OR (q2.q2 = thousand))))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = q1.q1)
+                           Index Cond: ((thousand = q1.q1) AND (thousand = ANY (ARRAY[q1.q1, q2.q2])))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = q2.q2)
+                           Index Cond: ((thousand = q2.q2) AND (thousand = ANY (ARRAY[q1.q1, q2.q2])))
    ->  Hash
          ->  Seq Scan on int4_tbl
 (15 rows)
-- 
2.39.5 (Apple Git-154)

v41-0002-Teach-bitmap-path-generation-about-transforming-.patchapplication/octet-stream; name=v41-0002-Teach-bitmap-path-generation-about-transforming-.patchDownload
From 402d11e28d8f6bd98affbfc1542349faeff72fbb Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 23 Sep 2024 14:04:03 +0300
Subject: [PATCH v41 2/3] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 426 ++++++++++++++++++++-
 src/backend/optimizer/util/restrictinfo.c  | 107 +++---
 src/include/optimizer/restrictinfo.h       |  11 +
 src/test/regress/expected/create_index.out | 123 +++++-
 src/test/regress/expected/join.out         |  56 ++-
 src/test/regress/sql/create_index.sql      |  36 ++
 src/tools/pgindent/typedefs.list           |   1 +
 7 files changed, 653 insertions(+), 107 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index b24b10b986b..5c8b64a5b1e 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1173,6 +1173,383 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Utility structure used to group similar OR-clause arguments in
+ * group_similar_or_args().  It represents information about the OR-clause
+ * argument and its matching index key.
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index, or -1 if no
+								 * matching index */
+	int			colnum;			/* index of the matching column, or -1 if no
+								 * matching index */
+	Oid			opno;			/* OID of the OpClause operator, or InvalidOid
+								 * if not an OpExpr */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Transform incoming OR-restrictinfo into a list of sub-restrictinfos,
+ *		each of them containing a subset of OR-clauses from the source rinfo
+ *		matching the same index column with the same operator and collation,
+ *		It may be employed later, during the match_clause_to_indexcol() to
+ *		transform whole OR-sub-rinfo to an SAOP clause.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constant may comprise either Const
+ * or Param.
+ *
+ * Returns the processed list of arguments.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	bool		matched = false;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * To avoid N^2 behavior, take utility pass along the list of OR-clause
+	 * arguments.  For each argument, fill the OrArgIndexMatch structure,
+	 * which will be used to sort these arguments at the next step.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses can match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			continue;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+					matched = true;
+					break;
+				}
+			}
+
+			/*
+			 * Stop looping through the indexes, if we managed to match
+			 * nonConstExpr to any index column.
+			 */
+			if (matches[i].indexnum >= 0)
+				break;
+			indexnum++;
+		}
+	}
+
+	/*
+	 * Fast-path check: if no clause is matching to the index column, we can
+	 * just give up at this stage and return the clause list as-is.
+	 */
+	if (!matched)
+	{
+		pfree(matches);
+		return orargs;
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/*
+	 * Group similar clauses into single sub-restrictinfo. Side effect: the
+	 * resulting list of restrictions will be sorted by indexnum and colnum.
+	 */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				List	   *rargs = NIL;
+				RestrictInfo *subrinfo;
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+				{
+					Node	   *arg = list_nth(orargs, matches[j].argindex);
+
+					rargs = lappend(rargs, arg);
+					if (IsA(arg, RestrictInfo))
+						args = lappend(args, ((RestrictInfo *) arg)->clause);
+					else
+						args = lappend(args, arg);
+				}
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				subrinfo = make_plain_restrictinfo(root,
+												   make_orclause(args),
+												   make_orclause(rargs),
+												   rinfo->is_pushed_down,
+												   rinfo->has_clone,
+												   rinfo->is_clone,
+												   rinfo->pseudoconstant,
+												   rinfo->security_level,
+												   rinfo->required_relids,
+												   rinfo->incompatible_relids,
+												   rinfo->outer_relids);
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->orclause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+	}
+
+	/*
+	 * If we manage to find a bitmap scan, which uses the group of OR-clause
+	 * arguments as a whole, we can skip matching OR-clause arguments
+	 * one-by-one as long as there are no other clauses, which can bring more
+	 * efficiency to one-by-one case.
+	 */
+	if (jointlist != NIL && other_clauses == NIL)
+		return jointlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1203,6 +1580,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1213,7 +1591,13 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into dedicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as a whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1233,12 +1617,40 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+				List	   *inner_other_clauses;
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.  In this case we need to immediately remove the
+				 * rinfo from other clauses.  This is because rinfo can be
+				 * transformed during index matching.  So, we might be unable
+				 * to remove that later.
+				 */
+				inner_other_clauses = list_delete(list_copy(all_clauses), rinfo);
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 inner_other_clauses);
+				list_free(inner_other_clauses);
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
@@ -2441,7 +2853,7 @@ match_opclause_to_indexcol(PlannerInfo *root,
 
 	/*
 	 * Check for clauses of the form: (indexkey operator constant) or
-	 * (constant operator indexkey).  See match_clause_to_indexcol's notes
+	 * (constant operator indexkey).  See match_clause_to_indexcol()'s notes
 	 * about const-ness.
 	 *
 	 * Note that we don't ask the support function about clauses that don't
@@ -3002,8 +3414,12 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
 
 		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
-		foreach(lc, consts)
-			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+		foreach_node(Const, value, consts)
+		{
+			Assert(!value->constisnull && value->constvalue);
+
+			elems[i++] = value->constvalue;
+		}
 
 		arrayConst = construct_array(elems, i, consttype,
 									 typlen, typbyval, typalign);
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e93342..9e1458401c2 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -21,17 +21,6 @@
 #include "optimizer/restrictinfo.h"
 
 
-static RestrictInfo *make_restrictinfo_internal(PlannerInfo *root,
-												Expr *clause,
-												Expr *orclause,
-												bool is_pushed_down,
-												bool has_clone,
-												bool is_clone,
-												bool pseudoconstant,
-												Index security_level,
-												Relids required_relids,
-												Relids incompatible_relids,
-												Relids outer_relids);
 static Expr *make_sub_restrictinfos(PlannerInfo *root,
 									Expr *clause,
 									bool is_pushed_down,
@@ -90,36 +79,38 @@ make_restrictinfo(PlannerInfo *root,
 	/* Shouldn't be an AND clause, else AND/OR flattening messed up */
 	Assert(!is_andclause(clause));
 
-	return make_restrictinfo_internal(root,
-									  clause,
-									  NULL,
-									  is_pushed_down,
-									  has_clone,
-									  is_clone,
-									  pseudoconstant,
-									  security_level,
-									  required_relids,
-									  incompatible_relids,
-									  outer_relids);
+	return make_plain_restrictinfo(root,
+								   clause,
+								   NULL,
+								   is_pushed_down,
+								   has_clone,
+								   is_clone,
+								   pseudoconstant,
+								   security_level,
+								   required_relids,
+								   incompatible_relids,
+								   outer_relids);
 }
 
 /*
- * make_restrictinfo_internal
+ * make_plain_restrictinfo
  *
- * Common code for the main entry points and the recursive cases.
+ * Common code for the main entry points and the recursive cases.  Also,
+ * useful while contrucitng RestrictInfos above OR clause, which already has
+ * RestrictInfos above its subclauses.
  */
-static RestrictInfo *
-make_restrictinfo_internal(PlannerInfo *root,
-						   Expr *clause,
-						   Expr *orclause,
-						   bool is_pushed_down,
-						   bool has_clone,
-						   bool is_clone,
-						   bool pseudoconstant,
-						   Index security_level,
-						   Relids required_relids,
-						   Relids incompatible_relids,
-						   Relids outer_relids)
+RestrictInfo *
+make_plain_restrictinfo(PlannerInfo *root,
+						Expr *clause,
+						Expr *orclause,
+						bool is_pushed_down,
+						bool has_clone,
+						bool is_clone,
+						bool pseudoconstant,
+						Index security_level,
+						Relids required_relids,
+						Relids incompatible_relids,
+						Relids outer_relids)
 {
 	RestrictInfo *restrictinfo = makeNode(RestrictInfo);
 	Relids		baserels;
@@ -296,17 +287,17 @@ make_sub_restrictinfos(PlannerInfo *root,
 													NULL,
 													incompatible_relids,
 													outer_relids));
-		return (Expr *) make_restrictinfo_internal(root,
-												   clause,
-												   make_orclause(orlist),
-												   is_pushed_down,
-												   has_clone,
-												   is_clone,
-												   pseudoconstant,
-												   security_level,
-												   required_relids,
-												   incompatible_relids,
-												   outer_relids);
+		return (Expr *) make_plain_restrictinfo(root,
+												clause,
+												make_orclause(orlist),
+												is_pushed_down,
+												has_clone,
+												is_clone,
+												pseudoconstant,
+												security_level,
+												required_relids,
+												incompatible_relids,
+												outer_relids);
 	}
 	else if (is_andclause(clause))
 	{
@@ -328,17 +319,17 @@ make_sub_restrictinfos(PlannerInfo *root,
 		return make_andclause(andlist);
 	}
 	else
-		return (Expr *) make_restrictinfo_internal(root,
-												   clause,
-												   NULL,
-												   is_pushed_down,
-												   has_clone,
-												   is_clone,
-												   pseudoconstant,
-												   security_level,
-												   required_relids,
-												   incompatible_relids,
-												   outer_relids);
+		return (Expr *) make_plain_restrictinfo(root,
+												clause,
+												NULL,
+												is_pushed_down,
+												has_clone,
+												is_clone,
+												pseudoconstant,
+												security_level,
+												required_relids,
+												incompatible_relids,
+												outer_relids);
 }
 
 /*
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c59..b77bf7ddfe9 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -22,6 +22,17 @@
 	make_restrictinfo(root, clause, true, false, false, false, 0, \
 		NULL, NULL, NULL)
 
+extern RestrictInfo *make_plain_restrictinfo(PlannerInfo *root,
+											 Expr *clause,
+											 Expr *orclause,
+											 bool is_pushed_down,
+											 bool has_clone,
+											 bool is_clone,
+											 bool pseudoconstant,
+											 Index security_level,
+											 Relids required_relids,
+											 Relids incompatible_relids,
+											 Relids outer_relids);
 extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Expr *clause,
 									   bool is_pushed_down,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index e4d117e47ae..de0e4dcffd1 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1875,6 +1875,60 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
+                                                                QUERY PLAN                                                                 
+-------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND (tenthous IS NULL)) OR ((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42))))
+   Filter: ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42) OR (tenthous IS NULL))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous IS NULL))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR ((tenthous)::smallint = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+                                                                     QUERY PLAN                                                                      
+-----------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND ((tenthous = '3'::bigint) OR (tenthous = '42'::bigint))) OR ((thousand = 42) AND (tenthous = '1'::smallint)))
+   Filter: ((tenthous = '1'::smallint) OR (tenthous = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{3,42}'::bigint[])))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = '1'::smallint))
+(8 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -2003,25 +2057,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                        
+--------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND (((thousand = 42) OR (thousand = 99)) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2033,22 +2086,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR ((thousand = 42) OR (thousand = 41))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
@@ -3144,6 +3196,47 @@ SELECT  b.relname,
 (2 rows)
 
 DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before;
+-- Check bitmap scan can consider similar OR arguments separately without
+-- grouping them into SAOP.
+CREATE TABLE bitmap_split_or (a int NOT NULL, b int NOT NULL, c int NOT NULL);
+INSERT INTO bitmap_split_or (SELECT 1, 1, i FROM generate_series(1, 1000) i);
+INSERT INTO bitmap_split_or (select i, 2, 2 FROM generate_series(1, 1000) i);
+VACUUM ANALYZE bitmap_split_or;
+CREATE INDEX t_b_partial_1_idx ON bitmap_split_or (b) WHERE a = 1;
+CREATE INDEX t_b_partial_2_idx ON bitmap_split_or (b) WHERE a = 2;
+EXPLAIN SELECT * FROM bitmap_split_or WHERE (a = 1 OR a = 2) AND b = 2;
+                                       QUERY PLAN                                        
+-----------------------------------------------------------------------------------------
+ Bitmap Heap Scan on bitmap_split_or  (cost=16.29..36.06 rows=501 width=12)
+   Recheck Cond: (((b = 2) AND (a = 1)) OR ((b = 2) AND (a = 2)))
+   ->  BitmapOr  (cost=16.29..16.29 rows=501 width=0)
+         ->  Bitmap Index Scan on t_b_partial_1_idx  (cost=0.00..11.91 rows=501 width=0)
+               Index Cond: (b = 2)
+         ->  Bitmap Index Scan on t_b_partial_2_idx  (cost=0.00..4.13 rows=1 width=0)
+               Index Cond: (b = 2)
+(7 rows)
+
+DROP INDEX t_b_partial_1_idx;
+DROP INDEX t_b_partial_2_idx;
+CREATE INDEX t_a_b_idx ON bitmap_split_or (a, b);
+CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
+CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
+CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
+ANALYZE bitmap_split_or;
+EXPLAIN SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Bitmap Heap Scan on bitmap_split_or  (cost=8.83..14.31 rows=501 width=12)
+   Recheck Cond: (((b = 1) AND (c = 2)) OR ((a = 1) AND (b = 2)))
+   Filter: ((a = 1) AND (c = 2))
+   ->  BitmapOr  (cost=8.83..8.83 rows=2 width=0)
+         ->  Bitmap Index Scan on t_b_c_idx  (cost=0.00..4.29 rows=1 width=0)
+               Index Cond: ((b = 1) AND (c = 2))
+         ->  Bitmap Index Scan on t_a_b_idx  (cost=0.00..4.29 rows=1 width=0)
+               Index Cond: ((a = 1) AND (b = 2))
+(8 rows)
+
+DROP TABLE bitmap_split_or;
 --
 -- REINDEX SCHEMA
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 6d02360cf43..198b9168045 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR ((unique1 = 3) OR (unique1 = 1)) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 71a7115067e..deb9384a33f 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -738,6 +738,23 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1321,6 +1338,25 @@ SELECT  b.relname,
   ORDER BY 1;
 DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before;
 
+-- Check bitmap scan can consider similar OR arguments separately without
+-- grouping them into SAOP.
+CREATE TABLE bitmap_split_or (a int NOT NULL, b int NOT NULL, c int NOT NULL);
+INSERT INTO bitmap_split_or (SELECT 1, 1, i FROM generate_series(1, 1000) i);
+INSERT INTO bitmap_split_or (select i, 2, 2 FROM generate_series(1, 1000) i);
+VACUUM ANALYZE bitmap_split_or;
+CREATE INDEX t_b_partial_1_idx ON bitmap_split_or (b) WHERE a = 1;
+CREATE INDEX t_b_partial_2_idx ON bitmap_split_or (b) WHERE a = 2;
+EXPLAIN SELECT * FROM bitmap_split_or WHERE (a = 1 OR a = 2) AND b = 2;
+DROP INDEX t_b_partial_1_idx;
+DROP INDEX t_b_partial_2_idx;
+CREATE INDEX t_a_b_idx ON bitmap_split_or (a, b);
+CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
+CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
+CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
+ANALYZE bitmap_split_or;
+EXPLAIN SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
+DROP TABLE bitmap_split_or;
+
 --
 -- REINDEX SCHEMA
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index a65e1c07c5d..3926c1e65b4 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1766,6 +1766,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.39.5 (Apple Git-154)

#275Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alexander Korotkov (#274)
3 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Fri, Oct 11, 2024 at 7:15 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

On Fri, Oct 11, 2024 at 4:20 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

This is all for now. The feedback is welcome.

Just figured out, I forgot the patchset itself. Here it goes.

I forgot to specify (COSTS OFF) for EXPLAINs in regression tests. Fixed in v42.

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v42-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchapplication/octet-stream; name=v42-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchDownload
From ead7054169837fd4a90836210ae141e3f8bb4f98 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 23 Sep 2024 14:03:54 +0300
Subject: [PATCH v42 1/3] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is an i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows handling long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 281 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out | 270 ++++++++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/expected/rowsecurity.out  |   7 +
 src/test/regress/expected/stats_ext.out    |  12 +
 src/test/regress/expected/uuid.out         |  31 +++
 src/test/regress/sql/create_index.sql      |  69 +++++
 src/test/regress/sql/join.sql              |   9 +
 src/test/regress/sql/rowsecurity.sql       |   1 +
 src/test/regress/sql/stats_ext.sql         |   3 +
 src/test/regress/sql/uuid.sql              |  12 +
 11 files changed, 729 insertions(+), 23 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..b24b10b986b 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -32,8 +33,10 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "utils/syscache.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -177,6 +180,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2149,7 +2156,10 @@ match_clause_to_index(PlannerInfo *root,
  *	  (3)  must match the collation of the index, if collation is relevant.
  *
  *	  Our definition of "const" is exceedingly liberal: we allow anything that
- *	  doesn't involve a volatile function or a Var of the index's relation.
+ *	  doesn't involve a volatile function or a Var of the index's relation
+ *	  except for a boolean OR expression input: due to a trade-off between the
+ *	  expected execution speedup and planning complexity, we limit or->saop
+ *	  transformation by obvious cases when an index scan can get a profit.
  *	  In particular, Vars belonging to other relations of the query are
  *	  accepted here, since a clause of that form can be used in a
  *	  parameterized indexscan.  It's the responsibility of higher code levels
@@ -2179,6 +2189,10 @@ match_clause_to_index(PlannerInfo *root,
  *	  It is also possible to match ScalarArrayOpExpr clauses to indexes, when
  *	  the clause is of the form "indexkey op ANY (arrayconst)".
  *
+ *	  It is also possible to match a list of OR clauses if it might be
+ *	  transformed into a single ScalarArrayOpExpr clause.  On success,
+ *	  the returning index clause will contain a trasformed clause.
+ *
  *	  For boolean indexes, it is also possible to match the clause directly
  *	  to the indexkey; or perhaps the clause is (NOT indexkey).
  *
@@ -2228,9 +2242,9 @@ match_clause_to_indexcol(PlannerInfo *root,
 	}
 
 	/*
-	 * Clause must be an opclause, funcclause, ScalarArrayOpExpr, or
-	 * RowCompareExpr.  Or, if the index supports it, we can handle IS
-	 * NULL/NOT NULL clauses.
+	 * Clause must be an opclause, funcclause, ScalarArrayOpExpr,
+	 * RowCompareExpr, or OR-clause that could be converted to SAOP.  Or, if
+	 * the index supports it, we can handle IS NULL/NOT NULL clauses.
 	 */
 	if (IsA(clause, OpExpr))
 	{
@@ -2248,6 +2262,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2789,261 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ *
+ * Given a list of OR-clause args, attempts to transform this BoolExpr into
+ * a single SAOP expression. On success, returns an IndexClause, containing
+ * the transformed expression or NULL, if failed.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Try to convert a list of OR-clauses to a single SAOP expression. Each
+	 * OR entry must be in the form: (indexkey operator constant) or (constant
+	 * operator indexkey).  Operators of all the entries must match. Constant
+	 * might be either Const or Param. To be effective, give up on the first
+	 * non-matching entry. Exit is implemented as a break from the loop, which
+	 * is catched afterwards.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			break;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses can match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			break;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			break;
+
+		/*
+		 * The parameters below must match between sub-rinfo and its parent as
+		 * make_restrictinfo() fills them with the same values, and further
+		 * modifications are also the same for the whole subtree. However,
+		 * still make a sanity check.
+		 */
+		Assert(subRinfo->is_pushed_down == rinfo->is_pushed_down);
+		Assert(subRinfo->is_clone == rinfo->is_clone);
+		Assert(subRinfo->security_level == rinfo->security_level);
+		Assert(bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids));
+		Assert(bms_equal(subRinfo->outer_relids, rinfo->outer_relids));
+
+		/*
+		 * Also, check that required_relids in sub-rinfo is subset of parent's
+		 * required_relids.
+		 */
+		Assert(bms_is_subset(subRinfo->required_relids, rinfo->required_relids));
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			break;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				break;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			break;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			break;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			break;
+
+		/*
+		 * Save information about the operator, type, and collation for the
+		 * first matching qual. Then, check that subsequent quals match the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * Check that the operator is presented in the opfamily and that
+			 * the expression collation matches the index collation. Also,
+			 * there must be an array type to construct an array later.
+			 */
+			if (!IndexCollMatchesExprColl(index->indexcollations[indexcol], inputcollid) ||
+				!op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+				!OidIsValid(arraytype))
+				break;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				break;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	/*
+	 * Catch the break from the loop above.  Normally, a foreach() loop ends
+	 * up with a NULL list cell.  A non-NULL list cell indicates a break from
+	 * the foreach() loop.  Free the consts list and return NULL then.
+	 */
+	if (lc != NULL)
+	{
+		list_free(consts);
+		return NULL;
+	}
+
+	/*
+	 * Assemble an array from the list of constants. It seems more profitable
+	 * to build a const array. But in the presence of parameters, we don't
+	 * have a specific value here and must employ an ArrayExpr instead.
+	 */
+
+	if (have_param)
+	{
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = get_opcode(matchOpno);
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	/*
+	 * Finally, build an IndexClause based on the SAOP node. Use
+	 * make_simple_restrictinfo() to get RestrictInfo with clean selectivity
+	 * estimations because it may differ from the estimation made for an OR
+	 * clause. Although it is not a lossy expression, keep the old version of
+	 * rinfo in iclause->rinfo to detect duplicates and recheck the original
+	 * clause.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = rinfo;
+	iclause->indexquals = list_make1(make_simple_restrictinfo(root,
+															  &saopexpr->xpr));
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index d3358dfc394..e4d117e47ae 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,67 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                   QUERY PLAN                                    
+---------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,6 +1913,27 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1872,6 +1942,102 @@ SELECT count(*) FROM tenk1
  Aggregate
    ->  Bitmap Heap Scan on tenk1
          Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand < 42) OR (thousand < 99) OR (43 > thousand) OR (42 > thousand)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                             QUERY PLAN                                              
+-----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,16 +2045,90 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 756c2e24965..6d02360cf43 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 319190855bd..ef890b96cc6 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4492,6 +4492,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index fe162cc7c30..71a7115067e 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -732,12 +732,81 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 0c65e5af4be..8f6acb5f618 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 3011d71b12b..6d2414b6044 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
-- 
2.39.5 (Apple Git-154)

v42-0003-Allow-match_orclause_to_indexcol-for-joins.patchapplication/octet-stream; name=v42-0003-Allow-match_orclause_to_indexcol-for-joins.patchDownload
From 038061bce7edfa228df57e1a9e1ce6abeed40015 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Wed, 9 Oct 2024 18:44:25 +0300
Subject: [PATCH v42 3/3] Allow match_orclause_to_indexcol() for joins

---
 src/backend/optimizer/path/indxpath.c | 19 ++++++++++---------
 src/test/regress/expected/join.out    | 10 +++++-----
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 5c8b64a5b1e..ed3f8ff9991 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -2418,8 +2418,8 @@ match_join_clauses_to_index(PlannerInfo *root,
 		/* Potentially usable, so see if it matches the index or is an OR */
 		if (restriction_is_or_clause(rinfo))
 			*joinorclauses = lappend(*joinorclauses, rinfo);
-		else
-			match_clause_to_index(root, rinfo, index, clauseset);
+
+		match_clause_to_index(root, rinfo, index, clauseset);
 	}
 }
 
@@ -3229,6 +3229,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Oid			inputcollid = InvalidOid;
 	bool		firstTime = true;
 	bool		have_param = false;
+	Index		index_relid = index->rel->relid;
 
 	Assert(IsA(orclause, BoolExpr));
 	Assert(orclause->boolop == OR_EXPR);
@@ -3295,12 +3296,16 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		 */
 		leftop = (Node *) linitial(subClause->args);
 		rightop = (Node *) lsecond(subClause->args);
-		if (match_index_to_operand(leftop, indexcol, index))
+		if (match_index_to_operand(leftop, indexcol, index) &&
+			!bms_is_member(index_relid, rinfo->right_relids) &&
+			!contain_volatile_functions(rightop))
 		{
 			indexExpr = leftop;
 			constExpr = rightop;
 		}
-		else if (match_index_to_operand(rightop, indexcol, index))
+		else if (match_index_to_operand(rightop, indexcol, index) &&
+			!bms_is_member(index_relid, rinfo->left_relids) &&
+			!contain_volatile_functions(leftop))
 		{
 			opno = get_commutator(opno);
 			if (!OidIsValid(opno))
@@ -3327,10 +3332,6 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		if (IsA(indexExpr, RelabelType))
 			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
 
-		/* We allow constant to be Const or Param */
-		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
-			break;
-
 		/* Forbid transformation for composite types, records. */
 		if (type_is_rowtype(exprType(constExpr)) ||
 			type_is_rowtype(exprType(indexExpr)))
@@ -3367,7 +3368,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 				break;
 		}
 
-		if (IsA(constExpr, Param))
+		if (!IsA(constExpr, Const))
 			have_param = true;
 		consts = lappend(consts, constExpr);
 	}
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 198b9168045..b4354c12079 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -3729,8 +3729,8 @@ select * from
   tenk1 join int4_tbl on f1 = twothousand,
   q1, q2
 where q1 = thousand or q2 = thousand;
-                               QUERY PLAN                               
-------------------------------------------------------------------------
+                                                                                QUERY PLAN                                                                                
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Hash Join
    Hash Cond: (tenk1.twothousand = int4_tbl.f1)
    ->  Nested Loop
@@ -3738,12 +3738,12 @@ where q1 = thousand or q2 = thousand;
                ->  Seq Scan on q1
                ->  Seq Scan on q2
          ->  Bitmap Heap Scan on tenk1
-               Recheck Cond: ((q1.q1 = thousand) OR (q2.q2 = thousand))
+               Recheck Cond: (((q1.q1 = thousand) AND ((q1.q1 = thousand) OR (q2.q2 = thousand))) OR ((q2.q2 = thousand) AND ((q1.q1 = thousand) OR (q2.q2 = thousand))))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = q1.q1)
+                           Index Cond: ((thousand = q1.q1) AND (thousand = ANY (ARRAY[q1.q1, q2.q2])))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = q2.q2)
+                           Index Cond: ((thousand = q2.q2) AND (thousand = ANY (ARRAY[q1.q1, q2.q2])))
    ->  Hash
          ->  Seq Scan on int4_tbl
 (15 rows)
-- 
2.39.5 (Apple Git-154)

v42-0002-Teach-bitmap-path-generation-about-transforming-.patchapplication/octet-stream; name=v42-0002-Teach-bitmap-path-generation-about-transforming-.patchDownload
From 2e946aa04985e08cb7d32967141fe610421f426f Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 23 Sep 2024 14:04:03 +0300
Subject: [PATCH v42 2/3] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 426 ++++++++++++++++++++-
 src/backend/optimizer/util/restrictinfo.c  | 107 +++---
 src/include/optimizer/restrictinfo.h       |  11 +
 src/test/regress/expected/create_index.out | 125 +++++-
 src/test/regress/expected/join.out         |  56 ++-
 src/test/regress/sql/create_index.sql      |  38 ++
 src/tools/pgindent/typedefs.list           |   1 +
 7 files changed, 657 insertions(+), 107 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index b24b10b986b..5c8b64a5b1e 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1173,6 +1173,383 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Utility structure used to group similar OR-clause arguments in
+ * group_similar_or_args().  It represents information about the OR-clause
+ * argument and its matching index key.
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index, or -1 if no
+								 * matching index */
+	int			colnum;			/* index of the matching column, or -1 if no
+								 * matching index */
+	Oid			opno;			/* OID of the OpClause operator, or InvalidOid
+								 * if not an OpExpr */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Transform incoming OR-restrictinfo into a list of sub-restrictinfos,
+ *		each of them containing a subset of OR-clauses from the source rinfo
+ *		matching the same index column with the same operator and collation,
+ *		It may be employed later, during the match_clause_to_indexcol() to
+ *		transform whole OR-sub-rinfo to an SAOP clause.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constant may comprise either Const
+ * or Param.
+ *
+ * Returns the processed list of arguments.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	bool		matched = false;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * To avoid N^2 behavior, take utility pass along the list of OR-clause
+	 * arguments.  For each argument, fill the OrArgIndexMatch structure,
+	 * which will be used to sort these arguments at the next step.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses can match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			continue;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+					matched = true;
+					break;
+				}
+			}
+
+			/*
+			 * Stop looping through the indexes, if we managed to match
+			 * nonConstExpr to any index column.
+			 */
+			if (matches[i].indexnum >= 0)
+				break;
+			indexnum++;
+		}
+	}
+
+	/*
+	 * Fast-path check: if no clause is matching to the index column, we can
+	 * just give up at this stage and return the clause list as-is.
+	 */
+	if (!matched)
+	{
+		pfree(matches);
+		return orargs;
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/*
+	 * Group similar clauses into single sub-restrictinfo. Side effect: the
+	 * resulting list of restrictions will be sorted by indexnum and colnum.
+	 */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				List	   *rargs = NIL;
+				RestrictInfo *subrinfo;
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+				{
+					Node	   *arg = list_nth(orargs, matches[j].argindex);
+
+					rargs = lappend(rargs, arg);
+					if (IsA(arg, RestrictInfo))
+						args = lappend(args, ((RestrictInfo *) arg)->clause);
+					else
+						args = lappend(args, arg);
+				}
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				subrinfo = make_plain_restrictinfo(root,
+												   make_orclause(args),
+												   make_orclause(rargs),
+												   rinfo->is_pushed_down,
+												   rinfo->has_clone,
+												   rinfo->is_clone,
+												   rinfo->pseudoconstant,
+												   rinfo->security_level,
+												   rinfo->required_relids,
+												   rinfo->incompatible_relids,
+												   rinfo->outer_relids);
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->orclause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+	}
+
+	/*
+	 * If we manage to find a bitmap scan, which uses the group of OR-clause
+	 * arguments as a whole, we can skip matching OR-clause arguments
+	 * one-by-one as long as there are no other clauses, which can bring more
+	 * efficiency to one-by-one case.
+	 */
+	if (jointlist != NIL && other_clauses == NIL)
+		return jointlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1203,6 +1580,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1213,7 +1591,13 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into dedicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as a whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1233,12 +1617,40 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+				List	   *inner_other_clauses;
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.  In this case we need to immediately remove the
+				 * rinfo from other clauses.  This is because rinfo can be
+				 * transformed during index matching.  So, we might be unable
+				 * to remove that later.
+				 */
+				inner_other_clauses = list_delete(list_copy(all_clauses), rinfo);
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 inner_other_clauses);
+				list_free(inner_other_clauses);
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
@@ -2441,7 +2853,7 @@ match_opclause_to_indexcol(PlannerInfo *root,
 
 	/*
 	 * Check for clauses of the form: (indexkey operator constant) or
-	 * (constant operator indexkey).  See match_clause_to_indexcol's notes
+	 * (constant operator indexkey).  See match_clause_to_indexcol()'s notes
 	 * about const-ness.
 	 *
 	 * Note that we don't ask the support function about clauses that don't
@@ -3002,8 +3414,12 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
 
 		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
-		foreach(lc, consts)
-			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+		foreach_node(Const, value, consts)
+		{
+			Assert(!value->constisnull && value->constvalue);
+
+			elems[i++] = value->constvalue;
+		}
 
 		arrayConst = construct_array(elems, i, consttype,
 									 typlen, typbyval, typalign);
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e93342..9e1458401c2 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -21,17 +21,6 @@
 #include "optimizer/restrictinfo.h"
 
 
-static RestrictInfo *make_restrictinfo_internal(PlannerInfo *root,
-												Expr *clause,
-												Expr *orclause,
-												bool is_pushed_down,
-												bool has_clone,
-												bool is_clone,
-												bool pseudoconstant,
-												Index security_level,
-												Relids required_relids,
-												Relids incompatible_relids,
-												Relids outer_relids);
 static Expr *make_sub_restrictinfos(PlannerInfo *root,
 									Expr *clause,
 									bool is_pushed_down,
@@ -90,36 +79,38 @@ make_restrictinfo(PlannerInfo *root,
 	/* Shouldn't be an AND clause, else AND/OR flattening messed up */
 	Assert(!is_andclause(clause));
 
-	return make_restrictinfo_internal(root,
-									  clause,
-									  NULL,
-									  is_pushed_down,
-									  has_clone,
-									  is_clone,
-									  pseudoconstant,
-									  security_level,
-									  required_relids,
-									  incompatible_relids,
-									  outer_relids);
+	return make_plain_restrictinfo(root,
+								   clause,
+								   NULL,
+								   is_pushed_down,
+								   has_clone,
+								   is_clone,
+								   pseudoconstant,
+								   security_level,
+								   required_relids,
+								   incompatible_relids,
+								   outer_relids);
 }
 
 /*
- * make_restrictinfo_internal
+ * make_plain_restrictinfo
  *
- * Common code for the main entry points and the recursive cases.
+ * Common code for the main entry points and the recursive cases.  Also,
+ * useful while contrucitng RestrictInfos above OR clause, which already has
+ * RestrictInfos above its subclauses.
  */
-static RestrictInfo *
-make_restrictinfo_internal(PlannerInfo *root,
-						   Expr *clause,
-						   Expr *orclause,
-						   bool is_pushed_down,
-						   bool has_clone,
-						   bool is_clone,
-						   bool pseudoconstant,
-						   Index security_level,
-						   Relids required_relids,
-						   Relids incompatible_relids,
-						   Relids outer_relids)
+RestrictInfo *
+make_plain_restrictinfo(PlannerInfo *root,
+						Expr *clause,
+						Expr *orclause,
+						bool is_pushed_down,
+						bool has_clone,
+						bool is_clone,
+						bool pseudoconstant,
+						Index security_level,
+						Relids required_relids,
+						Relids incompatible_relids,
+						Relids outer_relids)
 {
 	RestrictInfo *restrictinfo = makeNode(RestrictInfo);
 	Relids		baserels;
@@ -296,17 +287,17 @@ make_sub_restrictinfos(PlannerInfo *root,
 													NULL,
 													incompatible_relids,
 													outer_relids));
-		return (Expr *) make_restrictinfo_internal(root,
-												   clause,
-												   make_orclause(orlist),
-												   is_pushed_down,
-												   has_clone,
-												   is_clone,
-												   pseudoconstant,
-												   security_level,
-												   required_relids,
-												   incompatible_relids,
-												   outer_relids);
+		return (Expr *) make_plain_restrictinfo(root,
+												clause,
+												make_orclause(orlist),
+												is_pushed_down,
+												has_clone,
+												is_clone,
+												pseudoconstant,
+												security_level,
+												required_relids,
+												incompatible_relids,
+												outer_relids);
 	}
 	else if (is_andclause(clause))
 	{
@@ -328,17 +319,17 @@ make_sub_restrictinfos(PlannerInfo *root,
 		return make_andclause(andlist);
 	}
 	else
-		return (Expr *) make_restrictinfo_internal(root,
-												   clause,
-												   NULL,
-												   is_pushed_down,
-												   has_clone,
-												   is_clone,
-												   pseudoconstant,
-												   security_level,
-												   required_relids,
-												   incompatible_relids,
-												   outer_relids);
+		return (Expr *) make_plain_restrictinfo(root,
+												clause,
+												NULL,
+												is_pushed_down,
+												has_clone,
+												is_clone,
+												pseudoconstant,
+												security_level,
+												required_relids,
+												incompatible_relids,
+												outer_relids);
 }
 
 /*
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 1b42c832c59..b77bf7ddfe9 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -22,6 +22,17 @@
 	make_restrictinfo(root, clause, true, false, false, false, 0, \
 		NULL, NULL, NULL)
 
+extern RestrictInfo *make_plain_restrictinfo(PlannerInfo *root,
+											 Expr *clause,
+											 Expr *orclause,
+											 bool is_pushed_down,
+											 bool has_clone,
+											 bool is_clone,
+											 bool pseudoconstant,
+											 Index security_level,
+											 Relids required_relids,
+											 Relids incompatible_relids,
+											 Relids outer_relids);
 extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Expr *clause,
 									   bool is_pushed_down,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index e4d117e47ae..b003492c5c8 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1875,6 +1875,60 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
+                                                                QUERY PLAN                                                                 
+-------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND (tenthous IS NULL)) OR ((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42))))
+   Filter: ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42) OR (tenthous IS NULL))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous IS NULL))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR ((tenthous)::smallint = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+                                                                     QUERY PLAN                                                                      
+-----------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND ((tenthous = '3'::bigint) OR (tenthous = '42'::bigint))) OR ((thousand = 42) AND (tenthous = '1'::smallint)))
+   Filter: ((tenthous = '1'::smallint) OR (tenthous = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{3,42}'::bigint[])))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = '1'::smallint))
+(8 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -2003,25 +2057,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                        
+--------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND (((thousand = 42) OR (thousand = 99)) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2033,22 +2086,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR ((thousand = 42) OR (thousand = 41))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
@@ -3144,6 +3196,49 @@ SELECT  b.relname,
 (2 rows)
 
 DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before;
+-- Check bitmap scan can consider similar OR arguments separately without
+-- grouping them into SAOP.
+CREATE TABLE bitmap_split_or (a int NOT NULL, b int NOT NULL, c int NOT NULL);
+INSERT INTO bitmap_split_or (SELECT 1, 1, i FROM generate_series(1, 1000) i);
+INSERT INTO bitmap_split_or (select i, 2, 2 FROM generate_series(1, 1000) i);
+VACUUM ANALYZE bitmap_split_or;
+CREATE INDEX t_b_partial_1_idx ON bitmap_split_or (b) WHERE a = 1;
+CREATE INDEX t_b_partial_2_idx ON bitmap_split_or (b) WHERE a = 2;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or WHERE (a = 1 OR a = 2) AND b = 2;
+                            QUERY PLAN                            
+------------------------------------------------------------------
+ Bitmap Heap Scan on bitmap_split_or
+   Recheck Cond: (((b = 2) AND (a = 1)) OR ((b = 2) AND (a = 2)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on t_b_partial_1_idx
+               Index Cond: (b = 2)
+         ->  Bitmap Index Scan on t_b_partial_2_idx
+               Index Cond: (b = 2)
+(7 rows)
+
+DROP INDEX t_b_partial_1_idx;
+DROP INDEX t_b_partial_2_idx;
+CREATE INDEX t_a_b_idx ON bitmap_split_or (a, b);
+CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
+CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
+CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
+ANALYZE bitmap_split_or;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
+                            QUERY PLAN                            
+------------------------------------------------------------------
+ Bitmap Heap Scan on bitmap_split_or
+   Recheck Cond: (((b = 1) AND (c = 2)) OR ((a = 1) AND (b = 2)))
+   Filter: ((a = 1) AND (c = 2))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on t_b_c_idx
+               Index Cond: ((b = 1) AND (c = 2))
+         ->  Bitmap Index Scan on t_a_b_idx
+               Index Cond: ((a = 1) AND (b = 2))
+(8 rows)
+
+DROP TABLE bitmap_split_or;
 --
 -- REINDEX SCHEMA
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 6d02360cf43..198b9168045 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR ((unique1 = 3) OR (unique1 = 1)) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 71a7115067e..216bd9660c3 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -738,6 +738,23 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1321,6 +1338,27 @@ SELECT  b.relname,
   ORDER BY 1;
 DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before;
 
+-- Check bitmap scan can consider similar OR arguments separately without
+-- grouping them into SAOP.
+CREATE TABLE bitmap_split_or (a int NOT NULL, b int NOT NULL, c int NOT NULL);
+INSERT INTO bitmap_split_or (SELECT 1, 1, i FROM generate_series(1, 1000) i);
+INSERT INTO bitmap_split_or (select i, 2, 2 FROM generate_series(1, 1000) i);
+VACUUM ANALYZE bitmap_split_or;
+CREATE INDEX t_b_partial_1_idx ON bitmap_split_or (b) WHERE a = 1;
+CREATE INDEX t_b_partial_2_idx ON bitmap_split_or (b) WHERE a = 2;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or WHERE (a = 1 OR a = 2) AND b = 2;
+DROP INDEX t_b_partial_1_idx;
+DROP INDEX t_b_partial_2_idx;
+CREATE INDEX t_a_b_idx ON bitmap_split_or (a, b);
+CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
+CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
+CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
+ANALYZE bitmap_split_or;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
+DROP TABLE bitmap_split_or;
+
 --
 -- REINDEX SCHEMA
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index a65e1c07c5d..3926c1e65b4 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1766,6 +1766,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.39.5 (Apple Git-154)

#276Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#275)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 10/12/24 21:25, Alexander Korotkov wrote:

I forgot to specify (COSTS OFF) for EXPLAINs in regression tests. Fixed in v42.

I've passed through the patch set.

Let me put aside the v42-0003 patch—it looks debatable, and I need time
to analyse the change in regression tests caused by this patch.

Comments look much better according to my current language level. Ideas
with fast exits also look profitable and are worth an additional
'matched' variable.

So, in general, it is ok. I think only one place with
inner_other_clauses can be improved. Maybe it will be enough to create
this list only once, outside 'foreach(j, groupedArgs)' cycle? Also, the
comment on the necessity of this operation was unclear to me. See the
attachment for my modest attempt at improving it.

--
regards, Andrei Lepikhov

Attachments:

minor-fix.txttext/plain; charset=UTF-8; name=minor-fix.txtDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 5c8b64a5b1..0615c6d4de 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1581,6 +1581,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		Path	   *bitmapqual;
 		ListCell   *j;
 		List	   *groupedArgs;
+		List	   *inner_other_clauses = NIL;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1597,6 +1598,19 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * because those RestrictInfos might match to the index as a whole.
 		 */
 		groupedArgs = group_similar_or_args(root, rel, rinfo);
+
+		if (groupedArgs != ((BoolExpr *) rinfo->orclause)->args)
+			/*
+			 * Some parts of the rinfo were grouped. In this case we have a set
+			 * of sub-rinfos that together is an exact duplicate of rinfo.
+			 * In this case we need to remove the rinfo from other clauses.
+			 * match_clauses_to_index detects duplicated iclause by comparing
+			 * pointers to original rinfos that will be different. So, we must
+			 * delete rinfo to avoid de-facto duplicated clauses in the index
+			 * clauses list.
+			 */
+			inner_other_clauses = list_delete(list_copy(all_clauses), rinfo);
+
 		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
@@ -1620,20 +1634,14 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
-				List	   *inner_other_clauses;
 
 				/*
 				 * Generate bitmap paths for the group of similar OR-clause
-				 * arguments.  In this case we need to immediately remove the
-				 * rinfo from other clauses.  This is because rinfo can be
-				 * transformed during index matching.  So, we might be unable
-				 * to remove that later.
+				 * arguments.
 				 */
-				inner_other_clauses = list_delete(list_copy(all_clauses), rinfo);
 				indlist = make_bitmap_paths_for_or_group(root,
 														 rel, ri,
 														 inner_other_clauses);
-				list_free(inner_other_clauses);
 
 				if (indlist == NIL)
 				{
@@ -1676,6 +1684,8 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 			pathlist = lappend(pathlist, bitmapqual);
 		}
 
+		list_free(inner_other_clauses);
+
 		/*
 		 * If we have a match for every arm, then turn them into a
 		 * BitmapOrPath, and add to result list.
#277Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#276)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Wed, Oct 16, 2024 at 7:22 AM Andrei Lepikhov <lepihov@gmail.com> wrote:

On 10/12/24 21:25, Alexander Korotkov wrote:

I forgot to specify (COSTS OFF) for EXPLAINs in regression tests. Fixed in v42.

I've passed through the patch set.

Let me put aside the v42-0003 patch—it looks debatable, and I need time
to analyse the change in regression tests caused by this patch.

Yes, 0003 patch is for illustration purposes for now. I will not keep
rebasing it. We can pick it later when main patches are committed.

Comments look much better according to my current language level. Ideas
with fast exits also look profitable and are worth an additional
'matched' variable.

So, in general, it is ok. I think only one place with
inner_other_clauses can be improved. Maybe it will be enough to create
this list only once, outside 'foreach(j, groupedArgs)' cycle? Also, the
comment on the necessity of this operation was unclear to me. See the
attachment for my modest attempt at improving it.

Thank you, I've integrated your patch with minor edits from me.

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v43-0002-Teach-bitmap-path-generation-about-transforming-.patchapplication/octet-stream; name=v43-0002-Teach-bitmap-path-generation-about-transforming-.patchDownload
From 4973458e71db18df07c1b8c753d965bf9a4f2cbe Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 23 Sep 2024 14:04:03 +0300
Subject: [PATCH v43 2/2] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
---
 src/backend/optimizer/path/indxpath.c      | 439 ++++++++++++++++++++-
 src/backend/optimizer/util/restrictinfo.c  | 107 +++--
 src/include/optimizer/restrictinfo.h       |  11 +
 src/test/regress/expected/create_index.out | 125 +++++-
 src/test/regress/expected/join.out         |  56 ++-
 src/test/regress/sql/create_index.sql      |  38 ++
 src/tools/pgindent/typedefs.list           |   1 +
 7 files changed, 670 insertions(+), 107 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index b24b10b986b..3da7ea8ed57 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1173,6 +1173,383 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Utility structure used to group similar OR-clause arguments in
+ * group_similar_or_args().  It represents information about the OR-clause
+ * argument and its matching index key.
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index, or -1 if no
+								 * matching index */
+	int			colnum;			/* index of the matching column, or -1 if no
+								 * matching index */
+	Oid			opno;			/* OID of the OpClause operator, or InvalidOid
+								 * if not an OpExpr */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Transform incoming OR-restrictinfo into a list of sub-restrictinfos,
+ *		each of them containing a subset of OR-clauses from the source rinfo
+ *		matching the same index column with the same operator and collation,
+ *		It may be employed later, during the match_clause_to_indexcol() to
+ *		transform whole OR-sub-rinfo to an SAOP clause.
+ *
+ * Similar arguments clauses of form "indexkey op constant" having same
+ * indexkey, operator, and collation.  Constant may comprise either Const
+ * or Param.
+ *
+ * Returns the processed list of arguments.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	bool		matched = false;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * To avoid N^2 behavior, take utility pass along the list of OR-clause
+	 * arguments.  For each argument, fill the OrArgIndexMatch structure,
+	 * which will be used to sort these arguments at the next step.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses can match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			continue;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+					matched = true;
+					break;
+				}
+			}
+
+			/*
+			 * Stop looping through the indexes, if we managed to match
+			 * nonConstExpr to any index column.
+			 */
+			if (matches[i].indexnum >= 0)
+				break;
+			indexnum++;
+		}
+	}
+
+	/*
+	 * Fast-path check: if no clause is matching to the index column, we can
+	 * just give up at this stage and return the clause list as-is.
+	 */
+	if (!matched)
+	{
+		pfree(matches);
+		return orargs;
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/*
+	 * Group similar clauses into single sub-restrictinfo. Side effect: the
+	 * resulting list of restrictions will be sorted by indexnum and colnum.
+	 */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				List	   *rargs = NIL;
+				RestrictInfo *subrinfo;
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+				{
+					Node	   *arg = list_nth(orargs, matches[j].argindex);
+
+					rargs = lappend(rargs, arg);
+					if (IsA(arg, RestrictInfo))
+						args = lappend(args, ((RestrictInfo *) arg)->clause);
+					else
+						args = lappend(args, arg);
+				}
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				subrinfo = make_plain_restrictinfo(root,
+												   make_orclause(args),
+												   make_orclause(rargs),
+												   rinfo->is_pushed_down,
+												   rinfo->has_clone,
+												   rinfo->is_clone,
+												   rinfo->pseudoconstant,
+												   rinfo->security_level,
+												   rinfo->required_relids,
+												   rinfo->incompatible_relids,
+												   rinfo->outer_relids);
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->orclause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+	}
+
+	/*
+	 * If we manage to find a bitmap scan, which uses the group of OR-clause
+	 * arguments as a whole, we can skip matching OR-clause arguments
+	 * one-by-one as long as there are no other clauses, which can bring more
+	 * efficiency to one-by-one case.
+	 */
+	if (jointlist != NIL && other_clauses == NIL)
+		return jointlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1203,6 +1580,8 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
+		List	   *inner_other_clauses = NIL;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1213,7 +1592,28 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause argument into dedicated RestrictInfos,
+		 * because those RestrictInfos might match to the index as a whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+
+		if (groupedArgs != ((BoolExpr *) rinfo->orclause)->args)
+		{
+			/*
+			 * Some parts of the rinfo were grouped. In this case, we have a
+			 * set of sub-rinfos that together are an exact duplicate of
+			 * rinfo. Thus, we need to remove the rinfo from other clauses.
+			 * match_clauses_to_index detects duplicated iclauses by comparing
+			 * pointers to original rinfos that would be different. So, we
+			 * must delete rinfo to avoid de-facto duplicated clauses in the
+			 * index clauses list.
+			 */
+			inner_other_clauses = list_delete(list_copy(all_clauses), rinfo);
+		}
+
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1233,12 +1633,34 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.
+				 */
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 inner_other_clauses);
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
@@ -1264,6 +1686,9 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 			pathlist = lappend(pathlist, bitmapqual);
 		}
 
+		if (inner_other_clauses != NIL)
+			list_free(inner_other_clauses);
+
 		/*
 		 * If we have a match for every arm, then turn them into a
 		 * BitmapOrPath, and add to result list.
@@ -2441,7 +2866,7 @@ match_opclause_to_indexcol(PlannerInfo *root,
 
 	/*
 	 * Check for clauses of the form: (indexkey operator constant) or
-	 * (constant operator indexkey).  See match_clause_to_indexcol's notes
+	 * (constant operator indexkey).  See match_clause_to_indexcol()'s notes
 	 * about const-ness.
 	 *
 	 * Note that we don't ask the support function about clauses that don't
@@ -3002,8 +3427,12 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
 
 		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
-		foreach(lc, consts)
-			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+		foreach_node(Const, value, consts)
+		{
+			Assert(!value->constisnull && value->constvalue);
+
+			elems[i++] = value->constvalue;
+		}
 
 		arrayConst = construct_array(elems, i, consttype,
 									 typlen, typbyval, typalign);
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e93342..9e1458401c2 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -21,17 +21,6 @@
 #include "optimizer/restrictinfo.h"
 
 
-static RestrictInfo *make_restrictinfo_internal(PlannerInfo *root,
-												Expr *clause,
-												Expr *orclause,
-												bool is_pushed_down,
-												bool has_clone,
-												bool is_clone,
-												bool pseudoconstant,
-												Index security_level,
-												Relids required_relids,
-												Relids incompatible_relids,
-												Relids outer_relids);
 static Expr *make_sub_restrictinfos(PlannerInfo *root,
 									Expr *clause,
 									bool is_pushed_down,
@@ -90,36 +79,38 @@ make_restrictinfo(PlannerInfo *root,
 	/* Shouldn't be an AND clause, else AND/OR flattening messed up */
 	Assert(!is_andclause(clause));
 
-	return make_restrictinfo_internal(root,
-									  clause,
-									  NULL,
-									  is_pushed_down,
-									  has_clone,
-									  is_clone,
-									  pseudoconstant,
-									  security_level,
-									  required_relids,
-									  incompatible_relids,
-									  outer_relids);
+	return make_plain_restrictinfo(root,
+								   clause,
+								   NULL,
+								   is_pushed_down,
+								   has_clone,
+								   is_clone,
+								   pseudoconstant,
+								   security_level,
+								   required_relids,
+								   incompatible_relids,
+								   outer_relids);
 }
 
 /*
- * make_restrictinfo_internal
+ * make_plain_restrictinfo
  *
- * Common code for the main entry points and the recursive cases.
+ * Common code for the main entry points and the recursive cases.  Also,
+ * useful while contrucitng RestrictInfos above OR clause, which already has
+ * RestrictInfos above its subclauses.
  */
-static RestrictInfo *
-make_restrictinfo_internal(PlannerInfo *root,
-						   Expr *clause,
-						   Expr *orclause,
-						   bool is_pushed_down,
-						   bool has_clone,
-						   bool is_clone,
-						   bool pseudoconstant,
-						   Index security_level,
-						   Relids required_relids,
-						   Relids incompatible_relids,
-						   Relids outer_relids)
+RestrictInfo *
+make_plain_restrictinfo(PlannerInfo *root,
+						Expr *clause,
+						Expr *orclause,
+						bool is_pushed_down,
+						bool has_clone,
+						bool is_clone,
+						bool pseudoconstant,
+						Index security_level,
+						Relids required_relids,
+						Relids incompatible_relids,
+						Relids outer_relids)
 {
 	RestrictInfo *restrictinfo = makeNode(RestrictInfo);
 	Relids		baserels;
@@ -296,17 +287,17 @@ make_sub_restrictinfos(PlannerInfo *root,
 													NULL,
 													incompatible_relids,
 													outer_relids));
-		return (Expr *) make_restrictinfo_internal(root,
-												   clause,
-												   make_orclause(orlist),
-												   is_pushed_down,
-												   has_clone,
-												   is_clone,
-												   pseudoconstant,
-												   security_level,
-												   required_relids,
-												   incompatible_relids,
-												   outer_relids);
+		return (Expr *) make_plain_restrictinfo(root,
+												clause,
+												make_orclause(orlist),
+												is_pushed_down,
+												has_clone,
+												is_clone,
+												pseudoconstant,
+												security_level,
+												required_relids,
+												incompatible_relids,
+												outer_relids);
 	}
 	else if (is_andclause(clause))
 	{
@@ -328,17 +319,17 @@ make_sub_restrictinfos(PlannerInfo *root,
 		return make_andclause(andlist);
 	}
 	else
-		return (Expr *) make_restrictinfo_internal(root,
-												   clause,
-												   NULL,
-												   is_pushed_down,
-												   has_clone,
-												   is_clone,
-												   pseudoconstant,
-												   security_level,
-												   required_relids,
-												   incompatible_relids,
-												   outer_relids);
+		return (Expr *) make_plain_restrictinfo(root,
+												clause,
+												NULL,
+												is_pushed_down,
+												has_clone,
+												is_clone,
+												pseudoconstant,
+												security_level,
+												required_relids,
+												incompatible_relids,
+												outer_relids);
 }
 
 /*
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index fe03a8ecd34..f32dae8620b 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -22,6 +22,17 @@
 	make_restrictinfo(root, clause, true, false, false, false, 0, \
 		NULL, NULL, NULL)
 
+extern RestrictInfo *make_plain_restrictinfo(PlannerInfo *root,
+											 Expr *clause,
+											 Expr *orclause,
+											 bool is_pushed_down,
+											 bool has_clone,
+											 bool is_clone,
+											 bool pseudoconstant,
+											 Index security_level,
+											 Relids required_relids,
+											 Relids incompatible_relids,
+											 Relids outer_relids);
 extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Expr *clause,
 									   bool is_pushed_down,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index e4d117e47ae..b003492c5c8 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1875,6 +1875,60 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
+                                                                QUERY PLAN                                                                 
+-------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND (tenthous IS NULL)) OR ((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42))))
+   Filter: ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42) OR (tenthous IS NULL))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous IS NULL))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR ((tenthous)::smallint = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+                                                                     QUERY PLAN                                                                      
+-----------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND ((tenthous = '3'::bigint) OR (tenthous = '42'::bigint))) OR ((thousand = 42) AND (tenthous = '1'::smallint)))
+   Filter: ((tenthous = '1'::smallint) OR (tenthous = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{3,42}'::bigint[])))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = '1'::smallint))
+(8 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -2003,25 +2057,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                        
+--------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND (((thousand = 42) OR (thousand = 99)) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2033,22 +2086,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR ((thousand = 42) OR (thousand = 41))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
@@ -3144,6 +3196,49 @@ SELECT  b.relname,
 (2 rows)
 
 DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before;
+-- Check bitmap scan can consider similar OR arguments separately without
+-- grouping them into SAOP.
+CREATE TABLE bitmap_split_or (a int NOT NULL, b int NOT NULL, c int NOT NULL);
+INSERT INTO bitmap_split_or (SELECT 1, 1, i FROM generate_series(1, 1000) i);
+INSERT INTO bitmap_split_or (select i, 2, 2 FROM generate_series(1, 1000) i);
+VACUUM ANALYZE bitmap_split_or;
+CREATE INDEX t_b_partial_1_idx ON bitmap_split_or (b) WHERE a = 1;
+CREATE INDEX t_b_partial_2_idx ON bitmap_split_or (b) WHERE a = 2;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or WHERE (a = 1 OR a = 2) AND b = 2;
+                            QUERY PLAN                            
+------------------------------------------------------------------
+ Bitmap Heap Scan on bitmap_split_or
+   Recheck Cond: (((b = 2) AND (a = 1)) OR ((b = 2) AND (a = 2)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on t_b_partial_1_idx
+               Index Cond: (b = 2)
+         ->  Bitmap Index Scan on t_b_partial_2_idx
+               Index Cond: (b = 2)
+(7 rows)
+
+DROP INDEX t_b_partial_1_idx;
+DROP INDEX t_b_partial_2_idx;
+CREATE INDEX t_a_b_idx ON bitmap_split_or (a, b);
+CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
+CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
+CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
+ANALYZE bitmap_split_or;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
+                            QUERY PLAN                            
+------------------------------------------------------------------
+ Bitmap Heap Scan on bitmap_split_or
+   Recheck Cond: (((b = 1) AND (c = 2)) OR ((a = 1) AND (b = 2)))
+   Filter: ((a = 1) AND (c = 2))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on t_b_c_idx
+               Index Cond: ((b = 1) AND (c = 2))
+         ->  Bitmap Index Scan on t_a_b_idx
+               Index Cond: ((a = 1) AND (b = 2))
+(8 rows)
+
+DROP TABLE bitmap_split_or;
 --
 -- REINDEX SCHEMA
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 6d02360cf43..198b9168045 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4226,20 +4226,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4253,12 +4253,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4270,21 +4270,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4296,21 +4296,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4324,18 +4324,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR ((unique1 = 3) OR (unique1 = 1)) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 71a7115067e..216bd9660c3 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -738,6 +738,23 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1321,6 +1338,27 @@ SELECT  b.relname,
   ORDER BY 1;
 DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before;
 
+-- Check bitmap scan can consider similar OR arguments separately without
+-- grouping them into SAOP.
+CREATE TABLE bitmap_split_or (a int NOT NULL, b int NOT NULL, c int NOT NULL);
+INSERT INTO bitmap_split_or (SELECT 1, 1, i FROM generate_series(1, 1000) i);
+INSERT INTO bitmap_split_or (select i, 2, 2 FROM generate_series(1, 1000) i);
+VACUUM ANALYZE bitmap_split_or;
+CREATE INDEX t_b_partial_1_idx ON bitmap_split_or (b) WHERE a = 1;
+CREATE INDEX t_b_partial_2_idx ON bitmap_split_or (b) WHERE a = 2;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or WHERE (a = 1 OR a = 2) AND b = 2;
+DROP INDEX t_b_partial_1_idx;
+DROP INDEX t_b_partial_2_idx;
+CREATE INDEX t_a_b_idx ON bitmap_split_or (a, b);
+CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
+CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
+CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
+ANALYZE bitmap_split_or;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
+DROP TABLE bitmap_split_or;
+
 --
 -- REINDEX SCHEMA
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 57de1acff3a..dd356c78586 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1766,6 +1766,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.39.5 (Apple Git-154)

v43-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchapplication/octet-stream; name=v43-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchDownload
From ef99fc9bd21a6a774564b89196c4e13c9ecc452b Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Mon, 23 Sep 2024 14:03:54 +0300
Subject: [PATCH v43 1/2] Transform OR-clauses to SAOP's during index matching

Replace "(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" with
"indexkey op ANY(ARRAY[C1, C2, ...])" (ScalarArrayOpExpr node) during matching
a clause to index.

Here Ci is an i-th constant or parameters expression, 'expr' is non-constant
expression, 'op' is an operator which returns boolean result and has a commuter
(for the case of reverse order of constant and non-constant parts of the
expression, like 'Cn op expr').

This transformation allows handling long OR-clauses with single IndexScan
avoiding slower bitmap scans.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nikolay Shaplov <dhyan@nataraj.su>
---
 src/backend/optimizer/path/indxpath.c      | 281 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out | 270 ++++++++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/expected/rowsecurity.out  |   7 +
 src/test/regress/expected/stats_ext.out    |  12 +
 src/test/regress/expected/uuid.out         |  31 +++
 src/test/regress/sql/create_index.sql      |  69 +++++
 src/test/regress/sql/join.sql              |   9 +
 src/test/regress/sql/rowsecurity.sql       |   1 +
 src/test/regress/sql/stats_ext.sql         |   3 +
 src/test/regress/sql/uuid.sql              |  12 +
 11 files changed, 729 insertions(+), 23 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..b24b10b986b 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -32,8 +33,10 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "utils/syscache.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -177,6 +180,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2149,7 +2156,10 @@ match_clause_to_index(PlannerInfo *root,
  *	  (3)  must match the collation of the index, if collation is relevant.
  *
  *	  Our definition of "const" is exceedingly liberal: we allow anything that
- *	  doesn't involve a volatile function or a Var of the index's relation.
+ *	  doesn't involve a volatile function or a Var of the index's relation
+ *	  except for a boolean OR expression input: due to a trade-off between the
+ *	  expected execution speedup and planning complexity, we limit or->saop
+ *	  transformation by obvious cases when an index scan can get a profit.
  *	  In particular, Vars belonging to other relations of the query are
  *	  accepted here, since a clause of that form can be used in a
  *	  parameterized indexscan.  It's the responsibility of higher code levels
@@ -2179,6 +2189,10 @@ match_clause_to_index(PlannerInfo *root,
  *	  It is also possible to match ScalarArrayOpExpr clauses to indexes, when
  *	  the clause is of the form "indexkey op ANY (arrayconst)".
  *
+ *	  It is also possible to match a list of OR clauses if it might be
+ *	  transformed into a single ScalarArrayOpExpr clause.  On success,
+ *	  the returning index clause will contain a trasformed clause.
+ *
  *	  For boolean indexes, it is also possible to match the clause directly
  *	  to the indexkey; or perhaps the clause is (NOT indexkey).
  *
@@ -2228,9 +2242,9 @@ match_clause_to_indexcol(PlannerInfo *root,
 	}
 
 	/*
-	 * Clause must be an opclause, funcclause, ScalarArrayOpExpr, or
-	 * RowCompareExpr.  Or, if the index supports it, we can handle IS
-	 * NULL/NOT NULL clauses.
+	 * Clause must be an opclause, funcclause, ScalarArrayOpExpr,
+	 * RowCompareExpr, or OR-clause that could be converted to SAOP.  Or, if
+	 * the index supports it, we can handle IS NULL/NOT NULL clauses.
 	 */
 	if (IsA(clause, OpExpr))
 	{
@@ -2248,6 +2262,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2789,261 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ *
+ * Given a list of OR-clause args, attempts to transform this BoolExpr into
+ * a single SAOP expression. On success, returns an IndexClause, containing
+ * the transformed expression or NULL, if failed.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		have_param = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Try to convert a list of OR-clauses to a single SAOP expression. Each
+	 * OR entry must be in the form: (indexkey operator constant) or (constant
+	 * operator indexkey).  Operators of all the entries must match. Constant
+	 * might be either Const or Param. To be effective, give up on the first
+	 * non-matching entry. Exit is implemented as a break from the loop, which
+	 * is catched afterwards.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			break;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses can match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			break;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			break;
+
+		/*
+		 * The parameters below must match between sub-rinfo and its parent as
+		 * make_restrictinfo() fills them with the same values, and further
+		 * modifications are also the same for the whole subtree. However,
+		 * still make a sanity check.
+		 */
+		Assert(subRinfo->is_pushed_down == rinfo->is_pushed_down);
+		Assert(subRinfo->is_clone == rinfo->is_clone);
+		Assert(subRinfo->security_level == rinfo->security_level);
+		Assert(bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids));
+		Assert(bms_equal(subRinfo->outer_relids, rinfo->outer_relids));
+
+		/*
+		 * Also, check that required_relids in sub-rinfo is subset of parent's
+		 * required_relids.
+		 */
+		Assert(bms_is_subset(subRinfo->required_relids, rinfo->required_relids));
+
+		/* Only operator returning boolean suits the transformation */
+		if (get_op_rettype(opno) != BOOLOID)
+			break;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				break;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			break;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			break;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			break;
+
+		/*
+		 * Save information about the operator, type, and collation for the
+		 * first matching qual. Then, check that subsequent quals match the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * Check that the operator is presented in the opfamily and that
+			 * the expression collation matches the index collation. Also,
+			 * there must be an array type to construct an array later.
+			 */
+			if (!IndexCollMatchesExprColl(index->indexcollations[indexcol], inputcollid) ||
+				!op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+				!OidIsValid(arraytype))
+				break;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				break;
+		}
+
+		if (IsA(constExpr, Param))
+			have_param = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	/*
+	 * Catch the break from the loop above.  Normally, a foreach() loop ends
+	 * up with a NULL list cell.  A non-NULL list cell indicates a break from
+	 * the foreach() loop.  Free the consts list and return NULL then.
+	 */
+	if (lc != NULL)
+	{
+		list_free(consts);
+		return NULL;
+	}
+
+	/*
+	 * Assemble an array from the list of constants. It seems more profitable
+	 * to build a const array. But in the presence of parameters, we don't
+	 * have a specific value here and must employ an ArrayExpr instead.
+	 */
+
+	if (have_param)
+	{
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach(lc, consts)
+			elems[i++] = ((Const *) lfirst(lc))->constvalue;
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = get_opcode(matchOpno);
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	/*
+	 * Finally, build an IndexClause based on the SAOP node. Use
+	 * make_simple_restrictinfo() to get RestrictInfo with clean selectivity
+	 * estimations because it may differ from the estimation made for an OR
+	 * clause. Although it is not a lossy expression, keep the old version of
+	 * rinfo in iclause->rinfo to detect duplicates and recheck the original
+	 * clause.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = rinfo;
+	iclause->indexquals = list_make1(make_simple_restrictinfo(root,
+															  &saopexpr->xpr));
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index d3358dfc394..e4d117e47ae 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,67 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                   QUERY PLAN                                    
+---------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,6 +1913,27 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1872,6 +1942,102 @@ SELECT count(*) FROM tenk1
  Aggregate
    ->  Bitmap Heap Scan on tenk1
          Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand < 42) OR (thousand < 99) OR (43 > thousand) OR (42 > thousand)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                             QUERY PLAN                                              
+-----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,16 +2045,90 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 756c2e24965..6d02360cf43 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4278,15 +4278,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 319190855bd..ef890b96cc6 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4492,6 +4492,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index fe162cc7c30..71a7115067e 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -732,12 +732,81 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 0c65e5af4be..8f6acb5f618 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1433,6 +1433,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 3011d71b12b..6d2414b6044 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
-- 
2.39.5 (Apple Git-154)

#278Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#277)
Re: POC, WIP: OR-clause support for indexes

On 10/17/24 03:39, Alexander Korotkov wrote:

On Wed, Oct 16, 2024 at 7:22 AM Andrei Lepikhov <lepihov@gmail.com> wrote:

On 10/12/24 21:25, Alexander Korotkov wrote:

I forgot to specify (COSTS OFF) for EXPLAINs in regression tests. Fixed in v42.

I've passed through the patch set.

Let me put aside the v42-0003 patch—it looks debatable, and I need time
to analyse the change in regression tests caused by this patch.

Yes, 0003 patch is for illustration purposes for now. I will not keep
rebasing it. We can pick it later when main patches are committed.

Got it. I will save it into the TODO list.

Comments look much better according to my current language level. Ideas
with fast exits also look profitable and are worth an additional
'matched' variable.

So, in general, it is ok. I think only one place with
inner_other_clauses can be improved. Maybe it will be enough to create
this list only once, outside 'foreach(j, groupedArgs)' cycle? Also, the
comment on the necessity of this operation was unclear to me. See the
attachment for my modest attempt at improving it.

Thank you, I've integrated your patch with minor edits from me.

Thanks, I'm not sure about necessity to check NIL value of a list
(list_free also do it), but I'm ok with the edits.

--
regards, Andrei Lepikhov

#279jian he
jian.universality@gmail.com
In reply to: Alexander Korotkov (#277)
Re: POC, WIP: OR-clause support for indexes

* NOTE: returns NULL if clause is an OR or AND clause; it is the
* responsibility of higher-level routines to cope with those.
*/
static IndexClause *
match_clause_to_indexcol(PlannerInfo *root,
RestrictInfo *rinfo,
int indexcol,
IndexOptInfo *index)

the above comments need a slight change.

EXPLAIN (COSTS OFF, settings) SELECT * FROM tenk2 WHERE (thousand = 1
OR thousand = 3);
QUERY PLAN
-----------------------------------------------------------
Bitmap Heap Scan on tenk2
Recheck Cond: ((thousand = 1) OR (thousand = 3))
-> Bitmap Index Scan on tenk2_thous_tenthous
Index Cond: (thousand = ANY ('{1,3}'::integer[]))

EXPLAIN (COSTS OFF, settings) SELECT * FROM tenk2 WHERE (thousand in (1,3));
QUERY PLAN
-----------------------------------------------------------
Bitmap Heap Scan on tenk2
Recheck Cond: (thousand = ANY ('{1,3}'::integer[]))
-> Bitmap Index Scan on tenk2_thous_tenthous
Index Cond: (thousand = ANY ('{1,3}'::integer[]))

tenk2 index:
Indexes:
"tenk2_thous_tenthous" btree (thousand, tenthous)

Looking at the above cases, I found out the "Recheck Cond" is
different from "Index Cond".
I wonder why there is a difference, or if they should be the same.
then i come to:
match_orclause_to_indexcol

/*
* Finally, build an IndexClause based on the SAOP node. Use
* make_simple_restrictinfo() to get RestrictInfo with clean selectivity
* estimations because it may differ from the estimation made for an OR
* clause. Although it is not a lossy expression, keep the old version of
* rinfo in iclause->rinfo to detect duplicates and recheck the original
* clause.
*/
iclause = makeNode(IndexClause);
iclause->rinfo = rinfo;
iclause->indexquals = list_make1(make_simple_restrictinfo(root,
&saopexpr->xpr));
iclause->lossy = false;
iclause->indexcol = indexcol;
iclause->indexcols = NIL;

looking at create_bitmap_scan_plan.
I think "iclause->rinfo" itself won't be able to detect duplicates.
since the upper code would mostly use "iclause->indexquals" for comparison?

typedef struct IndexClause comments says:
"
* indexquals is a list of RestrictInfos for the directly-usable index
* conditions associated with this IndexClause. In the simplest case
* it's a one-element list whose member is iclause->rinfo. Otherwise,
* it contains one or more directly-usable indexqual conditions extracted
* from the given clause. The 'lossy' flag indicates whether the
* indexquals are semantically equivalent to the original clause, or
* represent a weaker condition.
"
should lossy be iclause->lossy be true at the end of match_orclause_to_indexcol?
since it meets the comment condition: "semantically equivalent to the
original clause"
or is the above comment slightly wrong?

in match_orclause_to_indexcol
i changed from
iclause->rinfo = rinfo;
to
iclause->rinfo = make_simple_restrictinfo(root,
&saopexpr->xpr);

as expected. now the "Recheck Cond" is same as "Index Cond"
Recheck Cond: (thousand = ANY ('{1,3}'::integer[]))
-> Bitmap Index Scan on tenk2_thous_tenthous
Index Cond: (thousand = ANY ('{1,3}'::integer[]))

I am not sure of the implication of this change.

#280Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: jian he (#279)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi, Jian! Thank you for your work on this topic!

On 28.10.2024 10:19, jian he wrote:

* NOTE: returns NULL if clause is an OR or AND clause; it is the
* responsibility of higher-level routines to cope with those.
*/
static IndexClause *
match_clause_to_indexcol(PlannerInfo *root,
RestrictInfo *rinfo,
int indexcol,
IndexOptInfo *index)

the above comments need a slight change.

EXPLAIN (COSTS OFF, settings) SELECT * FROM tenk2 WHERE (thousand = 1
OR thousand = 3);
QUERY PLAN
-----------------------------------------------------------
Bitmap Heap Scan on tenk2
Recheck Cond: ((thousand = 1) OR (thousand = 3))
-> Bitmap Index Scan on tenk2_thous_tenthous
Index Cond: (thousand = ANY ('{1,3}'::integer[]))

EXPLAIN (COSTS OFF, settings) SELECT * FROM tenk2 WHERE (thousand in (1,3));
QUERY PLAN
-----------------------------------------------------------
Bitmap Heap Scan on tenk2
Recheck Cond: (thousand = ANY ('{1,3}'::integer[]))
-> Bitmap Index Scan on tenk2_thous_tenthous
Index Cond: (thousand = ANY ('{1,3}'::integer[]))

tenk2 index:
Indexes:
"tenk2_thous_tenthous" btree (thousand, tenthous)

Looking at the above cases, I found out the "Recheck Cond" is
different from "Index Cond".
I wonder why there is a difference, or if they should be the same.
then i come to:
match_orclause_to_indexcol

/*
* Finally, build an IndexClause based on the SAOP node. Use
* make_simple_restrictinfo() to get RestrictInfo with clean selectivity
* estimations because it may differ from the estimation made for an OR
* clause. Although it is not a lossy expression, keep the old version of
* rinfo in iclause->rinfo to detect duplicates and recheck the original
* clause.
*/
iclause = makeNode(IndexClause);
iclause->rinfo = rinfo;
iclause->indexquals = list_make1(make_simple_restrictinfo(root,
&saopexpr->xpr));
iclause->lossy = false;
iclause->indexcol = indexcol;
iclause->indexcols = NIL;

looking at create_bitmap_scan_plan.
I think "iclause->rinfo" itself won't be able to detect duplicates.
since the upper code would mostly use "iclause->indexquals" for comparison?

typedef struct IndexClause comments says:
"
* indexquals is a list of RestrictInfos for the directly-usable index
* conditions associated with this IndexClause. In the simplest case
* it's a one-element list whose member is iclause->rinfo. Otherwise,
* it contains one or more directly-usable indexqual conditions extracted
* from the given clause. The 'lossy' flag indicates whether the
* indexquals are semantically equivalent to the original clause, or
* represent a weaker condition.
"
should lossy be iclause->lossy be true at the end of match_orclause_to_indexcol?
since it meets the comment condition: "semantically equivalent to the
original clause"
or is the above comment slightly wrong?

in match_orclause_to_indexcol
i changed from
iclause->rinfo = rinfo;
to
iclause->rinfo = make_simple_restrictinfo(root,
&saopexpr->xpr);

as expected. now the "Recheck Cond" is same as "Index Cond"
Recheck Cond: (thousand = ANY ('{1,3}'::integer[]))
-> Bitmap Index Scan on tenk2_thous_tenthous
Index Cond: (thousand = ANY ('{1,3}'::integer[]))

I am not sure of the implication of this change.

I may be wrong, but the original idea was to double-check the result
with the original expression.

But I'm willing to agree with you. I think we should add transformed
rinfo variable through add_predicate_to_index_quals function. I attached
the diff file to the letter.

diff --git a/src/backend/optimizer/path/indxpath.c 
b/src/backend/optimizer/path/indxpath.c
index 3da7ea8ed57..c68ac7008e6 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3463,10 +3463,11 @@ match_orclause_to_indexcol(PlannerInfo *root,
       * rinfo in iclause->rinfo to detect duplicates and recheck the 
original
       * clause.
       */
+    RestrictInfo *rinfo_new = make_simple_restrictinfo(root,
+ &saopexpr->xpr);
      iclause = makeNode(IndexClause);
-    iclause->rinfo = rinfo;
-    iclause->indexquals = list_make1(make_simple_restrictinfo(root,
- &saopexpr->xpr));
+    iclause->rinfo = rinfo_new;
+    iclause->indexquals = add_predicate_to_index_quals(index, 
list_make1(rinfo_new));
      iclause->lossy = false;
      iclause->indexcol = indexcol;
      iclause->indexcols = NIL;

I figured out comments that you mentioned and found some addition
explanation.

As I understand it, this processing is related to ensuring that the
selectivity of the index is assessed correctly and that there is no
underestimation, which can lead to the selection of a partial index in
the plan. See comment for the add_predicate_to_index_quals function:

* ANDing the index predicate with the explicitly given indexquals produces
 * a more accurate idea of the index's selectivity. *However, we need to be
 * careful not to insert redundant clauses, because
clauselist_selectivity()
 * is easily fooled into computing a too-low selectivity estimate*.  Our
 * approach is to add only the predicate clause(s) that cannot be proven to
 * be implied by the given indexquals.  This successfully handles cases
such
 * as a qual "x = 42" used with a partial index "WHERE x >= 40 AND x < 50".
 * There are many other cases where we won't detect redundancy, leading
to a
 * too-low selectivity estimate, which will bias the system in favor of
using
 * partial indexes where possible.  That is not necessarily bad though.
 *
 * *Note that indexQuals contains RestrictInfo nodes while the indpred
 * does not, so the output list will be mixed.  This is OK for both
 * predicate_implied_by() and clauselist_selectivity()*, but might be
 * problematic if the result were passed to other things.
 */

In those comments that you mentioned, it was written that this problem
of expression redundancy is checked using the predicate_implied_by
function, note that it is called there.

* In some situations (particularly with OR'd index conditions) we may *
have scan_clauses that are not equal to, but are logically implied by, *
the index quals; so we also try a predicate_implied_by() check to see *
if we can discard quals that way. (predicate_implied_by assumes its *
first input contains only immutable functions, so we have to check * that.)

I also figured out more information about loosy variable. First of all,
I tried changing the value of the variable and did not notice any
difference in regression tests. As I understood, our transformation is
completely equivalent, so loosy should be true. But I don't think they
are needed since our expressions are equivalent. I thought for a long
time about an example where this could be a mistake and didn’t come up
with any of them.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

or_any.difftext/x-patch; charset=UTF-8; name=or_any.diffDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 3da7ea8ed57..e72a4fb15dd 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3242,6 +3242,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Oid			inputcollid = InvalidOid;
 	bool		firstTime = true;
 	bool		have_param = false;
+	RestrictInfo *rinfo_new;
 
 	Assert(IsA(orclause, BoolExpr));
 	Assert(orclause->boolop == OR_EXPR);
@@ -3463,11 +3464,12 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	 * rinfo in iclause->rinfo to detect duplicates and recheck the original
 	 * clause.
 	 */
+	rinfo_new = make_simple_restrictinfo(root,
+                                                &saopexpr->xpr);
 	iclause = makeNode(IndexClause);
-	iclause->rinfo = rinfo;
-	iclause->indexquals = list_make1(make_simple_restrictinfo(root,
-															  &saopexpr->xpr));
-	iclause->lossy = false;
+	iclause->rinfo = rinfo_new;
+	iclause->indexquals = add_predicate_to_index_quals(index, list_make1(rinfo_new));
+	iclause->lossy = true;
 	iclause->indexcol = indexcol;
 	iclause->indexcols = NIL;
 	return iclause;
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index b003492c5c8..3c46484d642 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1878,10 +1878,10 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
-                                                                QUERY PLAN                                                                 
--------------------------------------------------------------------------------------------------------------------------------------------
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous IS NULL)) OR ((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42))))
+   Recheck Cond: (((thousand = 42) AND (tenthous IS NULL)) OR ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[]))))
    Filter: ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42) OR (tenthous IS NULL))
    ->  BitmapOr
          ->  Bitmap Index Scan on tenk1_thous_tenthous
@@ -1917,10 +1917,10 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
-                                                                     QUERY PLAN                                                                      
------------------------------------------------------------------------------------------------------------------------------------------------------
+                                                            QUERY PLAN                                                             
+-----------------------------------------------------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND ((tenthous = '3'::bigint) OR (tenthous = '42'::bigint))) OR ((thousand = 42) AND (tenthous = '1'::smallint)))
+   Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{3,42}'::bigint[]))) OR ((thousand = 42) AND (tenthous = '1'::smallint)))
    Filter: ((tenthous = '1'::smallint) OR (tenthous = '3'::bigint) OR (tenthous = '42'::bigint))
    ->  BitmapOr
          ->  Bitmap Index Scan on tenk1_thous_tenthous
@@ -1932,11 +1932,11 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1991,11 +1991,11 @@ SELECT * FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
-                                   QUERY PLAN                                    
----------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         Recheck Cond: ((hundred = 42) AND (thousand = ANY ('{42,99}'::integer[])))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -2013,11 +2013,11 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
-                                                      QUERY PLAN                                                       
------------------------------------------------------------------------------------------------------------------------
+                                        QUERY PLAN                                        
+------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand < 42) OR (thousand < 99) OR (43 > thousand) OR (42 > thousand)))
+         Recheck Cond: ((hundred = 42) AND (thousand < ANY ('{42,99,43,42}'::integer[])))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -2035,11 +2035,11 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
-                                             QUERY PLAN                                              
------------------------------------------------------------------------------------------------------
+                                               QUERY PLAN                                               
+--------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3))) OR (thousand = 41))
+         Recheck Cond: (((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[]))) OR (thousand = 41))
          ->  BitmapOr
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
@@ -2057,11 +2057,11 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                        QUERY PLAN                                                        
---------------------------------------------------------------------------------------------------------------------------
+                                                         QUERY PLAN                                                          
+-----------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND (((thousand = 42) OR (thousand = 99)) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND ((thousand = ANY ('{42,99}'::integer[])) OR (tenthous < 2))) OR (thousand = 41))
          Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
@@ -2086,11 +2086,11 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                        QUERY PLAN                                                         
----------------------------------------------------------------------------------------------------------------------------
+                                                          QUERY PLAN                                                          
+------------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR ((thousand = 42) OR (thousand = 41))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR (thousand = ANY ('{42,41}'::integer[]))))
          Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index ebf2e3f851a..ea83578ccf1 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4348,7 +4348,7 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique2
@@ -4374,7 +4374,7 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique2
@@ -4394,7 +4394,7 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR ((unique1 = 3) OR (unique1 = 1)) OR (unique1 < 20))
+               Recheck Cond: ((unique2 = ANY ('{3,7}'::integer[])) OR (unique1 = ANY ('{3,1}'::integer[])) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique2
#281Alexander Korotkov
aekorotkov@gmail.com
In reply to: jian he (#279)
Re: POC, WIP: OR-clause support for indexes

Hi, Jian!

On Mon, Oct 28, 2024 at 9:19 AM jian he <jian.universality@gmail.com> wrote:

* NOTE: returns NULL if clause is an OR or AND clause; it is the
* responsibility of higher-level routines to cope with those.
*/
static IndexClause *
match_clause_to_indexcol(PlannerInfo *root,
RestrictInfo *rinfo,
int indexcol,
IndexOptInfo *index)

the above comments need a slight change.

EXPLAIN (COSTS OFF, settings) SELECT * FROM tenk2 WHERE (thousand = 1
OR thousand = 3);
QUERY PLAN
-----------------------------------------------------------
Bitmap Heap Scan on tenk2
Recheck Cond: ((thousand = 1) OR (thousand = 3))
-> Bitmap Index Scan on tenk2_thous_tenthous
Index Cond: (thousand = ANY ('{1,3}'::integer[]))

EXPLAIN (COSTS OFF, settings) SELECT * FROM tenk2 WHERE (thousand in

(1,3));

QUERY PLAN
-----------------------------------------------------------
Bitmap Heap Scan on tenk2
Recheck Cond: (thousand = ANY ('{1,3}'::integer[]))
-> Bitmap Index Scan on tenk2_thous_tenthous
Index Cond: (thousand = ANY ('{1,3}'::integer[]))

tenk2 index:
Indexes:
"tenk2_thous_tenthous" btree (thousand, tenthous)

Looking at the above cases, I found out the "Recheck Cond" is
different from "Index Cond".
I wonder why there is a difference, or if they should be the same.
then i come to:
match_orclause_to_indexcol

/*
* Finally, build an IndexClause based on the SAOP node. Use
* make_simple_restrictinfo() to get RestrictInfo with clean

selectivity

* estimations because it may differ from the estimation made for an

OR

* clause. Although it is not a lossy expression, keep the old

version of

* rinfo in iclause->rinfo to detect duplicates and recheck the

original

* clause.
*/
iclause = makeNode(IndexClause);
iclause->rinfo = rinfo;
iclause->indexquals = list_make1(make_simple_restrictinfo(root,

&saopexpr->xpr));

iclause->lossy = false;
iclause->indexcol = indexcol;
iclause->indexcols = NIL;

looking at create_bitmap_scan_plan.
I think "iclause->rinfo" itself won't be able to detect duplicates.
since the upper code would mostly use "iclause->indexquals" for

comparison?

typedef struct IndexClause comments says:
"
* indexquals is a list of RestrictInfos for the directly-usable index
* conditions associated with this IndexClause. In the simplest case
* it's a one-element list whose member is iclause->rinfo. Otherwise,
* it contains one or more directly-usable indexqual conditions extracted
* from the given clause. The 'lossy' flag indicates whether the
* indexquals are semantically equivalent to the original clause, or
* represent a weaker condition.
"
should lossy be iclause->lossy be true at the end of

match_orclause_to_indexcol?

since it meets the comment condition: "semantically equivalent to the
original clause"
or is the above comment slightly wrong?

in match_orclause_to_indexcol
i changed from
iclause->rinfo = rinfo;
to
iclause->rinfo = make_simple_restrictinfo(root,
&saopexpr->xpr);

as expected. now the "Recheck Cond" is same as "Index Cond"
Recheck Cond: (thousand = ANY ('{1,3}'::integer[]))
-> Bitmap Index Scan on tenk2_thous_tenthous
Index Cond: (thousand = ANY ('{1,3}'::integer[]))

I am not sure of the implication of this change.

As comment says IndexClause.rinfo must be original restriction or join
clause.

typedef struct IndexClause
{
pg_node_attr(no_copy_equal, no_read, no_query_jumble)

NodeTag type;
struct RestrictInfo *rinfo; /* original restriction or join clause */

I don't see any reason why should we violate that. Note that there are
already cases when "Recheck Cond" doesn't match "Index Cond". For instance:

# explain select * from t where 100000 > i;
QUERY PLAN
-----------------------------------------------------------------------------
Bitmap Heap Scan on t (cost=1860.66..7524.75 rows=99127 width=4)
Recheck Cond: (100000 > i)
-> Bitmap Index Scan on t_i_idx (cost=0.00..1835.88 rows=99127 width=0)
Index Cond: (i < 100000)
(4 rows)

Thus, this type of mismatch seems normal to me.

IndexClause.lossy should be false in our case (as it is). Lossy
transformation happens when there are cases of false positives in the
transformed clause. The comment gives an example of transformation "x
LIKE 'foo%bar'" into "x >= 'foo' AND x < 'fop'". In this case, 'fooqux'
would be case of false positive matching transformed clause but not
matching the original clause. In our case, original and transformed
clauses are equivalent. Therefore our transformation isn't lossy.

------
Regards,
Alexander Korotkov
Supabase

#282Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#280)
Re: POC, WIP: OR-clause support for indexes

Hi, Alena!

On Mon, Oct 28, 2024 at 6:55 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I may be wrong, but the original idea was to double-check the result with the original expression.

But I'm willing to agree with you. I think we should add transformed rinfo variable through add_predicate_to_index_quals function. I attached the diff file to the letter.

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 3da7ea8ed57..c68ac7008e6 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3463,10 +3463,11 @@ match_orclause_to_indexcol(PlannerInfo *root,
* rinfo in iclause->rinfo to detect duplicates and recheck the original
* clause.
*/
+    RestrictInfo *rinfo_new = make_simple_restrictinfo(root,
+                                                &saopexpr->xpr);
iclause = makeNode(IndexClause);
-    iclause->rinfo = rinfo;
-    iclause->indexquals = list_make1(make_simple_restrictinfo(root,
-                                                              &saopexpr->xpr));
+    iclause->rinfo = rinfo_new;
+    iclause->indexquals = add_predicate_to_index_quals(index, list_make1(rinfo_new));
iclause->lossy = false;
iclause->indexcol = indexcol;
iclause->indexcols = NIL;

As I stated in [1], I don't think we should pass transformed clause to
IndexClause.rinfo while comment explicitly says us to pass original
rinfo there.

I figured out comments that you mentioned and found some addition explanation.

As I understand it, this processing is related to ensuring that the selectivity of the index is assessed correctly and that there is no underestimation, which can lead to the selection of a partial index in the plan. See comment for the add_predicate_to_index_quals function:

* ANDing the index predicate with the explicitly given indexquals produces
* a more accurate idea of the index's selectivity. However, we need to be
* careful not to insert redundant clauses, because clauselist_selectivity()
* is easily fooled into computing a too-low selectivity estimate. Our
* approach is to add only the predicate clause(s) that cannot be proven to
* be implied by the given indexquals. This successfully handles cases such
* as a qual "x = 42" used with a partial index "WHERE x >= 40 AND x < 50".
* There are many other cases where we won't detect redundancy, leading to a
* too-low selectivity estimate, which will bias the system in favor of using
* partial indexes where possible. That is not necessarily bad though.
*
* Note that indexQuals contains RestrictInfo nodes while the indpred
* does not, so the output list will be mixed. This is OK for both
* predicate_implied_by() and clauselist_selectivity(), but might be
* problematic if the result were passed to other things.
*/

In those comments that you mentioned, it was written that this problem of expression redundancy is checked using the predicate_implied_by function, note that it is called there.

* In some situations (particularly with OR'd index conditions) we may * have scan_clauses that are not equal to, but are logically implied by, * the index quals; so we also try a predicate_implied_by() check to see * if we can discard quals that way. (predicate_implied_by assumes its * first input contains only immutable functions, so we have to check * that.)

As the first line of header comment of add_predicate_to_index_quals()
says it adds partial index predicate to the quals list. I don't see
why should we use that in match_orclause_to_indexcol(), because this
function is only responsible to matching rinfo to particular index
column. Matching of partial index predicate is handled elsewhere.
Also check there is get_index_clause_from_support(), which is fetch
transformed clause from a support function. And it doesn't have to
fiddle with add_predicate_to_index_quals().

I also figured out more information about loosy variable. First of all, I tried changing the value of the variable and did not notice any difference in regression tests. As I understood, our transformation is completely equivalent, so loosy should be true. But I don't think they are needed since our expressions are equivalent. I thought for a long time about an example where this could be a mistake and didn’t come up with any of them.

Yes, our transformation isn't lossy, thus IndexClause.lossy should be unset.

Links
1. /messages/by-id/CAPpHfdvjtEWqjVcPd3-JQw8yCoppMXjK8kHnvinxBXGMZt-M_g@mail.gmail.com

------
Regards,
Alexander Korotkov
Supabase

#283Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alexander Korotkov (#282)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Fri, Nov 15, 2024 at 3:27 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

On Mon, Oct 28, 2024 at 6:55 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I may be wrong, but the original idea was to double-check the result with the original expression.

But I'm willing to agree with you. I think we should add transformed rinfo variable through add_predicate_to_index_quals function. I attached the diff file to the letter.

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 3da7ea8ed57..c68ac7008e6 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3463,10 +3463,11 @@ match_orclause_to_indexcol(PlannerInfo *root,
* rinfo in iclause->rinfo to detect duplicates and recheck the original
* clause.
*/
+    RestrictInfo *rinfo_new = make_simple_restrictinfo(root,
+                                                &saopexpr->xpr);
iclause = makeNode(IndexClause);
-    iclause->rinfo = rinfo;
-    iclause->indexquals = list_make1(make_simple_restrictinfo(root,
-                                                              &saopexpr->xpr));
+    iclause->rinfo = rinfo_new;
+    iclause->indexquals = add_predicate_to_index_quals(index, list_make1(rinfo_new));
iclause->lossy = false;
iclause->indexcol = indexcol;
iclause->indexcols = NIL;

As I stated in [1], I don't think we should pass transformed clause to
IndexClause.rinfo while comment explicitly says us to pass original
rinfo there.

I figured out comments that you mentioned and found some addition explanation.

As I understand it, this processing is related to ensuring that the selectivity of the index is assessed correctly and that there is no underestimation, which can lead to the selection of a partial index in the plan. See comment for the add_predicate_to_index_quals function:

* ANDing the index predicate with the explicitly given indexquals produces
* a more accurate idea of the index's selectivity. However, we need to be
* careful not to insert redundant clauses, because clauselist_selectivity()
* is easily fooled into computing a too-low selectivity estimate. Our
* approach is to add only the predicate clause(s) that cannot be proven to
* be implied by the given indexquals. This successfully handles cases such
* as a qual "x = 42" used with a partial index "WHERE x >= 40 AND x < 50".
* There are many other cases where we won't detect redundancy, leading to a
* too-low selectivity estimate, which will bias the system in favor of using
* partial indexes where possible. That is not necessarily bad though.
*
* Note that indexQuals contains RestrictInfo nodes while the indpred
* does not, so the output list will be mixed. This is OK for both
* predicate_implied_by() and clauselist_selectivity(), but might be
* problematic if the result were passed to other things.
*/

In those comments that you mentioned, it was written that this problem of expression redundancy is checked using the predicate_implied_by function, note that it is called there.

* In some situations (particularly with OR'd index conditions) we may * have scan_clauses that are not equal to, but are logically implied by, * the index quals; so we also try a predicate_implied_by() check to see * if we can discard quals that way. (predicate_implied_by assumes its * first input contains only immutable functions, so we have to check * that.)

As the first line of header comment of add_predicate_to_index_quals()
says it adds partial index predicate to the quals list. I don't see
why should we use that in match_orclause_to_indexcol(), because this
function is only responsible to matching rinfo to particular index
column. Matching of partial index predicate is handled elsewhere.
Also check there is get_index_clause_from_support(), which is fetch
transformed clause from a support function. And it doesn't have to
fiddle with add_predicate_to_index_quals().

I also figured out more information about loosy variable. First of all, I tried changing the value of the variable and did not notice any difference in regression tests. As I understood, our transformation is completely equivalent, so loosy should be true. But I don't think they are needed since our expressions are equivalent. I thought for a long time about an example where this could be a mistake and didn’t come up with any of them.

Yes, our transformation isn't lossy, thus IndexClause.lossy should be unset.

Here is the next revision of this patch. No material changes,
adjustments for comments and commit message.

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v44-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchapplication/octet-stream; name=v44-0001-Transform-OR-clauses-to-SAOP-s-during-index-matc.patchDownload
From cd52478b1d7676ed08a56c8bcd04d1a41752bd7a Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sun, 17 Nov 2024 17:35:19 +0200
Subject: [PATCH v44 1/2] Transform OR-clauses to SAOP's during index matching

This commit makes match_clause_to_indexcol() match
"(indexkey op C1) OR (indexkey op C2) ... (indexkey op CN)" expression
to the index while transformting it into "indexkey op ANY(ARRAY[C1, C2, ...])"
(ScalarArrayOpExpr node).

This transformation allows handling long OR-clauses with single IndexScan
avoiding diving them into a slower BitmapOr.

We currently restrict Ci to be either Const or Param to apply this
transformation only when it's clearly beneficial.  However, in the future,
we might switch to a liberal understanding of constants, as it is in other
cases.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina, Andrey Lepikhov, Alexander Korotkov
Reviewed-by: Peter Geoghegan, Ranier Vilela, Alexander Korotkov, Robert Haas
Reviewed-by: Jian He, Tom Lane, Nikolay Shaplov
---
 src/backend/optimizer/path/indxpath.c      | 284 ++++++++++++++++++++-
 src/test/regress/expected/create_index.out | 270 ++++++++++++++++++--
 src/test/regress/expected/join.out         |  57 ++++-
 src/test/regress/expected/rowsecurity.out  |   7 +
 src/test/regress/expected/stats_ext.out    |  12 +
 src/test/regress/expected/uuid.out         |  31 +++
 src/test/regress/sql/create_index.sql      |  69 +++++
 src/test/regress/sql/join.sql              |   9 +
 src/test/regress/sql/rowsecurity.sql       |   1 +
 src/test/regress/sql/stats_ext.sql         |   3 +
 src/test/regress/sql/uuid.sql              |  12 +
 11 files changed, 732 insertions(+), 23 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c0fcc7d78df..720a9a84d6a 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -20,6 +20,7 @@
 #include "access/stratnum.h"
 #include "access/sysattr.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
@@ -32,8 +33,10 @@
 #include "optimizer/paths.h"
 #include "optimizer/prep.h"
 #include "optimizer/restrictinfo.h"
+#include "utils/array.h"
 #include "utils/lsyscache.h"
 #include "utils/selfuncs.h"
+#include "utils/syscache.h"
 
 
 /* XXX see PartCollMatchesExprColl */
@@ -177,6 +180,10 @@ static IndexClause *match_rowcompare_to_indexcol(PlannerInfo *root,
 												 RestrictInfo *rinfo,
 												 int indexcol,
 												 IndexOptInfo *index);
+static IndexClause *match_orclause_to_indexcol(PlannerInfo *root,
+											   RestrictInfo *rinfo,
+											   int indexcol,
+											   IndexOptInfo *index);
 static IndexClause *expand_indexqual_rowcompare(PlannerInfo *root,
 												RestrictInfo *rinfo,
 												int indexcol,
@@ -2149,7 +2156,10 @@ match_clause_to_index(PlannerInfo *root,
  *	  (3)  must match the collation of the index, if collation is relevant.
  *
  *	  Our definition of "const" is exceedingly liberal: we allow anything that
- *	  doesn't involve a volatile function or a Var of the index's relation.
+ *	  doesn't involve a volatile function or a Var of the index's relation
+ *	  except for a boolean OR expression input: due to a trade-off between the
+ *	  expected execution speedup and planning complexity, we limit or->saop
+ *	  transformation by obvious cases when an index scan can get a profit.
  *	  In particular, Vars belonging to other relations of the query are
  *	  accepted here, since a clause of that form can be used in a
  *	  parameterized indexscan.  It's the responsibility of higher code levels
@@ -2179,6 +2189,10 @@ match_clause_to_index(PlannerInfo *root,
  *	  It is also possible to match ScalarArrayOpExpr clauses to indexes, when
  *	  the clause is of the form "indexkey op ANY (arrayconst)".
  *
+ *	  It is also possible to match a list of OR clauses if it might be
+ *	  transformed into a single ScalarArrayOpExpr clause.  On success,
+ *	  the returning index clause will contain a trasformed clause.
+ *
  *	  For boolean indexes, it is also possible to match the clause directly
  *	  to the indexkey; or perhaps the clause is (NOT indexkey).
  *
@@ -2228,9 +2242,9 @@ match_clause_to_indexcol(PlannerInfo *root,
 	}
 
 	/*
-	 * Clause must be an opclause, funcclause, ScalarArrayOpExpr, or
-	 * RowCompareExpr.  Or, if the index supports it, we can handle IS
-	 * NULL/NOT NULL clauses.
+	 * Clause must be an opclause, funcclause, ScalarArrayOpExpr,
+	 * RowCompareExpr, or OR-clause that could be converted to SAOP.  Or, if
+	 * the index supports it, we can handle IS NULL/NOT NULL clauses.
 	 */
 	if (IsA(clause, OpExpr))
 	{
@@ -2248,6 +2262,10 @@ match_clause_to_indexcol(PlannerInfo *root,
 	{
 		return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
 	}
+	else if (restriction_is_or_clause(rinfo))
+	{
+		return match_orclause_to_indexcol(root, rinfo, indexcol, index);
+	}
 	else if (index->amsearchnulls && IsA(clause, NullTest))
 	{
 		NullTest   *nt = (NullTest *) clause;
@@ -2771,6 +2789,264 @@ match_rowcompare_to_indexcol(PlannerInfo *root,
 	return NULL;
 }
 
+/*
+ * match_orclause_to_indexcol()
+ *	  Handles the OR-expr case for match_clause_to_indexcol() in the case
+ *	  when it could be transformed to ScalarArrayOpExpr.
+ *
+ * In this routine, we attempt to transform a list of OR-clause args into a
+ * single SAOP expression matching the target index column.  On success,
+ * return an IndexClause, containing the transformed expression or NULL,
+ * if failed.
+ */
+static IndexClause *
+match_orclause_to_indexcol(PlannerInfo *root,
+						   RestrictInfo *rinfo,
+						   int indexcol,
+						   IndexOptInfo *index)
+{
+	ListCell   *lc;
+	BoolExpr   *orclause = (BoolExpr *) rinfo->orclause;
+	Node	   *indexExpr = NULL;
+	List	   *consts = NIL;
+	Node	   *arrayNode = NULL;
+	ScalarArrayOpExpr *saopexpr = NULL;
+	Oid			matchOpno = InvalidOid;
+	IndexClause *iclause;
+	Oid			consttype = InvalidOid;
+	Oid			arraytype = InvalidOid;
+	Oid			inputcollid = InvalidOid;
+	bool		firstTime = true;
+	bool		haveParam = false;
+
+	Assert(IsA(orclause, BoolExpr));
+	Assert(orclause->boolop == OR_EXPR);
+
+	/*
+	 * Try to convert a list of OR-clauses to a single SAOP expression. Each
+	 * OR entry must be in the form: (indexkey operator constant) or (constant
+	 * operator indexkey).  Operators of all the entries must match.  Constant
+	 * might be either Const or Param.  To be effective, give up on the first
+	 * non-matching entry.  Exit is implemented as a break from the loop,
+	 * which is catched afterwards.
+	 */
+	foreach(lc, orclause->args)
+	{
+		RestrictInfo *subRinfo;
+		OpExpr	   *subClause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *constExpr;
+
+		if (!IsA(lfirst(lc), RestrictInfo))
+			break;
+
+		subRinfo = (RestrictInfo *) lfirst(lc);
+
+		/* Only operator clauses can match  */
+		if (!IsA(subRinfo->clause, OpExpr))
+			break;
+
+		subClause = (OpExpr *) subRinfo->clause;
+		opno = subClause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(subClause->args) != 2)
+			break;
+
+		/*
+		 * The parameters below must match between sub-rinfo and its parent as
+		 * make_restrictinfo() fills them with the same values, and further
+		 * modifications are also the same for the whole subtree.  However,
+		 * still make a sanity check.
+		 */
+		Assert(subRinfo->is_pushed_down == rinfo->is_pushed_down);
+		Assert(subRinfo->is_clone == rinfo->is_clone);
+		Assert(subRinfo->security_level == rinfo->security_level);
+		Assert(bms_equal(subRinfo->incompatible_relids, rinfo->incompatible_relids));
+		Assert(bms_equal(subRinfo->outer_relids, rinfo->outer_relids));
+
+		/*
+		 * Also, check that required_relids in sub-rinfo is subset of parent's
+		 * required_relids.
+		 */
+		Assert(bms_is_subset(subRinfo->required_relids, rinfo->required_relids));
+
+		/* Only the operator returning a boolean suits the transformation. */
+		if (get_op_rettype(opno) != BOOLOID)
+			break;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  Determine indexkey side first, check
+		 * the constant later.
+		 */
+		leftop = (Node *) linitial(subClause->args);
+		rightop = (Node *) lsecond(subClause->args);
+		if (match_index_to_operand(leftop, indexcol, index))
+		{
+			indexExpr = leftop;
+			constExpr = rightop;
+		}
+		else if (match_index_to_operand(rightop, indexcol, index))
+		{
+			opno = get_commutator(opno);
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				break;
+			}
+			indexExpr = rightop;
+			constExpr = leftop;
+		}
+		else
+		{
+			break;
+		}
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		if (IsA(constExpr, RelabelType))
+			constExpr = (Node *) ((RelabelType *) constExpr)->arg;
+		if (IsA(indexExpr, RelabelType))
+			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
+
+		/* We allow constant to be Const or Param */
+		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
+			break;
+
+		/* Forbid transformation for composite types, records. */
+		if (type_is_rowtype(exprType(constExpr)) ||
+			type_is_rowtype(exprType(indexExpr)))
+			break;
+
+		/*
+		 * Save information about the operator, type, and collation for the
+		 * first matching qual.  Then, check that subsequent quals match the
+		 * first.
+		 */
+		if (firstTime)
+		{
+			matchOpno = opno;
+			consttype = exprType(constExpr);
+			arraytype = get_array_type(consttype);
+			inputcollid = subClause->inputcollid;
+
+			/*
+			 * Check that the operator is presented in the opfamily and that
+			 * the expression collation matches the index collation.  Also,
+			 * there must be an array type to construct an array later.
+			 */
+			if (!IndexCollMatchesExprColl(index->indexcollations[indexcol], inputcollid) ||
+				!op_in_opfamily(matchOpno, index->opfamily[indexcol]) ||
+				!OidIsValid(arraytype))
+				break;
+			firstTime = false;
+		}
+		else
+		{
+			if (opno != matchOpno ||
+				inputcollid != subClause->inputcollid ||
+				consttype != exprType(constExpr))
+				break;
+		}
+
+		if (IsA(constExpr, Param))
+			haveParam = true;
+		consts = lappend(consts, constExpr);
+	}
+
+	/*
+	 * Catch the break from the loop above.  Normally, a foreach() loop ends
+	 * up with a NULL list cell.  A non-NULL list cell indicates a break from
+	 * the foreach() loop.  Free the consts list and return NULL then.
+	 */
+	if (lc != NULL)
+	{
+		list_free(consts);
+		return NULL;
+	}
+
+	/*
+	 * Assemble an array from the list of constants.  It seems more profitable
+	 * to build a const array.  But in the presence of parameters, we don't
+	 * have a specific value here and must employ an ArrayExpr instead.
+	 */
+	if (haveParam)
+	{
+		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
+
+		/* array_collid will be set by parse_collate.c */
+		arrayExpr->element_typeid = consttype;
+		arrayExpr->array_typeid = arraytype;
+		arrayExpr->multidims = false;
+		arrayExpr->elements = consts;
+		arrayExpr->location = -1;
+
+		arrayNode = (Node *) arrayExpr;
+	}
+	else
+	{
+		int16		typlen;
+		bool		typbyval;
+		char		typalign;
+		Datum	   *elems;
+		int			i = 0;
+		ArrayType  *arrayConst;
+
+		get_typlenbyvalalign(consttype, &typlen, &typbyval, &typalign);
+
+		elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
+		foreach_node(Const, value, consts)
+		{
+			Assert(!value->constisnull && value->constvalue);
+
+			elems[i++] = value->constvalue;
+		}
+
+		arrayConst = construct_array(elems, i, consttype,
+									 typlen, typbyval, typalign);
+		arrayNode = (Node *) makeConst(arraytype, -1, inputcollid,
+									   -1, PointerGetDatum(arrayConst),
+									   false, false);
+
+		pfree(elems);
+		list_free(consts);
+	}
+
+	/* Build the SAOP expression node */
+	saopexpr = makeNode(ScalarArrayOpExpr);
+	saopexpr->opno = matchOpno;
+	saopexpr->opfuncid = get_opcode(matchOpno);
+	saopexpr->hashfuncid = InvalidOid;
+	saopexpr->negfuncid = InvalidOid;
+	saopexpr->useOr = true;
+	saopexpr->inputcollid = inputcollid;
+	saopexpr->args = list_make2(indexExpr, arrayNode);
+	saopexpr->location = -1;
+
+	/*
+	 * Finally, build an IndexClause based on the SAOP node.  Use
+	 * make_simple_restrictinfo() to get RestrictInfo with clean selectivity
+	 * estimations, because they may differ from the estimation made for an OR
+	 * clause.  Although it is not a lossy expression, keep the original rinfo
+	 * in iclause->rinfo as prescribed.
+	 */
+	iclause = makeNode(IndexClause);
+	iclause->rinfo = rinfo;
+	iclause->indexquals = list_make1(make_simple_restrictinfo(root,
+															  &saopexpr->xpr));
+	iclause->lossy = false;
+	iclause->indexcol = indexcol;
+	iclause->indexcols = NIL;
+	return iclause;
+}
+
 /*
  * expand_indexqual_rowcompare --- expand a single indexqual condition
  *		that is a RowCompareExpr
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index d3358dfc394..e4d117e47ae 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1844,18 +1844,67 @@ DROP TABLE onek_with_null;
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                                               QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
- Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
-   ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 1))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 3))
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = 42))
-(9 rows)
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+                                       QUERY PLAN                                       
+----------------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY (ARRAY[1, (InitPlan 1).col1, 42])))
+   InitPlan 1
+     ->  Result
+(4 rows)
+
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+ unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
+---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
+      42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+                                   QUERY PLAN                                    
+---------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(2 rows)
 
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
@@ -1864,6 +1913,27 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Seq Scan on tenk1
+   Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
+(2 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1872,6 +1942,102 @@ SELECT count(*) FROM tenk1
  Aggregate
    ->  Bitmap Heap Scan on tenk1
          Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY ('{42,99}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+                                                      QUERY PLAN                                                       
+-----------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand < 42) OR (thousand < 99) OR (43 > thousand) OR (42 > thousand)))
+         ->  BitmapAnd
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand < ANY ('{42,99,43,42}'::integer[]))
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+                                             QUERY PLAN                                              
+-----------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3}'::integer[])))
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(8 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+ count 
+-------
+    10
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+                                                       QUERY PLAN                                                       
+------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         ->  BitmapOr
+               ->  BitmapAnd
+                     ->  Bitmap Index Scan on tenk1_hundred
+                           Index Cond: (hundred = 42)
+                     ->  BitmapOr
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 42)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (thousand = 99)
+                           ->  Bitmap Index Scan on tenk1_thous_tenthous
+                                 Index Cond: (tenthous < 2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = 41)
+(16 rows)
+
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+ count 
+-------
+    20
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
@@ -1879,16 +2045,90 @@ SELECT count(*) FROM tenk1
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = 42)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 99)
-(11 rows)
+                           Index Cond: (thousand = 41)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
+(13 rows)
 
 SELECT count(*) FROM tenk1
-  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
  count 
 -------
     10
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                          QUERY PLAN                                           
+-----------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         Join Filter: ((tenk2.thousand = 42) OR (tenk1.thousand = 41) OR (tenk2.tenthous = 2))
+         ->  Bitmap Heap Scan on tenk1
+               Recheck Cond: (hundred = 42)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 42)
+         ->  Materialize
+               ->  Bitmap Heap Scan on tenk2
+                     Recheck Cond: (hundred = 42)
+                     ->  Bitmap Index Scan on tenk2_hundred
+                           Index Cond: (hundred = 42)
+(12 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Bitmap Heap Scan on tenk2
+               Recheck Cond: (hundred = 42)
+               Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+               ->  Bitmap Index Scan on tenk2_hundred
+                     Index Cond: (hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+               Index Cond: (hundred = 42)
+(9 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         Join Filter: (tenk1.hundred = 42)
+         ->  Index Only Scan using tenk1_hundred on tenk1
+         ->  Memoize
+               Cache Key: tenk1.hundred
+               Cache Mode: logical
+               ->  Index Scan using tenk2_hundred on tenk2
+                     Index Cond: (hundred = tenk1.hundred)
+                     Filter: ((thousand = 42) OR (thousand = 41) OR (tenthous = 2))
+(10 rows)
+
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9b2973694ff..270a7191e68 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4348,15 +4348,64 @@ select * from tenk1 a join tenk1 b on
                      Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                      QUERY PLAN                                                      
+----------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Bitmap Heap Scan on tenk1 b
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 7)
-(19 rows)
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(18 rows)
+
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+                                                                         QUERY PLAN                                                                          
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Nested Loop
+   Join Filter: ((a.unique1 < 20) OR (a.unique1 = 3) OR ((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
+   ->  Seq Scan on tenk1 b
+   ->  Materialize
+         ->  Bitmap Heap Scan on tenk1 a
+               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
+               ->  BitmapOr
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+(16 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 6d127c19f47..fd5654df35e 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -4494,6 +4494,13 @@ SELECT * FROM rls_tbl WHERE a <<< 1000;
 ---
 (0 rows)
 
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
+        QUERY PLAN        
+--------------------------
+ Result
+   One-Time Filter: false
+(2 rows)
+
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 8c4da955084..a4c7be487ef 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -3254,6 +3254,8 @@ CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ERROR:  permission denied for table priv_test_tbl
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 ERROR:  permission denied for table priv_test_tbl
 -- Grant access via a security barrier view, but hide all data
@@ -3268,6 +3270,11 @@ SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not l
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- Grant table access, but hide all data with RLS
 RESET SESSION AUTHORIZATION;
@@ -3280,6 +3287,11 @@ SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not le
 ---+---
 (0 rows)
 
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
+ a | b 
+---+---
+(0 rows)
+
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 6026e15ed31..8f4ef0d7a6a 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -129,6 +129,37 @@ CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field);
 CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                   QUERY PLAN                                                                   
+------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <> '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+                                                                                                   QUERY PLAN                                                                                                   
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field <= '22222222-2222-2222-2222-222222222222'::uuid) OR (guid_field <= '11111111-1111-1111-1111-111111111111'::uuid) OR (guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid))
+(3 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+                                                                  QUERY PLAN                                                                  
+----------------------------------------------------------------------------------------------------------------------------------------------
+ Aggregate
+   ->  Seq Scan on guid1
+         Filter: ((guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'::uuid) OR (guid_field = '11111111-1111-1111-1111-111111111111'::uuid))
+(3 rows)
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 ERROR:  duplicate key value violates unique constraint "guid1_unique_btree"
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index fe162cc7c30..71a7115067e 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -732,12 +732,81 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand < 42 OR thousand < 99 OR 43 > thousand OR 42 > thousand);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+SELECT count(*) FROM tenk1
+  WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk1.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1, tenk2
+  WHERE tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 LEFT JOIN tenk2 ON
+  tenk1.hundred = 42 AND (tenk2.thousand = 42 OR tenk2.thousand = 41 OR tenk2.tenthous = 2) AND
+  tenk2.hundred = tenk1.hundred;
 --
 -- Check behavior with duplicate index column contents
 --
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 4c9c3e9f49b..1004fc03551 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1462,6 +1462,15 @@ select * from tenk1 a join tenk1 b on
   (a.unique1 = 1 and b.unique1 = 2) or
   ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
 
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+explain (costs off)
+select * from tenk1 a join tenk1 b on
+  (a.unique1 < 20 or a.unique1 = 3 or a.unique1 = 1 and b.unique1 = 2) or
+  ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4);
+
 --
 -- test placement of movable quals in a parameterized join tree
 --
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index eab7d99003e..cf09f62eaba 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -2177,6 +2177,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM rls_tbl WHERE a <<< 1000;
+EXPLAIN (COSTS OFF) SELECT * FROM rls_tbl WHERE a <<< 1000 or a <<< 900;
 DROP OPERATOR <<< (int, int);
 DROP FUNCTION op_leak(int, int);
 RESET SESSION AUTHORIZATION;
diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql
index 0c08a6cc42e..5c786b16c6f 100644
--- a/src/test/regress/sql/stats_ext.sql
+++ b/src/test/regress/sql/stats_ext.sql
@@ -1634,6 +1634,7 @@ CREATE FUNCTION op_leak(int, int) RETURNS bool
 CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
                      restrict = scalarltsel);
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
 
 -- Grant access via a security barrier view, but hide all data
@@ -1645,6 +1646,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
 -- Should now have access via the view, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_view WHERE a <<< 0 OR b <<< 0; -- Should not leak
 DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- Grant table access, but hide all data with RLS
@@ -1655,6 +1657,7 @@ GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
 -- Should now have direct table access, but see nothing and leak nothing
 SET SESSION AUTHORIZATION regress_stats_user1;
 SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
+SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 OR b <<< 0;
 DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
 
 -- privilege checks for pg_stats_ext and pg_stats_ext_exprs
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index c88f6d087a7..75ee966ded0 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -63,6 +63,18 @@ CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);
 
 -- unique index test
 CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field);
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <> '11111111111111111111111111111111' OR
+							guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field <= '22222222-2222-2222-2222-222222222222' OR
+									guid_field <= '11111111111111111111111111111111' OR
+									guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e';
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM guid1 WHERE guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' OR
+							guid_field = '11111111111111111111111111111111';
+
 -- should fail
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 
-- 
2.39.5 (Apple Git-154)

v44-0002-Teach-bitmap-path-generation-about-transforming-.patchapplication/octet-stream; name=v44-0002-Teach-bitmap-path-generation-about-transforming-.patchDownload
From 175f7c1d5667474072ce6d3112226cfb5dabf602 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sun, 17 Nov 2024 19:26:43 +0200
Subject: [PATCH v44 2/2] Teach bitmap path generation about transforming
 OR-clauses to SAOP's

When optimizer generates bitmap paths, it considers breaking OR-clause
arguments one-by-one.  But now, a group of similar OR-clauses can be
transformed into SAOP during index matching.  So, bitmap paths should
keep up.

This commit teaches bitmap paths generation machinery to group similar
OR-clauses into dedicated RestrictInfos.  Those RestrictInfos are considered
both to match index as a whole (as SAOP), or to match as a set of individual
OR-clause argument one-by-one (the old way).

Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's
transformation.  The old way of handling them is also considered.  So, there
shouldn't be planning regression.

Discussion: https://postgr.es/m/CAPpHfdu5iQOjF93vGbjidsQkhHvY2NSm29duENYH_cbhC6x%2BMg%40mail.gmail.com
Author: Alexander Korotkov, Andrey Lepikhov
Reviewed-by: Alena Rybakina, Andrei Lepikhov, Jian he, Robert Haas
Reviewed-by: Peter Geoghegan,
---
 src/backend/optimizer/path/indxpath.c      | 430 ++++++++++++++++++++-
 src/backend/optimizer/util/restrictinfo.c  | 107 +++--
 src/include/optimizer/restrictinfo.h       |  11 +
 src/test/regress/expected/create_index.out | 125 +++++-
 src/test/regress/expected/join.out         |  56 ++-
 src/test/regress/sql/create_index.sql      |  38 ++
 src/tools/pgindent/typedefs.list           |   1 +
 7 files changed, 664 insertions(+), 104 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 720a9a84d6a..8b8506dcfba 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1173,6 +1173,383 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
 	return result;
 }
 
+/*
+ * Utility structure used to group similar OR-clause arguments in
+ * group_similar_or_args().  It represents information about the OR-clause
+ * argument and its matching index key.
+ */
+typedef struct
+{
+	int			indexnum;		/* index of the matching index, or -1 if no
+								 * matching index */
+	int			colnum;			/* index of the matching column, or -1 if no
+								 * matching index */
+	Oid			opno;			/* OID of the OpClause operator, or InvalidOid
+								 * if not an OpExpr */
+	Oid			inputcollid;	/* OID of the OpClause input collation */
+	int			argindex;		/* index of the clause in the list of
+								 * arguments */
+} OrArgIndexMatch;
+
+/*
+ * Comparison function for OrArgIndexMatch which provides sort order placing
+ * similar OR-clause arguments together.
+ */
+static int
+or_arg_index_match_cmp(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->indexnum < match_b->indexnum)
+		return -1;
+	else if (match_a->indexnum > match_b->indexnum)
+		return 1;
+
+	if (match_a->colnum < match_b->colnum)
+		return -1;
+	else if (match_a->colnum > match_b->colnum)
+		return 1;
+
+	if (match_a->opno < match_b->opno)
+		return -1;
+	else if (match_a->opno > match_b->opno)
+		return 1;
+
+	if (match_a->inputcollid < match_b->inputcollid)
+		return -1;
+	else if (match_a->inputcollid > match_b->inputcollid)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * group_similar_or_args
+ *		Transform incoming OR-restrictinfo into a list of sub-restrictinfos,
+ *		each of them containing a subset of similar OR-clause arguments from
+ *		the source rinfo.
+ *
+ * Similar OR-clause arguments are of the form "indexkey op constant" having
+ * the same indexkey, operator, and collation.  Constant may comprise either
+ * Const or Param.  It may be employed later, during the
+ * match_clause_to_indexcol() to transform the whole OR-sub-rinfo to an SAOP
+ * clause.
+ *
+ * Returns the processed list of OR-clause arguments.
+ */
+static List *
+group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
+{
+	int			n;
+	int			i;
+	int			group_start;
+	OrArgIndexMatch *matches;
+	bool		matched = false;
+	ListCell   *lc;
+	ListCell   *lc2;
+	List	   *orargs;
+	List	   *result = NIL;
+
+	Assert(IsA(rinfo->orclause, BoolExpr));
+	orargs = ((BoolExpr *) rinfo->orclause)->args;
+	n = list_length(orargs);
+
+	/*
+	 * To avoid N^2 behavior, take utility pass along the list of OR-clause
+	 * arguments.  For each argument, fill the OrArgIndexMatch structure,
+	 * which will be used to sort these arguments at the next step.
+	 */
+	i = -1;
+	matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n);
+	foreach(lc, orargs)
+	{
+		Node	   *arg = lfirst(lc);
+		RestrictInfo *argrinfo;
+		OpExpr	   *clause;
+		Oid			opno;
+		Node	   *leftop,
+				   *rightop;
+		Node	   *nonConstExpr;
+		int			indexnum;
+		int			colnum;
+
+		i++;
+		matches[i].argindex = i;
+		matches[i].indexnum = -1;
+		matches[i].colnum = -1;
+		matches[i].opno = InvalidOid;
+		matches[i].inputcollid = InvalidOid;
+
+		if (!IsA(arg, RestrictInfo))
+			continue;
+
+		argrinfo = castNode(RestrictInfo, arg);
+
+		/* Only operator clauses can match  */
+		if (!IsA(argrinfo->clause, OpExpr))
+			continue;
+
+		clause = (OpExpr *) argrinfo->clause;
+		opno = clause->opno;
+
+		/* Only binary operators can match  */
+		if (list_length(clause->args) != 2)
+			continue;
+
+		/*
+		 * Ignore any RelabelType node above the operands.  This is needed to
+		 * be able to apply indexscanning in binary-compatible-operator cases.
+		 * Note: we can assume there is at most one RelabelType node;
+		 * eval_const_expressions() will have simplified if more than one.
+		 */
+		leftop = get_leftop(clause);
+		if (IsA(leftop, RelabelType))
+			leftop = (Node *) ((RelabelType *) leftop)->arg;
+
+		rightop = get_rightop(clause);
+		if (IsA(rightop, RelabelType))
+			rightop = (Node *) ((RelabelType *) rightop)->arg;
+
+		/*
+		 * Check for clauses of the form: (indexkey operator constant) or
+		 * (constant operator indexkey).  But we don't know a particular index
+		 * yet.  First check for a constant, which must be Const or Param.
+		 * That's cheaper than search for an index key among all indexes.
+		 */
+		if (IsA(leftop, Const) || IsA(leftop, Param))
+		{
+			opno = get_commutator(opno);
+
+			if (!OidIsValid(opno))
+			{
+				/* commutator doesn't exist, we can't reverse the order */
+				continue;
+			}
+			nonConstExpr = rightop;
+		}
+		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		{
+			nonConstExpr = leftop;
+		}
+		else
+		{
+			continue;
+		}
+
+		/*
+		 * Match non-constant part to the index key.  It's possible that a
+		 * single non-constant part matches multiple index keys.  It's OK, we
+		 * just stop with first matching index key.  Given that this choice is
+		 * determined the same for every clause, we will group similar clauses
+		 * together anyway.
+		 */
+		indexnum = 0;
+		foreach(lc2, rel->indexlist)
+		{
+			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
+
+			/* Ignore index if it doesn't support bitmap scans */
+			if (!index->amhasgetbitmap)
+				continue;
+
+			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
+			{
+				if (match_index_to_operand(nonConstExpr, colnum, index))
+				{
+					matches[i].indexnum = indexnum;
+					matches[i].colnum = colnum;
+					matches[i].opno = opno;
+					matches[i].inputcollid = clause->inputcollid;
+					matched = true;
+					break;
+				}
+			}
+
+			/*
+			 * Stop looping through the indexes, if we managed to match
+			 * nonConstExpr to any index column.
+			 */
+			if (matches[i].indexnum >= 0)
+				break;
+			indexnum++;
+		}
+	}
+
+	/*
+	 * Fast-path check: if no clause is matching to the index column, we can
+	 * just give up at this stage and return the clause list as-is.
+	 */
+	if (!matched)
+	{
+		pfree(matches);
+		return orargs;
+	}
+
+	/* Sort clauses to make similar clauses go together */
+	qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
+
+	/*
+	 * Group similar clauses into single sub-restrictinfo. Side effect: the
+	 * resulting list of restrictions will be sorted by indexnum and colnum.
+	 */
+	group_start = 0;
+	for (i = 1; i <= n; i++)
+	{
+		/* Check if it's a group boundary */
+		if (group_start >= 0 &&
+			(i == n ||
+			 matches[i].indexnum != matches[group_start].indexnum ||
+			 matches[i].colnum != matches[group_start].colnum ||
+			 matches[i].opno != matches[group_start].opno ||
+			 matches[i].inputcollid != matches[group_start].inputcollid ||
+			 matches[i].indexnum == -1))
+		{
+			/*
+			 * One clause in group: add it "as is" to the upper-level OR.
+			 */
+			if (i - group_start == 1)
+			{
+				result = lappend(result,
+								 list_nth(orargs,
+										  matches[group_start].argindex));
+			}
+			else
+			{
+				/*
+				 * Two or more clauses in a group: create a nested OR.
+				 */
+				List	   *args = NIL;
+				List	   *rargs = NIL;
+				RestrictInfo *subrinfo;
+				int			j;
+
+				Assert(i - group_start >= 2);
+
+				/* Construct the list of nested OR arguments */
+				for (j = group_start; j < i; j++)
+				{
+					Node	   *arg = list_nth(orargs, matches[j].argindex);
+
+					rargs = lappend(rargs, arg);
+					if (IsA(arg, RestrictInfo))
+						args = lappend(args, ((RestrictInfo *) arg)->clause);
+					else
+						args = lappend(args, arg);
+				}
+
+				/* Construct the nested OR and wrap it with RestrictInfo */
+				subrinfo = make_plain_restrictinfo(root,
+												   make_orclause(args),
+												   make_orclause(rargs),
+												   rinfo->is_pushed_down,
+												   rinfo->has_clone,
+												   rinfo->is_clone,
+												   rinfo->pseudoconstant,
+												   rinfo->security_level,
+												   rinfo->required_relids,
+												   rinfo->incompatible_relids,
+												   rinfo->outer_relids);
+				result = lappend(result, subrinfo);
+			}
+
+			group_start = i;
+		}
+	}
+	pfree(matches);
+	return result;
+}
+
+/*
+ * make_bitmap_paths_for_or_group
+ *		Generate bitmap paths for a group of similar OR-clause arguments
+ *		produced by group_similar_or_args().
+ *
+ * This function considers two cases: (1) matching a group of clauses to
+ * the index as a whole, and (2) matching the individual clauses one-by-one.
+ * (1) typically comprises an optimal solution.  If not, (2) typically
+ * comprises fair alternative.
+ *
+ * Ideally, we could consider all arbitrary splits of arguments into
+ * subgroups, but that could lead to unacceptable computational complexity.
+ * This is why we only consider two cases of above.
+ */
+static List *
+make_bitmap_paths_for_or_group(PlannerInfo *root, RelOptInfo *rel,
+							   RestrictInfo *ri, List *other_clauses)
+{
+	List	   *jointlist = NIL;
+	List	   *splitlist = NIL;
+	ListCell   *lc;
+	List	   *orargs;
+	List	   *args = ((BoolExpr *) ri->orclause)->args;
+	Cost		jointcost = 0.0,
+				splitcost = 0.0;
+	Path	   *bitmapqual;
+	List	   *indlist;
+
+	/*
+	 * 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);
+	}
+
+	/*
+	 * If we manage to find a bitmap scan, which uses the group of OR-clause
+	 * arguments as a whole, we can skip matching OR-clause arguments
+	 * one-by-one as long as there are no other clauses, which can bring more
+	 * efficiency to one-by-one case.
+	 */
+	if (jointlist != NIL && other_clauses == NIL)
+		return jointlist;
+
+	/*
+	 * 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);
+		splitcost += bitmapqual->total_cost;
+		splitlist = lappend(splitlist, bitmapqual);
+	}
+
+	/*
+	 * Pick the best option.
+	 */
+	if (splitlist == NIL)
+		return jointlist;
+	else if (jointlist == NIL)
+		return splitlist;
+	else
+		return (jointcost < splitcost) ? jointlist : splitlist;
+}
+
+
 /*
  * generate_bitmap_or_paths
  *		Look through the list of clauses to find OR clauses, and generate
@@ -1203,6 +1580,8 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		List	   *pathlist;
 		Path	   *bitmapqual;
 		ListCell   *j;
+		List	   *groupedArgs;
+		List	   *inner_other_clauses = NIL;
 
 		/* Ignore RestrictInfos that aren't ORs */
 		if (!restriction_is_or_clause(rinfo))
@@ -1213,7 +1592,29 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 		 * the OR, else we can't use it.
 		 */
 		pathlist = NIL;
-		foreach(j, ((BoolExpr *) rinfo->orclause)->args)
+
+		/*
+		 * Group the similar OR-clause arguments into dedicated RestrictInfos,
+		 * because eacho of those RestrictInfos has a chance to match the
+		 * index as a whole.
+		 */
+		groupedArgs = group_similar_or_args(root, rel, rinfo);
+
+		if (groupedArgs != ((BoolExpr *) rinfo->orclause)->args)
+		{
+			/*
+			 * Some parts of the rinfo were probably grouped.  In this case,
+			 * we have a set of sub-rinfos that together are an exact
+			 * duplicate of rinfo.  Thus, we need to remove the rinfo from
+			 * other clauses. match_clauses_to_index detects duplicated
+			 * iclauses by comparing pointers to original rinfos that would be
+			 * different.  So, we must delete rinfo to avoid de-facto
+			 * duplicated clauses in the index clauses list.
+			 */
+			inner_other_clauses = list_delete(list_copy(all_clauses), rinfo);
+		}
+
+		foreach(j, groupedArgs)
 		{
 			Node	   *orarg = (Node *) lfirst(j);
 			List	   *indlist;
@@ -1233,12 +1634,34 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 															   andargs,
 															   all_clauses));
 			}
+			else if (restriction_is_or_clause(castNode(RestrictInfo, orarg)))
+			{
+				RestrictInfo *ri = castNode(RestrictInfo, orarg);
+
+				/*
+				 * Generate bitmap paths for the group of similar OR-clause
+				 * arguments.
+				 */
+				indlist = make_bitmap_paths_for_or_group(root,
+														 rel, ri,
+														 inner_other_clauses);
+
+				if (indlist == NIL)
+				{
+					pathlist = NIL;
+					break;
+				}
+				else
+				{
+					pathlist = list_concat(pathlist, indlist);
+					continue;
+				}
+			}
 			else
 			{
 				RestrictInfo *ri = castNode(RestrictInfo, orarg);
 				List	   *orargs;
 
-				Assert(!restriction_is_or_clause(ri));
 				orargs = list_make1(ri);
 
 				indlist = build_paths_for_OR(root, rel,
@@ -1264,6 +1687,9 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
 			pathlist = lappend(pathlist, bitmapqual);
 		}
 
+		if (inner_other_clauses != NIL)
+			list_free(inner_other_clauses);
+
 		/*
 		 * If we have a match for every arm, then turn them into a
 		 * BitmapOrPath, and add to result list.
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 0b406e93342..9e1458401c2 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -21,17 +21,6 @@
 #include "optimizer/restrictinfo.h"
 
 
-static RestrictInfo *make_restrictinfo_internal(PlannerInfo *root,
-												Expr *clause,
-												Expr *orclause,
-												bool is_pushed_down,
-												bool has_clone,
-												bool is_clone,
-												bool pseudoconstant,
-												Index security_level,
-												Relids required_relids,
-												Relids incompatible_relids,
-												Relids outer_relids);
 static Expr *make_sub_restrictinfos(PlannerInfo *root,
 									Expr *clause,
 									bool is_pushed_down,
@@ -90,36 +79,38 @@ make_restrictinfo(PlannerInfo *root,
 	/* Shouldn't be an AND clause, else AND/OR flattening messed up */
 	Assert(!is_andclause(clause));
 
-	return make_restrictinfo_internal(root,
-									  clause,
-									  NULL,
-									  is_pushed_down,
-									  has_clone,
-									  is_clone,
-									  pseudoconstant,
-									  security_level,
-									  required_relids,
-									  incompatible_relids,
-									  outer_relids);
+	return make_plain_restrictinfo(root,
+								   clause,
+								   NULL,
+								   is_pushed_down,
+								   has_clone,
+								   is_clone,
+								   pseudoconstant,
+								   security_level,
+								   required_relids,
+								   incompatible_relids,
+								   outer_relids);
 }
 
 /*
- * make_restrictinfo_internal
+ * make_plain_restrictinfo
  *
- * Common code for the main entry points and the recursive cases.
+ * Common code for the main entry points and the recursive cases.  Also,
+ * useful while contrucitng RestrictInfos above OR clause, which already has
+ * RestrictInfos above its subclauses.
  */
-static RestrictInfo *
-make_restrictinfo_internal(PlannerInfo *root,
-						   Expr *clause,
-						   Expr *orclause,
-						   bool is_pushed_down,
-						   bool has_clone,
-						   bool is_clone,
-						   bool pseudoconstant,
-						   Index security_level,
-						   Relids required_relids,
-						   Relids incompatible_relids,
-						   Relids outer_relids)
+RestrictInfo *
+make_plain_restrictinfo(PlannerInfo *root,
+						Expr *clause,
+						Expr *orclause,
+						bool is_pushed_down,
+						bool has_clone,
+						bool is_clone,
+						bool pseudoconstant,
+						Index security_level,
+						Relids required_relids,
+						Relids incompatible_relids,
+						Relids outer_relids)
 {
 	RestrictInfo *restrictinfo = makeNode(RestrictInfo);
 	Relids		baserels;
@@ -296,17 +287,17 @@ make_sub_restrictinfos(PlannerInfo *root,
 													NULL,
 													incompatible_relids,
 													outer_relids));
-		return (Expr *) make_restrictinfo_internal(root,
-												   clause,
-												   make_orclause(orlist),
-												   is_pushed_down,
-												   has_clone,
-												   is_clone,
-												   pseudoconstant,
-												   security_level,
-												   required_relids,
-												   incompatible_relids,
-												   outer_relids);
+		return (Expr *) make_plain_restrictinfo(root,
+												clause,
+												make_orclause(orlist),
+												is_pushed_down,
+												has_clone,
+												is_clone,
+												pseudoconstant,
+												security_level,
+												required_relids,
+												incompatible_relids,
+												outer_relids);
 	}
 	else if (is_andclause(clause))
 	{
@@ -328,17 +319,17 @@ make_sub_restrictinfos(PlannerInfo *root,
 		return make_andclause(andlist);
 	}
 	else
-		return (Expr *) make_restrictinfo_internal(root,
-												   clause,
-												   NULL,
-												   is_pushed_down,
-												   has_clone,
-												   is_clone,
-												   pseudoconstant,
-												   security_level,
-												   required_relids,
-												   incompatible_relids,
-												   outer_relids);
+		return (Expr *) make_plain_restrictinfo(root,
+												clause,
+												NULL,
+												is_pushed_down,
+												has_clone,
+												is_clone,
+												pseudoconstant,
+												security_level,
+												required_relids,
+												incompatible_relids,
+												outer_relids);
 }
 
 /*
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index fe03a8ecd34..f32dae8620b 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -22,6 +22,17 @@
 	make_restrictinfo(root, clause, true, false, false, false, 0, \
 		NULL, NULL, NULL)
 
+extern RestrictInfo *make_plain_restrictinfo(PlannerInfo *root,
+											 Expr *clause,
+											 Expr *orclause,
+											 bool is_pushed_down,
+											 bool has_clone,
+											 bool is_clone,
+											 bool pseudoconstant,
+											 Index security_level,
+											 Relids required_relids,
+											 Relids incompatible_relids,
+											 Relids outer_relids);
 extern RestrictInfo *make_restrictinfo(PlannerInfo *root,
 									   Expr *clause,
 									   bool is_pushed_down,
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index e4d117e47ae..b003492c5c8 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1875,6 +1875,60 @@ SELECT * FROM tenk1
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
 (1 row)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
+                                                                QUERY PLAN                                                                 
+-------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND (tenthous IS NULL)) OR ((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42))))
+   Filter: ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42) OR (tenthous IS NULL))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous IS NULL))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+(8 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+                                                 QUERY PLAN                                                  
+-------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+                                                       QUERY PLAN                                                        
+-------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (thousand = 42)
+   Filter: ((tenthous = '1'::smallint) OR ((tenthous)::smallint = '3'::bigint) OR ((tenthous)::smallint = '42'::bigint))
+   ->  Bitmap Index Scan on tenk1_thous_tenthous
+         Index Cond: (thousand = 42)
+(5 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+                                                                     QUERY PLAN                                                                      
+-----------------------------------------------------------------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: (((thousand = 42) AND ((tenthous = '3'::bigint) OR (tenthous = '42'::bigint))) OR ((thousand = 42) AND (tenthous = '1'::smallint)))
+   Filter: ((tenthous = '1'::smallint) OR (tenthous = '3'::bigint) OR (tenthous = '42'::bigint))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{3,42}'::bigint[])))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = '1'::smallint))
+(8 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -2003,25 +2057,24 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
-                                                       QUERY PLAN                                                       
-------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                        
+--------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
+         Recheck Cond: (((hundred = 42) AND (((thousand = 42) OR (thousand = 99)) OR (tenthous < 2))) OR (thousand = 41))
+         Filter: (((hundred = 42) AND ((thousand = 42) OR (thousand = 99) OR (tenthous < 2))) OR (thousand = 41))
          ->  BitmapOr
                ->  BitmapAnd
                      ->  Bitmap Index Scan on tenk1_hundred
                            Index Cond: (hundred = 42)
                      ->  BitmapOr
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 42)
-                           ->  Bitmap Index Scan on tenk1_thous_tenthous
-                                 Index Cond: (thousand = 99)
+                                 Index Cond: (thousand = ANY ('{42,99}'::integer[]))
                            ->  Bitmap Index Scan on tenk1_thous_tenthous
                                  Index Cond: (tenthous < 2)
                ->  Bitmap Index Scan on tenk1_thous_tenthous
                      Index Cond: (thousand = 41)
-(16 rows)
+(15 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99 OR tenthous < 2) OR thousand = 41;
@@ -2033,22 +2086,21 @@ SELECT count(*) FROM tenk1
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
-                                                       QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR ((thousand = 42) OR (thousand = 41))))
+         Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 42)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = 41)
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: ((thousand = 99) AND (tenthous = 2))
-(13 rows)
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+(12 rows)
 
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 41 OR thousand = 99 AND tenthous = 2);
@@ -3144,6 +3196,49 @@ SELECT  b.relname,
 (2 rows)
 
 DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before;
+-- Check bitmap scan can consider similar OR arguments separately without
+-- grouping them into SAOP.
+CREATE TABLE bitmap_split_or (a int NOT NULL, b int NOT NULL, c int NOT NULL);
+INSERT INTO bitmap_split_or (SELECT 1, 1, i FROM generate_series(1, 1000) i);
+INSERT INTO bitmap_split_or (select i, 2, 2 FROM generate_series(1, 1000) i);
+VACUUM ANALYZE bitmap_split_or;
+CREATE INDEX t_b_partial_1_idx ON bitmap_split_or (b) WHERE a = 1;
+CREATE INDEX t_b_partial_2_idx ON bitmap_split_or (b) WHERE a = 2;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or WHERE (a = 1 OR a = 2) AND b = 2;
+                            QUERY PLAN                            
+------------------------------------------------------------------
+ Bitmap Heap Scan on bitmap_split_or
+   Recheck Cond: (((b = 2) AND (a = 1)) OR ((b = 2) AND (a = 2)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on t_b_partial_1_idx
+               Index Cond: (b = 2)
+         ->  Bitmap Index Scan on t_b_partial_2_idx
+               Index Cond: (b = 2)
+(7 rows)
+
+DROP INDEX t_b_partial_1_idx;
+DROP INDEX t_b_partial_2_idx;
+CREATE INDEX t_a_b_idx ON bitmap_split_or (a, b);
+CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
+CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
+CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
+ANALYZE bitmap_split_or;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
+                            QUERY PLAN                            
+------------------------------------------------------------------
+ Bitmap Heap Scan on bitmap_split_or
+   Recheck Cond: (((b = 1) AND (c = 2)) OR ((a = 1) AND (b = 2)))
+   Filter: ((a = 1) AND (c = 2))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on t_b_c_idx
+               Index Cond: ((b = 1) AND (c = 2))
+         ->  Bitmap Index Scan on t_a_b_idx
+               Index Cond: ((a = 1) AND (b = 2))
+(8 rows)
+
+DROP TABLE bitmap_split_or;
 --
 -- REINDEX SCHEMA
 --
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 270a7191e68..ebf2e3f851a 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4296,20 +4296,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (17 rows)
 
 explain (costs off)
@@ -4323,12 +4323,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
+               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = 3)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (12 rows)
 
 explain (costs off)
@@ -4340,21 +4340,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4366,21 +4366,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
+         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_unique1
-                     Index Cond: (unique1 = 2)
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 4)
+               ->  Bitmap Index Scan on tenk1_unique1
+                     Index Cond: (unique1 = 2)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = 1)
 (18 rows)
 
 explain (costs off)
@@ -4394,18 +4394,16 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
+               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR ((unique1 = 3) OR (unique1 = 1)) OR (unique1 < 20))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 < 20)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 3)
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = 1)
                      ->  Bitmap Index Scan on tenk1_unique2
                            Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-(16 rows)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 < 20)
+(14 rows)
 
 --
 -- test placement of movable quals in a parameterized join tree
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 71a7115067e..216bd9660c3 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -738,6 +738,23 @@ SELECT * FROM tenk1
 SELECT * FROM tenk1
   WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
+
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1
+  WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1321,6 +1338,27 @@ SELECT  b.relname,
   ORDER BY 1;
 DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before;
 
+-- Check bitmap scan can consider similar OR arguments separately without
+-- grouping them into SAOP.
+CREATE TABLE bitmap_split_or (a int NOT NULL, b int NOT NULL, c int NOT NULL);
+INSERT INTO bitmap_split_or (SELECT 1, 1, i FROM generate_series(1, 1000) i);
+INSERT INTO bitmap_split_or (select i, 2, 2 FROM generate_series(1, 1000) i);
+VACUUM ANALYZE bitmap_split_or;
+CREATE INDEX t_b_partial_1_idx ON bitmap_split_or (b) WHERE a = 1;
+CREATE INDEX t_b_partial_2_idx ON bitmap_split_or (b) WHERE a = 2;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or WHERE (a = 1 OR a = 2) AND b = 2;
+DROP INDEX t_b_partial_1_idx;
+DROP INDEX t_b_partial_2_idx;
+CREATE INDEX t_a_b_idx ON bitmap_split_or (a, b);
+CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
+CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
+CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
+ANALYZE bitmap_split_or;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
+DROP TABLE bitmap_split_or;
+
 --
 -- REINDEX SCHEMA
 --
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 08521d51a9b..b54428b38cd 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1767,6 +1767,7 @@ OprCacheKey
 OprInfo
 OprProofCacheEntry
 OprProofCacheKey
+OrArgIndexMatch
 OuterJoinClauseInfo
 OutputPluginCallbacks
 OutputPluginOptions
-- 
2.39.5 (Apple Git-154)

#284Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#283)
Re: POC, WIP: OR-clause support for indexes

On 18/11/2024 06:19, Alexander Korotkov wrote:

On Fri, Nov 15, 2024 at 3:27 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:
Here is the next revision of this patch. No material changes,
adjustments for comments and commit message.

I have passed through the code and found no issues. Maybe only phrase:
"eval_const_expressions() will be simplified if there is more than one."
which is used in both patches: here, the 'will' may be removed, as for me.

Also, I re-read the thread, and as AFAICS, no other issues remain. So, I
think it would be OK to move the status of this feature to 'ready for
committer'.

--
regards, Andrei Lepikhov

#285Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#284)
Re: POC, WIP: OR-clause support for indexes

On Wed, Nov 20, 2024 at 8:20 AM Andrei Lepikhov <lepihov@gmail.com> wrote:

On 18/11/2024 06:19, Alexander Korotkov wrote:

On Fri, Nov 15, 2024 at 3:27 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:
Here is the next revision of this patch. No material changes,
adjustments for comments and commit message.

I have passed through the code and found no issues. Maybe only phrase:
"eval_const_expressions() will be simplified if there is more than one."
which is used in both patches: here, the 'will' may be removed, as for me.

Exactly same wording is used in match_index_to_operand(). So, I think
we can save this.

Also, I re-read the thread, and as AFAICS, no other issues remain. So, I
think it would be OK to move the status of this feature to 'ready for
committer'.

Yes, I also re-read the thread. One thing caught my eye is that
Robert didn't answer my point that as we generally don't care about
lazy parameters evaluation while pushing quals as index conds then we
don't have to do this in this patch. I think there were quite amount
of time to express disagreement if any. If even this question will
arise, that's well isolated issue which could be nailed down later.

I'm going to push this if no objections.

Links.
1. /messages/by-id/CAPpHfdt8kowRDUkmOnO7_WJJQ1uk+O379JiZCk_9_Pt5AQ4+0w@mail.gmail.com

------
Regards,
Alexander Korotkov
Supabase

#286jian he
jian.universality@gmail.com
In reply to: Alexander Korotkov (#285)
Re: POC, WIP: OR-clause support for indexes

looking at it again. in match_orclause_to_indexcol

/* Only the operator returning a boolean suits the transformation. */
if (get_op_rettype(opno) != BOOLOID)
break;

can change to

if (subClause->opresulttype != BOOLOID)
break;

for saving some cycles?

#287Richard Guo
guofenglinux@gmail.com
In reply to: Alexander Korotkov (#285)
Re: POC, WIP: OR-clause support for indexes

On Thu, Nov 21, 2024 at 3:34 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

I'm going to push this if no objections.

Here is an Assert failure in match_orclause_to_indexcol.

create table t (a int);
create index on t (a);

# explain select * from t where a <= 0 or a <= 1;
server closed the connection unexpectedly

The assertion is that the collected Const values cannot be NULL and
cannot be zero. The latter part about zero values doesn't make sense
to me. Why can't the values be zero?

Assert(!value->constisnull && value->constvalue);

Thanks
Richard

#288Alexander Korotkov
aekorotkov@gmail.com
In reply to: Richard Guo (#287)
Re: POC, WIP: OR-clause support for indexes

Hi, Richard!

On Mon, Nov 25, 2024 at 8:28 AM Richard Guo <guofenglinux@gmail.com> wrote:

On Thu, Nov 21, 2024 at 3:34 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

I'm going to push this if no objections.

Here is an Assert failure in match_orclause_to_indexcol.

create table t (a int);
create index on t (a);

# explain select * from t where a <= 0 or a <= 1;
server closed the connection unexpectedly

The assertion is that the collected Const values cannot be NULL and
cannot be zero. The latter part about zero values doesn't make sense
to me. Why can't the values be zero?

Assert(!value->constisnull && value->constvalue);

Yes, this is a dumb assertion. Removed.

------
Regards,
Alexander Korotkov
Supabase

#289Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#288)
Re: POC, WIP: OR-clause support for indexes

On 11/25/24 14:08, Alexander Korotkov wrote:

Hi, Richard!

On Mon, Nov 25, 2024 at 8:28 AM Richard Guo <guofenglinux@gmail.com> wrote:

On Thu, Nov 21, 2024 at 3:34 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:

I'm going to push this if no objections.

Here is an Assert failure in match_orclause_to_indexcol.

create table t (a int);
create index on t (a);

# explain select * from t where a <= 0 or a <= 1;
server closed the connection unexpectedly

The assertion is that the collected Const values cannot be NULL and
cannot be zero. The latter part about zero values doesn't make sense
to me. Why can't the values be zero?

I guess, this code came from the first raw prototypes designed with the
erroneous assumption that they would check a NULL pointer.
Anyway, thanks for looking into it!

Assert(!value->constisnull && value->constvalue);

Yes, this is a dumb assertion. Removed.

Thank you!

--
regards, Andrei Lepikhov

#290Alexander Lakhin
exclusion@gmail.com
In reply to: Alexander Korotkov (#285)
Re: POC, WIP: OR-clause support for indexes

Hello Alexander,

21.11.2024 09:34, Alexander Korotkov wrote:

I'm going to push this if no objections.

Please look at the following query, which triggers an error after ae4569161:
SET random_page_cost = 1;
CREATE TABLE tbl(u UUID);
CREATE INDEX idx ON tbl USING HASH (u);
SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR
  u = '11111111111111111111111111111111';

ERROR:  XX000: ScalarArrayOpExpr index qual found where not allowed
LOCATION:  ExecIndexBuildScanKeys, nodeIndexscan.c:1625

Best regards,
Alexander

#291Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Lakhin (#290)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi! Thank you for the case.

On 28.11.2024 21:00, Alexander Lakhin wrote:

Hello Alexander,

21.11.2024 09:34, Alexander Korotkov wrote:

I'm going to push this if no objections.

Please look at the following query, which triggers an error after
ae4569161:
SET random_page_cost = 1;
CREATE TABLE tbl(u UUID);
CREATE INDEX idx ON tbl USING HASH (u);
SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR
  u = '11111111111111111111111111111111';

ERROR:  XX000: ScalarArrayOpExpr index qual found where not allowed
LOCATION:  ExecIndexBuildScanKeys, nodeIndexscan.c:1625

I found out what the problem is index scan method was not generated. We
need to check this during OR clauses for SAOP transformation.

There is a patch to fix this problem.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

bugfix.difftext/x-patch; charset=UTF-8; name=bugfix.diffDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index d827fc9f4d9..61110db65dd 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3303,6 +3303,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		if (get_op_rettype(opno) != BOOLOID)
 			break;
 
+		/* Ignore index if it doesn't support index scans */
+		if(!index->amsearcharray)
+			break;
+
 		/*
 		 * Check for clauses of the form: (indexkey operator constant) or
 		 * (constant operator indexkey).  Determine indexkey side first, check
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index ddd0d9ad396..0e6529f3f3d 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -372,6 +372,11 @@ CREATE INDEX hash_tuplesort_idx ON tenk1 USING hash (stringu1 name_ops) WITH (fi
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1 WHERE stringu1 = 'TVAAAA';
 SELECT count(*) FROM tenk1 WHERE stringu1 = 'TVAAAA';
+-- Transform OR-clauses to SAOP's shouldn't be chosen
+SET random_page_cost = 1;
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM tenk1 WHERE stringu1 = 'TVAAAA' OR  stringu1 = 'TVAAAB';
+RESET random_page_cost;
 DROP INDEX hash_tuplesort_idx;
 RESET maintenance_work_mem;
 
#292Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#291)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Sorry, I was in a hurry and forgot to add the test result. I updated the
patch

On 28.11.2024 22:03, Alena Rybakina wrote:

Hi! Thank you for the case.

On 28.11.2024 21:00, Alexander Lakhin wrote:

Hello Alexander,

21.11.2024 09:34, Alexander Korotkov wrote:

I'm going to push this if no objections.

Please look at the following query, which triggers an error after
ae4569161:
SET random_page_cost = 1;
CREATE TABLE tbl(u UUID);
CREATE INDEX idx ON tbl USING HASH (u);
SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR
  u = '11111111111111111111111111111111';

ERROR:  XX000: ScalarArrayOpExpr index qual found where not allowed
LOCATION:  ExecIndexBuildScanKeys, nodeIndexscan.c:1625

I found out what the problem is index scan method was not generated.
We need to check this during OR clauses for SAOP transformation.

There is a patch to fix this problem.

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

bugfix.difftext/x-patch; charset=UTF-8; name=bugfix.diffDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index d827fc9f4d9..61110db65dd 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3303,6 +3303,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		if (get_op_rettype(opno) != BOOLOID)
 			break;
 
+		/* Ignore index if it doesn't support index scans */
+		if(!index->amsearcharray)
+			break;
+
 		/*
 		 * Check for clauses of the form: (indexkey operator constant) or
 		 * (constant operator indexkey).  Determine indexkey side first, check
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 1b0a5f0e9e1..ef8bbf4748c 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1233,6 +1233,23 @@ SELECT count(*) FROM tenk1 WHERE stringu1 = 'TVAAAA';
     14
 (1 row)
 
+-- Transform OR-clauses to SAOP's shouldn't be chosen
+SET random_page_cost = 1;
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM tenk1 WHERE stringu1 = 'TVAAAA' OR  stringu1 = 'TVAAAB';
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((stringu1 = 'TVAAAA'::name) OR (stringu1 = 'TVAAAB'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on hash_tuplesort_idx
+                     Index Cond: (stringu1 = 'TVAAAA'::name)
+               ->  Bitmap Index Scan on hash_tuplesort_idx
+                     Index Cond: (stringu1 = 'TVAAAB'::name)
+(8 rows)
+
+RESET random_page_cost;
 DROP INDEX hash_tuplesort_idx;
 RESET maintenance_work_mem;
 --
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index ddd0d9ad396..0e6529f3f3d 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -372,6 +372,11 @@ CREATE INDEX hash_tuplesort_idx ON tenk1 USING hash (stringu1 name_ops) WITH (fi
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1 WHERE stringu1 = 'TVAAAA';
 SELECT count(*) FROM tenk1 WHERE stringu1 = 'TVAAAA';
+-- Transform OR-clauses to SAOP's shouldn't be chosen
+SET random_page_cost = 1;
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM tenk1 WHERE stringu1 = 'TVAAAA' OR  stringu1 = 'TVAAAB';
+RESET random_page_cost;
 DROP INDEX hash_tuplesort_idx;
 RESET maintenance_work_mem;
 
#293Ranier Vilela
ranier.vf@gmail.com
In reply to: Alena Rybakina (#291)
Re: POC, WIP: OR-clause support for indexes

Em qui., 28 de nov. de 2024 às 16:03, Alena Rybakina <
a.rybakina@postgrespro.ru> escreveu:

Hi! Thank you for the case.

On 28.11.2024 21:00, Alexander Lakhin wrote:

Hello Alexander,

21.11.2024 09:34, Alexander Korotkov wrote:

I'm going to push this if no objections.

Please look at the following query, which triggers an error after
ae4569161:
SET random_page_cost = 1;
CREATE TABLE tbl(u UUID);
CREATE INDEX idx ON tbl USING HASH (u);
SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR
u = '11111111111111111111111111111111';

ERROR: XX000: ScalarArrayOpExpr index qual found where not allowed
LOCATION: ExecIndexBuildScanKeys, nodeIndexscan.c:1625

I found out what the problem is index scan method was not generated. We
need to check this during OR clauses for SAOP transformation.

There is a patch to fix this problem.

Hi.
Thanks for the quick fix.

But I wonder if it is not possible to avoid all if the index is useless?
Maybe moving your fix to the beginning of the function?

diff --git a/src/backend/optimizer/path/indxpath.c
b/src/backend/optimizer/path/indxpath.c
index d827fc9f4d..5ea0b27d01 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3248,6 +3248,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
  Assert(IsA(orclause, BoolExpr));
  Assert(orclause->boolop == OR_EXPR);
+ /* Ignore index if it doesn't support index scans */
+ if(!index->amsearcharray)
+ return NULL;
+
  /*
  * Try to convert a list of OR-clauses to a single SAOP expression. Each
  * OR entry must be in the form: (indexkey operator constant) or (constant

The test bug:
EXPLAIN SELECT COUNT(*) FROM tbl WHERE u =
'00000000000000000000000000000000' OR u =
'11111111111111111111111111111111';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=12.46..12.47 rows=1 width=8)
-> Bitmap Heap Scan on tbl (cost=2.14..12.41 rows=18 width=0)
Recheck Cond: ((u = '00000000-0000-0000-0000-000000000000'::uuid)
OR (u = '11111111-1111-1111-1111-111111111111'::uuid))
-> BitmapOr (cost=2.14..2.14 rows=18 width=0)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9
width=0)
Index Cond: (u =
'00000000-0000-0000-0000-000000000000'::uuid)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9
width=0)
Index Cond: (u =
'11111111-1111-1111-1111-111111111111'::uuid)
(8 rows)

best regards,
Ranier Vilela

#294Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Ranier Vilela (#293)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 28.11.2024 22:28, Ranier Vilela wrote:

Em qui., 28 de nov. de 2024 às 16:03, Alena Rybakina
<a.rybakina@postgrespro.ru> escreveu:

Hi! Thank you for the case.

On 28.11.2024 21:00, Alexander Lakhin wrote:

Hello Alexander,

21.11.2024 09:34, Alexander Korotkov wrote:

I'm going to push this if no objections.

Please look at the following query, which triggers an error after
ae4569161:
SET random_page_cost = 1;
CREATE TABLE tbl(u UUID);
CREATE INDEX idx ON tbl USING HASH (u);
SELECT COUNT(*) FROM tbl WHERE u =

'00000000000000000000000000000000' OR

  u = '11111111111111111111111111111111';

ERROR:  XX000: ScalarArrayOpExpr index qual found where not allowed
LOCATION:  ExecIndexBuildScanKeys, nodeIndexscan.c:1625

I found out what the problem is index scan method was not
generated. We
need to check this during OR clauses for SAOP transformation.

There is a patch to fix this problem.

Hi.
Thanks for the quick fix.

But I wonder if it is not possible to avoid all if the index is useless?
Maybe moving your fix to the beginning of the function?

diff --git a/src/backend/optimizer/path/indxpath.c 
b/src/backend/optimizer/path/indxpath.c
index d827fc9f4d..5ea0b27d01 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3248,6 +3248,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
  Assert(IsA(orclause, BoolExpr));
  Assert(orclause->boolop == OR_EXPR);
+ /* Ignore index if it doesn't support index scans */
+ if(!index->amsearcharray)
+ return NULL;
+

Agree. I have updated the patch

  /*
  * Try to convert a list of OR-clauses to a single SAOP expression. Each
  * OR entry must be in the form: (indexkey operator constant) or
(constant

The test bug:
EXPLAIN SELECT COUNT(*) FROM tbl WHERE u =
'00000000000000000000000000000000' OR u =
'11111111111111111111111111111111';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=12.46..12.47 rows=1 width=8)
   ->  Bitmap Heap Scan on tbl  (cost=2.14..12.41 rows=18 width=0)
         Recheck Cond: ((u =
'00000000-0000-0000-0000-000000000000'::uuid) OR (u =
'11111111-1111-1111-1111-111111111111'::uuid))
         ->  BitmapOr  (cost=2.14..2.14 rows=18 width=0)
               ->  Bitmap Index Scan on idx  (cost=0.00..1.07 rows=9
width=0)
                     Index Cond: (u =
'00000000-0000-0000-0000-000000000000'::uuid)
               ->  Bitmap Index Scan on idx  (cost=0.00..1.07 rows=9
width=0)
                     Index Cond: (u =
'11111111-1111-1111-1111-111111111111'::uuid)
(8 rows)

Thank you

--
Regards,
Alena Rybakina
Postgres Professional

Attachments:

bugfix.difftext/x-patch; charset=UTF-8; name=bugfix.diffDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index d827fc9f4d9..5ea0b27d014 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3248,6 +3248,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Assert(IsA(orclause, BoolExpr));
 	Assert(orclause->boolop == OR_EXPR);
 
+	/* Ignore index if it doesn't support index scans */
+	if(!index->amsearcharray)
+		return NULL;
+
 	/*
 	 * Try to convert a list of OR-clauses to a single SAOP expression. Each
 	 * OR entry must be in the form: (indexkey operator constant) or (constant
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 1b0a5f0e9e1..ef8bbf4748c 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1233,6 +1233,23 @@ SELECT count(*) FROM tenk1 WHERE stringu1 = 'TVAAAA';
     14
 (1 row)
 
+-- Transform OR-clauses to SAOP's shouldn't be chosen
+SET random_page_cost = 1;
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM tenk1 WHERE stringu1 = 'TVAAAA' OR  stringu1 = 'TVAAAB';
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((stringu1 = 'TVAAAA'::name) OR (stringu1 = 'TVAAAB'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on hash_tuplesort_idx
+                     Index Cond: (stringu1 = 'TVAAAA'::name)
+               ->  Bitmap Index Scan on hash_tuplesort_idx
+                     Index Cond: (stringu1 = 'TVAAAB'::name)
+(8 rows)
+
+RESET random_page_cost;
 DROP INDEX hash_tuplesort_idx;
 RESET maintenance_work_mem;
 --
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index ddd0d9ad396..0e6529f3f3d 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -372,6 +372,11 @@ CREATE INDEX hash_tuplesort_idx ON tenk1 USING hash (stringu1 name_ops) WITH (fi
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1 WHERE stringu1 = 'TVAAAA';
 SELECT count(*) FROM tenk1 WHERE stringu1 = 'TVAAAA';
+-- Transform OR-clauses to SAOP's shouldn't be chosen
+SET random_page_cost = 1;
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM tenk1 WHERE stringu1 = 'TVAAAA' OR  stringu1 = 'TVAAAB';
+RESET random_page_cost;
 DROP INDEX hash_tuplesort_idx;
 RESET maintenance_work_mem;
 
#295Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#294)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Thu, Nov 28, 2024 at 9:33 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 28.11.2024 22:28, Ranier Vilela wrote:

Em qui., 28 de nov. de 2024 às 16:03, Alena Rybakina <a.rybakina@postgrespro.ru> escreveu:

Hi! Thank you for the case.

On 28.11.2024 21:00, Alexander Lakhin wrote:

Hello Alexander,

21.11.2024 09:34, Alexander Korotkov wrote:

I'm going to push this if no objections.

Please look at the following query, which triggers an error after
ae4569161:
SET random_page_cost = 1;
CREATE TABLE tbl(u UUID);
CREATE INDEX idx ON tbl USING HASH (u);
SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR
u = '11111111111111111111111111111111';

ERROR: XX000: ScalarArrayOpExpr index qual found where not allowed
LOCATION: ExecIndexBuildScanKeys, nodeIndexscan.c:1625

I found out what the problem is index scan method was not generated. We
need to check this during OR clauses for SAOP transformation.

There is a patch to fix this problem.

Hi.
Thanks for the quick fix.

But I wonder if it is not possible to avoid all if the index is useless?
Maybe moving your fix to the beginning of the function?

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index d827fc9f4d..5ea0b27d01 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3248,6 +3248,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
Assert(IsA(orclause, BoolExpr));
Assert(orclause->boolop == OR_EXPR);
+ /* Ignore index if it doesn't support index scans */
+ if(!index->amsearcharray)
+ return NULL;
+

Agree. I have updated the patch

/*
* Try to convert a list of OR-clauses to a single SAOP expression. Each
* OR entry must be in the form: (indexkey operator constant) or (constant

The test bug:
EXPLAIN SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR u = '11111111111111111111111111111111';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=12.46..12.47 rows=1 width=8)
-> Bitmap Heap Scan on tbl (cost=2.14..12.41 rows=18 width=0)
Recheck Cond: ((u = '00000000-0000-0000-0000-000000000000'::uuid) OR (u = '11111111-1111-1111-1111-111111111111'::uuid))
-> BitmapOr (cost=2.14..2.14 rows=18 width=0)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
Index Cond: (u = '00000000-0000-0000-0000-000000000000'::uuid)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
Index Cond: (u = '11111111-1111-1111-1111-111111111111'::uuid)
(8 rows)

I slightly revised the fix and added similar check to
group_similar_or_args(). Could you, please, review that before
commit?

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v3-0001-Skip-not-SOAP-supported-indexes-while-transformin.patchapplication/octet-stream; name=v3-0001-Skip-not-SOAP-supported-indexes-while-transformin.patchDownload
From b9fc7d52ebb051fe5f67501407c56daf0af765da Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Fri, 29 Nov 2024 01:46:43 +0200
Subject: [PATCH v3] Skip not SOAP-supported indexes while transforming an OR
 clause into SAOP

There is no point in transforming OR-clauses into SAOP's if the target index
doesn't support SAOP scans anyway.  This commit adds corresponding checks
to match_orclause_to_indexcol() and group_similar_or_args().  The first check
fixes the actual bug, while the second just saves some cycles.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/8174de69-9e1a-0827-0e81-ef97f56a5939%40gmail.com
Author: Alena Rybakina
Reviewed-by: Ranier Vilela, Alexander Korotkov
---
 src/backend/optimizer/path/indxpath.c      | 11 +++++++++--
 src/test/regress/expected/create_index.out | 18 ++++++++++++++++++
 src/test/regress/sql/create_index.sql      |  6 ++++++
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index d827fc9f4d9..640b28a68fc 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1354,8 +1354,11 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 		{
 			IndexOptInfo *index = (IndexOptInfo *) lfirst(lc2);
 
-			/* Ignore index if it doesn't support bitmap scans */
-			if (!index->amhasgetbitmap)
+			/*
+			 * Ignore index if it doesn't support bitmap scans or SAOP
+			 * clauses.
+			 */
+			if (!index->amhasgetbitmap || !index->amsearcharray)
 				continue;
 
 			for (colnum = 0; colnum < index->nkeycolumns; colnum++)
@@ -3248,6 +3251,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Assert(IsA(orclause, BoolExpr));
 	Assert(orclause->boolop == OR_EXPR);
 
+	/* Ignore index if it doesn't support SAOP clauses */
+	if(!index->amsearcharray)
+		return NULL;
+
 	/*
 	 * Try to convert a list of OR-clauses to a single SAOP expression. Each
 	 * OR entry must be in the form: (indexkey operator constant) or (constant
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 1b0a5f0e9e1..1904eb65bb9 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1233,6 +1233,24 @@ SELECT count(*) FROM tenk1 WHERE stringu1 = 'TVAAAA';
     14
 (1 row)
 
+-- OR-clauses shouldn't be transformed into SAOP because hash indexes don't
+-- support SAOP scans.
+SET enable_seqscan = off;
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM tenk1 WHERE stringu1 = 'TVAAAA' OR  stringu1 = 'TVAAAB';
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
+ Aggregate
+   ->  Bitmap Heap Scan on tenk1
+         Recheck Cond: ((stringu1 = 'TVAAAA'::name) OR (stringu1 = 'TVAAAB'::name))
+         ->  BitmapOr
+               ->  Bitmap Index Scan on hash_tuplesort_idx
+                     Index Cond: (stringu1 = 'TVAAAA'::name)
+               ->  Bitmap Index Scan on hash_tuplesort_idx
+                     Index Cond: (stringu1 = 'TVAAAB'::name)
+(8 rows)
+
+RESET enable_seqscan;
 DROP INDEX hash_tuplesort_idx;
 RESET maintenance_work_mem;
 --
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index ddd0d9ad396..c085e05f052 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -372,6 +372,12 @@ CREATE INDEX hash_tuplesort_idx ON tenk1 USING hash (stringu1 name_ops) WITH (fi
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1 WHERE stringu1 = 'TVAAAA';
 SELECT count(*) FROM tenk1 WHERE stringu1 = 'TVAAAA';
+-- OR-clauses shouldn't be transformed into SAOP because hash indexes don't
+-- support SAOP scans.
+SET enable_seqscan = off;
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM tenk1 WHERE stringu1 = 'TVAAAA' OR  stringu1 = 'TVAAAB';
+RESET enable_seqscan;
 DROP INDEX hash_tuplesort_idx;
 RESET maintenance_work_mem;
 
-- 
2.39.5 (Apple Git-154)

#296Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#295)
Re: POC, WIP: OR-clause support for indexes

On 11/29/24 07:04, Alexander Korotkov wrote:

On Thu, Nov 28, 2024 at 9:33 PM Alena Rybakina
I slightly revised the fix and added similar check to
group_similar_or_args(). Could you, please, review that before
commit?

LGTM,
As I see, we didn't pay attention to this option from the beginning.
Thanks for fixing it!

--
regards, Andrei Lepikhov

#297Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#295)
Re: POC, WIP: OR-clause support for indexes

On 29.11.2024 03:04, Alexander Korotkov wrote:

On Thu, Nov 28, 2024 at 9:33 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 28.11.2024 22:28, Ranier Vilela wrote:

Em qui., 28 de nov. de 2024 às 16:03, Alena Rybakina <a.rybakina@postgrespro.ru> escreveu:

Hi! Thank you for the case.

On 28.11.2024 21:00, Alexander Lakhin wrote:

Hello Alexander,

21.11.2024 09:34, Alexander Korotkov wrote:

I'm going to push this if no objections.

Please look at the following query, which triggers an error after
ae4569161:
SET random_page_cost = 1;
CREATE TABLE tbl(u UUID);
CREATE INDEX idx ON tbl USING HASH (u);
SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR
u = '11111111111111111111111111111111';

ERROR: XX000: ScalarArrayOpExpr index qual found where not allowed
LOCATION: ExecIndexBuildScanKeys, nodeIndexscan.c:1625

I found out what the problem is index scan method was not generated. We
need to check this during OR clauses for SAOP transformation.

There is a patch to fix this problem.

Hi.
Thanks for the quick fix.

But I wonder if it is not possible to avoid all if the index is useless?
Maybe moving your fix to the beginning of the function?

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index d827fc9f4d..5ea0b27d01 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3248,6 +3248,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
Assert(IsA(orclause, BoolExpr));
Assert(orclause->boolop == OR_EXPR);
+ /* Ignore index if it doesn't support index scans */
+ if(!index->amsearcharray)
+ return NULL;
+

Agree. I have updated the patch

/*
* Try to convert a list of OR-clauses to a single SAOP expression. Each
* OR entry must be in the form: (indexkey operator constant) or (constant

The test bug:
EXPLAIN SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR u = '11111111111111111111111111111111';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=12.46..12.47 rows=1 width=8)
-> Bitmap Heap Scan on tbl (cost=2.14..12.41 rows=18 width=0)
Recheck Cond: ((u = '00000000-0000-0000-0000-000000000000'::uuid) OR (u = '11111111-1111-1111-1111-111111111111'::uuid))
-> BitmapOr (cost=2.14..2.14 rows=18 width=0)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
Index Cond: (u = '00000000-0000-0000-0000-000000000000'::uuid)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
Index Cond: (u = '11111111-1111-1111-1111-111111111111'::uuid)
(8 rows)

I slightly revised the fix and added similar check to
group_similar_or_args(). Could you, please, review that before
commit?

I agree with changes. Thank you!

--
Regards,
Alena Rybakina
Postgres Professional

#298Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#297)
Re: POC, WIP: OR-clause support for indexes

On Fri, Nov 29, 2024 at 7:51 AM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 29.11.2024 03:04, Alexander Korotkov wrote:

On Thu, Nov 28, 2024 at 9:33 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 28.11.2024 22:28, Ranier Vilela wrote:

Em qui., 28 de nov. de 2024 às 16:03, Alena Rybakina <a.rybakina@postgrespro.ru> escreveu:

Hi! Thank you for the case.

On 28.11.2024 21:00, Alexander Lakhin wrote:

Hello Alexander,

21.11.2024 09:34, Alexander Korotkov wrote:

I'm going to push this if no objections.

Please look at the following query, which triggers an error after
ae4569161:
SET random_page_cost = 1;
CREATE TABLE tbl(u UUID);
CREATE INDEX idx ON tbl USING HASH (u);
SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR
u = '11111111111111111111111111111111';

ERROR: XX000: ScalarArrayOpExpr index qual found where not allowed
LOCATION: ExecIndexBuildScanKeys, nodeIndexscan.c:1625

I found out what the problem is index scan method was not generated. We
need to check this during OR clauses for SAOP transformation.

There is a patch to fix this problem.

Hi.
Thanks for the quick fix.

But I wonder if it is not possible to avoid all if the index is useless?
Maybe moving your fix to the beginning of the function?

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index d827fc9f4d..5ea0b27d01 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3248,6 +3248,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
Assert(IsA(orclause, BoolExpr));
Assert(orclause->boolop == OR_EXPR);
+ /* Ignore index if it doesn't support index scans */
+ if(!index->amsearcharray)
+ return NULL;
+

Agree. I have updated the patch

/*
* Try to convert a list of OR-clauses to a single SAOP expression. Each
* OR entry must be in the form: (indexkey operator constant) or (constant

The test bug:
EXPLAIN SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR u = '11111111111111111111111111111111';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=12.46..12.47 rows=1 width=8)
-> Bitmap Heap Scan on tbl (cost=2.14..12.41 rows=18 width=0)
Recheck Cond: ((u = '00000000-0000-0000-0000-000000000000'::uuid) OR (u = '11111111-1111-1111-1111-111111111111'::uuid))
-> BitmapOr (cost=2.14..2.14 rows=18 width=0)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
Index Cond: (u = '00000000-0000-0000-0000-000000000000'::uuid)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
Index Cond: (u = '11111111-1111-1111-1111-111111111111'::uuid)
(8 rows)

I slightly revised the fix and added similar check to
group_similar_or_args(). Could you, please, review that before
commit?

I agree with changes. Thank you!

Andrei, Alena, thank you for the feedback. Pushed!

------
Regards,
Alexander Korotkov
Supabase

#299Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alexander Korotkov (#298)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Fri, Nov 29, 2024 at 9:54 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

On Fri, Nov 29, 2024 at 7:51 AM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 29.11.2024 03:04, Alexander Korotkov wrote:

On Thu, Nov 28, 2024 at 9:33 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 28.11.2024 22:28, Ranier Vilela wrote:

Em qui., 28 de nov. de 2024 às 16:03, Alena Rybakina <a.rybakina@postgrespro.ru> escreveu:

Hi! Thank you for the case.

On 28.11.2024 21:00, Alexander Lakhin wrote:

Hello Alexander,

21.11.2024 09:34, Alexander Korotkov wrote:

I'm going to push this if no objections.

Please look at the following query, which triggers an error after
ae4569161:
SET random_page_cost = 1;
CREATE TABLE tbl(u UUID);
CREATE INDEX idx ON tbl USING HASH (u);
SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR
u = '11111111111111111111111111111111';

ERROR: XX000: ScalarArrayOpExpr index qual found where not allowed
LOCATION: ExecIndexBuildScanKeys, nodeIndexscan.c:1625

I found out what the problem is index scan method was not generated. We
need to check this during OR clauses for SAOP transformation.

There is a patch to fix this problem.

Hi.
Thanks for the quick fix.

But I wonder if it is not possible to avoid all if the index is useless?
Maybe moving your fix to the beginning of the function?

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index d827fc9f4d..5ea0b27d01 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3248,6 +3248,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
Assert(IsA(orclause, BoolExpr));
Assert(orclause->boolop == OR_EXPR);
+ /* Ignore index if it doesn't support index scans */
+ if(!index->amsearcharray)
+ return NULL;
+

Agree. I have updated the patch

/*
* Try to convert a list of OR-clauses to a single SAOP expression. Each
* OR entry must be in the form: (indexkey operator constant) or (constant

The test bug:
EXPLAIN SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR u = '11111111111111111111111111111111';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=12.46..12.47 rows=1 width=8)
-> Bitmap Heap Scan on tbl (cost=2.14..12.41 rows=18 width=0)
Recheck Cond: ((u = '00000000-0000-0000-0000-000000000000'::uuid) OR (u = '11111111-1111-1111-1111-111111111111'::uuid))
-> BitmapOr (cost=2.14..2.14 rows=18 width=0)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
Index Cond: (u = '00000000-0000-0000-0000-000000000000'::uuid)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
Index Cond: (u = '11111111-1111-1111-1111-111111111111'::uuid)
(8 rows)

I slightly revised the fix and added similar check to
group_similar_or_args(). Could you, please, review that before
commit?

I agree with changes. Thank you!

Andrei, Alena, thank you for the feedback. Pushed!

I think we should give some more attention to the patch enabling OR to
SAOP transformation for joins (first time posted in [1]). I think we
tried to only work with Const and Param, because we were previously
working during parse stage. So, at that stage if we have the clause
like "a.x = 1 OR a.x = b.x OR b.x = 2", then we don't know if we
should transform it into "a.x = ANY(1, b.x) OR b.x = 2" or into "a.x
=1 OR b.x = ANY(a.x, 2)". But if we do the transformation during the
index matching, we would actually be able to try the both and select
the best.

The revised patch is attached. Most notably it revises
group_similar_or_args() to have the same notion of const-ness as
others. In that function we split potential index key and constant
early to save time on enumerating all possible index keys. But it
appears to be possible to split by relids bitmapsets: index key should
use our relid, while const shouldn't. Other that that, comments,
commit message and naming are revised.

Links.
1. /messages/by-id/CAPpHfdu9QJ=Gbua3CUUH2KKG_8urakJTen4JD47PGh9wWP=QxQ@mail.gmail.com

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v45-0001-Allow-usage-of-match_orclause_to_indexcol-for-jo.patchapplication/octet-stream; name=v45-0001-Allow-usage-of-match_orclause_to_indexcol-for-jo.patchDownload
From e0bc064032af36d027c497aa5e4302d4fb667950 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Wed, 9 Oct 2024 18:44:25 +0300
Subject: [PATCH v45] Allow usage of match_orclause_to_indexcol() for joins

This commit allows transformation of OR-clauses into SAOP's for index scans
within nested loop joins.  That required the following changes.

 1. Make match_orclause_to_indexcol() and group_similar_or_args() understand
    const-ness in the same way as match_opclause_to_indexcol().  This
    generally makes our approach more uniform.
 2. Make match_join_clauses_to_index() pass OR-clauses to
    match_clause_to_index().
---
 src/backend/optimizer/path/indxpath.c        | 61 +++++++++++---------
 src/test/regress/expected/join.out           |  9 +--
 src/test/regress/expected/partition_join.out | 12 ++--
 3 files changed, 43 insertions(+), 39 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 5f428e835b0..c03547a9973 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1255,6 +1255,7 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 	ListCell   *lc2;
 	List	   *orargs;
 	List	   *result = NIL;
+	Index		relid = rel->relid;
 
 	Assert(IsA(rinfo->orclause, BoolExpr));
 	orargs = ((BoolExpr *) rinfo->orclause)->args;
@@ -1319,10 +1320,13 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 		/*
 		 * Check for clauses of the form: (indexkey operator constant) or
 		 * (constant operator indexkey).  But we don't know a particular index
-		 * yet.  First check for a constant, which must be Const or Param.
-		 * That's cheaper than search for an index key among all indexes.
+		 * yet.  Therefore, we try to distinguish the potential index key and
+		 * constant first, then search for a matching index key among all
+		 * indexes.
 		 */
-		if (IsA(leftop, Const) || IsA(leftop, Param))
+		if (bms_is_member(relid, argrinfo->right_relids) &&
+			!bms_is_member(relid, argrinfo->left_relids) &&
+			!contain_volatile_functions(leftop))
 		{
 			opno = get_commutator(opno);
 
@@ -1333,7 +1337,9 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 			}
 			nonConstExpr = rightop;
 		}
-		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		else if (bms_is_member(relid, argrinfo->left_relids) &&
+				 !bms_is_member(relid, argrinfo->right_relids) &&
+				 !contain_volatile_functions(rightop))
 		{
 			nonConstExpr = leftop;
 		}
@@ -2435,8 +2441,8 @@ match_join_clauses_to_index(PlannerInfo *root,
 		/* Potentially usable, so see if it matches the index or is an OR */
 		if (restriction_is_or_clause(rinfo))
 			*joinorclauses = lappend(*joinorclauses, rinfo);
-		else
-			match_clause_to_index(root, rinfo, index, clauseset);
+
+		match_clause_to_index(root, rinfo, index, clauseset);
 	}
 }
 
@@ -2585,10 +2591,7 @@ match_clause_to_index(PlannerInfo *root,
  *	  (3)  must match the collation of the index, if collation is relevant.
  *
  *	  Our definition of "const" is exceedingly liberal: we allow anything that
- *	  doesn't involve a volatile function or a Var of the index's relation
- *	  except for a boolean OR expression input: due to a trade-off between the
- *	  expected execution speedup and planning complexity, we limit or->saop
- *	  transformation by obvious cases when an index scan can get a profit.
+ *	  doesn't involve a volatile function or a Var of the index's relation.
  *	  In particular, Vars belonging to other relations of the query are
  *	  accepted here, since a clause of that form can be used in a
  *	  parameterized indexscan.  It's the responsibility of higher code levels
@@ -3246,7 +3249,8 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Oid			arraytype = InvalidOid;
 	Oid			inputcollid = InvalidOid;
 	bool		firstTime = true;
-	bool		haveParam = false;
+	bool		haveNonConst = false;
+	Index		indexRelid = index->rel->relid;
 
 	Assert(IsA(orclause, BoolExpr));
 	Assert(orclause->boolop == OR_EXPR);
@@ -3258,10 +3262,9 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	/*
 	 * Try to convert a list of OR-clauses to a single SAOP expression. Each
 	 * OR entry must be in the form: (indexkey operator constant) or (constant
-	 * operator indexkey).  Operators of all the entries must match.  Constant
-	 * might be either Const or Param.  To be effective, give up on the first
-	 * non-matching entry.  Exit is implemented as a break from the loop,
-	 * which is catched afterwards.
+	 * operator indexkey).  Operators of all the entries must match.  To be
+	 * effective, give up on the first non-matching entry.  Exit is
+	 * implemented as a break from the loop, which is catched afterwards.
 	 */
 	foreach(lc, orclause->args)
 	{
@@ -3312,17 +3315,21 @@ match_orclause_to_indexcol(PlannerInfo *root,
 
 		/*
 		 * Check for clauses of the form: (indexkey operator constant) or
-		 * (constant operator indexkey).  Determine indexkey side first, check
-		 * the constant later.
+		 * (constant operator indexkey).  See match_clause_to_indexcol's notes
+		 * about const-ness.
 		 */
 		leftop = (Node *) linitial(subClause->args);
 		rightop = (Node *) lsecond(subClause->args);
-		if (match_index_to_operand(leftop, indexcol, index))
+		if (match_index_to_operand(leftop, indexcol, index) &&
+			!bms_is_member(indexRelid, rinfo->right_relids) &&
+			!contain_volatile_functions(rightop))
 		{
 			indexExpr = leftop;
 			constExpr = rightop;
 		}
-		else if (match_index_to_operand(rightop, indexcol, index))
+		else if (match_index_to_operand(rightop, indexcol, index) &&
+			!bms_is_member(indexRelid, rinfo->left_relids) &&
+			!contain_volatile_functions(leftop))
 		{
 			opno = get_commutator(opno);
 			if (!OidIsValid(opno))
@@ -3349,10 +3356,6 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		if (IsA(indexExpr, RelabelType))
 			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
 
-		/* We allow constant to be Const or Param */
-		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
-			break;
-
 		/* Forbid transformation for composite types, records. */
 		if (type_is_rowtype(exprType(constExpr)) ||
 			type_is_rowtype(exprType(indexExpr)))
@@ -3389,8 +3392,12 @@ match_orclause_to_indexcol(PlannerInfo *root,
 				break;
 		}
 
-		if (IsA(constExpr, Param))
-			haveParam = true;
+		/*
+		 * Check if our list of constants in match_clause_to_indexcol's
+		 * understanding of const-ness have something other than Const.
+		 */
+		if (!IsA(constExpr, Const))
+			haveNonConst = true;
 		consts = lappend(consts, constExpr);
 	}
 
@@ -3407,10 +3414,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
 
 	/*
 	 * Assemble an array from the list of constants.  It seems more profitable
-	 * to build a const array.  But in the presence of parameters, we don't
+	 * to build a const array.  But in the presence of other nodes, we don't
 	 * have a specific value here and must employ an ArrayExpr instead.
 	 */
-	if (haveParam)
+	if (haveNonConst)
 	{
 		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
 
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 079fcf46f0d..634eff4d751 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -3849,14 +3849,11 @@ where q1 = thousand or q2 = thousand;
                ->  Seq Scan on q2
          ->  Bitmap Heap Scan on tenk1
                Recheck Cond: ((q1.q1 = thousand) OR (q2.q2 = thousand))
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = q1.q1)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = q2.q2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY (ARRAY[q1.q1, q2.q2]))
    ->  Hash
          ->  Seq Scan on int4_tbl
-(15 rows)
+(12 rows)
 
 explain (costs off)
 select * from
diff --git a/src/test/regress/expected/partition_join.out b/src/test/regress/expected/partition_join.out
index 108f9ecb445..af468682a2d 100644
--- a/src/test/regress/expected/partition_join.out
+++ b/src/test/regress/expected/partition_join.out
@@ -2533,24 +2533,24 @@ where not exists (select 1 from prtx2
          ->  Seq Scan on prtx1_1
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_1
-               Recheck Cond: ((b = (prtx1_1.b + 1)) OR (c = 99))
+               Recheck Cond: ((c = 99) OR (b = (prtx1_1.b + 1)))
                Filter: (a = prtx1_1.a)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on prtx2_1_b_idx
-                           Index Cond: (b = (prtx1_1.b + 1))
                      ->  Bitmap Index Scan on prtx2_1_c_idx
                            Index Cond: (c = 99)
+                     ->  Bitmap Index Scan on prtx2_1_b_idx
+                           Index Cond: (b = (prtx1_1.b + 1))
    ->  Nested Loop Anti Join
          ->  Seq Scan on prtx1_2
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_2
-               Recheck Cond: ((b = (prtx1_2.b + 1)) OR (c = 99))
+               Recheck Cond: ((c = 99) OR (b = (prtx1_2.b + 1)))
                Filter: (a = prtx1_2.a)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on prtx2_2_b_idx
-                           Index Cond: (b = (prtx1_2.b + 1))
                      ->  Bitmap Index Scan on prtx2_2_c_idx
                            Index Cond: (c = 99)
+                     ->  Bitmap Index Scan on prtx2_2_b_idx
+                           Index Cond: (b = (prtx1_2.b + 1))
 (23 rows)
 
 select * from prtx1
-- 
2.39.5 (Apple Git-154)

#300Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#299)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 12.01.2025 21:39, Alexander Korotkov wrote:

On Fri, Nov 29, 2024 at 9:54 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

On Fri, Nov 29, 2024 at 7:51 AM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 29.11.2024 03:04, Alexander Korotkov wrote:

On Thu, Nov 28, 2024 at 9:33 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 28.11.2024 22:28, Ranier Vilela wrote:

Em qui., 28 de nov. de 2024 às 16:03, Alena Rybakina <a.rybakina@postgrespro.ru> escreveu:

Hi! Thank you for the case.

On 28.11.2024 21:00, Alexander Lakhin wrote:

Hello Alexander,

21.11.2024 09:34, Alexander Korotkov wrote:

I'm going to push this if no objections.

Please look at the following query, which triggers an error after
ae4569161:
SET random_page_cost = 1;
CREATE TABLE tbl(u UUID);
CREATE INDEX idx ON tbl USING HASH (u);
SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR
u = '11111111111111111111111111111111';

ERROR: XX000: ScalarArrayOpExpr index qual found where not allowed
LOCATION: ExecIndexBuildScanKeys, nodeIndexscan.c:1625

I found out what the problem is index scan method was not generated. We
need to check this during OR clauses for SAOP transformation.

There is a patch to fix this problem.

Hi.
Thanks for the quick fix.

But I wonder if it is not possible to avoid all if the index is useless?
Maybe moving your fix to the beginning of the function?

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index d827fc9f4d..5ea0b27d01 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3248,6 +3248,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
Assert(IsA(orclause, BoolExpr));
Assert(orclause->boolop == OR_EXPR);
+ /* Ignore index if it doesn't support index scans */
+ if(!index->amsearcharray)
+ return NULL;
+

Agree. I have updated the patch

/*
* Try to convert a list of OR-clauses to a single SAOP expression. Each
* OR entry must be in the form: (indexkey operator constant) or (constant

The test bug:
EXPLAIN SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR u = '11111111111111111111111111111111';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=12.46..12.47 rows=1 width=8)
-> Bitmap Heap Scan on tbl (cost=2.14..12.41 rows=18 width=0)
Recheck Cond: ((u = '00000000-0000-0000-0000-000000000000'::uuid) OR (u = '11111111-1111-1111-1111-111111111111'::uuid))
-> BitmapOr (cost=2.14..2.14 rows=18 width=0)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
Index Cond: (u = '00000000-0000-0000-0000-000000000000'::uuid)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
Index Cond: (u = '11111111-1111-1111-1111-111111111111'::uuid)
(8 rows)

I slightly revised the fix and added similar check to
group_similar_or_args(). Could you, please, review that before
commit?

I agree with changes. Thank you!

Andrei, Alena, thank you for the feedback. Pushed!

I think we should give some more attention to the patch enabling OR to
SAOP transformation for joins (first time posted in [1]). I think we
tried to only work with Const and Param, because we were previously
working during parse stage. So, at that stage if we have the clause
like "a.x = 1 OR a.x = b.x OR b.x = 2", then we don't know if we
should transform it into "a.x = ANY(1, b.x) OR b.x = 2" or into "a.x
=1 OR b.x = ANY(a.x, 2)". But if we do the transformation during the
index matching, we would actually be able to try the both and select
the best.

The revised patch is attached. Most notably it revises
group_similar_or_args() to have the same notion of const-ness as
others. In that function we split potential index key and constant
early to save time on enumerating all possible index keys. But it
appears to be possible to split by relids bitmapsets: index key should
use our relid, while const shouldn't. Other that that, comments,
commit message and naming are revised.

Links.
1. /messages/by-id/CAPpHfdu9QJ=Gbua3CUUH2KKG_8urakJTen4JD47PGh9wWP=QxQ@mail.gmail.com

I like your idea. I looked at your patch and haven't noticed any bugs
yet, but my review is not finished.

I think we're missing tests here - I only noticed one difference in the
regression test related to your specific improvement.

I thought it would be possible to look at cases where q1 and q2 are not
equal to an integer constant table,
but have a more complex structure. For example, set the conditions "q1
as select (1=1)::integer" and "q2 as select (1=0)::integer".

--
Regards,
Alena Rybakina
Postgres Professional

#301Yura Sokolov
y.sokolov@postgrespro.ru
In reply to: Alexander Korotkov (#299)
Re: POC, WIP: OR-clause support for indexes

<div>Вс, 12 янв. 2025 г. в 21:39, Alexander Korotkov &lt;aekorotkov@gmail.com&gt;:<br></div><div><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">On Fri, Nov 29, 2024 at 9:54 AM Alexander Korotkov &lt;aekorotkov@gmail.com&gt; wrote:
<br>&gt; On Fri, Nov 29, 2024 at 7:51 AM Alena Rybakina
<br>&gt; &lt;a.rybakina@postgrespro.ru&gt; wrote:
<br>&gt; &gt;
<br>&gt; &gt; On 29.11.2024 03:04, Alexander Korotkov wrote:
<br>&gt; &gt; &gt; On Thu, Nov 28, 2024 at 9:33 PM Alena Rybakina
<br>&gt; &gt; &gt; &lt;a.rybakina@postgrespro.ru&gt; wrote:
<br>&gt; &gt; &gt;&gt; On 28.11.2024 22:28, Ranier Vilela wrote:
<br>&gt; &gt; &gt;&gt;
<br>&gt; &gt; &gt;&gt; Em qui., 28 de nov. de 2024 às 16:03, Alena Rybakina &lt;a.rybakina@postgrespro.ru&gt; escreveu:
<br>&gt; &gt; &gt;&gt;&gt; Hi! Thank you for the case.
<br>&gt; &gt; &gt;&gt;&gt;
<br>&gt; &gt; &gt;&gt;&gt; On 28.11.2024 21:00, Alexander Lakhin wrote:
<br>&gt; &gt; &gt;&gt;&gt;&gt; Hello Alexander,
<br>&gt; &gt; &gt;&gt;&gt;&gt;
<br>&gt; &gt; &gt;&gt;&gt;&gt; 21.11.2024 09:34, Alexander Korotkov wrote:
<br>&gt; &gt; &gt;&gt;&gt;&gt;&gt; I'm going to push this if no objections.
<br>&gt; &gt; &gt;&gt;&gt;&gt; Please look at the following query, which triggers an error after
<br>&gt; &gt; &gt;&gt;&gt;&gt; ae4569161:
<br>&gt; &gt; &gt;&gt;&gt;&gt; SET random_page_cost = 1;
<br>&gt; &gt; &gt;&gt;&gt;&gt; CREATE TABLE tbl(u UUID);
<br>&gt; &gt; &gt;&gt;&gt;&gt; CREATE INDEX idx ON tbl USING HASH (u);
<br>&gt; &gt; &gt;&gt;&gt;&gt; SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR
<br>&gt; &gt; &gt;&gt;&gt;&gt; u = '11111111111111111111111111111111';
<br>&gt; &gt; &gt;&gt;&gt;&gt;
<br>&gt; &gt; &gt;&gt;&gt;&gt; ERROR: XX000: ScalarArrayOpExpr index qual found where not allowed
<br>&gt; &gt; &gt;&gt;&gt;&gt; LOCATION: ExecIndexBuildScanKeys, nodeIndexscan.c:1625
<br>&gt; &gt; &gt;&gt;&gt;&gt;
<br>&gt; &gt; &gt;&gt;&gt;&gt;
<br>&gt; &gt; &gt;&gt;&gt; I found out what the problem is index scan method was not generated. We
<br>&gt; &gt; &gt;&gt;&gt; need to check this during OR clauses for SAOP transformation.
<br>&gt; &gt; &gt;&gt;&gt;
<br>&gt; &gt; &gt;&gt;&gt; There is a patch to fix this problem.
<br>&gt; &gt; &gt;&gt; Hi.
<br>&gt; &gt; &gt;&gt; Thanks for the quick fix.
<br>&gt; &gt; &gt;&gt;
<br>&gt; &gt; &gt;&gt; But I wonder if it is not possible to avoid all if the index is useless?
<br>&gt; &gt; &gt;&gt; Maybe moving your fix to the beginning of the function?
<br>&gt; &gt; &gt;&gt;
<br>&gt; &gt; &gt;&gt; diff --git a/src/backend/optimizer/path/indxpath.<wbr>c b/src/backend/optimizer/path/indxpath.c
<br>&gt; &gt; &gt;&gt; index d827fc9f4d..5ea0b27d01 100644
<br>&gt; &gt; &gt;&gt; --- a/src/backend/optimizer/path/indxpath.c
<br>&gt; &gt; &gt;&gt; +++ b/src/backend/optimizer/path/indxpath.c
<br>&gt; &gt; &gt;&gt; @@ -3248,6 +3248,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
<br>&gt; &gt; &gt;&gt; Assert(IsA(orclause, BoolExpr));
<br>&gt; &gt; &gt;&gt; Assert(orclause-&gt;boolop == OR_EXPR);
<br>&gt; &gt; &gt;&gt;
<br>&gt; &gt; &gt;&gt; + /* Ignore index if it doesn't support index scans */
<br>&gt; &gt; &gt;&gt; + if(!index-&gt;amsearcharray)
<br>&gt; &gt; &gt;&gt; + return NULL;
<br>&gt; &gt; &gt;&gt; +
<br>&gt; &gt; &gt;&gt;
<br>&gt; &gt; &gt;&gt; Agree. I have updated the patch
<br>&gt; &gt; &gt;&gt;
<br>&gt; &gt; &gt;&gt; /*
<br>&gt; &gt; &gt;&gt; * Try to convert a list of OR-clauses to a single SAOP expression. Each
<br>&gt; &gt; &gt;&gt; * OR entry must be in the form: (indexkey operator constant) or (constant
<br>&gt; &gt; &gt;&gt;
<br>&gt; &gt; &gt;&gt; The test bug:
<br>&gt; &gt; &gt;&gt; EXPLAIN SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000'<wbr> OR u = '11111111111111111111111111111111';
<br>&gt; &gt; &gt;&gt; QUERY PLAN
<br>&gt; &gt; &gt;&gt; --------------------------------<wbr>--------------------------------<wbr>--------------------------------<wbr>----------------------------------
<br>&gt; &gt; &gt;&gt; Aggregate (cost=12.46..12.47 rows=1 width=8)
<br>&gt; &gt; &gt;&gt; -&gt; Bitmap Heap Scan on tbl (cost=2.14..12.41 rows=18 width=0)
<br>&gt; &gt; &gt;&gt; Recheck Cond: ((u = '00000000-0000-0000-0000-000000000000'<wbr>::uuid) OR (u = '11111111-1111-1111-1111-111111111111'<wbr>::uuid))
<br>&gt; &gt; &gt;&gt; -&gt; BitmapOr (cost=2.14..2.14 rows=18 width=0)
<br>&gt; &gt; &gt;&gt; -&gt; Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
<br>&gt; &gt; &gt;&gt; Index Cond: (u = '00000000-0000-0000-0000-000000000000'<wbr>::uuid)
<br>&gt; &gt; &gt;&gt; -&gt; Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
<br>&gt; &gt; &gt;&gt; Index Cond: (u = '11111111-1111-1111-1111-111111111111'<wbr>::uuid)
<br>&gt; &gt; &gt;&gt; (8 rows)
<br>&gt; &gt; &gt; I slightly revised the fix and added similar check to
<br>&gt; &gt; &gt; group_similar_or_args(). Could you, please, review that before
<br>&gt; &gt; &gt; commit?
<br>&gt; &gt; &gt;
<br>&gt; &gt; I agree with changes. Thank you!
<br>&gt;
<br>&gt; Andrei, Alena, thank you for the feedback. Pushed!
<br>
<br>I think we should give some more attention to the patch enabling OR to
<br>SAOP transformation for joins (first time posted in [1]). I think we
<br>tried to only work with Const and Param, because we were previously
<br>working during parse stage. So, at that stage if we have the clause
<br>like "a.x = 1 OR a.x = b.x OR b.x = 2", then we don't know if we
<br>should transform it into "a.x = ANY(1, b.x) OR b.x = 2" or into "a.x
<br>=1 OR b.x = ANY(a.x, 2)". But if we do the transformation during the
<br>index matching, we would actually be able to try the both and select
<br>the best.
</blockquote><div dir="auto"><br></div><div dir="auto">But why not “a.x = ANY(1, b.x) OR b.x = ANY(a.x, 2)” ? Looks strange, but correct ))</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;" dir="auto"><br>The revised patch is attached. Most notably it revises
<br>group_similar_or_args() to have the same notion of const-ness as
<br>others. In that function we split potential index key and constant
<br>early to save time on enumerating all possible index keys. But it
<br>appears to be possible to split by relids bitmapsets: index key should
<br>use our relid, while const shouldn't. Other that that, comments,
<br>commit message and naming are revised.
<br>
<br>Links.
<br>1. https://www.postgresql.org/message-&lt;wbr&gt;id/CAPpHfdu9QJ%3DGbua3CUUH2KKG_8urakJTen4JD47PGh9wWP%3DQxQ%40mail.&lt;wbr&gt;gmail.com
<br>
<br>------
<br>Regards,
<br>Alexander Korotkov
<br>Supabase
<br></blockquote></div></div>

#302Alexander Korotkov
aekorotkov@gmail.com
In reply to: Yura Sokolov (#301)
Re: POC, WIP: OR-clause support for indexes

On Mon, Jan 13, 2025 at 2:47 AM Yura Sokolov <y.sokolov@postgrespro.ru> wrote:

Вс, 12 янв. 2025 г. в 21:39, Alexander Korotkov <aekorotkov@gmail.com>:

On Fri, Nov 29, 2024 at 9:54 AM Alexander Korotkov <aekorotkov@gmail.com> wrote:

On Fri, Nov 29, 2024 at 7:51 AM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 29.11.2024 03:04, Alexander Korotkov wrote:

On Thu, Nov 28, 2024 at 9:33 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

On 28.11.2024 22:28, Ranier Vilela wrote:

Em qui., 28 de nov. de 2024 às 16:03, Alena Rybakina <a.rybakina@postgrespro.ru> escreveu:

Hi! Thank you for the case.

On 28.11.2024 21:00, Alexander Lakhin wrote:

Hello Alexander,

21.11.2024 09:34, Alexander Korotkov wrote:

I'm going to push this if no objections.

Please look at the following query, which triggers an error after
ae4569161:
SET random_page_cost = 1;
CREATE TABLE tbl(u UUID);
CREATE INDEX idx ON tbl USING HASH (u);
SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR
u = '11111111111111111111111111111111';

ERROR: XX000: ScalarArrayOpExpr index qual found where not allowed
LOCATION: ExecIndexBuildScanKeys, nodeIndexscan.c:1625

I found out what the problem is index scan method was not generated. We
need to check this during OR clauses for SAOP transformation.

There is a patch to fix this problem.

Hi.
Thanks for the quick fix.

But I wonder if it is not possible to avoid all if the index is useless?
Maybe moving your fix to the beginning of the function?

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index d827fc9f4d..5ea0b27d01 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3248,6 +3248,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
Assert(IsA(orclause, BoolExpr));
Assert(orclause->boolop == OR_EXPR);
+ /* Ignore index if it doesn't support index scans */
+ if(!index->amsearcharray)
+ return NULL;
+

Agree. I have updated the patch

/*
* Try to convert a list of OR-clauses to a single SAOP expression. Each
* OR entry must be in the form: (indexkey operator constant) or (constant

The test bug:
EXPLAIN SELECT COUNT(*) FROM tbl WHERE u = '00000000000000000000000000000000' OR u = '11111111111111111111111111111111';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=12.46..12.47 rows=1 width=8)
-> Bitmap Heap Scan on tbl (cost=2.14..12.41 rows=18 width=0)
Recheck Cond: ((u = '00000000-0000-0000-0000-000000000000'::uuid) OR (u = '11111111-1111-1111-1111-111111111111'::uuid))
-> BitmapOr (cost=2.14..2.14 rows=18 width=0)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
Index Cond: (u = '00000000-0000-0000-0000-000000000000'::uuid)
-> Bitmap Index Scan on idx (cost=0.00..1.07 rows=9 width=0)
Index Cond: (u = '11111111-1111-1111-1111-111111111111'::uuid)
(8 rows)

I slightly revised the fix and added similar check to
group_similar_or_args(). Could you, please, review that before
commit?

I agree with changes. Thank you!

Andrei, Alena, thank you for the feedback. Pushed!

I think we should give some more attention to the patch enabling OR to
SAOP transformation for joins (first time posted in [1]). I think we
tried to only work with Const and Param, because we were previously
working during parse stage. So, at that stage if we have the clause
like "a.x = 1 OR a.x = b.x OR b.x = 2", then we don't know if we
should transform it into "a.x = ANY(1, b.x) OR b.x = 2" or into "a.x
=1 OR b.x = ANY(a.x, 2)". But if we do the transformation during the
index matching, we would actually be able to try the both and select
the best.

But why not “a.x = ANY(1, b.x) OR b.x = ANY(a.x, 2)” ? Looks strange, but correct ))

That could probably work for a parse stage, but as you can check that
approach has a lot of other problems. As we do during index matching,
that doesn't matter. I just wanted to state that nothing in the
current approach prevent us from working the same way for joins.

------
Regards,
Alexander Korotkov
Supabase

#303Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#299)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On 1/13/25 01:39, Alexander Korotkov wrote:

The revised patch is attached. Most notably it revises
group_similar_or_args() to have the same notion of const-ness as
others. In that function we split potential index key and constant
early to save time on enumerating all possible index keys. But it
appears to be possible to split by relids bitmapsets: index key should
use our relid, while const shouldn't. Other that that, comments,
commit message and naming are revised.

Hmm, I would say we should carefully review this code.
Curiously, this patch has activated the dormant problem of duplicated
clauses in joinorclauses. Look:

EXPLAIN (COSTS OFF)
SELECT * FROM bitmap_split_or t1, bitmap_split_or t2
WHERE t1.a=t2.b OR t1.a=1;

Nested Loop
-> Seq Scan on bitmap_split_or t2
-> Bitmap Heap Scan on bitmap_split_or t1
Recheck Cond: (((a = t2.b) OR (a = 1)) AND
((a = t2.b) OR (a = 1)))
-> Bitmap Index Scan on t_a_b_idx
Index Cond: ((a = ANY (ARRAY[t2.b, 1])) AND
(a = ANY (ARRAY[t2.b, 1])))

It can be resolved with a single-line change (see attached). But I need
some time to ponder over the changing behaviour when a clause may match
an index and be in joinorclauses.

--
regards, Andrei Lepikhov

Attachments:

joinorclauses-fix.difftext/x-patch; charset=UTF-8; name=joinorclauses-fix.diffDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c03547a997..2a86298d9d 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -2440,7 +2440,7 @@ match_join_clauses_to_index(PlannerInfo *root,
 
 		/* Potentially usable, so see if it matches the index or is an OR */
 		if (restriction_is_or_clause(rinfo))
-			*joinorclauses = lappend(*joinorclauses, rinfo);
+			*joinorclauses = list_append_unique_ptr(*joinorclauses, rinfo);
 
 		match_clause_to_index(root, rinfo, index, clauseset);
 	}
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 8011c141bf..47bdee1d41 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -3255,6 +3255,16 @@ CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
 CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
 CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
 ANALYZE bitmap_split_or;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.b OR t1.a=1;
+                       QUERY PLAN                       
+--------------------------------------------------------
+ Nested Loop
+   ->  Seq Scan on bitmap_split_or t2
+   ->  Index Scan using t_a_b_idx on bitmap_split_or t1
+         Index Cond: (a = ANY (ARRAY[t2.b, 1]))
+(4 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
                             QUERY PLAN                            
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 068c66b95a..bc12d2f098 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -1367,6 +1367,8 @@ CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
 CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
 ANALYZE bitmap_split_or;
 EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.b OR t1.a=1;
+EXPLAIN (COSTS OFF)
 SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
 DROP TABLE bitmap_split_or;
 
#304Andrei Lepikhov
lepihov@gmail.com
In reply to: Andrei Lepikhov (#303)
Re: POC, WIP: OR-clause support for indexes

On 1/13/25 10:39, Andrei Lepikhov wrote:

On 1/13/25 01:39, Alexander Korotkov wrote:
It can be resolved with a single-line change (see attached). But I need
some time to ponder over the changing behaviour when a clause may match
an index and be in joinorclauses.

In addition, let me raise a couple of issues:
1. As Robert has said before, it may interfere with some short-circuit
optimisations like below:

EXPLAIN (COSTS OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 AND (t1.b=2 OR t1.b = (
SELECT sum(c1.reltuples) FROM pg_class c1, pg_class c2
WHERE c1.relpages=c2.relpages AND c1.relpages = t1.a));

Here, a user may avoid evaluating the subplan at all if t1.b=2 all the
time when t1.a=2. OR->ANY may accidentally shift this behaviour.

2. The query:

EXPLAIN (ANALYZE, COSTS OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 OR t1.a = (
SELECT sum(c1.reltuples) FROM pg_class c1, pg_class c2
WHERE c1.relpages=c2.relpages AND c1.relpages = t1.a)::integer;

causes SEGFAULT during index keys evaluation. I haven't dived into it
yet, but it seems quite a typical misstep and is not difficult to fix.

--
regards, Andrei Lepikhov

#305Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#304)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Wed, Jan 15, 2025 at 10:24 AM Andrei Lepikhov <lepihov@gmail.com> wrote:

On 1/13/25 10:39, Andrei Lepikhov wrote:

On 1/13/25 01:39, Alexander Korotkov wrote:
It can be resolved with a single-line change (see attached). But I need
some time to ponder over the changing behaviour when a clause may match
an index and be in joinorclauses.

In addition, let me raise a couple of issues:
1. As Robert has said before, it may interfere with some short-circuit
optimisations like below:

EXPLAIN (COSTS OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 AND (t1.b=2 OR t1.b = (
SELECT sum(c1.reltuples) FROM pg_class c1, pg_class c2
WHERE c1.relpages=c2.relpages AND c1.relpages = t1.a));

Here, a user may avoid evaluating the subplan at all if t1.b=2 all the
time when t1.a=2. OR->ANY may accidentally shift this behaviour.

2. The query:

EXPLAIN (ANALYZE, COSTS OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 OR t1.a = (
SELECT sum(c1.reltuples) FROM pg_class c1, pg_class c2
WHERE c1.relpages=c2.relpages AND c1.relpages = t1.a)::integer;

causes SEGFAULT during index keys evaluation. I haven't dived into it
yet, but it seems quite a typical misstep and is not difficult to fix.

Segfault appears to be caused by a typo. Patch used parent rinfo
instead of child rinfo. Fixed in the attached patch.

It appears that your first query also changed a plan after fixing
this. Could you, please, provide another example of a regression for
short-circuit optimization, which is related to this patch?

Also, I've integrated your fix from [1].

Links.
1. /messages/by-id/41ba3d47-2a48-476c-88d4-6ebd889a7af2@gmail.com

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v46-0001-Allow-usage-of-match_orclause_to_indexcol-for-jo.patchapplication/octet-stream; name=v46-0001-Allow-usage-of-match_orclause_to_indexcol-for-jo.patchDownload
From 2338465f4e88fbeb0c803bbe5d9318e85d26e31e Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Wed, 9 Oct 2024 18:44:25 +0300
Subject: [PATCH v46] Allow usage of match_orclause_to_indexcol() for joins

This commit allows transformation of OR-clauses into SAOP's for index scans
within nested loop joins.  That required the following changes.

 1. Make match_orclause_to_indexcol() and group_similar_or_args() understand
    const-ness in the same way as match_opclause_to_indexcol().  This
    generally makes our approach more uniform.
 2. Make match_join_clauses_to_index() pass OR-clauses to
    match_clause_to_index().
---
 src/backend/optimizer/path/indxpath.c        | 63 +++++++++++---------
 src/test/regress/expected/create_index.out   | 25 ++++++++
 src/test/regress/expected/join.out           |  9 +--
 src/test/regress/expected/partition_join.out | 12 ++--
 src/test/regress/sql/create_index.sql        |  8 +++
 5 files changed, 77 insertions(+), 40 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index fa3edf60f3c..f6a0618b0a5 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1255,6 +1255,7 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 	ListCell   *lc2;
 	List	   *orargs;
 	List	   *result = NIL;
+	Index		relid = rel->relid;
 
 	Assert(IsA(rinfo->orclause, BoolExpr));
 	orargs = ((BoolExpr *) rinfo->orclause)->args;
@@ -1319,10 +1320,13 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 		/*
 		 * Check for clauses of the form: (indexkey operator constant) or
 		 * (constant operator indexkey).  But we don't know a particular index
-		 * yet.  First check for a constant, which must be Const or Param.
-		 * That's cheaper than search for an index key among all indexes.
+		 * yet.  Therefore, we try to distinguish the potential index key and
+		 * constant first, then search for a matching index key among all
+		 * indexes.
 		 */
-		if (IsA(leftop, Const) || IsA(leftop, Param))
+		if (bms_is_member(relid, argrinfo->right_relids) &&
+			!bms_is_member(relid, argrinfo->left_relids) &&
+			!contain_volatile_functions(leftop))
 		{
 			opno = get_commutator(opno);
 
@@ -1333,7 +1337,9 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 			}
 			nonConstExpr = rightop;
 		}
-		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		else if (bms_is_member(relid, argrinfo->left_relids) &&
+				 !bms_is_member(relid, argrinfo->right_relids) &&
+				 !contain_volatile_functions(rightop))
 		{
 			nonConstExpr = leftop;
 		}
@@ -2434,9 +2440,9 @@ match_join_clauses_to_index(PlannerInfo *root,
 
 		/* Potentially usable, so see if it matches the index or is an OR */
 		if (restriction_is_or_clause(rinfo))
-			*joinorclauses = lappend(*joinorclauses, rinfo);
-		else
-			match_clause_to_index(root, rinfo, index, clauseset);
+			*joinorclauses = list_append_unique_ptr(*joinorclauses, rinfo);
+
+		match_clause_to_index(root, rinfo, index, clauseset);
 	}
 }
 
@@ -2585,10 +2591,7 @@ match_clause_to_index(PlannerInfo *root,
  *	  (3)  must match the collation of the index, if collation is relevant.
  *
  *	  Our definition of "const" is exceedingly liberal: we allow anything that
- *	  doesn't involve a volatile function or a Var of the index's relation
- *	  except for a boolean OR expression input: due to a trade-off between the
- *	  expected execution speedup and planning complexity, we limit or->saop
- *	  transformation by obvious cases when an index scan can get a profit.
+ *	  doesn't involve a volatile function or a Var of the index's relation.
  *	  In particular, Vars belonging to other relations of the query are
  *	  accepted here, since a clause of that form can be used in a
  *	  parameterized indexscan.  It's the responsibility of higher code levels
@@ -3246,7 +3249,8 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Oid			arraytype = InvalidOid;
 	Oid			inputcollid = InvalidOid;
 	bool		firstTime = true;
-	bool		haveParam = false;
+	bool		haveNonConst = false;
+	Index		indexRelid = index->rel->relid;
 
 	Assert(IsA(orclause, BoolExpr));
 	Assert(orclause->boolop == OR_EXPR);
@@ -3258,10 +3262,9 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	/*
 	 * Try to convert a list of OR-clauses to a single SAOP expression. Each
 	 * OR entry must be in the form: (indexkey operator constant) or (constant
-	 * operator indexkey).  Operators of all the entries must match.  Constant
-	 * might be either Const or Param.  To be effective, give up on the first
-	 * non-matching entry.  Exit is implemented as a break from the loop,
-	 * which is catched afterwards.
+	 * operator indexkey).  Operators of all the entries must match.  To be
+	 * effective, give up on the first non-matching entry.  Exit is
+	 * implemented as a break from the loop, which is catched afterwards.
 	 */
 	foreach(lc, orclause->args)
 	{
@@ -3312,17 +3315,21 @@ match_orclause_to_indexcol(PlannerInfo *root,
 
 		/*
 		 * Check for clauses of the form: (indexkey operator constant) or
-		 * (constant operator indexkey).  Determine indexkey side first, check
-		 * the constant later.
+		 * (constant operator indexkey).  See match_clause_to_indexcol's notes
+		 * about const-ness.
 		 */
 		leftop = (Node *) linitial(subClause->args);
 		rightop = (Node *) lsecond(subClause->args);
-		if (match_index_to_operand(leftop, indexcol, index))
+		if (match_index_to_operand(leftop, indexcol, index) &&
+			!bms_is_member(indexRelid, subRinfo->right_relids) &&
+			!contain_volatile_functions(rightop))
 		{
 			indexExpr = leftop;
 			constExpr = rightop;
 		}
-		else if (match_index_to_operand(rightop, indexcol, index))
+		else if (match_index_to_operand(rightop, indexcol, index) &&
+			!bms_is_member(indexRelid, subRinfo->left_relids) &&
+			!contain_volatile_functions(leftop))
 		{
 			opno = get_commutator(opno);
 			if (!OidIsValid(opno))
@@ -3349,10 +3356,6 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		if (IsA(indexExpr, RelabelType))
 			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
 
-		/* We allow constant to be Const or Param */
-		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
-			break;
-
 		/* Forbid transformation for composite types, records. */
 		if (type_is_rowtype(exprType(constExpr)) ||
 			type_is_rowtype(exprType(indexExpr)))
@@ -3389,8 +3392,12 @@ match_orclause_to_indexcol(PlannerInfo *root,
 				break;
 		}
 
-		if (IsA(constExpr, Param))
-			haveParam = true;
+		/*
+		 * Check if our list of constants in match_clause_to_indexcol's
+		 * understanding of const-ness have something other than Const.
+		 */
+		if (!IsA(constExpr, Const))
+			haveNonConst = true;
 		consts = lappend(consts, constExpr);
 	}
 
@@ -3407,10 +3414,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
 
 	/*
 	 * Assemble an array from the list of constants.  It seems more profitable
-	 * to build a const array.  But in the presence of parameters, we don't
+	 * to build a const array.  But in the presence of other nodes, we don't
 	 * have a specific value here and must employ an ArrayExpr instead.
 	 */
-	if (haveParam)
+	if (haveNonConst)
 	{
 		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 8011c141bf8..36343a3781d 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2006,6 +2006,21 @@ SELECT * FROM tenk1
    Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
 (2 rows)
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1 t1
+  WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous);
+                           QUERY PLAN                           
+----------------------------------------------------------------
+ Seq Scan on tenk1 t1
+   Filter: ((thousand = 42) OR (thousand = (SubPlan 1)))
+   SubPlan 1
+     ->  Index Only Scan using tenk1_thous_tenthous on tenk1 t2
+           Index Cond: (thousand = t1.tenthous)
+(5 rows)
+
+SELECT * FROM tenk1 t1
+  WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous);
+ERROR:  more than one row returned by a subquery used as an expression
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -3255,6 +3270,16 @@ CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
 CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
 CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
 ANALYZE bitmap_split_or;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.b OR t1.a=1;
+                       QUERY PLAN                       
+--------------------------------------------------------
+ Nested Loop
+   ->  Seq Scan on bitmap_split_or t2
+   ->  Index Scan using t_a_b_idx on bitmap_split_or t1
+         Index Cond: (a = ANY (ARRAY[t2.b, 1]))
+(4 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
                             QUERY PLAN                            
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 079fcf46f0d..634eff4d751 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -3849,14 +3849,11 @@ where q1 = thousand or q2 = thousand;
                ->  Seq Scan on q2
          ->  Bitmap Heap Scan on tenk1
                Recheck Cond: ((q1.q1 = thousand) OR (q2.q2 = thousand))
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = q1.q1)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = q2.q2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY (ARRAY[q1.q1, q2.q2]))
    ->  Hash
          ->  Seq Scan on int4_tbl
-(15 rows)
+(12 rows)
 
 explain (costs off)
 select * from
diff --git a/src/test/regress/expected/partition_join.out b/src/test/regress/expected/partition_join.out
index 108f9ecb445..af468682a2d 100644
--- a/src/test/regress/expected/partition_join.out
+++ b/src/test/regress/expected/partition_join.out
@@ -2533,24 +2533,24 @@ where not exists (select 1 from prtx2
          ->  Seq Scan on prtx1_1
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_1
-               Recheck Cond: ((b = (prtx1_1.b + 1)) OR (c = 99))
+               Recheck Cond: ((c = 99) OR (b = (prtx1_1.b + 1)))
                Filter: (a = prtx1_1.a)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on prtx2_1_b_idx
-                           Index Cond: (b = (prtx1_1.b + 1))
                      ->  Bitmap Index Scan on prtx2_1_c_idx
                            Index Cond: (c = 99)
+                     ->  Bitmap Index Scan on prtx2_1_b_idx
+                           Index Cond: (b = (prtx1_1.b + 1))
    ->  Nested Loop Anti Join
          ->  Seq Scan on prtx1_2
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_2
-               Recheck Cond: ((b = (prtx1_2.b + 1)) OR (c = 99))
+               Recheck Cond: ((c = 99) OR (b = (prtx1_2.b + 1)))
                Filter: (a = prtx1_2.a)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on prtx2_2_b_idx
-                           Index Cond: (b = (prtx1_2.b + 1))
                      ->  Bitmap Index Scan on prtx2_2_c_idx
                            Index Cond: (c = 99)
+                     ->  Bitmap Index Scan on prtx2_2_b_idx
+                           Index Cond: (b = (prtx1_2.b + 1))
 (23 rows)
 
 select * from prtx1
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 068c66b95a5..aded693bf7b 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -781,6 +781,12 @@ EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
 
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1 t1
+  WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous);
+SELECT * FROM tenk1 t1
+  WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1367,6 +1373,8 @@ CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
 CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
 ANALYZE bitmap_split_or;
 EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.b OR t1.a=1;
+EXPLAIN (COSTS OFF)
 SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
 DROP TABLE bitmap_split_or;
 
-- 
2.39.5 (Apple Git-154)

#306Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#305)
Re: POC, WIP: OR-clause support for indexes

On 1/25/25 12:04, Alexander Korotkov wrote:

On Wed, Jan 15, 2025 at 10:24 AM Andrei Lepikhov <lepihov@gmail.com> wrote:

causes SEGFAULT during index keys evaluation. I haven't dived into it
yet, but it seems quite a typical misstep and is not difficult to fix.

Segfault appears to be caused by a typo. Patch used parent rinfo
instead of child rinfo. Fixed in the attached patch.

Great!

It appears that your first query also changed a plan after fixing
this. Could you, please, provide another example of a regression for
short-circuit optimization, which is related to this patch?

Yes, it may be caused by the current lazy InitPlan evaluation strategy,
which would only happen if it was really needed.

Examples:
---------

EXPLAIN (ANALYZE, COSTS OFF, BUFFERS OFF, TIMING OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 AND (t1.b=2 OR t1.b = (
SELECT avg(x) FROM generate_series(1,1e6) AS x)::integer);

without optimisation:

Index Scan using t_a_b_idx on bitmap_split_or t1 (actual rows=1 loops=1)
Index Cond: (a = 2)
Filter: ((b = 2) OR (b = ((InitPlan 1).col1)::integer))
InitPlan 1
-> Aggregate (never executed)
-> Function Scan on generate_series x (never executed)
Planning Time: 0.564 ms
Execution Time: 0.182 ms

But having it as a part of an array, we forcedly evaluate it for (not
100% sure) more precise selectivity estimation:

Index Scan using t_a_b_idx on bitmap_split_or t1
(actual rows=1 loops=1)
Index Cond: ((a = 2) AND
(b = ANY (ARRAY[2, ((InitPlan 1).col1)::integer])))
InitPlan 1
-> Aggregate (actual rows=1 loops=1)
-> Function Scan on generate_series x
(actual rows=1000000 loops=1)
Planning Time: 0.927 ms
Execution Time: 489.933 ms

This also means that if, before the patch, we executed a query
successfully, after applying the patch, we sometimes may get the error:
'ERROR: more than one row returned by a subquery used as an expression'
because of early InitPlan evaluation. See the example below:

EXPLAIN (ANALYZE, COSTS OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 AND (t1.b=2 OR t1.b = (
SELECT random() FROM generate_series(1,1e6) AS x)::integer);

Index Scan using t_a_b_idx on bitmap_split_or t1
Index Cond: ((a = 2) AND (b = ANY (ARRAY[2, ((InitPlan
1).col1)::integer])))
InitPlan 1
-> Function Scan on generate_series x

I think optimisation should have never happened and this is another
issue, isn't it?

--
regards, Andrei Lepikhov

#307Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#306)
Re: POC, WIP: OR-clause support for indexes

Hi, Andrei!

On Mon, Jan 27, 2025 at 10:52 AM Andrei Lepikhov <lepihov@gmail.com> wrote:

On 1/25/25 12:04, Alexander Korotkov wrote:

On Wed, Jan 15, 2025 at 10:24 AM Andrei Lepikhov <lepihov@gmail.com>

wrote:

causes SEGFAULT during index keys evaluation. I haven't dived into it
yet, but it seems quite a typical misstep and is not difficult to fix.

Segfault appears to be caused by a typo. Patch used parent rinfo
instead of child rinfo. Fixed in the attached patch.

Great!

It appears that your first query also changed a plan after fixing
this. Could you, please, provide another example of a regression for
short-circuit optimization, which is related to this patch?

Yes, it may be caused by the current lazy InitPlan evaluation strategy,
which would only happen if it was really needed.

Examples:
---------

EXPLAIN (ANALYZE, COSTS OFF, BUFFERS OFF, TIMING OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 AND (t1.b=2 OR t1.b = (
SELECT avg(x) FROM generate_series(1,1e6) AS x)::integer);

without optimisation:

Index Scan using t_a_b_idx on bitmap_split_or t1 (actual rows=1 loops=1)
Index Cond: (a = 2)
Filter: ((b = 2) OR (b = ((InitPlan 1).col1)::integer))
InitPlan 1
-> Aggregate (never executed)
-> Function Scan on generate_series x (never executed)
Planning Time: 0.564 ms
Execution Time: 0.182 ms

But having it as a part of an array, we forcedly evaluate it for (not
100% sure) more precise selectivity estimation:

Index Scan using t_a_b_idx on bitmap_split_or t1
(actual rows=1 loops=1)
Index Cond: ((a = 2) AND
(b = ANY (ARRAY[2, ((InitPlan 1).col1)::integer])))
InitPlan 1
-> Aggregate (actual rows=1 loops=1)
-> Function Scan on generate_series x
(actual rows=1000000 loops=1)
Planning Time: 0.927 ms
Execution Time: 489.933 ms

This also means that if, before the patch, we executed a query
successfully, after applying the patch, we sometimes may get the error:
'ERROR: more than one row returned by a subquery used as an expression'
because of early InitPlan evaluation. See the example below:

EXPLAIN (ANALYZE, COSTS OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 AND (t1.b=2 OR t1.b = (
SELECT random() FROM generate_series(1,1e6) AS x)::integer);

Index Scan using t_a_b_idx on bitmap_split_or t1
Index Cond: ((a = 2) AND (b = ANY (ARRAY[2, ((InitPlan
1).col1)::integer])))
InitPlan 1
-> Function Scan on generate_series x

I think optimisation should have never happened and this is another
issue, isn't it?

Thank you for your examples. The reason why these example works only with
the patch is that you apply the cast outside of subquery. This is
because d4378c0005 requires OR argument to be either Cost or Param, but not
a cast over the param. Consider this example on master.

# EXPLAIN (ANALYZE, COSTS OFF, BUFFERS OFF, TIMING OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 AND (t1.b=2 OR t1.b = (
SELECT avg(x)::integer FROM generate_series(1,1e6) AS x));
QUERY PLAN
--------------------------------------------------------------------------------
Index Scan using t_a_b_idx on bitmap_split_or t1 (actual rows=1 loops=1)
Index Cond: ((a = 2) AND (b = ANY (ARRAY[2, (InitPlan 1).col1])))
InitPlan 1
-> Aggregate (actual rows=1 loops=1)
-> Function Scan on generate_series x (actual rows=1000000
loops=1)
Planning Time: 0.731 ms
Execution Time: 577.953 ms
(7 rows)

I expressed my point on this in [1]. We generally greedy about index quals
and there is no logic which prevent us from using a clause and index qual
because of its cost. And there are many cases when this causes regressions
before d4378c0005. One of examples from [1].

# explain analyze select * from t where i = 0 and j = (select slowfunc());
QUERY PLAN
---------------------------------------------------------------------------------------------------
Seq Scan on t (cost=25000.01..25195.01 rows=1 width=8) (actual
time=0.806..0.807 rows=0 loops=1)
Filter: ((i = 0) AND (j = (InitPlan 1).col1))
Rows Removed by Filter: 10000
InitPlan 1
-> Result (cost=0.00..25000.01 rows=1 width=4) (never executed)
Planning Time: 0.165 ms
Execution Time: 0.843 ms
(7 rows)

Links.
1.
/messages/by-id/CAPpHfdt8kowRDUkmOnO7_WJJQ1uk+O379JiZCk_9_Pt5AQ4+0w@mail.gmail.com

------
Regards,
Alexander Korotkov
Supabase

#308Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#307)
Re: POC, WIP: OR-clause support for indexes

On 1/27/25 16:50, Alexander Korotkov wrote:

I expressed my point on this in [1].  We generally greedy about index
quals and there is no logic which prevent us from using a clause and
index qual because of its cost.  And there are many cases when this
causes regressions before d4378c0005.  One of examples from [1].

Ok,
Generally, I don't concern myself with the evaluation of individual
subplans. As you mentioned, it should be a rare occurrence when this
becomes important. My main concern is the shift in frequency of
evaluations during execution for various reasons.
For example:

qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);

To fit an index, the order of elements in the target array of the
`ScalarArrayOpExpr` may change compared to the initial list of OR
expressions. If there are indexes that cover the same set of columns but
in reverse order, this could potentially alter the position of a
Subplan. However, I believe this is a rare case; it is supported by the
initial OR path and should be acceptable.

So, I do not have any further objections at this time.

--
regards, Andrei Lepikhov

#309Andrei Lepikhov
lepihov@gmail.com
In reply to: Andrei Lepikhov (#308)
Re: POC, WIP: OR-clause support for indexes

On 1/28/25 11:36, Andrei Lepikhov wrote:

On 1/27/25 16:50, Alexander Korotkov wrote:
qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);

To fit an index, the order of elements in the target array of the
`ScalarArrayOpExpr` may change compared to the initial list of OR
expressions. If there are indexes that cover the same set of columns but
in reverse order, this could potentially alter the position of a
Subplan. However, I believe this is a rare case; it is supported by the
initial OR path and should be acceptable.

I beg your pardon - I forgot that we've restricted the feature's scope
and can't combine OR clauses into ScalarArrayOpExpr if the args list
contains references to different columns.
So, my note can't be applied here.

--
regards, Andrei Lepikhov

#310Pavel Borisov
pashkin.elfe@gmail.com
In reply to: Andrei Lepikhov (#309)
Re: POC, WIP: OR-clause support for indexes

On Tue, 28 Jan 2025 at 12:42, Andrei Lepikhov <lepihov@gmail.com> wrote:

On 1/28/25 11:36, Andrei Lepikhov wrote:

On 1/27/25 16:50, Alexander Korotkov wrote:
qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);

To fit an index, the order of elements in the target array of the
`ScalarArrayOpExpr` may change compared to the initial list of OR
expressions. If there are indexes that cover the same set of columns but
in reverse order, this could potentially alter the position of a
Subplan. However, I believe this is a rare case; it is supported by the
initial OR path and should be acceptable.

I beg your pardon - I forgot that we've restricted the feature's scope
and can't combine OR clauses into ScalarArrayOpExpr if the args list
contains references to different columns.
So, my note can't be applied here.

--
regards, Andrei Lepikhov

I've looked at the patch v46-0001
Looks good to me.

There is a test that demonstrates the behavior change. Maybe some more
cases like are also worth adding to a test.

+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.c
OR (t1.a=t2.b OR t1.a=1);
+                       QUERY PLAN
+--------------------------------------------------------
+ Nested Loop
+   ->  Seq Scan on bitmap_split_or t2
+   ->  Index Scan using t_a_b_idx on bitmap_split_or t1
+         Index Cond: (a = ANY (ARRAY[t2.c, t2.b, 1]))
+(4 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.c=t2.b OR t1.a=1;
+                  QUERY PLAN
+----------------------------------------------
+ Nested Loop
+   Join Filter: ((t1.c = t2.b) OR (t1.a = 1))
+   ->  Seq Scan on bitmap_split_or t1
+   ->  Materialize
+         ->  Seq Scan on bitmap_split_or t2
+(5 rows)
+
+EXPLAIN (COSTS OFF)

Comment

* Also, add any potentially usable join OR clauses to *joinorclauses

may reflect the change in v46-0001 lappend -> list_append_unique_ptr
that differs in the processing of equal clauses in the list.

Semantics mentioned in the commit message:

2. Make match_join_clauses_to_index() pass OR-clauses to
match_clause_to_index().

could also be added as comments in the section just before
match_join_clauses_to_index()

Since d4378c0005e6 comment for match_clause_to_indexcol() I think
needs change. This could be as a separate commit, not regarding
current patch v46-0001.

* NOTE: returns NULL if clause is an OR or AND clause; it is the
* responsibility of higher-level routines to co

I think the patch can be pushed with possible additions to regression
test and comments.

Regards,
Pavel Borisov
Supabase

#311Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#305)
Re: POC, WIP: OR-clause support for indexes

Hi!

On 25.01.2025 08:04, Alexander Korotkov wrote:

On Wed, Jan 15, 2025 at 10:24 AM Andrei Lepikhov<lepihov@gmail.com> wrote:

On 1/13/25 10:39, Andrei Lepikhov wrote:

On 1/13/25 01:39, Alexander Korotkov wrote:
It can be resolved with a single-line change (see attached). But I need
some time to ponder over the changing behaviour when a clause may match
an index and be in joinorclauses.

In addition, let me raise a couple of issues:
1. As Robert has said before, it may interfere with some short-circuit
optimisations like below:

EXPLAIN (COSTS OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 AND (t1.b=2 OR t1.b = (
SELECT sum(c1.reltuples) FROM pg_class c1, pg_class c2
WHERE c1.relpages=c2.relpages AND c1.relpages = t1.a));

Here, a user may avoid evaluating the subplan at all if t1.b=2 all the
time when t1.a=2. OR->ANY may accidentally shift this behaviour.

2. The query:

EXPLAIN (ANALYZE, COSTS OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 OR t1.a = (
SELECT sum(c1.reltuples) FROM pg_class c1, pg_class c2
WHERE c1.relpages=c2.relpages AND c1.relpages = t1.a)::integer;

causes SEGFAULT during index keys evaluation. I haven't dived into it
yet, but it seems quite a typical misstep and is not difficult to fix.

Segfault appears to be caused by a typo. Patch used parent rinfo
instead of child rinfo. Fixed in the attached patch.

It appears that your first query also changed a plan after fixing
this. Could you, please, provide another example of a regression for
short-circuit optimization, which is related to this patch?

Also, I've integrated your fix from [1].

Links.
1./messages/by-id/41ba3d47-2a48-476c-88d4-6ebd889a7af2@gmail.com

I started reviewing at the patch and saw some output "ERROR" in the
output of the test and is it okay here?

SELECT * FROM tenk1 t1
WHERE t1.thousand= 42OR t1.thousand= (SELECT t2.tenthousFROM tenk1 t2
WHERE t2.thousand= t1.tenthous);
ERROR: more than one row returned by a subquery used as an expression

--
Regards,
Alena Rybakina
Postgres Professional

#312Alexander Korotkov
aekorotkov@gmail.com
In reply to: Pavel Borisov (#310)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Thu, Jan 30, 2025 at 3:23 PM Pavel Borisov <pashkin.elfe@gmail.com> wrote:

On Tue, 28 Jan 2025 at 12:42, Andrei Lepikhov <lepihov@gmail.com> wrote:

On 1/28/25 11:36, Andrei Lepikhov wrote:

On 1/27/25 16:50, Alexander Korotkov wrote:
qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);

To fit an index, the order of elements in the target array of the
`ScalarArrayOpExpr` may change compared to the initial list of OR
expressions. If there are indexes that cover the same set of columns but
in reverse order, this could potentially alter the position of a
Subplan. However, I believe this is a rare case; it is supported by the
initial OR path and should be acceptable.

I beg your pardon - I forgot that we've restricted the feature's scope
and can't combine OR clauses into ScalarArrayOpExpr if the args list
contains references to different columns.
So, my note can't be applied here.

--
regards, Andrei Lepikhov

I've looked at the patch v46-0001
Looks good to me.

There is a test that demonstrates the behavior change. Maybe some more
cases like are also worth adding to a test.

+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.c
OR (t1.a=t2.b OR t1.a=1);
+                       QUERY PLAN
+--------------------------------------------------------
+ Nested Loop
+   ->  Seq Scan on bitmap_split_or t2
+   ->  Index Scan using t_a_b_idx on bitmap_split_or t1
+         Index Cond: (a = ANY (ARRAY[t2.c, t2.b, 1]))
+(4 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.c=t2.b OR t1.a=1;
+                  QUERY PLAN
+----------------------------------------------
+ Nested Loop
+   Join Filter: ((t1.c = t2.b) OR (t1.a = 1))
+   ->  Seq Scan on bitmap_split_or t1
+   ->  Materialize
+         ->  Seq Scan on bitmap_split_or t2
+(5 rows)
+
+EXPLAIN (COSTS OFF)

Added more tests to join.sql

Comment

* Also, add any potentially usable join OR clauses to *joinorclauses

may reflect the change in v46-0001 lappend -> list_append_unique_ptr
that differs in the processing of equal clauses in the list.

Comments in this function are revised. I also added detailed
explanation of this change to the commit message.

Semantics mentioned in the commit message:

2. Make match_join_clauses_to_index() pass OR-clauses to
match_clause_to_index().

could also be added as comments in the section just before
match_join_clauses_to_index()

Right, this is addressed too.

Since d4378c0005e6 comment for match_clause_to_indexcol() I think
needs change. This could be as a separate commit, not regarding
current patch v46-0001.

* NOTE: returns NULL if clause is an OR or AND clause; it is the
* responsibility of higher-level routines to co

Good catch. This is added as a separate patch.

I think the patch can be pushed with possible additions to regression
test and comments.

OK, thank you!

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v47-0001-Revise-the-header-comment-for-match_clause_to_in.patchapplication/octet-stream; name=v47-0001-Revise-the-header-comment-for-match_clause_to_in.patchDownload
From 0fe7f1eb6447b86f8c9e8ec472333e13ed36a255 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sat, 1 Feb 2025 16:53:32 +0200
Subject: [PATCH v47 1/2] Revise the header comment for
 match_clause_to_indexcol()

Since d4378c0005e6, match_clause_to_indexcol() doesn't always return NULL
for an OR clause.  This commit reflects that in the header comment.

Reported-by: Pavel Borisov <pashkin.elfe@gmail.com>
---
 src/backend/optimizer/path/indxpath.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index fa3edf60f3c..a58cf5bad1a 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -2639,8 +2639,9 @@ match_clause_to_index(PlannerInfo *root,
  * Returns an IndexClause if the clause can be used with this index key,
  * or NULL if not.
  *
- * NOTE:  returns NULL if clause is an OR or AND clause; it is the
- * responsibility of higher-level routines to cope with those.
+ * NOTE:  This routine always returns NULL if the clause is an AND clause.
+ * Higher-level routines deal with OR and AND clauses. OR clause can be
+ * matched as a whole by match_orclause_to_indexcol() though.
  */
 static IndexClause *
 match_clause_to_indexcol(PlannerInfo *root,
-- 
2.39.5 (Apple Git-154)

v47-0002-Allow-usage-of-match_orclause_to_indexcol-for-jo.patchapplication/octet-stream; name=v47-0002-Allow-usage-of-match_orclause_to_indexcol-for-jo.patchDownload
From 3522cfd0a792e77b3740ea7541826bd0fbc6e752 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Wed, 9 Oct 2024 18:44:25 +0300
Subject: [PATCH v47 2/2] Allow usage of match_orclause_to_indexcol() for joins

This commit allows transformation of OR-clauses into SAOP's for index scans
within nested loop joins.  That required the following changes.

 1. Make match_orclause_to_indexcol() and group_similar_or_args() understand
    const-ness in the same way as match_opclause_to_indexcol().  This
    generally makes our approach more uniform.
 2. Make match_join_clauses_to_index() pass OR-clauses to
    match_clause_to_index().
 3. Also switch match_join_clauses_to_index() to use list_append_unique_ptr()
    for adding clauses to *joinorclauses.  That avoids possible duplicates
    when processing the same clauses with different indexes.  Previously such
    duplicates were elimited in match_clause_to_index(), but now
    group_similar_or_args() each time generates distinct copies of grouped
    OR clauses.

Discussion: https://postgr.es/m/CAPpHfdv%2BjtNwofg-p5z86jLYZUTt6tR17Wy00ta0dL%3DwHQN3ZA%40mail.gmail.com
Reviewed-by: Andrei Lepikhov <lepihov@gmail.com>
Reviewed-by: Alena Rybakina <a.rybakina@postgrespro.ru>
Reviewed-by: Pavel Borisov <pashkin.elfe@gmail.com>
---
 src/backend/optimizer/path/indxpath.c        | 70 ++++++++++++--------
 src/test/regress/expected/create_index.out   | 39 +++++++++++
 src/test/regress/expected/join.out           | 51 ++++++++++++--
 src/test/regress/expected/partition_join.out | 12 ++--
 src/test/regress/sql/create_index.sql        |  8 +++
 src/test/regress/sql/join.sql                | 18 ++++-
 6 files changed, 156 insertions(+), 42 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index a58cf5bad1a..6e2051efc65 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1255,6 +1255,7 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 	ListCell   *lc2;
 	List	   *orargs;
 	List	   *result = NIL;
+	Index		relid = rel->relid;
 
 	Assert(IsA(rinfo->orclause, BoolExpr));
 	orargs = ((BoolExpr *) rinfo->orclause)->args;
@@ -1319,10 +1320,13 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 		/*
 		 * Check for clauses of the form: (indexkey operator constant) or
 		 * (constant operator indexkey).  But we don't know a particular index
-		 * yet.  First check for a constant, which must be Const or Param.
-		 * That's cheaper than search for an index key among all indexes.
+		 * yet.  Therefore, we try to distinguish the potential index key and
+		 * constant first, then search for a matching index key among all
+		 * indexes.
 		 */
-		if (IsA(leftop, Const) || IsA(leftop, Param))
+		if (bms_is_member(relid, argrinfo->right_relids) &&
+			!bms_is_member(relid, argrinfo->left_relids) &&
+			!contain_volatile_functions(leftop))
 		{
 			opno = get_commutator(opno);
 
@@ -1333,7 +1337,9 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 			}
 			nonConstExpr = rightop;
 		}
-		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		else if (bms_is_member(relid, argrinfo->left_relids) &&
+				 !bms_is_member(relid, argrinfo->right_relids) &&
+				 !contain_volatile_functions(rightop))
 		{
 			nonConstExpr = leftop;
 		}
@@ -2414,6 +2420,7 @@ match_restriction_clauses_to_index(PlannerInfo *root,
  *	  Identify join clauses for the rel that match the index.
  *	  Matching clauses are added to *clauseset.
  *	  Also, add any potentially usable join OR clauses to *joinorclauses.
+ *	  They also might be processed by match_clause_to_index() as a whole.
  */
 static void
 match_join_clauses_to_index(PlannerInfo *root,
@@ -2432,11 +2439,15 @@ match_join_clauses_to_index(PlannerInfo *root,
 		if (!join_clause_is_movable_to(rinfo, rel))
 			continue;
 
-		/* Potentially usable, so see if it matches the index or is an OR */
+		/*
+		 * Potentially usable, so see if it matches the index or is an OR. Use
+		 * list_append_unique_ptr() here to avoid possible duplicates when
+		 * processing the same clauses with different indexes.
+		 */
 		if (restriction_is_or_clause(rinfo))
-			*joinorclauses = lappend(*joinorclauses, rinfo);
-		else
-			match_clause_to_index(root, rinfo, index, clauseset);
+			*joinorclauses = list_append_unique_ptr(*joinorclauses, rinfo);
+
+		match_clause_to_index(root, rinfo, index, clauseset);
 	}
 }
 
@@ -2585,10 +2596,7 @@ match_clause_to_index(PlannerInfo *root,
  *	  (3)  must match the collation of the index, if collation is relevant.
  *
  *	  Our definition of "const" is exceedingly liberal: we allow anything that
- *	  doesn't involve a volatile function or a Var of the index's relation
- *	  except for a boolean OR expression input: due to a trade-off between the
- *	  expected execution speedup and planning complexity, we limit or->saop
- *	  transformation by obvious cases when an index scan can get a profit.
+ *	  doesn't involve a volatile function or a Var of the index's relation.
  *	  In particular, Vars belonging to other relations of the query are
  *	  accepted here, since a clause of that form can be used in a
  *	  parameterized indexscan.  It's the responsibility of higher code levels
@@ -3247,7 +3255,8 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Oid			arraytype = InvalidOid;
 	Oid			inputcollid = InvalidOid;
 	bool		firstTime = true;
-	bool		haveParam = false;
+	bool		haveNonConst = false;
+	Index		indexRelid = index->rel->relid;
 
 	Assert(IsA(orclause, BoolExpr));
 	Assert(orclause->boolop == OR_EXPR);
@@ -3259,10 +3268,9 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	/*
 	 * Try to convert a list of OR-clauses to a single SAOP expression. Each
 	 * OR entry must be in the form: (indexkey operator constant) or (constant
-	 * operator indexkey).  Operators of all the entries must match.  Constant
-	 * might be either Const or Param.  To be effective, give up on the first
-	 * non-matching entry.  Exit is implemented as a break from the loop,
-	 * which is catched afterwards.
+	 * operator indexkey).  Operators of all the entries must match.  To be
+	 * effective, give up on the first non-matching entry.  Exit is
+	 * implemented as a break from the loop, which is catched afterwards.
 	 */
 	foreach(lc, orclause->args)
 	{
@@ -3313,17 +3321,21 @@ match_orclause_to_indexcol(PlannerInfo *root,
 
 		/*
 		 * Check for clauses of the form: (indexkey operator constant) or
-		 * (constant operator indexkey).  Determine indexkey side first, check
-		 * the constant later.
+		 * (constant operator indexkey).  See match_clause_to_indexcol's notes
+		 * about const-ness.
 		 */
 		leftop = (Node *) linitial(subClause->args);
 		rightop = (Node *) lsecond(subClause->args);
-		if (match_index_to_operand(leftop, indexcol, index))
+		if (match_index_to_operand(leftop, indexcol, index) &&
+			!bms_is_member(indexRelid, subRinfo->right_relids) &&
+			!contain_volatile_functions(rightop))
 		{
 			indexExpr = leftop;
 			constExpr = rightop;
 		}
-		else if (match_index_to_operand(rightop, indexcol, index))
+		else if (match_index_to_operand(rightop, indexcol, index) &&
+				 !bms_is_member(indexRelid, subRinfo->left_relids) &&
+				 !contain_volatile_functions(leftop))
 		{
 			opno = get_commutator(opno);
 			if (!OidIsValid(opno))
@@ -3350,10 +3362,6 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		if (IsA(indexExpr, RelabelType))
 			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
 
-		/* We allow constant to be Const or Param */
-		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
-			break;
-
 		/* Forbid transformation for composite types, records. */
 		if (type_is_rowtype(exprType(constExpr)) ||
 			type_is_rowtype(exprType(indexExpr)))
@@ -3390,8 +3398,12 @@ match_orclause_to_indexcol(PlannerInfo *root,
 				break;
 		}
 
-		if (IsA(constExpr, Param))
-			haveParam = true;
+		/*
+		 * Check if our list of constants in match_clause_to_indexcol's
+		 * understanding of const-ness have something other than Const.
+		 */
+		if (!IsA(constExpr, Const))
+			haveNonConst = true;
 		consts = lappend(consts, constExpr);
 	}
 
@@ -3408,10 +3420,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
 
 	/*
 	 * Assemble an array from the list of constants.  It seems more profitable
-	 * to build a const array.  But in the presence of parameters, we don't
+	 * to build a const array.  But in the presence of other nodes, we don't
 	 * have a specific value here and must employ an ArrayExpr instead.
 	 */
-	if (haveParam)
+	if (haveNonConst)
 	{
 		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 8011c141bf8..0ee7b2d7c61 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2006,6 +2006,35 @@ SELECT * FROM tenk1
    Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
 (2 rows)
 
+EXPLAIN (COSTS OFF)
+SELECT t1.thousand FROM tenk1 t1
+  WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous + 1 LIMIT 1);
+                              QUERY PLAN                              
+----------------------------------------------------------------------
+ Index Only Scan using tenk1_thous_tenthous on tenk1 t1
+   Filter: ((thousand = 42) OR (thousand = (SubPlan 1)))
+   SubPlan 1
+     ->  Limit
+           ->  Index Only Scan using tenk1_thous_tenthous on tenk1 t2
+                 Index Cond: (thousand = (t1.tenthous + 1))
+(6 rows)
+
+SELECT t1.thousand FROM tenk1 t1
+  WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous + 1 LIMIT 1);
+ thousand 
+----------
+       42
+       42
+       42
+       42
+       42
+       42
+       42
+       42
+       42
+       42
+(10 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -3255,6 +3284,16 @@ CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
 CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
 CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
 ANALYZE bitmap_split_or;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.b OR t1.a=1;
+                       QUERY PLAN                       
+--------------------------------------------------------
+ Nested Loop
+   ->  Seq Scan on bitmap_split_or t2
+   ->  Index Scan using t_a_b_idx on bitmap_split_or t1
+         Index Cond: (a = ANY (ARRAY[t2.b, 1]))
+(4 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
                             QUERY PLAN                            
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 079fcf46f0d..3ffc066b1f8 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -3849,14 +3849,11 @@ where q1 = thousand or q2 = thousand;
                ->  Seq Scan on q2
          ->  Bitmap Heap Scan on tenk1
                Recheck Cond: ((q1.q1 = thousand) OR (q2.q2 = thousand))
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = q1.q1)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = q2.q2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY (ARRAY[q1.q1, q2.q2]))
    ->  Hash
          ->  Seq Scan on int4_tbl
-(15 rows)
+(12 rows)
 
 explain (costs off)
 select * from
@@ -8239,3 +8236,45 @@ GROUP BY s.c1, s.c2;
 (7 rows)
 
 DROP TABLE group_tbl;
+--
+-- Test for a nested loop join involving index scan, transforming OR-clauses
+-- to SAOP.
+--
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM tenk1 t1, tenk1 t2
+WHERE t2.thousand = t1.tenthous OR t2.thousand = t1.unique1 OR t2.thousand = t1.unique2;
+                                       QUERY PLAN                                        
+-----------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Seq Scan on tenk1 t1
+         ->  Index Only Scan using tenk1_thous_tenthous on tenk1 t2
+               Index Cond: (thousand = ANY (ARRAY[t1.tenthous, t1.unique1, t1.unique2]))
+(5 rows)
+
+SELECT COUNT(*) FROM tenk1 t1, tenk1 t2
+WHERE t2.thousand = t1.tenthous OR t2.thousand = t1.unique1 OR t2.thousand = t1.unique2;
+ count 
+-------
+ 20000
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM onek t1 LEFT JOIN tenk1 t2
+    ON (t2.thousand = t1.tenthous OR t2.thousand = t1.thousand);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         ->  Seq Scan on onek t1
+         ->  Index Only Scan using tenk1_thous_tenthous on tenk1 t2
+               Index Cond: (thousand = ANY (ARRAY[t1.tenthous, t1.thousand]))
+(5 rows)
+
+SELECT COUNT(*) FROM onek t1 LEFT JOIN tenk1 t2
+    ON (t2.thousand = t1.tenthous OR t2.thousand = t1.thousand);
+ count 
+-------
+ 19000
+(1 row)
+
diff --git a/src/test/regress/expected/partition_join.out b/src/test/regress/expected/partition_join.out
index 108f9ecb445..af468682a2d 100644
--- a/src/test/regress/expected/partition_join.out
+++ b/src/test/regress/expected/partition_join.out
@@ -2533,24 +2533,24 @@ where not exists (select 1 from prtx2
          ->  Seq Scan on prtx1_1
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_1
-               Recheck Cond: ((b = (prtx1_1.b + 1)) OR (c = 99))
+               Recheck Cond: ((c = 99) OR (b = (prtx1_1.b + 1)))
                Filter: (a = prtx1_1.a)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on prtx2_1_b_idx
-                           Index Cond: (b = (prtx1_1.b + 1))
                      ->  Bitmap Index Scan on prtx2_1_c_idx
                            Index Cond: (c = 99)
+                     ->  Bitmap Index Scan on prtx2_1_b_idx
+                           Index Cond: (b = (prtx1_1.b + 1))
    ->  Nested Loop Anti Join
          ->  Seq Scan on prtx1_2
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_2
-               Recheck Cond: ((b = (prtx1_2.b + 1)) OR (c = 99))
+               Recheck Cond: ((c = 99) OR (b = (prtx1_2.b + 1)))
                Filter: (a = prtx1_2.a)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on prtx2_2_b_idx
-                           Index Cond: (b = (prtx1_2.b + 1))
                      ->  Bitmap Index Scan on prtx2_2_c_idx
                            Index Cond: (c = 99)
+                     ->  Bitmap Index Scan on prtx2_2_b_idx
+                           Index Cond: (b = (prtx1_2.b + 1))
 (23 rows)
 
 select * from prtx1
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 068c66b95a5..ca8a20af115 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -781,6 +781,12 @@ EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
 
+EXPLAIN (COSTS OFF)
+SELECT t1.thousand FROM tenk1 t1
+  WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous + 1 LIMIT 1);
+SELECT t1.thousand FROM tenk1 t1
+  WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous + 1 LIMIT 1);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1367,6 +1373,8 @@ CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
 CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
 ANALYZE bitmap_split_or;
 EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.b OR t1.a=1;
+EXPLAIN (COSTS OFF)
 SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
 DROP TABLE bitmap_split_or;
 
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 779d56cb30f..c7349eab933 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -3016,7 +3016,6 @@ SELECT t1.a FROM skip_fetch t1 LEFT JOIN skip_fetch t2 ON t2.a = 1 WHERE t2.a IS
 
 RESET enable_indexonlyscan;
 RESET enable_seqscan;
-
 -- Test BitmapHeapScan with a rescan releases resources correctly
 SET enable_seqscan = off;
 SET enable_indexscan = off;
@@ -3046,3 +3045,20 @@ SELECT 1 FROM group_tbl t1
 GROUP BY s.c1, s.c2;
 
 DROP TABLE group_tbl;
+
+--
+-- Test for a nested loop join involving index scan, transforming OR-clauses
+-- to SAOP.
+--
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM tenk1 t1, tenk1 t2
+WHERE t2.thousand = t1.tenthous OR t2.thousand = t1.unique1 OR t2.thousand = t1.unique2;
+SELECT COUNT(*) FROM tenk1 t1, tenk1 t2
+WHERE t2.thousand = t1.tenthous OR t2.thousand = t1.unique1 OR t2.thousand = t1.unique2;
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM onek t1 LEFT JOIN tenk1 t2
+    ON (t2.thousand = t1.tenthous OR t2.thousand = t1.thousand);
+SELECT COUNT(*) FROM onek t1 LEFT JOIN tenk1 t2
+    ON (t2.thousand = t1.tenthous OR t2.thousand = t1.thousand);
-- 
2.39.5 (Apple Git-154)

#313Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#309)
Re: POC, WIP: OR-clause support for indexes

On Tue, Jan 28, 2025 at 10:42 AM Andrei Lepikhov <lepihov@gmail.com> wrote:

On 1/28/25 11:36, Andrei Lepikhov wrote:

On 1/27/25 16:50, Alexander Korotkov wrote:
qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);

To fit an index, the order of elements in the target array of the
`ScalarArrayOpExpr` may change compared to the initial list of OR
expressions. If there are indexes that cover the same set of columns but
in reverse order, this could potentially alter the position of a
Subplan. However, I believe this is a rare case; it is supported by the
initial OR path and should be acceptable.

I beg your pardon - I forgot that we've restricted the feature's scope
and can't combine OR clauses into ScalarArrayOpExpr if the args list
contains references to different columns.
So, my note can't be applied here.

OK, thank you!

------
Regards,
Alexander Korotkov
Supabase

#314Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#311)
Re: POC, WIP: OR-clause support for indexes

On Fri, Jan 31, 2025 at 4:31 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I started reviewing at the patch and saw some output "ERROR" in the output of the test and is it okay here?

SELECT * FROM tenk1 t1
WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous);
ERROR: more than one row returned by a subquery used as an expression

The output is correct for this query. But the query is very
unfortunate for the regression test. I've revised query in the v47
revision [1].

Links.
1. /messages/by-id/CAPpHfdsBZmNt9qUoJBqsQFiVDX1=yCKpuVAt1YnR7JCpP=k8+A@mail.gmail.com

------
Regards,
Alexander Korotkov
Supabase

#315Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#312)
Re: POC, WIP: OR-clause support for indexes

On 2/3/25 00:57, Alexander Korotkov wrote:

On Thu, Jan 30, 2025 at 3:23 PM Pavel Borisov <pashkin.elfe@gmail.com> wrote:

On Tue, 28 Jan 2025 at 12:42, Andrei Lepikhov <lepihov@gmail.com> wrote:

On 1/28/25 11:36, Andrei Lepikhov wrote:

On 1/27/25 16:50, Alexander Korotkov wrote:
qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);

To fit an index, the order of elements in the target array of the
`ScalarArrayOpExpr` may change compared to the initial list of OR
expressions. If there are indexes that cover the same set of columns but
in reverse order, this could potentially alter the position of a
Subplan. However, I believe this is a rare case; it is supported by the
initial OR path and should be acceptable.

I beg your pardon - I forgot that we've restricted the feature's scope
and can't combine OR clauses into ScalarArrayOpExpr if the args list
contains references to different columns.
So, my note can't be applied here.

--
regards, Andrei Lepikhov

I've looked at the patch v46-0001
Looks good to me.

There is a test that demonstrates the behavior change. Maybe some more
cases like are also worth adding to a test.

+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.c
OR (t1.a=t2.b OR t1.a=1);
+                       QUERY PLAN
+--------------------------------------------------------
+ Nested Loop
+   ->  Seq Scan on bitmap_split_or t2
+   ->  Index Scan using t_a_b_idx on bitmap_split_or t1
+         Index Cond: (a = ANY (ARRAY[t2.c, t2.b, 1]))
+(4 rows)
+
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.c=t2.b OR t1.a=1;
+                  QUERY PLAN
+----------------------------------------------
+ Nested Loop
+   Join Filter: ((t1.c = t2.b) OR (t1.a = 1))
+   ->  Seq Scan on bitmap_split_or t1
+   ->  Materialize
+         ->  Seq Scan on bitmap_split_or t2
+(5 rows)
+
+EXPLAIN (COSTS OFF)

Added more tests to join.sql

I have made final pass through the changes. All looks good.
Only one thing looks strange for me - multiple '42's in the output of
the test. May be reduce output by an aggregate in the target list of the
query?

--
regards, Andrei Lepikhov

#316Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#314)
Re: POC, WIP: OR-clause support for indexes

Thank you for updated version! I agree for your version of the code.

On 02.02.2025 21:00, Alexander Korotkov wrote:

On Fri, Jan 31, 2025 at 4:31 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I started reviewing at the patch and saw some output "ERROR" in the output of the test and is it okay here?

SELECT * FROM tenk1 t1
WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous);
ERROR: more than one row returned by a subquery used as an expression

The output is correct for this query. But the query is very
unfortunate for the regression test. I've revised query in the v47
revision [1].

Links.
1./messages/by-id/CAPpHfdsBZmNt9qUoJBqsQFiVDX1=yCKpuVAt1YnR7JCpP=k8+A@mail.gmail.com

While analyzing the modified query plan from the regression test, I
noticed that despite using a full seqscan for table t2 in the original
plan,
its results are cached by Materialize node, and this can significantly
speed up the execution of the NestedLoop algorithm.

For example, after running the query several times, I got results that
show that the query execution time was twice as bad.

Original plan:

EXPLAIN ANALYZE SELECT * FROM bitmap_split_or t1, bitmap_split_or t2
WHERE t1.a=t2.b OR t1.a=1; QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..70067.00 rows=2502499 width=24) (actual
time=0.015..1123.247 rows=2003000 loops=1) Join Filter: ((t1.a = t2.b)
OR (t1.a = 1)) Rows Removed by Join Filter: 1997000 Buffers: shared
hit=22 -> Seq Scan on bitmap_split_or t1 (cost=0.00..31.00 rows=2000
width=12) (actual time=0.006..0.372 rows=2000 loops=1) Buffers: shared
hit=11 -> Materialize (cost=0.00..41.00 rows=2000 width=12) (actual
time=0.000..0.111 rows=2000 loops=2000) Storage: Memory Maximum Storage:
110kB Buffers: shared hit=11 -> Seq Scan on bitmap_split_or t2
(cost=0.00..31.00 rows=2000 width=12) (actual time=0.003..0.188
rows=2000 loops=1) Buffers: shared hit=11 Planning Time: 0.118 ms
Execution Time: 1204.874 ms (13 rows)

Query plan after the patch:

EXPLAIN ANALYZE SELECT * FROM bitmap_split_or t1, bitmap_split_or t2
WHERE t1.a=t2.b OR t1.a=1; QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.28..56369.00 rows=2502499 width=24) (actual
time=0.121..2126.606 rows=2003000 loops=1) Buffers: shared hit=16009
read=2 -> Seq Scan on bitmap_split_or t2 (cost=0.00..31.00 rows=2000
width=12) (actual time=0.017..0.652 rows=2000 loops=1) Buffers: shared
hit=11 -> Index Scan using t_a_b_idx on bitmap_split_or t1
(cost=0.28..18.15 rows=1002 width=12) (actual time=0.044..0.627
rows=1002 loops=2000) Index Cond: (a = ANY (ARRAY[t2.b, 1])) Buffers:
shared hit=15998 read=2 Planning Time: 0.282 ms Execution Time: 2344.367
ms (9 rows)

I'm afraid that we may lose this with this optimization. Maybe this can
be taken into account somehow, what do you think?

--
Regards,
Alena Rybakina
Postgres Professional

#317Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#316)
2 attachment(s)
Re: POC, WIP: OR-clause support for indexes

On Mon, Feb 3, 2025 at 12:22 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

Thank you for updated version! I agree for your version of the code.

On 02.02.2025 21:00, Alexander Korotkov wrote:

On Fri, Jan 31, 2025 at 4:31 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I started reviewing at the patch and saw some output "ERROR" in the output of the test and is it okay here?

SELECT * FROM tenk1 t1
WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous);
ERROR: more than one row returned by a subquery used as an expression

The output is correct for this query. But the query is very
unfortunate for the regression test. I've revised query in the v47
revision [1].

Links.
1. /messages/by-id/CAPpHfdsBZmNt9qUoJBqsQFiVDX1=yCKpuVAt1YnR7JCpP=k8+A@mail.gmail.com

While analyzing the modified query plan from the regression test, I noticed that despite using a full seqscan for table t2 in the original plan,
its results are cached by Materialize node, and this can significantly speed up the execution of the NestedLoop algorithm.

For example, after running the query several times, I got results that show that the query execution time was twice as bad.

Original plan:

EXPLAIN ANALYZE SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.b OR t1.a=1; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.00..70067.00 rows=2502499 width=24) (actual time=0.015..1123.247 rows=2003000 loops=1) Join Filter: ((t1.a = t2.b) OR (t1.a = 1)) Rows Removed by Join Filter: 1997000 Buffers: shared hit=22 -> Seq Scan on bitmap_split_or t1 (cost=0.00..31.00 rows=2000 width=12) (actual time=0.006..0.372 rows=2000 loops=1) Buffers: shared hit=11 -> Materialize (cost=0.00..41.00 rows=2000 width=12) (actual time=0.000..0.111 rows=2000 loops=2000) Storage: Memory Maximum Storage: 110kB Buffers: shared hit=11 -> Seq Scan on bitmap_split_or t2 (cost=0.00..31.00 rows=2000 width=12) (actual time=0.003..0.188 rows=2000 loops=1) Buffers: shared hit=11 Planning Time: 0.118 ms Execution Time: 1204.874 ms (13 rows)

Query plan after the patch:

EXPLAIN ANALYZE SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.b OR t1.a=1; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.28..56369.00 rows=2502499 width=24) (actual time=0.121..2126.606 rows=2003000 loops=1) Buffers: shared hit=16009 read=2 -> Seq Scan on bitmap_split_or t2 (cost=0.00..31.00 rows=2000 width=12) (actual time=0.017..0.652 rows=2000 loops=1) Buffers: shared hit=11 -> Index Scan using t_a_b_idx on bitmap_split_or t1 (cost=0.28..18.15 rows=1002 width=12) (actual time=0.044..0.627 rows=1002 loops=2000) Index Cond: (a = ANY (ARRAY[t2.b, 1])) Buffers: shared hit=15998 read=2 Planning Time: 0.282 ms Execution Time: 2344.367 ms (9 rows)

I'm afraid that we may lose this with this optimization. Maybe this can be taken into account somehow, what do you think?

The important aspect is that the second plan have lower cost than the
first one. So, that's the question to the cost model. The patch just
lets optimizer consider more comprehensive plurality of paths. You
can let optimizer select the first plan by tuning *_cost params. For
example, setting cpu_index_tuple_cost = 0.02 makes first plan win for
me.

Other than that the test query is quite unfortunate as t1.a=1 is very
frequent. I've adjusted the query so that nested loop with index scan
wins both in cost and execution time.

I've also adjusted another test query as proposed by Andrei.

I'm going to push this patch is there is no more notes.

Links.
1. /messages/by-id/fc1017ca-877b-4f86-b491-154cf123eedd@gmail.com

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v48-0001-Revise-the-header-comment-for-match_clause_to_in.patchapplication/octet-stream; name=v48-0001-Revise-the-header-comment-for-match_clause_to_in.patchDownload
From 0fe7f1eb6447b86f8c9e8ec472333e13ed36a255 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sat, 1 Feb 2025 16:53:32 +0200
Subject: [PATCH v48 1/2] Revise the header comment for
 match_clause_to_indexcol()

Since d4378c0005e6, match_clause_to_indexcol() doesn't always return NULL
for an OR clause.  This commit reflects that in the header comment.

Reported-by: Pavel Borisov <pashkin.elfe@gmail.com>
---
 src/backend/optimizer/path/indxpath.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index fa3edf60f3c..a58cf5bad1a 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -2639,8 +2639,9 @@ match_clause_to_index(PlannerInfo *root,
  * Returns an IndexClause if the clause can be used with this index key,
  * or NULL if not.
  *
- * NOTE:  returns NULL if clause is an OR or AND clause; it is the
- * responsibility of higher-level routines to cope with those.
+ * NOTE:  This routine always returns NULL if the clause is an AND clause.
+ * Higher-level routines deal with OR and AND clauses. OR clause can be
+ * matched as a whole by match_orclause_to_indexcol() though.
  */
 static IndexClause *
 match_clause_to_indexcol(PlannerInfo *root,
-- 
2.39.5 (Apple Git-154)

v48-0002-Allow-usage-of-match_orclause_to_indexcol-for-jo.patchapplication/octet-stream; name=v48-0002-Allow-usage-of-match_orclause_to_indexcol-for-jo.patchDownload
From c35d3b71bd8db9de8941af1d07421ba2456c223b Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Wed, 9 Oct 2024 18:44:25 +0300
Subject: [PATCH v48 2/2] Allow usage of match_orclause_to_indexcol() for joins

This commit allows transformation of OR-clauses into SAOP's for index scans
within nested loop joins.  That required the following changes.

 1. Make match_orclause_to_indexcol() and group_similar_or_args() understand
    const-ness in the same way as match_opclause_to_indexcol().  This
    generally makes our approach more uniform.
 2. Make match_join_clauses_to_index() pass OR-clauses to
    match_clause_to_index().
 3. Also switch match_join_clauses_to_index() to use list_append_unique_ptr()
    for adding clauses to *joinorclauses.  That avoids possible duplicates
    when processing the same clauses with different indexes.  Previously such
    duplicates were elimited in match_clause_to_index(), but now
    group_similar_or_args() each time generates distinct copies of grouped
    OR clauses.

Discussion: https://postgr.es/m/CAPpHfdv%2BjtNwofg-p5z86jLYZUTt6tR17Wy00ta0dL%3DwHQN3ZA%40mail.gmail.com
Reviewed-by: Andrei Lepikhov <lepihov@gmail.com>
Reviewed-by: Alena Rybakina <a.rybakina@postgrespro.ru>
Reviewed-by: Pavel Borisov <pashkin.elfe@gmail.com>
---
 src/backend/optimizer/path/indxpath.c        | 70 ++++++++++++--------
 src/test/regress/expected/create_index.out   | 32 +++++++++
 src/test/regress/expected/join.out           | 51 ++++++++++++--
 src/test/regress/expected/partition_join.out | 12 ++--
 src/test/regress/sql/create_index.sql        |  9 +++
 src/test/regress/sql/join.sql                | 18 ++++-
 6 files changed, 150 insertions(+), 42 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index a58cf5bad1a..6e2051efc65 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1255,6 +1255,7 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 	ListCell   *lc2;
 	List	   *orargs;
 	List	   *result = NIL;
+	Index		relid = rel->relid;
 
 	Assert(IsA(rinfo->orclause, BoolExpr));
 	orargs = ((BoolExpr *) rinfo->orclause)->args;
@@ -1319,10 +1320,13 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 		/*
 		 * Check for clauses of the form: (indexkey operator constant) or
 		 * (constant operator indexkey).  But we don't know a particular index
-		 * yet.  First check for a constant, which must be Const or Param.
-		 * That's cheaper than search for an index key among all indexes.
+		 * yet.  Therefore, we try to distinguish the potential index key and
+		 * constant first, then search for a matching index key among all
+		 * indexes.
 		 */
-		if (IsA(leftop, Const) || IsA(leftop, Param))
+		if (bms_is_member(relid, argrinfo->right_relids) &&
+			!bms_is_member(relid, argrinfo->left_relids) &&
+			!contain_volatile_functions(leftop))
 		{
 			opno = get_commutator(opno);
 
@@ -1333,7 +1337,9 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 			}
 			nonConstExpr = rightop;
 		}
-		else if (IsA(rightop, Const) || IsA(rightop, Param))
+		else if (bms_is_member(relid, argrinfo->left_relids) &&
+				 !bms_is_member(relid, argrinfo->right_relids) &&
+				 !contain_volatile_functions(rightop))
 		{
 			nonConstExpr = leftop;
 		}
@@ -2414,6 +2420,7 @@ match_restriction_clauses_to_index(PlannerInfo *root,
  *	  Identify join clauses for the rel that match the index.
  *	  Matching clauses are added to *clauseset.
  *	  Also, add any potentially usable join OR clauses to *joinorclauses.
+ *	  They also might be processed by match_clause_to_index() as a whole.
  */
 static void
 match_join_clauses_to_index(PlannerInfo *root,
@@ -2432,11 +2439,15 @@ match_join_clauses_to_index(PlannerInfo *root,
 		if (!join_clause_is_movable_to(rinfo, rel))
 			continue;
 
-		/* Potentially usable, so see if it matches the index or is an OR */
+		/*
+		 * Potentially usable, so see if it matches the index or is an OR. Use
+		 * list_append_unique_ptr() here to avoid possible duplicates when
+		 * processing the same clauses with different indexes.
+		 */
 		if (restriction_is_or_clause(rinfo))
-			*joinorclauses = lappend(*joinorclauses, rinfo);
-		else
-			match_clause_to_index(root, rinfo, index, clauseset);
+			*joinorclauses = list_append_unique_ptr(*joinorclauses, rinfo);
+
+		match_clause_to_index(root, rinfo, index, clauseset);
 	}
 }
 
@@ -2585,10 +2596,7 @@ match_clause_to_index(PlannerInfo *root,
  *	  (3)  must match the collation of the index, if collation is relevant.
  *
  *	  Our definition of "const" is exceedingly liberal: we allow anything that
- *	  doesn't involve a volatile function or a Var of the index's relation
- *	  except for a boolean OR expression input: due to a trade-off between the
- *	  expected execution speedup and planning complexity, we limit or->saop
- *	  transformation by obvious cases when an index scan can get a profit.
+ *	  doesn't involve a volatile function or a Var of the index's relation.
  *	  In particular, Vars belonging to other relations of the query are
  *	  accepted here, since a clause of that form can be used in a
  *	  parameterized indexscan.  It's the responsibility of higher code levels
@@ -3247,7 +3255,8 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	Oid			arraytype = InvalidOid;
 	Oid			inputcollid = InvalidOid;
 	bool		firstTime = true;
-	bool		haveParam = false;
+	bool		haveNonConst = false;
+	Index		indexRelid = index->rel->relid;
 
 	Assert(IsA(orclause, BoolExpr));
 	Assert(orclause->boolop == OR_EXPR);
@@ -3259,10 +3268,9 @@ match_orclause_to_indexcol(PlannerInfo *root,
 	/*
 	 * Try to convert a list of OR-clauses to a single SAOP expression. Each
 	 * OR entry must be in the form: (indexkey operator constant) or (constant
-	 * operator indexkey).  Operators of all the entries must match.  Constant
-	 * might be either Const or Param.  To be effective, give up on the first
-	 * non-matching entry.  Exit is implemented as a break from the loop,
-	 * which is catched afterwards.
+	 * operator indexkey).  Operators of all the entries must match.  To be
+	 * effective, give up on the first non-matching entry.  Exit is
+	 * implemented as a break from the loop, which is catched afterwards.
 	 */
 	foreach(lc, orclause->args)
 	{
@@ -3313,17 +3321,21 @@ match_orclause_to_indexcol(PlannerInfo *root,
 
 		/*
 		 * Check for clauses of the form: (indexkey operator constant) or
-		 * (constant operator indexkey).  Determine indexkey side first, check
-		 * the constant later.
+		 * (constant operator indexkey).  See match_clause_to_indexcol's notes
+		 * about const-ness.
 		 */
 		leftop = (Node *) linitial(subClause->args);
 		rightop = (Node *) lsecond(subClause->args);
-		if (match_index_to_operand(leftop, indexcol, index))
+		if (match_index_to_operand(leftop, indexcol, index) &&
+			!bms_is_member(indexRelid, subRinfo->right_relids) &&
+			!contain_volatile_functions(rightop))
 		{
 			indexExpr = leftop;
 			constExpr = rightop;
 		}
-		else if (match_index_to_operand(rightop, indexcol, index))
+		else if (match_index_to_operand(rightop, indexcol, index) &&
+				 !bms_is_member(indexRelid, subRinfo->left_relids) &&
+				 !contain_volatile_functions(leftop))
 		{
 			opno = get_commutator(opno);
 			if (!OidIsValid(opno))
@@ -3350,10 +3362,6 @@ match_orclause_to_indexcol(PlannerInfo *root,
 		if (IsA(indexExpr, RelabelType))
 			indexExpr = (Node *) ((RelabelType *) indexExpr)->arg;
 
-		/* We allow constant to be Const or Param */
-		if (!IsA(constExpr, Const) && !IsA(constExpr, Param))
-			break;
-
 		/* Forbid transformation for composite types, records. */
 		if (type_is_rowtype(exprType(constExpr)) ||
 			type_is_rowtype(exprType(indexExpr)))
@@ -3390,8 +3398,12 @@ match_orclause_to_indexcol(PlannerInfo *root,
 				break;
 		}
 
-		if (IsA(constExpr, Param))
-			haveParam = true;
+		/*
+		 * Check if our list of constants in match_clause_to_indexcol's
+		 * understanding of const-ness have something other than Const.
+		 */
+		if (!IsA(constExpr, Const))
+			haveNonConst = true;
 		consts = lappend(consts, constExpr);
 	}
 
@@ -3408,10 +3420,10 @@ match_orclause_to_indexcol(PlannerInfo *root,
 
 	/*
 	 * Assemble an array from the list of constants.  It seems more profitable
-	 * to build a const array.  But in the presence of parameters, we don't
+	 * to build a const array.  But in the presence of other nodes, we don't
 	 * have a specific value here and must employ an ArrayExpr instead.
 	 */
-	if (haveParam)
+	if (haveNonConst)
 	{
 		ArrayExpr  *arrayExpr = makeNode(ArrayExpr);
 
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 8011c141bf8..bd5f002cf20 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2006,6 +2006,27 @@ SELECT * FROM tenk1
    Filter: (((tenthous)::numeric = '1'::numeric) OR (tenthous = 3) OR ((tenthous)::numeric = '42'::numeric))
 (2 rows)
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 t1
+  WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous + 1 LIMIT 1);
+                                 QUERY PLAN                                 
+----------------------------------------------------------------------------
+ Aggregate
+   ->  Index Only Scan using tenk1_thous_tenthous on tenk1 t1
+         Filter: ((thousand = 42) OR (thousand = (SubPlan 1)))
+         SubPlan 1
+           ->  Limit
+                 ->  Index Only Scan using tenk1_thous_tenthous on tenk1 t2
+                       Index Cond: (thousand = (t1.tenthous + 1))
+(7 rows)
+
+SELECT count(*) FROM tenk1 t1
+  WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous + 1 LIMIT 1);
+ count 
+-------
+    10
+(1 row)
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -3255,6 +3276,17 @@ CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
 CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
 CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
 ANALYZE bitmap_split_or;
+EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2
+WHERE t1.a = t2.b OR t1.a = 2;
+                       QUERY PLAN                       
+--------------------------------------------------------
+ Nested Loop
+   ->  Seq Scan on bitmap_split_or t2
+   ->  Index Scan using t_a_b_idx on bitmap_split_or t1
+         Index Cond: (a = ANY (ARRAY[t2.b, 2]))
+(4 rows)
+
 EXPLAIN (COSTS OFF)
 SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
                             QUERY PLAN                            
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 079fcf46f0d..3ffc066b1f8 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -3849,14 +3849,11 @@ where q1 = thousand or q2 = thousand;
                ->  Seq Scan on q2
          ->  Bitmap Heap Scan on tenk1
                Recheck Cond: ((q1.q1 = thousand) OR (q2.q2 = thousand))
-               ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = q1.q1)
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: (thousand = q2.q2)
+               ->  Bitmap Index Scan on tenk1_thous_tenthous
+                     Index Cond: (thousand = ANY (ARRAY[q1.q1, q2.q2]))
    ->  Hash
          ->  Seq Scan on int4_tbl
-(15 rows)
+(12 rows)
 
 explain (costs off)
 select * from
@@ -8239,3 +8236,45 @@ GROUP BY s.c1, s.c2;
 (7 rows)
 
 DROP TABLE group_tbl;
+--
+-- Test for a nested loop join involving index scan, transforming OR-clauses
+-- to SAOP.
+--
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM tenk1 t1, tenk1 t2
+WHERE t2.thousand = t1.tenthous OR t2.thousand = t1.unique1 OR t2.thousand = t1.unique2;
+                                       QUERY PLAN                                        
+-----------------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop
+         ->  Seq Scan on tenk1 t1
+         ->  Index Only Scan using tenk1_thous_tenthous on tenk1 t2
+               Index Cond: (thousand = ANY (ARRAY[t1.tenthous, t1.unique1, t1.unique2]))
+(5 rows)
+
+SELECT COUNT(*) FROM tenk1 t1, tenk1 t2
+WHERE t2.thousand = t1.tenthous OR t2.thousand = t1.unique1 OR t2.thousand = t1.unique2;
+ count 
+-------
+ 20000
+(1 row)
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM onek t1 LEFT JOIN tenk1 t2
+    ON (t2.thousand = t1.tenthous OR t2.thousand = t1.thousand);
+                                  QUERY PLAN                                  
+------------------------------------------------------------------------------
+ Aggregate
+   ->  Nested Loop Left Join
+         ->  Seq Scan on onek t1
+         ->  Index Only Scan using tenk1_thous_tenthous on tenk1 t2
+               Index Cond: (thousand = ANY (ARRAY[t1.tenthous, t1.thousand]))
+(5 rows)
+
+SELECT COUNT(*) FROM onek t1 LEFT JOIN tenk1 t2
+    ON (t2.thousand = t1.tenthous OR t2.thousand = t1.thousand);
+ count 
+-------
+ 19000
+(1 row)
+
diff --git a/src/test/regress/expected/partition_join.out b/src/test/regress/expected/partition_join.out
index 108f9ecb445..af468682a2d 100644
--- a/src/test/regress/expected/partition_join.out
+++ b/src/test/regress/expected/partition_join.out
@@ -2533,24 +2533,24 @@ where not exists (select 1 from prtx2
          ->  Seq Scan on prtx1_1
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_1
-               Recheck Cond: ((b = (prtx1_1.b + 1)) OR (c = 99))
+               Recheck Cond: ((c = 99) OR (b = (prtx1_1.b + 1)))
                Filter: (a = prtx1_1.a)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on prtx2_1_b_idx
-                           Index Cond: (b = (prtx1_1.b + 1))
                      ->  Bitmap Index Scan on prtx2_1_c_idx
                            Index Cond: (c = 99)
+                     ->  Bitmap Index Scan on prtx2_1_b_idx
+                           Index Cond: (b = (prtx1_1.b + 1))
    ->  Nested Loop Anti Join
          ->  Seq Scan on prtx1_2
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_2
-               Recheck Cond: ((b = (prtx1_2.b + 1)) OR (c = 99))
+               Recheck Cond: ((c = 99) OR (b = (prtx1_2.b + 1)))
                Filter: (a = prtx1_2.a)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on prtx2_2_b_idx
-                           Index Cond: (b = (prtx1_2.b + 1))
                      ->  Bitmap Index Scan on prtx2_2_c_idx
                            Index Cond: (c = 99)
+                     ->  Bitmap Index Scan on prtx2_2_b_idx
+                           Index Cond: (b = (prtx1_2.b + 1))
 (23 rows)
 
 select * from prtx1
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 068c66b95a5..be570da08a0 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -781,6 +781,12 @@ EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
   WHERE tenthous = 1::numeric OR tenthous = 3::int4 OR tenthous = 42::numeric;
 
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM tenk1 t1
+  WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous + 1 LIMIT 1);
+SELECT count(*) FROM tenk1 t1
+  WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous + 1 LIMIT 1);
+
 EXPLAIN (COSTS OFF)
 SELECT count(*) FROM tenk1
   WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
@@ -1367,6 +1373,9 @@ CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
 CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
 ANALYZE bitmap_split_or;
 EXPLAIN (COSTS OFF)
+SELECT * FROM bitmap_split_or t1, bitmap_split_or t2
+WHERE t1.a = t2.b OR t1.a = 2;
+EXPLAIN (COSTS OFF)
 SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
 DROP TABLE bitmap_split_or;
 
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 779d56cb30f..c7349eab933 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -3016,7 +3016,6 @@ SELECT t1.a FROM skip_fetch t1 LEFT JOIN skip_fetch t2 ON t2.a = 1 WHERE t2.a IS
 
 RESET enable_indexonlyscan;
 RESET enable_seqscan;
-
 -- Test BitmapHeapScan with a rescan releases resources correctly
 SET enable_seqscan = off;
 SET enable_indexscan = off;
@@ -3046,3 +3045,20 @@ SELECT 1 FROM group_tbl t1
 GROUP BY s.c1, s.c2;
 
 DROP TABLE group_tbl;
+
+--
+-- Test for a nested loop join involving index scan, transforming OR-clauses
+-- to SAOP.
+--
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM tenk1 t1, tenk1 t2
+WHERE t2.thousand = t1.tenthous OR t2.thousand = t1.unique1 OR t2.thousand = t1.unique2;
+SELECT COUNT(*) FROM tenk1 t1, tenk1 t2
+WHERE t2.thousand = t1.tenthous OR t2.thousand = t1.unique1 OR t2.thousand = t1.unique2;
+
+EXPLAIN (COSTS OFF)
+SELECT COUNT(*) FROM onek t1 LEFT JOIN tenk1 t2
+    ON (t2.thousand = t1.tenthous OR t2.thousand = t1.thousand);
+SELECT COUNT(*) FROM onek t1 LEFT JOIN tenk1 t2
+    ON (t2.thousand = t1.tenthous OR t2.thousand = t1.thousand);
-- 
2.39.5 (Apple Git-154)

#318Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#317)
Re: POC, WIP: OR-clause support for indexes

On 03.02.2025 14:32, Alexander Korotkov wrote:

On Mon, Feb 3, 2025 at 12:22 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

Thank you for updated version! I agree for your version of the code.

On 02.02.2025 21:00, Alexander Korotkov wrote:

On Fri, Jan 31, 2025 at 4:31 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I started reviewing at the patch and saw some output "ERROR" in the output of the test and is it okay here?

SELECT * FROM tenk1 t1
WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous);
ERROR: more than one row returned by a subquery used as an expression

The output is correct for this query. But the query is very
unfortunate for the regression test. I've revised query in the v47
revision [1].

Links.
1./messages/by-id/CAPpHfdsBZmNt9qUoJBqsQFiVDX1=yCKpuVAt1YnR7JCpP=k8+A@mail.gmail.com

While analyzing the modified query plan from the regression test, I noticed that despite using a full seqscan for table t2 in the original plan,
its results are cached by Materialize node, and this can significantly speed up the execution of the NestedLoop algorithm.

For example, after running the query several times, I got results that show that the query execution time was twice as bad.

Original plan:

EXPLAIN ANALYZE SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.b OR t1.a=1; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.00..70067.00 rows=2502499 width=24) (actual time=0.015..1123.247 rows=2003000 loops=1) Join Filter: ((t1.a = t2.b) OR (t1.a = 1)) Rows Removed by Join Filter: 1997000 Buffers: shared hit=22 -> Seq Scan on bitmap_split_or t1 (cost=0.00..31.00 rows=2000 width=12) (actual time=0.006..0.372 rows=2000 loops=1) Buffers: shared hit=11 -> Materialize (cost=0.00..41.00 rows=2000 width=12) (actual time=0.000..0.111 rows=2000 loops=2000) Storage: Memory Maximum Storage: 110kB Buffers: shared hit=11 -> Seq Scan on bitmap_split_or t2 (cost=0.00..31.00 rows=2000 width=12) (actual time=0.003..0.188 rows=2000 loops=1) Buffers: shared hit=11 Planning Time: 0.118 ms Execution Time: 1204.874 ms (13 rows)

Query plan after the patch:

EXPLAIN ANALYZE SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.b OR t1.a=1; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.28..56369.00 rows=2502499 width=24) (actual time=0.121..2126.606 rows=2003000 loops=1) Buffers: shared hit=16009 read=2 -> Seq Scan on bitmap_split_or t2 (cost=0.00..31.00 rows=2000 width=12) (actual time=0.017..0.652 rows=2000 loops=1) Buffers: shared hit=11 -> Index Scan using t_a_b_idx on bitmap_split_or t1 (cost=0.28..18.15 rows=1002 width=12) (actual time=0.044..0.627 rows=1002 loops=2000) Index Cond: (a = ANY (ARRAY[t2.b, 1])) Buffers: shared hit=15998 read=2 Planning Time: 0.282 ms Execution Time: 2344.367 ms (9 rows)

I'm afraid that we may lose this with this optimization. Maybe this can be taken into account somehow, what do you think?

The important aspect is that the second plan have lower cost than the
first one. So, that's the question to the cost model. The patch just
lets optimizer consider more comprehensive plurality of paths. You
can let optimizer select the first plan by tuning *_cost params. For
example, setting cpu_index_tuple_cost = 0.02 makes first plan win for
me.

Other than that the test query is quite unfortunate as t1.a=1 is very
frequent. I've adjusted the query so that nested loop with index scan
wins both in cost and execution time.

I've also adjusted another test query as proposed by Andrei.

I'm going to push this patch is there is no more notes.

Links.
1./messages/by-id/fc1017ca-877b-4f86-b491-154cf123eedd@gmail.com

Okay.I agree with your codeand have no more notes

--
Regards,
Alena Rybakina
Postgres Professional

#319Pavel Borisov
pashkin.elfe@gmail.com
In reply to: Alena Rybakina (#318)
Re: POC, WIP: OR-clause support for indexes

On Mon, 3 Feb 2025 at 15:54, Alena Rybakina <a.rybakina@postgrespro.ru> wrote:

On 03.02.2025 14:32, Alexander Korotkov wrote:

On Mon, Feb 3, 2025 at 12:22 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

Thank you for updated version! I agree for your version of the code.

On 02.02.2025 21:00, Alexander Korotkov wrote:

On Fri, Jan 31, 2025 at 4:31 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I started reviewing at the patch and saw some output "ERROR" in the output of the test and is it okay here?

SELECT * FROM tenk1 t1
WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous);
ERROR: more than one row returned by a subquery used as an expression

The output is correct for this query. But the query is very
unfortunate for the regression test. I've revised query in the v47
revision [1].

Links.
1. /messages/by-id/CAPpHfdsBZmNt9qUoJBqsQFiVDX1=yCKpuVAt1YnR7JCpP=k8+A@mail.gmail.com

While analyzing the modified query plan from the regression test, I noticed that despite using a full seqscan for table t2 in the original plan,
its results are cached by Materialize node, and this can significantly speed up the execution of the NestedLoop algorithm.

For example, after running the query several times, I got results that show that the query execution time was twice as bad.

Original plan:

EXPLAIN ANALYZE SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.b OR t1.a=1; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.00..70067.00 rows=2502499 width=24) (actual time=0.015..1123.247 rows=2003000 loops=1) Join Filter: ((t1.a = t2.b) OR (t1.a = 1)) Rows Removed by Join Filter: 1997000 Buffers: shared hit=22 -> Seq Scan on bitmap_split_or t1 (cost=0.00..31.00 rows=2000 width=12) (actual time=0.006..0.372 rows=2000 loops=1) Buffers: shared hit=11 -> Materialize (cost=0.00..41.00 rows=2000 width=12) (actual time=0.000..0.111 rows=2000 loops=2000) Storage: Memory Maximum Storage: 110kB Buffers: shared hit=11 -> Seq Scan on bitmap_split_or t2 (cost=0.00..31.00 rows=2000 width=12) (actual time=0.003..0.188 rows=2000 loops=1) Buffers: shared hit=11 Planning Time: 0.118 ms Execution Time: 1204.874 ms (13 rows)

Query plan after the patch:

EXPLAIN ANALYZE SELECT * FROM bitmap_split_or t1, bitmap_split_or t2 WHERE t1.a=t2.b OR t1.a=1; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.28..56369.00 rows=2502499 width=24) (actual time=0.121..2126.606 rows=2003000 loops=1) Buffers: shared hit=16009 read=2 -> Seq Scan on bitmap_split_or t2 (cost=0.00..31.00 rows=2000 width=12) (actual time=0.017..0.652 rows=2000 loops=1) Buffers: shared hit=11 -> Index Scan using t_a_b_idx on bitmap_split_or t1 (cost=0.28..18.15 rows=1002 width=12) (actual time=0.044..0.627 rows=1002 loops=2000) Index Cond: (a = ANY (ARRAY[t2.b, 1])) Buffers: shared hit=15998 read=2 Planning Time: 0.282 ms Execution Time: 2344.367 ms (9 rows)

I'm afraid that we may lose this with this optimization. Maybe this can be taken into account somehow, what do you think?

The important aspect is that the second plan have lower cost than the
first one. So, that's the question to the cost model. The patch just
lets optimizer consider more comprehensive plurality of paths. You
can let optimizer select the first plan by tuning *_cost params. For
example, setting cpu_index_tuple_cost = 0.02 makes first plan win for
me.

Other than that the test query is quite unfortunate as t1.a=1 is very
frequent. I've adjusted the query so that nested loop with index scan
wins both in cost and execution time.

I've also adjusted another test query as proposed by Andrei.

I'm going to push this patch is there is no more notes.

Links.
1. /messages/by-id/fc1017ca-877b-4f86-b491-154cf123eedd@gmail.com

Okay.I agree with your code and have no more notes

Hi, Alexander!
I've looked at patchset v48 and it looks good to me.

Regards,
Pavel Borisov
Supabase

#320Andrei Lepikhov
lepihov@gmail.com
In reply to: Pavel Borisov (#319)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi,

Playing with the feature, I found a slightly irritating permutation -
even if this code doesn't group any clauses, it may permute positions of
the quals. See:

DROP TABLE IF EXISTS main_tbl;
CREATE TABLE main_tbl(id bigint, hundred int, thousand int);
CREATE INDEX mt_hundred_ix ON main_tbl(hundred);
CREATE INDEX mt_thousand_ix ON main_tbl(thousand);
VACUUM (ANALYZE) main_tbl;

SET enable_seqscan = off;
EXPLAIN (COSTS OFF)
SELECT m.id, m.hundred, m.thousand
FROM main_tbl m WHERE (m.hundred < 2 OR m.thousand < 3);

Bitmap Heap Scan on public.main_tbl m
Output: id, hundred, thousand
Recheck Cond: ((m.thousand < 3) OR (m.hundred < 2))
-> BitmapOr
-> Bitmap Index Scan on mt_thousand_ix
Index Cond: (m.thousand < 3)
-> Bitmap Index Scan on mt_hundred_ix
Index Cond: (m.hundred < 2)

Conditions on the columns "thousand" and "hundred" changed their places
according to the initial positions defined in the user's SQL.
It isn't okay. I see that users often use the trick of "OR order" to
avoid unnecessary calculations - most frequently, Subplan evaluations.
So, it makes sense to fix.
In the attachment, I have included a quick fix for this issue. Although
many tests returned to their initial (pre-18) state, I added some tests
specifically related to this issue to make it clearer.

--
regards, Andrei Lepikhov

Attachments:

clause-permutation-fix.difftext/x-patch; charset=UTF-8; name=clause-permutation-fix.diffDownload
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index a43ca16d68..7d8ef0c90f 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1254,6 +1254,7 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 	ListCell   *lc;
 	ListCell   *lc2;
 	List	   *orargs;
+	bool		grouping_happened = false;
 	List	   *result = NIL;
 	Index		relid = rel->relid;
 
@@ -1465,13 +1466,18 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 												   rinfo->incompatible_relids,
 												   rinfo->outer_relids);
 				result = lappend(result, subrinfo);
+				grouping_happened = true;
 			}
 
 			group_start = i;
 		}
 	}
 	pfree(matches);
-	return result;
+
+	if (grouping_happened)
+		return result;
+	else
+		return orargs;
 }
 
 /*
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index bd5f002cf2..c6f84bda64 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -3248,6 +3248,37 @@ SELECT  b.relname,
 (2 rows)
 
 DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before;
+-- No OR-clause groupings should happen - no clause permutations in
+-- the filtering conditions we should see in the EXPLAIN.
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1 WHERE unique1 < 1 OR hundred < 2;
+                    QUERY PLAN                    
+--------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: ((unique1 < 1) OR (hundred < 2))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_unique1
+               Index Cond: (unique1 < 1)
+         ->  Bitmap Index Scan on tenk1_hundred
+               Index Cond: (hundred < 2)
+(7 rows)
+
+-- OR clauses on the 'unique' column is grouped. So, clause permutation happened
+-- We see it in the 'Recheck Cond' and order of BitmapOr subpaths: index scan on
+-- the 'hundred' column occupies the first position.
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1 WHERE unique1 < 1 OR unique1 < 3 OR hundred < 2;
+                             QUERY PLAN                              
+---------------------------------------------------------------------
+ Bitmap Heap Scan on tenk1
+   Recheck Cond: ((hundred < 2) OR ((unique1 < 1) OR (unique1 < 3)))
+   ->  BitmapOr
+         ->  Bitmap Index Scan on tenk1_hundred
+               Index Cond: (hundred < 2)
+         ->  Bitmap Index Scan on tenk1_unique1
+               Index Cond: (unique1 < ANY ('{1,3}'::integer[]))
+(7 rows)
+
 -- Check bitmap scan can consider similar OR arguments separately without
 -- grouping them into SAOP.
 CREATE TABLE bitmap_split_or (a int NOT NULL, b int NOT NULL, c int NOT NULL);
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index a57bb18c24..a950153d76 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4333,20 +4333,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_hundred
-                     Index Cond: (hundred = 4)
                ->  Bitmap Index Scan on tenk1_unique1
                      Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 3)
 (17 rows)
 
 explain (costs off)
@@ -4360,12 +4360,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 3)
 (12 rows)
 
 explain (costs off)
@@ -4377,12 +4377,12 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_hundred
-                     Index Cond: (hundred = 4)
                ->  Bitmap Index Scan on tenk1_unique1
                      Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
                Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
@@ -4403,12 +4403,12 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_hundred
-                     Index Cond: (hundred = 4)
                ->  Bitmap Index Scan on tenk1_unique1
                      Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
                Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
diff --git a/src/test/regress/expected/partition_join.out b/src/test/regress/expected/partition_join.out
index 938cedd79a..6101c8c7cf 100644
--- a/src/test/regress/expected/partition_join.out
+++ b/src/test/regress/expected/partition_join.out
@@ -2568,24 +2568,24 @@ where not exists (select 1 from prtx2
          ->  Seq Scan on prtx1_1
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_1
-               Recheck Cond: ((c = 99) OR (b = (prtx1_1.b + 1)))
+               Recheck Cond: ((b = (prtx1_1.b + 1)) OR (c = 99))
                Filter: (a = prtx1_1.a)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on prtx2_1_c_idx
-                           Index Cond: (c = 99)
                      ->  Bitmap Index Scan on prtx2_1_b_idx
                            Index Cond: (b = (prtx1_1.b + 1))
+                     ->  Bitmap Index Scan on prtx2_1_c_idx
+                           Index Cond: (c = 99)
    ->  Nested Loop Anti Join
          ->  Seq Scan on prtx1_2
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_2
-               Recheck Cond: ((c = 99) OR (b = (prtx1_2.b + 1)))
+               Recheck Cond: ((b = (prtx1_2.b + 1)) OR (c = 99))
                Filter: (a = prtx1_2.a)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on prtx2_2_c_idx
-                           Index Cond: (c = 99)
                      ->  Bitmap Index Scan on prtx2_2_b_idx
                            Index Cond: (b = (prtx1_2.b + 1))
+                     ->  Bitmap Index Scan on prtx2_2_c_idx
+                           Index Cond: (c = 99)
 (23 rows)
 
 select * from prtx1
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index be570da08a..51e030294e 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -1355,6 +1355,17 @@ SELECT  b.relname,
   ORDER BY 1;
 DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before;
 
+-- No OR-clause groupings should happen - no clause permutations in
+-- the filtering conditions we should see in the EXPLAIN.
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1 WHERE unique1 < 1 OR hundred < 2;
+
+-- OR clauses on the 'unique' column is grouped. So, clause permutation happened
+-- We see it in the 'Recheck Cond' and order of BitmapOr subpaths: index scan on
+-- the 'hundred' column occupies the first position.
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1 WHERE unique1 < 1 OR unique1 < 3 OR hundred < 2;
+
 -- Check bitmap scan can consider similar OR arguments separately without
 -- grouping them into SAOP.
 CREATE TABLE bitmap_split_or (a int NOT NULL, b int NOT NULL, c int NOT NULL);
#321Pavel Borisov
pashkin.elfe@gmail.com
In reply to: Andrei Lepikhov (#320)
Re: POC, WIP: OR-clause support for indexes

Hi, Andrei!

On Mon, 24 Mar 2025 at 14:10, Andrei Lepikhov <lepihov@gmail.com> wrote:

Hi,

Playing with the feature, I found a slightly irritating permutation -
even if this code doesn't group any clauses, it may permute positions of
the quals. See:

DROP TABLE IF EXISTS main_tbl;
CREATE TABLE main_tbl(id bigint, hundred int, thousand int);
CREATE INDEX mt_hundred_ix ON main_tbl(hundred);
CREATE INDEX mt_thousand_ix ON main_tbl(thousand);
VACUUM (ANALYZE) main_tbl;

SET enable_seqscan = off;
EXPLAIN (COSTS OFF)
SELECT m.id, m.hundred, m.thousand
FROM main_tbl m WHERE (m.hundred < 2 OR m.thousand < 3);

Bitmap Heap Scan on public.main_tbl m
Output: id, hundred, thousand
Recheck Cond: ((m.thousand < 3) OR (m.hundred < 2))
-> BitmapOr
-> Bitmap Index Scan on mt_thousand_ix
Index Cond: (m.thousand < 3)
-> Bitmap Index Scan on mt_hundred_ix
Index Cond: (m.hundred < 2)

Conditions on the columns "thousand" and "hundred" changed their places
according to the initial positions defined in the user's SQL.
It isn't okay. I see that users often use the trick of "OR order" to
avoid unnecessary calculations - most frequently, Subplan evaluations.
So, it makes sense to fix.
In the attachment, I have included a quick fix for this issue. Although
many tests returned to their initial (pre-18) state, I added some tests
specifically related to this issue to make it clearer.

I looked at your patch and have no objections to it.

However it's clearly stated in PostgreSQL manual that nothing about
the OR order is warranted [1]https://www.postgresql.org/docs/17/sql-expressions.html#SYNTAX-EXPRESS-EVAL. So changing OR order was (and is) ok
and any users query tricks about OR order may work and may not work.

[1]: https://www.postgresql.org/docs/17/sql-expressions.html#SYNTAX-EXPRESS-EVAL

Regards,
Pavel Borisov
Supabase

#322Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Pavel Borisov (#321)
Re: POC, WIP: OR-clause support for indexes

On 24.03.2025 13:46, Pavel Borisov wrote:

Hi, Andrei!

On Mon, 24 Mar 2025 at 14:10, Andrei Lepikhov<lepihov@gmail.com> wrote:

Hi,

Playing with the feature, I found a slightly irritating permutation -
even if this code doesn't group any clauses, it may permute positions of
the quals. See:

DROP TABLE IF EXISTS main_tbl;
CREATE TABLE main_tbl(id bigint, hundred int, thousand int);
CREATE INDEX mt_hundred_ix ON main_tbl(hundred);
CREATE INDEX mt_thousand_ix ON main_tbl(thousand);
VACUUM (ANALYZE) main_tbl;

SET enable_seqscan = off;
EXPLAIN (COSTS OFF)
SELECT m.id, m.hundred, m.thousand
FROM main_tbl m WHERE (m.hundred < 2 OR m.thousand < 3);

Bitmap Heap Scan on public.main_tbl m
Output: id, hundred, thousand
Recheck Cond: ((m.thousand < 3) OR (m.hundred < 2))
-> BitmapOr
-> Bitmap Index Scan on mt_thousand_ix
Index Cond: (m.thousand < 3)
-> Bitmap Index Scan on mt_hundred_ix
Index Cond: (m.hundred < 2)

Conditions on the columns "thousand" and "hundred" changed their places
according to the initial positions defined in the user's SQL.
It isn't okay. I see that users often use the trick of "OR order" to
avoid unnecessary calculations - most frequently, Subplan evaluations.
So, it makes sense to fix.
In the attachment, I have included a quick fix for this issue. Although
many tests returned to their initial (pre-18) state, I added some tests
specifically related to this issue to make it clearer.

I looked at your patch and have no objections to it.

However it's clearly stated in PostgreSQL manual that nothing about
the OR order is warranted [1]. So changing OR order was (and is) ok
and any users query tricks about OR order may work and may not work.

[1]https://www.postgresql.org/docs/17/sql-expressions.html#SYNTAX-EXPRESS-EVAL

I agree with Andrey's changes and think we should fix this, because
otherwise it might be inconvenient.
For example, without this changes we will have to have different test
output files for the same query for different versions of Postres in
extensions if the whole change is only related to the order of column
output for a transformation that was not applied.

--
Regards,
Alena Rybakina
Postgres Professional

#323Alexander Korotkov
aekorotkov@gmail.com
In reply to: Alena Rybakina (#322)
1 attachment(s)
Re: POC, WIP: OR-clause support for indexes

Hi!

On Mon, Mar 24, 2025 at 2:46 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I agree with Andrey's changes and think we should fix this, because otherwise it might be inconvenient.
For example, without this changes we will have to have different test output files for the same query for different versions of Postres in extensions if the whole change is only related to the order of column output for a transformation that was not applied.

I agree with problem spotted by Andrei: it should be preferred to
preserve original order of clauses as much as possible. The approach
implemented in Andrei's patch seems fragile for me. Original order is
preserved if we didn't find any group. But once we find a single
group original order might be destroyed completely.

The attached patch changes the reordering algorithm of
group_similar_or_args() in the following way. We reorder each group
of similar clauses so that the first item of the group stays in place,
but all the other items are moved after it. So, if there are no
similar clauses, the order of clauses stays the same. When there are
some groups, only required reordering happens while the rest of the
clauses remain in their places.

------
Regards,
Alexander Korotkov
Supabase

Attachments:

v1-0001-Make-group_similar_or_args-reorder-clause-list-as.patchapplication/octet-stream; name=v1-0001-Make-group_similar_or_args-reorder-clause-list-as.patchDownload
From 1829564b42450cac8d030d9942ef0a5f26ff86fe Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Fri, 28 Mar 2025 00:15:29 +0200
Subject: [PATCH v1] Make group_similar_or_args() reorder clause list as little
 as possible

Currently, group_similar_or_args() permutes original positions of clauses
independently on whether it manages to find any groups of similar clauses.
While we are not providing any strict warranties on saving the original order
of OR-clauses, it is preferred that the original order be modified as little
as possible.

This commit changes the reordering algorithm of group_similar_or_args() in
the following way.  We reorder each group of similar clauses so that the
first item of the group stays in place, but all the other items are moved
after it.  So, if there are no similar clauses, the order of clauses stays
the same.  When there are some groups, only required reordering happens while
the rest of the clauses remain in their places.

Reported-by: Andrei Lepikhov <lepihov@gmail.com>
Discussion: https://postgr.es/m/3ac7c436-81e1-4191-9caf-b0dd70b51511%40gmail.com
---
 src/backend/optimizer/path/indxpath.c        | 60 +++++++++++++++++++-
 src/test/regress/expected/create_index.out   | 18 +++---
 src/test/regress/expected/join.out           | 52 ++++++++---------
 src/test/regress/expected/partition_join.out | 12 ++--
 4 files changed, 100 insertions(+), 42 deletions(-)

diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index a43ca16d683..2a18bf7c7c3 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1189,6 +1189,8 @@ typedef struct
 	Oid			inputcollid;	/* OID of the OpClause input collation */
 	int			argindex;		/* index of the clause in the list of
 								 * arguments */
+	int			groupindex;		/* value of argindex for the fist clause in
+								 * the group of similar clauses */
 } OrArgIndexMatch;
 
 /*
@@ -1229,6 +1231,29 @@ or_arg_index_match_cmp(const void *a, const void *b)
 	return 0;
 }
 
+/*
+ * Another comparison function for OrArgIndexMatch.  It sorts groups together
+ * using groupindex.  The group items are then sorted by argindex.
+ */
+static int
+or_arg_index_match_cmp_group(const void *a, const void *b)
+{
+	const OrArgIndexMatch *match_a = (const OrArgIndexMatch *) a;
+	const OrArgIndexMatch *match_b = (const OrArgIndexMatch *) b;
+
+	if (match_a->groupindex < match_b->groupindex)
+		return -1;
+	else if (match_a->groupindex > match_b->groupindex)
+		return 1;
+
+	if (match_a->argindex < match_b->argindex)
+		return -1;
+	else if (match_a->argindex > match_b->argindex)
+		return 1;
+
+	return 0;
+}
+
 /*
  * group_similar_or_args
  *		Transform incoming OR-restrictinfo into a list of sub-restrictinfos,
@@ -1282,6 +1307,7 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 
 		i++;
 		matches[i].argindex = i;
+		matches[i].groupindex = i;
 		matches[i].indexnum = -1;
 		matches[i].colnum = -1;
 		matches[i].opno = InvalidOid;
@@ -1400,9 +1426,41 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo)
 		return orargs;
 	}
 
-	/* Sort clauses to make similar clauses go together */
+	/*
+	 * Sort clauses to make similar clauses go together.  But at the same
+	 * time, we would like to change the order of clauses as little as
+	 * possible.  To have this property, we reorder each group of similar
+	 * clauses so that the first item of the group stays in place, but all the
+	 * other items are moved after it.  So, if there are no similar clauses,
+	 * the order of clauses stays the same.  When there are some groups, only
+	 * required reordering happens while the rest of the clauses remain in
+	 * their places.  That is achieved by assigning a 'groupindex' to each
+	 * clause: the number of the first item in the group in the original
+	 * clause list.
+	 */
 	qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp);
 
+	/* Assign groupindex to the sorted clauses */
+	for (i = 1; i < n; i++)
+	{
+		/*
+		 * When two clauses are similar and should belong to the same group,
+		 * copy the 'groupindex' from the previous clause.  Given we are
+		 * considering clauses in direct order, all the clauses would have a
+		 * 'groupindex' equal to the 'groupindex' of the first clause in the
+		 * group.
+		 */
+		if ((matches[i].indexnum == matches[i - 1].indexnum ||
+			 matches[i].colnum == matches[i - 1].colnum ||
+			 matches[i].opno == matches[i - 1].opno ||
+			 matches[i].inputcollid == matches[i - 1].inputcollid) &&
+			matches[i].indexnum != -1)
+			matches[i].groupindex = matches[i - 1].groupindex;
+	}
+
+	/* Resort clauses first by groupindex then by argindex */
+	qsort(matches, n, sizeof(OrArgIndexMatch), or_arg_index_match_cmp_group);
+
 	/*
 	 * Group similar clauses into single sub-restrictinfo. Side effect: the
 	 * resulting list of restrictions will be sorted by indexnum and colnum.
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index bd5f002cf20..3bd18bbbac9 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1899,13 +1899,13 @@ SELECT * FROM tenk1
                                                                 QUERY PLAN                                                                 
 -------------------------------------------------------------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND (tenthous IS NULL)) OR ((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42))))
+   Recheck Cond: (((thousand = 42) AND ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42))) OR ((thousand = 42) AND (tenthous IS NULL)))
    Filter: ((tenthous = 1) OR (tenthous = 3) OR (tenthous = 42) OR (tenthous IS NULL))
    ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous IS NULL))
          ->  Bitmap Index Scan on tenk1_thous_tenthous
                Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous IS NULL))
 (8 rows)
 
 EXPLAIN (COSTS OFF)
@@ -1938,13 +1938,13 @@ SELECT * FROM tenk1
                                                                      QUERY PLAN                                                                      
 -----------------------------------------------------------------------------------------------------------------------------------------------------
  Bitmap Heap Scan on tenk1
-   Recheck Cond: (((thousand = 42) AND ((tenthous = '3'::bigint) OR (tenthous = '42'::bigint))) OR ((thousand = 42) AND (tenthous = '1'::smallint)))
+   Recheck Cond: (((thousand = 42) AND (tenthous = '1'::smallint)) OR ((thousand = 42) AND ((tenthous = '3'::bigint) OR (tenthous = '42'::bigint))))
    Filter: ((tenthous = '1'::smallint) OR (tenthous = '3'::bigint) OR (tenthous = '42'::bigint))
    ->  BitmapOr
-         ->  Bitmap Index Scan on tenk1_thous_tenthous
-               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{3,42}'::bigint[])))
          ->  Bitmap Index Scan on tenk1_thous_tenthous
                Index Cond: ((thousand = 42) AND (tenthous = '1'::smallint))
+         ->  Bitmap Index Scan on tenk1_thous_tenthous
+               Index Cond: ((thousand = 42) AND (tenthous = ANY ('{3,42}'::bigint[])))
 (8 rows)
 
 EXPLAIN (COSTS OFF)
@@ -2129,16 +2129,16 @@ SELECT count(*) FROM tenk1
 ---------------------------------------------------------------------------------------------------------------------------
  Aggregate
    ->  Bitmap Heap Scan on tenk1
-         Recheck Cond: ((hundred = 42) AND (((thousand = 99) AND (tenthous = 2)) OR ((thousand = 42) OR (thousand = 41))))
+         Recheck Cond: ((hundred = 42) AND (((thousand = 42) OR (thousand = 41)) OR ((thousand = 99) AND (tenthous = 2))))
          Filter: ((thousand = 42) OR (thousand = 41) OR ((thousand = 99) AND (tenthous = 2)))
          ->  BitmapAnd
                ->  Bitmap Index Scan on tenk1_hundred
                      Index Cond: (hundred = 42)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_thous_tenthous
-                           Index Cond: ((thousand = 99) AND (tenthous = 2))
                      ->  Bitmap Index Scan on tenk1_thous_tenthous
                            Index Cond: (thousand = ANY ('{42,41}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_thous_tenthous
+                           Index Cond: ((thousand = 99) AND (tenthous = 2))
 (12 rows)
 
 SELECT count(*) FROM tenk1
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index a57bb18c24f..14da5708451 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4333,20 +4333,20 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_hundred
-                     Index Cond: (hundred = 4)
                ->  Bitmap Index Scan on tenk1_unique1
                      Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 3)
 (17 rows)
 
 explain (costs off)
@@ -4360,12 +4360,12 @@ select * from tenk1 a join tenk1 b on
          Filter: ((unique1 = 2) OR (ten = 4))
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: ((unique2 = 3) OR (unique1 = 1))
+               Recheck Cond: ((unique1 = 1) OR (unique2 = 3))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = 3)
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = 3)
 (12 rows)
 
 explain (costs off)
@@ -4377,21 +4377,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_hundred
-                     Index Cond: (hundred = 4)
                ->  Bitmap Index Scan on tenk1_unique1
                      Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
 (18 rows)
 
 explain (costs off)
@@ -4403,21 +4403,21 @@ select * from tenk1 a join tenk1 b on
  Nested Loop
    Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4)))
    ->  Bitmap Heap Scan on tenk1 b
-         Recheck Cond: ((hundred = 4) OR (unique1 = 2))
+         Recheck Cond: ((unique1 = 2) OR (hundred = 4))
          ->  BitmapOr
-               ->  Bitmap Index Scan on tenk1_hundred
-                     Index Cond: (hundred = 4)
                ->  Bitmap Index Scan on tenk1_unique1
                      Index Cond: (unique1 = 2)
+               ->  Bitmap Index Scan on tenk1_hundred
+                     Index Cond: (hundred = 4)
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR (unique1 = 1))
+               Recheck Cond: ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))
                Filter: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 = 1)
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
 (18 rows)
 
 explain (costs off)
@@ -4431,15 +4431,15 @@ select * from tenk1 a join tenk1 b on
    ->  Seq Scan on tenk1 b
    ->  Materialize
          ->  Bitmap Heap Scan on tenk1 a
-               Recheck Cond: (((unique2 = 3) OR (unique2 = 7)) OR ((unique1 = 3) OR (unique1 = 1)) OR (unique1 < 20))
+               Recheck Cond: ((unique1 < 20) OR ((unique1 = 3) OR (unique1 = 1)) OR ((unique2 = 3) OR (unique2 = 7)))
                Filter: ((unique1 < 20) OR (unique1 = 3) OR (unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))
                ->  BitmapOr
-                     ->  Bitmap Index Scan on tenk1_unique2
-                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
-                     ->  Bitmap Index Scan on tenk1_unique1
-                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
                      ->  Bitmap Index Scan on tenk1_unique1
                            Index Cond: (unique1 < 20)
+                     ->  Bitmap Index Scan on tenk1_unique1
+                           Index Cond: (unique1 = ANY ('{3,1}'::integer[]))
+                     ->  Bitmap Index Scan on tenk1_unique2
+                           Index Cond: (unique2 = ANY ('{3,7}'::integer[]))
 (14 rows)
 
 --
diff --git a/src/test/regress/expected/partition_join.out b/src/test/regress/expected/partition_join.out
index 938cedd79ad..6101c8c7cf1 100644
--- a/src/test/regress/expected/partition_join.out
+++ b/src/test/regress/expected/partition_join.out
@@ -2568,24 +2568,24 @@ where not exists (select 1 from prtx2
          ->  Seq Scan on prtx1_1
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_1
-               Recheck Cond: ((c = 99) OR (b = (prtx1_1.b + 1)))
+               Recheck Cond: ((b = (prtx1_1.b + 1)) OR (c = 99))
                Filter: (a = prtx1_1.a)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on prtx2_1_c_idx
-                           Index Cond: (c = 99)
                      ->  Bitmap Index Scan on prtx2_1_b_idx
                            Index Cond: (b = (prtx1_1.b + 1))
+                     ->  Bitmap Index Scan on prtx2_1_c_idx
+                           Index Cond: (c = 99)
    ->  Nested Loop Anti Join
          ->  Seq Scan on prtx1_2
                Filter: ((a < 20) AND (c = 91))
          ->  Bitmap Heap Scan on prtx2_2
-               Recheck Cond: ((c = 99) OR (b = (prtx1_2.b + 1)))
+               Recheck Cond: ((b = (prtx1_2.b + 1)) OR (c = 99))
                Filter: (a = prtx1_2.a)
                ->  BitmapOr
-                     ->  Bitmap Index Scan on prtx2_2_c_idx
-                           Index Cond: (c = 99)
                      ->  Bitmap Index Scan on prtx2_2_b_idx
                            Index Cond: (b = (prtx1_2.b + 1))
+                     ->  Bitmap Index Scan on prtx2_2_c_idx
+                           Index Cond: (c = 99)
 (23 rows)
 
 select * from prtx1
-- 
2.39.5 (Apple Git-154)

#324Pavel Borisov
pashkin.elfe@gmail.com
In reply to: Alexander Korotkov (#323)
Re: POC, WIP: OR-clause support for indexes

Hi, Alexander!
d4378c0005e61b1bb7

On Fri, 28 Mar 2025 at 03:18, Alexander Korotkov <aekorotkov@gmail.com> wrote:

Hi!

On Mon, Mar 24, 2025 at 2:46 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I agree with Andrey's changes and think we should fix this, because otherwise it might be inconvenient.
For example, without this changes we will have to have different test output files for the same query for different versions of Postres in extensions if the whole change is only related to the order of column output for a transformation that was not applied.

I agree with problem spotted by Andrei: it should be preferred to
preserve original order of clauses as much as possible. The approach
implemented in Andrei's patch seems fragile for me. Original order is
preserved if we didn't find any group. But once we find a single
group original order might be destroyed completely.

The attached patch changes the reordering algorithm of
group_similar_or_args() in the following way. We reorder each group
of similar clauses so that the first item of the group stays in place,
but all the other items are moved after it. So, if there are no
similar clauses, the order of clauses stays the same. When there are
some groups, only required reordering happens while the rest of the
clauses remain in their places.

With your patch, I've re-checked that there are no changes in the
order of evaluation in plans compared to d4378c0005e61b1bb7

It might be good to also include Andrei's test from his last patch. i.e:

+-- No OR-clause groupings should happen - no clause permutations in
+-- the filtering conditions we should see in the EXPLAIN.
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1 WHERE unique1 < 1 OR hundred < 2;
+
+-- OR clauses on the 'unique' column is grouped. So, clause
permutation happened
+-- We see it in the 'Recheck Cond' and order of BitmapOr subpaths:
index scan on
+-- the 'hundred' column occupies the first position.
+EXPLAIN (COSTS OFF)
+SELECT * FROM tenk1 WHERE unique1 < 1 OR unique1 < 3 OR hundred < 2;

I propose small changes for comments:

s/To have this property,/To do so,/g
s/in place, but all the/in place, and all the/g
s/some groups, only/some groups,/g
s/Resort/Re-sort/п

The patch overall looks good to me.

Regards,
Pavel Borisov
Supabase

#325Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#323)
Re: POC, WIP: OR-clause support for indexes

On 3/28/25 00:18, Alexander Korotkov wrote:

The attached patch changes the reordering algorithm of
group_similar_or_args() in the following way. We reorder each group
of similar clauses so that the first item of the group stays in place,
but all the other items are moved after it. So, if there are no
similar clauses, the order of clauses stays the same. When there are
some groups, only required reordering happens while the rest of the
clauses remain in their places.

The patch looks good to me from a technical perspective. But it seems
like an overkill, isn't it?
You introduce additional CPU-consuming operations in the planning OR
operations.
My point is: 1) as Pavel has mentioned, Postgres doesn't guarantee the
evaluation/output order of the clauses at all. 2) we need that to keep
regression tests stable (don't forget extensions' and forks' developers
too). But it should be done once if we have no fluidity in OR clauses
order in general.
The trade-off with tricky query writers and regression tests may be
preserving the order until OR->ANY has happened. If it has happened,
just ensure the order is determined somehow. Except that, any other
spending on CPU cycles seems too expensive.

--
regards, Andrei Lepikhov

#326Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andrei Lepikhov (#325)
Re: POC, WIP: OR-clause support for indexes

On Fri, Mar 28, 2025 at 1:32 PM Andrei Lepikhov <lepihov@gmail.com> wrote:

On 3/28/25 00:18, Alexander Korotkov wrote:

The attached patch changes the reordering algorithm of
group_similar_or_args() in the following way. We reorder each group
of similar clauses so that the first item of the group stays in place,
but all the other items are moved after it. So, if there are no
similar clauses, the order of clauses stays the same. When there are
some groups, only required reordering happens while the rest of the
clauses remain in their places.

The patch looks good to me from a technical perspective. But it seems
like an overkill, isn't it?
You introduce additional CPU-consuming operations in the planning OR
operations.

I don't think this is going to be CPU-consuming. I don't think this
is going to be measurable. This patch introduces one additional pass
over array of OrArgIndexMatch'es, and qsort of them. I think I've
seen places where we spend quadratic time over the number of
OR-clauses. Even calls of match_index_to_operand() for every clause
and every index look way more expensive.

My point is: 1) as Pavel has mentioned, Postgres doesn't guarantee the
evaluation/output order of the clauses at all. 2) we need that to keep
regression tests stable (don't forget extensions' and forks' developers
too). But it should be done once if we have no fluidity in OR clauses
order in general.
The trade-off with tricky query writers and regression tests may be
preserving the order until OR->ANY has happened. If it has happened,
just ensure the order is determined somehow. Except that, any other
spending on CPU cycles seems too expensive.

I think my patch gives better determinism too. For instance, output
order doesn't depend on order of indexes in rel->indexlist.

------
Regards,
Alexander Korotkov
Supabase

#327Andrei Lepikhov
lepihov@gmail.com
In reply to: Alexander Korotkov (#326)
Re: POC, WIP: OR-clause support for indexes

On 3/28/25 12:59, Alexander Korotkov wrote:

On Fri, Mar 28, 2025 at 1:32 PM Andrei Lepikhov <lepihov@gmail.com> wrote:
I don't think this is going to be CPU-consuming. I don't think this
is going to be measurable. This patch introduces one additional pass
over array of OrArgIndexMatch'es, and qsort of them. I think I've
seen places where we spend quadratic time over the number of
OR-clauses. Even calls of match_index_to_operand() for every clause
and every index look way more expensive.

Ok, I have no more objections.

I think my patch gives better determinism too. For instance, output
order doesn't depend on order of indexes in rel->indexlist.

Nice!

--
regards, Andrei Lepikhov

#328Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alexander Korotkov (#323)
Re: POC, WIP: OR-clause support for indexes

On 28.03.2025 02:18, Alexander Korotkov wrote:

Hi!

On Mon, Mar 24, 2025 at 2:46 PM Alena Rybakina
<a.rybakina@postgrespro.ru> wrote:

I agree with Andrey's changes and think we should fix this, because otherwise it might be inconvenient.
For example, without this changes we will have to have different test output files for the same query for different versions of Postres in extensions if the whole change is only related to the order of column output for a transformation that was not applied.

I agree with problem spotted by Andrei: it should be preferred to
preserve original order of clauses as much as possible. The approach
implemented in Andrei's patch seems fragile for me. Original order is
preserved if we didn't find any group. But once we find a single
group original order might be destroyed completely.

The attached patch changes the reordering algorithm of
group_similar_or_args() in the following way. We reorder each group
of similar clauses so that the first item of the group stays in place,
but all the other items are moved after it. So, if there are no
similar clauses, the order of clauses stays the same. When there are
some groups, only required reordering happens while the rest of the
clauses remain in their places.

I agree with your code in general, but to be honest, double qsort
confused me a little.

I understood why it is needed - we need to sort the elements so that
they stand next to each other if they can be assigned to the same group,
and then sort the groups themselves according to the set identifier.

I may be missing something, but in the worst case we can get the
complexity of qsort O(n^2), right? And I saw the letter where you
mentioned this, but it is possible to use mergesort algorithm instead of
qsort, which in the worst case gives n * O(n) complexity?

--
Regards,
Alena Rybakina
Postgres Professional

#329Alena Rybakina
a.rybakina@postgrespro.ru
In reply to: Alena Rybakina (#328)
Re: POC, WIP: OR-clause support for indexes

On 28.03.2025 15:23, Alena Rybakina wrote:

I agree with your code in general, but to be honest, double qsort
confused me a little.

I understood why it is needed - we need to sort the elements so that
they stand next to each other if they can be assigned to the same
group, and then sort the groups themselves according to the set
identifier.

I may be missing something, but in the worst case we can get the
complexity of qsort O(n^2), right? And I saw the letter where you
mentioned this, but it is possible to use mergesort algorithm  instead
of qsort, which in the worst case gives n * O(n) complexity?

No, sorry, I was wrong here and it is impossible to rewrite it this way.
I apologize, I agree with your code.

--
Regards,
Alena Rybakina
Postgres Professional